// File: /workspace/github_cpp_makefile_star2_O2/ArashPartow[P]exprtk-extras/exprtk_e_10kdigits.cpp
// Function: void e_10k_digits<double>()
void e_10k_digits()
{
   typedef exprtk::symbol_table<T> symbol_table_t;
   typedef exprtk::expression<T>   expression_t;
   typedef exprtk::parser<T>       parser_t;

   symbol_table_t symbol_table;

   symbol_table.add_function("print",
                             [](T t) -> T
                             {
                                printf("%1d",static_cast<int>(t));
                                return T(1);
                             });

   const std::string e_10k_digits_spigot =
      " const var num_digits := 10000;                       "
      " var a[num_digits] := [2:1];                          "
      " var b[num_digits] := [1];                            "
      "                                                      "
      " print(2);                                            "
      "                                                      "
      " for (var digit := 0; digit < num_digits; digit += 1) "
      " {                                                    "
      "    b *= 10;                                          "
      "                                                      "
      "    for (var i := (b[] - 1); i > 0; i -= 1)           "
      "    {                                                 "
      "       var q := floor(b[i] / a[i]);                   "
      "       var r := floor(b[i] % a[i]);                   "
      "       b[i - 1] := b[i - 1] + q;                      "
      "       b[i] := r;                                     "
      "    };                                                "
      "                                                      "
      "    print(floor(b[0] / a[0]));                        "
      "                                                      "
      "    b[0] %= a[0];                                     "
      " }                                                    ";

   expression_t expression;
   expression.register_symbol_table(symbol_table);

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

   expression.value();
}

// Assembly:
pushq %rbx
subq $0xac0, %rsp            # imm = 0xAC0
movq %rsp, %rdi
pushq $0x1
popq %rsi
callq 0x1104f8
leaq 0x12adf4(%rip), %rsi    # 0x23b101
leaq 0x198(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x1102b8
leaq 0x28a8(%rip), %rdx      # 0x112bce
movq %rsp, %rdi
leaq 0x198(%rsp), %rsi
callq 0x11051c
leaq 0x198(%rsp), %rdi
callq 0x10e5b8
leaq 0x12adbd(%rip), %rsi    # 0x23b107
leaq 0x28(%rsp), %rdi
leaq 0x198(%rsp), %rdx
callq 0x1102b8
leaq 0x8(%rsp), %rdi
callq 0x1105d0
leaq 0x8(%rsp), %rdi
movq %rsp, %rsi
callq 0x110630
leaq 0x48(%rsp), %rdi
pushq $0x7f
popq %rsi
callq 0x11068c
leaq 0x198(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x11079c
leaq 0x48(%rsp), %rdi
callq 0x110db4
leaq 0x198(%rsp), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x110dfc
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
leaq 0x198(%rsp), %rdi
callq 0x11127e
leaq 0x8(%rsp), %rdi
callq 0x1113b8
leaq 0x28(%rsp), %rdi
callq 0x10e5b8
movq %rsp, %rdi
callq 0x1113ce
addq $0xac0, %rsp            # imm = 0xAC0
popq %rbx
retq
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x110db4
jmp 0x110433
jmp 0x110405
movq %rax, %rbx
jmp 0x110433
movq %rax, %rbx
jmp 0x11043d
jmp 0x11041e
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
jmp 0x110442
movq %rax, %rbx
jmp 0x110447
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
callq 0x11127e
leaq 0x8(%rsp), %rdi
callq 0x1113b8
leaq 0x28(%rsp), %rdi
callq 0x10e5b8
movq %rsp, %rdi
callq 0x1113ce
movq %rbx, %rdi
callq 0x10e310