// File: /workspace/github_cpp_makefile_star2_O3/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 0x119ac6
leaq 0xb8(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x196493(%rip), %rsi    # 0x2af959
leaq 0x196494(%rip), %rdx    # 0x2af961
leaq 0xa8(%rsp), %rdi
callq 0x119a30
leaq 0x1f8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x119c50
leaq 0x50(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1963b2(%rip), %rsi    # 0x2af8b1
leaq 0x1963ac(%rip), %rdx    # 0x2af8b2
leaq 0x40(%rsp), %rdi
callq 0x119a30
leaq 0x238(%rsp), %rbx
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x126850
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x19642c(%rip), %rsi    # 0x2af962
leaq 0x196e0e(%rip), %rdx    # 0x2b034b
movq %rsp, %rdi
callq 0x119a30
leaq 0x218(%rsp), %r15
movq %rsp, %rsi
movq %r15, %rdi
callq 0x116520
leaq 0x1450(%rsp), %r14
leaq 0x1f8(%rsp), %rsi
movq %r14, %rdi
callq 0x11dd4c
leaq 0x1458(%rsp), %rcx
cmpq %rax, %rcx
jne 0x11962a
leaq 0xb20(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x11cab2
testb %al, %al
je 0x11962a
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 0x11d970
movq (%rax), %r15
leaq 0x1f8(%rsp), %rsi
movq %r14, %rdi
callq 0x11dcd0
movq %r15, %rdi
movq %rax, %rsi
callq 0x11d9ec
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x119640
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x119657
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x116090
movq %rbx, %rdi
callq 0x126aea
leaq 0x228(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x119680
movq 0x228(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x208(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x1196a1
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0xa8(%rsp), %rdi
cmpq %r13, %rdi
je 0x1196be
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x116090
movq %rsp, %rdi
movq %r12, (%rdi)
leaq 0x196c81(%rip), %rsi    # 0x2b034c
leaq 0x196d7d(%rip), %rdx    # 0x2b044f
callq 0x119a30
leaq 0x1f8(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x196d67(%rip), %rsi    # 0x2b0450
leaq 0x196d66(%rip), %rdx    # 0x2b0456
callq 0x119a30
leaq 0x40(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x119d2a
movq 0x1f8(%rsp), %rdi
cmpq %r14, %rdi
je 0x119724
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x1f8(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x196d21(%rip), %rsi    # 0x2b0457
leaq 0x196d21(%rip), %rdx    # 0x2b045e
callq 0x119a30
leaq 0xb20(%rsp), %rbx
leaq 0x1f8(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x119e32
movq 0x1f8(%rsp), %rdi
cmpq %r14, %rdi
je 0x11977c
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x20(%rsp), %rdi
callq 0x119f9c
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
subq %rax, %rcx
je 0x1197bc
sarq $0x3, %rcx
movq 0xb20(%rsp), %rdx
cmpq $0x1, %rcx
adcq $0x0, %rcx
cmpq %rbx, %rax
je 0x1197ce
cmpq (%rax), %rdx
je 0x1197ce
addq $0x8, %rax
decq %rcx
jne 0x1197a9
leaq 0x28(%rsp), %rdi
leaq 0xb20(%rsp), %rsi
callq 0x127866
leaq 0xa8(%rsp), %rdi
movl $0x7f, %esi
callq 0x11a028
leaq 0x1f8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x11a128
leaq 0x1a8(%rsp), %rdi
callq 0x127a4c
leaq 0x178(%rsp), %rdi
callq 0x127a4c
leaq 0x148(%rsp), %rdi
callq 0x127a4c
leaq 0x118(%rsp), %rdi
callq 0x127a4c
leaq 0xe8(%rsp), %rdi
callq 0x127a4c
leaq 0xb8(%rsp), %rdi
callq 0x127a4c
leaq 0x1f8(%rsp), %rdi
movq %rsp, %rsi
leaq 0x20(%rsp), %rdx
callq 0x11a94c
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
leaq 0x1f8(%rsp), %rdi
callq 0x11b4e8
leaq 0x20(%rsp), %rdi
callq 0x11b7aa
leaq 0x98(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11989f
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x28ff3a(%rip), %rax    # 0x3a97e0
leaq 0x70(%rsp), %rcx
movq %rax, -0x30(%rcx)
movq -0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0x1198c5
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x116090
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x1198db
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0xb20(%rsp), %rdi
callq 0x11b83a
addq $0x1508, %rsp           # imm = 0x1508
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x119911
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x11a904
jmp 0x119991
movq %rax, %rbx
jmp 0x119991
jmp 0x11993a
movq %rax, %rbx
movq 0x1f8(%rsp), %rdi
cmpq %r14, %rdi
je 0x11999b
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x116090
jmp 0x11999b
movq %rax, %rbx
jmp 0x11999b
movq %rax, %rbx
movq 0x1f8(%rsp), %rdi
cmpq %r14, %rdi
je 0x1199a5
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x116090
jmp 0x1199a5
movq %rax, %rbx
jmp 0x1199a5
jmp 0x119979
jmp 0x11996a
movq %rax, %rbx
jmp 0x1199ce
movq %rax, %rbx
jmp 0x1199e5
movq %rax, %rbx
jmp 0x1199f2
movq %rax, %rbx
jmp 0x119a0f
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0x11b4e8
leaq 0x20(%rsp), %rdi
callq 0x11b7aa
leaq 0x40(%rsp), %rdi
callq 0x11b7f8
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x119a0f
movq 0x10(%rsp), %rsi
jmp 0x119a07
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x1199ce
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1199e5
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x1f8(%rsp), %rdi
callq 0x119cea
movq 0xa8(%rsp), %rdi
cmpq %r13, %rdi
je 0x119a0f
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0xb20(%rsp), %rdi
callq 0x11b83a
movq %rbx, %rdi
callq 0x1162e0