#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 *);
scalar_t__ strlen(char const *);
int enumstr_to_int(const char *test, const char *enumstr) {
  int i = 0;
  while (*enumstr) {
    if (!strcmp(test, enumstr))
      return i;
    enumstr += strlen(enumstr) + 1;
    i++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<enumstr_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1188 <enumstr_to_int+0x68>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1165 <enumstr_to_int+0x45>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118f <enumstr_to_int+0x6f>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <enumstr_to_int+0x17>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enumstr_to_int>:
push   %rbp
push   %r14
push   %rbx
cmpb   $0x0,(%rsi)
je     1166 <enumstr_to_int+0x46>
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1168 <enumstr_to_int+0x48>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x1,%ebp
cmpb   $0x0,0x1(%rax,%rbx,1)
lea    0x1(%rax,%rbx,1),%rbx
jne    1140 <enumstr_to_int+0x20>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @enumstr_to_int(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %7
7: ; preds = %18, %2
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %26
11: ; preds = %7
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i32 @strcmp(i8* %12, i8* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = load i32, i32* %6
store i32 %17, i32* %3
br label %27
18: ; preds = %11
%19 = load i8*, i8** %5
%20 = call i64 @strlen(i8* %19)
%21 = add nsw i64 %20, 1
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 %21
store i8* %23, i8** %5
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %7
26: ; preds = %7
store i32 0, i32* %3
br label %27
27: ; preds = %26, %16
%28 = load i32, i32* %3
ret i32 %28
}

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