// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %r9, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
testq %r8, %r8
jle 0x1fd61e
movq %rdx, 0x28(%rsp)
movl 0x90(%rsp), %r13d
movl 0x80(%rsp), %r9d
movq %rsi, 0x20(%rsp)
movq 0x48(%rsi), %r12
movl %r9d, %ebx
shrl %ebx
movl %r9d, %r14d
andl $-0x2, %r14d
movq $-0x1, %rdi
xorl %r15d, %r15d
xorl %ebp, %ebp
movl %ebx, 0x14(%rsp)
movl %r14d, 0x10(%rsp)
movq (%rcx,%rbp,8), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x58, %rax, %rax
movq 0x30(%r12,%rax), %rsi
leaq (%rdx,%rdx,8), %rdx
movzbl 0x20(%rsi,%rdx,4), %eax
testb $0x40, %al
jne 0x1fd62f
testb %al, %al
jns 0x1fd62f
leaq (%rsi,%rdx,4), %rdx
cmpl %ebx, (%rdx)
jne 0x1fd62f
testb $0x1f, %al
je 0x1fd544
shrl $0x5, %eax
andl $0x1, %eax
orl %r14d, %eax
testl %r13d, %r13d
je 0x1fd4f3
cmpl $-0x1, 0x14(%rdx)
je 0x1fd544
xorl $0x1, %eax
jmp 0x1fd4f9
cmpl $-0x1, 0x1c(%rdx)
je 0x1fd544
cmpl %r9d, %eax
jne 0x1fd544
movq %rdi, 0x38(%rsp)
movq 0x8(%rsp), %rdi
movl %r9d, %esi
movq %r15, 0x30(%rsp)
movl %r9d, %r15d
movq %rcx, %r14
movq %r8, %rbx
callq 0x1fbe0d
movq 0x38(%rsp), %rdi
movq %rbx, %r8
movl 0x14(%rsp), %ebx
movq %r14, %rcx
movl 0x10(%rsp), %r14d
movl %r15d, %r9d
movq 0x30(%rsp), %r15
addq %rax, %r15
testq %rax, %rax
cmovneq %rbp, %rdi
incq %rbp
cmpq %rbp, %r8
jne 0x1fd49e
testq %r15, %r15
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %rax
je 0x1fd61e
movq 0x48(%rax), %rax
movq (%rcx,%rdi,8), %rdx
movl %edx, %ecx
shrq $0x20, %rdx
imulq $0x58, %rdx, %rdx
movq 0x30(%rax,%rdx), %rdi
leaq 0x90(%r15), %r14
leaq 0x40(%rsp), %rax
movq %r14, %rsi
movq 0x8(%rsp), %r8
movl %r9d, %ebx
pushq %rax
pushq %r13
callq 0x1fbeff
addq $0x10, %rsp
movq 0xa8(%r15), %rax
cmpq $0x1, %rax
je 0x1fd61e
testq %rax, %rax
je 0x1fd64e
movl %ebx, %ecx
movq 0x40(%rsp), %rdx
movsd 0x33fbe(%rip), %xmm0    # 0x231580
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movl 0x88(%rsp), %r8d
callq 0x1fc511
movsd 0x33fce(%rip), %xmm1    # 0x2315b0
movq %rbx, %rsi
movq %r14, %rdx
movsd 0x33f90(%rip), %xmm0    # 0x231580
callq 0x1fc919
testl %eax, %eax
je 0x1fd61e
movsd 0x33ff7(%rip), %xmm0    # 0x2315f8
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x1fceaa
xorl %ecx, %ecx
testq %rax, %rax
cmovleq %rcx, %rax
jmp 0x1fd620
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48aba(%rip), %rdi     # 0x2460f0
leaq 0x47fcc(%rip), %rsi     # 0x245609
leaq 0x48ad4(%rip), %rcx     # 0x246118
movl $0xec3, %edx            # imm = 0xEC3
callq 0x2110
leaq 0x48b33(%rip), %rdi     # 0x246188
leaq 0x47fad(%rip), %rsi     # 0x245609
leaq 0x48ab5(%rip), %rcx     # 0x246118
movl $0xee4, %edx            # imm = 0xEE4
callq 0x2110