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

   const T n = T(15);
   std::vector<T> board(static_cast<std::size_t>(n), T(- 1));

   exprtk::rtl::io::package<T> io_package;

   symbol_table_t symbol_table;
   symbol_table.add_constant("n"     , n    );
   symbol_table.add_vector  ("board" , board);
   symbol_table.add_package (io_package);

   compositor_t compositor(symbol_table);

   compositor.load_variables(true);
   compositor.load_vectors  (true);

   compositor.add(
      function_t("display_board")
      .expression
      (
         " for (var row := 0; row < n; row += 1)             "
         " {                                                 "
         "    for (var col := 0; col < n; col += 1)          "
         "    {                                              "
         "       print((board[row] == col) ? ' Q ' : ' . '); "
         "    };                                             "
         "                                                   "
         "    println('');                                   "
         " }                                                 "
      ));

   compositor.add(
      function_t("is_valid")
      .vars("row", "col")
      .expression
      (
         " for (var i := 0; i < row; i += 1)             "
         " {                                             "
         "    if (                                       "
         "         (board[i] == col) or                  "
         "         (abs(board[i] - col) == abs(i - row)) "
         "       )                                       "
         "    {                                          "
         "       return [false];                         "
         "    }                                          "
         " };                                            "
         "                                               "
         " return [true];                                "
      ));

   compositor.add(
      function_t("solve_nqueens")
      .var("row")
      .expression
      (
         " if (row == n)                         "
         " {                                     "
         "     return [true];                    "
         " };                                    "
         "                                       "
         " for (var col := 0; col < n; col += 1) "
         " {                                     "
         "    if (is_valid(row, col))            "
         "    {                                  "
         "       board[row] := col;              "
         "                                       "
         "       if (solve_nqueens(row + 1))     "
         "       {                               "
         "           return [true];              "
         "       }                               "
         "    }                                  "
         " };                                    "
         "                                       "
         " return [false];                       "
      ));

   const std::string sudoku_solver_program =
      " if (solve_nqueens(0))                                  "
      " {                                                      "
      "    println('N-Queens Puzzle Solved!');                 "
      " }                                                      "
      " else                                                   "
      " {                                                      "
      "    println('Error: Failed to solve n-queens puzzle.'); "
      " };                                                     "
      "                                                        "
      " display_board();                                       ";

   expression_t expression;
   expression.register_symbol_table(symbol_table);

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

   expression.value();
}

