#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/worksheet3/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/worksheet3/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/worksheet3/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    $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    0xdcb(%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    1440 <read_pgm+0x2a0>
movl   $0x1,-0x420(%rbp)
mov    -0x420(%rbp),%eax
mov    -0x418(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1427 <read_pgm+0x287>
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    140e <read_pgm+0x26e>
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)
jmp    1413 <read_pgm+0x273>
mov    -0x420(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x420(%rbp)
jmp    1369 <read_pgm+0x1c9>
jmp    142c <read_pgm+0x28c>
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    148d <read_pgm+0x2ed>
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    144a <read_pgm+0x2aa>
movl   $0x0,-0x420(%rbp)
mov    -0x420(%rbp),%eax
mov    -0x418(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    14e7 <read_pgm+0x347>
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    1497 <read_pgm+0x2f7>
movl   $0x0,-0x424(%rbp)
mov    -0x424(%rbp),%eax
mov    -0x41c(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jge    1559 <read_pgm+0x3b9>
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    14f1 <read_pgm+0x351>
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    0xe35(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1203 <read_pgm+0x53>
lea    0xe24(%rip),%rsi
lea    0x30(%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    0x30(%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    0x30(%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,0x30(%rsp)
je     1250 <read_pgm+0xa0>
lea    0xe5a(%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    0xc(%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    0xe17(%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    0xe0d(%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    0xddd(%rip),%r15
lea    0x14(%rsp),%r12
mov    0x2cd5(%rip),%rbp
jmp    1336 <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    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    $0x1e4,%edi
lea    0xc7c(%rip),%rsi
lea    0xd40(%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 = [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/worksheet3/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) {
%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 = %106, %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 %109
69: ; preds = %64
store i32 1, i32* %8
br label %70
70: ; preds = %102, %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 %105
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 %101
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
br label %101
101: ; preds = %88, %84
br label %102
102: ; preds = %101
%103 = load i32, i32* %8
%104 = add nsw i32 %103, 1
store i32 %104, i32* %8
br label %70
105: ; preds = %70
br label %106
106: ; preds = %105
%107 = load i32, i32* %9
%108 = add nsw i32 %107, 1
store i32 %108, i32* %9
br label %64
109: ; preds = %64
store i32 0, i32* %8
br label %110
110: ; preds = %122, %109
%111 = load i32, i32* %8
%112 = load i32, i32* %6
%113 = add nsw i32 %112, 2
%114 = icmp slt i32 %111, %113
br i1 %114, label %115, label %125
115: ; preds = %110
%116 = load i32**, i32*** %10
%117 = load i32, i32* %8
%118 = sext i32 %117 to i64
%119 = getelementptr inbounds i32*, i32** %116, i64 %118
%120 = load i32*, i32** %119
%121 = getelementptr inbounds i32, i32* %120, i64 0
store i32 0, i32* %121
br label %122
122: ; preds = %115
%123 = load i32, i32* %8
%124 = add nsw i32 %123, 1
store i32 %124, i32* %8
br label %110
125: ; preds = %110
store i32 0, i32* %8
br label %126
126: ; preds = %141, %125
%127 = load i32, i32* %8
%128 = load i32, i32* %6
%129 = add nsw i32 %128, 2
%130 = icmp slt i32 %127, %129
br i1 %130, label %131, label %144
131: ; preds = %126
%132 = load i32**, i32*** %10
%133 = load i32, i32* %8
%134 = sext i32 %133 to i64
%135 = getelementptr inbounds i32*, i32** %132, i64 %134
%136 = load i32*, i32** %135
%137 = load i32, i32* %7
%138 = add nsw i32 %137, 1
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds i32, i32* %136, i64 %139
store i32 0, i32* %140
br label %141
141: ; preds = %131
%142 = load i32, i32* %8
%143 = add nsw i32 %142, 1
store i32 %143, i32* %8
br label %126
144: ; preds = %126
store i32 0, i32* %9
br label %145
145: ; preds = %166, %144
%146 = load i32, i32* %9
%147 = load i32, i32* %7
%148 = add nsw i32 %147, 2
%149 = icmp slt i32 %146, %148
br i1 %149, label %150, label %169
150: ; preds = %145
%151 = load i32**, i32*** %10
%152 = getelementptr inbounds i32*, i32** %151, i64 0
%153 = load i32*, i32** %152
%154 = load i32, i32* %9
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds i32, i32* %153, i64 %155
store i32 0, i32* %156
%157 = load i32**, i32*** %10
%158 = load i32, i32* %6
%159 = add nsw i32 %158, 1
%160 = sext i32 %159 to i64
%161 = getelementptr inbounds i32*, i32** %157, i64 %160
%162 = load i32*, i32** %161
%163 = load i32, i32* %9
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds i32, i32* %162, i64 %164
store i32 0, i32* %165
br label %166
166: ; preds = %150
%167 = load i32, i32* %9
%168 = add nsw i32 %167, 1
store i32 %168, i32* %9
br label %145
169: ; preds = %145
%170 = load i32*, i32** %3
%171 = call i32 @fclose(i32* %170)
%172 = load i32**, i32*** %10
ret i32** %172
}

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/worksheet3/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) {
%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 %56
46: ; preds = %29
%47 = bitcast i32* %7 to i8*
%48 = load i32, i32* %4
br label %49
49: ; preds = %46, %82
%50 = phi i32 [ %42, %46 ], [ %83, %82 ]
%51 = phi i32 [ %48, %46 ], [ %84, %82 ]
%52 = phi i32 [ 1, %46 ], [ %85, %82 ]
%53 = icmp slt i32 %51, 1
br i1 %53, label %82, label %54
54: ; preds = %49
%55 = sub nsw i32 1, %52
br label %59
56: ; preds = %82, %44
%57 = phi i32 [ %45, %44 ], [ %84, %82 ]
%58 = icmp sgt i32 %57, -2
br i1 %58, label %89, label %97
59: ; preds = %54, %75
%60 = phi i64 [ 1, %54 ], [ %76, %75 ]
%61 = call i64 @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 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 %75
68: ; preds = %59
%69 = getelementptr inbounds i32*, i32** %40, i64 %60
%70 = load i32*, i32** %69
%71 = load i32, i32* %5
%72 = add i32 %55, %71
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i32, i32* %70, i64 %73
store i32 %62, i32* %74
br label %75
75: ; preds = %68, %65
%76 = add nuw nsw i64 %60, 1
%77 = load i32, i32* %4
%78 = sext i32 %77 to i64
%79 = icmp slt i64 %60, %78
br i1 %79, label %59, label %80
80: ; preds = %75
%81 = load i32, i32* %5
br label %82
82: ; preds = %80, %49
%83 = phi i32 [ %81, %80 ], [ %50, %49 ]
%84 = phi i32 [ %77, %80 ], [ %51, %49 ]
%85 = add nuw nsw i32 %52, 1
%86 = icmp slt i32 %52, %83
br i1 %86, label %49, label %56
87: ; preds = %89
%88 = icmp sgt i32 %94, -2
br i1 %88, label %102, label %97
89: ; preds = %56, %89
%90 = phi i64 [ %93, %89 ], [ 0, %56 ]
%91 = getelementptr inbounds i32*, i32** %40, i64 %90
%92 = load i32*, i32** %91
store i32 0, i32* %92
%93 = add nuw nsw i64 %90, 1
%94 = load i32, i32* %4
%95 = sext i32 %94 to i64
%96 = icmp sgt i64 %90, %95
br i1 %96, label %87, label %89
97: ; preds = %102, %56, %87
%98 = load i32, i32* %5
%99 = icmp sgt i32 %98, -2
br i1 %99, label %100, label %127
100: ; preds = %97
%101 = load i32*, i32** %40
br label %114
102: ; preds = %87, %102
%103 = phi i64 [ %110, %102 ], [ 0, %87 ]
%104 = getelementptr inbounds i32*, i32** %40, i64 %103
%105 = load i32*, i32** %104
%106 = load i32, i32* %5
%107 = add nsw i32 %106, 1
%108 = sext i32 %107 to i64
%109 = getelementptr inbounds i32, i32* %105, i64 %108
store i32 0, i32* %109
%110 = add nuw nsw i64 %103, 1
%111 = load i32, i32* %4
%112 = sext i32 %111 to i64
%113 = icmp sgt i64 %103, %112
br i1 %113, label %97, label %102
114: ; preds = %100, %114
%115 = phi i64 [ 0, %100 ], [ %123, %114 ]
%116 = getelementptr inbounds i32, i32* %101, i64 %115
store i32 0, i32* %116
%117 = load i32, i32* %4
%118 = add nsw i32 %117, 1
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds i32*, i32** %40, i64 %119
%121 = load i32*, i32** %120
%122 = getelementptr inbounds i32, i32* %121, i64 %115
store i32 0, i32* %122
%123 = add nuw nsw i64 %115, 1
%124 = load i32, i32* %5
%125 = sext i32 %124 to i64
%126 = icmp sgt i64 %115, %125
br i1 %126, label %127, label %114
127: ; preds = %114, %97
%128 = call i32 @fclose(i32* %12)
ret i32** %40
}