// File: /workspace/github_c_makefile_star2_O1/jonof[P]jftekwar/src/datascan.c
// Function: ImportDataFromFile
static int ImportDataFromFile(const char *path, int size, struct importdatameta *cbs)
{
    char *fn;
    int fh, rv;

    fn = strrchr(path, '/');
#ifdef _WIN32
    fn = max(fn, strrchr(path, '\\'));
#endif
    if (!fn) fn = strdup(path);
    else fn = strdup(fn+1);
    strlwr(fn);

    fh = open(path, O_RDONLY|O_BINARY, S_IREAD);
    if (fh < 0) return IMPORTDATA_OK;  // Maybe no permission. Whatever.

    switch (CopyFile(fh, size, fn, cbs)) {
        case COPYFILE_ERR_CANCELLED:
            rv = IMPORTDATA_OK;
            break;
        case COPYFILE_ERR_EXISTS:
            rv = IMPORTDATA_SKIPPED;
            break;
        case COPYFILE_OK: // Copied.
            rv = IMPORTDATA_COPIED;
            break;
        default:
            rv = IMPORTDATA_ERROR;
            break;
    }
    close(fh);
    free(fn);
    return rv;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4018, %rsp           # imm = 0x4018
movq %rdx, %r15
movl %esi, %r13d
movq %rdi, %r14
movl $0x2f, %esi
callq 0x8dd0
testq %rax, %rax
je 0x2dc35
incq %rax
movq %rax, %rdi
jmp 0x2dc38
movq %r14, %rdi
callq 0x8070
movq %rax, %rbx
movq %rax, %rdi
callq 0x34880
xorl %r12d, %r12d
movq %r14, %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
xorl %eax, %eax
callq 0x8670
testl %eax, %eax
js 0x2dd93
movl %eax, %ebp
movq %rbx, %rdi
movl $0xc1, %esi
movl $0x180, %edx            # imm = 0x180
xorl %eax, %eax
callq 0x8670
testl %eax, %eax
js 0x2dd4c
movl %eax, %r12d
movl %r13d, 0x4(%rsp)
movq %rbx, 0x8(%rsp)
xorl %r14d, %r14d
movl %ebp, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x83b0
leaq 0x10(%rsp), %r13
movq (%r15), %rdi
callq *0x10(%r15)
testl %eax, %eax
je 0x2dcc9
movl $0xfffffffc, %ebx       # imm = 0xFFFFFFFC
xorl %ecx, %ecx
testb %cl, %cl
je 0x2dd10
cmpq $0x4000, %r14           # imm = 0x4000
movl $0x4000, %r14d          # imm = 0x4000
je 0x2dca2
jmp 0x2dd10
movl $0x4000, %edx           # imm = 0x4000
movl %ebp, %edi
movq %r13, %rsi
callq 0x8b20
movq %rax, %r14
xorl %ebx, %ebx
testq %rax, %rax
js 0x2dd02
je 0x2dd09
movl %r12d, %edi
movq %r13, %rsi
movq %r14, %rdx
callq 0x8f10
xorl %ecx, %ecx
cmpq %r14, %rax
sete %cl
leal (%rcx,%rcx,2), %ebx
addl $-0x3, %ebx
jmp 0x2dcb4
movl $0xfffffffd, %ebx       # imm = 0xFFFFFFFD
jmp 0x2dcb2
movb $0x1, %cl
xorl %r14d, %r14d
jmp 0x2dcb4
movl %r12d, %edi
callq 0x8310
movslq 0x4(%rsp), %r14
movl %ebp, %edi
xorl %esi, %esi
movl $0x1, %edx
callq 0x83b0
cmpq %r14, %rax
movl $0xfffffffd, %r14d      # imm = 0xFFFFFFFD
cmovel %ebx, %r14d
testl %r14d, %r14d
je 0x2dd61
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x82a0
jmp 0x2dd66
callq 0x8ea0
xorl %r14d, %r14d
cmpl $0x11, (%rax)
sete %r14b
orl $-0x2, %r14d
jmp 0x2dd66
movq 0x8(%rsp), %rbx
addl $0x4, %r14d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $0x4, %r14d
ja 0x2dd84
movl %r14d, %eax
leaq 0x5fecc(%rip), %rcx     # 0x8dc4c
movl (%rcx,%rax,4), %r12d
movl %ebp, %edi
callq 0x8310
movq %rbx, %rdi
callq 0x8270
movl %r12d, %eax
addq $0x4018, %rsp           # imm = 0x4018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq