/* Generated by Nim Compiler v2.2.10 */
/* Compiled for: MacOSX, arm64, clang */
/* Command for C compiler:
   clang -c  -w -ferror-limit=3 -fno-strict-aliasing -pthread -isysroot /Applications/Xcode_16.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -target arm64-apple-darwin24.2.0 -O3   -I/Users/runner/work/nightlies/nightlies/nim-2.2.10/lib -I/Users/runner/work/nightlies/nightlies/nim-2.2.10/dist/atlas/src -o /Users/runner/work/nightlies/nightlies/nim-2.2.10/dist/atlas/.nimcache/@pstd@sprivate@sosfiles.nim.c.o /Users/runner/work/nightlies/nightlies/nim-2.2.10/dist/atlas/.nimcache/@pstd@sprivate@sosfiles.nim.c */
#define NIM_INTBITS 64
#define NIM_EmulateOverflowChecks

#include "nimbase.h"
#include <copyfile.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <time.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__UV3llMMYFckfui8YMBuUZA tyTuple__UV3llMMYFckfui8YMBuUZA;
typedef struct tyTuple__K9bnJYb9aLeQF1tCAa7bW9cWA tyTuple__K9bnJYb9aLeQF1tCAa7bW9cWA;
typedef struct Exception Exception;
typedef struct RootObj RootObj;
typedef struct TNimTypeV2 TNimTypeV2;
typedef struct tySequence__3EvzHGO0xyXGnJBUggwfKQ tySequence__3EvzHGO0xyXGnJBUggwfKQ;
typedef struct tySequence__3EvzHGO0xyXGnJBUggwfKQ_Content tySequence__3EvzHGO0xyXGnJBUggwfKQ_Content;
typedef struct tyObject_StackTraceEntry__lcKzdyiD6sm3eeh28rx7fw tyObject_StackTraceEntry__lcKzdyiD6sm3eeh28rx7fw;
struct NimStrPayload {
	NI cap;
	NIM_CHAR data[SEQ_DECL_SIZE];
};
struct NimStringV2 {
	NI len;
	NimStrPayload* p;
};
typedef NU8 tySet_tyEnum_CopyFlag__6cN1ZxVKOK6LwdRV7k5u2g;
typedef NU8 tyEnum_CopyFlag__6cN1ZxVKOK6LwdRV7k5u2g;
struct tyTuple__UV3llMMYFckfui8YMBuUZA {
	NimStringV2 Field0;
	NimStringV2 Field1;
};
typedef NU16 tySet_tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw;
typedef NU8 tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw;
struct tyTuple__K9bnJYb9aLeQF1tCAa7bW9cWA {
	NimStringV2 Field0;
	tySet_tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw 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__3EvzHGO0xyXGnJBUggwfKQ {
  NI len; tySequence__3EvzHGO0xyXGnJBUggwfKQ_Content* p;
};
struct Exception {
	RootObj Sup;
	Exception* parent;
	NCSTRING name;
	NimStringV2 message;
	tySequence__3EvzHGO0xyXGnJBUggwfKQ trace;
	Exception* up;
};
struct tyObject_StackTraceEntry__lcKzdyiD6sm3eeh28rx7fw {
	NCSTRING procname;
	NI line;
	NCSTRING filename;
};
struct tySequence__3EvzHGO0xyXGnJBUggwfKQ_Content { NI cap; tyObject_StackTraceEntry__lcKzdyiD6sm3eeh28rx7fw data[SEQ_DECL_SIZE]; };
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_u95)(NimStringV2 msg_p0);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nossymlinkExists)(NimStringV2 link_p0);
N_LIB_PRIVATE N_NIMCALL(void, createSymlink__stdZprivateZossymlinks_u10)(NimStringV2 src_p0, NimStringV2 dest_p1);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, expandSymlink__stdZprivateZossymlinks_u16)(NimStringV2 symlinkPath_p0);
N_LIB_PRIVATE N_NOCONV(void, deallocShared)(void* p_p0);
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_u93)(tyTuple__UV3llMMYFckfui8YMBuUZA* x_p0);
N_LIB_PRIVATE N_NIMCALL(NIM_BOOL, nostryRemoveFile)(NimStringV2 file_p0);
N_LIB_PRIVATE N_NIMCALL(void, noscopyFile)(NimStringV2 source_p0, NimStringV2 dest_p1, tySet_tyEnum_CopyFlag__6cN1ZxVKOK6LwdRV7k5u2g options_p2, NI bufferSize_p3);
N_LIB_PRIVATE N_NIMCALL(void, nossetFilePermissions)(NimStringV2 filename_p0, tySet_tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw permissions_p1, NIM_BOOL followSymlinks_p2);
N_LIB_PRIVATE N_NIMCALL(NimStringV2, dollar___stdZprivateZosfiles_u131)(tyTuple__K9bnJYb9aLeQF1tCAa7bW9cWA x_p0);
N_LIB_PRIVATE N_NIMCALL(tySet_tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw, nosgetFilePermissions)(NimStringV2 filename_p0);
static N_INLINE(void, nimZeroMem)(void* p_p0, NI size_p1);
static N_INLINE(void, nimSetMem__system_u2188)(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___system_u3719)(Exception** dest_p0, Exception* src_p1, NIM_BOOL cyclic_p2);
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_THREADVAR NIM_BOOL nimInErrorMode__system_u4198;
extern NIM_THREADVAR Exception* currException__system_u3686;
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_u4198);
	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;
}
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(void, noscopyFile)(NimStringV2 source_p0, NimStringV2 dest_p1, tySet_tyEnum_CopyFlag__6cN1ZxVKOK6LwdRV7k5u2g 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_u95(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__6cN1ZxVKOK6LwdRV7k5u2g)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__6cN1ZxVKOK6LwdRV7k5u2g)0)))&7U)))!=0);
LA16_: ;
		if (!T15_) goto LA17_;
		colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
		colontmpD_ = expandSymlink__stdZprivateZossymlinks_u16(source_p0);
		if (NIM_UNLIKELY(*nimErr_)) goto LA19_;
		createSymlink__stdZprivateZossymlinks_u10(colontmpD_, dest_p1);
		if (NIM_UNLIKELY(*nimErr_)) goto LA19_;
		{
			LA19_:;
		}
		{
			if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD_.p);
}
		}
		if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}
	goto LA13_;
