#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*/ clear_stdin(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ sscanf(char *, char *, int *);
int /*<<< orphan*/ stdin;
int stub1(int);
int process_numeric_input_from_user(const char *output, int (*func)(int)) {
  char buf[10];
  int success = 0;
  int res = 0;
  while (!success) {
    printf("%s: ", output);
    if (fgets(buf, 10, stdin) == NULL) {
      clear_stdin(buf);
      printf("ERROR: You didn't enter any data!\n");
      continue;
    }
    if (sscanf(buf, "%d", &res) <= 0) {
      clear_stdin(buf);
      printf("ERROR: You didn't enter a number!\n");
      continue;
    }
    if (!(success = (*func)(res))) {
      clear_stdin(buf);
      printf("ERROR: That number is not a valid choice\n");
    }
  }
  return res;
}


x86 assembly (clang, -O0):
<process_numeric_input_from_user>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1174 <process_numeric_input_from_user+0x34>
jmp    122e <process_numeric_input_from_user+0xee>
mov    -0x8(%rbp),%rsi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1a(%rbp),%rdi
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    11c3 <process_numeric_input_from_user+0x83>
lea    -0x1a(%rbp),%rdi
call   1030 <clear_stdin@plt>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    115e <process_numeric_input_from_user+0x1e>
lea    -0x1a(%rbp),%rdi
lea    0xe5a(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x0,%rax
jg     11fd <process_numeric_input_from_user+0xbd>
lea    -0x1a(%rbp),%rdi
call   1030 <clear_stdin@plt>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    115e <process_numeric_input_from_user+0x1e>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%edi
call   *%rax
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jne    1229 <process_numeric_input_from_user+0xe9>
lea    -0x1a(%rbp),%rdi
call   1030 <clear_stdin@plt>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    115e <process_numeric_input_from_user+0x1e>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_numeric_input_from_user>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,0x10(%rsp)
mov    %rdi,%r12
movl   $0x0,0xc(%rsp)
lea    0xe8b(%rip),%r15
mov    0x2e6c(%rip),%rbp
lea    0x1e(%rsp),%rbx
lea    0xecb(%rip),%r14
jmp    11a0 <process_numeric_input_from_user+0x50>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <clear_stdin@plt>
mov    %r13,%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <fgets@plt>
mov    %r14,%r13
test   %rax,%rax
je     1190 <process_numeric_input_from_user+0x40>
mov    %rbx,%rdi
lea    0xe36(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1070 <sscanf@plt>
lea    0xe51(%rip),%r13
test   %rax,%rax
jle    1190 <process_numeric_input_from_user+0x40>
mov    0xc(%rsp),%edi
call   *0x10(%rsp)
lea    0xe14(%rip),%r13
test   %eax,%eax
je     1190 <process_numeric_input_from_user+0x40>
mov    0xc(%rsp),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s: \00"
@stdin = global i32 0
@.str.1 = [35 x i8] c"ERROR: You didn't enter any data!\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [35 x i8] c"ERROR: You didn't enter a number!\0A\00"
@.str.4 = [42 x i8] c"ERROR: That number is not a valid choice\0A\00"
define i32 @process_numeric_input_from_user(i8* %0, i32 (i32)* %1) {
%3 = alloca i8*
%4 = alloca i32 (i32)*
%5 = alloca [10 x i8]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 (i32)* %1, i32 (i32)** %4
store i32 0, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %40, %27, %19, %2
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
%11 = xor i1 %10, true
br i1 %11, label %12, label %41
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%16 = load i32, i32* @stdin
%17 = call i32* @fgets(i8* %15, i32 10, i32 %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %12
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%21 = call i32 @clear_stdin(i8* %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
br label %8
23: ; preds = %12
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%25 = call i64 @sscanf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%26 = icmp sle i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%29 = call i32 @clear_stdin(i8* %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %8
31: ; preds = %23
%32 = load i32 (i32)*, i32 (i32)** %4
%33 = load i32, i32* %7
%34 = call i32 %32(i32 %33)
store i32 %34, i32* %6
%35 = icmp ne i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %31
%37 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%38 = call i32 @clear_stdin(i8* %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
br label %40
40: ; preds = %36, %31
br label %8
41: ; preds = %8
%42 = load i32, i32* %7
ret i32 %42
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s: \00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%d\00"
@str = [41 x i8] c"ERROR: That number is not a valid choice\00"
@str.5 = [34 x i8] c"ERROR: You didn't enter a number!\00"
@str.6 = [34 x i8] c"ERROR: You didn't enter any data!\00"
define i32 @process_numeric_input_from_user(i8* %0, i32 (i32)* nocapture %1) {
%3 = alloca [10 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
br label %7
7: ; preds = %12, %2
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = load i32, i32* @stdin
%10 = call i32* @fgets(i8* %5, i32 10, i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %7, %19, %16
%13 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.5, i64 0, i64 0), %16 ], [ getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0), %19 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @str.6, i64 0, i64 0), %7 ]
%14 = call i32 @clear_stdin(i8* %5)
%15 = call i32 @puts(i8* dereferenceable(1) %13)
br label %7
16: ; preds = %7
%17 = call i64 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%18 = icmp slt i64 %17, 1
br i1 %18, label %12, label %19
19: ; preds = %16
%20 = load i32, i32* %4
%21 = call i32 %1(i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %12, label %23
23: ; preds = %19
%24 = load i32, i32* %4
ret i32 %24
}