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

/* Variables and functions */
int atoi(char *);
int functionIterationsCount();
int functionRun();
int /*<<< orphan*/ functionSetupEach();
int /*<<< orphan*/ functionSetupOnce();
int /*<<< orphan*/ functionTeardownEach(char *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char *argv[]) {
  int iterations = functionIterationsCount();
  if (argc > 1) {
    iterations = atoi(argv[1]);
  }
  printf("Will run %d iterations.\n", iterations);
  char *outputFile = NULL;
  if (argc > 2) {
    outputFile = argv[2];
  }
  if (iterations == 0) {
    return 0;
  }
  functionSetupOnce();
  for (int i = 0; i != iterations; ++i) {
    functionSetupEach();
    struct timeval start, end;
    gettimeofday(&start, NULL);
    int result = functionRun();
    gettimeofday(&end, NULL);
    long start_t = start.tv_sec * 1000000 + start.tv_usec;
    long end_t = end.tv_sec * 1000000 + end.tv_usec;
    double time = (end_t - start_t) / 1000000.0;
    printf("Iteration %d, result = %d, sec = %.3f, ops / sec = %.3f\n", i,
           result, time, 1.0 / time);
    functionTeardownEach(outputFile);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10a0 <functionIterationsCount@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11ba <main+0x3a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11e9 <main+0x69>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11ff <main+0x7f>
movl   $0x0,-0x4(%rbp)
jmp    12c6 <main+0x146>
mov    $0x0,%al
call   1070 <functionSetupOnce@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     12bf <main+0x13f>
mov    $0x0,%al
call   1080 <functionSetupEach@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    $0x0,%al
call   1030 <functionRun@plt>
mov    %eax,-0x3c(%rbp)
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
imul   $0xf4240,-0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
cltq
mov    %rax,-0x48(%rbp)
imul   $0xf4240,-0x38(%rbp),%eax
add    -0x34(%rbp),%eax
cltq
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
sub    -0x48(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  0xd8f(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x24(%rbp),%esi
mov    -0x3c(%rbp),%edx
movsd  -0x58(%rbp),%xmm0
movsd  0xd6b(%rip),%xmm1
divsd  -0x58(%rbp),%xmm1
lea    0xd88(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <functionTeardownEach@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    120d <main+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
xor    %eax,%eax
call   10a0 <functionIterationsCount@plt>
cmp    $0x1,%ebp
jle    11c8 <main+0x48>
mov    0x8(%r15),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebx
lea    0xe5f(%rip),%rdi
xor    %r14d,%r14d
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebp
je     11dd <main+0x5d>
mov    0x10(%r15),%r14
jmp    11dd <main+0x5d>
mov    %eax,%ebx
lea    0xe3f(%rip),%rdi
xor    %r14d,%r14d
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
je     1290 <main+0x110>
xor    %eax,%eax
call   1070 <functionSetupOnce@plt>
lea    0x8(%rsp),%r12
lea    0xe31(%rip),%r13
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <functionSetupEach@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
xor    %eax,%eax
call   1030 <functionRun@plt>
mov    %eax,%r15d
mov    %r12,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
movslq 0x10(%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0x14(%rsp),%rcx
add    %rax,%rcx
movslq 0x8(%rsp),%rax
imul   $0xf4240,%rax,%rax
movslq 0xc(%rsp),%rdx
add    %rax,%rdx
sub    %rcx,%rdx
xorps  %xmm0,%xmm0
cvtsi2sd %rdx,%xmm0
divsd  0xd9e(%rip),%xmm0
movsd  0xd9e(%rip),%xmm1
divsd  %xmm0,%xmm1
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    $0x2,%al
call   1040 <printf@plt>
mov    %r14,%rdi
call   1060 <functionTeardownEach@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1200 <main+0x80>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [25 x i8] c"Will run %d iterations.\0A\00"
@.str.1 = [57 x i8] c"Iteration %d, result = %d, sec = %.3f, ops / sec = %.3f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i32 (...) @functionIterationsCount()
store i32 %15, i32* %6
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %6
br label %23
23: ; preds = %18, %2
%24 = load i32, i32* %6
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %24)
store i8* null, i8** %7
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 2
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
store i8* %31, i8** %7
br label %32
32: ; preds = %28, %23
%33 = load i32, i32* %6
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %32
store i32 0, i32* %3
br label %78
36: ; preds = %32
%37 = call i32 (...) @functionSetupOnce()
store i32 0, i32* %8
br label %38
38: ; preds = %74, %36
%39 = load i32, i32* %8
%40 = load i32, i32* %6
%41 = icmp ne i32 %39, %40
br i1 %41, label %42, label %77
42: ; preds = %38
%43 = call i32 (...) @functionSetupEach()
%44 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%45 = call i32 (...) @functionRun()
store i32 %45, i32* %11
%46 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%47 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%48 = load i32, i32* %47
%49 = mul nsw i32 %48, 1000000
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%51 = load i32, i32* %50
%52 = add nsw i32 %49, %51
%53 = sext i32 %52 to i64
store i64 %53, i64* %12
%54 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%55 = load i32, i32* %54
%56 = mul nsw i32 %55, 1000000
%57 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%58 = load i32, i32* %57
%59 = add nsw i32 %56, %58
%60 = sext i32 %59 to i64
store i64 %60, i64* %13
%61 = load i64, i64* %13
%62 = load i64, i64* %12
%63 = sub nsw i64 %61, %62
%64 = sitofp i64 %63 to double
%65 = fdiv double %64, 1.000000e+06
store double %65, double* %14
%66 = load i32, i32* %8
%67 = load i32, i32* %11
%68 = load double, double* %14
%69 = load double, double* %14
%70 = fdiv double 1.000000e+00, %69
%71 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %66, i32 %67, double %68, double %70)
%72 = load i8*, i8** %7
%73 = call i32 @functionTeardownEach(i8* %72)
br label %74
74: ; preds = %42
%75 = load i32, i32* %8
%76 = add nsw i32 %75, 1
store i32 %76, i32* %8
br label %38
77: ; preds = %38
store i32 0, i32* %3
br label %78
78: ; preds = %77, %35
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [25 x i8] c"Will run %d iterations.\0A\00"
@.str.1 = [57 x i8] c"Iteration %d, result = %d, sec = %.3f, ops / sec = %.3f\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = tail call i32 (...) @functionIterationsCount()
%6 = icmp sgt i32 %0, 1
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %18
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp eq i32 %0, 2
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
br label %18
18: ; preds = %7, %15, %9
%19 = phi i32 [ %12, %15 ], [ %12, %9 ], [ %5, %7 ]
%20 = phi i8* [ %17, %15 ], [ null, %9 ], [ null, %7 ]
%21 = icmp eq i32 %19, 0
br i1 %21, label %54, label %22
22: ; preds = %18
%23 = tail call i32 (...) @functionSetupOnce()
%24 = bitcast %struct.timeval* %3 to i8*
%25 = bitcast %struct.timeval* %4 to i8*
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
br label %30
30: ; preds = %22, %30
%31 = phi i32 [ 0, %22 ], [ %52, %30 ]
%32 = tail call i32 (...) @functionSetupEach()
%33 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%34 = tail call i32 (...) @functionRun()
%35 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%36 = load i32, i32* %26
%37 = mul nsw i32 %36, 1000000
%38 = load i32, i32* %27
%39 = add nsw i32 %37, %38
%40 = sext i32 %39 to i64
%41 = load i32, i32* %28
%42 = mul nsw i32 %41, 1000000
%43 = load i32, i32* %29
%44 = add nsw i32 %42, %43
%45 = sext i32 %44 to i64
%46 = sub nsw i64 %45, %40
%47 = sitofp i64 %46 to double
%48 = fdiv double %47, 1.000000e+06
%49 = fdiv double 1.000000e+00, %48
%50 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %34, double %48, double %49)
%51 = tail call i32 @functionTeardownEach(i8* %20)
%52 = add nuw nsw i32 %31, 1
%53 = icmp eq i32 %52, %19
br i1 %53, label %54, label %30
54: ; preds = %30, %18
ret i32 0
}