#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_down();
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 view_mode() {
  console_title("View mode");
  console_status("Press ESC to exit.");
  console_update();
  while (1) {
    char c = getchar();
    switch (c) {
    case 0:
      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;
    }
  }
}


x86 assembly (clang, -O0):
<view_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1040 <console_title@plt>
lea    0xebf(%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     1255 <view_mode+0xb5>
mov    -0x10(%rbp),%rax
lea    0xe11(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    1255 <view_mode+0xb5>
jmp    1255 <view_mode+0xb5>
jmp    1255 <view_mode+0xb5>
mov    $0x0,%al
call   10b0 <console_pageup@plt>
jmp    1255 <view_mode+0xb5>
mov    $0x0,%al
call   1030 <console_pagedown@plt>
jmp    1255 <view_mode+0xb5>
mov    $0x0,%al
call   1050 <console_up@plt>
jmp    1255 <view_mode+0xb5>
mov    $0x0,%al
call   1070 <console_down@plt>
jmp    1255 <view_mode+0xb5>
mov    $0x0,%al
call   10c0 <console_right@plt>
jmp    1255 <view_mode+0xb5>
mov    $0x0,%al
call   10a0 <console_left@plt>
jmp    1255 <view_mode+0xb5>
add    $0x10,%rsp
pop    %rbp
ret
jmp    11c7 <view_mode+0x27>

x86 assembly (clang, -O2):
<view_mode>:
push   %rbx
lea    0xe78(%rip),%rdi
call   1040 <console_title@plt>
lea    0xe76(%rip),%rdi
call   1080 <console_status@plt>
xor    %eax,%eax
call   1060 <console_update@plt>
lea    0xe39(%rip),%rbx
jmp    11d0 <view_mode+0x30>
xor    %eax,%eax
call   1070 <console_down@plt>
xor    %eax,%eax
call   1090 <getchar@plt>
movsbl %al,%eax
add    $0xffffffec,%eax
cmp    $0x7,%eax
ja     11d0 <view_mode+0x30>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
xor    %eax,%eax
call   10b0 <console_pageup@plt>
jmp    11d0 <view_mode+0x30>
xor    %eax,%eax
call   1030 <console_pagedown@plt>
jmp    11d0 <view_mode+0x30>
xor    %eax,%eax
call   1050 <console_up@plt>
jmp    11d0 <view_mode+0x30>
xor    %eax,%eax
call   10c0 <console_right@plt>
jmp    11d0 <view_mode+0x30>
xor    %eax,%eax
call   10a0 <console_left@plt>
jmp    11d0 <view_mode+0x30>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"View mode\00"
@.str.1 = [19 x i8] c"Press ESC to exit.\00"
define void @view_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 ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 (...) @console_update()
br label %5
5: ; preds = %0, %25
%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 %25 [
i32 0, label %9
i32 18, label %10
i32 19, label %11
i32 20, label %12
i32 21, label %14
i32 23, label %16
i32 24, label %18
i32 25, label %20
i32 26, label %22
i32 27, label %24
]
9: ; preds = %5
br label %25
10: ; preds = %5
br label %25
11: ; preds = %5
br label %25
12: ; preds = %5
%13 = call i32 (...) @console_pageup()
br label %25
14: ; preds = %5
%15 = call i32 (...) @console_pagedown()
br label %25
16: ; preds = %5
%17 = call i32 (...) @console_up()
br label %25
18: ; preds = %5
%19 = call i32 (...) @console_down()
br label %25
20: ; preds = %5
%21 = call i32 (...) @console_right()
br label %25
22: ; preds = %5
%23 = call i32 (...) @console_left()
br label %25
24: ; preds = %5
ret void
25: ; preds = %5, %22, %20, %18, %16, %14, %12, %11, %10, %9
br label %5
}

LLVM IR (-O2):
@.str = [10 x i8] c"View mode\00"
@.str.1 = [19 x i8] c"Press ESC to exit.\00"
define void @view_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 ([19 x i8], [19 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 %9 [
i32 27, label %20
i32 26, label %18
i32 25, label %16
i32 20, label %7
i32 21, label %10
i32 23, label %12
i32 24, label %14
]
7: ; preds = %4
%8 = tail call i32 (...) @console_pageup()
br label %9
9: ; preds = %7, %10, %12, %14, %16, %18, %4
br label %4
10: ; preds = %4
%11 = tail call i32 (...) @console_pagedown()
br label %9
12: ; preds = %4
%13 = tail call i32 (...) @console_up()
br label %9
14: ; preds = %4
%15 = tail call i32 (...) @console_down()
br label %9
16: ; preds = %4
%17 = tail call i32 (...) @console_right()
br label %9
18: ; preds = %4
%19 = tail call i32 (...) @console_left()
br label %9
20: ; preds = %4
ret void
}