#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ft_cat(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int ac, char **av) {
  int fda;
  int fdb;
  int fdc;
  int fdd;
  printf("-----------------------\n");
  printf("          cat         \n");
  printf("-----------------------\n");
  fda = open("tests_cat/aaa", O_RDONLY);
  printf("aaa opened - fd = %d\n", fda);
  ft_cat(fda);
  printf("\n-----------------------");
  fdb = open("tests_cat/bbb", O_RDONLY);
  printf("\nbbb opened - fd = %d\n", fdb);
  ft_cat(fdb);
  printf("\n-----------------------");
  fdc = open("tests_cat/ccc", O_RDONLY);
  printf("\nccc opened - fd = %d\n", fdc);
  ft_cat(fdc);
  printf("\n-----------------------");
  fdd = open("ft_cat.o", O_RDONLY);
  if (fdd > 0) {
    printf("\nft_cat.o opened - fd = %d\n", fdd);
    ft_cat(fdd);
    close(fdd);
  }
  printf("\n-----------------------");
  printf("\nTEST NEG FD - fd = -42\n");
  ft_cat(-42);
  printf("\n-----------------------");
  printf("\nTEST FD non ouvert - fd = 60\n");
  ft_cat(60);
  close(fdc);
  close(fdb);
  close(fda);
  printf("\n\n");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <ft_cat@plt>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
call   1040 <ft_cat@plt>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1040 <ft_cat@plt>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%esi
lea    0xe6b(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    1280 <main+0x140>
mov    -0x20(%rbp),%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%edi
call   1040 <ft_cat@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffd6,%edi
call   1040 <ft_cat@plt>
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x3c,%edi
call   1040 <ft_cat@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xec6(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xf3e(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0x2e66(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xe74(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r14d
lea    0xe73(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14d,%edi
call   1050 <ft_cat@plt>
lea    0xe71(%rip),%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%rbp),%esi
lea    0xe76(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%r12d
lea    0xe75(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%edi
call   1050 <ft_cat@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%rbp),%esi
lea    0xe67(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
lea    0xe67(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <ft_cat@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%rbp),%esi
lea    0xe5a(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
jle    1256 <main+0x106>
mov    %eax,%ebp
lea    0xe51(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <ft_cat@plt>
mov    %ebp,%edi
call   1060 <close@plt>
lea    0xdc7(%rip),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffd6,%edi
call   1050 <ft_cat@plt>
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x3c,%edi
call   1050 <ft_cat@plt>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    %r14d,%edi
call   1060 <close@plt>
lea    0xd67(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"-----------------------\0A\00"
@.str.1 = [24 x i8] c" cat \0A\00"
@.str.2 = [14 x i8] c"tests_cat/aaa\00"
@O_RDONLY = global i32 0
@.str.3 = [22 x i8] c"aaa opened - fd = %d\0A\00"
@.str.4 = [25 x i8] c"\0A-----------------------\00"
@.str.5 = [14 x i8] c"tests_cat/bbb\00"
@.str.6 = [23 x i8] c"\0Abbb opened - fd = %d\0A\00"
@.str.7 = [14 x i8] c"tests_cat/ccc\00"
@.str.8 = [23 x i8] c"\0Accc opened - fd = %d\0A\00"
@.str.9 = [9 x i8] c"ft_cat.o\00"
@.str.10 = [28 x i8] c"\0Aft_cat.o opened - fd = %d\0A\00"
@.str.11 = [25 x i8] c"\0ATEST NEG FD - fd = -42\0A\00"
@.str.12 = [31 x i8] c"\0ATEST FD non ouvert - fd = 60\0A\00"
@.str.13 = [3 x i8] c"\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %6
%18 = call i32 @ft_cat(i32 %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %7
%25 = call i32 @ft_cat(i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %8
%32 = call i32 @ft_cat(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%34 = load i32, i32* @O_RDONLY
%35 = call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 %34)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %2
%39 = load i32, i32* %9
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %9
%42 = call i32 @ft_cat(i32 %41)
%43 = load i32, i32* %9
%44 = call i32 @close(i32 %43)
br label %45
45: ; preds = %38, %2
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0))
%48 = call i32 @ft_cat(i32 -42)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0))
%51 = call i32 @ft_cat(i32 60)
%52 = load i32, i32* %8
%53 = call i32 @close(i32 %52)
%54 = load i32, i32* %7
%55 = call i32 @close(i32 %54)
%56 = load i32, i32* %6
%57 = call i32 @close(i32 %56)
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.2 = [14 x i8] c"tests_cat/aaa\00"
@O_RDONLY = global i32 0
@.str.3 = [22 x i8] c"aaa opened - fd = %d\0A\00"
@.str.4 = [25 x i8] c"\0A-----------------------\00"
@.str.5 = [14 x i8] c"tests_cat/bbb\00"
@.str.6 = [23 x i8] c"\0Abbb opened - fd = %d\0A\00"
@.str.7 = [14 x i8] c"tests_cat/ccc\00"
@.str.8 = [23 x i8] c"\0Accc opened - fd = %d\0A\00"
@.str.9 = [9 x i8] c"ft_cat.o\00"
@.str.10 = [28 x i8] c"\0Aft_cat.o opened - fd = %d\0A\00"
@str.14 = [23 x i8] c" cat \00"
@str.15 = [24 x i8] c"-----------------------\00"
@str.16 = [24 x i8] c"\0ATEST NEG FD - fd = -42\00"
@str.17 = [30 x i8] c"\0ATEST FD non ouvert - fd = 60\00"
@str.18 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.15, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.14, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.15, i64 0, i64 0))
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%9 = tail call i32 @ft_cat(i32 %7)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i32 %12)
%14 = tail call i32 @ft_cat(i32 %12)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%16 = load i32, i32* @O_RDONLY
%17 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %17)
%19 = tail call i32 @ft_cat(i32 %17)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%21 = load i32, i32* @O_RDONLY
%22 = tail call i32 @open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32 %21)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %2
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0), i32 %22)
%26 = tail call i32 @ft_cat(i32 %22)
%27 = tail call i32 @close(i32 %22)
br label %28
28: ; preds = %24, %2
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.16, i64 0, i64 0))
%31 = tail call i32 @ft_cat(i32 -42)
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.17, i64 0, i64 0))
%34 = tail call i32 @ft_cat(i32 60)
%35 = tail call i32 @close(i32 %17)
%36 = tail call i32 @close(i32 %12)
%37 = tail call i32 @close(i32 %7)
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.18, i64 0, i64 0))
ret i32 0
}