#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ malloc(int);
scalar_t__ readUInt8(int /*<<< orphan*/ *);
char *readBytes(FILE *f, int size) {
  int i;
  char *buf;
  buf = (char *)malloc(sizeof(char) * size);
  for (i = 0; i < size; i++) {
    buf[i] = (char)readUInt8(f);
  }
  return buf;
}


x86 assembly (clang, -O0):
<readBytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1179 <readBytes+0x59>
mov    -0x8(%rbp),%rdi
call   1030 <readUInt8@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    1149 <readBytes+0x29>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readBytes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    1155 <readBytes+0x35>
mov    %ebp,%ebp
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <readUInt8@plt>
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <readBytes+0x20>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @readBytes(i32* %0, i32 %1) {
%3 = tail call i64 @malloc(i32 %1)
%4 = inttoptr i64 %3 to i8*
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %13, %8 ]
%10 = tail call i64 @readUInt8(i32* %0)
%11 = trunc i64 %10 to i8
%12 = getelementptr inbounds i8, i8* %4, i64 %9
store i8 %11, i8* %12
%13 = add nuw nsw i64 %9, 1
%14 = icmp eq i64 %13, %7
br i1 %14, label %15, label %8
15: ; preds = %8, %2
ret i8* %4
}