// File: /workspace/github_c_makefile_star2_O2/JimKent[P]linearSat/linearSat/linearSat.c
// Function: integrateOrphans
void integrateOrphans(struct alphaStore *store)
/* Make up fake reads that integrate orphans (monomers only found at beginning or end
 * of a read) better. */
{
struct alphaOrphan *orphanStarts = findOrphanStarts(store->readList, store);
struct alphaOrphan *orphanEnds = findOrphanEnds(store->readList, store);
verbose(3, "orphanStarts has %d items, orphanEnds %d\n", 
    slCount(orphanStarts), slCount(orphanEnds));

/* First look for the excellent situation where you can pair up orphans with each 
 * other.  For Y at least this happens half the time. */
struct alphaOrphan *start, *end;
for (start = orphanStarts; start != NULL; start = start->next)
    {
    struct monomerType *startType = start->monomer->type;
    if (startType == NULL)
        continue;
    for (end = orphanEnds; end != NULL && !start->paired; end = end->next)
        {
	struct monomerType *endType = end->monomer->type;
	if (endType == NULL)
	    continue;
	if (!end->paired)
	    {
	    struct monomerType *nextType = typeAfter(store, endType, 1);
	    if (nextType == startType)
	        {
		end->paired = TRUE;
		start->paired = TRUE;
		addReadOfTwo(store, end->monomer, start->monomer);
		verbose(3, "Pairing %s with %s\n", end->monomer->word, start->monomer->word);
		}
	    }
	}
    }

/* Ok, now have to just manufacture other side of orphan starts out of thin air. */
for (start = orphanStarts; start != NULL; start = start->next)
    {
    if (start->paired)
        continue;
    struct monomer *startMono = start->monomer;
    struct monomerType *startType = startMono->type;
    if (startType == NULL)
        continue;

    struct monomerType *newType = typeBefore(store, startType, 1);
    verbose(3, "Trying to find end of type %s\n", newType->name);
    struct monomer *newMono = pickRandomFromType(newType);
    addReadOfTwo(store, newMono, startMono);
    verbose(3, "Pairing new %s with start %s\n", newMono->word, startMono->word);
    }

/* Ok, now have to just manufacture other side of orphan ends out of thin air. */
for (end = orphanEnds; end != NULL; end = end->next)
    {
    if (end->paired)
        continue;
    struct monomer *endMono = end->monomer;
    struct monomerType *endType = endMono->type;
    if (endType == NULL)
        continue;

    struct monomerType *newType = typeAfter(store, endType, 1);
    verbose(3, "Trying to find start of type %s\n", newType->name);
    struct monomer *newMono = pickRandomFromType(newType);
    addReadOfTwo(store, endMono, newMono);
    verbose(3, "Pairing end %s with new %s\n", endMono->word, newMono->word);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
callq 0x4c59
movq %rax, %r13
movq %rbx, 0x8(%rsp)
movq 0x10(%rbx), %rdi
callq 0x4d67
movq %rax, %rbx
movq %r13, %rdi
callq 0x6082
movl %eax, %ebp
movq %rbx, 0x10(%rsp)
movq %rbx, %rdi
callq 0x6082
leaq 0x11d0e(%rip), %rsi     # 0x16c92
pushq $0x3
popq %rdi
movl %ebp, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x110f9
pushq $0x1
popq %r12
movq %r13, %r15
testq %r15, %r15
je 0x502d
movq 0x8(%r15), %rax
movq 0x20(%rax), %rbx
testq %rbx, %rbx
je 0x5025
movq 0x10(%rsp), %r14
testq %r14, %r14
je 0x5025
cmpl $0x0, 0x10(%r15)
jne 0x5025
movq 0x8(%r14), %rbp
movq 0x20(%rbp), %rsi
testq %rsi, %rsi
je 0x5020
cmpl $0x0, 0x10(%r14)
jne 0x5020
movq 0x8(%rsp), %rdi
movl %r12d, %edx
callq 0x4098
cmpq %rbx, %rax
jne 0x5020
movl %r12d, 0x10(%r14)
movl %r12d, 0x10(%r15)
movq 0x8(%r15), %rdx
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x4e7c
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdx
movq 0x8(%r15), %rax
movq 0x8(%rax), %rcx
pushq $0x3
popq %rdi
leaq 0x11ca3(%rip), %rsi     # 0x16cbc
xorl %eax, %eax
callq 0x110f9
movq (%r14), %r14
jmp 0x4fb4
movq (%r15), %r15
jmp 0x4f99
pushq $0x1
popq %r14
pushq $0x3
popq %r15
movq 0x8(%rsp), %rbx
testq %r13, %r13
je 0x50b0
cmpl $0x0, 0x10(%r13)
jne 0x50aa
movq 0x8(%r13), %r12
movq 0x20(%r12), %rsi
testq %rsi, %rsi
je 0x50aa
movq %rbx, %rdi
movl %r14d, %edx
callq 0x40b6
movq %rax, %rbp
movq 0x8(%rax), %rdx
movl %r15d, %edi
leaq 0x11c60(%rip), %rsi     # 0x16cd0
xorl %eax, %eax
callq 0x110f9
movq %rbp, %rdi
callq 0x3e7a
movq %rax, %rbp
movq %rbx, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x4e7c
movq 0x8(%rbp), %rdx
movq 0x8(%r12), %rcx
movl %r15d, %edi
leaq 0x11c4c(%rip), %rsi     # 0x16cef
xorl %eax, %eax
callq 0x110f9
movq (%r13), %r13
jmp 0x503a
pushq $0x3
popq %r12
leaq 0x11c73(%rip), %r13     # 0x16d2e
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rbx
testq %r14, %r14
je 0x5134
cmpl $0x0, 0x10(%r14)
jne 0x512f
movq 0x8(%r14), %rbp
movq 0x20(%rbp), %rsi
testq %rsi, %rsi
je 0x512f
movq %rbx, %rdi
pushq $0x1
popq %rdx
callq 0x4098
movq %rax, %r15
movq 0x8(%rax), %rdx
movl %r12d, %edi
leaq 0x11c13(%rip), %rsi     # 0x16d0d
xorl %eax, %eax
callq 0x110f9
movq %r15, %rdi
callq 0x3e7a
movq %rax, %r15
movq %rbx, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x4e7c
movq 0x8(%rbp), %rdx
movq 0x8(%r15), %rcx
movl %r12d, %edi
movq %r13, %rsi
xorl %eax, %eax
callq 0x110f9
movq (%r14), %r14
jmp 0x50c5
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq