// File: chhylp123[P]hifiasm/hic.cpp
// Function: adjust_contig_partition(H_partition*, hc_links*)
void adjust_contig_partition(H_partition* hap, hc_links* link)
{
    double index_time = yak_realtime();
    uint32_t i, k, *h0, h0_n, *h1, h1_n;
    uint32_t h0_status[4], h1_status[4], h0_status_max;
    int h0_h, h1_h;
    for (i = 0; i < hap->g_p.n; i++)
    {

        get_phased_block(&(hap->g_p), NULL, i, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
        hap->g_p.a[i].status[0] = hap->g_p.a[i].status[1] = -2;
        hap->g_p.a[i].weight[0] = hap->g_p.a[i].weight[1] = hap->g_p.a[i].weight_convex = 0;


        h0_status[0] = h0_status[1] = h0_status[2] = h0_status[3] = 0;
        for (k = 0; k < h0_n; k++)
        {
            h0_status[get_phase_status(hap, h0[k])+2]++;
        }

        hap->g_p.a[i].weight[0] = get_cluster_weight(hap, link, h0, h0_n);
        if(h1_n == 0)
        {
            if(h0_status[0] == h0_n) ///unset, flag = -2
            {
                hap->g_p.a[i].status[0] = -2;
            }
            else
            {
                if(h0_status[1] > 0 || h0_status[3] > 0) ///phased flag = 1/-1
                {
                    h0_status[0] = h0_status[2] = 0;

                    h0_h = -2;
                    h0_status_max = 0;
                    for (k = 0; k < 4; k++)
                    {
                        if(h0_status[k] > h0_status_max)
                        {
                            h0_status_max = h0_status[k];
                            h0_h = (int)(k) - 2;
                        }
                    }
                    hap->g_p.a[i].status[0] = h0_h;
                }
                else if(h0_status[2] > 0) ///hom flag
                {
                    hap->g_p.a[i].status[0] = 0;
                }
                else  //unset flag
                {
                    hap->g_p.a[i].status[0] = -2;
                }
            }
        }
        else
        {
            hap->g_p.a[i].weight[1] = get_cluster_weight( hap, link, h1, h1_n);
            h1_status[0] = h1_status[1] = h1_status[2] = h1_status[3] = 0;
            for (k = 0; k < h1_n; k++)
            {
                h1_status[get_phase_status(hap, h1[k])+2]++;
            }


            h0_h = h1_h = 0;
            for (k = 0; k < 4; k++)
            {
                if(h0_status[k] == h0_n) h0_h = (int)(k) - 2;
                if(h1_status[k] == h1_n) h1_h = (int)(k) - 2;
            }

            if(h0_h * h1_h == -1)
            {
                hap->g_p.a[i].status[0] = h0_h;
                hap->g_p.a[i].status[1] = h1_h;
            }
            else
            {
                if(hap->g_p.a[i].weight[0] >= hap->g_p.a[i].weight[1])
                {
                    hap->g_p.a[i].status[0] = 1;
                    hap->g_p.a[i].status[1] = -1;
                }
                else
                {
                    hap->g_p.a[i].status[0] = -1;
                    hap->g_p.a[i].status[1] = 1;
                }
            }
        }
        hap->g_p.a[i].weight_convex = get_cluster_inner_weight(hap, link, h0, h0_n, h1, h1_n);
        update_partition_flag(hap, &(hap->g_p), link, i);
        ///update_partition_flag_debug(hap, &(hap->g_p), link, i);
    }

    for (i = 0; i < hap->g_p.n; i++)
    {
        get_phased_block(&(hap->g_p), NULL, i, NULL, NULL, &h0, &h0_n, &h1, &h1_n, NULL, NULL);
        hap->g_p.a[i].weight[0] = get_cluster_weight(hap, link, h0, h0_n);
        hap->g_p.a[i].weight[1] = get_cluster_weight(hap, link, h1, h1_n);
        hap->g_p.a[i].weight_convex = get_cluster_inner_weight(hap, link, h0, h0_n, h1, h1_n);
    }
    fprintf(stderr, "[M::%s::%.3f]\n", __func__, yak_realtime()-index_time);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0x1b7ca0
movsd %xmm0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x1eec5e
movq -0x8(%rbp), %rdi
addq $0x38, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %edx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x28(%rbp), %r9
leaq -0x2c(%rbp), %r11
leaq -0x38(%rbp), %r10
leaq -0x3c(%rbp), %rax
movq %r8, %rsi
movq %r8, %rcx
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
callq 0x214690
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0xfffffffe, 0x28(%rax) # imm = 0xFFFFFFFE
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0xfffffffe, 0x24(%rax) # imm = 0xFFFFFFFE
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x30(%rax)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x1ee93b
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,4), %esi
callq 0x2145e0
addl $0x2, %eax
cltq
movl -0x50(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x50(%rbp,%rax,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1ee905
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
callq 0x1edfb0
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x30(%rax)
cmpl $0x0, -0x3c(%rbp)
jne 0x1eea54
movl -0x50(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x1ee996
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0xfffffffe, 0x24(%rax) # imm = 0xFFFFFFFE
jmp 0x1eea4f
cmpl $0x0, -0x4c(%rbp)
ja 0x1ee9a2
cmpl $0x0, -0x44(%rbp)
jbe 0x1eea11
movl $0x0, -0x48(%rbp)
movl $0x0, -0x50(%rbp)
movl $0xfffffffe, -0x68(%rbp) # imm = 0xFFFFFFFE
movl $0x0, -0x64(%rbp)
movl $0x0, -0x20(%rbp)
cmpl $0x4, -0x20(%rbp)
jae 0x1ee9f7
movl -0x20(%rbp), %eax
movl -0x50(%rbp,%rax,4), %eax
cmpl -0x64(%rbp), %eax
jbe 0x1ee9ea
movl -0x20(%rbp), %eax
movl -0x50(%rbp,%rax,4), %eax
movl %eax, -0x64(%rbp)
movl -0x20(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x68(%rbp)
jmp 0x1ee9ec
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1ee9c5
movl -0x68(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %edx
imulq $0x48, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x24(%rax)
jmp 0x1eea4d
cmpl $0x0, -0x48(%rbp)
jbe 0x1eea32
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x24(%rax)
jmp 0x1eea4b
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0xfffffffe, 0x24(%rax) # imm = 0xFFFFFFFE
jmp 0x1eea4d
jmp 0x1eea4f
jmp 0x1eec05
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl -0x3c(%rbp), %ecx
callq 0x1edfb0
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x38(%rax)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jae 0x1eead8
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movl -0x20(%rbp), %ecx
movl (%rax,%rcx,4), %esi
callq 0x2145e0
addl $0x2, %eax
cltq
movl -0x60(%rbp,%rax,4), %ecx
addl $0x1, %ecx
movl %ecx, -0x60(%rbp,%rax,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1eeaa2
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x68(%rbp)
movl $0x0, -0x20(%rbp)
cmpl $0x4, -0x20(%rbp)
jae 0x1eeb2a
movl -0x20(%rbp), %eax
movl -0x50(%rbp,%rax,4), %eax
cmpl -0x2c(%rbp), %eax
jne 0x1eeb08
movl -0x20(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x68(%rbp)
movl -0x20(%rbp), %eax
movl -0x60(%rbp,%rax,4), %eax
cmpl -0x3c(%rbp), %eax
jne 0x1eeb1d
movl -0x20(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x6c(%rbp)
jmp 0x1eeb1f
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1eeaed
movl -0x68(%rbp), %eax
imull -0x6c(%rbp), %eax
cmpl $-0x1, %eax
jne 0x1eeb6b
movl -0x68(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %edx
imulq $0x48, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x24(%rax)
movl -0x6c(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %edx
imulq $0x48, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x28(%rax)
jmp 0x1eec03
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movsd 0x30(%rax), %xmm0
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
ucomisd 0x38(%rax), %xmm0
jb 0x1eebcf
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0x24(%rax)
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x28(%rax) # imm = 0xFFFFFFFF
jmp 0x1eec01
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0xffffffff, 0x24(%rax) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0x28(%rax)
jmp 0x1eec03
jmp 0x1eec05
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movq -0x38(%rbp), %r8
movl -0x3c(%rbp), %r9d
callq 0x1ee160
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x40(%rax)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rsi
addq $0x38, %rsi
movq -0x10(%rbp), %rdx
movl -0x1c(%rbp), %ecx
callq 0x1ee2c0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1ee804
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x1eed5a
movq -0x8(%rbp), %rdi
addq $0x38, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %edx
xorl %eax, %eax
movl %eax, %r8d
leaq -0x28(%rbp), %r9
leaq -0x2c(%rbp), %r11
leaq -0x38(%rbp), %r10
leaq -0x3c(%rbp), %rax
movq %r8, %rsi
movq %r8, %rcx
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
callq 0x214690
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
callq 0x1edfb0
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x30(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rdx
movl -0x3c(%rbp), %ecx
callq 0x1edfb0
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x38(%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movq -0x38(%rbp), %r8
movl -0x3c(%rbp), %r9d
callq 0x1ee160
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movsd %xmm0, 0x40(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1eec65
movq 0x1d527f(%rip), %rax    # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x78(%rbp)
callq 0x1b7ca0
movq -0x78(%rbp), %rdi
subsd -0x18(%rbp), %xmm0
leaq 0x19da8b(%rip), %rsi    # 0x38c808
leaq 0x19de7b(%rip), %rdx    # 0x38cbff
movb $0x1, %al
callq 0x22a0
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)