#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 */
scalar_t__ strcmp(char *, char *);
int findParen(char **tokens, int start, int finish, int firstParenLocation) {
  int parenCount = 0, j = 0;
  for (j = firstParenLocation; j < finish; j++) {
    if (strcmp(tokens[j], "(") == 0)
      parenCount++;
    else if (strcmp(tokens[j], ")") == 0)
      parenCount--;
    if (parenCount == 0 && j != start)
      break;
  }
  return j;
}


x86 assembly (clang, -O0):
<findParen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11d3 <findParen+0xc3>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xea8(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1175 <findParen+0x65>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a5 <findParen+0x95>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe7a(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11a0 <findParen+0x90>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    11a5 <findParen+0x95>
cmpl   $0x0,-0x18(%rbp)
jne    11c0 <findParen+0xb0>
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     11c0 <findParen+0xb0>
jmp    11d3 <findParen+0xc3>
jmp    11c5 <findParen+0xb5>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1139 <findParen+0x29>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findParen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebx
cmp    %edx,%ecx
jge    1194 <findParen+0x84>
mov    %edx,%r14d
mov    %rdi,%rbp
movslq %ebx,%rbx
movslq %esi,%r13
xor    %r12d,%r12d
lea    0xec9(%rip),%r15
jmp    1149 <findParen+0x39>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %ebx,%r14d
je     1191 <findParen+0x81>
mov    0x0(%rbp,%rbx,8),%rdi
mov    %r15,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     1180 <findParen+0x70>
mov    0x0(%rbp,%rbx,8),%rdi
lea    0xe9b(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x1,%rax
sbb    %eax,%eax
add    %eax,%r12d
je     118a <findParen+0x7a>
jmp    1140 <findParen+0x30>
nopl   0x0(%rax)
mov    $0x1,%eax
add    %eax,%r12d
jne    1140 <findParen+0x30>
cmp    %rbx,%r13
je     1140 <findParen+0x30>
jmp    1194 <findParen+0x84>
mov    %r14d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"(\00"
@.str.1 = [2 x i8] c")\00"
define i32 @findParen(i8** nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp slt i32 %3, %2
br i1 %5, label %6, label %33
6: ; preds = %4
%7 = sext i32 %3 to i64
%8 = sext i32 %1 to i64
br label %9
9: ; preds = %6, %27
%10 = phi i64 [ %7, %6 ], [ %28, %27 ]
%11 = phi i32 [ 0, %6 ], [ %23, %27 ]
%12 = getelementptr inbounds i8*, i8** %0, i64 %10
%13 = load i8*, i8** %12
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %9
%17 = load i8*, i8** %12
%18 = tail call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
%20 = sext i1 %19 to i32
br label %21
21: ; preds = %9, %16
%22 = phi i32 [ %20, %16 ], [ 1, %9 ]
%23 = add nsw i32 %11, %22
%24 = icmp ne i32 %23, 0
%25 = icmp eq i64 %10, %8
%26 = select i1 %24, i1 true, i1 %25
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = add nsw i64 %10, 1
%29 = trunc i64 %28 to i32
%30 = icmp eq i32 %29, %2
br i1 %30, label %33, label %9
31: ; preds = %21
%32 = trunc i64 %10 to i32
br label %33
33: ; preds = %27, %31, %4
%34 = phi i32 [ %3, %4 ], [ %32, %31 ], [ %2, %27 ]
ret i32 %34
}