// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r14
movq 0xa0(%rsp), %r10
movl 0x20(%rdx), %esi
movl 0xa8(%rsp), %ebp
addl %esi, %ebp
movl 0x18(%r15), %eax
movq %rax, 0x38(%rsp)
addq $0x18, %r15
movq (%r10), %rcx
xorl %r11d, %r11d
testq %rcx, %rcx
movq %rbp, 0x20(%rsp)
je 0x1852f4
movq %r9, 0x50(%rsp)
movq %r13, 0x10(%rsp)
movl $0x1, %ebx
movl $0x1, %edx
xorl %r12d, %r12d
movl $0x0, 0x8(%rsp)
movl %esi, %eax
movq %rax, 0x28(%rsp)
xorl %eax, %eax
movq %rsi, %r13
movq %rsi, 0x58(%rsp)
cmpq %rdx, %rcx
jne 0x18504b
movl %eax, %edx
cmpq %rdx, %rcx
jbe 0x185131
movq 0x10(%r10), %rcx
movl (%rcx,%rdx,4), %edx
cmpl %r13d, %edx
setae %sil
cmpl %ebp, %edx
setb %dl
testb %dl, %sil
jne 0x1850a3
jmp 0x185131
movq 0x10(%r10), %rcx
movl %eax, %esi
movl (%rcx,%rsi,4), %esi
cmpl %r13d, %esi
setae %r8b
cmpl %ebp, %esi
setb %dil
andb %r8b, %dil
movl (%rcx,%rdx,4), %edx
cmpl %r13d, %edx
setae %r9b
cmpl %ebp, %edx
setb %r8b
andb %r9b, %r8b
cmpb $0x1, %dil
jne 0x185091
testb %r8b, %r8b
je 0x185091
subl %esi, %edx
movl %ebx, %esi
subl %eax, %esi
cmpl %esi, %edx
jne 0x1850a3
jmp 0x1852c6
cmpb %r8b, %dil
je 0x1852c6
testb %dil, %dil
je 0x185131
movq %r11, 0x30(%rsp)
movl %eax, %edi
movl (%rcx,%rdi,4), %eax
movl %eax, %r10d
movq 0x28(%rsp), %rdx
subl %edx, %r10d
jbe 0x18525f
movq 0x50(%rsp), %r11
testq %r11, %r11
setne %al
cmpl $0x0, 0x8(%rsp)
setne %cl
testb %cl, %al
je 0x1851de
movq 0x10(%rsp), %rcx
movl 0x20(%rcx), %eax
subl %eax, %edx
subq $0x8, %rsp
movq %rdi, 0x10(%rsp)
movq %r15, %rdi
movq 0x40(%rsp), %rsi
movq %rdx, %rbp
movq %r14, %rdx
movq 0x48(%rsp), %r8
movq 0x50(%rsp), %r9
pushq %rbp
pushq %r10
pushq $0x3
pushq %rax
pushq %r11
callq 0x183fb6
addq $0x30, %rsp
addq %rax, %r12
movq 0xa0(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x8(%rsp), %rax
movl (%rcx,%rax,4), %eax
jmp 0x18525f
movl $0x1, 0x8(%rsp)
cmpl %eax, %ebx
jbe 0x1851d7
movq %rbx, 0x18(%rsp)
movl %ebx, %ebx
movl %eax, %ebp
movq %r11, 0x30(%rsp)
subl %eax, %r11d
movq %r11, 0x60(%rsp)
movl 0x1c(%r14), %eax
movq 0x10(%rsp), %r13
movq 0x10(%r13), %rcx
movq 0x10(%r10), %rdx
movl (%rdx,%rbp,4), %edx
leaq (%rdx,%rdx,4), %rdx
movl (%rcx,%rdx,8), %ecx
xorl %r9d, %r9d
testl %eax, %eax
setne %r9b
andl $0x3, %ecx
movq %r15, %rdi
movl $0x2, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0x1, %r8d
callq 0x1967e1
movq 0xa0(%rsp), %r10
movl (%r15), %eax
subl 0x18(%r14), %eax
movl %eax, 0x1c(%r14)
incq %rbp
cmpq %rbp, %rbx
jne 0x185160
movq 0x60(%rsp), %rax
addq %rax, %r12
incq %r12
movq 0x18(%rsp), %rbx
movl %ebx, %eax
movq 0x20(%rsp), %rbp
movq 0x58(%rsp), %r13
movq 0x30(%rsp), %r11
jmp 0x1852c6
movl %ebx, %eax
jmp 0x1852c6
movq %rbx, 0x18(%rsp)
movl %edx, %ebx
movl 0x1c(%r14), %esi
leaq (,%rbx,8), %rax
leaq (%rax,%rax,4), %rbp
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%rbp), %edx
xorl %r9d, %r9d
testl %esi, %esi
setne %r9b
andl $0x3, %edx
movq %rdi, %r13
movq %r15, %rdi
movl $0x3, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r8d
callq 0x1967e1
movq %r13, %rdi
movl (%r15), %esi
subl 0x18(%r14), %esi
movl %esi, 0x1c(%r14)
incq %r12
incq %rbx
movq 0xa0(%rsp), %rax
movq 0x10(%rax), %rcx
movl (%rcx,%r13,4), %eax
addq $0x28, %rbp
cmpq %rax, %rbx
jb 0x1851f5
movq 0x58(%rsp), %r13
movq 0x18(%rsp), %rbx
movq %rbx, %rbp
decl %ebx
movl (%rcx,%rbx,4), %r8d
subl %eax, %r8d
incl %r8d
xorl %r9d, %r9d
cmpl $0x0, 0x1c(%r14)
setne %r9b
movl $0x0, 0x8(%rsp)
movq %r15, %rdi
xorl %esi, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0xffff, %ecx           # imm = 0xFFFF
callq 0x1967e1
movl (%r15), %eax
subl 0x18(%r14), %eax
movl %eax, 0x1c(%r14)
movq 0xa0(%rsp), %r10
movq 0x10(%r10), %rax
movl (%rax,%rbx,4), %eax
movq %rbp, %rbx
incl %eax
movq %rax, 0x28(%rsp)
movl %ebp, %eax
movq 0x30(%rsp), %r11
movq 0x20(%rsp), %rbp
incl %ebx
movq (%r10), %rcx
incl %r11d
movq %rbx, %rdx
cmpq %rbx, %rcx
jae 0x18501e
cmpl $0x0, 0x8(%rsp)
setne %r11b
movq 0x28(%rsp), %rsi
movq 0x10(%rsp), %r13
movq 0x50(%rsp), %r9
jmp 0x1852f7
xorl %r12d, %r12d
subl %esi, %ebp
jbe 0x1853a2
movq %rsi, %rcx
testq %r9, %r9
setne %al
testb %r11b, %al
je 0x185353
movq %r9, %r10
movl 0x20(%r13), %eax
movq 0x20(%rsp), %r11
movq %rcx, %rbx
subl %ebx, %r11d
subl %eax, %ebx
subq $0x8, %rsp
movq %r15, %rdi
movq 0x40(%rsp), %rsi
movq %r14, %rdx
movq %r13, %rcx
movq 0x48(%rsp), %r8
movq 0x50(%rsp), %r9
pushq %rbx
pushq %r11
pushq $0x3
pushq %rax
pushq %r10
callq 0x183fb6
addq $0x30, %rsp
addq %rax, %r12
jmp 0x1853a2
movl %ecx, %ecx
movl 0x1c(%r14), %eax
shlq $0x3, %rcx
leaq (%rcx,%rcx,4), %rbx
movq 0x10(%r13), %rcx
movl (%rcx,%rbx), %edx
xorl %r9d, %r9d
testl %eax, %eax
setne %r9b
andl $0x3, %edx
movq %r15, %rdi
movl $0x3, %esi
movl $0xffff, %ecx           # imm = 0xFFFF
movl $0x1, %r8d
callq 0x1967e1
movl (%r15), %eax
subl 0x18(%r14), %eax
movl %eax, 0x1c(%r14)
incq %r12
addq $0x28, %rbx
decl %ebp
jne 0x185361
movq %r12, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq