#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 */
long int_to_fix(int);
long escape_iteration_count(long cx, long cy) {
  long zx = 0, zy = 0, zx2 = 0, zy2 = 0;
  unsigned long i = 0;
  unsigned long const iteration_limit = 256;
  while (((zx2 + zy2) < int_to_fix(4)) && (i < iteration_limit)) {
    long tx, ty;
    zx2 = (zx * zx) >> 16;
    zy2 = (zy * zy) >> 16;
    tx = cx + (zx2 - zy2);
    ty = cy + ((zx * zy) >> 15);
    i++;
    zx = tx;
    zy = ty;
  }
  return (i == iteration_limit) ? -1 : i;
}


x86 assembly (clang, -O0):
<escape_iteration_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x100,-0x40(%rbp)
mov    -0x28(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    $0x4,%edi
call   1030 <int_to_fix@plt>
mov    -0x60(%rbp),%rcx
mov    %rax,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x51(%rbp)
jge    1189 <escape_iteration_count+0x79>
cmpq   $0x100,-0x38(%rbp)
setb   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    1199 <escape_iteration_count+0x89>
jmp    1207 <escape_iteration_count+0xf7>
mov    -0x18(%rbp),%rax
imul   -0x18(%rbp),%rax
sar    $0x10,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
imul   -0x20(%rbp),%rax
sar    $0x10,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
imul   -0x20(%rbp),%rcx
sar    $0xf,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x50(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1150 <escape_iteration_count+0x40>
cmpq   $0x100,-0x38(%rbp)
jne    1225 <escape_iteration_count+0x115>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x68(%rbp)
jmp    122d <escape_iteration_count+0x11d>
mov    -0x38(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<escape_iteration_count>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x8(%rsp)
mov    %rdi,(%rsp)
mov    $0x4,%edi
call   1030 <int_to_fix@plt>
test   %rax,%rax
jle    11b2 <escape_iteration_count+0xa2>
xor    %r13d,%r13d
xor    %r15d,%r15d
xor    %r12d,%r12d
nop
mov    %r13,%rbx
imul   %r13,%rbx
shr    $0x10,%rbx
mov    %r15,%r14
imul   %r15,%r14
shr    $0x10,%r14
lea    0x1(%r12),%rbp
lea    (%rbx,%r14,1),%rax
mov    %rax,0x10(%rsp)
mov    $0x4,%edi
call   1030 <int_to_fix@plt>
cmp    %rax,0x10(%rsp)
jge    119e <escape_iteration_count+0x8e>
mov    (%rsp),%rax
sub    %r14,%rax
add    %rbx,%rax
imul   %r15,%r13
sar    $0xf,%r13
mov    %r13,%r15
add    0x8(%rsp),%r15
mov    %rax,%r13
cmp    $0xff,%r12
mov    %rbp,%r12
jb     1140 <escape_iteration_count+0x30>
cmp    $0x100,%rbp
mov    $0xffffffffffffffff,%rax
cmovne %rbp,%rax
jmp    11b4 <escape_iteration_count+0xa4>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @escape_iteration_count(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
store i64 0, i64* %5
store i64 0, i64* %6
store i64 0, i64* %7
store i64 0, i64* %8
store i64 0, i64* %9
store i64 256, i64* %10
br label %13
13: ; preds = %24, %2
%14 = load i64, i64* %7
%15 = load i64, i64* %8
%16 = add nsw i64 %14, %15
%17 = call i64 @int_to_fix(i32 4)
%18 = icmp slt i64 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i64, i64* %9
%21 = icmp ult i64 %20, 256
br label %22
22: ; preds = %19, %13
%23 = phi i1 [ false, %13 ], [ %21, %19 ]
br i1 %23, label %24, label %48
24: ; preds = %22
%25 = load i64, i64* %5
%26 = load i64, i64* %5
%27 = mul nsw i64 %25, %26
%28 = ashr i64 %27, 16
store i64 %28, i64* %7
%29 = load i64, i64* %6
%30 = load i64, i64* %6
%31 = mul nsw i64 %29, %30
%32 = ashr i64 %31, 16
store i64 %32, i64* %8
%33 = load i64, i64* %3
%34 = load i64, i64* %7
%35 = load i64, i64* %8
%36 = sub nsw i64 %34, %35
%37 = add nsw i64 %33, %36
store i64 %37, i64* %11
%38 = load i64, i64* %4
%39 = load i64, i64* %5
%40 = load i64, i64* %6
%41 = mul nsw i64 %39, %40
%42 = ashr i64 %41, 15
%43 = add nsw i64 %38, %42
store i64 %43, i64* %12
%44 = load i64, i64* %9
%45 = add i64 %44, 1
store i64 %45, i64* %9
%46 = load i64, i64* %11
store i64 %46, i64* %5
%47 = load i64, i64* %12
store i64 %47, i64* %6
br label %13
48: ; preds = %22
%49 = load i64, i64* %9
%50 = icmp eq i64 %49, 256
br i1 %50, label %51, label %52
51: ; preds = %48
br label %54
52: ; preds = %48
%53 = load i64, i64* %9
br label %54
54: ; preds = %52, %51
%55 = phi i64 [ -1, %51 ], [ %53, %52 ]
ret i64 %55
}

LLVM IR (-O2):
define i64 @escape_iteration_count(i64 %0, i64 %1) {
%3 = tail call i64 @int_to_fix(i32 4)
%4 = icmp sgt i64 %3, 0
br i1 %4, label %5, label %27
5: ; preds = %2, %5
%6 = phi i64 [ %14, %5 ], [ 0, %2 ]
%7 = phi i64 [ %17, %5 ], [ 0, %2 ]
%8 = phi i64 [ %18, %5 ], [ 0, %2 ]
%9 = mul nsw i64 %6, %6
%10 = lshr i64 %9, 16
%11 = mul nsw i64 %7, %7
%12 = lshr i64 %11, 16
%13 = sub i64 %0, %12
%14 = add i64 %13, %10
%15 = mul nsw i64 %6, %7
%16 = ashr i64 %15, 15
%17 = add nsw i64 %16, %1
%18 = add nuw nsw i64 %8, 1
%19 = add nuw nsw i64 %10, %12
%20 = tail call i64 @int_to_fix(i32 4)
%21 = icmp slt i64 %19, %20
%22 = icmp ult i64 %8, 255
%23 = select i1 %21, i1 %22, i1 false
br i1 %23, label %5, label %24
24: ; preds = %5
%25 = icmp eq i64 %18, 256
%26 = select i1 %25, i64 -1, i64 %18
br label %27
27: ; preds = %24, %2
%28 = phi i64 [ 0, %2 ], [ %26, %24 ]
ret i64 %28
}