// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq %rsi, 0x30(%rsp)
movq %rdi, %r12
leaq 0x58(%rdx), %rdi
movq %rdi, 0x28(%rsp)
callq 0x142f71
xorps %xmm0, %xmm0
movups %xmm0, 0x68(%r15)
movups %xmm0, 0x58(%r15)
movq (%r15), %r14
leaq (,%r14,4), %rbx
movq %rbx, %rdi
callq 0x2280
movq %r15, %rdi
xorps %xmm0, %xmm0
movups %xmm0, 0x58(%r15)
movq $0x0, 0x68(%r15)
movq %rax, 0x70(%r15)
testq %r14, %r14
movq %r15, (%rsp)
je 0x1567e4
movq %rax, %rdi
movl $0xff, %esi
movq %rbx, %rdx
callq 0x20e0
movq (%rsp), %rdi
cmpq $0x0, 0xe0(%r12)
je 0x156bc9
xorl %r15d, %r15d
movq 0x60(%rdi), %rax
cmpq %rax, 0x58(%rdi)
jne 0x15682d
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x60(%rdi)
movq 0x68(%rdi), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,8), %rsi
callq 0x2370
movq (%rsp), %rdi
movq %rax, 0x68(%rdi)
movq 0x58(%rdi), %rax
movq 0x68(%rdi), %rdx
leaq 0x1(%rax), %rcx
movq %rcx, 0x58(%rdi)
leaq (%rax,%rax,8), %rax
movq %rdx, 0x40(%rsp)
movq %rax, 0x38(%rsp)
leaq (%rdx,%rax,8), %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r14)
movups %xmm0, (%r14)
movb $0x0, 0x20(%r14)
movabsq $-0xffffffff, %rax      # imm = 0xFFFFFFFF00000001
movq %rax, 0x24(%r14)
movups %xmm0, 0x30(%r14)
movq $0x0, 0x40(%r14)
movq 0xf0(%r12), %rax
movq %r15, 0x20(%rsp)
leaq (%r15,%r15,4), %rsi
movl 0x8(%rax,%rsi,8), %ecx
leaq (%rcx,%rcx,4), %rcx
movq 0x10(%rax,%rcx,8), %rcx
cmpl $0x0, 0x10(%rcx)
movq %rsi, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
je 0x156996
xorl %edx, %edx
movq 0x18(%rcx), %rax
movq %rdx, 0x18(%rsp)
movq (%rax,%rdx,8), %rax
movq 0x40(%r12), %rdx
shrq $0x21, %rax
movl (%rdx,%rax,4), %ecx
movl 0x4(%rdx,%rax,4), %eax
subl %ecx, %eax
addl $-0x2, %eax
je 0x15697d
movq 0x28(%r12), %rdx
leaq (%rdx,%rcx,4), %rbp
addq $0x8, %rbp
movl %eax, %ebx
xorl %r15d, %r15d
movl (%rbp,%r15,4), %r13d
shrl %r13d
movq 0xf0(%r12), %rax
movq 0x100(%r12), %rcx
movl (%rcx,%r13,4), %ecx
cmpl 0x8(%rax,%rsi,8), %ecx
jne 0x156971
movq 0x10(%rdi), %rax
movl (%rax,%r13,4), %eax
testl %eax, 0x20(%rdi)
jne 0x156971
movl 0x1c(%rdi), %ecx
andl %eax, %ecx
jne 0x156971
andl 0x18(%rdi), %eax
je 0x156971
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x15695b
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movl %r13d, (%rcx,%rax,4)
incl 0x18(%r14)
incq %r15
cmpq %r15, %rbx
jne 0x1568e9
movq 0x18(%rsp), %rdx
incq %rdx
movq 0x10(%rsp), %rcx
movl 0x10(%rcx), %eax
cmpq %rax, %rdx
jb 0x1568af
cmpl $0x0, 0x10(%rcx)
je 0x156a80
xorl %edx, %edx
movq 0x18(%rcx), %rax
movq %rdx, 0x18(%rsp)
movq (%rax,%rdx,8), %rax
movq 0x40(%r12), %rdx
shrq $0x21, %rax
movl (%rdx,%rax,4), %ecx
movl 0x4(%rdx,%rax,4), %eax
subl %ecx, %eax
addl $-0x2, %eax
je 0x156a67
movq 0x28(%r12), %rdx
leaq (%rdx,%rcx,4), %r15
addq $0x8, %r15
movl %eax, %ebp
xorl %ebx, %ebx
movl (%r15,%rbx,4), %r13d
shrl %r13d
movq 0xf0(%r12), %rax
movq 0x100(%r12), %rcx
movl (%rcx,%r13,4), %ecx
cmpl 0x8(%rax,%rsi,8), %ecx
jne 0x156a5b
movq 0x10(%rdi), %rax
movl (%rax,%r13,4), %eax
testl %eax, 0x20(%rdi)
jne 0x156a5b
andl 0x1c(%rdi), %eax
je 0x156a5b
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x156a45
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movl %r13d, (%rcx,%rax,4)
incl 0x1c(%r14)
incq %rbx
cmpq %rbx, %rbp
jne 0x1569db
movq 0x18(%rsp), %rdx
incq %rdx
movq 0x10(%rsp), %rcx
movl 0x10(%rcx), %eax
cmpq %rax, %rdx
jb 0x1569a2
cmpl $0x0, 0x18(%r14)
je 0x156ab9
movl 0x58(%rdi), %eax
decl %eax
movq 0x70(%rdi), %rdx
movq 0x10(%r14), %rsi
xorl %ecx, %ecx
movq 0x20(%rsp), %r15
movl (%rsi,%rcx,4), %r8d
movl %eax, (%rdx,%r8,4)
movl (%rsi,%rcx,4), %r8d
shll (%rdx,%r8,4)
incq %rcx
movl 0x18(%r14), %r8d
cmpq %r8, %rcx
jb 0x156a9b
jmp 0x156ac0
xorl %ecx, %ecx
movq 0x20(%rsp), %r15
movq (%r14), %rax
movl %ecx, %ecx
cmpq %rcx, %rax
jbe 0x156b02
movl 0x58(%rdi), %edx
decl %edx
movq 0x70(%rdi), %rsi
movq 0x10(%r14), %r10
leal 0x1(%rcx), %r8d
movl (%r10,%rcx,4), %r9d
movl %edx, (%rsi,%r9,4)
movl (%r10,%rcx,4), %ecx
movl (%rsi,%rcx,4), %r9d
leal 0x1(,%r9,2), %r9d
movl %r9d, (%rsi,%rcx,4)
movl %r8d, %ecx
incl %r8d
cmpq %rcx, %rax
ja 0x156adb
movq 0x68(%rdi), %rax
leaq (%r15,%r15,8), %rcx
movq 0x10(%rax,%rcx,8), %r13
movl 0x18(%rax,%rcx,8), %ebp
leaq (,%rbp,4), %rdx
addq %r13, %rdx
movl 0x1c(%rax,%rcx,8), %ebx
testl %ebx, %ebx
movl $0x0, %r8d
cmovneq %rdx, %r8
testq %rbp, %rbp
cmoveq %rbp, %r13
je 0x156b77
movq 0x40(%rsp), %rax
movq 0x38(%rsp), %rcx
movl %ebx, 0x8(%rsp)
leaq (%rax,%rcx,8), %rax
addq $0x30, %rax
movq %rax, 0x10(%rsp)
movq 0x30(%rdi), %rsi
movq %r13, %rdx
movl %ebp, %ecx
movq %r8, %rbx
callq 0x14d809
movq %rbx, %r8
movq (%rsp), %rdi
movq 0x10(%rsp), %rax
movsd %xmm0, (%rax)
movl 0x8(%rsp), %ebx
testl %ebx, %ebx
je 0x156b9d
movq 0x30(%rdi), %rsi
movq %r8, %rdx
movl %ebx, %ecx
movq %r8, 0x8(%rsp)
callq 0x14d809
movq 0x8(%rsp), %r8
movq (%rsp), %rdi
movsd %xmm0, 0x38(%r14)
movq 0x30(%rdi), %rsi
movq %r13, %rdx
movl %ebp, %ecx
movl %ebx, %r9d
callq 0x14d8ef
movq (%rsp), %rdi
movsd %xmm0, 0x40(%r14)
incl %r15d
cmpq %r15, 0xe0(%r12)
ja 0x1567f6
movq 0x28(%rsp), %rbx
movq %rbx, %rsi
callq 0x150412
movq 0x30(%rsp), %rax
movq (%rax), %rsi
movq %rbx, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x155abc