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

/* Variables and functions */
long long timeval_diff(struct timeval *end_time, struct timeval *start_time) {
  struct timeval *difference;
  difference->tv_sec = end_time->tv_sec - start_time->tv_sec;
  difference->tv_usec = end_time->tv_usec - start_time->tv_usec;
  while (difference->tv_usec < 0) {
    difference->tv_usec += 1000000;
    difference->tv_sec -= 1;
  }
  return (1000000LL * difference->tv_sec + difference->tv_usec);
}


x86 assembly (clang, -O0):
<timeval_diff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
sub    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jge    1168 <timeval_diff+0x68>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
sub    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1136 <timeval_diff+0x36>
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
imul   $0xf4240,%rax,%rax
mov    -0x18(%rbp),%rcx
add    0x8(%rcx),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define i64 @timeval_diff(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval*
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
%6 = load %struct.timeval*, %struct.timeval** %3
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = load %struct.timeval*, %struct.timeval** %4
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = sub nsw i32 %8, %11
%13 = load %struct.timeval*, %struct.timeval** %5
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
store i32 %12, i32* %14
%15 = load %struct.timeval*, %struct.timeval** %3
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%17 = load i64, i64* %16
%18 = load %struct.timeval*, %struct.timeval** %4
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
%20 = load i64, i64* %19
%21 = sub nsw i64 %17, %20
%22 = load %struct.timeval*, %struct.timeval** %5
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
store i64 %21, i64* %23
br label %24
24: ; preds = %29, %2
%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 = icmp slt i64 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %24
%30 = load %struct.timeval*, %struct.timeval** %5
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %30, i32 0, i32 1
%32 = load i64, i64* %31
%33 = add nsw i64 %32, 1000000
store i64 %33, i64* %31
%34 = load %struct.timeval*, %struct.timeval** %5
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = sub nsw i32 %36, 1
store i32 %37, i32* %35
br label %24
38: ; preds = %24
%39 = load %struct.timeval*, %struct.timeval** %5
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = sext i32 %41 to i64
%43 = mul nsw i64 1000000, %42
%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 = add nsw i64 %43, %46
ret i64 %47
}

LLVM IR (-O2):