// File: /workspace/github_cpp_makefile_star2_O1/ArashPartow[P]exprtk/exprtk_simple_example_23.cpp
// Function: void real_1d_discrete_fourier_transform<double>()
void real_1d_discrete_fourier_transform()
{
   typedef exprtk::symbol_table<T>         symbol_table_t;
   typedef exprtk::expression<T>           expression_t;
   typedef exprtk::parser<T>               parser_t;
   typedef exprtk::function_compositor<T>  compositor_t;
   typedef typename compositor_t::function function_t;

   const T sampling_rate = 1024.0;            // ~1KHz
   const T N             = 8 * sampling_rate; // 8 seconds worth of samples

   std::vector<T> input (static_cast<std::size_t>(N),0.0);
   std::vector<T> output(static_cast<std::size_t>(N),0.0);

   exprtk::rtl::io::println<T> println;

   symbol_table_t symbol_table;
   symbol_table.add_vector   ("input"        , input        );
   symbol_table.add_vector   ("output"       , output       );
   symbol_table.add_function ("println"      , println      );
   symbol_table.add_constant ("N"            , N            );
   symbol_table.add_constant ("sampling_rate", sampling_rate);
   symbol_table.add_pi();

   compositor_t compositor(symbol_table);
   compositor.load_vectors(true);

   compositor.add(
      function_t("dft_1d_real")
      .var("N")
      .expression
      (
         " for (var k := 0; k < N; k += 1)        "
         " {                                      "
         "    var k_real := 0.0;                  "
         "    var k_imag := 0.0;                  "
         "                                        "
         "    for (var i := 0; i < N; i += 1)     "
         "    {                                   "
         "       var theta := 2pi * k * i / N;    "
         "       k_real += input[i] * cos(theta); "
         "       k_imag -= input[i] * sin(theta); "
         "    };                                  "
         "                                        "
         "    output[k] := hypot(k_real,k_imag);  "
         " }                                      "
      ));

   const std::string dft_program =
      "                                                                          "
      " /*                                                                       "
      "    Generate an aggregate waveform comprised of three                     "
      "    sine waves of varying frequencies and amplitudes.                     "
      " */                                                                       "
      " const var num_waves := 3;                                                "
      "                                                                          "
      " var frequencies[num_waves] := { 111.125, 222.250, 333.375 }; /* Hz    */ "
      " var amplitudes [num_waves] := {  11.111,  22.222,  33.333 }; /* Power */ "
      "                                                                          "
      " for (var i := 0; i < N; i += 1)                                          "
      " {                                                                        "
      "    var time := i / sampling_rate;                                        "
      "                                                                          "
      "    for (var j := 0; j < frequencies[]; j += 1)                           "
      "    {                                                                     "
      "       var frequency := frequencies[j];                                   "
      "       var amplitude := amplitudes [j];                                   "
      "       var theta     := 2 * pi * frequency * time;                        "
      "                                                                          "
      "       input[i] += amplitude * sin(theta);                                "
      "    }                                                                     "
      " };                                                                       "
      "                                                                          "
      " dft_1d_real(input[]);                                                    "
      "                                                                          "
      " var freq_bin_size   := sampling_rate / N;                                "
      " var max_bin         := ceil(N / 2);                                      "
      " var max_noise_level := 1e-6;                                             "
      "                                                                          "
      " /* Normalise amplitudes */                                               "
      " output /= max_bin;                                                       "
      "                                                                          "
      " println('1D Real DFT Frequencies');                                      "
      "                                                                          "
      " for (var k := 0; k < max_bin; k += 1)                                    "
      " {                                                                        "
      "    if (output[k] > max_noise_level)                                      "
      "    {                                                                     "
      "       var freq_begin := k * freq_bin_size;                               "
      "       var freq_end   := freq_begin + freq_bin_size;                      "
      "                                                                          "
      "       println('Index: ', k,' ',                                          "
      "               'Freq. range: [', freq_begin, 'Hz, ', freq_end, 'Hz) ',    "
      "               'Amplitude: ', output[k]);                                 "
      "    }                                                                     "
      " }                                                                        "
      "                                                                          ";

   expression_t expression;
   expression.register_symbol_table(symbol_table);

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

   expression.value();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1568, %rsp           # imm = 0x1568
movabsq $0x4090000000000000, %rax # imm = 0x4090000000000000
movq %rax, 0x98(%rsp)
movabsq $0x40c0000000000000, %rax # imm = 0x40C0000000000000
movq %rax, 0x90(%rsp)
xorl %ebx, %ebx
movq %rbx, 0x80(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movl $0x10000, %edi          # imm = 0x10000
callq 0x1190c0
movq %rax, 0x70(%rsp)
movq %rax, 0x78(%rsp)
leaq 0x10000(%rax), %r14
movq %r14, 0x80(%rsp)
movl $0x10000, %edx          # imm = 0x10000
movq %rax, %rdi
xorl %esi, %esi
callq 0x119150
movq %r14, 0x78(%rsp)
movq %rbx, 0x60(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movl $0x10000, %edi          # imm = 0x10000
callq 0x1190c0
movq %rax, 0x50(%rsp)
movq %rax, 0x58(%rsp)
movq %rax, %rbx
addq $0x10000, %rbx          # imm = 0x10000
movq %rbx, 0x60(%rsp)
movl $0x10000, %edx          # imm = 0x10000
movq %rax, %rdi
xorl %esi, %esi
callq 0x119150
movq %rbx, 0x58(%rsp)
leaq 0x268(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1b92ea(%rip), %rsi    # 0x2d58dd
leaq 0x1b92e9(%rip), %rdx    # 0x2d58e3
leaq 0x258(%rsp), %rdi
callq 0x11ce48
leaq 0xa0(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0x11cff0
movq 0x258(%rsp), %rdi
cmpq %r14, %rdi
je 0x11c639
movq 0x268(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x8(%rsp), %rdi
movl $0x1, %esi
callq 0x11d0f8
leaq 0x258(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1b928a(%rip), %rsi    # 0x2d58e4
leaq 0x1b9288(%rip), %rdx    # 0x2d58e9
callq 0x11ce48
leaq 0x8(%rsp), %rdi
leaq 0x258(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x11d140
movq 0x258(%rsp), %rdi
cmpq %r14, %rdi
je 0x11c69a
movq 0x268(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x258(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1b923e(%rip), %rsi    # 0x2d58ea
leaq 0x1b923d(%rip), %rdx    # 0x2d58f0
callq 0x11ce48
leaq 0x8(%rsp), %rdi
leaq 0x258(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x11d140
movq 0x258(%rsp), %rdi
cmpq %r14, %rdi
je 0x11c6ec
movq 0x268(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x258(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1b91f3(%rip), %rsi    # 0x2d58f1
leaq 0x1b91f3(%rip), %rdx    # 0x2d58f8
callq 0x11ce48
leaq 0x8(%rsp), %rdi
leaq 0x258(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0x11d258
movq 0x258(%rsp), %rdi
cmpq %r14, %rdi
je 0x11c741
movq 0x268(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x258(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1ba912(%rip), %rsi    # 0x2d7065
leaq 0x1ba90c(%rip), %rdx    # 0x2d7066
callq 0x11ce48
leaq 0x8(%rsp), %rdi
leaq 0x258(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0x11d3e2
movq 0x258(%rsp), %rdi
cmpq %r14, %rdi
je 0x11c796
movq 0x268(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x258(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x1b9151(%rip), %rsi    # 0x2d58f9
leaq 0x1b9157(%rip), %rdx    # 0x2d5906
callq 0x11ce48
leaq 0x8(%rsp), %rdi
leaq 0x258(%rsp), %rsi
leaq 0x98(%rsp), %rdx
callq 0x11d3e2
movq 0x258(%rsp), %rdi
cmpq %r14, %rdi
je 0x11c7eb
movq 0x268(%rsp), %rsi
incq %rsi
callq 0x119090
movb 0x32d607(%rip), %al     # 0x449df8
testb %al, %al
je 0x11cc75
leaq 0x258(%rsp), %rsi
movq %r14, (%rsi)
movw $0x6970, 0x10(%rsi)     # imm = 0x6970
movq $0x2, 0x8(%rsi)
movb $0x0, 0x12(%rsi)
leaq 0x32d5d3(%rip), %rdx    # 0x449df0
leaq 0x8(%rsp), %rdi
callq 0x11d3e2
movq 0x258(%rsp), %rdi
cmpq %r14, %rdi
je 0x11c844
movq 0x268(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x258(%rsp), %rdi
leaq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x11d52c
movb $0x1, 0xc39(%rsp)
leaq 0x118(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x1b9093(%rip), %rsi    # 0x2d5907
leaq 0x1b9097(%rip), %rdx    # 0x2d5912
leaq 0x108(%rsp), %rdi
callq 0x11ce48
leaq 0xc40(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x11d6b4
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x1ba7b8(%rip), %rsi    # 0x2d7065
leaq 0x1ba7b2(%rip), %rdx    # 0x2d7066
leaq 0x10(%rsp), %rdi
callq 0x11ce48
leaq 0xc80(%rsp), %r14
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x12c8a8
leaq 0x40(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1b9030(%rip), %rsi    # 0x2d5913
leaq 0x1b9259(%rip), %rdx    # 0x2d5b43
leaq 0x30(%rsp), %rdi
callq 0x11ce48
leaq 0xc60(%rsp), %r12
leaq 0x30(%rsp), %rsi
movq %r12, %rdi
callq 0x119520
leaq 0xb88(%rsp), %r15
leaq 0xc40(%rsp), %rsi
movq %r15, %rdi
callq 0x124b0a
leaq 0xb90(%rsp), %rcx
cmpq %rax, %rcx
jne 0x11c9db
leaq 0x258(%rsp), %rdi
leaq 0xc40(%rsp), %rsi
movq %r12, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x123868
testb %al, %al
je 0x11c9db
leaq 0xc40(%rsp), %rsi
movq 0x88(%rsi), %rax
movq %rax, %rcx
subq 0x68(%rsi), %rcx
shrq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
movq 0x60(%rsi), %rax
movq 0x70(%rsi), %rdx
subq 0x78(%rsi), %rdx
subq 0x50(%rsi), %rax
sarq $0x5, %rdx
sarq $0x5, %rax
leaq (%rcx,%rcx,2), %rcx
shlq $0x8, %rcx
addq 0xbb8(%rsp), %rcx
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
addq %rdx, %rdi
addq %rcx, %rdi
callq 0x12473a
movq (%rax), %r12
leaq 0xc40(%rsp), %rsi
movq %r15, %rdi
callq 0x124a8e
movq %r12, %rdi
movq %rax, %rsi
callq 0x1247b6
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
je 0x11c9f2
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %r15
cmpq %r15, %rdi
je 0x11ca0e
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x119090
movq %r14, %rdi
callq 0x12cb42
leaq 0xc70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11ca37
movq 0xc70(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0xc50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11ca58
movq 0xc50(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x108(%rsp), %rdi
cmpq %r13, %rdi
je 0x11ca75
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x10(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x1b90c0(%rip), %rsi    # 0x2d5b44
leaq 0x1b9e99(%rip), %rdx    # 0x2d6924
callq 0x11ce48
leaq 0x30(%rsp), %rdi
callq 0x11d78e
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %rax
subq %rcx, %rax
je 0x11caf6
sarq $0x3, %rax
cmpq $0x1, %rax
movq %rax, %rsi
adcq $0x0, %rsi
cmpq %rbx, %rcx
je 0x11cb05
movq 0x8(%rsp), %rdx
cmpq (%rcx), %rdx
je 0x11cb05
addq $0x8, %rcx
movl $0x1, %edi
subq %rsi, %rdi
xorl %esi, %esi
cmpq %rsi, %rdi
je 0x11caf6
decq %rsi
cmpq %rbx, %rcx
je 0x11caee
leaq 0x8(%rcx), %r8
cmpq (%rcx), %rdx
movq %r8, %rcx
jne 0x11cad5
negq %rsi
cmpq %rax, %rsi
jb 0x11cb05
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x12cdb4
leaq 0x108(%rsp), %rdi
movl $0x7f, %esi
callq 0x11d828
leaq 0xc40(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x11d928
leaq 0x208(%rsp), %rdi
callq 0x12cf9a
leaq 0x1d8(%rsp), %rdi
callq 0x12cf9a
leaq 0x1a8(%rsp), %rdi
callq 0x12cf9a
leaq 0x178(%rsp), %rdi
callq 0x12cf9a
leaq 0x148(%rsp), %rdi
callq 0x12cf9a
leaq 0x118(%rsp), %rdi
callq 0x12cf9a
leaq 0xc40(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x11e14c
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
leaq 0xc40(%rsp), %rdi
callq 0x11eb1e
leaq 0x30(%rsp), %rdi
callq 0x11ede0
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x11cbce
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x258(%rsp), %rdi
callq 0x11ee2e
leaq 0x8(%rsp), %rdi
callq 0x11ee90
leaq 0xf8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11cc06
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x2c2f13(%rip), %rax    # 0x3dfb20
leaq 0xd0(%rsp), %rcx
movq %rax, -0x30(%rcx)
movq -0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0x11cc32
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x11cc49
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x119090
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x11cc63
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x119090
addq $0x1568, %rsp           # imm = 0x1568
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1195ec
jmp 0x11c7f9
jmp 0x11cc96
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x11e104
jmp 0x11cd60
movq %rax, %rbx
jmp 0x11cd60
movq %rax, %rbx
jmp 0x11cd6a
jmp 0x11ccc2
jmp 0x11ccaa
movq %rax, %rbx
jmp 0x11cd9a
movq %rax, %rbx
jmp 0x11cdb6
movq %rax, %rbx
jmp 0x11cdc3
movq %rax, %rbx
jmp 0x11cde0
jmp 0x11cd07
jmp 0x11ccde
jmp 0x11ccde
jmp 0x11cd07
jmp 0x11ccde
jmp 0x11cd07
jmp 0x11ccde
jmp 0x11cd07
jmp 0x11ccde
jmp 0x11cd07
movq %rax, %rbx
movq 0x258(%rsp), %rdi
cmpq %r14, %rdi
je 0x11cded
movq 0x268(%rsp), %rsi
incq %rsi
callq 0x119090
jmp 0x11cded
movq %rax, %rbx
jmp 0x11cded
movq %rax, %rbx
jmp 0x11cdf7
movq %rax, %rbx
movq 0x258(%rsp), %rdi
cmpq %r14, %rdi
je 0x11ce04
movq 0x268(%rsp), %rsi
incq %rsi
callq 0x119090
jmp 0x11ce04
movq %rax, %rbx
jmp 0x11ce04
movq %rax, %rbx
jmp 0x11ce1b
movq %rax, %rbx
leaq 0xc40(%rsp), %rdi
callq 0x11eb1e
leaq 0x30(%rsp), %rdi
callq 0x11ede0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x11cde0
movq 0x20(%rsp), %rsi
jmp 0x11cdd8
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
je 0x11cd9a
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x119090
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x11cdb6
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0xc40(%rsp), %rdi
callq 0x11d74e
movq 0x108(%rsp), %rdi
cmpq %r13, %rdi
je 0x11cde0
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x119090
leaq 0x258(%rsp), %rdi
callq 0x11ee2e
leaq 0x8(%rsp), %rdi
callq 0x11ee90
leaq 0xa0(%rsp), %rdi
callq 0x11ef26
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x11ce1b
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x119090
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x11ce35
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x119090
movq %rbx, %rdi
callq 0x1192e0