#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 */
struct Stack {
  int dummy;
};

/* Variables and functions */
struct Stack *createStack(int);
scalar_t__ isEmpty(struct Stack *);
char pop(struct Stack *);
int /*<<< orphan*/ printf(char *, char *, char);
int /*<<< orphan*/ push(struct Stack *, char);
int strlen(char *);
int checkParenthesis(char exp[]) {
  struct Stack *root = createStack(100);
  int n = strlen(exp);
  int i;
  for (i = 0; i < n; i++) {
    printf("%s %c\n", "Checking: ", exp[i]);
    switch (exp[i]) {
    case '(':
    case '{':
    case '[':
      push(root, exp[i]);
      break;
    case ')':
      if (pop(root) != '(')
        return 0;
      break;
    case '}':
      if (pop(root) != '{')
        return 0;
      break;
    case ']':
      if (pop(root) != '[')
        return 0;
      break;
    }
  }
  if (isEmpty(root)) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<checkParenthesis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x64,%edi
call   1060 <createStack@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12c9 <checkParenthesis+0x169>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xe54(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x24(%rbp)
sub    $0x28,%eax
je     122a <checkParenthesis+0xca>
jmp    11d5 <checkParenthesis+0x75>
mov    -0x24(%rbp),%eax
sub    $0x29,%eax
je     1244 <checkParenthesis+0xe4>
jmp    11e6 <checkParenthesis+0x86>
mov    -0x24(%rbp),%eax
sub    $0x5b,%eax
je     122a <checkParenthesis+0xca>
jmp    11f7 <checkParenthesis+0x97>
mov    -0x24(%rbp),%eax
sub    $0x5d,%eax
je     1290 <checkParenthesis+0x130>
jmp    1208 <checkParenthesis+0xa8>
mov    -0x24(%rbp),%eax
sub    $0x7b,%eax
je     122a <checkParenthesis+0xca>
jmp    1219 <checkParenthesis+0xb9>
mov    -0x24(%rbp),%eax
sub    $0x7d,%eax
je     126a <checkParenthesis+0x10a>
jmp    12b6 <checkParenthesis+0x156>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1080 <push@plt>
jmp    12b6 <checkParenthesis+0x156>
mov    -0x18(%rbp),%rdi
call   1050 <pop@plt>
movsbl %al,%eax
cmp    $0x28,%eax
je     1265 <checkParenthesis+0x105>
movl   $0x0,-0x4(%rbp)
jmp    12ef <checkParenthesis+0x18f>
jmp    12b6 <checkParenthesis+0x156>
mov    -0x18(%rbp),%rdi
call   1050 <pop@plt>
movsbl %al,%eax
cmp    $0x7b,%eax
je     128b <checkParenthesis+0x12b>
movl   $0x0,-0x4(%rbp)
jmp    12ef <checkParenthesis+0x18f>
jmp    12b6 <checkParenthesis+0x156>
mov    -0x18(%rbp),%rdi
call   1050 <pop@plt>
movsbl %al,%eax
cmp    $0x5b,%eax
je     12b1 <checkParenthesis+0x151>
movl   $0x0,-0x4(%rbp)
jmp    12ef <checkParenthesis+0x18f>
jmp    12b6 <checkParenthesis+0x156>
jmp    12bb <checkParenthesis+0x15b>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    118d <checkParenthesis+0x2d>
mov    -0x18(%rbp),%rdi
call   1070 <isEmpty@plt>
cmp    $0x0,%rax
je     12e8 <checkParenthesis+0x188>
movl   $0x1,-0x4(%rbp)
jmp    12ef <checkParenthesis+0x18f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkParenthesis>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x64,%edi
call   1060 <createStack@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    121a <checkParenthesis+0xba>
mov    %eax,%r13d
xor    %ebp,%ebp
lea    0xefc(%rip),%r12
lea    0xe62(%rip),%r15
jmp    11b1 <checkParenthesis+0x51>
mov    %r14,%rdi
call   1080 <push@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     121a <checkParenthesis+0xba>
movsbl (%rbx,%rbp,1),%edx
lea    0xed0(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
movsbl (%rbx,%rbp,1),%esi
lea    -0x5b(%rsi),%eax
cmp    $0x22,%eax
ja     11f0 <checkParenthesis+0x90>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    %r14,%rdi
call   1050 <pop@plt>
cmp    $0x5b,%al
je     11a8 <checkParenthesis+0x48>
jmp    1216 <checkParenthesis+0xb6>
nopw   0x0(%rax,%rax,1)
cmp    $0x29,%esi
je     120a <checkParenthesis+0xaa>
cmp    $0x28,%esi
je     11a0 <checkParenthesis+0x40>
jmp    11a8 <checkParenthesis+0x48>
mov    %r14,%rdi
call   1050 <pop@plt>
cmp    $0x7b,%al
je     11a8 <checkParenthesis+0x48>
jmp    1216 <checkParenthesis+0xb6>
mov    %r14,%rdi
call   1050 <pop@plt>
cmp    $0x28,%al
je     11a8 <checkParenthesis+0x48>
xor    %eax,%eax
jmp    122d <checkParenthesis+0xcd>
mov    %r14,%rdi
call   1070 <isEmpty@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.Stack = type { i32 }
@.str = [7 x i8] c"%s %c\0A\00"
@.str.1 = [11 x i8] c"Checking: \00"
define i32 @checkParenthesis(i8* %0) {
%2 = tail call %struct.Stack* @createStack(i32 100)
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %28
5: ; preds = %1
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %25
%8 = phi i64 [ 0, %5 ], [ %26, %25 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8 signext %10)
%12 = load i8, i8* %9
%13 = sext i8 %12 to i32
switch i32 %13, label %25 [
i32 40, label %14
i32 123, label %14
i32 91, label %14
i32 41, label %16
i32 125, label %19
i32 93, label %22
]
14: ; preds = %7, %7, %7
%15 = tail call i32 @push(%struct.Stack* %2, i8 signext %12)
br label %25
16: ; preds = %7
%17 = tail call signext i8 @pop(%struct.Stack* %2)
%18 = icmp eq i8 %17, 40
br i1 %18, label %25, label %32
19: ; preds = %7
%20 = tail call signext i8 @pop(%struct.Stack* %2)
%21 = icmp eq i8 %20, 123
br i1 %21, label %25, label %32
22: ; preds = %7
%23 = tail call signext i8 @pop(%struct.Stack* %2)
%24 = icmp eq i8 %23, 91
br i1 %24, label %25, label %32
25: ; preds = %14, %7, %16, %19, %22
%26 = add nuw nsw i64 %8, 1
%27 = icmp eq i64 %26, %6
br i1 %27, label %28, label %7
28: ; preds = %25, %1
%29 = tail call i64 @isEmpty(%struct.Stack* %2)
%30 = icmp ne i64 %29, 0
%31 = zext i1 %30 to i32
br label %32
32: ; preds = %22, %19, %16, %28
%33 = phi i32 [ %31, %28 ], [ 0, %16 ], [ 0, %19 ], [ 0, %22 ]
ret i32 %33
}