#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 */

/* Variables and functions */
int /*<<< orphan*/ errhandler(int, char *, char *);
scalar_t__ malloc(size_t);
double **matrix(int nrl, int nrh, int ncl, int nch) {
  int i;
  int nrow = nrh - nrl + 1;
  int ncol = nch - ncl + 1;
  double **pArray = (double **)malloc((size_t)(nrow * sizeof(double *)));
  double *pMatrix = (double *)malloc((size_t)(nrow * ncol * sizeof(double)));
  if (pArray == 0)
    errhandler(353,
               "/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/ws1/helper.c",
               "Storage cannot be allocated");
  if (pMatrix == 0)
    errhandler(354,
               "/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/ws1/helper.c",
               "Storage cannot be allocated");
  pArray[0] = pMatrix - ncl;
  for (i = 1; i < nrow; i++) {
    pArray[i] = pArray[i - 1] + ncol;
  }
  return pArray - nrl;
}


x86 assembly (clang, -O0):
<matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x18(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
imul   -0x1c(%rbp),%eax
movslq %eax,%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1197 <matrix+0x77>
mov    $0x161,%edi
lea    0xe75(%rip),%rsi
lea    0xf1e(%rip),%rdx
call   1030 <errhandler@plt>
cmpq   $0x0,-0x30(%rbp)
jne    11ba <matrix+0x9a>
mov    $0x162,%edi
lea    0xe52(%rip),%rsi
lea    0xefb(%rip),%rdx
call   1030 <errhandler@plt>
mov    -0x30(%rbp),%rcx
movslq -0xc(%rbp),%rdx
xor    %eax,%eax
sub    %rdx,%rax
shl    $0x3,%rax
add    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    121e <matrix+0xfe>
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
movslq -0x1c(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11dc <matrix+0xbc>
mov    -0x28(%rbp),%rax
movslq -0x4(%rbp),%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r13d
mov    %esi,%r12d
mov    %edi,0x4(%rsp)
sub    %edi,%r12d
lea    0x1(%r12),%r14d
sub    %edx,%r15d
add    $0x1,%r15d
movslq %r12d,%rax
lea    0x8(,%rax,8),%rdi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %r15d,%eax
imul   %r14d,%eax
movslq %eax,%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,%rbp
test   %rbx,%rbx
je     127e <matrix+0x15e>
test   %rbp,%rbp
jne    1196 <matrix+0x76>
lea    0xe7b(%rip),%rsi
lea    0xf24(%rip),%rdx
mov    $0x162,%edi
call   1030 <errhandler@plt>
movslq %r13d,%rax
shl    $0x3,%rax
sub    %rax,%rbp
mov    %rbp,(%rbx)
test   %r12d,%r12d
jle    1260 <matrix+0x140>
movslq %r15d,%r9
lea    -0x1(%r14),%rsi
add    $0xfffffffffffffffe,%r14
mov    %esi,%ecx
and    $0x7,%ecx
mov    $0x1,%edx
cmp    $0x7,%r14
jb     1236 <matrix+0x116>
and    $0xfffffffffffffff8,%rsi
mov    %r9,%r8
shl    $0x6,%r8
lea    0x0(,%r9,8),%rdi
xor    %edx,%edx
nopl   0x0(%rax)
mov    %rbp,%rax
add    %rdi,%rbp
mov    %rbp,0x8(%rbx,%rdx,8)
add    %rdi,%rbp
mov    %rbp,0x10(%rbx,%rdx,8)
add    %rdi,%rbp
mov    %rbp,0x18(%rbx,%rdx,8)
add    %rdi,%rbp
mov    %rbp,0x20(%rbx,%rdx,8)
add    %rdi,%rbp
mov    %rbp,0x28(%rbx,%rdx,8)
add    %rdi,%rbp
mov    %rbp,0x30(%rbx,%rdx,8)
add    %rdi,%rbp
mov    %rbp,0x38(%rbx,%rdx,8)
add    %rdi,%rbp
mov    %rbp,0x40(%rbx,%rdx,8)
add    $0x8,%rdx
cmp    %rdx,%rsi
jne    11e0 <matrix+0xc0>
add    %r8,%rax
add    $0x1,%rdx
mov    %rax,%rbp
test   %rcx,%rcx
je     1260 <matrix+0x140>
lea    0x0(,%r9,8),%rax
add    %rbp,%rax
shl    $0x3,%r9
lea    (%rbx,%rdx,8),%rdx
xor    %esi,%esi
mov    %rax,(%rdx,%rsi,8)
add    $0x1,%rsi
add    %r9,%rax
cmp    %rsi,%rcx
jne    1250 <matrix+0x130>
movslq 0x4(%rsp),%rax
shl    $0x3,%rax
sub    %rax,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd7b(%rip),%rsi
lea    0xe24(%rip),%rdx
mov    $0x161,%edi
call   1030 <errhandler@plt>
test   %rbp,%rbp
jne    1196 <matrix+0x76>
jmp    117e <matrix+0x5e>

LLVM IR (-O0):
@.str = [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/ws1/helper.c\00"
@.str.1 = [28 x i8] c"Storage cannot be allocated\00"
define double** @matrix(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca double**
%13 = alloca double*
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = sub nsw i32 %14, %15
%17 = add nsw i32 %16, 1
store i32 %17, i32* %10
%18 = load i32, i32* %8
%19 = load i32, i32* %7
%20 = sub nsw i32 %18, %19
%21 = add nsw i32 %20, 1
store i32 %21, i32* %11
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 8
%25 = call i64 @malloc(i64 %24)
%26 = inttoptr i64 %25 to double**
store double** %26, double*** %12
%27 = load i32, i32* %10
%28 = load i32, i32* %11
%29 = mul nsw i32 %27, %28
%30 = sext i32 %29 to i64
%31 = mul i64 %30, 8
%32 = call i64 @malloc(i64 %31)
%33 = inttoptr i64 %32 to double*
store double* %33, double** %13
%34 = load double**, double*** %12
%35 = icmp eq double** %34, null
br i1 %35, label %36, label %38
36: ; preds = %4
%37 = call i32 @errhandler(i32 353, i8* getelementptr inbounds ([176 x i8], [176 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %4
%39 = load double*, double** %13
%40 = icmp eq double* %39, null
br i1 %40, label %41, label %43
41: ; preds = %38
%42 = call i32 @errhandler(i32 354, i8* getelementptr inbounds ([176 x i8], [176 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
%44 = load double*, double** %13
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = sub i64 0, %46
%48 = getelementptr inbounds double, double* %44, i64 %47
%49 = load double**, double*** %12
%50 = getelementptr inbounds double*, double** %49, i64 0
store double* %48, double** %50
store i32 1, i32* %9
br label %51
51: ; preds = %69, %43
%52 = load i32, i32* %9
%53 = load i32, i32* %10
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %72
55: ; preds = %51
%56 = load double**, double*** %12
%57 = load i32, i32* %9
%58 = sub nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double*, double** %56, i64 %59
%61 = load double*, double** %60
%62 = load i32, i32* %11
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds double, double* %61, i64 %63
%65 = load double**, double*** %12
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double*, double** %65, i64 %67
store double* %64, double** %68
br label %69
69: ; preds = %55
%70 = load i32, i32* %9
%71 = add nsw i32 %70, 1
store i32 %71, i32* %9
br label %51
72: ; preds = %51
%73 = load double**, double*** %12
%74 = load i32, i32* %5
%75 = sext i32 %74 to i64
%76 = sub i64 0, %75
%77 = getelementptr inbounds double*, double** %73, i64 %76
ret double** %77
}

LLVM IR (-O2):
@.str = [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/ws1/helper.c\00"
@.str.1 = [28 x i8] c"Storage cannot be allocated\00"
define double** @matrix(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = sub nsw i32 %1, %0
%6 = add nsw i32 %5, 1
%7 = sub nsw i32 %3, %2
%8 = add nsw i32 %7, 1
%9 = sext i32 %6 to i64
%10 = shl nsw i64 %9, 3
%11 = tail call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to double**
%13 = mul nsw i32 %8, %6
%14 = sext i32 %13 to i64
%15 = shl nsw i64 %14, 3
%16 = tail call i64 @malloc(i64 %15)
%17 = inttoptr i64 %16 to double*
%18 = icmp eq i64 %11, 0
br i1 %18, label %19, label %21
19: ; preds = %4
%20 = tail call i32 @errhandler(i32 353, i8* getelementptr inbounds ([176 x i8], [176 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %4
%22 = icmp eq i64 %16, 0
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = tail call i32 @errhandler(i32 354, i8* getelementptr inbounds ([176 x i8], [176 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
%26 = sext i32 %2 to i64
%27 = sub nsw i64 0, %26
%28 = getelementptr inbounds double, double* %17, i64 %27
store double* %28, double** %12
%29 = icmp slt i32 %5, 1
br i1 %29, label %84, label %30
30: ; preds = %25
%31 = sext i32 %8 to i64
%32 = add i32 %1, 1
%33 = sub i32 %32, %0
%34 = zext i32 %33 to i64
%35 = add nsw i64 %34, -1
%36 = add nsw i64 %34, -2
%37 = and i64 %35, 7
%38 = icmp ult i64 %36, 7
br i1 %38, label %71, label %39
39: ; preds = %30
%40 = and i64 %35, -8
br label %41
41: ; preds = %41, %39
%42 = phi double* [ %28, %39 ], [ %66, %41 ]
%43 = phi i64 [ 1, %39 ], [ %68, %41 ]
%44 = phi i64 [ 0, %39 ], [ %69, %41 ]
%45 = getelementptr inbounds double, double* %42, i64 %31
%46 = getelementptr inbounds double*, double** %12, i64 %43
store double* %45, double** %46
%47 = add nuw nsw i64 %43, 1
%48 = getelementptr inbounds double, double* %45, i64 %31
%49 = getelementptr inbounds double*, double** %12, i64 %47
store double* %48, double** %49
%50 = add nuw nsw i64 %43, 2
%51 = getelementptr inbounds double, double* %48, i64 %31
%52 = getelementptr inbounds double*, double** %12, i64 %50
store double* %51, double** %52
%53 = add nuw nsw i64 %43, 3
%54 = getelementptr inbounds double, double* %51, i64 %31
%55 = getelementptr inbounds double*, double** %12, i64 %53
store double* %54, double** %55
%56 = add nuw nsw i64 %43, 4
%57 = getelementptr inbounds double, double* %54, i64 %31
%58 = getelementptr inbounds double*, double** %12, i64 %56
store double* %57, double** %58
%59 = add nuw nsw i64 %43, 5
%60 = getelementptr inbounds double, double* %57, i64 %31
%61 = getelementptr inbounds double*, double** %12, i64 %59
store double* %60, double** %61
%62 = add nuw nsw i64 %43, 6
%63 = getelementptr inbounds double, double* %60, i64 %31
%64 = getelementptr inbounds double*, double** %12, i64 %62
store double* %63, double** %64
%65 = add nuw nsw i64 %43, 7
%66 = getelementptr inbounds double, double* %63, i64 %31
%67 = getelementptr inbounds double*, double** %12, i64 %65
store double* %66, double** %67
%68 = add nuw nsw i64 %43, 8
%69 = add i64 %44, 8
%70 = icmp eq i64 %69, %40
br i1 %70, label %71, label %41
71: ; preds = %41, %30
%72 = phi double* [ %28, %30 ], [ %66, %41 ]
%73 = phi i64 [ 1, %30 ], [ %68, %41 ]
%74 = icmp eq i64 %37, 0
br i1 %74, label %84, label %75
75: ; preds = %71, %75
%76 = phi double* [ %79, %75 ], [ %72, %71 ]
%77 = phi i64 [ %81, %75 ], [ %73, %71 ]
%78 = phi i64 [ %82, %75 ], [ 0, %71 ]
%79 = getelementptr inbounds double, double* %76, i64 %31
%80 = getelementptr inbounds double*, double** %12, i64 %77
store double* %79, double** %80
%81 = add nuw nsw i64 %77, 1
%82 = add i64 %78, 1
%83 = icmp eq i64 %82, %37
br i1 %83, label %84, label %75
84: ; preds = %71, %75, %25
%85 = sext i32 %0 to i64
%86 = sub nsw i64 0, %85
%87 = getelementptr inbounds double*, double** %12, i64 %86
ret double** %87
}