#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*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
scalar_t__ 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(441,
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/nathanwbrei/cfdlab/refs/"
               "heads/master/worksheet2/helper.c",
               szBuff);
  }
  if (fread(line, 1, 3, input) != 3) {
    fclose(input);
    errhandler(448,
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/nathanwbrei/cfdlab/refs/"
               "heads/master/worksheet2/helper.c",
               "Error Wrong Magic field!");
  }
  do
    if (fgets(line, sizeof line, input))
      ;
  while (*line == '#');
  sscanf(line, "%d %d\n", &xsize, &ysize);
  printf("Image size: %d x %d\n", xsize, ysize);
  if (fgets(line, sizeof line, input))
    ;
  sscanf(line, "%d\n", &levels);
  pic = imatrix(0, xsize + 2, 0, ysize + 2);
  printf("Image initialised...\n");
  for (j1 = 1; j1 < ysize + 1; j1++) {
    for (i1 = 1; i1 < xsize + 1; i1++) {
      int byte;
      if (fscanf(input, "%d", &byte))
        ;
      if (byte == EOF) {
        fclose(input);
        errhandler(484,
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/nathanwbrei/cfdlab/refs/"
                   "heads/master/worksheet2/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    $0x1b9,%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    $0x1c0,%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>
cmp    $0x0,%rax
je     127c <read_pgm+0xdc>
jmp    127c <read_pgm+0xdc>
jmp    1281 <read_pgm+0xe1>
movsbl -0x410(%rbp),%eax
cmp    $0x23,%eax
je     1258 <read_pgm+0xb8>
lea    -0x410(%rbp),%rdi
lea    0xe29(%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    0xe08(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     12f2 <read_pgm+0x152>
jmp    12f2 <read_pgm+0x152>
lea    -0x410(%rbp),%rdi
lea    0xe10(%rip),%rsi
lea    -0x414(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
mov    -0x418(%rbp),%esi
add    $0x2,%esi
mov    -0x41c(%rbp),%ecx
add    $0x2,%ecx
xor    %edx,%edx
mov    %edx,%edi
call   1030 <imatrix@plt>
mov    %rax,-0x430(%rbp)
lea    0xdad(%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    1469 <read_pgm+0x2c9>
movl   $0x1,-0x420(%rbp)
mov    -0x420(%rbp),%eax
mov    -0x418(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1450 <read_pgm+0x2b0>
mov    -0x10(%rbp),%rdi
lea    0xd6f(%rip),%rsi
lea    -0x484(%rbp),%rdx
call   1080 <fscanf@plt>
cmp    $0x0,%rax
je     13a6 <read_pgm+0x206>
jmp    13a6 <read_pgm+0x206>
mov    -0x484(%rbp),%eax
mov    0x2c35(%rip),%rcx
cmp    (%rcx),%eax
jne    13e1 <read_pgm+0x241>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1e4,%edi
lea    0xc4c(%rip),%rsi
lea    0xd26(%rip),%rdx
call   1050 <errhandler@plt>
jmp    1437 <read_pgm+0x297>
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    0xcd9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    143c <read_pgm+0x29c>
mov    -0x420(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x420(%rbp)
jmp    1369 <read_pgm+0x1c9>
jmp    1455 <read_pgm+0x2b5>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    1348 <read_pgm+0x1a8>
movl   $0x0,-0x420(%rbp)
mov    -0x420(%rbp),%eax
mov    -0x418(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    14b6 <read_pgm+0x316>
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    1473 <read_pgm+0x2d3>
movl   $0x0,-0x420(%rbp)
mov    -0x420(%rbp),%eax
mov    -0x418(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    1510 <read_pgm+0x370>
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    14c0 <read_pgm+0x320>
movl   $0x0,-0x424(%rbp)
mov    -0x424(%rbp),%eax
mov    -0x41c(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    1582 <read_pgm+0x3e2>
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    151a <read_pgm+0x37a>
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    $0x1b9,%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    $0x1c0,%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    $0x2,%esi
mov    0x4(%rsp),%ecx
add    $0x2,%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    $0x1e4,%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/worksheet2/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 441, 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 448, 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 = %39, %31
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%34 = load i32*, i32** %3
%35 = call i64 @fgets(i8* %33, i32 1024, i32* %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
br label %38
38: ; preds = %37, %32
br label %39
39: ; preds = %38
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 35
br i1 %43, label %32, label %44
44: ; preds = %39
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%46 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %45, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %6, i32* %7)
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %47, i32 %48)
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%51 = load i32*, i32** %3
%52 = call i64 @fgets(i8* %50, i32 1024, i32* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %44
br label %55
55: ; preds = %54, %44
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%57 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %56, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32* %5)
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 2
%60 = load i32, i32* %7
%61 = add nsw i32 %60, 2
%62 = call i32** @imatrix(i32 0, i32 %59, i32 0, i32 %61)
store i32** %62, i32*** %10
%63 = 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 %64
64: ; preds = %113, %55
%65 = load i32, i32* %9
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
%68 = icmp slt i32 %65, %67
br i1 %68, label %69, label %116
69: ; preds = %64
store i32 1, i32* %8
br label %70
70: ; preds = %109, %69
%71 = load i32, i32* %8
%72 = load i32, i32* %6
%73 = add nsw i32 %72, 1
%74 = icmp slt i32 %71, %73
br i1 %74, label %75, label %112
75: ; preds = %70
%76 = load i32*, i32** %3
%77 = call i64 @fscanf(i32* %76, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %12)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %80
79: ; preds = %75
br label %80
80: ; preds = %79, %75
%81 = load i32, i32* %12
%82 = load i32, i32* @EOF
%83 = icmp eq i32 %81, %82
br i1 %83, label %84, label %88
84: ; preds = %80
%85 = load i32*, i32** %3
%86 = call i32 @fclose(i32* %85)
%87 = call i32 @errhandler(i32 484, 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 %108
88: ; preds = %80
%89 = load i32, i32* %12
%90 = load i32**, i32*** %10
%91 = load i32, i32* %8
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i32*, i32** %90, i64 %92
%94 = load i32*, i32** %93
%95 = load i32, i32* %7
%96 = add nsw i32 %95, 1
%97 = load i32, i32* %9
%98 = sub nsw i32 %96, %97
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds i32, i32* %94, i64 %99
store i32 %89, i32* %100
%101 = load i32, i32* %8
%102 = load i32, i32* %7
%103 = add nsw i32 %102, 1
%104 = load i32, i32* %9
%105 = sub nsw i32 %103, %104
%106 = load i32, i32* %12
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), i32 %101, i32 %105, i32 %106)
br label %108
108: ; preds = %88, %84
br label %109
109: ; preds = %108
%110 = load i32, i32* %8
%111 = add nsw i32 %110, 1
store i32 %111, i32* %8
br label %70
112: ; preds = %70
br label %113
113: ; preds = %112
%114 = load i32, i32* %9
%115 = add nsw i32 %114, 1
store i32 %115, i32* %9
br label %64
116: ; preds = %64
store i32 0, i32* %8
br label %117
117: ; preds = %129, %116
%118 = load i32, i32* %8
%119 = load i32, i32* %6
%120 = add nsw i32 %119, 2
%121 = icmp slt i32 %118, %120
br i1 %121, label %122, label %132
122: ; preds = %117
%123 = load i32**, i32*** %10
%124 = load i32, i32* %8
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds i32*, i32** %123, i64 %125
%127 = load i32*, i32** %126
%128 = getelementptr inbounds i32, i32* %127, i64 0
store i32 0, i32* %128
br label %129
129: ; preds = %122
%130 = load i32, i32* %8
%131 = add nsw i32 %130, 1
store i32 %131, i32* %8
br label %117
132: ; preds = %117
store i32 0, i32* %8
br label %133
133: ; preds = %148, %132
%134 = load i32, i32* %8
%135 = load i32, i32* %6
%136 = add nsw i32 %135, 2
%137 = icmp slt i32 %134, %136
br i1 %137, label %138, label %151
138: ; preds = %133
%139 = load i32**, i32*** %10
%140 = load i32, i32* %8
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds i32*, i32** %139, i64 %141
%143 = load i32*, i32** %142
%144 = load i32, i32* %7
%145 = add nsw i32 %144, 1
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds i32, i32* %143, i64 %146
store i32 0, i32* %147
br label %148
148: ; preds = %138
%149 = load i32, i32* %8
%150 = add nsw i32 %149, 1
store i32 %150, i32* %8
br label %133
151: ; preds = %133
store i32 0, i32* %9
br label %152
152: ; preds = %173, %151
%153 = load i32, i32* %9
%154 = load i32, i32* %7
%155 = add nsw i32 %154, 2
%156 = icmp slt i32 %153, %155
br i1 %156, label %157, label %176
157: ; preds = %152
%158 = load i32**, i32*** %10
%159 = getelementptr inbounds i32*, i32** %158, i64 0
%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
%164 = load i32**, i32*** %10
%165 = load i32, i32* %6
%166 = add nsw i32 %165, 1
%167 = sext i32 %166 to i64
%168 = getelementptr inbounds i32*, i32** %164, i64 %167
%169 = load i32*, i32** %168
%170 = load i32, i32* %9
%171 = sext i32 %170 to i64
%172 = getelementptr inbounds i32, i32* %169, i64 %171
store i32 0, i32* %172
br label %173
173: ; preds = %157
%174 = load i32, i32* %9
%175 = add nsw i32 %174, 1
store i32 %175, i32* %9
br label %152
176: ; preds = %152
%177 = load i32*, i32** %3
%178 = call i32 @fclose(i32* %177)
%179 = load i32**, i32*** %10
ret i32** %179
}

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/worksheet2/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 441, 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 448, 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 i64 @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 i64 @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, 2
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 2
%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 i64 @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 484, 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
}