// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
leaq 0x18(%rsp), %rax
leaq 0x2d97(%rip), %rcx      # 0x87a1
leaq 0x20(%rsp), %rdi
movq %rcx, (%rdi)
movq %rax, 0x8(%rdi)
andl $0x0, 0x10(%rdi)
andq $0x0, 0x18(%rdi)
movabsq $0x4000000000000000, %rcx # imm = 0x4000000000000000
leaq 0x10(%rsp), %rdx
leaq 0x2d51(%rip), %rsi      # 0x8786
movq %rsi, 0x20(%rdi)
movq %rdx, 0x28(%rdi)
andl $0x0, 0x30(%rdi)
movq %rcx, (%rax)
andq $0x0, 0x38(%rdi)
movabsq $0x4008000000000000, %rax # imm = 0x4008000000000000
movq %rax, (%rdx)
pushq $0x8
popq %rbp
cmpq $0xc8, %rbp
je 0x5bc9
leaq 0x5e43(%rip), %rax      # 0xb8b0
movq -0x8(%rbp,%rax), %r13
movq (%rbp,%rax), %r12
movq %r13, %rdi
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
pushq $0x2
popq %r15
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x6b26
movq %rax, %r14
movq %r12, %rdi
movq %rbx, %rsi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x6b26
movq %rax, %r15
movl 0x6650(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x6648(%rip)      # 0xc0fc
testq %r14, %r14
jne 0x5adf
incl 0x6641(%rip)            # 0xc100
leaq 0x28ef(%rip), %rdi      # 0x83b5
leaq 0x28f6(%rip), %rsi      # 0x83c3
movl $0x276, %edx            # imm = 0x276
xorl %eax, %eax
callq 0x3090
movl 0x661d(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x6615(%rip)      # 0xc0fc
testq %r15, %r15
jne 0x5b0c
incl 0x660e(%rip)            # 0xc100
leaq 0x28bc(%rip), %rdi      # 0x83b5
leaq 0x28c3(%rip), %rsi      # 0x83c3
movl $0x277, %edx            # imm = 0x277
xorl %eax, %eax
callq 0x3090
movq %r14, %rdi
callq 0x652d
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
callq 0x652d
movsd %xmm0, (%rsp)
movq 0x64a2(%rip), %rax      # 0xbfd0
movq (%rax), %rdi
callq 0x3120
movsd (%rsp), %xmm1
movsd 0x8(%rsp), %xmm0
incl 0x65b5(%rip)            # 0xc0fc
movl 0x65b3(%rip), %ebx      # 0xc100
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movapd %xmm2, %xmm3
andpd 0x24af(%rip), %xmm3     # 0x8010
ucomisd 0x24d7(%rip), %xmm3     # 0x8040
ja 0x5b71
ucomisd %xmm2, %xmm2
jnp 0x5bb0
leal 0x1(%rbx), %eax
movl %eax, 0x6586(%rip)      # 0xc100
leaq 0x284a(%rip), %rdi      # 0x83cb
leaq 0x283b(%rip), %rsi      # 0x83c3
movl $0x27e, %edx            # imm = 0x27E
movb $0x2, %al
callq 0x3090
cmpl 0x6566(%rip), %ebx      # 0xc100
je 0x5bb0
leaq 0x2c00(%rip), %rdi      # 0x87a3
movq %r13, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3090
movq %r14, %rdi
callq 0x6224
movq %r15, %rdi
callq 0x6224
addq $0x10, %rbp
jmp 0x5a59
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq