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

   symbol_table_t symbol_table;

   compositor_t compositor(symbol_table);

   // define function: sum_of_primes(z)
   compositor.add(
      function_t("sum_of_primes")
        .var("z")
        .expression(
          " var i     := 2;      "
          " var total := 0;      "
          " while (z > 1)        "
          " {                    "
          "    if (0 == (z % i)) "
          "    {                 "
          "       total += i;    "
          "       z /= i;        "
          "    }                 "
          "    else              "
          "       i += 1;        "
          " };                   "
          " total;               "));

   exprtk::rtl::io::println<T> println;

   symbol_table.add_function("println",println);

   const std::string sum_of_prime_factors_program =
      " for (var i := 1; i <= 100; i += 1) "
      " {                                  "
      "    println(i, sum_of_primes(i));   "
      " }                                  ";

   expression_t expression;
   expression.register_symbol_table(symbol_table);

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

   expression.value();
}

// Assembly:
subq $0x16c8, %rsp           # imm = 0x16C8
leaq 0x16c0(%rsp), %rdi
movq %rdi, 0x40(%rsp)
movl $0x1, %esi
callq 0x11c090
movq 0x40(%rsp), %rsi
leaq 0xcd8(%rsp), %rdi
callq 0x11c0d0
jmp 0x11b862
leaq 0xc17(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x114660
movq 0x38(%rsp), %rdx
leaq 0x347ce5(%rip), %rsi    # 0x463565
leaq 0xc18(%rsp), %rdi
callq 0x11b770
jmp 0x11b88f
leaq 0xc38(%rsp), %rdi
leaq 0xc18(%rsp), %rsi
callq 0x11c2c0
jmp 0x11b8a6
leaq 0xbef(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x114660
movq 0x30(%rsp), %rdx
leaq 0x347caf(%rip), %rsi    # 0x463573
leaq 0xbf0(%rsp), %rdi
callq 0x11b770
jmp 0x11b8d3
leaq 0xc38(%rsp), %rdi
leaq 0xbf0(%rsp), %rsi
callq 0x11c340
movq %rax, 0x28(%rsp)
jmp 0x11b8ef
leaq 0xbc7(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x114660
movq 0x20(%rsp), %rdx
leaq 0x347c68(%rip), %rsi    # 0x463575
leaq 0xbc8(%rsp), %rdi
callq 0x11b770
jmp 0x11b91c
movq 0x28(%rsp), %rdi
leaq 0xbc8(%rsp), %rsi
callq 0x11c370
movq %rax, 0x18(%rsp)
jmp 0x11b935
movq 0x18(%rsp), %rsi
leaq 0xcd8(%rsp), %rdi
xorl %edx, %edx
callq 0x11c270
jmp 0x11b94b
leaq 0xbc8(%rsp), %rdi
callq 0x1147a8
leaq 0xbc7(%rsp), %rdi
callq 0x114790
leaq 0xbf0(%rsp), %rdi
callq 0x1147a8
leaq 0xbef(%rsp), %rdi
callq 0x114790
leaq 0xc38(%rsp), %rdi
callq 0x11c3a0
leaq 0xc18(%rsp), %rdi
callq 0x1147a8
leaq 0xc17(%rsp), %rdi
callq 0x114790
leaq 0xb37(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x114660
movq 0x10(%rsp), %rdx
leaq 0x347cd0(%rip), %rsi    # 0x463694
leaq 0xb38(%rsp), %rdi
callq 0x11b770
jmp 0x11b9d3
leaq 0xb58(%rsp), %rdi
leaq 0xb38(%rsp), %rsi
callq 0x11c3e0
jmp 0x11b9ea
leaq 0xb38(%rsp), %rdi
callq 0x1147a8
leaq 0xb37(%rsp), %rdi
callq 0x114790
leaq 0xb0f(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x114660
movq 0x8(%rsp), %rdx
leaq 0x347c79(%rip), %rsi    # 0x46369b
leaq 0xb10(%rsp), %rdi
callq 0x11b770
jmp 0x11ba31
leaq 0x16c0(%rsp), %rdi
leaq 0xb10(%rsp), %rsi
leaq 0xb58(%rsp), %rdx
callq 0x11c4f0
jmp 0x11ba50
leaq 0xb10(%rsp), %rdi
callq 0x1147a8
leaq 0xb0f(%rsp), %rdi
callq 0x114790
leaq 0xae7(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x114660
movq (%rsp), %rdx
leaq 0x347c1d(%rip), %rsi    # 0x4636a3
leaq 0xae8(%rsp), %rdi
callq 0x11b770
jmp 0x11ba95
leaq 0xae7(%rsp), %rdi
callq 0x114790
leaq 0xac0(%rsp), %rdi
callq 0x11c6f0
jmp 0x11bab1
leaq 0xac0(%rsp), %rdi
leaq 0x16c0(%rsp), %rsi
callq 0x11c7a0
jmp 0x11bac8
leaq 0x48(%rsp), %rdi
movl $0x7f, %esi
callq 0x11c850
jmp 0x11bad9
leaq 0x198(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x11c980
jmp 0x11baed
leaq 0x48(%rsp), %rdi
callq 0x11d1b0
leaq 0x198(%rsp), %rdi
leaq 0xae8(%rsp), %rsi
leaq 0xac0(%rsp), %rdx
callq 0x11d220
jmp 0x11bb16
leaq 0xac0(%rsp), %rdi
callq 0x11dab0
jmp 0x11bb25
leaq 0x198(%rsp), %rdi
callq 0x11dad0
leaq 0xac0(%rsp), %rdi
callq 0x11dcd0
leaq 0xae8(%rsp), %rdi
callq 0x1147a8
leaq 0xb58(%rsp), %rdi
callq 0x11dd10
leaq 0xcd8(%rsp), %rdi
callq 0x11dd40
leaq 0x16c0(%rsp), %rdi
callq 0x11ddd0
addq $0x16c8, %rsp           # imm = 0x16C8
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
jmp 0x11bdd5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
jmp 0x11bc6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
jmp 0x11bc5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
jmp 0x11bc43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
jmp 0x11bc36
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
jmp 0x11bc29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
leaq 0xbc8(%rsp), %rdi
callq 0x1147a8
leaq 0xbc7(%rsp), %rdi
callq 0x114790
leaq 0xbf0(%rsp), %rdi
callq 0x1147a8
leaq 0xbef(%rsp), %rdi
callq 0x114790
leaq 0xc38(%rsp), %rdi
callq 0x11c3a0
leaq 0xc18(%rsp), %rdi
callq 0x1147a8
leaq 0xc17(%rsp), %rdi
callq 0x114790
jmp 0x11bdc8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
jmp 0x11bcb3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
leaq 0xb38(%rsp), %rdi
callq 0x1147a8
leaq 0xb37(%rsp), %rdi
callq 0x114790
jmp 0x11bdc8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
jmp 0x11bcfc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
leaq 0xb10(%rsp), %rdi
callq 0x1147a8
leaq 0xb0f(%rsp), %rdi
callq 0x114790
jmp 0x11bdbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
leaq 0xae7(%rsp), %rdi
callq 0x114790
jmp 0x11bdbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
jmp 0x11bdae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
jmp 0x11bda1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x11d1b0
jmp 0x11bda1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xcd0(%rsp)
movl %eax, 0xccc(%rsp)
leaq 0x198(%rsp), %rdi
callq 0x11dad0
leaq 0xac0(%rsp), %rdi
callq 0x11dcd0
leaq 0xae8(%rsp), %rdi
callq 0x1147a8
leaq 0xb58(%rsp), %rdi
callq 0x11dd10
leaq 0xcd8(%rsp), %rdi
callq 0x11dd40
leaq 0x16c0(%rsp), %rdi
callq 0x11ddd0
movq 0xcd0(%rsp), %rdi
callq 0x114450
nop