// File: /workspace/github_cpp_makefile_star2_O2/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 0x134d7(%rip), %r12     # 0x256f0
movq %r12, %rdi
callq 0x1085a
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
js 0x12276
movl %ecx, %ecx
movq 0x28(%r12), %rdx
imulq $0xb0, %rcx, %rbp
movq 0x28(%rdx,%rbp), %rcx
testb $0x4, %cl
je 0x12276
testb $0x8, %cl
jne 0x12265
pushq $0x20
popq %rdi
callq 0x127df
testl %eax, %eax
je 0x12288
leaq 0x8923(%rip), %rdi      # 0x1ab7c
movq %rbx, %rsi
xorl %eax, %eax
callq 0xf258
jmp 0x12273
leaq 0x88ca(%rip), %rdi      # 0x1ab36
xorl %eax, %eax
callq 0xf258
pushq $-0x1
popq %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%r12), %rdi
testq %r15, %r15
je 0x1235f
leaq (%rdi,%rbp), %rax
movq 0x28(%rdi,%rbp), %rcx
andq $-0x5, %rcx
movq %rcx, 0x8(%r15)
movzwl 0x20(%rdi,%rbp), %edx
movw %dx, (%r15)
movzwl 0x40(%rdi,%rbp), %ecx
movw %cx, 0x18(%r15)
movq 0x38(%rdi,%rbp), %rcx
cmpw $0x4, %dx
jne 0x12353
testq %rcx, %rcx
jne 0x122eb
movq 0x58(%rax), %rcx
movabsq $0xfffffffafffffff, %rdx # imm = 0xFFFFFFFAFFFFFFF
andq (%rcx), %rdx
imulq $0xb0, %rdx, %rcx
movq 0x38(%rdi,%rcx), %rcx
movq %rcx, 0x10(%r15)
movq 0x48(%rax), %rax
movq %rax, 0x20(%r15)
xorl %r13d, %r13d
addq %rbp, %rdi
callq 0xfe4e
cltq
movq 0x28(%r12), %rdi
cmpq %rax, %r13
jg 0x1235f
addq %rbp, %rdi
addq $0x88, %rdi
movq -0x30(%rdi), %rax
movq (%rax,%r13,8), %rax
movq %rax, 0x28(%r15,%r13,8)
movq -0x18(%rdi), %rax
movl (%rax,%r13,4), %eax
movl %eax, 0xa8(%r15,%r13,4)
movq %r13, %rsi
callq 0xe96e
testq %rdx, (%rax)
setne 0xe8(%r15,%r13)
incq %r13
movq 0x28(%r12), %rdi
jmp 0x122fa
movq %rcx, 0x10(%r15)
movq 0x48(%rax), %rax
movq %rax, 0x20(%r15)
andw $0x0, 0x20(%rdi,%rbp)
andq $0x0, 0x28(%rdi,%rbp)
leaq 0x882c(%rip), %rsi      # 0x1ab9e
xorl %ebp, %ebp
movq %rsp, %r15
movq %r15, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x30c0
movq %r15, %rdi
callq 0x3190
movslq %eax, %r12
movslq 0x58(%r14), %rax
cmpq %rax, %rbp
jge 0x123cb
movq 0x50(%r14), %rax
movq (%rax,%rbp,8), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3450
testl %eax, %eax
je 0x123c1
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x31d0
testl %eax, %eax
jne 0x123c6
movb $0x0, (%r13)
incq %rbp
jmp 0x1238f
xorl %eax, %eax
jmp 0x12276