// File: /workspace/github_cpp_makefile_star2_O2/havluj[P]spreadsheet/src/CExpressionParser.cpp
// Function: CExpressionParser::Evaluate(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
bool CExpressionParser::Evaluate(const std::vector<std::string>& rpn, std::string& result) {
    typedef std::vector<std::string>::const_iterator rpn_iter;
    std::stack<std::string> stack;

    // While there are input tokens left
    for (rpn_iter it = rpn.begin(); it != rpn.end(); it++) {
	  // Read the next token from input.
	  std::string token = *it;

	  // If the token is a value push it onto the stack.
	  if (IsNumber(token) ||
		    IsFloat(token) ||
		    IsPi(token) ||
		    IsE(token)) {
		if (IsPi(token)) {
		    std::stringstream s;
		    s << pi;
		    token = s.str();
		} else if (IsE(token)) {
		    std::stringstream s;
		    s << e;
		    token = s.str();
		}
		stack.push(token);
	  }// Otherwise, the token is an operator or a function
	  else if (IsOperator(token) || IsFunction(token)) {
		double result = 0.0;

		// It is known a priori that the operator takes n arguments.
		unsigned int nargs = OpArgCount(UpperCase(token));

		bool isUnary = false;
		unsigned int stackArgs = stack.size();
		std::vector<double> args;

		if (stackArgs < nargs) {
		    // For dealing with unary '-' or unary '+'
		    if (stackArgs == 1 && nargs == 2 && (token == "+" || token == "-")) {
			  std::string value = stack.top();
			  result = strtod(value.c_str(), NULL);
			  stack.pop();
			  isUnary = true;
		    } else {
			  // (Error) The user has not input sufficient values in the expression.
			  return false;
		    }
		} else {
		    // Else, Pop the top n values from the stack.				
		    while (nargs > 0) {
			  std::string value = stack.top();
			  double d = strtod(value.c_str(), NULL);
			  args.push_back(d);
			  stack.pop();
			  nargs--;
		    }
		}

		// Evaluate the operator, with the values as arguments.                       
		if (IsOperator(token) && !isUnary) {
		    // Token is an operator: pop top two entries                          
		    double d2 = args[ 0 ];
		    double d1 = args[ 1 ];

		    //Get the result  
		    if (token == "+") {
			  result = d1 + d2;
		    } else if (token == "-") {
			  result = d1 - d2;
		    } else if (token == "*") {
			  result = d1 * d2;
		    } else if (token == "/") {
			  result = d1 / d2;
		    } else if (token == "%") {
			  int i2 = (int) args[ 0 ];
			  int i1 = (int) args[ 1 ];
			  double iresult = Modulo(i1, i2);
			  result = iresult;
		    }
		} else if (IsFunction(token)) {
		    double d0 = args[ 0 ];

		    std::string capToken = UpperCase(token);

		    // If say -SIN( x ) then multiply result of SIN by -1.0
		    double mult =
				token.find("-") != std::string::npos ? -1 : 1;

		    if (capToken.find("SIN") != std::string::npos) {
			  result = sin(d0);
		    } else if (capToken.find("COS") != std::string::npos) {
			  result = cos(d0);
		    } else if (capToken.find("TAN") != std::string::npos) {
			  result = tan(d0);
		    } else if (capToken.find("LN") != std::string::npos) {
			  result = log(d0);
		    } else if (capToken.find("LOG") != std::string::npos) {
			  result = log10(d0);
		    } else if (capToken.find("EXP") != std::string::npos) {
			  result = exp(d0);
		    } else if (capToken.find("^") != std::string::npos) {
			  double d2 = args[ 0 ];
			  double d1 = args[ 1 ];

			  if (d1 < 0) mult = -1.0;

			  result = pow((double) d1, d2);
		    } else if (capToken.find("POW") != std::string::npos) {
			  double d2 = args[ 0 ];
			  double d1 = args[ 1 ];
			  result = pow(d1, d2);
		    } else if (capToken.find("SQRT") != std::string::npos) {
			  result = sqrt(d0);
		    }

		    result *= mult;
		}

		// Push the returned results, if any, back onto the stack
		// Push result onto stack   
		if (result == (long) result) {
		    result = long( result);
		}
		std::stringstream s;
		s << result;
		stack.push(s.str());
	  }
    }

    // If there is only one value in the stack then
    // that value is the result of the calculation.
    if (stack.size() == 1) {
	  result = stack.top();

	  // Output the result
	  double res = strtod(result.c_str(), NULL);
	  if (res == (long) res) {
		long lres = (long) res;
		std::stringstream s;
		s << lres;
		result = s.str();
	  }

	  return true;
    }

    // If there are more values in the stack
    // (Error) The user input has too many values.
    return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2b8, %rsp            # imm = 0x2B8
movq %rdx, %r15
movq %rsi, %r14
leaq 0x60(%rsp), %rdi
callq 0xb5e6
movq (%r14), %r12
leaq 0xb0(%rsp), %rbp
leaq 0xf0(%rsp), %rbx
leaq 0xd0(%rsp), %r13
movq %r15, 0x38(%rsp)
movq %r14, 0x58(%rsp)
cmpq 0x8(%r14), %r12
je 0xad11
movq %rbp, %rdi
movq %r12, %rsi
callq 0x4440
movq %rbp, %rdi
callq 0x9c9f
testb %al, %al
jne 0xa6cf
movq %rbp, %rdi
callq 0x9c2a
testb %al, %al
jne 0xa6cf
movq %rbp, %rdi
callq 0x9a55
testb %al, %al
jne 0xa6cf
movq %rbp, %rdi
callq 0x9aa7
testb %al, %al
je 0xa77c
movq %rbp, %rdi
callq 0x9a55
testb %al, %al
je 0xa70a
movq %rbx, %rdi
callq 0x4220
leaq 0x100(%rsp), %rdi
movsd 0x31cd(%rip), %xmm0     # 0xd8c0
callq 0x44f0
movq %r13, %rdi
leaq 0x108(%rsp), %rsi
callq 0x44e0
jmp 0xa743
movq %rbp, %rdi
callq 0x9aa7
testb %al, %al
je 0xa75e
movq %rbx, %rdi
callq 0x4220
leaq 0x100(%rsp), %rdi
movsd 0x318a(%rip), %xmm0     # 0xd8b8
callq 0x44f0
movq %r13, %rdi
leaq 0x108(%rsp), %rsi
callq 0x44e0
movq %rbp, %rdi
movq %r13, %rsi
callq 0x43b0
movq %r13, %rdi
callq 0x4150
movq %rbx, %rdi
callq 0x4250
leaq 0x60(%rsp), %rdi
movq %rbp, %rsi
callq 0xbb84
movq %rbp, %rdi
callq 0x4150
addq $0x20, %r12
jmp 0xa686
movq %rbp, %rdi
callq 0x9980
testb %al, %al
jne 0xa794
movq %rbp, %rdi
callq 0x9af9
testb %al, %al
je 0xa76b
leaq 0x298(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4440
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9a13
movq %rbx, %rdi
callq 0x978c
movl %eax, %r14d
movq %rbx, %rdi
callq 0x4150
movq %r15, %rdi
callq 0x4150
leaq 0x60(%rsp), %rdi
callq 0xbc62
andq $0x0, 0x50(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movl %r14d, %r15d
movl %r14d, 0x10(%rsp)
movq %rax, 0x8(%rsp)
cmpl %eax, %r14d
ja 0xa86e
subl $0x1, %r15d
jb 0xa911
movq 0x90(%rsp), %rsi
cmpq 0x98(%rsp), %rsi
jne 0xa829
movq 0xa8(%rsp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %rbx, %rdi
callq 0x4440
movq 0xf0(%rsp), %rdi
xorl %esi, %esi
callq 0x4260
movsd %xmm0, 0xd0(%rsp)
leaq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0xb602
leaq 0x60(%rsp), %rdi
callq 0xbe2e
movq %rbx, %rdi
callq 0x4150
jmp 0xa7f9
movl 0x10(%rsp), %r14d
cmpl $0x2, %r14d
movq 0x8(%rsp), %r15
jne 0xadce
cmpl $0x1, %r15d
jne 0xadce
movq %rbp, %rdi
leaq 0x2772(%rip), %rsi      # 0xd008
callq 0xb473
testb %al, %al
jne 0xa8b6
movq %rbp, %rdi
leaq 0x2761(%rip), %rsi      # 0xd00a
callq 0xb473
testb %al, %al
je 0xadce
movq 0x90(%rsp), %rsi
cmpq 0x98(%rsp), %rsi
jne 0xa8dc
movq 0xa8(%rsp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %rbx, %rdi
callq 0x4440
movq 0xf0(%rsp), %rdi
xorl %esi, %esi
callq 0x4260
movapd %xmm0, 0x20(%rsp)
leaq 0x60(%rsp), %rdi
callq 0xbe2e
movq %rbx, %rdi
callq 0x4150
jmp 0xa925
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movl 0x10(%rsp), %r14d
movq 0x8(%rsp), %r15
cmpl %r15d, %r14d
seta %r15b
movq %rbp, %rdi
callq 0x9980
xorb $0x1, %al
orb %r15b, %al
jne 0xa987
movq 0x40(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbp, %rdi
leaq 0x26a9(%rip), %rsi      # 0xd008
callq 0xb473
testb %al, %al
movq 0x38(%rsp), %r15
movq 0x58(%rsp), %r14
je 0xaa2d
movsd 0x10(%rsp), %xmm0
addsd 0x8(%rsp), %xmm0
jmp 0xab34
movq %rbp, %rdi
callq 0x9af9
movq 0x38(%rsp), %r15
movq 0x58(%rsp), %r14
testb %al, %al
je 0xabc5
movq 0x40(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x278(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4440
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9a13
movq %r15, %rdi
callq 0x4150
movq %rbp, %rdi
leaq 0x262a(%rip), %rsi      # 0xd00a
xorl %edx, %edx
callq 0x4640
xorl %ecx, %ecx
cmpq $-0x1, %rax
sete %cl
leaq 0x2e99(%rip), %rax      # 0xd890
movsd (%rax,%rcx,8), %xmm0
movaps %xmm0, 0x10(%rsp)
movq %rbx, %rdi
leaq 0x2ece(%rip), %rsi      # 0xd8d9
xorl %edx, %edx
callq 0x4640
cmpq $-0x1, %rax
je 0xaa75
movsd 0x8(%rsp), %xmm0
callq 0x4080
movq 0x38(%rsp), %r15
jmp 0xabad
movq %rbp, %rdi
leaq 0x25d3(%rip), %rsi      # 0xd00a
callq 0xb473
testb %al, %al
je 0xaa51
movsd 0x8(%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
jmp 0xab34
movq %rbp, %rdi
leaq 0x25b1(%rip), %rsi      # 0xd00c
callq 0xb473
testb %al, %al
je 0xaaa1
movsd 0x10(%rsp), %xmm0
mulsd 0x8(%rsp), %xmm0
jmp 0xab34
movq %rbx, %rdi
leaq 0x2e5e(%rip), %rsi      # 0xd8dd
xorl %edx, %edx
callq 0x4640
cmpq $-0x1, %rax
movq 0x38(%rsp), %r15
je 0xaac2
movsd 0x8(%rsp), %xmm0
callq 0x45e0
jmp 0xabad
movq %rbp, %rdi
leaq 0x2563(%rip), %rsi      # 0xd00e
callq 0xb473
testb %al, %al
je 0xaae9
movsd 0x8(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
jmp 0xab34
movq %rbx, %rdi
leaq 0x2e15(%rip), %rsi      # 0xd8e1
xorl %edx, %edx
callq 0x4640
cmpq $-0x1, %rax
je 0xab3f
movsd 0x8(%rsp), %xmm0
callq 0x41c0
jmp 0xabad
movq %rbp, %rdi
leaq 0x2513(%rip), %rsi      # 0xd006
callq 0xb473
testb %al, %al
je 0xabc5
movq 0x40(%rsp), %rax
movupd (%rax), %xmm0
cvttpd2dq %xmm0, %xmm0
movd %xmm0, %esi
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %ecx
movl %ecx, %eax
cltd
idivl %esi
testl %edx, %edx
cmovel %edx, %esi
testl %ecx, %ecx
movl $0x0, %eax
cmovnsl %eax, %esi
addl %edx, %esi
cvtsi2sd %esi, %xmm0
movapd %xmm0, 0x20(%rsp)
jmp 0xabc5
movq %rbx, %rdi
leaq 0x2d9c(%rip), %rsi      # 0xd8e5
xorl %edx, %edx
callq 0x4640
cmpq $-0x1, %rax
je 0xab63
movsd 0x8(%rsp), %xmm0
callq 0x4290
jmp 0xabad
movq %rbx, %rdi
leaq 0x2d7b(%rip), %rsi      # 0xd8e8
xorl %edx, %edx
callq 0x4640
cmpq $-0x1, %rax
je 0xab87
movsd 0x8(%rsp), %xmm0
callq 0x4190
jmp 0xabad
movq %rbx, %rdi
leaq 0x2d5b(%rip), %rsi      # 0xd8ec
xorl %edx, %edx
callq 0x4640
cmpq $-0x1, %rax
je 0xac3b
movsd 0x8(%rsp), %xmm0
callq 0x45a0
movapd 0x10(%rsp), %xmm1
mulsd %xmm1, %xmm0
movapd %xmm0, 0x20(%rsp)
movq %rbx, %rdi
callq 0x4150
movq %rbx, %rdi
callq 0x4220
movapd 0x20(%rsp), %xmm2
cvttsd2si %xmm2, %rax
cvtsi2sd %rax, %xmm1
movapd %xmm2, %xmm0
cmpeqsd %xmm1, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
leaq 0x100(%rsp), %rdi
callq 0x44f0
movq %r13, %rdi
leaq 0x108(%rsp), %rsi
callq 0x44e0
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0xbfd4
movq %r13, %rdi
callq 0x4150
movq %rbx, %rdi
callq 0x4250
leaq 0x40(%rsp), %rdi
callq 0xbdfa
jmp 0xa76b
movq %rbx, %rdi
leaq 0x2790(%rip), %rsi      # 0xd3d5
xorl %edx, %edx
callq 0x4640
cmpq $-0x1, %rax
je 0xac9d
movq 0x40(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x8(%rax), %xmm0
movapd %xmm0, %xmm4
cmpltsd 0x2c5b(%rip), %xmm4     # 0xd8c8
movapd %xmm4, %xmm2
movsd 0x2c37(%rip), %xmm3     # 0xd8b0
andpd %xmm3, %xmm2
andnpd 0x10(%rsp), %xmm4
orpd %xmm2, %xmm4
movapd %xmm4, 0x20(%rsp)
callq 0x4580
movapd 0x20(%rsp), %xmm1
jmp 0xabb3
movq %rbx, %rdi
leaq 0x2c29(%rip), %rsi      # 0xd8d0
xorl %edx, %edx
callq 0x4640
cmpq $-0x1, %rax
je 0xaccc
movq 0x40(%rsp), %rax
movsd (%rax), %xmm1
movsd 0x8(%rax), %xmm0
callq 0x4580
jmp 0xabad
movq %rbx, %rdi
leaq 0x2c1a(%rip), %rsi      # 0xd8f0
xorl %edx, %edx
callq 0x4640
cmpq $-0x1, %rax
je 0xacfc
movsd 0x8(%rsp), %xmm0
ucomisd 0x2bd7(%rip), %xmm0     # 0xd8c8
jb 0xad07
sqrtsd %xmm0, %xmm0
jmp 0xabad
movapd 0x20(%rsp), %xmm0
jmp 0xabad
callq 0x4280
jmp 0xabad
leaq 0x60(%rsp), %rdi
callq 0xbc62
cmpq $0x1, %rax
jne 0xade5
movq 0x90(%rsp), %rsi
cmpq 0x98(%rsp), %rsi
jne 0xad48
movq 0xa8(%rsp), %rax
movl $0x200, %esi            # imm = 0x200
addq -0x8(%rax), %rsi
addq $-0x20, %rsi
movq %r15, %rdi
callq 0x41b0
movq (%r15), %rdi
xorl %esi, %esi
callq 0x4260
cvttsd2si %xmm0, %r14
cvtsi2sd %r14, %xmm1
movb $0x1, %bl
ucomisd %xmm1, %xmm0
jne 0xade7
jp 0xade7
leaq 0xf0(%rsp), %rdi
callq 0x4220
leaq 0x100(%rsp), %rdi
movq %r14, %rsi
callq 0x4300
leaq 0x108(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x44e0
leaq 0xb0(%rsp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x43b0
movq %r14, %rdi
callq 0x4150
leaq 0xf0(%rsp), %rdi
callq 0x4250
jmp 0xade7
leaq 0x40(%rsp), %rdi
callq 0xbdfa
leaq 0xb0(%rsp), %rdi
callq 0x4150
xorl %ebx, %ebx
leaq 0x60(%rsp), %rdi
callq 0xb6a2
movl %ebx, %eax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xae07
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x4250
jmp 0xaea2
jmp 0xae8d
jmp 0xae6c
jmp 0xae8d
jmp 0xae6c
jmp 0xae6c
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x4150
jmp 0xae3d
jmp 0xae3a
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x4250
jmp 0xae81
jmp 0xae6c
jmp 0xae92
jmp 0xae5a
jmp 0xae5a
jmp 0xae92
jmp 0xae5a
jmp 0xae92
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x4250
jmp 0xae95
movq %rax, %rbx
jmp 0xae81
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x4150
leaq 0x40(%rsp), %rdi
callq 0xbdfa
jmp 0xae95
movq %rax, %rbx
jmp 0xaea2
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x4150
leaq 0x60(%rsp), %rdi
callq 0xb6a2
movq %rbx, %rdi
callq 0x4590