#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 */
int COLOR_PAIRS;
int /*<<< orphan*/ clear();
int /*<<< orphan*/ color_set(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ delwin(int /*<<< orphan*/ *);
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ getch();
scalar_t__ has_colors();
int /*<<< orphan*/ init_colors();
int /*<<< orphan*/ *initscr();
int /*<<< orphan*/ mvaddstr(int, int, char *);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ start_color();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usleep(int);
int main() {
  WINDOW *window;
  if ((window = initscr()) == NULL) {
    fprintf(stderr, "error initialising curses.\n");
    return 1;
  }
  start_color();
  if (has_colors() && COLOR_PAIRS >= 13) {
    init_colors();
    for (int i = 0; i < 13; i++) {
      color_set(i, NULL);
      mvaddstr(6 + i, 32, "rainbow");
      refresh();
      usleep(100 * 1000);
      clear();
    }
  }
  getch();
  delwin(window);
  endwin();
  refresh();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <initscr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1215 <main+0x45>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xdfc(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12c1 <main+0xf1>
mov    $0x0,%al
call   1050 <start_color@plt>
mov    $0x0,%al
call   1030 <has_colors@plt>
cmp    $0x0,%rax
je     12a3 <main+0xd3>
mov    0x2db4(%rip),%rax
cmpl   $0xd,(%rax)
jl     12a3 <main+0xd3>
mov    $0x0,%al
call   10c0 <init_colors@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xd,-0x14(%rbp)
jge    129e <main+0xce>
mov    -0x14(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   10e0 <color_set@plt>
mov    -0x14(%rbp),%edi
add    $0x6,%edi
mov    $0x20,%esi
lea    0xda9(%rip),%rdx
call   10b0 <mvaddstr@plt>
mov    $0x0,%al
call   1080 <refresh@plt>
mov    $0x186a0,%edi
call   10f0 <usleep@plt>
mov    $0x0,%al
call   10d0 <clear@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    124b <main+0x7b>
jmp    12a3 <main+0xd3>
mov    $0x0,%al
call   1090 <getch@plt>
mov    -0x10(%rbp),%rdi
call   1070 <delwin@plt>
mov    $0x0,%al
call   10a0 <endwin@plt>
mov    $0x0,%al
call   1080 <refresh@plt>
mov    -0x4(%rbp),%eax
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>
test   %rax,%rax
je     1278 <main+0xa8>
mov    %rax,%r15
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <start_color@plt>
xor    %eax,%eax
call   1030 <has_colors@plt>
test   %rax,%rax
je     1259 <main+0x89>
mov    0x2de1(%rip),%rax
cmpl   $0xd,(%rax)
jl     1259 <main+0x89>
xor    %eax,%eax
call   10c0 <init_colors@plt>
lea    0xe02(%rip),%rbp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %ebx,%edi
xor    %esi,%esi
call   10e0 <color_set@plt>
lea    0x6(%rbx),%edi
mov    $0x20,%esi
mov    %rbp,%rdx
call   10b0 <mvaddstr@plt>
xor    %eax,%eax
call   1080 <refresh@plt>
mov    $0x186a0,%edi
call   10f0 <usleep@plt>
xor    %eax,%eax
call   10d0 <clear@plt>
add    $0x1,%ebx
cmp    $0xd,%ebx
jne    1220 <main+0x50>
xor    %eax,%eax
call   1090 <getch@plt>
mov    %r15,%rdi
call   1070 <delwin@plt>
xor    %eax,%eax
call   10a0 <endwin@plt>
xor    %eax,%eax
call   1080 <refresh@plt>
jmp    1293 <main+0xc3>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
lea    0xd78(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"error initialising curses.\0A\00"
@COLOR_PAIRS = global i32 0
@.str.1 = [8 x i8] c"rainbow\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32* (...) @initscr()
store i32* %4, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %1
br label %40
9: ; preds = %0
%10 = call i32 (...) @start_color()
%11 = call i64 (...) @has_colors()
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %9
%14 = load i32, i32* @COLOR_PAIRS
%15 = icmp sge i32 %14, 13
br i1 %15, label %16, label %34
16: ; preds = %13
%17 = call i32 (...) @init_colors()
store i32 0, i32* %3
br label %18
18: ; preds = %30, %16
%19 = load i32, i32* %3
%20 = icmp slt i32 %19, 13
br i1 %20, label %21, label %33
21: ; preds = %18
%22 = load i32, i32* %3
%23 = call i32 @color_set(i32 %22, i32* null)
%24 = load i32, i32* %3
%25 = add nsw i32 6, %24
%26 = call i32 @mvaddstr(i32 %25, i32 32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 (...) @refresh()
%28 = call i32 @usleep(i32 100000)
%29 = call i32 (...) @clear()
br label %30
30: ; preds = %21
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %18
33: ; preds = %18
br label %34
34: ; preds = %33, %13, %9
%35 = call i32 (...) @getch()
%36 = load i32*, i32** %2
%37 = call i32 @delwin(i32* %36)
%38 = call i32 (...) @endwin()
%39 = call i32 (...) @refresh()
br label %40
40: ; preds = %34, %6
%41 = load i32, i32* %1
ret i32 %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"error initialising curses.\0A\00"
@COLOR_PAIRS = global i32 0
@.str.1 = [8 x i8] c"rainbow\00"
define i32 @main() {
%1 = tail call i32* (...) @initscr()
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %30
6: ; preds = %0
%7 = tail call i32 (...) @start_color()
%8 = tail call i64 (...) @has_colors()
%9 = icmp ne i64 %8, 0
%10 = load i32, i32* @COLOR_PAIRS
%11 = icmp sgt i32 %10, 12
%12 = select i1 %9, i1 %11, i1 false
br i1 %12, label %13, label %25
13: ; preds = %6
%14 = tail call i32 (...) @init_colors()
br label %15
15: ; preds = %13, %15
%16 = phi i32 [ 0, %13 ], [ %23, %15 ]
%17 = tail call i32 @color_set(i32 %16, i32* null)
%18 = add nuw nsw i32 %16, 6
%19 = tail call i32 @mvaddstr(i32 %18, i32 32, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 (...) @refresh()
%21 = tail call i32 @usleep(i32 100000)
%22 = tail call i32 (...) @clear()
%23 = add nuw nsw i32 %16, 1
%24 = icmp eq i32 %23, 13
br i1 %24, label %25, label %15
25: ; preds = %15, %6
%26 = tail call i32 (...) @getch()
%27 = tail call i32 @delwin(i32* %1)
%28 = tail call i32 (...) @endwin()
%29 = tail call i32 (...) @refresh()
br label %30
30: ; preds = %25, %3
%31 = phi i32 [ 1, %3 ], [ 0, %25 ]
ret i32 %31
}