#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 */
struct termios {
  int c_lflag;
};

/* Variables and functions */
int ECHO;
int ICANON;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ TCSANOW;
int /*<<< orphan*/ clrscr();
int getchar();
scalar_t__ islower(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int tolower(int);
int toupper(int);
int getInputInv(char *drop_screen, int range, int queue) {
  while (1) {
    struct termios newt, oldt;
    tcgetattr(STDIN_FILENO, &oldt);
    newt = oldt;
    newt.c_lflag &= ~(ICANON | ECHO);
    tcsetattr(STDIN_FILENO, TCSANOW, &newt);
    int input, ch;
    input = getchar();
    if (input == 126)
      input = getchar();
    if (input == 27)
      input = getchar();
    if (input == '[')
      ch = getchar();
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
    if ((input >= 65 && input <= 90) || (input >= 97 && input <= 122) ||
        input == '0' || (input == '-' && queue == 1)) {
      if (islower(input)) {
        input = toupper(input);
        range = toupper(range);
      } else {
        input = tolower(input);
        range = tolower(range);
      }
      if (input > range) {
        printf("\33[%d;%dH", 0, 0);
        printf("\33[0;97;40m"
               "%s",
               drop_screen);
        printf("\33[40m"
               "                                                               "
               "           ");
        printf("\r"
               "\33[1;31;40m"
               "You don't see such item.");
        continue;
      } else {
        clrscr();
        if (islower(input))
          input = toupper(input);
        else
          input = tolower(input);
        return input;
      }
    }
    printf("\33[%d;%dH", 0, 0);
    printf("\33[0;97;40m"
           "%s",
           drop_screen);
    printf("\33[40m"
           "                                                                   "
           "       ");
    printf("\r"
           "\33[1;31;40m"
           "Wrong command.");
  }
  return 1;
}


x86 assembly (clang, -O0):
<getInputInv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1090 <tcgetattr@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    0x2e26(%rip),%rcx
or     (%rcx),%eax
xor    $0xffffffff,%eax
and    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   10a0 <tcsetattr@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x7e,-0x24(%rbp)
jne    11fe <getInputInv+0x7e>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1b,-0x24(%rbp)
jne    1212 <getInputInv+0x92>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x5b,-0x24(%rbp)
jne    1226 <getInputInv+0xa6>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x28(%rbp)
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   10a0 <tcsetattr@plt>
cmpl   $0x41,-0x24(%rbp)
jl     1255 <getInputInv+0xd5>
cmpl   $0x5a,-0x24(%rbp)
jle    1287 <getInputInv+0x107>
cmpl   $0x61,-0x24(%rbp)
jl     1269 <getInputInv+0xe9>
cmpl   $0x7a,-0x24(%rbp)
jle    1287 <getInputInv+0x107>
cmpl   $0x30,-0x24(%rbp)
je     1287 <getInputInv+0x107>
cmpl   $0x2d,-0x24(%rbp)
jne    1358 <getInputInv+0x1d8>
cmpl   $0x1,-0x10(%rbp)
jne    1358 <getInputInv+0x1d8>
mov    -0x24(%rbp),%edi
call   1040 <islower@plt>
cmp    $0x0,%rax
je     12b4 <getInputInv+0x134>
mov    -0x24(%rbp),%edi
call   1050 <toupper@plt>
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <toupper@plt>
mov    %eax,-0xc(%rbp)
jmp    12ca <getInputInv+0x14a>
mov    -0x24(%rbp),%edi
call   1080 <tolower@plt>
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%edi
call   1080 <tolower@plt>
mov    %eax,-0xc(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    131b <getInputInv+0x19b>
lea    0xd23(%rip),%rdi
xor    %edx,%edx
mov    %edx,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xd16(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1192 <getInputInv+0x12>
mov    $0x0,%al
call   1030 <clrscr@plt>
mov    -0x24(%rbp),%edi
call   1040 <islower@plt>
cmp    $0x0,%rax
je     1344 <getInputInv+0x1c4>
mov    -0x24(%rbp),%edi
call   1050 <toupper@plt>
mov    %eax,-0x24(%rbp)
jmp    134f <getInputInv+0x1cf>
mov    -0x24(%rbp),%edi
call   1080 <tolower@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret
lea    0xca1(%rip),%rdi
xor    %edx,%edx
mov    %edx,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xc94(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xc93(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xcf9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1192 <getInputInv+0x12>

x86 assembly (clang, -O2):
<getInputInv>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,0x10(%rsp)
mov    0x2e33(%rip),%r15
mov    %rsp,%rbx
mov    0x2e41(%rip),%r12
xor    $0x1,%edx
mov    %edx,0xc(%rsp)
jmp    1211 <getInputInv+0x91>
call   1080 <tolower@plt>
mov    %eax,%ebp
mov    %r14d,%edi
call   1080 <tolower@plt>
mov    %eax,%r14d
lea    0xe9d(%rip),%rbx
cmp    %eax,%ebp
jle    130c <getInputInv+0x18c>
lea    0xe28(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe1f(%rip),%rdi
mov    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe19(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rsp,%rbx
mov    (%r15),%edi
mov    %rbx,%rsi
call   1090 <tcgetattr@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%eax
mov    0x2d9c(%rip),%rcx
or     (%rcx),%eax
not    %eax
and    (%rsp),%eax
mov    %eax,0x8(%rsp)
mov    (%r15),%edi
mov    (%r12),%esi
lea    0x8(%rsp),%rdx
call   10a0 <tcsetattr@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%r13d
cmp    $0x7e,%eax
je     12b0 <getInputInv+0x130>
cmp    $0x1b,%r13d
je     12c0 <getInputInv+0x140>
cmp    $0x5b,%r13d
jne    126a <getInputInv+0xea>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    (%r15),%edi
mov    (%r12),%esi
mov    %rbx,%rdx
call   10a0 <tcsetattr@plt>
lea    -0x41(%r13),%eax
cmp    $0x1a,%eax
jae    12e0 <getInputInv+0x160>
mov    %r13d,%edi
call   1040 <islower@plt>
mov    %r13d,%edi
test   %rax,%rax
je     11b0 <getInputInv+0x30>
call   1050 <toupper@plt>
mov    %eax,%ebp
mov    %r14d,%edi
call   1050 <toupper@plt>
jmp    11bf <getInputInv+0x3f>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%r13d
cmp    $0x1b,%r13d
jne    125d <getInputInv+0xdd>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%r13d
cmp    $0x5b,%r13d
je     1263 <getInputInv+0xe3>
jmp    126a <getInputInv+0xea>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13d,%eax
xor    $0x2d,%eax
or     0xc(%rsp),%eax
sete   %al
cmp    $0x30,%r13d
je     1282 <getInputInv+0x102>
lea    -0x61(%r13),%ecx
cmp    $0x1a,%ecx
jb     1282 <getInputInv+0x102>
test   %al,%al
jne    1282 <getInputInv+0x102>
lea    0xd83(%rip),%rbx
jmp    11d1 <getInputInv+0x51>
xor    %eax,%eax
call   1030 <clrscr@plt>
mov    %ebp,%edi
call   1040 <islower@plt>
mov    %ebp,%edi
test   %rax,%rax
je     1328 <getInputInv+0x1a8>
call   1050 <toupper@plt>
jmp    132d <getInputInv+0x1ad>
call   1080 <tolower@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
@.str = [9 x i8] c"\1B[%d;%dH\00"
@.str.1 = [13 x i8] c"\1B[0;97;40m%s\00"
@.str.2 = [80 x i8] c"\1B[40m \00"
@.str.3 = [36 x i8] c"\0D\1B[1;31;40mYou don't see such item.\00"
@.str.4 = [26 x i8] c"\0D\1B[1;31;40mWrong command.\00"
define i32 @getInputInv(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.termios
%8 = alloca %struct.termios
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
br label %11
11: ; preds = %3, %83, %102
%12 = load i32, i32* @STDIN_FILENO
%13 = call i32 @tcgetattr(i32 %12, %struct.termios* %8)
%14 = bitcast %struct.termios* %7 to i8*
%15 = bitcast %struct.termios* %8 to i8*
%16 = load i32, i32* @ICANON
%17 = load i32, i32* @ECHO
%18 = or i32 %16, %17
%19 = xor i32 %18, -1
%20 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%21 = load i32, i32* %20
%22 = and i32 %21, %19
store i32 %22, i32* %20
%23 = load i32, i32* @STDIN_FILENO
%24 = load i32, i32* @TCSANOW
%25 = call i32 @tcsetattr(i32 %23, i32 %24, %struct.termios* %7)
%26 = call i32 (...) @getchar()
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp eq i32 %27, 126
br i1 %28, label %29, label %31
29: ; preds = %11
%30 = call i32 (...) @getchar()
store i32 %30, i32* %9
br label %31
31: ; preds = %29, %11
%32 = load i32, i32* %9
%33 = icmp eq i32 %32, 27
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 (...) @getchar()
store i32 %35, i32* %9
br label %36
36: ; preds = %34, %31
%37 = load i32, i32* %9
%38 = icmp eq i32 %37, 91
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 (...) @getchar()
store i32 %40, i32* %10
br label %41
41: ; preds = %39, %36
%42 = load i32, i32* @STDIN_FILENO
%43 = load i32, i32* @TCSANOW
%44 = call i32 @tcsetattr(i32 %42, i32 %43, %struct.termios* %8)
%45 = load i32, i32* %9
%46 = icmp sge i32 %45, 65
br i1 %46, label %47, label %50
47: ; preds = %41
%48 = load i32, i32* %9
%49 = icmp sle i32 %48, 90
br i1 %49, label %65, label %50
50: ; preds = %47, %41
%51 = load i32, i32* %9
%52 = icmp sge i32 %51, 97
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* %9
%55 = icmp sle i32 %54, 122
br i1 %55, label %65, label %56
56: ; preds = %53, %50
%57 = load i32, i32* %9
%58 = icmp eq i32 %57, 48
br i1 %58, label %65, label %59
59: ; preds = %56
%60 = load i32, i32* %9
%61 = icmp eq i32 %60, 45
br i1 %61, label %62, label %102
62: ; preds = %59
%63 = load i32, i32* %6
%64 = icmp eq i32 %63, 1
br i1 %64, label %65, label %102
65: ; preds = %62, %56, %53, %47
%66 = load i32, i32* %9
%67 = call i64 @islower(i32 %66)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %74
69: ; preds = %65
%70 = load i32, i32* %9
%71 = call i32 @toupper(i32 %70)
store i32 %71, i32* %9
%72 = load i32, i32* %5
%73 = call i32 @toupper(i32 %72)
store i32 %73, i32* %5
br label %79
74: ; preds = %65
%75 = load i32, i32* %9
%76 = call i32 @tolower(i32 %75)
store i32 %76, i32* %9
%77 = load i32, i32* %5
%78 = call i32 @tolower(i32 %77)
store i32 %78, i32* %5
br label %79
79: ; preds = %74, %69
%80 = load i32, i32* %9
%81 = load i32, i32* %5
%82 = icmp sgt i32 %80, %81
br i1 %82, label %83, label %89
83: ; preds = %79
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
%85 = load i8*, i8** %4
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %85)
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.2, i64 0, i64 0))
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0))
br label %11
89: ; preds = %79
%90 = call i32 (...) @clrscr()
%91 = load i32, i32* %9
%92 = call i64 @islower(i32 %91)
%93 = icmp ne i64 %92, 0
br i1 %93, label %94, label %97
94: ; preds = %89
%95 = load i32, i32* %9
%96 = call i32 @toupper(i32 %95)
store i32 %96, i32* %9
br label %100
97: ; preds = %89
%98 = load i32, i32* %9
%99 = call i32 @tolower(i32 %98)
store i32 %99, i32* %9
br label %100
100: ; preds = %97, %94
%101 = load i32, i32* %9
ret i32 %101
102: ; preds = %62, %59
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
%104 = load i8*, i8** %4
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %104)
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.2, i64 0, i64 0))
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
br label %11
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@STDIN_FILENO = global i32 0
@ICANON = global i32 0
@ECHO = global i32 0
@TCSANOW = global i32 0
@.str = [9 x i8] c"\1B[%d;%dH\00"
@.str.1 = [13 x i8] c"\1B[0;97;40m%s\00"
@.str.2 = [80 x i8] c"\1B[40m \00"
@.str.3 = [36 x i8] c"\0D\1B[1;31;40mYou don't see such item.\00"
@.str.4 = [26 x i8] c"\0D\1B[1;31;40mWrong command.\00"
define i32 @getInputInv(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.termios
%5 = alloca %struct.termios
%6 = bitcast %struct.termios* %4 to i8*
%7 = bitcast %struct.termios* %5 to i8*
%8 = getelementptr inbounds %struct.termios, %struct.termios* %5, i64 0, i32 0
%9 = getelementptr inbounds %struct.termios, %struct.termios* %4, i64 0, i32 0
%10 = icmp eq i32 %2, 1
br label %11
11: ; preds = %73, %3
%12 = phi i32 [ %1, %3 ], [ %75, %73 ]
%13 = load i32, i32* @STDIN_FILENO
%14 = call i32 @tcgetattr(i32 %13, %struct.termios* %5)
%15 = load i32, i32* %8
%16 = load i32, i32* @ICANON
%17 = load i32, i32* @ECHO
%18 = or i32 %17, %16
%19 = xor i32 %18, -1
%20 = and i32 %15, %19
store i32 %20, i32* %9
%21 = load i32, i32* @STDIN_FILENO
%22 = load i32, i32* @TCSANOW
%23 = call i32 @tcsetattr(i32 %21, i32 %22, %struct.termios* %4)
%24 = call i32 (...) @getchar()
%25 = icmp eq i32 %24, 126
br i1 %25, label %26, label %28
26: ; preds = %11
%27 = call i32 (...) @getchar()
br label %28
28: ; preds = %26, %11
%29 = phi i32 [ %27, %26 ], [ %24, %11 ]
%30 = icmp eq i32 %29, 27
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 (...) @getchar()
br label %33
33: ; preds = %31, %28
%34 = phi i32 [ %32, %31 ], [ %29, %28 ]
%35 = icmp eq i32 %34, 91
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 (...) @getchar()
br label %38
38: ; preds = %36, %33
%39 = load i32, i32* @STDIN_FILENO
%40 = load i32, i32* @TCSANOW
%41 = call i32 @tcsetattr(i32 %39, i32 %40, %struct.termios* %5)
%42 = add i32 %34, -65
%43 = icmp ult i32 %42, 26
br i1 %43, label %52, label %44
44: ; preds = %38
%45 = add i32 %34, -97
%46 = icmp ult i32 %45, 26
%47 = icmp eq i32 %34, 48
%48 = or i1 %47, %46
%49 = icmp eq i32 %34, 45
%50 = and i1 %10, %49
%51 = or i1 %48, %50
br i1 %51, label %52, label %73
52: ; preds = %44, %38
%53 = call i64 @islower(i32 %34)
%54 = icmp eq i64 %53, 0
br i1 %54, label %58, label %55
55: ; preds = %52
%56 = call i32 @toupper(i32 %34)
%57 = call i32 @toupper(i32 %12)
br label %61
58: ; preds = %52
%59 = call i32 @tolower(i32 %34)
%60 = call i32 @tolower(i32 %12)
br label %61
61: ; preds = %58, %55
%62 = phi i32 [ %57, %55 ], [ %60, %58 ]
%63 = phi i32 [ %56, %55 ], [ %59, %58 ]
%64 = icmp sgt i32 %63, %62
br i1 %64, label %73, label %65
65: ; preds = %61
%66 = call i32 (...) @clrscr()
%67 = call i64 @islower(i32 %63)
%68 = icmp eq i64 %67, 0
br i1 %68, label %71, label %69
69: ; preds = %65
%70 = call i32 @toupper(i32 %63)
br label %80
71: ; preds = %65
%72 = call i32 @tolower(i32 %63)
br label %80
73: ; preds = %44, %61
%74 = phi i8* [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), %61 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), %44 ]
%75 = phi i32 [ %62, %61 ], [ %12, %44 ]
%76 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0, i32 0)
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @.str.2, i64 0, i64 0))
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %74)
br label %11
80: ; preds = %71, %69
%81 = phi i32 [ %72, %71 ], [ %70, %69 ]
ret i32 %81
}