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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ fs_exsists(char const *);
int /*<<< orphan*/ fs_filesize(char const *);
char *malloc(int /*<<< orphan*/);
char *restrict read_string_from_file(const char *restrict filename) {
  FILE *file_stream = NULL;
  char *restrict file_content;
  off_t file_size = 0;
  if (fs_exsists(filename)) {
    file_size = fs_filesize(filename);
    file_content = malloc(file_size);
    file_stream = fopen(filename, "r");
    fread(file_content, 1, file_size, file_stream);
    fclose(file_stream);
    return file_content;
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_string_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <fs_exsists@plt>
cmp    $0x0,%rax
je     11e5 <read_string_from_file+0x85>
mov    -0x10(%rbp),%rdi
call   1070 <fs_filesize@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ed <read_string_from_file+0x8d>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_string_from_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1080 <fs_exsists@plt>
test   %rax,%rax
je     11b3 <read_string_from_file+0x53>
mov    %rbx,%rdi
call   1070 <fs_filesize@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
lea    0xe74(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11b6 <read_string_from_file+0x56>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i8* @read_string_from_file(i8* noalias %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32* null, i32** %4
store i32 0, i32* %6
%7 = load i8*, i8** %3
%8 = call i64 @fs_exsists(i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %24
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @fs_filesize(i8* %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %3
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %4
%17 = load i8*, i8** %5
%18 = load i32, i32* %6
%19 = load i32*, i32** %4
%20 = call i32 @fread(i8* %17, i32 1, i32 %18, i32* %19)
%21 = load i32*, i32** %4
%22 = call i32 @fclose(i32* %21)
%23 = load i8*, i8** %5
store i8* %23, i8** %2
br label %25
24: ; preds = %1
store i8* null, i8** %2
br label %25
25: ; preds = %24, %10
%26 = load i8*, i8** %2
ret i8* %26
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define noalias i8* @read_string_from_file(i8* noalias %0) {
%2 = tail call i64 @fs_exsists(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %10, label %4
4: ; preds = %1
%5 = tail call i32 @fs_filesize(i8* %0)
%6 = tail call i8* @malloc(i32 %5)
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @fread(i8* %6, i32 1, i32 %5, i32* %7)
%9 = tail call i32 @fclose(i32* %7)
br label %10
10: ; preds = %1, %4
%11 = phi i8* [ %6, %4 ], [ null, %1 ]
ret i8* %11
}