// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/path.c
// Function: annot_sequence_og_type
og_component_v *annot_sequence_og_type(hmm_annot_db_t *annot_db, asg_t *asg, int no_trn, int no_rrn, double max_eval,
        int n_core, int min_len, int min_score, int fix_og, int verbose)
{
    uint32_t i, j, k, n, n_seg, n_gene, m_gene, gid, imax, smax;
    uint32_t *asg_snameid_map;
    hmm_annot_t *annots, *annot;
    double a_s[4], *annot_score;
    OG_TYPE_t og_t;
    og_component_t *component;
    og_component_v *component_v;

    n_gene = annot_db->n;
    n_seg = asg->n_seg;

    if (n_gene == 0) return 0;
    if (n_core == 0) n_core = INT32_MAX;

    m_gene = annot_db->n_gene;

    // sort annotations by sid - og_type - gid - score
    hmm_annot_db_sort(annot_db, ORDER_SID_OG);
    // build asg sname to annot_db sname id map
    MYMALLOC(asg_snameid_map, n_seg);
    for (i = 0; i < n_seg; ++i)
        asg_snameid_map[i] = hmm_annot_sname2id(annot_db, asg->seg[i].name);

    MYMALLOC(annot_score, m_gene * 4);
    MYCALLOC(component_v, 1);
    MYCALLOC(component_v->a, n_seg);
    component_v->n = n_seg;
    component_v->m = n_seg;
    for (i = 0; i < n_seg; ++i) {
        component_v->a[i].type = (uint32_t) OG_UNCLASSIFIED;
        if (asg->asmg->vtx[i].del)
            continue;

        MYBZERO(annot_score, m_gene * 4);
        annots = hmm_annot_db_index_query(annot_db, asg_snameid_map[i], &n);
        if (annots) {
            for (k = 0; k < n; ++k) {
                annot = &annots[k];
                if (annot->evalue > max_eval ||
                        (no_trn && is_trn(annot)) ||
                        (no_rrn && is_rrn(annot)))
                    continue;
                gid = annot->og_type * m_gene + annot->gid;
                if (annot_score[gid] < annot->score)
                    annot_score[gid] = annot->score;
            }
        }

        // sort annotation scores for each og_type
        // and get the sum annotation score
        MYBZERO(a_s, 4);
        for (j = 0; j < 4; ++j) {
            qsort(&annot_score[j * m_gene], m_gene, sizeof(double), dbl_cmpfunc_r);
            n = MIN((uint32_t) n_core, m_gene);
            for (k = 0 ; k < n; ++k)
                a_s[j] += annot_score[j * m_gene + k];
        }
        imax = max2(a_s, 4, &smax);
        og_t = OG_UNCLASSIFIED;
        if (a_s[imax] >= min_score)
            // 1, mito; 2, pltd; 3, mini
            og_t = a_s[imax] == a_s[smax]? OG_UNCLASSIFIED : imax;

        if (og_t != OG_UNCLASSIFIED) {
            // make seg list
            uint32_t *comp_v;
            MYMALLOC(comp_v, 1);
            comp_v[0] = i;
            // make gene list
            // get all genes in the component
            kvec_t(uint64_t) comp_g;
            kv_init(comp_g);
            annots = hmm_annot_db_index_query(annot_db, asg_snameid_map[i], &n);
            if (annots) {
                for (k = 0; k < n; ++k) {
                    annot = &annots[k];
                    if (annot->evalue > max_eval ||
                            (no_trn && is_trn(annot)) ||
                            (no_rrn && is_rrn(annot)))
                        continue;
                    // gid:30 | OG_TYPE:2 | score:32
                    kv_push(uint64_t, comp_g,
                            ((uint64_t) annot->gid << 2 | annot->og_type) << 32 |
                            (uint32_t) annot->score);
                }
            }
            // sort by gid and then score - descending order
            qsort(comp_g.a, comp_g.n, sizeof(uint64_t), u64_cmpfunc_r);
            // keep only the best hit for each gene
            k = 0;
            gid = UINT32_MAX;
            for (j = 0; j < comp_g.n; ++j) {
                if (comp_g.a[j] >> 32 != gid) {
                    comp_g.a[k++] = comp_g.a[j];
                    gid = comp_g.a[j] >> 32;
                }
            }
            comp_g.n = comp_g.m = k;
            MYREALLOC(comp_g.a, k);

            // add og_component
            component = &component_v->a[i];
            component->type = (uint32_t) og_t;
            component->score = a_s[imax];
            component->sscore = a_s[smax];
            component->len = asg->seg[i].len;
            component->nv = 1;
            component->v = comp_v;
            component->ng = comp_g.n;
            component->g = comp_g.a;
            component->asmg = 0;
        }

        if (verbose > 0)
            fprintf(stderr, "[M::%s] sequence %s: size, %d; mito score, %.3f; pltd score, %.3f; mini score, %.3f; classification, %d\n",
                    __func__, asg->seg[i].name, asg->seg[i].len, a_s[OG_MITO], a_s[OG_PLTD], a_s[OG_MINI], og_t);
    }

    free(annot_score);
    free(asg_snameid_map);
    
    if (fix_og) fix_og_misclassification(component_v, verbose);

    return component_v;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x48(%rbp)
jne 0xde47
movq $0x0, -0x8(%rbp)
jmp 0xe5ba
cmpl $0x0, -0x2c(%rbp)
jne 0xde54
movl $0x7fffffff, -0x2c(%rbp) # imm = 0x7FFFFFFF
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x10(%rbp), %rdi
movl $0x5, %esi
callq 0x1eeb0
movl -0x44(%rbp), %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x22f0
movq %rax, -0x60(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0xdec2
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x1eca0
movl %eax, %edx
movq -0x60(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xde85
movl -0x4c(%rbp), %eax
shll $0x2, %eax
movl %eax, %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x22f0
movq %rax, -0x98(%rbp)
movl $0x1, %edi
movl $0x18, %esi
callq 0x2240
movq %rax, -0xb0(%rbp)
movl -0x44(%rbp), %eax
movl %eax, %edi
movl $0x40, %esi
callq 0x2240
movq %rax, %rcx
movq -0xb0(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x44(%rbp), %eax
movl %eax, %ecx
movq -0xb0(%rbp), %rax
movq %rcx, (%rax)
movl -0x44(%rbp), %eax
movl %eax, %ecx
movq -0xb0(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0xe585
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xdf85
jmp 0xe577
movq -0x98(%rbp), %rdi
movl -0x4c(%rbp), %eax
shll $0x2, %eax
movl %eax, %eax
movl %eax, %edx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x21c0
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %esi
leaq -0x40(%rbp), %rdx
callq 0x1f480
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0xe091
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0xe08f
movq -0x68(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movsd 0x30(%rax), %xmm0
ucomisd -0x28(%rbp), %xmm0
ja 0xe024
cmpl $0x0, -0x1c(%rbp)
je 0xe010
movq -0x70(%rbp), %rdi
callq 0x1fdd0
cmpl $0x0, %eax
jne 0xe024
cmpl $0x0, -0x20(%rbp)
je 0xe026
movq -0x70(%rbp), %rdi
callq 0x1fe10
cmpl $0x0, %eax
je 0xe026
jmp 0xe081
movq -0x70(%rbp), %rax
movl 0x48(%rax), %eax
shrl $0x1d, %eax
andl $0x3, %eax
imull -0x4c(%rbp), %eax
movq -0x70(%rbp), %rcx
movl 0x48(%rcx), %ecx
andl $0x1fffffff, %ecx       # imm = 0x1FFFFFFF
addl %ecx, %eax
movl %eax, -0x50(%rbp)
movq -0x98(%rbp), %rax
movl -0x50(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm1
movq -0x70(%rbp), %rax
movsd 0x38(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xe07f
movq -0x70(%rbp), %rax
movsd 0x38(%rax), %xmm0
movq -0x98(%rbp), %rax
movl -0x50(%rbp), %ecx
movsd %xmm0, (%rax,%rcx,8)
jmp 0xe081
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xdfce
jmp 0xe091
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x21c0
movl $0x0, -0x38(%rbp)
cmpl $0x4, -0x38(%rbp)
jae 0xe15e
movq -0x98(%rbp), %rdi
movl -0x38(%rbp), %eax
imull -0x4c(%rbp), %eax
movl %eax, %eax
shlq $0x3, %rax
addq %rax, %rdi
movl -0x4c(%rbp), %eax
movl %eax, %esi
movl $0x8, %edx
leaq -0x33d(%rip), %rcx      # 0xdda0
callq 0x20c0
movl -0x2c(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0xe0f5
movl -0x2c(%rbp), %eax
movl %eax, -0xd4(%rbp)
jmp 0xe0fe
movl -0x4c(%rbp), %eax
movl %eax, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0xe14e
movq -0x98(%rbp), %rax
movl -0x38(%rbp), %ecx
imull -0x4c(%rbp), %ecx
addl -0x3c(%rbp), %ecx
movl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movl -0x38(%rbp), %eax
addsd -0x90(%rbp,%rax,8), %xmm0
movsd %xmm0, -0x90(%rbp,%rax,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xe10e
jmp 0xe150
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xe0ab
leaq -0x90(%rbp), %rdi
movl $0x4, %esi
leaq -0x58(%rbp), %rdx
callq 0xe5d0
movl %eax, -0x54(%rbp)
movl $0x0, -0x9c(%rbp)
movl -0x54(%rbp), %eax
movsd -0x90(%rbp,%rax,8), %xmm0
cvtsi2sdl 0x10(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jb 0xe1d2
movl -0x54(%rbp), %eax
movsd -0x90(%rbp,%rax,8), %xmm0
movl -0x58(%rbp), %eax
ucomisd -0x90(%rbp,%rax,8), %xmm0
jne 0xe1bd
jp 0xe1bd
xorl %eax, %eax
movl %eax, -0xd8(%rbp)
jmp 0xe1c6
movl -0x54(%rbp), %eax
movl %eax, -0xd8(%rbp)
movl -0xd8(%rbp), %eax
movl %eax, -0x9c(%rbp)
cmpl $0x0, -0x9c(%rbp)
je 0xe50c
movl $0x4, %edi
callq 0x22f0
movq %rax, -0xb8(%rbp)
movl -0x34(%rbp), %ecx
movq -0xb8(%rbp), %rax
movl %ecx, (%rax)
movq $0x0, -0xc8(%rbp)
movq $0x0, -0xd0(%rbp)
movq $0x0, -0xc0(%rbp)
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %esi
leaq -0x40(%rbp), %rdx
callq 0x1f480
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0xe36f
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0xe36d
movq -0x68(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movsd 0x30(%rax), %xmm0
ucomisd -0x28(%rbp), %xmm0
ja 0xe2a0
cmpl $0x0, -0x1c(%rbp)
je 0xe28c
movq -0x70(%rbp), %rdi
callq 0x1fdd0
cmpl $0x0, %eax
jne 0xe2a0
cmpl $0x0, -0x20(%rbp)
je 0xe2a5
movq -0x70(%rbp), %rdi
callq 0x1fe10
cmpl $0x0, %eax
je 0xe2a5
jmp 0xe35f
jmp 0xe2a7
movq -0xd0(%rbp), %rax
cmpq -0xc8(%rbp), %rax
jne 0xe30e
cmpq $0x0, -0xc8(%rbp)
je 0xe2d4
movq -0xc8(%rbp), %rax
shlq %rax
movq %rax, -0xe0(%rbp)
jmp 0xe2e2
movl $0x2, %eax
movq %rax, -0xe0(%rbp)
jmp 0xe2e2
movq -0xe0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rdi
movq -0xc8(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2330
movq %rax, -0xc0(%rbp)
movq -0x70(%rbp), %rax
movl 0x48(%rax), %esi
movl %esi, %ecx
andl $0x1fffffff, %ecx       # imm = 0x1FFFFFFF
movl %ecx, %edx
shrl $0x1d, %esi
andl $0x3, %esi
movl %esi, %ecx
shlq $0x22, %rdx
shlq $0x20, %rcx
orq %rcx, %rdx
cvttsd2si 0x38(%rax), %rax
movl %eax, %eax
orq %rax, %rdx
movq -0xc0(%rbp), %rax
movq -0xd0(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0xd0(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0xe35f
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xe24a
jmp 0xe36f
movq -0xc0(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movl $0x8, %edx
leaq 0x317(%rip), %rcx       # 0xe6a0
callq 0x20c0
movl $0x0, -0x3c(%rbp)
movl $0xffffffff, -0x50(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpq -0xd0(%rbp), %rax
jae 0xe411
movq -0xc0(%rbp), %rax
movl -0x38(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl -0x50(%rbp), %ecx
cmpq %rcx, %rax
je 0xe404
movq -0xc0(%rbp), %rax
movl -0x38(%rbp), %ecx
movq (%rax,%rcx,8), %rdx
movq -0xc0(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
movq -0xc0(%rbp), %rax
movl -0x38(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x50(%rbp)
jmp 0xe406
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xe3a3
movl -0x3c(%rbp), %eax
movq %rax, -0xc8(%rbp)
movq %rax, -0xd0(%rbp)
movq -0xc0(%rbp), %rdi
movl -0x3c(%rbp), %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x2330
movq %rax, -0xc0(%rbp)
movq -0xb0(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movl -0x9c(%rbp), %ecx
movq -0xa8(%rbp), %rax
movl %ecx, (%rax)
movl -0x54(%rbp), %eax
movsd -0x90(%rbp,%rax,8), %xmm0
movq -0xa8(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movl -0x58(%rbp), %eax
movsd -0x90(%rbp,%rax,8), %xmm0
movq -0xa8(%rbp), %rax
movsd %xmm0, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movq -0xa8(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0xa8(%rbp), %rax
movl $0x1, 0x1c(%rax)
movq -0xb8(%rbp), %rcx
movq -0xa8(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0xd0(%rbp), %rax
movl %eax, %ecx
movq -0xa8(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0xc0(%rbp), %rcx
movq -0xa8(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0xa8(%rbp), %rax
movq $0x0, 0x38(%rax)
cmpl $0x0, 0x20(%rbp)
jle 0xe575
movq 0x1badf(%rip), %rax     # 0x29ff8
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x34(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movl 0x10(%rax), %r8d
movsd -0x88(%rbp), %xmm0
movsd -0x80(%rbp), %xmm1
movsd -0x78(%rbp), %xmm2
movl -0x9c(%rbp), %r9d
leaq 0x15707(%rip), %rsi     # 0x23c6e
leaq 0x15769(%rip), %rdx     # 0x23cd7
movb $0x3, %al
callq 0x2290
jmp 0xe577
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xdf35
movq -0x98(%rbp), %rdi
callq 0x2060
movq -0x60(%rbp), %rdi
callq 0x2060
cmpl $0x0, 0x18(%rbp)
je 0xe5af
movq -0xb0(%rbp), %rdi
movl 0x20(%rbp), %esi
callq 0xe6e0
movq -0xb0(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nopw (%rax,%rax)