// Assembly:
pushq %rbx
subq $0x15d0, %rsp           # imm = 0x15D0
movabsq $0x402e000000000000, %rax # imm = 0x402E000000000000
movq %rax, 0x60(%rsp)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
leaq 0xbe8(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x88(%rsp), %rdi
pushq $0xf
popq %rsi
leaq 0x2c0(%rsp), %rcx
callq 0x113912
leaq 0x1f0(%rsp), %rdi
callq 0x113968
leaq 0x10(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x113a0c
leaq 0x131c70(%rip), %rsi    # 0x244fe8
leaq 0xbe8(%rsp), %rdi
leaq 0x2c0(%rsp), %rdx
callq 0x1132d8
leaq 0x10(%rsp), %rdi
leaq 0xbe8(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x113a30
leaq 0xbe8(%rsp), %rdi
callq 0x1115d8
leaq 0x131d6d(%rip), %rsi    # 0x245125
leaq 0xbe8(%rsp), %rdi
leaq 0x2c0(%rsp), %rdx
callq 0x1132d8
leaq 0x10(%rsp), %rdi
leaq 0xbe8(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x113aac
leaq 0xbe8(%rsp), %rdi
callq 0x1115d8
leaq 0x1f0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x116cf8
leaq 0xbe8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x113b16
movw $0x101, 0x15c8(%rsp)    # imm = 0x101
leaq 0x131cf4(%rip), %rsi    # 0x24511d
leaq 0xa0(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x1132d8
leaq 0x2c0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x113c34
leaq 0x131cd4(%rip), %rsi    # 0x24512b
leaq 0x20(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x1132d8
leaq 0x2e0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x111550
leaq 0xbe8(%rsp), %rdi
leaq 0x2c0(%rsp), %rsi
xorl %edx, %edx
callq 0x113c24
leaq 0x20(%rsp), %rdi
callq 0x1115d8
leaq 0x2c0(%rsp), %rdi
callq 0x113c80
leaq 0xa0(%rsp), %rdi
callq 0x1115d8
leaq 0x131e3d(%rip), %rsi    # 0x2452f7
leaq 0xa0(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x1132d8
leaq 0x2c0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x113c34
leaq 0x131e18(%rip), %rsi    # 0x245300
leaq 0x20(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x1132d8
leaq 0x131e06(%rip), %rsi    # 0x245304
leaq 0x40(%rsp), %rdi
leaq 0x1f(%rsp), %rdx
callq 0x1132d8
leaq 0x2c0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x113ca0
movq %rax, %rbx
leaq 0x131dda(%rip), %rsi    # 0x245308
leaq 0x68(%rsp), %rdi
leaq 0x1e(%rsp), %rdx
callq 0x1132d8
leaq 0x20(%rbx), %rdi
leaq 0x68(%rsp), %rsi
callq 0x111550
leaq 0xbe8(%rsp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x113c24
leaq 0x68(%rsp), %rdi
callq 0x1115d8
leaq 0x40(%rsp), %rdi
callq 0x1115d8
leaq 0x20(%rsp), %rdi
callq 0x1115d8
leaq 0x2c0(%rsp), %rdi
callq 0x113c80
leaq 0xa0(%rsp), %rdi
callq 0x1115d8
leaq 0x131fa1(%rip), %rsi    # 0x24553d
leaq 0xa0(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x1132d8
leaq 0x2c0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x113c34
leaq 0x131d36(%rip), %rsi    # 0x245300
leaq 0x20(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x1132d8
leaq 0x300(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x11ed2c
leaq 0x131f59(%rip), %rsi    # 0x24554b
leaq 0x40(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x1132d8
leaq 0x2e0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x111550
leaq 0xbe8(%rsp), %rdi
leaq 0x2c0(%rsp), %rsi
xorl %edx, %edx
callq 0x113c24
leaq 0x40(%rsp), %rdi
callq 0x1115d8
leaq 0x20(%rsp), %rdi
callq 0x1115d8
leaq 0x2c0(%rsp), %rdi
callq 0x113c80
leaq 0xa0(%rsp), %rdi
callq 0x1115d8
leaq 0x1321d2(%rip), %rsi    # 0x245831
leaq 0x20(%rsp), %rdi
leaq 0x2c0(%rsp), %rdx
callq 0x1132d8
leaq 0x40(%rsp), %rdi
callq 0x113ccc
leaq 0x40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x113d2c
leaq 0xa0(%rsp), %rdi
pushq $0x7f
popq %rsi
callq 0x113d88
leaq 0x2c0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x113e98
leaq 0xa0(%rsp), %rdi
callq 0x1144b0
leaq 0x2c0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x1144f8
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
leaq 0x2c0(%rsp), %rdi
callq 0x11497a
leaq 0x40(%rsp), %rdi
callq 0x114ab4
leaq 0x20(%rsp), %rdi
callq 0x1115d8
leaq 0xbe8(%rsp), %rdi
callq 0x114aca
leaq 0x10(%rsp), %rdi
callq 0x114b1e
leaq 0x1f0(%rsp), %rdi
callq 0x114b60
leaq 0x88(%rsp), %rdi
callq 0x114ba2
addq $0x15d0, %rsp           # imm = 0x15D0
popq %rbx
retq
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x1144b0
jmp 0x1137e2
jmp 0x113754
movq %rax, %rbx
jmp 0x1137e2
movq %rax, %rbx
jmp 0x1137ec
jmp 0x113795
jmp 0x113811
jmp 0x113811
jmp 0x113785
jmp 0x11378d
jmp 0x113795
jmp 0x1137f3
jmp 0x1137f3
jmp 0x113811
jmp 0x113785
jmp 0x11378d
jmp 0x113795
movq %rax, %rbx
jmp 0x11381e
movq %rax, %rbx
jmp 0x11382b
movq %rax, %rbx
jmp 0x113838
jmp 0x1137ba
jmp 0x1137ba
jmp 0x1137a5
jmp 0x1137ba
movq %rax, %rbx
leaq 0xbe8(%rsp), %rdi
callq 0x1115d8
jmp 0x113845
movq %rax, %rbx
jmp 0x113845
movq %rax, %rbx
jmp 0x11384f
movq %rax, %rbx
jmp 0x11385c
movq %rax, %rbx
leaq 0x2c0(%rsp), %rdi
callq 0x11497a
leaq 0x40(%rsp), %rdi
callq 0x114ab4
leaq 0x20(%rsp), %rdi
jmp 0x113833
movq %rax, %rbx
jmp 0x113805
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x1115d8
leaq 0x40(%rsp), %rdi
callq 0x1115d8
jmp 0x113814
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x1115d8
leaq 0x2c0(%rsp), %rdi
callq 0x113c80
leaq 0xa0(%rsp), %rdi
callq 0x1115d8
leaq 0xbe8(%rsp), %rdi
callq 0x114aca
leaq 0x10(%rsp), %rdi
callq 0x114b1e
leaq 0x1f0(%rsp), %rdi
callq 0x114b60
leaq 0x88(%rsp), %rdi
callq 0x114ba2
movq %rbx, %rdi
callq 0x111310