// File: /workspace/github_c_makefile_star2_O1/janet-lang[P]janet/src/core/marsh.c
// Function: marshal_one_def
static void marshal_one_def(MarshalState *st, JanetFuncDef *def, int flags) {
    MARSH_STACKCHECK;
    for (int32_t i = 0; i < janet_v_count(st->seen_defs); i++) {
        if (st->seen_defs[i] == def) {
            pushbyte(st, LB_FUNCDEF_REF);
            pushint(st, i);
            return;
        }
    }
    /* Add to lookup */
    janet_v_push(st->seen_defs, def);

    pushint(st, def->flags);
    pushint(st, def->slotcount);
    pushint(st, def->arity);
    pushint(st, def->min_arity);
    pushint(st, def->max_arity);
    pushint(st, def->constants_length);
    pushint(st, def->bytecode_length);
    if (def->flags & JANET_FUNCDEF_FLAG_HASENVS)
        pushint(st, def->environments_length);
    if (def->flags & JANET_FUNCDEF_FLAG_HASDEFS)
        pushint(st, def->defs_length);
    if (def->flags & JANET_FUNCDEF_FLAG_HASSYMBOLMAP)
        pushint(st, def->symbolmap_length);
    if (def->flags & JANET_FUNCDEF_FLAG_HASNAME)
        marshal_one(st, janet_wrap_string(def->name), flags);
    if (def->flags & JANET_FUNCDEF_FLAG_HASSOURCE)
        marshal_one(st, janet_wrap_string(def->source), flags);

    /* marshal constants */
    for (int32_t i = 0; i < def->constants_length; i++)
        marshal_one(st, def->constants[i], flags + 1);

    /* Marshal symbol map, if needed */
    for (int32_t i = 0; i < def->symbolmap_length; i++) {
        pushint(st, (int32_t) def->symbolmap[i].birth_pc);
        pushint(st, (int32_t) def->symbolmap[i].death_pc);
        pushint(st, (int32_t) def->symbolmap[i].slot_index);
        marshal_one(st, janet_wrap_symbol(def->symbolmap[i].symbol), flags + 1);
    }

    /* marshal the bytecode */
    janet_marshal_u32s(st, def->bytecode, def->bytecode_length);

    /* marshal the environments if needed */
    for (int32_t i = 0; i < def->environments_length; i++)
        pushint(st, def->environments[i]);

    /* marshal the sub funcdefs if needed */
    for (int32_t i = 0; i < def->defs_length; i++)
        marshal_one_def(st, def->defs[i], flags + 1);

    /* marshal source maps if needed */
    if (def->flags & JANET_FUNCDEF_FLAG_HASSOURCEMAP) {
        int32_t current = 0;
        for (int32_t i = 0; i < def->bytecode_length; i++) {
            JanetSourceMapping map = def->sourcemap[i];
            pushint(st, map.line - current);
            pushint(st, map.column);
            current = map.line;
        }
    }

    /* Marshal closure bitset, if needed */
    if (def->flags & JANET_FUNCDEF_FLAG_HASCLOBITSET) {
        janet_marshal_u32s(st, def->closure_bitset, ((def->slotcount + 31) >> 5));
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r13d
movzwl %r13w, %eax
cmpl $0x400, %eax            # imm = 0x400
ja 0x31c06
movq %rsi, %r14
movq %rdi, %rbx
movq 0x48(%rdi), %rax
xorl %r12d, %r12d
testq %rax, %rax
je 0x3192c
movslq -0x4(%rax), %r15
jmp 0x3192f
xorl %r15d, %r15d
cmpq %r15, %r12
jge 0x31960
cmpq %r14, (%rax,%r12,8)
je 0x3193f
incq %r12
jmp 0x31921
movq (%rbx), %rdi
movl $0xdc, %esi
callq 0x179a7
movq %rbx, %rdi
movl %r12d, %esi
callq 0x2fa79
cmpq %r15, %r12
jl 0x31bd3
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x31973
movl -0x4(%rdi), %eax
incl %eax
cmpl -0x8(%rdi), %eax
jl 0x31986
movl $0x1, %esi
movl $0x8, %edx
callq 0x4c0b4
movq %rax, 0x48(%rbx)
movq 0x48(%rbx), %rax
movslq -0x4(%rax), %rcx
leal 0x1(%rcx), %edx
movl %edx, -0x4(%rax)
movq %r14, (%rax,%rcx,8)
movl 0x58(%r14), %esi
movq %rbx, %rdi
callq 0x2fa79
movl 0x5c(%r14), %esi
movq %rbx, %rdi
callq 0x2fa79
movl 0x60(%r14), %esi
movq %rbx, %rdi
callq 0x2fa79
movl 0x64(%r14), %esi
movq %rbx, %rdi
callq 0x2fa79
movl 0x68(%r14), %esi
movq %rbx, %rdi
callq 0x2fa79
movl 0x6c(%r14), %esi
movq %rbx, %rdi
callq 0x2fa79
movl 0x70(%r14), %esi
movq %rbx, %rdi
callq 0x2fa79
testb $0x40, 0x5a(%r14)
je 0x319ff
movl 0x74(%r14), %esi
movq %rbx, %rdi
callq 0x2fa79
testb $0x20, 0x5a(%r14)
je 0x31a12
movl 0x78(%r14), %esi
movq %rbx, %rdi
callq 0x2fa79
testb $0x4, 0x5a(%r14)
je 0x31a25
movl 0x7c(%r14), %esi
movq %rbx, %rdi
callq 0x2fa79
movabsq $-0x6000000000000, %r12 # imm = 0xFFFA000000000000
testb $0x8, 0x5a(%r14)
je 0x31a50
movq 0x48(%r14), %rdi
movq %r12, %rsi
callq 0x4f9ad
movq %rbx, %rdi
movq %rax, %rsi
movl %r13d, %edx
callq 0x2fb6f
testb $0x10, 0x5a(%r14)
je 0x31a71
movq 0x40(%r14), %rdi
movq %r12, %rsi
callq 0x4f9ad
movq %rbx, %rdi
movq %rax, %rsi
movl %r13d, %edx
callq 0x2fb6f
cmpl $0x0, 0x6c(%r14)
jle 0x31a9e
leal 0x1(%r13), %r12d
xorl %r15d, %r15d
movq 0x18(%r14), %rax
movq (%rax,%r15,8), %rsi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x2fb6f
incq %r15
movslq 0x6c(%r14), %rax
cmpq %rax, %r15
jl 0x31a7f
movq %r13, -0x30(%rbp)
cmpl $0x0, 0x7c(%r14)
jle 0x31b1f
movq -0x30(%rbp), %rax
leal 0x1(%rax), %r12d
xorl %r15d, %r15d
xorl %r13d, %r13d
movq 0x50(%r14), %rax
movl (%rax,%r15), %esi
movq %rbx, %rdi
callq 0x2fa79
movq 0x50(%r14), %rax
movl 0x4(%rax,%r15), %esi
movq %rbx, %rdi
callq 0x2fa79
movq 0x50(%r14), %rax
movl 0x8(%rax,%r15), %esi
movq %rbx, %rdi
callq 0x2fa79
movq 0x50(%r14), %rax
movq 0x10(%rax,%r15), %rdi
movabsq $-0x5800000000000, %rsi # imm = 0xFFFA800000000000
callq 0x4f9ad
movq %rbx, %rdi
movq %rax, %rsi
movl %r12d, %edx
callq 0x2fb6f
incq %r13
movslq 0x7c(%r14), %rax
addq $0x18, %r15
cmpq %rax, %r13
jl 0x31ab7
movq 0x28(%r14), %rsi
movl 0x70(%r14), %edx
movq %rbx, %rdi
callq 0x3206b
cmpl $0x0, 0x74(%r14)
jle 0x31b55
xorl %r15d, %r15d
movq 0x10(%r14), %rax
movl (%rax,%r15,4), %esi
movq %rbx, %rdi
callq 0x2fa79
incq %r15
movslq 0x74(%r14), %rax
cmpq %rax, %r15
jl 0x31b39
cmpl $0x0, 0x78(%r14)
movq -0x30(%rbp), %r12
jle 0x31b85
incl %r12d
xorl %r15d, %r15d
movq 0x20(%r14), %rax
movq (%rax,%r15,8), %rsi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x318f4
incq %r15
movslq 0x78(%r14), %rax
cmpq %rax, %r15
jl 0x31b66
testb $-0x80, 0x5a(%r14)
je 0x31bcc
cmpl $0x0, 0x70(%r14)
jle 0x31bcc
xorl %r12d, %r12d
xorl %eax, %eax
movq 0x38(%r14), %rcx
movl (%rcx,%r12,8), %r13d
movl 0x4(%rcx,%r12,8), %r15d
movl %r13d, %esi
subl %eax, %esi
movq %rbx, %rdi
callq 0x2fa79
movq %rbx, %rdi
movl %r15d, %esi
callq 0x2fa79
incq %r12
movslq 0x70(%r14), %rcx
movl %r13d, %eax
cmpq %rcx, %r12
jl 0x31b98
testb $0x2, 0x5b(%r14)
jne 0x31be2
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%r14), %rsi
movl 0x5c(%r14), %edx
addl $0x1f, %edx
sarl $0x5, %edx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3206b
leaq 0x2c2e6(%rip), %rdi     # 0x5def3
callq 0x19263