// File: melop[P]admixem/./newran02/newran.cpp
// Function: DiscreteGen::Gen(int, double*)
void DiscreteGen::Gen(int n1, Real* prob)
{
   n=n1;                                         // number of values
   p=new Real[n]; ialt=new int[n];
   if (!p || !ialt)  ErrorNoSpace();
   Real rn = 1.0/n; Real px = 0; int i;
   for (i=0; i<n; i++) { p[i]=0.0; ialt[i]=-1; }
   for (i=0; i<n; i++)
   {
      Real pmin=1.0; Real pmax=-1.0; int jmin=-1; int jmax=-1;
      for (int j=0; j<n; j++)
      {
         if (ialt[j]<0)
         {
            px=prob[j]-p[j];
            if (pmax<=px) { pmax=px; jmax=j; }
            if (pmin>=px) { pmin=px; jmin=j; }
         }
      }
      if ((jmax<0) || (jmin<0)) Throw(Runtime_error("Newran: method fails"));
      ialt[jmin]=jmax; px=rn-pmin; p[jmax]+=px; px*=n; p[jmin]=px;
      if ((px>1.00001)||(px<-.00001))
         Throw(Runtime_error("Newran: probs don't add to 1 (a)"));
   }
   if (px>0.00001) Throw(Runtime_error("Newran: probs don't add to 1 (b)"));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0xc(%rbp), %ecx
movl %ecx, 0x18(%rax)
movslq 0x18(%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x8040
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x8(%rax)
movslq 0x18(%rax), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x8040
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x10(%rax)
cmpq $0x0, 0x8(%rax)
je 0x16066
movq -0x68(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x1606b
callq 0x136a0
movq -0x68(%rbp), %rax
cvtsi2sdl 0x18(%rax), %xmm1
movsd 0x5ff94(%rip), %xmm0    # 0x76010
divsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x68(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl 0x18(%rcx), %eax
jge 0x160ce
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rcx
movslq -0x2c(%rbp), %rdx
xorps %xmm0, %xmm0
movsd %xmm0, (%rcx,%rdx,8)
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x16094
movl $0x0, -0x2c(%rbp)
movq -0x68(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl 0x18(%rcx), %eax
jge 0x162db
movsd 0x5ff23(%rip), %xmm0    # 0x76010
movsd %xmm0, -0x38(%rbp)
movsd 0x6059e(%rip), %xmm0    # 0x76698
movsd %xmm0, -0x40(%rbp)
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x4c(%rbp)
movq -0x68(%rbp), %rcx
movl -0x4c(%rbp), %eax
cmpl 0x18(%rcx), %eax
jge 0x161a7
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x4c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jge 0x16197
movq -0x68(%rbp), %rax
movq -0x18(%rbp), %rcx
movslq -0x4c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
movq 0x8(%rax), %rax
movslq -0x4c(%rbp), %rcx
subsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x40(%rbp), %xmm1
movsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x16179
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x48(%rbp)
movsd -0x38(%rbp), %xmm0
ucomisd -0x28(%rbp), %xmm0
jb 0x16195
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x16197
jmp 0x16199
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x16114
cmpl $0x0, -0x48(%rbp)
jl 0x161b3
cmpl $0x0, -0x44(%rbp)
jge 0x16203
movl $0x1, %edi
callq 0x8230
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x70(%rbp)
leaq 0x6089a(%rip), %rsi     # 0x76a68
callq 0x12df0
jmp 0x161d5
movq -0x70(%rbp), %rdi
leaq 0x93ab8(%rip), %rsi     # 0xa9c98
xorl %eax, %eax
movl %eax, %edx
callq 0x8820
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x8370
jmp 0x16344
movq -0x68(%rbp), %rax
movl -0x48(%rbp), %esi
movq 0x10(%rax), %rcx
movslq -0x44(%rbp), %rdx
movl %esi, (%rcx,%rdx,4)
movsd -0x20(%rbp), %xmm0
subsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movq 0x8(%rax), %rcx
movslq -0x48(%rbp), %rdx
addsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
cvtsi2sdl 0x18(%rax), %xmm0
mulsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
movq 0x8(%rax), %rax
movslq -0x44(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd -0x28(%rbp), %xmm0
movsd 0x60497(%rip), %xmm1    # 0x76700
ucomisd %xmm1, %xmm0
ja 0x1627e
movsd 0x60491(%rip), %xmm0    # 0x76708
ucomisd -0x28(%rbp), %xmm0
jbe 0x162cb
movl $0x1, %edi
callq 0x8230
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x78(%rbp)
leaq 0x607e4(%rip), %rsi     # 0x76a7d
callq 0x12df0
jmp 0x162a0
movq -0x78(%rbp), %rdi
leaq 0x939ed(%rip), %rsi     # 0xa9c98
xorl %eax, %eax
movl %eax, %edx
callq 0x8820
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x8370
jmp 0x16344
jmp 0x162cd
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x160d5
movsd -0x28(%rbp), %xmm0
movsd 0x60410(%rip), %xmm1    # 0x766f8
ucomisd %xmm1, %xmm0
jbe 0x1633b
movl $0x1, %edi
callq 0x8230
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x80(%rbp)
leaq 0x60795(%rip), %rsi     # 0x76a9e
callq 0x12df0
jmp 0x16310
movq -0x80(%rbp), %rdi
leaq 0x9397d(%rip), %rsi     # 0xa9c98
xorl %eax, %eax
movl %eax, %edx
callq 0x8820
movq -0x80(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x8370
jmp 0x16344
addq $0x80, %rsp
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x8860
nopl (%rax)