/* Generated by Nim Compiler v0.17.0 */
/*   (c) 2017 Andreas Rumpf */
/* The generated code is subject to the original license. */
/* Compiled for: Linux, i386, gcc */
/* Command for C compiler:
   gcc -c  -w -O3 -fno-strict-aliasing -fPIC  -I/build/nim/src/Nim-0.17.0/lib -o lib/nimcache/stdlib_ospaths.o lib/nimcache/stdlib_ospaths.c */
#define NIM_NEW_MANGLING_RULES
#define NIM_INTBITS 32

#include "nimbase.h"
#include <string.h>
#undef linux
#undef near
typedef struct NimStringDesc NimStringDesc;
typedef struct TGenericSeq TGenericSeq;
typedef struct TY_7q7q3E6Oj24ZNVJb9aonhAg TY_7q7q3E6Oj24ZNVJb9aonhAg;
struct  TGenericSeq  {
NI len;
NI reserved;
};
struct  NimStringDesc  {
  TGenericSeq Sup;
NIM_CHAR data[SEQ_DECL_SIZE];
};
struct TY_7q7q3E6Oj24ZNVJb9aonhAg {
NimStringDesc* Field0;
NimStringDesc* Field1;
NimStringDesc* Field2;
};
N_NIMCALL(NimStringDesc*, nosjoinPath)(NimStringDesc* head, NimStringDesc* tail);
N_LIB_EXPORT N_CDECL(NimStringDesc*, nimrtl_copyString)(NimStringDesc* src);
static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src);
static N_INLINE(void, copyMem_fPlwH3r9agN9aEHB6yCPMh0wsystem)(void* dest, void* source, NI size);
N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s, NI start);
N_NIMCALL(NimStringDesc*, copyStr)(NimStringDesc* s, NI first);
N_NIMCALL(NimStringDesc*, rawNewString)(NI space);
static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c);
N_NIMCALL(void, unsureAsgnRef)(void** dest, void* src);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI start, NI last);
N_NIMCALL(NimStringDesc*, copyStrLast)(NimStringDesc* s, NI first, NI last);
STRING_LITERAL(TM_jvWQYw9bcuYhftfPX2ynPeg_2, "", 0);

static N_INLINE(void, copyMem_fPlwH3r9agN9aEHB6yCPMh0wsystem)(void* dest, void* source, NI size) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memcpy(dest, source, ((size_t) (size)));
}

static N_INLINE(void, appendString)(NimStringDesc* dest, NimStringDesc* src) {
	copyMem_fPlwH3r9agN9aEHB6yCPMh0wsystem(((void*) ((&(*dest).data[((*dest).Sup.len)- 0]))), ((void*) ((*src).data)), ((NI) ((NI)((*src).Sup.len + ((NI) 1)))));
	(*dest).Sup.len += (*src).Sup.len;
}

static N_INLINE(void, appendChar)(NimStringDesc* dest, NIM_CHAR c) {
	(*dest).data[((*dest).Sup.len)- 0] = c;
	(*dest).data[((NI)((*dest).Sup.len + ((NI) 1)))- 0] = 0;
	(*dest).Sup.len += ((NI) 1);
}

