#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
char *malloc(long);
int /*<<< orphan*/ printf(char *, char *);
char *_dcontent_from_file(char *filename) {
  FILE *file = fopen(filename, "rb");
  if (file != NULL) {
    fseek(file, 0, SEEK_END);
    long size = ftell(file);
    fseek(file, 0, SEEK_SET);
    char *content = malloc(size + 1);
    for (int i = 0; i < size; i++) {
      content[i] = fgetc(file);
    }
    content[size] = '\0';
    fclose(file);
    return content;
  } else {
    printf("Unable to open: %s.\n", filename);
    return "";
  }
}


x86 assembly (clang, -O0):
<_dcontent_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     123c <_dcontent_from_file+0xcc>
mov    -0x18(%rbp),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x20(%rbp),%rax
jge    121a <_dcontent_from_file+0xaa>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,%dl
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e8 <_dcontent_from_file+0x78>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1257 <_dcontent_from_file+0xe7>
mov    -0x10(%rbp),%rsi
lea    0xdbc(%rip),%rdi
call   1040 <printf@plt>
lea    0xdc4(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_dcontent_from_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe7e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1204 <_dcontent_from_file+0x94>
mov    %rax,%r14
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r14,%rdi
call   1060 <ftell@plt>
mov    %rax,%r15
mov    0x2e24(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
lea    0x1(%r15),%rdi
call   1070 <malloc@plt>
mov    %rax,%r12
test   %r15,%r15
jle    11f5 <_dcontent_from_file+0x85>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11e0 <_dcontent_from_file+0x70>
movb   $0x0,(%r12,%r15,1)
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    121a <_dcontent_from_file+0xaa>
lea    0xdf8(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xdfd(%rip),%r12
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [21 x i8] c"Unable to open: %s.\0A\00"
@.str.2 = [1 x i8] zeroinitializer
define i8* @_dcontent_from_file(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %22, label %4
4: ; preds = %1
%5 = load i32, i32* @SEEK_END
%6 = tail call i32 @fseek(i32* %2, i32 0, i32 %5)
%7 = tail call i64 @ftell(i32* %2)
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @fseek(i32* %2, i32 0, i32 %8)
%10 = add nsw i64 %7, 1
%11 = tail call i8* @malloc(i64 %10)
%12 = icmp sgt i64 %7, 0
br i1 %12, label %16, label %13
13: ; preds = %16, %4
%14 = getelementptr inbounds i8, i8* %11, i64 %7
store i8 0, i8* %14
%15 = tail call i32 @fclose(i32* %2)
br label %24
16: ; preds = %4, %16
%17 = phi i64 [ %20, %16 ], [ 0, %4 ]
%18 = tail call signext i8 @fgetc(i32* %2)
%19 = getelementptr inbounds i8, i8* %11, i64 %17
store i8 %18, i8* %19
%20 = add nuw nsw i64 %17, 1
%21 = icmp eq i64 %20, %7
br i1 %21, label %13, label %16
22: ; preds = %1
%23 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %24
24: ; preds = %22, %13
%25 = phi i8* [ %11, %13 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), %22 ]
ret i8* %25
}