// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbx
subq $0xae0, %rsp            # imm = 0xAE0
leaq 0x129e0f(%rip), %rsi    # 0x23a111
leaq 0x48(%rsp), %rdi
leaq 0x1b8(%rsp), %rdx
callq 0x1102b8
movabsq $0x3fd41b2f769cf0e0, %rax # imm = 0x3FD41B2F769CF0E0
movq %rax, 0x20(%rsp)
movabsq $0x4024000000000000, %rax # imm = 0x4024000000000000
movq %rax, 0x18(%rsp)
andq $0x0, 0x10(%rsp)
leaq 0x8(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x110602
leaq 0x12a67a(%rip), %rsi    # 0x23a9c6
leaq 0x1b8(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x1102b8
leaq 0x8(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
leaq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0x110626
leaq 0x1b8(%rsp), %rdi
callq 0x10e5b8
leaq 0x129cf3(%rip), %rsi    # 0x23a07e
leaq 0x1b8(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x1102b8
leaq 0x8(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x110692
leaq 0x1b8(%rsp), %rdi
callq 0x10e5b8
leaq 0x12b161(%rip), %rsi    # 0x23b529
leaq 0x1b8(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0x1102b8
leaq 0x8(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x110692
leaq 0x1b8(%rsp), %rdi
callq 0x10e5b8
leaq 0x8(%rsp), %rdi
callq 0x11070e
leaq 0x28(%rsp), %rdi
callq 0x110734
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x110794
leaq 0x68(%rsp), %rdi
pushq $0x7f
popq %rsi
callq 0x1107f0
leaq 0x1b8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x110900
leaq 0x68(%rsp), %rdi
callq 0x110f18
leaq 0x1b8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x110f60
movsd 0x124b9f(%rip), %xmm0   # 0x235008
leaq 0x129e93(%rip), %rbx    # 0x23a303
movsd %xmm0, 0x10(%rsp)
movsd 0x124b92(%rip), %xmm1   # 0x235010
ucomisd %xmm0, %xmm1
jb 0x1104b7
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movapd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
movb $0x2, %al
callq 0x10e060
movsd 0x10(%rsp), %xmm0
addsd 0x124b63(%rip), %xmm0   # 0x235018
jmp 0x110470
leaq 0x1b8(%rsp), %rdi
callq 0x1113e2
leaq 0x28(%rsp), %rdi
callq 0x11151c
leaq 0x8(%rsp), %rdi
callq 0x111532
leaq 0x48(%rsp), %rdi
callq 0x10e5b8
addq $0xae0, %rsp            # imm = 0xAE0
popq %rbx
retq
jmp 0x11052b
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x110f18
jmp 0x11053b
jmp 0x1104fe
movq %rax, %rbx
jmp 0x11053b
jmp 0x110521
jmp 0x110521
jmp 0x11050f
jmp 0x110521
jmp 0x11050f
jmp 0x110521
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x10e5b8
jmp 0x110545
movq %rax, %rbx
jmp 0x110545
movq %rax, %rbx
jmp 0x11054f
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
callq 0x1113e2
leaq 0x28(%rsp), %rdi
callq 0x11151c
leaq 0x8(%rsp), %rdi
callq 0x111532
leaq 0x48(%rsp), %rdi
callq 0x10e5b8
movq %rbx, %rdi
callq 0x10e310