// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/jkOwnLib/genoFind.c
// Function: gfIndexTransNibsAndTwoBits
void gfIndexTransNibsAndTwoBits(struct genoFind *transGf[2][3], 
    int fileCount, char *fileNames[], 
    int minMatch, int maxGap, int tileSize, int maxPat, char *oocFile,
    boolean allowOneMismatch, boolean doMask, int stepSize)
/* Make translated (6 frame) index for all .nib and .2bit files. */
{
struct genoFind *gf;
int i,isRc, frame;
bits32 offset[2][3];
char *fileName;
struct dnaSeq *seq;
int sourceCount = 0;
long long totalBases = 0, warnAt = maxTotalBases();

if (allowOneMismatch)
    errAbort("Don't currently support allowOneMismatch in gfIndexTransNibsAndTwoBits");
/* Allocate indices for all reading frames. */
for (isRc=0; isRc <= 1; ++isRc)
    {
    for (frame = 0; frame < 3; ++frame)
	{
	transGf[isRc][frame] = gf = gfNewEmpty(minMatch, maxGap, 
		tileSize, stepSize, maxPat, oocFile, TRUE, allowOneMismatch);
	}
    }

/* Mask simple AA repeats (of period 1 and 2). */
for (isRc = 0; isRc <= 1; ++isRc)
    for (frame = 0; frame < 3; ++frame)
	maskSimplePepRepeat(transGf[isRc][frame]);

/* Scan through .nib and .2bit files once counting tiles. */
for (i=0; i<fileCount; ++i)
    {
    fileName = fileNames[i];
    printf("Counting %s\n", fileName);
    if (nibIsFile(fileName))
	{
	seq = readMaskedNib(fileName, doMask);
	transCountBothStrands(seq, transGf);
	sourceCount += 1;
	totalBases += seq->size;
	freeDnaSeq(&seq);
	}
    else if (twoBitIsFile(fileName))
        {
	struct twoBitFile *tbf = twoBitOpen(fileName);
	struct twoBitIndex *index;
	totalBases += twoBitCheckTotalSize(tbf);

	for (index = tbf->indexList; index != NULL; index = index->next)
	    {
	    seq = readMaskedTwoBit(tbf, index->name, doMask);
	    transCountBothStrands(seq, transGf);
	    sourceCount += 1;
	    freeDnaSeq(&seq);
	    }
	twoBitClose(&tbf);
	}
    else 
	errAbort("Unrecognized file type %s", fileName);
    if (totalBases >= warnAt)
	errAbort("Exceeding 4 billion bases, sorry gfServer can't handle that.");
    }

/* Get space for entries in indexed of all reading frames. */
for (isRc=0; isRc <= 1; ++isRc)
    {
    for (frame = 0; frame < 3; ++frame)
	{
	gf = transGf[isRc][frame];
	gfAllocLists(gf);
	gfZeroNonOverused(gf);
	AllocArray(gf->sources, sourceCount);
	gf->sourceCount = sourceCount;
	offset[isRc][frame] = 0;
	}
    }

/* Scan through nibs a second time building index. */
sourceCount = 0;
for (i=0; i<fileCount; ++i)
    {
    fileName = fileNames[i];
    printf("Indexing %s\n", fileName);
    if (nibIsFile(fileName))
	{
	seq = readMaskedNib(fileName, doMask);
	transIndexBothStrands(seq, transGf, offset, sourceCount, fileName);
	freeDnaSeq(&seq);
	sourceCount += 1;
	}
    else	/* .2bit file */
        {
	struct twoBitFile *tbf = twoBitOpen(fileName);
	struct twoBitIndex *index;
	for (index = tbf->indexList; index != NULL; index = index->next)
	    {
	    char nameBuf[PATH_LEN+256];
	    safef(nameBuf, sizeof(nameBuf), "%s:%s", fileName, index->name);
	    seq = readMaskedTwoBit(tbf, index->name, doMask);
	    transIndexBothStrands(seq, transGf, offset, sourceCount, nameBuf);
	    sourceCount += 1;
	    freeDnaSeq(&seq);
	    }
	twoBitClose(&tbf);
	}
    }

for (isRc=0; isRc <= 1; ++isRc)
    {
    for (frame = 0; frame < 3; ++frame)
	{
	gf = transGf[isRc][frame];
	gf->totalSeqSize = offset[isRc][frame];
	gfZeroOverused(gf);
	}
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
movl %r9d, %ebp
movl %r8d, %r14d
movl %ecx, %r15d
movq %rdx, 0x20(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, (%rsp)
movl 0x3a0(%rsp), %eax
testl %eax, %eax
je 0xb173
leaq 0x718f7(%rip), %rdi     # 0x7ca63
xorl %eax, %eax
callq 0x223fb
movl 0x390(%rsp), %ebx
xorl %eax, %eax
movq (%rsp), %r12
cmpq $0x2, %rax
je 0xb1d8
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
cmpq $0x3, %r13
je 0xb1ca
movl %r15d, %edi
movl %r14d, %esi
movl %ebp, %edx
movl 0x3b0(%rsp), %ecx
movl %ebx, %r8d
movq 0x398(%rsp), %r9
movl 0x3a0(%rsp), %eax
pushq %rax
pushq $0x1
callq 0xae1c
addq $0x10, %rsp
movq %rax, (%r12,%r13,8)
incq %r13
jmp 0xb18e
movq 0x18(%rsp), %rax
incq %rax
addq $0x18, %r12
jmp 0xb180
xorl %ebx, %ebx
movq (%rsp), %r14
cmpq $0x2, %rbx
je 0xb204
xorl %r15d, %r15d
cmpq $0x3, %r15
je 0xb1fb
movq (%r14,%r15,8), %rdi
callq 0xb4f2
incq %r15
jmp 0xb1e7
incq %rbx
addq $0x18, %r14
jmp 0xb1de
xorl %eax, %eax
movq 0x10(%rsp), %rcx
testl %ecx, %ecx
cmovlel %eax, %ecx
movq %rcx, 0x10(%rsp)
leaq 0x7188e(%rip), %r14     # 0x7caaa
leaq 0x8(%rsp), %r13
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r12d, %r12d
cmpq 0x10(%rsp), %r15
je 0xb344
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %rbx
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6070
movq %rbx, %rdi
callq 0x2ce73
testl %eax, %eax
je 0xb291
movq %rbx, %rdi
movl 0x3a8(%rsp), %esi
callq 0xb0c0
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq (%rsp), %rsi
callq 0xb540
incl %ebp
movq 0x8(%rsp), %rax
movslq 0x18(%rax), %rax
addq %rax, %r12
movq %r13, %rdi
callq 0x20737
jmp 0xb31f
movq %rbx, %rdi
callq 0x38f60
testl %eax, %eax
je 0xb30e
movq %rbx, %rdi
callq 0x3842b
movq %rax, 0x50(%rsp)
movq %rax, %rdi
callq 0xb5c0
movq %rax, %rbx
movq 0x50(%rsp), %r14
addq $0x28, %r14
movq (%r14), %r14
testq %r14, %r14
je 0xb2f8
movq 0x50(%rsp), %rdi
movq 0x8(%r14), %rsi
movl 0x3a8(%rsp), %edx
callq 0xb0fb
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq (%rsp), %rsi
callq 0xb540
incl %ebp
movq %r13, %rdi
callq 0x20737
jmp 0xb2be
addq %rbx, %r12
leaq 0x50(%rsp), %rdi
callq 0x3833b
leaq 0x7179e(%rip), %r14     # 0x7caaa
jmp 0xb31f
leaq 0x716f7(%rip), %rdi     # 0x7ca0c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x223fb
movabsq $0x100000000, %rax      # imm = 0x100000000
cmpq %rax, %r12
jl 0xb33c
leaq 0x716f1(%rip), %rdi     # 0x7ca26
xorl %eax, %eax
callq 0x223fb
incq %r15
jmp 0xb229
movslq %ebp, %rax
imulq $0x28, %rax, %r14
leaq 0x30(%rsp), %r15
xorl %eax, %eax
movq (%rsp), %r13
cmpq $0x2, %rax
je 0xb3aa
movq %rax, 0x18(%rsp)
xorl %r12d, %r12d
cmpq $0x3, %r12
je 0xb398
movq (%r13,%r12,8), %rbx
movq %rbx, %rdi
callq 0xaf4f
movq %rbx, %rdi
callq 0xafc6
movq %r14, %rdi
callq 0x28a1f
movq %rax, 0x20(%rbx)
movl %ebp, 0x1c(%rbx)
andl $0x0, (%r15,%r12,4)
incq %r12
jmp 0xb364
movq 0x18(%rsp), %rax
incq %rax
addq $0x18, %r13
addq $0xc, %r15
jmp 0xb356
leaq 0x50(%rsp), %r14
leaq 0x30(%rsp), %r12
xorl %ebx, %ebx
xorl %ebp, %ebp
movq (%rsp), %r15
cmpq 0x10(%rsp), %rbx
je 0xb4ad
movq 0x20(%rsp), %rax
movq (%rax,%rbx,8), %r13
leaq 0x716e0(%rip), %rdi     # 0x7cab7
movq %r13, %rsi
xorl %eax, %eax
callq 0x6070
movq %r13, %rdi
callq 0x2ce73
movq %r13, %rdi
testl %eax, %eax
je 0xb425
movl 0x3a8(%rsp), %esi
callq 0xb0c0
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl %ebp, %ecx
movq %r13, %r8
callq 0xb608
leaq 0x8(%rsp), %rdi
callq 0x20737
incl %ebp
jmp 0xb4a5
callq 0x3842b
movq %rax, %r15
movq %rax, 0x28(%rsp)
addq $0x28, %r15
movq (%r15), %r15
testq %r15, %r15
je 0xb497
movq 0x8(%r15), %r8
movq %r14, %rdi
movl $0x300, %esi            # imm = 0x300
leaq 0x76568(%rip), %rdx     # 0x819b9
movq %r13, %rcx
xorl %eax, %eax
callq 0x1fab2
movq 0x28(%rsp), %rdi
movq 0x8(%r15), %rsi
movl 0x3a8(%rsp), %edx
callq 0xb0fb
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq (%rsp), %rsi
movq %r12, %rdx
movl %ebp, %ecx
movq %r14, %r8
callq 0xb608
incl %ebp
leaq 0x8(%rsp), %rdi
callq 0x20737
jmp 0xb436
leaq 0x28(%rsp), %rdi
callq 0x3833b
movq (%rsp), %r15
incq %rbx
jmp 0xb3bc
xorl %ebx, %ebx
cmpq $0x2, %rbx
je 0xb4e0
xorl %r14d, %r14d
cmpq $0x3, %r14
je 0xb4d3
movq (%r15,%r14,8), %rdi
movl (%r12,%r14,4), %eax
movl %eax, 0x30(%rdi)
callq 0xb09c
incq %r14
jmp 0xb4b8
incq %rbx
addq $0x18, %r15
addq $0xc, %r12
jmp 0xb4af
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq