#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 *tvadd(struct timeval *a, struct timeval *b) {
  a->tv_sec += b->tv_sec;
  if (a->tv_usec + b->tv_usec >= 1000000) {
    a->tv_sec++;
    a->tv_usec = a->tv_usec + b->tv_usec - 1000000;
  } else {
    a->tv_usec = a->tv_usec + b->tv_usec;
  }
  return a;
}


x86 assembly (clang, -O0):
<tvadd>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
add    0x8(%rax),%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
add    (%rcx),%eax
cmp    $0xf4240,%eax
jl     1164 <tvadd+0x64>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
sub    $0xf4240,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    1176 <tvadd+0x76>
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<tvadd>:
mov    %rdi,%rax
mov    0x8(%rdi),%rdx
add    0x8(%rsi),%rdx
mov    %rdx,0x8(%rdi)
mov    (%rsi),%ecx
add    (%rdi),%ecx
cmp    $0xf4240,%ecx
jl     1129 <tvadd+0x29>
add    $0x1,%rdx
mov    %rdx,0x8(%rax)
add    $0xfff0bdc0,%ecx
mov    %ecx,(%rax)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define %struct.timeval* @tvadd(%struct.timeval* returned %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%6 = load i64, i64* %5
%7 = add nsw i64 %6, %4
store i64 %7, i64* %5
%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
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = add nsw i64 %7, 1
store i64 %15, i64* %5
%16 = add nsw i32 %12, -1000000
br label %17
17: ; preds = %2, %14
%18 = phi i32 [ %16, %14 ], [ %12, %2 ]
store i32 %18, i32* %8
ret %struct.timeval* %0
}