#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 *ShareMallocM1d(int);
scalar_t__ calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
double **ShareMallocM2d(int size1, int size2) {
  int i;
  double **s = NULL;
  if ((s = (double **)calloc(size1, sizeof(double *))) == NULL) {
    printf("double ** malloc error!\n");
    exit(1);
  }
  if (size2 > 0) {
    for (i = 0; i < size1; i++)
      s[i] = ShareMallocM1d(size2);
  }
  return s;
}


x86 assembly (clang, -O0):
<ShareMallocM2d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1187 <ShareMallocM2d+0x47>
lea    0xe88(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
jle    11ce <ShareMallocM2d+0x8e>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c9 <ShareMallocM2d+0x89>
mov    -0x8(%rbp),%edi
call   1030 <ShareMallocM1d@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1198 <ShareMallocM2d+0x58>
jmp    11ce <ShareMallocM2d+0x8e>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ShareMallocM2d>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
mov    $0x8,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     1191 <ShareMallocM2d+0x51>
mov    %rax,%r12
test   %r15d,%r15d
jle    1185 <ShareMallocM2d+0x45>
test   %r14d,%r14d
jle    1185 <ShareMallocM2d+0x45>
mov    %r14d,%ebp
xor    %ebx,%ebx
nop
mov    %r15d,%edi
call   1030 <ShareMallocM1d@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1170 <ShareMallocM2d+0x30>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe68(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"double ** malloc error!\0A\00"
define double** @ShareMallocM2d(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
store double** null, double*** %6
%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 = icmp eq double** %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %33
17: ; preds = %14
store i32 0, i32* %5
br label %18
18: ; preds = %29, %17
%19 = load i32, i32* %5
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i32, i32* %4
%24 = call double* @ShareMallocM1d(i32 %23)
%25 = load double**, double*** %6
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds double*, double** %25, i64 %27
store double* %24, double** %28
br label %29
29: ; preds = %22
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %18
32: ; preds = %18
br label %33
33: ; preds = %32, %14
%34 = load double**, double*** %6
ret double** %34
}

LLVM IR (-O2):
@str = [24 x i8] c"double ** malloc error!\00"
define double** @ShareMallocM2d(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 %6, label %9
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = icmp sgt i32 %1, 0
%11 = icmp sgt i32 %0, 0
%12 = and i1 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = zext i32 %0 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %19, %15 ]
%17 = tail call double* @ShareMallocM1d(i32 %1)
%18 = getelementptr inbounds double*, double** %4, i64 %16
store double* %17, double** %18
%19 = add nuw nsw i64 %16, 1
%20 = icmp eq i64 %19, %14
br i1 %20, label %21, label %15
21: ; preds = %15, %9
ret double** %4
}