#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 */
void tvadd(struct timeval *t1, struct timeval *t2, struct timeval *r) {
  long u;
  r->tv_sec = t1->tv_sec + t2->tv_sec;
  u = t1->tv_usec + t2->tv_usec;
  if (u >= 1000000) {
    u -= 1000000;
    ++r->tv_sec;
  }
  r->tv_usec = u;
}


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

x86 assembly (clang, -O2):
<tvadd>:
mov    0x8(%rsi),%rcx
add    0x8(%rdi),%rcx
mov    %rcx,0x8(%rdx)
mov    (%rsi),%rax
add    (%rdi),%rax
cmp    $0xf4240,%rax
jl     1128 <tvadd+0x28>
add    $0xfffffffffff0bdc0,%rax
add    $0x1,%rcx
mov    %rcx,0x8(%rdx)
mov    %rax,(%rdx)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @tvadd(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1, %struct.timeval* nocapture writeonly %2) {
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%5 = load i64, i64* %4
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%7 = load i64, i64* %6
%8 = add nsw i64 %7, %5
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i64 %8, i64* %9
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%13 = load i64, i64* %12
%14 = add nsw i64 %13, %11
%15 = icmp sgt i64 %14, 999999
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = add nsw i64 %14, -1000000
%18 = add nsw i64 %8, 1
store i64 %18, i64* %9
br label %19
19: ; preds = %16, %3
%20 = phi i64 [ %17, %16 ], [ %14, %3 ]
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i64 %20, i64* %21
ret void
}