#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ check_ch(int);
int /*<<< orphan*/ get_way();
scalar_t__ kbhit(struct termios *);
int /*<<< orphan*/ printf(char *);
int readch();
void switch_key(struct termios *new_term) {
  int ch = 0;
  struct termios *nterm = new_term;
  while (1) {
    if (kbhit(nterm)) {
      ch = readch();
      switch (ch) {
      case 27:
        get_way();
        break;
      case 10:
        printf("enter the menu\n");
        break;
      default:
        check_ch(ch);
        break;
      }
    }
  }
}


x86 assembly (clang, -O0):
<switch_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <kbhit@plt>
cmp    $0x0,%rax
je     11d7 <switch_key+0x87>
xor    %eax,%eax
call   1070 <readch@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0xa,%eax
je     11b9 <switch_key+0x69>
jmp    119c <switch_key+0x4c>
mov    -0x1c(%rbp),%eax
sub    $0x1b,%eax
jne    11ca <switch_key+0x7a>
jmp    11ad <switch_key+0x5d>
mov    $0x0,%al
call   1050 <get_way@plt>
jmp    11d2 <switch_key+0x82>
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
jmp    11d2 <switch_key+0x82>
mov    -0xc(%rbp),%edi
call   1060 <check_ch@plt>
jmp    11d7 <switch_key+0x87>
jmp    116b <switch_key+0x1b>

x86 assembly (clang, -O2):
<switch_key>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xea2(%rip),%r14
jmp    1168 <switch_key+0x18>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1040 <kbhit@plt>
test   %rax,%rax
je     1168 <switch_key+0x18>
xor    %eax,%eax
call   1070 <readch@plt>
cmp    $0xa,%eax
je     1160 <switch_key+0x10>
cmp    $0x1b,%eax
jne    1190 <switch_key+0x40>
xor    %eax,%eax
call   1050 <get_way@plt>
jmp    1168 <switch_key+0x18>
nop
mov    %eax,%edi
call   1060 <check_ch@plt>
jmp    1168 <switch_key+0x18>

LLVM IR (-O0):
%struct.termios = type { i32 }
@.str = [16 x i8] c"enter the menu\0A\00"
define void @switch_key(%struct.termios* %0) {
%2 = alloca %struct.termios*
%3 = alloca i32
%4 = alloca %struct.termios*
store %struct.termios* %0, %struct.termios** %2
store i32 0, i32* %3
%5 = load %struct.termios*, %struct.termios** %2
store %struct.termios* %5, %struct.termios** %4
br label %6
6: ; preds = %1, %21
%7 = load %struct.termios*, %struct.termios** %4
%8 = call i64 @kbhit(%struct.termios* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %21
10: ; preds = %6
%11 = call i32 (...) @readch()
store i32 %11, i32* %3
%12 = load i32, i32* %3
switch i32 %12, label %17 [
i32 27, label %13
i32 10, label %15
]
13: ; preds = %10
%14 = call i32 (...) @get_way()
br label %20
15: ; preds = %10
%16 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %20
17: ; preds = %10
%18 = load i32, i32* %3
%19 = call i32 @check_ch(i32 %18)
br label %20
20: ; preds = %17, %15, %13
br label %21
21: ; preds = %20, %6
br label %6
}

LLVM IR (-O2):
%struct.termios = type { i32 }
@str = [15 x i8] c"enter the menu\00"
define void @switch_key(%struct.termios* %0) {
br label %2
2: ; preds = %9, %1
%3 = tail call i64 @kbhit(%struct.termios* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = tail call i32 (...) @readch()
switch i32 %6, label %12 [
i32 27, label %7
i32 10, label %10
]
7: ; preds = %5
%8 = tail call i32 (...) @get_way()
br label %9
9: ; preds = %7, %10, %12, %2
br label %2
10: ; preds = %5
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %9
12: ; preds = %5
%13 = tail call i32 @check_ch(i32 %6)
br label %9
}