// File: /workspace/github_c_makefile_star2_O0/jonof[P]jftekwar/src/datascan.c
// Function: ImportFilesFromDir
static int ImportFilesFromDir(const char *path, struct importdatameta *cbs)
{
    BDIR *dir;
    struct Bdirent *dirent;
    int found = 0, errors = 0;
    size_t subpathlen;
    char *subpath;
    static const char *pats[] = {
        "tiles???.art",
        "beach?.map",
        "city?.map",
        "final?.map",
        "free?.map",
        "inds?.map",
        "level?.map",
        "load.map",
        "matrix.map",
        "mid?.map",
        "net?.map",
        "park?.map",
        "sewer?.map",
        "subway?.map",
        "ware*.map",
        "lookup.dat",
        "nlookup.dat",
        "songs",
        "sounds",
        "*.smk",
        NULL
    };

    cbs->progress(cbs->data, path);

    dir = Bopendir(path);
    if (!dir) return IMPORTDATA_OK;    // Maybe no permission.

    while ((dirent = Breaddir(dir))) {
        if (cbs->cancelled(cbs->data)) break;

        if (dirent->name[0] == '.' &&
            (dirent->name[1] == 0 || (dirent->name[1] == '.' && dirent->name[2] == 0)))
                continue;
        if (!(dirent->mode & (BS_IFDIR|BS_IFREG))) continue; // Ignore non-directories and non-regular files.
        if (dirent->mode & BS_IFREG) {
            int i;
            for (i=0; pats[i]; i++) {
                if (Bwildmatch(dirent->name, pats[i])) break;
            }
            if (!pats[i]) continue;    // No match to any pattern.
        }

        subpathlen = strlen(path) + 1 + dirent->namlen + 1;
        subpath = malloc(subpathlen);
        if (!subpath) { Bclosedir(dir); break; }
        snprintf(subpath, subpathlen, "%s/%s", path, dirent->name);

        if (dirent->mode & BS_IFDIR) {
            switch (ImportFilesFromDir(subpath, cbs)) {
                case IMPORTDATA_COPIED: found = 1; break;
                case IMPORTDATA_ERROR: errors = 1; break;
            }
        }
        else {
            switch (ImportDataFromFile(subpath, (int)dirent->size, cbs)) {
                case IMPORTDATA_SKIPPED: buildprintf("Skipped %s\n", subpath); break;
                case IMPORTDATA_COPIED: buildprintf("Imported %s\n", subpath); found = 1; break;
                case IMPORTDATA_ERROR: buildprintf("Error importing %s\n", subpath); errors = 1; break;
            }
        }
        free(subpath);
    }
    Bclosedir(dir);
    if (found) return IMPORTDATA_COPIED;   // Finding anything is considered fine.
    else if (errors) return IMPORTDATA_ERROR; // Finding nothing but errors reports back errors.
    return IMPORTDATA_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rdi
movq -0x10(%rbp), %rsi
callq *%rax
movq -0x10(%rbp), %rdi
callq 0x504d0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x44463
movl $0x0, -0x4(%rbp)
jmp 0x446c7
jmp 0x44465
movq -0x20(%rbp), %rdi
callq 0x50560
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x44697
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movq (%rcx), %rdi
callq *%rax
cmpl $0x0, %eax
je 0x44497
jmp 0x44697
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %eax
cmpl $0x2e, %eax
jne 0x444dc
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
je 0x444da
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2e, %eax
jne 0x444dc
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movsbl 0x2(%rax), %eax
cmpl $0x0, %eax
jne 0x444dc
jmp 0x44465
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xc000, %eax           # imm = 0xC000
cmpl $0x0, %eax
jne 0x444f2
jmp 0x44465
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x44565
movl $0x0, -0x44(%rbp)
movslq -0x44(%rbp), %rcx
leaq 0xd6a1b(%rip), %rax     # 0x11af30
cmpq $0x0, (%rax,%rcx,8)
je 0x4454c
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movslq -0x44(%rbp), %rcx
leaq 0xd6a01(%rip), %rax     # 0x11af30
movq (%rax,%rcx,8), %rsi
callq 0x506b0
cmpl $0x0, %eax
je 0x4453f
jmp 0x4454c
jmp 0x44541
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x4450a
movslq -0x44(%rbp), %rcx
leaq 0xd69d9(%rip), %rax     # 0x11af30
cmpq $0x0, (%rax,%rcx,8)
jne 0x44563
jmp 0x44465
jmp 0x44565
movq -0x10(%rbp), %rdi
callq 0x8540
addq $0x1, %rax
movq -0x28(%rbp), %rcx
addq (%rcx), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x8ca0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x445a3
movq -0x20(%rbp), %rdi
callq 0x50670
jmp 0x44697
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x10(%rbp), %rcx
movq -0x28(%rbp), %rax
movq 0x8(%rax), %r8
leaq 0x94948(%rip), %rdx     # 0xd8f06
movb $0x0, %al
callq 0x86a0
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x4000, %eax           # imm = 0x4000
cmpl $0x0, %eax
je 0x4460b
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x44410
movl %eax, %ecx
movl %ecx, -0x48(%rbp)
subl $-0x1, %eax
je 0x44602
jmp 0x445ef
movl -0x48(%rbp), %eax
subl $0x2, %eax
jne 0x44609
jmp 0x445f9
movl $0x1, -0x2c(%rbp)
jmp 0x44609
movl $0x1, -0x30(%rbp)
jmp 0x44689
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x18(%rax), %esi
movq -0x18(%rbp), %rdx
callq 0x44810
movl %eax, %ecx
movl %ecx, -0x4c(%rbp)
subl $-0x1, %eax
je 0x4466e
jmp 0x4462b
movl -0x4c(%rbp), %eax
subl $0x1, %eax
je 0x4463f
jmp 0x44635
movl -0x4c(%rbp), %eax
subl $0x2, %eax
je 0x44653
jmp 0x44687
movq -0x40(%rbp), %rsi
leaq 0x96634(%rip), %rdi     # 0xdac7e
movb $0x0, %al
callq 0x52630
jmp 0x44687
movq -0x40(%rbp), %rsi
leaq 0x9662c(%rip), %rdi     # 0xdac8a
movb $0x0, %al
callq 0x52630
movl $0x1, -0x2c(%rbp)
jmp 0x44687
movq -0x40(%rbp), %rsi
leaq 0x9661e(%rip), %rdi     # 0xdac97
movb $0x0, %al
callq 0x52630
movl $0x1, -0x30(%rbp)
jmp 0x44689
movq -0x40(%rbp), %rdi
callq 0x8260
jmp 0x44465
movq -0x20(%rbp), %rdi
callq 0x50670
cmpl $0x0, -0x2c(%rbp)
je 0x446af
movl $0x2, -0x4(%rbp)
jmp 0x446c7
cmpl $0x0, -0x30(%rbp)
je 0x446be
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x446c7
jmp 0x446c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq