// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
xorl %eax, %eax
testl %r9d, %r9d
jne 0x152512
cmpl $0x0, 0x8(%r14)
je 0x152512
leaq 0x30(%rsp), %rax
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r13, %rdx
movq %r14, %rcx
xorl %r9d, %r9d
pushq %rax
pushq $0x0
callq 0x151cae
addq $0x10, %rsp
movl %eax, 0xc(%rsp)
movq (%r13), %rcx
testq %rcx, %rcx
je 0x152679
movq %r14, 0x28(%rsp)
movq 0x10(%r13), %rax
xorl %edx, %edx
leaq (%rdx,%rdx,2), %r14
shlq $0x4, %r14
cmpq $0x0, (%rax,%r14)
je 0x1525c6
movl $0x18, %ebp
xorl %r15d, %r15d
movq %rdx, (%rsp)
movq 0x10(%rax,%r14), %rbx
cmpb $0x0, (%rbx,%rbp)
js 0x152588
cmpq $-0x1, -0x8(%rbx,%rbp)
jne 0x152588
movl -0x10(%rbx,%rbp), %esi
movq %r13, %rdi
xorl %ecx, %ecx
callq 0x144201
movq %rax, %r12
testq %rax, %rax
je 0x152597
orb $-0x80, (%rbx,%rbp)
orb $-0x80, 0x18(%r12)
movq 0x10(%r13), %rax
movq (%rsp), %rdx
incq %r15
addq $0x28, %rbp
cmpq (%rax,%r14), %r15
jb 0x15254d
jmp 0x1525c2
movq 0x142a42(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0x6, %esi
movl $0x1, %edx
leaq 0xe68d2(%rip), %rdi     # 0x238e84
callq 0x2410
movq 0x10(%r13), %rax
movq 0x10(%rax,%r14), %rbx
jmp 0x152576
movq (%r13), %rcx
incq %rdx
cmpq %rcx, %rdx
jb 0x15252e
testq %rcx, %rcx
movq 0x28(%rsp), %r14
je 0x152679
movq 0x10(%r13), %rsi
xorl %eax, %eax
xorl %edx, %edx
leaq (%rdx,%rdx,2), %rdi
shlq $0x4, %rdi
cmpq $0x0, (%rsi,%rdi)
je 0x152664
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
movq 0x10(%rsi,%rdi), %r10
cmpb $0x0, 0x18(%r10,%rcx)
js 0x15264e
leaq (%r10,%rcx), %rsi
leaq (,%r8,8), %r11
leaq (%r11,%r11,4), %r11
movq 0x20(%rsi), %rbx
movq %rbx, 0x20(%r10,%r11)
movupd (%rsi), %xmm0
movups 0x10(%rsi), %xmm1
movups %xmm1, 0x10(%r10,%r11)
movupd %xmm0, (%r10,%r11)
movq 0x10(%r13), %rsi
movq 0x10(%rsi,%rdi), %r10
movq %rax, (%r10,%r11)
movq %rax, 0x20(%r10,%r11)
incq %r8
incq %r9
addq $0x28, %rcx
cmpq (%rsi,%rdi), %r9
jb 0x1525ff
addq %rsi, %rdi
movq (%r13), %rcx
jmp 0x15266a
addq %rsi, %rdi
xorl %r8d, %r8d
movq %r8, (%rdi)
incq %rdx
cmpq %rcx, %rdx
jb 0x1525e8
xorl %eax, %eax
cmpb $0x0, 0xc(%rsp)
leaq 0x30(%rsp), %r8
cmoveq %rax, %r8
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x14a8a4
movq (%r13), %rcx
testq %rcx, %rcx
je 0x1527bb
movq 0x10(%r13), %rax
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movq %r13, 0x20(%rsp)
movq 0x20(%rsp), %r14
leaq (%r15,%r15,2), %rdx
shlq $0x4, %rdx
cmpq $0x0, (%rax,%rdx)
je 0x152733
movl $0x18, %r12d
xorl %r13d, %r13d
movq %rdx, (%rsp)
movq 0x10(%rax,%rdx), %rbx
movb (%rbx,%r12), %bpl
testb %bpl, %bpl
js 0x15271d
ucomisd -0x18(%rbx,%r12), %xmm0
jb 0x15271d
movl -0x10(%rbx,%r12), %esi
movq %r14, %rdi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x144201
movq (%rsp), %rdx
xorpd %xmm0, %xmm0
orb $-0x80, %bpl
movb %bpl, (%rbx,%r12)
orb $-0x80, 0x18(%rax)
movq 0x10(%r14), %rax
incq %r13
addq $0x28, %r12
cmpq (%rax,%rdx), %r13
jb 0x1526dc
movq 0x20(%rsp), %r13
movq (%r13), %rcx
incq %r15
cmpq %rcx, %r15
jb 0x1526c0
testq %rcx, %rcx
je 0x1527bb
movq 0x10(%r13), %rdx
xorl %eax, %eax
leaq (%rax,%rax,2), %rsi
shlq $0x4, %rsi
cmpq $0x0, (%rdx,%rsi)
je 0x1527ab
xorl %ecx, %ecx
xorl %edi, %edi
xorl %r8d, %r8d
movq 0x10(%rdx,%rsi), %r9
cmpb $0x0, 0x18(%r9,%rcx)
js 0x152795
leaq (%r9,%rcx), %rdx
leaq (%rdi,%rdi,4), %r10
movq 0x20(%rdx), %r11
movq %r11, 0x20(%r9,%r10,8)
movupd (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups %xmm1, 0x10(%r9,%r10,8)
movupd %xmm0, (%r9,%r10,8)
incq %rdi
movq 0x10(%r13), %rdx
incq %r8
addq $0x28, %rcx
cmpq (%rdx,%rsi), %r8
jb 0x15275c
addq %rdx, %rsi
movq (%r13), %rcx
jmp 0x1527b0
addq %rdx, %rsi
xorl %edi, %edi
movq %rdi, (%rsi)
incq %rax
cmpq %rcx, %rax
jb 0x152746
movq 0x30(%rsp), %rdi
callq 0x2220
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq