int get_index(char str[4]) {
  char names[15][4] = {
      "GEN", "LTG", "MJG", "COL", "LTC", "MAJ", "CPT", "1LT",
      "2LT", "PLA", "TNK", "CAV", "ENG", "SPY", "MIN",
  };
  int i;
  for (i = 0; i < 15; i++) {
    if (strcmp(str, names[i]) == 0) {
      return i;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xec9(%rip),%rsi
mov    $0x3c,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0xf,-0x54(%rbp)
jge    1191 <get_index+0x71>
mov    -0x10(%rbp),%rdi
movslq -0x54(%rbp),%rax
lea    -0x50(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    117e <get_index+0x5e>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1198 <get_index+0x78>
jmp    1183 <get_index+0x63>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    1148 <get_index+0x28>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_index>:
push   %rbx
mov    %rdi,%rbx
lea    0xee5(%rip),%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1263 <get_index+0x153>
lea    0xed5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1267 <get_index+0x157>
lea    0xec2(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     126e <get_index+0x15e>
lea    0xeaf(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1275 <get_index+0x165>
lea    0xe9c(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     127c <get_index+0x16c>
lea    0xe89(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1283 <get_index+0x173>
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     128a <get_index+0x17a>
lea    0xe63(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1291 <get_index+0x181>
lea    0xe50(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1298 <get_index+0x188>
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     129f <get_index+0x18f>
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     12a6 <get_index+0x196>
lea    0xe17(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     12ad <get_index+0x19d>
lea    0xe04(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     12b4 <get_index+0x1a4>
lea    0xdf5(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     12bb <get_index+0x1ab>
lea    0xde6(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
neg    %eax
sbb    %eax,%eax
or     $0xe,%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret
mov    $0x2,%eax
pop    %rbx
ret
mov    $0x3,%eax
pop    %rbx
ret
mov    $0x4,%eax
pop    %rbx
ret
mov    $0x5,%eax
pop    %rbx
ret
mov    $0x6,%eax
pop    %rbx
ret
mov    $0x7,%eax
pop    %rbx
ret
mov    $0x8,%eax
pop    %rbx
ret
mov    $0x9,%eax
pop    %rbx
ret
mov    $0xa,%eax
pop    %rbx
ret
mov    $0xb,%eax
pop    %rbx
ret
mov    $0xc,%eax
pop    %rbx
ret
mov    $0xd,%eax
pop    %rbx
ret

LLVM IR (-O0):
@__const.get_index.names = [15 x [4 x i8]] [[4 x i8] c"GEN\00", [4 x i8] c"LTG\00", [4 x i8] c"MJG\00", [4 x i8] c"COL\00", [4 x i8] c"LTC\00", [4 x i8] c"MAJ\00", [4 x i8] c"CPT\00", [4 x i8] c"1LT\00", [4 x i8] c"2LT\00", [4 x i8] c"PLA\00", [4 x i8] c"TNK\00", [4 x i8] c"CAV\00", [4 x i8] c"ENG\00", [4 x i8] c"SPY\00", [4 x i8] c"MIN\00"]
define i32 @get_index(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [15 x [4 x i8]]
%5 = alloca i32
store i8* %0, i8** %3
%6 = bitcast [15 x [4 x i8]]* %4 to i8*
store i32 0, i32* %5
br label %7
7: ; preds = %21, %1
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 15
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = load i8*, i8** %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [15 x [4 x i8]], [15 x [4 x i8]]* %4, i64 0, i64 %13
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %14, i64 0, i64 0
%16 = call i32 @strcmp(i8* %11, i8* %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = load i32, i32* %5
store i32 %19, i32* %2
br label %25
20: ; preds = %10
br label %21
21: ; preds = %20
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %7
24: ; preds = %7
store i32 -1, i32* %2
br label %25
25: ; preds = %24, %18
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@__const.get_index.names = [15 x [4 x i8]] [[4 x i8] c"GEN\00", [4 x i8] c"LTG\00", [4 x i8] c"MJG\00", [4 x i8] c"COL\00", [4 x i8] c"LTC\00", [4 x i8] c"MAJ\00", [4 x i8] c"CPT\00", [4 x i8] c"1LT\00", [4 x i8] c"2LT\00", [4 x i8] c"PLA\00", [4 x i8] c"TNK\00", [4 x i8] c"CAV\00", [4 x i8] c"ENG\00", [4 x i8] c"SPY\00", [4 x i8] c"MIN\00"]
define i32 @get_index(i8* nocapture %0) {
%2 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 0, i64 0))
%3 = icmp eq i32 %2, 0
br i1 %3, label %47, label %4
4: ; preds = %1
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 1, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %47, label %7
7: ; preds = %4
%8 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 2, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %47, label %10
10: ; preds = %7
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 3, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %47, label %13
13: ; preds = %10
%14 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 4, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %47, label %16
16: ; preds = %13
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 5, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %47, label %19
19: ; preds = %16
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 6, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %47, label %22
22: ; preds = %19
%23 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 7, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %47, label %25
25: ; preds = %22
%26 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 8, i64 0))
%27 = icmp eq i32 %26, 0
br i1 %27, label %47, label %28
28: ; preds = %25
%29 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 9, i64 0))
%30 = icmp eq i32 %29, 0
br i1 %30, label %47, label %31
31: ; preds = %28
%32 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 10, i64 0))
%33 = icmp eq i32 %32, 0
br i1 %33, label %47, label %34
34: ; preds = %31
%35 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 11, i64 0))
%36 = icmp eq i32 %35, 0
br i1 %36, label %47, label %37
37: ; preds = %34
%38 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 12, i64 0))
%39 = icmp eq i32 %38, 0
br i1 %39, label %47, label %40
40: ; preds = %37
%41 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 13, i64 0))
%42 = icmp eq i32 %41, 0
br i1 %42, label %47, label %43
43: ; preds = %40
%44 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([15 x [4 x i8]], [15 x [4 x i8]]* @__const.get_index.names, i64 0, i64 14, i64 0))
%45 = icmp eq i32 %44, 0
%46 = select i1 %45, i32 14, i32 -1
br label %47
47: ; preds = %43, %40, %37, %34, %31, %28, %25, %22, %19, %16, %13, %10, %7, %4, %1
%48 = phi i32 [ 0, %1 ], [ 1, %4 ], [ 2, %7 ], [ 3, %10 ], [ 4, %13 ], [ 5, %16 ], [ 6, %19 ], [ 7, %22 ], [ 8, %25 ], [ 9, %28 ], [ 10, %31 ], [ 11, %34 ], [ 12, %37 ], [ 13, %40 ], [ %46, %43 ]
ret i32 %48
}