#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 DynArr {
  int dummy;
};

/* Variables and functions */
struct DynArr *newDynArr(int);
char nextChar(char *);
int /*<<< orphan*/ popDynArr(struct DynArr *);
int /*<<< orphan*/ pushDynArr(struct DynArr *, char);
scalar_t__ sizeDynArr(struct DynArr *);
char topDynArr(struct DynArr *);
int isBalanced(char *s) {
  char t;
  struct DynArr *l = newDynArr(2);
  do {
    t = nextChar(s);
    if (((t) == ('{')) || ((t) == ('[')) || ((t) == ('('))) {
      pushDynArr(l, t);
    }
    if (((t) == ('}')) || ((t) == (']')) || ((t) == (')'))) {
      if (sizeDynArr(l) == 0) {
        return 0;
      } else {
        if (((t) == ('}'))) {
          if (((topDynArr(l)) == ('{'))) {
            popDynArr(l);
          }
        }
        if (((t) == (']'))) {
          if (((topDynArr(l)) == ('['))) {
            popDynArr(l);
          }
        }
        if (((t) == (')'))) {
          if (((topDynArr(l)) == ('('))) {
            popDynArr(l);
          }
        }
      }
    }
  } while (t != 0);
  if (sizeDynArr(l) == 0) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<isBalanced>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x2,%edi
call   1070 <newDynArr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <nextChar@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x7b,%eax
je     11ad <isBalanced+0x4d>
movsbl -0x11(%rbp),%eax
cmp    $0x5b,%eax
je     11ad <isBalanced+0x4d>
movsbl -0x11(%rbp),%eax
cmp    $0x28,%eax
jne    11ba <isBalanced+0x5a>
mov    -0x20(%rbp),%rdi
movsbl -0x11(%rbp),%esi
call   1080 <pushDynArr@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x7d,%eax
je     11e1 <isBalanced+0x81>
movsbl -0x11(%rbp),%eax
cmp    $0x5d,%eax
je     11e1 <isBalanced+0x81>
movsbl -0x11(%rbp),%eax
cmp    $0x29,%eax
jne    129a <isBalanced+0x13a>
mov    -0x20(%rbp),%rdi
call   1040 <sizeDynArr@plt>
cmp    $0x0,%rax
jne    1200 <isBalanced+0xa0>
movl   $0x0,-0x4(%rbp)
jmp    12d2 <isBalanced+0x172>
movsbl -0x11(%rbp),%eax
cmp    $0x7d,%eax
jne    1230 <isBalanced+0xd0>
mov    -0x20(%rbp),%rdi
call   1030 <topDynArr@plt>
movsbl %al,%eax
cmp    $0x7b,%eax
jne    122b <isBalanced+0xcb>
mov    -0x20(%rbp),%rdi
call   1060 <popDynArr@plt>
jmp    1230 <isBalanced+0xd0>
movsbl -0x11(%rbp),%eax
cmp    $0x5d,%eax
jne    1260 <isBalanced+0x100>
mov    -0x20(%rbp),%rdi
call   1030 <topDynArr@plt>
movsbl %al,%eax
cmp    $0x5b,%eax
jne    125b <isBalanced+0xfb>
mov    -0x20(%rbp),%rdi
call   1060 <popDynArr@plt>
jmp    1260 <isBalanced+0x100>
movsbl -0x11(%rbp),%eax
cmp    $0x29,%eax
jne    1290 <isBalanced+0x130>
mov    -0x20(%rbp),%rdi
call   1030 <topDynArr@plt>
movsbl %al,%eax
cmp    $0x28,%eax
jne    128b <isBalanced+0x12b>
mov    -0x20(%rbp),%rdi
call   1060 <popDynArr@plt>
jmp    1290 <isBalanced+0x130>
jmp    1295 <isBalanced+0x135>
jmp    129a <isBalanced+0x13a>
jmp    129f <isBalanced+0x13f>
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    117a <isBalanced+0x1a>
mov    -0x20(%rbp),%rdi
call   1040 <sizeDynArr@plt>
cmp    $0x0,%rax
jne    12cb <isBalanced+0x16b>
movl   $0x1,-0x4(%rbp)
jmp    12d2 <isBalanced+0x172>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isBalanced>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x2,%edi
call   1070 <newDynArr@plt>
mov    %rax,%r15
lea    0xe81(%rip),%r12
jmp    1198 <isBalanced+0x38>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1060 <popDynArr@plt>
mov    %r14,%rdi
call   1050 <nextChar@plt>
mov    %eax,%ebx
cmp    $0x5a,%al
jle    11c0 <isBalanced+0x60>
lea    -0x5b(%rbx),%eax
cmp    $0x22,%al
ja     1198 <isBalanced+0x38>
movzbl %al,%eax
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
nopl   0x0(%rax)
cmp    $0x28,%bl
je     11e0 <isBalanced+0x80>
cmp    $0x29,%bl
je     1200 <isBalanced+0xa0>
test   %bl,%bl
jne    1198 <isBalanced+0x38>
jmp    126d <isBalanced+0x10d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %bl,%esi
mov    %r15,%rdi
call   1080 <pushDynArr@plt>
cmp    $0x29,%bl
je     1200 <isBalanced+0xa0>
cmp    $0x5d,%bl
jne    1198 <isBalanced+0x38>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1040 <sizeDynArr@plt>
test   %rax,%rax
je     125f <isBalanced+0xff>
cmp    $0x29,%bl
je     1235 <isBalanced+0xd5>
cmp    $0x5d,%bl
je     124a <isBalanced+0xea>
cmp    $0x7d,%bl
jne    1198 <isBalanced+0x38>
mov    %r15,%rdi
call   1030 <topDynArr@plt>
cmp    $0x7b,%al
jne    1198 <isBalanced+0x38>
jmp    1190 <isBalanced+0x30>
mov    %r15,%rdi
call   1030 <topDynArr@plt>
cmp    $0x28,%al
jne    1198 <isBalanced+0x38>
jmp    1190 <isBalanced+0x30>
mov    %r15,%rdi
call   1030 <topDynArr@plt>
cmp    $0x5b,%al
jne    1198 <isBalanced+0x38>
jmp    1190 <isBalanced+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %r15,%rdi
call   1040 <sizeDynArr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
sete   %al
jmp    1261 <isBalanced+0x101>

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

LLVM IR (-O2):
%struct.DynArr = type { i32 }
define i32 @isBalanced(i8* %0) {
%2 = tail call %struct.DynArr* @newDynArr(i32 2)
br label %3
3: ; preds = %9, %1
%4 = tail call signext i8 @nextChar(i8* %0)
switch i8 %4, label %9 [
i8 123, label %5
i8 91, label %5
i8 40, label %5
i8 125, label %10
i8 93, label %10
i8 41, label %10
i8 0, label %23
]
5: ; preds = %3, %3, %3
%6 = tail call i32 @pushDynArr(%struct.DynArr* %2, i8 signext %4)
switch i8 %4, label %9 [
i8 41, label %10
i8 93, label %10
]
7: ; preds = %20, %17, %14
%8 = tail call i32 @popDynArr(%struct.DynArr* %2)
br label %9
9: ; preds = %7, %20, %17, %14, %5, %13, %3
br label %3
10: ; preds = %5, %3, %3, %3, %5
%11 = tail call i64 @sizeDynArr(%struct.DynArr* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %27, label %13
13: ; preds = %10
switch i8 %4, label %9 [
i8 125, label %14
i8 93, label %17
i8 41, label %20
]
14: ; preds = %13
%15 = tail call signext i8 @topDynArr(%struct.DynArr* %2)
%16 = icmp eq i8 %15, 123
br i1 %16, label %7, label %9
17: ; preds = %13
%18 = tail call signext i8 @topDynArr(%struct.DynArr* %2)
%19 = icmp eq i8 %18, 91
br i1 %19, label %7, label %9
20: ; preds = %13
%21 = tail call signext i8 @topDynArr(%struct.DynArr* %2)
%22 = icmp eq i8 %21, 40
br i1 %22, label %7, label %9
23: ; preds = %3
%24 = tail call i64 @sizeDynArr(%struct.DynArr* %2)
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
br label %27
27: ; preds = %10, %23
%28 = phi i32 [ %26, %23 ], [ 0, %10 ]
ret i32 %28
}