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

#include "nimbase.h"
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <time.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
typedef struct NimStrPayload NimStrPayload;
typedef struct NimStringV2 NimStringV2;
typedef struct tyTuple__mwCuj9awZDY9chWmMUlUHDfA tyTuple__mwCuj9awZDY9chWmMUlUHDfA;
typedef struct Exception Exception;
typedef struct RootObj RootObj;
typedef struct TNimTypeV2 TNimTypeV2;
typedef struct tySequence__S89cE01OvNjsN9c71FKsSrqQ tySequence__S89cE01OvNjsN9c71FKsSrqQ;
typedef struct tySequence__S89cE01OvNjsN9c71FKsSrqQ_Content tySequence__S89cE01OvNjsN9c71FKsSrqQ_Content;
typedef struct tyObject_StackTraceEntry__RcJz5RXFIYjIseutvVFICA tyObject_StackTraceEntry__RcJz5RXFIYjIseutvVFICA;
struct NimStrPayload {
	NI cap;
	NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
	NI len;
	NimStrPayload* p;
};
typedef NU8 tySet_tyEnum_CopyFlag__1j5oUmplkZXgil3SrVhR7g;
typedef NU8 tyEnum_CopyFlag__1j5oUmplkZXgil3SrVhR7g;
typedef NU8 tyEnum_FileMode__YkEVJbjDa9aPvYTBr8yiUWg;
typedef NU16 tySet_tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg;
typedef NU8 tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg;
struct tyTuple__mwCuj9awZDY9chWmMUlUHDfA {
	NimStringV2 Field0;
	tySet_tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg Field1;
};
struct TNimTypeV2 {
	void* destructor;
	NI size;
	NI16 align;
	NI16 depth;
	NU32* display;
	void* traceImpl;
	void* typeInfoV1;
	NI flags;
	void* vTable[SEQ_DECL_SIZE];
};
struct RootObj {
	TNimTypeV2* m_type;
};
struct tySequence__S89cE01OvNjsN9c71FKsSrqQ {
  NI len; tySequence__S89cE01OvNjsN9c71FKsSrqQ_Content* p;
};
struct Exception {
	RootObj Sup;
	Exception* parent;
	NCSTRING name;
	NimStringV2 message;
	tySequence__S89cE01OvNjsN9c71FKsSrqQ trace;
	Exception* up;
};
struct tyObject_StackTraceEntry__RcJz5RXFIYjIseutvVFICA {
	NCSTRING procname;
	NI line;
	NCSTRING filename;
};
struct tySequence__S89cE01OvNjsN9c71FKsSrqQ_Content { NI cap; tyObject_StackTraceEntry__RcJz5RXFIYjIseutvVFICA data[SEQ_DECL_SIZE]; };
static N_INLINE(NCSTRING, nimToCStringConv)(NimStringV2 s_p0);
static N_INLINE(NI, countBits32)(NU32 n_p0);
static N_INLINE(NI, countSetBitsImpl__systemZcountbits95impl_u26)(NU32 x_p0);
N_CDECL(int, __builtin_popcount)(unsigned int x_p0);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
N_LIB_PRIVATE N_NIMCALL(void, failedAssertImpl__stdZassertions_u242)(NimStringV2 msg_p0);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nossymlinkExists)(NimStringV2 link_p0);
N_LIB_PRIVATE N_NIMCALL(void, createSymlink__stdZprivateZossymlinks_u13)(NimStringV2 src_p0, NimStringV2 dest_p1);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, expandSymlink__stdZprivateZossymlinks_u19)(NimStringV2 symlinkPath_p0);
N_LIB_PRIVATE N_NIMCALL(void, eqdestroy___system_u2627)(NimStringV2 dest_p0);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, open__stdZsyncio_u412)(FILE** f_p0, NimStringV2 filename_p1, tyEnum_FileMode__YkEVJbjDa9aPvYTBr8yiUWg mode_p2, NI bufSize_p3);
N_LIB_PRIVATE N_NOINLINE(void, raiseOSError__stdZoserrors_u119)(NI32 errorCode_p0, NimStringV2 additionalInfo_p1);
N_LIB_PRIVATE N_NIMCALL(NI32, osLastError__stdZoserrors_u122)(void);
N_LIB_PRIVATE N_NIMCALL(void, close__stdZsyncio_u268)(FILE* f_p0);
N_LIB_PRIVATE N_NIMCALL(int, getFileHandle__stdZsyncio_u280)(FILE* f_p0);
N_LIB_PRIVATE N_NOCONV(void*, allocImpl__system_u1734)(NI size_p0);
N_LIB_PRIVATE N_NIMCALL(NI, readBuffer__stdZsyncio_u165)(FILE* f_p0, void* buffer_p1, NI len_p2);
N_LIB_PRIVATE N_NIMCALL(NI, writeBuffer__stdZsyncio_u196)(FILE* f_p0, void* buffer_p1, NI len_p2);
N_LIB_PRIVATE N_NOCONV(void, dealloc)(void* p_p0);
N_LIB_PRIVATE N_NIMCALL(void, flushFile__stdZsyncio_u278)(FILE* f_p0);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nostryRemoveFile)(NimStringV2 file_p0);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, tryMoveFSObject__stdZprivateZoscommon_u87)(NimStringV2 source_p0, NimStringV2 dest_p1, NIM_BOOL isDir_p2);
N_LIB_PRIVATE N_NIMCALL(void, copyFileWithPermissions__stdZprivateZosfiles_u363)(NimStringV2 source_p0, NimStringV2 dest_p1, NIM_BOOL ignorePermissionErrors_p2, tySet_tyEnum_CopyFlag__1j5oUmplkZXgil3SrVhR7g options_p3);
N_LIB_PRIVATE N_NIMCALL(void, noscopyFile)(NimStringV2 source_p0, NimStringV2 dest_p1, tySet_tyEnum_CopyFlag__1j5oUmplkZXgil3SrVhR7g options_p2, NI bufferSize_p3);
N_LIB_PRIVATE N_NIMCALL(void, nossetFilePermissions)(NimStringV2 filename_p0, tySet_tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg permissions_p1, NIM_BOOL followSymlinks_p2);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___stdZprivateZosfiles_u134)(tyTuple__mwCuj9awZDY9chWmMUlUHDfA x_p0);
N_LIB_PRIVATE N_NIMCALL(tySet_tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg, nosgetFilePermissions)(NimStringV2 filename_p0);
static N_INLINE(void, nimZeroMem)(void* p_p0, NI size_p1);
static N_INLINE(void, nimSetMem__systemZmemory_u7)(void* a_p0, int v_p1, NI size_p2);
N_LIB_PRIVATE N_NIMCALL(void, raiseDefect)(void);
N_LIB_PRIVATE N_NIMCALL(void, reraiseException)(void);
static N_INLINE(void, popCurrentException)(void);
N_LIB_PRIVATE N_NIMCALL(void, eqcopy___stdZassertions_u22)(Exception** dest_p0, Exception* src_p1, NIM_BOOL cyclic_p2);
N_LIB_PRIVATE N_NIMCALL(void, nosremoveFile)(NimStringV2 file_p0);
static const struct {
  NI cap; NIM_CHAR data[108+1];
} TM__CMIme9a8i2wZOUbxErcFpJA_2 = { 108 | NIM_STRLIT_FLAG, "osfiles.nim(213, 3) `card(copyFlagSymlink * options) == 1` There should be exactly one cfSymlink* in options" };
static const NimStringV2 TM__CMIme9a8i2wZOUbxErcFpJA_3 = {108, (NimStrPayload*)&TM__CMIme9a8i2wZOUbxErcFpJA_2};
static const struct {
  NI cap; NIM_CHAR data[10+1];
} TM__CMIme9a8i2wZOUbxErcFpJA_4 = { 10 | NIM_STRLIT_FLAG, "fpUserExec" };
static const NimStringV2 TM__CMIme9a8i2wZOUbxErcFpJA_5 = {10, (NimStrPayload*)&TM__CMIme9a8i2wZOUbxErcFpJA_4};
static const struct {
  NI cap; NIM_CHAR data[11+1];
} TM__CMIme9a8i2wZOUbxErcFpJA_6 = { 11 | NIM_STRLIT_FLAG, "fpUserWrite" };
static const NimStringV2 TM__CMIme9a8i2wZOUbxErcFpJA_7 = {11, (NimStrPayload*)&TM__CMIme9a8i2wZOUbxErcFpJA_6};
static const struct {
  NI cap; NIM_CHAR data[10+1];
} TM__CMIme9a8i2wZOUbxErcFpJA_8 = { 10 | NIM_STRLIT_FLAG, "fpUserRead" };
static const NimStringV2 TM__CMIme9a8i2wZOUbxErcFpJA_9 = {10, (NimStrPayload*)&TM__CMIme9a8i2wZOUbxErcFpJA_8};
static const struct {
  NI cap; NIM_CHAR data[11+1];
} TM__CMIme9a8i2wZOUbxErcFpJA_10 = { 11 | NIM_STRLIT_FLAG, "fpGroupExec" };
static const NimStringV2 TM__CMIme9a8i2wZOUbxErcFpJA_11 = {11, (NimStrPayload*)&TM__CMIme9a8i2wZOUbxErcFpJA_10};
static const struct {
  NI cap; NIM_CHAR data[12+1];
} TM__CMIme9a8i2wZOUbxErcFpJA_12 = { 12 | NIM_STRLIT_FLAG, "fpGroupWrite" };
static const NimStringV2 TM__CMIme9a8i2wZOUbxErcFpJA_13 = {12, (NimStrPayload*)&TM__CMIme9a8i2wZOUbxErcFpJA_12};
static const struct {
  NI cap; NIM_CHAR data[11+1];
} TM__CMIme9a8i2wZOUbxErcFpJA_14 = { 11 | NIM_STRLIT_FLAG, "fpGroupRead" };
static const NimStringV2 TM__CMIme9a8i2wZOUbxErcFpJA_15 = {11, (NimStrPayload*)&TM__CMIme9a8i2wZOUbxErcFpJA_14};
static const struct {
  NI cap; NIM_CHAR data[12+1];
} TM__CMIme9a8i2wZOUbxErcFpJA_16 = { 12 | NIM_STRLIT_FLAG, "fpOthersExec" };
static const NimStringV2 TM__CMIme9a8i2wZOUbxErcFpJA_17 = {12, (NimStrPayload*)&TM__CMIme9a8i2wZOUbxErcFpJA_16};
static const struct {
  NI cap; NIM_CHAR data[13+1];
} TM__CMIme9a8i2wZOUbxErcFpJA_18 = { 13 | NIM_STRLIT_FLAG, "fpOthersWrite" };
static const NimStringV2 TM__CMIme9a8i2wZOUbxErcFpJA_19 = {13, (NimStrPayload*)&TM__CMIme9a8i2wZOUbxErcFpJA_18};
static const struct {
  NI cap; NIM_CHAR data[12+1];
} TM__CMIme9a8i2wZOUbxErcFpJA_20 = { 12 | NIM_STRLIT_FLAG, "fpOthersRead" };
static const NimStringV2 TM__CMIme9a8i2wZOUbxErcFpJA_21 = {12, (NimStrPayload*)&TM__CMIme9a8i2wZOUbxErcFpJA_20};
static const struct {
  NI cap; NIM_CHAR data[0+1];
} TM__CMIme9a8i2wZOUbxErcFpJA_22 = { 0 | NIM_STRLIT_FLAG, "" };
static const NimStringV2 TM__CMIme9a8i2wZOUbxErcFpJA_23 = {0, (NimStrPayload*)&TM__CMIme9a8i2wZOUbxErcFpJA_22};
extern NIM_BOOL nimInErrorMode__system_u4304;
extern Exception* currException__system_u4008;
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, nostryRemoveFile)(NimStringV2 file_p0) {
	NIM_BOOL result;
	result = NIM_TRUE;
	{
		NIM_BOOL T3_;
		int T4_;
		T3_ = (NIM_BOOL)0;
		T4_ = (int)0;
		T4_ = unlink(nimToCStringConv(file_p0));
		T3_ = !((T4_ == ((NI32)0)));
		if (!(T3_)) goto LA5_;
		T3_ = !((errno == ENOENT));
LA5_: ;
		if (!T3_) goto LA6_;
		result = NIM_FALSE;
	}
LA6_: ;
	return result;
}
static N_INLINE(NI, countSetBitsImpl__systemZcountbits95impl_u26)(NU32 x_p0) {
	NI result;
	NU32 x_2;
	int T1_;
	result = (NI)0;
	x_2 = x_p0;
	T1_ = (int)0;
	T1_ = __builtin_popcount(((unsigned int) (x_2)));
	result = ((NI) (T1_));
	return result;
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4304);
	return result;
}
static N_INLINE(NI, countBits32)(NU32 n_p0) {
	NI result;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	result = (NI)0;
	result = countSetBitsImpl__systemZcountbits95impl_u26(n_p0);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, noscopyFile)(NimStringV2 source_p0, NimStringV2 dest_p1, tySet_tyEnum_CopyFlag__1j5oUmplkZXgil3SrVhR7g options_p2, NI bufferSize_p3) {
	NIM_BOOL isSymlink_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	{
		if (!!((countBits32((7 & options_p2)) == ((NI)1)))) goto LA3_;
		failedAssertImpl__stdZassertions_u242(TM__CMIme9a8i2wZOUbxErcFpJA_3);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA3_: ;
	isSymlink_1 = nossymlinkExists(source_p0);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	{
		NIM_BOOL T7_;
		NIM_BOOL T9_;
		T7_ = (NIM_BOOL)0;
		T7_ = isSymlink_1;
		if (!(T7_)) goto LA8_;
		T9_ = (NIM_BOOL)0;
		T9_ = ((options_p2 &((NU8)1<<((NU)((((tyEnum_CopyFlag__1j5oUmplkZXgil3SrVhR7g)2)))&7U)))!=0);
		if (T9_) goto LA10_;
		T9_ = NIM_FALSE;
LA10_: ;
		T7_ = T9_;
LA8_: ;
		if (!T7_) goto LA11_;
		goto BeforeRet_;
	}
LA11_: ;
	{
		NIM_BOOL T15_;
		NimStringV2 colontmpD_;
		T15_ = (NIM_BOOL)0;
		T15_ = isSymlink_1;
		if (!(T15_)) goto LA16_;
		T15_ = ((options_p2 &((NU8)1<<((NU)((((tyEnum_CopyFlag__1j5oUmplkZXgil3SrVhR7g)0)))&7U)))!=0);
LA16_: ;
		if (!T15_) goto LA17_;
		colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
		colontmpD_ = expandSymlink__stdZprivateZossymlinks_u19(source_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto LA19_;
		createSymlink__stdZprivateZossymlinks_u13(colontmpD_, dest_p1);
		if (NIM_UNLIKELY(*nimErr_)) goto LA19_;
		{
			LA19_:;
		}
		{
			eqdestroy___system_u2627(colontmpD_);
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA13_;
LA17_: ;
	{
		FILE* d_1;
		FILE* s_1;
		int T35_;
		int T36_;
		int T37_;
		int T38_;
		void* buf_1;
		d_1 = (FILE*)0;
		s_1 = (FILE*)0;
		{
			NIM_BOOL T25_;
			NI32 T28_;
			T25_ = (NIM_BOOL)0;
			T25_ = open__stdZsyncio_u412(&s_1, source_p0, ((tyEnum_FileMode__YkEVJbjDa9aPvYTBr8yiUWg)0), ((NI)-1));
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			if (!!(T25_)) goto LA26_;
			T28_ = (NI32)0;
			T28_ = osLastError__stdZoserrors_u122();
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			raiseOSError__stdZoserrors_u119(T28_, source_p0);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		}
LA26_: ;
		{
			NIM_BOOL T31_;
			NI32 T34_;
			T31_ = (NIM_BOOL)0;
			T31_ = open__stdZsyncio_u412(&d_1, dest_p1, ((tyEnum_FileMode__YkEVJbjDa9aPvYTBr8yiUWg)1), ((NI)-1));
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			if (!!(T31_)) goto LA32_;
			close__stdZsyncio_u268(s_1);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			T34_ = (NI32)0;
			T34_ = osLastError__stdZoserrors_u122();
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
			raiseOSError__stdZoserrors_u119(T34_, dest_p1);
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		}
LA32_: ;
		T35_ = (int)0;
		T35_ = getFileHandle__stdZsyncio_u280(d_1);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		T36_ = (int)0;
		T36_ = posix_fadvise(T35_, IL64(0), IL64(0), POSIX_FADV_SEQUENTIAL);
		(void)(T36_);
		T37_ = (int)0;
		T37_ = getFileHandle__stdZsyncio_u280(s_1);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		T38_ = (int)0;
		T38_ = posix_fadvise(T37_, IL64(0), IL64(0), POSIX_FADV_SEQUENTIAL);
		(void)(T38_);
		buf_1 = allocImpl__system_u1734((bufferSize_p3));
		{
			while (1) {
				NI bytesread_1;
				bytesread_1 = readBuffer__stdZsyncio_u165(s_1, buf_1, (bufferSize_p3));
				if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
				{
					NI byteswritten_1;
					if (!(((NI)0) < bytesread_1)) goto LA43_;
					byteswritten_1 = writeBuffer__stdZsyncio_u196(d_1, buf_1, (bytesread_1));
					if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
					{
						NI32 T49_;
						if (!!((bytesread_1 == byteswritten_1))) goto LA47_;
						dealloc(buf_1);
						close__stdZsyncio_u268(s_1);
						if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
						close__stdZsyncio_u268(d_1);
						if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
						T49_ = (NI32)0;
						T49_ = osLastError__stdZoserrors_u122();
						if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
						raiseOSError__stdZoserrors_u119(T49_, dest_p1);
						if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
					}
LA47_: ;
				}
LA43_: ;
				{
					if (!!((bytesread_1 == bufferSize_p3))) goto LA52_;
					goto LA39;
				}
LA52_: ;
			}
		} LA39: ;
		dealloc(buf_1);
		close__stdZsyncio_u268(s_1);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		flushFile__stdZsyncio_u278(d_1);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		close__stdZsyncio_u268(d_1);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA13_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, nosremoveFile)(NimStringV2 file_p0) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	{
		NIM_BOOL T3_;
		NI32 T6_;
		T3_ = (NIM_BOOL)0;
		T3_ = nostryRemoveFile(file_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!!(T3_)) goto LA4_;
		T6_ = (NI32)0;
		T6_ = osLastError__stdZoserrors_u122();
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		raiseOSError__stdZoserrors_u119(T6_, file_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA4_: ;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___stdZprivateZosfiles_u30)(tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg e_p0) {
	NimStringV2 result;
	switch (e_p0) {
	case ((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)0):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_5;
	}
	break;
	case ((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)1):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_7;
	}
	break;
	case ((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)2):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_9;
	}
	break;
	case ((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)3):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_11;
	}
	break;
	case ((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)4):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_13;
	}
	break;
	case ((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)5):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_15;
	}
	break;
	case ((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)6):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_17;
	}
	break;
	case ((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)7):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_19;
	}
	break;
	case ((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)8):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_21;
	}
	break;
	default:
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_23;
	}
	break;
	}
	return result;
}
N_LIB_PRIVATE N_NIMCALL(void, nossetFilePermissions)(NimStringV2 filename_p0, tySet_tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg permissions_p1, NIM_BOOL followSymlinks_p2) {
	mode_t p_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	p_1 = ((mode_t)0);
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)2)))&15U)))!=0)) goto LA3_;
		p_1 = (NU32)(p_1 | ((mode_t) (S_IRUSR)));
	}
