#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*/ free(char *);
char *getLine();
int /*<<< orphan*/ printf(char *, ...);
int strtol(char *, char **, int /*<<< orphan*/);
void number(char *what, short *num, int min, int max) {
  char *line, *end;
  int val;
  printf("%s (%d..%d) [%hd]:  ", what, min, max, *num);
  line = getLine();
  if (!*line)
    val = *num;
  else {
    val = strtol(line, &end, 0);
    if (val < min || val > max || *end) {
      printf("???");
      val = *num;
    }
  }
  free(line);
  *num = val;
}


x86 assembly (clang, -O0):
<number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
movswl (%rax),%r8d
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <getLine@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    119d <number+0x5d>
mov    -0x10(%rbp),%rax
movswl (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    11f4 <number+0xb4>
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     11d7 <number+0x97>
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     11d7 <number+0x97>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ef <number+0xaf>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
movswl (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    11f4 <number+0xb4>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<number>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%rsi
movswl (%r14),%r8d
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <getLine@plt>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     11ac <number+0x6c>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <strtol@plt>
cmp    %r12d,%eax
jl     119e <number+0x5e>
mov    %eax,%ebp
cmp    %r15d,%eax
jg     119e <number+0x5e>
mov    0x8(%rsp),%rax
cmpb   $0x0,(%rax)
je     11b0 <number+0x70>
lea    0xe70(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzwl (%r14),%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %bp,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"%s (%d..%d) [%hd]: \00"
@.str.1 = [4 x i8] c"???\00"
define void @number(i8* %0, i16* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i16*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store i16* %1, i16** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i8*, i8** %5
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = load i16*, i16** %6
%16 = load i16, i16* %15
%17 = sext i16 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %13, i32 %14, i32 %17)
%19 = call i8* (...) @getLine()
store i8* %19, i8** %9
%20 = load i8*, i8** %9
%21 = load i8, i8* %20
%22 = icmp ne i8 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %4
%24 = load i16*, i16** %6
%25 = load i16, i16* %24
%26 = sext i16 %25 to i32
store i32 %26, i32* %11
br label %48
27: ; preds = %4
%28 = load i8*, i8** %9
%29 = call i32 @strtol(i8* %28, i8** %10, i32 0)
store i32 %29, i32* %11
%30 = load i32, i32* %11
%31 = load i32, i32* %7
%32 = icmp slt i32 %30, %31
br i1 %32, label %42, label %33
33: ; preds = %27
%34 = load i32, i32* %11
%35 = load i32, i32* %8
%36 = icmp sgt i32 %34, %35
br i1 %36, label %42, label %37
37: ; preds = %33
%38 = load i8*, i8** %10
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %37, %33, %27
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%44 = load i16*, i16** %6
%45 = load i16, i16* %44
%46 = sext i16 %45 to i32
store i32 %46, i32* %11
br label %47
47: ; preds = %42, %37
br label %48
48: ; preds = %47, %23
%49 = load i8*, i8** %9
%50 = call i32 @free(i8* %49)
%51 = load i32, i32* %11
%52 = trunc i32 %51 to i16
%53 = load i16*, i16** %6
store i16 %52, i16* %53
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"%s (%d..%d) [%hd]: \00"
@.str.1 = [4 x i8] c"???\00"
define void @number(i8* %0, i16* nocapture %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = load i16, i16* %1
%8 = sext i16 %7 to i32
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %2, i32 %3, i32 %8)
%10 = tail call i8* (...) @getLine()
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %24, label %13
13: ; preds = %4
%14 = call i32 @strtol(i8* %10, i8** %5, i32 0)
%15 = icmp slt i32 %14, %2
%16 = icmp sgt i32 %14, %3
%17 = or i1 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %18, %13
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %4, %22
%25 = load i16, i16* %1
%26 = zext i16 %25 to i32
br label %27
27: ; preds = %24, %18
%28 = phi i32 [ %14, %18 ], [ %26, %24 ]
%29 = tail call i32 @free(i8* %10)
%30 = trunc i32 %28 to i16
store i16 %30, i16* %1
ret void
}