#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 getchar();
int /*<<< orphan*/ printf(char *, ...);
int GetChoice(char *greet, char *choice[]) {
  int ret;
  char **option;
  int input;
  int selected = 0;
  if (greet != NULL)
    printf("\nGetChoice: %s\n", greet);
  do {
    option = choice;
    int i = 0;
    while (option[i]) {
      printf("\t %s\n", option[i]);
      i++;
    }
    do {
      input = getchar();
    } while (input == '\n');
    option = choice;
    i = 0;
    while (option[i]) {
      if (option[i][0] == input) {
        selected = 1;
        printf("You select choice: %c\n", input);
        break;
      }
      i++;
    }
    if (selected == 0) {
      printf("input error, please select a new choice\n");
    }
  } while (selected == 0);
  return input;
}


x86 assembly (clang, -O0):
<GetChoice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1154 <GetChoice+0x34>
mov    -0x8(%rbp),%rsi
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1159 <GetChoice+0x39>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11a3 <GetChoice+0x83>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1168 <GetChoice+0x48>
jmp    11a8 <GetChoice+0x88>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xa,-0x24(%rbp)
je     11a8 <GetChoice+0x88>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1221 <GetChoice+0x101>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    -0x24(%rbp),%eax
jne    1213 <GetChoice+0xf3>
movl   $0x1,-0x28(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1221 <GetChoice+0x101>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11cb <GetChoice+0xab>
cmpl   $0x0,-0x28(%rbp)
jne    1239 <GetChoice+0x119>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123e <GetChoice+0x11e>
cmpl   $0x0,-0x28(%rbp)
je     1159 <GetChoice+0x39>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetChoice>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
test   %rdi,%rdi
je     1151 <GetChoice+0x21>
mov    %rdi,%rsi
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%r15),%r12
lea    0xed1(%rip),%r14
lea    0xead(%rip),%rbx
jmp    1178 <GetChoice+0x48>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1030 <puts@plt>
mov    (%r15),%rsi
test   %rsi,%rsi
je     11b0 <GetChoice+0x80>
mov    %r12,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%rbp),%rsi
add    $0x8,%rbp
test   %rsi,%rsi
jne    1190 <GetChoice+0x60>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
je     11b0 <GetChoice+0x80>
mov    %eax,%ebp
mov    (%r15),%rcx
mov    %r12,%rax
test   %rcx,%rcx
je     1170 <GetChoice+0x40>
nopl   0x0(%rax)
movsbl (%rcx),%ecx
cmp    %ecx,%ebp
je     11e5 <GetChoice+0xb5>
mov    (%rax),%rcx
add    $0x8,%rax
test   %rcx,%rcx
jne    11d0 <GetChoice+0xa0>
jmp    1170 <GetChoice+0x40>
lea    0xe2a(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [16 x i8] c"\0AGetChoice: %s\0A\00"
@.str.1 = [6 x i8] c"\09 %s\0A\00"
@.str.2 = [23 x i8] c"You select choice: %c\0A\00"
@str = [40 x i8] c"input error, please select a new choice\00"
define i32 @GetChoice(i8* %0, i8** nocapture %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %6
6: ; preds = %4, %2
br label %9
7: ; preds = %27, %24
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %9
9: ; preds = %6, %7
%10 = load i8*, i8** %1
%11 = icmp eq i8* %10, null
br i1 %11, label %20, label %12
12: ; preds = %9, %12
%13 = phi i64 [ %16, %12 ], [ 0, %9 ]
%14 = phi i8* [ %18, %12 ], [ %10, %9 ]
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = add nuw i64 %13, 1
%17 = getelementptr inbounds i8*, i8** %1, i64 %16
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %12
20: ; preds = %12, %9
br label %21
21: ; preds = %20, %21
%22 = tail call i32 (...) @getchar()
%23 = icmp eq i32 %22, 10
br i1 %23, label %21, label %24
24: ; preds = %21
%25 = load i8*, i8** %1
%26 = icmp eq i8* %25, null
br i1 %26, label %7, label %31
27: ; preds = %31
%28 = getelementptr inbounds i8*, i8** %1, i64 %37
%29 = load i8*, i8** %28
%30 = icmp eq i8* %29, null
br i1 %30, label %7, label %31
31: ; preds = %24, %27
%32 = phi i64 [ %37, %27 ], [ 0, %24 ]
%33 = phi i8* [ %29, %27 ], [ %25, %24 ]
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %22, %35
%37 = add nuw i64 %32, 1
br i1 %36, label %38, label %27
38: ; preds = %31
%39 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %22)
ret i32 %22
}