// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/jkOwnLib/gfBlatLib.c
// Function: gfAlignTrans
void gfAlignTrans(int *pConn, char *tSeqDir, aaSeq *seq, int minMatch, 
    struct hash *tFileCache, struct gfOutput *out)
/* Search indexed translated genome on server with an amino acid sequence. 
 * Then load homologous bits of genome locally and do detailed alignment.
 * Call 'outFunction' with each alignment that is found. */
{
struct ssBundle *bun;
struct gfClump *clumps[2][3], *clump;
struct gfRange *rangeList = NULL, *range, *rl;
struct dnaSeq *targetSeq, *tSeqList = NULL;
char targetName[PATH_LEN];
int tileSize;
int frame, isRc = 0;
struct hash *t3Hash = NULL;
struct slRef *t3RefList = NULL, *ref;
struct gfSeqSource *ssList = NULL, *ss;
struct trans3 *t3;
struct lm *lm = lmInit(0);

/* Get clumps from server. */
gfQuerySeqTrans(*pConn, seq, clumps, lm, &ssList, &tileSize);
close(*pConn);
*pConn = -1;

for (isRc = 0; isRc <= 1;  ++isRc)
    {
    /* Figure out which parts of sequence we need to load. */
    for (frame = 0; frame < 3; ++frame)
	{
	rl = seqClumpToRangeList(clumps[isRc][frame], frame);
	rangeList = slCat(rangeList, rl);
	}
    /* Convert from amino acid to nucleotide coordinates. */
    rangeCoorTimes3(rangeList);
    slSort(&rangeList, gfRangeCmpTarget);
    rangeList = gfRangesBundle(rangeList, ffIntronMax);
    loadHashT3Ranges(rangeList, tSeqDir, tFileCache, seq->size, 
    	isRc, &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 (frame = 0; frame < 3; ++frame)
	{
	for (clump = clumps[isRc][frame]; clump != NULL; clump = clump->next)
	    {
	    struct gfSeqSource *ss = clump->target;
	    t3 = trans3Find(t3Hash, clumpTargetName(clump), clump->tStart*3, clump->tEnd*3);
	    ss->seq = t3->trans[frame];
	    ss->start = t3->start/3;
	    ss->end = t3->end/3;
	    clumpToHspRange(clump, seq, tileSize, frame, t3, &rangeList, TRUE, FALSE);
	    }
	}
    slReverse(&rangeList);
    slSort(&rangeList, gfRangeCmpTarget);
    rangeList = gfRangesBundle(rangeList, ffIntronMax/3);

    /* Do detailed alignment of each of the clustered ranges. */
    for (range = rangeList; range != NULL; range = range->next)
	{
	targetSeq = range->tSeq;
	AllocVar(bun);
	bun->qSeq = seq;
	bun->genoSeq = targetSeq;
	bun->ffList = gfRangesToFfItem(range->components, seq);
	bun->isProt = TRUE;
	t3 = hashMustFindVal(t3Hash, range->tName);
	bun->t3List = t3;
	ssStitch(bun, ffCdna, minMatch, ssAliCount);
	getTargetName(range->tName, out->includeTargetFile, targetName);
	saveAlignments(targetName, t3->nibSize, 0, 
	    bun, t3Hash, FALSE, isRc, ffCdna, minMatch, out);
	ssBundleFree(&bun);
	}

    /* Cleanup for this strand of database. */
    gfRangeFreeList(&rangeList);
    freeHash(&t3Hash);
    for (ref = t3RefList; ref != NULL; ref = ref->next)
        {
	struct trans3 *t3 = ref->val;
	trans3Free(&t3);
	}
    slFreeList(&t3RefList);
    freeDnaSeqList(&tSeqList);
    }

/* Final cleanup. */
for (isRc=0; isRc<=1; ++isRc)
    for (frame=0; frame<3; ++frame)
	gfClumpFreeList(&clumps[isRc][frame]);
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 $0x318, %rsp            # imm = 0x318
movq %r9, 0x60(%rsp)
movq %r8, 0x50(%rsp)
movq %rcx, 0x58(%rsp)
andq $0x0, 0x8(%rsp)
movq %rdx, %r14
andq $0x0, 0x38(%rsp)
movq %rsi, 0x48(%rsp)
andq $0x0, 0x18(%rsp)
movq %rdi, %r15
andq $0x0, 0x30(%rsp)
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x26f00
movq %rax, 0x10(%rsp)
movq %rax, 0x70(%rsp)
movq %r15, 0x28(%rsp)
movl (%r15), %r13d
leaq 0xe0(%rsp), %rax
cmpq $0x2, %rbx
je 0xe7dd
xorl %ecx, %ecx
cmpq $0x3, %rcx
je 0xe7d4
andq $0x0, (%rax,%rcx,8)
incq %rcx
jmp 0xe7c4
incq %rbx
addq $0x18, %rax
jmp 0xe7bc
leaq 0x6e6df(%rip), %rdx     # 0x7cec3
movl %r13d, %edi
movq %r14, %rsi
callq 0x10111
leaq 0x110(%rsp), %rsi
movl %r13d, %edi
callq 0x2bbc0
movq %rax, %rbx
leaq 0x6e5aa(%rip), %rdi     # 0x7cdb3
movq %rax, %rsi
callq 0x1db41
testl %eax, %eax
movq %r14, %rbp
je 0xeb80
movq %r14, %rdi
movq %rbx, %rsi
callq 0x101c5
xorl %r12d, %r12d
movl $0x0, 0x24(%rsp)
movq %r12, 0x40(%rsp)
movq %r12, 0x78(%rsp)
movq 0x28(%rsp), %rbx
movl (%rbx), %edi
callq 0x6e80
orl $-0x1, (%rbx)
leaq 0xe0(%rsp), %r14
xorl %r15d, %r15d
pushq $0x3
popq %r13
cmpq $0x2, %r15
je 0xeb10
xorl %ebx, %ebx
cmpq $0x3, %rbx
je 0xe88e
movq (%r14,%rbx,8), %rdi
movl %ebx, %esi
callq 0xed3a
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x1c549
movq %rax, 0x8(%rsp)
incq %rbx
jmp 0xe866
movq %r14, 0x28(%rsp)
movq 0x8(%rsp), %rdi
callq 0xe72f
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
leaq -0x10f5(%rip), %rsi     # 0xd7b7
callq 0x1c5ab
movq 0x8(%rsp), %rdi
leaq 0xa62b3(%rip), %rax     # 0xb4b70
movl (%rax), %esi
callq 0xd8b7
movq %rax, 0x8(%rsp)
movl 0x18(%rbp), %ecx
movq %rax, %rdi
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq %r15, 0x10(%rsp)
movl %r15d, %r8d
leaq 0x18(%rsp), %r9
leaq 0x30(%rsp), %rax
pushq %rax
leaq 0x40(%rsp), %rax
pushq %rax
callq 0xedee
popq %rax
popq %rcx
movq %rbx, %rdi
callq 0xd77e
xorl %r15d, %r15d
cmpq $0x3, %r15
je 0xe99d
imulq $0x18, 0x10(%rsp), %rax
addq %rsp, %rax
addq $0xe0, %rax
leaq (%rax,%r15,8), %rbx
movq (%rbx), %rbx
testq %rbx, %rbx
je 0xe995
movq 0x10(%rbx), %r12
movq 0x18(%rsp), %r14
movq %rbx, %rdi
callq 0xdf70
imull $0x3, 0x18(%rbx), %edx
imull $0x3, 0x1c(%rbx), %ecx
movq %r14, %rdi
movq %rax, %rsi
callq 0x13060
movq %rax, %r8
movq 0x18(%rax,%r15,8), %rax
movq %rax, 0x10(%r12)
movl 0x30(%r8), %eax
cltd
idivl %r13d
movl %eax, 0x18(%r12)
movl 0x34(%r8), %eax
cltd
idivl %r13d
movl %eax, 0x1c(%r12)
movq %rbx, %rdi
movq %rbp, %rsi
movl 0x24(%rsp), %edx
movl %r15d, %ecx
leaq 0x8(%rsp), %r9
pushq $0x0
pushq $0x1
callq 0xe37d
addq $0x10, %rsp
jmp 0xe921
incq %r15
jmp 0xe904
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x1c567
movq %rbx, %rdi
leaq -0x11fd(%rip), %rsi     # 0xd7b7
callq 0x1c5ab
movq 0x8(%rsp), %rdi
leaq 0xa61ab(%rip), %rax     # 0xb4b70
movl (%rax), %eax
cltd
idivl %r13d
movl %eax, %esi
callq 0xd8b7
movq %rax, %r15
movq %rax, 0x8(%rsp)
testq %r15, %r15
je 0xeab0
movq 0x18(%r15), %rbx
pushq $0x48
popq %rdi
callq 0x28bb0
movq %rax, 0x80(%rsp)
movq %rbp, %rsi
movq %rbp, 0x10(%rax)
movq %rbx, 0x18(%rax)
movq 0x28(%r15), %rdi
callq 0xdfa8
movq 0x80(%rsp), %rcx
movq %rax, 0x8(%rcx)
pushq $0x1
popq %r14
movl %r14d, 0x30(%rcx)
movq 0x18(%rsp), %rdi
movq 0x10(%r15), %rsi
callq 0x2447a
movq %rax, %rbx
movq 0x80(%rsp), %rdi
movq %rax, 0x38(%rdi)
movl %r14d, %esi
movq 0x58(%rsp), %r12
movl %r12d, %edx
pushq $0x10
popq %rcx
callq 0x121d7
movq 0x10(%r15), %rdi
movq 0x60(%rsp), %r14
movl 0x48(%r14), %esi
leaq 0x110(%rsp), %rdx
callq 0xdc90
movl 0x38(%rbx), %esi
movq 0x80(%rsp), %rcx
movq 0x18(%rsp), %r8
leaq 0x110(%rsp), %rdi
xorl %edx, %edx
xorl %r9d, %r9d
pushq %r14
pushq %r12
pushq $0x1
popq %rax
pushq %rax
pushq 0x28(%rsp)
callq 0xdde1
addq $0x20, %rsp
leaq 0x80(%rsp), %rdi
callq 0x11cb5
movq (%r15), %r15
jmp 0xe9da
leaq 0x8(%rsp), %rdi
callq 0xd77e
leaq 0x18(%rsp), %rdi
callq 0x2494c
leaq 0x30(%rsp), %rbx
movq 0x28(%rsp), %r14
movq 0x10(%rsp), %r15
movq (%rbx), %rbx
testq %rbx, %rbx
je 0xeaf0
movq 0x8(%rbx), %rax
movq %rax, 0x68(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x12fe3
jmp 0xead3
leaq 0x30(%rsp), %rdi
callq 0x1c583
leaq 0x38(%rsp), %rdi
callq 0x2077b
incq %r15
addq $0x18, %r14
jmp 0xe85a
leaq 0xe0(%rsp), %rbx
xorl %r14d, %r14d
cmpq $0x2, %r14
je 0xeb42
xorl %r15d, %r15d
cmpq $0x18, %r15
je 0xeb39
leaq (%rbx,%r15), %rdi
callq 0xba5e
addq $0x8, %r15
jmp 0xeb24
incq %r14
addq $0x18, %rbx
jmp 0xeb1b
movq 0x40(%rsp), %rbx
testq %rbx, %rbx
je 0xeb5a
movq 0x8(%rbx), %rdi
callq 0x28c2d
movq (%rbx), %rbx
jmp 0xeb47
leaq 0x78(%rsp), %rdi
callq 0x1c583
leaq 0x70(%rsp), %rdi
callq 0x26fa2
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x101da
movl %eax, 0x24(%rsp)
leaq 0x110(%rsp), %rbx
xorl %r12d, %r12d
movl %r13d, %edi
movq %rbx, %rsi
callq 0x2bbc0
cmpl $0x646e65, 0x110(%rsp) # imm = 0x646E65
je 0xed04
leaq 0x6e1f9(%rip), %rdi     # 0x7cdb3
movq %rbx, %rsi
callq 0x1db41
testl %eax, %eax
jne 0xecf4
movq %rbx, %rdi
leaq 0x80(%rsp), %rsi
pushq $0xc
popq %rdx
callq 0x1e59b
cmpl $0x7, %eax
jg 0xebf2
leaq 0x6e2e4(%rip), %rdi     # 0x7cecd
movl %eax, %esi
xorl %eax, %eax
callq 0x223fb
pushq $0x38
popq %rdi
callq 0x28bb0
movq %rax, %r14
movq 0x80(%rsp), %rdi
callq 0x35d13
movl %eax, 0x8(%r14)
movq 0x88(%rsp), %rdi
callq 0x35d13
movl %eax, 0xc(%r14)
pushq $0x28
popq %rdi
callq 0x28bb0
movq %rax, %r15
movq 0x90(%rsp), %rdi
callq 0x1c306
movq %rax, 0x8(%r15)
movq %r12, (%r15)
movq %r15, 0x10(%r14)
movq 0x98(%rsp), %rdi
callq 0x35d13
movl %eax, 0x18(%r14)
movq 0xa0(%rsp), %rdi
callq 0x35d13
movl %eax, 0x1c(%r14)
movq 0xa8(%rsp), %rdi
callq 0x35d13
movl %eax, 0x20(%r14)
movq 0xb0(%rsp), %rax
movq 0xb8(%rsp), %rdi
xorl %r12d, %r12d
cmpb $0x2d, (%rax)
sete %r12b
callq 0x35d13
cltq
imulq $0x18, %r12, %rcx
addq %rsp, %rcx
addq $0xe0, %rcx
movq (%rcx,%rax,8), %rdx
movq %rdx, (%r14)
movq %r14, (%rcx,%rax,8)
movl %r13d, %edi
movq 0x10(%rsp), %rsi
callq 0xd7f6
movq %rax, 0x28(%r14)
movq %rax, %rdi
callq 0x1c4aa
movq %r15, %r12
cmpl 0x20(%r14), %eax
je 0xeb97
leaq 0x6e216(%rip), %rdi     # 0x7cef2
leaq 0x6e0b5(%rip), %rsi     # 0x7cd98
leaq 0x6e233(%rip), %rcx     # 0x7cf1d
movl $0x109, %edx            # imm = 0x109
callq 0x6460
leaq 0x110(%rsp), %rsi
movq %rbp, %rdi
callq 0x101c5
leaq 0xe0(%rsp), %rbx
xorl %r14d, %r14d
cmpq $0x2, %r14
je 0xe832
xorl %r15d, %r15d
cmpq $0x18, %r15
je 0xed31
leaq (%rbx,%r15), %rdi
callq 0x1c567
addq $0x8, %r15
jmp 0xed1c
incq %r14
addq $0x18, %rbx
jmp 0xed0f