// File: /workspace/github_cpp_makefile_star2_O3/rofl0r[P]ascc/cs_parser.cpp
// Function: remove_locals(int, int, ccCompiledScript*)
int remove_locals(int from_level, int just_count, ccCompiledScript *scrip) {
    int cc, totalsub = 0;
    int zeroPtrCmd = SCMD_MEMZEROPTR;
    if (from_level == 0)
        zeroPtrCmd = SCMD_MEMZEROPTRND;

    for (cc=0; (size_t)cc<sym.entries.size();cc++) {
        if ((sym.entries[cc].sscope > from_level) && (sym.entries[cc].stype == SYM_LOCALVAR)) {
            // caller will sort out stack, so ignore parameters
            if ((sym.entries[cc].flags & SFLG_PARAMETER)==0) {
                if (sym.entries[cc].flags & SFLG_DYNAMICARRAY)
                    totalsub += 4;
                else
                {
                    // remove all elements if array
                    if (sym.entries[cc].flags & SFLG_ARRAY) {
                        if(sym.entries[cc].arrsize == 0) /* raw pointer */
                          totalsub += 4;
                        else
                          totalsub += (sym.entries[cc].arrsize) * sym.entries[cc].ssize;
                    } else
                        totalsub += sym.entries[cc].ssize;
                }
                if (sym.entries[cc].flags & SFLG_STRBUFFER)
                    totalsub += STRING_LENGTH;
            }
            // release the pointer reference if applicable
            if (sym.entries[cc].flags & SFLG_THISPTR) { }
            else if (((sym.entries[cc].flags & SFLG_POINTER) != 0) ||
                ((sym.entries[cc].flags & SFLG_DYNAMICARRAY) != 0))
            {
                free_pointer(scrip->cur_sp - sym.entries[cc].soffs, zeroPtrCmd, cc, scrip);
            }
            else if (sym.entries[sym.entries[cc].vartype].flags & SFLG_STRUCTTYPE) {
                // a struct -- free any pointers it contains
                free_pointers_from_struct(cc, scrip);
            }

            if (just_count == 0) {
                sym.entries[cc].stype = 0;
                sym.entries[cc].sscope = 0;
                sym.entries[cc].flags = 0;
            }
        }
    }
    return totalsub;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, 0x10(%rsp)
testl %edi, %edi
movl $0x45, %eax
movl $0x31, %ecx
cmovel %eax, %ecx
movl %ecx, 0xc(%rsp)
leaq 0x2031a(%rip), %r12     # 0x256e0
movq 0x28(%r12), %r10
cmpq %r10, 0x30(%r12)
je 0x54ea
movl %esi, %ebp
movl %edi, %r14d
movl $0x40, %r15d
movabsq $0x2e8ba2e8ba2e8ba3, %rdi # imm = 0x2E8BA2E8BA2E8BA3
xorl %r13d, %r13d
xorl %ebx, %ebx
movswl (%r10,%r15), %ecx
cmpl %r14d, %ecx
jle 0x54c5
cmpw $0x2, -0x20(%r10,%r15)
jne 0x54c5
movq -0x18(%r10,%r15), %rcx
testb $0x1, %cl
jne 0x544e
movl $0x4, %edx
btl $0x12, %ecx
jb 0x543e
testb $0x2, %cl
jne 0x542c
movl -0x8(%r10,%r15), %edx
jmp 0x543e
movq 0x8(%r10,%r15), %rsi
testq %rsi, %rsi
je 0x543e
imull -0x8(%r10,%r15), %esi
movl %esi, %edx
leal (%rbx,%rdx), %esi
testb $0x10, %cl
leal 0xc8(%rbx,%rdx), %ebx
cmovel %esi, %ebx
btl $0xb, %ecx
jb 0x54a6
testl $0x40100, %ecx          # imm = 0x40100
je 0x547a
movq 0x10(%rsp), %rcx
movl 0x8d40(%rcx), %edi
subl -0xc(%r10,%r15), %edi
movl 0xc(%rsp), %esi
movl %r13d, %edx
callq 0x5188
jmp 0x549c
movswq -0x10(%r10,%r15), %rcx
imulq $0xb0, %rcx, %rcx
testb $0x4, 0x29(%r10,%rcx)
je 0x54a6
movl %r13d, %edi
movq 0x10(%rsp), %rsi
callq 0x5270
movabsq $0x2e8ba2e8ba2e8ba3, %rdi # imm = 0x2E8BA2E8BA2E8BA3
movq 0x28(%r12), %r10
testl %ebp, %ebp
jne 0x54c5
xorl %ecx, %ecx
movw %cx, -0x20(%r10,%r15)
movw %cx, (%r10,%r15)
movq $0x0, -0x18(%r10,%r15)
incq %r13
movq 0x30(%r12), %rcx
subq %r10, %rcx
sarq $0x4, %rcx
imulq %rdi, %rcx
addq $0xb0, %r15
cmpq %r13, %rcx
ja 0x53f0
jmp 0x54ec
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq