#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 atoi(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char const *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strlen(char *);
int prompt_for_int(const char *prompt, int min, int max) {
  char input[1024];
  char *t;
  int valid;
  int ret;
  while (1) {
    printf(prompt);
    fflush(stdout);
    fgets(input, 1024, stdin);
    valid = 1;
    for (t = input; t < input + 1024; t++) {
      if (*t == 0)
        break;
      if (*t < 20) {
        *t = '\0';
        break;
      }
      if (*t == 'q' || *t == 'Q') {
        return -1;
      }
      if (*t < '0' || *t > '9') {
        valid = 0;
        break;
      }
    }
    if (strlen(input) == 0) {
      valid = 0;
    }
    if (valid) {
      ret = atoi(input);
      if (ret >= min && ret <= max) {
        return ret;
      }
    }
    printf("Please enter a number from %d to %d\n", min, max);
  }
  return 0;
}


x86 assembly (clang, -O0):
<prompt_for_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    -0x420(%rbp),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1050 <fgets@plt>
movl   $0x1,-0x42c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rax
lea    -0x420(%rbp),%rcx
add    $0x400,%rcx
cmp    %rcx,%rax
jae    128b <prompt_for_int+0x13b>
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11e6 <prompt_for_int+0x96>
jmp    128b <prompt_for_int+0x13b>
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x14,%eax
jge    1208 <prompt_for_int+0xb8>
mov    -0x428(%rbp),%rax
movb   $0x0,(%rax)
jmp    128b <prompt_for_int+0x13b>
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x71,%eax
je     122e <prompt_for_int+0xde>
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x51,%eax
jne    123a <prompt_for_int+0xea>
movl   $0xffffffff,-0x4(%rbp)
jmp    1314 <prompt_for_int+0x1c4>
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     1260 <prompt_for_int+0x110>
mov    -0x428(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    126f <prompt_for_int+0x11f>
movl   $0x0,-0x42c(%rbp)
jmp    128b <prompt_for_int+0x13b>
jmp    1274 <prompt_for_int+0x124>
mov    -0x428(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x428(%rbp)
jmp    11b0 <prompt_for_int+0x60>
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%rax
jne    12ab <prompt_for_int+0x15b>
movl   $0x0,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
je     12fb <prompt_for_int+0x1ab>
lea    -0x420(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x430(%rbp)
mov    -0x430(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     12f6 <prompt_for_int+0x1a6>
mov    -0x430(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     12f6 <prompt_for_int+0x1a6>
mov    -0x430(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1314 <prompt_for_int+0x1c4>
jmp    12fb <prompt_for_int+0x1ab>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xcf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1165 <prompt_for_int+0x15>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prompt_for_int>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %edx,0x8(%rsp)
mov    %esi,0xc(%rsp)
mov    %rdi,%r13
lea    0x410(%rsp),%rbx
lea    0x10(%rsp),%r15
mov    0x2e68(%rip),%r12
mov    0x2e71(%rip),%rbp
jmp    1199 <prompt_for_int+0x59>
nopl   0x0(%rax)
lea    0xe79(%rip),%rdi
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%r12
mov    %r13,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,%r14
mov    (%r12),%edi
call   1050 <fflush@plt>
mov    0x0(%rbp),%edx
mov    %r15,%rdi
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %r15,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rax),%ecx
test   %cl,%cl
je     11f7 <prompt_for_int+0xb7>
cmp    $0x13,%cl
jle    1200 <prompt_for_int+0xc0>
mov    %ecx,%edx
or     $0x20,%dl
cmp    $0x71,%dl
je     122c <prompt_for_int+0xec>
add    $0xc6,%cl
cmp    $0xf6,%cl
jb     1180 <prompt_for_int+0x40>
add    $0x1,%rax
cmp    %rbx,%rax
jb     11d0 <prompt_for_int+0x90>
cmpb   $0x0,0x10(%rsp)
jne    120e <prompt_for_int+0xce>
jmp    1180 <prompt_for_int+0x40>
movb   $0x0,(%rax)
cmpb   $0x0,0x10(%rsp)
je     1180 <prompt_for_int+0x40>
mov    %r15,%rdi
call   1060 <atoi@plt>
cmp    0xc(%rsp),%eax
jl     1180 <prompt_for_int+0x40>
cmp    0x8(%rsp),%eax
jg     1180 <prompt_for_int+0x40>
jmp    1231 <prompt_for_int+0xf1>
mov    $0xffffffff,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@stdin = global i32 0
@.str = [37 x i8] c"Please enter a number from %d to %d\0A\00"
define i32 @prompt_for_int(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
br label %12
12: ; preds = %3, %86
%13 = load i8*, i8** %5
%14 = call i32 (i8*, ...) @printf(i8* %13)
%15 = load i32, i32* @stdout
%16 = call i32 @fflush(i32 %15)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %17, i32 1024, i32 %18)
store i32 1, i32* %10
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
store i8* %20, i8** %9
br label %21
21: ; preds = %62, %12
%22 = load i8*, i8** %9
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%24 = getelementptr inbounds i8, i8* %23, i64 1024
%25 = icmp ult i8* %22, %24
br i1 %25, label %26, label %65
26: ; preds = %21
%27 = load i8*, i8** %9
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
br label %65
32: ; preds = %26
%33 = load i8*, i8** %9
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp slt i32 %35, 20
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = load i8*, i8** %9
store i8 0, i8* %38
br label %65
39: ; preds = %32
%40 = load i8*, i8** %9
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 113
br i1 %43, label %49, label %44
44: ; preds = %39
%45 = load i8*, i8** %9
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 81
br i1 %48, label %49, label %50
49: ; preds = %44, %39
store i32 -1, i32* %4
br label %90
50: ; preds = %44
%51 = load i8*, i8** %9
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp slt i32 %53, 48
br i1 %54, label %60, label %55
55: ; preds = %50
%56 = load i8*, i8** %9
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp sgt i32 %58, 57
br i1 %59, label %60, label %61
60: ; preds = %55, %50
store i32 0, i32* %10
br label %65
61: ; preds = %55
br label %62
62: ; preds = %61
%63 = load i8*, i8** %9
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %9
br label %21
65: ; preds = %60, %37, %31, %21
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%67 = call i64 @strlen(i8* %66)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %65
store i32 0, i32* %10
br label %70
70: ; preds = %69, %65
%71 = load i32, i32* %10
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %86
73: ; preds = %70
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%75 = call i32 @atoi(i8* %74)
store i32 %75, i32* %11
%76 = load i32, i32* %11
%77 = load i32, i32* %6
%78 = icmp sge i32 %76, %77
br i1 %78, label %79, label %85
79: ; preds = %73
%80 = load i32, i32* %11
%81 = load i32, i32* %7
%82 = icmp sle i32 %80, %81
br i1 %82, label %83, label %85
83: ; preds = %79
%84 = load i32, i32* %11
store i32 %84, i32* %4
br label %90
85: ; preds = %79, %73
br label %86
86: ; preds = %85, %70
%87 = load i32, i32* %6
%88 = load i32, i32* %7
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %87, i32 %88)
br label %12
90: ; preds = %83, %49
%91 = load i32, i32* %4
ret i32 %91
}

LLVM IR (-O2):
@stdout = global i32 0
@stdin = global i32 0
@.str = [37 x i8] c"Please enter a number from %d to %d\0A\00"
define i32 @prompt_for_int(i8* nocapture %0, i32 %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 1024
br label %7
7: ; preds = %35, %3
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %0)
%9 = load i32, i32* @stdout
%10 = call i32 @fflush(i32 %9)
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %5, i32 1024, i32 %11)
br label %13
13: ; preds = %7, %24
%14 = phi i8* [ %5, %7 ], [ %25, %24 ]
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %27, label %17
17: ; preds = %13
%18 = icmp slt i8 %15, 20
br i1 %18, label %19, label %20
19: ; preds = %17
store i8 0, i8* %14
br label %27
20: ; preds = %17
switch i8 %15, label %21 [
i8 113, label %37
i8 81, label %37
]
21: ; preds = %20
%22 = add nsw i8 %15, -58
%23 = icmp ult i8 %22, -10
br i1 %23, label %35, label %24
24: ; preds = %21
%25 = getelementptr inbounds i8, i8* %14, i64 1
%26 = icmp ult i8* %25, %6
br i1 %26, label %13, label %27
27: ; preds = %13, %24, %19
%28 = load i8, i8* %5
%29 = icmp eq i8 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %27
%31 = call i32 @atoi(i8* %5)
%32 = icmp slt i32 %31, %1
%33 = icmp sgt i32 %31, %2
%34 = or i1 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %21, %30, %27
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
br label %7
37: ; preds = %30, %20, %20
%38 = phi i32 [ -1, %20 ], [ -1, %20 ], [ %31, %30 ]
ret i32 %38
}