// File: /workspace/github_c_makefile_star2_O2/janet-lang[P]janet/src/core/marsh.c
// Function: unmarshal_one_def
static const uint8_t *unmarshal_one_def(
    UnmarshalState *st,
    const uint8_t *data,
    JanetFuncDef **out,
    int flags) {
    MARSH_EOS(st, data);
    if (*data == LB_FUNCDEF_REF) {
        data++;
        int32_t index = readint(st, &data);
        if (index < 0 || index >= janet_v_count(st->lookup_defs))
            janet_panicf("invalid funcdef reference %d", index);
        *out = st->lookup_defs[index];
    } else {
        /* Initialize with values that will not break garbage collection
         * if unmarshalling fails. */
        JanetFuncDef *def = janet_gcalloc(JANET_MEMORY_FUNCDEF, sizeof(JanetFuncDef));
        def->environments_length = 0;
        def->defs_length = 0;
        def->constants_length = 0;
        def->bytecode_length = 0;
        def->name = NULL;
        def->source = NULL;
        def->closure_bitset = NULL;
        def->defs = NULL;
        def->environments = NULL;
        def->constants = NULL;
        def->bytecode = NULL;
        def->sourcemap = NULL;
        def->symbolmap = NULL;
        def->symbolmap_length = 0;
        janet_v_push(st->lookup_defs, def);

        /* Set default lengths to zero */
        int32_t bytecode_length = 0;
        int32_t constants_length = 0;
        int32_t environments_length = 0;
        int32_t defs_length = 0;
        int32_t symbolmap_length = 0;

        /* Read flags and other fixed values */
        def->flags = readint(st, &data);
        def->slotcount = readnat(st, &data);
        def->arity = readnat(st, &data);
        def->min_arity = readnat(st, &data);
        def->max_arity = readnat(st, &data);

        /* Read some lengths */
        constants_length = readnat(st, &data);
        bytecode_length = readnat(st, &data);
        if (def->flags & JANET_FUNCDEF_FLAG_HASENVS)
            environments_length = readnat(st, &data);
        if (def->flags & JANET_FUNCDEF_FLAG_HASDEFS)
            defs_length = readnat(st, &data);
        if (def->flags & JANET_FUNCDEF_FLAG_HASSYMBOLMAP)
            symbolmap_length = readnat(st, &data);

        /* Check name and source (optional) */
        if (def->flags & JANET_FUNCDEF_FLAG_HASNAME) {
            Janet x;
            data = unmarshal_one(st, data, &x, flags + 1);
            janet_asserttype(x, JANET_STRING, st);
            def->name = janet_unwrap_string(x);
        }
        if (def->flags & JANET_FUNCDEF_FLAG_HASSOURCE) {
            Janet x;
            data = unmarshal_one(st, data, &x, flags + 1);
            janet_asserttype(x, JANET_STRING, st);
            def->source = janet_unwrap_string(x);
        }

        /* Unmarshal constants */
        if (constants_length) {
            def->constants = janet_malloc(sizeof(Janet) * constants_length);
            if (!def->constants) {
                JANET_OUT_OF_MEMORY;
            }
            for (int32_t i = 0; i < constants_length; i++)
                data = unmarshal_one(st, data, def->constants + i, flags + 1);
        } else {
            def->constants = NULL;
        }
        def->constants_length = constants_length;

        /* Unmarshal symbol map, if needed */
        if (def->flags & JANET_FUNCDEF_FLAG_HASSYMBOLMAP) {
            size_t size = sizeof(JanetSymbolMap) * symbolmap_length;
            def->symbolmap = janet_malloc(size);
            if (def->symbolmap == NULL) {
                JANET_OUT_OF_MEMORY;
            }
            for (int32_t i = 0; i < symbolmap_length; i++) {
                def->symbolmap[i].birth_pc = (uint32_t) readint(st, &data);
                def->symbolmap[i].death_pc = (uint32_t) readint(st, &data);
                def->symbolmap[i].slot_index = (uint32_t) readint(st, &data);
                Janet value;
                data = unmarshal_one(st, data, &value, flags + 1);
                if (!janet_checktype(value, JANET_SYMBOL)) {
                    janet_panicf("corrupted symbolmap when unmarshalling debug info, got %v", value);
                }
                def->symbolmap[i].symbol = janet_unwrap_symbol(value);
            }
            def->symbolmap_length = (uint32_t) symbolmap_length;
        }

        /* Unmarshal bytecode */
        def->bytecode = janet_malloc(sizeof(uint32_t) * bytecode_length);
        if (!def->bytecode) {
            JANET_OUT_OF_MEMORY;
        }
        data = janet_unmarshal_u32s(st, data, def->bytecode, bytecode_length);
        def->bytecode_length = bytecode_length;

        /* Unmarshal environments */
        if (def->flags & JANET_FUNCDEF_FLAG_HASENVS) {
            def->environments = janet_calloc(1, sizeof(int32_t) * (size_t) environments_length);
            if (!def->environments) {
                JANET_OUT_OF_MEMORY;
            }
            for (int32_t i = 0; i < environments_length; i++) {
                def->environments[i] = readint(st, &data);
            }
        } else {
            def->environments = NULL;
        }
        def->environments_length = environments_length;

        /* Unmarshal sub funcdefs */
        if (def->flags & JANET_FUNCDEF_FLAG_HASDEFS) {
            def->defs = janet_calloc(1, sizeof(JanetFuncDef *) * (size_t) defs_length);
            if (!def->defs) {
                JANET_OUT_OF_MEMORY;
            }
            for (int32_t i = 0; i < defs_length; i++) {
                data = unmarshal_one_def(st, data, def->defs + i, flags + 1);
            }
        } else {
            def->defs = NULL;
        }
        def->defs_length = defs_length;

        /* Unmarshal source maps if needed */
        if (def->flags & JANET_FUNCDEF_FLAG_HASSOURCEMAP) {
            int32_t current = 0;
            def->sourcemap = janet_malloc(sizeof(JanetSourceMapping) * (size_t) bytecode_length);
            if (!def->sourcemap) {
                JANET_OUT_OF_MEMORY;
            }
            for (int32_t i = 0; i < bytecode_length; i++) {
                current += readint(st, &data);
                def->sourcemap[i].line = current;
                def->sourcemap[i].column = readint(st, &data);
            }
        } else {
            def->sourcemap = NULL;
        }

        /* Unmarshal closure bitset if needed */
        if (def->flags & JANET_FUNCDEF_FLAG_HASCLOBITSET) {
            int32_t n = (def->slotcount + 31) >> 5;
            def->closure_bitset = janet_malloc(sizeof(uint32_t) * (size_t) n);
            if (NULL == def->closure_bitset) {
                JANET_OUT_OF_MEMORY;
            }
            data = janet_unmarshal_u32s(st, data, def->closure_bitset, n);
        }

        /* Validate */
        if (janet_verify(def))
            janet_panic("funcdef has invalid bytecode");

        /* Set def */
        *out = def;
    }
    return data;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, -0x30(%rbp)
cmpq %rsi, 0xf0(%rdi)
jbe 0x2fbb0
movq %rdi, %r14
cmpb $-0x24, (%rsi)
movq %rdx, -0x68(%rbp)
jne 0x2f6da
incq %rsi
leaq -0x30(%rbp), %rax
movq %rsi, (%rax)
movq %r14, %rdi
movq %rax, %rsi
callq 0x2da62
testl %eax, %eax
js 0x2fba0
movq 0xe0(%r14), %rcx
testq %rcx, %rcx
je 0x2fba0
cmpl -0x4(%rcx), %eax
jge 0x2fba0
movl %eax, %eax
movq (%rcx,%rax,8), %r15
jmp 0x2fb78
movl %ecx, %ebx
pushq $0xc
popq %rdi
movl $0x80, %esi
callq 0x291a0
movq %rax, %r15
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
andq $0x0, 0x50(%rax)
movups %xmm0, 0x40(%rax)
andl $0x0, 0x7c(%rax)
movups %xmm0, 0x6c(%rax)
movq 0xe0(%r14), %rax
testq %rax, %rax
je 0x2f723
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
cmpl -0x8(%rax), %edx
jl 0x2f73e
pushq $0x1
popq %rsi
pushq $0x8
popq %rdx
movq %rax, %rdi
callq 0x4799c
movq %rax, 0xe0(%r14)
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
movl %edx, -0x4(%rax)
movslq %ecx, %rcx
movq %r15, (%rax,%rcx,8)
leaq -0x30(%rbp), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x2da62
movl %eax, 0x58(%r15)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2f64c
movl %eax, 0x5c(%r15)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2f64c
movl %eax, 0x60(%r15)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2f64c
movl %eax, 0x64(%r15)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2f64c
movl %eax, 0x68(%r15)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2f64c
movl %eax, -0x38(%rbp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2f64c
movl %eax, -0x54(%rbp)
movl 0x58(%r15), %ecx
movl $0x0, -0x40(%rbp)
btl $0x16, %ecx
movl $0x0, %eax
jae 0x2f7d9
leaq -0x30(%rbp), %rsi
movq %r14, %rdi
callq 0x2f64c
movl 0x58(%r15), %ecx
movl %eax, -0x3c(%rbp)
btl $0x15, %ecx
jae 0x2f7f5
leaq -0x30(%rbp), %rsi
movq %r14, %rdi
callq 0x2f64c
movl %eax, -0x40(%rbp)
movl 0x58(%r15), %ecx
xorl %r13d, %r13d
btl $0x12, %ecx
jae 0x2f811
leaq -0x30(%rbp), %rsi
movq %r14, %rdi
callq 0x2f64c
movl %eax, %r13d
movl 0x58(%r15), %ecx
btl $0x13, %ecx
jae 0x2f850
movq -0x30(%rbp), %rsi
leal 0x1(%rbx), %ecx
leaq -0x50(%rbp), %r12
movq %r14, %rdi
movq %r12, %rdx
callq 0x2dc5b
movq %rax, -0x30(%rbp)
movq (%r12), %r12
pushq $0x4
popq %rsi
movq %r12, %rdi
callq 0x2feb7
movq %r12, %rdi
callq 0x4b1f1
movq %rax, 0x48(%r15)
movl 0x58(%r15), %ecx
btl $0x14, %ecx
jae 0x2f88b
movq -0x30(%rbp), %rsi
leal 0x1(%rbx), %ecx
leaq -0x50(%rbp), %r12
movq %r14, %rdi
movq %r12, %rdx
callq 0x2dc5b
movq %rax, -0x30(%rbp)
movq (%r12), %r12
pushq $0x4
popq %rsi
movq %r12, %rdi
callq 0x2feb7
movq %r12, %rdi
callq 0x4b1f1
movq %rax, 0x40(%r15)
movl -0x38(%rbp), %eax
testl %eax, %eax
movq %rbx, -0x60(%rbp)
movl %r13d, -0x44(%rbp)
je 0x2f8f1
movl %eax, %r12d
shlq $0x3, %r12
movq %r12, %rdi
callq 0x12760
movq %rax, 0x18(%r15)
testq %rax, %rax
je 0x2fbea
leal 0x1(%rbx), %r13d
movq -0x30(%rbp), %rax
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0x2f8e0
movq 0x18(%r15), %rdx
addq %rbx, %rdx
movq %r14, %rdi
movq %rax, %rsi
movl %r13d, %ecx
callq 0x2dc5b
addq $0x8, %rbx
jmp 0x2f8c0
movq %rax, -0x30(%rbp)
movq -0x60(%rbp), %rbx
movl -0x44(%rbp), %r13d
movl -0x38(%rbp), %eax
jmp 0x2f8f6
andq $0x0, 0x18(%r15)
movl %eax, 0x6c(%r15)
testb $0x4, 0x5a(%r15)
je 0x2f9b8
movl %r13d, %eax
imulq $0x18, %rax, %rdi
movq %rdi, -0x38(%rbp)
callq 0x12760
movq %rax, 0x50(%r15)
testq %rax, %rax
je 0x2fc0c
leal 0x1(%rbx), %r13d
xorl %ebx, %ebx
leaq -0x30(%rbp), %r12
cmpq %rbx, -0x38(%rbp)
je 0x2f9b1
movq %r14, %rdi
movq %r12, %rsi
callq 0x2da62
movq 0x50(%r15), %rcx
movl %eax, (%rcx,%rbx)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2da62
movq 0x50(%r15), %rcx
movl %eax, 0x4(%rcx,%rbx)
movq %r14, %rdi
movq %r12, %rsi
callq 0x2da62
movq 0x50(%r15), %rcx
movl %eax, 0x8(%rcx,%rbx)
movq -0x30(%rbp), %rsi
movq %r14, %rdi
leaq -0x50(%rbp), %rdx
movl %r13d, %ecx
callq 0x2dc5b
movq %rax, -0x30(%rbp)
movq -0x50(%rbp), %rsi
movq %rsi, %rax
shrq $0x2f, %rax
cmpl $0x1fff5, %eax          # imm = 0x1FFF5
jne 0x2fb92
movq %rsi, %rdi
callq 0x4b1f1
movq 0x50(%r15), %rcx
movq %rax, 0x10(%rcx,%rbx)
addq $0x18, %rbx
jmp 0x2f92c
movl -0x44(%rbp), %eax
movl %eax, 0x7c(%r15)
movl -0x54(%rbp), %ebx
movl %ebx, %eax
movq %rax, -0x38(%rbp)
leaq (,%rax,4), %rdi
callq 0x12760
movq %rax, 0x28(%r15)
testq %rax, %rax
je 0x2fbbc
movq %r15, %r13
addq $0x10, %r13
movq -0x30(%rbp), %rsi
movq %r14, %rdi
movq %rax, %rdx
movl %ebx, %ecx
callq 0x2fef4
movq %rax, -0x30(%rbp)
movl %ebx, 0x70(%r15)
movl 0x58(%r15), %eax
btl $0x16, %eax
jb 0x2fa0c
andq $0x0, (%r13)
jmp 0x2fa50
movl -0x3c(%rbp), %r12d
leaq (,%r12,4), %rsi
pushq $0x1
popq %rdi
callq 0x125a0
movq %rax, (%r13)
testq %rax, %rax
je 0x2fc2b
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0x2fa4c
movq %r14, %rdi
leaq -0x30(%rbp), %rsi
callq 0x2da62
movq (%r13), %rcx
movl %eax, (%rcx,%rbx,4)
incq %rbx
jmp 0x2fa2f
movl 0x58(%r15), %eax
movl -0x3c(%rbp), %ecx
movl %ecx, 0x74(%r15)
btl $0x15, %eax
movq -0x60(%rbp), %r13
jb 0x2fa68
andq $0x0, 0x20(%r15)
jmp 0x2fab9
movl -0x40(%rbp), %ebx
shlq $0x3, %rbx
pushq $0x1
popq %rdi
movq %rbx, %rsi
callq 0x125a0
movq %rax, 0x20(%r15)
testq %rax, %rax
je 0x2fc4a
movq -0x30(%rbp), %rax
incl %r13d
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x2fab1
movq 0x20(%r15), %rdx
addq %r12, %rdx
movq %r14, %rdi
movq %rax, %rsi
movl %r13d, %ecx
callq 0x2f66b
addq $0x8, %r12
jmp 0x2fa91
movq %rax, -0x30(%rbp)
movl 0x58(%r15), %eax
movl -0x40(%rbp), %ecx
movl %ecx, 0x78(%r15)
btl $0x17, %eax
jb 0x2facd
andq $0x0, 0x38(%r15)
jmp 0x2fb2e
movq -0x38(%rbp), %rax
leaq (,%rax,8), %rdi
callq 0x12760
movq %rax, 0x38(%r15)
testq %rax, %rax
je 0x2fc69
xorl %r12d, %r12d
leaq -0x30(%rbp), %rbx
xorl %r13d, %r13d
cmpq %r12, -0x38(%rbp)
je 0x2fb2a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2da62
addl %eax, %r13d
movq 0x38(%r15), %rax
movl %r13d, (%rax,%r12,8)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2da62
movq 0x38(%r15), %rcx
movl %eax, 0x4(%rcx,%r12,8)
incq %r12
jmp 0x2faf5
movl 0x58(%r15), %eax
btl $0x19, %eax
jae 0x2fb6c
movl 0x5c(%r15), %ebx
addl $0x1f, %ebx
sarl $0x5, %ebx
movslq %ebx, %rdi
shlq $0x2, %rdi
callq 0x12760
movq %rax, 0x30(%r15)
testq %rax, %rax
je 0x2fc88
movq -0x30(%rbp), %rsi
movq %r14, %rdi
movq %rax, %rdx
movl %ebx, %ecx
callq 0x2fef4
movq %rax, -0x30(%rbp)
movq %r15, %rdi
callq 0x1738f
testl %eax, %eax
jne 0x2fbde
movq -0x68(%rbp), %rax
movq %r15, (%rax)
movq -0x30(%rbp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2c378(%rip), %rdi     # 0x5bf11
xorl %eax, %eax
callq 0x176c9
leaq 0x2c34d(%rip), %rdi     # 0x5bef4
movl %eax, %esi
xorl %eax, %eax
callq 0x176c9
leaq 0x2bfd5(%rip), %rdi     # 0x5bb8c
callq 0x177b1
movq 0x5042d(%rip), %rax     # 0x7fff0
movq (%rax), %rdi
leaq 0x1d437(%rip), %rsi     # 0x4d004
leaq 0x2c04c(%rip), %rdx     # 0x5bc20
movl $0x3e2, %ecx            # imm = 0x3E2
jmp 0x2fca5
leaq 0x2c366(%rip), %rdi     # 0x5bf4b
callq 0x177b1
movq 0x503ff(%rip), %rax     # 0x7fff0
movq (%rax), %rdi
leaq 0x1d409(%rip), %rsi     # 0x4d004
leaq 0x2c01e(%rip), %rdx     # 0x5bc20
movl $0x3c1, %ecx            # imm = 0x3C1
jmp 0x2fca5
movq 0x503dd(%rip), %rax     # 0x7fff0
movq (%rax), %rdi
leaq 0x1d3e7(%rip), %rsi     # 0x4d004
leaq 0x2bffc(%rip), %rdx     # 0x5bc20
movl $0x3cf, %ecx            # imm = 0x3CF
jmp 0x2fca5
movq 0x503be(%rip), %rax     # 0x7fff0
movq (%rax), %rdi
leaq 0x1d3c8(%rip), %rsi     # 0x4d004
leaq 0x2bfdd(%rip), %rdx     # 0x5bc20
movl $0x3eb, %ecx            # imm = 0x3EB
jmp 0x2fca5
movq 0x5039f(%rip), %rax     # 0x7fff0
movq (%rax), %rdi
leaq 0x1d3a9(%rip), %rsi     # 0x4d004
leaq 0x2bfbe(%rip), %rdx     # 0x5bc20
movl $0x3f9, %ecx            # imm = 0x3F9
jmp 0x2fca5
movq 0x50380(%rip), %rax     # 0x7fff0
movq (%rax), %rdi
leaq 0x1d38a(%rip), %rsi     # 0x4d004
leaq 0x2bf9f(%rip), %rdx     # 0x5bc20
movl $0x408, %ecx            # imm = 0x408
jmp 0x2fca5
movq 0x50361(%rip), %rax     # 0x7fff0
movq (%rax), %rdi
leaq 0x1d36b(%rip), %rsi     # 0x4d004
leaq 0x2bf80(%rip), %rdx     # 0x5bc20
movl $0x418, %ecx            # imm = 0x418
xorl %eax, %eax
callq 0x125e0
pushq $0x1
popq %rdi
callq 0x12a60