// File: /workspace/github_c_makefile_star2_O3/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 0x326a1
movq %rdi, %r15
movq %rdx, -0x70(%rbp)
cmpb $-0x24, (%rsi)
jne 0x32101
incq %rsi
leaq -0x30(%rbp), %rax
movq %rsi, (%rax)
movq %r15, %rdi
movq %rax, %rsi
callq 0x3007a
testl %eax, %eax
js 0x326bb
movq 0xe0(%r15), %rcx
testq %rcx, %rcx
je 0x326bb
cmpl -0x4(%rcx), %eax
jge 0x326bb
movl %eax, %eax
movq (%rcx,%rax,8), %r14
jmp 0x32687
movl %ecx, %r12d
movl $0x80, %esi
movl $0xc, %edi
callq 0x2b686
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
movq $0x0, 0x50(%rax)
movups %xmm0, 0x6c(%rax)
movq %rax, -0x68(%rbp)
movl $0x0, 0x7c(%rax)
movq 0xe0(%r15), %rax
testq %rax, %rax
je 0x32157
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
cmpl -0x8(%rax), %edx
jl 0x32176
movq %rax, %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0x4b4e8
movq %rax, 0xe0(%r15)
movl -0x4(%rax), %ecx
leal 0x1(%rcx), %edx
movl %edx, -0x4(%rax)
movslq %ecx, %rcx
movq %r14, (%rax,%rcx,8)
leaq -0x30(%rbp), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3007a
movl %eax, 0x58(%r14)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x31b3b
movl %eax, 0x5c(%r14)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x31b3b
movl %eax, 0x60(%r14)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x31b3b
movl %eax, 0x64(%r14)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x31b3b
movl %eax, 0x68(%r14)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x31b3b
movl %eax, -0x48(%rbp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x31b3b
movl %eax, %r13d
movl 0x58(%r14), %ecx
movl $0x0, -0x38(%rbp)
btl $0x16, %ecx
movl $0x0, %eax
jae 0x32211
leaq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x31b3b
movl 0x58(%r14), %ecx
movl %eax, -0x4c(%rbp)
btl $0x15, %ecx
jae 0x3222d
leaq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x31b3b
movl %eax, -0x38(%rbp)
movl 0x58(%r14), %ecx
movl $0x0, -0x34(%rbp)
btl $0x12, %ecx
jae 0x3224d
leaq -0x30(%rbp), %rsi
movq %r15, %rdi
callq 0x31b3b
movl %eax, -0x34(%rbp)
movl 0x58(%r14), %ecx
btl $0x13, %ecx
jae 0x322a5
movq -0x30(%rbp), %rsi
leal 0x1(%r12), %ecx
leaq -0x58(%rbp), %rbx
movq %r15, %rdi
movq %rbx, %rdx
callq 0x30284
movq %rax, -0x30(%rbp)
movq (%rbx), %rdx
movq %rdx, %rax
movabsq $-0x800000000000, %rcx  # imm = 0xFFFF800000000000
andq %rcx, %rax
movabsq $-0x6000000000000, %rcx # imm = 0xFFFA000000000000
cmpq %rcx, %rax
jne 0x326cb
movq %rdx, %rdi
callq 0x4ebc4
movq %rax, 0x48(%r14)
movl 0x58(%r14), %ecx
btl $0x14, %ecx
jae 0x322f9
movq -0x30(%rbp), %rsi
leal 0x1(%r12), %ecx
leaq -0x58(%rbp), %rbx
movq %r15, %rdi
movq %rbx, %rdx
callq 0x30284
movq %rax, -0x30(%rbp)
movq (%rbx), %rdx
movq %rdx, %rax
movabsq $-0x800000000000, %rcx  # imm = 0xFFFF800000000000
andq %rcx, %rax
movabsq $-0x6000000000000, %rcx # imm = 0xFFFA000000000000
cmpq %rcx, %rax
jne 0x326cb
movq %rdx, %rdi
callq 0x4ebc4
movq %rax, 0x40(%r14)
movl -0x48(%rbp), %eax
testl %eax, %eax
movq %r12, -0x60(%rbp)
movl %r13d, -0x3c(%rbp)
je 0x32358
movl %eax, %ebx
shlq $0x3, %rbx
movq %rbx, %rdi
callq 0x12760
movq %rax, 0x18(%r14)
testq %rax, %rax
je 0x326ef
incl %r12d
movq -0x30(%rbp), %rax
xorl %r13d, %r13d
movq 0x18(%r14), %rdx
addq %r13, %rdx
movq %r15, %rdi
movq %rax, %rsi
movl %r12d, %ecx
callq 0x30284
addq $0x8, %r13
cmpq %r13, %rbx
jne 0x3232d
movq %rax, -0x30(%rbp)
movl -0x3c(%rbp), %r13d
movl -0x48(%rbp), %eax
jmp 0x32360
movq $0x0, 0x18(%r14)
movl %eax, 0x6c(%r14)
testb $0x4, 0x5a(%r14)
je 0x3244c
movl -0x34(%rbp), %ebx
movl %ebx, %eax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
movq %rdi, -0x48(%rbp)
callq 0x12760
movq %rax, 0x50(%r14)
testq %rax, %rax
je 0x326f4
testl %ebx, %ebx
je 0x32441
movq -0x60(%rbp), %rax
leal 0x1(%rax), %r12d
xorl %r13d, %r13d
leaq -0x30(%rbp), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3007a
movq 0x50(%r14), %rcx
movl %eax, (%rcx,%r13)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3007a
movq 0x50(%r14), %rcx
movl %eax, 0x4(%rcx,%r13)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3007a
movq 0x50(%r14), %rcx
movl %eax, 0x8(%rcx,%r13)
movq -0x30(%rbp), %rsi
movq %r15, %rdi
leaq -0x58(%rbp), %rdx
movl %r12d, %ecx
callq 0x30284
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %rsi
movq %rsi, %rax
movabsq $-0x800000000000, %rcx  # imm = 0xFFFF800000000000
andq %rcx, %rax
movabsq $-0x5800000000000, %rcx # imm = 0xFFFA800000000000
cmpq %rcx, %rax
jne 0x326ad
movq %rsi, %rdi
callq 0x4ebc4
movq 0x50(%r14), %rcx
movq %rax, 0x10(%rcx,%r13)
addq $0x18, %r13
cmpq %r13, -0x48(%rbp)
jne 0x323a9
movl -0x34(%rbp), %eax
movl %eax, 0x7c(%r14)
movl -0x3c(%rbp), %r13d
movl %r13d, %ebx
leaq (,%rbx,4), %rdi
callq 0x12760
movq %rax, 0x28(%r14)
testq %rax, %rax
je 0x326de
movq -0x30(%rbp), %rcx
testl %r13d, %r13d
je 0x32499
movq 0xf0(%r15), %rdx
xorl %esi, %esi
leaq 0x3(%rcx), %rdi
cmpq %rdx, %rdi
jae 0x326a1
movl (%rcx), %edi
movl %edi, (%rax,%rsi,4)
addq $0x4, %rcx
incq %rsi
cmpq %rsi, %rbx
jne 0x3247b
movq %rbx, -0x48(%rbp)
movq -0x68(%rbp), %rbx
addq $0x10, %rbx
movq %rcx, -0x30(%rbp)
movl %r13d, 0x70(%r14)
movl 0x58(%r14), %ecx
btl $0x16, %ecx
jb 0x324c0
movq $0x0, (%rbx)
jmp 0x32512
movl %ecx, -0x34(%rbp)
movl -0x4c(%rbp), %r12d
movl %r12d, %r13d
leaq (,%r13,4), %rsi
movl $0x1, %edi
callq 0x125a0
movq %rax, (%rbx)
testq %rax, %rax
je 0x326f9
testl %r12d, %r12d
movl -0x34(%rbp), %ecx
je 0x32516
xorl %r12d, %r12d
movq %r15, %rdi
leaq -0x30(%rbp), %rsi
callq 0x3007a
movq (%rbx), %rcx
movl %eax, (%rcx,%r12,4)
incq %r12
cmpq %r12, %r13
jne 0x324f3
movl 0x58(%r14), %ecx
movl -0x4c(%rbp), %r12d
movl %r12d, 0x74(%r14)
btl $0x15, %ecx
jb 0x3252a
movq $0x0, 0x20(%r14)
jmp 0x32590
movl %ecx, -0x34(%rbp)
movl -0x38(%rbp), %r12d
movl %r12d, %ebx
shlq $0x3, %rbx
movl $0x1, %edi
movq %rbx, %rsi
callq 0x125a0
movq %rax, 0x20(%r14)
testq %rax, %rax
je 0x326fe
movq -0x30(%rbp), %rax
testl %r12d, %r12d
movq -0x60(%rbp), %r13
je 0x32589
incl %r13d
xorl %r12d, %r12d
movq 0x20(%r14), %rdx
addq %r12, %rdx
movq %r15, %rdi
movq %rax, %rsi
movl %r13d, %ecx
callq 0x32092
addq $0x8, %r12
cmpq %r12, %rbx
jne 0x32565
movl 0x58(%r14), %ecx
jmp 0x3258c
movl -0x34(%rbp), %ecx
movq %rax, -0x30(%rbp)
movl -0x3c(%rbp), %ebx
movl -0x38(%rbp), %eax
movl %eax, 0x78(%r14)
btl $0x17, %ecx
jb 0x325aa
movq $0x0, 0x38(%r14)
jmp 0x3261f
movl %ecx, %r12d
movq -0x48(%rbp), %rax
leaq (,%rax,8), %rdi
callq 0x12760
movq %rax, 0x38(%r14)
testq %rax, %rax
je 0x32703
testl %ebx, %ebx
movl %r12d, %ecx
je 0x3261f
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %r15, %rbx
movq %r14, %r15
movq %rbx, %rdi
leaq -0x30(%rbp), %r14
movq %r14, %rsi
callq 0x3007a
addl %eax, %r12d
movq 0x38(%r15), %rax
movl %r12d, (%rax,%r13,8)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3007a
movq 0x38(%r15), %rcx
movl %eax, 0x4(%rcx,%r13,8)
incq %r13
cmpq %r13, -0x48(%rbp)
jne 0x325de
movl 0x58(%r15), %ecx
movq %r15, %r14
movq %rbx, %r15
btl $0x19, %ecx
jae 0x3267b
movl 0x5c(%r14), %ebx
addl $0x1f, %ebx
sarl $0x5, %ebx
movslq %ebx, %rdi
shlq $0x2, %rdi
callq 0x12760
movq %rax, 0x30(%r14)
testq %rax, %rax
je 0x32708
movq -0x30(%rbp), %rcx
testl %ebx, %ebx
jle 0x32677
movq 0xf0(%r15), %rdx
movl %ebx, %esi
xorl %edi, %edi
leaq 0x3(%rcx), %r8
cmpq %rdx, %r8
jae 0x326a1
movl (%rcx), %r8d
movl %r8d, (%rax,%rdi,4)
addq $0x4, %rcx
incq %rdi
cmpq %rdi, %rsi
jne 0x3265b
movq %rcx, -0x30(%rbp)
movq %r14, %rdi
callq 0x18d7e
testl %eax, %eax
jne 0x326e3
movq -0x70(%rbp), %rax
movq %r14, (%rax)
movq -0x30(%rbp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2d4e4(%rip), %rdi     # 0x5fb8c
callq 0x191a3
leaq 0x2d85d(%rip), %rdi     # 0x5ff11
xorl %eax, %eax
callq 0x190bb
leaq 0x2d832(%rip), %rdi     # 0x5fef4
movl %eax, %esi
xorl %eax, %eax
callq 0x190bb
leaq 0x2d950(%rip), %rdi     # 0x60022
movl $0x10, %esi
xorl %eax, %eax
callq 0x190bb
callq 0x13bbc
leaq 0x2d861(%rip), %rdi     # 0x5ff4b
callq 0x191a3
callq 0x13a9c
callq 0x13acc
callq 0x13afc
callq 0x13b2c
callq 0x13b5c
callq 0x13b8c