#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, int *xlength, int *ylength) {
  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/nyxcalamity/classwork/refs/"
               "heads/master/tum/computational-fluid-dynamics/ws3/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/nyxcalamity/classwork/refs/"
               "heads/master/tum/computational-fluid-dynamics/ws3/helper.c",
               "Error Wrong Magic field!");
  }
  do
    if (fgets(line, sizeof line, input))
      ;
  while (*line == '#');
  sscanf(line, "%d %d\n", &xsize, &ysize);
  *xlength = xsize;
  *ylength = 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(
            482,
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/nyxcalamity/classwork/refs/heads/master/"
            "tum/computational-fluid-dynamics/ws3/helper.c",
            "read failed");
      } else {
        pic[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    $0x4a0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x440(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe2b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1217 <read_pgm+0x77>
lea    -0x490(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe09(%rip),%rsi
call   10c0 <sprintf@plt>
lea    -0x490(%rbp),%rdx
mov    $0x1b7,%edi
lea    0xe0a(%rip),%rsi
call   1050 <errhandler@plt>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3,%edx
call   1040 <fread@plt>
cmp    $0x3,%eax
je     125b <read_pgm+0xbb>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1be,%edi
lea    0xdcd(%rip),%rsi
lea    0xe76(%rip),%rdx
call   1050 <errhandler@plt>
jmp    1260 <read_pgm+0xc0>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     1284 <read_pgm+0xe4>
jmp    1284 <read_pgm+0xe4>
jmp    1289 <read_pgm+0xe9>
movsbl -0x420(%rbp),%eax
cmp    $0x23,%eax
je     1260 <read_pgm+0xc0>
lea    -0x420(%rbp),%rdi
lea    0xe3e(%rip),%rsi
lea    -0x428(%rbp),%rdx
lea    -0x42c(%rbp),%rcx
mov    $0x0,%al
call   10a0 <sscanf@plt>
mov    -0x428(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x42c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x428(%rbp),%esi
mov    -0x42c(%rbp),%edx
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     1312 <read_pgm+0x172>
jmp    1312 <read_pgm+0x172>
lea    -0x420(%rbp),%rdi
lea    0xdc8(%rip),%rsi
lea    -0x424(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
mov    -0x428(%rbp),%esi
add    $0x2,%esi
mov    -0x42c(%rbp),%ecx
add    $0x2,%ecx
xor    %edx,%edx
mov    %edx,%edi
call   1030 <imatrix@plt>
mov    %rax,-0x440(%rbp)
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x434(%rbp)
mov    -0x434(%rbp),%eax
mov    -0x42c(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1460 <read_pgm+0x2c0>
movl   $0x1,-0x430(%rbp)
mov    -0x430(%rbp),%eax
mov    -0x428(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1447 <read_pgm+0x2a7>
mov    -0x20(%rbp),%rdi
lea    0xd6c(%rip),%rsi
lea    -0x494(%rbp),%rdx
call   1080 <fscanf@plt>
cmp    $0x0,%rax
je     13c6 <read_pgm+0x226>
jmp    13c6 <read_pgm+0x226>
mov    -0x494(%rbp),%eax
mov    0x2c15(%rip),%rcx
cmp    (%rcx),%eax
jne    1401 <read_pgm+0x261>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1e2,%edi
lea    0xc2c(%rip),%rsi
lea    0xd23(%rip),%rdx
call   1050 <errhandler@plt>
jmp    142e <read_pgm+0x28e>
mov    -0x494(%rbp),%edx
mov    -0x440(%rbp),%rax
movslq -0x430(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x42c(%rbp),%ecx
add    $0x1,%ecx
sub    -0x434(%rbp),%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1433 <read_pgm+0x293>
mov    -0x430(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x430(%rbp)
jmp    1389 <read_pgm+0x1e9>
jmp    144c <read_pgm+0x2ac>
mov    -0x434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x434(%rbp)
jmp    1368 <read_pgm+0x1c8>
movl   $0x0,-0x430(%rbp)
mov    -0x430(%rbp),%eax
mov    -0x428(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    14ad <read_pgm+0x30d>
mov    -0x440(%rbp),%rax
movslq -0x430(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movl   $0x0,(%rax)
mov    -0x430(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x430(%rbp)
jmp    146a <read_pgm+0x2ca>
movl   $0x0,-0x430(%rbp)
mov    -0x430(%rbp),%eax
mov    -0x428(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    1507 <read_pgm+0x367>
mov    -0x440(%rbp),%rax
movslq -0x430(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x42c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x430(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x430(%rbp)
jmp    14b7 <read_pgm+0x317>
movl   $0x0,-0x434(%rbp)
mov    -0x434(%rbp),%eax
mov    -0x42c(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    1579 <read_pgm+0x3d9>
mov    -0x440(%rbp),%rax
mov    (%rax),%rax
movslq -0x434(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x440(%rbp),%rax
mov    -0x428(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x434(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x434(%rbp)
jmp    1511 <read_pgm+0x371>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x440(%rbp),%rax
add    $0x4a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pgm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0xe2f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1209 <read_pgm+0x59>
lea    0xe1e(%rip),%rsi
lea    0x30(%rsp),%r12
mov    %r12,%rdi
mov    %rbp,%rdx
call   10d0 <sprintf@plt>
lea    0xe20(%rip),%rsi
mov    $0x1b7,%edi
mov    %r12,%rdx
call   1060 <errhandler@plt>
lea    0x30(%rsp),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    $0x3,%eax
je     1245 <read_pgm+0x95>
mov    %rbx,%rdi
call   1070 <fclose@plt>
lea    0xde8(%rip),%rsi
lea    0xe91(%rip),%rdx
mov    $0x1be,%edi
call   1060 <errhandler@plt>
lea    0x30(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   10a0 <fgets@plt>
cmpb   $0x23,0x30(%rsp)
je     1250 <read_pgm+0xa0>
lea    0xe77(%rip),%rsi
lea    0x30(%rsp),%rbp
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbp,%rdi
xor    %eax,%eax
call   10b0 <sscanf@plt>
mov    0x10(%rsp),%esi
mov    %esi,(%r15)
mov    0xc(%rsp),%edx
mov    %edx,(%r14)
lea    0xe50(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   10a0 <fgets@plt>
lea    0xe2e(%rip),%rsi
lea    0x2c(%rsp),%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   10b0 <sscanf@plt>
mov    0x10(%rsp),%esi
add    $0x2,%esi
mov    0xc(%rsp),%ecx
add    $0x2,%ecx
xor    %edi,%edi
xor    %edx,%edx
call   1030 <imatrix@plt>
mov    %rax,0x18(%rsp)
lea    0xe24(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
jle    13ae <read_pgm+0x1fe>
mov    $0x1,%esi
mov    0x10(%rsp),%eax
lea    0xdf4(%rip),%r15
lea    0x14(%rsp),%r12
mov    0x2ccf(%rip),%rbp
jmp    1336 <read_pgm+0x186>
nopl   0x0(%rax,%rax,1)
mov    0xc(%rsp),%ecx
mov    0x20(%rsp),%rsi
lea    0x1(%rsi),%edx
cmp    %ecx,%esi
mov    %edx,%esi
jge    13b2 <read_pgm+0x202>
test   %eax,%eax
jle    1329 <read_pgm+0x179>
mov    $0x1,%r13d
mov    %rsi,0x20(%rsp)
sub    %esi,%r13d
xor    %r14d,%r14d
jmp    1375 <read_pgm+0x1c5>
nopl   (%rax)
mov    0x18(%rsp),%rcx
mov    0x8(%rcx,%r14,8),%rcx
mov    0xc(%rsp),%edx
add    %r13d,%edx
movslq %edx,%rdx
mov    %eax,(%rcx,%rdx,4)
movslq 0x10(%rsp),%rax
add    $0x1,%r14
cmp    %rax,%r14
jge    1320 <read_pgm+0x170>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1090 <fscanf@plt>
mov    0x14(%rsp),%eax
cmp    0x0(%rbp),%eax
jne    1350 <read_pgm+0x1a0>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    $0x1e2,%edi
lea    0xc7c(%rip),%rsi
lea    0xd5d(%rip),%rdx
call   1060 <errhandler@plt>
jmp    1367 <read_pgm+0x1b7>
mov    0x10(%rsp),%eax
cmp    $0xffffffff,%eax
mov    0x18(%rsp),%rbp
jl     1420 <read_pgm+0x270>
mov    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x8(%rbp,%rax,8),%rcx
movl   $0x0,(%rcx)
movslq 0x10(%rsp),%rcx
add    $0x1,%rax
cmp    %rcx,%rax
jle    13d0 <read_pgm+0x220>
cmp    $0xffffffff,%ecx
jl     1420 <read_pgm+0x270>
mov    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%rbp,%rax,8),%rcx
movslq 0xc(%rsp),%rdx
movl   $0x0,0x4(%rcx,%rdx,4)
movslq 0x10(%rsp),%rcx
add    $0x1,%rax
cmp    %rcx,%rax
jle    1400 <read_pgm+0x250>
cmpl   $0xffffffff,0xc(%rsp)
jl     1468 <read_pgm+0x2b8>
mov    0x0(%rbp),%rax
mov    $0xffffffffffffffff,%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movl   $0x0,0x4(%rax,%rcx,4)
movslq 0x10(%rsp),%rdx
mov    0x8(%rbp,%rdx,8),%rdx
movl   $0x0,0x4(%rdx,%rcx,4)
movslq 0xc(%rsp),%rdx
add    $0x1,%rcx
cmp    %rdx,%rcx
jle    1440 <read_pgm+0x290>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    %rbp,%rax
add    $0x438,%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 = [176 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/nyxcalamity/classwork/refs/heads/master/tum/computational-fluid-dynamics/ws3/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"
define i32** @read_pgm(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32**
%15 = alloca [80 x i8]
%16 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
store i32* null, i32** %7
store i32** null, i32*** %14
%17 = load i8*, i8** %4
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %7
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %26
20: ; preds = %3
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %15, i64 0, i64 0
%22 = load i8*, i8** %4
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %15, i64 0, i64 0
%25 = call i32 @errhandler(i32 439, i8* getelementptr inbounds ([176 x i8], [176 x i8]* @.str.2, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %20, %3
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%28 = load i32*, i32** %7
%29 = call i32 @fread(i8* %27, i32 1, i32 3, i32* %28)
%30 = icmp ne i32 %29, 3
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = load i32*, i32** %7
%33 = call i32 @fclose(i32* %32)
%34 = call i32 @errhandler(i32 446, i8* getelementptr inbounds ([176 x i8], [176 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 %35
35: ; preds = %31, %26
br label %36
36: ; preds = %43, %35
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%38 = load i32*, i32** %7
%39 = call i64 @fgets(i8* %37, i32 1024, i32* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %36
br label %42
42: ; preds = %41, %36
br label %43
43: ; preds = %42
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 35
br i1 %47, label %36, label %48
48: ; preds = %43
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%50 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %49, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %10, i32* %11)
%51 = load i32, i32* %10
%52 = load i32*, i32** %5
store i32 %51, i32* %52
%53 = load i32, i32* %11
%54 = load i32*, i32** %6
store i32 %53, i32* %54
%55 = load i32, i32* %10
%56 = load i32, i32* %11
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0), i32 %55, i32 %56)
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%59 = load i32*, i32** %7
%60 = call i64 @fgets(i8* %58, i32 1024, i32* %59)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %48
br label %63
63: ; preds = %62, %48
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%65 = call i32 (i8*, i8*, i32*, ...) @sscanf(i8* %64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32* %9)
%66 = load i32, i32* %10
%67 = add nsw i32 %66, 2
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 2
%70 = call i32** @imatrix(i32 0, i32 %67, i32 0, i32 %69)
store i32** %70, i32*** %14
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %13
br label %72
72: ; preds = %114, %63
%73 = load i32, i32* %13
%74 = load i32, i32* %11
%75 = add nsw i32 %74, 1
%76 = icmp slt i32 %73, %75
br i1 %76, label %77, label %117
77: ; preds = %72
store i32 1, i32* %12
br label %78
78: ; preds = %110, %77
%79 = load i32, i32* %12
%80 = load i32, i32* %10
%81 = add nsw i32 %80, 1
%82 = icmp slt i32 %79, %81
br i1 %82, label %83, label %113
83: ; preds = %78
%84 = load i32*, i32** %7
%85 = call i64 @fscanf(i32* %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %16)
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %88
87: ; preds = %83
br label %88
88: ; preds = %87, %83
%89 = load i32, i32* %16
%90 = load i32, i32* @EOF
%91 = icmp eq i32 %89, %90
br i1 %91, label %92, label %96
92: ; preds = %88
%93 = load i32*, i32** %7
%94 = call i32 @fclose(i32* %93)
%95 = call i32 @errhandler(i32 482, i8* getelementptr inbounds ([176 x i8], [176 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 %109
96: ; preds = %88
%97 = load i32, i32* %16
%98 = load i32**, i32*** %14
%99 = load i32, i32* %12
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i32*, i32** %98, i64 %100
%102 = load i32*, i32** %101
%103 = load i32, i32* %11
%104 = add nsw i32 %103, 1
%105 = load i32, i32* %13
%106 = sub nsw i32 %104, %105
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds i32, i32* %102, i64 %107
store i32 %97, i32* %108
br label %109
109: ; preds = %96, %92
br label %110
110: ; preds = %109
%111 = load i32, i32* %12
%112 = add nsw i32 %111, 1
store i32 %112, i32* %12
br label %78
113: ; preds = %78
br label %114
114: ; preds = %113
%115 = load i32, i32* %13
%116 = add nsw i32 %115, 1
store i32 %116, i32* %13
br label %72
117: ; preds = %72
store i32 0, i32* %12
br label %118
118: ; preds = %130, %117
%119 = load i32, i32* %12
%120 = load i32, i32* %10
%121 = add nsw i32 %120, 2
%122 = icmp slt i32 %119, %121
br i1 %122, label %123, label %133
123: ; preds = %118
%124 = load i32**, i32*** %14
%125 = load i32, i32* %12
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds i32*, i32** %124, i64 %126
%128 = load i32*, i32** %127
%129 = getelementptr inbounds i32, i32* %128, i64 0
store i32 0, i32* %129
br label %130
130: ; preds = %123
%131 = load i32, i32* %12
%132 = add nsw i32 %131, 1
store i32 %132, i32* %12
br label %118
133: ; preds = %118
store i32 0, i32* %12
br label %134
134: ; preds = %149, %133
%135 = load i32, i32* %12
%136 = load i32, i32* %10
%137 = add nsw i32 %136, 2
%138 = icmp slt i32 %135, %137
br i1 %138, label %139, label %152
139: ; preds = %134
%140 = load i32**, i32*** %14
%141 = load i32, i32* %12
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds i32*, i32** %140, i64 %142
%144 = load i32*, i32** %143
%145 = load i32, i32* %11
%146 = add nsw i32 %145, 1
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds i32, i32* %144, i64 %147
store i32 0, i32* %148
br label %149
149: ; preds = %139
%150 = load i32, i32* %12
%151 = add nsw i32 %150, 1
store i32 %151, i32* %12
br label %134
152: ; preds = %134
store i32 0, i32* %13
br label %153
153: ; preds = %174, %152
%154 = load i32, i32* %13
%155 = load i32, i32* %11
%156 = add nsw i32 %155, 2
%157 = icmp slt i32 %154, %156
br i1 %157, label %158, label %177
158: ; preds = %153
%159 = load i32**, i32*** %14
%160 = getelementptr inbounds i32*, i32** %159, i64 0
%161 = load i32*, i32** %160
%162 = load i32, i32* %13
%163 = sext i32 %162 to i64
%164 = getelementptr inbounds i32, i32* %161, i64 %163
store i32 0, i32* %164
%165 = load i32**, i32*** %14
%166 = load i32, i32* %10
%167 = add nsw i32 %166, 1
%168 = sext i32 %167 to i64
%169 = getelementptr inbounds i32*, i32** %165, i64 %168
%170 = load i32*, i32** %169
%171 = load i32, i32* %13
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds i32, i32* %170, i64 %172
store i32 0, i32* %173
br label %174
174: ; preds = %158
%175 = load i32, i32* %13
%176 = add nsw i32 %175, 1
store i32 %176, i32* %13
br label %153
177: ; preds = %153
%178 = load i32*, i32** %7
%179 = call i32 @fclose(i32* %178)
%180 = load i32**, i32*** %14
ret i32** %180
}

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