// File: /workspace/github_cpp_makefile_star2_O2/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)
movl %esi, %ebp
movl %edi, %r14d
testl %edi, %edi
pushq $0x45
popq %rax
pushq $0x31
popq %rdx
cmovel %eax, %edx
movl %edx, 0xc(%rsp)
xorl %r12d, %r12d
pushq $0x40
popq %r15
leaq 0x20521(%rip), %rbx     # 0x256f0
movl $0xb0, %edi
xorl %r13d, %r13d
movq 0x28(%rbx), %r8
movq 0x30(%rbx), %rax
subq %r8, %rax
cqto
idivq %rdi
cmpq %r12, %rax
jbe 0x52cb
movswl (%r8,%r15), %eax
cmpl %r14d, %eax
jle 0x52bc
cmpw $0x2, -0x20(%r8,%r15)
jne 0x52bc
movq -0x18(%r8,%r15), %rax
testb $0x1, %al
jne 0x524f
btl $0x12, %eax
pushq $0x4
popq %rdx
jb 0x523d
testb $0x2, %al
jne 0x5228
movl -0x8(%r8,%r15), %edx
jmp 0x523d
movq 0x8(%r8,%r15), %rsi
pushq $0x4
popq %rdx
testq %rsi, %rsi
je 0x523d
imull -0x8(%r8,%r15), %esi
movl %esi, %edx
leal (%rdx,%r13), %esi
testb $0x10, %al
leal 0xc8(%r13,%rdx), %r13d
cmovel %esi, %r13d
btl $0xb, %eax
jb 0x52a1
testl $0x40100, %eax          # imm = 0x40100
je 0x527a
movq 0x10(%rsp), %rcx
movl 0x8d40(%rcx), %edi
subl -0xc(%r8,%r15), %edi
movl 0xc(%rsp), %esi
movl %r12d, %edx
callq 0x4f9d
jmp 0x529c
movswq -0x10(%r8,%r15), %rax
imulq $0xb0, %rax, %rax
testb $0x4, 0x29(%r8,%rax)
je 0x52a1
movl %r12d, %edi
movq 0x10(%rsp), %rsi
callq 0x507d
movl $0xb0, %edi
testl %ebp, %ebp
jne 0x52bc
movq 0x28(%rbx), %rax
andw $0x0, -0x20(%rax,%r15)
andw $0x0, (%rax,%r15)
andq $0x0, -0x18(%rax,%r15)
incq %r12
addq $0xb0, %r15
jmp 0x51d7
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq