#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__ isalpha(int);
scalar_t__ strchr(char const *, int);
int strlen(char const *);
int tolower(char const);
int first_alpha(const char *string, const char *exempt) {
  int i, in_paren = 0, c;
  for (i = 0; i < strlen(string); i++) {
    c = tolower(string[i]);
    if (strchr("<[(", c))
      ++in_paren;
    if (strchr(">])", c) && in_paren > 0)
      --in_paren;
    if ((!in_paren) && isalpha(c) && strchr(exempt, c) == 0)
      return i;
  }
  return 0;
}


x86 assembly (clang, -O0):
<first_alpha>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jge    122c <first_alpha+0xec>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <tolower@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe68(%rip),%rdi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11b0 <first_alpha+0x70>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe4a(%rip),%rdi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11dc <first_alpha+0x9c>
cmpl   $0x0,-0x20(%rbp)
jle    11dc <first_alpha+0x9c>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1219 <first_alpha+0xd9>
mov    -0x24(%rbp),%edi
call   1060 <isalpha@plt>
cmp    $0x0,%rax
je     1219 <first_alpha+0xd9>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
jne    1219 <first_alpha+0xd9>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1233 <first_alpha+0xf3>
jmp    121e <first_alpha+0xde>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115e <first_alpha+0x1e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<first_alpha>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,(%rsp)
mov    %rdi,%r15
call   1030 <strlen@plt>
xor    %ebx,%ebx
test   %eax,%eax
jle    11f1 <first_alpha+0xb1>
lea    0xe98(%rip),%r12
lea    0xe95(%rip),%r13
xor    %r14d,%r14d
jmp    1193 <first_alpha+0x53>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11ef <first_alpha+0xaf>
movsbl (%r15,%rbx,1),%edi
call   1050 <tolower@plt>
mov    %eax,%ebp
mov    %r12,%rdi
mov    %eax,%esi
call   1040 <strchr@plt>
cmp    $0x1,%rax
sbb    $0xffffffff,%r14d
mov    %r13,%rdi
mov    %ebp,%esi
call   1040 <strchr@plt>
test   %rax,%rax
setne  %al
test   %r14d,%r14d
setg   %cl
and    %al,%cl
movzbl %cl,%eax
sub    %eax,%r14d
jne    1180 <first_alpha+0x40>
mov    %ebp,%edi
call   1060 <isalpha@plt>
test   %rax,%rax
je     1180 <first_alpha+0x40>
mov    (%rsp),%rdi
mov    %ebp,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1180 <first_alpha+0x40>
jmp    11f1 <first_alpha+0xb1>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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