// File: /workspace/github_cpp_makefile_star2_O2/auton1[P]motiflocation/random.cpp
// Function: bnlrnd(double, int)
int bnlrnd(double pp, int n)
{
	int j;
	static int nold=(-1);
	double am,em,g,angle,p,bnl,sq,t,y;
	static double pold=(-1.0),pc,plog,pclog,en,oldg;
	p=(pp <= 0.5 ? pp : 1.0-pp);
	am=n*p;		//This is the mean of the deviate to be produced.
	if (n < 25) { 
		bnl = 0.0;
		for (j=1;j<=n;j++)
			if (ran2() < p) ++bnl;
	} else if (am < 1.0) { 
		g=exp(-am);
		t=1.0;
		for (j=0;j<=n;j++) {
			t *= ran2();
			if (t < g) break;
		}
		bnl=(j <= n ? j : n);
	} else {
		if (n != nold) { 
			en=n; 
			oldg=gammln(en+1.0);
			nold=n;
		} if (p != pold) { 
			pc=1.0-p; 
			plog=log(p);
			pclog=log(pc);
			pold=p;
		}
		sq=sqrt(2.0*am*pc); 
		do {
			do {
				angle=PI*ran2();
				y=tan(angle);
				em=sq*y+am;
			} while (em < 0.0 || em >= (en+1.0)); 
			em=floor(em); 
			t=1.2*sq*(1.0+y*y)*exp(oldg-gammln(em+1.0)-gammln(en-em+1.0)+em*plog+(en-em)*pclog);
		} while (ran2() > t); bnl=em; 
	}
	if (p != pp) bnl=n-bnl; 
	return (int)bnl;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x70, %rsp
movl %edi, %ebx
movsd 0x1404(%rip), %xmm3     # 0x85a8
movapd %xmm3, %xmm2
subsd %xmm0, %xmm2
movapd %xmm0, %xmm4
cmplesd 0x15a7(%rip), %xmm4     # 0x8760
movapd %xmm4, %xmm1
movapd %xmm0, 0x60(%rsp)
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm4
orpd %xmm1, %xmm4
cvtsi2sd %edi, %xmm1
cmpl $0x18, %edi
movapd %xmm1, 0x30(%rsp)
movsd %xmm4, 0x8(%rsp)
jg 0x7234
xorl %ebp, %ebp
testl %ebx, %ebx
cmovgl %ebx, %ebp
xorpd %xmm2, %xmm2
subl $0x1, %ebp
jb 0x74c1
movapd %xmm2, 0x10(%rsp)
callq 0x69af
movapd 0x10(%rsp), %xmm2
movapd %xmm2, %xmm1
addsd 0x1393(%rip), %xmm1     # 0x85a8
cmpltsd 0x8(%rsp), %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movapd 0x30(%rsp), %xmm1
movapd %xmm0, %xmm2
jmp 0x71ef
movapd %xmm4, %xmm0
mulsd %xmm1, %xmm4
ucomisd %xmm4, %xmm3
jbe 0x72a4
xorpd 0x1576(%rip), %xmm4     # 0x87c0
movapd %xmm4, %xmm0
callq 0x3480
movsd 0x134d(%rip), %xmm2     # 0x85a8
movapd 0x30(%rsp), %xmm1
movsd %xmm0, (%rsp)
leal 0x1(%rbx), %ebp
xorl %r14d, %r14d
cmpl %r14d, %ebp
je 0x74b8
movsd %xmm2, 0x10(%rsp)
callq 0x69af
movsd 0x10(%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd (%rsp), %xmm0
ucomisd %xmm2, %xmm0
ja 0x74af
incl %r14d
movapd 0x30(%rsp), %xmm1
jmp 0x726c
cmpl %ebx, 0x5006(%rip)      # 0xc2b0
movapd %xmm4, 0x40(%rsp)
je 0x72f3
movapd 0x30(%rsp), %xmm1
movsd %xmm1, 0x5170(%rip)     # 0xc430
movsd 0x12e0(%rip), %xmm0     # 0x85a8
addsd %xmm1, %xmm0
callq 0x6b7e
movapd 0x40(%rsp), %xmm4
movsd 0x12c9(%rip), %xmm3     # 0x85a8
movsd %xmm0, 0x5151(%rip)     # 0xc438
movsd 0x8(%rsp), %xmm0
movl %ebx, 0x4fbd(%rip)      # 0xc2b0
ucomisd 0x4fbd(%rip), %xmm0     # 0xc2b8
jne 0x72ff
jnp 0x734d
movapd %xmm0, %xmm1
movapd %xmm3, %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x5105(%rip)     # 0xc418
movapd %xmm1, %xmm0
callq 0x31f0
movsd %xmm0, 0x50fc(%rip)     # 0xc420
movsd 0x50ec(%rip), %xmm0     # 0xc418
callq 0x31f0
movsd 0x8(%rsp), %xmm1
movapd 0x40(%rsp), %xmm4
movsd %xmm0, 0x50e3(%rip)     # 0xc428
movsd %xmm1, 0x4f6b(%rip)     # 0xc2b8
addsd %xmm4, %xmm4
mulsd 0x50bf(%rip), %xmm4     # 0xc418
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm4
jb 0x7369
sqrtsd %xmm4, %xmm0
jmp 0x7372
movapd %xmm4, %xmm0
callq 0x31e0
movsd 0x143e(%rip), %xmm1     # 0x87b8
movsd %xmm0, 0x58(%rsp)
mulsd %xmm0, %xmm1
movsd %xmm1, 0x50(%rsp)
callq 0x69af
mulsd 0x1411(%rip), %xmm0     # 0x87a8
callq 0x3180
movapd %xmm0, %xmm2
movsd 0x58(%rsp), %xmm0
mulsd %xmm2, %xmm0
addsd 0x40(%rsp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
movsd 0x5070(%rip), %xmm1     # 0xc430
addsd 0x11e0(%rip), %xmm1     # 0x85a8
ja 0x738a
ucomisd %xmm1, %xmm0
jae 0x738a
movsd %xmm2, (%rsp)
callq 0x3400
movapd %xmm0, %xmm2
movapd %xmm0, 0x10(%rsp)
movsd (%rsp), %xmm1
mulsd %xmm1, %xmm1
movsd 0x11b3(%rip), %xmm3     # 0x85a8
addsd %xmm3, %xmm1
mulsd 0x50(%rsp), %xmm1
movsd %xmm1, (%rsp)
movsd 0x502c(%rip), %xmm0     # 0xc438
movsd %xmm0, 0x28(%rsp)
addsd %xmm3, %xmm2
movapd %xmm2, %xmm0
callq 0x6b7e
movsd 0x28(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x28(%rsp)
movsd 0x4ff9(%rip), %xmm0     # 0xc430
subsd 0x10(%rsp), %xmm0
addsd 0x1163(%rip), %xmm0     # 0x85a8
callq 0x6b7e
movsd 0x28(%rsp), %xmm3
subsd %xmm0, %xmm3
movsd 0x4fc4(%rip), %xmm1     # 0xc420
movapd 0x10(%rsp), %xmm2
mulsd %xmm2, %xmm1
addsd %xmm3, %xmm1
movsd 0x4fbe(%rip), %xmm0     # 0xc430
subsd %xmm2, %xmm0
mulsd 0x4faa(%rip), %xmm0     # 0xc428
addsd %xmm1, %xmm0
callq 0x3480
mulsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
callq 0x69af
ucomisd (%rsp), %xmm0
ja 0x738a
movapd 0x30(%rsp), %xmm1
movapd 0x10(%rsp), %xmm2
jmp 0x74c1
movl %r14d, %ebp
movapd 0x30(%rsp), %xmm1
cmpl %ebx, %ebp
cmovll %ebp, %ebx
cvtsi2sd %ebx, %xmm2
subsd %xmm2, %xmm1
movapd 0x60(%rsp), %xmm0
cmpneqsd 0x8(%rsp), %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
addq $0x70, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nop