#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*/ exit(int);
float fabs(float);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ printf(char *, int, int, char *);
int /*<<< orphan*/ stderr;
void pgmwrite(char *filename, void *vx, int nx, int ny) {
  FILE *fp;
  int i, j, k, grey;
  float xmin, xmax, tmp, fval;
  float thresh = 255.0;
  float *x = (float *)vx;
  if (NULL == (fp = fopen(filename, "w"))) {
    fprintf(stderr, "pgmwrite: cannot create <%s>\n", filename);
    exit(-1);
  }
  printf("Writing %d x %d picture into file: %s\n", nx, ny, filename);
  xmin = fabs(x[0]);
  xmax = fabs(x[0]);
  for (i = 0; i < nx * ny; i++) {
    if (fabs(x[i]) < xmin)
      xmin = fabs(x[i]);
    if (fabs(x[i]) > xmax)
      xmax = fabs(x[i]);
  }
  if (xmin == xmax)
    xmin = xmax - 1.0;
  fprintf(fp, "P2\n");
  fprintf(fp, "# Written by pgmio::pgmwrite\n");
  fprintf(fp, "%d %d\n", nx, ny);
  fprintf(fp, "%d\n", (int)thresh);
  k = 0;
  for (j = ny - 1; j >= 0; j--) {
    for (i = 0; i < nx; i++) {
      tmp = x[j + ny * i];
      fval = thresh * ((fabs(tmp) - xmin) / (xmax - xmin)) + 0.5;
      grey = (int)fval;
      fprintf(fp, "%3d ", grey);
      if (0 == (k + 1) % 16)
        fprintf(fp, "\n");
      k++;
    }
  }
  if (0 != k % 16)
    fprintf(fp, "\n");
  fclose(fp);
}


x86 assembly (clang, -O0):
<pgmwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
movss  0xe82(%rip),%xmm0
movss  %xmm0,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11d3 <pgmwrite+0x73>
mov    0x2e2c(%rip),%rax
movslq (%rax),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xe54(%rip),%rdi
call   1040 <printf@plt>
mov    -0x50(%rbp),%rax
movss  (%rax),%xmm0
call   1050 <fabs@plt>
movss  %xmm0,-0x34(%rbp)
mov    -0x50(%rbp),%rax
movss  (%rax),%xmm0
call   1050 <fabs@plt>
movss  %xmm0,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
jge    12a6 <pgmwrite+0x146>
mov    -0x50(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1050 <fabs@plt>
movaps %xmm0,%xmm1
movss  -0x34(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    1260 <pgmwrite+0x100>
mov    -0x50(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1050 <fabs@plt>
movss  %xmm0,-0x34(%rbp)
mov    -0x50(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1050 <fabs@plt>
ucomiss -0x38(%rbp),%xmm0
jbe    1293 <pgmwrite+0x133>
mov    -0x50(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
call   1050 <fabs@plt>
movss  %xmm0,-0x38(%rbp)
jmp    1298 <pgmwrite+0x138>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1214 <pgmwrite+0xb4>
movss  -0x34(%rbp),%xmm0
ucomiss -0x38(%rbp),%xmm0
jne    12d9 <pgmwrite+0x179>
jp     12d9 <pgmwrite+0x179>
movss  -0x38(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd3c(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xd7b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xd6d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
cvttss2si -0x44(%rbp),%edx
lea    0xd5f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jl     1433 <pgmwrite+0x2d3>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1420 <pgmwrite+0x2c0>
mov    -0x50(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%edx
imul   -0x24(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x3c(%rbp)
movss  -0x44(%rbp),%xmm0
movss  %xmm0,-0x54(%rbp)
movss  -0x3c(%rbp),%xmm0
call   1050 <fabs@plt>
movaps %xmm0,%xmm1
movss  -0x54(%rbp),%xmm0
subss  -0x34(%rbp),%xmm1
movss  -0x38(%rbp),%xmm2
subss  -0x34(%rbp),%xmm2
divss  %xmm2,%xmm1
mulss  %xmm1,%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xc5b(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x40(%rbp)
cvttss2si -0x40(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%edx
lea    0xcb0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    %edx,%eax
jne    1409 <pgmwrite+0x2a9>
mov    -0x20(%rbp),%rdi
lea    0xc5f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    134d <pgmwrite+0x1ed>
jmp    1425 <pgmwrite+0x2c5>
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    133c <pgmwrite+0x1dc>
mov    -0x2c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    %edx,%eax
je     145a <pgmwrite+0x2fa>
mov    -0x20(%rbp),%rdi
lea    0xc0e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pgmwrite>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe8b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     144e <pgmwrite+0x2de>
mov    %rax,%rbx
lea    0xe93(%rip),%rdi
mov    %r12d,%esi
mov    %r15d,%edx
mov    %r14,%rcx
call   1040 <printf@plt>
movss  0x0(%rbp),%xmm4
andps  0xe3d(%rip),%xmm4
mov    %r15d,%ecx
imul   %r12d,%ecx
movaps %xmm4,%xmm5
test   %ecx,%ecx
jle    127f <pgmwrite+0x10f>
minss  %xmm4,%xmm5
maxss  %xmm4,%xmm4
cmp    $0x1,%ecx
je     127f <pgmwrite+0x10f>
mov    %ecx,%eax
add    $0xffffffffffffffff,%rax
cmp    $0x2,%ecx
jne    11f8 <pgmwrite+0x88>
mov    $0x1,%ecx
jmp    125d <pgmwrite+0xed>
mov    %rax,%rdx
and    $0xfffffffffffffffe,%rdx
neg    %rdx
mov    $0x1,%ecx
movaps 0xdf2(%rip),%xmm0
movaps %xmm4,%xmm1
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movss  0x0(%rbp,%rcx,4),%xmm2
movss  0x4(%rbp,%rcx,4),%xmm4
andps  %xmm0,%xmm2
movaps %xmm2,%xmm3
minss  %xmm5,%xmm3
maxss  %xmm1,%xmm2
andps  %xmm0,%xmm4
movaps %xmm4,%xmm5
minss  %xmm3,%xmm5
maxss  %xmm2,%xmm4
lea    (%rdx,%rcx,1),%rsi
add    $0x2,%rsi
add    $0x2,%rcx
movaps %xmm4,%xmm1
cmp    $0x1,%rsi
jne    1220 <pgmwrite+0xb0>
test   $0x1,%al
je     127f <pgmwrite+0x10f>
movss  0x0(%rbp,%rcx,4),%xmm0
andps  0xd92(%rip),%xmm0
movaps %xmm0,%xmm1
minss  %xmm5,%xmm1
maxss  %xmm4,%xmm0
movaps %xmm0,%xmm4
movaps %xmm1,%xmm5
movaps %xmm5,0x20(%rsp)
movaps %xmm4,0x30(%rsp)
lea    0xdd3(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
lea    0xdbe(%rip),%rdi
mov    $0x1d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
lea    0xdc3(%rip),%rsi
mov    %rbx,%rdi
mov    %r12d,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xdaf(%rip),%rsi
mov    %rbx,%rdi
mov    $0xff,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %r15d,%r15d
jle    1438 <pgmwrite+0x2c8>
movss  0xd17(%rip),%xmm0
movaps 0x30(%rsp),%xmm1
addss  %xmm1,%xmm0
movaps 0x20(%rsp),%xmm2
movaps %xmm2,%xmm3
cmpeqss %xmm1,%xmm3
andps  %xmm3,%xmm0
andnps %xmm2,%xmm3
orps   %xmm0,%xmm3
movaps %xmm3,0x20(%rsp)
subss  %xmm3,%xmm1
mov    %r15d,0x10(%rsp)
mov    %r15d,%ecx
test   %r12d,%r12d
mov    $0x0,%eax
cmovg  %r12d,%eax
mov    %eax,0xc(%rsp)
mov    %r12d,%eax
mov    %rax,0x40(%rsp)
lea    0x0(,%rcx,4),%r15
lea    -0x4(,%rcx,4),%r14
ff
add    %rbp,%r14
mov    $0x1,%r13d
lea    0xd2b(%rip),%rbp
xor    %edx,%edx
mov    %r12d,0x14(%rsp)
movaps %xmm1,0x30(%rsp)
jmp    13a1 <pgmwrite+0x231>
nop
mov    0x14(%rsp),%r12d
mov    0x18(%rsp),%edx
add    %r12d,%edx
mov    0x50(%rsp),%rcx
mov    0x48(%rsp),%r14
mov    0x1c(%rsp),%r13d
lea    -0x1(%rcx),%rax
add    $0xfffffffffffffffc,%r14
add    0xc(%rsp),%r13d
cmp    $0x2,%rcx
mov    %rax,%rcx
jl     141e <pgmwrite+0x2ae>
test   %r12d,%r12d
jle    138b <pgmwrite+0x21b>
mov    %edx,0x18(%rsp)
mov    %rcx,0x50(%rsp)
mov    %r13d,0x1c(%rsp)
mov    0x40(%rsp),%r12
mov    %r14,0x48(%rsp)
jmp    13d2 <pgmwrite+0x262>
add    %r15,%r14
add    $0x1,%r13d
add    $0xffffffffffffffff,%r12
movaps 0x30(%rsp),%xmm1
je     1370 <pgmwrite+0x200>
movss  (%r14),%xmm0
andps  0xc22(%rip),%xmm0
subss  0x20(%rsp),%xmm0
divss  %xmm1,%xmm0
mulss  0xc24(%rip),%xmm0
addss  0xc20(%rip),%xmm0
cvttss2si %xmm0,%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
test   $0xf,%r13b
jne    13c0 <pgmwrite+0x250>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
jmp    13c0 <pgmwrite+0x250>
mov    0xc(%rsp),%eax
imul   0x10(%rsp),%eax
test   $0xf,%al
je     1438 <pgmwrite+0x2c8>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2b8b(%rip),%rax
movslq (%rax),%rdi
lea    0xbbf(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"pgmwrite: cannot create <%s>\0A\00"
@.str.2 = [39 x i8] c"Writing %d x %d picture into file: %s\0A\00"
@.str.3 = [4 x i8] c"P2\0A\00"
@.str.4 = [30 x i8] c"# Written by pgmio::pgmwrite\0A\00"
@.str.5 = [7 x i8] c"%d %d\0A\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@.str.7 = [5 x i8] c"%3d \00"
define void @pgmwrite(i8* %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = bitcast i8* %1 to float*
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %14
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i32*
%12 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %4
%15 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i32 %2, i32 %3, i8* %0)
%16 = load float, float* %5
%17 = tail call float @llvm.fabs.f32(float %16)
%18 = mul i32 %3, %2
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %72
20: ; preds = %14
%21 = tail call float @llvm.fabs.f32(float %16)
%22 = fcmp olt float %21, %17
%23 = select i1 %22, float %21, float %17
%24 = fcmp ogt float %21, %17
%25 = select i1 %24, float %21, float %17
%26 = icmp eq i32 %18, 1
br i1 %26, label %72, label %27
27: ; preds = %20
%28 = zext i32 %18 to i64
%29 = add nsw i64 %28, -1
%30 = and i64 %29, 1
%31 = icmp eq i32 %18, 2
br i1 %31, label %57, label %32
32: ; preds = %27
%33 = and i64 %29, -2
br label %34
34: ; preds = %34, %32
%35 = phi i64 [ 1, %32 ], [ %54, %34 ]
%36 = phi float [ %25, %32 ], [ %53, %34 ]
%37 = phi float [ %23, %32 ], [ %51, %34 ]
%38 = phi i64 [ 0, %32 ], [ %55, %34 ]
%39 = getelementptr inbounds float, float* %5, i64 %35
%40 = load float, float* %39
%41 = tail call float @llvm.fabs.f32(float %40)
%42 = fcmp olt float %41, %37
%43 = select i1 %42, float %41, float %37
%44 = fcmp ogt float %41, %36
%45 = select i1 %44, float %41, float %36
%46 = add nuw nsw i64 %35, 1
%47 = getelementptr inbounds float, float* %5, i64 %46
%48 = load float, float* %47
%49 = tail call float @llvm.fabs.f32(float %48)
%50 = fcmp olt float %49, %43
%51 = select i1 %50, float %49, float %43
%52 = fcmp ogt float %49, %45
%53 = select i1 %52, float %49, float %45
%54 = add nuw nsw i64 %35, 2
%55 = add i64 %38, 2
%56 = icmp eq i64 %55, %33
br i1 %56, label %57, label %34
57: ; preds = %34, %27
%58 = phi float [ undef, %27 ], [ %51, %34 ]
%59 = phi float [ undef, %27 ], [ %53, %34 ]
%60 = phi i64 [ 1, %27 ], [ %54, %34 ]
%61 = phi float [ %25, %27 ], [ %53, %34 ]
%62 = phi float [ %23, %27 ], [ %51, %34 ]
%63 = icmp eq i64 %30, 0
br i1 %63, label %72, label %64
64: ; preds = %57
%65 = getelementptr inbounds float, float* %5, i64 %60
%66 = load float, float* %65
%67 = tail call float @llvm.fabs.f32(float %66)
%68 = fcmp olt float %67, %62
%69 = select i1 %68, float %67, float %62
%70 = fcmp ogt float %67, %61
%71 = select i1 %70, float %67, float %61
br label %72
72: ; preds = %64, %57, %20, %14
%73 = phi float [ %17, %14 ], [ %25, %20 ], [ %59, %57 ], [ %71, %64 ]
%74 = phi float [ %17, %14 ], [ %23, %20 ], [ %58, %57 ], [ %69, %64 ]
%75 = fcmp oeq float %74, %73
%76 = fadd float %73, -1.000000e+00
%77 = select i1 %75, float %76, float %74
%78 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3, i64 1, i32* %6)
%79 = tail call i64 @fwrite(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i64 29, i64 1, i32* %6)
%80 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 %2, i32 %3)
%81 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 255)
%82 = icmp sgt i32 %3, 0
br i1 %82, label %83, label %126
83: ; preds = %72
%84 = icmp sgt i32 %2, 0
%85 = fsub float %73, %77
%86 = zext i32 %3 to i64
%87 = call i32 @llvm.smax.i32(i32 %2, i32 0)
%88 = zext i32 %2 to i64
br label %94
89: ; preds = %117
%90 = add i32 %96, %2
br label %91
91: ; preds = %89, %94
%92 = phi i32 [ %96, %94 ], [ %90, %89 ]
%93 = icmp sgt i64 %95, 1
br i1 %93, label %94, label %120
94: ; preds = %83, %91
%95 = phi i64 [ %86, %83 ], [ %97, %91 ]
%96 = phi i32 [ 0, %83 ], [ %92, %91 ]
%97 = add nsw i64 %95, -1
br i1 %84, label %98, label %91
98: ; preds = %94, %117
%99 = phi i64 [ %118, %117 ], [ 0, %94 ]
%100 = phi i32 [ %112, %117 ], [ %96, %94 ]
%101 = mul nsw i64 %99, %86
%102 = add nsw i64 %101, %97
%103 = getelementptr inbounds float, float* %5, i64 %102
%104 = load float, float* %103
%105 = tail call float @llvm.fabs.f32(float %104)
%106 = fsub float %105, %77
%107 = fdiv float %106, %85
%108 = fmul float %107, 2.550000e+02
%109 = fadd float %108, 5.000000e-01
%110 = fptosi float %109 to i32
%111 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %110)
%112 = add nsw i32 %100, 1
%113 = and i32 %112, 15
%114 = icmp eq i32 %113, 0
br i1 %114, label %115, label %117
115: ; preds = %98
%116 = tail call i32 @fputc(i32 10, i32* %6)
br label %117
117: ; preds = %115, %98
%118 = add nuw nsw i64 %99, 1
%119 = icmp eq i64 %118, %88
br i1 %119, label %89, label %98
120: ; preds = %91
%121 = mul i32 %87, %3
%122 = and i32 %121, 15
%123 = icmp eq i32 %122, 0
br i1 %123, label %126, label %124
124: ; preds = %120
%125 = tail call i32 @fputc(i32 10, i32* %6)
br label %126
126: ; preds = %72, %124, %120
%127 = tail call i32 @fclose(i32* %6)
ret void
}