#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;
  scalar_t__ tv_sec;
};

/* Variables and functions */
void timeval_norm(struct timeval *tv) {
  if (tv->tv_usec >= 1000000 || tv->tv_usec < 0) {
    tv->tv_sec += tv->tv_usec / 1000000;
    tv->tv_usec %= 1000000;
  }
  if (tv->tv_usec < 0) {
    tv->tv_sec--;
    tv->tv_usec += 1000000;
  }
}


x86 assembly (clang, -O0):
<timeval_norm>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpl   $0xf4240,(%rax)
jge    1125 <timeval_norm+0x25>
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jge    115a <timeval_norm+0x5a>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
movslq %eax,%rcx
mov    -0x8(%rbp),%rax
add    0x8(%rax),%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    (%rax),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    -0x10(%rbp),%rax
mov    %edx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jge    1185 <timeval_norm+0x85>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0xf4240,%ecx
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_norm>:
mov    (%rdi),%eax
cmp    $0xf4240,%eax
jb     113a <timeval_norm+0x3a>
movslq %eax,%rcx
imul   $0x431bde83,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
movslq %ecx,%rdx
mov    0x8(%rdi),%rcx
add    %rdx,%rcx
mov    %rcx,0x8(%rdi)
imul   $0xf4240,%edx,%edx
sub    %edx,%eax
mov    %eax,(%rdi)
js     113b <timeval_norm+0x3b>
ret
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rdi)
add    $0xf4240,%eax
mov    %eax,(%rdi)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define void @timeval_norm(%struct.timeval* nocapture %0) {
%2 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = icmp ugt i32 %3, 999999
br i1 %4, label %5, label %16
5: ; preds = %1
%6 = sdiv i32 %3, 1000000
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%9 = load i64, i64* %8
%10 = add nsw i64 %9, %7
store i64 %10, i64* %8
%11 = srem i32 %3, 1000000
store i32 %11, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %5
%14 = add nsw i64 %10, -1
store i64 %14, i64* %8
%15 = add nsw i32 %11, 1000000
store i32 %15, i32* %2
br label %16
16: ; preds = %1, %13, %5
ret void
}