#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;
};
typedef int int32_t;

/* Variables and functions */
struct timeval tv_add(struct timeval *t0, struct timeval *t1) {
  struct timeval tv;
  int32_t t0_us = t0->tv_usec;
  int32_t t1_us = t1->tv_usec;
  int32_t tr_us;
  tv.tv_sec = t1->tv_sec + t0->tv_sec;
  tr_us = t1_us + t0_us;
  if (tr_us >= 1000000) {
    tv.tv_sec++;
    tv.tv_usec = tr_us - 1000000l;
  } else
    tv.tv_usec = tr_us;
  return tv;
}


x86 assembly (clang, -O0):
<tv_add>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x18(%rbp),%rcx
add    0x8(%rcx),%rax
mov    %rax,-0x8(%rbp)
mov    -0x28(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0xf4240,-0x2c(%rbp)
jl     1166 <tv_add+0x66>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
movslq -0x2c(%rbp),%rax
sub    $0xf4240,%rax
mov    %eax,-0x10(%rbp)
jmp    116c <tv_add+0x6c>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%rdx
pop    %rbp
ret

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

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

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