// File: /workspace/github_cpp_makefile_star2_O3/ArashPartow[P]exprtk-extras/exprtk_factorize_pollard.cpp
// Function: void factorize_pollards_rho<double>()
void factorize_pollards_rho()
{
   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, 1552390397, 1765737859, 1878769589, 1993904873,
      2257133471, 2520523529, 2579094799, 2853450949, 2935025369,
      3095780533, 3164132249, 3408963511, 4260042859, 4608613981,
      4654875857, 5085931997, 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("gcd")
      .var("x") .var("y")
      .expression
      (
         " x := abs(x);       "
         " y := abs(y);       "
         " while (0 != y)     "
         " {                  "
         "    var r := x % y; "
         "    x := y;         "
         "    y := r;         "
         " };                 "
         " x                  "
      ));

   compositor.add(function_t()
      .name("pollard_rho")
      .var("n")
      .expression
      (
         " var c  := 10;                "
         " var a1 := 1 + c;             "
         " var a2 := 11 + c;            "
         "                              "
         " while (gcd(n, a2 - a1) == 1) "
         " {                            "
         "    /* The Tortoise */        "
         "    a1 := (a1^2 + c) % n;     "
         "                              "
         "    /* The Hare */            "
         "    a2 := (a2^2 + c) % n;     "
         "    a2 := (a2^2 + c) % n;     "
         " };                           "
         "                              "
         " var g := gcd(n, a2 - a1);    "
         "                              "
         " n / g                        "
      ));

   const std::string factorize_composites_program =
      " for (var i := 0; i < composites[]; i += 1)                               "
      " {                                                                        "
      "    var n       := composites[i];                                         "
      "    var factor0 := pollard_rho(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 0x19b733(%rip), %rsi    # 0x2b4be0
