#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*/ HandleDirectory(char const *);
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  const char *dir = "";
  if (argc > 1) {
    struct stat sbuf;
    dir = argv[1];
    if (stat(dir, &sbuf) < 0) {
      fprintf(stderr, "Unable to open %s: %s\n", dir, strerror(errno));
      return 1;
    }
    if (!S_ISDIR(sbuf.st_mode)) {
      fprintf(stderr, "%s is not a directory\n", dir);
      return 1;
    }
  } else {
    dir = ".";
  }
  HandleDirectory(dir);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea9(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1221 <main+0xd1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%rax
jge    11e4 <main+0x94>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123c <main+0xec>
mov    -0x20(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    121c <main+0xcc>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123c <main+0xec>
jmp    122c <main+0xdc>
lea    0xe06(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <HandleDirectory@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     1194 <main+0x44>
mov    0x8(%rsi),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <stat@plt>
test   %rax,%rax
js     11a7 <main+0x57>
mov    (%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %eax,%eax
jne    119b <main+0x4b>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    11d4 <main+0x84>
lea    0xe93(%rip),%rbx
mov    %rbx,%rdi
call   1030 <HandleDirectory@plt>
xor    %eax,%eax
jmp    11d9 <main+0x89>
mov    0x2e32(%rip),%rax
mov    (%rax),%ebp
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe3b(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [1 x i8] zeroinitializer
@stderr = global i32 0
@.str.1 = [23 x i8] c"Unable to open %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"%s is not a directory\0A\00"
@.str.3 = [2 x i8] c".\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %6
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %33
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = call i64 @stat(i8* %14, %struct.stat* %7)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %6
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %21)
store i32 1, i32* %3
br label %37
23: ; preds = %10
%24 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @S_ISDIR(i32 %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %6
%31 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %30)
store i32 1, i32* %3
br label %37
32: ; preds = %23
br label %34
33: ; preds = %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %6
br label %34
34: ; preds = %33, %32
%35 = load i8*, i8** %6
%36 = call i32 @HandleDirectory(i8* %35)
store i32 0, i32* %3
br label %37
37: ; preds = %34, %28, %17
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str.1 = [23 x i8] c"Unable to open %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"%s is not a directory\0A\00"
@.str.3 = [2 x i8] c".\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %26
5: ; preds = %2
%6 = bitcast %struct.stat* %3 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i64 @stat(i8* %8, %struct.stat* %3)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %5
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %8, i8* %14)
br label %24
16: ; preds = %5
%17 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @S_ISDIR(i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %24
24: ; preds = %21, %11
br label %29
25: ; preds = %16
br label %26
26: ; preds = %25, %2
%27 = phi i8* [ %8, %25 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), %2 ]
%28 = call i32 @HandleDirectory(i8* %27)
br label %29
29: ; preds = %24, %26
%30 = phi i32 [ 0, %26 ], [ 1, %24 ]
ret i32 %30
}