// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %rdx, 0x30(%rsp)
movq %rsi, %r12
movq %rdi, %rbx
movq %rsi, %rdi
movl $0x6, %esi
callq 0x4955
movq %r12, %rdi
movq %r13, %rsi
callq 0x478d
cmpl %eax, 0x44(%r12)
movq %rbx, 0x28(%rsp)
jbe 0x4f88
movq 0x48(%r12), %rcx
movl %eax, %eax
movq (%rcx,%rax,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,4), %rsi
shlq $0x4, %rsi
addq 0x10(%r12), %rsi
jmp 0x4f8c
xorl %eax, %eax
xorl %esi, %esi
testl %eax, %eax
movsd (%rsp), %xmm1
je 0x5144
movl 0x80(%rsp), %edi
movl %eax, %eax
shlq $0x4, %rax
leaq (%rax,%rax,4), %r8
xorl %ebp, %ebp
movq %rsi, 0x18(%rsp)
movq %r8, 0x10(%rsp)
movl 0x48(%rsi,%rbp), %r12d
movl %r12d, %eax
shrl $0x1d, %eax
andl $0x3, %eax
cmpl %edi, %eax
jne 0x5137
movsd 0x30(%rsi,%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x5137
movl 0x18(%rsi,%rbp), %r13d
movl 0x1c(%rsi,%rbp), %r15d
movl %r15d, %ebx
subl %r13d, %ebx
jb 0x5137
movsd 0x38(%rsi,%rbp), %xmm0
callq 0x20e0
movq 0x10(%rsp), %r8
movl 0x80(%rsp), %edi
movq 0x18(%rsp), %rsi
movq %rax, %r9
movl $0x3e8, %eax            # imm = 0x3E8
cmpl %eax, %r9d
cmovgel %eax, %r9d
movl 0x8(%rsp), %r14d
movl %r14d, %r10d
subl %r15d, %r10d
subl %r13d, %r14d
cmpl $0x0, 0x70(%rsp)
cmovel %r15d, %r14d
cmovel %r13d, %r10d
movl 0xc(%rsp), %eax
subl %eax, %r10d
movl $0x0, %ecx
cmovbl %ecx, %r10d
subl %eax, %r14d
cmovbl %ecx, %r14d
movl %r14d, %eax
subl %r10d, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rbx, %xmm1
mulsd 0x2513(%rip), %xmm1     # 0x7580
ucomisd %xmm0, %xmm1
movsd (%rsp), %xmm1
ja 0x5137
movl %r12d, %eax
shrl $0x1f, %eax
xorl %ebx, %ebx
testl %r12d, %r12d
setns %bl
cmpl $0x0, 0x70(%rsp)
cmovel %eax, %ebx
movq (%rsi,%rbp), %r11
movq 0x28(%rsp), %r15
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
jne 0x50f5
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x5, %rsi
movq %r9, %r13
movl %r10d, %r12d
movq %r11, 0x20(%rsp)
callq 0x22c0
movq 0x20(%rsp), %r11
movl %r12d, %r10d
movq %r13, %r9
movq 0x10(%rsp), %r8
movl 0x80(%rsp), %edi
movq 0x18(%rsp), %rsi
movsd (%rsp), %xmm1
movq %rax, 0x10(%r15)
movl 0x78(%rsp), %eax
addl %eax, %r10d
addl %eax, %r14d
addb %bl, %bl
addb $0x2b, %bl
movq (%r15), %rax
movq 0x10(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r15)
shlq $0x5, %rax
movq 0x30(%rsp), %rdx
movq %rdx, (%rcx,%rax)
movq %r11, 0x8(%rcx,%rax)
movb %bl, 0x10(%rcx,%rax)
movl %r10d, 0x14(%rcx,%rax)
movl %r14d, 0x18(%rcx,%rax)
movl %r9d, 0x1c(%rcx,%rax)
addq $0x50, %rbp
cmpq %rbp, %r8
jne 0x4fb6
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq