// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: rphase_lidel(overlap_region_alloc*, All_reads*, haplotype_evdience_alloc*, UC_Read*, UC_Read*, kv_ul_ov_t*, asg64_v*, asg64_v*, long, long, long, unsigned char, unsigned long, unsigned long, unsigned long)
uint64_t rphase_lidel(overlap_region_alloc* ol, All_reads *rref, haplotype_evdience_alloc* hp, UC_Read *qu, UC_Read *tu, kv_ul_ov_t *c_idx, asg64_v* idx, asg64_v* buf, int64_t bd, int64_t wl, int64_t ql, uint8_t occ_thres, uint64_t rid, uint64_t hpc_len, uint64_t std_bs)
{
    hp->length = hp->snp_stat.n = 0; 
    int64_t on = ol->length, k, i, zwn, q[2], t[2]; 
    overlap_region *z; //ul_ov_t *cp;
    for (k = idx->n = c_idx->n = 0; k < on; k++) {
        z = &(ol->list[k]); zwn = z->w_list.n; 
        if((!zwn) || (z->is_match != 1)) continue;
        for (i = 0; i < zwn; i++) {
            if(is_ualn_win(z->w_list.a[i])) continue;
            q[0] = z->w_list.a[i].x_start; q[1] = z->w_list.a[i].x_end + 1;
            t[0] = z->w_list.a[i].y_start; t[1] = z->w_list.a[i].y_end + 1;
            if(q[1] > q[0] && t[1] > t[0]) {
                extract_sub_cigar_sv(z, k, i, rref, qu->seq, qu->length, tu, c_idx, 16, hpc_len, 2);
            }
        }
    }
    if(c_idx->n <= 0) return 0;

    idx->n = (c_idx->n<<1);
    kv_resize(uint64_t, *idx, idx->n); on = c_idx->n; idx->n = 0;
    radix_sort_ul_ov_srt_qs1(c_idx->a, c_idx->a + on);
    for (k = 1, i = 0; k <= on; k++) {
        if (k == on || (c_idx->a[k].qs) != (c_idx->a[i].qs)) {
            if(k > i + k) radix_sort_ul_ov_srt_qe1(c_idx->a + i, c_idx->a + k);
            i = k;
        }
    }
    // fprintf(stderr, "-0-[M::%s]\n", __func__); 
    on = rphase_lidel_cc(ol, c_idx->a, on, 0.500001, 3, 0.25, 3, rid, buf, idx);
    c_idx->n = on; 
    // fprintf(stderr, "-1-[M::%s]\n", __func__); 
    return rcall_lidel_variant(c_idx, ol, hp, idx, buf, rid);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x40(%rsp)
movq %rcx, %r15
movq %rsi, 0x38(%rsp)
movq 0xb8(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x80(%rsp), %rcx
xorl %eax, %eax
movq %rax, 0x220(%rdx)
movq %rdx, 0x20(%rsp)
movl $0x0, 0x10(%rdx)
movq %rdi, 0x8(%rsp)
movq 0x10(%rdi), %rdx
movq %r9, (%rsp)
movq %rax, 0x8(%r9)
movq %rcx, 0x10(%rsp)
movq %rax, (%rcx)
movq %rdx, 0x28(%rsp)
testq %rdx, %rdx
jle 0x72e44
xorl %r13d, %r13d
movq 0x8(%rsp), %rax
movq (%rax), %r12
imulq $0xa8, %r13, %rax
movq 0x48(%r12,%rax), %r14
testq %r14, %r14
je 0x72e36
addq %rax, %r12
cmpb $0x1, 0x2c(%r12)
setne %al
testq %r14, %r14
setle %cl
orb %al, %cl
jne 0x72e36
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x58(%r12), %rax
cmpw $0x7fff, 0x14(%rax,%rbp) # imm = 0x7FFF
jne 0x72de5
cmpl $0x0, 0x1c(%rax,%rbp)
jne 0x72de5
cmpw $0x0, 0x12(%rax,%rbp)
js 0x72e2a
movl 0x4(%rax,%rbp), %ecx
cmpl (%rax,%rbp), %ecx
jl 0x72e2a
movl 0xc(%rax,%rbp), %ecx
cmpl 0x8(%rax,%rbp), %ecx
jl 0x72e2a
movq (%r15), %r8
movq 0x8(%r15), %r9
subq $0x8, %rsp
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq 0x40(%rsp), %rcx
pushq $0x2
pushq 0x40(%rsp)
pushq $0x10
pushq 0x20(%rsp)
pushq 0x68(%rsp)
callq 0x6e059
addq $0x30, %rsp
incq %rbx
addq $0x20, %rbp
cmpq %rbx, %r14
jne 0x72dc8
incq %r13
cmpq 0x28(%rsp), %r13
jne 0x72d91
movq (%rsp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x72fc7
addq %rax, %rax
movq 0x10(%rsp), %r13
movq %rax, (%r13)
cmpq %rax, 0x8(%r13)
jae 0x72eb8
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%r13)
movq 0x10(%r13), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x10(%r13)
movq (%rsp), %rax
movq 0x8(%rax), %r14
movq $0x0, (%r13)
movq (%rax), %rdi
leaq (%r14,%r14,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rdi, %rsi
addq %r14, %rsi
callq 0x4751b
testq %r14, %r14
jle 0x72f60
movq %r14, %rbx
negq %rbx
movl $0x1, %r15d
movl $0x1c, %r12d
xorl %eax, %eax
movq %rbx, %rcx
addq %r15, %rcx
je 0x72f21
movq (%rsp), %rcx
movq (%rcx), %rcx
movl 0x4(%rcx,%r12), %edx
leaq (%rax,%rax,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rax, %rsi
cmpl 0x4(%rcx,%rsi), %edx
jne 0x72f21
movq %rax, %rcx
jmp 0x72f49
movq %r15, %rcx
testq %rax, %rax
jns 0x72f49
movq (%rsp), %rcx
movq (%rcx), %rsi
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rdi
addq %rax, %rdi
addq %rsi, %rdi
addq %r12, %rsi
callq 0x47d0b
movq %r15, %rcx
leaq (%rbx,%r15), %rdx
incq %rdx
incq %r15
addq $0x1c, %r12
movq %rcx, %rax
cmpq $0x1, %rdx
jne 0x72ef7
movq (%rsp), %rbx
movq (%rbx), %rsi
movsd 0x1b25f1(%rip), %xmm0   # 0x225560
movsd 0x1b2559(%rip), %xmm1   # 0x2254d0
movl $0x3, %ecx
movl $0x3, %r8d
movq 0x8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rdx
pushq %r13
movq 0x20(%rsp), %r14
pushq %r14
callq 0x71507
addq $0x10, %rsp
movq %rax, 0x8(%rbx)
movq %rbx, %rdi
movq %r15, %rsi
movq 0x20(%rsp), %rdx
movq %r13, %rcx
movq %r14, %r8
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x724b4
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq