#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 tv_add(struct timeval t1, struct timeval t2) {
  struct timeval t;
  t.tv_sec = t1.tv_sec + t2.tv_sec;
  t.tv_usec = t1.tv_usec + t2.tv_usec;
  if (t.tv_usec >= 1E6L) {
    t.tv_sec++;
    t.tv_usec -= 1E6L;
  }
  return t;
}


x86 assembly (clang, -O0):
<tv_add>:
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
mov    -0x28(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
fildll -0x38(%rbp)
flds   0xebd(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jb     1194 <tv_add+0x94>
jmp    1154 <tv_add+0x54>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
fildll -0x48(%rbp)
flds   0xe93(%rip)
faddp  %st,%st(1)
fnstcw -0x4a(%rbp)
movzwl -0x4a(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x4c(%rbp)
fldcw  -0x4c(%rbp)
fistpll -0x40(%rbp)
fldcw  -0x4a(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rdx
pop    %rbp
ret

x86 assembly (clang, -O2):
<tv_add>:
mov    %rdi,%rax
add    %rdx,%rax
mov    %rax,-0x10(%rsp)
fildll -0x10(%rsp)
fadds  0xeeb(%rip)
fnstcw -0x14(%rsp)
movzwl -0x14(%rsp),%edx
or     $0xc00,%edx
mov    %dx,-0x12(%rsp)
fldcw  -0x12(%rsp)
mov    %rsi,%rdx
fistpll -0x8(%rsp)
fldcw  -0x14(%rsp)
add    %rcx,%rdx
xor    %ecx,%ecx
cmp    $0xf4240,%rax
setge  %sil
jl     114e <tv_add+0x4e>
mov    -0x8(%rsp),%rax
mov    %sil,%cl
add    %rcx,%rdx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define { i64, i64 } @tv_add(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 = sitofp i64 %27 to x86_fp80
%29 = fcmp oge x86_fp80 %28, 0xK4012F424000000000000
br i1 %29, label %30, label %39
30: ; preds = %4
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%32 = load i64, i64* %31
%33 = add nsw i64 %32, 1
store i64 %33, i64* %31
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%35 = load i64, i64* %34
%36 = sitofp i64 %35 to x86_fp80
%37 = fsub x86_fp80 %36, 0xK4012F424000000000000
%38 = fptosi x86_fp80 %37 to i64
store i64 %38, i64* %34
br label %39
39: ; preds = %30, %4
%40 = bitcast %struct.timeval* %5 to { i64, i64 }*
%41 = load { i64, i64 }, { i64, i64 }* %40
ret { i64, i64 } %41
}

LLVM IR (-O2):
define { i64, i64 } @tv_add(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 = sitofp i64 %6 to x86_fp80
%9 = fadd x86_fp80 %8, 0xKC012F424000000000000
%10 = fptosi x86_fp80 %9 to i64
%11 = select i1 %7, i64 %10, i64 %6
%12 = zext i1 %7 to i64
%13 = add nsw i64 %5, %12
%14 = insertvalue { i64, i64 } poison, i64 %11, 0
%15 = insertvalue { i64, i64 } %14, i64 %13, 1
ret { i64, i64 } %15
}