#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*/ PPM_scan_ws(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char **);
unsigned char getc(int /*<<< orphan*/ *);
scalar_t__ isdigit(unsigned char);
int /*<<< orphan*/ isspace(unsigned char);
unsigned char **malloc(int);
int ReadPPM6(const char *fname, unsigned char (**data)[3], int *w, int *h) {
  FILE *fp = fopen(fname, "rb");
  unsigned char buf[6] = {0};
  unsigned char c;
  int maxval;
  int i;
  unsigned char(*rgb)[3];
  *data = NULL;
  if (!fp)
    goto close_fail;
  fread(buf, 1, 2, fp);
  if (buf[0] != 'P' || buf[1] != '6')
    goto close_fail;
  *w = *h = 0;
  maxval = 0;
  c = getc(fp);
  PPM_scan_ws(&c, fp);
  while (isdigit(c)) {
    *w = 10 * (*w) + c - '0';
    c = getc(fp);
  }
  PPM_scan_ws(&c, fp);
  while (isdigit(c)) {
    *h = 10 * (*h) + c - '0';
    c = getc(fp);
  }
  PPM_scan_ws(&c, fp);
  while (isdigit(c)) {
    maxval = 10 * maxval + c - '0';
    c = getc(fp);
  }
  if (!isspace(c) || maxval > 65536 || maxval <= 0)
    goto close_fail;
  if (*w <= 0 || *h <= 0)
    goto close_fail;
  *data = malloc((*w) * (*h) * sizeof **data);
  if (*data == NULL)
    goto nospace_fail;
  for (i = 0, rgb = *data; i < (*w) * (*h); ++i, ++rgb) {
    if (maxval < 256) {
      if (fread(buf, 1, 3, fp) != 3)
        goto corrupt_fail;
      (*rgb)[0] = (buf[0] + 1) * 256 / (maxval + 1) - 1;
      (*rgb)[1] = (buf[1] + 1) * 256 / (maxval + 1) - 1;
      (*rgb)[2] = (buf[2] + 1) * 256 / (maxval + 1) - 1;
    } else {
      if (fread(buf, 1, 6, fp) != 6)
        goto corrupt_fail;
      (*rgb)[0] = ((buf[0] << 8 | buf[1]) + 1) * 256 / (maxval + 1) - 1;
      (*rgb)[1] = ((buf[2] << 8 | buf[3]) + 1) * 256 / (maxval + 1) - 1;
      (*rgb)[2] = ((buf[4] << 8 | buf[5]) + 1) * 256 / (maxval + 1) - 1;
    }
  }
  fclose(fp);
  return 0;
close_fail:
  if (*data)
    free(*data);
  *data = NULL;
  if (fp)
    fclose(fp);
  return -1;
corrupt_fail:
  fclose(fp);
  return -2;
nospace_fail:
  fclose(fp);
  return -3;
}


x86 assembly (clang, -O0):
<ReadPPM6>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
lea    -0x36(%rbp),%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1070 <memset@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x30(%rbp)
jne    11f7 <ReadPPM6+0x57>
jmp    1534 <ReadPPM6+0x394>
lea    -0x36(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1050 <fread@plt>
movzbl -0x36(%rbp),%eax
cmp    $0x50,%eax
jne    1228 <ReadPPM6+0x88>
movzbl -0x35(%rbp),%eax
cmp    $0x36,%eax
je     122d <ReadPPM6+0x8d>
jmp    1534 <ReadPPM6+0x394>
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   10c0 <getc@plt>
mov    %al,-0x37(%rbp)
mov    -0x30(%rbp),%rsi
lea    -0x37(%rbp),%rdi
call   10b0 <PPM_scan_ws@plt>
movzbl -0x37(%rbp),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     129b <ReadPPM6+0xfb>
mov    -0x20(%rbp),%rax
imul   $0xa,(%rax),%ecx
movzbl -0x37(%rbp),%eax
add    %eax,%ecx
sub    $0x30,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rdi
call   10c0 <getc@plt>
mov    %al,-0x37(%rbp)
jmp    1261 <ReadPPM6+0xc1>
mov    -0x30(%rbp),%rsi
lea    -0x37(%rbp),%rdi
call   10b0 <PPM_scan_ws@plt>
movzbl -0x37(%rbp),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     12e2 <ReadPPM6+0x142>
mov    -0x28(%rbp),%rax
imul   $0xa,(%rax),%ecx
movzbl -0x37(%rbp),%eax
add    %eax,%ecx
sub    $0x30,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rdi
call   10c0 <getc@plt>
mov    %al,-0x37(%rbp)
jmp    12a8 <ReadPPM6+0x108>
mov    -0x30(%rbp),%rsi
lea    -0x37(%rbp),%rdi
call   10b0 <PPM_scan_ws@plt>
movzbl -0x37(%rbp),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1323 <ReadPPM6+0x183>
imul   $0xa,-0x3c(%rbp),%eax
movzbl -0x37(%rbp),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   10c0 <getc@plt>
mov    %al,-0x37(%rbp)
jmp    12ef <ReadPPM6+0x14f>
movzbl -0x37(%rbp),%edi
call   1080 <isspace@plt>
cmp    $0x0,%eax
je     134c <ReadPPM6+0x1ac>
cmpl   $0x10000,-0x3c(%rbp)
jg     134c <ReadPPM6+0x1ac>
cmpl   $0x0,-0x3c(%rbp)
jg     1351 <ReadPPM6+0x1b1>
jmp    1534 <ReadPPM6+0x394>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jle    136b <ReadPPM6+0x1cb>
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1370 <ReadPPM6+0x1d0>
jmp    1534 <ReadPPM6+0x394>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    -0x28(%rbp),%rcx
imul   (%rcx),%eax
cltq
imul   $0x3,%rax,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    13a7 <ReadPPM6+0x207>
jmp    158e <ReadPPM6+0x3ee>
movl   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
mov    -0x28(%rbp),%rdx
imul   (%rdx),%ecx
cmp    %ecx,%eax
jge    151f <ReadPPM6+0x37f>
cmpl   $0x100,-0x3c(%rbp)
jge    1464 <ReadPPM6+0x2c4>
lea    -0x36(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1050 <fread@plt>
cmp    $0x3,%eax
je     1403 <ReadPPM6+0x263>
jmp    1579 <ReadPPM6+0x3d9>
movzbl -0x36(%rbp),%eax
add    $0x1,%eax
shl    $0x8,%eax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %al,%cl
mov    -0x48(%rbp),%rax
mov    %cl,(%rax)
movzbl -0x35(%rbp),%eax
add    $0x1,%eax
shl    $0x8,%eax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %al,%cl
mov    -0x48(%rbp),%rax
mov    %cl,0x1(%rax)
movzbl -0x34(%rbp),%eax
add    $0x1,%eax
shl    $0x8,%eax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %al,%cl
mov    -0x48(%rbp),%rax
mov    %cl,0x2(%rax)
jmp    1500 <ReadPPM6+0x360>
lea    -0x36(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x6,%edx
call   1050 <fread@plt>
cmp    $0x6,%eax
je     1489 <ReadPPM6+0x2e9>
jmp    1579 <ReadPPM6+0x3d9>
movzbl -0x36(%rbp),%eax
shl    $0x8,%eax
movzbl -0x35(%rbp),%ecx
or     %ecx,%eax
add    $0x1,%eax
shl    $0x8,%eax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %al,%cl
mov    -0x48(%rbp),%rax
mov    %cl,(%rax)
movzbl -0x34(%rbp),%eax
shl    $0x8,%eax
movzbl -0x33(%rbp),%ecx
or     %ecx,%eax
add    $0x1,%eax
shl    $0x8,%eax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %al,%cl
mov    -0x48(%rbp),%rax
mov    %cl,0x1(%rax)
movzbl -0x32(%rbp),%eax
shl    $0x8,%eax
movzbl -0x31(%rbp),%ecx
or     %ecx,%eax
add    $0x1,%eax
shl    $0x8,%eax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %al,%cl
mov    -0x48(%rbp),%rax
mov    %cl,0x2(%rax)
jmp    1505 <ReadPPM6+0x365>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
mov    -0x48(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x48(%rbp)
jmp    13b9 <ReadPPM6+0x219>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    159e <ReadPPM6+0x3fe>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     154e <ReadPPM6+0x3ae>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x30(%rbp)
je     156d <ReadPPM6+0x3cd>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    159e <ReadPPM6+0x3fe>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    159e <ReadPPM6+0x3fe>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xfffffffd,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadPPM6>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbp
lea    0xe52(%rip),%rsi
call   1090 <fopen@plt>
movw   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
movq   $0x0,0x0(%rbp)
test   %rax,%rax
je     125f <ReadPPM6+0xcf>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
cmpb   $0x50,0x8(%rsp)
jne    1360 <ReadPPM6+0x1d0>
cmpb   $0x36,0x9(%rsp)
jne    1360 <ReadPPM6+0x1d0>
movl   $0x0,(%r14)
movl   $0x0,(%r15)
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    %al,0x7(%rsp)
lea    0x7(%rsp),%rdi
mov    %rbx,%rsi
call   10a0 <PPM_scan_ws@plt>
movzbl 0x7(%rsp),%edi
nop
call   1040 <isdigit@plt>
test   %rax,%rax
je     1269 <ReadPPM6+0xd9>
mov    (%r15),%eax
lea    (%rax,%rax,4),%eax
movzbl 0x7(%rsp),%ecx
lea    (%rcx,%rax,2),%eax
add    $0xffffffd0,%eax
mov    %eax,(%r15)
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    %al,0x7(%rsp)
movzbl %al,%edi
jmp    1230 <ReadPPM6+0xa0>
mov    $0xffffffff,%ebp
jmp    1383 <ReadPPM6+0x1f3>
lea    0x7(%rsp),%rdi
mov    %rbx,%rsi
call   10a0 <PPM_scan_ws@plt>
movzbl 0x7(%rsp),%edi
nopl   0x0(%rax,%rax,1)
call   1040 <isdigit@plt>
test   %rax,%rax
je     12af <ReadPPM6+0x11f>
mov    (%r14),%eax
lea    (%rax,%rax,4),%eax
movzbl 0x7(%rsp),%ecx
lea    (%rcx,%rax,2),%eax
add    $0xffffffd0,%eax
mov    %eax,(%r14)
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    %al,0x7(%rsp)
movzbl %al,%edi
jmp    1280 <ReadPPM6+0xf0>
lea    0x7(%rsp),%rdi
mov    %rbx,%rsi
call   10a0 <PPM_scan_ws@plt>
movzbl 0x7(%rsp),%edi
call   1040 <isdigit@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     12fa <ReadPPM6+0x16a>
xchg   %ax,%ax
lea    (%r12,%r12,4),%eax
movzbl 0x7(%rsp),%ecx
lea    (%rcx,%rax,2),%r12d
add    $0xffffffd0,%r12d
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    %al,0x7(%rsp)
movzbl %al,%edi
call   1040 <isdigit@plt>
test   %rax,%rax
jne    12d0 <ReadPPM6+0x140>
movzbl 0x7(%rsp),%edi
call   1070 <isspace@plt>
test   %eax,%eax
je     1360 <ReadPPM6+0x1d0>
cmp    $0x10000,%r12d
jg     1360 <ReadPPM6+0x1d0>
test   %r12d,%r12d
jle    1360 <ReadPPM6+0x1d0>
mov    (%r15),%ecx
test   %ecx,%ecx
jle    1360 <ReadPPM6+0x1d0>
mov    (%r14),%eax
test   %eax,%eax
jle    1360 <ReadPPM6+0x1d0>
imul   %eax,%ecx
mov    %rcx,0x10(%rsp)
lea    (%rcx,%rcx,2),%edi
call   1080 <malloc@plt>
mov    %rax,0x0(%rbp)
test   %rax,%rax
je     14a7 <ReadPPM6+0x317>
cmpl   $0x0,0x10(%rsp)
jle    14b1 <ReadPPM6+0x321>
mov    %rax,%r13
lea    0x1(%r12),%eax
mov    %eax,0x10(%rsp)
add    $0x2,%r13
xor    %ecx,%ecx
jmp    13bc <ReadPPM6+0x22c>
mov    0x0(%rbp),%rdi
test   %rdi,%rdi
je     136e <ReadPPM6+0x1de>
call   1030 <free@plt>
movq   $0x0,0x0(%rbp)
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0xff,%al
mov    %al,0x0(%r13)
mov    (%r14),%eax
imul   (%r15),%eax
mov    %ebp,%ecx
add    $0x1,%ecx
add    $0x3,%r13
xor    %ebp,%ebp
cmp    %eax,%ecx
jge    137b <ReadPPM6+0x1eb>
mov    %ecx,%ebp
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
cmp    $0xff,%r12d
ja     142f <ReadPPM6+0x29f>
mov    $0x3,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    $0x3,%eax
jne    14b8 <ReadPPM6+0x328>
movzbl 0x8(%rsp),%eax
shl    $0x8,%eax
add    $0x100,%eax
xor    %edx,%edx
mov    0x10(%rsp),%ecx
div    %ecx
add    $0xff,%al
mov    %al,-0x2(%r13)
movzbl 0x9(%rsp),%eax
shl    $0x8,%eax
add    $0x100,%eax
xor    %edx,%edx
div    %ecx
add    $0xff,%al
mov    %al,-0x1(%r13)
movzbl 0xa(%rsp),%eax
shl    $0x8,%eax
add    $0x100,%eax
xor    %edx,%edx
div    %ecx
jmp    13a0 <ReadPPM6+0x210>
mov    $0x6,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    $0x6,%eax
jne    14b8 <ReadPPM6+0x328>
movzbl 0x8(%rsp),%eax
movzbl 0x9(%rsp),%ecx
shl    $0x10,%eax
shl    $0x8,%ecx
add    %ecx,%eax
add    $0x100,%eax
xor    %edx,%edx
mov    0x10(%rsp),%esi
idiv   %esi
add    $0xff,%al
mov    %al,-0x2(%r13)
movzbl 0xa(%rsp),%eax
movzbl 0xb(%rsp),%ecx
shl    $0x10,%eax
shl    $0x8,%ecx
add    %ecx,%eax
add    $0x100,%eax
xor    %edx,%edx
idiv   %esi
add    $0xff,%al
mov    %al,-0x1(%r13)
movzbl 0xc(%rsp),%eax
movzbl 0xd(%rsp),%ecx
shl    $0x10,%eax
shl    $0x8,%ecx
add    %ecx,%eax
add    $0x100,%eax
xor    %edx,%edx
idiv   %esi
jmp    13a0 <ReadPPM6+0x210>
mov    $0xfffffffd,%ebp
jmp    137b <ReadPPM6+0x1eb>
xor    %ebp,%ebp
jmp    137b <ReadPPM6+0x1eb>
mov    $0xfffffffe,%ebp
jmp    137b <ReadPPM6+0x1eb>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @ReadPPM6(i8* %0, [3 x i8]** %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [3 x i8]**
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [6 x i8]
%12 = alloca i8
%13 = alloca i32
%14 = alloca i32
%15 = alloca [3 x i8]*
store i8* %0, i8** %6
store [3 x i8]** %1, [3 x i8]*** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%16 = load i8*, i8** %6
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %10
%18 = bitcast [6 x i8]* %11 to i8*
%19 = load [3 x i8]**, [3 x i8]*** %7
store [3 x i8]* null, [3 x i8]** %19
%20 = load i32*, i32** %10
%21 = icmp ne i32* %20, null
br i1 %21, label %23, label %22
22: ; preds = %4
br label %253
23: ; preds = %4
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%25 = load i32*, i32** %10
%26 = call i32 @fread(i8* %24, i32 1, i32 2, i32* %25)
%27 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = icmp ne i32 %29, 80
br i1 %30, label %36, label %31
31: ; preds = %23
%32 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 1
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = icmp ne i32 %34, 54
br i1 %35, label %36, label %37
36: ; preds = %31, %23
br label %253
37: ; preds = %31
%38 = load i32*, i32** %9
store i32 0, i32* %38
%39 = load i32*, i32** %8
store i32 0, i32* %39
store i32 0, i32* %13
%40 = load i32*, i32** %10
%41 = call zeroext i8 @getc(i32* %40)
store i8 %41, i8* %12
%42 = load i32*, i32** %10
%43 = call i32 @PPM_scan_ws(i8* %12, i32* %42)
br label %44
44: ; preds = %48, %37
%45 = load i8, i8* %12
%46 = call i64 @isdigit(i8 zeroext %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %59
48: ; preds = %44
%49 = load i32*, i32** %8
%50 = load i32, i32* %49
%51 = mul nsw i32 10, %50
%52 = load i8, i8* %12
%53 = zext i8 %52 to i32
%54 = add nsw i32 %51, %53
%55 = sub nsw i32 %54, 48
%56 = load i32*, i32** %8
store i32 %55, i32* %56
%57 = load i32*, i32** %10
%58 = call zeroext i8 @getc(i32* %57)
store i8 %58, i8* %12
br label %44
59: ; preds = %44
%60 = load i32*, i32** %10
%61 = call i32 @PPM_scan_ws(i8* %12, i32* %60)
br label %62
62: ; preds = %66, %59
%63 = load i8, i8* %12
%64 = call i64 @isdigit(i8 zeroext %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %77
66: ; preds = %62
%67 = load i32*, i32** %9
%68 = load i32, i32* %67
%69 = mul nsw i32 10, %68
%70 = load i8, i8* %12
%71 = zext i8 %70 to i32
%72 = add nsw i32 %69, %71
%73 = sub nsw i32 %72, 48
%74 = load i32*, i32** %9
store i32 %73, i32* %74
%75 = load i32*, i32** %10
%76 = call zeroext i8 @getc(i32* %75)
store i8 %76, i8* %12
br label %62
77: ; preds = %62
%78 = load i32*, i32** %10
%79 = call i32 @PPM_scan_ws(i8* %12, i32* %78)
br label %80
80: ; preds = %84, %77
%81 = load i8, i8* %12
%82 = call i64 @isdigit(i8 zeroext %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %93
84: ; preds = %80
%85 = load i32, i32* %13
%86 = mul nsw i32 10, %85
%87 = load i8, i8* %12
%88 = zext i8 %87 to i32
%89 = add nsw i32 %86, %88
%90 = sub nsw i32 %89, 48
store i32 %90, i32* %13
%91 = load i32*, i32** %10
%92 = call zeroext i8 @getc(i32* %91)
store i8 %92, i8* %12
br label %80
93: ; preds = %80
%94 = load i8, i8* %12
%95 = call i32 @isspace(i8 zeroext %94)
%96 = icmp ne i32 %95, 0
br i1 %96, label %97, label %103
97: ; preds = %93
%98 = load i32, i32* %13
%99 = icmp sgt i32 %98, 65536
br i1 %99, label %103, label %100
100: ; preds = %97
%101 = load i32, i32* %13
%102 = icmp sle i32 %101, 0
br i1 %102, label %103, label %104
103: ; preds = %100, %97, %93
br label %253
104: ; preds = %100
%105 = load i32*, i32** %8
%106 = load i32, i32* %105
%107 = icmp sle i32 %106, 0
br i1 %107, label %112, label %108
108: ; preds = %104
%109 = load i32*, i32** %9
%110 = load i32, i32* %109
%111 = icmp sle i32 %110, 0
br i1 %111, label %112, label %113
112: ; preds = %108, %104
br label %253
113: ; preds = %108
%114 = load i32*, i32** %8
%115 = load i32, i32* %114
%116 = load i32*, i32** %9
%117 = load i32, i32* %116
%118 = mul nsw i32 %115, %117
%119 = sext i32 %118 to i64
%120 = mul i64 %119, 3
%121 = trunc i64 %120 to i32
%122 = call i8** @malloc(i32 %121)
%123 = bitcast i8** %122 to [3 x i8]*
%124 = load [3 x i8]**, [3 x i8]*** %7
store [3 x i8]* %123, [3 x i8]** %124
%125 = load [3 x i8]**, [3 x i8]*** %7
%126 = load [3 x i8]*, [3 x i8]** %125
%127 = icmp eq [3 x i8]* %126, null
br i1 %127, label %128, label %129
128: ; preds = %113
br label %273
129: ; preds = %113
store i32 0, i32* %14
%130 = load [3 x i8]**, [3 x i8]*** %7
%131 = load [3 x i8]*, [3 x i8]** %130
store [3 x i8]* %131, [3 x i8]** %15
br label %132
132: ; preds = %245, %129
%133 = load i32, i32* %14
%134 = load i32*, i32** %8
%135 = load i32, i32* %134
%136 = load i32*, i32** %9
%137 = load i32, i32* %136
%138 = mul nsw i32 %135, %137
%139 = icmp slt i32 %133, %138
br i1 %139, label %140, label %250
140: ; preds = %132
%141 = load i32, i32* %13
%142 = icmp slt i32 %141, 256
br i1 %142, label %143, label %186
143: ; preds = %140
%144 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%145 = load i32*, i32** %10
%146 = call i32 @fread(i8* %144, i32 1, i32 3, i32* %145)
%147 = icmp ne i32 %146, 3
br i1 %147, label %148, label %149
148: ; preds = %143
br label %270
149: ; preds = %143
%150 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%151 = load i8, i8* %150
%152 = zext i8 %151 to i32
%153 = add nsw i32 %152, 1
%154 = mul nsw i32 %153, 256
%155 = load i32, i32* %13
%156 = add nsw i32 %155, 1
%157 = sdiv i32 %154, %156
%158 = sub nsw i32 %157, 1
%159 = trunc i32 %158 to i8
%160 = load [3 x i8]*, [3 x i8]** %15
%161 = getelementptr inbounds [3 x i8], [3 x i8]* %160, i64 0, i64 0
store i8 %159, i8* %161
%162 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 1
%163 = load i8, i8* %162
%164 = zext i8 %163 to i32
%165 = add nsw i32 %164, 1
%166 = mul nsw i32 %165, 256
%167 = load i32, i32* %13
%168 = add nsw i32 %167, 1
%169 = sdiv i32 %166, %168
%170 = sub nsw i32 %169, 1
%171 = trunc i32 %170 to i8
%172 = load [3 x i8]*, [3 x i8]** %15
%173 = getelementptr inbounds [3 x i8], [3 x i8]* %172, i64 0, i64 1
store i8 %171, i8* %173
%174 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 2
%175 = load i8, i8* %174
%176 = zext i8 %175 to i32
%177 = add nsw i32 %176, 1
%178 = mul nsw i32 %177, 256
%179 = load i32, i32* %13
%180 = add nsw i32 %179, 1
%181 = sdiv i32 %178, %180
%182 = sub nsw i32 %181, 1
%183 = trunc i32 %182 to i8
%184 = load [3 x i8]*, [3 x i8]** %15
%185 = getelementptr inbounds [3 x i8], [3 x i8]* %184, i64 0, i64 2
store i8 %183, i8* %185
br label %244
186: ; preds = %140
%187 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%188 = load i32*, i32** %10
%189 = call i32 @fread(i8* %187, i32 1, i32 6, i32* %188)
%190 = icmp ne i32 %189, 6
br i1 %190, label %191, label %192
191: ; preds = %186
br label %270
192: ; preds = %186
%193 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 0
%194 = load i8, i8* %193
%195 = zext i8 %194 to i32
%196 = shl i32 %195, 8
%197 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 1
%198 = load i8, i8* %197
%199 = zext i8 %198 to i32
%200 = or i32 %196, %199
%201 = add nsw i32 %200, 1
%202 = mul nsw i32 %201, 256
%203 = load i32, i32* %13
%204 = add nsw i32 %203, 1
%205 = sdiv i32 %202, %204
%206 = sub nsw i32 %205, 1
%207 = trunc i32 %206 to i8
%208 = load [3 x i8]*, [3 x i8]** %15
%209 = getelementptr inbounds [3 x i8], [3 x i8]* %208, i64 0, i64 0
store i8 %207, i8* %209
%210 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 2
%211 = load i8, i8* %210
%212 = zext i8 %211 to i32
%213 = shl i32 %212, 8
%214 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 3
%215 = load i8, i8* %214
%216 = zext i8 %215 to i32
%217 = or i32 %213, %216
%218 = add nsw i32 %217, 1
%219 = mul nsw i32 %218, 256
%220 = load i32, i32* %13
%221 = add nsw i32 %220, 1
%222 = sdiv i32 %219, %221
%223 = sub nsw i32 %222, 1
%224 = trunc i32 %223 to i8
%225 = load [3 x i8]*, [3 x i8]** %15
%226 = getelementptr inbounds [3 x i8], [3 x i8]* %225, i64 0, i64 1
store i8 %224, i8* %226
%227 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 4
%228 = load i8, i8* %227
%229 = zext i8 %228 to i32
%230 = shl i32 %229, 8
%231 = getelementptr inbounds [6 x i8], [6 x i8]* %11, i64 0, i64 5
%232 = load i8, i8* %231
%233 = zext i8 %232 to i32
%234 = or i32 %230, %233
%235 = add nsw i32 %234, 1
%236 = mul nsw i32 %235, 256
%237 = load i32, i32* %13
%238 = add nsw i32 %237, 1
%239 = sdiv i32 %236, %238
%240 = sub nsw i32 %239, 1
%241 = trunc i32 %240 to i8
%242 = load [3 x i8]*, [3 x i8]** %15
%243 = getelementptr inbounds [3 x i8], [3 x i8]* %242, i64 0, i64 2
store i8 %241, i8* %243
br label %244
244: ; preds = %192, %149
br label %245
245: ; preds = %244
%246 = load i32, i32* %14
%247 = add nsw i32 %246, 1
store i32 %247, i32* %14
%248 = load [3 x i8]*, [3 x i8]** %15
%249 = getelementptr inbounds [3 x i8], [3 x i8]* %248, i32 1
store [3 x i8]* %249, [3 x i8]** %15
br label %132
250: ; preds = %132
%251 = load i32*, i32** %10
%252 = call i32 @fclose(i32* %251)
store i32 0, i32* %5
br label %276
253: ; preds = %112, %103, %36, %22
%254 = load [3 x i8]**, [3 x i8]*** %7
%255 = load [3 x i8]*, [3 x i8]** %254
%256 = icmp ne [3 x i8]* %255, null
br i1 %256, label %257, label %262
257: ; preds = %253
%258 = load [3 x i8]**, [3 x i8]*** %7
%259 = load [3 x i8]*, [3 x i8]** %258
%260 = bitcast [3 x i8]* %259 to i8**
%261 = call i32 @free(i8** %260)
br label %262
262: ; preds = %257, %253
%263 = load [3 x i8]**, [3 x i8]*** %7
store [3 x i8]* null, [3 x i8]** %263
%264 = load i32*, i32** %10
%265 = icmp ne i32* %264, null
br i1 %265, label %266, label %269
266: ; preds = %262
%267 = load i32*, i32** %10
%268 = call i32 @fclose(i32* %267)
br label %269
269: ; preds = %266, %262
store i32 -1, i32* %5
br label %276
270: ; preds = %191, %148
%271 = load i32*, i32** %10
%272 = call i32 @fclose(i32* %271)
store i32 -2, i32* %5
br label %276
273: ; preds = %128
%274 = load i32*, i32** %10
%275 = call i32 @fclose(i32* %274)
store i32 -3, i32* %5
br label %276
276: ; preds = %273, %270, %269, %250
%277 = load i32, i32* %5
ret i32 %277
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @ReadPPM6(i8* nocapture %0, [3 x i8]** nocapture %1, i32* nocapture %2, i32* nocapture %3) {
%5 = alloca [6 x i8]
%6 = alloca i8
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
store [3 x i8]* null, [3 x i8]** %1
%9 = icmp eq i32* %7, null
br i1 %9, label %182, label %10
10: ; preds = %4
%11 = call i32 @fread(i8* %8, i32 1, i32 2, i32* %7)
%12 = load i8, i8* %8
%13 = icmp ne i8 %12, 80
%14 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 1
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 54
%17 = select i1 %13, i1 true, i1 %16
br i1 %17, label %172, label %18
18: ; preds = %10
store i32 0, i32* %3
store i32 0, i32* %2
%19 = tail call zeroext i8 @getc(i32* %7)
store i8 %19, i8* %6
%20 = call i32 @PPM_scan_ws(i8* %6, i32* %7)
%21 = load i8, i8* %6
%22 = call i64 @isdigit(i8 zeroext %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %34, label %24
24: ; preds = %18, %24
%25 = load i32, i32* %2
%26 = mul nsw i32 %25, 10
%27 = load i8, i8* %6
%28 = zext i8 %27 to i32
%29 = add i32 %26, -48
%30 = add i32 %29, %28
store i32 %30, i32* %2
%31 = call zeroext i8 @getc(i32* %7)
store i8 %31, i8* %6
%32 = call i64 @isdigit(i8 zeroext %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %24
34: ; preds = %24, %18
%35 = call i32 @PPM_scan_ws(i8* %6, i32* %7)
%36 = load i8, i8* %6
%37 = call i64 @isdigit(i8 zeroext %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %49, label %39
39: ; preds = %34, %39
%40 = load i32, i32* %3
%41 = mul nsw i32 %40, 10
%42 = load i8, i8* %6
%43 = zext i8 %42 to i32
%44 = add i32 %41, -48
%45 = add i32 %44, %43
store i32 %45, i32* %3
%46 = call zeroext i8 @getc(i32* %7)
store i8 %46, i8* %6
%47 = call i64 @isdigit(i8 zeroext %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %39
49: ; preds = %39, %34
%50 = call i32 @PPM_scan_ws(i8* %6, i32* %7)
%51 = load i8, i8* %6
%52 = call i64 @isdigit(i8 zeroext %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %64, label %54
54: ; preds = %49, %54
%55 = phi i32 [ %60, %54 ], [ 0, %49 ]
%56 = mul nsw i32 %55, 10
%57 = load i8, i8* %6
%58 = zext i8 %57 to i32
%59 = add i32 %56, -48
%60 = add i32 %59, %58
%61 = call zeroext i8 @getc(i32* %7)
store i8 %61, i8* %6
%62 = call i64 @isdigit(i8 zeroext %61)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %54
64: ; preds = %54, %49
%65 = phi i32 [ 0, %49 ], [ %60, %54 ]
%66 = load i8, i8* %6
%67 = call i32 @isspace(i8 zeroext %66)
%68 = icmp eq i32 %67, 0
%69 = icmp sgt i32 %65, 65536
%70 = select i1 %68, i1 true, i1 %69
%71 = icmp slt i32 %65, 1
%72 = select i1 %70, i1 true, i1 %71
br i1 %72, label %172, label %73
73: ; preds = %64
%74 = load i32, i32* %2
%75 = icmp slt i32 %74, 1
br i1 %75, label %172, label %76
76: ; preds = %73
%77 = load i32, i32* %3
%78 = icmp slt i32 %77, 1
br i1 %78, label %172, label %79
79: ; preds = %76
%80 = mul i32 %74, 3
%81 = mul i32 %80, %77
%82 = call i8** @malloc(i32 %81)
%83 = bitcast [3 x i8]** %1 to i8***
store i8** %82, i8*** %83
%84 = icmp eq i8** %82, null
br i1 %84, label %179, label %85
85: ; preds = %79
%86 = mul nsw i32 %77, %74
%87 = icmp sgt i32 %86, 0
br i1 %87, label %88, label %179
88: ; preds = %85
%89 = bitcast i8** %82 to [3 x i8]*
%90 = icmp ult i32 %65, 256
%91 = add nuw nsw i32 %65, 1
%92 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 2
%93 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 3
%94 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 4
%95 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 5
br label %96
96: ; preds = %88, %161
%97 = phi [3 x i8]* [ %89, %88 ], [ %167, %161 ]
%98 = phi i32 [ 0, %88 ], [ %166, %161 ]
br i1 %90, label %99, label %124
99: ; preds = %96
%100 = call i32 @fread(i8* %8, i32 1, i32 3, i32* %7)
%101 = icmp eq i32 %100, 3
br i1 %101, label %102, label %179
102: ; preds = %99
%103 = load i8, i8* %8
%104 = zext i8 %103 to i32
%105 = shl nuw nsw i32 %104, 8
%106 = add nuw nsw i32 %105, 256
%107 = udiv i32 %106, %91
%108 = trunc i32 %107 to i8
%109 = add i8 %108, -1
%110 = getelementptr inbounds [3 x i8], [3 x i8]* %97, i64 0, i64 0
store i8 %109, i8* %110
%111 = load i8, i8* %14
%112 = zext i8 %111 to i32
%113 = shl nuw nsw i32 %112, 8
%114 = add nuw nsw i32 %113, 256
%115 = udiv i32 %114, %91
%116 = trunc i32 %115 to i8
%117 = add i8 %116, -1
%118 = getelementptr inbounds [3 x i8], [3 x i8]* %97, i64 0, i64 1
store i8 %117, i8* %118
%119 = load i8, i8* %92
%120 = zext i8 %119 to i32
%121 = shl nuw nsw i32 %120, 8
%122 = add nuw nsw i32 %121, 256
%123 = udiv i32 %122, %91
br label %161
124: ; preds = %96
%125 = call i32 @fread(i8* %8, i32 1, i32 6, i32* %7)
%126 = icmp eq i32 %125, 6
br i1 %126, label %127, label %179
127: ; preds = %124
%128 = load i8, i8* %8
%129 = zext i8 %128 to i32
%130 = load i8, i8* %14
%131 = zext i8 %130 to i32
%132 = shl nuw nsw i32 %129, 16
%133 = shl nuw nsw i32 %131, 8
%134 = or i32 %133, %132
%135 = add nuw nsw i32 %134, 256
%136 = sdiv i32 %135, %91
%137 = trunc i32 %136 to i8
%138 = add i8 %137, -1
%139 = getelementptr inbounds [3 x i8], [3 x i8]* %97, i64 0, i64 0
store i8 %138, i8* %139
%140 = load i8, i8* %92
%141 = zext i8 %140 to i32
%142 = load i8, i8* %93
%143 = zext i8 %142 to i32
%144 = shl nuw nsw i32 %141, 16
%145 = shl nuw nsw i32 %143, 8
%146 = or i32 %145, %144
%147 = add nuw nsw i32 %146, 256
%148 = sdiv i32 %147, %91
%149 = trunc i32 %148 to i8
%150 = add i8 %149, -1
%151 = getelementptr inbounds [3 x i8], [3 x i8]* %97, i64 0, i64 1
store i8 %150, i8* %151
%152 = load i8, i8* %94
%153 = zext i8 %152 to i32
%154 = load i8, i8* %95
%155 = zext i8 %154 to i32
%156 = shl nuw nsw i32 %153, 16
%157 = shl nuw nsw i32 %155, 8
%158 = or i32 %157, %156
%159 = add nuw nsw i32 %158, 256
%160 = sdiv i32 %159, %91
br label %161
161: ; preds = %102, %127
%162 = phi i32 [ %123, %102 ], [ %160, %127 ]
%163 = trunc i32 %162 to i8
%164 = add i8 %163, -1
%165 = getelementptr inbounds [3 x i8], [3 x i8]* %97, i64 0, i64 2
store i8 %164, i8* %165
%166 = add nuw nsw i32 %98, 1
%167 = getelementptr inbounds [3 x i8], [3 x i8]* %97, i64 1
%168 = load i32, i32* %2
%169 = load i32, i32* %3
%170 = mul nsw i32 %169, %168
%171 = icmp slt i32 %166, %170
br i1 %171, label %96, label %179
172: ; preds = %73, %76, %64, %10
%173 = load [3 x i8]*, [3 x i8]** %1
%174 = icmp eq [3 x i8]* %173, null
br i1 %174, label %178, label %175
175: ; preds = %172
%176 = bitcast [3 x i8]* %173 to i8**
%177 = call i32 @free(i8** %176)
br label %178
178: ; preds = %172, %175
store [3 x i8]* null, [3 x i8]** %1
br label %179
179: ; preds = %99, %124, %161, %79, %85, %178
%180 = phi i32 [ -1, %178 ], [ 0, %85 ], [ -3, %79 ], [ 0, %161 ], [ -2, %124 ], [ -2, %99 ]
%181 = call i32 @fclose(i32* %7)
br label %182
182: ; preds = %179, %4
%183 = phi i32 [ -1, %4 ], [ %180, %179 ]
ret i32 %183
}