#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 timezone {
  int dummy;
};
struct timeval {
  scalar_t__ tv_usec;
  double tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
double timer_stop(struct timeval *tvp) {
  struct timeval tv1;
  struct timezone tz;
  double t;
  gettimeofday(&tv1, &tz);
  if (tvp->tv_usec > tv1.tv_usec) {
    tv1.tv_sec--;
    tv1.tv_usec += 1000000;
  }
  tv1.tv_sec -= tvp->tv_sec;
  tv1.tv_usec -= tvp->tv_usec;
  return t = tv1.tv_sec + (double)tv1.tv_usec / 1000000.0;
}


x86 assembly (clang, -O0):
<timer_stop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <gettimeofday@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
jle    115a <timer_stop+0x4a>
movsd  0xebe(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xf4240,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  -0x10(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
movsd  0xe72(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_stop>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <gettimeofday@plt>
mov    (%rbx),%rax
mov    0x10(%rsp),%rdx
lea    0xf4240(%rdx),%rcx
movsd  0x18(%rsp),%xmm1
cmp    %rdx,%rax
cmovle %rdx,%rcx
jle    114d <timer_stop+0x3d>
addsd  0xeb3(%rip),%xmm1
subsd  0x8(%rbx),%xmm1
sub    %rax,%rcx
cvtsi2sd %rcx,%xmm0
divsd  0xea6(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, double }
%struct.timezone = type { i32 }
define double @timer_stop(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca %struct.timeval
%4 = alloca %struct.timezone
%5 = alloca double
store %struct.timeval* %0, %struct.timeval** %2
%6 = call i32 @gettimeofday(%struct.timeval* %3, %struct.timezone* %4)
%7 = load %struct.timeval*, %struct.timeval** %2
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%11 = load i64, i64* %10
%12 = icmp sgt i64 %9, %11
br i1 %12, label %13, label %20
13: ; preds = %1
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%15 = load double, double* %14
%16 = fadd double %15, -1.000000e+00
store double %16, double* %14
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%18 = load i64, i64* %17
%19 = add nsw i64 %18, 1000000
store i64 %19, i64* %17
br label %20
20: ; preds = %13, %1
%21 = load %struct.timeval*, %struct.timeval** %2
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 1
%23 = load double, double* %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%25 = load double, double* %24
%26 = fsub double %25, %23
store double %26, double* %24
%27 = load %struct.timeval*, %struct.timeval** %2
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i32 0, i32 0
%29 = load i64, i64* %28
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%31 = load i64, i64* %30
%32 = sub nsw i64 %31, %29
store i64 %32, i64* %30
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%34 = load double, double* %33
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%36 = load i64, i64* %35
%37 = sitofp i64 %36 to double
%38 = fdiv double %37, 1.000000e+06
%39 = fadd double %34, %38
store double %39, double* %5
ret double %39
}

LLVM IR (-O2):
%struct.timeval = type { i64, double }
%struct.timezone = type { i32 }
define double @timer_stop(%struct.timeval* nocapture %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timezone
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timezone* %3 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%8 = load i64, i64* %7
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%10 = load i64, i64* %9
%11 = icmp sgt i64 %8, %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%13 = load double, double* %12
%14 = fadd double %13, -1.000000e+00
%15 = add nsw i64 %10, 1000000
%16 = select i1 %11, i64 %15, i64 %10
%17 = select i1 %11, double %14, double %13
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%19 = load double, double* %18
%20 = fsub double %17, %19
%21 = sub nsw i64 %16, %8
%22 = sitofp i64 %21 to double
%23 = fdiv double %22, 1.000000e+06
%24 = fadd double %20, %23
ret double %24
}