// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1d8, %rsp            # imm = 0x1D8
xorpd %xmm0, %xmm0
movapd %xmm0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
leaq -0x1f8(%rbp), %rdi
movl $0x18, %edx
callq 0x2260
leaq -0x58(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x1f8(%rbp), %rbx
leaq -0x68(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21f0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x43b6
movq -0x68(%rbp), %r15
movb (%r15), %al
leal -0x30(%rax), %ecx
cmpb $0xa, %cl
jb 0x4251
cmpb $0x2d, %al
jne 0x4299
cmpq $0x2, -0x60(%rbp)
jb 0x4299
callq 0x2050
movq %rax, %r13
movl (%rax), %r12d
movl $0x0, (%rax)
movq %r15, %rdi
leaq -0x70(%rbp), %rsi
callq 0x2150
cmpq %r15, -0x70(%rbp)
je 0x4430
movl (%r13), %eax
testl %eax, %eax
je 0x428a
cmpl $0x22, %eax
jne 0x428e
jmp 0x443c
movl %r12d, (%r13)
leaq -0x40(%rbp), %rdi
callq 0x45ce
jmp 0x421a
movq -0x40(%rbp), %rax
movsd (%rax), %xmm1
movq 0x8(%rax), %rcx
movq %rcx, -0x40(%rbp)
movl -0x30(%rbp), %eax
leal -0x1(%rax), %edx
movl %edx, -0x30(%rbp)
movzbl (%r15), %edx
leal -0x2a(%rdx), %esi
cmpl $0x5, %esi
ja 0x42d7
leaq 0xe7f(%rip), %rdi       # 0x5144
movslq (%rdi,%rsi,4), %rdx
addq %rdi, %rdx
jmpq *%rdx
mulsd (%rcx), %xmm1
jmp 0x437a
cmpl $0x5e, %edx
jne 0x42f8
movsd (%rcx), %xmm0
movq 0x8(%rcx), %rcx
movq %rcx, -0x40(%rbp)
addl $-0x2, %eax
movl %eax, -0x30(%rbp)
callq 0x22a0
jmp 0x43a0
movsd %xmm1, -0x48(%rbp)
movq %r14, %rdi
leaq 0xe73(%rip), %rsi       # 0x517a
callq 0x2080
testl %eax, %eax
je 0x438a
movq %r14, %rdi
leaq 0xe64(%rip), %rsi       # 0x517e
callq 0x2080
testl %eax, %eax
je 0x4396
movq %r14, %rdi
leaq 0xe55(%rip), %rsi       # 0x5182
callq 0x2080
testl %eax, %eax
jne 0x421a
movsd -0x48(%rbp), %xmm0
callq 0x20f0
jmp 0x43a0
movsd (%rcx), %xmm0
movq 0x8(%rcx), %rcx
movq %rcx, -0x40(%rbp)
addl $-0x2, %eax
movl %eax, -0x30(%rbp)
subsd %xmm1, %xmm0
jmp 0x43a0
movsd (%rcx), %xmm0
movq 0x8(%rcx), %rcx
movq %rcx, -0x40(%rbp)
addl $-0x2, %eax
movl %eax, -0x30(%rbp)
divsd %xmm1, %xmm0
jmp 0x43a0
addsd (%rcx), %xmm1
movq 0x8(%rcx), %rcx
movq %rcx, -0x40(%rbp)
addl $-0x2, %eax
movl %eax, -0x30(%rbp)
jmp 0x43a4
movsd -0x48(%rbp), %xmm0
callq 0x2070
jmp 0x43a0
movsd -0x48(%rbp), %xmm0
callq 0x22e0
movapd %xmm0, %xmm1
leaq -0x40(%rbp), %rdi
movapd %xmm1, %xmm0
callq 0x45ce
jmp 0x421a
movq -0x40(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
decl -0x30(%rbp)
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x43e0
callq 0x21a0
movq 0x2bc9(%rip), %rsi      # 0x6fb0
leaq -0x1f8(%rbp), %rdi
callq 0x2140
leaq -0x178(%rbp), %rdi
callq 0x20a0
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x4419
movq 0x8(%rdi), %rbx
callq 0x2200
movq %rbx, %rdi
testq %rbx, %rbx
jne 0x4408
movsd -0x48(%rbp), %xmm0
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc06(%rip), %rdi       # 0x503d
callq 0x2100
leaq 0xbfa(%rip), %rdi       # 0x503d
callq 0x2220
movq %rax, %rbx
jmp 0x4493
jmp 0x445f
movq %rax, %rbx
cmpl $0x0, (%r13)
jne 0x4462
movl %r12d, (%r13)
jmp 0x4462
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x4474
callq 0x21a0
movq 0x2b35(%rip), %rsi      # 0x6fb0
leaq -0x1f8(%rbp), %rdi
callq 0x2140
leaq -0x178(%rbp), %rdi
callq 0x20a0
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x44ad
movq 0x8(%rdi), %r14
callq 0x2200
movq %r14, %rdi
testq %r14, %r14
jne 0x449c
movq %rbx, %rdi
callq 0x22b0
nop