// File: /workspace/github_cpp_makefile_star2_O1/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 %rdx, %r15
movq %rdi, 0x18(%rsp)
movl 0x90(%rsp), %r12d
movl 0x80(%rsp), %r9d
testq %r8, %r8
jle 0x1f1fc8
movq %r8, %rbp
movq %r15, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq 0x48(%rsi), %r11
movl %r9d, %ebx
shrl %ebx
movq $-0x1, %rdi
xorl %r14d, %r14d
xorl %r13d, %r13d
movl %ebx, 0x14(%rsp)
movq (%rcx,%r13,8), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x58, %rax, %rax
movq 0x30(%r11,%rax), %rsi
leaq (%rdx,%rdx,8), %rdx
movzbl 0x20(%rsi,%rdx,4), %eax
testb $0x40, %al
jne 0x1f20a5
testb %al, %al
jns 0x1f20a5
leaq (%rsi,%rdx,4), %rdx
movl (%rdx), %esi
cmpl %ebx, %esi
jne 0x1f20a5
testb $0x1f, %al
je 0x1f1faa
shrl $0x5, %eax
andl $0x1, %eax
leal (%rax,%rsi,2), %eax
testl %r12d, %r12d
je 0x1f1f5e
cmpl $-0x1, 0x14(%rdx)
je 0x1f1faa
xorl $0x1, %eax
jmp 0x1f1f64
cmpl $-0x1, 0x1c(%rdx)
je 0x1f1faa
cmpl %r9d, %eax
jne 0x1f1faa
movq %rdi, 0x38(%rsp)
movq 0x8(%rsp), %rdi
movl %r9d, %esi
movl %r9d, %r15d
movq %rcx, %rbx
movq %r14, 0x30(%rsp)
movq %r11, %r14
callq 0x1f0877
movq %r14, %r11
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %rdi
movq %rbx, %rcx
movl 0x14(%rsp), %ebx
movl %r15d, %r9d
addq %rax, %r14
testq %rax, %rax
cmovneq %r13, %rdi
incq %r13
cmpq %r13, %rbp
jne 0x1f1f07
testq %r14, %r14
sete %al
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %rsi
jmp 0x1f1fd1
movq $-0x1, %rdi
movb $0x1, %al
testb %al, %al
jne 0x1f2094
movq 0x48(%rsi), %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 %r12
callq 0x1f0968
addq $0x10, %rsp
movq 0xa8(%r15), %rax
cmpq $0x1, %rax
je 0x1f2094
testq %rax, %rax
je 0x1f20c4
movl %ebx, %ecx
movl 0x88(%rsp), %r8d
movq 0x40(%rsp), %rdx
movsd 0x33440(%rip), %xmm0    # 0x225480
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1f0f42
movsd 0x33458(%rip), %xmm1    # 0x2254b0
movq %rbx, %rsi
movq %r14, %rdx
movsd 0x3341a(%rip), %xmm0    # 0x225480
callq 0x1f1349
testl %eax, %eax
je 0x1f2094
movsd 0x33481(%rip), %xmm0    # 0x2254f8
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x1f1905
xorl %ecx, %ecx
testq %rax, %rax
cmovleq %rcx, %rax
jmp 0x1f2096
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x47d60(%rip), %rdi     # 0x239e0c
leaq 0x47272(%rip), %rsi     # 0x239325
leaq 0x47d7a(%rip), %rcx     # 0x239e34
movl $0xec3, %edx            # imm = 0xEC3
callq 0x2110
leaq 0x47dd9(%rip), %rdi     # 0x239ea4
leaq 0x47253(%rip), %rsi     # 0x239325
leaq 0x47d5b(%rip), %rcx     # 0x239e34
movl $0xee4, %edx            # imm = 0xEE4
callq 0x2110