#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*/ console_backspace();
int /*<<< orphan*/ console_down();
int /*<<< orphan*/ console_insert(char);
int /*<<< orphan*/ console_left();
int /*<<< orphan*/ console_pagedown();
int /*<<< orphan*/ console_pageup();
int /*<<< orphan*/ console_right();
int /*<<< orphan*/ console_status(char *);
int /*<<< orphan*/ console_title(char *);
int /*<<< orphan*/ console_up();
int /*<<< orphan*/ console_update();
char getchar();
void edit_mode() {
  console_title("Edit mode");
  console_status("Press ESC to return back to command mode.");
  console_update();
  while (1) {
    char c = getchar();
    switch (c) {
    case 0:
      break;
    case 8:
      console_backspace();
      break;
    case 18:
      break;
    case 19:
      break;
    case 20:
      console_pageup();
      break;
    case 21:
      console_pagedown();
      break;
    case 23:
      console_up();
      break;
    case 24:
      console_down();
      break;
    case 25:
      console_right();
      break;
    case 26:
      console_left();
      break;
    case 27:
      return;
    default:
      console_insert(c);
    }
  }
}


x86 assembly (clang, -O0):
<edit_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1040 <console_title@plt>
lea    0xe9f(%rip),%rdi
call   1080 <console_status@plt>
mov    $0x0,%al
call   1060 <console_update@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x1b,%eax
ja     1281 <edit_mode+0xc1>
mov    -0x10(%rbp),%rax
lea    0xdf1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    128a <edit_mode+0xca>
mov    $0x0,%al
call   10c0 <console_backspace@plt>
jmp    128a <edit_mode+0xca>
jmp    128a <edit_mode+0xca>
jmp    128a <edit_mode+0xca>
mov    $0x0,%al
call   10d0 <console_pageup@plt>
jmp    128a <edit_mode+0xca>
mov    $0x0,%al
call   1030 <console_pagedown@plt>
jmp    128a <edit_mode+0xca>
mov    $0x0,%al
call   1050 <console_up@plt>
jmp    128a <edit_mode+0xca>
mov    $0x0,%al
call   1070 <console_down@plt>
jmp    128a <edit_mode+0xca>
mov    $0x0,%al
call   10e0 <console_right@plt>
jmp    128a <edit_mode+0xca>
mov    $0x0,%al
call   10b0 <console_left@plt>
jmp    128a <edit_mode+0xca>
add    $0x10,%rsp
pop    %rbp
ret
movsbl -0x1(%rbp),%edi
call   10a0 <console_insert@plt>
jmp    11e7 <edit_mode+0x27>

x86 assembly (clang, -O2):
<edit_mode>:
push   %rbx
lea    0xea8(%rip),%rdi
call   1040 <console_title@plt>
lea    0xea6(%rip),%rdi
call   1080 <console_status@plt>
xor    %eax,%eax
call   1060 <console_update@plt>
lea    0xe19(%rip),%rbx
jmp    11f0 <edit_mode+0x30>
xor    %eax,%eax
call   10b0 <console_left@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
movsbl %al,%edi
cmp    $0x1b,%edi
ja     123e <edit_mode+0x7e>
movslq (%rbx,%rdi,4),%rax
add    %rbx,%rax
jmp    *%rax
xor    %eax,%eax
call   10c0 <console_backspace@plt>
jmp    11f0 <edit_mode+0x30>
xor    %eax,%eax
call   10d0 <console_pageup@plt>
jmp    11f0 <edit_mode+0x30>
xor    %eax,%eax
call   1030 <console_pagedown@plt>
jmp    11f0 <edit_mode+0x30>
xor    %eax,%eax
call   1050 <console_up@plt>
jmp    11f0 <edit_mode+0x30>
xor    %eax,%eax
call   1070 <console_down@plt>
jmp    11f0 <edit_mode+0x30>
xor    %eax,%eax
call   10e0 <console_right@plt>
jmp    11f0 <edit_mode+0x30>
call   10a0 <console_insert@plt>
jmp    11f0 <edit_mode+0x30>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"Edit mode\00"
@.str.1 = [42 x i8] c"Press ESC to return back to command mode.\00"
define void @edit_mode() {
%1 = alloca i8
%2 = call i32 @console_title(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%3 = call i32 @console_status(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 (...) @console_update()
br label %5
5: ; preds = %0, %30
%6 = call signext i8 (...) @getchar()
store i8 %6, i8* %1
%7 = load i8, i8* %1
%8 = sext i8 %7 to i32
switch i32 %8, label %27 [
i32 0, label %9
i32 8, label %10
i32 18, label %12
i32 19, label %13
i32 20, label %14
i32 21, label %16
i32 23, label %18
i32 24, label %20
i32 25, label %22
i32 26, label %24
i32 27, label %26
]
9: ; preds = %5
br label %30
10: ; preds = %5
%11 = call i32 (...) @console_backspace()
br label %30
12: ; preds = %5
br label %30
13: ; preds = %5
br label %30
14: ; preds = %5
%15 = call i32 (...) @console_pageup()
br label %30
16: ; preds = %5
%17 = call i32 (...) @console_pagedown()
br label %30
18: ; preds = %5
%19 = call i32 (...) @console_up()
br label %30
20: ; preds = %5
%21 = call i32 (...) @console_down()
br label %30
22: ; preds = %5
%23 = call i32 (...) @console_right()
br label %30
24: ; preds = %5
%25 = call i32 (...) @console_left()
br label %30
26: ; preds = %5
ret void
27: ; preds = %5
%28 = load i8, i8* %1
%29 = call i32 @console_insert(i8 signext %28)
br label %30
30: ; preds = %27, %24, %22, %20, %18, %16, %14, %13, %12, %10, %9
br label %5
}

LLVM IR (-O2):
@.str = [10 x i8] c"Edit mode\00"
@.str.1 = [42 x i8] c"Press ESC to return back to command mode.\00"
define void @edit_mode() {
%1 = tail call i32 @console_title(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @console_status(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i32 (...) @console_update()
br label %4
4: ; preds = %9, %0
%5 = tail call signext i8 (...) @getchar()
%6 = sext i8 %5 to i32
switch i32 %6, label %22 [
i32 0, label %9
i32 8, label %7
i32 18, label %9
i32 19, label %9
i32 20, label %10
i32 21, label %12
i32 23, label %14
i32 24, label %16
i32 25, label %18
i32 26, label %20
i32 27, label %24
]
7: ; preds = %4
%8 = tail call i32 (...) @console_backspace()
br label %9
9: ; preds = %7, %10, %12, %14, %16, %18, %20, %4, %4, %4, %22
br label %4
10: ; preds = %4
%11 = tail call i32 (...) @console_pageup()
br label %9
12: ; preds = %4
%13 = tail call i32 (...) @console_pagedown()
br label %9
14: ; preds = %4
%15 = tail call i32 (...) @console_up()
br label %9
16: ; preds = %4
%17 = tail call i32 (...) @console_down()
br label %9
18: ; preds = %4
%19 = tail call i32 (...) @console_right()
br label %9
20: ; preds = %4
%21 = tail call i32 (...) @console_left()
br label %9
22: ; preds = %4
%23 = tail call i32 @console_insert(i8 signext %5)
br label %9
24: ; preds = %4
ret void
}