#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 dir;

/* Variables and functions */
int dfs_dir_findfirst(char *, char *);
int dfs_dir_findnext(char *);
int /*<<< orphan*/ pr_depth(int);
int /*<<< orphan*/ printf(char *, char *);
void list_dir(char *directory, int depth) {
  char path[512];
  int dir = dfs_dir_findfirst(directory, path);
  do {
    pr_depth(depth);
    printf("%s\n", path);
    if (((dir)&3) == 0x1) {
      list_dir(path, depth + 2);
    }
  } while ((dir = dfs_dir_findnext(path)) != 0x2);
}


x86 assembly (clang, -O0):
<list_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1060 <dfs_dir_findfirst@plt>
mov    %eax,-0x214(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <pr_depth@plt>
lea    -0x210(%rbp),%rsi
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
mov    -0x214(%rbp),%eax
and    $0x3,%eax
cmp    $0x1,%eax
jne    11b7 <list_dir+0x67>
lea    -0x210(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0x2,%esi
call   1050 <list_dir@plt>
jmp    11bc <list_dir+0x6c>
lea    -0x210(%rbp),%rdi
call   1070 <dfs_dir_findnext@plt>
mov    %eax,-0x214(%rbp)
cmp    $0x2,%eax
jne    1178 <list_dir+0x28>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_dir>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %esi,%r14d
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1060 <dfs_dir_findfirst@plt>
mov    %eax,%ebp
lea    0x2(%r14),%r12d
lea    0xe86(%rip),%r15
jmp    118f <list_dir+0x3f>
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <dfs_dir_findnext@plt>
mov    %eax,%ebp
cmp    $0x2,%eax
je     11b7 <list_dir+0x67>
mov    %r14d,%edi
call   1040 <pr_depth@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
and    $0x3,%ebp
cmp    $0x1,%ebp
jne    1180 <list_dir+0x30>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1050 <list_dir@plt>
jmp    1180 <list_dir+0x30>
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define void @list_dir(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [512 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%9 = call i32 @dfs_dir_findfirst(i8* %7, i8* %8)
store i32 %9, i32* %6
br label %10
10: ; preds = %23, %2
%11 = load i32, i32* %4
%12 = call i32 @pr_depth(i32 %11)
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* %6
%16 = and i32 %15, 3
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %22
18: ; preds = %10
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 2
br label %22
22: ; preds = %18, %10
br label %23
23: ; preds = %22
%24 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%25 = call i32 @dfs_dir_findnext(i8* %24)
store i32 %25, i32* %6
%26 = icmp ne i32 %25, 2
br i1 %26, label %10, label %27
27: ; preds = %23
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define void @list_dir(i8* %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = call i32 @dfs_dir_findfirst(i8* %0, i8* %4)
%6 = add nsw i32 %1, 2
br label %7
7: ; preds = %14, %2
%8 = phi i32 [ %5, %2 ], [ %15, %14 ]
%9 = call i32 @pr_depth(i32 %1)
%10 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%11 = and i32 %8, 3
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %7
br label %14
14: ; preds = %7, %13
%15 = call i32 @dfs_dir_findnext(i8* %4)
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %7
17: ; preds = %14
ret void
}