// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r15
movl %esi, 0x18(%rdi)
movslq %esi, %r13
leaq (,%r13,8), %rdi
testl %r13d, %r13d
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
leaq (,%r13,4), %r12
cmovsq %rax, %r12
callq 0x7030
movq %rax, %r14
movq %rax, 0x8(%r15)
movq %r12, %rdi
callq 0x7030
movq %rax, 0x10(%r15)
cvtsi2sd %r13d, %xmm0
xorl %ecx, %ecx
cmpq %r13, %rcx
jge 0xca9d
andq $0x0, (%r14,%rcx,8)
orl $-0x1, (%rax,%rcx,4)
incq %rcx
jmp 0xca8a
movsd 0x2056b(%rip), %xmm1    # 0x2d010
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
movl %ebp, %ecx
xorl %edx, %edx
xorpd %xmm6, %xmm6
pushq $-0x1
popq %rsi
movsd 0x20968(%rip), %xmm3    # 0x2d428
movsd 0x209b8(%rip), %xmm4    # 0x2d480
movsd 0x209b8(%rip), %xmm5    # 0x2d488
cmpl %ebp, %edx
jge 0xcbaa
xorl %r9d, %r9d
movapd %xmm1, %xmm7
movapd %xmm3, %xmm6
movl %esi, %r8d
movl %esi, %edi
cmpq %r9, %rcx
je 0xcb48
cmpl $0x0, (%rax,%r9,4)
jns 0xcb34
movsd (%rbx,%r9,8), %xmm8
subsd (%r14,%r9,8), %xmm8
ucomisd %xmm6, %xmm8
movapd %xmm6, %xmm9
cmpnlesd %xmm8, %xmm9
movapd %xmm9, %xmm10
andnpd %xmm8, %xmm10
andpd %xmm6, %xmm9
orpd %xmm10, %xmm9
movapd %xmm9, %xmm6
cmovael %r9d, %edi
ucomisd %xmm8, %xmm7
jae 0xcb43
movapd %xmm7, %xmm8
incq %r9
movapd %xmm8, %xmm7
jmp 0xcae8
movl %r9d, %r8d
jmp 0xcb39
testl %edi, %edi
js 0xcbc3
testl %r8d, %r8d
js 0xcbc3
movl %r8d, %r8d
movl %edi, (%rax,%r8,4)
movapd %xmm2, %xmm6
subsd %xmm7, %xmm6
movl %edi, %edi
movsd (%r14,%rdi,8), %xmm7
addsd %xmm6, %xmm7
movsd %xmm7, (%r14,%rdi,8)
mulsd %xmm0, %xmm6
movsd %xmm6, (%r14,%r8,8)
ucomisd %xmm4, %xmm6
ja 0xcb8e
incl %edx
ucomisd %xmm6, %xmm5
jbe 0xcad0
pushq $0x1
popq %rdi
callq 0x71d0
movq %rax, %rbx
leaq 0x20c95(%rip), %rsi     # 0x2d835
movq %rax, %rdi
callq 0xb076
jmp 0xcbdd
ucomisd 0x208c6(%rip), %xmm6    # 0x2d478
ja 0xcbee
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rdi
callq 0x71d0
movq %rax, %rbx
leaq 0x20c4b(%rip), %rsi     # 0x2d820
movq %rax, %rdi
callq 0xb076
leaq 0x380c4(%rip), %rsi     # 0x44ca8
movq %rbx, %rdi
xorl %edx, %edx
callq 0x76a0
pushq $0x1
popq %rdi
callq 0x71d0
movq %rax, %rbx
leaq 0x20c56(%rip), %rsi     # 0x2d856
movq %rax, %rdi
callq 0xb076
jmp 0xcbdd
jmp 0xcc0e
jmp 0xcc0e
movq %rax, %r14
movq %rbx, %rdi
callq 0x7300
movq %r14, %rdi
callq 0x76d0
nop