#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 uint64_t;
struct timespec {
  unsigned long tv_sec;
  int tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC_RAW;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ turtle_execute(char const *);
void _run_benchmark(const char *execute_str) {
  struct timespec start, end;
  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
  for (int i = 0; i < (20000000); i++) {
    turtle_execute(execute_str);
  }
  clock_gettime(CLOCK_MONOTONIC_RAW, &end);
  uint64_t duration;
  duration = (1000000000UL * (end.tv_sec - start.tv_sec)) +
             (end.tv_nsec - start.tv_nsec);
  printf("Command: %s\n", execute_str);
  printf("- Iterations              : %lu\n", (20000000));
  printf("- Time per iteration (ns) : %lu\n", duration / (20000000));
  printf("- Items/second            : %.03fM\n",
         (double)(20000000) / duration * 1000L);
  printf("\n");
}


x86 assembly (clang, -O0):
<_run_benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x1312d00,-0x2c(%rbp)
jge    1179 <_run_benchmark+0x49>
mov    -0x8(%rbp),%rdi
call   1050 <turtle_execute@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1155 <_run_benchmark+0x25>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x28(%rbp),%rax
sub    -0x18(%rbp),%rax
imul   $0x3b9aca00,%rax,%rax
mov    -0x20(%rbp),%ecx
sub    -0x10(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe5b(%rip),%rdi
mov    $0x1312d00,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%eax
mov    $0x1312d00,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cvtsi2sdl -0x30(%rbp),%xmm1
movsd  0xe12(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  0xdfe(%rip),%xmm1
mulsd  %xmm1,%xmm0
lea    0xe52(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_run_benchmark>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
mov    0x2e96(%rip),%r14
mov    (%r14),%edi
lea    0x10(%rsp),%rsi
call   1040 <clock_gettime@plt>
mov    $0x1312d00,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1060 <turtle_execute@plt>
add    $0xffffffff,%ebp
jne    1170 <_run_benchmark+0x30>
mov    (%r14),%edi
mov    %rsp,%rsi
call   1040 <clock_gettime@plt>
mov    (%rsp),%eax
mov    0x8(%rsp),%ecx
sub    0x10(%rsp),%eax
sub    0x18(%rsp),%ecx
imul   $0x3b9aca00,%eax,%ebp
add    %ecx,%ebp
lea    0xe6a(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe66(%rip),%rdi
mov    $0x1312d00,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movslq %ebp,%rbx
imul   $0x6b5fca6b,%rbx,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x37,%rsi
add    %eax,%esi
lea    0xe5d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cvtsi2sd %ebx,%xmm1
movsd  0xe0c(%rip),%xmm0
divsd  %xmm1,%xmm0
mulsd  0xe08(%rip),%xmm0
lea    0xe58(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i32 }
@CLOCK_MONOTONIC_RAW = global i32 0
@.str = [13 x i8] c"Command: %s\0A\00"
@.str.1 = [33 x i8] c"- Iterations : %lu\0A\00"
@.str.2 = [33 x i8] c"- Time per iteration (ns) : %lu\0A\00"
@.str.3 = [36 x i8] c"- Items/second : %.03fM\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @_run_benchmark(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i32, i32* @CLOCK_MONOTONIC_RAW
%8 = call i32 @clock_gettime(i32 %7, %struct.timespec* %3)
store i32 0, i32* %5
br label %9
9: ; preds = %15, %1
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 20000000
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = load i8*, i8** %2
%14 = call i32 @turtle_execute(i8* %13)
br label %15
15: ; preds = %12
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
store i32 %17, i32* %5
br label %9
18: ; preds = %9
%19 = load i32, i32* @CLOCK_MONOTONIC_RAW
%20 = call i32 @clock_gettime(i32 %19, %struct.timespec* %4)
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%22 = load i64, i64* %21
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%24 = load i64, i64* %23
%25 = sub i64 %22, %24
%26 = mul i64 1000000000, %25
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%30 = load i32, i32* %29
%31 = sub nsw i32 %28, %30
%32 = sext i32 %31 to i64
%33 = add i64 %26, %32
%34 = trunc i64 %33 to i32
store i32 %34, i32* %6
%35 = load i8*, i8** %2
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 20000000)
%38 = load i32, i32* %6
%39 = sdiv i32 %38, 20000000
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %6
%42 = sitofp i32 %41 to double
%43 = fdiv double 2.000000e+07, %42
%44 = fmul double %43, 1.000000e+03
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), double %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i32 }
@CLOCK_MONOTONIC_RAW = global i32 0
@.str = [13 x i8] c"Command: %s\0A\00"
@.str.1 = [33 x i8] c"- Iterations : %lu\0A\00"
@.str.2 = [33 x i8] c"- Time per iteration (ns) : %lu\0A\00"
@.str.3 = [36 x i8] c"- Items/second : %.03fM\0A\00"
define void @_run_benchmark(i8* %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %2 to i8*
%5 = bitcast %struct.timespec* %3 to i8*
%6 = load i32, i32* @CLOCK_MONOTONIC_RAW
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %2)
br label %33
8: ; preds = %33
%9 = load i32, i32* @CLOCK_MONOTONIC_RAW
%10 = call i32 @clock_gettime(i32 %9, %struct.timespec* %3)
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%12 = load i64, i64* %11
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%14 = load i64, i64* %13
%15 = sub i64 %12, %14
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%17 = load i32, i32* %16
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%19 = load i32, i32* %18
%20 = sub nsw i32 %17, %19
%21 = trunc i64 %15 to i32
%22 = mul i32 %21, 1000000000
%23 = add i32 %22, %20
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 20000000)
%26 = sdiv i32 %23, 20000000
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = sitofp i32 %23 to double
%29 = fdiv double 2.000000e+07, %28
%30 = fmul double %29, 1.000000e+03
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), double %30)
%32 = call i32 @putchar(i32 10)
ret void
33: ; preds = %1, %33
%34 = phi i32 [ 0, %1 ], [ %36, %33 ]
%35 = call i32 @turtle_execute(i8* %0)
%36 = add nuw nsw i32 %34, 1
%37 = icmp eq i32 %36, 20000000
br i1 %37, label %8, label %33
}