// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rdx, %r14
movq %rdi, %r15
movslq %ecx, %r10
movl 0x4(%rdi), %r12d
movq %r12, %rax
xorl %edx, %edx
idivq %rsi
subq %rdx, %r12
movq %r10, %rax
subq %r12, %rax
cqto
idivq %rsi
movq 0x58(%rdi), %rdi
movq %rax, %rbx
shlq $0x5, %rbx
cmpl %r10d, (%rdi,%rbx)
jne 0x65ec8
movq %rax, %rbp
movq %r8, 0x10(%rsp)
incq %r8
movq %r8, %rax
subq %r12, %rax
cqto
idivq %rsi
movq %rax, %r12
shlq $0x5, %rax
movslq 0x4(%rdi,%rax), %rax
cmpq %rax, %r8
jne 0x65ee7
movq 0x58(%rsp), %r10
movq 0x48(%r14), %rsi
cmpq 0x50(%r14), %rsi
jne 0x65d7c
leaq (%rsi,%rsi), %rax
testq %rsi, %rsi
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x50(%r14)
movq 0x58(%r14), %rdi
shlq $0x5, %rsi
movq %r15, %r13
movq %r9, %r15
movl %ecx, 0xc(%rsp)
callq 0x2370
movl 0xc(%rsp), %ecx
movq %r15, %r9
movq %r13, %r15
movq 0x58(%rsp), %r10
movq %rax, 0x58(%r14)
movq 0x48(%r14), %rsi
jmp 0x65d80
movq 0x58(%r14), %rax
leaq 0x1(%rsi), %r13
movq %r13, 0x48(%r14)
shlq $0x5, %rsi
leaq (%rax,%rsi), %rdx
movl %ecx, 0x4(%rax,%rsi)
movl %ecx, (%rax,%rsi)
movl %r9d, 0xc(%rax,%rsi)
movl %r9d, 0x8(%rax,%rsi)
movw %r10w, 0x16(%rax,%rsi)
movw $0x0, 0x14(%rax,%rsi)
movl $0x0, 0x10(%rax,%rsi)
movq $0x0, 0x18(%rax,%rsi)
cmpq %r12, %rbp
jg 0x65e8a
movq 0x58(%r15), %rsi
subq %rbp, %r12
incq %r12
xorl %edi, %edi
movl 0xc(%rsi,%rbx), %r8d
cmpl $-0x1, %r8d
je 0x65ea9
movswq 0x14(%rsi,%rbx), %rbp
addq %rbp, %rdi
cmpq $0x7ffe, %rdi           # imm = 0x7FFE
jg 0x65e07
movl 0x4(%rsi,%rbx), %r9d
movl %r9d, 0x4(%rdx)
movl %r8d, 0xc(%rdx)
movq %rdi, %rbp
jmp 0x65e79
cmpq 0x50(%r14), %r13
jne 0x65e42
leaq (,%r13,2), %rsi
testq %r13, %r13
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x50(%r14)
shlq $0x5, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x58(%rsp), %r10
movq %rax, 0x58(%r14)
movq 0x48(%r14), %r13
movq 0x58(%r15), %rsi
leaq 0x1(%r13), %rdi
movq %rdi, 0x48(%r14)
shlq $0x5, %r13
leaq (%rax,%r13), %rdx
movups (%rsi,%rbx), %xmm0
movups %xmm0, (%rax,%r13)
movw %r10w, 0x16(%rax,%r13)
movl $0x0, 0x10(%rax,%r13)
movq $0x0, 0x18(%rax,%r13)
movq %rdi, %r13
movq %rbp, %rdi
movw %bp, 0x14(%rdx)
addq $0x20, %rbx
decq %r12
jne 0x65dd4
movq 0x50(%rsp), %rax
movq 0x10(%rsp), %rcx
movl %ecx, 0x4(%rdx)
movl %eax, 0xc(%rdx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1cce5a(%rip), %rdi    # 0x232d0a
leaq 0x1cb89c(%rip), %rsi    # 0x231753
leaq 0x1ccdb6(%rip), %rcx    # 0x232c74
movl $0x3eba, %edx           # imm = 0x3EBA
callq 0x2110
leaq 0x1ccd86(%rip), %rdi    # 0x232c55
leaq 0x1cb87d(%rip), %rsi    # 0x231753
leaq 0x1ccd97(%rip), %rcx    # 0x232c74
movl $0x3eb0, %edx           # imm = 0x3EB0
callq 0x2110
leaq 0x1ccdfb(%rip), %rdi    # 0x232ce9
leaq 0x1cb85e(%rip), %rsi    # 0x231753
leaq 0x1ccd78(%rip), %rcx    # 0x232c74
movl $0x3eb1, %edx           # imm = 0x3EB1
callq 0x2110