#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 /*<<< orphan*/ isalpha(char const);
scalar_t__ islower(char const);
int capstate(const char *varname) {
  if (islower(varname[0]))
    return 0;
  if (islower(varname[1]))
    return 2;
  if (!isalpha(varname[1]) && varname[1] != 0 && islower(varname[2]))
    return 2;
  else
    return 1;
}


x86 assembly (clang, -O0):
<capstate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     114e <capstate+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <capstate+0xa2>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     1171 <capstate+0x51>
movl   $0x2,-0x4(%rbp)
jmp    11c2 <capstate+0xa2>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <isalpha@plt>
cmp    $0x0,%eax
jne    11bb <capstate+0x9b>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     11bb <capstate+0x9b>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <islower@plt>
cmp    $0x0,%rax
je     11bb <capstate+0x9b>
movl   $0x2,-0x4(%rbp)
jmp    11c2 <capstate+0xa2>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<capstate>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <islower@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    115a <capstate+0x3a>
movsbl 0x1(%rbx),%edi
call   1030 <islower@plt>
mov    $0x2,%ebp
test   %rax,%rax
jne    115a <capstate+0x3a>
movsbl 0x1(%rbx),%edi
call   1040 <isalpha@plt>
test   %eax,%eax
je     1163 <capstate+0x43>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
cmpb   $0x0,0x1(%rbx)
je     1155 <capstate+0x35>
movsbl 0x2(%rbx),%edi
call   1030 <islower@plt>
test   %rax,%rax
jne    115a <capstate+0x3a>
jmp    1155 <capstate+0x35>

LLVM IR (-O0):
define i32 @capstate(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = call i64 @islower(i8 signext %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %37
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = call i64 @islower(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
store i32 2, i32* %2
br label %37
17: ; preds = %10
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i8, i8* %19
%21 = call i32 @isalpha(i8 signext %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %36, label %23
23: ; preds = %17
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %23
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i64 2
%32 = load i8, i8* %31
%33 = call i64 @islower(i8 signext %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 2, i32* %2
br label %37
36: ; preds = %29, %23, %17
store i32 1, i32* %2
br label %37
37: ; preds = %36, %35, %16, %9
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
define i32 @capstate(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i64 @islower(i8 signext %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %23
5: ; preds = %1
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = load i8, i8* %6
%8 = tail call i64 @islower(i8 signext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %5
%11 = load i8, i8* %6
%12 = tail call i32 @isalpha(i8 signext %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load i8, i8* %6
%16 = icmp eq i8 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %14
%18 = getelementptr inbounds i8, i8* %0, i64 2
%19 = load i8, i8* %18
%20 = tail call i64 @islower(i8 signext %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %17, %14, %10
br label %23
23: ; preds = %17, %5, %1, %22
%24 = phi i32 [ 1, %22 ], [ 0, %1 ], [ 2, %5 ], [ 2, %17 ]
ret i32 %24
}