// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: init_poa_dp(ma_ug_t*, poa_dp_t*, poa_g_t*, unsigned long, unsigned long*, unsigned long, unsigned long, uc_block_t*, integer_t*)
void init_poa_dp(ma_ug_t *ug, poa_dp_t *dp, poa_g_t *g, uint64_t g_occ, uint64_t *str, uint64_t str_occ, uint64_t is_rev, uc_block_t *raw, integer_t *buf)
{
    kv_resize(uint8_t, dp->dir, (str_occ+1)*(g_occ+1));
    kv_resize(int64_t, dp->sc, (str_occ+1)*(g_occ+1));
    kv_resize(uint64_t, dp->prefix, (str_occ+1)*(g_occ+1));
    dp->n = str_occ+1; dp->m = g_occ+1;
    kv_resize(uint64_t, buf->u, str_occ);
    int64_t *sc = dp->sc.a, bsc, ss; uint8_t *dir = dp->dir.a; uint64_t k, l, *str_w = buf->u.a, *prefix = dp->prefix.a, m; 
    uc_block_t *z; uint32_t *g_idx = g->srt_b.res.a, *n2gidx = g->srt_b.res2nid.a, v, w, a_n, bsc_i; poa_arc_t *a; 
    for (k = 0; k < str_occ; k++) {
        z = &(raw[str[k]>>32]); str_w[k] = ug_occ_w(z->ts, z->te, &(ug->u.a[z->hid]));
    }
    
    sc[poa_dp_idx(*dp, 0, 0)] = dir[poa_dp_idx(*dp, 0, 0)] = 0;
    for (k = 1, l = 0; k < dp->n; k++) {///pat; new ul read
        l += str_w[poa_str_idx(k-1, str_occ, is_rev)];
        sc[poa_dp_idx(*dp, k, 0)] = l;
        dir[poa_dp_idx(*dp, k, 0)] = lstr_dp;
        prefix[poa_dp_idx(*dp, k, 0)] = ((k - 1)<<32);
    }
    
    for (k = 1; k < dp->m; k++) {///ref; graph
        v = (g_idx[k-1]<<1) + 1;
        a_n = poa_arc_n(g, v); a = poa_arc_a(g, v);
        for (m = 0, bsc = bsc_i = 0; m < a_n; m++) {
            w = n2gidx[a[m].v>>1]; assert(w+1 < k);
            ss = sc[poa_dp_idx(*dp, 0, w+1)];
            if(ss < bsc || bsc_i == 0) {
                bsc = ss; bsc_i = w + 1;
            }
        }
        sc[poa_dp_idx(*dp, 0, k)] = bsc + g->seq.a[v>>1].occ;
        dir[poa_dp_idx(*dp, 0, k)] = lref_dp;
        prefix[poa_dp_idx(*dp, 0, k)] = bsc_i;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %r15
movq %r8, 0x30(%rsp)
movq %rcx, %rbp
movq %rdx, 0x10(%rsp)
movq %rsi, %r14
movq %rdi, 0x28(%rsp)
leaq 0x1(%r9), %rbx
incq %rbp
movq %rbx, %r12
imulq %rbp, %r12
cmpq %r12, 0x20(%rsi)
jae 0x1b7790
leaq -0x1(%r12), %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, 0x20(%r14)
movq 0x28(%r14), %rdi
callq 0x2370
movq %rax, 0x28(%r14)
cmpq %r12, 0x8(%r14)
jae 0x1b77e9
leaq -0x1(%r12), %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, 0x8(%r14)
movq 0x10(%r14), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, 0x10(%r14)
movq 0x80(%rsp), %r13
cmpq %r12, 0x38(%r14)
jae 0x1b7848
decq %r12
movq %r12, %rax
shrq %rax
orq %r12, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x38(%r14)
movq 0x40(%r14), %rdi
leaq 0x8(,%rax,8), %rsi
callq 0x2370
movq %rax, 0x40(%r14)
movq %rbx, 0x48(%r14)
movq %r14, 0x8(%rsp)
movq %rbp, 0x50(%r14)
cmpq %r15, 0x98(%r13)
jae 0x1b78be
leaq -0x1(%r15), %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, 0x98(%r13)
movq 0xa0(%r13), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq %rax, %rbp
movq %rax, 0xa0(%r13)
jmp 0x1b78c5
movq 0xa0(%r13), %rbp
movq 0x78(%rsp), %r13
movq 0x8(%rsp), %rax
movq 0x10(%rax), %r12
movq 0x28(%rax), %rcx
movq %rcx, (%rsp)
movq 0x40(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %rax
movq 0x90(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0xa8(%rax), %rbx
xorl %r14d, %r14d
cmpq %r14, %r15
je 0x1b793d
movq 0x30(%rsp), %rax
movl 0x4(%rax,%r14,8), %eax
imulq $0x24, %rax, %rax
movl (%r13,%rax), %ecx
movl 0xc(%r13,%rax), %edi
movl 0x10(%r13,%rax), %esi
imulq $0x28, %rcx, %rdx
movq 0x28(%rsp), %rax
addq 0x10(%rax), %rdx
callq 0x1b2312
movq %rax, (%rbp,%r14,8)
incq %r14
jmp 0x1b78ff
movq (%rsp), %rax
movb $0x0, (%rax)
andq $0x0, (%r12)
decq %r15
pushq $0x1
popq %rax
xorl %ecx, %ecx
movabsq $0x100000000, %rdx      # imm = 0x100000000
xorl %esi, %esi
movq 0x8(%rsp), %r13
movq 0x70(%rsp), %r9
cmpq 0x48(%r13), %rax
jae 0x1b79b6
leaq -0x1(%rax), %rdi
testq %r9, %r9
cmovneq %r15, %rdi
addq (%rbp,%rdi,8), %rsi
movq 0x50(%r13), %rdi
imulq %rax, %rdi
movq %rsi, (%r12,%rdi,8)
movq 0x50(%r13), %rdi
imulq %rax, %rdi
movq (%rsp), %r8
movb $0x2, (%r8,%rdi)
movq 0x50(%r13), %rdi
imulq %rax, %rdi
movq 0x18(%rsp), %r8
movq %rcx, (%r8,%rdi,8)
addq %rdx, %rcx
decq %r15
incq %rax
jmp 0x1b7967
pushq $0x1
popq %rax
movq 0x10(%rsp), %r15
cmpq 0x50(%r13), %rax
jae 0x1b7a6d
movq 0x20(%rsp), %rcx
movl -0x4(%rcx,%rax,4), %ecx
leal (%rcx,%rcx), %edx
movq 0x28(%r15), %rsi
movq 0x40(%r15), %rdi
movq 0x8(%rdi,%rdx,8), %rdi
movl %edi, %edx
shlq $0x4, %rdx
shrq $0x1c, %rdi
andq $-0x10, %rdi
addq %rsi, %rdi
addq $0x8, %rdi
xorl %r8d, %r8d
xorl %esi, %esi
xorl %r9d, %r9d
cmpq %r8, %rdx
je 0x1b7a3e
movl (%rdi,%r8), %r10d
shrl %r10d
movl (%rbx,%r10,4), %r10d
incl %r10d
cmpq %r10, %rax
jbe 0x1b7a7c
movq (%r12,%r10,8), %r11
cmpq %r9, %r11
setl %bpl
testl %esi, %esi
sete %r14b
orb %bpl, %r14b
jne 0x1b7a32
movl %esi, %r10d
movq %r9, %r11
addq $0x10, %r8
movl %r10d, %esi
movq %r11, %r9
jmp 0x1b79fe
movq 0x10(%r15), %rdx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl (%rdx,%rcx,8), %ecx
addq %rcx, %r9
movq %r9, (%r12,%rax,8)
movq (%rsp), %rcx
movb $0x3, (%rcx,%rax)
movl %esi, %ecx
movq 0x18(%rsp), %rdx
movq %rcx, (%rdx,%rax,8)
incq %rax
jmp 0x1b79be
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4144c(%rip), %rdi     # 0x1f8ecf
leaq 0x3fa4f(%rip), %rsi     # 0x1f74d9
leaq 0x41446(%rip), %rcx     # 0x1f8ed7
movl $0x1673, %edx           # imm = 0x1673
callq 0x2110