#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 /*<<< orphan*/ errhandler(int, char *, char *);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(float *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(float *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
void read_matrix(const char *szFileName, double **m, int nrl, int nrh, int ncl,
                 int nch) {
  int i, j;
  FILE *fh = 0;
  int nSize = (nrh - nrl + 1) * (nch - ncl + 1);
  float *tmp = (float *)malloc((size_t)(nSize * sizeof(float)));
  int k = 0;
  fh = fopen(szFileName, "r");
  if (fh == NULL) {
    char szBuff[80];
    sprintf(szBuff, "Can not read file %s !!!", szFileName);
    errhandler(608,
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/EvaBr/CFD-Lab/refs/heads/"
               "master/FinalProject/helper.c",
               szBuff);
  }
  fread(tmp, sizeof(float), nSize, fh);
  for (j = ncl; j <= nch; j++)
    for (i = nrl; i <= nrh; i++)
      m[i][j] = tmp[k++];
  if (fclose(fh)) {
    char szBuff[80];
    sprintf(szBuff, "Inputfile %s cannot be closed", szFileName);
    errhandler(624,
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/EvaBr/CFD-Lab/refs/heads/"
               "master/FinalProject/helper.c",
               szBuff);
  };
  free(tmp);
}


x86 assembly (clang, -O0):
<read_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x14(%rbp),%eax
add    $0x1,%eax
mov    -0x20(%rbp),%ecx
sub    -0x1c(%rbp),%ecx
add    $0x1,%ecx
imul   %ecx,%eax
mov    %eax,-0x34(%rbp)
movslq -0x34(%rbp),%rdi
shl    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe2c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1217 <read_matrix+0xa7>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe08(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0xa0(%rbp),%rdx
mov    $0x260,%edi
lea    0xe09(%rip),%rsi
call   1050 <errhandler@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x4,%esi
call   1040 <fread@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     12a1 <read_matrix+0x131>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     128e <read_matrix+0x11e>
mov    -0x40(%rbp),%rax
mov    -0x44(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x44(%rbp)
movslq %ecx,%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1244 <read_matrix+0xd4>
jmp    1293 <read_matrix+0x123>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1232 <read_matrix+0xc2>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
cmp    $0x0,%rax
je     12e3 <read_matrix+0x173>
lea    -0xf0(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xde5(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0xf0(%rbp),%rdx
mov    $0x270,%edi
lea    0xd3d(%rip),%rsi
call   1050 <errhandler@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %r9d,%r13d
mov    %ecx,%r14d
mov    %edx,%ebp
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbx
mov    %ecx,%eax
sub    %edx,%eax
add    $0x1,%eax
mov    %r9d,%r12d
mov    %r8d,(%rsp)
sub    %r8d,%r12d
add    $0x1,%r12d
imul   %eax,%r12d
movslq %r12d,%rdi
shl    $0x2,%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
lea    0xe40(%rip),%rsi
mov    %rbx,0x8(%rsp)
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1201 <read_matrix+0x91>
lea    0xe26(%rip),%rsi
lea    0x30(%rsp),%rdi
mov    0x8(%rsp),%rdx
call   1090 <sprintf@plt>
lea    0xe29(%rip),%rsi
mov    $0x260,%edi
lea    0x30(%rsp),%rdx
call   1050 <errhandler@plt>
mov    %r15,%rdi
mov    $0x4,%esi
mov    %r12d,%edx
mov    %rbx,0x20(%rsp)
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    (%rsp),%eax
cmp    %r13d,%eax
mov    %r15,0x18(%rsp)
jle    1281 <read_matrix+0x111>
mov    0x20(%rsp),%rdi
call   1060 <fclose@plt>
test   %rax,%rax
je     1267 <read_matrix+0xf7>
lea    0xe6f(%rip),%rsi
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    0x8(%rsp),%rdx
call   1090 <sprintf@plt>
lea    0xdc6(%rip),%rsi
mov    $0x270,%edi
mov    %rbx,%rdx
mov    0x18(%rsp),%r15
call   1050 <errhandler@plt>
mov    %r15,%rdi
call   1030 <free@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movslq %ebp,%r12
lea    0x1(%r14),%r9d
movslq %eax,%rdx
add    $0x1,%r13d
mov    %r9d,%r10d
sub    %ebp,%r10d
lea    0x1(%r12),%rax
mov    %rax,(%rsp)
mov    0x10(%rsp),%rax
add    $0x8,%rax
mov    %rax,0x28(%rsp)
mov    %r15,%r11
add    $0x4,%r11
xor    %ecx,%ecx
jmp    12cd <read_matrix+0x15d>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rdx
cmp    %edx,%r13d
je     1226 <read_matrix+0xb6>
cmp    %ebp,%r14d
jl     12c0 <read_matrix+0x150>
movslq %ecx,%rcx
test   $0x1,%r10b
jne    12f0 <read_matrix+0x180>
mov    %r12,%rax
cmp    %ebp,%r14d
je     12c0 <read_matrix+0x150>
jmp    1315 <read_matrix+0x1a5>
cs nopw 0x0(%rax,%rax,1)
nop
movss  (%r15,%rcx,4),%xmm0
add    $0x1,%rcx
cvtss2sd %xmm0,%xmm0
mov    0x10(%rsp),%rax
mov    (%rax,%r12,8),%rax
movsd  %xmm0,(%rax,%rdx,8)
mov    (%rsp),%rax
cmp    %ebp,%r14d
je     12c0 <read_matrix+0x150>
mov    %r9d,%edi
sub    %eax,%edi
mov    0x28(%rsp),%rsi
lea    (%rsi,%rax,8),%rax
lea    (%r11,%rcx,4),%r15
xor    %esi,%esi
nopl   0x0(%rax)
movss  -0x4(%r15,%rsi,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x8(%rax,%rsi,8),%r8
movsd  %xmm0,(%r8,%rdx,8)
movss  (%r15,%rsi,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    (%rax,%rsi,8),%rbx
movsd  %xmm0,(%rbx,%rdx,8)
add    $0x2,%rsi
cmp    %esi,%edi
jne    1330 <read_matrix+0x1c0>
add    %rsi,%rcx
mov    0x18(%rsp),%r15
jmp    12c0 <read_matrix+0x150>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"Can not read file %s !!!\00"
@.str.2 = [144 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/FinalProject/helper.c\00"
@.str.3 = [30 x i8] c"Inputfile %s cannot be closed\00"
define void @read_matrix(i8* %0, double** %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i8*
%8 = alloca double**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32*
%16 = alloca i32
%17 = alloca float*
%18 = alloca i32
%19 = alloca [80 x i8]
%20 = alloca [80 x i8]
store i8* %0, i8** %7
store double** %1, double*** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store i32* null, i32** %15
%21 = load i32, i32* %10
%22 = load i32, i32* %9
%23 = sub nsw i32 %21, %22
%24 = add nsw i32 %23, 1
%25 = load i32, i32* %12
%26 = load i32, i32* %11
%27 = sub nsw i32 %25, %26
%28 = add nsw i32 %27, 1
%29 = mul nsw i32 %24, %28
store i32 %29, i32* %16
%30 = load i32, i32* %16
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 4
%33 = call i64 @malloc(i64 %32)
%34 = inttoptr i64 %33 to float*
store float* %34, float** %17
store i32 0, i32* %18
%35 = load i8*, i8** %7
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %36, i32** %15
%37 = load i32*, i32** %15
%38 = icmp eq i32* %37, null
br i1 %38, label %39, label %45
39: ; preds = %6
%40 = getelementptr inbounds [80 x i8], [80 x i8]* %19, i64 0, i64 0
%41 = load i8*, i8** %7
%42 = call i32 @sprintf(i8* %40, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = getelementptr inbounds [80 x i8], [80 x i8]* %19, i64 0, i64 0
%44 = call i32 @errhandler(i32 608, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.2, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %39, %6
%46 = load float*, float** %17
%47 = load i32, i32* %16
%48 = load i32*, i32** %15
%49 = call i32 @fread(float* %46, i32 4, i32 %47, i32* %48)
%50 = load i32, i32* %11
store i32 %50, i32* %14
br label %51
51: ; preds = %81, %45
%52 = load i32, i32* %14
%53 = load i32, i32* %12
%54 = icmp sle i32 %52, %53
br i1 %54, label %55, label %84
55: ; preds = %51
%56 = load i32, i32* %9
store i32 %56, i32* %13
br label %57
57: ; preds = %77, %55
%58 = load i32, i32* %13
%59 = load i32, i32* %10
%60 = icmp sle i32 %58, %59
br i1 %60, label %61, label %80
61: ; preds = %57
%62 = load float*, float** %17
%63 = load i32, i32* %18
%64 = add nsw i32 %63, 1
store i32 %64, i32* %18
%65 = sext i32 %63 to i64
%66 = getelementptr inbounds float, float* %62, i64 %65
%67 = load float, float* %66
%68 = fpext float %67 to double
%69 = load double**, double*** %8
%70 = load i32, i32* %13
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double*, double** %69, i64 %71
%73 = load double*, double** %72
%74 = load i32, i32* %14
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds double, double* %73, i64 %75
store double %68, double* %76
br label %77
77: ; preds = %61
%78 = load i32, i32* %13
%79 = add nsw i32 %78, 1
store i32 %79, i32* %13
br label %57
80: ; preds = %57
br label %81
81: ; preds = %80
%82 = load i32, i32* %14
%83 = add nsw i32 %82, 1
store i32 %83, i32* %14
br label %51
84: ; preds = %51
%85 = load i32*, i32** %15
%86 = call i64 @fclose(i32* %85)
%87 = icmp ne i64 %86, 0
br i1 %87, label %88, label %94
88: ; preds = %84
%89 = getelementptr inbounds [80 x i8], [80 x i8]* %20, i64 0, i64 0
%90 = load i8*, i8** %7
%91 = call i32 @sprintf(i8* %89, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %90)
%92 = getelementptr inbounds [80 x i8], [80 x i8]* %20, i64 0, i64 0
%93 = call i32 @errhandler(i32 624, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.2, i64 0, i64 0), i8* %92)
br label %94
94: ; preds = %88, %84
%95 = load float*, float** %17
%96 = call i32 @free(float* %95)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [25 x i8] c"Can not read file %s !!!\00"
@.str.2 = [144 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/FinalProject/helper.c\00"
@.str.3 = [30 x i8] c"Inputfile %s cannot be closed\00"
define void @read_matrix(i8* %0, double** nocapture %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca [80 x i8]
%8 = alloca [80 x i8]
%9 = sub i32 1, %2
%10 = add i32 %9, %3
%11 = sub i32 1, %4
%12 = add i32 %11, %5
%13 = mul nsw i32 %12, %10
%14 = sext i32 %13 to i64
%15 = shl nsw i64 %14, 2
%16 = tail call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to float*
%18 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %6
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%22 = call i32 @sprintf(i8* %21, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%23 = call i32 @errhandler(i32 608, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %24
24: ; preds = %20, %6
%25 = call i32 @fread(float* %17, i32 4, i32 %13, i32* %18)
%26 = icmp sgt i32 %4, %5
br i1 %26, label %84, label %27
27: ; preds = %24
%28 = icmp slt i32 %3, %2
%29 = sext i32 %2 to i64
%30 = add i32 %3, 1
%31 = sext i32 %4 to i64
%32 = add i32 %5, 1
%33 = sub i32 %30, %2
%34 = and i32 %33, 1
%35 = icmp eq i32 %34, 0
%36 = getelementptr inbounds double*, double** %1, i64 %29
%37 = add nsw i64 %29, 1
%38 = icmp eq i32 %3, %2
br label %39
39: ; preds = %27, %79
%40 = phi i64 [ %31, %27 ], [ %81, %79 ]
%41 = phi i32 [ 0, %27 ], [ %80, %79 ]
br i1 %28, label %79, label %42
42: ; preds = %39
%43 = sext i32 %41 to i64
br i1 %35, label %51, label %44
44: ; preds = %42
%45 = add nsw i64 %43, 1
%46 = getelementptr inbounds float, float* %17, i64 %43
%47 = load float, float* %46
%48 = fpext float %47 to double
%49 = load double*, double** %36
%50 = getelementptr inbounds double, double* %49, i64 %40
store double %48, double* %50
br label %51
51: ; preds = %44, %42
%52 = phi i64 [ undef, %42 ], [ %45, %44 ]
%53 = phi i64 [ %29, %42 ], [ %37, %44 ]
%54 = phi i64 [ %43, %42 ], [ %45, %44 ]
br i1 %38, label %76, label %55
55: ; preds = %51, %55
%56 = phi i64 [ %73, %55 ], [ %53, %51 ]
%57 = phi i64 [ %66, %55 ], [ %54, %51 ]
%58 = add nsw i64 %57, 1
%59 = getelementptr inbounds float, float* %17, i64 %57
%60 = load float, float* %59
%61 = fpext float %60 to double
%62 = getelementptr inbounds double*, double** %1, i64 %56
%63 = load double*, double** %62
%64 = getelementptr inbounds double, double* %63, i64 %40
store double %61, double* %64
%65 = add nsw i64 %56, 1
%66 = add nsw i64 %57, 2
%67 = getelementptr inbounds float, float* %17, i64 %58
%68 = load float, float* %67
%69 = fpext float %68 to double
%70 = getelementptr inbounds double*, double** %1, i64 %65
%71 = load double*, double** %70
%72 = getelementptr inbounds double, double* %71, i64 %40
store double %69, double* %72
%73 = add nsw i64 %56, 2
%74 = trunc i64 %73 to i32
%75 = icmp eq i32 %30, %74
br i1 %75, label %76, label %55
76: ; preds = %55, %51
%77 = phi i64 [ %52, %51 ], [ %66, %55 ]
%78 = trunc i64 %77 to i32
br label %79
79: ; preds = %76, %39
%80 = phi i32 [ %41, %39 ], [ %78, %76 ]
%81 = add nsw i64 %40, 1
%82 = trunc i64 %81 to i32
%83 = icmp eq i32 %32, %82
br i1 %83, label %84, label %39
84: ; preds = %79, %24
%85 = call i64 @fclose(i32* %18)
%86 = icmp eq i64 %85, 0
br i1 %86, label %91, label %87
87: ; preds = %84
%88 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%89 = call i32 @sprintf(i8* %88, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%90 = call i32 @errhandler(i32 624, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.2, i64 0, i64 0), i8* %88)
br label %91
91: ; preds = %87, %84
%92 = call i32 @free(float* %17)
ret void
}