#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*/ clr_keyboard_buffer();
int /*<<< orphan*/ printf(char *);
int scanf(char *, int *);
int validate_input(int num, int non_int_char) {
  while (num < 0 || num >= 3 || non_int_char == 0) {
    clr_keyboard_buffer();
    printf("\nI'm sorry that number is not valid\n");
    printf("Please enter a valid number: ");
    non_int_char = scanf("%d", &num);
  }
  return num;
}


x86 assembly (clang, -O0):
<validate_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x9(%rbp)
jl     1166 <validate_input+0x36>
mov    $0x1,%al
cmpl   $0x3,-0x4(%rbp)
mov    %al,-0x9(%rbp)
jge    1166 <validate_input+0x36>
cmpl   $0x0,-0x8(%rbp)
sete   %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1176 <validate_input+0x46>
jmp    11ad <validate_input+0x7d>
mov    $0x0,%al
call   1030 <clr_keyboard_buffer@plt>
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
lea    0xea7(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <scanf@plt>
mov    %eax,-0x8(%rbp)
jmp    113e <validate_input+0xe>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_input>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,0x4(%rsp)
test   %esi,%esi
je     1157 <validate_input+0x17>
mov    %edi,%eax
cmp    $0x3,%edi
jb     11af <validate_input+0x6f>
lea    0xec3(%rip),%r14
lea    0xe9b(%rip),%r15
lea    0xeb2(%rip),%r12
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <clr_keyboard_buffer@plt>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
test   %eax,%eax
je     1180 <validate_input+0x40>
mov    0x4(%rsp),%eax
cmp    $0x2,%eax
ja     1180 <validate_input+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [37 x i8] c"\0AI'm sorry that number is not valid\0A\00"
@.str.1 = [30 x i8] c"Please enter a valid number: \00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @validate_input(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
br label %5
5: ; preds = %16, %2
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = load i32, i32* %3
%10 = icmp sge i32 %9, 3
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 0
br label %14
14: ; preds = %11, %8, %5
%15 = phi i1 [ true, %8 ], [ true, %5 ], [ %13, %11 ]
br i1 %15, label %16, label %21
16: ; preds = %14
%17 = call i32 (...) @clr_keyboard_buffer()
%18 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
store i32 %20, i32* %4
br label %5
21: ; preds = %14
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@.str.1 = [30 x i8] c"Please enter a valid number: \00"
@.str.2 = [3 x i8] c"%d\00"
@str = [36 x i8] c"\0AI'm sorry that number is not valid\00"
define i32 @validate_input(i32 %0, i32 %1) {
%3 = alloca i32
store i32 %0, i32* %3
%4 = icmp ugt i32 %0, 2
%5 = icmp eq i32 %1, 0
%6 = or i1 %5, %4
br i1 %6, label %7, label %16
7: ; preds = %2, %7
%8 = call i32 (...) @clr_keyboard_buffer()
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
%13 = icmp ugt i32 %12, 2
%14 = icmp eq i32 %11, 0
%15 = or i1 %14, %13
br i1 %15, label %7, label %16
16: ; preds = %7, %2
%17 = phi i32 [ %0, %2 ], [ %12, %7 ]
ret i32 %17
}