LA17_: ;
	{
		copyfile_state_t state_1;
		int status_1;
		int status2_1;
		state_1 = copyfile_state_alloc();
		status_1 = copyfile(nimToCStringConv(source_p0), nimToCStringConv(dest_p1), state_1, COPYFILE_DATA);
		{
			NimStringV2 colontmpD__2;
			NI32 err_1;
			int T28_;
			tyTuple__UV3llMMYFckfui8YMBuUZA T29_;
			if (!!((status_1 == ((NI32)0)))) goto LA25_;
			colontmpD__2.len = 0; colontmpD__2.p = NIM_NIL;
			err_1 = osLastError__stdZoserrors_u122();
			if (NIM_UNLIKELY(*nimErr_)) goto LA27_;
			T28_ = (int)0;
			T28_ = copyfile_state_free(state_1);
			(void)(T28_);
			T29_.Field0 = source_p0;
			T29_.Field1 = dest_p1;
			colontmpD__2 = dollar___stdZprivateZoscommon_u93((&T29_));
			if (NIM_UNLIKELY(*nimErr_)) goto LA27_;
			raiseOSError__stdZoserrors_u119(err_1, colontmpD__2);
			if (NIM_UNLIKELY(*nimErr_)) goto LA27_;
			{
				LA27_:;
			}
			{
				if (colontmpD__2.p && !(colontmpD__2.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD__2.p);
}
			}
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		}
LA25_: ;
		status2_1 = copyfile_state_free(state_1);
		{
			NimStringV2 colontmpD__3;
			NI32 T37_;
			tyTuple__UV3llMMYFckfui8YMBuUZA T38_;
			if (!!((status2_1 == ((NI32)0)))) goto LA34_;
			colontmpD__3.len = 0; colontmpD__3.p = NIM_NIL;
			T37_ = (NI32)0;
			T37_ = osLastError__stdZoserrors_u122();
			if (NIM_UNLIKELY(*nimErr_)) goto LA36_;
			T38_.Field0 = source_p0;
			T38_.Field1 = dest_p1;
			colontmpD__3 = dollar___stdZprivateZoscommon_u93((&T38_));
			if (NIM_UNLIKELY(*nimErr_)) goto LA36_;
			raiseOSError__stdZoserrors_u119(T37_, colontmpD__3);
			if (NIM_UNLIKELY(*nimErr_)) goto LA36_;
			{
				LA36_:;
			}
			{
				if (colontmpD__3.p && !(colontmpD__3.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD__3.p);
}
			}
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		}
LA34_: ;
	}
