// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: push_replace_alnw_adv(overlap_region*, long, overlap_region*, int, long, long, long, long)
void push_replace_alnw_adv(overlap_region *z, int64_t wl, overlap_region *aux_o, int32_t qs, int64_t qe, int64_t ts, int64_t te, int64_t mode)
{
    int64_t k, wsk, wek, err, t; window_list *p = NULL;
    wsk = get_win_id_by_s(z, qs, wl, NULL); assert(z->w_list.a[wsk].x_start == qs);
    wek = get_win_id_by_s(z, qe+1, wl, NULL); assert(z->w_list.a[wek].x_end == (qe+1));
    kv_pushp(window_list, aux_o->w_list, &p);
    p->x_start = p->x_end = qs;
    p->y_start = p->y_end = ts;
    p->error_threshold = mode; p->error = 0;
    p->extra_begin = p->extra_end = 0;
    p->cidx = p->clen = 0; err = 0;

    for (k = wsk; k <= wek; k++) {
        assert(z->w_list.a[k].y_end != -1);
        t = err + z->w_list.a[k].error;
        if(t < INT16_MAX) {///note: t cannot be equal to INT16_MAX; otherwise it is unable to distiguish unaligned regions
            err += z->w_list.a[k].error;
            p->x_end = z->w_list.a[k].x_end;
            p->y_end = z->w_list.a[k].y_end;
        } else {
            err = z->w_list.a[k].error;
            kv_pushp(window_list, aux_o->w_list, &p);
            p->x_start = z->w_list.a[k].x_start;
            p->x_end = z->w_list.a[k].x_end;
            p->y_start = z->w_list.a[k].y_start;
            p->y_end = z->w_list.a[k].y_end;
            p->error_threshold = mode;
            p->extra_begin = p->extra_end = 0;
            p->cidx = p->clen = 0;
        }
        p->error = err; 
    }
    p->x_end = qe; p->y_end = te;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebp
movq %rdx, %r14
movq %rdi, %r15
movslq %ecx, %r10
movl 0x4(%rdi), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %rsi
subq %rdx, %rcx
movq %r10, %rax
subq %rcx, %rax
cqto
idivq %rsi
movq 0x58(%rdi), %rdi
movq %rax, %rbx
shlq $0x5, %rbx
cmpl %r10d, (%rdi,%rbx)
jne 0x661a8
movq %rax, %r11
movq %r8, 0x10(%rsp)
incq %r8
movq %r8, %rax
subq %rcx, %rax
cqto
idivq %rsi
movq %rax, %r12
shlq $0x5, %rax
movslq 0x4(%rdi,%rax), %rax
cmpq %rax, %r8
jne 0x661c7
movq 0x58(%rsp), %r8
movq 0x50(%r14), %rax
cmpq %rax, 0x48(%r14)
jne 0x6603f
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x50(%r14)
movq 0x58(%r14), %rdi
shlq $0x5, %rsi
movq %r9, %r13
movq %r11, 0x8(%rsp)
callq 0x2370
movq 0x8(%rsp), %r11
movq %r13, %r9
movq 0x58(%rsp), %r8
movq %rax, 0x58(%r14)
movq 0x48(%r14), %rcx
movq 0x58(%r14), %rdx
leaq 0x1(%rcx), %rax
movq %rax, 0x48(%r14)
shlq $0x5, %rcx
leaq (%rdx,%rcx), %rax
movl %ebp, 0x4(%rdx,%rcx)
movl %ebp, (%rdx,%rcx)
movl %r9d, 0xc(%rdx,%rcx)
movl %r9d, 0x8(%rdx,%rcx)
movw %r8w, 0x16(%rdx,%rcx)
movw $0x0, 0x14(%rdx,%rcx)
movl $0x0, 0x10(%rdx,%rcx)
movq $0x0, 0x18(%rdx,%rcx)
cmpq %r12, %r11
jg 0x6616a
subq %r11, %r12
incq %r12
orq $0xc, %rbx
xorl %ecx, %ecx
movl $0x2, %r13d
movq 0x58(%r15), %rdx
cmpl $-0x1, (%rdx,%rbx)
je 0x66189
movswq 0x8(%rdx,%rbx), %rbp
addq %rbp, %rcx
cmpq $0x7ffe, %rcx           # imm = 0x7FFE
jg 0x660d6
movl -0x8(%rdx,%rbx), %esi
movl %esi, 0x4(%rax)
movl (%rdx,%rbx), %edx
movl %edx, 0xc(%rax)
movq %rcx, %rbp
jmp 0x66159
movq 0x50(%r14), %rax
cmpq %rax, 0x48(%r14)
jne 0x66105
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r13, %rsi
movq %rsi, 0x50(%r14)
movq 0x58(%r14), %rdi
shlq $0x5, %rsi
callq 0x2370
movq 0x58(%rsp), %r8
movq %rax, 0x58(%r14)
movq 0x48(%r14), %rcx
movq 0x58(%r14), %rdx
leaq 0x1(%rcx), %rax
movq %rax, 0x48(%r14)
shlq $0x5, %rcx
leaq (%rdx,%rcx), %rax
movq 0x58(%r15), %rsi
movl -0xc(%rsi,%rbx), %edi
movl %edi, (%rdx,%rcx)
movl -0x8(%rsi,%rbx), %edi
movl %edi, 0x4(%rdx,%rcx)
movl -0x4(%rsi,%rbx), %edi
movl %edi, 0x8(%rdx,%rcx)
movl (%rsi,%rbx), %esi
movl %esi, 0xc(%rdx,%rcx)
movw %r8w, 0x16(%rdx,%rcx)
movl $0x0, 0x10(%rdx,%rcx)
movq $0x0, 0x18(%rdx,%rcx)
movq %rbp, %rcx
movw %bp, 0x14(%rax)
addq $0x20, %rbx
decq %r12
jne 0x660a1
movq 0x50(%rsp), %rcx
movq 0x10(%rsp), %rdx
movl %edx, 0x4(%rax)
movl %ecx, 0xc(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1c0a6a(%rip), %rdi    # 0x226bfa
leaq 0x1bf4ac(%rip), %rsi    # 0x225643
leaq 0x1c09c6(%rip), %rcx    # 0x226b64
movl $0x3eba, %edx           # imm = 0x3EBA
callq 0x2110
leaq 0x1c0996(%rip), %rdi    # 0x226b45
leaq 0x1bf48d(%rip), %rsi    # 0x225643
leaq 0x1c09a7(%rip), %rcx    # 0x226b64
movl $0x3eb0, %edx           # imm = 0x3EB0
callq 0x2110
leaq 0x1c0a0b(%rip), %rdi    # 0x226bd9
leaq 0x1bf46e(%rip), %rsi    # 0x225643
leaq 0x1c0988(%rip), %rcx    # 0x226b64
movl $0x3eb1, %edx           # imm = 0x3EB1
callq 0x2110