double **new_Array2D_double(int M, int N) {
  int i = 0;
  int failed = 0;
  double **A = (double **)malloc(sizeof(double *) * M);
  if (A == 0)
    return 0;
  for (i = 0; i < M; i++) {
    A[i] = (double *)malloc(N * sizeof(double));
    if (A[i] == 0) {
      failed = 1;
      break;
    }
  }
  if (failed) {
    i--;
    for (; i <= 0; i--)
      free(A[i]);
    free(A);
    return 0;
  } else
    return A;
}


x86 assembly (clang, -O0):
<new_Array2D_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movslq -0xc(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1165 <new_Array2D_double+0x45>
movq   $0x0,-0x8(%rbp)
jmp    1220 <new_Array2D_double+0x100>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c6 <new_Array2D_double+0xa6>
movslq -0x10(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11b3 <new_Array2D_double+0x93>
movl   $0x1,-0x18(%rbp)
jmp    11c6 <new_Array2D_double+0xa6>
jmp    11b8 <new_Array2D_double+0x98>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116c <new_Array2D_double+0x4c>
cmpl   $0x0,-0x18(%rbp)
je     1218 <new_Array2D_double+0xf8>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1202 <new_Array2D_double+0xe2>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11d9 <new_Array2D_double+0xb9>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1220 <new_Array2D_double+0x100>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_Array2D_double>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebx
mov    %edi,%ebp
movslq %edi,%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1190 <new_Array2D_double+0x70>
mov    %rax,%r14
test   %ebp,%ebp
jle    1193 <new_Array2D_double+0x73>
movslq %ebx,%r12
shl    $0x3,%r12
mov    %ebp,%r15d
mov    %r14,%rbp
add    $0xfffffffffffffff8,%rbp
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <malloc@plt>
mov    %rax,0x8(%rbp)
test   %rax,%rax
je     1180 <new_Array2D_double+0x60>
add    $0x1,%rbx
add    $0x8,%rbp
cmp    %rbx,%r15
jne    1160 <new_Array2D_double+0x40>
jmp    1193 <new_Array2D_double+0x73>
test   $0xfffffffe,%ebx
je     11a0 <new_Array2D_double+0x80>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
nop
mov    0x0(%rbp),%rdi
call   1030 <free@plt>
add    $0xfffffffffffffff8,%rbp
jmp    11a0 <new_Array2D_double+0x80>

LLVM IR (-O0):
define double** @new_Array2D_double(i32 %0, i32 %1) {
%3 = alloca double**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double**
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = mul i64 8, %10
%12 = call i8* @malloc(i64 %11)
%13 = bitcast i8* %12 to double**
store double** %13, double*** %8
%14 = load double**, double*** %8
%15 = icmp eq double** %14, null
br i1 %15, label %16, label %17
16: ; preds = %2
store double** null, double*** %3
br label %67
17: ; preds = %2
store i32 0, i32* %6
br label %18
18: ; preds = %40, %17
%19 = load i32, i32* %6
%20 = load i32, i32* %4
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %43
22: ; preds = %18
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 8
%26 = call i8* @malloc(i64 %25)
%27 = bitcast i8* %26 to double*
%28 = load double**, double*** %8
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds double*, double** %28, i64 %30
store double* %27, double** %31
%32 = load double**, double*** %8
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds double*, double** %32, i64 %34
%36 = load double*, double** %35
%37 = icmp eq double* %36, null
br i1 %37, label %38, label %39
38: ; preds = %22
store i32 1, i32* %7
br label %43
39: ; preds = %22
br label %40
40: ; preds = %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
store i32 %42, i32* %6
br label %18
43: ; preds = %38, %18
%44 = load i32, i32* %7
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %65
46: ; preds = %43
%47 = load i32, i32* %6
%48 = add nsw i32 %47, -1
store i32 %48, i32* %6
br label %49
49: ; preds = %59, %46
%50 = load i32, i32* %6
%51 = icmp sle i32 %50, 0
br i1 %51, label %52, label %62
52: ; preds = %49
%53 = load double**, double*** %8
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double*, double** %53, i64 %55
%57 = load double*, double** %56
%58 = bitcast double* %57 to i8*
br label %59
59: ; preds = %52
%60 = load i32, i32* %6
%61 = add nsw i32 %60, -1
store i32 %61, i32* %6
br label %49
62: ; preds = %49
%63 = load double**, double*** %8
%64 = bitcast double** %63 to i8*
store double** null, double*** %3
br label %67
65: ; preds = %43
%66 = load double**, double*** %8
store double** %66, double*** %3
br label %67
67: ; preds = %65, %62, %16
%68 = load double**, double*** %3
ret double** %68
}

LLVM IR (-O2):
define noalias double** @new_Array2D_double(i32 %0, i32 %1) {
%3 = sext i32 %0 to i64
%4 = shl nsw i64 %3, 3
%5 = tail call i8* @malloc(i64 %4)
%6 = bitcast i8* %5 to double**
%7 = icmp eq i8* %5, null
br i1 %7, label %33, label %8
8: ; preds = %2
%9 = icmp sgt i32 %0, 0
br i1 %9, label %10, label %33
10: ; preds = %8
%11 = sext i32 %1 to i64
%12 = shl nsw i64 %11, 3
%13 = zext i32 %0 to i64
br label %14
14: ; preds = %10, %23
%15 = phi i64 [ 0, %10 ], [ %24, %23 ]
%16 = tail call i8* @malloc(i64 %12)
%17 = getelementptr inbounds double*, double** %6, i64 %15
%18 = bitcast double** %17 to i8**
store i8* %16, i8** %18
%19 = icmp eq i8* %16, null
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = and i64 %15, 4294967294
%22 = icmp eq i64 %21, 0
br i1 %22, label %26, label %32
23: ; preds = %14
%24 = add nuw nsw i64 %15, 1
%25 = icmp eq i64 %24, %13
br i1 %25, label %33, label %14
26: ; preds = %20, %26
%27 = phi i64 [ %28, %26 ], [ %15, %20 ]
%28 = add nsw i64 %27, -1
%29 = getelementptr inbounds double*, double** %6, i64 %28
%30 = bitcast double** %29 to i8**
%31 = load i8*, i8** %30
tail call void @free(i8* %31)
br label %26
32: ; preds = %20
tail call void @free(i8* %5)
br label %33
33: ; preds = %23, %8, %2, %32
%34 = phi double** [ null, %32 ], [ null, %2 ], [ %6, %8 ], [ %6, %23 ]
ret double** %34
}