#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
scalar_t__ get_symbol_value(char, int *);
int /*<<< orphan*/ pop(int *);
int /*<<< orphan*/ push(int);
char *strtok(char *const, char *);
scalar_t__ strtol(char *, char **, int);
bool evaluate_expression(char *const expr) {
  char *p = strtok(expr, " ");
  while (NULL != p) {
    char *endptr = NULL;
    int r = 0, s = 0, item = (int)strtol(p, &endptr, 10);
    if (('\0' == *endptr) && ('\0' != *p)) {
      if (!push(item)) {
        return false;
      } else {
        goto finish;
      }
    }
    if ('\0' != *(p + 1)) {
      return false;
    }
    if (get_symbol_value(*p, &item)) {
      if (!push(item)) {
        return false;
      } else {
        goto finish;
      }
    }
    if (!pop(&r) || !pop(&s)) {
      return false;
    }
    switch (*p) {
    case '+':
      if (!push(r + s))
        return false;
      break;
    case '*':
      if (!push(r * s))
        return false;
      break;
    case '-':
      if (!push(r - s))
        return false;
      break;
    default:
      return false;
      break;
    }
  finish:
    p = strtok(NULL, " ");
  }
  return true;
}


x86 assembly (clang, -O0):
<evaluate_expression>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     1349 <evaluate_expression+0x1f9>
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    11eb <evaluate_expression+0x9b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     11eb <evaluate_expression+0x9b>
mov    -0x2c(%rbp),%edi
call   1060 <push@plt>
cmp    $0x0,%eax
jne    11e6 <evaluate_expression+0x96>
movl   $0x0,-0x4(%rbp)
jmp    1350 <evaluate_expression+0x200>
jmp    1330 <evaluate_expression+0x1e0>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
je     1209 <evaluate_expression+0xb9>
movl   $0x0,-0x4(%rbp)
jmp    1350 <evaluate_expression+0x200>
mov    -0x18(%rbp),%rax
lea    -0x2c(%rbp),%rsi
movsbl (%rax),%edi
call   1030 <get_symbol_value@plt>
cmp    $0x0,%rax
je     1245 <evaluate_expression+0xf5>
mov    -0x2c(%rbp),%edi
call   1060 <push@plt>
cmp    $0x0,%eax
jne    1240 <evaluate_expression+0xf0>
movl   $0x0,-0x4(%rbp)
jmp    1350 <evaluate_expression+0x200>
jmp    1330 <evaluate_expression+0x1e0>
lea    -0x24(%rbp),%rdi
call   1040 <pop@plt>
cmp    $0x0,%eax
je     1269 <evaluate_expression+0x119>
lea    -0x28(%rbp),%rdi
call   1040 <pop@plt>
cmp    $0x0,%eax
jne    1275 <evaluate_expression+0x125>
movl   $0x0,-0x4(%rbp)
jmp    1350 <evaluate_expression+0x200>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x30(%rbp)
sub    $0x2a,%eax
je     12d4 <evaluate_expression+0x184>
jmp    128d <evaluate_expression+0x13d>
mov    -0x30(%rbp),%eax
sub    $0x2b,%eax
je     12af <evaluate_expression+0x15f>
jmp    129e <evaluate_expression+0x14e>
mov    -0x30(%rbp),%eax
sub    $0x2d,%eax
je     12fa <evaluate_expression+0x1aa>
jmp    131f <evaluate_expression+0x1cf>
mov    -0x24(%rbp),%edi
add    -0x28(%rbp),%edi
call   1060 <push@plt>
cmp    $0x0,%eax
jne    12cf <evaluate_expression+0x17f>
movl   $0x0,-0x4(%rbp)
jmp    1350 <evaluate_expression+0x200>
jmp    132b <evaluate_expression+0x1db>
mov    -0x24(%rbp),%edi
imul   -0x28(%rbp),%edi
call   1060 <push@plt>
cmp    $0x0,%eax
jne    12f5 <evaluate_expression+0x1a5>
movl   $0x0,-0x4(%rbp)
jmp    1350 <evaluate_expression+0x200>
jmp    132b <evaluate_expression+0x1db>
mov    -0x24(%rbp),%edi
sub    -0x28(%rbp),%edi
call   1060 <push@plt>
cmp    $0x0,%eax
jne    131a <evaluate_expression+0x1ca>
movl   $0x0,-0x4(%rbp)
jmp    1350 <evaluate_expression+0x200>
jmp    132b <evaluate_expression+0x1db>
movl   $0x0,-0x4(%rbp)
jmp    1350 <evaluate_expression+0x200>
jmp    1330 <evaluate_expression+0x1e0>
xor    %eax,%eax
mov    %eax,%edi
lea    0xcc5(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
jmp    1170 <evaluate_expression+0x20>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evaluate_expression>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe9b(%rip),%rsi
call   1070 <strtok@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     1284 <evaluate_expression+0x134>
mov    %rax,%r12
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r13
lea    0x8(%rsp),%r15
lea    0xe6e(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movq   $0x0,0x10(%rsp)
movl   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,0xc(%rsp)
mov    0x10(%rsp),%rcx
cmpb   $0x0,(%rcx)
je     1200 <evaluate_expression+0xb0>
cmpb   $0x0,0x1(%r12)
jne    1281 <evaluate_expression+0x131>
movsbl (%r12),%edi
mov    %r13,%rsi
call   1030 <get_symbol_value@plt>
test   %rax,%rax
je     1210 <evaluate_expression+0xc0>
mov    0xc(%rsp),%edi
jmp    1260 <evaluate_expression+0x110>
nopl   0x0(%rax,%rax,1)
cmpb   $0x0,(%r12)
je     11d7 <evaluate_expression+0x87>
mov    %eax,%edi
jmp    1260 <evaluate_expression+0x110>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1040 <pop@plt>
test   %eax,%eax
je     1281 <evaluate_expression+0x131>
lea    0x4(%rsp),%rdi
call   1040 <pop@plt>
test   %eax,%eax
je     1281 <evaluate_expression+0x131>
movsbl (%r12),%eax
cmp    $0x2a,%eax
je     1248 <evaluate_expression+0xf8>
cmp    $0x2d,%eax
je     1253 <evaluate_expression+0x103>
cmp    $0x2b,%eax
jne    1281 <evaluate_expression+0x131>
mov    0x4(%rsp),%edi
add    0x8(%rsp),%edi
jmp    1260 <evaluate_expression+0x110>
mov    0x4(%rsp),%edi
imul   0x8(%rsp),%edi
jmp    1260 <evaluate_expression+0x110>
mov    0x8(%rsp),%edi
sub    0x4(%rsp),%edi
nopl   0x0(%rax,%rax,1)
call   1060 <push@plt>
test   %eax,%eax
je     1281 <evaluate_expression+0x131>
xor    %edi,%edi
mov    %rbp,%rsi
call   1070 <strtok@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11a0 <evaluate_expression+0x50>
jmp    1284 <evaluate_expression+0x134>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define i32 @evaluate_expression(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i8* @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %4
br label %11
11: ; preds = %88, %1
%12 = load i8*, i8** %4
%13 = icmp ne i8* null, %12
br i1 %13, label %14, label %90
14: ; preds = %11
store i8* null, i8** %5
store i32 0, i32* %6
store i32 0, i32* %7
%15 = load i8*, i8** %4
%16 = call i64 @strtol(i8* %15, i8** %5, i32 10)
%17 = trunc i64 %16 to i32
store i32 %17, i32* %8
%18 = load i8*, i8** %5
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 0, %20
br i1 %21, label %22, label %33
22: ; preds = %14
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 0, %25
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i32, i32* %8
%29 = call i32 @push(i32 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %27
store i32 0, i32* %2
br label %91
32: ; preds = %27
br label %88
33: ; preds = %22, %14
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 0, %37
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 0, i32* %2
br label %91
40: ; preds = %33
%41 = load i8*, i8** %4
%42 = load i8, i8* %41
%43 = call i64 @get_symbol_value(i8 signext %42, i32* %8)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %40
%46 = load i32, i32* %8
%47 = call i32 @push(i32 %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %50, label %49
49: ; preds = %45
store i32 0, i32* %2
br label %91
50: ; preds = %45
br label %88
51: ; preds = %40
%52 = call i32 @pop(i32* %6)
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = call i32 @pop(i32* %7)
%56 = icmp ne i32 %55, 0
br i1 %56, label %58, label %57
57: ; preds = %54, %51
store i32 0, i32* %2
br label %91
58: ; preds = %54
%59 = load i8*, i8** %4
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
switch i32 %61, label %86 [
i32 43, label %62
i32 42, label %70
i32 45, label %78
]
62: ; preds = %58
%63 = load i32, i32* %6
%64 = load i32, i32* %7
%65 = add nsw i32 %63, %64
%66 = call i32 @push(i32 %65)
%67 = icmp ne i32 %66, 0
br i1 %67, label %69, label %68
68: ; preds = %62
store i32 0, i32* %2
br label %91
69: ; preds = %62
br label %87
70: ; preds = %58
%71 = load i32, i32* %6
%72 = load i32, i32* %7
%73 = mul nsw i32 %71, %72
%74 = call i32 @push(i32 %73)
%75 = icmp ne i32 %74, 0
br i1 %75, label %77, label %76
76: ; preds = %70
store i32 0, i32* %2
br label %91
77: ; preds = %70
br label %87
78: ; preds = %58
%79 = load i32, i32* %6
%80 = load i32, i32* %7
%81 = sub nsw i32 %79, %80
%82 = call i32 @push(i32 %81)
%83 = icmp ne i32 %82, 0
br i1 %83, label %85, label %84
84: ; preds = %78
store i32 0, i32* %2
br label %91
85: ; preds = %78
br label %87
86: ; preds = %58
store i32 0, i32* %2
br label %91
87: ; preds = %85, %77, %69
br label %88
88: ; preds = %87, %50, %32
%89 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %89, i8** %4
br label %11
90: ; preds = %11
store i32 1, i32* %2
br label %91
91: ; preds = %90, %86, %84, %76, %68, %57, %49, %39, %31
%92 = load i32, i32* %2
ret i32 %92
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define i32 @evaluate_expression(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %69, label %8
8: ; preds = %1
%9 = bitcast i8** %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = bitcast i32* %4 to i8*
%12 = bitcast i32* %5 to i8*
br label %13
13: ; preds = %8, %66
%14 = phi i8* [ %6, %8 ], [ %67, %66 ]
store i8* null, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
%15 = call i64 @strtol(i8* %14, i8** %2, i32 10)
%16 = trunc i64 %15 to i32
store i32 %16, i32* %5
%17 = load i8*, i8** %2
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %13
%21 = load i8, i8* %14
%22 = icmp eq i8 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = call i32 @push(i32 %16)
%25 = icmp eq i32 %24, 0
br i1 %25, label %65, label %66
26: ; preds = %20, %13
%27 = getelementptr inbounds i8, i8* %14, i64 1
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %30, label %65
30: ; preds = %26
%31 = load i8, i8* %14
%32 = call i64 @get_symbol_value(i8 signext %31, i32* %5)
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %30
%35 = load i32, i32* %5
%36 = call i32 @push(i32 %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %65, label %66
38: ; preds = %30
%39 = call i32 @pop(i32* %3)
%40 = icmp eq i32 %39, 0
br i1 %40, label %65, label %41
41: ; preds = %38
%42 = call i32 @pop(i32* %4)
%43 = icmp eq i32 %42, 0
br i1 %43, label %65, label %44
44: ; preds = %41
%45 = load i8, i8* %14
%46 = sext i8 %45 to i32
switch i32 %46, label %65 [
i32 43, label %47
i32 42, label %53
i32 45, label %59
]
47: ; preds = %44
%48 = load i32, i32* %3
%49 = load i32, i32* %4
%50 = add nsw i32 %49, %48
%51 = call i32 @push(i32 %50)
%52 = icmp eq i32 %51, 0
br i1 %52, label %65, label %66
53: ; preds = %44
%54 = load i32, i32* %3
%55 = load i32, i32* %4
%56 = mul nsw i32 %55, %54
%57 = call i32 @push(i32 %56)
%58 = icmp eq i32 %57, 0
br i1 %58, label %65, label %66
59: ; preds = %44
%60 = load i32, i32* %3
%61 = load i32, i32* %4
%62 = sub nsw i32 %60, %61
%63 = call i32 @push(i32 %62)
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %23, %26, %34, %41, %38, %47, %53, %59, %44
br label %69
66: ; preds = %23, %34, %59, %53, %47
%67 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%68 = icmp eq i8* %67, null
br i1 %68, label %69, label %13
69: ; preds = %66, %1, %65
%70 = phi i32 [ 0, %65 ], [ 1, %1 ], [ 1, %66 ]
ret i32 %70
}