#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);
int pop();
int pow(int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(int);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  char postfix[20], ch;
  int i, op1, op2, res;
  printf("Postfix Expression Evaluvation\n");
  printf("Enter the expression : \n");
  scanf("%s", postfix);
  for (i = 0; i < strlen(postfix); i++) {
    ch = postfix[i];
    if (isdigit(ch))
      push(ch - '0');
    else {
      op2 = pop();
      op1 = pop();
      switch (ch) {
      case '+':
        res = op1 + op2;
        break;
      case '-':
        res = op1 - op2;
        break;
      case '*':
        res = op1 * op2;
        break;
      case '/':
        res = op1 / op2;
        break;
      case '^':
        res = pow(op1, op2);
        break;
      default:
        printf("Invalid Entry");
      }
      push(res);
    }
  }
  printf("Result expression : % d", pop());
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe93(%rip),%rdi
call   1070 <scanf@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x38(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jge    12e6 <main+0x176>
movslq -0x28(%rbp),%rax
mov    -0x20(%rbp,%rax,1),%al
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11fd <main+0x8d>
movsbl -0x21(%rbp),%edi
sub    $0x30,%edi
call   1080 <push@plt>
jmp    12d3 <main+0x163>
xor    %eax,%eax
mov    %al,-0x3d(%rbp)
call   1060 <pop@plt>
mov    %eax,%ecx
mov    -0x3d(%rbp),%al
mov    %ecx,-0x30(%rbp)
call   1060 <pop@plt>
mov    %eax,-0x2c(%rbp)
movsbl -0x21(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x2a,%eax
je     128c <main+0x11c>
jmp    122c <main+0xbc>
mov    -0x3c(%rbp),%eax
sub    $0x2b,%eax
je     1270 <main+0x100>
jmp    123d <main+0xcd>
mov    -0x3c(%rbp),%eax
sub    $0x2d,%eax
je     127e <main+0x10e>
jmp    124e <main+0xde>
mov    -0x3c(%rbp),%eax
sub    $0x2f,%eax
je     129b <main+0x12b>
jmp    125f <main+0xef>
mov    -0x3c(%rbp),%eax
sub    $0x5e,%eax
je     12aa <main+0x13a>
jmp    12bd <main+0x14d>
mov    -0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    12cb <main+0x15b>
mov    -0x2c(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    12cb <main+0x15b>
mov    -0x2c(%rbp),%eax
imul   -0x30(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    12cb <main+0x15b>
mov    -0x2c(%rbp),%eax
cltd
idivl  -0x30(%rbp)
mov    %eax,-0x34(%rbp)
jmp    12cb <main+0x15b>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1090 <pow@plt>
mov    %eax,-0x34(%rbp)
jmp    12cb <main+0x15b>
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x34(%rbp),%edi
call   1080 <push@plt>
jmp    12d8 <main+0x168>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b2 <main+0x42>
mov    $0x0,%al
call   1060 <pop@plt>
mov    %eax,%esi
lea    0xd54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeac(%rip),%rdi
call   1040 <puts@plt>
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6b(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1271 <main+0xf1>
lea    0xe31(%rip),%r12
mov    %rsp,%r15
xor    %ebp,%ebp
jmp    11fd <main+0x7d>
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffd0,%ebx
mov    %ebx,%edi
call   1090 <push@plt>
add    $0x1,%rbp
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    1271 <main+0xf1>
movsbl (%rsp,%rbp,1),%ebx
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    11e0 <main+0x60>
xor    %eax,%eax
call   1070 <pop@plt>
mov    %eax,%r13d
xor    %eax,%eax
call   1070 <pop@plt>
lea    -0x2a(%rbx),%ecx
cmp    $0x5,%ecx
ja     1235 <main+0xb5>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
jmp    *%rcx
imul   %r13d,%eax
jmp    1267 <main+0xe7>
cmp    $0x5e,%ebx
jne    1246 <main+0xc6>
mov    %eax,%edi
mov    %r13d,%esi
call   10a0 <pow@plt>
jmp    1267 <main+0xe7>
lea    0xdce(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%ebx
jmp    11e3 <main+0x63>
add    %r13d,%eax
jmp    1267 <main+0xe7>
sub    %r13d,%eax
jmp    1267 <main+0xe7>
cltd
idiv   %r13d
mov    %eax,%ebx
mov    %eax,%r14d
jmp    11e3 <main+0x63>
xor    %eax,%eax
call   1070 <pop@plt>
lea    0xdaa(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [14 x i8] c"Invalid Entry\00"
@.str.4 = [24 x i8] c"Result expression : % d\00"
@str = [31 x i8] c"Postfix Expression Evaluvation\00"
@str.5 = [24 x i8] c"Enter the expression : \00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.5, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%6 = call i32 @strlen(i8* %2)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %42
8: ; preds = %0, %34
%9 = phi i64 [ %38, %34 ], [ 0, %0 ]
%10 = phi i32 [ %36, %34 ], [ undef, %0 ]
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %9
%12 = load i8, i8* %11
%13 = call i64 @isdigit(i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %8
%16 = sext i8 %12 to i32
%17 = add nsw i32 %16, -48
br label %34
18: ; preds = %8
%19 = call i32 (...) @pop()
%20 = call i32 (...) @pop()
%21 = sext i8 %12 to i32
switch i32 %21, label %32 [
i32 43, label %22
i32 45, label %24
i32 42, label %26
i32 47, label %28
i32 94, label %30
]
22: ; preds = %18
%23 = add nsw i32 %20, %19
br label %34
24: ; preds = %18
%25 = sub nsw i32 %20, %19
br label %34
26: ; preds = %18
%27 = mul nsw i32 %20, %19
br label %34
28: ; preds = %18
%29 = sdiv i32 %20, %19
br label %34
30: ; preds = %18
%31 = call i32 @pow(i32 %20, i32 %19)
br label %34
32: ; preds = %18
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %22, %24, %26, %28, %30, %32, %15
%35 = phi i32 [ %17, %15 ], [ %10, %32 ], [ %31, %30 ], [ %29, %28 ], [ %27, %26 ], [ %25, %24 ], [ %23, %22 ]
%36 = phi i32 [ %10, %15 ], [ %10, %32 ], [ %31, %30 ], [ %29, %28 ], [ %27, %26 ], [ %25, %24 ], [ %23, %22 ]
%37 = call i32 @push(i32 %35)
%38 = add nuw nsw i64 %9, 1
%39 = call i32 @strlen(i8* %2)
%40 = sext i32 %39 to i64
%41 = icmp slt i64 %38, %40
br i1 %41, label %8, label %42
42: ; preds = %34, %0
%43 = call i32 (...) @pop()
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i32 %43)
ret i32 0
}