LA3_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)1)))&15U)))!=0)) goto LA7_;
		p_1 = (NU32)(p_1 | ((mode_t) (S_IWUSR)));
	}
LA7_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)0)))&15U)))!=0)) goto LA11_;
		p_1 = (NU32)(p_1 | ((mode_t) (S_IXUSR)));
	}
LA11_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)5)))&15U)))!=0)) goto LA15_;
		p_1 = (NU32)(p_1 | ((mode_t) (S_IRGRP)));
	}
LA15_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)4)))&15U)))!=0)) goto LA19_;
		p_1 = (NU32)(p_1 | ((mode_t) (S_IWGRP)));
	}
LA19_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)3)))&15U)))!=0)) goto LA23_;
		p_1 = (NU32)(p_1 | ((mode_t) (S_IXGRP)));
	}
LA23_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)8)))&15U)))!=0)) goto LA27_;
		p_1 = (NU32)(p_1 | ((mode_t) (S_IROTH)));
	}
LA27_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)7)))&15U)))!=0)) goto LA31_;
		p_1 = (NU32)(p_1 | ((mode_t) (S_IWOTH)));
	}
LA31_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)6)))&15U)))!=0)) goto LA35_;
		p_1 = (NU32)(p_1 | ((mode_t) (S_IXOTH)));
	}
