#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__ ARRAY_SIZE(char const *const *);
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)ARRAY_SIZE(color_names); 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    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    0x2c7d(%rip),%rdi
call   1050 <ARRAY_SIZE@plt>
mov    %rax,%rcx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    11c5 <parse_color+0x95>
movslq -0x24(%rbp),%rcx
lea    0x2c5f(%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    11b2 <parse_color+0x82>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    11b2 <parse_color+0x82>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    121b <parse_color+0xeb>
jmp    11b7 <parse_color+0x87>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1146 <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    1214 <parse_color+0xe4>
cmpl   $0xffffffff,-0x24(%rbp)
jl     1214 <parse_color+0xe4>
cmpl   $0xff,-0x24(%rbp)
jg     1214 <parse_color+0xe4>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    121b <parse_color+0xeb>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_color>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r12d
mov    %rdi,%r14
lea    0x2c85(%rip),%r13
mov    %r13,%rdi
call   1050 <ARRAY_SIZE@plt>
movslq %r12d,%rcx
mov    %rcx,0x8(%rsp)
test   %eax,%eax
jle    11ad <parse_color+0x7d>
xor    %ebx,%ebx
mov    %r13,%r15
jmp    1187 <parse_color+0x57>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %r13,%rdi
call   1050 <ARRAY_SIZE@plt>
cltq
add    $0x8,%r15
cmp    %rax,%rbx
jge    11ad <parse_color+0x7d>
mov    (%r15),%rbp
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
call   1040 <strncasecmp@plt>
test   %eax,%eax
jne    1170 <parse_color+0x40>
mov    0x8(%rsp),%rax
cmpb   $0x0,0x0(%rbp,%rax,1)
jne    1170 <parse_color+0x40>
add    $0xffffffff,%ebx
jmp    11e7 <parse_color+0xb7>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    0x10(%rsp),%rcx
sub    %r14,%rcx
cmp    $0x100,%eax
mov    $0xfffffffe,%ebx
cmovl  %eax,%ebx
mov    $0xfffffffe,%edx
cmp    $0xffffffff,%eax
cmovl  %edx,%ebx
cmp    0x8(%rsp),%rcx
cmovne %edx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
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 = %35, %2
%10 = load i32, i32* %7
%11 = call i64 @ARRAY_SIZE(i8** getelementptr inbounds ([9 x i8*], [9 x i8*]* @parse_color.color_names, i64 0, i64 0))
%12 = trunc i64 %11 to i32
%13 = icmp slt i32 %10, %12
br i1 %13, label %14, label %38
14: ; preds = %9
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [9 x i8*], [9 x i8*]* @parse_color.color_names, i64 0, i64 %16
%18 = load i8*, i8** %17
store i8* %18, i8** %8
%19 = load i8*, i8** %4
%20 = load i8*, i8** %8
%21 = load i32, i32* %5
%22 = call i32 @strncasecmp(i8* %19, i8* %20, i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %34, label %24
24: ; preds = %14
%25 = load i8*, i8** %8
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %24
%32 = load i32, i32* %7
%33 = sub nsw i32 %32, 1
store i32 %33, i32* %3
br label %58
34: ; preds = %24, %14
br label %35
35: ; preds = %34
%36 = load i32, i32* %7
%37 = add nsw i32 %36, 1
store i32 %37, i32* %7
br label %9
38: ; preds = %9
%39 = load i8*, i8** %4
%40 = call i32 @strtol(i8* %39, i8** %6, i32 10)
store i32 %40, i32* %7
%41 = load i8*, i8** %6
%42 = load i8*, i8** %4
%43 = ptrtoint i8* %41 to i64
%44 = ptrtoint i8* %42 to i64
%45 = sub i64 %43, %44
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = icmp eq i64 %45, %47
br i1 %48, label %49, label %57
49: ; preds = %38
%50 = load i32, i32* %7
%51 = icmp sge i32 %50, -1
br i1 %51, label %52, label %57
52: ; preds = %49
%53 = load i32, i32* %7
%54 = icmp sle i32 %53, 255
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = load i32, i32* %7
store i32 %56, i32* %3
br label %58
57: ; preds = %52, %49, %38
store i32 -2, i32* %3
br label %58
58: ; preds = %57, %55, %31
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@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 i8*
%4 = bitcast i8** %3 to i8*
%5 = tail call i64 @ARRAY_SIZE(i8** getelementptr inbounds ([9 x i8*], [9 x i8*]* @parse_color.color_names, i64 0, i64 0))
%6 = trunc i64 %5 to i32
%7 = icmp sgt i32 %6, 0
%8 = sext i32 %1 to i64
br i1 %7, label %9, label %25
9: ; preds = %2, %19
%10 = phi i64 [ %20, %19 ], [ 0, %2 ]
%11 = getelementptr inbounds [9 x i8*], [9 x i8*]* @parse_color.color_names, i64 0, i64 %10
%12 = load i8*, i8** %11
%13 = tail call i32 @strncasecmp(i8* %0, i8* %12, i32 %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = getelementptr inbounds i8, i8* %12, i64 %8
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %37, label %19
19: ; preds = %9, %15
%20 = add nuw nsw i64 %10, 1
%21 = tail call i64 @ARRAY_SIZE(i8** getelementptr inbounds ([9 x i8*], [9 x i8*]* @parse_color.color_names, i64 0, i64 0))
%22 = shl i64 %21, 32
%23 = ashr exact i64 %22, 32
%24 = icmp slt i64 %20, %23
br i1 %24, label %9, label %25
25: ; preds = %19, %2
%26 = call i32 @strtol(i8* %0, i8** %3, i32 10)
%27 = load i8*, i8** %3
%28 = ptrtoint i8* %27 to i64
%29 = ptrtoint i8* %0 to i64
%30 = sub i64 %28, %29
%31 = icmp eq i64 %30, %8
%32 = icmp sgt i32 %26, -2
%33 = select i1 %31, i1 %32, i1 false
%34 = icmp slt i32 %26, 256
%35 = select i1 %33, i1 %34, i1 false
%36 = select i1 %35, i32 %26, i32 -2
br label %40
37: ; preds = %15
%38 = trunc i64 %10 to i32
%39 = add i32 %38, -1
br label %40
40: ; preds = %37, %25
%41 = phi i32 [ %36, %25 ], [ %39, %37 ]
ret i32 %41
}