#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 /*<<< orphan*/ timer_reset(struct timeval *);
void timer_add(const struct timeval *timer_a, const struct timeval *timer_b,
               struct timeval *ret) {
  timer_reset(ret);
  ret->tv_usec = timer_a->tv_usec + timer_b->tv_usec;
  ret->tv_sec = timer_a->tv_sec + timer_b->tv_sec;
  if (ret->tv_usec >= 1000000) {
    ret->tv_usec -= 1000000;
    ret->tv_sec += 1;
  }
}


x86 assembly (clang, -O0):
<timer_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <timer_reset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
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    -0x18(%rbp),%rax
cmpl   $0xf4240,(%rax)
jl     1185 <timer_add+0x75>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    $0xf4240,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_add>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1030 <timer_reset@plt>
mov    (%r14),%eax
add    (%r15),%eax
mov    %eax,(%rbx)
mov    0x8(%r14),%rcx
add    0x8(%r15),%rcx
mov    %rcx,0x8(%rbx)
cmp    $0xf4240,%eax
jl     1150 <timer_add+0x40>
add    $0xfff0bdc0,%eax
mov    %eax,(%rbx)
add    $0x1,%rcx
mov    %rcx,0x8(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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