LA35_: ;
	{
		NIM_BOOL T39_;
		T39_ = (NIM_BOOL)0;
		T39_ = !(followSymlinks_p2);
		if (!(T39_)) goto LA40_;
		T39_ = nossymlinkExists(filename_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
LA40_: ;
		if (!T39_) goto LA41_;
	}
	goto LA37_;
LA41_: ;
	{
		{
			int T46_;
			NimStringV2 colontmpD_;
			NI32 T50_;
			tyTuple__mwCuj9awZDY9chWmMUlUHDfA T51_;
			T46_ = (int)0;
			T46_ = chmod(nimToCStringConv(filename_p0), ((mode_t) (p_1)));
			if (!!((T46_ == ((NI32)0)))) goto LA47_;
			colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
			T50_ = (NI32)0;
			T50_ = osLastError__stdZoserrors_u122();
			if (NIM_UNLIKELY(*nimErr_)) goto LA49_;
			T51_.Field0 = filename_p0;
			T51_.Field1 = permissions_p1;
			colontmpD_ = dollar___stdZprivateZosfiles_u134(T51_);
			if (NIM_UNLIKELY(*nimErr_)) goto LA49_;
			raiseOSError__stdZoserrors_u119(T50_, colontmpD_);
			if (NIM_UNLIKELY(*nimErr_)) goto LA49_;
			{
				LA49_:;
			}
			{
				eqdestroy___system_u2627(colontmpD_);
			}
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		}
LA47_: ;
	}
LA37_: ;
	}BeforeRet_: ;
}
static N_INLINE(void, nimSetMem__systemZmemory_u7)(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) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	nimSetMem__systemZmemory_u7(p_p0, ((int)0), size_p1);
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(tySet_tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg, nosgetFilePermissions)(NimStringV2 filename_p0) {
	tySet_tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg result;
	struct stat a_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	nimZeroMem((void*)(&result), sizeof(tySet_tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg));
	nimZeroMem((void*)(&a_1), sizeof(struct stat));
	{
		int T3_;
		NI32 T6_;
		T3_ = (int)0;
		T3_ = stat(nimToCStringConv(filename_p0), (&a_1));
		if (!(T3_ < ((NI32)0))) goto LA4_;
		T6_ = (NI32)0;
		T6_ = osLastError__stdZoserrors_u122();
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		raiseOSError__stdZoserrors_u119(T6_, filename_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA4_: ;
	result = 0;
	{
		if (!!(((NU32)(a_1.st_mode & ((mode_t) (S_IRUSR))) == ((mode_t)0)))) goto LA9_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)2))) & 15);
	}
