// File: /workspace/github_c_makefile_star2_O2/icebert[P]pblat/jkOwnLib/patSpace.c
// Function: makePatSpace
struct patSpace *makePatSpace(
    struct dnaSeq **seqArray,       /* Array of sequence lists. */
    int seqArrayCount,              /* Size of above array. */
    int seedSize,	            /* Alignment seed size - 10 or 11. Must match oocFileName */
    char *oocFileName,              /* File with tiles to filter out, may be NULL. */
    int minMatch,                   /* Minimum # of matching tiles.  4 is good. */
    int maxGap                      /* Maximum gap size - 32k is good for 
                                       cDNA (introns), 500 is good for DNA assembly. */
    )
/* Allocate a pattern space and fill from sequences.  (Each element of
   seqArray is a list of sequences. */
{
struct patSpace *ps = newPatSpace(minMatch, maxGap,seedSize);
int i;
int startIx = 0;
int total = 0;
struct dnaSeq *seq;
psBits maxPat;
psBits *listSizes;
int seedSpaceSize = ps->seedSpaceSize;

maxPat = ps->maxPat = maxPatCount;
for (i=0; i<seqArrayCount; ++i)
    {
    for (seq = seqArray[i]; seq != NULL; seq = seq->next)
        {
        total += seq->size;
        countPatSpace(ps, seq);
        }
    }

listSizes = ps->listSizes;

/* Scan through over-popular patterns and set their count to value 
 * where they won't be added to pat space. */
oocMaskCounts(oocFileName, listSizes, ps->seedSize, maxPat);

/* Get rid of simple repeats as well. */
oocMaskSimpleRepeats(listSizes, ps->seedSize, maxPat);


allocPatSpaceLists(ps);

/* Zero out pattern counts that aren't oversubscribed. */
for (i=0; i<ps->seedSpaceSize; ++i)
    {
    if (listSizes[i] < maxPat)
        listSizes[i] = 0;
    }
for (i=0; i<seqArrayCount; ++i)
    {
	int j;
    for (seq = seqArray[i], j=0; seq != NULL; seq = seq->next, ++j)
        {
        startIx = addToPatSpace(ps, i, j, seq, startIx);
        if (startIx >= maxBlockCount)
	    tooManyBlocks();
        }
    }
ps->blocksUsed = startIx;

/* Zero local over-popular patterns. */
for (i=0; i<seedSpaceSize; ++i)
    {
    if (listSizes[i] >= maxPat)
        listSizes[i] = 0;
    }

return ps;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, 0x20(%rsp)
movl %r8d, 0x38(%rsp)
movq %rcx, 0x28(%rsp)
movl %edx, %r13d
movl %esi, %r14d
movq %rdi, 0x40(%rsp)
leal (,%r13,2), %ebx
movl $0xe60018, %edi         # imm = 0xE60018
callq 0x28bb0
movq %rax, %r15
pushq $0x1
popq %rax
movl %eax, %ebp
movl %ebx, %ecx
shll %cl, %ebp
movl %r13d, 0xe6000c(%r15)
movl %ebp, 0xe60010(%r15)
leaq (,%rbp,8), %rdi
callq 0x28a1f
movq %rax, (%r15)
shlq $0x2, %rbp
movq %rbp, %rdi
callq 0x28a1f
movq %r15, %rdi
movq %rax, %r12
movq %rax, 0x8(%r15)
movl 0x38(%rsp), %eax
movl %eax, 0xe60004(%r15)
movl 0x20(%rsp), %eax
movl %eax, 0xe60008(%r15)
movl 0xe60010(%r15), %eax
movq %rax, 0x58(%rsp)
movq %r15, 0x50(%rsp)
movl $0x4000, 0xe60000(%r15) # imm = 0x4000
xorl %eax, %eax
testl %r14d, %r14d
cmovlel %eax, %r14d
movq %r14, 0x48(%rsp)
leaq 0xa0675(%rip), %r14     # 0xb5c90
movq %r15, (%rsp)
cmpq 0x48(%rsp), %rax
je 0x156ce
movq 0x40(%rsp), %rcx
leaq (%rcx,%rax,8), %rcx
movq (%rcx), %rcx
testq %rcx, %rcx
je 0x156c6
movslq 0x18(%rcx), %rdx
movslq 0xe60010(%rdi), %rsi
movslq 0xe6000c(%rdi), %rdi
cmpl $0x2, %edi
pushq $0x1
popq %r8
movl %r8d, %r10d
cmovgel %edi, %r10d
movq 0x10(%rcx), %r8
decl %r10d
xorl %r11d, %r11d
xorl %r9d, %r9d
cmpq %r11, %r10
je 0x15683
movsbq (%r8,%r11), %rbx
shll $0x2, %r9d
addl (%r14,%rbx,4), %r9d
incq %r11
jmp 0x1566c
decq %rsi
decq %rdi
cmpq %rdx, %rdi
jge 0x156bd
movsbq (%r8,%rdi), %r10
movslq (%r14,%r10,4), %r10
shll $0x2, %r9d
movslq %r9d, %r9
addq %r10, %r9
andq %rsi, %r9
movl (%r12,%r9,4), %r10d
cmpl $0x3fff, %r10d          # imm = 0x3FFF
jg 0x156b8
incl %r10d
movl %r10d, (%r12,%r9,4)
incq %rdi
jmp 0x15689
movq (%rsp), %rdi
jmp 0x15633
incq %rax
jmp 0x1561f
movl 0xe6000c(%rdi), %edx
movq 0x28(%rsp), %rdi
movq %r12, %rsi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x11af0
movq (%rsp), %rax
movl 0xe6000c(%rax), %esi
movq %r12, %rdi
movl $0x4000, %edx           # imm = 0x4000
callq 0x11c0b
movq (%rsp), %rax
movq (%rax), %rbx
movq 0x8(%rax), %r14
movl 0xe60000(%rax), %ebp
movl 0xe60010(%rax), %r15d
xorl %eax, %eax
testl %r15d, %r15d
cmovlel %eax, %r15d
xorl %edx, %edx
xorl %ecx, %ecx
cmpq %rdx, %r15
je 0x15737
movl (%r14,%rdx,4), %esi
cmpl %ebp, %esi
cmovael %eax, %esi
addl %esi, %ecx
incq %rdx
jmp 0x15722
movslq %ecx, %rdi
shlq $0x2, %rdi
callq 0x289b8
movq (%rsp), %rdi
movq %rax, 0x10(%rdi)
xorl %ecx, %ecx
cmpq %rcx, %r15
je 0x15767
movslq (%r14,%rcx,4), %rdx
cmpl %ebp, %edx
jae 0x15762
movq %rax, (%rbx,%rcx,8)
leaq (%rax,%rdx,4), %rax
incq %rcx
jmp 0x1574d
xorl %eax, %eax
leaq 0xa0520(%rip), %r14     # 0xb5c90
movslq 0xe60010(%rdi), %rcx
cmpq %rcx, %rax
jge 0x15790
cmpl $0x3fff, (%r12,%rax,4)  # imm = 0x3FFF
ja 0x1578b
andl $0x0, (%r12,%rax,4)
incq %rax
jmp 0x15770
addq $0x398018, 0x50(%rsp)   # imm = 0x398018
movq $0x0, 0x10(%rsp)
xorl %r10d, %r10d
movq %r12, 0x60(%rsp)
movq 0x10(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0x15a07
movq 0x40(%rsp), %rax
movq 0x10(%rsp), %rcx
leaq (%rax,%rcx,8), %r9
movl $0x0, 0xc(%rsp)
movq (%r9), %r9
testq %r9, %r9
je 0x159fd
movslq 0x18(%r9), %r11
movslq 0xe60010(%rdi), %rbx
movq 0x10(%r9), %rax
movq %rax, 0x28(%rsp)
movl 0xe60000(%rdi), %eax
movl %eax, 0x1c(%rsp)
movq (%rdi), %rax
movq %rax, 0x38(%rsp)
movq 0x8(%rdi), %rax
movq %rax, 0x20(%rsp)
movslq %r10d, %rax
imulq $0x18, %rax, %rdx
movq 0x50(%rsp), %rsi
movq 0x10(%rsp), %rax
movw %ax, (%rsi,%rdx)
movl 0xc(%rsp), %eax
movw %ax, 0x2(%rsi,%rdx)
movq %r9, 0x8(%rsi,%rdx)
andl $0x0, 0x10(%rsi,%rdx)
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r11d
cmovll %r11d, %eax
movl %eax, 0x14(%rsi,%rdx)
movslq 0xe6000c(%rdi), %rax
cmpl $0x2, %eax
pushq $0x1
popq %rcx
cmovgel %eax, %ecx
leaq (%rsi,%rdx), %r15
decl %ecx
xorl %edx, %edx
xorl %r13d, %r13d
cmpq %rdx, %rcx
je 0x1587a
movq 0x28(%rsp), %rsi
movsbq (%rsi,%rdx), %rsi
shll $0x2, %r13d
addl (%r14,%rsi,4), %r13d
incq %rdx
jmp 0x1585e
movq %rbx, %rdx
decq %rdx
addq $0x18, %r15
movq %rax, %rbp
decq %rbp
movl %eax, %ebx
notl %ebx
leal 0x1(%rax), %r14d
movl $0x100, %r12d           # imm = 0x100
movq %r9, 0x30(%rsp)
movl 0x1c(%rsp), %esi
movq %r11, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
cmpq %r11, %rbp
jge 0x1597c
movq 0x28(%rsp), %rax
movsbq (%rax,%rbp), %rax
leaq 0xa03cb(%rip), %rcx     # 0xb5c90
movslq (%rcx,%rax,4), %rax
shll $0x2, %r13d
movslq %r13d, %r13
addq %rax, %r13
andq %rdx, %r13
movq 0x20(%rsp), %rax
movslq (%rax,%r13,4), %rax
cmpl %esi, %eax
jae 0x158fc
leal 0x1(%rax), %ecx
movq 0x20(%rsp), %r8
movl %ecx, (%r8,%r13,4)
movq 0x38(%rsp), %rcx
movq (%rcx,%r13,8), %rcx
movl %r10d, (%rcx,%rax,4)
decl %r12d
jne 0x1596f
cmpl $0x72ffe, %r10d         # imm = 0x72FFE
jl 0x1592c
movq %r10, %r12
callq 0x15547
movl 0x1c(%rsp), %esi
movq 0x68(%rsp), %rdx
movq 0x70(%rsp), %r11
movq %r12, %r10
movq 0x30(%rsp), %r9
movq (%rsp), %rdi
movq 0x10(%rsp), %rax
movw %ax, (%r15)
movl 0xc(%rsp), %eax
movw %ax, 0x2(%r15)
movq %r9, 0x8(%r15)
movl 0xe6000c(%rdi), %eax
movl %r14d, %ecx
subl %eax, %ecx
movl %ecx, 0x10(%r15)
addl 0x18(%r9), %eax
incl %r10d
addl %ebx, %eax
movl $0x100, %r12d           # imm = 0x100
cmpl %r12d, %eax
cmovgel %r12d, %eax
movl %eax, 0x14(%r15)
addq $0x18, %r15
incq %rbp
decl %ebx
incl %r14d
jmp 0x158ab
xorl %ebx, %ebx
leaq 0xa030b(%rip), %r14     # 0xb5c90
movl 0xe6000c(%rdi), %eax
decl %eax
cmpl %eax, %ebx
jge 0x159c3
decl %r12d
je 0x159a0
movl %r10d, %ebp
incl %ebx
movl %ebp, %r10d
jmp 0x15985
leal 0x1(%r10), %ebp
movl $0x100, %r12d           # imm = 0x100
cmpl $0x72ffe, %r10d         # imm = 0x72FFE
jl 0x15999
callq 0x15547
movq 0x30(%rsp), %r9
movq (%rsp), %rdi
jmp 0x15999
xorl %eax, %eax
cmpl $0x100, %r12d           # imm = 0x100
setne %al
addl %eax, %r10d
cmpl $0x72fff, %r10d         # imm = 0x72FFF
jl 0x159ef
movq %r10, %rbx
callq 0x15547
movq %rbx, %r10
movq 0x30(%rsp), %r9
movq (%rsp), %rdi
incl 0xc(%rsp)
movq 0x60(%rsp), %r12
jmp 0x157d0
incq 0x10(%rsp)
jmp 0x157aa
movl %r10d, 0x18(%rdi)
xorl %eax, %eax
movq 0x58(%rsp), %rcx
testl %ecx, %ecx
cmovlel %eax, %ecx
cmpq %rax, %rcx
je 0x15a30
cmpl $0x4000, (%r12,%rax,4)  # imm = 0x4000
jb 0x15a2b
andl $0x0, (%r12,%rax,4)
incq %rax
jmp 0x15a17
movq %rdi, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq