/* 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@smonotimes.nim.c.o /Users/runner/work/nightlies/nightlies/nim-2.2.10/dist/atlas/.nimcache/@pstd@smonotimes.nim.c */
#define NIM_INTBITS 64
#define NIM_EmulateOverflowChecks

#include "nimbase.h"
#include <string.h>
#include <mach/mach.h>
#include <mach/mach_time.h>
#include <math.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 tyObject_MonoTime__OPj9am9cm67Ww8xBOG3ksEhw tyObject_MonoTime__OPj9am9cm67Ww8xBOG3ksEhw;
typedef struct tyObject_Duration__IhPGomXjacpk8ChnxqMuoA tyObject_Duration__IhPGomXjacpk8ChnxqMuoA;
struct tyObject_MonoTime__OPj9am9cm67Ww8xBOG3ksEhw {
	NI64 ticks;
};
struct tyObject_Duration__IhPGomXjacpk8ChnxqMuoA {
	NI64 seconds;
	NI nanosecond;
};
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);
static N_INLINE(NIM_BOOL, nimMulInt64)(NI64 a_p0, NI64 b_p1, NI64* res_p2);
static N_INLINE(NF, toBiggestFloat__system_u1708)(NI64 i_p0);
static N_INLINE(NF, abs__system_u5188)(NF x_p0);
N_LIB_PRIVATE N_NOINLINE(void, raiseOverflow)(void);
N_LIB_PRIVATE N_NOINLINE(void, raiseDivByZero)(void);
static N_INLINE(NIM_BOOL, nimDivInt64)(NI64 a_p0, NI64 b_p1, NI64* res_p2);
N_LIB_PRIVATE N_NIMCALL(tyObject_Duration__IhPGomXjacpk8ChnxqMuoA, initDuration__pureZtimes_u491)(NI64 nanoseconds_p0, NI64 microseconds_p1, NI64 milliseconds_p2, NI64 seconds_p3, NI64 minutes_p4, NI64 hours_p5, NI64 days_p6, NI64 weeks_p7);
static N_INLINE(NIM_BOOL, nimSubInt64)(NI64 a_p0, NI64 b_p1, NI64* res_p2);
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void);
extern NIM_THREADVAR NIM_BOOL nimInErrorMode__system_u4198;
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);
}
static N_INLINE(NF, toBiggestFloat__system_u1708)(NI64 i_p0) {
	NF result;
	result = ((NF) (i_p0));
	return result;
}
static N_INLINE(NF, abs__system_u5188)(NF x_p0) {
	NF result;
	result = (NF)0;
	result = fabs(x_p0);
	return result;
}
static N_INLINE(NIM_BOOL, nimMulInt64)(NI64 a_p0, NI64 b_p1, NI64* res_p2) {
	NIM_BOOL result;
	NI64 r_1;
	NF floatProd_1;
	NF T1_;
	NF T2_;
	NF resAsFloat_1;
	result = (NIM_BOOL)0;
	r_1 = ((NI64) ((NU64)((NU64)(((NU64) (a_p0))) * (NU64)(((NU64) (b_p1))))));
	T1_ = (NF)0;
	T1_ = toBiggestFloat__system_u1708(a_p0);
	T2_ = (NF)0;
	T2_ = toBiggestFloat__system_u1708(b_p1);
	floatProd_1 = ((NF)(T1_) * (NF)(T2_));
	resAsFloat_1 = toBiggestFloat__system_u1708(r_1);
	{
		if (!(resAsFloat_1 == floatProd_1)) goto LA5_;
		(*res_p2) = r_1;
	}
	goto LA3_;
LA5_: ;
	{
		{
			NF T10_;
			NF T11_;
			T10_ = (NF)0;
			T10_ = abs__system_u5188(((NF)(resAsFloat_1) - (NF)(floatProd_1)));
			T11_ = (NF)0;
			T11_ = abs__system_u5188(floatProd_1);
			if (!(((NF)(32.0) * (NF)(T10_)) <= T11_)) goto LA12_;
			(*res_p2) = r_1;
		}
		goto LA8_;
LA12_: ;
		{
			result = NIM_TRUE;
		}
LA8_: ;
	}
LA3_: ;
	return result;
}
static N_INLINE(NIM_BOOL, nimDivInt64)(NI64 a_p0, NI64 b_p1, NI64* res_p2) {
	NIM_BOOL result;
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = (a_p0 == (IL64(-9223372036854775807) - IL64(1)));
		if (!(T3_)) goto LA4_;
		T3_ = (b_p1 == IL64(-1));
LA4_: ;
		if (!T3_) goto LA5_;
		result = NIM_TRUE;
	}
	goto LA1_;
