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

/* Variables and functions */
void ts_normalize(struct timespec *t) {
  while (t->tv_nsec >= 1000000000UL) {
    t->tv_sec++;
    t->tv_nsec -= 1000000000UL;
  }
  if ((t->tv_sec >= 1) && (t->tv_nsec < 0)) {
    t->tv_sec--;
    t->tv_nsec += 1000000000UL;
  }
}


x86 assembly (clang, -O0):
<ts_normalize>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x3b9aca00,(%rax)
jb     113c <ts_normalize+0x3c>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
sub    $0x3b9aca00,%rcx
mov    %rcx,(%rax)
jmp    1108 <ts_normalize+0x8>
mov    -0x8(%rbp),%rax
cmpl   $0x1,0x8(%rax)
jl     1176 <ts_normalize+0x76>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jae    1176 <ts_normalize+0x76>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,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
cmp    $0x3b9aca00,%rcx
jb     1146 <ts_normalize+0x46>
mov    0x8(%rdi),%esi
lea    -0x3b9aca00(%rcx),%rax
shr    $0x9,%rax
movabs $0x44b82fa09b5a53,%rdx
mul    %rdx
shr    $0xb,%rdx
imul   $0xffffffffc4653600,%rdx,%rax
add    %esi,%edx
add    $0x1,%edx
add    %rcx,%rax
add    $0xffffffffc4653600,%rax
mov    %edx,0x8(%rdi)
mov    %rax,(%rdi)
ret

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

LLVM IR (-O2):
%struct.timespec = type { i64, i32 }
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 = icmp ugt i64 %3, 999999999
br i1 %4, label %5, label %15
5: ; preds = %1
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%7 = load i32, i32* %6
%8 = add i64 %3, -1000000000
%9 = udiv i64 %8, 1000000000
%10 = trunc i64 %9 to i32
%11 = add i32 %7, %10
%12 = mul i64 %9, -1000000000
%13 = add i32 %11, 1
%14 = add i64 %12, %8
store i32 %13, i32* %6
store i64 %14, i64* %2
br label %15
15: ; preds = %5, %1
ret void
}