// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
movq 0x8(%rdi), %rax
movq 0x8(%rax), %r12
movl 0x14(%rdi), %eax
movl %eax, 0x18(%rsp)
movq $0x0, 0x30(%rsp)
testl %ecx, %ecx
je 0x1dad6
movq %rdx, %r15
leaq 0x72024(%rip), %rdx     # 0x8fa7c
leaq 0x3c(%rsp), %r13
movl $0xb, %esi
movl $0xa, %ecx
movq %r13, %rdi
callq 0x23c98
movb $0x0, 0xa(%r13)
leaq 0x72017(%rip), %rsi     # 0x8fa92
leaq 0x6f952(%rip), %rdx     # 0x8d3d4
movq 0x10(%rsp), %rdi
movq %r13, %rcx
movq 0x10(%rsp), %rbx
xorl %eax, %eax
callq 0x6a90
leaq 0x72005(%rip), %rsi     # 0x8faa2
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x6a90
leaq 0x71ffe(%rip), %rsi     # 0x8faaf
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x6a90
leaq 0x73326(%rip), %rsi     # 0x90deb
leaq 0x71ff3(%rip), %rdx     # 0x8fabf
movq %rbx, %rdi
xorl %eax, %eax
callq 0x6a90
movq %r14, %rdi
callq 0x1dd34
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x1dd1b
movq %rax, %rbx
movq 0x18(%rbx), %r15
testq %r15, %r15
je 0x1dd0f
movq %rbx, 0x20(%rsp)
movq %r15, 0x28(%rsp)
movq 0x8(%r15), %rbp
movq 0x40(%rbp), %r14
movq 0x48(%rbp), %r13
movslq 0x38(%rbp), %r15
movq %r14, %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0x1de49
movl %eax, 0x1c(%rsp)
xorl %r12d, %r12d
movl $0x0, %ebx
testq %r15, %r15
jle 0x1db5a
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, %r15
jne 0x1db39
testl %r15d, %r15d
jle 0x1db8d
xorl %eax, %eax
xorl %ecx, %ecx
xorl %r12d, %r12d
cmpb $0x2d, (%r14,%rax)
je 0x1db77
xorl %edx, %edx
cmpb $0x2d, (%r13,%rax)
jne 0x1db83
cmpl $0x1, %ecx
adcl $0x0, %r12d
movl $0x1, %edx
incq %rax
movl %edx, %ecx
cmpq %rax, %r15
jne 0x1db66
movq 0x8(%rbp), %rdx
movq 0x10(%rsp), %r14
movq %r14, %rdi
leaq 0x71fae(%rip), %r15     # 0x8fb4e
movq %r15, %rsi
xorl %eax, %eax
callq 0x6a90
movq 0x20(%rbp), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x6a90
movl 0x1c(%rsp), %r13d
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
mulsd 0x70610(%rip), %xmm0    # 0x8e1e0
cvtsi2sdl 0x38(%rbp), %xmm1
divsd %xmm1, %xmm0
movq %r14, %rdi
leaq 0x71f6f(%rip), %rsi     # 0x8fb52
movb $0x1, %al
callq 0x6a90
movl 0x38(%rbp), %edx
movq %r14, %rdi
leaq 0x706a7(%rip), %r15     # 0x8e29e
movq %r15, %rsi
xorl %eax, %eax
callq 0x6a90
movl 0x38(%rbp), %edx
addl %r13d, %ebx
subl %ebx, %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x6a90
movq %r14, %rdi
movq %r15, %rsi
movl %r12d, %edx
xorl %eax, %eax
callq 0x6a90
cmpb $0x2d, 0x18(%rbp)
jne 0x1dc66
movl 0x10(%rbp), %eax
movl %eax, 0x3c(%rsp)
movl 0x14(%rbp), %eax
movl %eax, 0xc(%rsp)
leaq 0x3c(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movl 0x18(%rsp), %edx
callq 0x25145
movl 0x3c(%rsp), %edx
incl %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x6a90
movl 0xc(%rsp), %edx
jmp 0x1dc7b
movl 0x10(%rbp), %edx
incl %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x6a90
movl 0x14(%rbp), %edx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x6a90
movq 0x20(%rsp), %rbx
movl 0x10(%rbx), %edx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x1e2db
movq 0x28(%rsp), %r15
xorps %xmm0, %xmm0
cvtsi2sdl 0x34(%rbp), %xmm0
mulsd 0x71108(%rip), %xmm0    # 0x8edb8
mulsd 0x71108(%rip), %xmm0    # 0x8edc0
callq 0x6d90
mulsd 0x71103(%rip), %xmm0    # 0x8edc8
movq %r14, %rdi
leaq 0x71e89(%rip), %rsi     # 0x8fb58
movb $0x1, %al
callq 0x6a90
xorps %xmm0, %xmm0
cvtsi2sdl 0x34(%rbp), %xmm0
mulsd 0x710ca(%rip), %xmm0    # 0x8edb0
addsd 0x710ba(%rip), %xmm0    # 0x8eda8
cvttsd2si %xmm0, %edx
movq %r14, %rdi
leaq 0x71e63(%rip), %rsi     # 0x8fb5f
xorl %eax, %eax
callq 0x6a90
movq (%r15), %r15
testq %r15, %r15
jne 0x1db01
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x1daef
leaq 0x30(%rsp), %rdi
callq 0x1e1a1
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq