// File: /workspace/github_c_makefile_star2_O3/johsteffens[P]beth/lib/bcore/bcore_folder.c
// Function: bcore_folder_s_parse
bl_t bcore_folder_s_parse( bcore_folder_s* o, sc_t path, bl_t recurse )
{
    BLM_INIT();
    bcore_folder_s_clear( o );

    if( !bcore_folder_exists( path ) ) BLM_RETURNV( bl_t, false );

    struct dirent* entry;
    struct stat file_stat;

    DIR* dirp = opendir( path );
    if( !dirp ) BLM_RETURNV( bl_t, false );

    st_s_copy_sc( &o->name, path );

    st_s* full_path = BLM_CREATE( st_s );

    while( ( entry = readdir( dirp ) ) )
    {
        if( !sc_t_equ( entry->d_name, "." ) && !sc_t_equ( entry->d_name, ".." ) )
        {
            st_s_copy_fa( full_path, "#<sc_t>/#<sc_t>", path, entry->d_name );
            if( stat( full_path->sc, &file_stat ) == 0 )
            {
                if( S_ISREG( file_stat.st_mode ) ) // regular file
                {
                    bcore_arr_st_s_push_sc( &o->arr_file, full_path->sc );
                }
                else if( recurse && S_ISDIR( file_stat.st_mode ) ) // folder
                {
                    bcore_folder_s* sub_folder = bcore_folder_s_create();
                    if( bcore_folder_s_parse( sub_folder, full_path->sc, recurse ) )
                    {
                        bcore_array_a_push( ( bcore_array* )o, sr_asm( sub_folder ) );
                    }
                    else
                    {
                        bcore_folder_s_discard( sub_folder );
                    }
                }
            }
        }
    }

    if( closedir( dirp ) ) ERR_fa( "Error closing path '#<sc_t>'.", path );

    BLM_RETURNV( bl_t, true );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movl %edx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xd53a5(%rip), %rax     # 0x19bdd0
movq (%rax), %rsi
leaq 0x58(%rsp), %rdi
callq 0xd6675
movq %r14, %rdi
callq 0xc694b
leaq 0x88(%rsp), %rsi
movq %rbx, %rdi
callq 0xd460
testl %eax, %eax
jne 0xc6ceb
movl $0xf000, %eax           # imm = 0xF000
andl 0xa0(%rsp), %eax
cmpl $0x4000, %eax           # imm = 0x4000
jne 0xc6ceb
movq %rbx, %rdi
callq 0xd260
testq %rax, %rax
setne %r15b
je 0xc6cdf
movq %rax, %r12
movl %r15d, 0x2c(%rsp)
movl %ebp, 0x1c(%rsp)
movq %r14, 0x20(%rsp)
leaq 0x8(%r14), %rdi
movq %rbx, %rsi
callq 0x109612
xorl %eax, %eax
callq 0x109c82
leaq 0x58(%rsp), %rdi
movabsq $-0x503db0e6e1c2e704, %rsi # imm = 0xAFC24F191E3D18FC
movq %rax, %rdx
callq 0xd67bd
movq %rax, %r13
movq %r12, %rdi
callq 0xd280
testq %rax, %rax
je 0xc6caa
movq %rax, %r14
movq 0x20(%rsp), %rax
addq $0x40, %rax
movq %rax, 0x38(%rsp)
leaq 0x6a0a8(%rip), %rbp     # 0x130b93
leaq 0x66783(%rip), %r15     # 0x12d275
movl 0x1c(%rsp), %eax
xorb $0x1, %al
movl %eax, 0x1c(%rsp)
addq $0x13, %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0xdfa34
testl %eax, %eax
je 0xc6c96
movq %r14, %rdi
movq %r15, %rsi
callq 0xdfa34
testl %eax, %eax
je 0xc6c96
movq %r13, %rdi
leaq 0x66548(%rip), %rsi     # 0x12d078
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x1097fd
movq 0x8(%r13), %rdi
leaq 0x88(%rsp), %rsi
callq 0xd460
testl %eax, %eax
jne 0xc6c96
movl 0xa0(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x8000, %eax           # imm = 0x8000
jne 0xc6b7e
movq 0x8(%r13), %rsi
movq 0x38(%rsp), %rdi
callq 0xb9ea0
jmp 0xc6c96
cmpl $0x4000, %eax           # imm = 0x4000
setne %al
orb 0x1c(%rsp), %al
jne 0xc6c96
callq 0xc6724
movq %rax, %r14
movq 0x8(%r13), %rsi
movq %rax, %rdi
movl $0x1, %edx
callq 0xc6a0b
testb %al, %al
je 0xc6bbc
testq %r14, %r14
je 0xc6bc9
movq (%r14), %rdi
callq 0x1074f1
jmp 0xc6bcb
movq %r14, %rdi
callq 0xc67cf
jmp 0xc6c96
xorl %eax, %eax
movq %r14, 0x40(%rsp)
movq %rax, 0x48(%rsp)
movq $0x2, 0x50(%rsp)
movq 0x20(%rsp), %rax
movq (%rax), %rsi
leaq 0xd5233(%rip), %rdx     # 0x19be20
movl (%rdx), %eax
cltq
leaq (%rax,%rax,2), %rax
movq 0x20(%rdx,%rax,8), %rcx
movq 0x18(%rdx,%rax,8), %rdx
andq %rsi, %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rax
movq (%rcx,%rdx), %rdx
movl $0x8, %ecx
cmpq %rsi, %rdx
je 0xc6c42
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %rsi, %rdx
je 0xc6c42
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %rsi, %rdx
je 0xc6c42
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %rsi, %rdx
jne 0xc6c4b
movq (%rax,%rcx), %r14
testq %r14, %r14
jne 0xc6c76
movabsq $-0x5073d588c3beb52e, %rdi # imm = 0xAF8C2A773C414AD2
movq %rsi, 0x30(%rsp)
callq 0xe9bc5
movq %rax, %r14
leaq 0xd51b7(%rip), %rdi     # 0x19be20
movq 0x30(%rsp), %rsi
movq %rax, %rdx
callq 0x115fac
movq 0x50(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x40(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
movq 0x20(%rsp), %rsi
callq 0xed355
movq %r12, %rdi
callq 0xd280
movq %rax, %r14
testq %rax, %rax
jne 0xc6afc
movq %r12, %rdi
callq 0xd3b0
testl %eax, %eax
movl 0x2c(%rsp), %r15d
je 0xc6cdf
leaq 0x7e673(%rip), %rdi     # 0x145335
leaq 0x7e65d(%rip), %rsi     # 0x145326
leaq 0x7e67a(%rip), %rcx     # 0x14534a
movl $0x96, %edx
movq %rbx, %r8
xorl %eax, %eax
callq 0xbe6f9
leaq 0x58(%rsp), %rdi
callq 0xd6d2c
jmp 0xc6cf8
leaq 0x58(%rsp), %rdi
callq 0xd6d2c
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq