// File: /workspace/github_c_makefile_star2_O0/dolphinking[P]slimox/src/slimox-pack.c
// Function: traverse_directory_make_header
static int traverse_directory_make_header(const char* path, const char* root, FILE* fp) {
    string_t* fulldir_path = str_new_with(path);
    string_t* rootdir_path = str_new_with(root);
    string_t* full_path;
    string_t* root_path;
    struct file_item* item = file_item_new();
    DIR* dir;
    struct dirent* dirent;

    formalize_path(fulldir_path);
    formalize_path(rootdir_path);

    /* write file item of current path */
    if(!file_item_from_path(item, fulldir_path, rootdir_path)) {
        fprintf(stderr, "warning: cannot stat '%s'.\n", fulldir_path->str);
        file_item_del(item);
        str_del(fulldir_path);
        str_del(rootdir_path);
        return -1;
    }
    file_item_put(item, fp);

    /* traverse directory */
    if(S_ISDIR(item->m_mode)) {
        if((dir = opendir(fulldir_path->str)) == NULL) {
            fprintf(stderr, "warning: cannot open directory '%s'.\n", fulldir_path->str);
            file_item_del(item);
            str_del(fulldir_path);
            str_del(rootdir_path);
            return -1;
        }

        full_path = str_new();
        root_path = str_new();
        while((dirent = readdir(dir)) != NULL) {
            if(strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, "..") == 0) {
                continue;
            }
            str_sprintf(full_path, PATH_JOINER, fulldir_path->str, dirent->d_name); /* reach a sub file/dir */
            str_sprintf(root_path, PATH_JOINER, rootdir_path->str, dirent->d_name);

            if(!file_item_from_path(item, full_path, root_path)) { /* get file item */
                fprintf(stderr, "warning: cannot stat '%s'.\n", full_path->str);
                continue;
            }
            if(S_ISREG(item->m_mode) || S_ISDIR(item->m_mode)) { /* traverse into a sub directory */
                traverse_directory_make_header(full_path->str, root_path->str, fp);
            }
        }
        closedir(dir);
        str_del(full_path);
        str_del(root_path);
    }
    str_del(fulldir_path);
    str_del(rootdir_path);
    file_item_del(item);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x16590
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rdi
callq 0x16590
movq %rax, -0x30(%rbp)
callq 0x17040
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
callq 0x16640
movq -0x30(%rbp), %rdi
callq 0x16640
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x16ee0
cmpl $0x0, %eax
jne 0x16296
movq 0x4da2(%rip), %rax      # 0x1aff8
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x2547(%rip), %rsi      # 0x187af
movb $0x0, %al
callq 0x1150
movq -0x48(%rbp), %rdi
callq 0x16560
movq -0x28(%rbp), %rdi
callq 0x16ab0
movq -0x30(%rbp), %rdi
callq 0x16ab0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x16472
movq -0x48(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x16480
movq -0x48(%rbp), %rax
movl (%rax), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x16450
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x10a0
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
jne 0x16317
movq 0x4d21(%rip), %rax      # 0x1aff8
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x24e2(%rip), %rsi      # 0x187cb
movb $0x0, %al
callq 0x1150
movq -0x48(%rbp), %rdi
callq 0x16560
movq -0x28(%rbp), %rdi
callq 0x16ab0
movq -0x30(%rbp), %rdi
callq 0x16ab0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x16472
callq 0x17090
movq %rax, -0x38(%rbp)
callq 0x17090
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rdi
callq 0x1180
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x16435
movq -0x58(%rbp), %rdi
addq $0x13, %rdi
leaq 0x24a3(%rip), %rsi      # 0x187f2
callq 0x1140
cmpl $0x0, %eax
je 0x16372
movq -0x58(%rbp), %rdi
addq $0x13, %rdi
leaq 0x2489(%rip), %rsi      # 0x187f1
callq 0x1140
cmpl $0x0, %eax
jne 0x16374
jmp 0x16329
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x58(%rbp), %rcx
addq $0x13, %rcx
leaq 0x2363(%rip), %rsi      # 0x186f2
movb $0x0, %al
callq 0x16800
movq -0x40(%rbp), %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x58(%rbp), %rcx
addq $0x13, %rcx
leaq 0x2341(%rip), %rsi      # 0x186f2
movb $0x0, %al
callq 0x16800
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x16ee0
cmpl $0x0, %eax
jne 0x163f3
movq 0x4c23(%rip), %rax      # 0x1aff8
movq (%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdx
leaq 0x23c8(%rip), %rsi      # 0x187af
movb $0x0, %al
callq 0x1150
jmp 0x16329
movq -0x48(%rbp), %rax
movl (%rax), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
je 0x16417
movq -0x48(%rbp), %rax
movl (%rax), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x16430
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x20(%rbp), %rdx
callq 0x161f0
jmp 0x16329
movq -0x50(%rbp), %rdi
callq 0x1100
movq -0x38(%rbp), %rdi
callq 0x16ab0
movq -0x40(%rbp), %rdi
callq 0x16ab0
movq -0x28(%rbp), %rdi
callq 0x16ab0
movq -0x30(%rbp), %rdi
callq 0x16ab0
movq -0x48(%rbp), %rdi
callq 0x16560
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)