// File: DCTewi[P]Truthtable-Calculator/functions.cpp
// Function: toReverseNotation(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
std::string toReverseNotation(const std::string &expr)
{
    if (!isLegal(expr))
    {
        throw std::overflow_error("Illegal Expression!");
    }

    // Result
    std::string res;
    // Stack of operators, Stack for cache data
    std::stack<char> soper, smid;
    // For every char in expressions
    for (int i = 0; i < static_cast<int>(expr.size()); i++)
    {
        const char &now = expr[i];
        // variables
        if (isalpha(now))
        {
            smid.push(now);
        }
        // operators
        else if (operators.count(now))
        {
            int flag = 0;
            while (!flag)
            {
                // Empty or top with (
                if (soper.empty() || soper.top() == '(')
                {
                    soper.push(now); flag = 1;
                }
                // Higher priority than top
                else if (getPriority(now) > getPriority(soper.top()))
                {
                    soper.push(now); flag = 1;
                }
                // Lower
                else
                {
                    smid.push(soper.top());
                    soper.pop();
                }
            }
        }
        // braces
        else if (now == '(')
        {
            soper.push(now);
        }
        else if (now == ')')
        {
            // pop!!!
            while (soper.size() && soper.top() != '(')
            {
                smid.push(soper.top());
                soper.pop();
            }
            if (soper.top() == '(') soper.pop();
        }
        else
        {
            throw std::overflow_error("Illegal Expression!");
        }
    }
    // Summary
    while (soper.size())
    {
        smid.push(soper.top());
        soper.pop();
    }
    while (smid.size())
    {
        res += smid.top();
        smid.pop();
    }
    std::reverse(res.begin(), res.end());

    return res;
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq %rdi, 0x90(%rsp)
movq %rdi, %rax
movq %rax, 0x98(%rsp)
movq %rdi, 0x180(%rsp)
movq %rsi, 0x178(%rsp)
movq 0x178(%rsp), %rdi
callq 0x28f0
testb $0x1, %al
jne 0x2c02
movl $0x10, %edi
callq 0x20c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x88(%rsp)
leaq 0xa458(%rip), %rsi      # 0xd012
callq 0x2060
jmp 0x2bc1
movq 0x88(%rsp), %rdi
movq 0x103e8(%rip), %rsi     # 0x12fb8
movq 0x103d9(%rip), %rdx     # 0x12fb0
callq 0x22f0
movq 0x88(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
callq 0x2170
jmp 0x314a
movq 0x90(%rsp), %rdi
movb $0x0, 0x16b(%rsp)
callq 0x2270
leaq 0x118(%rsp), %rdi
callq 0x4ad0
jmp 0x2c26
leaq 0xc8(%rsp), %rdi
callq 0x4ad0
jmp 0x2c35
movl $0x0, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
movl %eax, 0x84(%rsp)
movq 0x178(%rsp), %rdi
callq 0x2160
movq %rax, %rcx
movl 0x84(%rsp), %eax
cmpl %ecx, %eax
jge 0x2fe0
movq 0x178(%rsp), %rdi
movslq 0xc4(%rsp), %rsi
callq 0x2220
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rax
movsbl (%rax), %edi
callq 0x22b0
cmpl $0x0, %eax
je 0x2d06
movq 0xb8(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x4b00
jmp 0x2cb6
jmp 0x2fc8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
jmp 0x313d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
jmp 0x3111
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
jmp 0x3104
movq 0xb8(%rsp), %rsi
leaq 0x104cb(%rip), %rdi     # 0x131e0
callq 0x4a70
movq %rax, 0x78(%rsp)
jmp 0x2d21
movq 0x78(%rsp), %rax
cmpq $0x0, %rax
je 0x2e58
movl $0x0, 0xb4(%rsp)
cmpl $0x0, 0xb4(%rsp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2d51
jmp 0x2e53
leaq 0x118(%rsp), %rdi
callq 0x4b30
movb %al, 0x77(%rsp)
jmp 0x2d64
movb 0x77(%rsp), %al
testb $0x1, %al
jne 0x2d8f
jmp 0x2d6e
leaq 0x118(%rsp), %rdi
callq 0x4b50
movq %rax, 0x68(%rsp)
jmp 0x2d82
movq 0x68(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x28, %eax
jne 0x2db6
movq 0xb8(%rsp), %rsi
leaq 0x118(%rsp), %rdi
callq 0x4b00
jmp 0x2da6
movl $0x1, 0xb4(%rsp)
jmp 0x2e4e
movq 0xb8(%rsp), %rdi
callq 0x2ad0
movl %eax, 0x5c(%rsp)
leaq 0x118(%rsp), %rdi
callq 0x4b50
movq %rax, 0x60(%rsp)
jmp 0x2ddb
movq 0x60(%rsp), %rdi
callq 0x2ad0
movl %eax, %ecx
movl 0x5c(%rsp), %eax
cmpl %ecx, %eax
jle 0x2e13
movq 0xb8(%rsp), %rsi
leaq 0x118(%rsp), %rdi
callq 0x4b00
jmp 0x2e06
movl $0x1, 0xb4(%rsp)
jmp 0x2e4c
leaq 0x118(%rsp), %rdi
callq 0x4b50
movq %rax, 0x50(%rsp)
jmp 0x2e27
movq 0x50(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x4b00
jmp 0x2e3b
leaq 0x118(%rsp), %rdi
callq 0x4b60
jmp 0x2e4a
jmp 0x2e4c
jmp 0x2e4e
jmp 0x2d3b
jmp 0x2fc6
movq 0xb8(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x28, %eax
jne 0x2e84
movq 0xb8(%rsp), %rsi
leaq 0x118(%rsp), %rdi
callq 0x4b00
jmp 0x2e7f
jmp 0x2fc4
movq 0xb8(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x29, %eax
jne 0x2f5f
jmp 0x2e9a
leaq 0x118(%rsp), %rdi
callq 0x4b70
movq %rax, 0x48(%rsp)
jmp 0x2eae
movq 0x48(%rsp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, 0x47(%rsp)
je 0x2ee5
leaq 0x118(%rsp), %rdi
callq 0x4b50
movq %rax, 0x38(%rsp)
jmp 0x2ed3
movq 0x38(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x28, %eax
setne %al
movb %al, 0x47(%rsp)
movb 0x47(%rsp), %al
testb $0x1, %al
jne 0x2eef
jmp 0x2f2b
leaq 0x118(%rsp), %rdi
callq 0x4b50
movq %rax, 0x30(%rsp)
jmp 0x2f03
movq 0x30(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x4b00
jmp 0x2f17
leaq 0x118(%rsp), %rdi
callq 0x4b60
jmp 0x2f26
jmp 0x2e9a
leaq 0x118(%rsp), %rdi
callq 0x4b50
movq %rax, 0x28(%rsp)
jmp 0x2f3f
movq 0x28(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x28, %eax
jne 0x2f5d
leaq 0x118(%rsp), %rdi
callq 0x4b60
jmp 0x2f5b
jmp 0x2f5d
jmp 0x2fc2
movl $0x10, %edi
callq 0x20c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x20(%rsp)
leaq 0xa097(%rip), %rsi      # 0xd012
callq 0x2060
jmp 0x2f82
movq 0x20(%rsp), %rdi
movq 0x1002a(%rip), %rsi     # 0x12fb8
movq 0x1001b(%rip), %rdx     # 0x12fb0
callq 0x22f0
jmp 0x3157
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x170(%rsp)
movl %eax, 0x16c(%rsp)
callq 0x2170
jmp 0x3104
jmp 0x2fc4
jmp 0x2fc6
jmp 0x2fc8
jmp 0x2fca
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
jmp 0x2c40
jmp 0x2fe2
leaq 0x118(%rsp), %rdi
callq 0x4b70
movq %rax, 0x18(%rsp)
jmp 0x2ff6
movq 0x18(%rsp), %rax
cmpq $0x0, %rax
je 0x303a
leaq 0x118(%rsp), %rdi
callq 0x4b50
movq %rax, 0x10(%rsp)
jmp 0x3015
movq 0x10(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x4b00
jmp 0x3029
leaq 0x118(%rsp), %rdi
callq 0x4b60
jmp 0x3038
jmp 0x2fe2
jmp 0x303c
leaq 0xc8(%rsp), %rdi
callq 0x4b70
movq %rax, 0x8(%rsp)
jmp 0x3050
movq 0x8(%rsp), %rax
cmpq $0x0, %rax
je 0x3095
leaq 0xc8(%rsp), %rdi
callq 0x4b50
movq %rax, (%rsp)
jmp 0x306e
movq 0x90(%rsp), %rdi
movq (%rsp), %rax
movsbl (%rax), %esi
callq 0x2140
jmp 0x3084
leaq 0xc8(%rsp), %rdi
callq 0x4b60
jmp 0x3093
jmp 0x303c
movq 0x90(%rsp), %rdi
callq 0x2190
movq 0x90(%rsp), %rdi
movq %rax, 0xa8(%rsp)
callq 0x2100
movq %rax, 0xa0(%rsp)
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
callq 0x4b80
jmp 0x30d6
movb $0x1, 0x16b(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x4bc0
leaq 0x118(%rsp), %rdi
callq 0x4bc0
testb $0x1, 0x16b(%rsp)
jne 0x312d
jmp 0x3120
leaq 0xc8(%rsp), %rdi
callq 0x4bc0
leaq 0x118(%rsp), %rdi
callq 0x4bc0
jmp 0x313d
movq 0x90(%rsp), %rdi
callq 0x2130
movq 0x98(%rsp), %rax
addq $0x188, %rsp            # imm = 0x188
retq
movq 0x90(%rsp), %rdi
callq 0x2130
movq 0x170(%rsp), %rdi
callq 0x2310
nopw (%rax,%rax)