// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/src/core/marsh.c
// Function: marshal_one_env
static void marshal_one_env(MarshalState *st, JanetFuncEnv *env, int flags) {
    MARSH_STACKCHECK;
    for (int32_t i = 0; i < janet_v_count(st->seen_envs); i++) {
        if (st->seen_envs[i] == env) {
            pushbyte(st, LB_FUNCENV_REF);
            pushint(st, i);
            return;
        }
    }
    janet_env_valid(env);
    janet_v_push(st->seen_envs, env);

    /* Special case for early detachment */
    if (env->offset > 0 && fiber_cannot_be_marshalled(env->as.fiber)) {
        pushint(st, 0);
        pushint(st, env->length);
        Janet *values = env->as.fiber->data + env->offset;
        uint32_t *bitset = janet_stack_frame(values)->func->def->closure_bitset;
        for (int32_t i = 0; i < env->length; i++) {
            if (1 & (bitset[i >> 5] >> (i & 0x1F))) {
                marshal_one(st, values[i], flags + 1);
            } else {
                pushbyte(st, LB_NIL);
            }
        }
    } else {
        janet_env_maybe_detach(env);
        pushint(st, env->offset);
        pushint(st, env->length);
        if (env->offset > 0) {
            /* On stack variant */
            marshal_one(st, janet_wrap_fiber(env->as.fiber), flags + 1);
        } else {
            /* Off stack variant */
            for (int32_t i = 0; i < env->length; i++)
                marshal_one(st, env->as.values[i], flags + 1);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, -0x2c(%rbp)
movzwl %dx, %eax
cmpl $0x400, %eax            # imm = 0x400
ja 0x3187c
movq %rsi, %r15
movq %rdi, %rbx
movq 0x40(%rdi), %rax
xorl %r12d, %r12d
testq %rax, %rax
je 0x316a3
movslq -0x4(%rax), %rcx
jmp 0x316a5
xorl %ecx, %ecx
cmpq %rcx, %r12
jge 0x316b9
cmpq %r15, (%rax,%r12,8)
je 0x3179f
incq %r12
jmp 0x31698
movq %r15, %rdi
callq 0x298b5
movq 0x40(%rbx), %rax
testq %rax, %rax
je 0x316d5
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
cmpl -0x8(%rax), %edx
jl 0x316f1
movq %rax, %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0x4b4e8
movq %rax, 0x40(%rbx)
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
movl %edx, -0x4(%rax)
movslq %ecx, %rcx
movq %r15, (%rax,%rcx,8)
cmpl $0x0, 0x1c(%r15)
jle 0x317e9
movq 0x10(%r15), %r12
movq %r12, %rdi
callq 0x2996f
cmpl $0xf, %eax
jne 0x317c5
movq (%rbx), %rdi
xorl %esi, %esi
callq 0x17947
movl 0x18(%r15), %esi
movq %rbx, %rdi
callq 0x2f4c1
cmpl $0x0, 0x18(%r15)
jle 0x3186d
movq 0x10(%r15), %rax
movq 0x30(%rax), %rax
movslq 0x1c(%r15), %rcx
leaq (%rax,%rcx,8), %r12
movq -0x20(%r12), %rax
movq 0x10(%rax), %rax
movq 0x30(%rax), %r13
incl -0x2c(%rbp)
xorl %r14d, %r14d
movl %r14d, %eax
shrl $0x5, %eax
movl (%r13,%rax,4), %eax
btl %r14d, %eax
jae 0x31781
movq (%r12,%r14,8), %rsi
movq %rbx, %rdi
movl -0x2c(%rbp), %edx
callq 0x2f5b7
jmp 0x3178e
movq (%rbx), %rdi
movl $0xc9, %esi
callq 0x17947
incq %r14
movslq 0x18(%r15), %rax
cmpq %rax, %r14
jl 0x3175f
jmp 0x3186d
movq (%rbx), %rdi
movl $0xdb, %esi
callq 0x17947
movq %rbx, %rdi
movl %r12d, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2f4c1
movl 0x14(%r12), %ecx
testl %ecx, %ecx
jle 0x317e9
movq 0x30(%r12), %rax
movl %ecx, %ecx
cmpq $0x0, -0x20(%rax,%rcx,8)
je 0x3171b
movl -0x8(%rax,%rcx,8), %ecx
testl %ecx, %ecx
jg 0x317d3
movq %r15, %rdi
callq 0x2991d
movl 0x1c(%r15), %esi
movq %rbx, %rdi
callq 0x2f4c1
movl 0x18(%r15), %esi
movq %rbx, %rdi
callq 0x2f4c1
cmpl $0x0, 0x1c(%r15)
jle 0x31841
movq 0x10(%r15), %rdi
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
callq 0x4ed7e
movl -0x2c(%rbp), %edx
incl %edx
movq %rbx, %rdi
movq %rax, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2f5b7
cmpl $0x0, 0x18(%r15)
jle 0x3186d
incl -0x2c(%rbp)
xorl %r14d, %r14d
movq 0x10(%r15), %rax
movq (%rax,%r14,8), %rsi
movq %rbx, %rdi
movl -0x2c(%rbp), %edx
callq 0x2f5b7
incq %r14
movslq 0x18(%r15), %rax
cmpq %rax, %r14
jl 0x3184e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2b670(%rip), %rdi     # 0x5cef3
callq 0x191a3