#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 w_timeval_add(const struct timeval a, const 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++;
    result->tv_usec -= 1000000;
  }
}


x86 assembly (clang, -O0):
<w_timeval_add>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
mov    %edx,-0x20(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rcx
add    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%ecx
add    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
cmpl   $0xf4240,(%rax)
jle    1160 <w_timeval_add+0x60>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
sub    $0xf4240,%ecx
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<w_timeval_add>:
add    %rcx,%rsi
mov    %rsi,0x8(%r8)
add    %edx,%edi
mov    %edi,(%r8)
cmp    $0xf4241,%edi
jl     1125 <w_timeval_add+0x25>
add    $0x1,%rsi
mov    %rsi,0x8(%r8)
add    $0xfff0bdc0,%edi
mov    %edi,(%r8)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define void @w_timeval_add(i32 %0, i64 %1, i32 %2, i64 %3, %struct.timeval* nocapture %4) {
%6 = add nsw i64 %3, %1
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i64 %6, i64* %7
%8 = add nsw i32 %2, %0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 %8, i32* %9
%10 = icmp sgt i32 %8, 1000000
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = add nsw i64 %6, 1
store i64 %12, i64* %7
%13 = add nsw i32 %8, -1000000
store i32 %13, i32* %9
br label %14
14: ; preds = %11, %5
ret void
}