// File: WolfgangLechner[P]StructureAnalysis/molecular_system.cpp
// Function: CMolecularSystem::PLM(int, int, double)
double CMolecularSystem::PLM(int l, int m, double x)
{
  double fact,pll,pmm,pmmp1,somx2;
  int i,ll;
  pll = 0.0;
  if (m < 0 || m > l || fabs(x) > 1.0)
  cerr << "impossible combination of l and m" << "\n";
  pmm=1.0;
  if (m > 0)
  {
    somx2=sqrt((1.0-x)*(1.0+x));
    fact=1.0;
    for (i=1;i<=m;i++)
    {
      pmm *= -fact*somx2;
      fact += 2.0;
    }
  }
  if (l == m)
    return pmm;
  else
  {
    pmmp1=x*(2*m+1)*pmm;
    if (l == (m+1))
      return pmmp1;
    else
    {
      for (ll=m+2;ll<=l;ll++)
        {
          pll=(x*(2*ll-1)*pmmp1-(ll+m-1)*pmm)/(ll-m);
          pmm=pmmp1;
          pmmp1=pll;
        }
        return pll;
     }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movsd %xmm0, -0x20(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
cmpl $0x0, -0x18(%rbp)
jl 0x6aeb
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x6aeb
movsd -0x20(%rbp), %xmm0
movaps 0x56e7(%rip), %xmm1     # 0xc1c0
pand %xmm1, %xmm0
movsd 0x5593(%rip), %xmm1     # 0xc078
ucomisd %xmm1, %xmm0
jbe 0x6b0d
movq 0x84fe(%rip), %rdi      # 0xeff0
leaq 0x58a5(%rip), %rsi      # 0xc39e
callq 0x3200
movq %rax, %rdi
leaq 0x5982(%rip), %rsi      # 0xc48a
callq 0x3200
movsd 0x5563(%rip), %xmm0     # 0xc078
movsd %xmm0, -0x38(%rbp)
cmpl $0x0, -0x18(%rbp)
jle 0x6bb2
movsd 0x554c(%rip), %xmm0     # 0xc078
subsd -0x20(%rbp), %xmm0
movsd 0x553f(%rip), %xmm1     # 0xc078
addsd -0x20(%rbp), %xmm1
mulsd %xmm1, %xmm0
callq 0x31a0
movsd %xmm0, -0x48(%rbp)
movsd 0x5524(%rip), %xmm0     # 0xc078
movsd %xmm0, -0x28(%rbp)
movl $0x1, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0x6bb0
movsd -0x28(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd -0x48(%rbp), %xmm0
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd 0x55bd(%rip), %xmm0     # 0xc158
addsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x6b60
jmp 0x6bb2
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x6bc9
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x6ca3
movsd -0x20(%rbp), %xmm0
movl -0x18(%rbp), %eax
shll %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
mulsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x14(%rbp), %eax
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0x6c04
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x6ca3
movl -0x18(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x6c99
movsd -0x20(%rbp), %xmm0
movl -0x50(%rbp), %eax
shll %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
movsd -0x40(%rbp), %xmm2
movl -0x50(%rbp), %eax
addl -0x18(%rbp), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
mulsd -0x38(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movl -0x50(%rbp), %eax
subl -0x18(%rbp), %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x6c0d
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x50, %rsp
popq %rbp
retq
nop