// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: purge_phase(ha_ug_index*, mmhap_t*, unsigned long, unsigned long, hc_links*, kvec_pe_hit*, bubble_type*, ps_t*, kv_u_trans_t*, unsigned char*, unsigned int*, kv_u_trans_t*, asg64_v*)
void purge_phase(ha_ug_index* idx, mmhap_t *hh, uint64_t hapid, uint64_t max_round, hc_links *link, kvec_pe_hit* hits,
bubble_type *bub, ps_t *s, kv_u_trans_t *k_trans, uint8_t *del, uint32_t *bidx, kv_u_trans_t *ref, asg64_v *srt)
{
    uint64_t k, len; uint32_t *bm;
    ma_ug_t *ug = idx->ug;
    if(max_round <= 0) {
        for (k = 0; k < ug->g->n_seq; k++) {
            if(hh->h.a[k].n >= hh->h.a[k].m) continue;
            hh->a.a[hh->h.a[k].a+hh->h.a[k].n] = hapid;
            hh->h.a[k].n++;
        }
        return;
    }

    for (k = 0; k < ug->g->n_seq; k++) {
        del[k] = 0; s->s[k] = 0;
        if(hh->h.a[k].n >= hh->h.a[k].m) {///all haplotypes have been set
            bub->index[k] = (uint32_t)-1; del[k] = 1;
        } else {
            if(IF_HOM(k, (*bub))) bub->index[k] = bub->num.n;
        }
        bidx[k] = bub->index[k];
    }
    bm = bub->index; bub->index = bidx; bidx = bm;

    kv_resize(u_trans_t, *ref, idx->t_ch->k_trans.n); ref->n = idx->t_ch->k_trans.n;
    memcpy(ref->a, idx->t_ch->k_trans.a, ref->n*sizeof((*(ref->a))));
    kv_resize(uint64_t, ref->idx, idx->t_ch->k_trans.idx.n); ref->idx.n = idx->t_ch->k_trans.idx.n;
    memcpy(ref->idx.a, idx->t_ch->k_trans.idx.a, ref->idx.n*sizeof((*(ref->idx.a))));
    exchange_kv_u_trans_t(ref, &(idx->t_ch->k_trans));

    for (k = 0; k < max_round; k++) {
        clean_trans_ovlp(bub, &(idx->t_ch->k_trans), ref, ((k+1)<max_round)?srt:NULL, ug);
        purge_phase_0(idx, link, bub, s, hits, k_trans, del, hh);
    }

    for (k = len = 0; k < ug->g->n_seq; k++) {
        if(del[k] != 2) {
            if((hh->h.a[k].n == hh->h.a[k].m) && (hh->h.a[k].m == ((uint64_t)asm_opt.polyploidy))) {
                len += ug->g->seq[k].len;
            }
            continue;
        }
        assert(hh->h.a[k].n < hh->h.a[k].m);
        hh->a.a[hh->h.a[k].a+hh->h.a[k].n] = hapid;
        hh->h.a[k].n++; len += ug->g->seq[k].len;
    }
    fprintf(stderr, "[M::%s::stat] # hap%lu bases: %lu\n", __func__, hapid+1, len);
    
    bm = bub->index; bub->index = bidx; bidx = bm;
    exchange_kv_u_trans_t(ref, &(idx->t_ch->k_trans));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %r15
movq (%rdi), %rdi
testq %rcx, %rcx
jne 0x11dd98
movq 0x18(%rdi), %rax
xorl %ecx, %ecx
xorl %r9d, %r9d
movl 0x14(%rax), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
cmpq %rsi, %r9
jae 0x11dd89
movq 0x10(%r14), %rsi
movl (%rsi,%rcx), %edi
cmpl 0x4(%rsi,%rcx), %edi
jae 0x11dd80
movq 0x28(%r14), %r8
addl 0x8(%rsi,%rcx), %edi
movl %edx, (%r8,%rdi,4)
incl (%rsi,%rcx)
incq %r9
addq $0xc, %rcx
jmp 0x11dd56
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r8, %rbp
movq %rcx, 0x8(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xb8(%rsp), %rbx
movq 0xb0(%rsp), %rax
movq 0xa8(%rsp), %r12
movq 0xa0(%rsp), %rcx
movq %rcx, 0x38(%rsp)
movq 0x98(%rsp), %rcx
movq %rcx, 0x18(%rsp)
movq 0x90(%rsp), %r13
pushq $0x1
popq %rcx
xorl %r10d, %r10d
xorl %esi, %esi
movq %rdi, 0x20(%rsp)
movq 0x18(%rdi), %rdi
movl 0x14(%rdi), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
cmpq %rdi, %rsi
jae 0x11de69
movb %r10b, (%r12,%rsi)
movq 0x18(%rsp), %rdi
movq (%rdi), %rdi
movb %r10b, (%rdi,%rsi)
movq 0x10(%r14), %r8
movl -0x4(%r8,%rcx,4), %r11d
movq (%r13), %rdi
cmpl (%r8,%rcx,4), %r11d
jae 0x11de46
movl (%rdi,%rsi,4), %r8d
movq 0x80(%r13), %r11
incq %r11
cmpq %r8, %r11
jae 0x11de57
movl 0x30(%r13), %r8d
movl %r8d, (%rdi,%rsi,4)
jmp 0x11de57
orl $-0x1, (%rdi,%rsi,4)
movb $0x1, (%r12,%rsi)
movq (%r13), %rdi
movl (%rdi,%rsi,4), %r8d
movl %r8d, (%rax,%rsi,4)
incq %rsi
addq $0x3, %rcx
movq 0x20(%rsp), %rdi
jmp 0x11ddf4
movq (%r13), %rsi
movq %rax, (%r13)
movq 0x10(%r15), %rcx
movq 0x138(%rcx), %rax
cmpq %rax, 0x8(%rbx)
movq %rdx, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %r9, 0x50(%rsp)
jae 0x11deed
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
incq %rcx
movq %rcx, 0x8(%rbx)
movq 0x10(%rbx), %rdi
imulq $0x30, %rcx, %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x10(%rbx)
movq 0x10(%r15), %rcx
movq 0x138(%rcx), %rax
jmp 0x11def1
movq 0x10(%rbx), %rdi
movq %rax, (%rbx)
movq 0x148(%rcx), %rsi
imulq $0x30, %rax, %rdx
callq 0x2160
movq 0x10(%r15), %rax
movq 0x150(%rax), %rdx
cmpq %rdx, 0x20(%rbx)
movq %r12, 0x10(%rsp)
movq %rbp, 0x48(%rsp)
jae 0x11df80
decq %rdx
movq %rdx, %rax
shrq %rax
orq %rdx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x20(%rbx)
movq 0x28(%rbx), %rdi
leaq 0x8(,%rax,8), %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, 0x28(%rbx)
movq 0x10(%r15), %rax
movq 0x150(%rax), %rdx
jmp 0x11df84
movq 0x28(%rbx), %rdi
movq %rdx, 0x18(%rbx)
movq 0x160(%rax), %rsi
shlq $0x3, %rdx
callq 0x2160
movl $0x138, %eax            # imm = 0x138
movq %r15, %r12
movq 0x10(%r15), %rsi
addq %rax, %rsi
movq %rbx, (%rsp)
movq %rbx, %rdi
callq 0x11d8a0
movq 0x8(%rsp), %r15
negq %r15
pushq $0x1
popq %rbp
leaq (%r15,%rbp), %rax
cmpq $0x1, %rax
movq 0x20(%rsp), %r8
je 0x11e024
movq 0x10(%r12), %rsi
movl $0x138, %eax            # imm = 0x138
addq %rax, %rsi
cmpq 0x8(%rsp), %rbp
movl $0x0, %ecx
cmovbq 0x40(%rsp), %rcx
movq %r13, %rdi
movq (%rsp), %rdx
callq 0x11d994
movq %r12, %rdi
movq 0x48(%rsp), %rsi
movq %r13, %rdx
movq 0x18(%rsp), %rcx
movq 0x50(%rsp), %r8
movq 0x38(%rsp), %r9
pushq %r14
pushq 0x18(%rsp)
callq 0x11d665
addq $0x10, %rsp
incq %rbp
jmp 0x11dfbe
movq 0x18(%r8), %rax
xorl %r11d, %r11d
leaq 0x135726(%rip), %rdx    # 0x253758
xorl %esi, %esi
xorl %r8d, %r8d
movq 0x30(%rsp), %rcx
movq 0x10(%rsp), %r15
movl 0x14(%rax), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
cmpq %rdi, %rsi
jae 0x11e0a9
cmpb $0x2, (%r15,%rsi)
movq 0x10(%r14), %r9
movl (%r9,%r11), %edi
movl 0x4(%r9,%r11), %r10d
jne 0x11e07f
cmpl %r10d, %edi
jae 0x11e0f5
movq 0x28(%r14), %r10
addl 0x8(%r9,%r11), %edi
movl %ecx, (%r10,%rdi,4)
incl (%r9,%r11)
jmp 0x11e090
cmpl %r10d, %edi
jne 0x11e0a0
movslq 0x1bc(%rdx), %rdi
cmpq %rdi, %r10
jne 0x11e0a0
movq 0x20(%rax), %rdi
movl (%rdi,%rsi,8), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
addq %rdi, %r8
incq %rsi
addq $0xc, %r11
jmp 0x11e041
movq 0x134f30(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
incq %rcx
leaq 0xd097a(%rip), %rsi     # 0x1eea37
leaq 0xd0996(%rip), %rdx     # 0x1eea5a
xorl %eax, %eax
callq 0x22b0
movq 0x28(%rsp), %rax
movq %rax, (%r13)
movl $0x138, %esi            # imm = 0x138
addq 0x10(%r12), %rsi
movq (%rsp), %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x11d8a0
leaq 0xd0864(%rip), %rdi     # 0x1ee960
leaq 0xd0879(%rip), %rsi     # 0x1ee97c
leaq 0xd087a(%rip), %rcx     # 0x1ee984
movl $0x44ef, %edx           # imm = 0x44EF
callq 0x2110