#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 */
__attribute__((unused)) int timeval_add(struct timeval *result,
                                        const struct timeval *x,
                                        const struct timeval *y) {
  result->tv_sec = x->tv_sec + y->tv_sec;
  result->tv_usec = x->tv_usec + y->tv_usec;
  while (result->tv_usec > 1000000) {
    result->tv_usec -= 1000000;
    result->tv_sec++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<timeval_add>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
add    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
add    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0xf4240,(%rax)
jle    116d <timeval_add+0x6d>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    $0xf4240,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rax)
jmp    113a <timeval_add+0x3a>
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_add>:
mov    0x8(%rdx),%rax
add    0x8(%rsi),%rax
mov    %rax,0x8(%rdi)
mov    (%rdx),%ecx
add    (%rsi),%ecx
mov    %ecx,(%rdi)
cmp    $0xf4241,%ecx
jl     1165 <timeval_add+0x65>
cmp    $0x1e8480,%ecx
mov    $0x1e8480,%edx
cmovl  %ecx,%edx
neg    %edx
lea    (%rcx,%rdx,1),%r9d
add    $0xf423f,%r9d
imul   $0x431bde83,%r9,%rsi
shr    $0x32,%rsi
imul   $0xf4240,%esi,%r8d
mov    %r9d,%edx
sub    %r8d,%edx
sub    %r9d,%edx
add    %edx,%ecx
add    $0xfff0bdc0,%ecx
add    %rsi,%rax
add    $0x1,%rax
mov    %ecx,(%rdi)
mov    %rax,0x8(%rdi)
xor    %eax,%eax
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define i32 @timeval_add(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1, %struct.timeval* nocapture %2) {
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%5 = load i64, i64* %4
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%7 = load i64, i64* %6
%8 = add nsw i64 %7, %5
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
store i64 %8, i64* %9
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%13 = load i32, i32* %12
%14 = add i32 %13, %11
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
store i32 %14, i32* %15
%16 = icmp sgt i32 %14, 1000000
br i1 %16, label %17, label %29
17: ; preds = %3
%18 = add nuw i32 %14, 999999
%19 = call i32 @llvm.smin.i32(i32 %14, i32 2000000)
%20 = sub nuw i32 %18, %19
%21 = urem i32 %20, 1000000
%22 = sub nsw i32 %21, %20
%23 = udiv i32 %20, 1000000
%24 = zext i32 %23 to i64
%25 = add i64 %8, %24
%26 = add nsw i32 %14, -1000000
%27 = add nsw i32 %22, %26
%28 = add i64 %25, 1
store i32 %27, i32* %15
store i64 %28, i64* %9
br label %29
29: ; preds = %17, %3
ret i32 0
}