#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 dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
char *dtfs_concat_path(char const *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int dtfs_list_node(const char *base, const char *node_path,
                   void (*new_sub_node)(const char *path, const char *name,
                                        void *priv),
                   void *priv) {
  char *str;
  DIR *dp;
  struct dirent *ep;
  if (new_sub_node == NULL)
    return 0;
  if (!base)
    return -1;
  str = dtfs_concat_path(base, node_path);
  if (!str) {
    fprintf(stderr, "dtfs_list_node: concat path failed (%m)\n");
    return -1;
  }
  dp = opendir(str);
  if (dp != NULL) {
    while ((ep = readdir(dp))) {
      if (ep->d_name[0] != '.')
        new_sub_node(str, ep->d_name, priv);
    }
    (void)closedir(dp);
  } else
    fprintf(stderr, "dtfs_list_node: Couldn't open the directory");
  free(str);
  return 0;
}


x86 assembly (clang, -O0):
<dtfs_list_node>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118f <dtfs_list_node+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    1277 <dtfs_list_node+0x117>
cmpq   $0x0,-0x10(%rbp)
jne    11a6 <dtfs_list_node+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    1277 <dtfs_list_node+0x117>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <dtfs_concat_path@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e3 <dtfs_list_node+0x83>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1277 <dtfs_list_node+0x117>
mov    -0x30(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1252 <dtfs_list_node+0xf2>
jmp    1200 <dtfs_list_node+0xa0>
mov    -0x38(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     1244 <dtfs_list_node+0xe4>
mov    -0x40(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     123f <dtfs_list_node+0xdf>
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rcx
mov    (%rcx),%rsi
mov    -0x28(%rbp),%rdx
call   *%rax
jmp    1200 <dtfs_list_node+0xa0>
mov    -0x38(%rbp),%rdi
call   1060 <closedir@plt>
jmp    1267 <dtfs_list_node+0x107>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdc7(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dtfs_list_node>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r14d,%r14d
test   %rdx,%rdx
je     120b <dtfs_list_node+0xab>
test   %rdi,%rdi
je     11bf <dtfs_list_node+0x5f>
mov    %rcx,%r15
mov    %rdx,%rbp
call   1040 <dtfs_concat_path@plt>
test   %rax,%rax
je     11d1 <dtfs_list_node+0x71>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     11ee <dtfs_list_node+0x8e>
mov    %rax,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     11c7 <dtfs_list_node+0x67>
mov    (%rax),%rsi
cmpb   $0x2e,(%rsi)
je     11a0 <dtfs_list_node+0x40>
mov    %r12,%rdi
mov    %r15,%rdx
call   *%rbp
jmp    11a0 <dtfs_list_node+0x40>
mov    $0xffffffff,%r14d
jmp    120b <dtfs_list_node+0xab>
mov    %rbx,%rdi
call   1060 <closedir@plt>
jmp    1203 <dtfs_list_node+0xa3>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%r14d
jmp    120b <dtfs_list_node+0xab>
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
call   1070 <fprintf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [41 x i8] c"dtfs_list_node: concat path failed (%m)\0A\00"
@.str.1 = [44 x i8] c"dtfs_list_node: Couldn't open the directory\00"
define i32 @dtfs_list_node(i8* %0, i8* %1, void (i8*, i8*, i8*)* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca void (i8*, i8*, i8*)*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca %struct.dirent*
store i8* %0, i8** %6
store i8* %1, i8** %7
store void (i8*, i8*, i8*)* %2, void (i8*, i8*, i8*)** %8
store i8* %3, i8** %9
%13 = load void (i8*, i8*, i8*)*, void (i8*, i8*, i8*)** %8
%14 = icmp eq void (i8*, i8*, i8*)* %13, null
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 0, i32* %5
br label %64
16: ; preds = %4
%17 = load i8*, i8** %6
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %16
store i32 -1, i32* %5
br label %64
20: ; preds = %16
%21 = load i8*, i8** %6
%22 = load i8*, i8** %7
%23 = call i8* @dtfs_concat_path(i8* %21, i8* %22)
store i8* %23, i8** %10
%24 = load i8*, i8** %10
%25 = icmp ne i8* %24, null
br i1 %25, label %29, label %26
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %64
29: ; preds = %20
%30 = load i8*, i8** %10
%31 = call i32* @opendir(i8* %30)
store i32* %31, i32** %11
%32 = load i32*, i32** %11
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %58
34: ; preds = %29
br label %35
35: ; preds = %54, %34
%36 = load i32*, i32** %11
%37 = call %struct.dirent* @readdir(i32* %36)
store %struct.dirent* %37, %struct.dirent** %12
%38 = icmp ne %struct.dirent* %37, null
br i1 %38, label %39, label %55
39: ; preds = %35
%40 = load %struct.dirent*, %struct.dirent** %12
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = getelementptr inbounds i8, i8* %42, i64 0
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp ne i32 %45, 46
br i1 %46, label %47, label %54
47: ; preds = %39
%48 = load void (i8*, i8*, i8*)*, void (i8*, i8*, i8*)** %8
%49 = load i8*, i8** %10
%50 = load %struct.dirent*, %struct.dirent** %12
%51 = getelementptr inbounds %struct.dirent, %struct.dirent* %50, i32 0, i32 0
%52 = load i8*, i8** %51
%53 = load i8*, i8** %9
br label %54
54: ; preds = %47, %39
br label %35
55: ; preds = %35
%56 = load i32*, i32** %11
%57 = call i32 @closedir(i32* %56)
br label %61
58: ; preds = %29
%59 = load i32, i32* @stderr
%60 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %61
61: ; preds = %58, %55
%62 = load i8*, i8** %10
%63 = call i32 @free(i8* %62)
store i32 0, i32* %5
br label %64
64: ; preds = %61, %26, %19, %15
%65 = load i32, i32* %5
ret i32 %65
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [41 x i8] c"dtfs_list_node: concat path failed (%m)\0A\00"
@.str.1 = [44 x i8] c"dtfs_list_node: Couldn't open the directory\00"
define i32 @dtfs_list_node(i8* %0, i8* %1, void (i8*, i8*, i8*)* %2, i8* %3) {
%5 = icmp eq void (i8*, i8*, i8*)* %2, null
br i1 %5, label %37, label %6
6: ; preds = %4
%7 = icmp eq i8* %0, null
br i1 %7, label %37, label %8
8: ; preds = %6
%9 = tail call i8* @dtfs_concat_path(i8* %0, i8* %1)
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
br label %37
14: ; preds = %8
%15 = tail call i32* @opendir(i8* %9)
%16 = icmp eq i32* %15, null
br i1 %16, label %32, label %17
17: ; preds = %14
%18 = tail call %struct.dirent* @readdir(i32* %15)
%19 = icmp eq %struct.dirent* %18, null
br i1 %19, label %30, label %20
20: ; preds = %17, %27
%21 = phi %struct.dirent* [ %28, %27 ], [ %18, %17 ]
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i64 0, i32 0
%23 = load i8*, i8** %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 46
br i1 %25, label %27, label %26
26: ; preds = %20
tail call void %2(i8* %9, i8* %23, i8* %3)
br label %27
27: ; preds = %26, %20
%28 = tail call %struct.dirent* @readdir(i32* %15)
%29 = icmp eq %struct.dirent* %28, null
br i1 %29, label %30, label %20
30: ; preds = %27, %17
%31 = tail call i32 @closedir(i32* %15)
br label %35
32: ; preds = %14
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %32, %30
%36 = tail call i32 @free(i8* %9)
br label %37
37: ; preds = %6, %4, %35, %11
%38 = phi i32 [ 0, %35 ], [ -1, %11 ], [ 0, %4 ], [ -1, %6 ]
ret i32 %38
}