// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/src/core/compile.c
// Function: janetc_popscope
void janetc_popscope(JanetCompiler *c) {
    JanetScope *oldscope = c->scope;
    JanetScope *newscope = oldscope->parent;
    /* Move free slots to parent scope if not a new function.
     * We need to know the total number of slots used when compiling the function. */
    if (!(oldscope->flags & (JANET_SCOPE_FUNCTION | JANET_SCOPE_UNUSED)) && newscope) {
        /* Parent scopes inherit child's closure flag. Needed
         * for while loops. (if a while loop creates a closure, it
         * is compiled to a tail recursive iife) */
        if (oldscope->flags & JANET_SCOPE_CLOSURE) {
            newscope->flags |= JANET_SCOPE_CLOSURE;
        }
        if (newscope->ra.max < oldscope->ra.max) {
            newscope->ra.max = oldscope->ra.max;
        }

        /* Keep upvalue slots and symbols for debugging. */
        for (int32_t i = 0; i < janet_v_count(oldscope->syms); i++) {
            SymPair pair = oldscope->syms[i];
            /* The variable should not be lexically accessible */
            pair.sym = NULL;
            if (pair.death_pc == UINT32_MAX) {
                pair.death_pc = (uint32_t) janet_v_count(c->buffer);
            }
            if (pair.keep) {
                /* The variable should also not be included in the locals */
                pair.sym2 = NULL;
                janetc_regalloc_touch(&newscope->ra, pair.slot.index);
            }
            janet_v_push(newscope->syms, pair);
        }
    }

    /* Free the old scope */
    janet_v_free(oldscope->consts);
    janet_v_free(oldscope->syms);
    janet_v_free(oldscope->envs);
    janet_v_free(oldscope->defs);
    janetc_regalloc_deinit(&oldscope->ra);
    janetc_regalloc_deinit(&oldscope->ua);
    /* Update pointer */
    if (newscope)
        newscope->child = NULL;
    c->scope = newscope;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, -0x48(%rbp)
movq (%rdi), %rax
movq 0x8(%rax), %rsi
movq %rax, -0x30(%rbp)
movl 0x6c(%rax), %eax
testb $0x9, %al
sete %cl
testq %rsi, %rsi
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
movq %rsi, -0x38(%rbp)
jne 0x1c072
testb $0x10, %al
je 0x1bf31
orb $0x10, 0x6c(%rsi)
movq -0x30(%rbp), %rax
movl 0x40(%rax), %eax
cmpl %eax, 0x40(%rsi)
jge 0x1bf40
movl %eax, 0x40(%rsi)
leaq 0x30(%rsi), %rax
movq %rax, -0x60(%rbp)
movl $0x34, %ebx
xorl %edx, %edx
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x1bf62
movslq -0x4(%rax), %rcx
jmp 0x1bf64
xorl %ecx, %ecx
cmpq %rcx, %rdx
jge 0x1c072
movq -0x34(%rax,%rbx), %rcx
movq %rcx, -0x68(%rbp)
movl -0x2c(%rax,%rbx), %r12d
movl -0x20(%rax,%rbx), %ecx
movl %ecx, -0x50(%rbp)
movq -0x28(%rax,%rbx), %rcx
movq %rcx, -0x58(%rbp)
movl -0x4(%rax,%rbx), %r13d
cmpl $-0x1, %r13d
jne 0x1bfac
movq -0x48(%rbp), %rcx
movq 0x8(%rcx), %rcx
testq %rcx, %rcx
je 0x1bfa9
movl -0x4(%rcx), %r13d
jmp 0x1bfac
xorl %r13d, %r13d
movq %rdx, -0x70(%rbp)
movl -0xc(%rax,%rbx), %r15d
movl -0x8(%rax,%rbx), %ecx
movl %ecx, -0x3c(%rbp)
movl (%rax,%rbx), %ecx
movl %ecx, -0x40(%rbp)
testl %r15d, %r15d
je 0x1bfdc
movq -0x60(%rbp), %rdi
movl %r12d, %esi
callq 0x409ac
movq -0x38(%rbp), %rsi
xorl %r14d, %r14d
jmp 0x1bfe1
movq -0x14(%rax,%rbx), %r14
movq 0x20(%rsi), %rax
testq %rax, %rax
je 0x1bff5
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
cmpl -0x8(%rax), %edx
jl 0x1c015
movq %rax, %rdi
movl $0x1, %esi
movl $0x38, %edx
callq 0x4b4e8
movq -0x38(%rbp), %rsi
movq %rax, 0x20(%rsi)
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
movl %edx, -0x4(%rax)
movslq %ecx, %rcx
imulq $0x38, %rcx, %rcx
movq -0x68(%rbp), %rdx
movq %rdx, (%rax,%rcx)
movl %r12d, 0x8(%rax,%rcx)
movq -0x58(%rbp), %rdx
movq %rdx, 0xc(%rax,%rcx)
movl -0x50(%rbp), %edx
movl %edx, 0x14(%rax,%rcx)
movq $0x0, 0x18(%rax,%rcx)
movq %r14, 0x20(%rax,%rcx)
movl %r15d, 0x28(%rax,%rcx)
movl -0x3c(%rbp), %edx
movl %edx, 0x2c(%rax,%rcx)
movl %r13d, 0x30(%rax,%rcx)
movl -0x40(%rbp), %edx
movl %edx, 0x34(%rax,%rcx)
movq -0x70(%rbp), %rdx
incq %rdx
addq $0x38, %rbx
jmp 0x1bf4f
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
testq %rdi, %rdi
je 0x1c088
addq $-0x8, %rdi
callq 0x2bcd9
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
testq %rdi, %rdi
je 0x1c09e
addq $-0x8, %rdi
callq 0x2bcd9
movq -0x30(%rbp), %rax
movq 0x60(%rax), %rdi
testq %rdi, %rdi
je 0x1c0b4
addq $-0x8, %rdi
callq 0x2bcd9
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rdi
testq %rdi, %rdi
je 0x1c0ca
addq $-0x8, %rdi
callq 0x2bcd9
movq -0x30(%rbp), %rbx
leaq 0x30(%rbx), %rdi
callq 0x4092c
addq $0x48, %rbx
movq %rbx, %rdi
callq 0x4092c
movq -0x38(%rbp), %rcx
testq %rcx, %rcx
je 0x1c0f4
movq $0x0, 0x10(%rcx)
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq