// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rsi
callq 0x59a0
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x8(%rbp), %rsi
callq 0x5b20
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x78f0
movl %eax, -0x84(%rbp)
movq -0x18(%rbp), %rdi
callq 0x78f0
movl -0x84(%rbp), %edx
movl %eax, %ecx
movl $0x3, %edi
leaq 0x1de5d(%rip), %rsi     # 0x23c82
movb $0x0, %al
callq 0x1adf0
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x5f5a
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x5e5b
jmp 0x5f4a
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x28(%rbp)
movb %al, -0x85(%rbp)
je 0x5e85
movq -0x20(%rbp), %rax
cmpl $0x0, 0x10(%rax)
setne %al
xorb $-0x1, %al
movb %al, -0x85(%rbp)
movb -0x85(%rbp), %al
testb $0x1, %al
jne 0x5e94
jmp 0x5f48
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x5eb0
jmp 0x5f38
movq -0x28(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x5f36
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x1, %edx
callq 0x4660
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x30(%rbp), %rax
jne 0x5f34
movq -0x28(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x20(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdx
callq 0x5cb0
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdx
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rcx
movl $0x3, %edi
leaq 0x1dd7f(%rip), %rsi     # 0x23cac
movb $0x0, %al
callq 0x1adf0
jmp 0x5f36
jmp 0x5f38
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x5e63
jmp 0x5f4a
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x5e34
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x601f
movq -0x20(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x5f7c
jmp 0x600f
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x5f9d
jmp 0x600f
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl $0x1, %edx
callq 0x46c0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x3, %edi
leaq 0x1dcf9(%rip), %rsi     # 0x23cc0
movb $0x0, %al
callq 0x1adf0
movq -0x58(%rbp), %rdi
callq 0x4250
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x48(%rbp), %rdx
callq 0x5cb0
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x3, %edi
leaq 0x1dcd7(%rip), %rsi     # 0x23cdf
movb $0x0, %al
callq 0x1adf0
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x5f62
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x60e4
movq -0x28(%rbp), %rax
cmpl $0x0, 0x10(%rax)
je 0x6041
jmp 0x60d4
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x6062
jmp 0x60d4
movq -0x8(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl $0x1, %edx
callq 0x4660
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x3, %edi
leaq 0x1dc71(%rip), %rsi     # 0x23cfd
movb $0x0, %al
callq 0x1adf0
movq -0x78(%rbp), %rdi
callq 0x4250
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x80(%rbp), %rdx
callq 0x5cb0
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x3, %edi
leaq 0x1dc51(%rip), %rsi     # 0x23d1e
movb $0x0, %al
callq 0x1adf0
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x6027
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)