#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 /*<<< orphan*/ assert(int);
int pop();
int /*<<< orphan*/ push(int);
int sscanf(char const *, char *, ...);
int eval_expr(const char *expr) {
  int offset = 0;
  while (1) {
    int val;
    int offset_incr;
    char op;
    if (sscanf(&expr[offset], " %d%n", &val, &offset_incr) == 1) {
      push(val);
    } else if (sscanf(&expr[offset], " %c%n", &op, &offset_incr) == 1) {
      int right = pop();
      int left = pop();
      switch (op) {
      case '+':
        push(left + right);
        break;
      case '-':
        push(left - right);
        break;
      case '*':
        push(left * right);
        break;
      case '/':
        assert(right != 0);
        push(left / right);
        break;
      default:
        assert(0);
      }
    } else {
      break;
    }
    offset += offset_incr;
  }
  return pop();
}


x86 assembly (clang, -O0):
<eval_expr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
lea    0xeb3(%rip),%rsi
lea    -0x10(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    118a <eval_expr+0x4a>
mov    -0x10(%rbp),%edi
call   1060 <push@plt>
jmp    1263 <eval_expr+0x123>
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
lea    0xe82(%rip),%rsi
lea    -0x15(%rbp),%rdx
lea    -0x14(%rbp),%rcx
mov    $0x0,%al
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    1259 <eval_expr+0x119>
xor    %eax,%eax
mov    %al,-0x29(%rbp)
call   1030 <pop@plt>
mov    %eax,%ecx
mov    -0x29(%rbp),%al
mov    %ecx,-0x1c(%rbp)
call   1030 <pop@plt>
mov    %eax,-0x20(%rbp)
movsbl -0x15(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5,%eax
ja     124d <eval_expr+0x10d>
mov    -0x28(%rbp),%rax
lea    0xe11(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%edi
add    -0x1c(%rbp),%edi
call   1060 <push@plt>
jmp    1254 <eval_expr+0x114>
mov    -0x20(%rbp),%edi
sub    -0x1c(%rbp),%edi
call   1060 <push@plt>
jmp    1254 <eval_expr+0x114>
mov    -0x20(%rbp),%edi
imul   -0x1c(%rbp),%edi
call   1060 <push@plt>
jmp    1254 <eval_expr+0x114>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
mov    %eax,%edi
call   1060 <push@plt>
jmp    1254 <eval_expr+0x114>
xor    %edi,%edi
call   1040 <assert@plt>
jmp    125e <eval_expr+0x11e>
jmp    1271 <eval_expr+0x131>
jmp    1263 <eval_expr+0x123>
mov    -0x14(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1153 <eval_expr+0x13>
mov    $0x0,%al
call   1030 <pop@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eval_expr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
lea    0xec0(%rip),%r13
lea    0x14(%rsp),%r12
lea    0x4(%rsp),%rbx
xor    %r14d,%r14d
mov    %rdi,0x8(%rsp)
jmp    117e <eval_expr+0x3e>
nopl   0x0(%rax)
mov    0x14(%rsp),%edi
call   1060 <push@plt>
add    0x4(%rsp),%r14d
movslq %r14d,%rbp
add    %r15,%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     1170 <eval_expr+0x30>
mov    %rbp,%rdi
lea    0xe78(%rip),%rsi
lea    0x3(%rsp),%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <sscanf@plt>
cmp    $0x1,%eax
jne    123f <eval_expr+0xff>
mov    %rbx,%r15
mov    %r13,%rbx
xor    %eax,%eax
call   1030 <pop@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   1030 <pop@plt>
mov    %eax,%ebp
movsbl 0x3(%rsp),%eax
add    $0xffffffd6,%eax
cmp    $0x5,%eax
ja     11ff <eval_expr+0xbf>
lea    0xe15(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
imul   %r13d,%ebp
jmp    120b <eval_expr+0xcb>
add    %r13d,%ebp
jmp    120b <eval_expr+0xcb>
xor    %edi,%edi
call   1040 <assert@plt>
jmp    122a <eval_expr+0xea>
sub    %r13d,%ebp
mov    %ebp,%edi
jmp    1225 <eval_expr+0xe5>
xor    %edi,%edi
test   %r13d,%r13d
setne  %dil
call   1040 <assert@plt>
mov    %ebp,%eax
cltd
idiv   %r13d
mov    %eax,%edi
call   1060 <push@plt>
add    0x4(%rsp),%r14d
mov    %rbx,%r13
mov    %r15,%rbx
mov    0x8(%rsp),%r15
jmp    117e <eval_expr+0x3e>
xor    %eax,%eax
call   1030 <pop@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c" %d%n\00"
@.str.1 = [6 x i8] c" %c%n\00"
define i32 @eval_expr(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
br label %7
7: ; preds = %41, %1
%8 = phi i32 [ 0, %1 ], [ %43, %41 ]
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = call i32 (i8*, i8*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = load i32, i32* %2
%15 = call i32 @push(i32 %14)
br label %41
16: ; preds = %7
%17 = call i32 (i8*, i8*, ...) @sscanf(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32* %3)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %44
19: ; preds = %16
%20 = call i32 (...) @pop()
%21 = call i32 (...) @pop()
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
switch i32 %23, label %39 [
i32 43, label %24
i32 45, label %27
i32 42, label %30
i32 47, label %33
]
24: ; preds = %19
%25 = add nsw i32 %21, %20
%26 = call i32 @push(i32 %25)
br label %41
27: ; preds = %19
%28 = sub nsw i32 %21, %20
%29 = call i32 @push(i32 %28)
br label %41
30: ; preds = %19
%31 = mul nsw i32 %21, %20
%32 = call i32 @push(i32 %31)
br label %41
33: ; preds = %19
%34 = icmp ne i32 %20, 0
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = sdiv i32 %21, %20
%38 = call i32 @push(i32 %37)
br label %41
39: ; preds = %19
%40 = call i32 @assert(i32 0)
br label %41
41: ; preds = %13, %39, %33, %30, %27, %24
%42 = load i32, i32* %3
%43 = add nsw i32 %42, %8
br label %7
44: ; preds = %16
%45 = call i32 (...) @pop()
ret i32 %45
}