// File: /workspace/github_c_makefile_star2_O1/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 0x31e12
movq %rsi, %r15
movq %rdi, %r14
movq 0x40(%rdi), %rax
xorl %r12d, %r12d
testq %rax, %rax
je 0x31c49
movslq -0x4(%rax), %rbx
jmp 0x31c4b
xorl %ebx, %ebx
cmpq %rbx, %r12
jge 0x31c7c
cmpq %r15, (%rax,%r12,8)
je 0x31c5b
incq %r12
jmp 0x31c3e
movq (%r14), %rdi
movl $0xdb, %esi
callq 0x179a7
movq %r14, %rdi
movl %r12d, %esi
callq 0x2fa79
cmpq %rbx, %r12
jl 0x31e03
movq %r15, %rdi
callq 0x29d85
movq 0x40(%r14), %rdi
testq %rdi, %rdi
je 0x31c97
movl -0x4(%rdi), %eax
incl %eax
cmpl -0x8(%rdi), %eax
jl 0x31caa
movl $0x1, %esi
movl $0x8, %edx
callq 0x4c0b4
movq %rax, 0x40(%r14)
movq 0x40(%r14), %rax
movslq -0x4(%rax), %rcx
leal 0x1(%rcx), %edx
movl %edx, -0x4(%rax)
movq %r15, (%rax,%rcx,8)
cmpl $0x0, 0x1c(%r15)
jle 0x31d80
movq 0x10(%r15), %r12
movq %r12, %rdi
callq 0x29e47
cmpl $0xf, %eax
je 0x31cff
movl 0x14(%r12), %eax
testl %eax, %eax
jle 0x31d80
movq 0x30(%r12), %rdx
movl %eax, %esi
movq -0x20(%rdx,%rsi,8), %rcx
testq %rcx, %rcx
je 0x31cfa
movl -0x8(%rdx,%rsi,8), %eax
testq %rcx, %rcx
jne 0x31cdd
movq (%r14), %rdi
xorl %esi, %esi
callq 0x179a7
movl 0x18(%r15), %esi
movq %r14, %rdi
callq 0x2fa79
cmpl $0x0, 0x18(%r15)
jle 0x31e03
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 %ebx, %ebx
movl %ebx, %eax
shrl $0x5, %eax
movl (%r13,%rax,4), %eax
btl %ebx, %eax
jae 0x31d62
movq (%r12,%rbx,8), %rsi
movq %r14, %rdi
movl -0x2c(%rbp), %edx
callq 0x2fb6f
jmp 0x31d6f
movq (%r14), %rdi
movl $0xc9, %esi
callq 0x179a7
incq %rbx
movslq 0x18(%r15), %rax
cmpq %rax, %rbx
jl 0x31d42
jmp 0x31e03
movq %r15, %rdi
callq 0x29df5
movl 0x1c(%r15), %esi
movq %r14, %rdi
callq 0x2fa79
movl 0x18(%r15), %esi
movq %r14, %rdi
callq 0x2fa79
cmpl $0x0, 0x1c(%r15)
jle 0x31dd8
movq 0x10(%r15), %rdi
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
callq 0x4f9f2
movl -0x2c(%rbp), %edx
incl %edx
movq %r14, %rdi
movq %rax, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2fb6f
cmpl $0x0, 0x18(%r15)
jle 0x31e03
incl -0x2c(%rbp)
xorl %ebx, %ebx
movq 0x10(%r15), %rax
movq (%rax,%rbx,8), %rsi
movq %r14, %rdi
movl -0x2c(%rbp), %edx
callq 0x2fb6f
incq %rbx
movslq 0x18(%r15), %rax
cmpq %rax, %rbx
jl 0x31de4
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2c0da(%rip), %rdi     # 0x5def3
callq 0x19263