// File: /workspace/github_c_makefile_star2_O2/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, 0x18(%rsp)
movq %r8, %rbx
movl %ecx, 0xc(%rsp)
movl %edx, %r13d
movl %esi, %r15d
movq %rdi, %rbp
movq 0x98(%rsp), %r14
movl $0x10, 0x24(%rsp)
movq %r8, %rdi
callq 0x62d0
movq %rax, %r12
movl $0x88, %edi
callq 0x28bb0
movq %r14, %rdi
callq 0x62d0
movslq %r12d, %rcx
cmpq %rcx, %rax
je 0x33b81
leaq 0x4f4b9(%rip), %rdi     # 0x83033
xorl %eax, %eax
callq 0x223fb
subq $0x8, %rsp
movq %rbp, %rdi
movl %r15d, %esi
movl %r13d, %edx
movl 0x14(%rsp), %ecx
movq 0x20(%rsp), %r8
movl 0x88(%rsp), %r9d
pushq $0x0
pushq $0x10
movq 0xb8(%rsp), %rbp
pushq %rbp
movl 0xb0(%rsp), %eax
pushq %rax
movl 0xb0(%rsp), %eax
pushq %rax
callq 0x34040
addq $0x30, %rsp
movq %rax, %r10
movq %rax, 0x38(%rsp)
addq $0x54, %rax
leaq 0x3c(%r10), %rcx
movl %r12d, %edx
sarl $0x1f, %edx
andl %r12d, %edx
movabsq $0x4000000010003, %r13  # imm = 0x4000000010003
testl %r12d, %r12d
jle 0x33c44
movzbl (%rbx), %esi
leal -0x2d(%rsi), %edi
cmpl $0x32, %edi
ja 0x33c18
btq %rdi, %r13
jae 0x33c18
movzbl (%r14), %esi
addl $-0x2d, %esi
movq %rax, %rdi
cmpl $0x32, %esi
ja 0x33c37
btq %rsi, %r13
movq %rax, %rdi
jb 0x33c39
jmp 0x33c37
movzbl (%r14), %edi
addl $-0x2d, %edi
cmpl $0x32, %edi
ja 0x33c47
btq %rdi, %r13
jae 0x33c47
cmpl $0x5f, %esi
je 0x33bfe
movq %rcx, %rdi
cmpl $0x3d, %esi
je 0x33bfe
incl (%rdi)
incq %rbx
incq %r14
decl %r12d
jmp 0x33be8
movl %edx, %r12d
leaq 0x58(%r10), %rdx
movq %r10, %rsi
addq $0x40, %rsi
movl %r12d, %edi
movl %r12d, %r11d
sarl $0x1f, %r11d
andl %r12d, %r11d
testl %edi, %edi
jle 0x33cc7
movzbl -0x1(%rbx,%rdi), %r8d
leal -0x2d(%r8), %r9d
cmpl $0x32, %r9d
ja 0x33c97
btq %r9, %r13
jae 0x33c97
movzbl -0x1(%r14,%rdi), %r8d
addl $-0x2d, %r8d
movq %rdx, %r9
cmpl $0x32, %r8d
ja 0x33cbc
btq %r8, %r13
movq %rdx, %r9
jb 0x33cbf
jmp 0x33cbc
movzbl -0x1(%r14,%rdi), %r9d
addl $-0x2d, %r9d
cmpl $0x32, %r9d
ja 0x33cc4
btq %r9, %r13
jae 0x33cc4
cmpl $0x5f, %r8d
je 0x33c79
movq %rsi, %r9
cmpl $0x3d, %r8d
je 0x33c79
decl (%r9)
decq %rdi
jmp 0x33c5f
movl %edi, %r11d
movl (%rcx), %edi
movl (%rsi), %esi
cmpl %esi, %edi
je 0x33cd7
movl (%rax), %eax
movl (%rdx), %ecx
cmpl %ecx, %eax
jne 0x33ce8
leaq 0x38(%rsp), %rdi
callq 0x30fe5
xorl %eax, %eax
jmp 0x34031
movl %edi, 0x10(%rsp)
movl %esi, 0x8(%rsp)
cmpb $0x2d, (%rbp)
jne 0x33d1d
movl 0x38(%r10), %edx
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movq %r10, %r15
movq %r11, %r12
callq 0x20d61
movq %r12, %r11
movq %r15, %r10
movl 0x54(%r15), %eax
movl 0x58(%r15), %ecx
movl %eax, 0x14(%rsp)
movl %ecx, 0x4(%rsp)
cmpb $0x2d, 0x1(%rbp)
jne 0x33d51
movl 0x50(%r10), %edx
leaq 0x14(%rsp), %r12
leaq 0x4(%rsp), %rsi
movq %r12, %rdi
movq %r10, %r15
movq %r11, %rbp
callq 0x20d61
movq %rbp, %r11
movq %r15, %r10
movl (%r12), %eax
movl 0x10(%rsp), %ecx
movl %ecx, 0x8(%rsp)
movl %eax, 0x4(%rsp)
xorl %r12d, %r12d
testl %r11d, %r11d
cmovlel %r12d, %r11d
pushq $0x1
popq %rdx
xorl %ecx, %ecx
xorl %r9d, %r9d
xorl %r8d, %r8d
movq %r11, 0x30(%rsp)
cmpq %r12, %r11
je 0x3400e
movb (%rbx,%r12), %sil
movzbl %sil, %eax
movb (%r14,%r12), %dil
movzbl %dil, %ebp
movq %rax, 0x18(%rsp)
leal -0x2d(%rax), %r15d
cmpl $0x32, %r15d
ja 0x33dc9
btq %r15, %r13
jae 0x33dc9
leal -0x2d(%rbp), %eax
cmpl $0x32, %eax
ja 0x33dbd
btq %rax, %r13
jae 0x33dbd
movl %ecx, %esi
movl %r9d, %edi
jmp 0x33e8a
cmpl $0x32, %r15d
ja 0x33dc9
btq %r15, %r13
jb 0x33ddf
leal -0x2d(%rbp), %eax
cmpl $0x32, %eax
ja 0x33f1b
btq %rax, %r13
jae 0x33f1b
testl %r8d, %r8d
jne 0x33e32
movb %sil, 0xc(%rsp)
movl 0x10(%rsp), %esi
movl 0x8(%rsp), %edx
movq %rcx, 0x40(%rsp)
movl 0x14(%rsp), %ecx
movl 0x4(%rsp), %r8d
movb %dil, 0x3(%rsp)
movq %r10, %rdi
movq %r9, 0x28(%rsp)
leaq 0x24(%rsp), %r9
callq 0x3414d
movq 0x40(%rsp), %rcx
movq 0x28(%rsp), %r9
movb 0x3(%rsp), %dil
movb 0xc(%rsp), %sil
pushq $0x1
popq %rdx
movq 0x30(%rsp), %r11
cmpl $0x32, %r15d
ja 0x33ee3
btq %r15, %r13
jae 0x33ee3
leal -0x2d(%rbp), %eax
cmpl $0x32, %eax
ja 0x33eec
btq %rax, %r13
movl %edx, %r8d
jae 0x33eec
movq 0x38(%rsp), %r10
cmpl $0x32, %r15d
ja 0x33e97
btq %r15, %r13
jae 0x33e97
addl $-0x2d, %ebp
cmpl $0x32, %ebp
ja 0x33ec8
btq %rbp, %r13
jae 0x33ec8
cmpl $0x32, %r15d
ja 0x33ef8
btq %r15, %r13
jae 0x33ef8
incq %r12
movl %esi, %ecx
movl %edi, %r9d
jmp 0x33d77
leal -0x2d(%rbp), %eax
cmpl $0x32, %eax
ja 0x33f4a
btq %rax, %r13
jae 0x33f4a
cmpl $0x5f, 0x18(%rsp)
je 0x33e70
cmpl $0x3d, 0x18(%rsp)
je 0x33e70
cmpl $0x32, %eax
ja 0x33e8a
btq %rax, %r13
jb 0x33e7e
jmp 0x33e8a
incl 0x24(%r10)
movzbl %cl, %eax
addl $-0x2d, %eax
cmpl $0x32, %eax
ja 0x33edd
btq %rax, %r13
jb 0x33e8a
incl 0x20(%r10)
jmp 0x33e8a
incl 0x8(%rsp)
jmp 0x33e46
incl 0x4(%rsp)
movl %edx, %r8d
jmp 0x33e5f
incl 0x1c(%r10)
movzbl %r9b, %eax
addl $-0x2d, %eax
cmpl $0x32, %eax
ja 0x33f12
btq %rax, %r13
jb 0x33e8a
incl 0x18(%r10)
jmp 0x33e8a
movq %rcx, %r10
movl 0x8(%rsp), %ecx
movl 0x4(%rsp), %eax
testl %r8d, %r8d
je 0x33f33
movl %ecx, 0x10(%rsp)
movl %eax, 0x14(%rsp)
incl %ecx
movl %ecx, 0x8(%rsp)
incl %eax
movl %eax, 0x4(%rsp)
xorl %r8d, %r8d
movq %r10, %rcx
jmp 0x33e5f
cmpb $0x4e, %sil
setne %al
cmpb $0x4e, %dil
setne %cl
testb %cl, %al
jne 0x33f65
incl 0x14(%r10)
jmp 0x33e8a
movl %r8d, 0x28(%rsp)
movq %r10, 0x18(%rsp)
movb %sil, 0xc(%rsp)
movsbq %sil, %r15
movb %dil, 0x3(%rsp)
movsbq %dil, %rbp
callq 0x6100
movq (%rax), %rax
movl (%rax,%rbp,4), %ecx
movl (%rax,%r15,4), %eax
movl %eax, %edx
shll $0x18, %edx
shll $0x18, %ecx
cmpl %ecx, %edx
jne 0x33fe0
movl 0xa8(%rsp), %ecx
testb $0x1, %cl
movq 0x18(%rsp), %r10
movq 0x30(%rsp), %r11
pushq $0x1
popq %rdx
movb 0xc(%rsp), %sil
movb 0x3(%rsp), %dil
movl 0x28(%rsp), %r8d
je 0x33fd7
movsbl %dil, %ecx
movsbl %al, %eax
cmpl %ecx, %eax
jne 0x34005
movsbl %sil, %ecx
cmpl %ecx, %eax
jne 0x34005
incl 0x8(%r10)
jmp 0x33e8a
movq 0x18(%rsp), %r10
incl 0xc(%r10)
movq 0x30(%rsp), %r11
pushq $0x1
popq %rdx
movb 0xc(%rsp), %sil
movb 0x3(%rsp), %dil
movl 0x28(%rsp), %r8d
jmp 0x33e8a
incl 0x10(%r10)
jmp 0x33e8a
movl 0x10(%rsp), %esi
movl 0x8(%rsp), %edx
movl 0x14(%rsp), %ecx
movl 0x4(%rsp), %r8d
leaq 0x24(%rsp), %r9
movq %r10, %rdi
callq 0x3414d
movq 0x38(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq