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


x86 assembly (clang, -O0):
<ShareMallocM2c>:
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   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1187 <ShareMallocM2c+0x47>
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
jle    11ce <ShareMallocM2c+0x8e>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c9 <ShareMallocM2c+0x89>
mov    -0x8(%rbp),%edi
call   1050 <ShareMallocM1c@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 <ShareMallocM2c+0x58>
jmp    11ce <ShareMallocM2c+0x8e>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@.str = [23 x i8] c"char ** malloc error!\0A\00"
define i8** @ShareMallocM2c(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8** null, i8*** %6
%7 = load i32, i32* %3
%8 = call i64 @calloc(i32 %7, i32 8)
%9 = inttoptr i64 %8 to i8**
store i8** %9, i8*** %6
%10 = icmp eq i8** %9, null
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 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 i8* @ShareMallocM1c(i32 %23)
%25 = load i8**, i8*** %6
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
store i8* %24, i8** %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 i8**, i8*** %6
ret i8** %34
}

LLVM IR (-O2):
@str = [22 x i8] c"char ** malloc error!\00"
define i8** @ShareMallocM2c(i32 %0, i32 %1) {
%3 = tail call i64 @calloc(i32 %0, i32 8)
%4 = inttoptr i64 %3 to i8**
%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 ([22 x i8], [22 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 i8* @ShareMallocM1c(i32 %1)
%18 = getelementptr inbounds i8*, i8** %4, i64 %16
store i8* %17, i8** %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 i8** %4
}