#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*/ ft_putstr(char *);
void bad_fds(int fd, char **av, int i) {
  if (fd < 0) {
    ft_putstr("hexdump: ");
    ft_putstr(av[i]);
    ft_putstr(": No such file or directory\n");
    if (!av[++i]) {
      ft_putstr("hexdump: ");
      ft_putstr(av[--i]);
      ft_putstr(": Bad file descriptor\n");
    }
  }
}


x86 assembly (clang, -O0):
<bad_fds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11a6 <bad_fds+0x96>
lea    0xecd(%rip),%rdi
call   1030 <ft_putstr@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <ft_putstr@plt>
lea    0xeba(%rip),%rdi
call   1030 <ft_putstr@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    11a1 <bad_fds+0x91>
lea    0xe89(%rip),%rdi
call   1030 <ft_putstr@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <ft_putstr@plt>
lea    0xe8b(%rip),%rdi
call   1030 <ft_putstr@plt>
jmp    11a6 <bad_fds+0x96>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bad_fds>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jns    1148 <bad_fds+0x38>
mov    %edx,%ebp
mov    %rsi,%rbx
lea    0xedd(%rip),%rdi
call   1030 <ft_putstr@plt>
movslq %ebp,%rbp
mov    (%rbx,%rbp,8),%rdi
call   1030 <ft_putstr@plt>
lea    0xecf(%rip),%rdi
call   1030 <ft_putstr@plt>
cmpq   $0x0,0x8(%rbx,%rbp,8)
je     114f <bad_fds+0x3f>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xeaa(%rip),%rdi
call   1030 <ft_putstr@plt>
mov    (%rbx,%rbp,8),%rdi
call   1030 <ft_putstr@plt>
lea    0xebc(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <ft_putstr@plt>

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

LLVM IR (-O2):
@.str = [10 x i8] c"hexdump: \00"
@.str.1 = [29 x i8] c": No such file or directory\0A\00"
@.str.2 = [23 x i8] c": Bad file descriptor\0A\00"
define void @bad_fds(i32 %0, i8** nocapture %1, i32 %2) {
%4 = icmp slt i32 %0, 0
br i1 %4, label %5, label %22
5: ; preds = %3
%6 = tail call i32 @ft_putstr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i32 @ft_putstr(i8* %9)
%11 = tail call i32 @ft_putstr(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%12 = add nsw i32 %2, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %22
17: ; preds = %5
%18 = tail call i32 @ft_putstr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %8
%20 = tail call i32 @ft_putstr(i8* %19)
%21 = tail call i32 @ft_putstr(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %22
22: ; preds = %5, %17, %3
ret void
}