// File: 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
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jbe 0x1eb378
cmpl $0x0, -0x2c(%rbp)
jne 0x1eb378
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
leaq -0x78(%rbp), %rax
movq $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x1ea4b0
cltq
movq %rax, -0x50(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1eb4c3
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1eb4b0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x1eb3e9
jmp 0x1eb49f
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
cmpq $-0x1, 0x10(%rax)
jne 0x1eb49d
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, %esi
movq -0x40(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1d09c0
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x1eb465
movq 0x1d8b8c(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x19e651(%rip), %rsi    # 0x389aaf
movb $0x0, %al
callq 0x22a0
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movb 0x18(%rax), %cl
andb $0x7f, %cl
orb $-0x80, %cl
movb %cl, 0x18(%rax)
movq -0x80(%rbp), %rax
movb 0x18(%rax), %cl
andb $0x7f, %cl
orb $-0x80, %cl
movb %cl, 0x18(%rax)
jmp 0x1eb49f
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1eb3a1
jmp 0x1eb4b2
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1eb388
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1eb602
movq $0x0, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1eb5da
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x1eb534
jmp 0x1eb5c9
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rsi
imulq $0x28, -0x38(%rbp), %rax
addq %rax, %rsi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
imulq $0x28, -0x48(%rbp), %rax
addq %rax, %rdi
movl $0x28, %edx
callq 0x2180
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x48(%rbp), %rcx
addq %rcx, %rax
movq $0x0, 0x20(%rax)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1eb4ec
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1eb4cb
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x88(%rbp)
cmpq $0x1, -0x50(%rbp)
jne 0x1eb642
leaq -0x78(%rbp), %rax
movq %rax, -0xa8(%rbp)
jmp 0x1eb64d
xorl %eax, %eax
movq %rax, -0xa8(%rbp)
jmp 0x1eb64d
movq -0x88(%rbp), %rcx
movq -0x90(%rbp), %rdx
movq -0x98(%rbp), %rsi
movq -0xa0(%rbp), %rdi
movq -0xa8(%rbp), %r8
callq 0x1dc0b0
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1eb797
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1eb784
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x1eb6de
jmp 0x1eb773
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
ucomisd (%rax), %xmm0
jb 0x1eb771
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, %esi
movq -0x40(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x1d09c0
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movb 0x18(%rax), %cl
andb $0x7f, %cl
orb $-0x80, %cl
movb %cl, 0x18(%rax)
movq -0x80(%rbp), %rax
movb 0x18(%rax), %cl
andb $0x7f, %cl
orb $-0x80, %cl
movb %cl, 0x18(%rax)
jmp 0x1eb773
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1eb696
jmp 0x1eb786
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1eb67d
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x1eb88c
movq $0x0, -0x48(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jae 0x1eb864
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movb 0x18(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
je 0x1eb805
jmp 0x1eb853
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rsi
imulq $0x28, -0x38(%rbp), %rax
addq %rax, %rsi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
imulq $0x28, -0x48(%rbp), %rax
addq %rax, %rdi
movl $0x28, %edx
callq 0x2180
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1eb7c0
movq -0x48(%rbp), %rcx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
imulq $0x30, -0x40(%rbp), %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1eb79f
movq -0x78(%rbp), %rdi
callq 0x2210
addq $0xc0, %rsp
popq %rbp
retq
nop