#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 */
typedef scalar_t__ int64_t;

/* Variables and functions */
scalar_t__ INT64_MAX;
scalar_t__ gettime_i64();
int /*<<< orphan*/ print_number(scalar_t__);
int /*<<< orphan*/ printf(char *, ...);
void run_benchmark(char *name, void (*benchmark)(void *, int),
                   void (*setup)(void *), void (*teardown)(void *, int),
                   void *data, int count, int iter) {
  int i;
  int64_t min = INT64_MAX;
  int64_t sum = 0;
  int64_t max = 0;
  for (i = 0; i < count; i++) {
    int64_t begin, total;
    if (setup != NULL) {
      setup(data);
    }
    begin = gettime_i64();
    benchmark(data, iter);
    total = gettime_i64() - begin;
    if (teardown != NULL) {
      teardown(data, iter);
    }
    if (total < min) {
      min = total;
    }
    if (total > max) {
      max = total;
    }
    sum += total;
  }
  printf("%s: min ", name);
  print_number(min * (1000000LL) / iter);
  printf("us / avg ");
  print_number(((sum * (1000000LL)) / count) / iter);
  printf("us / max ");
  print_number(max * (1000000LL) / iter);
  printf("us\n");
}


x86 assembly (clang, -O0):
<run_benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    121e <run_benchmark+0xee>
cmpq   $0x0,-0x18(%rbp)
je     1199 <run_benchmark+0x69>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rdi
call   *%rax
mov    $0x0,%al
call   1050 <gettime_i64@plt>
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rdi
mov    0x10(%rbp),%esi
call   *%rax
mov    $0x0,%al
call   1050 <gettime_i64@plt>
sub    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d8 <run_benchmark+0xa8>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rdi
mov    0x10(%rbp),%esi
call   *%rax
mov    -0x58(%rbp),%rax
cmp    -0x38(%rbp),%rax
jge    11ee <run_benchmark+0xbe>
mov    -0x58(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x58(%rbp),%rax
cmp    -0x48(%rbp),%rax
jle    1204 <run_benchmark+0xd4>
mov    -0x58(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x58(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1178 <run_benchmark+0x48>
mov    -0x8(%rbp),%rsi
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
imul   $0xf4240,-0x38(%rbp),%rax
movslq 0x10(%rbp),%rcx
cqto
idiv   %rcx
mov    %rax,%rdi
call   1040 <print_number@plt>
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
imul   $0xf4240,-0x40(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cqto
idiv   %rcx
movslq 0x10(%rbp),%rcx
cqto
idiv   %rcx
mov    %rax,%rdi
call   1040 <print_number@plt>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
imul   $0xf4240,-0x48(%rbp),%rax
movslq 0x10(%rbp),%rcx
cqto
idiv   %rcx
mov    %rax,%rdi
call   1040 <print_number@plt>
lea    0xd76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_benchmark>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rsi,0x28(%rsp)
mov    %rdi,%rsi
mov    0x70(%rsp),%ebx
mov    0x2e87(%rip),%rax
mov    (%rax),%rbp
test   %r9d,%r9d
mov    %r9d,0xc(%rsp)
jle    1221 <run_benchmark+0xe1>
mov    %r8,%r13
mov    %rdx,%r12
mov    %rbp,(%rsp)
mov    %rsi,0x18(%rsp)
mov    %r9d,%r15d
xor    %r14d,%r14d
xor    %ebp,%ebp
mov    %rcx,0x10(%rsp)
mov    %rdx,0x20(%rsp)
jmp    11c4 <run_benchmark+0x84>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rsp),%rax
cmp    %rax,%r12
cmovl  %r12,%rax
mov    %rax,(%rsp)
cmp    %r14,%r12
cmovg  %r12,%r14
add    %r12,%rbp
add    $0xffffffff,%r15d
mov    0x20(%rsp),%r12
je     1208 <run_benchmark+0xc8>
test   %r12,%r12
je     11cf <run_benchmark+0x8f>
mov    %r13,%rdi
call   *%r12
xor    %eax,%eax
call   1060 <gettime_i64@plt>
mov    %rax,0x30(%rsp)
mov    %r13,%rdi
mov    %ebx,%esi
call   *0x28(%rsp)
xor    %eax,%eax
call   1060 <gettime_i64@plt>
mov    %rax,%r12
sub    0x30(%rsp),%r12
mov    0x10(%rsp),%rcx
test   %rcx,%rcx
je     11a0 <run_benchmark+0x60>
mov    %r13,%rdi
mov    %ebx,%esi
call   *0x10(%rsp)
jmp    11a0 <run_benchmark+0x60>
imul   $0xf4240,%rbp,%r12
imul   $0xf4240,%r14,%r14
mov    0x18(%rsp),%rsi
mov    (%rsp),%rbp
jmp    1227 <run_benchmark+0xe7>
xor    %r12d,%r12d
xor    %r14d,%r14d
lea    0xdd2(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
imul   $0xf4240,%rbp,%rax
movslq %ebx,%rbp
mov    %rax,%rcx
or     %rbp,%rcx
shr    $0x20,%rcx
je     1252 <run_benchmark+0x112>
cqto
idiv   %rbp
jmp    1256 <run_benchmark+0x116>
xor    %edx,%edx
div    %ebx
mov    %rax,%rdi
call   1050 <print_number@plt>
lea    0xda4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
movslq %esi,%rcx
mov    %r12,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1289 <run_benchmark+0x149>
mov    %r12,%rax
cqto
idiv   %rcx
jmp    1290 <run_benchmark+0x150>
mov    %r12d,%eax
xor    %edx,%edx
div    %esi
mov    %rax,%rcx
or     %rbp,%rcx
shr    $0x20,%rcx
je     12a3 <run_benchmark+0x163>
cqto
idiv   %rbp
jmp    12a7 <run_benchmark+0x167>
xor    %edx,%edx
div    %ebx
mov    %rax,%rdi
call   1050 <print_number@plt>
lea    0xd5d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rax
or     %rbp,%rax
shr    $0x20,%rax
je     12d3 <run_benchmark+0x193>
mov    %r14,%rax
cqto
idiv   %rbp
jmp    12da <run_benchmark+0x19a>
mov    %r14d,%eax
xor    %edx,%edx
div    %ebx
mov    %rax,%rdi
call   1050 <print_number@plt>
lea    0xd34(%rip),%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@INT64_MAX = global i64 0
@.str = [9 x i8] c"%s: min \00"
@.str.1 = [10 x i8] c"us / avg \00"
@.str.2 = [10 x i8] c"us / max \00"
@.str.3 = [4 x i8] c"us\0A\00"
define void @run_benchmark(i8* %0, void (i8*, i32)* %1, void (i8*)* %2, void (i8*, i32)* %3, i8* %4, i32 %5, i32 %6) {
%8 = alloca i8*
%9 = alloca void (i8*, i32)*
%10 = alloca void (i8*)*
%11 = alloca void (i8*, i32)*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i64
store i8* %0, i8** %8
store void (i8*, i32)* %1, void (i8*, i32)** %9
store void (i8*)* %2, void (i8*)** %10
store void (i8*, i32)* %3, void (i8*, i32)** %11
store i8* %4, i8** %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%21 = load i64, i64* @INT64_MAX
store i64 %21, i64* %16
store i64 0, i64* %17
store i64 0, i64* %18
store i32 0, i32* %15
br label %22
22: ; preds = %62, %7
%23 = load i32, i32* %15
%24 = load i32, i32* %13
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %65
26: ; preds = %22
%27 = load void (i8*)*, void (i8*)** %10
%28 = icmp ne void (i8*)* %27, null
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load void (i8*)*, void (i8*)** %10
%31 = load i8*, i8** %12
br label %32
32: ; preds = %29, %26
%33 = call i64 (...) @gettime_i64()
store i64 %33, i64* %19
%34 = load void (i8*, i32)*, void (i8*, i32)** %9
%35 = load i8*, i8** %12
%36 = load i32, i32* %14
%37 = call i64 (...) @gettime_i64()
%38 = load i64, i64* %19
%39 = sub nsw i64 %37, %38
store i64 %39, i64* %20
%40 = load void (i8*, i32)*, void (i8*, i32)** %11
%41 = icmp ne void (i8*, i32)* %40, null
br i1 %41, label %42, label %46
42: ; preds = %32
%43 = load void (i8*, i32)*, void (i8*, i32)** %11
%44 = load i8*, i8** %12
%45 = load i32, i32* %14
br label %46
46: ; preds = %42, %32
%47 = load i64, i64* %20
%48 = load i64, i64* %16
%49 = icmp slt i64 %47, %48
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = load i64, i64* %20
store i64 %51, i64* %16
br label %52
52: ; preds = %50, %46
%53 = load i64, i64* %20
%54 = load i64, i64* %18
%55 = icmp sgt i64 %53, %54
br i1 %55, label %56, label %58
56: ; preds = %52
%57 = load i64, i64* %20
store i64 %57, i64* %18
br label %58
58: ; preds = %56, %52
%59 = load i64, i64* %20
%60 = load i64, i64* %17
%61 = add nsw i64 %60, %59
store i64 %61, i64* %17
br label %62
62: ; preds = %58
%63 = load i32, i32* %15
%64 = add nsw i32 %63, 1
store i32 %64, i32* %15
br label %22
65: ; preds = %22
%66 = load i8*, i8** %8
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %66)
%68 = load i64, i64* %16
%69 = mul nsw i64 %68, 1000000
%70 = load i32, i32* %14
%71 = sext i32 %70 to i64
%72 = sdiv i64 %69, %71
%73 = call i32 @print_number(i64 %72)
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%75 = load i64, i64* %17
%76 = mul nsw i64 %75, 1000000
%77 = load i32, i32* %13
%78 = sext i32 %77 to i64
%79 = sdiv i64 %76, %78
%80 = load i32, i32* %14
%81 = sext i32 %80 to i64
%82 = sdiv i64 %79, %81
%83 = call i32 @print_number(i64 %82)
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%85 = load i64, i64* %18
%86 = mul nsw i64 %85, 1000000
%87 = load i32, i32* %14
%88 = sext i32 %87 to i64
%89 = sdiv i64 %86, %88
%90 = call i32 @print_number(i64 %89)
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@INT64_MAX = global i64 0
@.str = [9 x i8] c"%s: min \00"
@.str.1 = [10 x i8] c"us / avg \00"
@.str.2 = [10 x i8] c"us / max \00"
@str = [3 x i8] c"us\00"
define void @run_benchmark(i8* %0, void (i8*, i32)* nocapture %1, void (i8*)* %2, void (i8*, i32)* %3, i8* %4, i32 %5, i32 %6) {
%8 = load i64, i64* @INT64_MAX
%9 = icmp sgt i32 %5, 0
br i1 %9, label %10, label %35
10: ; preds = %7
%11 = icmp eq void (i8*)* %2, null
%12 = icmp eq void (i8*, i32)* %3, null
br label %13
13: ; preds = %10, %24
%14 = phi i32 [ 0, %10 ], [ %30, %24 ]
%15 = phi i64 [ %8, %10 ], [ %26, %24 ]
%16 = phi i64 [ 0, %10 ], [ %28, %24 ]
%17 = phi i64 [ 0, %10 ], [ %29, %24 ]
br i1 %11, label %19, label %18
18: ; preds = %13
tail call void %2(i8* %4)
br label %19
19: ; preds = %18, %13
%20 = tail call i64 (...) @gettime_i64()
tail call void %1(i8* %4, i32 %6)
%21 = tail call i64 (...) @gettime_i64()
%22 = sub nsw i64 %21, %20
br i1 %12, label %24, label %23
23: ; preds = %19
tail call void %3(i8* %4, i32 %6)
br label %24
24: ; preds = %23, %19
%25 = icmp slt i64 %22, %15
%26 = select i1 %25, i64 %22, i64 %15
%27 = icmp sgt i64 %22, %16
%28 = select i1 %27, i64 %22, i64 %16
%29 = add nsw i64 %22, %17
%30 = add nuw nsw i32 %14, 1
%31 = icmp eq i32 %30, %5
br i1 %31, label %32, label %13
32: ; preds = %24
%33 = mul i64 %29, 1000000
%34 = mul i64 %28, 1000000
br label %35
35: ; preds = %32, %7
%36 = phi i64 [ 0, %7 ], [ %33, %32 ]
%37 = phi i64 [ 0, %7 ], [ %34, %32 ]
%38 = phi i64 [ %8, %7 ], [ %26, %32 ]
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %0)
%40 = mul nsw i64 %38, 1000000
%41 = sext i32 %6 to i64
%42 = sdiv i64 %40, %41
%43 = tail call i32 @print_number(i64 %42)
%44 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%45 = sext i32 %5 to i64
%46 = sdiv i64 %36, %45
%47 = sdiv i64 %46, %41
%48 = tail call i32 @print_number(i64 %47)
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%50 = sdiv i64 %37, %41
%51 = tail call i32 @print_number(i64 %50)
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
ret void
}