// File: /workspace/github_c_makefile_star2_O0/JimKent[P]linearSat/linearSat/linearSat.c
// Function: makeMarkovChains
struct wordTree *makeMarkovChains(struct alphaStore *store)
/* Return wordTree containing all words, and also all chains-of-words of length 
 * chainSize seen in file.  */
{
/* We'll build up the tree starting with an empty root node. */
struct wordTree *wt = wordTreeNew(alphaStoreAddMonomer(store, ""));	
int chainSize = store->maxChainSize;

/* Loop through each read. There's special cases at the beginning and end of read, and for 
 * short reads.  In the main case we'll be maintaining a chain (doubly linked list) of maxChainSize 
 * words, * popping off one word from the start, and adding one word to the end for each
 * new word we encounter. This list is added to the tree each iteration. */
struct alphaRead *read;
for (read = store->readList; read != NULL; read = read->next)
    {
    /* We'll keep a chain of three or so words in a doubly linked list. */
    struct dlNode *node;
    struct dlList *chain = dlListNew();
    int curSize = 0;
    int wordCount = 0;

    struct monomerRef *ref;
    for (ref = read->list; ref != NULL; ref = ref->next)
        {
	struct monomer *monomer = ref->val;
	 /* For the first few words in the file after ID, we'll just build up the chain,
	 * only adding it to the tree when we finally do get to the desired
	 * chain size.  Once past the initial section of the file we'll be
	 * getting rid of the first link in the chain as well as adding a new
	 * last link in the chain with each new word we see. */
	if (curSize < chainSize)
	    {
	    dlAddValTail(chain, monomer);
	    ++curSize;
	    if (curSize == chainSize)
		addChainToTree(wt, chain);
	    }
	else
	    {
	    /* Reuse doubly-linked-list node, but give it a new value, as we move
	     * it from head to tail of list. */
	    node = dlPopHead(chain);
	    node->val = monomer;
	    dlAddTail(chain, node);
	    addChainToTree(wt, chain);
	    }
	++wordCount;
	}
    /* Handle last few words in line, where can't make a chain of full size.  Also handles       
    * lines that have fewer than chain size words. */
    if (curSize < chainSize)
 	addChainToTree(wt, chain);
    while ((node = dlPopHead(chain)) != NULL)
	{
	if (!dlEmpty(chain))
	    addChainToTree(wt, chain);
	freeMem(node);
	}
    dlListFree(&chain);
    }
wordTreeSort(wt);  // Make output of chain file prettier
return wt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x1ebf3(%rip), %rsi     # 0x24cfa
callq 0x56f0
movq %rax, %rdi
callq 0x38b0
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x625f
movb $0x0, %al
callq 0xe7b0
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x61f6
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x61aa
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0xeb10
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jne 0x61a8
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x3aa0
jmp 0x61dd
movq -0x30(%rbp), %rdi
callq 0xebf0
movq %rax, -0x28(%rbp)
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xe9e0
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x3aa0
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x615e
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x620b
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x3aa0
jmp 0x620d
movq -0x30(%rbp), %rdi
callq 0xebf0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0x6246
movq -0x30(%rbp), %rdi
callq 0xee40
cmpl $0x0, %eax
jne 0x623b
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x3aa0
movq -0x28(%rbp), %rdi
callq 0x153e0
jmp 0x620d
leaq -0x30(%rbp), %rdi
callq 0xe860
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x612e
movq -0x10(%rbp), %rdi
callq 0x6280
movq -0x10(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)