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

/* Variables and functions */
int /*<<< orphan*/ free(struct timeval *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
double gusto_stop_clock(void *clock_s) {
  struct timeval *T0 = (struct timeval *)clock_s;
  struct timeval *T1 = (struct timeval *)malloc(sizeof(struct timeval));
  gettimeofday(T1, NULL);
  double ds = T1->tv_sec - T0->tv_sec;
  double du = T1->tv_usec - T0->tv_usec;
  double dt = ds + 1e-6 * du;
  free(T0);
  free(T1);
  return dt;
}


x86 assembly (clang, -O0):
<gusto_stop_clock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  0xe63(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gusto_stop_clock>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movsd  (%rbx),%xmm0
movsd  0x8(%rbx),%xmm1
subsd  (%r14),%xmm0
subsd  0x8(%r14),%xmm1
mulsd  0xe96(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
define double @gusto_stop_clock(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = bitcast i8* %8 to %struct.timeval*
store %struct.timeval* %9, %struct.timeval** %3
%10 = call i64 @malloc(i32 16)
%11 = inttoptr i64 %10 to %struct.timeval*
store %struct.timeval* %11, %struct.timeval** %4
%12 = load %struct.timeval*, %struct.timeval** %4
%13 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
%14 = load %struct.timeval*, %struct.timeval** %4
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%16 = load double, double* %15
%17 = load %struct.timeval*, %struct.timeval** %3
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
%19 = load double, double* %18
%20 = fsub double %16, %19
store double %20, double* %5
%21 = load %struct.timeval*, %struct.timeval** %4
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 1
%23 = load double, double* %22
%24 = load %struct.timeval*, %struct.timeval** %3
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %24, i32 0, i32 1
%26 = load double, double* %25
%27 = fsub double %23, %26
store double %27, double* %6
%28 = load double, double* %5
%29 = load double, double* %6
%30 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %29, double %28)
store double %30, double* %7
%31 = load %struct.timeval*, %struct.timeval** %3
%32 = call i32 @free(%struct.timeval* %31)
%33 = load %struct.timeval*, %struct.timeval** %4
%34 = call i32 @free(%struct.timeval* %33)
%35 = load double, double* %7
ret double %35
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
define double @gusto_stop_clock(i8* nocapture %0) {
%2 = bitcast i8* %0 to %struct.timeval*
%3 = tail call i64 @malloc(i32 16)
%4 = inttoptr i64 %3 to %struct.timeval*
%5 = tail call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%7 = load double, double* %6
%8 = bitcast i8* %0 to double*
%9 = load double, double* %8
%10 = fsub double %7, %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%12 = load double, double* %11
%13 = getelementptr inbounds i8, i8* %0, i64 8
%14 = bitcast i8* %13 to double*
%15 = load double, double* %14
%16 = fsub double %12, %15
%17 = tail call double @llvm.fmuladd.f64(double %16, double 0x3EB0C6F7A0B5ED8D, double %10)
%18 = tail call i32 @free(%struct.timeval* %2)
%19 = tail call i32 @free(%struct.timeval* %4)
ret double %17
}