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

   symbol_table_t symbol_table;
   symbol_table.add_package(io_package);
   symbol_table.add_function("print_coeff",
                             [](T t)
                             {
                                printf("%6d", static_cast<unsigned int>(t));
                                return T(0);
                             });

   compositor_t compositor(symbol_table);

   compositor.add(
      function_t("n_choose_k")
      .vars("n","k")
      .expression
      (
        " switch                                      "
        " {                                           "
        "    case n <= k : 1;                         "
        "    case k <= 0 : 1;                         "
        "    default     : n_choose_k(n - 1, k - 1) + "
        "                  n_choose_k(n - 1, k    ) ; "
        " }                                           "
      ));

   const std::string pascals_triangle_program =
      " const var rows := 20;                            "
      "                                                  "
      " for (var n := 0; n < rows; n += 1)               "
      " {                                                "
      "    for (var s := 0; s <= (rows - n) - 2; s += 1) "
      "    {                                             "
      "       print('   ');                              "
      "    };                                            "
      "                                                  "
      "    for (var k := 0; k <= n; k += 1)              "
      "    {                                             "
      "       print_coeff(n_choose_k(n,k));              "
      "    };                                            "
      "                                                  "
      "    println();                                    "
      " }                                                ";

   expression_t expression;
   expression.register_symbol_table(symbol_table);

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

   expression.value();
}

// Assembly:
pushq %rbx
subq $0x15a0, %rsp           # imm = 0x15A0
leaq 0x1c0(%rsp), %rdi
callq 0x1136c2
leaq 0x8(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x113766
leaq 0x1c0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x115782
leaq 0x131dcf(%rip), %rsi    # 0x24511d
leaq 0xbb8(%rsp), %rdi
leaq 0x290(%rsp), %rdx
callq 0x1132d8
leaq 0x36d4(%rip), %rdx      # 0x116a3e
leaq 0x8(%rsp), %rdi
leaq 0xbb8(%rsp), %rsi
callq 0x11378a
leaq 0xbb8(%rsp), %rdi
callq 0x1115d8
leaq 0xbb8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x11383e
leaq 0x131d87(%rip), %rsi    # 0x245129
leaq 0x70(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x1132d8
leaq 0x290(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x11395c
leaq 0x131c1e(%rip), %rsi    # 0x244fe8
leaq 0x30(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x1132d8
leaq 0x131d52(%rip), %rsi    # 0x245132
leaq 0x10(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0x1132d8
leaq 0x290(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x1139a8
movq %rax, %rbx
leaq 0x131d24(%rip), %rsi    # 0x245134
leaq 0x50(%rsp), %rdi
leaq 0x4(%rsp), %rdx
callq 0x1132d8
leaq 0x20(%rbx), %rdi
leaq 0x50(%rsp), %rsi
callq 0x111550
leaq 0xbb8(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x11394c
leaq 0x50(%rsp), %rdi
callq 0x1115d8
leaq 0x10(%rsp), %rdi
callq 0x1115d8
leaq 0x30(%rsp), %rdi
callq 0x1115d8
leaq 0x290(%rsp), %rdi
callq 0x1139d4
leaq 0x70(%rsp), %rdi
callq 0x1115d8
leaq 0x131df5(%rip), %rsi    # 0x245270
leaq 0x30(%rsp), %rdi
leaq 0x290(%rsp), %rdx
callq 0x1132d8
leaq 0x10(%rsp), %rdi
callq 0x1139f4
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x113a54
leaq 0x70(%rsp), %rdi
pushq $0x7f
popq %rsi
callq 0x113ab0
leaq 0x290(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x113bc0
leaq 0x70(%rsp), %rdi
callq 0x1141d8
leaq 0x290(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x114220
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
leaq 0x290(%rsp), %rdi
callq 0x1146a2
leaq 0x10(%rsp), %rdi
callq 0x1147dc
leaq 0x30(%rsp), %rdi
callq 0x1115d8
leaq 0xbb8(%rsp), %rdi
callq 0x1147f2
leaq 0x8(%rsp), %rdi
callq 0x114846
leaq 0x1c0(%rsp), %rdi
callq 0x114888
addq $0x15a0, %rsp           # imm = 0x15A0
popq %rbx
retq
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x1141d8
jmp 0x1135ab
jmp 0x113554
movq %rax, %rbx
jmp 0x1135ab
movq %rax, %rbx
jmp 0x1135b5
jmp 0x113576
jmp 0x113562
movq %rax, %rbx
jmp 0x1135c9
movq %rax, %rbx
jmp 0x1135d3
movq %rax, %rbx
jmp 0x1135dd
movq %rax, %rbx
jmp 0x1135ea
movq %rax, %rbx
jmp 0x1135f4
jmp 0x113591
movq %rax, %rbx
leaq 0xbb8(%rsp), %rdi
callq 0x1115d8
jmp 0x113601
jmp 0x113591
movq %rax, %rbx
jmp 0x113601
movq %rax, %rbx
jmp 0x11360b
movq %rax, %rbx
leaq 0x290(%rsp), %rdi
callq 0x1146a2
leaq 0x10(%rsp), %rdi
callq 0x1147dc
leaq 0x30(%rsp), %rdi
jmp 0x1135ef
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x1115d8
leaq 0x10(%rsp), %rdi
callq 0x1115d8
leaq 0x30(%rsp), %rdi
callq 0x1115d8
leaq 0x290(%rsp), %rdi
callq 0x1139d4
leaq 0x70(%rsp), %rdi
callq 0x1115d8
leaq 0xbb8(%rsp), %rdi
callq 0x1147f2
leaq 0x8(%rsp), %rdi
callq 0x114846
leaq 0x1c0(%rsp), %rdi
callq 0x114888
movq %rbx, %rdi
callq 0x111310