// File: /workspace/github_cpp_makefile_star2_O1/rofl0r[P]ascc/cc_compiledscript.cpp
// Function: ccCompiledScript::remove_any_import(char const*, SymbolDef*)
int ccCompiledScript::remove_any_import (const char*namm, SymbolDef *oldSym) {
    // Remove any import with the specified name
    int i, sidx;
    sidx = sym.find(namm);
    if (sidx < 0)
        return 0;
    if ((sym.entries[sidx].flags & SFLG_IMPORTED) == 0)
        return 0;
    // if this import has been referenced, flag an error
    if (sym.entries[sidx].flags & SFLG_ACCESSED) {
        cc_error("Already referenced name as import; you must define it before using it");
        return -1;
    }
    // if they set the No Override Imports flag, don't allow it
    if (ccGetOption(SCOPT_NOIMPORTOVERRIDE)) {
        cc_error("Variable '%s' is already imported", namm);
        return -1;
    }

    if (oldSym) {
        // Copy the import declaration to a backup struct
        // This allows a type comparison to be done
        // strip the imported flag, since it the real def won't be
        oldSym->flags = sym.entries[sidx].flags & ~SFLG_IMPORTED;
        oldSym->stype = sym.entries[sidx].stype;
        oldSym->sscope = sym.entries[sidx].sscope;
        // Return size may have been unknown at the time of forward declaration. Check the actual return type for those cases.
        if(sym.entries[sidx].stype == SYM_FUNCTION && sym.entries[sidx].ssize == 0) {
            oldSym->ssize = sym.entries[sym.entries[sidx].funcparamtypes[0] & ~(STYPE_POINTER | STYPE_DYNARRAY)].ssize;
        } else {
            oldSym->ssize = sym.entries[sidx].ssize;
        }
        oldSym->arrsize = sym.entries[sidx].arrsize;
        if (sym.entries[sidx].stype == SYM_FUNCTION) {
            // <= because of return type
            for (i = 0; i <= sym.entries[sidx].get_num_args(); i++) {
                oldSym->funcparamtypes[i] = sym.entries[sidx].funcparamtypes[i];
                oldSym->funcParamDefaultValues[i] = sym.entries[sidx].funcParamDefaultValues[i];
                oldSym->funcParamHasDefaultValues[i] = sym.entries[sidx].funcParamHasDefaultValues[i];
            }
        }
    }

    // remove its type so that it can be declared
    sym.entries[sidx].stype = 0;
    sym.entries[sidx].flags = 0;

    // check also for a number-of-parameters appended version
    char appended[200];
    sprintf(appended, "%s^", namm);
    int applen = strlen(appended);

    for (i = 0; i < numimports; i++) {
        if (strcmp(imports[i], namm) == 0) {
            // Just null the name of the import
            // DO NOT remove the import from the list, as some other
            // import indexes might already be referenced by the code
            // compiled so far.
            imports[i][0] = 0;
        }
        else if (strncmp(imports[i], appended, applen) == 0) {
            imports[i][0] = 0;
        }

    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x11c6b(%rip), %r12     # 0x256e0
movq %r12, %rdi
callq 0x11f96
xorl %ebp, %ebp
testl %eax, %eax
js 0x13ad2
movl %eax, %eax
movq 0x28(%r12), %rcx
imulq $0xb0, %rax, %r13
movq 0x28(%rcx,%r13), %rax
testb $0x4, %al
je 0x13ad2
testb $0x8, %al
jne 0x13abf
movl $0x20, %edi
callq 0x140a4
testl %eax, %eax
je 0x13ae6
leaq 0x90b8(%rip), %rdi      # 0x1cb6b
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10418
jmp 0x13acd
leaq 0x905f(%rip), %rdi      # 0x1cb25
xorl %eax, %eax
callq 0x10418
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r15, %r15
je 0x13bbd
movq 0x28(%r12), %rdx
leaq (%rdx,%r13), %rax
movq 0x28(%rdx,%r13), %rcx
andq $-0x5, %rcx
movq %rcx, 0x8(%r15)
movzwl 0x20(%rdx,%r13), %ecx
movw %cx, (%r15)
movzwl 0x40(%rdx,%r13), %esi
movw %si, 0x18(%r15)
cmpw $0x4, %cx
jne 0x13b2b
cmpq $0x0, 0x38(%rax)
je 0x13c41
leaq 0x38(%rax), %rdx
movq (%rdx), %rdx
movq %rdx, 0x10(%r15)
movq 0x48(%rax), %rax
movq %rax, 0x20(%r15)
cmpw $0x4, %cx
jne 0x13bbd
movq 0x28(%r12), %rdi
addq %r13, %rdi
callq 0x1118a
testl %eax, %eax
js 0x13bbd
movq $-0x1, %rax
leaq 0x1(%rax), %rbp
movq 0x28(%r12), %rcx
movq 0x58(%rcx,%r13), %rdx
movq 0x8(%rdx,%rax,8), %rdx
movq %rdx, 0x30(%r15,%rax,8)
movq 0x70(%rcx,%r13), %rdx
movl 0x4(%rdx,%rax,4), %edx
movl %edx, 0xac(%r15,%rax,4)
movq 0x88(%rcx,%r13), %rcx
movq %rbp, %rdx
shrq $0x6, %rdx
movq (%rcx,%rdx,8), %rcx
btq %rbp, %rcx
setb 0xe9(%r15,%rax)
movq 0x28(%r12), %rdi
addq %r13, %rdi
callq 0x1118a
movslq %eax, %rcx
movq %rbp, %rax
cmpq %rcx, %rbp
jl 0x13b5c
movq 0x28(%r12), %rax
movw $0x0, 0x20(%rax,%r13)
movq $0x0, 0x28(%rax,%r13)
leaq 0x8fb3(%rip), %rsi      # 0x1cb8d
xorl %ebp, %ebp
movq %rsp, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x30d0
cmpl $0x0, 0x58(%r14)
jle 0x13ad2
movq %rsp, %rdi
callq 0x31a0
movslq %eax, %r12
xorl %r15d, %r15d
movq 0x50(%r14), %rax
movq (%rax,%r15,8), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3450
testl %eax, %eax
je 0x13c2b
movq %r13, %rdi
movq %rsp, %rsi
movq %r12, %rdx
callq 0x31d0
testl %eax, %eax
jne 0x13c30
movb $0x0, (%r13)
incq %r15
movslq 0x58(%r14), %rax
cmpq %rax, %r15
jl 0x13c02
jmp 0x13ad2
movq 0x58(%rax), %rsi
movabsq $0xfffffffafffffff, %rdi # imm = 0xFFFFFFFAFFFFFFF
andq (%rsi), %rdi
imulq $0xb0, %rdi, %rsi
addq %rsi, %rdx
addq $0x38, %rdx
jmp 0x13b2f
nop