#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*/ TRUE;
int /*<<< orphan*/ has_colors();
int /*<<< orphan*/ init_colors();
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ keypad(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ start_color();
int /*<<< orphan*/ stdscr;
int /*<<< orphan*/ ui_destroy();
bool ui_init() {
  initscr();
  if (!has_colors()) {
    ui_destroy();
    printf("Your terminal doesn't support color. Sad smiley :(\n");
    return false;
  }
  start_color();
  init_colors();
  keypad(stdscr, TRUE);
  return true;
}


x86 assembly (clang, -O0):
<ui_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1070 <initscr@plt>
mov    $0x0,%al
call   1030 <has_colors@plt>
cmp    $0x0,%eax
jne    11ae <ui_init+0x3e>
mov    $0x0,%al
call   1040 <ui_destroy@plt>
lea    0xe63(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11da <ui_init+0x6a>
mov    $0x0,%al
call   1080 <start_color@plt>
mov    $0x0,%al
call   1090 <init_colors@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
call   1060 <keypad@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ui_init>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <initscr@plt>
xor    %eax,%eax
call   1040 <has_colors@plt>
test   %eax,%eax
je     11b1 <ui_init+0x41>
xor    %eax,%eax
call   1080 <start_color@plt>
xor    %eax,%eax
call   1090 <init_colors@plt>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
call   1060 <keypad@plt>
mov    $0x1,%ebx
jmp    11c4 <ui_init+0x54>
xor    %eax,%eax
call   1050 <ui_destroy@plt>
lea    0xe41(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [52 x i8] c"Your terminal doesn't support color. Sad smiley :(\0A\00"
@stdscr = global i32 0
@TRUE = global i32 0
define i32 @ui_init() {
%1 = alloca i32
%2 = call i32 (...) @initscr()
%3 = call i32 (...) @has_colors()
%4 = icmp ne i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 (...) @ui_destroy()
%7 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %14
8: ; preds = %0
%9 = call i32 (...) @start_color()
%10 = call i32 (...) @init_colors()
%11 = load i32, i32* @stdscr
%12 = load i32, i32* @TRUE
%13 = call i32 @keypad(i32 %11, i32 %12)
store i32 1, i32* %1
br label %14
14: ; preds = %8, %5
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
@stdscr = global i32 0
@TRUE = global i32 0
@str = [51 x i8] c"Your terminal doesn't support color. Sad smiley :(\00"
define i32 @ui_init() {
%1 = tail call i32 (...) @initscr()
%2 = tail call i32 (...) @has_colors()
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 (...) @ui_destroy()
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
br label %13
7: ; preds = %0
%8 = tail call i32 (...) @start_color()
%9 = tail call i32 (...) @init_colors()
%10 = load i32, i32* @stdscr
%11 = load i32, i32* @TRUE
%12 = tail call i32 @keypad(i32 %10, i32 %11)
br label %13
13: ; preds = %7, %4
%14 = phi i32 [ 1, %7 ], [ 0, %4 ]
ret i32 %14
}