#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*/ abort();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
double **paw_alloc_2d_array(int n1, int n2) {
  double **array;
  int i;
  int j;
  array = (double **)malloc(n1 * sizeof(double *));
  if (array == 0) {
    printf("memory allocation problem in alloc_2d_array\n");
    abort();
  }
  for (i = 0; i < n1; i++) {
    array[i] = (double *)malloc(n2 * sizeof(double));
    if (array == 0) {
      printf("memory allocation problem in alloc_1d_array\n");
      abort();
    }
  }
  for (i = 0; i < n1; i++) {
    for (j = 0; j < n2; j++)
      array[i][j] = 0.0;
  }
  return array;
}


x86 assembly (clang, -O0):
<paw_alloc_2d_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116f <paw_alloc_2d_array+0x3f>
lea    0xe9d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d1 <paw_alloc_2d_array+0xa1>
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
cmpq   $0x0,-0x10(%rbp)
jne    11be <paw_alloc_2d_array+0x8e>
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11c3 <paw_alloc_2d_array+0x93>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1176 <paw_alloc_2d_array+0x46>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1230 <paw_alloc_2d_array+0x100>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121d <paw_alloc_2d_array+0xed>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x18(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11eb <paw_alloc_2d_array+0xbb>
jmp    1222 <paw_alloc_2d_array+0xf2>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d8 <paw_alloc_2d_array+0xa8>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<paw_alloc_2d_array>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
lea    0x0(,%r15,8),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     125b <paw_alloc_2d_array+0x11b>
mov    %rax,%r12
test   %r15d,%r15d
jle    11ef <paw_alloc_2d_array+0xaf>
lea    0x0(,%r14,8),%ebp
mov    %r15d,%r13d
xor    %ebx,%ebx
mov    %ebp,%edi
call   1060 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1180 <paw_alloc_2d_array+0x40>
test   %r15d,%r15d
jle    11ef <paw_alloc_2d_array+0xaf>
mov    %r14d,%r15d
shl    $0x3,%r15
lea    -0x1(%r13),%rax
mov    %r13d,%ecx
and    $0x3,%ecx
mov    %rcx,%rbx
cmp    $0x3,%rax
jae    1201 <paw_alloc_2d_array+0xc1>
xor    %ebp,%ebp
test   %rbx,%rbx
je     11ef <paw_alloc_2d_array+0xaf>
lea    (%r12,%rbp,8),%r13
xor    %ebp,%ebp
jmp    11d9 <paw_alloc_2d_array+0x99>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     11ef <paw_alloc_2d_array+0xaf>
test   %r14d,%r14d
jle    11d0 <paw_alloc_2d_array+0x90>
mov    0x0(%r13,%rbp,8),%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1050 <memset@plt>
jmp    11d0 <paw_alloc_2d_array+0x90>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
and    $0xfffffffc,%r13d
xor    %ebp,%ebp
jmp    1219 <paw_alloc_2d_array+0xd9>
nopl   0x0(%rax)
add    $0x4,%rbp
cmp    %rbp,%r13
je     11b5 <paw_alloc_2d_array+0x75>
test   %r14d,%r14d
jle    1210 <paw_alloc_2d_array+0xd0>
mov    (%r12,%rbp,8),%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1050 <memset@plt>
mov    0x8(%r12,%rbp,8),%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1050 <memset@plt>
mov    0x10(%r12,%rbp,8),%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1050 <memset@plt>
mov    0x18(%r12,%rbp,8),%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1050 <memset@plt>
jmp    1210 <paw_alloc_2d_array+0xd0>
lea    0xd9e(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"memory allocation problem in alloc_2d_array\0A\00"
@.str.1 = [45 x i8] c"memory allocation problem in alloc_1d_array\0A\00"
define double** @paw_alloc_2d_array(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double**
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to double**
store double** %13, double*** %5
%14 = load double**, double*** %5
%15 = icmp eq double** %14, null
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %2
store i32 0, i32* %6
br label %20
20: ; preds = %41, %19
%21 = load i32, i32* %6
%22 = load i32, i32* %3
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %44
24: ; preds = %20
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 8
%28 = trunc i64 %27 to i32
%29 = call i64 @malloc(i32 %28)
%30 = inttoptr i64 %29 to double*
%31 = load double**, double*** %5
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double*, double** %31, i64 %33
store double* %30, double** %34
%35 = load double**, double*** %5
%36 = icmp eq double** %35, null
br i1 %36, label %37, label %40
37: ; preds = %24
%38 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 (...) @abort()
unreachable
40: ; preds = %24
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %20
44: ; preds = %20
store i32 0, i32* %6
br label %45
45: ; preds = %67, %44
%46 = load i32, i32* %6
%47 = load i32, i32* %3
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %70
49: ; preds = %45
store i32 0, i32* %7
br label %50
50: ; preds = %63, %49
%51 = load i32, i32* %7
%52 = load i32, i32* %4
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %66
54: ; preds = %50
%55 = load double**, double*** %5
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double*, double** %55, i64 %57
%59 = load double*, double** %58
%60 = load i32, i32* %7
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
store double 0.000000e+00, double* %62
br label %63
63: ; preds = %54
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %50
66: ; preds = %50
br label %67
67: ; preds = %66
%68 = load i32, i32* %6
%69 = add nsw i32 %68, 1
store i32 %69, i32* %6
br label %45
70: ; preds = %45
%71 = load double**, double*** %5
ret double** %71
}

LLVM IR (-O2):
@str = [44 x i8] c"memory allocation problem in alloc_2d_array\00"
define double** @paw_alloc_2d_array(i32 %0, i32 %1) {
%3 = shl i32 %0, 3
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to double**
%6 = icmp eq i64 %4, 0
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %69
9: ; preds = %7
%10 = shl i32 %1, 3
%11 = zext i32 %0 to i64
br label %25
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 (...) @abort()
unreachable
15: ; preds = %25
br i1 %8, label %16, label %69
16: ; preds = %15
%17 = icmp sgt i32 %1, 0
%18 = zext i32 %1 to i64
%19 = shl nuw nsw i64 %18, 3
%20 = add nsw i64 %11, -1
%21 = and i64 %11, 3
%22 = icmp ult i64 %20, 3
br i1 %22, label %55, label %23
23: ; preds = %16
%24 = and i64 %11, 4294967292
br label %32
25: ; preds = %9, %25
%26 = phi i64 [ 0, %9 ], [ %30, %25 ]
%27 = tail call i64 @malloc(i32 %10)
%28 = inttoptr i64 %27 to double*
%29 = getelementptr inbounds double*, double** %5, i64 %26
store double* %28, double** %29
%30 = add nuw nsw i64 %26, 1
%31 = icmp eq i64 %30, %11
br i1 %31, label %15, label %25
32: ; preds = %51, %23
%33 = phi i64 [ 0, %23 ], [ %52, %51 ]
%34 = phi i64 [ 0, %23 ], [ %53, %51 ]
br i1 %17, label %35, label %51
35: ; preds = %32
%36 = getelementptr inbounds double*, double** %5, i64 %33
%37 = bitcast double** %36 to i8**
%38 = load i8*, i8** %37
%39 = or i64 %33, 1
%40 = getelementptr inbounds double*, double** %5, i64 %39
%41 = bitcast double** %40 to i8**
%42 = load i8*, i8** %41
%43 = or i64 %33, 2
%44 = getelementptr inbounds double*, double** %5, i64 %43
%45 = bitcast double** %44 to i8**
%46 = load i8*, i8** %45
%47 = or i64 %33, 3
%48 = getelementptr inbounds double*, double** %5, i64 %47
%49 = bitcast double** %48 to i8**
%50 = load i8*, i8** %49
br label %51
51: ; preds = %32, %35
%52 = add nuw nsw i64 %33, 4
%53 = add i64 %34, 4
%54 = icmp eq i64 %53, %24
br i1 %54, label %55, label %32
55: ; preds = %51, %16
%56 = phi i64 [ 0, %16 ], [ %52, %51 ]
%57 = icmp eq i64 %21, 0
br i1 %57, label %69, label %58
58: ; preds = %55, %65
%59 = phi i64 [ %66, %65 ], [ %56, %55 ]
%60 = phi i64 [ %67, %65 ], [ 0, %55 ]
br i1 %17, label %61, label %65
61: ; preds = %58
%62 = getelementptr inbounds double*, double** %5, i64 %59
%63 = bitcast double** %62 to i8**
%64 = load i8*, i8** %63
br label %65
65: ; preds = %61, %58
%66 = add nuw nsw i64 %59, 1
%67 = add i64 %60, 1
%68 = icmp eq i64 %67, %21
br i1 %68, label %69, label %58
69: ; preds = %55, %65, %7, %15
ret double** %5
}