// File: /workspace/github_cpp_makefile_star2_O3/auton1[P]motiflocation/random.cpp
// Function: gamrnd(double, double)
double gamrnd(double ia, double ib)
{
	double b, c, d, u, v, w, x, y, z;
	int accept;
	double ret = 0;

	if (ia == 1.0)
	{
		// gamma is exponetial (Devroye pg 405)
		ret = -ib * log(ran2());
	}
	else if ((ia < 1) && (ia > 0))
	{
		c = 1 / ia;
		d = 1 / (1 - ia);
		accept = 0;
		do 
		{
			u = ran2();
			v = ran2();
			x = pow(u, c);
			y = pow(v, d);
			z = x + y;
			if (z <= 1.0)
				accept = 1;
		} while (accept != 1);

		ret = -ib * log(ran2()) * x / z;
	}
	else if (ia > 1)
	{
		b = ia - 1;
		c = 3.0 * ia - 0.75;
		accept = 0;
		do
		{
			u = ran2();
			v = ran2();
			w = u * (1 - u);
			y = (u - 0.5) * sqrt(c / w);
			x = b + y;
			if (x >= 0.0)
			{
				z = 64.0 * pow(w, 3) * pow(v, 2);
				if (z <= (1 - 2 * y * y / x))
				{ accept = 1; }
				else
				{	
					if (log(z) <= (2 * (b * log(x / b) - y)))
					{ accept = 1; }
				}
			}
		} while (accept != 1);

			ret = ib * x;
	}
	return ret;
}

// Assembly:
subq $0x38, %rsp
ucomisd 0x1890(%rip), %xmm0     # 0x95c8
jne 0x7d64
jp 0x7d64
xorpd 0x1aec(%rip), %xmm1     # 0x9830
movapd %xmm1, 0x20(%rsp)
callq 0x79af
callq 0x31d0
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rsp)
jmp 0x7fab
movsd 0x185c(%rip), %xmm2     # 0x95c8
ucomisd %xmm0, %xmm2
jbe 0x7e3e
xorpd %xmm3, %xmm3
ucomisd %xmm3, %xmm0
jbe 0x7e3e
movaps %xmm1, 0x20(%rsp)
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
divsd %xmm1, %xmm2
movsd %xmm2, 0x10(%rsp)
callq 0x79af
movsd %xmm0, (%rsp)
callq 0x79af
movsd %xmm0, 0x8(%rsp)
movsd (%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
callq 0x34c0
movsd %xmm0, (%rsp)
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
callq 0x34c0
movapd %xmm0, %xmm1
addsd (%rsp), %xmm1
movsd 0x17d3(%rip), %xmm0     # 0x95c8
ucomisd %xmm1, %xmm0
jb 0x7da9
movapd 0x20(%rsp), %xmm0
xorpd 0x1a27(%rip), %xmm0     # 0x9830
movapd %xmm0, 0x20(%rsp)
movsd %xmm1, 0x8(%rsp)
callq 0x79af
callq 0x31d0
mulsd 0x20(%rsp), %xmm0
movsd (%rsp), %xmm1
mulsd %xmm0, %xmm1
divsd 0x8(%rsp), %xmm1
movsd %xmm1, (%rsp)
jmp 0x7fab
xorpd %xmm2, %xmm2
movsd %xmm2, (%rsp)
ucomisd 0x1779(%rip), %xmm0     # 0x95c8
jbe 0x7fab
movaps %xmm1, 0x20(%rsp)
movsd 0x1976(%rip), %xmm1     # 0x97d8
addsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
mulsd 0x1764(%rip), %xmm0     # 0x95d8
addsd 0x196c(%rip), %xmm0     # 0x97e8
movsd %xmm0, 0x30(%rsp)
callq 0x79af
movsd %xmm0, 0x8(%rsp)
callq 0x79af
movsd 0x8(%rsp), %xmm2
movapd %xmm0, %xmm3
movsd 0x1724(%rip), %xmm1     # 0x95c8
subsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
addsd 0x193c(%rip), %xmm2     # 0x97f0
movsd 0x30(%rsp), %xmm0
divsd %xmm1, %xmm0
ucomisd 0x193a(%rip), %xmm0     # 0x9800
movsd %xmm3, 0x10(%rsp)
jb 0x7ed4
sqrtsd %xmm0, %xmm0
jmp 0x7eef
movsd %xmm2, 0x8(%rsp)
movsd %xmm1, (%rsp)
callq 0x31c0
movsd (%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd 0x18(%rsp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, (%rsp)
ucomisd 0x18f6(%rip), %xmm0     # 0x9800
jb 0x7e82
movapd %xmm1, %xmm0
movsd 0x16bc(%rip), %xmm1     # 0x95d8
movsd %xmm2, 0x8(%rsp)
callq 0x34c0
movsd 0x10(%rsp), %xmm3
movsd 0x8(%rsp), %xmm2
mulsd 0x18bd(%rip), %xmm0     # 0x97f8
mulsd %xmm3, %xmm3
mulsd %xmm0, %xmm3
movapd %xmm2, %xmm0
addsd %xmm2, %xmm0
mulsd %xmm2, %xmm0
divsd (%rsp), %xmm0
movsd 0x166c(%rip), %xmm1     # 0x95c8
subsd %xmm0, %xmm1
ucomisd %xmm3, %xmm1
jae 0x7fa1
movapd %xmm3, %xmm0
callq 0x31d0
movsd %xmm0, 0x10(%rsp)
movsd (%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
callq 0x31d0
mulsd 0x18(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
addsd %xmm0, %xmm0
ucomisd 0x10(%rsp), %xmm0
jb 0x7e82
movsd (%rsp), %xmm0
jmp 0x7d54
movsd (%rsp), %xmm0
addq $0x38, %rsp
retq