#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 NormalizeTime(struct timeval *tv) {
  tv->tv_sec += tv->tv_usec / 1000000;
  tv->tv_usec %= 1000000;
  if (tv->tv_usec < 0) {
    tv->tv_usec += 1000000;
    --tv->tv_sec;
  }
}


x86 assembly (clang, -O0):
<NormalizeTime>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
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    1168 <NormalizeTime+0x68>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0xf4240,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<NormalizeTime>:
movslq (%rdi),%rax
imul   $0x431bde83,%rax,%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     1132 <NormalizeTime+0x32>
ret
add    $0xf4240,%eax
mov    %eax,(%rdi)
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rdi)
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define void @NormalizeTime(%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 = sdiv i32 %5, 1000000
%7 = sext i32 %6 to i64
%8 = load %struct.timeval*, %struct.timeval** %2
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%10 = load i64, i64* %9
%11 = add nsw i64 %10, %7
store i64 %11, i64* %9
%12 = load %struct.timeval*, %struct.timeval** %2
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = srem i32 %14, 1000000
store i32 %15, i32* %13
%16 = load %struct.timeval*, %struct.timeval** %2
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %1
%21 = load %struct.timeval*, %struct.timeval** %2
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1000000
store i32 %24, i32* %22
%25 = load %struct.timeval*, %struct.timeval** %2
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %25, i32 0, i32 1
%27 = load i64, i64* %26
%28 = add nsw i64 %27, -1
store i64 %28, i64* %26
br label %29
29: ; preds = %20, %1
ret void
}

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