// File: /workspace/github_c_makefile_star2_O0/JimKent[P]linearSat/linearSat/linearSat.c
// Function: pickRandomFromType
struct monomer *pickRandomFromType(struct monomerType *type)
/* Pick a random word, weighted by outTarget, from all available of given type */
{
/* Figure out total on list */
int total = 0;
struct monomerRef *ref;
for (ref = type->list; ref != NULL; ref = ref->next)
    total += ref->val->outTarget;
verbose(3, "pickRandomFromType %s total of outTarget=%d\n", type->name, total);

/* Loop through list returning selection corresponding to random threshold. */
if (total > 0)
    {
    int threshold = rand() % total; 
    int binStart = 0;
    for (ref = type->list; ref != NULL; ref = ref->next)
	{
	struct monomer *monomer = ref->val;
	int size = monomer->outTarget;
	int binEnd = binStart + size;
	if (threshold < binEnd)
	    return monomer;
	binStart = binEnd;
	}
    }

verbose(3, "Backup plan for %s in pickRandomFromType\n", type->name);

/* Try again based on use counts. */
total = 0;
for (ref = type->list; ref != NULL; ref = ref->next)
    total += ref->val->useCount;
if (total > 0)
    {
    int threshold = rand() % total; 
    int binStart = 0;
    for (ref = type->list; ref != NULL; ref = ref->next)
	{
	struct monomer *monomer = ref->val;
	int size = monomer->useCount;
	int binEnd = binStart + size;
	if (threshold < binEnd)
	    return monomer;
	binStart = binEnd;
	}
    }

errAbort("Fell off end in pickRandomFromType on %s", type->name);
return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x4294
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x14(%rax), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x426f
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl -0x14(%rbp), %ecx
movl $0x3, %edi
leaq 0x1f4c2(%rip), %rsi     # 0x2376d
movb $0x0, %al
callq 0x1adf0
cmpl $0x0, -0x14(%rbp)
jle 0x4327
callq 0x3750
cltd
idivl -0x14(%rbp)
movl %edx, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x4325
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x28(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x4312
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x440a
movl -0x38(%rbp), %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x42d7
jmp 0x4327
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x3, %edi
leaq 0x1f45f(%rip), %rsi     # 0x2379a
movb $0x0, %al
callq 0x1adf0
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x437a
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x4355
cmpl $0x0, -0x14(%rbp)
jle 0x43ec
callq 0x3750
cltd
idivl -0x14(%rbp)
movl %edx, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x43ea
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x4c(%rbp)
movl -0x40(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0x43d7
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x440a
movl -0x50(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x439f
jmp 0x43ec
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0x1f3c9(%rip), %rdi     # 0x237c4
movb $0x0, %al
callq 0xfd50
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)