#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__ isdigit(char);
double pop();
int /*<<< orphan*/ push(double);
int /*<<< orphan*/ swap();
double eval(char *s, int n) {
  int i;
  for (i = 0; i < n; i++) {
    char c = s[i];
    if (isdigit(c))
      push(c - '0');
    else
      switch (c) {
      case '+':
        push(pop() + pop());
        break;
      case '*':
        push(pop() * pop());
        break;
      case '-':
        swap();
        push(pop() - pop());
        break;
      case '/':
        swap();
        push(pop() / pop());
        break;
      default:
        break;
      }
  }
  return pop();
}


x86 assembly (clang, -O0):
<eval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1291 <eval+0x151>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1198 <eval+0x58>
movsbl -0x11(%rbp),%eax
sub    $0x30,%eax
cvtsi2sd %eax,%xmm0
call   1050 <push@plt>
jmp    127e <eval+0x13e>
movsbl -0x11(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x5,%eax
ja     1274 <eval+0x134>
mov    -0x20(%rbp),%rax
lea    0xe47(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1040 <pop@plt>
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1040 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
addsd  %xmm1,%xmm0
call   1050 <push@plt>
jmp    1279 <eval+0x139>
mov    $0x0,%al
call   1040 <pop@plt>
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1040 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
call   1050 <push@plt>
jmp    1279 <eval+0x139>
mov    $0x0,%al
call   1060 <swap@plt>
mov    $0x0,%al
call   1040 <pop@plt>
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1040 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
call   1050 <push@plt>
jmp    1279 <eval+0x139>
mov    $0x0,%al
call   1060 <swap@plt>
mov    $0x0,%al
call   1040 <pop@plt>
movsd  %xmm0,-0x40(%rbp)
mov    $0x0,%al
call   1040 <pop@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
divsd  %xmm1,%xmm0
call   1050 <push@plt>
jmp    1279 <eval+0x139>
jmp    1279 <eval+0x139>
jmp    127e <eval+0x13e>
jmp    1283 <eval+0x143>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1156 <eval+0x16>
mov    $0x0,%al
call   1040 <pop@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eval>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    123e <eval+0xfe>
mov    %rdi,%r14
mov    %esi,%r15d
lea    0xe9e(%rip),%r12
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%r14,%r13,1),%ebx
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11a0 <eval+0x60>
add    $0xffffffd0,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
call   1050 <push@plt>
add    $0x1,%r13
cmp    %r13,%r15
jne    1170 <eval+0x30>
jmp    123e <eval+0xfe>
xchg   %ax,%ax
add    $0xffffffd6,%ebx
cmp    $0x5,%ebx
ja     1190 <eval+0x50>
movslq (%r12,%rbx,4),%rax
add    %r12,%rax
jmp    *%rax
xor    %eax,%eax
call   1040 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <pop@plt>
mulsd  0x8(%rsp),%xmm0
jmp    118b <eval+0x4b>
xor    %eax,%eax
call   1040 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <pop@plt>
addsd  0x8(%rsp),%xmm0
jmp    118b <eval+0x4b>
xor    %eax,%eax
call   1060 <swap@plt>
xor    %eax,%eax
call   1040 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <pop@plt>
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
jmp    1235 <eval+0xf5>
xor    %eax,%eax
call   1060 <swap@plt>
xor    %eax,%eax
call   1040 <pop@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <pop@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
jmp    118b <eval+0x4b>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1040 <pop@plt>

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

LLVM IR (-O2):
define double @eval(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %41
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %38
%7 = phi i64 [ 0, %4 ], [ %39, %38 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = tail call i64 @isdigit(i8 signext %9)
%11 = icmp eq i64 %10, 0
%12 = sext i8 %9 to i32
br i1 %11, label %16, label %13
13: ; preds = %6
%14 = add nsw i32 %12, -48
%15 = sitofp i32 %14 to double
br label %35
16: ; preds = %6
switch i32 %12, label %38 [
i32 43, label %17
i32 42, label %21
i32 45, label %25
i32 47, label %30
]
17: ; preds = %16
%18 = tail call double (...) @pop()
%19 = tail call double (...) @pop()
%20 = fadd double %18, %19
br label %35
21: ; preds = %16
%22 = tail call double (...) @pop()
%23 = tail call double (...) @pop()
%24 = fmul double %22, %23
br label %35
25: ; preds = %16
%26 = tail call i32 (...) @swap()
%27 = tail call double (...) @pop()
%28 = tail call double (...) @pop()
%29 = fsub double %27, %28
br label %35
30: ; preds = %16
%31 = tail call i32 (...) @swap()
%32 = tail call double (...) @pop()
%33 = tail call double (...) @pop()
%34 = fdiv double %32, %33
br label %35
35: ; preds = %13, %30, %25, %21, %17
%36 = phi double [ %20, %17 ], [ %24, %21 ], [ %29, %25 ], [ %34, %30 ], [ %15, %13 ]
%37 = tail call i32 @push(double %36)
br label %38
38: ; preds = %35, %16
%39 = add nuw nsw i64 %7, 1
%40 = icmp eq i64 %39, %5
br i1 %40, label %41, label %6
41: ; preds = %38, %2
%42 = tail call double (...) @pop()
ret double %42
}