// File: /workspace/github_cpp_makefile_star2_O3/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 $0xd8, %rsp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x11de5(%rip), %r12     # 0x256e0
movq %r12, %rdi
callq 0x11e22
xorl %ebp, %ebp
testl %eax, %eax
js 0x13958
movl %eax, %eax
movq 0x28(%r12), %rcx
imulq $0xb0, %rax, %r13
movq 0x28(%rcx,%r13), %rax
testb $0x4, %al
je 0x13958
testb $0x8, %al
jne 0x13945
movl $0x20, %edi
callq 0x13f2c
testl %eax, %eax
je 0x1396c
leaq 0x9232(%rip), %rdi      # 0x1cb6b
movq %rbx, %rsi
xorl %eax, %eax
callq 0x102f4
jmp 0x13953
leaq 0x91d9(%rip), %rdi      # 0x1cb25
xorl %eax, %eax
callq 0x102f4
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, 0x8(%rsp)
testq %r15, %r15
je 0x13a59
movq 0x28(%r12), %rax
leaq (%rax,%r13), %rdi
movq 0x28(%rax,%r13), %rcx
andq $-0x5, %rcx
movq %rcx, 0x8(%r15)
movzwl 0x20(%rax,%r13), %edx
movw %dx, (%r15)
movzwl 0x40(%rax,%r13), %ecx
movw %cx, 0x18(%r15)
movq 0x38(%rax,%r13), %rcx
cmpw $0x4, %dx
jne 0x13a4d
testq %rcx, %rcx
jne 0x139d6
movq 0x58(%rdi), %rcx
movabsq $0xfffffffafffffff, %rdx # imm = 0xFFFFFFFAFFFFFFF
andq (%rcx), %rdx
imulq $0xb0, %rdx, %rcx
movq 0x38(%rax,%rcx), %rcx
movq %rcx, 0x10(%r15)
movq 0x48(%rdi), %rax
movq %rax, 0x20(%r15)
callq 0x11052
testl %eax, %eax
js 0x13a59
xorl %ebp, %ebp
movq 0x28(%r12), %rax
leaq (%rax,%r13), %rdi
movq 0x58(%rax,%r13), %rcx
movq (%rcx,%rbp,8), %rcx
movq %rcx, 0x28(%r15,%rbp,8)
movq 0x70(%rax,%r13), %rcx
movl (%rcx,%rbp,4), %ecx
movl %ecx, 0xa8(%r15,%rbp,4)
movq 0x88(%rax,%r13), %rax
movl %ebp, %ecx
shrl $0x6, %ecx
movq (%rax,%rcx,8), %rax
btq %rbp, %rax
setb 0xe8(%r15,%rbp)
movq %r12, %rbx
leaq 0x1(%rbp), %r12
callq 0x11052
cltq
cmpq %rax, %rbp
movq %r12, %rbp
movq %rbx, %r12
jl 0x139ed
jmp 0x13a59
movq %rcx, 0x10(%r15)
movq 0x48(%rdi), %rax
movq %rax, 0x20(%r15)
movq 0x28(%r12), %rax
movw $0x0, 0x20(%rax,%r13)
movq $0x0, 0x28(%rax,%r13)
leaq 0x9117(%rip), %rsi      # 0x1cb8d
xorl %ebp, %ebp
leaq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rdx
xorl %eax, %eax
callq 0x30d0
cmpl $0x0, 0x58(%r14)
jle 0x13958
leaq 0x10(%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 0x13ad2
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
movq %r12, %rdx
callq 0x31d0
testl %eax, %eax
jne 0x13ad7
movb $0x0, (%r13)
incq %r15
movslq 0x58(%r14), %rax
cmpq %rax, %r15
jl 0x13aa7
jmp 0x13958