// File: /workspace/github_cpp_makefile_star2_O1/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 0x1be68a(%rip), %rsi    # 0x2dab90
leaq 0x1510(%rsp), %rdi
movl $0xe0, %edx
callq 0x119060
leaq 0x210(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1b93b2(%rip), %rsi    # 0x2d58dd
leaq 0x1b93b1(%rip), %rdx    # 0x2d58e3
leaq 0x200(%rsp), %rdi
callq 0x11cfea
leaq 0x198(%rsp), %rdi
leaq 0x200(%rsp), %rsi
callq 0x11d07a
movq 0x200(%rsp), %rdi
cmpq %r14, %rdi
je 0x11c571
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x119090
movq %rsp, %rdi
movl $0x1, %esi
callq 0x11d182
leaq 0x200(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1b9354(%rip), %rsi    # 0x2d58e4
leaq 0x1b9357(%rip), %rdx    # 0x2d58ee
callq 0x11cfea
movq (%rsp), %rax
testq %rax, %rax
je 0x11c786
movq 0x8(%rax), %rbx
testq %rbx, %rbx
je 0x11c786
movq 0x208(%rsp), %rax
testq %rax, %rax
je 0x11c786
movq 0x200(%rsp), %rcx
movb (%rcx), %dl
andb $-0x21, %dl
addb $-0x41, %dl
cmpb $0x19, %dl
ja 0x11c786
cmpq $0x1, %rax
je 0x11c631
leaq -0x1(%rax), %rsi
movl $0x1, %edi
xorl %edx, %edx
movb (%rcx,%rdi), %r8b
cmpb $0x5f, %r8b
je 0x11c621
leal -0x30(%r8), %r9d
cmpb $0xa, %r9b
jb 0x11c621
movl %r8d, %r9d
andb $-0x21, %r9b
addb $-0x41, %r9b
cmpb $0x1a, %r9b
jb 0x11c621
cmpq %rsi, %rdi
jae 0x11c62c
cmpb $0x2e, %r8b
jne 0x11c62c
incq %rdi
cmpq %rax, %rdi
setae %dl
jne 0x11c5f1
testb $0x1, %dl
je 0x11c652
leaq 0x1f0(%rbx), %rdi
leaq 0x200(%rsp), %rsi
callq 0x11fbfc
addq $0x1f8, %rbx            # imm = 0x1F8
cmpq %rax, %rbx
sete %dl
testb $0x1, %dl
je 0x11c786
movq (%rsp), %rax
testq %rax, %rax
je 0x11c75c
movq 0x8(%rax), %rbx
testq %rbx, %rbx
je 0x11c75c
cmpq $0x0, 0x208(%rsp)
je 0x11c69d
leaq 0x200(%rsp), %rsi
movq %rbx, %rdi
callq 0x11fc86
addq $0x8, %rbx
cmpq %rax, %rbx
jne 0x11c786
cmpq $0x0, 0x208(%rsp)
je 0x11c6d4
movq (%rsp), %rax
movq 0x8(%rax), %rbx
leaq 0x188(%rbx), %rdi
leaq 0x200(%rsp), %rsi
callq 0x11fec6
addq $0x190, %rbx            # imm = 0x190
cmpq %rax, %rbx
jne 0x11c786
cmpq $0x0, 0x208(%rsp)
je 0x11c707
movq (%rsp), %rax
movq 0x8(%rax), %rbx
leaq 0x150(%rbx), %rdi
leaq 0x200(%rsp), %rsi
callq 0x120106
addq $0x158, %rbx            # imm = 0x158
cmpq %rax, %rbx
jne 0x11c786
cmpq $0x0, 0x208(%rsp)
je 0x11c734
movq (%rsp), %rax
movq 0x8(%rax), %rbx
leaq 0x38(%rbx), %rdi
leaq 0x200(%rsp), %rsi
callq 0x120346
addq $0x40, %rbx
cmpq %rax, %rbx
jne 0x11c786
movq (%rsp), %rax
movq 0x8(%rax), %rbx
leaq 0x1f0(%rbx), %rdi
leaq 0x200(%rsp), %rsi
callq 0x11fbfc
addq $0x1f8, %rbx            # imm = 0x1F8
cmpq %rax, %rbx
jne 0x11c786
movq (%rsp), %rax
movl $0x150, %edi            # imm = 0x150
addq 0x8(%rax), %rdi
leaq 0x200(%rsp), %rsi
leaq 0x1510(%rsp), %rdx
movl $0x1c, %ecx
xorl %r8d, %r8d
callq 0x120586
movq 0x200(%rsp), %rdi
cmpq %r14, %rdi
je 0x11c7a3
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x200(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1b913a(%rip), %rsi    # 0x2d58ef
leaq 0x1b913a(%rip), %rdx    # 0x2d58f6
callq 0x11cfea
movq %rsp, %rdi
leaq 0x200(%rsp), %rsi
leaq 0x198(%rsp), %rdx
callq 0x11d1ca
movq 0x200(%rsp), %rdi
cmpq %r14, %rdi
je 0x11c7f6
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x200(%rsp), %rdi
movq %rsp, %rbx
movq %rbx, %rsi
callq 0x11d354
leaq 0xbe8(%rsp), %rdi
callq 0x11d4dc
leaq 0x58(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1b90d1(%rip), %rsi    # 0x2d58f7
leaq 0x1b90d3(%rip), %rdx    # 0x2d5900
leaq 0x48(%rsp), %rdi
callq 0x11cfea
leaq 0xbe8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x119520
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1b8fdc(%rip), %rsi    # 0x2d5835
leaq 0x1b8fd6(%rip), %rdx    # 0x2d5836
leaq 0x8(%rsp), %rdi
callq 0x11cfea
leaq 0xc28(%rsp), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x12c798
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1b9072(%rip), %rsi    # 0x2d5901
leaq 0x1b90a7(%rip), %rdx    # 0x2d593d
leaq 0x28(%rsp), %rdi
callq 0x11cfea
leaq 0xc08(%rsp), %r12
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x119520
leaq 0xb30(%rsp), %rdi
leaq 0xbe8(%rsp), %rsi
callq 0x1239a0
leaq 0xb38(%rsp), %rbp
cmpq %rax, %rbp
jne 0x11c989
leaq 0x200(%rsp), %rdi
leaq 0xbe8(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x1226fe
testb %al, %al
je 0x11c989
leaq 0xbe8(%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 0xb60(%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 0x1235d0
movq (%rax), %r12
leaq 0xbe8(%rsp), %rsi
leaq 0xb30(%rsp), %rdi
callq 0x123924
movq %r12, %rdi
movq %rax, %rsi
callq 0x12364c
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x11c9a5
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11c9c1
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x11c9d8
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x119090
movq %r15, %rdi
callq 0x12ca32
leaq 0xc18(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x11ca01
movq 0xc18(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0xbf8(%rsp), %r13
movq -0x10(%r13), %rdi
cmpq %r13, %rdi
je 0x11ca22
movq 0xbf8(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0xbe8(%rsp), %rdi
callq 0x11d4dc
leaq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
movq %rax, (%rdi)
leaq 0x1b8efb(%rip), %rsi    # 0x2d593e
leaq 0x1b8efa(%rip), %rdx    # 0x2d5944
callq 0x11cfea
leaq 0xbe8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x119520
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
leaq 0x1b8d33(%rip), %rsi    # 0x2d57a8
leaq 0x1b8d2d(%rip), %rdx    # 0x2d57a9
callq 0x11cfea
leaq 0xc28(%rsp), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x12c798
leaq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
movq %rax, (%rdi)
leaq 0x1b8e9b(%rip), %rsi    # 0x2d5945
leaq 0x1b9107(%rip), %rdx    # 0x2d5bb8
callq 0x11cfea
leaq 0xc08(%rsp), %r12
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x119520
leaq 0xbe8(%rsp), %rsi
leaq 0xb30(%rsp), %rdi
callq 0x1239a0
cmpq %rax, %rbp
jne 0x11cb97
leaq 0x200(%rsp), %rdi
leaq 0xbe8(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x1226fe
testb %al, %al
je 0x11cb97
leaq 0xbe8(%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 0xb60(%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 0x1235d0
movq (%rax), %r12
leaq 0xbe8(%rsp), %rsi
leaq 0xb30(%rsp), %rdi
callq 0x123924
movq %r12, %rdi
movq %rax, %rsi
callq 0x12364c
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x11cbb3
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11cbcf
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x11cbeb
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x119090
movq %r15, %rdi
callq 0x12ca32
movq 0xc08(%rsp), %rdi
cmpq %r14, %rdi
je 0x11cc10
movq 0xc18(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0xbe8(%rsp), %rdi
cmpq %r13, %rdi
je 0x11cc2d
movq 0xbf8(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
movq %rax, (%rdi)
leaq 0x1b8f78(%rip), %rsi    # 0x2d5bb9
leaq 0x1b9411(%rip), %rdx    # 0x2d6059
callq 0x11cfea
leaq 0x28(%rsp), %rdi
callq 0x11d5a8
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rax
subq %rcx, %rax
je 0x11ccb2
sarq $0x3, %rax
cmpq $0x1, %rax
movq %rax, %rsi
adcq $0x0, %rsi
cmpq %rbx, %rcx
je 0x11ccbf
movq (%rsp), %rdx
cmpq (%rcx), %rdx
je 0x11ccbf
addq $0x8, %rcx
movl $0x1, %edi
subq %rsi, %rdi
xorl %esi, %esi
cmpq %rsi, %rdi
je 0x11ccb2
decq %rsi
cmpq %rbx, %rcx
je 0x11ccaa
leaq 0x8(%rcx), %r8
cmpq (%rcx), %rdx
movq %r8, %rcx
jne 0x11cc91
negq %rsi
cmpq %rax, %rsi
jb 0x11ccbf
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
callq 0x12cca4
leaq 0x48(%rsp), %rdi
movl $0x7f, %esi
callq 0x11d642
leaq 0xbe8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x11d742
leaq 0x148(%rsp), %rdi
callq 0x12ce8a
leaq 0x118(%rsp), %rdi
callq 0x12ce8a
leaq 0xe8(%rsp), %rdi
callq 0x12ce8a
leaq 0xb8(%rsp), %rdi
callq 0x12ce8a
leaq 0x88(%rsp), %rdi
callq 0x12ce8a
leaq 0x58(%rsp), %rdi
callq 0x12ce8a
leaq 0xbe8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x11df66
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
leaq 0xbe8(%rsp), %rdi
callq 0x11e938
leaq 0x28(%rsp), %rdi
callq 0x11ebfa
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11cd84
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x200(%rsp), %rdi
callq 0x11ec48
movq %rsp, %rdi
callq 0x11ecaa
leaq 0x1f0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11cdba
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x2c1dcf(%rip), %rax    # 0x3deb90
leaq 0x1c8(%rsp), %rcx
movq %rax, -0x30(%rcx)
movq -0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0x11cde6
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x119090
addq $0x15f8, %rsp           # imm = 0x15F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x11ce5e
jmp 0x11ce0e
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x11df1e
jmp 0x11ceda
movq %rax, %rbx
jmp 0x11ceda
movq %rax, %rbx
jmp 0x11cee4
jmp 0x11ce54
jmp 0x11ce22
movq %rax, %rbx
jmp 0x11cf28
jmp 0x11ce2c
movq %rax, %rbx
jmp 0x11cf44
jmp 0x11ce4c
jmp 0x11ce54
jmp 0x11ce3a
movq %rax, %rbx
jmp 0x11cf74
jmp 0x11ce44
movq %rax, %rbx
jmp 0x11cf90
movq %rax, %rbx
jmp 0x11cfa7
movq %rax, %rbx
jmp 0x11cfb4
jmp 0x11ce89
movq %rax, %rbx
movq 0x200(%rsp), %rdi
cmpq %r14, %rdi
je 0x11cfc1
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x119090
jmp 0x11cfc1
jmp 0x11ce89
movq %rax, %rbx
jmp 0x11cfc1
movq %rax, %rbx
jmp 0x11cfc9
movq %rax, %rbx
movq 0x200(%rsp), %rdi
cmpq %r14, %rdi
je 0x11cfd6
movq 0x210(%rsp), %rsi
incq %rsi
callq 0x119090
jmp 0x11cfd6
movq %rax, %rbx
jmp 0x11cfd6
movq %rax, %rbx
leaq 0xbe8(%rsp), %rdi
callq 0x11e938
leaq 0x28(%rsp), %rdi
callq 0x11ebfa
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11cfb4
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x119090
jmp 0x11cfb4
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x11cf28
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11cf44
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
jne 0x11cf9a
jmp 0x11cfa7
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x11cf74
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x11cf90
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x11cfa7
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0xbe8(%rsp), %rdi
callq 0x11d568
leaq 0x200(%rsp), %rdi
callq 0x11ec48
movq %rsp, %rdi
callq 0x11ecaa
leaq 0x198(%rsp), %rdi
callq 0x11ed40
movq %rbx, %rdi
callq 0x1192e0