// File: /workspace/github_cpp_makefile_star2_O1/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, 0x8(%rsp)
movq $-0x1, 0x30(%rsp)
testl %edx, %edx
setne %al
je 0x13ed18
movl %esi, %r15d
movq %rdi, %r12
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
movl %edx, %ebp
xorl %edx, %edx
leal (%rdx,%r15), %esi
movl (%r12,%rsi,8), %esi
leaq (%rsi,%rsi,2), %rdi
shlq $0x4, %rdi
movq (%rcx,%rdi), %rsi
testq %rsi, %rsi
setne %bl
je 0x13ed0d
addq %rcx, %rdi
movq 0x10(%rdi), %rdi
testb $0x7f, 0x18(%rdi)
je 0x13ed09
movl $0x1, %r11d
movl %r11d, %r11d
cmpq %r11, %rsi
seta %bl
jbe 0x13ed0d
leaq (%r11,%r11,4), %r10
incl %r11d
testb $0x7f, 0x18(%rdi,%r10,8)
jne 0x13ecef
testb %bl, %bl
jne 0x13ed27
incq %rdx
cmpq %rbp, %rdx
setb %al
jne 0x13ecc0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x1, %al
je 0x13ed18
movq $0x0, (%r9)
xorl %ebx, %ebx
movq %rbp, 0x18(%rsp)
movl %r15d, %r13d
movq %r9, 0x10(%rsp)
movq %r15, 0x28(%rsp)
movl %r13d, %eax
movl (%r12,%rax,8), %r14d
movq 0x28(%r8), %rax
leal (%r14,%r14), %ecx
cmpl $0x0, (%rax,%rcx,8)
je 0x13ed64
movl %ecx, %ecx
cmpl $0x0, 0x8(%rax,%rcx,8)
jne 0x13edb6
movq 0x8(%r9), %rax
cmpq %rax, (%r9)
jne 0x13eda2
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r9)
movq 0x10(%r9), %rdi
shlq $0x2, %rsi
movq %r8, %r15
callq 0x2370
movq %r15, %r8
movq 0x28(%rsp), %r15
movq 0x10(%rsp), %r9
movq %rax, 0x10(%r9)
movq (%r9), %rax
movq 0x10(%r9), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r9)
movl %r14d, (%rcx,%rax,4)
incl %ebx
incl %r13d
decq %rbp
jne 0x13ed46
testl %ebx, %ebx
movq 0x18(%rsp), %r14
je 0x13ed18
xorl %r13d, %r13d
xorl %r8d, %r8d
leal (%r15,%r13), %eax
movq (%r12,%rax,8), %rbp
movl %ebp, %eax
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
leaq (%rax,%rax,2), %rdx
shlq $0x4, %rdx
movq (%rcx,%rdx), %rax
testq %rax, %rax
je 0x13ee72
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
testb $0x7f, 0x18(%rcx)
je 0x13ee21
movl $0x1, %esi
movl %esi, %edx
cmpq %rdx, %rax
jbe 0x13ee72
leaq (%rdx,%rdx,4), %rdi
leal 0x1(%rdx), %esi
testb $0x7f, 0x18(%rcx,%rdi,8)
jne 0x13ee07
cmpq %rdx, %rax
jbe 0x13ee72
movq 0x8(%r9), %rax
cmpq %rax, (%r9)
jne 0x13ee5e
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r9)
movq 0x10(%r9), %rdi
shlq $0x2, %rsi
movl %r8d, 0x20(%rsp)
callq 0x2370
movl 0x20(%rsp), %r8d
movq 0x10(%rsp), %r9
movq %rax, 0x10(%r9)
movq (%r9), %rax
movq 0x10(%r9), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r9)
movl %ebp, (%rcx,%rax,4)
incl %r8d
incq %r13
cmpq %r14, %r13
jne 0x13edd1
testl %r8d, %r8d
je 0x13ed18
movq 0x10(%r9), %rax
movl %ebx, %ecx
movq %rax, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
leaq (%rax,%rcx,4), %rbp
movl %r8d, %esi
xorl %ecx, %ecx
movq %rsi, 0x10(%rsp)
movq 0x8(%rsp), %r13
movq 0x20(%rsp), %rax
movq %rcx, 0x28(%rsp)
movl (%rax,%rcx,4), %ebx
leaq (%rbx,%rbx,2), %r15
shlq $0x4, %r15
xorl %r14d, %r14d
movl (%rbp,%r14,4), %r12d
cmpl %r12d, %ebx
je 0x13ef73
movq 0x8(%rsp), %rax
cmpq %rbx, (%rax)
jbe 0x13ef0d
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movq (%rax,%r15), %rcx
testq %rcx, %rcx
je 0x13ef0d
movq 0x10(%rax,%r15), %rax
cmpb $0x0, 0x18(%rax)
js 0x13eefd
cmpl %r12d, 0x8(%rax)
je 0x13ef08
addq $0x28, %rax
decq %rcx
jne 0x13eef1
xorl %eax, %eax
testq %rax, %rax
jne 0x13ef73
movq $-0x1, %rax
movq %rax, 0x30(%rsp)
movq 0x10(%r13), %rdi
addq %r15, %rdi
xorps %xmm0, %xmm0
movq %r12, %rsi
xorl %edx, %edx
leaq 0x30(%rsp), %rcx
callq 0x13b8bb
andb $-0x80, 0x18(%rax)
movq $-0x1, %rcx
movq %rcx, 0x20(%rax)
leaq (%r12,%r12,2), %rdi
shlq $0x4, %rdi
addq 0x10(%r13), %rdi
xorps %xmm0, %xmm0
movq %rbx, %rsi
xorl %edx, %edx
leaq 0x30(%rsp), %rcx
callq 0x13b8bb
movq 0x10(%rsp), %rsi
andb $-0x80, 0x18(%rax)
movq $-0x1, %rcx
movq %rcx, 0x20(%rax)
incq %r14
cmpq %rsi, %r14
jne 0x13eec2
movq 0x28(%rsp), %rcx
incq %rcx
cmpq 0x18(%rsp), %rcx
jne 0x13eeaa
jmp 0x13ed18