#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 */
int /*<<< orphan*/ strcmp(char const *, char const *);
int enum_table_val(const char *table[], const char *key) {
  for (const char **i = table + 1; *i; i++)
    if (!strcmp(key, *i))
      return i - table;
  return 0;
}


x86 assembly (clang, -O0):
<enum_table_val>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
je     1180 <enum_table_val+0x70>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    116a <enum_table_val+0x5a>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sar    $0x3,%rax
mov    %eax,-0x4(%rbp)
jmp    1187 <enum_table_val+0x77>
jmp    116f <enum_table_val+0x5f>
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <enum_table_val+0x1c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enum_table_val>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
xor    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x8(%r12,%rbx,1),%rsi
test   %rsi,%rsi
je     1151 <enum_table_val+0x41>
mov    %r15,%rdi
call   1030 <strcmp@plt>
add    $0x8,%rbx
test   %eax,%eax
jne    1130 <enum_table_val+0x20>
shr    $0x3,%rbx
mov    %ebx,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @enum_table_val(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8**
store i8** %0, i8*** %4
store i8* %1, i8** %5
%7 = load i8**, i8*** %4
%8 = getelementptr inbounds i8*, i8** %7, i64 1
store i8** %8, i8*** %6
br label %9
9: ; preds = %28, %2
%10 = load i8**, i8*** %6
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %31
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = load i8**, i8*** %6
%16 = load i8*, i8** %15
%17 = call i32 @strcmp(i8* %14, i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %27, label %19
19: ; preds = %13
%20 = load i8**, i8*** %6
%21 = load i8**, i8*** %4
%22 = ptrtoint i8** %20 to i64
%23 = ptrtoint i8** %21 to i64
%24 = sub i64 %22, %23
%25 = sdiv exact i64 %24, 8
%26 = trunc i64 %25 to i32
store i32 %26, i32* %3
br label %32
27: ; preds = %13
br label %28
28: ; preds = %27
%29 = load i8**, i8*** %6
%30 = getelementptr inbounds i8*, i8** %29, i32 1
store i8** %30, i8*** %6
br label %9
31: ; preds = %9
store i32 0, i32* %3
br label %32
32: ; preds = %31, %19
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
define i32 @enum_table_val(i8** %0, i8* nocapture %1) {
br label %3
3: ; preds = %8, %2
%4 = phi i8** [ %0, %2 ], [ %5, %8 ]
%5 = getelementptr inbounds i8*, i8** %4, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %17, label %8
8: ; preds = %3
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* %6)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %3
11: ; preds = %8
%12 = ptrtoint i8** %5 to i64
%13 = ptrtoint i8** %0 to i64
%14 = sub i64 %12, %13
%15 = lshr exact i64 %14, 3
%16 = trunc i64 %15 to i32
br label %17
17: ; preds = %3, %11
%18 = phi i32 [ %16, %11 ], [ 0, %3 ]
ret i32 %18
}