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

/* Variables and functions */
struct timeval tvAdd(struct timeval time1, struct timeval time2) {
  struct timeval result;
  result.tv_sec = time1.tv_sec + time2.tv_sec;
  result.tv_usec = time1.tv_usec + time2.tv_usec;
  if (result.tv_usec >= 1000000L) {
    result.tv_sec++;
    result.tv_usec = result.tv_usec - 1000000L;
  }
  return (result);
}


x86 assembly (clang, -O0):
<tvAdd>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x20(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x30(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0xf4240,-0x10(%rbp)
jl     1154 <tvAdd+0x54>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
sub    $0xf4240,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rdx
pop    %rbp
ret

x86 assembly (clang, -O2):
<tvAdd>:
lea    (%rsi,%rcx,1),%r8
lea    (%rdx,%rdi,1),%rsi
xor    %ecx,%ecx
cmp    $0xf4240,%rsi
setge  %cl
lea    -0xf4240(%rdx,%rdi,1),%rax
ff
cmovl  %rsi,%rax
add    %r8,%rcx
mov    %rcx,%rdx
ret

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

LLVM IR (-O2):
define { i64, i64 } @tvAdd(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = add nsw i64 %3, %1
%6 = add nsw i64 %2, %0
%7 = icmp sgt i64 %6, 999999
%8 = add nsw i64 %6, -1000000
%9 = select i1 %7, i64 %8, i64 %6
%10 = zext i1 %7 to i64
%11 = add nsw i64 %5, %10
%12 = insertvalue { i64, i64 } poison, i64 %9, 0
%13 = insertvalue { i64, i64 } %12, i64 %11, 1
ret { i64, i64 } %13
}