#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*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
char *get_string_file(char *path) {
  FILE *ptr_file;
  char *buf;
  long size;
  ptr_file = fopen(path, "r");
  if (!ptr_file) {
    printf("Fail fopen\n");
    return NULL;
  }
  fseek(ptr_file, 0L, SEEK_END);
  size = ftell(ptr_file);
  fseek(ptr_file, 0L, SEEK_SET);
  if (!(buf = malloc(sizeof(char) * size))) {
    printf("Fail Malloc\n");
    return NULL;
  }
  if ((int)fread(buf, 1, size, ptr_file) == -1)
    printf("fread Fail\n");
  buf[size] = 0;
  if (!ptr_file)
    return NULL;
  return buf;
}


x86 assembly (clang, -O0):
<get_string_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a4 <get_string_file+0x44>
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    126a <get_string_file+0x10a>
mov    -0x18(%rbp),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e06(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
mov    -0x28(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1213 <get_string_file+0xb3>
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    126a <get_string_file+0x10a>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    $0xffffffff,%eax
jne    123e <get_string_file+0xde>
lea    0xde2(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
cmpq   $0x0,-0x18(%rbp)
jne    1262 <get_string_file+0x102>
movq   $0x0,-0x8(%rbp)
jmp    126a <get_string_file+0x10a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_string_file>:
push   %r15
push   %r14
push   %rbx
lea    0xe94(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e5 <get_string_file+0x85>
mov    %rax,%rbx
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %rax,%r14
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %r14d,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11ee <get_string_file+0x8e>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0xffffffff,%eax
jne    11de <get_string_file+0x7e>
lea    0xe40(%rip),%rdi
call   1030 <puts@plt>
movb   $0x0,(%r15,%r14,1)
jmp    11fd <get_string_file+0x9d>
lea    0xe16(%rip),%rdi
jmp    11f5 <get_string_file+0x95>
lea    0xe18(%rip),%rdi
call   1030 <puts@plt>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@str = [11 x i8] c"Fail fopen\00"
@str.4 = [12 x i8] c"Fail Malloc\00"
@str.5 = [11 x i8] c"fread Fail\00"
define noalias i8* @get_string_file(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %25
6: ; preds = %1
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %2, i64 0, i32 %7)
%9 = tail call i64 @ftell(i32* %2)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %2, i64 0, i32 %10)
%12 = trunc i64 %9 to i32
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %6
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.4, i64 0, i64 0))
br label %25
17: ; preds = %6
%18 = tail call i64 @fread(i8* %13, i32 1, i64 %9, i32* %2)
%19 = trunc i64 %18 to i32
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.5, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
%24 = getelementptr inbounds i8, i8* %13, i64 %9
store i8 0, i8* %24
br label %25
25: ; preds = %23, %15, %4
%26 = phi i8* [ %13, %23 ], [ null, %15 ], [ null, %4 ]
ret i8* %26
}