#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
void load_file_content(const char *filename, char *content, size_t size) {
  FILE *fp = fopen(filename, "r");
  if (!fp) {
    fprintf(stderr, "ERROR OPENING THE FILE %s : not found\n", filename);
    exit(EXIT_FAILURE);
  }
  size_t i = 0;
  while (i < size) {
    content[i] = fgetc(fp);
    i++;
  }
  fclose(fp);
  fflush(fp);
}


x86 assembly (clang, -O0):
<load_file_content>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ba <load_file_content+0x5a>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5b(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11f7 <load_file_content+0x97>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11c2 <load_file_content+0x62>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1060 <fflush@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_file_content>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11be <load_file_content+0x5e>
mov    %rax,%r13
test   %r15,%r15
je     11a5 <load_file_content+0x45>
xor    %ebx,%ebx
nopl   (%rax)
mov    %r13,%rdi
call   1040 <fgetc@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1190 <load_file_content+0x30>
mov    %r13,%rdi
call   1030 <fclose@plt>
mov    %r13,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1060 <fflush@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
mov    %r12,%rdx
call   1050 <fprintf@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"ERROR OPENING THE FILE %s : not found\0A\00"
@EXIT_FAILURE = global i32 0
define void @load_file_content(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %19, label %13
13: ; preds = %3
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %4
%16 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %3
store i64 0, i64* %8
br label %20
20: ; preds = %24, %19
%21 = load i64, i64* %8
%22 = load i64, i64* %6
%23 = icmp ult i64 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i32*, i32** %7
%26 = call signext i8 @fgetc(i32* %25)
%27 = load i8*, i8** %5
%28 = load i64, i64* %8
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8 %26, i8* %29
%30 = load i64, i64* %8
%31 = add i64 %30, 1
store i64 %31, i64* %8
br label %20
32: ; preds = %20
%33 = load i32*, i32** %7
%34 = call i32 @fclose(i32* %33)
%35 = load i32*, i32** %7
%36 = call i32 @fflush(i32* %35)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"ERROR OPENING THE FILE %s : not found\0A\00"
@EXIT_FAILURE = global i32 0
define void @load_file_content(i8* %0, i8* nocapture writeonly %1, i64 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = icmp eq i64 %2, 0
br i1 %7, label %19, label %13
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %6, %13
%14 = phi i64 [ %17, %13 ], [ 0, %6 ]
%15 = tail call signext i8 @fgetc(i32* %4)
%16 = getelementptr inbounds i8, i8* %1, i64 %14
store i8 %15, i8* %16
%17 = add nuw i64 %14, 1
%18 = icmp eq i64 %17, %2
br i1 %18, label %19, label %13
19: ; preds = %13, %6
%20 = tail call i32 @fclose(i32* %4)
%21 = tail call i32 @fflush(i32* %4)
ret void
}