#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int, int);
void allocate(int ***array, int r, int c) {
  int i;
  *array = (int **)malloc(r * sizeof(int *));
  for (i = 0; i < r; i++)
    (*array)[i] = (int *)malloc(c * sizeof(int));
  printf("Allocated memory dynamically for array[%d][%d]\n", r, c);
}


x86 assembly (clang, -O0):
<allocate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118d <allocate+0x6d>
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1152 <allocate+0x32>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe66(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %esi,%r15d
mov    %rdi,%r12
lea    0x0(,%r15,8),%edi
call   1040 <malloc@plt>
mov    %rax,(%r12)
test   %r15d,%r15d
jle    1179 <allocate+0x59>
lea    0x0(,%r14,4),%r13d
mov    %r15d,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edi
call   1040 <malloc@plt>
mov    (%r12),%rcx
mov    %rax,(%rcx,%rbp,8)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <allocate+0x40>
lea    0xe80(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"Allocated memory dynamically for array[%d][%d]\0A\00"
define void @allocate(i32*** %0, i32 %1, i32 %2) {
%4 = alloca i32***
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32*** %0, i32**** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = sext i32 %8 to i64
%10 = mul i64 %9, 8
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i32**
%14 = load i32***, i32**** %4
store i32** %13, i32*** %14
store i32 0, i32* %7
br label %15
15: ; preds = %31, %3
%16 = load i32, i32* %7
%17 = load i32, i32* %5
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %34
19: ; preds = %15
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 4
%23 = trunc i64 %22 to i32
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i32*
%26 = load i32***, i32**** %4
%27 = load i32**, i32*** %26
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32*, i32** %27, i64 %29
store i32* %25, i32** %30
br label %31
31: ; preds = %19
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %15
34: ; preds = %15
%35 = load i32, i32* %5
%36 = load i32, i32* %6
%37 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %35, i32 %36)
ret void
}

LLVM IR (-O2):
@.str = [48 x i8] c"Allocated memory dynamically for array[%d][%d]\0A\00"
define void @allocate(i32*** nocapture %0, i32 %1, i32 %2) {
%4 = shl i32 %1, 3
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i32**
store i32** %6, i32*** %0
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %19
8: ; preds = %3
%9 = shl i32 %2, 2
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %8, %11
%12 = phi i64 [ 0, %8 ], [ %17, %11 ]
%13 = tail call i64 @malloc(i32 %9)
%14 = inttoptr i64 %13 to i32*
%15 = load i32**, i32*** %0
%16 = getelementptr inbounds i32*, i32** %15, i64 %12
store i32* %14, i32** %16
%17 = add nuw nsw i64 %12, 1
%18 = icmp eq i64 %17, %10
br i1 %18, label %19, label %11
19: ; preds = %11, %3
%20 = tail call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
ret void
}