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


x86 assembly (clang, -O0):
<GetChoice>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1160 <GetChoice+0x40>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xea7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1165 <GetChoice+0x45>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11b3 <GetChoice+0x93>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe72(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1174 <GetChoice+0x54>
jmp    11b8 <GetChoice+0x98>
mov    -0x18(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
je     11b8 <GetChoice+0x98>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1237 <GetChoice+0x117>
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    -0x34(%rbp),%eax
jne    1229 <GetChoice+0x109>
movl   $0x1,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1237 <GetChoice+0x117>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11dd <GetChoice+0xbd>
cmpl   $0x0,-0x38(%rbp)
jne    1253 <GetChoice+0x133>
mov    -0x20(%rbp),%rdi
lea    0xde1(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    1258 <GetChoice+0x138>
cmpl   $0x0,-0x38(%rbp)
je     1165 <GetChoice+0x45>
mov    -0x34(%rbp),%eax
add    $0x40,%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,%r14
mov    %rdx,%rbx
mov    %rsi,%r15
test   %rdi,%rdi
je     115d <GetChoice+0x2d>
mov    %rdi,%rdx
lea    0xead(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0x8(%r15),%r12
lea    0xea8(%rip),%r13
jmp    1189 <GetChoice+0x59>
nopw   0x0(%rax,%rax,1)
mov    $0x28,%esi
mov    $0x1,%edx
lea    0xeac(%rip),%rdi
mov    %r14,%rcx
call   1040 <fwrite@plt>
mov    (%r15),%rdx
test   %rdx,%rdx
je     11c0 <GetChoice+0x90>
mov    %r12,%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x0(%rbp),%rdx
add    $0x8,%rbp
test   %rdx,%rdx
jne    11a0 <GetChoice+0x70>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    $0xa,%eax
je     11c0 <GetChoice+0x90>
mov    %eax,%ebp
mov    (%r15),%rcx
mov    %r12,%rax
test   %rcx,%rcx
je     1170 <GetChoice+0x40>
nopw   0x0(%rax,%rax,1)
movsbl (%rcx),%ecx
cmp    %ecx,%ebp
je     11f8 <GetChoice+0xc8>
mov    (%rax),%rcx
add    $0x8,%rax
test   %rcx,%rcx
jne    11e0 <GetChoice+0xb0>
jmp    1170 <GetChoice+0x40>
lea    0xe17(%rip),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
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, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8**
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
store i32 0, i32* %12
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = load i32*, i32** %8
%18 = load i8*, i8** %5
%19 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %16, %4
br label %21
21: ; preds = %81, %20
%22 = load i8**, i8*** %6
store i8** %22, i8*** %10
store i32 0, i32* %13
br label %23
23: ; preds = %30, %21
%24 = load i8**, i8*** %10
%25 = load i32, i32* %13
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %40
30: ; preds = %23
%31 = load i32*, i32** %8
%32 = load i8**, i8*** %10
%33 = load i32, i32* %13
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i32, i32* %13
%39 = add nsw i32 %38, 1
store i32 %39, i32* %13
br label %23
40: ; preds = %23
br label %41
41: ; preds = %44, %40
%42 = load i32*, i32** %7
%43 = call i32 @getc(i32* %42)
store i32 %43, i32* %11
br label %44
44: ; preds = %41
%45 = load i32, i32* %11
%46 = icmp eq i32 %45, 10
br i1 %46, label %41, label %47
47: ; preds = %44
%48 = load i8**, i8*** %6
store i8** %48, i8*** %10
store i32 0, i32* %13
br label %49
49: ; preds = %71, %47
%50 = load i8**, i8*** %10
%51 = load i32, i32* %13
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %74
56: ; preds = %49
%57 = load i8**, i8*** %10
%58 = load i32, i32* %13
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = getelementptr inbounds i8, i8* %61, i64 0
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = load i32, i32* %11
%66 = icmp eq i32 %64, %65
br i1 %66, label %67, label %71
67: ; preds = %56
store i32 1, i32* %12
%68 = load i32*, i32** %8
%69 = load i32, i32* %11
%70 = call i32 (i32*, i8*, ...) @fprintf(i32* %68, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %69)
br label %74
71: ; preds = %56
%72 = load i32, i32* %13
%73 = add nsw i32 %72, 1
store i32 %73, i32* %13
br label %49
74: ; preds = %67, %49
%75 = load i32, i32* %12
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = load i32*, i32** %8
%79 = call i32 (i32*, i8*, ...) @fprintf(i32* %78, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
br label %80
80: ; preds = %77, %74
br label %81
81: ; preds = %80
%82 = load i32, i32* %12
%83 = icmp eq i32 %82, 0
br i1 %83, label %21, label %84
84: ; preds = %81
%85 = load i32, i32* %11
ret i32 %85
}

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