#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 */
char *get_input(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcasecmp(char *, char *);
int strlen(char *);
char *choose(char *options[], int num_of_options) {
  printf("Choose one of the following:\n");
  int max_length = 0;
  int length = 0;
  for (int i = 0; i < num_of_options; i++) {
    printf("\t%d: "
           "\e[1m"
           "%s"
           "\x1b[0m"
           "\n",
           i + 1, options[i]);
    length = strlen(options[i]) + 1;
    if (length > max_length) {
      max_length = length + 1;
    }
  }
  char input[max_length];
  char *input_ptr = input;
  while (true) {
    input_ptr = get_input(max_length);
    for (int i = 0; i < num_of_options; i++) {
      if (strcasecmp(options[i], input_ptr) == 0) {
        return options[i];
      }
    }
  }
  perror("Fell out of infinite loop");
  return NULL;
}


x86 assembly (clang, -O0):
<choose>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11dd <choose+0x9d>
mov    -0x18(%rbp),%esi
add    $0x1,%esi
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    11ca <choose+0x8a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11cf <choose+0x8f>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1172 <choose+0x32>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x20(%rbp)
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,%rsp
mov    %rcx,-0x28(%rbp)
mov    %rax,-0x30(%rbp)
jmp    120a <choose+0xca>
mov    -0x10(%rbp),%edi
call   1060 <get_input@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1273 <choose+0x133>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1260 <choose+0x120>
mov    -0x8(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret
jmp    1265 <choose+0x125>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    121d <choose+0xdd>
jmp    1205 <choose+0xc5>

x86 assembly (clang, -O2):
<choose>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r12
lea    0xeaa(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%r13d
mov    %ebx,0x4(%rsp)
test   %ebx,%ebx
jle    11b9 <choose+0x69>
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbx),%r15
mov    (%r12,%rbx,8),%rdx
lea    0xe71(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%r12,%rbx,8),%rdi
call   1050 <strlen@plt>
lea    0x2(%rax),%r14d
cmp    %ebp,%eax
cmovl  %ebp,%r14d
mov    %r15,%rbx
mov    %r14d,%ebp
cmp    %r15,%r13
jne    1180 <choose+0x30>
jmp    11c0 <choose+0x70>
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %r14d,%edi
call   1070 <get_input@plt>
cmpl   $0x0,0x4(%rsp)
jle    11c0 <choose+0x70>
mov    %rax,%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12,%rbp,8),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
je     11ff <choose+0xaf>
add    $0x1,%rbp
cmp    %rbp,%r13
jne    11e0 <choose+0x90>
jmp    11c0 <choose+0x70>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Choose one of the following:\0A\00"
@.str.1 = [17 x i8] c"\09%d: \1B[1m%s\1B[0m\0A\00"
define i8* @choose(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
store i8** %0, i8*** %3
store i32 %1, i32* %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
br label %13
13: ; preds = %40, %2
%14 = load i32, i32* %7
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %43
17: ; preds = %13
%18 = load i32, i32* %7
%19 = add nsw i32 %18, 1
%20 = load i8**, i8*** %3
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %19, i8* %24)
%26 = load i8**, i8*** %3
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = load i32, i32* %5
%35 = icmp sgt i32 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %17
%37 = load i32, i32* %6
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %39
39: ; preds = %36, %17
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %13
43: ; preds = %13
%44 = load i32, i32* %5
%45 = zext i32 %44 to i64
%46 = call i8* @llvm.stacksave()
store i8* %46, i8** %8
%47 = alloca i8, i64 %45
store i64 %45, i64* %9
store i8* %47, i8** %10
br label %48
48: ; preds = %76, %43
br label %49
49: ; preds = %48
%50 = load i32, i32* %5
%51 = call i8* @get_input(i32 %50)
store i8* %51, i8** %10
store i32 0, i32* %11
br label %52
52: ; preds = %73, %49
%53 = load i32, i32* %11
%54 = load i32, i32* %4
%55 = icmp slt i32 %53, %54
br i1 %55, label %56, label %76
56: ; preds = %52
%57 = load i8**, i8*** %3
%58 = load i32, i32* %11
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = load i8*, i8** %10
%63 = call i64 @strcasecmp(i8* %61, i8* %62)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %72
65: ; preds = %56
%66 = load i8**, i8*** %3
%67 = load i32, i32* %11
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %66, i64 %68
%70 = load i8*, i8** %69
%71 = load i8*, i8** %8
ret i8* %70
72: ; preds = %56
br label %73
73: ; preds = %72
%74 = load i32, i32* %11
%75 = add nsw i32 %74, 1
store i32 %75, i32* %11
br label %52
76: ; preds = %52
br label %48
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"\09%d: \1B[1m%s\1B[0m\0A\00"
@str = [29 x i8] c"Choose one of the following:\00"
define i8* @choose(i8** nocapture %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %10
7: ; preds = %10, %2
%8 = phi i32 [ 0, %2 ], [ %22, %10 ]
%9 = zext i32 %1 to i64
br label %24
10: ; preds = %5, %10
%11 = phi i64 [ 0, %5 ], [ %13, %10 ]
%12 = phi i32 [ 0, %5 ], [ %22, %10 ]
%13 = add nuw nsw i64 %11, 1
%14 = getelementptr inbounds i8*, i8** %0, i64 %11
%15 = load i8*, i8** %14
%16 = trunc i64 %13 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %16, i8* %15)
%18 = load i8*, i8** %14
%19 = tail call i32 @strlen(i8* %18)
%20 = icmp slt i32 %19, %12
%21 = add nsw i32 %19, 2
%22 = select i1 %20, i32 %12, i32 %21
%23 = icmp eq i64 %13, %6
br i1 %23, label %7, label %10
24: ; preds = %26, %7
%25 = tail call i8* @get_input(i32 %8)
br i1 %4, label %29, label %26
26: ; preds = %27, %24
br label %24
27: ; preds = %29
%28 = icmp eq i64 %35, %9
br i1 %28, label %26, label %29
29: ; preds = %24, %27
%30 = phi i64 [ %35, %27 ], [ 0, %24 ]
%31 = getelementptr inbounds i8*, i8** %0, i64 %30
%32 = load i8*, i8** %31
%33 = tail call i64 @strcasecmp(i8* %32, i8* %25)
%34 = icmp eq i64 %33, 0
%35 = add nuw nsw i64 %30, 1
br i1 %34, label %36, label %27
36: ; preds = %29
ret i8* %32
}