#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__ calloc(int, int);
int /*<<< orphan*/ memoryCheck();
short int *allocateShortVector(int n) {
  int i;
  short int *vector;
  if ((vector = (short int *)calloc(n, sizeof(short int))) == NULL)
    memoryCheck();
  for (i = 0; i < n; i++)
    vector[i] = 0.0;
  return vector;
}


x86 assembly (clang, -O0):
<allocateShortVector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x2,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    114d <allocateShortVector+0x2d>
mov    $0x0,%al
call   1040 <memoryCheck@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    117c <allocateShortVector+0x5c>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movw   $0x0,(%rax,%rcx,2)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1154 <allocateShortVector+0x34>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<allocateShortVector>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x2,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1164 <allocateShortVector+0x34>
test   %ebp,%ebp
jle    115a <allocateShortVector+0x2a>
mov    %ebp,%edx
add    %rdx,%rdx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1050 <memoryCheck@plt>
test   %ebp,%ebp
jg     114b <allocateShortVector+0x1b>
jmp    115a <allocateShortVector+0x2a>

LLVM IR (-O0):
define i16* @allocateShortVector(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i16*
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i64 @calloc(i32 %5, i32 2)
%7 = inttoptr i64 %6 to i16*
store i16* %7, i16** %4
%8 = icmp eq i16* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 (...) @memoryCheck()
br label %11
11: ; preds = %9, %1
store i32 0, i32* %3
br label %12
12: ; preds = %21, %11
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %12
%17 = load i16*, i16** %4
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i16, i16* %17, i64 %19
store i16 0, i16* %20
br label %21
21: ; preds = %16
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
br label %12
24: ; preds = %12
%25 = load i16*, i16** %4
ret i16* %25
}

LLVM IR (-O2):
define i16* @allocateShortVector(i32 %0) {
%2 = tail call i64 @calloc(i32 %0, i32 2)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 (...) @memoryCheck()
br label %7
7: ; preds = %5, %1
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = zext i32 %0 to i64
%11 = shl nuw nsw i64 %10, 1
br label %12
12: ; preds = %9, %7
%13 = inttoptr i64 %2 to i16*
ret i16* %13
}