// File: /workspace/github_cpp_makefile_star2_O3/xzebra[P]function-plotter/mathParser/mathParser.cpp
// Function: Parser::Solve(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
double Parser::Solve(const std::string postfix) {
    Stack<double> operandStack = Stack<double>();
    std::stringstream ss(postfix);
    std::string token;
    
    while(ss >> token) { // iterate through each token in string    
        if(isNum(token[0]) || token.length() > 1 && token[0] == '-') { //starts with -  
            // if number push to stack
            operandStack.push(std::stod(token));
        } else { // is operator -> solve that operation
            double y = operandStack.pop();
            // push result to stack      
            switch (token[0]) {
                case '+':    
                    operandStack.push(operandStack.pop() + y);
                    continue;
                case '-':
                    operandStack.push(operandStack.pop() - y);
                    continue;
                case '*':
                    operandStack.push(operandStack.pop() * y);
                    continue;
                case '/':
                    operandStack.push(operandStack.pop() / y);
                    continue;
                case '^':
                    operandStack.push(std::pow(operandStack.pop(), y));
                    continue;
            }
            if(token == "sin") {               
                operandStack.push(std::sin(y));
            } else if(token == "cos") {
                operandStack.push(std::cos(y));
            } else if(token == "tan") {
                operandStack.push(std::tan(y));
            }         
        }
    }

    // pop result from stack
    return operandStack.pop();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
leaq -0x1e8(%rbp), %rdi
movl $0x18, %edx
callq 0x2260
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorl %ebx, %ebx
leaq -0x58(%rbp), %r15
leaq -0x1e8(%rbp), %rdi
movq %r15, %rsi
callq 0x21f0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x44ea
movq -0x58(%rbp), %r12
movzbl (%r12), %eax
leal -0x30(%rax), %ecx
cmpb $0xa, %cl
jb 0x42f6
cmpl $0x2d, %eax
jne 0x4357
cmpq $0x2, -0x50(%rbp)
jb 0x4357
callq 0x2050
movq %rax, %r13
movl (%rax), %r14d
movl $0x0, (%rax)
movq %r12, %rdi
leaq -0x60(%rbp), %rsi
callq 0x2150
movsd %xmm0, -0x30(%rbp)
cmpq %r12, -0x60(%rbp)
je 0x4558
movl (%r13), %eax
testl %eax, %eax
je 0x4334
cmpl $0x22, %eax
jne 0x4338
jmp 0x4564
movl %r14d, (%r13)
movl $0x10, %edi
callq 0x21c0
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %rbx, 0x8(%rax)
movq %rax, %rbx
jmp 0x42b8
movsd (%rbx), %xmm1
movq 0x8(%rbx), %rbx
leal -0x2a(%rax), %ecx
cmpl $0x5, %ecx
movsd %xmm1, -0x30(%rbp)
ja 0x43a2
leaq 0xdd1(%rip), %rdx       # 0x5144
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
movsd (%rbx), %xmm0
movsd %xmm0, -0x38(%rbp)
movq 0x8(%rbx), %rbx
movl $0x10, %edi
callq 0x21c0
movsd -0x30(%rbp), %xmm0
mulsd -0x38(%rbp), %xmm0
jmp 0x44cd
cmpl $0x5e, %eax
jne 0x43c8
movsd (%rbx), %xmm0
movq 0x8(%rbx), %rbx
callq 0x22a0
movsd %xmm0, -0x30(%rbp)
movl $0x10, %edi
callq 0x21c0
jmp 0x44c8
movq %r15, %rdi
leaq 0xda8(%rip), %rsi       # 0x517a
callq 0x2080
testl %eax, %eax
je 0x4494
movq %r15, %rdi
leaq 0xd95(%rip), %rsi       # 0x517e
callq 0x2080
testl %eax, %eax
je 0x44af
movq %r15, %rdi
leaq 0xd82(%rip), %rsi       # 0x5182
callq 0x2080
testl %eax, %eax
jne 0x42b8
movsd -0x30(%rbp), %xmm0
callq 0x20f0
movsd %xmm0, -0x30(%rbp)
movl $0x10, %edi
callq 0x21c0
jmp 0x44c8
movsd (%rbx), %xmm0
movsd %xmm0, -0x38(%rbp)
movq 0x8(%rbx), %rbx
movl $0x10, %edi
callq 0x21c0
movsd -0x38(%rbp), %xmm0
subsd -0x30(%rbp), %xmm0
jmp 0x44cd
movsd (%rbx), %xmm0
movsd %xmm0, -0x38(%rbp)
movq 0x8(%rbx), %rbx
movl $0x10, %edi
callq 0x21c0
movsd -0x38(%rbp), %xmm0
divsd -0x30(%rbp), %xmm0
jmp 0x44cd
movsd (%rbx), %xmm0
movsd %xmm0, -0x38(%rbp)
movq 0x8(%rbx), %rbx
movl $0x10, %edi
callq 0x21c0
movsd -0x30(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
jmp 0x44cd
movsd -0x30(%rbp), %xmm0
callq 0x2070
movsd %xmm0, -0x30(%rbp)
movl $0x10, %edi
callq 0x21c0
jmp 0x44c8
movsd -0x30(%rbp), %xmm0
callq 0x22e0
movsd %xmm0, -0x30(%rbp)
movl $0x10, %edi
callq 0x21c0
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax)
testq %rbx, %rbx
jne 0x434b
movq $0x0, 0x8(%rax)
movq %rax, %rbx
jmp 0x42b8
movsd (%rbx), %xmm0
movsd %xmm0, -0x30(%rbp)
movq 0x8(%rbx), %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x4509
callq 0x21a0
movq 0x2aa0(%rip), %rsi      # 0x6fb0
leaq -0x1e8(%rbp), %rdi
callq 0x2140
leaq -0x168(%rbp), %rdi
callq 0x20a0
testq %rbx, %rbx
je 0x4541
movq 0x8(%rbx), %r14
movq %rbx, %rdi
callq 0x2200
movq %r14, %rbx
testq %r14, %r14
jne 0x452d
movsd -0x30(%rbp), %xmm0
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xade(%rip), %rdi       # 0x503d
callq 0x2100
leaq 0xad2(%rip), %rdi       # 0x503d
callq 0x2220
jmp 0x4582
movq %rax, %r15
cmpl $0x0, (%r13)
jne 0x4585
movl %r14d, (%r13)
jmp 0x4585
movq %rax, %r15
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x4597
callq 0x21a0
movq 0x2a12(%rip), %rsi      # 0x6fb0
leaq -0x1e8(%rbp), %rdi
callq 0x2140
leaq -0x168(%rbp), %rdi
callq 0x20a0
testq %rbx, %rbx
je 0x45cf
movq 0x8(%rbx), %r14
movq %rbx, %rdi
callq 0x2200
movq %r14, %rbx
testq %r14, %r14
jne 0x45bb
movq %r15, %rdi
callq 0x22b0
nop