#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 */
int add_time_katcp(struct timeval *sigma, struct timeval *alpha,
                   struct timeval *beta) {
  if (alpha->tv_usec + beta->tv_usec >= 1000000) {
    sigma->tv_sec = alpha->tv_sec + beta->tv_sec + 1;
    sigma->tv_usec = (alpha->tv_usec + beta->tv_usec) - 1000000;
  } else {
    sigma->tv_sec = alpha->tv_sec + beta->tv_sec;
    sigma->tv_usec = alpha->tv_usec + beta->tv_usec;
  }
  return 0;
}


x86 assembly (clang, -O0):
<add_time_katcp>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
add    (%rcx),%eax
cmp    $0xf4240,%eax
jl     1160 <add_time_katcp+0x60>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
add    0x8(%rax),%rcx
add    $0x1,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
add    (%rax),%ecx
sub    $0xf4240,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    118a <add_time_katcp+0x8a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
add    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
add    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
xor    %eax,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_time_katcp>:
mov    (%rsi),%r9d
mov    (%rdx),%ecx
lea    (%rcx,%r9,1),%r8d
xor    %eax,%eax
cmp    $0xf4240,%r8d
setge  %al
lea    -0xf4240(%rcx,%r9,1),%ecx
ff
cmovl  %r8d,%ecx
add    0x8(%rsi),%rax
add    0x8(%rdx),%rax
mov    %rax,0x8(%rdi)
mov    %ecx,(%rdi)
xor    %eax,%eax
ret

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

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