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

   const std::string expression_str =
      " for (var i := 0; i < max(v0[],v1[]); i += 1) "
      " {                                            "
      "    v0[i] := (2 * v0[i]) + (v1[i] / 3);       "
      " }                                            ";

   T v0[5 ] = { 0, 1, 2, 3, 4 };
   T v1[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

   vector_access_rtc vec_rtc;

   vec_rtc.vector_map[v0] = "v0";
   vec_rtc.vector_map[v1] = "v1";

   symbol_table_t symbol_table;
   expression_t   expression;
   parser_t       parser;

   symbol_table.add_vector("v0", v0);
   symbol_table.add_vector("v1", v1);

   expression.register_symbol_table(symbol_table);

   parser.register_vector_access_runtime_check(vec_rtc);

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

      return;
   }

   try
   {
      expression.value();
   }
   catch(std::runtime_error& exception)
   {
      printf("Exception: %s\n",exception.what());
   }
}

// Assembly:
subq $0xc58, %rsp            # imm = 0xC58
leaq 0xc37(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x111670
movq 0x30(%rsp), %rdx
leaq 0x331ce0(%rip), %rsi    # 0x44a535
leaq 0xc38(%rsp), %rdi
callq 0x118770
jmp 0x118864
leaq 0xc37(%rsp), %rdi
callq 0x111790
xorps %xmm0, %xmm0
movaps %xmm0, 0xc00(%rsp)
movaps %xmm0, 0xbf0(%rsp)
movq $0x0, 0xc10(%rsp)
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0xbf8(%rsp)
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0xc00(%rsp)
movabsq $0x4008000000000000, %rax # imm = 0x4008000000000000
movq %rax, 0xc08(%rsp)
movabsq $0x4010000000000000, %rax # imm = 0x4010000000000000
movq %rax, 0xc10(%rsp)
movaps 0x336941(%rip), %xmm0   # 0x44f220
movaps %xmm0, 0xbe0(%rsp)
movaps 0x336922(%rip), %xmm0   # 0x44f210
movaps %xmm0, 0xbd0(%rsp)
movaps 0x336903(%rip), %xmm0   # 0x44f200
movaps %xmm0, 0xbc0(%rsp)
movaps 0x3368e4(%rip), %xmm0   # 0x44f1f0
movaps %xmm0, 0xbb0(%rsp)
movaps 0x3368c5(%rip), %xmm0   # 0x44f1e0
movaps %xmm0, 0xba0(%rsp)
leaq 0xb68(%rsp), %rdi
callq 0x1190c0
leaq 0xb70(%rsp), %rdi
leaq 0xbf0(%rsp), %rax
movq %rax, 0xb60(%rsp)
leaq 0xb60(%rsp), %rsi
callq 0x119100
movq %rax, 0x28(%rsp)
jmp 0x11895c
movq 0x28(%rsp), %rdi
leaq 0x331c86(%rip), %rsi    # 0x44a5ee
callq 0x111310
jmp 0x11896f
leaq 0xb70(%rsp), %rdi
leaq 0xba0(%rsp), %rax
movq %rax, 0xb58(%rsp)
leaq 0xb58(%rsp), %rsi
callq 0x119100
movq %rax, 0x20(%rsp)
jmp 0x11899b
movq 0x20(%rsp), %rdi
leaq 0x331c4a(%rip), %rsi    # 0x44a5f1
callq 0x111310
jmp 0x1189ae
leaq 0xb50(%rsp), %rdi
movl $0x1, %esi
callq 0x119200
jmp 0x1189c2
leaq 0xb30(%rsp), %rdi
callq 0x119240
jmp 0x1189d1
leaq 0xb8(%rsp), %rdi
movl $0x7f, %esi
callq 0x1192f0
jmp 0x1189e5
leaq 0x208(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x119420
jmp 0x1189fc
leaq 0xb8(%rsp), %rdi
callq 0x119c50
leaq 0x97(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x111670
movq 0x18(%rsp), %rdx
leaq 0x331bc7(%rip), %rsi    # 0x44a5ee
leaq 0x98(%rsp), %rdi
callq 0x118770
jmp 0x118a36
leaq 0xb50(%rsp), %rdi
leaq 0x98(%rsp), %rsi
leaq 0xbf0(%rsp), %rdx
callq 0x119cc0
jmp 0x118a55
leaq 0x98(%rsp), %rdi
callq 0x1117a8
leaq 0x97(%rsp), %rdi
callq 0x111790
leaq 0x6f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x111670
movq 0x10(%rsp), %rdx
leaq 0x331b67(%rip), %rsi    # 0x44a5f1
leaq 0x70(%rsp), %rdi
callq 0x118770
jmp 0x118a96
leaq 0xb50(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0xba0(%rsp), %rdx
callq 0x119d60
jmp 0x118ab2
leaq 0x70(%rsp), %rdi
callq 0x1117a8
leaq 0x6f(%rsp), %rdi
callq 0x111790
leaq 0xb30(%rsp), %rdi
leaq 0xb50(%rsp), %rsi
callq 0x119e00
jmp 0x118add
leaq 0x208(%rsp), %rdi
leaq 0xb68(%rsp), %rsi
callq 0x119eb0
jmp 0x118af4
leaq 0x208(%rsp), %rdi
leaq 0xc38(%rsp), %rsi
leaq 0xb30(%rsp), %rdx
callq 0x119ed0
movb %al, 0xf(%rsp)
jmp 0x118b17
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x118ce1
jmp 0x118b25
leaq 0x48(%rsp), %rdi
leaq 0x208(%rsp), %rsi
callq 0x11a760
jmp 0x118b39
leaq 0x48(%rsp), %rdi
callq 0x1110f0
movq %rax, (%rsp)
leaq 0xc38(%rsp), %rdi
callq 0x1110f0
movq (%rsp), %rsi
movq %rax, %rdx
leaq 0x331a92(%rip), %rdi    # 0x44a5f4
xorl %eax, %eax
callq 0x111080
jmp 0x118b6b
leaq 0x48(%rsp), %rdi
callq 0x1117a8
movl $0x1, 0x44(%rsp)
jmp 0x118d5e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc28(%rsp)
movl %eax, 0xc24(%rsp)
leaq 0xc37(%rsp), %rdi
callq 0x111790
jmp 0x118e05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc28(%rsp)
movl %eax, 0xc24(%rsp)
jmp 0x118deb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc28(%rsp)
movl %eax, 0xc24(%rsp)
jmp 0x118dde
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc28(%rsp)
movl %eax, 0xc24(%rsp)
jmp 0x118dd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc28(%rsp)
movl %eax, 0xc24(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x119c50
jmp 0x118dd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc28(%rsp)
movl %eax, 0xc24(%rsp)
jmp 0x118c50
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc28(%rsp)
movl %eax, 0xc24(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x1117a8
leaq 0x97(%rsp), %rdi
callq 0x111790
jmp 0x118dc4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc28(%rsp)
movl %eax, 0xc24(%rsp)
jmp 0x118c96
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc28(%rsp)
movl %eax, 0xc24(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x1117a8
leaq 0x6f(%rsp), %rdi
callq 0x111790
jmp 0x118dc4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc28(%rsp)
movl %eax, 0xc24(%rsp)
jmp 0x118dc4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc28(%rsp)
movl %eax, 0xc24(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x1117a8
jmp 0x118dc4
leaq 0xb30(%rsp), %rdi
callq 0x11a820
jmp 0x118cf0
jmp 0x118d56
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc28(%rsp)
movl %eax, 0xc24(%rsp)
movl 0xc24(%rsp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x118dc4
movq 0xc28(%rsp), %rdi
callq 0x111070
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq %rax, %rsi
leaq 0x3318ca(%rip), %rdi    # 0x44a60e
xorl %eax, %eax
callq 0x111080
jmp 0x118d4d
callq 0x1114f0
jmp 0x118d54
jmp 0x118d56
movl $0x0, 0x44(%rsp)
leaq 0x208(%rsp), %rdi
callq 0x11a840
leaq 0xb30(%rsp), %rdi
callq 0x11aa40
leaq 0xb50(%rsp), %rdi
callq 0x11aa80
leaq 0xb68(%rsp), %rdi
callq 0x11ab00
leaq 0xc38(%rsp), %rdi
callq 0x1117a8
addq $0xc58, %rsp            # imm = 0xC58
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xc28(%rsp)
movl %eax, 0xc24(%rsp)
callq 0x1114f0
jmp 0x118dc2
jmp 0x118dc4
leaq 0x208(%rsp), %rdi
callq 0x11a840
leaq 0xb30(%rsp), %rdi
callq 0x11aa40
leaq 0xb50(%rsp), %rdi
callq 0x11aa80
leaq 0xb68(%rsp), %rdi
callq 0x11ab00
leaq 0xc38(%rsp), %rdi
callq 0x1117a8
movq 0xc28(%rsp), %rdi
callq 0x111470
movq %rax, %rdi
callq 0x119080
nopw (%rax,%rax)