// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/jkOwnLib/genoFind.c
// Function: gfMakeOoc
void gfMakeOoc(char *outName, char *files[], int fileCount, 
	int tileSize, bits32 maxPat, enum gfType tType)
/* Count occurences of tiles in seqList and make a .ooc file. */
{
boolean dbIsPep = (tType == gftProt || tType == gftDnaX || tType == gftRnaX);
struct genoFind *gf = gfNewEmpty(gfMinMatch, gfMaxGap, tileSize, tileSize,
	maxPat, NULL, dbIsPep, FALSE);
bits32 *sizes = gf->listSizes;
int tileSpaceSize = gf->tileSpaceSize;
bioSeq *seq, *seqList;
bits32 sig = oocSig, psz = tileSize;
bits32 i;
int oocCount = 0;
char *inName;
FILE *f = mustOpen(outName, "w");


unsigned faFastBufSize = 0;
DNA     *faFastBuf = NULL;


if (gf->segSize > 0)
    errAbort("Don't yet know how to make ooc files for large tile sizes.");
for (i=0; i<fileCount; ++i)
    {
    inName = files[i];
    printf("Loading %s\n", inName);
    if (nibIsFile(inName))
        {
	seqList = nibLoadAll(inName);
	}
    else if (twoBitIsFile(inName))
        {
	seqList = twoBitLoadAll(inName);
	for (seq = seqList; seq != NULL; seq = seq->next)
	    toLowerN(seq->dna, seq->size);
	}
    else
        {
	seqList = faReadAllSeq(inName, tType != gftProt, &faFastBuf, &faFastBufSize);
    faFreeFastBuf(&faFastBuf, &faFastBufSize);
	}
    printf("Counting %s\n", inName);
    for (seq = seqList; seq != NULL; seq = seq->next)
	{
	int isRc;
	for (isRc = 0; isRc <= 1; ++isRc)
	    {
	    if (tType == gftDnaX || tType == gftRnaX)
		{
		struct trans3 *t3 = trans3New(seq);
		int frame;
		for (frame=0; frame<3; ++frame)
		    {
		    gfCountSeq(gf, t3->trans[frame]);
		    }
		trans3Free(&t3);
		}
	    else
		{
		gfCountSeq(gf, seq);
		}
	    if (tType == gftProt || tType == gftRnaX)
	        break;
	    else 
	        {
		reverseComplement(seq->dna, seq->size);
		}
	    }
	}
    freeDnaSeqList(&seqList);
    }
printf("Writing %s\n", outName);
writeOne(f, sig);
writeOne(f, psz);
for (i=0; i<tileSpaceSize; ++i)
    {
    if (sizes[i] >= maxPat)
	{
	writeOne(f, i);
	++oocCount;
	}
    }
carefulClose(&f);
genoFindFree(&gf);
printf("Wrote %d overused %d-mers to %s\n", oocCount, tileSize, outName);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, %r15d
movl %ecx, %ebp
movl %edx, 0x4(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdi, %r14
movl %r9d, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
sete %al
cmpl $0x4, %r9d
sete %cl
orb %al, %cl
movzbl %cl, %eax
xorl %ebx, %ebx
movl $0x2, %edi
movl $0x2, %esi
movl %ebp, %edx
movl %ebp, %ecx
movl %r8d, 0x28(%rsp)
xorl %r9d, %r9d
pushq %rbx
pushq %rax
callq 0xccd3
addq $0x10, %rsp
movq %rax, 0x18(%rsp)
movq 0x38(%rax), %rcx
movq %rcx, 0x48(%rsp)
movl 0x14(%rax), %eax
movl %eax, 0x24(%rsp)
movl $0x584155f2, 0x3c(%rsp) # imm = 0x584155F2
movl %ebp, 0x2c(%rsp)
movl %ebp, 0x38(%rsp)
leaq 0x7fd43(%rip), %rsi     # 0x8ec89
movq %r14, 0x50(%rsp)
movq %r14, %rdi
callq 0x22d5a
movq %rax, 0x8(%rsp)
movl %ebx, 0x34(%rsp)
movq $0x0, 0x60(%rsp)
movq 0x18(%rsp), %rax
cmpl %ebx, 0x2c(%rax)
jle 0xef7d
leaq 0x7eb87(%rip), %rdi     # 0x8dafd
xorl %eax, %eax
callq 0x26b6f
movl $0x0, (%rsp)
cmpl $0x0, 0x4(%rsp)
je 0xf0f6
xorl %eax, %eax
cmpl $0x2, %r15d
setne %al
movl %eax, 0x30(%rsp)
leal -0x3(%r15), %r13d
leaq 0x40(%rsp), %r14
xorl %eax, %eax
movl %eax, %eax
movq 0x58(%rsp), %rcx
movq (%rcx,%rax,8), %rbx
leaq 0x7eb7f(%rip), %rdi     # 0x8db38
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6070
movq %rbx, %rdi
callq 0x3221b
movq %rbx, %rdi
testl %eax, %eax
je 0xf08c
callq 0x31eda
movq %rax, 0x10(%rsp)
leaq 0x7eae3(%rip), %rdi     # 0x8daca
movq %rbx, %rsi
xorl %eax, %eax
callq 0x6070
movq 0x10(%rsp), %rbx
testq %rbx, %rbx
je 0xf06e
xorl %ebp, %ebp
cmpl $0x1, %r13d
ja 0xf03a
movq %rbx, %rdi
callq 0x15d78
movq %rax, 0x40(%rsp)
xorl %r12d, %r12d
movq 0x18(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x18(%rax,%r12,8), %rsi
callq 0xf1ba
incq %r12
cmpq $0x3, %r12
jne 0xf013
movq %r14, %rdi
callq 0x15ddb
jmp 0xf047
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0xf1ba
cmpl $0x2, %r15d
je 0xf069
cmpl $0x4, %r15d
je 0xf069
movq 0x10(%rbx), %rdi
movslq 0x18(%rbx), %rsi
callq 0x250f6
leal 0x1(%rbp), %eax
testl %ebp, %ebp
movl %eax, %ebp
je 0xeffd
movq (%rbx), %rbx
jmp 0xeff6
leaq 0x10(%rsp), %rdi
callq 0x24af5
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
cmpl 0x4(%rsp), %eax
jb 0xefa7
jmp 0xf0f6
callq 0x3ec3e
movq %rbx, %rdi
testl %eax, %eax
je 0xf0c8
callq 0x3e9b8
movq %rax, 0x10(%rsp)
testq %rax, %rax
je 0xefe0
movq %rax, %rbp
movq 0x10(%rbp), %rdi
movl 0x18(%rbp), %esi
callq 0x21c6b
movq (%rbp), %rbp
testq %rbp, %rbp
jne 0xf0ae
jmp 0xefe0
movl 0x30(%rsp), %esi
leaq 0x60(%rsp), %r12
movq %r12, %rdx
leaq 0x34(%rsp), %rbp
movq %rbp, %rcx
callq 0x27d67
movq %rax, 0x10(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x275e3
jmp 0xefe0
leaq 0x7ea47(%rip), %rdi     # 0x8db44
xorl %ebx, %ebx
movq 0x50(%rsp), %r15
movq %r15, %rsi
xorl %eax, %eax
callq 0x6070
movq 0x8(%rsp), %rdi
leaq 0x3c(%rsp), %rsi
movl $0x4, %edx
callq 0x22e1e
movq 0x8(%rsp), %rdi
leaq 0x38(%rsp), %rsi
movl $0x4, %edx
callq 0x22e1e
movl $0x0, (%rsp)
movl 0x24(%rsp), %r13d
testl %r13d, %r13d
movl 0x28(%rsp), %ebp
movq 0x48(%rsp), %r12
je 0xf180
xorl %ebx, %ebx
movq %rsp, %r14
xorl %eax, %eax
movl %eax, %eax
cmpl %ebp, (%r12,%rax,4)
jb 0xf173
movq 0x8(%rsp), %rdi
movl $0x4, %edx
movq %r14, %rsi
callq 0x22e1e
incl %ebx
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
cmpl %r13d, %eax
jb 0xf157
leaq 0x8(%rsp), %rdi
callq 0x23400
leaq 0x18(%rsp), %rdi
callq 0xc6e0
leaq 0x7e9b5(%rip), %rdi     # 0x8db50
movl %ebx, %esi
movl 0x2c(%rsp), %edx
movq %r15, %rcx
xorl %eax, %eax
callq 0x6070
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq