/* Generated by Nim Compiler v1.6.14 */
#define NIM_INTBITS 64

#include "nimbase.h"
#include <io.h>
#include <string.h>
#include <stdio.h>
#undef LANGUAGE_C
#undef MIPSEB
#undef MIPSEL
#undef PPC
#undef R3000
#undef R4000
#undef i386
#undef linux
#undef mips
#undef near
#undef far
#undef powerpc
#undef unix
#define nimfr_(x, y)
#define nimln_(x, y)
typedef struct tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg;
typedef struct TNimType TNimType;
typedef struct TNimNode TNimNode;
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct tyObject_CONSOLE_SCREEN_BUFFER_INFO__Xb69a1MvqxkFXnw789aBguWw tyObject_CONSOLE_SCREEN_BUFFER_INFO__Xb69a1MvqxkFXnw789aBguWw;
typedef struct tyObject_COORD__D9cXjc0OthppjV9a2UJc9al0g tyObject_COORD__D9cXjc0OthppjV9a2UJc9al0g;
typedef struct tyObject_SMALL_RECT__nSdmS9czNHJ1PSwdMrQkYXA tyObject_SMALL_RECT__nSdmS9czNHJ1PSwdMrQkYXA;
typedef struct tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g;
typedef struct tyObject_CellSeq__nav876ELHgxScHhs30CKiA tyObject_CellSeq__nav876ELHgxScHhs30CKiA;
typedef struct tyObject_GcHeap__ZRn9bWCksoiGwT2drZZzyWQ tyObject_GcHeap__ZRn9bWCksoiGwT2drZZzyWQ;
typedef struct tyObject_GcStack__qFeGMKlnq6c9cTM2vPWycQQ tyObject_GcStack__qFeGMKlnq6c9cTM2vPWycQQ;
typedef struct tyObject_MemRegion__6QRscFDo4mEwbg9aL76vDGQ tyObject_MemRegion__6QRscFDo4mEwbg9aL76vDGQ;
typedef struct tyObject_SmallChunk__eUrTKmsk1Dqt5tm2WUT2Lw tyObject_SmallChunk__eUrTKmsk1Dqt5tm2WUT2Lw;
typedef struct tyObject_BigChunk__39bC3HTk2w4NGDjG74oNjmA tyObject_BigChunk__39bC3HTk2w4NGDjG74oNjmA;
typedef struct tyObject_LLChunk__Fjkr5Ya6Zl0UoUGxG047hA tyObject_LLChunk__Fjkr5Ya6Zl0UoUGxG047hA;
typedef struct tyObject_IntSet__WrQriiGmHk59cB1lNPtGo6A tyObject_IntSet__WrQriiGmHk59cB1lNPtGo6A;
typedef struct tyObject_Trunk__Ju1AURWHenTn3cJwAjbUhg tyObject_Trunk__Ju1AURWHenTn3cJwAjbUhg;
typedef struct tyObject_AvlNode__aGkK1t9a0WoXjpugXR6FWpw tyObject_AvlNode__aGkK1t9a0WoXjpugXR6FWpw;
typedef struct tyObject_HeapLinks__5IkCDh5QlsYpsfEMJf6zNw tyObject_HeapLinks__5IkCDh5QlsYpsfEMJf6zNw;
typedef struct tyTuple__p2vAp9cQ6YrpDq9cI3XzEDWA tyTuple__p2vAp9cQ6YrpDq9cI3XzEDWA;
typedef struct tyObject_GcStat__OG9ams3mtFJyICkjTOHbc9bg tyObject_GcStat__OG9ams3mtFJyICkjTOHbc9bg;
typedef struct tyObject_CellSet__A0mJvGLunfUxGkLUtesjdA tyObject_CellSet__A0mJvGLunfUxGkLUtesjdA;
typedef struct tyObject_PageDesc__N7tjEodqPVJaQ6oKQW8YfQ tyObject_PageDesc__N7tjEodqPVJaQ6oKQW8YfQ;
struct tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg {
NIM_BOOL trueColorIsSupported;
NIM_BOOL trueColorIsEnabled;
NIM_BOOL fgSetColor;
NI hStdout;
NI hStderr;
NI16 oldStdoutAttr;
NI16 oldStderrAttr;
};
typedef NU8 tyEnum_TNimKind__pspQAsqJLrw3jEKBD9bxmyQ;
typedef NU8 tySet_tyEnum_TNimTypeFlag__Yt5hq6z2IoHhKZrzIVrc1w;
typedef N_NIMCALL_PTR(void, tyProc__ojoeKfW4VYIm36I9cpDTQIg) (void* p, NI op);
typedef N_NIMCALL_PTR(void*, tyProc__WSm2xU5ARYv9aAR4l0z9c9auQ) (void* p);
struct TNimType {
NI size;
NI align;
tyEnum_TNimKind__pspQAsqJLrw3jEKBD9bxmyQ kind;
tySet_tyEnum_TNimTypeFlag__Yt5hq6z2IoHhKZrzIVrc1w flags;
TNimType* base;
TNimNode* node;
void* finalizer;
tyProc__ojoeKfW4VYIm36I9cpDTQIg marker;
tyProc__WSm2xU5ARYv9aAR4l0z9c9auQ deepcopy;
};
typedef NU8 tyEnum_TNimNodeKind__rrp49bl1h9aEkXfXp9bNg0yZw;
struct TNimNode {
tyEnum_TNimNodeKind__rrp49bl1h9aEkXfXp9bNg0yZw kind;
NI offset;
TNimType* typ;
NCSTRING name;
NI len;
TNimNode** sons;
};
typedef N_NIMCALL_PTR(void, tyProc__T4eqaYlFJYZUv9aG9b1TV0bQ) (void);
typedef NU16 tySet_tyEnum_Style__IfhGTpNOgg3EytKq9c3Vnwg;
typedef N_STDCALL_PTR(NI, tyProc__zP2zGemcuVRvOUE82f9a0Pw) (NI32 nStdHandle);
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
typedef N_STDCALL_PTR(NI32, tyProc__oew1DfaGl5XhHmnBK0HYXQ) (NI hSourceProcessHandle, NI hSourceHandle, NI hTargetProcessHandle, NI* lpTargetHandle, NI32 dwDesiredAccess, NI32 bInheritHandle, NI32 dwOptions);
typedef N_STDCALL_PTR(NI, tyProc__uryidYWkntM7ddjZSyxvyQ) (void);
struct tyObject_COORD__D9cXjc0OthppjV9a2UJc9al0g {
NI16 x;
NI16 y;
};
struct tyObject_SMALL_RECT__nSdmS9czNHJ1PSwdMrQkYXA {
NI16 left;
NI16 top;
NI16 right;
NI16 bottom;
};
struct tyObject_CONSOLE_SCREEN_BUFFER_INFO__Xb69a1MvqxkFXnw789aBguWw {
tyObject_COORD__D9cXjc0OthppjV9a2UJc9al0g dwSize;
tyObject_COORD__D9cXjc0OthppjV9a2UJc9al0g dwCursorPosition;
NI16 wAttributes;
tyObject_SMALL_RECT__nSdmS9czNHJ1PSwdMrQkYXA srWindow;
tyObject_COORD__D9cXjc0OthppjV9a2UJc9al0g dwMaximumWindowSize;
};
typedef N_STDCALL_PTR(NI32, tyProc__EmkmlYX9crhgylsTGNg9aF5Q) (NI hConsoleOutput, tyObject_CONSOLE_SCREEN_BUFFER_INFO__Xb69a1MvqxkFXnw789aBguWw* lpConsoleScreenBufferInfo);
struct tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g {
NI refcount;
TNimType* typ;
};
struct tyObject_GcStack__qFeGMKlnq6c9cTM2vPWycQQ {
void* bottom;
};
struct tyObject_CellSeq__nav876ELHgxScHhs30CKiA {
NI len;
NI cap;
tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g** d;
};
typedef tyObject_SmallChunk__eUrTKmsk1Dqt5tm2WUT2Lw* tyArray__1eFxjkcKGHnofywkmCV8oQ[256];
typedef NU32 tyArray__BHbOSqU1t9b3Gt7K2c6fQig[24];
typedef tyObject_BigChunk__39bC3HTk2w4NGDjG74oNjmA* tyArray__KxTmKT9a3kTkdwYfqXhEYSw[32];
typedef tyArray__KxTmKT9a3kTkdwYfqXhEYSw tyArray__ATT5LBefmjy9bg8ApRmg3rw[24];
typedef tyObject_Trunk__Ju1AURWHenTn3cJwAjbUhg* tyArray__RxhBwkGQwTHLKhoK685Xfg[256];
struct tyObject_IntSet__WrQriiGmHk59cB1lNPtGo6A {
tyArray__RxhBwkGQwTHLKhoK685Xfg data;
};
typedef tyObject_AvlNode__aGkK1t9a0WoXjpugXR6FWpw* tyArray__DrxDrI9bg9apB70ydOoNZrWw[2];
struct tyObject_AvlNode__aGkK1t9a0WoXjpugXR6FWpw {
tyArray__DrxDrI9bg9apB70ydOoNZrWw link;
NI key;
NI upperBound;
NI level;
};
struct tyTuple__p2vAp9cQ6YrpDq9cI3XzEDWA {
tyObject_BigChunk__39bC3HTk2w4NGDjG74oNjmA* Field0;
NI Field1;
};
typedef tyTuple__p2vAp9cQ6YrpDq9cI3XzEDWA tyArray__wsokuoa9bVBSU4gPLKbFaaw[30];
struct tyObject_HeapLinks__5IkCDh5QlsYpsfEMJf6zNw {
NI len;
tyArray__wsokuoa9bVBSU4gPLKbFaaw chunks;
tyObject_HeapLinks__5IkCDh5QlsYpsfEMJf6zNw* next;
};
struct tyObject_MemRegion__6QRscFDo4mEwbg9aL76vDGQ {
NI minLargeObj;
NI maxLargeObj;
tyArray__1eFxjkcKGHnofywkmCV8oQ freeSmallChunks;
NU32 flBitmap;
tyArray__BHbOSqU1t9b3Gt7K2c6fQig slBitmap;
tyArray__ATT5LBefmjy9bg8ApRmg3rw matrix;
tyObject_LLChunk__Fjkr5Ya6Zl0UoUGxG047hA* llmem;
NI currMem;
NI maxMem;
NI freeMem;
NI occ;
NI lastSize;
tyObject_IntSet__WrQriiGmHk59cB1lNPtGo6A chunkStarts;
tyObject_AvlNode__aGkK1t9a0WoXjpugXR6FWpw* root;
tyObject_AvlNode__aGkK1t9a0WoXjpugXR6FWpw* deleted;
tyObject_AvlNode__aGkK1t9a0WoXjpugXR6FWpw* last;
tyObject_AvlNode__aGkK1t9a0WoXjpugXR6FWpw* freeAvlNodes;
NIM_BOOL locked;
NIM_BOOL blockChunkSizeIncrease;
NI nextChunkSize;
tyObject_AvlNode__aGkK1t9a0WoXjpugXR6FWpw bottomData;
tyObject_HeapLinks__5IkCDh5QlsYpsfEMJf6zNw heapLinks;
};
struct tyObject_GcStat__OG9ams3mtFJyICkjTOHbc9bg {
NI stackScans;
NI cycleCollections;
NI maxThreshold;
NI maxStackSize;
NI maxStackCells;
NI cycleTableSize;
NI64 maxPause;
};
struct tyObject_CellSet__A0mJvGLunfUxGkLUtesjdA {
NI counter;
NI max;
tyObject_PageDesc__N7tjEodqPVJaQ6oKQW8YfQ* head;
tyObject_PageDesc__N7tjEodqPVJaQ6oKQW8YfQ** data;
};
struct tyObject_GcHeap__ZRn9bWCksoiGwT2drZZzyWQ {
tyObject_GcStack__qFeGMKlnq6c9cTM2vPWycQQ stack;
NI cycleThreshold;
NI zctThreshold;
tyObject_CellSeq__nav876ELHgxScHhs30CKiA zct;
tyObject_CellSeq__nav876ELHgxScHhs30CKiA decStack;
tyObject_CellSeq__nav876ELHgxScHhs30CKiA tempStack;
NI recGcLock;
tyObject_MemRegion__6QRscFDo4mEwbg9aL76vDGQ region;
tyObject_GcStat__OG9ams3mtFJyICkjTOHbc9bg stat;
tyObject_CellSet__A0mJvGLunfUxGkLUtesjdA marked;
tyObject_CellSeq__nav876ELHgxScHhs30CKiA additionalRoots;
NI gcThreadId;
};
typedef NU8 tyEnum_Style__IfhGTpNOgg3EytKq9c3Vnwg;
typedef N_STDCALL_PTR(NI32, tyProc__oPCjp4xTgEl9a8fqSzOv8lw) (NI hConsoleOutput, NI16 wAttributes);
typedef NU8 tyEnum_ForegroundColor__avKgWVVKiIc89c9aKDsFLd7w;
typedef NI tyArray__I3aEt72W7FcrU0RRtOwSOA[10];
static N_NIMCALL(void, Marker_tyRef__VTNB4axZc9aSVvMADQfFQjw)(void* p, NI op);
N_LIB_PRIVATE N_NIMCALL(void, nimGCvisit)(void* d, NI op);
static N_NIMCALL(void, TM__CN3raB9atujkEiPpxYAdlgQ_3)(void);
N_LIB_PRIVATE N_NIMCALL(void, nimRegisterThreadLocalMarker)(tyProc__T4eqaYlFJYZUv9aG9b1TV0bQ markerProc);
N_LIB_PRIVATE N_NIMCALL(int, getFileHandle__systemZio_248)(FILE* f);
static N_INLINE(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg*, getTerminal__pureZterminal_26)(void);
N_LIB_PRIVATE N_NIMCALL(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg*, newTerminal__pureZterminal_16)(void);
N_LIB_PRIVATE N_NOINLINE(void*, newObj)(TNimType* typ, NI size);
N_LIB_PRIVATE N_NIMCALL(void, initTerminal__pureZterminal_191)(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg* term);
N_LIB_PRIVATE N_NIMCALL(void*, nimLoadLibrary)(NimStringDesc* path);
N_LIB_PRIVATE N_NIMCALL(void, nimLoadLibraryError)(NimStringDesc* path);
N_LIB_PRIVATE N_NIMCALL(void*, nimGetProcAddr)(void* lib, NCSTRING name);
N_LIB_PRIVATE N_NIMCALL(NI16, getAttributes__pureZterminal_187)(NI h);
static N_INLINE(void, nimZeroMem)(void* p, NI size);
static N_INLINE(void, nimSetMem__systemZmemory_7)(void* a, int v, NI size);
static N_INLINE(void, asgnRef)(void** dest, void* src);
static N_INLINE(void, incRef__system_5374)(tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g* c);
static N_INLINE(NI, pluspercent___system_696)(NI x, NI y);
static N_INLINE(tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g*, usrToCell__system_5336)(void* usr);
static N_INLINE(NI, minuspercent___system_716)(NI x, NI y);
static N_INLINE(void, decRef__system_5381)(tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g* c);
static N_INLINE(NIM_BOOL, ltpercent___system_1005)(NI x, NI y);
static N_INLINE(void, rtlAddZCT__system_5379)(tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g* c);
N_LIB_PRIVATE N_NOINLINE(void, addZCT__system_5330)(tyObject_CellSeq__nav876ELHgxScHhs30CKiA* s, tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g* c);
N_LIB_PRIVATE N_NIMCALL(NI16, toU16__system_301)(NI x);
N_LIB_PRIVATE TNimType NTIpterminal58objecttype__UsCBTY9apiEsmVq1ekVwEMg_;
extern TNimType NTIbool__VaVACK0bpYmqIQ0mKcHfQQ_;
extern TNimType NTIint__rR5Bzr1D5krxoo1NcNyeMA_;
extern TNimType NTIint4954__kDPg4wXyR8DDyA0MeEjIsw_;
N_LIB_PRIVATE TNimType NTIpterminal__VTNB4axZc9aSVvMADQfFQjw_;
STRING_LITERAL(TM__CN3raB9atujkEiPpxYAdlgQ_6, "kernel32", 8);
STRING_LITERAL(TM__CN3raB9atujkEiPpxYAdlgQ_7, "kernel32", 8);
N_LIB_PRIVATE NIM_CONST tyArray__I3aEt72W7FcrU0RRtOwSOA lookup__pureZterminal_515 = {((NI) 0),
((NI) 4),
((NI) 2),
((NI) 6),
((NI) 1),
((NI) 5),
((NI) 3),
((NI) 7),
((NI) 0),
((NI) 0)}
;
N_LIB_PRIVATE tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg* gTerm__pureZterminal_15;
N_LIB_PRIVATE NI16 defaultForegroundColor__pureZterminal_501 = ((NI16) -1);
N_LIB_PRIVATE NI16 defaultBackgroundColor__pureZterminal_502 = ((NI16) -1);
extern tyProc__zP2zGemcuVRvOUE82f9a0Pw Dl_1325400227_;
static void* TM__CN3raB9atujkEiPpxYAdlgQ_4;
tyProc__oew1DfaGl5XhHmnBK0HYXQ Dl_1761607747_;
tyProc__uryidYWkntM7ddjZSyxvyQ Dl_1761607755_;
tyProc__EmkmlYX9crhgylsTGNg9aF5Q Dl_1761607756_;
extern tyObject_GcHeap__ZRn9bWCksoiGwT2drZZzyWQ gch__system_5283;
tyProc__oPCjp4xTgEl9a8fqSzOv8lw Dl_1761607838_;
static N_NIMCALL(void, Marker_tyRef__VTNB4axZc9aSVvMADQfFQjw)(void* p, NI op) {
	tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg* a;
	a = (tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg*)p;
}
static N_NIMCALL(void, TM__CN3raB9atujkEiPpxYAdlgQ_3)(void) {
	nimGCvisit((void*)gTerm__pureZterminal_15, 0);
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, isatty__pureZterminal_649)(FILE* f) {
	NIM_BOOL result;
	int T1_;
	int T2_;
	result = (NIM_BOOL)0;
	T1_ = (int)0;
	T1_ = getFileHandle__systemZio_248(f);
	T2_ = (int)0;
	T2_ = _isatty(T1_);
	result = !((T2_ == ((NI32) 0)));
	return result;
}
static N_INLINE(void, nimSetMem__systemZmemory_7)(void* a, int v, NI size) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memset(a, v, ((size_t) (size)));
}
static N_INLINE(void, nimZeroMem)(void* p, NI size) {
	nimSetMem__systemZmemory_7(p, ((int) 0), size);
}
N_LIB_PRIVATE N_NIMCALL(NI16, getAttributes__pureZterminal_187)(NI h) {
	NI16 result;
	tyObject_CONSOLE_SCREEN_BUFFER_INFO__Xb69a1MvqxkFXnw789aBguWw c;
{	result = (NI16)0;
	nimZeroMem((void*)(&c), sizeof(tyObject_CONSOLE_SCREEN_BUFFER_INFO__Xb69a1MvqxkFXnw789aBguWw));
	{
		NI32 T3_;
		T3_ = (NI32)0;
		T3_ = Dl_1761607756_(h, (&c));
		if (!!((T3_ == ((NI32) 0)))) goto LA4_;
		result = c.wAttributes;
		goto BeforeRet_;
	}
	LA4_: ;
	result = ((NI16) 112);
	goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, initTerminal__pureZterminal_191)(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg* term) {
	NI hStdoutTemp;
	NI hStderrTemp;
	hStdoutTemp = Dl_1325400227_(((NI32) -11));
	{
		NI T3_;
		NI T4_;
		NI32 T5_;
		T3_ = (NI)0;
		T3_ = Dl_1761607755_();
		T4_ = (NI)0;
		T4_ = Dl_1761607755_();
		T5_ = (NI32)0;
		T5_ = Dl_1761607747_(T3_, hStdoutTemp, T4_, (&(*term).hStdout), ((NI32) 0), ((NI32) 1), ((NI32) 2));
		if (!(T5_ == ((NI32) 0))) goto LA6_;
	}
	LA6_: ;
	hStderrTemp = Dl_1325400227_(((NI32) -12));
	{
		NI T10_;
		NI T11_;
		NI32 T12_;
		T10_ = (NI)0;
		T10_ = Dl_1761607755_();
		T11_ = (NI)0;
		T11_ = Dl_1761607755_();
		T12_ = (NI32)0;
		T12_ = Dl_1761607747_(T10_, hStderrTemp, T11_, (&(*term).hStderr), ((NI32) 0), ((NI32) 1), ((NI32) 2));
		if (!(T12_ == ((NI32) 0))) goto LA13_;
	}
	LA13_: ;
	(*term).oldStdoutAttr = getAttributes__pureZterminal_187((*term).hStdout);
	(*term).oldStderrAttr = getAttributes__pureZterminal_187((*term).hStderr);
}
N_LIB_PRIVATE N_NIMCALL(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg*, newTerminal__pureZterminal_16)(void) {
	tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg* result;
	result = NIM_NIL;
	result = (tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg*) newObj((&NTIpterminal__VTNB4axZc9aSVvMADQfFQjw_), sizeof(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg));
	initTerminal__pureZterminal_191(result);
	return result;
}
static N_INLINE(NI, pluspercent___system_696)(NI x, NI y) {
	NI result;
	result = (NI)0;
	result = ((NI) ((NU)((NU64)(((NU) (x))) + (NU64)(((NU) (y))))));
	return result;
}
static N_INLINE(void, incRef__system_5374)(tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g* c) {
	(*c).refcount = pluspercent___system_696((*c).refcount, ((NI) 8));
}
static N_INLINE(NI, minuspercent___system_716)(NI x, NI y) {
	NI result;
	result = (NI)0;
	result = ((NI) ((NU)((NU64)(((NU) (x))) - (NU64)(((NU) (y))))));
	return result;
}
static N_INLINE(tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g*, usrToCell__system_5336)(void* usr) {
	tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g* result;
	NI T1_;
	result = (tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g*)0;
	T1_ = (NI)0;
	T1_ = minuspercent___system_716(((NI) (ptrdiff_t) (usr)), ((NI) 16));
	result = ((tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g*) (T1_));
	return result;
}
static N_INLINE(NIM_BOOL, ltpercent___system_1005)(NI x, NI y) {
	NIM_BOOL result;
	result = (NIM_BOOL)0;
	result = ((NU64)(((NU) (x))) < (NU64)(((NU) (y))));
	return result;
}
static N_INLINE(void, rtlAddZCT__system_5379)(tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g* c) {
	addZCT__system_5330((&gch__system_5283.zct), c);
}
static N_INLINE(void, decRef__system_5381)(tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g* c) {
	(*c).refcount = minuspercent___system_716((*c).refcount, ((NI) 8));
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = ltpercent___system_1005((*c).refcount, ((NI) 8));
		if (!T3_) goto LA4_;
		rtlAddZCT__system_5379(c);
	}
	LA4_: ;
}
static N_INLINE(void, asgnRef)(void** dest, void* src) {
	{
		tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g* T5_;
		if (!!((src == NIM_NIL))) goto LA3_;
		T5_ = (tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g*)0;
		T5_ = usrToCell__system_5336(src);
		incRef__system_5374(T5_);
	}
	LA3_: ;
	{
		tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g* T10_;
		if (!!(((*dest) == NIM_NIL))) goto LA8_;
		T10_ = (tyObject_Cell__nhn83Yf9cX7rcmG5W9b4oa6g*)0;
		T10_ = usrToCell__system_5336((*dest));
		decRef__system_5381(T10_);
	}
	LA8_: ;
	(*dest) = src;
}
static N_INLINE(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg*, getTerminal__pureZterminal_26)(void) {
	tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg* result;
	result = NIM_NIL;
	{
		if (!(gTerm__pureZterminal_15 == 0)) goto LA3_;
		asgnRef((void**) (&gTerm__pureZterminal_15), newTerminal__pureZterminal_16());
	}
	LA3_: ;
	result = gTerm__pureZterminal_15;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, setStyle__pureZterminal_439)(FILE* f, tySet_tyEnum_Style__IfhGTpNOgg3EytKq9c3Vnwg style) {
	NI h;
	tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg* termX60gensym19_;
	NI16 old;
	NI16 T6_;
	NI16 a;
	NI32 T23_;
	termX60gensym19_ = getTerminal__pureZterminal_26();
	{
		if (!(f == stderr)) goto LA3_;
		h = (*termX60gensym19_).hStderr;
	}
	goto LA1_;
	LA3_: ;
	{
		h = (*termX60gensym19_).hStdout;
	}
	LA1_: ;
	T6_ = (NI16)0;
	T6_ = getAttributes__pureZterminal_187(h);
	old = (NI16)(T6_ & ((NI16) 119));
	a = ((NI16) 0);
	{
		if (!((style &((NU16)1<<((NU)((((tyEnum_Style__IfhGTpNOgg3EytKq9c3Vnwg) 1)- 1))&15U)))!=0)) goto LA9_;
		a = (NI16)(a | ((NI16) 8));
	}
	LA9_: ;
	{
		if (!((style &((NU16)1<<((NU)((((tyEnum_Style__IfhGTpNOgg3EytKq9c3Vnwg) 5)- 1))&15U)))!=0)) goto LA13_;
		a = (NI16)(a | ((NI16) 128));
	}
	LA13_: ;
	{
		if (!((style &((NU16)1<<((NU)((((tyEnum_Style__IfhGTpNOgg3EytKq9c3Vnwg) 7)- 1))&15U)))!=0)) goto LA17_;
		a = (NI16)(a | ((NI16) 16384));
	}
	LA17_: ;
	{
		if (!((style &((NU16)1<<((NU)((((tyEnum_Style__IfhGTpNOgg3EytKq9c3Vnwg) 4)- 1))&15U)))!=0)) goto LA21_;
		a = (NI16)(a | ((NI16) -32768));
	}
	LA21_: ;
	T23_ = (NI32)0;
	T23_ = Dl_1761607838_(h, (NI16)(old | a));
	(void)(T23_);
}
N_LIB_PRIVATE N_NIMCALL(void, resetAttributes__pureZterminal_356)(FILE* f) {
	tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg* term;
	term = getTerminal__pureZterminal_26();
	{
		NI32 T5_;
		if (!(f == stderr)) goto LA3_;
		T5_ = (NI32)0;
		T5_ = Dl_1761607838_((*term).hStderr, (*term).oldStderrAttr);
		(void)(T5_);
	}
	goto LA1_;
	LA3_: ;
	{
		NI32 T7_;
		T7_ = (NI32)0;
		T7_ = Dl_1761607838_((*term).hStdout, (*term).oldStdoutAttr);
		(void)(T7_);
	}
	LA1_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, setForegroundColor__pureZterminal_503)(FILE* f, tyEnum_ForegroundColor__avKgWVVKiIc89c9aKDsFLd7w fg, NIM_BOOL bright) {
	NI h;
	tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg* termX60gensym24_;
	NI16 old;
	NI16 T6_;
	termX60gensym24_ = getTerminal__pureZterminal_26();
	{
		if (!(f == stderr)) goto LA3_;
		h = (*termX60gensym24_).hStderr;
	}
	goto LA1_;
	LA3_: ;
	{
		h = (*termX60gensym24_).hStdout;
	}
	LA1_: ;
	T6_ = (NI16)0;
	T6_ = getAttributes__pureZterminal_187(h);
	old = (NI16)(T6_ & ((NI16) -8));
	{
		if (!(defaultForegroundColor__pureZterminal_501 == ((NI16) -1))) goto LA9_;
		defaultForegroundColor__pureZterminal_501 = old;
	}
	LA9_: ;
	{
		if (!bright) goto LA13_;
		old = (NI16)(old | ((NI16) 8));
	}
	goto LA11_;
	LA13_: ;
	{
		old = (NI16)(old & ((NI16) -9));
	}
	LA11_: ;
	{
		NI16 T20_;
		NI32 T21_;
		if (!(fg == ((tyEnum_ForegroundColor__avKgWVVKiIc89c9aKDsFLd7w) 39))) goto LA18_;
		T20_ = (NI16)0;
		T20_ = toU16__system_301(((NI) ((NI16)(old | defaultForegroundColor__pureZterminal_501))));
		T21_ = (NI32)0;
		T21_ = Dl_1761607838_(h, T20_);
		(void)(T21_);
	}
	goto LA16_;
	LA18_: ;
	{
		NI16 T23_;
		NI32 T24_;
		T23_ = (NI16)0;
		T23_ = toU16__system_301((NI)(((NI) (old)) | lookup__pureZterminal_515[(fg)- 30]));
		T24_ = (NI32)0;
		T24_ = Dl_1761607838_(h, T23_);
		(void)(T24_);
	}
	LA16_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatslibatspureatsterminaldotnim_Init000)(void) {
{
	TFrame FR_; FR_.len = 0;

	nimRegisterThreadLocalMarker(TM__CN3raB9atujkEiPpxYAdlgQ_3);

}/* preInitProc end */
{
}
}

