// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: init_ul_dp(asg_t*, path_dp_t*)
void init_ul_dp(asg_t *g, path_dp_t *dp)
{
    kv_resize(uint8_t, dp->m_dir, (dp->pat.n+1)*(dp->ref.n+1));
    kv_resize(int64_t, dp->m_score, (dp->pat.n+1)*(dp->ref.n+1));
    dp->n = dp->pat.n+1; dp->m = dp->ref.n+1;
    /**
    uint64_t k, s, e, sp, ep, sc;
    dp->m_dir.a[0] = dp->m_score.a[0] = 0; ///[0, 0]
    for (k = 1, sp = ep = (uint64_t)-1; k < dp->n; k++) {///pat; ul read
        s = dp->pat.a[k-1]>>32; e = (dp->pat.a[k-1]>>32) + g->seq[(uint32_t)dp->pat.a[k-1]].len; sc = 0;
        if(ep == (uint64_t)-1 || s >= ep) {
            sc = e - s; sp = s; ep = e;
        } else {
            if(e > ep) sc = e - ep;
        }
        if(((uint32_t)dp->pat.a[k-1]) == ((uint32_t)dp->ref.a[0])) {
            dp->m_score.a[ul_dp_idx(*dp, k, 0)] = dp->m_dir.a[ul_dp_idx(*dp, k, 0)] = 0;
        } else {
            dp->m_score.a[ul_dp_idx(*dp, k, 0)] = dp->m_score.a[ul_dp_idx(*dp, k-1, 0)] + sc;
            dp->m_dir.a[ul_dp_idx(*dp, k, 0)] = lpat_dp;
        }
    }

    for (k = 1, sp = ep = (uint64_t)-1; k < dp->m; k++) {///ref; graph
        s = dp->ref.a[k-1]>>32; e = (dp->ref.a[k-1]>>32) + g->seq[(uint32_t)dp->ref.a[k-1]].len; sc = 0;
        if(ep == (uint64_t)-1 || s >= ep) {
            sc = e - s; sp = s; ep = e;
        } else {
            if(e > ep) sc = e - ep;
        }
        dp->m_score.a[ul_dp_idx(*dp, 0, k)] = dp->m_score.a[ul_dp_idx(*dp, 0, k-1)] + sc;
        dp->m_dir.a[ul_dp_idx(*dp, 0, k)] = lref_dp;
    }
    **/
   uint64_t k; int64_t min_weight = -1*((int64_t)(0xffffffff)); dp->m_dir.a[0] = dp->m_score.a[0] = 0; ///[0, 0]

   for (k = 1; k < dp->n; k++) {///pat; ul read
        if(((uint32_t)dp->pat.a[k-1]) == ((uint32_t)dp->ref.a[0])) {
            dp->m_score.a[ul_dp_idx(*dp, k, 0)] = dp->m_dir.a[ul_dp_idx(*dp, k, 0)] = 0;
        } else {
            dp->m_score.a[ul_dp_idx(*dp, k, 0)] = min_weight;
                        // dp->m_score.a[ul_dp_idx(*dp, k-1, 0)] - g->seq[((uint32_t)dp->pat.a[k-1])>>1].len;
            dp->m_dir.a[ul_dp_idx(*dp, k, 0)] = lpat_dp;
        }
    }

    for (k = 1; k < dp->m; k++) {///ref; graph
        dp->m_score.a[ul_dp_idx(*dp, 0, k)] = min_weight;
                // dp->m_score.a[ul_dp_idx(*dp, 0, k-1)] - g->seq[((uint32_t)dp->ref.a[k-1])>>1].len;
        dp->m_dir.a[ul_dp_idx(*dp, 0, k)] = lref_dp;
    }
}

// Assembly:
pushq %rbx
movq %rsi, %rbx
movq (%rsi), %rdx
movq 0x18(%rsi), %rsi
incq %rsi
incq %rdx
movq %rdx, %rax
imulq %rsi, %rax
cmpq %rax, 0x68(%rbx)
jae 0x1fcc60
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, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
incq %rsi
movq %rsi, 0x68(%rbx)
movq 0x70(%rbx), %rdi
callq 0x2370
movq %rax, 0x70(%rbx)
movq (%rbx), %rdx
movq 0x18(%rbx), %rsi
incq %rsi
incq %rdx
movq %rdx, %rax
imulq %rsi, %rax
cmpq %rax, 0x80(%rbx)
jae 0x1fccd2
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, 0x80(%rbx)
movq 0x88(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x88(%rbx)
movq (%rbx), %rdx
movq 0x18(%rbx), %rsi
incq %rsi
incq %rdx
jmp 0x1fccd9
movq 0x88(%rbx), %rax
movabsq $-0xffffffff, %rcx      # imm = 0xFFFFFFFF00000001
movq %rsi, 0x90(%rbx)
movq %rdx, 0x98(%rbx)
movq $0x0, (%rax)
movq 0x70(%rbx), %rax
movb $0x0, (%rax)
cmpq $0x2, 0x90(%rbx)
jb 0x1fcd77
movl $0x1, %eax
movq 0x10(%rbx), %rsi
movq 0x28(%rbx), %rdx
movl -0x8(%rdx,%rax,8), %edi
movq 0x98(%rbx), %rdx
imulq %rax, %rdx
cmpl (%rsi), %edi
jne 0x1fcd4d
movq 0x70(%rbx), %rsi
movb $0x0, (%rsi,%rdx)
movq 0x88(%rbx), %rdx
movq 0x98(%rbx), %rsi
imulq %rax, %rsi
movq $0x0, (%rdx,%rsi,8)
jmp 0x1fcd6b
movq 0x88(%rbx), %rsi
movq %rcx, (%rsi,%rdx,8)
movq 0x70(%rbx), %rdx
movq 0x98(%rbx), %rsi
imulq %rax, %rsi
movb $0x2, (%rdx,%rsi)
incq %rax
cmpq 0x90(%rbx), %rax
jb 0x1fcd0e
cmpq $0x2, 0x98(%rbx)
jb 0x1fcda5
movl $0x1, %eax
movq 0x88(%rbx), %rdx
movq %rcx, (%rdx,%rax,8)
movq 0x70(%rbx), %rdx
movb $0x3, (%rdx,%rax)
incq %rax
cmpq 0x98(%rbx), %rax
jb 0x1fcd86
popq %rbx
retq