// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: usg_unique_arcs_cluster_adv(asg64_v*, unsigned long, unsigned long*, unsigned long*, asg64_v*)
uint32_t usg_unique_arcs_cluster_adv(asg64_v *b64, uint64_t a_n, uint64_t *idx, uint64_t *integ_seq, asg64_v *buf)
{
    uint64_t bn = b64->n, k, z, v; buf->n = 0;
    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, i;

    ///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
        if(cidx[i] != (uint64_t)-1) continue;
        iter_unique_arcs(buf, b64, a_n, idx, integ_seq, cidx, i);
    }

    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++;
        }
    }

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq (%rcx), %rcx
addq -0x10(%rbp), %rcx
cmpq %rcx, %rax
jae 0x356eec
movq -0x8(%rbp), %rax
movq (%rax), %rcx
addq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
shrq %rcx
movq -0x8(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x2, %rcx
movq -0x8(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x4, %rcx
movq -0x8(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x8, %rcx
movq -0x8(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x10, %rcx
movq -0x8(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x356eee
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
addq (%rax), %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x10(%rbp), %rdx
shlq $0x3, %rdx
movl $0xff, %esi
callq 0x2100
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x356f8e
movq -0x50(%rbp), %rax
movq -0x58(%rbp), %rcx
cmpq $-0x1, (%rax,%rcx,8)
je 0x356f5b
jmp 0x356f80
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x50(%rbp), %r9
movq -0x58(%rbp), %rax
movq %rax, (%rsp)
callq 0x356580
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x356f40
movq -0x50(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x10(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x30ed90
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq $0x0, -0x58(%rbp)
movq $0x1, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x10(%rbp), %rax
ja 0x3570b7
movq -0x38(%rbp), %rax
cmpq -0x10(%rbp), %rax
je 0x35700a
movq -0x50(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x50(%rbp), %rcx
movq -0x38(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
je 0x3570a4
movq -0x58(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
jae 0x357090
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq $-0x1, (%rax,%rcx,8)
je 0x35702d
jmp 0x35704c
leaq 0x42532(%rip), %rdi     # 0x399566
leaq 0x3f17e(%rip), %rsi     # 0x3961b9
movl $0x2fbc, %edx           # imm = 0x2FBC
leaq 0x425d4(%rip), %rcx     # 0x39961b
callq 0x2130
movq -0x48(%rbp), %rdx
shlq $0x20, %rdx
movq -0x50(%rbp), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
orq %rax, %rdx
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x8(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x357012
movq -0x38(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x3570a6
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x356fc9
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rcx
shlq %rcx
cmpq %rcx, %rax
jne 0x3570d7
jmp 0x3570f6
leaq 0x424a0(%rip), %rdi     # 0x39957e
leaq 0x3f0d4(%rip), %rsi     # 0x3961b9
movl $0x2fc5, %edx           # imm = 0x2FC5
leaq 0x4252a(%rip), %rcx     # 0x39961b
callq 0x2130
movq -0x48(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq