#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 */
scalar_t__ EOF;
char *calloc(int, int);
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *realloc(char *, int);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
char *ReadLines(char *NameFile) {
  FILE *arq = NULL;
  arq = fopen(NameFile, "rx");
  if (arq == NULL) {
    exit(1);
  }
  char *lineBuffer = calloc(1, 1);
  char line[2048];
  while (fgets(line, sizeof line, arq)) {
    lineBuffer = realloc(lineBuffer, strlen(lineBuffer) + strlen(line));
    strncat(lineBuffer, line, 2048);
  }
  lineBuffer = realloc(lineBuffer, strlen(lineBuffer) + 4);
  strncat(lineBuffer, " \n", 4);
  if (fclose(arq) == EOF) {
    exit(1);
  }
  arq = NULL;
  lineBuffer[strlen(lineBuffer) - 1] = '\0';
  char *tmp = lineBuffer;
  free(lineBuffer);
  return tmp;
}


x86 assembly (clang, -O0):
<ReadLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d0 <ReadLines+0x40>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x1,%esi
mov    %esi,%edi
call   1080 <calloc@plt>
mov    %rax,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x800,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1257 <ReadLines+0xc7>
mov    -0x18(%rbp),%rax
mov    %rax,-0x830(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x834(%rbp)
lea    -0x820(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x834(%rbp),%esi
mov    -0x830(%rbp),%rdi
add    %eax,%esi
call   1090 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
call   1060 <strncat@plt>
jmp    11e0 <ReadLines+0x50>
mov    -0x18(%rbp),%rax
mov    %rax,-0x840(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x840(%rbp),%rdi
mov    %eax,%esi
add    $0x4,%esi
call   1090 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xd78(%rip),%rsi
mov    $0x4,%edx
call   1060 <strncat@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d43(%rip),%rcx
cmp    (%rcx),%rax
jne    12b8 <ReadLines+0x128>
mov    $0x1,%edi
call   10b0 <exit@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x848(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x848(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x828(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x828(%rbp),%rax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadLines>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x808,%rsp
lea    0xe5c(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     128c <ReadLines+0xfc>
mov    %rax,%r14
mov    $0x1,%edi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1226 <ReadLines+0x96>
mov    %rsp,%r15
nop
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1050 <strlen@plt>
add    %eax,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
call   1090 <realloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0x800,%edx
call   1060 <strncat@plt>
mov    %r15,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    11e0 <ReadLines+0x50>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x4(%rax),%esi
mov    %rbx,%rdi
call   1090 <realloc@plt>
mov    %rax,%rbx
lea    0xdc0(%rip),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1060 <strncat@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2d89(%rip),%rcx
cmp    (%rcx),%rax
je     128c <ReadLines+0xfc>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x808,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rx\00"
@.str.1 = [3 x i8] c" \0A\00"
@EOF = global i64 0
define i8* @ReadLines(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca [2048 x i8]
%6 = alloca i8*
store i8* %0, i8** %2
store i32* null, i32** %3
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = call i8* @calloc(i32 1, i32 1)
store i8* %14, i8** %4
br label %15
15: ; preds = %20, %13
%16 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %3
%18 = call i64 @fgets(i8* %16, i32 2048, i32* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %31
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i8*, i8** %4
%23 = call i32 @strlen(i8* %22)
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = add nsw i32 %23, %25
%27 = call i8* @realloc(i8* %21, i32 %26)
store i8* %27, i8** %4
%28 = load i8*, i8** %4
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%30 = call i32 @strncat(i8* %28, i8* %29, i32 2048)
br label %15
31: ; preds = %15
%32 = load i8*, i8** %4
%33 = load i8*, i8** %4
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %34, 4
%36 = call i8* @realloc(i8* %32, i32 %35)
store i8* %36, i8** %4
%37 = load i8*, i8** %4
%38 = call i32 @strncat(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 4)
%39 = load i32*, i32** %3
%40 = call i64 @fclose(i32* %39)
%41 = load i64, i64* @EOF
%42 = icmp eq i64 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %31
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %31
store i32* null, i32** %3
%46 = load i8*, i8** %4
%47 = load i8*, i8** %4
%48 = call i32 @strlen(i8* %47)
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %46, i64 %50
store i8 0, i8* %51
%52 = load i8*, i8** %4
store i8* %52, i8** %6
%53 = load i8*, i8** %4
%54 = call i32 @free(i8* %53)
%55 = load i8*, i8** %6
ret i8* %55
}

LLVM IR (-O2):
@.str = [3 x i8] c"rx\00"
@.str.1 = [3 x i8] c" \0A\00"
@EOF = global i64 0
define i8* @ReadLines(i8* nocapture %0) {
%2 = alloca [2048 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = tail call dereferenceable_or_null(1) i8* @calloc(i32 1, i32 1)
%9 = getelementptr inbounds [2048 x i8], [2048 x i8]* %2, i64 0, i64 0
%10 = call i64 @fgets(i8* %9, i32 2048, i32* %3)
%11 = icmp eq i64 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %7, %12
%13 = phi i8* [ %17, %12 ], [ %8, %7 ]
%14 = call i32 @strlen(i8* %13)
%15 = call i32 @strlen(i8* %9)
%16 = add nsw i32 %15, %14
%17 = call i8* @realloc(i8* %13, i32 %16)
%18 = call i32 @strncat(i8* %17, i8* %9, i32 2048)
%19 = call i64 @fgets(i8* %9, i32 2048, i32* %3)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %12
21: ; preds = %12, %7
%22 = phi i8* [ %8, %7 ], [ %17, %12 ]
%23 = call i32 @strlen(i8* %22)
%24 = add nsw i32 %23, 4
%25 = call i8* @realloc(i8* %22, i32 %24)
%26 = call i32 @strncat(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 4)
%27 = call i64 @fclose(i32* %3)
%28 = load i64, i64* @EOF
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %21
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %21
%33 = call i32 @strlen(i8* %25)
%34 = add nsw i32 %33, -1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %25, i64 %35
store i8 0, i8* %36
%37 = call i32 @free(i8* %25)
ret i8* %25
}