#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_putstr(char *);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void disp_files(int argc, char **argv) {
  char buffer;
  int fd;
  int i;
  i = 1;
  while (i < argc) {
    fd = open(argv[i], O_RDONLY);
    if (fd >= 0) {
      while (read(fd, &buffer, 1) != 0)
        write(1, &buffer, 1);
    } else {
      ft_putstr("ft_cat: ");
      ft_putstr(argv[i]);
      ft_putstr(": No such file or directory\n");
    }
    close(fd);
    i++;
  }
}


x86 assembly (clang, -O0):
<disp_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1212 <disp_files+0xc2>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11d3 <disp_files+0x83>
jmp    119e <disp_files+0x4e>
mov    -0x18(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
je     11ce <disp_files+0x7e>
mov    $0x1,%edx
lea    -0x11(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
jmp    119e <disp_files+0x4e>
jmp    11fc <disp_files+0xac>
lea    0xe26(%rip),%rdi
call   1070 <ft_putstr@plt>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <ft_putstr@plt>
lea    0xe12(%rip),%rdi
call   1070 <ft_putstr@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1166 <disp_files+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<disp_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11f8 <disp_files+0xa8>
mov    %rsi,%r14
mov    %edi,%r13d
mov    $0x1,%r15d
mov    0x2e71(%rip),%r12
lea    0x7(%rsp),%rbx
jmp    11b1 <disp_files+0x61>
xchg   %ax,%ax
lea    0xe79(%rip),%rdi
call   1070 <ft_putstr@plt>
mov    (%r14,%r15,8),%rdi
call   1070 <ft_putstr@plt>
lea    0xe6d(%rip),%rdi
call   1070 <ft_putstr@plt>
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x1,%r15
cmp    %r13,%r15
je     11f8 <disp_files+0xa8>
mov    (%r14,%r15,8),%rdi
mov    (%r12),%esi
call   1060 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1180 <disp_files+0x30>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
test   %rax,%rax
je     11a1 <disp_files+0x51>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    11d0 <disp_files+0x80>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [9 x i8] c"ft_cat: \00"
@.str.1 = [29 x i8] c": No such file or directory\0A\00"
define void @disp_files(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 1, i32* %7
br label %8
8: ; preds = %39, %2
%9 = load i32, i32* %7
%10 = load i32, i32* %3
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %44
12: ; preds = %8
%13 = load i8**, i8*** %4
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %12
br label %23
23: ; preds = %27, %22
%24 = load i32, i32* %6
%25 = call i64 @read(i32 %24, i8* %5, i32 1)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @write(i32 1, i8* %5, i32 1)
br label %23
29: ; preds = %23
br label %39
30: ; preds = %12
%31 = call i32 @ft_putstr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%32 = load i8**, i8*** %4
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 @ft_putstr(i8* %36)
%38 = call i32 @ft_putstr(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %30, %29
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %8
44: ; preds = %8
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [9 x i8] c"ft_cat: \00"
@.str.1 = [29 x i8] c": No such file or directory\0A\00"
define void @disp_files(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %30
5: ; preds = %2
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %26
%8 = phi i64 [ 1, %5 ], [ %28, %26 ]
%9 = getelementptr inbounds i8*, i8** %1, i64 %8
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = icmp sgt i32 %12, -1
br i1 %13, label %14, label %21
14: ; preds = %7
%15 = call i64 @read(i32 %12, i8* %3, i32 1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %14, %17
%18 = call i32 @write(i32 1, i8* %3, i32 1)
%19 = call i64 @read(i32 %12, i8* %3, i32 1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %26, label %17
21: ; preds = %7
%22 = tail call i32 @ft_putstr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%23 = load i8*, i8** %9
%24 = tail call i32 @ft_putstr(i8* %23)
%25 = tail call i32 @ft_putstr(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %17, %14, %21
%27 = tail call i32 @close(i32 %12)
%28 = add nuw nsw i64 %8, 1
%29 = icmp eq i64 %28, %6
br i1 %29, label %30, label %7
30: ; preds = %26, %2
ret void
}