// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/peg.c
// Function: peg_unmarshal
static void *peg_unmarshal(JanetMarshalContext *ctx) {
    size_t bytecode_len = janet_unmarshal_size(ctx);
    uint32_t num_constants = (uint32_t) janet_unmarshal_int(ctx);

    /* Calculate offsets. Should match those in make_peg */
    size_t bytecode_start = size_padded(sizeof(JanetPeg), sizeof(uint32_t));
    size_t bytecode_size = bytecode_len * sizeof(uint32_t);
    size_t constants_start = size_padded(bytecode_start + bytecode_size, sizeof(Janet));
    size_t total_size = constants_start + sizeof(Janet) * (size_t) num_constants;

    /* DOS prevention? I.E. we could read bytecode and constants before
     * hand so we don't allocated a ton of memory on bad, short input */

    /* Allocate PEG */
    char *mem = janet_unmarshal_abstract(ctx, total_size);
    JanetPeg *peg = (JanetPeg *)mem;
    uint32_t *bytecode = (uint32_t *)(mem + bytecode_start);
    Janet *constants = (Janet *)(mem + constants_start);
    peg->bytecode = NULL;
    peg->constants = NULL;
    peg->bytecode_len = bytecode_len;
    peg->num_constants = num_constants;

    for (size_t i = 0; i < peg->bytecode_len; i++)
        bytecode[i] = (uint32_t) janet_unmarshal_int(ctx);
    for (uint32_t j = 0; j < peg->num_constants; j++)
        constants[j] = janet_unmarshal_janet(ctx);

    /* After here, no panics except for the bad: label. */

    /* Keep track at each index if an instruction was
     * reference (0x01) or is in a main bytecode position
     * (0x02). This lets us do a linear scan and not
     * need to a depth first traversal. It is stricter
     * than a dfs by not allowing certain kinds of unused
     * bytecode. */
    uint32_t blen = (int32_t) peg->bytecode_len;
    uint32_t clen = peg->num_constants;
    uint8_t *op_flags = janet_calloc(1, blen);
    if (NULL == op_flags) {
        JANET_OUT_OF_MEMORY;
    }

    /* verify peg bytecode */
    int32_t has_backref = 0;
    uint32_t i = 0;
    while (i < blen) {
        uint32_t instr = bytecode[i];
        uint32_t *rule = bytecode + i;
        op_flags[i] |= 0x02;
        switch (instr) {
            case RULE_LITERAL:
                i += 2 + ((rule[1] + 3) >> 2);
                break;
            case RULE_NCHAR:
            case RULE_NOTNCHAR:
            case RULE_RANGE:
            case RULE_POSITION:
            case RULE_LINE:
            case RULE_COLUMN:
                /* [1 word] */
                i += 2;
                break;
            case RULE_BACKMATCH:
                /* [1 word] */
                i += 2;
                has_backref = 1;
                break;
            case RULE_SET:
                /* [8 words] */
                i += 9;
                break;
            case RULE_LOOK:
                /* [offset, rule] */
                if (rule[2] >= blen) goto bad;
                op_flags[rule[2]] |= 0x1;
                i += 3;
                break;
            case RULE_CHOICE:
            case RULE_SEQUENCE:
                /* [len, rules...] */
            {
                uint32_t len = rule[1];
                for (uint32_t j = 0; j < len; j++) {
                    if (rule[2 + j] >= blen) goto bad;
                    op_flags[rule[2 + j]] |= 0x1;
                }
                i += 2 + len;
            }
            break;
            case RULE_IF:
            case RULE_IFNOT:
            case RULE_LENPREFIX:
                /* [rule_a, rule_b (b if not a)] */
                if (rule[1] >= blen) goto bad;
                if (rule[2] >= blen) goto bad;
                op_flags[rule[1]] |= 0x01;
                op_flags[rule[2]] |= 0x01;
                i += 3;
                break;
            case RULE_BETWEEN:
                /* [lo, hi, rule] */
                if (rule[3] >= blen) goto bad;
                op_flags[rule[3]] |= 0x01;
                i += 4;
                break;
            case RULE_ARGUMENT:
                /* [searchtag, tag] */
                i += 3;
                break;
            case RULE_GETTAG:
                /* [searchtag, tag] */
                i += 3;
                has_backref = 1;
                break;
            case RULE_CONSTANT:
                /* [constant, tag] */
                if (rule[1] >= clen) goto bad;
                i += 3;
                break;
            case RULE_CAPTURE_NUM:
                /* [rule, base, tag] */
                if (rule[1] >= blen) goto bad;
                op_flags[rule[1]] |= 0x01;
                i += 4;
                break;
            case RULE_ACCUMULATE:
            case RULE_GROUP:
            case RULE_CAPTURE:
            case RULE_UNREF:
                /* [rule, tag] */
                if (rule[1] >= blen) goto bad;
                op_flags[rule[1]] |= 0x01;
                i += 3;
                break;
            case RULE_REPLACE:
            case RULE_MATCHTIME:
                /* [rule, constant, tag] */
                if (rule[1] >= blen) goto bad;
                if (rule[2] >= clen) goto bad;
                op_flags[rule[1]] |= 0x01;
                i += 4;
                break;
            case RULE_SUB:
            case RULE_TIL:
            case RULE_SPLIT:
                /* [rule, rule] */
                if (rule[1] >= blen) goto bad;
                if (rule[2] >= blen) goto bad;
                op_flags[rule[1]] |= 0x01;
                op_flags[rule[2]] |= 0x01;
                i += 3;
                break;
            case RULE_ERROR:
            case RULE_DROP:
            case RULE_ONLY_TAGS:
            case RULE_NOT:
            case RULE_TO:
            case RULE_THRU:
                /* [rule] */
                if (rule[1] >= blen) goto bad;
                op_flags[rule[1]] |= 0x01;
                i += 2;
                break;
            case RULE_READINT:
                /* [ width | (endianness << 5) | (signedness << 6), tag ] */
                if (rule[1] > JANET_MAX_READINT_WIDTH) goto bad;
                i += 3;
                break;
            case RULE_NTH:
                /* [nth, rule, tag] */
                if (rule[2] >= blen) goto bad;
                op_flags[rule[2]] |= 0x01;
                i += 4;
                break;
            default:
                goto bad;
        }
    }

    /* last instruction cannot overflow */
    if (i != blen) goto bad;

    /* Make sure all referenced instructions are actually
     * in instruction positions. */
    for (i = 0; i < blen; i++)
        if (op_flags[i] == 0x01) goto bad;

    /* Good return */
    peg->bytecode = bytecode;
    peg->constants = constants;
    peg->has_backref = has_backref;
    janet_free(op_flags);
    return peg;

bad:
    janet_free(op_flags);
    janet_panic("invalid peg bytecode");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x41a60
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0x41890
movl %eax, -0x14(%rbp)
movl $0x20, %edi
movl $0x4, %esi
callq 0x57190
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
shlq $0x2, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
addq -0x28(%rbp), %rdi
movl $0x8, %esi
callq 0x57190
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl -0x14(%rbp), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x43690
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq $0x0, (%rax)
movq -0x48(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x10(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x14(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x18(%rax)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x48(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x53827
movq -0x8(%rbp), %rdi
callq 0x41890
movl %eax, %edx
movq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x537f5
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jae 0x53880
movq -0x58(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl -0x64(%rbp), %eax
movq %rax, -0xb0(%rbp)
movq -0x8(%rbp), %rdi
callq 0x41d30
movq -0xb0(%rbp), %rcx
movq %rax, %rdx
movq -0xa8(%rbp), %rax
movq %rdx, -0x70(%rbp)
movq -0x70(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x5382e
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movl %eax, -0x74(%rbp)
movq -0x48(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x78(%rbp)
movl -0x74(%rbp), %eax
movl %eax, %esi
movl $0x1, %edi
callq 0x125a0
movq %rax, -0x80(%rbp)
xorl %eax, %eax
cmpq -0x80(%rbp), %rax
jne 0x538e0
jmp 0x538b2
movq 0x5c737(%rip), %rax     # 0xafff0
movq (%rax), %rdi
leaq 0x2a741(%rip), %rsi     # 0x7e004
leaq 0x41913(%rip), %rdx     # 0x951dd
movl $0x649, %ecx            # imm = 0x649
movb $0x0, %al
callq 0x125f0
movl $0x1, %edi
callq 0x12a70
movl $0x0, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpl -0x74(%rbp), %eax
jae 0x53d98
movq -0x50(%rbp), %rax
movl -0x88(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x8c(%rbp)
movq -0x50(%rbp), %rax
movl -0x88(%rbp), %ecx
leaq (%rax,%rcx,4), %rax
movq %rax, -0x98(%rbp)
movq -0x80(%rbp), %rax
movl -0x88(%rbp), %ecx
movb (%rax,%rcx), %dl
orb $0x2, %dl
movb %dl, (%rax,%rcx)
movl -0x8c(%rbp), %eax
movq %rax, -0xb8(%rbp)
subq $0x24, %rax
ja 0x53d8e
movq -0xb8(%rbp), %rax
leaq 0x4116d(%rip), %rcx     # 0x94ad0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x98(%rbp), %rax
movl 0x4(%rax), %eax
addl $0x3, %eax
shrl $0x2, %eax
addl $0x2, %eax
addl -0x88(%rbp), %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movl -0x88(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movl -0x88(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x88(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x53d93
movl -0x88(%rbp), %eax
addl $0x9, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movq -0x98(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x74(%rbp), %eax
jb 0x539ea
jmp 0x53e1c
movq -0x80(%rbp), %rax
movq -0x98(%rbp), %rcx
movl 0x8(%rcx), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movl -0x88(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movq -0x98(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x9c(%rbp)
movl $0x0, -0xa0(%rbp)
movl -0xa0(%rbp), %eax
cmpl -0x9c(%rbp), %eax
jae 0x53a91
movq -0x98(%rbp), %rax
movl -0xa0(%rbp), %ecx
addl $0x2, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x74(%rbp), %eax
jb 0x53a5d
jmp 0x53e1c
movq -0x80(%rbp), %rax
movq -0x98(%rbp), %rcx
movl -0xa0(%rbp), %edx
addl $0x2, %edx
movl %edx, %edx
movl (%rcx,%rdx,4), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movl -0xa0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa0(%rbp)
jmp 0x53a30
movl -0x9c(%rbp), %eax
addl $0x2, %eax
addl -0x88(%rbp), %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movq -0x98(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x74(%rbp), %eax
jb 0x53abf
jmp 0x53e1c
movq -0x98(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x74(%rbp), %eax
jb 0x53ad3
jmp 0x53e1c
movq -0x80(%rbp), %rax
movq -0x98(%rbp), %rcx
movl 0x4(%rcx), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movq -0x80(%rbp), %rax
movq -0x98(%rbp), %rcx
movl 0x8(%rcx), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movl -0x88(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movq -0x98(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x74(%rbp), %eax
jb 0x53b2b
jmp 0x53e1c
movq -0x80(%rbp), %rax
movq -0x98(%rbp), %rcx
movl 0xc(%rcx), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movl -0x88(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movl -0x88(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movl -0x88(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x88(%rbp)
movl $0x1, -0x84(%rbp)
jmp 0x53d93
movq -0x98(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x78(%rbp), %eax
jb 0x53b9d
jmp 0x53e1c
movl -0x88(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movq -0x98(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x74(%rbp), %eax
jb 0x53bc5
jmp 0x53e1c
movq -0x80(%rbp), %rax
movq -0x98(%rbp), %rcx
movl 0x4(%rcx), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movl -0x88(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movq -0x98(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x74(%rbp), %eax
jb 0x53c05
jmp 0x53e1c
movq -0x80(%rbp), %rax
movq -0x98(%rbp), %rcx
movl 0x4(%rcx), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movl -0x88(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movq -0x98(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x74(%rbp), %eax
jb 0x53c45
jmp 0x53e1c
movq -0x98(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x78(%rbp), %eax
jb 0x53c59
jmp 0x53e1c
movq -0x80(%rbp), %rax
movq -0x98(%rbp), %rcx
movl 0x4(%rcx), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movl -0x88(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movq -0x98(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x74(%rbp), %eax
jb 0x53c99
jmp 0x53e1c
movq -0x98(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x74(%rbp), %eax
jb 0x53cad
jmp 0x53e1c
movq -0x80(%rbp), %rax
movq -0x98(%rbp), %rcx
movl 0x4(%rcx), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movq -0x80(%rbp), %rax
movq -0x98(%rbp), %rcx
movl 0x8(%rcx), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movl -0x88(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movq -0x98(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x74(%rbp), %eax
jb 0x53d05
jmp 0x53e1c
movq -0x80(%rbp), %rax
movq -0x98(%rbp), %rcx
movl 0x4(%rcx), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movl -0x88(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movq -0x98(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jbe 0x53d40
jmp 0x53e1c
movl -0x88(%rbp), %eax
addl $0x3, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
movq -0x98(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x74(%rbp), %eax
jb 0x53d65
jmp 0x53e1c
movq -0x80(%rbp), %rax
movq -0x98(%rbp), %rcx
movl 0x8(%rcx), %ecx
movzbl (%rax,%rcx), %edx
orl $0x1, %edx
movb %dl, (%rax,%rcx)
movl -0x88(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x88(%rbp)
jmp 0x53d93
jmp 0x53e1c
jmp 0x538f4
movl -0x88(%rbp), %eax
cmpl -0x74(%rbp), %eax
je 0x53da5
jmp 0x53e1c
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
cmpl -0x74(%rbp), %eax
jae 0x53de2
movq -0x80(%rbp), %rax
movl -0x88(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jne 0x53dcf
jmp 0x53e1c
jmp 0x53dd1
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x53daf
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, (%rax)
movq -0x58(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x84(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x80(%rbp), %rdi
callq 0x120b0
movq -0x48(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
movq -0x80(%rbp), %rdi
callq 0x120b0
leaq 0x413fc(%rip), %rdi     # 0x95228
callq 0x1ad60
nopw %cs:(%rax,%rax)