// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x8d58, %edi           # imm = 0x8D58
callq 0x4380
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x68(%rbp)
callq 0x25370
jmp 0x2bc6e
movq -0x68(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x253e0
leaq 0x16bea(%rip), %rdi     # 0x42870
callq 0x1e360
leaq 0x16dee(%rip), %rdi     # 0x42a80
callq 0x2d760
cmpq $0x0, -0x18(%rbp)
jne 0x2bcca
leaq 0x83e1(%rip), %rax      # 0x34086
movq %rax, -0x18(%rbp)
jmp 0x2bcca
movq -0x68(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x8d58, %esi           # imm = 0x8D58
callq 0x4390
jmp 0x2c109
leaq 0x16b7f(%rip), %rax     # 0x42850
movl $0x0, (%rax)
leaq 0x16b76(%rip), %rax     # 0x42854
movl $0x0, (%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x1cb54(%rip), %eax     # 0x48848
jge 0x2bd81
movq 0x16d77(%rip), %rax     # 0x42a78
movslq -0x1c(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x2bd27
movq 0x16d65(%rip), %rax     # 0x42a78
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
leaq 0x1672e(%rip), %rax     # 0x42450
movq %rcx, (%rax)
jmp 0x2bd38
leaq 0x16722(%rip), %rax     # 0x42450
leaq 0x835d(%rip), %rcx      # 0x34092
movq %rcx, (%rax)
movq -0x28(%rbp), %rdi
leaq 0x1670d(%rip), %rax     # 0x42450
movq (%rax), %rsi
callq 0x26020
movq 0x16d1e(%rip), %rax     # 0x42a70
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x28(%rbp), %rsi
callq 0x17b70
leaq 0x16ae6(%rip), %rax     # 0x42850
cmpl $0x0, (%rax)
je 0x2bd71
jmp 0x2bd81
jmp 0x2bd73
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2bceb
leaq 0x16ac8(%rip), %rax     # 0x42850
cmpl $0x0, (%rax)
jne 0x2bdbb
movq -0x18(%rbp), %rcx
leaq 0x166b8(%rip), %rax     # 0x42450
movq %rcx, (%rax)
movq -0x28(%rbp), %rdi
leaq 0x166aa(%rip), %rax     # 0x42450
movq (%rax), %rsi
callq 0x26020
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x17b70
callq 0x2d7a0
leaq 0x16a89(%rip), %rax     # 0x42850
cmpl $0x0, (%rax)
je 0x2bdfa
movq -0x28(%rbp), %rdi
callq 0x25560
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, %rax
je 0x2bded
movq -0x70(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, -0x8(%rbp)
jmp 0x2c0fc
movl $0x0, -0x1c(%rbp)
movslq -0x1c(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq 0x16a60(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e80
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jae 0x2c05e
movl -0x1c(%rbp), %esi
leaq 0x16a3d(%rip), %rdi     # 0x42870
callq 0x1e1e0
movl %eax, -0x38(%rbp)
movslq -0x1c(%rbp), %rsi
leaq 0x16a2a(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x4, %rax
cmpq $0x0, %rax
je 0x2bf64
movslq -0x1c(%rbp), %rsi
leaq 0x16a04(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x8, %rax
cmpq $0x0, %rax
jne 0x2bf64
cmpl $0x4, -0x38(%rbp)
je 0x2be93
cmpl $0x1, -0x38(%rbp)
jne 0x2beca
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x80(%rbp)
movslq -0x1c(%rbp), %rsi
leaq 0x169c6(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq %rax, %rcx
movq -0x80(%rbp), %rax
movslq 0x34(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movb $0x0, (%rax)
jmp 0x2bf62
movslq -0x1c(%rbp), %rsi
leaq 0x1699b(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x200, %rax            # imm = 0x200
cmpq $0x0, %rax
je 0x2bf60
movslq -0x1c(%rbp), %rsi
leaq 0x16977(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq %rax, %rdi
callq 0x1e2e0
movl %eax, -0x3c(%rbp)
movslq -0x1c(%rbp), %rsi
leaq 0x16958(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq %rax, %rdi
callq 0x1e320
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x2bf45
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb $0x0, (%rax)
cmpl $0x0, -0x40(%rbp)
jl 0x2bf5e
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb $0x0, (%rax)
jmp 0x2bf60
jmp 0x2bf62
jmp 0x2bf64
movl -0x1c(%rbp), %esi
leaq 0x16902(%rip), %rdi     # 0x42870
callq 0x1e1e0
cmpl $0x1, %eax
je 0x2bf91
movl -0x1c(%rbp), %esi
leaq 0x168ee(%rip), %rdi     # 0x42870
callq 0x1e1e0
cmpl $0x2, %eax
je 0x2bf91
jmp 0x2c050
movslq -0x1c(%rbp), %rsi
leaq 0x168d4(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x4, %rax
cmpq $0x0, %rax
je 0x2bfb8
jmp 0x2c050
movl $0x2, %edi
callq 0x265a0
cmpl $0x0, %eax
jne 0x2bfcc
jmp 0x2c04e
movslq -0x1c(%rbp), %rsi
leaq 0x16899(%rip), %rdi     # 0x42870
addq $0x28, %rdi
callq 0x17e60
movq 0x28(%rax), %rax
andq $0x8, %rax
cmpq $0x0, %rax
jne 0x2c04c
movl -0x1c(%rbp), %edx
leaq 0x16878(%rip), %rsi     # 0x42870
leaq -0x60(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x1f080
movq -0x88(%rbp), %rdi
callq 0x41b0
movq %rax, %rsi
leaq 0x8089(%rip), %rdi      # 0x340a7
xorl %eax, %eax
callq 0x4090
jmp 0x2c027
leaq -0x60(%rbp), %rdi
callq 0x4270
jmp 0x2c04c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x4270
jmp 0x2c109
jmp 0x2c04e
jmp 0x2c050
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2be01
movl $0x1, %edi
callq 0x265a0
cmpl $0x0, %eax
je 0x2c0eb
movl $0x0, -0x1c(%rbp)
movslq -0x1c(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8d38(%rcx), %rax
jge 0x2c0e9
movq -0x28(%rbp), %rdi
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq 0x98(%rax,%rcx,8), %rsi
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq 0x3f18(%rax,%rcx,8), %rcx
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rdx
movswl 0x7d98(%rax,%rdx,2), %r8d
movl $0x1, %edx
callq 0x25e30
cmpl $-0x1, %eax
jne 0x2c0dc
movq -0x28(%rbp), %rdi
callq 0x25560
movq $0x0, -0x8(%rbp)
jmp 0x2c0fc
jmp 0x2c0de
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2c074
jmp 0x2c0eb
movq -0x28(%rbp), %rdi
callq 0x261d0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x4670
nopw %cs:(%rax,%rax)
nopl (%rax)