#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 */
int addTimeValue(struct timeval *timeR, struct timeval timeA,
                 struct timeval timeB) {
  if (timeA.tv_usec + timeB.tv_usec >= 1000000) {
    timeR->tv_usec = timeA.tv_usec + timeB.tv_usec - 1000000;
    timeR->tv_sec = timeA.tv_sec + timeB.tv_sec + 1;
  } else {
    timeR->tv_usec = timeA.tv_usec + timeB.tv_usec;
    timeR->tv_sec = timeA.tv_sec + timeB.tv_sec;
  }
  return 0;
}


x86 assembly (clang, -O0):
<addTimeValue>:
push   %rbp
mov    %rsp,%rbp
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x8(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8,-0x18(%rbp)
mov    %rdi,-0x28(%rbp)
mov    -0x10(%rbp),%eax
add    -0x20(%rbp),%eax
cmp    $0xf4240,%eax
jl     1152 <addTimeValue+0x52>
mov    -0x10(%rbp),%ecx
add    -0x20(%rbp),%ecx
sub    $0xf4240,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rcx
add    -0x18(%rbp),%rcx
add    $0x1,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x8(%rax)
jmp    116e <addTimeValue+0x6e>
mov    -0x10(%rbp),%ecx
add    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rcx
add    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x8(%rax)
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<addTimeValue>:
lea    (%rcx,%rsi,1),%eax
lea    (%r8,%rdx,1),%r9
cmp    $0xf4240,%eax
lea    -0xf4240(%rcx,%rsi,1),%ecx
lea    0x1(%r8,%rdx,1),%rdx
cmovl  %eax,%ecx
cmovl  %r9,%rdx
mov    %ecx,(%rdi)
mov    %rdx,0x8(%rdi)
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define i32 @addTimeValue(%struct.timeval* %0, i32 %1, i64 %2, i32 %3, i64 %4) {
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = alloca %struct.timeval*
%9 = bitcast %struct.timeval* %6 to { i32, i64 }*
%10 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %9, i32 0, i32 0
store i32 %1, i32* %10
%11 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %9, i32 0, i32 1
store i64 %2, i64* %11
%12 = bitcast %struct.timeval* %7 to { i32, i64 }*
%13 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %12, i32 0, i32 0
store i32 %3, i32* %13
%14 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %12, i32 0, i32 1
store i64 %4, i64* %14
store %struct.timeval* %0, %struct.timeval** %8
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%18 = load i32, i32* %17
%19 = add nsw i32 %16, %18
%20 = icmp sge i32 %19, 1000000
br i1 %20, label %21, label %38
21: ; preds = %5
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%25 = load i32, i32* %24
%26 = add nsw i32 %23, %25
%27 = sub nsw i32 %26, 1000000
%28 = load %struct.timeval*, %struct.timeval** %8
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%31 = load i64, i64* %30
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%33 = load i64, i64* %32
%34 = add nsw i64 %31, %33
%35 = add nsw i64 %34, 1
%36 = load %struct.timeval*, %struct.timeval** %8
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %36, i32 0, i32 1
store i64 %35, i64* %37
br label %53
38: ; preds = %5
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%42 = load i32, i32* %41
%43 = add nsw i32 %40, %42
%44 = load %struct.timeval*, %struct.timeval** %8
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %44, i32 0, i32 0
store i32 %43, i32* %45
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%47 = load i64, i64* %46
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%49 = load i64, i64* %48
%50 = add nsw i64 %47, %49
%51 = load %struct.timeval*, %struct.timeval** %8
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %51, i32 0, i32 1
store i64 %50, i64* %52
br label %53
53: ; preds = %38, %21
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define i32 @addTimeValue(%struct.timeval* nocapture writeonly %0, i32 %1, i64 %2, i32 %3, i64 %4) {
%6 = add nsw i32 %3, %1
%7 = icmp sgt i32 %6, 999999
%8 = add nsw i32 %6, -1000000
%9 = add nsw i64 %4, %2
%10 = add nsw i64 %9, 1
%11 = add nsw i64 %4, %2
%12 = select i1 %7, i32 %8, i32 %6
%13 = select i1 %7, i64 %10, i64 %11
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
store i32 %12, i32* %14
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
store i64 %13, i64* %15
ret i32 0
}