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

   symbol_table_t symbol_table;
   symbol_table.add_function("println",ncr_println);

   compositor_t compositor(symbol_table);

   // define function: ncr(n,r)
   compositor.add(
      function_t("ncr")
      .vars("n", "r")
      .expression
      (
        " switch                               "
        " {                                    "
        "    case n <= r : 1;                  "
        "    case r <= 0 : 1;                  "
        "    default     : ncr(n - 1, r - 1) + "
        "                  ncr(n - 1, r    ) ; "
        " }                                    "
      ));

   const std::string ncr_program =
      " var n := 25;                     "
      " for (var r := 1; r < n; r += 1)  "
      " {                                "
      "    println(n, r, ncr(n,r));      "
      " };                               ";

   expression_t expression;
   expression.register_symbol_table(symbol_table);

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

   expression.value();
}

// Assembly:
subq $0x1658, %rsp           # imm = 0x1658
leaq 0x1650(%rsp), %rdi
movl $0x1, %esi
callq 0x11c030
leaq 0x162f(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x114650
movq 0x38(%rsp), %rdx
leaq 0x347d1e(%rip), %rsi    # 0x463565
leaq 0x1630(%rsp), %rdi
callq 0x11b750
jmp 0x11b856
leaq 0x943(%rip), %rdx       # 0x11c1a0
leaq 0x1650(%rsp), %rdi
leaq 0x1630(%rsp), %rsi
callq 0x11c070
jmp 0x11b874
leaq 0x1630(%rsp), %rdi
callq 0x114788
leaq 0x162f(%rsp), %rdi
callq 0x114770
leaq 0xc30(%rsp), %rdi
leaq 0x1650(%rsp), %rsi
callq 0x11c210
jmp 0x11b8a5
leaq 0xb7f(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x114650
movq 0x30(%rsp), %rdx
leaq 0x347caa(%rip), %rsi    # 0x46356d
leaq 0xb80(%rsp), %rdi
callq 0x11b750
jmp 0x11b8d2
leaq 0xba0(%rsp), %rdi
leaq 0xb80(%rsp), %rsi
callq 0x11c400
jmp 0x11b8e9
leaq 0xb57(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x114650
movq 0x28(%rsp), %rdx
leaq 0x347b29(%rip), %rsi    # 0x463430
leaq 0xb58(%rsp), %rdi
callq 0x11b750
jmp 0x11b916
leaq 0xb2f(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x114650
movq 0x20(%rsp), %rdx
leaq 0x347acc(%rip), %rsi    # 0x463400
leaq 0xb30(%rsp), %rdi
callq 0x11b750
jmp 0x11b943
leaq 0xba0(%rsp), %rdi
leaq 0xb58(%rsp), %rsi
leaq 0xb30(%rsp), %rdx
callq 0x11c480
movq %rax, 0x18(%rsp)
jmp 0x11b967
leaq 0xb07(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x114650
movq 0x10(%rsp), %rdx
leaq 0x347bec(%rip), %rsi    # 0x463571
leaq 0xb08(%rsp), %rdi
callq 0x11b750
jmp 0x11b994
movq 0x18(%rsp), %rdi
leaq 0xb08(%rsp), %rsi
callq 0x11c4d0
movq %rax, 0x8(%rsp)
jmp 0x11b9ad
movq 0x8(%rsp), %rsi
leaq 0xc30(%rsp), %rdi
xorl %edx, %edx
callq 0x11c3b0
jmp 0x11b9c3
leaq 0xb08(%rsp), %rdi
callq 0x114788
leaq 0xb07(%rsp), %rdi
callq 0x114770
leaq 0xb30(%rsp), %rdi
callq 0x114788
leaq 0xb2f(%rsp), %rdi
callq 0x114770
leaq 0xb58(%rsp), %rdi
callq 0x114788
leaq 0xb57(%rsp), %rdi
callq 0x114770
leaq 0xba0(%rsp), %rdi
callq 0x11c500
leaq 0xb80(%rsp), %rdi
callq 0x114788
leaq 0xb7f(%rsp), %rdi
callq 0x114770
leaq 0xadf(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x114650
movq (%rsp), %rdx
leaq 0x347c28(%rip), %rsi    # 0x46367c
leaq 0xae0(%rsp), %rdi
callq 0x11b750
jmp 0x11ba63
leaq 0xadf(%rsp), %rdi
callq 0x114770
leaq 0xab8(%rsp), %rdi
callq 0x11c540
jmp 0x11ba7f
leaq 0xab8(%rsp), %rdi
leaq 0x1650(%rsp), %rsi
callq 0x11c5f0
jmp 0x11ba96
leaq 0x40(%rsp), %rdi
movl $0x7f, %esi
callq 0x11c6a0
jmp 0x11baa7
leaq 0x190(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x11c7d0
jmp 0x11babb
leaq 0x40(%rsp), %rdi
callq 0x11d000
leaq 0x190(%rsp), %rdi
leaq 0xae0(%rsp), %rsi
leaq 0xab8(%rsp), %rdx
callq 0x11d070
jmp 0x11bae4
leaq 0xab8(%rsp), %rdi
callq 0x11d900
jmp 0x11baf3
leaq 0x190(%rsp), %rdi
callq 0x11d920
leaq 0xab8(%rsp), %rdi
callq 0x11db20
leaq 0xae0(%rsp), %rdi
callq 0x114788
leaq 0xc30(%rsp), %rdi
callq 0x11db60
leaq 0x1650(%rsp), %rdi
callq 0x11dbf0
addq $0x1658, %rsp           # imm = 0x1658
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
jmp 0x11bb73
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
leaq 0x1630(%rsp), %rdi
callq 0x114788
leaq 0x162f(%rsp), %rdi
callq 0x114770
jmp 0x11bd73
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
jmp 0x11bd73
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
jmp 0x11bca7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
jmp 0x11bc9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
jmp 0x11bc80
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
jmp 0x11bc66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
jmp 0x11bc59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
jmp 0x11bc4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
leaq 0xb08(%rsp), %rdi
callq 0x114788
leaq 0xb07(%rsp), %rdi
callq 0x114770
leaq 0xb30(%rsp), %rdi
callq 0x114788
leaq 0xb2f(%rsp), %rdi
callq 0x114770
leaq 0xb58(%rsp), %rdi
callq 0x114788
leaq 0xb57(%rsp), %rdi
callq 0x114770
leaq 0xba0(%rsp), %rdi
callq 0x11c500
leaq 0xb80(%rsp), %rdi
callq 0x114788
leaq 0xb7f(%rsp), %rdi
callq 0x114770
jmp 0x11bd66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
leaq 0xadf(%rsp), %rdi
callq 0x114770
jmp 0x11bd66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
jmp 0x11bd59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
jmp 0x11bd4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x11d000
jmp 0x11bd4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1620(%rsp)
movl %eax, 0x161c(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x11d920
leaq 0xab8(%rsp), %rdi
callq 0x11db20
leaq 0xae0(%rsp), %rdi
callq 0x114788
leaq 0xc30(%rsp), %rdi
callq 0x11db60
leaq 0x1650(%rsp), %rdi
callq 0x11dbf0
movq 0x1620(%rsp), %rdi
callq 0x114440
nopl (%rax)