.data
    ;; Allocate 16 bytes for struct timespec (tv_sec + tv_nsec)
    timespec_buf: .space 16

.text
.global _start
_start:
    ;; 1. Prepare arguments
    mov $228, %rax          ; syscall 228: sys_clock_gettime
    mov $0, %rdi            ; clockid_t which_clock = CLOCK_REALTIME (0)
    lea timespec_buf(%rip), %rsi ; struct timespec *tp (pointer to our buffer)

    ;; 2. Make the system call
    syscall

    ;; 3. Check for errors in %rax
    cmp $0, %rax
    jl handle_error

    ;; At this point, timespec_buf contains the time:
    ;; - Bytes 0-7:  seconds (tv_sec)
    ;; - Bytes 8-15: nanoseconds (tv_nsec)

    ;; Exit program cleanly
    mov $60, %rax           ; syscall 60: exit
    xor %rdi, %rdi          ; status 0
    syscall

handle_error:
    ;; %rax holds the negative error code
    mov $60, %rax
    mov $1, %rdi            ; exit status 1 (error)
    syscall
