// File: /workspace/github_cpp_makefile_star2_O1/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 0x11bb56
movq %rbx, %rdi
callq 0x11bb9e
leaq 0xae0(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1b8322(%rip), %rsi    # 0x2d3845
leaq 0x1b831c(%rip), %rdx    # 0x2d3846
leaq 0xad0(%rsp), %rdi
callq 0x11bac6
movq %rsp, %rdi
leaq 0xad0(%rsp), %rsi
leaq 0x8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x11bce4
movq 0xad0(%rsp), %rdi
cmpq %r14, %rdi
je 0x11b56b
movq 0xae0(%rsp), %rsi
incq %rsi
callq 0x118090
leaq 0xad0(%rsp), %rdi
movq %rsp, %rbx
movq %rbx, %rsi
callq 0x11be52
leaq 0x68(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1b835a(%rip), %rsi    # 0x2d38e8
leaq 0x1b835e(%rip), %rdx    # 0x2d38f3
leaq 0x58(%rsp), %rdi
callq 0x11bac6
leaq 0x1a8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x11bfda
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1b8284(%rip), %rsi    # 0x2d3845
leaq 0x1b827e(%rip), %rdx    # 0x2d3846
leaq 0x10(%rsp), %rdi
callq 0x11bac6
leaq 0x1e8(%rsp), %r14
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x12af38
leaq 0x40(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x1b82fd(%rip), %rsi    # 0x2d38f4
leaq 0x1b86d0(%rip), %rdx    # 0x2d3cce
leaq 0x30(%rsp), %rdi
callq 0x11bac6
leaq 0x1c8(%rsp), %r12
leaq 0x30(%rsp), %rsi
movq %r12, %rdi
callq 0x118520
leaq 0x1400(%rsp), %r15
leaq 0x1a8(%rsp), %rsi
movq %r15, %rdi
callq 0x1214b0
leaq 0x1408(%rsp), %rcx
cmpq %rax, %rcx
jne 0x11b6ef
leaq 0xad0(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
movq %r12, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x12020e
testb %al, %al
je 0x11b6ef
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 0x1210e0
movq (%rax), %r12
leaq 0x1a8(%rsp), %rsi
movq %r15, %rdi
callq 0x121434
movq %r12, %rdi
movq %rax, %rsi
callq 0x12115c
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x11b706
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x118090
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %r15
cmpq %r15, %rdi
je 0x11b722
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x118090
movq %r14, %rdi
callq 0x12b1d2
leaq 0x1d8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11b74b
movq 0x1d8(%rsp), %rsi
incq %rsi
callq 0x118090
leaq 0x1b8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11b76c
movq 0x1b8(%rsp), %rsi
incq %rsi
callq 0x118090
movq 0x58(%rsp), %rdi
cmpq %rbp, %rdi
je 0x11b783
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x118090
leaq 0x10(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x1b853d(%rip), %rsi    # 0x2d3ccf
leaq 0x1b8544(%rip), %rdx    # 0x2d3cdd
callq 0x11bac6
leaq 0x30(%rsp), %rdi
callq 0x11c0b4
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %rax
subq %rcx, %rax
je 0x11b803
sarq $0x3, %rax
cmpq $0x1, %rax
movq %rax, %rsi
adcq $0x0, %rsi
cmpq %rbx, %rcx
je 0x11b810
movq (%rsp), %rdx
cmpq (%rcx), %rdx
je 0x11b810
addq $0x8, %rcx
movl $0x1, %edi
subq %rsi, %rdi
xorl %esi, %esi
cmpq %rsi, %rdi
je 0x11b803
decq %rsi
cmpq %rbx, %rcx
je 0x11b7fb
leaq 0x8(%rcx), %r8
cmpq (%rcx), %rdx
movq %r8, %rcx
jne 0x11b7e2
negq %rsi
cmpq %rax, %rsi
jb 0x11b810
leaq 0x38(%rsp), %rdi
movq %rsp, %rsi
callq 0x12b444
leaq 0x58(%rsp), %rdi
movl $0x7f, %esi
callq 0x11c14e
leaq 0x1a8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x11c24e
leaq 0x158(%rsp), %rdi
callq 0x12b62a
leaq 0x128(%rsp), %rdi
callq 0x12b62a
leaq 0xf8(%rsp), %rdi
callq 0x12b62a
leaq 0xc8(%rsp), %rdi
callq 0x12b62a
leaq 0x98(%rsp), %rdi
callq 0x12b62a
leaq 0x68(%rsp), %rdi
callq 0x12b62a
leaq 0x1a8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x11ca72
movq $0x0, 0x8(%rsp)
movl $0x54, %ebp
leaq 0x1b8436(%rip), %rbx    # 0x2d3cde
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movapd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
ucomisd 0x1b37df(%rip), %xmm0   # 0x2cf0a8
jb 0x11b8d4
xorps %xmm2, %xmm2
sqrtsd %xmm0, %xmm2
jmp 0x11b8e9
movsd %xmm1, 0x50(%rsp)
callq 0x118230
movsd 0x50(%rsp), %xmm1
movapd %xmm0, %xmm2
movapd %xmm1, %xmm3
subsd %xmm2, %xmm3
andpd 0x1b3717(%rip), %xmm3   # 0x2cf010
movsd 0x1b378f(%rip), %xmm0   # 0x2cf090
ucomisd %xmm3, %xmm0
movsd 0x8(%rsp), %xmm0
movl $0x46, %esi
cmovael %ebp, %esi
movq %rbx, %rdi
movb $0x4, %al
callq 0x118050
movsd 0x8(%rsp), %xmm0
addsd 0x1b376d(%rip), %xmm0   # 0x2cf098
movsd %xmm0, 0x8(%rsp)
movsd 0x1b3767(%rip), %xmm1   # 0x2cf0a0
ucomisd %xmm0, %xmm1
ja 0x11b8a8
leaq 0x1a8(%rsp), %rdi
callq 0x11d444
leaq 0x30(%rsp), %rdi
callq 0x11d706
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x11b971
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x118090
leaq 0xad0(%rsp), %rdi
callq 0x11d754
movq %rsp, %rdi
callq 0x11d7b6
addq $0x14b8, %rsp           # imm = 0x14B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x11b9b1
jmp 0x11ba68
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x11ca2a
jmp 0x11ba78
movq %rax, %rbx
jmp 0x11ba78
movq %rax, %rbx
jmp 0x11ba82
jmp 0x11b9d7
jmp 0x11b9c5
movq %rax, %rbx
jmp 0x11ba2e
movq %rax, %rbx
jmp 0x11ba4a
movq %rax, %rbx
jmp 0x11ba57
movq %rax, %rbx
jmp 0x11ba9e
jmp 0x11ba0c
movq %rax, %rbx
movq 0xad0(%rsp), %rdi
cmpq %r14, %rdi
je 0x11baab
movq 0xae0(%rsp), %rsi
incq %rsi
callq 0x118090
jmp 0x11baab
jmp 0x11ba0c
movq %rax, %rbx
jmp 0x11baab
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x11ba2e
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x118090
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x11ba4a
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x118090
leaq 0x1a8(%rsp), %rdi
callq 0x11c074
movq 0x58(%rsp), %rdi
cmpq %rbp, %rdi
je 0x11ba9e
movq 0x68(%rsp), %rsi
jmp 0x11ba96
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
callq 0x11d444
leaq 0x30(%rsp), %rdi
callq 0x11d706
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x11ba9e
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x118090
leaq 0xad0(%rsp), %rdi
callq 0x11d754
movq %rsp, %rdi
callq 0x11d7b6
movq %rbx, %rdi
callq 0x1182e0