N_NIMCALL(NimStringDesc*, nosjoinPath)(NimStringDesc* head, NimStringDesc* tail) {
	NimStringDesc* result;
	result = (NimStringDesc*)0;
	{
		if (!((head ? head->Sup.len : 0) == ((NI) 0))) goto LA3_;
		result = nimrtl_copyString(tail);
	}
	goto LA1_;
	LA3_: ;
	{
		if (!(((NU8)(head->data[(NI)((head ? head->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)) || ((NU8)(head->data[(NI)((head ? head->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)))) goto LA6_;
		{
			NimStringDesc* T12_;
			NimStringDesc* T13_;
			if (!(((NU8)(tail->data[((NI) 0)])) == ((NU8)(47)) || ((NU8)(tail->data[((NI) 0)])) == ((NU8)(47)))) goto LA10_;
			T12_ = (NimStringDesc*)0;
			T13_ = (NimStringDesc*)0;
			T13_ = copyStr(tail, ((NI) 1));
			T12_ = rawNewString(head->Sup.len + T13_->Sup.len + 0);
appendString(T12_, head);
appendString(T12_, T13_);
			result = T12_;
		}
		goto LA8_;
		LA10_: ;
		{
			NimStringDesc* T15_;
			T15_ = (NimStringDesc*)0;
			T15_ = rawNewString(head->Sup.len + tail->Sup.len + 0);
appendString(T15_, head);
appendString(T15_, tail);
			result = T15_;
		}
		LA8_: ;
	}
	goto LA1_;
	LA6_: ;
	{
		{
			NimStringDesc* T21_;
			if (!(((NU8)(tail->data[((NI) 0)])) == ((NU8)(47)) || ((NU8)(tail->data[((NI) 0)])) == ((NU8)(47)))) goto LA19_;
			T21_ = (NimStringDesc*)0;
			T21_ = rawNewString(head->Sup.len + tail->Sup.len + 0);
appendString(T21_, head);
appendString(T21_, tail);
			result = T21_;
		}
		goto LA17_;
		LA19_: ;
		{
			NimStringDesc* T23_;
			T23_ = (NimStringDesc*)0;
			T23_ = rawNewString(head->Sup.len + tail->Sup.len + 1);
appendString(T23_, head);
appendChar(T23_, 47);
appendString(T23_, tail);
			result = T23_;
		}
		LA17_: ;
	}
	LA1_: ;
	return result;
}

N_NIMCALL(NimStringDesc*, slash__lXoMhn1ZYc9cAJa9bfA61msg)(NimStringDesc* head, NimStringDesc* tail) {
	NimStringDesc* result;
{	result = (NimStringDesc*)0;
	result = nosjoinPath(head, tail);
	goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}

N_NIMCALL(void, nossplitFile)(NimStringDesc* path, TY_7q7q3E6Oj24ZNVJb9aonhAg* Result) {
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = ((path ? path->Sup.len : 0) == ((NI) 0));
		if (T3_) goto LA4_;
		T3_ = (((NU8)(path->data[(NI)((path ? path->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)) || ((NU8)(path->data[(NI)((path ? path->Sup.len : 0) - ((NI) 1))])) == ((NU8)(47)));
		LA4_: ;
		if (!T3_) goto LA5_;
		unsureAsgnRef((void**) (&(*Result).Field0), nimrtl_copyString(path));
		unsureAsgnRef((void**) (&(*Result).Field1), nimrtl_copyString(((NimStringDesc*) &TM_jvWQYw9bcuYhftfPX2ynPeg_2)));
		unsureAsgnRef((void**) (&(*Result).Field2), nimrtl_copyString(((NimStringDesc*) &TM_jvWQYw9bcuYhftfPX2ynPeg_2)));
	}
	goto LA1_;
	LA5_: ;
	{
		NI sepPos;
		NI dotPos;
		sepPos = ((NI) -1);
		dotPos = (path ? path->Sup.len : 0);
		{
			NI i;
			NI colontmp_;
			NI res;
			i = (NI)0;
			colontmp_ = (NI)0;
			colontmp_ = (NI)((path ? path->Sup.len : 0) - ((NI) 1));
			res = colontmp_;
			{
				while (1) {
					if (!(((NI) 0) <= res)) goto LA10;
					i = res;
					{
						if (!((NU8)(path->data[i]) == (NU8)(46))) goto LA13_;
						{
							NIM_BOOL T17_;
							NIM_BOOL T18_;
							T17_ = (NIM_BOOL)0;
							T18_ = (NIM_BOOL)0;
							T18_ = (dotPos == (path ? path->Sup.len : 0));
							if (!(T18_)) goto LA19_;
							T18_ = (((NI) 0) < i);
							LA19_: ;
							T17_ = T18_;
							if (!(T17_)) goto LA20_;
							T17_ = !((((NU8)(path->data[(NI)(i - ((NI) 1))])) == ((NU8)(47)) || ((NU8)(path->data[(NI)(i - ((NI) 1))])) == ((NU8)(47))));
							LA20_: ;
							if (!T17_) goto LA21_;
							dotPos = i;
						}
						LA21_: ;
					}
					goto LA11_;
					LA13_: ;
					{
						if (!(((NU8)(path->data[i])) == ((NU8)(47)) || ((NU8)(path->data[i])) == ((NU8)(47)))) goto LA24_;
						sepPos = i;
						goto LA8;
					}
					goto LA11_;
					LA24_: ;
					LA11_: ;
					res -= ((NI) 1);
				} LA10: ;
			}
		} LA8: ;
		unsureAsgnRef((void**) (&(*Result).Field0), copyStrLast(path, ((NI) 0), (NI)(sepPos - ((NI) 1))));
		unsureAsgnRef((void**) (&(*Result).Field1), copyStrLast(path, (NI)(sepPos + ((NI) 1)), (NI)(dotPos - ((NI) 1))));
		unsureAsgnRef((void**) (&(*Result).Field2), copyStr(path, dotPos));
	}
	LA1_: ;
}
NIM_EXTERNC N_NOINLINE(void, stdlib_ospathsInit000)(void) {
}

NIM_EXTERNC N_NOINLINE(void, stdlib_ospathsDatInit000)(void) {
}

