// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: usg_unique_arcs_cluster(asg64_v*, unsigned long, unsigned long*, unsigned long*)
uint32_t usg_unique_arcs_cluster(asg64_v *b64, uint64_t a_n, uint64_t *idx, uint64_t *integ_seq)
{
    uint64_t bn = b64->n, k, v; 
    kv_resize(uint64_t, *b64, b64->n + a_n); b64->n += a_n; 
    memset(b64->a + bn, -1, sizeof((*(b64->a)))*a_n);
    uint64_t *cidx = b64->a + bn, s, e, i, zs, ze, z;

    ///b64.a[0, a_n]:: all resolvable paths with unique beg && end
    ///b64.a[a_n, bn]:: (raw unitig/non-unqiue node id)|(resolvable path id)
    ///idx:: the idx for b64.a[a_n, bn]
    for (i = 0; i < a_n; i++) {///available interval with beg/end with unique arcs
        s = b64->a[i]>>32; e = (uint32_t)(b64->a[i]); assert(e > s);
        if(cidx[i] != (uint64_t)-1) continue;
        for (k = s + 1; k < e; k++) {///note: here is [s, e]
            v = integ_seq[k];///v is the raw unitig id
            zs = (idx[v]<<1)>>33; ze = (uint32_t)idx[v];
            for (z = zs; z < ze; z++) {
                // if((b64->a[z]>>32)!=v) {
                //     fprintf(stderr, "[M::%s::] v::%lu, b64->a[z]::%lu, zs::%lu, ze::%lu, a_n::%lu\n", 
                //                                     __func__, v, b64->a[z]>>32, zs, ze, a_n);
                // }
                ///(b64->a[z]>>32):: raw unitig id
                ///(uint32_t)b64->a[z]:: available interval id
                assert((b64->a[z]>>32)==v);
                cidx[((uint32_t)b64->a[z])] = (i<<32)|((uint32_t)b64->a[z]);
            }

            v = integ_seq[k]^1;
            zs = (idx[v]<<1)>>33; ze = (uint32_t)idx[v];
            for (z = zs; z < ze; z++) {
                assert((b64->a[z]>>32)==v);
                cidx[((uint32_t)b64->a[z])] = (i<<32)|((uint32_t)b64->a[z]);
            }
        }
        v = integ_seq[s];
        zs = (idx[v]<<1)>>33; ze = (uint32_t)idx[v];
        for (z = zs; z < ze; z++) {
            assert((b64->a[z]>>32)==v);
            cidx[((uint32_t)b64->a[z])] = (i<<32)|((uint32_t)b64->a[z]);
        }

        v = integ_seq[e]^1;
        zs = (idx[v]<<1)>>33; ze = (uint32_t)idx[v];
        for (z = zs; z < ze; z++) {
            assert((b64->a[z]>>32)==v);
            cidx[((uint32_t)b64->a[z])] = (i<<32)|((uint32_t)b64->a[z]);
        }
    }

    radix_sort_srt64(cidx, cidx + a_n); b64->n = a_n;
    for (i = 0, k = 1, v = 0; k <= a_n; k++) {
        if(k == a_n || (cidx[i]>>32) != (cidx[k]>>32)) {
            for (z = i; z < k; z++) {
                assert(cidx[z] != (uint64_t)-1);
                ///cluest integer seqs-> (cluster id)|(available interval id) 
                b64->a[b64->n++] = (v<<32)|((uint32_t)cidx[z]);
            }
            i = k; v++;
        }
    }

    assert(b64->n == (a_n<<1));
    return v;///how many cluster
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r14
movq (%rdi), %r15
leaq (%r15,%rsi), %rcx
cmpq %rcx, 0x8(%rdi)
jae 0x21857f
decq %rcx
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%r14)
movq 0x10(%r14), %rdi
leaq 0x8(,%rax,8), %rsi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rcx
addq %rbx, %rcx
jmp 0x218583
movq 0x10(%r14), %rax
movq %rcx, (%r14)
leaq (%rax,%r15,8), %rdi
leaq (,%rbx,8), %rdx
movl $0xff, %esi
callq 0x20e0
movq 0x10(%r14), %rax
leaq (%rax,%r15,8), %r15
testq %rbx, %rbx
je 0x21879e
xorl %ecx, %ecx
movq %rbx, (%rsp)
movq (%rax,%rcx,8), %rsi
movl %esi, %edx
shrq $0x20, %rsi
cmpq %rsi, %rdx
jbe 0x218867
cmpq $-0x1, (%r15,%rcx,8)
jne 0x21871b
leaq 0x1(%rsi), %rdi
cmpq %rdx, %rdi
jae 0x21867d
movq %rcx, %r8
shlq $0x20, %r8
movq (%r12,%rdi,8), %r9
movq (%r13,%r9,8), %r11
movl %r11d, %r10d
shrq $0x20, %r11
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
cmpq %r10, %r11
jae 0x21862d
movq (%rax,%r11,8), %rbx
movq %rbx, %rbp
shrq $0x20, %rbp
cmpq %r9, %rbp
jne 0x2187cc
movl %ebx, %ebx
movq %rbx, %rbp
orq %r8, %rbp
movq %rbp, (%r15,%rbx,8)
incq %r11
cmpq %r11, %r10
jne 0x218601
movq (%r12,%rdi,8), %r9
xorq $0x1, %r9
movq (%r13,%r9,8), %r11
movl %r11d, %r10d
shrq $0x20, %r11
andl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
cmpq %r10, %r11
jae 0x218671
movq (%rax,%r11,8), %rbp
movq %rbp, %rbx
shrq $0x20, %rbx
cmpq %r9, %rbx
jne 0x2187eb
movl %ebp, %ebx
movq %rbx, %rbp
orq %r8, %rbp
movq %rbp, (%r15,%rbx,8)
incq %r11
cmpq %r11, %r10
jne 0x218649
incq %rdi
cmpq %rdx, %rdi
jne 0x2185e5
movq (%r12,%rsi,8), %rsi
movq (%r13,%rsi,8), %r8
movl %r8d, %edi
shrq $0x20, %r8
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
cmpq %rdi, %r8
movq (%rsp), %rbx
jae 0x2186cd
movq %rcx, %r9
shlq $0x20, %r9
movq (%rax,%r8,8), %r10
movq %r10, %r11
shrq $0x20, %r11
cmpq %rsi, %r11
jne 0x218829
movl %r10d, %r10d
movq %r10, %r11
orq %r9, %r11
movq %r11, (%r15,%r10,8)
incq %r8
cmpq %r8, %rdi
jne 0x2186a4
movq (%r12,%rdx,8), %rdx
xorq $0x1, %rdx
movq (%r13,%rdx,8), %rdi
movl %edi, %esi
shrq $0x20, %rdi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
cmpq %rsi, %rdi
jae 0x21871b
movq %rcx, %r8
shlq $0x20, %r8
movq (%rax,%rdi,8), %r9
movq %r9, %r10
shrq $0x20, %r10
cmpq %rdx, %r10
jne 0x218848
movl %r9d, %r9d
movq %r9, %r10
orq %r8, %r10
movq %r10, (%r15,%r9,8)
incq %rdi
cmpq %rdi, %rsi
jne 0x2186f2
incq %rcx
cmpq %rbx, %rcx
jne 0x2185b3
leaq (%r15,%rbx,8), %rsi
movq %r15, %rdi
callq 0x1ee586
movq %rbx, (%r14)
movl $0x1, %ecx
xorl %edx, %edx
xorl %eax, %eax
cmpq %rbx, %rcx
je 0x218752
movq (%r15,%rcx,8), %rsi
xorq (%r15,%rdx,8), %rsi
shrq $0x20, %rsi
je 0x218791
cmpq %rcx, %rdx
jae 0x21878b
movq %rax, %rsi
shlq $0x20, %rsi
movq (%r15,%rdx,8), %rdi
cmpq $-0x1, %rdi
je 0x21880a
movl %edi, %edi
orq %rsi, %rdi
movq (%r14), %r8
movq 0x10(%r14), %r9
leaq 0x1(%r8), %r10
movq %r10, (%r14)
movq %rdi, (%r9,%r8,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x21875e
incq %rax
movq %rcx, %rdx
incq %rcx
cmpq %rbx, %rcx
jbe 0x21873f
movq (%r14), %rcx
jmp 0x2187b1
leaq (%r15,%rbx,8), %rsi
movq %r15, %rdi
callq 0x1ee586
movq %rbx, (%r14)
xorl %ecx, %ecx
xorl %eax, %eax
addq %rbx, %rbx
cmpq %rbx, %rcx
jne 0x218886
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30090(%rip), %rdi     # 0x248863
leaq 0x2ce2f(%rip), %rsi     # 0x245609
leaq 0x30034(%rip), %rcx     # 0x248815
movl $0x2f3d, %edx           # imm = 0x2F3D
callq 0x2110
leaq 0x30071(%rip), %rdi     # 0x248863
leaq 0x2ce10(%rip), %rsi     # 0x245609
leaq 0x30015(%rip), %rcx     # 0x248815
movl $0x2f44, %edx           # imm = 0x2F44
callq 0x2110
leaq 0x30065(%rip), %rdi     # 0x248876
leaq 0x2cdf1(%rip), %rsi     # 0x245609
leaq 0x2fff6(%rip), %rcx     # 0x248815
movl $0x2f5b, %edx           # imm = 0x2F5B
callq 0x2110
leaq 0x30033(%rip), %rdi     # 0x248863
leaq 0x2cdd2(%rip), %rsi     # 0x245609
leaq 0x2ffd7(%rip), %rcx     # 0x248815
movl $0x2f4b, %edx           # imm = 0x2F4B
callq 0x2110
leaq 0x30014(%rip), %rdi     # 0x248863
leaq 0x2cdb3(%rip), %rsi     # 0x245609
leaq 0x2ffb8(%rip), %rcx     # 0x248815
movl $0x2f52, %edx           # imm = 0x2F52
callq 0x2110
leaq 0x2ffa1(%rip), %rdi     # 0x24880f
leaq 0x2cd94(%rip), %rsi     # 0x245609
leaq 0x2ff99(%rip), %rcx     # 0x248815
movl $0x2f31, %edx           # imm = 0x2F31
callq 0x2110
leaq 0x30001(%rip), %rdi     # 0x24888e
leaq 0x2cd75(%rip), %rsi     # 0x245609
leaq 0x2ff7a(%rip), %rcx     # 0x248815
movl $0x2f63, %edx           # imm = 0x2F63
callq 0x2110