// File: /workspace/github_cpp_makefile_star2_O3/ArashPartow[P]exprtk-extras/exprtk_factorize_fermat.cpp
// Function: void factorize_fermats_method<double>()
void factorize_fermats_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;

   // Form: n = p*q where p,q are prime
   T composites[] =
   {
       199203677,  779234623,  843093203,  883543291, 1197162971, 1282615157, 1368190717,
      1552390397, 1765737859, 1800091571, 1878769589, 1993904873, 2257133471, 2520523529,
      2579094799, 2853450949, 2935025369, 3095780533, 3164132249, 3408963511, 4260042859,
      4608613981, 4654875857, 5085931997, 6064982771, 7278175081, 7289187463, 9206112101
   };

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

   symbol_table_t symbol_table;

   symbol_table.add_vector  ("composites", composites);
   symbol_table.add_function("println"   , println   );

   compositor_t compositor(symbol_table);

   compositor.add(function_t()
      .name("is_square")
      .var("x")
      .expression
      (
         " var s := sqrt(x);  "
         " var t := trunc(s); "
         " (s - t) == 0;      "
      ));

   compositor.add(function_t()
      .name("fermat")
      .var("n")
      .expression
      (
         " if (n == 0)                     "
         " {                               "
         "    return [0];                  "
         " }                               "
         " else if ((n % 2) == 0)          "
         " {                               "
         "    return [n / 2];              "
         " };                              "
         "                                 "
         " var a := ceil(sqrt(n));         "
         "                                 "
         " while (not(is_square(a^2 - n))) "
         " {                               "
         "    a += 1;                      "
         " };                              "
         "                                 "
         " var b := sqrt(a^2 - n);         "
         "                                 "
         " a - b;                          "
      ));

   const std::string factorize_composites_program =
      " for (var i := 0; i < composites[]; i += 1)                               "
      " {                                                                        "
      "    var n       := composites[i];                                         "
      "    var factor0 := fermat(n);                                             "
      "    var factor1 := n / factor0;                                           "
      "                                                                          "
      "    if ((factor0 * factor1 == n) and (factor0 != 1))                      "
      "    {                                                                     "
      "       println('n: ', n, ' factors: { ', factor0 ,' , ', factor1 ,' } '); "
      "    }                                                                     "
      "    else                                                                  "
      "    {                                                                     "
      "       println('failed to factorize ', n);                                "
      "    }                                                                     "
      " }                                                                        "
      "                                                                          ";
   expression_t expression;
   expression.register_symbol_table(symbol_table);

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

   expression.value();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x15f8, %rsp           # imm = 0x15F8
