#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 const *d_name;
};
struct ListNode {
  int dummy;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ joinDir(char *, char const *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ readFileNode(char *, struct ListNode **);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char const *, char *);
void readDir(const char *fpath, struct ListNode **file_list) {
  DIR *dir;
  struct dirent *ent;
  dir = opendir(fpath);
  if (dir != NULL) {
    while ((ent = readdir(dir)) != NULL) {
      if (strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0) {
        char buf[255 + 1] = {0};
        joinDir(buf, fpath);
        joinDir(buf, ent->d_name);
        readFileNode(buf, file_list);
      }
    }
    closedir(dir);
  }
}


x86 assembly (clang, -O0):
<readDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1245 <readDir+0xd5>
jmp    11a0 <readDir+0x30>
mov    -0x18(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     123c <readDir+0xcc>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe3c(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1237 <readDir+0xc7>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe1e(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1237 <readDir+0xc7>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <joinDir@plt>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   1030 <joinDir@plt>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <readFileNode@plt>
jmp    11a0 <readDir+0x30>
mov    -0x18(%rbp),%rdi
call   1070 <closedir@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readDir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <opendir@plt>
test   %rax,%rax
je     1283 <readDir+0x123>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     127b <readDir+0x11b>
mov    %rax,%r13
lea    0xe5e(%rip),%r12
mov    %rsp,%rbp
jmp    11c4 <readDir+0x64>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     127b <readDir+0x11b>
mov    0x0(%r13),%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11b0 <readDir+0x50>
mov    0x0(%r13),%rdi
lea    0xe20(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11b0 <readDir+0x50>
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rbp,%rdi
mov    %r15,%rsi
call   1030 <joinDir@plt>
mov    0x0(%r13),%rsi
mov    %rbp,%rdi
call   1030 <joinDir@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <readFileNode@plt>
jmp    11b0 <readDir+0x50>
mov    %rbx,%rdi
call   1060 <closedir@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ListNode = type { i32 }
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define void @readDir(i8* %0, %struct.ListNode** %1) {
%3 = alloca i8*
%4 = alloca %struct.ListNode**
%5 = alloca i32*
%6 = alloca %struct.dirent*
%7 = alloca [256 x i8]
store i8* %0, i8** %3
store %struct.ListNode** %1, %struct.ListNode*** %4
%8 = load i8*, i8** %3
%9 = call i32* @opendir(i8* %8)
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %46
12: ; preds = %2
br label %13
13: ; preds = %42, %12
%14 = load i32*, i32** %5
%15 = call %struct.dirent* @readdir(i32* %14)
store %struct.dirent* %15, %struct.dirent** %6
%16 = icmp ne %struct.dirent* %15, null
br i1 %16, label %17, label %43
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %6
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %42
23: ; preds = %17
%24 = load %struct.dirent*, %struct.dirent** %6
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %42
29: ; preds = %23
%30 = bitcast [256 x i8]* %7 to i8*
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%32 = load i8*, i8** %3
%33 = call i32 @joinDir(i8* %31, i8* %32)
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%35 = load %struct.dirent*, %struct.dirent** %6
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = call i32 @joinDir(i8* %34, i8* %37)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%40 = load %struct.ListNode**, %struct.ListNode*** %4
%41 = call i32 @readFileNode(i8* %39, %struct.ListNode** %40)
br label %42
42: ; preds = %29, %23, %17
br label %13
43: ; preds = %13
%44 = load i32*, i32** %5
%45 = call i32 @closedir(i32* %44)
br label %46
46: ; preds = %43, %2
ret void
}

LLVM IR (-O2):
%struct.ListNode = type { i32 }
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
define void @readDir(i8* %0, %struct.ListNode** %1) {
%3 = alloca [256 x i8]
%4 = tail call i32* @opendir(i8* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %31, label %6
6: ; preds = %2
%7 = call %struct.dirent* @readdir(i32* %4)
%8 = icmp eq %struct.dirent* %7, null
br i1 %8, label %29, label %9
9: ; preds = %6
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
br label %11
11: ; preds = %9, %26
%12 = phi %struct.dirent* [ %7, %9 ], [ %27, %26 ]
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %11
%18 = load i8*, i8** %13
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %17
%22 = call i32 @joinDir(i8* %10, i8* %0)
%23 = load i8*, i8** %13
%24 = call i32 @joinDir(i8* %10, i8* %23)
%25 = call i32 @readFileNode(i8* %10, %struct.ListNode** %1)
br label %26
26: ; preds = %21, %17, %11
%27 = call %struct.dirent* @readdir(i32* %4)
%28 = icmp eq %struct.dirent* %27, null
br i1 %28, label %29, label %11
29: ; preds = %26, %6
%30 = call i32 @closedir(i32* %4)
br label %31
31: ; preds = %29, %2
ret void
}