// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Correct.cpp
// Function: ul_rid_lalign_adv(overlap_region_alloc*, Candidates_list*, ul_idx_t const*, ug_opt_t const*, char*, unsigned long, UC_Read*, UC_Read*, bit_extz_t*, overlap_region*, double, long, kv_ul_ov_t*, kv_ul_ov_t*, kv_rtrace_t*, long, unsigned long, void*)
void ul_rid_lalign_adv(overlap_region_alloc* ol, Candidates_list *cl, const ul_idx_t *uref, const ug_opt_t *uopt, 
        char *qstr, uint64_t ql, UC_Read* qu, UC_Read* tu, bit_extz_t *exz, overlap_region *aux_o, double e_rate, 
        int64_t wl, kv_ul_ov_t *aln, kv_ul_ov_t *cln, kv_rtrace_t *trace, int64_t sid, uint64_t khit, void *km)
{
    uint64_t i, bs, k; Window_Pool w; double err; 
    overlap_region t; overlap_region *z; //asg64_v iidx, buf, buf1;
    ol->mapped_overlaps_length = 0;
    if(ol->length <= 0) return;

    ///base alignment
    err = e_rate; 
    init_Window_Pool(&w, ql, wl, (int)(1.0/err));
    bs = (w.window_length)+(THRESHOLD_MAX_SIZE<<1)+1;
    resize_UC_Read(tu, bs<<1); 

    if(!aux_o) {
        resize_UC_Read(qu, ql); qu->length = ql; memcpy(qu->seq, qstr, ql); 
        for (i = k = 0; i < ol->length; i++) {
            z = &(ol->list[i]); z->shared_seed = z->non_homopolymer_errors;///for index
            if(!ul_local_aln(z, cl, uref, qu->seq, tu, exz, err, w.window_length, 
            1000, OVERLAP_THRESHOLD_NOSI_FILTER, NULL, NULL, NULL, ql, sid, i, khit, NULL)) {
                continue;
            }
            if(k != i) {
                t = ol->list[k];
                ol->list[k] = ol->list[i];
                ol->list[i] = t;
            }
            z = &(ol->list[k++]); z->is_match = 1; 
        }
        ol->length = k;
        if(ol->length <= 0) return;
    } else {
        for (i = cln->n = trace->n = 0; i < ol->length; i++) {
            z = &(ol->list[i]); z->shared_seed = z->non_homopolymer_errors;///for index
            // fprintf(stderr, "\n[M::%s::utg%.6dl(%c)] i::%lu, aln_l::%u, q::[%u, %u), ql::%u\n", __func__, 
            // (int32_t)z->y_id + 1, "+-"[z->y_pos_strand], i, z->align_length, 
            // z->x_pos_s, z->x_pos_e+1, z->x_pos_e+1-z->x_pos_s);
            ul_local_aln(z, cl, uref, qu->seq, tu, exz, err, w.window_length, 1000, 
            OVERLAP_THRESHOLD_NOSI_FILTER, aln, cln, trace, ql, sid, i, khit, aux_o);
        }

        ///contained reads
        if(cln->n) dedup_ul_ov_t(cln);
        if(cln->n) {
            kv_resize(ul_ov_t, *aln, aln->n+cln->n);
            memcpy(aln->a+aln->n, cln->a, cln->n*sizeof(*(aln->a)));
            aln->n += cln->n;
        }

    }
}

