int detect_command(const char string[]) {
  const char CommandList[][8] = {"-v",  "init", "do",     "done",
                                 "now", "list", "remove", "edit"};
  const int CommandNum = sizeof CommandList / sizeof CommandList[0];
  int i;
  for (i = 0; i < CommandNum; i++) {
    if (strcmp(string, CommandList[i]) == 0)
      break;
  }
  if (i == CommandNum)
    return -1;
  return i;
}


x86 assembly (clang, -O0):
<detect_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xec9(%rip),%rsi
mov    $0x40,%edx
call   1040 <memcpy@plt>
movl   $0x8,-0x54(%rbp)
movl   $0x0,-0x58(%rbp)
cmpl   $0x8,-0x58(%rbp)
jge    1192 <detect_command+0x72>
mov    -0x10(%rbp),%rdi
movslq -0x58(%rbp),%rax
lea    -0x50(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    117f <detect_command+0x5f>
jmp    1192 <detect_command+0x72>
jmp    1184 <detect_command+0x64>
mov    -0x58(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x58(%rbp)
jmp    114f <detect_command+0x2f>
cmpl   $0x8,-0x58(%rbp)
jne    11a8 <detect_command+0x88>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <detect_command+0x8e>
mov    -0x58(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_command>:
push   %rbx
mov    %rdi,%rbx
lea    0xee5(%rip),%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11b2 <detect_command+0xa2>
lea    0xed9(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11b6 <detect_command+0xa6>
lea    0xece(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11bd <detect_command+0xad>
lea    0xec3(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11c4 <detect_command+0xb4>
lea    0xeb8(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11cb <detect_command+0xbb>
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11d2 <detect_command+0xc2>
lea    0xea2(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11d9 <detect_command+0xc9>
lea    0xe97(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
neg    %eax
sbb    %eax,%eax
or     $0x7,%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

LLVM IR (-O0):
@__const.detect_command.CommandList = [8 x [8 x i8]] [[8 x i8] c"-v\00\00\00\00\00\00", [8 x i8] c"init\00\00\00\00", [8 x i8] c"do\00\00\00\00\00\00", [8 x i8] c"done\00\00\00\00", [8 x i8] c"now\00\00\00\00\00", [8 x i8] c"list\00\00\00\00", [8 x i8] c"remove\00\00", [8 x i8] c"edit\00\00\00\00"]
define i32 @detect_command(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [8 x [8 x i8]]
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = bitcast [8 x [8 x i8]]* %4 to i8*
store i32 8, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %21, %1
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 8
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [8 x [8 x i8]], [8 x [8 x i8]]* %4, i64 0, i64 %14
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %15, i64 0, i64 0
%17 = call i32 @strcmp(i8* %12, i8* %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %11
br label %24
20: ; preds = %11
br label %21
21: ; preds = %20
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %8
24: ; preds = %19, %8
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, 8
br i1 %26, label %27, label %28
27: ; preds = %24
store i32 -1, i32* %2
br label %30
28: ; preds = %24
%29 = load i32, i32* %6
store i32 %29, i32* %2
br label %30
30: ; preds = %28, %27
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@__const.detect_command.CommandList = [8 x [8 x i8]] [[8 x i8] c"-v\00\00\00\00\00\00", [8 x i8] c"init\00\00\00\00", [8 x i8] c"do\00\00\00\00\00\00", [8 x i8] c"done\00\00\00\00", [8 x i8] c"now\00\00\00\00\00", [8 x i8] c"list\00\00\00\00", [8 x i8] c"remove\00\00", [8 x i8] c"edit\00\00\00\00"]
define i32 @detect_command(i8* nocapture %0) {
%2 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([8 x [8 x i8]], [8 x [8 x i8]]* @__const.detect_command.CommandList, i64 0, i64 0, i64 0))
%3 = icmp eq i32 %2, 0
br i1 %3, label %26, label %4
4: ; preds = %1
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([8 x [8 x i8]], [8 x [8 x i8]]* @__const.detect_command.CommandList, i64 0, i64 1, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %26, label %7
7: ; preds = %4
%8 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([8 x [8 x i8]], [8 x [8 x i8]]* @__const.detect_command.CommandList, i64 0, i64 2, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %26, label %10
10: ; preds = %7
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([8 x [8 x i8]], [8 x [8 x i8]]* @__const.detect_command.CommandList, i64 0, i64 3, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %26, label %13
13: ; preds = %10
%14 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([8 x [8 x i8]], [8 x [8 x i8]]* @__const.detect_command.CommandList, i64 0, i64 4, i64 0))
%15 = icmp eq i32 %14, 0
br i1 %15, label %26, label %16
16: ; preds = %13
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([8 x [8 x i8]], [8 x [8 x i8]]* @__const.detect_command.CommandList, i64 0, i64 5, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %16
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([8 x [8 x i8]], [8 x [8 x i8]]* @__const.detect_command.CommandList, i64 0, i64 6, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* getelementptr inbounds ([8 x [8 x i8]], [8 x [8 x i8]]* @__const.detect_command.CommandList, i64 0, i64 7, i64 0))
%24 = icmp eq i32 %23, 0
%25 = select i1 %24, i32 7, i32 -1
br label %26
26: ; preds = %22, %19, %16, %13, %10, %7, %4, %1
%27 = phi i32 [ 6, %19 ], [ 5, %16 ], [ 4, %13 ], [ 3, %10 ], [ 2, %7 ], [ 1, %4 ], [ 0, %1 ], [ %25, %22 ]
ret i32 %27
}