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

   compositor_t compositor;

   compositor.add(
      function_t("is_prime")
      .var("x")
      .expression
      (
         " switch                                                    "
         " {                                                         "
         "    case x <= 1       : return [false];                    "
         "    case frac(x) != 0 : return [false];                    "
         "    case x == 2       : return [true ];                    "
         "    default           :                                    "
         "    {                                                      "
         "       var prime_lut[81] :=                                "
         "       {                                                   "
         "            2,   3,   5,   7,  11,  13,  17,  19,  23,     "
         "           29,  31,  37,  41,  43,  47,  53,  59,  61,     "
         "           67,  71,  73,  79,  83,  89,  97, 101, 103,     "
         "          107, 109, 113, 127, 131, 137, 139, 149, 151,     "
         "          157, 163, 167, 173, 179, 181, 191, 193, 197,     "
         "          199, 211, 223, 227, 229, 233, 239, 241, 251,     "
         "          257, 263, 269, 271, 277, 281, 283, 293, 307,     "
         "          311, 313, 317, 331, 337, 347, 349, 353, 359,     "
         "          367, 373, 379, 383, 389, 397, 401, 409, 419      "
         "       };                                                  "
         "                                                           "
         "       var upper_bound := min(x - 1, trunc(sqrt(x)) + 1);  "
         "                                                           "
         "       for (var i := 0; i < prime_lut[]; i += 1)           "
         "       {                                                   "
         "          if (prime_lut[i] >= upper_bound)                 "
         "             return [true];                                "
         "          else if ((x % prime_lut[i]) == 0)                "
         "             return [false];                               "
         "       };                                                  "
         "                                                           "
         "       var lower_bound := prime_lut[prime_lut[] - 1] + 2;  "
         "                                                           "
         "       for (var i := lower_bound; i < upper_bound; i += 2) "
         "       {                                                   "
         "          if ((x % i) == 0)                                "
         "          {                                                "
         "             return [false];                               "
         "          }                                                "
         "       }                                                   "
         "    };                                                     "
         " };                                                        "
         "                                                           "
         " return [true];                                            "
      ));

   const std::string primes_via_naive_method_program =
      " for (var i := 1; i < 10000; i += 1) "
      " {                                   "
      "    if (is_prime(i))                 "
      "    {                                "
      "       println(i, ' is prime');      "
      "    }                                "
      " };                                  ";

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

   symbol_table_t& symbol_table = compositor.symbol_table();
   symbol_table.add_function("println",println);

   expression_t expression;
   expression.register_symbol_table(symbol_table);

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

   expression.value();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1508, %rsp           # imm = 0x1508