// Assembly:
movq $0x0, 0x18(%rdi)
cmpq $0x0, 0x10(%rdi)
je 0x83af6
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %r9, %r13
movq %rsi, %r14
movq %rdi, %rbx
movq %rdx, 0x60(%rsp)
movq 0x170(%rsp), %rcx
movq 0x168(%rsp), %r15
movq 0x158(%rsp), %rax
leaq 0x7e(,%rcx,2), %rbp
cmpq %rbp, 0x10(%rax)
movsd %xmm0, 0x50(%rsp)
jge 0x8378b
movq (%rax), %rdi
movq %rbp, %rsi
movq %r8, %r12
callq 0x2370
movq 0x170(%rsp), %rcx
movq %r12, %r8
movq 0x158(%rsp), %rdx
movq %rax, (%rdx)
movq %rbp, 0x10(%rdx)
movq 0x198(%rsp), %rdx
movq 0x150(%rsp), %rsi
testq %r15, %r15
je 0x83963
movq 0x188(%rsp), %r10
movq 0x180(%rsp), %r9
movq 0x178(%rsp), %r11
xorl %eax, %eax
movq %rax, 0x8(%r10)
movq %rax, 0x8(%r9)
cmpq %rax, 0x10(%rbx)
je 0x838ab
movq %r13, %r8
movq %rcx, %rbp
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %r8, 0x58(%rsp)
movq %r14, 0x68(%rsp)
movq (%rbx), %rax
leaq (%rax,%r12), %rdi
movl 0x30(%rax,%r12), %ecx
movl %ecx, 0x24(%rax,%r12)
movq (%rsi), %rcx
movq %r15, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %r13, 0x38(%rsp)
movq %r8, 0x28(%rsp)
movq %r10, 0x20(%rsp)
movq %r9, 0x18(%rsp)
movq %r11, 0x10(%rsp)
movq %rbp, (%rsp)
movq $0x3e8, 0x8(%rsp)       # imm = 0x3E8
movq %r14, %rsi
movq 0x60(%rsp), %rdx
movq 0x158(%rsp), %r8
movq 0x160(%rsp), %r9
movsd 0x50(%rsp), %xmm0
movsd 0x1a1c50(%rip), %xmm1   # 0x2254a0
movq %r10, %r14
movq %rbp, %r15
movq %rbx, %rbp
movq %r11, %rbx
callq 0x82bc7
movq 0x58(%rsp), %r8
movq %rbx, %r11
movq %rbp, %rbx
movq %r15, %rbp
movq %r14, %r10
movq 0x68(%rsp), %r14
movq 0x180(%rsp), %r9
movq 0x168(%rsp), %r15
movq 0x150(%rsp), %rsi
movq 0x198(%rsp), %rdx
incq %r13
addq $0xa8, %r12
cmpq 0x10(%rbx), %r13
jb 0x837e6
movq %r11, %rbx
cmpq $0x0, 0x8(%r9)
movq %r9, %r14
je 0x838c0
movq %r14, %rdi
callq 0x8343b
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x83ae5
addq 0x8(%rbx), %rax
cmpq %rax, 0x10(%rbx)
jae 0x8392d
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, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rax,%rax,8), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax), %rsi
incq %rsi
callq 0x2370
movq %rax, (%rbx)
movq 0x8(%rbx), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rdi
addq %rax, %rdi
addq (%rbx), %rdi
movq (%r14), %rsi
movq 0x8(%r14), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rdx
addq %rax, %rdx
callq 0x2160
movq 0x8(%r14), %rax
addq %rax, 0x8(%rbx)
jmp 0x83ae5
cmpq %r13, 0x10(%rsi)
jge 0x83989
movq (%rsi), %rdi
movq %r13, %rsi
movq %r8, %r15
callq 0x2370
movq %r15, %r8
movq 0x150(%rsp), %rsi
movq %rax, (%rsi)
movq %r13, 0x10(%rsi)
movq %r13, 0x8(%rsi)
movq (%rsi), %rdi
movq %r8, %rsi
movq %r13, %rdx
callq 0x2160
cmpq $0x0, 0x10(%rbx)
movq 0x60(%rsp), %rbp
je 0x83ade
movq %r14, 0x68(%rsp)
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r15d, %r15d
movsd 0x50(%rsp), %xmm0
movq 0x198(%rsp), %rdx
movq 0x160(%rsp), %r9
movq %r13, 0x58(%rsp)
movq (%rbx), %rax
leaq (%rax,%r12), %rdi
movl 0x30(%rax,%r12), %ecx
movl %ecx, 0x24(%rax,%r12)
movq 0x150(%rsp), %rax
movq (%rax), %rcx
xorl %eax, %eax
movq %rax, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %r14, 0x38(%rsp)
movq %r13, 0x28(%rsp)
movq %rax, 0x20(%rsp)
xorps %xmm1, %xmm1
movups %xmm1, 0x10(%rsp)
movq 0x170(%rsp), %rax
movq %rax, (%rsp)
movq $0x3e8, 0x8(%rsp)       # imm = 0x3E8
movq 0x68(%rsp), %rsi
movq %rbp, %rdx
movq 0x158(%rsp), %r8
movsd 0x1a1a60(%rip), %xmm1   # 0x2254a0
callq 0x82bc7
testq %rax, %rax
je 0x83ab2
cmpq %r15, %r14
je 0x83aa0
movq (%rbx), %rbp
imulq $0xa8, %r15, %r13
addq %rbp, %r13
movl $0xa8, %edx
leaq 0x70(%rsp), %rdi
movq %r13, %rsi
callq 0x2160
addq %r12, %rbp
movl $0xa8, %edx
movq %r13, %rdi
movq 0x58(%rsp), %r13
movq %rbp, %rsi
movq 0x60(%rsp), %rbp
callq 0x2160
movq (%rbx), %rdi
addq %r12, %rdi
movl $0xa8, %edx
leaq 0x70(%rsp), %rsi
callq 0x2160
movq (%rbx), %rax
imulq $0xa8, %r15, %rcx
incq %r15
movb $0x1, 0x2c(%rax,%rcx)
movsd 0x50(%rsp), %xmm0
movq 0x198(%rsp), %rdx
movq 0x160(%rsp), %r9
incq %r14
addq $0xa8, %r12
cmpq 0x10(%rbx), %r14
jb 0x839d4
jmp 0x83ae1
xorl %r15d, %r15d
movq %r15, 0x10(%rbx)
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq