#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 */
scalar_t__ chdir(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ readable(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  char pathname[4096];
  if (argc > 2) {
    fprintf(stderr, "Usage ./readable <directory>\n");
    return 1;
  } else if (argv[1] != NULL) {
    if (chdir(argv[1]) != 0) {
      fprintf(stderr, "Problem reading directory\n");
      return 1;
    }
  }
  getcwd(pathname, 4096);
  readable(pathname);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1010,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1184 <main+0x44>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f9 <main+0xb9>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11d0 <main+0x90>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <chdir@plt>
cmp    $0x0,%rax
je     11cb <main+0x8b>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f9 <main+0xb9>
jmp    11d0 <main+0x90>
jmp    11d5 <main+0x95>
lea    -0x1010(%rbp),%rdi
mov    $0x1000,%esi
call   1050 <getcwd@plt>
lea    -0x1010(%rbp),%rdi
call   1040 <readable@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1010,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x1000,%rsp
cmp    $0x3,%edi
jl     115f <main+0x1f>
mov    0x2e8c(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
jmp    1182 <main+0x42>
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     118e <main+0x4e>
call   1030 <chdir@plt>
test   %rax,%rax
je     118e <main+0x4e>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    11a8 <main+0x68>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   1050 <getcwd@plt>
mov    %rbx,%rdi
call   1040 <readable@plt>
xor    %eax,%eax
add    $0x1000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Usage ./readable <directory>\0A\00"
@.str.1 = [27 x i8] c"Problem reading directory\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 2
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %33
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %27
17: ; preds = %12
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @chdir(i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %33
26: ; preds = %17
br label %27
27: ; preds = %26, %12
br label %28
28: ; preds = %27
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%30 = call i32 @getcwd(i8* %29, i32 4096)
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%32 = call i32 @readable(i8* %31)
store i32 0, i32* %3
br label %33
33: ; preds = %28, %23, %9
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Usage ./readable <directory>\0A\00"
@.str.1 = [27 x i8] c"Problem reading directory\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %22
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %9
%14 = tail call i64 @chdir(i8* %11)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %22
19: ; preds = %9, %13
%20 = call i32 @getcwd(i8* %4, i32 4096)
%21 = call i32 @readable(i8* %4)
br label %22
22: ; preds = %19, %16, %6
%23 = phi i32 [ 1, %6 ], [ 1, %16 ], [ 0, %19 ]
ret i32 %23
}