#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*/ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t getdelim(char **, size_t *, int /*<<< orphan*/, int /*<<< orphan*/ *);
int get_all_content_of_file(char *path, char **rs, char **rend) {
  size_t len;
  size_t n;
  char *line;
  FILE *fp;
  fp = fopen(path, "r");
  if (fp == 0)
    return -1;
  n = 0;
  line = NULL;
  len = getdelim(&line, &n, EOF, fp);
  fclose(fp);
  if (len < 0)
    return -2;
  *rs = line;
  *rend = line + len;
  return 0;
}


x86 assembly (clang, -O0):
<get_all_content_of_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    116f <get_all_content_of_file+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11de <get_all_content_of_file+0xae>
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edx
mov    -0x40(%rbp),%rcx
lea    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <getdelim@plt>
mov    %rax,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
jae    11bd <get_all_content_of_file+0x8d>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11de <get_all_content_of_file+0xae>
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
add    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_all_content_of_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xeb8(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     119f <get_all_content_of_file+0x6f>
mov    %rax,%r12
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r12,%rcx
call   1050 <getdelim@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1030 <fclose@plt>
mov    0x8(%rsp),%rax
mov    %rax,(%r15)
add    %rax,%rbx
mov    %rbx,(%r14)
xor    %eax,%eax
jmp    11a4 <get_all_content_of_file+0x74>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @get_all_content_of_file(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %11
%14 = load i32*, i32** %11
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %4
br label %33
17: ; preds = %3
store i64 0, i64* %9
store i8* null, i8** %10
%18 = load i32, i32* @EOF
%19 = load i32*, i32** %11
%20 = call i64 @getdelim(i8** %10, i64* %9, i32 %18, i32* %19)
store i64 %20, i64* %8
%21 = load i32*, i32** %11
%22 = call i32 @fclose(i32* %21)
%23 = load i64, i64* %8
%24 = icmp ult i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %17
store i32 -2, i32* %4
br label %33
26: ; preds = %17
%27 = load i8*, i8** %10
%28 = load i8**, i8*** %6
store i8* %27, i8** %28
%29 = load i8*, i8** %10
%30 = load i64, i64* %8
%31 = getelementptr inbounds i8, i8* %29, i64 %30
%32 = load i8**, i8*** %7
store i8* %31, i8** %32
store i32 0, i32* %4
br label %33
33: ; preds = %26, %25, %16
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @get_all_content_of_file(i8* nocapture %0, i8** nocapture writeonly %1, i8** nocapture writeonly %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = bitcast i64* %4 to i8*
%7 = bitcast i8** %5 to i8*
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %16, label %10
10: ; preds = %3
store i64 0, i64* %4
store i8* null, i8** %5
%11 = load i32, i32* @EOF
%12 = call i64 @getdelim(i8** %5, i64* %4, i32 %11, i32* %8)
%13 = call i32 @fclose(i32* %8)
%14 = load i8*, i8** %5
store i8* %14, i8** %1
%15 = getelementptr inbounds i8, i8* %14, i64 %12
store i8* %15, i8** %2
br label %16
16: ; preds = %3, %10
%17 = phi i32 [ 0, %10 ], [ -1, %3 ]
ret i32 %17
}