// File: /workspace/github_c_makefile_star2_O0/dapogon[P]cellcoal/src/cellcoal.c
// Function: SimulateTriNucFreqGenome
void SimulateTriNucFreqGenome (int cell, long int *seed)
	{
	int 		chosenTriNucleotide, nextNucleotide;
	int			k, n1, n2, n3, rest, site;
	double 		*prob4, sum;
	
	/* memory allocations */
	prob4 = (double *) calloc (4, sizeof(double));
	if (!prob4)
		{
		fprintf (stderr, "Could not allocate the prob4 vector\n");
		exit (-1);
		}
		
	/* choose first trinucleotide */
	chosenTriNucleotide = ChooseUniformState(triNucFreq, seed);

	/* find bases of the selected trinucleotide */
	n1 = chosenTriNucleotide/16;
	rest = chosenTriNucleotide%16;
	n2 = rest/4;
	n3 = rest%4;
	//fprintf (stderr, "\n%2d %c%c%c ", chosenTriNucleotide, WhichNuc(n1), WhichNuc(n2), WhichNuc(n3));

	site = 0;
	data[MATERNAL][cell][site] = data[PATERNAL][cell][site] = allSites[site].referenceAllele = n1;
	site++;
	data[MATERNAL][cell][site] = data[PATERNAL][cell][site] = allSites[site].referenceAllele = n2;
	site++;
	data[MATERNAL][cell][site] = data[PATERNAL][cell][site] = allSites[site].referenceAllele = n3;
	
	/* fill the rest of the genome */
	/* choose next nucleotide given the last two bases of the previous trinucleotide  */
	for (site=3; site<numSites; site++)
		{
		/* normalize frequencies given the last two bases */
		sum = 0;
		for (k=0; k<4; k++)
			sum += triNucFreq[trinuc(n2,n3,k)];
		for (k=0; k<4; k++)
			prob4[k] = triNucFreq[trinuc(n2,n3,k)] / sum;
		
		nextNucleotide = ChooseUniformState(prob4, seed);
		data[MATERNAL][cell][site] = data[PATERNAL][cell][site] = allSites[site].referenceAllele = nextNucleotide;

		/* move downstream one position */
		n1 = n2;
		n2 = n3;
		n3 = nextNucleotide;
		}
 
	free(prob4);
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x4, %edi
movl $0x8, %esi
callq 0x2190
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x1a45b
movq 0x33bb8(%rip), %rax     # 0x4dff8
movq (%rax), %rdi
leaq 0x26bed(%rip), %rsi     # 0x41037
movb $0x0, %al
callq 0x21b0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x2290
leaq 0x35f5e(%rip), %rax     # 0x503c0
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x1a6f0
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %eax, -0x20(%rbp)
movl -0x14(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %eax, -0x24(%rbp)
movl -0x2c(%rbp), %eax
movl $0x4, %ecx
cltd
idivl %ecx
movl %edx, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x20(%rbp), %edx
movq 0x352ee(%rip), %rax     # 0x4f7a8
movslq -0x30(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl %edx, 0x6c(%rax)
movq 0x352ce(%rip), %rax     # 0x4f7a0
movq 0x8(%rax), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x352b4(%rip), %rax     # 0x4f7a0
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x24(%rbp), %edx
movq 0x35297(%rip), %rax     # 0x4f7a8
movslq -0x30(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl %edx, 0x6c(%rax)
movq 0x35277(%rip), %rax     # 0x4f7a0
movq 0x8(%rax), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x3525d(%rip), %rax     # 0x4f7a0
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x28(%rbp), %edx
movq 0x35240(%rip), %rax     # 0x4f7a8
movslq -0x30(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl %edx, 0x6c(%rax)
movq 0x35220(%rip), %rax     # 0x4f7a0
movq 0x8(%rax), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x35206(%rip), %rax     # 0x4f7a0
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl $0x3, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl 0x33c20(%rip), %eax     # 0x4e1dc
jge 0x1a6da
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x4, -0x1c(%rbp)
jge 0x1a60f
leaq 0x35de2(%rip), %rax     # 0x503c0
movq (%rax), %rax
movl -0x24(%rbp), %ecx
shll $0x4, %ecx
movl -0x28(%rbp), %edx
shll $0x2, %edx
addl %edx, %ecx
addl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1a5d1
movl $0x0, -0x1c(%rbp)
cmpl $0x4, -0x1c(%rbp)
jge 0x1a65c
leaq 0x35d9d(%rip), %rax     # 0x503c0
movq (%rax), %rax
movl -0x24(%rbp), %ecx
shll $0x4, %ecx
movl -0x28(%rbp), %edx
shll $0x2, %edx
addl %edx, %ecx
addl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
divsd -0x40(%rbp), %xmm0
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1a616
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x1a6f0
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %edx
movq 0x35132(%rip), %rax     # 0x4f7a8
movslq -0x30(%rbp), %rcx
imulq $0x88, %rcx, %rcx
addq %rcx, %rax
movl %edx, 0x6c(%rax)
movq 0x35112(%rip), %rax     # 0x4f7a0
movq 0x8(%rax), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x350f8(%rip), %rax     # 0x4f7a0
movq (%rax), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x30(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x1a5b3
movq -0x38(%rbp), %rdi
callq 0x2030
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)