// File: akojo[P]quickfind/qfind.cpp
// Function: main
int main(int argc, char *argv[])
{
    auto flags = 0;
    int opt{};

    while ((opt = getopt(argc, argv, "adfh")) != -1) {
        switch (opt) {
        case 'a':
            flags |= DW_HIDDEN;
            break;
        case 'd':
            flags |= DW_DIRECTORIES;
            break;
        case 'f':
            flags |= DW_FILES;
            break;
        case 'h':
        case '?':
        default:
            usage();
        }
    }
    argc -= optind;
    argv += optind;

    if ((flags & (DW_DIRECTORIES | DW_FILES)) == 0) {
        flags |= DW_DIRECTORIES | DW_FILES;
    }

    vector<string> dirs = { "." };
    if (argc > 1) {
        dirs.clear();
        for (int i = 1; i < argc; ++i) {
            auto len = strlen(argv[i]);
            if (argv[i][len - 1] == '/')
                argv[i][len - 1] = '\0';
            dirs.emplace_back(argv[i]);
        }
    }

    string pattern = argc == 0 ? "" : *argv;
    vector<wstr> strings;
    for (auto& dir : dirs)
        dirwalk(dir, flags, [&](auto name) { strings.emplace_back(name); });
    auto last = match(strings.begin(), strings.end(), pattern);
    for_each(strings.begin(), last, [](auto& s) { puts(s.str.c_str()); });

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x5c0a(%rip), %rdx      # 0x81ef
callq 0x2050
movl %eax, -0x18(%rbp)
cmpl $-0x1, %eax
je 0x2647
movl -0x18(%rbp), %eax
addl $-0x3f, %eax
movl %eax, %ecx
movq %rcx, -0x170(%rbp)
subl $0x29, %eax
ja 0x2640
movq -0x170(%rbp), %rax
leaq 0x59f0(%rip), %rcx      # 0x8004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl -0x14(%rbp), %eax
orl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2645
movl -0x14(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x14(%rbp)
jmp 0x2645
movl -0x14(%rbp), %eax
orl $0x4, %eax
movl %eax, -0x14(%rbp)
jmp 0x2645
jmp 0x2640
callq 0x2470
jmp 0x25d7
movq 0x9982(%rip), %rax      # 0xbfd0
movl (%rax), %ecx
movl -0x8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x8(%rbp)
movq 0x9971(%rip), %rax      # 0xbfd0
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movl -0x14(%rbp), %eax
andl $0x6, %eax
cmpl $0x0, %eax
jne 0x2687
movl -0x14(%rbp), %eax
orl $0x6, %eax
movl %eax, -0x14(%rbp)
movb $0x1, -0x7d(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x180(%rbp)
movq %rax, -0x68(%rbp)
leaq -0x69(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x2300
movq -0x180(%rbp), %rdi
movq -0x178(%rbp), %rdx
leaq 0x5b35(%rip), %rsi      # 0x81f4
callq 0x3020
jmp 0x26c6
movb $0x0, -0x7d(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x1, -0x38(%rbp)
leaq -0x7e(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x30d0
movq -0x188(%rbp), %rcx
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x30f0
jmp 0x2704
leaq -0x7e(%rbp), %rdi
callq 0x3170
leaq -0x60(%rbp), %rax
movq %rax, -0x198(%rbp)
addq $0x20, %rax
movq %rax, -0x190(%rbp)
movq -0x190(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x2120
movq -0x198(%rbp), %rcx
movq -0x1a0(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x190(%rbp)
jne 0x2723
leaq -0x69(%rbp), %rdi
callq 0x2200
cmpl $0x1, -0x8(%rbp)
jle 0x28f7
leaq -0x30(%rbp), %rdi
callq 0x3190
movl $0x1, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x28f5
movq -0x10(%rbp), %rax
movslq -0x84(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x20d0
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rax
movslq -0x84(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x90(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
jne 0x28b4
movq -0x10(%rbp), %rax
movslq -0x84(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x90(%rbp), %rcx
subq $0x1, %rcx
movb $0x0, (%rax,%rcx)
jmp 0x28b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x285a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x7e(%rbp), %rdi
callq 0x3170
leaq -0x60(%rbp), %rax
movq %rax, -0x1b0(%rbp)
addq $0x20, %rax
movq %rax, -0x1a8(%rbp)
movq -0x1a8(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x2120
movq -0x1b0(%rbp), %rcx
movq -0x1b8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x1a8(%rbp)
jne 0x2827
jmp 0x285a
leaq -0x69(%rbp), %rdi
callq 0x2200
testb $0x1, -0x7d(%rbp)
jne 0x286b
jmp 0x28af
movq -0x68(%rbp), %rax
leaq -0x60(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x1c0(%rbp)
je 0x28ad
movq -0x1c0(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x2120
movq -0x1c8(%rbp), %rax
leaq -0x60(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x1c0(%rbp)
jne 0x287f
jmp 0x28af
jmp 0x2b9a
movq -0x10(%rbp), %rax
movslq -0x84(%rbp), %rcx
leaq (%rax,%rcx,8), %rsi
leaq -0x30(%rbp), %rdi
callq 0x31b0
jmp 0x28ce
jmp 0x28d0
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x277a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x2b91
jmp 0x28f7
cmpl $0x0, -0x8(%rbp)
jne 0x290d
leaq 0x594c(%rip), %rax      # 0x8250
movq %rax, -0x1d0(%rbp)
jmp 0x291b
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1d0(%rbp)
movq -0x1d0(%rbp), %rax
movq %rax, -0x1e0(%rbp)
leaq -0xb1(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x2300
movq -0x1e0(%rbp), %rsi
movq -0x1d8(%rbp), %rdx
leaq -0xb0(%rbp), %rdi
callq 0x3020
jmp 0x2958
leaq -0xb1(%rbp), %rdi
callq 0x2200
leaq -0xd0(%rbp), %rdi
callq 0x3230
leaq -0x30(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rdi
callq 0x3250
movq %rax, -0xe0(%rbp)
movq -0xd8(%rbp), %rdi
callq 0x3280
movq %rax, -0xe8(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x32b0
testb $0x1, %al
jne 0x29bd
jmp 0x2ab1
leaq -0xe0(%rbp), %rdi
callq 0x32f0
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0x20c0
jmp 0x29e5
movl -0x14(%rbp), %eax
movl %eax, -0x1ec(%rbp)
leaq -0xd0(%rbp), %rax
movq %rax, -0x138(%rbp)
leaq -0x130(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
leaq -0x138(%rbp), %rsi
callq 0x2bb0
movl -0x1ec(%rbp), %esi
movq -0x1e8(%rbp), %rdx
leaq -0x110(%rbp), %rdi
callq 0x5500
jmp 0x2a31
leaq -0x130(%rbp), %rdi
callq 0x3310
leaq -0x110(%rbp), %rdi
callq 0x2120
leaq -0xe0(%rbp), %rdi
callq 0x3330
jmp 0x29a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xb1(%rbp), %rdi
callq 0x2200
jmp 0x2b91
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x2b79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x3310
leaq -0x110(%rbp), %rdi
callq 0x2120
jmp 0x2b79
leaq -0xd0(%rbp), %rdi
movq %rdi, -0x200(%rbp)
callq 0x3350
movq -0x200(%rbp), %rdi
movq %rax, -0x148(%rbp)
callq 0x3380
movq %rax, -0x150(%rbp)
movq -0x148(%rbp), %rdi
movq -0x150(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x5970
movq %rax, -0x1f8(%rbp)
jmp 0x2b01
movq -0x1f8(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x3350
movq %rax, -0x158(%rbp)
movq -0x140(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x158(%rbp), %rdi
movq -0x160(%rbp), %rsi
callq 0x2c40
jmp 0x2b45
movl $0x0, -0x4(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x33b0
leaq -0xb0(%rbp), %rdi
callq 0x2120
leaq -0x30(%rbp), %rdi
callq 0x3410
movl -0x4(%rbp), %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
leaq -0xd0(%rbp), %rdi
callq 0x33b0
leaq -0xb0(%rbp), %rdi
callq 0x2120
leaq -0x30(%rbp), %rdi
callq 0x3410
movq -0x78(%rbp), %rdi
callq 0x22f0
nopw %cs:(%rax,%rax)