// File: /workspace/github_cpp_makefile_star2_O3/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
movq $-0x1, %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)
testl %r13d, %r13d
jle 0xd7d0
cvtsi2sd %ebp, %xmm0
movsd 0x2694a(%rip), %xmm1    # 0x34018
movapd %xmm1, %xmm2
divsd %xmm0, %xmm2
movl %ebp, %ecx
xorl %edx, %edx
movq $0x0, (%r14,%rdx,8)
movl $0xffffffff, (%rax,%rdx,4) # imm = 0xFFFFFFFF
incq %rdx
cmpq %r13, %rdx
jl 0xd6da
testl %ebp, %ebp
jle 0xd7d0
xorl %edx, %edx
movsd 0x26d05(%rip), %xmm3    # 0x34408
movsd 0x26d55(%rip), %xmm4    # 0x34460
movsd 0x26d55(%rip), %xmm5    # 0x34468
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movapd %xmm3, %xmm7
movapd %xmm1, %xmm6
cmpl $0x0, (%rax,%r8,4)
jns 0xd777
movsd (%rbx,%r8,8), %xmm8
subsd (%r14,%r8,8), %xmm8
ucomisd %xmm7, %xmm8
movapd %xmm7, %xmm9
cmpnlesd %xmm8, %xmm9
movapd %xmm9, %xmm10
andnpd %xmm8, %xmm10
andpd %xmm7, %xmm9
orpd %xmm10, %xmm9
movapd %xmm9, %xmm7
cmovael %r8d, %esi
ucomisd %xmm8, %xmm6
jb 0xd777
movapd %xmm8, %xmm6
movl %r8d, %edi
incq %r8
cmpq %r8, %rcx
jne 0xd728
testl %esi, %esi
js 0xd7df
testl %edi, %edi
js 0xd7df
movl %edi, %edi
movl %esi, (%rax,%rdi,4)
movapd %xmm2, %xmm7
subsd %xmm6, %xmm7
movl %esi, %esi
movsd (%r14,%rsi,8), %xmm6
addsd %xmm7, %xmm6
movsd %xmm6, (%r14,%rsi,8)
mulsd %xmm0, %xmm7
movsd %xmm7, (%r14,%rdi,8)
ucomisd %xmm4, %xmm7
ja 0xd7fd
ucomisd %xmm7, %xmm5
ja 0xd7fd
incl %edx
cmpl %ecx, %edx
jl 0xd713
ucomisd 0x26ca2(%rip), %xmm7    # 0x34470
ja 0xd82a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x7180
movq %rax, %rbx
leaq 0x2705d(%rip), %rsi     # 0x34850
movq %rax, %rdi
callq 0xb924
jmp 0xd819
movl $0x1, %edi
callq 0x7180
movq %rax, %rbx
leaq 0x27054(%rip), %rsi     # 0x34865
movq %rax, %rdi
callq 0xb924
leaq 0x3a468(%rip), %rsi     # 0x47c88
movq %rbx, %rdi
xorl %edx, %edx
callq 0x7660
movl $0x1, %edi
callq 0x7180
movq %rax, %rbx
leaq 0x27048(%rip), %rsi     # 0x34886
movq %rax, %rdi
callq 0xb924
jmp 0xd819
jmp 0xd84c
jmp 0xd84c
movq %rax, %r14
movq %rbx, %rdi
callq 0x72a0
movq %r14, %rdi
callq 0x76a0
nop