#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 *readClassInterfaces(unsigned short length) {
  unsigned short *interfaces;
  unsigned short count = 0;
  interfaces = _malloc_(sizeof(unsigned short) * (length + 1));
  if (!interfaces) {
    return 0;
  }
  interfaces[count] = length;
  for (count = 1; count < length + 1; count++) {
    interfaces[count] = readShort();
  }
  return interfaces;
}


x86 assembly (clang, -O0):
<readClassInterfaces>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0xa(%rbp)
movw   $0x0,-0x1a(%rbp)
movzwl -0xa(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x1,%rax
mov    %eax,%edi
call   1030 <_malloc_@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1165 <readClassInterfaces+0x45>
movq   $0x0,-0x8(%rbp)
jmp    11bd <readClassInterfaces+0x9d>
mov    -0xa(%rbp),%dx
mov    -0x18(%rbp),%rax
movzwl -0x1a(%rbp),%ecx
mov    %dx,(%rax,%rcx,2)
movw   $0x1,-0x1a(%rbp)
movzwl -0x1a(%rbp),%eax
movzwl -0xa(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11b5 <readClassInterfaces+0x95>
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    117b <readClassInterfaces+0x5b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readClassInterfaces>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%r14d
lea    (%r14,%r14,1),%edi
add    $0x2,%edi
call   1030 <_malloc_@plt>
mov    %rax,%r15
test   %rax,%rax
je     1168 <readClassInterfaces+0x48>
mov    %r14w,(%r15)
test   %r14w,%r14w
je     1168 <readClassInterfaces+0x48>
mov    $0x1,%bx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <readShort@plt>
movzwl %bx,%ecx
mov    %ax,(%r15,%rcx,2)
add    $0x1,%ebx
cmp    %r14w,%bx
jbe    1150 <readClassInterfaces+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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