// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/lib/psl.c
// Function: pslFromAlign
struct psl* pslFromAlign(char *qName, int qSize, int qStart, int qEnd, char *qString,
                         char *tName, int tSize, int tStart, int tEnd, char *tString,
                         char* strand, unsigned options)
/* Create a PSL from an alignment.  Options PSL_IS_SOFTMASK if lower case
 * bases indicate repeat masking.  Returns NULL if alignment is empty after
 * triming leading and trailing indels.*/
{
/* Note, the unit tests for these programs exercise this function:
 *   hg/embossToPsl
 *   hg/mouseStuff/axtToPsl
 *   hg/spideyToPsl
 *   utils/est2genomeToPsl
 */

int blockSpace = 16;
struct psl* psl = NULL;
int aliSize = strlen(qString);
boolean eitherInsert = FALSE;	/* True if either in insert state. */
int i, qs,qe,ts,te;
char prevQ = '\0',  prevT = '\0';
AllocVar(psl);

if (strlen(tString) != aliSize)
    errAbort("query and target alignment strings are different lengths");

psl = pslNew(qName, qSize, qStart, qEnd, tName, tSize, tStart, tEnd,
             strand, blockSpace, 0);
trimAlignment(psl, &qString, &tString, &aliSize);

/* Don't create if either query or target is zero length after trim */
 if ((psl->qStart == psl->qEnd) || (psl->tStart == psl->tEnd))
     {
     pslFree(&psl);
     return NULL;
     }

/* Get range of alignment in strand-specified coordinates */
qs = psl->qStart;
qe = psl->qEnd;
if (strand[0] == '-')
    reverseIntRange(&qs, &qe, psl->qSize);
ts = psl->tStart;
te = psl->tEnd;
if (strand[1] == '-')
    reverseIntRange(&ts, &te, psl->tSize);

eitherInsert = FALSE;
qe = qs;  /* current block coords */
te = ts;
for (i=0; i<aliSize; ++i)
    {
    char q = qString[i];
    char t = tString[i];
    if (isDelChar(q) && isDelChar(t))
        {
        continue; /* nothing in this column, just ignore it */
        }
    else if (isDelChar(q) || isDelChar(t))
        {
        /* insert in one of the columns */
	if (!eitherInsert)
	    {
            /* end of a block */
            addBlock(psl, qs, qe, ts, te, &blockSpace);
	    eitherInsert = TRUE;
	    }
	if (!isDelChar(q))
            qe += 1;
	if (!isDelChar(t))
            te += 1;
	}
    else
        {
        /* columns aligned */
	if (eitherInsert)
	    {
            /* start new block */
	    qs = qe;
	    ts = te;
	    eitherInsert = FALSE;
	    }
	qe += 1;
	te += 1;
	}
    accumCounts(psl, prevQ, prevT, q, t, options);
    prevQ = q; /* will not include skipped empty columns */
    prevT = t;
    }
addBlock(psl, qs, qe, ts, te, &blockSpace);
return psl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x28(%rsp)
movq %r8, %rbx
movl %ecx, 0x14(%rsp)
movl %edx, %r13d
movl %esi, %r12d
movq %rdi, %rbp
movq 0x98(%rsp), %r14
movl $0x10, 0x34(%rsp)
movq $0x0, 0x20(%rsp)
movq %r8, %rdi
callq 0x62d0
movq %rax, %r15
movl $0x88, %edi
callq 0x2dc95
movq %rax, 0x20(%rsp)
movq %r14, %rdi
callq 0x62d0
movslq %r15d, %rcx
cmpq %rcx, %rax
je 0x39524
leaq 0x5ab43(%rip), %rdi     # 0x94060
xorl %eax, %eax
callq 0x26b6f
subq $0x8, %rsp
movq %rbp, %rdi
movl %r12d, %esi
movl %r13d, %edx
movl 0x1c(%rsp), %ecx
movq 0x30(%rsp), %r8
movl 0x88(%rsp), %r9d
pushq $0x0
pushq $0x10
movq 0xb8(%rsp), %r12
pushq %r12
movl 0xb0(%rsp), %eax
pushq %rax
movl 0xb0(%rsp), %eax
pushq %rax
callq 0x399ef
addq $0x30, %rsp
movq %rax, 0x20(%rsp)
testl %r15d, %r15d
jle 0x39610
leaq 0x54(%rax), %rdx
leaq 0x3c(%rax), %rsi
movl %r15d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rbx,%rcx), %rdi
addq %r14, %rcx
movabsq $0x4000000010003, %r8   # imm = 0x4000000010003
movzbl (%rbx), %r9d
addl $-0x2d, %r9d
cmpl $0x32, %r9d
ja 0x395df
btq %r9, %r8
jae 0x395df
movzbl (%r14), %r9d
addl $-0x2d, %r9d
movq %rdx, %r10
cmpl $0x32, %r9d
ja 0x395c7
btq %r9, %r8
movq %rdx, %r10
jb 0x395ca
incl (%r10)
incq %rbx
incq %r14
leal -0x1(%r15), %r9d
cmpl $0x1, %r15d
movl %r9d, %r15d
jg 0x39599
jmp 0x39607
movzbl (%r14), %r10d
addl $-0x2d, %r10d
cmpl $0x32, %r10d
ja 0x39610
btq %r10, %r8
jae 0x39610
movq %rsi, %r10
cmpl $0x32, %r9d
ja 0x395c7
btq %r9, %r8
movq %rsi, %r10
jb 0x395ad
jmp 0x395c7
xorl %r15d, %r15d
movq %rdi, %rbx
movq %rcx, %r14
testl %r15d, %r15d
jle 0x3969d
leaq 0x58(%rax), %rcx
movq %rax, %rdx
addq $0x40, %rdx
movl %r15d, %r15d
movabsq $0x4000000010003, %rsi  # imm = 0x4000000010003
movzbl -0x1(%rbx,%r15), %edi
addl $-0x2d, %edi
cmpl $0x32, %edi
ja 0x39671
btq %rdi, %rsi
jae 0x39671
movzbl -0x1(%r14,%r15), %edi
addl $-0x2d, %edi
movq %rcx, %r8
cmpl $0x32, %edi
ja 0x3965f
btq %rdi, %rsi
movq %rcx, %r8
jb 0x39662
decl (%r8)
decq %r15
leaq 0x1(%r15), %rdi
cmpq $0x1, %rdi
jg 0x39631
jmp 0x3969a
movzbl -0x1(%r14,%r15), %r8d
addl $-0x2d, %r8d
cmpl $0x32, %r8d
ja 0x3969d
btq %r8, %rsi
jae 0x3969d
movq %rdx, %r8
cmpl $0x32, %edi
ja 0x3965f
btq %rdi, %rsi
movq %rdx, %r8
jb 0x39645
jmp 0x3965f
xorl %r15d, %r15d
movl 0x3c(%rax), %ecx
movl 0x40(%rax), %edx
cmpl %edx, %ecx
je 0x396af
movl 0x54(%rax), %esi
cmpl 0x58(%rax), %esi
jne 0x396c0
leaq 0x20(%rsp), %rdi
callq 0x367b9
xorl %eax, %eax
jmp 0x399e0
movl %ecx, 0x1c(%rsp)
movl %edx, 0x10(%rsp)
cmpb $0x2d, (%r12)
jne 0x396e1
movl 0x38(%rax), %edx
leaq 0x1c(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x25145
movq 0x20(%rsp), %rax
movl 0x54(%rax), %ecx
movl %ecx, 0x18(%rsp)
movl 0x58(%rax), %ecx
movl %ecx, 0xc(%rsp)
cmpb $0x2d, 0x1(%r12)
jne 0x3970e
movl 0x50(%rax), %edx
leaq 0x18(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x25145
movl 0x1c(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0xc(%rsp)
testl %r15d, %r15d
jle 0x399bb
movl %r15d, %ecx
xorl %r13d, %r13d
movabsq $0x4000000010003, %rdx  # imm = 0x4000000010003
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %r15d, %r15d
movq %rcx, 0x38(%rsp)
movb (%rbx,%r13), %sil
movzbl %sil, %r12d
movb (%r14,%r13), %dil
movzbl %dil, %ebp
addl $-0x2d, %r12d
cmpl $0x32, %r12d
ja 0x3978a
btq %r12, %rdx
jae 0x3978a
leal -0x2d(%rbp), %eax
cmpl $0x32, %eax
ja 0x3977e
btq %rax, %rdx
jae 0x3977e
movl %r15d, %esi
movl %r9d, %edi
jmp 0x3984d
cmpl $0x32, %r12d
ja 0x3978a
btq %r12, %rdx
jb 0x397a0
leal -0x2d(%rbp), %eax
cmpl $0x32, %eax
ja 0x398e4
btq %rax, %rdx
jae 0x398e4
testl %r8d, %r8d
jne 0x397f2
movb %dil, 0x14(%rsp)
movq 0x20(%rsp), %rdi
movb %sil, 0x28(%rsp)
movl 0x1c(%rsp), %esi
movl 0x10(%rsp), %edx
movl 0x18(%rsp), %ecx
movl 0xc(%rsp), %r8d
movq %r9, 0x40(%rsp)
leaq 0x34(%rsp), %r9
callq 0x39afe
movq 0x40(%rsp), %r9
movb 0x14(%rsp), %dil
movb 0x28(%rsp), %sil
movabsq $0x4000000010003, %rdx  # imm = 0x4000000010003
movq 0x38(%rsp), %rcx
cmpl $0x32, %r12d
ja 0x398af
btq %r12, %rdx
jae 0x398af
movl $0x1, %r8d
leal -0x2d(%rbp), %eax
cmpl $0x32, %eax
ja 0x398b8
btq %rax, %rdx
jae 0x398b8
movq 0x20(%rsp), %r10
cmpl $0x32, %r12d
ja 0x39864
btq %r12, %rdx
jae 0x39864
addl $-0x2d, %ebp
cmpl $0x32, %ebp
ja 0x39893
btq %rbp, %rdx
jae 0x39893
cmpl $0x32, %r12d
ja 0x398c1
btq %r12, %rdx
jae 0x398c1
incq %r13
movl %edi, %r9d
movl %esi, %r15d
cmpq %r13, %rcx
jne 0x39745
jmp 0x399bb
leal -0x2d(%rbp), %eax
cmpl $0x32, %eax
ja 0x39909
btq %rax, %rdx
jae 0x39909
cmpl $0x32, %r12d
ja 0x39886
btq %r12, %rdx
jb 0x39833
cmpl $0x32, %eax
ja 0x3984d
btq %rax, %rdx
jb 0x39841
jmp 0x3984d
incl 0x24(%r10)
movzbl %r15b, %eax
addl $-0x2d, %eax
cmpl $0x32, %eax
ja 0x398a9
btq %rax, %rdx
jb 0x3984d
incl 0x20(%r10)
jmp 0x3984d
incl 0x10(%rsp)
jmp 0x39806
incl 0xc(%rsp)
jmp 0x39822
incl 0x1c(%r10)
movzbl %r9b, %eax
addl $-0x2d, %eax
cmpl $0x32, %eax
ja 0x398db
btq %rax, %rdx
jb 0x3984d
incl 0x18(%r10)
jmp 0x3984d
testl %r8d, %r8d
je 0x398f9
movl 0x10(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x18(%rsp)
incl 0x10(%rsp)
incl 0xc(%rsp)
xorl %r8d, %r8d
jmp 0x39822
cmpb $0x4e, %sil
je 0x39975
cmpb $0x4e, %dil
je 0x39975
movq %r10, %rbp
movl %r8d, 0x40(%rsp)
movb %sil, 0x28(%rsp)
movsbq %sil, %r15
movb %dil, 0x14(%rsp)
movsbq %dil, %r12
callq 0x6100
movq (%rax), %rax
movsbl (%rax,%r12,4), %ecx
movsbl (%rax,%r15,4), %eax
cmpl %ecx, %eax
jne 0x3997e
movl 0xa8(%rsp), %edx
testb $0x1, %dl
movb 0x28(%rsp), %sil
movb 0x14(%rsp), %dil
movl 0x40(%rsp), %r8d
je 0x39970
movsbl %dil, %edx
cmpl %edx, %ecx
jne 0x399a4
movsbl %sil, %ecx
cmpl %ecx, %eax
jne 0x399a4
incl 0x8(%rbp)
jmp 0x399a7
incl 0x14(%r10)
jmp 0x3984d
incl 0xc(%rbp)
movq 0x38(%rsp), %rcx
movabsq $0x4000000010003, %rdx  # imm = 0x4000000010003
movb 0x28(%rsp), %sil
movb 0x14(%rsp), %dil
movl 0x40(%rsp), %r8d
jmp 0x3984d
incl 0x10(%rbp)
movq 0x38(%rsp), %rcx
movabsq $0x4000000010003, %rdx  # imm = 0x4000000010003
jmp 0x3984d
movq 0x20(%rsp), %rdi
movl 0x1c(%rsp), %esi
movl 0x10(%rsp), %edx
movl 0x18(%rsp), %ecx
movl 0xc(%rsp), %r8d
leaq 0x34(%rsp), %r9
callq 0x39afe
movq 0x20(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq