// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
cmpl $0x0, -0x1c(%rbp)
jbe 0x335446
movl 0x10(%rbp), %eax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x38(%rbp)
movabsq $0xffffffff, %rax       # imm = 0xFFFFFFFF
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq 0x18(%rbp), %rax
movq 0x300(%rax), %rax
movq 0x18(%rbp), %rcx
cmpq 0x308(%rcx), %rax
jne 0x335301
movq 0x18(%rbp), %rax
cmpq $0x0, 0x308(%rax)
je 0x3352ba
movq 0x18(%rbp), %rax
movq 0x308(%rax), %rax
shlq %rax
movq %rax, -0x78(%rbp)
jmp 0x3352c5
movl $0x2, %eax
movq %rax, -0x78(%rbp)
jmp 0x3352c5
movq -0x78(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x308(%rax)
movq 0x18(%rbp), %rax
movq 0x310(%rax), %rdi
movq 0x18(%rbp), %rax
movq 0x308(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x310(%rax)
movq -0x38(%rbp), %rdx
movq 0x18(%rbp), %rax
movq 0x310(%rax), %rax
movq 0x18(%rbp), %rsi
movq 0x300(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x300(%rsi)
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
movl 0x4(%rax,%rcx,8), %eax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x18(%rbp), %rdx
movl (%rdx), %edx
shrl %edx
movl %edx, %edx
movl 0x4(%rcx,%rdx,8), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
shlq $0x20, %rax
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq 0x18(%rbp), %rax
movq 0x300(%rax), %rax
movq 0x18(%rbp), %rcx
cmpq 0x308(%rcx), %rax
jne 0x335404
movq 0x18(%rbp), %rax
cmpq $0x0, 0x308(%rax)
je 0x3353bd
movq 0x18(%rbp), %rax
movq 0x308(%rax), %rax
shlq %rax
movq %rax, -0x80(%rbp)
jmp 0x3353c8
movl $0x2, %eax
movq %rax, -0x80(%rbp)
jmp 0x3353c8
movq -0x80(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x308(%rax)
movq 0x18(%rbp), %rax
movq 0x310(%rax), %rdi
movq 0x18(%rbp), %rax
movq 0x308(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x310(%rax)
movq -0x38(%rbp), %rdx
movq 0x18(%rbp), %rax
movq 0x310(%rax), %rax
movq 0x18(%rbp), %rsi
movq 0x300(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x300(%rsi)
movq %rdx, (%rax,%rcx,8)
movq 0x18(%rbp), %rax
movq 0x318(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x318(%rax)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq 0x28(%rbp), %rax
jae 0x335a89
movq 0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x54(%rbp)
movq 0x20(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %esi
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %edx
callq 0x335180
movl -0x58(%rbp), %ecx
subl -0x54(%rbp), %ecx
cmpl %ecx, %eax
jne 0x3354aa
jmp 0x3354c9
leaq 0x62a9d(%rip), %rdi     # 0x397f4e
leaq 0x60d01(%rip), %rsi     # 0x3961b9
movl $0x18d3, %edx           # imm = 0x18D3
leaq 0x62ac3(%rip), %rcx     # 0x397f87
callq 0x2130
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jbe 0x3354d3
jmp 0x3354f2
leaq 0x62b30(%rip), %rdi     # 0x39800a
leaq 0x60cd8(%rip), %rsi     # 0x3961b9
movl $0x18d3, %edx           # imm = 0x18D3
leaq 0x62a9a(%rip), %rcx     # 0x397f87
callq 0x2130
movq 0x18(%rbp), %rax
movq $0x0, 0x78(%rax)
movq 0x18(%rbp), %rax
movq 0x80(%rax), %rax
movl -0x58(%rbp), %ecx
subl -0x54(%rbp), %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jae 0x33562c
movl -0x58(%rbp), %eax
subl -0x54(%rbp), %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movq %rcx, 0x80(%rax)
movq 0x18(%rbp), %rax
movq 0x80(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x80(%rax)
movq 0x18(%rbp), %rax
movq 0x80(%rax), %rcx
shrq %rcx
movq 0x18(%rbp), %rax
orq 0x80(%rax), %rcx
movq %rcx, 0x80(%rax)
movq 0x18(%rbp), %rax
movq 0x80(%rax), %rcx
shrq $0x2, %rcx
movq 0x18(%rbp), %rax
orq 0x80(%rax), %rcx
movq %rcx, 0x80(%rax)
movq 0x18(%rbp), %rax
movq 0x80(%rax), %rcx
shrq $0x4, %rcx
movq 0x18(%rbp), %rax
orq 0x80(%rax), %rcx
movq %rcx, 0x80(%rax)
movq 0x18(%rbp), %rax
movq 0x80(%rax), %rcx
shrq $0x8, %rcx
movq 0x18(%rbp), %rax
orq 0x80(%rax), %rcx
movq %rcx, 0x80(%rax)
movq 0x18(%rbp), %rax
movq 0x80(%rax), %rcx
shrq $0x10, %rcx
movq 0x18(%rbp), %rax
orq 0x80(%rax), %rcx
movq %rcx, 0x80(%rax)
movq 0x18(%rbp), %rax
movq 0x80(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x80(%rax)
movq 0x18(%rbp), %rax
movq 0x88(%rax), %rdi
movq 0x18(%rbp), %rax
movq 0x80(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x88(%rax)
jmp 0x33562e
movl $0x0, -0x64(%rbp)
movl -0x54(%rbp), %eax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl -0x58(%rbp), %ecx
cmpq %rcx, %rax
jae 0x335912
movq -0x8(%rbp), %rax
movq 0xd8(%rax), %rax
imulq $0x18, -0x50(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq (%rax), %rcx
shrq $0x20, %rcx
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rdx
movl (%rax,%rdx,4), %eax
shrl %eax
movl %eax, %eax
movl %eax, %edx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x81(%rbp)
jne 0x3356ac
movq -0x70(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq -0x48(%rbp), %rdx
movl 0x4(%rcx,%rdx,4), %ecx
shrl %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x3356b8
jmp 0x3356ba
jmp 0x3356d9
leaq 0x62953(%rip), %rdi     # 0x398014
leaq 0x60af1(%rip), %rsi     # 0x3961b9
movl $0x18d7, %edx           # imm = 0x18D7
leaq 0x628b3(%rip), %rcx     # 0x397f87
callq 0x2130
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rdx
shrq $0x20, %rdx
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %eax
movl %eax, %esi
xorl %eax, %eax
movl $0x1, %ecx
cmpq %rsi, %rdx
cmoval %ecx, %eax
movl %eax, -0x5c(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x70(%rbp), %rcx
movq (%rcx), %rcx
shrq $0x20, %rcx
movl 0x4(%rax,%rcx,8), %eax
movl -0x5c(%rbp), %esi
xorl %ecx, %ecx
movl $0x1, %edx
cmpl $0x0, %esi
cmovnel %edx, %ecx
xorl %ecx, %eax
movq -0x30(%rbp), %rcx
movq -0x70(%rbp), %rdx
movl 0x10(%rdx), %edx
shlq $0x5, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movq -0x70(%rbp), %rdx
movq 0x8(%rdx), %rdx
shrq $0x20, %rdx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
jne 0x335756
jmp 0x335775
leaq 0x6290a(%rip), %rdi     # 0x398067
leaq 0x60a55(%rip), %rsi     # 0x3961b9
movl $0x18d9, %edx           # imm = 0x18D9
leaq 0x62817(%rip), %rcx     # 0x397f87
callq 0x2130
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x70(%rbp), %rcx
movq (%rcx), %rcx
movl %ecx, %ecx
movl 0x4(%rax,%rcx,8), %eax
movl -0x5c(%rbp), %esi
xorl %ecx, %ecx
movl $0x1, %edx
cmpl $0x0, %esi
cmovnel %edx, %ecx
xorl %ecx, %eax
movq -0x30(%rbp), %rcx
movq -0x70(%rbp), %rdx
movl 0x10(%rdx), %edx
shlq $0x5, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movq -0x70(%rbp), %rdx
movq 0x8(%rdx), %rdx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
jne 0x3357c6
jmp 0x3357e5
leaq 0x628f9(%rip), %rdi     # 0x3980c6
leaq 0x609e5(%rip), %rsi     # 0x3961b9
movl $0x18da, %edx           # imm = 0x18DA
leaq 0x627a7(%rip), %rcx     # 0x397f87
callq 0x2130
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x70(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq 0x30(%rax), %rsi
movq -0x30(%rbp), %rax
movq -0x70(%rbp), %rcx
movl 0x10(%rcx), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq -0x70(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x20, %rcx
movq (%rax,%rcx,8), %rdx
shrq $0x20, %rdx
movq -0x30(%rbp), %rax
movq -0x70(%rbp), %rcx
movl 0x10(%rcx), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq -0x70(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rcx
shrq $0x20, %rcx
movl -0x5c(%rbp), %eax
movl %eax, %r8d
leaq -0x60(%rbp), %r9
callq 0x3346d0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
shlq %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x335885
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x60(%rbp)
je 0x3358b1
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movq -0x40(%rbp), %rdx
movq 0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x18(%rbp), %rcx
movq 0x78(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x3358f1
movq -0x40(%rbp), %rdx
movq 0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x18(%rbp), %rcx
movq 0x78(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x18(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x18(%rbp), %rcx
movq 0x78(%rcx), %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq 0x18(%rbp), %rax
movq 0x78(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x78(%rax)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x33563c
movq 0x18(%rbp), %rax
movq 0x88(%rax), %rdi
movq 0x18(%rbp), %rax
movq 0x88(%rax), %rsi
movq 0x18(%rbp), %rax
movq 0x78(%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x30ed90
cmpl $0x0, -0x64(%rbp)
jbe 0x33594f
movl -0x64(%rbp), %eax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movq %rcx, 0x78(%rax)
movl 0x10(%rbp), %edi
movq 0x18(%rbp), %rax
movq 0x88(%rax), %rsi
movq 0x18(%rbp), %rax
movq 0x78(%rax), %rdx
movsd 0x4c923(%rip), %xmm0    # 0x382290
callq 0x3349d0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movq -0x48(%rbp), %rdx
movl 0x4(%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
movl 0x4(%rax,%rcx,8), %eax
movq %rax, -0x38(%rbp)
movq -0x40(%rbp), %rax
shlq $0x20, %rax
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, -0x64(%rbp)
jbe 0x3359be
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x3359c0
movq 0x18(%rbp), %rax
movq 0x300(%rax), %rax
movq 0x18(%rbp), %rcx
cmpq 0x308(%rcx), %rax
jne 0x335a4a
movq 0x18(%rbp), %rax
cmpq $0x0, 0x308(%rax)
je 0x3359fd
movq 0x18(%rbp), %rax
movq 0x308(%rax), %rax
shlq %rax
movq %rax, -0x90(%rbp)
jmp 0x335a0b
movl $0x2, %eax
movq %rax, -0x90(%rbp)
jmp 0x335a0b
movq -0x90(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x308(%rax)
movq 0x18(%rbp), %rax
movq 0x310(%rax), %rdi
movq 0x18(%rbp), %rax
movq 0x308(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0x310(%rax)
movq -0x38(%rbp), %rdx
movq 0x18(%rbp), %rax
movq 0x310(%rax), %rax
movq 0x18(%rbp), %rsi
movq 0x300(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x300(%rsi)
movq %rdx, (%rax,%rcx,8)
jmp 0x335a78
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x33544e
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)