LA5_: ;
	{
		result = NIM_FALSE;
		(*res_p2) = (NI64)(a_p0 / b_p1);
	}
LA1_: ;
	return result;
}
N_LIB_PRIVATE N_NIMCALL(tyObject_MonoTime__OPj9am9cm67Ww8xBOG3ksEhw, getMonoTime__stdZmonotimes_u10)(void) {
	tyObject_MonoTime__OPj9am9cm67Ww8xBOG3ksEhw result;
	NI64 ticks_1;
	mach_timebase_info_data_t machAbsoluteTimeFreq_1;
	NI64 TM__IP4V1hRabVpf8OnX9bWuPxw_2;
	NI64 TM__IP4V1hRabVpf8OnX9bWuPxw_3;
{	nimZeroMem((void*)(&result), sizeof(tyObject_MonoTime__OPj9am9cm67Ww8xBOG3ksEhw));
	ticks_1 = mach_absolute_time();
	nimZeroMem((void*)(&machAbsoluteTimeFreq_1), sizeof(mach_timebase_info_data_t));
	mach_timebase_info((&machAbsoluteTimeFreq_1));
	if (nimMulInt64(ticks_1, ((NI64) (machAbsoluteTimeFreq_1.numer)), &TM__IP4V1hRabVpf8OnX9bWuPxw_2)) { raiseOverflow(); goto BeforeRet_;
	};
	if (((NI64) (machAbsoluteTimeFreq_1.denom)) == 0){ raiseDivByZero(); goto BeforeRet_;
	}
	if (nimDivInt64((NI64)(TM__IP4V1hRabVpf8OnX9bWuPxw_2), ((NI64) (machAbsoluteTimeFreq_1.denom)), &TM__IP4V1hRabVpf8OnX9bWuPxw_3)) { raiseOverflow(); goto BeforeRet_;
	};
	result.ticks = (NI64)(TM__IP4V1hRabVpf8OnX9bWuPxw_3);
	}BeforeRet_: ;
	return result;
}
static N_INLINE(NIM_BOOL, nimSubInt64)(NI64 a_p0, NI64 b_p1, NI64* res_p2) {
	NIM_BOOL result;
	NI64 r_1;
	result = (NIM_BOOL)0;
	r_1 = ((NI64) ((NU64)((NU64)(((NU64) (a_p0))) - (NU64)(((NU64) (b_p1))))));
	{
		NIM_BOOL T3_;
		T3_ = (NIM_BOOL)0;
		T3_ = (IL64(0) <= (NI64)(r_1 ^ a_p0));
		if (T3_) goto LA4_;
		T3_ = (IL64(0) <= (NI64)(r_1 ^ (NI64)((NU64) ~(b_p1))));
LA4_: ;
		if (!T3_) goto LA5_;
		(*res_p2) = r_1;
	}
	goto LA1_;
LA5_: ;
	{
		result = NIM_TRUE;
	}
LA1_: ;
	return result;
}
static N_INLINE(NIM_BOOL*, nimErrorFlag)(void) {
	NIM_BOOL* result;
	result = (&nimInErrorMode__system_u4198);
	return result;
}
N_LIB_PRIVATE N_NIMCALL(tyObject_Duration__IhPGomXjacpk8ChnxqMuoA, minus___stdZmonotimes_u63)(tyObject_MonoTime__OPj9am9cm67Ww8xBOG3ksEhw a_p0, tyObject_MonoTime__OPj9am9cm67Ww8xBOG3ksEhw b_p1) {
	tyObject_Duration__IhPGomXjacpk8ChnxqMuoA result;
	NI64 TM__IP4V1hRabVpf8OnX9bWuPxw_4;
NIM_BOOL* nimErr_;
{nimErr_ = nimErrorFlag();
	nimZeroMem((void*)(&result), sizeof(tyObject_Duration__IhPGomXjacpk8ChnxqMuoA));
	if (nimSubInt64(a_p0.ticks, b_p1.ticks, &TM__IP4V1hRabVpf8OnX9bWuPxw_4)) { raiseOverflow(); goto BeforeRet_;
	};
	result = initDuration__pureZtimes_u491((NI64)(TM__IP4V1hRabVpf8OnX9bWuPxw_4), IL64(0), IL64(0), IL64(0), IL64(0), IL64(0), IL64(0), IL64(0));
	if (NIM_UNLIKELY(*nimErr_)) goto BeforeRet_;
	}BeforeRet_: ;
	return result;
}
