#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_nsec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
struct timespec *t2p_normalize_timespec(struct timespec *ts) {
  while (ts->tv_nsec >= 1000000000) {
    ts->tv_nsec -= 1000000000;
    ts->tv_sec++;
  }
  return ts;
}


x86 assembly (clang, -O0):
<t2p_normalize_timespec>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0x3b9aca00,(%rax)
jl     1138 <t2p_normalize_timespec+0x38>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    $0x3b9aca00,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rax)
jmp    1108 <t2p_normalize_timespec+0x8>
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<t2p_normalize_timespec>:
mov    %rdi,%rax
mov    (%rdi),%ecx
cmp    $0x3b9aca00,%ecx
jl     114e <t2p_normalize_timespec+0x4e>
mov    0x4(%rax),%edx
cmp    $0x773593ff,%ecx
mov    $0x773593ff,%esi
cmovl  %ecx,%esi
neg    %esi
add    %ecx,%esi
add    $0x3b9ac9ff,%esi
shr    $0x9,%esi
imul   $0x44b83,%rsi,%rsi
shr    $0x27,%rsi
imul   $0xc4653600,%esi,%edi
add    %edi,%ecx
add    $0xc4653600,%ecx
add    %esi,%edx
add    $0x1,%edx
mov    %ecx,(%rax)
mov    %edx,0x4(%rax)
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define %struct.timespec* @t2p_normalize_timespec(%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 i32, i32* %5
%7 = icmp sge i32 %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 0
%11 = load i32, i32* %10
%12 = sub nsw i32 %11, 1000000000
store i32 %12, i32* %10
%13 = load %struct.timespec*, %struct.timespec** %2
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = add nsw i32 %15, 1
store i32 %16, i32* %14
br label %3
17: ; preds = %3
%18 = load %struct.timespec*, %struct.timespec** %2
ret %struct.timespec* %18
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define %struct.timespec* @t2p_normalize_timespec(%struct.timespec* returned %0) {
%2 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = icmp sgt i32 %3, 999999999
br i1 %4, label %5, label %17
5: ; preds = %1
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%7 = load i32, i32* %6
%8 = add nuw i32 %3, 999999999
%9 = call i32 @llvm.smin.i32(i32 %3, i32 1999999999)
%10 = sub nuw i32 %8, %9
%11 = udiv i32 %10, 1000000000
%12 = mul nsw i32 %11, -1000000000
%13 = add i32 %7, %11
%14 = add nsw i32 %3, -1000000000
%15 = add nsw i32 %12, %14
%16 = add i32 %13, 1
store i32 %15, i32* %2
store i32 %16, i32* %6
br label %17
17: ; preds = %5, %1
ret %struct.timespec* %0
}