#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 */
struct timeval timeval_add(struct timeval *a, struct timeval *b) {
  struct timeval 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 += 1;
    result.tv_usec -= 1000000;
  }
  return result;
}


x86 assembly (clang, -O0):
<timeval_add>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x20(%rbp),%rcx
add    0x8(%rcx),%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x20(%rbp),%rcx
add    (%rcx),%eax
mov    %eax,-0x10(%rbp)
cmpl   $0xf4240,-0x10(%rbp)
jl     1153 <timeval_add+0x53>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
sub    $0xf4240,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%rdx
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_add>:
mov    0x8(%rsi),%rcx
add    0x8(%rdi),%rcx
mov    (%rdi),%eax
mov    (%rsi),%esi
lea    (%rsi,%rax,1),%edi
xor    %edx,%edx
cmp    $0xf4240,%edi
setge  %dl
lea    -0xf4240(%rsi,%rax,1),%eax
cmovl  %edi,%eax
add    %rcx,%rdx
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define { i32, i64 } @timeval_add(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%6 = load i64, i64* %5
%7 = add nsw i64 %6, %4
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%11 = load i32, i32* %10
%12 = add nsw i32 %11, %9
%13 = icmp sgt i32 %12, 999999
%14 = add nsw i32 %12, -1000000
%15 = select i1 %13, i32 %14, i32 %12
%16 = zext i1 %13 to i64
%17 = add nsw i64 %7, %16
%18 = insertvalue { i32, i64 } poison, i32 %15, 0
%19 = insertvalue { i32, i64 } %18, i64 %17, 1
ret { i32, i64 } %19
}