// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/lib/psl.c
// Function: pslFromGff3Cigar
struct psl* pslFromGff3Cigar(char *qName, int qSize, int qStart, int qEnd,
                             char *tName, int tSize, int tStart, int tEnd,
                             char* strand, char *cigar)
/* create a PSL from a GFF3-style cigar formatted alignment */
{
// this is currently tested by the gff3ToPsl
int blocksAlloced = 4;
struct psl *psl = pslNew(qName, qSize, qStart, qEnd, tName, tSize, tStart, tEnd, strand, blocksAlloced, 0);

char op;
int size;
int totalSize = 0;

int qNext = qStart, qBlkEnd = qEnd;
if (strand[0] == '-')
    reverseIntRange(&qNext, &qBlkEnd, qSize);
int tNext = tStart, tBlkEnd = tEnd;
if (strand[1] == '-')
    reverseIntRange(&tNext, &tBlkEnd, tSize);

if (cigar == NULL)
    {
    // no cigar means one block
    size = qEnd - qStart;
    totalSize += size;
    psl->blockSizes[psl->blockCount] = size;
    psl->qStarts[psl->blockCount] = qNext;
    psl->tStarts[psl->blockCount] = tNext;
    psl->blockCount++;
    tNext += size;
    qNext += size;
    }
else
    {
    if (strand[0] == '-' && strand[1] == '-')
        errAbort("GFF3 spec is vague about Gap when both strands are '-'; not implemented yet.");
    char cigarSpec[strlen(cigar)+1];  // copy since parsing is destructive
    safecpy(cigarSpec, sizeof cigarSpec, cigar);
    char *cigarNext = cigarSpec;
    while(getNextCigarOp(cigarSpec, FALSE, &cigarNext, &op, &size))
	{
	switch (op)
	    {
	    case 'M': // match or mismatch (gapless aligned block)
		if (psl->blockCount == blocksAlloced)
		    pslGrow(psl, &blocksAlloced);

		totalSize += size;
		psl->blockSizes[psl->blockCount] = size;
		psl->qStarts[psl->blockCount] = qNext;
		psl->tStarts[psl->blockCount] = tNext;
		psl->blockCount++;
		tNext += size;
		qNext += size;
		break;
	    case 'I': // inserted in target
		tNext += size;
		break;
	    case 'D': // deleted from target
		qNext += size;
		break;
	    
	    default:
		errAbort("unrecognized CIGAR op %c in %s", op, cigar);
	    }
	}
    }

/* CIGARs starting/ending with indels require adjusting of query/target ranges,
 * as PSL starts/ends with matches */
psl->qStart = psl->qStarts[0];
psl->qEnd = pslQEnd(psl, psl->blockCount-1);
if (strand[0] == '-')
    reverseIntRange(&psl->qStart, &psl->qEnd, qSize);
psl->tStart = psl->tStarts[0];
psl->tEnd = pslTEnd(psl, psl->blockCount-1);
if (strand[1] == '-')
    reverseIntRange(&psl->tStart, &psl->tEnd, tSize);

/* sanity check */
if (qNext != qBlkEnd)
    errAbort("CIGAR query length does not match specified query range %s:%d-%d", qName, qStart, qEnd);
if (tNext != tBlkEnd)
    errAbort("CIGAR target length does not match specified target range %s:%d-%d", tName, tStart, tEnd);
psl->match = totalSize;
pslComputeInsertCounts(psl);
return psl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x80, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x18(%rbp)
movl %esi, -0x1c(%rbp)
movl %edx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movl $0x4, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x20(%rbp), %edx
movl -0x24(%rbp), %ecx
movq -0x30(%rbp), %r8
movl -0x34(%rbp), %r9d
movl 0x10(%rbp), %ebx
movl 0x18(%rbp), %r11d
movq 0x20(%rbp), %r10
movl -0x38(%rbp), %eax
xorl %r14d, %r14d
subq $0x30, %rsp
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movl $0x0, 0x20(%rsp)
callq 0x51e50
addq $0x30, %rsp
movq %rax, -0x40(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x54(%rbp)
movq 0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x52717
movl -0x1c(%rbp), %edx
leaq -0x50(%rbp), %rdi
leaq -0x54(%rbp), %rsi
callq 0x33350
movl 0x10(%rbp), %eax
movl %eax, -0x58(%rbp)
movl 0x18(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq 0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2d, %eax
jne 0x52740
movl -0x34(%rbp), %edx
leaq -0x58(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
callq 0x33350
cmpq $0x0, 0x28(%rbp)
jne 0x527bc
movl -0x24(%rbp), %eax
subl -0x20(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %edx
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x40(%rbp), %rcx
movl 0x5c(%rcx), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x50(%rbp), %edx
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x40(%rbp), %rcx
movl 0x5c(%rcx), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x58(%rbp), %edx
movq -0x40(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x40(%rbp), %rcx
movl 0x5c(%rcx), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
movl 0x5c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x5c(%rax)
movl -0x48(%rbp), %eax
addl -0x58(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x48(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x52934
movq 0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x527e3
movq 0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2d, %eax
jne 0x527e3
leaq 0x8b7cb(%rip), %rdi     # 0xddfa7
movb $0x0, %al
callq 0x35d40
movq 0x28(%rbp), %rdi
callq 0x62c0
movq %rax, %rsi
incq %rsi
movq %rsp, %rcx
movq %rcx, -0x68(%rbp)
addq $0x10, %rax
andq $-0x10, %rax
movq %rsp, %rdi
subq %rax, %rdi
movq %rdi, -0x80(%rbp)
movq %rdi, %rsp
movq %rsi, -0x70(%rbp)
movq 0x28(%rbp), %rdx
callq 0x2caf0
movq -0x80(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rdi
xorl %esi, %esi
leaq -0x78(%rbp), %rdx
leaq -0x41(%rbp), %rcx
leaq -0x48(%rbp), %r8
callq 0x52a40
cmpl $0x0, %eax
je 0x5292d
movsbl -0x41(%rbp), %eax
movl %eax, -0x84(%rbp)
subl $0x44, %eax
je 0x52907
jmp 0x52858
movl -0x84(%rbp), %eax
subl $0x49, %eax
je 0x528fc
jmp 0x52869
movl -0x84(%rbp), %eax
subl $0x4d, %eax
jne 0x52912
jmp 0x5287a
movq -0x40(%rbp), %rax
movl 0x5c(%rax), %eax
cmpl -0x38(%rbp), %eax
jne 0x52893
movq -0x40(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x52430
movl -0x48(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x48(%rbp), %edx
movq -0x40(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x40(%rbp), %rcx
movl 0x5c(%rcx), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x50(%rbp), %edx
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rax
movq -0x40(%rbp), %rcx
movl 0x5c(%rcx), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x58(%rbp), %edx
movq -0x40(%rbp), %rax
movq 0x70(%rax), %rax
movq -0x40(%rbp), %rcx
movl 0x5c(%rcx), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x40(%rbp), %rax
movl 0x5c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x5c(%rax)
movl -0x48(%rbp), %eax
addl -0x58(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x48(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x52928
movl -0x48(%rbp), %eax
addl -0x58(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x52928
movl -0x48(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x52928
movsbl -0x41(%rbp), %esi
movq 0x28(%rbp), %rdx
leaq 0x8b6d3(%rip), %rdi     # 0xddff4
movb $0x0, %al
callq 0x35d40
jmp 0x52823
movq -0x68(%rbp), %rax
movq %rax, %rsp
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rax
movl (%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x3c(%rax)
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rax
movl 0x5c(%rax), %esi
subl $0x1, %esi
callq 0x52bb0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x40(%rax)
movq 0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x52985
movq -0x40(%rbp), %rdi
addq $0x3c, %rdi
movq -0x40(%rbp), %rsi
addq $0x40, %rsi
movl -0x1c(%rbp), %edx
callq 0x33350
movq -0x40(%rbp), %rax
movq 0x70(%rax), %rax
movl (%rax), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x40(%rbp), %rdi
movq -0x40(%rbp), %rax
movl 0x5c(%rax), %esi
subl $0x1, %esi
callq 0x52be0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x58(%rax)
movq 0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2d, %eax
jne 0x529d7
movq -0x40(%rbp), %rdi
addq $0x54, %rdi
movq -0x40(%rbp), %rsi
addq $0x58, %rsi
movl -0x34(%rbp), %edx
callq 0x33350
movl -0x50(%rbp), %eax
cmpl -0x54(%rbp), %eax
je 0x529f7
movq -0x18(%rbp), %rsi
movl -0x20(%rbp), %edx
movl -0x24(%rbp), %ecx
leaq 0x8b623(%rip), %rdi     # 0xde013
movb $0x0, %al
callq 0x35d40
movl -0x58(%rbp), %eax
cmpl -0x5c(%rbp), %eax
je 0x52a17
movq -0x30(%rbp), %rsi
movl 0x10(%rbp), %edx
movl 0x18(%rbp), %ecx
leaq 0x8b644(%rip), %rdi     # 0xde054
movb $0x0, %al
callq 0x35d40
movl -0x4c(%rbp), %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x40(%rbp), %rdi
callq 0x52540
movq -0x40(%rbp), %rax
leaq -0x10(%rbp), %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopw (%rax,%rax)