var createRNNWasmModuleSync = (() => {
    var _scriptDir = '.';

    return function (createRNNWasmModuleSync) {
        createRNNWasmModuleSync = createRNNWasmModuleSync || {};

        var Module = typeof createRNNWasmModuleSync != 'undefined' ? createRNNWasmModuleSync : {};

        var readyPromiseResolve, readyPromiseReject;

        Module['ready'] = new Promise(function (resolve, reject) {
            readyPromiseResolve = resolve;
            readyPromiseReject = reject;
        });

        var moduleOverrides = Object.assign({}, Module);

        var arguments_ = [];

        var thisProgram = './this.program';

        var quit_ = (status, toThrow) => {
            throw toThrow;
        };

        var ENVIRONMENT_IS_WEB = typeof window == 'object';

        var ENVIRONMENT_IS_WORKER = typeof importScripts == 'function';

        var ENVIRONMENT_IS_NODE =
            typeof process == 'object' &&
            typeof process.versions == 'object' &&
            typeof process.versions.node == 'string';

        var scriptDirectory = '';

        function locateFile(path) {
            if (Module['locateFile']) {
                return Module['locateFile'](path, scriptDirectory);
            }
            return scriptDirectory + path;
        }

        var read_, readAsync, readBinary, setWindowTitle;

        if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
            if (ENVIRONMENT_IS_WORKER) {
                scriptDirectory = self.location.href;
            } else if (typeof document != 'undefined' && document.currentScript) {
                scriptDirectory = document.currentScript.src;
            }
            if (_scriptDir) {
                scriptDirectory = _scriptDir;
            }
            if (scriptDirectory.indexOf('blob:') !== 0) {
                scriptDirectory = scriptDirectory.substr(0, scriptDirectory.replace(/[?#].*/, '').lastIndexOf('/') + 1);
            } else {
                scriptDirectory = '';
            }
            {
                read_ = (url) => {
                    try {
                        var xhr = new XMLHttpRequest();
                        xhr.open('GET', url, false);
                        xhr.send(null);
                        return xhr.responseText;
                    } catch (err) {
                        var data = tryParseAsDataURI(url);
                        if (data) {
                            return intArrayToString(data);
                        }
                        throw err;
                    }
                };
                if (ENVIRONMENT_IS_WORKER) {
                    readBinary = (url) => {
                        try {
                            var xhr = new XMLHttpRequest();
                            xhr.open('GET', url, false);
                            xhr.responseType = 'arraybuffer';
                            xhr.send(null);
                            return new Uint8Array(xhr.response);
                        } catch (err) {
                            var data = tryParseAsDataURI(url);
                            if (data) {
                                return data;
                            }
                            throw err;
                        }
                    };
                }
                readAsync = (url, onload, onerror) => {
                    var xhr = new XMLHttpRequest();
                    xhr.open('GET', url, true);
                    xhr.responseType = 'arraybuffer';
                    xhr.onload = () => {
                        if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) {
                            onload(xhr.response);
                            return;
                        }
                        var data = tryParseAsDataURI(url);
                        if (data) {
                            onload(data.buffer);
                            return;
                        }
                        onerror();
                    };
                    xhr.onerror = onerror;
                    xhr.send(null);
                };
            }
            setWindowTitle = (title) => (document.title = title);
        } else {
        }

        var out = Module['print'] || console.log.bind(console);

        var err = Module['printErr'] || console.warn.bind(console);

        Object.assign(Module, moduleOverrides);

        moduleOverrides = null;

        if (Module['arguments']) arguments_ = Module['arguments'];

        if (Module['thisProgram']) thisProgram = Module['thisProgram'];

        if (Module['quit']) quit_ = Module['quit'];

        var wasmBinary;

        if (Module['wasmBinary']) wasmBinary = Module['wasmBinary'];

        var noExitRuntime = Module['noExitRuntime'] || true;

        if (typeof WebAssembly != 'object') {
            abort('no native wasm support detected');
        }

        var wasmMemory;

        var ABORT = false;

        var EXITSTATUS;

        function assert(condition, text) {
            if (!condition) {
                abort(text);
            }
        }

        var buffer, HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;

        function updateGlobalBufferAndViews(buf) {
            buffer = buf;
            Module['HEAP8'] = HEAP8 = new Int8Array(buf);
            Module['HEAP16'] = HEAP16 = new Int16Array(buf);
            Module['HEAP32'] = HEAP32 = new Int32Array(buf);
            Module['HEAPU8'] = HEAPU8 = new Uint8Array(buf);
            Module['HEAPU16'] = HEAPU16 = new Uint16Array(buf);
            Module['HEAPU32'] = HEAPU32 = new Uint32Array(buf);
            Module['HEAPF32'] = HEAPF32 = new Float32Array(buf);
            Module['HEAPF64'] = HEAPF64 = new Float64Array(buf);
        }

        var INITIAL_MEMORY = Module['INITIAL_MEMORY'] || 16777216;

        var wasmTable;

        var __ATPRERUN__ = [];

        var __ATINIT__ = [];

        var __ATPOSTRUN__ = [];

        var runtimeInitialized = false;

        function preRun() {
            if (Module['preRun']) {
                if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
                while (Module['preRun'].length) {
                    addOnPreRun(Module['preRun'].shift());
                }
            }
            callRuntimeCallbacks(__ATPRERUN__);
        }

        function initRuntime() {
            runtimeInitialized = true;
            callRuntimeCallbacks(__ATINIT__);
        }

        function postRun() {
            if (Module['postRun']) {
                if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
                while (Module['postRun'].length) {
                    addOnPostRun(Module['postRun'].shift());
                }
            }
            callRuntimeCallbacks(__ATPOSTRUN__);
        }

        function addOnPreRun(cb) {
            __ATPRERUN__.unshift(cb);
        }

        function addOnInit(cb) {
            __ATINIT__.unshift(cb);
        }

        function addOnPostRun(cb) {
            __ATPOSTRUN__.unshift(cb);
        }

        var runDependencies = 0;

        var runDependencyWatcher = null;

        var dependenciesFulfilled = null;

        function addRunDependency(id) {
            runDependencies++;
            if (Module['monitorRunDependencies']) {
                Module['monitorRunDependencies'](runDependencies);
            }
        }

        function removeRunDependency(id) {
            runDependencies--;
            if (Module['monitorRunDependencies']) {
                Module['monitorRunDependencies'](runDependencies);
            }
            if (runDependencies == 0) {
                if (runDependencyWatcher !== null) {
                    clearInterval(runDependencyWatcher);
                    runDependencyWatcher = null;
                }
                if (dependenciesFulfilled) {
                    var callback = dependenciesFulfilled;
                    dependenciesFulfilled = null;
                    callback();
                }
            }
        }

        function abort(what) {
            {
                if (Module['onAbort']) {
                    Module['onAbort'](what);
                }
            }
            what = 'Aborted(' + what + ')';
            err(what);
            ABORT = true;
            EXITSTATUS = 1;
            what += '. Build with -sASSERTIONS for more info.';
            var e = new WebAssembly.RuntimeError(what);
            readyPromiseReject(e);
            throw e;
        }

        var dataURIPrefix = 'data:application/octet-stream;base64,';

        function isDataURI(filename) {
            return filename.startsWith(dataURIPrefix);
        }

        var wasmBinaryFile;

        wasmBinaryFile =
            'data:application/octet-stream;base64,[encoded data, 1920160 characters]';

        if (!isDataURI(wasmBinaryFile)) {
            wasmBinaryFile = locateFile(wasmBinaryFile);
        }

        function getBinary(file) {
            try {
                if (file == wasmBinaryFile && wasmBinary) {
                    return new Uint8Array(wasmBinary);
                }
                var binary = tryParseAsDataURI(file);
                if (binary) {
                    return binary;
                }
                if (readBinary) {
                    return readBinary(file);
                } else {
                    throw "sync fetching of the wasm failed: you can preload it to Module['wasmBinary'] manually, or emcc.py will do that for you when generating HTML (but not JS)";
                }
            } catch (err) {
                abort(err);
            }
        }

        function instantiateSync(file, info) {
            var instance;
            var module;
            var binary;
            try {
                binary = getBinary(file);
                module = new WebAssembly.Module(binary);
                instance = new WebAssembly.Instance(module, info);
            } catch (e) {
                var str = e.toString();
                err('failed to compile wasm module: ' + str);
                if (str.includes('imported Memory') || str.includes('memory import')) {
                    err(
                        'Memory size incompatibility issues may be due to changing INITIAL_MEMORY at runtime to something too large. Use ALLOW_MEMORY_GROWTH to allow any size memory (and also make sure not to set INITIAL_MEMORY at runtime to something smaller than it was at compile time).'
                    );
                }
                throw e;
            }
            return [instance, module];
        }

        function createWasm() {
            var info = {
                a: asmLibraryArg,
            };
            function receiveInstance(instance, module) {
                var exports = instance.exports;
                Module['asm'] = exports;
                wasmMemory = Module['asm']['c'];
                updateGlobalBufferAndViews(wasmMemory.buffer);
                wasmTable = Module['asm']['k'];
                addOnInit(Module['asm']['d']);
                removeRunDependency('wasm-instantiate');
            }
            addRunDependency('wasm-instantiate');
            if (Module['instantiateWasm']) {
                try {
                    var exports = Module['instantiateWasm'](info, receiveInstance);
                    return exports;
                } catch (e) {
                    err('Module.instantiateWasm callback failed with error: ' + e);
                    return false;
                }
            }
            var result = instantiateSync(wasmBinaryFile, info);
            receiveInstance(result[0]);
            return Module['asm'];
        }

        function callRuntimeCallbacks(callbacks) {
            while (callbacks.length > 0) {
                var callback = callbacks.shift();
                if (typeof callback == 'function') {
                    callback(Module);
                    continue;
                }
                var func = callback.func;
                if (typeof func == 'number') {
                    if (callback.arg === undefined) {
                        getWasmTableEntry(func)();
                    } else {
                        getWasmTableEntry(func)(callback.arg);
                    }
                } else {
                    func(callback.arg === undefined ? null : callback.arg);
                }
            }
        }

        function getWasmTableEntry(funcPtr) {
            return wasmTable.get(funcPtr);
        }

        function _emscripten_memcpy_big(dest, src, num) {
            HEAPU8.copyWithin(dest, src, src + num);
        }

        function getHeapMax() {
            return 2147483648;
        }

        function emscripten_realloc_buffer(size) {
            try {
                wasmMemory.grow((size - buffer.byteLength + 65535) >>> 16);
                updateGlobalBufferAndViews(wasmMemory.buffer);
                return 1;
            } catch (e) {}
        }

        function _emscripten_resize_heap(requestedSize) {
            var oldSize = HEAPU8.length;
            requestedSize = requestedSize >>> 0;
            var maxHeapSize = getHeapMax();
            if (requestedSize > maxHeapSize) {
                return false;
            }
            let alignUp = (x, multiple) => x + ((multiple - (x % multiple)) % multiple);
            for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
                var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown);
                overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296);
                var newSize = Math.min(maxHeapSize, alignUp(Math.max(requestedSize, overGrownHeapSize), 65536));
                var replacement = emscripten_realloc_buffer(newSize);
                if (replacement) {
                    return true;
                }
            }
            return false;
        }

        var ASSERTIONS = false;

        function intArrayToString(array) {
            var ret = [];
            for (var i = 0; i < array.length; i++) {
                var chr = array[i];
                if (chr > 255) {
                    if (ASSERTIONS) {
                        assert(
                            false,
                            'Character code ' +
                                chr +
                                ' (' +
                                String.fromCharCode(chr) +
                                ')  at offset ' +
                                i +
                                ' not in 0x00-0xFF.'
                        );
                    }
                    chr &= 255;
                }
                ret.push(String.fromCharCode(chr));
            }
            return ret.join('');
        }

        var decodeBase64 =
            typeof atob == 'function'
                ? atob
                : function (input) {
                      var keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
                      var output = '';
                      var chr1, chr2, chr3;
                      var enc1, enc2, enc3, enc4;
                      var i = 0;
                      input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
                      do {
                          enc1 = keyStr.indexOf(input.charAt(i++));
                          enc2 = keyStr.indexOf(input.charAt(i++));
                          enc3 = keyStr.indexOf(input.charAt(i++));
                          enc4 = keyStr.indexOf(input.charAt(i++));
                          chr1 = (enc1 << 2) | (enc2 >> 4);
                          chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
                          chr3 = ((enc3 & 3) << 6) | enc4;
                          output = output + String.fromCharCode(chr1);
                          if (enc3 !== 64) {
                              output = output + String.fromCharCode(chr2);
                          }
                          if (enc4 !== 64) {
                              output = output + String.fromCharCode(chr3);
                          }
                      } while (i < input.length);
                      return output;
                  };

        function intArrayFromBase64(s) {
            try {
                var decoded = decodeBase64(s);
                var bytes = new Uint8Array(decoded.length);
                for (var i = 0; i < decoded.length; ++i) {
                    bytes[i] = decoded.charCodeAt(i);
                }
                return bytes;
            } catch (_) {
                throw new Error('Converting base64 string to bytes failed.');
            }
        }

        function tryParseAsDataURI(filename) {
            if (!isDataURI(filename)) {
                return;
            }
            return intArrayFromBase64(filename.slice(dataURIPrefix.length));
        }

        var asmLibraryArg = {
            b: _emscripten_memcpy_big,
            a: _emscripten_resize_heap,
        };

        var asm = createWasm();

        var ___wasm_call_ctors = (Module['___wasm_call_ctors'] = asm['d']);

        var _malloc = (Module['_malloc'] = asm['e']);

        var _free = (Module['_free'] = asm['f']);

        var _rnnoise_init = (Module['_rnnoise_init'] = asm['g']);

        var _rnnoise_create = (Module['_rnnoise_create'] = asm['h']);

        var _rnnoise_destroy = (Module['_rnnoise_destroy'] = asm['i']);

        var _rnnoise_process_frame = (Module['_rnnoise_process_frame'] = asm['j']);

        var calledRun;

        dependenciesFulfilled = function runCaller() {
            if (!calledRun) run();
            if (!calledRun) dependenciesFulfilled = runCaller;
        };

        function run(args) {
            args = args || arguments_;
            if (runDependencies > 0) {
                return;
            }
            preRun();
            if (runDependencies > 0) {
                return;
            }
            function doRun() {
                if (calledRun) return;
                calledRun = true;
                Module['calledRun'] = true;
                if (ABORT) return;
                initRuntime();
                readyPromiseResolve(Module);
                if (Module['onRuntimeInitialized']) Module['onRuntimeInitialized']();
                postRun();
            }
            if (Module['setStatus']) {
                Module['setStatus']('Running...');
                setTimeout(function () {
                    setTimeout(function () {
                        Module['setStatus']('');
                    }, 1);
                    doRun();
                }, 1);
            } else {
                doRun();
            }
        }

        Module['run'] = run;

        if (Module['preInit']) {
            if (typeof Module['preInit'] == 'function') Module['preInit'] = [Module['preInit']];
            while (Module['preInit'].length > 0) {
                Module['preInit'].pop()();
            }
        }

        run();

        return createRNNWasmModuleSync;
    };
})();
