// File: ArashPartow[P]exprtk/exprtk_simple_example_08.cpp
// Function: void composite<double>()
void composite()
{
   typedef exprtk::symbol_table<T>         symbol_table_t;
   typedef exprtk::expression<T>           expression_t;
   typedef exprtk::parser<T>               parser_t;
   typedef exprtk::parser_error::type      err_t;
   typedef exprtk::function_compositor<T>  compositor_t;
   typedef typename compositor_t::function function_t;

   T x = T(1);
   T y = T(2);

   compositor_t compositor;

   symbol_table_t& symbol_table = compositor.symbol_table();
   symbol_table.add_constants();
   symbol_table.add_variable("x",x);
   symbol_table.add_variable("y",y);

   compositor.add(
      function_t("f")     // f(x) = sin(x / pi)
      .var("x")
      .expression( "sin(x / pi)" ));

   compositor.add(
      function_t("g")     // g(x,y) = 3[f(x) + f(y)]
      .vars("x", "y")
      .expression( "3*[f(x) + f(y)]" ));

   std::string expression_string = "g(1 + f(x), f(y) / 2)";

   expression_t expression;
   expression.register_symbol_table(symbol_table);

   parser_t parser;

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

      for (std::size_t i = 0; i < parser.error_count(); ++i)
      {
         const err_t error = parser.get_error(i);

         printf("Error: %02d  Position: %02d Type: [%14s] Msg: %s\tExpression: %s\n",
                static_cast<unsigned int>(i),
                static_cast<unsigned int>(error.token.position),
                exprtk::parser_error::to_str(error.mode).c_str(),
                error.diagnostic.c_str(),
                expression_string.c_str());
      }

      return;
   }

   const T result = expression.value();

   printf("%s = %e\n", expression_string.c_str(), result);
}

// Assembly:
subq $0x1928, %rsp           # imm = 0x1928
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x1920(%rsp)
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
movq %rax, 0x1918(%rsp)
leaq 0xf30(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
callq 0x11b5f0
movq 0xc0(%rsp), %rdi
callq 0x11b780
movq %rax, 0xc8(%rsp)
jmp 0x11a877
movq 0xc8(%rsp), %rax
movq %rax, 0xf28(%rsp)
movq 0xf28(%rsp), %rdi
callq 0x11b790
jmp 0x11a896
movq 0xf28(%rsp), %rax
movq %rax, 0xb0(%rsp)
leaq 0xef7(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0x113660
movq 0xb8(%rsp), %rdx
leaq 0x347c13(%rip), %rsi    # 0x4624dd
leaq 0xef8(%rsp), %rdi
callq 0x11a760
jmp 0x11a8d9
movq 0xb0(%rsp), %rdi
leaq 0xef8(%rsp), %rsi
leaq 0x1920(%rsp), %rdx
xorl %ecx, %ecx
callq 0x11b7f0
jmp 0x11a8fa
leaq 0xef8(%rsp), %rdi
callq 0x113798
leaq 0xef7(%rsp), %rdi
callq 0x113780
movq 0xf28(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0xecf(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x113660
movq 0xa8(%rsp), %rdx
leaq 0x347c3d(%rip), %rsi    # 0x462585
leaq 0xed0(%rsp), %rdi
callq 0x11a760
jmp 0x11a957
movq 0xa0(%rsp), %rdi
leaq 0xed0(%rsp), %rsi
leaq 0x1918(%rsp), %rdx
xorl %ecx, %ecx
callq 0x11b7f0
jmp 0x11a978
leaq 0xed0(%rsp), %rdi
callq 0x113798
leaq 0xecf(%rsp), %rdi
callq 0x113780
leaq 0xe17(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x113660
movq 0x98(%rsp), %rdx
leaq 0x347b3c(%rip), %rsi    # 0x4624f2
leaq 0xe18(%rsp), %rdi
callq 0x11a760
jmp 0x11a9c5
leaq 0xe38(%rsp), %rdi
leaq 0xe18(%rsp), %rsi
callq 0x11b8f0
jmp 0x11a9dc
leaq 0xdef(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x113660
movq 0x90(%rsp), %rdx
leaq 0x347add(%rip), %rsi    # 0x4624dd
leaq 0xdf0(%rsp), %rdi
callq 0x11a760
jmp 0x11aa0f
leaq 0xe38(%rsp), %rdi
leaq 0xdf0(%rsp), %rsi
callq 0x11b970
movq %rax, 0x88(%rsp)
jmp 0x11aa2e
leaq 0xdc7(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x113660
movq 0x80(%rsp), %rdx
leaq 0x347b35(%rip), %rsi    # 0x462587
leaq 0xdc8(%rsp), %rdi
callq 0x11a760
jmp 0x11aa61
movq 0x88(%rsp), %rdi
leaq 0xdc8(%rsp), %rsi
callq 0x11b9a0
movq %rax, 0x78(%rsp)
jmp 0x11aa7d
movq 0x78(%rsp), %rsi
leaq 0xf30(%rsp), %rdi
xorl %edx, %edx
callq 0x11b8a0
jmp 0x11aa93
leaq 0xdc8(%rsp), %rdi
callq 0x113798
leaq 0xdc7(%rsp), %rdi
callq 0x113780
leaq 0xdf0(%rsp), %rdi
callq 0x113798
leaq 0xdef(%rsp), %rdi
callq 0x113780
leaq 0xe38(%rsp), %rdi
callq 0x11b9d0
leaq 0xe18(%rsp), %rdi
callq 0x113798
leaq 0xe17(%rsp), %rdi
callq 0x113780
leaq 0xd0f(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0x113660
movq 0x70(%rsp), %rdx
leaq 0x347999(%rip), %rsi    # 0x4624a5
leaq 0xd10(%rsp), %rdi
callq 0x11a760
jmp 0x11ab1b
leaq 0xd30(%rsp), %rdi
leaq 0xd10(%rsp), %rsi
callq 0x11b8f0
jmp 0x11ab32
leaq 0xce7(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x113660
movq 0x68(%rsp), %rdx
leaq 0x34798d(%rip), %rsi    # 0x4624dd
leaq 0xce8(%rsp), %rdi
callq 0x11a760
jmp 0x11ab5f
leaq 0xcbf(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x113660
movq 0x60(%rsp), %rdx
leaq 0x347a08(%rip), %rsi    # 0x462585
leaq 0xcc0(%rsp), %rdi
callq 0x11a760
jmp 0x11ab8c
leaq 0xd30(%rsp), %rdi
leaq 0xce8(%rsp), %rsi
leaq 0xcc0(%rsp), %rdx
callq 0x11ba10
movq %rax, 0x58(%rsp)
jmp 0x11abb0
leaq 0xc97(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x113660
movq 0x50(%rsp), %rdx
leaq 0x3479c5(%rip), %rsi    # 0x462593
leaq 0xc98(%rsp), %rdi
callq 0x11a760
jmp 0x11abdd
movq 0x58(%rsp), %rdi
leaq 0xc98(%rsp), %rsi
callq 0x11b9a0
movq %rax, 0x48(%rsp)
jmp 0x11abf6
movq 0x48(%rsp), %rsi
leaq 0xf30(%rsp), %rdi
xorl %edx, %edx
callq 0x11b8a0
jmp 0x11ac0c
leaq 0xc98(%rsp), %rdi
callq 0x113798
leaq 0xc97(%rsp), %rdi
callq 0x113780
leaq 0xcc0(%rsp), %rdi
callq 0x113798
leaq 0xcbf(%rsp), %rdi
callq 0x113780
leaq 0xce8(%rsp), %rdi
callq 0x113798
leaq 0xce7(%rsp), %rdi
callq 0x113780
leaq 0xd30(%rsp), %rdi
callq 0x11b9d0
leaq 0xd10(%rsp), %rdi
callq 0x113798
leaq 0xd0f(%rsp), %rdi
callq 0x113780
leaq 0xc6f(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x113660
movq 0x40(%rsp), %rdx
leaq 0x347904(%rip), %rsi    # 0x4625a3
leaq 0xc70(%rsp), %rdi
callq 0x11a760
jmp 0x11acae
leaq 0xc6f(%rsp), %rdi
callq 0x113780
leaq 0xc48(%rsp), %rdi
callq 0x11ba60
jmp 0x11acca
movq 0xf28(%rsp), %rsi
leaq 0xc48(%rsp), %rdi
callq 0x11bb10
jmp 0x11ace1
leaq 0x1d0(%rsp), %rdi
movl $0x7f, %esi
callq 0x11bbc0
jmp 0x11acf5
leaq 0x320(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x11bcf0
jmp 0x11ad0c
leaq 0x1d0(%rsp), %rdi
callq 0x11c520
leaq 0x320(%rsp), %rdi
leaq 0xc70(%rsp), %rsi
leaq 0xc48(%rsp), %rdx
callq 0x11c590
movb %al, 0x3f(%rsp)
jmp 0x11ad3c
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0x11b27a
jmp 0x11ad4a
leaq 0x1b0(%rsp), %rdi
leaq 0x320(%rsp), %rsi
callq 0x11ce20
jmp 0x11ad61
leaq 0x1b0(%rsp), %rdi
callq 0x1130f0
movq %rax, 0x30(%rsp)
leaq 0xc70(%rsp), %rdi
callq 0x1130f0
movq 0x30(%rsp), %rsi
movq %rax, %rdx
leaq 0x34782a(%rip), %rdi    # 0x4625b9
xorl %eax, %eax
callq 0x113080
jmp 0x11ad98
leaq 0x1b0(%rsp), %rdi
callq 0x113798
movq $0x0, 0x1a8(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x320(%rsp), %rdi
callq 0x11cee0
movq %rax, 0x28(%rsp)
jmp 0x11add2
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
cmpq %rcx, %rax
jae 0x11b26d
leaq 0x100(%rsp), %rdi
leaq 0x320(%rsp), %rsi
leaq 0x1a8(%rsp), %rdx
callq 0x11cf00
jmp 0x11ae04
movl 0x1a8(%rsp), %eax
movl %eax, 0x18(%rsp)
movl 0x128(%rsp), %eax
movl %eax, 0x1c(%rsp)
movl 0x130(%rsp), %esi
leaq 0xe0(%rsp), %rdi
callq 0x11cfe0
jmp 0x11ae30
leaq 0xe0(%rsp), %rdi
callq 0x1130f0
movq %rax, 0x8(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x1130f0
movq %rax, 0x10(%rsp)
leaq 0xc70(%rsp), %rdi
callq 0x1130f0
movl 0x18(%rsp), %esi
movl 0x1c(%rsp), %edx
movq 0x8(%rsp), %rcx
movq 0x10(%rsp), %r8
movq %rax, %r9
leaq 0x347756(%rip), %rdi    # 0x4625d3
xorl %eax, %eax
callq 0x113080
jmp 0x11ae86
leaq 0xe0(%rsp), %rdi
callq 0x113798
leaq 0x100(%rsp), %rdi
callq 0x11d320
movq 0x1a8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x1a8(%rsp)
jmp 0x11adb1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b333
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11af09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
leaq 0xef8(%rsp), %rdi
callq 0x113798
leaq 0xef7(%rsp), %rdi
callq 0x113780
jmp 0x11b333
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11af52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
leaq 0xed0(%rsp), %rdi
callq 0x113798
leaq 0xecf(%rsp), %rdi
callq 0x113780
jmp 0x11b333
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b03a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b02d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b013
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b006
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11aff9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
leaq 0xdc8(%rsp), %rdi
callq 0x113798
leaq 0xdc7(%rsp), %rdi
callq 0x113780
leaq 0xdf0(%rsp), %rdi
callq 0x113798
leaq 0xdef(%rsp), %rdi
callq 0x113780
leaq 0xe38(%rsp), %rdi
callq 0x11b9d0
leaq 0xe18(%rsp), %rdi
callq 0x113798
leaq 0xe17(%rsp), %rdi
callq 0x113780
jmp 0x11b333
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b155
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b148
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b12e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b114
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b107
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b0fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
leaq 0xc98(%rsp), %rdi
callq 0x113798
leaq 0xc97(%rsp), %rdi
callq 0x113780
leaq 0xcc0(%rsp), %rdi
callq 0x113798
leaq 0xcbf(%rsp), %rdi
callq 0x113780
leaq 0xce8(%rsp), %rdi
callq 0x113798
leaq 0xce7(%rsp), %rdi
callq 0x113780
leaq 0xd30(%rsp), %rdi
callq 0x11b9d0
leaq 0xd10(%rsp), %rdi
callq 0x113798
leaq 0xd0f(%rsp), %rdi
callq 0x113780
jmp 0x11b333
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
leaq 0xc6f(%rsp), %rdi
callq 0x113780
jmp 0x11b333
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b326
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b319
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x11c520
jmp 0x11b319
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b30c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
leaq 0x1b0(%rsp), %rdi
callq 0x113798
jmp 0x11b30c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
jmp 0x11b25b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf20(%rsp)
movl %eax, 0xf1c(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x113798
leaq 0x100(%rsp), %rdi
callq 0x11d320
jmp 0x11b30c
movl $0x1, 0xdc(%rsp)
jmp 0x11b2d0
leaq 0xc48(%rsp), %rdi
callq 0x11d370
movsd %xmm0, (%rsp)
jmp 0x11b28e
movsd (%rsp), %xmm0
movsd %xmm0, 0xd0(%rsp)
leaq 0xc70(%rsp), %rdi
callq 0x1130f0
movq %rax, %rsi
movsd 0xd0(%rsp), %xmm0
leaq 0x347358(%rip), %rdi    # 0x462614
movb $0x1, %al
callq 0x113080
jmp 0x11b2c5
movl $0x0, 0xdc(%rsp)
leaq 0x320(%rsp), %rdi
callq 0x11d390
leaq 0xc48(%rsp), %rdi
callq 0x11d590
leaq 0xc70(%rsp), %rdi
callq 0x113798
leaq 0xf30(%rsp), %rdi
callq 0x11d5d0
addq $0x1928, %rsp           # imm = 0x1928
retq
leaq 0x320(%rsp), %rdi
callq 0x11d390
leaq 0xc48(%rsp), %rdi
callq 0x11d590
leaq 0xc70(%rsp), %rdi
callq 0x113798
leaq 0xf30(%rsp), %rdi
callq 0x11d5d0
movq 0xf20(%rsp), %rdi
callq 0x113450
nopl (%rax)