#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 A_BLINK;
int A_REVERSE;
short COLORS;
int /*<<< orphan*/ COLOR_PAIR(int);
int /*<<< orphan*/ FALSE;
#define KEY_DOWN 131
#define KEY_LEFT 130
#define KEY_RIGHT 129
#define KEY_UP 128
int /*<<< orphan*/ TRUE;
int atoi(char *);
int /*<<< orphan*/ attroff(int);
int /*<<< orphan*/ attron(int);
int /*<<< orphan*/ attrset(int /*<<< orphan*/);
int /*<<< orphan*/ cbreak();
int /*<<< orphan*/ clear();
int /*<<< orphan*/ curs_set(int /*<<< orphan*/);
int /*<<< orphan*/ delwin(int /*<<< orphan*/ *);
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ erase();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getch();
int /*<<< orphan*/ getmaxyx(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ has_colors();
int /*<<< orphan*/ init_pair(int /*<<< orphan*/, short, short);
int /*<<< orphan*/ *initscr();
int /*<<< orphan*/ keypad(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ nonl();
int /*<<< orphan*/ print_footer(int, int, int);
int /*<<< orphan*/ print_header(int, int);
int /*<<< orphan*/ print_tree(int, char);
int /*<<< orphan*/ print_trunk(int, int, char);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ start_color();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strncmp(char *, char *, int);
int /*<<< orphan*/ usage(char *);
int /*<<< orphan*/ use_default_colors();
int main(int argc, char *argv[]) {
  WINDOW *mainwin;
  int ch;
  int maxX = 0, maxY = 0;
  if (argc != 3)
    usage(argv[0]);
  int height_tree = atoi(argv[1]);
  int height_trunk = ((height_tree) / (1.61803 * 2.0));
  char half = -1;
  if (!strncmp("half", argv[2], 4 * sizeof(char)))
    half = 1;
  else if (!strncmp("full", argv[2], 4 * sizeof(char)))
    half = 0;
  else
    usage(argv[0]);
  mainwin = initscr();
  if (mainwin == NULL) {
    fprintf(stderr, "Error initialising ncurses.\n");
    exit(-1);
  }
  getmaxyx(mainwin, maxY, maxX);
  if (!has_colors()) {
    delwin(mainwin);
    endwin();
    fprintf(stderr, "Your terminal does not support color\n");
    exit(-1);
  } else {
    start_color();
    use_default_colors();
    short pair_count = 0;
    for (short i = 0; i < COLORS; i++)
      for (short j = 0; j < COLORS; j++)
        init_pair(pair_count++, i, j);
  }
  clear();
  noecho();
  cbreak();
  curs_set(FALSE);
  nonl();
  keypad(mainwin, TRUE);
  print_header(maxY, maxX);
  print_tree(height_tree, half);
  print_trunk(height_tree, height_trunk, half);
  print_footer(maxY, height_tree, height_trunk);
  while ((ch = getch()) != 'q') {
    switch (ch) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
      attrset(COLOR_PAIR(ch - '0'));
      break;
    case KEY_UP:
      height_tree += 1;
      height_trunk = ((height_tree) / (1.61803 * 2.0));
      if (height_tree + height_trunk + 1 > maxY - 1) {
        height_tree -= 1;
        height_trunk = ((height_tree) / (1.61803 * 2.0));
      }
      break;
    case KEY_DOWN:
      height_tree -= 1;
      height_trunk = ((height_tree) / (1.61803 * 2.0));
      if (height_tree - height_trunk < 1) {
        height_tree = 1;
        height_trunk = ((height_tree) / (1.61803 * 2.0));
      }
      break;
    case KEY_RIGHT:
      attron(A_REVERSE | A_BLINK);
      break;
    case KEY_LEFT:
      attroff(A_REVERSE | A_BLINK);
      break;
    case 'f':
    case 'F':
      half = 0;
      break;
    case 'h':
    case 'H':
      half = 1;
      break;
    }
    erase();
    print_header(maxY, maxX);
    print_tree(height_tree, half);
    print_trunk(height_tree, height_trunk, half);
    print_footer(maxY, height_tree, height_trunk);
  }
  delwin(mainwin);
  endwin();
  refresh();
  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)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     131a <main+0x3a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1150 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   11c0 <atoi@plt>
mov    %eax,-0x28(%rbp)
cvtsi2sdl -0x28(%rbp),%xmm0
movsd  0xcc9(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
movb   $0xff,-0x2d(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xe03(%rip),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    1371 <main+0x91>
movb   $0x1,-0x2d(%rbp)
jmp    13ad <main+0xcd>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xddd(%rip),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    139c <main+0xbc>
movb   $0x0,-0x2d(%rbp)
jmp    13a8 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1150 <usage@plt>
jmp    13ad <main+0xcd>
mov    $0x0,%al
call   10a0 <initscr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    13e2 <main+0x102>
mov    0x2bf6(%rip),%rax
mov    (%rax),%edi
lea    0xd8f(%rip),%rsi
call   10f0 <fprintf@plt>
mov    $0xffffffff,%edi
call   11e0 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
call   10e0 <getmaxyx@plt>
mov    $0x0,%al
call   1060 <has_colors@plt>
cmp    $0x0,%eax
jne    1430 <main+0x150>
mov    -0x18(%rbp),%rdi
call   1120 <delwin@plt>
mov    $0x0,%al
call   1170 <endwin@plt>
mov    0x2ba8(%rip),%rax
mov    (%rax),%edi
lea    0xd5e(%rip),%rsi
call   10f0 <fprintf@plt>
mov    $0xffffffff,%edi
call   11e0 <exit@plt>
mov    $0x0,%al
call   10c0 <start_color@plt>
mov    $0x0,%al
call   1050 <use_default_colors@plt>
movw   $0x0,-0x30(%rbp)
movw   $0x0,-0x32(%rbp)
movswl -0x32(%rbp),%eax
mov    0x2b73(%rip),%rcx
movswl (%rcx),%ecx
cmp    %ecx,%eax
jge    14c5 <main+0x1e5>
movw   $0x0,-0x34(%rbp)
movswl -0x34(%rbp),%eax
mov    0x2b57(%rip),%rcx
movswl (%rcx),%ecx
cmp    %ecx,%eax
jge    14af <main+0x1cf>
mov    -0x30(%rbp),%ax
mov    %ax,%cx
add    $0x1,%cx
mov    %cx,-0x30(%rbp)
movswl %ax,%edi
mov    -0x32(%rbp),%ax
movswl %ax,%esi
movswl -0x34(%rbp),%edx
call   1080 <init_pair@plt>
mov    -0x34(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x34(%rbp)
jmp    1466 <main+0x186>
jmp    14b4 <main+0x1d4>
mov    -0x32(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x32(%rbp)
jmp    144a <main+0x16a>
jmp    14ca <main+0x1ea>
mov    $0x0,%al
call   11f0 <clear@plt>
mov    $0x0,%al
call   11b0 <noecho@plt>
mov    $0x0,%al
call   1070 <cbreak@plt>
mov    0x2ad2(%rip),%rax
mov    (%rax),%edi
call   1200 <curs_set@plt>
mov    $0x0,%al
call   1110 <nonl@plt>
mov    -0x18(%rbp),%rdi
mov    0x2ae9(%rip),%rax
mov    (%rax),%esi
call   1090 <keypad@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1190 <print_header@plt>
mov    -0x28(%rbp),%edi
movsbl -0x2d(%rbp),%esi
call   11d0 <print_tree@plt>
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
movsbl -0x2d(%rbp),%edx
call   11a0 <print_trunk@plt>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1100 <print_footer@plt>
mov    $0x0,%al
call   1160 <getch@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x71,%eax
je     16c4 <main+0x3e4>
mov    -0x1c(%rbp),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x53,%eax
ja     1684 <main+0x3a4>
mov    -0x40(%rbp),%rax
lea    0xa9b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x1c(%rbp),%edi
sub    $0x30,%edi
call   1130 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1180 <attrset@plt>
jmp    1684 <main+0x3a4>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
cvtsi2sdl -0x28(%rbp),%xmm0
movsd  0xa5d(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
add    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    15e6 <main+0x306>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
cvtsi2sdl -0x28(%rbp),%xmm0
movsd  0xa25(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
jmp    1684 <main+0x3a4>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
cvtsi2sdl -0x28(%rbp),%xmm0
movsd  0x9ff(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
sub    -0x2c(%rbp),%eax
cmp    $0x1,%eax
jge    163a <main+0x35a>
movl   $0x1,-0x28(%rbp)
cvtsi2sdl -0x28(%rbp),%xmm0
movsd  0x9d1(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x2c(%rbp)
jmp    1684 <main+0x3a4>
mov    0x298a(%rip),%rax
mov    (%rax),%edi
mov    0x2991(%rip),%rax
or     (%rax),%edi
call   10d0 <attron@plt>
jmp    1684 <main+0x3a4>
mov    0x296e(%rip),%rax
mov    (%rax),%edi
mov    0x2975(%rip),%rax
or     (%rax),%edi
call   1030 <attroff@plt>
jmp    1684 <main+0x3a4>
movb   $0x0,-0x2d(%rbp)
jmp    1684 <main+0x3a4>
movb   $0x1,-0x2d(%rbp)
mov    $0x0,%al
call   10b0 <erase@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1190 <print_header@plt>
mov    -0x28(%rbp),%edi
movsbl -0x2d(%rbp),%esi
call   11d0 <print_tree@plt>
mov    -0x28(%rbp),%edi
mov    -0x2c(%rbp),%esi
movsbl -0x2d(%rbp),%edx
call   11a0 <print_trunk@plt>
mov    -0x24(%rbp),%edi
mov    -0x28(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1100 <print_footer@plt>
jmp    153a <main+0x25a>
mov    -0x18(%rbp),%rdi
call   1120 <delwin@plt>
mov    $0x0,%al
call   1170 <endwin@plt>
mov    $0x0,%al
call   1140 <refresh@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
sub    $0x18,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
je     12fe <main+0x1e>
mov    (%r14),%rdi
call   1150 <usage@plt>
mov    0x8(%r14),%rdi
call   11c0 <atoi@plt>
mov    %eax,%ebx
mov    0x10(%r14),%rsi
lea    0xe44(%rip),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     1348 <main+0x68>
mov    0x10(%r14),%rsi
lea    0xe30(%rip),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %eax,%eax
je     134d <main+0x6d>
mov    (%r14),%rdi
call   1150 <usage@plt>
mov    $0xff,%r12b
jmp    1350 <main+0x70>
mov    $0x1,%r12b
jmp    1350 <main+0x70>
xor    %r12d,%r12d
xor    %eax,%eax
call   10a0 <initscr@plt>
test   %rax,%rax
je     15a5 <main+0x2c5>
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10e0 <getmaxyx@plt>
xor    %eax,%eax
call   1060 <has_colors@plt>
test   %eax,%eax
je     15b7 <main+0x2d7>
cvtsi2sd %ebx,%xmm0
divsd  0xc74(%rip),%xmm0
cvttsd2si %xmm0,%r15d
xor    %eax,%eax
call   10c0 <start_color@plt>
xor    %eax,%eax
call   1050 <use_default_colors@plt>
mov    0x2c22(%rip),%r14
movzwl (%r14),%eax
test   %ax,%ax
jle    13fb <main+0x11b>
xor    %ebp,%ebp
xor    %r13d,%r13d
mov    %r12d,0x14(%rsp)
jmp    13c8 <main+0xe8>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %ax,%bp
jge    13fb <main+0x11b>
test   %ax,%ax
jle    13c0 <main+0xe0>
xor    %r12d,%r12d
lea    (%r12,%r13,1),%eax
movswl %ax,%edi
movswl %bp,%esi
movswl %r12w,%edx
call   1080 <init_pair@plt>
add    $0x1,%r12d
movzwl (%r14),%eax
cmp    %ax,%r12w
jl     13d0 <main+0xf0>
add    %r12d,%r13d
mov    0x14(%rsp),%r12d
jmp    13c0 <main+0xe0>
xor    %eax,%eax
call   11f0 <clear@plt>
xor    %eax,%eax
call   11b0 <noecho@plt>
xor    %eax,%eax
call   1070 <cbreak@plt>
mov    0x2ba1(%rip),%rax
mov    (%rax),%edi
call   1200 <curs_set@plt>
xor    %eax,%eax
call   1110 <nonl@plt>
mov    0x2bbc(%rip),%rax
mov    (%rax),%esi
mov    0x8(%rsp),%rdi
call   1090 <keypad@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1190 <print_header@plt>
movsbl %r12b,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   11d0 <print_tree@plt>
mov    %ebx,%edi
mov    %r15d,%esi
mov    %ebp,%edx
call   11a0 <print_trunk@plt>
xor    %edi,%edi
mov    %ebx,%esi
mov    %r15d,%edx
call   1100 <print_footer@plt>
lea    0xb9b(%rip),%r13
mov    0x2b6c(%rip),%r14
jmp    14c3 <main+0x1e3>
cs nopw 0x0(%rax,%rax,1)
mov    %eax,%edi
call   1130 <COLOR_PAIR@plt>
mov    %eax,%edi
call   1180 <attrset@plt>
xor    %eax,%eax
call   10b0 <erase@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1190 <print_header@plt>
movsbl %r12b,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
call   11d0 <print_tree@plt>
mov    %ebx,%edi
mov    %r15d,%esi
mov    %ebp,%edx
call   11a0 <print_trunk@plt>
xor    %edi,%edi
mov    %ebx,%esi
mov    %r15d,%edx
call   1100 <print_footer@plt>
xor    %eax,%eax
call   1160 <getch@plt>
add    $0xffffffd0,%eax
cmp    $0x53,%eax
ja     148e <main+0x1ae>
movslq 0x0(%r13,%rax,4),%rcx
add    %r13,%rcx
jmp    *%rcx
xor    %r12d,%r12d
jmp    148e <main+0x1ae>
mov    $0x1,%r12b
jmp    148e <main+0x1ae>
mov    (%r14),%edi
mov    0x2ae0(%rip),%rax
or     (%rax),%edi
call   10d0 <attron@plt>
jmp    148e <main+0x1ae>
mov    (%r14),%edi
mov    0x2acd(%rip),%rax
or     (%rax),%edi
call   1030 <attroff@plt>
jmp    148e <main+0x1ae>
add    $0xffffffff,%ebx
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  0xae2(%rip),%xmm0
cvttsd2si %xmm0,%r15d
cmp    %r15d,%ebx
jg     148e <main+0x1ae>
xor    %r15d,%r15d
mov    $0x1,%ebx
jmp    148e <main+0x1ae>
lea    0x1(%rbx),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xab5(%rip),%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%r15d
lea    (%rbx,%r15,1),%ecx
add    $0x1,%ecx
cmp    $0xffffffff,%ecx
jl     1575 <main+0x295>
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%r15d
jmp    148e <main+0x1ae>
mov    %eax,%ebx
jmp    148e <main+0x1ae>
mov    0x8(%rsp),%rdi
call   1120 <delwin@plt>
xor    %eax,%eax
call   1170 <endwin@plt>
xor    %eax,%eax
call   1140 <refresh@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a14(%rip),%rax
mov    (%rax),%edi
lea    0xbad(%rip),%rsi
jmp    15d8 <main+0x2f8>
mov    0x8(%rsp),%rdi
call   1120 <delwin@plt>
xor    %eax,%eax
call   1170 <endwin@plt>
mov    0x29f1(%rip),%rax
mov    (%rax),%edi
lea    0xba7(%rip),%rsi
call   10f0 <fprintf@plt>
mov    $0xffffffff,%edi
call   11e0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"half\00"
@.str.1 = [5 x i8] c"full\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"Error initialising ncurses.\0A\00"
@.str.3 = [38 x i8] c"Your terminal does not support color\0A\00"
@COLORS = global i16 0
@FALSE = global i32 0
@TRUE = global i32 0
@A_REVERSE = global i32 0
@A_BLINK = 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
%12 = alloca i8
%13 = alloca i16
%14 = alloca i16
%15 = alloca i16
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %9
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = call i32 @usage(i8* %21)
br label %23
23: ; preds = %18, %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %10
%28 = load i32, i32* %10
%29 = sitofp i32 %28 to double
%30 = fdiv double %29, 3.236060e+00
%31 = fptosi double %30 to i32
store i32 %31, i32* %11
store i8 -1, i8* %12
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %34, i32 4)
%36 = icmp ne i32 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %23
store i8 1, i8* %12
br label %51
38: ; preds = %23
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 2
%41 = load i8*, i8** %40
%42 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %41, i32 4)
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %38
store i8 0, i8* %12
br label %50
45: ; preds = %38
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 0
%48 = load i8*, i8** %47
%49 = call i32 @usage(i8* %48)
br label %50
50: ; preds = %45, %44
br label %51
51: ; preds = %50, %37
%52 = call i32* (...) @initscr()
store i32* %52, i32** %6
%53 = load i32*, i32** %6
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %59
55: ; preds = %51
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%58 = call i32 @exit(i32 -1)
unreachable
59: ; preds = %51
%60 = load i32*, i32** %6
%61 = load i32, i32* %9
%62 = load i32, i32* %8
%63 = call i32 @getmaxyx(i32* %60, i32 %61, i32 %62)
%64 = call i32 (...) @has_colors()
%65 = icmp ne i32 %64, 0
br i1 %65, label %73, label %66
66: ; preds = %59
%67 = load i32*, i32** %6
%68 = call i32 @delwin(i32* %67)
%69 = call i32 (...) @endwin()
%70 = load i32, i32* @stderr
%71 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%72 = call i32 @exit(i32 -1)
unreachable
73: ; preds = %59
%74 = call i32 (...) @start_color()
%75 = call i32 (...) @use_default_colors()
store i16 0, i16* %13
store i16 0, i16* %14
br label %76
76: ; preds = %100, %73
%77 = load i16, i16* %14
%78 = sext i16 %77 to i32
%79 = load i16, i16* @COLORS
%80 = sext i16 %79 to i32
%81 = icmp slt i32 %78, %80
br i1 %81, label %82, label %103
82: ; preds = %76
store i16 0, i16* %15
br label %83
83: ; preds = %96, %82
%84 = load i16, i16* %15
%85 = sext i16 %84 to i32
%86 = load i16, i16* @COLORS
%87 = sext i16 %86 to i32
%88 = icmp slt i32 %85, %87
br i1 %88, label %89, label %99
89: ; preds = %83
%90 = load i16, i16* %13
%91 = add i16 %90, 1
store i16 %91, i16* %13
%92 = sext i16 %90 to i32
%93 = load i16, i16* %14
%94 = load i16, i16* %15
%95 = call i32 @init_pair(i32 %92, i16 signext %93, i16 signext %94)
br label %96
96: ; preds = %89
%97 = load i16, i16* %15
%98 = add i16 %97, 1
store i16 %98, i16* %15
br label %83
99: ; preds = %83
br label %100
100: ; preds = %99
%101 = load i16, i16* %14
%102 = add i16 %101, 1
store i16 %102, i16* %14
br label %76
103: ; preds = %76
br label %104
104: ; preds = %103
%105 = call i32 (...) @clear()
%106 = call i32 (...) @noecho()
%107 = call i32 (...) @cbreak()
%108 = load i32, i32* @FALSE
%109 = call i32 @curs_set(i32 %108)
%110 = call i32 (...) @nonl()
%111 = load i32*, i32** %6
%112 = load i32, i32* @TRUE
%113 = call i32 @keypad(i32* %111, i32 %112)
%114 = load i32, i32* %9
%115 = load i32, i32* %8
%116 = call i32 @print_header(i32 %114, i32 %115)
%117 = load i32, i32* %10
%118 = load i8, i8* %12
%119 = call i32 @print_tree(i32 %117, i8 signext %118)
%120 = load i32, i32* %10
%121 = load i32, i32* %11
%122 = load i8, i8* %12
%123 = call i32 @print_trunk(i32 %120, i32 %121, i8 signext %122)
%124 = load i32, i32* %9
%125 = load i32, i32* %10
%126 = load i32, i32* %11
%127 = call i32 @print_footer(i32 %124, i32 %125, i32 %126)
br label %128
128: ; preds = %189, %104
%129 = call i32 (...) @getch()
store i32 %129, i32* %7
%130 = icmp ne i32 %129, 113
br i1 %130, label %131, label %205
131: ; preds = %128
%132 = load i32, i32* %7
switch i32 %132, label %189 [
i32 48, label %133
i32 49, label %133
i32 50, label %133
i32 51, label %133
i32 52, label %133
i32 53, label %133
i32 54, label %133
i32 55, label %133
i32 56, label %133
i32 57, label %133
i32 128, label %138
i32 131, label %160
i32 129, label %177
i32 130, label %182
i32 102, label %187
i32 70, label %187
i32 104, label %188
i32 72, label %188
]
133: ; preds = %131, %131, %131, %131, %131, %131, %131, %131, %131, %131
%134 = load i32, i32* %7
%135 = sub nsw i32 %134, 48
%136 = call i32 @COLOR_PAIR(i32 %135)
%137 = call i32 @attrset(i32 %136)
br label %189
138: ; preds = %131
%139 = load i32, i32* %10
%140 = add nsw i32 %139, 1
store i32 %140, i32* %10
%141 = load i32, i32* %10
%142 = sitofp i32 %141 to double
%143 = fdiv double %142, 3.236060e+00
%144 = fptosi double %143 to i32
store i32 %144, i32* %11
%145 = load i32, i32* %10
%146 = load i32, i32* %11
%147 = add nsw i32 %145, %146
%148 = add nsw i32 %147, 1
%149 = load i32, i32* %9
%150 = sub nsw i32 %149, 1
%151 = icmp sgt i32 %148, %150
br i1 %151, label %152, label %159
152: ; preds = %138
%153 = load i32, i32* %10
%154 = sub nsw i32 %153, 1
store i32 %154, i32* %10
%155 = load i32, i32* %10
%156 = sitofp i32 %155 to double
%157 = fdiv double %156, 3.236060e+00
%158 = fptosi double %157 to i32
store i32 %158, i32* %11
br label %159
159: ; preds = %152, %138
br label %189
160: ; preds = %131
%161 = load i32, i32* %10
%162 = sub nsw i32 %161, 1
store i32 %162, i32* %10
%163 = load i32, i32* %10
%164 = sitofp i32 %163 to double
%165 = fdiv double %164, 3.236060e+00
%166 = fptosi double %165 to i32
store i32 %166, i32* %11
%167 = load i32, i32* %10
%168 = load i32, i32* %11
%169 = sub nsw i32 %167, %168
%170 = icmp slt i32 %169, 1
br i1 %170, label %171, label %176
171: ; preds = %160
store i32 1, i32* %10
%172 = load i32, i32* %10
%173 = sitofp i32 %172 to double
%174 = fdiv double %173, 3.236060e+00
%175 = fptosi double %174 to i32
store i32 %175, i32* %11
br label %176
176: ; preds = %171, %160
br label %189
177: ; preds = %131
%178 = load i32, i32* @A_REVERSE
%179 = load i32, i32* @A_BLINK
%180 = or i32 %178, %179
%181 = call i32 @attron(i32 %180)
br label %189
182: ; preds = %131
%183 = load i32, i32* @A_REVERSE
%184 = load i32, i32* @A_BLINK
%185 = or i32 %183, %184
%186 = call i32 @attroff(i32 %185)
br label %189
187: ; preds = %131, %131
store i8 0, i8* %12
br label %189
188: ; preds = %131, %131
store i8 1, i8* %12
br label %189
189: ; preds = %131, %188, %187, %182, %177, %176, %159, %133
%190 = call i32 (...) @erase()
%191 = load i32, i32* %9
%192 = load i32, i32* %8
%193 = call i32 @print_header(i32 %191, i32 %192)
%194 = load i32, i32* %10
%195 = load i8, i8* %12
%196 = call i32 @print_tree(i32 %194, i8 signext %195)
%197 = load i32, i32* %10
%198 = load i32, i32* %11
%199 = load i8, i8* %12
%200 = call i32 @print_trunk(i32 %197, i32 %198, i8 signext %199)
%201 = load i32, i32* %9
%202 = load i32, i32* %10
%203 = load i32, i32* %11
%204 = call i32 @print_footer(i32 %201, i32 %202, i32 %203)
br label %128
205: ; preds = %128
%206 = load i32*, i32** %6
%207 = call i32 @delwin(i32* %206)
%208 = call i32 (...) @endwin()
%209 = call i32 (...) @refresh()
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"half\00"
@.str.1 = [5 x i8] c"full\00"
@stderr = global i32 0
@.str.2 = [29 x i8] c"Error initialising ncurses.\0A\00"
@.str.3 = [38 x i8] c"Your terminal does not support color\0A\00"
@COLORS = global i16 0
@FALSE = global i32 0
@TRUE = global i32 0
@A_REVERSE = global i32 0
@A_BLINK = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
br label %7
7: ; preds = %4, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @atoi(i8* %9)
%11 = sitofp i32 %10 to double
%12 = fdiv double %11, 3.236060e+00
%13 = fptosi double %12 to i32
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %15, i32 4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %25, label %18
18: ; preds = %7
%19 = load i8*, i8** %14
%20 = tail call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32 4)
%21 = icmp eq i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i8*, i8** %1
%24 = tail call i32 @usage(i8* %23)
br label %25
25: ; preds = %18, %7, %22
%26 = phi i8 [ -1, %22 ], [ 1, %7 ], [ 0, %18 ]
%27 = tail call i32* (...) @initscr()
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%32 = tail call i32 @exit(i32 -1)
unreachable
33: ; preds = %25
%34 = tail call i32 @getmaxyx(i32* %27, i32 0, i32 0)
%35 = tail call i32 (...) @has_colors()
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %33
%38 = tail call i32 @delwin(i32* %27)
%39 = tail call i32 (...) @endwin()
%40 = load i32, i32* @stderr
%41 = tail call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%42 = tail call i32 @exit(i32 -1)
unreachable
43: ; preds = %33
%44 = tail call i32 (...) @start_color()
%45 = tail call i32 (...) @use_default_colors()
%46 = load i16, i16* @COLORS
%47 = icmp sgt i16 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %43, %66
%49 = phi i16 [ %67, %66 ], [ %46, %43 ]
%50 = phi i16 [ %69, %66 ], [ 0, %43 ]
%51 = phi i16 [ %68, %66 ], [ 0, %43 ]
%52 = icmp sgt i16 %49, 0
br i1 %52, label %71, label %66
53: ; preds = %66, %43
%54 = tail call i32 (...) @clear()
%55 = tail call i32 (...) @noecho()
%56 = tail call i32 (...) @cbreak()
%57 = load i32, i32* @FALSE
%58 = tail call i32 @curs_set(i32 %57)
%59 = tail call i32 (...) @nonl()
%60 = load i32, i32* @TRUE
%61 = tail call i32 @keypad(i32* %27, i32 %60)
%62 = tail call i32 @print_header(i32 0, i32 0)
%63 = tail call i32 @print_tree(i32 %10, i8 signext %26)
%64 = tail call i32 @print_trunk(i32 %10, i32 %13, i8 signext %26)
%65 = tail call i32 @print_footer(i32 0, i32 %10, i32 %13)
br label %80
66: ; preds = %71, %48
%67 = phi i16 [ %49, %48 ], [ %78, %71 ]
%68 = phi i16 [ %51, %48 ], [ %74, %71 ]
%69 = add nuw nsw i16 %50, 1
%70 = icmp slt i16 %69, %67
br i1 %70, label %48, label %53
71: ; preds = %48, %71
%72 = phi i16 [ %77, %71 ], [ 0, %48 ]
%73 = phi i16 [ %74, %71 ], [ %51, %48 ]
%74 = add i16 %73, 1
%75 = sext i16 %73 to i32
%76 = tail call i32 @init_pair(i32 %75, i16 signext %50, i16 signext %72)
%77 = add nuw nsw i16 %72, 1
%78 = load i16, i16* @COLORS
%79 = icmp slt i16 %77, %78
br i1 %79, label %71, label %66
80: ; preds = %120, %53
%81 = phi i32 [ %10, %53 ], [ %121, %120 ]
%82 = phi i32 [ %13, %53 ], [ %122, %120 ]
%83 = phi i8 [ %26, %53 ], [ %123, %120 ]
%84 = tail call i32 (...) @getch()
switch i32 %84, label %120 [
i32 113, label %129
i32 48, label %85
i32 49, label %85
i32 50, label %85
i32 51, label %85
i32 52, label %85
i32 53, label %85
i32 54, label %85
i32 55, label %85
i32 56, label %85
i32 57, label %85
i32 128, label %89
i32 131, label %100
i32 129, label %108
i32 130, label %113
i32 102, label %118
i32 70, label %118
i32 104, label %119
i32 72, label %119
]
85: ; preds = %80, %80, %80, %80, %80, %80, %80, %80, %80, %80
%86 = add nsw i32 %84, -48
%87 = tail call i32 @COLOR_PAIR(i32 %86)
%88 = tail call i32 @attrset(i32 %87)
br label %120
89: ; preds = %80
%90 = add nsw i32 %81, 1
%91 = sitofp i32 %90 to double
%92 = fdiv double %91, 3.236060e+00
%93 = fptosi double %92 to i32
%94 = add nsw i32 %90, %93
%95 = icmp sgt i32 %94, -2
br i1 %95, label %96, label %120
96: ; preds = %89
%97 = sitofp i32 %81 to double
%98 = fdiv double %97, 3.236060e+00
%99 = fptosi double %98 to i32
br label %120
100: ; preds = %80
%101 = add nsw i32 %81, -1
%102 = sitofp i32 %101 to double
%103 = fdiv double %102, 3.236060e+00
%104 = fptosi double %103 to i32
%105 = icmp sgt i32 %101, %104
%106 = select i1 %105, i32 %101, i32 1
%107 = select i1 %105, i32 %104, i32 0
br label %120
108: ; preds = %80
%109 = load i32, i32* @A_REVERSE
%110 = load i32, i32* @A_BLINK
%111 = or i32 %110, %109
%112 = tail call i32 @attron(i32 %111)
br label %120
113: ; preds = %80
%114 = load i32, i32* @A_REVERSE
%115 = load i32, i32* @A_BLINK
%116 = or i32 %115, %114
%117 = tail call i32 @attroff(i32 %116)
br label %120
118: ; preds = %80, %80
br label %120
119: ; preds = %80, %80
br label %120
120: ; preds = %100, %80, %89, %96, %119, %118, %113, %108, %85
%121 = phi i32 [ %81, %119 ], [ %81, %118 ], [ %81, %113 ], [ %81, %108 ], [ %81, %96 ], [ %90, %89 ], [ %81, %85 ], [ %81, %80 ], [ %106, %100 ]
%122 = phi i32 [ %82, %119 ], [ %82, %118 ], [ %82, %113 ], [ %82, %108 ], [ %99, %96 ], [ %93, %89 ], [ %82, %85 ], [ %82, %80 ], [ %107, %100 ]
%123 = phi i8 [ 1, %119 ], [ 0, %118 ], [ %83, %113 ], [ %83, %108 ], [ %83, %96 ], [ %83, %89 ], [ %83, %85 ], [ %83, %80 ], [ %83, %100 ]
%124 = tail call i32 (...) @erase()
%125 = tail call i32 @print_header(i32 0, i32 0)
%126 = tail call i32 @print_tree(i32 %121, i8 signext %123)
%127 = tail call i32 @print_trunk(i32 %121, i32 %122, i8 signext %123)
%128 = tail call i32 @print_footer(i32 0, i32 %121, i32 %122)
br label %80
129: ; preds = %80
%130 = tail call i32 @delwin(i32* %27)
%131 = tail call i32 (...) @endwin()
%132 = tail call i32 (...) @refresh()
ret i32 0
}