// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/hic.cpp
// Function: append_tig_link(unsigned long*, unsigned int, unsigned int, hc_links*, asg_t*, kvec_t_u32_warp*)
void append_tig_link(uint64_t *cc, uint32_t cc_off, uint32_t cc_size, hc_links *link, asg_t *sg, kvec_t_u32_warp *buf)
{
    uint32_t i, k, id, tig_occ, b_cc_occ, *tig, *b_cc, qn, tn;
    uint64_t t_d = (uint64_t)-1;
    hc_edge *p = NULL;
    for (i = 0; i < cc_size; ++i) ///how many nodes
    {
        id = (uint32_t)cc[cc_off + i];///node id
        for (k = 0; k < link->a.a[id].e.n; k++)
        {
            if(link->a.a[id].e.a[k].is_cc == 0) break;
        }
        if(k < link->a.a[id].e.n) break;
    }
    if(i >= cc_size) return;

    buf->a.n = 0; tig_occ = 0;
    for (i = 0; i < cc_size; ++i) ///how many nodes
    {
        id = (uint32_t)cc[cc_off + i];///node id
        
        if(asg_arc_n(sg, (id<<1)) == 0 || asg_arc_n(sg, ((id<<1)+1)) == 0)///tig
        {
            kv_push(uint32_t, buf->a, id);
            tig_occ++;
        }
    }

    if(tig_occ == 0) return;

    b_cc_occ = 0;
    for (i = 0; i < cc_size; ++i) ///how many nodes
    {
        id = (uint32_t)cc[cc_off + i];///node id
        if(link->a.a[id].e.n == 0) continue;

        for (k = 0; k < link->a.a[id].e.n; k++)
        {
            if(link->a.a[id].e.a[k].is_cc == 0) break;
        }
        if(k < link->a.a[id].e.n)///disconnected
        {
            kv_push(uint32_t, buf->a, id);
            b_cc_occ++;
        }
    }

    if(b_cc_occ == 0) return;

    tig = buf->a.a;
    b_cc = buf->a.a + tig_occ;
    for (i = 0; i < tig_occ; i++)
    {
        qn = tig[i];
        for (k = 0; k < b_cc_occ; k++)
        {
            tn = b_cc[k];
            if(qn == tn) continue;
            p = get_hc_edge(link, qn, tn, 0);
            if(p) continue;

            t_d = (uint64_t)-1;
            p = push_hc_edge(&(link->a.a[qn]), tn, 0, 0, &t_d);
            p->is_cc = 0; p->occ = (uint64_t)-1;
            p = push_hc_edge(&(link->a.a[tn]), qn, 0, 0, &t_d);
            p->is_cc = 0; p->occ = (uint64_t)-1;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x10(%rsp)
movq $-0x1, 0x30(%rsp)
testl %edx, %edx
je 0x144b9b
movq %r9, %r14
movq %rdi, %r12
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movl %edx, %r15d
xorl %ecx, %ecx
leal (%rcx,%rsi), %edx
movl (%r12,%rdx,8), %edx
leaq (%rdx,%rdx,2), %rdi
shlq $0x4, %rdi
movq (%rax,%rdi), %rdx
testq %rdx, %rdx
je 0x144952
addq %rax, %rdi
movq 0x10(%rdi), %r9
movl $0x1, %edi
xorl %r10d, %r10d
leaq (%r10,%r10,4), %r10
testb $0x7f, 0x18(%r9,%r10,8)
je 0x14495f
movl %edi, %r10d
incl %edi
cmpq %r10, %rdx
ja 0x14493c
incq %rcx
cmpq %r15, %rcx
jne 0x144915
jmp 0x144b9b
movq $0x0, (%r14)
xorl %ecx, %ecx
movq %r15, 0x18(%rsp)
movq %rsi, 0x8(%rsp)
movl %esi, %ebp
xorl %r9d, %r9d
movq %r14, 0x28(%rsp)
movl %ebp, %eax
movl (%r12,%rax,8), %ebx
movq 0x28(%r8), %rax
leal (%rbx,%rbx), %edx
cmpl $0x0, (%rax,%rdx,8)
je 0x144998
movl %edx, %edx
cmpl $0x0, 0x8(%rax,%rdx,8)
jne 0x1449f0
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x1449e0
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
movl %r9d, %r13d
movq %r12, %r14
movq %r8, %r12
callq 0x2370
movq %r12, %r8
movq %r14, %r12
movq 0x28(%rsp), %r14
movl %r13d, %r9d
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
movl %ebx, (%rax,%rcx,4)
incl %r9d
movq %rdx, %rcx
incl %ebp
decq %r15
jne 0x14497c
testl %r9d, %r9d
movq 0x8(%rsp), %r10
movq 0x18(%rsp), %rbx
je 0x144b9b
xorl %r15d, %r15d
xorl %ebp, %ebp
movl %r9d, 0x20(%rsp)
leal (%r15,%r10), %eax
movq (%r12,%rax,8), %r13
movl %r13d, %eax
movq 0x10(%rsp), %rdx
movq 0x10(%rdx), %rdx
leaq (%rax,%rax,2), %rsi
shlq $0x4, %rsi
movq (%rdx,%rsi), %rax
testq %rax, %rax
je 0x144aa8
addq %rsi, %rdx
movq 0x10(%rdx), %rdx
movl $0x1, %esi
xorl %edi, %edi
leaq (%rdi,%rdi,4), %rdi
testb $0x7f, 0x18(%rdx,%rdi,8)
je 0x144a5d
movl %esi, %edi
incl %esi
cmpq %rdi, %rax
ja 0x144a47
jmp 0x144aa8
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x144a98
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %r10
movl 0x20(%rsp), %r9d
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
movl %r13d, (%rax,%rcx,4)
incl %ebp
movq %rdx, %rcx
incq %r15
cmpq %rbx, %r15
jne 0x144a14
testl %ebp, %ebp
je 0x144b9b
movq 0x10(%r14), %rax
movl %r9d, %ecx
movq %rax, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
leaq (%rax,%rcx,4), %r13
movl %ebp, %ebp
xorl %ecx, %ecx
movq 0x10(%rsp), %rbx
movq 0x20(%rsp), %rax
movq %rcx, 0x8(%rsp)
movl (%rax,%rcx,4), %r15d
leaq (%r15,%r15,2), %rax
shlq $0x4, %rax
movq %rax, 0x28(%rsp)
xorl %r14d, %r14d
movl (%r13,%r14,4), %r12d
cmpl %r12d, %r15d
je 0x144b7c
movq 0x10(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x144201
testq %rax, %rax
jne 0x144b7c
movq $-0x1, %rax
movq %rax, 0x30(%rsp)
movq 0x10(%rbx), %rdi
addq 0x28(%rsp), %rdi
xorps %xmm0, %xmm0
movq %r12, %rsi
xorl %edx, %edx
leaq 0x30(%rsp), %rcx
callq 0x1416e0
andb $-0x80, 0x18(%rax)
movq $-0x1, %rcx
movq %rcx, 0x20(%rax)
leaq (%r12,%r12,2), %rdi
shlq $0x4, %rdi
addq 0x10(%rbx), %rdi
xorps %xmm0, %xmm0
movq %r15, %rsi
xorl %edx, %edx
leaq 0x30(%rsp), %rcx
callq 0x1416e0
andb $-0x80, 0x18(%rax)
movq $-0x1, %rcx
movq %rcx, 0x20(%rax)
incq %r14
cmpq %r14, %rbp
jne 0x144af8
movq 0x8(%rsp), %rcx
incq %rcx
cmpq 0x18(%rsp), %rcx
jne 0x144ada
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq