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

   const std::string bubblesort_program =
      " var upper_bound := v[];                      "
      "                                              "
      " repeat                                       "
      "    var new_upper_bound := 0;                 "
      "                                              "
      "    for (var i := 1; i < upper_bound; i += 1) "
      "    {                                         "
      "       if (v[i - 1] > v[i])                   "
      "       {                                      "
      "          v[i - 1] <=> v[i];                  "
      "          new_upper_bound := i;               "
      "       };                                     "
      "    };                                        "
      "                                              "
      "    upper_bound := new_upper_bound;           "
      "                                              "
      " until (upper_bound <= 1);                    ";

   T v[] = { T(9.1), T(2.2), T(1.3), T(5.4), T(7.5), T(4.6), T(3.7) };

   symbol_table_t symbol_table;
   symbol_table.add_vector("v",v);

   expression_t expression;
   expression.register_symbol_table(symbol_table);

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

   expression.value();
}

// Assembly:
subq $0xb58, %rsp            # imm = 0xB58
leaq 0xb37(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x111630
movq 0x10(%rsp), %rdx
leaq 0x32fd20(%rip), %rsi    # 0x448535
leaq 0xb38(%rsp), %rdi
callq 0x118730
jmp 0x118824
leaq 0xb37(%rsp), %rdi
callq 0x111750
movabsq $0x400d99999999999a, %rax # imm = 0x400D99999999999A
movq %rax, 0xb10(%rsp)
movaps 0x334b36(%rip), %xmm0   # 0x44d380
movaps %xmm0, 0xb00(%rsp)
movaps 0x334b17(%rip), %xmm0   # 0x44d370
movaps %xmm0, 0xaf0(%rsp)
movaps 0x334af8(%rip), %xmm0   # 0x44d360
movaps %xmm0, 0xae0(%rsp)
leaq 0xad8(%rsp), %rdi
movl $0x1, %esi
callq 0x118d70
jmp 0x118884
leaq 0xab7(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x111630
movq 0x8(%rsp), %rdx
leaq 0x32ffa2(%rip), %rsi    # 0x448844
leaq 0xab8(%rsp), %rdi
callq 0x118730
jmp 0x1188b1
leaq 0xad8(%rsp), %rdi
leaq 0xab8(%rsp), %rsi
leaq 0xae0(%rsp), %rdx
callq 0x118db0
jmp 0x1188d0
leaq 0xab8(%rsp), %rdi
callq 0x111768
leaq 0xab7(%rsp), %rdi
callq 0x111750
leaq 0xa90(%rsp), %rdi
callq 0x118e50
jmp 0x1188f9
leaq 0xa90(%rsp), %rdi
leaq 0xad8(%rsp), %rsi
callq 0x118f00
jmp 0x118910
leaq 0x18(%rsp), %rdi
movl $0x7f, %esi
callq 0x118fb0
jmp 0x118921
leaq 0x168(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x1190e0
jmp 0x118935
leaq 0x18(%rsp), %rdi
callq 0x119910
leaq 0x168(%rsp), %rdi
leaq 0xb38(%rsp), %rsi
leaq 0xa90(%rsp), %rdx
callq 0x119980
jmp 0x11895e
leaq 0xa90(%rsp), %rdi
callq 0x11a210
jmp 0x11896d
leaq 0x168(%rsp), %rdi
callq 0x11a230
leaq 0xa90(%rsp), %rdi
callq 0x11a430
leaq 0xad8(%rsp), %rdi
callq 0x11a470
leaq 0xb38(%rsp), %rdi
callq 0x111768
addq $0xb58, %rsp            # imm = 0xB58
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb28(%rsp)
movl %eax, 0xb24(%rsp)
leaq 0xb37(%rsp), %rdi
callq 0x111750
jmp 0x118ac2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb28(%rsp)
movl %eax, 0xb24(%rsp)
jmp 0x118ab5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb28(%rsp)
movl %eax, 0xb24(%rsp)
jmp 0x118a1f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb28(%rsp)
movl %eax, 0xb24(%rsp)
leaq 0xab8(%rsp), %rdi
callq 0x111768
leaq 0xab7(%rsp), %rdi
callq 0x111750
jmp 0x118aa8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb28(%rsp)
movl %eax, 0xb24(%rsp)
jmp 0x118aa8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb28(%rsp)
movl %eax, 0xb24(%rsp)
jmp 0x118a9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb28(%rsp)
movl %eax, 0xb24(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x119910
jmp 0x118a9b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb28(%rsp)
movl %eax, 0xb24(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x11a230
leaq 0xa90(%rsp), %rdi
callq 0x11a430
leaq 0xad8(%rsp), %rdi
callq 0x11a470
leaq 0xb38(%rsp), %rdi
callq 0x111768
movq 0xb28(%rsp), %rdi
callq 0x111430
nop