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

   const std::string base_expression_string =
      "x := "
      "((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));";

   std::string large_expression_string = "var x := 0;";

   for (std::size_t i = 0; i < 60000; ++i)
   {
      large_expression_string += base_expression_string;
   }

   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);

   compilation_timeout_check compilation_timeout_chck;

   parser_t parser;
   parser.register_compilation_timeout_check(compilation_timeout_chck);

   const auto max_duration = std::chrono::seconds(8);
   const auto timeout_tp   = std::chrono::steady_clock::now() + max_duration;
   compilation_timeout_chck.set_timeout_time(timeout_tp);

   if (!parser.compile(large_expression_string, expression))
   {
      printf("Error: %s\t\n", parser.error().c_str());
      return;
   }
}

// Assembly:
subq $0xc28, %rsp            # imm = 0xC28
leaq 0xc07(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x111660
movq 0x30(%rsp), %rdx
leaq 0x32fd10(%rip), %rsi    # 0x448555
leaq 0xc08(%rsp), %rdi
callq 0x118760
jmp 0x118854
leaq 0xc07(%rsp), %rdi
callq 0x111780
leaq 0xbcf(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x111660
movq 0x28(%rsp), %rdx
leaq 0x32fe96(%rip), %rsi    # 0x448715
leaq 0xbd0(%rsp), %rdi
callq 0x118760
jmp 0x11888e
leaq 0xbcf(%rsp), %rdi
callq 0x111780
movq $0x0, 0xbc0(%rsp)
cmpq $0xea60, 0xbc0(%rsp) # imm = 0xEA60
jae 0x11894d
leaq 0xbd0(%rsp), %rdi
leaq 0xc08(%rsp), %rsi
callq 0x1110b0
jmp 0x1188d0
jmp 0x1188d2
movq 0xbc0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xbc0(%rsp)
jmp 0x1188a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
leaq 0xc07(%rsp), %rdi
callq 0x111780
jmp 0x118e3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
leaq 0xbcf(%rsp), %rdi
callq 0x111780
jmp 0x118e2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
jmp 0x118e20
movabsq $0x3fd41b2f769cf0e0, %rax # imm = 0x3FD41B2F769CF0E0
movq %rax, 0xbb8(%rsp)
movabsq $0x4024000000000000, %rax # imm = 0x4024000000000000
movq %rax, 0xbb0(%rsp)
movq $0x0, 0xba8(%rsp)
leaq 0xba0(%rsp), %rdi
movl $0x1, %esi
callq 0x1190f0
jmp 0x118991
leaq 0xb7f(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x111660
movq 0x20(%rsp), %rdx
leaq 0x330438(%rip), %rsi    # 0x448de7
leaq 0xb80(%rsp), %rdi
callq 0x118760
jmp 0x1189be
leaq 0xba0(%rsp), %rdi
leaq 0xb80(%rsp), %rsi
leaq 0xba8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x119130
jmp 0x1189df
leaq 0xb80(%rsp), %rdi
callq 0x111798
leaq 0xb7f(%rsp), %rdi
callq 0x111780
leaq 0xb57(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x111660
movq 0x18(%rsp), %rdx
leaq 0x32faab(%rip), %rsi    # 0x4484c2
leaq 0xb58(%rsp), %rdi
callq 0x118760
jmp 0x118a26
leaq 0xba0(%rsp), %rdi
leaq 0xb58(%rsp), %rsi
leaq 0xbb8(%rsp), %rdx
callq 0x1191e0
jmp 0x118a45
leaq 0xb58(%rsp), %rdi
callq 0x111798
leaq 0xb57(%rsp), %rdi
callq 0x111780
leaq 0xb2f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x111660
movq 0x10(%rsp), %rdx
leaq 0x330ecb(%rip), %rsi    # 0x449948
leaq 0xb30(%rsp), %rdi
callq 0x118760
jmp 0x118a8c
leaq 0xba0(%rsp), %rdi
leaq 0xb30(%rsp), %rsi
leaq 0xbb0(%rsp), %rdx
callq 0x1191e0
jmp 0x118aab
leaq 0xb30(%rsp), %rdi
callq 0x111798
leaq 0xb2f(%rsp), %rdi
callq 0x111780
leaq 0xba0(%rsp), %rdi
callq 0x1192c0
jmp 0x118ad4
leaq 0xb08(%rsp), %rdi
callq 0x119320
jmp 0x118ae3
leaq 0xb08(%rsp), %rdi
leaq 0xba0(%rsp), %rsi
callq 0x1193d0
jmp 0x118afa
leaq 0xaf0(%rsp), %rdi
callq 0x119480
jmp 0x118b09
leaq 0x78(%rsp), %rdi
movl $0x7f, %esi
callq 0x1194f0
jmp 0x118b1a
leaq 0x1c8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x119620
jmp 0x118b2e
leaq 0x78(%rsp), %rdi
callq 0x119e50
leaq 0x1c8(%rsp), %rdi
leaq 0xaf0(%rsp), %rsi
callq 0x119ec0
jmp 0x118b4f
movq $0x8, 0x70(%rsp)
callq 0x111630
movq %rax, 0x60(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x119ee0
movq %rax, 0x8(%rsp)
jmp 0x118b78
movq 0x8(%rsp), %rax
movq %rax, 0x68(%rsp)
leaq 0xaf0(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x119f30
jmp 0x118b96
leaq 0x1c8(%rsp), %rdi
leaq 0xbd0(%rsp), %rsi
leaq 0xb08(%rsp), %rdx
callq 0x119f50
movb %al, 0x7(%rsp)
jmp 0x118bb9
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0x118d8e
jmp 0x118bc7
leaq 0x40(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x11a7e0
jmp 0x118bdb
leaq 0x40(%rsp), %rdi
callq 0x1110f0
movq %rax, %rsi
leaq 0x32fb32(%rip), %rdi    # 0x448721
xorl %eax, %eax
callq 0x111080
jmp 0x118bf8
leaq 0x40(%rsp), %rdi
callq 0x111798
movl $0x1, 0x3c(%rsp)
jmp 0x118d96
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
jmp 0x118c46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
leaq 0xb80(%rsp), %rdi
callq 0x111798
leaq 0xb7f(%rsp), %rdi
callq 0x111780
jmp 0x118e13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
jmp 0x118c8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
leaq 0xb58(%rsp), %rdi
callq 0x111798
leaq 0xb57(%rsp), %rdi
callq 0x111780
jmp 0x118e13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
jmp 0x118cd8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
leaq 0xb30(%rsp), %rdi
callq 0x111798
leaq 0xb2f(%rsp), %rdi
callq 0x111780
jmp 0x118e13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
jmp 0x118e13
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
jmp 0x118e06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
jmp 0x118df9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x119e50
jmp 0x118df9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
jmp 0x118dec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xbf8(%rsp)
movl %eax, 0xbf4(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x111798
jmp 0x118dec
movl $0x0, 0x3c(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0x11a8a0
leaq 0xaf0(%rsp), %rdi
callq 0x11aaa0
leaq 0xb08(%rsp), %rdi
callq 0x11aab0
leaq 0xba0(%rsp), %rdi
callq 0x11aaf0
leaq 0xbd0(%rsp), %rdi
callq 0x111798
leaq 0xc08(%rsp), %rdi
callq 0x111798
addq $0xc28, %rsp            # imm = 0xC28
retq
leaq 0x1c8(%rsp), %rdi
callq 0x11a8a0
leaq 0xaf0(%rsp), %rdi
callq 0x11aaa0
leaq 0xb08(%rsp), %rdi
callq 0x11aab0
leaq 0xba0(%rsp), %rdi
callq 0x11aaf0
leaq 0xbd0(%rsp), %rdi
callq 0x111798
leaq 0xc08(%rsp), %rdi
callq 0x111798
movq 0xbf8(%rsp), %rdi
callq 0x111450
nopw (%rax,%rax)