// File: /workspace/github_c_makefile_star2_O1/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
movabsq $0x4000000000000000, %rax # imm = 0x4000000000000000
leaq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movabsq $0x4008000000000000, %rax # imm = 0x4008000000000000
leaq 0x10(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x2ec7(%rip), %rax      # 0x8799
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
movq %rcx, 0x8(%rsi)
xorl %eax, %eax
movl %eax, 0x10(%rsi)
movq %rax, 0x18(%rsi)
leaq 0x2e90(%rip), %rcx      # 0x877e
movq %rcx, 0x20(%rsi)
movq %rdx, 0x28(%rsi)
movl %eax, 0x30(%rsi)
movq %rax, 0x38(%rsi)
movl $0x8, %r15d
leaq 0x5fa6(%rip), %rax      # 0xb8b0
movq -0x8(%r15,%rax), %rbp
movq (%r15,%rax), %r12
movq %rbp, %rdi
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x6af2
movq %rax, %r13
movq %r12, %rdi
movq %rbx, %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x6af2
movq %rax, %r14
incl 0x67bc(%rip)            # 0xc104
testq %r13, %r13
jne 0x596d
incl 0x67b5(%rip)            # 0xc108
leaq 0x2a53(%rip), %rdi      # 0x83ad
leaq 0x2a5a(%rip), %rsi      # 0x83bb
movl $0x276, %edx            # imm = 0x276
xorl %eax, %eax
callq 0x3090
incl 0x6791(%rip)            # 0xc104
testq %r14, %r14
jne 0x5998
incl 0x678a(%rip)            # 0xc108
leaq 0x2a28(%rip), %rdi      # 0x83ad
leaq 0x2a2f(%rip), %rsi      # 0x83bb
movl $0x277, %edx            # imm = 0x277
xorl %eax, %eax
callq 0x3090
movq %r13, %rdi
callq 0x64f9
movsd %xmm0, 0x8(%rsp)
movq %r14, %rdi
callq 0x64f9
movsd %xmm0, (%rsp)
movq 0x6616(%rip), %rax      # 0xbfd0
movq (%rax), %rdi
callq 0x3130
movsd (%rsp), %xmm1
movsd 0x8(%rsp), %xmm0
incl 0x6731(%rip)            # 0xc104
movl 0x672f(%rip), %ebx      # 0xc108
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movapd %xmm2, %xmm3
andpd 0x2623(%rip), %xmm3     # 0x8010
ucomisd 0x264b(%rip), %xmm3     # 0x8040
ja 0x59fd
ucomisd %xmm2, %xmm2
jnp 0x5a20
leal 0x1(%rbx), %eax
movl %eax, 0x6702(%rip)      # 0xc108
leaq 0x29b6(%rip), %rdi      # 0x83c3
leaq 0x29a7(%rip), %rsi      # 0x83bb
movl $0x27e, %edx            # imm = 0x27E
movb $0x2, %al
callq 0x3090
cmpl 0x66e2(%rip), %ebx      # 0xc108
je 0x5a3c
leaq 0x2d6c(%rip), %rdi      # 0x879b
movq %rbp, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3090
movq %r13, %rdi
callq 0x61c7
movq %r14, %rdi
callq 0x61c7
addq $0x10, %r15
cmpq $0xc8, %r15
jne 0x5903
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq