// File: /workspace/github_c_makefile_star2_O1/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 $0x378, %rsp            # imm = 0x378
movl %r9d, %r11d
movl %r8d, %r14d
movl %ecx, %r15d
movq %rdx, 0x38(%rsp)
movl %esi, 0x2c(%rsp)
movq %rdi, 0x8(%rsp)
movl 0x3c0(%rsp), %ebx
testl %ebx, %ebx
je 0xd06c
leaq 0x80a24(%rip), %rdi     # 0x8da83
xorl %eax, %eax
movl %r11d, %ebp
callq 0x26b6f
movl %ebp, %r11d
movl 0x3d0(%rsp), %ebp
movq 0x3b8(%rsp), %r12
movl 0x3b0(%rsp), %r8d
xorl %eax, %eax
movq 0x8(%rsp), %rcx
movl %r15d, 0x20(%rsp)
movl %r14d, 0x30(%rsp)
movq %rax, 0x48(%rsp)
xorl %r13d, %r13d
movq %rcx, 0x10(%rsp)
movl %r15d, %edi
movl %r14d, %esi
movl %r11d, %edx
movl %ebp, %ecx
movl %r8d, %r15d
movl %r11d, %r14d
movq %r12, %r9
pushq %rbx
pushq $0x1
callq 0xccd3
movq 0x20(%rsp), %rcx
movl %r15d, %r8d
movl %r14d, %r11d
movl 0x40(%rsp), %r14d
movl 0x30(%rsp), %r15d
addq $0x10, %rsp
movq %rax, (%rcx,%r13,8)
incq %r13
cmpq $0x3, %r13
jne 0xd0a1
movq 0x48(%rsp), %rdx
leaq 0x1(%rdx), %rax
addq $0x18, %rcx
testq %rdx, %rdx
je 0xd094
xorl %r14d, %r14d
movq 0x8(%rsp), %rbx
xorl %r15d, %r15d
movq (%rbx,%r15,8), %rdi
callq 0xd4b6
incq %r15
cmpq $0x3, %r15
jne 0xd100
leaq 0x1(%r14), %rax
addq $0x18, %rbx
testq %r14, %r14
movq %rax, %r14
je 0xd0fd
movl 0x2c(%rsp), %eax
movl %eax, %r15d
testl %eax, %eax
movq %r15, 0x20(%rsp)
jle 0xd288
leaq 0x18(%rsp), %r13
xorl %r12d, %r12d
xorl %ebx, %ebx
xorl %ebp, %ebp
movq 0x8(%rsp), %r14
movq %rbx, 0x10(%rsp)
movq 0x38(%rsp), %rax
movq (%rax,%r12,8), %rbx
leaq 0x8096e(%rip), %rdi     # 0x8daca
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6070
movq %rbx, %rdi
callq 0x3221b
testl %eax, %eax
je 0xd1b1
movq %rbx, %rdi
movl 0x3c8(%rsp), %esi
callq 0xcfb1
movq %rax, 0x18(%rsp)
movq %rax, %rdi
movq %r14, %rsi
callq 0xd4fe
incl %ebp
movq 0x18(%rsp), %rax
movslq 0x18(%rax), %rax
movq 0x10(%rsp), %rbx
addq %rax, %rbx
movq %r13, %rdi
callq 0x24ab1
jmp 0xd25d
movq %rbx, %rdi
callq 0x3ec3e
testl %eax, %eax
je 0xd227
movq %rbx, %rdi
callq 0x3e08d
movq %rax, 0x70(%rsp)
movq %rax, %rdi
callq 0xd57e
movq %rax, 0x30(%rsp)
movq 0x70(%rsp), %rax
movq 0x28(%rax), %rbx
testq %rbx, %rbx
je 0xd23f
movq 0x8(%rsp), %r14
movl 0x3c8(%rsp), %r15d
movq 0x70(%rsp), %rdi
movq 0x8(%rbx), %rsi
movl %r15d, %edx
callq 0xcfee
movq %rax, 0x18(%rsp)
movq %rax, %rdi
movq %r14, %rsi
callq 0xd4fe
incl %ebp
movq %r13, %rdi
callq 0x24ab1
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0xd1f2
jmp 0xd244
leaq 0x807fe(%rip), %rdi     # 0x8da2c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x26b6f
movq 0x10(%rsp), %rbx
jmp 0xd25d
movq 0x8(%rsp), %r14
movq 0x10(%rsp), %rbx
addq 0x30(%rsp), %rbx
leaq 0x70(%rsp), %rdi
callq 0x3df96
movq 0x20(%rsp), %r15
movabsq $0x100000000, %rax      # imm = 0x100000000
cmpq %rax, %rbx
jl 0xd27a
leaq 0x807d3(%rip), %rdi     # 0x8da46
xorl %eax, %eax
callq 0x26b6f
incq %r12
cmpq %r15, %r12
jne 0xd147
jmp 0xd28a
xorl %ebp, %ebp
movslq %ebp, %rax
shlq $0x3, %rax
leaq (%rax,%rax,4), %r14
xorl %eax, %eax
movq %rax, 0x10(%rsp)
leaq (%rax,%rax,2), %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
leaq (%rsp,%rax,4), %r13
addq $0x50, %r13
xorl %r15d, %r15d
movq (%r12,%r15,8), %rbx
movq %rbx, %rdi
callq 0xce4f
movslq 0x14(%rbx), %rax
testq %rax, %rax
jle 0xd2e5
movq 0x38(%rbx), %rcx
movl (%rbx), %edx
xorl %esi, %esi
cmpl %edx, (%rcx,%rsi,4)
jae 0xd2dd
movl $0x0, (%rcx,%rsi,4)
incq %rsi
cmpq %rsi, %rax
jne 0xd2d1
movq %r14, %rdi
callq 0x2db04
movq %rax, 0x20(%rbx)
movl %ebp, 0x1c(%rbx)
movl $0x0, (%r13,%r15,4)
incq %r15
cmpq $0x3, %r15
jne 0xd2b4
movq 0x10(%rsp), %rcx
leaq 0x1(%rcx), %rax
testq %rcx, %rcx
je 0xd297
cmpl $0x0, 0x2c(%rsp)
movq 0x20(%rsp), %r15
jle 0xd442
leaq 0x807ac(%rip), %r12     # 0x8dad7
leaq 0x50(%rsp), %rbx
leaq 0x18(%rsp), %r13
xorl %ecx, %ecx
xorl %ebp, %ebp
movq 0x38(%rsp), %rax
movq %rcx, 0x10(%rsp)
movq (%rax,%rcx,8), %r14
movq %r12, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x6070
movq %r14, %rdi
callq 0x3221b
movq %r14, %rdi
testl %eax, %eax
je 0xd398
movl 0x3c8(%rsp), %esi
callq 0xcfb1
movq %rax, 0x18(%rsp)
movq %rax, %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %rdx
movl %ebp, %ecx
movq %r14, %r8
callq 0xd5c6
movq %r13, %rdi
callq 0x24ab1
incl %ebp
jmp 0xd431
callq 0x3e08d
movq %rax, 0x40(%rsp)
movq 0x28(%rax), %r15
testq %r15, %r15
je 0xd416
movq %r14, %r12
movq 0x8(%rsp), %r14
leaq 0x70(%rsp), %rbx
movq 0x8(%r15), %r8
movq %rbx, %rdi
movl $0x300, %esi            # imm = 0x300
leaq 0x855fe(%rip), %rdx     # 0x929c9
movq %r12, %rcx
xorl %eax, %eax
callq 0x23c18
movq 0x40(%rsp), %rdi
movq 0x8(%r15), %rsi
movl 0x3c8(%rsp), %edx
callq 0xcfee
movq %rax, 0x18(%rsp)
movq %rax, %rdi
movq %r14, %rsi
leaq 0x50(%rsp), %rdx
movl %ebp, %ecx
movq %rbx, %r8
callq 0xd5c6
incl %ebp
movq %r13, %rdi
callq 0x24ab1
movq (%r15), %r15
testq %r15, %r15
jne 0xd3b8
leaq 0x40(%rsp), %rdi
callq 0x3df96
movq 0x20(%rsp), %r15
leaq 0x806ab(%rip), %r12     # 0x8dad7
leaq 0x50(%rsp), %rbx
movq 0x10(%rsp), %rcx
incq %rcx
cmpq %r15, %rcx
jne 0xd339
xorl %eax, %eax
movq 0x8(%rsp), %r11
leaq (%rax,%rax,2), %rdx
leaq (%r11,%rdx,8), %rcx
leaq (%rsp,%rdx,4), %rdx
addq $0x50, %rdx
xorl %esi, %esi
movq (%rcx,%rsi,8), %r9
movl (%rdx,%rsi,4), %edi
movl %edi, 0x30(%r9)
movslq 0x14(%r9), %rdi
testq %rdi, %rdi
jle 0xd48f
movq 0x38(%r9), %r8
movl (%r9), %r9d
xorl %r10d, %r10d
cmpl %r9d, (%r8,%r10,4)
jb 0xd487
movl $0x0, (%r8,%r10,4)
incq %r10
cmpq %r10, %rdi
jne 0xd479
incq %rsi
cmpq $0x3, %rsi
jne 0xd45b
leaq 0x1(%rax), %rcx
testq %rax, %rax
movq %rcx, %rax
je 0xd449
addq $0x378, %rsp            # imm = 0x378
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq