#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 tspecNew(long int sec, long int nsec) {
  sec = (sec < 0) ? 0 : sec;
  nsec = (nsec < 0) ? 0 : nsec;
  sec += nsec / 1000000000;
  nsec = nsec % 1000000000;
  struct timespec tspec = {.tv_sec = sec, .tv_nsec = nsec};
  return tspec;
}


x86 assembly (clang, -O0):
<tspecNew>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1122 <tspecNew+0x22>
xor    %eax,%eax
mov    %rax,-0x28(%rbp)
jmp    112a <tspecNew+0x2a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1148 <tspecNew+0x48>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    1150 <tspecNew+0x50>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movabs $0x112e0be826d694b3,%rcx
0b 2e 11
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1a,%rdx
add    %rax,%rdx
mov    -0x18(%rbp),%rax
add    %rdx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
imul   %rcx
mov    -0x38(%rbp),%rax
mov    %rdx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x1a,%rcx
add    %rdx,%rcx
imul   $0x3b9aca00,%rcx,%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
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):
<tspecNew>:
xor    %ecx,%ecx
test   %rdi,%rdi
cmovs  %rcx,%rdi
test   %rsi,%rsi
cmovns %rsi,%rcx
mov    %rcx,%rax
shr    $0x9,%rax
movabs $0x44b82fa09b5a53,%rdx
mul    %rdx
shr    $0xb,%rdx
lea    (%rdi,%rdx,1),%rax
imul   $0x3b9aca00,%rdx,%rdx
sub    %rdx,%rcx
mov    %rcx,%rdx
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
define { i64, i64 } @tspecNew(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
%20 = load i64, i64* %5
%21 = sdiv i64 %20, 1000000000
%22 = load i64, i64* %4
%23 = add nsw i64 %22, %21
store i64 %23, i64* %4
%24 = load i64, i64* %5
%25 = srem i64 %24, 1000000000
store i64 %25, i64* %5
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%27 = load i64, i64* %4
store i64 %27, i64* %26
%28 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%29 = load i64, i64* %5
store i64 %29, i64* %28
%30 = bitcast %struct.timespec* %3 to { i64, i64 }*
%31 = load { i64, i64 }, { i64, i64 }* %30
ret { i64, i64 } %31
}

LLVM IR (-O2):
define { i64, i64 } @tspecNew(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 = udiv i64 %6, 1000000000
%8 = add nuw nsw i64 %7, %4
%9 = urem i64 %6, 1000000000
%10 = insertvalue { i64, i64 } poison, i64 %8, 0
%11 = insertvalue { i64, i64 } %10, i64 %9, 1
ret { i64, i64 } %11
}