#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 char *_malloc_(unsigned short);
unsigned char readByte();
unsigned char *readCode(unsigned short codeSize) {
  if (codeSize > 0) {
    int count;
    unsigned char *code = _malloc_(codeSize);
    if (!code) {
      return 0;
    }
    for (count = 0; count < codeSize; count++) {
      code[count] = readByte();
    }
    return code;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<readCode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0xa(%rbp)
movzwl -0xa(%rbp),%eax
cmp    $0x0,%eax
jle    11a6 <readCode+0x86>
movzwl -0xa(%rbp),%edi
call   1030 <_malloc_@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1161 <readCode+0x41>
movq   $0x0,-0x8(%rbp)
jmp    11ae <readCode+0x8e>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
movzwl -0xa(%rbp),%ecx
cmp    %ecx,%eax
jge    1199 <readCode+0x79>
mov    $0x0,%al
call   1040 <readByte@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1168 <readCode+0x48>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ae <readCode+0x8e>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readCode>:
push   %r15
push   %r14
push   %rbx
test   %edi,%edi
je     1156 <readCode+0x36>
movzwl %di,%r15d
mov    %r15d,%edi
call   1030 <_malloc_@plt>
test   %rax,%rax
je     1156 <readCode+0x36>
mov    %rax,%r14
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1040 <readByte@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <readCode+0x20>
jmp    1159 <readCode+0x39>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @readCode(i16 zeroext %0) {
%2 = alloca i8*
%3 = alloca i16
%4 = alloca i32
%5 = alloca i8*
store i16 %0, i16* %3
%6 = load i16, i16* %3
%7 = zext i16 %6 to i32
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %32
9: ; preds = %1
%10 = load i16, i16* %3
%11 = call i8* @_malloc_(i16 zeroext %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %9
store i8* null, i8** %2
br label %33
15: ; preds = %9
store i32 0, i32* %4
br label %16
16: ; preds = %27, %15
%17 = load i32, i32* %4
%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 = %16
%22 = call zeroext i8 (...) @readByte()
%23 = load i8*, i8** %5
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 %22, i8* %26
br label %27
27: ; preds = %21
%28 = load i32, i32* %4
%29 = add nsw i32 %28, 1
store i32 %29, i32* %4
br label %16
30: ; preds = %16
%31 = load i8*, i8** %5
store i8* %31, i8** %2
br label %33
32: ; preds = %1
store i8* null, i8** %2
br label %33
33: ; preds = %32, %30, %14
%34 = load i8*, i8** %2
ret i8* %34
}

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