// File: /workspace/github_cpp_makefile_star2_O1/rofl0r[P]ascc/cs_compiler.cpp
// Function: ccCompileText(char const*, char const*)
ccScript* ccCompileText(const char *texo, const char *scriptName) {
    int t;
    ccCompiledScript *cctemp = new ccCompiledScript();
    cctemp->init();

    sym.reset();
    preproc_startup(&predefinedMacros);

    if (scriptName == NULL)
        scriptName = "Main script";

    ccError = 0;
    ccErrorLine = 0;

    for (t=0;t<numheaders;t++) {
        if (defaultHeaderNames[t] != NULL)
            ccCurScriptName = defaultHeaderNames[t];
        else
            ccCurScriptName = "Internal header file";

        cctemp->start_new_section(ccCurScriptName);
        cc_compile(defaultheaders[t],cctemp);
        if (ccError) break;
    }

    if (!ccError) {
        ccCurScriptName = scriptName;
        cctemp->start_new_section(ccCurScriptName);
        cc_compile(texo,cctemp);
    }
    preproc_shutdown();

    if (ccError) {
        cctemp->shutdown();
        delete cctemp;
        return NULL;
    }

    for (t=0; (size_t)t<sym.entries.size();t++) {
        int stype = sym.get_type(t);
        // blank out the name for imports that are not used, to save space
        // in the output file
        if (((sym.entries[t].flags & SFLG_IMPORTED)!=0) && ((sym.entries[t].flags & SFLG_ACCESSED)==0)) {

            if ((stype == SYM_FUNCTION) || (stype == SYM_GLOBALVAR)) {
                // unused func/variable
                cctemp->imports[sym.entries[t].soffs][0] = 0;
            }
            else if (sym.entries[t].flags & SFLG_PROPERTY) {
                // unused property -- get rid of the getter and setter
                int propGet = sym.entries[t].get_propget();
                int propSet = sym.entries[t].get_propset();
                if (propGet >= 0)
                    cctemp->imports[propGet][0] = 0;
                if (propSet >= 0)
                    cctemp->imports[propSet][0] = 0;
            }
        }

        if ((sym.get_type(t) != SYM_GLOBALVAR) &&
            (sym.get_type(t) != SYM_LOCALVAR)) continue;

        if (sym.entries[t].flags & SFLG_IMPORTED) continue;
        if (ccGetOption(SCOPT_SHOWWARNINGS)==0) ;
        else if ((sym.entries[t].flags & SFLG_ACCESSED)==0) {
            printf("warning: variable '%s' is never used\n",sym.get_friendly_name(t).c_str());
        }
    }

    if (ccGetOption(SCOPT_EXPORTALL)) {
        // export all functions
        for (t=0;t<cctemp->numfunctions;t++) {
            if (cctemp->add_new_export(cctemp->functions[t],EXPORT_FUNCTION,
                cctemp->funccodeoffs[t], cctemp->funcnumparams[t]) == -1) {
                    cctemp->shutdown();
                    return NULL;
            }

        }
    }

    cctemp->free_extra();
    return cctemp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r13
movq %rdi, 0x10(%rsp)
movl $0x8d58, %edi           # imm = 0x8D58
callq 0x3310
movq %rax, %rbx
movq %rax, %rdi
callq 0x136e0
movq %rbx, %rdi
callq 0x1372e
leaq 0xeb36(%rip), %r14      # 0x256e0
movq %r14, %rdi
callq 0x11236
leaq 0xed37(%rip), %rdi      # 0x258f0
callq 0x17ad5
testq %r13, %r13
leaq 0x64f5(%rip), %rax      # 0x1d0bd
cmovneq %r13, %rax
movq %rax, 0x8(%rsp)
leaq 0xeae8(%rip), %r13      # 0x256c0
xorl %eax, %eax
movl %eax, (%r13)
leaq 0xeadf(%rip), %rcx      # 0x256c4
movl %eax, (%rcx)
cmpl %eax, 0x14acb(%rip)     # 0x2b6b8
jle 0x16c46
xorl %ebp, %ebp
leaq 0x64d1(%rip), %r15      # 0x1d0c9
leaq 0xe761(%rip), %r12      # 0x25360
movq 0xece2(%rip), %rax      # 0x258e8
movq (%rax,%rbp,8), %rsi
testq %rsi, %rsi
cmoveq %r15, %rsi
movq %rsi, (%r12)
movq %rbx, %rdi
callq 0x13de8
movq 0xecbc(%rip), %rax      # 0x258e0
movq (%rax,%rbp,8), %rdi
movq %rbx, %rsi
callq 0xf914
cmpl $0x0, (%r13)
jne 0x16c46
incq %rbp
movslq 0x14a77(%rip), %rax     # 0x2b6b8
cmpq %rax, %rbp
jl 0x16bff
cmpl $0x0, (%r13)
jne 0x16c71
leaq 0xe70c(%rip), %rax      # 0x25360
movq 0x8(%rsp), %rsi
movq %rsi, (%rax)
movq %rbx, %rdi
callq 0x13de8
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0xf914
callq 0x17afc
cmpl $0x0, (%r13)
je 0x16c95
movq %rbx, %rdi
callq 0x137be
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
xorl %ebx, %ebx
jmp 0x16e36
movq 0x30(%r14), %rax
cmpq 0x28(%r14), %rax
je 0x16ddc
movabsq $0x2e8ba2e8ba2e8ba3, %r15 # imm = 0x2E8BA2E8BA2E8BA3
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %r14, %rdi
movl %r13d, %esi
callq 0x111aa
movq 0x28(%r14), %rdi
movq 0x28(%rdi,%r12), %rcx
movl %ecx, %edx
andl $0xc, %edx
cmpl $0x4, %edx
jne 0x16cf2
cmpl $0x4, %eax
je 0x16cdf
cmpl $0x1, %eax
jne 0x16d9c
movslq 0x34(%rdi,%r12), %rax
shlq $0x3, %rax
addq 0x50(%rbx), %rax
movq (%rax), %rax
movb $0x0, (%rax)
movq %r14, %rdi
movl %r13d, %esi
callq 0x111aa
cmpl $0x1, %eax
je 0x16d12
movq %r14, %rdi
movl %r13d, %esi
callq 0x111aa
cmpl $0x2, %eax
jne 0x16d77
movq 0x28(%r14), %rax
testb $0x4, 0x28(%rax,%r12)
jne 0x16d77
movl $0x2, %edi
callq 0x140a4
testl %eax, %eax
je 0x16d77
movq 0x28(%r14), %rax
testb $0x8, 0x28(%rax,%r12)
jne 0x16d77
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
movl %r13d, %edx
callq 0x11fa0
movq 0x18(%rsp), %rsi
leaq 0x638a(%rip), %rdi      # 0x1d0de
xorl %eax, %eax
callq 0x3080
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x16d77
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x3320
incq %r13
movq 0x30(%r14), %rax
subq 0x28(%r14), %rax
sarq $0x4, %rax
imulq %r15, %rax
addq $0xb0, %r12
cmpq %r13, %rax
ja 0x16cb3
jmp 0x16ddc
btl $0x9, %ecx
jae 0x16cf2
addq %r12, %rdi
callq 0x1120c
movl %eax, %ebp
movq 0x28(%r14), %rdi
addq %r12, %rdi
callq 0x11222
testl %ebp, %ebp
js 0x16dcd
movq 0x50(%rbx), %rcx
movl %ebp, %edx
movq (%rcx,%rdx,8), %rcx
movb $0x0, (%rcx)
testl %eax, %eax
js 0x16cf2
movl %eax, %eax
jmp 0x16ce4
movl $0x1, %edi
callq 0x140a4
testl %eax, %eax
je 0x16e2e
cmpq $0x0, 0x8d38(%rbx)
jle 0x16e2e
xorl %r14d, %r14d
movq 0x98(%rbx,%r14,8), %rsi
movq 0x3f18(%rbx,%r14,8), %rcx
movswl 0x7d98(%rbx,%r14,2), %r8d
movq %rbx, %rdi
movl $0x1, %edx
callq 0x13c66
cmpl $-0x1, %eax
je 0x16e48
incq %r14
cmpq %r14, 0x8d38(%rbx)
jg 0x16df7
movq %rbx, %rdi
callq 0x13efe
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x137be
jmp 0x16c8e
movq %rax, %r14
movl $0x8d58, %esi           # imm = 0x8D58
movq %rbx, %rdi
callq 0x3320
movq %r14, %rdi
callq 0x3560
nopl (%rax)