// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r12
movq %rsi, %rbx
callq 0x7611
movq %rax, %r14
movq %rbx, %rdi
callq 0x7611
movq %rax, %rbx
callq 0x7d93
movq %rax, %r15
movq %r14, %rdi
callq 0x7693
movq %rbx, %rdi
callq 0x7693
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, (%rsp)
movq %rbx, %rdx
callq 0x7cb8
testl %eax, %eax
je 0x7529
movq %r15, %rdi
movq %r12, %rsi
callq 0x7579
movl $0xf000, %eax           # imm = 0xF000
andl (%r15), %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x74ff
movq 0x10(%r14), %r13
movq %r13, %rdi
callq 0x10a0
testq %rax, %rax
je 0x7540
movq %rax, %rbp
movq %r12, 0x10(%rsp)
movq %r14, 0x8(%rsp)
callq 0x7db1
movq %rax, %r14
callq 0x7db1
movq %rax, %r12
movq %rbp, %rdi
callq 0x1170
testq %rax, %rax
je 0x74e2
movq %rax, %rbx
cmpb $0x2e, 0x13(%rax)
jne 0x7456
cmpb $0x0, 0x14(%rbx)
je 0x742a
cmpb $0x2e, 0x14(%rbx)
jne 0x7456
cmpb $0x0, 0x15(%rbx)
je 0x742a
addq $0x13, %rbx
movq %r14, %rdi
movq %r13, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x779a
movq (%rsp), %rax
movq 0x10(%rax), %rdx
movq %r12, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x779a
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x7cb8
testl %eax, %eax
je 0x74c1
movl (%r15), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
movl %eax, %ecx
negw %cx
jo 0x74a9
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x742a
movq 0x10(%r14), %rdi
movq 0x10(%r12), %rsi
movq 0x10(%rsp), %rdx
callq 0x7381
jmp 0x742a
movq 0x3b30(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq 0x10(%r14), %rdx
leaq 0x1259(%rip), %rsi      # 0x872f
xorl %eax, %eax
callq 0x1140
jmp 0x742a
movq %rbp, %rdi
callq 0x1100
movq %r14, %rdi
callq 0x7979
movq %r12, %rdi
callq 0x7979
movq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x7979
movq (%rsp), %rdi
callq 0x7979
movq %r15, %rdi
callq 0x75fb
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3ac8(%rip), %rax      # 0xaff8
movq (%rax), %rdi
movq 0x10(%r14), %rdx
leaq 0x11f1(%rip), %rsi      # 0x872f
jmp 0x7554
movq 0x3ab1(%rip), %rax      # 0xaff8
movq (%rax), %rdi
leaq 0x11fa(%rip), %rsi      # 0x874b
movq %r13, %rdx
xorl %eax, %eax
callq 0x1140
movq %r15, %rdi
callq 0x75fb
movq %r14, %rdi
callq 0x7979
movq (%rsp), %rdi
callq 0x7979
pushq $-0x1
popq %rax
jmp 0x751a