// File: Fohlen[P]cubescript-standalone/stream.cpp
// Function: listfiles(char const*, char const*, vector<char*>&)
int listfiles(const char *dir, const char *ext, vector<char *> &files)
{
    string dirname;
    copystring(dirname, dir);
    path(dirname);
    size_t dirlen = strlen(dirname);
    while(dirlen > 1 && dirname[dirlen-1] == PATHDIV) dirname[--dirlen] = '\0';
    int dirs = 0;
    if(listdir(dirname, true, ext, files)) dirs++;
    string s;
    if(homedir[0])
    {
        formatstring(s)("%s%s", homedir, dirname);
        if(listdir(s, false, ext, files)) dirs++;
    }
    loopv(packagedirs)
    {
        packagedir &pf = packagedirs[i];
        if(pf.filter && strncmp(dirname, pf.filter, dirlen == pf.filterlen-1 ? dirlen : pf.filterlen))
            continue;
        formatstring(s)("%s%s", pf.dir, dirname);
        if(listdir(s, false, ext, files)) dirs++;
    }

    return dirs;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x270, %rsp            # imm = 0x270
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x120(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl $0x104, %edx            # imm = 0x104
callq 0x15f30
leaq -0x120(%rbp), %rdi
callq 0x183c0
leaq -0x120(%rbp), %rdi
callq 0x20b0
movq %rax, -0x128(%rbp)
xorl %eax, %eax
cmpq $0x1, -0x128(%rbp)
movb %al, -0x251(%rbp)
jbe 0x1916c
movq -0x128(%rbp), %rax
subq $0x1, %rax
movsbl -0x120(%rbp,%rax), %eax
cmpl $0x2f, %eax
sete %al
movb %al, -0x251(%rbp)
movb -0x251(%rbp), %al
testb $0x1, %al
jne 0x19178
jmp 0x19197
movq -0x128(%rbp), %rax
movq %rax, %rcx
addq $-0x1, %rcx
movq %rcx, -0x128(%rbp)
movb $0x0, -0x121(%rbp,%rax)
jmp 0x1913b
movl $0x0, -0x12c(%rbp)
leaq -0x120(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movl $0x1, %esi
callq 0x18ef0
testb $0x1, %al
jne 0x191c0
jmp 0x191cf
movl -0x12c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x12c(%rbp)
cmpb $0x0, 0xefaa(%rip)      # 0x28180
je 0x1923b
leaq -0x230(%rbp), %rsi
leaq -0x238(%rbp), %rdi
callq 0x167a0
leaq -0x120(%rbp), %rcx
leaq -0x238(%rbp), %rdi
leaq 0x5c32(%rip), %rsi      # 0x1ee32
leaq 0xef79(%rip), %rdx      # 0x28180
movb $0x0, %al
callq 0x167c0
leaq -0x230(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
xorl %esi, %esi
callq 0x18ef0
testb $0x1, %al
jne 0x1922a
jmp 0x19239
movl -0x12c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x12c(%rbp)
jmp 0x1923b
movl $0x0, -0x23c(%rbp)
movl -0x23c(%rbp), %eax
movl %eax, -0x258(%rbp)
leaq 0xf030(%rip), %rdi      # 0x28288
callq 0x19da0
movl %eax, %ecx
movl -0x258(%rbp), %eax
cmpl %ecx, %eax
jge 0x1938c
movl -0x23c(%rbp), %esi
leaq 0xf00e(%rip), %rdi      # 0x28288
callq 0x19dc0
movq %rax, -0x248(%rbp)
movq -0x248(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x19312
leaq -0x120(%rbp), %rax
movq %rax, -0x268(%rbp)
movq -0x248(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x260(%rbp)
movq -0x128(%rbp), %rax
movq -0x248(%rbp), %rcx
movq 0x18(%rcx), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x192df
movq -0x128(%rbp), %rax
movq %rax, -0x270(%rbp)
jmp 0x192f1
movq -0x248(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x270(%rbp)
movq -0x260(%rbp), %rsi
movq -0x268(%rbp), %rdi
movq -0x270(%rbp), %rdx
callq 0x20d0
cmpl $0x0, %eax
je 0x19312
jmp 0x19378
leaq -0x230(%rbp), %rsi
leaq -0x250(%rbp), %rdi
callq 0x167a0
movq -0x248(%rbp), %rax
movq (%rax), %rdx
leaq -0x120(%rbp), %rcx
leaq -0x250(%rbp), %rdi
leaq 0x5aee(%rip), %rsi      # 0x1ee32
movb $0x0, %al
callq 0x167c0
leaq -0x230(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
xorl %esi, %esi
callq 0x18ef0
testb $0x1, %al
jne 0x19367
jmp 0x19376
movl -0x12c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x12c(%rbp)
jmp 0x19378
movl -0x23c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x23c(%rbp)
jmp 0x19245
movl -0x12c(%rbp), %eax
addq $0x270, %rsp            # imm = 0x270
popq %rbp
retq
nopl (%rax,%rax)