// File: /workspace/github_c_makefile_star2_O3/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 0x2abb(%rip), %xmm0     # 0x8020
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
movapd 0x2abb(%rip), %xmm0     # 0x8030
movapd %xmm0, 0x10(%rax)
movabsq $0x4022000000000000, %rcx # imm = 0x4022000000000000
movq %rcx, 0x20(%rax)
leaq 0x3137(%rip), %rcx      # 0x86c6
leaq 0x50(%rsp), %rbx
movq %rcx, (%rbx)
leaq -0x94(%rip), %rcx       # 0x550a
movq %rcx, 0x8(%rbx)
movl $0x10, 0x10(%rbx)
leaq 0x10(%rsp), %rcx
movq %rcx, 0x18(%rbx)
leaq 0x3110(%rip), %rdx      # 0x86c9
movq %rdx, 0x20(%rbx)
leaq -0x9f(%rip), %rdx       # 0x5525
movq %rdx, 0x28(%rbx)
movl $0x11, %edx
movl %edx, 0x30(%rbx)
movq %rcx, 0x38(%rbx)
leaq 0x30f1(%rip), %rsi      # 0x86cc
movq %rsi, 0x40(%rbx)
leaq -0xb3(%rip), %rsi       # 0x5533
movq %rsi, 0x48(%rbx)
movl $0x12, 0x50(%rbx)
movq %rcx, 0x58(%rbx)
leaq 0x30d3(%rip), %rcx      # 0x86cf
movq %rcx, 0x60(%rbx)
leaq -0xc6(%rip), %rcx       # 0x5541
movq %rcx, 0x68(%rbx)
movl %edx, 0x70(%rbx)
movq %rax, 0x78(%rbx)
movl $0x8, %r15d
leaq 0x61e1(%rip), %r14      # 0xb800
leaq 0x2d95(%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 0x6c46
movq %rax, %rbp
movl 0x6aa0(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x6a98(%rip)      # 0xc0fc
testq %rbp, %rbp
jne 0x568b
incl 0x6a91(%rip)            # 0xc100
leaq 0x2d37(%rip), %rdi      # 0x83ad
movq %r12, %rsi
movl $0x205, %edx            # imm = 0x205
xorl %eax, %eax
callq 0x3090
movl 0x6a71(%rip), %eax      # 0xc0fc
movq $0x0, 0x10(%rsp)
incl %eax
movl %eax, 0x6a60(%rip)      # 0xc0fc
movq %rbp, %rdi
callq 0x664d
movsd 0x10(%rsp), %xmm1
addsd 0x8(%rsp), %xmm1
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
andpd 0x2950(%rip), %xmm1     # 0x8010
ucomisd 0x2978(%rip), %xmm1     # 0x8040
ja 0x56d0
ucomisd %xmm0, %xmm0
jnp 0x5700
incl 0x6a2a(%rip)            # 0xc100
movq %rbp, %rdi
callq 0x664d
movsd 0x10(%rsp), %xmm1
addsd 0x8(%rsp), %xmm1
leaq 0x2cd2(%rip), %rdi      # 0x83c3
movq %r12, %rsi
movl $0x208, %edx            # imm = 0x208
movb $0x2, %al
callq 0x3090
movq %r13, 0x10(%rsp)
incl 0x69f1(%rip)            # 0xc0fc
movq %rbp, %rdi
callq 0x664d
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
addsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
andpd 0x28dd(%rip), %xmm1     # 0x8010
ucomisd 0x2905(%rip), %xmm1     # 0x8040
ja 0x5743
ucomisd %xmm0, %xmm0
jnp 0x5773
incl 0x69b7(%rip)            # 0xc100
movq %rbp, %rdi
callq 0x664d
movsd 0x8(%rsp), %xmm1
addsd 0x10(%rsp), %xmm1
leaq 0x2c5f(%rip), %rdi      # 0x83c3
movq %r12, %rsi
movl $0x20b, %edx            # imm = 0x20B
movb $0x2, %al
callq 0x3090
movq %rbp, %rdi
callq 0x632f
addq $0x10, %r15
cmpq $0x38, %r15
jne 0x5630
leaq 0x60a0(%rip), %r15      # 0xb830
leaq 0x50(%rsp), %rbx
leaq 0x1c(%rsp), %r14
leaq 0x2c1a(%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 0x6c46
movq %rax, %rbp
movl 0x692d(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x6925(%rip)      # 0xc0fc
testq %rbp, %rbp
jne 0x57fe
incl 0x691e(%rip)            # 0xc100
leaq 0x2bc4(%rip), %rdi      # 0x83ad
movq %r12, %rsi
movl $0x21e, %edx            # imm = 0x21E
xorl %eax, %eax
callq 0x3090
movl 0x68fe(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x68f6(%rip)      # 0xc0fc
movq %rbp, %rdi
callq 0x664d
movsd 0x8(%rsp), %xmm2
subsd %xmm2, %xmm0
movapd %xmm0, %xmm1
andpd 0x27ec(%rip), %xmm1     # 0x8010
ucomisd 0x2814(%rip), %xmm1     # 0x8040
ja 0x5834
ucomisd %xmm0, %xmm0
jnp 0x585e
incl 0x68c6(%rip)            # 0xc100
movq %rbp, %rdi
callq 0x664d
leaq 0x2b7a(%rip), %rdi      # 0x83c3
movq %r12, %rsi
movl $0x21f, %edx            # imm = 0x21F
movsd 0x8(%rsp), %xmm1
movb $0x2, %al
callq 0x3090
movq %rbp, %rdi
callq 0x632f
addq $0x10, %r13
cmpq $0x40, %r13
jne 0x57a4
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq