// File: /workspace/github_cpp_makefile_star2_O2/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 %r9, %r11
movq %rdx, %r14
movq %rdi, %r15
movslq %ecx, %r9
movl 0x4(%rdi), %r10d
movq %r10, %rax
xorl %edx, %edx
idivq %rsi
subq %rdx, %r10
movq %r9, %rax
subq %r10, %rax
cqto
idivq %rsi
movq 0x58(%rdi), %rdi
movq %rax, %r12
shlq $0x5, %r12
cmpl %r9d, (%rdi,%r12)
jne 0x34d79
movq %rax, %rbp
movq %r8, 0x10(%rsp)
incq %r8
movq %r8, %rax
subq %r10, %rax
cqto
idivq %rsi
movq %rax, %r13
shlq $0x5, %rax
movslq 0x4(%rdi,%rax), %rax
cmpq %rax, %r8
jne 0x34d98
movq 0x58(%rsp), %r9
movq 0x48(%r14), %rdi
pushq $0x2
popq %rax
cmpq 0x50(%r14), %rdi
jne 0x34c47
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
cmoveq %rax, %rsi
movq %rsi, 0x50(%r14)
movq 0x58(%r14), %rdi
shlq $0x5, %rsi
movl %ecx, %ebx
movq %r11, 0x8(%rsp)
callq 0x2370
movq 0x8(%rsp), %r11
movl %ebx, %ecx
movq 0x58(%rsp), %r9
movq %rax, 0x58(%r14)
movq 0x48(%r14), %rdi
jmp 0x34c4b
movq 0x58(%r14), %rax
leaq 0x1(%rdi), %r10
movq %r10, 0x48(%r14)
shlq $0x5, %rdi
movl %ecx, 0x4(%rax,%rdi)
movl %ecx, (%rax,%rdi)
movl %r11d, 0xc(%rax,%rdi)
movl %r11d, 0x8(%rax,%rdi)
movw %r9w, 0x16(%rax,%rdi)
andw $0x0, 0x14(%rax,%rdi)
leaq (%rax,%rdi), %rdx
andl $0x0, 0x10(%rax,%rdi)
andq $0x0, 0x18(%rax,%rdi)
xorl %esi, %esi
cmpq %r13, %rbp
jg 0x34d3b
movq 0x58(%r15), %rdi
movl 0xc(%rdi,%r12), %r8d
cmpl $-0x1, %r8d
je 0x34d5a
movswq 0x14(%rdi,%r12), %rbx
addq %rbx, %rsi
cmpq $0x7ffe, %rsi           # imm = 0x7FFE
jg 0x34cc4
movl 0x4(%rdi,%r12), %edi
movl %edi, 0x4(%rdx)
movl %r8d, 0xc(%rdx)
movq %rsi, %rbx
jmp 0x34d2b
cmpq 0x50(%r14), %r10
jne 0x34cf9
leaq (%r10,%r10), %rsi
testq %r10, %r10
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x50(%r14)
shlq $0x5, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x58(%rsp), %r9
movq %rax, 0x58(%r14)
movq 0x48(%r14), %r10
movq 0x58(%r15), %rdi
leaq 0x1(%r10), %rsi
movq %rsi, 0x48(%r14)
shlq $0x5, %r10
movups (%rdi,%r12), %xmm0
movups %xmm0, (%rax,%r10)
movw %r9w, 0x16(%rax,%r10)
andl $0x0, 0x10(%rax,%r10)
andq $0x0, 0x18(%rax,%r10)
leaq (%rax,%r10), %rdx
movq %rsi, %r10
movq %rbx, %rsi
movw %bx, 0x14(%rdx)
incq %rbp
addq $0x20, %r12
jmp 0x34c85
movq 0x10(%rsp), %rax
movl %eax, 0x4(%rdx)
movq 0x50(%rsp), %rax
movl %eax, 0xc(%rdx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1afef9(%rip), %rdi    # 0x1e4c5a
leaq 0x1ae93b(%rip), %rsi    # 0x1e36a3
leaq 0x1afe55(%rip), %rcx    # 0x1e4bc4
movl $0x3eba, %edx           # imm = 0x3EBA
callq 0x2110
leaq 0x1afe25(%rip), %rdi    # 0x1e4ba5
leaq 0x1ae91c(%rip), %rsi    # 0x1e36a3
leaq 0x1afe36(%rip), %rcx    # 0x1e4bc4
movl $0x3eb0, %edx           # imm = 0x3EB0
callq 0x2110
leaq 0x1afe9a(%rip), %rdi    # 0x1e4c39
leaq 0x1ae8fd(%rip), %rsi    # 0x1e36a3
leaq 0x1afe17(%rip), %rcx    # 0x1e4bc4
movl $0x3eb1, %edx           # imm = 0x3EB1
callq 0x2110