#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;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ errorf(char *, char const *);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int get_num(int /*<<< orphan*/ *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ isspace(int);
int /*<<< orphan*/ skip_whites_and_comments(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
float *read_pgm_float(const char *fname, int *ncol, int *nrow) {
  FILE *f;
  int c, bin;
  int depth, i, j;
  float *data;
  f = fopen(fname, "rb");
  if (f == NULL)
    errorf("Error: unable to open input image file ", fname);
  if (getc(f) != 'P')
    errorf("Error: not a PGM file ", fname);
  if ((c = getc(f)) == '2')
    bin = 0;
  else if (c == '5')
    bin = 1;
  else
    errorf("Error: not a PGM file ", fname);
  skip_whites_and_comments(f);
  *ncol = get_num(f);
  skip_whites_and_comments(f);
  *nrow = get_num(f);
  skip_whites_and_comments(f);
  depth = get_num(f);
  if (depth == 0)
    fprintf(stderr, "Warning: depth=0, probably invalid PGM file\n");
  if (!isspace(c = getc(f)))
    errorf("Error: corrupted PGM file ", fname);
  data = (float *)calloc((*ncol) * (*nrow), sizeof(float));
  if (data == NULL)
    error("not enough memory.");
  if (depth < 256) {
    for (i = 0; i < *nrow; i++)
      for (j = 0; j < *ncol; j++)
        data[j + i * (*ncol)] = bin ? (float)getc(f) : (float)get_num(f);
  } else {
    for (i = 0; i < *nrow; i++)
      for (j = 0; j < *ncol; j++)
        data[j + i * (*ncol)] =
            bin ? ((float)getc(f) * 256) + (float)getc(f) : (float)get_num(f);
  }
  if (f != stdin && fclose(f) == EOF)
    errorf("Error: unable to close file while reading PGM file ", fname);
  return data;
}


x86 assembly (clang, -O0):
<read_pgm_float>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11e3 <read_pgm_float+0x43>
mov    -0x8(%rbp),%rsi
lea    0xe29(%rip),%rdi
call   1080 <errorf@plt>
mov    -0x20(%rbp),%rdi
call   10c0 <getc@plt>
movsbl %al,%eax
cmp    $0x50,%eax
je     1208 <read_pgm_float+0x68>
mov    -0x8(%rbp),%rsi
lea    0xe2c(%rip),%rdi
call   1080 <errorf@plt>
mov    -0x20(%rbp),%rdi
call   10c0 <getc@plt>
movsbl %al,%eax
mov    %eax,-0x24(%rbp)
cmp    $0x32,%eax
jne    122c <read_pgm_float+0x8c>
movl   $0x0,-0x28(%rbp)
jmp    1257 <read_pgm_float+0xb7>
cmpl   $0x35,-0x24(%rbp)
jne    1242 <read_pgm_float+0xa2>
movl   $0x1,-0x28(%rbp)
jmp    1252 <read_pgm_float+0xb2>
mov    -0x8(%rbp),%rsi
lea    0xde2(%rip),%rdi
call   1080 <errorf@plt>
jmp    1257 <read_pgm_float+0xb7>
mov    -0x20(%rbp),%rdi
call   10b0 <skip_whites_and_comments@plt>
mov    -0x20(%rbp),%rdi
call   1030 <get_num@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   10b0 <skip_whites_and_comments@plt>
mov    -0x20(%rbp),%rdi
call   1030 <get_num@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rdi
call   10b0 <skip_whites_and_comments@plt>
mov    -0x20(%rbp),%rdi
call   1030 <get_num@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    12bf <read_pgm_float+0x11f>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
lea    0xd8c(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   10c0 <getc@plt>
movsbl %al,%edi
mov    %edi,-0x24(%rbp)
call   1050 <isspace@plt>
cmp    $0x0,%eax
jne    12ec <read_pgm_float+0x14c>
mov    -0x8(%rbp),%rsi
lea    0xd8c(%rip),%rdi
call   1080 <errorf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
imul   (%rax),%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    131e <read_pgm_float+0x17e>
lea    0xd75(%rip),%rdi
call   1090 <error@plt>
cmpl   $0x100,-0x2c(%rbp)
jge    13d3 <read_pgm_float+0x233>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    13ce <read_pgm_float+0x22e>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    13bb <read_pgm_float+0x21b>
cmpl   $0x0,-0x28(%rbp)
je     137b <read_pgm_float+0x1db>
mov    -0x20(%rbp),%rdi
call   10c0 <getc@plt>
movsbl %al,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x44(%rbp)
jmp    138d <read_pgm_float+0x1ed>
mov    -0x20(%rbp),%rdi
call   1030 <get_num@plt>
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x44(%rbp)
movss  -0x44(%rbp),%xmm0
mov    -0x40(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    -0x30(%rbp),%edx
mov    -0x10(%rbp),%rsi
imul   (%rsi),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1348 <read_pgm_float+0x1a8>
jmp    13c0 <read_pgm_float+0x220>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1332 <read_pgm_float+0x192>
jmp    14a5 <read_pgm_float+0x305>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    14a0 <read_pgm_float+0x300>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    148d <read_pgm_float+0x2ed>
cmpl   $0x0,-0x28(%rbp)
je     144d <read_pgm_float+0x2ad>
mov    -0x20(%rbp),%rdi
call   10c0 <getc@plt>
movsbl %al,%eax
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x20(%rbp),%rdi
call   10c0 <getc@plt>
movss  -0x4c(%rbp),%xmm0
movsbl %al,%eax
cvtsi2ss %eax,%xmm1
movss  0xbc5(%rip),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x48(%rbp)
jmp    145f <read_pgm_float+0x2bf>
mov    -0x20(%rbp),%rdi
call   1030 <get_num@plt>
cvtsi2ss %eax,%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x48(%rbp),%xmm0
mov    -0x40(%rbp),%rax
mov    -0x34(%rbp),%ecx
mov    -0x30(%rbp),%edx
mov    -0x10(%rbp),%rsi
imul   (%rsi),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    13f0 <read_pgm_float+0x250>
jmp    1492 <read_pgm_float+0x2f2>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    13da <read_pgm_float+0x23a>
jmp    14a5 <read_pgm_float+0x305>
mov    -0x20(%rbp),%rax
mov    0x2b38(%rip),%rcx
cmp    (%rcx),%rax
je     14e2 <read_pgm_float+0x342>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2b17(%rip),%rcx
cmp    (%rcx),%rax
jne    14e2 <read_pgm_float+0x342>
mov    -0x8(%rbp),%rsi
lea    0xbc4(%rip),%rdi
call   1080 <errorf@plt>
mov    -0x40(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pgm_float>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,(%rsp)
mov    %rdi,%rbx
lea    0xe45(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    11db <read_pgm_float+0x3b>
lea    0xe34(%rip),%rdi
mov    %rbx,%rsi
call   1080 <errorf@plt>
mov    %r13,%rdi
call   10c0 <getc@plt>
cmp    $0x50,%al
je     11f6 <read_pgm_float+0x56>
lea    0xe41(%rip),%rdi
mov    %rbx,%rsi
call   1080 <errorf@plt>
mov    %r13,%rdi
call   10c0 <getc@plt>
cmp    $0x32,%al
je     120b <read_pgm_float+0x6b>
cmp    $0x35,%al
jne    1210 <read_pgm_float+0x70>
xor    %r14d,%r14d
jmp    121f <read_pgm_float+0x7f>
mov    $0x1,%r14b
jmp    121f <read_pgm_float+0x7f>
lea    0xe18(%rip),%rdi
mov    %rbx,%rsi
call   1080 <errorf@plt>
mov    %r13,%rdi
call   10b0 <skip_whites_and_comments@plt>
mov    %r13,%rdi
call   1030 <get_num@plt>
mov    (%rsp),%rcx
mov    %eax,(%rcx)
mov    %r13,%rdi
call   10b0 <skip_whites_and_comments@plt>
mov    %r13,%rdi
call   1030 <get_num@plt>
mov    %eax,(%r15)
mov    %r13,%rdi
call   10b0 <skip_whites_and_comments@plt>
mov    %r13,%rdi
call   1030 <get_num@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1273 <read_pgm_float+0xd3>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
lea    0xdd8(%rip),%rsi
call   1070 <fprintf@plt>
mov    %r13,%rdi
call   10c0 <getc@plt>
movsbl %al,%edi
call   1050 <isspace@plt>
test   %eax,%eax
jne    1296 <read_pgm_float+0xf6>
lea    0xde5(%rip),%rdi
mov    %rbx,%rsi
call   1080 <errorf@plt>
mov    %rbx,0x10(%rsp)
mov    (%r15),%edi
mov    (%rsp),%rax
imul   (%rax),%edi
mov    $0x4,%esi
call   1060 <calloc@plt>
mov    %rax,%r12
test   %rax,%rax
jne    12c3 <read_pgm_float+0x123>
lea    0xdd0(%rip),%rdi
call   1090 <error@plt>
mov    (%r15),%eax
cmp    $0x100,%ebp
jge    133d <read_pgm_float+0x19d>
test   %eax,%eax
jle    13e2 <read_pgm_float+0x242>
mov    (%rsp),%rcx
mov    (%rcx),%ecx
xor    %ebp,%ebp
jmp    12ee <read_pgm_float+0x14e>
mov    (%r15),%eax
add    $0x1,%ebp
cmp    %eax,%ebp
jge    13e2 <read_pgm_float+0x242>
test   %ecx,%ecx
jle    12e3 <read_pgm_float+0x143>
xor    %ebx,%ebx
jmp    132a <read_pgm_float+0x18a>
cs nopw 0x0(%rax,%rax,1)
call   1030 <get_num@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
mov    (%rsp),%rax
mov    (%rax),%ecx
mov    %ebp,%eax
imul   %ecx,%eax
cltq
add    %rbx,%rax
movss  %xmm0,(%r12,%rax,4)
add    $0x1,%rbx
cmp    %ecx,%ebx
jge    12e0 <read_pgm_float+0x140>
mov    %r13,%rdi
test   $0x1,%r14b
jne    1300 <read_pgm_float+0x160>
call   10c0 <getc@plt>
movsbl %al,%eax
jmp    1305 <read_pgm_float+0x165>
test   %eax,%eax
jle    13e2 <read_pgm_float+0x242>
mov    (%rsp),%rcx
mov    (%rcx),%ecx
xor    %ebp,%ebp
jmp    1360 <read_pgm_float+0x1c0>
nop
mov    %rbx,%r15
mov    (%rbx),%eax
add    $0x1,%ebp
cmp    %eax,%ebp
jge    13e2 <read_pgm_float+0x242>
test   %ecx,%ecx
jle    1355 <read_pgm_float+0x1b5>
mov    %r15,%rbx
xor    %r15d,%r15d
jmp    139b <read_pgm_float+0x1fb>
nopl   0x0(%rax)
call   1030 <get_num@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
mov    (%rsp),%rax
mov    (%rax),%ecx
mov    %ebp,%eax
imul   %ecx,%eax
cltq
add    %r15,%rax
movss  %xmm0,(%r12,%rax,4)
add    $0x1,%r15
cmp    %ecx,%r15d
jge    1350 <read_pgm_float+0x1b0>
mov    %r13,%rdi
test   $0x1,%r14b
jne    1370 <read_pgm_float+0x1d0>
call   10c0 <getc@plt>
movsbl %al,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  %xmm0,0xc(%rsp)
mov    %r13,%rdi
call   10c0 <getc@plt>
movsbl %al,%eax
xorps  %xmm0,%xmm0
cvtsi2ss %eax,%xmm0
movss  0xc(%rsp),%xmm1
mulss  0xc27(%rip),%xmm1
addss  %xmm0,%xmm1
movaps %xmm1,%xmm0
jmp    137c <read_pgm_float+0x1dc>
mov    0x2bff(%rip),%rax
cmp    (%rax),%r13
je     1413 <read_pgm_float+0x273>
mov    %r13,%rdi
call   1040 <fclose@plt>
mov    0x2be3(%rip),%rcx
cmp    (%rcx),%rax
jne    1413 <read_pgm_float+0x273>
lea    0xc98(%rip),%rdi
mov    0x10(%rsp),%rsi
call   1080 <errorf@plt>
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [40 x i8] c"Error: unable to open input image file \00"
@.str.2 = [23 x i8] c"Error: not a PGM file \00"
@stderr = global i32 0
@.str.3 = [45 x i8] c"Warning: depth=0, probably invalid PGM file\0A\00"
@.str.4 = [27 x i8] c"Error: corrupted PGM file \00"
@.str.5 = [19 x i8] c"not enough memory.\00"
@stdin = global i32* null
@EOF = global i64 0
@.str.6 = [52 x i8] c"Error: unable to close file while reading PGM file \00"
define float* @read_pgm_float(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca float*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%14 = load i8*, i8** %4
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
%16 = load i32*, i32** %7
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %3
%19 = load i8*, i8** %4
%20 = call i32 @errorf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %3
%22 = load i32*, i32** %7
%23 = call signext i8 @getc(i32* %22)
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 80
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = call i32 @errorf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %26, %21
%30 = load i32*, i32** %7
%31 = call signext i8 @getc(i32* %30)
%32 = sext i8 %31 to i32
store i32 %32, i32* %8
%33 = icmp eq i32 %32, 50
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 0, i32* %9
br label %43
35: ; preds = %29
%36 = load i32, i32* %8
%37 = icmp eq i32 %36, 53
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 1, i32* %9
br label %42
39: ; preds = %35
%40 = load i8*, i8** %4
%41 = call i32 @errorf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %39, %38
br label %43
43: ; preds = %42, %34
%44 = load i32*, i32** %7
%45 = call i32 @skip_whites_and_comments(i32* %44)
%46 = load i32*, i32** %7
%47 = call i32 @get_num(i32* %46)
%48 = load i32*, i32** %5
store i32 %47, i32* %48
%49 = load i32*, i32** %7
%50 = call i32 @skip_whites_and_comments(i32* %49)
%51 = load i32*, i32** %7
%52 = call i32 @get_num(i32* %51)
%53 = load i32*, i32** %6
store i32 %52, i32* %53
%54 = load i32*, i32** %7
%55 = call i32 @skip_whites_and_comments(i32* %54)
%56 = load i32*, i32** %7
%57 = call i32 @get_num(i32* %56)
store i32 %57, i32* %10
%58 = load i32, i32* %10
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %43
%61 = load i32, i32* @stderr
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
br label %63
63: ; preds = %60, %43
%64 = load i32*, i32** %7
%65 = call signext i8 @getc(i32* %64)
%66 = sext i8 %65 to i32
store i32 %66, i32* %8
%67 = call i32 @isspace(i32 %66)
%68 = icmp ne i32 %67, 0
br i1 %68, label %72, label %69
69: ; preds = %63
%70 = load i8*, i8** %4
%71 = call i32 @errorf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %69, %63
%73 = load i32*, i32** %5
%74 = load i32, i32* %73
%75 = load i32*, i32** %6
%76 = load i32, i32* %75
%77 = mul nsw i32 %74, %76
%78 = call i64 @calloc(i32 %77, i32 4)
%79 = inttoptr i64 %78 to float*
store float* %79, float** %13
%80 = load float*, float** %13
%81 = icmp eq float* %80, null
br i1 %81, label %82, label %84
82: ; preds = %72
%83 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %84
84: ; preds = %82, %72
%85 = load i32, i32* %10
%86 = icmp slt i32 %85, 256
br i1 %86, label %87, label %129
87: ; preds = %84
store i32 0, i32* %11
br label %88
88: ; preds = %125, %87
%89 = load i32, i32* %11
%90 = load i32*, i32** %6
%91 = load i32, i32* %90
%92 = icmp slt i32 %89, %91
br i1 %92, label %93, label %128
93: ; preds = %88
store i32 0, i32* %12
br label %94
94: ; preds = %121, %93
%95 = load i32, i32* %12
%96 = load i32*, i32** %5
%97 = load i32, i32* %96
%98 = icmp slt i32 %95, %97
br i1 %98, label %99, label %124
99: ; preds = %94
%100 = load i32, i32* %9
%101 = icmp ne i32 %100, 0
br i1 %101, label %102, label %106
102: ; preds = %99
%103 = load i32*, i32** %7
%104 = call signext i8 @getc(i32* %103)
%105 = sitofp i8 %104 to float
br label %110
106: ; preds = %99
%107 = load i32*, i32** %7
%108 = call i32 @get_num(i32* %107)
%109 = sitofp i32 %108 to float
br label %110
110: ; preds = %106, %102
%111 = phi float [ %105, %102 ], [ %109, %106 ]
%112 = load float*, float** %13
%113 = load i32, i32* %12
%114 = load i32, i32* %11
%115 = load i32*, i32** %5
%116 = load i32, i32* %115
%117 = mul nsw i32 %114, %116
%118 = add nsw i32 %113, %117
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds float, float* %112, i64 %119
store float %111, float* %120
br label %121
121: ; preds = %110
%122 = load i32, i32* %12
%123 = add nsw i32 %122, 1
store i32 %123, i32* %12
br label %94
124: ; preds = %94
br label %125
125: ; preds = %124
%126 = load i32, i32* %11
%127 = add nsw i32 %126, 1
store i32 %127, i32* %11
br label %88
128: ; preds = %88
br label %175
129: ; preds = %84
store i32 0, i32* %11
br label %130
130: ; preds = %171, %129
%131 = load i32, i32* %11
%132 = load i32*, i32** %6
%133 = load i32, i32* %132
%134 = icmp slt i32 %131, %133
br i1 %134, label %135, label %174
135: ; preds = %130
store i32 0, i32* %12
br label %136
136: ; preds = %167, %135
%137 = load i32, i32* %12
%138 = load i32*, i32** %5
%139 = load i32, i32* %138
%140 = icmp slt i32 %137, %139
br i1 %140, label %141, label %170
141: ; preds = %136
%142 = load i32, i32* %9
%143 = icmp ne i32 %142, 0
br i1 %143, label %144, label %152
144: ; preds = %141
%145 = load i32*, i32** %7
%146 = call signext i8 @getc(i32* %145)
%147 = sitofp i8 %146 to float
%148 = load i32*, i32** %7
%149 = call signext i8 @getc(i32* %148)
%150 = sitofp i8 %149 to float
%151 = call float @llvm.fmuladd.f32(float %147, float 2.560000e+02, float %150)
br label %156
152: ; preds = %141
%153 = load i32*, i32** %7
%154 = call i32 @get_num(i32* %153)
%155 = sitofp i32 %154 to float
br label %156
156: ; preds = %152, %144
%157 = phi float [ %151, %144 ], [ %155, %152 ]
%158 = load float*, float** %13
%159 = load i32, i32* %12
%160 = load i32, i32* %11
%161 = load i32*, i32** %5
%162 = load i32, i32* %161
%163 = mul nsw i32 %160, %162
%164 = add nsw i32 %159, %163
%165 = sext i32 %164 to i64
%166 = getelementptr inbounds float, float* %158, i64 %165
store float %157, float* %166
br label %167
167: ; preds = %156
%168 = load i32, i32* %12
%169 = add nsw i32 %168, 1
store i32 %169, i32* %12
br label %136
170: ; preds = %136
br label %171
171: ; preds = %170
%172 = load i32, i32* %11
%173 = add nsw i32 %172, 1
store i32 %173, i32* %11
br label %130
174: ; preds = %130
br label %175
175: ; preds = %174, %128
%176 = load i32*, i32** %7
%177 = load i32*, i32** @stdin
%178 = icmp ne i32* %176, %177
br i1 %178, label %179, label %187
179: ; preds = %175
%180 = load i32*, i32** %7
%181 = call i64 @fclose(i32* %180)
%182 = load i64, i64* @EOF
%183 = icmp eq i64 %181, %182
br i1 %183, label %184, label %187
184: ; preds = %179
%185 = load i8*, i8** %4
%186 = call i32 @errorf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), i8* %185)
br label %187
187: ; preds = %184, %179, %175
%188 = load float*, float** %13
ret float* %188
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [40 x i8] c"Error: unable to open input image file \00"
@.str.2 = [23 x i8] c"Error: not a PGM file \00"
@stderr = global i32 0
@.str.3 = [45 x i8] c"Warning: depth=0, probably invalid PGM file\0A\00"
@.str.4 = [27 x i8] c"Error: corrupted PGM file \00"
@.str.5 = [19 x i8] c"not enough memory.\00"
@stdin = global i32* null
@EOF = global i64 0
@.str.6 = [52 x i8] c"Error: unable to close file while reading PGM file \00"
define float* @read_pgm_float(i8* %0, i32* nocapture %1, i32* nocapture %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @errorf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %8
8: ; preds = %6, %3
%9 = tail call signext i8 @getc(i32* %4)
%10 = icmp eq i8 %9, 80
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @errorf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %11, %8
%14 = tail call signext i8 @getc(i32* %4)
switch i8 %14, label %16 [
i8 50, label %18
i8 53, label %15
]
15: ; preds = %13
br label %18
16: ; preds = %13
%17 = tail call i32 @errorf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %18
18: ; preds = %13, %15, %16
%19 = phi i1 [ false, %15 ], [ undef, %16 ], [ true, %13 ]
%20 = tail call i32 @skip_whites_and_comments(i32* %4)
%21 = tail call i32 @get_num(i32* %4)
store i32 %21, i32* %1
%22 = tail call i32 @skip_whites_and_comments(i32* %4)
%23 = tail call i32 @get_num(i32* %4)
store i32 %23, i32* %2
%24 = tail call i32 @skip_whites_and_comments(i32* %4)
%25 = tail call i32 @get_num(i32* %4)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %18
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
br label %30
30: ; preds = %27, %18
%31 = tail call signext i8 @getc(i32* %4)
%32 = sext i8 %31 to i32
%33 = tail call i32 @isspace(i32 %32)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = tail call i32 @errorf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %37
37: ; preds = %35, %30
%38 = load i32, i32* %1
%39 = load i32, i32* %2
%40 = mul nsw i32 %39, %38
%41 = tail call i64 @calloc(i32 %40, i32 4)
%42 = inttoptr i64 %41 to float*
%43 = icmp eq i64 %41, 0
br i1 %43, label %44, label %46
44: ; preds = %37
%45 = tail call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %44, %37
%47 = icmp slt i32 %25, 256
%48 = load i32, i32* %2
%49 = icmp sgt i32 %48, 0
br i1 %47, label %53, label %50
50: ; preds = %46
br i1 %49, label %51, label %117
51: ; preds = %50
%52 = load i32, i32* %1
br label %85
53: ; preds = %46
br i1 %49, label %54, label %117
54: ; preds = %53
%55 = load i32, i32* %1
br label %56
56: ; preds = %54, %80
%57 = phi i32 [ %81, %80 ], [ %48, %54 ]
%58 = phi i32 [ %82, %80 ], [ %55, %54 ]
%59 = phi i32 [ %83, %80 ], [ 0, %54 ]
%60 = icmp sgt i32 %58, 0
br i1 %60, label %61, label %80
61: ; preds = %56, %69
%62 = phi i32 [ %76, %69 ], [ 0, %56 ]
br i1 %19, label %66, label %63
63: ; preds = %61
%64 = tail call signext i8 @getc(i32* %4)
%65 = sitofp i8 %64 to float
br label %69
66: ; preds = %61
%67 = tail call i32 @get_num(i32* %4)
%68 = sitofp i32 %67 to float
br label %69
69: ; preds = %66, %63
%70 = phi float [ %65, %63 ], [ %68, %66 ]
%71 = load i32, i32* %1
%72 = mul nsw i32 %71, %59
%73 = add nsw i32 %72, %62
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds float, float* %42, i64 %74
store float %70, float* %75
%76 = add nuw nsw i32 %62, 1
%77 = icmp slt i32 %76, %71
br i1 %77, label %61, label %78
78: ; preds = %69
%79 = load i32, i32* %2
br label %80
80: ; preds = %78, %56
%81 = phi i32 [ %79, %78 ], [ %57, %56 ]
%82 = phi i32 [ %71, %78 ], [ %58, %56 ]
%83 = add nuw nsw i32 %59, 1
%84 = icmp slt i32 %83, %81
br i1 %84, label %56, label %117
85: ; preds = %51, %112
%86 = phi i32 [ %113, %112 ], [ %48, %51 ]
%87 = phi i32 [ %114, %112 ], [ %52, %51 ]
%88 = phi i32 [ %115, %112 ], [ 0, %51 ]
%89 = icmp sgt i32 %87, 0
br i1 %89, label %90, label %112
90: ; preds = %85, %101
%91 = phi i32 [ %108, %101 ], [ 0, %85 ]
br i1 %19, label %98, label %92
92: ; preds = %90
%93 = tail call signext i8 @getc(i32* %4)
%94 = sitofp i8 %93 to float
%95 = tail call signext i8 @getc(i32* %4)
%96 = sitofp i8 %95 to float
%97 = tail call float @llvm.fmuladd.f32(float %94, float 2.560000e+02, float %96)
br label %101
98: ; preds = %90
%99 = tail call i32 @get_num(i32* %4)
%100 = sitofp i32 %99 to float
br label %101
101: ; preds = %98, %92
%102 = phi float [ %97, %92 ], [ %100, %98 ]
%103 = load i32, i32* %1
%104 = mul nsw i32 %103, %88
%105 = add nsw i32 %104, %91
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds float, float* %42, i64 %106
store float %102, float* %107
%108 = add nuw nsw i32 %91, 1
%109 = icmp slt i32 %108, %103
br i1 %109, label %90, label %110
110: ; preds = %101
%111 = load i32, i32* %2
br label %112
112: ; preds = %110, %85
%113 = phi i32 [ %111, %110 ], [ %86, %85 ]
%114 = phi i32 [ %103, %110 ], [ %87, %85 ]
%115 = add nuw nsw i32 %88, 1
%116 = icmp slt i32 %115, %113
br i1 %116, label %85, label %117
117: ; preds = %112, %80, %50, %53
%118 = load i32*, i32** @stdin
%119 = icmp eq i32* %4, %118
br i1 %119, label %126, label %120
120: ; preds = %117
%121 = tail call i64 @fclose(i32* %4)
%122 = load i64, i64* @EOF
%123 = icmp eq i64 %121, %122
br i1 %123, label %124, label %126
124: ; preds = %120
%125 = tail call i32 @errorf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.6, i64 0, i64 0), i8* %0)
br label %126
126: ; preds = %124, %120, %117
ret float* %42
}