#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 c_timeval_diff(struct timeval *res, struct timeval *t2,
                    struct timeval *t1) {
  if (t2->tv_usec >= t1->tv_usec) {
    res->tv_usec = t2->tv_usec - t1->tv_usec;
    res->tv_sec = t2->tv_sec - t1->tv_sec;
  } else {
    res->tv_usec = 1000000 - t1->tv_usec + t2->tv_usec;
    res->tv_sec = t2->tv_sec - t1->tv_sec - 1;
  }
  return;
}


x86 assembly (clang, -O0):
<c_timeval_diff>:
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
cmp    (%rcx),%eax
jl     1151 <c_timeval_diff+0x51>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
sub    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
jmp    1184 <c_timeval_diff+0x84>
mov    -0x18(%rbp),%rax
mov    $0xf4240,%ecx
sub    (%rax),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
sub    0x8(%rax),%rcx
sub    $0x1,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<c_timeval_diff>:
mov    (%rsi),%eax
mov    (%rdx),%r8d
cmp    %r8d,%eax
jge    111c <c_timeval_diff+0x1c>
add    $0xf4240,%eax
mov    0x8(%rdx),%rcx
not    %rcx
add    0x8(%rsi),%rcx
jmp    1124 <c_timeval_diff+0x24>
mov    0x8(%rsi),%rcx
sub    0x8(%rdx),%rcx
sub    %r8d,%eax
mov    %eax,(%rdi)
mov    %rcx,0x8(%rdi)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define void @c_timeval_diff(%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 = icmp slt i32 %5, %7
br i1 %8, label %15, label %9
9: ; preds = %3
%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 = sub nsw i64 %11, %13
br label %23
15: ; preds = %3
%16 = add i32 %5, 1000000
%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 = xor i64 %20, -1
%22 = add i64 %18, %21
br label %23
23: ; preds = %15, %9
%24 = phi i32 [ %16, %15 ], [ %5, %9 ]
%25 = phi i64 [ %22, %15 ], [ %14, %9 ]
%26 = sub i32 %24, %7
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
store i32 %26, i32* %27
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
store i64 %25, i64* %28
ret void
}