#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct timespec {
  int tv_sec;
  int tv_nsec;
};

/* Variables and functions */
void nsectospec(long long nsecs, struct timespec *ts) {
  if (nsecs < 0) {
    ts->tv_sec = -1;
    ts->tv_nsec = -1;
    return;
  }
  ts->tv_sec = nsecs / (1000LL * 1000000LL);
  ts->tv_nsec = (nsecs % (1000LL * 1000000LL));
}


x86 assembly (clang, -O0):
<nsectospec>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    1131 <nsectospec+0x31>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x10(%rbp),%rax
movl   $0xffffffff,0x4(%rax)
jmp    115e <nsectospec+0x5e>
mov    -0x8(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %edx,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<nsectospec>:
test   %rdi,%rdi
js     1127 <nsectospec+0x27>
mov    %rdi,%rax
shr    $0x9,%rax
movabs $0x44b82fa09b5a53,%rcx
mul    %rcx
shr    $0xb,%rdx
imul   $0x3b9aca00,%edx,%eax
sub    %eax,%edi
jmp    1131 <nsectospec+0x31>
mov    $0xffffffff,%edx
mov    $0xffffffff,%edi
mov    %edx,(%rsi)
mov    %edi,0x4(%rsi)
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define void @nsectospec(i64 %0, %struct.timespec* %1) {
%3 = alloca i64
%4 = alloca %struct.timespec*
store i64 %0, i64* %3
store %struct.timespec* %1, %struct.timespec** %4
%5 = load i64, i64* %3
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load %struct.timespec*, %struct.timespec** %4
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
store i32 -1, i32* %9
%10 = load %struct.timespec*, %struct.timespec** %4
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 1
store i32 -1, i32* %11
br label %23
12: ; preds = %2
%13 = load i64, i64* %3
%14 = sdiv i64 %13, 1000000000
%15 = trunc i64 %14 to i32
%16 = load %struct.timespec*, %struct.timespec** %4
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 0
store i32 %15, i32* %17
%18 = load i64, i64* %3
%19 = srem i64 %18, 1000000000
%20 = trunc i64 %19 to i32
%21 = load %struct.timespec*, %struct.timespec** %4
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %21, i32 0, i32 1
store i32 %20, i32* %22
br label %23
23: ; preds = %12, %7
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define void @nsectospec(i64 %0, %struct.timespec* nocapture writeonly %1) {
%3 = icmp slt i64 %0, 0
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = udiv i64 %0, 1000000000
%6 = trunc i64 %5 to i32
%7 = urem i64 %0, 1000000000
%8 = trunc i64 %7 to i32
br label %9
9: ; preds = %2, %4
%10 = phi i32 [ %6, %4 ], [ -1, %2 ]
%11 = phi i32 [ %8, %4 ], [ -1, %2 ]
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i32 %10, i32* %12
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i32 %11, i32* %13
ret void
}