#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 */
scalar_t__ memchr(char *, char, int);
int /*<<< orphan*/ strcpy(char *, char *);
unsigned int strlen(char *);
char tolower(char);
char toupper(char);
int parse_choice(char *str, char *err, void *choices, void *choice) {
  unsigned int i;
  char *c;
  strcpy(err, "");
  if (strlen(str) == 0)
    return 0;
  for (i = 0; i < strlen((char *)choices); ++i) {
    c = (char *)(memchr(str, ((char *)choices)[i], 1));
    c = !c ? (char *)memchr(str, toupper(((char *)choices)[i]), 1) : c;
    if (c) {
      *(char *)choice = tolower(*c);
      return !0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_choice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%eax
jne    1196 <parse_choice+0x46>
movl   $0x0,-0x4(%rbp)
jmp    126a <parse_choice+0x11a>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jae    1263 <parse_choice+0x113>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,1),%al
movsbl %al,%esi
mov    $0x1,%edx
call   1060 <memchr@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1215 <parse_choice+0xc5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movsbl (%rax,%rcx,1),%edi
call   1040 <toupper@plt>
mov    -0x50(%rbp),%rdi
movsbl %al,%esi
mov    $0x1,%edx
call   1060 <memchr@plt>
mov    %rax,-0x48(%rbp)
jmp    121d <parse_choice+0xcd>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1250 <parse_choice+0x100>
mov    -0x38(%rbp),%rax
movsbl (%rax),%edi
call   1070 <tolower@plt>
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    126a <parse_choice+0x11a>
jmp    1255 <parse_choice+0x105>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119d <parse_choice+0x4d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_choice>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%rax
mov    %rdi,%r15
lea    0xe96(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     11eb <parse_choice+0x9b>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     11eb <parse_choice+0x9b>
xor    %ebp,%ebp
xchg   %ax,%ax
movsbl (%rbx,%rbp,1),%esi
mov    %r15,%rdi
mov    $0x1,%edx
call   1060 <memchr@plt>
test   %rax,%rax
jne    11db <parse_choice+0x8b>
movsbl (%rbx,%rbp,1),%edi
call   1040 <toupper@plt>
movsbl %al,%esi
mov    %r15,%rdi
mov    $0x1,%edx
call   1060 <memchr@plt>
test   %rax,%rax
jne    11db <parse_choice+0x8b>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbp
jb     1190 <parse_choice+0x40>
xor    %ebp,%ebp
jmp    11eb <parse_choice+0x9b>
movsbl (%rax),%edi
call   1070 <tolower@plt>
mov    %al,(%r14)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i32 @parse_choice(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%12 = load i8*, i8** %7
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%14 = load i8*, i8** %6
%15 = call i32 @strlen(i8* %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 0, i32* %5
br label %61
18: ; preds = %4
store i32 0, i32* %10
br label %19
19: ; preds = %57, %18
%20 = load i32, i32* %10
%21 = load i8*, i8** %8
%22 = call i32 @strlen(i8* %21)
%23 = icmp ult i32 %20, %22
br i1 %23, label %24, label %60
24: ; preds = %19
%25 = load i8*, i8** %6
%26 = load i8*, i8** %8
%27 = load i32, i32* %10
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = call i64 @memchr(i8* %25, i8 signext %30, i32 1)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %11
%33 = load i8*, i8** %11
%34 = icmp ne i8* %33, null
br i1 %34, label %45, label %35
35: ; preds = %24
%36 = load i8*, i8** %6
%37 = load i8*, i8** %8
%38 = load i32, i32* %10
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i8, i8* %40
%42 = call signext i8 @toupper(i8 signext %41)
%43 = call i64 @memchr(i8* %36, i8 signext %42, i32 1)
%44 = inttoptr i64 %43 to i8*
br label %47
45: ; preds = %24
%46 = load i8*, i8** %11
br label %47
47: ; preds = %45, %35
%48 = phi i8* [ %44, %35 ], [ %46, %45 ]
store i8* %48, i8** %11
%49 = load i8*, i8** %11
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %56
51: ; preds = %47
%52 = load i8*, i8** %11
%53 = load i8, i8* %52
%54 = call signext i8 @tolower(i8 signext %53)
%55 = load i8*, i8** %9
store i8 %54, i8* %55
store i32 1, i32* %5
br label %61
56: ; preds = %47
br label %57
57: ; preds = %56
%58 = load i32, i32* %10
%59 = add i32 %58, 1
store i32 %59, i32* %10
br label %19
60: ; preds = %19
store i32 0, i32* %5
br label %61
61: ; preds = %60, %51, %17
%62 = load i32, i32* %5
ret i32 %62
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i32 @parse_choice(i8* %0, i8* %1, i8* %2, i8* nocapture writeonly %3) {
%5 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %32, label %8
8: ; preds = %4
%9 = tail call i32 @strlen(i8* %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %32, label %15
11: ; preds = %21
%12 = tail call i32 @strlen(i8* %2)
%13 = zext i32 %12 to i64
%14 = icmp ult i64 %26, %13
br i1 %14, label %15, label %32
15: ; preds = %8, %11
%16 = phi i64 [ %26, %11 ], [ 0, %8 ]
%17 = getelementptr inbounds i8, i8* %2, i64 %16
%18 = load i8, i8* %17
%19 = tail call i64 @memchr(i8* %0, i8 signext %18, i32 1)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = load i8, i8* %17
%23 = tail call signext i8 @toupper(i8 signext %22)
%24 = tail call i64 @memchr(i8* %0, i8 signext %23, i32 1)
%25 = icmp eq i64 %24, 0
%26 = add nuw nsw i64 %16, 1
br i1 %25, label %11, label %27
27: ; preds = %15, %21
%28 = phi i64 [ %24, %21 ], [ %19, %15 ]
%29 = inttoptr i64 %28 to i8*
%30 = load i8, i8* %29
%31 = tail call signext i8 @tolower(i8 signext %30)
store i8 %31, i8* %3
br label %32
32: ; preds = %11, %8, %4, %27
%33 = phi i32 [ 1, %27 ], [ 0, %4 ], [ 0, %8 ], [ 0, %11 ]
ret i32 %33
}