#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);
short **allocGrid() {
  short i;
  short **array = malloc((100 - 20 - 1) * sizeof(short *));
  array[0] = malloc(((31 + 3) - 3 - 2) * (100 - 20 - 1) * sizeof(short));
  for (i = 1; i < (100 - 20 - 1); i++) {
    array[i] = array[0] + i * ((31 + 3) - 3 - 2);
  }
  return array;
}


x86 assembly (clang, -O0):
<allocGrid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x278,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x11e6,%edi
call   1030 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movw   $0x1,-0x2(%rbp)
movswl -0x2(%rbp),%eax
cmp    $0x4f,%eax
jge    1182 <allocGrid+0x72>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
movswl -0x2(%rbp),%eax
imul   $0x1d,%eax,%eax
cltq
shl    $0x1,%rax
add    %rax,%rdx
mov    -0x10(%rbp),%rax
movswq -0x2(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x2(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x2(%rbp)
jmp    1140 <allocGrid+0x30>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocGrid>:
push   %rbx
mov    $0x278,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
mov    $0x11e6,%edi
call   1030 <malloc@plt>
mov    %rax,(%rbx)
mov    %rbx,%rcx
add    $0x30,%rcx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    (%rax,%rdx,1),%rsi
add    $0x3a,%rsi
mov    %rsi,-0x28(%rcx)
lea    0x74(%rax,%rdx,1),%rsi
mov    %rsi,-0x20(%rcx)
lea    0xae(%rax,%rdx,1),%rsi
mov    %rsi,-0x18(%rcx)
lea    0xe8(%rax,%rdx,1),%rsi
mov    %rsi,-0x10(%rcx)
lea    0x122(%rax,%rdx,1),%rsi
mov    %rsi,-0x8(%rcx)
lea    (%rax,%rdx,1),%rsi
add    $0x15c,%rsi
mov    %rsi,(%rcx)
add    $0x15c,%rdx
add    $0x30,%rcx
cmp    $0x11ac,%rdx
jne    1140 <allocGrid+0x30>
mov    %rbx,%rax
pop    %rbx
ret

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

LLVM IR (-O2):
define noalias i16** @allocGrid() {
%1 = tail call dereferenceable_or_null(632) i8* @malloc(i32 632)
%2 = bitcast i8* %1 to i16**
%3 = tail call dereferenceable_or_null(4582) i8* @malloc(i32 4582)
%4 = bitcast i8* %1 to i8**
store i8* %3, i8** %4
%5 = bitcast i8* %3 to i16*
br label %6
6: ; preds = %6, %0
%7 = phi i64 [ 1, %0 ], [ %31, %6 ]
%8 = mul nuw nsw i64 %7, 29
%9 = getelementptr inbounds i16, i16* %5, i64 %8
%10 = getelementptr inbounds i16*, i16** %2, i64 %7
store i16* %9, i16** %10
%11 = add nuw nsw i64 %7, 1
%12 = mul nuw nsw i64 %11, 29
%13 = getelementptr inbounds i16, i16* %5, i64 %12
%14 = getelementptr inbounds i16*, i16** %2, i64 %11
store i16* %13, i16** %14
%15 = add nuw nsw i64 %7, 2
%16 = mul nuw nsw i64 %15, 29
%17 = getelementptr inbounds i16, i16* %5, i64 %16
%18 = getelementptr inbounds i16*, i16** %2, i64 %15
store i16* %17, i16** %18
%19 = add nuw nsw i64 %7, 3
%20 = mul nuw nsw i64 %19, 29
%21 = getelementptr inbounds i16, i16* %5, i64 %20
%22 = getelementptr inbounds i16*, i16** %2, i64 %19
store i16* %21, i16** %22
%23 = add nuw nsw i64 %7, 4
%24 = mul nuw nsw i64 %23, 29
%25 = getelementptr inbounds i16, i16* %5, i64 %24
%26 = getelementptr inbounds i16*, i16** %2, i64 %23
store i16* %25, i16** %26
%27 = add nuw nsw i64 %7, 5
%28 = mul nuw nsw i64 %27, 29
%29 = getelementptr inbounds i16, i16* %5, i64 %28
%30 = getelementptr inbounds i16*, i16** %2, i64 %27
store i16* %29, i16** %30
%31 = add nuw nsw i64 %7, 6
%32 = icmp eq i64 %31, 79
br i1 %32, label %33, label %6
33: ; preds = %6
ret i16** %2
}