// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]oatk/path.c
// Function: get_sequence_annot_score
double *get_sequence_annot_score(hmm_annot_db_t *annot_db, asg_t *asg, int no_trn, int no_rrn, double max_eval,
        int n_core, int verbose)
{
    uint32_t i, j, k, n, n_seg, n_gene, m_gene, gid;
    uint32_t *asg_snameid_map;
    hmm_annot_t *annots, *annot;
    double *annot_score, *gene_score, *a_s;

    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);

    // calculate annotation score for each seg
    MYCALLOC(annot_score, n_seg * 4);
    MYMALLOC(gene_score, m_gene * 4);
    for (i = 0; i < n_seg; ++i) {
        annots = hmm_annot_db_index_query(annot_db, asg_snameid_map[i], &n);
        if (!annots) continue;
        
        MYBZERO(gene_score, m_gene * 4);
        for (j = 0; j < n; ++j) {
            annot = &annots[j];
            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 (gene_score[gid] < annot->score)
                gene_score[gid] = annot->score;
        }

        // sort annotation scores for each og_type
        // and get the sum annotation score
        a_s = &annot_score[i * 4];
        for (j = 0; j < 4; ++j) {
            qsort(&gene_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] += gene_score[j * m_gene + k];
        }
        
        if (verbose > 0)
            fprintf(stderr, "[M::%s] sequence %s: size, %d; mito score, %.3f; pltd score, %.3f; mini score, %.3f\n",
                    __func__, asg->seg[i].name, asg->seg[i].len, a_s[OG_MITO], a_s[OG_PLTD], a_s[OG_MINI]);
    }
    
    free(gene_score);
    free(asg_snameid_map);

    return annot_score;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
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 0xda6e
movq $0x0, -0x8(%rbp)
jmp 0xdd89
cmpl $0x0, -0x2c(%rbp)
jne 0xda7b
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, -0x58(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0xdae9
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 -0x58(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xdaac
movl -0x44(%rbp), %eax
shll $0x2, %eax
movl %eax, %eax
movl %eax, %edi
movl $0x8, %esi
callq 0x2240
movq %rax, -0x70(%rbp)
movl -0x4c(%rbp), %eax
shll $0x2, %eax
movl %eax, %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x22f0
movq %rax, -0x78(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x44(%rbp), %eax
jae 0xdd6f
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rax
movl -0x34(%rbp), %ecx
movl (%rax,%rcx,4), %esi
leaq -0x40(%rbp), %rdx
callq 0x1f480
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0xdb52
jmp 0xdd61
movq -0x78(%rbp), %rdi
movl -0x4c(%rbp), %eax
shll $0x2, %eax
movl %eax, %eax
movl %eax, %edx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x21c0
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0xdc2d
movq -0x60(%rbp), %rax
movl -0x38(%rbp), %ecx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movsd 0x30(%rax), %xmm0
ucomisd -0x28(%rbp), %xmm0
ja 0xdbc8
cmpl $0x0, -0x1c(%rbp)
je 0xdbb4
movq -0x68(%rbp), %rdi
callq 0x1fdd0
cmpl $0x0, %eax
jne 0xdbc8
cmpl $0x0, -0x20(%rbp)
je 0xdbca
movq -0x68(%rbp), %rdi
callq 0x1fe10
cmpl $0x0, %eax
je 0xdbca
jmp 0xdc1f
movq -0x68(%rbp), %rax
movl 0x48(%rax), %eax
shrl $0x1d, %eax
andl $0x3, %eax
imull -0x4c(%rbp), %eax
movq -0x68(%rbp), %rcx
movl 0x48(%rcx), %ecx
andl $0x1fffffff, %ecx       # imm = 0x1FFFFFFF
addl %ecx, %eax
movl %eax, -0x50(%rbp)
movq -0x78(%rbp), %rax
movl -0x50(%rbp), %ecx
movsd (%rax,%rcx,8), %xmm1
movq -0x68(%rbp), %rax
movsd 0x38(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xdc1d
movq -0x68(%rbp), %rax
movsd 0x38(%rax), %xmm0
movq -0x78(%rbp), %rax
movl -0x50(%rbp), %ecx
movsd %xmm0, (%rax,%rcx,8)
jmp 0xdc1f
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xdb72
movq -0x70(%rbp), %rax
movl -0x34(%rbp), %ecx
shll $0x2, %ecx
movl %ecx, %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x38(%rbp)
cmpl $0x4, -0x38(%rbp)
jae 0xdcf4
movq -0x78(%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 0x126(%rip), %rcx       # 0xdda0
callq 0x20c0
movl -0x2c(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jae 0xdc92
movl -0x2c(%rbp), %eax
movl %eax, -0x84(%rbp)
jmp 0xdc9b
movl -0x4c(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jae 0xdce4
movq -0x78(%rbp), %rax
movl -0x38(%rbp), %ecx
imull -0x4c(%rbp), %ecx
addl -0x3c(%rbp), %ecx
movl %ecx, %ecx
movsd (%rax,%rcx,8), %xmm0
movq -0x80(%rbp), %rax
movl -0x38(%rbp), %ecx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xdcab
jmp 0xdce6
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xdc4b
cmpl $0x0, -0x30(%rbp)
jle 0xdd5f
movq 0x1c2f7(%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
movq -0x80(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x80(%rbp), %rax
movsd 0x10(%rax), %xmm1
movq -0x80(%rbp), %rax
movsd 0x18(%rax), %xmm2
leaq 0x15eaf(%rip), %rsi     # 0x23c00
leaq 0x15efd(%rip), %rdx     # 0x23c55
movb $0x3, %al
callq 0x2290
jmp 0xdd61
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xdb1f
movq -0x78(%rbp), %rdi
callq 0x2060
movq -0x58(%rbp), %rdi
callq 0x2060
movq -0x70(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)