// File: /workspace/github_c_makefile_star2_O3/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 $0xd8, %rsp
movq %rdx, 0x28(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
callq 0x10b0
movq %rax, %r12
leaq 0x4(%rax), %rdi
callq 0x1180
testq %rax, %rax
je 0xa54a
movq %rax, %rbp
movq %rax, %rdi
movq %r14, %rsi
callq 0x1050
movq %rbx, %rdi
callq 0x10b0
movq %rax, %r13
leaq 0x4(%rax), %rdi
callq 0x1180
testq %rax, %rax
je 0xa54f
movq %rax, %r14
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1050
movl $0x10, %edi
callq 0x1180
movq %rax, 0x8(%rsp)
movl $0x18, %edi
callq 0x1180
testq %rax, %rax
je 0xa55c
movq %rax, %r15
movl $0x4, %edi
callq 0x1180
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0xa554
movb $0x0, (%rax)
movq $0x0, (%r15)
movq $0x1, 0x8(%r15)
movq 0x8(%rsp), %rax
movq %r15, 0x8(%rax)
testq %r12, %r12
je 0xa11d
cmpb $0x2f, -0x1(%rbp,%r12)
jne 0xa11d
movb $0x0, -0x1(%rbp,%r12)
decq %r12
jne 0xa10a
testq %r13, %r13
je 0xa135
cmpb $0x2f, -0x1(%r14,%r13)
jne 0xa135
movb $0x0, -0x1(%r14,%r13)
decq %r13
jne 0xa122
leaq 0x48(%rsp), %rsi
movq %rbp, %rdi
callq 0x1160
cmpl $-0x1, %eax
movq 0x8(%rsp), %r13
je 0xa4f8
movl 0x60(%rsp), %eax
movl %eax, %edx
andl $0xf000, %edx           # imm = 0xF000
xorl %ecx, %ecx
cmpl $0x4000, %edx           # imm = 0x4000
je 0xa176
cmpl $0x8000, %edx           # imm = 0x8000
jne 0xa4f8
movl 0x78(%rsp), %ecx
movl %eax, (%r13)
movl %ecx, 0x4(%r13)
movq %r14, %rdi
callq 0x10b0
movq %rax, %rbx
movq 0x10(%r15), %rdi
leaq 0x4(%rax), %r12
movq %r12, %rsi
callq 0x11b0
testq %rax, %rax
je 0xa561
movq %r14, %rsi
movq %r13, %r14
addq $0x4, %r14
movq %rax, 0x10(%r15)
movq %rax, %rdi
movq %rsi, 0x10(%rsp)
callq 0x1050
movq %rbx, (%r15)
movq %r12, 0x8(%r15)
movl $0x4, %esi
movl $0x1, %edx
movq %r13, %rdi
movq 0x28(%rsp), %rbx
movq %rbx, %rcx
callq 0x1210
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rbx, %r14
movq %rbx, %rcx
callq 0x1210
movq 0x8(%r13), %r12
movl $0x8, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %rbx, %rcx
callq 0x1210
cmpq $0x0, (%r12)
je 0xa240
xorl %ebx, %ebx
movq 0x10(%r12), %rax
movzbl (%rax,%rbx), %eax
movl $0x0, %ecx
cmpb $0x2f, %al
je 0xa22c
movl %eax, %ecx
movsbl %cl, %edi
movq %r14, %rsi
callq 0x1110
incq %rbx
cmpq (%r12), %rbx
jb 0xa218
movl $0xf000, %eax           # imm = 0xF000
movq 0x8(%rsp), %r15
andl (%r15), %eax
cmpl $0x4000, %eax           # imm = 0x4000
movq 0x10(%rsp), %r14
jne 0xa4b2
movq %rbp, %rdi
callq 0x10a0
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0xa52e
movq %rbp, 0x40(%rsp)
movq %r12, 0x38(%rsp)
movl $0x18, %edi
callq 0x1180
testq %rax, %rax
je 0xa56e
movq %rax, %rbp
movl $0x4, %edi
callq 0x1180
movq %rax, 0x10(%rbp)
testq %rax, %rax
je 0xa566
movq %rax, %r15
movb $0x0, (%rax)
movq $0x0, (%rbp)
movq $0x1, 0x8(%rbp)
movl $0x18, %edi
callq 0x1180
testq %rax, %rax
je 0xa57b
movq %rax, %r13
movl $0x4, %edi
callq 0x1180
movq %rax, 0x10(%r13)
testq %rax, %rax
je 0xa573
movb $0x0, (%rax)
movq $0x0, (%r13)
movq $0x1, 0x8(%r13)
movq 0x18(%rsp), %rdi
callq 0x1170
testq %rax, %rax
je 0xa478
movq %rax, %rbx
movq %rbp, 0x30(%rsp)
cmpb $0x2e, 0x13(%rbx)
jne 0xa33b
cmpb $0x0, 0x14(%rbx)
je 0xa462
cmpb $0x2e, 0x14(%rbx)
jne 0xa33b
cmpb $0x0, 0x15(%rbx)
je 0xa462
addq $0x13, %rbx
movq %rbp, %rdi
movq 0x40(%rsp), %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0xa6fb
movq %r13, %rdi
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0xa6fb
movq 0x10(%rbp), %rdi
movq %rdi, 0x20(%rsp)
leaq 0x48(%rsp), %rsi
callq 0x1160
cmpl $-0x1, %eax
je 0xa442
movl 0x60(%rsp), %eax
movl %eax, %r15d
andl $0xf000, %r15d          # imm = 0xF000
xorl %ecx, %ecx
cmpl $0x4000, %r15d          # imm = 0x4000
je 0xa3a7
cmpl $0x8000, %r15d          # imm = 0x8000
jne 0xa442
movl 0x78(%rsp), %ecx
movq 0x8(%rsp), %rdx
movl %eax, (%rdx)
movl %ecx, 0x4(%rdx)
movq %r13, %r12
movq 0x10(%r13), %rbx
movq %rbx, %rdi
callq 0x10b0
movq %rax, %rbp
movq 0x38(%rsp), %r13
movq 0x10(%r13), %rdi
leaq 0x4(%rax), %r14
movq %r14, %rsi
callq 0x11b0
testq %rax, %rax
je 0xa545
movq %rax, 0x10(%r13)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x1050
movq %rbp, (%r13)
movq %r14, 0x8(%r13)
movzwl %r15w, %eax
cmpl $0x8000, %eax           # imm = 0x8000
je 0xa40a
cmpl $0x4000, %eax           # imm = 0x4000
jne 0xa42e
movq 0x20(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq 0x28(%rsp), %rdx
callq 0xa03f
movq 0x10(%rsp), %r14
movq 0x30(%rsp), %rbp
movq %r12, %r13
jmp 0xa462
movq 0x10(%rsp), %r14
movq 0x30(%rsp), %rbp
movq %r12, %r13
movq 0x20(%rsp), %r15
jmp 0xa462
movq 0x3baf(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x139c(%rip), %rsi      # 0xb7ef
movq 0x20(%rsp), %r15
movq %r15, %rdx
xorl %eax, %eax
callq 0x1140
movq 0x18(%rsp), %rdi
callq 0x1170
movq %rax, %rbx
testq %rax, %rax
jne 0xa31b
movq 0x18(%rsp), %rdi
callq 0x1100
movq %r15, %rdi
callq 0x1030
movq %rbp, %rdi
callq 0x1030
movq 0x10(%r13), %rdi
callq 0x1030
movq %r13, %rdi
callq 0x1030
movq 0x8(%rsp), %r15
movq 0x38(%rsp), %r12
movq 0x40(%rsp), %rbp
movq %rbp, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movq 0x10(%r12), %rdi
callq 0x1030
xorl %ebx, %ebx
movq %r12, %rbp
movq %r15, %r14
movq %rbp, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
movl %ebx, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3af9(%rip), %rax      # 0xdff8
movq (%rax), %rdi
leaq 0x12e6(%rip), %rsi      # 0xb7ef
movq %rbp, %rdx
xorl %eax, %eax
callq 0x1140
movq 0x10(%r15), %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
movq %r13, %rdi
callq 0x1030
jmp 0xa53e
movq %rbp, %rdi
movq %r12, %rsi
movq 0x8(%rsp), %rdx
callq 0x1465
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xa4d4
callq 0x13ff
callq 0x1510
callq 0x14ee
movq %r15, %rdi
callq 0x1030
callq 0x14cc
callq 0x14aa
movq %rbp, %rdi
callq 0x1030
callq 0x1443
movq %r13, %rdi
callq 0x1030
callq 0x1421