#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 */
unsigned int *allocArray1D(size_t);
scalar_t__ malloc(size_t);
int **allocArray2D(size_t rows, size_t cols) {
  unsigned int **arr = (int **)malloc(rows * sizeof(int *)), i;
  for (i = 0; i < rows; i++)
    arr[i] = allocArray1D(cols);
  return arr;
}


x86 assembly (clang, -O0):
<allocArray2D>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
shl    $0x3,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%rax
jae    117a <allocArray2D+0x5a>
mov    -0x10(%rbp),%rdi
call   1030 <allocArray1D@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1148 <allocArray2D+0x28>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocArray2D>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x0(,%rdi,8),%rdi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %r15,%r15
je     1164 <allocArray2D+0x44>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1030 <allocArray1D@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%ebx
cmp    %r15,%rbx
jb     1150 <allocArray2D+0x30>
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32** @allocArray2D(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32**
%6 = alloca i32
store i64 %0, i64* %3
store i64 %1, i64* %4
%7 = load i64, i64* %3
%8 = mul i64 %7, 8
%9 = call i64 @malloc(i64 %8)
%10 = inttoptr i64 %9 to i32**
store i32** %10, i32*** %5
store i32 0, i32* %6
br label %11
11: ; preds = %23, %2
%12 = load i32, i32* %6
%13 = zext i32 %12 to i64
%14 = load i64, i64* %3
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = load i64, i64* %4
%18 = call i32* @allocArray1D(i64 %17)
%19 = load i32**, i32*** %5
%20 = load i32, i32* %6
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i32*, i32** %19, i64 %21
store i32* %18, i32** %22
br label %23
23: ; preds = %16
%24 = load i32, i32* %6
%25 = add i32 %24, 1
store i32 %25, i32* %6
br label %11
26: ; preds = %11
%27 = load i32**, i32*** %5
ret i32** %27
}

LLVM IR (-O2):
define i32** @allocArray2D(i64 %0, i64 %1) {
%3 = shl i64 %0, 3
%4 = tail call i64 @malloc(i64 %3)
%5 = inttoptr i64 %4 to i32**
%6 = icmp eq i64 %0, 0
br i1 %6, label %14, label %7
7: ; preds = %2, %7
%8 = phi i64 [ %12, %7 ], [ 0, %2 ]
%9 = tail call i32* @allocArray1D(i64 %1)
%10 = getelementptr inbounds i32*, i32** %5, i64 %8
store i32* %9, i32** %10
%11 = add nuw nsw i64 %8, 1
%12 = and i64 %11, 4294967295
%13 = icmp ult i64 %12, %0
br i1 %13, label %7, label %14
14: ; preds = %7, %2
ret i32** %5
}