#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 */
typedef int /*<<< orphan*/ path;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int strlen(char *);
int /*<<< orphan*/ walkthrough(char *, int, int, int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    return 1;
  }
  DIR *root = opendir(argv[1]);
  if (!root) {
    return 1;
  }
  char path[PATH_MAX];
  memset(path, 0, sizeof(path));
  snprintf(path, sizeof(path), "%s", argv[1]);
  int pathlen = strlen(path);
  if (path[pathlen - 1] != '/') {
    path[pathlen++] = '/';
  }
  walkthrough(path, pathlen, sizeof(path), NULL);
  closedir(root);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     118c <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    1276 <main+0x116>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b4 <main+0x54>
movl   $0x1,-0x4(%rbp)
jmp    1276 <main+0x116>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xdfa(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1249 <main+0xe9>
mov    -0x38(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1080 <walkthrough@plt>
mov    -0x18(%rbp),%rdi
call   1070 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x1,%r12d
cmp    $0x2,%edi
jne    120d <main+0xad>
mov    %rsi,%r13
mov    0x8(%rsi),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     120d <main+0xad>
mov    %rax,%r14
mov    %rsp,-0x30(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%rbx
mov    %r15,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
xor    %r12d,%r12d
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1060 <memset@plt>
mov    0x8(%r13),%rcx
lea    0xe32(%rip),%rdx
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
movslq %eax,%rcx
cmpb   $0x2f,-0x1(%rcx,%rbx,1)
je     11f2 <main+0x92>
lea    0x1(%rcx),%eax
movb   $0x2f,(%rbx,%rcx,1)
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r15d,%edx
xor    %ecx,%ecx
call   1080 <walkthrough@plt>
mov    %r14,%rdi
call   1070 <closedir@plt>
mov    -0x30(%rbp),%rsp
mov    %r12d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 1, i32* %3
br label %53
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32* @opendir(i8* %16)
store i32* %17, i32** %6
%18 = load i32*, i32** %6
%19 = icmp ne i32* %18, null
br i1 %19, label %21, label %20
20: ; preds = %13
store i32 1, i32* %3
br label %53
21: ; preds = %13
%22 = load i32, i32* @PATH_MAX
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %7
%25 = alloca i8, i64 %23
store i64 %23, i64* %8
%26 = trunc i64 %23 to i32
%27 = call i32 @memset(i8* %25, i32 0, i32 %26)
%28 = trunc i64 %23 to i32
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @snprintf(i8* %25, i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = call i32 @strlen(i8* %25)
store i32 %33, i32* %9
%34 = load i32, i32* %9
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %25, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 47
br i1 %40, label %41, label %46
41: ; preds = %21
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i8, i8* %25, i64 %44
store i8 47, i8* %45
br label %46
46: ; preds = %41, %21
%47 = load i32, i32* %9
%48 = trunc i64 %23 to i32
%49 = call i32 @walkthrough(i8* %25, i32 %47, i32 %48, i32* null)
%50 = load i32*, i32** %6
%51 = call i32 @closedir(i32* %50)
store i32 0, i32* %3
%52 = load i8*, i8** %7
br label %53
53: ; preds = %46, %20, %12
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %31
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @opendir(i8* %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %31, label %9
9: ; preds = %4
%10 = load i32, i32* @PATH_MAX
%11 = zext i32 %10 to i64
%12 = tail call i8* @llvm.stacksave()
%13 = alloca i8, i64 %11
%14 = call i32 @memset(i8* %13, i32 0, i32 %10)
%15 = load i8*, i8** %5
%16 = call i32 @snprintf(i8* %13, i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @strlen(i8* %13)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %13, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 47
br i1 %22, label %27, label %23
23: ; preds = %9
%24 = add nsw i32 %17, 1
%25 = sext i32 %17 to i64
%26 = getelementptr inbounds i8, i8* %13, i64 %25
store i8 47, i8* %26
br label %27
27: ; preds = %23, %9
%28 = phi i32 [ %24, %23 ], [ %17, %9 ]
%29 = call i32 @walkthrough(i8* %13, i32 %28, i32 %10, i32* null)
%30 = call i32 @closedir(i32* %7)
br label %31
31: ; preds = %27, %4, %2
%32 = phi i32 [ 1, %2 ], [ 0, %27 ], [ 1, %4 ]
ret i32 %32
}