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

/* Variables and functions */
void tsnorm(struct timespec *ts) {
  while (ts->tv_nsec >= 1E9L) {
    ts->tv_nsec -= 1E9L;
    ts->tv_sec++;
  }
}


x86 assembly (clang, -O0):
<tsnorm>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
fildll -0x10(%rbp)
flds   0xee4(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jb     1176 <tsnorm+0x76>
jmp    112d <tsnorm+0x2d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    %rcx,-0x20(%rbp)
fildll -0x20(%rbp)
flds   0xec3(%rip)
faddp  %st,%st(1)
fnstcw -0x22(%rbp)
movzwl -0x22(%rbp),%ecx
or     $0xc00,%ecx
mov    %cx,-0x24(%rbp)
fldcw  -0x24(%rbp)
fistpll -0x18(%rbp)
fldcw  -0x22(%rbp)
mov    -0x18(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x8(%rax)
jmp    1108 <tsnorm+0x8>
pop    %rbp
ret

x86 assembly (clang, -O2):
<tsnorm>:
mov    (%rdi),%rcx
cmp    $0x3b9aca00,%rcx
jl     1156 <tsnorm+0x56>
mov    0x8(%rdi),%eax
nop
mov    %rcx,-0x10(%rsp)
fildll -0x10(%rsp)
fadds  0xee1(%rip)
fnstcw -0x14(%rsp)
movzwl -0x14(%rsp),%ecx
or     $0xc00,%ecx
mov    %cx,-0x12(%rsp)
fldcw  -0x12(%rsp)
fistpll -0x8(%rsp)
fldcw  -0x14(%rsp)
mov    -0x8(%rsp),%rcx
add    $0x1,%eax
cmp    $0x3b9ac9ff,%rcx
jg     1110 <tsnorm+0x10>
mov    %rcx,(%rdi)
mov    %eax,0x8(%rdi)
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i32 }
define void @tsnorm(%struct.timespec* %0) {
%2 = alloca %struct.timespec*
store %struct.timespec* %0, %struct.timespec** %2
br label %3
3: ; preds = %9, %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 = sitofp i64 %6 to x86_fp80
%8 = fcmp oge x86_fp80 %7, 0xK401CEE6B280000000000
br i1 %8, label %9, label %20
9: ; preds = %3
%10 = load %struct.timespec*, %struct.timespec** %2
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = sitofp i64 %12 to x86_fp80
%14 = fsub x86_fp80 %13, 0xK401CEE6B280000000000
%15 = fptosi x86_fp80 %14 to i64
store i64 %15, i64* %11
%16 = load %struct.timespec*, %struct.timespec** %2
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %17
br label %3
20: ; preds = %3
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i32 }
define void @tsnorm(%struct.timespec* nocapture %0) {
%2 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%3 = load i64, i64* %2
%4 = icmp sgt i64 %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
br label %8
8: ; preds = %5, %8
%9 = phi i32 [ %7, %5 ], [ %14, %8 ]
%10 = phi i64 [ %3, %5 ], [ %13, %8 ]
%11 = sitofp i64 %10 to x86_fp80
%12 = fadd x86_fp80 %11, 0xKC01CEE6B280000000000
%13 = fptosi x86_fp80 %12 to i64
%14 = add nsw i32 %9, 1
%15 = icmp sgt i64 %13, 999999999
br i1 %15, label %8, label %16
16: ; preds = %8
store i64 %13, i64* %2
store i32 %14, i32* %6
br label %17
17: ; preds = %16, %1
ret void
}