#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;
  int p = 1;
  while (c != EOF) {
    c = getchar();
    if (c == '(')
      n++;
    if (c == ')')
      n--;
    if (n < 0) {
      printf("%d\n", p);
      break;
    }
    p++;
  }
  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)
movl   $0x1,-0x1c(%rbp)
movsbl -0x11(%rbp),%eax
mov    0x2e95(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11c0 <main+0xa0>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x28,%eax
jne    117e <main+0x5e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x29,%eax
jne    1194 <main+0x74>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11b2 <main+0x92>
mov    -0x1c(%rbp),%esi
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
jmp    11c0 <main+0xa0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1148 <main+0x28>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2ebd(%rip),%r14
cmpb   $0x0,(%r14)
je     1173 <main+0x53>
mov    $0x1,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
xor    %ecx,%ecx
cmp    $0x28,%al
sete   %cl
add    %ecx,%ebp
xor    %ecx,%ecx
cmp    $0x29,%al
sete   %cl
sub    %ecx,%ebp
js     1165 <main+0x45>
add    $0x1,%ebx
cmp    (%r14),%al
jne    1140 <main+0x20>
jmp    1173 <main+0x53>
lea    0xe94(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
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
%8 = 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
store i32 1, i32* %8
br label %9
9: ; preds = %36, %2
%10 = load i8, i8* %6
%11 = sext i8 %10 to i32
%12 = load i8, i8* @EOF
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %11, %13
br i1 %14, label %15, label %39
15: ; preds = %9
%16 = call signext i8 (...) @getchar()
store i8 %16, i8* %6
%17 = load i8, i8* %6
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 40
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 1
store i32 %22, i32* %7
br label %23
23: ; preds = %20, %15
%24 = load i8, i8* %6
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 41
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* %7
%29 = add nsw i32 %28, -1
store i32 %29, i32* %7
br label %30
30: ; preds = %27, %23
%31 = load i32, i32* %7
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %8
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %34)
br label %39
36: ; preds = %30
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %9
39: ; preds = %33, %9
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 %22, label %5
5: ; preds = %2, %18
%6 = phi i32 [ %19, %18 ], [ 1, %2 ]
%7 = phi i32 [ %14, %18 ], [ 0, %2 ]
%8 = tail call signext i8 (...) @getchar()
%9 = icmp eq i8 %8, 40
%10 = zext i1 %9 to i32
%11 = add nuw nsw i32 %7, %10
%12 = icmp eq i8 %8, 41
%13 = sext i1 %12 to i32
%14 = add nsw i32 %11, %13
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %5
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %6)
br label %22
18: ; preds = %5
%19 = add nuw nsw i32 %6, 1
%20 = load i8, i8* @EOF
%21 = icmp eq i8 %8, %20
br i1 %21, label %22, label %5
22: ; preds = %18, %2, %16
ret i32 0
}