// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: init_contig_H_partition(bubble_type*, ha_ug_index*, H_partition*)
void init_contig_H_partition(bubble_type* bub, ha_ug_index* idx, H_partition* hap)
{
    uint32_t i, k_i, k_j, uID, *a = NULL, n, *h0, h0_n, *h1, h1_n;
    destory_G_partition(&(hap->group_g_p)); memset(&(hap->group_g_p), 0, sizeof(G_partition));
    init_G_partition(&(hap->group_g_p), hap->n);
    partition_warp *res = NULL;
    ma_utg_t *u_x = NULL;
    chain_hic_warp *c_w = &(bub->c_w);

    for (i = 0; i < bub->c_w.n; i++)
    {
        kv_pushp(partition_warp, hap->group_g_p, &res);
        kv_init(res->a);
        res->full_bub = 0;
        res->h[0] = res->h[1] = 0;

        res->status[0] = 1; res->status[1] = -1;
        res->weight[0] = res->weight[1] = res->weight_convex = 0;


        u_x = (*c_w).a[(*c_w).a[i].id].u;
        for (k_i = 0; k_i < u_x->n; k_i++)
        {
            get_bubbles(bub, u_x->a[k_i]>>33, NULL, NULL, &a, &n, NULL);
            for (k_j = 0; k_j < n; k_j++)
            {
                uID = a[k_j]>>1;
                if((*c_w).chain_idx[uID] != (*c_w).a[i].id) continue;
                if(get_phase_status(hap, uID)==1)
                {
                    kv_push(uint32_t, res->a, uID);
                    res->h[0]++;
                }
            }
        }

        for (k_i = 0; k_i < u_x->n; k_i++)
        {
            get_bubbles(bub, u_x->a[k_i]>>33, NULL, NULL, &a, &n, NULL);
            for (k_j = 0; k_j < n; k_j++)
            {
                uID = a[k_j]>>1;
                if((*c_w).chain_idx[uID] != (*c_w).a[i].id) continue;
                if(get_phase_status(hap, uID)==-1)
                {
                    kv_push(uint32_t, res->a, uID);
                    res->h[1]++;
                }
            }
        }


        for (k_i = 0; k_i < res->h[0]; k_i++)
        {
            ///if(hap->group_g_p.index[res->a.a[k_i]] != (uint32_t)-1) fprintf(stderr, "ERROR---00\n");
            hap->group_g_p.index[res->a.a[k_i]] = hap->group_g_p.n-1;
            hap->group_g_p.index[res->a.a[k_i]] = hap->group_g_p.index[res->a.a[k_i]] << 1;
        } 

        for (; k_i < res->a.n; k_i++)
        {
            ///if(hap->group_g_p.index[res->a.a[k_i]] != (uint32_t)-1) fprintf(stderr, "ERROR---11\n");
            hap->group_g_p.index[res->a.a[k_i]] = hap->group_g_p.n-1;
            hap->group_g_p.index[res->a.a[k_i]] = (hap->group_g_p.index[res->a.a[k_i]] << 1) + 1;
        }

        get_phased_block(&(hap->group_g_p), NULL, i, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
        if(h0_n >0) res->weight[0] = get_cluster_weight(hap, hap->link, h0, h0_n); 
        if(h1_n >0) res->weight[1] = get_cluster_weight(hap, hap->link, h1, h1_n); 
        res->weight_convex = get_cluster_inner_weight(hap, hap->link, h0, h0_n, h1, h1_n);
    }

    flip_by_node(hap, &(hap->group_g_p), bub);
    label_unitigs(&(hap->group_g_p), idx->ug);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r14
movq %rsi, 0x38(%rsp)
movq %rdi, %r12
leaq 0x58(%rdx), %rbx
movq %rbx, %rdi
callq 0x10191d
xorps %xmm0, %xmm0
movups %xmm0, 0x68(%r14)
movups %xmm0, 0x58(%r14)
movq (%r14), %rsi
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
callq 0x1018c5
xorl %ebx, %ebx
movq %r14, 0x8(%rsp)
movl %ebx, %ebx
cmpq %rbx, 0xe0(%r12)
jbe 0x1170ca
movq 0x58(%r14), %rcx
movq 0x68(%r14), %rax
cmpq 0x60(%r14), %rcx
jne 0x116d85
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x60(%r14)
imulq $0x48, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x68(%r14)
movq 0x58(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq 0x20(%rsp), %rsi
movq %rdx, (%rsi)
imulq $0x48, %rcx, %rcx
leaq (%rax,%rcx), %rsi
addq $0x30, %rsi
xorps %xmm0, %xmm0
movups %xmm0, -0x20(%rsi)
movups %xmm0, -0x30(%rsi)
movb $0x0, -0x10(%rsi)
movabsq $-0xffffffff, %rdx      # imm = 0xFFFFFFFF00000001
movq %rdx, -0xc(%rsi)
andq $0x0, 0x10(%rsi)
addq %rcx, %rax
movq %rax, (%rsp)
movq %rsi, 0x40(%rsp)
movups %xmm0, (%rsi)
movq 0xf0(%r12), %rax
movq %rbx, 0x28(%rsp)
imulq $0x28, %rbx, %rbp
movl 0x8(%rax,%rbp), %ecx
imulq $0x28, %rcx, %rcx
movq 0x10(%rax,%rcx), %rcx
xorl %edx, %edx
movq %rbp, 0x10(%rsp)
movq %rcx, 0x30(%rsp)
movl 0x10(%rcx), %eax
cmpq %rax, %rdx
jae 0x116ed8
movq 0x18(%rcx), %rax
movq %rdx, 0x18(%rsp)
movq (%rax,%rdx,8), %rax
movq 0x28(%r12), %rcx
movq 0x40(%r12), %rdx
shrq $0x21, %rax
movl (%rdx,%rax,4), %esi
movl 0x4(%rdx,%rax,4), %ebx
leaq (%rcx,%rsi,4), %r15
addq $0x8, %r15
subl %esi, %ebx
addl $-0x2, %ebx
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x116ec6
movl (%r15,%r14,4), %r13d
shrl %r13d
movq 0xf0(%r12), %rax
movq 0x100(%r12), %rcx
movl (%rcx,%r13,4), %ecx
cmpl 0x8(%rax,%rbp), %ecx
jne 0x116ebe
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x121555
cmpl $0x1, %eax
jne 0x116ebe
movq (%rsp), %rbp
movq (%rbp), %rcx
movq 0x10(%rbp), %rax
cmpq 0x8(%rbp), %rcx
jne 0x116eaa
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbp)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbp)
movq (%rbp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbp)
movl %r13d, (%rax,%rcx,4)
incl 0x18(%rbp)
movq 0x10(%rsp), %rbp
incq %r14
jmp 0x116e36
movq 0x18(%rsp), %rdx
incq %rdx
movq 0x30(%rsp), %rcx
jmp 0x116df8
xorl %edx, %edx
movl %eax, %eax
cmpq %rax, %rdx
jae 0x116fbc
movq 0x18(%rcx), %rax
movq %rdx, 0x18(%rsp)
movq (%rax,%rdx,8), %rax
movq 0x28(%r12), %rcx
movq 0x40(%r12), %rdx
shrq $0x21, %rax
movl (%rdx,%rax,4), %esi
movl 0x4(%rdx,%rax,4), %ebx
leaq (%rcx,%rsi,4), %r15
addq $0x8, %r15
subl %esi, %ebx
addl $-0x2, %ebx
xorl %r14d, %r14d
cmpq %r14, %rbx
je 0x116fa7
movl (%r15,%r14,4), %r13d
shrl %r13d
movq 0xf0(%r12), %rax
movq 0x100(%r12), %rcx
movl (%rcx,%r13,4), %ecx
cmpl 0x8(%rax,%rbp), %ecx
jne 0x116f9f
movq 0x8(%rsp), %rdi
movl %r13d, %esi
callq 0x121555
cmpl $-0x1, %eax
jne 0x116f9f
movq (%rsp), %rbp
movq (%rbp), %rcx
movq 0x10(%rbp), %rax
cmpq 0x8(%rbp), %rcx
jne 0x116f8b
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbp)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbp)
movq (%rbp), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbp)
movl %r13d, (%rax,%rcx,4)
incl 0x1c(%rbp)
movq 0x10(%rsp), %rbp
incq %r14
jmp 0x116f17
movq 0x18(%rsp), %rdx
incq %rdx
movq 0x30(%rsp), %rcx
movl 0x10(%rcx), %eax
jmp 0x116eda
xorl %eax, %eax
movq 0x8(%rsp), %rbx
movq (%rsp), %r9
movl 0x18(%r9), %ecx
cmpq %rcx, %rax
jae 0x116fee
movl 0x58(%rbx), %ecx
decl %ecx
movq 0x70(%rbx), %rdx
movq 0x10(%r9), %rsi
movl (%rsi,%rax,4), %edi
movl %ecx, (%rdx,%rdi,4)
movl (%rsi,%rax,4), %ecx
shll (%rdx,%rcx,4)
incq %rax
jmp 0x116fc7
movq (%r9), %rcx
movl %eax, %eax
cmpq %rax, %rcx
jbe 0x117021
movl 0x58(%rbx), %edx
decl %edx
movq 0x70(%rbx), %rsi
movq 0x10(%r9), %rdi
movl (%rdi,%rax,4), %r8d
movl %edx, (%rsi,%r8,4)
movl (%rdi,%rax,4), %edx
movl (%rsi,%rdx,4), %edi
leal 0x1(,%rdi,2), %edi
movl %edi, (%rsi,%rdx,4)
incl %eax
jmp 0x116ff1
movq 0x30(%rbx), %rsi
movq 0x68(%rbx), %rax
imulq $0x48, 0x28(%rsp), %rcx
movq 0x10(%rax,%rcx), %rdx
movl 0x18(%rax,%rcx), %r13d
leaq (%rdx,%r13,4), %r14
movl 0x1c(%rax,%rcx), %ebp
testl %ebp, %ebp
movl $0x0, %r15d
cmovneq %r14, %r15
movq %r13, %rax
testq %r13, %r13
cmovneq %rdx, %rax
movq %rax, 0x10(%rsp)
je 0x117076
movq %rbx, %rdi
movl %r13d, %ecx
callq 0x10c812
movq 0x40(%rsp), %rax
movsd %xmm0, (%rax)
movq 0x30(%rbx), %rsi
testl %ebp, %ebp
je 0x11709c
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rdx
movl %ebp, %ecx
callq 0x10c812
movq (%rsp), %r14
movsd %xmm0, 0x38(%r14)
movq 0x30(%rbx), %rsi
jmp 0x1170a0
movq (%rsp), %r14
movq 0x10(%rsp), %rdx
movl %r13d, %ecx
movq %r15, %r8
movl %ebp, %r9d
callq 0x10c8e2
movsd %xmm0, 0x40(%r14)
movq 0x28(%rsp), %rbx
incl %ebx
movq 0x8(%rsp), %r14
jmp 0x116d41
movq %r14, %rdi
movq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x10f73b
movq 0x38(%rsp), %rax
movq (%rax), %rsi
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x116021