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

   exprtk::rtl::io::print<T> print("%3.0f ");

   symbol_table_t symbol_table;
   symbol_table.add_function("print",print);

   compositor_t compositor(symbol_table);

   // define function: collatz_trace(x)
   compositor.add(
      function_t("collatz_trace")
      .var("x")
      .expression
      (
         " while (x > 1)                           "
         " {                                       "
         "    x := (x % 2 == 0) ? x / 2 : 3x + 1;  "
         "    print(x);                            "
         " }                                       "
      ));

   const std::string collatz_program =
      " x := 0;              "
      " repeat               "
      "    print(x += 1);    "
      "    collatz_trace(x); "
      "    print('\n\n');    "
      " until (x > 100);     "
      " println;             ";

   expression_t expression;
   expression.register_symbol_table(symbol_table);

   parser_t parser;
   parser.enable_unknown_symbol_resolver();
   parser.compile(collatz_program,expression);

   expression.value();
}

// Assembly:
pushq %rbx
subq $0x1520, %rsp           # imm = 0x1520
leaq 0x130dfb(%rip), %rsi    # 0x24411d
leaq 0xb38(%rsp), %rdi
leaq 0x210(%rsp), %rdx
callq 0x1132d8
leaq 0x58(%rsp), %rdi
leaq 0xb38(%rsp), %rsi
callq 0x1136f6
leaq 0xb38(%rsp), %rdi
callq 0x1115d8
leaq 0x10(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x113788
leaq 0x130dba(%rip), %rsi    # 0x244124
leaq 0xb38(%rsp), %rdi
leaq 0x210(%rsp), %rdx
callq 0x1132d8
leaq 0x10(%rsp), %rdi
leaq 0xb38(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x1137ac
leaq 0xb38(%rsp), %rdi
callq 0x1115d8
leaq 0xb38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x113874
leaq 0x130d6e(%rip), %rsi    # 0x24412a
leaq 0xc0(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x1132d8
leaq 0x210(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x113992
leaq 0x130c8b(%rip), %rsi    # 0x244075
leaq 0x38(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x1132d8
leaq 0x250(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x11e63a
leaq 0x130d26(%rip), %rsi    # 0x244138
leaq 0x18(%rsp), %rdi
leaq 0xd(%rsp), %rdx
callq 0x1132d8
leaq 0x230(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x111550
leaq 0xb38(%rsp), %rdi
leaq 0x210(%rsp), %rsi
xorl %edx, %edx
callq 0x113982
leaq 0x18(%rsp), %rdi
callq 0x1115d8
leaq 0x38(%rsp), %rdi
callq 0x1115d8
leaq 0x210(%rsp), %rdi
callq 0x1139de
leaq 0xc0(%rsp), %rdi
callq 0x1115d8
leaq 0x130d87(%rip), %rsi    # 0x244206
leaq 0x38(%rsp), %rdi
leaq 0x210(%rsp), %rdx
callq 0x1132d8
leaq 0x18(%rsp), %rdi
callq 0x1139fe
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x113a5e
leaq 0xc0(%rsp), %rdi
pushq $0x7f
popq %rsi
callq 0x113aba
leaq 0x210(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x113bca
leaq 0xc0(%rsp), %rdi
callq 0x1141e2
leaq 0x5f0(%rsp), %rax
movb $0x1, -0x18(%rax)
movq %rax, -0x8(%rax)
leaq 0x210(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x11422a
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
leaq 0x210(%rsp), %rdi
callq 0x1146ac
leaq 0x18(%rsp), %rdi
callq 0x1147e6
leaq 0x38(%rsp), %rdi
callq 0x1115d8
leaq 0xb38(%rsp), %rdi
callq 0x1147fc
leaq 0x10(%rsp), %rdi
callq 0x114850
leaq 0x58(%rsp), %rdi
callq 0x114892
addq $0x1520, %rsp           # imm = 0x1520
popq %rbx
retq
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x1141e2
jmp 0x1135ea
jmp 0x113571
movq %rax, %rbx
jmp 0x1135ea
movq %rax, %rbx
jmp 0x1135f4
jmp 0x113597
jmp 0x11357f
movq %rax, %rbx
jmp 0x113608
movq %rax, %rbx
jmp 0x113612
movq %rax, %rbx
jmp 0x11361f
movq %rax, %rbx
jmp 0x11362c
jmp 0x1135b6
movq %rax, %rbx
leaq 0xb38(%rsp), %rdi
callq 0x1115d8
jmp 0x113639
movq %rax, %rbx
jmp 0x113639
movq %rax, %rbx
jmp 0x113643
movq %rax, %rbx
leaq 0xb38(%rsp), %rdi
callq 0x1115d8
jmp 0x11364d
movq %rax, %rbx
jmp 0x11364d
movq %rax, %rbx
leaq 0x210(%rsp), %rdi
callq 0x1146ac
leaq 0x18(%rsp), %rdi
callq 0x1147e6
leaq 0x38(%rsp), %rdi
jmp 0x113627
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x1115d8
leaq 0x38(%rsp), %rdi
callq 0x1115d8
leaq 0x210(%rsp), %rdi
callq 0x1139de
leaq 0xc0(%rsp), %rdi
callq 0x1115d8
leaq 0xb38(%rsp), %rdi
callq 0x1147fc
leaq 0x10(%rsp), %rdi
callq 0x114850
leaq 0x58(%rsp), %rdi
callq 0x114892
movq %rbx, %rdi
callq 0x111310