// File: /workspace/github_c_makefile_star2_O0/JimKent[P]linearSat/linearSat/linearSat.c
// Function: pickWeightedRandomFromList
struct wordTree *pickWeightedRandomFromList(struct wordTree *list)
/* Pick word from list randomly, but so that words with higher outTargets
 * are picked more often. */
{
struct wordTree *picked = NULL;

/* Debug output. */
    {
    verbose(4, "   pickWeightedRandomFromList(");
    struct wordTree *wt;
    for (wt = list; wt != NULL; wt = wt->next)
        {
	if (wt != list)
	    verbose(4, " ");
	verbose(4, "%s:%d", wt->monomer->word, wt->outTarget);
	}
    verbose(4, ") total %d\n", wordTreeSumOutTargets(list));
    }

/* Figure out total number of outputs left, and a random number between 0 and that total. */
int total = wordTreeSumOutTargets(list);
if (total > 0)
    {
    int threshold = rand() % total; 
    verbose(4, "      threshold %d\n", threshold);

    /* Loop through list returning selection corresponding to random threshold. */
    int binStart = 0;
    struct wordTree *wt;
    for (wt = list; wt != NULL; wt = wt->next)
	{
	int size = wt->outTarget;
	int binEnd = binStart + size;
	verbose(4, "      %s size %d, binEnd %d\n", wt->monomer->word, size, binEnd);
	if (threshold < binEnd)
	    {
	    picked = wt;
	    verbose(4, "      picked %s\n", wt->monomer->word);
	    break;
	    }
	binStart = binEnd;
	}
    }
return picked;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movl $0x4, %edi
leaq 0x1f61a(%rip), %rsi     # 0x236fa
movb $0x0, %al
callq 0x1adf0
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x4146
movq -0x18(%rbp), %rax
cmpq -0x8(%rbp), %rax
je 0x4113
movl $0x4, %edi
leaq 0x22826(%rip), %rsi     # 0x26932
movb $0x0, %al
callq 0x1adf0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rdx
movq -0x18(%rbp), %rax
movl 0x24(%rax), %ecx
movl $0x4, %edi
leaq 0x1f5e7(%rip), %rsi     # 0x23719
movb $0x0, %al
callq 0x1adf0
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x40ef
movq -0x8(%rbp), %rdi
callq 0x3a60
movl %eax, %edx
movl $0x4, %edi
leaq 0x1f5c2(%rip), %rsi     # 0x2371f
movb $0x0, %al
callq 0x1adf0
movq -0x8(%rbp), %rdi
callq 0x3a60
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0x4238
callq 0x3750
cltd
idivl -0x1c(%rbp)
movl %edx, -0x20(%rbp)
movl -0x20(%rbp), %edx
movl $0x4, %edi
leaq 0x1f596(%rip), %rsi     # 0x2372b
movb $0x0, %al
callq 0x1adf0
movl $0x0, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x4236
movq -0x30(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x24(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rdx
movl -0x34(%rbp), %ecx
movl -0x38(%rbp), %r8d
movl $0x4, %edi
leaq 0x1f557(%rip), %rsi     # 0x2373f
movb $0x0, %al
callq 0x1adf0
movl -0x20(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x4220
movq -0x30(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rdx
movl $0x4, %edi
leaq 0x1f545(%rip), %rsi     # 0x2375c
movb $0x0, %al
callq 0x1adf0
jmp 0x4236
movl -0x38(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x41ab
jmp 0x4238
movq -0x10(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)