// File: /workspace/github_cpp_makefile_star2_O3/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), %rcx
movq 0x80(%rsp), %rsi
xorl %eax, %eax
movq %rax, 0x220(%rdx)
movl $0x0, 0x10(%rdx)
movq %rdi, 0x10(%rsp)
movq 0x10(%rdi), %rdi
movq %r9, (%rsp)
movq %rax, 0x8(%r9)
movq %rax, (%rsi)
movq %rdi, 0x28(%rsp)
testq %rdi, %rdi
jle 0x729f9
movq %rsi, 0x8(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
xorl %r13d, %r13d
movq 0x10(%rsp), %rax
movq (%rax), %r12
imulq $0xa8, %r13, %rax
movq 0x48(%r12,%rax), %r14
testq %r14, %r14
je 0x72852
addq %rax, %r12
cmpb $0x1, 0x2c(%r12)
setne %al
testq %r14, %r14
setle %cl
orb %al, %cl
jne 0x72852
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x58(%r12), %rax
cmpw $0x7fff, 0x14(%rax,%rbp) # imm = 0x7FFF
jne 0x72801
cmpl $0x0, 0x1c(%rax,%rbp)
jne 0x72801
cmpw $0x0, 0x12(%rax,%rbp)
js 0x72846
movl 0x4(%rax,%rbp), %ecx
cmpl (%rax,%rbp), %ecx
jl 0x72846
movl 0xc(%rax,%rbp), %ecx
cmpl 0x8(%rax,%rbp), %ecx
jl 0x72846
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 0x6db18
addq $0x30, %rsp
incq %rbx
addq $0x20, %rbp
cmpq %rbx, %r14
jne 0x727e4
incq %r13
cmpq 0x28(%rsp), %r13
jne 0x727ad
movq (%rsp), %rax
movq 0x8(%rax), %rbp
testq %rbp, %rbp
movq 0x20(%rsp), %r12
movq 0x18(%rsp), %r13
movq 0x8(%rsp), %rbx
je 0x729f9
leaq (,%rbp,2), %rax
movq %rax, (%rbx)
cmpq %rax, 0x8(%rbx)
jae 0x728ea
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(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rsp), %rax
movq 0x8(%rax), %rbp
movq $0x0, (%rbx)
movq (%rsp), %rax
movq (%rax), %rdi
leaq (,%rbp,8), %rax
addq %rbp, %rax
leaq (%rax,%rax,2), %rsi
addq %rdi, %rsi
addq %rbp, %rsi
callq 0x46b25
testq %rbp, %rbp
jle 0x72994
movq %rbp, %rbx
negq %rbx
movl $0x1, %r14d
movl $0x1c, %r15d
xorl %eax, %eax
movq %rbx, %rcx
addq %r14, %rcx
je 0x72955
movq (%rsp), %rcx
movq (%rcx), %rcx
movl 0x4(%rcx,%r15), %edx
leaq (%rax,%rax,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rax, %rsi
cmpl 0x4(%rcx,%rsi), %edx
jne 0x72955
movq %rax, %rcx
jmp 0x7297d
movq %r14, %rcx
testq %rax, %rax
jns 0x7297d
movq (%rsp), %rcx
movq (%rcx), %rsi
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rdi
addq %rax, %rdi
addq %rsi, %rdi
addq %r15, %rsi
callq 0x47306
movq %r14, %rcx
leaq (%rbx,%r14), %rdx
incq %rdx
incq %r14
addq $0x1c, %r15
movq %rcx, %rax
cmpq $0x1, %rdx
jne 0x7292b
movq (%rsp), %rbx
movq (%rbx), %rsi
movsd 0x1becbd(%rip), %xmm0   # 0x231660
movsd 0x1bec25(%rip), %xmm1   # 0x2315d0
movl $0x3, %ecx
movl $0x3, %r8d
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rdx
movq 0x8(%rsp), %r15
pushq %r15
pushq %r13
callq 0x70eb6
addq $0x10, %rsp
movq %rax, 0x8(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r13, %r8
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x71e69
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq