// File: /workspace/github_c_makefile_star2_O2/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 0x2ab0(%rip), %xmm0     # 0x8020
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
movapd 0x2ab0(%rip), %xmm0     # 0x8030
movapd %xmm0, 0x10(%rax)
movabsq $0x4022000000000000, %rcx # imm = 0x4022000000000000
movq %rcx, 0x20(%rax)
leaq 0x3134(%rip), %rcx      # 0x86ce
leaq 0x50(%rsp), %rbx
movq %rcx, (%rbx)
leaq -0x94(%rip), %rcx       # 0x5515
movq %rcx, 0x8(%rbx)
movl $0x10, 0x10(%rbx)
leaq 0x10(%rsp), %rcx
movq %rcx, 0x18(%rbx)
leaq 0x310d(%rip), %rdx      # 0x86d1
movq %rdx, 0x20(%rbx)
leaq -0x9f(%rip), %rdx       # 0x5530
movq %rdx, 0x28(%rbx)
pushq $0x11
popq %rdx
movl %edx, 0x30(%rbx)
movq %rcx, 0x38(%rbx)
leaq 0x30f0(%rip), %rsi      # 0x86d4
movq %rsi, 0x40(%rbx)
leaq -0xb1(%rip), %rsi       # 0x553e
movq %rsi, 0x48(%rbx)
movl $0x12, 0x50(%rbx)
movq %rcx, 0x58(%rbx)
leaq 0x30d2(%rip), %rcx      # 0x86d7
movq %rcx, 0x60(%rbx)
leaq -0xc4(%rip), %rcx       # 0x554c
movq %rcx, 0x68(%rbx)
movl %edx, 0x70(%rbx)
movq %rax, 0x78(%rbx)
pushq $0x8
popq %rbp
leaq 0x61db(%rip), %r14      # 0xb800
leaq 0x2d97(%rip), %r12      # 0x83c3
movabsq $0x4024000000000000, %r13 # imm = 0x4024000000000000
cmpq $0x38, %rbp
je 0x5790
movq -0x8(%rbp,%r14), %rdi
movsd (%rbp,%r14), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rsi
pushq $0x4
popq %rdx
leaq 0x1c(%rsp), %rcx
callq 0x6b26
movq %rax, %r15
movl 0x6a91(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x6a89(%rip)      # 0xc0fc
testq %r15, %r15
jne 0x569a
incl 0x6a82(%rip)            # 0xc100
leaq 0x2d30(%rip), %rdi      # 0x83b5
movq %r12, %rsi
movl $0x205, %edx            # imm = 0x205
xorl %eax, %eax
callq 0x3090
movl 0x6a62(%rip), %eax      # 0xc0fc
andq $0x0, 0x10(%rsp)
incl %eax
movl %eax, 0x6a54(%rip)      # 0xc0fc
movq %r15, %rdi
callq 0x652d
movsd 0x10(%rsp), %xmm1
addsd 0x8(%rsp), %xmm1
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
andpd 0x2944(%rip), %xmm1     # 0x8010
ucomisd 0x296c(%rip), %xmm1     # 0x8040
ja 0x56dc
ucomisd %xmm0, %xmm0
jnp 0x570c
incl 0x6a1e(%rip)            # 0xc100
movq %r15, %rdi
callq 0x652d
movsd 0x10(%rsp), %xmm1
addsd 0x8(%rsp), %xmm1
leaq 0x2cce(%rip), %rdi      # 0x83cb
movq %r12, %rsi
movl $0x208, %edx            # imm = 0x208
movb $0x2, %al
callq 0x3090
movq %r13, 0x10(%rsp)
incl 0x69e5(%rip)            # 0xc0fc
movq %r15, %rdi
callq 0x652d
movsd 0x10(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
addsd %xmm2, %xmm1
subsd %xmm1, %xmm0
movapd %xmm0, %xmm1
andpd 0x28d1(%rip), %xmm1     # 0x8010
ucomisd 0x28f9(%rip), %xmm1     # 0x8040
ja 0x574f
ucomisd %xmm0, %xmm0
jnp 0x577f
incl 0x69ab(%rip)            # 0xc100
movq %r15, %rdi
callq 0x652d
movsd 0x8(%rsp), %xmm1
addsd 0x10(%rsp), %xmm1
leaq 0x2c5b(%rip), %rdi      # 0x83cb
movq %r12, %rsi
movl $0x20b, %edx            # imm = 0x20B
movb $0x2, %al
callq 0x3090
movq %r15, %rdi
callq 0x6224
addq $0x10, %rbp
jmp 0x5636
leaq 0x6099(%rip), %r13      # 0xb830
leaq 0x50(%rsp), %rbx
pushq $0x4
popq %rbp
leaq 0x1c(%rsp), %r14
xorl %r12d, %r12d
cmpq $0x40, %r12
je 0x5880
movq (%r12,%r13), %rdi
movsd 0x8(%r12,%r13), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rsi
movl %ebp, %edx
movq %r14, %rcx
callq 0x6b26
movq %rax, %r15
movl 0x6924(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x691c(%rip)      # 0xc0fc
testq %r15, %r15
jne 0x580b
incl 0x6915(%rip)            # 0xc100
leaq 0x2bc3(%rip), %rdi      # 0x83b5
leaq 0x2bca(%rip), %rsi      # 0x83c3
movl $0x21e, %edx            # imm = 0x21E
xorl %eax, %eax
callq 0x3090
movl 0x68f1(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x68e9(%rip)      # 0xc0fc
movq %r15, %rdi
callq 0x652d
movsd 0x8(%rsp), %xmm2
subsd %xmm2, %xmm0
movapd %xmm0, %xmm1
andpd 0x27df(%rip), %xmm1     # 0x8010
ucomisd 0x2807(%rip), %xmm1     # 0x8040
ja 0x5841
ucomisd %xmm0, %xmm0
jnp 0x586f
incl 0x68b9(%rip)            # 0xc100
movq %r15, %rdi
callq 0x652d
leaq 0x2b75(%rip), %rdi      # 0x83cb
leaq 0x2b66(%rip), %rsi      # 0x83c3
movl $0x21f, %edx            # imm = 0x21F
movsd 0x8(%rsp), %xmm1
movb $0x2, %al
callq 0x3090
movq %r15, %rdi
callq 0x6224
addq $0x10, %r12
jmp 0x57a7
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq