#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
long diff_usec(struct timeval, struct timeval);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double loops_per_usec() {
  long i;
  struct timeval before, after;
  if (gettimeofday(&before, NULL) == -1)
    err(EXIT_FAILURE, "gettimeofday(before) failed");
  for (i = 0; i < 10000000000L; i++)
    ;
  if (gettimeofday(&after, NULL) == -1)
    err(EXIT_FAILURE, "gettimeofday(after) failed");
  return 10000000000L / diff_usec(before, after);
}


x86 assembly (clang, -O0):
<loops_per_usec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    1163 <loops_per_usec+0x33>
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
lea    0xea2(%rip),%rsi
call   1040 <err@plt>
movq   $0x0,-0x8(%rbp)
movabs $0x2540be400,%rax
cmp    %rax,-0x8(%rbp)
jge    1195 <loops_per_usec+0x65>
jmp    1184 <loops_per_usec+0x54>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    116b <loops_per_usec+0x3b>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    11c0 <loops_per_usec+0x90>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1040 <err@plt>
mov    -0x10(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1050 <diff_usec@plt>
mov    %rax,%rcx
movabs $0x2540be400,%rax
cqto
idiv   %rcx
cvtsi2sd %rax,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loops_per_usec>:
sub    $0x18,%rsp
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    115a <loops_per_usec+0x2a>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
call   1040 <err@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    1180 <loops_per_usec+0x50>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
lea    0xea1(%rip),%rsi
call   1040 <err@plt>
mov    0x10(%rsp),%edi
mov    0x8(%rsp),%esi
call   1050 <diff_usec@plt>
mov    %rax,%rcx
movabs $0x2540be400,%rax
xor    %edx,%edx
idiv   %rcx
cvtsi2sd %rax,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [28 x i8] c"gettimeofday(before) failed\00"
@.str.1 = [27 x i8] c"gettimeofday(after) failed\00"
define double @loops_per_usec() {
%1 = alloca i64
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @EXIT_FAILURE
%8 = call i32 @err(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %6, %0
store i64 0, i64* %1
br label %10
10: ; preds = %14, %9
%11 = load i64, i64* %1
%12 = icmp slt i64 %11, 10000000000
br i1 %12, label %13, label %17
13: ; preds = %10
br label %14
14: ; preds = %13
%15 = load i64, i64* %1
%16 = add nsw i64 %15, 1
store i64 %16, i64* %1
br label %10
17: ; preds = %10
%18 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @err(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %20, %17
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i64 @diff_usec(i32 %25, i32 %27)
%29 = sdiv i64 10000000000, %28
%30 = sitofp i64 %29 to double
ret double %30
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@EXIT_FAILURE = global i32 0
@.str = [28 x i8] c"gettimeofday(before) failed\00"
@.str.1 = [27 x i8] c"gettimeofday(after) failed\00"
define double @loops_per_usec() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @err(i32 %8, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %0
%11 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @err(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %13, %10
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%20 = load i32, i32* %19
%21 = tail call i64 @diff_usec(i32 %18, i32 %20)
%22 = sdiv i64 10000000000, %21
%23 = sitofp i64 %22 to double
ret double %23
}