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

/* Variables and functions */
int /*<<< orphan*/ strncasecmp(char const *, char const *, int);
int parse_attr(const char *name, int len) {
  static const int attr_values[] = {1, 2, 4, 5, 7};
  static const char *const attr_names[] = {"bold", "dim", "ul", "blink",
                                           "reverse"};
  unsigned int i;
  for (i = 0; i < (sizeof(attr_names) / sizeof(attr_names[0])); i++) {
    const char *str = attr_names[i];
    if (!strncasecmp(name, str, len) && !str[len])
      return attr_values[i];
  }
  return -1;
}


x86 assembly (clang, -O0):
<parse_attr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    $0x5,%rax
jae    119c <parse_attr+0x8c>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
lea    0x2cb1(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncasecmp@plt>
cmp    $0x0,%eax
jne    1189 <parse_attr+0x79>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    1189 <parse_attr+0x79>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
lea    0xe82(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x4(%rbp)
jmp    11a3 <parse_attr+0x93>
jmp    118e <parse_attr+0x7e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1126 <parse_attr+0x16>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_attr>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xef4(%rip),%rsi
mov    %ebx,%edx
call   1030 <strncasecmp@plt>
test   %eax,%eax
jne    1137 <parse_attr+0x27>
cmp    $0x4,%ebx
jne    1137 <parse_attr+0x27>
xor    %ecx,%ecx
jmp    11ba <parse_attr+0xaa>
lea    0xedb(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <strncasecmp@plt>
test   %eax,%eax
jne    1156 <parse_attr+0x46>
mov    $0x1,%ecx
cmp    $0x3,%ebx
je     11ba <parse_attr+0xaa>
lea    0xec0(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <strncasecmp@plt>
test   %eax,%eax
jne    1175 <parse_attr+0x65>
mov    $0x2,%ecx
cmp    $0x2,%ebx
je     11ba <parse_attr+0xaa>
lea    0xea4(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <strncasecmp@plt>
test   %eax,%eax
jne    1194 <parse_attr+0x84>
mov    $0x3,%ecx
cmp    $0x5,%ebx
je     11ba <parse_attr+0xaa>
lea    0xe8b(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <strncasecmp@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
test   %ecx,%ecx
jne    11c4 <parse_attr+0xb4>
mov    $0x4,%ecx
cmp    $0x7,%ebx
jne    11c4 <parse_attr+0xb4>
lea    0xe3f(%rip),%rax
mov    (%rax,%rcx,4),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@parse_attr.attr_values = internal constant [5 x i32] [i32 1, i32 2, i32 4, i32 5, i32 7]
@parse_attr.attr_names = internal constant [5 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 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 ([3 x i8], [3 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 ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0)]
@.str = [5 x i8] c"bold\00"
@.str.1 = [4 x i8] c"dim\00"
@.str.2 = [3 x i8] c"ul\00"
@.str.3 = [6 x i8] c"blink\00"
@.str.4 = [8 x i8] c"reverse\00"
define i32 @parse_attr(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
br label %8
8: ; preds = %35, %2
%9 = load i32, i32* %6
%10 = zext i32 %9 to i64
%11 = icmp ult i64 %10, 5
br i1 %11, label %12, label %38
12: ; preds = %8
%13 = load i32, i32* %6
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [5 x i8*], [5 x i8*]* @parse_attr.attr_names, i64 0, i64 %14
%16 = load i8*, i8** %15
store i8* %16, i8** %7
%17 = load i8*, i8** %4
%18 = load i8*, i8** %7
%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 %34, label %22
22: ; preds = %12
%23 = load i8*, i8** %7
%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 %34, label %29
29: ; preds = %22
%30 = load i32, i32* %6
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds [5 x i32], [5 x i32]* @parse_attr.attr_values, i64 0, i64 %31
%33 = load i32, i32* %32
store i32 %33, i32* %3
br label %39
34: ; preds = %22, %12
br label %35
35: ; preds = %34
%36 = load i32, i32* %6
%37 = add i32 %36, 1
store i32 %37, i32* %6
br label %8
38: ; preds = %8
store i32 -1, i32* %3
br label %39
39: ; preds = %38, %29
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@parse_attr.attr_values = internal unnamed_addr constant [5 x i32] [i32 1, i32 2, i32 4, i32 5, i32 7]
@.str = [5 x i8] c"bold\00"
@.str.1 = [4 x i8] c"dim\00"
@.str.2 = [3 x i8] c"ul\00"
@.str.3 = [6 x i8] c"blink\00"
@.str.4 = [8 x i8] c"reverse\00"
define i32 @parse_attr(i8* nocapture %0, i32 %1) {
%3 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %1)
%4 = icmp eq i32 %3, 0
%5 = icmp eq i32 %1, 4
%6 = and i1 %4, %5
br i1 %6, label %7, label %11
7: ; preds = %26, %21, %16, %11, %2
%8 = phi i64 [ 0, %2 ], [ 1, %11 ], [ 2, %16 ], [ 3, %21 ], [ 4, %26 ]
%9 = getelementptr inbounds [5 x i32], [5 x i32]* @parse_attr.attr_values, i64 0, i64 %8
%10 = load i32, i32* %9
br label %31
11: ; preds = %2
%12 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%13 = icmp eq i32 %12, 0
%14 = icmp eq i32 %1, 3
%15 = and i1 %13, %14
br i1 %15, label %7, label %16
16: ; preds = %11
%17 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %1)
%18 = icmp eq i32 %17, 0
%19 = icmp eq i32 %1, 2
%20 = and i1 %18, %19
br i1 %20, label %7, label %21
21: ; preds = %16
%22 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%23 = icmp eq i32 %22, 0
%24 = icmp eq i32 %1, 5
%25 = and i1 %23, %24
br i1 %25, label %7, label %26
26: ; preds = %21
%27 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %1)
%28 = icmp eq i32 %27, 0
%29 = icmp eq i32 %1, 7
%30 = and i1 %28, %29
br i1 %30, label %7, label %31
31: ; preds = %26, %7
%32 = phi i32 [ %10, %7 ], [ -1, %26 ]
ret i32 %32
}