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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ run2();
void run() {
  struct timeval aTv;
  gettimeofday(&aTv, NULL);
  long init_time = aTv.tv_sec;
  long init_usec = aTv.tv_usec;
  int i;
  for (i = 0; i < 100; i++)
    run2();
  gettimeofday(&aTv, NULL);
  double query_time =
      (aTv.tv_sec - init_time) + (double)(aTv.tv_usec - init_usec) / 1000000.0;
  printf("C Elapsed %0.2f\n", query_time);
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jge    117b <run+0x4b>
mov    $0x0,%al
call   1050 <run2@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115c <run+0x2c>
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%rax
sub    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    -0x8(%rbp),%rax
sub    -0x20(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  0xe56(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    (%rsp),%rbx
mov    0x8(%rsp),%r14
mov    $0x64,%ebp
xor    %eax,%eax
call   1050 <run2@plt>
add    $0xffffffff,%ebp
jne    1150 <run+0x20>
mov    %rsp,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    (%rsp),%rax
sub    %rbx,%rax
mov    0x8(%rsp),%rcx
sub    %r14,%rcx
cvtsi2sd %rax,%xmm1
cvtsi2sd %rcx,%xmm0
divsd  0xe79(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0xe76(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [17 x i8] c"C Elapsed %0.2f\0A\00"
define void @run() {
%1 = alloca %struct.timeval
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca double
%6 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%8 = load i64, i64* %7
store i64 %8, i64* %2
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%10 = load i64, i64* %9
store i64 %10, i64* %3
store i32 0, i32* %4
br label %11
11: ; preds = %16, %0
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 100
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = call i32 (...) @run2()
br label %16
16: ; preds = %14
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %11
19: ; preds = %11
%20 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%22 = load i64, i64* %21
%23 = load i64, i64* %2
%24 = sub nsw i64 %22, %23
%25 = sitofp i64 %24 to double
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%27 = load i64, i64* %26
%28 = load i64, i64* %3
%29 = sub nsw i64 %27, %28
%30 = sitofp i64 %29 to double
%31 = fdiv double %30, 1.000000e+06
%32 = fadd double %25, %31
store double %32, double* %5
%33 = load double, double* %5
%34 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), double %33)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [17 x i8] c"C Elapsed %0.2f\0A\00"
define void @run() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%5 = load i64, i64* %4
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%7 = load i64, i64* %6
br label %8
8: ; preds = %0, %8
%9 = phi i32 [ 0, %0 ], [ %11, %8 ]
%10 = tail call i32 (...) @run2()
%11 = add nuw nsw i32 %9, 1
%12 = icmp eq i32 %11, 100
br i1 %12, label %13, label %8
13: ; preds = %8
%14 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%15 = load i64, i64* %4
%16 = sub nsw i64 %15, %5
%17 = sitofp i64 %16 to double
%18 = load i64, i64* %6
%19 = sub nsw i64 %18, %7
%20 = sitofp i64 %19 to double
%21 = fdiv double %20, 1.000000e+06
%22 = fadd double %21, %17
%23 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), double %22)
ret void
}