// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: dump_cns_res(poa_g_t*, ma_ug_t*, unsigned int*, unsigned int, all_ul_t*, ul_str_t*, unsigned int, integer_t*, unsigned long*, unsigned long)
void dump_cns_res(poa_g_t *pg, ma_ug_t *ug, uint32_t *cns_seq, uint32_t cns_occ, all_ul_t *ul_idx, ul_str_t *str, uint32_t qid, integer_t *buf,
uint64_t *arc_idx, uint64_t arc_idx_n)
{   
    uint64_t t, dd, k, i; uint32_t e_s, e_e, is_rev, is_g_connect, con_occ; emap_t *g_arc;
    if(cns_occ > 0) {
        t = qid; t <<= 32; t |= ((uint64_t)(0xffffffff));
        kv_push(uint64_t, buf->res_dump, t);

        t = pg->seq.a[cns_seq[0]>>1].nid; 
        // t = pg->seq.a[cns_seq[0]>>1].nid; t |= ((uint64_t)(0xffffffff00000000));
        t |= ((uint64_t)(ug->g->seq[pg->seq.a[cns_seq[0]>>1].nid>>1].len))<<32;
        kv_push(uint64_t, buf->res_dump, t);
        buf->n_correct++;
    }
    for (k = 0; k < arc_idx_n; k++) {
        // csn_v = pg->seq.a[cns_seq[k]>>1].nid; cns_w = pg->seq.a[cns_seq[k+1]>>1].nid;
        e_s = arc_idx[k]>>32; e_e = (uint32_t)arc_idx[k]; 
        // fprintf(stderr, "[M::%s::] k::%lu, arc_idx_n::%lu, e_s::%u, e_e::%u\n", __func__, k, arc_idx_n, e_s, e_e);
        assert(poa_g_arc_w(pg, cns_seq[k], cns_seq[k+1]) == (e_e - e_s)); assert(e_e > e_s); 
        buf->o.n = 0; kv_resize(uint64_t, buf->o, e_e - e_s); con_occ = 0;
        for (i = e_s; i < e_e; i++) {
            g_arc = &(pg->e_idx.a[i]);
            assert((g_arc->pge>>32) == (cns_seq[k]>>1) && ((uint32_t)g_arc->pge) == (cns_seq[k+1]>>1));
            is_rev = ((g_arc->ule>>32) > ((uint32_t)g_arc->ule)?1:0);
            assert((pg->seq.a[g_arc->pge>>32].nid^(is_rev?1:0)) == ((uint32_t)str[g_arc->ulid].a[g_arc->ule>>32]));
            assert((pg->seq.a[(uint32_t)g_arc->pge].nid^(is_rev?1:0)) == ((uint32_t)str[g_arc->ulid].a[(uint32_t)g_arc->ule]));
            // fprintf(stderr, "+++i::%lu, target_ulid::%u, str_sidx::%u, str_eidx::%u, str_cn::%u, ul_idx->a[g_arc->ulid].bb.n::%u\n", 
            // i - e_s, g_arc->ulid, (uint32_t)(g_arc->ule>>32), (uint32_t)g_arc->ule, str[g_arc->ulid].cn, (uint32_t)ul_idx->a[g_arc->ulid].bb.n);
            dd = cal_integer_match_dis(ug, ul_idx->a[g_arc->ulid].bb.a, str[g_arc->ulid].a[g_arc->ule>>32]>>32, 
                                                                    str[g_arc->ulid].a[(uint32_t)g_arc->ule]>>32, is_rev, &is_g_connect);
            // fprintf(stderr, "---i::%lu, dd::%lu, is_g_connect::%u\n", i - e_s, dd, is_g_connect);
            dd <<= 1; if(is_rev) dd += 1; 
            if(is_g_connect) {
                con_occ++; buf->o.a[buf->o.n] = dd;
            } else {
                buf->o.a[buf->o.n] = dd; buf->o.a[buf->o.n] |= ((uint64_t)(0x8000000000000000));
            } 
            buf->o.n++;
        }

        radix_sort_srt64(buf->o.a, buf->o.a + buf->o.n);
        if(con_occ > 0) buf->o.n = con_occ;
        dd = cal_integer_most_dis(qid, buf->o.a, buf->o.n, 0.08);


        t = pg->seq.a[cns_seq[k+1]>>1].nid; t |= ((uint64_t)(dd<<32)); 
        if(con_occ > 0) t |= ((uint64_t)(0x8000000000000000));
        kv_push(uint64_t, buf->res_dump, t);
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x30(%rsp)
movq %r8, 0x28(%rsp)
movq %rdx, %rbp
movq %rsi, 0x20(%rsp)
movq %rdi, %r12
movq 0x78(%rsp), %r9
testl %ecx, %ecx
je 0x1f9d7c
movl 0x70(%rsp), %eax
shlq $0x20, %rax
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
orq %rax, %rbx
movq 0x308(%r9), %rax
cmpq %rax, 0x300(%r9)
jne 0x1f9cd1
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x308(%r9)
movq 0x310(%r9), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x78(%rsp), %r9
movq %rax, 0x310(%r9)
movq 0x300(%r9), %rax
movq 0x310(%r9), %rdi
leaq 0x1(%rax), %rcx
movq %rcx, 0x300(%r9)
movq %rbx, (%rdi,%rax,8)
movq 0x10(%r12), %rax
movl (%rbp), %ecx
shrl %ecx
movl 0x4(%rax,%rcx,8), %eax
movq 0x20(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rcx), %rcx
movl %eax, %edx
shrl %edx
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andl (%rcx,%rdx,8), %ebx
shlq $0x20, %rbx
orq %rax, %rbx
movq 0x308(%r9), %rax
cmpq %rax, 0x300(%r9)
jne 0x1f9d58
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x308(%r9)
shlq $0x3, %rsi
callq 0x2370
movq 0x78(%rsp), %r9
movq %rax, 0x310(%r9)
movq 0x300(%r9), %rax
movq 0x310(%r9), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x300(%r9)
movq %rbx, (%rcx,%rax,8)
incq 0x318(%r9)
cmpq $0x0, 0x88(%rsp)
je 0x1fa0db
xorl %r14d, %r14d
movl (%rbp,%r14,4), %eax
movq 0x40(%r12), %rcx
movq (%rcx,%rax,8), %rsi
movl $0x0, %eax
testl %esi, %esi
je 0x1f9de5
movl 0x4(%rbp,%r14,4), %edx
movq 0x28(%r12), %rax
movq %rsi, %rcx
shrq $0x20, %rcx
movl %esi, %esi
shlq $0x4, %rcx
leaq (%rax,%rcx), %rdi
addq $0x8, %rdi
shlq $0x4, %rsi
xorl %r8d, %r8d
cmpl %edx, (%rdi,%r8)
je 0x1f9dde
addq $0x10, %r8
cmpq %r8, %rsi
jne 0x1f9dcb
xorl %eax, %eax
jmp 0x1f9de5
addq %rcx, %rax
movl (%r8,%rax), %eax
movq 0x80(%rsp), %rcx
movq (%rcx,%r14,8), %rbx
movq %rbx, %r13
shrq $0x20, %r13
movl %ebx, %ecx
subl %r13d, %ecx
cmpl %ecx, %eax
jne 0x1fa150
cmpl %r13d, %ebx
jbe 0x1fa147
movq $0x0, 0x78(%r9)
movl %ecx, %eax
cmpq %rax, 0x80(%r9)
jae 0x1f9e80
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(%r9)
movq 0x88(%r9), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq 0x78(%rsp), %r9
movq %rax, 0x88(%r9)
leaq 0x1(%r14), %rax
movq %rax, 0x10(%rsp)
movl %ebx, %r15d
movl $0x0, 0xc(%rsp)
subq %r13, %r15
jbe 0x1f9ff0
leaq (,%r13,2), %rax
addq %r13, %rax
leaq 0x10(,%rax,8), %r13
movl $0x0, 0xc(%rsp)
movq 0xd8(%r12), %rcx
movq -0x10(%rcx,%r13), %rax
movq %rax, %rdx
shrq $0x20, %rdx
movl (%rbp,%r14,4), %esi
shrl %esi
cmpq %rsi, %rdx
jne 0x1fa0ea
movq 0x10(%rsp), %rsi
movl (%rbp,%rsi,4), %esi
shrl %esi
cmpl %eax, %esi
jne 0x1fa0ea
movq -0x8(%rcx,%r13), %rdi
movl %edi, %esi
shrq $0x20, %rdi
xorl %r9d, %r9d
cmpq %rsi, %rdi
seta %r9b
movq 0x10(%r12), %r10
movl 0x4(%r10,%rdx,8), %r11d
xorl %r9d, %r11d
movl (%rcx,%r13), %r8d
movq %r8, %rcx
shlq $0x5, %rcx
movq 0x30(%rsp), %rdx
movq 0x10(%rdx,%rcx), %rcx
movq (%rcx,%rdi,8), %rdx
cmpl %edx, %r11d
jne 0x1fa109
movl %eax, %eax
xorl 0x4(%r10,%rax,8), %r9d
movq (%rcx,%rsi,8), %rcx
cmpl %ecx, %r9d
jne 0x1fa128
movq %r14, %rbx
movq %r12, %r14
movq %rbp, %r12
xorl %ebp, %ebp
cmpl %esi, %edi
seta %bpl
movq 0x28(%rsp), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r8, %rsi
movq 0x30(%rax,%rsi), %rsi
shrq $0x20, %rdx
shrq $0x20, %rcx
movq 0x20(%rsp), %rdi
movq %rbp, %r8
leaq 0x1c(%rsp), %r9
callq 0x1f963d
leaq (,%rax,2), %rax
addq %rbp, %rax
cmpl $0x0, 0x1c(%rsp)
je 0x1f9fb0
incl 0xc(%rsp)
movq 0x78(%rsp), %r9
movq 0x78(%r9), %rcx
movq 0x88(%r9), %rdx
movq %rax, (%rdx,%rcx,8)
jmp 0x1f9fd6
movq 0x78(%rsp), %r9
movq 0x78(%r9), %rcx
movq 0x88(%r9), %rdx
movq %rax, (%rdx,%rcx,8)
movq 0x78(%r9), %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
orq %rcx, (%rdx,%rax,8)
movq %r12, %rbp
incq 0x78(%r9)
addq $0x18, %r13
decq %r15
movq %r14, %r12
movq %rbx, %r14
jne 0x1f9eb8
movq 0x78(%r9), %rax
movq 0x88(%r9), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x1e3b6a
movq 0x78(%rsp), %rcx
movl 0xc(%rsp), %ebx
testl %ebx, %ebx
je 0x1fa017
movl %ebx, %eax
movq %rax, 0x78(%rcx)
movq 0x78(%rcx), %rdx
movq 0x88(%rcx), %rsi
movsd 0x2b4de(%rip), %xmm0    # 0x225508
callq 0x1f981f
movq 0x78(%rsp), %r9
movq 0x10(%r12), %rcx
movq 0x10(%rsp), %rdx
movl (%rbp,%rdx,4), %edx
shrl %edx
movl 0x4(%rcx,%rdx,8), %ecx
shlq $0x20, %rax
orq %rcx, %rax
movq %rax, %r15
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
orq %rcx, %r15
testl %ebx, %ebx
cmoveq %rax, %r15
movq 0x308(%r9), %rax
cmpq %rax, 0x300(%r9)
jne 0x1fa0a8
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x308(%r9)
movq 0x310(%r9), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x78(%rsp), %r9
movq %rax, 0x310(%r9)
movq 0x300(%r9), %rax
movq 0x310(%r9), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x300(%r9)
movq %r15, (%rcx,%rax,8)
movq 0x10(%rsp), %rax
movq %rax, %r14
cmpq 0x88(%rsp), %rax
jne 0x1f9d8e
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40f4f(%rip), %rdi     # 0x23b040
leaq 0x3f22d(%rip), %rsi     # 0x239325
leaq 0x40eb4(%rip), %rcx     # 0x23afb3
movl $0x18d7, %edx           # imm = 0x18D7
callq 0x2110
leaq 0x40f83(%rip), %rdi     # 0x23b093
leaq 0x3f20e(%rip), %rsi     # 0x239325
leaq 0x40e95(%rip), %rcx     # 0x23afb3
movl $0x18d9, %edx           # imm = 0x18D9
callq 0x2110
leaq 0x40fc3(%rip), %rdi     # 0x23b0f2
leaq 0x3f1ef(%rip), %rsi     # 0x239325
leaq 0x40e76(%rip), %rcx     # 0x23afb3
movl $0x18da, %edx           # imm = 0x18DA
callq 0x2110
leaq 0x40ee8(%rip), %rdi     # 0x23b036
jmp 0x1fa157
leaq 0x40e23(%rip), %rdi     # 0x23af7a
leaq 0x3f1c7(%rip), %rsi     # 0x239325
leaq 0x40e4e(%rip), %rcx     # 0x23afb3
movl $0x18d3, %edx           # imm = 0x18D3
callq 0x2110