#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_resize(char const *, void **, size_t *, int, int, int,
                                int /*<<< orphan*/);
double benchmark_image_resize(int n, const char *input) {
  double total = 0;
  void *buffer;
  size_t len;
  int i = 0;
  for (i = 0; i < n; i++) {
    clock_t begin = clock();
    image_resize(input, &buffer, &len, 200, 1, 90, 0);
    clock_t end = clock();
    total += (double)(end - begin) / CLOCKS_PER_SEC * 1000;
  }
  return total / n;
}


x86 assembly (clang, -O0):
<benchmark_image_resize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d2 <benchmark_image_resize+0xb2>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
mov    $0xc8,%ecx
mov    $0x1,%r8d
mov    $0x5a,%r9d
xor    %eax,%eax
movl   $0x0,(%rsp)
call   1030 <image_resize@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
sub    -0x38(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e42(%rip),%rax
divsd  (%rax),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe49(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1145 <benchmark_image_resize+0x25>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark_image_resize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %edi,%edi
mov    %edi,0xc(%rsp)
jle    11c8 <benchmark_image_resize+0xa8>
mov    %rsi,%rbx
xorpd  %xmm0,%xmm0
lea    0x20(%rsp),%r15
lea    0x18(%rsp),%r12
mov    0x2e96(%rip),%r13
mov    %edi,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbp
movl   $0x0,(%rsp)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    $0xc8,%ecx
mov    $0x1,%r8d
mov    $0x5a,%r9d
call   1030 <image_resize@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  0x10(%rsp),%xmm0
sub    %rbp,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  0x0(%r13),%xmm1
mulsd  0xe44(%rip),%xmm1
addsd  %xmm1,%xmm0
add    $0xffffffff,%r14d
jne    1160 <benchmark_image_resize+0x40>
jmp    11cc <benchmark_image_resize+0xac>
xorpd  %xmm0,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdl 0xc(%rsp),%xmm1
divsd  %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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