// File: /workspace/github_cpp_makefile_star2_O2/ArashPartow[P]exprtk-extras/exprtk_archimedes_pi.cpp
// Function: void archimedes_pi<double>()
void archimedes_pi()
{
   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;

   exprtk::rtl::io::println<T> println("%25.23f");

   symbol_table_t symbol_table;

   symbol_table.add_function("println", println);
   symbol_table.add_constants();

   compositor_t compositor(symbol_table);

   compositor.add(
      function_t("archimedes_pi")
      .var("iterations")
      .expression
      (
         " var s         := 1.0;                    "
         " var approx_pi := 0.0;                    "
         "                                          "
         " for (var i := 0; i < iterations; i += 1) "
         " {                                        "
         "     var n  := 6 * 2^i;                   "
         "     var s2 := (s / 2)^2;                 "
         "     var t  := sqrt(1 - s2);              "
         "     var q  := 1 - t;                     "
         "     var p  := n * s;                     "
         "                                          "
         "     approx_pi := p / 2;                  "
         "     s         := sqrt(q^2 + s2);         "
         " };                                       "
         "                                          "
         " approx_pi;                               "
      ));

   const std::string archimedes_pi_program =
      " const var n := 30;                                              "
      "                                                                 "
      " for (var i := 1; i <= n; i += 1)                                "
      " {                                                               "
      "    var approx_pi := archimedes_pi(i);                           "
      "    var abs_error := abs(approx_pi - pi);                        "
      "                                                                 "
      "    println('approx pi: ', approx_pi, ' abs error:', abs_error); "
      " }                                                               ";

   expression_t expression;
   expression.register_symbol_table(symbol_table);

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

   expression.value();
}

// Assembly:
pushq %rbx
subq $0x1520, %rsp           # imm = 0x1520
leaq 0x130dfb(%rip), %rsi    # 0x24411d
leaq 0xb38(%rsp), %rdi
leaq 0x210(%rsp), %rdx
callq 0x1132d8
leaq 0x58(%rsp), %rdi
leaq 0xb38(%rsp), %rsi
callq 0x1136f2
leaq 0xb38(%rsp), %rdi
callq 0x1115d8
leaq 0x10(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x113784
leaq 0x130dbb(%rip), %rsi    # 0x244125
leaq 0xb38(%rsp), %rdi
leaq 0x210(%rsp), %rdx
callq 0x1132d8
leaq 0x10(%rsp), %rdi
leaq 0xb38(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x1137a8
leaq 0xb38(%rsp), %rdi
callq 0x1115d8
leaq 0x10(%rsp), %rdi
callq 0x113870
leaq 0xb38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x113896
leaq 0x130d67(%rip), %rsi    # 0x24412d
leaq 0xc0(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x1132d8
leaq 0x210(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x1139b4
leaq 0x130d47(%rip), %rsi    # 0x24413b
leaq 0x38(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x1132d8
leaq 0x250(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x11e63e
leaq 0x130d2a(%rip), %rsi    # 0x244146
leaq 0x18(%rsp), %rdi
leaq 0xd(%rsp), %rdx
callq 0x1132d8
leaq 0x230(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x111550
leaq 0xb38(%rsp), %rdi
leaq 0x210(%rsp), %rsi
xorl %edx, %edx
callq 0x1139a4
leaq 0x18(%rsp), %rdi
callq 0x1115d8
leaq 0x38(%rsp), %rdi
callq 0x1115d8
leaq 0x210(%rsp), %rdi
callq 0x113a00
leaq 0xc0(%rsp), %rdi
callq 0x1115d8
leaq 0x130f5e(%rip), %rsi    # 0x2443e7
leaq 0x38(%rsp), %rdi
leaq 0x210(%rsp), %rdx
callq 0x1132d8
leaq 0x18(%rsp), %rdi
callq 0x113a20
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x113a80
leaq 0xc0(%rsp), %rdi
pushq $0x7f
popq %rsi
callq 0x113adc
leaq 0x210(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x113bec
leaq 0xc0(%rsp), %rdi
callq 0x114204
leaq 0x210(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x11424c
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
leaq 0x210(%rsp), %rdi
callq 0x1146ce
leaq 0x18(%rsp), %rdi
callq 0x114808
leaq 0x38(%rsp), %rdi
callq 0x1115d8
leaq 0xb38(%rsp), %rdi
callq 0x11481e
leaq 0x10(%rsp), %rdi
callq 0x114872
leaq 0x58(%rsp), %rdi
callq 0x1148b4
addq $0x1520, %rsp           # imm = 0x1520
popq %rbx
retq
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x114204
jmp 0x1135e6
jmp 0x11356b
movq %rax, %rbx
jmp 0x1135e6
movq %rax, %rbx
jmp 0x1135f0
jmp 0x113591
jmp 0x113579
movq %rax, %rbx
jmp 0x113604
movq %rax, %rbx
jmp 0x11360e
movq %rax, %rbx
jmp 0x11361b
movq %rax, %rbx
jmp 0x113628
jmp 0x1135b2
jmp 0x1135b2
movq %rax, %rbx
leaq 0xb38(%rsp), %rdi
callq 0x1115d8
jmp 0x113635
movq %rax, %rbx
jmp 0x113635
movq %rax, %rbx
jmp 0x11363f
movq %rax, %rbx
leaq 0xb38(%rsp), %rdi
callq 0x1115d8
jmp 0x113649
movq %rax, %rbx
jmp 0x113649
movq %rax, %rbx
leaq 0x210(%rsp), %rdi
callq 0x1146ce
leaq 0x18(%rsp), %rdi
callq 0x114808
leaq 0x38(%rsp), %rdi
jmp 0x113623
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x1115d8
leaq 0x38(%rsp), %rdi
callq 0x1115d8
leaq 0x210(%rsp), %rdi
callq 0x113a00
leaq 0xc0(%rsp), %rdi
callq 0x1115d8
leaq 0xb38(%rsp), %rdi
callq 0x11481e
leaq 0x10(%rsp), %rdi
callq 0x114872
leaq 0x58(%rsp), %rdi
callq 0x1148b4
movq %rbx, %rdi
callq 0x111310