#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*/ fflush(int /*<<< orphan*/ *);
int **imgalloc(int, int);
int imgcelliter(int **, int **, int, int);
int /*<<< orphan*/ imgclear(int **, int, int);
int imgcompare(int **, int **, int **, int, int);
int imgdrawcircle(int **, int, int, int);
int /*<<< orphan*/ imgfree(int **, int, int);
int /*<<< orphan*/ imgseed(int **, int, int);
int /*<<< orphan*/ printf(char *, int, int, int, double, int, double);
int /*<<< orphan*/ saveppm(char *, int **, int, int);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int main() {
  int s = 500;
  int **cells = imgalloc(s, s);
  int **buffer = imgalloc(s, s);
  int **circle = imgalloc(s, s);
  int **compare = imgalloc(s, s);
  imgclear(cells, s, s);
  imgclear(circle, s, s);
  imgclear(compare, s, s);
  imgseed(cells, s / 2, s / 2);
  int circlearea = imgdrawcircle(circle, s / 2, s / 2, s / 3);
  int cellsarea = 1;
  int hits = 0;
  int error;
  char fname[64];
  int i = 0;
  while (cellsarea <= circlearea + circlearea / 4) {
    hits = imgcompare(compare, circle, cells, s, s);
    printf("img/cell%04d.ppm %d %d %.2f %d %.2f\n", i, cellsarea, circlearea,
           (double)(cellsarea * 100) / circlearea, hits,
           (double)(hits * 100) / circlearea);
    fflush(NULL);
    sprintf(fname, "img/cell%04d.ppm", i++);
    saveppm(fname, compare, s, s);
    error = circlearea - hits;
    cellsarea = imgcelliter(cells, buffer, s, s);
  }
  imgfree(cells, s, s);
  imgfree(buffer, s, s);
  imgfree(circle, s, s);
  imgfree(compare, s, s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1f4,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <imgalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <imgalloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <imgalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1080 <imgalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1070 <imgclear@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1070 <imgclear@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1070 <imgclear@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
call   1030 <imgseed@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x88(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    -0x88(%rbp),%edx
mov    %eax,%ecx
call   10b0 <imgdrawcircle@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x84(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x2c(%rbp),%eax
mov    $0x4,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x8c(%rbp),%eax
add    %edx,%ecx
cmp    %ecx,%eax
jg     138d <main+0x1dd>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%ecx
mov    -0x8(%rbp),%r8d
call   10a0 <imgcompare@plt>
mov    %eax,-0x34(%rbp)
mov    -0x84(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
imul   $0x64,-0x30(%rbp),%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
divsd  %xmm1,%xmm0
mov    -0x34(%rbp),%r8d
imul   $0x64,-0x34(%rbp),%eax
cvtsi2sd %eax,%xmm1
cvtsi2sdl -0x2c(%rbp),%xmm2
divsd  %xmm2,%xmm1
lea    0xcd9(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <fflush@plt>
lea    -0x80(%rbp),%rdi
mov    -0x84(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
lea    0xcd4(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x80(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x8(%rbp),%ecx
call   10d0 <saveppm@plt>
mov    -0x2c(%rbp),%eax
sub    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
mov    -0x8(%rbp),%ecx
call   1060 <imgcelliter@plt>
mov    %eax,-0x30(%rbp)
jmp    12aa <main+0xfa>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1040 <imgfree@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1040 <imgfree@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1040 <imgfree@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x8(%rbp),%edx
call   1040 <imgfree@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    $0x1f4,%edi
mov    $0x1f4,%esi
call   1080 <imgalloc@plt>
mov    %rax,%r13
mov    $0x1f4,%edi
mov    $0x1f4,%esi
call   1080 <imgalloc@plt>
mov    %rax,0x18(%rsp)
mov    $0x1f4,%edi
mov    $0x1f4,%esi
call   1080 <imgalloc@plt>
mov    %rax,%rbp
mov    $0x1f4,%edi
mov    $0x1f4,%esi
call   1080 <imgalloc@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    $0x1f4,%esi
mov    $0x1f4,%edx
call   1070 <imgclear@plt>
mov    %rbp,%rdi
mov    $0x1f4,%esi
mov    $0x1f4,%edx
call   1070 <imgclear@plt>
mov    %rbx,%rdi
mov    $0x1f4,%esi
mov    $0x1f4,%edx
call   1070 <imgclear@plt>
mov    %r13,%rdi
mov    $0xfa,%esi
mov    $0xfa,%edx
call   1030 <imgseed@plt>
mov    %rbp,%rdi
mov    $0xfa,%esi
mov    $0xfa,%edx
mov    $0xa6,%ecx
call   10b0 <imgdrawcircle@plt>
lea    0x3(%rax),%r12d
test   %eax,%eax
cmovns %eax,%r12d
sar    $0x2,%r12d
mov    %rax,0x10(%rsp)
add    %eax,%r12d
jle    1360 <main+0x1b0>
cvtsi2sdl 0x10(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
mov    $0x1,%r15d
xor    %r14d,%r14d
mov    %rbp,0x28(%rsp)
nopl   (%rax)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
mov    $0x1f4,%ecx
mov    $0x1f4,%r8d
call   10a0 <imgcompare@plt>
imul   $0x64,%r15d,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movsd  0x20(%rsp),%xmm2
divsd  %xmm2,%xmm0
imul   $0x64,%eax,%ecx
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
divsd  %xmm2,%xmm1
lea    0xd1d(%rip),%rdi
mov    %r14d,%esi
mov    %r15d,%edx
mov    0x10(%rsp),%rcx
mov    %eax,%r8d
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <fflush@plt>
lea    0x1(%r14),%eax
mov    %eax,0xc(%rsp)
lea    0x30(%rsp),%rbp
mov    %rbp,%rdi
lea    0xd11(%rip),%rsi
mov    %r14d,%edx
call   10c0 <sprintf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x1f4,%edx
mov    $0x1f4,%ecx
call   10d0 <saveppm@plt>
mov    %r13,%rdi
mov    0x18(%rsp),%rsi
mov    $0x1f4,%edx
mov    $0x1f4,%ecx
call   1060 <imgcelliter@plt>
mov    %eax,%r15d
mov    0xc(%rsp),%eax
mov    %eax,%r14d
mov    0x28(%rsp),%rbp
cmp    %r12d,%r15d
jle    12a0 <main+0xf0>
mov    %r13,%rdi
mov    $0x1f4,%esi
mov    $0x1f4,%edx
call   1040 <imgfree@plt>
mov    0x18(%rsp),%rdi
mov    $0x1f4,%esi
mov    $0x1f4,%edx
call   1040 <imgfree@plt>
mov    %rbp,%rdi
mov    $0x1f4,%esi
mov    $0x1f4,%edx
call   1040 <imgfree@plt>
mov    %rbx,%rdi
mov    $0x1f4,%esi
mov    $0x1f4,%edx
call   1040 <imgfree@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"img/cell%04d.ppm %d %d %.2f %d %.2f\0A\00"
@.str.1 = [17 x i8] c"img/cell%04d.ppm\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32**
%4 = alloca i32**
%5 = alloca i32**
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [64 x i8]
%12 = alloca i32
store i32 0, i32* %1
store i32 500, i32* %2
%13 = load i32, i32* %2
%14 = load i32, i32* %2
%15 = call i32** @imgalloc(i32 %13, i32 %14)
store i32** %15, i32*** %3
%16 = load i32, i32* %2
%17 = load i32, i32* %2
%18 = call i32** @imgalloc(i32 %16, i32 %17)
store i32** %18, i32*** %4
%19 = load i32, i32* %2
%20 = load i32, i32* %2
%21 = call i32** @imgalloc(i32 %19, i32 %20)
store i32** %21, i32*** %5
%22 = load i32, i32* %2
%23 = load i32, i32* %2
%24 = call i32** @imgalloc(i32 %22, i32 %23)
store i32** %24, i32*** %6
%25 = load i32**, i32*** %3
%26 = load i32, i32* %2
%27 = load i32, i32* %2
%28 = call i32 @imgclear(i32** %25, i32 %26, i32 %27)
%29 = load i32**, i32*** %5
%30 = load i32, i32* %2
%31 = load i32, i32* %2
%32 = call i32 @imgclear(i32** %29, i32 %30, i32 %31)
%33 = load i32**, i32*** %6
%34 = load i32, i32* %2
%35 = load i32, i32* %2
%36 = call i32 @imgclear(i32** %33, i32 %34, i32 %35)
%37 = load i32**, i32*** %3
%38 = load i32, i32* %2
%39 = sdiv i32 %38, 2
%40 = load i32, i32* %2
%41 = sdiv i32 %40, 2
%42 = call i32 @imgseed(i32** %37, i32 %39, i32 %41)
%43 = load i32**, i32*** %5
%44 = load i32, i32* %2
%45 = sdiv i32 %44, 2
%46 = load i32, i32* %2
%47 = sdiv i32 %46, 2
%48 = load i32, i32* %2
%49 = sdiv i32 %48, 3
%50 = call i32 @imgdrawcircle(i32** %43, i32 %45, i32 %47, i32 %49)
store i32 %50, i32* %7
store i32 1, i32* %8
store i32 0, i32* %9
store i32 0, i32* %12
br label %51
51: ; preds = %58, %0
%52 = load i32, i32* %8
%53 = load i32, i32* %7
%54 = load i32, i32* %7
%55 = sdiv i32 %54, 4
%56 = add nsw i32 %53, %55
%57 = icmp sle i32 %52, %56
br i1 %57, label %58, label %100
58: ; preds = %51
%59 = load i32**, i32*** %6
%60 = load i32**, i32*** %5
%61 = load i32**, i32*** %3
%62 = load i32, i32* %2
%63 = load i32, i32* %2
%64 = call i32 @imgcompare(i32** %59, i32** %60, i32** %61, i32 %62, i32 %63)
store i32 %64, i32* %9
%65 = load i32, i32* %12
%66 = load i32, i32* %8
%67 = load i32, i32* %7
%68 = load i32, i32* %8
%69 = mul nsw i32 %68, 100
%70 = sitofp i32 %69 to double
%71 = load i32, i32* %7
%72 = sitofp i32 %71 to double
%73 = fdiv double %70, %72
%74 = load i32, i32* %9
%75 = load i32, i32* %9
%76 = mul nsw i32 %75, 100
%77 = sitofp i32 %76 to double
%78 = load i32, i32* %7
%79 = sitofp i32 %78 to double
%80 = fdiv double %77, %79
%81 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %65, i32 %66, i32 %67, double %73, i32 %74, double %80)
%82 = call i32 @fflush(i32* null)
%83 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%84 = load i32, i32* %12
%85 = add nsw i32 %84, 1
store i32 %85, i32* %12
%86 = call i32 @sprintf(i8* %83, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %84)
%87 = getelementptr inbounds [64 x i8], [64 x i8]* %11, i64 0, i64 0
%88 = load i32**, i32*** %6
%89 = load i32, i32* %2
%90 = load i32, i32* %2
%91 = call i32 @saveppm(i8* %87, i32** %88, i32 %89, i32 %90)
%92 = load i32, i32* %7
%93 = load i32, i32* %9
%94 = sub nsw i32 %92, %93
store i32 %94, i32* %10
%95 = load i32**, i32*** %3
%96 = load i32**, i32*** %4
%97 = load i32, i32* %2
%98 = load i32, i32* %2
%99 = call i32 @imgcelliter(i32** %95, i32** %96, i32 %97, i32 %98)
store i32 %99, i32* %8
br label %51
100: ; preds = %51
%101 = load i32**, i32*** %3
%102 = load i32, i32* %2
%103 = load i32, i32* %2
%104 = call i32 @imgfree(i32** %101, i32 %102, i32 %103)
%105 = load i32**, i32*** %4
%106 = load i32, i32* %2
%107 = load i32, i32* %2
%108 = call i32 @imgfree(i32** %105, i32 %106, i32 %107)
%109 = load i32**, i32*** %5
%110 = load i32, i32* %2
%111 = load i32, i32* %2
%112 = call i32 @imgfree(i32** %109, i32 %110, i32 %111)
%113 = load i32**, i32*** %6
%114 = load i32, i32* %2
%115 = load i32, i32* %2
%116 = call i32 @imgfree(i32** %113, i32 %114, i32 %115)
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"img/cell%04d.ppm %d %d %.2f %d %.2f\0A\00"
@.str.1 = [17 x i8] c"img/cell%04d.ppm\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = tail call i32** @imgalloc(i32 500, i32 500)
%3 = tail call i32** @imgalloc(i32 500, i32 500)
%4 = tail call i32** @imgalloc(i32 500, i32 500)
%5 = tail call i32** @imgalloc(i32 500, i32 500)
%6 = tail call i32 @imgclear(i32** %2, i32 500, i32 500)
%7 = tail call i32 @imgclear(i32** %4, i32 500, i32 500)
%8 = tail call i32 @imgclear(i32** %5, i32 500, i32 500)
%9 = tail call i32 @imgseed(i32** %2, i32 250, i32 250)
%10 = tail call i32 @imgdrawcircle(i32** %4, i32 250, i32 250, i32 166)
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%12 = sdiv i32 %10, 4
%13 = add nsw i32 %12, %10
%14 = icmp slt i32 %13, 1
br i1 %14, label %34, label %15
15: ; preds = %0
%16 = sitofp i32 %10 to double
br label %17
17: ; preds = %15, %17
%18 = phi i32 [ 0, %15 ], [ %29, %17 ]
%19 = phi i32 [ 1, %15 ], [ %32, %17 ]
%20 = call i32 @imgcompare(i32** %5, i32** %4, i32** %2, i32 500, i32 500)
%21 = mul nsw i32 %19, 100
%22 = sitofp i32 %21 to double
%23 = fdiv double %22, %16
%24 = mul nsw i32 %20, 100
%25 = sitofp i32 %24 to double
%26 = fdiv double %25, %16
%27 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19, i32 %10, double %23, i32 %20, double %26)
%28 = call i32 @fflush(i32* null)
%29 = add nuw nsw i32 %18, 1
%30 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%31 = call i32 @saveppm(i8* %11, i32** %5, i32 500, i32 500)
%32 = call i32 @imgcelliter(i32** %2, i32** %3, i32 500, i32 500)
%33 = icmp sgt i32 %32, %13
br i1 %33, label %34, label %17
34: ; preds = %17, %0
%35 = call i32 @imgfree(i32** %2, i32 500, i32 500)
%36 = call i32 @imgfree(i32** %3, i32 500, i32 500)
%37 = call i32 @imgfree(i32** %4, i32 500, i32 500)
%38 = call i32 @imgfree(i32** %5, i32 500, i32 500)
ret i32 0
}