#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 */
int /*<<< orphan*/ assert(struct stack *);
struct stack *createStack(int /*<<< orphan*/);
int isEmpty(struct stack *);
scalar_t__ paris(int /*<<< orphan*/, char);
int /*<<< orphan*/ peek(struct stack *);
int /*<<< orphan*/ pop(struct stack *);
int /*<<< orphan*/ push(struct stack *, char);
int /*<<< orphan*/ strlen(char *);
bool areParenthesisBalanced(char exp[]) {
  struct stack *stack = createStack(strlen(exp));
  assert(stack);
  for (int i = 0; exp[i]; i++) {
    if (exp[i] == '{' || exp[i] == '(' || exp[i] == '[') {
      push(stack, exp[i]);
    } else if (exp[i] == '}' || exp[i] == ']' || exp[i] == ')') {
      if (!isEmpty(stack) && paris(peek(stack), exp[i])) {
        pop(stack);
      } else {
        return false;
      }
    } else {
    }
  }
  return isEmpty(stack);
}


x86 assembly (clang, -O0):
<areParenthesisBalanced>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1080 <createStack@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <assert@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     12ce <areParenthesisBalanced+0x14e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7b,%eax
je     1201 <areParenthesisBalanced+0x81>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x28,%eax
je     1201 <areParenthesisBalanced+0x81>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5b,%eax
jne    121b <areParenthesisBalanced+0x9b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   10a0 <push@plt>
jmp    12bb <areParenthesisBalanced+0x13b>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7d,%eax
je     125a <areParenthesisBalanced+0xda>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5d,%eax
je     125a <areParenthesisBalanced+0xda>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x29,%eax
jne    12b1 <areParenthesisBalanced+0x131>
mov    -0x18(%rbp),%rdi
call   1090 <isEmpty@plt>
cmp    $0x0,%eax
jne    12a0 <areParenthesisBalanced+0x120>
mov    -0x18(%rbp),%rdi
call   1030 <peek@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1040 <paris@plt>
cmp    $0x0,%rax
je     12a0 <areParenthesisBalanced+0x120>
mov    -0x18(%rbp),%rdi
call   1060 <pop@plt>
jmp    12ac <areParenthesisBalanced+0x12c>
movl   $0x0,-0x4(%rbp)
jmp    12da <areParenthesisBalanced+0x15a>
jmp    12b6 <areParenthesisBalanced+0x136>
jmp    12b6 <areParenthesisBalanced+0x136>
jmp    12bb <areParenthesisBalanced+0x13b>
jmp    12c0 <areParenthesisBalanced+0x140>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b0 <areParenthesisBalanced+0x30>
mov    -0x18(%rbp),%rdi
call   1090 <isEmpty@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<areParenthesisBalanced>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %eax,%edi
call   1080 <createStack@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <assert@plt>
lea    0xe5a(%rip),%r15
jmp    11bf <areParenthesisBalanced+0x3f>
nopl   0x0(%rax,%rax,1)
movsbl %al,%esi
mov    %r14,%rdi
call   10a0 <push@plt>
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x5a,%al
jle    11e0 <areParenthesisBalanced+0x60>
lea    -0x5b(%rax),%ecx
cmp    $0x22,%cl
ja     1213 <areParenthesisBalanced+0x93>
movzbl %cl,%ecx
movslq (%r15,%rcx,4),%rcx
add    %r15,%rcx
jmp    *%rcx
nopw   0x0(%rax,%rax,1)
cmp    $0x28,%al
je     11b0 <areParenthesisBalanced+0x30>
cmp    $0x29,%al
jne    1219 <areParenthesisBalanced+0x99>
mov    %r14,%rdi
call   1090 <isEmpty@plt>
test   %eax,%eax
jne    122a <areParenthesisBalanced+0xaa>
mov    %r14,%rdi
call   1030 <peek@plt>
movsbl (%rbx),%esi
mov    %eax,%edi
call   1040 <paris@plt>
test   %rax,%rax
je     122a <areParenthesisBalanced+0xaa>
mov    %r14,%rdi
call   1060 <pop@plt>
add    $0x1,%rbx
jmp    11bf <areParenthesisBalanced+0x3f>
test   %al,%al
jne    1213 <areParenthesisBalanced+0x93>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1090 <isEmpty@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stack = type { i32 }
define i32 @areParenthesisBalanced(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.stack*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = call %struct.stack* @createStack(i32 %7)
store %struct.stack* %8, %struct.stack** %4
%9 = load %struct.stack*, %struct.stack** %4
%10 = call i32 @assert(%struct.stack* %9)
store i32 0, i32* %5
br label %11
11: ; preds = %96, %1
%12 = load i8*, i8** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %99
18: ; preds = %11
%19 = load i8*, i8** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 123
br i1 %25, label %42, label %26
26: ; preds = %18
%27 = load i8*, i8** %3
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 40
br i1 %33, label %42, label %34
34: ; preds = %26
%35 = load i8*, i8** %3
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 91
br i1 %41, label %42, label %50
42: ; preds = %34, %26, %18
%43 = load %struct.stack*, %struct.stack** %4
%44 = load i8*, i8** %3
%45 = load i32, i32* %5
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = call i32 @push(%struct.stack* %43, i8 signext %48)
br label %95
50: ; preds = %34
%51 = load i8*, i8** %3
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 125
br i1 %57, label %74, label %58
58: ; preds = %50
%59 = load i8*, i8** %3
%60 = load i32, i32* %5
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 93
br i1 %65, label %74, label %66
66: ; preds = %58
%67 = load i8*, i8** %3
%68 = load i32, i32* %5
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 41
br i1 %73, label %74, label %93
74: ; preds = %66, %58, %50
%75 = load %struct.stack*, %struct.stack** %4
%76 = call i32 @isEmpty(%struct.stack* %75)
%77 = icmp ne i32 %76, 0
br i1 %77, label %91, label %78
78: ; preds = %74
%79 = load %struct.stack*, %struct.stack** %4
%80 = call i32 @peek(%struct.stack* %79)
%81 = load i8*, i8** %3
%82 = load i32, i32* %5
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %81, i64 %83
%85 = load i8, i8* %84
%86 = call i64 @paris(i32 %80, i8 signext %85)
%87 = icmp ne i64 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %78
%89 = load %struct.stack*, %struct.stack** %4
%90 = call i32 @pop(%struct.stack* %89)
br label %92
91: ; preds = %78, %74
store i32 0, i32* %2
br label %102
92: ; preds = %88
br label %94
93: ; preds = %66
br label %94
94: ; preds = %93, %92
br label %95
95: ; preds = %94, %42
br label %96
96: ; preds = %95
%97 = load i32, i32* %5
%98 = add nsw i32 %97, 1
store i32 %98, i32* %5
br label %11
99: ; preds = %11
%100 = load %struct.stack*, %struct.stack** %4
%101 = call i32 @isEmpty(%struct.stack* %100)
store i32 %101, i32* %2
br label %102
102: ; preds = %99, %91
%103 = load i32, i32* %2
ret i32 %103
}

