#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 ReadPGM5(const char *fname, unsigned char **data, int *w, int *h) {
  FILE *fp = fopen(fname, "rb");
  unsigned char buf[2] = {0};
  unsigned char c;
  int maxval;
  int i;
  unsigned char *rgb;
  *data = NULL;
  if (!fp)
    goto close_fail;
  fread(buf, 1, 2, fp);
  if (buf[0] != 'P' || buf[1] != '5')
    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, 1, fp) != 1)
        goto corrupt_fail;
      *rgb = (buf[0] + 1) * 256 / (maxval + 1) - 1;
    } else {
      if (fread(buf, 1, 2, fp) != 2)
        goto corrupt_fail;
      *rgb = ((buf[0] << 8 | buf[1]) + 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):
<ReadPGM5>:
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    -0x32(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1070 <memset@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x30(%rbp)
jne    11f7 <ReadPGM5+0x57>
jmp    14a3 <ReadPGM5+0x303>
lea    -0x32(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1050 <fread@plt>
movzbl -0x32(%rbp),%eax
cmp    $0x50,%eax
jne    1228 <ReadPGM5+0x88>
movzbl -0x31(%rbp),%eax
cmp    $0x35,%eax
je     122d <ReadPGM5+0x8d>
jmp    14a3 <ReadPGM5+0x303>
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   10c0 <getc@plt>
mov    %al,-0x33(%rbp)
mov    -0x30(%rbp),%rsi
lea    -0x33(%rbp),%rdi
call   10b0 <PPM_scan_ws@plt>
movzbl -0x33(%rbp),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     129b <ReadPGM5+0xfb>
mov    -0x20(%rbp),%rax
imul   $0xa,(%rax),%ecx
movzbl -0x33(%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,-0x33(%rbp)
jmp    1261 <ReadPGM5+0xc1>
mov    -0x30(%rbp),%rsi
lea    -0x33(%rbp),%rdi
call   10b0 <PPM_scan_ws@plt>
movzbl -0x33(%rbp),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     12e2 <ReadPGM5+0x142>
mov    -0x28(%rbp),%rax
imul   $0xa,(%rax),%ecx
movzbl -0x33(%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,-0x33(%rbp)
jmp    12a8 <ReadPGM5+0x108>
mov    -0x30(%rbp),%rsi
lea    -0x33(%rbp),%rdi
call   10b0 <PPM_scan_ws@plt>
movzbl -0x33(%rbp),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%rax
je     1323 <ReadPGM5+0x183>
imul   $0xa,-0x38(%rbp),%eax
movzbl -0x33(%rbp),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   10c0 <getc@plt>
mov    %al,-0x33(%rbp)
jmp    12ef <ReadPGM5+0x14f>
movzbl -0x33(%rbp),%edi
call   1080 <isspace@plt>
cmp    $0x0,%eax
je     134c <ReadPGM5+0x1ac>
cmpl   $0x10000,-0x38(%rbp)
jg     134c <ReadPGM5+0x1ac>
cmpl   $0x0,-0x38(%rbp)
jg     1351 <ReadPGM5+0x1b1>
jmp    14a3 <ReadPGM5+0x303>
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jle    136b <ReadPGM5+0x1cb>
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1370 <ReadPGM5+0x1d0>
jmp    14a3 <ReadPGM5+0x303>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    -0x28(%rbp),%rcx
imul   (%rcx),%eax
cltq
shl    $0x0,%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 <ReadPGM5+0x207>
jmp    14fd <ReadPGM5+0x35d>
movl   $0x0,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
mov    -0x28(%rbp),%rdx
imul   (%rdx),%ecx
cmp    %ecx,%eax
jge    148e <ReadPGM5+0x2ee>
cmpl   $0x100,-0x38(%rbp)
jge    1423 <ReadPGM5+0x283>
lea    -0x32(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1050 <fread@plt>
cmp    $0x1,%eax
je     1400 <ReadPGM5+0x260>
jmp    14e8 <ReadPGM5+0x348>
movzbl -0x32(%rbp),%eax
add    $0x1,%eax
shl    $0x8,%eax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %al,%cl
mov    -0x48(%rbp),%rax
mov    %cl,(%rax)
jmp    146f <ReadPGM5+0x2cf>
lea    -0x32(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2,%edx
call   1050 <fread@plt>
cmp    $0x2,%eax
je     1448 <ReadPGM5+0x2a8>
jmp    14e8 <ReadPGM5+0x348>
movzbl -0x32(%rbp),%eax
shl    $0x8,%eax
movzbl -0x31(%rbp),%ecx
or     %ecx,%eax
add    $0x1,%eax
shl    $0x8,%eax
mov    -0x38(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %al,%cl
mov    -0x48(%rbp),%rax
mov    %cl,(%rax)
jmp    1474 <ReadPGM5+0x2d4>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    13b9 <ReadPGM5+0x219>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    150d <ReadPGM5+0x36d>
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     14bd <ReadPGM5+0x31d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x30(%rbp)
je     14dc <ReadPGM5+0x33c>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    150d <ReadPGM5+0x36d>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    150d <ReadPGM5+0x36d>
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):
<ReadPGM5>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
lea    0xe52(%rip),%rsi
call   1090 <fopen@plt>
movw   $0x0,0xa(%rsp)
movq   $0x0,(%r12)
test   %rax,%rax
je     125f <ReadPGM5+0xcf>
mov    %rax,%rbx
lea    0xa(%rsp),%rdi
mov    $0x1,%esi
mov    $0x2,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
cmpb   $0x50,0xa(%rsp)
jne    1358 <ReadPGM5+0x1c8>
cmpb   $0x35,0xb(%rsp)
jne    1358 <ReadPGM5+0x1c8>
movl   $0x0,(%r14)
movl   $0x0,(%r15)
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    %al,0x9(%rsp)
lea    0x9(%rsp),%rdi
mov    %rbx,%rsi
call   10a0 <PPM_scan_ws@plt>
movzbl 0x9(%rsp),%edi
nopw   0x0(%rax,%rax,1)
call   1040 <isdigit@plt>
test   %rax,%rax
je     1269 <ReadPGM5+0xd9>
mov    (%r15),%eax
lea    (%rax,%rax,4),%eax
movzbl 0x9(%rsp),%ecx
lea    (%rcx,%rax,2),%eax
add    $0xffffffd0,%eax
mov    %eax,(%r15)
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    %al,0x9(%rsp)
movzbl %al,%edi
jmp    1230 <ReadPGM5+0xa0>
mov    $0xffffffff,%ebp
jmp    137b <ReadPGM5+0x1eb>
lea    0x9(%rsp),%rdi
mov    %rbx,%rsi
call   10a0 <PPM_scan_ws@plt>
movzbl 0x9(%rsp),%edi
nopl   0x0(%rax,%rax,1)
call   1040 <isdigit@plt>
test   %rax,%rax
je     12af <ReadPGM5+0x11f>
mov    (%r14),%eax
lea    (%rax,%rax,4),%eax
movzbl 0x9(%rsp),%ecx
lea    (%rcx,%rax,2),%eax
add    $0xffffffd0,%eax
mov    %eax,(%r14)
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    %al,0x9(%rsp)
movzbl %al,%edi
jmp    1280 <ReadPGM5+0xf0>
lea    0x9(%rsp),%rdi
mov    %rbx,%rsi
call   10a0 <PPM_scan_ws@plt>
movzbl 0x9(%rsp),%edi
call   1040 <isdigit@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     12fb <ReadPGM5+0x16b>
xchg   %ax,%ax
lea    0x0(%r13,%r13,4),%eax
movzbl 0x9(%rsp),%ecx
lea    (%rcx,%rax,2),%r13d
add    $0xffffffd0,%r13d
mov    %rbx,%rdi
call   10b0 <getc@plt>
mov    %al,0x9(%rsp)
movzbl %al,%edi
call   1040 <isdigit@plt>
test   %rax,%rax
jne    12d0 <ReadPGM5+0x140>
movzbl 0x9(%rsp),%edi
call   1070 <isspace@plt>
test   %eax,%eax
je     1358 <ReadPGM5+0x1c8>
cmp    $0x10000,%r13d
jg     1358 <ReadPGM5+0x1c8>
test   %r13d,%r13d
jle    1358 <ReadPGM5+0x1c8>
mov    (%r15),%eax
test   %eax,%eax
jle    1358 <ReadPGM5+0x1c8>
mov    (%r14),%ebp
test   %ebp,%ebp
jle    1358 <ReadPGM5+0x1c8>
imul   %eax,%ebp
mov    %ebp,%edi
call   1080 <malloc@plt>
mov    %rax,(%r12)
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     140b <ReadPGM5+0x27b>
test   %ebp,%ebp
jle    1415 <ReadPGM5+0x285>
lea    0x1(%r13),%eax
mov    %eax,0xc(%rsp)
xor    %r12d,%r12d
xor    %ebp,%ebp
jmp    13b6 <ReadPGM5+0x226>
mov    (%r12),%rdi
test   %rdi,%rdi
je     1366 <ReadPGM5+0x1d6>
call   1030 <free@plt>
movq   $0x0,(%r12)
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
nopl   0x0(%rax)
add    $0x100,%eax
xor    %edx,%edx
idivl  0xc(%rsp)
add    $0xff,%al
mov    0x10(%rsp),%rcx
mov    %al,(%rcx,%r12,1)
mov    (%r14),%eax
imul   (%r15),%eax
add    $0x1,%r12
cmp    %eax,%r12d
jge    1373 <ReadPGM5+0x1e3>
lea    0xa(%rsp),%rdi
mov    $0x1,%esi
cmp    $0xff,%r13d
ja     13e5 <ReadPGM5+0x255>
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    $0x1,%eax
jne    141c <ReadPGM5+0x28c>
movzbl 0xa(%rsp),%eax
shl    $0x8,%eax
jmp    1390 <ReadPGM5+0x200>
mov    $0x2,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    $0x2,%eax
jne    141c <ReadPGM5+0x28c>
movzbl 0xa(%rsp),%ecx
movzbl 0xb(%rsp),%eax
shl    $0x10,%ecx
shl    $0x8,%eax
or     %ecx,%eax
jmp    1390 <ReadPGM5+0x200>
mov    $0xfffffffd,%ebp
jmp    1373 <ReadPGM5+0x1e3>
xor    %ebp,%ebp
jmp    1373 <ReadPGM5+0x1e3>
mov    $0xfffffffe,%ebp
jmp    1373 <ReadPGM5+0x1e3>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @ReadPGM5(i8* %0, i8** %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca [2 x i8]
%12 = alloca i8
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
store i8* %0, i8** %6
store i8** %1, 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 [2 x i8]* %11 to i8*
%19 = load i8**, i8*** %7
store i8* null, 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 %192
23: ; preds = %4
%24 = getelementptr inbounds [2 x i8], [2 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 [2 x i8], [2 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 [2 x i8], [2 x i8]* %11, i64 0, i64 1
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = icmp ne i32 %34, 53
br i1 %35, label %36, label %37
36: ; preds = %31, %23
br label %192
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 %192
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 %192
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, 1
%121 = trunc i64 %120 to i32
%122 = call i8* @malloc(i32 %121)
%123 = load i8**, i8*** %7
store i8* %122, i8** %123
%124 = load i8**, i8*** %7
%125 = load i8*, i8** %124
%126 = icmp eq i8* %125, null
br i1 %126, label %127, label %128
127: ; preds = %113
br label %211
128: ; preds = %113
store i32 0, i32* %14
%129 = load i8**, i8*** %7
%130 = load i8*, i8** %129
store i8* %130, i8** %15
br label %131
131: ; preds = %184, %128
%132 = load i32, i32* %14
%133 = load i32*, i32** %8
%134 = load i32, i32* %133
%135 = load i32*, i32** %9
%136 = load i32, i32* %135
%137 = mul nsw i32 %134, %136
%138 = icmp slt i32 %132, %137
br i1 %138, label %139, label %189
139: ; preds = %131
%140 = load i32, i32* %13
%141 = icmp slt i32 %140, 256
br i1 %141, label %142, label %160
142: ; preds = %139
%143 = getelementptr inbounds [2 x i8], [2 x i8]* %11, i64 0, i64 0
%144 = load i32*, i32** %10
%145 = call i32 @fread(i8* %143, i32 1, i32 1, i32* %144)
%146 = icmp ne i32 %145, 1
br i1 %146, label %147, label %148
147: ; preds = %142
br label %208
148: ; preds = %142
%149 = getelementptr inbounds [2 x i8], [2 x i8]* %11, i64 0, i64 0
%150 = load i8, i8* %149
%151 = zext i8 %150 to i32
%152 = add nsw i32 %151, 1
%153 = mul nsw i32 %152, 256
%154 = load i32, i32* %13
%155 = add nsw i32 %154, 1
%156 = sdiv i32 %153, %155
%157 = sub nsw i32 %156, 1
%158 = trunc i32 %157 to i8
%159 = load i8*, i8** %15
store i8 %158, i8* %159
br label %183
160: ; preds = %139
%161 = getelementptr inbounds [2 x i8], [2 x i8]* %11, i64 0, i64 0
%162 = load i32*, i32** %10
%163 = call i32 @fread(i8* %161, i32 1, i32 2, i32* %162)
%164 = icmp ne i32 %163, 2
br i1 %164, label %165, label %166
165: ; preds = %160
br label %208
166: ; preds = %160
%167 = getelementptr inbounds [2 x i8], [2 x i8]* %11, i64 0, i64 0
%168 = load i8, i8* %167
%169 = zext i8 %168 to i32
%170 = shl i32 %169, 8
%171 = getelementptr inbounds [2 x i8], [2 x i8]* %11, i64 0, i64 1
%172 = load i8, i8* %171
%173 = zext i8 %172 to i32
%174 = or i32 %170, %173
%175 = add nsw i32 %174, 1
%176 = mul nsw i32 %175, 256
%177 = load i32, i32* %13
%178 = add nsw i32 %177, 1
%179 = sdiv i32 %176, %178
%180 = sub nsw i32 %179, 1
%181 = trunc i32 %180 to i8
%182 = load i8*, i8** %15
store i8 %181, i8* %182
br label %183
183: ; preds = %166, %148
br label %184
184: ; preds = %183
%185 = load i32, i32* %14
%186 = add nsw i32 %185, 1
store i32 %186, i32* %14
%187 = load i8*, i8** %15
%188 = getelementptr inbounds i8, i8* %187, i32 1
store i8* %188, i8** %15
br label %131
189: ; preds = %131
%190 = load i32*, i32** %10
%191 = call i32 @fclose(i32* %190)
store i32 0, i32* %5
br label %214
192: ; preds = %112, %103, %36, %22
%193 = load i8**, i8*** %7
%194 = load i8*, i8** %193
%195 = icmp ne i8* %194, null
br i1 %195, label %196, label %200
196: ; preds = %192
%197 = load i8**, i8*** %7
%198 = load i8*, i8** %197
%199 = call i32 @free(i8* %198)
br label %200
200: ; preds = %196, %192
%201 = load i8**, i8*** %7
store i8* null, i8** %201
%202 = load i32*, i32** %10
%203 = icmp ne i32* %202, null
br i1 %203, label %204, label %207
204: ; preds = %200
%205 = load i32*, i32** %10
%206 = call i32 @fclose(i32* %205)
br label %207
207: ; preds = %204, %200
store i32 -1, i32* %5
br label %214
208: ; preds = %165, %147
%209 = load i32*, i32** %10
%210 = call i32 @fclose(i32* %209)
store i32 -2, i32* %5
br label %214
211: ; preds = %127
%212 = load i32*, i32** %10
%213 = call i32 @fclose(i32* %212)
store i32 -3, i32* %5
br label %214
214: ; preds = %211, %208, %207, %189
%215 = load i32, i32* %5
ret i32 %215
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @ReadPGM5(i8* nocapture %0, i8** nocapture %1, i32* nocapture %2, i32* nocapture %3) {
%5 = alloca i16
%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 = bitcast i16* %5 to i8*
store i16 0, i16* %5
store i8* null, i8** %1
%9 = icmp eq i32* %7, null
br i1 %9, label %131, label %10
10: ; preds = %4
%11 = bitcast i16* %5 to [2 x i8]*
%12 = call i32 @fread(i8* %8, i32 1, i32 2, i32* %7)
%13 = load i8, i8* %8
%14 = icmp ne i8 %13, 80
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %11, i64 0, i64 1
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 53
%18 = select i1 %14, i1 true, i1 %17
br i1 %18, label %122, label %19
19: ; preds = %10
store i32 0, i32* %3
store i32 0, i32* %2
%20 = tail call zeroext i8 @getc(i32* %7)
store i8 %20, i8* %6
%21 = call i32 @PPM_scan_ws(i8* %6, i32* %7)
%22 = load i8, i8* %6
%23 = call i64 @isdigit(i8 zeroext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %35, label %25
25: ; preds = %19, %25
%26 = load i32, i32* %2
%27 = mul nsw i32 %26, 10
%28 = load i8, i8* %6
%29 = zext i8 %28 to i32
%30 = add i32 %27, -48
%31 = add i32 %30, %29
store i32 %31, i32* %2
%32 = call zeroext i8 @getc(i32* %7)
store i8 %32, i8* %6
%33 = call i64 @isdigit(i8 zeroext %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %25
35: ; preds = %25, %19
%36 = call i32 @PPM_scan_ws(i8* %6, i32* %7)
%37 = load i8, i8* %6
%38 = call i64 @isdigit(i8 zeroext %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %50, label %40
40: ; preds = %35, %40
%41 = load i32, i32* %3
%42 = mul nsw i32 %41, 10
%43 = load i8, i8* %6
%44 = zext i8 %43 to i32
%45 = add i32 %42, -48
%46 = add i32 %45, %44
store i32 %46, i32* %3
%47 = call zeroext i8 @getc(i32* %7)
store i8 %47, i8* %6
%48 = call i64 @isdigit(i8 zeroext %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %40
50: ; preds = %40, %35
%51 = call i32 @PPM_scan_ws(i8* %6, i32* %7)
%52 = load i8, i8* %6
%53 = call i64 @isdigit(i8 zeroext %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %65, label %55
55: ; preds = %50, %55
%56 = phi i32 [ %61, %55 ], [ 0, %50 ]
%57 = mul nsw i32 %56, 10
%58 = load i8, i8* %6
%59 = zext i8 %58 to i32
%60 = add i32 %57, -48
%61 = add i32 %60, %59
%62 = call zeroext i8 @getc(i32* %7)
store i8 %62, i8* %6
%63 = call i64 @isdigit(i8 zeroext %62)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %55
65: ; preds = %55, %50
%66 = phi i32 [ 0, %50 ], [ %61, %55 ]
%67 = load i8, i8* %6
%68 = call i32 @isspace(i8 zeroext %67)
%69 = icmp eq i32 %68, 0
%70 = icmp sgt i32 %66, 65536
%71 = select i1 %69, i1 true, i1 %70
%72 = icmp slt i32 %66, 1
%73 = select i1 %71, i1 true, i1 %72
br i1 %73, label %122, label %74
74: ; preds = %65
%75 = load i32, i32* %2
%76 = icmp slt i32 %75, 1
br i1 %76, label %122, label %77
77: ; preds = %74
%78 = load i32, i32* %3
%79 = icmp slt i32 %78, 1
br i1 %79, label %122, label %80
80: ; preds = %77
%81 = mul nsw i32 %78, %75
%82 = call i8* @malloc(i32 %81)
store i8* %82, i8** %1
%83 = icmp eq i8* %82, null
br i1 %83, label %128, label %84
84: ; preds = %80
%85 = icmp sgt i32 %81, 0
br i1 %85, label %86, label %128
86: ; preds = %84
%87 = icmp ult i32 %66, 256
%88 = add nuw nsw i32 %66, 1
br label %89
89: ; preds = %86, %110
%90 = phi i8* [ %82, %86 ], [ %117, %110 ]
%91 = phi i32 [ 0, %86 ], [ %116, %110 ]
br i1 %87, label %92, label %99
92: ; preds = %89
%93 = call i32 @fread(i8* %8, i32 1, i32 1, i32* %7)
%94 = icmp eq i32 %93, 1
br i1 %94, label %95, label %128
95: ; preds = %92
%96 = load i8, i8* %8
%97 = zext i8 %96 to i32
%98 = shl nuw nsw i32 %97, 8
br label %110
99: ; preds = %89
%100 = call i32 @fread(i8* %8, i32 1, i32 2, i32* %7)
%101 = icmp eq i32 %100, 2
br i1 %101, label %102, label %128
102: ; preds = %99
%103 = load i8, i8* %8
%104 = zext i8 %103 to i32
%105 = load i8, i8* %15
%106 = zext i8 %105 to i32
%107 = shl nuw nsw i32 %104, 16
%108 = shl nuw nsw i32 %106, 8
%109 = or i32 %108, %107
br label %110
110: ; preds = %95, %102
%111 = phi i32 [ %109, %102 ], [ %98, %95 ]
%112 = add nuw nsw i32 %111, 256
%113 = sdiv i32 %112, %88
%114 = trunc i32 %113 to i8
%115 = add i8 %114, -1
store i8 %115, i8* %90
%116 = add nuw nsw i32 %91, 1
%117 = getelementptr inbounds i8, i8* %90, i64 1
%118 = load i32, i32* %2
%119 = load i32, i32* %3
%120 = mul nsw i32 %119, %118
%121 = icmp slt i32 %116, %120
br i1 %121, label %89, label %128
122: ; preds = %74, %77, %65, %10
%123 = load i8*, i8** %1
%124 = icmp eq i8* %123, null
br i1 %124, label %127, label %125
125: ; preds = %122
%126 = call i32 @free(i8* %123)
br label %127
127: ; preds = %122, %125
store i8* null, i8** %1
br label %128
128: ; preds = %92, %99, %110, %80, %84, %127
%129 = phi i32 [ -1, %127 ], [ 0, %84 ], [ -3, %80 ], [ 0, %110 ], [ -2, %99 ], [ -2, %92 ]
%130 = call i32 @fclose(i32* %7)
br label %131
131: ; preds = %128, %4
%132 = phi i32 [ -1, %4 ], [ %129, %128 ]
ret i32 %132
}