// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/hic.cpp
// Function: init_hic_advance(ha_ug_index*, kvec_pe_hit*, hc_links*, bubble_type*, H_partition*, unsigned int)
void init_hic_advance(ha_ug_index* idx, kvec_pe_hit* hits, hc_links* link, bubble_type* bub, H_partition* hap, uint32_t ignore_dis)
{
    uint64_t k, i, m, is_comples_weight = 0;
    trans_idx dis;
    kv_init(dis);
    
    if(bub->round_id > 0 && ignore_dis == 0)
    {
        is_comples_weight = get_trans_rate_function_advance(idx, hits, link, bub, hap, NULL, NULL, &dis);
    }
    

    hc_edge *e = NULL;
    for (i = 0; i < link->a.n; i++)
    {
        for (k = 0; k < link->a.a[i].e.n; k++)
        {
            if(link->a.a[i].e.a[k].del) continue;
            if(link->a.a[i].e.a[k].dis == (uint64_t)-1)
            {
                e = get_hc_edge(link, link->a.a[i].e.a[k].uID, i, 0);
                if(!e) fprintf(stderr, "ERROR\n");
                e->del = link->a.a[i].e.a[k].del = 1;
            }
        }
    }

    for (i = 0; i < link->a.n; i++)
    {
        for (k = m = 0; k < link->a.a[i].e.n; k++)
        {
            if(link->a.a[i].e.a[k].del) continue;
            link->a.a[i].e.a[m] = link->a.a[i].e.a[k];
            link->a.a[i].e.a[m].weight = 0;
            link->a.a[i].e.a[m].occ = 0;
            m++;
        }
        link->a.a[i].e.n = m;
    }

    weight_edges_advance(idx, hits, link, bub, is_comples_weight == 1? &dis : NULL);

    for (i = 0; i < link->a.n; i++)
    {
        for (k = 0; k < link->a.a[i].e.n; k++)
        {
            if(link->a.a[i].e.a[k].del) continue;
            if(link->a.a[i].e.a[k].weight <= 0)
            {
                e = get_hc_edge(link, link->a.a[i].e.a[k].uID, i, 0);
                e->del = link->a.a[i].e.a[k].del = 1;
            }
        }
    }

    for (i = 0; i < link->a.n; i++)
    {
        for (k = m = 0; k < link->a.a[i].e.n; k++)
        {
            if(link->a.a[i].e.a[k].del) continue;
            link->a.a[i].e.a[m] = link->a.a[i].e.a[k];
            m++;
        }
        link->a.a[i].e.n = m;
    }
    kv_destroy(dis);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
xorl %eax, %eax
testl %r9d, %r9d
jne 0x14bec2
cmpl $0x0, 0x8(%r14)
je 0x14bec2
leaq 0x20(%rsp), %rax
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movq %r14, %rcx
xorl %r9d, %r9d
pushq %rax
pushq $0x0
callq 0x14b663
addq $0x10, %rsp
movl %eax, 0x4(%rsp)
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
cmpq $0x0, (%rbx)
je 0x14bf92
xorl %r13d, %r13d
movq 0x10(%rbx), %rax
leaq (,%r13,2), %r15
addq %r13, %r15
shlq $0x4, %r15
cmpq $0x0, (%rax,%r15)
je 0x14bf86
xorl %r12d, %r12d
movq 0x10(%rax,%r15), %rcx
leaq (%r12,%r12,4), %rbp
cmpb $0x0, 0x18(%rcx,%rbp,8)
js 0x14bf70
leaq (%rcx,%rbp,8), %rcx
cmpq $-0x1, 0x10(%rcx)
jne 0x14bf70
movl 0x8(%rcx), %ecx
cmpq %rcx, (%rbx)
jbe 0x14bf55
leaq (%rcx,%rcx,2), %rdx
shlq $0x4, %rdx
movq (%rax,%rdx), %rcx
testq %rcx, %rcx
je 0x14bf55
movq 0x10(%rax,%rdx), %r14
cmpb $0x0, 0x18(%r14)
js 0x14bf4c
movl 0x8(%r14), %eax
cmpq %rax, %r13
je 0x14bf58
addq $0x28, %r14
decq %rcx
jne 0x14bf3c
xorl %r14d, %r14d
testq %r14, %r14
je 0x14bf7f
movq 0x10(%rbx), %rax
movq 0x10(%rax,%r15), %rax
orb $-0x80, 0x18(%rax,%rbp,8)
orb $-0x80, 0x18(%r14)
incq %r12
movq 0x10(%rbx), %rax
cmpq (%rax,%r15), %r12
jb 0x14bf03
jmp 0x14bf86
callq 0x1d34b
jmp 0x14bf5d
incq %r13
cmpq (%rbx), %r13
jb 0x14bee2
cmpq $0x0, (%rbx)
movq 0x18(%rsp), %rcx
movq 0x8(%rsp), %rdi
je 0x14c041
xorl %eax, %eax
xorl %r15d, %r15d
movq 0x10(%rbx), %r9
leaq (%r15,%r15,2), %rdx
shlq $0x4, %rdx
cmpq $0x0, (%r9,%rdx)
je 0x14c02d
xorl %r12d, %r12d
xorl %esi, %esi
xorl %r8d, %r8d
movq 0x10(%r9,%rdx), %r9
cmpb $0x0, 0x18(%r9,%r12)
js 0x14c017
leaq (%r9,%r12), %r10
leaq (,%rsi,8), %r11
leaq (%r11,%r11,4), %r11
movq 0x20(%r10), %r14
movq %r14, 0x20(%r9,%r11)
movupd (%r10), %xmm0
movups 0x10(%r10), %xmm1
movups %xmm1, 0x10(%r9,%r11)
movupd %xmm0, (%r9,%r11)
movq 0x10(%rbx), %r9
movq 0x10(%r9,%rdx), %r9
movq %rax, (%r9,%r11)
movq %rax, 0x20(%r9,%r11)
incq %rsi
incq %r8
movq 0x10(%rbx), %r9
addq $0x28, %r12
cmpq (%r9,%rdx), %r8
jb 0x14bfc6
addq %rdx, %r9
jmp 0x14c032
addq %rdx, %r9
xorl %esi, %esi
movq %rsi, (%r9)
incq %r15
cmpq (%rbx), %r15
jb 0x14bfab
xorl %eax, %eax
cmpb $0x0, 0x4(%rsp)
leaq 0x20(%rsp), %r8
cmoveq %rax, %r8
movq 0x10(%rsp), %rsi
movq %rbx, %rdx
callq 0x14423c
cmpq $0x0, (%rbx)
je 0x14c0ec
xorl %eax, %eax
xorpd %xmm0, %xmm0
movq 0x10(%rbx), %rdx
leaq (%rax,%rax,2), %rcx
shlq $0x4, %rcx
cmpq $0x0, (%rdx,%rcx)
je 0x14c0e4
xorl %esi, %esi
movq 0x10(%rdx,%rcx), %r8
leaq (%rsi,%rsi,4), %rdi
cmpb $0x0, 0x18(%r8,%rdi,8)
js 0x14c0d7
leaq (%r8,%rdi,8), %r8
ucomisd (%r8), %xmm0
jb 0x14c0d7
movl 0x8(%r8), %r8d
leaq (%r8,%r8,2), %r8
shlq $0x4, %r8
movq 0x10(%rdx,%r8), %r8
addq $0x18, %r8
cmpb $0x0, (%r8)
js 0x14c0c3
movl -0x10(%r8), %r9d
cmpq %r9, %rax
je 0x14c0c9
addq $0x28, %r8
jmp 0x14c0b4
movq 0x10(%rdx,%rcx), %rdx
orb $-0x80, 0x18(%rdx,%rdi,8)
orb $-0x80, (%r8)
incq %rsi
movq 0x10(%rbx), %rdx
cmpq (%rdx,%rcx), %rsi
jb 0x14c083
incq %rax
cmpq (%rbx), %rax
jb 0x14c06e
cmpq $0x0, (%rbx)
je 0x14c16a
xorl %eax, %eax
movq 0x10(%rbx), %rsi
leaq (%rax,%rax,2), %rcx
shlq $0x4, %rcx
cmpq $0x0, (%rsi,%rcx)
je 0x14c15a
xorl %edi, %edi
xorl %edx, %edx
xorl %r8d, %r8d
movq 0x10(%rsi,%rcx), %rsi
cmpb $0x0, 0x18(%rsi,%rdi)
js 0x14c144
leaq (%rsi,%rdi), %r9
leaq (%rdx,%rdx,4), %r10
movq 0x20(%r9), %r11
movq %r11, 0x20(%rsi,%r10,8)
movupd (%r9), %xmm0
movups 0x10(%r9), %xmm1
movups %xmm1, 0x10(%rsi,%r10,8)
movupd %xmm0, (%rsi,%r10,8)
incq %rdx
incq %r8
movq 0x10(%rbx), %rsi
addq $0x28, %rdi
cmpq (%rsi,%rcx), %r8
jb 0x14c10e
addq %rcx, %rsi
jmp 0x14c15f
addq %rcx, %rsi
xorl %edx, %edx
movq %rdx, (%rsi)
incq %rax
cmpq (%rbx), %rax
jb 0x14c0f4
movq 0x20(%rsp), %rdi
callq 0x2220
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq