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

/* Variables and functions */
#define COLOR_BLACK 135
#define COLOR_BLUE 134
#define COLOR_CYAN 133
#define COLOR_GREEN 132
#define COLOR_MAGENTA 131
#define COLOR_RED 130
#define COLOR_WHITE 129
#define COLOR_YELLOW 128
int check_color(unsigned int);
int sscanf(char const *, char *, unsigned int *);
scalar_t__ strcmp(char const *, char const *);
int parse_color(const char *name) {
  unsigned int i;
  int ret;
  struct color_map {
    const int color;
    const char *name;
  };
  static const struct color_map colors_map[] = {
      {COLOR_BLACK, "black"}, {COLOR_RED, "red"},
      {COLOR_GREEN, "green"}, {COLOR_YELLOW, "yellow"},
      {COLOR_BLUE, "blue"},   {COLOR_MAGENTA, "magenta"},
      {COLOR_CYAN, "cyan"},   {COLOR_WHITE, "white"},
  };
  ret = sscanf(name, "%d", &i);
  if (ret == 1) {
    return check_color(i);
  }
  ret = sscanf(name, "color%3d", &i);
  if (ret == 1) {
    return check_color(i);
  }
  for (i = 0; i < sizeof(colors_map) / sizeof(struct color_map); i++) {
    if ((strcmp((colors_map[i].name), (name)) == 0)) {
      return check_color(colors_map[i].color);
    }
  }
  return -2;
}


