#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 {
  long tv_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
void timeval_increment(struct timeval *out, struct timeval *diff) {
  out->tv_sec += diff->tv_sec;
  long tv_usec = out->tv_usec + diff->tv_usec;
  if (tv_usec >= 1000000) {
    ++out->tv_sec;
    out->tv_usec = 1000000 - tv_usec;
  } else {
    out->tv_usec = tv_usec;
  };
  return;
}


x86 assembly (clang, -O0):
<timeval_increment>:
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),%rax
mov    -0x10(%rbp),%rcx
add    (%rcx),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0xf4240,-0x18(%rbp)
jl     1165 <timeval_increment+0x65>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rax)
mov    $0xf4240,%ecx
sub    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    1170 <timeval_increment+0x70>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_increment>:
mov    0x8(%rdi),%rcx
add    0x8(%rsi),%rcx
mov    %rcx,0x8(%rdi)
mov    (%rsi),%rax
add    (%rdi),%rax
cmp    $0xf4240,%rax
jl     112d <timeval_increment+0x2d>
add    $0x1,%rcx
mov    %rcx,0x8(%rdi)
mov    $0xf4240,%ecx
sub    %rax,%rcx
mov    %rcx,%rax
mov    %rax,(%rdi)
ret

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

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