// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %r9, %r11
movq %r8, 0x30(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq 0x80(%rsp), %rcx
movl 0x20(%rdx), %r13d
movl 0x88(%rsp), %eax
addl %r13d, %eax
movl %eax, 0x4(%rsp)
movl 0x18(%rsi), %eax
movq %rax, 0x20(%rsp)
addq $0x18, %r15
movq (%rcx), %rcx
xorl %eax, %eax
testq %rcx, %rcx
movq %rdx, 0x18(%rsp)
je 0x140ed8
movq %r11, 0x38(%rsp)
pushq $0x1
popq %rdx
movl %edx, %ebp
movq %r13, 0x40(%rsp)
movq %r13, 0x10(%rsp)
xorl %r11d, %r11d
xorl %r12d, %r12d
movl %ebp, %r13d
cmpq %r13, %rcx
jb 0x140ec6
movq %rbp, 0x8(%rsp)
movl %eax, %ebp
jne 0x140ca8
cmpq %rbp, %rcx
jbe 0x140e36
movq 0x80(%rsp), %rax
movq 0x10(%rax), %rcx
movl (%rcx,%rbp,4), %eax
cmpl 0x40(%rsp), %eax
setae %dl
cmpl 0x4(%rsp), %eax
setb %al
testb %al, %dl
je 0x140e36
jmp 0x140d16
movq 0x80(%rsp), %rcx
movq 0x10(%rcx), %rcx
movl (%rcx,%rbp,4), %edx
movq 0x40(%rsp), %r8
cmpl %r8d, %edx
setae %dil
movl 0x4(%rsp), %r10d
cmpl %r10d, %edx
setb %sil
andb %dil, %sil
movl (%rcx,%r13,4), %edi
cmpl %r8d, %edi
setae %r9b
cmpl %r10d, %edi
setb %r8b
andb %r9b, %r8b
cmpb $0x1, %sil
jne 0x140d04
testb %r8b, %r8b
je 0x140d04
subl %edx, %edi
movq 0x8(%rsp), %rdx
subl %eax, %edx
cmpl %edx, %edi
jne 0x140d16
jmp 0x140e48
cmpb %r8b, %sil
je 0x140e48
testb %sil, %sil
je 0x140e36
movl (%rcx,%rbp,4), %eax
movl %eax, %r10d
movq 0x10(%rsp), %r13
subl %r13d, %r10d
jbe 0x140d89
movl %r11d, %esi
movq 0x38(%rsp), %r11
testq %r11, %r11
setne %dl
testl %esi, %esi
setne %sil
testb %sil, %dl
je 0x140e5f
movl 0x20(%rbx), %eax
subl %eax, %r13d
subq $0x8, %rsp
movq %r15, %rdi
movq 0x28(%rsp), %rsi
movq %r14, %rdx
movq %rbx, %rcx
movq 0x30(%rsp), %r8
movq 0x38(%rsp), %r9
pushq %r13
pushq %r10
pushq $0x3
pushq %rax
pushq %r11
callq 0x1402df
addq $0x30, %rsp
addq %rax, %r12
movq 0x80(%rsp), %rax
movq 0x10(%rax), %rcx
movl (%rcx,%rbp,4), %eax
movq 0x8(%rsp), %rbp
leal -0x1(%rbp), %ebx
movl (%rcx,%rbx,4), %r8d
subl %eax, %r8d
incl %r8d
xorl %r9d, %r9d
cmpl $0x0, 0x1c(%r14)
setne %r9b
movq %r15, %rdi
xorl %esi, %esi
movl $0xffff, %edx           # imm = 0xFFFF
movl $0xffff, %ecx           # imm = 0xFFFF
callq 0x14f542
xorl %r11d, %r11d
movl (%r15), %eax
subl 0x18(%r14), %eax
movl %eax, 0x1c(%r14)
movq 0x80(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%rbx,4), %eax
incl %eax
movq %rax, 0x10(%rsp)
movl %ebp, %eax
movq 0x18(%rsp), %rbx
jmp 0x140e4d
movq 0x10(%rbx), %rax
movq 0x80(%rsp), %rcx
movq 0x10(%rcx), %rcx
movl (%rcx,%rbp,4), %ecx
imulq $0x28, %rcx, %rcx
movl (%rax,%rcx), %ecx
xorl %r9d, %r9d
cmpl $0x0, 0x1c(%r14)
setne %r9b
andl $0x3, %ecx
movq %r15, %rdi
pushq $0x2
popq %rsi
movl $0xffff, %edx           # imm = 0xFFFF
pushq $0x1
popq %r8
callq 0x14f542
movl (%r15), %eax
subl 0x18(%r14), %eax
movl %eax, 0x1c(%r14)
incq %r12
incq %rbp
cmpq %r13, %rbp
jb 0x140de8
movq 0x8(%rsp), %rbp
movl %ebp, %eax
pushq $0x1
popq %r11
jmp 0x140e4d
movq 0x8(%rsp), %rbp
incl %ebp
movq 0x80(%rsp), %rcx
movq (%rcx), %rcx
jmp 0x140c63
movl %r13d, %r13d
imulq $0x28, %r13, %rbx
movl %eax, %edx
cmpq %rdx, %r13
jae 0x140d89
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%rbx), %edx
xorl %r9d, %r9d
cmpl $0x0, 0x1c(%r14)
setne %r9b
andl $0x3, %edx
movq %r15, %rdi
pushq $0x3
popq %rsi
movl $0xffff, %ecx           # imm = 0xFFFF
pushq $0x1
popq %r8
callq 0x14f542
movl (%r15), %eax
subl 0x18(%r14), %eax
movl %eax, 0x1c(%r14)
incq %r12
incq %r13
movq 0x80(%rsp), %rax
movq 0x10(%rax), %rcx
movl (%rcx,%rbp,4), %eax
addq $0x28, %rbx
jmp 0x140e66
testl %r11d, %r11d
setne %al
movq 0x10(%rsp), %r13
movq 0x38(%rsp), %r11
jmp 0x140edb
xorl %r12d, %r12d
movl 0x4(%rsp), %ecx
movl %ecx, %r10d
subl %r13d, %r10d
jbe 0x140f28
testq %r11, %r11
setne %cl
testb %al, %cl
je 0x140f3a
movl 0x20(%rbx), %eax
subl %eax, %r13d
subq $0x8, %rsp
movq %r15, %rdi
movq 0x28(%rsp), %rsi
movq %r14, %rdx
movq %rbx, %rcx
movq 0x30(%rsp), %r8
movq 0x38(%rsp), %r9
pushq %r13
pushq %r10
pushq $0x3
pushq %rax
pushq %r11
callq 0x1402df
addq $0x30, %rsp
addq %rax, %r12
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r13d, %ebx
movl 0x4(%rsp), %ebp
imulq $0x28, %rbx, %r13
addq %rbp, %r12
subq %rbx, %r12
cmpq %rbp, %rbx
jae 0x140f28
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%r13), %edx
xorl %r9d, %r9d
cmpl $0x0, 0x1c(%r14)
setne %r9b
andl $0x3, %edx
movq %r15, %rdi
pushq $0x3
popq %rsi
movl $0xffff, %ecx           # imm = 0xFFFF
pushq $0x1
popq %r8
callq 0x14f542
movl (%r15), %eax
subl 0x18(%r14), %eax
movl %eax, 0x1c(%r14)
incq %rbx
addq $0x28, %r13
jmp 0x140f4b