#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*/ gets(char *);
int /*<<< orphan*/ printMenu(int, char **);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int presentMenu(char *question, int optionsc, char **optionsv) {
  int chosenOption = 0;
  printf("%s\n", question);
  printMenu(optionsc, optionsv);
  printf("> ");
  char input[20];
  for (int i = 0; i < 20; i++) {
    input[i] = 0;
  }
  int choice;
  gets(input);
  sscanf(input, "%d", &choice);
  while (choice < 1 || choice > optionsc) {
    do {
      printf("Invalid choice, choose from 1 to %i (or ?).\n> ", optionsc);
      gets(input);
      if (input[0] == '?') {
        printf("%s\n", question);
        printMenu(optionsc, optionsv);
        printf("> ");
        gets(input);
      }
    } while (input[0] < '0' || input[0] > '9');
    sscanf(input, "%i", &choice);
  }
  return choice;
}


x86 assembly (clang, -O0):
<presentMenu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <printMenu@plt>
lea    0xeb4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x14,-0x34(%rbp)
jge    11ae <presentMenu+0x6e>
movslq -0x34(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    118d <presentMenu+0x4d>
lea    -0x30(%rbp),%rdi
call   1040 <gets@plt>
lea    -0x30(%rbp),%rdi
lea    0xe42(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <sscanf@plt>
mov    $0x1,%al
cmpl   $0x1,-0x38(%rbp)
mov    %al,-0x39(%rbp)
jl     11e6 <presentMenu+0xa6>
mov    -0x38(%rbp),%eax
cmp    -0xc(%rbp),%eax
setg   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    11f6 <presentMenu+0xb6>
jmp    129f <presentMenu+0x15f>
jmp    11fb <presentMenu+0xbb>
mov    -0xc(%rbp),%esi
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <gets@plt>
movsbl -0x30(%rbp),%eax
cmp    $0x3f,%eax
jne    1257 <presentMenu+0x117>
mov    -0x8(%rbp),%rsi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <printMenu@plt>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x30(%rbp),%rdi
call   1040 <gets@plt>
jmp    125c <presentMenu+0x11c>
movsbl -0x30(%rbp),%ecx
mov    $0x1,%al
cmp    $0x30,%ecx
mov    %al,-0x3a(%rbp)
jl     127b <presentMenu+0x13b>
movsbl -0x30(%rbp),%eax
cmp    $0x39,%eax
setg   %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
test   $0x1,%al
jne    11fb <presentMenu+0xbb>
lea    -0x30(%rbp),%rdi
lea    0xda5(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1050 <sscanf@plt>
jmp    11cb <presentMenu+0x8b>
mov    -0x38(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<presentMenu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1070 <printMenu@plt>
lea    0xeb3(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <gets@plt>
lea    0xe59(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <sscanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11c4 <presentMenu+0x74>
cmp    %ebp,%eax
jle    124e <presentMenu+0xfe>
lea    0xe38(%rip),%r12
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <gets@plt>
movzbl 0x10(%rsp),%eax
cmp    $0x3f,%al
jne    122a <presentMenu+0xda>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1070 <printMenu@plt>
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <gets@plt>
movzbl 0x10(%rsp),%eax
add    $0xc6,%al
cmp    $0xf6,%al
jb     11e0 <presentMenu+0x90>
mov    %rbx,%rdi
lea    0xdf8(%rip),%rsi
mov    %r13,%rdx
call   1060 <sscanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
jle    11e0 <presentMenu+0x90>
cmp    %ebp,%eax
jg     11e0 <presentMenu+0x90>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [47 x i8] c"Invalid choice, choose from 1 to %i (or ?).\0A> \00"
@.str.4 = [3 x i8] c"%i\00"
define i32 @presentMenu(i8* nocapture %0, i32 %1, i8** %2) {
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%6 = alloca i32
%7 = tail call i32 @puts(i8* dereferenceable(1) %0)
%8 = tail call i32 @printMenu(i32 %1, i8** %2)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%11 = bitcast i32* %6 to i8*
%12 = call i32 @gets(i8* %10)
%13 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %6)
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 1
%16 = icmp sgt i32 %14, %1
%17 = or i1 %15, %16
br i1 %17, label %18, label %40
18: ; preds = %3, %33
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%20 = call i32 @gets(i8* %10)
%21 = load i8, i8* %10
%22 = icmp eq i8 %21, 63
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = call i32 @puts(i8* dereferenceable(1) %0)
%25 = call i32 @printMenu(i32 %1, i8** %2)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @gets(i8* %10)
%28 = load i8, i8* %10
br label %29
29: ; preds = %18, %23
%30 = phi i8 [ %21, %18 ], [ %28, %23 ]
%31 = add i8 %30, -58
%32 = icmp ult i8 %31, -10
br i1 %32, label %33, label %34
33: ; preds = %29, %34
br label %18
34: ; preds = %29
%35 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %6)
%36 = load i32, i32* %6
%37 = icmp slt i32 %36, 1
%38 = icmp sgt i32 %36, %1
%39 = or i1 %37, %38
br i1 %39, label %33, label %40
40: ; preds = %34, %3
%41 = phi i32 [ %14, %3 ], [ %36, %34 ]
ret i32 %41
}