// File: /workspace/github_c_makefile_star2_O1/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 $0xc8, %rsp
movq %rdx, 0x20(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
callq 0x10b0
movq %rax, %r13
leaq 0x4(%rax), %rdi
callq 0x1190
testq %rax, %rax
je 0x9dfe
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1050
movq %r15, %rdi
callq 0x10b0
movq %rax, %rbp
leaq 0x4(%rax), %rdi
callq 0x1190
testq %rax, %rax
je 0x9e03
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
callq 0x1050
movl $0x10, %edi
callq 0x1190
movq %rax, %rbx
movq $0x0, (%rax)
movl $0x18, %edi
callq 0x1190
testq %rax, %rax
je 0x9e10
movq %rax, %r15
movl $0x4, %edi
callq 0x1190
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0x9e08
movb $0x0, (%rax)
movq $0x0, (%r15)
movq $0x1, 0x8(%r15)
movq %r15, 0x8(%rbx)
testq %r13, %r13
je 0x99ea
cmpb $0x2f, -0x1(%r12,%r13)
jne 0x99ea
movb $0x0, -0x1(%r12,%r13)
decq %r13
jne 0x99d7
testq %rbp, %rbp
je 0x9a02
cmpb $0x2f, -0x1(%r14,%rbp)
jne 0x9a02
movb $0x0, -0x1(%r14,%rbp)
decq %rbp
jne 0x99ef
leaq 0x38(%rsp), %rsi
movq %r12, %rdi
callq 0x1170
cmpl $-0x1, %eax
je 0x9db6
movl 0x50(%rsp), %eax
movl %eax, %ecx
andl $0xf000, %ecx           # imm = 0xF000
movl %ecx, %edx
negw %dx
jo 0x9a40
cmpl $0x4000, %ecx           # imm = 0x4000
jne 0x9db6
movq $0x0, 0x68(%rsp)
movq %r12, 0x18(%rsp)
movl %eax, (%rbx)
movl 0x68(%rsp), %eax
movl %eax, 0x4(%rbx)
movq %r14, %rdi
callq 0x10b0
movq %rax, %r12
movq 0x10(%r15), %rdi
leaq 0x4(%rax), %r13
movq %r13, %rsi
callq 0x11c0
testq %rax, %rax
je 0x9e15
movq %rbx, %rbp
addq $0x4, %rbx
movq %rax, 0x10(%r15)
movq %rax, %rdi
movq %r14, %rsi
callq 0x1050
movq %r12, (%r15)
movq %r13, 0x8(%r15)
movl $0x4, %esi
movl $0x1, %edx
movq %rbp, %rdi
movq 0x20(%rsp), %r12
movq %r12, %rcx
callq 0x1220
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rcx
callq 0x1220
movq %rbp, %r15
movq 0x8(%rbp), %r13
movq %r12, %rbp
movl $0x8, %esi
movl $0x1, %edx
movq %r13, %rdi
movq %r12, %rcx
callq 0x1220
cmpq $0x0, (%r13)
movq 0x18(%rsp), %r12
je 0x9b12
xorl %ebx, %ebx
movq 0x10(%r13), %rax
movzbl (%rax,%rbx), %eax
movl $0x0, %ecx
cmpb $0x2f, %al
je 0x9afe
movl %eax, %ecx
movsbl %cl, %edi
movq %rbp, %rsi
callq 0x1110
incq %rbx
cmpq (%r13), %rbx
jb 0x9aeb
movl $0xf000, %eax           # imm = 0xF000
movq %r15, %rbx
andl (%r15), %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0x9d71
movq %r12, %rdi
callq 0x10a0
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0x9de4
movl $0x18, %edi
callq 0x1190
testq %rax, %rax
je 0x9e22
movq %rax, %rbp
movl $0x4, %edi
callq 0x1190
movq %rax, 0x10(%rbp)
testq %rax, %rax
je 0x9e1a
movb $0x0, (%rax)
movq $0x0, (%rbp)
movq $0x1, 0x8(%rbp)
movl $0x18, %edi
callq 0x1190
testq %rax, %rax
je 0x9e2f
movq %rax, %r15
movl $0x4, %edi
callq 0x1190
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0x9e27
movb $0x0, (%rax)
movq $0x0, (%r15)
movq %r15, 0x8(%rsp)
movq $0x1, 0x8(%r15)
movq 0x10(%rsp), %rdi
callq 0x1180
testq %rax, %rax
je 0x9d40
movq %rax, %r15
movq %rbp, 0x28(%rsp)
addq $0x13, %r15
movq %r15, %rdi
leaq 0x1c17(%rip), %rsi      # 0xb802
callq 0x1140
testl %eax, %eax
je 0x9d0b
movq %r15, %rdi
leaq 0x1bff(%rip), %rsi      # 0xb801
callq 0x1140
testl %eax, %eax
je 0x9d0b
movq %rbp, %rdi
movq %r12, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x9f9a
movq 0x8(%rsp), %rdi
movq %r14, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x9f9a
movq 0x10(%rbp), %r15
movq %r15, %rdi
leaq 0x38(%rsp), %rsi
callq 0x1170
cmpl $-0x1, %eax
je 0x9d23
movl 0x50(%rsp), %eax
movl %eax, %ecx
andl $0xf000, %ecx           # imm = 0xF000
movl %ecx, %edx
negw %dx
jo 0x9c73
cmpl $0x4000, %ecx           # imm = 0x4000
jne 0x9d23
movq $0x0, 0x68(%rsp)
movq %r15, 0x30(%rsp)
movq %r14, %r15
movl %eax, (%rbx)
movl 0x68(%rsp), %eax
movl %eax, 0x4(%rbx)
movq 0x8(%rsp), %rax
movq 0x10(%rax), %r12
movq %r12, %rdi
callq 0x10b0
movq %rax, %rbp
movq 0x10(%r13), %rdi
movq %rbx, %r14
leaq 0x4(%rax), %rbx
movq %rbx, %rsi
callq 0x11c0
testq %rax, %rax
je 0x9df9
movq %rax, 0x10(%r13)
movq %rax, %rdi
movq %r12, %rsi
callq 0x1050
movq %rbp, (%r13)
movq %rbx, 0x8(%r13)
movl (%r14), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x4000, %eax           # imm = 0x4000
movq 0x18(%rsp), %r12
movq %r14, %rbx
movq %r15, %r14
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rbp
je 0x9cf8
cmpl $0x8000, %eax           # imm = 0x8000
jne 0x9d0b
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x30(%rsp), %rdi
callq 0x990c
movq 0x10(%rsp), %rdi
callq 0x1180
movq %rax, %r15
testq %rax, %rax
jne 0x9bdd
jmp 0x9d40
movq 0x42ce(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x1a8b(%rip), %rsi      # 0xb7bf
movq %r15, %rdx
xorl %eax, %eax
callq 0x1150
jmp 0x9d0b
movq 0x10(%rsp), %rdi
callq 0x1100
movq 0x10(%rbp), %rdi
callq 0x1030
movq %rbp, %rdi
callq 0x1030
movq 0x8(%rsp), %r15
movq 0x10(%r15), %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
movq %r12, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movq 0x10(%r13), %rdi
xorl %ebp, %ebp
movq %r13, %r12
movq %rbx, %r14
callq 0x1030
movq %r12, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x423b(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x19f8(%rip), %rsi      # 0xb7bf
movq %r12, %rdx
xorl %eax, %eax
callq 0x1150
movq 0x10(%r15), %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
jmp 0x9def
movq %r12, %rdi
movq %r13, %rsi
callq 0x14ca
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rbx, %rdi
jmp 0x9d8d
callq 0x1464
callq 0x1561
callq 0x153f
movq %r15, %rdi
callq 0x1030
callq 0x151d
callq 0x14fb
movq %rbp, %rdi
callq 0x1030
callq 0x14a8
movq %r15, %rdi
callq 0x1030
callq 0x1486