leaq 0xb20(%rsp), %rdi
callq 0x11cb42
leaq 0xb8(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x1b93c2(%rip), %rsi    # 0x2d58e1
leaq 0x1b93c3(%rip), %rdx    # 0x2d58e9
leaq 0xa8(%rsp), %rdi
callq 0x11cab2
leaq 0x1f8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x11cccc
leaq 0x50(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1b92e1(%rip), %rsi    # 0x2d5839
leaq 0x1b92db(%rip), %rdx    # 0x2d583a
leaq 0x40(%rsp), %rdi
callq 0x11cab2
leaq 0x238(%rsp), %rbx
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x12b2dc
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1b935b(%rip), %rsi    # 0x2d58ea
leaq 0x1b9d3d(%rip), %rdx    # 0x2d62d3
movq %rsp, %rdi
callq 0x11cab2
leaq 0x218(%rsp), %r15
movq %rsp, %rsi
movq %r15, %rdi
callq 0x119520
leaq 0x1450(%rsp), %r14
leaq 0x1f8(%rsp), %rsi
movq %r14, %rdi
callq 0x120c1c
leaq 0x1458(%rsp), %rcx
cmpq %rax, %rcx
jne 0x11c683
leaq 0xb20(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x11f97a
testb %al, %al
je 0x11c683
leaq 0x1f8(%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 0x1480(%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 0x12084c
movq (%rax), %r15
leaq 0x1f8(%rsp), %rsi
movq %r14, %rdi
callq 0x120ba0
movq %r15, %rdi
movq %rax, %rsi
callq 0x1208c8
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x11c699
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x11c6b0
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x119090
movq %rbx, %rdi
callq 0x12b576
leaq 0x228(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11c6d9
movq 0x228(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x208(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x11c6fa
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0xa8(%rsp), %rdi
cmpq %r13, %rdi
je 0x11c717
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x119090
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x1b9bb0(%rip), %rsi    # 0x2d62d4
leaq 0x1b9cac(%rip), %rdx    # 0x2d63d7
callq 0x11cab2
leaq 0x1f8(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1b9c96(%rip), %rsi    # 0x2d63d8
leaq 0x1b9c95(%rip), %rdx    # 0x2d63de
callq 0x11cab2
leaq 0x40(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x11cda6
movq 0x1f8(%rsp), %rdi
cmpq %r14, %rdi
je 0x11c77d
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x1f8(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1b9c50(%rip), %rsi    # 0x2d63df
leaq 0x1b9c50(%rip), %rdx    # 0x2d63e6
callq 0x11cab2
leaq 0xb20(%rsp), %rbx
leaq 0x1f8(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x11ceae
movq 0x1f8(%rsp), %rdi
cmpq %r14, %rdi
je 0x11c7d5
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x20(%rsp), %rdi
callq 0x11d038
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rax
subq %rcx, %rax
je 0x11c83e
sarq $0x3, %rax
cmpq $0x1, %rax
movq %rax, %rsi
adcq $0x0, %rsi
cmpq %rbx, %rcx
je 0x11c850
movq 0xb20(%rsp), %rdx
cmpq (%rcx), %rdx
je 0x11c850
addq $0x8, %rcx
movl $0x1, %edi
subq %rsi, %rdi
xorl %esi, %esi
cmpq %rsi, %rdi
je 0x11c83e
decq %rsi
cmpq %rbx, %rcx
je 0x11c836
leaq 0x8(%rcx), %r8
cmpq (%rcx), %rdx
movq %r8, %rcx
jne 0x11c81d
negq %rsi
cmpq %rax, %rsi
jb 0x11c850
leaq 0x28(%rsp), %rdi
leaq 0xb20(%rsp), %rsi
callq 0x12c77c
leaq 0xa8(%rsp), %rdi
movl $0x7f, %esi
callq 0x11d0d2
leaq 0x1f8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x11d1d2
leaq 0x1a8(%rsp), %rdi
callq 0x12c962
leaq 0x178(%rsp), %rdi
callq 0x12c962
leaq 0x148(%rsp), %rdi
callq 0x12c962
leaq 0x118(%rsp), %rdi
callq 0x12c962
leaq 0xe8(%rsp), %rdi
callq 0x12c962
leaq 0xb8(%rsp), %rdi
callq 0x12c962
leaq 0x1f8(%rsp), %rdi
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
callq 0x11d9f6
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
leaq 0x1f8(%rsp), %rdi
callq 0x11e3c8
leaq 0x20(%rsp), %rdi
callq 0x11e68a
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11c921
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x2c33b0(%rip), %rax    # 0x3dfcd8
leaq 0x70(%rsp), %rcx
movq %rax, -0x30(%rcx)
movq -0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0x11c947
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x119090
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x11c95d
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0xb20(%rsp), %rdi
callq 0x11e71a
addq $0x1508, %rsp           # imm = 0x1508
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x11c993
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x11d9ae
jmp 0x11ca13
movq %rax, %rbx
jmp 0x11ca13
jmp 0x11c9bc
movq %rax, %rbx
movq 0x1f8(%rsp), %rdi
cmpq %r14, %rdi
je 0x11ca1d
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x119090
jmp 0x11ca1d
movq %rax, %rbx
jmp 0x11ca1d
movq %rax, %rbx
movq 0x1f8(%rsp), %rdi
cmpq %r14, %rdi
je 0x11ca27
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x119090
jmp 0x11ca27
movq %rax, %rbx
jmp 0x11ca27
jmp 0x11c9fb
jmp 0x11c9ec
movq %rax, %rbx
jmp 0x11ca50
movq %rax, %rbx
jmp 0x11ca67
movq %rax, %rbx
jmp 0x11ca74
movq %rax, %rbx
jmp 0x11ca91
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0x11e3c8
leaq 0x20(%rsp), %rdi
callq 0x11e68a
leaq 0x40(%rsp), %rdi
callq 0x11e6d8
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x11ca91
movq 0x10(%rsp), %rsi
jmp 0x11ca89
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x11ca50
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x11ca67
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x1f8(%rsp), %rdi
callq 0x11cd66
movq 0xa8(%rsp), %rdi
cmpq %r13, %rdi
je 0x11ca91
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0xb20(%rsp), %rdi
callq 0x11e71a
movq %rbx, %rdi
callq 0x1192e0