#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 */
double *allocate_double_1D(int);
double **allocate_double_2D_AP(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
double **allocate_double_RT(int nrow, int ncol) {
  int i, j;
  double **pointerarray = allocate_double_2D_AP(nrow);
  if (pointerarray == NULL) {
    fprintf(stderr, "PE: Memory allocation fails!\n");
    exit(1);
  }
  for (i = 0; i < nrow; i++) {
    pointerarray[i] = allocate_double_1D(ncol);
    if (pointerarray[i] == NULL) {
      fprintf(stderr, "PE: Memory allocation fails!\n");
      exit(1);
    }
    for (j = 0; j < ncol; j++) {
      pointerarray[i][j] = 0.0;
    }
  }
  return (pointerarray);
}


x86 assembly (clang, -O0):
<allocate_double_RT>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1060 <allocate_double_2D_AP@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1184 <allocate_double_RT+0x44>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    122c <allocate_double_RT+0xec>
mov    -0x8(%rbp),%edi
call   1040 <allocate_double_1D@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11e0 <allocate_double_RT+0xa0>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1219 <allocate_double_RT+0xd9>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x10(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e7 <allocate_double_RT+0xa7>
jmp    121e <allocate_double_RT+0xde>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118b <allocate_double_RT+0x4b>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_double_RT>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
call   1070 <allocate_double_2D_AP@plt>
test   %rax,%rax
je     11b8 <allocate_double_RT+0x68>
mov    %rax,%r14
test   %ebp,%ebp
jle    11ac <allocate_double_RT+0x5c>
mov    %ebx,%r15d
shl    $0x3,%r15
mov    %ebp,%r12d
xor    %ebp,%ebp
jmp    1189 <allocate_double_RT+0x39>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r12
je     11ac <allocate_double_RT+0x5c>
mov    %ebx,%edi
call   1050 <allocate_double_1D@plt>
mov    %rax,(%r14,%rbp,8)
test   %rax,%rax
je     11b8 <allocate_double_RT+0x68>
test   %ebx,%ebx
jle    1180 <allocate_double_RT+0x30>
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1030 <memset@plt>
jmp    1180 <allocate_double_RT+0x30>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"PE: Memory allocation fails!\0A\00"
define double** @allocate_double_RT(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double**
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = call double** @allocate_double_2D_AP(i32 %8)
store double** %9, double*** %7
%10 = load double**, double*** %7
%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 ([30 x i8], [30 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 = %56, %16
%18 = load i32, i32* %5
%19 = load i32, i32* %3
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %59
21: ; preds = %17
%22 = load i32, i32* %4
%23 = call double* @allocate_double_1D(i32 %22)
%24 = load double**, double*** %7
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds double*, double** %24, i64 %26
store double* %23, double** %27
%28 = load double**, double*** %7
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double*, double** %28, i64 %30
%32 = load double*, double** %31
%33 = icmp eq double* %32, null
br i1 %33, label %34, label %38
34: ; preds = %21
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %21
store i32 0, i32* %6
br label %39
39: ; preds = %52, %38
%40 = load i32, i32* %6
%41 = load i32, i32* %4
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %55
43: ; preds = %39
%44 = load double**, double*** %7
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds double*, double** %44, i64 %46
%48 = load double*, double** %47
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds double, double* %48, i64 %50
store double 0.000000e+00, double* %51
br label %52
52: ; preds = %43
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
br label %39
55: ; preds = %39
br label %56
56: ; preds = %55
%57 = load i32, i32* %5
%58 = add nsw i32 %57, 1
store i32 %58, i32* %5
br label %17
59: ; preds = %17
%60 = load double**, double*** %7
ret double** %60
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"PE: Memory allocation fails!\0A\00"
define double** @allocate_double_RT(i32 %0, i32 %1) {
%3 = tail call double** @allocate_double_2D_AP(i32 %0)
%4 = icmp eq double** %3, null
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %31
7: ; preds = %5
%8 = icmp sgt i32 %1, 0
%9 = zext i32 %1 to i64
%10 = shl nuw nsw i64 %9, 3
%11 = zext i32 %0 to i64
br label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %7, %28
%17 = phi i64 [ 0, %7 ], [ %29, %28 ]
%18 = tail call double* @allocate_double_1D(i32 %1)
%19 = bitcast double* %18 to i8*
%20 = getelementptr inbounds double*, double** %3, i64 %17
store double* %18, double** %20
%21 = icmp eq double* %18, null
br i1 %21, label %24, label %22
22: ; preds = %16
br i1 %8, label %23, label %28
23: ; preds = %22
br label %28
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %23, %22
%29 = add nuw nsw i64 %17, 1
%30 = icmp eq i64 %29, %11
br i1 %30, label %31, label %16
31: ; preds = %28, %5
ret double** %3
}