// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/path.c
// Function: fix_og_misclassification
static void fix_og_misclassification(og_component_v *component_v, int verbose)
{
    // TODO fix this by maybe improving the specificity of the HMM database
    // revisit to deal with mito misclassification
    // find the best pltd component
    uint32_t i, j, m, n, p_b, p_b1, genid, *mito_gen, *pltd_gen;
    uint64_t x;
    double p_s, p_s1;
    og_component_t *component;
    kvec_t(uint64_t) gen_list;
    OG_TYPE_t og_type;
    
    n = component_v->n;
    kv_init(gen_list);
    // collect best gene hits in each subgraph
    // pack in the component id
    for (i = 0; i < n; ++i) {
        component = &component_v->a[i];
        m = gen_list.n;
        kv_pushn(uint64_t, gen_list, component->g, component->ng);
        for (j = m; j < gen_list.n; ++j) {
            x = gen_list.a[j];
            gen_list.a[j] = (x & 0xFFFFFFFF00000000ULL) | ((uint32_t) x << 16 | i);
        }
    }
    
    if (gen_list.n == 0)
        return;

    // sort by gid and then score - descending order
    qsort(gen_list.a, gen_list.n, sizeof(uint64_t), u64_cmpfunc_r);
    
    MYCALLOC(mito_gen, n);
    MYCALLOC(pltd_gen, n);
    genid = gen_list.a[0] >> 32;
    for (i = 0, j = 0, m = gen_list.n; i < m; ++i) {
        if (gen_list.a[i] >> 32 != genid ||
                i == m - 1) {
            og_type = (gen_list.a[i] >> 32) & 0x3;
            if (og_type != OG_MITO &&
                    og_type != OG_PLTD)
                continue;
            if (i == j || 
                   (double) ((gen_list.a[j+1] >> 16) & 0xFFFFULL) < 
                   (double) ((gen_list.a[j] >> 16) & 0xFFFFULL) * 0.8) {
                x = gen_list.a[j] & 0xFFFFULL;
                if (og_type == OG_MITO)
                    ++mito_gen[x];
                else
                    ++pltd_gen[x];
            }
            genid = gen_list.a[i] >> 32;
            j = i;
        }
    }

    p_b = p_b1 = UINT32_MAX;
    p_s = p_s1 = 0;
    for (i = 0; i < component_v->n; ++i) {
        component = &component_v->a[i];
        if (component->type != OG_PLTD)
            continue;
        if (component->score > p_s && component->len >= COMMON_MIN_PLTD_SIZE) {
            if (component->len <= COMMON_MAX_PLTD_SIZE) {
                p_b = i;
                p_s = component->score;
            }
            p_b1 = i;
            p_s1 = component->score;
        }
    }
    if (p_b == UINT32_MAX) p_b = p_b1;
    if (p_b != UINT32_MAX) {
        // PLTD is likely there
        for (i = 0; i < component_v->n; ++i) {
            if (i == p_b) continue;
            component = &component_v->a[i];
            if (component->type != OG_PLTD)
                continue;
            if (pltd_gen[i] > mito_gen[i] * PLTD_TO_MITO_FST[1])
                continue;
            if (component->score > component->sscore * PLTD_TO_MITO_FST[1])
                continue;
            if (component->score < component->sscore * PLTD_TO_MITO_FST[0] ||
                    (component->len < COMMON_MIN_PLTD_SIZE ||
                     component->len > COMMON_MAX_PLTD_SIZE)) {
                double tmp = component->score;
                component->score = component->sscore;
                component->sscore = tmp;
                component->type = component->score > .0? OG_MITO : OG_UNCLASSIFIED;
                if (verbose > 0)
                    fprintf(stderr, "[M::%s] change subgraph organelle type annotation: PLTD [S=%.3f G=%u] -> MITO [S=%.3f G=%u]\n",
                            __func__, component->sscore, pltd_gen[i], component->score, mito_gen[i]);
            }
        }
    }

    free(mito_gen);
    free(pltd_gen);
    kv_destroy(gen_list);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x1c(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0xe8b0
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x10(%rbp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x70(%rbp), %rax
movl %eax, -0x18(%rbp)
movq -0x70(%rbp), %rax
movq -0x58(%rbp), %rcx
movl 0x28(%rcx), %ecx
addq %rcx, %rax
cmpq -0x68(%rbp), %rax
jbe 0xe817
movq -0x70(%rbp), %rax
movq -0x58(%rbp), %rcx
movl 0x28(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0xe782
movq -0x68(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0xe790
movl $0x1, %eax
movq %rax, -0x88(%rbp)
jmp 0xe790
movq -0x88(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
shrq %rax
orq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
shrq $0x2, %rax
orq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
shrq $0x4, %rax
orq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
shrq $0x8, %rax
orq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
shrq $0x10, %rax
orq -0x68(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2330
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
movq -0x70(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x58(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x58(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, %edx
shlq $0x3, %rdx
callq 0x22c0
movq -0x58(%rbp), %rax
movl 0x28(%rax), %eax
addq -0x70(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpq -0x70(%rbp), %rax
jae 0xe8a0
movq -0x60(%rbp), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
andq -0x40(%rbp), %rdx
movq -0x40(%rbp), %rax
shll $0x10, %eax
orl -0x10(%rbp), %eax
movl %eax, %eax
orq %rax, %rdx
movq -0x60(%rbp), %rax
movl -0x14(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xe855
jmp 0xe8a2
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xe71b
cmpq $0x0, -0x70(%rbp)
jne 0xe8bc
jmp 0xec89
movq -0x60(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl $0x8, %edx
leaq -0x230(%rip), %rcx      # 0xe6a0
callq 0x20c0
movl -0x1c(%rbp), %eax
movl %eax, %edi
movl $0x4, %esi
callq 0x2240
movq %rax, -0x30(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, %edi
movl $0x4, %esi
callq 0x2240
movq %rax, -0x38(%rbp)
movq -0x60(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x28(%rbp)
movl $0x0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x70(%rbp), %rax
movl %eax, -0x18(%rbp)
movl -0x10(%rbp), %eax
cmpl -0x18(%rbp), %eax
jae 0xea19
movq -0x60(%rbp), %rax
movl -0x10(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl -0x28(%rbp), %ecx
cmpq %rcx, %rax
jne 0xe952
movl -0x10(%rbp), %eax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0xea09
movq -0x60(%rbp), %rax
movl -0x10(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
andq $0x3, %rax
movl %eax, -0x74(%rbp)
cmpl $0x1, -0x74(%rbp)
je 0xe979
cmpl $0x2, -0x74(%rbp)
je 0xe979
jmp 0xea0b
movl -0x10(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0xe9b0
movq -0x60(%rbp), %rax
movl -0x14(%rbp), %ecx
movl %ecx, %edx
incl %edx
movzwl 0x2(%rax,%rdx,8), %edx
cvtsi2sd %edx, %xmm1
movzwl 0x2(%rax,%rcx,8), %eax
cvtsi2sd %eax, %xmm0
movsd 0x14b82(%rip), %xmm2    # 0x23528
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0xe9f1
movq -0x60(%rbp), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
andq $0xffff, %rax           # imm = 0xFFFF
movq %rax, -0x40(%rbp)
cmpl $0x1, -0x74(%rbp)
jne 0xe9de
movq -0x30(%rbp), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0xe9ef
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0xe9f1
movq -0x60(%rbp), %rax
movl -0x10(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x28(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0xea0b
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xe91e
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x20(%rbp) # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0xead1
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x10(%rbp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x2, (%rax)
je 0xea6f
jmp 0xeac3
movq -0x58(%rbp), %rax
movsd 0x8(%rax), %xmm0
ucomisd -0x48(%rbp), %xmm0
jbe 0xeac1
movq -0x58(%rbp), %rax
cmpl $0x13880, 0x18(%rax)    # imm = 0x13880
jb 0xeac1
movq -0x58(%rbp), %rax
cmpl $0x3d090, 0x18(%rax)    # imm = 0x3D090
ja 0xeaad
movl -0x10(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x58(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movl -0x10(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x58(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0xeac3
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xea3e
cmpl $-0x1, -0x20(%rbp)
jne 0xeadd
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
je 0xec6e
movl $0x0, -0x10(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
jae 0xec6c
movl -0x10(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0xeb0b
jmp 0xec5e
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x10(%rbp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpl $0x2, (%rax)
je 0xeb2f
jmp 0xec5e
movq -0x38(%rbp), %rax
movl -0x10(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cvtsi2sd %rax, %xmm0
movq -0x30(%rbp), %rax
movl (%rax,%rcx,4), %eax
cvtsi2sd %rax, %xmm1
mulsd 0x15b66(%rip), %xmm1    # 0x246b8
ucomisd %xmm1, %xmm0
jbe 0xeb5d
jmp 0xec5e
movq -0x58(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x58(%rbp), %rax
movsd 0x10(%rax), %xmm1
mulsd 0x15b41(%rip), %xmm1    # 0x246b8
ucomisd %xmm1, %xmm0
jbe 0xeb82
jmp 0xec5e
movq -0x58(%rbp), %rax
movsd 0x8(%rax), %xmm1
movq -0x58(%rbp), %rax
movsd 0x10(%rax), %xmm0
mulsd 0x15b14(%rip), %xmm0    # 0x246b0
ucomisd %xmm1, %xmm0
ja 0xebc0
movq -0x58(%rbp), %rax
cmpl $0x13880, 0x18(%rax)    # imm = 0x13880
jb 0xebc0
movq -0x58(%rbp), %rax
cmpl $0x3d090, 0x18(%rax)    # imm = 0x3D090
jbe 0xec5c
movq -0x58(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x80(%rbp)
movq -0x58(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x58(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movsd -0x80(%rbp), %xmm0
movq -0x58(%rbp), %rax
movsd %xmm0, 0x10(%rax)
movq -0x58(%rbp), %rax
movsd 0x8(%rax), %xmm0
xorps %xmm1, %xmm1
xorl %ecx, %ecx
movl $0x1, %eax
ucomisd %xmm1, %xmm0
cmoval %eax, %ecx
movq -0x58(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0xc(%rbp)
jle 0xec5a
movq 0x1b3dd(%rip), %rax     # 0x29ff8
movq (%rax), %rdi
movq -0x58(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x38(%rbp), %rax
movl -0x10(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
movq -0x58(%rbp), %rax
movsd 0x8(%rax), %xmm1
movq -0x30(%rbp), %rax
movl -0x10(%rbp), %edx
movl (%rax,%rdx,4), %r8d
leaq 0x1582b(%rip), %rsi     # 0x24477
leaq 0x15881(%rip), %rdx     # 0x244d4
movb $0x2, %al
callq 0x2290
jmp 0xec5c
jmp 0xec5e
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0xeaee
jmp 0xec6e
movq -0x30(%rbp), %rdi
callq 0x2060
movq -0x38(%rbp), %rdi
callq 0x2060
movq -0x60(%rbp), %rdi
callq 0x2060
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)