#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
char *get_string_file(char *path) {
  FILE *ptr_file;
  char *buf;
  int size;
  ptr_file = fopen(path, "r");
  if (!ptr_file) {
    printf("Fail fopen");
    return NULL;
  }
  fseek(ptr_file, 0L, SEEK_END);
  size = ftell(ptr_file);
  fseek(ptr_file, 0L, SEEK_SET);
  buf = malloc(sizeof(*buf) * size + 1);
  if (!buf)
    return NULL;
  if ((int)fread(buf, 1, size, ptr_file) == -1)
    printf("fread Fail");
  buf[size] = 0;
  fclose(ptr_file);
  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    0xe79(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b4 <get_string_file+0x44>
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1262 <get_string_file+0xf2>
mov    -0x18(%rbp),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2df7(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121b <get_string_file+0xab>
movq   $0x0,-0x8(%rbp)
jmp    1262 <get_string_file+0xf2>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
cmp    $0xffffffff,%eax
jne    1245 <get_string_file+0xd5>
lea    0xdcd(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
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   %r12
push   %rbx
push   %rax
lea    0xe81(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     120f <get_string_file+0x9f>
mov    %rax,%rbx
mov    0x2e51(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %eax,%r12d
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
lea    0x1(%r12),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     121e <get_string_file+0xae>
mov    %rax,%r15
movslq %r12d,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    $0xffffffff,%eax
jne    11fd <get_string_file+0x8d>
lea    0xe15(%rip),%rdi
call   1050 <printf@plt>
movb   $0x0,(%r15,%r14,1)
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r15,%r14
jmp    121e <get_string_file+0xae>
lea    0xdec(%rip),%rdi
call   1050 <printf@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"Fail fopen\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [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 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, 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 i32 @ftell(i32* %2)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %2, i64 0, i32 %10)
%12 = sext i32 %9 to i64
%13 = add i32 %9, 1
%14 = tail call i8* @malloc(i32 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %25, label %16
16: ; preds = %6
%17 = tail call i64 @fread(i8* %14, i32 1, i32 %9, i32* %2)
%18 = trunc i64 %17 to i32
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = getelementptr inbounds i8, i8* %14, i64 %12
store i8 0, i8* %23
%24 = tail call i32 @fclose(i32* %2)
br label %25
25: ; preds = %6, %22, %4
%26 = phi i8* [ %14, %22 ], [ null, %4 ], [ null, %6 ]
ret i8* %26
}