LA9_: ;
	{
		if (!!(((NU32)(a_1.st_mode & ((mode_t) (S_IWUSR))) == ((mode_t)0)))) goto LA13_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)1))) & 15);
	}
LA13_: ;
	{
		if (!!(((NU32)(a_1.st_mode & ((mode_t) (S_IXUSR))) == ((mode_t)0)))) goto LA17_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)0))) & 15);
	}
LA17_: ;
	{
		if (!!(((NU32)(a_1.st_mode & ((mode_t) (S_IRGRP))) == ((mode_t)0)))) goto LA21_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)5))) & 15);
	}
LA21_: ;
	{
		if (!!(((NU32)(a_1.st_mode & ((mode_t) (S_IWGRP))) == ((mode_t)0)))) goto LA25_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)4))) & 15);
	}
LA25_: ;
	{
		if (!!(((NU32)(a_1.st_mode & ((mode_t) (S_IXGRP))) == ((mode_t)0)))) goto LA29_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)3))) & 15);
	}
LA29_: ;
	{
		if (!!(((NU32)(a_1.st_mode & ((mode_t) (S_IROTH))) == ((mode_t)0)))) goto LA33_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)8))) & 15);
	}
LA33_: ;
	{
		if (!!(((NU32)(a_1.st_mode & ((mode_t) (S_IWOTH))) == ((mode_t)0)))) goto LA37_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)7))) & 15);
	}
