// File: /workspace/github_cpp_makefile_star2_O2/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), %r14
movq 0x98(%rsp), %r12
movq 0x90(%rsp), %r13
movq 0x80(%rsp), %rdi
movq %rsi, 0x40(%rsp)
movl 0x8(%rsi), %ebp
addl %ebp, %ebp
xorl %ebx, %ebx
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
andq $0x0, (%rax)
movl %ebx, %r13d
movq 0x10(%r12), %rax
cmpq %r14, %r13
jae 0x1d13bf
movq (%rax,%r13,8), %rcx
movq %rcx, %r14
shrq $0x20, %r14
movl %ecx, %ebx
cmpq %r14, %rbx
jbe 0x1d14a0
testq %rcx, %rcx
js 0x1d14bf
leaq 0x1(%r14), %rbp
movq (%r12), %rcx
movq 0x8(%r12), %rdx
cmpq %rbp, %rbx
jbe 0x1d1313
cmpq %rdx, %rcx
jne 0x1d129d
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
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,%rbp,8), %rdx
shlq $0x20, %rdx
orq %r13, %rdx
movq %rdx, (%rax,%rcx,8)
movq (%r12), %rcx
cmpq 0x8(%r12), %rcx
jne 0x1d12e7
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
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,%rbp,8), %rdx
shlq $0x20, %rdx
orq %r13, %rdx
movabsq $0x100000000, %rsi      # imm = 0x100000000
xorq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
incq %rbp
jmp 0x1d125e
cmpq %rdx, %rcx
jne 0x1d1340
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
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,%r14,8), %rdx
shlq $0x20, %rdx
orq %r13, %rdx
movq %rdx, (%rax,%rcx,8)
movq (%r12), %rcx
cmpq 0x8(%r12), %rcx
jne 0x1d138a
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
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), %r14
leaq 0x1(%rcx), %rdx
movq %rdx, (%r12)
movq (%r15,%rbx,8), %rdx
shlq $0x20, %rdx
orq %r13, %rdx
movabsq $0x100000000, %rsi      # imm = 0x100000000
xorq %rsi, %rdx
movq %rdx, (%rax,%rcx,8)
leal 0x1(%r13), %ebx
jmp 0x1d122a
leaq (%rax,%r14,8), %rdi
movq (%r12), %rcx
leaq (%rax,%rcx,8), %rsi
callq 0x1a3def
movl %r14d, %eax
movq 0xa0(%rsp), %rbx
movq 0x90(%rsp), %rdx
movq (%r12), %rsi
movl %eax, %ecx
incl %eax
movl %eax, %r8d
movl %r8d, %r10d
cmpq %r10, %rsi
jb 0x1d1433
movl %r8d, %eax
movq 0x10(%r12), %r8
je 0x1d141a
movq (%r8,%rcx,8), %rdi
movq (%r8,%r10,8), %r9
xorq %rdi, %r9
shrq $0x20, %r9
leal 0x1(%rax), %r8d
testq %r9, %r9
je 0x1d13ee
jmp 0x1d141e
movq (%r8,%rcx,8), %rdi
shlq $0x20, %rcx
shrq $0x20, %rdi
orq (%rdx,%rdi,8), %rcx
orq %r10, %rcx
movq %rcx, (%rdx,%rdi,8)
jmp 0x1d13e3
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rcx
movq %rbx, %r8
callq 0x1ca70e
leaq (%r14,%r14), %rax
cmpq %rax, (%r12)
jne 0x1d14de
movl 0x34(%rsp), %eax
movl %eax, 0x20(%rsp)
movq 0x88(%rsp), %rax
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 %rbx, %rcx
movq %r14, %r8
callq 0x1cd29e
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x29327(%rip), %rdi     # 0x1fa7ce
leaq 0x2602b(%rip), %rsi     # 0x1f74d9
leaq 0x2a176(%rip), %rcx     # 0x1fb62b
movl $0x37e8, %edx           # imm = 0x37E8
callq 0x2110
leaq 0x29dff(%rip), %rdi     # 0x1fb2c5
leaq 0x2600c(%rip), %rsi     # 0x1f74d9
leaq 0x2a157(%rip), %rcx     # 0x1fb62b
movl $0x37e9, %edx           # imm = 0x37E9
callq 0x2110
leaq 0x29368(%rip), %rdi     # 0x1fa84d
leaq 0x25fed(%rip), %rsi     # 0x1f74d9
leaq 0x2a138(%rip), %rcx     # 0x1fb62b
movl $0x380c, %edx           # imm = 0x380C
callq 0x2110