#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 *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, ...);
void write_matrix2(const char *szDebug, int timeStepNumber, double ***m,
                   int nrl, int nrh, int ncl, int nch, int nll, int nlh) {
  int i, j, k;
  FILE *fh = 0;
  char szFileName[80];
  if (timeStepNumber < 1000) {
    sprintf(szFileName, "simulation/debug/d%i_%s", timeStepNumber, szDebug);
  } else {
    timeStepNumber = timeStepNumber - 1000;
    sprintf(szFileName, "simulation/debug/P/d%i_%s", timeStepNumber, szDebug);
  }
  fh = fopen(szFileName, "w");
  if (fh == NULL) {
    char szBuff[80];
    sprintf(szBuff, "Outputfile %s cannot be created", szFileName);
    errhandler(505,
               "/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);
  }
  for (k = nll; k <= nlh; k++) {
    for (j = ncl; j <= nch; j++) {
      for (i = nrl; i <= nrh; i++) {
        fprintf(fh, "%f ", m[i][j][k]);
      }
      fprintf(fh, "\n");
    }
    fprintf(fh,
            "-----------------------------------------------------------\n");
  }
  if (fclose(fh)) {
    char szBuff[80];
    sprintf(szBuff, "Outputfile %s cannot be closed", szFileName);
    errhandler(524,
               "/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);
  };
}


x86 assembly (clang, -O0):
<write_matrix2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
movq   $0x0,-0x38(%rbp)
cmpl   $0x3e8,-0xc(%rbp)
jge    11b0 <write_matrix2+0x60>
lea    -0x90(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    11d7 <write_matrix2+0x87>
mov    -0xc(%rbp),%eax
sub    $0x3e8,%eax
mov    %eax,-0xc(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xe48(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe4d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    122d <write_matrix2+0xdd>
lea    -0xe0(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0xe0(%rbp),%rdx
mov    $0x1f9,%edi
lea    0xe2c(%rip),%rsi
call   1030 <errhandler@plt>
mov    0x18(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    0x20(%rbp),%eax
jg     12e0 <write_matrix2+0x190>
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    0x10(%rbp),%eax
jg     12c0 <write_matrix2+0x170>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x20(%rbp),%eax
jg     12a0 <write_matrix2+0x150>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
lea    0xe59(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1257 <write_matrix2+0x107>
mov    -0x38(%rbp),%rdi
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1245 <write_matrix2+0xf5>
mov    -0x38(%rbp),%rdi
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1233 <write_matrix2+0xe3>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     1327 <write_matrix2+0x1d7>
lea    -0x130(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
lea    -0x130(%rbp),%rdx
mov    $0x20c,%edi
lea    0xd32(%rip),%rsi
call   1030 <errhandler@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_matrix2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe8,%rsp
mov    %r9d,0x4(%rsp)
mov    %r8d,0xc(%rsp)
mov    %ecx,0x8(%rsp)
mov    %rdx,%r13
mov    %esi,%edx
mov    %rdi,%rcx
cmp    $0x3e7,%esi
jg     11a8 <write_matrix2+0x38>
lea    0xe5a(%rip),%rsi
jmp    11b5 <write_matrix2+0x45>
add    $0xfffffc18,%edx
lea    0xe63(%rip),%rsi
lea    0x40(%rsp),%rdi
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    0x130(%rsp),%ebx
mov    0x128(%rsp),%r15d
lea    0xe5b(%rip),%rsi
lea    0x40(%rsp),%rdi
call   1070 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11f3 <write_matrix2+0x83>
cmp    %ebx,%r15d
jg     122a <write_matrix2+0xba>
jmp    127b <write_matrix2+0x10b>
lea    0xe3a(%rip),%rsi
lea    0x90(%rsp),%r14
lea    0x40(%rsp),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <sprintf@plt>
lea    0xe3c(%rip),%rsi
mov    $0x1f9,%edi
mov    %r14,%rdx
call   1030 <errhandler@plt>
cmp    %ebx,%r15d
jle    127b <write_matrix2+0x10b>
mov    %rbp,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     1269 <write_matrix2+0xf9>
lea    0xee7(%rip),%rsi
lea    0x90(%rsp),%rbx
lea    0x40(%rsp),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <sprintf@plt>
lea    0xdf8(%rip),%rsi
mov    $0x20c,%edi
mov    %rbx,%rdx
call   1030 <errhandler@plt>
add    $0xe8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x120(%rsp),%ecx
movslq 0x8(%rsp),%rax
movslq 0x4(%rsp),%rdx
mov    %rdx,0x20(%rsp)
add    $0x1,%ecx
mov    %ecx,0x14(%rsp)
movslq %r15d,%rdx
add    $0x1,%ebx
lea    0x0(,%rax,8),%rcx
add    %r13,%rcx
mov    %rcx,0x30(%rsp)
mov    0xc(%rsp),%ecx
sub    %eax,%ecx
add    $0x1,%ecx
mov    %rcx,0x28(%rsp)
mov    %ebx,0x10(%rsp)
mov    0x28(%rsp),%r15
jmp    12fe <write_matrix2+0x18e>
nopw   0x0(%rax,%rax,1)
mov    $0x3c,%esi
mov    $0x1,%edx
lea    0xe07(%rip),%rdi
mov    %rbp,%rcx
call   1090 <fwrite@plt>
mov    0x18(%rsp),%rdx
add    $0x1,%rdx
mov    0x10(%rsp),%ebx
cmp    %edx,%ebx
je     122a <write_matrix2+0xba>
mov    %rdx,0x18(%rsp)
mov    0x120(%rsp),%eax
cmp    %eax,0x4(%rsp)
jg     12d0 <write_matrix2+0x160>
mov    0x20(%rsp),%r14
jmp    133b <write_matrix2+0x1cb>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    %rcx,%rbp
mov    %rcx,%rsi
call   1050 <fputc@plt>
add    $0x1,%r14
cmp    %r14d,0x14(%rsp)
je     12d0 <write_matrix2+0x160>
mov    0x8(%rsp),%eax
cmp    0xc(%rsp),%eax
mov    %rbp,%rcx
lea    0xd97(%rip),%r12
mov    0x18(%rsp),%r13
mov    0x30(%rsp),%rbp
jg     1320 <write_matrix2+0x1b0>
xor    %ebx,%ebx
mov    %r14,0x38(%rsp)
mov    0x0(%rbp,%rbx,8),%rax
mov    (%rax,%r14,8),%rax
movsd  (%rax,%r13,8),%xmm0
mov    %rcx,%rdi
mov    %rcx,%r14
mov    %r12,%rsi
mov    $0x1,%al
call   1060 <fprintf@plt>
mov    %r14,%rcx
mov    0x38(%rsp),%r14
add    $0x1,%rbx
cmp    %ebx,%r15d
jne    1360 <write_matrix2+0x1f0>
jmp    1320 <write_matrix2+0x1b0>

LLVM IR (-O0):
@.str = [24 x i8] c"simulation/debug/d%i_%s\00"
@.str.1 = [26 x i8] c"simulation/debug/P/d%i_%s\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [32 x i8] c"Outputfile %s cannot be created\00"
@.str.4 = [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.5 = [4 x i8] c"%f \00"
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [61 x i8] c"-----------------------------------------------------------\0A\00"
@.str.8 = [31 x i8] c"Outputfile %s cannot be closed\00"
define void @write_matrix2(i8* %0, i32 %1, double*** %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = alloca i8*
%11 = alloca i32
%12 = alloca double***
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32*
%23 = alloca [80 x i8]
%24 = alloca [80 x i8]
%25 = alloca [80 x i8]
store i8* %0, i8** %10
store i32 %1, i32* %11
store double*** %2, double**** %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
store i32 %8, i32* %18
store i32* null, i32** %22
%26 = load i32, i32* %11
%27 = icmp slt i32 %26, 1000
br i1 %27, label %28, label %33
28: ; preds = %9
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %23, i64 0, i64 0
%30 = load i32, i32* %11
%31 = load i8*, i8** %10
%32 = call i32 (i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %30, i8* %31)
br label %40
33: ; preds = %9
%34 = load i32, i32* %11
%35 = sub nsw i32 %34, 1000
store i32 %35, i32* %11
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %23, i64 0, i64 0
%37 = load i32, i32* %11
%38 = load i8*, i8** %10
%39 = call i32 (i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %37, i8* %38)
br label %40
40: ; preds = %33, %28
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %23, i64 0, i64 0
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %42, i32** %22
%43 = load i32*, i32** %22
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %51
45: ; preds = %40
%46 = getelementptr inbounds [80 x i8], [80 x i8]* %24, i64 0, i64 0
%47 = getelementptr inbounds [80 x i8], [80 x i8]* %23, i64 0, i64 0
%48 = call i32 (i8*, i8*, ...) @sprintf(i8* %46, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %47)
%49 = getelementptr inbounds [80 x i8], [80 x i8]* %24, i64 0, i64 0
%50 = call i32 @errhandler(i32 505, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.4, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %45, %40
%52 = load i32, i32* %17
store i32 %52, i32* %21
br label %53
53: ; preds = %97, %51
%54 = load i32, i32* %21
%55 = load i32, i32* %18
%56 = icmp sle i32 %54, %55
br i1 %56, label %57, label %100
57: ; preds = %53
%58 = load i32, i32* %15
store i32 %58, i32* %20
br label %59
59: ; preds = %91, %57
%60 = load i32, i32* %20
%61 = load i32, i32* %16
%62 = icmp sle i32 %60, %61
br i1 %62, label %63, label %94
63: ; preds = %59
%64 = load i32, i32* %13
store i32 %64, i32* %19
br label %65
65: ; preds = %85, %63
%66 = load i32, i32* %19
%67 = load i32, i32* %14
%68 = icmp sle i32 %66, %67
br i1 %68, label %69, label %88
69: ; preds = %65
%70 = load i32*, i32** %22
%71 = load double***, double**** %12
%72 = load i32, i32* %19
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double**, double*** %71, i64 %73
%75 = load double**, double*** %74
%76 = load i32, i32* %20
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds double*, double** %75, i64 %77
%79 = load double*, double** %78
%80 = load i32, i32* %21
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds double, double* %79, i64 %81
%83 = load double, double* %82
%84 = call i32 (i32*, i8*, ...) @fprintf(i32* %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double %83)
br label %85
85: ; preds = %69
%86 = load i32, i32* %19
%87 = add nsw i32 %86, 1
store i32 %87, i32* %19
br label %65
88: ; preds = %65
%89 = load i32*, i32** %22
%90 = call i32 (i32*, i8*, ...) @fprintf(i32* %89, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %91
91: ; preds = %88
%92 = load i32, i32* %20
%93 = add nsw i32 %92, 1
store i32 %93, i32* %20
br label %59
94: ; preds = %59
%95 = load i32*, i32** %22
%96 = call i32 (i32*, i8*, ...) @fprintf(i32* %95, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.7, i64 0, i64 0))
br label %97
97: ; preds = %94
%98 = load i32, i32* %21
%99 = add nsw i32 %98, 1
store i32 %99, i32* %21
br label %53
100: ; preds = %53
%101 = load i32*, i32** %22
%102 = call i64 @fclose(i32* %101)
%103 = icmp ne i64 %102, 0
br i1 %103, label %104, label %110
104: ; preds = %100
%105 = getelementptr inbounds [80 x i8], [80 x i8]* %25, i64 0, i64 0
%106 = getelementptr inbounds [80 x i8], [80 x i8]* %23, i64 0, i64 0
%107 = call i32 (i8*, i8*, ...) @sprintf(i8* %105, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %106)
%108 = getelementptr inbounds [80 x i8], [80 x i8]* %25, i64 0, i64 0
%109 = call i32 @errhandler(i32 524, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.4, i64 0, i64 0), i8* %108)
br label %110
110: ; preds = %104, %100
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"simulation/debug/d%i_%s\00"
@.str.1 = [26 x i8] c"simulation/debug/P/d%i_%s\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [32 x i8] c"Outputfile %s cannot be created\00"
@.str.4 = [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.5 = [4 x i8] c"%f \00"
@.str.7 = [61 x i8] c"-----------------------------------------------------------\0A\00"
@.str.8 = [31 x i8] c"Outputfile %s cannot be closed\00"
define void @write_matrix2(i8* %0, i32 %1, double*** nocapture %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = alloca [80 x i8]
%11 = alloca [80 x i8]
%12 = alloca [80 x i8]
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%14 = icmp slt i32 %1, 1000
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %0)
br label %20
17: ; preds = %9
%18 = add nsw i32 %1, -1000
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* %0)
br label %20
20: ; preds = %17, %15
%21 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %11, i64 0, i64 0
%25 = call i32 (i8*, i8*, ...) @sprintf(i8* %24, i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %13)
%26 = call i32 @errhandler(i32 505, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.4, i64 0, i64 0), i8* %24)
br label %27
27: ; preds = %23, %20
%28 = icmp sgt i32 %7, %8
br i1 %28, label %64, label %29
29: ; preds = %27
%30 = icmp sgt i32 %5, %6
%31 = icmp sgt i32 %3, %4
%32 = sext i32 %3 to i64
%33 = add i32 %4, 1
%34 = sext i32 %5 to i64
%35 = add i32 %6, 1
%36 = sext i32 %7 to i64
%37 = add i32 %8, 1
br label %38
38: ; preds = %29, %59
%39 = phi i64 [ %36, %29 ], [ %61, %59 ]
br i1 %30, label %59, label %40
40: ; preds = %38, %54
%41 = phi i64 [ %56, %54 ], [ %34, %38 ]
br i1 %31, label %54, label %42
42: ; preds = %40, %42
%43 = phi i64 [ %51, %42 ], [ %32, %40 ]
%44 = getelementptr inbounds double**, double*** %2, i64 %43
%45 = load double**, double*** %44
%46 = getelementptr inbounds double*, double** %45, i64 %41
%47 = load double*, double** %46
%48 = getelementptr inbounds double, double* %47, i64 %39
%49 = load double, double* %48
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double %49)
%51 = add nsw i64 %43, 1
%52 = trunc i64 %51 to i32
%53 = icmp eq i32 %33, %52
br i1 %53, label %54, label %42
54: ; preds = %42, %40
%55 = call i32 @fputc(i32 10, i32* %21)
%56 = add nsw i64 %41, 1
%57 = trunc i64 %56 to i32
%58 = icmp eq i32 %35, %57
br i1 %58, label %59, label %40
59: ; preds = %54, %38
%60 = call i64 @fwrite(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.7, i64 0, i64 0), i64 60, i64 1, i32* %21)
%61 = add nsw i64 %39, 1
%62 = trunc i64 %61 to i32
%63 = icmp eq i32 %37, %62
br i1 %63, label %64, label %38
64: ; preds = %59, %27
%65 = call i64 @fclose(i32* %21)
%66 = icmp eq i64 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %64
%68 = getelementptr inbounds [80 x i8], [80 x i8]* %12, i64 0, i64 0
%69 = call i32 (i8*, i8*, ...) @sprintf(i8* %68, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i8* %13)
%70 = call i32 @errhandler(i32 524, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.4, i64 0, i64 0), i8* %68)
br label %71
71: ; preds = %67, %64
ret void
}