#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 {
  long tv_sec;
  long tv_nsec;
};

/* Variables and functions */
struct timespec tsCreate(long seconds, long nanoseconds) {
  struct timespec result;
  seconds = (seconds < 0) ? 0 : seconds;
  nanoseconds = (nanoseconds < 0) ? 0 : nanoseconds;
  while (nanoseconds >= 1000000000L) {
    seconds++;
    nanoseconds = nanoseconds - 1000000000L;
  }
  result.tv_sec = seconds;
  result.tv_nsec = nanoseconds;
  return (result);
}


x86 assembly (clang, -O0):
<tsCreate>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1122 <tsCreate+0x22>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    112a <tsCreate+0x2a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1148 <tsCreate+0x48>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    1150 <tsCreate+0x50>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x3b9aca00,-0x20(%rbp)
3b
jl     1185 <tsCreate+0x85>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
sub    $0x3b9aca00,%rax
mov    %rax,-0x20(%rbp)
jmp    1158 <tsCreate+0x58>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rdx
pop    %rbp
ret

x86 assembly (clang, -O2):
<tsCreate>:
xor    %ecx,%ecx
test   %rdi,%rdi
cmovs  %rcx,%rdi
test   %rsi,%rsi
cmovns %rsi,%rcx
cmp    $0x3b9aca00,%rcx
jb     1162 <tsCreate+0x62>
cmp    $0x773593ff,%rcx
mov    $0x773593ff,%eax
cmovl  %rcx,%rax
neg    %rax
add    %rcx,%rax
add    $0x3b9ac9ff,%rax
shr    $0x9,%rax
movabs $0x44b82fa09b5a53,%rdx
mul    %rdx
shr    $0xb,%rdx
add    %rdx,%rdi
add    $0x1,%rdi
imul   $0xffffffffc4653600,%rdx,%rax
add    %rax,%rcx
add    $0xffffffffc4653600,%rcx
mov    %rdi,%rax
mov    %rcx,%rdx
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
define { i64, i64 } @tsCreate(i64 %0, i64 %1) {
%3 = alloca %struct.timespec
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %4
store i64 %1, i64* %5
%6 = load i64, i64* %4
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %2
br label %11
9: ; preds = %2
%10 = load i64, i64* %4
br label %11
11: ; preds = %9, %8
%12 = phi i64 [ 0, %8 ], [ %10, %9 ]
store i64 %12, i64* %4
%13 = load i64, i64* %5
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
br label %18
16: ; preds = %11
%17 = load i64, i64* %5
br label %18
18: ; preds = %16, %15
%19 = phi i64 [ 0, %15 ], [ %17, %16 ]
store i64 %19, i64* %5
br label %20
20: ; preds = %23, %18
%21 = load i64, i64* %5
%22 = icmp sge i64 %21, 1000000000
br i1 %22, label %23, label %28
23: ; preds = %20
%24 = load i64, i64* %4
%25 = add nsw i64 %24, 1
store i64 %25, i64* %4
%26 = load i64, i64* %5
%27 = sub nsw i64 %26, 1000000000
store i64 %27, i64* %5
br label %20
28: ; preds = %20
%29 = load i64, i64* %4
%30 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i64 %29, i64* %30
%31 = load i64, i64* %5
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i64 %31, i64* %32
%33 = bitcast %struct.timespec* %3 to { i64, i64 }*
%34 = load { i64, i64 }, { i64, i64 }* %33
ret { i64, i64 } %34
}

LLVM IR (-O2):
define { i64, i64 } @tsCreate(i64 %0, i64 %1) {
%3 = icmp sgt i64 %0, 0
%4 = select i1 %3, i64 %0, i64 0
%5 = icmp sgt i64 %1, 0
%6 = select i1 %5, i64 %1, i64 0
%7 = icmp ugt i64 %6, 999999999
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = add nuw i64 %6, 999999999
%10 = call i64 @llvm.smin.i64(i64 %6, i64 1999999999)
%11 = sub nuw i64 %9, %10
%12 = udiv i64 %11, 1000000000
%13 = add nuw i64 %4, %12
%14 = add nuw i64 %13, 1
%15 = mul nsw i64 %12, -1000000000
%16 = add nsw i64 %6, -1000000000
%17 = add nsw i64 %15, %16
br label %18
18: ; preds = %8, %2
%19 = phi i64 [ %4, %2 ], [ %14, %8 ]
%20 = phi i64 [ %6, %2 ], [ %17, %8 ]
%21 = insertvalue { i64, i64 } poison, i64 %19, 0
%22 = insertvalue { i64, i64 } %21, i64 %20, 1
ret { i64, i64 } %22
}