#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 *malloc(int);
void **malloc_matrix(int n, int m, int size) {
  void **matrix = (void **)malloc(n * sizeof(void *));
  int i;
  for (i = 0; i < n; i++) {
    matrix[i] = malloc(m * size);
  }
  return matrix;
}


x86 assembly (clang, -O0):
<malloc_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1170 <malloc_matrix+0x60>
mov    -0x8(%rbp),%edi
imul   -0xc(%rbp),%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113b <malloc_matrix+0x2b>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<malloc_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %esi,%r14d
mov    %edi,%r15d
lea    0x0(,%r15,8),%edi
call   1030 <malloc@plt>
mov    %rax,%r13
test   %r15d,%r15d
jle    1166 <malloc_matrix+0x56>
imul   %r14d,%r12d
mov    %r15d,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12d,%edi
call   1030 <malloc@plt>
mov    %rax,0x0(%r13,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <malloc_matrix+0x40>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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