#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 short *_malloc_(int);
unsigned short readShort();
unsigned short *readVtable(unsigned short size) {
  unsigned short *vtable = _malloc_(sizeof(unsigned short) * size);
  unsigned short count;
  if (!vtable) {
    return 0;
  }
  for (count = 0; count < size; count++) {
    vtable[count] = readShort();
  }
  return vtable;
}


x86 assembly (clang, -O0):
<readVtable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%eax
shl    $0x1,%rax
mov    %eax,%edi
call   1030 <_malloc_@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    115a <readVtable+0x3a>
movq   $0x0,-0x8(%rbp)
jmp    119f <readVtable+0x7f>
movw   $0x0,-0x1a(%rbp)
movzwl -0x1a(%rbp),%eax
movzwl -0xa(%rbp),%ecx
cmp    %ecx,%eax
jge    1197 <readVtable+0x77>
mov    $0x0,%al
call   1040 <readShort@plt>
mov    %ax,%dx
mov    -0x18(%rbp),%rax
movzwl -0x1a(%rbp),%ecx
mov    %dx,(%rax,%rcx,2)
mov    -0x1a(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x1a(%rbp)
jmp    1160 <readVtable+0x40>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readVtable>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%r14d
lea    (%r14,%r14,1),%edi
call   1030 <_malloc_@plt>
mov    %rax,%r15
test   %rax,%rax
je     1165 <readVtable+0x45>
test   %r14w,%r14w
je     1165 <readVtable+0x45>
movzwl %r14w,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <readShort@plt>
mov    %ax,(%r15,%rbx,2)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <readVtable+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i16* @readVtable(i16 zeroext %0) {
%2 = zext i16 %0 to i32
%3 = shl nuw nsw i32 %2, 1
%4 = tail call i16* @_malloc_(i32 %3)
%5 = icmp ne i16* %4, null
%6 = icmp ne i16 %0, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %16
8: ; preds = %1
%9 = zext i16 %0 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %14, %10 ]
%12 = tail call zeroext i16 (...) @readShort()
%13 = getelementptr inbounds i16, i16* %4, i64 %11
store i16 %12, i16* %13
%14 = add nuw nsw i64 %11, 1
%15 = icmp eq i64 %14, %9
br i1 %15, label %16, label %10
16: ; preds = %10, %1
ret i16* %4
}