#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*/ A_REVERSE;
#define KEY_BACKSPACE 132
#define KEY_DOWN 131
#define KEY_LEFT 130
#define KEY_RIGHT 129
#define KEY_UP 128
int /*<<< orphan*/ addch(int);
int /*<<< orphan*/ attroff(int /*<<< orphan*/);
int /*<<< orphan*/ attron(int /*<<< orphan*/);
int /*<<< orphan*/ box(int /*<<< orphan*/, char, char);
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ exit(int);
int getch();
int /*<<< orphan*/ initial();
int /*<<< orphan*/ move(int, int);
int /*<<< orphan*/ mvaddch(int, int, char);
int /*<<< orphan*/ mvaddstr(int /*<<< orphan*/, int, char *);
int /*<<< orphan*/ stdscr;
main() {
  int x = 1;
  int y = 1;
  int ch;
  initial();
  box(stdscr, '|', '-');
  attron(A_REVERSE);
  mvaddstr(0, 20, "jiwenibao curses program");
  attroff(A_REVERSE);
  move(x, y);
  do {
    ch = getch();
    switch (ch) {
    case KEY_UP:
      --y;
      break;
    case KEY_DOWN:
      ++y;
      break;
    case KEY_RIGHT:
      ++x;
      break;
    case KEY_LEFT:
      --x;
      break;
    case ' ':
      ++y;
      x = 0;
      break;
    case '\t':
      x += 7;
      break;
    case KEY_BACKSPACE:
      mvaddch(y, --x, ' ');
      break;
    case 27:
      endwin();
      exit(1);
    default:
      addch(ch);
      x++;
      break;
    }
    move(y, x);
  } while (1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    $0x0,%al
call   1040 <initial@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    $0x7c,%esi
mov    $0x2d,%edx
call   1060 <box@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1050 <attron@plt>
xor    %edi,%edi
mov    $0x14,%esi
lea    0xdf8(%rip),%rdx
call   10b0 <mvaddstr@plt>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1030 <attroff@plt>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
call   10d0 <move@plt>
xor    %eax,%eax
call   1080 <getch@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x9,%eax
je     1312 <main+0x162>
jmp    1244 <main+0x94>
mov    -0x14(%rbp),%eax
sub    $0x1b,%eax
je     133b <main+0x18b>
jmp    1255 <main+0xa5>
mov    -0x14(%rbp),%eax
sub    $0x20,%eax
je     12fd <main+0x14d>
jmp    1266 <main+0xb6>
mov    -0x14(%rbp),%eax
sub    $0x80,%eax
je     12c5 <main+0x115>
jmp    1279 <main+0xc9>
mov    -0x14(%rbp),%eax
sub    $0x81,%eax
je     12e1 <main+0x131>
jmp    128c <main+0xdc>
mov    -0x14(%rbp),%eax
sub    $0x82,%eax
je     12ef <main+0x13f>
jmp    129f <main+0xef>
mov    -0x14(%rbp),%eax
sub    $0x83,%eax
je     12d3 <main+0x123>
jmp    12b2 <main+0x102>
mov    -0x14(%rbp),%eax
sub    $0x84,%eax
je     1320 <main+0x170>
jmp    134c <main+0x19c>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    135d <main+0x1ad>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    135d <main+0x1ad>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    135d <main+0x1ad>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    135d <main+0x1ad>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
jmp    135d <main+0x1ad>
mov    -0x8(%rbp),%eax
add    $0x7,%eax
mov    %eax,-0x8(%rbp)
jmp    135d <main+0x1ad>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
add    $0xffffffff,%esi
mov    %esi,-0x8(%rbp)
mov    $0x20,%edx
call   10a0 <mvaddch@plt>
jmp    135d <main+0x1ad>
mov    $0x0,%al
call   1090 <endwin@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%edi
call   1070 <addch@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10d0 <move@plt>
mov    $0x1,%al
test   $0x1,%al
jne    1226 <main+0x76>
jmp    1377 <main+0x1c7>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1040 <initial@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    $0x7c,%esi
mov    $0x2d,%edx
call   1060 <box@plt>
mov    0x2dfe(%rip),%rbx
mov    (%rbx),%edi
call   1050 <attron@plt>
lea    0xe2c(%rip),%rdx
xor    %edi,%edi
mov    $0x14,%esi
call   10b0 <mvaddstr@plt>
mov    (%rbx),%edi
call   1030 <attroff@plt>
mov    $0x1,%ebx
mov    $0x1,%edi
mov    $0x1,%esi
call   10d0 <move@plt>
lea    0xdea(%rip),%r14
mov    $0x1,%ebp
jmp    1235 <main+0x85>
cmp    $0x1b,%eax
je     1293 <main+0xe3>
mov    %eax,%edi
call   1070 <addch@plt>
add    $0x1,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   10d0 <move@plt>
xor    %eax,%eax
call   1080 <getch@plt>
cmp    $0x7f,%eax
jle    1260 <main+0xb0>
lea    -0x80(%rax),%ecx
cmp    $0x4,%ecx
ja     1222 <main+0x72>
movslq (%r14,%rcx,4),%rax
add    %r14,%rax
jmp    *%rax
add    $0xffffffff,%ebx
jmp    122c <main+0x7c>
nopw   0x0(%rax,%rax,1)
cmp    $0x9,%eax
je     128e <main+0xde>
cmp    $0x20,%eax
jne    121d <main+0x6d>
add    $0x1,%ebx
xor    %ebp,%ebp
jmp    122c <main+0x7c>
add    $0xffffffff,%ebp
jmp    122c <main+0x7c>
add    $0x1,%ebx
jmp    122c <main+0x7c>
add    $0xffffffff,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
mov    $0x20,%edx
call   10a0 <mvaddch@plt>
jmp    122c <main+0x7c>
add    $0x7,%ebp
jmp    122c <main+0x7c>
xor    %eax,%eax
call   1090 <endwin@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stdscr = global i32 0
@A_REVERSE = global i32 0
@.str = [25 x i8] c"jiwenibao curses program\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %2
store i32 1, i32* %3
%5 = call i32 (...) @initial()
%6 = load i32, i32* @stdscr
%7 = call i32 @box(i32 %6, i8 signext 124, i8 signext 45)
%8 = load i32, i32* @A_REVERSE
%9 = call i32 @attron(i32 %8)
%10 = call i32 @mvaddstr(i32 0, i32 20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @A_REVERSE
%12 = call i32 @attroff(i32 %11)
%13 = load i32, i32* %2
%14 = load i32, i32* %3
%15 = call i32 @move(i32 %13, i32 %14)
br label %16
16: ; preds = %54, %0
%17 = call i32 (...) @getch()
store i32 %17, i32* %4
%18 = load i32, i32* %4
switch i32 %18, label %45 [
i32 128, label %19
i32 131, label %22
i32 129, label %25
i32 130, label %28
i32 32, label %31
i32 9, label %34
i32 132, label %37
i32 27, label %42
]
19: ; preds = %16
%20 = load i32, i32* %3
%21 = add nsw i32 %20, -1
store i32 %21, i32* %3
br label %50
22: ; preds = %16
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %50
25: ; preds = %16
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %50
28: ; preds = %16
%29 = load i32, i32* %2
%30 = add nsw i32 %29, -1
store i32 %30, i32* %2
br label %50
31: ; preds = %16
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
store i32 0, i32* %2
br label %50
34: ; preds = %16
%35 = load i32, i32* %2
%36 = add nsw i32 %35, 7
store i32 %36, i32* %2
br label %50
37: ; preds = %16
%38 = load i32, i32* %3
%39 = load i32, i32* %2
%40 = add nsw i32 %39, -1
store i32 %40, i32* %2
%41 = call i32 @mvaddch(i32 %38, i32 %40, i8 signext 32)
br label %50
42: ; preds = %16
%43 = call i32 (...) @endwin()
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %16
%46 = load i32, i32* %4
%47 = call i32 @addch(i32 %46)
%48 = load i32, i32* %2
%49 = add nsw i32 %48, 1
store i32 %49, i32* %2
br label %50
50: ; preds = %45, %37, %34, %31, %28, %25, %22, %19
%51 = load i32, i32* %3
%52 = load i32, i32* %2
%53 = call i32 @move(i32 %51, i32 %52)
br label %54
54: ; preds = %50
br i1 true, label %16, label %55
55: ; preds = %54
%56 = load i32, i32* %1
ret i32 %56
}

LLVM IR (-O2):
@stdscr = global i32 0
@A_REVERSE = global i32 0
@.str = [25 x i8] c"jiwenibao curses program\00"
define i32 @main() {
%1 = tail call i32 (...) @initial()
%2 = load i32, i32* @stdscr
%3 = tail call i32 @box(i32 %2, i8 signext 124, i8 signext 45)
%4 = load i32, i32* @A_REVERSE
%5 = tail call i32 @attron(i32 %4)
%6 = tail call i32 @mvaddstr(i32 0, i32 20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @A_REVERSE
%8 = tail call i32 @attroff(i32 %7)
%9 = tail call i32 @move(i32 1, i32 1)
br label %10
10: ; preds = %35, %0
%11 = phi i32 [ 1, %0 ], [ %36, %35 ]
%12 = phi i32 [ 1, %0 ], [ %37, %35 ]
%13 = tail call i32 (...) @getch()
switch i32 %13, label %32 [
i32 128, label %14
i32 131, label %16
i32 129, label %18
i32 130, label %20
i32 32, label %22
i32 9, label %24
i32 132, label %26
i32 27, label %29
]
14: ; preds = %10
%15 = add nsw i32 %11, -1
br label %35
16: ; preds = %10
%17 = add nsw i32 %11, 1
br label %35
18: ; preds = %10
%19 = add nsw i32 %12, 1
br label %35
20: ; preds = %10
%21 = add nsw i32 %12, -1
br label %35
22: ; preds = %10
%23 = add nsw i32 %11, 1
br label %35
24: ; preds = %10
%25 = add nsw i32 %12, 7
br label %35
26: ; preds = %10
%27 = add nsw i32 %12, -1
%28 = tail call i32 @mvaddch(i32 %11, i32 %27, i8 signext 32)
br label %35
29: ; preds = %10
%30 = tail call i32 (...) @endwin()
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %10
%33 = tail call i32 @addch(i32 %13)
%34 = add nsw i32 %12, 1
br label %35
35: ; preds = %32, %26, %24, %22, %20, %18, %16, %14
%36 = phi i32 [ %11, %32 ], [ %11, %26 ], [ %11, %24 ], [ %23, %22 ], [ %11, %20 ], [ %11, %18 ], [ %17, %16 ], [ %15, %14 ]
%37 = phi i32 [ %34, %32 ], [ %27, %26 ], [ %25, %24 ], [ 0, %22 ], [ %21, %20 ], [ %19, %18 ], [ %12, %16 ], [ %12, %14 ]
%38 = tail call i32 @move(i32 %36, i32 %37)
br label %10
}