// File: /workspace/github_c_makefile_star2_O3/janet-lang[P]janet/src/core/marsh.c
// Function: marshal_one_fiber
static void marshal_one_fiber(MarshalState *st, JanetFiber *fiber, int flags) {
    MARSH_STACKCHECK;
    int32_t fflags = fiber->flags;
    if (fiber->child) fflags |= JANET_FIBER_FLAG_HASCHILD;
    if (fiber->env) fflags |= JANET_FIBER_FLAG_HASENV;
    if (janet_fiber_status(fiber) == JANET_STATUS_ALIVE)
        janet_panic("cannot marshal alive fiber");
    pushint(st, fflags);
    pushint(st, fiber->frame);
    pushint(st, fiber->stackstart);
    pushint(st, fiber->stacktop);
    pushint(st, fiber->maxstack);
    /* Do frames */
    int32_t i = fiber->frame;
    int32_t j = fiber->stackstart - JANET_FRAME_SIZE;
    while (i > 0) {
        JanetStackFrame *frame = (JanetStackFrame *)(fiber->data + i - JANET_FRAME_SIZE);
        if (frame->env) frame->flags |= JANET_STACKFRAME_HASENV;
        if (!frame->func) janet_panicf("cannot marshal fiber with c stackframe (%v)", janet_wrap_cfunction((JanetCFunction) frame->pc));
        pushint(st, frame->flags);
        pushint(st, frame->prevframe);
        int32_t pcdiff = (int32_t)(frame->pc - frame->func->def->bytecode);
        pushint(st, pcdiff);
        marshal_one(st, janet_wrap_function(frame->func), flags + 1);
        if (frame->env) marshal_one_env(st, frame->env, flags + 1);
        /* Marshal all values in the stack frame */
        for (int32_t k = i; k < j; k++)
            marshal_one(st, fiber->data[k], flags + 1);
        j = i - JANET_FRAME_SIZE;
        i = frame->prevframe;
    }
    if (fiber->env) {
        marshal_one(st, janet_wrap_table(fiber->env), flags + 1);
    }
    if (fiber->child)
        marshal_one(st, janet_wrap_fiber(fiber->child), flags + 1);
    marshal_one(st, fiber->last_value, flags + 1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movzwl %dx, %eax
cmpl $0x401, %eax            # imm = 0x401
jae 0x31ac0
movq %rsi, %r13
movq %rdi, %r12
movq %rdx, -0x40(%rbp)
movl 0x10(%rsi), %r14d
movq 0x38(%rsi), %r15
movq 0x28(%rsi), %rbx
movq %rsi, %rdi
callq 0x2996f
cmpl $0xf, %eax
je 0x31acc
movl %r14d, %eax
orl $0x20000000, %eax       # imm = 0x20000000
testq %r15, %r15
cmovel %r14d, %eax
movl %eax, %esi
orl $0x40000000, %esi       # imm = 0x40000000
testq %rbx, %rbx
cmovel %eax, %esi
movq %r12, %r15
movq %r12, %rdi
callq 0x2f4c1
movl 0x14(%r13), %esi
movq %r12, %rdi
callq 0x2f4c1
movl 0x18(%r13), %esi
movq %r12, %rdi
callq 0x2f4c1
movl 0x1c(%r13), %esi
movq %r12, %rdi
callq 0x2f4c1
movl 0x24(%r13), %esi
movq %r12, %rdi
callq 0x2f4c1
movl 0x14(%r13), %eax
testl %eax, %eax
jle 0x31a2a
movl 0x18(%r13), %ebx
movq -0x40(%rbp), %rcx
leal 0x1(%rcx), %r12d
movq %r13, -0x48(%rbp)
movq 0x30(%r13), %r14
movl %eax, %ecx
cmpq $0x0, -0x10(%r14,%rcx,8)
je 0x31956
orb $-0x80, -0x1(%r14,%rcx,8)
cmpq $0x0, -0x20(%r14,%rcx,8)
je 0x31a9b
movl %eax, -0x34(%rbp)
movq %rcx, %r13
movl -0x4(%r14,%rcx,8), %esi
movq %r15, %rdi
callq 0x2f4c1
movl -0x8(%r14,%r13,8), %esi
movq %r15, %rdi
callq 0x2f4c1
movq -0x20(%r14,%r13,8), %rax
movq -0x18(%r14,%r13,8), %rsi
movq 0x10(%rax), %rax
subq 0x28(%rax), %rsi
shrq $0x2, %rsi
movq %r15, %rdi
callq 0x2f4c1
movq -0x20(%r14,%r13,8), %rdi
movabsq $-0x2000000000000, %rsi # imm = 0xFFFE000000000000
callq 0x4ed7e
movq %r15, %rdi
movq %rax, %rsi
movl %r12d, %edx
callq 0x2f5b7
movq %r14, -0x50(%rbp)
movq %r13, -0x30(%rbp)
movq -0x10(%r14,%r13,8), %rsi
testq %rsi, %rsi
je 0x319df
movq %r15, %rdi
movl %r12d, %edx
callq 0x3166c
addl $-0x4, %ebx
cmpl %ebx, -0x30(%rbp)
movq %r15, %r13
movq -0x48(%rbp), %r14
jge 0x31a0d
movq -0x30(%rbp), %r15
movq 0x30(%r14), %rax
movq (%rax,%r15,8), %rsi
movq %r13, %rdi
movl %r12d, %edx
callq 0x2f5b7
incq %r15
cmpl %r15d, %ebx
jg 0x319f2
movq -0x50(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x8(%rax,%rcx,8), %eax
testl %eax, %eax
movq %r13, %r15
movq %r14, %r13
movl -0x34(%rbp), %ebx
jg 0x31942
movq 0x28(%r13), %rdi
testq %rdi, %rdi
movq -0x40(%rbp), %rbx
je 0x31a54
movabsq $-0x3800000000000, %rsi # imm = 0xFFFC800000000000
callq 0x4ed7e
leal 0x1(%rbx), %edx
movq %r15, %rdi
movq %rax, %rsi
callq 0x2f5b7
movq 0x38(%r13), %rdi
testq %rdi, %rdi
je 0x31a7d
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
callq 0x4ed7e
incl %ebx
movq %r15, %rdi
movq %rax, %rsi
movl %ebx, %edx
callq 0x2f5b7
jmp 0x31a7f
incl %ebx
movq 0x40(%r13), %rsi
movq %r15, %rdi
movl %ebx, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2f5b7
movq -0x18(%r14,%rcx,8), %rdi
movabsq $-0x1800000000000, %rsi # imm = 0xFFFE800000000000
callq 0x4ed7e
leaq 0x2e1d3(%rip), %rdi     # 0x5fc89
movq %rax, %rsi
xorl %eax, %eax
callq 0x190bb
leaq 0x2b42c(%rip), %rdi     # 0x5cef3
callq 0x191a3
leaq 0x2e19b(%rip), %rdi     # 0x5fc6e
callq 0x191a3