#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__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ image_transcode_compute(char const *, int);
double benchmark_image_transcode(int n, const char *input) {
  double total = 0;
  int i = 0;
  for (i = 0; i < n; i++) {
    clock_t begin = clock();
    image_transcode_compute(input, 200);
    clock_t end = clock();
    total += (double)(end - begin) / CLOCKS_PER_SEC * 1000;
  }
  return total / n;
}


x86 assembly (clang, -O0):
<benchmark_image_transcode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b5 <benchmark_image_transcode+0x95>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xc8,%esi
call   1040 <image_transcode_compute@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
sub    -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e5f(%rip),%rax
divsd  (%rax),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe66(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <benchmark_image_transcode+0x25>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark_image_transcode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
test   %edi,%edi
jle    119d <benchmark_image_transcode+0x7d>
mov    %rsi,%r12
xorpd  %xmm0,%xmm0
mov    0x2ea7(%rip),%r15
mov    %r14d,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbp
mov    %r12,%rdi
mov    $0xc8,%esi
call   1040 <image_transcode_compute@plt>
xor    %eax,%eax
call   1030 <clock@plt>
movsd  0x8(%rsp),%xmm0
sub    %rbp,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  (%r15),%xmm1
mulsd  0xe6e(%rip),%xmm1
addsd  %xmm1,%xmm0
add    $0xffffffff,%ebx
jne    1150 <benchmark_image_transcode+0x30>
jmp    11a1 <benchmark_image_transcode+0x81>
xorpd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
divsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global double 0.000000e+00
define double @benchmark_image_transcode(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca double
%6 = alloca i32
%7 = alloca i64
%8 = alloca i64
store i32 %0, i32* %3
store i8* %1, i8** %4
store double 0.000000e+00, double* %5
store i32 0, i32* %6
store i32 0, i32* %6
br label %9
9: ; preds = %26, %2
%10 = load i32, i32* %6
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %29
13: ; preds = %9
%14 = call i64 (...) @clock()
store i64 %14, i64* %7
%15 = load i8*, i8** %4
%16 = call i32 @image_transcode_compute(i8* %15, i32 200)
%17 = call i64 (...) @clock()
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = load i64, i64* %7
%20 = sub nsw i64 %18, %19
%21 = sitofp i64 %20 to double
%22 = load double, double* @CLOCKS_PER_SEC
%23 = fdiv double %21, %22
%24 = load double, double* %5
%25 = call double @llvm.fmuladd.f64(double %23, double 1.000000e+03, double %24)
store double %25, double* %5
br label %26
26: ; preds = %13
%27 = load i32, i32* %6
%28 = add nsw i32 %27, 1
store i32 %28, i32* %6
br label %9
29: ; preds = %9
%30 = load double, double* %5
%31 = load i32, i32* %3
%32 = sitofp i32 %31 to double
%33 = fdiv double %30, %32
ret double %33
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
define double @benchmark_image_transcode(i32 %0, i8* %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %17
4: ; preds = %2, %4
%5 = phi double [ %14, %4 ], [ 0.000000e+00, %2 ]
%6 = phi i32 [ %15, %4 ], [ 0, %2 ]
%7 = tail call i64 (...) @clock()
%8 = tail call i32 @image_transcode_compute(i8* %1, i32 200)
%9 = tail call i64 (...) @clock()
%10 = sub nsw i64 %9, %7
%11 = sitofp i64 %10 to double
%12 = load double, double* @CLOCKS_PER_SEC
%13 = fdiv double %11, %12
%14 = tail call double @llvm.fmuladd.f64(double %13, double 1.000000e+03, double %5)
%15 = add nuw nsw i32 %6, 1
%16 = icmp eq i32 %15, %0
br i1 %16, label %17, label %4
17: ; preds = %4, %2
%18 = phi double [ 0.000000e+00, %2 ], [ %14, %4 ]
%19 = sitofp i32 %0 to double
%20 = fdiv double %18, %19
ret double %20
}