LLVM IR (-O2):
%struct.stack = type { i32 }
define i32 @areParenthesisBalanced(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call %struct.stack* @createStack(i32 %2)
%4 = tail call i32 @assert(%struct.stack* %3)
br label %5
5: ; preds = %21, %1
%6 = phi i64 [ %22, %21 ], [ 0, %1 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
switch i8 %8, label %21 [
i8 0, label %23
i8 123, label %9
i8 40, label %9
i8 91, label %9
i8 125, label %11
i8 93, label %11
i8 41, label %11
]
9: ; preds = %5, %5, %5
%10 = tail call i32 @push(%struct.stack* %3, i8 signext %8)
br label %21
11: ; preds = %5, %5, %5
%12 = tail call i32 @isEmpty(%struct.stack* %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = tail call i32 @peek(%struct.stack* %3)
%16 = load i8, i8* %7
%17 = tail call i64 @paris(i32 %15, i8 signext %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %14
%20 = tail call i32 @pop(%struct.stack* %3)
br label %21
21: ; preds = %5, %9, %19
%22 = add nuw i64 %6, 1
br label %5
23: ; preds = %5
%24 = tail call i32 @isEmpty(%struct.stack* %3)
br label %25
25: ; preds = %14, %11, %23
%26 = phi i32 [ %24, %23 ], [ 0, %11 ], [ 0, %14 ]
ret i32 %26
}