#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char getchar();
int /*<<< orphan*/ stderr;
int getchoice(char *prompt, char *menu[], FILE *in, FILE *out) {
  char **menu_p = menu;
  char selected = 0;
  int flag = 0;
  fprintf(out, "%s\n", prompt);
  do {
    while (*menu_p != NULL) {
      fprintf(out, "%s\n", *menu_p);
      menu_p++;
    }
    menu_p = menu;
    do {
      selected = getchar();
    } while (selected == '\n');
    while (*menu_p != NULL) {
      if (selected == *menu_p[0]) {
        flag = 1;
        break;
      }
      menu_p++;
    }
    if (flag == 0) {
      fprintf(stderr, "Error choice!\nSelect again:\n");
    }
  } while (flag == 0);
  return selected;
}


x86 assembly (clang, -O0):
<getchoice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movb   $0x0,-0x29(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    %eax,%edi
mov    -0x8(%rbp),%rdx
lea    0xea4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1168 <getchoice+0x48>
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     11a2 <getchoice+0x82>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%rdx
lea    0xe76(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    1168 <getchoice+0x48>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
cmp    $0xa,%eax
je     11aa <getchoice+0x8a>
jmp    11c6 <getchoice+0xa6>
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     1207 <getchoice+0xe7>
movsbl -0x29(%rbp),%eax
mov    -0x28(%rbp),%rcx
mov    (%rcx),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11f6 <getchoice+0xd6>
movl   $0x1,-0x30(%rbp)
jmp    1207 <getchoice+0xe7>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    11c6 <getchoice+0xa6>
cmpl   $0x0,-0x30(%rbp)
jne    1228 <getchoice+0x108>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    122d <getchoice+0x10d>
cmpl   $0x0,-0x30(%rbp)
je     1163 <getchoice+0x43>
movsbl -0x29(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getchoice>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rsi,%r14
mov    %rdi,%rdx
lea    0xec5(%rip),%r15
mov    %ebx,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e92(%rip),%r13
lea    0xeaf(%rip),%r12
mov    %r14,%rbp
jmp    116e <getchoice+0x4e>
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%rbp),%rdx
test   %rdx,%rdx
je     11a0 <getchoice+0x80>
add    $0x8,%rbp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x0(%rbp),%rdx
add    $0x8,%rbp
test   %rdx,%rdx
jne    1180 <getchoice+0x60>
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     11a0 <getchoice+0x80>
mov    (%r14),%rcx
mov    %r14,%rbp
test   %rcx,%rcx
je     1160 <getchoice+0x40>
mov    %r14,%rbp
nopl   0x0(%rax)
cmp    (%rcx),%al
je     11d3 <getchoice+0xb3>
mov    0x8(%rbp),%rcx
add    $0x8,%rbp
test   %rcx,%rcx
jne    11c0 <getchoice+0xa0>
jmp    1160 <getchoice+0x40>
movsbl %al,%eax
add    $0x8,%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"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Error choice!\0ASelect again:\0A\00"
define i32 @getchoice(i8* %0, i8** %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8**
%10 = alloca i8
%11 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%12 = load i8**, i8*** %6
store i8** %12, i8*** %9
store i8 0, i8* %10
store i32 0, i32* %11
%13 = load i32*, i32** %8
%14 = ptrtoint i32* %13 to i32
%15 = load i8*, i8** %5
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %63, %4
br label %18
18: ; preds = %22, %17
%19 = load i8**, i8*** %9
%20 = load i8*, i8** %19
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %30
22: ; preds = %18
%23 = load i32*, i32** %8
%24 = ptrtoint i32* %23 to i32
%25 = load i8**, i8*** %9
%26 = load i8*, i8** %25
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = load i8**, i8*** %9
%29 = getelementptr inbounds i8*, i8** %28, i32 1
store i8** %29, i8*** %9
br label %18
30: ; preds = %18
%31 = load i8**, i8*** %6
store i8** %31, i8*** %9
br label %32
32: ; preds = %34, %30
%33 = call signext i8 (...) @getchar()
store i8 %33, i8* %10
br label %34
34: ; preds = %32
%35 = load i8, i8* %10
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 10
br i1 %37, label %32, label %38
38: ; preds = %34
br label %39
39: ; preds = %53, %38
%40 = load i8**, i8*** %9
%41 = load i8*, i8** %40
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %56
43: ; preds = %39
%44 = load i8, i8* %10
%45 = sext i8 %44 to i32
%46 = load i8**, i8*** %9
%47 = getelementptr inbounds i8*, i8** %46, i64 0
%48 = load i8*, i8** %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %45, %50
br i1 %51, label %52, label %53
52: ; preds = %43
store i32 1, i32* %11
br label %56
53: ; preds = %43
%54 = load i8**, i8*** %9
%55 = getelementptr inbounds i8*, i8** %54, i32 1
store i8** %55, i8*** %9
br label %39
56: ; preds = %52, %39
%57 = load i32, i32* %11
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %62
62: ; preds = %59, %56
br label %63
63: ; preds = %62
%64 = load i32, i32* %11
%65 = icmp eq i32 %64, 0
br i1 %65, label %17, label %66
66: ; preds = %63
%67 = load i8, i8* %10
%68 = sext i8 %67 to i32
ret i32 %68
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@stderr = global i32 0
@.str.1 = [29 x i8] c"Error choice!\0ASelect again:\0A\00"
define i32 @getchoice(i8* %0, i8** nocapture %1, i32* nocapture readnone %2, i32* %3) {
%5 = ptrtoint i32* %3 to i64
%6 = trunc i64 %5 to i32
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %12
8: ; preds = %35, %27
%9 = phi i8** [ %1, %27 ], [ %36, %35 ]
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %8, %4
%13 = phi i8** [ %1, %4 ], [ %9, %8 ]
%14 = load i8*, i8** %13
%15 = icmp eq i8* %14, null
br i1 %15, label %23, label %16
16: ; preds = %12, %16
%17 = phi i8* [ %21, %16 ], [ %14, %12 ]
%18 = phi i8** [ %20, %16 ], [ %13, %12 ]
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %17)
%20 = getelementptr inbounds i8*, i8** %18, i64 1
%21 = load i8*, i8** %20
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %16
23: ; preds = %16, %12
br label %24
24: ; preds = %23, %24
%25 = tail call signext i8 (...) @getchar()
%26 = icmp eq i8 %25, 10
br i1 %26, label %24, label %27
27: ; preds = %24
%28 = load i8*, i8** %1
%29 = icmp eq i8* %28, null
br i1 %29, label %8, label %30
30: ; preds = %27, %35
%31 = phi i8* [ %37, %35 ], [ %28, %27 ]
%32 = phi i8** [ %36, %35 ], [ %1, %27 ]
%33 = load i8, i8* %31
%34 = icmp eq i8 %25, %33
br i1 %34, label %39, label %35
35: ; preds = %30
%36 = getelementptr inbounds i8*, i8** %32, i64 1
%37 = load i8*, i8** %36
%38 = icmp eq i8* %37, null
br i1 %38, label %8, label %30
39: ; preds = %30
%40 = sext i8 %25 to i32
ret i32 %40
}