N_LIB_PRIVATE N_NIMCALL(void, atmdotdotatslibatspureatsterminaldotnim_DatInit000)(void) {
static TNimNode* TM__CN3raB9atujkEiPpxYAdlgQ_2_7[7];
static TNimNode TM__CN3raB9atujkEiPpxYAdlgQ_0[8];
NTIpterminal58objecttype__UsCBTY9apiEsmVq1ekVwEMg_.size = sizeof(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg);
NTIpterminal58objecttype__UsCBTY9apiEsmVq1ekVwEMg_.align = NIM_ALIGNOF(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg);
NTIpterminal58objecttype__UsCBTY9apiEsmVq1ekVwEMg_.kind = 18;
NTIpterminal58objecttype__UsCBTY9apiEsmVq1ekVwEMg_.base = 0;
NTIpterminal58objecttype__UsCBTY9apiEsmVq1ekVwEMg_.flags = 3;
TM__CN3raB9atujkEiPpxYAdlgQ_2_7[0] = &TM__CN3raB9atujkEiPpxYAdlgQ_0[1];
TM__CN3raB9atujkEiPpxYAdlgQ_0[1].kind = 1;
TM__CN3raB9atujkEiPpxYAdlgQ_0[1].offset = offsetof(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg, trueColorIsSupported);
TM__CN3raB9atujkEiPpxYAdlgQ_0[1].typ = (&NTIbool__VaVACK0bpYmqIQ0mKcHfQQ_);
TM__CN3raB9atujkEiPpxYAdlgQ_0[1].name = "trueColorIsSupported";
TM__CN3raB9atujkEiPpxYAdlgQ_2_7[1] = &TM__CN3raB9atujkEiPpxYAdlgQ_0[2];
TM__CN3raB9atujkEiPpxYAdlgQ_0[2].kind = 1;
TM__CN3raB9atujkEiPpxYAdlgQ_0[2].offset = offsetof(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg, trueColorIsEnabled);
TM__CN3raB9atujkEiPpxYAdlgQ_0[2].typ = (&NTIbool__VaVACK0bpYmqIQ0mKcHfQQ_);
TM__CN3raB9atujkEiPpxYAdlgQ_0[2].name = "trueColorIsEnabled";
TM__CN3raB9atujkEiPpxYAdlgQ_2_7[2] = &TM__CN3raB9atujkEiPpxYAdlgQ_0[3];
TM__CN3raB9atujkEiPpxYAdlgQ_0[3].kind = 1;
TM__CN3raB9atujkEiPpxYAdlgQ_0[3].offset = offsetof(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg, fgSetColor);
TM__CN3raB9atujkEiPpxYAdlgQ_0[3].typ = (&NTIbool__VaVACK0bpYmqIQ0mKcHfQQ_);
TM__CN3raB9atujkEiPpxYAdlgQ_0[3].name = "fgSetColor";
TM__CN3raB9atujkEiPpxYAdlgQ_2_7[3] = &TM__CN3raB9atujkEiPpxYAdlgQ_0[4];
TM__CN3raB9atujkEiPpxYAdlgQ_0[4].kind = 1;
TM__CN3raB9atujkEiPpxYAdlgQ_0[4].offset = offsetof(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg, hStdout);
TM__CN3raB9atujkEiPpxYAdlgQ_0[4].typ = (&NTIint__rR5Bzr1D5krxoo1NcNyeMA_);
TM__CN3raB9atujkEiPpxYAdlgQ_0[4].name = "hStdout";
TM__CN3raB9atujkEiPpxYAdlgQ_2_7[4] = &TM__CN3raB9atujkEiPpxYAdlgQ_0[5];
TM__CN3raB9atujkEiPpxYAdlgQ_0[5].kind = 1;
TM__CN3raB9atujkEiPpxYAdlgQ_0[5].offset = offsetof(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg, hStderr);
TM__CN3raB9atujkEiPpxYAdlgQ_0[5].typ = (&NTIint__rR5Bzr1D5krxoo1NcNyeMA_);
TM__CN3raB9atujkEiPpxYAdlgQ_0[5].name = "hStderr";
TM__CN3raB9atujkEiPpxYAdlgQ_2_7[5] = &TM__CN3raB9atujkEiPpxYAdlgQ_0[6];
TM__CN3raB9atujkEiPpxYAdlgQ_0[6].kind = 1;
TM__CN3raB9atujkEiPpxYAdlgQ_0[6].offset = offsetof(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg, oldStdoutAttr);
TM__CN3raB9atujkEiPpxYAdlgQ_0[6].typ = (&NTIint4954__kDPg4wXyR8DDyA0MeEjIsw_);
TM__CN3raB9atujkEiPpxYAdlgQ_0[6].name = "oldStdoutAttr";
TM__CN3raB9atujkEiPpxYAdlgQ_2_7[6] = &TM__CN3raB9atujkEiPpxYAdlgQ_0[7];
TM__CN3raB9atujkEiPpxYAdlgQ_0[7].kind = 1;
TM__CN3raB9atujkEiPpxYAdlgQ_0[7].offset = offsetof(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg, oldStderrAttr);
TM__CN3raB9atujkEiPpxYAdlgQ_0[7].typ = (&NTIint4954__kDPg4wXyR8DDyA0MeEjIsw_);
TM__CN3raB9atujkEiPpxYAdlgQ_0[7].name = "oldStderrAttr";
TM__CN3raB9atujkEiPpxYAdlgQ_0[0].len = 7; TM__CN3raB9atujkEiPpxYAdlgQ_0[0].kind = 2; TM__CN3raB9atujkEiPpxYAdlgQ_0[0].sons = &TM__CN3raB9atujkEiPpxYAdlgQ_2_7[0];
NTIpterminal58objecttype__UsCBTY9apiEsmVq1ekVwEMg_.node = &TM__CN3raB9atujkEiPpxYAdlgQ_0[0];
NTIpterminal__VTNB4axZc9aSVvMADQfFQjw_.size = sizeof(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg*);
NTIpterminal__VTNB4axZc9aSVvMADQfFQjw_.align = NIM_ALIGNOF(tyObject_PTerminalcolonObjectType___UsCBTY9apiEsmVq1ekVwEMg*);
NTIpterminal__VTNB4axZc9aSVvMADQfFQjw_.kind = 22;
NTIpterminal__VTNB4axZc9aSVvMADQfFQjw_.base = (&NTIpterminal58objecttype__UsCBTY9apiEsmVq1ekVwEMg_);
NTIpterminal__VTNB4axZc9aSVvMADQfFQjw_.flags = 2;
NTIpterminal__VTNB4axZc9aSVvMADQfFQjw_.marker = Marker_tyRef__VTNB4axZc9aSVvMADQfFQjw;
if (!((TM__CN3raB9atujkEiPpxYAdlgQ_4 = nimLoadLibrary(((NimStringDesc*) &TM__CN3raB9atujkEiPpxYAdlgQ_6)))
)) nimLoadLibraryError(((NimStringDesc*) &TM__CN3raB9atujkEiPpxYAdlgQ_7));
	Dl_1761607747_ = (tyProc__oew1DfaGl5XhHmnBK0HYXQ) nimGetProcAddr(TM__CN3raB9atujkEiPpxYAdlgQ_4, "DuplicateHandle");
	Dl_1761607755_ = (tyProc__uryidYWkntM7ddjZSyxvyQ) nimGetProcAddr(TM__CN3raB9atujkEiPpxYAdlgQ_4, "GetCurrentProcess");
	Dl_1761607756_ = (tyProc__EmkmlYX9crhgylsTGNg9aF5Q) nimGetProcAddr(TM__CN3raB9atujkEiPpxYAdlgQ_4, "GetConsoleScreenBufferInfo");
	Dl_1761607838_ = (tyProc__oPCjp4xTgEl9a8fqSzOv8lw) nimGetProcAddr(TM__CN3raB9atujkEiPpxYAdlgQ_4, "SetConsoleTextAttribute");
}