LA13_: ;
	}BeforeRet_: ;
}
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;
}
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_u27)(tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw e_p0) {
	NimStringV2 result;
	switch (e_p0) {
	case ((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)0):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_5;
	}
	break;
	case ((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)1):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_7;
	}
	break;
	case ((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)2):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_9;
	}
	break;
	case ((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)3):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_11;
	}
	break;
	case ((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)4):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_13;
	}
	break;
	case ((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)5):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_15;
	}
	break;
	case ((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)6):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_17;
	}
	break;
	case ((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)7):
	{
		result = TM__CMIme9a8i2wZOUbxErcFpJA_19;
	}
	break;
	case ((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)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__bk3PQ1mxFRJKj2pEuekkJw 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__bk3PQ1mxFRJKj2pEuekkJw)2)))&15U)))!=0)) goto LA3_;
		p_1 = (NU16)(p_1 | ((mode_t) (S_IRUSR)));
	}
LA3_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)1)))&15U)))!=0)) goto LA7_;
		p_1 = (NU16)(p_1 | ((mode_t) (S_IWUSR)));
	}
LA7_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)0)))&15U)))!=0)) goto LA11_;
		p_1 = (NU16)(p_1 | ((mode_t) (S_IXUSR)));
	}
LA11_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)5)))&15U)))!=0)) goto LA15_;
		p_1 = (NU16)(p_1 | ((mode_t) (S_IRGRP)));
	}
LA15_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)4)))&15U)))!=0)) goto LA19_;
		p_1 = (NU16)(p_1 | ((mode_t) (S_IWGRP)));
	}
LA19_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)3)))&15U)))!=0)) goto LA23_;
		p_1 = (NU16)(p_1 | ((mode_t) (S_IXGRP)));
	}
LA23_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)8)))&15U)))!=0)) goto LA27_;
		p_1 = (NU16)(p_1 | ((mode_t) (S_IROTH)));
	}
LA27_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)7)))&15U)))!=0)) goto LA31_;
		p_1 = (NU16)(p_1 | ((mode_t) (S_IWOTH)));
	}
LA31_: ;
	{
		if (!((permissions_p1 &((NU16)1<<((NU)((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)6)))&15U)))!=0)) goto LA35_;
		p_1 = (NU16)(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_;
		{
			int T45_;
			NimStringV2 colontmpD_;
			NI32 T49_;
			tyTuple__K9bnJYb9aLeQF1tCAa7bW9cWA T50_;
			T45_ = (int)0;
			T45_ = lchmod(nimToCStringConv(filename_p0), ((mode_t) (p_1)));
			if (!!((T45_ == ((NI32)0)))) goto LA46_;
			colontmpD_.len = 0; colontmpD_.p = NIM_NIL;
			T49_ = (NI32)0;
			T49_ = osLastError__stdZoserrors_u122();
			if (NIM_UNLIKELY(*nimErr_)) goto LA48_;
			T50_.Field0 = filename_p0;
			T50_.Field1 = permissions_p1;
			colontmpD_ = dollar___stdZprivateZosfiles_u131(T50_);
			if (NIM_UNLIKELY(*nimErr_)) goto LA48_;
			raiseOSError__stdZoserrors_u119(T49_, colontmpD_);
			if (NIM_UNLIKELY(*nimErr_)) goto LA48_;
			{
				LA48_:;
			}
			{
				if (colontmpD_.p && !(colontmpD_.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD_.p);
}
			}
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		}
LA46_: ;
	}
	goto LA37_;
