#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 EOF;
int is_val_ok(int, int const, int const);
int /*<<< orphan*/ myflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *);
int /*<<< orphan*/ stdin;
int read_int(const char *prompt, const int lo_val, const int hi_val) {
  int retval, input, val_ok;
  val_ok = 0;
  do {
    printf("\n%s", prompt);
    if (lo_val != hi_val)
      printf("<%d-%d>+<Enter>: ", lo_val, hi_val);
    retval = scanf("%d", &input);
    if (retval == 1) {
      if (lo_val != hi_val) {
        val_ok = is_val_ok(input, lo_val, hi_val);
        if (!val_ok)
          printf("Invalid selection - use <%d> to <%d>...!", lo_val, hi_val);
      } else
        val_ok = 1;
    } else
      printf("Invalid input - integer only!");
    myflush(stdin);
  } while (retval == EOF || !val_ok);
  return input;
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     118b <read_int+0x4b>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe84(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <scanf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    11f4 <read_int+0xb4>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     11e8 <read_int+0xa8>
mov    -0x18(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <is_val_ok@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11e3 <read_int+0xa3>
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ef <read_int+0xaf>
movl   $0x1,-0x1c(%rbp)
jmp    1202 <read_int+0xc2>
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   1040 <myflush@plt>
mov    -0x14(%rbp),%ecx
mov    $0x1,%al
mov    0x2dc4(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1d(%rbp)
je     1233 <read_int+0xf3>
cmpl   $0x0,-0x1c(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1159 <read_int+0x19>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %esi,%ebp
mov    %rdi,0x10(%rsp)
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %r15d,%r13d
lea    0xe96(%rip),%rdi
mov    0x10(%rsp),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    %ebx,%ebp
jne    11b0 <read_int+0x70>
lea    0xe95(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    %eax,%r12d
mov    $0x1,%r14d
mov    $0x1,%r15d
cmp    $0x1,%eax
jne    1200 <read_int+0xc0>
jmp    1214 <read_int+0xd4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe4d(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe4d(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1060 <scanf@plt>
mov    %eax,%r12d
cmp    $0x1,%eax
jne    1200 <read_int+0xc0>
mov    0xc(%rsp),%edi
mov    %ebp,%esi
mov    %ebx,%edx
call   1050 <is_val_ok@plt>
mov    $0x1,%r14d
test   %eax,%eax
je     123d <read_int+0xfd>
mov    %eax,%r15d
jmp    1214 <read_int+0xd4>
nopw   0x0(%rax,%rax,1)
lea    0xe3b(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12d,%r14d
mov    %r13d,%r15d
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1040 <myflush@plt>
mov    0x2db7(%rip),%rax
cmp    (%rax),%r14d
je     1160 <read_int+0x20>
test   %r15d,%r15d
je     1160 <read_int+0x20>
jmp    1254 <read_int+0x114>
xor    %r15d,%r15d
lea    0xdd2(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1214 <read_int+0xd4>
mov    0xc(%rsp),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"\0A%s\00"
@.str.1 = [18 x i8] c"<%d-%d>+<Enter>: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [41 x i8] c"Invalid selection - use <%d> to <%d>...!\00"
@.str.4 = [30 x i8] c"Invalid input - integer only!\00"
@stdin = global i32 0
@EOF = global i32 0
define i32 @read_int(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %9
br label %10
10: ; preds = %55, %3
%11 = load i8*, i8** %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = load i32, i32* %5
%18 = load i32, i32* %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18)
br label %20
20: ; preds = %16, %10
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %42
24: ; preds = %20
%25 = load i32, i32* %5
%26 = load i32, i32* %6
%27 = icmp ne i32 %25, %26
br i1 %27, label %28, label %40
28: ; preds = %24
%29 = load i32, i32* %8
%30 = load i32, i32* %5
%31 = load i32, i32* %6
%32 = call i32 @is_val_ok(i32 %29, i32 %30, i32 %31)
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = icmp ne i32 %33, 0
br i1 %34, label %39, label %35
35: ; preds = %28
%36 = load i32, i32* %5
%37 = load i32, i32* %6
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %36, i32 %37)
br label %39
39: ; preds = %35, %28
br label %41
40: ; preds = %24
store i32 1, i32* %9
br label %41
41: ; preds = %40, %39
br label %44
42: ; preds = %20
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %41
%45 = load i32, i32* @stdin
%46 = call i32 @myflush(i32 %45)
br label %47
47: ; preds = %44
%48 = load i32, i32* %7
%49 = load i32, i32* @EOF
%50 = icmp eq i32 %48, %49
br i1 %50, label %55, label %51
51: ; preds = %47
%52 = load i32, i32* %9
%53 = icmp ne i32 %52, 0
%54 = xor i1 %53, true
br label %55
55: ; preds = %51, %47
%56 = phi i1 [ true, %47 ], [ %54, %51 ]
br i1 %56, label %10, label %57
57: ; preds = %55
%58 = load i32, i32* %8
ret i32 %58
}

LLVM IR (-O2):
@.str = [4 x i8] c"\0A%s\00"
@.str.1 = [18 x i8] c"<%d-%d>+<Enter>: \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [41 x i8] c"Invalid selection - use <%d> to <%d>...!\00"
@.str.4 = [30 x i8] c"Invalid input - integer only!\00"
@stdin = global i32 0
@EOF = global i32 0
define i32 @read_int(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp eq i32 %1, %2
br label %7
7: ; preds = %26, %3
%8 = phi i32 [ 0, %3 ], [ %28, %26 ]
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
br i1 %6, label %10, label %13
10: ; preds = %7
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%12 = icmp eq i32 %11, 1
br i1 %12, label %26, label %23
13: ; preds = %7
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %1, i32 %2)
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* %4
%19 = call i32 @is_val_ok(i32 %18, i32 %1, i32 %2)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0), i32 %1, i32 %2)
br label %26
23: ; preds = %13, %10
%24 = phi i32 [ %15, %13 ], [ %11, %10 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %26
26: ; preds = %10, %21, %17, %23
%27 = phi i32 [ 1, %17 ], [ 1, %21 ], [ %24, %23 ], [ 1, %10 ]
%28 = phi i32 [ %19, %17 ], [ 0, %21 ], [ %8, %23 ], [ 1, %10 ]
%29 = load i32, i32* @stdin
%30 = call i32 @myflush(i32 %29)
%31 = load i32, i32* @EOF
%32 = icmp eq i32 %27, %31
%33 = icmp eq i32 %28, 0
%34 = select i1 %32, i1 true, i1 %33
br i1 %34, label %7, label %35
35: ; preds = %26
%36 = load i32, i32* %4
ret i32 %36
}