#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);
short **allocate_matrix(short **matrix, int size_x, int size_y) {
  int i;
  matrix = (short **)malloc(size_x * sizeof(short *));
  for (i = 0; i < size_x; ++i) {
    matrix[i] = (short *)malloc(size_y * sizeof(short));
  }
  return matrix;
}


x86 assembly (clang, -O0):
<allocate_matrix>:
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   1030 <malloc@plt>
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1174 <allocate_matrix+0x64>
movslq -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113c <allocate_matrix+0x2c>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocate_matrix>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %esi,%r14d
lea    0x0(,%r14,8),%edi
call   1030 <malloc@plt>
mov    %rax,%r12
test   %r14d,%r14d
jle    1155 <allocate_matrix+0x45>
add    %r15d,%r15d
mov    %r14d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
call   1030 <malloc@plt>
mov    %rax,(%r12,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <allocate_matrix+0x30>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i16** @allocate_matrix(i16** %0, i32 %1, i32 %2) {
%4 = alloca i16**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i16** %0, i16*** %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 i16**
store i16** %13, i16*** %4
store i32 0, i32* %7
br label %14
14: ; preds = %29, %3
%15 = load i32, i32* %7
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %32
18: ; preds = %14
%19 = load i32, i32* %6
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 2
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i16*
%25 = load i16**, i16*** %4
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i16*, i16** %25, i64 %27
store i16* %24, i16** %28
br label %29
29: ; preds = %18
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %14
32: ; preds = %14
%33 = load i16**, i16*** %4
ret i16** %33
}

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