// File: /workspace/github_cpp_makefile_star2_O3/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 0x832c9
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %r9, %r13
movq %r8, %r15
movq %rsi, %r12
movq %rdi, %rbx
movq %rdx, 0x58(%rsp)
movq 0x170(%rsp), %rax
movq 0x168(%rsp), %r8
movq 0x158(%rsp), %r14
leaq 0x7e(,%rax,2), %rbp
cmpq %rbp, 0x10(%r14)
movsd %xmm0, 0x50(%rsp)
jge 0x82f62
movq (%r14), %rdi
movq %rbp, %rsi
callq 0x2370
movq 0x168(%rsp), %r8
movq %rax, (%r14)
movq %rbp, 0x10(%r14)
movq 0x198(%rsp), %rdx
movq 0x150(%rsp), %rsi
testq %r8, %r8
je 0x8313c
movq 0x188(%rsp), %r9
movq 0x180(%rsp), %rdi
xorl %eax, %eax
movq %rax, 0x8(%r9)
movq %rax, 0x8(%rdi)
cmpq %rax, 0x10(%rbx)
movq 0x58(%rsp), %r14
je 0x832b8
movq %r13, 0x60(%rsp)
movq %r12, 0x68(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
movq (%rbx), %rax
leaq (%rax,%r12), %rdi
movl 0x30(%rax,%r12), %ecx
movl %ecx, 0x24(%rax,%r12)
movq (%rsi), %rcx
movq %r8, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq %rbp, 0x38(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %r9, 0x20(%rsp)
movq 0x180(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x178(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x170(%rsp), %rax
movq %rax, (%rsp)
movq $0x3e8, 0x8(%rsp)       # imm = 0x3E8
movq 0x68(%rsp), %rsi
movq %r14, %rdx
movq %r8, %r15
movq 0x158(%rsp), %r8
movq %r9, %r13
movq 0x160(%rsp), %r9
movsd 0x50(%rsp), %xmm0
movsd 0x1ae560(%rip), %xmm1   # 0x2315a0
callq 0x823e0
movq %r13, %r9
movq %r15, %r8
movq 0x150(%rsp), %rsi
movq 0x198(%rsp), %rdx
incq %rbp
addq $0xa8, %r12
cmpq 0x10(%rbx), %rbp
jb 0x82fb3
movq 0x178(%rsp), %r14
movq 0x180(%rsp), %rbx
cmpq $0x0, 0x8(%rbx)
je 0x832b8
movq %rbx, %rdi
callq 0x82c14
movq 0x8(%rbx), %rax
testq %rax, %rax
je 0x832b8
movq (%r14), %rdi
movq 0x8(%r14), %rcx
leaq (%rcx,%rax), %rdx
cmpq %rdx, 0x10(%r14)
jae 0x8310e
decq %rdx
movq %rdx, %rax
shrq %rax
orq %rdx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%r14)
leaq (%rcx,%rcx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx), %rsi
incq %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, (%r14)
movq 0x8(%r14), %rcx
movq 0x8(%rbx), %rax
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdi
addq %rdx, %rdi
movq (%rbx), %rsi
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rdx
addq %rax, %rdx
callq 0x2160
movq 0x8(%rbx), %rax
addq %rax, 0x8(%r14)
jmp 0x832b8
movq (%rsi), %rdi
cmpq %r13, 0x10(%rsi)
movq 0x58(%rsp), %rbp
jge 0x83164
movq %r13, %rsi
callq 0x2370
movq 0x150(%rsp), %rsi
movq %rax, %rdi
movq %rax, (%rsi)
movq %r13, 0x10(%rsi)
movq %r13, 0x8(%rsi)
movq %r15, %rsi
movq %r13, %rdx
callq 0x2160
cmpq $0x0, 0x10(%rbx)
je 0x832b1
movq %r12, 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, 0x60(%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 0x1ae38d(%rip), %xmm1   # 0x2315a0
callq 0x823e0
testq %rax, %rax
je 0x83285
cmpq %r15, %r14
je 0x83273
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 0x60(%rsp), %r13
movq %rbp, %rsi
movq 0x58(%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 0x831a7
jmp 0x832b4
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