// File: nwieder[P]SSTS/src/Random/Uni_Rnd.cpp
// Function: nw::Uni_Rnd::uni_Rnd(long*)
double Uni_Rnd::uni_Rnd(long* idum){

	int j;
	long k;
	static long iy=0;
	static long iv[NTAB];
	double temp;
//	Initialize.
	if (*idum <= 0 || !iy){
// 		Make sure to prevent idum = 0.
		if (-(*idum) < 1) *idum=1;
		else *idum = -(*idum);
//		Load the shuffle table (after 8 warm-ups).
		for (j=NTAB+7;j>=0;j--){
			k=(*idum)/IQ;
			*idum=IA*(*idum-k*IQ)-IR*k;
			if (*idum < 0) *idum += IM;
			if (j < NTAB) iv[j] = *idum;
		}
	   iy=iv[0];
	}
// 	Start here when not initializing.
	k=(*idum)/IQ;
// 	Compute idum=(IA*idum) % IM without over
	*idum=IA*(*idum-k*IQ)-IR*k;

// 	flows by Schrage's method.
	if (*idum < 0) *idum += IM;

// 	Will be in the range 0..NTAB-1.
	j=iy/NDIV;
//  Output previously stored value and refill the
	iy=iv[j];
//	shuffle table.
	iv[j] = *idum;

// 	Because users don't expect endpoint values.
	if ((temp=AM*iy) > RNMX) return RNMX;
	else return temp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jle 0x19014
cmpq $0x0, 0x4541a(%rip)     # 0x5e428
jne 0x190e6
movq -0x18(%rbp), %rcx
xorl %eax, %eax
subq (%rcx), %rax
cmpq $0x1, %rax
jge 0x19030
movq -0x18(%rbp), %rax
movq $0x1, (%rax)
jmp 0x19040
movq -0x18(%rbp), %rax
xorl %ecx, %ecx
subq (%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movl $0x27, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x190d8
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl $0x1f31d, %ecx          # imm = 0x1F31D
cqto
idivq %rcx
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1f31d, -0x28(%rbp), %rcx # imm = 0x1F31D
subq %rcx, %rax
imulq $0x41a7, %rax, %rcx     # imm = 0x41A7
imulq $0xb14, -0x28(%rbp), %rax # imm = 0xB14
subq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jge 0x190ac
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
movq %rcx, (%rax)
cmpl $0x20, -0x1c(%rbp)
jge 0x190c8
movq -0x18(%rbp), %rax
movq (%rax), %rdx
movslq -0x1c(%rbp), %rcx
leaq 0x4536c(%rip), %rax     # 0x5e430
movq %rdx, (%rax,%rcx,8)
jmp 0x190ca
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x19047
movq 0x45351(%rip), %rax     # 0x5e430
movq %rax, 0x45342(%rip)     # 0x5e428
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl $0x1f31d, %ecx          # imm = 0x1F31D
cqto
idivq %rcx
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
imulq $0x1f31d, -0x28(%rbp), %rcx # imm = 0x1F31D
subq %rcx, %rax
imulq $0x41a7, %rax, %rcx     # imm = 0x41A7
imulq $0xb14, -0x28(%rbp), %rax # imm = 0xB14
subq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, (%rax)
jge 0x19141
movq -0x18(%rbp), %rax
movq (%rax), %rcx
addq $0x7fffffff, %rcx       # imm = 0x7FFFFFFF
movq %rcx, (%rax)
movq 0x452e0(%rip), %rax     # 0x5e428
movl $0x4000000, %ecx        # imm = 0x4000000
cqto
idivq %rcx
movl %eax, -0x1c(%rbp)
movslq -0x1c(%rbp), %rcx
leaq 0x452d0(%rip), %rax     # 0x5e430
movq (%rax,%rcx,8), %rax
movq %rax, 0x452bd(%rip)     # 0x5e428
movq -0x18(%rbp), %rax
movq (%rax), %rdx
movslq -0x1c(%rbp), %rcx
leaq 0x452b3(%rip), %rax     # 0x5e430
movq %rdx, (%rax,%rcx,8)
cvtsi2sdq 0x4529e(%rip), %xmm1 # 0x5e428
movsd 0x2c78e(%rip), %xmm0    # 0x45920
mulsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd 0x2c775(%rip), %xmm1    # 0x45918
ucomisd %xmm1, %xmm0
jbe 0x191b8
movsd 0x2c767(%rip), %xmm0    # 0x45918
movsd %xmm0, -0x8(%rbp)
jmp 0x191c2
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
popq %rbp
retq
nopl (%rax)