// File: /workspace/github_cpp_makefile_star2_O2/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 $0x18, %rsp
andq $0x0, 0x8(%rsi)
movq 0x8(%rdi), %rbp
testq %rbp, %rbp
je 0x133672
movq %rsi, %rbx
movq %rdi, %r14
xorl %r15d, %r15d
movq %rbp, %r13
xorl %r12d, %r12d
movq (%r14), %rdi
subq $0x1, %r13
jb 0x13343b
shlq (%rdi,%r15)
movq 0x10(%rdi,%r15), %rax
cmpq %rax, %r12
cmovbeq %rax, %r12
movq 0x8(%r14), %rax
cmpq 0x10(%r14), %rax
jne 0x1333ff
leaq (%rax,%rax), %rcx
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r14)
imulq $0x18, %rcx, %rsi
callq 0x2370
movq %rax, %rdi
movq %rax, (%r14)
movq 0x8(%r14), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%r14)
imulq $0x18, %rax, %rax
movq 0x10(%rdi,%r15), %rcx
movq %rcx, 0x10(%rdi,%rax)
movups (%rdi,%r15), %xmm0
movups %xmm0, (%rdi,%rax)
movq (%r14), %rcx
movq 0x8(%rcx,%r15), %rcx
leaq 0x1(,%rcx,2), %rcx
movq %rcx, (%rdi,%rax)
addq $0x18, %r15
jmp 0x1333b7
imulq $0x18, 0x8(%r14), %rsi
addq %rdi, %rsi
callq 0x130013
andq $0x0, 0x8(%rbx)
pushq $-0x1
popq %rax
xorl %r15d, %r15d
xorl %ecx, %ecx
xorl %edi, %edi
xorl %r13d, %r13d
xorl %r8d, %r8d
movq %rbp, 0x10(%rsp)
cmpq 0x8(%r14), %r13
jae 0x133566
movq (%r14), %rdx
movq (%rdx,%r15), %rbp
testb $0x1, %bpl
jne 0x133484
movq %rbp, %r8
shrq %r8
jmp 0x133548
cmpq %rdi, %rax
jge 0x13349f
andq $0x0, 0x8(%rbx)
cmpq $0x0, 0x10(%rbx)
movq (%rbx), %rax
je 0x1334f5
xorl %esi, %esi
jmp 0x133524
jne 0x133548
movq (%rbx), %rax
cmpq 0x10(%rbx), %rcx
jne 0x1334e8
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
imulq $0x18, %rdx, %rsi
movq %rdi, 0x8(%rsp)
movq %rax, %rdi
movq %r8, (%rsp)
callq 0x2370
movq (%rsp), %r8
movq 0x8(%rsp), %rdi
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
movq (%r14), %rdx
imulq $0x18, %rcx, %rsi
incq %rcx
movq %rcx, 0x8(%rbx)
jmp 0x133530
movq $0x2, 0x10(%rbx)
movq %rdi, 0x8(%rsp)
movq %rax, %rdi
pushq $0x30
popq %rsi
movq %r8, (%rsp)
callq 0x2370
movq (%rsp), %r8
movq 0x8(%rsp), %rdi
movq %rax, (%rbx)
movq 0x8(%rbx), %rsi
movq (%r14), %rdx
leaq 0x1(%rsi), %rcx
movq %rcx, 0x8(%rbx)
imulq $0x18, %rsi, %rsi
movq %r8, (%rax,%rsi)
movq (%rdx,%r15), %rdx
shrq %rdx
movq %rdx, 0x8(%rax,%rsi)
movq %r12, 0x10(%rax,%rsi)
movq %rdi, %rax
andl $0x1, %ebp
negq %rbp
orq $0x1, %rbp
addq %rbp, %rdi
incq %r13
addq $0x18, %r15
movq 0x10(%rsp), %rbp
jmp 0x133462
testq %rcx, %rcx
je 0x133681
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
cmpq 0x8(%r14), %rdx
jae 0x1335b0
movq (%r14), %rsi
testb $0x1, (%rsi,%rax)
jne 0x1335a7
leaq (%rsi,%rax), %rdi
imulq $0x18, %rcx, %r8
movq 0x10(%rdi), %r9
movq %r9, 0x10(%rsi,%r8)
movups (%rdi), %xmm0
movups %xmm0, (%rsi,%r8)
movq (%r14), %rsi
shrq (%rsi,%r8)
incq %rcx
incq %rdx
addq $0x18, %rax
jmp 0x133575
movq %rcx, 0x8(%r14)
cmpq %rbp, %rcx
jne 0x1336a2
xorl %eax, %eax
pushq $0x10
popq %rcx
cmpq %rbp, %rax
je 0x13362a
movq 0x8(%rbx), %rdx
imulq $0x18, %rax, %rsi
movq %rcx, %rdi
subq $0x1, %rdx
jb 0x133625
movq (%r14), %r9
movq (%r9,%rsi), %r10
movq 0x8(%r9,%rsi), %r11
movq (%rbx), %r8
movq -0x10(%r8,%rdi), %r15
movq -0x8(%r8,%rdi), %r13
cmpq %r13, %r11
cmovbq %r11, %r13
cmpq %r15, %r10
cmovaq %r10, %r15
cmpq %r15, %r13
jbe 0x13361f
movq (%r8,%rdi), %r10
movq 0x10(%r9,%rsi), %r9
cmpq %r9, %r10
cmovbq %r10, %r9
movq %r9, (%r8,%rdi)
cmpq %r9, %r12
cmovaeq %r9, %r12
addq $0x18, %rdi
jmp 0x1335d2
incq %rax
jmp 0x1335c2
pushq $0x10
popq %rax
xorl %ecx, %ecx
xorl %edx, %edx
cmpq 0x8(%rbx), %rcx
jae 0x133669
movq (%rbx), %rsi
cmpq (%rsi,%rax), %r12
jne 0x133660
leaq (%rsi,%rax), %rdi
addq $-0x10, %rdi
imulq $0x18, %rdx, %r8
movq 0x10(%rdi), %r9
movq %r9, 0x10(%rsi,%r8)
movups (%rdi), %xmm0
movups %xmm0, (%rsi,%r8)
incq %rdx
incq %rcx
addq $0x18, %rax
jmp 0x133631
movq %rdx, 0x8(%rbx)
testq %rdx, %rdx
je 0x1336c7
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x11f958(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0xbc0eb(%rip), %rdi     # 0x1ef77d
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0x13356f
movq 0x11f937(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0xbc0d9(%rip), %rdi     # 0x1ef78c
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x8(%r14), %rbp
jmp 0x1335bd
movq 0x11f912(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0xbc0c3(%rip), %rdi     # 0x1ef79b
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2410