// File: /workspace/github_c_makefile_star2_O0/codeplea[P]tinyexpr/smoke.c
// Function: test_pow
void test_pow() {
#ifdef TE_POW_FROM_RIGHT
    test_equ cases[] = {
        {"2^3^4", "2^(3^4)"},
        {"-2^2", "-(2^2)"},
        {"--2^2", "(2^2)"},
        {"---2^2", "-(2^2)"},
        {"-(2*1)^2", "-(2^2)"},
        {"-2^2", "-4"},
        {"2^1.1^1.2^1.3", "2^(1.1^(1.2^1.3))"},
        {"-a^b", "-(a^b)"},
        {"-a^-b", "-(a^-b)"},
        {"1^0", "1"},
        {"(1)^0", "1"},
        {"-(2)^2", "-(2^2)"}
        /* TODO POW FROM RIGHT IS STILL BUGGY
        {"(-2)^2", "4"},
        {"(-1)^0", "1"},
        {"(-5)^0", "1"},
        {"-2^-3^-4", "-(2^(-(3^-4)))"}*/
    };
#else
    test_equ cases[] = {
        {"2^3^4", "(2^3)^4"},
        {"-2^2", "(-2)^2"},
        {"(-2)^2", "4"},
        {"--2^2", "2^2"},
        {"---2^2", "(-2)^2"},
        {"-2^2", "4"},
        {"2^1.1^1.2^1.3", "((2^1.1)^1.2)^1.3"},
        {"-a^b", "(-a)^b"},
        {"-a^-b", "(-a)^(-b)"},
        {"1^0", "1"},
        {"(1)^0", "1"},
        {"(-1)^0", "1"},
        {"(-5)^0", "1"},
        {"-2^-3^-4", "((-2)^(-3))^(-4)"}
    };
#endif

    double a = 2, b = 3;

    te_variable lookup[] = {
        {"a", &a},
        {"b", &b}
    };

    int i;
    for (i = 0; i < sizeof(cases) / sizeof(test_equ); ++i) {
        const char *expr1 = cases[i].expr1;
        const char *expr2 = cases[i].expr2;

        te_expr *ex1 = te_compile(expr1, lookup, sizeof(lookup)/sizeof(te_variable), 0);
        te_expr *ex2 = te_compile(expr2, lookup, sizeof(lookup)/sizeof(te_variable), 0);

        lok(ex1);
        lok(ex2);

        double r1 = te_eval(ex1);
        double r2 = te_eval(ex2);

        fflush(stdout);
        const int olfail = lfails;
        lfequal(r1, r2);
        if (olfail != lfails) {
            printf("Failed expression: %s <> %s\n", expr1, expr2);
        }

        te_free(ex1);
        te_free(ex2);
    }

}

// Assembly:
subq $0x168, %rsp            # imm = 0x168
leaq 0xa0(%rsp), %rdi
leaq 0x76ea(%rip), %rsi      # 0xe8b0
movl $0xc0, %edx
callq 0x30e0
movsd 0x3e40(%rip), %xmm0     # 0xb018
movsd %xmm0, 0x98(%rsp)
movsd 0x3e37(%rip), %xmm0     # 0xb020
movsd %xmm0, 0x90(%rsp)
leaq 0x45a0(%rip), %rax      # 0xb799
movq %rax, 0x50(%rsp)
leaq 0x98(%rsp), %rax
movq %rax, 0x58(%rsp)
movl $0x0, 0x60(%rsp)
movq $0x0, 0x68(%rsp)
leaq 0x455b(%rip), %rax      # 0xb77e
movq %rax, 0x70(%rsp)
leaq 0x90(%rsp), %rax
movq %rax, 0x78(%rsp)
movl $0x0, 0x80(%rsp)
movq $0x0, 0x88(%rsp)
movl $0x0, 0x4c(%rsp)
movslq 0x4c(%rsp), %rax
cmpq $0xc, %rax
jae 0x7466
movslq 0x4c(%rsp), %rcx
leaq 0xa0(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, 0x40(%rsp)
movslq 0x4c(%rsp), %rcx
leaq 0xa0(%rsp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl $0x2, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x8ff0
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movl $0x2, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x8ff0
movq %rax, 0x28(%rsp)
movl 0x7e20(%rip), %eax      # 0xf0fc
addl $0x1, %eax
movl %eax, 0x7e17(%rip)      # 0xf0fc
cmpq $0x0, 0x30(%rsp)
jne 0x7316
movl 0x7e0d(%rip), %eax      # 0xf100
addl $0x1, %eax
movl %eax, 0x7e04(%rip)      # 0xf100
leaq 0x40aa(%rip), %rdi      # 0xb3ad
leaq 0x40b1(%rip), %rsi      # 0xb3bb
movl $0x276, %edx            # imm = 0x276
movb $0x0, %al
callq 0x3080
jmp 0x7318
jmp 0x731a
movl 0x7ddc(%rip), %eax      # 0xf0fc
addl $0x1, %eax
movl %eax, 0x7dd3(%rip)      # 0xf0fc
cmpq $0x0, 0x28(%rsp)
jne 0x735a
movl 0x7dc9(%rip), %eax      # 0xf100
addl $0x1, %eax
movl %eax, 0x7dc0(%rip)      # 0xf100
leaq 0x4066(%rip), %rdi      # 0xb3ad
leaq 0x406d(%rip), %rsi      # 0xb3bb
movl $0x277, %edx            # imm = 0x277
movb $0x0, %al
callq 0x3080
jmp 0x735c
movq 0x30(%rsp), %rdi
callq 0x8450
movsd %xmm0, 0x20(%rsp)
movq 0x28(%rsp), %rdi
callq 0x8450
movsd %xmm0, 0x18(%rsp)
movq 0x7c4d(%rip), %rax      # 0xefd0
movq (%rax), %rdi
callq 0x3120
movl 0x7d6f(%rip), %eax      # 0xf100
movl %eax, 0x14(%rsp)
movl 0x7d61(%rip), %eax      # 0xf0fc
addl $0x1, %eax
movl %eax, 0x7d58(%rip)      # 0xf0fc
movsd 0x20(%rsp), %xmm0
subsd 0x18(%rsp), %xmm0
movaps 0x3cc9(%rip), %xmm1     # 0xb080
pand %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd 0x8(%rsp), %xmm0
movsd 0x3c39(%rip), %xmm1     # 0xb008
ucomisd %xmm1, %xmm0
ja 0x73e7
movsd 0x8(%rsp), %xmm0
ucomisd 0x8(%rsp), %xmm0
jne 0x73e7
jp 0x73e7
jmp 0x741c
movl 0x7d13(%rip), %eax      # 0xf100
addl $0x1, %eax
movl %eax, 0x7d0a(%rip)      # 0xf100
movsd 0x20(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
leaq 0x3fba(%rip), %rdi      # 0xb3c3
leaq 0x3fab(%rip), %rsi      # 0xb3bb
movl $0x27e, %edx            # imm = 0x27E
movb $0x2, %al
callq 0x3080
jmp 0x741e
movl 0x14(%rsp), %eax
cmpl 0x7cd8(%rip), %eax      # 0xf100
je 0x7442
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %rdx
leaq 0x4360(%rip), %rdi      # 0xb79b
movb $0x0, %al
callq 0x3080
movq 0x30(%rsp), %rdi
callq 0x7e40
movq 0x28(%rsp), %rdi
callq 0x7e40
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x7254
addq $0x168, %rsp            # imm = 0x168
retq
nop