#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ doit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ fstat(int, struct stat *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  int ret = 0;
  if (argc == 1) {
    doit(0);
  }
  for (int i = 1; i < argc; ++i) {
    int fd = open(argv[i], O_RDONLY);
    if (fd == -1) {
      fprintf(stderr, "%s: %s: no such file or directory\n", argv[0], argv[i]);
      ret = 1;
      continue;
    }
    struct stat _stat;
    fstat(fd, &_stat);
    if (S_ISDIR(_stat.st_mode)) {
      fprintf(stderr, "%s: %s: Is a directory\n", argv[0], argv[i]);
      close(fd);
      ret = 1;
      continue;
    }
    doit(fd);
    close(fd);
  }
  return ret;
}


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)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    118e <main+0x2e>
xor    %edi,%edi
call   1060 <doit@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1274 <main+0x114>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11fc <main+0x9c>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe15(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x14(%rbp)
jmp    1266 <main+0x106>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
call   1080 <fstat@plt>
mov    -0x20(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1256 <main+0xf6>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xde6(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
movl   $0x1,-0x14(%rbp)
jmp    1266 <main+0x106>
mov    -0x1c(%rbp),%edi
call   1060 <doit@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1195 <main+0x35>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %r13d,%r13d
cmp    $0x1,%edi
jne    117f <main+0x1f>
xor    %edi,%edi
call   1060 <doit@plt>
jmp    1230 <main+0xd0>
cmp    $0x2,%edi
jl     1230 <main+0xd0>
mov    %rsi,%rbx
mov    %edi,%r14d
xor    %r13d,%r13d
mov    $0x1,%r12d
mov    0x2e4a(%rip),%r15
jmp    11cb <main+0x6b>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    (%rbx,%r12,8),%rcx
lea    0xe49(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%r13d
add    $0x1,%r12
cmp    %r12,%r14
je     1230 <main+0xd0>
mov    (%rbx,%r12,8),%rdi
mov    (%r15),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11a0 <main+0x40>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rsp,%rsi
call   1080 <fstat@plt>
mov    (%rsp),%edi
call   1030 <S_ISDIR@plt>
test   %rax,%rax
je     1220 <main+0xc0>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    (%rbx,%r12,8),%rcx
lea    0xe17(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%r13d
jmp    1227 <main+0xc7>
nopl   0x0(%rax)
mov    %ebp,%edi
call   1060 <doit@plt>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    11c2 <main+0x62>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [35 x i8] c"%s: %s: no such file or directory\0A\00"
@.str.1 = [24 x i8] c"%s: %s: Is a directory\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 %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @doit(i32 0)
br label %14
14: ; preds = %12, %2
store i32 1, i32* %7
br label %15
15: ; preds = %65, %14
%16 = load i32, i32* %7
%17 = load i32, i32* %4
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %68
19: ; preds = %15
%20 = load i8**, i8*** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %40
29: ; preds = %19
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %5
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8*, i8** %34, i64 %36
%38 = load i8*, i8** %37
%39 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %33, i8* %38)
store i32 1, i32* %6
br label %65
40: ; preds = %19
%41 = load i32, i32* %8
%42 = call i32 @fstat(i32 %41, %struct.stat* %9)
%43 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i64 @S_ISDIR(i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %60
47: ; preds = %40
%48 = load i32, i32* @stderr
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 0
%51 = load i8*, i8** %50
%52 = load i8**, i8*** %5
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
%56 = load i8*, i8** %55
%57 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %51, i8* %56)
%58 = load i32, i32* %8
%59 = call i32 @close(i32 %58)
store i32 1, i32* %6
br label %65
60: ; preds = %40
%61 = load i32, i32* %8
%62 = call i32 @doit(i32 %61)
%63 = load i32, i32* %8
%64 = call i32 @close(i32 %63)
br label %65
65: ; preds = %60, %47, %29
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %15
68: ; preds = %15
%69 = load i32, i32* %6
ret i32 %69
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str = [35 x i8] c"%s: %s: no such file or directory\0A\00"
@.str.1 = [24 x i8] c"%s: %s: Is a directory\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @doit(i32 0)
br label %13
7: ; preds = %2
%8 = icmp sgt i32 %0, 1
br i1 %8, label %9, label %13
9: ; preds = %7
%10 = bitcast %struct.stat* %3 to i8*
%11 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%12 = zext i32 %0 to i64
br label %15
13: ; preds = %43, %5, %7
%14 = phi i32 [ 0, %7 ], [ 0, %5 ], [ %44, %43 ]
ret i32 %14
15: ; preds = %9, %43
%16 = phi i64 [ 1, %9 ], [ %45, %43 ]
%17 = phi i32 [ 0, %9 ], [ %44, %43 ]
%18 = getelementptr inbounds i8*, i8** %1, i64 %16
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = tail call i32 @open(i8* %19, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %28
23: ; preds = %15
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %1
%26 = load i8*, i8** %18
%27 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %25, i8* %26)
br label %43
28: ; preds = %15
%29 = call i32 @fstat(i32 %21, %struct.stat* %3)
%30 = load i32, i32* %11
%31 = tail call i64 @S_ISDIR(i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %38, label %33
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %1
%36 = load i8*, i8** %18
%37 = tail call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* %36)
br label %40
38: ; preds = %28
%39 = tail call i32 @doit(i32 %21)
br label %40
40: ; preds = %38, %33
%41 = phi i32 [ 1, %33 ], [ %17, %38 ]
%42 = tail call i32 @close(i32 %21)
br label %43
43: ; preds = %40, %23
%44 = phi i32 [ 1, %23 ], [ %41, %40 ]
%45 = add nuw nsw i64 %16, 1
%46 = icmp eq i64 %45, %12
br i1 %46, label %13, label %15
}