#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 COLORS;
int /*<<< orphan*/ COLOR_BLACK;
int /*<<< orphan*/ COLOR_PAIR(int);
int /*<<< orphan*/ COLOR_RED;
int /*<<< orphan*/ COLS;
scalar_t__ FALSE;
int LINES;
int /*<<< orphan*/ attroff(int /*<<< orphan*/);
int /*<<< orphan*/ attron(int /*<<< orphan*/);
scalar_t__ can_change_color();
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getch();
scalar_t__ has_colors();
int /*<<< orphan*/ init_color(int /*<<< orphan*/, int, int /*<<< orphan*/,
                              int /*<<< orphan*/);
int /*<<< orphan*/ init_pair(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ print_in_middle(int /*<<< orphan*/, int, int /*<<< orphan*/,
                                   int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ start_color();
int /*<<< orphan*/ stdscr;
int main() {
  initscr();
  noecho();
  if (has_colors() == FALSE) {
    endwin();
    printf("Your terminal does not support color\n");
    exit(1);
  }
  start_color();
  init_pair(1, COLOR_RED, COLOR_BLACK);
  attron(COLOR_PAIR(1));
  print_in_middle(stdscr, LINES / 2, 0, COLS, "This really is in color..");
  attroff(COLOR_PAIR(1));
  if (can_change_color()) {
    init_color(COLOR_RED, 700, 0, 0);
  }
  getch();
  endwin();
  printf("Number of available colours: %d\n", COLORS);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <initscr@plt>
mov    $0x0,%al
call   10f0 <noecho@plt>
mov    $0x0,%al
call   1040 <has_colors@plt>
mov    0x2d9d(%rip),%rcx
cmp    (%rcx),%rax
jne    1243 <main+0x53>
mov    $0x0,%al
call   10e0 <endwin@plt>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    $0x0,%al
call   1090 <start_color@plt>
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
mov    0x2d7e(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1060 <init_pair@plt>
mov    $0x1,%edi
call   10b0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   10a0 <attron@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
mov    0x2d61(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    0x2d36(%rip),%rax
mov    (%rax),%ecx
xor    %edx,%edx
lea    0xd81(%rip),%r8
call   1100 <print_in_middle@plt>
mov    $0x1,%edi
call   10b0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1030 <attroff@plt>
mov    $0x0,%al
call   10c0 <can_change_color@plt>
cmp    $0x0,%rax
je     12e3 <main+0xf3>
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
mov    $0x2bc,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1050 <init_color@plt>
mov    $0x0,%al
call   10d0 <getch@plt>
mov    $0x0,%al
call   10e0 <endwin@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%esi
lea    0xd3f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1090 <initscr@plt>
xor    %eax,%eax
call   1100 <noecho@plt>
xor    %eax,%eax
call   1050 <has_colors@plt>
mov    0x2d9b(%rip),%rcx
cmp    (%rcx),%rax
je     12e2 <main+0xe2>
xor    %eax,%eax
call   10a0 <start_color@plt>
mov    0x2d7c(%rip),%rbx
mov    (%rbx),%esi
mov    0x2d9b(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%edi
call   1070 <init_pair@plt>
mov    $0x1,%edi
call   10c0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   10b0 <attron@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,%esi
shr    $0x1f,%esi
add    %eax,%esi
sar    %esi
mov    0x2d54(%rip),%rax
mov    (%rax),%ecx
lea    0xd7b(%rip),%r8
xor    %edx,%edx
call   1110 <print_in_middle@plt>
mov    $0x1,%edi
call   10c0 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1030 <attroff@plt>
xor    %eax,%eax
call   10d0 <can_change_color@plt>
test   %rax,%rax
je     12b9 <main+0xb9>
mov    (%rbx),%edi
mov    $0x2bc,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1060 <init_color@plt>
xor    %eax,%eax
call   10e0 <getch@plt>
xor    %eax,%eax
call   10f0 <endwin@plt>
mov    0x2cf2(%rip),%rax
mov    (%rax),%esi
lea    0xd43(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret
xor    %eax,%eax
call   10f0 <endwin@plt>
lea    0xd4b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
@FALSE = global i64 0
@.str = [38 x i8] c"Your terminal does not support color\0A\00"
@COLOR_RED = global i32 0
@COLOR_BLACK = global i32 0
@stdscr = global i32 0
@LINES = global i32 0
@COLS = global i32 0
@.str.1 = [26 x i8] c"This really is in color..\00"
@.str.2 = [33 x i8] c"Number of available colours: %d\0A\00"
@COLORS = global i32 0
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 (...) @initscr()
%3 = call i32 (...) @noecho()
%4 = call i64 (...) @has_colors()
%5 = load i64, i64* @FALSE
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 (...) @endwin()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call i32 (...) @start_color()
%13 = load i32, i32* @COLOR_RED
%14 = load i32, i32* @COLOR_BLACK
%15 = call i32 @init_pair(i32 1, i32 %13, i32 %14)
%16 = call i32 @COLOR_PAIR(i32 1)
%17 = call i32 @attron(i32 %16)
%18 = load i32, i32* @stdscr
%19 = load i32, i32* @LINES
%20 = sdiv i32 %19, 2
%21 = load i32, i32* @COLS
%22 = call i32 @print_in_middle(i32 %18, i32 %20, i32 0, i32 %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @COLOR_PAIR(i32 1)
%24 = call i32 @attroff(i32 %23)
%25 = call i64 (...) @can_change_color()
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %11
%28 = load i32, i32* @COLOR_RED
%29 = call i32 @init_color(i32 %28, i32 700, i32 0, i32 0)
br label %30
30: ; preds = %27, %11
%31 = call i32 (...) @getch()
%32 = call i32 (...) @endwin()
%33 = load i32, i32* @COLORS
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %33)
ret i32 0
}

LLVM IR (-O2):
@FALSE = global i64 0
@COLOR_RED = global i32 0
@COLOR_BLACK = global i32 0
@stdscr = global i32 0
@LINES = global i32 0
@COLS = global i32 0
@.str.1 = [26 x i8] c"This really is in color..\00"
@.str.2 = [33 x i8] c"Number of available colours: %d\0A\00"
@COLORS = global i32 0
@str = [37 x i8] c"Your terminal does not support color\00"
define i32 @main() {
%1 = tail call i32 (...) @initscr()
%2 = tail call i32 (...) @noecho()
%3 = tail call i64 (...) @has_colors()
%4 = load i64, i64* @FALSE
%5 = icmp eq i64 %3, %4
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = tail call i32 (...) @endwin()
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = tail call i32 (...) @start_color()
%12 = load i32, i32* @COLOR_RED
%13 = load i32, i32* @COLOR_BLACK
%14 = tail call i32 @init_pair(i32 1, i32 %12, i32 %13)
%15 = tail call i32 @COLOR_PAIR(i32 1)
%16 = tail call i32 @attron(i32 %15)
%17 = load i32, i32* @stdscr
%18 = load i32, i32* @LINES
%19 = sdiv i32 %18, 2
%20 = load i32, i32* @COLS
%21 = tail call i32 @print_in_middle(i32 %17, i32 %19, i32 0, i32 %20, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @COLOR_PAIR(i32 1)
%23 = tail call i32 @attroff(i32 %22)
%24 = tail call i64 (...) @can_change_color()
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %10
%27 = load i32, i32* @COLOR_RED
%28 = tail call i32 @init_color(i32 %27, i32 700, i32 0, i32 0)
br label %29
29: ; preds = %26, %10
%30 = tail call i32 (...) @getch()
%31 = tail call i32 (...) @endwin()
%32 = load i32, i32* @COLORS
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i32 %32)
ret i32 0
}