#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;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ exit(int);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, long, int, int /*<<< orphan*/);
char *malloc(long);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
char *ReadLines(char *NameFile) {
  FILE *fh;
  char *buffer = NULL;
  fh = fopen(NameFile, "rb");
  if (fh == NULL) {
    printf("error in to open() file");
    exit(1);
  }
  fseek(fh, 0L, SEEK_END);
  long s = ftell(fh);
  rewind(fh);
  buffer = malloc(s);
  if (buffer != NULL) {
    fread(buffer, s, 1, fh);
    fwrite(buffer, s, 1, stdout);
  }
  if (fclose(fh) == EOF) {
    printf("Error in close() file %s", NameFile);
    exit(1);
  }
  fh = NULL;
  return buffer;
}


x86 assembly (clang, -O0):
<ReadLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11eb <ReadLines+0x4b>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1090 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <rewind@plt>
mov    -0x20(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1260 <ReadLines+0xc0>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2d7c(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   10c0 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d70(%rip),%rcx
cmp    (%rcx),%rax
jne    1295 <ReadLines+0xf5>
mov    -0x8(%rbp),%rsi
lea    0xd97(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadLines>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe4e(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1248 <ReadLines+0xa8>
mov    %rax,%rbx
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1060 <rewind@plt>
mov    %r12,%rdi
call   1080 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     1225 <ReadLines+0x85>
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%ecx
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   10c0 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2dac(%rip),%rcx
cmp    (%rcx),%rax
je     1260 <ReadLines+0xc0>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdb4(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdb4(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [24 x i8] c"error in to open() file\00"
@SEEK_END = global i32 0
@stdout = global i32 0
@EOF = global i64 0
@.str.2 = [25 x i8] c"Error in close() file %s\00"
define i8* @ReadLines(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %4
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = load i32*, i32** %3
%15 = load i32, i32* @SEEK_END
%16 = call i32 @fseek(i32* %14, i64 0, i32 %15)
%17 = load i32*, i32** %3
%18 = call i64 @ftell(i32* %17)
store i64 %18, i64* %5
%19 = load i32*, i32** %3
%20 = call i32 @rewind(i32* %19)
%21 = load i64, i64* %5
%22 = call i8* @malloc(i64 %21)
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %34
25: ; preds = %13
%26 = load i8*, i8** %4
%27 = load i64, i64* %5
%28 = load i32*, i32** %3
%29 = call i32 @fread(i8* %26, i64 %27, i32 1, i32* %28)
%30 = load i8*, i8** %4
%31 = load i64, i64* %5
%32 = load i32, i32* @stdout
%33 = call i32 @fwrite(i8* %30, i64 %31, i32 1, i32 %32)
br label %34
34: ; preds = %25, %13
%35 = load i32*, i32** %3
%36 = call i64 @fclose(i32* %35)
%37 = load i64, i64* @EOF
%38 = icmp eq i64 %36, %37
br i1 %38, label %39, label %43
39: ; preds = %34
%40 = load i8*, i8** %2
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %40)
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %34
store i32* null, i32** %3
%44 = load i8*, i8** %4
ret i8* %44
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [24 x i8] c"error in to open() file\00"
@SEEK_END = global i32 0
@stdout = global i32 0
@EOF = global i64 0
@.str.2 = [25 x i8] c"Error in close() file %s\00"
define i8* @ReadLines(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @fseek(i32* %2, i64 0, i32 %8)
%10 = tail call i64 @ftell(i32* %2)
%11 = tail call i32 @rewind(i32* %2)
%12 = tail call i8* @malloc(i64 %10)
%13 = icmp eq i8* %12, null
br i1 %13, label %18, label %14
14: ; preds = %7
%15 = tail call i32 @fread(i8* %12, i64 %10, i32 1, i32* %2)
%16 = load i32, i32* @stdout
%17 = tail call i32 @fwrite(i8* %12, i64 %10, i32 1, i32 %16)
br label %18
18: ; preds = %14, %7
%19 = tail call i64 @fclose(i32* %2)
%20 = load i64, i64* @EOF
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %18
ret i8* %12
}