#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 *malloc(unsigned int);
void init_matrix(unsigned int ***matrix, unsigned int x, unsigned int y) {
  *matrix = (unsigned int **)malloc(y * sizeof(unsigned int *));
  for (; y > 0; --y) {
    (*matrix)[y - 1] = malloc(x * sizeof(unsigned int));
  }
}


x86 assembly (clang, -O0):
<init_matrix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
cmpl   $0x0,-0x10(%rbp)
jbe    1176 <init_matrix+0x66>
mov    -0xc(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    %rdx,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    113a <init_matrix+0x2a>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %esi,%r13d
mov    %rdi,%r14
lea    0x0(,%r12,8),%edi
call   1030 <malloc@plt>
mov    %rax,(%r14)
test   %r12d,%r12d
je     117a <init_matrix+0x6a>
mov    %rax,%r15
shl    $0x2,%r13d
mov    %r12d,%ebx
mov    %r13d,%edi
call   1030 <malloc@plt>
mov    %rbx,%rcx
mov    %rax,-0x8(%r15,%rbx,8)
add    $0xffffffffffffffff,%rcx
je     117a <init_matrix+0x6a>
nopl   0x0(%rax)
mov    (%r14),%rbp
mov    %r13d,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp,%rbx,8)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jne    1160 <init_matrix+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @init_matrix(i32*** nocapture %0, i32 %1, i32 %2) {
%4 = shl i32 %2, 3
%5 = tail call i32* @malloc(i32 %4)
%6 = bitcast i32*** %0 to i32**
store i32* %5, i32** %6
%7 = icmp eq i32 %2, 0
br i1 %7, label %23, label %8
8: ; preds = %3
%9 = bitcast i32* %5 to i32**
%10 = shl i32 %1, 2
%11 = zext i32 %2 to i64
%12 = tail call i32* @malloc(i32 %10)
%13 = add nsw i64 %11, -1
%14 = getelementptr inbounds i32*, i32** %9, i64 %13
store i32* %12, i32** %14
%15 = icmp eq i64 %13, 0
br i1 %15, label %23, label %16
16: ; preds = %8, %16
%17 = phi i64 [ %20, %16 ], [ %13, %8 ]
%18 = load i32**, i32*** %0
%19 = tail call i32* @malloc(i32 %10)
%20 = add nsw i64 %17, -1
%21 = getelementptr inbounds i32*, i32** %18, i64 %20
store i32* %19, i32** %21
%22 = icmp eq i64 %20, 0
br i1 %22, label %23, label %16
23: ; preds = %16, %8, %3
ret void
}