#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 *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ showhelp(int);
int get_input_num(char *name, int defaultval, int helpnum, int minval,
                  int maxval, int *retval) {
  char str[80];
  int i;
  for (;;) {
    printf("\nPlease enter %s (default = %d) -> ", name, defaultval);
    scanf("%s", str);
    if (str[0] == 'x')
      return 1;
    if (str[0] == '?')
      showhelp(helpnum);
    else if (isdigit(str[0]) || (str[0] == '-') || str[0] == 'd') {
      if (str[0] == 'd')
        i = defaultval;
      else
        i = atoi(str);
      if (i < minval || i > maxval)
        printf("Please enter \"?\", \"x\", \"d\" or an integer value between "
               "%d and %d.",
               minval, maxval);
      else {
        *retval = i;
        return 0;
      }
    } else
      printf("Please enter \"?\", \"x\", \"d\" or an integer value between %d "
             "and %d.",
             minval, maxval);
  }
}


x86 assembly (clang, -O0):
<get_input_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe94(%rip),%rdi
call   1050 <scanf@plt>
movsbl -0x80(%rbp),%eax
cmp    $0x78,%eax
jne    11ae <get_input_num+0x5e>
movl   $0x1,-0x4(%rbp)
jmp    1291 <get_input_num+0x141>
movsbl -0x80(%rbp),%eax
cmp    $0x3f,%eax
jne    11c8 <get_input_num+0x78>
mov    -0x18(%rbp),%edi
call   1060 <showhelp@plt>
jmp    128c <get_input_num+0x13c>
movsbl -0x80(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    11f5 <get_input_num+0xa5>
movsbl -0x80(%rbp),%eax
cmp    $0x2d,%eax
je     11f5 <get_input_num+0xa5>
movsbl -0x80(%rbp),%eax
cmp    $0x64,%eax
jne    1273 <get_input_num+0x123>
movsbl -0x80(%rbp),%eax
cmp    $0x64,%eax
jne    1210 <get_input_num+0xc0>
mov    -0x14(%rbp),%eax
mov    %eax,-0x84(%rbp)
jmp    121f <get_input_num+0xcf>
lea    -0x80(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     123d <get_input_num+0xed>
mov    -0x84(%rbp),%eax
cmp    -0x20(%rbp),%eax
jle    1256 <get_input_num+0x106>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126e <get_input_num+0x11e>
mov    -0x84(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1291 <get_input_num+0x141>
jmp    1287 <get_input_num+0x137>
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    128c <get_input_num+0x13c>
jmp    1170 <get_input_num+0x20>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_input_num>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r9,0x8(%rsp)
mov    %r8d,%r12d
mov    %ecx,%r13d
mov    %edx,0x4(%rsp)
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xeab(%rip),%r15
lea    0x10(%rsp),%r14
jmp    1189 <get_input_num+0x39>
mov    0x4(%rsp),%edi
call   1060 <showhelp@plt>
lea    0xe70(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <scanf@plt>
movzbl 0x10(%rsp),%eax
cmp    $0x3f,%al
je     1180 <get_input_num+0x30>
cmp    $0x78,%al
je     121b <get_input_num+0xcb>
movsbl %al,%edi
call   1030 <isdigit@plt>
movzbl 0x10(%rsp),%ecx
test   %rax,%rax
je     11cf <get_input_num+0x7f>
mov    %ebp,%eax
cmp    $0x64,%cl
je     11e0 <get_input_num+0x90>
jmp    11f0 <get_input_num+0xa0>
cmp    $0x2d,%cl
je     11f0 <get_input_num+0xa0>
mov    %ebp,%eax
cmp    $0x64,%cl
jne    1202 <get_input_num+0xb2>
nopl   0x0(%rax,%rax,1)
cmp    %r13d,%eax
jge    11fd <get_input_num+0xad>
jmp    1202 <get_input_num+0xb2>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1070 <atoi@plt>
cmp    %r13d,%eax
jl     1202 <get_input_num+0xb2>
cmp    %r12d,%eax
jle    1222 <get_input_num+0xd2>
lea    0xe1e(%rip),%rdi
mov    %r13d,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1189 <get_input_num+0x39>
mov    $0x1,%eax
jmp    122b <get_input_num+0xdb>
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"\0APlease enter %s (default = %d) -> \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [66 x i8] c"Please enter \22?\22, \22x\22, \22d\22 or an integer value between %d and %d.\00"
define i32 @get_input_num(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca [80 x i8]
%15 = alloca i32
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32* %5, i32** %13
br label %16
16: ; preds = %81, %6
%17 = load i8*, i8** %8
%18 = load i32, i32* %9
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %18)
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 120
br i1 %25, label %26, label %27
26: ; preds = %16
store i32 1, i32* %7
br label %82
27: ; preds = %16
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 63
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = load i32, i32* %10
%34 = call i32 @showhelp(i32 %33)
br label %81
35: ; preds = %27
%36 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%37 = load i8, i8* %36
%38 = call i64 @isdigit(i8 signext %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %50, label %40
40: ; preds = %35
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %43, 45
br i1 %44, label %50, label %45
45: ; preds = %40
%46 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 100
br i1 %49, label %50, label %76
50: ; preds = %45, %40, %35
%51 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 100
br i1 %54, label %55, label %57
55: ; preds = %50
%56 = load i32, i32* %9
store i32 %56, i32* %15
br label %60
57: ; preds = %50
%58 = getelementptr inbounds [80 x i8], [80 x i8]* %14, i64 0, i64 0
%59 = call i32 @atoi(i8* %58)
store i32 %59, i32* %15
br label %60
60: ; preds = %57, %55
%61 = load i32, i32* %15
%62 = load i32, i32* %11
%63 = icmp slt i32 %61, %62
br i1 %63, label %68, label %64
64: ; preds = %60
%65 = load i32, i32* %15
%66 = load i32, i32* %12
%67 = icmp sgt i32 %65, %66
br i1 %67, label %68, label %72
68: ; preds = %64, %60
%69 = load i32, i32* %11
%70 = load i32, i32* %12
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i32 %69, i32 %70)
br label %75
72: ; preds = %64
%73 = load i32, i32* %15
%74 = load i32*, i32** %13
store i32 %73, i32* %74
store i32 0, i32* %7
br label %82
75: ; preds = %68
br label %80
76: ; preds = %45
%77 = load i32, i32* %11
%78 = load i32, i32* %12
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i32 %77, i32 %78)
br label %80
80: ; preds = %76, %75
br label %81
81: ; preds = %80, %32
br label %16
82: ; preds = %72, %26
%83 = load i32, i32* %7
ret i32 %83
}

LLVM IR (-O2):
@.str = [36 x i8] c"\0APlease enter %s (default = %d) -> \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [66 x i8] c"Please enter \22?\22, \22x\22, \22d\22 or an integer value between %d and %d.\00"
define i32 @get_input_num(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32* nocapture writeonly %5) {
%7 = alloca [80 x i8]
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
br label %9
9: ; preds = %32, %6
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1)
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%12 = load i8, i8* %8
switch i8 %12, label %15 [
i8 120, label %36
i8 63, label %13
]
13: ; preds = %9
%14 = call i32 @showhelp(i32 %2)
br label %32
15: ; preds = %9
%16 = call i64 @isdigit(i8 signext %12)
%17 = freeze i64 %16
%18 = icmp eq i64 %17, 0
%19 = load i8, i8* %8
br i1 %18, label %20, label %21
20: ; preds = %15
switch i8 %19, label %34 [
i8 100, label %25
i8 45, label %23
]
21: ; preds = %15
%22 = icmp eq i8 %19, 100
br i1 %22, label %25, label %23
23: ; preds = %20, %21
%24 = call i32 @atoi(i8* %8)
br label %25
25: ; preds = %21, %20, %23
%26 = phi i32 [ %24, %23 ], [ %1, %20 ], [ %1, %21 ]
%27 = icmp slt i32 %26, %3
%28 = icmp sgt i32 %26, %4
%29 = or i1 %27, %28
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i32 %3, i32 %4)
br label %32
32: ; preds = %30, %34, %13
br label %9
33: ; preds = %25
store i32 %26, i32* %5
br label %36
34: ; preds = %20
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i32 %3, i32 %4)
br label %32
36: ; preds = %9, %33
%37 = phi i32 [ 0, %33 ], [ 1, %9 ]
ret i32 %37
}