leaq 0x1530(%rsp), %rdi
movl $0xc8, %edx
callq 0x116060
leaq 0xb58(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x196483(%rip), %rsi    # 0x2af955
leaq 0x196482(%rip), %rdx    # 0x2af95b
leaq 0xb48(%rsp), %rdi
callq 0x119dea
leaq 0x1b8(%rsp), %rdi
leaq 0xb48(%rsp), %rsi
callq 0x119e80
movq 0xb48(%rsp), %rdi
cmpq %r14, %rdi
je 0x119518
movq 0xb58(%rsp), %rsi
incq %rsi
callq 0x116090
movq %rsp, %rdi
movl $0x1, %esi
callq 0x119f88
leaq 0xb48(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x196425(%rip), %rsi    # 0x2af95c
leaq 0x196428(%rip), %rdx    # 0x2af966
callq 0x119dea
movq %rsp, %rdi
leaq 0xb48(%rsp), %rsi
leaq 0x1530(%rsp), %rdx
callq 0x119fd0
movq 0xb48(%rsp), %rdi
cmpq %r14, %rdi
je 0x119578
movq 0xb58(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0xb48(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1963dd(%rip), %rsi    # 0x2af967
leaq 0x1963dd(%rip), %rdx    # 0x2af96e
callq 0x119dea
movq %rsp, %rdi
leaq 0xb48(%rsp), %rsi
leaq 0x1b8(%rsp), %rdx
callq 0x11a1a2
movq 0xb48(%rsp), %rdi
cmpq %r14, %rdi
je 0x1195cb
movq 0xb58(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0xb48(%rsp), %rdi
movq %rsp, %rbx
movq %rbx, %rsi
callq 0x11a30c
leaq 0x220(%rsp), %rdi
callq 0x11a494
leaq 0x78(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x196374(%rip), %rsi    # 0x2af96f
leaq 0x196370(%rip), %rdx    # 0x2af972
leaq 0x68(%rsp), %rdi
callq 0x119dea
leaq 0x220(%rsp), %rdi
leaq 0x68(%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 0x119dea
leaq 0x260(%rsp), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x1278c0
leaq 0x38(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x196c04(%rip), %rsi    # 0x2b0268
leaq 0x196bfe(%rip), %rdx    # 0x2b0269
leaq 0x28(%rsp), %rdi
callq 0x119dea
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x1278c0
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1962e1(%rip), %rsi    # 0x2af973
leaq 0x19638e(%rip), %rdx    # 0x2afa27
leaq 0x48(%rsp), %rdi
callq 0x119dea
leaq 0x240(%rsp), %r12
leaq 0x48(%rsp), %rsi
movq %r12, %rdi
callq 0x116520
leaq 0x1478(%rsp), %rdi
leaq 0x220(%rsp), %rsi
callq 0x11fcdc
leaq 0x1480(%rsp), %rcx
cmpq %rax, %rcx
jne 0x11978c
leaq 0xb48(%rsp), %rdi
leaq 0x220(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x11ea42
testb %al, %al
je 0x11978c
leaq 0x220(%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 0x14a8(%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 0x11f900
movq (%rax), %r12
leaq 0x220(%rsp), %rsi
leaq 0x1478(%rsp), %rdi
callq 0x11fc60
movq %r12, %rdi
movq %rax, %rsi
callq 0x11f97c
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x1197a3
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1197ba
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1197d6
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x68(%rsp), %rdi
cmpq %r13, %rdi
je 0x1197ed
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x116090
movq %r15, %rdi
callq 0x127b5a
leaq 0x250(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x119816
movq 0x250(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x230(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x119837
movq 0x230(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x220(%rsp), %rdi
callq 0x11a494
leaq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
movq %rax, (%rdi)
leaq 0x1961d0(%rip), %rsi    # 0x2afa28
leaq 0x1961d4(%rip), %rdx    # 0x2afa33
callq 0x119dea
leaq 0x220(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x116520
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
leaq 0x195f96(%rip), %rsi    # 0x2af820
leaq 0x195f90(%rip), %rdx    # 0x2af821
callq 0x119dea
leaq 0x260(%rsp), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x1278c0
leaq 0x28(%rsp), %rdi
movq %rbp, (%rdi)
leaq 0x19617a(%rip), %rsi    # 0x2afa34
leaq 0x196371(%rip), %rdx    # 0x2afc32
callq 0x119dea
leaq 0x240(%rsp), %r12
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x116520
leaq 0x220(%rsp), %rsi
leaq 0x1478(%rsp), %rdi
callq 0x11fcdc
leaq 0x1480(%rsp), %rcx
cmpq %rax, %rcx
jne 0x1199af
leaq 0xb48(%rsp), %rdi
leaq 0x220(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x11ea42
testb %al, %al
je 0x1199af
leaq 0x220(%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 0x14a8(%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 0x11f900
movq (%rax), %r12
leaq 0x220(%rsp), %rsi
leaq 0x1478(%rsp), %rdi
callq 0x11fc60
movq %r12, %rdi
movq %rax, %rsi
callq 0x11f97c
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1199c6
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x1199e2
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x1199fe
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x116090
movq %r15, %rdi
callq 0x127b5a
movq 0x240(%rsp), %rdi
cmpq %r14, %rdi
je 0x119a23
movq 0x250(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x220(%rsp), %rdi
cmpq %r13, %rdi
je 0x119a40
movq 0x230(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
leaq 0x1961df(%rip), %rsi    # 0x2afc33
leaq 0x196678(%rip), %rdx    # 0x2b00d3
callq 0x119dea
leaq 0x28(%rsp), %rdi
callq 0x11a560
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rax, %rcx
je 0x119a9c
sarq $0x3, %rcx
movq (%rsp), %rdx
cmpq $0x1, %rcx
adcq $0x0, %rcx
cmpq %rbx, %rax
je 0x119aa9
cmpq (%rax), %rdx
je 0x119aa9
addq $0x8, %rax
decq %rcx
jne 0x119a89
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
callq 0x127de0
leaq 0x68(%rsp), %rdi
movl $0x7f, %esi
callq 0x11a5ec
leaq 0x220(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x11a6ec
leaq 0x168(%rsp), %rdi
callq 0x127fc6
leaq 0x138(%rsp), %rdi
callq 0x127fc6
leaq 0x108(%rsp), %rdi
callq 0x127fc6
leaq 0xd8(%rsp), %rdi
callq 0x127fc6
leaq 0xa8(%rsp), %rdi
callq 0x127fc6
leaq 0x78(%rsp), %rdi
callq 0x127fc6
leaq 0x220(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x11af10
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
leaq 0x220(%rsp), %rdi
callq 0x11baac
leaq 0x28(%rsp), %rdi
callq 0x11bd6e
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x119b6e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0xb48(%rsp), %rdi
callq 0x11bdbc
movq %rsp, %rdi
callq 0x11be1e
leaq 0x210(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x119ba4
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x28eca5(%rip), %rax    # 0x3a8850
leaq 0x1e8(%rsp), %rcx
movq %rax, -0x30(%rcx)
movq -0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0x119bd0
movq 0x1e8(%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 0x119bf6
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x11aec8
jmp 0x119cce
movq %rax, %rbx
jmp 0x119cce
movq %rax, %rbx
jmp 0x119cd8
jmp 0x119c46
jmp 0x119c0a
movq %rax, %rbx
jmp 0x119d17
jmp 0x119c14
movq %rax, %rbx
jmp 0x119d33
jmp 0x119c3e
jmp 0x119c46
jmp 0x119c22
movq %rax, %rbx
jmp 0x119d5e
jmp 0x119c2c
movq %rax, %rbx
jmp 0x119d75
jmp 0x119c36
movq %rax, %rbx
jmp 0x119d91
movq %rax, %rbx
jmp 0x119da8
movq %rax, %rbx
jmp 0x119db5
jmp 0x119c7d
jmp 0x119c54
jmp 0x119c7d
movq %rax, %rbx
movq 0xb48(%rsp), %rdi
cmpq %r14, %rdi
je 0x119dc2
movq 0xb58(%rsp), %rsi
incq %rsi
callq 0x116090
jmp 0x119dc2
movq %rax, %rbx
jmp 0x119dc2
movq %rax, %rbx
jmp 0x119dca
movq %rax, %rbx
movq 0xb48(%rsp), %rdi
cmpq %r14, %rdi
je 0x119dd7
movq 0xb58(%rsp), %rsi
incq %rsi
callq 0x116090
jmp 0x119dd7
movq %rax, %rbx
jmp 0x119dd7
movq %rax, %rbx
leaq 0x220(%rsp), %rdi
callq 0x11baac
leaq 0x28(%rsp), %rdi
callq 0x11bd6e
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x119db5
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x116090
jmp 0x119db5
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x119d17
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x119d33
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
jne 0x119d9b
jmp 0x119da8
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x119d5e
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x28(%rsp), %rdi
cmpq %rbp, %rdi
je 0x119d75
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x119d91
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x116090
movq 0x68(%rsp), %rdi
cmpq %r13, %rdi
je 0x119da8
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x116090
leaq 0x220(%rsp), %rdi
callq 0x11a520
leaq 0xb48(%rsp), %rdi
callq 0x11bdbc
movq %rsp, %rdi
callq 0x11be1e
leaq 0x1b8(%rsp), %rdi
callq 0x11beb4
movq %rbx, %rdi
callq 0x1162e0