// File: /workspace/github_c_makefile_star2_O1/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
pushq %rax
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
callq 0x510e
movq %rax, %r15
movq %rbx, (%rsp)
movq 0x10(%rbx), %rdi
callq 0x5229
movq %rax, %rbx
movq %r15, %rdi
callq 0x6674
movl %eax, %ebp
movq %rbx, %rdi
callq 0x6674
leaq 0x13830(%rip), %rsi     # 0x18c82
movl $0x3, %edi
movl %ebp, %edx
movl %eax, %ecx
xorl %eax, %eax
callq 0x12c8e
testq %r15, %r15
je 0x5584
movl $0x1, %ebp
movq %r15, %r13
movq 0x8(%r13), %rax
movq 0x20(%rax), %r12
testq %r12, %r12
je 0x54f8
testq %rbx, %rbx
je 0x54f8
movq %rbx, %r14
cmpl $0x0, 0x10(%r13)
jne 0x54f8
movq 0x8(%r14), %rsi
movq 0x20(%rsi), %rax
testq %rax, %rax
je 0x54f0
cmpl $0x0, 0x10(%r14)
jne 0x54f0
movq (%rax), %rax
testq %rax, %rax
jne 0x54b3
movq (%rsp), %rax
movq 0x38(%rax), %rax
cmpq %r12, %rax
jne 0x54f0
movl %ebp, 0x10(%r14)
movl %ebp, 0x10(%r13)
movq 0x8(%r13), %rdx
movq (%rsp), %rdi
callq 0x534b
movq 0x8(%r14), %rax
movq 0x8(%rax), %rdx
movq 0x8(%r13), %rax
movq 0x8(%rax), %rcx
movl $0x3, %edi
leaq 0x137c3(%rip), %rsi     # 0x18cac
xorl %eax, %eax
callq 0x12c8e
movq (%r14), %r14
testq %r14, %r14
jne 0x5488
movq (%r13), %r13
testq %r13, %r13
jne 0x5473
leaq 0x137d3(%rip), %r13     # 0x18cdf
movq (%rsp), %r14
cmpl $0x0, 0x10(%r15)
jne 0x557c
movq 0x8(%r15), %rbp
movq 0x20(%rbp), %rsi
testq %rsi, %rsi
je 0x557c
movq %r14, %rdi
movl $0x1, %edx
callq 0x43fc
movq %rax, %r12
movq 0x8(%rax), %rdx
movl $0x3, %edi
leaq 0x1377c(%rip), %rsi     # 0x18cc0
xorl %eax, %eax
callq 0x12c8e
movq %r12, %rdi
callq 0x4185
movq %rax, %r12
movq %r14, %rdi
movq %rax, %rsi
movq %rbp, %rdx
callq 0x534b
movq 0x8(%r12), %rdx
movq 0x8(%rbp), %rcx
movl $0x3, %edi
movq %r13, %rsi
xorl %eax, %eax
callq 0x12c8e
movq (%r15), %r15
testq %r15, %r15
jne 0x5510
testq %rbx, %rbx
je 0x5606
leaq 0x1376d(%rip), %r15     # 0x18cfd
leaq 0x13787(%rip), %r12     # 0x18d1e
cmpl $0x0, 0x10(%rbx)
jne 0x55fe
movq 0x8(%rbx), %r13
movq 0x20(%r13), %rax
testq %rax, %rax
je 0x55fe
movq (%rax), %rbp
testq %rbp, %rbp
jne 0x55ba
movq (%rsp), %rax
movq 0x38(%rax), %rbp
movq 0x8(%rbp), %rdx
movl $0x3, %edi
movq %r15, %rsi
xorl %eax, %eax
callq 0x12c8e
movq %rbp, %rdi
callq 0x4185
movq %rax, %rbp
movq (%rsp), %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x534b
movq 0x8(%r13), %rdx
movq 0x8(%rbp), %rcx
movl $0x3, %edi
movq %r12, %rsi
xorl %eax, %eax
callq 0x12c8e
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x5597
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq