#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 dirtoindex(char *);
scalar_t__ isalpha(char const);
char tolower(char const);
int checkdir(const char *dir) {
  if (isalpha(dir[0])) {
    char d[3];
    int i;
    for (i = 0; i < 2; i++) {
      d[i] = tolower(dir[0]);
    }
    d[2] = '\0';
    i = dirtoindex(d);
    return (0 <= i && i <= 7);
  }
  return 0;
}


x86 assembly (clang, -O0):
<checkdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isalpha@plt>
cmp    $0x0,%rax
je     11c1 <checkdir+0x91>
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x18(%rbp)
jge    1187 <checkdir+0x57>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1040 <tolower@plt>
mov    %al,%cl
movslq -0x18(%rbp),%rax
mov    %cl,-0x13(%rbp,%rax,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1159 <checkdir+0x29>
movb   $0x0,-0x11(%rbp)
lea    -0x13(%rbp),%rdi
call   1030 <dirtoindex@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
xor    %ecx,%ecx
cmp    -0x18(%rbp),%ecx
mov    %al,-0x19(%rbp)
jg     11b1 <checkdir+0x81>
cmpl   $0x7,-0x18(%rbp)
setle  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
jmp    11c8 <checkdir+0x98>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkdir>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1050 <isalpha@plt>
test   %rax,%rax
je     1178 <checkdir+0x48>
movsbl (%rbx),%edi
call   1040 <tolower@plt>
mov    %al,0xd(%rsp)
movsbl (%rbx),%edi
call   1040 <tolower@plt>
mov    %al,0xe(%rsp)
movb   $0x0,0xf(%rsp)
lea    0xd(%rsp),%rdi
call   1030 <dirtoindex@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x8,%ecx
setb   %al
jmp    117a <checkdir+0x4a>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @checkdir(i8* nocapture %0) {
%2 = alloca [3 x i8]
%3 = load i8, i8* %0
%4 = tail call i64 @isalpha(i8 signext %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %17, label %6
6: ; preds = %1
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%8 = load i8, i8* %0
%9 = tail call signext i8 @tolower(i8 signext %8)
store i8 %9, i8* %7
%10 = load i8, i8* %0
%11 = tail call signext i8 @tolower(i8 signext %10)
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
store i8 %11, i8* %12
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
store i8 0, i8* %13
%14 = call i32 @dirtoindex(i8* %7)
%15 = icmp ult i32 %14, 8
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %1, %6
%18 = phi i32 [ %16, %6 ], [ 0, %1 ]
ret i32 %18
}