#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 */
double pow(double, int);
int mandelbrot(double c_x, double c_y, int n) {
  double x_n = 0, y_n = 0, x_n_1, y_n_1;
  for (int i = 0; i < n; i++) {
    x_n_1 = pow(x_n, 2) - pow(y_n, 2) + c_x;
    y_n_1 = 2.0 * x_n * y_n + c_y;
    if (pow(x_n_1, 2) + pow(y_n_1, 2) > 4.0) {
      return n;
    } else {
      x_n = x_n_1;
      y_n = y_n_1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<mandelbrot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1218 <mandelbrot+0x108>
movsd  -0x28(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
subsd  %xmm1,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe7f(%rip),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x40(%rbp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xe24(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11f1 <mandelbrot+0xe1>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121f <mandelbrot+0x10f>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    120a <mandelbrot+0xfa>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    113c <mandelbrot+0x2c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mandelbrot>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
movsd  %xmm1,0x28(%rsp)
movsd  %xmm0,0x20(%rsp)
xor    %r14d,%r14d
test   %edi,%edi
jle    11e7 <mandelbrot+0xd7>
mov    %edi,%ebx
xorps  %xmm1,%xmm1
mov    %edi,%ebp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
movaps %xmm1,%xmm0
movsd  %xmm1,0x10(%rsp)
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  0x18(%rsp),%xmm2
subsd  %xmm0,%xmm2
addsd  0x20(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
addsd  %xmm1,%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  %xmm1,%xmm0
addsd  0x28(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  %xmm2,0x18(%rsp)
movapd %xmm2,%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
mov    $0x2,%edi
call   1030 <pow@plt>
addsd  0x10(%rsp),%xmm0
ucomisd 0xe2f(%rip),%xmm0
ja     11e4 <mandelbrot+0xd4>
add    $0xffffffff,%ebp
movsd  0x18(%rsp),%xmm1
jne    1140 <mandelbrot+0x30>
jmp    11e7 <mandelbrot+0xd7>
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @mandelbrot(double %0, double %1, i32 %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca i32
store double %0, double* %5
store double %1, double* %6
store i32 %2, i32* %7
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
store i32 0, i32* %12
br label %13
13: ; preds = %42, %3
%14 = load i32, i32* %12
%15 = load i32, i32* %7
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %45
17: ; preds = %13
%18 = load double, double* %8
%19 = call double @pow(double %18, i32 2)
%20 = load double, double* %9
%21 = call double @pow(double %20, i32 2)
%22 = fsub double %19, %21
%23 = load double, double* %5
%24 = fadd double %22, %23
store double %24, double* %10
%25 = load double, double* %8
%26 = fmul double 2.000000e+00, %25
%27 = load double, double* %9
%28 = load double, double* %6
%29 = call double @llvm.fmuladd.f64(double %26, double %27, double %28)
store double %29, double* %11
%30 = load double, double* %10
%31 = call double @pow(double %30, i32 2)
%32 = load double, double* %11
%33 = call double @pow(double %32, i32 2)
%34 = fadd double %31, %33
%35 = fcmp ogt double %34, 4.000000e+00
br i1 %35, label %36, label %38
36: ; preds = %17
%37 = load i32, i32* %7
store i32 %37, i32* %4
br label %46
38: ; preds = %17
%39 = load double, double* %10
store double %39, double* %8
%40 = load double, double* %11
store double %40, double* %9
br label %41
41: ; preds = %38
br label %42
42: ; preds = %41
%43 = load i32, i32* %12
%44 = add nsw i32 %43, 1
store i32 %44, i32* %12
br label %13
45: ; preds = %13
store i32 0, i32* %4
br label %46
46: ; preds = %45, %36
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
define i32 @mandelbrot(double %0, double %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %7, label %22
5: ; preds = %7
%6 = icmp eq i32 %21, %2
br i1 %6, label %22, label %7
7: ; preds = %3, %5
%8 = phi i32 [ %21, %5 ], [ 0, %3 ]
%9 = phi double [ %14, %5 ], [ 0.000000e+00, %3 ]
%10 = phi double [ %16, %5 ], [ 0.000000e+00, %3 ]
%11 = tail call double @pow(double %9, i32 2)
%12 = tail call double @pow(double %10, i32 2)
%13 = fsub double %11, %12
%14 = fadd double %13, %0
%15 = fmul double %9, 2.000000e+00
%16 = tail call double @llvm.fmuladd.f64(double %15, double %10, double %1)
%17 = tail call double @pow(double %14, i32 2)
%18 = tail call double @pow(double %16, i32 2)
%19 = fadd double %17, %18
%20 = fcmp ogt double %19, 4.000000e+00
%21 = add nuw nsw i32 %8, 1
br i1 %20, label %22, label %5
22: ; preds = %5, %7, %3
%23 = phi i32 [ 0, %3 ], [ %2, %7 ], [ 0, %5 ]
ret i32 %23
}