#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ realloc(char *, int);
char *file_rough_reader(char *path) {
  FILE *file_pointer = fopen(path, "r");
  if (file_pointer == NULL) {
    printf("Inner: The path is invalid when calling file_rough_reader(..) "
           "function.\n");
    return NULL;
  }
  char *buffer = (char *)malloc(1);
  int i = 0;
  while ((buffer[i] = fgetc(file_pointer)) != EOF) {
    i++;
    if (NULL == (buffer = (char *)realloc(buffer, i + 1))) {
      printf("Inner: Fail to reallocation memory when calling "
             "file_read_line(..) function.\n");
      break;
    }
  }
  fclose(file_pointer);
  buffer[i - 1] = '\0';
  return buffer;
}


x86 assembly (clang, -O0):
<file_rough_reader>:
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 <file_rough_reader+0x44>
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1244 <file_rough_reader+0xe4>
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    -0x20(%rbp),%rcx
movslq -0x24(%rbp),%rdx
mov    %al,(%rcx,%rdx,1)
movsbl %al,%eax
mov    0x2e11(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1222 <file_rough_reader+0xc2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0x1,%esi
call   1070 <realloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    121d <file_rough_reader+0xbd>
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
jmp    1222 <file_rough_reader+0xc2>
jmp    11b9 <file_rough_reader+0x59>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_rough_reader>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xe90(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11df <file_rough_reader+0x7f>
mov    %rax,%r14
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
xor    %ebx,%ebx
mov    0x2e55(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %al,(%r15,%rbx,1)
cmp    0x0(%r13),%al
je     11f0 <file_rough_reader+0x90>
lea    0x1(%rbx),%r12
add    $0x2,%ebx
mov    %r15,%rdi
mov    %ebx,%esi
call   1070 <realloc@plt>
mov    %rax,%r15
mov    %r12,%rbx
test   %rax,%rax
jne    11a0 <file_rough_reader+0x40>
lea    0xe2d(%rip),%rdi
call   1030 <puts@plt>
xor    %r15d,%r15d
jmp    11f3 <file_rough_reader+0x93>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
xor    %r15d,%r15d
jmp    1207 <file_rough_reader+0xa7>
mov    %rbx,%r12
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0xffffffff,%r12d
movslq %r12d,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [73 x i8] c"Inner: The path is invalid when calling file_rough_reader(..) function.\0A\00"
@EOF = global i8 0
@.str.2 = [78 x i8] c"Inner: Fail to reallocation memory when calling file_read_line(..) function.\0A\00"
define i8* @file_rough_reader(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 eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %2
br label %48
13: ; preds = %1
%14 = call i64 @malloc(i32 1)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %5
store i32 0, i32* %6
br label %16
16: ; preds = %38, %13
%17 = load i32*, i32** %4
%18 = call signext i8 @fgetc(i32* %17)
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 %18, i8* %22
%23 = sext i8 %18 to i32
%24 = load i8, i8* @EOF
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %23, %25
br i1 %26, label %27, label %39
27: ; preds = %16
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
%30 = load i8*, i8** %5
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
%33 = call i64 @realloc(i8* %30, i32 %32)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %5
%35 = icmp eq i8* null, %34
br i1 %35, label %36, label %38
36: ; preds = %27
%37 = call i32 @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.2, i64 0, i64 0))
br label %39
38: ; preds = %27
br label %16
39: ; preds = %36, %16
%40 = load i32*, i32** %4
%41 = call i32 @fclose(i32* %40)
%42 = load i8*, i8** %5
%43 = load i32, i32* %6
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
store i8 0, i8* %46
%47 = load i8*, i8** %5
store i8* %47, i8** %2
br label %48
48: ; preds = %39, %11
%49 = load i8*, i8** %2
ret i8* %49
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i8 0
@str = [77 x i8] c"Inner: Fail to reallocation memory when calling file_read_line(..) function.\00"
@str.3 = [72 x i8] c"Inner: The path is invalid when calling file_rough_reader(..) function.\00"
define i8* @file_rough_reader(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 ([72 x i8], [72 x i8]* @str.3, i64 0, i64 0))
br label %34
6: ; preds = %1
%7 = tail call i64 @malloc(i32 1)
br label %8
8: ; preds = %16, %6
%9 = phi i64 [ %17, %16 ], [ 0, %6 ]
%10 = phi i64 [ %20, %16 ], [ %7, %6 ]
%11 = inttoptr i64 %10 to i8*
%12 = tail call signext i8 @fgetc(i32* %2)
%13 = getelementptr inbounds i8, i8* %11, i64 %9
store i8 %12, i8* %13
%14 = load i8, i8* @EOF
%15 = icmp eq i8 %12, %14
br i1 %15, label %24, label %16
16: ; preds = %8
%17 = add nuw i64 %9, 1
%18 = trunc i64 %9 to i32
%19 = add i32 %18, 2
%20 = tail call i64 @realloc(i8* %11, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %8
22: ; preds = %16
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str, i64 0, i64 0))
br label %26
24: ; preds = %8
%25 = inttoptr i64 %10 to i8*
br label %26
26: ; preds = %24, %22
%27 = phi i8* [ null, %22 ], [ %25, %24 ]
%28 = phi i64 [ %17, %22 ], [ %9, %24 ]
%29 = tail call i32 @fclose(i32* %2)
%30 = shl i64 %28, 32
%31 = add i64 %30, -4294967296
%32 = ashr exact i64 %31, 32
%33 = getelementptr inbounds i8, i8* %27, i64 %32
store i8 0, i8* %33
br label %34
34: ; preds = %26, %4
%35 = phi i8* [ null, %4 ], [ %27, %26 ]
ret i8* %35
}