#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 EOF;
int getchar();
int /*<<< orphan*/ in_comment();
int /*<<< orphan*/ in_quote(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ search(int);
main() {
  int c;
  extern int brace, brack, paren;
  while ((c = getchar()) != EOF) {
    if (c == '/') {
      if ((c = getchar()) == '*')
        in_comment();
      else
        search(c);
    } else if (c == '\'' || c == '"')
      in_quote(c);
    else
      search(c);
    if (brace < 0) {
      printf("Unbalanced braces\n");
      brace = 0;
    } else if (brack < 0) {
      printf("Unbalanced brackets\n");
    } else if (paren < 0) {
      printf("Unbalanced parentheses\n");
      paren = 0;
    }
  }
  if (brace > 0)
    printf("Unbalanced braces\n");
  if (brack > 0)
    printf("Unbalanced brackets\n");
  if (paren > 0)
    printf("Unbalanced parentheses\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%eax
je     1263 <main+0x113>
cmpl   $0x2f,-0x8(%rbp)
jne    11ae <main+0x5e>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x2a,%eax
jne    11a1 <main+0x51>
mov    $0x0,%al
call   1030 <in_comment@plt>
jmp    11a9 <main+0x59>
mov    -0x8(%rbp),%edi
call   1050 <search@plt>
jmp    11dc <main+0x8c>
cmpl   $0x27,-0x8(%rbp)
je     11c2 <main+0x72>
cmpl   $0x22,-0x8(%rbp)
jne    11cf <main+0x7f>
mov    -0x8(%rbp),%edi
call   1070 <in_quote@plt>
jmp    11d7 <main+0x87>
mov    -0x8(%rbp),%edi
call   1050 <search@plt>
jmp    11dc <main+0x8c>
mov    0x2ddd(%rip),%rax
cmpl   $0x0,(%rax)
jge    120a <main+0xba>
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dc1(%rip),%rax
movl   $0x0,(%rax)
jmp    125e <main+0x10e>
mov    0x2ddf(%rip),%rax
cmpl   $0x0,(%rax)
jge    122b <main+0xdb>
lea    0xdf2(%rip),%rdi
call   1040 <printf@plt>
jmp    1259 <main+0x109>
mov    0x2d9e(%rip),%rax
cmpl   $0x0,(%rax)
jge    1254 <main+0x104>
lea    0xde6(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d82(%rip),%rax
movl   $0x0,(%rax)
jmp    1259 <main+0x109>
jmp    125e <main+0x10e>
jmp    115f <main+0xf>
mov    0x2d56(%rip),%rax
cmpl   $0x0,(%rax)
jle    127f <main+0x12f>
lea    0xd86(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d6a(%rip),%rax
cmpl   $0x0,(%rax)
jle    129b <main+0x14b>
lea    0xd7d(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d2e(%rip),%rax
cmpl   $0x0,(%rax)
jle    12b7 <main+0x167>
lea    0xd76(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e77(%rip),%r13
cmp    0x0(%r13),%eax
jne    11c8 <main+0x78>
mov    0x2e4a(%rip),%rax
cmpl   $0x0,(%rax)
jle    1187 <main+0x37>
lea    0xea9(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e62(%rip),%rax
cmpl   $0x0,(%rax)
jle    119f <main+0x4f>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e2a(%rip),%rax
cmpl   $0x0,(%rax)
jle    11b7 <main+0x67>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df1(%rip),%rbx
lea    0xe55(%rip),%r12
mov    0x2e13(%rip),%rbp
lea    0xe33(%rip),%r14
mov    0x2de5(%rip),%r15
jmp    120f <main+0xbf>
nopl   (%rax)
mov    %r12,%rdi
call   1030 <puts@plt>
movl   $0x0,(%rbx)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    0x0(%r13),%eax
je     116f <main+0x1f>
cmp    $0x22,%eax
je     1240 <main+0xf0>
cmp    $0x27,%eax
je     1240 <main+0xf0>
cmp    $0x2f,%eax
jne    1250 <main+0x100>
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0x2a,%eax
jne    1250 <main+0x100>
xor    %eax,%eax
call   1040 <in_comment@plt>
cmpl   $0x0,(%rbx)
jns    125c <main+0x10c>
jmp    11f0 <main+0xa0>
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1070 <in_quote@plt>
cmpl   $0x0,(%rbx)
jns    125c <main+0x10c>
jmp    11f0 <main+0xa0>
xchg   %ax,%ax
mov    %eax,%edi
call   1050 <search@plt>
cmpl   $0x0,(%rbx)
js     11f0 <main+0xa0>
cmpl   $0x0,0x0(%rbp)
js     1280 <main+0x130>
cmpl   $0x0,(%r15)
jns    11fe <main+0xae>
lea    0xd91(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,(%r15)
jmp    11fe <main+0xae>
nopl   (%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    11fe <main+0xae>

LLVM IR (-O0):
@EOF = global i32 0
@brace = external global i32
@.str = [19 x i8] c"Unbalanced braces\0A\00"
@brack = external global i32
@.str.1 = [21 x i8] c"Unbalanced brackets\0A\00"
@paren = external global i32
@.str.2 = [24 x i8] c"Unbalanced parentheses\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %49, %0
%4 = call i32 (...) @getchar()
store i32 %4, i32* %2
%5 = load i32, i32* @EOF
%6 = icmp ne i32 %4, %5
br i1 %6, label %7, label %50
7: ; preds = %3
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, 47
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = call i32 (...) @getchar()
store i32 %11, i32* %2
%12 = icmp eq i32 %11, 42
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (...) @in_comment()
br label %18
15: ; preds = %10
%16 = load i32, i32* %2
%17 = call i32 @search(i32 %16)
br label %18
18: ; preds = %15, %13
br label %32
19: ; preds = %7
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, 39
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %2
%24 = icmp eq i32 %23, 34
br i1 %24, label %25, label %28
25: ; preds = %22, %19
%26 = load i32, i32* %2
%27 = call i32 @in_quote(i32 %26)
br label %31
28: ; preds = %22
%29 = load i32, i32* %2
%30 = call i32 @search(i32 %29)
br label %31
31: ; preds = %28, %25
br label %32
32: ; preds = %31, %18
%33 = load i32, i32* @brace
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* @brace
br label %49
37: ; preds = %32
%38 = load i32, i32* @brack
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %48
42: ; preds = %37
%43 = load i32, i32* @paren
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* @paren
br label %47
47: ; preds = %45, %42
br label %48
48: ; preds = %47, %40
br label %49
49: ; preds = %48, %35
br label %3
50: ; preds = %3
%51 = load i32, i32* @brace
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %55
55: ; preds = %53, %50
%56 = load i32, i32* @brack
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %55
%59 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %60
60: ; preds = %58, %55
%61 = load i32, i32* @paren
%62 = icmp sgt i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %60
%64 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
br label %65
65: ; preds = %63, %60
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
@EOF = global i32 0
@brace = external global i32
@brack = external global i32
@paren = external global i32
@str.5 = [23 x i8] c"Unbalanced parentheses\00"
@str.6 = [20 x i8] c"Unbalanced brackets\00"
@str.7 = [18 x i8] c"Unbalanced braces\00"
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %36, label %4
4: ; preds = %0, %32
%5 = phi i32 [ %33, %32 ], [ %1, %0 ]
switch i32 %5, label %15 [
i32 47, label %6
i32 39, label %13
i32 34, label %13
]
6: ; preds = %4
%7 = tail call i32 (...) @getchar()
%8 = icmp eq i32 %7, 42
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 (...) @in_comment()
br label %17
11: ; preds = %6
%12 = tail call i32 @search(i32 %7)
br label %17
13: ; preds = %4, %4
%14 = tail call i32 @in_quote(i32 %5)
br label %17
15: ; preds = %4
%16 = tail call i32 @search(i32 %5)
br label %17
17: ; preds = %13, %15, %9, %11
%18 = load i32, i32* @brace
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.7, i64 0, i64 0))
store i32 0, i32* @brace
br label %32
22: ; preds = %17
%23 = load i32, i32* @brack
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0))
br label %32
27: ; preds = %22
%28 = load i32, i32* @paren
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
store i32 0, i32* @paren
br label %32
32: ; preds = %25, %30, %27, %20
%33 = tail call i32 (...) @getchar()
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %4
36: ; preds = %32, %0
%37 = load i32, i32* @brace
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.7, i64 0, i64 0))
br label %41
41: ; preds = %39, %36
%42 = load i32, i32* @brack
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.6, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
%47 = load i32, i32* @paren
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.5, i64 0, i64 0))
br label %51
51: ; preds = %49, %46
ret i32 0
}