leaq 0x19b723(%rip), %rsi    # 0x2b4bd0
leaq 0x1510(%rsp), %rdi
movl $0xe0, %edx
callq 0x116060
leaq 0xb38(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x196483(%rip), %rsi    # 0x2af955
leaq 0x196482(%rip), %rdx    # 0x2af95b
leaq 0xb28(%rsp), %rdi
callq 0x119d96
leaq 0x198(%rsp), %rdi
leaq 0xb28(%rsp), %rsi
callq 0x119e2c
movq 0xb28(%rsp), %rdi
cmpq %r14, %rdi
je 0x119518
movq 0xb38(%rsp), %rsi
incq %rsi
callq 0x116090
movq %rsp, %rdi
movl $0x1, %esi
callq 0x119f34
leaq 0xb28(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x196425(%rip), %rsi    # 0x2af95c
leaq 0x196428(%rip), %rdx    # 0x2af966
callq 0x119d96
movq %rsp, %rdi
leaq 0xb28(%rsp), %rsi
leaq 0x1510(%rsp), %rdx
callq 0x119f7c
movq 0xb28(%rsp), %rdi
cmpq %r14, %rdi
je 0x119578
movq 0xb38(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0xb28(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1963dd(%rip), %rsi    # 0x2af967
leaq 0x1963dd(%rip), %rdx    # 0x2af96e
callq 0x119d96
movq %rsp, %rdi
leaq 0xb28(%rsp), %rsi
leaq 0x198(%rsp), %rdx
callq 0x11a14e
movq 0xb28(%rsp), %rdi
cmpq %r14, %rdi
je 0x1195cb
movq 0xb38(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0xb28(%rsp), %rdi
movq %rsp, %rbx
movq %rbx, %rsi
callq 0x11a2b8
leaq 0x200(%rsp), %rdi
callq 0x11a440
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x196374(%rip), %rsi    # 0x2af96f
leaq 0x196376(%rip), %rdx    # 0x2af978
leaq 0x48(%rsp), %rdi
callq 0x119d96
leaq 0x200(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x116520
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x19627f(%rip), %rsi    # 0x2af8ad
leaq 0x196279(%rip), %rdx    # 0x2af8ae
leaq 0x8(%rsp), %rdi
callq 0x119d96
leaq 0x240(%rsp), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x12786c
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x196315(%rip), %rsi    # 0x2af979
leaq 0x19634a(%rip), %rdx    # 0x2af9b5
leaq 0x28(%rsp), %rdi
callq 0x119d96
leaq 0x220(%rsp), %r12
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x116520
leaq 0x1458(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x11fc88
leaq 0x1460(%rsp), %rbp
cmpq %rax, %rbp
jne 0x11975e
leaq 0xb28(%rsp), %rdi
leaq 0x200(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x11e9ee
testb %al, %al
je 0x11975e
leaq 0x200(%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 0x1488(%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 0x11f8ac
movq (%rax), %r12
leaq 0x200(%rsp), %rsi
leaq 0x1458(%rsp), %rdi
callq 0x11fc0c
movq %r12, %rdi
movq %rax, %rsi
callq 0x11f928
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x11977a
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x119796
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x1197ad
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x116090
movq %r15, %rdi
callq 0x127b06
leaq 0x230(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x1197d6
movq 0x230(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x210(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x1197f7
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x200(%rsp), %rdi
callq 0x11a440
leaq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
movq %rax, (%rdi)
leaq 0x19619e(%rip), %rsi    # 0x2af9b6
leaq 0x19619d(%rip), %rdx    # 0x2af9bc
callq 0x119d96
leaq 0x200(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x116520
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
leaq 0x195fd6(%rip), %rsi    # 0x2af820
leaq 0x195fd0(%rip), %rdx    # 0x2af821
callq 0x119d96
leaq 0x240(%rsp), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x12786c
leaq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
movq %rax, (%rdi)
leaq 0x19613e(%rip), %rsi    # 0x2af9bd
leaq 0x1963aa(%rip), %rdx    # 0x2afc30
callq 0x119d96
leaq 0x220(%rsp), %r12
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x116520
leaq 0x200(%rsp), %rsi
leaq 0x1458(%rsp), %rdi
callq 0x11fc88
cmpq %rax, %rbp
jne 0x11996c
leaq 0xb28(%rsp), %rdi
leaq 0x200(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x11e9ee
testb %al, %al
je 0x11996c
leaq 0x200(%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 0x1488(%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 0x11f8ac
movq (%rax), %r12
leaq 0x200(%rsp), %rsi
leaq 0x1458(%rsp), %rdi
callq 0x11fc0c
movq %r12, %rdi
movq %rax, %rsi
callq 0x11f928
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x119988
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1199a4
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x1199c0
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x116090
movq %r15, %rdi
callq 0x127b06
movq 0x220(%rsp), %rdi
cmpq %r14, %rdi
je 0x1199e5
movq 0x230(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x200(%rsp), %rdi
cmpq %r13, %rdi
je 0x119a02
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
leaq 0x19621b(%rip), %rsi    # 0x2afc31
leaq 0x1966b4(%rip), %rdx    # 0x2b00d1
callq 0x119d96
leaq 0x28(%rsp), %rdi
callq 0x11a50c
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rax, %rcx
je 0x119a5e
sarq $0x3, %rcx
movq (%rsp), %rdx
cmpq $0x1, %rcx
adcq $0x0, %rcx
cmpq %rbx, %rax
je 0x119a6b
cmpq (%rax), %rdx
je 0x119a6b
addq $0x8, %rax
decq %rcx
jne 0x119a4b
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
callq 0x127d8c
leaq 0x48(%rsp), %rdi
movl $0x7f, %esi
callq 0x11a598
leaq 0x200(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x11a698
leaq 0x148(%rsp), %rdi
callq 0x127f72
leaq 0x118(%rsp), %rdi
callq 0x127f72
leaq 0xe8(%rsp), %rdi
callq 0x127f72
leaq 0xb8(%rsp), %rdi
callq 0x127f72
leaq 0x88(%rsp), %rdi
callq 0x127f72
leaq 0x58(%rsp), %rdi
callq 0x127f72
leaq 0x200(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x11aebc
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
leaq 0x200(%rsp), %rdi
callq 0x11ba58
leaq 0x28(%rsp), %rdi
callq 0x11bd1a
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x119b30
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0xb28(%rsp), %rdi
callq 0x11bd68
movq %rsp, %rdi
callq 0x11bdca
leaq 0x1f0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x119b66
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x28ece3(%rip), %rax    # 0x3a8850
leaq 0x1c8(%rsp), %rcx
movq %rax, -0x30(%rcx)
movq -0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0x119b92
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x116090
addq $0x15f8, %rsp           # imm = 0x15F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x119bb8
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x11ae74
jmp 0x119c86
movq %rax, %rbx
jmp 0x119c86
movq %rax, %rbx
jmp 0x119c90
jmp 0x119bfe
jmp 0x119bcc
movq %rax, %rbx
jmp 0x119cd4
jmp 0x119bd6
movq %rax, %rbx
jmp 0x119cf0
jmp 0x119bf6
jmp 0x119bfe
jmp 0x119be4
movq %rax, %rbx
jmp 0x119d20
jmp 0x119bee
movq %rax, %rbx
jmp 0x119d3c
movq %rax, %rbx
jmp 0x119d53
movq %rax, %rbx
jmp 0x119d60
jmp 0x119c35
jmp 0x119c0c
jmp 0x119c35
movq %rax, %rbx
movq 0xb28(%rsp), %rdi
cmpq %r14, %rdi
je 0x119d6d
movq 0xb38(%rsp), %rsi
incq %rsi
callq 0x116090
jmp 0x119d6d
movq %rax, %rbx
jmp 0x119d6d
movq %rax, %rbx
jmp 0x119d75
movq %rax, %rbx
movq 0xb28(%rsp), %rdi
cmpq %r14, %rdi
je 0x119d82
movq 0xb38(%rsp), %rsi
incq %rsi
callq 0x116090
jmp 0x119d82
movq %rax, %rbx
jmp 0x119d82
movq %rax, %rbx
leaq 0x200(%rsp), %rdi
callq 0x11ba58
leaq 0x28(%rsp), %rdi
callq 0x11bd1a
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x119d60
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x116090
jmp 0x119d60
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x119cd4
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x119cf0
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
jne 0x119d46
jmp 0x119d53
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x119d20
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x119d3c
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x119d53
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x200(%rsp), %rdi
callq 0x11a4cc
leaq 0xb28(%rsp), %rdi
callq 0x11bd68
movq %rsp, %rdi
callq 0x11bdca
leaq 0x198(%rsp), %rdi
callq 0x11be60
movq %rbx, %rdi
callq 0x1162e0