#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__ isAbbreviatedPhrase(char const *, char const *);
int validateChoiceEx(unsigned int *value, const char *string,
                     const void *choices, size_t size) {
  *value = 0;
  if (!*string)
    return 1;
  const void *choice = choices;
  while (1) {
    typedef struct {
      const char *name;
    } Entry;
    const Entry *entry = choice;
    const char *name = entry->name;
    if (!name)
      break;
    if (isAbbreviatedPhrase(name, string)) {
      *value = (choice - choices) / size;
      return 1;
    }
    choice += size;
  }
  return 0;
}


x86 assembly (clang, -O0):
<validateChoiceEx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    114b <validateChoiceEx+0x3b>
movl   $0x1,-0x4(%rbp)
jmp    11cc <validateChoiceEx+0xbc>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1176 <validateChoiceEx+0x66>
jmp    11c5 <validateChoiceEx+0xb5>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <isAbbreviatedPhrase@plt>
cmp    $0x0,%rax
je     11b4 <validateChoiceEx+0xa4>
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x28(%rbp)
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11cc <validateChoiceEx+0xbc>
mov    -0x28(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1153 <validateChoiceEx+0x43>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validateChoiceEx>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
movl   $0x0,(%rdi)
mov    $0x1,%r14d
cmpb   $0x0,(%rsi)
je     118f <validateChoiceEx+0x7f>
mov    %rdx,%rbp
mov    %rdi,%r15
mov    (%rdx),%rdi
test   %rdi,%rdi
je     116a <validateChoiceEx+0x5a>
mov    %rcx,%r12
mov    %rsi,%r13
add    %rcx,%rbp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rsi
call   1030 <isAbbreviatedPhrase@plt>
test   %rax,%rax
jne    116f <validateChoiceEx+0x5f>
mov    0x0(%rbp,%rbx,1),%rdi
add    %r12,%rbx
test   %rdi,%rdi
jne    1150 <validateChoiceEx+0x40>
xor    %r14d,%r14d
jmp    118f <validateChoiceEx+0x7f>
mov    %rbx,%rax
or     %r12,%rax
shr    $0x20,%rax
je     1185 <validateChoiceEx+0x75>
mov    %rbx,%rax
xor    %edx,%edx
div    %r12
jmp    118c <validateChoiceEx+0x7c>
mov    %ebx,%eax
xor    %edx,%edx
div    %r12d
mov    %eax,(%r15)
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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