// File: chhylp123[P]hifiasm/ecovlp.cpp
// Function: push_correct1(window_list*, window_list_alloc*, cns_gfa*, asg32_v*, unsigned int)
uint64_t push_correct1(window_list *idx, window_list_alloc *res, cns_gfa *cns, asg32_v *rc, uint32_t bl)
{
    // fprintf(stderr, "[M::%s]\t", __func__);
    uint64_t nec = 0; uint32_t k, l, i, ff, sl, sk, bs = cns->off, be = bl + cns->off, bend = cns->off;///[bs, be)
    if(rc->n) {///it is possible that rc->n == 0, which means there is a deletion
        for (k = 1, l = 0; k <= rc->n; ++k) {
            ff = 0; sl = sk = 0;
            if(k == rc->n) {
                if(l < rc->n) sl = ((rc->a[l] >= bs && rc->a[l] < be)?1:0); 
                ff = 1;
            } else {
                sl = ((rc->a[l] >= bs && rc->a[l] < be)?1:0); 
                sk = ((rc->a[k] >= bs && rc->a[k] < be)?1:0);
                if(sl != sk) {
                    ff = 1;
                } else if((sl == 1) && ((rc->a[k] - rc->a[l]) != (k - l))) {
                    ff = 1;
                }
            }

            if(!ff) continue;

            if(sl) { ///match
                if(rc->a[l] > bend) {///deltetion [bend, rc->a[l])
                    push_trace_bp(((asg16_v *)(&(res->c))), 3, (uint16_t)-1, rc->a[l] - bend, ((idx->clen>0)?1:0)); 
                    idx->clen = res->c.n - idx->cidx; nec += rc->a[l] - bend;
                    // fprintf(stderr, "%uD", rc->a[l] - bend);
                }

                ///push match
                push_trace_bp(((asg16_v *)(&(res->c))), 0, (uint16_t)-1, rc->a[k-1] + 1 - rc->a[l], ((idx->clen>0)?1:0)); 
                idx->clen = res->c.n - idx->cidx;

                // fprintf(stderr, "%uM", rc->a[k-1] + 1 - rc->a[l]);

                bend = rc->a[k-1] + 1;
            } else { ///unmatch
                for (i = l; i < k; i++) {
                    push_trace_bp(((asg16_v *)(&(res->c))), 2, cns->a[rc->a[i]].c, 1, ((idx->clen>0)?1:0)); 
                    idx->clen = res->c.n - idx->cidx; nec++;
                    // fprintf(stderr, "I");
                }
            }
            l = k;
        }
    } 
    
    ///push remaining deletion
    if(be > bend) {
        push_trace_bp(((asg16_v *)(&(res->c))), 3, (uint16_t)-1, be - bend, ((idx->clen>0)?1:0)); 
        idx->clen = res->c.n - idx->cidx; nec += be - bend;
        // fprintf(stderr, "%uD", be - bend);
    }
    // fprintf(stderr, "\n");
    return nec;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x4c(%rbp)
movl -0x24(%rbp), %eax
movq -0x18(%rbp), %rcx
addl 0x20(%rcx), %eax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0x2510ac
movl $0x1, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x34(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
ja 0x2510aa
movl $0x0, -0x40(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x34(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x250e0c
movl -0x38(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x250e00
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
xorl %eax, %eax
cmpl -0x4c(%rbp), %ecx
movb %al, -0x55(%rbp)
jb 0x250ded
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x50(%rbp), %eax
setb %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x44(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x250ed8
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
xorl %eax, %eax
cmpl -0x4c(%rbp), %ecx
movb %al, -0x56(%rbp)
jb 0x250e3b
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x50(%rbp), %eax
setb %al
movb %al, -0x56(%rbp)
movb -0x56(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
xorl %eax, %eax
cmpl -0x4c(%rbp), %ecx
movb %al, -0x57(%rbp)
jb 0x250e7d
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x50(%rbp), %eax
setb %al
movb %al, -0x57(%rbp)
movb -0x57(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
je 0x250ea1
movl $0x1, -0x40(%rbp)
jmp 0x250ed6
cmpl $0x1, -0x44(%rbp)
jne 0x250ed4
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x38(%rbp), %edx
subl (%rcx,%rdx,4), %eax
movl -0x34(%rbp), %ecx
subl -0x38(%rbp), %ecx
cmpl %ecx, %eax
je 0x250ed4
movl $0x1, -0x40(%rbp)
jmp 0x250ed6
jmp 0x250ed8
cmpl $0x0, -0x40(%rbp)
jne 0x250ee3
jmp 0x25109c
cmpl $0x0, -0x44(%rbp)
je 0x250ffb
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x54(%rbp), %eax
jbe 0x250f74
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
subl -0x54(%rbp), %ecx
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %edx
xorl %r8d, %r8d
movl $0x1, %eax
cmpl $0x0, %edx
cmoval %eax, %r8d
movl $0x3, %esi
movl $0xffff, %edx           # imm = 0xFFFF
callq 0x26d4e0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x18(%rcx), %ecx
subq %rcx, %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %eax
subl -0x54(%rbp), %eax
movl %eax, %eax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %ecx
addl $0x1, %ecx
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %edx
subl (%rax,%rdx,4), %ecx
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %edx
xorl %r8d, %r8d
movl $0x1, %eax
cmpl $0x0, %edx
cmoval %eax, %r8d
xorl %esi, %esi
movl $0xffff, %edx           # imm = 0xFFFF
callq 0x26d4e0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x18(%rcx), %ecx
subq %rcx, %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x251096
movl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x251094
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x3c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x3, %eax
movq -0x8(%rbp), %rcx
movl 0x1c(%rcx), %edx
xorl %r8d, %r8d
movl $0x1, %ecx
cmpl $0x0, %edx
cmoval %ecx, %r8d
movl $0x2, %esi
movl $0x1, %ecx
movzwl %ax, %edx
callq 0x26d4e0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x18(%rcx), %ecx
subq %rcx, %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x251001
jmp 0x251096
movl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x250d81
jmp 0x2510ac
movl -0x50(%rbp), %eax
cmpl -0x54(%rbp), %eax
jbe 0x251112
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movl -0x50(%rbp), %ecx
subl -0x54(%rbp), %ecx
movq -0x8(%rbp), %rax
movl 0x1c(%rax), %edx
xorl %r8d, %r8d
movl $0x1, %eax
cmpl $0x0, %edx
cmoval %eax, %r8d
movl $0x3, %esi
movl $0xffff, %edx           # imm = 0xFFFF
callq 0x26d4e0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rcx
movl 0x18(%rcx), %ecx
subq %rcx, %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x1c(%rax)
movl -0x50(%rbp), %eax
subl -0x54(%rbp), %eax
movl %eax, %eax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)