// File: /workspace/github_cpp_makefile_star2_O1/ksherlock[P]wdc-utils/expression.cpp
// Function: evaluate_expression(expression&, bool)
optional<uint32_t> evaluate_expression(expression &e, bool force) {
	std::vector<expr> tmp;
	for (const auto &t : e.stack) {
		if (t.tag == OP_LOC && force) {
			tmp.emplace_back(OP_VAL, t.value);
			continue;				
		}
		if (t.tag >= OP_BIN) {
			binary_op(t.tag, tmp);
		} else if (t.tag >= OP_UNA) {
			unary_op(t.tag, tmp);
		} else {
			tmp.emplace_back(t);
		}
	}

	if (tmp.size() == 1 && tmp.front().tag == OP_VAL) return optional<uint32_t>(tmp.front().value);
	return optional<uint32_t>();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x10(%rsi), %r14
movq 0x18(%rsi), %r15
cmpq %r15, %r14
je 0xbdd5
movl %edx, %ebx
xorb $0x1, %bl
movl %ebx, 0x24(%rsp)
movq %r15, 0x30(%rsp)
movl (%r14), %edi
cmpl $0x3, %edi
setne %al
orb %bl, %al
jne 0xbc7e
movq 0x8(%rsp), %rbp
cmpq 0x10(%rsp), %rbp
je 0xbca2
movl 0x4(%r14), %eax
movl $0x2, (%rbp)
movl %eax, 0x4(%rbp)
movl $0x0, 0x8(%rbp)
addq $0xc, %rbp
movq %rbp, 0x8(%rsp)
jmp 0xbdc8
cmpl $0x14, %edi
jl 0xbc90
movq %rsp, %rsi
callq 0xb6fe
jmp 0xbdc8
cmpl $0xa, %edi
jl 0xbd0f
movq %rsp, %rsi
callq 0xb6be
jmp 0xbdc8
movq (%rsp), %r12
movq %rbp, %r15
subq %r12, %r15
movabsq $0x7ffffffffffffff8, %rax # imm = 0x7FFFFFFFFFFFFFF8
cmpq %rax, %r15
je 0xbe32
sarq $0x2, %r15
movabsq $-0x5555555555555555, %rax # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %r15
cmpq $0x1, %r15
movq %r15, %rax
adcq $0x0, %rax
leaq (%rax,%r15), %r13
movabsq $0xaaaaaaaaaaaaaaa, %rcx # imm = 0xAAAAAAAAAAAAAAA
cmpq %rcx, %r13
cmovaeq %rcx, %r13
addq %r15, %rax
cmovbq %rcx, %r13
testq %r13, %r13
je 0xbd37
movq %rsp, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x88c4
movq %rax, %rbx
jmp 0xbd39
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0xbdbd
movl 0x8(%r14), %eax
movl %eax, 0x8(%rsi)
movq (%r14), %rax
movq %rax, (%rsi)
addq $0xc, 0x8(%rsp)
jmp 0xbdc8
xorl %ebx, %ebx
leaq (%r15,%r15,2), %rax
movl 0x4(%r14), %ecx
movl $0x2, (%rbx,%rax,4)
movl %ecx, 0x4(%rbx,%rax,4)
movl $0x0, 0x8(%rbx,%rax,4)
movq %rbx, %r15
cmpq %rbp, %r12
je 0xbd7c
movq %rbx, %r15
movq %r12, %rax
movl 0x8(%rax), %ecx
movl %ecx, 0x8(%r15)
movq (%rax), %rcx
movq %rcx, (%r15)
addq $0xc, %rax
addq $0xc, %r15
cmpq %rbp, %rax
jne 0xbd62
testq %r12, %r12
je 0xbd91
movq 0x10(%rsp), %rsi
subq %r12, %rsi
movq %r12, %rdi
callq 0x2260
addq $0xc, %r15
movq %rbx, (%rsp)
movq %r15, 0x8(%rsp)
leaq (,%r13,2), %rax
addq %r13, %rax
leaq (%rbx,%rax,4), %rax
movq %rax, 0x10(%rsp)
movl 0x24(%rsp), %ebx
movq 0x30(%rsp), %r15
jmp 0xbdc8
movq %rsp, %rdi
movq %r14, %rdx
callq 0xc10e
addq $0xc, %r14
cmpq %r15, %r14
jne 0xbc42
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
subq %rdi, %rax
cmpq $0xc, %rax
jne 0xbdfe
cmpl $0x2, (%rdi)
jne 0xbdfe
movq 0x28(%rsp), %rbx
movb $0x0, (%rbx)
movl 0x4(%rdi), %eax
movl %eax, 0x4(%rbx)
movb $0x1, %al
jmp 0xbe0c
movq 0x28(%rsp), %rbx
movq $0x0, (%rbx)
xorl %eax, %eax
movb %al, (%rbx)
testq %rdi, %rdi
je 0xbe20
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x39ee(%rip), %rdi      # 0xf827
callq 0x2150
jmp 0xbe42
jmp 0xbe42
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0xbe5b
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x2260
movq %rbx, %rdi
callq 0x23c0
nop