// File: /workspace/github_c_makefile_star2_O2/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 0x2f5da
movq %rsi, %r15
movq %rdi, %rbx
movq 0x40(%rdi), %rax
xorl %r12d, %r12d
testq %rax, %rax
je 0x2f418
movslq -0x4(%rax), %rcx
jmp 0x2f41a
xorl %ecx, %ecx
cmpq %rcx, %r12
jge 0x2f42e
cmpq %r15, (%rax,%r12,8)
je 0x2f526
incq %r12
jmp 0x2f40d
movq %r15, %rdi
callq 0x27498
movq 0x40(%rbx), %rax
testq %rax, %rax
je 0x2f44a
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
cmpl -0x8(%rax), %edx
jl 0x2f462
pushq $0x1
popq %rsi
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x4799c
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 0x2f54c
movq 0x10(%r15), %r12
movq %r12, %rdi
callq 0x27553
cmpl $0xf, %eax
je 0x2f4ad
leaq 0x14(%r12), %rax
movslq (%rax), %rax
testq %rax, %rax
jle 0x2f54c
movq 0x30(%r12), %rcx
leaq (%rcx,%rax,8), %rax
addq $-0x8, %rax
cmpq $0x0, -0x18(%rax)
jne 0x2f48d
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2ccd8
movl 0x18(%r15), %esi
movq %rbx, %rdi
callq 0x2ccd8
movq 0x10(%r15), %rax
movq 0x30(%rax), %rax
movslq 0x1c(%r15), %rcx
leaq (%rax,%rcx,8), %r13
movq -0x20(%r13), %rax
movq 0x10(%rax), %rax
movq 0x30(%rax), %r14
incl -0x2c(%rbp)
movslq 0x18(%r15), %rax
cmpq %rax, %r12
jge 0x2f5cb
movl %r12d, %eax
shrl $0x5, %eax
movl (%r14,%rax,4), %eax
btl %r12d, %eax
jae 0x2f514
movq (%r13,%r12,8), %rsi
movq %rbx, %rdi
movl -0x2c(%rbp), %edx
callq 0x2cddb
jmp 0x2f521
movq %rbx, %rdi
movl $0xc9, %esi
callq 0x2cd91
incq %r12
jmp 0x2f4e5
movq %rbx, %rdi
movl $0xdb, %esi
callq 0x2cd91
movq %rbx, %rdi
movl %r12d, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2ccd8
movq %r15, %rdi
callq 0x27501
movl 0x1c(%r15), %esi
movq %rbx, %rdi
callq 0x2ccd8
movl 0x18(%r15), %esi
movq %rbx, %rdi
callq 0x2ccd8
cmpl $0x0, 0x1c(%r15)
jle 0x2f5a4
movq 0x10(%r15), %rdi
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
callq 0x4b3ab
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 0x2cddb
incl -0x2c(%rbp)
xorl %r14d, %r14d
movslq 0x18(%r15), %rax
cmpq %rax, %r14
jge 0x2f5cb
movq 0x10(%r15), %rax
movq (%rax,%r14,8), %rsi
movq %rbx, %rdi
movl -0x2c(%rbp), %edx
callq 0x2cddb
incq %r14
jmp 0x2f5aa
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x29912(%rip), %rdi     # 0x58ef3
callq 0x177b1