// File: /workspace/github_c_makefile_star2_O1/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 0x341c(%rip), %rax      # 0x858f
leaq 0x20(%rsp), %rbx
movq %rax, (%rbx)
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rbx)
xorl %ecx, %ecx
movl %ecx, 0x10(%rbx)
movq %rcx, 0x18(%rbx)
leaq 0x34ae(%rip), %rdx      # 0x8642
movq %rdx, 0x20(%rbx)
leaq 0x10(%rsp), %rdx
movq %rdx, 0x28(%rbx)
movl %ecx, 0x30(%rbx)
movq %rcx, 0x38(%rbx)
leaq 0x347e(%rip), %rsi      # 0x862d
movq %rsi, 0x40(%rbx)
leaq -0xc7(%rip), %rsi       # 0x50f3
movq %rsi, 0x48(%rbx)
movl $0x8, 0x50(%rbx)
movq %rcx, 0x58(%rbx)
leaq 0x33ea(%rip), %rsi      # 0x85ba
movq %rsi, 0x60(%rbx)
leaq -0xdf(%rip), %rsi       # 0x50fc
movq %rsi, 0x68(%rbx)
movl $0x9, 0x70(%rbx)
movq %rcx, 0x78(%rbx)
leaq 0x33ce(%rip), %rsi      # 0x85bf
movq %rsi, 0x80(%rbx)
leaq -0xfe(%rip), %rsi       # 0x5101
movq %rsi, 0x88(%rbx)
movl $0xa, 0x90(%rbx)
movq %rcx, 0x98(%rbx)
leaq 0x33a6(%rip), %rsi      # 0x85c4
movq %rsi, 0xa0(%rbx)
leaq -0x126(%rip), %rsi      # 0x5106
movq %rsi, 0xa8(%rbx)
movl $0xb, 0xb0(%rbx)
movq %rcx, 0xb8(%rbx)
leaq 0x337e(%rip), %rsi      # 0x85c9
movq %rsi, 0xc0(%rbx)
leaq -0x14a(%rip), %rsi      # 0x510f
movq %rsi, 0xc8(%rbx)
movl $0xc, 0xd0(%rbx)
movq %rcx, 0xd8(%rbx)
leaq 0x3356(%rip), %rsi      # 0x85ce
movq %rsi, 0xe0(%rbx)
leaq -0x16a(%rip), %rsi      # 0x511c
movq %rsi, 0xe8(%rbx)
movl $0xd, 0xf0(%rbx)
movq %rcx, 0xf8(%rbx)
leaq 0x332e(%rip), %rsi      # 0x85d3
movq %rsi, 0x100(%rbx)
leaq -0x186(%rip), %rsi      # 0x512d
movq %rsi, 0x108(%rbx)
movl $0xe, 0x110(%rbx)
movq %rcx, 0x118(%rbx)
leaq 0x3306(%rip), %rsi      # 0x85d8
movq %rsi, 0x120(%rbx)
leaq -0x19e(%rip), %rsi      # 0x5142
movq %rsi, 0x128(%rbx)
movl $0xf, 0x130(%rbx)
movq %rcx, 0x138(%rbx)
movabsq $0x4000000000000000, %rcx # imm = 0x4000000000000000
movq %rcx, (%rax)
movabsq $0x4014000000000000, %rax # imm = 0x4014000000000000
movq %rax, (%rdx)
movl $0x8, %r15d
leaq 0x6381(%rip), %r13      # 0xb6a0
leaq 0xc(%rsp), %r14
leaq 0x3090(%rip), %r12      # 0x83bb
movq -0x8(%r15,%r13), %rdi
movsd (%r15,%r13), %xmm0
movsd %xmm0, (%rsp)
movq %rbx, %rsi
movl $0xa, %edx
movq %r14, %rcx
callq 0x6af2
movq %rax, %rbp
incl 0x6db0(%rip)            # 0xc104
testq %rax, %rax
jne 0x5375
incl 0x6da9(%rip)            # 0xc108
leaq 0x3047(%rip), %rdi      # 0x83ad
movq %r12, %rsi
movl $0x1d3, %edx            # imm = 0x1D3
xorl %eax, %eax
callq 0x3090
incl 0x6d89(%rip)            # 0xc104
movq %rbp, %rdi
callq 0x64f9
movsd (%rsp), %xmm2
subsd %xmm2, %xmm0
movapd %xmm0, %xmm1
andpd 0x2c78(%rip), %xmm1     # 0x8010
ucomisd 0x2ca0(%rip), %xmm1     # 0x8040
ja 0x53a8
ucomisd %xmm0, %xmm0
jnp 0x53d1
incl 0x6d5a(%rip)            # 0xc108
movq %rbp, %rdi
callq 0x64f9
leaq 0x3006(%rip), %rdi      # 0x83c3
movq %r12, %rsi
movl $0x1d4, %edx            # imm = 0x1D4
movsd (%rsp), %xmm1
movb $0x2, %al
callq 0x3090
movq %rbp, %rdi
callq 0x61c7
addq $0x10, %r15
cmpq $0x168, %r15            # imm = 0x168
jne 0x532b
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq