// File: /workspace/github_cpp_makefile_star2_O3/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 0x1452f
movq %r14, %rdi
callq 0x2080
incq %rax
movq %rax, -0x38(%rbp)
jmp 0x14537
movq $0x0, -0x38(%rbp)
leaq -0x160(%rbp), %r13
leaq -0x30(%rbp), %rdi
movq %r13, (%rdi)
leaq 0x47db(%rip), %rax      # 0x18d27
leaq 0x3c37(%rip), %rsi      # 0x1818a
testb %r12b, %r12b
cmovneq %rax, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x12e1e
movq %r13, %rdi
callq 0x22b0
movq %rax, %r12
testq %rax, %rax
je 0x14669
movq %r12, %rdi
callq 0x20d0
testq %rax, %rax
je 0x14661
movq %rax, %r13
movq -0x38(%rbp), %rax
decq %rax
movq %rax, -0x50(%rbp)
addq $0x13, %r13
movq %r13, %rdi
testq %r14, %r14
je 0x1461a
callq 0x2080
movq %rax, %rbx
subq -0x38(%rbp), %rbx
jbe 0x1464d
cmpb $0x2e, (%r13,%rbx)
jne 0x1464d
leaq (%rbx,%r13), %rdi
incq %rdi
movq %r14, %rsi
movq -0x50(%rbp), %rdx
callq 0x20a0
testl %eax, %eax
jne 0x1464d
incq %rbx
movq %rbx, %rdi
callq 0x15705
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 0x14640
callq 0x2080
leaq 0x1(%rax), %rbx
movq %rbx, %rdi
callq 0x15705
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 0x12d82
movq %r12, %rdi
callq 0x20d0
movq %rax, %r13
testq %rax, %rax
jne 0x14597
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