#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 */
size_t strlen(char const *);
scalar_t__ strncasecmp(char const *, char const *, size_t);
int validateChoice(unsigned int *value, const char *string,
                   const char *const *choices) {
  size_t length = strlen(string);
  *value = 0;
  if (!length)
    return 1;
  {
    unsigned int index = 0;
    const char *choice;
    while ((choice = choices[index])) {
      if (strncasecmp(string, choice, length) == 0) {
        *value = index;
        return 1;
      }
      index += 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<validateChoice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
cmpq   $0x0,-0x28(%rbp)
jne    1162 <validateChoice+0x42>
movl   $0x1,-0x4(%rbp)
jmp    11c7 <validateChoice+0xa7>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     11c0 <validateChoice+0xa0>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <strncasecmp@plt>
cmp    $0x0,%rax
jne    11b2 <validateChoice+0x92>
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11c7 <validateChoice+0xa7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1169 <validateChoice+0x49>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validateChoice>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
movl   $0x0,(%r14)
mov    $0x1,%r15d
test   %rax,%rax
je     1184 <validateChoice+0x64>
mov    (%r12),%rsi
test   %rsi,%rsi
je     117c <validateChoice+0x5c>
mov    %rax,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %rbx,%rdx
call   1040 <strncasecmp@plt>
test   %rax,%rax
je     1181 <validateChoice+0x61>
add    $0x1,%ebp
mov    (%r12,%rbp,8),%rsi
test   %rsi,%rsi
jne    1160 <validateChoice+0x40>
xor    %r15d,%r15d
jmp    1184 <validateChoice+0x64>
mov    %ebp,(%r14)
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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