#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 discardUnnecessaryInput();
int /*<<< orphan*/ printf(char *);
int scanf(char *, int *);
int getMenuOption() {
  int i;
  while (1 != scanf("%d", &i)) {
    printf("\nThat is not a valid choice, please re-enter: ");
    discardUnnecessaryInput();
  }
  if (false == discardUnnecessaryInput()) {
    return i;
  } else {
    printf("\nThat is not a valid choice, please re-enter: ");
    return getMenuOption();
  }
}


x86 assembly (clang, -O0):
<getMenuOption>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     117f <getMenuOption+0x3f>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <discardUnnecessaryInput@plt>
jmp    1148 <getMenuOption+0x8>
mov    $0x0,%al
call   1050 <discardUnnecessaryInput@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    119d <getMenuOption+0x5d>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b1 <getMenuOption+0x71>
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
call   1030 <getMenuOption@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMenuOption>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb0(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
je     119f <getMenuOption+0x5f>
lea    0xe9d(%rip),%r14
lea    0xe93(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <discardUnnecessaryInput@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmp    $0x1,%eax
jne    1180 <getMenuOption+0x40>
xor    %eax,%eax
call   1050 <discardUnnecessaryInput@plt>
test   %eax,%eax
je     11bd <getMenuOption+0x7d>
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
call   1030 <getMenuOption@plt>
jmp    11c1 <getMenuOption+0x81>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [47 x i8] c"\0AThat is not a valid choice, please re-enter: \00"
define i32 @getMenuOption() {
%1 = alloca i32
%2 = alloca i32
br label %3
3: ; preds = %6, %0
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%5 = icmp ne i32 1, %4
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 (...) @discardUnnecessaryInput()
br label %3
9: ; preds = %3
%10 = call i32 (...) @discardUnnecessaryInput()
%11 = icmp eq i32 0, %10
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = load i32, i32* %2
store i32 %13, i32* %1
br label %17
14: ; preds = %9
%15 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @getMenuOption()
store i32 %16, i32* %1
br label %17
17: ; preds = %14, %12
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [47 x i8] c"\0AThat is not a valid choice, please re-enter: \00"
define i32 @getMenuOption() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %10, label %5
5: ; preds = %0, %5
%6 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (...) @discardUnnecessaryInput()
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %5
10: ; preds = %5, %0
%11 = call i32 (...) @discardUnnecessaryInput()
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = load i32, i32* %1
br label %18
15: ; preds = %10
%16 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @getMenuOption()
br label %18
18: ; preds = %15, %13
%19 = phi i32 [ %14, %13 ], [ %17, %15 ]
ret i32 %19
}