#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*/ color_names;

/* Variables and functions */
int /*<<< orphan*/ strncasecmp(char const *, char const *, int);
int strtol(char const *, char **, int);
int parse_color(const char *name, int len) {
  static const char *const color_names[] = {"normal",  "black",  "red",
                                            "green",   "yellow", "blue",
                                            "magenta", "cyan",   "white"};
  char *end;
  int i;
  for (i = 0; i < (int)(sizeof(color_names) / sizeof(color_names[0])); i++) {
    const char *str = color_names[i];
    if (!strncasecmp(name, str, len) && !str[len])
      return i - 1;
  }
  i = strtol(name, &end, 10);
  if (end - name == len && i >= -1 && i <= 255)
    return i;
  return -2;
}


x86 assembly (clang, -O0):
<parse_color>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x9,-0x24(%rbp)
jge    119f <parse_color+0x7f>
movslq -0x24(%rbp),%rcx
lea    0x2c85(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <strncasecmp@plt>
cmp    $0x0,%eax
jne    118c <parse_color+0x6c>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    118c <parse_color+0x6c>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11f5 <parse_color+0xd5>
jmp    1191 <parse_color+0x71>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1136 <parse_color+0x16>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movslq -0x14(%rbp),%rcx
cmp    %rcx,%rax
jne    11ee <parse_color+0xce>
cmpl   $0xffffffff,-0x24(%rbp)
jl     11ee <parse_color+0xce>
cmpl   $0xff,-0x24(%rbp)
jg     11ee <parse_color+0xce>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11f5 <parse_color+0xd5>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_color>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xed1(%rip),%rsi
mov    %ebp,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
jne    1148 <parse_color+0x28>
mov    $0xffffffff,%eax
cmp    $0x6,%ebp
je     1293 <parse_color+0x173>
lea    0xeb8(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
jne    1170 <parse_color+0x50>
xor    %eax,%eax
cmp    $0x5,%ebp
setne  %cl
jne    1170 <parse_color+0x50>
mov    %cl,%al
neg    %eax
jmp    1293 <parse_color+0x173>
lea    0xe96(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
jne    1193 <parse_color+0x73>
mov    $0x1,%eax
cmp    $0x3,%ebp
je     1293 <parse_color+0x173>
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
jne    11b6 <parse_color+0x96>
mov    $0x2,%eax
cmp    $0x5,%ebp
je     1293 <parse_color+0x173>
lea    0xe5a(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
jne    11d9 <parse_color+0xb9>
mov    $0x3,%eax
cmp    $0x6,%ebp
je     1293 <parse_color+0x173>
lea    0xe3e(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
jne    11fc <parse_color+0xdc>
mov    $0x4,%eax
cmp    $0x4,%ebp
je     1293 <parse_color+0x173>
lea    0xe20(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
jne    121b <parse_color+0xfb>
mov    $0x5,%eax
cmp    $0x7,%ebp
je     1293 <parse_color+0x173>
lea    0xe09(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
jne    123a <parse_color+0x11a>
mov    $0x6,%eax
cmp    $0x4,%ebp
je     1293 <parse_color+0x173>
lea    0xdef(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
jne    1259 <parse_color+0x139>
mov    $0x7,%eax
cmp    $0x5,%ebp
je     1293 <parse_color+0x173>
movslq %ebp,%rbp
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,%ecx
mov    (%rsp),%rdx
sub    %rbx,%rdx
cmp    $0x100,%eax
mov    $0xfffffffe,%eax
cmovl  %ecx,%eax
mov    $0xfffffffe,%esi
cmp    $0xffffffff,%ecx
cmovl  %esi,%eax
cmp    %rbp,%rdx
cmovne %esi,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@parse_color.color_names = internal constant [9 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i32 0, i32 0)]
@.str = [7 x i8] c"normal\00"
@.str.1 = [6 x i8] c"black\00"
@.str.2 = [4 x i8] c"red\00"
@.str.3 = [6 x i8] c"green\00"
@.str.4 = [7 x i8] c"yellow\00"
@.str.5 = [5 x i8] c"blue\00"
@.str.6 = [8 x i8] c"magenta\00"
@.str.7 = [5 x i8] c"cyan\00"
@.str.8 = [6 x i8] c"white\00"
define i32 @parse_color(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %7
br label %9
9: ; preds = %33, %2
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 9
br i1 %11, label %12, label %36
12: ; preds = %9
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [9 x i8*], [9 x i8*]* @parse_color.color_names, i64 0, i64 %14
%16 = load i8*, i8** %15
store i8* %16, i8** %8
%17 = load i8*, i8** %4
%18 = load i8*, i8** %8
%19 = load i32, i32* %5
%20 = call i32 @strncasecmp(i8* %17, i8* %18, i32 %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %32, label %22
22: ; preds = %12
%23 = load i8*, i8** %8
%24 = load i32, i32* %5
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = icmp ne i8 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %22
%30 = load i32, i32* %7
%31 = sub nsw i32 %30, 1
store i32 %31, i32* %3
br label %56
32: ; preds = %22, %12
br label %33
33: ; preds = %32
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %9
36: ; preds = %9
%37 = load i8*, i8** %4
%38 = call i32 @strtol(i8* %37, i8** %6, i32 10)
store i32 %38, i32* %7
%39 = load i8*, i8** %6
%40 = load i8*, i8** %4
%41 = ptrtoint i8* %39 to i64
%42 = ptrtoint i8* %40 to i64
%43 = sub i64 %41, %42
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = icmp eq i64 %43, %45
br i1 %46, label %47, label %55
47: ; preds = %36
%48 = load i32, i32* %7
%49 = icmp sge i32 %48, -1
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = load i32, i32* %7
%52 = icmp sle i32 %51, 255
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = load i32, i32* %7
store i32 %54, i32* %3
br label %56
55: ; preds = %50, %47, %36
store i32 -2, i32* %3
br label %56
56: ; preds = %55, %53, %29
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [7 x i8] c"normal\00"
@.str.1 = [6 x i8] c"black\00"
@.str.2 = [4 x i8] c"red\00"
@.str.3 = [6 x i8] c"green\00"
@.str.4 = [7 x i8] c"yellow\00"
@.str.5 = [5 x i8] c"blue\00"
@.str.6 = [8 x i8] c"magenta\00"
@.str.7 = [5 x i8] c"cyan\00"
@.str.8 = [6 x i8] c"white\00"
define i32 @parse_color(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = sext i32 %1 to i64
%6 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %1)
%7 = icmp eq i32 %6, 0
%8 = icmp eq i32 %1, 6
%9 = and i1 %7, %8
br i1 %9, label %64, label %10
10: ; preds = %2
%11 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = icmp eq i32 %1, 5
%15 = xor i1 %14, true
%16 = sext i1 %15 to i32
br i1 %14, label %64, label %17
17: ; preds = %13, %10
%18 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%19 = icmp eq i32 %18, 0
%20 = icmp eq i32 %1, 3
%21 = and i1 %19, %20
br i1 %21, label %64, label %22
22: ; preds = %17
%23 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%24 = icmp eq i32 %23, 0
%25 = icmp eq i32 %1, 5
%26 = and i1 %24, %25
br i1 %26, label %64, label %27
27: ; preds = %22
%28 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %1)
%29 = icmp eq i32 %28, 0
%30 = icmp eq i32 %1, 6
%31 = and i1 %29, %30
br i1 %31, label %64, label %32
32: ; preds = %27
%33 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %1)
%34 = icmp eq i32 %33, 0
%35 = icmp eq i32 %1, 4
%36 = and i1 %34, %35
br i1 %36, label %64, label %37
37: ; preds = %32
%38 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 %1)
%39 = icmp eq i32 %38, 0
%40 = icmp eq i32 %1, 7
%41 = and i1 %39, %40
br i1 %41, label %64, label %42
42: ; preds = %37
%43 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i32 %1)
%44 = icmp eq i32 %43, 0
%45 = icmp eq i32 %1, 4
%46 = and i1 %44, %45
br i1 %46, label %64, label %47
47: ; preds = %42
%48 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 %1)
%49 = icmp eq i32 %48, 0
%50 = icmp eq i32 %1, 5
%51 = and i1 %49, %50
br i1 %51, label %64, label %52
52: ; preds = %47
%53 = call i32 @strtol(i8* %0, i8** %3, i32 10)
%54 = load i8*, i8** %3
%55 = ptrtoint i8* %54 to i64
%56 = ptrtoint i8* %0 to i64
%57 = sub i64 %55, %56
%58 = icmp eq i64 %57, %5
%59 = icmp sgt i32 %53, -2
%60 = select i1 %58, i1 %59, i1 false
%61 = icmp slt i32 %53, 256
%62 = select i1 %60, i1 %61, i1 false
%63 = select i1 %62, i32 %53, i32 -2
br label %64
64: ; preds = %47, %42, %37, %32, %27, %22, %17, %2, %13, %52
%65 = phi i32 [ %63, %52 ], [ %16, %13 ], [ -1, %2 ], [ 1, %17 ], [ 2, %22 ], [ 3, %27 ], [ 4, %32 ], [ 5, %37 ], [ 6, %42 ], [ 7, %47 ]
ret i32 %65
}