#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 *, char *);
int bind_to_enum(char *str, char **emap, char *eval, int emap_sz, char *res) {
  int i;
  for (i = 0; i < emap_sz; i++) {
    if (!strcmp(str, emap[i])) {
      if (eval) {
        *res = eval[i];
      } else {
        *res = i;
      }
      return 1;
    }
  }
  *res = -1;
  return 0;
}


x86 assembly (clang, -O0):
<bind_to_enum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11a7 <bind_to_enum+0x97>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1194 <bind_to_enum+0x84>
cmpq   $0x0,-0x20(%rbp)
je     117d <bind_to_enum+0x6d>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
jmp    1188 <bind_to_enum+0x78>
mov    -0x34(%rbp),%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11b5 <bind_to_enum+0xa5>
jmp    1199 <bind_to_enum+0x89>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1132 <bind_to_enum+0x22>
mov    -0x30(%rbp),%rax
movb   $0xff,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bind_to_enum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xff,%r13b
test   %ecx,%ecx
jle    115d <bind_to_enum+0x4d>
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %r8,(%rsp)
mov    %ecx,%r14d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12,%rbp,8),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     1161 <bind_to_enum+0x51>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1140 <bind_to_enum+0x30>
xor    %eax,%eax
jmp    1179 <bind_to_enum+0x69>
xor    %eax,%eax
jmp    117d <bind_to_enum+0x6d>
test   %r15,%r15
je     1171 <bind_to_enum+0x61>
mov    (%r15,%rbp,1),%r13b
mov    $0x1,%eax
jmp    1179 <bind_to_enum+0x69>
mov    $0x1,%eax
mov    %ebp,%r13d
mov    (%rsp),%r8
mov    %r13b,(%r8)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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