// File: /workspace/github_c_makefile_star2_O3/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 0x2d81(%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 0x2d4a(%rip), %rcx      # 0x877e
movq %rcx, 0x20(%rsi)
movq %rdx, 0x28(%rsi)
movl %eax, 0x30(%rsi)
movq %rax, 0x38(%rsi)
movl $0x8, %r15d
leaq 0x5e60(%rip), %rax      # 0xb8b0
movq -0x8(%r15,%rax), %rbp
movq (%r15,%rax), %r13
movq %rbp, %rdi
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x6c46
movq %rax, %r12
movq %r13, %rdi
movq %rbx, %rsi
movl $0x2, %edx
xorl %ecx, %ecx
callq 0x6c46
movq %rax, %r14
movl 0x666e(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x6666(%rip)      # 0xc0fc
testq %r12, %r12
jne 0x5ac1
incl 0x665f(%rip)            # 0xc100
leaq 0x2905(%rip), %rdi      # 0x83ad
leaq 0x290c(%rip), %rsi      # 0x83bb
movl $0x276, %edx            # imm = 0x276
xorl %eax, %eax
callq 0x3090
movl 0x663b(%rip), %eax      # 0xc0fc
incl %eax
movl %eax, 0x6633(%rip)      # 0xc0fc
testq %r14, %r14
jne 0x5aee
incl 0x662c(%rip)            # 0xc100
leaq 0x28d2(%rip), %rdi      # 0x83ad
leaq 0x28d9(%rip), %rsi      # 0x83bb
movl $0x277, %edx            # imm = 0x277
xorl %eax, %eax
callq 0x3090
movq %r12, %rdi
callq 0x664d
movsd %xmm0, 0x8(%rsp)
movq %r14, %rdi
callq 0x664d
movsd %xmm0, (%rsp)
movq 0x64c0(%rip), %rax      # 0xbfd0
movq (%rax), %rdi
callq 0x3120
movsd (%rsp), %xmm1
movsd 0x8(%rsp), %xmm0
incl 0x65d3(%rip)            # 0xc0fc
movl 0x65d1(%rip), %ebx      # 0xc100
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
movapd %xmm2, %xmm3
andpd 0x24cd(%rip), %xmm3     # 0x8010
ucomisd 0x24f5(%rip), %xmm3     # 0x8040
ja 0x5b53
ucomisd %xmm2, %xmm2
jnp 0x5b92
leal 0x1(%rbx), %eax
movl %eax, 0x65a4(%rip)      # 0xc100
leaq 0x2860(%rip), %rdi      # 0x83c3
leaq 0x2851(%rip), %rsi      # 0x83bb
movl $0x27e, %edx            # imm = 0x27E
movb $0x2, %al
callq 0x3090
cmpl 0x6584(%rip), %ebx      # 0xc100
je 0x5b92
leaq 0x2c16(%rip), %rdi      # 0x879b
movq %rbp, %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x3090
movq %r12, %rdi
callq 0x632f
movq %r14, %rdi
callq 0x632f
addq $0x10, %r15
cmpq $0xc8, %r15
jne 0x5a49
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq