#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 EOF;
int /*<<< orphan*/ errhandler(int, char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int **imatrix(int /*<<< orphan*/, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ sscanf(char *, char *, int *, ...);
int **read_pgm(const char *filename) {
  FILE *input = NULL;
  char line[1024];
  int levels;
  int xsize, ysize;
  int i1, j1;
  int **pic = NULL;
  if ((input = fopen(filename, "rb")) == 0) {
    char szBuff[80];
    sprintf(szBuff, "Can not read file %s !!!", filename);
    errhandler(439,
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/nathanwbrei/cfdlab/refs/"
               "heads/master/worksheet1/helper.c",
               szBuff);
  }
  if (fread(line, 1, 3, input) != 3) {
    fclose(input);
    errhandler(446,
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/nathanwbrei/cfdlab/refs/"
               "heads/master/worksheet1/helper.c",
               "Error Wrong Magic field!");
  }
  do
    fgets(line, sizeof line, input);
  while (*line == '#');
  sscanf(line, "%d %d\n", &xsize, &ysize);
  printf("Image size: %d x %d\n", xsize, ysize);
  fgets(line, sizeof line, input);
  sscanf(line, "%d\n", &levels);
  pic = imatrix(0, xsize + 1, 0, ysize + 1);
  printf("Image initialised...\n");
  for (j1 = 1; j1 < ysize + 1; j1++) {
    for (i1 = 1; i1 < xsize + 1; i1++) {
      int byte;
      fscanf(input, "%d", &byte);
      if (byte == EOF) {
        fclose(input);
        errhandler(478,
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/nathanwbrei/cfdlab/refs/"
                   "heads/master/worksheet1/helper.c",
                   "read failed");
      } else {
        pic[i1][ysize + 1 - j1] = byte;
        printf("%d,%d: %d\n", i1, ysize + 1 - j1, byte);
      }
    }
  }
  for (i1 = 0; i1 < xsize + 2; i1++) {
    pic[i1][0] = 0;
  }
  for (i1 = 0; i1 < xsize + 2; i1++) {
    pic[i1][ysize + 1] = 0;
  }
  for (j1 = 0; j1 < ysize + 2; j1++) {
    pic[0][j1] = 0;
    pic[xsize + 1][j1] = 0;
  }
  fclose(input);
  return pic;
}


x86 assembly (clang, -O0):
<read_pgm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x430(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe33(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    120f <read_pgm+0x6f>
lea    -0x480(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe11(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x480(%rbp),%rdx
mov    $0x1b7,%edi
lea    0xe12(%rip),%rsi
call   1050 <errhandler@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1040 <fread@plt>
cmp    $0x3,%eax
je     1253 <read_pgm+0xb3>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1be,%edi
lea    0xdd5(%rip),%rsi
lea    0xe61(%rip),%rdx
call   1050 <errhandler@plt>
jmp    1258 <read_pgm+0xb8>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
movsbl -0x410(%rbp),%eax
cmp    $0x23,%eax
je     1258 <read_pgm+0xb8>
lea    -0x410(%rbp),%rdi
lea    0xe3d(%rip),%rsi
lea    -0x418(%rbp),%rdx
lea    -0x41c(%rbp),%rcx
mov    $0x0,%al
call   10a0 <sscanf@plt>
mov    -0x418(%rbp),%esi
mov    -0x41c(%rbp),%edx
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
lea    -0x410(%rbp),%rdi
lea    0xe33(%rip),%rsi
lea    -0x414(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
mov    -0x418(%rbp),%esi
add    $0x1,%esi
mov    -0x41c(%rbp),%ecx
add    $0x1,%ecx
xor    %edx,%edx
mov    %edx,%edi
call   1030 <imatrix@plt>
mov    %rax,-0x430(%rbp)
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x424(%rbp)
mov    -0x424(%rbp),%eax
mov    -0x41c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1437 <read_pgm+0x297>
movl   $0x1,-0x420(%rbp)
mov    -0x420(%rbp),%eax
mov    -0x418(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    141e <read_pgm+0x27e>
mov    -0x10(%rbp),%rdi
lea    0xd92(%rip),%rsi
lea    -0x484(%rbp),%rdx
call   1080 <fscanf@plt>
mov    -0x484(%rbp),%eax
mov    0x2c67(%rip),%rcx
cmp    (%rcx),%eax
jne    13af <read_pgm+0x20f>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1de,%edi
lea    0xc7e(%rip),%rsi
lea    0xd58(%rip),%rdx
call   1050 <errhandler@plt>
jmp    1405 <read_pgm+0x265>
mov    -0x484(%rbp),%edx
mov    -0x430(%rbp),%rax
movslq -0x420(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x41c(%rbp),%ecx
add    $0x1,%ecx
sub    -0x424(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x420(%rbp),%esi
mov    -0x41c(%rbp),%edx
add    $0x1,%edx
sub    -0x424(%rbp),%edx
mov    -0x484(%rbp),%ecx
lea    0xd0b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    140a <read_pgm+0x26a>
mov    -0x420(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x420(%rbp)
jmp    1346 <read_pgm+0x1a6>
jmp    1423 <read_pgm+0x283>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    1325 <read_pgm+0x185>
movl   $0x0,-0x420(%rbp)
mov    -0x420(%rbp),%eax
mov    -0x418(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    1484 <read_pgm+0x2e4>
mov    -0x430(%rbp),%rax
movslq -0x420(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movl   $0x0,(%rax)
mov    -0x420(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x420(%rbp)
jmp    1441 <read_pgm+0x2a1>
movl   $0x0,-0x420(%rbp)
mov    -0x420(%rbp),%eax
mov    -0x418(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    14de <read_pgm+0x33e>
mov    -0x430(%rbp),%rax
movslq -0x420(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x41c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x420(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x420(%rbp)
jmp    148e <read_pgm+0x2ee>
movl   $0x0,-0x424(%rbp)
mov    -0x424(%rbp),%eax
mov    -0x41c(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    1550 <read_pgm+0x3b0>
mov    -0x430(%rbp),%rax
mov    (%rax),%rax
movslq -0x424(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x430(%rbp),%rax
mov    -0x418(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x424(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    14e8 <read_pgm+0x348>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x430(%rbp),%rax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pgm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rdi,%rbp
lea    0xe35(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1203 <read_pgm+0x53>
lea    0xe24(%rip),%rsi
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %rbp,%rdx
call   10d0 <sprintf@plt>
lea    0xe26(%rip),%rsi
mov    $0x1b7,%edi
mov    %r14,%rdx
call   1060 <errhandler@plt>
lea    0x20(%rsp),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    $0x3,%eax
je     123f <read_pgm+0x8f>
mov    %rbx,%rdi
call   1070 <fclose@plt>
lea    0xdee(%rip),%rsi
lea    0xe7a(%rip),%rdx
mov    $0x1be,%edi
call   1060 <errhandler@plt>
lea    0x20(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   10a0 <fgets@plt>
cmpb   $0x23,0x20(%rsp)
je     1250 <read_pgm+0xa0>
lea    0xe5a(%rip),%rsi
lea    0x20(%rsp),%rbp
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rbp,%rdi
xor    %eax,%eax
call   10b0 <sscanf@plt>
mov    0x8(%rsp),%esi
mov    0x4(%rsp),%edx
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   10a0 <fgets@plt>
lea    0xe46(%rip),%rsi
lea    0x1c(%rsp),%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   10b0 <sscanf@plt>
mov    0x8(%rsp),%esi
add    $0x1,%esi
mov    0x4(%rsp),%ecx
add    $0x1,%ecx
xor    %edi,%edi
xor    %edx,%edx
call   1030 <imatrix@plt>
mov    %rax,0x10(%rsp)
lea    0xe18(%rip),%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
jle    13cf <read_pgm+0x21f>
mov    $0x1,%r13d
mov    $0xffffffff,%r15d
mov    0x8(%rsp),%eax
lea    0xc(%rsp),%r12
mov    0x2cd5(%rip),%r14
jmp    133a <read_pgm+0x18a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x4(%rsp),%ecx
lea    0x1(%r13),%edx
cmp    %ecx,%r13d
not    %r13d
mov    %r13d,%r15d
mov    %edx,%r13d
jge    13d3 <read_pgm+0x223>
test   %eax,%eax
jle    1324 <read_pgm+0x174>
add    $0x1,%r15d
mov    $0x1,%ebp
jmp    1392 <read_pgm+0x1e2>
nopl   0x0(%rax)
mov    0x10(%rsp),%rcx
mov    (%rcx,%rbp,8),%rcx
mov    0x4(%rsp),%edx
add    %r15d,%edx
movslq %edx,%rdx
mov    %eax,(%rcx,%rdx,4)
mov    0x4(%rsp),%edx
add    %r15d,%edx
mov    0xc(%rsp),%ecx
lea    0xd7b(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x1(%rbp),%rcx
movslq 0x8(%rsp),%rax
cmp    %rax,%rbp
mov    %rcx,%rbp
jge    1320 <read_pgm+0x170>
mov    %rbx,%rdi
lea    0xd48(%rip),%rsi
mov    %r12,%rdx
call   1090 <fscanf@plt>
mov    0xc(%rsp),%eax
cmp    (%r14),%eax
jne    1350 <read_pgm+0x1a0>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    $0x1de,%edi
lea    0xc5b(%rip),%rsi
lea    0xd1f(%rip),%rdx
call   1060 <errhandler@plt>
jmp    1381 <read_pgm+0x1d1>
mov    0x8(%rsp),%eax
cmp    $0xffffffff,%eax
mov    0x10(%rsp),%rbp
jl     1440 <read_pgm+0x290>
mov    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x8(%rbp,%rax,8),%rcx
movl   $0x0,(%rcx)
movslq 0x8(%rsp),%rcx
add    $0x1,%rax
cmp    %rcx,%rax
jle    13f0 <read_pgm+0x240>
cmp    $0xffffffff,%ecx
jl     1440 <read_pgm+0x290>
mov    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%rbp,%rax,8),%rcx
movslq 0x4(%rsp),%rdx
movl   $0x0,0x4(%rcx,%rdx,4)
movslq 0x8(%rsp),%rcx
add    $0x1,%rax
cmp    %rcx,%rax
jle    1420 <read_pgm+0x270>
cmpl   $0xffffffff,0x4(%rsp)
jl     1488 <read_pgm+0x2d8>
mov    0x0(%rbp),%rax
mov    $0xffffffffffffffff,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movl   $0x0,0x4(%rax,%rcx,4)
movslq 0x8(%rsp),%rdx
mov    0x8(%rbp,%rdx,8),%rdx
movl   $0x0,0x4(%rdx,%rcx,4)
movslq 0x4(%rsp),%rdx
add    $0x1,%rcx
cmp    %rdx,%rcx
jle    1460 <read_pgm+0x2b0>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %rbp,%rax
add    $0x428,%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 = [25 x i8] c"Can not read file %s !!!\00"
@.str.2 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/nathanwbrei/cfdlab/refs/heads/master/worksheet1/helper.c\00"
@.str.3 = [25 x i8] c"Error Wrong Magic field!\00"
@.str.4 = [7 x i8] c"%d %d\0A\00"
@.str.5 = [21 x i8] c"Image size: %d x %d\0A\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@.str.7 = [22 x i8] c"Image initialised...\0A\00"
@.str.8 = [3 x i8] c"%d\00"
@EOF = global i32 0
@.str.9 = [12 x i8] c"read failed\00"
@.str.10 = [11 x i8] c"%d,%d: %d\0A\00"
define i32** @read_pgm(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32**
%11 = alloca [80 x i8]
%12 = alloca i32
store i8* %0, i8** %2
store i32* null, i32** %3
store i32** null, i32*** %10
%13 = load i8*, i8** %2
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %3
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %22
16: ; preds = %1
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%18 = load i8*, i8** %2
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%21 = call i32 @errhandler(i32 439, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %16, %1
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%24 = load i32*, i32** %3
%25 = call i32 @fread(i8* %23, i32 1, i32 3, i32* %24)
%26 = icmp ne i32 %25, 3
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = load i32*, i32** %3
%29 = call i32 @fclose(i32* %28)
%30 = call i32 @errhandler(i32 446, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %27, %22
br label %32
32: ; preds = %36, %31
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%34 = load i32*, i32** %3
%35 = call i32 @fgets(i8* %33, i32 1024, i32* %34)
br label %36
36: ; preds = %32
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 35
br i1 %40, label %32, label %41
41: ; preds = %36
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%43 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %42, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %6, i32* %7)
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %44, i32 %45)
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%48 = load i32*, i32** %3
%49 = call i32 @fgets(i8* %47, i32 1024, i32* %48)
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%51 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32* %5)
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
%56 = call i32** @imatrix(i32 0, i32 %53, i32 0, i32 %55)
store i32** %56, i32*** %10
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %9
br label %58
58: ; preds = %104, %41
%59 = load i32, i32* %9
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 1
%62 = icmp slt i32 %59, %61
br i1 %62, label %63, label %107
63: ; preds = %58
store i32 1, i32* %8
br label %64
64: ; preds = %100, %63
%65 = load i32, i32* %8
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
%68 = icmp slt i32 %65, %67
br i1 %68, label %69, label %103
69: ; preds = %64
%70 = load i32*, i32** %3
%71 = call i32 @fscanf(i32* %70, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %12)
%72 = load i32, i32* %12
%73 = load i32, i32* @EOF
%74 = icmp eq i32 %72, %73
br i1 %74, label %75, label %79
75: ; preds = %69
%76 = load i32*, i32** %3
%77 = call i32 @fclose(i32* %76)
%78 = call i32 @errhandler(i32 478, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
br label %99
79: ; preds = %69
%80 = load i32, i32* %12
%81 = load i32**, i32*** %10
%82 = load i32, i32* %8
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i32*, i32** %81, i64 %83
%85 = load i32*, i32** %84
%86 = load i32, i32* %7
%87 = add nsw i32 %86, 1
%88 = load i32, i32* %9
%89 = sub nsw i32 %87, %88
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds i32, i32* %85, i64 %90
store i32 %80, i32* %91
%92 = load i32, i32* %8
%93 = load i32, i32* %7
%94 = add nsw i32 %93, 1
%95 = load i32, i32* %9
%96 = sub nsw i32 %94, %95
%97 = load i32, i32* %12
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i32 %92, i32 %96, i32 %97)
br label %99
99: ; preds = %79, %75
br label %100
100: ; preds = %99
%101 = load i32, i32* %8
%102 = add nsw i32 %101, 1
store i32 %102, i32* %8
br label %64
103: ; preds = %64
br label %104
104: ; preds = %103
%105 = load i32, i32* %9
%106 = add nsw i32 %105, 1
store i32 %106, i32* %9
br label %58
107: ; preds = %58
store i32 0, i32* %8
br label %108
108: ; preds = %120, %107
%109 = load i32, i32* %8
%110 = load i32, i32* %6
%111 = add nsw i32 %110, 2
%112 = icmp slt i32 %109, %111
br i1 %112, label %113, label %123
113: ; preds = %108
%114 = load i32**, i32*** %10
%115 = load i32, i32* %8
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds i32*, i32** %114, i64 %116
%118 = load i32*, i32** %117
%119 = getelementptr inbounds i32, i32* %118, i64 0
store i32 0, i32* %119
br label %120
120: ; preds = %113
%121 = load i32, i32* %8
%122 = add nsw i32 %121, 1
store i32 %122, i32* %8
br label %108
123: ; preds = %108
store i32 0, i32* %8
br label %124
124: ; preds = %139, %123
%125 = load i32, i32* %8
%126 = load i32, i32* %6
%127 = add nsw i32 %126, 2
%128 = icmp slt i32 %125, %127
br i1 %128, label %129, label %142
129: ; preds = %124
%130 = load i32**, i32*** %10
%131 = load i32, i32* %8
%132 = sext i32 %131 to i64
%133 = getelementptr inbounds i32*, i32** %130, i64 %132
%134 = load i32*, i32** %133
%135 = load i32, i32* %7
%136 = add nsw i32 %135, 1
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds i32, i32* %134, i64 %137
store i32 0, i32* %138
br label %139
139: ; preds = %129
%140 = load i32, i32* %8
%141 = add nsw i32 %140, 1
store i32 %141, i32* %8
br label %124
142: ; preds = %124
store i32 0, i32* %9
br label %143
143: ; preds = %164, %142
%144 = load i32, i32* %9
%145 = load i32, i32* %7
%146 = add nsw i32 %145, 2
%147 = icmp slt i32 %144, %146
br i1 %147, label %148, label %167
148: ; preds = %143
%149 = load i32**, i32*** %10
%150 = getelementptr inbounds i32*, i32** %149, i64 0
%151 = load i32*, i32** %150
%152 = load i32, i32* %9
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds i32, i32* %151, i64 %153
store i32 0, i32* %154
%155 = load i32**, i32*** %10
%156 = load i32, i32* %6
%157 = add nsw i32 %156, 1
%158 = sext i32 %157 to i64
%159 = getelementptr inbounds i32*, i32** %155, i64 %158
%160 = load i32*, i32** %159
%161 = load i32, i32* %9
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds i32, i32* %160, i64 %162
store i32 0, i32* %163
br label %164
164: ; preds = %148
%165 = load i32, i32* %9
%166 = add nsw i32 %165, 1
store i32 %166, i32* %9
br label %143
167: ; preds = %143
%168 = load i32*, i32** %3
%169 = call i32 @fclose(i32* %168)
%170 = load i32**, i32*** %10
ret i32** %170
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [25 x i8] c"Can not read file %s !!!\00"
@.str.2 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/nathanwbrei/cfdlab/refs/heads/master/worksheet1/helper.c\00"
@.str.3 = [25 x i8] c"Error Wrong Magic field!\00"
@.str.4 = [7 x i8] c"%d %d\0A\00"
@.str.5 = [21 x i8] c"Image size: %d x %d\0A\00"
@.str.6 = [4 x i8] c"%d\0A\00"
@.str.8 = [3 x i8] c"%d\00"
@EOF = global i32 0
@.str.9 = [12 x i8] c"read failed\00"
@.str.10 = [11 x i8] c"%d,%d: %d\0A\00"
@str = [21 x i8] c"Image initialised...\00"
define i32** @read_pgm(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [80 x i8]
%7 = alloca i32
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%16 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%17 = call i32 @errhandler(i32 439, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %18
18: ; preds = %14, %1
%19 = call i32 @fread(i8* %8, i32 1, i32 3, i32* %12)
%20 = icmp eq i32 %19, 3
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = call i32 @fclose(i32* %12)
%23 = call i32 @errhandler(i32 446, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %21, %18
br label %25
25: ; preds = %24, %25
%26 = call i32 @fgets(i8* %8, i32 1024, i32* %12)
%27 = load i8, i8* %8
%28 = icmp eq i8 %27, 35
br i1 %28, label %25, label %29
29: ; preds = %25
%30 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %4, i32* %5)
%31 = load i32, i32* %4
%32 = load i32, i32* %5
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %31, i32 %32)
%34 = call i32 @fgets(i8* %8, i32 1024, i32* %12)
%35 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32* %3)
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
%40 = call i32** @imatrix(i32 0, i32 %37, i32 0, i32 %39)
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
%42 = load i32, i32* %5
%43 = icmp slt i32 %42, 1
br i1 %43, label %44, label %46
44: ; preds = %29
%45 = load i32, i32* %4
br label %57
46: ; preds = %29
%47 = bitcast i32* %7 to i8*
%48 = load i32, i32* %4
br label %49
49: ; preds = %46, %88
%50 = phi i32 [ %42, %46 ], [ %89, %88 ]
%51 = phi i32 [ %48, %46 ], [ %90, %88 ]
%52 = phi i32 [ -1, %46 ], [ %92, %88 ]
%53 = phi i32 [ 1, %46 ], [ %91, %88 ]
%54 = icmp slt i32 %51, 1
br i1 %54, label %88, label %55
55: ; preds = %49
%56 = add nsw i32 %52, 1
br label %60
57: ; preds = %88, %44
%58 = phi i32 [ %45, %44 ], [ %90, %88 ]
%59 = icmp sgt i32 %58, -2
br i1 %59, label %96, label %104
60: ; preds = %55, %81
%61 = phi i64 [ 1, %55 ], [ %82, %81 ]
%62 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %7)
%63 = load i32, i32* %7
%64 = load i32, i32* @EOF
%65 = icmp eq i32 %63, %64
br i1 %65, label %66, label %69
66: ; preds = %60
%67 = call i32 @fclose(i32* %12)
%68 = call i32 @errhandler(i32 478, i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
br label %81
69: ; preds = %60
%70 = getelementptr inbounds i32*, i32** %40, i64 %61
%71 = load i32*, i32** %70
%72 = load i32, i32* %5
%73 = add i32 %56, %72
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %71, i64 %74
store i32 %63, i32* %75
%76 = load i32, i32* %5
%77 = add i32 %56, %76
%78 = load i32, i32* %7
%79 = trunc i64 %61 to i32
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i32 %79, i32 %77, i32 %78)
br label %81
81: ; preds = %69, %66
%82 = add nuw nsw i64 %61, 1
%83 = load i32, i32* %4
%84 = sext i32 %83 to i64
%85 = icmp slt i64 %61, %84
br i1 %85, label %60, label %86
86: ; preds = %81
%87 = load i32, i32* %5
br label %88
88: ; preds = %86, %49
%89 = phi i32 [ %87, %86 ], [ %50, %49 ]
%90 = phi i32 [ %83, %86 ], [ %51, %49 ]
%91 = add nuw nsw i32 %53, 1
%92 = xor i32 %53, -1
%93 = icmp slt i32 %53, %89
br i1 %93, label %49, label %57
94: ; preds = %96
%95 = icmp sgt i32 %101, -2
br i1 %95, label %109, label %104
96: ; preds = %57, %96
%97 = phi i64 [ %100, %96 ], [ 0, %57 ]
%98 = getelementptr inbounds i32*, i32** %40, i64 %97
%99 = load i32*, i32** %98
store i32 0, i32* %99
%100 = add nuw nsw i64 %97, 1
%101 = load i32, i32* %4
%102 = sext i32 %101 to i64
%103 = icmp sgt i64 %97, %102
br i1 %103, label %94, label %96
104: ; preds = %109, %57, %94
%105 = load i32, i32* %5
%106 = icmp sgt i32 %105, -2
br i1 %106, label %107, label %134
107: ; preds = %104
%108 = load i32*, i32** %40
br label %121
109: ; preds = %94, %109
%110 = phi i64 [ %117, %109 ], [ 0, %94 ]
%111 = getelementptr inbounds i32*, i32** %40, i64 %110
%112 = load i32*, i32** %111
%113 = load i32, i32* %5
%114 = add nsw i32 %113, 1
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds i32, i32* %112, i64 %115
store i32 0, i32* %116
%117 = add nuw nsw i64 %110, 1
%118 = load i32, i32* %4
%119 = sext i32 %118 to i64
%120 = icmp sgt i64 %110, %119
br i1 %120, label %104, label %109
121: ; preds = %107, %121
%122 = phi i64 [ 0, %107 ], [ %130, %121 ]
%123 = getelementptr inbounds i32, i32* %108, i64 %122
store i32 0, i32* %123
%124 = load i32, i32* %4
%125 = add nsw i32 %124, 1
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds i32*, i32** %40, i64 %126
%128 = load i32*, i32** %127
%129 = getelementptr inbounds i32, i32* %128, i64 %122
store i32 0, i32* %129
%130 = add nuw nsw i64 %122, 1
%131 = load i32, i32* %5
%132 = sext i32 %131 to i64
%133 = icmp sgt i64 %122, %132
br i1 %133, label %134, label %121
134: ; preds = %121, %104
%135 = call i32 @fclose(i32* %12)
ret i32** %40
}