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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ memset(struct timeval *, int /*<<< orphan*/, int);
int /*<<< orphan*/ timeradd(struct timeval *, struct timeval *,
                            struct timeval *);
int /*<<< orphan*/ timersub(struct timeval const *, struct timeval const *,
                            struct timeval *);
void add_timer(struct timeval *v, const struct timeval *start_time,
               const struct timeval *end_time) {
  struct timeval tmp;
  assert(end_time->tv_sec >= start_time->tv_sec);
  if (start_time->tv_sec == end_time->tv_sec) {
    assert(start_time->tv_usec <= end_time->tv_usec);
  }
  memset(&tmp, 0, sizeof(struct timeval));
  timersub(end_time, start_time, &tmp);
  timeradd(v, &tmp, v);
}


x86 assembly (clang, -O0):
<add_timer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jne    11a0 <add_timer+0x60>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x18(%rbp),%rcx
cmp    0x8(%rcx),%rax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1060 <timersub@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    -0x28(%rbp),%rsi
call   1030 <timeradd@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_timer>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rdx),%rax
xor    %edi,%edi
cmp    (%rsi),%rax
setge  %dil
call   1050 <assert@plt>
mov    (%rbx),%rax
cmp    (%r15),%rax
jne    1180 <add_timer+0x40>
mov    0x8(%rbx),%rax
xor    %edi,%edi
cmp    0x8(%r15),%rax
setle  %dil
call   1050 <assert@plt>
lea    0x8(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1060 <timersub@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1030 <timeradd@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @add_timer(%struct.timeval* %0, %struct.timeval* %1, %struct.timeval* %2) {
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %4 to i8*
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%7 = load i64, i64* %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%9 = load i64, i64* %8
%10 = icmp sge i64 %7, %9
%11 = zext i1 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = load i64, i64* %8
%14 = load i64, i64* %6
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %3
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%20 = load i64, i64* %19
%21 = icmp sle i64 %18, %20
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
br label %24
24: ; preds = %16, %3
%25 = call i32 @memset(%struct.timeval* %4, i32 0, i32 16)
%26 = call i32 @timersub(%struct.timeval* %2, %struct.timeval* %1, %struct.timeval* %4)
%27 = call i32 @timeradd(%struct.timeval* %0, %struct.timeval* %4, %struct.timeval* %0)
ret void
}