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

   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());

   T n = T(0);

   symbol_table_t symbol_table;
   symbol_table.add_variable("n", n);
   symbol_table.add_vector  ("v", vv);

   expression_t expression;
   expression.register_symbol_table(symbol_table);

   parser_t parser;

   const std::string vector_resize_expression =
      " sum(v) == ((v[]^2 + v[]) / 2) and sum(2v) == (n^2 + n)";

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

   for (std::size_t i = 1; i <= vv.base_size(); ++i)
   {
      vv.set_size(i);
      vv.rebase(i % 2 ? v0.data() : v1.data());

      n = T(i);

      const T result = expression.value();

      if (result != T(1))
      {
         printf("Error: vector size: %d\n", static_cast<unsigned int>(i));
      }
   }
}

// Assembly:
subq $0xd58, %rsp            # imm = 0xD58
movups 0x336912(%rip), %xmm0   # 0x44f130
movaps %xmm0, 0xd10(%rsp)
movups 0x3368f3(%rip), %xmm0   # 0x44f120
movaps %xmm0, 0xd00(%rsp)
movups 0x3368d4(%rip), %xmm0   # 0x44f110
movaps %xmm0, 0xcf0(%rsp)
movups 0x3368b5(%rip), %xmm0   # 0x44f100
movaps %xmm0, 0xce0(%rsp)
movups 0x336896(%rip), %xmm0   # 0x44f0f0
movaps %xmm0, 0xcd0(%rsp)
movups 0x336877(%rip), %xmm0   # 0x44f0e0
movaps %xmm0, 0xcc0(%rsp)
movups 0x336858(%rip), %xmm0   # 0x44f0d0
movaps %xmm0, 0xcb0(%rsp)
movabsq $0x402e000000000000, %rax # imm = 0x402E000000000000
movq %rax, 0xd20(%rsp)
leaq 0xcb0(%rsp), %rax
movq %rax, 0xd30(%rsp)
movq $0xf, 0xd38(%rsp)
leaq 0xcaf(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x119280
movq 0x58(%rsp), %rcx
movq 0xd30(%rsp), %rsi
movq 0xd38(%rsp), %rdx
leaq 0xd40(%rsp), %rdi
callq 0x119290
jmp 0x1188e4
leaq 0xcaf(%rsp), %rdi
callq 0x119320
movabsq $0x402e000000000000, %rax # imm = 0x402E000000000000
movq %rax, 0xc60(%rsp)
movups 0x33689e(%rip), %xmm0   # 0x44f1a8
movaps %xmm0, 0xc50(%rsp)
movups 0x33687f(%rip), %xmm0   # 0x44f198
movaps %xmm0, 0xc40(%rsp)
movups 0x336860(%rip), %xmm0   # 0x44f188
movaps %xmm0, 0xc30(%rsp)
movups 0x336841(%rip), %xmm0   # 0x44f178
movaps %xmm0, 0xc20(%rsp)
movups 0x336822(%rip), %xmm0   # 0x44f168
movaps %xmm0, 0xc10(%rsp)
movups 0x336803(%rip), %xmm0   # 0x44f158
movaps %xmm0, 0xc00(%rsp)
movups 0x3367e4(%rip), %xmm0   # 0x44f148
movaps %xmm0, 0xbf0(%rsp)
leaq 0xbf0(%rsp), %rax
movq %rax, 0xc70(%rsp)
movq $0xf, 0xc78(%rsp)
leaq 0xbef(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x119280
movq 0x50(%rsp), %rcx
movq 0xc70(%rsp), %rsi
movq 0xc78(%rsp), %rdx
leaq 0xc80(%rsp), %rdi
callq 0x119290
jmp 0x1189be
leaq 0xbef(%rsp), %rdi
callq 0x119320
leaq 0xd40(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x119390
movq 0x48(%rsp), %rsi
movq %rax, %rdx
xorl %eax, %eax
movl %eax, %ecx
leaq 0xbb8(%rsp), %rdi
callq 0x119330
jmp 0x1189f8
movq $0x0, 0xbb0(%rsp)
leaq 0xba8(%rsp), %rdi
movl $0x1, %esi
callq 0x1193b0
jmp 0x118a18
leaq 0xb87(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x111650
movq 0x40(%rsp), %rdx
leaq 0x3319d6(%rip), %rsi    # 0x44a40c
leaq 0xb88(%rsp), %rdi
callq 0x118750
jmp 0x118a45
leaq 0xba8(%rsp), %rdi
leaq 0xb88(%rsp), %rsi
leaq 0xbb0(%rsp), %rdx
xorl %ecx, %ecx
callq 0x1193f0
jmp 0x118a66
leaq 0xb88(%rsp), %rdi
callq 0x111788
leaq 0xb87(%rsp), %rdi
callq 0x111770
leaq 0xb5f(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x111650
movq 0x38(%rsp), %rdx
leaq 0x331aa3(%rip), %rsi    # 0x44a541
leaq 0xb60(%rsp), %rdi
callq 0x118750
jmp 0x118aad
leaq 0xba8(%rsp), %rdi
leaq 0xb60(%rsp), %rsi
leaq 0xbb8(%rsp), %rdx
callq 0x1194a0
jmp 0x118acc
leaq 0xb60(%rsp), %rdi
callq 0x111788
leaq 0xb5f(%rsp), %rdi
callq 0x111770
leaq 0xb38(%rsp), %rdi
callq 0x119560
jmp 0x118af5
leaq 0xb38(%rsp), %rdi
leaq 0xba8(%rsp), %rsi
callq 0x119610
jmp 0x118b0c
leaq 0xc0(%rsp), %rdi
movl $0x7f, %esi
callq 0x1196c0
jmp 0x118b20
leaq 0x210(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x1197f0
jmp 0x118b37
leaq 0xc0(%rsp), %rdi
callq 0x11a020
leaq 0x9f(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x111650
movq 0x30(%rsp), %rdx
leaq 0x3319e1(%rip), %rsi    # 0x44a543
leaq 0xa0(%rsp), %rdi
callq 0x118750
jmp 0x118b71
leaq 0x9f(%rsp), %rdi
callq 0x111770
leaq 0x210(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
leaq 0xb38(%rsp), %rdx
callq 0x11a090
movb %al, 0x2f(%rsp)
jmp 0x118ba1
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x118dd8
jmp 0x118baf
leaq 0x78(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x11a920
jmp 0x118bc3
leaq 0x78(%rsp), %rdi
callq 0x1110f0
movq %rax, 0x20(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x1110f0
movq 0x20(%rsp), %rsi
movq %rax, %rdx
leaq 0x33198d(%rip), %rdi    # 0x44a57b
xorl %eax, %eax
callq 0x111080
jmp 0x118bf7
leaq 0x78(%rsp), %rdi
callq 0x111788
movl $0x1, 0x74(%rsp)
jmp 0x118f0a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
leaq 0xcaf(%rsp), %rdi
callq 0x119320
jmp 0x118fc8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
leaq 0xbef(%rsp), %rdi
callq 0x119320
jmp 0x118fbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
jmp 0x118fae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
jmp 0x118fa1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
jmp 0x118cc3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
leaq 0xb88(%rsp), %rdi
callq 0x111788
leaq 0xb87(%rsp), %rdi
callq 0x111770
jmp 0x118f94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
jmp 0x118d0c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
leaq 0xb60(%rsp), %rdi
callq 0x111788
leaq 0xb5f(%rsp), %rdi
callq 0x111770
jmp 0x118f94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
jmp 0x118f94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
jmp 0x118f87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x11a020
jmp 0x118f87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
leaq 0x9f(%rsp), %rdi
callq 0x111770
jmp 0x118f7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
jmp 0x118f6d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xca0(%rsp)
movl %eax, 0xc9c(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x111788
jmp 0x118f6d
movq $0x1, 0x68(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xbb8(%rsp), %rdi
callq 0x11a9e0
movq %rax, 0x18(%rsp)
jmp 0x118dff
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
cmpq %rcx, %rax
ja 0x118f02
movq 0x68(%rsp), %rsi
leaq 0xbb8(%rsp), %rdi
callq 0x11a9f0
jmp 0x118e26
movq 0x68(%rsp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x118e49
leaq 0xd40(%rsp), %rdi
callq 0x11aae0
movq %rax, 0x8(%rsp)
jmp 0x118e5b
leaq 0xc80(%rsp), %rdi
callq 0x11aae0
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rsi
leaq 0xbb8(%rsp), %rdi
callq 0x11aa40
jmp 0x118e6f
movaps 0x32c19a(%rip), %xmm1   # 0x445010
movq 0x68(%rsp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x32c198(%rip), %xmm1   # 0x445020
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, 0xbb0(%rsp)
leaq 0xb38(%rsp), %rdi
callq 0x11ab00
movsd %xmm0, (%rsp)
jmp 0x118eb4
movsd (%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x60(%rsp), %xmm0
movsd 0x32c173(%rip), %xmm1   # 0x445040
ucomisd %xmm1, %xmm0
jne 0x118ed7
jp 0x118ed7
jmp 0x118eed
movl 0x68(%rsp), %esi
leaq 0x3316b3(%rip), %rdi    # 0x44a595
xorl %eax, %eax
callq 0x111080
jmp 0x118eeb
jmp 0x118eed
jmp 0x118eef
movq 0x68(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x68(%rsp)
jmp 0x118de1
movl $0x0, 0x74(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x111788
leaq 0x210(%rsp), %rdi
callq 0x11ab20
leaq 0xb38(%rsp), %rdi
callq 0x11ad20
leaq 0xba8(%rsp), %rdi
callq 0x11ad60
leaq 0xbb8(%rsp), %rdi
callq 0x11ade0
leaq 0xc80(%rsp), %rdi
callq 0x11ae00
leaq 0xd40(%rsp), %rdi
callq 0x11ae00
addq $0xd58, %rsp            # imm = 0xD58
retq
leaq 0xa0(%rsp), %rdi
callq 0x111788
leaq 0x210(%rsp), %rdi
callq 0x11ab20
leaq 0xb38(%rsp), %rdi
callq 0x11ad20
leaq 0xba8(%rsp), %rdi
callq 0x11ad60
leaq 0xbb8(%rsp), %rdi
callq 0x11ade0
leaq 0xc80(%rsp), %rdi
callq 0x11ae00
leaq 0xd40(%rsp), %rdi
callq 0x11ae00
movq 0xca0(%rsp), %rdi
callq 0x111450
nopw %cs:(%rax,%rax)
nop