#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 A_BOLD;
int /*<<< orphan*/ COLOR_BLACK;
int /*<<< orphan*/ COLOR_BLUE;
int /*<<< orphan*/ COLOR_GREEN;
int COLOR_PAIR(int);
int /*<<< orphan*/ COLOR_RED;
int /*<<< orphan*/ COLOR_WHITE;
int /*<<< orphan*/ attrset(int);
int /*<<< orphan*/ cbreak();
int /*<<< orphan*/ endwin();
int getch();
int /*<<< orphan*/ getmaxyx(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ init_pair(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ mvaddch(int, int, char);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ start_color();
int /*<<< orphan*/ stdscr;
int main(int argc, char *argv[]) {
  initscr();
  start_color();
  cbreak();
  noecho();
  init_pair(1, COLOR_WHITE, COLOR_BLACK);
  attrset(A_BOLD | COLOR_PAIR(1));
  int maxy = 0;
  int maxx = 0;
  getmaxyx(stdscr, maxy, maxx);
  int x, y;
  for (y = 0; y < maxy; y++) {
    for (x = 0; x < maxx; x++) {
      mvaddch(y, x, ' ');
    }
  }
  refresh();
  bool done = false;
  while (!done) {
    int c = getch();
    switch (c) {
    case 'q':
      done = true;
      break;
    case 'r':
      init_pair(1, COLOR_BLACK, COLOR_RED);
      refresh();
      break;
    case 'b':
      init_pair(1, COLOR_BLACK, COLOR_BLUE);
      refresh();
      break;
    case 'g':
      init_pair(1, COLOR_BLACK, COLOR_GREEN);
      refresh();
      break;
    case 'w':
      init_pair(1, COLOR_BLACK, COLOR_WHITE);
      refresh();
      break;
    case 'n':
      init_pair(1, COLOR_WHITE, COLOR_BLACK);
      refresh();
      break;
    }
  }
  endwin();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <initscr@plt>
mov    $0x0,%al
call   1060 <start_color@plt>
mov    $0x0,%al
call   1030 <cbreak@plt>
mov    $0x0,%al
call   10d0 <noecho@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
mov    0x2dde(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1040 <init_pair@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x1,%edi
call   1080 <COLOR_PAIR@plt>
mov    -0x2c(%rbp),%edi
or     %eax,%edi
call   10c0 <attrset@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1070 <getmaxyx@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12a7 <main+0xe7>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1294 <main+0xd4>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    $0x20,%edx
call   10e0 <mvaddch@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    126a <main+0xaa>
jmp    1299 <main+0xd9>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1257 <main+0x97>
mov    $0x0,%al
call   1090 <refresh@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12cb <main+0x10b>
jmp    13d2 <main+0x212>
xor    %eax,%eax
call   10a0 <getch@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
add    $0xffffff9e,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x15,%eax
ja     13cd <main+0x20d>
mov    -0x38(%rbp),%rax
lea    0xd0b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x1,-0x24(%rbp)
jmp    13cd <main+0x20d>
mov    0x2ccf(%rip),%rax
mov    (%rax),%esi
mov    0x2c96(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1040 <init_pair@plt>
mov    $0x0,%al
call   1090 <refresh@plt>
jmp    13cd <main+0x20d>
mov    0x2ca7(%rip),%rax
mov    (%rax),%esi
mov    0x2c7e(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1040 <init_pair@plt>
mov    $0x0,%al
call   1090 <refresh@plt>
jmp    13cd <main+0x20d>
mov    0x2c7f(%rip),%rax
mov    (%rax),%esi
mov    0x2c6e(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1040 <init_pair@plt>
mov    $0x0,%al
call   1090 <refresh@plt>
jmp    13cd <main+0x20d>
mov    0x2c57(%rip),%rax
mov    (%rax),%esi
mov    0x2c36(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1040 <init_pair@plt>
mov    $0x0,%al
call   1090 <refresh@plt>
jmp    13cd <main+0x20d>
mov    0x2c17(%rip),%rax
mov    (%rax),%esi
mov    0x2c26(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1040 <init_pair@plt>
mov    $0x0,%al
call   1090 <refresh@plt>
jmp    12b5 <main+0xf5>
mov    $0x0,%al
call   10b0 <endwin@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <initscr@plt>
xor    %eax,%eax
call   1060 <start_color@plt>
xor    %eax,%eax
call   1030 <cbreak@plt>
xor    %eax,%eax
call   10d0 <noecho@plt>
mov    0x2dea(%rip),%r14
mov    (%r14),%esi
mov    0x2df8(%rip),%r15
mov    (%r15),%edx
mov    $0x1,%edi
call   1040 <init_pair@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%ebx
mov    $0x1,%edi
call   1080 <COLOR_PAIR@plt>
or     %eax,%ebx
mov    %ebx,%edi
call   10c0 <attrset@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <getmaxyx@plt>
lea    0xdd6(%rip),%rbx
mov    0x2d8f(%rip),%r12
mov    0x2da0(%rip),%r13
mov    0x2d71(%rip),%rbp
jmp    125e <main+0xae>
mov    %r15,%rax
mov    %r12,%rcx
nopw   0x0(%rax,%rax,1)
mov    (%rax),%esi
mov    (%rcx),%edx
mov    $0x1,%edi
call   1040 <init_pair@plt>
xor    %eax,%eax
call   1090 <refresh@plt>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   10a0 <getch@plt>
add    $0xffffff9e,%eax
cmp    $0x15,%eax
ja     1270 <main+0xc0>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    %r15,%rax
mov    %r13,%rcx
jmp    1250 <main+0xa0>
mov    %r14,%rax
mov    %r15,%rcx
jmp    1250 <main+0xa0>
mov    %r15,%rax
mov    %rbp,%rcx
jmp    1250 <main+0xa0>
mov    %r15,%rax
mov    %r14,%rcx
jmp    1250 <main+0xa0>
xor    %eax,%eax
call   10b0 <endwin@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@COLOR_WHITE = global i32 0
@COLOR_BLACK = global i32 0
@A_BOLD = global i32 0
@stdscr = global i32 0
@COLOR_RED = global i32 0
@COLOR_BLUE = global i32 0
@COLOR_GREEN = 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()
%13 = call i32 (...) @start_color()
%14 = call i32 (...) @cbreak()
%15 = call i32 (...) @noecho()
%16 = load i32, i32* @COLOR_WHITE
%17 = load i32, i32* @COLOR_BLACK
%18 = call i32 @init_pair(i32 1, i32 %16, i32 %17)
%19 = load i32, i32* @A_BOLD
%20 = call i32 @COLOR_PAIR(i32 1)
%21 = or i32 %19, %20
%22 = call i32 @attrset(i32 %21)
store i32 0, i32* %6
store i32 0, i32* %7
%23 = load i32, i32* @stdscr
%24 = load i32, i32* %6
%25 = load i32, i32* %7
%26 = call i32 @getmaxyx(i32 %23, i32 %24, i32 %25)
store i32 0, i32* %9
br label %27
27: ; preds = %44, %2
%28 = load i32, i32* %9
%29 = load i32, i32* %6
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %47
31: ; preds = %27
store i32 0, i32* %8
br label %32
32: ; preds = %40, %31
%33 = load i32, i32* %8
%34 = load i32, i32* %7
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %43
36: ; preds = %32
%37 = load i32, i32* %9
%38 = load i32, i32* %8
%39 = call i32 @mvaddch(i32 %37, i32 %38, i8 signext 32)
br label %40
40: ; preds = %36
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %32
43: ; preds = %32
br label %44
44: ; preds = %43
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 1
store i32 %46, i32* %9
br label %27
47: ; preds = %27
%48 = call i32 (...) @refresh()
store i32 0, i32* %10
br label %49
49: ; preds = %82, %47
%50 = load i32, i32* %10
%51 = icmp ne i32 %50, 0
%52 = xor i1 %51, true
br i1 %52, label %53, label %83
53: ; preds = %49
%54 = call i32 (...) @getch()
store i32 %54, i32* %11
%55 = load i32, i32* %11
switch i32 %55, label %82 [
i32 113, label %56
i32 114, label %57
i32 98, label %62
i32 103, label %67
i32 119, label %72
i32 110, label %77
]
56: ; preds = %53
store i32 1, i32* %10
br label %82
57: ; preds = %53
%58 = load i32, i32* @COLOR_BLACK
%59 = load i32, i32* @COLOR_RED
%60 = call i32 @init_pair(i32 1, i32 %58, i32 %59)
%61 = call i32 (...) @refresh()
br label %82
62: ; preds = %53
%63 = load i32, i32* @COLOR_BLACK
%64 = load i32, i32* @COLOR_BLUE
%65 = call i32 @init_pair(i32 1, i32 %63, i32 %64)
%66 = call i32 (...) @refresh()
br label %82
67: ; preds = %53
%68 = load i32, i32* @COLOR_BLACK
%69 = load i32, i32* @COLOR_GREEN
%70 = call i32 @init_pair(i32 1, i32 %68, i32 %69)
%71 = call i32 (...) @refresh()
br label %82
72: ; preds = %53
%73 = load i32, i32* @COLOR_BLACK
%74 = load i32, i32* @COLOR_WHITE
%75 = call i32 @init_pair(i32 1, i32 %73, i32 %74)
%76 = call i32 (...) @refresh()
br label %82
77: ; preds = %53
%78 = load i32, i32* @COLOR_WHITE
%79 = load i32, i32* @COLOR_BLACK
%80 = call i32 @init_pair(i32 1, i32 %78, i32 %79)
%81 = call i32 (...) @refresh()
br label %82
82: ; preds = %53, %77, %72, %67, %62, %57, %56
br label %49
83: ; preds = %49
%84 = call i32 (...) @endwin()
ret i32 0
}

LLVM IR (-O2):
@COLOR_WHITE = global i32 0
@COLOR_BLACK = global i32 0
@A_BOLD = global i32 0
@stdscr = global i32 0
@COLOR_RED = global i32 0
@COLOR_BLUE = global i32 0
@COLOR_GREEN = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @initscr()
%4 = tail call i32 (...) @start_color()
%5 = tail call i32 (...) @cbreak()
%6 = tail call i32 (...) @noecho()
%7 = load i32, i32* @COLOR_WHITE
%8 = load i32, i32* @COLOR_BLACK
%9 = tail call i32 @init_pair(i32 1, i32 %7, i32 %8)
%10 = load i32, i32* @A_BOLD
%11 = tail call i32 @COLOR_PAIR(i32 1)
%12 = or i32 %11, %10
%13 = tail call i32 @attrset(i32 %12)
%14 = load i32, i32* @stdscr
%15 = tail call i32 @getmaxyx(i32 %14, i32 0, i32 0)
br label %16
16: ; preds = %2, %24
%17 = tail call i32 (...) @refresh()
br label %18
18: ; preds = %16, %18
%19 = tail call i32 (...) @getch()
switch i32 %19, label %18 [
i32 113, label %30
i32 114, label %23
i32 98, label %24
i32 103, label %20
i32 119, label %21
i32 110, label %22
]
20: ; preds = %18
br label %24
21: ; preds = %18
br label %24
22: ; preds = %18
br label %24
23: ; preds = %18
br label %24
24: ; preds = %18, %23, %20, %21, %22
%25 = phi i32* [ @COLOR_WHITE, %22 ], [ @COLOR_BLACK, %21 ], [ @COLOR_BLACK, %20 ], [ @COLOR_BLACK, %23 ], [ @COLOR_BLACK, %18 ]
%26 = phi i32* [ @COLOR_BLACK, %22 ], [ @COLOR_WHITE, %21 ], [ @COLOR_GREEN, %20 ], [ @COLOR_RED, %23 ], [ @COLOR_BLUE, %18 ]
%27 = load i32, i32* %25
%28 = load i32, i32* %26
%29 = tail call i32 @init_pair(i32 1, i32 %27, i32 %28)
br label %16
30: ; preds = %18
%31 = tail call i32 (...) @endwin()
ret i32 0
}