// File: /workspace/github_c_makefile_star2_O0/janet-lang[P]janet/src/core/peg.c
// Function: cfun_peg_replace_generic
static Janet cfun_peg_replace_generic(int32_t argc, Janet *argv, int only_one) {
    PegCall c = peg_cfun_init(argc, argv, 1);
    JanetBuffer *ret = janet_buffer(0);
    int32_t trail = 0;
    for (int32_t i = c.start; i < c.bytes.len;) {
        peg_call_reset(&c);
        const uint8_t *result = peg_rule(&c.s, c.s.bytecode, c.bytes.bytes + i);
        if (NULL != result) {
            if (trail < i) {
                janet_buffer_push_bytes(ret, c.bytes.bytes + trail, (i - trail));
                trail = i;
            }
            int32_t nexti = (int32_t)(result - c.bytes.bytes);
            JanetByteView subst = janet_text_substitution(&c.subst, c.bytes.bytes + i, nexti - i, c.s.captures);
            janet_buffer_push_bytes(ret, subst.bytes, subst.len);
            trail = nexti;
            if (nexti == i) nexti++;
            i = nexti;
            if (only_one) break;
        } else {
            i++;
        }
    }
    if (trail < c.bytes.len) {
        janet_buffer_push_bytes(ret, c.bytes.bytes + trail, (c.bytes.len - trail));
    }
    return janet_wrap_buffer(ret);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl -0xc(%rbp), %esi
movq -0x18(%rbp), %rdx
leaq -0xb8(%rbp), %rdi
movl $0x1, %ecx
callq 0x54050
xorl %edi, %edi
callq 0x18490
movq %rax, -0xc0(%rbp)
movl $0x0, -0xc4(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0xc8(%rbp)
movl -0xc8(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x570b5
leaq -0xb8(%rbp), %rdi
callq 0x56d80
leaq -0xb8(%rbp), %rdi
addq $0x8, %rdi
movq -0x98(%rbp), %rsi
movq -0x40(%rbp), %rdx
movslq -0xc8(%rbp), %rax
addq %rax, %rdx
callq 0x542f0
movq %rax, -0xd0(%rbp)
xorl %eax, %eax
cmpq -0xd0(%rbp), %rax
je 0x570a1
movl -0xc4(%rbp), %eax
cmpl -0xc8(%rbp), %eax
jge 0x56ff4
movq -0xc0(%rbp), %rdi
movq -0x40(%rbp), %rsi
movslq -0xc4(%rbp), %rax
addq %rax, %rsi
movl -0xc8(%rbp), %edx
subl -0xc4(%rbp), %edx
callq 0x18790
movl -0xc8(%rbp), %eax
movl %eax, -0xc4(%rbp)
movq -0xd0(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0xd4(%rbp)
leaq -0xb8(%rbp), %rdi
addq $0x88, %rdi
movq -0x40(%rbp), %rsi
movslq -0xc8(%rbp), %rax
addq %rax, %rsi
movl -0xd4(%rbp), %edx
subl -0xc8(%rbp), %edx
movq -0x88(%rbp), %rcx
callq 0x6cd00
movq %rax, -0xe8(%rbp)
movl %edx, -0xe0(%rbp)
movq -0xc0(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movl -0xe0(%rbp), %edx
callq 0x18790
movl -0xd4(%rbp), %eax
movl %eax, -0xc4(%rbp)
movl -0xd4(%rbp), %eax
cmpl -0xc8(%rbp), %eax
jne 0x5708b
movl -0xd4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
movl %eax, -0xc8(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x5709f
jmp 0x570b5
jmp 0x570b0
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x56f5e
movl -0xc4(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x570e3
movq -0xc0(%rbp), %rdi
movq -0x40(%rbp), %rsi
movslq -0xc4(%rbp), %rax
addq %rax, %rsi
movl -0x38(%rbp), %edx
subl -0xc4(%rbp), %edx
callq 0x18790
movq -0xc0(%rbp), %rdi
movabsq $-0x2800000000000, %rsi # imm = 0xFFFD800000000000
callq 0x7b610
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
nopw (%rax,%rax)