// File: auton1[P]motiflocation/random.cpp
// Function: poissrnd(double)
int poissrnd(double xm)
{
	//float gammln(float xx);
	static double sq, alxm, g, oldm=(-1.0);
	double em,t,y;
	
	if (xm < 12.0) { 
		if (xm != oldm) {
			oldm=xm;
			g=exp(-xm); 
		}
		em = -1;
		t=1.0;
		do {
			++em;
			t *= ran2();
		} while (t > g);
	} else { 
		if (xm != oldm) { 
			oldm=xm;
			sq=sqrt(2.0*xm);
			alxm=log(xm);
			g = xm*alxm - gammln(xm + 1.0);
		}
		do {
			do { 
				y=tan(PI * ran2());
				em=sq*y+xm; 
			} while (em < 0.0); 
			em=floor(em); 
			t=0.9*(1.0+y*y)*exp(em*alxm-gammln(em+1.0)-g);
		} while (ran2() > t);
	}
	return (int)em;
}

// Assembly:
subq $0x48, %rsp
movsd %xmm0, 0x40(%rsp)
movsd 0x1ed6(%rip), %xmm0     # 0x11958
ucomisd 0x40(%rsp), %xmm0
jbe 0xfb30
movsd 0x40(%rsp), %xmm0
ucomisd 0x7934(%rip), %xmm0     # 0x173d0
jne 0xfaa2
jp 0xfaa2
jmp 0xfada
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x7920(%rip)     # 0x173d0
movsd 0x40(%rsp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0x4620
movsd %xmm0, 0x7a66(%rip)     # 0x17540
movsd 0x1e56(%rip), %xmm0     # 0x11938
movsd %xmm0, 0x38(%rsp)
movsd 0x1c48(%rip), %xmm0     # 0x11738
movsd %xmm0, 0x30(%rsp)
movsd 0x1c3a(%rip), %xmm0     # 0x11738
addsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
callq 0xf090
mulsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x30(%rsp), %xmm0
ucomisd 0x7a17(%rip), %xmm0     # 0x17540
ja 0xfaf6
jmp 0xfd01
movsd 0x40(%rsp), %xmm0
ucomisd 0x7892(%rip), %xmm0     # 0x173d0
jne 0xfb47
jp 0xfb47
jmp 0xfbe6
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x787b(%rip)     # 0x173d0
movsd 0x1bd3(%rip), %xmm0     # 0x11730
mulsd 0x40(%rsp), %xmm0
callq 0x4270
movsd %xmm0, 0x79c0(%rip)     # 0x17530
movsd 0x40(%rsp), %xmm0
callq 0x4290
movsd %xmm0, 0x79b5(%rip)     # 0x17538
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x79a1(%rip), %xmm0     # 0x17538
movsd %xmm0, 0x18(%rsp)
movsd 0x1b93(%rip), %xmm0     # 0x11738
addsd 0x40(%rsp), %xmm0
callq 0xf440
movsd 0x18(%rsp), %xmm2
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x795a(%rip)     # 0x17540
jmp 0xfbe8
jmp 0xfbea
callq 0xf090
movaps %xmm0, %xmm1
movsd 0x1d66(%rip), %xmm0     # 0x11960
mulsd %xmm1, %xmm0
callq 0x41d0
movsd %xmm0, 0x28(%rsp)
movsd 0x791f(%rip), %xmm0     # 0x17530
movsd 0x28(%rsp), %xmm2
movsd 0x40(%rsp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rsp)
xorps %xmm0, %xmm0
ucomisd 0x38(%rsp), %xmm0
ja 0xfbea
movsd 0x38(%rsp), %xmm0
callq 0x4580
movsd %xmm0, 0x38(%rsp)
movsd 0x28(%rsp), %xmm1
movsd 0x28(%rsp), %xmm0
mulsd %xmm0, %xmm1
movsd 0x1ad9(%rip), %xmm0     # 0x11738
addsd %xmm0, %xmm1
movsd 0x1cfd(%rip), %xmm0     # 0x11968
mulsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x78af(%rip), %xmm0     # 0x17538
movsd %xmm0, (%rsp)
movsd 0x1aa2(%rip), %xmm0     # 0x11738
addsd 0x38(%rsp), %xmm0
callq 0xf440
movsd (%rsp), %xmm2
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
subsd 0x786a(%rip), %xmm0     # 0x17540
callq 0x4620
movaps %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
callq 0xf090
ucomisd 0x30(%rsp), %xmm0
ja 0xfbe8
jmp 0xfd01
cvttsd2si 0x38(%rsp), %eax
addq $0x48, %rsp
retq
nopl (%rax)