// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/marsh.c
// Function: unmarshal_one_fiber
static const uint8_t *unmarshal_one_fiber(
    UnmarshalState *st,
    const uint8_t *data,
    JanetFiber **out,
    int flags) {

    /* Initialize a new fiber with gc friendly defaults */
    JanetFiber *fiber = janet_gcalloc(JANET_MEMORY_FIBER, sizeof(JanetFiber));
    fiber->flags = 0;
    fiber->frame = 0;
    fiber->stackstart = 0;
    fiber->stacktop = 0;
    fiber->capacity = 0;
    fiber->maxstack = 0;
    fiber->data = NULL;
    fiber->child = NULL;
    fiber->env = NULL;
    fiber->last_value = janet_wrap_nil();
#ifdef JANET_EV
    fiber->sched_id = 0;
    fiber->supervisor_channel = NULL;
    fiber->ev_state = NULL;
    fiber->ev_callback = NULL;
    fiber->ev_stream = NULL;
#endif

    /* Push fiber to seen stack */
    janet_v_push(st->lookup, janet_wrap_fiber(fiber));

    /* Read ints */
    int32_t fiber_flags = readint(st, &data);
    int32_t frame = readnat(st, &data);
    int32_t fiber_stackstart = readnat(st, &data);
    int32_t fiber_stacktop = readnat(st, &data);
    int32_t fiber_maxstack = readnat(st, &data);
    JanetTable *fiber_env = NULL;

    /* Check for bad flags and ints */
    if ((int32_t)(frame + JANET_FRAME_SIZE) > fiber_stackstart ||
            fiber_stackstart > fiber_stacktop ||
            fiber_stacktop > fiber_maxstack) {
        janet_panic("fiber has incorrect stack setup");
    }

    /* Allocate stack memory */
    fiber->capacity = fiber_stacktop + 10;
    fiber->data = janet_malloc(sizeof(Janet) * fiber->capacity);
    if (!fiber->data) {
        JANET_OUT_OF_MEMORY;
    }
    for (int32_t i = 0; i < fiber->capacity; i++) {
        fiber->data[i] = janet_wrap_nil();
    }

    /* get frames */
    int32_t stack = frame;
    int32_t stacktop = fiber_stackstart - JANET_FRAME_SIZE;
    while (stack > 0) {
        JanetFunction *func = NULL;
        JanetFuncDef *def = NULL;
        JanetFuncEnv *env = NULL;
        int32_t frameflags = readint(st, &data);
        int32_t prevframe = readnat(st, &data);
        int32_t pcdiff = readnat(st, &data);

        /* Get frame items */
        Janet *framestack = fiber->data + stack;
        JanetStackFrame *framep = janet_stack_frame(framestack);

        /* Get function */
        Janet funcv;
        data = unmarshal_one(st, data, &funcv, flags + 1);
        janet_asserttype(funcv, JANET_FUNCTION, st);
        func = janet_unwrap_function(funcv);
        def = func->def;

        /* Check env */
        if (frameflags & JANET_STACKFRAME_HASENV) {
            frameflags &= ~JANET_STACKFRAME_HASENV;
            data = unmarshal_one_env(st, data, &env, flags + 1);
        }

        /* Error checking */
        int32_t expected_framesize = def->slotcount;
        if (expected_framesize != stacktop - stack) {
            janet_panic("fiber stackframe size mismatch");
        }
        if (pcdiff >= def->bytecode_length) {
            janet_panic("fiber stackframe has invalid pc");
        }
        if ((int32_t)(prevframe + JANET_FRAME_SIZE) > stack) {
            janet_panic("fiber stackframe does not align with previous frame");
        }

        /* Get stack items */
        for (int32_t i = stack; i < stacktop; i++)
            data = unmarshal_one(st, data, fiber->data + i, flags + 1);

        /* Set frame */
        framep->env = env;
        framep->pc = def->bytecode + pcdiff;
        framep->prevframe = prevframe;
        framep->flags = frameflags;
        framep->func = func;

        /* Goto previous frame */
        stacktop = stack - JANET_FRAME_SIZE;
        stack = prevframe;
    }
    if (stack < 0) {
        janet_panic("fiber has too many stackframes");
    }

    /* Check for fiber env */
    if (fiber_flags & JANET_FIBER_FLAG_HASENV) {
        Janet envv;
        fiber_flags &= ~JANET_FIBER_FLAG_HASENV;
        data = unmarshal_one(st, data, &envv, flags + 1);
        janet_asserttype(envv, JANET_TABLE, st);
        fiber_env = janet_unwrap_table(envv);
    }

    /* Check for child fiber */
    if (fiber_flags & JANET_FIBER_FLAG_HASCHILD) {
        Janet fiberv;
        fiber_flags &= ~JANET_FIBER_FLAG_HASCHILD;
        data = unmarshal_one(st, data, &fiberv, flags + 1);
        janet_asserttype(fiberv, JANET_FIBER, st);
        fiber->child = janet_unwrap_fiber(fiberv);
    }

    /* Get the fiber last value */
    data = unmarshal_one(st, data, &fiber->last_value, flags + 1);

    /* We have valid fiber, finally construct remaining fields. */
    fiber->frame = frame;
    fiber->flags = fiber_flags;
    fiber->stackstart = fiber_stackstart;
    fiber->stacktop = fiber_stacktop;
    fiber->maxstack = fiber_maxstack;
    fiber->env = fiber_env;

    int status = janet_fiber_status(fiber);
    if (status < 0 || status > JANET_STATUS_ALIVE) {
        janet_panic("invalid fiber status");
    }

    /* Return data */
    *out = fiber;
    return data;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0x7, %edi
movl $0x70, %esi
callq 0x39e40
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x20(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x24(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0xd8(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq %rax, %rcx
movq -0xd8(%rbp), %rax
movq %rcx, -0x30(%rbp)
movq -0x30(%rbp), %rcx
movq %rcx, 0x40(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x48(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x68(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x58(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0xc8(%rax)
je 0x4491d
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
movl -0x4(%rax), %eax
addl $0x1, %eax
movq -0x8(%rbp), %rcx
movq 0xc8(%rcx), %rcx
cmpl -0x8(%rcx), %eax
jl 0x44947
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0x70760
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xc8(%rax)
jmp 0x44949
jmp 0x44949
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0x8(%rbp), %rax
movq 0xc8(%rax), %rcx
movl -0x4(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x4(%rcx)
cltq
movq %rax, -0xe8(%rbp)
movq -0x28(%rbp), %rdi
movabsq $-0x6800000000000, %rsi # imm = 0xFFF9800000000000
callq 0x7b610
movq -0xe8(%rbp), %rcx
movq %rax, %rdx
movq -0xe0(%rbp), %rax
movq %rdx, -0x38(%rbp)
movq -0x38(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x418c0
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x447b0
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x447b0
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x447b0
movl %eax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x447b0
movl %eax, -0x4c(%rbp)
movq $0x0, -0x58(%rbp)
movl -0x40(%rbp), %eax
addl $0x4, %eax
cmpl -0x44(%rbp), %eax
jg 0x44a1d
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jg 0x44a1d
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jle 0x44a29
leaq 0x48488(%rip), %rdi     # 0x8ceac
callq 0x1ad60
movl -0x48(%rbp), %ecx
addl $0xa, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x28(%rbp), %rax
movslq 0x20(%rax), %rdi
shlq $0x3, %rdi
callq 0x12770
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x44a8d
jmp 0x44a5f
movq 0x6b58a(%rip), %rax     # 0xafff0
movq (%rax), %rdi
leaq 0x39594(%rip), %rsi     # 0x7e004
leaq 0x48209(%rip), %rdx     # 0x8cc80
movl $0x458, %ecx            # imm = 0x458
movb $0x0, %al
callq 0x125f0
movl $0x1, %edi
callq 0x12a70
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x44af1
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0xf0(%rbp)
movslq -0x5c(%rbp), %rax
movq %rax, -0xf8(%rbp)
movabsq $-0x77fffffffffff, %rdi # imm = 0xFFF8800000000001
callq 0x7b460
movq -0xf8(%rbp), %rcx
movq %rax, %rdx
movq -0xf0(%rbp), %rax
movq %rdx, -0x68(%rbp)
movq -0x68(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x44a94
movl -0x40(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x44(%rbp), %eax
subl $0x4, %eax
movl %eax, -0x70(%rbp)
cmpl $0x0, -0x6c(%rbp)
jle 0x44d40
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x418c0
movl %eax, -0x8c(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x447b0
movl %eax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
callq 0x447b0
movl %eax, -0x94(%rbp)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x6c(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
addq $-0x20, %rax
movq %rax, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
leaq -0xb0(%rbp), %rdx
callq 0x41d80
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdx
movq -0xb0(%rbp), %rdi
movl $0xc, %esi
callq 0x45cb0
movq -0xb0(%rbp), %rdi
callq 0x7b260
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x80(%rbp)
movl -0x8c(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
je 0x44c18
movl -0x8c(%rbp), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x8c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
leaq -0x88(%rbp), %rdx
callq 0x458a0
movq %rax, -0x10(%rbp)
movq -0x80(%rbp), %rax
movl 0x5c(%rax), %eax
movl %eax, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
movl -0x70(%rbp), %ecx
subl -0x6c(%rbp), %ecx
cmpl %ecx, %eax
je 0x44c41
leaq 0x48290(%rip), %rdi     # 0x8cecc
callq 0x1ad60
movl -0x94(%rbp), %eax
movq -0x80(%rbp), %rcx
cmpl 0x70(%rcx), %eax
jl 0x44c5c
leaq 0x48294(%rip), %rdi     # 0x8ceeb
callq 0x1ad60
movl -0x90(%rbp), %eax
addl $0x4, %eax
cmpl -0x6c(%rbp), %eax
jle 0x44c76
leaq 0x4829a(%rip), %rdi     # 0x8cf0b
callq 0x1ad60
movl -0x6c(%rbp), %eax
movl %eax, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
cmpl -0x70(%rbp), %eax
jge 0x44cc8
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rdx
movslq -0xb8(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdx
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
callq 0x41d80
movq %rax, -0x10(%rbp)
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x44c7f
movq -0x88(%rbp), %rcx
movq -0xa8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x80(%rbp), %rax
movq 0x28(%rax), %rcx
movslq -0x94(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rcx
movq -0xa8(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x90(%rbp), %ecx
movq -0xa8(%rbp), %rax
movl %ecx, 0x18(%rax)
movl -0x8c(%rbp), %ecx
movq -0xa8(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x78(%rbp), %rcx
movq -0xa8(%rbp), %rax
movq %rcx, (%rax)
movl -0x6c(%rbp), %eax
subl $0x4, %eax
movl %eax, -0x70(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x44b00
cmpl $0x0, -0x6c(%rbp)
jge 0x44d52
leaq 0x481f2(%rip), %rdi     # 0x8cf3f
callq 0x1ad60
movl -0x3c(%rbp), %eax
andl $0x40000000, %eax       # imm = 0x40000000
cmpl $0x0, %eax
je 0x44dad
movl -0x3c(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
leaq -0xc0(%rbp), %rdx
callq 0x41d80
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdx
movq -0xc0(%rbp), %rdi
movl $0x9, %esi
callq 0x45cb0
movq -0xc0(%rbp), %rdi
callq 0x7b260
movq %rax, -0x58(%rbp)
movl -0x3c(%rbp), %eax
andl $0x20000000, %eax       # imm = 0x20000000
cmpl $0x0, %eax
je 0x44e0f
movl -0x3c(%rbp), %eax
andl $0xdfffffff, %eax       # imm = 0xDFFFFFFF
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
leaq -0xc8(%rbp), %rdx
callq 0x41d80
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdx
movq -0xc8(%rbp), %rdi
movl $0x3, %esi
callq 0x45cb0
movq -0xc8(%rbp), %rdi
callq 0x7b260
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
addq $0x40, %rdx
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
callq 0x41d80
movq %rax, -0x10(%rbp)
movl -0x40(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x3c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x44(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x18(%rax)
movl -0x48(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl -0x4c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x58(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rdi
callq 0x36a40
movl %eax, -0xcc(%rbp)
cmpl $0x0, -0xcc(%rbp)
jl 0x44e8d
cmpl $0xf, -0xcc(%rbp)
jle 0x44e99
leaq 0x480ca(%rip), %rdi     # 0x8cf5e
callq 0x1ad60
movq -0x28(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw %cs:(%rax,%rax)