#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 int time_t;
struct rusage {
  int /*<<< orphan*/ ru_stime;
  int /*<<< orphan*/ ru_utime;
};

/* Variables and functions */
int /*<<< orphan*/ RUSAGE_SELF;
int /*<<< orphan*/ getrusage(int /*<<< orphan*/, struct rusage *);
int /*<<< orphan*/ printf(char *, char const *, float, unsigned int,
                          char const *);
int /*<<< orphan*/ system(char *);
int timeval_to_us(int /*<<< orphan*/ *);
time_t benchmark(time_t last_time, unsigned task_count, const char *label,
                 const char *task_name_plural) {
  struct rusage rusage;
  time_t time;
  getrusage(RUSAGE_SELF, &rusage);
  time = timeval_to_us(&rusage.ru_utime) + timeval_to_us(&rusage.ru_stime);
  if (last_time) {
    float seconds = (time - last_time) / 1000000.;
    system("clear");
    printf("\n%s took %fs (%f %s/sec)\n", label, seconds, task_count / seconds,
           task_name_plural);
  }
  return time;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1050 <getrusage@plt>
lea    -0x20(%rbp),%rdi
add    $0x4,%rdi
call   1060 <timeval_to_us@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <timeval_to_us@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11ee <benchmark+0xae>
mov    -0x24(%rbp),%eax
mov    -0x4(%rbp),%ecx
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe57(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x28(%rbp)
lea    0xe4b(%rip),%rdi
call   1030 <system@plt>
mov    -0x10(%rbp),%rsi
movss  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%eax
cvtsi2ss %rax,%xmm1
divss  %xmm0,%xmm1
cvttss2si %xmm1,%rax
mov    %eax,%edx
mov    -0x18(%rbp),%rcx
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r12d
mov    %edi,%r13d
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1050 <getrusage@plt>
lea    0x14(%rsp),%rdi
call   1060 <timeval_to_us@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <timeval_to_us@plt>
mov    %eax,%ebx
add    %ebp,%ebx
test   %r13d,%r13d
je     11dd <benchmark+0x9d>
mov    %ebx,%eax
sub    %r13d,%eax
cvtsi2sd %eax,%xmm0
divsd  0xe62(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,0xc(%rsp)
lea    0xe59(%rip),%rdi
call   1030 <system@plt>
mov    %r12d,%eax
cvtsi2ss %rax,%xmm1
movss  0xc(%rsp),%xmm0
divss  %xmm0,%xmm1
cvttss2si %xmm1,%rdx
lea    0xe3c(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rcx
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rusage = type { i32, i32 }
@RUSAGE_SELF = global i32 0
@.str = [6 x i8] c"clear\00"
@.str.1 = [26 x i8] c"\0A%s took %fs (%f %s/sec)\0A\00"
define i32 @benchmark(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.rusage
%10 = alloca i32
%11 = alloca float
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%12 = load i32, i32* @RUSAGE_SELF
%13 = call i32 @getrusage(i32 %12, %struct.rusage* %9)
%14 = getelementptr inbounds %struct.rusage, %struct.rusage* %9, i32 0, i32 1
%15 = call i32 @timeval_to_us(i32* %14)
%16 = getelementptr inbounds %struct.rusage, %struct.rusage* %9, i32 0, i32 0
%17 = call i32 @timeval_to_us(i32* %16)
%18 = add nsw i32 %15, %17
store i32 %18, i32* %10
%19 = load i32, i32* %5
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %38
21: ; preds = %4
%22 = load i32, i32* %10
%23 = load i32, i32* %5
%24 = sub nsw i32 %22, %23
%25 = sitofp i32 %24 to double
%26 = fdiv double %25, 1.000000e+06
%27 = fptrunc double %26 to float
store float %27, float* %11
%28 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%29 = load i8*, i8** %7
%30 = load float, float* %11
%31 = load i32, i32* %6
%32 = uitofp i32 %31 to float
%33 = load float, float* %11
%34 = fdiv float %32, %33
%35 = fptoui float %34 to i32
%36 = load i8*, i8** %8
%37 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %29, float %30, i32 %35, i8* %36)
br label %38
38: ; preds = %21, %4
%39 = load i32, i32* %10
ret i32 %39
}

LLVM IR (-O2):
%struct.rusage = type { i32, i32 }
@RUSAGE_SELF = global i32 0
@.str = [6 x i8] c"clear\00"
@.str.1 = [26 x i8] c"\0A%s took %fs (%f %s/sec)\0A\00"
define i32 @benchmark(i32 %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca %struct.rusage
%6 = bitcast %struct.rusage* %5 to i8*
%7 = load i32, i32* @RUSAGE_SELF
%8 = call i32 @getrusage(i32 %7, %struct.rusage* %5)
%9 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i64 0, i32 1
%10 = call i32 @timeval_to_us(i32* %9)
%11 = getelementptr inbounds %struct.rusage, %struct.rusage* %5, i64 0, i32 0
%12 = call i32 @timeval_to_us(i32* %11)
%13 = add nsw i32 %12, %10
%14 = icmp eq i32 %0, 0
br i1 %14, label %25, label %15
15: ; preds = %4
%16 = sub nsw i32 %13, %0
%17 = sitofp i32 %16 to double
%18 = fdiv double %17, 1.000000e+06
%19 = fptrunc double %18 to float
%20 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%21 = uitofp i32 %1 to float
%22 = fdiv float %21, %19
%23 = fptoui float %22 to i32
%24 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %2, float %19, i32 %23, i8* %3)
br label %25
25: ; preds = %15, %4
ret i32 %13
}