// File: /workspace/github_cpp_makefile_star2_O2/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), %rax
andq $0x0, 0x220(%rdx)
movq %rdx, 0x20(%rsp)
andl $0x0, 0x10(%rdx)
movq %rdi, 0x10(%rsp)
movq 0x10(%rdi), %rcx
movq %r9, (%rsp)
andq $0x0, 0x8(%r9)
movq %rax, 0x8(%rsp)
andq $0x0, (%rax)
xorl %eax, %eax
testq %rcx, %rcx
cmovleq %rax, %rcx
movq %rcx, 0x28(%rsp)
xorl %r12d, %r12d
cmpq 0x28(%rsp), %r12
je 0x40b8b
movq 0x10(%rsp), %rax
movq (%rax), %r13
imulq $0xa8, %r12, %rax
movq 0x48(%r13,%rax), %r14
testq %r14, %r14
je 0x40b83
addq %rax, %r13
cmpb $0x1, 0x2c(%r13)
jne 0x40b83
testq %r14, %r14
movl $0x0, %eax
cmovleq %rax, %r14
xorl %ebp, %ebp
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x40b83
movq 0x58(%r13), %rax
cmpw $0x7fff, 0x14(%rax,%rbp) # imm = 0x7FFF
jne 0x40b35
cmpl $0x0, 0x1c(%rax,%rbp)
jne 0x40b35
cmpw $0x0, 0x12(%rax,%rbp)
js 0x40b7a
movl 0x4(%rax,%rbp), %ecx
cmpl (%rax,%rbp), %ecx
jl 0x40b7a
movl 0xc(%rax,%rbp), %ecx
cmpl 0x8(%rax,%rbp), %ecx
jl 0x40b7a
movq (%r15), %r8
movq 0x8(%r15), %r9
subq $0x8, %rsp
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq 0x40(%rsp), %rcx
pushq $0x2
pushq 0x40(%rsp)
pushq $0x10
pushq 0x20(%rsp)
pushq 0x68(%rsp)
callq 0x3c40f
addq $0x30, %rsp
incq %rbx
addq $0x20, %rbp
jmp 0x40b14
incq %r12
jmp 0x40ad2
movq (%rsp), %rax
movq 0x8(%rax), %r14
testq %r14, %r14
je 0x40cf5
leaq (%r14,%r14), %rax
movq 0x8(%rsp), %rbx
movq %rax, (%rbx)
cmpq %rax, 0x8(%rbx)
jae 0x40c07
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), %r14
andq $0x0, (%rbx)
movq (%rsp), %rax
movq (%rax), %rdi
imulq $0x1c, %r14, %rsi
addq %rdi, %rsi
callq 0x1a7a0
xorl %eax, %eax
testq %r14, %r14
movl $0x0, %ebx
cmovgq %r14, %rbx
negq %rbx
pushq $0x1
popq %r15
pushq $0x1c
popq %r12
leaq (%rbx,%r15), %rcx
cmpq $0x1, %rcx
je 0x40c8e
cmpq %r15, %r14
je 0x40c61
movq (%rsp), %rcx
movq (%rcx), %rcx
movl 0x4(%rcx,%r12), %edx
imulq $0x1c, %rax, %rsi
cmpl 0x4(%rcx,%rsi), %edx
jne 0x40c61
movq %rax, %rcx
jmp 0x40c82
movq %r15, %rcx
testq %rax, %rax
jns 0x40c82
movq (%rsp), %rcx
movq (%rcx), %rsi
imulq $0x1c, %rax, %rdi
addq %rsi, %rdi
addq %r12, %rsi
callq 0x1af69
movq %r15, %rcx
incq %r15
addq $0x1c, %r12
movq %rcx, %rax
jmp 0x40c37
movq (%rsp), %rbx
movq (%rbx), %rsi
movsd 0x1a2913(%rip), %xmm0   # 0x1e35b0
movsd 0x1a287b(%rip), %xmm1   # 0x1e3520
pushq $0x3
popq %rcx
movq 0x10(%rsp), %r12
movq %r12, %rdi
movq %r14, %rdx
movq %rcx, %r8
movq 0x8(%rsp), %r15
pushq %r15
movq 0x20(%rsp), %r14
pushq %r14
callq 0x3f5d8
addq $0x10, %rsp
movq %rax, 0x8(%rbx)
movq %rbx, %rdi
movq %r12, %rsi
movq 0x20(%rsp), %rdx
movq %r15, %rcx
movq %r14, %r8
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x402ff
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq