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


x86 assembly (clang, -O0):
<timeval_add>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
add    (%rcx),%rax
mov    %rax,-0x20(%rbp)
cmp    $0xf4240,%rax
jge    1156 <timeval_add+0x56>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%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)
jmp    1184 <timeval_add+0x84>
mov    -0x20(%rbp),%rcx
sub    $0xf4240,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
add    0x8(%rax),%rcx
add    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_add>:
mov    (%rsi),%rax
add    (%rdi),%rax
cmp    $0xf423f,%rax
jg     1118 <timeval_add+0x18>
mov    0x8(%rsi),%rcx
add    0x8(%rdi),%rcx
jmp    112d <timeval_add+0x2d>
add    $0xfffffffffff0bdc0,%rax
mov    0x8(%rdi),%rcx
mov    0x8(%rsi),%rsi
add    %rsi,%rcx
add    $0x1,%rcx
mov    %rax,(%rdx)
mov    %rcx,0x8(%rdx)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @timeval_add(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1, %struct.timeval* nocapture writeonly %2) {
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%5 = load i64, i64* %4
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%7 = load i64, i64* %6
%8 = add nsw i64 %7, %5
%9 = icmp slt i64 %8, 1000000
br i1 %9, label %10, label %16
10: ; preds = %3
%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
br label %24
16: ; preds = %3
%17 = add nsw i64 %8, -1000000
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%19 = load i64, i64* %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%21 = load i64, i64* %20
%22 = add i64 %19, 1
%23 = add i64 %22, %21
br label %24
24: ; preds = %16, %10
%25 = phi i64 [ %8, %10 ], [ %17, %16 ]
%26 = phi i64 [ %15, %10 ], [ %23, %16 ]
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i64 %25, i64* %27
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i64 %26, i64* %28
ret void
}