// File: ArashPartow[P]exprtk-extras/exprtk_vector_resize_inline_example.cpp
// Function: void vector_inline_resize_example<double>()
void vector_inline_resize_example()
{
   typedef exprtk::symbol_table<T> symbol_table_t;
   typedef exprtk::expression<T>   expression_t;
   typedef exprtk::parser<T>       parser_t;

   const std::string inline_resize_expression =
      " var vec_original_size := v[];                                     "
      "                                                                   "
      " for (var i := 1; i <= 2 * vec_original_size; i += 1)              "
      " {                                                                 "
      "    if (resize(v,i) == true and v[] == i and sum(2v) == (i^2 + i)) "
      "    {                                                              "
      "       println('Success: set size: ', i ,'  v[] = ', v[]);         "
      "    }                                                              "
      "    else                                                           "
      "    {                                                              "
      "       println('Error: Failed to resize vector v to size: ', i);   "
      "    }                                                              "
      " };                                                                ";

   std::vector<T> v0 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
   std::vector<T> v1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };

   exprtk::vector_view<T> vv = exprtk::make_vector_view(v0, v0.size());


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

   my_vv_size_handler_t<T> vv_size_handler;
   vv_size_handler.register_vector_view(vv);

   symbol_table_t symbol_table;
   symbol_table.add_vector  ("v", vv);
   symbol_table.add_function("resize", vv_size_handler);
   symbol_table.add_package (io_package);

   expression_t expression;
   expression.register_symbol_table(symbol_table);

   parser_t parser;

   if (!parser.compile(inline_resize_expression, expression))
   {
      printf("Error: %s\tExpression: %s\n",
             parser.error().c_str(),
             inline_resize_expression.c_str());
      return;
   }

   vv.rebase(v0.data());
   vv_size_handler.register_vector_view(vv);
   expression.value();

   vv.rebase(v1.data());
   vv_size_handler.register_vector_view(vv);
   expression.value();
}

