// File: /workspace/github_cpp_makefile_star2_O3/ArashPartow[P]exprtk/exprtk_simple_example_10.cpp
// Function: void newton_sqrt<double>()
void newton_sqrt()
{
   typedef exprtk::symbol_table<T>         symbol_table_t;
   typedef exprtk::expression<T>           expression_t;
   typedef exprtk::parser<T>               parser_t;
   typedef exprtk::function_compositor<T>  compositor_t;
   typedef typename compositor_t::function function_t;

   T x = T(0);

   symbol_table_t symbol_table;

   symbol_table.add_constants();
   symbol_table.add_variable("x",x);

   compositor_t compositor(symbol_table);

   compositor.add(
      function_t("newton_sqrt")
      .var("x")
      .expression
      (
         " switch                                                   "
         " {                                                        "
         "    case x < 0  : null;                                   "
         "    case x == 0 : 0;                                      "
         "    case x == 1 : 1;                                      "
         "    default:                                              "
         "    {                                                     "
         "       var remaining_itrs := 100;                         "
         "       var sqrt_x := x / 2;                               "
         "       repeat                                             "
         "          if (equal(sqrt_x * sqrt_x, x))                  "
         "             break[sqrt_x];                               "
         "          else                                            "
         "             sqrt_x := (1 / 2) * (sqrt_x + (x / sqrt_x)); "
         "       until ((remaining_itrs -= 1) <= 0);                "
         "    };                                                    "
         " }                                                        "
      ));

   const std::string expression_str = "newton_sqrt(x)";

   expression_t expression;
   expression.register_symbol_table(symbol_table);

   parser_t parser;
   parser.compile(expression_str,expression);

   for (x = T(0); x < T(500); x += T(0.5))
   {
      const T result = expression.value();
      const T real   = std::sqrt(x);
      const T error  = std::abs(result - real);

      const bool err_in_bound = error <= exprtk::details::numeric::constant::pi;

      printf("sqrt(%6.2f) - Result: %15.13f\tReal: %15.13f\tError: %18.16f EIB: %c\n",
             x,
             result,
             real,
             error,
             err_in_bound ? 'T' : 'F');
   }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x14b8, %rsp           # imm = 0x14B8
movq $0x0, 0x8(%rsp)
movq %rsp, %rbx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x119ae0
movq %rbx, %rdi
callq 0x119b28
leaq 0xae0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1963f3(%rip), %rsi    # 0x2af8bd
leaq 0x1963ed(%rip), %rdx    # 0x2af8be
leaq 0xad0(%rsp), %rdi
callq 0x119a4a
movq %rsp, %rdi
leaq 0xad0(%rsp), %rsi
leaq 0x8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x119c6e
movq 0xad0(%rsp), %rdi
cmpq %r14, %rdi
je 0x119512
movq 0xae0(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0xad0(%rsp), %rdi
movq %rsp, %rbx
movq %rbx, %rsi
callq 0x119dbe
leaq 0x68(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x19642b(%rip), %rsi    # 0x2af960
leaq 0x19642f(%rip), %rdx    # 0x2af96b
leaq 0x58(%rsp), %rdi
callq 0x119a4a
leaq 0x1a8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x119f46
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x196355(%rip), %rsi    # 0x2af8bd
leaq 0x19634f(%rip), %rdx    # 0x2af8be
leaq 0x10(%rsp), %rdi
callq 0x119a4a
leaq 0x1e8(%rsp), %r14
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x12700a
leaq 0x40(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1963ce(%rip), %rsi    # 0x2af96c
leaq 0x1967a1(%rip), %rdx    # 0x2afd46
leaq 0x30(%rsp), %rdi
callq 0x119a4a
leaq 0x1c8(%rsp), %r12
leaq 0x30(%rsp), %rsi
movq %r12, %rdi
callq 0x116520
leaq 0x1400(%rsp), %r15
leaq 0x1a8(%rsp), %rsi
movq %r15, %rdi
callq 0x11ed64
leaq 0x1408(%rsp), %rcx
cmpq %rax, %rcx
jne 0x119696
leaq 0xad0(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
movq %r12, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x11daca
testb %al, %al
je 0x119696
leaq 0x1a8(%rsp), %rsi
movq 0x88(%rsi), %rax
movq %rax, %rcx
subq 0x68(%rsi), %rcx
shrq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
movq 0x60(%rsi), %rax
movq 0x70(%rsi), %rdx
subq 0x78(%rsi), %rdx
subq 0x50(%rsi), %rax
sarq $0x5, %rdx
sarq $0x5, %rax
leaq (%rcx,%rcx,2), %rcx
shlq $0x8, %rcx
addq 0x1430(%rsp), %rcx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
addq %rdx, %rdi
addq %rcx, %rdi
callq 0x11e988
movq (%rax), %r12
leaq 0x1a8(%rsp), %rsi
movq %r15, %rdi
callq 0x11ece8
movq %r12, %rdi
movq %rax, %rsi
callq 0x11ea04
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1196ad
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %r15
cmpq %r15, %rdi
je 0x1196c9
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x116090
movq %r14, %rdi
callq 0x1272a4
leaq 0x1d8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1196f2
movq 0x1d8(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x1b8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x119713
movq 0x1b8(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x58(%rsp), %rdi
cmpq %r13, %rdi
je 0x11972a
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x10(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x19660e(%rip), %rsi    # 0x2afd47
leaq 0x196615(%rip), %rdx    # 0x2afd55
callq 0x119a4a
leaq 0x30(%rsp), %rdi
callq 0x11a020
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rcx
subq %rax, %rcx
je 0x119781
sarq $0x3, %rcx
movq (%rsp), %rdx
cmpq $0x1, %rcx
adcq $0x0, %rcx
cmpq %rbx, %rax
je 0x11978e
cmpq (%rax), %rdx
je 0x11978e
addq $0x8, %rax
decq %rcx
jne 0x11976e
leaq 0x38(%rsp), %rdi
movq %rsp, %rsi
callq 0x12752a
leaq 0x58(%rsp), %rdi
movl $0x7f, %esi
callq 0x11a0ac
leaq 0x1a8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x11a1ac
leaq 0x158(%rsp), %rdi
callq 0x127710
leaq 0x128(%rsp), %rdi
callq 0x127710
leaq 0xf8(%rsp), %rdi
callq 0x127710
leaq 0xc8(%rsp), %rdi
callq 0x127710
leaq 0x98(%rsp), %rdi
callq 0x127710
leaq 0x68(%rsp), %rdi
callq 0x127710
leaq 0x1a8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x11a9d0
movq $0x0, 0x8(%rsp)
movl $0x54, %ebp
leaq 0x196530(%rip), %rbx    # 0x2afd56
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movapd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
ucomisd 0x191871(%rip), %xmm0   # 0x2ab0b8
jb 0x119852
xorps %xmm2, %xmm2
sqrtsd %xmm0, %xmm2
jmp 0x119867
movsd %xmm1, 0x50(%rsp)
callq 0x116230
movsd 0x50(%rsp), %xmm1
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
subsd %xmm2, %xmm3
andpd 0x191799(%rip), %xmm3   # 0x2ab010
movsd 0x191821(%rip), %xmm0   # 0x2ab0a0
ucomisd %xmm3, %xmm0
movsd 0x8(%rsp), %xmm0
movl $0x46, %esi
cmovael %ebp, %esi
movq %rbx, %rdi
movb $0x4, %al
callq 0x116050
movsd 0x8(%rsp), %xmm0
addsd 0x1917ff(%rip), %xmm0   # 0x2ab0a8
movsd %xmm0, 0x8(%rsp)
movsd 0x1917f9(%rip), %xmm1   # 0x2ab0b0
ucomisd %xmm0, %xmm1
ja 0x119826
leaq 0x1a8(%rsp), %rdi
callq 0x11b56c
leaq 0x30(%rsp), %rdi
callq 0x11b82e
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x1198f4
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0xad0(%rsp), %rdi
callq 0x11b87c
movq %rsp, %rdi
callq 0x11b8de
addq $0x14b8, %rsp           # imm = 0x14B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x119934
jmp 0x1199eb
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x11a988
jmp 0x1199fb
movq %rax, %rbx
jmp 0x1199fb
movq %rax, %rbx
jmp 0x119a05
jmp 0x11995a
jmp 0x119948
movq %rax, %rbx
jmp 0x1199b1
movq %rax, %rbx
jmp 0x1199cd
movq %rax, %rbx
jmp 0x1199da
movq %rax, %rbx
jmp 0x119a21
jmp 0x11998f
movq %rax, %rbx
movq 0xad0(%rsp), %rdi
cmpq %r14, %rdi
je 0x119a2e
movq 0xae0(%rsp), %rsi
incq %rsi
callq 0x116090
jmp 0x119a2e
jmp 0x11998f
movq %rax, %rbx
jmp 0x119a2e
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1199b1
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x1199cd
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x1a8(%rsp), %rdi
callq 0x119fe0
movq 0x58(%rsp), %rdi
cmpq %r13, %rdi
je 0x119a21
movq 0x68(%rsp), %rsi
jmp 0x119a19
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
callq 0x11b56c
leaq 0x30(%rsp), %rdi
callq 0x11b82e
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x119a21
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0xad0(%rsp), %rdi
callq 0x11b87c
movq %rsp, %rdi
callq 0x11b8de
movq %rbx, %rdi
callq 0x1162e0