#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 */
typedef int /*<<< orphan*/ cnames;

/* Variables and functions */
scalar_t__ stricmp(char const *, char *);
int getcolor(const char *arg) {
  static char *cnames[] = {"black", "red",     "green", "yellow",
                           "blue",  "magenta", "cyan",  "white"};
  static int num = sizeof(cnames) / sizeof(char *);
  int i;
  if (arg == NULL) {
    return -1;
  }
  for (i = 0; i < num; i++) {
    if (stricmp(arg, cnames[i]) == 0)
      return i;
  }
  return -1;
}


x86 assembly (clang, -O0):
<getcolor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <getcolor+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    1190 <getcolor+0x80>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    0x2f2d(%rip),%eax
jge    1189 <getcolor+0x79>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rcx
lea    0x2ed8(%rip),%rax
mov    (%rax,%rcx,8),%rsi
call   1030 <stricmp@plt>
cmp    $0x0,%rax
jne    1176 <getcolor+0x66>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1190 <getcolor+0x80>
jmp    117b <getcolor+0x6b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113a <getcolor+0x2a>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getcolor>:
push   %rbx
test   %rdi,%rdi
je     11c7 <getcolor+0xb7>
mov    %rdi,%rbx
lea    0xedc(%rip),%rsi
call   1030 <stricmp@plt>
test   %rax,%rax
je     11ce <getcolor+0xbe>
lea    0xecd(%rip),%rsi
mov    %rbx,%rdi
call   1030 <stricmp@plt>
test   %rax,%rax
je     11d2 <getcolor+0xc2>
lea    0xeb9(%rip),%rsi
mov    %rbx,%rdi
call   1030 <stricmp@plt>
test   %rax,%rax
je     11d9 <getcolor+0xc9>
lea    0xeab(%rip),%rsi
mov    %rbx,%rdi
call   1030 <stricmp@plt>
test   %rax,%rax
je     11e0 <getcolor+0xd0>
lea    0xe9e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <stricmp@plt>
test   %rax,%rax
je     11e7 <getcolor+0xd7>
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1030 <stricmp@plt>
test   %rax,%rax
je     11ee <getcolor+0xde>
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1030 <stricmp@plt>
test   %rax,%rax
je     11f5 <getcolor+0xe5>
lea    0xe74(%rip),%rsi
mov    %rbx,%rdi
call   1030 <stricmp@plt>
neg    %rax
sbb    %eax,%eax
or     $0x7,%eax
pop    %rbx
ret
mov    $0xffffffff,%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):
@getcolor.cnames = internal global [8 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i32 0, i32 0)]
@.str = [6 x i8] c"black\00"
@.str.1 = [4 x i8] c"red\00"
@.str.2 = [6 x i8] c"green\00"
@.str.3 = [7 x i8] c"yellow\00"
@.str.4 = [5 x i8] c"blue\00"
@.str.5 = [8 x i8] c"magenta\00"
@.str.6 = [5 x i8] c"cyan\00"
@.str.7 = [6 x i8] c"white\00"
@getcolor.num = internal global i32 8
define i32 @getcolor(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 -1, i32* %2
br label %28
8: ; preds = %1
store i32 0, i32* %4
br label %9
9: ; preds = %24, %8
%10 = load i32, i32* %4
%11 = load i32, i32* @getcolor.num
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load i8*, i8** %3
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [8 x i8*], [8 x i8*]* @getcolor.cnames, i64 0, i64 %16
%18 = load i8*, i8** %17
%19 = call i64 @stricmp(i8* %14, i8* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = load i32, i32* %4
store i32 %22, i32* %2
br label %28
23: ; preds = %13
br label %24
24: ; preds = %23
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
br label %9
27: ; preds = %9
store i32 -1, i32* %2
br label %28
28: ; preds = %27, %21, %7
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [6 x i8] c"black\00"
@.str.1 = [4 x i8] c"red\00"
@.str.2 = [6 x i8] c"green\00"
@.str.3 = [7 x i8] c"yellow\00"
@.str.4 = [5 x i8] c"blue\00"
@.str.5 = [8 x i8] c"magenta\00"
@.str.6 = [5 x i8] c"cyan\00"
@.str.7 = [6 x i8] c"white\00"
define i32 @getcolor(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %28, label %3
3: ; preds = %1
%4 = tail call i64 @stricmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %28, label %6
6: ; preds = %3
%7 = tail call i64 @stricmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %28, label %9
9: ; preds = %6
%10 = tail call i64 @stricmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %28, label %12
12: ; preds = %9
%13 = tail call i64 @stricmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %28, label %15
15: ; preds = %12
%16 = tail call i64 @stricmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %28, label %18
18: ; preds = %15
%19 = tail call i64 @stricmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %18
%22 = tail call i64 @stricmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = tail call i64 @stricmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, i32 7, i32 -1
br label %28
28: ; preds = %24, %3, %6, %9, %12, %15, %18, %21, %1
%29 = phi i32 [ -1, %1 ], [ 0, %3 ], [ 1, %6 ], [ 2, %9 ], [ 3, %12 ], [ 4, %15 ], [ 5, %18 ], [ 6, %21 ], [ %27, %24 ]
ret i32 %29
}