// File: ArashPartow[P]exprtk-extras/exprtk_extract_dependents.cpp
// Function: void extract_expression_dependents<double>()
void extract_expression_dependents()
{
   const std::string expression = "a * sin(3x) + foo(abs(y - z) / w)";

   exprtk::symbol_table<T> symbol_table;

   /*
      Note: Add any functions that are not part of the standard set
            of ExprTk functions
   */
   symbol_table.add_function("foo",[](T /*t*/)->T { return T(0); });

   std::deque<std::string> variable_list;
   std::deque<std::string> function_list;

   if (!exprtk::collect_variables(expression, symbol_table, variable_list))
   {
      printf("Error: Failed to collect variables for expression: %s\n",expression.c_str());
      variable_list.clear();
   }

   if (!exprtk::collect_functions(expression, symbol_table, function_list))
   {
      printf("Error: Failed to collect functions for expression: %s\n",expression.c_str());
      function_list.clear();
   }

   for (const auto& var : variable_list)
   {
      printf("variable: %s\n",var.c_str());
   }

   for (const auto& func : function_list)
   {
      printf("function: %s\n",func.c_str());
   }
}

// Assembly:
subq $0x1c8, %rsp            # imm = 0x1C8
leaq 0x1a7(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x111650
movq 0x18(%rsp), %rdx
leaq 0x336d10(%rip), %rsi    # 0x44f545
leaq 0x1a8(%rsp), %rdi
callq 0x118750
jmp 0x118844
leaq 0x1a7(%rsp), %rdi
callq 0x111770
leaq 0x188(%rsp), %rdi
movl $0x1, %esi
callq 0x118eb0
jmp 0x118865
leaq 0x167(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x111650
movq 0x10(%rsp), %rdx
leaq 0x336ce4(%rip), %rsi    # 0x44f567
leaq 0x168(%rsp), %rdi
callq 0x118750
jmp 0x118892
leaq 0x166(%rsp), %rdi
callq 0x119020
movq %rax, %rdx
leaq 0x188(%rsp), %rdi
leaq 0x168(%rsp), %rsi
callq 0x118ef0
jmp 0x1188b9
leaq 0x168(%rsp), %rdi
callq 0x111788
leaq 0x167(%rsp), %rdi
callq 0x111770
leaq 0x110(%rsp), %rdi
callq 0x119030
jmp 0x1188e2
leaq 0xc0(%rsp), %rdi
callq 0x119030
jmp 0x1188f1
leaq 0x1a8(%rsp), %rdi
leaq 0x188(%rsp), %rsi
leaq 0x110(%rsp), %rdx
callq 0x119040
movb %al, 0xf(%rsp)
jmp 0x118914
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x118a34
jmp 0x118922
leaq 0x1a8(%rsp), %rdi
callq 0x1110f0
movq %rax, %rsi
leaq 0x336c32(%rip), %rdi    # 0x44f56b
xorl %eax, %eax
callq 0x111080
jmp 0x118942
leaq 0x110(%rsp), %rdi
callq 0x1191c0
jmp 0x118a34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x1a7(%rsp), %rdi
callq 0x111770
jmp 0x118bfa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x118bed
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x1189ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x111788
leaq 0x167(%rsp), %rdi
callq 0x111770
jmp 0x118be0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x118be0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
jmp 0x118bd3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x198(%rsp)
movl %eax, 0x194(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x119470
jmp 0x118bd3
leaq 0x1a8(%rsp), %rdi
leaq 0x188(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
callq 0x119200
movb %al, 0xe(%rsp)
jmp 0x118a57
movb 0xe(%rsp), %al
testb $0x1, %al
jne 0x118a8e
jmp 0x118a61
leaq 0x1a8(%rsp), %rdi
callq 0x1110f0
movq %rax, %rsi
leaq 0x336b2a(%rip), %rdi    # 0x44f5a2
xorl %eax, %eax
callq 0x111080
jmp 0x118a81
leaq 0xc0(%rsp), %rdi
callq 0x1191c0
leaq 0x110(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rsi
leaq 0x98(%rsp), %rdi
callq 0x119380
movq 0xb8(%rsp), %rsi
leaq 0x78(%rsp), %rdi
callq 0x1193b0
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x1193e0
testb $0x1, %al
jne 0x118add
jmp 0x118b1d
leaq 0x98(%rsp), %rdi
callq 0x119410
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rdi
callq 0x1110f0
movq %rax, %rsi
leaq 0x336ad6(%rip), %rdi    # 0x44f5d9
xorl %eax, %eax
callq 0x111080
jmp 0x118b0c
jmp 0x118b0e
leaq 0x98(%rsp), %rdi
callq 0x119420
jmp 0x118ac5
leaq 0xc0(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x119380
movq 0x68(%rsp), %rsi
leaq 0x28(%rsp), %rdi
callq 0x1193b0
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x1193e0
testb $0x1, %al
jne 0x118b5d
jmp 0x118b97
leaq 0x48(%rsp), %rdi
callq 0x119410
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
callq 0x1110f0
movq %rax, %rsi
leaq 0x336a67(%rip), %rdi    # 0x44f5e7
xorl %eax, %eax
callq 0x111080
jmp 0x118b89
jmp 0x118b8b
leaq 0x48(%rsp), %rdi
callq 0x119420
jmp 0x118b48
leaq 0xc0(%rsp), %rdi
callq 0x119470
leaq 0x110(%rsp), %rdi
callq 0x119470
leaq 0x188(%rsp), %rdi
callq 0x1194e0
leaq 0x1a8(%rsp), %rdi
callq 0x111788
addq $0x1c8, %rsp            # imm = 0x1C8
retq
leaq 0x110(%rsp), %rdi
callq 0x119470
leaq 0x188(%rsp), %rdi
callq 0x1194e0
leaq 0x1a8(%rsp), %rdi
callq 0x111788
movq 0x198(%rsp), %rdi
callq 0x111450
nopw (%rax,%rax)