// File: 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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rdx
movq (%rdx), %rdx
addq $0x1, %rdx
imulq %rdx, %rcx
cmpq %rcx, %rax
jae 0x32479a
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
addq $0x1, %rax
imulq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
shrq %rcx
movq -0x10(%rbp), %rax
orq 0x68(%rax), %rcx
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
shrq $0x2, %rcx
movq -0x10(%rbp), %rax
orq 0x68(%rax), %rcx
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
shrq $0x4, %rcx
movq -0x10(%rbp), %rax
orq 0x68(%rax), %rcx
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
shrq $0x8, %rcx
movq -0x10(%rbp), %rax
orq 0x68(%rax), %rcx
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
shrq $0x10, %rcx
movq -0x10(%rbp), %rax
orq 0x68(%rax), %rcx
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rsi
shlq $0x0, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
jmp 0x32479c
jmp 0x32479e
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rdx
movq (%rdx), %rdx
addq $0x1, %rdx
imulq %rdx, %rcx
cmpq %rcx, %rax
jae 0x3248f0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
addq $0x1, %rax
imulq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x80(%rax)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rcx
shrq %rcx
movq -0x10(%rbp), %rax
orq 0x80(%rax), %rcx
movq %rcx, 0x80(%rax)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rcx
shrq $0x2, %rcx
movq -0x10(%rbp), %rax
orq 0x80(%rax), %rcx
movq %rcx, 0x80(%rax)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rcx
shrq $0x4, %rcx
movq -0x10(%rbp), %rax
orq 0x80(%rax), %rcx
movq %rcx, 0x80(%rax)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rcx
shrq $0x8, %rcx
movq -0x10(%rbp), %rax
orq 0x80(%rax), %rcx
movq %rcx, 0x80(%rax)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rcx
shrq $0x10, %rcx
movq -0x10(%rbp), %rax
orq 0x80(%rax), %rcx
movq %rcx, 0x80(%rax)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x80(%rax)
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x88(%rax)
jmp 0x3248f2
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x90(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x98(%rax)
movabsq $-0xffffffff, %rax      # imm = 0xFFFFFFFF00000001
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movb $0x0, (%rax)
movq $0x1, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x90(%rcx), %rax
jae 0x324a1d
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x18(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx), %rcx
cmpl %ecx, %eax
jne 0x3249cb
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x98(%rcx), %rcx
imulq -0x18(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x98(%rcx), %rcx
imulq -0x18(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x324a0a
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x98(%rcx), %rcx
imulq -0x18(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x98(%rcx), %rcx
imulq -0x18(%rbp), %rcx
movb $0x2, (%rax,%rcx)
jmp 0x324a0c
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x324952
movq $0x1, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x98(%rcx), %rax
jae 0x324a83
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x10(%rbp), %rcx
imulq $0x0, 0x98(%rcx), %rcx
addq -0x18(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x10(%rbp), %rcx
imulq $0x0, 0x98(%rcx), %rcx
addq -0x18(%rbp), %rcx
movb $0x3, (%rax,%rcx)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x324a25
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)