// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movq %rdx, %r15
movq %rsi, 0x38(%rsp)
movq %rdi, %r12
leaq 0x58(%rdx), %rdi
movq %rdi, 0x30(%rsp)
callq 0x149558
movq (%r15), %r14
leaq (,%r14,4), %rbx
movq %rbx, %rdi
callq 0x2280
xorps %xmm0, %xmm0
movups %xmm0, 0x58(%r15)
movq $0x0, 0x68(%r15)
movq %rax, 0x70(%r15)
testq %r14, %r14
je 0x15d111
movq %rax, %rdi
movl $0xff, %esi
movq %rbx, %rdx
callq 0x20e0
cmpq $0x0, 0xe0(%r12)
je 0x15d534
xorl %edi, %edi
xorl %esi, %esi
xorl %ebx, %ebx
movq %rbx, 0x50(%rsp)
movq 0x58(%r15), %r8
cmpq 0x60(%r15), %r8
jne 0x15d166
leaq (%r8,%r8), %rcx
testq %r8, %r8
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x60(%r15)
shlq $0x3, %rcx
movq %rsi, %rbx
leaq (%rcx,%rcx,8), %rsi
callq 0x2370
movq %rbx, %rsi
movq %rax, 0x68(%r15)
movq 0x58(%r15), %r8
jmp 0x15d169
movq %rdi, %rax
leaq 0x1(%r8), %rcx
movq 0x30(%rsp), %rdx
movq %rcx, (%rdx)
leaq (%r8,%r8,8), %rcx
movq %rax, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
leaq (%rax,%rcx,8), %r11
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r11)
movups %xmm0, (%r11)
movb $0x0, 0x20(%r11)
movabsq $-0xffffffff, %rax      # imm = 0xFFFFFFFF00000001
movq %rax, 0x24(%r11)
movups %xmm0, 0x30(%r11)
movq $0x0, 0x40(%r11)
movq 0xf0(%r12), %rax
movq %rsi, 0x28(%rsp)
leaq (%rsi,%rsi,4), %r9
movl 0x8(%rax,%r9,8), %ecx
leaq (%rcx,%rcx,4), %rcx
movq 0x10(%rax,%rcx,8), %rbx
movl 0x10(%rbx), %esi
testl %esi, %esi
movq %r11, 0x20(%rsp)
je 0x15d453
xorl %edx, %edx
xorl %eax, %eax
xorl %edi, %edi
xorl %ecx, %ecx
xorl %r14d, %r14d
movq %rbx, 0x18(%rsp)
movq %r9, 0x8(%rsp)
movq 0x18(%rbx), %r8
movq (%r8,%r14,8), %r8
movq 0x40(%r12), %r10
shrq $0x21, %r8
movl (%r10,%r8,4), %r9d
movl 0x4(%r10,%r8,4), %r8d
subl %r9d, %r8d
addl $-0x2, %r8d
je 0x15d2e3
movq %r14, 0x10(%rsp)
movq 0x28(%r12), %rsi
leaq (%rsi,%r9,4), %r14
addq $0x8, %r14
movl %r8d, %ebp
xorl %ebx, %ebx
movq 0x8(%rsp), %r9
movl (%r14,%rbx,4), %r13d
shrl %r13d
movq 0xf0(%r12), %rsi
movq 0x100(%r12), %r8
movl (%r8,%r13,4), %r8d
cmpl 0x8(%rsi,%r9,8), %r8d
jne 0x15d2c8
movq 0x10(%r15), %rsi
movl (%rsi,%r13,4), %esi
testl %esi, 0x20(%r15)
jne 0x15d2c8
movl 0x1c(%r15), %r8d
andl %esi, %r8d
jne 0x15d2c8
andl 0x18(%r15), %esi
je 0x15d2c8
cmpq 0x8(%r11), %rcx
jne 0x15d2ad
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r11)
shlq $0x2, %rsi
callq 0x2370
movq 0x8(%rsp), %r9
movq 0x20(%rsp), %r11
movq %rax, 0x10(%r11)
movq (%r11), %rcx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r11)
movl %r13d, (%rax,%rcx,4)
movl 0x18(%r11), %edx
incl %edx
movl %edx, 0x18(%r11)
movq %rax, %rdi
movq %rsi, %rcx
incq %rbx
cmpq %rbx, %rbp
jne 0x15d23a
movq 0x18(%rsp), %rbx
movl 0x10(%rbx), %esi
movq 0x10(%rsp), %r14
jmp 0x15d2e8
movq 0x8(%rsp), %r9
incq %r14
movl %esi, %r8d
cmpq %r8, %r14
jb 0x15d1f7
testl %esi, %esi
je 0x15d3e8
xorl %r10d, %r10d
movq 0x18(%rbx), %rdx
movq (%rdx,%r10,8), %rdx
movq 0x40(%r12), %r8
shrq $0x21, %rdx
movl (%r8,%rdx,4), %edi
movl 0x4(%r8,%rdx,4), %edx
subl %edi, %edx
addl $-0x2, %edx
je 0x15d3d6
movq %r10, 0x10(%rsp)
movq 0x28(%r12), %rsi
leaq (%rsi,%rdi,4), %rbx
addq $0x8, %rbx
movl %edx, %r14d
xorl %ebp, %ebp
movl (%rbx,%rbp,4), %r13d
shrl %r13d
movq 0xf0(%r12), %rdx
movq 0x100(%r12), %rsi
movl (%rsi,%r13,4), %esi
cmpl 0x8(%rdx,%r9,8), %esi
jne 0x15d3bd
movq 0x10(%r15), %rdx
movl (%rdx,%r13,4), %edx
testl %edx, 0x20(%r15)
jne 0x15d3bd
andl 0x1c(%r15), %edx
je 0x15d3bd
cmpq 0x8(%r11), %rcx
jne 0x15d3ab
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r11)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %r9
movq 0x20(%rsp), %r11
movq %rax, 0x10(%r11)
movq (%r11), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r11)
movl %r13d, (%rax,%rcx,4)
incl 0x1c(%r11)
movq %rdx, %rcx
incq %rbp
cmpq %rbp, %r14
jne 0x15d33e
movq 0x18(%rsp), %rbx
movl 0x10(%rbx), %esi
movq 0x10(%rsp), %r10
incq %r10
movl %esi, %edx
cmpq %rdx, %r10
jb 0x15d302
movl 0x18(%r11), %edx
testl %edx, %edx
je 0x15d416
movl 0x58(%r15), %esi
decl %esi
movq 0x70(%r15), %rdi
xorl %edx, %edx
movl (%rax,%rdx,4), %r8d
movl %esi, (%rdi,%r8,4)
movl (%rax,%rdx,4), %r8d
shll (%rdi,%r8,4)
incq %rdx
movl 0x18(%r11), %r8d
cmpq %r8, %rdx
jb 0x15d3f8
jmp 0x15d418
xorl %edx, %edx
movl %edx, %edx
cmpq %rdx, %rcx
jbe 0x15d453
movl 0x58(%r15), %esi
decl %esi
movq 0x70(%r15), %rdi
leal 0x1(%rdx), %r8d
movl (%rax,%rdx,4), %r9d
movl %esi, (%rdi,%r9,4)
movl (%rax,%rdx,4), %edx
movl (%rdi,%rdx,4), %r9d
leal 0x1(,%r9,2), %r9d
movl %r9d, (%rdi,%rdx,4)
movl %r8d, %edx
incl %r8d
cmpq %rdx, %rcx
ja 0x15d42d
movq 0x30(%r15), %rsi
movq 0x68(%r15), %rcx
movq 0x28(%rsp), %rax
leaq (%rax,%rax,8), %rax
movq 0x10(%rcx,%rax,8), %rdx
movl 0x18(%rcx,%rax,8), %r14d
leaq (%rdx,%r14,4), %r8
movq %rcx, 0x8(%rsp)
movl 0x1c(%rcx,%rax,8), %r13d
testl %r13d, %r13d
movl $0x0, %eax
cmovneq %r8, %rax
movq %rax, 0x10(%rsp)
movq %r14, %rax
testq %r14, %r14
cmovneq %rdx, %rax
movq %rax, 0x18(%rsp)
je 0x15d4d5
movq 0x48(%rsp), %rax
movq 0x40(%rsp), %rcx
leaq (%rax,%rcx,8), %rax
addq $0x30, %rax
movq %rax, 0x28(%rsp)
movq %r15, %rdi
movq %rsi, %rbp
movl %r14d, %ecx
movq %r8, %rbx
callq 0x153e0c
movq %rbx, %r8
movq %rbp, %rsi
movq 0x28(%rsp), %rax
movsd %xmm0, (%rax)
testl %r13d, %r13d
movq 0x50(%rsp), %rbx
movq 0x20(%rsp), %rbp
je 0x15d502
movq %r15, %rdi
movq %rsi, %rbp
movq %r8, %rdx
movl %r13d, %ecx
callq 0x153e0c
movq %rbp, %rsi
movq 0x20(%rsp), %rbp
movsd %xmm0, 0x38(%rbp)
movq 0x18(%rsp), %rdx
movl %r14d, %ecx
movq 0x10(%rsp), %r8
movl %r13d, %r9d
callq 0x153edf
movsd %xmm0, 0x40(%rbp)
incl %ebx
movq %rbx, %rsi
cmpq %rbx, 0xe0(%r12)
movq 0x8(%rsp), %rdi
ja 0x15d126
movq %r15, %rdi
movq 0x30(%rsp), %rbx
movq %rbx, %rsi
callq 0x15697b
movq 0x38(%rsp), %rax
movq (%rax), %rsi
movq %rbx, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x15c428