#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
unsigned int strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
unsigned performMenu(const char *const OPTIONS[], const size_t OPTIONS_SIZE) {
  unsigned option;
  do {
    printf("Select an option:\n");
    for (size_t i = 0; i < OPTIONS_SIZE; i++) {
      printf("\t%zu. %s\n", i + 1, OPTIONS[i]);
    }
    printf("> ");
    char buffer[32];
    if (!fgets(buffer, sizeof(buffer), stdin)) {
      fprintf(stderr, "Unable to get input from stdin.\n");
      return 1;
    }
    option = strtoul(buffer, NULL, 0);
  } while (!option || option > OPTIONS_SIZE);
  return option;
}


x86 assembly (clang, -O0):
<performMenu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a7 <performMenu+0x67>
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1166 <performMenu+0x26>
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e28(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1040 <fgets@plt>
cmp    $0x0,%eax
jne    11f6 <performMenu+0xb6>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1235 <performMenu+0xf5>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x51(%rbp)
je     1224 <performMenu+0xe4>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%rax
seta   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    1150 <performMenu+0x10>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<performMenu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %rsi,%r14
neg    %r14
mov    %rsp,%r13
lea    0xe8c(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xea7(%rip),%rdi
call   1030 <puts@plt>
test   %r12,%r12
je     11c4 <performMenu+0x74>
mov    $0x1,%r15d
nopw   0x0(%rax,%rax,1)
mov    -0x8(%rbx,%r15,8),%rdx
mov    %rbp,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%r14,%r15,1),%rax
add    $0x1,%rax
add    $0x1,%r15
cmp    $0x1,%rax
jne    11a0 <performMenu+0x50>
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    $0x20,%esi
call   1050 <fgets@plt>
test   %eax,%eax
je     1209 <performMenu+0xb9>
mov    %r13,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtoul@plt>
test   %eax,%eax
je     1180 <performMenu+0x30>
mov    %eax,%ecx
cmp    %r12,%rcx
ja     1180 <performMenu+0x30>
jmp    1223 <performMenu+0xd3>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Select an option:\0A\00"
@.str.1 = [10 x i8] c"\09%zu. %s\0A\00"
@.str.2 = [3 x i8] c"> \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.3 = [33 x i8] c"Unable to get input from stdin.\0A\00"
define i32 @performMenu(i8** %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
%8 = alloca [32 x i8]
store i8** %0, i8*** %4
store i64 %1, i64* %5
br label %9
9: ; preds = %46, %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %7
br label %11
11: ; preds = %23, %9
%12 = load i64, i64* %7
%13 = load i64, i64* %5
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i64, i64* %7
%17 = add i64 %16, 1
%18 = load i8**, i8*** %4
%19 = load i64, i64* %7
%20 = getelementptr inbounds i8*, i8** %18, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %17, i8* %21)
br label %23
23: ; preds = %15
%24 = load i64, i64* %7
%25 = add i64 %24, 1
store i64 %25, i64* %7
br label %11
26: ; preds = %11
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* %28, i32 32, i32 %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %26
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %50
35: ; preds = %26
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%37 = call i32 @strtoul(i8* %36, i32* null, i32 0)
store i32 %37, i32* %6
br label %38
38: ; preds = %35
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %46
41: ; preds = %38
%42 = load i32, i32* %6
%43 = zext i32 %42 to i64
%44 = load i64, i64* %5
%45 = icmp ugt i64 %43, %44
br label %46
46: ; preds = %41, %38
%47 = phi i1 [ true, %38 ], [ %45, %41 ]
br i1 %47, label %9, label %48
48: ; preds = %46
%49 = load i32, i32* %6
store i32 %49, i32* %3
br label %50
50: ; preds = %48, %32
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"\09%zu. %s\0A\00"
@.str.2 = [3 x i8] c"> \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.3 = [33 x i8] c"Unable to get input from stdin.\0A\00"
@str = [18 x i8] c"Select an option:\00"
define i32 @performMenu(i8** nocapture %0, i64 %1) {
%3 = alloca [32 x i8]
%4 = icmp eq i64 %1, 0
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
br label %6
6: ; preds = %23, %2
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br i1 %4, label %8, label %13
8: ; preds = %13, %6
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %5, i32 32, i32 %10)
%12 = icmp eq i32 %11, 0
br i1 %12, label %20, label %23
13: ; preds = %6, %13
%14 = phi i64 [ %15, %13 ], [ 0, %6 ]
%15 = add nuw i64 %14, 1
%16 = getelementptr inbounds i8*, i8** %0, i64 %14
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i64 %15, i8* %17)
%19 = icmp eq i64 %15, %1
br i1 %19, label %8, label %13
20: ; preds = %8
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %29
23: ; preds = %8
%24 = call i32 @strtoul(i8* nocapture %5, i32* null, i32 0)
%25 = icmp eq i32 %24, 0
%26 = zext i32 %24 to i64
%27 = icmp ugt i64 %26, %1
%28 = or i1 %25, %27
br i1 %28, label %6, label %29
29: ; preds = %23, %20
%30 = phi i32 [ 1, %20 ], [ %24, %23 ]
ret i32 %30
}