// Assembly:
subq $0xe68, %rsp            # imm = 0xE68
leaq 0xe47(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x111650
movq 0x40(%rsp), %rdx
leaq 0x334d00(%rip), %rsi    # 0x44d545
leaq 0xe48(%rsp), %rdi
callq 0x118760
jmp 0x118854
leaq 0xe47(%rsp), %rdi
callq 0x111780
movabsq $0x402e000000000000, %rax # imm = 0x402E000000000000
movq %rax, 0xe00(%rsp)
movups 0x339cb6(%rip), %xmm0   # 0x452530
movaps %xmm0, 0xdf0(%rsp)
movups 0x339c97(%rip), %xmm0   # 0x452520
movaps %xmm0, 0xde0(%rsp)
movups 0x339c78(%rip), %xmm0   # 0x452510
movaps %xmm0, 0xdd0(%rsp)
movups 0x339c59(%rip), %xmm0   # 0x452500
movaps %xmm0, 0xdc0(%rsp)
movups 0x339c3a(%rip), %xmm0   # 0x4524f0
movaps %xmm0, 0xdb0(%rsp)
movups 0x339c1b(%rip), %xmm0   # 0x4524e0
movaps %xmm0, 0xda0(%rsp)
movups 0x339bfc(%rip), %xmm0   # 0x4524d0
movaps %xmm0, 0xd90(%rsp)
leaq 0xd90(%rsp), %rax
movq %rax, 0xe08(%rsp)
movq $0xf, 0xe10(%rsp)
leaq 0xd8f(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x119280
movq 0x38(%rsp), %rcx
movq 0xe08(%rsp), %rsi
movq 0xe10(%rsp), %rdx
leaq 0xe18(%rsp), %rdi
callq 0x119290
jmp 0x11892e
leaq 0xd8f(%rsp), %rdi
callq 0x119320
movabsq $0x402e000000000000, %rax # imm = 0x402E000000000000
movq %rax, 0xd50(%rsp)
movups 0x339c54(%rip), %xmm0   # 0x4525a8
movaps %xmm0, 0xd40(%rsp)
movups 0x339c35(%rip), %xmm0   # 0x452598
movaps %xmm0, 0xd30(%rsp)
movups 0x339c16(%rip), %xmm0   # 0x452588
movaps %xmm0, 0xd20(%rsp)
movups 0x339bf7(%rip), %xmm0   # 0x452578
movaps %xmm0, 0xd10(%rsp)
movups 0x339bd8(%rip), %xmm0   # 0x452568
movaps %xmm0, 0xd00(%rsp)
movups 0x339bb9(%rip), %xmm0   # 0x452558
movaps %xmm0, 0xcf0(%rsp)
movups 0x339b9a(%rip), %xmm0   # 0x452548
movaps %xmm0, 0xce0(%rsp)
leaq 0xce0(%rsp), %rax
movq %rax, 0xd60(%rsp)
movq $0xf, 0xd68(%rsp)
leaq 0xcdf(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x119280
movq 0x30(%rsp), %rcx
movq 0xd60(%rsp), %rsi
movq 0xd68(%rsp), %rdx
leaq 0xd70(%rsp), %rdi
callq 0x119290
jmp 0x118a08
leaq 0xcdf(%rsp), %rdi
callq 0x119320
leaq 0xe18(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x119390
movq 0x28(%rsp), %rsi
movq %rax, %rdx
xorl %eax, %eax
movl %eax, %ecx
leaq 0xca8(%rsp), %rdi
callq 0x119330
jmp 0x118a42
leaq 0xbd8(%rsp), %rdi
callq 0x1193b0
jmp 0x118a51
leaq 0xb60(%rsp), %rdi
callq 0x119500
jmp 0x118a60
leaq 0xb60(%rsp), %rdi
leaq 0xca8(%rsp), %rsi
callq 0x1195c0
jmp 0x118a77
leaq 0xb58(%rsp), %rdi
movl $0x1, %esi
callq 0x119610
jmp 0x118a8b
leaq 0xb37(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x111650
movq 0x20(%rsp), %rdx
leaq 0x334e04(%rip), %rsi    # 0x44d8ad
leaq 0xb38(%rsp), %rdi
callq 0x118760
jmp 0x118ab8
leaq 0xb58(%rsp), %rdi
leaq 0xb38(%rsp), %rsi
leaq 0xca8(%rsp), %rdx
callq 0x119650
jmp 0x118ad7
leaq 0xb38(%rsp), %rdi
callq 0x111798
leaq 0xb37(%rsp), %rdi
callq 0x111780
leaq 0xb0f(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x111650
movq 0x18(%rsp), %rdx
leaq 0x334da0(%rip), %rsi    # 0x44d8af
leaq 0xb10(%rsp), %rdi
callq 0x118760
jmp 0x118b1e
leaq 0xb58(%rsp), %rdi
leaq 0xb10(%rsp), %rsi
leaq 0xb60(%rsp), %rdx
callq 0x119710
jmp 0x118b3d
leaq 0xb10(%rsp), %rdi
callq 0x111798
leaq 0xb0f(%rsp), %rdi
callq 0x111780
leaq 0xb58(%rsp), %rdi
leaq 0xbd8(%rsp), %rsi
callq 0x119910
jmp 0x118b6e
leaq 0xae8(%rsp), %rdi
callq 0x119940
jmp 0x118b7d
leaq 0xae8(%rsp), %rdi
leaq 0xb58(%rsp), %rsi
callq 0x1199f0
jmp 0x118b94
leaq 0x70(%rsp), %rdi
movl $0x7f, %esi
callq 0x119aa0
jmp 0x118ba5
leaq 0x1c0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x119bd0
jmp 0x118bb9
leaq 0x70(%rsp), %rdi
callq 0x11a400
leaq 0x1c0(%rsp), %rdi
leaq 0xe48(%rsp), %rsi
leaq 0xae8(%rsp), %rdx
callq 0x11a470
movb %al, 0x17(%rsp)
jmp 0x118be6
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x118e4c
jmp 0x118bf4
leaq 0x50(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0x11ad00
jmp 0x118c08
leaq 0x50(%rsp), %rdi
callq 0x1110f0
movq %rax, 0x8(%rsp)
leaq 0xe48(%rsp), %rdi
callq 0x1110f0
movq 0x8(%rsp), %rsi
movq %rax, %rdx
leaq 0x334c83(%rip), %rdi    # 0x44d8b6
xorl %eax, %eax
callq 0x111080
jmp 0x118c3c
leaq 0x50(%rsp), %rdi
callq 0x111798
movl $0x1, 0x4c(%rsp)
jmp 0x118ede
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
leaq 0xe47(%rsp), %rdi
callq 0x111780
jmp 0x118fd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
leaq 0xd8f(%rsp), %rdi
callq 0x119320
jmp 0x118fc3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
leaq 0xcdf(%rsp), %rdi
callq 0x119320
jmp 0x118fb6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
jmp 0x118fa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
jmp 0x118f9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
jmp 0x118f8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
jmp 0x118f82
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
jmp 0x118d60
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
leaq 0xb38(%rsp), %rdi
callq 0x111798
leaq 0xb37(%rsp), %rdi
callq 0x111780
jmp 0x118f75
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
jmp 0x118da9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
leaq 0xb10(%rsp), %rdi
callq 0x111798
leaq 0xb0f(%rsp), %rdi
callq 0x111780
jmp 0x118f75
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
jmp 0x118f75
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
jmp 0x118f68
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x11a400
jmp 0x118f68
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
jmp 0x118f5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe38(%rsp)
movl %eax, 0xe34(%rsp)
leaq 0x50(%rsp), %rdi
callq 0x111798
jmp 0x118f5b
leaq 0xe18(%rsp), %rdi
callq 0x11ae60
movq %rax, %rsi
leaq 0xca8(%rsp), %rdi
callq 0x11adc0
jmp 0x118e6b
leaq 0xb60(%rsp), %rdi
leaq 0xca8(%rsp), %rsi
callq 0x1195c0
jmp 0x118e82
leaq 0xae8(%rsp), %rdi
callq 0x11ae80
jmp 0x118e91
leaq 0xd70(%rsp), %rdi
callq 0x11ae60
movq %rax, %rsi
leaq 0xca8(%rsp), %rdi
callq 0x11adc0
jmp 0x118eb0
leaq 0xb60(%rsp), %rdi
leaq 0xca8(%rsp), %rsi
callq 0x1195c0
jmp 0x118ec7
leaq 0xae8(%rsp), %rdi
callq 0x11ae80
jmp 0x118ed6
movl $0x0, 0x4c(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x11aea0
leaq 0xae8(%rsp), %rdi
callq 0x11b0a0
leaq 0xb58(%rsp), %rdi
callq 0x11b0e0
leaq 0xb60(%rsp), %rdi
callq 0x11b160
leaq 0xbd8(%rsp), %rdi
callq 0x11b190
leaq 0xca8(%rsp), %rdi
callq 0x11b1c0
leaq 0xd70(%rsp), %rdi
callq 0x11b1e0
leaq 0xe18(%rsp), %rdi
callq 0x11b1e0
leaq 0xe48(%rsp), %rdi
callq 0x111798
addq $0xe68, %rsp            # imm = 0xE68
retq
leaq 0x1c0(%rsp), %rdi
callq 0x11aea0
leaq 0xae8(%rsp), %rdi
callq 0x11b0a0
leaq 0xb58(%rsp), %rdi
callq 0x11b0e0
leaq 0xb60(%rsp), %rdi
callq 0x11b160
leaq 0xbd8(%rsp), %rdi
callq 0x11b190
leaq 0xca8(%rsp), %rdi
callq 0x11b1c0
leaq 0xd70(%rsp), %rdi
callq 0x11b1e0
leaq 0xe18(%rsp), %rdi
callq 0x11b1e0
leaq 0xe48(%rsp), %rdi
callq 0x111798
movq 0xe38(%rsp), %rdi
callq 0x111450
nopl (%rax)