#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 uint8_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ curs_set(int /*<<< orphan*/);
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ getmaxyx(int /*<<< orphan*/, int, int);
scalar_t__ has_colors();
int /*<<< orphan*/ init_pair(int, int, int);
int /*<<< orphan*/ *initscr();
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ start_color();
int /*<<< orphan*/ stdscr;
uint8_t gfxInit() {
  uint16_t f, b, width = 0, height = 0;
  if (initscr() == NULL)
    return 1;
  if (has_colors() == 0)
    return 3;
  getmaxyx(stdscr, height, width);
  if (height < 10 || width < 40 || height > width) {
    endwin();
    return 2;
  }
  curs_set(0);
  noecho();
  start_color();
  for (f = 0; f < 8; f++)
    for (b = 0; b < 8; b++)
      init_pair(f * 8 + b, f, b);
  return 0;
}


x86 assembly (clang, -O0):
<gfxInit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1050 <initscr@plt>
cmp    $0x0,%rax
jne    11b3 <gfxInit+0x33>
movl   $0x1,-0x4(%rbp)
jmp    128a <gfxInit+0x10a>
mov    $0x0,%al
call   1030 <has_colors@plt>
cmp    $0x0,%rax
jne    11d0 <gfxInit+0x50>
movl   $0x3,-0x4(%rbp)
jmp    128a <gfxInit+0x10a>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1070 <getmaxyx@plt>
cmpl   $0xa,-0x14(%rbp)
jl     1204 <gfxInit+0x84>
cmpl   $0x28,-0x10(%rbp)
jl     1204 <gfxInit+0x84>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    1217 <gfxInit+0x97>
mov    $0x0,%al
call   1080 <endwin@plt>
movl   $0x2,-0x4(%rbp)
jmp    128a <gfxInit+0x10a>
xor    %edi,%edi
call   10a0 <curs_set@plt>
mov    $0x0,%al
call   1090 <noecho@plt>
mov    $0x0,%al
call   1060 <start_color@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x8,-0x8(%rbp)
jge    1283 <gfxInit+0x103>
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    1270 <gfxInit+0xf0>
mov    -0x8(%rbp),%edi
shl    $0x3,%edi
add    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <init_pair@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1244 <gfxInit+0xc4>
jmp    1275 <gfxInit+0xf5>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1233 <gfxInit+0xb3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gfxInit>:
push   %rax
xor    %eax,%eax
call   1040 <initscr@plt>
test   %rax,%rax
je     1179 <gfxInit+0x39>
xor    %eax,%eax
call   1030 <has_colors@plt>
test   %rax,%rax
je     1180 <gfxInit+0x40>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <getmaxyx@plt>
xor    %eax,%eax
call   1060 <endwin@plt>
mov    $0x2,%eax
pop    %rcx
ret
mov    $0x1,%eax
pop    %rcx
ret
mov    $0x3,%eax
pop    %rcx
ret

LLVM IR (-O0):
@stdscr = global i32 0
define i32 @gfxInit() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i32* (...) @initscr()
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %9
8: ; preds = %0
store i32 1, i32* %1
br label %56
9: ; preds = %0
%10 = call i64 (...) @has_colors()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 3, i32* %1
br label %56
13: ; preds = %9
%14 = load i32, i32* @stdscr
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = call i32 @getmaxyx(i32 %14, i32 %15, i32 %16)
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 10
br i1 %19, label %27, label %20
20: ; preds = %13
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 40
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = load i32, i32* %5
%25 = load i32, i32* %4
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %23, %20, %13
%28 = call i32 (...) @endwin()
store i32 2, i32* %1
br label %56
29: ; preds = %23
%30 = call i32 @curs_set(i32 0)
%31 = call i32 (...) @noecho()
%32 = call i32 (...) @start_color()
store i32 0, i32* %2
br label %33
33: ; preds = %52, %29
%34 = load i32, i32* %2
%35 = icmp slt i32 %34, 8
br i1 %35, label %36, label %55
36: ; preds = %33
store i32 0, i32* %3
br label %37
37: ; preds = %48, %36
%38 = load i32, i32* %3
%39 = icmp slt i32 %38, 8
br i1 %39, label %40, label %51
40: ; preds = %37
%41 = load i32, i32* %2
%42 = mul nsw i32 %41, 8
%43 = load i32, i32* %3
%44 = add nsw i32 %42, %43
%45 = load i32, i32* %2
%46 = load i32, i32* %3
%47 = call i32 @init_pair(i32 %44, i32 %45, i32 %46)
br label %48
48: ; preds = %40
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %3
br label %37
51: ; preds = %37
br label %52
52: ; preds = %51
%53 = load i32, i32* %2
%54 = add nsw i32 %53, 1
store i32 %54, i32* %2
br label %33
55: ; preds = %33
store i32 0, i32* %1
br label %56
56: ; preds = %55, %27, %12, %8
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@stdscr = global i32 0
define i32 @gfxInit() {
%1 = tail call i32* (...) @initscr()
%2 = icmp eq i32* %1, null
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call i64 (...) @has_colors()
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = load i32, i32* @stdscr
%8 = tail call i32 @getmaxyx(i32 %7, i32 0, i32 0)
%9 = tail call i32 (...) @endwin()
br label %10
10: ; preds = %3, %0, %6
%11 = phi i32 [ 2, %6 ], [ 1, %0 ], [ 3, %3 ]
ret i32 %11
}