#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 */
void *my_calloc(int, size_t);
void **calloc_2D(int dim1, int dim2, size_t si) {
  int i;
  void **array = NULL;
  array = my_calloc(dim1, si);
  for (i = 0; i < dim1; i++)
    array[i] = my_calloc(dim2, si);
  return array;
}


x86 assembly (clang, -O0):
<calloc_2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <my_calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1176 <calloc_2D+0x66>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <my_calloc@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <calloc_2D+0x31>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calloc_2D>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %esi,%r14d
mov    %edi,%r15d
mov    %rdx,%rsi
call   1030 <my_calloc@plt>
mov    %rax,%r13
test   %r15d,%r15d
jle    1159 <calloc_2D+0x49>
mov    %r15d,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %r12,%rsi
call   1030 <my_calloc@plt>
mov    %rax,0x0(%r13,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1140 <calloc_2D+0x30>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8** @calloc_2D(i32 %0, i32 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8**
store i32 %0, i32* %4
store i32 %1, i32* %5
store i64 %2, i64* %6
store i8** null, i8*** %8
%9 = load i32, i32* %4
%10 = load i64, i64* %6
%11 = call i8* @my_calloc(i32 %9, i64 %10)
%12 = bitcast i8* %11 to i8**
store i8** %12, i8*** %8
store i32 0, i32* %7
br label %13
13: ; preds = %25, %3
%14 = load i32, i32* %7
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %28
17: ; preds = %13
%18 = load i32, i32* %5
%19 = load i64, i64* %6
%20 = call i8* @my_calloc(i32 %18, i64 %19)
%21 = load i8**, i8*** %8
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
store i8* %20, i8** %24
br label %25
25: ; preds = %17
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 1
store i32 %27, i32* %7
br label %13
28: ; preds = %13
%29 = load i8**, i8*** %8
ret i8** %29
}

LLVM IR (-O2):
define i8** @calloc_2D(i32 %0, i32 %1, i64 %2) {
%4 = tail call i8* @my_calloc(i32 %0, i64 %2)
%5 = bitcast i8* %4 to i8**
%6 = icmp sgt i32 %0, 0
br i1 %6, label %7, label %15
7: ; preds = %3
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %13, %9 ]
%11 = tail call i8* @my_calloc(i32 %1, i64 %2)
%12 = getelementptr inbounds i8*, i8** %5, i64 %10
store i8* %11, i8** %12
%13 = add nuw nsw i64 %10, 1
%14 = icmp eq i64 %13, %8
br i1 %14, label %15, label %9
15: ; preds = %9, %3
ret i8** %5
}