#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*/ isdigit(char);
int /*<<< orphan*/ printf(char *);
int validateInput(int userInput, char charValue) {
  if (!isdigit(charValue)) {
    printf("Unknown character entered\n\n");
    return -1;
    ;
  }
  if (userInput > 4 || userInput < 0) {
    printf("Invalid number entered\n\n");
    return -1;
  } else {
    return userInput;
  }
}


x86 assembly (clang, -O0):
<validateInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    115b <validateInput+0x3b>
lea    0xeb6(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <validateInput+0x6d>
cmpl   $0x4,-0x8(%rbp)
jg     116f <validateInput+0x4f>
cmpl   $0x0,-0x8(%rbp)
jge    1187 <validateInput+0x67>
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <validateInput+0x6d>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validateInput>:
push   %rbx
mov    %edi,%ebx
mov    %esi,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     113c <validateInput+0x1c>
cmp    $0x5,%ebx
jb     114d <validateInput+0x2d>
lea    0xee1(%rip),%rdi
jmp    1143 <validateInput+0x23>
lea    0xebd(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Unknown character entered\0A\0A\00"
@.str.1 = [25 x i8] c"Invalid number entered\0A\0A\00"
define i32 @validateInput(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i32 %0, i32* %4
store i8 %1, i8* %5
%6 = load i8, i8* %5
%7 = call i32 @isdigit(i8 signext %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %21
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 4
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14, %11
%18 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %21
19: ; preds = %14
%20 = load i32, i32* %4
store i32 %20, i32* %3
br label %21
21: ; preds = %19, %17, %9
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
@str = [27 x i8] c"Unknown character entered\0A\00"
@str.2 = [24 x i8] c"Invalid number entered\0A\00"
define i32 @validateInput(i32 %0, i8 signext %1) {
%3 = tail call i32 @isdigit(i8 signext %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = icmp ugt i32 %0, 4
br i1 %6, label %7, label %10
7: ; preds = %5, %2
%8 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @str.2, i64 0, i64 0), %5 ]
%9 = tail call i32 @puts(i8* dereferenceable(1) %8)
br label %10
10: ; preds = %7, %5
%11 = phi i32 [ %0, %5 ], [ -1, %7 ]
ret i32 %11
}