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

#include "nimbase.h"
#include <string.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 NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct tyTuple__7q7q3E6Oj24ZNVJb9aonhAg tyTuple__7q7q3E6Oj24ZNVJb9aonhAg;
struct TGenericSeq {
NI len;
NI reserved;
};
struct NimStringDesc {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct tyTuple__7q7q3E6Oj24ZNVJb9aonhAg {
NimStringDesc* Field0;
NimStringDesc* Field1;
NimStringDesc* Field2;
};
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, nosrelativePath)(NimStringDesc* path, NimStringDesc* base, NIM_CHAR sep);
static N_INLINE(NIM_BOOL, eqImpl__pathutils_79)(NimStringDesc* x, NimStringDesc* y);
N_LIB_PRIVATE N_NIMCALL(NI, noscmpPaths)(NimStringDesc* pathA, NimStringDesc* pathB);
static N_INLINE(NIM_BOOL, isEmpty__pathutils_94)(NimStringDesc* x);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, nosgetCurrentDir)(void);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
N_LIB_PRIVATE N_NIMCALL(void, addNormalizePath__pureZpathnorm_71)(NimStringDesc* x, NimStringDesc** result, NI* state, NIM_CHAR dirSep);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nosisAbsolute)(NimStringDesc* path);
static N_INLINE(NimStringDesc*, slash___pureZos_121)(NimStringDesc* head, NimStringDesc* tail);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, nosjoinPath)(NimStringDesc* head, NimStringDesc* tail);
N_LIB_PRIVATE N_NIMCALL(void, nossplitFile)(NimStringDesc* path, tyTuple__7q7q3E6Oj24ZNVJb9aonhAg* Result);
static N_INLINE(void, nimZeroMem)(void* p, NI size);
static N_INLINE(void, nimSetMem__systemZmemory_7)(void* a, int v, NI size);
N_LIB_PRIVATE N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, customPathImpl__pathutils_176)(NimStringDesc* x);
N_LIB_PRIVATE N_NIMCALL(NI, skipHomeDir__pathutils_157)(NimStringDesc* x);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nsuStartsWith)(NimStringDesc* s, NimStringDesc* prefix);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nsuContinuesWith)(NimStringDesc* s, NimStringDesc* substr, NI start);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
static N_INLINE(void, copyMem__system_1733)(void* dest, void* source, NI size);
static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, relevantPart__pathutils_160)(NimStringDesc* s, NI afterSlashX);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, addChar)(NimStringDesc* s, NIM_CHAR c);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, slash___pathutils_90)(NimStringDesc* base, NimStringDesc* f);
STRING_LITERAL(TM__dje9awFf9c1DXjDuKVU9cWH6g_2, "/home/", 6);
STRING_LITERAL(TM__dje9awFf9c1DXjDuKVU9cWH6g_3, "/Users/", 7);
STRING_LITERAL(TM__dje9awFf9c1DXjDuKVU9cWH6g_4, "/mnt/", 5);
STRING_LITERAL(TM__dje9awFf9c1DXjDuKVU9cWH6g_5, "//user/", 7);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, dollar___options_4370)(NimStringDesc* x) {
	NimStringDesc* result;
	result = NIM_NIL;
	result = copyString(x);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, dollar___options_4472)(NimStringDesc* x) {
	NimStringDesc* result;
	result = NIM_NIL;
	result = copyString(x);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, relativeTo__pathutils_133)(NimStringDesc* fullPath, NimStringDesc* baseFilename, NIM_CHAR sep) {
	NimStringDesc* result;
	result = NIM_NIL;
	result = nosrelativePath(fullPath, baseFilename, sep);
	return result;
}
static N_INLINE(NIM_BOOL, eqImpl__pathutils_79)(NimStringDesc* x, NimStringDesc* y) {
	NIM_BOOL result;
	NI T1_;
	result = (NIM_BOOL)0;
	T1_ = (NI)0;
	T1_ = noscmpPaths(x, y);
	result = (T1_ == ((NI) 0));
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, eqeq___options_4108)(NimStringDesc* x, NimStringDesc* y) {
	NIM_BOOL result;
	result = (NIM_BOOL)0;
	result = eqImpl__pathutils_79(x, y);
	return result;
}
static N_INLINE(NIM_BOOL, isEmpty__pathutils_94)(NimStringDesc* x) {
	NIM_BOOL result;
	result = (NIM_BOOL)0;
	result = ((x ? x->Sup.len : 0) == ((NI) 0));
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, slash___pathutils_112)(NimStringDesc* base, NimStringDesc* f) {
	NimStringDesc* result;
	NimStringDesc* base_2;
	NI state;
	result = NIM_NIL;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = isEmpty__pathutils_94(base);
		if (!T3_) goto LA4_;
		base_2 = nosgetCurrentDir();
	}
	goto LA1_;
	LA4_: ;
	{
		base_2 = base;
	}
	LA1_: ;
	result = rawNewString(((NI) ((NI)((base_2 ? base_2->Sup.len : 0) + (f ? f->Sup.len : 0)))));
	state = ((NI) 0);
	addNormalizePath__pureZpathnorm_71(base_2, (&result), (&state), 47);
	addNormalizePath__pureZpathnorm_71(f, (&result), (&state), 47);
	return result;
}
static N_INLINE(NimStringDesc*, slash___pureZos_121)(NimStringDesc* head, NimStringDesc* tail) {
	NimStringDesc* result;
	result = NIM_NIL;
	result = nosjoinPath(head, tail);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, toAbsoluteDir__pathutils_72)(NimStringDesc* path) {
	NimStringDesc* result;
	result = NIM_NIL;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = nosisAbsolute(path);
		if (!T3_) goto LA4_;
		result = copyString(path);
	}
	goto LA1_;
	LA4_: ;
	{
		NimStringDesc* T7_;
		T7_ = NIM_NIL;
		T7_ = nosgetCurrentDir();
		result = slash___pureZos_121(T7_, path);
	}
	LA1_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, slash___pathutils_90)(NimStringDesc* base, NimStringDesc* f) {
	NimStringDesc* result;
	NimStringDesc* base_2;
	NI state;
	result = NIM_NIL;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = isEmpty__pathutils_94(base);
		if (!T3_) goto LA4_;
		base_2 = nosgetCurrentDir();
	}
	goto LA1_;
	LA4_: ;
	{
		base_2 = base;
	}
	LA1_: ;
	result = rawNewString(((NI) ((NI)((base_2 ? base_2->Sup.len : 0) + (f ? f->Sup.len : 0)))));
	state = ((NI) 0);
	addNormalizePath__pureZpathnorm_71(base_2, (&result), (&state), 47);
	addNormalizePath__pureZpathnorm_71(f, (&result), (&state), 47);
	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(void, splitFile__pathutils_27)(NimStringDesc* x, tyTuple__7q7q3E6Oj24ZNVJb9aonhAg* Result) {
	tyTuple__7q7q3E6Oj24ZNVJb9aonhAg T1_;
	NimStringDesc* a;
	NimStringDesc* b;
	NimStringDesc* c;
	NimStringDesc* colontmp_;
	NimStringDesc* colontmp__2;
	NimStringDesc* colontmp__3;
	nimZeroMem((void*)(&T1_), sizeof(tyTuple__7q7q3E6Oj24ZNVJb9aonhAg));
	nossplitFile(x, (&T1_));
	a = NIM_NIL;
	a = T1_.Field0;
	b = NIM_NIL;
	b = T1_.Field1;
	c = NIM_NIL;
	c = T1_.Field2;
	colontmp_ = copyString(a);
	colontmp__2 = copyString(b);
	colontmp__3 = copyString(c);
	unsureAsgnRef((void**) (&(*Result).Field0), copyString(colontmp_));
	unsureAsgnRef((void**) (&(*Result).Field1), copyString(colontmp__2));
	unsureAsgnRef((void**) (&(*Result).Field2), copyString(colontmp__3));
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, eqeq___nimconf_290)(NimStringDesc* x, NimStringDesc* y) {
	NIM_BOOL result;
	result = (NIM_BOOL)0;
	result = eqImpl__pathutils_79(x, y);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NI, skipHomeDir__pathutils_157)(NimStringDesc* x) {
	NI result;
	result = (NI)0;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = nsuStartsWith(x, ((NimStringDesc*) &TM__dje9awFf9c1DXjDuKVU9cWH6g_2));
		if (T3_) goto LA4_;
		T3_ = nsuStartsWith(x, ((NimStringDesc*) &TM__dje9awFf9c1DXjDuKVU9cWH6g_3));
		LA4_: ;
		if (!T3_) goto LA5_;
		result = ((NI) 3);
	}
	goto LA1_;
	LA5_: ;
	{
		NIM_BOOL T8_;
		T8_ = (NIM_BOOL)0;
		T8_ = nsuStartsWith(x, ((NimStringDesc*) &TM__dje9awFf9c1DXjDuKVU9cWH6g_4));
		if (!(T8_)) goto LA9_;
		T8_ = nsuContinuesWith(x, ((NimStringDesc*) &TM__dje9awFf9c1DXjDuKVU9cWH6g_3), ((NI) 6));
		LA9_: ;
		if (!T8_) goto LA10_;
		result = ((NI) 5);
	}
	goto LA1_;
	LA10_: ;
	{
		result = ((NI) 0);
	}
	LA1_: ;
	return result;
}
static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memcpy(dest, source, ((size_t) (size)));
}
static N_INLINE(void, copyMem__system_1733)(void* dest, void* source, NI size) {
	nimCopyMem(dest, source, size);
}
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
	{
		if (!!((src == ((NimStringDesc*) NIM_NIL)))) goto LA3_;
		copyMem__system_1733(((void*) ((&(*dest).data[(*dest).Sup.len]))), ((void*) ((*src).data)), ((NI) ((NI)((*src).Sup.len + ((NI) 1)))));
		(*dest).Sup.len += (*src).Sup.len;
	}
	LA3_: ;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, relevantPart__pathutils_160)(NimStringDesc* s, NI afterSlashX) {
	NimStringDesc* result;
	NI slashes;
	result = NIM_NIL;
	result = rawNewString(((NI) ((NI)((s ? s->Sup.len : 0) - ((NI) 8)))));
	slashes = afterSlashX;
	{
		NI i;
		NI colontmp_;
		NI i_2;
		i = (NI)0;
		colontmp_ = (NI)0;
		colontmp_ = (s ? s->Sup.len : 0);
		i_2 = ((NI) 0);
		{
			while (1) {
				if (!(i_2 < colontmp_)) goto LA3;
				i = i_2;
				{
					if (!(slashes == ((NI) 0))) goto LA6_;
					result = addChar(result, s->data[i]);
				}
				goto LA4_;
				LA6_: ;
				{
					if (!((NU8)(s->data[i]) == (NU8)(47))) goto LA9_;
					slashes -= ((NI) 1);
				}
				goto LA4_;
				LA9_: ;
				LA4_: ;
				i_2 += ((NI) 1);
			} LA3: ;
		}
	}
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, customPathImpl__pathutils_176)(NimStringDesc* x) {
	NimStringDesc* result;
	result = NIM_NIL;
	{
		NIM_BOOL T3_;
		NimStringDesc* T6_;
		NimStringDesc* T7_;
		T3_ = (NIM_BOOL)0;
		T3_ = nosisAbsolute(x);
		if (!!(T3_)) goto LA4_;
		T6_ = NIM_NIL;
		T6_ = nosgetCurrentDir();
		T7_ = NIM_NIL;
		T7_ = slash___pureZos_121(T6_, x);
		result = customPathImpl__pathutils_176(T7_);
	}
	goto LA1_;
	LA4_: ;
	{
		NI slashes;
		slashes = skipHomeDir__pathutils_157(x);
		{
			NimStringDesc* T13_;
			NimStringDesc* T14_;
			if (!(((NI) 0) < slashes)) goto LA11_;
			T13_ = NIM_NIL;
			T14_ = NIM_NIL;
			T14_ = relevantPart__pathutils_160(x, slashes);
			T13_ = rawNewString((T14_ ? T14_->Sup.len : 0) + 7);
appendString(T13_, ((NimStringDesc*) &TM__dje9awFf9c1DXjDuKVU9cWH6g_5));
appendString(T13_, T14_);
			result = T13_;
		}
		goto LA9_;
		LA11_: ;
		{
			result = copyString(x);
		}
		LA9_: ;
	}
	LA1_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, customPath__pathutils_180)(NimStringDesc* x) {
	NimStringDesc* result;
	result = NIM_NIL;
	result = customPathImpl__pathutils_176(x);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, eqeq___nimconf_430)(NimStringDesc* x, NimStringDesc* y) {
	NIM_BOOL result;
	result = (NIM_BOOL)0;
	result = eqImpl__pathutils_79(x, y);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, dollar___docgen_7091)(NimStringDesc* x) {
	NimStringDesc* result;
	result = NIM_NIL;
	result = copyString(x);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, toAbsolute__pathutils_138)(NimStringDesc* file, NimStringDesc* base) {
	NimStringDesc* result;
	result = NIM_NIL;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = nosisAbsolute(file);
		if (!T3_) goto LA4_;
		result = copyString(file);
	}
	goto LA1_;
	LA4_: ;
	{
		result = slash___pathutils_90(base, file);
	}
	LA1_: ;
	return result;
}
