// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/horder.cpp
// Function: get_consensus_break(h_covs*, h_covs*)
void get_consensus_break(h_covs *res, h_covs *tmp)
{
    uint64_t i, k, n, m, max_cut = 0;
    h_cov_t *p = NULL;
    tmp->n = 0;
    if(res->n == 0) return;
    n = res->n;
    for (i = 0; i < n; i++)
    {
        res->a[i].s <<= 1;
        if(max_cut < res->a[i].dp) max_cut = res->a[i].dp;
        kv_pushp(h_cov_t, *res, &p);
        *p = res->a[i];
        p->s = (res->a[i].e<<1)|1;
    }

    radix_sort_h_cov_s(res->a, res->a+res->n);
    int64_t dp, old_dp, start = 0, max_dp;
    p = NULL; max_dp = -1; tmp->n = 0;
    for (i = 0, dp = 0, start = 0; i < res->n; ++i) 
    {
        old_dp = dp;
        ///if a[j] is qe
        if (res->a[i].s&1) --dp;
        else ++dp;

        if (old_dp < dp) ///old_dp < dp, b.a[j] is qs
        { 
            ///case 2, a[j] is qs
            start = res->a[i].s>>1;
        } 
        else if (old_dp > dp) ///old_dp > min_dp, b.a[j] is qe
        {
            if(max_dp < old_dp)
            {
                max_dp = old_dp;
                tmp->n = 0;
                kv_pushp(h_cov_t, *tmp, &p);
                p->s = start; p->e = res->a[i].s>>1; p->dp = max_cut;
            }
            else if(max_dp == old_dp)
            {
                kv_pushp(h_cov_t, *tmp, &p);
                p->s = start; p->e = res->a[i].s>>1; p->dp = max_cut;
            }
        }
    }
    if(tmp->n == 0) fprintf(stderr, "ERROR-break-0\n");
    // if(tmp->n == 1) return;

    for (i = m = 0; i < res->n; ++i)
    {
        if(res->a[i].s&1) continue;
        res->a[m] = res->a[i];
        res->a[m].s >>= 1;
        m++;
    }
    res->n = m;
    if(res->n != n) fprintf(stderr, "ERROR-break-1\n");
    for (i = 0; i < res->n; ++i)
    {
        for (k = 0; k < tmp->n; k++)
        {
            if(OVL(res->a[i].s, res->a[i].e, tmp->a[k].s, tmp->a[k].e) == 0) continue;
            tmp->a[k].dp = MIN(tmp->a[k].dp, res->a[i].dp);
            if(max_cut > tmp->a[k].dp) max_cut = tmp->a[k].dp;
        }
    }

    for (k = m = 0; k < tmp->n; k++)
    {
        if(max_cut != tmp->a[k].dp) continue;
        tmp->a[m] = tmp->a[k];
        m++;
    }
    tmp->n = m;
    if(tmp->n == 0) fprintf(stderr, "ERROR-break-2\n");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq $0x0, 0x8(%rsi)
movq 0x8(%rdi), %r13
testq %r13, %r13
je 0x170947
movq %rsi, %rbp
movq %rdi, %r14
xorl %ebx, %ebx
movl $0x2, %r12d
movq %r13, 0x18(%rsp)
xorl %r15d, %r15d
movq (%r14), %rdi
shlq (%rdi,%rbx)
movq %r15, %rax
movq 0x10(%rdi,%rbx), %r15
cmpq %r15, %rax
cmovaq %rax, %r15
movq 0x10(%r14), %rax
cmpq %rax, 0x8(%r14)
jne 0x170657
leaq (%rax,%rax), %rcx
testq %rax, %rax
cmoveq %r12, %rcx
movq %rcx, 0x10(%r14)
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq %rax, (%r14)
movq (%r14), %rax
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rbx), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups (%rax,%rbx), %xmm0
movups %xmm0, (%rax,%rcx,8)
movq (%r14), %rdx
movq 0x8(%rdx,%rbx), %rdx
leaq 0x1(,%rdx,2), %rdx
movq %rdx, (%rax,%rcx,8)
addq $0x18, %rbx
decq %r13
jne 0x170618
movq (%r14), %rdi
movq 0x8(%r14), %rax
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x16d2c9
movq %rbp, 0x8(%rsp)
movq $0x0, 0x8(%rbp)
cmpq $0x0, 0x8(%r14)
je 0x170801
movq $-0x1, %rdi
xorl %r13d, %r13d
xorl %esi, %esi
xorl %ebp, %ebp
xorl %ebx, %ebx
movq (%r14), %rax
movq (%rax,%r13), %r12
testb $0x1, %r12b
jne 0x1706f1
movq %r12, %rsi
shrq %rsi
jmp 0x1707e2
cmpq %rbx, %rdi
jge 0x170766
movq 0x8(%rsp), %rdi
movq $0x0, 0x8(%rdi)
cmpq $0x0, 0x10(%rdi)
jne 0x170736
movq $0x2, 0x10(%rdi)
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq %rsi, 0x10(%rsp)
movl $0x30, %esi
callq 0x2370
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rax, (%rdi)
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rdi)
leaq (%rcx,%rcx,2), %rcx
movq %rsi, (%rax,%rcx,8)
movq (%r14), %rdx
movq (%rdx,%r13), %rdx
shrq %rdx
movq %rdx, 0x8(%rax,%rcx,8)
movq %r15, 0x10(%rax,%rcx,8)
movq %rbx, %rdi
jmp 0x1707e2
jne 0x1707e2
movq 0x8(%rsp), %r8
movq 0x10(%r8), %rax
cmpq %rax, 0x8(%r8)
jne 0x1707b7
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r8)
movq %rdi, 0x20(%rsp)
movq (%r8), %rdi
shlq $0x3, %rcx
movq %rsi, 0x10(%rsp)
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0x8(%rsp), %r8
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq %rax, (%r8)
movq (%r8), %rax
movq 0x8(%r8), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r8)
leaq (%rcx,%rcx,2), %rcx
movq %rsi, (%rax,%rcx,8)
movq (%r14), %rdx
movq (%rdx,%r13), %rdx
shrq %rdx
movq %rdx, 0x8(%rax,%rcx,8)
movq %r15, 0x10(%rax,%rcx,8)
andl $0x1, %r12d
negq %r12
orq $0x1, %r12
addq %r12, %rbx
incq %rbp
addq $0x18, %r13
cmpq 0x8(%r14), %rbp
jb 0x1706d9
movq 0x8(%rsp), %r12
cmpq $0x0, 0x8(%r12)
je 0x170956
cmpq $0x0, 0x8(%r14)
movq 0x18(%rsp), %r10
je 0x170867
xorl %ecx, %ecx
xorl %edx, %edx
xorl %eax, %eax
movq (%r14), %rsi
testb $0x1, (%rsi,%rcx)
jne 0x170858
leaq (%rsi,%rcx), %rdi
leaq (,%rax,8), %r8
leaq (%r8,%r8,2), %r8
movq 0x10(%rdi), %r9
movq %r9, 0x10(%rsi,%r8)
movups (%rdi), %xmm0
movups %xmm0, (%rsi,%r8)
movq (%r14), %rsi
shrq (%rsi,%r8)
incq %rax
incq %rdx
addq $0x18, %rcx
cmpq 0x8(%r14), %rdx
jb 0x170824
jmp 0x170869
xorl %eax, %eax
movq %rax, 0x8(%r14)
cmpq %r10, %rax
jne 0x170960
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x1708f0
movq 0x8(%r12), %rcx
xorl %edx, %edx
testq %rcx, %rcx
je 0x1708e8
movq (%r14), %rsi
leaq (%rdx,%rdx,2), %rdi
leaq (%rsi,%rdi,8), %rsi
addq $0x10, %rsi
movq -0x10(%rsi), %rdi
movq -0x8(%rsi), %r8
movq (%r12), %r9
addq $0x10, %r9
movq %rcx, %r10
movq -0x10(%r9), %r11
movq -0x8(%r9), %rbx
cmpq %rbx, %r8
cmovbq %r8, %rbx
cmpq %r11, %rdi
cmovaq %rdi, %r11
cmpq %r11, %rbx
jbe 0x1708df
movq (%r9), %r11
movq (%rsi), %rbx
cmpq %rbx, %r11
cmovbq %r11, %rbx
movq %rbx, (%r9)
cmpq %rbx, %r15
cmovaeq %rbx, %r15
addq $0x18, %r9
decq %r10
jne 0x1708ad
incq %rdx
cmpq %rax, %rdx
jne 0x170886
cmpq $0x0, 0x8(%r12)
je 0x17093b
movl $0x10, %ecx
xorl %eax, %eax
xorl %edx, %edx
movq (%r12), %rsi
cmpq (%rsi,%rcx), %r15
jne 0x17092b
leaq (%rsi,%rcx), %rdi
addq $-0x10, %rdi
leaq (%rax,%rax,2), %r8
movq 0x10(%rdi), %r9
movq %r9, 0x10(%rsi,%r8,8)
movups (%rdi), %xmm0
movups %xmm0, (%rsi,%r8,8)
incq %rax
incq %rdx
addq $0x18, %rcx
cmpq 0x8(%r12), %rdx
jb 0x170901
jmp 0x17093d
xorl %eax, %eax
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x17096a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x229a4
jmp 0x170812
callq 0x229c0
jmp 0x170876
callq 0x229dc
jmp 0x170947