#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 */
int INT_MAX;
scalar_t__ isdigit(char);
int /*<<< orphan*/ show_expr_error(char const *, int);
int evaluate(const char *s) {
  static int position = 0;
  char c = s[position++];
  if (c == 0)
    return INT_MAX;
  if (isdigit(c)) {
    return c - '0';
  } else {
    switch (c) {
    case '+':
      return evaluate(s) + evaluate(s);
    case '-':
      return evaluate(s) - evaluate(s);
    case '*':
      return evaluate(s) * evaluate(s);
    case '/':
      return evaluate(s) / evaluate(s);
    default:
      show_expr_error(s, position);
      return INT_MAX;
    }
  }
}


x86 assembly (clang, -O0):
<evaluate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2ef6(%rip),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,0x2eeb(%rip)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    1178 <evaluate+0x48>
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1271 <evaluate+0x141>
movsbl -0x11(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     119a <evaluate+0x6a>
movsbl -0x11(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    1271 <evaluate+0x141>
movsbl -0x11(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x5,%eax
ja     1256 <evaluate+0x126>
mov    -0x20(%rbp),%rax
lea    0xe45(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
call   1050 <evaluate@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <evaluate@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1271 <evaluate+0x141>
mov    -0x10(%rbp),%rdi
call   1050 <evaluate@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <evaluate@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1271 <evaluate+0x141>
mov    -0x10(%rbp),%rdi
call   1050 <evaluate@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <evaluate@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
imul   %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    1271 <evaluate+0x141>
mov    -0x10(%rbp),%rdi
call   1050 <evaluate@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <evaluate@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    1271 <evaluate+0x141>
mov    -0x10(%rbp),%rdi
mov    0x2ddc(%rip),%esi
call   1040 <show_expr_error@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evaluate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movslq 0x2efe(%rip),%rax
lea    0x1(%rax),%ecx
mov    %ecx,0x2ef5(%rip)
mov    (%rdi,%rax,1),%al
test   %al,%al
je     11c9 <evaluate+0x99>
mov    %rdi,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%ebp
mov    %ebp,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    11d6 <evaluate+0xa6>
cmp    $0x2b,%ebp
jne    119d <evaluate+0x6d>
mov    %r15,%rdi
call   1050 <evaluate@plt>
mov    %eax,%ebp
add    %ebx,%ebp
movslq 0x2eb5(%rip),%rax
lea    0x1(%rax),%ecx
mov    %ecx,0x2eac(%rip)
movzbl (%r15,%rax,1),%eax
mov    %ebp,%ebx
test   %al,%al
jne    1160 <evaluate+0x30>
jmp    11cb <evaluate+0x9b>
cmp    $0x2a,%ebp
je     11db <evaluate+0xab>
cmp    $0x2d,%ebp
je     11f8 <evaluate+0xc8>
cmp    $0x2f,%ebp
jne    1210 <evaluate+0xe0>
mov    %r15,%rdi
call   1050 <evaluate@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1050 <evaluate@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %eax,%ebp
jmp    11f4 <evaluate+0xc4>
xor    %ebp,%ebp
mov    0x2e16(%rip),%rax
add    (%rax),%ebp
jmp    1229 <evaluate+0xf9>
add    $0xffffffd0,%ebp
jmp    11f4 <evaluate+0xc4>
mov    %r15,%rdi
call   1050 <evaluate@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1050 <evaluate@plt>
mov    %eax,%ebp
imul   %r14d,%ebp
add    %ebx,%ebp
jmp    1229 <evaluate+0xf9>
mov    %r15,%rdi
call   1050 <evaluate@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1050 <evaluate@plt>
add    %ebx,%ebp
sub    %eax,%ebp
jmp    1229 <evaluate+0xf9>
mov    0x2e26(%rip),%esi
mov    %r15,%rdi
call   1040 <show_expr_error@plt>
mov    0x2dc3(%rip),%rax
add    (%rax),%ebx
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@evaluate.position = internal global i32 0
@INT_MAX = global i32 0
define i32 @evaluate(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = load i32, i32* @evaluate.position
%7 = add nsw i32 %6, 1
store i32 %7, i32* @evaluate.position
%8 = sext i32 %6 to i64
%9 = getelementptr inbounds i8, i8* %5, i64 %8
%10 = load i8, i8* %9
store i8 %10, i8* %4
%11 = load i8, i8* %4
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %1
%15 = load i32, i32* @INT_MAX
store i32 %15, i32* %2
br label %56
16: ; preds = %1
%17 = load i8, i8* %4
%18 = call i64 @isdigit(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i8, i8* %4
%22 = sext i8 %21 to i32
%23 = sub nsw i32 %22, 48
store i32 %23, i32* %2
br label %56
24: ; preds = %16
%25 = load i8, i8* %4
%26 = sext i8 %25 to i32
switch i32 %26, label %51 [
i32 43, label %27
i32 45, label %33
i32 42, label %39
i32 47, label %45
]
27: ; preds = %24
%28 = load i8*, i8** %3
%29 = call i32 @evaluate(i8* %28)
%30 = load i8*, i8** %3
%31 = call i32 @evaluate(i8* %30)
%32 = add nsw i32 %29, %31
store i32 %32, i32* %2
br label %56
33: ; preds = %24
%34 = load i8*, i8** %3
%35 = call i32 @evaluate(i8* %34)
%36 = load i8*, i8** %3
%37 = call i32 @evaluate(i8* %36)
%38 = sub nsw i32 %35, %37
store i32 %38, i32* %2
br label %56
39: ; preds = %24
%40 = load i8*, i8** %3
%41 = call i32 @evaluate(i8* %40)
%42 = load i8*, i8** %3
%43 = call i32 @evaluate(i8* %42)
%44 = mul nsw i32 %41, %43
store i32 %44, i32* %2
br label %56
45: ; preds = %24
%46 = load i8*, i8** %3
%47 = call i32 @evaluate(i8* %46)
%48 = load i8*, i8** %3
%49 = call i32 @evaluate(i8* %48)
%50 = sdiv i32 %47, %49
store i32 %50, i32* %2
br label %56
51: ; preds = %24
%52 = load i8*, i8** %3
%53 = load i32, i32* @evaluate.position
%54 = call i32 @show_expr_error(i8* %52, i32 %53)
%55 = load i32, i32* @INT_MAX
store i32 %55, i32* %2
br label %56
56: ; preds = %51, %45, %39, %33, %27, %20, %14
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
@evaluate.position = internal unnamed_addr global i32 0
@INT_MAX = global i32 0
define i32 @evaluate(i8* %0) {
%2 = load i32, i32* @evaluate.position
%3 = add nsw i32 %2, 1
store i32 %3, i32* @evaluate.position
%4 = sext i32 %2 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %20, %1
%9 = phi i32 [ 0, %1 ], [ %22, %20 ]
%10 = load i32, i32* @INT_MAX
br label %50
11: ; preds = %1, %20
%12 = phi i8 [ %27, %20 ], [ %6, %1 ]
%13 = phi i32 [ %22, %20 ], [ 0, %1 ]
%14 = tail call i64 @isdigit(i8 signext %12)
%15 = icmp eq i64 %14, 0
%16 = sext i8 %12 to i32
br i1 %15, label %19, label %17
17: ; preds = %11
%18 = add nsw i32 %16, -48
br label %50
19: ; preds = %11
switch i32 %16, label %46 [
i32 43, label %20
i32 45, label %31
i32 42, label %36
i32 47, label %41
]
20: ; preds = %19
%21 = tail call i32 @evaluate(i8* %0)
%22 = add nsw i32 %21, %13
%23 = load i32, i32* @evaluate.position
%24 = add nsw i32 %23, 1
store i32 %24, i32* @evaluate.position
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %0, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %8, label %11
29: ; preds = %50, %41, %36, %31
%30 = phi i32 [ %35, %31 ], [ %40, %36 ], [ %45, %41 ], [ %53, %50 ]
ret i32 %30
31: ; preds = %19
%32 = tail call i32 @evaluate(i8* %0)
%33 = tail call i32 @evaluate(i8* %0)
%34 = add i32 %32, %13
%35 = sub i32 %34, %33
br label %29
36: ; preds = %19
%37 = tail call i32 @evaluate(i8* %0)
%38 = tail call i32 @evaluate(i8* %0)
%39 = mul nsw i32 %38, %37
%40 = add nsw i32 %39, %13
br label %29
41: ; preds = %19
%42 = tail call i32 @evaluate(i8* %0)
%43 = tail call i32 @evaluate(i8* %0)
%44 = sdiv i32 %42, %43
%45 = add nsw i32 %44, %13
br label %29
46: ; preds = %19
%47 = load i32, i32* @evaluate.position
%48 = tail call i32 @show_expr_error(i8* %0, i32 %47)
%49 = load i32, i32* @INT_MAX
br label %50
50: ; preds = %46, %17, %8
%51 = phi i32 [ %9, %8 ], [ %13, %17 ], [ %13, %46 ]
%52 = phi i32 [ %10, %8 ], [ %18, %17 ], [ %49, %46 ]
%53 = add nsw i32 %52, %51
br label %29
}