// File: /workspace/github_c_makefile_star2_O0/JimKent[P]linearSat/linearSat/linearSat.c
// Function: subCommonCenter
boolean subCommonCenter(struct alphaStore *store,
    struct monomer *center, struct monomerRef *neighborhood, struct dlList *ll)
/* Scan list for places where have all items in neighborhood (except for center) matching. 
 * Substitute in center at one of these places chosen at random and return TRUE if possible. */
{
struct slRef *centerRefList = refsToPossibleCenters(center, neighborhood, ll);
verbose(4, "sub %s in neighborhood: ", center->word);
if (verboseLevel() >= 4)
    printMonomerRefList(neighborhood, stderr);
verbose(4, "Got %d possible centers\n", slCount(centerRefList));

if (centerRefList == NULL)
    return FALSE;
int commonCount = 0;
char *commonWord = NULL;
mostCommonMonomerWord(centerRefList, &commonWord, &commonCount);
struct monomer *commonMonomer = hashFindVal(store->monomerHash, commonWord);
verbose(4, "Commonest word to displace with %s is %s which occurs %d times in context and %d overall\n", center->word, commonWord, commonCount, commonMonomer->subbedOutCount);
if (commonMonomer->subbedOutCount < 2)
    {
    verbose(3, "Want to substitute %s for %s, but %s only occurs %d time.\n", 
	center->word, commonWord, commonWord, commonMonomer->subbedOutCount);
    return FALSE;
    }

/* Select a random one of the most commonly occuring possible centers. */
int targetIx = rand() % commonCount;
struct slRef *ref;
int currentIx = 0;
for (ref = centerRefList; ref != NULL; ref = ref->next)
    {
    struct dlNode *node = ref->val;
    struct monomer *monomer = node->val;
    if (sameString(monomer->word, commonWord))
         {
	 if (currentIx == targetIx)
	     {
	     verbose(3, "Substituting %s for %s in context of %d\n", center->word, commonWord, slCount(neighborhood));
	     struct monomer *oldCenter = node->val;
	     if (oldCenter->type != center->type)
		 verbose(3, "Type mismatch subbig %s vs %s\n", oldCenter->word, center->word);
	     node->val = center;
	     oldCenter->subbedOutCount -= 1;
	     center->subbedOutCount += 1;
	     return TRUE;
	     }
	 ++currentIx;
	 }
    }
internalErr();	// Should not get here.
return FALSE;	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x4e50
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x4, %edi
leaq 0x1e950(%rip), %rsi     # 0x23954
movb $0x0, %al
callq 0x1adf0
movb $0x0, %al
callq 0x1b100
cmpl $0x4, %eax
jl 0x502a
movq -0x20(%rbp), %rdi
movq 0x2cfce(%rip), %rax     # 0x31ff0
movq (%rax), %rsi
callq 0x4de0
movq -0x30(%rbp), %rdi
callq 0x78f0
movl %eax, %edx
movl $0x4, %edi
leaq 0x1e92c(%rip), %rsi     # 0x2396d
movb $0x0, %al
callq 0x1adf0
cmpq $0x0, -0x30(%rbp)
jne 0x505b
movl $0x0, -0x4(%rbp)
jmp 0x524d
movl $0x0, -0x34(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x34(%rbp), %rdx
callq 0x4ed0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x10d00
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x40(%rbp), %rcx
movl -0x34(%rbp), %r8d
movq -0x48(%rbp), %rax
movl 0x30(%rax), %r9d
movl $0x4, %edi
leaq 0x1e8d2(%rip), %rsi     # 0x23986
movb $0x0, %al
callq 0x1adf0
movq -0x48(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jge 0x50fc
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x40(%rbp), %rcx
movq -0x40(%rbp), %r8
movq -0x48(%rbp), %rax
movl 0x30(%rax), %r9d
movl $0x3, %edi
leaq 0x1e8f7(%rip), %rsi     # 0x239e0
movb $0x0, %al
callq 0x1adf0
movl $0x0, -0x4(%rbp)
jmp 0x524d
callq 0x3750
cltd
idivl -0x34(%rbp)
movl %edx, -0x4c(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x522c
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x3410
cmpl $0x0, %eax
jne 0x521a
movl -0x5c(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jne 0x5211
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x20(%rbp), %rdi
callq 0x78f0
movq -0x88(%rbp), %rdx
movq -0x80(%rbp), %rcx
movl %eax, %r8d
movl $0x3, %edi
leaq 0x1e881(%rip), %rsi     # 0x23a1b
movb $0x0, %al
callq 0x1adf0
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x20(%rcx), %rax
je 0x51e2
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movl $0x3, %edi
leaq 0x1e869(%rip), %rsi     # 0x23a44
movb $0x0, %al
callq 0x1adf0
movq -0x18(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x78(%rbp), %rax
movl 0x30(%rax), %ecx
subl $0x1, %ecx
movl %ecx, 0x30(%rax)
movq -0x18(%rbp), %rax
movl 0x30(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x30(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x524d
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x521c
movq -0x58(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x5117
leaq 0x1e830(%rip), %rdi     # 0x23a63
leaq 0x1e46d(%rip), %rsi     # 0x236a7
movl $0x3ce, %edx            # imm = 0x3CE
movb $0x0, %al
callq 0xfd50
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)