// File: /workspace/github_c_makefile_star2_O2/codeplea[P]tinyexpr/smoke.c
// Function: test_dynamic
void test_dynamic() {

    double x, f;
    te_variable lookup[] = {
        {"x", &x},
        {"f", &f},
        {"sum0", sum0, TE_FUNCTION0},
        {"sum1", sum1, TE_FUNCTION1},
        {"sum2", sum2, TE_FUNCTION2},
        {"sum3", sum3, TE_FUNCTION3},
        {"sum4", sum4, TE_FUNCTION4},
        {"sum5", sum5, TE_FUNCTION5},
        {"sum6", sum6, TE_FUNCTION6},
        {"sum7", sum7, TE_FUNCTION7},
    };

    test_case cases[] = {
        {"x", 2},
        {"f+x", 7},
        {"x+x", 4},
        {"x+f", 7},
        {"f+f", 10},
        {"f+sum0", 11},
        {"sum0+sum0", 12},
        {"sum0()+sum0", 12},
        {"sum0+sum0()", 12},
        {"sum0()+(0)+sum0()", 12},
        {"sum1 sum0", 12},
        {"sum1(sum0)", 12},
        {"sum1 f", 10},
        {"sum1 x", 4},
        {"sum2 (sum0, x)", 8},
        {"sum3 (sum0, x, 2)", 10},
        {"sum2(2,3)", 5},
        {"sum3(2,3,4)", 9},
        {"sum4(2,3,4,5)", 14},
        {"sum5(2,3,4,5,6)", 20},
        {"sum6(2,3,4,5,6,7)", 27},
        {"sum7(2,3,4,5,6,7,8)", 35},
    };

    x = 2;
    f = 5;

    int i;
    for (i = 0; i < sizeof(cases) / sizeof(test_case); ++i) {
        const char *expr = cases[i].expr;
        const double answer = cases[i].answer;

        int err;
        te_expr *ex = te_compile(expr, lookup, sizeof(lookup)/sizeof(te_variable), &err);
        lok(ex);
        lfequal(te_eval(ex), answer);
        te_free(ex);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
leaq 0x332a(%rip), %rax      # 0x8597
leaq 0x20(%rsp), %rbx
movq %rax, (%rbx)
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rbx)
andl $0x0, 0x10(%rbx)
andq $0x0, 0x18(%rbx)
leaq 0x33bc(%rip), %rcx      # 0x864a
movq %rcx, 0x20(%rbx)
leaq 0x10(%rsp), %rcx
movq %rcx, 0x28(%rbx)
andl $0x0, 0x30(%rbx)
andq $0x0, 0x38(%rbx)
leaq 0x338a(%rip), %rdx      # 0x8635
movq %rdx, 0x40(%rbx)
leaq -0xc9(%rip), %rdx       # 0x51ed
movq %rdx, 0x48(%rbx)
movl $0x8, 0x50(%rbx)
andq $0x0, 0x58(%rbx)
leaq 0x32f5(%rip), %rdx      # 0x85c2
movq %rdx, 0x60(%rbx)
leaq -0xe2(%rip), %rdx       # 0x51f6
movq %rdx, 0x68(%rbx)
movl $0x9, 0x70(%rbx)
andq $0x0, 0x78(%rbx)
leaq 0x32d8(%rip), %rdx      # 0x85c7
movq %rdx, 0x80(%rbx)
leaq -0x102(%rip), %rdx      # 0x51fb
movq %rdx, 0x88(%rbx)
movl $0xa, 0x90(%rbx)
andq $0x0, 0x98(%rbx)
leaq 0x32af(%rip), %rdx      # 0x85cc
movq %rdx, 0xa0(%rbx)
leaq -0x12b(%rip), %rdx      # 0x5200
movq %rdx, 0xa8(%rbx)
movl $0xb, 0xb0(%rbx)
andq $0x0, 0xb8(%rbx)
leaq 0x3286(%rip), %rdx      # 0x85d1
movq %rdx, 0xc0(%rbx)
leaq -0x150(%rip), %rdx      # 0x5209
movq %rdx, 0xc8(%rbx)
movl $0xc, 0xd0(%rbx)
andq $0x0, 0xd8(%rbx)
leaq 0x325d(%rip), %rdx      # 0x85d6
movq %rdx, 0xe0(%rbx)
leaq -0x171(%rip), %rdx      # 0x5216
movq %rdx, 0xe8(%rbx)
movl $0xd, 0xf0(%rbx)
andq $0x0, 0xf8(%rbx)
leaq 0x3234(%rip), %rdx      # 0x85db
movq %rdx, 0x100(%rbx)
leaq -0x18e(%rip), %rdx      # 0x5227
movq %rdx, 0x108(%rbx)
movl $0xe, 0x110(%rbx)
andq $0x0, 0x118(%rbx)
leaq 0x320b(%rip), %rdx      # 0x85e0
movq %rdx, 0x120(%rbx)
leaq -0x1a7(%rip), %rdx      # 0x523c
movq %rdx, 0x128(%rbx)
movl $0xf, 0x130(%rbx)
andq $0x0, 0x138(%rbx)
movabsq $0x4000000000000000, %rdx # imm = 0x4000000000000000
movq %rdx, (%rax)
movabsq $0x4014000000000000, %rax # imm = 0x4014000000000000
movq %rax, (%rcx)
pushq $0x8
popq %r13
leaq 0x627f(%rip), %r12      # 0xb6a0
pushq $0xa
popq %rbp
leaq 0xc(%rsp), %r14
cmpq $0x168, %r13            # imm = 0x168
je 0x5503
movq -0x8(%r13,%r12), %rdi
movsd (%r13,%r12), %xmm0
movsd %xmm0, (%rsp)
movq %rbx, %rsi
movl %ebp, %edx
movq %r14, %rcx
callq 0x6b26
movq %rax, %r15
movl 0x6c9f(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x6c97(%rip)      # 0xc0fc
testq %r15, %r15
jne 0x5490
incl 0x6c90(%rip)            # 0xc100
leaq 0x2f3e(%rip), %rdi      # 0x83b5
leaq 0x2f45(%rip), %rsi      # 0x83c3
movl $0x1d3, %edx            # imm = 0x1D3
xorl %eax, %eax
callq 0x3090
movl 0x6c6c(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x6c64(%rip)      # 0xc0fc
movq %r15, %rdi
callq 0x652d
movsd (%rsp), %xmm2
subsd %xmm2, %xmm0
movapd %xmm0, %xmm1
andpd 0x2b5b(%rip), %xmm1     # 0x8010
ucomisd 0x2b83(%rip), %xmm1     # 0x8040
ja 0x54c5
ucomisd %xmm0, %xmm0
jnp 0x54f2
incl 0x6c35(%rip)            # 0xc100
movq %r15, %rdi
callq 0x652d
leaq 0x2ef1(%rip), %rdi      # 0x83cb
leaq 0x2ee2(%rip), %rsi      # 0x83c3
movl $0x1d4, %edx            # imm = 0x1D4
movsd (%rsp), %xmm1
movb $0x2, %al
callq 0x3090
movq %r15, %rdi
callq 0x6224
addq $0x10, %r13
jmp 0x5429
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq