#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 */
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, char const *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdout;
int menu_display(const char *prompt, const char **choices, size_t n) {
  for (int i = 0; i < n; ++i) {
    printf("[%d] - %s\n", i + 1, choices[i]);
  }
  fputs(prompt, stdout);
  int input;
  scanf("%d", &input);
  return input;
}


x86 assembly (clang, -O0):
<menu_display>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1185 <menu_display+0x55>
mov    -0x1c(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114b <menu_display+0x1b>
mov    -0x8(%rbp),%rdi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
lea    0xe6d(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<menu_display>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
test   %rdx,%rdx
je     1177 <menu_display+0x47>
mov    %rdx,%r12
mov    %rsi,%r15
xor    %ebx,%ebx
lea    0xeac(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15,%rbx,8),%rdx
add    $0x1,%rbx
mov    %r13,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
cmp    %rbx,%r12
jne    1160 <menu_display+0x30>
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1040 <fputs@plt>
lea    0xe7c(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"[%d] - %s\0A\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @menu_display(i8* %0, i8** %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i64 %2, i64* %6
store i32 0, i32* %7
br label %9
9: ; preds = %23, %3
%10 = load i32, i32* %7
%11 = sext i32 %10 to i64
%12 = load i64, i64* %6
%13 = icmp ult i64 %11, %12
br i1 %13, label %14, label %26
14: ; preds = %9
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 1
%17 = load i8**, i8*** %5
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %21)
br label %23
23: ; preds = %14
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %9
26: ; preds = %9
%27 = load i8*, i8** %4
%28 = load i32, i32* @stdout
%29 = call i32 @fputs(i8* %27, i32 %28)
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %8)
%31 = load i32, i32* %8
ret i32 %31
}

LLVM IR (-O2):
@.str = [11 x i8] c"[%d] - %s\0A\00"
@stdout = global i32 0
@.str.1 = [3 x i8] c"%d\00"
define i32 @menu_display(i8* %0, i8** nocapture %1, i64 %2) {
%4 = alloca i32
%5 = icmp eq i64 %2, 0
br i1 %5, label %6, label %12
6: ; preds = %12, %3
%7 = load i32, i32* @stdout
%8 = tail call i32 @fputs(i8* %0, i32 %7)
%9 = bitcast i32* %4 to i8*
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%11 = load i32, i32* %4
ret i32 %11
12: ; preds = %3, %12
%13 = phi i64 [ %14, %12 ], [ 0, %3 ]
%14 = add nuw nsw i64 %13, 1
%15 = getelementptr inbounds i8*, i8** %1, i64 %13
%16 = load i8*, i8** %15
%17 = trunc i64 %14 to i32
%18 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %16)
%19 = icmp eq i64 %14, %2
br i1 %19, label %6, label %12
}