// File: /workspace/github_cpp_makefile_star2_O1/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 %rsi, 0x18(%rsp)
testl %ecx, %ecx
je 0x1fa4ef
movl %ecx, %r12d
movq %rdx, %rbp
movq %rdi, %r13
movq %r8, 0x10(%rsp)
movq 0x68(%rsp), %rsi
cmpl $0x1, %ecx
je 0x1fa1c7
movq 0xc8(%r13), %rax
movq 0xd8(%r13), %rdi
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x1e4bf7
movq 0x68(%rsp), %rsi
movl %r12d, %eax
movq %rax, (%rsp)
cmpq %rax, 0x98(%rsi)
jae 0x1fa23a
movq (%rsp), %rax
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)
leal -0x1(%r12), %edx
movq %rdx, 0x90(%rsi)
movq 0xa0(%rsi), %rax
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 0x1fa2f7
movl $0x1, %edi
xorl %r8d, %r8d
cmpq %rsi, %rdi
je 0x1fa2a1
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 0x1fa2ea
cmpq %r8, %rdi
jbe 0x1fa2e7
leaq (%r8,%r8,2), %r10
xorl %r9d, %r9d
cmpq %r9, %rax
je 0x1fa2e7
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 0x1fa2ad
shlq $0x20, %r8
addq %rdi, %r8
movq %r8, -0x8(%rcx,%r9,8)
decq %rdx
movq %rdi, %r8
incq %rdi
cmpq %rsi, %rdi
ja 0x1fa2f7
testq %rdx, %rdx
jne 0x1fa283
testq %rdx, %rdx
jne 0x1fa53c
movl 0x60(%rsp), %r10d
testq %rax, %rax
je 0x1fa4a4
movq 0x28(%r13), %rdx
movq 0x40(%r13), %rdi
addq $0x8, %rdx
xorl %esi, %esi
movl (%rbp,%rsi,4), %r8d
movq (%rdi,%r8,8), %r11
movl $0x0, %r8d
testl %r11d, %r11d
je 0x1fa365
movl 0x4(%rbp,%rsi,4), %r9d
movq %r11, %r8
shrq $0x20, %r8
movl %r11d, %r11d
shlq $0x4, %r8
addq %rdx, %r8
shlq $0x4, %r11
xorl %ebx, %ebx
cmpl %r9d, (%r8,%rbx)
je 0x1fa360
addq $0x10, %rbx
cmpq %rbx, %r11
jne 0x1fa34c
xorl %r8d, %r8d
jmp 0x1fa365
movl -0x8(%rbx,%r8), %r8d
movq (%rcx,%rsi,8), %r11
movq %r11, %r9
shrq $0x20, %r9
movl %r11d, %ebx
subl %r9d, %ebx
cmpl %ebx, %r8d
jne 0x1fa4fe
movl %r11d, %r11d
movq %r11, %r8
subq %r9, %r8
cmpq $0x1, %r8
jg 0x1fa3c3
cmpl %r9d, %r11d
jbe 0x1fa3b4
movq 0xd8(%r13), %r11
leaq (%r9,%r9,2), %r9
leaq (%r11,%r9,8), %r9
addq $0x10, %r9
cmpl %r10d, (%r9)
je 0x1fa3c3
addq $0x18, %r9
decq %r8
jne 0x1fa3a6
incq %rsi
cmpq %rax, %rsi
jne 0x1fa31c
movq %rax, %rsi
movq 0x28(%r13), %rdx
movq 0x40(%r13), %r9
cmpq $0x1, %rax
movq %rax, %r8
adcq $0x0, %r8
addq $0x8, %rdx
movq %rdx, 0x8(%rsp)
xorl %edi, %edi
movq %rax, %r11
subq %rdi, %r11
movl -0x4(%rbp,%r11,4), %ebx
movq (%r9,%rbx,8), %r15
movl $0x0, %ebx
testl %r15d, %r15d
je 0x1fa443
movq %rcx, %rdx
movq %r9, %rcx
movq %r12, %r9
movl (%rbp,%r11,4), %r14d
movq %r15, %r12
shrq $0x20, %r12
movl %r15d, %ebx
shlq $0x4, %r12
addq 0x8(%rsp), %r12
shlq $0x4, %rbx
xorl %r15d, %r15d
cmpl %r14d, (%r12,%r15)
je 0x1fa435
addq $0x10, %r15
cmpq %r15, %rbx
jne 0x1fa422
xorl %ebx, %ebx
jmp 0x1fa43a
movl -0x8(%r15,%r12), %ebx
movq %r9, %r12
movq %rcx, %r9
movq %rdx, %rcx
movq -0x8(%rcx,%r11,8), %r11
movq %r11, %r14
shrq $0x20, %r14
movl %r11d, %r15d
subl %r14d, %r15d
cmpl %r15d, %ebx
jne 0x1fa51d
movl %r11d, %ebx
movq %rbx, %r11
subq %r14, %r11
cmpq $0x1, %r11
jg 0x1fa4a8
cmpl %r14d, %ebx
jbe 0x1fa493
movq 0xd8(%r13), %rbx
leaq (%r14,%r14,2), %r14
leaq (%rbx,%r14,8), %rbx
addq $0x10, %rbx
cmpl %r10d, (%rbx)
je 0x1fa4a8
addq $0x18, %rbx
decq %r11
jne 0x1fa485
incq %rdi
cmpq %r8, %rdi
jne 0x1fa3e1
movq %r8, %rdi
jmp 0x1fa4a8
xorl %esi, %esi
xorl %edi, %edi
addq %rsi, %rdi
cmpq (%rsp), %rdi
movq 0x10(%rsp), %r8
jae 0x1fa4ef
leaq (,%rsi,4), %rdx
addq %rbp, %rdx
subl %edi, %r12d
leaq (%rcx,%rsi,8), %r11
subq %rdi, %rax
movq %r13, %rdi
movq 0x18(%rsp), %rsi
movl %r12d, %ecx
movq 0x20(%rsp), %r9
pushq %rax
pushq %r11
pushq 0x78(%rsp)
pushq %r10
callq 0x1f9c4e
addq $0x48, %rsp
jmp 0x1fa4f3
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x40a75(%rip), %rdi     # 0x23af7a
leaq 0x3ee19(%rip), %rsi     # 0x239325
leaq 0x40c52(%rip), %rcx     # 0x23b165
movl $0x191a, %edx           # imm = 0x191A
callq 0x2110
leaq 0x40a56(%rip), %rdi     # 0x23af7a
leaq 0x3edfa(%rip), %rsi     # 0x239325
leaq 0x40c33(%rip), %rcx     # 0x23b165
movl $0x1927, %edx           # imm = 0x1927
callq 0x2110
leaq 0x40c1a(%rip), %rdi     # 0x23b15d
leaq 0x3eddb(%rip), %rsi     # 0x239325
leaq 0x40c14(%rip), %rcx     # 0x23b165
movl $0x190a, %edx           # imm = 0x190A
callq 0x2110