// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
movq -0x10(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x9e2e0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x40(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x1c(%rbp), %eax
jne 0x60fa4
jmp 0x60fc3
leaq 0x322872(%rip), %rdi    # 0x38381d
leaq 0x321369(%rip), %rsi    # 0x38231b
movl $0x3eb0, %edx           # imm = 0x3EB0
leaq 0x32287e(%rip), %rcx    # 0x38383c
callq 0x2130
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
addq $0x1, %rsi
movq -0x10(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x9e2e0
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x48(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rax
movq -0x28(%rbp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jne 0x61006
jmp 0x61025
leaq 0x3228a4(%rip), %rdi    # 0x3838b1
leaq 0x321307(%rip), %rsi    # 0x38231b
movl $0x3eb1, %edx           # imm = 0x3EB1
leaq 0x32281c(%rip), %rcx    # 0x38383c
callq 0x2130
jmp 0x61027
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x50(%rcx), %rax
jne 0x61090
movq -0x18(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x61055
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x61060
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x61060
movq -0x68(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rsi
shlq $0x5, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x18(%rbp), %rdx
movq 0x48(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x48(%rdx)
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x60(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x60(%rbp), %rax
movl %ecx, 0x8(%rax)
movq 0x18(%rbp), %rax
movw %ax, %cx
movq -0x60(%rbp), %rax
movw %cx, 0x16(%rax)
movq -0x60(%rbp), %rax
movw $0x0, 0x14(%rax)
movq -0x60(%rbp), %rax
movw $0x0, 0x12(%rax)
movq -0x60(%rbp), %rax
movw $0x0, 0x10(%rax)
movq -0x60(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x60(%rbp), %rax
movl $0x0, 0x18(%rax)
movq $0x0, -0x50(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x48(%rbp), %rax
jg 0x61377
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpl $-0x1, 0xc(%rax)
je 0x61156
jmp 0x61175
leaq 0x322775(%rip), %rdi    # 0x3838d2
leaq 0x3211b7(%rip), %rsi    # 0x38231b
movl $0x3eba, %edx           # imm = 0x3EBA
leaq 0x3226cc(%rip), %rcx    # 0x38383c
callq 0x2130
movq -0x50(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq -0x38(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rcx
movswq 0x14(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
cmpq $0x7fff, -0x58(%rbp)    # imm = 0x7FFF
jge 0x61201
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswq 0x14(%rax), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0x61357
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movswq 0x14(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x50(%rcx), %rax
jne 0x61286
movq -0x18(%rbp), %rax
cmpq $0x0, 0x50(%rax)
je 0x6124b
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x61256
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0x61256
movq -0x70(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rsi
shlq $0x5, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x18(%rbp), %rdx
movq 0x48(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x48(%rdx)
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl (%rax), %ecx
movq -0x60(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0xc(%rax)
movq 0x18(%rbp), %rax
movw %ax, %cx
movq -0x60(%rbp), %rax
movw %cx, 0x16(%rax)
movq -0x60(%rbp), %rax
movw $0x0, 0x12(%rax)
movq -0x60(%rbp), %rax
movw $0x0, 0x10(%rax)
movq -0x60(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x60(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x50(%rbp), %rax
movw %ax, %cx
movq -0x60(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6112d
movq -0x28(%rbp), %rax
movl %eax, %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x4(%rax)
movq 0x10(%rbp), %rax
movl %eax, %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0xc(%rax)
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)