/* Generated by Nim Compiler v2.2.10 */
#define NIM_INTBITS 64
#define NIM_EmulateOverflowChecks

#include "nimbase.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <errno.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
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
typedef struct tyTuple__wjbnfGBIEcH6aaevyJWrgw tyTuple__wjbnfGBIEcH6aaevyJWrgw;
typedef struct tyTuple__UV3llMMYFckfui8YMBuUZA tyTuple__UV3llMMYFckfui8YMBuUZA;
struct NimStrPayload {
	NI cap;
	NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
	NI len;
	NimStrPayload* p;
};
typedef NU8 tyEnum_PathComponent__daMOTwam9cW3AQtl6fxq4sQ;
struct tyTuple__wjbnfGBIEcH6aaevyJWrgw {
	tyEnum_PathComponent__daMOTwam9cW3AQtl6fxq4sQ Field0;
	NIM_BOOL Field1;
};
struct tyTuple__UV3llMMYFckfui8YMBuUZA {
	NimStringV2 Field0;
	NimStringV2 Field1;
};
static N_INLINE(void, nimZeroMem)(void* p_p0, NI size_p1);
static N_INLINE(void, nimSetMem__system_u2172)(void* a_p0, int v_p1, NI size_p2);
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0);
N_LIB_PRIVATE N_NIMCALL(NI32, osLastError__stdZoserrors_u122)(void);
N_LIB_PRIVATE N_NOINLINE(void, raiseOSError__stdZoserrors_u119)(NI32 errorCode_p0, NimStringV2 additionalInfo_p1);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___stdZprivateZoscommon_u94)(tyTuple__UV3llMMYFckfui8YMBuUZA* x_p0);
N_LIB_PRIVATE N_NIMCALL(void, eqdestroy___system_u2691)(NimStringV2 dest_p0);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
extern NIM_BOOL nimInErrorMode__system_u4143;
static N_INLINE(void, nimSetMem__system_u2172)(void* a_p0, int v_p1, NI size_p2) {
	void* T1_;
	T1_ = (void*)0;
	T1_ = memset(a_p0, v_p1, ((size_t) (size_p2)));
}
static N_INLINE(void, nimZeroMem)(void* p_p0, NI size_p1) {
	nimSetMem__system_u2172(p_p0, ((int)0), size_p1);
}
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0) {
	NCSTRING result;
	{
		if (!(s_p0.len == ((NI)0))) goto LA3_;
		result = "";
	}
	goto LA1_;
LA3_: ;
	{
		result = ((NCSTRING) ((*s_p0.p).data));
	}
LA1_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nosfileExists)(NimStringV2 filename_p0) {
	NIM_BOOL result;
	struct stat res_1;
	NIM_BOOL T1_;
	int T2_;
{	nimZeroMem((void*)(&res_1), sizeof(struct stat));
	T1_ = (NIM_BOOL)0;
	T2_ = (int)0;
	T2_ = stat(nimToCStringConv(filename_p0), (&res_1));
	T1_ = (((NI32)0) <= T2_);
	if (!(T1_)) goto LA3_;
	T1_ = S_ISREG(res_1.st_mode);
LA3_: ;
	result = T1_;
	goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(tyTuple__wjbnfGBIEcH6aaevyJWrgw, getSymlinkFileKind__stdZprivateZoscommon_u20)(NimStringV2 path_p0) {
	tyTuple__wjbnfGBIEcH6aaevyJWrgw result;
	struct stat s_1;
	tyEnum_PathComponent__daMOTwam9cW3AQtl6fxq4sQ colontmp_;
	NIM_BOOL colontmp__2;
	nimZeroMem((void*)(&s_1), sizeof(struct stat));
	colontmp_ = ((tyEnum_PathComponent__daMOTwam9cW3AQtl6fxq4sQ)1);
	colontmp__2 = NIM_FALSE;
	result.Field0 = colontmp_;
	result.Field1 = colontmp__2;
	{
		int T3_;
		T3_ = (int)0;
		T3_ = stat(nimToCStringConv(path_p0), (&s_1));
		if (!(T3_ == ((NI32)0))) goto LA4_;
		{
			NIM_BOOL T8_;
			tyEnum_PathComponent__daMOTwam9cW3AQtl6fxq4sQ colontmp__3;
			NIM_BOOL colontmp__4;
			T8_ = (NIM_BOOL)0;
			T8_ = S_ISDIR(s_1.st_mode);
			if (!T8_) goto LA9_;
			colontmp__3 = ((tyEnum_PathComponent__daMOTwam9cW3AQtl6fxq4sQ)3);
			colontmp__4 = NIM_FALSE;
			result.Field0 = colontmp__3;
			result.Field1 = colontmp__4;
		}
		goto LA6_;
LA9_: ;
		{
			NIM_BOOL T12_;
			tyEnum_PathComponent__daMOTwam9cW3AQtl6fxq4sQ colontmp__5;
			NIM_BOOL colontmp__6;
			T12_ = (NIM_BOOL)0;
			T12_ = S_ISREG(s_1.st_mode);
			if (!!(T12_)) goto LA13_;
			colontmp__5 = ((tyEnum_PathComponent__daMOTwam9cW3AQtl6fxq4sQ)1);
			colontmp__6 = NIM_TRUE;
			result.Field0 = colontmp__5;
			result.Field1 = colontmp__6;
		}
		goto LA6_;
LA13_: ;
LA6_: ;
	}
LA4_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nosdirExists)(NimStringV2 dir_p0) {
	NIM_BOOL result;
	struct stat res_1;
	NIM_BOOL T1_;
	int T2_;
	nimZeroMem((void*)(&res_1), sizeof(struct stat));
	T1_ = (NIM_BOOL)0;
	T2_ = (int)0;
	T2_ = stat(nimToCStringConv(dir_p0), (&res_1));
	T1_ = (((NI32)0) <= T2_);
	if (!(T1_)) goto LA3_;
	T1_ = S_ISDIR(res_1.st_mode);
LA3_: ;
	result = T1_;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nossymlinkExists)(NimStringV2 link_p0) {
	NIM_BOOL result;
	struct stat res_1;
	NIM_BOOL T1_;
	int T2_;
	nimZeroMem((void*)(&res_1), sizeof(struct stat));
	T1_ = (NIM_BOOL)0;
	T2_ = (int)0;
	T2_ = lstat(nimToCStringConv(link_p0), (&res_1));
	T1_ = (((NI32)0) <= T2_);
	if (!(T1_)) goto LA3_;
	T1_ = S_ISLNK(res_1.st_mode);
LA3_: ;
	result = T1_;
	return result;
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4143);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, tryMoveFSObject__stdZprivateZoscommon_u87)(NimStringV2 source_p0, NimStringV2 dest_p1, NIM_BOOL isDir_p2) {
	NIM_BOOL result;
	int T1_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	T1_ = (int)0;
	T1_ = rename(nimToCStringConv(source_p0), nimToCStringConv(dest_p1));
	result = (T1_ == ((NI32)0));
	{
		NI32 err_1;
		NIM_BOOL isAccessDeniedError_1;
		if (!!(result)) goto LA4_;
		err_1 = osLastError__stdZoserrors_u122();
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		isAccessDeniedError_1 = (err_1 == ((NI32) (EXDEV)));
		{
			NimStringV2 colontmpD_;
			tyTuple__UV3llMMYFckfui8YMBuUZA T11_;
			if (!!(isAccessDeniedError_1)) goto LA8_;
			colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
			T11_.Field0 = source_p0;
			T11_.Field1 = dest_p1;
			colontmpD_ = dollar___stdZprivateZoscommon_u94((&T11_));
			if (NIM_UNLIKELY(*nimErr_)) goto LA10_;
			raiseOSError__stdZoserrors_u119(err_1, colontmpD_);
			if (NIM_UNLIKELY(*nimErr_)) goto LA10_;
			{
				LA10_:;
			}
			{
				eqdestroy___system_u2691(colontmpD_);
			}
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		}
LA8_: ;
	}
LA4_: ;
	}BeforeRet_: ;
	return result;
}
