// File: /workspace/github_c_makefile_star2_O3/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)
movl %ecx, %ebp
movl %edx, %r13d
movl %esi, %r15d
movq %rdi, %r14
movq 0x98(%rsp), %rbx
movl $0x10, 0x24(%rsp)
movq %r8, 0x10(%rsp)
movq %r8, %rdi
callq 0x62d0
movq %rax, %r12
movl $0x88, %edi
callq 0x2dff4
movq %rbx, %rdi
callq 0x62d0
movslq %r12d, %rcx
cmpq %rcx, %rax
je 0x39852
leaq 0x5a8e8(%rip), %rdi     # 0x94133
xorl %eax, %eax
callq 0x26e94
subq $0x8, %rsp
movq %r14, %rdi
movl %r15d, %esi
movl %r13d, %edx
movl %ebp, %ecx
movq 0x20(%rsp), %r8
movl 0x88(%rsp), %r9d
pushq $0x0
pushq $0x10
pushq 0xb8(%rsp)
movl 0xb0(%rsp), %eax
pushq %rax
movl 0xb0(%rsp), %eax
pushq %rax
callq 0x39d7e
addq $0x30, %rsp
movq %rax, 0x38(%rsp)
testl %r12d, %r12d
jle 0x39958
leaq 0x54(%rax), %rsi
movq %rax, %rbp
leaq 0x3c(%rax), %r8
movl %r12d, %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movq 0x10(%rsp), %r13
leaq (%rdi,%r13), %r9
movq 0x98(%rsp), %r15
addq %r15, %rdi
movl %r12d, %r14d
leal 0x1(%r12), %r10d
movabsq $0x4000000010003, %rdx  # imm = 0x4000000010003
movq %r14, %rcx
movzbl (%r13), %r11d
leal -0x2d(%r11), %ebx
cmpl $0x32, %ebx
ja 0x3990d
btq %rbx, %rdx
jae 0x3990d
movzbl (%r15), %r11d
addl $-0x2d, %r11d
movq %rsi, %rbx
cmpl $0x32, %r11d
ja 0x39936
btq %r11, %rdx
movq %rsi, %rbx
jb 0x39938
jmp 0x39936
movzbl (%r15), %ebx
addl $-0x2d, %ebx
cmpl $0x32, %ebx
ja 0x39ce7
btq %rbx, %rdx
jae 0x39ce7
cmpl $0x5f, %r11d
je 0x398f1
movq %r8, %rbx
cmpl $0x3d, %r11d
je 0x398f1
incl (%rbx)
incq %r13
incq %r15
decq %rcx
decl %r10d
cmpl $0x1, %r10d
jg 0x398dd
xorl %r12d, %r12d
movq %rdi, %r15
movq %r9, %r13
movq %rbp, %rax
jmp 0x39965
movq 0x98(%rsp), %r15
movq 0x10(%rsp), %r13
movl 0x3c(%rax), %ecx
movl 0x40(%rax), %edx
cmpl %edx, %ecx
je 0x3997b
movl 0x54(%rax), %r8d
movl 0x58(%rax), %esi
cmpl %esi, %r8d
jne 0x3998c
leaq 0x38(%rsp), %rdi
callq 0x36aa1
xorl %eax, %eax
jmp 0x39cd8
movl %ecx, 0x8(%rsp)
movl %edx, 0x4(%rsp)
movq 0xa0(%rsp), %rcx
cmpb $0x2d, (%rcx)
jne 0x399c0
movl 0x38(%rax), %edx
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
movq %rax, %rbx
callq 0x25472
movq %rbx, %rax
movl 0x54(%rbx), %r8d
movl 0x58(%rbx), %esi
movl %r8d, 0xc(%rsp)
movl %esi, (%rsp)
movq 0xa0(%rsp), %rcx
cmpb $0x2d, 0x1(%rcx)
jne 0x399f2
movl 0x50(%rax), %edx
leaq 0xc(%rsp), %r14
movq %rsp, %rsi
movq %r14, %rdi
movq %rax, %rbx
callq 0x25472
movq %rbx, %rax
movl (%r14), %r8d
movl 0x8(%rsp), %edx
movl %edx, 0x4(%rsp)
movl %r8d, (%rsp)
testl %r12d, %r12d
jle 0x39cc1
movl %r12d, %edx
xorl %ebp, %ebp
movabsq $0x4000000010003, %rsi  # imm = 0x4000000010003
xorl %r9d, %r9d
xorl %r10d, %r10d
xorl %r12d, %r12d
movq %rdx, 0x28(%rsp)
movb (%r13,%rbp), %dil
movzbl %dil, %r11d
movb (%r15,%rbp), %r8b
movzbl %r8b, %r14d
leal -0x2d(%r11), %ebx
cmpl $0x32, %ebx
ja 0x39a69
btq %rbx, %rsi
jae 0x39a69
leal -0x2d(%r14), %ecx
cmpl $0x32, %ecx
ja 0x39a5e
btq %rcx, %rsi
jae 0x39a5e
movl %r12d, %edi
movl %r10d, %r8d
jmp 0x39b34
cmpl $0x32, %ebx
ja 0x39a69
btq %rbx, %rsi
jb 0x39a80
leal -0x2d(%r14), %ecx
cmpl $0x32, %ecx
ja 0x39bc7
btq %rcx, %rsi
jae 0x39bc7
testl %r9d, %r9d
jne 0x39ad9
movl 0x8(%rsp), %esi
movl 0x4(%rsp), %edx
movl 0xc(%rsp), %ecx
movb %r8b, 0x18(%rsp)
movl (%rsp), %r8d
movb %dil, 0x10(%rsp)
movq %rax, %rdi
leaq 0x24(%rsp), %r9
movq %r10, 0x30(%rsp)
movq %r11, 0x40(%rsp)
callq 0x39e8d
movq 0x40(%rsp), %r11
movq 0x30(%rsp), %r10
movb 0x18(%rsp), %r8b
movb 0x10(%rsp), %dil
movabsq $0x4000000010003, %rsi  # imm = 0x4000000010003
movq 0x28(%rsp), %rdx
cmpl $0x32, %ebx
ja 0x39b95
btq %rbx, %rsi
jae 0x39b95
movl $0x1, %r9d
leal -0x2d(%r14), %eax
cmpl $0x32, %eax
ja 0x39b9e
btq %rax, %rsi
jae 0x39b9e
movq 0x38(%rsp), %rax
cmpl $0x32, %ebx
ja 0x39b4b
btq %rbx, %rsi
jae 0x39b4b
addl $-0x2d, %r14d
cmpl $0x32, %r14d
ja 0x39b7b
btq %r14, %rsi
jae 0x39b7b
cmpl $0x32, %ebx
ja 0x39ba6
btq %rbx, %rsi
jae 0x39ba6
incq %rbp
movl %r8d, %r10d
movl %edi, %r12d
cmpq %rbp, %rdx
jne 0x39a24
jmp 0x39caf
leal -0x2d(%r14), %ecx
cmpl $0x32, %ecx
ja 0x39bee
btq %rcx, %rsi
jae 0x39bee
cmpl $0x5f, %r11d
je 0x39b19
cmpl $0x3d, %r11d
je 0x39b19
cmpl $0x32, %ecx
ja 0x39b34
btq %rcx, %rsi
jb 0x39b29
jmp 0x39b34
incl 0x24(%rax)
movzbl %r12b, %ecx
addl $-0x2d, %ecx
cmpl $0x32, %ecx
ja 0x39b90
btq %rcx, %rsi
jb 0x39b34
incl 0x20(%rax)
jmp 0x39b34
incl 0x4(%rsp)
jmp 0x39aec
incl (%rsp)
jmp 0x39b09
incl 0x1c(%rax)
movzbl %r10b, %ecx
addl $-0x2d, %ecx
cmpl $0x32, %ecx
ja 0x39bbf
btq %rcx, %rsi
jb 0x39b34
incl 0x18(%rax)
jmp 0x39b34
movl 0x4(%rsp), %ecx
movl (%rsp), %eax
testl %r9d, %r9d
je 0x39bdb
movl %ecx, 0x8(%rsp)
movl %eax, 0xc(%rsp)
incl %ecx
movl %ecx, 0x4(%rsp)
incl %eax
movl %eax, (%rsp)
xorl %r9d, %r9d
jmp 0x39b09
cmpb $0x4e, %dil
je 0x39c65
cmpb $0x4e, %r8b
je 0x39c65
movl %r9d, 0x30(%rsp)
movq %rax, %r12
movb %dil, 0x10(%rsp)
movsbq %dil, %rbx
movb %r8b, 0x18(%rsp)
movsbq %r8b, %r14
callq 0x6100
movq (%rax), %rax
movl (%rax,%r14,4), %ecx
movl (%rax,%rbx,4), %esi
movl %esi, %edx
shll $0x18, %edx
shll $0x18, %ecx
cmpl %ecx, %edx
jne 0x39c6d
movl 0xa8(%rsp), %eax
testb $0x1, %al
movq %r12, %rax
movb 0x10(%rsp), %dil
movb 0x18(%rsp), %r8b
movl 0x30(%rsp), %r9d
je 0x39c60
movsbl %r8b, %ecx
movsbl %sil, %edx
cmpl %ecx, %edx
jne 0x39c98
movsbl %dil, %ecx
cmpl %ecx, %edx
jne 0x39c98
incl 0x8(%rax)
jmp 0x39c9b
incl 0x14(%rax)
jmp 0x39b34
movq %r12, %rax
incl 0xc(%r12)
movq 0x28(%rsp), %rdx
movabsq $0x4000000010003, %rsi  # imm = 0x4000000010003
movb 0x10(%rsp), %dil
movb 0x18(%rsp), %r8b
movl 0x30(%rsp), %r9d
jmp 0x39b34
incl 0x10(%rax)
movq 0x28(%rsp), %rdx
movabsq $0x4000000010003, %rsi  # imm = 0x4000000010003
jmp 0x39b34
movl 0x8(%rsp), %esi
movl 0x4(%rsp), %edx
movl 0xc(%rsp), %ecx
movl (%rsp), %r8d
jmp 0x39cc6
movl %r8d, %ecx
movl %edx, %esi
leaq 0x24(%rsp), %r9
movq %rax, %rdi
callq 0x39e8d
movq 0x38(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rax
leaq 0x58(%rbp), %rsi
movq %rbp, %rdi
addq $0x40, %rdi
decq %r14
movq 0x10(%rsp), %r10
movq 0x98(%rsp), %r11
movzbl (%r10,%r14), %r8d
leal -0x2d(%r8), %r9d
cmpl $0x32, %r9d
ja 0x39d37
btq %r9, %rdx
jae 0x39d37
movzbl (%r11,%r14), %r8d
addl $-0x2d, %r8d
movq %rsi, %r9
cmpl $0x32, %r8d
ja 0x39d5b
btq %r8, %rdx
movq %rsi, %r9
jb 0x39d5e
jmp 0x39d5b
movzbl (%r11,%r14), %r9d
addl $-0x2d, %r9d
cmpl $0x32, %r9d
ja 0x39d76
btq %r9, %rdx
jae 0x39d76
cmpl $0x5f, %r8d
je 0x39d1a
movq %rdi, %r9
cmpl $0x3d, %r8d
je 0x39d1a
decl (%r9)
decq %rcx
leaq 0x1(%rcx), %r8
decq %r14
xorl %r12d, %r12d
cmpq $0x1, %r8
ja 0x39d05
jmp 0x39965
movl %ecx, %r12d
jmp 0x39965