#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 */
scalar_t__ calloc(unsigned int, int);
double *create_1D_array(unsigned int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
double **create_2D_array(unsigned n1, unsigned n2) {
  unsigned i;
  double **matrix = (double **)calloc(n1, sizeof(double *));
  if (matrix == NULL) {
    fprintf(stderr, "memory issue in create_2D_array\n");
    exit(1);
  }
  for (i = 0; i < n1; i++)
    matrix[i] = create_1D_array(n2);
  return matrix;
}


x86 assembly (clang, -O0):
<create_2D_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1189 <create_2D_array+0x49>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    11c0 <create_2D_array+0x80>
mov    -0x8(%rbp),%edi
call   1050 <create_1D_array@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1190 <create_2D_array+0x50>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_2D_array>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
mov    $0x8,%esi
call   1030 <calloc@plt>
test   %rax,%rax
je     1191 <create_2D_array+0x51>
mov    %rax,%r12
test   %r14d,%r14d
je     1185 <create_2D_array+0x45>
mov    %r14d,%ebp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r15d,%edi
call   1050 <create_1D_array@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <create_2D_array+0x30>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"memory issue in create_2D_array\0A\00"
define double** @create_2D_array(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca double**
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = call i64 @calloc(i32 %7, i32 8)
%9 = inttoptr i64 %8 to double**
store double** %9, double*** %6
%10 = load double**, double*** %6
%11 = icmp eq double** %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
store i32 0, i32* %5
br label %17
17: ; preds = %28, %16
%18 = load i32, i32* %5
%19 = load i32, i32* %3
%20 = icmp ult i32 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i32, i32* %4
%23 = call double* @create_1D_array(i32 %22)
%24 = load double**, double*** %6
%25 = load i32, i32* %5
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds double*, double** %24, i64 %26
store double* %23, double** %27
br label %28
28: ; preds = %21
%29 = load i32, i32* %5
%30 = add i32 %29, 1
store i32 %30, i32* %5
br label %17
31: ; preds = %17
%32 = load double**, double*** %6
ret double** %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"memory issue in create_2D_array\0A\00"
define double** @create_2D_array(i32 %0, i32 %1) {
%3 = tail call i64 @calloc(i32 %0, i32 8)
%4 = inttoptr i64 %3 to double**
%5 = icmp eq i64 %3, 0
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = icmp eq i32 %0, 0
br i1 %7, label %20, label %8
8: ; preds = %6
%9 = zext i32 %0 to i64
br label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %8, %14
%15 = phi i64 [ 0, %8 ], [ %18, %14 ]
%16 = tail call double* @create_1D_array(i32 %1)
%17 = getelementptr inbounds double*, double** %4, i64 %15
store double* %16, double** %17
%18 = add nuw nsw i64 %15, 1
%19 = icmp eq i64 %18, %9
br i1 %19, label %20, label %14
20: ; preds = %14, %6
ret double** %4
}