#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*/ cleanup_screen();
int /*<<< orphan*/ draw_char(int, int, char);
int /*<<< orphan*/ draw_string(int /*<<< orphan*/, int, char *);
int /*<<< orphan*/ erase_line();
int get_char();
int /*<<< orphan*/ save_screen();
int screen_height();
int screen_width();
int /*<<< orphan*/ setup_screen();
int /*<<< orphan*/ show_screen();
int /*<<< orphan*/ timer_pause(int);
int /*<<< orphan*/ wait_char();
int main(void) {
  setup_screen();
  int x = screen_width() / 2;
  int y = screen_height() / 2;
  draw_char(x, y, 'Z');
  draw_string(0, screen_height() - 1,
              "Menu: 2 = Down; 4 = Left; 6 = Right; 8 = Up; q = Quit.");
  int key = get_char();
  while (key != 'q') {
    if (key == '4') {
      x = x - 1;
    } else if (key == '6') {
      x = x + 1;
    } else if (key == '8') {
      y = y - 1;
    } else if (key == '2') {
      y = y + 1;
    }
    draw_char(x, y, 'Z');
    show_screen();
    timer_pause(20);
    key = get_char();
  }
  save_screen();
  draw_string(0, screen_height() - 1, "Press any key to exit...");
  erase_line();
  wait_char();
  cleanup_screen();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <setup_screen@plt>
mov    $0x0,%al
call   10d0 <screen_width@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1040 <screen_height@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x5a,%edx
call   1080 <draw_char@plt>
mov    $0x0,%al
call   1040 <screen_height@plt>
mov    %eax,%esi
sub    $0x1,%esi
xor    %edi,%edi
lea    0xde1(%rip),%rdx
call   1090 <draw_string@plt>
mov    $0x0,%al
call   10e0 <get_char@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x71,-0x10(%rbp)
je     12d2 <main+0x112>
cmpl   $0x34,-0x10(%rbp)
jne    1250 <main+0x90>
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12a2 <main+0xe2>
cmpl   $0x36,-0x10(%rbp)
jne    1268 <main+0xa8>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    129d <main+0xdd>
cmpl   $0x38,-0x10(%rbp)
jne    1280 <main+0xc0>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1298 <main+0xd8>
cmpl   $0x32,-0x10(%rbp)
jne    1293 <main+0xd3>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1298 <main+0xd8>
jmp    129d <main+0xdd>
jmp    12a2 <main+0xe2>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    $0x5a,%edx
call   1080 <draw_char@plt>
mov    $0x0,%al
call   1060 <show_screen@plt>
mov    $0x14,%edi
call   10a0 <timer_pause@plt>
mov    $0x0,%al
call   10e0 <get_char@plt>
mov    %eax,-0x10(%rbp)
jmp    122e <main+0x6e>
mov    $0x0,%al
call   10b0 <save_screen@plt>
mov    $0x0,%al
call   1040 <screen_height@plt>
mov    %eax,%esi
sub    $0x1,%esi
xor    %edi,%edi
lea    0xd49(%rip),%rdx
call   1090 <draw_string@plt>
mov    $0x0,%al
call   10c0 <erase_line@plt>
mov    $0x0,%al
call   1050 <wait_char@plt>
mov    $0x0,%al
call   1030 <cleanup_screen@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1070 <setup_screen@plt>
xor    %eax,%eax
call   10d0 <screen_width@plt>
mov    %eax,%ebx
shr    $0x1f,%ebx
add    %eax,%ebx
sar    %ebx
xor    %eax,%eax
call   1040 <screen_height@plt>
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x5a,%edx
call   1080 <draw_char@plt>
xor    %eax,%eax
call   1040 <screen_height@plt>
lea    -0x1(%rax),%esi
lea    0xe12(%rip),%rdx
xor    %edi,%edi
call   1090 <draw_string@plt>
lea    0xde8(%rip),%r14
jmp    123f <main+0x7f>
add    $0x1,%ebp
nopl   (%rax)
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x5a,%edx
call   1080 <draw_char@plt>
xor    %eax,%eax
call   1060 <show_screen@plt>
mov    $0x14,%edi
call   10a0 <timer_pause@plt>
xor    %eax,%eax
call   10e0 <get_char@plt>
lea    -0x32(%rax),%ecx
cmp    $0x6,%ecx
ja     1266 <main+0xa6>
movslq (%r14,%rcx,4),%rax
add    %r14,%rax
jmp    *%rax
add    $0xffffffff,%ebx
jmp    1220 <main+0x60>
add    $0x1,%ebx
jmp    1220 <main+0x60>
add    $0xffffffff,%ebp
jmp    1220 <main+0x60>
cmp    $0x71,%eax
jne    1220 <main+0x60>
xor    %eax,%eax
call   10b0 <save_screen@plt>
xor    %eax,%eax
call   1040 <screen_height@plt>
lea    -0x1(%rax),%esi
lea    0xdd0(%rip),%rdx
xor    %edi,%edi
call   1090 <draw_string@plt>
xor    %eax,%eax
call   10c0 <erase_line@plt>
xor    %eax,%eax
call   1050 <wait_char@plt>
xor    %eax,%eax
call   1030 <cleanup_screen@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [55 x i8] c"Menu: 2 = Down; 4 = Left; 6 = Right; 8 = Up; q = Quit.\00"
@.str.1 = [25 x i8] c"Press any key to exit...\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @setup_screen()
%6 = call i32 (...) @screen_width()
%7 = sdiv i32 %6, 2
store i32 %7, i32* %2
%8 = call i32 (...) @screen_height()
%9 = sdiv i32 %8, 2
store i32 %9, i32* %3
%10 = load i32, i32* %2
%11 = load i32, i32* %3
%12 = call i32 @draw_char(i32 %10, i32 %11, i8 signext 90)
%13 = call i32 (...) @screen_height()
%14 = sub nsw i32 %13, 1
%15 = call i32 @draw_string(i32 0, i32 %14, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (...) @get_char()
store i32 %16, i32* %4
br label %17
17: ; preds = %47, %0
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 113
br i1 %19, label %20, label %54
20: ; preds = %17
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 52
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %2
%25 = sub nsw i32 %24, 1
store i32 %25, i32* %2
br label %47
26: ; preds = %20
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 54
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* %2
%31 = add nsw i32 %30, 1
store i32 %31, i32* %2
br label %46
32: ; preds = %26
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 56
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i32, i32* %3
%37 = sub nsw i32 %36, 1
store i32 %37, i32* %3
br label %45
38: ; preds = %32
%39 = load i32, i32* %4
%40 = icmp eq i32 %39, 50
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
store i32 %43, i32* %3
br label %44
44: ; preds = %41, %38
br label %45
45: ; preds = %44, %35
br label %46
46: ; preds = %45, %29
br label %47
47: ; preds = %46, %23
%48 = load i32, i32* %2
%49 = load i32, i32* %3
%50 = call i32 @draw_char(i32 %48, i32 %49, i8 signext 90)
%51 = call i32 (...) @show_screen()
%52 = call i32 @timer_pause(i32 20)
%53 = call i32 (...) @get_char()
store i32 %53, i32* %4
br label %17
54: ; preds = %17
%55 = call i32 (...) @save_screen()
%56 = call i32 (...) @screen_height()
%57 = sub nsw i32 %56, 1
%58 = call i32 @draw_string(i32 0, i32 %57, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%59 = call i32 (...) @erase_line()
%60 = call i32 (...) @wait_char()
%61 = call i32 (...) @cleanup_screen()
ret i32 0
}

LLVM IR (-O2):
@.str = [55 x i8] c"Menu: 2 = Down; 4 = Left; 6 = Right; 8 = Up; q = Quit.\00"
@.str.1 = [25 x i8] c"Press any key to exit...\00"
define i32 @main() {
%1 = tail call i32 (...) @setup_screen()
%2 = tail call i32 (...) @screen_width()
%3 = sdiv i32 %2, 2
%4 = tail call i32 (...) @screen_height()
%5 = sdiv i32 %4, 2
%6 = tail call i32 @draw_char(i32 %3, i32 %5, i8 signext 90)
%7 = tail call i32 (...) @screen_height()
%8 = add nsw i32 %7, -1
%9 = tail call i32 @draw_string(i32 0, i32 %8, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %22, %0
%11 = phi i32 [ %3, %0 ], [ %23, %22 ]
%12 = phi i32 [ %5, %0 ], [ %24, %22 ]
%13 = tail call i32 (...) @get_char()
switch i32 %13, label %22 [
i32 113, label %28
i32 52, label %14
i32 54, label %16
i32 56, label %18
i32 50, label %20
]
14: ; preds = %10
%15 = add nsw i32 %11, -1
br label %22
16: ; preds = %10
%17 = add nsw i32 %11, 1
br label %22
18: ; preds = %10
%19 = add nsw i32 %12, -1
br label %22
20: ; preds = %10
%21 = add nsw i32 %12, 1
br label %22
22: ; preds = %10, %16, %20, %18, %14
%23 = phi i32 [ %15, %14 ], [ %17, %16 ], [ %11, %18 ], [ %11, %20 ], [ %11, %10 ]
%24 = phi i32 [ %12, %14 ], [ %12, %16 ], [ %19, %18 ], [ %21, %20 ], [ %12, %10 ]
%25 = tail call i32 @draw_char(i32 %23, i32 %24, i8 signext 90)
%26 = tail call i32 (...) @show_screen()
%27 = tail call i32 @timer_pause(i32 20)
br label %10
28: ; preds = %10
%29 = tail call i32 (...) @save_screen()
%30 = tail call i32 (...) @screen_height()
%31 = add nsw i32 %30, -1
%32 = tail call i32 @draw_string(i32 0, i32 %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%33 = tail call i32 (...) @erase_line()
%34 = tail call i32 (...) @wait_char()
%35 = tail call i32 (...) @cleanup_screen()
ret i32 0
}