From 45f4ddb4c4eb6fed278fe5ebcac546ef0ebad973 Mon Sep 17 00:00:00 2001 From: Dennis Ranke Date: Tue, 4 Apr 2023 23:58:46 +0200 Subject: [PATCH] start calling into wasm2c version of platform --- Makefile | 8 +- loader.wasm | Bin 1269 -> 1282 bytes main.c | 89 +- platform.c | 4242 ++++++++++++++++++++++++++++++++++++++++++++++++ platform.h | 147 ++ platform.uw8 | Bin 3892 -> 4097 bytes wasm-rt-impl.c | 504 ++++++ wasm-rt-impl.h | 72 + wasm-rt.h | 409 +++++ 9 files changed, 5453 insertions(+), 18 deletions(-) create mode 100644 platform.c create mode 100644 platform.h create mode 100644 wasm-rt-impl.c create mode 100644 wasm-rt-impl.h create mode 100644 wasm-rt.h diff --git a/Makefile b/Makefile index b67a396..ea70ff3 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ WASM3_C := $(wildcard wasm3/source/*.c) WASM3_O := $(WASM3_C:.c=.o) -uw8-wasm3: main.o $(WASM3_O) +uw8-wasm3: main.o $(WASM3_O) platform.o wasm-rt-impl.o gcc -g -lm -lSDL2 -o uw8-wasm3 $^ run: uw8-wasm3 .PHONY @@ -11,10 +11,10 @@ run-ts: deno run --allow-read main.ts wasm3/source/%.o: wasm3/source/%.c - gcc -g -O2 -c -o $@ $^ + gcc -g -O2 -c -o $@ $< -main.o: main.c - gcc -g -O2 -c -o main.o main.c +%.o: %.c platform.h wasm-rt.h wasm-rt-impl.h + gcc -g -O2 -c -o $@ $< clean: rm uw8-wasm3 main.o $(WASM3_O) diff --git a/loader.wasm b/loader.wasm index 83425e2095c469579b1e332e8906775cf66e5800..ac3ef2a9f65fc995f60da4cab334e51306687cc9 100644 GIT binary patch delta 512 zcmV+b0{{K>34#i+4FiAk0|5X*01NB`|DTt}8u~LH zU0Ota>858xC6*bb^Fh^_ewQ8facOklTdYqR1qw8ub*ui*uyN5;Tdh0vF&qyF*qXdx z=9@+0j>wdWu*677Nov7v(q5)Eo(qHMjb6!u8ue8C1F_FHM$3P$3nKL2zjeC_aEnCz zn3R69QT*A-3Y0EWE379!DgpOTBuV1f_(*P?IBi&PI}vO!bqnHwgCR{0g32$KdRY>y zpr;85*{lkeuJJ5M?*3rgcODH47bh2a(8!=r4Fo)&J*=nET5=>G;(@}_QCZ*$Rw3%B zn~(a8P?~p8$|!$4uSOmRfuEB25Wvc|jlGd-*U6;_(XZ99P+F_6_ev=|DRi;a5=ewTyWvEk2w}f^xW^0+_(D5 CZ3OWE delta 499 zcmVzH<&UgS-0dkIF0MM)4 zSb0XAUT-`6EC3gR40+3EzqN}RhmER*S6&yN@3hgfyodIB>AZh2VqIbQ&74UVVAjVnx_QqP2R8#07MfZWR=gD>I$R8yd<`5h2q zE$s{i$>Ayz#GtY+%lmQm`3hf{3zBZLoJ5tFA`Vgr92$iVS5rj}X9Ssfdd(RQVI|#Y zhnUS&1H>M9{AzzTwjy)5pLG4i1Xa09tWnxBcXCgcUr^n_!(%o=B*nAJG*h0bW`8HW zfzMtag^b^=f8Pr7P}*QktoG6(F@EV?QBbS0&h(YYRobFpse5)eSG*!HOTMDELw4BF&{} z0q?H&ERO-%%+Xt?j^uZDbZ0K!e9Y$aOWTk+&ho~l*Mc!S*`vR71aEXRy(Azq2(bCy p=~l7Y6i!G{NmSr~@S6xvvp~{~1CX^Ow7I2=f>A5*>z(1UsQOh|`eFb8 diff --git a/main.c b/main.c index 3c41cf0..c16e9e6 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,6 @@ #include "wasm3/source/wasm3.h" #include "wasm3/source/m3_env.h" +#include "platform.h" #include "SDL2/SDL.h" #include "SDL2/SDL_video.h" #include "SDL2/SDL_render.h" @@ -21,6 +22,27 @@ void* loadFile(size_t* sizeOut, const char* filename) { return buffer; } +#define MATH1(name) \ +f32 Z_envZ_##name(struct Z_env_instance_t* i, f32 v) { \ + return name##f(v); \ +} +#define MATH2(name) \ +f32 Z_envZ_##name(struct Z_env_instance_t* i, f32 a, f32 b) { \ + return name##f(a, b); \ +} +MATH1(acos); MATH1(asin); MATH1(atan); MATH2(atan2); +MATH1(cos); MATH1(sin); MATH1(tan); +MATH1(exp); MATH2(pow); +void Z_envZ_logChar(struct Z_env_instance_t* i, u32 c) {} + +u32 reservedGlobal; +#define G_RESERVED(n) u32* Z_envZ_g_reserved##n(struct Z_env_instance_t* i) { return &reservedGlobal; } +G_RESERVED(0); G_RESERVED(1); G_RESERVED(2); G_RESERVED(3); +G_RESERVED(4); G_RESERVED(5); G_RESERVED(6); G_RESERVED(7); +G_RESERVED(8); G_RESERVED(9); G_RESERVED(10); G_RESERVED(11); +G_RESERVED(12); G_RESERVED(13); G_RESERVED(14); G_RESERVED(15); +wasm_rt_memory_t* Z_envZ_memory(struct Z_env_instance_t* i) { return (wasm_rt_memory_t*)i; } + void verifyM3(IM3Runtime runtime, M3Result result) { if (result != m3Err_none) { M3ErrorInfo info; @@ -86,6 +108,25 @@ m3ApiRawFunction(platformTrampoline) { m3ApiSuccess(); } +m3ApiRawFunction(callCircle) { + Z_platformZ_circle((Z_platform_instance_t*)_ctx->userdata, *(f32*)&_sp[0], *(f32*)&_sp[1], *(f32*)&_sp[2], _sp[3]); + m3ApiSuccess(); +} + +m3ApiRawFunction(callBlitSprite) { + Z_platformZ_blitSprite((Z_platform_instance_t*)_ctx->userdata, _sp[0], _sp[1], _sp[2], _sp[3], _sp[4]); + m3ApiSuccess(); +} + +struct { + const char* name; + const char* signature; + M3RawCall function; +} cPlatformFunctions[] = { + { "circle", "v(fffi)", callCircle }, + { "blitSprite", "v(iiiii)", callBlitSprite } +}; + void appendType(char* signature, M3ValueType type) { if(type == c_m3Type_i32) { strcat(signature, "i"); @@ -99,24 +140,33 @@ void appendType(char* signature, M3ValueType type) { } } -void linkPlatformFunctions(IM3Runtime runtime, IM3Module cartMod, IM3Module platformMod) { +void linkPlatformFunctions(IM3Runtime runtime, IM3Module cartMod, IM3Module platformMod, Z_platform_instance_t* platformInstance) { for(u32 functionIndex = 0; functionIndex < platformMod->numFunctions; ++functionIndex) { M3Function function = platformMod->functions[functionIndex]; if(function.export_name != NULL) { - IM3Function iFunc; - verifyM3(runtime, m3_FindFunction(&iFunc, runtime, function.export_name)); - char signature[128] = { 0 }; - if(m3_GetRetCount(iFunc) > 0) { - appendType(signature, m3_GetRetType(iFunc, 0)); - } else { - strcat(signature, "v"); + bool foundCImpl = false; + for(int i = 0; i * sizeof(cPlatformFunctions[0]) < sizeof(cPlatformFunctions); ++i) { + if(strcmp(function.export_name, cPlatformFunctions[i].name) == 0) { + m3_LinkRawFunctionEx(cartMod, "env", function.export_name, cPlatformFunctions[i].signature, cPlatformFunctions[i].function, platformInstance); + foundCImpl = true; + } } - strcat(signature, "("); - for(uint32_t i = 0; i < m3_GetArgCount(iFunc); ++i) { - appendType(signature, m3_GetArgType(iFunc, i)); + if(!foundCImpl) { + IM3Function iFunc; + verifyM3(runtime, m3_FindFunction(&iFunc, runtime, function.export_name)); + char signature[128] = { 0 }; + if(m3_GetRetCount(iFunc) > 0) { + appendType(signature, m3_GetRetType(iFunc, 0)); + } else { + strcat(signature, "v"); + } + strcat(signature, "("); + for(uint32_t i = 0; i < m3_GetArgCount(iFunc); ++i) { + appendType(signature, m3_GetArgType(iFunc, i)); + } + strcat(signature, ")"); + m3_LinkRawFunctionEx(cartMod, "env", function.export_name, signature, platformTrampoline, iFunc); } - strcat(signature, ")"); - m3_LinkRawFunctionEx(cartMod, "env", function.export_name, signature, platformTrampoline, iFunc); } } } @@ -141,6 +191,8 @@ const uint32_t uw8buttonScanCodes[] = { typedef struct { IM3Runtime runtime; IM3Module platform; + wasm_rt_memory_t memory_c; + Z_platform_instance_t platform_c; IM3Module cart; } Uw8Runtime; @@ -150,6 +202,12 @@ void initRuntime(Uw8Runtime* runtime, IM3Environment env, runtime->runtime->memory.maxPages = 4; verifyM3(runtime->runtime, ResizeMemory(runtime->runtime, 4)); + runtime->memory_c.data = m3_GetMemory(runtime->runtime, NULL, 0); + runtime->memory_c.max_pages = 4; + runtime->memory_c.pages = 4; + runtime->memory_c.size = 256*1024; + Z_platform_instantiate(&runtime->platform_c, (struct Z_env_instance_t*)&runtime->memory_c); + verifyM3(runtime->runtime, m3_ParseModule(env, &runtime->platform, platform, platformSize)); runtime->platform->memoryImported = true; verifyM3(runtime->runtime, m3_LoadModule(runtime->runtime, runtime->platform)); @@ -161,7 +219,7 @@ void initRuntime(Uw8Runtime* runtime, IM3Environment env, runtime->platform->memoryImported = true; verifyM3(runtime->runtime, m3_LoadModule(runtime->runtime, runtime->cart)); linkSystemFunctions(runtime->runtime, runtime->cart); - linkPlatformFunctions(runtime->runtime, runtime->cart, runtime->platform); + linkPlatformFunctions(runtime->runtime, runtime->cart, runtime->platform, &runtime->platform_c); verifyM3(runtime->runtime, m3_CompileModule(runtime->cart)); verifyM3(runtime->runtime, m3_RunStart(runtime->cart)); } @@ -226,6 +284,9 @@ int main(int argc, const char** argv) { m3_FreeRuntime(loaderRuntime); + wasm_rt_init(); + Z_platform_init_module(); + bool quit = false; while(!quit) { Uw8Runtime runtime; diff --git a/platform.c b/platform.c new file mode 100644 index 0000000..8e2b2c9 --- /dev/null +++ b/platform.c @@ -0,0 +1,4242 @@ +/* Automatically generated by wasm2c */ +#include +#include +#include +#include +#if defined(_MSC_VER) +#include +#include +#define alloca _alloca +#else +#include +#endif + +#include "platform.h" + +#define TRAP(x) (wasm_rt_trap(WASM_RT_TRAP_##x), 0) + +#if WASM_RT_USE_STACK_DEPTH_COUNT +#define FUNC_PROLOGUE \ + if (++wasm_rt_call_stack_depth > WASM_RT_MAX_CALL_STACK_DEPTH) \ + TRAP(EXHAUSTION); + +#define FUNC_EPILOGUE --wasm_rt_call_stack_depth +#else +#define FUNC_PROLOGUE + +#define FUNC_EPILOGUE +#endif + +#define UNREACHABLE TRAP(UNREACHABLE) + +#define CALL_INDIRECT(table, t, ft, x, ...) \ + (LIKELY((x) < table.size && table.data[x].func && \ + table.data[x].func_type == func_types[ft]) || \ + TRAP(CALL_INDIRECT), \ + ((t)table.data[x].func)(__VA_ARGS__)) + +#define RANGE_CHECK(mem, offset, len) \ + if (UNLIKELY(offset + (uint64_t)len > mem->size)) \ + TRAP(OOB); + +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER +#define MEMCHECK(mem, a, t) +#else +#define MEMCHECK(mem, a, t) RANGE_CHECK(mem, a, sizeof(t)) +#endif + +#ifdef __GNUC__ +#define wasm_asm __asm__ +#else +#define wasm_asm(X) +#endif + +#if WABT_BIG_ENDIAN +static inline void load_data(void* dest, const void* src, size_t n) { + size_t i = 0; + u8* dest_chars = dest; + memcpy(dest, src, n); + for (i = 0; i < (n >> 1); i++) { + u8 cursor = dest_chars[i]; + dest_chars[i] = dest_chars[n - i - 1]; + dest_chars[n - i - 1] = cursor; + } +} +#define LOAD_DATA(m, o, i, s) \ + do { \ + RANGE_CHECK((&m), m.size - o - s, s); \ + load_data(&(m.data[m.size - o - s]), i, s); \ + } while (0) +#define DEFINE_LOAD(name, t1, t2, t3) \ + static inline t3 name(wasm_rt_memory_t* mem, u64 addr) { \ + MEMCHECK(mem, addr, t1); \ + t1 result; \ + wasm_rt_memcpy(&result, &mem->data[mem->size - addr - sizeof(t1)], \ + sizeof(t1)); \ + wasm_asm("" ::"r"(result)); \ + return (t3)(t2)result; \ + } + +#define DEFINE_STORE(name, t1, t2) \ + static inline void name(wasm_rt_memory_t* mem, u64 addr, t2 value) { \ + MEMCHECK(mem, addr, t1); \ + t1 wrapped = (t1)value; \ + wasm_rt_memcpy(&mem->data[mem->size - addr - sizeof(t1)], &wrapped, \ + sizeof(t1)); \ + } +#else +static inline void load_data(void* dest, const void* src, size_t n) { + memcpy(dest, src, n); +} +#define LOAD_DATA(m, o, i, s) \ + do { \ + RANGE_CHECK((&m), o, s); \ + load_data(&(m.data[o]), i, s); \ + } while (0) +#define DEFINE_LOAD(name, t1, t2, t3) \ + static inline t3 name(wasm_rt_memory_t* mem, u64 addr) { \ + MEMCHECK(mem, addr, t1); \ + t1 result; \ + wasm_rt_memcpy(&result, &mem->data[addr], sizeof(t1)); \ + wasm_asm("" ::"r"(result)); \ + return (t3)(t2)result; \ + } + +#define DEFINE_STORE(name, t1, t2) \ + static inline void name(wasm_rt_memory_t* mem, u64 addr, t2 value) { \ + MEMCHECK(mem, addr, t1); \ + t1 wrapped = (t1)value; \ + wasm_rt_memcpy(&mem->data[addr], &wrapped, sizeof(t1)); \ + } +#endif + +DEFINE_LOAD(i32_load, u32, u32, u32) +DEFINE_LOAD(i64_load, u64, u64, u64) +DEFINE_LOAD(f32_load, f32, f32, f32) +DEFINE_LOAD(f64_load, f64, f64, f64) +DEFINE_LOAD(i32_load8_s, s8, s32, u32) +DEFINE_LOAD(i64_load8_s, s8, s64, u64) +DEFINE_LOAD(i32_load8_u, u8, u32, u32) +DEFINE_LOAD(i64_load8_u, u8, u64, u64) +DEFINE_LOAD(i32_load16_s, s16, s32, u32) +DEFINE_LOAD(i64_load16_s, s16, s64, u64) +DEFINE_LOAD(i32_load16_u, u16, u32, u32) +DEFINE_LOAD(i64_load16_u, u16, u64, u64) +DEFINE_LOAD(i64_load32_s, s32, s64, u64) +DEFINE_LOAD(i64_load32_u, u32, u64, u64) +DEFINE_STORE(i32_store, u32, u32) +DEFINE_STORE(i64_store, u64, u64) +DEFINE_STORE(f32_store, f32, f32) +DEFINE_STORE(f64_store, f64, f64) +DEFINE_STORE(i32_store8, u8, u32) +DEFINE_STORE(i32_store16, u16, u32) +DEFINE_STORE(i64_store8, u8, u64) +DEFINE_STORE(i64_store16, u16, u64) +DEFINE_STORE(i64_store32, u32, u64) + +#if defined(_MSC_VER) + +// Adapted from +// https://github.com/nemequ/portable-snippets/blob/master/builtin/builtin.h + +static inline int I64_CLZ(unsigned long long v) { + unsigned long r = 0; +#if defined(_M_AMD64) || defined(_M_ARM) + if (_BitScanReverse64(&r, v)) { + return 63 - r; + } +#else + if (_BitScanReverse(&r, (unsigned long)(v >> 32))) { + return 31 - r; + } else if (_BitScanReverse(&r, (unsigned long)v)) { + return 63 - r; + } +#endif + return 64; +} + +static inline int I32_CLZ(unsigned long v) { + unsigned long r = 0; + if (_BitScanReverse(&r, v)) { + return 31 - r; + } + return 32; +} + +static inline int I64_CTZ(unsigned long long v) { + if (!v) { + return 64; + } + unsigned long r = 0; +#if defined(_M_AMD64) || defined(_M_ARM) + _BitScanForward64(&r, v); + return (int)r; +#else + if (_BitScanForward(&r, (unsigned int)(v))) { + return (int)(r); + } + + _BitScanForward(&r, (unsigned int)(v >> 32)); + return (int)(r + 32); +#endif +} + +static inline int I32_CTZ(unsigned long v) { + if (!v) { + return 32; + } + unsigned long r = 0; + _BitScanForward(&r, v); + return (int)r; +} + +#define POPCOUNT_DEFINE_PORTABLE(f_n, T) \ + static inline u32 f_n(T x) { \ + x = x - ((x >> 1) & (T) ~(T)0 / 3); \ + x = (x & (T) ~(T)0 / 15 * 3) + ((x >> 2) & (T) ~(T)0 / 15 * 3); \ + x = (x + (x >> 4)) & (T) ~(T)0 / 255 * 15; \ + return (T)(x * ((T) ~(T)0 / 255)) >> (sizeof(T) - 1) * 8; \ + } + +POPCOUNT_DEFINE_PORTABLE(I32_POPCNT, u32) +POPCOUNT_DEFINE_PORTABLE(I64_POPCNT, u64) + +#undef POPCOUNT_DEFINE_PORTABLE + +#else + +#define I32_CLZ(x) ((x) ? __builtin_clz(x) : 32) +#define I64_CLZ(x) ((x) ? __builtin_clzll(x) : 64) +#define I32_CTZ(x) ((x) ? __builtin_ctz(x) : 32) +#define I64_CTZ(x) ((x) ? __builtin_ctzll(x) : 64) +#define I32_POPCNT(x) (__builtin_popcount(x)) +#define I64_POPCNT(x) (__builtin_popcountll(x)) + +#endif + +#define DIV_S(ut, min, x, y) \ + ((UNLIKELY((y) == 0)) \ + ? TRAP(DIV_BY_ZERO) \ + : (UNLIKELY((x) == min && (y) == -1)) ? TRAP(INT_OVERFLOW) \ + : (ut)((x) / (y))) + +#define REM_S(ut, min, x, y) \ + ((UNLIKELY((y) == 0)) \ + ? TRAP(DIV_BY_ZERO) \ + : (UNLIKELY((x) == min && (y) == -1)) ? 0 : (ut)((x) % (y))) + +#define I32_DIV_S(x, y) DIV_S(u32, INT32_MIN, (s32)x, (s32)y) +#define I64_DIV_S(x, y) DIV_S(u64, INT64_MIN, (s64)x, (s64)y) +#define I32_REM_S(x, y) REM_S(u32, INT32_MIN, (s32)x, (s32)y) +#define I64_REM_S(x, y) REM_S(u64, INT64_MIN, (s64)x, (s64)y) + +#define DIVREM_U(op, x, y) \ + ((UNLIKELY((y) == 0)) ? TRAP(DIV_BY_ZERO) : ((x)op(y))) + +#define DIV_U(x, y) DIVREM_U(/, x, y) +#define REM_U(x, y) DIVREM_U(%, x, y) + +#define ROTL(x, y, mask) \ + (((x) << ((y) & (mask))) | ((x) >> (((mask) - (y) + 1) & (mask)))) +#define ROTR(x, y, mask) \ + (((x) >> ((y) & (mask))) | ((x) << (((mask) - (y) + 1) & (mask)))) + +#define I32_ROTL(x, y) ROTL(x, y, 31) +#define I64_ROTL(x, y) ROTL(x, y, 63) +#define I32_ROTR(x, y) ROTR(x, y, 31) +#define I64_ROTR(x, y) ROTR(x, y, 63) + +#define FMIN(x, y) \ + ((UNLIKELY((x) != (x))) \ + ? NAN \ + : (UNLIKELY((y) != (y))) \ + ? NAN \ + : (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? x : y) \ + : (x < y) ? x : y) + +#define FMAX(x, y) \ + ((UNLIKELY((x) != (x))) \ + ? NAN \ + : (UNLIKELY((y) != (y))) \ + ? NAN \ + : (UNLIKELY((x) == 0 && (y) == 0)) ? (signbit(x) ? y : x) \ + : (x > y) ? x : y) + +#define TRUNC_S(ut, st, ft, min, minop, max, x) \ + ((UNLIKELY((x) != (x))) \ + ? TRAP(INVALID_CONVERSION) \ + : (UNLIKELY(!((x)minop(min) && (x) < (max)))) ? TRAP(INT_OVERFLOW) \ + : (ut)(st)(x)) + +#define I32_TRUNC_S_F32(x) \ + TRUNC_S(u32, s32, f32, (f32)INT32_MIN, >=, 2147483648.f, x) +#define I64_TRUNC_S_F32(x) \ + TRUNC_S(u64, s64, f32, (f32)INT64_MIN, >=, (f32)INT64_MAX, x) +#define I32_TRUNC_S_F64(x) \ + TRUNC_S(u32, s32, f64, -2147483649., >, 2147483648., x) +#define I64_TRUNC_S_F64(x) \ + TRUNC_S(u64, s64, f64, (f64)INT64_MIN, >=, (f64)INT64_MAX, x) + +#define TRUNC_U(ut, ft, max, x) \ + ((UNLIKELY((x) != (x))) \ + ? TRAP(INVALID_CONVERSION) \ + : (UNLIKELY(!((x) > (ft)-1 && (x) < (max)))) ? TRAP(INT_OVERFLOW) \ + : (ut)(x)) + +#define I32_TRUNC_U_F32(x) TRUNC_U(u32, f32, 4294967296.f, x) +#define I64_TRUNC_U_F32(x) TRUNC_U(u64, f32, (f32)UINT64_MAX, x) +#define I32_TRUNC_U_F64(x) TRUNC_U(u32, f64, 4294967296., x) +#define I64_TRUNC_U_F64(x) TRUNC_U(u64, f64, (f64)UINT64_MAX, x) + +#define TRUNC_SAT_S(ut, st, ft, min, smin, minop, max, smax, x) \ + ((UNLIKELY((x) != (x))) \ + ? 0 \ + : (UNLIKELY(!((x)minop(min)))) \ + ? smin \ + : (UNLIKELY(!((x) < (max)))) ? smax : (ut)(st)(x)) + +#define I32_TRUNC_SAT_S_F32(x) \ + TRUNC_SAT_S(u32, s32, f32, (f32)INT32_MIN, INT32_MIN, >=, 2147483648.f, \ + INT32_MAX, x) +#define I64_TRUNC_SAT_S_F32(x) \ + TRUNC_SAT_S(u64, s64, f32, (f32)INT64_MIN, INT64_MIN, >=, (f32)INT64_MAX, \ + INT64_MAX, x) +#define I32_TRUNC_SAT_S_F64(x) \ + TRUNC_SAT_S(u32, s32, f64, -2147483649., INT32_MIN, >, 2147483648., \ + INT32_MAX, x) +#define I64_TRUNC_SAT_S_F64(x) \ + TRUNC_SAT_S(u64, s64, f64, (f64)INT64_MIN, INT64_MIN, >=, (f64)INT64_MAX, \ + INT64_MAX, x) + +#define TRUNC_SAT_U(ut, ft, max, smax, x) \ + ((UNLIKELY((x) != (x))) ? 0 \ + : (UNLIKELY(!((x) > (ft)-1))) \ + ? 0 \ + : (UNLIKELY(!((x) < (max)))) ? smax : (ut)(x)) + +#define I32_TRUNC_SAT_U_F32(x) \ + TRUNC_SAT_U(u32, f32, 4294967296.f, UINT32_MAX, x) +#define I64_TRUNC_SAT_U_F32(x) \ + TRUNC_SAT_U(u64, f32, (f32)UINT64_MAX, UINT64_MAX, x) +#define I32_TRUNC_SAT_U_F64(x) TRUNC_SAT_U(u32, f64, 4294967296., UINT32_MAX, x) +#define I64_TRUNC_SAT_U_F64(x) \ + TRUNC_SAT_U(u64, f64, (f64)UINT64_MAX, UINT64_MAX, x) + +#define DEFINE_REINTERPRET(name, t1, t2) \ + static inline t2 name(t1 x) { \ + t2 result; \ + memcpy(&result, &x, sizeof(result)); \ + return result; \ + } + +DEFINE_REINTERPRET(f32_reinterpret_i32, u32, f32) +DEFINE_REINTERPRET(i32_reinterpret_f32, f32, u32) +DEFINE_REINTERPRET(f64_reinterpret_i64, u64, f64) +DEFINE_REINTERPRET(i64_reinterpret_f64, f64, u64) + +static float quiet_nanf(float x) { + uint32_t tmp; + memcpy(&tmp, &x, 4); + tmp |= 0x7fc00000lu; + memcpy(&x, &tmp, 4); + return x; +} + +static double quiet_nan(double x) { + uint64_t tmp; + memcpy(&tmp, &x, 8); + tmp |= 0x7ff8000000000000llu; + memcpy(&x, &tmp, 8); + return x; +} + +static double wasm_quiet(double x) { + if (UNLIKELY(isnan(x))) { + return quiet_nan(x); + } + return x; +} + +static float wasm_quietf(float x) { + if (UNLIKELY(isnan(x))) { + return quiet_nanf(x); + } + return x; +} + +static double wasm_floor(double x) { + if (UNLIKELY(isnan(x))) { + return quiet_nan(x); + } + return floor(x); +} + +static float wasm_floorf(float x) { + if (UNLIKELY(isnan(x))) { + return quiet_nanf(x); + } + return floorf(x); +} + +static double wasm_ceil(double x) { + if (UNLIKELY(isnan(x))) { + return quiet_nan(x); + } + return ceil(x); +} + +static float wasm_ceilf(float x) { + if (UNLIKELY(isnan(x))) { + return quiet_nanf(x); + } + return ceilf(x); +} + +static double wasm_trunc(double x) { + if (UNLIKELY(isnan(x))) { + return quiet_nan(x); + } + return trunc(x); +} + +static float wasm_truncf(float x) { + if (UNLIKELY(isnan(x))) { + return quiet_nanf(x); + } + return truncf(x); +} + +static float wasm_nearbyintf(float x) { + if (UNLIKELY(isnan(x))) { + return quiet_nanf(x); + } + return nearbyintf(x); +} + +static double wasm_nearbyint(double x) { + if (UNLIKELY(isnan(x))) { + return quiet_nan(x); + } + return nearbyint(x); +} + +static float wasm_fabsf(float x) { + if (UNLIKELY(isnan(x))) { + uint32_t tmp; + memcpy(&tmp, &x, 4); + tmp = tmp & ~(1 << 31); + memcpy(&x, &tmp, 4); + return x; + } + return fabsf(x); +} + +static double wasm_fabs(double x) { + if (UNLIKELY(isnan(x))) { + uint64_t tmp; + memcpy(&tmp, &x, 8); + tmp = tmp & ~(1ll << 63); + memcpy(&x, &tmp, 8); + return x; + } + return fabs(x); +} + +static double wasm_sqrt(double x) { + if (UNLIKELY(isnan(x))) { + return quiet_nan(x); + } + return sqrt(x); +} + +static float wasm_sqrtf(float x) { + if (UNLIKELY(isnan(x))) { + return quiet_nanf(x); + } + return sqrtf(x); +} + +static inline void memory_fill(wasm_rt_memory_t* mem, u32 d, u32 val, u32 n) { + RANGE_CHECK(mem, d, n); + memset(mem->data + d, val, n); +} + +static inline void memory_copy(wasm_rt_memory_t* dest, + const wasm_rt_memory_t* src, + u32 dest_addr, + u32 src_addr, + u32 n) { + RANGE_CHECK(dest, dest_addr, n); + RANGE_CHECK(src, src_addr, n); + memmove(dest->data + dest_addr, src->data + src_addr, n); +} + +static inline void memory_init(wasm_rt_memory_t* dest, + const u8* src, + u32 src_size, + u32 dest_addr, + u32 src_addr, + u32 n) { + if (UNLIKELY(src_addr + (uint64_t)n > src_size)) + TRAP(OOB); + LOAD_DATA((*dest), dest_addr, src + src_addr, n); +} + +typedef struct { + uint32_t func_type_index; + wasm_rt_function_ptr_t func; + size_t module_offset; +} wasm_elem_segment_expr_t; + +static inline void funcref_table_init(wasm_rt_funcref_table_t* dest, + const wasm_elem_segment_expr_t* src, + u32 src_size, + u32 dest_addr, + u32 src_addr, + u32 n, + void* module_instance, + const u32* func_types) { + if (UNLIKELY(src_addr + (uint64_t)n > src_size)) + TRAP(OOB); + if (UNLIKELY(dest_addr + (uint64_t)n > dest->size)) + TRAP(OOB); + for (u32 i = 0; i < n; i++) { + const wasm_elem_segment_expr_t* src_expr = &src[src_addr + i]; + dest->data[dest_addr + i] = (wasm_rt_funcref_t){ + func_types[src_expr->func_type_index], src_expr->func, + (char*)module_instance + src_expr->module_offset}; + } +} + +// Currently we only support initializing externref tables with ref.null. +static inline void externref_table_init(wasm_rt_externref_table_t* dest, + const wasm_rt_externref_t* src, + u32 src_size, + u32 dest_addr, + u32 src_addr, + u32 n) { + if (UNLIKELY(src_addr + (uint64_t)n > src_size)) + TRAP(OOB); + if (UNLIKELY(dest_addr + (uint64_t)n > dest->size)) + TRAP(OOB); + for (u32 i = 0; i < n; i++) { + const wasm_rt_externref_t* src_expr = &src[src_addr + i]; + dest->data[dest_addr + i] = *src_expr; + } +} + +#define DEFINE_TABLE_COPY(type) \ + static inline void type##_table_copy(wasm_rt_##type##_table_t* dest, \ + const wasm_rt_##type##_table_t* src, \ + u32 dest_addr, u32 src_addr, u32 n) { \ + if (UNLIKELY(dest_addr + (uint64_t)n > dest->size)) \ + TRAP(OOB); \ + if (UNLIKELY(src_addr + (uint64_t)n > src->size)) \ + TRAP(OOB); \ + \ + memmove(dest->data + dest_addr, src->data + src_addr, \ + n * sizeof(wasm_rt_##type##_t)); \ + } + +DEFINE_TABLE_COPY(funcref) +DEFINE_TABLE_COPY(externref) + +#define DEFINE_TABLE_GET(type) \ + static inline wasm_rt_##type##_t type##_table_get( \ + const wasm_rt_##type##_table_t* table, u32 i) { \ + if (UNLIKELY(i >= table->size)) \ + TRAP(OOB); \ + return table->data[i]; \ + } + +DEFINE_TABLE_GET(funcref) +DEFINE_TABLE_GET(externref) + +#define DEFINE_TABLE_SET(type) \ + static inline void type##_table_set(const wasm_rt_##type##_table_t* table, \ + u32 i, const wasm_rt_##type##_t val) { \ + if (UNLIKELY(i >= table->size)) \ + TRAP(OOB); \ + table->data[i] = val; \ + } + +DEFINE_TABLE_SET(funcref) +DEFINE_TABLE_SET(externref) + +#define DEFINE_TABLE_FILL(type) \ + static inline void type##_table_fill(const wasm_rt_##type##_table_t* table, \ + u32 d, const wasm_rt_##type##_t val, \ + u32 n) { \ + if (UNLIKELY((uint64_t)d + n > table->size)) \ + TRAP(OOB); \ + for (uint32_t i = d; i < d + n; i++) { \ + table->data[i] = val; \ + } \ + } + +DEFINE_TABLE_FILL(funcref) +DEFINE_TABLE_FILL(externref) + +static bool s_module_initialized = false; + +static u32 func_types[18]; + +static void init_func_types(void) { + func_types[0] = wasm_rt_register_func_type(1, 1, WASM_RT_F32, WASM_RT_F32); + func_types[1] = wasm_rt_register_func_type(2, 1, WASM_RT_F32, WASM_RT_F32, WASM_RT_F32); + func_types[2] = wasm_rt_register_func_type(1, 0, WASM_RT_I32); + func_types[3] = wasm_rt_register_func_type(0, 1, WASM_RT_F32); + func_types[4] = wasm_rt_register_func_type(1, 1, WASM_RT_I32, WASM_RT_I32); + func_types[5] = wasm_rt_register_func_type(0, 1, WASM_RT_I32); + func_types[6] = wasm_rt_register_func_type(0, 1, WASM_RT_I64); + func_types[7] = wasm_rt_register_func_type(3, 0, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32); + func_types[8] = wasm_rt_register_func_type(2, 1, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32); + func_types[9] = wasm_rt_register_func_type(3, 1, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32); + func_types[10] = wasm_rt_register_func_type(4, 0, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32); + func_types[11] = wasm_rt_register_func_type(5, 0, WASM_RT_F32, WASM_RT_F32, WASM_RT_F32, WASM_RT_F32, WASM_RT_I32); + func_types[12] = wasm_rt_register_func_type(4, 0, WASM_RT_F32, WASM_RT_F32, WASM_RT_F32, WASM_RT_I32); + func_types[13] = wasm_rt_register_func_type(5, 0, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32, WASM_RT_I32); + func_types[14] = wasm_rt_register_func_type(2, 0, WASM_RT_I32, WASM_RT_I32); + func_types[15] = wasm_rt_register_func_type(0, 0); + func_types[16] = wasm_rt_register_func_type(1, 1, WASM_RT_I32, WASM_RT_F32); + func_types[17] = wasm_rt_register_func_type(3, 1, WASM_RT_I32, WASM_RT_F32, WASM_RT_I32, WASM_RT_I32); +} + +static f32 w2c_time(Z_platform_instance_t*); +static u32 w2c_isButtonPressed(Z_platform_instance_t*, u32); +static u32 w2c_isButtonTriggered(Z_platform_instance_t*, u32); +static u32 w2c_random(Z_platform_instance_t*); +static u64 w2c_random64(Z_platform_instance_t*); +static f32 w2c_randomf(Z_platform_instance_t*); +static void w2c_randomSeed(Z_platform_instance_t*, u32); +static f32 w2c_fmod(Z_platform_instance_t*, f32, f32); +static void w2c_cls(Z_platform_instance_t*, u32); +static void w2c_setPixel(Z_platform_instance_t*, u32, u32, u32); +static u32 w2c_getPixel(Z_platform_instance_t*, u32, u32); +static void w2c_hline(Z_platform_instance_t*, u32, u32, u32, u32); +static void w2c_rectangle(Z_platform_instance_t*, f32, f32, f32, f32, u32); +static void w2c_rectangleOutline(Z_platform_instance_t*, f32, f32, f32, f32, u32); +static void w2c_circle(Z_platform_instance_t*, f32, f32, f32, u32); +static void w2c_circleOutline(Z_platform_instance_t*, f32, f32, f32, u32); +static void w2c_line(Z_platform_instance_t*, f32, f32, f32, f32, u32); +static void w2c_blitSprite(Z_platform_instance_t*, u32, u32, u32, u32, u32); +static void w2c_grabSprite(Z_platform_instance_t*, u32, u32, u32, u32, u32); +static void w2c_printChar(Z_platform_instance_t*, u32); +static void w2c_printString(Z_platform_instance_t*, u32); +static void w2c_printInt(Z_platform_instance_t*, u32); +static void w2c_setTextColor(Z_platform_instance_t*, u32); +static void w2c_setBackgroundColor(Z_platform_instance_t*, u32); +static void w2c_setCursorPosition(Z_platform_instance_t*, u32, u32); +static void w2c_playNote(Z_platform_instance_t*, u32, u32); +static void w2c_endFrame(Z_platform_instance_t*); +static f32 w2c_sndGes(Z_platform_instance_t*, u32); +static u32 w2c_f33(Z_platform_instance_t*, u32, u32, u32); +static void w2c_f34(Z_platform_instance_t*, u32); +static void w2c_f35(Z_platform_instance_t*, u32); +static void w2c_f36(Z_platform_instance_t*); +static u32 w2c_f37(Z_platform_instance_t*, u32, f32, u32); + +static void init_globals(Z_platform_instance_t* instance) { + instance->w2c_g0 = 37ull; + instance->w2c_g1 = 0u; + instance->w2c_g2 = 0u; + instance->w2c_g3 = 15u; + instance->w2c_g4 = 0u; + instance->w2c_g5 = 0u; + instance->w2c_g6 = 0u; +} + + +static const u8 data_segment_data_w2c_d0[] = { + 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x03, +}; + +static const u8 data_segment_data_w2c_d1[] = { + 0x80, 0xc0, 0x00, 0x51, 0xa0, 0x50, 0xc4, 0x00, 0x00, 0x45, 0x60, 0x40, + 0x44, 0xb0, 0x00, 0x45, 0x90, 0x43, 0x04, 0xf0, 0x00, 0x45, 0xa4, 0x44, + 0xff, 0xff, 0x01, 0x01, 0x00, 0x64, 0x00, 0x64, +}; + +static const u8 data_segment_data_w2c_d2[] = { + 0x50, 0x00, 0x00, 0x00, +}; + +static const u8 data_segment_data_w2c_d3[] = { + 0x1a, 0x1c, 0x2c, 0x00, 0x5d, 0x27, 0x5d, 0x00, 0xb1, 0x3e, 0x53, 0x00, + 0xef, 0x7d, 0x57, 0x00, 0xff, 0xcd, 0x75, 0x00, 0xa7, 0xf0, 0x70, 0x00, + 0x38, 0xb7, 0x64, 0x00, 0x25, 0x71, 0x79, 0x00, 0x29, 0x36, 0x6f, 0x00, + 0x3b, 0x5d, 0xc9, 0x00, 0x41, 0xa6, 0xf6, 0x00, 0x73, 0xef, 0xf7, 0x00, + 0xf4, 0xf4, 0xf4, 0x00, 0x94, 0xb0, 0xc2, 0x00, 0x56, 0x6c, 0x86, 0x00, + 0x33, 0x3c, 0x57, 0x00, +}; + +static const u8 data_segment_data_w2c_d4[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x38, 0x38, 0x38, 0x38, 0x38, 0x00, 0x38, 0x00, 0x6c, 0x6c, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0xfe, 0x74, 0xfe, 0x74, 0x00, 0x00, + 0x38, 0x7c, 0xb8, 0x7c, 0x3a, 0x7c, 0x38, 0x00, 0x00, 0x8e, 0x1c, 0x38, + 0x70, 0xe2, 0x00, 0x00, 0x78, 0xe4, 0xe4, 0x70, 0xea, 0xe4, 0x7a, 0x00, + 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x38, 0x70, 0x70, + 0x70, 0x38, 0x1c, 0x00, 0x70, 0x38, 0x1c, 0x1c, 0x1c, 0x38, 0x70, 0x00, + 0x00, 0x38, 0xfe, 0x7c, 0xfe, 0x38, 0x00, 0x00, 0x00, 0x30, 0x30, 0xfc, + 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x70, + 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x38, 0x00, 0x00, 0x00, 0x0e, 0x1c, 0x38, 0x70, 0xe0, 0x00, + 0x38, 0x74, 0xe2, 0xea, 0xe2, 0x74, 0x38, 0x00, 0x1c, 0x3c, 0x5c, 0x1c, + 0x1c, 0x1c, 0x3e, 0x00, 0x7c, 0x8e, 0x0e, 0x1c, 0x38, 0x70, 0xfe, 0x00, + 0x7c, 0x8e, 0x0e, 0x3c, 0x0e, 0x8e, 0x7c, 0x00, 0x1c, 0x3c, 0x5c, 0x9c, + 0xfe, 0x1c, 0x1c, 0x00, 0xfe, 0xe0, 0xe0, 0xfc, 0x02, 0xe2, 0x7c, 0x00, + 0x7c, 0xe2, 0xe0, 0xfc, 0xe2, 0xe2, 0x7c, 0x00, 0xfe, 0x0e, 0x1c, 0x38, + 0x38, 0x38, 0x38, 0x00, 0x7c, 0xe2, 0xe2, 0x7c, 0xe2, 0xe2, 0x7c, 0x00, + 0x7c, 0x8e, 0x8e, 0x7e, 0x0e, 0x8e, 0x7c, 0x00, 0x00, 0x00, 0x38, 0x38, + 0x00, 0x38, 0x38, 0x00, 0x00, 0x00, 0x38, 0x38, 0x00, 0x38, 0x38, 0x70, + 0x1c, 0x38, 0x70, 0xe0, 0x70, 0x38, 0x1c, 0x00, 0x00, 0x00, 0x7c, 0x00, + 0x7c, 0x00, 0x00, 0x00, 0xe0, 0x70, 0x38, 0x1c, 0x38, 0x70, 0xe0, 0x00, + 0x7c, 0x8e, 0x0e, 0x1c, 0x38, 0x00, 0x38, 0x00, 0x00, 0x7c, 0xe2, 0xea, + 0xec, 0xe0, 0x7c, 0x00, 0x38, 0x74, 0xe2, 0xe2, 0xfe, 0xe2, 0xe2, 0x00, + 0xfc, 0xe2, 0xe2, 0xfc, 0xe2, 0xe2, 0xfc, 0x00, 0x3c, 0x72, 0xe0, 0xe0, + 0xe0, 0x72, 0x3c, 0x00, 0xf8, 0xe4, 0xe2, 0xe2, 0xe2, 0xe4, 0xf8, 0x00, + 0xfe, 0xe0, 0xe0, 0xf8, 0xe0, 0xe0, 0xfe, 0x00, 0xfe, 0xe0, 0xe0, 0xf8, + 0xe0, 0xe0, 0xe0, 0x00, 0x7c, 0xe2, 0xe0, 0xee, 0xe2, 0xe6, 0x7a, 0x00, + 0xe2, 0xe2, 0xe2, 0xfe, 0xe2, 0xe2, 0xe2, 0x00, 0x7c, 0x38, 0x38, 0x38, + 0x38, 0x38, 0x7c, 0x00, 0x3e, 0x1c, 0x1c, 0x1c, 0x1c, 0x9c, 0x78, 0x00, + 0xe2, 0xe4, 0xe8, 0xf0, 0xe8, 0xe4, 0xe2, 0x00, 0xe0, 0xe0, 0xe0, 0xe0, + 0xe0, 0xe0, 0xfe, 0x00, 0xf6, 0xea, 0xea, 0xea, 0xe2, 0xe2, 0xe2, 0x00, + 0xe2, 0xf2, 0xfa, 0xee, 0xe6, 0xe2, 0xe2, 0x00, 0x7c, 0xe2, 0xe2, 0xe2, + 0xe2, 0xe2, 0x7c, 0x00, 0xfc, 0xe2, 0xe2, 0xe2, 0xfc, 0xe0, 0xe0, 0x00, + 0x7c, 0xe2, 0xe2, 0xe2, 0xea, 0xe4, 0x7a, 0x00, 0xfc, 0xe2, 0xe2, 0xfc, + 0xe8, 0xe4, 0xe2, 0x00, 0x7c, 0xe2, 0xe0, 0x7c, 0x02, 0xe2, 0x7c, 0x00, + 0xfe, 0x38, 0x38, 0x38, 0x38, 0x38, 0x38, 0x00, 0xe2, 0xe2, 0xe2, 0xe2, + 0xe2, 0xe2, 0x7c, 0x00, 0xe2, 0xe2, 0xe2, 0xe2, 0x74, 0x74, 0x38, 0x00, + 0xe2, 0xe2, 0xe2, 0xea, 0xea, 0xea, 0x74, 0x00, 0x8e, 0x8e, 0x5c, 0x38, + 0x74, 0xe2, 0xe2, 0x00, 0xe2, 0xe2, 0x74, 0x38, 0x38, 0x38, 0x38, 0x00, + 0xfe, 0x0e, 0x1c, 0x38, 0x70, 0xe0, 0xfe, 0x00, 0xfc, 0xe0, 0xe0, 0xe0, + 0xe0, 0xe0, 0xfc, 0x00, 0x00, 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x00, 0x00, + 0xfc, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0xfc, 0x00, 0x18, 0x3c, 0x72, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, + 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x0e, + 0x7e, 0x8e, 0x7e, 0x00, 0xe0, 0xe0, 0xfc, 0xe2, 0xe2, 0xe2, 0xfc, 0x00, + 0x00, 0x00, 0x7c, 0xe2, 0xe0, 0xe2, 0x7c, 0x00, 0x0e, 0x0e, 0x7e, 0x8e, + 0x8e, 0x8e, 0x7e, 0x00, 0x00, 0x00, 0x7c, 0xe2, 0xfe, 0xe0, 0x7c, 0x00, + 0x3c, 0x72, 0x70, 0xf8, 0x70, 0x70, 0x70, 0x00, 0x00, 0x00, 0x7e, 0xe2, + 0xe2, 0x7e, 0x02, 0x7c, 0xe0, 0xe0, 0xfc, 0xe2, 0xe2, 0xe2, 0xe2, 0x00, + 0x38, 0x00, 0x78, 0x38, 0x38, 0x38, 0x7c, 0x00, 0x0e, 0x00, 0x0e, 0x0e, + 0x0e, 0x0e, 0x8e, 0x7c, 0xe0, 0xe0, 0xe4, 0xe8, 0xf0, 0xe8, 0xe6, 0x00, + 0x78, 0x38, 0x38, 0x38, 0x38, 0x38, 0x7c, 0x00, 0x00, 0x00, 0xf4, 0xea, + 0xea, 0xe2, 0xe2, 0x00, 0x00, 0x00, 0xfc, 0xe2, 0xe2, 0xe2, 0xe2, 0x00, + 0x00, 0x00, 0x7c, 0xe2, 0xe2, 0xe2, 0x7c, 0x00, 0x00, 0x00, 0xfc, 0xe2, + 0xe2, 0xfc, 0xe0, 0xe0, 0x00, 0x00, 0x7e, 0x8e, 0x8e, 0x7e, 0x0e, 0x0e, + 0x00, 0x00, 0xee, 0xf0, 0xe0, 0xe0, 0xe0, 0x00, 0x00, 0x00, 0x7c, 0xe0, + 0x7c, 0x02, 0x7c, 0x00, 0x70, 0x70, 0xf8, 0x70, 0x70, 0x72, 0x3c, 0x00, + 0x00, 0x00, 0xe2, 0xe2, 0xe2, 0xe2, 0x7c, 0x00, 0x00, 0x00, 0xe2, 0xe2, + 0xe2, 0x74, 0x38, 0x00, 0x00, 0x00, 0xe2, 0xe2, 0xea, 0xea, 0x74, 0x00, + 0x00, 0x00, 0x8e, 0x5c, 0x38, 0x74, 0xe2, 0x00, 0x00, 0x00, 0xe2, 0xe2, + 0xe2, 0x7e, 0x02, 0x7c, 0x00, 0x00, 0xfe, 0x1c, 0x38, 0x70, 0xfe, 0x00, + 0x3c, 0x70, 0x70, 0xe0, 0x70, 0x70, 0x3c, 0x00, 0x38, 0x38, 0x38, 0x38, + 0x38, 0x38, 0x38, 0x00, 0xf0, 0x38, 0x38, 0x1c, 0x38, 0x38, 0xf0, 0x00, + 0x22, 0x74, 0xc8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00, + 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, + 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, 0x3c, + 0x00, 0x00, 0xf8, 0xfc, 0xfc, 0xf8, 0x00, 0x00, 0x3c, 0x3c, 0xfc, 0xfc, + 0xfc, 0xf8, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xfc, 0xfc, 0xfc, 0x3c, 0x3c, + 0x38, 0x38, 0xf8, 0xf8, 0xf8, 0xf8, 0x38, 0x38, 0x00, 0x00, 0x1f, 0x3f, + 0x3f, 0x1f, 0x00, 0x00, 0x3c, 0x3c, 0x3f, 0x3f, 0x3f, 0x1f, 0x00, 0x00, + 0x00, 0x00, 0x1f, 0x3f, 0x3f, 0x3f, 0x3c, 0x3c, 0x3c, 0x3c, 0x3f, 0x3f, + 0x3f, 0x3f, 0x3c, 0x3c, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, + 0x3c, 0x3c, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, + 0xff, 0xff, 0x3c, 0x3c, 0x3c, 0x3c, 0xff, 0xff, 0xff, 0xff, 0x3c, 0x3c, + 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0xc0, 0xe0, 0x70, 0x38, + 0x18, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0e, 0x1c, 0x18, 0x00, 0x00, 0x00, + 0xc3, 0xe7, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, + 0x1c, 0x0e, 0x07, 0x03, 0xc0, 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x07, 0x03, + 0x03, 0x07, 0x0e, 0x1c, 0x1c, 0x0e, 0x07, 0x03, 0xc3, 0xe7, 0x7e, 0x3c, + 0x1c, 0x0e, 0x07, 0x03, 0x00, 0x00, 0x00, 0x18, 0x38, 0x70, 0xe0, 0xc0, + 0xc0, 0xe0, 0x70, 0x38, 0x38, 0x70, 0xe0, 0xc0, 0x03, 0x07, 0x0e, 0x1c, + 0x38, 0x70, 0xe0, 0xc0, 0xc3, 0xe7, 0x7e, 0x3c, 0x38, 0x70, 0xe0, 0xc0, + 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xe7, 0xc3, 0xc0, 0xe0, 0x70, 0x38, + 0x3c, 0x7e, 0xe7, 0xc3, 0x03, 0x07, 0x0e, 0x1c, 0x3c, 0x7e, 0xe7, 0xc3, + 0xc3, 0xe7, 0x7e, 0x3c, 0x3c, 0x7e, 0xe7, 0xc3, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xaa, 0x00, 0xaa, 0x00, 0xaa, 0x00, 0xaa, 0x00, + 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xff, 0xaa, 0xff, 0xaa, + 0xff, 0xaa, 0xff, 0xaa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0x33, 0x33, 0xf0, 0xf0, 0xf0, 0xf0, + 0x0f, 0x0f, 0x0f, 0x0f, 0xcc, 0x33, 0xcc, 0x33, 0xcc, 0x33, 0xcc, 0x33, + 0xf0, 0xf0, 0x0f, 0x0f, 0xf0, 0xf0, 0x0f, 0x0f, 0xcc, 0x66, 0x33, 0x99, + 0xcc, 0x66, 0x33, 0x99, 0x33, 0x66, 0xcc, 0x99, 0x33, 0x66, 0xcc, 0x99, + 0x00, 0x22, 0x55, 0x88, 0x00, 0x22, 0x55, 0x88, 0x44, 0xee, 0x44, 0x00, + 0x11, 0xbb, 0x11, 0x00, 0x70, 0xf8, 0x70, 0x22, 0x07, 0x8f, 0x07, 0x22, + 0x7e, 0x3c, 0x99, 0xc3, 0xe7, 0xc3, 0x99, 0x3c, 0xee, 0x33, 0x11, 0x99, + 0xee, 0x33, 0x11, 0x99, 0xe0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xe0, + 0x1f, 0x0f, 0x07, 0x03, 0x03, 0x07, 0x0f, 0x1f, 0xf8, 0xf0, 0xe0, 0xc0, + 0xc0, 0xe0, 0xf0, 0xf8, 0x07, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x07, + 0xfc, 0xfc, 0xf8, 0xf8, 0xf0, 0xf0, 0xe0, 0xe0, 0x03, 0x03, 0x07, 0x07, + 0x0f, 0x0f, 0x1f, 0x1f, 0xc0, 0xc0, 0xe0, 0xe0, 0xf0, 0xf0, 0xf8, 0xf8, + 0x3f, 0x3f, 0x1f, 0x1f, 0x0f, 0x0f, 0x07, 0x07, 0xff, 0xff, 0xff, 0x7e, + 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0xc3, 0xe7, 0xff, 0xff, + 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xc3, + 0x81, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xfc, 0xf0, 0xc0, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x0f, 0x3f, 0xff, 0xff, 0x00, 0x00, 0x00, 0xc0, + 0xf0, 0xfc, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x0f, 0x03, 0x00, 0x00, + 0x00, 0x10, 0x38, 0x38, 0x10, 0x38, 0x7c, 0x7c, 0x00, 0x5a, 0x5a, 0x7e, + 0x7e, 0x3c, 0x3c, 0x7e, 0x20, 0x38, 0x74, 0x3e, 0x32, 0x38, 0x7c, 0x7c, + 0x10, 0x38, 0x28, 0x44, 0x28, 0x38, 0x92, 0x7c, 0x00, 0x28, 0xaa, 0xba, + 0x7c, 0x7c, 0x7c, 0x38, 0x10, 0x38, 0x10, 0x6c, 0xfe, 0xd6, 0x6c, 0x38, + 0x18, 0x24, 0x42, 0x81, 0x7e, 0x52, 0x5e, 0x7e, 0x00, 0x00, 0x38, 0x44, + 0x92, 0x44, 0x38, 0x00, 0x00, 0x70, 0x88, 0x68, 0xa8, 0x50, 0x60, 0x00, + 0x38, 0x44, 0x9a, 0xa2, 0x9a, 0x44, 0x38, 0x00, 0x70, 0x88, 0x1c, 0xbe, + 0x3a, 0x36, 0x1c, 0x00, 0x3c, 0x24, 0xe7, 0x99, 0x99, 0xe7, 0x24, 0x3c, + 0x38, 0x6c, 0xd6, 0xc6, 0xd6, 0x54, 0x38, 0x00, 0x38, 0x4c, 0xd6, 0xce, + 0xd6, 0x4c, 0x38, 0x00, 0x38, 0x54, 0xd6, 0xee, 0xd6, 0x54, 0x38, 0x00, + 0x38, 0x54, 0xd6, 0xc6, 0xee, 0x6c, 0x38, 0x00, 0x18, 0x3c, 0x24, 0x66, + 0x66, 0xff, 0xe7, 0xff, 0x30, 0x78, 0x7a, 0x7a, 0x7e, 0x7e, 0x7c, 0x38, + 0xfc, 0x92, 0x92, 0x82, 0x92, 0x82, 0xfe, 0x00, 0x3c, 0x22, 0xf2, 0x8a, + 0x8a, 0x8e, 0x88, 0xf8, 0x40, 0xa2, 0x54, 0x08, 0x54, 0xa2, 0x40, 0x00, + 0x6c, 0x92, 0x82, 0x44, 0x82, 0x92, 0x6c, 0x00, 0x62, 0x72, 0x62, 0x52, + 0x62, 0x72, 0x62, 0x52, 0x0f, 0x30, 0x6a, 0xf0, 0xe8, 0xf4, 0xff, 0x7f, + 0xff, 0x00, 0x02, 0x00, 0x20, 0x00, 0xff, 0xff, 0xf0, 0x0c, 0x02, 0x01, + 0x21, 0x01, 0xff, 0xfe, 0xe6, 0x9a, 0x82, 0x82, 0xe6, 0x98, 0x80, 0x80, + 0x5a, 0x7e, 0x5a, 0x18, 0xbd, 0xff, 0x99, 0x3c, 0x00, 0x60, 0x70, 0xd6, + 0xed, 0xff, 0xff, 0x00, 0x00, 0xff, 0x42, 0x7e, 0x5a, 0xff, 0x66, 0x00, + 0x10, 0x38, 0x28, 0x44, 0x54, 0xfe, 0xc6, 0x82, 0x42, 0x24, 0x7e, 0xdb, + 0xff, 0xff, 0x81, 0x66, 0x10, 0x38, 0x7c, 0xfe, 0x38, 0x38, 0x38, 0x38, + 0x38, 0x38, 0x38, 0x38, 0xfe, 0x7c, 0x38, 0x10, 0x10, 0x30, 0x7f, 0xff, + 0x7f, 0x30, 0x10, 0x00, 0x08, 0x0c, 0xfe, 0xff, 0xfe, 0x0c, 0x08, 0x00, + 0x00, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x7c, + 0x38, 0x10, 0x00, 0x00, 0x04, 0x0c, 0x1c, 0x3c, 0x1c, 0x0c, 0x04, 0x00, + 0x20, 0x30, 0x38, 0x3c, 0x38, 0x30, 0x20, 0x00, 0x10, 0x38, 0x7c, 0x10, + 0x7c, 0x38, 0x10, 0x00, 0x00, 0x28, 0x6c, 0xfe, 0x6c, 0x28, 0x00, 0x00, + 0x00, 0xe0, 0x97, 0x92, 0xff, 0xff, 0x66, 0x00, 0x00, 0x00, 0x38, 0x44, + 0xff, 0xff, 0x66, 0x00, 0x00, 0x10, 0xfe, 0xfe, 0x10, 0x38, 0x10, 0x00, + 0x00, 0x10, 0x38, 0x7c, 0x10, 0xfe, 0x7c, 0x38, 0x3c, 0x7e, 0xdb, 0xdb, + 0xff, 0xdb, 0x66, 0x3c, 0x3c, 0x7e, 0xdb, 0xdb, 0xff, 0xe7, 0x5a, 0x3c, + 0x38, 0x44, 0x92, 0x8a, 0x82, 0x44, 0x38, 0x00, 0x38, 0x74, 0xfa, 0xfe, + 0xfe, 0x7c, 0x38, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00, + 0x6c, 0xf2, 0xfa, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x10, 0x38, 0x7c, 0xfe, + 0x6c, 0x10, 0x38, 0x00, 0x38, 0x38, 0xfe, 0xfe, 0xfe, 0x10, 0x38, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x60, 0x90, 0x60, 0x00, 0x10, 0x10, 0x10, 0x10, + 0x70, 0x90, 0x60, 0x00, 0x10, 0x10, 0x10, 0x10, 0x70, 0xf0, 0x60, 0x00, + 0x18, 0x14, 0x14, 0x10, 0x70, 0xf0, 0x60, 0x00, 0x38, 0x38, 0x92, 0x7c, + 0x10, 0x28, 0x28, 0x28, 0x38, 0x38, 0x10, 0xfe, 0x10, 0x28, 0x44, 0x82, + 0x38, 0x38, 0x90, 0x7c, 0x12, 0x28, 0x24, 0x22, 0x38, 0x38, 0x12, 0x7c, + 0x90, 0x28, 0x48, 0x88, 0x99, 0x5a, 0x24, 0xc3, 0xc3, 0x24, 0x5a, 0x99, + 0x00, 0x3c, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x00, +}; + +static void init_memories(Z_platform_instance_t* instance) { + LOAD_DATA((*instance->Z_envZ_memory), 77056u, data_segment_data_w2c_d0, 32); + LOAD_DATA((*instance->Z_envZ_memory), 80u, data_segment_data_w2c_d1, 32); + LOAD_DATA((*instance->Z_envZ_memory), 76920u, data_segment_data_w2c_d2, 4); + LOAD_DATA((*instance->Z_envZ_memory), 78592u, data_segment_data_w2c_d3, 64); + LOAD_DATA((*instance->Z_envZ_memory), 78848u, data_segment_data_w2c_d4, 2048); +} + +static void init_data_instances(Z_platform_instance_t *instance) { +} + +static f32 w2c_time(Z_platform_instance_t* instance) { + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1; + f32 w2c_f0, w2c_f1; + w2c_i0 = 0u; + w2c_i0 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i0) + 64u); + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_i1 = 1000u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_f0 /= w2c_f1; + FUNC_EPILOGUE; + return w2c_f0; +} + +static u32 w2c_isButtonPressed(Z_platform_instance_t* instance, u32 w2c_p0) { + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1; + w2c_i0 = 68u; + w2c_i0 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i0)); + w2c_i1 = w2c_p0; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_i1 = 1u; + w2c_i0 &= w2c_i1; + FUNC_EPILOGUE; + return w2c_i0; +} + +static u32 w2c_isButtonTriggered(Z_platform_instance_t* instance, u32 w2c_p0) { + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2; + w2c_i0 = 68u; + w2c_i0 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i0)); + w2c_i1 = 4294967295u; + w2c_i2 = 68u; + w2c_i2 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i2) + 4u); + w2c_i1 -= w2c_i2; + w2c_i0 &= w2c_i1; + w2c_i1 = w2c_p0; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_i1 = 1u; + w2c_i0 &= w2c_i1; + FUNC_EPILOGUE; + return w2c_i0; +} + +static u32 w2c_random(Z_platform_instance_t* instance) { + FUNC_PROLOGUE; + u32 w2c_i0; + u64 w2c_j0, w2c_j1; + w2c_j0 = w2c_random64(instance); + w2c_j1 = 32ull; + w2c_j0 = (u64)((s64)w2c_j0 >> (w2c_j1 & 63)); + w2c_i0 = (u32)(w2c_j0); + FUNC_EPILOGUE; + return w2c_i0; +} + +static u64 w2c_random64(Z_platform_instance_t* instance) { + u64 w2c_l0 = 0; + FUNC_PROLOGUE; + u64 w2c_j0, w2c_j1, w2c_j2; + w2c_j0 = instance->w2c_g0; + w2c_j1 = instance->w2c_g0; + w2c_j2 = 12ull; + w2c_j1 >>= (w2c_j2 & 63); + w2c_j0 ^= w2c_j1; + w2c_l0 = w2c_j0; + w2c_j1 = w2c_l0; + w2c_j2 = 25ull; + w2c_j1 <<= (w2c_j2 & 63); + w2c_j0 ^= w2c_j1; + w2c_l0 = w2c_j0; + w2c_j1 = w2c_l0; + w2c_j2 = 27ull; + w2c_j1 >>= (w2c_j2 & 63); + w2c_j0 ^= w2c_j1; + instance->w2c_g0 = w2c_j0; + w2c_j0 = instance->w2c_g0; + w2c_j1 = 2685821657736338717ull; + w2c_j0 *= w2c_j1; + FUNC_EPILOGUE; + return w2c_j0; +} + +static f32 w2c_randomf(Z_platform_instance_t* instance) { + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2; + f32 w2c_f0, w2c_f1; + w2c_i0 = 1065353216u; + w2c_i1 = w2c_random(instance); + w2c_i2 = 9u; + w2c_i1 >>= (w2c_i2 & 31); + w2c_i0 |= w2c_i1; + w2c_f0 = f32_reinterpret_i32(w2c_i0); + w2c_i1 = 1u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_f0 -= w2c_f1; + FUNC_EPILOGUE; + return w2c_f0; +} + +static void w2c_randomSeed(Z_platform_instance_t* instance, u32 w2c_p0) { + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2; + u64 w2c_j0, w2c_j1; + w2c_i0 = w2c_p0; + w2c_j0 = (u64)(s64)(s32)(w2c_i0); + w2c_j1 = 32ull; + w2c_j0 <<= (w2c_j1 & 63); + w2c_i1 = 63u; + w2c_i2 = w2c_p0; + w2c_i1 -= w2c_i2; + w2c_j1 = (u64)(s64)(s32)(w2c_i1); + w2c_j0 ^= w2c_j1; + instance->w2c_g0 = w2c_j0; + w2c_j0 = w2c_random64(instance); + instance->w2c_g0 = w2c_j0; + w2c_j0 = w2c_random64(instance); + instance->w2c_g0 = w2c_j0; + FUNC_EPILOGUE; +} + +static f32 w2c_fmod(Z_platform_instance_t* instance, f32 w2c_p0, f32 w2c_p1) { + FUNC_PROLOGUE; + f32 w2c_f0, w2c_f1, w2c_f2; + w2c_f0 = w2c_p0; + w2c_f1 = w2c_p0; + w2c_f2 = w2c_p1; + w2c_f1 /= w2c_f2; + w2c_f1 = wasm_floorf(w2c_f1); + w2c_f2 = w2c_p1; + w2c_f1 *= w2c_f2; + w2c_f0 -= w2c_f1; + FUNC_EPILOGUE; + return w2c_f0; +} + +static void w2c_cls(Z_platform_instance_t* instance, u32 w2c_p0) { + u32 w2c_l1 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2; + w2c_i0 = 0u; + instance->w2c_g1 = w2c_i0; + w2c_i0 = 0u; + instance->w2c_g2 = w2c_i0; + w2c_i0 = 0u; + instance->w2c_g5 = w2c_i0; + w2c_i0 = 120u; + w2c_i1 = w2c_p0; + w2c_i2 = 76800u; + memory_fill(instance->Z_envZ_memory, w2c_i0, w2c_i1, w2c_i2); + FUNC_EPILOGUE; +} + +static void w2c_setPixel(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1, u32 w2c_p2) { + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2; + w2c_i0 = w2c_p0; + w2c_i1 = 320u; + w2c_i0 = w2c_i0 < w2c_i1; + w2c_i1 = w2c_p1; + w2c_i2 = 240u; + w2c_i1 = w2c_i1 < w2c_i2; + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_i0 = w2c_p0; + w2c_i1 = w2c_p1; + w2c_i2 = 320u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_p2; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 120, w2c_i1); + } + FUNC_EPILOGUE; +} + +static u32 w2c_getPixel(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1) { + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2; + w2c_i0 = w2c_p0; + w2c_i1 = 320u; + w2c_i0 = w2c_i0 < w2c_i1; + w2c_i1 = w2c_p1; + w2c_i2 = 240u; + w2c_i1 = w2c_i1 < w2c_i2; + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_i0 = w2c_p0; + w2c_i1 = w2c_p1; + w2c_i2 = 320u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 120u); + } else { + w2c_i0 = 0u; + } + FUNC_EPILOGUE; + return w2c_i0; +} + +static void w2c_hline(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1, u32 w2c_p2, u32 w2c_p3) { + u32 w2c_l4 = 0, w2c_l5 = 0, w2c_l6 = 0, w2c_l7 = 0, w2c_l8 = 0, w2c_l9 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2; + w2c_i0 = w2c_p0; + w2c_i1 = 0u; + w2c_i2 = 320u; + w2c_i0 = w2c_f33(instance, w2c_i0, w2c_i1, w2c_i2); + w2c_p0 = w2c_i0; + w2c_i0 = w2c_p1; + w2c_i1 = 0u; + w2c_i2 = 320u; + w2c_i0 = w2c_f33(instance, w2c_i0, w2c_i1, w2c_i2); + w2c_p1 = w2c_i0; + w2c_i0 = w2c_p2; + w2c_i1 = 240u; + w2c_i0 = w2c_i0 >= w2c_i1; + if (w2c_i0) { + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 3u; + w2c_i0 += w2c_i1; + w2c_i1 = 4294967292u; + w2c_i0 &= w2c_i1; + w2c_l4 = w2c_i0; + w2c_i0 = w2c_p1; + w2c_i1 = 4294967292u; + w2c_i0 &= w2c_i1; + w2c_l5 = w2c_i0; + w2c_i0 = w2c_l5; + w2c_i1 = w2c_l4; + w2c_i0 = (u32)((s32)w2c_i0 > (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_p3; + w2c_i1 = 255u; + w2c_i0 &= w2c_i1; + w2c_i1 = 16843009u; + w2c_i0 *= w2c_i1; + w2c_p3 = w2c_i0; + w2c_i0 = w2c_p2; + w2c_i1 = 320u; + w2c_i0 *= w2c_i1; + w2c_i1 = w2c_p0; + w2c_i0 += w2c_i1; + w2c_l6 = w2c_i0; + w2c_i0 = w2c_l6; + w2c_i1 = w2c_l4; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_p0; + w2c_i0 -= w2c_i1; + w2c_l7 = w2c_i0; + w2c_i0 = w2c_l6; + w2c_i1 = 2u; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l7; + w2c_i0 = (u32)((s32)w2c_i0 <= (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l6; + w2c_i1 = w2c_p3; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 120, w2c_i1); + w2c_i0 = w2c_l6; + w2c_i1 = w2c_p3; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 121, w2c_i1); + w2c_i0 = w2c_l6; + w2c_i1 = 2u; + w2c_i0 += w2c_i1; + w2c_l6 = w2c_i0; + } + w2c_i0 = w2c_l6; + w2c_i1 = w2c_l7; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l6; + w2c_i1 = w2c_p3; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 120, w2c_i1); + w2c_i0 = w2c_l6; + w2c_i1 = 1u; + w2c_i0 += w2c_i1; + w2c_l6 = w2c_i0; + } + w2c_i0 = w2c_l7; + w2c_i1 = w2c_l5; + w2c_i2 = w2c_l4; + w2c_i1 -= w2c_i2; + w2c_i0 += w2c_i1; + w2c_l7 = w2c_i0; + w2c_L4: + w2c_i0 = w2c_l6; + w2c_i1 = 16u; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l7; + w2c_i0 = (u32)((s32)w2c_i0 <= (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l6; + w2c_i1 = w2c_p3; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 120, w2c_i1); + w2c_i0 = w2c_l6; + w2c_i1 = w2c_p3; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 124, w2c_i1); + w2c_i0 = w2c_l6; + w2c_i1 = w2c_p3; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 128, w2c_i1); + w2c_i0 = w2c_l6; + w2c_i1 = w2c_p3; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 132, w2c_i1); + w2c_i0 = w2c_l6; + w2c_i1 = 16u; + w2c_i0 += w2c_i1; + w2c_l6 = w2c_i0; + goto w2c_L4; + } + w2c_i0 = w2c_l6; + w2c_i1 = 8u; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l7; + w2c_i0 = (u32)((s32)w2c_i0 <= (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l6; + w2c_i1 = w2c_p3; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 120, w2c_i1); + w2c_i0 = w2c_l6; + w2c_i1 = w2c_p3; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 124, w2c_i1); + w2c_i0 = w2c_l6; + w2c_i1 = 8u; + w2c_i0 += w2c_i1; + w2c_l6 = w2c_i0; + } + w2c_i0 = w2c_l6; + w2c_i1 = w2c_l7; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l6; + w2c_i1 = w2c_p3; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 120, w2c_i1); + w2c_i0 = w2c_l6; + w2c_i1 = 4u; + w2c_i0 += w2c_i1; + w2c_l6 = w2c_i0; + } + w2c_i0 = w2c_l7; + w2c_i1 = w2c_p1; + w2c_i2 = w2c_l5; + w2c_i1 -= w2c_i2; + w2c_i0 += w2c_i1; + w2c_l7 = w2c_i0; + w2c_i0 = w2c_l6; + w2c_i1 = 2u; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l7; + w2c_i0 = (u32)((s32)w2c_i0 <= (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l6; + w2c_i1 = w2c_p3; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 120, w2c_i1); + w2c_i0 = w2c_l6; + w2c_i1 = w2c_p3; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 121, w2c_i1); + w2c_i0 = w2c_l6; + w2c_i1 = 2u; + w2c_i0 += w2c_i1; + w2c_l6 = w2c_i0; + } + w2c_i0 = w2c_l6; + w2c_i1 = w2c_l7; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l6; + w2c_i1 = w2c_p3; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 120, w2c_i1); + } + } else { + w2c_i0 = w2c_p2; + w2c_i1 = 320u; + w2c_i0 *= w2c_i1; + w2c_i1 = w2c_p0; + w2c_i0 += w2c_i1; + w2c_l8 = w2c_i0; + w2c_i0 = w2c_l8; + w2c_i1 = w2c_p1; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_p0; + w2c_i0 -= w2c_i1; + w2c_l9 = w2c_i0; + w2c_i0 = w2c_l8; + w2c_i1 = 4u; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l9; + w2c_i0 = (u32)((s32)w2c_i0 <= (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l8; + w2c_i1 = w2c_p3; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 120, w2c_i1); + w2c_i0 = w2c_l8; + w2c_i1 = w2c_p3; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 121, w2c_i1); + w2c_i0 = w2c_l8; + w2c_i1 = w2c_p3; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 122, w2c_i1); + w2c_i0 = w2c_l8; + w2c_i1 = w2c_p3; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 123, w2c_i1); + w2c_i0 = w2c_l8; + w2c_i1 = 4u; + w2c_i0 += w2c_i1; + w2c_l8 = w2c_i0; + } + w2c_i0 = w2c_l8; + w2c_i1 = 2u; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l9; + w2c_i0 = (u32)((s32)w2c_i0 <= (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l8; + w2c_i1 = w2c_p3; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 120, w2c_i1); + w2c_i0 = w2c_l8; + w2c_i1 = w2c_p3; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 121, w2c_i1); + w2c_i0 = w2c_l8; + w2c_i1 = 2u; + w2c_i0 += w2c_i1; + w2c_l8 = w2c_i0; + } + w2c_i0 = w2c_l8; + w2c_i1 = w2c_l9; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l8; + w2c_i1 = w2c_p3; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 120, w2c_i1); + } + } + w2c_Bfunc:; + FUNC_EPILOGUE; +} + +static void w2c_rectangle(Z_platform_instance_t* instance, f32 w2c_p0, f32 w2c_p1, f32 w2c_p2, f32 w2c_p3, u32 w2c_p4) { + u32 w2c_l5 = 0, w2c_l6 = 0, w2c_l7 = 0, w2c_l8 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3; + f32 w2c_f0, w2c_f1, w2c_f2; + w2c_f0 = w2c_p2; + w2c_f0 = wasm_fabsf(w2c_f0); + w2c_f1 = w2c_p2; + w2c_i0 = w2c_f0 == w2c_f1; + w2c_f1 = w2c_p3; + w2c_f1 = wasm_fabsf(w2c_f1); + w2c_f2 = w2c_p3; + w2c_i1 = w2c_f1 == w2c_f2; + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_f0 = w2c_p0; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l5 = w2c_i0; + w2c_f0 = w2c_p1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_i1 = 0u; + w2c_i2 = 240u; + w2c_i0 = w2c_f33(instance, w2c_i0, w2c_i1, w2c_i2); + w2c_l6 = w2c_i0; + w2c_f0 = w2c_p0; + w2c_f1 = w2c_p2; + w2c_f0 += w2c_f1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l7 = w2c_i0; + w2c_f0 = w2c_p1; + w2c_f1 = w2c_p3; + w2c_f0 += w2c_f1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_i1 = 0u; + w2c_i2 = 240u; + w2c_i0 = w2c_f33(instance, w2c_i0, w2c_i1, w2c_i2); + w2c_l8 = w2c_i0; + w2c_L2: + w2c_i0 = w2c_l6; + w2c_i1 = w2c_l8; + w2c_i0 = (u32)((s32)w2c_i0 >= (s32)w2c_i1); + if (w2c_i0) {goto w2c_B1;} + w2c_i0 = w2c_l5; + w2c_i1 = w2c_l7; + w2c_i2 = w2c_l6; + w2c_i3 = w2c_p4; + w2c_hline(instance, w2c_i0, w2c_i1, w2c_i2, w2c_i3); + w2c_i0 = w2c_l6; + w2c_i1 = 1u; + w2c_i0 += w2c_i1; + w2c_l6 = w2c_i0; + goto w2c_L2; + w2c_B1:; + } + FUNC_EPILOGUE; +} + +static void w2c_rectangleOutline(Z_platform_instance_t* instance, f32 w2c_p0, f32 w2c_p1, f32 w2c_p2, f32 w2c_p3, u32 w2c_p4) { + u32 w2c_l5 = 0, w2c_l6 = 0, w2c_l7 = 0, w2c_l8 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3; + f32 w2c_f0, w2c_f1; + w2c_f0 = w2c_p0; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l5 = w2c_i0; + w2c_f0 = w2c_p0; + w2c_f1 = w2c_p2; + w2c_f0 += w2c_f1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l6 = w2c_i0; + w2c_f0 = w2c_p1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l7 = w2c_i0; + w2c_f0 = w2c_p1; + w2c_f1 = w2c_p3; + w2c_f0 += w2c_f1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l8 = w2c_i0; + w2c_i0 = w2c_l5; + w2c_i1 = w2c_l6; + w2c_i2 = w2c_l7; + w2c_i3 = w2c_p4; + w2c_hline(instance, w2c_i0, w2c_i1, w2c_i2, w2c_i3); + w2c_i0 = w2c_l7; + w2c_i1 = w2c_l8; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l5; + w2c_i1 = w2c_l6; + w2c_i2 = w2c_l8; + w2c_i3 = 1u; + w2c_i2 -= w2c_i3; + w2c_i3 = w2c_p4; + w2c_hline(instance, w2c_i0, w2c_i1, w2c_i2, w2c_i3); + w2c_L1: + w2c_i0 = w2c_l5; + w2c_i1 = w2c_l7; + w2c_i2 = w2c_p4; + w2c_setPixel(instance, w2c_i0, w2c_i1, w2c_i2); + w2c_i0 = w2c_l5; + w2c_i1 = w2c_l6; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l6; + w2c_i1 = 1u; + w2c_i0 -= w2c_i1; + w2c_i1 = w2c_l7; + w2c_i2 = w2c_p4; + w2c_setPixel(instance, w2c_i0, w2c_i1, w2c_i2); + } + w2c_i0 = w2c_l7; + w2c_i1 = 1u; + w2c_i0 += w2c_i1; + w2c_l7 = w2c_i0; + w2c_i1 = w2c_l8; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L1;} + } + FUNC_EPILOGUE; +} + +static void w2c_circle(Z_platform_instance_t* instance, f32 w2c_p0, f32 w2c_p1, f32 w2c_p2, u32 w2c_p3) { + u32 w2c_l4 = 0, w2c_l5 = 0; + f32 w2c_l6 = 0, w2c_l7 = 0, w2c_l8 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3; + f32 w2c_f0, w2c_f1, w2c_f2; + w2c_f0 = w2c_p1; + w2c_f1 = w2c_p2; + w2c_f0 -= w2c_f1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_i1 = 0u; + w2c_i2 = 240u; + w2c_i0 = w2c_f33(instance, w2c_i0, w2c_i1, w2c_i2); + w2c_l4 = w2c_i0; + w2c_f0 = w2c_p1; + w2c_f1 = w2c_p2; + w2c_f0 += w2c_f1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_i1 = 0u; + w2c_i2 = 240u; + w2c_i0 = w2c_f33(instance, w2c_i0, w2c_i1, w2c_i2); + w2c_l5 = w2c_i0; + w2c_L1: + w2c_i0 = w2c_l4; + w2c_i1 = w2c_l5; + w2c_i0 = (u32)((s32)w2c_i0 >= (s32)w2c_i1); + if (w2c_i0) {goto w2c_B0;} + w2c_f0 = w2c_p2; + w2c_f1 = w2c_p2; + w2c_f0 *= w2c_f1; + w2c_i1 = w2c_l4; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_f2 = w2c_p1; + w2c_f1 -= w2c_f2; + w2c_f2 = 0.5; + w2c_f1 += w2c_f2; + w2c_l6 = w2c_f1; + w2c_f2 = w2c_l6; + w2c_f1 *= w2c_f2; + w2c_f0 -= w2c_f1; + w2c_l7 = w2c_f0; + w2c_f0 = wasm_fabsf(w2c_f0); + w2c_f1 = w2c_l7; + w2c_i0 = w2c_f0 == w2c_f1; + if (w2c_i0) { + w2c_f0 = w2c_p0; + w2c_f1 = w2c_l7; + w2c_f1 = wasm_sqrtf(w2c_f1); + w2c_l8 = w2c_f1; + w2c_f0 -= w2c_f1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_f1 = w2c_p0; + w2c_f2 = w2c_l8; + w2c_f1 += w2c_f2; + w2c_f1 = wasm_nearbyintf(w2c_f1); + w2c_i1 = I32_TRUNC_S_F32(w2c_f1); + w2c_i2 = w2c_l4; + w2c_i3 = w2c_p3; + w2c_hline(instance, w2c_i0, w2c_i1, w2c_i2, w2c_i3); + } + w2c_i0 = w2c_l4; + w2c_i1 = 1u; + w2c_i0 += w2c_i1; + w2c_l4 = w2c_i0; + goto w2c_L1; + w2c_B0:; + FUNC_EPILOGUE; +} + +static void w2c_circleOutline(Z_platform_instance_t* instance, f32 w2c_p0, f32 w2c_p1, f32 w2c_p2, u32 w2c_p3) { + u32 w2c_l4 = 0, w2c_l5 = 0, w2c_l6 = 0, w2c_l7 = 0, w2c_l8 = 0, w2c_l9 = 0; + f32 w2c_l10 = 0, w2c_l11 = 0, w2c_l12 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3; + f32 w2c_f0, w2c_f1, w2c_f2, w2c_f3; + w2c_f0 = w2c_p1; + w2c_f1 = w2c_p2; + w2c_f0 -= w2c_f1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_i1 = 4294967295u; + w2c_i2 = 241u; + w2c_i0 = w2c_f33(instance, w2c_i0, w2c_i1, w2c_i2); + w2c_l4 = w2c_i0; + w2c_f0 = w2c_p1; + w2c_f1 = w2c_p2; + w2c_f0 += w2c_f1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_i1 = 4294967295u; + w2c_i2 = 241u; + w2c_i0 = w2c_f33(instance, w2c_i0, w2c_i1, w2c_i2); + w2c_l5 = w2c_i0; + w2c_L0: + w2c_i0 = 0u; + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_f1 = w2c_p2; + w2c_f2 = w2c_p2; + w2c_f1 *= w2c_f2; + w2c_i2 = w2c_l4; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_f3 = w2c_p1; + w2c_f2 -= w2c_f3; + w2c_f3 = 0.5; + w2c_f2 += w2c_f3; + w2c_l11 = w2c_f2; + w2c_f3 = w2c_l11; + w2c_f2 *= w2c_f3; + w2c_f1 -= w2c_f2; + w2c_f0 = FMAX(w2c_f0, w2c_f1); + w2c_f0 = wasm_sqrtf(w2c_f0); + w2c_l12 = w2c_f0; + w2c_f0 = w2c_p0; + w2c_f1 = w2c_l10; + w2c_f0 -= w2c_f1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l6 = w2c_i0; + w2c_f0 = w2c_p0; + w2c_f1 = w2c_l12; + w2c_f0 -= w2c_f1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l7 = w2c_i0; + w2c_f0 = w2c_p0; + w2c_f1 = w2c_l10; + w2c_f0 += w2c_f1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l8 = w2c_i0; + w2c_f0 = w2c_p0; + w2c_f1 = w2c_l12; + w2c_f0 += w2c_f1; + w2c_f0 = wasm_nearbyintf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l9 = w2c_i0; + w2c_f0 = w2c_l12; + w2c_f1 = w2c_l10; + w2c_i0 = w2c_f0 >= w2c_f1; + if (w2c_i0) { + w2c_i0 = w2c_l7; + w2c_i1 = w2c_l6; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l7; + w2c_i1 = w2c_l6; + w2c_i2 = w2c_l4; + w2c_i3 = w2c_p3; + w2c_hline(instance, w2c_i0, w2c_i1, w2c_i2, w2c_i3); + } else { + w2c_i0 = w2c_l7; + w2c_i1 = w2c_l9; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l7; + w2c_i1 = w2c_l4; + w2c_i2 = w2c_p3; + w2c_setPixel(instance, w2c_i0, w2c_i1, w2c_i2); + } + } + w2c_i0 = w2c_l9; + w2c_i1 = w2c_l8; + w2c_i0 = (u32)((s32)w2c_i0 > (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l8; + w2c_i1 = w2c_l9; + w2c_i2 = w2c_l4; + w2c_i3 = w2c_p3; + w2c_hline(instance, w2c_i0, w2c_i1, w2c_i2, w2c_i3); + } else { + w2c_i0 = w2c_l7; + w2c_i1 = w2c_l9; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l9; + w2c_i1 = 1u; + w2c_i0 -= w2c_i1; + w2c_i1 = w2c_l4; + w2c_i2 = w2c_p3; + w2c_setPixel(instance, w2c_i0, w2c_i1, w2c_i2); + } + } + } else { + w2c_i0 = w2c_l7; + w2c_i1 = w2c_l6; + w2c_i0 = (u32)((s32)w2c_i0 > (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l6; + w2c_i1 = w2c_l7; + w2c_i2 = w2c_l4; + w2c_i3 = 1u; + w2c_i2 -= w2c_i3; + w2c_i3 = w2c_p3; + w2c_hline(instance, w2c_i0, w2c_i1, w2c_i2, w2c_i3); + } else { + w2c_i0 = w2c_l6; + w2c_i1 = w2c_l8; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l6; + w2c_i1 = w2c_l4; + w2c_i2 = 1u; + w2c_i1 -= w2c_i2; + w2c_i2 = w2c_p3; + w2c_setPixel(instance, w2c_i0, w2c_i1, w2c_i2); + } + } + w2c_i0 = w2c_l9; + w2c_i1 = w2c_l8; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l9; + w2c_i1 = w2c_l8; + w2c_i2 = w2c_l4; + w2c_i3 = 1u; + w2c_i2 -= w2c_i3; + w2c_i3 = w2c_p3; + w2c_hline(instance, w2c_i0, w2c_i1, w2c_i2, w2c_i3); + } else { + w2c_i0 = w2c_l6; + w2c_i1 = w2c_l8; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l8; + w2c_i1 = 1u; + w2c_i0 -= w2c_i1; + w2c_i1 = w2c_l4; + w2c_i2 = 1u; + w2c_i1 -= w2c_i2; + w2c_i2 = w2c_p3; + w2c_setPixel(instance, w2c_i0, w2c_i1, w2c_i2); + } + } + } + w2c_i0 = w2c_l4; + w2c_i1 = 1u; + w2c_i0 += w2c_i1; + w2c_l4 = w2c_i0; + w2c_f0 = w2c_l12; + w2c_l10 = w2c_f0; + w2c_i0 = w2c_l4; + w2c_i1 = w2c_l5; + w2c_i0 = (u32)((s32)w2c_i0 <= (s32)w2c_i1); + if (w2c_i0) {goto w2c_L0;} + FUNC_EPILOGUE; +} + +static void w2c_line(Z_platform_instance_t* instance, f32 w2c_p0, f32 w2c_p1, f32 w2c_p2, f32 w2c_p3, u32 w2c_p4) { + u32 w2c_l5 = 0; + f32 w2c_l6 = 0, w2c_l7 = 0, w2c_l8 = 0, w2c_l9 = 0, w2c_l10 = 0, w2c_l11 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2; + f32 w2c_f0, w2c_f1, w2c_f2, w2c_f3; + w2c_f0 = w2c_p0; + w2c_f1 = w2c_p2; + w2c_i0 = w2c_f0 > w2c_f1; + if (w2c_i0) { + w2c_f0 = w2c_p0; + w2c_l6 = w2c_f0; + w2c_f0 = w2c_p2; + w2c_p0 = w2c_f0; + w2c_f0 = w2c_l6; + w2c_p2 = w2c_f0; + w2c_f0 = w2c_p1; + w2c_l6 = w2c_f0; + w2c_f0 = w2c_p3; + w2c_p1 = w2c_f0; + w2c_f0 = w2c_l6; + w2c_p3 = w2c_f0; + } + w2c_f0 = w2c_p0; + w2c_i1 = 0u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_i0 = w2c_f0 < w2c_f1; + w2c_f1 = w2c_p2; + w2c_i2 = 0u; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_i1 = w2c_f1 >= w2c_f2; + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_f0 = w2c_p1; + w2c_f1 = w2c_p3; + w2c_f2 = w2c_p1; + w2c_f1 -= w2c_f2; + w2c_f2 = w2c_p0; + w2c_f2 = -(w2c_f2); + w2c_f1 *= w2c_f2; + w2c_f2 = w2c_p2; + w2c_f3 = w2c_p0; + w2c_f2 -= w2c_f3; + w2c_f1 /= w2c_f2; + w2c_f0 += w2c_f1; + w2c_p1 = w2c_f0; + w2c_i0 = 0u; + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_p0 = w2c_f0; + } + w2c_f0 = w2c_p0; + w2c_i1 = 320u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_i0 = w2c_f0 < w2c_f1; + w2c_f1 = w2c_p2; + w2c_i2 = 320u; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_i1 = w2c_f1 >= w2c_f2; + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_f0 = w2c_p3; + w2c_f1 = w2c_p3; + w2c_f2 = w2c_p1; + w2c_f1 -= w2c_f2; + w2c_i2 = 320u; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_f3 = w2c_p2; + w2c_f2 -= w2c_f3; + w2c_f1 *= w2c_f2; + w2c_f2 = w2c_p2; + w2c_f3 = w2c_p0; + w2c_f2 -= w2c_f3; + w2c_f1 /= w2c_f2; + w2c_f0 += w2c_f1; + w2c_p3 = w2c_f0; + w2c_i0 = 320u; + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_p2 = w2c_f0; + } + w2c_f0 = w2c_p1; + w2c_f1 = w2c_p3; + w2c_i0 = w2c_f0 > w2c_f1; + if (w2c_i0) { + w2c_f0 = w2c_p0; + w2c_l6 = w2c_f0; + w2c_f0 = w2c_p2; + w2c_p0 = w2c_f0; + w2c_f0 = w2c_l6; + w2c_p2 = w2c_f0; + w2c_f0 = w2c_p1; + w2c_l6 = w2c_f0; + w2c_f0 = w2c_p3; + w2c_p1 = w2c_f0; + w2c_f0 = w2c_l6; + w2c_p3 = w2c_f0; + } + w2c_f0 = w2c_p1; + w2c_i1 = 0u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_i0 = w2c_f0 < w2c_f1; + w2c_f1 = w2c_p3; + w2c_i2 = 0u; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_i1 = w2c_f1 >= w2c_f2; + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_f0 = w2c_p0; + w2c_f1 = w2c_p2; + w2c_f2 = w2c_p0; + w2c_f1 -= w2c_f2; + w2c_f2 = w2c_p1; + w2c_f2 = -(w2c_f2); + w2c_f1 *= w2c_f2; + w2c_f2 = w2c_p3; + w2c_f3 = w2c_p1; + w2c_f2 -= w2c_f3; + w2c_f1 /= w2c_f2; + w2c_f0 += w2c_f1; + w2c_p0 = w2c_f0; + w2c_i0 = 0u; + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_p1 = w2c_f0; + } + w2c_f0 = w2c_p1; + w2c_i1 = 240u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_i0 = w2c_f0 < w2c_f1; + w2c_f1 = w2c_p3; + w2c_i2 = 240u; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_i1 = w2c_f1 >= w2c_f2; + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_f0 = w2c_p2; + w2c_f1 = w2c_p2; + w2c_f2 = w2c_p0; + w2c_f1 -= w2c_f2; + w2c_i2 = 240u; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_f3 = w2c_p3; + w2c_f2 -= w2c_f3; + w2c_f1 *= w2c_f2; + w2c_f2 = w2c_p3; + w2c_f3 = w2c_p1; + w2c_f2 -= w2c_f3; + w2c_f1 /= w2c_f2; + w2c_f0 += w2c_f1; + w2c_p2 = w2c_f0; + w2c_i0 = 240u; + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_p3 = w2c_f0; + } + w2c_f0 = w2c_p2; + w2c_f1 = w2c_p0; + w2c_f0 -= w2c_f1; + w2c_l7 = w2c_f0; + w2c_f0 = wasm_fabsf(w2c_f0); + w2c_f1 = w2c_p3; + w2c_f2 = w2c_p1; + w2c_f1 -= w2c_f2; + w2c_l8 = w2c_f1; + w2c_i0 = w2c_f0 >= w2c_f1; + if (w2c_i0) { + w2c_f0 = w2c_l7; + w2c_l9 = w2c_f0; + w2c_f0 = w2c_p0; + w2c_l10 = w2c_f0; + } else { + w2c_f0 = w2c_l8; + w2c_l9 = w2c_f0; + w2c_f0 = w2c_p1; + w2c_l10 = w2c_f0; + } + w2c_f0 = w2c_l9; + w2c_i1 = 0u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_i0 = w2c_f0 == w2c_f1; + if (w2c_i0) { + w2c_f0 = w2c_p0; + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_f1 = w2c_p1; + w2c_i1 = I32_TRUNC_S_F32(w2c_f1); + w2c_i2 = w2c_p4; + w2c_setPixel(instance, w2c_i0, w2c_i1, w2c_i2); + goto w2c_Bfunc; + } + w2c_f0 = w2c_l10; + w2c_f1 = w2c_l9; + w2c_f0 += w2c_f1; + w2c_f0 = wasm_floorf(w2c_f0); + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_f1 = w2c_l10; + w2c_f1 = wasm_floorf(w2c_f1); + w2c_i1 = I32_TRUNC_S_F32(w2c_f1); + w2c_i0 -= w2c_i1; + w2c_l5 = w2c_i0; + w2c_f0 = w2c_l10; + w2c_f0 = wasm_floorf(w2c_f0); + w2c_f1 = 0.5; + w2c_f0 += w2c_f1; + w2c_f1 = w2c_l10; + w2c_f0 -= w2c_f1; + w2c_l10 = w2c_f0; + w2c_f0 = w2c_l9; + w2c_i1 = 0u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_i0 = w2c_f0 < w2c_f1; + if (w2c_i0) { + w2c_i0 = 0u; + w2c_i1 = w2c_l5; + w2c_i0 -= w2c_i1; + w2c_l5 = w2c_i0; + w2c_f0 = w2c_l10; + w2c_f0 = -(w2c_f0); + w2c_l10 = w2c_f0; + w2c_f0 = w2c_l9; + w2c_f0 = -(w2c_f0); + w2c_l9 = w2c_f0; + } + w2c_f0 = w2c_l7; + w2c_f1 = w2c_l9; + w2c_f0 /= w2c_f1; + w2c_l7 = w2c_f0; + w2c_f0 = w2c_l8; + w2c_f1 = w2c_l9; + w2c_f0 /= w2c_f1; + w2c_l8 = w2c_f0; + w2c_f0 = w2c_l9; + w2c_i1 = 0u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_f2 = w2c_l10; + w2c_f1 = FMAX(w2c_f1, w2c_f2); + w2c_f0 = FMIN(w2c_f0, w2c_f1); + w2c_l11 = w2c_f0; + w2c_f0 = w2c_p0; + w2c_f1 = w2c_l11; + w2c_f2 = w2c_l7; + w2c_f1 *= w2c_f2; + w2c_f0 += w2c_f1; + w2c_i0 = I32_TRUNC_SAT_S_F32(w2c_f0); + w2c_f1 = w2c_p1; + w2c_f2 = w2c_l11; + w2c_f3 = w2c_l8; + w2c_f2 *= w2c_f3; + w2c_f1 += w2c_f2; + w2c_i1 = I32_TRUNC_SAT_S_F32(w2c_f1); + w2c_i2 = w2c_p4; + w2c_setPixel(instance, w2c_i0, w2c_i1, w2c_i2); + w2c_i0 = w2c_l5; + w2c_i0 = !(w2c_i0); + if (w2c_i0) { + goto w2c_Bfunc; + } + w2c_f0 = w2c_p0; + w2c_i1 = 1u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_f2 = w2c_l10; + w2c_f1 += w2c_f2; + w2c_f2 = w2c_l7; + w2c_f1 *= w2c_f2; + w2c_f0 += w2c_f1; + w2c_p0 = w2c_f0; + w2c_f0 = w2c_p1; + w2c_i1 = 1u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_f2 = w2c_l10; + w2c_f1 += w2c_f2; + w2c_f2 = w2c_l8; + w2c_f1 *= w2c_f2; + w2c_f0 += w2c_f1; + w2c_p1 = w2c_f0; + w2c_f0 = w2c_l10; + w2c_i1 = w2c_l5; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_f0 += w2c_f1; + w2c_l10 = w2c_f0; + w2c_L10: + w2c_i0 = w2c_l5; + w2c_i1 = 1u; + w2c_i0 -= w2c_i1; + w2c_l5 = w2c_i0; + if (w2c_i0) { + w2c_f0 = w2c_p0; + w2c_i0 = I32_TRUNC_SAT_S_F32(w2c_f0); + w2c_f1 = w2c_p1; + w2c_i1 = I32_TRUNC_SAT_S_F32(w2c_f1); + w2c_i2 = w2c_p4; + w2c_setPixel(instance, w2c_i0, w2c_i1, w2c_i2); + w2c_f0 = w2c_p0; + w2c_f1 = w2c_l7; + w2c_f0 += w2c_f1; + w2c_p0 = w2c_f0; + w2c_f0 = w2c_p1; + w2c_f1 = w2c_l8; + w2c_f0 += w2c_f1; + w2c_p1 = w2c_f0; + goto w2c_L10; + } + w2c_f0 = w2c_l9; + w2c_f1 = w2c_l10; + w2c_f0 = FMIN(w2c_f0, w2c_f1); + w2c_f1 = w2c_l10; + w2c_f0 -= w2c_f1; + w2c_l11 = w2c_f0; + w2c_f0 = w2c_p0; + w2c_f1 = w2c_l11; + w2c_f2 = w2c_l7; + w2c_f1 *= w2c_f2; + w2c_f0 += w2c_f1; + w2c_i0 = I32_TRUNC_SAT_S_F32(w2c_f0); + w2c_f1 = w2c_p1; + w2c_f2 = w2c_l11; + w2c_f3 = w2c_l8; + w2c_f2 *= w2c_f3; + w2c_f1 += w2c_f2; + w2c_i1 = I32_TRUNC_SAT_S_F32(w2c_f1); + w2c_i2 = w2c_p4; + w2c_setPixel(instance, w2c_i0, w2c_i1, w2c_i2); + w2c_Bfunc:; + FUNC_EPILOGUE; +} + +static void w2c_blitSprite(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1, u32 w2c_p2, u32 w2c_p3, u32 w2c_p4) { + u32 w2c_l5 = 0, w2c_l6 = 0, w2c_l7 = 0, w2c_l8 = 0, w2c_l9 = 0, w2c_l10 = 0, w2c_l11 = 0, w2c_l12 = 0, + w2c_l13 = 0, w2c_l14 = 0, w2c_l15 = 0, w2c_l16 = 0, w2c_l17 = 0, w2c_l18 = 0, w2c_l19 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3, w2c_i4, w2c_i5; + w2c_i0 = 240u; + w2c_i1 = w2c_p3; + w2c_i0 -= w2c_i1; + w2c_i1 = w2c_p1; + w2c_i2 = 16u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i2 = w2c_p1; + w2c_i3 = 65535u; + w2c_i2 &= w2c_i3; + w2c_l5 = w2c_i2; + w2c_i3 = w2c_p1; + w2c_i4 = 16u; + w2c_i3 = (u32)((s32)w2c_i3 >> (w2c_i4 & 31)); + w2c_i1 = w2c_i3 ? w2c_i1 : w2c_i2; + w2c_l6 = w2c_i1; + w2c_i2 = w2c_p3; + w2c_i3 = w2c_l6; + w2c_i2 += w2c_i3; + w2c_i3 = 240u; + w2c_i2 = (u32)((s32)w2c_i2 > (s32)w2c_i3); + w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; + w2c_l10 = w2c_i0; + w2c_i1 = 0u; + w2c_i2 = w2c_p3; + w2c_i1 -= w2c_i2; + w2c_i2 = 0u; + w2c_i3 = w2c_p3; + w2c_i4 = 0u; + w2c_i3 = (u32)((s32)w2c_i3 < (s32)w2c_i4); + w2c_i1 = w2c_i3 ? w2c_i1 : w2c_i2; + w2c_l9 = w2c_i1; + w2c_i0 -= w2c_i1; + w2c_l11 = w2c_i0; + w2c_i1 = 0u; + w2c_i0 = (u32)((s32)w2c_i0 <= (s32)w2c_i1); + w2c_i1 = 320u; + w2c_i2 = w2c_p2; + w2c_i1 -= w2c_i2; + w2c_i2 = w2c_l5; + w2c_i3 = w2c_p2; + w2c_i4 = w2c_l5; + w2c_i3 += w2c_i4; + w2c_i4 = 320u; + w2c_i3 = (u32)((s32)w2c_i3 > (s32)w2c_i4); + w2c_i1 = w2c_i3 ? w2c_i1 : w2c_i2; + w2c_l8 = w2c_i1; + w2c_i2 = 0u; + w2c_i3 = w2c_p2; + w2c_i2 -= w2c_i3; + w2c_i3 = 0u; + w2c_i4 = w2c_p2; + w2c_i5 = 0u; + w2c_i4 = (u32)((s32)w2c_i4 < (s32)w2c_i5); + w2c_i2 = w2c_i4 ? w2c_i2 : w2c_i3; + w2c_l7 = w2c_i2; + w2c_i1 -= w2c_i2; + w2c_l12 = w2c_i1; + w2c_i2 = 0u; + w2c_i1 = (u32)((s32)w2c_i1 <= (s32)w2c_i2); + w2c_i0 |= w2c_i1; + if (w2c_i0) { + goto w2c_Bfunc; + } + w2c_i0 = w2c_p4; + w2c_i1 = 511u; + w2c_i0 &= w2c_i1; + w2c_i1 = 256u; + w2c_i0 -= w2c_i1; + w2c_l13 = w2c_i0; + w2c_i0 = 1u; + w2c_i1 = w2c_p4; + w2c_i2 = 8u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i2 = 2u; + w2c_i1 &= w2c_i2; + w2c_i0 -= w2c_i1; + w2c_l14 = w2c_i0; + w2c_i1 = 0u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_p0; + w2c_i1 = w2c_l5; + w2c_i2 = 1u; + w2c_i1 -= w2c_i2; + w2c_i0 += w2c_i1; + w2c_p0 = w2c_i0; + } + w2c_i0 = 1u; + w2c_i1 = w2c_p4; + w2c_i2 = 9u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i2 = 2u; + w2c_i1 &= w2c_i2; + w2c_i0 -= w2c_i1; + w2c_l15 = w2c_i0; + w2c_i1 = 0u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_p0; + w2c_i1 = w2c_l6; + w2c_i2 = 1u; + w2c_i1 -= w2c_i2; + w2c_i2 = w2c_l5; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_p0 = w2c_i0; + } + w2c_i0 = w2c_p0; + w2c_i1 = w2c_l7; + w2c_i2 = w2c_l14; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l9; + w2c_i2 = w2c_l15; + w2c_i1 *= w2c_i2; + w2c_i2 = w2c_l5; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_l16 = w2c_i0; + w2c_i0 = w2c_p2; + w2c_i1 = w2c_l7; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_p3; + w2c_i2 = w2c_l9; + w2c_i1 += w2c_i2; + w2c_i2 = 320u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_l17 = w2c_i0; + w2c_L3: + w2c_i0 = 0u; + w2c_l18 = w2c_i0; + w2c_L4: + w2c_i0 = w2c_l16; + w2c_i1 = w2c_l18; + w2c_i2 = w2c_l14; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0)); + w2c_l19 = w2c_i0; + w2c_i1 = w2c_l13; + w2c_i0 = w2c_i0 != w2c_i1; + if (w2c_i0) { + w2c_i0 = w2c_l17; + w2c_i1 = w2c_l18; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l19; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 120, w2c_i1); + } + w2c_i0 = w2c_l18; + w2c_i1 = 1u; + w2c_i0 += w2c_i1; + w2c_l18 = w2c_i0; + w2c_i1 = w2c_l12; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L4;} + w2c_i0 = w2c_l16; + w2c_i1 = w2c_l5; + w2c_i2 = w2c_l15; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_l16 = w2c_i0; + w2c_i0 = w2c_l17; + w2c_i1 = 320u; + w2c_i0 += w2c_i1; + w2c_l17 = w2c_i0; + w2c_i0 = w2c_l11; + w2c_i1 = 1u; + w2c_i0 -= w2c_i1; + w2c_l11 = w2c_i0; + if (w2c_i0) {goto w2c_L3;} + w2c_Bfunc:; + FUNC_EPILOGUE; +} + +static void w2c_grabSprite(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1, u32 w2c_p2, u32 w2c_p3, u32 w2c_p4) { + u32 w2c_l5 = 0, w2c_l6 = 0, w2c_l7 = 0, w2c_l8 = 0, w2c_l9 = 0, w2c_l10 = 0, w2c_l11 = 0, w2c_l12 = 0, + w2c_l13 = 0, w2c_l14 = 0, w2c_l15 = 0, w2c_l16 = 0, w2c_l17 = 0, w2c_l18 = 0, w2c_l19 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3, w2c_i4, w2c_i5; + w2c_i0 = 240u; + w2c_i1 = w2c_p3; + w2c_i0 -= w2c_i1; + w2c_i1 = w2c_p1; + w2c_i2 = 16u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i2 = w2c_p1; + w2c_i3 = 65535u; + w2c_i2 &= w2c_i3; + w2c_l5 = w2c_i2; + w2c_i3 = w2c_p1; + w2c_i4 = 16u; + w2c_i3 = (u32)((s32)w2c_i3 >> (w2c_i4 & 31)); + w2c_i1 = w2c_i3 ? w2c_i1 : w2c_i2; + w2c_l6 = w2c_i1; + w2c_i2 = w2c_p3; + w2c_i3 = w2c_l6; + w2c_i2 += w2c_i3; + w2c_i3 = 240u; + w2c_i2 = (u32)((s32)w2c_i2 > (s32)w2c_i3); + w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; + w2c_l10 = w2c_i0; + w2c_i1 = 0u; + w2c_i2 = w2c_p3; + w2c_i1 -= w2c_i2; + w2c_i2 = 0u; + w2c_i3 = w2c_p3; + w2c_i4 = 0u; + w2c_i3 = (u32)((s32)w2c_i3 < (s32)w2c_i4); + w2c_i1 = w2c_i3 ? w2c_i1 : w2c_i2; + w2c_l9 = w2c_i1; + w2c_i0 -= w2c_i1; + w2c_l11 = w2c_i0; + w2c_i1 = 0u; + w2c_i0 = (u32)((s32)w2c_i0 <= (s32)w2c_i1); + w2c_i1 = 320u; + w2c_i2 = w2c_p2; + w2c_i1 -= w2c_i2; + w2c_i2 = w2c_l5; + w2c_i3 = w2c_p2; + w2c_i4 = w2c_l5; + w2c_i3 += w2c_i4; + w2c_i4 = 320u; + w2c_i3 = (u32)((s32)w2c_i3 > (s32)w2c_i4); + w2c_i1 = w2c_i3 ? w2c_i1 : w2c_i2; + w2c_l8 = w2c_i1; + w2c_i2 = 0u; + w2c_i3 = w2c_p2; + w2c_i2 -= w2c_i3; + w2c_i3 = 0u; + w2c_i4 = w2c_p2; + w2c_i5 = 0u; + w2c_i4 = (u32)((s32)w2c_i4 < (s32)w2c_i5); + w2c_i2 = w2c_i4 ? w2c_i2 : w2c_i3; + w2c_l7 = w2c_i2; + w2c_i1 -= w2c_i2; + w2c_l12 = w2c_i1; + w2c_i2 = 0u; + w2c_i1 = (u32)((s32)w2c_i1 <= (s32)w2c_i2); + w2c_i0 |= w2c_i1; + if (w2c_i0) { + goto w2c_Bfunc; + } + w2c_i0 = w2c_p4; + w2c_i1 = 511u; + w2c_i0 &= w2c_i1; + w2c_i1 = 256u; + w2c_i0 -= w2c_i1; + w2c_l13 = w2c_i0; + w2c_i0 = 1u; + w2c_i1 = w2c_p4; + w2c_i2 = 8u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i2 = 2u; + w2c_i1 &= w2c_i2; + w2c_i0 -= w2c_i1; + w2c_l14 = w2c_i0; + w2c_i1 = 0u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_p0; + w2c_i1 = w2c_l5; + w2c_i2 = 1u; + w2c_i1 -= w2c_i2; + w2c_i0 += w2c_i1; + w2c_p0 = w2c_i0; + } + w2c_i0 = 1u; + w2c_i1 = w2c_p4; + w2c_i2 = 9u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i2 = 2u; + w2c_i1 &= w2c_i2; + w2c_i0 -= w2c_i1; + w2c_l15 = w2c_i0; + w2c_i1 = 0u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_p0; + w2c_i1 = w2c_l6; + w2c_i2 = 1u; + w2c_i1 -= w2c_i2; + w2c_i2 = w2c_l5; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_p0 = w2c_i0; + } + w2c_i0 = w2c_p0; + w2c_i1 = w2c_l7; + w2c_i2 = w2c_l14; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l9; + w2c_i2 = w2c_l15; + w2c_i1 *= w2c_i2; + w2c_i2 = w2c_l5; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_l16 = w2c_i0; + w2c_i0 = w2c_p2; + w2c_i1 = w2c_l7; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_p3; + w2c_i2 = w2c_l9; + w2c_i1 += w2c_i2; + w2c_i2 = 320u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_l17 = w2c_i0; + w2c_L3: + w2c_i0 = 0u; + w2c_l18 = w2c_i0; + w2c_L4: + w2c_i0 = w2c_l17; + w2c_i1 = w2c_l18; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 120u); + w2c_l19 = w2c_i0; + w2c_i1 = w2c_l13; + w2c_i0 = w2c_i0 != w2c_i1; + if (w2c_i0) { + w2c_i0 = w2c_l16; + w2c_i1 = w2c_l18; + w2c_i2 = w2c_l14; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l19; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0), w2c_i1); + } + w2c_i0 = w2c_l18; + w2c_i1 = 1u; + w2c_i0 += w2c_i1; + w2c_l18 = w2c_i0; + w2c_i1 = w2c_l12; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L4;} + w2c_i0 = w2c_l16; + w2c_i1 = w2c_l5; + w2c_i2 = w2c_l15; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_l16 = w2c_i0; + w2c_i0 = w2c_l17; + w2c_i1 = 320u; + w2c_i0 += w2c_i1; + w2c_l17 = w2c_i0; + w2c_i0 = w2c_l11; + w2c_i1 = 1u; + w2c_i0 -= w2c_i1; + w2c_l11 = w2c_i0; + if (w2c_i0) {goto w2c_L3;} + w2c_Bfunc:; + FUNC_EPILOGUE; +} + +static void w2c_printChar(Z_platform_instance_t* instance, u32 w2c_p0) { + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1; + w2c_L0: + w2c_i0 = w2c_p0; + w2c_i1 = 255u; + w2c_i0 &= w2c_i1; + w2c_f34(instance, w2c_i0); + w2c_i0 = w2c_p0; + w2c_i1 = 8u; + w2c_i0 >>= (w2c_i1 & 31); + w2c_p0 = w2c_i0; + if (w2c_i0) {goto w2c_L0;} + FUNC_EPILOGUE; +} + +static void w2c_printString(Z_platform_instance_t* instance, u32 w2c_p0) { + u32 w2c_l1 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1; + w2c_L0: + w2c_i0 = w2c_p0; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0)); + w2c_l1 = w2c_i0; + if (w2c_i0) { + w2c_i0 = w2c_l1; + w2c_printChar(instance, w2c_i0); + w2c_i0 = w2c_p0; + w2c_i1 = 1u; + w2c_i0 += w2c_i1; + w2c_p0 = w2c_i0; + goto w2c_L0; + } + FUNC_EPILOGUE; +} + +static void w2c_printInt(Z_platform_instance_t* instance, u32 w2c_p0) { + u32 w2c_l1 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3; + w2c_i0 = 77823u; + w2c_l1 = w2c_i0; + w2c_i1 = 0u; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0), w2c_i1); + w2c_i0 = w2c_p0; + w2c_i1 = 0u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = 45u; + w2c_printChar(instance, w2c_i0); + w2c_i0 = 0u; + w2c_i1 = w2c_p0; + w2c_i0 -= w2c_i1; + w2c_p0 = w2c_i0; + } + w2c_L1: + w2c_i0 = w2c_l1; + w2c_i1 = 1u; + w2c_i0 -= w2c_i1; + w2c_l1 = w2c_i0; + w2c_i1 = 48u; + w2c_i2 = w2c_p0; + w2c_i3 = 10u; + w2c_i2 = REM_U(w2c_i2, w2c_i3); + w2c_i1 += w2c_i2; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0), w2c_i1); + w2c_i0 = w2c_p0; + w2c_i1 = 10u; + w2c_i0 = DIV_U(w2c_i0, w2c_i1); + w2c_p0 = w2c_i0; + if (w2c_i0) {goto w2c_L1;} + w2c_i0 = w2c_l1; + w2c_printString(instance, w2c_i0); + FUNC_EPILOGUE; +} + +static void w2c_setTextColor(Z_platform_instance_t* instance, u32 w2c_p0) { + FUNC_PROLOGUE; + u32 w2c_i0; + w2c_i0 = w2c_p0; + instance->w2c_g3 = w2c_i0; + FUNC_EPILOGUE; +} + +static void w2c_setBackgroundColor(Z_platform_instance_t* instance, u32 w2c_p0) { + FUNC_PROLOGUE; + u32 w2c_i0; + w2c_i0 = w2c_p0; + instance->w2c_g4 = w2c_i0; + FUNC_EPILOGUE; +} + +static void w2c_setCursorPosition(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1) { + u32 w2c_l2 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3; + w2c_i0 = w2c_p0; + w2c_i1 = 1u; + w2c_i2 = 8u; + w2c_i3 = instance->w2c_g5; + w2c_i1 = w2c_i3 ? w2c_i1 : w2c_i2; + w2c_l2 = w2c_i1; + w2c_i0 *= w2c_i1; + instance->w2c_g1 = w2c_i0; + w2c_i0 = w2c_p1; + w2c_i1 = w2c_l2; + w2c_i0 *= w2c_i1; + instance->w2c_g2 = w2c_i0; + FUNC_EPILOGUE; +} + +static void w2c_playNote(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1) { + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3, w2c_i4; + w2c_i0 = w2c_p0; + w2c_i1 = 6u; + w2c_i0 *= w2c_i1; + w2c_i1 = w2c_p0; + w2c_i2 = 6u; + w2c_i1 *= w2c_i2; + w2c_i1 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i1) + 80u); + w2c_i2 = 254u; + w2c_i1 &= w2c_i2; + w2c_i2 = w2c_p1; + if (w2c_i2) { + w2c_i2 = w2c_p0; + w2c_i3 = 6u; + w2c_i2 *= w2c_i3; + w2c_i3 = w2c_p1; + w2c_i4 = 127u; + w2c_i3 &= w2c_i4; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i2) + 83, w2c_i3); + w2c_i2 = 2u; + w2c_i3 = w2c_p1; + w2c_i4 = 7u; + w2c_i3 = (u32)((s32)w2c_i3 >> (w2c_i4 & 31)); + w2c_i3 = !(w2c_i3); + w2c_i2 |= w2c_i3; + } else { + w2c_i2 = 0u; + } + w2c_i1 ^= w2c_i2; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 80, w2c_i1); + FUNC_EPILOGUE; +} + +static void w2c_endFrame(Z_platform_instance_t* instance) { + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1; + w2c_i0 = 68u; + w2c_i1 = 68u; + w2c_i1 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i1)); + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 4, w2c_i1); + FUNC_EPILOGUE; +} + +static f32 w2c_sndGes(Z_platform_instance_t* instance, u32 w2c_p0) { + u32 w2c_l1 = 0, w2c_l2 = 0, w2c_l3 = 0, w2c_l4 = 0, w2c_l5 = 0, w2c_l6 = 0, w2c_l7 = 0, w2c_l8 = 0, + w2c_l9 = 0, w2c_l10 = 0, w2c_l11 = 0, w2c_l12 = 0, w2c_l13 = 0, w2c_l14 = 0, w2c_l15 = 0, w2c_l16 = 0, + w2c_l17 = 0, w2c_l18 = 0, w2c_l19 = 0, w2c_l20 = 0, w2c_l21 = 0, w2c_l22 = 0, w2c_l23 = 0, w2c_l24 = 0, + w2c_l25 = 0, w2c_l26 = 0, w2c_l27 = 0, w2c_l28 = 0, w2c_l29 = 0, w2c_l30 = 0, w2c_l31 = 0, w2c_l32 = 0, + w2c_l33 = 0, w2c_l34 = 0, w2c_l35 = 0, w2c_l36 = 0, w2c_l37 = 0, w2c_l38 = 0, w2c_l39 = 0, w2c_l40 = 0, + w2c_l41 = 0, w2c_l42 = 0, w2c_l43 = 0, w2c_l44 = 0, w2c_l45 = 0, w2c_l46 = 0, w2c_l47 = 0, w2c_l48 = 0, + w2c_l49 = 0; + f32 w2c_l50 = 0, w2c_l51 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3, w2c_i4, w2c_i5, w2c_i6; + f32 w2c_f0, w2c_f1, w2c_f2, w2c_f3, w2c_f4, w2c_f5; + w2c_i0 = 0u; + w2c_i0 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i0) + 76920u); + w2c_l1 = w2c_i0; + w2c_i0 = w2c_p0; + w2c_i1 = 127u; + w2c_i0 &= w2c_i1; + w2c_i0 = !(w2c_i0); + if (w2c_i0) { + w2c_L1: + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i0 += w2c_i1; + w2c_i1 = 0u; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 96, w2c_i1); + w2c_i0 = w2c_l2; + w2c_i1 = 4u; + w2c_i0 += w2c_i1; + w2c_l2 = w2c_i0; + w2c_i1 = 512u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L1;} + w2c_L2: + w2c_i0 = w2c_l1; + w2c_i1 = 32u; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l3; + w2c_i2 = 8u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_l4 = w2c_i0; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 1u); + w2c_l6 = w2c_i0; + w2c_i0 = w2c_l4; + w2c_i0 = i32_load16_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 2u); + w2c_l7 = w2c_i0; + w2c_i0 = w2c_l4; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0)); + w2c_l8 = w2c_i0; + w2c_i1 = w2c_l1; + w2c_i2 = w2c_l3; + w2c_i3 = 6u; + w2c_i2 *= w2c_i3; + w2c_i1 += w2c_i2; + w2c_l5 = w2c_i1; + w2c_i1 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i1)); + w2c_l9 = w2c_i1; + w2c_i0 ^= w2c_i1; + w2c_i1 = w2c_l9; + w2c_i2 = 2u; + w2c_i1 |= w2c_i2; + w2c_i0 &= w2c_i1; + w2c_i1 = 3u; + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_i0 = 1u; + w2c_l6 = w2c_i0; + w2c_i0 = 0u; + w2c_l7 = w2c_i0; + } + w2c_i0 = w2c_l4; + w2c_i1 = w2c_l9; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0), w2c_i1); + w2c_i0 = w2c_l6; + if (w2c_i0) { + w2c_i0 = w2c_l7; + w2c_i1 = 12u; + w2c_f2 = 1.67499995; + w2c_i3 = 15u; + w2c_i4 = w2c_l5; + w2c_i4 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i4) + 4u); + w2c_i5 = 15u; + w2c_i4 &= w2c_i5; + w2c_l10 = w2c_i4; + w2c_i3 -= w2c_i4; + w2c_f3 = (f32)(s32)(w2c_i3); + w2c_f2 = (*Z_envZ_pow)(instance->Z_env_instance, w2c_f2, w2c_f3); + w2c_i2 = I32_TRUNC_S_F32(w2c_f2); + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_l7 = w2c_i0; + w2c_i0 = w2c_l7; + w2c_i1 = 65535u; + w2c_i0 = (u32)((s32)w2c_i0 >= (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = 65535u; + w2c_l7 = w2c_i0; + w2c_i0 = 0u; + w2c_l6 = w2c_i0; + } + } else { + w2c_i0 = w2c_l7; + w2c_i1 = 8u; + w2c_f2 = 1.5625; + w2c_i3 = 15u; + w2c_i4 = w2c_l5; + w2c_i5 = w2c_l9; + w2c_i6 = 1u; + w2c_i5 &= w2c_i6; + w2c_i4 -= w2c_i5; + w2c_i4 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i4) + 5u); + w2c_i5 = 4u; + w2c_i4 = (u32)((s32)w2c_i4 >> (w2c_i5 & 31)); + w2c_i3 -= w2c_i4; + w2c_f3 = (f32)(s32)(w2c_i3); + w2c_f2 = (*Z_envZ_pow)(instance->Z_env_instance, w2c_f2, w2c_f3); + w2c_i2 = I32_TRUNC_S_F32(w2c_f2); + w2c_i1 *= w2c_i2; + w2c_i2 = w2c_l7; + w2c_i3 = 8192u; + w2c_i2 += w2c_i3; + w2c_i1 *= w2c_i2; + w2c_i2 = 16u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i0 -= w2c_i1; + w2c_l7 = w2c_i0; + w2c_i0 = w2c_l7; + w2c_i1 = w2c_l9; + w2c_i2 = 1u; + w2c_i1 &= w2c_i2; + w2c_i2 = w2c_l5; + w2c_i2 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i2) + 5u); + w2c_i3 = 15u; + w2c_i2 &= w2c_i3; + w2c_i3 = 12u; + w2c_i2 <<= (w2c_i3 & 31); + w2c_i1 *= w2c_i2; + w2c_l11 = w2c_i1; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l11; + w2c_l7 = w2c_i0; + } + } + w2c_i0 = w2c_l4; + w2c_i1 = w2c_l6; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 1, w2c_i1); + w2c_i0 = w2c_l4; + w2c_i1 = w2c_l7; + i32_store16(instance->Z_envZ_memory, (u64)(w2c_i0) + 2, w2c_i1); + w2c_i0 = 440u; + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_f1 = 2; + w2c_i2 = w2c_l5; + w2c_i2 = i32_load16_u(instance->Z_envZ_memory, (u64)(w2c_i2) + 2u); + w2c_i3 = 17664u; + w2c_i2 -= w2c_i3; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_i3 = 3072u; + w2c_f3 = (f32)(s32)(w2c_i3); + w2c_f2 /= w2c_f3; + w2c_f1 = (*Z_envZ_pow)(instance->Z_env_instance, w2c_f1, w2c_f2); + w2c_f0 *= w2c_f1; + w2c_l50 = w2c_f0; + w2c_f1 = 1.48607707; + w2c_f0 *= w2c_f1; + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l12 = w2c_i0; + w2c_i0 = w2c_l4; + w2c_i0 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i0) + 4u); + w2c_l13 = w2c_i0; + w2c_i0 = w2c_l5; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 1u); + w2c_i1 = 128u; + w2c_i0 -= w2c_i1; + w2c_i1 = 255u; + w2c_i0 *= w2c_i1; + w2c_l14 = w2c_i0; + w2c_i0 = 1u; + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_i1 = w2c_l12; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_f0 /= w2c_f1; + w2c_l51 = w2c_f0; + w2c_i0 = 0u; + w2c_l2 = w2c_i0; + w2c_i0 = w2c_l9; + w2c_i1 = 6u; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_l15 = w2c_i0; + w2c_i0 = w2c_l15; + w2c_i1 = 2u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l15; + if (w2c_i0) { + w2c_i0 = w2c_l5; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 1u); + w2c_i1 = 23u; + w2c_i0 <<= (w2c_i1 & 31); + w2c_l16 = w2c_i0; + w2c_i0 = 511u; + w2c_i1 = w2c_l5; + w2c_i1 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i1) + 1u); + w2c_i0 -= w2c_i1; + w2c_i1 = 23u; + w2c_i0 <<= (w2c_i1 & 31); + w2c_l17 = w2c_i0; + w2c_L9: + w2c_i0 = w2c_l13; + w2c_i1 = 32768u; + w2c_i0 ^= w2c_i1; + w2c_i1 = 16u; + w2c_i0 <<= (w2c_i1 & 31); + w2c_l18 = w2c_i0; + w2c_i0 = w2c_l18; + w2c_i1 = 16u; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_i1 = w2c_l13; + w2c_f2 = w2c_l51; + w2c_i3 = 4294934529u; + w2c_i1 = w2c_f37(instance, w2c_i1, w2c_f2, w2c_i3); + w2c_i0 -= w2c_i1; + w2c_l19 = w2c_i0; + w2c_i0 = 0u; + w2c_i1 = w2c_l19; + w2c_i0 -= w2c_i1; + w2c_i1 = w2c_l19; + w2c_i2 = w2c_l18; + w2c_i3 = w2c_l16; + w2c_i2 = w2c_i2 >= w2c_i3; + w2c_i3 = w2c_l18; + w2c_i4 = w2c_l17; + w2c_i3 = w2c_i3 < w2c_i4; + w2c_i2 &= w2c_i3; + w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; + w2c_l20 = w2c_i0; + w2c_i0 = w2c_l20; + w2c_i1 = w2c_l18; + w2c_i2 = w2c_l16; + w2c_i1 -= w2c_i2; + w2c_i2 = 16u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_f2 = w2c_l51; + w2c_i3 = 0u; + w2c_i4 = w2c_l19; + w2c_i3 -= w2c_i4; + w2c_i1 = w2c_f37(instance, w2c_i1, w2c_f2, w2c_i3); + w2c_i0 -= w2c_i1; + w2c_i1 = w2c_l18; + w2c_i2 = w2c_l17; + w2c_i1 -= w2c_i2; + w2c_i2 = 16u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_f2 = w2c_l51; + w2c_i3 = w2c_l19; + w2c_i1 = w2c_f37(instance, w2c_i1, w2c_f2, w2c_i3); + w2c_i0 -= w2c_i1; + w2c_l20 = w2c_i0; + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l20; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 608, w2c_i1); + w2c_i0 = w2c_l13; + w2c_i1 = w2c_l12; + w2c_i0 += w2c_i1; + w2c_l13 = w2c_i0; + w2c_i0 = w2c_l2; + w2c_i1 = 4u; + w2c_i0 += w2c_i1; + w2c_l2 = w2c_i0; + w2c_i1 = 256u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L9;} + } else { + w2c_i0 = 32768u; + w2c_i1 = w2c_l5; + w2c_i1 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i1) + 1u); + w2c_i2 = 128u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_l21 = w2c_i0; + w2c_L10: + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i0 += w2c_i1; + w2c_i1 = 4294934528u; + w2c_i2 = 32767u; + w2c_i3 = w2c_l13; + w2c_i4 = 65535u; + w2c_i3 &= w2c_i4; + w2c_i4 = w2c_l21; + w2c_i3 = (u32)((s32)w2c_i3 < (s32)w2c_i4); + w2c_i1 = w2c_i3 ? w2c_i1 : w2c_i2; + w2c_i2 = w2c_l13; + w2c_f3 = w2c_l51; + w2c_i4 = 4294934529u; + w2c_i2 = w2c_f37(instance, w2c_i2, w2c_f3, w2c_i4); + w2c_i1 -= w2c_i2; + w2c_i2 = w2c_l13; + w2c_i3 = w2c_l21; + w2c_i2 -= w2c_i3; + w2c_f3 = w2c_l51; + w2c_i4 = 32767u; + w2c_i2 = w2c_f37(instance, w2c_i2, w2c_f3, w2c_i4); + w2c_i1 -= w2c_i2; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 608, w2c_i1); + w2c_i0 = w2c_l13; + w2c_i1 = w2c_l12; + w2c_i0 += w2c_i1; + w2c_l13 = w2c_i0; + w2c_i0 = w2c_l2; + w2c_i1 = 4u; + w2c_i0 += w2c_i1; + w2c_l2 = w2c_i0; + w2c_i1 = 256u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L10;} + } + } else { + w2c_i0 = w2c_l15; + w2c_i1 = 2u; + w2c_i0 = w2c_i0 == w2c_i1; + if (w2c_i0) { + w2c_i0 = w2c_l5; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 1u); + w2c_i1 = 256u; + w2c_i0 += w2c_i1; + w2c_l22 = w2c_i0; + w2c_L12: + w2c_i0 = w2c_l13; + w2c_i1 = 16u; + w2c_i0 <<= (w2c_i1 & 31); + w2c_l23 = w2c_i0; + w2c_i0 = w2c_l23; + w2c_i1 = w2c_l23; + w2c_i2 = 31u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i0 ^= w2c_i1; + w2c_l23 = w2c_i0; + w2c_i0 = w2c_l23; + w2c_i1 = 8u; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_i1 = w2c_l22; + w2c_i0 *= w2c_i1; + w2c_l23 = w2c_i0; + w2c_i0 = w2c_l23; + w2c_i1 = w2c_l23; + w2c_i2 = 31u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i0 ^= w2c_i1; + w2c_l23 = w2c_i0; + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l23; + w2c_i2 = 15u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i2 = 32768u; + w2c_i1 -= w2c_i2; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 608, w2c_i1); + w2c_i0 = w2c_l13; + w2c_i1 = w2c_l12; + w2c_i0 += w2c_i1; + w2c_l13 = w2c_i0; + w2c_i0 = w2c_l2; + w2c_i1 = 4u; + w2c_i0 += w2c_i1; + w2c_l2 = w2c_i0; + w2c_i1 = 256u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L12;} + } else { + w2c_L13: + w2c_i0 = w2c_l13; + w2c_i1 = 12u; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_l24 = w2c_i0; + w2c_i0 = w2c_l24; + w2c_i1 = 1732688499u; + w2c_i0 *= w2c_i1; + w2c_l24 = w2c_i0; + w2c_i0 = w2c_l24; + w2c_i1 = w2c_l24; + w2c_i2 = 15u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i2 = w2c_l13; + w2c_i3 = 8u; + w2c_i2 = (u32)((s32)w2c_i2 >> (w2c_i3 & 31)); + w2c_i3 = 255u; + w2c_i2 &= w2c_i3; + w2c_i3 = w2c_l5; + w2c_i3 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i3) + 1u); + w2c_i2 = (u32)((s32)w2c_i2 >= (s32)w2c_i3); + w2c_i1 *= w2c_i2; + w2c_i0 ^= w2c_i1; + w2c_l24 = w2c_i0; + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l24; + w2c_i2 = 2203547335u; + w2c_i1 *= w2c_i2; + w2c_i2 = 16u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 608, w2c_i1); + w2c_i0 = w2c_l13; + w2c_i1 = w2c_l12; + w2c_i0 += w2c_i1; + w2c_l13 = w2c_i0; + w2c_i0 = w2c_l2; + w2c_i1 = 4u; + w2c_i0 += w2c_i1; + w2c_l2 = w2c_i0; + w2c_i1 = 256u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L13;} + } + } + w2c_i0 = w2c_l4; + w2c_i1 = w2c_l13; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 4, w2c_i1); + w2c_i0 = w2c_l9; + w2c_i1 = 32u; + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_i0 = 440u; + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_f1 = 2; + w2c_i2 = w2c_l1; + w2c_i3 = w2c_l3; + w2c_i4 = 1u; + w2c_i3 -= w2c_i4; + w2c_i4 = 3u; + w2c_i3 &= w2c_i4; + w2c_l25 = w2c_i3; + w2c_i4 = 6u; + w2c_i3 *= w2c_i4; + w2c_i2 += w2c_i3; + w2c_i2 = i32_load16_u(instance->Z_envZ_memory, (u64)(w2c_i2) + 2u); + w2c_i3 = 17664u; + w2c_i2 -= w2c_i3; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_i3 = 3072u; + w2c_f3 = (f32)(s32)(w2c_i3); + w2c_f2 /= w2c_f3; + w2c_f1 = (*Z_envZ_pow)(instance->Z_env_instance, w2c_f1, w2c_f2); + w2c_f0 *= w2c_f1; + w2c_f1 = 1.48607707; + w2c_f0 *= w2c_f1; + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l26 = w2c_i0; + w2c_i0 = w2c_l1; + w2c_i1 = 32u; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l25; + w2c_i2 = 8u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i0) + 4u); + w2c_l27 = w2c_i0; + w2c_i0 = w2c_l25; + w2c_i1 = w2c_l3; + w2c_i0 = (u32)((s32)w2c_i0 > (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l27; + w2c_i1 = w2c_l26; + w2c_i2 = 6u; + w2c_i1 <<= (w2c_i2 & 31); + w2c_i0 -= w2c_i1; + w2c_l27 = w2c_i0; + } + w2c_i0 = 0u; + w2c_l2 = w2c_i0; + w2c_L16: + w2c_i0 = w2c_l27; + w2c_i1 = 16u; + w2c_i0 <<= (w2c_i1 & 31); + w2c_l28 = w2c_i0; + w2c_i0 = w2c_l28; + w2c_i1 = w2c_l28; + w2c_i2 = 31u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i0 ^= w2c_i1; + w2c_l28 = w2c_i0; + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l1; + w2c_i2 = w2c_l2; + w2c_i1 += w2c_i2; + w2c_i1 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i1) + 608u); + w2c_i2 = w2c_l28; + w2c_i3 = 15u; + w2c_i2 = (u32)((s32)w2c_i2 >> (w2c_i3 & 31)); + w2c_i3 = 32768u; + w2c_i2 -= w2c_i3; + w2c_i1 *= w2c_i2; + w2c_i2 = 15u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 608, w2c_i1); + w2c_i0 = w2c_l27; + w2c_i1 = w2c_l26; + w2c_i0 += w2c_i1; + w2c_l27 = w2c_i0; + w2c_i0 = w2c_l2; + w2c_i1 = 4u; + w2c_i0 += w2c_i1; + w2c_l2 = w2c_i0; + w2c_i1 = 256u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L16;} + } + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l3; + w2c_i2 = 1u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i0 += w2c_i1; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 24u); + w2c_i1 = w2c_l3; + w2c_i2 = 1u; + w2c_i1 &= w2c_i2; + w2c_i2 = 4u; + w2c_i1 *= w2c_i2; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_i1 = 15u; + w2c_i0 &= w2c_i1; + w2c_l29 = w2c_i0; + w2c_i0 = w2c_l7; + w2c_i1 = w2c_l29; + w2c_i0 *= w2c_i1; + w2c_i1 = 15u; + w2c_i0 = I32_DIV_S(w2c_i0, w2c_i1); + w2c_l7 = w2c_i0; + w2c_i0 = 15707u; + w2c_i1 = 27257u; + w2c_i2 = w2c_l9; + w2c_i3 = 16u; + w2c_i2 &= w2c_i3; + w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; + w2c_i1 = w2c_l3; + w2c_i2 = 4u; + w2c_i1 *= w2c_i2; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_i1 = 15u; + w2c_i0 &= w2c_i1; + w2c_l30 = w2c_i0; + w2c_i0 = 16u; + w2c_i1 = w2c_l30; + w2c_i0 -= w2c_i1; + w2c_l31 = w2c_i0; + w2c_i0 = 0u; + w2c_l2 = w2c_i0; + w2c_i0 = w2c_l9; + w2c_i1 = 2u; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_i1 = 3u; + w2c_i0 &= w2c_i1; + w2c_l32 = w2c_i0; + w2c_i1 = 2u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l32; + if (w2c_i0) { + w2c_i0 = 4096u; + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_i1 = 4096u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_i2 = 4096u; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_f3 = w2c_l50; + w2c_f4 = -0.000569795899; + w2c_f3 *= w2c_f4; + w2c_f3 = (*Z_envZ_exp)(instance->Z_env_instance, w2c_f3); + w2c_f2 *= w2c_f3; + w2c_f1 = FMIN(w2c_f1, w2c_f2); + w2c_f0 -= w2c_f1; + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l33 = w2c_i0; + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l3; + w2c_i2 = 8u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i0) + 64u); + w2c_l34 = w2c_i0; + w2c_L19: + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i0) + 608u); + w2c_i1 = w2c_l7; + w2c_i0 *= w2c_i1; + w2c_i1 = 18u; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_l35 = w2c_i0; + w2c_i0 = w2c_l34; + w2c_i1 = w2c_l35; + w2c_i2 = w2c_l34; + w2c_i1 -= w2c_i2; + w2c_i2 = w2c_l33; + w2c_i1 *= w2c_i2; + w2c_i2 = 12u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i0 += w2c_i1; + w2c_l34 = w2c_i0; + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i2 = 2u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l1; + w2c_i2 = w2c_l2; + w2c_i3 = 2u; + w2c_i2 *= w2c_i3; + w2c_i1 += w2c_i2; + w2c_i1 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i1) + 96u); + w2c_i2 = w2c_l34; + w2c_i3 = w2c_l30; + w2c_i2 *= w2c_i3; + w2c_i3 = 4u; + w2c_i2 = (u32)((s32)w2c_i2 >> (w2c_i3 & 31)); + w2c_i1 += w2c_i2; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 96, w2c_i1); + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i2 = 2u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l1; + w2c_i2 = w2c_l2; + w2c_i3 = 2u; + w2c_i2 *= w2c_i3; + w2c_i1 += w2c_i2; + w2c_i1 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i1) + 100u); + w2c_i2 = w2c_l34; + w2c_i3 = w2c_l31; + w2c_i2 *= w2c_i3; + w2c_i3 = 4u; + w2c_i2 = (u32)((s32)w2c_i2 >> (w2c_i3 & 31)); + w2c_i1 += w2c_i2; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 100, w2c_i1); + w2c_i0 = w2c_l2; + w2c_i1 = 4u; + w2c_i0 += w2c_i1; + w2c_l2 = w2c_i0; + w2c_i1 = 256u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L19;} + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l3; + w2c_i2 = 8u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l34; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 64, w2c_i1); + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l3; + w2c_i2 = 8u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = 0u; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 68, w2c_i1); + } else { + w2c_L20: + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i0) + 608u); + w2c_i1 = w2c_l7; + w2c_i0 *= w2c_i1; + w2c_i1 = 18u; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_l36 = w2c_i0; + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i2 = 2u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l1; + w2c_i2 = w2c_l2; + w2c_i3 = 2u; + w2c_i2 *= w2c_i3; + w2c_i1 += w2c_i2; + w2c_i1 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i1) + 96u); + w2c_i2 = w2c_l36; + w2c_i3 = w2c_l30; + w2c_i2 *= w2c_i3; + w2c_i3 = 4u; + w2c_i2 = (u32)((s32)w2c_i2 >> (w2c_i3 & 31)); + w2c_i1 += w2c_i2; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 96, w2c_i1); + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i2 = 2u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l1; + w2c_i2 = w2c_l2; + w2c_i3 = 2u; + w2c_i2 *= w2c_i3; + w2c_i1 += w2c_i2; + w2c_i1 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i1) + 100u); + w2c_i2 = w2c_l36; + w2c_i3 = w2c_l31; + w2c_i2 *= w2c_i3; + w2c_i3 = 4u; + w2c_i2 = (u32)((s32)w2c_i2 >> (w2c_i3 & 31)); + w2c_i1 += w2c_i2; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 100, w2c_i1); + w2c_i0 = w2c_l2; + w2c_i1 = 4u; + w2c_i0 += w2c_i1; + w2c_l2 = w2c_i0; + w2c_i1 = 256u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L20;} + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l3; + w2c_i2 = 8u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l36; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 64, w2c_i1); + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l3; + w2c_i2 = 8u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = 0u; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 68, w2c_i1); + } + } else { + w2c_i0 = w2c_l32; + w2c_i1 = 2u; + w2c_i0 -= w2c_i1; + w2c_l32 = w2c_i0; + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l32; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 26u); + w2c_l37 = w2c_i0; + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l32; + w2c_i2 = 2u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load16_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 28u); + w2c_l38 = w2c_i0; + w2c_i0 = 8192u; + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_f1 = 0.25; + w2c_i2 = 440u; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_f3 = 2; + w2c_i4 = w2c_l38; + w2c_i5 = 17664u; + w2c_i4 -= w2c_i5; + w2c_f4 = (f32)(s32)(w2c_i4); + w2c_i5 = 3072u; + w2c_f5 = (f32)(s32)(w2c_i5); + w2c_f4 /= w2c_f5; + w2c_f3 = (*Z_envZ_pow)(instance->Z_env_instance, w2c_f3, w2c_f4); + w2c_f2 *= w2c_f3; + w2c_i3 = 44100u; + w2c_f3 = (f32)(s32)(w2c_i3); + w2c_f2 /= w2c_f3; + w2c_f1 = FMIN(w2c_f1, w2c_f2); + w2c_f2 = 3.1415; + w2c_f1 *= w2c_f2; + w2c_f1 = (*Z_envZ_sin)(instance->Z_env_instance, w2c_f1); + w2c_f0 *= w2c_f1; + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + w2c_l39 = w2c_i0; + w2c_i0 = 8192u; + w2c_i1 = w2c_l37; + w2c_i2 = 4u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i2 = 466u; + w2c_i1 *= w2c_i2; + w2c_i0 -= w2c_i1; + w2c_l40 = w2c_i0; + w2c_i0 = 33554432u; + w2c_i1 = w2c_l39; + w2c_i0 = I32_DIV_S(w2c_i0, w2c_i1); + w2c_i1 = w2c_l39; + w2c_i2 = 2u; + w2c_i1 = I32_DIV_S(w2c_i1, w2c_i2); + w2c_i0 -= w2c_i1; + w2c_i1 = 3u; + w2c_i0 *= w2c_i1; + w2c_i1 = 4u; + w2c_i0 = I32_DIV_S(w2c_i0, w2c_i1); + w2c_l41 = w2c_i0; + w2c_i0 = w2c_l40; + w2c_i1 = w2c_l41; + w2c_i0 = (u32)((s32)w2c_i0 > (s32)w2c_i1); + if (w2c_i0) { + w2c_i0 = w2c_l41; + w2c_l40 = w2c_i0; + } + w2c_i0 = w2c_l37; + w2c_i1 = 1u; + w2c_i0 &= w2c_i1; + w2c_l42 = w2c_i0; + w2c_i0 = w2c_l37; + w2c_i1 = 1u; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_i1 = 1u; + w2c_i0 &= w2c_i1; + w2c_l43 = w2c_i0; + w2c_i0 = w2c_l37; + w2c_i1 = 2u; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_i1 = 1u; + w2c_i0 &= w2c_i1; + w2c_l44 = w2c_i0; + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l3; + w2c_i2 = 8u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i0) + 64u); + w2c_l45 = w2c_i0; + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l3; + w2c_i2 = 8u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i0) + 68u); + w2c_l46 = w2c_i0; + w2c_L22: + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i0) + 608u); + w2c_i1 = w2c_l7; + w2c_i0 *= w2c_i1; + w2c_i1 = 18u; + w2c_i0 = (u32)((s32)w2c_i0 >> (w2c_i1 & 31)); + w2c_l47 = w2c_i0; + w2c_i0 = w2c_l47; + w2c_i1 = w2c_l45; + w2c_i0 -= w2c_i1; + w2c_i1 = w2c_l46; + w2c_i2 = w2c_l40; + w2c_i1 *= w2c_i2; + w2c_i2 = 12u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i0 -= w2c_i1; + w2c_l48 = w2c_i0; + w2c_i0 = w2c_l46; + w2c_i1 = w2c_l39; + w2c_i2 = w2c_l48; + w2c_i1 *= w2c_i2; + w2c_i2 = 12u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i0 += w2c_i1; + w2c_l46 = w2c_i0; + w2c_i0 = w2c_l45; + w2c_i1 = w2c_l39; + w2c_i2 = w2c_l46; + w2c_i1 *= w2c_i2; + w2c_i2 = 12u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_i0 += w2c_i1; + w2c_l45 = w2c_i0; + w2c_i0 = w2c_l45; + w2c_i1 = w2c_l42; + w2c_i0 *= w2c_i1; + w2c_i1 = w2c_l48; + w2c_i2 = w2c_l43; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l46; + w2c_i2 = w2c_l44; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_l49 = w2c_i0; + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i2 = 2u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l1; + w2c_i2 = w2c_l2; + w2c_i3 = 2u; + w2c_i2 *= w2c_i3; + w2c_i1 += w2c_i2; + w2c_i1 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i1) + 96u); + w2c_i2 = w2c_l49; + w2c_i3 = w2c_l30; + w2c_i2 *= w2c_i3; + w2c_i3 = 4u; + w2c_i2 = (u32)((s32)w2c_i2 >> (w2c_i3 & 31)); + w2c_i1 += w2c_i2; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 96, w2c_i1); + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l2; + w2c_i2 = 2u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l1; + w2c_i2 = w2c_l2; + w2c_i3 = 2u; + w2c_i2 *= w2c_i3; + w2c_i1 += w2c_i2; + w2c_i1 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i1) + 100u); + w2c_i2 = w2c_l49; + w2c_i3 = w2c_l31; + w2c_i2 *= w2c_i3; + w2c_i3 = 4u; + w2c_i2 = (u32)((s32)w2c_i2 >> (w2c_i3 & 31)); + w2c_i1 += w2c_i2; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 100, w2c_i1); + w2c_i0 = w2c_l2; + w2c_i1 = 4u; + w2c_i0 += w2c_i1; + w2c_l2 = w2c_i0; + w2c_i1 = 256u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L22;} + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l3; + w2c_i2 = 8u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l45; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 64, w2c_i1); + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l3; + w2c_i2 = 8u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = w2c_l46; + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 68, w2c_i1); + } + w2c_i0 = w2c_l3; + w2c_i1 = 1u; + w2c_i0 += w2c_i1; + w2c_l3 = w2c_i0; + w2c_i1 = 4u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L2;} + } + w2c_i0 = w2c_l1; + w2c_i1 = w2c_p0; + w2c_i2 = 127u; + w2c_i1 &= w2c_i2; + w2c_i2 = 4u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i0) + 96u); + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_i1 = 32768u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_f0 /= w2c_f1; + FUNC_EPILOGUE; + return w2c_f0; +} + +static u32 w2c_f33(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1, u32 w2c_p2) { + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3, w2c_i4; + w2c_i0 = w2c_p1; + w2c_i1 = w2c_p2; + w2c_i2 = w2c_p0; + w2c_i3 = w2c_p0; + w2c_i4 = w2c_p2; + w2c_i3 = (u32)((s32)w2c_i3 > (s32)w2c_i4); + w2c_i1 = w2c_i3 ? w2c_i1 : w2c_i2; + w2c_i2 = w2c_p0; + w2c_i3 = w2c_p1; + w2c_i2 = (u32)((s32)w2c_i2 < (s32)w2c_i3); + w2c_i0 = w2c_i2 ? w2c_i0 : w2c_i1; + FUNC_EPILOGUE; + return w2c_i0; +} + +static void w2c_f34(Z_platform_instance_t* instance, u32 w2c_p0) { + u32 w2c_l1 = 0, w2c_l2 = 0, w2c_l3 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3, w2c_i4; + f32 w2c_f0, w2c_f1, w2c_f2, w2c_f3; + w2c_i0 = instance->w2c_g5; + w2c_i1 = 2u; + w2c_i0 = (u32)((s32)w2c_i0 >= (s32)w2c_i1); + w2c_i1 = w2c_p0; + w2c_i2 = 4u; + w2c_i1 = (u32)((s32)w2c_i1 < (s32)w2c_i2); + w2c_i2 = w2c_p0; + w2c_i3 = 6u; + w2c_i2 = (u32)((s32)w2c_i2 > (s32)w2c_i3); + w2c_i1 |= w2c_i2; + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_i0 = w2c_p0; + (*Z_envZ_logChar)(instance->Z_env_instance, w2c_i0); + goto w2c_Bfunc; + } + w2c_i0 = instance->w2c_g6; + w2c_i1 = w2c_p0; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 77088, w2c_i1); + w2c_i0 = instance->w2c_g6; + w2c_i1 = 1u; + w2c_i0 += w2c_i1; + instance->w2c_g6 = w2c_i0; + w2c_i0 = 77088u; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0)); + w2c_p0 = w2c_i0; + w2c_i0 = w2c_p0; + w2c_i1 = 32u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + w2c_i1 = instance->w2c_g6; + w2c_i2 = w2c_p0; + w2c_i2 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i2) + 77056u); + w2c_i1 = (u32)((s32)w2c_i1 < (s32)w2c_i2); + w2c_i0 &= w2c_i1; + if (w2c_i0) { + goto w2c_Bfunc; + } + w2c_i0 = 0u; + instance->w2c_g6 = w2c_i0; + w2c_i0 = w2c_p0; + w2c_i1 = 1u; + w2c_i0 = w2c_i0 == w2c_i1; + if (w2c_i0) { + w2c_i0 = 77088u; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 1u); + w2c_f35(instance, w2c_i0); + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 4u; + w2c_i0 = (u32)((s32)w2c_i0 >= (s32)w2c_i1); + w2c_i1 = w2c_p0; + w2c_i2 = 6u; + w2c_i1 = (u32)((s32)w2c_i1 <= (s32)w2c_i2); + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_i0 = w2c_p0; + w2c_i1 = 4u; + w2c_i0 -= w2c_i1; + instance->w2c_g5 = w2c_i0; + w2c_i0 = instance->w2c_g5; + w2c_i0 = !(w2c_i0); + if (w2c_i0) { + w2c_i0 = 0u; + instance->w2c_g1 = w2c_i0; + w2c_i0 = 0u; + instance->w2c_g2 = w2c_i0; + } + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 7u; + w2c_i0 = w2c_i0 == w2c_i1; + if (w2c_i0) { + w2c_i0 = 80u; + w2c_i1 = 80u; + w2c_i1 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i1)); + w2c_i2 = 2u; + w2c_i1 ^= w2c_i2; + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0), w2c_i1); + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 8u; + w2c_i0 = w2c_i0 == w2c_i1; + if (w2c_i0) { + w2c_i0 = instance->w2c_g1; + w2c_i1 = 8u; + w2c_i0 -= w2c_i1; + instance->w2c_g1 = w2c_i0; + w2c_i0 = instance->w2c_g5; + w2c_i0 = !(w2c_i0); + w2c_i1 = instance->w2c_g1; + w2c_i2 = 0u; + w2c_i1 = (u32)((s32)w2c_i1 < (s32)w2c_i2); + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_i0 = 312u; + instance->w2c_g1 = w2c_i0; + w2c_i0 = 11u; + w2c_f34(instance, w2c_i0); + } + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 9u; + w2c_i0 = w2c_i0 == w2c_i1; + if (w2c_i0) { + w2c_i0 = instance->w2c_g5; + w2c_i0 = !(w2c_i0); + w2c_i1 = instance->w2c_g1; + w2c_i2 = 320u; + w2c_i1 = (u32)((s32)w2c_i1 >= (s32)w2c_i2); + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_i0 = 3338u; + w2c_printChar(instance, w2c_i0); + } + w2c_i0 = instance->w2c_g1; + w2c_i1 = 8u; + w2c_i0 += w2c_i1; + instance->w2c_g1 = w2c_i0; + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 10u; + w2c_i0 = w2c_i0 == w2c_i1; + if (w2c_i0) { + w2c_i0 = instance->w2c_g2; + w2c_i1 = 8u; + w2c_i0 += w2c_i1; + instance->w2c_g2 = w2c_i0; + w2c_i0 = instance->w2c_g5; + w2c_i0 = !(w2c_i0); + w2c_i1 = instance->w2c_g2; + w2c_i2 = 240u; + w2c_i1 = (u32)((s32)w2c_i1 >= (s32)w2c_i2); + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_i0 = 232u; + instance->w2c_g2 = w2c_i0; + w2c_L12: + w2c_i0 = w2c_l1; + w2c_i1 = w2c_l1; + w2c_i1 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i1) + 2680u); + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 120, w2c_i1); + w2c_i0 = w2c_l1; + w2c_i1 = 4u; + w2c_i0 += w2c_i1; + w2c_l1 = w2c_i0; + w2c_i1 = 74240u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L12;} + w2c_i0 = 0u; + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_i1 = 232u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_i2 = 320u; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_i3 = 8u; + w2c_f3 = (f32)(s32)(w2c_i3); + w2c_i4 = instance->w2c_g4; + w2c_rectangle(instance, w2c_f0, w2c_f1, w2c_f2, w2c_f3, w2c_i4); + } + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 11u; + w2c_i0 = w2c_i0 == w2c_i1; + if (w2c_i0) { + w2c_i0 = instance->w2c_g2; + w2c_i1 = 8u; + w2c_i0 -= w2c_i1; + instance->w2c_g2 = w2c_i0; + w2c_i0 = instance->w2c_g5; + w2c_i0 = !(w2c_i0); + w2c_i1 = instance->w2c_g2; + w2c_i2 = 0u; + w2c_i1 = (u32)((s32)w2c_i1 < (s32)w2c_i2); + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_i0 = 0u; + instance->w2c_g2 = w2c_i0; + w2c_i0 = 74240u; + w2c_l2 = w2c_i0; + w2c_L15: + w2c_i0 = w2c_l2; + w2c_i1 = w2c_l2; + w2c_i1 = i32_load(instance->Z_envZ_memory, (u64)(w2c_i1) + 116u); + i32_store(instance->Z_envZ_memory, (u64)(w2c_i0) + 2676, w2c_i1); + w2c_i0 = w2c_l2; + w2c_i1 = 4u; + w2c_i0 -= w2c_i1; + w2c_l2 = w2c_i0; + if (w2c_i0) {goto w2c_L15;} + w2c_i0 = 0u; + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_i1 = 0u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_i2 = 320u; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_i3 = 8u; + w2c_f3 = (f32)(s32)(w2c_i3); + w2c_i4 = instance->w2c_g4; + w2c_rectangle(instance, w2c_f0, w2c_f1, w2c_f2, w2c_f3, w2c_i4); + } + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 12u; + w2c_i0 = w2c_i0 == w2c_i1; + if (w2c_i0) { + w2c_i0 = instance->w2c_g4; + w2c_cls(instance, w2c_i0); + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 13u; + w2c_i0 = w2c_i0 == w2c_i1; + if (w2c_i0) { + w2c_i0 = 0u; + instance->w2c_g1 = w2c_i0; + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 14u; + w2c_i0 = w2c_i0 == w2c_i1; + if (w2c_i0) { + w2c_i0 = 77088u; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 1u); + instance->w2c_g4 = w2c_i0; + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 15u; + w2c_i0 = w2c_i0 == w2c_i1; + if (w2c_i0) { + w2c_i0 = 77088u; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 1u); + instance->w2c_g3 = w2c_i0; + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 24u; + w2c_i0 = w2c_i0 == w2c_i1; + if (w2c_i0) { + w2c_i0 = instance->w2c_g3; + w2c_l3 = w2c_i0; + w2c_i0 = instance->w2c_g4; + instance->w2c_g3 = w2c_i0; + w2c_i0 = w2c_l3; + instance->w2c_g4 = w2c_i0; + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 31u; + w2c_i0 = w2c_i0 == w2c_i1; + if (w2c_i0) { + w2c_i0 = 77088u; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 1u); + w2c_i1 = 8u; + w2c_i2 = instance->w2c_g5; + w2c_i3 = 6u; + w2c_i2 *= w2c_i3; + w2c_i1 -= w2c_i2; + w2c_i0 *= w2c_i1; + instance->w2c_g1 = w2c_i0; + w2c_i0 = 77088u; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 2u); + w2c_i1 = 8u; + w2c_i2 = instance->w2c_g5; + w2c_i3 = 7u; + w2c_i2 *= w2c_i3; + w2c_i1 -= w2c_i2; + w2c_i0 *= w2c_i1; + instance->w2c_g2 = w2c_i0; + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_i1 = 31u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) { + goto w2c_Bfunc; + } + w2c_i0 = w2c_p0; + w2c_f35(instance, w2c_i0); + w2c_Bfunc:; + FUNC_EPILOGUE; +} + +static void w2c_f35(Z_platform_instance_t* instance, u32 w2c_p0) { + u32 w2c_l1 = 0, w2c_l2 = 0, w2c_l3 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3, w2c_i4, w2c_i5; + w2c_i0 = instance->w2c_g5; + w2c_i0 = !(w2c_i0); + w2c_i1 = instance->w2c_g1; + w2c_i2 = 320u; + w2c_i1 = (u32)((s32)w2c_i1 >= (s32)w2c_i2); + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_i0 = 3338u; + w2c_printChar(instance, w2c_i0); + } + w2c_L1: + w2c_i0 = w2c_p0; + w2c_i1 = 8u; + w2c_i0 *= w2c_i1; + w2c_i1 = w2c_l1; + w2c_i0 += w2c_i1; + w2c_i0 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i0) + 78848u); + w2c_l2 = w2c_i0; + w2c_i0 = 0u; + w2c_l3 = w2c_i0; + w2c_i0 = instance->w2c_g5; + if (w2c_i0) { + w2c_L3: + w2c_i0 = w2c_l2; + w2c_i1 = 1u; + w2c_i0 <<= (w2c_i1 & 31); + w2c_l2 = w2c_i0; + w2c_i1 = 256u; + w2c_i0 &= w2c_i1; + if (w2c_i0) { + w2c_i0 = instance->w2c_g1; + w2c_i1 = w2c_l3; + w2c_i0 += w2c_i1; + w2c_i1 = instance->w2c_g2; + w2c_i2 = w2c_l1; + w2c_i1 += w2c_i2; + w2c_i2 = instance->w2c_g3; + w2c_setPixel(instance, w2c_i0, w2c_i1, w2c_i2); + } + w2c_i0 = w2c_l3; + w2c_i1 = 1u; + w2c_i0 += w2c_i1; + w2c_l3 = w2c_i0; + w2c_i1 = 8u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L3;} + } else { + w2c_L5: + w2c_i0 = instance->w2c_g1; + w2c_i1 = w2c_l3; + w2c_i0 += w2c_i1; + w2c_i1 = instance->w2c_g2; + w2c_i2 = w2c_l1; + w2c_i1 += w2c_i2; + w2c_i2 = instance->w2c_g3; + w2c_i3 = instance->w2c_g4; + w2c_i4 = w2c_l2; + w2c_i5 = 1u; + w2c_i4 <<= (w2c_i5 & 31); + w2c_l2 = w2c_i4; + w2c_i5 = 256u; + w2c_i4 &= w2c_i5; + w2c_i2 = w2c_i4 ? w2c_i2 : w2c_i3; + w2c_setPixel(instance, w2c_i0, w2c_i1, w2c_i2); + w2c_i0 = w2c_l3; + w2c_i1 = 1u; + w2c_i0 += w2c_i1; + w2c_l3 = w2c_i0; + w2c_i1 = 8u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L5;} + } + w2c_i0 = w2c_l1; + w2c_i1 = 1u; + w2c_i0 += w2c_i1; + w2c_l1 = w2c_i0; + w2c_i1 = 8u; + w2c_i0 = (u32)((s32)w2c_i0 < (s32)w2c_i1); + if (w2c_i0) {goto w2c_L1;} + w2c_i0 = instance->w2c_g1; + w2c_i1 = 8u; + w2c_i0 += w2c_i1; + instance->w2c_g1 = w2c_i0; + FUNC_EPILOGUE; +} + +static void w2c_f36(Z_platform_instance_t* instance) { + u32 w2c_l0 = 0, w2c_l1 = 0, w2c_l2 = 0, w2c_l3 = 0; + f32 w2c_l4 = 0, w2c_l5 = 0, w2c_l6 = 0, w2c_l7 = 0, w2c_l8 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3, w2c_i4, w2c_i5; + f32 w2c_f0, w2c_f1, w2c_f2, w2c_f3, w2c_f4, w2c_f5, w2c_f6; + w2c_i0 = 575u; + w2c_l0 = w2c_i0; + w2c_L0: + w2c_i0 = w2c_l0; + w2c_i1 = 3u; + w2c_i0 = I32_REM_S(w2c_i0, w2c_i1); + w2c_i1 = w2c_l0; + w2c_i2 = 3u; + w2c_i1 = I32_DIV_S(w2c_i1, w2c_i2); + w2c_i2 = 4u; + w2c_i1 *= w2c_i2; + w2c_i0 += w2c_i1; + w2c_i1 = 0u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_f2 = w2c_l4; + w2c_f3 = 0.800000012; + w2c_f2 -= w2c_f3; + w2c_f3 = w2c_l4; + w2c_f4 = 0.800000012; + w2c_f3 += w2c_f4; + w2c_f4 = 0.400000006; + w2c_i5 = w2c_l0; + w2c_f5 = (f32)(s32)(w2c_i5); + w2c_f6 = 2.08249998; + w2c_f5 *= w2c_f6; + w2c_f5 = (*Z_envZ_cos)(instance->Z_env_instance, w2c_f5); + w2c_f4 -= w2c_f5; + w2c_l6 = w2c_f4; + w2c_f3 = FMIN(w2c_f3, w2c_f4); + w2c_f2 = FMAX(w2c_f2, w2c_f3); + w2c_i3 = w2c_l0; + w2c_i4 = 48u; + w2c_i3 = I32_REM_S(w2c_i3, w2c_i4); + w2c_f3 = (f32)(s32)(w2c_i3); + w2c_i4 = 48u; + w2c_f4 = (f32)(s32)(w2c_i4); + w2c_f3 /= w2c_f4; + w2c_l5 = w2c_f3; + w2c_f4 = 0.0500000007; + w2c_f3 += w2c_f4; + w2c_f2 *= w2c_f3; + w2c_l7 = w2c_f2; + w2c_f3 = w2c_l5; + w2c_f4 = w2c_l5; + w2c_f3 *= w2c_f4; + w2c_f4 = 0.800000012; + w2c_f3 *= w2c_f4; + w2c_l8 = w2c_f3; + w2c_f2 += w2c_f3; + w2c_f3 = w2c_l7; + w2c_f4 = w2c_l8; + w2c_f3 *= w2c_f4; + w2c_f2 -= w2c_f3; + w2c_i3 = 1u; + w2c_f3 = (f32)(s32)(w2c_i3); + w2c_f2 = FMIN(w2c_f2, w2c_f3); + w2c_f1 = FMAX(w2c_f1, w2c_f2); + w2c_f2 = w2c_l5; + w2c_i3 = w2c_l0; + w2c_i4 = 528u; + w2c_i3 = (u32)((s32)w2c_i3 < (s32)w2c_i4); + w2c_f1 = w2c_i3 ? w2c_f1 : w2c_f2; + w2c_i2 = 255u; + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_f1 *= w2c_f2; + w2c_i1 = I32_TRUNC_S_F32(w2c_f1); + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 77824, w2c_i1); + w2c_f0 = w2c_l4; + w2c_f1 = w2c_l6; + w2c_f0 += w2c_f1; + w2c_f1 = 0.5; + w2c_f0 *= w2c_f1; + w2c_l4 = w2c_f0; + w2c_i0 = w2c_l0; + w2c_i1 = 1u; + w2c_i0 -= w2c_i1; + w2c_l0 = w2c_i0; + if (w2c_i0) {goto w2c_L0;} + w2c_i0 = 255u; + w2c_l0 = w2c_i0; + w2c_L1: + w2c_i0 = w2c_l0; + w2c_i1 = w2c_l0; + w2c_i2 = 2u; + w2c_i1 = (u32)((s32)w2c_i1 >> (w2c_i2 & 31)); + w2c_l2 = w2c_i1; + w2c_i2 = 32u; + w2c_i1 = I32_REM_S(w2c_i1, w2c_i2); + w2c_i2 = 2u; + w2c_i1 = I32_DIV_S(w2c_i1, w2c_i2); + w2c_i2 = w2c_l2; + w2c_i3 = 2u; + w2c_i2 *= w2c_i3; + w2c_i3 = w2c_l2; + w2c_i4 = 32u; + w2c_i3 = (u32)((s32)w2c_i3 >= (s32)w2c_i4); + w2c_l3 = w2c_i3; + w2c_i1 = w2c_i3 ? w2c_i1 : w2c_i2; + w2c_i2 = 4u; + w2c_i1 *= w2c_i2; + w2c_i2 = w2c_l0; + w2c_i3 = 3u; + w2c_i2 &= w2c_i3; + w2c_l1 = w2c_i2; + w2c_i1 += w2c_i2; + w2c_i1 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i1) + 78592u); + w2c_i2 = w2c_l2; + w2c_i3 = 1u; + w2c_i2 += w2c_i3; + w2c_i3 = 32u; + w2c_i2 = I32_REM_S(w2c_i2, w2c_i3); + w2c_i3 = 2u; + w2c_i2 = I32_DIV_S(w2c_i2, w2c_i3); + w2c_i3 = w2c_l2; + w2c_i4 = 2u; + w2c_i3 *= w2c_i4; + w2c_i4 = 1u; + w2c_i3 += w2c_i4; + w2c_i4 = w2c_l3; + w2c_i2 = w2c_i4 ? w2c_i2 : w2c_i3; + w2c_i3 = 4u; + w2c_i2 *= w2c_i3; + w2c_i3 = w2c_l1; + w2c_i2 += w2c_i3; + w2c_i2 = i32_load8_u(instance->Z_envZ_memory, (u64)(w2c_i2) + 78592u); + w2c_i1 += w2c_i2; + w2c_i2 = 3u; + w2c_i3 = w2c_l3; + w2c_i2 += w2c_i3; + w2c_i1 *= w2c_i2; + w2c_i2 = 8u; + w2c_i1 = I32_DIV_S(w2c_i1, w2c_i2); + i32_store8(instance->Z_envZ_memory, (u64)(w2c_i0) + 78592, w2c_i1); + w2c_i0 = w2c_l0; + w2c_i1 = 1u; + w2c_i0 -= w2c_i1; + w2c_l0 = w2c_i0; + w2c_i1 = 0u; + w2c_i0 = (u32)((s32)w2c_i0 >= (s32)w2c_i1); + if (w2c_i0) {goto w2c_L1;} + w2c_i0 = 0u; + w2c_i1 = 0u; + w2c_i2 = 64u; + memory_fill(instance->Z_envZ_memory, w2c_i0, w2c_i1, w2c_i2); + w2c_i0 = 112u; + w2c_i1 = 0u; + w2c_i2 = 8u; + memory_fill(instance->Z_envZ_memory, w2c_i0, w2c_i1, w2c_i2); + w2c_i0 = 81920u; + w2c_i1 = 0u; + w2c_i2 = 180224u; + memory_fill(instance->Z_envZ_memory, w2c_i0, w2c_i1, w2c_i2); + w2c_i0 = 0u; + w2c_cls(instance, w2c_i0); + w2c_i0 = w2c_random(instance); + w2c_randomSeed(instance, w2c_i0); + FUNC_EPILOGUE; +} + +static u32 w2c_f37(Z_platform_instance_t* instance, u32 w2c_p0, f32 w2c_p1, u32 w2c_p2) { + f32 w2c_l3 = 0, w2c_l4 = 0; + FUNC_PROLOGUE; + u32 w2c_i0, w2c_i1, w2c_i2, w2c_i3; + f32 w2c_f0, w2c_f1, w2c_f2, w2c_f3; + w2c_i0 = 0u; + w2c_f0 = (f32)(s32)(w2c_i0); + w2c_i1 = 1u; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_i2 = w2c_p0; + w2c_i3 = 16u; + w2c_i2 <<= (w2c_i3 & 31); + w2c_i3 = 16u; + w2c_i2 = (u32)((s32)w2c_i2 >> (w2c_i3 & 31)); + w2c_f2 = (f32)(s32)(w2c_i2); + w2c_f3 = w2c_p1; + w2c_f2 *= w2c_f3; + w2c_l3 = w2c_f2; + w2c_f2 = wasm_fabsf(w2c_f2); + w2c_f1 -= w2c_f2; + w2c_f0 = FMAX(w2c_f0, w2c_f1); + w2c_l4 = w2c_f0; + w2c_f1 = w2c_l4; + w2c_f0 *= w2c_f1; + w2c_f1 = w2c_l3; + w2c_f0 = copysignf(w2c_f0, w2c_f1); + w2c_i1 = w2c_p2; + w2c_f1 = (f32)(s32)(w2c_i1); + w2c_f0 *= w2c_f1; + w2c_i0 = I32_TRUNC_S_F32(w2c_f0); + FUNC_EPILOGUE; + return w2c_i0; +} + +/* export: 'time' */ +f32 Z_platformZ_time(Z_platform_instance_t* instance) { + return w2c_time(instance); +} + +/* export: 'isButtonPressed' */ +u32 Z_platformZ_isButtonPressed(Z_platform_instance_t* instance, u32 w2c_p0) { + return w2c_isButtonPressed(instance, w2c_p0); +} + +/* export: 'isButtonTriggered' */ +u32 Z_platformZ_isButtonTriggered(Z_platform_instance_t* instance, u32 w2c_p0) { + return w2c_isButtonTriggered(instance, w2c_p0); +} + +/* export: 'random' */ +u32 Z_platformZ_random(Z_platform_instance_t* instance) { + return w2c_random(instance); +} + +/* export: 'random64' */ +u64 Z_platformZ_random64(Z_platform_instance_t* instance) { + return w2c_random64(instance); +} + +/* export: 'randomf' */ +f32 Z_platformZ_randomf(Z_platform_instance_t* instance) { + return w2c_randomf(instance); +} + +/* export: 'randomSeed' */ +void Z_platformZ_randomSeed(Z_platform_instance_t* instance, u32 w2c_p0) { + return w2c_randomSeed(instance, w2c_p0); +} + +/* export: 'fmod' */ +f32 Z_platformZ_fmod(Z_platform_instance_t* instance, f32 w2c_p0, f32 w2c_p1) { + return w2c_fmod(instance, w2c_p0, w2c_p1); +} + +/* export: 'cls' */ +void Z_platformZ_cls(Z_platform_instance_t* instance, u32 w2c_p0) { + return w2c_cls(instance, w2c_p0); +} + +/* export: 'setPixel' */ +void Z_platformZ_setPixel(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1, u32 w2c_p2) { + return w2c_setPixel(instance, w2c_p0, w2c_p1, w2c_p2); +} + +/* export: 'getPixel' */ +u32 Z_platformZ_getPixel(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1) { + return w2c_getPixel(instance, w2c_p0, w2c_p1); +} + +/* export: 'hline' */ +void Z_platformZ_hline(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1, u32 w2c_p2, u32 w2c_p3) { + return w2c_hline(instance, w2c_p0, w2c_p1, w2c_p2, w2c_p3); +} + +/* export: 'rectangle' */ +void Z_platformZ_rectangle(Z_platform_instance_t* instance, f32 w2c_p0, f32 w2c_p1, f32 w2c_p2, f32 w2c_p3, u32 w2c_p4) { + return w2c_rectangle(instance, w2c_p0, w2c_p1, w2c_p2, w2c_p3, w2c_p4); +} + +/* export: 'rectangleOutline' */ +void Z_platformZ_rectangleOutline(Z_platform_instance_t* instance, f32 w2c_p0, f32 w2c_p1, f32 w2c_p2, f32 w2c_p3, u32 w2c_p4) { + return w2c_rectangleOutline(instance, w2c_p0, w2c_p1, w2c_p2, w2c_p3, w2c_p4); +} + +/* export: 'circle' */ +void Z_platformZ_circle(Z_platform_instance_t* instance, f32 w2c_p0, f32 w2c_p1, f32 w2c_p2, u32 w2c_p3) { + return w2c_circle(instance, w2c_p0, w2c_p1, w2c_p2, w2c_p3); +} + +/* export: 'circleOutline' */ +void Z_platformZ_circleOutline(Z_platform_instance_t* instance, f32 w2c_p0, f32 w2c_p1, f32 w2c_p2, u32 w2c_p3) { + return w2c_circleOutline(instance, w2c_p0, w2c_p1, w2c_p2, w2c_p3); +} + +/* export: 'line' */ +void Z_platformZ_line(Z_platform_instance_t* instance, f32 w2c_p0, f32 w2c_p1, f32 w2c_p2, f32 w2c_p3, u32 w2c_p4) { + return w2c_line(instance, w2c_p0, w2c_p1, w2c_p2, w2c_p3, w2c_p4); +} + +/* export: 'blitSprite' */ +void Z_platformZ_blitSprite(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1, u32 w2c_p2, u32 w2c_p3, u32 w2c_p4) { + return w2c_blitSprite(instance, w2c_p0, w2c_p1, w2c_p2, w2c_p3, w2c_p4); +} + +/* export: 'grabSprite' */ +void Z_platformZ_grabSprite(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1, u32 w2c_p2, u32 w2c_p3, u32 w2c_p4) { + return w2c_grabSprite(instance, w2c_p0, w2c_p1, w2c_p2, w2c_p3, w2c_p4); +} + +/* export: 'printChar' */ +void Z_platformZ_printChar(Z_platform_instance_t* instance, u32 w2c_p0) { + return w2c_printChar(instance, w2c_p0); +} + +/* export: 'printString' */ +void Z_platformZ_printString(Z_platform_instance_t* instance, u32 w2c_p0) { + return w2c_printString(instance, w2c_p0); +} + +/* export: 'printInt' */ +void Z_platformZ_printInt(Z_platform_instance_t* instance, u32 w2c_p0) { + return w2c_printInt(instance, w2c_p0); +} + +/* export: 'setTextColor' */ +void Z_platformZ_setTextColor(Z_platform_instance_t* instance, u32 w2c_p0) { + return w2c_setTextColor(instance, w2c_p0); +} + +/* export: 'setBackgroundColor' */ +void Z_platformZ_setBackgroundColor(Z_platform_instance_t* instance, u32 w2c_p0) { + return w2c_setBackgroundColor(instance, w2c_p0); +} + +/* export: 'setCursorPosition' */ +void Z_platformZ_setCursorPosition(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1) { + return w2c_setCursorPosition(instance, w2c_p0, w2c_p1); +} + +/* export: 'playNote' */ +void Z_platformZ_playNote(Z_platform_instance_t* instance, u32 w2c_p0, u32 w2c_p1) { + return w2c_playNote(instance, w2c_p0, w2c_p1); +} + +/* export: 'endFrame' */ +void Z_platformZ_endFrame(Z_platform_instance_t* instance) { + return w2c_endFrame(instance); +} + +/* export: 'sndGes' */ +f32 Z_platformZ_sndGes(Z_platform_instance_t* instance, u32 w2c_p0) { + return w2c_sndGes(instance, w2c_p0); +} + +static void init_instance_import(Z_platform_instance_t* instance, struct Z_env_instance_t* Z_env_instance){ + instance->Z_env_instance = Z_env_instance; + instance->Z_envZ_memory = Z_envZ_memory(Z_env_instance); +} + +void Z_platform_init_module(void) { + assert(wasm_rt_is_initialized()); + s_module_initialized = true; + init_func_types(); +} + +void Z_platform_instantiate(Z_platform_instance_t* instance, struct Z_env_instance_t* Z_env_instance) { + assert(wasm_rt_is_initialized()); + assert(s_module_initialized); + init_instance_import(instance, Z_env_instance); + init_globals(instance); + init_memories(instance); + init_data_instances(instance); + w2c_f36(instance); +} + +void Z_platform_free(Z_platform_instance_t* instance) { +} diff --git a/platform.h b/platform.h new file mode 100644 index 0000000..5389142 --- /dev/null +++ b/platform.h @@ -0,0 +1,147 @@ +/* Automatically generated by wasm2c */ +#ifndef PLATFORM_H_GENERATED_ +#define PLATFORM_H_GENERATED_ + +#include + +#include "wasm-rt.h" + +/* TODO(binji): only use stdint.h types in header */ +#ifndef WASM_RT_CORE_TYPES_DEFINED +#define WASM_RT_CORE_TYPES_DEFINED +typedef uint8_t u8; +typedef int8_t s8; +typedef uint16_t u16; +typedef int16_t s16; +typedef uint32_t u32; +typedef int32_t s32; +typedef uint64_t u64; +typedef int64_t s64; +typedef float f32; +typedef double f64; +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +struct Z_env_instance_t; +extern wasm_rt_memory_t* Z_envZ_memory(struct Z_env_instance_t*); + +typedef struct Z_platform_instance_t { + struct Z_env_instance_t* Z_env_instance; + /* import: 'env' 'memory' */ + wasm_rt_memory_t *Z_envZ_memory; + u64 w2c_g0; + u32 w2c_g1; + u32 w2c_g2; + u32 w2c_g3; + u32 w2c_g4; + u32 w2c_g5; + u32 w2c_g6; +} Z_platform_instance_t; + +void Z_platform_init_module(void); +void Z_platform_instantiate(Z_platform_instance_t*, struct Z_env_instance_t*); +void Z_platform_free(Z_platform_instance_t*); + +/* import: 'env' 'cos' */ +f32 Z_envZ_cos(struct Z_env_instance_t*, f32); +/* import: 'env' 'exp' */ +f32 Z_envZ_exp(struct Z_env_instance_t*, f32); +/* import: 'env' 'logChar' */ +void Z_envZ_logChar(struct Z_env_instance_t*, u32); +/* import: 'env' 'pow' */ +f32 Z_envZ_pow(struct Z_env_instance_t*, f32, f32); +/* import: 'env' 'sin' */ +f32 Z_envZ_sin(struct Z_env_instance_t*, f32); + +/* export: 'time' */ +f32 Z_platformZ_time(Z_platform_instance_t*); + +/* export: 'isButtonPressed' */ +u32 Z_platformZ_isButtonPressed(Z_platform_instance_t*, u32); + +/* export: 'isButtonTriggered' */ +u32 Z_platformZ_isButtonTriggered(Z_platform_instance_t*, u32); + +/* export: 'random' */ +u32 Z_platformZ_random(Z_platform_instance_t*); + +/* export: 'random64' */ +u64 Z_platformZ_random64(Z_platform_instance_t*); + +/* export: 'randomf' */ +f32 Z_platformZ_randomf(Z_platform_instance_t*); + +/* export: 'randomSeed' */ +void Z_platformZ_randomSeed(Z_platform_instance_t*, u32); + +/* export: 'fmod' */ +f32 Z_platformZ_fmod(Z_platform_instance_t*, f32, f32); + +/* export: 'cls' */ +void Z_platformZ_cls(Z_platform_instance_t*, u32); + +/* export: 'setPixel' */ +void Z_platformZ_setPixel(Z_platform_instance_t*, u32, u32, u32); + +/* export: 'getPixel' */ +u32 Z_platformZ_getPixel(Z_platform_instance_t*, u32, u32); + +/* export: 'hline' */ +void Z_platformZ_hline(Z_platform_instance_t*, u32, u32, u32, u32); + +/* export: 'rectangle' */ +void Z_platformZ_rectangle(Z_platform_instance_t*, f32, f32, f32, f32, u32); + +/* export: 'rectangleOutline' */ +void Z_platformZ_rectangleOutline(Z_platform_instance_t*, f32, f32, f32, f32, u32); + +/* export: 'circle' */ +void Z_platformZ_circle(Z_platform_instance_t*, f32, f32, f32, u32); + +/* export: 'circleOutline' */ +void Z_platformZ_circleOutline(Z_platform_instance_t*, f32, f32, f32, u32); + +/* export: 'line' */ +void Z_platformZ_line(Z_platform_instance_t*, f32, f32, f32, f32, u32); + +/* export: 'blitSprite' */ +void Z_platformZ_blitSprite(Z_platform_instance_t*, u32, u32, u32, u32, u32); + +/* export: 'grabSprite' */ +void Z_platformZ_grabSprite(Z_platform_instance_t*, u32, u32, u32, u32, u32); + +/* export: 'printChar' */ +void Z_platformZ_printChar(Z_platform_instance_t*, u32); + +/* export: 'printString' */ +void Z_platformZ_printString(Z_platform_instance_t*, u32); + +/* export: 'printInt' */ +void Z_platformZ_printInt(Z_platform_instance_t*, u32); + +/* export: 'setTextColor' */ +void Z_platformZ_setTextColor(Z_platform_instance_t*, u32); + +/* export: 'setBackgroundColor' */ +void Z_platformZ_setBackgroundColor(Z_platform_instance_t*, u32); + +/* export: 'setCursorPosition' */ +void Z_platformZ_setCursorPosition(Z_platform_instance_t*, u32, u32); + +/* export: 'playNote' */ +void Z_platformZ_playNote(Z_platform_instance_t*, u32, u32); + +/* export: 'endFrame' */ +void Z_platformZ_endFrame(Z_platform_instance_t*); + +/* export: 'sndGes' */ +f32 Z_platformZ_sndGes(Z_platform_instance_t*, u32); + +#ifdef __cplusplus +} +#endif + +#endif /* PLATFORM_H_GENERATED_ */ diff --git a/platform.uw8 b/platform.uw8 index 2425d513c13e60795216e9ef3226b268e9486756..16b588b0380e69117f013b69dcc52c8b3dac69d8 100644 GIT binary patch literal 4097 zcmV+c5dQB10nfX!mlX-`5*TUS$+q`RyQ(+^D_a-6b^lyd!0h=}Wc9~rQ#vpI9vtVqI-TJ%q)BRUx^Hft6#E{qhd%6$)AYC0b(2%D0 zj7zd&Vgcgnc(Ku_HPY7GEE~2|czW@3xAN&)zPkQg6JL-^30{txElw=qIiZ^U>YZgK z8RE&EF0fs`T%g)Bje4VlDDeh(2?=uOuK8=aU0*7?Ut|Cq>z#d5B55KspL|922ya@|1iS;&D%lQS zMn&3rIazX0umeuPWsGmu)TBSHX)F>Z2PoGL1qth*Br|7~1hr>*3-Y!^F8~@>lhkkF zjdCRp_T7)k9NUnK-b%+h8qxv>i~xmQ28JSCn>~MZ-RmW(2*Fgqc41#F6`Z)eS%;$+ zleNbn4Tsy^zClR~%N0Sk4vNPj5Uqr~7ALkjwL^<&ia;^1WZX#-6~Kj9tq3gKv2pPw z*O$Lru+w?w{Rd{8dIGy1al<-c%F2GEuoRm$2V$46c=a-RQC&vljNb$>xf4Z-u^D0j zo5Ron9ZJFq)u`^Ox`Vl0)3ICfRuPCK%gmj{pyTrky#Q;9i`(y>hLs73h4Yf}DO;`8 zhitxZ19Y2F?p8Ol-a3{Sp<#j#gj}gKX@sdIyDsUMSFGaApnI9CeSU%UwxMu5mF84S z3rxHdG%%puvd5kWau_}elaTDiq{YKPI}ac0H4&B#Dx{*!0MJJq3wVM3NuqD?gg_eC zX;ifs5x34X5&~VQv)fYB55jPE1KF~FZAi#ME7lU{Uyb~frx$F!cN!v!bz%wE$ zL3?IXt^_%FVNW^pJqc*g)Tm7qV=a2vOsR{{L8hBu+i3v{bfuHtC;Zts!~OcU8i-Ew zW(|MXC0*~$40W~*B0u!Kf#&5>umPBnw<&^$6i%e{S02xDf6`ipsM>&+H7`lPcE6!x zS`Lf^T4BbG*ewG|I0Qi2w>{F>1-cC%hcql2H6_(+jJ zwR&UD0m`4<&Zc+6`J|n5su^6V?1^t~eKiV))UvmXBtckpYUD@jc;#3+P3Ze=Lj3}=nZ?b94j^9Cy6L-ze zPdM+8$cd6RXZT$WX*75|{?D5E{mqpOW5QpyQ7p%`^Ki2g~D2#x!DjH(}AGuW%# zX8lzA*N-q3g`Rf#4qB1#-;y;LLVh@=6MNXp%2!= z8hc(Gvv31k9%gKC$VtTex0rtUE1)=&I^j>%XE9}58dxHg1Ta|CfpHrn<3c}L__RVA zjuae%xPi9y<-CIVu^*nb5ji-Ytgwe)M7*yq^wom!b?$Mi_@z5aM?eZWTb0J=G4 z9u0$l;Ilf7_EJjb2zE2yYTaz);K)wk;vxJN772u>aj@h15uK}9GOw*N&0*c&?E z_t2qvX%Oq=Mitgdk6674o6#$f0iBwehpYS3-IW6pbsIDaN;~{70)nh8qW9IJ+4vlR z*CIgwXK%lUm9dd zDkWN(+N`Nz@x}_)e11EmgB_s^{T&H!@jEk|QgAhyv=$YIQ*0PDk=pIwbumATx-+_7PkG8ul0|d#LAw$g^Ow4vI>Qv^MDSuv0aE zZ1l#vHt2Rkx#i36%2b2BO!*K&@8(o>f-R2_PF5E^VgJH|=eIZLzo*0KiUSV+f!;S{ zT%+*XqKLPdGd?b7Cefh)0{JW?5J=Hi8C^sZ@4XeQ1X=hDmkS3aABARHr{F{b0A&R~ zJB9;gQ;2@LXC+sT(tS8_G~bru2N3_*-gdxG4d`?jHG9Fm7?VYnEJI1t zkOr#)^W)$<&f-84#Rc$Avw^TBq#xP=$9SReH)O<-U>9!vjyt2&l{@Ca0r~&zhA6% z=M4uh?+-c#{xP7uxmRbu+qRf?sxO(QpJEyss=(-%n7ln2+(9l%Vj1tvKjM^8Wp(DB zPFI=#nTXr@m}-uTqa0i4Ls*XMlRJNbRH!(9 z)7fGmb{Tqa^JRxbXJ>eWNJ=$<$P8B+Tml6mMQYM?nBU@*x;3H%U|;u`+*uSwOBsv} zV3wJh_<6swhEbx=T~m~ZX5o_rt0FRvkL^)68dGVn1w`URw)Rbyf8Ziq#;>_)q%eVU z@ORopW&PB7zzjzq!`4&TTvSA;I%DnD;+G3 z*?$1>14fT+hc2v~!(U+h`V5JVtJ%B`xoe!YTY~bJ1y{&to*a5){ypkI}ZZAuw7&j?`vP073(M z1j^+WnETMX$aZB*9@X1T zyZy6x0`w@T*Elb>z1%{ znru@sgXH)t4BIg7rh~1Pkf&LapwUq^@U~{5^iHARMsg{4*(wq5k{PAEy)wG)sMpoi6kEOHn2{-ou#uti!z?zeGD8)aL5UaKIfz=z~Yo z9rKi^*W|!Zho5+Klyk|ME;w=BYq$lz3RCXUL?NA4UthP<%H{IW&-fke>gbLS0`Um( zfBX6P7DWI;P)97K6c&b~L%5k^c2GH?y~Kq*1-S+}jkMYwmlQD0bV8aGocaQ;3RU|} z(c>KyH5w6{6IzIXHu2qR4mB&K%hbbEEuBypBJeZ7Q*uS=_x<86pDhtIEEuF-kq@!~ zI9}_hnNMmtjOnhgpZ9e7WkmQl<3^8!=vXQtc& zGY%BhY2o8|u9)Q=CPI+;t)GZ!kEavg0b@$~TDx%~(NLz@ZVZMMM4$Sd@0~0FQ?{(3D({y>RNta?f?fFzp zu{{F{{<b;gBnZ5@WIl{1z!gt>9am5!Y$X)3$J?i$hOocjQn@ z^+DQD>-i(!XnEOq9>zO@qPj{tZyn z)x~AkW7KNZ`ES2dA{(OM)&*JkuX{@RkK|5Cu)rKP-*M)l_+dE->u`RXp^5)K&hnoe9fn!EGF`ym6@lS zF#k#X*uCtP@a4g#W>Yf`sS6UYf|CrIN^-q^erFWok}+Ac_Jsq5(_iVw=LhzW9nmP7 z2YsnoBs2t%0o$A38^N$uI?!Cl5{Cl5q;Pu_-jGyM9}K+o8zSS_w-swua#zd6(nf+U z0vlP@NP^V)GBmc+Zq^hJR3Cd{W%<#MTjnTnEyt#a z74TSeq2UAc11wgv13p5jt5SY1;TAY^oG*LRgg>k0^-LZkyrrq+_C3BteX*(b_iF>V zZ)7ZfE`*?P>9v^Mi#WK$$z8#>xlqW{VS|2Y_3XZ2EK_-pdeYMg7U&{U5>Gi=v}}ixtZ(T~{!K@sQ{n1+Vbs~PDWW3Q1)QIW%y*0qRng8pap>lYHZIV!L(o;hn;nC z%CV>=5u0)b7eS%Byefe(=40BZm**CEgh+JU6!+{dTrm#vNYH22P+wQW{1-*etWvhj z19WEeuCb}6?`$yQX{@{BsydCXGmV;j#(kHqztp}!ZCcJw;WM0tgHFhRuvw322U8;3 z79D;f2s4%o57Xf?SMjFMhjRmkMHr+^Np$7G&5(GNYHK`~Ry!#N$SPlltEjlJEq(iD+Yj z92k?&WK0_kp}&mMy707gB&gS9VsG$sAb!HCr~zHxPaCY^?NfzVCry!m7zx_t_*_vP=8)D9U?)&G#e{Rts3YY>3{Zos#dZbJ7H zG&h@0H@S)SeF6@ZH|c$C63?$7Z9XAcAb%qPDltDc$xu;Ajx<0zA!y#pS)5b0_*FT) zH3ypn&<)-s2>W?t4H=g0@#U0R6HaDS6dA48l-A)Affq&HJVdTSH_wx{w5#9o&sn4a4l zw&S<#Q^Y1$R(?`dAxz`jgd9eXuG?hpYP(=r&^n@UTaRe-xI|elzFLg__{H+auD9*k zkkQKRo`#7f&*GDZ*BDLYGz5|mJyjiE=-Kh7h`Qw`jwa+-%jt0En-83Ra$0L&ufh*C zT3-{u)W?@=pV5qyVo~Wig2_D7h|D-vaZ%86a5se}CwCrNUrAofAQiPLkCveENyw~p z(L?9EK~Pqp!4{+pjry>gRJDGx&+dmiZhZ2oO|X3hKId9Cxz^4!)rQzPsemIrV+Fv_ zp>nKZ8W+sVkk`uj1ory8g6y^Inq!f+s*oQ-{qKa!F=bPqor#v9S|nbXjNiBVE9EC| zEcRnU2Z5w!zOIwuO;O=(Lz=Y<&BRUCgSOdrcfml z;?{wUcy?2a9mzZEC|}8ka~$u@xm@nsTKM+>O#e(XfabLQWW>09Z_{M-Fh!3s2b&nc|3X37MwL%`}3 zN*#-+NVJC;Ym-Kvs1sM>wd)HBTrm{;#9qf8hUxC@?S!tUWB)si z-4<{ciQo`a>z$6pH-*d&mNt|u5_yM~%i?K^#lQ*WA0YeBrmf@7<6}L61&LRgf5>a= zoE3?$zh291H7CM-z`ZOif(#idhjD~=)o;c+XPTGEQ*VKT;hoIA9d#hqBo|y*`|8%M zi&T3kzDKI{uhtLL6`k|#yiDDX%-DgOoS!NWJt6+E{$h2lSMaT&n;^jpx54J-SaT!30&4>7kX7Q{eVi zRwXFhPnUy5La6re>`<5_ChU3hR=xzV>1HtO6P{p&c}C@fE?vp58*CLaQlO>Vx;qj9 z+GkL@oFelG(BktkH|jD2rX&+gF>1`L+mRtjoy+!_>STr)(7dvgR$e^3~8AKql{mfSB`JjywIR` zz8^;WkfD@>Z{j*`bQ=mYp%!r`%RSP!iMt$t(ajky=S#xx?~(8o!@1Bo1<^+!aVcB6%Vqc;2dI7dT+M+8TS(w5+U?rR;dnCjz1Pc zF7MBov@;R55G$IowLOKITpbA)RW@y*J#L1Nuuw1Jf${~PvHL-{g3C=f^jg#M%KwY_Nf27Qo5Z&M(9zrA zajvA12jqkVs$dojqqvLUEB?SvuS?0SKs*Y`*wAQW7;iY|Y59;Cak_A@t>gNF78FsYfGt;b30wjmmdV~!kDuIiVA7Wi6 z-@OJyh-fkjB3PPiT9;x-F>6kw((d0Xi&?8B4+E>`4^em zvrXIu9xFn7pKzsZP-uYO#%YJ|VDPr!>WBdai`*Wf&)NzMG{0Z`}pM`2};gHrJUiSI6Q zb>dE!+gq@@zv&cg6$s|@I%^1`jbfcx>5&-iJ8-Y z^kVkwq|LA2`MR?^@&ydXp@RkAUc+cv7!uk@1PB~up}cITxf5KpB8u2uo1EZ#s2NfT z{5d2;-*jMhwgFS%O*GW-cb;A(jipTe+h6$9v?yUP=RcxKg-ujT%Ykh{0-c{P z{js7e2i-H$nH+|e^{jiBCVctNP-N%B1m(jN($dwS$4A*Ia=9$+=^@d3Jg-P z#_Gy1gyp4uwuQkbw91xR_x$Iu+rgE;DR| C>cf8k diff --git a/wasm-rt-impl.c b/wasm-rt-impl.c new file mode 100644 index 0000000..0918836 --- /dev/null +++ b/wasm-rt-impl.c @@ -0,0 +1,504 @@ +/* + * Copyright 2018 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "wasm-rt-impl.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER && !WASM_RT_SKIP_SIGNAL_RECOVERY && \ + !defined(_WIN32) +#include +#include +#endif + +#ifdef _WIN32 +#include +#else +#include +#endif + +#if _MSC_VER +#include +#define alloca _alloca +#endif + +#define PAGE_SIZE 65536 +#define MAX_EXCEPTION_SIZE PAGE_SIZE + +typedef struct FuncType { + wasm_rt_type_t* params; + wasm_rt_type_t* results; + uint32_t param_count; + uint32_t result_count; +} FuncType; + +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER && !WASM_RT_SKIP_SIGNAL_RECOVERY +static bool g_signal_handler_installed = false; +#ifdef _WIN32 +static void* g_sig_handler_handle = 0; +#else +static char* g_alt_stack = 0; +#endif +#endif + +#if WASM_RT_USE_STACK_DEPTH_COUNT +uint32_t wasm_rt_call_stack_depth; +uint32_t wasm_rt_saved_call_stack_depth; +#endif + +static FuncType* g_func_types; +static uint32_t g_func_type_count; + +jmp_buf wasm_rt_jmp_buf; + +static uint32_t g_active_exception_tag; +static uint8_t g_active_exception[MAX_EXCEPTION_SIZE]; +static uint32_t g_active_exception_size; + +static jmp_buf* g_unwind_target; + +void wasm_rt_trap(wasm_rt_trap_t code) { + assert(code != WASM_RT_TRAP_NONE); +#if WASM_RT_USE_STACK_DEPTH_COUNT + wasm_rt_call_stack_depth = wasm_rt_saved_call_stack_depth; +#endif + +#ifdef WASM_RT_TRAP_HANDLER + WASM_RT_TRAP_HANDLER(code); + wasm_rt_unreachable(); +#else + WASM_RT_LONGJMP(wasm_rt_jmp_buf, code); +#endif +} + +static bool func_types_are_equal(FuncType* a, FuncType* b) { + if (a->param_count != b->param_count || a->result_count != b->result_count) + return 0; + uint32_t i; + for (i = 0; i < a->param_count; ++i) + if (a->params[i] != b->params[i]) + return 0; + for (i = 0; i < a->result_count; ++i) + if (a->results[i] != b->results[i]) + return 0; + return 1; +} + +uint32_t wasm_rt_register_func_type(uint32_t param_count, + uint32_t result_count, + ...) { + size_t param_size = param_count * sizeof(wasm_rt_type_t); + size_t result_size = result_count * sizeof(wasm_rt_type_t); + FuncType func_type; + func_type.param_count = param_count; + func_type.params = alloca(param_size); + func_type.result_count = result_count; + func_type.results = alloca(result_size); + + va_list args; + va_start(args, result_count); + + uint32_t i; + for (i = 0; i < param_count; ++i) + func_type.params[i] = va_arg(args, wasm_rt_type_t); + for (i = 0; i < result_count; ++i) + func_type.results[i] = va_arg(args, wasm_rt_type_t); + va_end(args); + + for (i = 0; i < g_func_type_count; ++i) + if (func_types_are_equal(&g_func_types[i], &func_type)) + return i + 1; + + // This is a new/unseed type. Copy our stack allocated params/results into + // permanent heap allocated space. + wasm_rt_type_t* params = malloc(param_size); + wasm_rt_type_t* results = malloc(result_size); + memcpy(params, func_type.params, param_size); + memcpy(results, func_type.results, result_size); + func_type.params = params; + func_type.results = results; + + uint32_t idx = g_func_type_count++; + g_func_types = realloc(g_func_types, g_func_type_count * sizeof(FuncType)); + g_func_types[idx] = func_type; + return idx + 1; +} + +uint32_t wasm_rt_register_tag(uint32_t size) { + static uint32_t s_tag_count = 0; + + if (size > MAX_EXCEPTION_SIZE) { + wasm_rt_trap(WASM_RT_TRAP_EXHAUSTION); + } + return s_tag_count++; +} + +void wasm_rt_load_exception(uint32_t tag, uint32_t size, const void* values) { + assert(size <= MAX_EXCEPTION_SIZE); + + g_active_exception_tag = tag; + g_active_exception_size = size; + + if (size) { + memcpy(g_active_exception, values, size); + } +} + +WASM_RT_NO_RETURN void wasm_rt_throw(void) { + WASM_RT_LONGJMP(*g_unwind_target, WASM_RT_TRAP_UNCAUGHT_EXCEPTION); +} + +WASM_RT_UNWIND_TARGET* wasm_rt_get_unwind_target(void) { + return g_unwind_target; +} + +void wasm_rt_set_unwind_target(WASM_RT_UNWIND_TARGET* target) { + g_unwind_target = target; +} + +uint32_t wasm_rt_exception_tag(void) { + return g_active_exception_tag; +} + +uint32_t wasm_rt_exception_size(void) { + return g_active_exception_size; +} + +void* wasm_rt_exception(void) { + return g_active_exception; +} + +#ifdef _WIN32 +static void* os_mmap(size_t size) { + void* ret = VirtualAlloc(NULL, size, MEM_RESERVE, PAGE_NOACCESS); + return ret; +} + +static int os_munmap(void* addr, size_t size) { + // Windows can only unmap the whole mapping + (void)size; /* unused */ + BOOL succeeded = VirtualFree(addr, 0, MEM_RELEASE); + return succeeded ? 0 : -1; +} + +static int os_mprotect(void* addr, size_t size) { + if (size == 0) { + return 0; + } + void* ret = VirtualAlloc(addr, size, MEM_COMMIT, PAGE_READWRITE); + if (ret == addr) { + return 0; + } + VirtualFree(addr, 0, MEM_RELEASE); + return -1; +} + +static void os_print_last_error(const char* msg) { + DWORD errorMessageID = GetLastError(); + if (errorMessageID != 0) { + LPSTR messageBuffer = 0; + // The api creates the buffer that holds the message + size_t size = FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPSTR)&messageBuffer, 0, NULL); + (void)size; + printf("%s. %s\n", msg, messageBuffer); + LocalFree(messageBuffer); + } else { + printf("%s. No error code.\n", msg); + } +} + +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER && !WASM_RT_SKIP_SIGNAL_RECOVERY + +static LONG os_signal_handler(PEXCEPTION_POINTERS info) { + if (info->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { + wasm_rt_trap(WASM_RT_TRAP_OOB); + } else if (info->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) { + wasm_rt_trap(WASM_RT_TRAP_EXHAUSTION); + } + return EXCEPTION_CONTINUE_SEARCH; +} + +static void os_install_signal_handler(void) { + g_sig_handler_handle = + AddVectoredExceptionHandler(1 /* CALL_FIRST */, os_signal_handler); +} + +static void os_cleanup_signal_handler(void) { + RemoveVectoredExceptionHandler(g_sig_handler_handle); +} + +#endif + +#else +static void* os_mmap(size_t size) { + int map_prot = PROT_NONE; + int map_flags = MAP_ANONYMOUS | MAP_PRIVATE; + uint8_t* addr = mmap(NULL, size, map_prot, map_flags, -1, 0); + if (addr == MAP_FAILED) + return NULL; + return addr; +} + +static int os_munmap(void* addr, size_t size) { + return munmap(addr, size); +} + +static int os_mprotect(void* addr, size_t size) { + return mprotect(addr, size, PROT_READ | PROT_WRITE); +} + +static void os_print_last_error(const char* msg) { + perror(msg); +} + +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER && !WASM_RT_SKIP_SIGNAL_RECOVERY +static void os_signal_handler(int sig, siginfo_t* si, void* unused) { + if (si->si_code == SEGV_ACCERR) { + wasm_rt_trap(WASM_RT_TRAP_OOB); + } else { + wasm_rt_trap(WASM_RT_TRAP_EXHAUSTION); + } +} + +static void os_install_signal_handler(void) { + /* Use alt stack to handle SIGSEGV from stack overflow */ + g_alt_stack = malloc(SIGSTKSZ); + if (g_alt_stack == NULL) { + perror("malloc failed"); + abort(); + } + + stack_t ss; + ss.ss_sp = g_alt_stack; + ss.ss_flags = 0; + ss.ss_size = SIGSTKSZ; + if (sigaltstack(&ss, NULL) != 0) { + perror("sigaltstack failed"); + abort(); + } + + struct sigaction sa; + sa.sa_flags = SA_SIGINFO | SA_ONSTACK; + sigemptyset(&sa.sa_mask); + sa.sa_sigaction = os_signal_handler; + + /* Install SIGSEGV and SIGBUS handlers, since macOS seems to use SIGBUS. */ + if (sigaction(SIGSEGV, &sa, NULL) != 0 || sigaction(SIGBUS, &sa, NULL) != 0) { + perror("sigaction failed"); + abort(); + } +} + +static void os_cleanup_signal_handler(void) { + /* Undo what was done in os_install_signal_handler */ + struct sigaction sa; + sa.sa_handler = SIG_DFL; + if (sigaction(SIGSEGV, &sa, NULL) != 0 || sigaction(SIGBUS, &sa, NULL)) { + perror("sigaction failed"); + abort(); + } + + if (sigaltstack(NULL, NULL) != 0) { + perror("sigaltstack failed"); + abort(); + } + + free(g_alt_stack); +} +#endif + +#endif + +void wasm_rt_init(void) { +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER && !WASM_RT_SKIP_SIGNAL_RECOVERY + if (!g_signal_handler_installed) { + g_signal_handler_installed = true; + os_install_signal_handler(); + } +#endif +} + +bool wasm_rt_is_initialized(void) { +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER && !WASM_RT_SKIP_SIGNAL_RECOVERY + return g_signal_handler_installed; +#else + return true; +#endif +} + +void wasm_rt_free(void) { + for (uint32_t i = 0; i < g_func_type_count; ++i) { + free(g_func_types[i].params); + free(g_func_types[i].results); + } + + g_func_type_count = 0; + free(g_func_types); + g_func_types = NULL; + +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER && !WASM_RT_SKIP_SIGNAL_RECOVERY + os_cleanup_signal_handler(); +#endif +} + +void wasm_rt_allocate_memory(wasm_rt_memory_t* memory, + uint32_t initial_pages, + uint32_t max_pages) { + uint32_t byte_length = initial_pages * PAGE_SIZE; +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER + /* Reserve 8GiB. */ + void* addr = os_mmap(0x200000000ul); + + if (!addr) { + os_print_last_error("os_mmap failed."); + abort(); + } + int ret = os_mprotect(addr, byte_length); + if (ret != 0) { + os_print_last_error("os_mprotect failed."); + abort(); + } + memory->data = addr; +#else + memory->data = calloc(byte_length, 1); +#endif + memory->size = byte_length; + memory->pages = initial_pages; + memory->max_pages = max_pages; +} + +uint32_t wasm_rt_grow_memory(wasm_rt_memory_t* memory, uint32_t delta) { + uint32_t old_pages = memory->pages; + uint32_t new_pages = memory->pages + delta; + if (new_pages == 0) { + return 0; + } + if (new_pages < old_pages || new_pages > memory->max_pages) { + return (uint32_t)-1; + } + uint32_t old_size = old_pages * PAGE_SIZE; + uint32_t new_size = new_pages * PAGE_SIZE; + uint32_t delta_size = delta * PAGE_SIZE; +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER + uint8_t* new_data = memory->data; + int ret = os_mprotect(new_data + old_size, delta_size); + if (ret != 0) { + return (uint32_t)-1; + } +#else + uint8_t* new_data = realloc(memory->data, new_size); + if (new_data == NULL) { + return (uint32_t)-1; + } +#if !WABT_BIG_ENDIAN + memset(new_data + old_size, 0, delta_size); +#endif +#endif +#if WABT_BIG_ENDIAN + memmove(new_data + new_size - old_size, new_data, old_size); + memset(new_data, 0, delta_size); +#endif + memory->pages = new_pages; + memory->size = new_size; + memory->data = new_data; + return old_pages; +} + +void wasm_rt_free_memory(wasm_rt_memory_t* memory) { +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER + os_munmap(memory->data, memory->size); // ignore error? +#else + free(memory->data); +#endif +} + +#define DEFINE_TABLE_OPS(type) \ + void wasm_rt_allocate_##type##_table(wasm_rt_##type##_table_t* table, \ + uint32_t elements, \ + uint32_t max_elements) { \ + table->size = elements; \ + table->max_size = max_elements; \ + table->data = calloc(table->size, sizeof(wasm_rt_##type##_t)); \ + } \ + void wasm_rt_free_##type##_table(wasm_rt_##type##_table_t* table) { \ + free(table->data); \ + } \ + uint32_t wasm_rt_grow_##type##_table(wasm_rt_##type##_table_t* table, \ + uint32_t delta, \ + wasm_rt_##type##_t init) { \ + uint32_t old_elems = table->size; \ + uint64_t new_elems = (uint64_t)table->size + delta; \ + if (new_elems == 0) { \ + return 0; \ + } \ + if ((new_elems < old_elems) || (new_elems > table->max_size)) { \ + return (uint32_t)-1; \ + } \ + void* new_data = \ + realloc(table->data, new_elems * sizeof(wasm_rt_##type##_t)); \ + if (!new_data) { \ + return (uint32_t)-1; \ + } \ + table->data = new_data; \ + table->size = new_elems; \ + for (uint32_t i = old_elems; i < new_elems; i++) { \ + table->data[i] = init; \ + } \ + return old_elems; \ + } + +DEFINE_TABLE_OPS(funcref) +DEFINE_TABLE_OPS(externref) + +const char* wasm_rt_strerror(wasm_rt_trap_t trap) { + switch (trap) { + case WASM_RT_TRAP_NONE: + return "No error"; + case WASM_RT_TRAP_OOB: +#if WASM_RT_MERGED_OOB_AND_EXHAUSTION_TRAPS + return "Out-of-bounds access in linear memory or a table, or call stack " + "exhausted"; +#else + return "Out-of-bounds access in linear memory or a table"; + case WASM_RT_TRAP_EXHAUSTION: + return "Call stack exhausted"; +#endif + case WASM_RT_TRAP_INT_OVERFLOW: + return "Integer overflow on divide or truncation"; + case WASM_RT_TRAP_DIV_BY_ZERO: + return "Integer divide by zero"; + case WASM_RT_TRAP_INVALID_CONVERSION: + return "Conversion from NaN to integer"; + case WASM_RT_TRAP_UNREACHABLE: + return "Unreachable instruction executed"; + case WASM_RT_TRAP_CALL_INDIRECT: + return "Invalid call_indirect"; + case WASM_RT_TRAP_UNCAUGHT_EXCEPTION: + return "Uncaught exception"; + } + return "invalid trap code"; +} diff --git a/wasm-rt-impl.h b/wasm-rt-impl.h new file mode 100644 index 0000000..3e5bad4 --- /dev/null +++ b/wasm-rt-impl.h @@ -0,0 +1,72 @@ +/* + * Copyright 2018 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WASM_RT_IMPL_H_ +#define WASM_RT_IMPL_H_ + +#include "wasm-rt.h" + +#ifdef _WIN32 +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** A setjmp buffer used for handling traps. */ +extern jmp_buf wasm_rt_jmp_buf; + +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER && !defined(_WIN32) +#define WASM_RT_LONGJMP(buf, val) siglongjmp(buf, val) +#else +#define WASM_RT_LONGJMP(buf, val) longjmp(buf, val) +#endif + +#if WASM_RT_USE_STACK_DEPTH_COUNT +/** Saved call stack depth that will be restored in case a trap occurs. */ +extern uint32_t wasm_rt_saved_call_stack_depth; +#define WASM_RT_SAVE_STACK_DEPTH() \ + wasm_rt_saved_call_stack_depth = wasm_rt_call_stack_depth +#else +#define WASM_RT_SAVE_STACK_DEPTH() (void)0 +#endif + +/** + * Convenience macro to use before calling a wasm function. On first execution + * it will return `WASM_RT_TRAP_NONE` (i.e. 0). If the function traps, it will + * jump back and return the trap that occurred. + * + * ``` + * wasm_rt_trap_t code = wasm_rt_impl_try(); + * if (code != 0) { + * printf("A trap occurred with code: %d\n", code); + * ... + * } + * + * // Call the potentially-trapping function. + * my_wasm_func(); + * ``` + */ +#define wasm_rt_impl_try() \ + (WASM_RT_SAVE_STACK_DEPTH(), wasm_rt_set_unwind_target(&wasm_rt_jmp_buf), \ + WASM_RT_SETJMP(wasm_rt_jmp_buf)) + +#ifdef __cplusplus +} +#endif + +#endif /* WASM_RT_IMPL_H_ */ diff --git a/wasm-rt.h b/wasm-rt.h new file mode 100644 index 0000000..b420087 --- /dev/null +++ b/wasm-rt.h @@ -0,0 +1,409 @@ +/* + * Copyright 2018 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WASM_RT_H_ +#define WASM_RT_H_ + +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef __has_builtin +#define __has_builtin(x) 0 // Compatibility with non-clang compilers. +#endif + +#if __has_builtin(__builtin_expect) +#define UNLIKELY(x) __builtin_expect(!!(x), 0) +#define LIKELY(x) __builtin_expect(!!(x), 1) +#else +#define UNLIKELY(x) (x) +#define LIKELY(x) (x) +#endif + +#if __has_builtin(__builtin_memcpy) +#define wasm_rt_memcpy __builtin_memcpy +#else +#define wasm_rt_memcpy memcpy +#endif + +#if __has_builtin(__builtin_unreachable) +#define wasm_rt_unreachable __builtin_unreachable +#else +#define wasm_rt_unreachable abort +#endif + +/** + * Enable memory checking via a signal handler via the following definition: + * + * #define WASM_RT_MEMCHECK_SIGNAL_HANDLER 1 + * + * This is usually 10%-25% faster, but requires OS-specific support. + */ + +#ifndef WASM_RT_SKIP_SIGNAL_RECOVERY +#define WASM_RT_SKIP_SIGNAL_RECOVERY 0 +#endif + +/** Signal handler not supported on 32-bit platforms. */ +#if UINTPTR_MAX > 0xffffffff + +#define WASM_RT_SIGNAL_RECOVERY_SUPPORTED 1 + +/* Signal handler is supported. Use it by default. */ +#ifndef WASM_RT_MEMCHECK_SIGNAL_HANDLER +#define WASM_RT_MEMCHECK_SIGNAL_HANDLER 1 +#endif + +#else +#define WASM_RT_SIGNAL_RECOVERY_SUPPORTED 0 + +/* Signal handler is not supported. */ +#ifndef WASM_RT_MEMCHECK_SIGNAL_HANDLER +#define WASM_RT_MEMCHECK_SIGNAL_HANDLER 0 +#endif + +#endif + +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER && \ + (!WASM_RT_SKIP_SIGNAL_RECOVERY && !WASM_RT_SIGNAL_RECOVERY_SUPPORTED) +/* The signal handler is not supported, error out if the user was trying to + * enable it. */ +#error "Signal handler is not supported for this OS/Architecture!" +#endif + +#ifndef WASM_RT_USE_STACK_DEPTH_COUNT +/* The signal handler on POSIX can detect call stack overflows. On windows, or + * platforms without a signal handler, we use stack depth counting. */ +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER && !defined(_WIN32) +#define WASM_RT_USE_STACK_DEPTH_COUNT 0 +#else +#define WASM_RT_USE_STACK_DEPTH_COUNT 1 +#endif +#endif + +#if WASM_RT_USE_STACK_DEPTH_COUNT +/** + * When the signal handler cannot be used to detect stack overflows, stack depth + * is limited explicitly. The maximum stack depth before trapping can be + * configured by defining this symbol before including wasm-rt when building the + * generated c files, for example: + * + * ``` + * cc -c -DWASM_RT_MAX_CALL_STACK_DEPTH=100 my_module.c -o my_module.o + * ``` + */ +#ifndef WASM_RT_MAX_CALL_STACK_DEPTH +#define WASM_RT_MAX_CALL_STACK_DEPTH 500 +#endif + +/** Current call stack depth. */ +extern uint32_t wasm_rt_call_stack_depth; + +#endif + +#if defined(_MSC_VER) +#define WASM_RT_NO_RETURN __declspec(noreturn) +#else +#define WASM_RT_NO_RETURN __attribute__((noreturn)) +#endif + +#if defined(__APPLE__) && WASM_RT_MEMCHECK_SIGNAL_HANDLER +#define WASM_RT_MERGED_OOB_AND_EXHAUSTION_TRAPS 1 +#else +#define WASM_RT_MERGED_OOB_AND_EXHAUSTION_TRAPS 0 +#endif + +/** Reason a trap occurred. Provide this to `wasm_rt_trap`. */ +typedef enum { + WASM_RT_TRAP_NONE, /** No error. */ + WASM_RT_TRAP_OOB, /** Out-of-bounds access in linear memory or a table. */ + WASM_RT_TRAP_INT_OVERFLOW, /** Integer overflow on divide or truncation. */ + WASM_RT_TRAP_DIV_BY_ZERO, /** Integer divide by zero. */ + WASM_RT_TRAP_INVALID_CONVERSION, /** Conversion from NaN to integer. */ + WASM_RT_TRAP_UNREACHABLE, /** Unreachable instruction executed. */ + WASM_RT_TRAP_CALL_INDIRECT, /** Invalid call_indirect, for any reason. */ + WASM_RT_TRAP_UNCAUGHT_EXCEPTION, /* Exception thrown and not caught */ +#if WASM_RT_MERGED_OOB_AND_EXHAUSTION_TRAPS + WASM_RT_TRAP_EXHAUSTION = WASM_RT_TRAP_OOB, +#else + WASM_RT_TRAP_EXHAUSTION, /** Call stack exhausted. */ +#endif +} wasm_rt_trap_t; + +/** Value types. Used to define function signatures. */ +typedef enum { + WASM_RT_I32, + WASM_RT_I64, + WASM_RT_F32, + WASM_RT_F64, + WASM_RT_FUNCREF, + WASM_RT_EXTERNREF, +} wasm_rt_type_t; + +/** + * A generic function pointer type, both for Wasm functions (`code`) + * and host functions (`hostcode`). All function pointers are stored + * in this canonical form, but must be cast to their proper signature + * to call. + */ +typedef void (*wasm_rt_function_ptr_t)(void); + +/** A function instance (the runtime representation of a function). + * These can be stored in tables of type funcref, or used as values. */ +typedef struct { + /** The index as returned from `wasm_rt_register_func_type`. */ + uint32_t func_type; + /** The function. The embedder must know the actual C signature of the + * function and cast to it before calling. */ + wasm_rt_function_ptr_t func; + /** A function instance is a closure of the function over an instance + * of the originating module. The module_instance element will be passed into + * the function at runtime. */ + void* module_instance; +} wasm_rt_funcref_t; + +/** Default (null) value of a funcref */ +static const wasm_rt_funcref_t wasm_rt_funcref_null_value = {0, NULL, NULL}; + +/** The type of an external reference (opaque to WebAssembly). */ +typedef void* wasm_rt_externref_t; + +/** Default (null) value of an externref */ +static const wasm_rt_externref_t wasm_rt_externref_null_value = NULL; + +/** A Memory object. */ +typedef struct { + /** The linear memory data, with a byte length of `size`. */ + uint8_t* data; + /** The current and maximum page count for this Memory object. If there is no + * maximum, `max_pages` is 0xffffffffu (i.e. UINT32_MAX). */ + uint32_t pages, max_pages; + /** The current size of the linear memory, in bytes. */ + uint32_t size; +} wasm_rt_memory_t; + +/** A Table of type funcref. */ +typedef struct { + /** The table element data, with an element count of `size`. */ + wasm_rt_funcref_t* data; + /** The maximum element count of this Table object. If there is no maximum, + * `max_size` is 0xffffffffu (i.e. UINT32_MAX). */ + uint32_t max_size; + /** The current element count of the table. */ + uint32_t size; +} wasm_rt_funcref_table_t; + +/** A Table of type externref. */ +typedef struct { + /** The table element data, with an element count of `size`. */ + wasm_rt_externref_t* data; + /** The maximum element count of this Table object. If there is no maximum, + * `max_size` is 0xffffffffu (i.e. UINT32_MAX). */ + uint32_t max_size; + /** The current element count of the table. */ + uint32_t size; +} wasm_rt_externref_table_t; + +/** Initialize the runtime. */ +void wasm_rt_init(void); + +/** Is the runtime initialized? */ +bool wasm_rt_is_initialized(void); + +/** Free the runtime's state. */ +void wasm_rt_free(void); + +/** + * Stop execution immediately and jump back to the call to `wasm_rt_impl_try`. + * The result of `wasm_rt_impl_try` will be the provided trap reason. + * + * This is typically called by the generated code, and not the embedder. + */ +WASM_RT_NO_RETURN void wasm_rt_trap(wasm_rt_trap_t); + +/** + * Return a human readable error string based on a trap type. + */ +const char* wasm_rt_strerror(wasm_rt_trap_t trap); + +/** + * Register a function type with the given signature. The returned function + * index is guaranteed to be the same for all calls with the same signature. + * The following varargs must all be of type `wasm_rt_type_t`, first the + * params` and then the `results`. + * + * ``` + * // Register (func (param i32 f32) (result i64)). + * wasm_rt_register_func_type(2, 1, WASM_RT_I32, WASM_RT_F32, WASM_RT_I64); + * => returns 1 + * + * // Register (func (result i64)). + * wasm_rt_register_func_type(0, 1, WASM_RT_I32); + * => returns 2 + * + * // Register (func (param i32 f32) (result i64)) again. + * wasm_rt_register_func_type(2, 1, WASM_RT_I32, WASM_RT_F32, WASM_RT_I64); + * => returns 1 + * ``` + */ +uint32_t wasm_rt_register_func_type(uint32_t params, uint32_t results, ...); + +/** + * Register a tag with the given size. Returns the tag. + */ +uint32_t wasm_rt_register_tag(uint32_t size); + +/** + * Set the active exception to given tag, size, and contents. + */ +void wasm_rt_load_exception(uint32_t tag, uint32_t size, const void* values); + +/** + * Throw the active exception. + */ +WASM_RT_NO_RETURN void wasm_rt_throw(void); + +/** + * The type of an unwind target if an exception is thrown and caught. + */ +#define WASM_RT_UNWIND_TARGET jmp_buf + +/** + * Get the current unwind target if an exception is thrown. + */ +WASM_RT_UNWIND_TARGET* wasm_rt_get_unwind_target(void); + +/** + * Set the unwind target if an exception is thrown. + */ +void wasm_rt_set_unwind_target(WASM_RT_UNWIND_TARGET* target); + +/** + * Tag of the active exception. + */ +uint32_t wasm_rt_exception_tag(void); + +/** + * Size of the active exception. + */ +uint32_t wasm_rt_exception_size(void); + +/** + * Contents of the active exception. + */ +void* wasm_rt_exception(void); + +#if WASM_RT_MEMCHECK_SIGNAL_HANDLER && !defined(_WIN32) +#define WASM_RT_SETJMP(buf) sigsetjmp(buf, 1) +#else +#define WASM_RT_SETJMP(buf) setjmp(buf) +#endif + +#define wasm_rt_try(target) WASM_RT_SETJMP(target) + +/** + * Initialize a Memory object with an initial page size of `initial_pages` and + * a maximum page size of `max_pages`. + * + * ``` + * wasm_rt_memory_t my_memory; + * // 1 initial page (65536 bytes), and a maximum of 2 pages. + * wasm_rt_allocate_memory(&my_memory, 1, 2); + * ``` + */ +void wasm_rt_allocate_memory(wasm_rt_memory_t*, + uint32_t initial_pages, + uint32_t max_pages); + +/** + * Grow a Memory object by `pages`, and return the previous page count. If + * this new page count is greater than the maximum page count, the grow fails + * and 0xffffffffu (UINT32_MAX) is returned instead. + * + * ``` + * wasm_rt_memory_t my_memory; + * ... + * // Grow memory by 10 pages. + * uint32_t old_page_size = wasm_rt_grow_memory(&my_memory, 10); + * if (old_page_size == UINT32_MAX) { + * // Failed to grow memory. + * } + * ``` + */ +uint32_t wasm_rt_grow_memory(wasm_rt_memory_t*, uint32_t pages); + +/** + * Free a Memory object. + */ +void wasm_rt_free_memory(wasm_rt_memory_t*); + +/** + * Initialize a funcref Table object with an element count of `elements` and a + * maximum size of `max_elements`. + * + * ``` + * wasm_rt_funcref_table_t my_table; + * // 5 elements and a maximum of 10 elements. + * wasm_rt_allocate_funcref_table(&my_table, 5, 10); + * ``` + */ +void wasm_rt_allocate_funcref_table(wasm_rt_funcref_table_t*, + uint32_t elements, + uint32_t max_elements); + +/** + * Free a funcref Table object. + */ +void wasm_rt_free_funcref_table(wasm_rt_funcref_table_t*); + +/** + * Initialize an externref Table object with an element count + * of `elements` and a maximum size of `max_elements`. + * Usage as per wasm_rt_allocate_funcref_table. + */ +void wasm_rt_allocate_externref_table(wasm_rt_externref_table_t*, + uint32_t elements, + uint32_t max_elements); + +/** + * Free an externref Table object. + */ +void wasm_rt_free_externref_table(wasm_rt_externref_table_t*); + +/** + * Grow a Table object by `delta` elements (giving the new elements the value + * `init`), and return the previous element count. If this new element count is + * greater than the maximum element count, the grow fails and 0xffffffffu + * (UINT32_MAX) is returned instead. + */ +uint32_t wasm_rt_grow_funcref_table(wasm_rt_funcref_table_t*, + uint32_t delta, + wasm_rt_funcref_t init); +uint32_t wasm_rt_grow_externref_table(wasm_rt_externref_table_t*, + uint32_t delta, + wasm_rt_externref_t init); + +#ifdef __cplusplus +} +#endif + +#endif /* WASM_RT_H_ */