#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 */
char EOF;
char getchar();
int /*<<< orphan*/ printf(char *, int);
int main(int argc, char *argv[]) {
  char c = '\0';
  int n = 0;
  while (c != EOF) {
    c = '\0';
    n = 0;
    while (c != '\n') {
      c = getchar();
      if (c == '(')
        n++;
      if (c == ')')
        n--;
      if (c == EOF)
        break;
    }
    printf("%d\n", n);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
movsbl -0x11(%rbp),%eax
mov    0x2e9c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11d9 <main+0xb9>
movb   $0x0,-0x11(%rbp)
movl   $0x0,-0x18(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
je     11c5 <main+0xa5>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x28,%eax
jne    118f <main+0x6f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x29,%eax
jne    11a5 <main+0x85>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
movsbl -0x11(%rbp),%eax
mov    0x2e38(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11c0 <main+0xa0>
jmp    11c5 <main+0xa5>
jmp    1162 <main+0x42>
mov    -0x18(%rbp),%esi
lea    0xe31(%rip),%rdi
call   1030 <printf@plt>
jmp    1141 <main+0x21>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2eba(%rip),%r15
cmpb   $0x0,(%r15)
je     117d <main+0x5d>
lea    0xec5(%rip),%r14
xor    %ebp,%ebp
jmp    1154 <main+0x34>
nop
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    $0x0,%ebp
cmp    (%r15),%bl
je     117d <main+0x5d>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
cmp    $0x28,%bl
sete   %al
add    %eax,%ebp
xor    %eax,%eax
cmp    $0x29,%bl
sete   %al
sub    %eax,%ebp
cmp    $0xa,%bl
je     1140 <main+0x20>
cmp    (%r15),%bl
jne    1154 <main+0x34>
jmp    1140 <main+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i8 0
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 0, i8* %6
store i32 0, i32* %7
br label %8
8: ; preds = %42, %2
%9 = load i8, i8* %6
%10 = sext i8 %9 to i32
%11 = load i8, i8* @EOF
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %10, %12
br i1 %13, label %14, label %45
14: ; preds = %8
store i8 0, i8* %6
store i32 0, i32* %7
br label %15
15: ; preds = %41, %14
%16 = load i8, i8* %6
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 10
br i1 %18, label %19, label %42
19: ; preds = %15
%20 = call signext i8 (...) @getchar()
store i8 %20, i8* %6
%21 = load i8, i8* %6
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 40
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %27
27: ; preds = %24, %19
%28 = load i8, i8* %6
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 41
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = load i32, i32* %7
%33 = add nsw i32 %32, -1
store i32 %33, i32* %7
br label %34
34: ; preds = %31, %27
%35 = load i8, i8* %6
%36 = sext i8 %35 to i32
%37 = load i8, i8* @EOF
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %36, %38
br i1 %39, label %40, label %41
40: ; preds = %34
br label %42
41: ; preds = %34
br label %15
42: ; preds = %40, %15
%43 = load i32, i32* %7
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %43)
br label %8
45: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@EOF = global i8 0
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i8, i8* @EOF
%4 = icmp eq i8 %3, 0
br i1 %4, label %24, label %5
5: ; preds = %2, %18
%6 = phi i32 [ %19, %18 ], [ 0, %2 ]
%7 = tail call signext i8 (...) @getchar()
%8 = icmp eq i8 %7, 40
%9 = zext i1 %8 to i32
%10 = add nsw i32 %6, %9
%11 = icmp eq i8 %7, 41
%12 = sext i1 %11 to i32
%13 = add nsw i32 %10, %12
%14 = load i8, i8* @EOF
%15 = icmp ne i8 %7, %14
%16 = icmp ne i8 %7, 10
%17 = and i1 %16, %15
br i1 %17, label %18, label %20
18: ; preds = %5, %20
%19 = phi i32 [ %13, %5 ], [ 0, %20 ]
br label %5
20: ; preds = %5
%21 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%22 = load i8, i8* @EOF
%23 = icmp eq i8 %7, %22
br i1 %23, label %24, label %18
24: ; preds = %20, %2
ret i32 0
}