// File: /workspace/github_c_makefile_star2_O3/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 0x331e(%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 0x33b0(%rip), %rdx      # 0x8642
movq %rdx, 0x20(%rbx)
leaq 0x10(%rsp), %rdx
movq %rdx, 0x28(%rbx)
movl %ecx, 0x30(%rbx)
movq %rcx, 0x38(%rbx)
leaq 0x3380(%rip), %rsi      # 0x862d
movq %rsi, 0x40(%rbx)
leaq -0xc7(%rip), %rsi       # 0x51f1
movq %rsi, 0x48(%rbx)
movl $0x8, 0x50(%rbx)
movq %rcx, 0x58(%rbx)
leaq 0x32ec(%rip), %rsi      # 0x85ba
movq %rsi, 0x60(%rbx)
leaq -0xdf(%rip), %rsi       # 0x51fa
movq %rsi, 0x68(%rbx)
movl $0x9, 0x70(%rbx)
movq %rcx, 0x78(%rbx)
leaq 0x32d0(%rip), %rsi      # 0x85bf
movq %rsi, 0x80(%rbx)
leaq -0xfe(%rip), %rsi       # 0x51ff
movq %rsi, 0x88(%rbx)
movl $0xa, 0x90(%rbx)
movq %rcx, 0x98(%rbx)
leaq 0x32a8(%rip), %rsi      # 0x85c4
movq %rsi, 0xa0(%rbx)
leaq -0x126(%rip), %rsi      # 0x5204
movq %rsi, 0xa8(%rbx)
movl $0xb, 0xb0(%rbx)
movq %rcx, 0xb8(%rbx)
leaq 0x3280(%rip), %rsi      # 0x85c9
movq %rsi, 0xc0(%rbx)
leaq -0x14a(%rip), %rsi      # 0x520d
movq %rsi, 0xc8(%rbx)
movl $0xc, 0xd0(%rbx)
movq %rcx, 0xd8(%rbx)
leaq 0x3258(%rip), %rsi      # 0x85ce
movq %rsi, 0xe0(%rbx)
leaq -0x16a(%rip), %rsi      # 0x521a
movq %rsi, 0xe8(%rbx)
movl $0xd, 0xf0(%rbx)
movq %rcx, 0xf8(%rbx)
leaq 0x3230(%rip), %rsi      # 0x85d3
movq %rsi, 0x100(%rbx)
leaq -0x186(%rip), %rsi      # 0x522b
movq %rsi, 0x108(%rbx)
movl $0xe, 0x110(%rbx)
movq %rcx, 0x118(%rbx)
leaq 0x3208(%rip), %rsi      # 0x85d8
movq %rsi, 0x120(%rbx)
leaq -0x19e(%rip), %rsi      # 0x5240
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 0x6283(%rip), %r13      # 0xb6a0
leaq 0xc(%rsp), %r14
leaq 0x2f92(%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 0x6c46
movq %rax, %rbp
movl 0x6caa(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x6ca2(%rip)      # 0xc0fc
testq %rbp, %rbp
jne 0x5481
incl 0x6c9b(%rip)            # 0xc100
leaq 0x2f41(%rip), %rdi      # 0x83ad
movq %r12, %rsi
movl $0x1d3, %edx            # imm = 0x1D3
xorl %eax, %eax
callq 0x3090
movl 0x6c7b(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x6c73(%rip)      # 0xc0fc
movq %rbp, %rdi
callq 0x664d
movsd (%rsp), %xmm2
subsd %xmm2, %xmm0
movapd %xmm0, %xmm1
andpd 0x2b6a(%rip), %xmm1     # 0x8010
ucomisd 0x2b92(%rip), %xmm1     # 0x8040
ja 0x54b6
ucomisd %xmm0, %xmm0
jnp 0x54df
incl 0x6c44(%rip)            # 0xc100
movq %rbp, %rdi
callq 0x664d
leaq 0x2ef8(%rip), %rdi      # 0x83c3
movq %r12, %rsi
movl $0x1d4, %edx            # imm = 0x1D4
movsd (%rsp), %xmm1
movb $0x2, %al
callq 0x3090
movq %rbp, %rdi
callq 0x632f
addq $0x10, %r15
cmpq $0x168, %r15            # imm = 0x168
jne 0x5429
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq