// File: /workspace/github_c_makefile_star2_O0/JimKent[P]linearSat/linearSat/linearSat.c
// Function: fillInTypeFromReads
struct monomerType *fillInTypeFromReads(struct monomer *monomer, struct alphaStore *store)
/* Look through read list trying to find best supported type for this monomer. */
{
/* The algorithm here could be better.  It picks the closest nearby monomer that is typed
 * to fill in from.  When have information from both before and after the program arbitrarily 
 * uses before preferentially.  When have information that is equally close from multiple reads,
 * it just uses info from first read.  Fortunately the data, at least on Y, shows a lot of
 * consistency, so it's probably not actually worth a more sophisticated algorithm that would
 * instead take the most popular choice rather than the first one. */
verbose(3, "fillInTypeFromReads on %s from %d reads\n", monomer->word, slCount(monomer->readList));
struct monomerType *bestType = NULL;
int bestPos = 0;
boolean bestIsAfter = FALSE;
struct slRef *readRef;
for (readRef = monomer->readList; readRef != NULL; readRef = readRef->next)
    {
    struct alphaRead *read = readRef->val;
    struct monomerRef *ref;
	{
	verbose(3, "  read %s (%d els):", read->name, slCount(read->list));
	for (ref = read->list; ref != NULL; ref = ref->next)
	    {
	    struct monomer *m = ref->val;
	    verbose(3, " %s", m->word);
	    }
	verbose(3, "\n");
	}
    struct monomerType *beforeType = NULL;
    int beforePos = 0;

    /* Look before. */
    for (ref = read->list; ref != NULL; ref = ref->next)
        {
	struct monomer *m = ref->val;
	if (m == monomer)
	     break;
	if (m->type != NULL)
	    {
	    beforeType = m->type;
	    beforePos = 0;
	    }
	++beforePos;
	}

    /* Look after. */
    struct monomerType *afterType = NULL;
    int afterPos = 0;
    assert(ref != NULL && ref->val == monomer);   
    for (ref = ref->next; ref != NULL; ref = ref->next)
        {
	struct monomer *m = ref->val;
	++afterPos;
	if (m->type != NULL)
	    {
	    afterType = m->type;
	    break;
	    }
	}

    if (beforeType != NULL)
        {
	if (bestType == NULL || beforePos < bestPos)
	    {
	    bestType = beforeType;
	    bestPos = beforePos;
	    bestIsAfter = FALSE;
	    }
	}

    if (afterType != NULL)
        {
	if (bestType == NULL || afterPos < bestPos)
	    {
	    bestType = afterType;
	    bestPos = afterPos;
	    bestIsAfter = TRUE;
	    }
	}
    }

/* Now have found a type that is at a known position relative to ourselves.  From this
 * infer our own type. */
struct monomerType *chosenType = NULL;
if (bestType != NULL)
    {
    if (bestIsAfter)
	chosenType = typeBefore(store, bestType, bestPos);
    else
	chosenType = typeAfter(store, bestType, bestPos);
    }
verbose(3, "chosenType for %s is %s\n", monomer->word, 
    (bestType == NULL ? "(null)" : chosenType->name));
return chosenType;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x78f0
movq -0x80(%rbp), %rdx
movl %eax, %ecx
movl $0x3, %edi
leaq 0x1d65e(%rip), %rsi     # 0x23e2c
movb $0x0, %al
callq 0x1adf0
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6a0e
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x78f0
movq -0x88(%rbp), %rdx
movl %eax, %ecx
movl $0x3, %edi
leaq 0x1d616(%rip), %rsi     # 0x23e55
movb $0x0, %al
callq 0x1adf0
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x688d
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x3, %edi
leaq 0x1e60a(%rip), %rsi     # 0x24e83
movb $0x0, %al
callq 0x1adf0
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x6852
movl $0x3, %edi
leaq 0x20c42(%rip), %rsi     # 0x274db
movb $0x0, %al
callq 0x1adf0
movq $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x690e
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x8(%rbp), %rax
jne 0x68da
jmp 0x690e
movq -0x58(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x68f8
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x68bb
movq $0x0, -0x60(%rbp)
movl $0x0, -0x64(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x6934
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x8(%rbp), %rax
jne 0x6934
jmp 0x6953
leaq 0x1d52e(%rip), %rdi     # 0x23e69
leaq 0x1cd65(%rip), %rsi     # 0x236a7
movl $0x65e, %edx            # imm = 0x65E
leaq 0x1d53e(%rip), %rcx     # 0x23e8c
callq 0x32d0
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x69a2
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movq -0x70(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x6993
movq -0x70(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x60(%rbp)
jmp 0x69a2
jmp 0x6995
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x695e
cmpq $0x0, -0x48(%rbp)
je 0x69cf
cmpq $0x0, -0x18(%rbp)
je 0x69b8
movl -0x4c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x69cd
movq -0x48(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
jmp 0x69cf
cmpq $0x0, -0x60(%rbp)
je 0x69fc
cmpq $0x0, -0x18(%rbp)
je 0x69e5
movl -0x64(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x69fa
movq -0x60(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl $0x1, -0x20(%rbp)
jmp 0x69fc
jmp 0x69fe
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x67f7
movq $0x0, -0x78(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x6a4f
cmpl $0x0, -0x20(%rbp)
je 0x6a39
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x46c0
movq %rax, -0x78(%rbp)
jmp 0x6a4d
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x4660
movq %rax, -0x78(%rbp)
jmp 0x6a4f
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x6a75
leaq 0x1d488(%rip), %rax     # 0x23ef4
movq %rax, -0x98(%rbp)
jmp 0x6a84
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdx
movq -0x98(%rbp), %rcx
movl $0x3, %edi
leaq 0x1d43d(%rip), %rsi     # 0x23edb
movb $0x0, %al
callq 0x1adf0
movq -0x78(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)