// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: ug_ext_0(ul_resolve_t*, usg_t*, unsigned long*, unsigned long, unsigned long*, unsigned int, unsigned char*, unsigned int*, unsigned long*, asg64_v*, asg64_v*, unsigned long)
uint32_t ug_ext_0(ul_resolve_t *uidx, usg_t *ng, uint64_t *int_idx, uint64_t int_idx_n, uint64_t *int_a, uint32_t max_ext, 
uint8_t *ff, uint32_t *ng_occ, uint64_t *i_idx, asg64_v *b64, asg64_v *ub64, uint64_t a_n)
{
    uint32_t n_vtx = ng->n<<1, k, i; uint64_t *pz;
    uint64_t s, e, n_clus;
    memset(ff, 0, sizeof((*ff))*n_vtx);
    // memset(ng_occ, 0, sizeof((*ng_occ))*n_vtx); 
    memset(i_idx, 0, sizeof((*i_idx))*n_vtx); 
    ub64->n = 0;

    for (i = 0; i < a_n; i++) { ///available intervals
        s = b64->a[i]>>32; e = (uint32_t)b64->a[i]; assert(e > s);///[s, e] -> coordinates within int_a[]
        assert(!(b64->a[i]&((uint64_t)0x8000000000000000)));
        // fprintf(stderr, "\n[M::%s::] occ::%lu\n", __func__, e - s);
        // for (k = s; k <= e; k++) {
        //     // fprintf(stderr, "utg%.6dl(%c),", (int32_t)(int_a[k]>>1)+1, "+-"[int_a[k]&1]);
        //     fprintf(stderr, "utg%.6dl,", (int32_t)(int_a[k]>>1)+1);
        // }
        // fprintf(stderr, "\n");

        for (k = s + 1; k < e; k++) {///note: here is [s, e]; s && e are unique, but [s+1, e-1] are not unique
            kv_pushp(uint64_t, *b64, &pz); //i_idx[int_a[k]]++;
            (*pz) = int_a[k]; (*pz) <<= 32; (*pz) |= i;///(raw unitig/non-unqiue node id)|(integer contig id)

            kv_pushp(uint64_t, *b64, &pz); //i_idx[int_a[k]^1]++;
            (*pz) = int_a[k]^1; (*pz) <<= 32; (*pz) |= i;
        }
        kv_pushp(uint64_t, *b64, &pz); //i_idx[int_a[s]]++;
        (*pz) = int_a[s]; (*pz) <<= 32; (*pz) |= i;

        kv_pushp(uint64_t, *b64, &pz); //i_idx[int_a[e]^1]++;
        (*pz) = int_a[e]^1; (*pz) <<= 32; (*pz) |= i;
    }
    // prt_thread_info(b64.a, a_n, NULL, 0, "tt2");
    // fprintf(stderr, "**1**[M::%s::] a_n::%lu, ua_n::%lu\n", __func__, a_n, ua_n);
    ///index
    radix_sort_srt64(b64->a + a_n, b64->a + b64->n);///(raw unitig node id)|(integer contig id)
    for (k = a_n + 1, i = a_n; k <= b64->n; k++) {
        if(k == b64->n || (b64->a[k]>>32) != (b64->a[i]>>32)) {
            i_idx[b64->a[i]>>32] |= (((uint64_t)i)<<32)|((uint64_t)k);///b64.a[i]>>32 appear once (unique ends)/multipe times
            i = k;
        }
    }

    n_clus = usg_unique_arcs_cluster_adv(b64, a_n, i_idx, int_a, ub64);
    // fprintf(stderr, "**3**[M::%s::] a_n::%lu, n_clus::%lu\n", __func__, a_n, n_clus);
    // prt_thread_info(b64.a, a_n, NULL, 0, "tt4");
    assert(b64->n == (a_n<<1));
    
    // new_path_ext(uidx, ng, &b64, &ub64, a_n, n_clus, i_idx, int_a, ff, ng_occ, max_ext);//wrong
    return old_path_ext(uidx, ng, b64, ub64, a_n, n_clus, i_idx, int_a, ff, ng_occ, max_ext);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, 0x34(%rsp)
movq %r8, %r15
movq %rdi, 0x38(%rsp)
movq 0xa8(%rsp), %rbx
movq 0x98(%rsp), %r12
movq 0x90(%rsp), %r13
movq 0x80(%rsp), %rdi
movq %rsi, 0x40(%rsp)
movl 0x8(%rsi), %ebp
addl %ebp, %ebp
xorl %r14d, %r14d
xorl %esi, %esi
movq %rbp, %rdx
callq 0x20e0
shlq $0x3, %rbp
movq %r13, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x20e0
movq 0xa0(%rsp), %rax
movq $0x0, (%rax)
testq %rbx, %rbx
je 0x2202e7
movq 0x10(%r12), %rax
movq (%rax,%r14,8), %rcx
movq %rcx, %rbp
shrq $0x20, %rbp
movl %ecx, %r13d
cmpq %rbp, %r13
jbe 0x2203f5
testq %rcx, %rcx
js 0x2203d6
leaq 0x1(%rbp), %rbx
jmp 0x220223
movq (%r12), %rcx
cmpq 0x8(%r12), %rcx
jne 0x2201b0
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r12)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r12)
movq (%r15,%rbx,8), %rdx
shlq $0x20, %rdx
orq %r14, %rdx
movq %rdx, (%rax,%rcx,8)
movq (%r12), %rcx
cmpq 0x8(%r12), %rcx
jne 0x2201fc
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r12)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r12)
movq (%r15,%rbx,8), %rdx
shlq $0x20, %rdx
orq %r14, %rdx
movabsq $0x100000000, %rsi      # imm = 0x100000000
xorq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
incq %rbx
cmpq %rbx, %r13
ja 0x22017b
movq (%r12), %rcx
cmpq 0x8(%r12), %rcx
jne 0x220261
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r12)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
movq 0xa8(%rsp), %rbx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r12)
movq (%r15,%rbp,8), %rdx
shlq $0x20, %rdx
orq %r14, %rdx
movq %rdx, (%rax,%rcx,8)
movq (%r12), %rcx
cmpq 0x8(%r12), %rcx
jne 0x2202b5
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r12)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r12)
movq (%r15,%r13,8), %rdx
shlq $0x20, %rdx
orq %r14, %rdx
movabsq $0x100000000, %rsi      # imm = 0x100000000
xorq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
incl %r14d
cmpq %rbx, %r14
jb 0x220152
jmp 0x2202ec
movq 0x10(%r12), %rax
leaq (%rax,%rbx,8), %rdi
movq (%r12), %rcx
leaq (%rax,%rcx,8), %rsi
callq 0x1ee586
leal 0x1(%rbx), %ecx
movq (%r12), %rsi
cmpq %rcx, %rsi
movq 0xa0(%rsp), %r14
movq 0x90(%rsp), %rdx
jb 0x220369
movq 0x10(%r12), %rax
leal 0x2(%rbx), %r11d
movl %ebx, %edi
movl %edi, %r8d
cmpq %rcx, %rsi
jne 0x220332
movq (%rax,%r8,8), %r9
jmp 0x220343
movq (%rax,%r8,8), %r9
movq (%rax,%rcx,8), %r10
xorq %r9, %r10
shrq $0x20, %r10
je 0x22035e
shlq $0x20, %r8
shrq $0x20, %r9
orq (%rdx,%r9,8), %r8
leal -0x1(%r11), %edi
orq %rcx, %r8
movq %r8, (%rdx,%r9,8)
movq (%r12), %rsi
movl %r11d, %ecx
incl %r11d
cmpq %rcx, %rsi
jae 0x220324
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rcx
movq %r14, %r8
callq 0x218d9b
leaq (%rbx,%rbx), %rax
cmpq %rax, (%r12)
jne 0x220414
movq 0x88(%rsp), %rax
movl 0x34(%rsp), %ecx
movl %ecx, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r15, 0x8(%rsp)
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq %r12, %rdx
movq %r14, %rcx
movq %rbx, %r8
callq 0x21beee
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28f29(%rip), %rdi     # 0x249306
leaq 0x25225(%rip), %rsi     # 0x245609
leaq 0x29281(%rip), %rcx     # 0x24966c
movl $0x37e9, %edx           # imm = 0x37E9
callq 0x2110
leaq 0x28413(%rip), %rdi     # 0x24880f
leaq 0x25206(%rip), %rsi     # 0x245609
leaq 0x29262(%rip), %rcx     # 0x24966c
movl $0x37e8, %edx           # imm = 0x37E8
callq 0x2110
leaq 0x28473(%rip), %rdi     # 0x24888e
leaq 0x251e7(%rip), %rsi     # 0x245609
leaq 0x29243(%rip), %rcx     # 0x24966c
movl $0x380c, %edx           # imm = 0x380C
callq 0x2110