// File: 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
movq %rsp, %rbp
pushq %rbx
subq $0xc8, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpl $0x0, -0x24(%rbp)
ja 0x335add
jmp 0x33612e
cmpl $0x1, -0x24(%rbp)
jbe 0x335b0d
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rsi
movq -0x10(%rbp), %rax
imulq $0x18, 0xc8(%rax), %rax
addq %rax, %rsi
callq 0x310fb0
jmp 0x335b0f
movq 0x18(%rbp), %rax
movq 0x98(%rax), %rax
movl -0x24(%rbp), %ecx
cmpq %rcx, %rax
jae 0x335c33
movl -0x24(%rbp), %eax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movq %rcx, 0x98(%rax)
movq 0x18(%rbp), %rax
movq 0x98(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x98(%rax)
movq 0x18(%rbp), %rax
movq 0x98(%rax), %rcx
shrq %rcx
movq 0x18(%rbp), %rax
orq 0x98(%rax), %rcx
movq %rcx, 0x98(%rax)
movq 0x18(%rbp), %rax
movq 0x98(%rax), %rcx
shrq $0x2, %rcx
movq 0x18(%rbp), %rax
orq 0x98(%rax), %rcx
movq %rcx, 0x98(%rax)
movq 0x18(%rbp), %rax
movq 0x98(%rax), %rcx
shrq $0x4, %rcx
movq 0x18(%rbp), %rax
orq 0x98(%rax), %rcx
movq %rcx, 0x98(%rax)
movq 0x18(%rbp), %rax
movq 0x98(%rax), %rcx
shrq $0x8, %rcx
movq 0x18(%rbp), %rax
orq 0x98(%rax), %rcx
movq %rcx, 0x98(%rax)
movq 0x18(%rbp), %rax
movq 0x98(%rax), %rcx
shrq $0x10, %rcx
movq 0x18(%rbp), %rax
orq 0x98(%rax), %rcx
movq %rcx, 0x98(%rax)
movq 0x18(%rbp), %rax
movq 0x98(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x98(%rax)
movq 0x18(%rbp), %rax
movq 0xa0(%rax), %rdi
movq 0x18(%rbp), %rax
movq 0x98(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq 0x18(%rbp), %rax
movq %rcx, 0xa0(%rax)
jmp 0x335c35
movl -0x24(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movq 0x18(%rbp), %rax
movq %rcx, 0x90(%rax)
movq 0x18(%rbp), %rax
movq 0xa0(%rax), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x2100
movq 0x18(%rbp), %rax
movq 0xa0(%rax), %rax
movq %rax, -0x40(%rbp)
movq 0x18(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0xc8(%rax), %rax
movq %rax, -0x70(%rbp)
movl -0x24(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0x78(%rbp)
movq $0x1, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x58(%rbp), %rcx
xorl %eax, %eax
cmpq -0x70(%rbp), %rcx
movb %al, -0xa1(%rbp)
ja 0x335cca
cmpq $0x0, -0x78(%rbp)
seta %al
movb %al, -0xa1(%rbp)
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0x335cd9
jmp 0x335e02
movq -0x58(%rbp), %rax
cmpq -0x70(%rbp), %rax
je 0x335d15
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rax
imulq $0x18, -0x58(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movq 0xd8(%rcx), %rcx
imulq $0x18, -0x60(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
je 0x335def
movq -0x58(%rbp), %rax
cmpq -0x60(%rbp), %rax
jbe 0x335de7
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x335de5
movq -0x20(%rbp), %rax
movq -0x68(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl %eax
movl %eax, %eax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq -0x68(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %eax
shrl %eax
movl %eax, %eax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0xd8(%rcx), %rcx
imulq $0x18, -0x60(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jne 0x335dd2
movq -0x60(%rbp), %rdx
movq -0x40(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
movq -0x68(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
shlq $0x20, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x58(%rbp), %rdx
movq -0x40(%rbp), %rax
movq -0x68(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x78(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x335de5
jmp 0x335dd4
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x335d2b
jmp 0x335de7
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x335df1
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x335caa
cmpq $0x0, -0x78(%rbp)
jne 0x335e0b
jmp 0x335e2a
leaq 0x6231f(%rip), %rdi     # 0x398131
leaq 0x603a0(%rip), %rsi     # 0x3961b9
movl $0x190a, %edx           # imm = 0x190A
leaq 0x62314(%rip), %rcx     # 0x398139
callq 0x2130
movq $0x0, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
cmpq $0x0, -0x48(%rbp)
jbe 0x33609f
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x335f70
movq -0x90(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x7c(%rbp)
movq -0x40(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq -0x58(%rbp), %rcx
movl (%rax,%rcx,4), %esi
movq -0x20(%rbp), %rax
movq -0x58(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %edx
callq 0x335180
movl -0x80(%rbp), %ecx
subl -0x7c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x335ec0
jmp 0x335edf
leaq 0x62087(%rip), %rdi     # 0x397f4e
leaq 0x602eb(%rip), %rsi     # 0x3961b9
movl $0x191a, %edx           # imm = 0x191A
leaq 0x6225f(%rip), %rcx     # 0x398139
callq 0x2130
movl -0x80(%rbp), %eax
movl -0x7c(%rbp), %ecx
subq %rcx, %rax
movq %rax, -0xa0(%rbp)
cmpq $0x1, -0xa0(%rbp)
jle 0x335efb
jmp 0x335f70
movl -0x7c(%rbp), %eax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl -0x80(%rbp), %ecx
cmpq %rcx, %rax
jae 0x335f49
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rax
imulq $0x18, -0x68(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movl 0x10(%rax), %eax
cmpl 0x10(%rbp), %eax
jne 0x335f39
jmp 0x335f49
jmp 0x335f3b
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x335f02
movq -0x68(%rbp), %rax
movl -0x80(%rbp), %ecx
cmpq %rcx, %rax
jae 0x335f57
jmp 0x335f70
jmp 0x335f59
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x335e56
movq $0x0, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x33609d
movq -0x48(%rbp), %rax
subq -0x98(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x7c(%rbp)
movq -0x40(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq -0x58(%rbp), %rcx
movl (%rax,%rcx,4), %esi
movq -0x20(%rbp), %rax
movq -0x58(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %edx
callq 0x335180
movl -0x80(%rbp), %ecx
subl -0x7c(%rbp), %ecx
cmpl %ecx, %eax
jne 0x335fed
jmp 0x33600c
leaq 0x61f5a(%rip), %rdi     # 0x397f4e
leaq 0x601be(%rip), %rsi     # 0x3961b9
movl $0x1927, %edx           # imm = 0x1927
leaq 0x62132(%rip), %rcx     # 0x398139
callq 0x2130
movl -0x80(%rbp), %eax
movl -0x7c(%rbp), %ecx
subq %rcx, %rax
movq %rax, -0xa0(%rbp)
cmpq $0x1, -0xa0(%rbp)
jle 0x336028
jmp 0x33609d
movl -0x7c(%rbp), %eax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl -0x80(%rbp), %ecx
cmpq %rcx, %rax
jae 0x336076
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rax
imulq $0x18, -0x68(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movl 0x10(%rax), %eax
cmpl 0x10(%rbp), %eax
jne 0x336066
jmp 0x336076
jmp 0x336068
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x33602f
movq -0x68(%rbp), %rax
movl -0x80(%rbp), %ecx
cmpq %rcx, %rax
jae 0x336084
jmp 0x33609d
jmp 0x336086
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x335f7b
jmp 0x33609f
movq -0x90(%rbp), %rax
addq -0x98(%rbp), %rax
movl -0x24(%rbp), %ecx
cmpq %rcx, %rax
jb 0x3360b7
jmp 0x33612e
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x90(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdx
movl -0x24(%rbp), %eax
subq -0x90(%rbp), %rax
subq -0x98(%rbp), %rax
movl %eax, %ecx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %r9
movl 0x10(%rbp), %ebx
movq 0x18(%rbp), %r11
movq -0x40(%rbp), %r10
movq -0x90(%rbp), %rax
shlq $0x3, %rax
addq %rax, %r10
movq -0x48(%rbp), %rax
subq -0x90(%rbp), %rax
subq -0x98(%rbp), %rax
movl %ebx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x335220
addq $0xc8, %rsp
popq %rbx
popq %rbp
retq
nopl (%rax,%rax)