#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*/ assert(struct timeval *);
void timeval_add(struct timeval *a, struct timeval *b, struct timeval *result) {
  assert(a);
  assert(b);
  assert(result);
  result->tv_sec = a->tv_sec + b->tv_sec;
  result->tv_usec = a->tv_usec + b->tv_usec;
  if (result->tv_usec >= 1000000) {
    result->tv_sec++;
    result->tv_usec -= 1000000;
  }
}


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

x86 assembly (clang, -O2):
<timeval_add>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
call   1030 <assert@plt>
mov    %rbx,%rdi
call   1030 <assert@plt>
mov    %r14,%rdi
call   1030 <assert@plt>
mov    0x8(%rbx),%rax
add    0x8(%r15),%rax
mov    %rax,0x8(%r14)
mov    (%rbx),%ecx
add    (%r15),%ecx
mov    %ecx,(%r14)
cmp    $0xf4240,%ecx
jl     1160 <timeval_add+0x50>
add    $0x1,%rax
mov    %rax,0x8(%r14)
add    $0xfff0bdc0,%ecx
mov    %ecx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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