#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 */
typedef int ssize_t;

/* Variables and functions */
int braces_checker(char, char);
char *calloc(int, int);
int isEmpty();
int isFull();
scalar_t__ pop(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ push(char *, char);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main() {
  int i;
  char *S = calloc(50, sizeof(char));
  char *A = calloc(15, sizeof(char));
  printf("ENter the expression to be checked:-\n");
  scanf("%s", S);
  ssize_t len = strlen(S);
  for (i = 0; i < len; i++) {
    if (S[i] == '{' || S[i] == '[' || S[i] == '(') {
      int z = isFull();
      if (z == 0)
        push(A, S[i]);
      else {
        printf("Stack overflow\n");
        return 0;
      }
    } else if (S[i] == '}' || S[i] == ']' || S[i] == ')') {
      if (isEmpty()) {
        printf("Not valid\n");
        return 0;
      } else {
        int z = isEmpty();
        if (z == 0) {
          char c = (char)pop(A);
          int l = braces_checker(c, S[i]);
          if (l == 0) {
            printf("Not valid\n");
            return 0;
          }
        }
      }
    }
  }
  if (isEmpty())
    printf("True expression\n");
  else
    printf("Not valid\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x32,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0xf,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe34(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe4a(%rip),%rdi
call   1090 <scanf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1374 <main+0x1e4>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7b,%eax
je     123f <main+0xaf>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5b,%eax
je     123f <main+0xaf>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x28,%eax
jne    128a <main+0xfa>
mov    $0x0,%al
call   10a0 <isFull@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    126d <main+0xdd>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   10b0 <push@plt>
jmp    1285 <main+0xf5>
lea    0xdb5(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a8 <main+0x218>
jmp    1361 <main+0x1d1>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7d,%eax
je     12c9 <main+0x139>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5d,%eax
je     12c9 <main+0x139>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x29,%eax
jne    135c <main+0x1cc>
mov    $0x0,%al
call   1080 <isEmpty@plt>
cmp    $0x0,%eax
je     12f1 <main+0x161>
lea    0xd59(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a8 <main+0x218>
mov    $0x0,%al
call   1080 <isEmpty@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1352 <main+0x1c2>
mov    -0x18(%rbp),%rdi
call   1060 <pop@plt>
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsbl %dl,%edi
movsbl (%rax,%rcx,1),%esi
call   1030 <braces_checker@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    134d <main+0x1bd>
lea    0xcfd(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13a8 <main+0x218>
jmp    1352 <main+0x1c2>
jmp    1357 <main+0x1c7>
jmp    135c <main+0x1cc>
jmp    1361 <main+0x1d1>
jmp    1366 <main+0x1d6>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11f4 <main+0x64>
mov    $0x0,%al
call   1080 <isEmpty@plt>
cmp    $0x0,%eax
je     1395 <main+0x205>
lea    0xcb9(%rip),%rdi
call   1050 <printf@plt>
jmp    13a1 <main+0x211>
lea    0xc9d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x32,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    $0xf,%edi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%r14
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
lea    0xeba(%rip),%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1295 <main+0x105>
mov    %eax,%r12d
lea    0xed0(%rip),%r15
lea    0xe05(%rip),%rbp
xor    %r13d,%r13d
jmp    120d <main+0x7d>
add    $0x1,%r13
cmp    %r13,%r12
je     1295 <main+0x105>
movzbl (%rbx,%r13,1),%eax
lea    -0x5b(%rax),%ecx
cmp    $0x22,%cl
ja     1230 <main+0xa0>
movzbl %cl,%eax
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
nopw   0x0(%rax,%rax,1)
cmp    $0x29,%al
je     1260 <main+0xd0>
cmp    $0x28,%al
jne    1200 <main+0x70>
xor    %eax,%eax
call   10a0 <isFull@plt>
test   %eax,%eax
jne    12c9 <main+0x139>
movsbl (%rbx,%r13,1),%esi
mov    %r14,%rdi
call   10b0 <push@plt>
jmp    1200 <main+0x70>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <isEmpty@plt>
test   %eax,%eax
jne    12b0 <main+0x120>
xor    %eax,%eax
call   1080 <isEmpty@plt>
test   %eax,%eax
jne    1200 <main+0x70>
mov    %r14,%rdi
call   1060 <pop@plt>
movsbl (%rbx,%r13,1),%esi
movsbl %al,%edi
call   1040 <braces_checker@plt>
test   %eax,%eax
jne    1200 <main+0x70>
jmp    12b0 <main+0x120>
xor    %eax,%eax
call   1080 <isEmpty@plt>
test   %eax,%eax
lea    0xe1f(%rip),%rax
lea    0xe08(%rip),%r15
cmove  %rax,%r15
mov    %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfe(%rip),%r15
jmp    12b0 <main+0x120>

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@str = [37 x i8] c"ENter the expression to be checked:-\00"
@str.6 = [16 x i8] c"True expression\00"
@str.8 = [10 x i8] c"Not valid\00"
@str.9 = [15 x i8] c"Stack overflow\00"
define i32 @main() {
%1 = tail call dereferenceable_or_null(50) i8* @calloc(i32 50, i32 1)
%2 = tail call dereferenceable_or_null(15) i8* @calloc(i32 15, i32 1)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %34
7: ; preds = %0
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %31
%10 = phi i64 [ 0, %7 ], [ %32, %31 ]
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = load i8, i8* %11
switch i8 %12, label %31 [
i8 123, label %13
i8 91, label %13
i8 40, label %13
i8 125, label %19
i8 93, label %19
i8 41, label %19
]
13: ; preds = %9, %9, %9
%14 = tail call i32 (...) @isFull()
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %38
16: ; preds = %13
%17 = load i8, i8* %11
%18 = tail call i32 @push(i8* %2, i8 signext %17)
br label %31
19: ; preds = %9, %9, %9
%20 = tail call i32 (...) @isEmpty()
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %38
22: ; preds = %19
%23 = tail call i32 (...) @isEmpty()
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = tail call i64 @pop(i8* %2)
%27 = trunc i64 %26 to i8
%28 = load i8, i8* %11
%29 = tail call i32 @braces_checker(i8 signext %27, i8 signext %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %38, label %31
31: ; preds = %16, %22, %25, %9
%32 = add nuw nsw i64 %10, 1
%33 = icmp eq i64 %32, %8
br i1 %33, label %34, label %9
34: ; preds = %31, %0
%35 = tail call i32 (...) @isEmpty()
%36 = icmp eq i32 %35, 0
%37 = select i1 %36, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.8, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str.6, i64 0, i64 0)
br label %38
38: ; preds = %25, %19, %13, %34
%39 = phi i8* [ %37, %34 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.9, i64 0, i64 0), %13 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.8, i64 0, i64 0), %19 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.8, i64 0, i64 0), %25 ]
%40 = tail call i32 @puts(i8* dereferenceable(1) %39)
ret i32 0
}