#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*/ printErrorMsg();
int main() {
  int c;
  int parenthesis = 0;
  while ((c = getchar()) != EOF) {
    if (c == '(') {
      ++parenthesis;
    } else if (c == ')') {
      --parenthesis;
    }
    if (parenthesis < 0) {
      printErrorMsg();
      parenthesis = 0;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2ea1(%rip),%rcx
cmp    (%rcx),%eax
je     119c <main+0x7c>
cmpl   $0x28,-0x8(%rbp)
jne    1167 <main+0x47>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117f <main+0x5f>
cmpl   $0x29,-0x8(%rbp)
jne    117a <main+0x5a>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    117f <main+0x5f>
cmpl   $0x0,-0xc(%rbp)
jge    1197 <main+0x77>
mov    $0x0,%al
call   1040 <printErrorMsg@plt>
movl   $0x0,-0xc(%rbp)
jmp    1136 <main+0x16>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getchar@plt>
mov    0x2eb7(%rip),%rbx
cmp    (%rbx),%eax
jne    113e <main+0x1e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %ebp,%ebp
jmp    115b <main+0x3b>
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printErrorMsg@plt>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    (%rbx),%eax
je     1135 <main+0x15>
cmp    $0x29,%eax
je     1170 <main+0x50>
cmp    $0x28,%eax
jne    1150 <main+0x30>
add    $0x1,%ebp
jmp    1150 <main+0x30>
nopw   0x0(%rax,%rax,1)
test   %ebp,%ebp
jle    1142 <main+0x22>
add    $0xffffffff,%ebp
jmp    1150 <main+0x30>

LLVM IR (-O0):
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
br label %4
4: ; preds = %26, %0
%5 = call i32 (...) @getchar()
store i32 %5, i32* %2
%6 = load i32, i32* @EOF
%7 = icmp ne i32 %5, %6
br i1 %7, label %8, label %27
8: ; preds = %4
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 40
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* %3
%13 = add nsw i32 %12, 1
store i32 %13, i32* %3
br label %21
14: ; preds = %8
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 41
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %3
%19 = add nsw i32 %18, -1
store i32 %19, i32* %3
br label %20
20: ; preds = %17, %14
br label %21
21: ; preds = %20, %11
%22 = load i32, i32* %3
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 (...) @printErrorMsg()
store i32 0, i32* %3
br label %26
26: ; preds = %24, %21
br label %4
27: ; preds = %4
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @getchar()
%2 = load i32, i32* @EOF
%3 = icmp eq i32 %1, %2
br i1 %3, label %19, label %4
4: ; preds = %0, %14
%5 = phi i32 [ %16, %14 ], [ %1, %0 ]
%6 = phi i32 [ %15, %14 ], [ 0, %0 ]
switch i32 %5, label %14 [
i32 40, label %7
i32 41, label %9
]
7: ; preds = %4
%8 = add nuw nsw i32 %6, 1
br label %14
9: ; preds = %4
%10 = add nsw i32 %6, -1
%11 = icmp slt i32 %6, 1
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 (...) @printErrorMsg()
br label %14
14: ; preds = %4, %7, %12, %9
%15 = phi i32 [ 0, %12 ], [ %10, %9 ], [ %6, %4 ], [ %8, %7 ]
%16 = tail call i32 (...) @getchar()
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %4
19: ; preds = %14, %0
ret i32 0
}