// File: /workspace/github_c_makefile_star2_O2/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, (%rsp)
movl %r9d, 0xc(%rsp)
movl %r8d, 0x8(%rsp)
movq %rcx, %r12
movq %rdx, 0x28(%rsp)
movq %rsi, %r13
movq %rdi, 0x10(%rsp)
pushq $0x6
popq %rsi
movq %r13, %rdi
callq 0x4421
leaq 0x34(%rsp), %r14
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x468f
movsd (%rsp), %xmm1
movq %rax, %r12
movl (%r14), %esi
addq $0x48, %r12
xorl %ebp, %ebp
movq %rsi, 0x18(%rsp)
cmpq %rsi, %rbp
jae 0x4b17
movl (%r12), %r13d
movl %r13d, %eax
shrl $0x1d, %eax
andl $0x3, %eax
cmpl 0x80(%rsp), %eax
jne 0x4b0b
movsd -0x18(%r12), %xmm0
ucomisd %xmm1, %xmm0
ja 0x4b0b
movl -0x30(%r12), %r15d
movl -0x2c(%r12), %ebx
movl %ebx, %r14d
subl %r15d, %r14d
jb 0x4b0b
movsd -0x10(%r12), %xmm0
callq 0x20e0
movq 0x18(%rsp), %rsi
movq %rax, %r8
movl $0x3e8, %eax            # imm = 0x3E8
cmpl %eax, %r8d
cmovgel %eax, %r8d
movl 0x8(%rsp), %eax
movl %eax, %r9d
subl %ebx, %r9d
movl %eax, %r10d
subl %r15d, %r10d
cmpl $0x0, 0x70(%rsp)
cmovel %ebx, %r10d
cmovel %r15d, %r9d
movl 0xc(%rsp), %eax
subl %eax, %r9d
movl $0x0, %ecx
cmovbl %ecx, %r9d
subl %eax, %r10d
cmovbl %ecx, %r10d
movl %r10d, %eax
subl %r9d, %eax
cvtsi2sd %rax, %xmm0
cvtsi2sd %r14, %xmm1
mulsd 0x1b42(%rip), %xmm1     # 0x6580
ucomisd %xmm0, %xmm1
movsd (%rsp), %xmm1
ja 0x4b0b
movl %r13d, %eax
shrl $0x1f, %eax
xorl %r14d, %r14d
testl %r13d, %r13d
setns %r14b
cmpl $0x0, 0x70(%rsp)
movq -0x48(%r12), %r11
cmovel %eax, %r14d
movq 0x10(%rsp), %rdi
movq (%rdi), %rcx
movq 0x10(%rdi), %rax
cmpq 0x8(%rdi), %rcx
jne 0x4acd
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rdi)
shlq $0x5, %rsi
movq %rax, %rdi
movq %r8, %rbx
movl %r9d, %r15d
movl %r10d, %r13d
movq %r11, 0x20(%rsp)
callq 0x22c0
movq 0x20(%rsp), %r11
movl %r13d, %r10d
movl %r15d, %r9d
movq %rbx, %r8
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdi
movsd (%rsp), %xmm1
movq %rax, 0x10(%rdi)
movq (%rdi), %rcx
movl 0x78(%rsp), %edx
addl %edx, %r9d
addl %edx, %r10d
addb %r14b, %r14b
addb $0x2b, %r14b
leaq 0x1(%rcx), %rdx
movq %rdx, (%rdi)
shlq $0x5, %rcx
movq 0x28(%rsp), %rdx
movq %rdx, (%rax,%rcx)
movq %r11, 0x8(%rax,%rcx)
movb %r14b, 0x10(%rax,%rcx)
movl %r9d, 0x14(%rax,%rcx)
movl %r10d, 0x18(%rax,%rcx)
movl %r8d, 0x1c(%rax,%rcx)
incq %rbp
addq $0x50, %r12
jmp 0x4988
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq