#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 **tsp_init_grid_init(int x, int y) {
  int i, j;
  short **grid;
  grid = (short **)malloc(sizeof(short *) * x);
  for (i = 0; i < x; i++) {
    grid[i] = (short *)malloc(sizeof(short) * y);
    for (j = 0; j < y; j++) {
      grid[i][j] = 0;
    }
  }
  return grid;
}


x86 assembly (clang, -O0):
<tsp_init_grid_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11ac <tsp_init_grid_init+0x9c>
movslq -0x8(%rbp),%rax
shl    $0x1,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1199 <tsp_init_grid_init+0x89>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x10(%rbp),%rcx
movw   $0x0,(%rax,%rcx,2)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1169 <tsp_init_grid_init+0x59>
jmp    119e <tsp_init_grid_init+0x8e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1138 <tsp_init_grid_init+0x28>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tsp_init_grid_init>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebx
lea    0x0(,%rbx,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r13
test   %ebx,%ebx
jle    118a <tsp_init_grid_init+0x6a>
lea    (%r14,%r14,1),%r12d
mov    %r14d,%r15d
add    %r15,%r15
mov    %ebx,%ebx
xor    %ebp,%ebp
jmp    1169 <tsp_init_grid_init+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     118a <tsp_init_grid_init+0x6a>
mov    %r12d,%edi
call   1040 <malloc@plt>
mov    %rax,0x0(%r13,%rbp,8)
test   %r14d,%r14d
jle    1160 <tsp_init_grid_init+0x40>
mov    %rax,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1030 <memset@plt>
jmp    1160 <tsp_init_grid_init+0x40>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i16** @tsp_init_grid_init(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i16**
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = mul i64 8, %9
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i16**
store i16** %13, i16*** %7
store i32 0, i32* %5
br label %14
14: ; preds = %46, %2
%15 = load i32, i32* %5
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %49
18: ; preds = %14
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = mul i64 2, %20
%22 = trunc i64 %21 to i32
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i16*
%25 = load i16**, i16*** %7
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i16*, i16** %25, i64 %27
store i16* %24, i16** %28
store i32 0, i32* %6
br label %29
29: ; preds = %42, %18
%30 = load i32, i32* %6
%31 = load i32, i32* %4
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %45
33: ; preds = %29
%34 = load i16**, i16*** %7
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i16*, i16** %34, i64 %36
%38 = load i16*, i16** %37
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i16, i16* %38, i64 %40
store i16 0, i16* %41
br label %42
42: ; preds = %33
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
store i32 %44, i32* %6
br label %29
45: ; preds = %29
br label %46
46: ; preds = %45
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %14
49: ; preds = %14
%50 = load i16**, i16*** %7
ret i16** %50
}

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