#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*/ error();
char peek();
char pop();
int preced(char, char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ push(char);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  char str[20], temp, t[10];
  int len, inp_ptr = 0, prec, countOfI = 0;
  printf("Enter the expression:- ");
  scanf("%s", str);
  push('$');
  len = strlen(str);
  str[len] = '$';
  str[len + 1] = '\0';
  while (str[inp_ptr] != '$' || peek() != '$') {
    if (str[inp_ptr] >= '0' && str[inp_ptr] <= '9') {
      while (str[inp_ptr] >= '0' && str[inp_ptr] <= '9')
        inp_ptr++;
      str[--inp_ptr] = 'i';
    }
    prec = preced(peek(), str[inp_ptr]);
    if (prec == 0) {
      if (str[inp_ptr] == 'i')
        countOfI++;
      else
        countOfI--;
      push(str[inp_ptr++]);
    } else if (prec == 1) {
      do {
        temp = pop();
      } while (preced(peek(), temp) != 0);
    } else
      error();
  }
  if (countOfI != 1)
    error();
  printf("Success\n", countOfI);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x3c(%rbp)
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe62(%rip),%rdi
call   1080 <scanf@plt>
mov    $0x24,%edi
call   10a0 <push@plt>
lea    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x30(%rbp)
movslq -0x30(%rbp),%rax
movb   $0x24,-0x20(%rbp,%rax,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x20(%rbp,%rax,1)
movslq -0x34(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%ecx
mov    $0x1,%al
cmp    $0x24,%ecx
mov    %al,-0x3d(%rbp)
jne    1211 <main+0x91>
mov    $0x0,%al
call   1030 <peek@plt>
movsbl %al,%eax
cmp    $0x24,%eax
setne  %al
mov    %al,-0x3d(%rbp)
mov    -0x3d(%rbp),%al
test   $0x1,%al
jne    1221 <main+0xa1>
jmp    1358 <main+0x1d8>
movslq -0x34(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x30,%eax
jl     12a1 <main+0x121>
movslq -0x34(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x39,%eax
jg     12a1 <main+0x121>
jmp    124a <main+0xca>
movslq -0x34(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x3e(%rbp)
jl     1273 <main+0xf3>
movslq -0x34(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x3e(%rbp)
mov    -0x3e(%rbp),%al
test   $0x1,%al
jne    1283 <main+0x103>
jmp    1291 <main+0x111>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    124a <main+0xca>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
cltq
movb   $0x69,-0x20(%rbp,%rax,1)
mov    $0x0,%al
call   1030 <peek@plt>
mov    %al,%cl
movslq -0x34(%rbp),%rax
movsbl %cl,%edi
movsbl -0x20(%rbp,%rax,1),%esi
call   1060 <preced@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    130d <main+0x18d>
movslq -0x34(%rbp),%rax
movsbl -0x20(%rbp,%rax,1),%eax
cmp    $0x69,%eax
jne    12e8 <main+0x168>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12f1 <main+0x171>
mov    -0x3c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x34(%rbp)
cltq
movsbl -0x20(%rbp,%rax,1),%edi
call   10a0 <push@plt>
jmp    1353 <main+0x1d3>
cmpl   $0x1,-0x38(%rbp)
jne    1347 <main+0x1c7>
jmp    131c <main+0x19c>
mov    $0x0,%al
call   1070 <pop@plt>
mov    %al,-0x21(%rbp)
mov    $0x0,%al
call   1030 <peek@plt>
movsbl %al,%edi
movsbl -0x21(%rbp),%esi
call   1060 <preced@plt>
cmp    $0x0,%eax
jne    131c <main+0x19c>
jmp    134e <main+0x1ce>
mov    $0x0,%al
call   1090 <error@plt>
jmp    1353 <main+0x1d3>
jmp    11e7 <main+0x67>
cmpl   $0x1,-0x3c(%rbp)
je     1369 <main+0x1e9>
mov    $0x0,%al
call   1090 <error@plt>
mov    -0x3c(%rbp),%esi
lea    0xca8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xe61(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6b(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    $0x24,%edi
call   10b0 <push@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movw   $0x24,(%rsp,%rax,1)
xor    %ebp,%ebp
xor    %r14d,%r14d
nopw   0x0(%rax,%rax,1)
movslq %ebp,%rbx
mov    (%rsp,%rbx,1),%al
cmp    $0x24,%al
jne    11fc <main+0x6c>
xor    %eax,%eax
call   1030 <peek@plt>
cmp    $0x24,%al
je     12a5 <main+0x115>
mov    (%rsp,%rbx,1),%al
add    $0xd0,%al
cmp    $0x9,%al
ja     122d <main+0x9d>
ja     121f <main+0x8f>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl 0x1(%rsp,%rbx,1),%eax
add    $0x1,%rbx
add    $0xd0,%al
cmp    $0xa,%al
jb     1210 <main+0x80>
movslq %ebx,%rbx
movb   $0x69,-0x1(%rsp,%rbx,1)
add    $0xffffffffffffffff,%rbx
mov    %ebx,%ebp
xor    %eax,%eax
call   1030 <peek@plt>
movsbl (%rsp,%rbx,1),%esi
movsbl %al,%edi
call   1070 <preced@plt>
cmp    $0x1,%eax
je     1260 <main+0xd0>
test   %eax,%eax
je     1284 <main+0xf4>
xor    %eax,%eax
call   10a0 <error@plt>
jmp    11e0 <main+0x50>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1080 <pop@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <peek@plt>
movsbl %bl,%esi
movsbl %al,%edi
call   1070 <preced@plt>
test   %eax,%eax
jne    1260 <main+0xd0>
jmp    11e0 <main+0x50>
movsbl (%rsp,%rbx,1),%edi
xor    %eax,%eax
cmp    $0x69,%edi
sete   %al
lea    (%r14,%rax,2),%r14d
add    $0xffffffff,%r14d
add    $0x1,%ebp
call   10b0 <push@plt>
jmp    11e0 <main+0x50>
cmp    $0x1,%r14d
je     12b2 <main+0x122>
xor    %eax,%eax
call   10a0 <error@plt>
lea    0xd62(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Enter the expression:- \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [9 x i8] c"Success\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i8
%4 = alloca [10 x i8]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %6
store i32 0, i32* %8
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, 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.1, i64 0, i64 0), i8* %10)
%12 = call i32 @push(i8 signext 36)
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %16
store i8 36, i8* %17
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %20
store i8 0, i8* %21
br label %22
22: ; preds = %118, %0
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 36
br i1 %28, label %33, label %29
29: ; preds = %22
%30 = call signext i8 (...) @peek()
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 36
br label %33
33: ; preds = %29, %22
%34 = phi i1 [ true, %22 ], [ %32, %29 ]
br i1 %34, label %35, label %119
35: ; preds = %33
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp sge i32 %40, 48
br i1 %41, label %42, label %74
42: ; preds = %35
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp sle i32 %47, 57
br i1 %48, label %49, label %74
49: ; preds = %42
br label %50
50: ; preds = %66, %49
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp sge i32 %55, 48
br i1 %56, label %57, label %64
57: ; preds = %50
%58 = load i32, i32* %6
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp sle i32 %62, 57
br label %64
64: ; preds = %57, %50
%65 = phi i1 [ false, %50 ], [ %63, %57 ]
br i1 %65, label %66, label %69
66: ; preds = %64
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %50
69: ; preds = %64
%70 = load i32, i32* %6
%71 = add nsw i32 %70, -1
store i32 %71, i32* %6
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %72
store i8 105, i8* %73
br label %74
74: ; preds = %69, %42, %35
%75 = call signext i8 (...) @peek()
%76 = load i32, i32* %6
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %77
%79 = load i8, i8* %78
%80 = call i32 @preced(i8 signext %75, i8 signext %79)
store i32 %80, i32* %7
%81 = load i32, i32* %7
%82 = icmp eq i32 %81, 0
br i1 %82, label %83, label %103
83: ; preds = %74
%84 = load i32, i32* %6
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %85
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = icmp eq i32 %88, 105
br i1 %89, label %90, label %93
90: ; preds = %83
%91 = load i32, i32* %8
%92 = add nsw i32 %91, 1
store i32 %92, i32* %8
br label %96
93: ; preds = %83
%94 = load i32, i32* %8
%95 = add nsw i32 %94, -1
store i32 %95, i32* %8
br label %96
96: ; preds = %93, %90
%97 = load i32, i32* %6
%98 = add nsw i32 %97, 1
store i32 %98, i32* %6
%99 = sext i32 %97 to i64
%100 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 %99
%101 = load i8, i8* %100
%102 = call i32 @push(i8 signext %101)
br label %118
103: ; preds = %74
%104 = load i32, i32* %7
%105 = icmp eq i32 %104, 1
br i1 %105, label %106, label %115
106: ; preds = %103
br label %107
107: ; preds = %109, %106
%108 = call signext i8 (...) @pop()
store i8 %108, i8* %3
br label %109
109: ; preds = %107
%110 = call signext i8 (...) @peek()
%111 = load i8, i8* %3
%112 = call i32 @preced(i8 signext %110, i8 signext %111)
%113 = icmp ne i32 %112, 0
br i1 %113, label %107, label %114
114: ; preds = %109
br label %117
115: ; preds = %103
%116 = call i32 (...) @error()
br label %117
117: ; preds = %115, %114
br label %118
118: ; preds = %117, %96
br label %22
119: ; preds = %33
%120 = load i32, i32* %8
%121 = icmp ne i32 %120, 1
br i1 %121, label %122, label %124
122: ; preds = %119
%123 = call i32 (...) @error()
br label %124
124: ; preds = %122, %119
%125 = load i32, i32* %8
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %125)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Enter the expression:- \00"
@.str.1 = [3 x i8] c"%s\00"
@str = [8 x i8] c"Success\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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 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 @push(i8 signext 36)
%6 = call i32 @strlen(i8* %2)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %7
store i8 36, i8* %8
%9 = add nsw i32 %6, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %53, %0
%13 = phi i32 [ %59, %53 ], [ 0, %0 ]
%14 = phi i32 [ %58, %53 ], [ 0, %0 ]
br label %15
15: ; preds = %68, %12
%16 = phi i32 [ %13, %12 ], [ %48, %68 ]
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 36
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = call signext i8 (...) @peek()
%23 = icmp eq i8 %22, 36
br i1 %23, label %69, label %24
24: ; preds = %21
%25 = load i8, i8* %18
br label %26
26: ; preds = %24, %15
%27 = phi i8 [ %25, %24 ], [ %19, %15 ]
%28 = add i8 %27, -48
%29 = icmp ult i8 %28, 10
br i1 %29, label %30, label %46
30: ; preds = %26
%31 = add i8 %27, -48
%32 = icmp ult i8 %31, 10
br i1 %32, label %33, label %40
33: ; preds = %30, %33
%34 = phi i64 [ %35, %33 ], [ %17, %30 ]
%35 = add i64 %34, 1
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = add i8 %37, -48
%39 = icmp ult i8 %38, 10
br i1 %39, label %33, label %40
40: ; preds = %33, %30
%41 = phi i64 [ %17, %30 ], [ %35, %33 ]
%42 = trunc i64 %41 to i32
%43 = add nsw i32 %42, -1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %44
store i8 105, i8* %45
br label %46
46: ; preds = %40, %26
%47 = phi i64 [ %44, %40 ], [ %17, %26 ]
%48 = phi i32 [ %43, %40 ], [ %16, %26 ]
%49 = call signext i8 (...) @peek()
%50 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %47
%51 = load i8, i8* %50
%52 = call i32 @preced(i8 signext %49, i8 signext %51)
switch i32 %52, label %66 [
i32 0, label %53
i32 1, label %61
]
53: ; preds = %46
%54 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %47
%55 = load i8, i8* %54
%56 = icmp eq i8 %55, 105
%57 = select i1 %56, i32 1, i32 -1
%58 = add nsw i32 %57, %14
%59 = add nsw i32 %48, 1
%60 = call i32 @push(i8 signext %55)
br label %12
61: ; preds = %46, %61
%62 = call signext i8 (...) @pop()
%63 = call signext i8 (...) @peek()
%64 = call i32 @preced(i8 signext %63, i8 signext %62)
%65 = icmp eq i32 %64, 0
br i1 %65, label %68, label %61
66: ; preds = %46
%67 = call i32 (...) @error()
br label %68
68: ; preds = %61, %66
br label %15
69: ; preds = %21
%70 = icmp eq i32 %14, 1
br i1 %70, label %73, label %71
71: ; preds = %69
%72 = call i32 (...) @error()
br label %73
73: ; preds = %71, %69
%74 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
ret i32 0
}