// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq %rdi, %r14
movl 0x14(%rdi), %eax
movl %eax, 0x14(%rsp)
testl %ecx, %ecx
je 0x1a413
movq %rdx, %rbx
movq 0x8(%r14), %rax
movq 0x8(%rax), %r15
leaq 0x646cd(%rip), %rdx     # 0x7ea6c
leaq 0x28(%rsp), %r12
pushq $0xb
popq %rsi
pushq $0xa
popq %rcx
movq %r12, %rdi
callq 0x1fb32
movb $0x0, 0xa(%r12)
leaq 0x646c3(%rip), %rsi     # 0x7ea82
leaq 0x6200e(%rip), %rdx     # 0x7c3d4
movq %r13, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x6a90
leaq 0x646b8(%rip), %rsi     # 0x7ea92
movq %r13, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x6a90
leaq 0x646b1(%rip), %rsi     # 0x7ea9f
movq %r13, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x6a90
leaq 0x659d9(%rip), %rsi     # 0x7fddb
leaq 0x646a6(%rip), %rdx     # 0x7eaaf
movq %r13, %rdi
xorl %eax, %eax
callq 0x6a90
movq %r14, %rdi
callq 0x1a630
movq %rax, %rbx
movq %rax, 0x28(%rsp)
pushq $0x1
popq %r14
movq %r13, 0x38(%rsp)
testq %rbx, %rbx
je 0x1a617
leaq 0x18(%rbx), %rax
movq %rbx, 0x20(%rsp)
movq (%rax), %rax
testq %rax, %rax
je 0x1a60f
movq %rax, 0x40(%rsp)
movq 0x8(%rax), %rbp
movq 0x40(%rbp), %r13
movq 0x48(%rbp), %r12
movl 0x38(%rbp), %ebx
movq %r13, %rdi
movq %r12, %rsi
movl %ebx, %edx
callq 0x1a768
movl %eax, 0x1c(%rsp)
movq %r13, %rdi
movq %r12, %rsi
movl %ebx, %edx
callq 0x1ac17
movl %eax, 0x18(%rsp)
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
xorl %r15d, %r15d
xorl %ecx, %ecx
cmpq %rax, %rbx
je 0x1a4b3
cmpb $0x2d, (%r13,%rax)
je 0x1a4a2
xorl %edx, %edx
cmpb $0x2d, (%r12,%rax)
jne 0x1a4ac
cmpl $0x1, %ecx
adcl $0x0, %r15d
movl %r14d, %edx
incq %rax
movl %edx, %ecx
jmp 0x1a48c
movq 0x8(%rbp), %rdx
movq 0x38(%rsp), %r13
movq %r13, %rdi
leaq 0x64678(%rip), %rbx     # 0x7eb3e
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6a90
movq 0x20(%rbp), %rdx
movq %r13, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6a90
movl 0x1c(%rsp), %r12d
cvtsi2sd %r12d, %xmm0
mulsd 0x62ccd(%rip), %xmm0    # 0x7d1c0
cvtsi2sdl 0x38(%rbp), %xmm1
divsd %xmm1, %xmm0
movq %r13, %rdi
leaq 0x6463c(%rip), %rsi     # 0x7eb42
movb $0x1, %al
callq 0x6a90
movl 0x38(%rbp), %edx
movq %r13, %rdi
leaq 0x62d64(%rip), %rbx     # 0x7d27e
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6a90
movl 0x38(%rbp), %edx
movl 0x18(%rsp), %eax
addl %r12d, %eax
subl %eax, %edx
movq %r13, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6a90
movq %r13, %rdi
movq %rbx, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x6a90
cmpb $0x2d, 0x18(%rbp)
jne 0x1a58d
movl 0x10(%rbp), %eax
movl %eax, 0x10(%rsp)
movl 0x14(%rbp), %eax
movl %eax, 0xc(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movl 0x14(%rsp), %edx
callq 0x20d61
movl 0x10(%rsp), %edx
incl %edx
movq %r13, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6a90
movl 0xc(%rsp), %edx
jmp 0x1a5a2
movl 0x10(%rbp), %edx
incl %edx
movq %r13, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6a90
movl 0x14(%rbp), %edx
movq %r13, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6a90
movq 0x20(%rsp), %rbx
movl 0x10(%rbx), %edx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x1ac47
movl 0x34(%rbp), %edi
callq 0x1ab3e
movq %r13, %rdi
leaq 0x64574(%rip), %rsi     # 0x7eb48
movb $0x1, %al
callq 0x6a90
cvtsi2sdl 0x34(%rbp), %xmm0
mulsd 0x637b8(%rip), %xmm0    # 0x7dda0
addsd 0x637a8(%rip), %xmm0    # 0x7dd98
cvttsd2si %xmm0, %edx
movq %r13, %rdi
leaq 0x64551(%rip), %rsi     # 0x7eb4f
xorl %eax, %eax
callq 0x6a90
movq 0x40(%rsp), %rax
jmp 0x1a43e
movq (%rbx), %rbx
jmp 0x1a42c
leaq 0x28(%rsp), %rdi
callq 0x1aacd
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq