// File: /workspace/github_cpp_makefile_star2_O1/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 0x214ea5
movq 0x10(%r12), %rax
movq (%rax,%r14,8), %rax
movq %rax, %rbp
shrq $0x20, %rbp
movl %eax, %r13d
cmpq %rbp, %r13
jbe 0x214fad
testq %rax, %rax
js 0x214f8e
leaq 0x1(%rbp), %rbx
jmp 0x214dda
movq 0x8(%r12), %rax
cmpq %rax, (%r12)
jne 0x214d5c
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rax
movq 0x10(%r12), %rdi
leaq 0x1(%rax), %rcx
movq %rcx, (%r12)
movq (%r15,%rbx,8), %rcx
shlq $0x20, %rcx
orq %r14, %rcx
movq %rcx, (%rdi,%rax,8)
movq 0x8(%r12), %rax
cmpq %rax, (%r12)
jne 0x214daa
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rax
movq 0x10(%r12), %rcx
leaq 0x1(%rax), %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, (%rcx,%rax,8)
incq %rbx
cmpq %rbx, %r13
ja 0x214d29
movq 0x8(%r12), %rax
cmpq %rax, (%r12)
jne 0x214e16
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rax
movq 0x10(%r12), %rdi
leaq 0x1(%rax), %rcx
movq %rcx, (%r12)
movq (%r15,%rbp,8), %rcx
shlq $0x20, %rcx
orq %r14, %rcx
movq %rcx, (%rdi,%rax,8)
movq 0x8(%r12), %rax
cmpq %rax, (%r12)
movq 0xa8(%rsp), %rbx
jne 0x214e6c
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r12)
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rax
movq 0x10(%r12), %rcx
leaq 0x1(%rax), %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, (%rcx,%rax,8)
incl %r14d
cmpq %rbx, %r14
jb 0x214cfb
movq (%r12), %rax
movq 0x10(%r12), %rcx
leaq (%rcx,%rbx,8), %rdi
leaq (%rcx,%rax,8), %rsi
callq 0x1e3b6a
leal 0x1(%rbx), %eax
movq (%r12), %rdi
cmpq %rax, %rdi
movq 0xa0(%rsp), %r14
movq 0x90(%rsp), %rdx
jb 0x214f21
leal 0x2(%rbx), %ecx
movl %ebx, %r9d
movl %r9d, %esi
cmpq %rax, %rdi
je 0x214ef8
movq 0x10(%r12), %rdi
movq (%rdi,%rsi,8), %r8
xorq (%rdi,%rax,8), %r8
shrq $0x20, %r8
je 0x214f14
leal -0x1(%rcx), %r9d
movq 0x10(%r12), %rdi
movl 0x4(%rdi,%rsi,8), %edi
shlq $0x20, %rsi
orq (%rdx,%rdi,8), %rsi
orq %rax, %rsi
movq %rsi, (%rdx,%rdi,8)
movl %ecx, %eax
movq (%r12), %rdi
incl %ecx
cmpq %rax, %rdi
jae 0x214edd
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rcx
movq %r14, %r8
callq 0x20dac8
leaq (%rbx,%rbx), %rax
cmpq %rax, (%r12)
jne 0x214fcc
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 0x210b27
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2808d(%rip), %rdi     # 0x23d022
leaq 0x24389(%rip), %rsi     # 0x239325
leaq 0x283e5(%rip), %rcx     # 0x23d388
movl $0x37e9, %edx           # imm = 0x37E9
callq 0x2110
leaq 0x27577(%rip), %rdi     # 0x23c52b
leaq 0x2436a(%rip), %rsi     # 0x239325
leaq 0x283c6(%rip), %rcx     # 0x23d388
movl $0x37e8, %edx           # imm = 0x37E8
callq 0x2110
leaq 0x275d7(%rip), %rdi     # 0x23c5aa
leaq 0x2434b(%rip), %rsi     # 0x239325
leaq 0x283a7(%rip), %rcx     # 0x23d388
movl $0x380c, %edx           # imm = 0x380C
callq 0x2110