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

/* Variables and functions */
void timeval_normalize(struct timeval *tv) {
  while (tv->tv_usec >= (1000000L)) {
    tv->tv_sec++;
    tv->tv_usec -= (1000000L);
  }
  while (tv->tv_usec < 0) {
    tv->tv_sec--;
    tv->tv_usec += (1000000L);
  }
}


x86 assembly (clang, -O0):
<timeval_normalize>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0xf4240,(%rax)
jl     113c <timeval_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    $0xf4240,%rcx
mov    %rcx,(%rax)
jmp    1108 <timeval_normalize+0x8>
jmp    1141 <timeval_normalize+0x41>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jge    1172 <timeval_normalize+0x72>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,(%rax)
jmp    1141 <timeval_normalize+0x41>
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_normalize>:
mov    (%rdi),%rcx
cmp    $0xf4240,%rcx
jge    1112 <timeval_normalize+0x12>
test   %rcx,%rcx
js     1164 <timeval_normalize+0x64>
ret
cmp    $0x1e847f,%rcx
mov    $0x1e847f,%eax
cmovl  %rcx,%rax
mov    0x8(%rdi),%esi
neg    %rax
add    %rcx,%rax
add    $0xf423f,%rax
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mul    %rdx
shr    $0x12,%rdx
lea    (%rsi,%rdx,1),%eax
add    $0x1,%eax
imul   $0xfffffffffff0bdc0,%rdx,%rdx
add    %rdx,%rcx
add    $0xfffffffffff0bdc0,%rcx
mov    %eax,0x8(%rdi)
mov    %rcx,(%rdi)
test   %rcx,%rcx
jns    1111 <timeval_normalize+0x11>
cmp    $0xfffffffffff0bdc1,%rcx
mov    $0xfffffffffff0bdc0,%rax
cmovge %rcx,%rax
xor    %esi,%esi
sub    %rcx,%rax
setne  %sil
sub    %rsi,%rax
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mul    %rdx
shr    $0x12,%rdx
add    %rsi,%rdx
imul   $0xf4240,%rdx,%rax
not    %edx
add    %rcx,%rax
add    $0xf4240,%rax
add    %edx,0x8(%rdi)
mov    %rax,(%rdi)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
define void @timeval_normalize(%struct.timeval* nocapture %0) {
%2 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%3 = load i64, i64* %2
%4 = icmp sgt i64 %3, 999999
br i1 %4, label %5, label %18
5: ; preds = %1
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%7 = load i32, i32* %6
%8 = add nuw i64 %3, 999999
%9 = call i64 @llvm.smin.i64(i64 %3, i64 1999999)
%10 = sub nuw i64 %8, %9
%11 = udiv i64 %10, 1000000
%12 = trunc i64 %11 to i32
%13 = add i32 %7, %12
%14 = add i32 %13, 1
%15 = mul nsw i64 %11, -1000000
%16 = add nsw i64 %3, -1000000
%17 = add nsw i64 %15, %16
store i32 %14, i32* %6
store i64 %17, i64* %2
br label %18
18: ; preds = %5, %1
%19 = phi i64 [ %17, %5 ], [ %3, %1 ]
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %37
21: ; preds = %18
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%23 = load i32, i32* %22
%24 = call i64 @llvm.smax.i64(i64 %19, i64 -1000000)
%25 = sub nsw i64 %24, %19
%26 = icmp ne i64 %25, 0
%27 = zext i1 %26 to i64
%28 = sub nsw i64 %25, %27
%29 = udiv i64 %28, 1000000
%30 = add nuw nsw i64 %29, %27
%31 = trunc i64 %30 to i32
%32 = mul i64 %30, 1000000
%33 = add i64 %19, %32
%34 = xor i32 %31, -1
%35 = add i32 %23, %34
%36 = add i64 %33, 1000000
store i32 %35, i32* %22
store i64 %36, i64* %2
br label %37
37: ; preds = %21, %18
ret void
}