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

/* Variables and functions */
struct timeval *t2p_normalize_timeval(struct timeval *tv) {
  while (tv->tv_usec >= 1000000) {
    tv->tv_usec -= 1000000;
    tv->tv_sec++;
  }
  return tv;
}


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

x86 assembly (clang, -O2):
<t2p_normalize_timeval>:
mov    %rdi,%rax
mov    (%rdi),%ecx
cmp    $0xf4240,%ecx
jl     114b <t2p_normalize_timeval+0x4b>
mov    0x4(%rax),%edx
cmp    $0x1e847f,%ecx
mov    $0x1e847f,%esi
cmovl  %ecx,%esi
neg    %esi
add    %ecx,%esi
add    $0xf423f,%esi
imul   $0x431bde83,%rsi,%rsi
shr    $0x32,%rsi
imul   $0xfff0bdc0,%esi,%edi
add    %edi,%ecx
add    $0xfff0bdc0,%ecx
add    %esi,%edx
add    $0x1,%edx
mov    %ecx,(%rax)
mov    %edx,0x4(%rax)
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define %struct.timeval* @t2p_normalize_timeval(%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 i32, i32* %5
%7 = icmp sge i32 %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 0
%11 = load i32, i32* %10
%12 = sub nsw i32 %11, 1000000
store i32 %12, i32* %10
%13 = load %struct.timeval*, %struct.timeval** %2
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %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.timeval*, %struct.timeval** %2
ret %struct.timeval* %18
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define %struct.timeval* @t2p_normalize_timeval(%struct.timeval* returned %0) {
%2 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = icmp sgt i32 %3, 999999
br i1 %4, label %5, label %17
5: ; preds = %1
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%7 = load i32, i32* %6
%8 = add nuw i32 %3, 999999
%9 = call i32 @llvm.smin.i32(i32 %3, i32 1999999)
%10 = sub nuw i32 %8, %9
%11 = udiv i32 %10, 1000000
%12 = mul nsw i32 %11, -1000000
%13 = add i32 %7, %11
%14 = add nsw i32 %3, -1000000
%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.timeval* %0
}