// File: jc-kim[P]swaptions/CumNormalInv.cpp
// Function: CumNormalInv(double)
FTYPE CumNormalInv( FTYPE u )
{
  // Returns the inverse of cumulative normal distribution function.
  // Reference: Moro, B., 1995, "The Full Monte," RISK (February), 57-58.
  FTYPE x, r;

  x = u - 0.5;
  if( fabs (x) < 0.42 )
  { 
    r = x * x;
    r = x * ((( a[3]*r + a[2]) * r + a[1]) * r + a[0])/
      ((((b[3] * r+ b[2]) * r + b[1]) * r + b[0]) * r + 1.0);
    return (r);
  }

  r = u;
  if( x > 0.0 ) r = 1.0 - u;
  r = log(-log(r));
  r = c[0] + r * (c[1] + r * 
      (c[2] + r * (c[3] + r * 
                   (c[4] + r * (c[5] + r * (c[6] + r * (c[7] + r*c[8])))))));
  if( x < 0.0 ) r = -r;

  return (r);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
movsd 0x2c36(%rip), %xmm1     # 0x5010
subsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm1
movaps 0x2c31(%rip), %xmm0     # 0x5020
pand %xmm0, %xmm1
movsd 0x2c0d(%rip), %xmm0     # 0x5008
ucomisd %xmm1, %xmm0
jbe 0x24d8
movsd -0x18(%rbp), %xmm0
mulsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x18(%rbp), %xmm0
movsd 0x4d47(%rip), %xmm1     # 0x7168
movsd -0x20(%rbp), %xmm3
movsd 0x4d32(%rip), %xmm2     # 0x7160
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
movsd -0x20(%rbp), %xmm3
movsd 0x4d15(%rip), %xmm2     # 0x7158
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
movsd -0x20(%rbp), %xmm3
movsd 0x4cf8(%rip), %xmm2     # 0x7150
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movsd 0x4d1c(%rip), %xmm1     # 0x7188
movsd -0x20(%rbp), %xmm3
movsd 0x4d07(%rip), %xmm2     # 0x7180
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
movsd -0x20(%rbp), %xmm3
movsd 0x4cea(%rip), %xmm2     # 0x7178
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
movsd -0x20(%rbp), %xmm3
movsd 0x4ccd(%rip), %xmm2     # 0x7170
mulsd %xmm3, %xmm1
addsd %xmm2, %xmm1
movsd -0x20(%rbp), %xmm2
mulsd %xmm2, %xmm1
movsd 0x2b5c(%rip), %xmm2     # 0x5018
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x2632
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2502
movsd 0x2b20(%rip), %xmm0     # 0x5018
subsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
callq 0x2100
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0x2100
movsd %xmm0, -0x20(%rbp)
movsd 0x4c5b(%rip), %xmm1     # 0x7190
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x28(%rbp)
movsd 0x4c51(%rip), %xmm3     # 0x7198
movsd -0x20(%rbp), %xmm2
movsd 0x4c4c(%rip), %xmm5     # 0x71a0
movsd -0x20(%rbp), %xmm4
movsd 0x4c47(%rip), %xmm7     # 0x71a8
movsd -0x20(%rbp), %xmm6
movsd 0x4c41(%rip), %xmm9     # 0x71b0
movsd -0x20(%rbp), %xmm8
movsd 0x4c3a(%rip), %xmm11    # 0x71b8
movsd -0x20(%rbp), %xmm10
movsd 0x4c33(%rip), %xmm13    # 0x71c0
movsd -0x20(%rbp), %xmm12
movsd 0x4c2c(%rip), %xmm15    # 0x71c8
movsd -0x20(%rbp), %xmm14
movsd 0x4c26(%rip), %xmm0     # 0x71d0
mulsd %xmm0, %xmm14
movsd -0x28(%rbp), %xmm0
addsd %xmm15, %xmm14
mulsd %xmm14, %xmm12
addsd %xmm13, %xmm12
mulsd %xmm12, %xmm10
addsd %xmm11, %xmm10
mulsd %xmm10, %xmm8
addsd %xmm9, %xmm8
mulsd %xmm8, %xmm6
addsd %xmm7, %xmm6
mulsd %xmm6, %xmm4
addsd %xmm5, %xmm4
mulsd %xmm4, %xmm2
addsd %xmm3, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x20(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x2628
movsd -0x20(%rbp), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x20(%rbp)
movsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)