#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 */
typedef int /*<<< orphan*/ WINDOW;

/* Variables and functions */
#define KEY_BACKSPACE 129
#define KEY_ENTER 128
int /*<<< orphan*/ TRUE;
int /*<<< orphan*/ cbreak();
int endwin();
int /*<<< orphan*/ getmaxyx(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ *initscr();
int /*<<< orphan*/ isascii(int);
int /*<<< orphan*/ keypad(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ stdscr;
int /*<<< orphan*/ waddch(int /*<<< orphan*/ *, int);
int wgetch(int /*<<< orphan*/ *);
int /*<<< orphan*/ wmove(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ wrefresh(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  WINDOW *w = initscr();
  cbreak();
  noecho();
  keypad(stdscr, TRUE);
  int ct;
  int mx, my;
  getmaxyx(w, my, mx);
  for (ct = 0;;) {
    wmove(w, my - 1, ct);
    wrefresh(w);
    int c = wgetch(w);
    switch (c) {
    case KEY_BACKSPACE:
      if (ct > 0) {
        ct--;
        wmove(w, my - 1, ct);
        waddch(w, ' ');
      }
      break;
    case KEY_ENTER:
    case '\n':
      ct = 0;
      break;
    default:
      if (isascii(c)) {
        waddch(w, c);
        ct++;
      }
    }
  }
  int ret = endwin();
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <initscr@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <cbreak@plt>
mov    $0x0,%al
call   10a0 <noecho@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
call   1060 <keypad@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
call   1080 <getmaxyx@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
add    $0xffffffff,%esi
mov    -0x1c(%rbp),%edx
call   10c0 <wmove@plt>
mov    -0x18(%rbp),%rdi
call   1050 <wrefresh@plt>
mov    -0x18(%rbp),%rdi
call   1090 <wgetch@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0xa,%eax
je     1295 <main+0xf5>
jmp    1237 <main+0x97>
mov    -0x30(%rbp),%eax
sub    $0x80,%eax
je     1295 <main+0xf5>
jmp    124a <main+0xaa>
mov    -0x30(%rbp),%eax
sub    $0x81,%eax
jne    12a1 <main+0x101>
jmp    125d <main+0xbd>
cmpl   $0x0,-0x1c(%rbp)
jle    1290 <main+0xf0>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
sub    $0x1,%esi
mov    -0x1c(%rbp),%edx
call   10c0 <wmove@plt>
mov    -0x18(%rbp),%rdi
mov    $0x20,%esi
call   1030 <waddch@plt>
jmp    12cc <main+0x12c>
movl   $0x0,-0x1c(%rbp)
jmp    12cc <main+0x12c>
mov    -0x28(%rbp),%edi
call   10b0 <isascii@plt>
cmp    $0x0,%eax
je     12c7 <main+0x127>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   1030 <waddch@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12cc <main+0x12c>
jmp    11fc <main+0x5c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1070 <initscr@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <cbreak@plt>
xor    %eax,%eax
call   10a0 <noecho@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
call   1060 <keypad@plt>
mov    %rbx,%rdi
call   1080 <getmaxyx@plt>
jmp    11d0 <main+0x40>
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %ebp,%edx
call   10b0 <wmove@plt>
mov    %rbx,%rdi
call   1050 <wrefresh@plt>
mov    %rbx,%rdi
call   1090 <wgetch@plt>
cmp    $0x81,%eax
je     1210 <main+0x80>
cmp    $0xa,%eax
je     11ce <main+0x3e>
cmp    $0x80,%eax
je     11ce <main+0x3e>
jae    11d0 <main+0x40>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <waddch@plt>
add    $0x1,%ebp
jmp    11d0 <main+0x40>
xchg   %ax,%ax
test   %ebp,%ebp
jle    11d0 <main+0x40>
add    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    %ebp,%edx
call   10b0 <wmove@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
call   1030 <waddch@plt>
jmp    11d0 <main+0x40>

LLVM IR (-O0):
@stdscr = global i32 0
@TRUE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32* (...) @initscr()
store i32* %12, i32** %6
%13 = call i32 (...) @cbreak()
%14 = call i32 (...) @noecho()
%15 = load i32, i32* @stdscr
%16 = load i32, i32* @TRUE
%17 = call i32 @keypad(i32 %15, i32 %16)
%18 = load i32*, i32** %6
%19 = load i32, i32* %9
%20 = load i32, i32* %8
%21 = call i32 @getmaxyx(i32* %18, i32 %19, i32 %20)
store i32 0, i32* %7
br label %22
22: ; preds = %59, %2
%23 = load i32*, i32** %6
%24 = load i32, i32* %9
%25 = sub nsw i32 %24, 1
%26 = load i32, i32* %7
%27 = call i32 @wmove(i32* %23, i32 %25, i32 %26)
%28 = load i32*, i32** %6
%29 = call i32 @wrefresh(i32* %28)
%30 = load i32*, i32** %6
%31 = call i32 @wgetch(i32* %30)
store i32 %31, i32* %10
%32 = load i32, i32* %10
switch i32 %32, label %48 [
i32 129, label %33
i32 128, label %47
i32 10, label %47
]
33: ; preds = %22
%34 = load i32, i32* %7
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %46
36: ; preds = %33
%37 = load i32, i32* %7
%38 = add nsw i32 %37, -1
store i32 %38, i32* %7
%39 = load i32*, i32** %6
%40 = load i32, i32* %9
%41 = sub nsw i32 %40, 1
%42 = load i32, i32* %7
%43 = call i32 @wmove(i32* %39, i32 %41, i32 %42)
%44 = load i32*, i32** %6
%45 = call i32 @waddch(i32* %44, i32 32)
br label %46
46: ; preds = %36, %33
br label %59
47: ; preds = %22, %22
store i32 0, i32* %7
br label %59
48: ; preds = %22
%49 = load i32, i32* %10
%50 = call i32 @isascii(i32 %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %48
%53 = load i32*, i32** %6
%54 = load i32, i32* %10
%55 = call i32 @waddch(i32* %53, i32 %54)
%56 = load i32, i32* %7
%57 = add nsw i32 %56, 1
store i32 %57, i32* %7
br label %58
58: ; preds = %52, %48
br label %59
59: ; preds = %58, %47, %46
br label %22
}

LLVM IR (-O2):
@stdscr = global i32 0
@TRUE = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* (...) @initscr()
%4 = tail call i32 (...) @cbreak()
%5 = tail call i32 (...) @noecho()
%6 = load i32, i32* @stdscr
%7 = load i32, i32* @TRUE
%8 = tail call i32 @keypad(i32 %6, i32 %7)
%9 = tail call i32 @getmaxyx(i32* %3, i32 undef, i32 undef)
br label %10
10: ; preds = %28, %2
%11 = phi i32 [ 0, %2 ], [ %29, %28 ]
%12 = icmp sgt i32 %11, 0
br label %13
13: ; preds = %24, %10
%14 = tail call i32 @wmove(i32* %3, i32 undef, i32 %11)
%15 = tail call i32 @wrefresh(i32* %3)
%16 = tail call i32 @wgetch(i32* %3)
switch i32 %16, label %22 [
i32 129, label %17
i32 128, label %28
i32 10, label %28
]
17: ; preds = %13
br i1 %12, label %18, label %24
18: ; preds = %17
%19 = add nsw i32 %11, -1
%20 = tail call i32 @wmove(i32* %3, i32 undef, i32 %19)
%21 = tail call i32 @waddch(i32* %3, i32 32)
br label %28
22: ; preds = %13
%23 = icmp ult i32 %16, 128
br i1 %23, label %25, label %24
24: ; preds = %22, %17
br label %13
25: ; preds = %22
%26 = tail call i32 @waddch(i32* %3, i32 %16)
%27 = add nsw i32 %11, 1
br label %28
28: ; preds = %13, %13, %25, %18
%29 = phi i32 [ %19, %18 ], [ %27, %25 ], [ 0, %13 ], [ 0, %13 ]
br label %10
}