#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 min(int, 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(454,
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/EvaBr/CFD-Lab/refs/heads/"
               "master/Worksheet3/helper.c",
               szBuff);
  }
  if (fread(line, 1, 3, input) != 3) {
    fclose(input);
    errhandler(461,
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/EvaBr/CFD-Lab/refs/heads/"
               "master/Worksheet3/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(493,
                   "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                   "outputs/2022-01-22/02-19-57/repos/EvaBr/CFD-Lab/refs/heads/"
                   "master/Worksheet3/helper.c",
                   "Read failed");
      } else {
        pic[i1][ysize + 1 - j1] = min(byte, 1);
      }
    }
  }
  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    0xe23(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    121f <read_pgm+0x6f>
lea    -0x480(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe01(%rip),%rsi
call   10d0 <sprintf@plt>
lea    -0x480(%rbp),%rdx
mov    $0x1c6,%edi
lea    0xdff(%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     1263 <read_pgm+0xb3>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1cd,%edi
lea    0xdc2(%rip),%rsi
lea    0xe49(%rip),%rdx
call   1050 <errhandler@plt>
jmp    1268 <read_pgm+0xb8>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   10a0 <fgets@plt>
movsbl -0x410(%rbp),%eax
cmp    $0x23,%eax
je     1268 <read_pgm+0xb8>
lea    -0x410(%rbp),%rdi
lea    0xe26(%rip),%rsi
lea    -0x418(%rbp),%rdx
lea    -0x41c(%rbp),%rcx
mov    $0x0,%al
call   10b0 <sscanf@plt>
mov    -0x418(%rbp),%esi
mov    -0x41c(%rbp),%edx
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   10a0 <fgets@plt>
lea    -0x410(%rbp),%rdi
lea    0xdd7(%rip),%rsi
lea    -0x414(%rbp),%rdx
mov    $0x0,%al
call   10b0 <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    0xdb9(%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    142a <read_pgm+0x27a>
movl   $0x1,-0x420(%rbp)
mov    -0x420(%rbp),%eax
mov    -0x418(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1411 <read_pgm+0x261>
mov    -0x10(%rbp),%rdi
lea    0xd7b(%rip),%rsi
lea    -0x484(%rbp),%rdx
call   1090 <fscanf@plt>
mov    -0x484(%rbp),%eax
mov    0x2c57(%rip),%rcx
cmp    (%rcx),%eax
jne    13bf <read_pgm+0x20f>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
mov    $0x1ed,%edi
lea    0xc6b(%rip),%rsi
lea    0xd41(%rip),%rdx
call   1050 <errhandler@plt>
jmp    13f8 <read_pgm+0x248>
mov    -0x484(%rbp),%edi
mov    $0x1,%esi
call   1080 <min@plt>
mov    %eax,%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)
jmp    13fd <read_pgm+0x24d>
mov    -0x420(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x420(%rbp)
jmp    1356 <read_pgm+0x1a6>
jmp    1416 <read_pgm+0x266>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
jmp    1335 <read_pgm+0x185>
movl   $0x0,-0x420(%rbp)
mov    -0x420(%rbp),%eax
mov    -0x418(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    1477 <read_pgm+0x2c7>
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    1434 <read_pgm+0x284>
movl   $0x0,-0x420(%rbp)
mov    -0x420(%rbp),%eax
mov    -0x418(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    14d1 <read_pgm+0x321>
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    1481 <read_pgm+0x2d1>
movl   $0x0,-0x424(%rbp)
mov    -0x424(%rbp),%eax
mov    -0x41c(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    1543 <read_pgm+0x393>
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    14db <read_pgm+0x32b>
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    $0x438,%rsp
mov    %rdi,%rbp
lea    0xe25(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1213 <read_pgm+0x53>
lea    0xe14(%rip),%rsi
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    %rbp,%rdx
call   10e0 <sprintf@plt>
lea    0xe13(%rip),%rsi
mov    $0x1c6,%edi
mov    %r14,%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     124f <read_pgm+0x8f>
mov    %rbx,%rdi
call   1070 <fclose@plt>
lea    0xddb(%rip),%rsi
lea    0xe62(%rip),%rdx
mov    $0x1cd,%edi
call   1060 <errhandler@plt>
lea    0x30(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   10b0 <fgets@plt>
cmpb   $0x23,0x30(%rsp)
je     1260 <read_pgm+0xa0>
lea    0xe43(%rip),%rsi
lea    0x30(%rsp),%rbp
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rbp,%rdi
xor    %eax,%eax
call   10c0 <sscanf@plt>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe22(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   10b0 <fgets@plt>
lea    0xe00(%rip),%rsi
lea    0x2c(%rsp),%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   10c0 <sscanf@plt>
mov    0x10(%rsp),%esi
add    $0x1,%esi
mov    0xc(%rsp),%ecx
add    $0x1,%ecx
xor    %edi,%edi
xor    %edx,%edx
call   1030 <imatrix@plt>
mov    %rax,0x18(%rsp)
lea    0xdf6(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
jle    13c8 <read_pgm+0x208>
mov    $0x1,%esi
mov    0x10(%rsp),%eax
lea    0xdc6(%rip),%r15
lea    0x14(%rsp),%r12
mov    0x2cc5(%rip),%rbp
jmp    1346 <read_pgm+0x186>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0xc(%rsp),%ecx
mov    0x20(%rsp),%rsi
lea    0x1(%rsi),%edx
cmp    %ecx,%esi
mov    %edx,%esi
jge    13cc <read_pgm+0x20c>
test   %eax,%eax
jle    1339 <read_pgm+0x179>
mov    $0x1,%r13d
mov    %rsi,0x20(%rsp)
sub    %esi,%r13d
xor    %r14d,%r14d
jmp    138f <read_pgm+0x1cf>
nopl   (%rax)
mov    $0x1,%esi
call   1090 <min@plt>
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    1330 <read_pgm+0x170>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   10a0 <fscanf@plt>
mov    0x14(%rsp),%edi
cmp    0x0(%rbp),%edi
jne    1360 <read_pgm+0x1a0>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    $0x1ed,%edi
lea    0xc5f(%rip),%rsi
lea    0xd1f(%rip),%rdx
call   1060 <errhandler@plt>
jmp    1381 <read_pgm+0x1c1>
mov    0x10(%rsp),%eax
cmp    $0xffffffff,%eax
mov    0x18(%rsp),%rbp
jl     1430 <read_pgm+0x270>
mov    $0xffffffffffffffff,%rax
nopl   (%rax)
mov    0x8(%rbp,%rax,8),%rcx
movl   $0x0,(%rcx)
movslq 0x10(%rsp),%rcx
add    $0x1,%rax
cmp    %rcx,%rax
jle    13e0 <read_pgm+0x220>
cmp    $0xffffffff,%ecx
jl     1430 <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    1410 <read_pgm+0x250>
cmpl   $0xffffffff,0xc(%rsp)
jl     1478 <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    1450 <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 = [22 x i8] c"Can not read file %s!\00"
@.str.2 = [142 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/EvaBr/CFD-Lab/refs/heads/master/Worksheet3/helper.c\00"
@.str.3 = [26 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) {
%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 ([22 x i8], [22 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 454, i8* getelementptr inbounds ([142 x i8], [142 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 461, i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 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 = %98, %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 %101
63: ; preds = %58
store i32 1, i32* %8
br label %64
64: ; preds = %94, %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 %97
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 493, i8* getelementptr inbounds ([142 x i8], [142 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 %93
79: ; preds = %69
%80 = load i32, i32* %12
%81 = call i32 @min(i32 %80, i32 1)
%82 = load i32**, i32*** %10
%83 = load i32, i32* %8
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i32*, i32** %82, i64 %84
%86 = load i32*, i32** %85
%87 = load i32, i32* %7
%88 = add nsw i32 %87, 1
%89 = load i32, i32* %9
%90 = sub nsw i32 %88, %89
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i32, i32* %86, i64 %91
store i32 %81, i32* %92
br label %93
93: ; preds = %79, %75
br label %94
94: ; preds = %93
%95 = load i32, i32* %8
%96 = add nsw i32 %95, 1
store i32 %96, i32* %8
br label %64
97: ; preds = %64
br label %98
98: ; preds = %97
%99 = load i32, i32* %9
%100 = add nsw i32 %99, 1
store i32 %100, i32* %9
br label %58
101: ; preds = %58
store i32 0, i32* %8
br label %102
102: ; preds = %114, %101
%103 = load i32, i32* %8
%104 = load i32, i32* %6
%105 = add nsw i32 %104, 2
%106 = icmp slt i32 %103, %105
br i1 %106, label %107, label %117
107: ; preds = %102
%108 = load i32**, i32*** %10
%109 = load i32, i32* %8
%110 = sext i32 %109 to i64
%111 = getelementptr inbounds i32*, i32** %108, i64 %110
%112 = load i32*, i32** %111
%113 = getelementptr inbounds i32, i32* %112, i64 0
store i32 0, i32* %113
br label %114
114: ; preds = %107
%115 = load i32, i32* %8
%116 = add nsw i32 %115, 1
store i32 %116, i32* %8
br label %102
117: ; preds = %102
store i32 0, i32* %8
br label %118
118: ; preds = %133, %117
%119 = load i32, i32* %8
%120 = load i32, i32* %6
%121 = add nsw i32 %120, 2
%122 = icmp slt i32 %119, %121
br i1 %122, label %123, label %136
123: ; preds = %118
%124 = load i32**, i32*** %10
%125 = load i32, i32* %8
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds i32*, i32** %124, i64 %126
%128 = load i32*, i32** %127
%129 = load i32, i32* %7
%130 = add nsw i32 %129, 1
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds i32, i32* %128, i64 %131
store i32 0, i32* %132
br label %133
133: ; preds = %123
%134 = load i32, i32* %8
%135 = add nsw i32 %134, 1
store i32 %135, i32* %8
br label %118
136: ; preds = %118
store i32 0, i32* %9
br label %137
137: ; preds = %158, %136
%138 = load i32, i32* %9
%139 = load i32, i32* %7
%140 = add nsw i32 %139, 2
%141 = icmp slt i32 %138, %140
br i1 %141, label %142, label %161
142: ; preds = %137
%143 = load i32**, i32*** %10
%144 = getelementptr inbounds i32*, i32** %143, i64 0
%145 = load i32*, i32** %144
%146 = load i32, i32* %9
%147 = sext i32 %146 to i64
%148 = getelementptr inbounds i32, i32* %145, i64 %147
store i32 0, i32* %148
%149 = load i32**, i32*** %10
%150 = load i32, i32* %6
%151 = add nsw i32 %150, 1
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds i32*, i32** %149, i64 %152
%154 = load i32*, i32** %153
%155 = load i32, i32* %9
%156 = sext i32 %155 to i64
%157 = getelementptr inbounds i32, i32* %154, i64 %156
store i32 0, i32* %157
br label %158
158: ; preds = %142
%159 = load i32, i32* %9
%160 = add nsw i32 %159, 1
store i32 %160, i32* %9
br label %137
161: ; preds = %137
%162 = load i32*, i32** %3
%163 = call i32 @fclose(i32* %162)
%164 = load i32**, i32*** %10
ret i32** %164
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [22 x i8] c"Can not read file %s!\00"
@.str.2 = [142 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/EvaBr/CFD-Lab/refs/heads/master/Worksheet3/helper.c\00"
@.str.3 = [26 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) {
%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 ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%17 = call i32 @errhandler(i32 454, i8* getelementptr inbounds ([142 x i8], [142 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 461, i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 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 %56
46: ; preds = %29
%47 = bitcast i32* %7 to i8*
%48 = load i32, i32* %4
br label %49
49: ; preds = %46, %83
%50 = phi i32 [ %42, %46 ], [ %84, %83 ]
%51 = phi i32 [ %48, %46 ], [ %85, %83 ]
%52 = phi i32 [ 1, %46 ], [ %86, %83 ]
%53 = icmp slt i32 %51, 1
br i1 %53, label %83, label %54
54: ; preds = %49
%55 = sub nsw i32 1, %52
br label %59
56: ; preds = %83, %44
%57 = phi i32 [ %45, %44 ], [ %85, %83 ]
%58 = icmp sgt i32 %57, -2
br i1 %58, label %90, label %98
59: ; preds = %54, %76
%60 = phi i64 [ 1, %54 ], [ %77, %76 ]
%61 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %7)
%62 = load i32, i32* %7
%63 = load i32, i32* @EOF
%64 = icmp eq i32 %62, %63
br i1 %64, label %65, label %68
65: ; preds = %59
%66 = call i32 @fclose(i32* %12)
%67 = call i32 @errhandler(i32 493, i8* getelementptr inbounds ([142 x i8], [142 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 %76
68: ; preds = %59
%69 = call i32 @min(i32 %62, i32 1)
%70 = getelementptr inbounds i32*, i32** %40, i64 %60
%71 = load i32*, i32** %70
%72 = load i32, i32* %5
%73 = add i32 %55, %72
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %71, i64 %74
store i32 %69, i32* %75
br label %76
76: ; preds = %68, %65
%77 = add nuw nsw i64 %60, 1
%78 = load i32, i32* %4
%79 = sext i32 %78 to i64
%80 = icmp slt i64 %60, %79
br i1 %80, label %59, label %81
81: ; preds = %76
%82 = load i32, i32* %5
br label %83
83: ; preds = %81, %49
%84 = phi i32 [ %82, %81 ], [ %50, %49 ]
%85 = phi i32 [ %78, %81 ], [ %51, %49 ]
%86 = add nuw nsw i32 %52, 1
%87 = icmp slt i32 %52, %84
br i1 %87, label %49, label %56
88: ; preds = %90
%89 = icmp sgt i32 %95, -2
br i1 %89, label %103, label %98
90: ; preds = %56, %90
%91 = phi i64 [ %94, %90 ], [ 0, %56 ]
%92 = getelementptr inbounds i32*, i32** %40, i64 %91
%93 = load i32*, i32** %92
store i32 0, i32* %93
%94 = add nuw nsw i64 %91, 1
%95 = load i32, i32* %4
%96 = sext i32 %95 to i64
%97 = icmp sgt i64 %91, %96
br i1 %97, label %88, label %90
98: ; preds = %103, %56, %88
%99 = load i32, i32* %5
%100 = icmp sgt i32 %99, -2
br i1 %100, label %101, label %128
101: ; preds = %98
%102 = load i32*, i32** %40
br label %115
103: ; preds = %88, %103
%104 = phi i64 [ %111, %103 ], [ 0, %88 ]
%105 = getelementptr inbounds i32*, i32** %40, i64 %104
%106 = load i32*, i32** %105
%107 = load i32, i32* %5
%108 = add nsw i32 %107, 1
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds i32, i32* %106, i64 %109
store i32 0, i32* %110
%111 = add nuw nsw i64 %104, 1
%112 = load i32, i32* %4
%113 = sext i32 %112 to i64
%114 = icmp sgt i64 %104, %113
br i1 %114, label %98, label %103
115: ; preds = %101, %115
%116 = phi i64 [ 0, %101 ], [ %124, %115 ]
%117 = getelementptr inbounds i32, i32* %102, i64 %116
store i32 0, i32* %117
%118 = load i32, i32* %4
%119 = add nsw i32 %118, 1
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds i32*, i32** %40, i64 %120
%122 = load i32*, i32** %121
%123 = getelementptr inbounds i32, i32* %122, i64 %116
store i32 0, i32* %123
%124 = add nuw nsw i64 %116, 1
%125 = load i32, i32* %5
%126 = sext i32 %125 to i64
%127 = icmp sgt i64 %116, %126
br i1 %127, label %128, label %115
128: ; preds = %115, %98
%129 = call i32 @fclose(i32* %12)
ret i32** %40
}