// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/jkOwnLib/gfOut.c
// Function: savePslx
static void savePslx(char *chromName, int chromSize, int chromOffset,
	struct ffAli *ali, struct dnaSeq *tSeq, struct dnaSeq *qSeq, 
	boolean isRc, enum ffStringency stringency, int minMatch, FILE *f,
	struct hash *t3Hash, boolean reportTargetStrand, boolean targetIsRc,
	struct hash *maskHash, int minIdentity, 
	boolean qIsProt, boolean tIsProt, boolean saveSeq)
/* Analyse one alignment and if it looks good enough write it out to file in
 * psl format (or pslX format - if saveSeq is TRUE).  */
{
/* This function was stolen from psLayout and slightly extensively to cope
 * with protein as well as DNA aligments. */
struct ffAli *ff, *nextFf;
struct ffAli *right = ffRightmost(ali);
DNA *needle = qSeq->dna;
DNA *hay = tSeq->dna;
int nStart = ali->nStart - needle;
int nEnd = right->nEnd - needle;
int hStart, hEnd; 
int nInsertBaseCount = 0;
int nInsertCount = 0;
int hInsertBaseCount = 0;
int hInsertCount = 0;
int matchCount = 0;
int mismatchCount = 0;
int repMatch = 0;
int countNs = 0;
DNA *np, *hp, n, h;
int blockSize;
int i;
struct trans3 *t3List = NULL;
Bits *maskBits = NULL;

if (maskHash != NULL)
    maskBits = hashMustFindVal(maskHash, tSeq->name);
if (t3Hash != NULL)
    t3List = hashMustFindVal(t3Hash, tSeq->name);
hStart = trans3GenoPos(ali->hStart, tSeq, t3List, FALSE) + chromOffset;
hEnd = trans3GenoPos(right->hEnd, tSeq, t3List, TRUE) + chromOffset;

/* Count up matches, mismatches, inserts, etc. */
for (ff = ali; ff != NULL; ff = nextFf)
    {
    nextFf = ff->right;
    blockSize = ff->nEnd - ff->nStart;
    np = ff->nStart;
    hp = ff->hStart;
    for (i=0; i<blockSize; ++i)
	{
	n = np[i];
	h = hp[i];
	if (n == 'n' || h == 'n')
	    ++countNs;
	else
	    {
	    if (n == h)
		{
		if (maskBits != NULL)
		    {
		    int seqOff = hp + i - hay;
		    if (bitReadOne(maskBits, seqOff))
		        ++repMatch;
		    else
		        ++matchCount;
		    }
		else
		    ++matchCount;
		}
	    else
		++mismatchCount;
	    }
	}
    if (nextFf != NULL)
	{
	int nhStart = trans3GenoPos(nextFf->hStart, tSeq, t3List, FALSE) + chromOffset;
	int ohEnd = trans3GenoPos(ff->hEnd, tSeq, t3List, TRUE) + chromOffset;
	int hGap = nhStart - ohEnd;
	int nGap = nextFf->nStart - ff->nEnd;

	if (nGap != 0)
	    {
	    ++nInsertCount;
	    nInsertBaseCount += nGap;
	    }
	if (hGap != 0)
	    {
	    ++hInsertCount;
	    hInsertBaseCount += hGap;
	    }
	}
    }


/* See if it looks good enough to output, and output. */
/* if (score >= minMatch) Moved to higher level */
    {
    int gaps = nInsertCount + (stringency == ffCdna ? 0: hInsertCount);
    if ((matchCount + repMatch + mismatchCount) > 0)
	{
	int id = roundingScale(1000, matchCount + repMatch - 2*gaps, matchCount + repMatch + mismatchCount);
	if (id >= minIdentity)
	    {
	    if (isRc)
		{
		int temp;
		int oSize = qSeq->size;
		temp = nStart;
		nStart = oSize - nEnd;
		nEnd = oSize - temp;
		}
	    if (targetIsRc)
		{
		int temp;
		temp = hStart;
		hStart = chromSize - hEnd;
		hEnd = chromSize - temp;
		}
	    fprintf(f, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%c",
		matchCount, mismatchCount, repMatch, countNs, nInsertCount, nInsertBaseCount, hInsertCount, hInsertBaseCount,
		(isRc ? '-' : '+'));
	    if (reportTargetStrand)
		fprintf(f, "%c", (targetIsRc ? '-' : '+') );
	    fprintf(f, "\t%s\t%d\t%d\t%d\t"
			 "%s\t%d\t%d\t%d\t%d\t",
		qSeq->name, qSeq->size, nStart, nEnd,
		chromName, chromSize, hStart, hEnd,
		ffAliCount(ali));
	    for (ff = ali; ff != NULL; ff = ff->right)
		fprintf(f, "%ld,", (long)(ff->nEnd - ff->nStart));
	    fprintf(f, "\t");
	    for (ff = ali; ff != NULL; ff = ff->right)
		fprintf(f, "%ld,", (long)(ff->nStart - needle));
	    fprintf(f, "\t");
	    for (ff = ali; ff != NULL; ff = ff->right)
		fprintf(f, "%d,", trans3GenoPos(ff->hStart, tSeq, t3List, FALSE) + chromOffset);
	    if (saveSeq)
		{
		fputc('\t', f);
		for (ff = ali; ff != NULL; ff = ff->right)
		    {
		    mustWrite(f, ff->nStart, ff->nEnd - ff->nStart);
		    fputc(',', f);
		    }
		fputc('\t', f);
		for (ff = ali; ff != NULL; ff = ff->right)
		    {
		    mustWrite(f, ff->hStart, ff->hEnd - ff->hStart);
		    fputc(',', f);
		    }
		}
	    fprintf(f, "\n");
	    if (ferror(f))
		{
		perror("");
		errAbort("Write error to .psl");
		}
	    }
	}
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movl 0x68(%rbp), %eax
movl 0x60(%rbp), %eax
movl 0x58(%rbp), %eax
movl 0x50(%rbp), %eax
movq 0x48(%rbp), %rax
movl 0x40(%rbp), %eax
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x20(%rbp)
movl %esi, -0x24(%rbp)
movl %edx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq -0x30(%rbp), %rdi
callq 0x37b90
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x60(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x6c(%rbp)
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x60(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0x70(%rbp)
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
movl $0x0, -0x90(%rbp)
movl $0x0, -0x94(%rbp)
movl $0x0, -0x98(%rbp)
movq $0x0, -0xc0(%rbp)
movq $0x0, -0xc8(%rbp)
cmpq $0x0, 0x48(%rbp)
je 0x177d5
movq 0x48(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x39590
movq %rax, -0xc8(%rbp)
cmpq $0x0, 0x30(%rbp)
je 0x177f4
movq 0x30(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x39590
movq %rax, -0xc0(%rbp)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0xc0(%rbp), %rdx
xorl %ecx, %ecx
callq 0x1a7a0
addl -0x28(%rbp), %eax
movl %eax, -0x74(%rbp)
movq -0x58(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0xc0(%rbp), %rdx
movl $0x1, %ecx
callq 0x1a7a0
addl -0x28(%rbp), %eax
movl %eax, -0x78(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x17a86
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0xb0(%rbp)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xa8(%rbp)
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
cmpl -0xb0(%rbp), %eax
jge 0x179ae
movq -0xa0(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0xa9(%rbp)
movq -0xa8(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0xaa(%rbp)
movsbl -0xa9(%rbp), %eax
cmpl $0x6e, %eax
je 0x178ef
movsbl -0xaa(%rbp), %eax
cmpl $0x6e, %eax
jne 0x17903
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x17998
movsbl -0xa9(%rbp), %eax
movsbl -0xaa(%rbp), %ecx
cmpl %ecx, %eax
jne 0x17987
cmpq $0x0, -0xc8(%rbp)
je 0x17976
movq -0xa8(%rbp), %rax
movslq -0xb4(%rbp), %rcx
addq %rcx, %rax
movq -0x68(%rbp), %rcx
subq %rcx, %rax
movl %eax, -0xcc(%rbp)
movq -0xc8(%rbp), %rdi
movl -0xcc(%rbp), %esi
callq 0x23dc0
cmpl $0x0, %eax
je 0x17965
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x17974
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x17985
movl -0x8c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
jmp 0x17996
movl -0x90(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x17998
jmp 0x1799a
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x17897
cmpq $0x0, -0x50(%rbp)
je 0x17a77
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0xc0(%rbp), %rdx
xorl %ecx, %ecx
callq 0x1a7a0
addl -0x28(%rbp), %eax
movl %eax, -0xd0(%rbp)
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0xc0(%rbp), %rdx
movl $0x1, %ecx
callq 0x1a7a0
addl -0x28(%rbp), %eax
movl %eax, -0xd4(%rbp)
movl -0xd0(%rbp), %eax
subl -0xd4(%rbp), %eax
movl %eax, -0xd8(%rbp)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x48(%rbp), %rcx
movq 0x18(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0xdc(%rbp)
cmpl $0x0, -0xdc(%rbp)
je 0x17a4b
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
movl -0xdc(%rbp), %eax
addl -0x7c(%rbp), %eax
movl %eax, -0x7c(%rbp)
cmpl $0x0, -0xd8(%rbp)
je 0x17a75
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
movl -0xd8(%rbp), %eax
addl -0x84(%rbp), %eax
movl %eax, -0x84(%rbp)
jmp 0x17a77
jmp 0x17a79
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x1783f
movl -0x80(%rbp), %eax
movl %eax, -0xf4(%rbp)
cmpl $0x1, 0x18(%rbp)
jne 0x17a9f
xorl %eax, %eax
movl %eax, -0xf8(%rbp)
jmp 0x17aab
movl -0x88(%rbp), %eax
movl %eax, -0xf8(%rbp)
movl -0xf4(%rbp), %eax
movl -0xf8(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0xe0(%rbp)
movl -0x8c(%rbp), %eax
addl -0x94(%rbp), %eax
addl -0x90(%rbp), %eax
cmpl $0x0, %eax
jle 0x17ec6
movl -0x8c(%rbp), %esi
addl -0x94(%rbp), %esi
movl -0xe0(%rbp), %eax
shll %eax
subl %eax, %esi
movl -0x8c(%rbp), %edx
addl -0x94(%rbp), %edx
addl -0x90(%rbp), %edx
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x30500
movl %eax, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
cmpl 0x50(%rbp), %eax
jl 0x17ec4
cmpl $0x0, 0x10(%rbp)
je 0x17b58
movq -0x40(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0xec(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0xe8(%rbp)
movl -0xec(%rbp), %eax
subl -0x70(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0xec(%rbp), %eax
subl -0xe8(%rbp), %eax
movl %eax, -0x70(%rbp)
cmpl $0x0, 0x40(%rbp)
je 0x17b7c
movl -0x74(%rbp), %eax
movl %eax, -0xf0(%rbp)
movl -0x24(%rbp), %eax
subl -0x78(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x24(%rbp), %eax
subl -0xf0(%rbp), %eax
movl %eax, -0x78(%rbp)
movq 0x28(%rbp), %rdi
movl -0x8c(%rbp), %edx
movl -0x90(%rbp), %ecx
movl -0x94(%rbp), %r8d
movl -0x98(%rbp), %r9d
movl -0x80(%rbp), %r14d
movl -0x7c(%rbp), %ebx
movl -0x88(%rbp), %r11d
movl -0x84(%rbp), %r10d
movl 0x10(%rbp), %r15d
movl $0x2b, %eax
movl $0x2d, %esi
cmpl $0x0, %r15d
cmovnel %esi, %eax
leaq 0xc05d7(%rip), %rsi     # 0xd81a2
movl %r14d, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movb $0x0, %al
callq 0x6a80
cmpl $0x0, 0x38(%rbp)
je 0x17c13
movq 0x28(%rbp), %rdi
movl 0x40(%rbp), %ecx
movl $0x2b, %edx
movl $0x2d, %eax
cmpl $0x0, %ecx
cmovnel %eax, %edx
leaq 0xc05ae(%rip), %rsi     # 0xd81ba
movb $0x0, %al
callq 0x6a80
movq 0x28(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x118(%rbp)
movq -0x40(%rbp), %rax
movl 0x18(%rax), %eax
movl %eax, -0x10c(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x108(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x104(%rbp)
movq -0x20(%rbp), %r14
movl -0x24(%rbp), %ebx
movl -0x74(%rbp), %eax
movl %eax, -0x100(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0xfc(%rbp)
movq -0x30(%rbp), %rdi
callq 0x37d90
movq -0x120(%rbp), %rdi
movq -0x118(%rbp), %rdx
movl -0x10c(%rbp), %ecx
movl -0x108(%rbp), %r8d
movl -0x104(%rbp), %r9d
movl -0x100(%rbp), %r11d
movl -0xfc(%rbp), %r10d
leaq 0xc0518(%rip), %rsi     # 0xd81bd
movq %r14, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movl %r10d, 0x18(%rsp)
movl %eax, 0x20(%rsp)
movb $0x0, %al
callq 0x6a80
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x17d04
movq 0x28(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
subq %rax, %rdx
leaq 0xc04eb(%rip), %rsi     # 0xd81da
movb $0x0, %al
callq 0x6a80
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x17cca
movq 0x28(%rbp), %rdi
leaq 0xcd6de(%rip), %rsi     # 0xe53ed
movb $0x0, %al
callq 0x6a80
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x17d54
movq 0x28(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rdx
movq -0x60(%rbp), %rax
subq %rax, %rdx
leaq 0xc049b(%rip), %rsi     # 0xd81da
movb $0x0, %al
callq 0x6a80
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x17d1e
movq 0x28(%rbp), %rdi
leaq 0xcd68e(%rip), %rsi     # 0xe53ed
movb $0x0, %al
callq 0x6a80
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x17dc2
movq 0x28(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x38(%rbp), %rsi
movq -0xc0(%rbp), %rdx
xorl %ecx, %ecx
callq 0x1a7a0
movq -0x128(%rbp), %rdi
movl %eax, %edx
addl -0x28(%rbp), %edx
leaq 0xc0432(%rip), %rsi     # 0xd81df
movb $0x0, %al
callq 0x6a80
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x17d6e
cmpl $0x0, 0x68(%rbp)
je 0x17e88
movq 0x28(%rbp), %rsi
movl $0x9, %edi
callq 0x6910
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x17e29
movq 0x28(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rdx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
subq %rax, %rdx
callq 0x2f8b0
movq 0x28(%rbp), %rsi
movl $0x2c, %edi
callq 0x6910
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x17de2
movq 0x28(%rbp), %rsi
movl $0x9, %edi
callq 0x6910
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x17e86
movq 0x28(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x48(%rbp), %rax
movq 0x28(%rax), %rdx
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
subq %rax, %rdx
callq 0x2f8b0
movq 0x28(%rbp), %rsi
movl $0x2c, %edi
callq 0x6910
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x17e3f
jmp 0x17e88
movq 0x28(%rbp), %rdi
leaq 0xc1186(%rip), %rsi     # 0xd9019
movb $0x0, %al
callq 0x6a80
movq 0x28(%rbp), %rdi
callq 0x6e10
cmpl $0x0, %eax
je 0x17ec2
leaq 0xcd557(%rip), %rdi     # 0xe5406
callq 0x6590
leaq 0xc0328(%rip), %rdi     # 0xd81e3
movb $0x0, %al
callq 0x35d40
jmp 0x17ec4
jmp 0x17ec6
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)