// File: /workspace/github_cpp_makefile_star2_O1/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), %rax
movq 0x18(%rsi), %rcx
incq %rcx
incq %rax
imulq %rcx, %rax
cmpq %rax, 0x68(%rsi)
jae 0x1f16ac
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), %rax
movq 0x18(%rbx), %rcx
incq %rcx
incq %rax
imulq %rcx, %rax
cmpq %rax, 0x80(%rbx)
jae 0x1f1720
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)
movabsq $-0xffffffff, %rax      # imm = 0xFFFFFFFF00000001
movq (%rbx), %rcx
movq 0x18(%rbx), %rdx
incq %rdx
movq %rdx, 0x90(%rbx)
incq %rcx
movq %rcx, 0x98(%rbx)
movq 0x88(%rbx), %rcx
movq $0x0, (%rcx)
movq 0x70(%rbx), %rcx
movb $0x0, (%rcx)
cmpq $0x2, 0x90(%rbx)
jb 0x1f17d2
movl $0x1, %ecx
movq 0x10(%rbx), %rsi
movq 0x28(%rbx), %rdx
movl -0x8(%rdx,%rcx,8), %edi
movq 0x98(%rbx), %rdx
imulq %rcx, %rdx
cmpl (%rsi), %edi
jne 0x1f17a8
movq 0x70(%rbx), %rsi
movb $0x0, (%rsi,%rdx)
movq 0x88(%rbx), %rdx
movq 0x98(%rbx), %rsi
imulq %rcx, %rsi
movq $0x0, (%rdx,%rsi,8)
jmp 0x1f17c6
movq 0x88(%rbx), %rsi
movq %rax, (%rsi,%rdx,8)
movq 0x70(%rbx), %rdx
movq 0x98(%rbx), %rsi
imulq %rcx, %rsi
movb $0x2, (%rdx,%rsi)
incq %rcx
cmpq 0x90(%rbx), %rcx
jb 0x1f1769
cmpq $0x2, 0x98(%rbx)
jb 0x1f1800
movl $0x1, %ecx
movq 0x88(%rbx), %rdx
movq %rax, (%rdx,%rcx,8)
movq 0x70(%rbx), %rdx
movb $0x3, (%rdx,%rcx)
incq %rcx
cmpq 0x98(%rbx), %rcx
jb 0x1f17e1
popq %rbx
retq