#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 */

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int log(int);
scalar_t__ malloc(int);
int sqrt(double);
int /*<<< orphan*/ stderr;
double *mandelbrot_end(int s, double xs, double ys, double r, int it) {
  double *buffer = (double *)malloc(s * s * sizeof(double));
  if (buffer == NULL) {
    fprintf(stderr, "out of memory\n");
    return NULL;
  }
  int xPos, yPos;
  for (yPos = 0; yPos < s; yPos++) {
    double yP = (ys - r) + (2.0f * r / s) * yPos;
    for (xPos = 0; xPos < s; xPos++) {
      double xP = (xs - r) + (2.0f * r / s) * xPos;
      int iteration = 1;
      double x = 0;
      double y = 0;
      while (x * x + y * y <= 4 && iteration < it) {
        double tmp = x * x - y * y + xP;
        y = 2 * x * y + yP;
        x = tmp;
        iteration++;
      }
      buffer[yPos * s + xPos] =
          iteration < it ? iteration - (log(log(sqrt(x * x + y * y)))) / log(2)
                         : 0;
    }
  }
  return buffer;
}


x86 assembly (clang, -O0):
<mandelbrot_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0xc(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  %xmm2,-0x28(%rbp)
mov    %esi,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
imul   -0xc(%rbp),%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11a5 <mandelbrot_end+0x65>
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1030 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    13c3 <mandelbrot_end+0x283>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    13bb <mandelbrot_end+0x27b>
movsd  -0x20(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movsd  0xe36(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm2
divsd  %xmm2,%xmm0
cvtsi2sdl -0x40(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    13a8 <mandelbrot_end+0x268>
movsd  -0x18(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movsd  0xdf1(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
cvtsi2sdl -0xc(%rbp),%xmm2
divsd  %xmm2,%xmm0
cvtsi2sdl -0x3c(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x1,-0x54(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm2
movsd  -0x68(%rbp),%xmm0
mulsd  -0x68(%rbp),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
xor    %eax,%eax
movsd  0xd9c(%rip),%xmm0
ucomisd %xmm1,%xmm0
mov    %al,-0x71(%rbp)
jb     1285 <mandelbrot_end+0x145>
mov    -0x54(%rbp),%eax
cmp    -0x2c(%rbp),%eax
setl   %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
test   $0x1,%al
jne    1295 <mandelbrot_end+0x155>
jmp    130e <mandelbrot_end+0x1ce>
movsd  -0x60(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x68(%rbp),%xmm1
mulsd  -0x68(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  0xd26(%rip),%xmm0
mulsd  -0x60(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1246 <mandelbrot_end+0x106>
mov    -0x54(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1373 <mandelbrot_end+0x233>
mov    -0x54(%rbp),%eax
mov    %eax,-0x7c(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x68(%rbp),%xmm1
mulsd  -0x68(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1050 <log@plt>
mov    %eax,%edi
call   1050 <log@plt>
mov    %eax,-0x80(%rbp)
mov    $0x2,%edi
call   1050 <log@plt>
mov    %eax,%ecx
mov    -0x80(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x7c(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x78(%rbp)
jmp    137d <mandelbrot_end+0x23d>
xor    %eax,%eax
mov    %eax,-0x78(%rbp)
jmp    137d <mandelbrot_end+0x23d>
mov    -0x78(%rbp),%eax
cvtsi2sd %eax,%xmm0
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%ecx
imul   -0xc(%rbp),%ecx
add    -0x3c(%rbp),%ecx
movslq %ecx,%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11f1 <mandelbrot_end+0xb1>
jmp    13ad <mandelbrot_end+0x26d>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11ac <mandelbrot_end+0x6c>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mandelbrot_end>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %esi,%ebx
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x10(%rsp)
mov    %edi,%ebp
imul   %edi,%edi
shl    $0x3,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1309 <mandelbrot_end+0x1c9>
mov    %rax,%rcx
test   %ebp,%ebp
jle    1320 <mandelbrot_end+0x1e0>
movsd  0x18(%rsp),%xmm5
movsd  0x8(%rsp),%xmm0
subsd  %xmm5,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x10(%rsp),%xmm8
subsd  %xmm5,%xmm8
addsd  %xmm5,%xmm5
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
divsd  %xmm0,%xmm5
mov    %ebp,%r13d
xor    %r15d,%r15d
movsd  0xe3e(%rip),%xmm7
movsd  %xmm5,0x18(%rsp)
movsd  %xmm8,0x10(%rsp)
mov    %rcx,0x28(%rsp)
jmp    11f2 <mandelbrot_end+0xb2>
cs nopw 0x0(%rax,%rax,1)
mov    0x20(%rsp),%r15
add    $0x1,%r15
cmp    %r13,%r15
je     1320 <mandelbrot_end+0x1e0>
xorps  %xmm6,%xmm6
cvtsi2sd %r15d,%xmm6
mulsd  %xmm5,%xmm6
addsd  0x8(%rsp),%xmm6
mov    %r15,0x20(%rsp)
imul   %r13,%r15
xor    %r12d,%r12d
movsd  %xmm6,0x30(%rsp)
jmp    1239 <mandelbrot_end+0xf9>
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
lea    (%r12,%r15,1),%rax
movsd  %xmm0,(%rcx,%rax,8)
add    $0x1,%r12
cmp    %r13,%r12
je     11e0 <mandelbrot_end+0xa0>
xor    %eax,%eax
cmp    $0x2,%ebx
jl     1220 <mandelbrot_end+0xe0>
xorps  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm1
mulsd  %xmm5,%xmm1
addsd  %xmm8,%xmm1
mov    $0x1,%r14d
xorpd  %xmm4,%xmm4
xorpd  %xmm2,%xmm2
xorpd  %xmm3,%xmm3
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm3
subsd  %xmm4,%xmm3
addsd  %xmm1,%xmm3
addsd  %xmm0,%xmm0
mulsd  %xmm0,%xmm2
addsd  %xmm6,%xmm2
add    $0x1,%r14d
movapd %xmm2,%xmm4
mulsd  %xmm2,%xmm4
movapd %xmm3,%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm4,%xmm0
ucomisd %xmm0,%xmm7
jb     12af <mandelbrot_end+0x16f>
cmp    %ebx,%r14d
jl     1270 <mandelbrot_end+0x130>
cmp    %ebx,%r14d
jge    1220 <mandelbrot_end+0xe0>
call   1060 <sqrt@plt>
mov    %eax,%edi
call   1050 <log@plt>
mov    %eax,%edi
call   1050 <log@plt>
mov    %eax,%ebp
mov    $0x2,%edi
call   1050 <log@plt>
movsd  0x30(%rsp),%xmm6
movsd  0xd1b(%rip),%xmm7
movsd  0x10(%rsp),%xmm8
movsd  0x18(%rsp),%xmm5
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    0x28(%rsp),%rcx
sub    %eax,%r14d
mov    %r14d,%eax
jmp    1220 <mandelbrot_end+0xe0>
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
lea    0xcef(%rip),%rsi
call   1030 <fprintf@plt>
xor    %ecx,%ecx
mov    %rcx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
define double* @mandelbrot_end(i32 %0, double %1, double %2, double %3, i32 %4) {
%6 = alloca double*
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca i32
%12 = alloca double*
%13 = alloca i32
%14 = alloca i32
%15 = alloca double
%16 = alloca double
%17 = alloca i32
%18 = alloca double
%19 = alloca double
%20 = alloca double
store i32 %0, i32* %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store i32 %4, i32* %11
%21 = load i32, i32* %7
%22 = load i32, i32* %7
%23 = mul nsw i32 %21, %22
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 8
%26 = trunc i64 %25 to i32
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to double*
store double* %28, double** %12
%29 = load double*, double** %12
%30 = icmp eq double* %29, null
br i1 %30, label %31, label %34
31: ; preds = %5
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store double* null, double** %6
br label %138
34: ; preds = %5
store i32 0, i32* %14
br label %35
35: ; preds = %133, %34
%36 = load i32, i32* %14
%37 = load i32, i32* %7
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %136
39: ; preds = %35
%40 = load double, double* %9
%41 = load double, double* %10
%42 = fsub double %40, %41
%43 = load double, double* %10
%44 = fmul double 2.000000e+00, %43
%45 = load i32, i32* %7
%46 = sitofp i32 %45 to double
%47 = fdiv double %44, %46
%48 = load i32, i32* %14
%49 = sitofp i32 %48 to double
%50 = call double @llvm.fmuladd.f64(double %47, double %49, double %42)
store double %50, double* %15
store i32 0, i32* %13
br label %51
51: ; preds = %129, %39
%52 = load i32, i32* %13
%53 = load i32, i32* %7
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %132
55: ; preds = %51
%56 = load double, double* %8
%57 = load double, double* %10
%58 = fsub double %56, %57
%59 = load double, double* %10
%60 = fmul double 2.000000e+00, %59
%61 = load i32, i32* %7
%62 = sitofp i32 %61 to double
%63 = fdiv double %60, %62
%64 = load i32, i32* %13
%65 = sitofp i32 %64 to double
%66 = call double @llvm.fmuladd.f64(double %63, double %65, double %58)
store double %66, double* %16
store i32 1, i32* %17
store double 0.000000e+00, double* %18
store double 0.000000e+00, double* %19
br label %67
67: ; preds = %81, %55
%68 = load double, double* %18
%69 = load double, double* %18
%70 = load double, double* %19
%71 = load double, double* %19
%72 = fmul double %70, %71
%73 = call double @llvm.fmuladd.f64(double %68, double %69, double %72)
%74 = fcmp ole double %73, 4.000000e+00
br i1 %74, label %75, label %79
75: ; preds = %67
%76 = load i32, i32* %17
%77 = load i32, i32* %11
%78 = icmp slt i32 %76, %77
br label %79
79: ; preds = %75, %67
%80 = phi i1 [ false, %67 ], [ %78, %75 ]
br i1 %80, label %81, label %99
81: ; preds = %79
%82 = load double, double* %18
%83 = load double, double* %18
%84 = load double, double* %19
%85 = load double, double* %19
%86 = fmul double %84, %85
%87 = fneg double %86
%88 = call double @llvm.fmuladd.f64(double %82, double %83, double %87)
%89 = load double, double* %16
%90 = fadd double %88, %89
store double %90, double* %20
%91 = load double, double* %18
%92 = fmul double 2.000000e+00, %91
%93 = load double, double* %19
%94 = load double, double* %15
%95 = call double @llvm.fmuladd.f64(double %92, double %93, double %94)
store double %95, double* %19
%96 = load double, double* %20
store double %96, double* %18
%97 = load i32, i32* %17
%98 = add nsw i32 %97, 1
store i32 %98, i32* %17
br label %67
99: ; preds = %79
%100 = load i32, i32* %17
%101 = load i32, i32* %11
%102 = icmp slt i32 %100, %101
br i1 %102, label %103, label %117
103: ; preds = %99
%104 = load i32, i32* %17
%105 = load double, double* %18
%106 = load double, double* %18
%107 = load double, double* %19
%108 = load double, double* %19
%109 = fmul double %107, %108
%110 = call double @llvm.fmuladd.f64(double %105, double %106, double %109)
%111 = call i32 @sqrt(double %110)
%112 = call i32 @log(i32 %111)
%113 = call i32 @log(i32 %112)
%114 = call i32 @log(i32 2)
%115 = sdiv i32 %113, %114
%116 = sub nsw i32 %104, %115
br label %118
117: ; preds = %99
br label %118
118: ; preds = %117, %103
%119 = phi i32 [ %116, %103 ], [ 0, %117 ]
%120 = sitofp i32 %119 to double
%121 = load double*, double** %12
%122 = load i32, i32* %14
%123 = load i32, i32* %7
%124 = mul nsw i32 %122, %123
%125 = load i32, i32* %13
%126 = add nsw i32 %124, %125
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds double, double* %121, i64 %127
store double %120, double* %128
br label %129
129: ; preds = %118
%130 = load i32, i32* %13
%131 = add nsw i32 %130, 1
store i32 %131, i32* %13
br label %51
132: ; preds = %51
br label %133
133: ; preds = %132
%134 = load i32, i32* %14
%135 = add nsw i32 %134, 1
store i32 %135, i32* %14
br label %35
136: ; preds = %35
%137 = load double*, double** %12
store double* %137, double** %6
br label %138
138: ; preds = %136, %31
%139 = load double*, double** %6
ret double* %139
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
define double* @mandelbrot_end(i32 %0, double %1, double %2, double %3, i32 %4) {
%6 = shl i32 %0, 3
%7 = mul i32 %6, %0
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to double*
%10 = icmp eq i64 %8, 0
br i1 %10, label %22, label %11
11: ; preds = %5
%12 = icmp sgt i32 %0, 0
br i1 %12, label %13, label %70
13: ; preds = %11
%14 = fsub double %2, %3
%15 = fmul double %3, 2.000000e+00
%16 = sitofp i32 %0 to double
%17 = fdiv double %15, %16
%18 = fsub double %1, %3
%19 = icmp sgt i32 %4, 1
%20 = zext i32 %0 to i64
%21 = zext i32 %0 to i64
br label %25
22: ; preds = %5
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %70
25: ; preds = %67, %13
%26 = phi i64 [ 0, %13 ], [ %68, %67 ]
%27 = trunc i64 %26 to i32
%28 = sitofp i32 %27 to double
%29 = tail call double @llvm.fmuladd.f64(double %17, double %28, double %14)
%30 = mul nsw i64 %26, %20
br label %31
31: ; preds = %25, %60
%32 = phi i64 [ 0, %25 ], [ %65, %60 ]
%33 = trunc i64 %32 to i32
%34 = sitofp i32 %33 to double
%35 = tail call double @llvm.fmuladd.f64(double %17, double %34, double %18)
br i1 %19, label %36, label %60
36: ; preds = %31, %36
%37 = phi double [ %47, %36 ], [ 0.000000e+00, %31 ]
%38 = phi double [ %45, %36 ], [ 0.000000e+00, %31 ]
%39 = phi double [ %43, %36 ], [ 0.000000e+00, %31 ]
%40 = phi i32 [ %46, %36 ], [ 1, %31 ]
%41 = fneg double %37
%42 = tail call double @llvm.fmuladd.f64(double %39, double %39, double %41)
%43 = fadd double %35, %42
%44 = fmul double %39, 2.000000e+00
%45 = tail call double @llvm.fmuladd.f64(double %44, double %38, double %29)
%46 = add nuw nsw i32 %40, 1
%47 = fmul double %45, %45
%48 = tail call double @llvm.fmuladd.f64(double %43, double %43, double %47)
%49 = fcmp ole double %48, 4.000000e+00
%50 = icmp slt i32 %46, %4
%51 = select i1 %49, i1 %50, i1 false
br i1 %51, label %36, label %52
52: ; preds = %36
br i1 %50, label %53, label %60
53: ; preds = %52
%54 = tail call i32 @sqrt(double %48)
%55 = tail call i32 @log(i32 %54)
%56 = tail call i32 @log(i32 %55)
%57 = tail call i32 @log(i32 2)
%58 = sdiv i32 %56, %57
%59 = sub nsw i32 %46, %58
br label %60
60: ; preds = %31, %52, %53
%61 = phi i32 [ %59, %53 ], [ 0, %52 ], [ 0, %31 ]
%62 = sitofp i32 %61 to double
%63 = add nuw nsw i64 %32, %30
%64 = getelementptr inbounds double, double* %9, i64 %63
store double %62, double* %64
%65 = add nuw nsw i64 %32, 1
%66 = icmp eq i64 %65, %21
br i1 %66, label %67, label %31
67: ; preds = %60
%68 = add nuw nsw i64 %26, 1
%69 = icmp eq i64 %68, %21
br i1 %69, label %70, label %25
70: ; preds = %67, %11, %22
%71 = phi double* [ null, %22 ], [ %9, %11 ], [ %9, %67 ]
ret double* %71
}