#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 *const);
int parse_enum(const char *arg, const char *const *names, int *dst) {
  int i;
  for (i = 0; names[i]; i++)
    if (!strcmp(arg, names[i])) {
      *dst = i;
      return 0;
    }
  return -1;
}


x86 assembly (clang, -O0):
<parse_enum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1184 <parse_enum+0x74>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1171 <parse_enum+0x61>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    118b <parse_enum+0x7b>
jmp    1176 <parse_enum+0x66>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112b <parse_enum+0x1b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_enum>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    (%rsi),%rsi
mov    $0xffffffff,%r15d
test   %rsi,%rsi
je     1162 <parse_enum+0x52>
mov    %rdx,%r14
mov    %rdi,%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     115c <parse_enum+0x4c>
mov    0x8(%rbx,%rbp,8),%rsi
add    $0x1,%rbp
test   %rsi,%rsi
jne    1140 <parse_enum+0x30>
jmp    1162 <parse_enum+0x52>
mov    %ebp,(%r14)
xor    %r15d,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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