#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 */
typedef int uint64_t;
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ free(struct timeval *);
scalar_t__ malloc(int);
int /*<<< orphan*/ timeval_difference(struct timeval *, struct timeval *,
                                      struct timeval **);
uint64_t timeval_difference_us(struct timeval *start, struct timeval *end) {
  uint64_t difference = 0;
  int multip = 1.0;
  struct timeval *temp = (struct timeval *)malloc(sizeof(struct timeval));
  timeval_difference(start, end, &temp);
  difference = (temp->tv_sec * multip) + (temp->tv_usec / multip);
  free(temp);
  return difference;
}


x86 assembly (clang, -O0):
<timeval_difference_us>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <timeval_difference@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_difference_us>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,(%rsp)
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <timeval_difference@plt>
mov    (%rsp),%rdi
mov    0x4(%rdi),%ebx
add    (%rdi),%ebx
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i32 @timeval_difference_us(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.timeval*
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
store i32 0, i32* %5
store i32 1, i32* %6
%8 = call i64 @malloc(i32 8)
%9 = inttoptr i64 %8 to %struct.timeval*
store %struct.timeval* %9, %struct.timeval** %7
%10 = load %struct.timeval*, %struct.timeval** %3
%11 = load %struct.timeval*, %struct.timeval** %4
%12 = call i32 @timeval_difference(%struct.timeval* %10, %struct.timeval* %11, %struct.timeval** %7)
%13 = load %struct.timeval*, %struct.timeval** %7
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = load i32, i32* %6
%17 = mul nsw i32 %15, %16
%18 = load %struct.timeval*, %struct.timeval** %7
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = load i32, i32* %6
%22 = sdiv i32 %20, %21
%23 = add nsw i32 %17, %22
store i32 %23, i32* %5
%24 = load %struct.timeval*, %struct.timeval** %7
%25 = call i32 @free(%struct.timeval* %24)
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i32 @timeval_difference_us(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = bitcast %struct.timeval** %3 to i8*
%5 = tail call i64 @malloc(i32 8)
%6 = inttoptr i64 %5 to %struct.timeval*
store %struct.timeval* %6, %struct.timeval** %3
%7 = call i32 @timeval_difference(%struct.timeval* %0, %struct.timeval* %1, %struct.timeval** %3)
%8 = load %struct.timeval*, %struct.timeval** %3
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 1
%12 = load i32, i32* %11
%13 = add nsw i32 %12, %10
%14 = call i32 @free(%struct.timeval* %8)
ret i32 %13
}