// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/jkOwnLib/gfBlatLib.c
// Function: gfAlignTransTrans
void gfAlignTransTrans(int *pConn, char *tSeqDir, struct dnaSeq *qSeq, 
	boolean qIsRc, int minMatch, struct hash *tFileCache, 
	struct gfOutput *out, boolean isRna)
/* Search indexed translated genome on server with an dna sequence.  Translate
 * this sequence in three frames. Load homologous bits of genome locally
 * and do detailed alignment.  Call 'outFunction' with each alignment
 * that is found. */
{
struct gfClump *clumps[2][3][3], *clump;
char targetName[PATH_LEN];
int qFrame, tFrame, tIsRc;
struct gfSeqSource *ssList = NULL, *ss;
struct lm *lm = lmInit(0);
int tileSize;
struct gfRange *rangeList = NULL, *rl, *range;
struct trans3 *qTrans = trans3New(qSeq), *t3;
struct slRef *t3RefList = NULL, *t3Ref;
struct hash *t3Hash = NULL;
struct dnaSeq *tSeqList = NULL;
enum ffStringency stringency = (isRna ? ffCdna : ffLoose);

/* Query server for clumps. */
gfQuerySeqTransTrans(*pConn, qSeq, clumps, lm, &ssList, &tileSize);
close(*pConn);
*pConn = -1;

for (tIsRc=0; tIsRc <= 1; ++tIsRc)
    {
    /* Figure out which ranges need to be loaded and load them. */
    for (qFrame = 0; qFrame < 3; ++qFrame)
        {
        for (tFrame = 0; tFrame < 3; ++tFrame)
            {
	    rl = seqClumpToRangeList(clumps[tIsRc][qFrame][tFrame], tFrame);
	    rangeList = slCat(rangeList, rl);
	    }
	}
    rangeCoorTimes3(rangeList);
    slSort(&rangeList, gfRangeCmpTarget);
    rangeList = gfRangesBundle(rangeList, ffIntronMax);
    loadHashT3Ranges(rangeList, tSeqDir, tFileCache,
    	qSeq->size/3, tIsRc, &t3Hash, &tSeqList, &t3RefList);

    /* The old range list was not very precise - it was just to get
     * the DNA loaded.  */
    gfRangeFreeList(&rangeList);

    /* Patch up clump list and associated sequence source to refer
     * to bits of genome loaded into memory.  Create new range list
     * by extending hits in clumps. */
    for (qFrame = 0; qFrame < 3; ++qFrame)
	{
	for (tFrame = 0; tFrame < 3; ++tFrame)
	    {
	    for (clump = clumps[tIsRc][qFrame][tFrame]; clump != NULL; clump = clump->next)
		{
		struct gfSeqSource *ss = clump->target;
		struct gfRange *rangeSet = NULL;
		t3 = trans3Find(t3Hash, clumpTargetName(clump), clump->tStart*3, clump->tEnd*3);
		ss->seq = t3->trans[tFrame];
		ss->start = t3->start/3;
		ss->end = t3->end/3;
		clumpToHspRange(clump, qTrans->trans[qFrame], tileSize, tFrame, t3, &rangeSet, TRUE, FALSE);
		untranslateRangeList(rangeSet, qFrame, tFrame, NULL, t3, t3->start);
		rangeList = slCat(rangeSet, rangeList);
		}
	    }
	}
    slReverse(&rangeList);
    slSort(&rangeList, gfRangeCmpTarget);
    rangeList = gfRangesBundle(rangeList, ffIntronMax);

    for (range = rangeList; range != NULL; range = range->next)
	{
	struct dnaSeq *targetSeq = range->tSeq;
	struct ssBundle *bun;

	AllocVar(bun);
	bun->qSeq = qSeq;
	bun->genoSeq = targetSeq;
	bun->ffList = gfRangesToFfItem(range->components, qSeq);
	ssStitch(bun, stringency, minMatch, ssAliCount);
	getTargetName(range->tName, out->includeTargetFile, targetName);
	t3 = range->t3;
	saveAlignments(targetName, t3->nibSize, t3->start, 
	    bun, NULL, qIsRc, tIsRc, stringency, minMatch, out);
	ssBundleFree(&bun);
	}

    /* Cleanup for this strand of database. */
    gfRangeFreeList(&rangeList);
    freeHash(&t3Hash);
    for (t3Ref = t3RefList; t3Ref != NULL; t3Ref = t3Ref->next)
        {
	struct trans3 *t3 = t3Ref->val;
	trans3Free(&t3);
	}
    slFreeList(&t3RefList);
    freeDnaSeqList(&tSeqList);
    }
trans3Free(&qTrans);
for (ss = ssList; ss != NULL; ss = ss->next)
    freeMem(ss->fileName);
slFreeList(&ssList);
lmCleanup(&lm);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x388, %rsp            # imm = 0x388
movq %r9, 0x68(%rsp)
movq %r8, 0x70(%rsp)
movl %ecx, 0x44(%rsp)
movq %rdx, %r15
movq %rsi, 0x60(%rsp)
movq %rdi, %r12
movl 0x3c8(%rsp), %ebx
andq $0x0, 0x50(%rsp)
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x26f00
movq %rax, 0x28(%rsp)
movq %rax, 0x88(%rsp)
andq $0x0, (%rsp)
movq %r15, 0x10(%rsp)
movq %r15, %rdi
callq 0x12f80
andq $0x0, 0x38(%rsp)
andq $0x0, 0x30(%rsp)
andq $0x0, 0x48(%rsp)
movq %rax, 0x78(%rsp)
movq %rax, 0x80(%rsp)
movq %r12, 0x18(%rsp)
movl (%r12), %r12d
leaq 0xf0(%rsp), %rax
cmpq $0x2, %r14
je 0xf05e
movq %rax, %rcx
xorl %edx, %edx
cmpq $0x3, %rdx
je 0xf055
xorl %esi, %esi
cmpq $0x3, %rsi
je 0xf04c
andq $0x0, (%rcx,%rsi,8)
incq %rsi
jmp 0xf03c
incq %rdx
addq $0x18, %rcx
jmp 0xf034
incq %r14
addq $0x48, %rax
jmp 0xf029
testl %ebx, %ebx
sete 0x20(%rsp)
leaq 0x6df17(%rip), %rdx     # 0x7cf83
movl %r12d, %edi
movq 0x10(%rsp), %r14
movq %r14, %rsi
callq 0x10111
leaq 0x180(%rsp), %rsi
movl %r12d, %edi
callq 0x2bbc0
movq %rax, %rbx
leaq 0x6dd1d(%rip), %rdi     # 0x7cdb3
movq %rax, %rsi
callq 0x1db41
testl %eax, %eax
je 0xf458
leaq 0x180(%rsp), %rsi
movq %r14, %rdi
callq 0x101c5
xorl %r13d, %r13d
movl $0x0, 0xc(%rsp)
xorl %eax, %eax
movb 0x20(%rsp), %cl
movb %cl, %al
leal 0x1(,%rax,2), %eax
movq %rax, 0x20(%rsp)
movq %r13, 0x58(%rsp)
movq %r13, 0x50(%rsp)
movq 0x18(%rsp), %rbx
movl (%rbx), %edi
callq 0x6e80
orl $-0x1, (%rbx)
leaq 0xf0(%rsp), %r15
xorl %ebp, %ebp
pushq $0x3
popq %rbx
cmpq $0x2, %rbp
je 0xf40a
movq %r15, 0x18(%rsp)
xorl %r12d, %r12d
cmpq $0x3, %r12
je 0xf146
xorl %r14d, %r14d
cmpq $0x3, %r14
je 0xf13d
movq (%r15,%r14,8), %rdi
movl %r14d, %esi
callq 0xed3a
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x1c549
movq %rax, (%rsp)
incq %r14
jmp 0xf116
incq %r12
addq $0x18, %r15
jmp 0xf10d
movq (%rsp), %rdi
callq 0xe72f
movq %rsp, %r14
movq %r14, %rdi
leaq -0x19a5(%rip), %rsi     # 0xd7b7
callq 0x1c5ab
movq (%rsp), %rdi
leaq 0xa5a04(%rip), %rax     # 0xb4b70
movl (%rax), %esi
callq 0xd8b7
movq %rax, %rdi
movq %rax, (%rsp)
movq 0x10(%rsp), %rax
movl 0x18(%rax), %eax
cltd
idivl %ebx
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
movl %eax, %ecx
movl %ebp, %r8d
leaq 0x30(%rsp), %r9
leaq 0x38(%rsp), %rax
pushq %rax
leaq 0x50(%rsp), %rax
pushq %rax
callq 0xedee
popq %rax
popq %rcx
movq %r14, %rdi
callq 0xd77e
xorl %r15d, %r15d
movq %rbp, 0x28(%rsp)
cmpq $0x3, %r15
je 0xf2bb
xorl %r12d, %r12d
cmpq $0x3, %r12
je 0xf2b3
imulq $0x18, %r15, %rax
imulq $0x48, %rbp, %rcx
addq %rsp, %rcx
addq $0xf0, %rcx
addq %rcx, %rax
leaq (%rax,%r12,8), %rbp
movq (%rbp), %rbp
testq %rbp, %rbp
je 0xf2a6
movq 0x10(%rbp), %r13
andq $0x0, 0x90(%rsp)
movq 0x30(%rsp), %r14
movq %rbp, %rdi
callq 0xdf70
imull $0x3, 0x18(%rbp), %edx
imull $0x3, 0x1c(%rbp), %ecx
movq %r14, %rdi
movq %rax, %rsi
callq 0x13060
movq %rax, %r14
movq 0x18(%rax,%r12,8), %rax
movq %rax, 0x10(%r13)
movl 0x30(%r14), %eax
cltd
idivl %ebx
movl %eax, 0x18(%r13)
movl 0x34(%r14), %eax
cltd
idivl %ebx
movl %eax, 0x1c(%r13)
movq 0x78(%rsp), %rax
movq 0x18(%rax,%r15,8), %rsi
movq %rbp, %rdi
movl 0xc(%rsp), %edx
movl %r12d, %ecx
movq %r14, %r8
leaq 0x90(%rsp), %r9
pushq $0x0
pushq $0x1
callq 0xe37d
popq %rax
popq %rcx
movq 0x90(%rsp), %r13
movl 0x30(%r14), %r9d
movq %r13, %rdi
movl %r15d, %esi
movl %r12d, %edx
xorl %ecx, %ecx
movq %r14, %r8
callq 0xef0e
movq (%rsp), %rsi
movq %r13, %rdi
callq 0x1c549
movq %rax, (%rsp)
jmp 0xf1ec
incq %r12
movq 0x28(%rsp), %rbp
jmp 0xf1c9
incq %r15
jmp 0xf1bc
movq %rsp, %r14
movq %r14, %rdi
callq 0x1c567
movq %r14, %rdi
leaq -0x1b19(%rip), %rsi     # 0xd7b7
callq 0x1c5ab
movq (%rsp), %rdi
leaq 0xa5890(%rip), %rax     # 0xb4b70
movl (%rax), %esi
callq 0xd8b7
movq %rax, %r15
movq %rax, (%rsp)
testq %r15, %r15
je 0xf3ab
movq 0x18(%r15), %r14
pushq $0x48
popq %rdi
callq 0x28bb0
movq %rax, 0x90(%rsp)
movq 0x10(%rsp), %rsi
movq %rsi, 0x10(%rax)
movq %r14, 0x18(%rax)
movq 0x28(%r15), %rdi
callq 0xdfa8
movq 0x90(%rsp), %rdi
movq %rax, 0x8(%rdi)
movq 0x20(%rsp), %r13
movl %r13d, %esi
movq 0x70(%rsp), %r14
movl %r14d, %edx
pushq $0x10
popq %rcx
callq 0x121d7
movq 0x10(%r15), %rdi
movq 0x3c0(%rsp), %rax
movl 0x48(%rax), %esi
leaq 0x180(%rsp), %r12
movq %r12, %rdx
callq 0xdc90
movq 0x38(%r15), %rax
movl 0x30(%rax), %edx
movl 0x38(%rax), %esi
movq 0x90(%rsp), %rcx
movq %r12, %rdi
xorl %r8d, %r8d
movl 0x44(%rsp), %r9d
pushq 0x3c0(%rsp)
pushq %r14
pushq %r13
pushq %rbp
callq 0xdde1
addq $0x20, %rsp
leaq 0x90(%rsp), %rdi
callq 0x11cb5
movq (%r15), %r15
jmp 0xf2ee
movq %rsp, %rdi
callq 0xd77e
leaq 0x30(%rsp), %rdi
callq 0x2494c
leaq 0x38(%rsp), %r14
movq 0x18(%rsp), %r15
movq (%r14), %r14
testq %r14, %r14
je 0xf3ea
movq 0x8(%r14), %rax
movq %rax, 0x90(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x12fe3
jmp 0xf3c7
leaq 0x38(%rsp), %rdi
callq 0x1c583
leaq 0x48(%rsp), %rdi
callq 0x2077b
incq %rbp
addq $0x48, %r15
jmp 0xf0fb
leaq 0x80(%rsp), %rdi
callq 0x12fe3
movq 0x58(%rsp), %rbx
testq %rbx, %rbx
je 0xf42f
movq 0x8(%rbx), %rdi
callq 0x28c2d
movq (%rbx), %rbx
jmp 0xf41c
leaq 0x50(%rsp), %rdi
callq 0x1c583
leaq 0x88(%rsp), %rdi
callq 0x26fa2
addq $0x388, %rsp            # imm = 0x388
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x101da
movl %eax, 0xc(%rsp)
leaq 0x180(%rsp), %r14
xorl %r13d, %r13d
movl %r12d, %edi
movq %r14, %rsi
callq 0x2bbc0
cmpl $0x646e65, 0x180(%rsp) # imm = 0x646E65
movq 0x10(%rsp), %rbx
je 0xf600
leaq 0x6d91c(%rip), %rdi     # 0x7cdb3
movq %r14, %rsi
callq 0x1db41
testl %eax, %eax
jne 0xf5f0
movq %r14, %rdi
leaq 0x90(%rsp), %rsi
pushq $0xc
popq %rdx
callq 0x1e59b
cmpl $0x8, %eax
jg 0xf4cf
leaq 0x6dac8(%rip), %rdi     # 0x7cf8e
movl %eax, %esi
xorl %eax, %eax
callq 0x223fb
pushq $0x38
popq %rdi
callq 0x28bb0
movq %rax, %r15
movq 0x90(%rsp), %rdi
callq 0x35d13
movl %eax, 0x8(%r15)
movq 0x98(%rsp), %rdi
callq 0x35d13
movl %eax, 0xc(%r15)
pushq $0x28
popq %rdi
callq 0x28bb0
movq %rax, %r14
movq 0xa0(%rsp), %rdi
callq 0x1c306
movq %rax, 0x8(%r14)
movq %r13, (%r14)
movq %r14, 0x10(%r15)
movq 0xa8(%rsp), %rdi
callq 0x35d13
movl %eax, 0x18(%r15)
movq 0xb0(%rsp), %rdi
callq 0x35d13
movl %eax, 0x1c(%r15)
movq 0xb8(%rsp), %rdi
callq 0x35d13
movl %eax, 0x20(%r15)
movq 0xc0(%rsp), %rax
movq 0xc8(%rsp), %rdi
xorl %ebx, %ebx
cmpb $0x2d, (%rax)
sete %bl
callq 0x35d13
movl %eax, %ebp
movq 0xd0(%rsp), %rdi
callq 0x35d13
movslq %ebp, %rcx
cltq
imulq $0x18, %rcx, %rcx
imulq $0x48, %rbx, %rdx
addq %rsp, %rdx
addq $0xf0, %rdx
addq %rdx, %rcx
movq (%rcx,%rax,8), %rdx
movq %rdx, (%r15)
movq %r15, (%rcx,%rax,8)
movl %r12d, %edi
movq 0x28(%rsp), %rsi
callq 0xd7f6
movq %rax, 0x28(%r15)
movq %rax, %rdi
callq 0x1c4aa
movq %r14, %r13
cmpl 0x20(%r15), %eax
leaq 0x180(%rsp), %r14
je 0xf46f
leaq 0x6d91a(%rip), %rdi     # 0x7cef2
leaq 0x6d7b9(%rip), %rsi     # 0x7cd98
leaq 0x6d9cd(%rip), %rcx     # 0x7cfb3
movl $0x152, %edx            # imm = 0x152
callq 0x6460
leaq 0x180(%rsp), %rsi
movq %rbx, %rdi
callq 0x101c5
leaq 0xf0(%rsp), %rbx
xorl %r14d, %r14d
cmpq $0x2, %r14
je 0xf0c1
movq %rbx, %r15
xorl %r12d, %r12d
cmpq $0x3, %r12
je 0xf641
xorl %ebp, %ebp
cmpq $0x18, %rbp
je 0xf638
leaq (%r15,%rbp), %rdi
callq 0x1c567
addq $0x8, %rbp
jmp 0xf623
incq %r12
addq $0x18, %r15
jmp 0xf61b
incq %r14
addq $0x48, %rbx
jmp 0xf60b