// File: /workspace/github_c_makefile_star2_O2/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 0x1a4b7
testb $0x10, %al
je 0x1a37d
orb $0x10, 0x6c(%rsi)
movq -0x30(%rbp), %rax
movl 0x40(%rax), %eax
cmpl %eax, 0x40(%rsi)
jge 0x1a38c
movl %eax, 0x40(%rsi)
leaq 0x30(%rsi), %rax
movq %rax, -0x60(%rbp)
pushq $0x34
popq %r13
xorl %edx, %edx
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
je 0x1a3ad
movslq -0x4(%rax), %rcx
jmp 0x1a3af
xorl %ecx, %ecx
cmpq %rcx, %rdx
jge 0x1a4b7
movq -0x34(%rax,%r13), %rcx
movq %rcx, -0x68(%rbp)
movl -0x2c(%rax,%r13), %ebx
movl -0x20(%rax,%r13), %ecx
movl %ecx, -0x50(%rbp)
movq -0x28(%rax,%r13), %rcx
movq %rcx, -0x58(%rbp)
movl -0x4(%rax,%r13), %r12d
cmpl $-0x1, %r12d
jne 0x1a3f8
movq -0x48(%rbp), %rcx
movq 0x8(%rcx), %rcx
testq %rcx, %rcx
je 0x1a3f5
movl -0x4(%rcx), %r12d
jmp 0x1a3f8
xorl %r12d, %r12d
movq %rdx, -0x70(%rbp)
movl -0xc(%rax,%r13), %r15d
movl -0x8(%rax,%r13), %ecx
movl %ecx, -0x3c(%rbp)
movl (%rax,%r13), %ecx
movl %ecx, -0x40(%rbp)
testl %r15d, %r15d
je 0x1a429
movq -0x60(%rbp), %rdi
movl %ebx, %esi
callq 0x3d36c
movq -0x38(%rbp), %rsi
xorl %r14d, %r14d
jmp 0x1a42e
movq -0x14(%rax,%r13), %r14
movq 0x20(%rsi), %rax
testq %rax, %rax
je 0x1a442
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
cmpl -0x8(%rax), %edx
jl 0x1a45e
movq %rax, %rdi
pushq $0x1
popq %rsi
pushq $0x38
popq %rdx
callq 0x4799c
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 %ebx, 0x8(%rax,%rcx)
movq -0x58(%rbp), %rdx
movq %rdx, 0xc(%rax,%rcx)
movl -0x50(%rbp), %edx
movl %edx, 0x14(%rax,%rcx)
andq $0x0, 0x18(%rax,%rcx)
movq %r14, 0x20(%rax,%rcx)
movl %r15d, 0x28(%rax,%rcx)
movl -0x3c(%rbp), %edx
movl %edx, 0x2c(%rax,%rcx)
movl %r12d, 0x30(%rax,%rcx)
movl -0x40(%rbp), %edx
movl %edx, 0x34(%rax,%rcx)
movq -0x70(%rbp), %rdx
incq %rdx
addq $0x38, %r13
jmp 0x1a39a
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
testq %rdi, %rdi
je 0x1a4cd
addq $-0x8, %rdi
callq 0x298c1
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
testq %rdi, %rdi
je 0x1a4e3
addq $-0x8, %rdi
callq 0x298c1
movq -0x30(%rbp), %rax
movq 0x60(%rax), %rdi
testq %rdi, %rdi
je 0x1a4f9
addq $-0x8, %rdi
callq 0x298c1
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rdi
testq %rdi, %rdi
je 0x1a50f
addq $-0x8, %rdi
callq 0x298c1
movq -0x30(%rbp), %rbx
leaq 0x30(%rbx), %rdi
callq 0x3d2cd
addq $0x48, %rbx
movq %rbx, %rdi
callq 0x3d2cd
movq -0x38(%rbp), %rcx
testq %rcx, %rcx
je 0x1a536
andq $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