#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 */
char getTop(char);
int pop();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ push(int);
int calculate(char s[]) {
  char c, stack[100], type;
  int i = 0;
  while ((c = s[i++]) != '\0') {
    type = getTop(c);
    switch (type) {
    case 1:
      push(c - '0');
      break;
    case '+':
      printf("+ executed");
      push(pop() + pop());
      break;
    default:
      return pop();
    }
  }
  return pop();
}


x86 assembly (clang, -O0):
<calculate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x88(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x88(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x88(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     1218 <calculate+0xd8>
movsbl -0x11(%rbp),%edi
call   1060 <getTop@plt>
mov    %al,-0x81(%rbp)
movsbl -0x81(%rbp),%eax
mov    %eax,-0x8c(%rbp)
sub    $0x1,%eax
je     11c1 <calculate+0x81>
jmp    11ad <calculate+0x6d>
mov    -0x8c(%rbp),%eax
sub    $0x2b,%eax
je     11d2 <calculate+0x92>
jmp    1204 <calculate+0xc4>
movsbl -0x11(%rbp),%edi
sub    $0x30,%edi
call   1050 <push@plt>
jmp    1213 <calculate+0xd3>
lea    0xe27(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <pop@plt>
mov    %eax,-0x90(%rbp)
mov    $0x0,%al
call   1040 <pop@plt>
mov    -0x90(%rbp),%edi
add    %eax,%edi
call   1050 <push@plt>
jmp    1213 <calculate+0xd3>
mov    $0x0,%al
call   1040 <pop@plt>
mov    %eax,-0x4(%rbp)
jmp    1222 <calculate+0xe2>
jmp    1159 <calculate+0x19>
mov    $0x0,%al
call   1040 <pop@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     11ac <calculate+0x6c>
mov    %rdi,%rbx
add    $0x1,%rbx
lea    0xea5(%rip),%r14
jmp    1190 <calculate+0x50>
nopl   (%rax)
mov    %r14,%rdi
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <pop@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1040 <pop@plt>
mov    %eax,%ebp
add    %r15d,%ebp
mov    %ebp,%edi
call   1050 <push@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11ac <calculate+0x6c>
movsbl %al,%ebp
mov    %ebp,%edi
call   1060 <getTop@plt>
movsbl %al,%eax
cmp    $0x2b,%eax
je     1160 <calculate+0x20>
cmp    $0x1,%eax
jne    11ac <calculate+0x6c>
add    $0xffffffd0,%ebp
jmp    117e <calculate+0x3e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <pop@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"+ executed\00"
define i32 @calculate(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca [100 x i8]
%6 = alloca i8
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %7
br label %8
8: ; preds = %35, %1
%9 = load i8*, i8** %3
%10 = load i32, i32* %7
%11 = add nsw i32 %10, 1
store i32 %11, i32* %7
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = load i8, i8* %13
store i8 %14, i8* %4
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %36
17: ; preds = %8
%18 = load i8, i8* %4
%19 = call signext i8 @getTop(i8 signext %18)
store i8 %19, i8* %6
%20 = load i8, i8* %6
%21 = sext i8 %20 to i32
switch i32 %21, label %33 [
i32 1, label %22
i32 43, label %27
]
22: ; preds = %17
%23 = load i8, i8* %4
%24 = sext i8 %23 to i32
%25 = sub nsw i32 %24, 48
%26 = call i32 @push(i32 %25)
br label %35
27: ; preds = %17
%28 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%29 = call i32 (...) @pop()
%30 = call i32 (...) @pop()
%31 = add nsw i32 %29, %30
%32 = call i32 @push(i32 %31)
br label %35
33: ; preds = %17
%34 = call i32 (...) @pop()
store i32 %34, i32* %2
br label %38
35: ; preds = %27, %22
br label %8
36: ; preds = %8
%37 = call i32 (...) @pop()
store i32 %37, i32* %2
br label %38
38: ; preds = %36, %33
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@.str = [11 x i8] c"+ executed\00"
define i32 @calculate(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %24, label %4
4: ; preds = %1, %17
%5 = phi i64 [ %20, %17 ], [ 1, %1 ]
%6 = phi i8 [ %22, %17 ], [ %2, %1 ]
%7 = tail call signext i8 @getTop(i8 signext %6)
%8 = sext i8 %7 to i32
switch i32 %8, label %24 [
i32 1, label %9
i32 43, label %12
]
9: ; preds = %4
%10 = sext i8 %6 to i32
%11 = add nsw i32 %10, -48
br label %17
12: ; preds = %4
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 (...) @pop()
%15 = tail call i32 (...) @pop()
%16 = add nsw i32 %15, %14
br label %17
17: ; preds = %12, %9
%18 = phi i32 [ %16, %12 ], [ %11, %9 ]
%19 = tail call i32 @push(i32 %18)
%20 = add nuw i64 %5, 1
%21 = getelementptr inbounds i8, i8* %0, i64 %5
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %24, label %4
24: ; preds = %17, %4, %1
%25 = tail call i32 (...) @pop()
ret i32 %25
}