// File: /workspace/github_cpp_makefile_star2_O1/Fohlen[P]cubescript-standalone/stream.cpp
// Function: listdir(char const*, bool, char const*, vector<char*>&)
bool listdir(const char *dirname, bool rel, const char *ext, vector<char *> &files)
{
    size_t extsize = ext ? strlen(ext)+1 : 0;
#ifdef WIN32
    defformatstring(pathname)(rel ? ".\\%s\\*.%s" : "%s\\*.%s", dirname, ext ? ext : "*");
    WIN32_FIND_DATA FindFileData;
    HANDLE Find = FindFirstFile(pathname, &FindFileData);
    if(Find != INVALID_HANDLE_VALUE)
    {
        do {
            if(!ext) files.add(newstring(FindFileData.cFileName));
            else
            {
                size_t namelen = strlen(FindFileData.cFileName); 
                if(namelen > extsize) 
                { 
                    namelen -= extsize;
                    if(FindFileData.cFileName[namelen] == '.' && strncmp(FindFileData.cFileName+namelen+1, ext, extsize-1)==0)
                        files.add(newstring(FindFileData.cFileName, namelen));
                }
            }
        } while(FindNextFile(Find, &FindFileData));
        FindClose(Find);
        return true;
    }
#else
    defformatstring(pathname)(rel ? "./%s" : "%s", dirname);
    DIR *d = opendir(pathname);
    if(d)
    {
        struct dirent *de;
        while((de = readdir(d)) != NULL)
        {
            if(!ext) files.add(newstring(de->d_name));
            else
            {
                size_t namelen = strlen(de->d_name);
                if(namelen > extsize)
                {
                    namelen -= extsize;
                    if(de->d_name[namelen] == '.' && strncmp(de->d_name+namelen+1, ext, extsize-1)==0)
                        files.add(newstring(de->d_name, namelen));
                }
            }
        }
        closedir(d);
        return true;
    }
#endif
    else return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rcx, -0x40(%rbp)
movq %rdx, %r14
movl %esi, %r12d
movq %rdi, %rbx
testq %rdx, %rdx
je 0x140cc
movq %r14, %rdi
callq 0x2080
incq %rax
movq %rax, -0x38(%rbp)
jmp 0x140d4
movq $0x0, -0x38(%rbp)
leaq -0x160(%rbp), %r13
leaq -0x30(%rbp), %rdi
movq %r13, (%rdi)
leaq 0x3ade(%rip), %rax      # 0x17bc7
leaq 0x2f3a(%rip), %rsi      # 0x1702a
testb %r12b, %r12b
cmovneq %rax, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x128d0
movq %r13, %rdi
callq 0x22b0
movq %rax, %r12
testq %rax, %rax
je 0x14206
movq %r12, %rdi
callq 0x20d0
testq %rax, %rax
je 0x141fe
movq %rax, %r13
movq -0x38(%rbp), %rax
decq %rax
movq %rax, -0x50(%rbp)
addq $0x13, %r13
movq %r13, %rdi
testq %r14, %r14
je 0x141b7
callq 0x2080
movq %rax, %rbx
subq -0x38(%rbp), %rbx
jbe 0x141ea
cmpb $0x2e, (%r13,%rbx)
jne 0x141ea
leaq (%rbx,%r13), %rdi
incq %rdi
movq %r14, %rsi
movq -0x50(%rbp), %rdx
callq 0x20a0
testl %eax, %eax
jne 0x141ea
incq %rbx
movq %rbx, %rdi
callq 0x152b1
movq %rax, -0x48(%rbp)
movq %r13, %rdi
callq 0x2080
movq %rax, %r15
incq %r15
cmpq %rbx, %r15
cmovaeq %rbx, %r15
movq -0x48(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x2130
movb $0x0, -0x1(%rbx,%r15)
movq %rbx, -0x30(%rbp)
jmp 0x141dd
callq 0x2080
leaq 0x1(%rax), %rbx
movq %rbx, %rdi
callq 0x152b1
movq %rax, %r15
movq %rax, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x2130
movq %r15, -0x30(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x12838
movq %r12, %rdi
callq 0x20d0
movq %rax, %r13
testq %rax, %rax
jne 0x14134
movq %r12, %rdi
callq 0x2330
testq %r12, %r12
setne %al
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq