// File: /workspace/github_cpp_makefile_star2_O2/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 %r9, %r14
movq %rcx, %rbx
orq $-0x1, 0x28(%rsp)
movq %rsi, 0x8(%rsp)
movl %edx, %r9d
xorl %eax, %eax
cmpq %r9, %rax
je 0xfd541
movq 0x8(%rsp), %rcx
addl %eax, %ecx
movl (%rdi,%rcx,8), %ecx
movq 0x10(%rbx), %rdx
imulq $0x30, %rcx, %rsi
leaq (%rdx,%rsi), %rcx
movq (%rdx,%rsi), %rdx
xorl %esi, %esi
movl %esi, %esi
cmpq %rsi, %rdx
jbe 0xfd311
movq 0x10(%rcx), %r10
imulq $0x28, %rsi, %r11
incl %esi
testb $0x7f, 0x18(%r10,%r11)
jne 0xfd2f6
jmp 0xfd316
incq %rax
jmp 0xfd2d1
andq $0x0, (%r14)
xorl %ecx, %ecx
movq 0x8(%rsp), %rax
movl %eax, %ebp
movq %r9, %r15
xorl %r12d, %r12d
movq %r9, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq %r14, 0x20(%rsp)
subq $0x1, %r15
jb 0xfd3b8
movl %ebp, %eax
movl (%rdi,%rax,8), %r13d
movq 0x28(%r8), %rax
leal (,%r13,2), %edx
cmpl $0x0, (%rax,%rdx,8)
je 0xfd35f
movl %edx, %edx
cmpl $0x0, 0x8(%rax,%rdx,8)
jne 0xfd3b4
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0xfd3a3
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
movq %r8, %r14
callq 0x2370
movq %r14, %r8
movq 0x20(%rsp), %r14
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r9
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
movl %r13d, (%rax,%rcx,4)
incl %r12d
movq %rdx, %rcx
incl %ebp
jmp 0xfd338
testl %r12d, %r12d
je 0xfd541
xorl %ebp, %ebp
xorl %r13d, %r13d
cmpq %r9, %rbp
je 0xfd45e
movq 0x8(%rsp), %rax
addl %ebp, %eax
movq (%rdi,%rax,8), %r15
movl %r15d, %edx
movq 0x10(%rbx), %rax
imulq $0x30, %rdx, %rsi
movq (%rax,%rsi), %rdx
testq %rdx, %rdx
je 0xfd456
addq %rsi, %rax
xorl %esi, %esi
movl %esi, %esi
cmpq %rsi, %rdx
jbe 0xfd456
movq 0x10(%rax), %r11
imulq $0x28, %rsi, %r8
incl %esi
testb $0x7f, 0x18(%r11,%r8)
jne 0xfd3f3
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0xfd445
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r9
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
movl %r15d, (%rax,%rcx,4)
incl %r13d
movq %rdx, %rcx
incq %rbp
jmp 0xfd3c6
testl %r13d, %r13d
je 0xfd541
movq 0x10(%r14), %rax
movl %r12d, %ecx
movq %rax, 0x30(%rsp)
movq %rcx, 0x20(%rsp)
leaq (%rax,%rcx,4), %rbp
movl %r13d, %r13d
xorl %ecx, %ecx
movq %rbp, 0x18(%rsp)
cmpq 0x20(%rsp), %rcx
je 0xfd541
movq 0x30(%rsp), %rax
movq %rcx, 0x10(%rsp)
movl (%rax,%rcx,4), %r15d
imulq $0x30, %r15, %rax
movq %rax, 0x8(%rsp)
xorl %r14d, %r14d
cmpq %r14, %r13
je 0xfd534
movl (%rbp,%r14,4), %r12d
cmpl %r12d, %r15d
je 0xfd52c
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0xfcabc
testq %rax, %rax
jne 0xfd52c
orq $-0x1, 0x28(%rsp)
movq 0x10(%rbx), %rdi
addq 0x8(%rsp), %rdi
xorps %xmm0, %xmm0
movq %r12, %rsi
xorl %edx, %edx
movq %rbx, %rbp
leaq 0x28(%rsp), %rbx
movq %rbx, %rcx
callq 0xfa2fb
andb $-0x80, 0x18(%rax)
orq $-0x1, 0x20(%rax)
imulq $0x30, %r12, %rdi
addq 0x10(%rbp), %rdi
xorps %xmm0, %xmm0
movq %r15, %rsi
xorl %edx, %edx
movq %rbx, %rcx
movq %rbp, %rbx
movq 0x18(%rsp), %rbp
callq 0xfa2fb
andb $-0x80, 0x18(%rax)
orq $-0x1, 0x20(%rax)
incq %r14
jmp 0xfd4ab
movq 0x10(%rsp), %rcx
incq %rcx
jmp 0xfd486
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq