#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__ strncmp(char *, char *, int);
char *strtolower(char *);
int getDirectionIndex(char *src) {
  char *word = strtolower(src);
  if (strncmp(word, "east", 4) == 0)
    return 0;
  else if (strncmp(word, "north", 5) == 0)
    return 1;
  else if (strncmp(word, "west", 4) == 0)
    return 2;
  else if (strncmp(word, "south", 5) == 0)
    return 3;
  else
    return -1;
}


x86 assembly (clang, -O0):
<getDirectionIndex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strtolower@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xebc(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1164 <getDirectionIndex+0x44>
movl   $0x0,-0x4(%rbp)
jmp    11ec <getDirectionIndex+0xcc>
mov    -0x18(%rbp),%rdi
lea    0xe96(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    118f <getDirectionIndex+0x6f>
movl   $0x1,-0x4(%rbp)
jmp    11ec <getDirectionIndex+0xcc>
mov    -0x18(%rbp),%rdi
lea    0xe71(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11ba <getDirectionIndex+0x9a>
movl   $0x2,-0x4(%rbp)
jmp    11ec <getDirectionIndex+0xcc>
mov    -0x18(%rbp),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11e5 <getDirectionIndex+0xc5>
movl   $0x3,-0x4(%rbp)
jmp    11ec <getDirectionIndex+0xcc>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDirectionIndex>:
push   %rbx
call   1040 <strtolower@plt>
mov    %rax,%rbx
lea    0xed0(%rip),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1192 <getDirectionIndex+0x72>
lea    0xebc(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1196 <getDirectionIndex+0x76>
lea    0xea9(%rip),%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     119d <getDirectionIndex+0x7d>
lea    0xe95(%rip),%rsi
mov    %rbx,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
neg    %rax
sbb    %eax,%eax
or     $0x3,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret
mov    $0x2,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"east\00"
@.str.1 = [6 x i8] c"north\00"
@.str.2 = [5 x i8] c"west\00"
@.str.3 = [6 x i8] c"south\00"
define i32 @getDirectionIndex(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @strtolower(i8* %5)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %27
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 1, i32* %2
br label %27
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = call i64 @strncmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 2, i32* %2
br label %27
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = call i64 @strncmp(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 3, i32* %2
br label %27
26: ; preds = %21
store i32 -1, i32* %2
br label %27
27: ; preds = %26, %25, %20, %15, %10
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [5 x i8] c"east\00"
@.str.1 = [6 x i8] c"north\00"
@.str.2 = [5 x i8] c"west\00"
@.str.3 = [6 x i8] c"south\00"
define i32 @getDirectionIndex(i8* %0) {
%2 = tail call i8* @strtolower(i8* %0)
%3 = tail call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%4 = icmp eq i64 %3, 0
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = tail call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %15, label %8
8: ; preds = %5
%9 = tail call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = tail call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 5)
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i32 3, i32 -1
br label %15
15: ; preds = %11, %8, %5, %1
%16 = phi i32 [ 0, %1 ], [ 1, %5 ], [ 2, %8 ], [ %14, %11 ]
ret i32 %16
}