// File: /workspace/github_cpp_makefile_star2_O3/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), %rbp
testq %rbp, %rbp
je 0x1774f6
movq %rdi, %r14
movq %rsi, 0x8(%rsp)
movq (%rdi), %rdi
xorl %ebx, %ebx
movl $0x2, %r12d
movq %rbp, %r13
xorl %r15d, %r15d
shlq (%rdi,%rbx)
movq %r15, %rax
movq 0x10(%rdi,%rbx), %r15
cmpq %r15, %rax
cmovaq %rax, %r15
movq 0x8(%r14), %rax
cmpq 0x10(%r14), %rax
jne 0x177216
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, %rdi
movq %rax, (%r14)
movq 0x8(%r14), %rax
movq %rdi, %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%r14)
leaq (%rax,%rax,2), %rax
movq 0x10(%rdi,%rbx), %rdx
movq %rdx, 0x10(%rdi,%rax,8)
movups (%rdi,%rbx), %xmm0
movups %xmm0, (%rdi,%rax,8)
movq (%r14), %rdi
movq 0x8(%rdi,%rbx), %rdx
leaq 0x1(,%rdx,2), %rdx
movq %rdx, (%rcx,%rax,8)
addq $0x18, %rbx
decq %r13
jne 0x1771d3
movq 0x8(%r14), %rax
leaq (%rax,%rax,2), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x173cff
movq 0x8(%rsp), %r10
movq $0x0, 0x8(%r10)
cmpq $0x0, 0x8(%r14)
je 0x177505
movq %rbp, 0x18(%rsp)
movq (%r14), %rcx
movq $-0x1, %r9
xorl %r13d, %r13d
xorl %edx, %edx
xorl %r8d, %r8d
xorl %ebp, %ebp
xorl %ebx, %ebx
movq (%rcx,%r13), %r12
testb $0x1, %r12b
jne 0x1772b1
movq %r12, %r8
shrq %r8
jmp 0x177399
cmpq %rbx, %r9
jge 0x1772cf
movq $0x0, 0x8(%r10)
cmpq $0x0, 0x10(%r10)
movq (%r10), %rax
je 0x177347
xorl %esi, %esi
jmp 0x177375
jne 0x177399
movq (%r10), %rax
cmpq 0x10(%r10), %rdx
jne 0x177325
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
movl $0x2, %edx
cmoveq %rdx, %rcx
movq %rcx, 0x10(%r10)
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rax, %rdi
movq %r8, 0x10(%rsp)
movq %r9, 0x20(%rsp)
callq 0x2370
movq 0x20(%rsp), %r9
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r10
movq %rax, (%r10)
movq 0x8(%r10), %rdx
movq (%r14), %rcx
leaq (%rdx,%rdx,2), %rsi
incq %rdx
movq %rdx, 0x8(%r10)
movq %r8, (%rax,%rsi,8)
movq (%rcx,%r13), %rdi
shrq %rdi
movq %rdi, 0x8(%rax,%rsi,8)
movq %r15, 0x10(%rax,%rsi,8)
jmp 0x177399
movq $0x2, 0x10(%r10)
movl $0x30, %esi
movq %rax, %rdi
movq %r8, 0x10(%rsp)
callq 0x2370
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r10
movq %rax, (%r10)
movq 0x8(%r10), %rsi
movq (%r14), %rcx
leaq 0x1(%rsi), %rdx
movq %rdx, 0x8(%r10)
leaq (%rsi,%rsi,2), %rsi
movq %r8, (%rax,%rsi,8)
movq (%rcx,%r13), %rdi
shrq %rdi
movq %rdi, 0x8(%rax,%rsi,8)
movq %r15, 0x10(%rax,%rsi,8)
movq %rbx, %r9
andl $0x1, %r12d
negq %r12
orq $0x1, %r12
addq %r12, %rbx
incq %rbp
movq 0x8(%r14), %rax
addq $0x18, %r13
cmpq %rax, %rbp
jb 0x17729c
testq %rdx, %rdx
movq 0x18(%rsp), %rbp
je 0x177505
testq %rax, %rax
je 0x17741a
movq (%r14), %rsi
xorl %edx, %edx
xorl %edi, %edi
xorl %ecx, %ecx
testb $0x1, (%rsi,%rdx)
jne 0x17740c
leaq (%rsi,%rdx), %rax
leaq (,%rcx,8), %r8
leaq (%r8,%r8,2), %r8
movq 0x10(%rax), %r9
movq %r9, 0x10(%rsi,%r8)
movups (%rax), %xmm0
movups %xmm0, (%rsi,%r8)
movq (%r14), %rsi
shrq (%rsi,%r8)
incq %rcx
movq 0x8(%r14), %rax
incq %rdi
addq $0x18, %rdx
cmpq %rax, %rdi
jb 0x1773d7
jmp 0x17741c
xorl %ecx, %ecx
movq %rcx, 0x8(%r14)
cmpq %rbp, %rcx
jne 0x17753a
movq 0x8(%r10), %rax
testq %rbp, %rbp
je 0x1774a2
xorl %ecx, %ecx
testq %rax, %rax
je 0x177495
movq (%r14), %rdx
leaq (%rcx,%rcx,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0x10, %rdx
movq -0x10(%rdx), %rsi
movq -0x8(%rdx), %rdi
movq (%r10), %r8
addq $0x10, %r8
movq %rax, %r9
movq -0x10(%r8), %r10
movq -0x8(%r8), %r11
cmpq %r11, %rdi
cmovbq %rdi, %r11
cmpq %r10, %rsi
cmovaq %rsi, %r10
cmpq %r10, %r11
jbe 0x17748c
movq (%r8), %r10
movq (%rdx), %r11
cmpq %r11, %r10
cmovbq %r10, %r11
movq %r11, (%r8)
cmpq %r11, %r15
cmovaeq %r11, %r15
addq $0x18, %r8
decq %r9
jne 0x17745a
incq %rcx
cmpq %rbp, %rcx
movq 0x8(%rsp), %r10
jne 0x177434
testq %rax, %rax
je 0x177533
movl $0x10, %edx
xorl %ecx, %ecx
xorl %esi, %esi
movq (%r10), %rdi
cmpq (%rdi,%rdx), %r15
jne 0x1774e1
leaq (%rdi,%rdx), %rax
addq $-0x10, %rax
leaq (%rcx,%rcx,2), %r8
movq 0x10(%rax), %r9
movq %r9, 0x10(%rdi,%r8,8)
movups (%rax), %xmm0
movups %xmm0, (%rdi,%r8,8)
incq %rcx
movq 0x8(%r10), %rax
incq %rsi
addq $0x18, %rdx
cmpq %rax, %rsi
jb 0x1774b4
movq %rcx, 0x8(%r10)
testq %rcx, %rcx
je 0x177533
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x11dad4(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0xc63a7(%rip), %rdi     # 0x23d8bd
movl $0xe, %esi
movl $0x1, %edx
callq 0x2410
movq 0x8(%rsp), %r10
movq 0x8(%r14), %rax
jmp 0x1773c9
callq 0x21ca8
jmp 0x1774f6
movq 0x11da9f(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0xc6381(%rip), %rdi     # 0x23d8cc
movl $0xe, %esi
movl $0x1, %edx
callq 0x2410
movq 0x8(%rsp), %r10
movq 0x8(%r14), %rbp
jmp 0x177429