// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/lib/blastOut.c
// Function: tabBlastOut
static void tabBlastOut(struct axtBundle *abList, int queryIx, boolean isProt, 
	FILE *f, char *databaseName, int databaseSeqCount, 
	double databaseLetterCount, char *ourId, boolean withComment)
/* Do NCBI tabular blast output. */
{
char *queryName = abList->axtList->qName;
int querySize = abList->qSize;
struct targetHits *targetList = NULL, *target;

if (withComment)
    {
    // use date from CVS, unless checked out with -kk, then ignore.
    char * rcsDate = "$Date: 2009/02/26 00:05:49 $";
    char dateStamp[11];
    if (strlen(rcsDate) > 17)
        safencpy(dateStamp, sizeof(dateStamp), rcsDate+7, 10);
    else
        safecpy(dateStamp, sizeof(dateStamp), "");
    dateStamp[10] = 0;
    fprintf(f, "# BLAT %s [%s]\n", gfVersion, dateStamp);
    fprintf(f, "# Query: %s\n", queryName);
    fprintf(f, "# Database: %s\n", databaseName);
    fprintf(f, "%s\n", 
    	"# Fields: Query id, Subject id, % identity, alignment length, "
	"mismatches, gap openings, q. start, q. end, s. start, s. end, "
	"e-value, bit score");
    }

/* Print out details on each target. */
targetList = bundleIntoTargets(abList);
for (target = targetList; target != NULL; target = target->next)
    {
    struct axtRef *ref;
    for (ref = target->axtList; ref != NULL; ref = ref->next)
        {
	struct axt *axt = ref->axt;
	int matches = countMatches(axt->qSym, axt->tSym, axt->symCount);
	int gaps = countGaps(axt->qSym, axt->tSym, axt->symCount);
	int gapOpens = countGapOpens(axt->qSym, axt->tSym, axt->symCount);
	fprintf(f, "%s\t", axt->qName);
	fprintf(f, "%s\t", axt->tName);
	fprintf(f, "%.2f\t", 100.0 * matches/axt->symCount);
	fprintf(f, "%d\t", axt->symCount);
	fprintf(f, "%d\t", axt->symCount - matches - gaps);
	fprintf(f, "%d\t", gapOpens);
	if (axt->qStrand == '-')
	    {
	    int s = axt->qStart, e = axt->qEnd;
	    reverseIntRange(&s, &e, querySize);
	    fprintf(f, "%d\t", s+1);
	    fprintf(f, "%d\t", e);
	    printAxtTargetBlastTab(f, axt, target->size);
	    }
	else
	    {
	    fprintf(f, "%d\t", axt->qStart + 1);
	    fprintf(f, "%d\t", axt->qEnd);
	    printAxtTargetBlastTab(f, axt, target->size);
	    }
	fprintf(f, "%3.1e\t", blastzScoreToNcbiExpectation(axt->score));
	fprintf(f, "%d.0\n", blastzScoreToNcbiBits(axt->score));
	}
    }

/* Cleanup time. */
targetHitsFreeList(&targetList);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, 0x8(%rsp)
movq %rdi, %r14
movl 0x14(%rdi), %eax
movl %eax, 0x10(%rsp)
testl %ecx, %ecx
je 0x1de92
movq %rdx, %r15
movq 0x8(%r14), %rax
movq 0x8(%rax), %r12
leaq 0x71d2a(%rip), %rdx     # 0x8fb3c
leaq 0x28(%rsp), %r13
movl $0xb, %esi
movl $0xa, %ecx
movq %r13, %rdi
callq 0x23fb3
movb $0x0, 0xa(%r13)
leaq 0x71d1d(%rip), %rsi     # 0x8fb52
leaq 0x6f598(%rip), %rdx     # 0x8d3d4
movq 0x8(%rsp), %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x6a90
leaq 0x71d10(%rip), %rsi     # 0x8fb62
movq 0x8(%rsp), %rdi
movq %r12, %rdx
movq 0x8(%rsp), %rbx
xorl %eax, %eax
callq 0x6a90
leaq 0x71d02(%rip), %rsi     # 0x8fb6f
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x6a90
leaq 0x7305a(%rip), %rsi     # 0x90edb
leaq 0x71cf7(%rip), %rdx     # 0x8fb7f
movq %rbx, %rdi
xorl %eax, %eax
callq 0x6a90
movq %r14, %rdi
callq 0x1e0e6
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x1e0cd
movq %rax, %rbx
movq 0x18(%rbx), %r15
testq %r15, %r15
je 0x1e0c1
movq %rbx, 0x18(%rsp)
movq 0x8(%r15), %rbp
movq 0x40(%rbp), %r14
movq 0x48(%rbp), %r13
movslq 0x38(%rbp), %r12
movq %r14, %rdi
movq %r13, %rsi
movl %r12d, %edx
callq 0x1e20b
movl %eax, 0x14(%rsp)
testq %r12, %r12
movq %r15, 0x20(%rsp)
jle 0x1df3e
xorl %eax, %eax
xorl %ebx, %ebx
xorl %ecx, %ecx
cmpb $0x2d, (%r14,%rax)
sete %cl
addl %ebx, %ecx
xorl %ebx, %ebx
cmpb $0x2d, (%r13,%rax)
sete %bl
addl %ecx, %ebx
incq %rax
cmpq %rax, %r12
jne 0x1deed
xorl %eax, %eax
xorl %ecx, %ecx
xorl %r15d, %r15d
cmpb $0x2d, (%r14,%rax)
je 0x1df26
xorl %edx, %edx
cmpb $0x2d, (%r13,%rax)
jne 0x1df32
cmpl $0x1, %ecx
adcl $0x0, %r15d
movl $0x1, %edx
incq %rax
movl %edx, %ecx
cmpq %rax, %r12
jne 0x1df15
jmp 0x1df43
xorl %ebx, %ebx
xorl %r15d, %r15d
movq 0x8(%rbp), %rdx
movq 0x8(%rsp), %r14
movq %r14, %rdi
leaq 0x71cb8(%rip), %r12     # 0x8fc0e
movq %r12, %rsi
xorl %eax, %eax
callq 0x6a90
movq 0x20(%rbp), %rdx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x6a90
movl 0x14(%rsp), %r13d
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
mulsd 0x7029a(%rip), %xmm0    # 0x8e220
cvtsi2sdl 0x38(%rbp), %xmm1
divsd %xmm1, %xmm0
movq %r14, %rdi
leaq 0x71c79(%rip), %rsi     # 0x8fc12
movb $0x1, %al
callq 0x6a90
movl 0x38(%rbp), %edx
movq %r14, %rdi
leaq 0x70331(%rip), %r12     # 0x8e2de
movq %r12, %rsi
xorl %eax, %eax
callq 0x6a90
movl 0x38(%rbp), %edx
addl %r13d, %ebx
subl %ebx, %edx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x6a90
movq %r14, %rdi
movq %r12, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x6a90
cmpb $0x2d, 0x18(%rbp)
jne 0x1e018
movl 0x10(%rbp), %eax
movl %eax, 0x4(%rsp)
movl 0x14(%rbp), %eax
movl %eax, (%rsp)
leaq 0x4(%rsp), %rdi
movq %rsp, %rsi
movl 0x10(%rsp), %edx
callq 0x25472
movl 0x4(%rsp), %edx
incl %edx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x6a90
movl (%rsp), %edx
jmp 0x1e02d
movl 0x10(%rbp), %edx
incl %edx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x6a90
movl 0x14(%rbp), %edx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x6a90
movq 0x18(%rsp), %rbx
movl 0x10(%rbx), %edx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1e6d7
movq 0x20(%rsp), %r15
xorps %xmm0, %xmm0
cvtsi2sdl 0x34(%rbp), %xmm0
mulsd 0x70e16(%rip), %xmm0    # 0x8ee78
mulsd 0x70e16(%rip), %xmm0    # 0x8ee80
callq 0x6d90
mulsd 0x70e11(%rip), %xmm0    # 0x8ee88
movq %r14, %rdi
leaq 0x71b97(%rip), %rsi     # 0x8fc18
movb $0x1, %al
callq 0x6a90
xorps %xmm0, %xmm0
cvtsi2sdl 0x34(%rbp), %xmm0
mulsd 0x70dd8(%rip), %xmm0    # 0x8ee70
addsd 0x70dc8(%rip), %xmm0    # 0x8ee68
cvttsd2si %xmm0, %edx
movq %r14, %rdi
leaq 0x71b71(%rip), %rsi     # 0x8fc1f
xorl %eax, %eax
callq 0x6a90
movq (%r15), %r15
testq %r15, %r15
jne 0x1debd
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x1deab
leaq 0x28(%rsp), %rdi
callq 0x1e59d
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq