// File: /workspace/github_cpp_makefile_star2_O2/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, 0x28(%rsp)
movq %r8, 0x20(%rsp)
movq %rdx, %rbp
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
movq 0x78(%rsp), %rdi
testl %ecx, %ecx
je 0x1b948f
movl 0x70(%rsp), %eax
shlq $0x20, %rax
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
orq %rax, %rbx
movq 0x300(%rdi), %rcx
cmpq 0x308(%rdi), %rcx
jne 0x1b93f2
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rax
cmoveq %rax, %rsi
movq %rsi, 0x308(%rdi)
movq 0x78(%rsp), %rax
movq 0x310(%rax), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x78(%rsp), %rdi
movq %rax, 0x310(%rdi)
movq 0x300(%rdi), %rcx
jmp 0x1b93f9
movq 0x310(%rdi), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0x300(%rdi)
movq %rbx, (%rax,%rcx,8)
movq 0x10(%r14), %rcx
movl (%rbp), %edx
shrl %edx
movl 0x4(%rcx,%rdx,8), %ecx
movq 0x18(%rsp), %rdx
movq 0x18(%rdx), %rdx
movq 0x20(%rdx), %rdx
movl %ecx, %esi
shrl %esi
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andl (%rdx,%rsi,8), %ebx
shlq $0x20, %rbx
orq %rcx, %rbx
movq 0x300(%rdi), %rcx
cmpq 0x308(%rdi), %rcx
jne 0x1b9479
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x308(%rdi)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x78(%rsp), %rdi
movq %rax, 0x310(%rdi)
movq 0x300(%rdi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x300(%rdi)
movq %rbx, (%rax,%rcx,8)
incq 0x318(%rdi)
xorl %r12d, %r12d
cmpq 0x88(%rsp), %r12
je 0x1b978c
movq 0x80(%rsp), %rax
movq (%rax,%r12,8), %r15
movq %r15, %rbx
shrq $0x20, %rbx
movl (%rbp,%r12,4), %esi
movl 0x4(%rbp,%r12,4), %edx
movq %r14, %rdi
callq 0x1b932b
movl %r15d, %ecx
subl %ebx, %ecx
cmpl %ecx, %eax
jne 0x1b9801
cmpl %ebx, %r15d
movq 0x78(%rsp), %rsi
jbe 0x1b97f8
andq $0x0, 0x78(%rsi)
movl %eax, %eax
cmpq %rax, 0x80(%rsi)
jae 0x1b9554
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(%rsi)
movq 0x78(%rsp), %rax
movq 0x88(%rax), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq 0x78(%rsp), %rsi
movq %rax, 0x88(%rsi)
leaq 0x1(%r12), %rax
movq %rax, 0x8(%rsp)
movl %r15d, %eax
movq %rax, 0x30(%rsp)
imulq $0x18, %rbx, %r15
addq $0x10, %r15
movl $0x0, 0x4(%rsp)
cmpq 0x30(%rsp), %rbx
jae 0x1b96b0
movq 0xd8(%r14), %rcx
movq -0x10(%rcx,%r15), %rax
movq %rax, %rdx
shrq $0x20, %rdx
movl (%rbp,%r12,4), %esi
shrl %esi
cmpq %rsi, %rdx
jne 0x1b979b
movq 0x8(%rsp), %rsi
movl (%rbp,%rsi,4), %esi
shrl %esi
cmpl %eax, %esi
jne 0x1b979b
movq -0x8(%rcx,%r15), %rdi
movl %edi, %esi
shrq $0x20, %rdi
xorl %r9d, %r9d
cmpq %rsi, %rdi
seta %r9b
movq 0x10(%r14), %r10
movl 0x4(%r10,%rdx,8), %r11d
xorl %r9d, %r11d
movl (%rcx,%r15), %r8d
movq %r8, %rcx
shlq $0x5, %rcx
movq 0x28(%rsp), %rdx
movq 0x10(%rdx,%rcx), %rcx
movq (%rcx,%rdi,8), %rdx
cmpl %edx, %r11d
jne 0x1b97ba
movl %eax, %eax
xorl 0x4(%r10,%rax,8), %r9d
movq (%rcx,%rsi,8), %rcx
cmpl %ecx, %r9d
jne 0x1b97d9
movq %r14, %r13
movq %rbp, %r14
xorl %ebp, %ebp
cmpl %esi, %edi
seta %bpl
movq 0x20(%rsp), %rax
movq 0x48(%rax), %rax
imulq $0x58, %r8, %rsi
movq 0x30(%rax,%rsi), %rsi
shrq $0x20, %rdx
shrq $0x20, %rcx
movq 0x18(%rsp), %rdi
movq %rbp, %r8
leaq 0x14(%rsp), %r9
callq 0x1b8de5
leaq (,%rax,2), %rax
addq %rbp, %rax
cmpl $0x0, 0x14(%rsp)
je 0x1b9674
incl 0x4(%rsp)
movq 0x78(%rsp), %rsi
movq 0x78(%rsi), %rcx
movq 0x88(%rsi), %rdx
movq %rax, (%rdx,%rcx,8)
jmp 0x1b969a
movq 0x78(%rsp), %rsi
movq 0x78(%rsi), %rcx
movq 0x88(%rsi), %rdx
movq %rax, (%rdx,%rcx,8)
movq 0x78(%rsi), %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
orq %rcx, (%rdx,%rax,8)
movq %r14, %rbp
incq 0x78(%rsi)
incq %rbx
addq $0x18, %r15
movq %r13, %r14
jmp 0x1b9576
movq 0x78(%rsi), %rax
movq %rsi, %rbx
movq 0x88(%rsi), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x1a3def
movl 0x4(%rsp), %r15d
testl %r15d, %r15d
je 0x1b96da
movl %r15d, %edx
movq %rdx, 0x78(%rbx)
jmp 0x1b96de
movq 0x78(%rbx), %rdx
movq 0x88(%rbx), %rsi
movsd 0x29e6b(%rip), %xmm0    # 0x1e3558
callq 0x1b8fa3
movq 0x78(%rsp), %rdi
movq 0x10(%r14), %rcx
movq 0x8(%rsp), %rdx
movl (%rbp,%rdx,4), %edx
shrl %edx
movl 0x4(%rcx,%rdx,8), %ecx
shlq $0x20, %rax
orq %rcx, %rax
movq %rax, %rbx
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
orq %rcx, %rbx
testl %r15d, %r15d
cmoveq %rax, %rbx
movq 0x300(%rdi), %rcx
movq 0x310(%rdi), %rax
cmpq 0x308(%rdi), %rcx
jne 0x1b9773
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x308(%rdi)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x78(%rsp), %rdi
movq %rax, 0x310(%rdi)
movq 0x300(%rdi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x300(%rdi)
movq %rbx, (%rax,%rcx,8)
movq 0x8(%rsp), %r12
jmp 0x1b9492
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3fb41(%rip), %rdi     # 0x1f92e3
leaq 0x3dd30(%rip), %rsi     # 0x1f74d9
leaq 0x3faa6(%rip), %rcx     # 0x1f9256
movl $0x18d7, %edx           # imm = 0x18D7
callq 0x2110
leaq 0x3fb75(%rip), %rdi     # 0x1f9336
leaq 0x3dd11(%rip), %rsi     # 0x1f74d9
leaq 0x3fa87(%rip), %rcx     # 0x1f9256
movl $0x18d9, %edx           # imm = 0x18D9
callq 0x2110
leaq 0x3fbb5(%rip), %rdi     # 0x1f9395
leaq 0x3dcf2(%rip), %rsi     # 0x1f74d9
leaq 0x3fa68(%rip), %rcx     # 0x1f9256
movl $0x18da, %edx           # imm = 0x18DA
callq 0x2110
leaq 0x3fada(%rip), %rdi     # 0x1f92d9
jmp 0x1b9808
leaq 0x3fa15(%rip), %rdi     # 0x1f921d
leaq 0x3dcca(%rip), %rsi     # 0x1f74d9
leaq 0x3fa40(%rip), %rcx     # 0x1f9256
movl $0x18d3, %edx           # imm = 0x18D3
callq 0x2110