LA37_: ;
	{
		if (!!(((NU32)(a_1.st_mode & ((mode_t) (S_IXOTH))) == ((mode_t)0)))) goto LA41_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg)6))) & 15);
	}
LA41_: ;
	}BeforeRet_: ;
	return result;
}
static N_INLINE(void, popCurrentException)(void) {
	eqcopy___stdZassertions_u22(&currException__system_u4008, (*currException__system_u4008).up, NIM_FALSE);
}
N_LIB_PRIVATE N_NIMCALL(void, copyFileWithPermissions__stdZprivateZosfiles_u363)(NimStringV2 source_p0, NimStringV2 dest_p1, NIM_BOOL ignorePermissionErrors_p2, tySet_tyEnum_CopyFlag__1j5oUmplkZXgil3SrVhR7g options_p3) {
	tySet_tyEnum_FilePermission__gpXj3SqAxcWRbUz4RaRDEg T2_;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	noscopyFile(source_p0, dest_p1, options_p3, ((NI)16384));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	T2_ = nosgetFilePermissions(source_p0);
	if (NIM_UNLIKELY(*nimErr_)) goto LA1_;
	nossetFilePermissions(dest_p1, T2_, ((options_p3 &((NU8)1<<((NU)((((tyEnum_CopyFlag__1j5oUmplkZXgil3SrVhR7g)1)))&7U)))!=0));
	if (NIM_UNLIKELY(*nimErr_)) goto LA1_;
	if (NIM_UNLIKELY(*nimErr_)) {
		LA1_:;
		{
			*nimErr_ = NIM_FALSE;
			raiseDefect();
			{
				if (!!(ignorePermissionErrors_p2)) goto LA8_;
				reraiseException();
goto LA4_;
			}
LA8_: ;
			popCurrentException();
			LA4_:;
		}
	}
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
}
N_LIB_PRIVATE N_NIMCALL(void, nosmoveFile)(NimStringV2 source_p0, NimStringV2 dest_p1) {
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = tryMoveFSObject__stdZprivateZoscommon_u87(source_p0, dest_p1, NIM_FALSE);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		if (!!(T3_)) goto LA4_;
		copyFileWithPermissions__stdZprivateZosfiles_u363(source_p0, dest_p1, NIM_TRUE, 1);
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		nosremoveFile(source_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto LA6_;
		if (NIM_UNLIKELY(*nimErr_)) {
			LA6_:;
			{
				NIM_BOOL T10_;
				*nimErr_ = NIM_FALSE;
				raiseDefect();
				T10_ = (NIM_BOOL)0;
				T10_ = nostryRemoveFile(dest_p1);
				if (NIM_UNLIKELY(*nimErr_)) goto LA8_;
				(void)(T10_);
				reraiseException();
goto LA8_;
				popCurrentException();
				LA8_:;
			}
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
LA4_: ;
	}BeforeRet_: ;
}
