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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ timeval_subtract(struct timeval *, struct timeval *,
                                    struct timeval *);
double clockDiff(struct timeval *clock_start) {
  struct timeval time_now, elapsed;
  gettimeofday(&time_now, NULL);
  timeval_subtract(&elapsed, &time_now, clock_start);
  return (elapsed.tv_sec + elapsed.tv_usec * 1e-6);
}


x86 assembly (clang, -O0):
<clockDiff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x8(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <timeval_subtract@plt>
movsd  -0x28(%rbp),%xmm1
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  0xea4(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clockDiff>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
lea    0x18(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
lea    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <timeval_subtract@plt>
cvtsi2sdl 0x10(%rsp),%xmm0
mulsd  0xea9(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { double, i32 }
define double @clockDiff(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %2
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = load %struct.timeval*, %struct.timeval** %2
%7 = call i32 @timeval_subtract(%struct.timeval* %4, %struct.timeval* %3, %struct.timeval* %6)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%9 = load double, double* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%11 = load i32, i32* %10
%12 = sitofp i32 %11 to double
%13 = call double @llvm.fmuladd.f64(double %12, double 0x3EB0C6F7A0B5ED8D, double %9)
ret double %13
}

LLVM IR (-O2):
%struct.timeval = type { double, i32 }
define double @clockDiff(%struct.timeval* %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timeval* %3 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%7 = call i32 @timeval_subtract(%struct.timeval* %3, %struct.timeval* %2, %struct.timeval* %0)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%9 = load double, double* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%11 = load i32, i32* %10
%12 = sitofp i32 %11 to double
%13 = call double @llvm.fmuladd.f64(double %12, double 0x3EB0C6F7A0B5ED8D, double %9)
ret double %13
}