// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %rdx, %rbx
movq %rsi, 0x30(%rsp)
movq %rdi, 0x28(%rsp)
andq $0x0, 0x50(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movl $0x0, 0x24(%rsp)
testl %r9d, %r9d
movq %rcx, 0x38(%rsp)
jne 0x10b1e7
cmpl $0x0, 0x8(%rcx)
je 0x10b1e7
andq $0x0, (%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %rbx, %rdx
movq 0x38(%rsp), %rcx
xorl %r9d, %r9d
callq 0x10aa3d
movl %eax, 0x24(%rsp)
xorl %edx, %edx
movq (%rbx), %rcx
cmpq %rcx, %rdx
jae 0x10b284
imulq $0x30, %rdx, %r12
pushq $0x18
popq %r15
xorl %ebp, %ebp
movq %rdx, 0x18(%rsp)
movq 0x10(%rbx), %r13
cmpq (%r13,%r12), %rbp
jae 0x10b27c
leaq (%r12,%r13), %rax
movq 0x10(%rax), %rax
cmpb $0x0, (%rax,%r15)
js 0x10b251
cmpq $-0x1, -0x8(%rax,%r15)
jne 0x10b251
movl -0x10(%rax,%r15), %esi
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0xfcabc
movq %rax, %r14
testq %rax, %rax
je 0x10b25a
movq 0x10(%r13,%r12), %rax
orb $-0x80, (%rax,%r15)
orb $-0x80, 0x18(%r14)
movq 0x18(%rsp), %rdx
incq %rbp
addq $0x28, %r15
jmp 0x10b204
movq 0x147d7f(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0xdfb19(%rip), %rdi     # 0x1ead84
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x10(%rbx), %r13
jmp 0x10b23d
incq %rdx
jmp 0x10b1e9
xorl %eax, %eax
cmpq %rcx, %rax
jae 0x10b301
movq 0x10(%rbx), %r8
imulq $0x30, %rax, %rcx
xorl %edx, %edx
xorl %edi, %edi
xorl %esi, %esi
leaq (%r8,%rcx), %r9
cmpq (%r8,%rcx), %rdi
jae 0x10b2f6
movq 0x10(%r9), %r9
cmpb $0x0, 0x18(%r9,%rdx)
js 0x10b2ed
leaq (%r9,%rdx), %r8
imulq $0x28, %rsi, %r10
movq 0x20(%r8), %r11
movq %r11, 0x20(%r9,%r10)
movupd (%r8), %xmm0
movups 0x10(%r8), %xmm1
movups %xmm1, 0x10(%r9,%r10)
movupd %xmm0, (%r9,%r10)
movq 0x10(%rbx), %r8
movq 0x10(%r8,%rcx), %r9
andq $0x0, (%r9,%r10)
andq $0x0, 0x20(%r9,%r10)
incq %rsi
incq %rdi
addq $0x28, %rdx
jmp 0x10b299
movq %rsi, (%r9)
incq %rax
movq (%rbx), %rcx
jmp 0x10b286
xorl %eax, %eax
cmpb $0x0, 0x24(%rsp)
leaq 0x40(%rsp), %r8
cmoveq %rax, %r8
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq %rbx, 0x18(%rsp)
movq %rbx, %rdx
movq 0x38(%rsp), %rcx
callq 0x102bed
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
movq 0x18(%rsp), %rax
movq (%rax), %rcx
cmpq %rcx, %rbx
jae 0x10b3a4
imulq $0x30, %rbx, %r12
pushq $0x18
popq %r13
xorl %ebp, %ebp
movq 0x18(%rsp), %rax
movq 0x10(%rax), %rax
cmpq (%rax,%r12), %rbp
jae 0x10b39f
addq %r12, %rax
movq 0x10(%rax), %r14
movb (%r14,%r13), %r15b
testb %r15b, %r15b
js 0x10b396
ucomisd -0x18(%r14,%r13), %xmm0
jb 0x10b396
movl -0x10(%r14,%r13), %esi
movq 0x18(%rsp), %rdi
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0xfcabc
xorpd %xmm0, %xmm0
orb $-0x80, %r15b
movb %r15b, (%r14,%r13)
orb $-0x80, 0x18(%rax)
incq %rbp
addq $0x28, %r13
jmp 0x10b34a
incq %rbx
jmp 0x10b333
xorl %eax, %eax
movq 0x18(%rsp), %rbx
cmpq %rcx, %rax
jae 0x10b412
imulq $0x30, %rax, %rcx
xorl %edx, %edx
xorl %edi, %edi
xorl %esi, %esi
movq 0x10(%rbx), %r9
leaq (%r9,%rcx), %r8
cmpq (%r9,%rcx), %rdi
jae 0x10b407
movq 0x10(%r8), %r8
cmpb $0x0, 0x18(%r8,%rdx)
js 0x10b3fe
leaq (%r8,%rdx), %r9
imulq $0x28, %rsi, %r10
movq 0x20(%r9), %r11
movq %r11, 0x20(%r8,%r10)
movupd (%r9), %xmm0
movups 0x10(%r9), %xmm1
movups %xmm1, 0x10(%r8,%r10)
movupd %xmm0, (%r8,%r10)
incq %rsi
incq %rdi
addq $0x28, %rdx
jmp 0x10b3ba
movq %rsi, (%r8)
incq %rax
movq (%rbx), %rcx
jmp 0x10b3ab
movq 0x40(%rsp), %rdi
callq 0x2220
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq