#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 */
scalar_t__ EOF;
int /*<<< orphan*/ error(char *);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
void write_pgm_image_int(int *image, int xsize, int ysize, char *name) {
  FILE *f;
  int x, y, n, v, max, min;
  if ((image == NULL) || (xsize <= 0) || (ysize <= 0))
    error("write_pgm_image_int: invalid input image.");
  max = min = 0;
  for (y = 0; y < ysize; y++)
    for (x = 0; x < xsize; x++) {
      v = image[x + y * xsize];
      if (v > max)
        max = v;
      if (v < min)
        min = v;
    }
  if (min < 0)
    fprintf(stderr, "Warning: write_pgm_image_int: negative values in '%s'.\n",
            name);
  if (max > 65535)
    fprintf(stderr,
            "Warning: write_pgm_image_int: values exceeding 65535 in '%s'.\n",
            name);
  if (strcmp(name, "-") == 0)
    f = stdout;
  else
    f = fopen(name, "w");
  if (f == NULL)
    error("write_pgm_image_int: unable to open output image file.");
  fprintf(f, "P2\n");
  fprintf(f, "%d %d\n", xsize, ysize);
  fprintf(f, "%d\n", max);
  for (n = 0, y = 0; y < ysize; y++)
    for (x = 0; x < xsize; x++) {
      fprintf(f, "%d ", image[x + y * xsize]);
      if (++n == 8) {
        fprintf(f, "\n");
        n = 0;
      }
    }
  if ((f != stdout) && (fclose(f) == EOF))
    error("write_pgm_image_int: unable to close file.");
}


x86 assembly (clang, -O0):
<write_pgm_image_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1185 <write_pgm_image_int+0x35>
cmpl   $0x0,-0xc(%rbp)
jle    1185 <write_pgm_image_int+0x35>
cmpl   $0x0,-0x10(%rbp)
jg     1191 <write_pgm_image_int+0x41>
lea    0xe74(%rip),%rdi
call   1060 <error@plt>
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1228 <write_pgm_image_int+0xd8>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1215 <write_pgm_image_int+0xc5>
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%edx
imul   -0xc(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jle    11f0 <write_pgm_image_int+0xa0>
mov    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x38(%rbp),%eax
jge    1202 <write_pgm_image_int+0xb2>
mov    -0x30(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    1207 <write_pgm_image_int+0xb7>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b9 <write_pgm_image_int+0x69>
jmp    121a <write_pgm_image_int+0xca>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a6 <write_pgm_image_int+0x56>
cmpl   $0x0,-0x38(%rbp)
jge    124e <write_pgm_image_int+0xfe>
mov    0x2d9f(%rip),%rax
movslq (%rax),%rdi
mov    -0x18(%rbp),%rdx
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0xffff,-0x34(%rbp)
jle    1277 <write_pgm_image_int+0x127>
mov    0x2d76(%rip),%rax
movslq (%rax),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    12a4 <write_pgm_image_int+0x154>
mov    0x2d38(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    12b8 <write_pgm_image_int+0x168>
mov    -0x18(%rbp),%rdi
lea    0xdf4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12cf <write_pgm_image_int+0x17f>
lea    0xddb(%rip),%rdi
call   1060 <error@plt>
mov    -0x20(%rbp),%rdi
lea    0xe02(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    13b4 <write_pgm_image_int+0x264>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    13a1 <write_pgm_image_int+0x251>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%edx
imul   -0xc(%rbp),%edx
add    %edx,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
lea    0xd8b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
cmp    $0x8,%eax
jne    138e <write_pgm_image_int+0x23e>
mov    -0x20(%rbp),%rdi
lea    0xd1f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
jmp    1393 <write_pgm_image_int+0x243>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    132f <write_pgm_image_int+0x1df>
jmp    13a6 <write_pgm_image_int+0x256>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    131c <write_pgm_image_int+0x1cc>
mov    -0x20(%rbp),%rax
mov    0x2c11(%rip),%rcx
cmp    (%rcx),%rax
je     13ed <write_pgm_image_int+0x29d>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2c10(%rip),%rcx
cmp    (%rcx),%rax
jne    13ed <write_pgm_image_int+0x29d>
lea    0xd03(%rip),%rdi
call   1060 <error@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_pgm_image_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rcx,0x8(%rsp)
mov    %edx,%r14d
mov    %esi,%r13d
movslq %esi,%rax
mov    %rax,0x10(%rsp)
mov    %edx,%r12d
mov    %esi,%r15d
mov    %rdi,0x18(%rsp)
test   %rdi,%rdi
je     11ab <write_pgm_image_int+0x3b>
test   %r13d,%r13d
jle    11ab <write_pgm_image_int+0x3b>
test   %r14d,%r14d
jg     11c0 <write_pgm_image_int+0x50>
lea    0xe4e(%rip),%rdi
call   1070 <error@plt>
test   %r14d,%r14d
jle    150b <write_pgm_image_int+0x39b>
mov    %r14d,0x24(%rsp)
mov    %r15d,%r11d
and    $0xfffffff8,%r11d
lea    -0x8(%r11),%r9
mov    %r9,%r10
shr    $0x3,%r10
add    $0x1,%r10
mov    %r10,%r8
and    $0xfffffffffffffffe,%r8
mov    0x18(%rsp),%rcx
lea    0x30(%rcx),%rdi
mov    0x10(%rsp),%rax
lea    0x0(,%rax,4),%r14
xor    %esi,%esi
xor    %edx,%edx
xor    %ebp,%ebp
jmp    1213 <write_pgm_image_int+0xa3>
add    $0x1,%rsi
add    %r14,%rdi
add    %r14,%rcx
cmp    %r12,%rsi
je     14b5 <write_pgm_image_int+0x345>
test   %r13d,%r13d
jle    1200 <write_pgm_image_int+0x90>
cmp    $0x8,%r13d
jae    1230 <write_pgm_image_int+0xc0>
xor    %eax,%eax
jmp    1480 <write_pgm_image_int+0x310>
cs nopw 0x0(%rax,%rax,1)
nop
movd   %edx,%xmm0
pshufd $0x0,%xmm0,%xmm10
movd   %ebp,%xmm0
pshufd $0x0,%xmm0,%xmm2
test   %r9,%r9
je     149b <write_pgm_image_int+0x32b>
mov    %r8,%rdx
xor    %ebp,%ebp
movdqa %xmm10,%xmm4
movdqa %xmm2,%xmm3
nopw   0x0(%rax,%rax,1)
movdqu -0x30(%rdi,%rbp,4),%xmm1
movdqu -0x20(%rdi,%rbp,4),%xmm5
movdqu -0x10(%rdi,%rbp,4),%xmm9
movdqu (%rdi,%rbp,4),%xmm8
movdqa %xmm1,%xmm6
pcmpgtd %xmm2,%xmm6
movdqa %xmm1,%xmm0
pand   %xmm6,%xmm0
pandn  %xmm2,%xmm6
por    %xmm0,%xmm6
movdqa %xmm5,%xmm7
pcmpgtd %xmm3,%xmm7
movdqa %xmm5,%xmm0
pand   %xmm7,%xmm0
pandn  %xmm3,%xmm7
por    %xmm0,%xmm7
movdqa %xmm10,%xmm0
pcmpgtd %xmm1,%xmm0
pand   %xmm0,%xmm1
pandn  %xmm10,%xmm0
por    %xmm1,%xmm0
movdqa %xmm4,%xmm1
pcmpgtd %xmm5,%xmm1
pand   %xmm1,%xmm5
pandn  %xmm4,%xmm1
por    %xmm5,%xmm1
movdqa %xmm9,%xmm2
pcmpgtd %xmm6,%xmm2
movdqa %xmm9,%xmm3
pand   %xmm2,%xmm3
pandn  %xmm6,%xmm2
por    %xmm3,%xmm2
movdqa %xmm8,%xmm3
pcmpgtd %xmm7,%xmm3
movdqa %xmm8,%xmm4
pand   %xmm3,%xmm4
pandn  %xmm7,%xmm3
por    %xmm4,%xmm3
movdqa %xmm0,%xmm10
pcmpgtd %xmm9,%xmm10
pand   %xmm10,%xmm9
pandn  %xmm0,%xmm10
por    %xmm9,%xmm10
movdqa %xmm1,%xmm4
pcmpgtd %xmm8,%xmm4
pand   %xmm4,%xmm8
pandn  %xmm1,%xmm4
por    %xmm8,%xmm4
add    $0x10,%rbp
add    $0xfffffffffffffffe,%rdx
jne    1260 <write_pgm_image_int+0xf0>
test   $0x1,%r10b
je     13d6 <write_pgm_image_int+0x266>
mov    %rsi,%rax
imul   0x10(%rsp),%rax
add    %rax,%rbp
mov    0x18(%rsp),%rax
movdqu (%rax,%rbp,4),%xmm0
movdqu 0x10(%rax,%rbp,4),%xmm1
movdqa %xmm0,%xmm5
pcmpgtd %xmm2,%xmm5
movdqa %xmm0,%xmm6
pand   %xmm5,%xmm6
pandn  %xmm2,%xmm5
por    %xmm6,%xmm5
movdqa %xmm1,%xmm6
pcmpgtd %xmm3,%xmm6
movdqa %xmm1,%xmm2
pand   %xmm6,%xmm2
pandn  %xmm3,%xmm6
por    %xmm2,%xmm6
movdqa %xmm10,%xmm7
pcmpgtd %xmm0,%xmm7
pand   %xmm7,%xmm0
pandn  %xmm10,%xmm7
por    %xmm0,%xmm7
movdqa %xmm4,%xmm0
pcmpgtd %xmm1,%xmm0
pand   %xmm0,%xmm1
pandn  %xmm4,%xmm0
por    %xmm1,%xmm0
movdqa %xmm5,%xmm2
movdqa %xmm6,%xmm3
movdqa %xmm7,%xmm10
movdqa %xmm0,%xmm4
movdqa %xmm2,%xmm0
pcmpgtd %xmm3,%xmm0
pand   %xmm0,%xmm2
pandn  %xmm3,%xmm0
por    %xmm2,%xmm0
pshufd $0xee,%xmm0,%xmm1
movdqa %xmm0,%xmm2
pcmpgtd %xmm1,%xmm2
pand   %xmm2,%xmm0
pandn  %xmm1,%xmm2
por    %xmm0,%xmm2
pshufd $0x55,%xmm2,%xmm0
movdqa %xmm2,%xmm1
pcmpgtd %xmm0,%xmm1
pand   %xmm1,%xmm2
pandn  %xmm0,%xmm1
por    %xmm2,%xmm1
movd   %xmm1,%ebp
movdqa %xmm4,%xmm0
pcmpgtd %xmm10,%xmm0
pand   %xmm0,%xmm10
pandn  %xmm4,%xmm0
por    %xmm10,%xmm0
pshufd $0xee,%xmm0,%xmm1
movdqa %xmm1,%xmm2
pcmpgtd %xmm0,%xmm2
pand   %xmm2,%xmm0
pandn  %xmm1,%xmm2
por    %xmm0,%xmm2
pshufd $0x55,%xmm2,%xmm0
movdqa %xmm0,%xmm1
pcmpgtd %xmm2,%xmm1
pand   %xmm1,%xmm2
pandn  %xmm0,%xmm1
por    %xmm2,%xmm1
movd   %xmm1,%edx
mov    %r11,%rax
cmp    %r15,%r11
je     1200 <write_pgm_image_int+0x90>
nopl   0x0(%rax)
mov    (%rcx,%rax,4),%ebx
cmp    %ebp,%ebx
cmovg  %ebx,%ebp
cmp    %edx,%ebx
cmovl  %ebx,%edx
add    $0x1,%rax
cmp    %rax,%r15
jne    1480 <write_pgm_image_int+0x310>
jmp    1200 <write_pgm_image_int+0x90>
xor    %ebp,%ebp
movdqa %xmm10,%xmm4
movdqa %xmm2,%xmm3
test   $0x1,%r10b
jne    134f <write_pgm_image_int+0x1df>
jmp    13d6 <write_pgm_image_int+0x266>
test   %edx,%edx
jns    14d6 <write_pgm_image_int+0x366>
mov    0x2b18(%rip),%rax
movslq (%rax),%rdi
lea    0xb60(%rip),%rsi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%al
mov    %eax,0x4(%rsp)
cmp    $0x10000,%ebp
mov    0x24(%rsp),%r14d
mov    0x8(%rsp),%rbx
jl     151a <write_pgm_image_int+0x3aa>
mov    0x2ae3(%rip),%rax
movslq (%rax),%rdi
lea    0xb63(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1515 <write_pgm_image_int+0x3a5>
movl   $0x0,0x4(%rsp)
xor    %ebp,%ebp
mov    0x8(%rsp),%rbx
lea    0xb80(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1542 <write_pgm_image_int+0x3d2>
lea    0xb6e(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
jmp    154c <write_pgm_image_int+0x3dc>
mov    0x2a87(%rip),%rax
mov    (%rax),%rbx
mov    %r12,0x8(%rsp)
test   %rbx,%rbx
jne    1562 <write_pgm_image_int+0x3f2>
lea    0xb48(%rip),%rdi
call   1070 <error@plt>
lea    0xb73(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1090 <fwrite@plt>
lea    0xb5e(%rip),%rsi
mov    %rbx,%rdi
mov    %r13d,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xb4a(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
cmpb   $0x0,0x4(%rsp)
je     163b <write_pgm_image_int+0x4cb>
shlq   $0x2,0x10(%rsp)
lea    0xb2a(%rip),%rbp
xor    %r14d,%r14d
xor    %r12d,%r12d
mov    %r13d,0x4(%rsp)
jmp    15ea <write_pgm_image_int+0x47a>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
mov    0x10(%rsp),%rax
add    %rax,0x18(%rsp)
cmp    0x8(%rsp),%r14
mov    0x4(%rsp),%r13d
je     163b <write_pgm_image_int+0x4cb>
test   %r13d,%r13d
jle    15d0 <write_pgm_image_int+0x460>
xor    %r13d,%r13d
jmp    1609 <write_pgm_image_int+0x499>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r13
cmp    %r13,%r15
je     15d0 <write_pgm_image_int+0x460>
mov    0x18(%rsp),%rax
mov    (%rax,%r13,4),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%r12d
cmp    $0x8,%r12d
jne    1600 <write_pgm_image_int+0x490>
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
xor    %r12d,%r12d
jmp    1600 <write_pgm_image_int+0x490>
mov    0x298e(%rip),%rax
cmp    (%rax),%rbx
je     1675 <write_pgm_image_int+0x505>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2992(%rip),%rcx
cmp    (%rcx),%rax
jne    1675 <write_pgm_image_int+0x505>
lea    0xa89(%rip),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <error@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"write_pgm_image_int: invalid input image.\00"
@stderr = global i32 0
@.str.1 = [56 x i8] c"Warning: write_pgm_image_int: negative values in '%s'.\0A\00"
@.str.2 = [63 x i8] c"Warning: write_pgm_image_int: values exceeding 65535 in '%s'.\0A\00"
@.str.3 = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [55 x i8] c"write_pgm_image_int: unable to open output image file.\00"
@.str.6 = [4 x i8] c"P2\0A\00"
@.str.7 = [7 x i8] c"%d %d\0A\00"
@.str.8 = [4 x i8] c"%d\0A\00"
@.str.9 = [4 x i8] c"%d \00"
@.str.10 = [2 x i8] c"\0A\00"
@EOF = global i64 0
@.str.11 = [43 x i8] c"write_pgm_image_int: unable to close file.\00"
define void @write_pgm_image_int(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%16 = load i32*, i32** %5
%17 = icmp eq i32* %16, null
br i1 %17, label %24, label %18
18: ; preds = %4
%19 = load i32, i32* %6
%20 = icmp sle i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = load i32, i32* %7
%23 = icmp sle i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21, %18, %4
%25 = call i32 @error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
store i32 0, i32* %15
store i32 0, i32* %14
store i32 0, i32* %11
br label %27
27: ; preds = %62, %26
%28 = load i32, i32* %11
%29 = load i32, i32* %7
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %65
31: ; preds = %27
store i32 0, i32* %10
br label %32
32: ; preds = %58, %31
%33 = load i32, i32* %10
%34 = load i32, i32* %6
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %61
36: ; preds = %32
%37 = load i32*, i32** %5
%38 = load i32, i32* %10
%39 = load i32, i32* %11
%40 = load i32, i32* %6
%41 = mul nsw i32 %39, %40
%42 = add nsw i32 %38, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %37, i64 %43
%45 = load i32, i32* %44
store i32 %45, i32* %13
%46 = load i32, i32* %13
%47 = load i32, i32* %14
%48 = icmp sgt i32 %46, %47
br i1 %48, label %49, label %51
49: ; preds = %36
%50 = load i32, i32* %13
store i32 %50, i32* %14
br label %51
51: ; preds = %49, %36
%52 = load i32, i32* %13
%53 = load i32, i32* %15
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %57
55: ; preds = %51
%56 = load i32, i32* %13
store i32 %56, i32* %15
br label %57
57: ; preds = %55, %51
br label %58
58: ; preds = %57
%59 = load i32, i32* %10
%60 = add nsw i32 %59, 1
store i32 %60, i32* %10
br label %32
61: ; preds = %32
br label %62
62: ; preds = %61
%63 = load i32, i32* %11
%64 = add nsw i32 %63, 1
store i32 %64, i32* %11
br label %27
65: ; preds = %27
%66 = load i32, i32* %15
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %74
68: ; preds = %65
%69 = load i32, i32* @stderr
%70 = sext i32 %69 to i64
%71 = inttoptr i64 %70 to i32*
%72 = load i8*, i8** %8
%73 = call i32 (i32*, i8*, ...) @fprintf(i32* %71, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %68, %65
%75 = load i32, i32* %14
%76 = icmp sgt i32 %75, 65535
br i1 %76, label %77, label %83
77: ; preds = %74
%78 = load i32, i32* @stderr
%79 = sext i32 %78 to i64
%80 = inttoptr i64 %79 to i32*
%81 = load i8*, i8** %8
%82 = call i32 (i32*, i8*, ...) @fprintf(i32* %80, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i8* %81)
br label %83
83: ; preds = %77, %74
%84 = load i8*, i8** %8
%85 = call i64 @strcmp(i8* %84, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%86 = icmp eq i64 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %83
%88 = load i32*, i32** @stdout
store i32* %88, i32** %9
br label %92
89: ; preds = %83
%90 = load i8*, i8** %8
%91 = call i32* @fopen(i8* %90, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %91, i32** %9
br label %92
92: ; preds = %89, %87
%93 = load i32*, i32** %9
%94 = icmp eq i32* %93, null
br i1 %94, label %95, label %97
95: ; preds = %92
%96 = call i32 @error(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0))
br label %97
97: ; preds = %95, %92
%98 = load i32*, i32** %9
%99 = call i32 (i32*, i8*, ...) @fprintf(i32* %98, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%100 = load i32*, i32** %9
%101 = load i32, i32* %6
%102 = load i32, i32* %7
%103 = call i32 (i32*, i8*, ...) @fprintf(i32* %100, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %101, i32 %102)
%104 = load i32*, i32** %9
%105 = load i32, i32* %14
%106 = call i32 (i32*, i8*, ...) @fprintf(i32* %104, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %105)
store i32 0, i32* %12
store i32 0, i32* %11
br label %107
107: ; preds = %139, %97
%108 = load i32, i32* %11
%109 = load i32, i32* %7
%110 = icmp slt i32 %108, %109
br i1 %110, label %111, label %142
111: ; preds = %107
store i32 0, i32* %10
br label %112
112: ; preds = %135, %111
%113 = load i32, i32* %10
%114 = load i32, i32* %6
%115 = icmp slt i32 %113, %114
br i1 %115, label %116, label %138
116: ; preds = %112
%117 = load i32*, i32** %9
%118 = load i32*, i32** %5
%119 = load i32, i32* %10
%120 = load i32, i32* %11
%121 = load i32, i32* %6
%122 = mul nsw i32 %120, %121
%123 = add nsw i32 %119, %122
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i32, i32* %118, i64 %124
%126 = load i32, i32* %125
%127 = call i32 (i32*, i8*, ...) @fprintf(i32* %117, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %126)
%128 = load i32, i32* %12
%129 = add nsw i32 %128, 1
store i32 %129, i32* %12
%130 = icmp eq i32 %129, 8
br i1 %130, label %131, label %134
131: ; preds = %116
%132 = load i32*, i32** %9
%133 = call i32 (i32*, i8*, ...) @fprintf(i32* %132, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
store i32 0, i32* %12
br label %134
134: ; preds = %131, %116
br label %135
135: ; preds = %134
%136 = load i32, i32* %10
%137 = add nsw i32 %136, 1
store i32 %137, i32* %10
br label %112
138: ; preds = %112
br label %139
139: ; preds = %138
%140 = load i32, i32* %11
%141 = add nsw i32 %140, 1
store i32 %141, i32* %11
br label %107
142: ; preds = %107
%143 = load i32*, i32** %9
%144 = load i32*, i32** @stdout
%145 = icmp ne i32* %143, %144
br i1 %145, label %146, label %153
146: ; preds = %142
%147 = load i32*, i32** %9
%148 = call i64 @fclose(i32* %147)
%149 = load i64, i64* @EOF
%150 = icmp eq i64 %148, %149
br i1 %150, label %151, label %153
151: ; preds = %146
%152 = call i32 @error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0))
br label %153
153: ; preds = %151, %146, %142
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"write_pgm_image_int: invalid input image.\00"
@stderr = global i32 0
@.str.1 = [56 x i8] c"Warning: write_pgm_image_int: negative values in '%s'.\0A\00"
@.str.2 = [63 x i8] c"Warning: write_pgm_image_int: values exceeding 65535 in '%s'.\0A\00"
@.str.3 = [2 x i8] c"-\00"
@stdout = global i32* null
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [55 x i8] c"write_pgm_image_int: unable to open output image file.\00"
@.str.6 = [4 x i8] c"P2\0A\00"
@.str.7 = [7 x i8] c"%d %d\0A\00"
@.str.8 = [4 x i8] c"%d\0A\00"
@.str.9 = [4 x i8] c"%d \00"
@EOF = global i64 0
@.str.11 = [43 x i8] c"write_pgm_image_int: unable to close file.\00"
define void @write_pgm_image_int(i32* %0, i32 %1, i32 %2, i8* %3) {
%5 = icmp eq i32* %0, null
%6 = icmp slt i32 %1, 1
%7 = or i1 %5, %6
%8 = icmp slt i32 %2, 1
%9 = or i1 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = tail call i32 @error(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %154
13: ; preds = %4, %10
%14 = icmp sgt i32 %1, 0
%15 = sext i32 %1 to i64
%16 = zext i32 %2 to i64
%17 = zext i32 %1 to i64
%18 = and i64 %17, 4294967288
%19 = add nsw i64 %18, -8
%20 = lshr exact i64 %19, 3
%21 = add nuw nsw i64 %20, 1
%22 = icmp ult i32 %1, 8
%23 = and i64 %17, 4294967288
%24 = and i64 %21, 1
%25 = icmp eq i64 %19, 0
%26 = and i64 %21, 4611686018427387902
%27 = icmp eq i64 %24, 0
%28 = icmp eq i64 %23, %17
br label %29
29: ; preds = %13, %135
%30 = phi i64 [ 0, %13 ], [ %138, %135 ]
%31 = phi i32 [ 0, %13 ], [ %137, %135 ]
%32 = phi i32 [ 0, %13 ], [ %136, %135 ]
br i1 %14, label %33, label %135
33: ; preds = %29
%34 = mul nsw i64 %30, %15
br i1 %22, label %118, label %35
35: ; preds = %33
%36 = insertelement <4 x i32> poison, i32 %31, i64 0
%37 = shufflevector <4 x i32> %36, <4 x i32> poison, <4 x i32> zeroinitializer
%38 = insertelement <4 x i32> poison, i32 %32, i64 0
%39 = shufflevector <4 x i32> %38, <4 x i32> poison, <4 x i32> zeroinitializer
br i1 %25, label %81, label %40
40: ; preds = %35, %40
%41 = phi i64 [ %78, %40 ], [ 0, %35 ]
%42 = phi <4 x i32> [ %76, %40 ], [ %37, %35 ]
%43 = phi <4 x i32> [ %77, %40 ], [ %37, %35 ]
%44 = phi <4 x i32> [ %72, %40 ], [ %39, %35 ]
%45 = phi <4 x i32> [ %73, %40 ], [ %39, %35 ]
%46 = phi i64 [ %79, %40 ], [ 0, %35 ]
%47 = add nsw i64 %41, %34
%48 = getelementptr inbounds i32, i32* %0, i64 %47
%49 = bitcast i32* %48 to <4 x i32>*
%50 = load <4 x i32>, <4 x i32>* %49
%51 = getelementptr inbounds i32, i32* %48, i64 4
%52 = bitcast i32* %51 to <4 x i32>*
%53 = load <4 x i32>, <4 x i32>* %52
%54 = icmp sgt <4 x i32> %50, %44
%55 = icmp sgt <4 x i32> %53, %45
%56 = select <4 x i1> %54, <4 x i32> %50, <4 x i32> %44
%57 = select <4 x i1> %55, <4 x i32> %53, <4 x i32> %45
%58 = icmp slt <4 x i32> %50, %42
%59 = icmp slt <4 x i32> %53, %43
%60 = select <4 x i1> %58, <4 x i32> %50, <4 x i32> %42
%61 = select <4 x i1> %59, <4 x i32> %53, <4 x i32> %43
%62 = or i64 %41, 8
%63 = add nsw i64 %62, %34
%64 = getelementptr inbounds i32, i32* %0, i64 %63
%65 = bitcast i32* %64 to <4 x i32>*
%66 = load <4 x i32>, <4 x i32>* %65
%67 = getelementptr inbounds i32, i32* %64, i64 4
%68 = bitcast i32* %67 to <4 x i32>*
%69 = load <4 x i32>, <4 x i32>* %68
%70 = icmp sgt <4 x i32> %66, %56
%71 = icmp sgt <4 x i32> %69, %57
%72 = select <4 x i1> %70, <4 x i32> %66, <4 x i32> %56
%73 = select <4 x i1> %71, <4 x i32> %69, <4 x i32> %57
%74 = icmp slt <4 x i32> %66, %60
%75 = icmp slt <4 x i32> %69, %61
%76 = select <4 x i1> %74, <4 x i32> %66, <4 x i32> %60
%77 = select <4 x i1> %75, <4 x i32> %69, <4 x i32> %61
%78 = add nuw i64 %41, 16
%79 = add i64 %46, 2
%80 = icmp eq i64 %79, %26
br i1 %80, label %81, label %40
81: ; preds = %40, %35
%82 = phi <4 x i32> [ undef, %35 ], [ %72, %40 ]
%83 = phi <4 x i32> [ undef, %35 ], [ %73, %40 ]
%84 = phi <4 x i32> [ undef, %35 ], [ %76, %40 ]
%85 = phi <4 x i32> [ undef, %35 ], [ %77, %40 ]
%86 = phi i64 [ 0, %35 ], [ %78, %40 ]
%87 = phi <4 x i32> [ %37, %35 ], [ %76, %40 ]
%88 = phi <4 x i32> [ %37, %35 ], [ %77, %40 ]
%89 = phi <4 x i32> [ %39, %35 ], [ %72, %40 ]
%90 = phi <4 x i32> [ %39, %35 ], [ %73, %40 ]
br i1 %27, label %107, label %91
91: ; preds = %81
%92 = add nsw i64 %86, %34
%93 = getelementptr inbounds i32, i32* %0, i64 %92
%94 = bitcast i32* %93 to <4 x i32>*
%95 = load <4 x i32>, <4 x i32>* %94
%96 = getelementptr inbounds i32, i32* %93, i64 4
%97 = bitcast i32* %96 to <4 x i32>*
%98 = load <4 x i32>, <4 x i32>* %97
%99 = icmp sgt <4 x i32> %95, %89
%100 = icmp sgt <4 x i32> %98, %90
%101 = select <4 x i1> %99, <4 x i32> %95, <4 x i32> %89
%102 = select <4 x i1> %100, <4 x i32> %98, <4 x i32> %90
%103 = icmp slt <4 x i32> %95, %87
%104 = icmp slt <4 x i32> %98, %88
%105 = select <4 x i1> %103, <4 x i32> %95, <4 x i32> %87
%106 = select <4 x i1> %104, <4 x i32> %98, <4 x i32> %88
br label %107
107: ; preds = %81, %91
%108 = phi <4 x i32> [ %82, %81 ], [ %101, %91 ]
%109 = phi <4 x i32> [ %83, %81 ], [ %102, %91 ]
%110 = phi <4 x i32> [ %84, %81 ], [ %105, %91 ]
%111 = phi <4 x i32> [ %85, %81 ], [ %106, %91 ]
%112 = icmp sgt <4 x i32> %108, %109
%113 = select <4 x i1> %112, <4 x i32> %108, <4 x i32> %109
%114 = call i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %113)
%115 = icmp slt <4 x i32> %110, %111
%116 = select <4 x i1> %115, <4 x i32> %110, <4 x i32> %111
%117 = call i32 @llvm.vector.reduce.smin.v4i32(<4 x i32> %116)
br i1 %28, label %135, label %118
118: ; preds = %33, %107
%119 = phi i64 [ 0, %33 ], [ %23, %107 ]
%120 = phi i32 [ %31, %33 ], [ %117, %107 ]
%121 = phi i32 [ %32, %33 ], [ %114, %107 ]
br label %122
122: ; preds = %118, %122
%123 = phi i64 [ %133, %122 ], [ %119, %118 ]
%124 = phi i32 [ %132, %122 ], [ %120, %118 ]
%125 = phi i32 [ %130, %122 ], [ %121, %118 ]
%126 = add nsw i64 %123, %34
%127 = getelementptr inbounds i32, i32* %0, i64 %126
%128 = load i32, i32* %127
%129 = icmp sgt i32 %128, %125
%130 = select i1 %129, i32 %128, i32 %125
%131 = icmp slt i32 %128, %124
%132 = select i1 %131, i32 %128, i32 %124
%133 = add nuw nsw i64 %123, 1
%134 = icmp eq i64 %133, %17
br i1 %134, label %135, label %122
135: ; preds = %122, %107, %29
%136 = phi i32 [ %32, %29 ], [ %114, %107 ], [ %130, %122 ]
%137 = phi i32 [ %31, %29 ], [ %117, %107 ], [ %132, %122 ]
%138 = add nuw nsw i64 %30, 1
%139 = icmp eq i64 %138, %16
br i1 %139, label %140, label %29
140: ; preds = %135
%141 = icmp slt i32 %137, 0
br i1 %141, label %142, label %147
142: ; preds = %140
%143 = load i32, i32* @stderr
%144 = sext i32 %143 to i64
%145 = inttoptr i64 %144 to i32*
%146 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %145, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %147
147: ; preds = %142, %140
%148 = icmp sgt i32 %136, 65535
br i1 %148, label %149, label %154
149: ; preds = %147
%150 = load i32, i32* @stderr
%151 = sext i32 %150 to i64
%152 = inttoptr i64 %151 to i32*
%153 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %152, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %154
154: ; preds = %10, %149, %147
%155 = phi i1 [ true, %149 ], [ true, %147 ], [ false, %10 ]
%156 = phi i32 [ %136, %149 ], [ %136, %147 ], [ 0, %10 ]
%157 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%158 = icmp eq i64 %157, 0
br i1 %158, label %159, label %161
159: ; preds = %154
%160 = load i32*, i32** @stdout
br label %163
161: ; preds = %154
%162 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %163
163: ; preds = %161, %159
%164 = phi i32* [ %160, %159 ], [ %162, %161 ]
%165 = icmp eq i32* %164, null
br i1 %165, label %166, label %168
166: ; preds = %163
%167 = tail call i32 @error(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0))
br label %168
168: ; preds = %166, %163
%169 = tail call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i64 3, i64 1, i32* %164)
%170 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %164, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i32 %1, i32 %2)
%171 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %164, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %156)
br i1 %155, label %172, label %201
172: ; preds = %168
%173 = icmp sgt i32 %1, 0
%174 = sext i32 %1 to i64
%175 = zext i32 %2 to i64
%176 = zext i32 %1 to i64
br label %177
177: ; preds = %172, %197
%178 = phi i64 [ 0, %172 ], [ %199, %197 ]
%179 = phi i32 [ 0, %172 ], [ %198, %197 ]
br i1 %173, label %180, label %197
180: ; preds = %177
%181 = mul nsw i64 %178, %174
br label %182
182: ; preds = %180, %193
%183 = phi i64 [ 0, %180 ], [ %195, %193 ]
%184 = phi i32 [ %179, %180 ], [ %194, %193 ]
%185 = add nsw i64 %183, %181
%186 = getelementptr inbounds i32, i32* %0, i64 %185
%187 = load i32, i32* %186
%188 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %164, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %187)
%189 = add nsw i32 %184, 1
%190 = icmp eq i32 %189, 8
br i1 %190, label %191, label %193
191: ; preds = %182
%192 = tail call i32 @fputc(i32 10, i32* %164)
br label %193
193: ; preds = %182, %191
%194 = phi i32 [ 0, %191 ], [ %189, %182 ]
%195 = add nuw nsw i64 %183, 1
%196 = icmp eq i64 %195, %176
br i1 %196, label %197, label %182
197: ; preds = %193, %177
%198 = phi i32 [ %179, %177 ], [ %194, %193 ]
%199 = add nuw nsw i64 %178, 1
%200 = icmp eq i64 %199, %175
br i1 %200, label %201, label %177
201: ; preds = %197, %168
%202 = load i32*, i32** @stdout
%203 = icmp eq i32* %164, %202
br i1 %203, label %210, label %204
204: ; preds = %201
%205 = tail call i64 @fclose(i32* %164)
%206 = load i64, i64* @EOF
%207 = icmp eq i64 %205, %206
br i1 %207, label %208, label %210
208: ; preds = %204
%209 = tail call i32 @error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0))
br label %210
210: ; preds = %208, %204, %201
ret void
}