#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ hotLoop(int, int, double, double, double *, double *, int,
                           double *, double *, double, double *, double *,
                           char *, int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int bench(int inputN) {
  int w, h, bit_num = 0;
  char byte_acc = 0;
  int iter = 50;
  double x, y, limit = 2.0;
  double Zr, Zi, Cr, Ci, Tr, Ti;
  w = h = inputN;
  char filename[64];
  sprintf(filename, "mandelbrot-%d.txt", w);
  FILE *outStream = fopen(filename, "w+");
  printf("P4\n%d %d\n", w, h);
  for (y = 0; y < h; ++y) {
    for (x = 0; x < w; ++x) {
      Zr = Zi = Tr = Ti = 0.0;
      hotLoop(w, h, x, y, &Cr, &Ci, iter, &Tr, &Ti, limit, &Zr, &Zi, &byte_acc,
              &bit_num, outStream);
    }
  }
  fclose(outStream);
  return 0;
}


x86 assembly (clang, -O0):
<bench>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0xe8,%rsp
mov    %edi,-0x1c(%rbp)
movl   $0x0,-0x28(%rbp)
movb   $0x0,-0x29(%rbp)
movl   $0x32,-0x30(%rbp)
movsd  0xe83(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    %eax,-0x20(%rbp)
lea    -0xc0(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xe74(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0xc0(%rbp),%rdi
lea    0xe73(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0xc8(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
cvtsi2sdl -0x24(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12ba <bench+0x16a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
cvtsi2sdl -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    129e <bench+0x14e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
mov    -0x30(%rbp),%r8d
movsd  -0x48(%rbp),%xmm2
mov    -0xc8(%rbp),%rax
lea    -0x60(%rbp),%rdx
lea    -0x68(%rbp),%rcx
lea    -0x70(%rbp),%r9
lea    -0x78(%rbp),%r15
lea    -0x50(%rbp),%r14
lea    -0x58(%rbp),%rbx
lea    -0x29(%rbp),%r11
lea    -0x28(%rbp),%r10
mov    %r15,(%rsp)
mov    %r14,0x8(%rsp)
mov    %rbx,0x10(%rsp)
mov    %r11,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %rax,0x28(%rsp)
call   1050 <hotLoop@plt>
movsd  0xd79(%rip),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11f1 <bench+0xa1>
jmp    12a3 <bench+0x153>
movsd  0xd5d(%rip),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    11d5 <bench+0x85>
mov    -0xc8(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xe8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<bench>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %edi,%r15d
movl   $0x0,0x14(%rsp)
movb   $0x0,0xf(%rsp)
lea    0xe98(%rip),%rsi
lea    0x60(%rsp),%r14
mov    %r14,%rdi
mov    %r15d,%edx
call   1070 <sprintf@plt>
lea    0xe93(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
lea    0xe84(%rip),%rdi
mov    %r15d,%esi
mov    %r15d,%edx
call   1040 <printf@plt>
test   %r15d,%r15d
jle    12ac <bench+0x15c>
cvtsi2sd %r15d,%xmm3
xorpd  %xmm1,%xmm1
lea    0x14(%rsp),%rbp
lea    0xf(%rsp),%rbx
lea    0x40(%rsp),%r12
lea    0x48(%rsp),%r13
lea    0x30(%rsp),%rax
movsd  %xmm3,0x20(%rsp)
mov    %r15d,0x10(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
movsd  %xmm1,0x18(%rsp)
nopl   0x0(%rax)
movsd  %xmm0,0x28(%rsp)
movq   $0x0,0x30(%rsp)
movq   $0x0,0x38(%rsp)
movq   $0x0,0x40(%rsp)
movq   $0x0,0x48(%rsp)
mov    %r15d,%edi
mov    %r15d,%esi
movsd  0x18(%rsp),%xmm1
lea    0x58(%rsp),%rdx
lea    0x50(%rsp),%rcx
mov    $0x32,%r8d
lea    0x38(%rsp),%r9
movsd  0xdad(%rip),%xmm2
push   %r14
push   %rbp
push   %rbx
push   %r12
push   %r13
push   %rax
mov    %r14,%r15
mov    %rax,%r14
call   1050 <hotLoop@plt>
movsd  0x58(%rsp),%xmm0
movsd  0xd93(%rip),%xmm2
mov    %r14,%rax
mov    %r15,%r14
mov    0x40(%rsp),%r15d
movsd  0x48(%rsp),%xmm1
movsd  0x50(%rsp),%xmm3
add    $0x30,%rsp
addsd  %xmm2,%xmm0
ucomisd %xmm0,%xmm3
ja     1200 <bench+0xb0>
addsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm3
ja     11f0 <bench+0xa0>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"mandelbrot-%d.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [10 x i8] c"P4\0A%d %d\0A\00"
define i32 @bench(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca [64 x i8]
%18 = alloca i32*
store i32 %0, i32* %2
store i32 0, i32* %5
store i8 0, i8* %6
store i32 50, i32* %7
store double 2.000000e+00, double* %10
%19 = load i32, i32* %2
store i32 %19, i32* %4
store i32 %19, i32* %3
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %17, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %17, i64 0, i64 0
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %18
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 %26)
store double 0.000000e+00, double* %9
br label %28
28: ; preds = %52, %1
%29 = load double, double* %9
%30 = load i32, i32* %4
%31 = sitofp i32 %30 to double
%32 = fcmp olt double %29, %31
br i1 %32, label %33, label %55
33: ; preds = %28
store double 0.000000e+00, double* %8
br label %34
34: ; preds = %48, %33
%35 = load double, double* %8
%36 = load i32, i32* %3
%37 = sitofp i32 %36 to double
%38 = fcmp olt double %35, %37
br i1 %38, label %39, label %51
39: ; preds = %34
store double 0.000000e+00, double* %16
store double 0.000000e+00, double* %15
store double 0.000000e+00, double* %12
store double 0.000000e+00, double* %11
%40 = load i32, i32* %3
%41 = load i32, i32* %4
%42 = load double, double* %8
%43 = load double, double* %9
%44 = load i32, i32* %7
%45 = load double, double* %10
%46 = load i32*, i32** %18
%47 = call i32 @hotLoop(i32 %40, i32 %41, double %42, double %43, double* %13, double* %14, i32 %44, double* %15, double* %16, double %45, double* %11, double* %12, i8* %6, i32* %5, i32* %46)
br label %48
48: ; preds = %39
%49 = load double, double* %8
%50 = fadd double %49, 1.000000e+00
store double %50, double* %8
br label %34
51: ; preds = %34
br label %52
52: ; preds = %51
%53 = load double, double* %9
%54 = fadd double %53, 1.000000e+00
store double %54, double* %9
br label %28
55: ; preds = %28
%56 = load i32*, i32** %18
%57 = call i32 @fclose(i32* %56)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"mandelbrot-%d.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [10 x i8] c"P4\0A%d %d\0A\00"
define i32 @bench(i32 %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca [64 x i8]
%11 = bitcast i32* %2 to i8*
store i32 0, i32* %2
store i8 0, i8* %3
%12 = bitcast double* %4 to i8*
%13 = bitcast double* %5 to i8*
%14 = bitcast double* %6 to i8*
%15 = bitcast double* %7 to i8*
%16 = bitcast double* %8 to i8*
%17 = bitcast double* %9 to i8*
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %10, i64 0, i64 0
%19 = call i32 @sprintf(i8* %18, i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %0)
%20 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %0)
%22 = sitofp i32 %0 to double
%23 = icmp sgt i32 %0, 0
br i1 %23, label %24, label %34
24: ; preds = %1, %31
%25 = phi double [ %32, %31 ], [ 0.000000e+00, %1 ]
br label %26
26: ; preds = %24, %26
%27 = phi double [ %29, %26 ], [ 0.000000e+00, %24 ]
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %5
store double 0.000000e+00, double* %4
%28 = call i32 @hotLoop(i32 %0, i32 %0, double %27, double %25, double* %6, double* %7, i32 50, double* %8, double* %9, double 2.000000e+00, double* %4, double* %5, i8* %3, i32* %2, i32* %20)
%29 = fadd double %27, 1.000000e+00
%30 = fcmp olt double %29, %22
br i1 %30, label %26, label %31
31: ; preds = %26
%32 = fadd double %25, 1.000000e+00
%33 = fcmp olt double %32, %22
br i1 %33, label %24, label %34
34: ; preds = %31, %1
%35 = call i32 @fclose(i32* %20)
ret i32 0
}