// File: /workspace/github_c_makefile_star2_O3/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 0x31660
movq %rsi, %r14
movq %rdi, %rbx
movq 0x48(%rdi), %rax
testq %rax, %rax
je 0x3138d
movslq -0x4(%rax), %rcx
xorl %r12d, %r12d
cmpq %rcx, %r12
jge 0x31382
cmpq %r14, (%rax,%r12,8)
je 0x3163a
incq %r12
testq %rax, %rax
jne 0x31369
jmp 0x3138d
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
cmpl -0x8(%rax), %edx
jl 0x313a9
movq %rax, %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0x4b4e8
movq %rax, 0x48(%rbx)
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
movl %edx, -0x4(%rax)
movslq %ecx, %rcx
movq %r14, (%rax,%rcx,8)
movl 0x58(%r14), %esi
movq %rbx, %rdi
callq 0x2f4c1
movl 0x5c(%r14), %esi
movq %rbx, %rdi
callq 0x2f4c1
movl 0x60(%r14), %esi
movq %rbx, %rdi
callq 0x2f4c1
movl 0x64(%r14), %esi
movq %rbx, %rdi
callq 0x2f4c1
movl 0x68(%r14), %esi
movq %rbx, %rdi
callq 0x2f4c1
movl 0x6c(%r14), %esi
movq %rbx, %rdi
callq 0x2f4c1
movl 0x70(%r14), %esi
movq %rbx, %rdi
callq 0x2f4c1
movl 0x58(%r14), %eax
btl $0x16, %eax
jae 0x31421
movl 0x74(%r14), %esi
movq %rbx, %rdi
callq 0x2f4c1
movl 0x58(%r14), %eax
btl $0x15, %eax
jae 0x31437
movl 0x78(%r14), %esi
movq %rbx, %rdi
callq 0x2f4c1
movl 0x58(%r14), %eax
btl $0x12, %eax
jae 0x3144d
movl 0x7c(%r14), %esi
movq %rbx, %rdi
callq 0x2f4c1
movl 0x58(%r14), %eax
btl $0x13, %eax
jae 0x31478
movq 0x48(%r14), %rdi
movabsq $-0x6000000000000, %rsi # imm = 0xFFFA000000000000
callq 0x4ed39
movq %rbx, %rdi
movq %rax, %rsi
movl %r13d, %edx
callq 0x2f5b7
movl 0x58(%r14), %eax
btl $0x14, %eax
jae 0x3149f
movq 0x40(%r14), %rdi
movabsq $-0x6000000000000, %rsi # imm = 0xFFFA000000000000
callq 0x4ed39
movq %rbx, %rdi
movq %rax, %rsi
movl %r13d, %edx
callq 0x2f5b7
cmpl $0x0, 0x6c(%r14)
jle 0x314cc
leal 0x1(%r13), %r12d
xorl %r15d, %r15d
movq 0x18(%r14), %rax
movq (%rax,%r15,8), %rsi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x2f5b7
incq %r15
movslq 0x6c(%r14), %rax
cmpq %rax, %r15
jl 0x314ad
movq %r13, -0x30(%rbp)
cmpl $0x0, 0x7c(%r14)
jle 0x3154d
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 0x2f4c1
movq 0x50(%r14), %rax
movl 0x4(%rax,%r15), %esi
movq %rbx, %rdi
callq 0x2f4c1
movq 0x50(%r14), %rax
movl 0x8(%rax,%r15), %esi
movq %rbx, %rdi
callq 0x2f4c1
movq 0x50(%r14), %rax
movq 0x10(%rax,%r15), %rdi
movabsq $-0x5800000000000, %rsi # imm = 0xFFFA800000000000
callq 0x4ed39
movq %rbx, %rdi
movq %rax, %rsi
movl %r12d, %edx
callq 0x2f5b7
incq %r13
movslq 0x7c(%r14), %rax
addq $0x18, %r15
cmpq %rax, %r13
jl 0x314e5
movq 0x28(%r14), %rsi
movl 0x70(%r14), %edx
movq %rbx, %rdi
callq 0x31ad8
cmpl $0x0, 0x74(%r14)
jle 0x31583
xorl %r15d, %r15d
movq 0x10(%r14), %rax
movl (%rax,%r15,4), %esi
movq %rbx, %rdi
callq 0x2f4c1
incq %r15
movslq 0x74(%r14), %rax
cmpq %rax, %r15
jl 0x31567
cmpl $0x0, 0x78(%r14)
movq -0x30(%rbp), %r12
jle 0x315b3
incl %r12d
xorl %r15d, %r15d
movq 0x20(%r14), %rax
movq (%rax,%r15,8), %rsi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x31333
incq %r15
movslq 0x78(%r14), %rax
cmpq %rax, %r15
jl 0x31594
movl 0x58(%r14), %eax
btl $0x17, %eax
jae 0x31601
cmpl $0x0, 0x70(%r14)
jle 0x31601
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 0x2f4c1
movq %rbx, %rdi
movl %r15d, %esi
callq 0x2f4c1
incq %r12
movslq 0x70(%r14), %rcx
movl %r13d, %eax
cmpq %rcx, %r12
jl 0x315c9
movl 0x58(%r14), %eax
btl $0x19, %eax
jb 0x31616
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 0x31ad8
movq (%rbx), %rdi
movl $0xdc, %esi
callq 0x17947
movq %rbx, %rdi
movl %r12d, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2f4c1
leaq 0x2b88c(%rip), %rdi     # 0x5cef3
callq 0x191a3