#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 */
void timevaladd(struct timeval *tv1, struct timeval *tv2) {
  tv1->tv_sec += tv2->tv_sec;
  tv1->tv_usec += tv2->tv_usec;
  if (tv1->tv_usec >= 1000000) {
    tv1->tv_sec++;
    tv1->tv_usec -= 1000000;
  }
  if (tv1->tv_usec < 0) {
    tv1->tv_sec--;
    tv1->tv_usec += 1000000;
  }
}


x86 assembly (clang, -O0):
<timevaladd>:
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    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0xf4240,(%rax)
jl     115c <timevaladd+0x5c>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    $0xf4240,%ecx
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
cmpl   $0x0,(%rax)
jge    1187 <timevaladd+0x87>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
add    $0xf4240,%ecx
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timevaladd>:
mov    0x8(%rdi),%rax
add    0x8(%rsi),%rax
mov    %rax,0x8(%rdi)
mov    (%rdi),%ecx
add    (%rsi),%ecx
mov    %ecx,(%rdi)
cmp    $0xf423f,%ecx
jle    1126 <timevaladd+0x26>
mov    $0xfff0bdc0,%edx
mov    $0x1,%esi
jmp    1137 <timevaladd+0x37>
test   %ecx,%ecx
js     112b <timevaladd+0x2b>
ret
mov    $0xf4240,%edx
mov    $0xffffffffffffffff,%rsi
add    %rsi,%rax
mov    %rax,0x8(%rdi)
add    %edx,%ecx
mov    %ecx,(%rdi)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define void @timevaladd(%struct.timeval* nocapture %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* %1, i64 0, i32 0
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%11 = load i32, i32* %10
%12 = add nsw i32 %11, %9
store i32 %12, i32* %10
%13 = icmp sgt i32 %12, 999999
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = icmp slt i32 %12, 0
br i1 %15, label %16, label %21
16: ; preds = %14, %2
%17 = phi i64 [ 1, %2 ], [ -1, %14 ]
%18 = phi i32 [ -1000000, %2 ], [ 1000000, %14 ]
%19 = add nsw i64 %7, %17
store i64 %19, i64* %5
%20 = add nsw i32 %12, %18
store i32 %20, i32* %10
br label %21
21: ; preds = %16, %14
ret void
}