LA41_: ;
	{
		{
			int T56_;
			NimStringV2 colontmpD__2;
			NI32 T60_;
			tyTuple__K9bnJYb9aLeQF1tCAa7bW9cWA T61_;
			T56_ = (int)0;
			T56_ = chmod(nimToCStringConv(filename_p0), ((mode_t) (p_1)));
			if (!!((T56_ == ((NI32)0)))) goto LA57_;
			colontmpD__2.len = 0; colontmpD__2.p = NIM_NIL;
			T60_ = (NI32)0;
			T60_ = osLastError__stdZoserrors_u122();
			if (NIM_UNLIKELY(*nimErr_)) goto LA59_;
			T61_.Field0 = filename_p0;
			T61_.Field1 = permissions_p1;
			colontmpD__2 = dollar___stdZprivateZosfiles_u131(T61_);
			if (NIM_UNLIKELY(*nimErr_)) goto LA59_;
			raiseOSError__stdZoserrors_u119(T60_, colontmpD__2);
			if (NIM_UNLIKELY(*nimErr_)) goto LA59_;
			{
				LA59_:;
			}
			{
				if (colontmpD__2.p && !(colontmpD__2.p->cap & NIM_STRLIT_FLAG)) {
 deallocShared(colontmpD__2.p);
}
			}
			if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
		}
LA57_: ;
	}
LA37_: ;
	}BeforeRet_: ;
}
static N_INLINE(void, nimSetMem__system_u2188)(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_u2188(p_p0, ((int)0), size_p1);
}
N_LIB_PRIVATE N_NIMCALL(tySet_tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw, nosgetFilePermissions)(NimStringV2 filename_p0) {
	tySet_tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw result;
	struct stat a_1;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	nimZeroMem((void*)(&result), sizeof(tySet_tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw));
	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 (!!(((NU16)(a_1.st_mode & ((mode_t) (S_IRUSR))) == ((mode_t)0)))) goto LA9_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)2))) & 15);
	}
LA9_: ;
	{
		if (!!(((NU16)(a_1.st_mode & ((mode_t) (S_IWUSR))) == ((mode_t)0)))) goto LA13_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)1))) & 15);
	}
LA13_: ;
	{
		if (!!(((NU16)(a_1.st_mode & ((mode_t) (S_IXUSR))) == ((mode_t)0)))) goto LA17_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)0))) & 15);
	}
LA17_: ;
	{
		if (!!(((NU16)(a_1.st_mode & ((mode_t) (S_IRGRP))) == ((mode_t)0)))) goto LA21_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)5))) & 15);
	}
LA21_: ;
	{
		if (!!(((NU16)(a_1.st_mode & ((mode_t) (S_IWGRP))) == ((mode_t)0)))) goto LA25_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)4))) & 15);
	}
LA25_: ;
	{
		if (!!(((NU16)(a_1.st_mode & ((mode_t) (S_IXGRP))) == ((mode_t)0)))) goto LA29_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)3))) & 15);
	}
LA29_: ;
	{
		if (!!(((NU16)(a_1.st_mode & ((mode_t) (S_IROTH))) == ((mode_t)0)))) goto LA33_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)8))) & 15);
	}
LA33_: ;
	{
		if (!!(((NU16)(a_1.st_mode & ((mode_t) (S_IWOTH))) == ((mode_t)0)))) goto LA37_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)7))) & 15);
	}
LA37_: ;
	{
		if (!!(((NU16)(a_1.st_mode & ((mode_t) (S_IXOTH))) == ((mode_t)0)))) goto LA41_;
		result |= ((NU16)1)<<(((((tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw)6))) & 15);
	}
LA41_: ;
	}BeforeRet_: ;
	return result;
}
static N_INLINE(void, popCurrentException)(void) {
	eqcopy___system_u3719(&currException__system_u3686, (*currException__system_u3686).up, NIM_FALSE);
}
N_LIB_PRIVATE N_NIMCALL(void, copyFileWithPermissions__stdZprivateZosfiles_u384)(NimStringV2 source_p0, NimStringV2 dest_p1, NIM_BOOL ignorePermissionErrors_p2, tySet_tyEnum_CopyFlag__6cN1ZxVKOK6LwdRV7k5u2g options_p3) {
	tySet_tyEnum_FilePermission__bk3PQ1mxFRJKj2pEuekkJw 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__6cN1ZxVKOK6LwdRV7k5u2g)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_: ;
}
