#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 */
unsigned int ARRAY_SIZE(char const *const *);
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 < ARRAY_SIZE(attr_names); 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    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    0x2cad(%rip),%rdi
call   1040 <ARRAY_SIZE@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jae    11be <parse_attr+0x9e>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
lea    0x2c8f(%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    11ab <parse_attr+0x8b>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    11ab <parse_attr+0x8b>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
lea    0xe60(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x4(%rbp)
jmp    11c5 <parse_attr+0xa5>
jmp    11b0 <parse_attr+0x90>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1136 <parse_attr+0x16>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_attr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r13d
mov    %rdi,0x10(%rsp)
lea    0x2cb3(%rip),%r12
mov    %r12,%rdi
call   1040 <ARRAY_SIZE@plt>
mov    $0xffffffff,%ecx
test   %eax,%eax
je     11b7 <parse_attr+0x97>
movslq %r13d,%rax
mov    %rax,0x8(%rsp)
lea    0xea3(%rip),%rbp
xor    %r14d,%r14d
mov    %r12,%r15
jmp    118b <parse_attr+0x6b>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%r14
mov    %r12,%rdi
call   1040 <ARRAY_SIZE@plt>
mov    %eax,%eax
add    $0x4,%rbp
add    $0x8,%r15
cmp    %rax,%r14
jae    11b2 <parse_attr+0x92>
mov    (%r15),%rbx
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1030 <strncasecmp@plt>
test   %eax,%eax
jne    1170 <parse_attr+0x50>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rbx,%rax,1)
jne    1170 <parse_attr+0x50>
mov    0x0(%rbp),%ecx
jmp    11b7 <parse_attr+0x97>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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 = call i32 @ARRAY_SIZE(i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @parse_attr.attr_names, i64 0, i64 0))
%11 = icmp ult i32 %9, %10
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]
@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* nocapture %0, i32 %1) {
%3 = tail call i32 @ARRAY_SIZE(i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @parse_attr.attr_names, i64 0, i64 0))
%4 = icmp eq i32 %3, 0
br i1 %4, label %26, label %5
5: ; preds = %2
%6 = sext i32 %1 to i64
br label %7
7: ; preds = %5, %21
%8 = phi i64 [ 0, %5 ], [ %22, %21 ]
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* @parse_attr.attr_names, i64 0, i64 %8
%10 = load i8*, i8** %9
%11 = tail call i32 @strncasecmp(i8* %0, i8* %10, i32 %1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %7
%14 = getelementptr inbounds i8, i8* %10, i64 %6
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = and i64 %8, 4294967295
%19 = getelementptr inbounds [5 x i32], [5 x i32]* @parse_attr.attr_values, i64 0, i64 %18
%20 = load i32, i32* %19
br label %26
21: ; preds = %13, %7
%22 = add nuw nsw i64 %8, 1
%23 = tail call i32 @ARRAY_SIZE(i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @parse_attr.attr_names, i64 0, i64 0))
%24 = zext i32 %23 to i64
%25 = icmp ult i64 %22, %24
br i1 %25, label %7, label %26
26: ; preds = %21, %2, %17
%27 = phi i32 [ %20, %17 ], [ -1, %2 ], [ -1, %21 ]
ret i32 %27
}