x86 assembly (clang, -O0):
<parse_color>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xee8(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    116d <parse_color+0x3d>
mov    -0x14(%rbp),%edi
call   1030 <check_color@plt>
mov    %eax,-0x4(%rbp)
jmp    1218 <parse_color+0xe8>
mov    -0x10(%rbp),%rdi
lea    0xeba(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jne    119e <parse_color+0x6e>
mov    -0x14(%rbp),%edi
call   1030 <check_color@plt>
mov    %eax,-0x4(%rbp)
jmp    1218 <parse_color+0xe8>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    $0x8,%rax
jae    1211 <parse_color+0xe1>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
lea    0x2be2(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11fe <parse_color+0xce>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
lea    0x2bb8(%rip),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%edi
call   1030 <check_color@plt>
mov    %eax,-0x4(%rbp)
jmp    1218 <parse_color+0xe8>
jmp    1203 <parse_color+0xd3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a5 <parse_color+0x75>
movl   $0xfffffffe,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_color>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xef1(%rip),%rsi
lea    0x4(%rsp),%rbx
mov    %rbx,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11b6 <parse_color+0x86>
lea    0xedb(%rip),%rsi
lea    0x4(%rsp),%rbx
mov    %r14,%rdi
mov    %rbx,%rdx
call   1050 <sscanf@plt>
cmp    $0x1,%eax
je     11b6 <parse_color+0x86>
movl   $0x0,0x4(%rsp)
xor    %ecx,%ecx
lea    0x2c23(%rip),%rbx
nopl   (%rax)
mov    %ecx,%eax
shl    $0x4,%rax
mov    0x8(%rax,%rbx,1),%rdi
mov    %r14,%rsi
call   1040 <strcmp@plt>
mov    0x4(%rsp),%ecx
test   %rax,%rax
je     11af <parse_color+0x7f>
add    $0x1,%ecx
mov    %ecx,0x4(%rsp)
cmp    $0x8,%ecx
jb     1180 <parse_color+0x50>
mov    $0xfffffffe,%eax
jmp    11bd <parse_color+0x8d>
shl    $0x4,%rcx
add    %rcx,%rbx
mov    (%rbx),%edi
call   1030 <check_color@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.color_map = type { i32, i8* }
@parse_color.colors_map = internal constant [8 x %struct.color_map] [%struct.color_map { i32 135, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0) }, %struct.color_map { i32 130, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0) }, %struct.color_map { i32 132, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0) }, %struct.color_map { i32 128, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0) }, %struct.color_map { i32 134, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0) }, %struct.color_map { i32 131, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0) }, %struct.color_map { i32 133, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0) }, %struct.color_map { i32 129, 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"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [9 x i8] c"color%3d\00"
define i32 @parse_color(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %4)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* %4
%12 = call i32 @check_color(i32 %11)
store i32 %12, i32* %2
br label %47
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32* %4)
store i32 %15, i32* %5
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* %4
%20 = call i32 @check_color(i32 %19)
store i32 %20, i32* %2
br label %47
21: ; preds = %13
store i32 0, i32* %4
br label %22
22: ; preds = %43, %21
%23 = load i32, i32* %4
%24 = zext i32 %23 to i64
%25 = icmp ult i64 %24, 8
br i1 %25, label %26, label %46
26: ; preds = %22
%27 = load i32, i32* %4
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [8 x %struct.color_map], [8 x %struct.color_map]* @parse_color.colors_map, i64 0, i64 %28
%30 = getelementptr inbounds %struct.color_map, %struct.color_map* %29, i32 0, i32 1
%31 = load i8*, i8** %30
%32 = load i8*, i8** %3
%33 = call i64 @strcmp(i8* %31, i8* %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %26
%36 = load i32, i32* %4
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds [8 x %struct.color_map], [8 x %struct.color_map]* @parse_color.colors_map, i64 0, i64 %37
%39 = getelementptr inbounds %struct.color_map, %struct.color_map* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i32 @check_color(i32 %40)
store i32 %41, i32* %2
br label %47
42: ; preds = %26
br label %43
43: ; preds = %42
%44 = load i32, i32* %4
%45 = add i32 %44, 1
store i32 %45, i32* %4
br label %22
46: ; preds = %22
store i32 -2, i32* %2
br label %47
47: ; preds = %46, %35, %18, %10
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
%struct.color_map = type { i32, i8* }
@parse_color.colors_map = internal unnamed_addr constant [8 x %struct.color_map] [%struct.color_map { i32 135, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0) }, %struct.color_map { i32 130, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0) }, %struct.color_map { i32 132, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0) }, %struct.color_map { i32 128, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i32 0, i32 0) }, %struct.color_map { i32 134, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0) }, %struct.color_map { i32 131, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0) }, %struct.color_map { i32 133, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0) }, %struct.color_map { i32 129, 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"
@.str.8 = [3 x i8] c"%d\00"
@.str.9 = [9 x i8] c"color%3d\00"
define i32 @parse_color(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32* %2)
%5 = icmp eq i32 %4, 1
br i1 %5, label %24, label %6
6: ; preds = %1
%7 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.9, i64 0, i64 0), i32* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %24, label %9
9: ; preds = %6
store i32 0, i32* %2
br label %10
10: ; preds = %9, %21
%11 = phi i32 [ 0, %9 ], [ %22, %21 ]
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds [8 x %struct.color_map], [8 x %struct.color_map]* @parse_color.colors_map, i64 0, i64 %12, i32 1
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* %14, i8* %0)
%16 = icmp eq i64 %15, 0
%17 = load i32, i32* %2
br i1 %16, label %18, label %21
18: ; preds = %10
%19 = zext i32 %17 to i64
%20 = getelementptr inbounds [8 x %struct.color_map], [8 x %struct.color_map]* @parse_color.colors_map, i64 0, i64 %19, i32 0
br label %24
21: ; preds = %10
%22 = add i32 %17, 1
store i32 %22, i32* %2
%23 = icmp ult i32 %22, 8
br i1 %23, label %10, label %28
24: ; preds = %6, %1, %18
%25 = phi i32* [ %20, %18 ], [ %2, %1 ], [ %2, %6 ]
%26 = load i32, i32* %25
%27 = call i32 @check_color(i32 %26)
br label %28
28: ; preds = %21, %24
%29 = phi i32 [ %27, %24 ], [ -2, %21 ]
ret i32 %29
}