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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
char *fstr(const char *path) {
  char *buff = malloc(102400);
  FILE *f = fopen(path, "r");
  char *line = malloc(1024);
  while (fgets(line, sizeof(line), f)) {
    strcat(buff, line);
  }
  return buff;
}


x86 assembly (clang, -O0):
<fstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x19000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x8,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     11aa <fstr+0x6a>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcat@plt>
jmp    117c <fstr+0x3c>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fstr>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x19000,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0xea4(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%r15
mov    $0x400,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
nopw   0x0(%rax,%rax,1)
mov    $0x8,%esi
mov    %r15,%rdx
call   1030 <fgets@plt>
test   %rax,%rax
je     11a2 <fstr+0x62>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
mov    %rbx,%rdi
jmp    1180 <fstr+0x40>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i8* @fstr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = call i8* @malloc(i32 102400)
store i8* %6, i8** %3
%7 = load i8*, i8** %2
%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 = call i8* @malloc(i32 1024)
store i8* %9, i8** %5
br label %10
10: ; preds = %15, %1
%11 = load i8*, i8** %5
%12 = load i32*, i32** %4
%13 = call i64 @fgets(i8* %11, i32 8, i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = load i8*, i8** %3
%17 = load i8*, i8** %5
%18 = call i32 @strcat(i8* %16, i8* %17)
br label %10
19: ; preds = %10
%20 = load i8*, i8** %3
ret i8* %20
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i8* @fstr(i8* nocapture %0) {
%2 = tail call dereferenceable_or_null(102400) i8* @malloc(i32 102400)
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%5 = tail call i64 @fgets(i8* %4, i32 8, i32* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1, %7
%8 = tail call i32 @strcat(i8* %2, i8* %4)
%9 = tail call i64 @fgets(i8* %4, i32 8, i32* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %7
11: ; preds = %7, %1
ret i8* %2
}