#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*/ temp;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ S_IRUSR;
int /*<<< orphan*/ close(int);
int ft_file_len(char *);
scalar_t__ malloc(int);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, char *, int);
char *ft_file_to_str(char *argv) {
  int i;
  int fd;
  char *temp;
  char c;
  int ret;
  i = 0;
  temp = (char *)malloc(sizeof(temp) * ft_file_len(argv));
  fd = open(argv, O_RDONLY, S_IRUSR);
  if (!temp || fd == -1)
    return (0);
  while ((ret = read(fd, &c, 1))) {
    if (ret == -1)
      return (0);
    temp[i] = c;
    i++;
  }
  if (!ret && i == 0) {
    return (0);
  }
  temp[i] = '\0';
  close(fd);
  return (temp);
}


x86 assembly (clang, -O0):
<ft_file_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <ft_file_len@plt>
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11b0 <ft_file_to_str+0x60>
cmpl   $0xffffffff,-0x18(%rbp)
jne    11bd <ft_file_to_str+0x6d>
movq   $0x0,-0x8(%rbp)
jmp    124f <ft_file_to_str+0xff>
jmp    11c2 <ft_file_to_str+0x72>
mov    -0x18(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     1212 <ft_file_to_str+0xc2>
cmpl   $0xffffffff,-0x28(%rbp)
jne    11f6 <ft_file_to_str+0xa6>
movq   $0x0,-0x8(%rbp)
jmp    124f <ft_file_to_str+0xff>
mov    -0x21(%rbp),%dl
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11c2 <ft_file_to_str+0x72>
cmpl   $0x0,-0x28(%rbp)
jne    1233 <ft_file_to_str+0xe3>
cmpl   $0x0,-0x14(%rbp)
jne    1233 <ft_file_to_str+0xe3>
movq   $0x0,-0x8(%rbp)
jmp    124f <ft_file_to_str+0xff>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_file_to_str>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbp
call   1030 <ft_file_len@plt>
lea    0x0(,%rax,8),%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
xor    %eax,%eax
test   %r15,%r15
je     11e0 <ft_file_to_str+0x90>
cmp    $0xffffffff,%ebp
je     11e0 <ft_file_to_str+0x90>
xor    %ebx,%ebx
lea    0x7(%rsp),%r14
nopl   (%rax)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     11de <ft_file_to_str+0x8e>
test   %eax,%eax
je     11c7 <ft_file_to_str+0x77>
movzbl 0x7(%rsp),%eax
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
jmp    11a0 <ft_file_to_str+0x50>
test   %ebx,%ebx
je     11de <ft_file_to_str+0x8e>
mov    %ebx,%eax
movb   $0x0,(%r15,%rax,1)
mov    %ebp,%edi
call   1040 <close@plt>
mov    %r15,%rax
jmp    11e0 <ft_file_to_str+0x90>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@S_IRUSR = global i32 0
define i8* @ft_file_to_str(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%9 = load i8*, i8** %3
%10 = call i32 @ft_file_len(i8* %9)
%11 = sext i32 %10 to i64
%12 = mul i64 8, %11
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %6
%16 = load i8*, i8** %3
%17 = load i32, i32* @O_RDONLY
%18 = load i32, i32* @S_IRUSR
%19 = call i32 @open(i8* %16, i32 %17, i32 %18)
store i32 %19, i32* %5
%20 = load i8*, i8** %6
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %1
%23 = load i32, i32* %5
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %22, %1
store i8* null, i8** %2
br label %58
26: ; preds = %22
br label %27
27: ; preds = %35, %26
%28 = load i32, i32* %5
%29 = call i32 @read(i32 %28, i8* %7, i32 1)
store i32 %29, i32* %8
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %43
31: ; preds = %27
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %35
34: ; preds = %31
store i8* null, i8** %2
br label %58
35: ; preds = %31
%36 = load i8, i8* %7
%37 = load i8*, i8** %6
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 %36, i8* %40
%41 = load i32, i32* %4
%42 = add nsw i32 %41, 1
store i32 %42, i32* %4
br label %27
43: ; preds = %27
%44 = load i32, i32* %8
%45 = icmp ne i32 %44, 0
br i1 %45, label %50, label %46
46: ; preds = %43
%47 = load i32, i32* %4
%48 = icmp eq i32 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %46
store i8* null, i8** %2
br label %58
50: ; preds = %46, %43
%51 = load i8*, i8** %6
%52 = load i32, i32* %4
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 0, i8* %54
%55 = load i32, i32* %5
%56 = call i32 @close(i32 %55)
%57 = load i8*, i8** %6
store i8* %57, i8** %2
br label %58
58: ; preds = %50, %49, %34, %25
%59 = load i8*, i8** %2
ret i8* %59
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@S_IRUSR = global i32 0
define i8* @ft_file_to_str(i8* %0) {
%2 = alloca i8
%3 = tail call i32 @ft_file_len(i8* %0)
%4 = shl i32 %3, 3
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = load i32, i32* @O_RDONLY
%8 = load i32, i32* @S_IRUSR
%9 = tail call i32 @open(i8* %0, i32 %7, i32 %8)
%10 = icmp eq i64 %5, 0
%11 = icmp eq i32 %9, -1
%12 = or i1 %10, %11
br i1 %12, label %27, label %13
13: ; preds = %1, %16
%14 = phi i64 [ %19, %16 ], [ 0, %1 ]
%15 = call i32 @read(i32 %9, i8* %2, i32 1)
switch i32 %15, label %16 [
i32 0, label %20
i32 -1, label %27
]
16: ; preds = %13
%17 = load i8, i8* %2
%18 = getelementptr inbounds i8, i8* %6, i64 %14
store i8 %17, i8* %18
%19 = add nuw i64 %14, 1
br label %13
20: ; preds = %13
%21 = trunc i64 %14 to i32
%22 = icmp eq i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = and i64 %14, 4294967295
%25 = getelementptr inbounds i8, i8* %6, i64 %24
store i8 0, i8* %25
%26 = tail call i32 @close(i32 %9)
br label %27
27: ; preds = %13, %20, %1, %23
%28 = phi i8* [ %6, %23 ], [ null, %1 ], [ null, %20 ], [ null, %13 ]
ret i8* %28
}