#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 */
struct argp_state {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ argp_error(struct argp_state *, char *, char const *,
                              char const *);
scalar_t__ strcasecmp(char const *, char const *);
int strlen(char const *);
scalar_t__ strncasecmp(char const *, char const *, int);
char const *stub1(unsigned int);
int parse_enum(const char *arg, const char *(*choice_fn)(unsigned n),
               const char *kind, int allow_mismatches,
               struct argp_state *state) {
  const char *choice;
  int arglen = strlen(arg);
  int n = 0;
  int partial_match = -1;
  while ((choice = (*choice_fn)(n)) != NULL)
    if (strcasecmp(choice, arg) == 0)
      return n;
    else {
      if (strncasecmp(choice, arg, arglen) == 0) {
        if (partial_match >= 0) {
          argp_error(state, "%s: Ambiguous %s", arg, kind);
          return -1;
        } else
          partial_match = n;
      }
      n++;
    }
  if (partial_match < 0 && !allow_mismatches)
    argp_error(state, "%s: Invalid %s", arg, kind);
  return partial_match;
}


x86 assembly (clang, -O0):
<parse_enum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0xffffffff,-0x44(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%edi
call   *%rax
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     120f <parse_enum+0xcf>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    11ae <parse_enum+0x6e>
mov    -0x40(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1241 <parse_enum+0x101>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%rax
jne    1201 <parse_enum+0xc1>
cmpl   $0x0,-0x44(%rbp)
jl     11f6 <parse_enum+0xb6>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe1b(%rip),%rsi
call   1050 <argp_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1241 <parse_enum+0x101>
mov    -0x40(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    1201 <parse_enum+0xc1>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1175 <parse_enum+0x35>
cmpl   $0x0,-0x44(%rbp)
jge    123b <parse_enum+0xfb>
cmpl   $0x0,-0x24(%rbp)
jne    123b <parse_enum+0xfb>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xddb(%rip),%rsi
call   1050 <argp_error@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_enum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x8(%rsp)
mov    %ecx,0x4(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rsi,%r13
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%r14d
xor    %ebp,%ebp
xor    %edi,%edi
call   *%r13
test   %rax,%rax
je     11da <parse_enum+0x9a>
mov    %rax,%r15
mov    $0xffffffff,%r12d
jmp    11a0 <parse_enum+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %ebp,%edi
call   *%r13
mov    %rax,%r15
test   %rax,%rax
je     11e0 <parse_enum+0xa0>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     1208 <parse_enum+0xc8>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1060 <strncasecmp@plt>
test   %rax,%rax
jne    1190 <parse_enum+0x50>
test   %r12d,%r12d
mov    %ebp,%r12d
js     1190 <parse_enum+0x50>
mov    $0xffffffff,%r12d
lea    0xe28(%rip),%rsi
jmp    11f3 <parse_enum+0xb3>
mov    $0xffffffff,%r12d
cmpl   $0x0,0x4(%rsp)
jne    1205 <parse_enum+0xc5>
test   %r12d,%r12d
jns    1205 <parse_enum+0xc5>
lea    0xe1e(%rip),%rsi
mov    0x8(%rsp),%rdi
mov    %rbx,%rdx
mov    0x10(%rsp),%rcx
call   1050 <argp_error@plt>
mov    %r12d,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.argp_state = type { i32 }
@.str = [17 x i8] c"%s: Ambiguous %s\00"
@.str.1 = [15 x i8] c"%s: Invalid %s\00"
define i32 @parse_enum(i8* %0, i8* (i32)* %1, i8* %2, i32 %3, %struct.argp_state* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8* (i32)*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca %struct.argp_state*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %7
store i8* (i32)* %1, i8* (i32)** %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store %struct.argp_state* %4, %struct.argp_state** %11
%16 = load i8*, i8** %7
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %13
store i32 0, i32* %14
store i32 -1, i32* %15
br label %18
18: ; preds = %50, %5
%19 = load i8* (i32)*, i8* (i32)** %8
%20 = load i32, i32* %14
%21 = call i8* %19(i32 %20)
store i8* %21, i8** %12
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %51
23: ; preds = %18
%24 = load i8*, i8** %12
%25 = load i8*, i8** %7
%26 = call i64 @strcasecmp(i8* %24, i8* %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = load i32, i32* %14
store i32 %29, i32* %6
br label %64
30: ; preds = %23
%31 = load i8*, i8** %12
%32 = load i8*, i8** %7
%33 = load i32, i32* %13
%34 = call i64 @strncasecmp(i8* %31, i8* %32, i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %47
36: ; preds = %30
%37 = load i32, i32* %15
%38 = icmp sge i32 %37, 0
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = load %struct.argp_state*, %struct.argp_state** %11
%41 = load i8*, i8** %7
%42 = load i8*, i8** %9
%43 = call i32 @argp_error(%struct.argp_state* %40, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %41, i8* %42)
store i32 -1, i32* %6
br label %64
44: ; preds = %36
%45 = load i32, i32* %14
store i32 %45, i32* %15
br label %46
46: ; preds = %44
br label %47
47: ; preds = %46, %30
%48 = load i32, i32* %14
%49 = add nsw i32 %48, 1
store i32 %49, i32* %14
br label %50
50: ; preds = %47
br label %18
51: ; preds = %18
%52 = load i32, i32* %15
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %62
54: ; preds = %51
%55 = load i32, i32* %10
%56 = icmp ne i32 %55, 0
br i1 %56, label %62, label %57
57: ; preds = %54
%58 = load %struct.argp_state*, %struct.argp_state** %11
%59 = load i8*, i8** %7
%60 = load i8*, i8** %9
%61 = call i32 @argp_error(%struct.argp_state* %58, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %59, i8* %60)
br label %62
62: ; preds = %57, %54, %51
%63 = load i32, i32* %15
store i32 %63, i32* %6
br label %64
64: ; preds = %62, %39, %28
%65 = load i32, i32* %6
ret i32 %65
}

LLVM IR (-O2):
%struct.argp_state = type { i32 }
@.str = [17 x i8] c"%s: Ambiguous %s\00"
@.str.1 = [15 x i8] c"%s: Invalid %s\00"
define i32 @parse_enum(i8* %0, i8* (i32)* nocapture %1, i8* %2, i32 %3, %struct.argp_state* %4) {
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i8* %1(i32 0)
%8 = icmp eq i8* %7, null
br i1 %8, label %25, label %9
9: ; preds = %5, %20
%10 = phi i8* [ %23, %20 ], [ %7, %5 ]
%11 = phi i32 [ %21, %20 ], [ -1, %5 ]
%12 = phi i32 [ %22, %20 ], [ 0, %5 ]
%13 = tail call i64 @strcasecmp(i8* %10, i8* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %34, label %15
15: ; preds = %9
%16 = tail call i64 @strncasecmp(i8* %10, i8* %0, i32 %6)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = icmp sgt i32 %11, -1
br i1 %19, label %30, label %20
20: ; preds = %18, %15
%21 = phi i32 [ %11, %15 ], [ %12, %18 ]
%22 = add nuw nsw i32 %12, 1
%23 = tail call i8* %1(i32 %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %9
25: ; preds = %20, %5
%26 = phi i32 [ -1, %5 ], [ %21, %20 ]
%27 = icmp sgt i32 %26, -1
%28 = icmp ne i32 %3, 0
%29 = or i1 %28, %27
br i1 %29, label %34, label %30
30: ; preds = %18, %25
%31 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %25 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %18 ]
%32 = phi i32 [ %26, %25 ], [ -1, %18 ]
%33 = tail call i32 @argp_error(%struct.argp_state* %4, i8* %31, i8* %0, i8* %2)
br label %34
34: ; preds = %9, %30, %25
%35 = phi i32 [ %26, %25 ], [ %32, %30 ], [ %12, %9 ]
ret i32 %35
}