// File: /workspace/github_c_makefile_star2_O3/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, 0x68(%rsp)
movq %r8, 0x58(%rsp)
movq %rcx, 0x60(%rsp)
movq %rdx, %r12
movq %rsi, 0x50(%rsp)
movq %rdi, %r13
xorl %eax, %eax
movq %rax, (%rsp)
movq %rax, 0x30(%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x40(%rsp)
movq %rax, 0x28(%rsp)
xorl %edi, %edi
callq 0x2c220
movq %rax, %r14
movq %rax, 0x70(%rsp)
movl (%r13), %r15d
xorps %xmm0, %xmm0
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
leaq 0x7d0b4(%rip), %rdx     # 0x8df23
movl %r15d, %edi
movq %r12, %rsi
callq 0x12b22
leaq 0x110(%rsp), %rsi
movl %r15d, %edi
callq 0x311c3
movq %rax, %rbx
leaq 0x7cf7f(%rip), %rdi     # 0x8de13
movq %rax, %rsi
callq 0x21b23
testl %eax, %eax
je 0x10ebd
movq 0x8(%r12), %rsi
leaq 0x7cfdc(%rip), %rdi     # 0x8de88
movq %rbx, %rdx
xorl %eax, %eax
callq 0x26bea
xorl %ebp, %ebp
jmp 0x11097
movq %r14, 0x20(%rsp)
movq %r13, 0x18(%rsp)
movq %rbx, %rdi
callq 0x12bd8
movq %rax, 0x40(%rsp)
leaq 0x110(%rsp), %r13
xorl %ebp, %ebp
movl %r15d, %edi
movq %r13, %rsi
callq 0x311c3
cmpl $0x646e65, 0x110(%rsp) # imm = 0x646E65
je 0x1105a
leaq 0x7cf12(%rip), %rdi     # 0x8de13
movq %r13, %rsi
callq 0x21b23
testl %eax, %eax
jne 0x1103f
movq %r13, %rdi
leaq 0x80(%rsp), %rsi
movl $0xc, %edx
callq 0x226f5
cmpl $0x7, %eax
jg 0x10f3b
leaq 0x7cffb(%rip), %rdi     # 0x8df2d
movl %eax, %esi
xorl %eax, %eax
callq 0x26e94
movl $0x38, %edi
callq 0x2dff4
movq %rax, %rbx
movq 0x80(%rsp), %rdi
callq 0x3bc10
movl %eax, 0x8(%rbx)
movq 0x88(%rsp), %rdi
callq 0x3bc10
movl %eax, 0xc(%rbx)
movl $0x28, %edi
callq 0x2dff4
movq %rax, %r14
movq 0x90(%rsp), %rdi
callq 0x1feba
movq %rax, 0x8(%r14)
movq %rbp, (%r14)
movq %r14, 0x10(%rbx)
movq 0x98(%rsp), %rdi
callq 0x3bc10
movl %eax, 0x18(%rbx)
movq 0xa0(%rsp), %rdi
callq 0x3bc10
movl %eax, 0x1c(%rbx)
movq 0xa8(%rsp), %rdi
callq 0x3bc10
movl %eax, 0x20(%rbx)
movq 0xb0(%rsp), %rax
movq 0xb8(%rsp), %rdi
xorl %ebp, %ebp
cmpb $0x2d, (%rax)
sete %bpl
callq 0x3bc10
cltq
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
leaq 0xe0(%rsp,%rcx,8), %rcx
movq (%rcx,%rax,8), %rdx
movq %rdx, (%rbx)
movq %rbx, (%rcx,%rax,8)
movl %r15d, %edi
movq 0x20(%rsp), %rsi
callq 0xfc90
movq %rax, 0x28(%rbx)
movq %rax, %rdi
callq 0x200ac
movq %r14, %rbp
cmpl 0x20(%rbx), %eax
je 0x10ede
leaq 0x7cf2b(%rip), %rdi     # 0x8df52
leaq 0x7cdca(%rip), %rsi     # 0x8ddf8
leaq 0x7cf48(%rip), %rcx     # 0x8df7d
movl $0x109, %edx            # imm = 0x109
callq 0x6460
movq 0x8(%r12), %rsi
leaq 0x7ce3d(%rip), %rdi     # 0x8de88
leaq 0x110(%rsp), %rdx
xorl %eax, %eax
callq 0x26bea
movb $0x1, %bl
xorl %eax, %eax
movq 0x18(%rsp), %r13
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax,8), %r14
addq $0xe0, %r14
xorl %r15d, %r15d
leaq (%r14,%r15), %rdi
callq 0x20173
addq $0x8, %r15
cmpq $0x18, %r15
jne 0x11075
movl $0x1, %eax
testb $0x1, %bl
movl $0x0, %ebx
jne 0x11063
movq %rbp, 0x48(%rsp)
movq %rbp, 0x78(%rsp)
movl (%r13), %edi
callq 0x6e80
movl $0xffffffff, (%r13)     # imm = 0xFFFFFFFF
movb $0x1, %al
leaq 0x28(%rsp), %r14
leaq 0x8(%rsp), %r13
xorl %ebp, %ebp
movl %eax, 0x3c(%rsp)
leaq (,%rbp,2), %rax
addq %rbp, %rax
leaq (%rsp,%rax,8), %r15
addq $0xe0, %r15
xorl %ebx, %ebx
movq (%r15,%rbx,8), %rdi
movl %ebx, %esi
callq 0x114a9
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x20155
movq %rax, (%rsp)
incq %rbx
cmpq $0x3, %rbx
jne 0x110dc
movq %r15, 0x20(%rsp)
movq %rax, %rdi
callq 0x10dc2
movq %rsp, %rdi
leaq -0x14cb(%rip), %rsi     # 0xfc4c
callq 0x201c4
movq (%rsp), %rdi
leaq 0xafa49(%rip), %rax     # 0xc0b70
movl (%rax), %esi
callq 0xfd63
movq %rax, (%rsp)
movl 0x18(%r12), %ecx
movq %rax, %rdi
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq %rbp, 0x18(%rsp)
movl %ebp, %r8d
movq %r13, %r9
pushq %r14
leaq 0x38(%rsp), %rax
pushq %rax
callq 0x11586
addq $0x10, %rsp
movq (%rsp), %rbx
movq %rbx, 0x80(%rsp)
testq %rbx, %rbx
leaq 0x80(%rsp), %r14
je 0x11191
movq (%rbx), %rbx
movq %r14, %rdi
callq 0xfbac
movq %rbx, 0x80(%rsp)
testq %rbx, %rbx
jne 0x11179
movq $0x0, (%rsp)
xorl %r14d, %r14d
movq 0x20(%rsp), %rax
movq (%rax,%r14,8), %rbx
testq %rbx, %rbx
je 0x11264
movq 0x10(%rbx), %rbp
movq 0x8(%rsp), %r15
movq 0x10(%rbp), %rax
testq %rax, %rax
cmoveq %rbp, %rax
movq 0x8(%rax), %r13
testq %r13, %r13
jne 0x111e5
leaq 0x7ca39(%rip), %rdi     # 0x8dc0b
leaq 0x7cc1f(%rip), %rsi     # 0x8ddf8
movl $0x251, %edx            # imm = 0x251
xorl %eax, %eax
callq 0x26e94
movl 0x18(%rbx), %eax
movl 0x1c(%rbx), %ecx
leal (%rax,%rax,2), %edx
leal (%rcx,%rcx,2), %ecx
movq %r15, %rdi
movq %r13, %rsi
callq 0x15eab
movq 0x18(%rax,%r14,8), %rcx
movq %rcx, 0x10(%rbp)
movslq 0x30(%rax), %rcx
imulq $0x55555556, %rcx, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
movl %ecx, 0x18(%rbp)
movslq 0x34(%rax), %rcx
imulq $0x55555556, %rcx, %rcx # imm = 0x55555556
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
movl %ecx, 0x1c(%rbp)
movq %rbx, %rdi
movq %r12, %rsi
movq 0x40(%rsp), %rdx
movl %r14d, %ecx
movq %rax, %r8
movq %rsp, %r9
pushq $0x0
pushq $0x1
callq 0x1098c
addq $0x10, %rsp
movq (%rbx), %rbx
jmp 0x111a5
incq %r14
cmpq $0x3, %r14
jne 0x1119c
movq %rsp, %rbx
movq %rbx, %rdi
callq 0x20173
movq %rbx, %rdi
leaq -0x163a(%rip), %rsi     # 0xfc4c
callq 0x201c4
movq (%rsp), %rdi
leaq 0xaf8da(%rip), %rax     # 0xc0b70
movslq (%rax), %rax
imulq $0x55555556, %rax, %rsi # imm = 0x55555556
movq %rsi, %rax
shrq $0x3f, %rax
shrq $0x20, %rsi
addl %eax, %esi
callq 0xfd63
movq %rax, %rbx
movq %rax, (%rsp)
testq %rax, %rax
je 0x113c1
movq 0x18(%rbx), %r14
movl $0x48, %edi
callq 0x2dff4
movq %rax, 0x10(%rsp)
movq %r12, 0x10(%rax)
movq %r14, 0x18(%rax)
movq 0x28(%rbx), %rdi
movq %r12, %rsi
callq 0x10529
movq 0x10(%rsp), %rcx
movq %rax, 0x8(%rcx)
movl $0x1, %eax
movl %eax, 0x30(%rcx)
movq 0x8(%rsp), %rdi
movq 0x10(%rbx), %rsi
callq 0x29361
movq %rax, %r14
movq 0x10(%rsp), %rdi
movq %rax, 0x38(%rdi)
movl $0x1, %esi
movq 0x60(%rsp), %rbp
movl %ebp, %edx
movl $0x10, %ecx
callq 0x14f5d
movq 0x10(%rbx), %rdi
movq 0x68(%rsp), %r13
movl 0x48(%r13), %esi
leaq 0x110(%rsp), %r15
movq %r15, %rdx
callq 0x101f3
movl 0x38(%r14), %esi
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %r8
movq %r15, %rdi
xorl %edx, %edx
xorl %r9d, %r9d
pushq %r13
pushq %rbp
movl $0x1, %eax
pushq %rax
pushq 0x30(%rsp)
callq 0x10352
addq $0x20, %rsp
leaq 0x10(%rsp), %rdi
callq 0x149ec
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x112c2
movq (%rsp), %rbx
movq %rbx, 0x80(%rsp)
testq %rbx, %rbx
leaq 0x30(%rsp), %r15
leaq 0x80(%rsp), %rbp
je 0x113ce
movq (%rbx), %rbx
movq %rbp, %rdi
callq 0xfbac
movq %rbx, 0x80(%rsp)
testq %rbx, %rbx
jne 0x113a7
jmp 0x113ce
leaq 0x30(%rsp), %r15
leaq 0x80(%rsp), %rbp
movq $0x0, (%rsp)
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0x298bd
movq 0x28(%rsp), %rbx
testq %rbx, %rbx
leaq 0x28(%rsp), %r14
je 0x1140e
movq 0x8(%rbx), %rax
movq %rax, 0x80(%rsp)
movq %rbp, %rdi
callq 0x15e23
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x113f2
movq %r14, %rdi
callq 0x20196
movq %r15, %rdi
callq 0x24df5
movl $0x1, %ebp
testb $0x1, 0x3c(%rsp)
movl $0x0, %eax
jne 0x110c0
movb $0x1, %bl
xorl %eax, %eax
leaq (%rax,%rax,2), %rax
leaq (%rsp,%rax,8), %r14
addq $0xe0, %r14
xorl %r15d, %r15d
leaq (%r14,%r15), %rdi
callq 0xdbe4
addq $0x8, %r15
cmpq $0x18, %r15
jne 0x11449
movl $0x1, %eax
testb $0x1, %bl
movl $0x0, %ebx
jne 0x11437
movq 0x48(%rsp), %rbx
testq %rbx, %rbx
je 0x11483
movq 0x8(%rbx), %rdi
callq 0x2e0a0
movq (%rbx), %rbx
jmp 0x11470
leaq 0x78(%rsp), %rdi
callq 0x20196
leaq 0x70(%rsp), %rdi
callq 0x2c2c7
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq