// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: ul_dp(bubble_type*, all_ul_t*, ubuf_t*, unsigned long*, long, asg_t*, unsigned int, unsigned int, unsigned int)
uint64_t ul_dp(bubble_type* bub, all_ul_t *ul, ubuf_t *b, uint64_t *a, int64_t a_n, asg_t *g, uint32_t v, uint32_t w, uint32_t is_backward)
{
    int64_t i, m, a_i = -1; uc_block_t *p; uint32_t gv; uint64_t url; int64_t we;
    for (i = m = 0; i < a_n; i++) {
        p = &(ul->a[a[i]>>32].bb.a[(uint32_t)(a[i])]);
        assert((!p->base)&&(p->hid == (v>>1))&&(p->el)/**&&(p->pchain)**/);
        if(!p->pchain) continue;
        gv = (((uint32_t)(p->hid))<<1)|((uint32_t)(p->rev));
        if(is_backward) {
            gv ^= 1;
            if(p->pidx == (uint32_t)-1) continue;
        } else {
            if(p->aidx == (uint32_t)-1) continue;
        }
        if(gv != v) continue;
        // fprintf(stderr, "[M::%s::] i:%ld, a_n:%lu, v:%u, w:%u, ulid:%lu, uidx:%u, is_backward:%u\n", 
        // __func__, i, a_n, v, w, a[i]>>32, (uint32_t)(a[i]), is_backward);
        // if(v == 6 && w == 5 && (a[i]>>32) == 95) {
        // int64_t z;
        //     for (z = 0; z < ul->a[a[i]>>32].bb.n; z++) {
        //         fprintf(stderr, "[M::%s::vid->%u] qs:%u, qe:%u, qlen:%u, ts:%u, te:%u, tlen:%u\n", __func__, 
        //         (((uint32_t)(ul->a[a[i]>>32].bb.a[z].hid))<<1)|((uint32_t)(ul->a[a[i]>>32].bb.a[z].rev)), 
        //         ul->a[a[i]>>32].bb.a[z].qs, ul->a[a[i]>>32].bb.a[z].qe, ul->a[a[i]>>32].rlen, 
        //         ul->a[a[i]>>32].bb.a[z].ts, ul->a[a[i]>>32].bb.a[z].te, g->seq[ul->a[a[i]>>32].bb.a[z].hid].len);
        //     }
        // }
        if(ulg_len_check(g, v, p) == 0) continue;///too short
        m++; a_i = i;
    }
    
    if(m == 0) return 0;
    // uint32_t is_debug = (v == 231);
    // if(is_debug) {
    //     fprintf(stderr, "\n+[M::%s::] m->%ld, ulid->%lu\n", __func__, m, a[a_i]>>32);
    // }

    p = &(ul->a[a[a_i]>>32].bb.a[(uint32_t)(a[a_i])]);//longest one
    m = gen_ul_pat_seq(ul->a[a[a_i]>>32].bb.a, &(b->dp), ul, (uint32_t)(a[a_i]), g, v, is_backward, &url);
    assert(b->dp.pat.n > 0);

    // if(is_debug) {
    //     for (i = 0; i < (int64_t)b->dp.pat.n; i++) {
    //         fprintf(stderr, "pat[M::%s::] utg%.6dl(%c), d::%lu\n", __func__, 
    //         (((uint32_t)b->dp.pat.a[i])>>1)+1, "+-"[((uint32_t)b->dp.pat.a[i])&1], b->dp.pat.a[i]>>32);
    //     }
    // }
    if(b->dp.pat.n == 1) return 0;
    gen_ref_pat_seq(g, b, url, UL_TRAV_HERATE, v, w/**, is_debug**/);

    // if(is_debug) {
    //     for (i = 0; i < (int64_t)b->dp.ref.n; i++) {
    //         fprintf(stderr, "ref[M::%s::] utg%.6dl(%c), d::%lu\n", __func__, 
    //         (((uint32_t)b->dp.ref.a[i])>>1)+1, "+-"[((uint32_t)b->dp.ref.a[i])&1], b->dp.ref.a[i]>>32);
    //     }
    // }

    if(!quick_check(ul->a[a[a_i]>>32].bb.a, g, &(b->dp), UL_TRAV_HERATE, UL_TRAV_FT_RATE)) return 0;
    we = ul_dp0(bub, g, &(b->dp), 0.9/**, is_debug**/);
    if(we < 0) return 0;
    return we;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, (%rsp)
movq %rcx, %rbp
movq %rdx, 0x10(%rsp)
movq %rsi, %r11
movq %rdi, 0x18(%rsp)
movl 0x80(%rsp), %r13d
movl 0x70(%rsp), %r9d
movl %r9d, %edi
shrl %edi
xorl %ebx, %ebx
testq %r8, %r8
cmovleq %rbx, %r8
movl %r9d, %r15d
andl $-0x2, %r15d
pushq $-0x1
popq %r10
xorl %r14d, %r14d
movq %r8, 0x20(%rsp)
movl %r15d, 0xc(%rsp)
movl %edi, 0x8(%rsp)
cmpq %rbx, %r8
je 0x1b170d
movq 0x48(%r11), %rax
movq (%rbp,%rbx,8), %rcx
movl %ecx, %esi
shrq $0x20, %rcx
imulq $0x58, %rcx, %rcx
movq 0x30(%rax,%rcx), %rdx
imulq $0x24, %rsi, %rcx
movzbl 0x20(%rdx,%rcx), %eax
testb $0x40, %al
jne 0x1b17e4
testb %al, %al
jns 0x1b17e4
addq %rcx, %rdx
cmpl %edi, (%rdx)
jne 0x1b17e4
testb $0x1f, %al
je 0x1b1705
shrl $0x5, %eax
andl $0x1, %eax
orl %r15d, %eax
testl %r13d, %r13d
je 0x1b16c0
cmpl $-0x1, 0x14(%rdx)
je 0x1b1705
xorl $0x1, %eax
jmp 0x1b16c6
cmpl $-0x1, 0x1c(%rdx)
je 0x1b1705
cmpl %r9d, %eax
jne 0x1b1705
movq %r10, 0x28(%rsp)
movq (%rsp), %rdi
movl %r9d, %esi
movl %r9d, %r15d
movq %r11, %r12
callq 0x1b01be
movl 0x8(%rsp), %edi
movq 0x28(%rsp), %r10
movq 0x20(%rsp), %r8
movq %r12, %r11
movl %r15d, %r9d
movl 0xc(%rsp), %r15d
addq %rax, %r14
testq %rax, %rax
cmovneq %rbx, %r10
incq %rbx
jmp 0x1b165e
testq %r14, %r14
je 0x1b17d3
movq 0x48(%r11), %rax
movq (%rbp,%r10,8), %rdx
movl %edx, %ecx
shrq $0x20, %rdx
imulq $0x58, %rdx, %rdx
movq 0x30(%rax,%rdx), %rdi
movq 0x10(%rsp), %rbx
leaq 0x90(%rbx), %r14
leaq 0x30(%rsp), %rax
movq %r14, %rsi
movq (%rsp), %r8
movl %r9d, %ebp
pushq %rax
pushq %r13
callq 0x1b02af
addq $0x10, %rsp
movq 0xa8(%rbx), %rax
cmpq $0x1, %rax
je 0x1b17d3
testq %rax, %rax
je 0x1b1803
movq 0x30(%rsp), %rdx
movsd 0x31d58(%rip), %xmm0    # 0x1e34d0
movq (%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movl %ebp, %ecx
movl 0x78(%rsp), %r8d
callq 0x1b081c
movsd 0x31d68(%rip), %xmm1    # 0x1e3500
movq %rbx, %rsi
movq %r14, %rdx
movsd 0x31d2a(%rip), %xmm0    # 0x1e34d0
callq 0x1b0bef
testl %eax, %eax
je 0x1b17d3
movsd 0x31d89(%rip), %xmm0    # 0x1e3540
movq 0x18(%rsp), %rdi
movq (%rsp), %rsi
movq %r14, %rdx
callq 0x1b114b
xorl %ecx, %ecx
testq %rax, %rax
cmovleq %rcx, %rax
jmp 0x1b17d5
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x467d5(%rip), %rdi     # 0x1f7fc0
leaq 0x45ce7(%rip), %rsi     # 0x1f74d9
leaq 0x467ef(%rip), %rcx     # 0x1f7fe8
movl $0xec3, %edx            # imm = 0xEC3
callq 0x2110
leaq 0x4684e(%rip), %rdi     # 0x1f8058
leaq 0x45cc8(%rip), %rsi     # 0x1f74d9
leaq 0x467d0(%rip), %rcx     # 0x1f7fe8
movl $0xee4, %edx            # imm = 0xEE4
callq 0x2110