#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
unsigned char *load_textfile(char *fvalue, int size) {
  0;
  unsigned char *buffer = (unsigned char *)malloc(size + 1);
  int i, rc;
  for (i = 0; i < size; i++)
    buffer[i] = 0x0;
  FILE *fp = fopen(fvalue, "rb");
  if (fp == NULL) {
    0;
    return 0;
  }
  for (i = 0; i < size; i++) {
    rc = getc(fp);
    buffer[i] = rc;
  }
  0;
  fclose(fp);
  return buffer;
}


x86 assembly (clang, -O0):
<load_textfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    118b <load_textfile+0x4b>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1165 <load_textfile+0x25>
mov    -0x10(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11b7 <load_textfile+0x77>
movq   $0x0,-0x8(%rbp)
jmp    1205 <load_textfile+0xc5>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f4 <load_textfile+0xb4>
mov    -0x30(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11be <load_textfile+0x7e>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_textfile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r12
lea    0x1(%rbx),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
jle    11b7 <load_textfile+0x67>
mov    %ebx,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1040 <memset@plt>
lea    0xe7d(%rip),%rsi
mov    %r12,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11d8 <load_textfile+0x88>
mov    %rax,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1070 <getc@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11a0 <load_textfile+0x50>
jmp    11ce <load_textfile+0x7e>
lea    0xe42(%rip),%rsi
mov    %r12,%rdi
call   1060 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
je     11d8 <load_textfile+0x88>
mov    %r12,%rdi
call   1030 <fclose@plt>
jmp    11db <load_textfile+0x8b>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i8* @load_textfile(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 1
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %6
store i32 0, i32* %7
br label %14
14: ; preds = %23, %2
%15 = load i32, i32* %7
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %26
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
br label %23
23: ; preds = %18
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %14
26: ; preds = %14
%27 = load i8*, i8** %4
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %28, i32** %9
%29 = load i32*, i32** %9
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %32
31: ; preds = %26
store i8* null, i8** %3
br label %53
32: ; preds = %26
store i32 0, i32* %7
br label %33
33: ; preds = %46, %32
%34 = load i32, i32* %7
%35 = load i32, i32* %5
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %49
37: ; preds = %33
%38 = load i32*, i32** %9
%39 = call i32 @getc(i32* %38)
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = trunc i32 %40 to i8
%42 = load i8*, i8** %6
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
store i8 %41, i8* %45
br label %46
46: ; preds = %37
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
br label %33
49: ; preds = %33
%50 = load i32*, i32** %9
%51 = call i32 @fclose(i32* %50)
%52 = load i8*, i8** %6
store i8* %52, i8** %3
br label %53
53: ; preds = %49, %31
%54 = load i8*, i8** %3
ret i8* %54
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i8* @load_textfile(i8* nocapture %0, i32 %1) {
%3 = add nsw i32 %1, 1
%4 = tail call i64 @malloc(i32 %3)
%5 = inttoptr i64 %4 to i8*
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = zext i32 %1 to i64
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %26, label %14
11: ; preds = %2
%12 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %26, label %23
14: ; preds = %7
%15 = zext i32 %1 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %21, %16 ]
%18 = tail call i32 @getc(i32* %9)
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds i8, i8* %5, i64 %17
store i8 %19, i8* %20
%21 = add nuw nsw i64 %17, 1
%22 = icmp eq i64 %21, %15
br i1 %22, label %23, label %16
23: ; preds = %16, %11
%24 = phi i32* [ %12, %11 ], [ %9, %16 ]
%25 = tail call i32 @fclose(i32* %24)
br label %26
26: ; preds = %11, %7, %23
%27 = phi i8* [ %5, %23 ], [ null, %7 ], [ null, %11 ]
ret i8* %27
}