// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Correct.cpp
// Function: gen_rphase_dp0_multiple_path(SnpStats*, long, haplotype_evdience*, Chain_Data*, asg64_v*, asg64_v*)
void gen_rphase_dp0_multiple_path(SnpStats *a, int64_t an, haplotype_evdience *za, Chain_Data *dp, asg64_v *idx, asg64_v *res)
{
    if(an <= 0) return;
    int64_t *p, *t, i, k, j, max_f, sc, ch_n, plus = 0, rn; int32_t *f, *ii; uint64_t m;
    resize_Chain_Data(dp, an, NULL); idx->n = res->n = 0;
    t = dp->tmp; f = dp->score; p = dp->pre; ii = dp->occ;

    for (i = 0; i < an; ++i) {
        max_f = 1; ch_n = idx->n;
        for (j = i - 1; j >= 0; --j) {
            sc = comput_sc_rphase(&a[i], i, &a[j], j, za, 0);
            if (sc == INT64_MIN) continue;
            sc += f[j];
            if (sc > max_f) {
                max_f = sc; 
                idx->n = ch_n; kv_push(uint64_t, *idx, j);
            } else if (sc == max_f) {
                kv_push(uint64_t, *idx, j);
            }
        }

        f[i] = max_f; p[i] = idx->n; ii[i] = 0;
        if(f[i] < plus) plus = f[i];
    }
    ch_n = idx->n;

    for (i = 0; i < an; i++) {
        f[i] -= plus;
        m = f[i]; m = ((uint32_t)-1) - m; m <<= 32; m |= i;
        kv_push(uint64_t, *idx, m);
    }
    radix_sort_bc64(idx->a + ch_n, idx->a + idx->n);

    for (i = 0; i < an; i++) {///idx->a:: [0, ch_n) -> tree; [ch_n, ch_n + an) -> sort; [ch_n + an, -1) -> path
        k = (uint32_t)idx->a[ch_n + i];
        if(ii[k]) continue;
        gen_rphase_path(idx, p, ii, t, k, res);
    }

    rn = res->n;
    for (k = 1, i = 0; k <= rn; k++) {
        if(k == rn || (res->a[i]>>32) != (res->a[k]>>32)) {
            if(k - i > 0) {
                fprintf(stderr, "\n[M::%s]\tcnt::%lu\n", __func__, k - i);
                for (j = i; j < k; j++) {
                    fprintf(stderr, "pos::%u\n", a[(uint32_t)res->a[j]].site);
                    // if(k - i == 2) {
                    //     dbg_prt_rphase_vec(&(a[(uint32_t)res->a[j]]), (uint32_t)res->a[j], za);
                    // }
                }
            }
            i = k;
        }
    }
    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, (%rsp)
movq %rdx, 0x70(%rsp)
movq %rdi, 0x8(%rsp)
testq %rsi, %rsi
jle 0x254d6
movq %r8, %r15
movq %rcx, %r14
movq %rsi, %r12
xorl %r13d, %r13d
movq %rcx, %rdi
xorl %edx, %edx
callq 0x1383e
movq (%rsp), %rax
andq $0x0, (%rax)
andq $0x0, (%r15)
movq 0x28(%r14), %rax
movq %rax, 0x38(%rsp)
movq (%r14), %rax
movq %rax, 0x20(%rsp)
movq 0x8(%r14), %rax
movq %rax, 0x30(%rsp)
movq 0x20(%r14), %rbp
movq 0x8(%rsp), %rax
addq $-0x28, %rax
movq %rax, 0x68(%rsp)
movq $0x0, 0x18(%rsp)
xorl %ebx, %ebx
movq %r15, 0x10(%rsp)
movq %r12, 0x48(%rsp)
movq %rbp, 0x40(%rsp)
cmpq %r12, %rbx
je 0x25372
imulq $0x28, %rbx, %rbp
addq 0x8(%rsp), %rbp
leaq (,%r13,2), %rcx
movq %r13, 0x60(%rsp)
testq %r13, %r13
pushq $0x2
popq %rax
cmoveq %rax, %rcx
movq %rcx, 0x58(%rsp)
leaq (,%rcx,8), %rax
movq %rax, 0x50(%rsp)
pushq $0x1
popq %rax
movq %rax, 0x28(%rsp)
movq %rbx, %r13
imulq $0x28, %r13, %r12
addq 0x68(%rsp), %r12
movq %r13, %r14
testq %r14, %r14
jle 0x25328
leaq -0x1(%r14), %r13
movq %rbp, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq 0x70(%rsp), %r8
xorl %r9d, %r9d
callq 0x53aca
movq %rax, %r15
negq %rax
jo 0x2528f
movq 0x20(%rsp), %rax
movslq -0x4(%rax,%r14,4), %rax
addq %rax, %r15
cmpq 0x28(%rsp), %r15
jg 0x25298
je 0x252de
addq $-0x28, %r12
decq %r14
jmp 0x2524b
movq 0x10(%rsp), %r14
movq 0x60(%rsp), %rcx
movq %rcx, (%r14)
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x252cc
movq 0x58(%rsp), %rcx
movq %rcx, 0x8(%r14)
movq %rax, %rdi
movq 0x50(%rsp), %rsi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
leaq (%rax,%rcx,8), %rax
movq %r15, 0x28(%rsp)
jmp 0x25320
movq 0x10(%rsp), %r14
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x25315
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
leaq (%rax,%rcx,8), %rax
movq %r13, (%rax)
jmp 0x2523f
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rax
movl %eax, (%rcx,%rbx,4)
movq 0x10(%rsp), %r15
movq (%r15), %r13
movq 0x30(%rsp), %rax
movq %r13, (%rax,%rbx,8)
movq 0x40(%rsp), %rbp
andl $0x0, (%rbp,%rbx,4)
movslq (%rcx,%rbx,4), %rax
movq 0x18(%rsp), %rcx
cmpq %rax, %rcx
cmovgeq %rax, %rcx
movq %rcx, 0x18(%rsp)
incq %rbx
movq 0x48(%rsp), %r12
jmp 0x251f9
xorl %ebx, %ebx
cmpq %rbx, %r12
je 0x253d7
movq 0x20(%rsp), %rax
movl (%rax,%rbx,4), %r14d
subl 0x18(%rsp), %r14d
movl %r14d, (%rax,%rbx,4)
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x253bd
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r15), %rcx
notl %r14d
shlq $0x20, %r14
orq %rbx, %r14
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
movq %r14, (%rax,%rcx,8)
incq %rbx
jmp 0x25374
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq (%rcx,%r13,8), %rdi
leaq (%rcx,%rax,8), %rsi
callq 0x1905d
movq 0x38(%rsp), %rbx
subq $0x1, %r12
jb 0x25422
movq 0x10(%r15), %rax
movl (%rax,%r13,8), %r8d
cmpl $0x0, (%rbp,%r8,4)
jne 0x2541d
movq %r15, %rdi
movq 0x30(%rsp), %rsi
movq %rbp, %rdx
movq %rbx, %rcx
movq (%rsp), %r9
callq 0x24ef5
incq %r13
jmp 0x253f0
movq (%rsp), %rax
movq (%rax), %r12
testq %r12, %r12
movl $0x0, %r13d
cmovgq %r12, %r13
incq %r13
pushq $0x1
popq %rbp
movq 0x22db9d(%rip), %rbx    # 0x252fe0
leaq 0x1be9ea(%rip), %r15    # 0x1e3e34
xorl %r14d, %r14d
cmpq %r13, %rbp
je 0x254d6
cmpq %r12, %rbp
je 0x25476
movq (%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax,%rbp,8), %rcx
xorq (%rax,%r14,8), %rcx
shrq $0x20, %rcx
jne 0x25476
movq %r14, %rax
jmp 0x25481
movq %rbp, %rcx
movq %rbp, %rax
subq %r14, %rcx
jg 0x25489
incq %rbp
movq %rax, %r14
jmp 0x2544d
movq (%rbx), %rdi
leaq 0x1be971(%rip), %rsi    # 0x1e3e04
leaq 0x1be97d(%rip), %rdx    # 0x1e3e17
xorl %eax, %eax
callq 0x22b0
cmpq %rbp, %r14
jge 0x254d1
movq (%rbx), %rdi
movq (%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%r14,8), %eax
imulq $0x28, %rax, %rax
movq 0x8(%rsp), %rcx
movl 0x20(%rcx,%rax), %edx
movq %r15, %rsi
xorl %eax, %eax
callq 0x22b0
incq %r14
jmp 0x254a1
movq %rbp, %rax
jmp 0x25481
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq