#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__ isdig(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  char symbol, postfix[30];
  int a, b, res, i;
  void push(int);
  int pop();
  int op(int, int, char);
  printf("Postfix expression\n");
  scanf("%s", postfix);
  for (i = 0; i < strlen(postfix); i++) {
    symbol = postfix[i];
    if (isdig(symbol))
      push(symbol - '0');
    else {
      a = pop();
      b = pop();
      res = op(b, a, symbol);
      push(res);
    }
  }
  printf("%d", pop());
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    0xe7c(%rip),%rdi
call   1070 <scanf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %eax,-0x44(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
jge    1230 <main+0xc0>
movslq -0x40(%rbp),%rax
mov    -0x30(%rbp,%rax,1),%al
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1030 <isdig@plt>
cmp    $0x0,%rax
je     11ef <main+0x7f>
movsbl -0x5(%rbp),%edi
sub    $0x30,%edi
call   1090 <push@plt>
jmp    121d <main+0xad>
mov    $0x0,%al
call   1060 <pop@plt>
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1060 <pop@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%esi
movsbl -0x5(%rbp),%edx
call   1080 <op@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
call   1090 <push@plt>
jmp    1222 <main+0xb2>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11a4 <main+0x34>
mov    $0x0,%al
call   1060 <pop@plt>
mov    %eax,%esi
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xe75(%rip),%rdi
call   1040 <puts@plt>
lea    0xe63(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1080 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    120e <main+0x8e>
mov    %rsp,%r14
xor    %ebx,%ebx
jmp    11f9 <main+0x79>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <pop@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1070 <pop@plt>
mov    %eax,%edi
mov    %r15d,%esi
mov    %ebp,%edx
call   1090 <op@plt>
mov    %eax,%ebp
mov    %ebp,%edi
call   10a0 <push@plt>
add    $0x1,%rbx
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    120e <main+0x8e>
movsbl (%rsp,%rbx,1),%ebp
mov    %ebp,%edi
call   1030 <isdig@plt>
test   %rax,%rax
je     11c0 <main+0x40>
add    $0xffffffd0,%ebp
jmp    11df <main+0x5f>
xor    %eax,%eax
call   1070 <pop@plt>
lea    0xde7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Postfix expression\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [30 x 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 ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
store i32 0, i32* %7
br label %11
11: ; preds = %37, %0
%12 = load i32, i32* %7
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %40
16: ; preds = %11
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 %18
%20 = load i8, i8* %19
store i8 %20, i8* %2
%21 = load i8, i8* %2
%22 = call i64 @isdig(i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %16
%25 = load i8, i8* %2
%26 = sext i8 %25 to i32
%27 = sub nsw i32 %26, 48
br label %36
28: ; preds = %16
%29 = call i32 (...) @pop()
store i32 %29, i32* %4
%30 = call i32 (...) @pop()
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = load i32, i32* %4
%33 = load i8, i8* %2
%34 = call i32 @op(i32 %31, i32 %32, i8 signext %33)
store i32 %34, i32* %6
%35 = load i32, i32* %6
br label %36
36: ; preds = %28, %24
br label %37
37: ; preds = %36
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %11
40: ; preds = %11
%41 = call i32 (...) @pop()
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %41)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"%d\00"
@str = [19 x i8] c"Postfix expression\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = call i32 @strlen(i8* %2)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %26
7: ; preds = %0, %20
%8 = phi i64 [ %22, %20 ], [ 0, %0 ]
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = call i64 @isdig(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = sext i8 %10 to i32
%15 = add nsw i32 %14, -48
br label %20
16: ; preds = %7
%17 = call i32 (...) @pop()
%18 = call i32 (...) @pop()
%19 = call i32 @op(i32 %18, i32 %17, i8 signext %10)
br label %20
20: ; preds = %13, %16
%21 = phi i32 [ %15, %13 ], [ %19, %16 ]
%22 = add nuw nsw i64 %8, 1
%23 = call i32 @strlen(i8* %2)
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %7, label %26
26: ; preds = %20, %0
%27 = call i32 (...) @pop()
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %27)
ret i32 0
}