// File: /workspace/github_cpp_makefile_star2_O3/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 $0x98, %rsp
movq %r9, 0x8(%rsp)
testq %rsi, %rsi
jle 0x537c3
movq %r8, %rbp
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
xorl %r12d, %r12d
movq %rcx, %rdi
xorl %edx, %edx
callq 0x3ecb0
movq 0x8(%rsp), %rax
movq %r12, (%rax)
movq %r12, (%rbp)
movq 0x28(%r13), %rax
movq %rax, 0x70(%rsp)
movq (%r13), %rax
movq %rax, 0x38(%rsp)
movq 0x8(%r13), %rax
movq %rax, 0x50(%rsp)
movq 0x20(%r13), %rcx
leaq 0xc(%r15), %rax
movq %rax, 0x90(%rsp)
xorps %xmm0, %xmm0
xorl %edi, %edi
xorl %esi, %esi
movq $0x0, 0x30(%rsp)
movq %rbx, 0x28(%rsp)
movq %rcx, 0x18(%rsp)
movq %r15, 0x10(%rsp)
movq %r14, 0x48(%rsp)
movq %rbp, 0x20(%rsp)
testq %rsi, %rsi
je 0x5361a
leaq (%rsi,%rsi,4), %rax
leaq (%rdi,%rdi), %rdx
movq %rdi, 0x88(%rsp)
testq %rdi, %rdi
movl $0x2, %ecx
cmoveq %rcx, %rdx
leaq (%r14,%rax,8), %r12
movq %rdx, 0x80(%rsp)
leaq (,%rdx,8), %rax
movq %rax, 0x78(%rsp)
movl $0x1, %eax
movq %rax, 0x40(%rsp)
movq %rsi, 0x58(%rsp)
movq %rsi, %rbx
movq %rbx, %r13
decq %rbx
leaq (%rbx,%rbx,4), %rax
movl 0x20(%r12), %ecx
cmpl 0x20(%r14,%rax,8), %ecx
jne 0x533f7
cmpq $0x1, %r13
jg 0x533d6
jmp 0x53600
leaq (%r14,%rax,8), %rsi
movl 0x14(%r12), %eax
movl 0x18(%r12), %edx
movl 0x14(%rsi), %ecx
movl 0x18(%rsi), %esi
movaps %xmm0, 0x60(%rsp)
subl %edx, %eax
je 0x533ec
cmpl %esi, %ecx
je 0x533ec
leaq (%rdx,%rdx,2), %rdx
leaq (%r15,%rdx,8), %rdx
subl %esi, %ecx
leaq (%rsi,%rsi,2), %rsi
movq 0x90(%rsp), %rdi
leaq (%rdi,%rsi,8), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
leaq (%r8,%r8,2), %r9
movl 0x4(%rdx,%r9,8), %r11d
leaq (%rdi,%rdi,2), %r10
leaq (%rsi,%r10,8), %r10
cmpl %r11d, -0x8(%r10)
jae 0x5345f
incq %rdi
addq $0x18, %r10
cmpq %rcx, %rdi
jl 0x53448
jmp 0x53524
jne 0x53513
leaq (%rdx,%r9,8), %r11
xorl %r15d, %r15d
testb $0x1, 0xc(%r11)
movl $0x0, %r9d
je 0x5348a
movl 0x8(%r11), %r9d
cmpq %r9, 0x58(%rsp)
setne %r15b
leal 0x1(%r15), %r9d
testb $0x1, (%r10)
jne 0x53495
xorl %r10d, %r10d
jmp 0x534e8
movl -0x4(%r10), %ebp
cmpq %rbp, %rbx
setne %r14b
leal 0x1(%r14), %r10d
andb %r14b, %r15b
cmpb $0x1, %r15b
jne 0x534de
cmpl $-0x1, 0x8(%r11)
movq 0x48(%rsp), %r14
movq 0x10(%rsp), %r15
je 0x534d7
cmpl $-0x1, %ebp
movzbl %r9b, %r9d
movl $0x0, %r11d
cmovnel %r11d, %r9d
movzbl %r10b, %r10d
cmovnel %r11d, %r10d
movq 0x20(%rsp), %rbp
jmp 0x534ed
movq 0x48(%rsp), %r14
movq 0x20(%rsp), %rbp
movq 0x10(%rsp), %r15
cmpb %r10b, %r9b
jne 0x533ec
cmpb $0x2, %r9b
je 0x533ec
cmpb $0x2, %r10b
je 0x533ec
movzbl %r9b, %r9d
incq 0x60(%rsp,%r9,8)
incq %r8
cmpq %rax, %r8
jae 0x53524
cmpq %rcx, %rdi
jl 0x53437
cmpq $0x0, 0x60(%rsp)
jle 0x533ec
cmpq $0x0, 0x68(%rsp)
jle 0x533ec
movq 0x38(%rsp), %rax
movslq (%rax,%rbx,4), %rax
leaq 0x1(%rax), %r15
movq 0x40(%rsp), %rcx
cmpq %rax, %rcx
jle 0x535ab
cmpq %rcx, %r15
jne 0x535f6
movq (%rbp), %rcx
movq 0x10(%rbp), %rax
cmpq 0x8(%rbp), %rcx
movq 0x10(%rsp), %r15
jne 0x5359a
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbp)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
xorps %xmm0, %xmm0
movq %rax, 0x10(%rbp)
movq (%rbp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbp)
movq %rbx, (%rax,%rcx,8)
jmp 0x533ec
movq 0x88(%rsp), %rcx
movq %rcx, (%rbp)
movq 0x10(%rbp), %rax
cmpq 0x8(%rbp), %rcx
jne 0x535e5
movq 0x80(%rsp), %rcx
movq %rcx, 0x8(%rbp)
movq %rax, %rdi
movq 0x78(%rsp), %rsi
callq 0x2370
xorps %xmm0, %xmm0
movq %rax, 0x10(%rbp)
movq (%rbp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbp)
movq %rbx, (%rax,%rcx,8)
movq %r15, 0x40(%rsp)
movq 0x10(%rsp), %r15
jmp 0x533ec
movq (%rbp), %rdi
movq 0x28(%rsp), %rbx
movq 0x18(%rsp), %rcx
movq 0x58(%rsp), %rsi
movq 0x40(%rsp), %rax
jmp 0x5361f
movl $0x1, %eax
movq 0x38(%rsp), %rdx
movl %eax, (%rdx,%rsi,4)
movq 0x50(%rsp), %rax
movq %rdi, (%rax,%rsi,8)
movl $0x0, (%rcx,%rsi,4)
movslq (%rdx,%rsi,4), %rax
movq 0x30(%rsp), %rdx
cmpq %rax, %rdx
cmovgeq %rax, %rdx
movq %rdx, 0x30(%rsp)
incq %rsi
cmpq %rbx, %rsi
jne 0x53386
movq (%rbp), %rbx
movq 0x10(%rbp), %rax
xorl %r12d, %r12d
movl $0x2, %r13d
movq %rbp, %r15
movq 0x38(%rsp), %rcx
movl (%rcx,%r12,4), %ebp
subl 0x30(%rsp), %ebp
movl %ebp, (%rcx,%r12,4)
movq (%r15), %rcx
cmpq 0x8(%r15), %rcx
jne 0x536a8
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
cmoveq %r13, %rsi
movq %rsi, 0x8(%r15)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r15), %rcx
notl %ebp
shlq $0x20, %rbp
orq %r12, %rbp
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
movq %rbp, (%rax,%rcx,8)
incq %r12
cmpq %r12, 0x28(%rsp)
jne 0x5366c
movq (%r15), %rcx
leaq (%rax,%rbx,8), %rdi
leaq (%rax,%rcx,8), %rsi
callq 0x45373
movq 0x28(%rsp), %r12
movq 0x70(%rsp), %r13
movq 0x18(%rsp), %rdx
movq 0x10(%r15), %rax
movl (%rax,%rbx,8), %r8d
cmpl $0x0, (%rdx,%r8,4)
jne 0x5370e
movq %r15, %rdi
movq 0x50(%rsp), %rsi
movq %r13, %rcx
movq 0x8(%rsp), %r9
callq 0x530d7
movq 0x18(%rsp), %rdx
incq %rbx
decq %r12
jne 0x536e5
movq 0x8(%rsp), %rax
movq (%rax), %rbp
testq %rbp, %rbp
jle 0x537c3
addq $0x10, 0x8(%rsp)
negq %rbp
movl $0x1, %ebx
leaq 0x1de778(%rip), %r15    # 0x231eb4
leaq 0x1de784(%rip), %r12    # 0x231ec7
xorl %r13d, %r13d
movq %rbp, %rax
addq %rbx, %rax
je 0x53769
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq (%rax,%rbx,8), %rcx
xorq (%rax,%r13,8), %rcx
shrq $0x20, %rcx
jne 0x53769
movq %r13, %rax
jmp 0x53777
movq %rbx, %rcx
subq %r13, %rcx
movq %rbx, %rax
testq %rcx, %rcx
jg 0x5378c
leaq (%rbx,%rbp), %rcx
incq %rcx
incq %rbx
movq %rax, %r13
cmpq $0x1, %rcx
jne 0x53746
jmp 0x537c3
movq 0x24184d(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x22b0
movq %rbx, %rax
cmpq %rbx, %r13
jge 0x53777
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x5ca6
movq %rbx, %rax
jmp 0x53777
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq