// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
movq %rdx, %rbx
movq %rdi, %r14
movl %esi, 0x18(%rdi)
movslq %esi, %rax
leaq (,%rax,8), %rdi
testl %eax, %eax
movq $-0x1, %rcx
cmovsq %rcx, %rdi
leaq (,%rax,4), %r15
cmovsq %rcx, %r15
callq 0x7030
movq %rax, 0x8(%r14)
movq %r15, %rdi
callq 0x7030
movq %rax, 0x10(%r14)
movl 0x18(%r14), %eax
testl %eax, %eax
jle 0xd5fc
movq 0x8(%r14), %rcx
movq 0x10(%r14), %rdx
xorl %esi, %esi
movq $0x0, (%rcx,%rsi,8)
movl $0xffffffff, (%rdx,%rsi,4) # imm = 0xFFFFFFFF
incq %rsi
movslq 0x18(%r14), %rdi
cmpq %rdi, %rsi
jl 0xd5e1
movl 0x18(%r14), %esi
testl %esi, %esi
jle 0xd723
cvtsi2sd %eax, %xmm2
movsd 0x27a04(%rip), %xmm0    # 0x35018
movapd %xmm0, %xmm1
divsd %xmm2, %xmm1
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
xorl %edx, %edx
movsd 0x27e0a(%rip), %xmm2    # 0x35438
movsd 0x27e5a(%rip), %xmm3    # 0x35490
movsd 0x27e5a(%rip), %xmm4    # 0x35498
testl %esi, %esi
jle 0xd6ba
movq 0x8(%r14), %r8
movl %esi, %r9d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %r10d, %r10d
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movapd %xmm2, %xmm6
movapd %xmm0, %xmm7
cmpl $0x0, (%rcx,%r10,4)
jns 0xd6a3
movsd (%rbx,%r10,8), %xmm5
subsd (%r8,%r10,8), %xmm5
ucomisd %xmm6, %xmm5
movapd %xmm6, %xmm8
cmpnlesd %xmm5, %xmm8
movapd %xmm8, %xmm9
andnpd %xmm5, %xmm9
andpd %xmm6, %xmm8
orpd %xmm9, %xmm8
movapd %xmm8, %xmm6
cmovael %r10d, %esi
ucomisd %xmm5, %xmm7
jae 0xd6b5
movapd %xmm7, %xmm5
incq %r10
movapd %xmm5, %xmm7
cmpq %r10, %r9
jne 0xd65e
jmp 0xd6c8
movl %r10d, %edi
jmp 0xd6a7
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movapd %xmm0, %xmm5
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
testl %esi, %esi
js 0xd729
testl %edi, %edi
js 0xd729
movl %edi, %edi
movl %esi, (%rcx,%rdi,4)
movapd %xmm1, %xmm6
subsd %xmm5, %xmm6
movl %esi, %esi
movsd (%rax,%rsi,8), %xmm5
addsd %xmm6, %xmm5
movsd %xmm5, (%rax,%rsi,8)
xorps %xmm5, %xmm5
cvtsi2sdl 0x18(%r14), %xmm5
mulsd %xmm6, %xmm5
movsd %xmm5, (%rax,%rdi,8)
ucomisd %xmm3, %xmm5
ja 0xd747
ucomisd %xmm5, %xmm4
ja 0xd747
incl %edx
movl 0x18(%r14), %esi
cmpl %esi, %edx
jl 0xd63e
ucomisd 0x27d7f(%rip), %xmm5    # 0x354a0
ja 0xd774
popq %rbx
popq %r14
popq %r15
retq
movl $0x1, %edi
callq 0x7180
movq %rax, %rbx
leaq 0x280f3(%rip), %rsi     # 0x35830
movq %rax, %rdi
callq 0xb82c
jmp 0xd763
movl $0x1, %edi
callq 0x7180
movq %rax, %rbx
leaq 0x280ea(%rip), %rsi     # 0x35845
movq %rax, %rdi
callq 0xb82c
leaq 0x3b51e(%rip), %rsi     # 0x48c88
movq %rbx, %rdi
xorl %edx, %edx
callq 0x7660
movl $0x1, %edi
callq 0x7180
movq %rax, %rbx
leaq 0x280de(%rip), %rsi     # 0x35866
movq %rax, %rdi
callq 0xb82c
jmp 0xd763
jmp 0xd796
jmp 0xd796
movq %rax, %r14
movq %rbx, %rdi
callq 0x72a0
movq %r14, %rdi
callq 0x76a0
nop