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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
long time_difference(struct timeval *time1) {
  struct timeval time2;
  time2.tv_sec = time1->tv_sec;
  time2.tv_usec = time1->tv_usec;
  gettimeofday(time1, NULL);
  return time1->tv_sec * 1000000 + time1->tv_usec - time2.tv_sec * 1000000 -
         time2.tv_usec;
}


x86 assembly (clang, -O0):
<time_difference>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x8(%rbp),%rax
imul   $0xf4240,(%rax),%eax
mov    -0x8(%rbp),%rcx
add    0x4(%rcx),%eax
imul   $0xf4240,-0x10(%rbp),%ecx
sub    %ecx,%eax
sub    -0xc(%rbp),%eax
cltq
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_difference>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%ebp
mov    0x4(%rdi),%r14d
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rbx),%eax
sub    %ebp,%eax
mov    0x4(%rbx),%ecx
sub    %r14d,%ecx
imul   $0xf4240,%eax,%eax
add    %ecx,%eax
cltq
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i64 @time_difference(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %2
%4 = load %struct.timeval*, %struct.timeval** %2
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 %6, i32* %7
%8 = load %struct.timeval*, %struct.timeval** %2
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i32 %10, i32* %11
%12 = load %struct.timeval*, %struct.timeval** %2
%13 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%14 = load %struct.timeval*, %struct.timeval** %2
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = mul nsw i32 %16, 1000000
%18 = load %struct.timeval*, %struct.timeval** %2
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = add nsw i32 %17, %20
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%23 = load i32, i32* %22
%24 = mul nsw i32 %23, 1000000
%25 = sub nsw i32 %21, %24
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%27 = load i32, i32* %26
%28 = sub nsw i32 %25, %27
%29 = sext i32 %28 to i64
ret i64 %29
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i64 @time_difference(%struct.timeval* nocapture %0) {
%2 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%5 = load i32, i32* %4
%6 = tail call i32 @gettimeofday(%struct.timeval* %0, i32* null)
%7 = load i32, i32* %2
%8 = load i32, i32* %4
%9 = sub i32 %7, %3
%10 = mul i32 %9, 1000000
%11 = sub i32 %8, %5
%12 = add i32 %11, %10
%13 = sext i32 %12 to i64
ret i64 %13
}