// File: chhylp123[P]hifiasm/ecovlp.cpp
// Function: push_correct1_fhc(window_list*, window_list_alloc*, cns_gfa*, char*, UC_Read*, bit_extz_t*, asg32_v*, unsigned int, unsigned int)
uint64_t push_correct1_fhc(window_list *idx, window_list_alloc *res, cns_gfa *cns, char* qstr, UC_Read* tu, bit_extz_t *exz, asg32_v *rc, uint32_t bl, uint32_t rid)
{
    // fprintf(stderr, "[M::%s]\trc->n::%u\tbl::%u\n", __func__, (uint32_t)rc->n, bl);
    uint64_t nec = 0; uint32_t k, l, i, ff, sl, sk, bs = cns->off, be = bl + cns->off, bend = cns->off, is_i = 0, sc0 = res->c.n;///[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])
                    if(is_i && exz) {
                        nec += push_correct1_fhc_indel_exz(((asg16_v *)(&(res->c))), sc0, idx, cns, qstr, tu, exz, cns->off, 3, rc->a[l] - bend, bend-cns->off);
                    } else {
                        for (i = bend; i < rc->a[l]; i++) {
                            push_trace_bp_f(((asg16_v *)(&(res->c))), 3, cns->a[i].c, (uint16_t)-1,  1, ((idx->clen>0)?1:0));
                            idx->clen = res->c.n - idx->cidx; nec++;
                        }
                    }
                }

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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x90, %rsp
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x64(%rbp)
movl 0x18(%rbp), %eax
movq -0x28(%rbp), %rcx
addl 0x20(%rcx), %eax
movl %eax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movl %eax, -0x74(%rbp)
movq 0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x2524eb
movl $0x1, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x4c(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpq (%rcx), %rax
ja 0x2524e9
movl $0x0, -0x58(%rbp)
movl $0x0, -0x60(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x4c(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x252172
movl -0x50(%rbp), %eax
movq 0x10(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x252166
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
xorl %eax, %eax
cmpl -0x64(%rbp), %ecx
movb %al, -0x75(%rbp)
jb 0x252153
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x68(%rbp), %eax
setb %al
movb %al, -0x75(%rbp)
movb -0x75(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x5c(%rbp)
movl $0x1, -0x58(%rbp)
jmp 0x25223e
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
xorl %eax, %eax
cmpl -0x64(%rbp), %ecx
movb %al, -0x76(%rbp)
jb 0x2521a1
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x68(%rbp), %eax
setb %al
movb %al, -0x76(%rbp)
movb -0x76(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x5c(%rbp)
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
xorl %eax, %eax
cmpl -0x64(%rbp), %ecx
movb %al, -0x77(%rbp)
jb 0x2521e3
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x68(%rbp), %eax
setb %al
movb %al, -0x77(%rbp)
movb -0x77(%rbp), %dl
xorl %eax, %eax
movl $0x1, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x60(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x60(%rbp), %eax
je 0x252207
movl $0x1, -0x58(%rbp)
jmp 0x25223c
cmpl $0x1, -0x5c(%rbp)
jne 0x25223a
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq 0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x50(%rbp), %edx
subl (%rcx,%rdx,4), %eax
movl -0x4c(%rbp), %ecx
subl -0x50(%rbp), %ecx
cmpl %ecx, %eax
je 0x25223a
movl $0x1, -0x58(%rbp)
jmp 0x25223c
jmp 0x25223e
cmpl $0x0, -0x58(%rbp)
jne 0x252249
jmp 0x2524db
cmpl $0x0, -0x5c(%rbp)
je 0x25242f
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x6c(%rbp), %eax
jbe 0x25239c
cmpl $0x0, -0x70(%rbp)
je 0x2522f9
cmpq $0x0, -0x40(%rbp)
je 0x2522f9
movq -0x20(%rbp), %rdi
addq $0x18, %rdi
movl -0x74(%rbp), %eax
movl %eax, %esi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x40(%rbp), %rbx
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, %r11d
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %r10d
movl (%rax,%r10,4), %eax
subl -0x6c(%rbp), %eax
movl %eax, %eax
movl %eax, %r10d
movl -0x6c(%rbp), %eax
movq -0x28(%rbp), %r14
subl 0x20(%r14), %eax
movl %eax, %eax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq $0x3, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x251120
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x25239a
movl -0x6c(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movq 0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x50(%rbp), %edx
cmpl (%rcx,%rdx,4), %eax
jae 0x252398
movq -0x20(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x54(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x3, %eax
movq -0x18(%rbp), %rcx
movl 0x1c(%rcx), %edx
xorl %r9d, %r9d
movl $0x1, %ecx
cmpl $0x0, %edx
cmoval %ecx, %r9d
movl $0x3, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r8d
movzwl %ax, %edx
callq 0x26d790
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x18(%rcx), %ecx
subq %rcx, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x2522ff
jmp 0x25239a
jmp 0x25239c
movq -0x20(%rbp), %rdi
addq $0x18, %rdi
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %r8d
addl $0x1, %r8d
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x50(%rbp), %ecx
subl (%rax,%rcx,4), %r8d
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %ecx
xorl %r9d, %r9d
movl $0x1, %eax
cmpl $0x0, %ecx
cmoval %eax, %r9d
xorl %esi, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, %edx
callq 0x26d790
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x18(%rcx), %ecx
subq %rcx, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
jmp 0x2524d5
movl -0x50(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0x2524ce
movq -0x20(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x54(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x3, %eax
movq -0x18(%rbp), %rcx
movl 0x1c(%rcx), %edx
xorl %r9d, %r9d
movl $0x1, %ecx
cmpl $0x0, %edx
cmoval %ecx, %r9d
movl $0x2, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0x1, %r8d
movzwl %ax, %ecx
callq 0x26d790
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x18(%rcx), %ecx
subq %rcx, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x252435
movl $0x1, -0x70(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2520e7
jmp 0x2524eb
movl -0x68(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jbe 0x25260d
cmpl $0x0, -0x70(%rbp)
je 0x252575
cmpq $0x0, -0x40(%rbp)
je 0x252575
movq -0x20(%rbp), %rdi
addq $0x18, %rdi
movl -0x74(%rbp), %eax
movl %eax, %esi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r9
movq -0x40(%rbp), %rbx
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, %r11d
movl -0x68(%rbp), %eax
subl -0x6c(%rbp), %eax
movl %eax, %eax
movl %eax, %r10d
movl -0x6c(%rbp), %eax
movq -0x28(%rbp), %r14
subl 0x20(%r14), %eax
movl %eax, %eax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq $0x3, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x251120
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x25260b
movl -0x6c(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x68(%rbp), %eax
jae 0x252609
movq -0x20(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x54(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x3, %eax
movq -0x18(%rbp), %rcx
movl 0x1c(%rcx), %edx
xorl %r9d, %r9d
movl $0x1, %ecx
cmpl $0x0, %edx
cmoval %ecx, %r9d
movl $0x3, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r8d
movzwl %ax, %edx
callq 0x26d790
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x18(%rcx), %ecx
subq %rcx, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x25257b
jmp 0x25260b
jmp 0x25260d
movq -0x48(%rbp), %rax
addq $0x90, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax)