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

    double extra;
    double c[] = {5,6,7,8,9};

    te_variable lookup[] = {
        {"c0", clo0, TE_CLOSURE0, &extra},
        {"c1", clo1, TE_CLOSURE1, &extra},
        {"c2", clo2, TE_CLOSURE2, &extra},
        {"cell", cell, TE_CLOSURE1, c},
    };

    test_case cases[] = {
        {"c0", 6},
        {"c1 4", 8},
        {"c2 (10, 20)", 30},
    };

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

        extra = 0;
        lfequal(te_eval(ex), answer + extra);

        extra = 10;
        lfequal(te_eval(ex), answer + extra);

        te_free(ex);
    }


    test_case cases2[] = {
        {"cell 0", 5},
        {"cell 1", 6},
        {"cell 0 + cell 1", 11},
        {"cell 1 * cell 3 + cell 4", 57},
    };

    for (i = 0; i < sizeof(cases2) / sizeof(test_case); ++i) {
        const char *expr = cases2[i].expr;
        const double answer = cases2[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 $0xd8, %rsp
movaps 0x2bc9(%rip), %xmm0     # 0x8020
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
movapd 0x2bc9(%rip), %xmm0     # 0x8030
movapd %xmm0, 0x10(%rax)
movabsq $0x4022000000000000, %rcx # imm = 0x4022000000000000
movq %rcx, 0x20(%rax)
leaq 0x3245(%rip), %rcx      # 0x86c6
leaq 0x50(%rsp), %rbx
movq %rcx, (%rbx)
leaq -0x94(%rip), %rcx       # 0x53fc
movq %rcx, 0x8(%rbx)
movl $0x10, 0x10(%rbx)
leaq 0x10(%rsp), %rcx
movq %rcx, 0x18(%rbx)
leaq 0x321e(%rip), %rdx      # 0x86c9
movq %rdx, 0x20(%rbx)
leaq -0x9f(%rip), %rdx       # 0x5417
movq %rdx, 0x28(%rbx)
movl $0x11, %edx
movl %edx, 0x30(%rbx)
movq %rcx, 0x38(%rbx)
leaq 0x31ff(%rip), %rsi      # 0x86cc
movq %rsi, 0x40(%rbx)
leaq -0xb3(%rip), %rsi       # 0x5425
movq %rsi, 0x48(%rbx)
movl $0x12, 0x50(%rbx)
movq %rcx, 0x58(%rbx)
leaq 0x31e1(%rip), %rcx      # 0x86cf
movq %rcx, 0x60(%rbx)
leaq -0xc6(%rip), %rcx       # 0x5433
movq %rcx, 0x68(%rbx)
movl %edx, 0x70(%rbx)
movq %rax, 0x78(%rbx)
movl $0x8, %r15d
leaq 0x62ef(%rip), %r14      # 0xb800
leaq 0x2ea3(%rip), %r12      # 0x83bb
movabsq $0x4024000000000000, %r13 # imm = 0x4024000000000000
movq -0x8(%r15,%r14), %rdi
movsd (%r15,%r14), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rsi
movl $0x4, %edx
leaq 0x1c(%rsp), %rcx
callq 0x6af2
movq %rax, %rbp
incl 0x6bb6(%rip)            # 0xc104
testq %rax, %rax
jne 0x556f
incl 0x6baf(%rip)            # 0xc108
leaq 0x2e4d(%rip), %rdi      # 0x83ad
movq %r12, %rsi
movl $0x205, %edx            # imm = 0x205
xorl %eax, %eax
callq 0x3090
movq $0x0, 0x10(%rsp)
incl 0x6b86(%rip)            # 0xc104
movq %rbp, %rdi
callq 0x64f9
movsd 0x10(%rsp), %xmm1
addsd 0x8(%rsp), %xmm1
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
andpd 0x2a6e(%rip), %xmm1     # 0x8010
ucomisd 0x2a96(%rip), %xmm1     # 0x8040
ja 0x55b2
ucomisd %xmm0, %xmm0
jnp 0x55e2
incl 0x6b50(%rip)            # 0xc108
movq %rbp, %rdi
callq 0x64f9
movsd 0x10(%rsp), %xmm1
addsd 0x8(%rsp), %xmm1
leaq 0x2df0(%rip), %rdi      # 0x83c3
movq %r12, %rsi
movl $0x208, %edx            # imm = 0x208
movb $0x2, %al
callq 0x3090
movq %r13, 0x10(%rsp)
incl 0x6b17(%rip)            # 0xc104
movq %rbp, %rdi
callq 0x64f9
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
addsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
andpd 0x29fb(%rip), %xmm1     # 0x8010
ucomisd 0x2a23(%rip), %xmm1     # 0x8040
ja 0x5625
ucomisd %xmm0, %xmm0
jnp 0x5655
incl 0x6add(%rip)            # 0xc108
movq %rbp, %rdi
callq 0x64f9
movsd 0x8(%rsp), %xmm1
addsd 0x10(%rsp), %xmm1
leaq 0x2d7d(%rip), %rdi      # 0x83c3
movq %r12, %rsi
movl $0x20b, %edx            # imm = 0x20B
movb $0x2, %al
callq 0x3090
movq %rbp, %rdi
callq 0x61c7
addq $0x10, %r15
cmpq $0x38, %r15
jne 0x5522
leaq 0x61be(%rip), %r15      # 0xb830
leaq 0x50(%rsp), %rbx
leaq 0x1c(%rsp), %r14
leaq 0x2d38(%rip), %r12      # 0x83bb
xorl %r13d, %r13d
movq (%r13,%r15), %rdi
movsd 0x8(%r13,%r15), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rsi
movl $0x4, %edx
movq %r14, %rcx
callq 0x6af2
movq %rax, %rbp
incl 0x6a53(%rip)            # 0xc104
testq %rax, %rax
jne 0x56d2
incl 0x6a4c(%rip)            # 0xc108
leaq 0x2cea(%rip), %rdi      # 0x83ad
movq %r12, %rsi
movl $0x21e, %edx            # imm = 0x21E
xorl %eax, %eax
callq 0x3090
incl 0x6a2c(%rip)            # 0xc104
movq %rbp, %rdi
callq 0x64f9
movsd 0x8(%rsp), %xmm2
subsd %xmm2, %xmm0
movapd %xmm0, %xmm1
andpd 0x291a(%rip), %xmm1     # 0x8010
ucomisd 0x2942(%rip), %xmm1     # 0x8040
ja 0x5706
ucomisd %xmm0, %xmm0
jnp 0x5730
incl 0x69fc(%rip)            # 0xc108
movq %rbp, %rdi
callq 0x64f9
leaq 0x2ca8(%rip), %rdi      # 0x83c3
movq %r12, %rsi
movl $0x21f, %edx            # imm = 0x21F
movsd 0x8(%rsp), %xmm1
movb $0x2, %al
callq 0x3090
movq %rbp, %rdi
callq 0x61c7
addq $0x10, %r13
cmpq $0x40, %r13
jne 0x5686
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq