// File: /workspace/github_cpp_makefile_star2_O1/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 0x20295(%rip), %rbx     # 0x256e0
movq 0x28(%rbx), %r9
cmpq %r9, 0x30(%rbx)
je 0x5583
movl %esi, %ebp
movl %edi, %r14d
movl $0x40, %r15d
movabsq $0x2e8ba2e8ba2e8ba3, %r12 # imm = 0x2E8BA2E8BA2E8BA3
xorl %r13d, %r13d
xorl %eax, %eax
movswl (%r9,%r15), %ecx
cmpl %r14d, %ecx
jle 0x555b
cmpw $0x2, -0x20(%r9,%r15)
jne 0x555b
movq -0x18(%r9,%r15), %rcx
testb $0x1, %cl
jne 0x54d1
movl $0x4, %edx
btl $0x12, %ecx
jb 0x54c1
testb $0x2, %cl
jne 0x54af
movl -0x8(%r9,%r15), %edx
jmp 0x54c1
movq 0x8(%r9,%r15), %rsi
testq %rsi, %rsi
je 0x54c1
imull -0x8(%r9,%r15), %esi
movl %esi, %edx
leal (%rax,%rdx), %esi
testb $0x10, %cl
leal 0xc8(%rax,%rdx), %eax
cmovel %esi, %eax
btl $0xb, %ecx
jb 0x553d
testl $0x40100, %ecx          # imm = 0x40100
je 0x550d
movq 0x10(%rsp), %rcx
movl 0x8d40(%rcx), %edi
subl -0xc(%r9,%r15), %edi
movl 0xc(%rsp), %esi
movl %r13d, %edx
movq %rax, %r12
callq 0x51ff
movq %r12, %rax
movabsq $0x2e8ba2e8ba2e8ba3, %r12 # imm = 0x2E8BA2E8BA2E8BA3
jmp 0x553d
movswq -0x10(%r9,%r15), %rcx
imulq $0xb0, %rcx, %rcx
testb $0x4, 0x29(%r9,%rcx)
je 0x553d
movl %r13d, %edi
movq 0x10(%rsp), %rsi
movl %ebp, 0x8(%rsp)
movq %rax, %rbp
callq 0x52eb
movq %rbp, %rax
movl 0x8(%rsp), %ebp
testl %ebp, %ebp
jne 0x555b
movq 0x28(%rbx), %rdx
xorl %ecx, %ecx
movw %cx, -0x20(%rdx,%r15)
movw %cx, (%rdx,%r15)
movq $0x0, -0x18(%rdx,%r15)
incq %r13
movq 0x28(%rbx), %r9
movq 0x30(%rbx), %rcx
subq %r9, %rcx
sarq $0x4, %rcx
imulq %r12, %rcx
addq $0xb0, %r15
cmpq %r13, %rcx
ja 0x5473
jmp 0x5585
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq