/* Generated by Nim Compiler v1.2.4 */
/*   (c) 2020 Andreas Rumpf */
/* The generated code is subject to the original license. */
#define NIM_INTBITS 32
#define NIM_EmulateOverflowChecks

#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;
};
static N_INLINE(NIM_BOOL, eqImpl__yNLoUCFTwIp72A4e3FgdXApathutils)(NimStringDesc* x, NimStringDesc* y);
N_LIB_PRIVATE N_NIMCALL(NI, noscmpPaths)(NimStringDesc* pathA, NimStringDesc* pathB);
static N_INLINE(NIM_BOOL, isEmpty__ZNWb41IwBSHCUIjlqlGoxgpathutils)(NimStringDesc* x);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, nosgetCurrentDir)(void);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nosisAbsolute)(NimStringDesc* path);
N_LIB_PRIVATE N_NIMCALL(void, failedAssertImpl__W9cjVocn1tjhW7p7xohJj6A)(NimStringDesc* msg);
N_NIMCALL(NimStringDesc*, rawNewString)(NI cap);
static N_INLINE(NIM_BOOL, nimAddInt)(NI a, NI b, NI* res);
N_LIB_PRIVATE N_NOINLINE(void, raiseOverflow)(void);
N_LIB_PRIVATE N_NOINLINE(void, raiseRangeErrorI)(NI64 i, NI64 a, NI64 b);
N_LIB_PRIVATE N_NIMCALL(void, addNormalizePath__bx9csIXjBBeHkYSkIUixO1g)(NimStringDesc* x, NimStringDesc** result, NI* state, NIM_CHAR dirSep);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, copyString)(NimStringDesc* src);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, slash___gEyhbzZ1UcxyenWRLJRXNQ)(NimStringDesc* head, NimStringDesc* tail);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
static N_INLINE(void, copyMem__M04YC71iJg1N7gBF3HZTngsystem)(void* dest, void* source, NI size);
static N_INLINE(void, nimCopyMem)(void* dest, void* source, NI size);
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__JE6t4x7Z3v2iVz27Nx0MRAmemory)(void* a, int v, NI size);
N_LIB_PRIVATE N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, nosrelativePath)(NimStringDesc* path, NimStringDesc* base, NIM_CHAR sep);
STRING_LITERAL(TM__r4WvUOkTx4ylahJtpRE9aTQ_2, "pathutils.nim(78, 11) `not isAbsolute(f.string)` ", 49);
STRING_LITERAL(TM__r4WvUOkTx4ylahJtpRE9aTQ_4, "pathutils.nim(70, 11) `not isAbsolute(f.string)` ", 49);
static N_INLINE(NIM_BOOL, eqImpl__yNLoUCFTwIp72A4e3FgdXApathutils)(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___RkPToIJrmXtRS03VT1CneA)(NimStringDesc* x, NimStringDesc* y) {
	NIM_BOOL result;
	result = (NIM_BOOL)0;
	result = eqImpl__yNLoUCFTwIp72A4e3FgdXApathutils(x, y);
	return result;
}
static N_INLINE(NIM_BOOL, isEmpty__ZNWb41IwBSHCUIjlqlGoxgpathutils)(NimStringDesc* x) {
	NIM_BOOL result;
	result = (NIM_BOOL)0;
	result = ((x ? x->Sup.len : 0) == ((NI) 0));
	return result;
}
static N_INLINE(NIM_BOOL, nimAddInt)(NI a, NI b, NI* res) {
	NIM_BOOL result;
	NI r;
	result = (NIM_BOOL)0;
	r = ((NI) ((NU)((NU32)(((NU) (a))) + (NU32)(((NU) (b))))));
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = (((NI) 0) <= (NI)(r ^ a));
		if (T3_) goto LA4_;
		T3_ = (((NI) 0) <= (NI)(r ^ b));
		LA4_: ;
		if (!T3_) goto LA5_;
		(*res) = r;
	}
	goto LA1_;
	LA5_: ;
	{
		result = NIM_TRUE;
	}
	LA1_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, slash___0U8YTiSB6NvFwgvyimFN2Q)(NimStringDesc* base, NimStringDesc* f) {
	NimStringDesc* result;
	NimStringDesc* base_2;
	NI TM__r4WvUOkTx4ylahJtpRE9aTQ_3;
	NI state;
	result = (NimStringDesc*)0;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = isEmpty__ZNWb41IwBSHCUIjlqlGoxgpathutils(base);
		if (!T3_) goto LA4_;
		base_2 = nosgetCurrentDir();
	}
	goto LA1_;
	LA4_: ;
	{
		base_2 = base;
	}
	LA1_: ;
	{
		NIM_BOOL T9_;
		T9_ = (NIM_BOOL)0;
		T9_ = nosisAbsolute(f);
		if (!!(!(T9_))) goto LA10_;
		failedAssertImpl__W9cjVocn1tjhW7p7xohJj6A(((NimStringDesc*) &TM__r4WvUOkTx4ylahJtpRE9aTQ_2));
	}
	LA10_: ;
	if (nimAddInt((base_2 ? base_2->Sup.len : 0), (f ? f->Sup.len : 0), &TM__r4WvUOkTx4ylahJtpRE9aTQ_3)) { raiseOverflow(); };
	if (((NI)(TM__r4WvUOkTx4ylahJtpRE9aTQ_3)) < ((NI) 0) || ((NI)(TM__r4WvUOkTx4ylahJtpRE9aTQ_3)) > ((NI) 2147483647)){ raiseRangeErrorI((NI)(TM__r4WvUOkTx4ylahJtpRE9aTQ_3), ((NI) 0), ((NI) 2147483647)); }
	result = rawNewString(((NI) ((NI)(TM__r4WvUOkTx4ylahJtpRE9aTQ_3))));
	state = ((NI) 0);
	addNormalizePath__bx9csIXjBBeHkYSkIUixO1g(base_2, (&result), (&state), 47);
	addNormalizePath__bx9csIXjBBeHkYSkIUixO1g(f, (&result), (&state), 47);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, toAbsoluteDir__jHVASw8gMU0B9bVk9atXU77g)(NimStringDesc* path) {
	NimStringDesc* result;
	result = (NimStringDesc*)0;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = nosisAbsolute(path);
		if (!T3_) goto LA4_;
		result = copyString(path);
	}
	goto LA1_;
	LA4_: ;
	{
		NimStringDesc* T7_;
		T7_ = (NimStringDesc*)0;
		T7_ = nosgetCurrentDir();
		result = slash___gEyhbzZ1UcxyenWRLJRXNQ(T7_, path);
	}
	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__M04YC71iJg1N7gBF3HZTngsystem)(void* dest, void* source, NI size) {
	nimCopyMem(dest, source, size);
}
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
	{
		if (!!((src == NIM_NIL))) goto LA3_;
		copyMem__M04YC71iJg1N7gBF3HZTngsystem(((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*, slash___QVqo5OOQAdrjFqBsPctklw)(NimStringDesc* base, NimStringDesc* f) {
	NimStringDesc* result;
	NimStringDesc* base_2;
	NI TM__r4WvUOkTx4ylahJtpRE9aTQ_5;
	NI state;
	result = (NimStringDesc*)0;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = isEmpty__ZNWb41IwBSHCUIjlqlGoxgpathutils(base);
		if (!T3_) goto LA4_;
		base_2 = nosgetCurrentDir();
	}
	goto LA1_;
	LA4_: ;
	{
		base_2 = base;
	}
	LA1_: ;
	{
		NIM_BOOL T9_;
		NimStringDesc* T12_;
		T9_ = (NIM_BOOL)0;
		T9_ = nosisAbsolute(f);
		if (!!(!(T9_))) goto LA10_;
		T12_ = (NimStringDesc*)0;
		T12_ = rawNewString((f ? f->Sup.len : 0) + 49);
appendString(T12_, ((NimStringDesc*) &TM__r4WvUOkTx4ylahJtpRE9aTQ_4));
appendString(T12_, f);
		failedAssertImpl__W9cjVocn1tjhW7p7xohJj6A(T12_);
	}
	LA10_: ;
	if (nimAddInt((base_2 ? base_2->Sup.len : 0), (f ? f->Sup.len : 0), &TM__r4WvUOkTx4ylahJtpRE9aTQ_5)) { raiseOverflow(); };
	if (((NI)(TM__r4WvUOkTx4ylahJtpRE9aTQ_5)) < ((NI) 0) || ((NI)(TM__r4WvUOkTx4ylahJtpRE9aTQ_5)) > ((NI) 2147483647)){ raiseRangeErrorI((NI)(TM__r4WvUOkTx4ylahJtpRE9aTQ_5), ((NI) 0), ((NI) 2147483647)); }
	result = rawNewString(((NI) ((NI)(TM__r4WvUOkTx4ylahJtpRE9aTQ_5))));
	state = ((NI) 0);
	addNormalizePath__bx9csIXjBBeHkYSkIUixO1g(base_2, (&result), (&state), 47);
	addNormalizePath__bx9csIXjBBeHkYSkIUixO1g(f, (&result), (&state), 47);
	return result;
}
static N_INLINE(void, nimSetMem__JE6t4x7Z3v2iVz27Nx0MRAmemory)(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__JE6t4x7Z3v2iVz27Nx0MRAmemory(p, ((int) 0), size);
}
N_LIB_PRIVATE N_NIMCALL(void, splitFile__z7B4FbwzX3Y0L1EA2lLGXw)(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 = (NimStringDesc*)0;
	a = T1_.Field0;
	b = (NimStringDesc*)0;
	b = T1_.Field1;
	c = (NimStringDesc*)0;
	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(NimStringDesc*, relativeTo__zjjWvxBunys9bbBJHoqyLyQ)(NimStringDesc* fullPath, NimStringDesc* baseFilename, NIM_CHAR sep) {
	NimStringDesc* result;
	result = (NimStringDesc*)0;
	result = nosrelativePath(fullPath, baseFilename, sep);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, dollar___l9cjIIY6CNqmzrJ1PC9apeYg)(NimStringDesc* x) {
	NimStringDesc* result;
	result = (NimStringDesc*)0;
	result = copyString(x);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, eqeq___YYHMY7OZpnNmtTBJy5X3VA)(NimStringDesc* x, NimStringDesc* y) {
	NIM_BOOL result;
	result = (NIM_BOOL)0;
	result = eqImpl__yNLoUCFTwIp72A4e3FgdXApathutils(x, y);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, eqeq___UCoYdHlZt2oxX9ceSn0adYg)(NimStringDesc* x, NimStringDesc* y) {
	NIM_BOOL result;
	result = (NIM_BOOL)0;
	result = eqImpl__yNLoUCFTwIp72A4e3FgdXApathutils(x, y);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, dollar___hGkBbU4pIQDXq4yGHJbKBQ)(NimStringDesc* x) {
	NimStringDesc* result;
	result = (NimStringDesc*)0;
	result = copyString(x);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NimStringDesc*, dollar___1d2waHISqAkJMu7hkyCpZg)(NimStringDesc* x) {
	NimStringDesc* result;
	result = (NimStringDesc*)0;
	result = copyString(x);
	return result;
}
