#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_BLINK;
int /*<<< orphan*/ attroff(int /*<<< orphan*/);
int /*<<< orphan*/ attron(int /*<<< orphan*/);
int endwin();
int /*<<< orphan*/ erase();
int getchar();
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ printw(char *, ...);
int /*<<< orphan*/ refresh();
int main(int argc, char *argv[]) {
  int ch;
  int keep_running = 1;
  unsigned int ch_cnt = 0;
  initscr();
  noecho();
  attron(A_BLINK);
  printw("hello world!\n");
  attroff(A_BLINK);
  while (keep_running) {
    refresh();
    ch = getchar();
    if (ch == 'q' || ch == 'Q')
      keep_running = 0;
    if (ch == '\r')
      printw("\n");
    printw("%c", (char)ch);
    if (++ch_cnt == 25) {
      erase();
      ch_cnt = 0;
    }
  }
  return endwin();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <initscr@plt>
mov    $0x0,%al
call   10b0 <noecho@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1060 <attron@plt>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1080 <printw@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1030 <attroff@plt>
cmpl   $0x0,-0x18(%rbp)
je     1273 <main+0xe3>
mov    $0x0,%al
call   1090 <refresh@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x71,-0x14(%rbp)
je     121b <main+0x8b>
cmpl   $0x51,-0x14(%rbp)
jne    1222 <main+0x92>
movl   $0x0,-0x18(%rbp)
cmpl   $0xd,-0x14(%rbp)
jne    123a <main+0xaa>
lea    0xdd9(%rip),%rdi
mov    $0x0,%al
call   1080 <printw@plt>
mov    -0x14(%rbp),%eax
movsbl %al,%esi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1080 <printw@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x19,%eax
jne    126e <main+0xde>
mov    $0x0,%al
call   1050 <erase@plt>
movl   $0x0,-0x1c(%rbp)
jmp    11ec <main+0x5c>
mov    $0x0,%al
call   10a0 <endwin@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <initscr@plt>
xor    %eax,%eax
call   10b0 <noecho@plt>
mov    0x2e3c(%rip),%rbx
mov    (%rbx),%edi
call   1060 <attron@plt>
lea    0xe46(%rip),%rdi
xor    %eax,%eax
call   1080 <printw@plt>
mov    (%rbx),%edi
call   1030 <attroff@plt>
lea    0xe3d(%rip),%r14
lea    0xe38(%rip),%r15
xor    %ebx,%ebx
jmp    11ff <main+0x6f>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%eax
and    $0xffffffdf,%ebp
movsbl %al,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1080 <printw@plt>
add    $0x1,%ebx
cmp    $0x19,%ebx
je     1220 <main+0x90>
cmp    $0x51,%ebp
je     122e <main+0x9e>
xor    %eax,%eax
call   1090 <refresh@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%ebp
cmp    $0xd,%eax
jne    11e0 <main+0x50>
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <printw@plt>
jmp    11e0 <main+0x50>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <erase@plt>
cmp    $0x51,%ebp
jne    11ff <main+0x6f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <endwin@plt>

LLVM IR (-O0):
@A_BLINK = global i32 0
@.str = [14 x i8] c"hello world!\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [3 x i8] c"%c\00"
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
store i32 0, i32* %8
%9 = call i32 (...) @initscr()
%10 = call i32 (...) @noecho()
%11 = load i32, i32* @A_BLINK
%12 = call i32 @attron(i32 %11)
%13 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @A_BLINK
%15 = call i32 @attroff(i32 %14)
br label %16
16: ; preds = %43, %2
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %44
19: ; preds = %16
%20 = call i32 (...) @refresh()
%21 = call i32 (...) @getchar()
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 113
br i1 %23, label %27, label %24
24: ; preds = %19
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, 81
br i1 %26, label %27, label %28
27: ; preds = %24, %19
store i32 0, i32* %7
br label %28
28: ; preds = %27, %24
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, 13
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %28
%34 = load i32, i32* %6
%35 = trunc i32 %34 to i8
%36 = sext i8 %35 to i32
%37 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %8
%39 = add i32 %38, 1
store i32 %39, i32* %8
%40 = icmp eq i32 %39, 25
br i1 %40, label %41, label %43
41: ; preds = %33
%42 = call i32 (...) @erase()
store i32 0, i32* %8
br label %43
43: ; preds = %41, %33
br label %16
44: ; preds = %16
%45 = call i32 (...) @endwin()
ret i32 %45
}

LLVM IR (-O2):
@A_BLINK = global i32 0
@.str = [14 x i8] c"hello world!\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @initscr()
%4 = tail call i32 (...) @noecho()
%5 = load i32, i32* @A_BLINK
%6 = tail call i32 @attron(i32 %5)
%7 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @A_BLINK
%9 = tail call i32 @attroff(i32 %8)
br label %10
10: ; preds = %2, %27
%11 = phi i32 [ 0, %2 ], [ %28, %27 ]
%12 = tail call i32 (...) @refresh()
%13 = tail call i32 (...) @getchar()
%14 = and i32 %13, -33
%15 = icmp eq i32 %14, 81
%16 = icmp eq i32 %13, 13
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %10
%20 = shl i32 %13, 24
%21 = ashr exact i32 %20, 24
%22 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = add i32 %11, 1
%24 = icmp eq i32 %23, 25
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = tail call i32 (...) @erase()
br label %27
27: ; preds = %25, %19
%28 = phi i32 [ 0, %25 ], [ %23, %19 ]
br i1 %15, label %29, label %10
29: ; preds = %27
%30 = tail call i32 (...) @endwin()
ret i32 %30
}