#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 escape_iteration_count(long, long);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
long const int_to_fix(int);
char *malloc(long const);
int /*<<< orphan*/ printf(char *, long const, long const);
int /*<<< orphan*/ putrgb(char *, long const, long, long, long, long, long);
int /*<<< orphan*/ write(int, char *, long const);
int main(int argc, char *argv[]) {
  long const width = 1024;
  long const height = 1024;
  long y, x;
  char *buf = malloc(width * height * 3);
  printf("P6 %d %d 255\n", width, height);
  fflush(NULL);
  for (y = 0; y < height; y++) {
    for (x = 0; x < width; x++) {
      long i = escape_iteration_count(
          int_to_fix(-2) + (x * (int_to_fix(4) / width)),
          int_to_fix(-2) + (y * (int_to_fix(4) / height)));
      long b = (i == -1) ? 0 : i;
      putrgb(buf, width, x, y, b, b, b);
    }
  }
  write(1, buf, width * height * 3);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x400,-0x18(%rbp)
movq   $0x400,-0x20(%rbp)
mov    $0x300000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
lea    0xe52(%rip),%rdi
mov    $0x400,%edx
mov    %rdx,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <fflush@plt>
movq   $0x0,-0x28(%rbp)
cmpq   $0x400,-0x28(%rbp)
jge    12ec <main+0x17c>
movq   $0x0,-0x30(%rbp)
cmpq   $0x400,-0x30(%rbp)
jge    12d6 <main+0x166>
mov    $0xfffffffe,%edi
call   1030 <int_to_fix@plt>
mov    %rax,-0x68(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    $0x4,%edi
call   1030 <int_to_fix@plt>
mov    -0x70(%rbp),%rcx
mov    $0x400,%esi
cqto
idiv   %rsi
mov    %rax,%rdx
mov    -0x68(%rbp),%rax
imul   %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x58(%rbp)
mov    $0xfffffffe,%edi
call   1030 <int_to_fix@plt>
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    $0x4,%edi
call   1030 <int_to_fix@plt>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdi
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
imul   %rcx,%rax
add    %rax,%rsi
call   1090 <escape_iteration_count@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0xffffffffffffffff,-0x40(%rbp)
jne    128f <main+0x11f>
xor    %eax,%eax
mov    %rax,-0x78(%rbp)
jmp    1297 <main+0x127>
mov    -0x40(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x48(%rbp),%r8
mov    -0x48(%rbp),%r9
mov    -0x48(%rbp),%rax
mov    $0x400,%esi
mov    %rax,(%rsp)
call   1060 <putrgb@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11e2 <main+0x72>
jmp    12db <main+0x16b>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11cc <main+0x5c>
mov    -0x38(%rbp),%rsi
mov    $0x1,%edi
mov    $0x300000,%edx
call   1040 <write@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0x300000,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe6f(%rip),%rdi
mov    $0x400,%esi
mov    $0x400,%edx
call   1050 <printf@plt>
xor    %r15d,%r15d
xor    %edi,%edi
call   1080 <fflush@plt>
nopw   0x0(%rax,%rax,1)
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0xfffffffe,%edi
call   1030 <int_to_fix@plt>
mov    %rax,%r13
mov    $0x4,%edi
call   1030 <int_to_fix@plt>
lea    0x3ff(%rax),%rbx
test   %rax,%rax
cmovns %rax,%rbx
sar    $0xa,%rbx
imul   %r12,%rbx
add    %r13,%rbx
mov    $0xfffffffe,%edi
call   1030 <int_to_fix@plt>
mov    %rax,%r13
mov    $0x4,%edi
call   1030 <int_to_fix@plt>
lea    0x3ff(%rax),%rsi
test   %rax,%rax
cmovns %rax,%rsi
sar    $0xa,%rsi
imul   %r15,%rsi
add    %r13,%rsi
mov    %rbx,%rdi
call   1090 <escape_iteration_count@plt>
cmp    $0xffffffffffffffff,%rax
mov    $0x0,%r8d
cmovne %rax,%r8
mov    %r8,(%rsp)
mov    $0x400,%esi
mov    %r14,%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r8,%r9
call   1060 <putrgb@plt>
add    $0x1,%r12
cmp    $0x400,%r12
jne    11c0 <main+0x50>
add    $0x1,%r15
cmp    $0x400,%r15
jne    11b0 <main+0x40>
mov    $0x300000,%edx
mov    $0x1,%edi
mov    %r14,%rsi
call   1040 <write@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"P6 %d %d 255\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1024, i64* %6
store i64 1024, i64* %7
%13 = call i8* @malloc(i64 3145728)
store i8* %13, i8** %10
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 1024, i64 1024)
%15 = call i32 @fflush(i32* null)
store i64 0, i64* %8
br label %16
16: ; preds = %55, %2
%17 = load i64, i64* %8
%18 = icmp slt i64 %17, 1024
br i1 %18, label %19, label %58
19: ; preds = %16
store i64 0, i64* %9
br label %20
20: ; preds = %51, %19
%21 = load i64, i64* %9
%22 = icmp slt i64 %21, 1024
br i1 %22, label %23, label %54
23: ; preds = %20
%24 = call i64 @int_to_fix(i32 -2)
%25 = load i64, i64* %9
%26 = call i64 @int_to_fix(i32 4)
%27 = sdiv i64 %26, 1024
%28 = mul nsw i64 %25, %27
%29 = add nsw i64 %24, %28
%30 = call i64 @int_to_fix(i32 -2)
%31 = load i64, i64* %8
%32 = call i64 @int_to_fix(i32 4)
%33 = sdiv i64 %32, 1024
%34 = mul nsw i64 %31, %33
%35 = add nsw i64 %30, %34
%36 = call i64 @escape_iteration_count(i64 %29, i64 %35)
store i64 %36, i64* %11
%37 = load i64, i64* %11
%38 = icmp eq i64 %37, -1
br i1 %38, label %39, label %40
39: ; preds = %23
br label %42
40: ; preds = %23
%41 = load i64, i64* %11
br label %42
42: ; preds = %40, %39
%43 = phi i64 [ 0, %39 ], [ %41, %40 ]
store i64 %43, i64* %12
%44 = load i8*, i8** %10
%45 = load i64, i64* %9
%46 = load i64, i64* %8
%47 = load i64, i64* %12
%48 = load i64, i64* %12
%49 = load i64, i64* %12
%50 = call i32 @putrgb(i8* %44, i64 1024, i64 %45, i64 %46, i64 %47, i64 %48, i64 %49)
br label %51
51: ; preds = %42
%52 = load i64, i64* %9
%53 = add nsw i64 %52, 1
store i64 %53, i64* %9
br label %20
54: ; preds = %20
br label %55
55: ; preds = %54
%56 = load i64, i64* %8
%57 = add nsw i64 %56, 1
store i64 %57, i64* %8
br label %16
58: ; preds = %16
%59 = load i8*, i8** %10
%60 = call i32 @write(i32 1, i8* %59, i64 3145728)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"P6 %d %d 255\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(3145728) i8* @malloc(i64 3145728)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 1024, i64 1024)
%5 = tail call i32 @fflush(i32* null)
br label %6
6: ; preds = %2, %26
%7 = phi i64 [ 0, %2 ], [ %27, %26 ]
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %24, %8 ]
%10 = tail call i64 @int_to_fix(i32 -2)
%11 = tail call i64 @int_to_fix(i32 4)
%12 = sdiv i64 %11, 1024
%13 = mul nsw i64 %12, %9
%14 = add nsw i64 %13, %10
%15 = tail call i64 @int_to_fix(i32 -2)
%16 = tail call i64 @int_to_fix(i32 4)
%17 = sdiv i64 %16, 1024
%18 = mul nsw i64 %17, %7
%19 = add nsw i64 %18, %15
%20 = tail call i64 @escape_iteration_count(i64 %14, i64 %19)
%21 = icmp eq i64 %20, -1
%22 = select i1 %21, i64 0, i64 %20
%23 = tail call i32 @putrgb(i8* %3, i64 1024, i64 %9, i64 %7, i64 %22, i64 %22, i64 %22)
%24 = add nuw nsw i64 %9, 1
%25 = icmp eq i64 %24, 1024
br i1 %25, label %26, label %8
26: ; preds = %8
%27 = add nuw nsw i64 %7, 1
%28 = icmp eq i64 %27, 1024
br i1 %28, label %29, label %6
29: ; preds = %26
%30 = tail call i32 @write(i32 1, i8* %3, i64 3145728)
ret i32 0
}