// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/fiber.c
// Function: janet_env_detach
static void janet_env_detach(JanetFuncEnv *env) {
    /* Check for closure environment */
    if (env) {
        janet_env_valid(env);
        int32_t len = env->length;
        size_t s = sizeof(Janet) * (size_t) len;
        Janet *vmem = janet_malloc(s);
        janet_vm.next_collection += (uint32_t) s;
        if (NULL == vmem) {
            JANET_OUT_OF_MEMORY;
        }
        Janet *values = env->as.fiber->data + env->offset;
        safe_memcpy(vmem, values, s);
        uint32_t *bitset = janet_stack_frame(values)->func->def->closure_bitset;
        if (bitset) {
            /* Clear unneeded references in closure environment */
            for (int32_t i = 0; i < len; i += 32) {
                uint32_t mask = ~(bitset[i >> 5]);
                int32_t maxj = i + 32 > len ? len : i + 32;
                for (int32_t j = i; j < maxj; j++) {
                    if (mask & 1) vmem[j] = janet_wrap_nil();
                    mask >>= 1;
                }
            }
        }
        env->offset = 0;
        env->as.values = vmem;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x36c2c
movq -0x8(%rbp), %rdi
callq 0x368b0
movq -0x8(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rax
shlq $0x3, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x12770
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq %fs:0x0, %rax
leaq -0x348(%rax), %rax
movq -0x50(%rbp), %rcx
addq 0xa8(%rax), %rcx
movq %rcx, 0xa8(%rax)
xorl %eax, %eax
cmpq -0x20(%rbp), %rax
jne 0x36b07
jmp 0x36ad9
movq 0x79510(%rip), %rax     # 0xafff0
movq (%rax), %rdi
leaq 0x4751a(%rip), %rsi     # 0x7e004
leaq 0x53411(%rip), %rdx     # 0x89f02
movl $0x106, %ecx            # imm = 0x106
movb $0x0, %al
callq 0x125f0
movl $0x1, %edi
callq 0x12a70
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x30(%rax), %rax
movq -0x8(%rbp), %rcx
movslq 0x1c(%rcx), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x6ae40
movq -0x28(%rbp), %rax
movq -0x20(%rax), %rax
movq 0x10(%rax), %rax
movq 0x30(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x36c15
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x36c13
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
sarl $0x5, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
xorl $-0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
addl $0x20, %eax
cmpl -0xc(%rbp), %eax
jle 0x36b92
movl -0xc(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x36b9b
movl -0x34(%rbp), %eax
addl $0x20, %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x36c03
movl -0x38(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x36bf0
movq -0x20(%rbp), %rax
movq %rax, -0x60(%rbp)
movslq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq -0x68(%rbp), %rcx
movq %rax, %rdx
movq -0x60(%rbp), %rax
movq %rdx, -0x48(%rbp)
movq -0x48(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
shrl %eax
movl %eax, -0x38(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x36ba7
jmp 0x36c05
movl -0x34(%rbp), %eax
addl $0x20, %eax
movl %eax, -0x34(%rbp)
jmp 0x36b5d
jmp 0x36c15
movq -0x8(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)