#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ stderr;
int ExportToPGM(int **img, int w, int h, char *filename) {
  FILE *f;
  char line[50000];
  f = fopen(filename, "wb");
  if (f == NULL) {
    fprintf(stderr, "fopen(%s)\n", filename);
    return -1;
  }
  int min = 1000000000;
  int max = -1000000000;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (max < img[y][x])
        max = img[y][x];
      if (min > img[y][x])
        min = img[y][x];
      if (img[y][x] < -1000)
        printf("%d    %d %d\n", min, x, y);
    }
  }
  fprintf(f, "P5\n");
  fprintf(f, "# width height\n");
  fprintf(f, "%d %d\n", w, h);
  fprintf(f, "255\n");
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      line[x] = (char)((double)(img[y][x] - min) / (double)(max - min) * 255.);
    }
    if (fwrite(line, sizeof(char) * w, 1, f) != 1) {
      fprintf(stderr, "fwrite(%s)\n", filename);
      fclose(f);
      return -1;
    }
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<ExportToPGM>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc3a0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11af <ExportToPGM+0x5f>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1462 <ExportToPGM+0x312>
movl   $0x3b9aca00,-0xc384(%rbp)
ca 9a 3b
movl   $0xc4653600,-0xc388(%rbp)
36 65 c4
movl   $0x0,-0xc38c(%rbp)
mov    -0xc38c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    12f0 <ExportToPGM+0x1a0>
movl   $0x0,-0xc390(%rbp)
mov    -0xc390(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12d7 <ExportToPGM+0x187>
mov    -0xc388(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0xc38c(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
movslq -0xc390(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    1239 <ExportToPGM+0xe9>
mov    -0x10(%rbp),%rax
movslq -0xc38c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0xc390(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0xc388(%rbp)
mov    -0xc384(%rbp),%eax
mov    -0x10(%rbp),%rcx
movslq -0xc38c(%rbp),%rdx
mov    (%rcx,%rdx,8),%rcx
movslq -0xc390(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jle    127d <ExportToPGM+0x12d>
mov    -0x10(%rbp),%rax
movslq -0xc38c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0xc390(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0xc384(%rbp)
mov    -0x10(%rbp),%rax
movslq -0xc38c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0xc390(%rbp),%rcx
cmpl   $0xfffffc18,(%rax,%rcx,4)
jge    12be <ExportToPGM+0x16e>
mov    -0xc384(%rbp),%esi
mov    -0xc390(%rbp),%edx
mov    -0xc38c(%rbp),%ecx
lea    0xd5d(%rip),%rdi
call   1040 <printf@plt>
jmp    12c3 <ExportToPGM+0x173>
mov    -0xc390(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc390(%rbp)
jmp    11e6 <ExportToPGM+0x96>
jmp    12dc <ExportToPGM+0x18c>
mov    -0xc38c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc38c(%rbp)
jmp    11cd <ExportToPGM+0x7d>
mov    -0x28(%rbp),%rax
mov    %eax,%edi
lea    0xd26(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rax
mov    %eax,%edi
lea    0xd16(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rax
mov    %eax,%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xcf1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rax
mov    %eax,%edi
lea    0xcf8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0xc394(%rbp)
mov    -0xc394(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1452 <ExportToPGM+0x302>
movl   $0x0,-0xc398(%rbp)
mov    -0xc398(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    13e1 <ExportToPGM+0x291>
mov    -0x10(%rbp),%rax
movslq -0xc394(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0xc398(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0xc384(%rbp),%ecx
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
mov    -0xc388(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  0xc4b(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %al,%cl
movslq -0xc398(%rbp),%rax
mov    %cl,-0xc380(%rbp,%rax,1)
mov    -0xc398(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc398(%rbp)
jmp    1369 <ExportToPGM+0x219>
lea    -0xc380(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
je     1439 <ExportToPGM+0x2e9>
mov    0x2bd0(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xc1f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1462 <ExportToPGM+0x312>
jmp    143e <ExportToPGM+0x2ee>
mov    -0xc394(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc394(%rbp)
jmp    1350 <ExportToPGM+0x200>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc3a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ExportToPGM>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc3c8,%rsp
mov    %rcx,%r14
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%rbx
lea    0xea5(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     121a <ExportToPGM+0xca>
mov    %ebp,%eax
mov    %rax,0x18(%rsp)
mov    %r15d,%r12d
test   %ebp,%ebp
mov    %r15d,0xc(%rsp)
mov    %r14,0x30(%rsp)
mov    %ebp,0x20(%rsp)
jle    123e <ExportToPGM+0xee>
mov    $0x3b9aca00,%ebp
mov    $0xc4653600,%r13d
xor    %r14d,%r14d
jmp    11d0 <ExportToPGM+0x80>
nopl   0x0(%rax)
add    $0x1,%r14
cmp    0x18(%rsp),%r14
mov    0xc(%rsp),%r15d
je     1249 <ExportToPGM+0xf9>
test   %r15d,%r15d
jle    11c0 <ExportToPGM+0x70>
xor    %r15d,%r15d
jmp    11e9 <ExportToPGM+0x99>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r15
cmp    %r15,%r12
je     11c0 <ExportToPGM+0x70>
mov    (%rbx,%r14,8),%rax
mov    (%rax,%r15,4),%eax
cmp    %eax,%r13d
cmovl  %eax,%r13d
cmp    %eax,%ebp
cmovg  %eax,%ebp
cmp    $0xfffffc17,%eax
jg     11e0 <ExportToPGM+0x90>
lea    0xe1b(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1040 <printf@plt>
jmp    11e0 <ExportToPGM+0x90>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1508 <ExportToPGM+0x3b8>
mov    $0xc4653600,%r13d
mov    $0x3b9aca00,%ebp
lea    0xde3(%rip),%rsi
mov    0x10(%rsp),%r14
mov    %r14d,%edi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xdd1(%rip),%rsi
mov    %r14d,%edi
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xdb5(%rip),%rsi
mov    %r14d,%edi
mov    %r15d,%edx
mov    0x20(%rsp),%r15d
mov    %r15d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xdb4(%rip),%rsi
mov    %r14d,%edi
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r15d,%r15d
jle    14fc <ExportToPGM+0x3ac>
sub    %ebp,%r13d
cvtsi2sd %r13d,%xmm2
mov    %r12d,%r14d
and    $0xfffffffc,%r14d
lea    -0x4(%r14),%rax
mov    %rax,0x48(%rsp)
mov    %rax,%rcx
shr    $0x2,%rcx
add    $0x1,%rcx
movd   %ebp,%xmm0
pshufd $0x0,%xmm0,%xmm3
movapd %xmm2,%xmm4
unpcklpd %xmm2,%xmm4
mov    %rcx,%rax
mov    %rcx,0x40(%rsp)
and    $0xfffffffffffffffe,%rcx
mov    %rcx,0x38(%rsp)
mov    $0x1,%r15b
xor    %r13d,%r13d
movsd  0xd17(%rip),%xmm5
movapd 0xcff(%rip),%xmm6
movapd %xmm2,0x20(%rsp)
movdqa %xmm3,0x60(%rsp)
movapd %xmm4,0x50(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmpl   $0x0,0xc(%rsp)
jle    1465 <ExportToPGM+0x315>
mov    (%rbx,%r13,8),%rax
cmpl   $0x4,0xc(%rsp)
jae    1340 <ExportToPGM+0x1f0>
xor    %ecx,%ecx
jmp    1440 <ExportToPGM+0x2f0>
nopl   (%rax)
cmpq   $0x0,0x48(%rsp)
je     14b9 <ExportToPGM+0x369>
mov    0x38(%rsp),%rdx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movdqu (%rax,%rcx,4),%xmm0
psubd  %xmm3,%xmm0
pshufd $0xee,%xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
cvtdq2pd %xmm0,%xmm0
divpd  %xmm4,%xmm0
divpd  %xmm4,%xmm1
mulpd  %xmm6,%xmm0
cvttpd2dq %xmm0,%xmm0
mulpd  %xmm6,%xmm1
cvttpd2dq %xmm1,%xmm1
unpcklpd %xmm1,%xmm0
packssdw %xmm0,%xmm0
packsswb %xmm0,%xmm0
movd   %xmm0,0x70(%rsp,%rcx,1)
movdqu 0x10(%rax,%rcx,4),%xmm0
psubd  %xmm3,%xmm0
pshufd $0xee,%xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
cvtdq2pd %xmm0,%xmm0
divpd  %xmm4,%xmm0
divpd  %xmm4,%xmm1
mulpd  %xmm6,%xmm1
mulpd  %xmm6,%xmm0
cvttpd2dq %xmm0,%xmm0
cvttpd2dq %xmm1,%xmm1
unpcklpd %xmm1,%xmm0
packssdw %xmm0,%xmm0
packsswb %xmm0,%xmm0
movd   %xmm0,0x74(%rsp,%rcx,1)
add    $0x8,%rcx
add    $0xfffffffffffffffe,%rdx
jne    1360 <ExportToPGM+0x210>
testb  $0x1,0x40(%rsp)
je     1436 <ExportToPGM+0x2e6>
movdqu (%rax,%rcx,4),%xmm0
psubd  %xmm3,%xmm0
pshufd $0xee,%xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
cvtdq2pd %xmm0,%xmm0
divpd  %xmm4,%xmm0
divpd  %xmm4,%xmm1
mulpd  %xmm6,%xmm1
mulpd  %xmm6,%xmm0
cvttpd2dq %xmm0,%xmm0
cvttpd2dq %xmm1,%xmm1
unpcklpd %xmm1,%xmm0
packssdw %xmm0,%xmm0
packsswb %xmm0,%xmm0
movd   %xmm0,0x70(%rsp,%rcx,1)
mov    %r14,%rcx
cmp    %r12,%r14
je     1465 <ExportToPGM+0x315>
xchg   %ax,%ax
mov    (%rax,%rcx,4),%edx
sub    %ebp,%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
divsd  %xmm2,%xmm0
mulsd  %xmm5,%xmm0
cvttsd2si %xmm0,%edx
mov    %dl,0x70(%rsp,%rcx,1)
add    $0x1,%rcx
cmp    %rcx,%r12
jne    1440 <ExportToPGM+0x2f0>
lea    0x70(%rsp),%rdi
mov    0xc(%rsp),%esi
mov    $0x1,%edx
mov    0x10(%rsp),%rcx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
jne    14cb <ExportToPGM+0x37b>
add    $0x1,%r13
cmp    0x18(%rsp),%r13
setb   %r15b
movapd 0x20(%rsp),%xmm2
movdqa 0x60(%rsp),%xmm3
movapd 0x50(%rsp),%xmm4
movsd  0xb67(%rip),%xmm5
movapd 0xb4f(%rip),%xmm6
jne    1320 <ExportToPGM+0x1d0>
jmp    14fc <ExportToPGM+0x3ac>
xor    %ecx,%ecx
testb  $0x1,0x40(%rsp)
jne    13f6 <ExportToPGM+0x2a6>
jmp    1436 <ExportToPGM+0x2e6>
mov    0x2b0e(%rip),%rax
mov    (%rax),%edi
lea    0xb71(%rip),%rsi
mov    0x30(%rsp),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x10(%rsp),%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%eax
test   $0x1,%r15b
jne    1508 <ExportToPGM+0x3b8>
mov    0x10(%rsp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0xc3c8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [11 x i8] c"fopen(%s)\0A\00"
@.str.2 = [13 x i8] c"%d %d %d\0A\00"
@.str.3 = [4 x i8] c"P5\0A\00"
@.str.4 = [16 x i8] c"# width height\0A\00"
@.str.5 = [7 x i8] c"%d %d\0A\00"
@.str.6 = [5 x i8] c"255\0A\00"
@.str.7 = [12 x i8] c"fwrite(%s)\0A\00"
define i32 @ExportToPGM(i32** %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca [50000 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32** %0, i32*** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%18 = load i8*, i8** %9
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %10
%20 = load i32*, i32** %10
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %26
22: ; preds = %4
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %9
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store i32 -1, i32* %5
br label %176
26: ; preds = %4
store i32 1000000000, i32* %12
store i32 -1000000000, i32* %13
store i32 0, i32* %14
br label %27
27: ; preds = %101, %26
%28 = load i32, i32* %14
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %104
31: ; preds = %27
store i32 0, i32* %15
br label %32
32: ; preds = %97, %31
%33 = load i32, i32* %15
%34 = load i32, i32* %7
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %100
36: ; preds = %32
%37 = load i32, i32* %13
%38 = load i32**, i32*** %6
%39 = load i32, i32* %14
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32*, i32** %38, i64 %40
%42 = load i32*, i32** %41
%43 = load i32, i32* %15
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = load i32, i32* %45
%47 = icmp slt i32 %37, %46
br i1 %47, label %48, label %58
48: ; preds = %36
%49 = load i32**, i32*** %6
%50 = load i32, i32* %14
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i32*, i32** %49, i64 %51
%53 = load i32*, i32** %52
%54 = load i32, i32* %15
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i32, i32* %53, i64 %55
%57 = load i32, i32* %56
store i32 %57, i32* %13
br label %58
58: ; preds = %48, %36
%59 = load i32, i32* %12
%60 = load i32**, i32*** %6
%61 = load i32, i32* %14
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i32*, i32** %60, i64 %62
%64 = load i32*, i32** %63
%65 = load i32, i32* %15
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i32, i32* %64, i64 %66
%68 = load i32, i32* %67
%69 = icmp sgt i32 %59, %68
br i1 %69, label %70, label %80
70: ; preds = %58
%71 = load i32**, i32*** %6
%72 = load i32, i32* %14
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32*, i32** %71, i64 %73
%75 = load i32*, i32** %74
%76 = load i32, i32* %15
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i32, i32* %75, i64 %77
%79 = load i32, i32* %78
store i32 %79, i32* %12
br label %80
80: ; preds = %70, %58
%81 = load i32**, i32*** %6
%82 = load i32, i32* %14
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32*, i32** %81, i64 %83
%85 = load i32*, i32** %84
%86 = load i32, i32* %15
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i32, i32* %85, i64 %87
%89 = load i32, i32* %88
%90 = icmp slt i32 %89, -1000
br i1 %90, label %91, label %96
91: ; preds = %80
%92 = load i32, i32* %12
%93 = load i32, i32* %15
%94 = load i32, i32* %14
%95 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %92, i32 %93, i32 %94)
br label %96
96: ; preds = %91, %80
br label %97
97: ; preds = %96
%98 = load i32, i32* %15
%99 = add nsw i32 %98, 1
store i32 %99, i32* %15
br label %32
100: ; preds = %32
br label %101
101: ; preds = %100
%102 = load i32, i32* %14
%103 = add nsw i32 %102, 1
store i32 %103, i32* %14
br label %27
104: ; preds = %27
%105 = load i32*, i32** %10
%106 = ptrtoint i32* %105 to i32
%107 = call i32 (i32, i8*, ...) @fprintf(i32 %106, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%108 = load i32*, i32** %10
%109 = ptrtoint i32* %108 to i32
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%111 = load i32*, i32** %10
%112 = ptrtoint i32* %111 to i32
%113 = load i32, i32* %7
%114 = load i32, i32* %8
%115 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %113, i32 %114)
%116 = load i32*, i32** %10
%117 = ptrtoint i32* %116 to i32
%118 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %16
br label %119
119: ; preds = %170, %104
%120 = load i32, i32* %16
%121 = load i32, i32* %8
%122 = icmp slt i32 %120, %121
br i1 %122, label %123, label %173
123: ; preds = %119
store i32 0, i32* %17
br label %124
124: ; preds = %151, %123
%125 = load i32, i32* %17
%126 = load i32, i32* %7
%127 = icmp slt i32 %125, %126
br i1 %127, label %128, label %154
128: ; preds = %124
%129 = load i32**, i32*** %6
%130 = load i32, i32* %16
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds i32*, i32** %129, i64 %131
%133 = load i32*, i32** %132
%134 = load i32, i32* %17
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds i32, i32* %133, i64 %135
%137 = load i32, i32* %136
%138 = load i32, i32* %12
%139 = sub nsw i32 %137, %138
%140 = sitofp i32 %139 to double
%141 = load i32, i32* %13
%142 = load i32, i32* %12
%143 = sub nsw i32 %141, %142
%144 = sitofp i32 %143 to double
%145 = fdiv double %140, %144
%146 = fmul double %145, 2.550000e+02
%147 = fptosi double %146 to i8
%148 = load i32, i32* %17
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds [50000 x i8], [50000 x i8]* %11, i64 0, i64 %149
store i8 %147, i8* %150
br label %151
151: ; preds = %128
%152 = load i32, i32* %17
%153 = add nsw i32 %152, 1
store i32 %153, i32* %17
br label %124
154: ; preds = %124
%155 = getelementptr inbounds [50000 x i8], [50000 x i8]* %11, i64 0, i64 0
%156 = load i32, i32* %7
%157 = sext i32 %156 to i64
%158 = mul i64 1, %157
%159 = trunc i64 %158 to i32
%160 = load i32*, i32** %10
%161 = call i32 @fwrite(i8* %155, i32 %159, i32 1, i32* %160)
%162 = icmp ne i32 %161, 1
br i1 %162, label %163, label %169
163: ; preds = %154
%164 = load i32, i32* @stderr
%165 = load i8*, i8** %9
%166 = call i32 (i32, i8*, ...) @fprintf(i32 %164, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %165)
%167 = load i32*, i32** %10
%168 = call i32 @fclose(i32* %167)
store i32 -1, i32* %5
br label %176
169: ; preds = %154
br label %170
170: ; preds = %169
%171 = load i32, i32* %16
%172 = add nsw i32 %171, 1
store i32 %172, i32* %16
br label %119
173: ; preds = %119
%174 = load i32*, i32** %10
%175 = call i32 @fclose(i32* %174)
store i32 0, i32* %5
br label %176
176: ; preds = %173, %163, %22
%177 = load i32, i32* %5
ret i32 %177
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@stderr = global i32 0
@.str.1 = [11 x i8] c"fopen(%s)\0A\00"
@.str.2 = [13 x i8] c"%d %d %d\0A\00"
@.str.3 = [4 x i8] c"P5\0A\00"
@.str.4 = [16 x i8] c"# width height\0A\00"
@.str.5 = [7 x i8] c"%d %d\0A\00"
@.str.6 = [5 x i8] c"255\0A\00"
@.str.7 = [12 x i8] c"fwrite(%s)\0A\00"
define i32 @ExportToPGM(i32** nocapture %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca [50000 x i8]
%6 = getelementptr inbounds [50000 x i8], [50000 x i8]* %5, i64 0, i64 0
%7 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %15, label %9
9: ; preds = %4
%10 = icmp sgt i32 %2, 0
br i1 %10, label %11, label %25
11: ; preds = %9
%12 = icmp sgt i32 %1, 0
%13 = zext i32 %2 to i64
%14 = zext i32 %1 to i64
br label %18
15: ; preds = %4
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %154
18: ; preds = %11, %56
%19 = phi i64 [ 0, %11 ], [ %59, %56 ]
%20 = phi i32 [ -1000000000, %11 ], [ %58, %56 ]
%21 = phi i32 [ 1000000000, %11 ], [ %57, %56 ]
br i1 %12, label %22, label %56
22: ; preds = %18
%23 = getelementptr inbounds i32*, i32** %0, i64 %19
%24 = trunc i64 %19 to i32
br label %61
25: ; preds = %56, %9
%26 = phi i32 [ 1000000000, %9 ], [ %57, %56 ]
%27 = phi i32 [ -1000000000, %9 ], [ %58, %56 ]
%28 = ptrtoint i32* %7 to i64
%29 = trunc i64 %28 to i32
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%32 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %1, i32 %2)
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br i1 %10, label %34, label %152
34: ; preds = %25
%35 = icmp sgt i32 %1, 0
%36 = sub nsw i32 %27, %26
%37 = sitofp i32 %36 to double
%38 = zext i32 %2 to i64
%39 = zext i32 %2 to i64
%40 = zext i32 %1 to i64
%41 = and i64 %40, 4294967292
%42 = add nsw i64 %41, -4
%43 = lshr exact i64 %42, 2
%44 = add nuw nsw i64 %43, 1
%45 = icmp ult i32 %1, 4
%46 = and i64 %40, 4294967292
%47 = insertelement <4 x i32> poison, i32 %26, i64 0
%48 = shufflevector <4 x i32> %47, <4 x i32> poison, <4 x i32> zeroinitializer
%49 = insertelement <4 x double> poison, double %37, i64 0
%50 = shufflevector <4 x double> %49, <4 x double> poison, <4 x i32> zeroinitializer
%51 = and i64 %44, 1
%52 = icmp eq i64 %42, 0
%53 = and i64 %44, 9223372036854775806
%54 = icmp eq i64 %51, 0
%55 = icmp eq i64 %46, %40
br label %82
56: ; preds = %76, %18
%57 = phi i32 [ %21, %18 ], [ %71, %76 ]
%58 = phi i32 [ %20, %18 ], [ %69, %76 ]
%59 = add nuw nsw i64 %19, 1
%60 = icmp eq i64 %59, %13
br i1 %60, label %25, label %18
61: ; preds = %22, %76
%62 = phi i64 [ 0, %22 ], [ %77, %76 ]
%63 = phi i32 [ %20, %22 ], [ %69, %76 ]
%64 = phi i32 [ %21, %22 ], [ %71, %76 ]
%65 = load i32*, i32** %23
%66 = getelementptr inbounds i32, i32* %65, i64 %62
%67 = load i32, i32* %66
%68 = icmp slt i32 %63, %67
%69 = select i1 %68, i32 %67, i32 %63
%70 = icmp sgt i32 %64, %67
%71 = select i1 %70, i32 %67, i32 %64
%72 = icmp slt i32 %67, -1000
br i1 %72, label %73, label %76
73: ; preds = %61
%74 = trunc i64 %62 to i32
%75 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %71, i32 %74, i32 %24)
br label %76
76: ; preds = %61, %73
%77 = add nuw nsw i64 %62, 1
%78 = icmp eq i64 %77, %14
br i1 %78, label %56, label %61
79: ; preds = %132
%80 = icmp ult i64 %135, %38
%81 = icmp eq i64 %135, %39
br i1 %81, label %152, label %82
82: ; preds = %34, %79
%83 = phi i64 [ 0, %34 ], [ %135, %79 ]
%84 = phi i1 [ true, %34 ], [ %80, %79 ]
br i1 %35, label %85, label %132
85: ; preds = %82
%86 = getelementptr inbounds i32*, i32** %0, i64 %83
%87 = load i32*, i32** %86
br i1 %45, label %130, label %88
88: ; preds = %85
br i1 %52, label %116, label %89
89: ; preds = %88, %89
%90 = phi i64 [ %113, %89 ], [ 0, %88 ]
%91 = phi i64 [ %114, %89 ], [ 0, %88 ]
%92 = getelementptr inbounds i32, i32* %87, i64 %90
%93 = bitcast i32* %92 to <4 x i32>*
%94 = load <4 x i32>, <4 x i32>* %93
%95 = sub nsw <4 x i32> %94, %48
%96 = sitofp <4 x i32> %95 to <4 x double>
%97 = fdiv <4 x double> %96, %50
%98 = fmul <4 x double> %97, <double 2.550000e+02, double 2.550000e+02, double 2.550000e+02, double 2.550000e+02>
%99 = fptosi <4 x double> %98 to <4 x i8>
%100 = getelementptr inbounds [50000 x i8], [50000 x i8]* %5, i64 0, i64 %90
%101 = bitcast i8* %100 to <4 x i8>*
store <4 x i8> %99, <4 x i8>* %101
%102 = or i64 %90, 4
%103 = getelementptr inbounds i32, i32* %87, i64 %102
%104 = bitcast i32* %103 to <4 x i32>*
%105 = load <4 x i32>, <4 x i32>* %104
%106 = sub nsw <4 x i32> %105, %48
%107 = sitofp <4 x i32> %106 to <4 x double>
%108 = fdiv <4 x double> %107, %50
%109 = fmul <4 x double> %108, <double 2.550000e+02, double 2.550000e+02, double 2.550000e+02, double 2.550000e+02>
%110 = fptosi <4 x double> %109 to <4 x i8>
%111 = getelementptr inbounds [50000 x i8], [50000 x i8]* %5, i64 0, i64 %102
%112 = bitcast i8* %111 to <4 x i8>*
store <4 x i8> %110, <4 x i8>* %112
%113 = add nuw i64 %90, 8
%114 = add i64 %91, 2
%115 = icmp eq i64 %114, %53
br i1 %115, label %116, label %89
116: ; preds = %89, %88
%117 = phi i64 [ 0, %88 ], [ %113, %89 ]
br i1 %54, label %129, label %118
118: ; preds = %116
%119 = getelementptr inbounds i32, i32* %87, i64 %117
%120 = bitcast i32* %119 to <4 x i32>*
%121 = load <4 x i32>, <4 x i32>* %120
%122 = sub nsw <4 x i32> %121, %48
%123 = sitofp <4 x i32> %122 to <4 x double>
%124 = fdiv <4 x double> %123, %50
%125 = fmul <4 x double> %124, <double 2.550000e+02, double 2.550000e+02, double 2.550000e+02, double 2.550000e+02>
%126 = fptosi <4 x double> %125 to <4 x i8>
%127 = getelementptr inbounds [50000 x i8], [50000 x i8]* %5, i64 0, i64 %117
%128 = bitcast i8* %127 to <4 x i8>*
store <4 x i8> %126, <4 x i8>* %128
br label %129
129: ; preds = %116, %118
br i1 %55, label %132, label %130
130: ; preds = %85, %129
%131 = phi i64 [ 0, %85 ], [ %46, %129 ]
br label %136
132: ; preds = %136, %129, %82
%133 = call i32 @fwrite(i8* %6, i32 %1, i32 1, i32* %7)
%134 = icmp eq i32 %133, 1
%135 = add nuw nsw i64 %83, 1
br i1 %134, label %79, label %148
136: ; preds = %130, %136
%137 = phi i64 [ %146, %136 ], [ %131, %130 ]
%138 = getelementptr inbounds i32, i32* %87, i64 %137
%139 = load i32, i32* %138
%140 = sub nsw i32 %139, %26
%141 = sitofp i32 %140 to double
%142 = fdiv double %141, %37
%143 = fmul double %142, 2.550000e+02
%144 = fptosi double %143 to i8
%145 = getelementptr inbounds [50000 x i8], [50000 x i8]* %5, i64 0, i64 %137
store i8 %144, i8* %145
%146 = add nuw nsw i64 %137, 1
%147 = icmp eq i64 %146, %40
br i1 %147, label %132, label %136
148: ; preds = %132
%149 = load i32, i32* @stderr
%150 = tail call i32 (i32, i8*, ...) @fprintf(i32 %149, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %3)
%151 = tail call i32 @fclose(i32* %7)
br i1 %84, label %154, label %152
152: ; preds = %79, %25, %148
%153 = tail call i32 @fclose(i32* %7)
br label %154
154: ; preds = %152, %148, %15
%155 = phi i32 [ -1, %15 ], [ 0, %152 ], [ -1, %148 ]
ret i32 %155
}