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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ft_putstr(char *);
int read(int, char *, int);
int ft_display_file(int fd) {
  int ret;
  char buf[4096 + 1];
  if (fd == -1)
    return (-1);
  while ((ret = read(fd, buf, 4096)) != 0 && ret != -1) {
    buf[ret] = '\0';
    ft_putstr(buf);
  }
  if (ret == -1)
    return (1);
  if (fd != 0)
    close(fd);
  return (0);
}


x86 assembly (clang, -O0):
<ft_display_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1154 <ft_display_file+0x24>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ef <ft_display_file+0xbf>
jmp    1159 <ft_display_file+0x29>
mov    -0x8(%rbp),%edi
lea    -0x1010(%rbp),%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1011(%rbp)
je     1190 <ft_display_file+0x60>
cmpl   $0xffffffff,-0xc(%rbp)
setne  %al
mov    %al,-0x1011(%rbp)
mov    -0x1011(%rbp),%al
test   $0x1,%al
jne    11a3 <ft_display_file+0x73>
jmp    11c0 <ft_display_file+0x90>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x1010(%rbp,%rax,1)
lea    -0x1010(%rbp),%rdi
call   1050 <ft_putstr@plt>
jmp    1159 <ft_display_file+0x29>
cmpl   $0xffffffff,-0xc(%rbp)
jne    11d6 <ft_display_file+0xa6>
movl   $0x1,-0x4(%rbp)
jmp    11ef <ft_display_file+0xbf>
cmpl   $0x0,-0x8(%rbp)
je     11e8 <ft_display_file+0xb8>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_display_file>:
push   %rbp
push   %rbx
sub    $0x1008,%rsp
cmp    $0xffffffff,%edi
je     119b <ft_display_file+0x6b>
mov    %edi,%ebp
mov    %rsp,%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
mov    %eax,%ecx
add    $0xffffffff,%ecx
cmp    $0xfffffffd,%ecx
ja     1187 <ft_display_file+0x57>
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %rbx,%rdi
call   1050 <ft_putstr@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1040 <read@plt>
mov    %eax,%ecx
add    $0xffffffff,%ecx
cmp    $0xfffffffe,%ecx
jb     1160 <ft_display_file+0x30>
cmp    $0xffffffff,%eax
je     11a2 <ft_display_file+0x72>
xor    %ebx,%ebx
test   %ebp,%ebp
je     11a7 <ft_display_file+0x77>
mov    %ebp,%edi
call   1030 <close@plt>
jmp    11a7 <ft_display_file+0x77>
mov    $0xffffffff,%ebx
jmp    11a7 <ft_display_file+0x77>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ft_display_file(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [4097 x i8]
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %37
9: ; preds = %1
br label %10
10: ; preds = %20, %9
%11 = load i32, i32* %3
%12 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 4096)
store i32 %13, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, -1
br label %18
18: ; preds = %15, %10
%19 = phi i1 [ false, %10 ], [ %17, %15 ]
br i1 %19, label %20, label %26
20: ; preds = %18
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 %22
store i8 0, i8* %23
%24 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 0
%25 = call i32 @ft_putstr(i8* %24)
br label %10
26: ; preds = %18
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 1, i32* %2
br label %37
30: ; preds = %26
%31 = load i32, i32* %3
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %3
%35 = call i32 @close(i32 %34)
br label %36
36: ; preds = %33, %30
store i32 0, i32* %2
br label %37
37: ; preds = %36, %29, %8
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @ft_display_file(i32 %0) {
%2 = alloca [4097 x i8]
%3 = getelementptr inbounds [4097 x i8], [4097 x i8]* %2, i64 0, i64 0
%4 = icmp eq i32 %0, -1
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = call i32 @read(i32 %0, i8* %3, i32 4096)
%7 = add i32 %6, -1
%8 = icmp ult i32 %7, -2
br i1 %8, label %9, label %17
9: ; preds = %5, %9
%10 = phi i32 [ %14, %9 ], [ %6, %5 ]
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [4097 x i8], [4097 x i8]* %2, i64 0, i64 %11
store i8 0, i8* %12
%13 = call i32 @ft_putstr(i8* %3)
%14 = call i32 @read(i32 %0, i8* %3, i32 4096)
%15 = add i32 %14, -1
%16 = icmp ult i32 %15, -2
br i1 %16, label %9, label %17
17: ; preds = %9, %5
%18 = phi i32 [ %6, %5 ], [ %14, %9 ]
%19 = icmp eq i32 %18, -1
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = icmp eq i32 %0, 0
br i1 %21, label %24, label %22
22: ; preds = %20
%23 = call i32 @close(i32 %0)
br label %24
24: ; preds = %20, %22, %17, %1
%25 = phi i32 [ -1, %1 ], [ 1, %17 ], [ 0, %22 ], [ 0, %20 ]
ret i32 %25
}