// File: /workspace/github_c_makefile_star2_O1/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 $0x88, %rsp
movl %r9d, 0x20(%rsp)
movl %r8d, %r12d
movq %rcx, 0x28(%rsp)
movl %edx, %r15d
movl %esi, %r13d
movq %rdi, 0x50(%rsp)
leal (%r15,%r15), %ebx
movl $0xe60018, %edi         # imm = 0xE60018
callq 0x2dc95
movl $0x1, %ebp
movl %ebx, %ecx
shll %cl, %ebp
movq %rax, %rbx
movl %r15d, 0xe6000c(%rax)
movl %ebp, 0xe60010(%rax)
leaq (,%rbp,8), %rdi
callq 0x2db04
movq %rax, (%rbx)
shlq $0x2, %rbp
movq %rbp, %rdi
callq 0x2db04
movq %rax, %r14
movq %rax, 0x8(%rbx)
movl %r12d, 0xe60004(%rbx)
movq %rbx, %r12
movl 0x20(%rsp), %eax
movl %eax, 0xe60008(%rbx)
movl 0xe60010(%rbx), %eax
movq %rax, 0x68(%rsp)
movl $0x4000, 0xe60000(%rbx) # imm = 0x4000
movl %r13d, %eax
movq %rax, 0x48(%rsp)
testl %r13d, %r13d
jle 0x18663
xorl %eax, %eax
leaq 0xa96bc(%rip), %rcx     # 0xc1c70
movq 0x50(%rsp), %rdx
movq (%rdx,%rax,8), %rdx
testq %rdx, %rdx
je 0x18655
movq 0x10(%rdx), %rsi
movl 0xe6000c(%r12), %r10d
leal -0x1(%r10), %r11d
xorl %edi, %edi
cmpl $0x2, %r10d
jl 0x185f9
movl %r11d, %r8d
xorl %r9d, %r9d
xorl %edi, %edi
movsbq (%rsi,%r9), %rbx
shll $0x2, %edi
addl (%rcx,%rbx,4), %edi
incq %r9
cmpq %r9, %r8
jne 0x185e6
movl 0x18(%rdx), %r8d
cmpl %r8d, %r10d
jg 0x1864d
movslq 0xe60010(%r12), %r9
decq %r9
movslq %r11d, %r11
subl %r10d, %r8d
incl %r8d
addq %r11, %rsi
xorl %r10d, %r10d
movsbq (%rsi,%r10), %r11
movslq (%rcx,%r11,4), %r11
shll $0x2, %edi
movslq %edi, %rdi
addq %r11, %rdi
andq %r9, %rdi
movl (%r14,%rdi,4), %r11d
cmpl $0x3fff, %r11d          # imm = 0x3FFF
jg 0x18645
incl %r11d
movl %r11d, (%r14,%rdi,4)
incq %r10
cmpl %r10d, %r8d
jne 0x1861c
movq (%rdx), %rdx
jmp 0x185bd
incq %rax
cmpq 0x48(%rsp), %rax
jne 0x185b4
movl 0xe6000c(%r12), %edx
movq 0x28(%rsp), %rdi
movq %r14, %rsi
movl $0x4000, %ecx           # imm = 0x4000
callq 0x1474c
movl 0xe6000c(%r12), %esi
movq %r14, 0x40(%rsp)
movq %r14, %rdi
movl $0x4000, %edx           # imm = 0x4000
callq 0x14891
movq 0x8(%r12), %rbx
movl 0xe60000(%r12), %ebp
movslq 0xe60010(%r12), %r14
xorl %edi, %edi
testq %r14, %r14
jle 0x186d0
xorl %ecx, %ecx
xorl %eax, %eax
movl (%rbx,%rcx,4), %edx
cmpl %ebp, %edx
cmovael %edi, %edx
addl %edx, %eax
incq %rcx
cmpq %rcx, %r14
jne 0x186b7
movslq %eax, %rdi
shlq $0x2, %rdi
movq (%r12), %r15
callq 0x2da9d
movq %rax, 0x10(%r12)
testl %r14d, %r14d
jle 0x186fd
xorl %ecx, %ecx
movslq (%rbx,%rcx,4), %rdx
cmpl %ebp, %edx
jae 0x186f5
movq %rax, (%r15,%rcx,8)
leaq (%rax,%rdx,4), %rax
incq %rcx
cmpq %rcx, %r14
jne 0x186e5
cmpl $0x0, 0xe60010(%r12)
movq 0x40(%rsp), %rdx
jle 0x1872f
xorl %eax, %eax
cmpl $0x3fff, (%rdx,%rax,4)  # imm = 0x3FFF
ja 0x1871f
movl $0x0, (%rdx,%rax,4)
incq %rax
movslq 0xe60010(%r12), %rcx
cmpq %rcx, %rax
jl 0x1870f
testl %r13d, %r13d
jle 0x18a40
movq %r12, %rax
addq $0x398018, %rax         # imm = 0x398018
movq %rax, 0x58(%rsp)
leaq 0xa9523(%rip), %r8      # 0xc1c70
movq $0x0, 0x10(%rsp)
xorl %r14d, %r14d
movq %r12, 0x60(%rsp)
movq 0x50(%rsp), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %r10
testq %r10, %r10
je 0x18a26
xorl %r11d, %r11d
movl 0x18(%r10), %esi
movslq 0xe60010(%r12), %rax
movq %rax, 0x30(%rsp)
movq 0x10(%r10), %rbx
movl 0xe60000(%r12), %eax
movl %eax, 0x1c(%rsp)
movq (%r12), %rax
movq %rax, 0x80(%rsp)
movq 0x8(%r12), %rax
movq %rax, 0x28(%rsp)
movslq %r14d, %rax
leaq (%rax,%rax,2), %rax
movq 0x58(%rsp), %rdx
movq 0x10(%rsp), %rcx
movw %cx, (%rdx,%rax,8)
movw %r11w, 0x2(%rdx,%rax,8)
movq %r10, 0x8(%rdx,%rax,8)
movl $0x0, 0x10(%rdx,%rax,8)
movl $0x100, %ecx            # imm = 0x100
cmpl %ecx, %esi
movl %esi, %r15d
cmovll %esi, %ecx
movl %ecx, 0x14(%rdx,%rax,8)
movl 0xe6000c(%r12), %edx
leal -0x1(%rdx), %ecx
movl $0x0, %ebp
movq %rdx, %r9
cmpl $0x2, %edx
jl 0x1881a
movl %ecx, %edx
xorl %esi, %esi
xorl %ebp, %ebp
movsbq (%rbx,%rsi), %rdi
shll $0x2, %ebp
addl (%r8,%rdi,4), %ebp
incq %rsi
cmpq %rsi, %rdx
jne 0x18806
movl $0x100, %r13d           # imm = 0x100
cmpl %r15d, %r9d
movq %r10, 0x38(%rsp)
movl %r11d, 0xc(%rsp)
jg 0x1896e
movl %r15d, %esi
movq 0x30(%rsp), %rdi
decq %rdi
movq 0x58(%rsp), %rdx
leaq (%rdx,%rax,8), %rax
addq $0x18, %rax
movq %rax, 0x20(%rsp)
movslq %ecx, %rax
movl %r9d, %ecx
negl %ecx
movq %rcx, 0x70(%rsp)
subl %r9d, %esi
incl %r9d
movq %r9, 0x78(%rsp)
incl %esi
addq %rax, %rbx
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movl 0x1c(%rsp), %edx
movq %rdi, 0x30(%rsp)
movsbq (%rbx), %rax
movslq (%r8,%rax,4), %rax
shll $0x2, %ebp
movslq %ebp, %rbp
addq %rax, %rbp
andq %rdi, %rbp
movq 0x28(%rsp), %rax
movslq (%rax,%rbp,4), %rax
cmpl %edx, %eax
jae 0x188bc
leal 0x1(%rax), %ecx
movq 0x28(%rsp), %r9
movl %ecx, (%r9,%rbp,4)
movq 0x80(%rsp), %rcx
movq (%rcx,%rbp,8), %rcx
movl %r14d, (%rcx,%rax,4)
decl %r13d
jne 0x1895c
cmpl $0x72ffe, %r14d         # imm = 0x72FFE
jl 0x18901
leaq 0x75ccb(%rip), %rdi     # 0x8e5a0
movl %esi, %r13d
movl $0x72fff, %esi          # imm = 0x72FFF
xorl %eax, %eax
callq 0x26b6f
movl 0x1c(%rsp), %edx
movq 0x30(%rsp), %rdi
movl %r13d, %esi
movl 0xc(%rsp), %r11d
movq 0x38(%rsp), %r10
leaq 0xa936f(%rip), %r8      # 0xc1c70
incl %r14d
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %r9
movw %ax, (%r9)
movw %r11w, 0x2(%r9)
movq %r10, 0x8(%r9)
movq 0x60(%rsp), %rax
movl 0xe6000c(%rax), %eax
movq 0x78(%rsp), %rcx
addl %r15d, %ecx
subl %eax, %ecx
movl %ecx, 0x10(%r9)
addl 0x18(%r10), %eax
movq 0x70(%rsp), %rcx
addl %r12d, %ecx
addl %ecx, %eax
movl $0x100, %r13d           # imm = 0x100
cmpl %r13d, %eax
cmovgel %r13d, %eax
movl %eax, 0x14(%r9)
addq $0x18, %r9
movq %r9, 0x20(%rsp)
decl %r12d
incl %r15d
incq %rbx
cmpl %r15d, %esi
jne 0x1887f
movq 0x60(%rsp), %r12
cmpl $0x2, 0xe6000c(%r12)
jl 0x189d6
xorl %ebx, %ebx
decl %r13d
je 0x1899d
movl %r14d, %ebp
incl %ebx
movl 0xe6000c(%r12), %eax
decl %eax
movl %ebp, %r14d
cmpl %eax, %ebx
jl 0x18980
jmp 0x189d9
leal 0x1(%r14), %ebp
movl $0x100, %r13d           # imm = 0x100
cmpl $0x72ffe, %r14d         # imm = 0x72FFE
jl 0x18988
leaq 0x75be9(%rip), %rdi     # 0x8e5a0
movl $0x72fff, %esi          # imm = 0x72FFF
xorl %eax, %eax
callq 0x26b6f
movl 0xc(%rsp), %r11d
movq 0x38(%rsp), %r10
leaq 0xa929c(%rip), %r8      # 0xc1c70
jmp 0x18988
movl %r14d, %ebp
xorl %r14d, %r14d
cmpl $0x100, %r13d           # imm = 0x100
setne %r14b
addl %ebp, %r14d
cmpl $0x72fff, %r14d         # imm = 0x72FFF
jl 0x18a17
leaq 0x75ba6(%rip), %rdi     # 0x8e5a0
movl $0x72fff, %esi          # imm = 0x72FFF
xorl %eax, %eax
callq 0x26b6f
movl 0xc(%rsp), %r11d
movq 0x38(%rsp), %r10
leaq 0xa9259(%rip), %r8      # 0xc1c70
incl %r11d
movq (%r10), %r10
testq %r10, %r10
jne 0x18778
movq 0x10(%rsp), %rcx
incq %rcx
movq %rcx, 0x10(%rsp)
cmpq 0x48(%rsp), %rcx
jne 0x1875e
jmp 0x18a43
xorl %r14d, %r14d
movl %r14d, 0x18(%r12)
movq 0x68(%rsp), %rdx
testl %edx, %edx
movq 0x40(%rsp), %rcx
jle 0x18a70
xorl %eax, %eax
cmpl $0x4000, (%rcx,%rax,4)  # imm = 0x4000
jb 0x18a68
movl $0x0, (%rcx,%rax,4)
incq %rax
cmpq %rax, %rdx
jne 0x18a58
movq %r12, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq