// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]oatk/hmmannot.c
// Function: hmm_annot_bed6_sname_add
void hmm_annot_bed6_sname_add(hmm_annot_bed6_db_t *annots, hmm_annot_db_t *annot_db, char *cname, 
        char *sname, uint32_t len, uint32_t beg, int rev, uint32_t offset, OG_TYPE_t og_type, double max_evalue)
{
    uint32_t i, n_annot, alifrom, alito, alilen, strand;
    int score;
    hmm_annot_t *annot;
    hmm_annot_db_sort(annot_db, ORDER_SID_CO);
    annot = hmm_annot_db_sname_query(annot_db, sname, &n_annot);
    for (i = 0; i < n_annot; ++i) {
        if (annot[i].og_type != (uint32_t) og_type ||
                annot[i].evalue > max_evalue) continue;
        alifrom = annot[i].alifrom;
        alito = annot[i].alito;
        if (alifrom > alito) continue; // this should never happend unless nhmmer bug
        alilen = alito - alifrom;
        strand = annot[i].strand;
        score = lround(annot[i].score);
        score = MIN(score, MAX_BED_SCORE);
        if (rev) {
            SWAP(alifrom, alito);
            alifrom = len - alifrom;
            alito = len - alito;
            strand = !strand;
        }
        alifrom = MAX(alifrom, beg);
        alito = MAX(alito, beg);
        alifrom -= beg;
        alito -= beg;
        // for annotation clipped at the ends
        // keep it only when at least [half] the sequence retained
        if ((alito - alifrom) < (double) alilen * .5)
            continue; 
        alifrom += offset;
        alito += offset;
            
        hmm_annot_bed6_t bed6 = {cname, annot[i].gname, strand? '-' : '+', alifrom, alito, score};
        kv_push(hmm_annot_bed6_t, *annots, bed6);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movsd %xmm0, 0x30(%rsp)
movl %r9d, 0x14(%rsp)
movl %r8d, 0x10(%rsp)
movq %rcx, %r13
movq %rdx, 0x28(%rsp)
movq %rsi, %r12
movq %rdi, 0x20(%rsp)
movq %rsi, %rdi
movl $0x6, %esi
callq 0x4ac1
movq %r12, %rdi
movq %r13, %rsi
callq 0x4906
cmpl %eax, 0x44(%r12)
jbe 0x52be
movq 0x48(%r12), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0x52be
movl 0x80(%rsp), %esi
movq 0x10(%r12), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,4), %rdx
shlq $0x4, %rdx
leaq (%rdx,%rcx), %r14
addq $0x48, %r14
shlq $0x4, %rax
leaq (%rax,%rax,4), %rdi
xorl %ebp, %ebp
movq %rdi, 0x18(%rsp)
movl (%r14,%rbp), %r12d
movl %r12d, %eax
shrl $0x1d, %eax
andl $0x3, %eax
cmpl %esi, %eax
jne 0x52b1
movsd -0x18(%r14,%rbp), %xmm0
ucomisd 0x30(%rsp), %xmm0
ja 0x52b1
movl -0x30(%r14,%rbp), %r15d
movl -0x2c(%r14,%rbp), %r13d
movl %r13d, %ebx
subl %r15d, %ebx
jb 0x52b1
movsd -0x10(%r14,%rbp), %xmm0
callq 0x20e0
movq 0x18(%rsp), %rdi
movl 0x80(%rsp), %esi
movq %rax, %r8
movl $0x3e8, %eax            # imm = 0x3E8
cmpl %eax, %r8d
cmovgel %eax, %r8d
movl 0x10(%rsp), %eax
movl %eax, %r9d
subl %r13d, %r9d
movl %eax, %r10d
subl %r15d, %r10d
cmpl $0x0, 0x70(%rsp)
cmovel %r13d, %r10d
cmovel %r15d, %r9d
movl 0x14(%rsp), %eax
subl %eax, %r9d
movl $0x0, %ecx
cmovbl %ecx, %r9d
subl %eax, %r10d
cmovbl %ecx, %r10d
movl %r10d, %eax
subl %r9d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rbx, %xmm1
mulsd 0x238e(%rip), %xmm1     # 0x7580
ucomisd %xmm0, %xmm1
ja 0x52b1
movl %r12d, %eax
shrl $0x1f, %eax
xorl %ebx, %ebx
testl %r12d, %r12d
setns %bl
cmpl $0x0, 0x70(%rsp)
movq -0x48(%r14,%rbp), %r12
cmovel %eax, %ebx
movq 0x20(%rsp), %r15
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0x5276
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x5, %rsi
movq %rax, %rdi
movq %r8, %r13
movl %r9d, 0x8(%rsp)
movl %r10d, 0xc(%rsp)
callq 0x22c0
movl 0xc(%rsp), %r10d
movl 0x8(%rsp), %r9d
movq %r13, %r8
movq 0x18(%rsp), %rdi
movl 0x80(%rsp), %esi
movq %rax, 0x10(%r15)
movq (%r15), %rcx
movl 0x78(%rsp), %edx
addl %edx, %r9d
addl %edx, %r10d
addb %bl, %bl
addb $0x2b, %bl
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
shlq $0x5, %rcx
movq 0x28(%rsp), %rdx
movq %rdx, (%rax,%rcx)
movq %r12, 0x8(%rax,%rcx)
movb %bl, 0x10(%rax,%rcx)
movl %r9d, 0x14(%rax,%rcx)
movl %r10d, 0x18(%rax,%rcx)
movl %r8d, 0x1c(%rax,%rcx)
addq $0x50, %rbp
cmpq %rbp, %rdi
jne 0x513b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq