// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movq $-0x1, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0x1d1980
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x34(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1d1954
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x30(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
andb $0x7f, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x1d1947
jmp 0x1d1954
jmp 0x1d1949
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1d18fe
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x34(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1d1970
jmp 0x1d1980
jmp 0x1d1972
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1d18d8
movl -0x2c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jb 0x1d198d
jmp 0x1d1d61
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0x1d1a9e
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x34(%rbp), %ecx
shll %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x0, %eax
je 0x1d19fc
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x34(%rbp), %ecx
shll %ecx
addl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
cmpl $0x0, %eax
jne 0x1d1a8e
jmp 0x1d19fe
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1d1a66
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1d1a2b
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x1d1a36
movl $0x2, %eax
movq %rax, -0x70(%rbp)
jmp 0x1d1a36
movq -0x70(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x34(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1d1a90
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1d19a6
cmpl $0x0, -0x38(%rbp)
jne 0x1d1aa9
jmp 0x1d1d61
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0x1d1c10
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
jne 0x1d1af3
jmp 0x1d1c02
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x34(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1d1b50
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x30(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
andb $0x7f, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x1d1b43
jmp 0x1d1b50
jmp 0x1d1b45
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1d1afa
movl -0x30(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x34(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1d1c00
jmp 0x1d1b70
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1d1bd8
movq -0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1d1b9d
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x78(%rbp)
jmp 0x1d1ba8
movl $0x2, %eax
movq %rax, -0x78(%rbp)
jmp 0x1d1ba8
movq -0x78(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x34(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1d1c02
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1d1ab7
cmpl $0x0, -0x3c(%rbp)
jne 0x1d1c1b
jmp 0x1d1d61
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x38(%rbp), %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x1d1d61
movq -0x48(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x54(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jae 0x1d1d51
movq -0x50(%rbp), %rax
movl -0x30(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x58(%rbp), %eax
jne 0x1d1c8a
jmp 0x1d1d43
movq -0x18(%rbp), %rdi
movl -0x54(%rbp), %eax
movl %eax, %esi
movl -0x58(%rbp), %eax
movl %eax, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1d09c0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x1d1cb1
jmp 0x1d1d43
movq $-0x1, -0x60(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x54(%rbp), %eax
imulq $0x30, %rax, %rax
addq %rax, %rdi
movl -0x58(%rbp), %eax
movl %eax, %esi
xorps %xmm0, %xmm0
xorl %edx, %edx
leaq -0x60(%rbp), %rcx
callq 0x1cb380
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movb 0x18(%rax), %cl
andb $-0x80, %cl
orb $0x0, %cl
movb %cl, 0x18(%rax)
movq -0x68(%rbp), %rax
movq $-0x1, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x58(%rbp), %eax
imulq $0x30, %rax, %rax
addq %rax, %rdi
movl -0x54(%rbp), %eax
movl %eax, %esi
xorps %xmm0, %xmm0
xorl %edx, %edx
leaq -0x60(%rbp), %rcx
callq 0x1cb380
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movb 0x18(%rax), %cl
andb $-0x80, %cl
orb $0x0, %cl
movb %cl, 0x18(%rax)
movq -0x68(%rbp), %rax
movq $-0x1, 0x20(%rax)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1d1c64
jmp 0x1d1d53
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x1d1c44
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)