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

   const std::string expression_string =
      "a *(4 / pi) * "
      "((1 /  1) * sin( 2 * pi * f * t) + (1 /  3) * sin( 6 * pi * f * t) + "
      " (1 /  5) * sin(10 * pi * f * t) + (1 /  7) * sin(14 * pi * f * t) + "
      " (1 /  9) * sin(18 * pi * f * t) + (1 / 11) * sin(22 * pi * f * t) + "
      " (1 / 13) * sin(26 * pi * f * t) + (1 / 15) * sin(30 * pi * f * t) + "
      " (1 / 17) * sin(34 * pi * f * t) + (1 / 19) * sin(38 * pi * f * t) + "
      " (1 / 21) * sin(42 * pi * f * t) + (1 / 23) * sin(46 * pi * f * t) + "
      " (1 / 25) * sin(50 * pi * f * t) + (1 / 27) * sin(54 * pi * f * t))  ";

   static const T pi = T(3.141592653589793238462643383279502);

   const T f = pi / T(10);
   const T a = T(10);
         T t = T(0);

   symbol_table_t symbol_table;
   symbol_table.add_variable("t",t);
   symbol_table.add_constant("f",f);
   symbol_table.add_constant("a",a);
   symbol_table.add_constants();

   expression_t expression;
   expression.register_symbol_table(symbol_table);

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

   const T delta = (T(4) * pi) / T(1000);

   for (t = (T(-2) * pi); t <= (T(+2) * pi); t += delta)
   {
      const T result = expression.value();
      printf("%19.15f\t%19.15f\n", t, result);
   }
}

// Assembly:
subq $0xba8, %rsp            # imm = 0xBA8
leaq 0xb87(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x111640
movq 0x28(%rsp), %rdx
leaq 0x32fd40(%rip), %rsi    # 0x448565
leaq 0xb88(%rsp), %rdi
callq 0x118740
jmp 0x118834
leaq 0xb87(%rsp), %rdi
callq 0x111760
movabsq $0x3fd41b2f769cf0e0, %rax # imm = 0x3FD41B2F769CF0E0
movq %rax, 0xb68(%rsp)
movabsq $0x4024000000000000, %rax # imm = 0x4024000000000000
movq %rax, 0xb60(%rsp)
movq $0x0, 0xb58(%rsp)
leaq 0xb50(%rsp), %rdi
movl $0x1, %esi
callq 0x118f70
jmp 0x118885
leaq 0xb2f(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x111640
movq 0x20(%rsp), %rdx
leaq 0x330565(%rip), %rsi    # 0x448e08
leaq 0xb30(%rsp), %rdi
callq 0x118740
jmp 0x1188b2
leaq 0xb50(%rsp), %rdi
leaq 0xb30(%rsp), %rsi
leaq 0xb58(%rsp), %rdx
xorl %ecx, %ecx
callq 0x118fb0
jmp 0x1188d3
leaq 0xb30(%rsp), %rdi
callq 0x111778
leaq 0xb2f(%rsp), %rdi
callq 0x111760
leaq 0xb07(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x111640
movq 0x18(%rsp), %rdx
leaq 0x32fbc7(%rip), %rsi    # 0x4484d2
leaq 0xb08(%rsp), %rdi
callq 0x118740
jmp 0x11891a
leaq 0xb50(%rsp), %rdi
leaq 0xb08(%rsp), %rsi
leaq 0xb68(%rsp), %rdx
callq 0x119060
jmp 0x118939
leaq 0xb08(%rsp), %rdi
callq 0x111778
leaq 0xb07(%rsp), %rdi
callq 0x111760
leaq 0xadf(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x111640
movq 0x10(%rsp), %rdx
leaq 0x330ffa(%rip), %rsi    # 0x44996b
leaq 0xae0(%rsp), %rdi
callq 0x118740
jmp 0x118980
leaq 0xb50(%rsp), %rdi
leaq 0xae0(%rsp), %rsi
leaq 0xb60(%rsp), %rdx
callq 0x119060
jmp 0x11899f
leaq 0xae0(%rsp), %rdi
callq 0x111778
leaq 0xadf(%rsp), %rdi
callq 0x111760
leaq 0xb50(%rsp), %rdi
callq 0x119140
jmp 0x1189c8
leaq 0xab8(%rsp), %rdi
callq 0x1191a0
jmp 0x1189d7
leaq 0xab8(%rsp), %rdi
leaq 0xb50(%rsp), %rsi
callq 0x119250
jmp 0x1189ee
leaq 0x40(%rsp), %rdi
movl $0x7f, %esi
callq 0x119300
jmp 0x1189ff
leaq 0x190(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x119430
jmp 0x118a13
leaq 0x40(%rsp), %rdi
callq 0x119c60
leaq 0x190(%rsp), %rdi
leaq 0xb88(%rsp), %rsi
leaq 0xab8(%rsp), %rdx
callq 0x119cd0
jmp 0x118a3c
movsd 0x32a5cc(%rip), %xmm0   # 0x443010
movsd %xmm0, 0x38(%rsp)
movsd 0x32a5b6(%rip), %xmm0   # 0x443008
movsd %xmm0, 0xb58(%rsp)
movsd 0x32a5b5(%rip), %xmm0   # 0x443018
ucomisd 0xb58(%rsp), %xmm0
jb 0x118c5c
leaq 0xab8(%rsp), %rdi
callq 0x11a560
movsd %xmm0, 0x8(%rsp)
jmp 0x118a87
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0xb58(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
leaq 0x32fcae(%rip), %rdi    # 0x448757
movb $0x2, %al
callq 0x111080
jmp 0x118ab2
jmp 0x118ab4
movsd 0x32a554(%rip), %xmm0   # 0x443010
addsd 0xb58(%rsp), %xmm0
movsd %xmm0, 0xb58(%rsp)
jmp 0x118a5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb78(%rsp)
movl %eax, 0xb74(%rsp)
leaq 0xb87(%rsp), %rdi
callq 0x111760
jmp 0x118cbf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb78(%rsp)
movl %eax, 0xb74(%rsp)
jmp 0x118cb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb78(%rsp)
movl %eax, 0xb74(%rsp)
jmp 0x118b46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb78(%rsp)
movl %eax, 0xb74(%rsp)
leaq 0xb30(%rsp), %rdi
callq 0x111778
leaq 0xb2f(%rsp), %rdi
callq 0x111760
jmp 0x118ca5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb78(%rsp)
movl %eax, 0xb74(%rsp)
jmp 0x118b8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb78(%rsp)
movl %eax, 0xb74(%rsp)
leaq 0xb08(%rsp), %rdi
callq 0x111778
leaq 0xb07(%rsp), %rdi
callq 0x111760
jmp 0x118ca5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb78(%rsp)
movl %eax, 0xb74(%rsp)
jmp 0x118bd8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb78(%rsp)
movl %eax, 0xb74(%rsp)
leaq 0xae0(%rsp), %rdi
callq 0x111778
leaq 0xadf(%rsp), %rdi
callq 0x111760
jmp 0x118ca5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb78(%rsp)
movl %eax, 0xb74(%rsp)
jmp 0x118ca5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb78(%rsp)
movl %eax, 0xb74(%rsp)
jmp 0x118c98
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb78(%rsp)
movl %eax, 0xb74(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x119c60
jmp 0x118c98
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb78(%rsp)
movl %eax, 0xb74(%rsp)
leaq 0x190(%rsp), %rdi
callq 0x11a580
jmp 0x118c98
leaq 0x190(%rsp), %rdi
callq 0x11a580
leaq 0xab8(%rsp), %rdi
callq 0x11a780
leaq 0xb50(%rsp), %rdi
callq 0x11a7c0
leaq 0xb88(%rsp), %rdi
callq 0x111778
addq $0xba8, %rsp            # imm = 0xBA8
retq
leaq 0xab8(%rsp), %rdi
callq 0x11a780
leaq 0xb50(%rsp), %rdi
callq 0x11a7c0
leaq 0xb88(%rsp), %rdi
callq 0x111778
movq 0xb78(%rsp), %rdi
callq 0x111440
nopl (%rax)