// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: update_raw_integer_seq(poa_g_t*, ma_ug_t*, unsigned int*, unsigned int, all_ul_t*, ul_str_t*, unsigned int, integer_t*, ul_chain_t*, unsigned long)
void update_raw_integer_seq(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, ul_chain_t *idx_a, uint64_t idx_n)
{
    if(cns_occ <= 0) return;
    ///no need to check edges if there is just one node -> no dege
    if(cns_occ > 1) radix_sort_emap_t_srt(pg->e_idx.a, pg->e_idx.a + pg->e_idx.n); 
    kv_resize(uint64_t, buf->u, cns_occ); buf->u.n = cns_occ - 1; memset(buf->u.a, 0, sizeof(*(buf->u.a)*buf->u.n));
    uint64_t *arc_idx = buf->u.a, arc_idx_n = buf->u.n, x; uint64_t k, l, i, n = pg->e_idx.n, fe = cns_occ - 1;
    for (k = 1, l = 0; k <= n && fe > 0; k++) {
        if(k == n || pg->e_idx.a[k].pge != pg->e_idx.a[l].pge) {
            if(k > l) {
                for (i = 0; i < arc_idx_n; i++) {
                    x = (cns_seq[i]>>1); x <<= 32; x += (cns_seq[i+1]>>1);
                    if(x == pg->e_idx.a[l].pge) {
                        arc_idx[i] = l; arc_idx[i] <<= 32; arc_idx[i] += k; fe--;
                        break;
                    }
                }
            }
            l = k;
        }
    }
    assert(fe == 0);
    // for (k = 0; k < pg->e_idx.n; k++) {
    //     assert((pg->seq.a[pg->e_idx.a[k].pge>>32].nid>>1) == 
    //                             (((uint32_t)str[pg->e_idx.a[k].ulid].a[pg->e_idx.a[k].ule>>32])>>1));
    //     assert((pg->seq.a[(uint32_t)pg->e_idx.a[k].pge].nid>>1) == 
    //                             (((uint32_t)str[pg->e_idx.a[k].ulid].a[(uint32_t)pg->e_idx.a[k].ule])>>1));
    //     assert(((pg->seq.a[pg->e_idx.a[k].pge>>32].nid&1)^(((uint32_t)str[pg->e_idx.a[k].ulid].a[pg->e_idx.a[k].ule>>32])&1)) ==
    //         ((pg->seq.a[(uint32_t)pg->e_idx.a[k].pge].nid&1)^(((uint32_t)str[pg->e_idx.a[k].ulid].a[(uint32_t)pg->e_idx.a[k].ule])&1)));
    // }

    uint32_t e_s, e_e; emap_t *g_arc; uint64_t l_clip = 0, r_clip = 0; int64_t e_occ;
    if(arc_idx_n > 0) {
        ///clip unreliable left/right end
        for (l_clip = 0; l_clip < arc_idx_n; l_clip++) {
            k = l_clip;
            e_s = arc_idx[k]>>32; e_e = (uint32_t)arc_idx[k]; 
            assert(poa_g_arc_w(pg, cns_seq[k], cns_seq[k+1]) == (e_e - e_s)); 
            e_occ = ((int64_t)e_e) - ((int64_t)e_s);
            if(e_occ > 1) break;///more than one read supporting this edge
            for (i = e_s; i < e_e; i++) {
                g_arc = &(pg->e_idx.a[i]);
                if(g_arc->ulid == qid) break;
            }
            if(i < e_e) break;///the query read itself supports this edge
        }
        
        for (r_clip = 0; r_clip < arc_idx_n; r_clip++) {
            k = arc_idx_n - r_clip - 1;
            e_s = arc_idx[k]>>32; e_e = (uint32_t)arc_idx[k]; 
            assert(poa_g_arc_w(pg, cns_seq[k], cns_seq[k+1]) == (e_e - e_s)); 
            e_occ = ((int64_t)e_e) - ((int64_t)e_s);
            if(e_occ > 1) break;///more than one read supporting this edge
            for (i = e_s; i < e_e; i++) {
                g_arc = &(pg->e_idx.a[i]);
                if(g_arc->ulid == qid) break;
            }
            if(i < e_e) break;///the query read itself supports this edge
        }
    }
    if(l_clip+r_clip >= cns_occ) return;
    dump_cns_res(pg, ug, cns_seq+l_clip, cns_occ-l_clip-r_clip, ul_idx, str, qid, buf, arc_idx+l_clip, arc_idx_n-l_clip-r_clip);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x20(%rsp)
movq %r8, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
testl %ecx, %ecx
je 0x205ac8
movl %ecx, %r15d
movq %rdx, %rbp
movq %rdi, %r13
movq 0x68(%rsp), %rsi
cmpl $0x1, %ecx
je 0x2057c4
movq 0xc8(%r13), %rax
movq 0xd8(%r13), %rdi
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x1ef606
movq 0x68(%rsp), %rsi
movl %r15d, %eax
cmpq %rax, 0x98(%rsi)
movq %rax, 0x8(%rsp)
jae 0x205836
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, 0x98(%rsi)
movq 0xa0(%rsi), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq 0x68(%rsp), %rsi
movq %rax, 0xa0(%rsi)
jmp 0x20583d
movq 0xa0(%rsi), %rax
leal -0x1(%r15), %edx
movq %rdx, 0x90(%rsi)
movq $0x0, (%rax)
movq 0x90(%rsi), %rax
movq 0xa0(%rsi), %rcx
movq 0xc8(%r13), %rsi
testq %rsi, %rsi
sete %dil
testl %edx, %edx
sete %r8b
orb %dil, %r8b
jne 0x2058f2
movl $0x1, %edi
xorl %r8d, %r8d
cmpq %rsi, %rdi
je 0x20589c
movq 0xd8(%r13), %r9
leaq (%rdi,%rdi,2), %r10
movq (%r9,%r10,8), %r10
leaq (%r8,%r8,2), %r11
cmpq (%r9,%r11,8), %r10
je 0x2058e5
cmpq %r8, %rdi
jbe 0x2058e2
leaq (%r8,%r8,2), %r10
xorl %r9d, %r9d
cmpq %r9, %rax
je 0x2058e2
movl (%rbp,%r9,4), %r11d
movl 0x4(%rbp,%r9,4), %ebx
shrl %r11d
shlq $0x20, %r11
incq %r9
shrl %ebx
orq %r11, %rbx
movq 0xd8(%r13), %r11
cmpq (%r11,%r10,8), %rbx
jne 0x2058a8
shlq $0x20, %r8
addq %rdi, %r8
movq %r8, -0x8(%rcx,%r9,8)
decq %rdx
movq %rdi, %r8
incq %rdi
cmpq %rsi, %rdi
ja 0x2058f2
testq %rdx, %rdx
jne 0x20587e
testq %rdx, %rdx
jne 0x205b15
movl 0x60(%rsp), %r10d
testq %rax, %rax
je 0x205a7b
movq 0x28(%r13), %rdx
movq 0x40(%r13), %rdi
movl (%rbp), %r8d
addq $0x8, %rdx
xorl %esi, %esi
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl %r8d, %r11d
movl 0x4(%rbp,%rsi,4), %r8d
movq (%rdi,%r11,8), %r11
movq %r11, %rbx
movl $0x0, %r14d
andq %r9, %rbx
je 0x205966
shrq $0x20, %r11
shlq $0x4, %rbx
shlq $0x4, %r11
addq %rdx, %r11
xorl %r14d, %r14d
cmpl %r8d, (%r11,%r14)
je 0x205961
addq $0x10, %r14
cmpq %r14, %rbx
jne 0x20594d
xorl %r14d, %r14d
jmp 0x205966
movl -0x8(%r14,%r11), %r14d
movq (%rcx,%rsi,8), %r11
movq %r11, %rbx
shrq $0x20, %rbx
movl %r11d, %r12d
subl %ebx, %r12d
cmpl %r12d, %r14d
jne 0x205ad7
movl %r11d, %r14d
movq %r14, %r11
subq %rbx, %r11
cmpq $0x1, %r11
jg 0x2059c4
cmpl %ebx, %r14d
jbe 0x2059b5
movq 0xd8(%r13), %r14
leaq (%rbx,%rbx,2), %rbx
leaq (%r14,%rbx,8), %rbx
addq $0x10, %rbx
cmpl %r10d, (%rbx)
je 0x2059c4
addq $0x18, %rbx
decq %r11
jne 0x2059a7
incq %rsi
cmpq %rax, %rsi
jne 0x205921
movq %rax, %rsi
xorl %r8d, %r8d
movq %rax, %r11
subq %r8, %r11
movl -0x4(%rbp,%r11,4), %r9d
movq (%rdi,%r9,8), %r12
movq %r12, %rbx
movl $0x0, %r14d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
andq %r9, %rbx
je 0x205a1a
movl (%rbp,%r11,4), %r14d
shrq $0x20, %r12
shlq $0x4, %rbx
shlq $0x4, %r12
addq %rdx, %r12
xorl %r9d, %r9d
cmpl %r14d, (%r12,%r9)
je 0x205a15
addq $0x10, %r9
cmpq %r9, %rbx
jne 0x205a01
xorl %r14d, %r14d
jmp 0x205a1a
movl -0x8(%r9,%r12), %r14d
movq -0x8(%rcx,%r11,8), %r9
movq %r9, %rbx
shrq $0x20, %rbx
movl %r9d, %r11d
subl %ebx, %r11d
cmpl %r11d, %r14d
jne 0x205af6
movl %r9d, %r9d
movq %r9, %r11
subq %rbx, %r11
cmpq $0x1, %r11
jg 0x205a80
cmpl %ebx, %r9d
jbe 0x205a6a
movq 0xd8(%r13), %r9
leaq (%rbx,%rbx,2), %rbx
leaq (%r9,%rbx,8), %rbx
addq $0x10, %rbx
cmpl %r10d, (%rbx)
je 0x205a80
addq $0x18, %rbx
decq %r11
jne 0x205a5c
incq %r8
cmpq %rax, %r8
jne 0x2059c7
movq %rax, %r8
jmp 0x205a80
xorl %esi, %esi
xorl %r8d, %r8d
addq %rsi, %r8
cmpq 0x8(%rsp), %r8
jae 0x205ac8
leaq (,%rsi,4), %rdx
addq %rbp, %rdx
subl %r8d, %r15d
leaq (%rcx,%rsi,8), %r11
subq %r8, %rax
movq %r13, %rdi
movq 0x10(%rsp), %rsi
movl %r15d, %ecx
movq 0x18(%rsp), %r8
movq 0x20(%rsp), %r9
pushq %rax
pushq %r11
pushq 0x78(%rsp)
pushq %r10
callq 0x20525e
addq $0x48, %rsp
jmp 0x205acc
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x41780(%rip), %rdi     # 0x24725e
leaq 0x3fb24(%rip), %rsi     # 0x245609
leaq 0x4195d(%rip), %rcx     # 0x247449
movl $0x191a, %edx           # imm = 0x191A
callq 0x2110
leaq 0x41761(%rip), %rdi     # 0x24725e
leaq 0x3fb05(%rip), %rsi     # 0x245609
leaq 0x4193e(%rip), %rcx     # 0x247449
movl $0x1927, %edx           # imm = 0x1927
callq 0x2110
leaq 0x41925(%rip), %rdi     # 0x247441
leaq 0x3fae6(%rip), %rsi     # 0x245609
leaq 0x4191f(%rip), %rcx     # 0x247449
movl $0x190a, %edx           # imm = 0x190A
callq 0x2110