#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 fmax(double, double);
int /*<<< orphan*/ printf(char *, ...);
void mandel(void) {
  int w = 80;
  int h = 40;
  int iter = 100;
  int i, j, k;
  double x0, y0, xx, yy, xx2, yy2;
  char c;
  for (i = 0; i - h; i += 1) {
    y0 = ((double)i / (double)h) * 4.0 - 2.0;
    for (j = 0; j - w; j += 1) {
      x0 = ((double)j / (double)w) * 4.0 - 2.0;
      xx = 0.0;
      yy = 0.0;
      c = '#';
      for (k = 0; k - iter; k += 1) {
        xx2 = xx * xx;
        yy2 = yy * yy;
        if (fmax(0.0, 4.0 - (xx2 + yy2)) != 0.0) {
          yy = 2 * xx * yy + y0;
          xx = xx2 - yy2 + x0;
        } else {
          c = '.';
          break;
        }
      }
      printf("%c", c);
    }
    printf("\n");
  }
}


x86 assembly (clang, -O0):
<mandel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x50,-0x4(%rbp)
movl   $0x28,-0x8(%rbp)
movl   $0x64,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    -0x8(%rbp),%eax
cmp    $0x0,%eax
je     12c1 <mandel+0x1b1>
cvtsi2sdl -0x10(%rbp),%xmm0
cvtsi2sdl -0x8(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xea7(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xea3(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    -0x4(%rbp),%eax
cmp    $0x0,%eax
je     12a5 <mandel+0x195>
cvtsi2sdl -0x14(%rbp),%xmm0
cvtsi2sdl -0x4(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe66(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe62(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movb   $0x23,-0x49(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
sub    -0xc(%rbp),%eax
cmp    $0x0,%eax
je     1285 <mandel+0x175>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm1
addsd  -0x48(%rbp),%xmm1
movsd  0xdf7(%rip),%xmm0
subsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
maxsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    122c <mandel+0x11c>
jp     122c <mandel+0x11c>
jmp    1269 <mandel+0x159>
movsd  0xddc(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x40(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1272 <mandel+0x162>
movb   $0x2e,-0x49(%rbp)
jmp    1285 <mandel+0x175>
jmp    1277 <mandel+0x167>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ca <mandel+0xba>
movsbl -0x49(%rbp),%esi
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1175 <mandel+0x65>
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1134 <mandel+0x24>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mandel>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
xor    %ebx,%ebx
movsd  0xee8(%rip),%xmm0
xorpd  %xmm1,%xmm1
jmp    115b <mandel+0x4b>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
movsd  (%rsp),%xmm1
addsd  0xed9(%rip),%xmm1
add    $0x1,%ebx
cmp    $0x28,%ebx
movsd  0xeb3(%rip),%xmm0
je     1259 <mandel+0x149>
movsd  %xmm1,(%rsp)
movapd %xmm1,%xmm9
divsd  0xe92(%rip),%xmm9
mulsd  %xmm0,%xmm9
addsd  0xe94(%rip),%xmm9
xorpd  %xmm0,%xmm0
xor    %ebp,%ebp
movsd  %xmm9,0x8(%rsp)
jmp    11bb <mandel+0xab>
nopl   0x0(%rax,%rax,1)
mov    $0x2e,%edi
call   1030 <putchar@plt>
movsd  0x10(%rsp),%xmm0
addsd  0xe78(%rip),%xmm0
add    $0x1,%ebp
cmp    $0x50,%ebp
movsd  0x8(%rsp),%xmm9
je     1130 <mandel+0x20>
movsd  %xmm0,0x10(%rsp)
divsd  0xe4f(%rip),%xmm0
movsd  0xe36(%rip),%xmm8
mulsd  %xmm8,%xmm0
addsd  0xe31(%rip),%xmm0
xorpd  %xmm3,%xmm3
mov    $0x64,%eax
xorpd  %xmm2,%xmm2
movapd %xmm2,%xmm1
xorpd  %xmm7,%xmm7
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mulsd  %xmm1,%xmm1
movapd %xmm3,%xmm4
mulsd  %xmm3,%xmm4
movapd %xmm1,%xmm5
addsd  %xmm4,%xmm5
movapd %xmm8,%xmm6
subsd  %xmm5,%xmm6
maxsd  %xmm7,%xmm6
ucomisd %xmm7,%xmm6
jne    122d <mandel+0x11d>
jnp    1190 <mandel+0x80>
addsd  %xmm2,%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm9,%xmm2
subsd  %xmm4,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm2,%xmm3
movapd %xmm1,%xmm2
add    $0xffffffff,%eax
jne    1200 <mandel+0xf0>
mov    $0x23,%edi
jmp    1195 <mandel+0x85>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @mandel() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca i8
store i32 80, i32* %1
store i32 40, i32* %2
store i32 100, i32* %3
store i32 0, i32* %4
br label %14
14: ; preds = %81, %0
%15 = load i32, i32* %4
%16 = load i32, i32* %2
%17 = sub nsw i32 %15, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %84
19: ; preds = %14
%20 = load i32, i32* %4
%21 = sitofp i32 %20 to double
%22 = load i32, i32* %2
%23 = sitofp i32 %22 to double
%24 = fdiv double %21, %23
%25 = call double @llvm.fmuladd.f64(double %24, double 4.000000e+00, double -2.000000e+00)
store double %25, double* %8
store i32 0, i32* %5
br label %26
26: ; preds = %76, %19
%27 = load i32, i32* %5
%28 = load i32, i32* %1
%29 = sub nsw i32 %27, %28
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %79
31: ; preds = %26
%32 = load i32, i32* %5
%33 = sitofp i32 %32 to double
%34 = load i32, i32* %1
%35 = sitofp i32 %34 to double
%36 = fdiv double %33, %35
%37 = call double @llvm.fmuladd.f64(double %36, double 4.000000e+00, double -2.000000e+00)
store double %37, double* %7
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %10
store i8 35, i8* %13
store i32 0, i32* %6
br label %38
38: ; preds = %69, %31
%39 = load i32, i32* %6
%40 = load i32, i32* %3
%41 = sub nsw i32 %39, %40
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %72
43: ; preds = %38
%44 = load double, double* %9
%45 = load double, double* %9
%46 = fmul double %44, %45
store double %46, double* %11
%47 = load double, double* %10
%48 = load double, double* %10
%49 = fmul double %47, %48
store double %49, double* %12
%50 = load double, double* %11
%51 = load double, double* %12
%52 = fadd double %50, %51
%53 = fsub double 4.000000e+00, %52
%54 = call double @llvm.maxnum.f64(double 0.000000e+00, double %53)
%55 = fcmp une double %54, 0.000000e+00
br i1 %55, label %56, label %67
56: ; preds = %43
%57 = load double, double* %9
%58 = fmul double 2.000000e+00, %57
%59 = load double, double* %10
%60 = load double, double* %8
%61 = call double @llvm.fmuladd.f64(double %58, double %59, double %60)
store double %61, double* %10
%62 = load double, double* %11
%63 = load double, double* %12
%64 = fsub double %62, %63
%65 = load double, double* %7
%66 = fadd double %64, %65
store double %66, double* %9
br label %68
67: ; preds = %43
store i8 46, i8* %13
br label %72
68: ; preds = %56
br label %69
69: ; preds = %68
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 1
store i32 %71, i32* %6
br label %38
72: ; preds = %67, %38
%73 = load i8, i8* %13
%74 = sext i8 %73 to i32
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %72
%77 = load i32, i32* %5
%78 = add nsw i32 %77, 1
store i32 %78, i32* %5
br label %26
79: ; preds = %26
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %81
81: ; preds = %79
%82 = load i32, i32* %4
%83 = add nsw i32 %82, 1
store i32 %83, i32* %4
br label %14
84: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @mandel() {
br label %1
1: ; preds = %0, %33
%2 = phi i32 [ 0, %0 ], [ %35, %33 ]
%3 = sitofp i32 %2 to double
%4 = fdiv double %3, 4.000000e+01
%5 = tail call double @llvm.fmuladd.f64(double %4, double 4.000000e+00, double -2.000000e+00)
br label %6
6: ; preds = %1, %28
%7 = phi i32 [ 0, %1 ], [ %31, %28 ]
%8 = sitofp i32 %7 to double
%9 = fdiv double %8, 8.000000e+01
%10 = tail call double @llvm.fmuladd.f64(double %9, double 4.000000e+00, double -2.000000e+00)
br label %11
11: ; preds = %6, %21
%12 = phi double [ 0.000000e+00, %6 ], [ %23, %21 ]
%13 = phi double [ 0.000000e+00, %6 ], [ %25, %21 ]
%14 = phi i32 [ 0, %6 ], [ %26, %21 ]
%15 = fmul double %13, %13
%16 = fmul double %12, %12
%17 = fadd double %15, %16
%18 = fsub double 4.000000e+00, %17
%19 = tail call double @llvm.maxnum.f64(double %18, double 0.000000e+00)
%20 = fcmp une double %19, 0.000000e+00
br i1 %20, label %21, label %28
21: ; preds = %11
%22 = fmul double %13, 2.000000e+00
%23 = tail call double @llvm.fmuladd.f64(double %22, double %12, double %5)
%24 = fsub double %15, %16
%25 = fadd double %10, %24
%26 = add nuw nsw i32 %14, 1
%27 = icmp eq i32 %26, 100
br i1 %27, label %28, label %11
28: ; preds = %11, %21
%29 = phi i32 [ 35, %21 ], [ 46, %11 ]
%30 = tail call i32 @putchar(i32 %29)
%31 = add nuw nsw i32 %7, 1
%32 = icmp eq i32 %31, 80
br i1 %32, label %33, label %6
33: ; preds = %28
%34 = tail call i32 @putchar(i32 10)
%35 = add nuw nsw i32 %2, 1
%36 = icmp eq i32 %35, 40
br i1 %36, label %37, label %1
37: ; preds = %33
ret void
}