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

/* Variables and functions */
void ts_normalize(struct timespec *const t) {
  if (t->tv_nsec >= 1000000000L || t->tv_nsec <= -1000000000L) {
    t->tv_sec += t->tv_nsec / 1000000000L;
    t->tv_nsec %= 1000000000L;
  }
  if (t->tv_nsec < 0) {
    t->tv_sec -= 1;
    t->tv_nsec += 1000000000L;
  }
}


x86 assembly (clang, -O0):
<ts_normalize>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x3b9aca00,(%rax)
jge    112a <ts_normalize+0x2a>
mov    -0x8(%rbp),%rax
cmpq   $0xffffffffc4653600,(%rax)
jg     1166 <ts_normalize+0x66>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
add    0x8(%rax),%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    (%rax),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    -0x10(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jge    1195 <ts_normalize+0x95>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
sub    $0x1,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x3b9aca00,%rcx
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<ts_normalize>:
mov    (%rdi),%rcx
lea    -0x3b9aca00(%rcx),%rax
cmp    $0xffffffff88ca6c00,%rax
jbe    1118 <ts_normalize+0x18>
test   %rcx,%rcx
js     114c <ts_normalize+0x4c>
ret
movabs $0x112e0be826d694b3,%rdx
0b 2e 11
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1a,%rdx
add    %rax,%rdx
add    %rdx,0x8(%rdi)
imul   $0x3b9aca00,%rdx,%rax
sub    %rax,%rcx
mov    %rcx,(%rdi)
test   %rcx,%rcx
jns    1117 <ts_normalize+0x17>
addq   $0xffffffffffffffff,0x8(%rdi)
add    $0x3b9aca00,%rcx
mov    %rcx,(%rdi)
ret

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

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
define void @ts_normalize(%struct.timespec* nocapture %0) {
%2 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%3 = load i64, i64* %2
%4 = add i64 %3, -1000000000
%5 = icmp ult i64 %4, -1999999999
br i1 %5, label %6, label %12
6: ; preds = %1
%7 = sdiv i64 %3, 1000000000
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%9 = load i64, i64* %8
%10 = add nsw i64 %9, %7
store i64 %10, i64* %8
%11 = srem i64 %3, 1000000000
store i64 %11, i64* %2
br label %12
12: ; preds = %1, %6
%13 = phi i64 [ %3, %1 ], [ %11, %6 ]
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%17 = load i64, i64* %16
%18 = add nsw i64 %17, -1
store i64 %18, i64* %16
%19 = add nsw i64 %13, 1000000000
store i64 %19, i64* %2
br label %20
20: ; preds = %15, %12
ret void
}