@areb0s/scip.js 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/scip-wrapper.js +1 -1
- package/dist/scip.js +387 -387
- package/dist/scip.min.js +10 -10
- package/package.json +1 -1
package/dist/scip-wrapper.js
CHANGED
|
@@ -41,7 +41,7 @@ export const ready = new Promise((resolve, reject) => {
|
|
|
41
41
|
/**
|
|
42
42
|
* Default CDN base URL for WASM files
|
|
43
43
|
*/
|
|
44
|
-
const DEFAULT_CDN_BASE = 'https://cdn.jsdelivr.net/
|
|
44
|
+
const DEFAULT_CDN_BASE = 'https://cdn.jsdelivr.net/npm/@areb0s/scip.js@1.1.6/dist/';
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Get base URL from global SCIP_BASE_URL or default CDN
|
package/dist/scip.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* SCIP.js Browser Bundle
|
|
4
|
-
* Supports: LP, MIP, MINLP (Mixed Integer Nonlinear Programming)
|
|
5
|
-
*/
|
|
6
|
-
(function(global) {
|
|
7
|
-
'use strict';
|
|
8
|
-
|
|
9
|
-
// Script directory detection for WASM loading
|
|
10
|
-
var __SCIP_SCRIPT_DIR__ = (function() {
|
|
11
|
-
// Check for explicit SCIP_BASE_URL
|
|
12
|
-
if (typeof SCIP_BASE_URL !== 'undefined' && SCIP_BASE_URL) {
|
|
13
|
-
return SCIP_BASE_URL + (SCIP_BASE_URL.endsWith('/') ? '' : '/');
|
|
14
|
-
}
|
|
15
|
-
// Try to detect from current script
|
|
16
|
-
if (typeof document !== 'undefined' && document.currentScript && document.currentScript.src) {
|
|
17
|
-
var src = document.currentScript.src;
|
|
18
|
-
return src.substring(0, src.lastIndexOf('/') + 1);
|
|
19
|
-
}
|
|
20
|
-
// Default CDN (npm)
|
|
21
|
-
return 'https://cdn.jsdelivr.net/npm/@areb0s/scip.js@
|
|
22
|
-
})();
|
|
23
|
-
|
|
24
|
-
// Inline the transformed scip-core.js (createSCIP factory function)
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* SCIP.js Browser Bundle
|
|
4
|
+
* Supports: LP, MIP, MINLP (Mixed Integer Nonlinear Programming)
|
|
5
|
+
*/
|
|
6
|
+
(function(global) {
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
// Script directory detection for WASM loading
|
|
10
|
+
var __SCIP_SCRIPT_DIR__ = (function() {
|
|
11
|
+
// Check for explicit SCIP_BASE_URL
|
|
12
|
+
if (typeof SCIP_BASE_URL !== 'undefined' && SCIP_BASE_URL) {
|
|
13
|
+
return SCIP_BASE_URL + (SCIP_BASE_URL.endsWith('/') ? '' : '/');
|
|
14
|
+
}
|
|
15
|
+
// Try to detect from current script
|
|
16
|
+
if (typeof document !== 'undefined' && document.currentScript && document.currentScript.src) {
|
|
17
|
+
var src = document.currentScript.src;
|
|
18
|
+
return src.substring(0, src.lastIndexOf('/') + 1);
|
|
19
|
+
}
|
|
20
|
+
// Default CDN (npm)
|
|
21
|
+
return 'https://cdn.jsdelivr.net/npm/@areb0s/scip.js@1.1.6/dist/';
|
|
22
|
+
})();
|
|
23
|
+
|
|
24
|
+
// Inline the transformed scip-core.js (createSCIP factory function)
|
|
25
25
|
|
|
26
26
|
var createSCIP = (() => {
|
|
27
27
|
var _scriptDir = __SCIP_SCRIPT_DIR__;
|
|
@@ -36,366 +36,366 @@ var Module=moduleArg;var readyPromiseResolve,readyPromiseReject;Module["ready"]=
|
|
|
36
36
|
}
|
|
37
37
|
);
|
|
38
38
|
})();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// SCIP wrapper implementation
|
|
42
|
-
var scipModule = null;
|
|
43
|
-
var isInitialized = false;
|
|
44
|
-
var initPromise = null;
|
|
45
|
-
var readyResolve = null;
|
|
46
|
-
var readyReject = null;
|
|
47
|
-
|
|
48
|
-
// Exception tracking for debugging WASM crashes
|
|
49
|
-
var lastAbortReason = null;
|
|
50
|
-
var lastExitCode = null;
|
|
51
|
-
|
|
52
|
-
var readyPromise = new Promise(function(resolve, reject) {
|
|
53
|
-
readyResolve = resolve;
|
|
54
|
-
readyReject = reject;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
var Status = {
|
|
58
|
-
OPTIMAL: 'optimal',
|
|
59
|
-
INFEASIBLE: 'infeasible',
|
|
60
|
-
UNBOUNDED: 'unbounded',
|
|
61
|
-
TIME_LIMIT: 'timelimit',
|
|
62
|
-
UNKNOWN: 'unknown',
|
|
63
|
-
ERROR: 'error'
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
function parseStatus(output) {
|
|
67
|
-
if (output.includes('optimal solution found')) return Status.OPTIMAL;
|
|
68
|
-
if (output.includes('problem is infeasible')) return Status.INFEASIBLE;
|
|
69
|
-
if (output.includes('problem is unbounded')) return Status.UNBOUNDED;
|
|
70
|
-
if (output.includes('time limit reached')) return Status.TIME_LIMIT;
|
|
71
|
-
return Status.UNKNOWN;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function parseSolution(output) {
|
|
75
|
-
var variables = {};
|
|
76
|
-
var objective = { value: null };
|
|
77
|
-
|
|
78
|
-
var objMatch = output.match(/objective value:\s*([\d.e+-]+)/i);
|
|
79
|
-
if (objMatch) {
|
|
80
|
-
objective.value = parseFloat(objMatch[1]);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
var varRegex = /^(\w+)\s+([\d.e+-]+)/gm;
|
|
84
|
-
var match;
|
|
85
|
-
var solSection = output.split('solution:')[1] || output;
|
|
86
|
-
|
|
87
|
-
while ((match = varRegex.exec(solSection)) !== null) {
|
|
88
|
-
var name = match[1];
|
|
89
|
-
var value = parseFloat(match[2]);
|
|
90
|
-
if (!isNaN(value) && name !== 'objective') {
|
|
91
|
-
variables[name] = value;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return { variables: variables, objective: objective };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function parseStatistics(output) {
|
|
99
|
-
var stats = { solvingTime: null, nodes: null, iterations: null, gap: null };
|
|
100
|
-
|
|
101
|
-
var timeMatch = output.match(/Solving Time \(sec\)\s*:\s*([\d.]+)/);
|
|
102
|
-
if (timeMatch) stats.solvingTime = parseFloat(timeMatch[1]);
|
|
103
|
-
|
|
104
|
-
var nodesMatch = output.match(/Nodes\s*:\s*(\d+)/);
|
|
105
|
-
if (nodesMatch) stats.nodes = parseInt(nodesMatch[1]);
|
|
106
|
-
|
|
107
|
-
var iterMatch = output.match(/LP Iterations\s*:\s*(\d+)/);
|
|
108
|
-
if (iterMatch) stats.iterations = parseInt(iterMatch[1]);
|
|
109
|
-
|
|
110
|
-
var gapMatch = output.match(/Gap\s*:\s*([\d.]+)\s*%/);
|
|
111
|
-
if (gapMatch) stats.gap = parseFloat(gapMatch[1]);
|
|
112
|
-
|
|
113
|
-
return stats;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function init(options) {
|
|
117
|
-
options = options || {};
|
|
118
|
-
|
|
119
|
-
if (isInitialized) {
|
|
120
|
-
return Promise.resolve();
|
|
121
|
-
}
|
|
122
|
-
if (initPromise) {
|
|
123
|
-
return initPromise;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
initPromise = new Promise(function(resolve, reject) {
|
|
127
|
-
try {
|
|
128
|
-
var wasmPath = options.wasmPath || (__SCIP_SCRIPT_DIR__ + 'scip.wasm');
|
|
129
|
-
console.log('[SCIP.js] __SCIP_SCRIPT_DIR__:', __SCIP_SCRIPT_DIR__);
|
|
130
|
-
console.log('[SCIP.js] Loading WASM from:', wasmPath);
|
|
131
|
-
|
|
132
|
-
// Verify WASM is accessible
|
|
133
|
-
fetch(wasmPath, { method: 'HEAD' })
|
|
134
|
-
.then(function(res) {
|
|
135
|
-
console.log('[SCIP.js] WASM file check:', res.ok ? 'OK' : 'FAILED', res.status);
|
|
136
|
-
})
|
|
137
|
-
.catch(function(err) {
|
|
138
|
-
console.error('[SCIP.js] WASM file check failed:', err);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
createSCIP({
|
|
142
|
-
locateFile: function(path) {
|
|
143
|
-
if (path.endsWith('.wasm')) {
|
|
144
|
-
console.log('[SCIP.js] locateFile called for:', path, '-> returning:', wasmPath);
|
|
145
|
-
return wasmPath;
|
|
146
|
-
}
|
|
147
|
-
return path;
|
|
148
|
-
},
|
|
149
|
-
print: function(text) {
|
|
150
|
-
if (scipModule && scipModule.onStdout) {
|
|
151
|
-
scipModule.onStdout(text);
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
printErr: function(text) {
|
|
155
|
-
if (scipModule && scipModule.onStderr) {
|
|
156
|
-
scipModule.onStderr(text);
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
// Capture abort/exit reasons for better error messages
|
|
160
|
-
onAbort: function(reason) {
|
|
161
|
-
lastAbortReason = reason;
|
|
162
|
-
console.error('[SCIP WASM Abort]', reason);
|
|
163
|
-
},
|
|
164
|
-
onExit: function(code) {
|
|
165
|
-
lastExitCode = code;
|
|
166
|
-
if (code !== 0) {
|
|
167
|
-
console.error('[SCIP WASM Exit]', code);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}).then(function(module) {
|
|
171
|
-
console.log('[SCIP.js] WASM loaded successfully');
|
|
172
|
-
scipModule = module;
|
|
173
|
-
|
|
174
|
-
if (scipModule.FS) {
|
|
175
|
-
try { scipModule.FS.mkdir('/problems'); } catch (e) {}
|
|
176
|
-
try { scipModule.FS.mkdir('/solutions'); } catch (e) {}
|
|
177
|
-
try { scipModule.FS.mkdir('/settings'); } catch (e) {}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
isInitialized = true;
|
|
181
|
-
if (readyResolve) readyResolve();
|
|
182
|
-
resolve();
|
|
183
|
-
}).catch(function(err) {
|
|
184
|
-
console.error('[SCIP.js] WASM loading failed:', err);
|
|
185
|
-
console.error('[SCIP.js] Attempted WASM path:', wasmPath);
|
|
186
|
-
console.error('[SCIP.js] Make sure the WASM file is accessible at this URL.');
|
|
187
|
-
console.error('[SCIP.js] You can set window.SCIP_BASE_URL before loading this script to specify a custom path.');
|
|
188
|
-
var error = new Error('SCIP WASM loading failed: ' + (err.message || err) + '. WASM path: ' + wasmPath);
|
|
189
|
-
if (readyReject) readyReject(error);
|
|
190
|
-
reject(error);
|
|
191
|
-
});
|
|
192
|
-
} catch (err) {
|
|
193
|
-
console.error('[SCIP.js] Initialization error:', err);
|
|
194
|
-
if (readyReject) readyReject(err);
|
|
195
|
-
reject(err);
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
return initPromise;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function solve(problem, options) {
|
|
203
|
-
options = options || {};
|
|
204
|
-
|
|
205
|
-
var doSolve = function() {
|
|
206
|
-
var format = options.format || 'lp';
|
|
207
|
-
var timeLimit = options.timeLimit || 3600;
|
|
208
|
-
var gap = options.gap || null;
|
|
209
|
-
var verbose = options.verbose || false;
|
|
210
|
-
var parameters = options.parameters || {};
|
|
211
|
-
|
|
212
|
-
var stdout = '';
|
|
213
|
-
var stderr = '';
|
|
214
|
-
|
|
215
|
-
scipModule.onStdout = function(text) {
|
|
216
|
-
stdout += text + '\n';
|
|
217
|
-
if (verbose) console.log('[SCIP]', text);
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
scipModule.onStderr = function(text) {
|
|
221
|
-
stderr += text + '\n';
|
|
222
|
-
if (verbose) console.error('[SCIP Error]', text);
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
try {
|
|
226
|
-
var formatExtMap = { mps: 'mps', zpl: 'zpl', cip: 'cip', lp: 'lp' };
|
|
227
|
-
var ext = formatExtMap[format] || 'lp';
|
|
228
|
-
var problemFile = '/problems/problem.' + ext;
|
|
229
|
-
var solutionFile = '/solutions/solution.sol';
|
|
230
|
-
|
|
231
|
-
scipModule.FS.writeFile(problemFile, problem);
|
|
232
|
-
|
|
233
|
-
var commands = [];
|
|
234
|
-
commands.push('set limits time ' + timeLimit);
|
|
235
|
-
|
|
236
|
-
if (gap !== null) {
|
|
237
|
-
commands.push('set limits gap ' + gap);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
for (var key in parameters) {
|
|
241
|
-
if (parameters.hasOwnProperty(key)) {
|
|
242
|
-
commands.push('set ' + key + ' ' + parameters[key]);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
commands.push('read ' + problemFile);
|
|
247
|
-
commands.push('optimize');
|
|
248
|
-
commands.push('display solution');
|
|
249
|
-
commands.push('write solution ' + solutionFile);
|
|
250
|
-
commands.push('display statistics');
|
|
251
|
-
commands.push('quit');
|
|
252
|
-
|
|
253
|
-
var settingsContent = commands.join('\n');
|
|
254
|
-
scipModule.FS.writeFile('/settings/commands.txt', settingsContent);
|
|
255
|
-
|
|
256
|
-
var exitCode = scipModule.callMain(['-b', '/settings/commands.txt']);
|
|
257
|
-
|
|
258
|
-
var status = parseStatus(stdout);
|
|
259
|
-
var parsed = parseSolution(stdout);
|
|
260
|
-
var statistics = parseStatistics(stdout);
|
|
261
|
-
|
|
262
|
-
var rawSolution = null;
|
|
263
|
-
try {
|
|
264
|
-
rawSolution = scipModule.FS.readFile(solutionFile, { encoding: 'utf8' });
|
|
265
|
-
} catch (e) {}
|
|
266
|
-
|
|
267
|
-
// Cleanup
|
|
268
|
-
var cleanupFiles = [
|
|
269
|
-
'/problems/problem.lp', '/problems/problem.mps',
|
|
270
|
-
'/problems/problem.zpl', '/problems/problem.cip',
|
|
271
|
-
'/solutions/solution.sol', '/settings/commands.txt'
|
|
272
|
-
];
|
|
273
|
-
for (var i = 0; i < cleanupFiles.length; i++) {
|
|
274
|
-
try { scipModule.FS.unlink(cleanupFiles[i]); } catch (e) {}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return {
|
|
278
|
-
status: status,
|
|
279
|
-
objective: parsed.objective.value,
|
|
280
|
-
variables: parsed.variables,
|
|
281
|
-
statistics: statistics,
|
|
282
|
-
exitCode: exitCode,
|
|
283
|
-
output: verbose ? stdout : undefined,
|
|
284
|
-
rawSolution: rawSolution
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
} catch (error) {
|
|
288
|
-
// Attempt to extract detailed exception message from WASM
|
|
289
|
-
var errorMessage = error.message || String(error);
|
|
290
|
-
var exceptionInfo = null;
|
|
291
|
-
|
|
292
|
-
// Check if this is a WASM exception (pointer address)
|
|
293
|
-
if (typeof error === 'number' || /^\d+$/.test(String(error))) {
|
|
294
|
-
var ptr = typeof error === 'number' ? error : parseInt(String(error), 10);
|
|
295
|
-
|
|
296
|
-
// Try to get exception message using Emscripten's exception handling
|
|
297
|
-
if (scipModule) {
|
|
298
|
-
try {
|
|
299
|
-
// Modern Emscripten exception handling
|
|
300
|
-
if (typeof scipModule.getExceptionMessage === 'function') {
|
|
301
|
-
exceptionInfo = scipModule.getExceptionMessage(ptr);
|
|
302
|
-
errorMessage = 'WASM Exception: ' + exceptionInfo;
|
|
303
|
-
} else if (typeof scipModule.UTF8ToString === 'function') {
|
|
304
|
-
// Fallback: try to read as string from memory
|
|
305
|
-
try {
|
|
306
|
-
var str = scipModule.UTF8ToString(ptr);
|
|
307
|
-
if (str && str.length > 0 && str.length < 1000) {
|
|
308
|
-
exceptionInfo = str;
|
|
309
|
-
errorMessage = 'WASM Exception: ' + str;
|
|
310
|
-
}
|
|
311
|
-
} catch (e) { /* not a valid string pointer */ }
|
|
312
|
-
}
|
|
313
|
-
} catch (e) {
|
|
314
|
-
console.error('[SCIP] Failed to get exception message:', e);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (!exceptionInfo) {
|
|
319
|
-
errorMessage = 'WASM Exception (ptr: ' + ptr + '). Enable exception handling in build for details.';
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
return {
|
|
324
|
-
status: Status.ERROR,
|
|
325
|
-
error: errorMessage,
|
|
326
|
-
errorDetails: {
|
|
327
|
-
rawError: String(error),
|
|
328
|
-
exceptionInfo: exceptionInfo,
|
|
329
|
-
abortReason: lastAbortReason,
|
|
330
|
-
exitCode: lastExitCode,
|
|
331
|
-
type: typeof error,
|
|
332
|
-
stdout: stdout,
|
|
333
|
-
stderr: stderr
|
|
334
|
-
},
|
|
335
|
-
output: stdout + stderr
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// Reset exception tracking after solve
|
|
340
|
-
lastAbortReason = null;
|
|
341
|
-
lastExitCode = null;
|
|
342
|
-
};
|
|
343
|
-
|
|
344
|
-
if (!isInitialized) {
|
|
345
|
-
return init(options).then(doSolve);
|
|
346
|
-
}
|
|
347
|
-
return Promise.resolve(doSolve());
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
function minimize(problem, options) {
|
|
351
|
-
if (!problem.toLowerCase().includes('minimize')) {
|
|
352
|
-
problem = 'Minimize\n' + problem;
|
|
353
|
-
}
|
|
354
|
-
return solve(problem, options);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
function maximize(problem, options) {
|
|
358
|
-
if (!problem.toLowerCase().includes('maximize')) {
|
|
359
|
-
problem = 'Maximize\n' + problem;
|
|
360
|
-
}
|
|
361
|
-
return solve(problem, options);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function version() {
|
|
365
|
-
var getVersion = function() {
|
|
366
|
-
var output = '';
|
|
367
|
-
scipModule.onStdout = function(text) { output += text + '\n'; };
|
|
368
|
-
scipModule.callMain(['--version']);
|
|
369
|
-
return output.trim();
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
if (!isInitialized) {
|
|
373
|
-
return init().then(getVersion);
|
|
374
|
-
}
|
|
375
|
-
return Promise.resolve(getVersion());
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function isReady() {
|
|
379
|
-
return isInitialized;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
// Expose SCIP API
|
|
383
|
-
var SCIP = {
|
|
384
|
-
init: init,
|
|
385
|
-
ready: readyPromise,
|
|
386
|
-
isReady: isReady,
|
|
387
|
-
solve: solve,
|
|
388
|
-
minimize: minimize,
|
|
389
|
-
maximize: maximize,
|
|
390
|
-
version: version,
|
|
391
|
-
Status: Status
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
global.SCIP = SCIP;
|
|
395
|
-
|
|
396
|
-
// Auto-initialize
|
|
397
|
-
init().catch(function(err) {
|
|
398
|
-
console.error('[SCIP.js] Auto-initialization failed:', err.message);
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
})(typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : globalThis);
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
// SCIP wrapper implementation
|
|
42
|
+
var scipModule = null;
|
|
43
|
+
var isInitialized = false;
|
|
44
|
+
var initPromise = null;
|
|
45
|
+
var readyResolve = null;
|
|
46
|
+
var readyReject = null;
|
|
47
|
+
|
|
48
|
+
// Exception tracking for debugging WASM crashes
|
|
49
|
+
var lastAbortReason = null;
|
|
50
|
+
var lastExitCode = null;
|
|
51
|
+
|
|
52
|
+
var readyPromise = new Promise(function(resolve, reject) {
|
|
53
|
+
readyResolve = resolve;
|
|
54
|
+
readyReject = reject;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
var Status = {
|
|
58
|
+
OPTIMAL: 'optimal',
|
|
59
|
+
INFEASIBLE: 'infeasible',
|
|
60
|
+
UNBOUNDED: 'unbounded',
|
|
61
|
+
TIME_LIMIT: 'timelimit',
|
|
62
|
+
UNKNOWN: 'unknown',
|
|
63
|
+
ERROR: 'error'
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
function parseStatus(output) {
|
|
67
|
+
if (output.includes('optimal solution found')) return Status.OPTIMAL;
|
|
68
|
+
if (output.includes('problem is infeasible')) return Status.INFEASIBLE;
|
|
69
|
+
if (output.includes('problem is unbounded')) return Status.UNBOUNDED;
|
|
70
|
+
if (output.includes('time limit reached')) return Status.TIME_LIMIT;
|
|
71
|
+
return Status.UNKNOWN;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function parseSolution(output) {
|
|
75
|
+
var variables = {};
|
|
76
|
+
var objective = { value: null };
|
|
77
|
+
|
|
78
|
+
var objMatch = output.match(/objective value:\s*([\d.e+-]+)/i);
|
|
79
|
+
if (objMatch) {
|
|
80
|
+
objective.value = parseFloat(objMatch[1]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
var varRegex = /^(\w+)\s+([\d.e+-]+)/gm;
|
|
84
|
+
var match;
|
|
85
|
+
var solSection = output.split('solution:')[1] || output;
|
|
86
|
+
|
|
87
|
+
while ((match = varRegex.exec(solSection)) !== null) {
|
|
88
|
+
var name = match[1];
|
|
89
|
+
var value = parseFloat(match[2]);
|
|
90
|
+
if (!isNaN(value) && name !== 'objective') {
|
|
91
|
+
variables[name] = value;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return { variables: variables, objective: objective };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function parseStatistics(output) {
|
|
99
|
+
var stats = { solvingTime: null, nodes: null, iterations: null, gap: null };
|
|
100
|
+
|
|
101
|
+
var timeMatch = output.match(/Solving Time \(sec\)\s*:\s*([\d.]+)/);
|
|
102
|
+
if (timeMatch) stats.solvingTime = parseFloat(timeMatch[1]);
|
|
103
|
+
|
|
104
|
+
var nodesMatch = output.match(/Nodes\s*:\s*(\d+)/);
|
|
105
|
+
if (nodesMatch) stats.nodes = parseInt(nodesMatch[1]);
|
|
106
|
+
|
|
107
|
+
var iterMatch = output.match(/LP Iterations\s*:\s*(\d+)/);
|
|
108
|
+
if (iterMatch) stats.iterations = parseInt(iterMatch[1]);
|
|
109
|
+
|
|
110
|
+
var gapMatch = output.match(/Gap\s*:\s*([\d.]+)\s*%/);
|
|
111
|
+
if (gapMatch) stats.gap = parseFloat(gapMatch[1]);
|
|
112
|
+
|
|
113
|
+
return stats;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function init(options) {
|
|
117
|
+
options = options || {};
|
|
118
|
+
|
|
119
|
+
if (isInitialized) {
|
|
120
|
+
return Promise.resolve();
|
|
121
|
+
}
|
|
122
|
+
if (initPromise) {
|
|
123
|
+
return initPromise;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
initPromise = new Promise(function(resolve, reject) {
|
|
127
|
+
try {
|
|
128
|
+
var wasmPath = options.wasmPath || (__SCIP_SCRIPT_DIR__ + 'scip.wasm');
|
|
129
|
+
console.log('[SCIP.js] __SCIP_SCRIPT_DIR__:', __SCIP_SCRIPT_DIR__);
|
|
130
|
+
console.log('[SCIP.js] Loading WASM from:', wasmPath);
|
|
131
|
+
|
|
132
|
+
// Verify WASM is accessible
|
|
133
|
+
fetch(wasmPath, { method: 'HEAD' })
|
|
134
|
+
.then(function(res) {
|
|
135
|
+
console.log('[SCIP.js] WASM file check:', res.ok ? 'OK' : 'FAILED', res.status);
|
|
136
|
+
})
|
|
137
|
+
.catch(function(err) {
|
|
138
|
+
console.error('[SCIP.js] WASM file check failed:', err);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
createSCIP({
|
|
142
|
+
locateFile: function(path) {
|
|
143
|
+
if (path.endsWith('.wasm')) {
|
|
144
|
+
console.log('[SCIP.js] locateFile called for:', path, '-> returning:', wasmPath);
|
|
145
|
+
return wasmPath;
|
|
146
|
+
}
|
|
147
|
+
return path;
|
|
148
|
+
},
|
|
149
|
+
print: function(text) {
|
|
150
|
+
if (scipModule && scipModule.onStdout) {
|
|
151
|
+
scipModule.onStdout(text);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
printErr: function(text) {
|
|
155
|
+
if (scipModule && scipModule.onStderr) {
|
|
156
|
+
scipModule.onStderr(text);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
// Capture abort/exit reasons for better error messages
|
|
160
|
+
onAbort: function(reason) {
|
|
161
|
+
lastAbortReason = reason;
|
|
162
|
+
console.error('[SCIP WASM Abort]', reason);
|
|
163
|
+
},
|
|
164
|
+
onExit: function(code) {
|
|
165
|
+
lastExitCode = code;
|
|
166
|
+
if (code !== 0) {
|
|
167
|
+
console.error('[SCIP WASM Exit]', code);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}).then(function(module) {
|
|
171
|
+
console.log('[SCIP.js] WASM loaded successfully');
|
|
172
|
+
scipModule = module;
|
|
173
|
+
|
|
174
|
+
if (scipModule.FS) {
|
|
175
|
+
try { scipModule.FS.mkdir('/problems'); } catch (e) {}
|
|
176
|
+
try { scipModule.FS.mkdir('/solutions'); } catch (e) {}
|
|
177
|
+
try { scipModule.FS.mkdir('/settings'); } catch (e) {}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
isInitialized = true;
|
|
181
|
+
if (readyResolve) readyResolve();
|
|
182
|
+
resolve();
|
|
183
|
+
}).catch(function(err) {
|
|
184
|
+
console.error('[SCIP.js] WASM loading failed:', err);
|
|
185
|
+
console.error('[SCIP.js] Attempted WASM path:', wasmPath);
|
|
186
|
+
console.error('[SCIP.js] Make sure the WASM file is accessible at this URL.');
|
|
187
|
+
console.error('[SCIP.js] You can set window.SCIP_BASE_URL before loading this script to specify a custom path.');
|
|
188
|
+
var error = new Error('SCIP WASM loading failed: ' + (err.message || err) + '. WASM path: ' + wasmPath);
|
|
189
|
+
if (readyReject) readyReject(error);
|
|
190
|
+
reject(error);
|
|
191
|
+
});
|
|
192
|
+
} catch (err) {
|
|
193
|
+
console.error('[SCIP.js] Initialization error:', err);
|
|
194
|
+
if (readyReject) readyReject(err);
|
|
195
|
+
reject(err);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
return initPromise;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function solve(problem, options) {
|
|
203
|
+
options = options || {};
|
|
204
|
+
|
|
205
|
+
var doSolve = function() {
|
|
206
|
+
var format = options.format || 'lp';
|
|
207
|
+
var timeLimit = options.timeLimit || 3600;
|
|
208
|
+
var gap = options.gap || null;
|
|
209
|
+
var verbose = options.verbose || false;
|
|
210
|
+
var parameters = options.parameters || {};
|
|
211
|
+
|
|
212
|
+
var stdout = '';
|
|
213
|
+
var stderr = '';
|
|
214
|
+
|
|
215
|
+
scipModule.onStdout = function(text) {
|
|
216
|
+
stdout += text + '\n';
|
|
217
|
+
if (verbose) console.log('[SCIP]', text);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
scipModule.onStderr = function(text) {
|
|
221
|
+
stderr += text + '\n';
|
|
222
|
+
if (verbose) console.error('[SCIP Error]', text);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
try {
|
|
226
|
+
var formatExtMap = { mps: 'mps', zpl: 'zpl', cip: 'cip', lp: 'lp' };
|
|
227
|
+
var ext = formatExtMap[format] || 'lp';
|
|
228
|
+
var problemFile = '/problems/problem.' + ext;
|
|
229
|
+
var solutionFile = '/solutions/solution.sol';
|
|
230
|
+
|
|
231
|
+
scipModule.FS.writeFile(problemFile, problem);
|
|
232
|
+
|
|
233
|
+
var commands = [];
|
|
234
|
+
commands.push('set limits time ' + timeLimit);
|
|
235
|
+
|
|
236
|
+
if (gap !== null) {
|
|
237
|
+
commands.push('set limits gap ' + gap);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
for (var key in parameters) {
|
|
241
|
+
if (parameters.hasOwnProperty(key)) {
|
|
242
|
+
commands.push('set ' + key + ' ' + parameters[key]);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
commands.push('read ' + problemFile);
|
|
247
|
+
commands.push('optimize');
|
|
248
|
+
commands.push('display solution');
|
|
249
|
+
commands.push('write solution ' + solutionFile);
|
|
250
|
+
commands.push('display statistics');
|
|
251
|
+
commands.push('quit');
|
|
252
|
+
|
|
253
|
+
var settingsContent = commands.join('\n');
|
|
254
|
+
scipModule.FS.writeFile('/settings/commands.txt', settingsContent);
|
|
255
|
+
|
|
256
|
+
var exitCode = scipModule.callMain(['-b', '/settings/commands.txt']);
|
|
257
|
+
|
|
258
|
+
var status = parseStatus(stdout);
|
|
259
|
+
var parsed = parseSolution(stdout);
|
|
260
|
+
var statistics = parseStatistics(stdout);
|
|
261
|
+
|
|
262
|
+
var rawSolution = null;
|
|
263
|
+
try {
|
|
264
|
+
rawSolution = scipModule.FS.readFile(solutionFile, { encoding: 'utf8' });
|
|
265
|
+
} catch (e) {}
|
|
266
|
+
|
|
267
|
+
// Cleanup
|
|
268
|
+
var cleanupFiles = [
|
|
269
|
+
'/problems/problem.lp', '/problems/problem.mps',
|
|
270
|
+
'/problems/problem.zpl', '/problems/problem.cip',
|
|
271
|
+
'/solutions/solution.sol', '/settings/commands.txt'
|
|
272
|
+
];
|
|
273
|
+
for (var i = 0; i < cleanupFiles.length; i++) {
|
|
274
|
+
try { scipModule.FS.unlink(cleanupFiles[i]); } catch (e) {}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
status: status,
|
|
279
|
+
objective: parsed.objective.value,
|
|
280
|
+
variables: parsed.variables,
|
|
281
|
+
statistics: statistics,
|
|
282
|
+
exitCode: exitCode,
|
|
283
|
+
output: verbose ? stdout : undefined,
|
|
284
|
+
rawSolution: rawSolution
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
} catch (error) {
|
|
288
|
+
// Attempt to extract detailed exception message from WASM
|
|
289
|
+
var errorMessage = error.message || String(error);
|
|
290
|
+
var exceptionInfo = null;
|
|
291
|
+
|
|
292
|
+
// Check if this is a WASM exception (pointer address)
|
|
293
|
+
if (typeof error === 'number' || /^\d+$/.test(String(error))) {
|
|
294
|
+
var ptr = typeof error === 'number' ? error : parseInt(String(error), 10);
|
|
295
|
+
|
|
296
|
+
// Try to get exception message using Emscripten's exception handling
|
|
297
|
+
if (scipModule) {
|
|
298
|
+
try {
|
|
299
|
+
// Modern Emscripten exception handling
|
|
300
|
+
if (typeof scipModule.getExceptionMessage === 'function') {
|
|
301
|
+
exceptionInfo = scipModule.getExceptionMessage(ptr);
|
|
302
|
+
errorMessage = 'WASM Exception: ' + exceptionInfo;
|
|
303
|
+
} else if (typeof scipModule.UTF8ToString === 'function') {
|
|
304
|
+
// Fallback: try to read as string from memory
|
|
305
|
+
try {
|
|
306
|
+
var str = scipModule.UTF8ToString(ptr);
|
|
307
|
+
if (str && str.length > 0 && str.length < 1000) {
|
|
308
|
+
exceptionInfo = str;
|
|
309
|
+
errorMessage = 'WASM Exception: ' + str;
|
|
310
|
+
}
|
|
311
|
+
} catch (e) { /* not a valid string pointer */ }
|
|
312
|
+
}
|
|
313
|
+
} catch (e) {
|
|
314
|
+
console.error('[SCIP] Failed to get exception message:', e);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (!exceptionInfo) {
|
|
319
|
+
errorMessage = 'WASM Exception (ptr: ' + ptr + '). Enable exception handling in build for details.';
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return {
|
|
324
|
+
status: Status.ERROR,
|
|
325
|
+
error: errorMessage,
|
|
326
|
+
errorDetails: {
|
|
327
|
+
rawError: String(error),
|
|
328
|
+
exceptionInfo: exceptionInfo,
|
|
329
|
+
abortReason: lastAbortReason,
|
|
330
|
+
exitCode: lastExitCode,
|
|
331
|
+
type: typeof error,
|
|
332
|
+
stdout: stdout,
|
|
333
|
+
stderr: stderr
|
|
334
|
+
},
|
|
335
|
+
output: stdout + stderr
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Reset exception tracking after solve
|
|
340
|
+
lastAbortReason = null;
|
|
341
|
+
lastExitCode = null;
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
if (!isInitialized) {
|
|
345
|
+
return init(options).then(doSolve);
|
|
346
|
+
}
|
|
347
|
+
return Promise.resolve(doSolve());
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function minimize(problem, options) {
|
|
351
|
+
if (!problem.toLowerCase().includes('minimize')) {
|
|
352
|
+
problem = 'Minimize\n' + problem;
|
|
353
|
+
}
|
|
354
|
+
return solve(problem, options);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function maximize(problem, options) {
|
|
358
|
+
if (!problem.toLowerCase().includes('maximize')) {
|
|
359
|
+
problem = 'Maximize\n' + problem;
|
|
360
|
+
}
|
|
361
|
+
return solve(problem, options);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function version() {
|
|
365
|
+
var getVersion = function() {
|
|
366
|
+
var output = '';
|
|
367
|
+
scipModule.onStdout = function(text) { output += text + '\n'; };
|
|
368
|
+
scipModule.callMain(['--version']);
|
|
369
|
+
return output.trim();
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
if (!isInitialized) {
|
|
373
|
+
return init().then(getVersion);
|
|
374
|
+
}
|
|
375
|
+
return Promise.resolve(getVersion());
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function isReady() {
|
|
379
|
+
return isInitialized;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Expose SCIP API
|
|
383
|
+
var SCIP = {
|
|
384
|
+
init: init,
|
|
385
|
+
ready: readyPromise,
|
|
386
|
+
isReady: isReady,
|
|
387
|
+
solve: solve,
|
|
388
|
+
minimize: minimize,
|
|
389
|
+
maximize: maximize,
|
|
390
|
+
version: version,
|
|
391
|
+
Status: Status
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
global.SCIP = SCIP;
|
|
395
|
+
|
|
396
|
+
// Auto-initialize
|
|
397
|
+
init().catch(function(err) {
|
|
398
|
+
console.error('[SCIP.js] Auto-initialization failed:', err.message);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
})(typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : globalThis);
|
package/dist/scip.min.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
(function(Ie){"use strict";var br=function(){if(typeof SCIP_BASE_URL<"u"&&SCIP_BASE_URL)return SCIP_BASE_URL+(SCIP_BASE_URL.endsWith("/")?"":"/");if(typeof document<"u"&&document.currentScript&&document.currentScript.src){var F=document.currentScript.src;return F.substring(0,F.lastIndexOf("/")+1)}return"https://cdn.jsdelivr.net/npm/@areb0s/scip.js@
|
|
2
|
-
`)):typeof readline=="function"&&(r=readline(),r!==null&&(r+=`
|
|
3
|
-
`)),!r)return null;Xr=Lr(r,!0)}return Xr.shift()},tr={ttys:[],init(){},shutdown(){},register(r,e){tr.ttys[r]={input:[],output:[],ops:e},i.registerDevice(r,tr.stream_ops)},stream_ops:{open(r){var e=tr.ttys[r.node.rdev];if(!e)throw new i.ErrnoError(43);r.tty=e,r.seekable=!1},close(r){r.tty.ops.fsync(r.tty)},fsync(r){r.tty.ops.fsync(r.tty)},read(r,e,t,n,o){if(!r.tty||!r.tty.ops.get_char)throw new i.ErrnoError(60);for(var a=0,s=0;s<n;s++){var u;try{u=r.tty.ops.get_char(r.tty)}catch{throw new i.ErrnoError(29)}if(u===void 0&&a===0)throw new i.ErrnoError(6);if(u==null)break;a++,e[t+s]=u}return a&&(r.node.timestamp=Date.now()),a},write(r,e,t,n,o){if(!r.tty||!r.tty.ops.put_char)throw new i.ErrnoError(60);try{for(var a=0;a<n;a++)r.tty.ops.put_char(r.tty,e[t+a])}catch{throw new i.ErrnoError(29)}return n&&(r.node.timestamp=Date.now()),a}},default_tty_ops:{get_char(r){return pt()},put_char(r,e){e===null||e===10?(_r(dr(r.output,0)),r.output=[]):e!=0&&r.output.push(e)},fsync(r){r.output&&r.output.length>0&&(_r(dr(r.output,0)),r.output=[])},ioctl_tcgets(r){return{c_iflag:25856,c_oflag:5,c_cflag:191,c_lflag:35387,c_cc:[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},ioctl_tcsets(r,e,t){return 0},ioctl_tiocgwinsz(r){return[24,80]}},default_tty1_ops:{put_char(r,e){e===null||e===10?(K(dr(r.output,0)),r.output=[]):e!=0&&r.output.push(e)},fsync(r){r.output&&r.output.length>0&&(K(dr(r.output,0)),r.output=[])}}},wt=(r,e)=>(q.fill(0,r,r+e),r),yt=(r,e)=>Math.ceil(r/e)*e,ve=r=>{r=yt(r,65536);var e=Se(65536,r);return e?wt(e,r):0},b={ops_table:null,mount(r){return b.createNode(null,"/",16895,0)},createNode(r,e,t,n){if(i.isBlkdev(t)||i.isFIFO(t))throw new i.ErrnoError(63);b.ops_table||(b.ops_table={dir:{node:{getattr:b.node_ops.getattr,setattr:b.node_ops.setattr,lookup:b.node_ops.lookup,mknod:b.node_ops.mknod,rename:b.node_ops.rename,unlink:b.node_ops.unlink,rmdir:b.node_ops.rmdir,readdir:b.node_ops.readdir,symlink:b.node_ops.symlink},stream:{llseek:b.stream_ops.llseek}},file:{node:{getattr:b.node_ops.getattr,setattr:b.node_ops.setattr},stream:{llseek:b.stream_ops.llseek,read:b.stream_ops.read,write:b.stream_ops.write,allocate:b.stream_ops.allocate,mmap:b.stream_ops.mmap,msync:b.stream_ops.msync}},link:{node:{getattr:b.node_ops.getattr,setattr:b.node_ops.setattr,readlink:b.node_ops.readlink},stream:{}},chrdev:{node:{getattr:b.node_ops.getattr,setattr:b.node_ops.setattr},stream:i.chrdev_stream_ops}});var o=i.createNode(r,e,t,n);return i.isDir(o.mode)?(o.node_ops=b.ops_table.dir.node,o.stream_ops=b.ops_table.dir.stream,o.contents={}):i.isFile(o.mode)?(o.node_ops=b.ops_table.file.node,o.stream_ops=b.ops_table.file.stream,o.usedBytes=0,o.contents=null):i.isLink(o.mode)?(o.node_ops=b.ops_table.link.node,o.stream_ops=b.ops_table.link.stream):i.isChrdev(o.mode)&&(o.node_ops=b.ops_table.chrdev.node,o.stream_ops=b.ops_table.chrdev.stream),o.timestamp=Date.now(),r&&(r.contents[e]=o,r.timestamp=o.timestamp),o},getFileDataAsTypedArray(r){return r.contents?r.contents.subarray?r.contents.subarray(0,r.usedBytes):new Uint8Array(r.contents):new Uint8Array(0)},expandFileStorage(r,e){var t=r.contents?r.contents.length:0;if(!(t>=e)){var n=1024*1024;e=Math.max(e,t*(t<n?2:1.125)>>>0),t!=0&&(e=Math.max(e,256));var o=r.contents;r.contents=new Uint8Array(e),r.usedBytes>0&&r.contents.set(o.subarray(0,r.usedBytes),0)}},resizeFileStorage(r,e){if(r.usedBytes!=e)if(e==0)r.contents=null,r.usedBytes=0;else{var t=r.contents;r.contents=new Uint8Array(e),t&&r.contents.set(t.subarray(0,Math.min(e,r.usedBytes))),r.usedBytes=e}},node_ops:{getattr(r){var e={};return e.dev=i.isChrdev(r.mode)?r.id:1,e.ino=r.id,e.mode=r.mode,e.nlink=1,e.uid=0,e.gid=0,e.rdev=r.rdev,i.isDir(r.mode)?e.size=4096:i.isFile(r.mode)?e.size=r.usedBytes:i.isLink(r.mode)?e.size=r.link.length:e.size=0,e.atime=new Date(r.timestamp),e.mtime=new Date(r.timestamp),e.ctime=new Date(r.timestamp),e.blksize=4096,e.blocks=Math.ceil(e.size/e.blksize),e},setattr(r,e){e.mode!==void 0&&(r.mode=e.mode),e.timestamp!==void 0&&(r.timestamp=e.timestamp),e.size!==void 0&&b.resizeFileStorage(r,e.size)},lookup(r,e){throw i.genericErrors[44]},mknod(r,e,t,n){return b.createNode(r,e,t,n)},rename(r,e,t){if(i.isDir(r.mode)){var n;try{n=i.lookupNode(e,t)}catch{}if(n)for(var o in n.contents)throw new i.ErrnoError(55)}delete r.parent.contents[r.name],r.parent.timestamp=Date.now(),r.name=t,e.contents[t]=r,e.timestamp=r.parent.timestamp,r.parent=e},unlink(r,e){delete r.contents[e],r.timestamp=Date.now()},rmdir(r,e){var t=i.lookupNode(r,e);for(var n in t.contents)throw new i.ErrnoError(55);delete r.contents[e],r.timestamp=Date.now()},readdir(r){var e=[".",".."];for(var t of Object.keys(r.contents))e.push(t);return e},symlink(r,e,t){var n=b.createNode(r,e,41471,0);return n.link=t,n},readlink(r){if(!i.isLink(r.mode))throw new i.ErrnoError(28);return r.link}},stream_ops:{read(r,e,t,n,o){var a=r.node.contents;if(o>=r.node.usedBytes)return 0;var s=Math.min(r.node.usedBytes-o,n);if(s>8&&a.subarray)e.set(a.subarray(o,o+s),t);else for(var u=0;u<s;u++)e[t+u]=a[o+u];return s},write(r,e,t,n,o,a){if(e.buffer===N.buffer&&(a=!1),!n)return 0;var s=r.node;if(s.timestamp=Date.now(),e.subarray&&(!s.contents||s.contents.subarray)){if(a)return s.contents=e.subarray(t,t+n),s.usedBytes=n,n;if(s.usedBytes===0&&o===0)return s.contents=e.slice(t,t+n),s.usedBytes=n,n;if(o+n<=s.usedBytes)return s.contents.set(e.subarray(t,t+n),o),n}if(b.expandFileStorage(s,o+n),s.contents.subarray&&e.subarray)s.contents.set(e.subarray(t,t+n),o);else for(var u=0;u<n;u++)s.contents[o+u]=e[t+u];return s.usedBytes=Math.max(s.usedBytes,o+n),n},llseek(r,e,t){var n=e;if(t===1?n+=r.position:t===2&&i.isFile(r.node.mode)&&(n+=r.node.usedBytes),n<0)throw new i.ErrnoError(28);return n},allocate(r,e,t){b.expandFileStorage(r.node,e+t),r.node.usedBytes=Math.max(r.node.usedBytes,e+t)},mmap(r,e,t,n,o){if(!i.isFile(r.node.mode))throw new i.ErrnoError(43);var a,s,u=r.node.contents;if(!(o&2)&&u.buffer===N.buffer)s=!1,a=u.byteOffset;else{if((t>0||t+e<u.length)&&(u.subarray?u=u.subarray(t,t+e):u=Array.prototype.slice.call(u,t,t+e)),s=!0,a=ve(e),!a)throw new i.ErrnoError(48);N.set(u,a)}return{ptr:a,allocated:s}},msync(r,e,t,n,o){return b.stream_ops.write(r,e,0,n,t,!1),0}}},gt=(r,e,t,n)=>{var o=n?"":`al ${r}`;cr(r,a=>{e(new Uint8Array(a)),o&&yr(o)},a=>{if(t)t();else throw`Loading data file "${r}" failed.`}),o&&Ar(o)},Et=(r,e,t,n,o,a)=>{i.createDataFile(r,e,t,n,o,a)},kt=f.preloadPlugins||[],St=(r,e,t,n)=>{typeof Browser<"u"&&Browser.init();var o=!1;return kt.forEach(a=>{o||a.canHandle(e)&&(a.handle(r,e,t,n),o=!0)}),o},bt=(r,e,t,n,o,a,s,u,c,d)=>{var v=e?Q.resolve(C.join2(r,e)):r,E=`cp ${v}`;function h(w){function P(j){d?.(),u||Et(r,e,j,n,o,c),a?.(),yr(E)}St(w,v,P,()=>{s?.(),yr(E)})||P(w)}Ar(E),typeof t=="string"?gt(t,h,s):h(t)},Ft=r=>{var e={r:0,"r+":2,w:577,"w+":578,a:1089,"a+":1090},t=e[r];if(typeof t>"u")throw new Error(`Unknown file open mode: ${r}`);return t},Vr=(r,e)=>{var t=0;return r&&(t|=365),e&&(t|=146),t},i={root:null,mounts:[],devices:{},streams:[],nextInode:1,nameTable:null,currentPath:"/",initialized:!1,ignorePermissions:!0,ErrnoError:class{constructor(r){this.name="ErrnoError",this.errno=r}},genericErrors:{},filesystems:null,syncFSRequests:0,FSStream:class{constructor(){this.shared={}}get object(){return this.node}set object(r){this.node=r}get isRead(){return(this.flags&2097155)!==1}get isWrite(){return(this.flags&2097155)!==0}get isAppend(){return this.flags&1024}get flags(){return this.shared.flags}set flags(r){this.shared.flags=r}get position(){return this.shared.position}set position(r){this.shared.position=r}},FSNode:class{constructor(r,e,t,n){r||(r=this),this.parent=r,this.mount=r.mount,this.mounted=null,this.id=i.nextInode++,this.name=e,this.mode=t,this.node_ops={},this.stream_ops={},this.rdev=n,this.readMode=365,this.writeMode=146}get read(){return(this.mode&this.readMode)===this.readMode}set read(r){r?this.mode|=this.readMode:this.mode&=~this.readMode}get write(){return(this.mode&this.writeMode)===this.writeMode}set write(r){r?this.mode|=this.writeMode:this.mode&=~this.writeMode}get isFolder(){return i.isDir(this.mode)}get isDevice(){return i.isChrdev(this.mode)}},lookupPath(r,e={}){if(r=Q.resolve(r),!r)return{path:"",node:null};var t={follow_mount:!0,recurse_count:0};if(e=Object.assign(t,e),e.recurse_count>8)throw new i.ErrnoError(32);for(var n=r.split("/").filter(E=>!!E),o=i.root,a="/",s=0;s<n.length;s++){var u=s===n.length-1;if(u&&e.parent)break;if(o=i.lookupNode(o,n[s]),a=C.join2(a,n[s]),i.isMountpoint(o)&&(!u||u&&e.follow_mount)&&(o=o.mounted.root),!u||e.follow)for(var c=0;i.isLink(o.mode);){var d=i.readlink(a);a=Q.resolve(C.dirname(a),d);var v=i.lookupPath(a,{recurse_count:e.recurse_count+1});if(o=v.node,c++>40)throw new i.ErrnoError(32)}}return{path:a,node:o}},getPath(r){for(var e;;){if(i.isRoot(r)){var t=r.mount.mountpoint;return e?t[t.length-1]!=="/"?`${t}/${e}`:t+e:t}e=e?`${r.name}/${e}`:r.name,r=r.parent}},hashName(r,e){for(var t=0,n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return(r+t>>>0)%i.nameTable.length},hashAddNode(r){var e=i.hashName(r.parent.id,r.name);r.name_next=i.nameTable[e],i.nameTable[e]=r},hashRemoveNode(r){var e=i.hashName(r.parent.id,r.name);if(i.nameTable[e]===r)i.nameTable[e]=r.name_next;else for(var t=i.nameTable[e];t;){if(t.name_next===r){t.name_next=r.name_next;break}t=t.name_next}},lookupNode(r,e){var t=i.mayLookup(r);if(t)throw new i.ErrnoError(t);for(var n=i.hashName(r.id,e),o=i.nameTable[n];o;o=o.name_next){var a=o.name;if(o.parent.id===r.id&&a===e)return o}return i.lookup(r,e)},createNode(r,e,t,n){var o=new i.FSNode(r,e,t,n);return i.hashAddNode(o),o},destroyNode(r){i.hashRemoveNode(r)},isRoot(r){return r===r.parent},isMountpoint(r){return!!r.mounted},isFile(r){return(r&61440)===32768},isDir(r){return(r&61440)===16384},isLink(r){return(r&61440)===40960},isChrdev(r){return(r&61440)===8192},isBlkdev(r){return(r&61440)===24576},isFIFO(r){return(r&61440)===4096},isSocket(r){return(r&49152)===49152},flagsToPermissionString(r){var e=["r","w","rw"][r&3];return r&512&&(e+="w"),e},nodePermissions(r,e){return i.ignorePermissions?0:e.includes("r")&&!(r.mode&292)||e.includes("w")&&!(r.mode&146)||e.includes("x")&&!(r.mode&73)?2:0},mayLookup(r){if(!i.isDir(r.mode))return 54;var e=i.nodePermissions(r,"x");return e||(r.node_ops.lookup?0:2)},mayCreate(r,e){try{var t=i.lookupNode(r,e);return 20}catch{}return i.nodePermissions(r,"wx")},mayDelete(r,e,t){var n;try{n=i.lookupNode(r,e)}catch(a){return a.errno}var o=i.nodePermissions(r,"wx");if(o)return o;if(t){if(!i.isDir(n.mode))return 54;if(i.isRoot(n)||i.getPath(n)===i.cwd())return 10}else if(i.isDir(n.mode))return 31;return 0},mayOpen(r,e){return r?i.isLink(r.mode)?32:i.isDir(r.mode)&&(i.flagsToPermissionString(e)!=="r"||e&512)?31:i.nodePermissions(r,i.flagsToPermissionString(e)):44},MAX_OPEN_FDS:4096,nextfd(){for(var r=0;r<=i.MAX_OPEN_FDS;r++)if(!i.streams[r])return r;throw new i.ErrnoError(33)},getStreamChecked(r){var e=i.getStream(r);if(!e)throw new i.ErrnoError(8);return e},getStream:r=>i.streams[r],createStream(r,e=-1){return r=Object.assign(new i.FSStream,r),e==-1&&(e=i.nextfd()),r.fd=e,i.streams[e]=r,r},closeStream(r){i.streams[r]=null},dupStream(r,e=-1){var t=i.createStream(r,e);return t.stream_ops?.dup?.(t),t},chrdev_stream_ops:{open(r){var e=i.getDevice(r.node.rdev);r.stream_ops=e.stream_ops,r.stream_ops.open?.(r)},llseek(){throw new i.ErrnoError(70)}},major:r=>r>>8,minor:r=>r&255,makedev:(r,e)=>r<<8|e,registerDevice(r,e){i.devices[r]={stream_ops:e}},getDevice:r=>i.devices[r],getMounts(r){for(var e=[],t=[r];t.length;){var n=t.pop();e.push(n),t.push(...n.mounts)}return e},syncfs(r,e){typeof r=="function"&&(e=r,r=!1),i.syncFSRequests++,i.syncFSRequests>1&&K(`warning: ${i.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);var t=i.getMounts(i.root.mount),n=0;function o(s){return i.syncFSRequests--,e(s)}function a(s){if(s)return a.errored?void 0:(a.errored=!0,o(s));++n>=t.length&&o(null)}t.forEach(s=>{if(!s.type.syncfs)return a(null);s.type.syncfs(s,r,a)})},mount(r,e,t){var n=t==="/",o=!t,a;if(n&&i.root)throw new i.ErrnoError(10);if(!n&&!o){var s=i.lookupPath(t,{follow_mount:!1});if(t=s.path,a=s.node,i.isMountpoint(a))throw new i.ErrnoError(10);if(!i.isDir(a.mode))throw new i.ErrnoError(54)}var u={type:r,opts:e,mountpoint:t,mounts:[]},c=r.mount(u);return c.mount=u,u.root=c,n?i.root=c:a&&(a.mounted=u,a.mount&&a.mount.mounts.push(u)),c},unmount(r){var e=i.lookupPath(r,{follow_mount:!1});if(!i.isMountpoint(e.node))throw new i.ErrnoError(28);var t=e.node,n=t.mounted,o=i.getMounts(n);Object.keys(i.nameTable).forEach(s=>{for(var u=i.nameTable[s];u;){var c=u.name_next;o.includes(u.mount)&&i.destroyNode(u),u=c}}),t.mounted=null;var a=t.mount.mounts.indexOf(n);t.mount.mounts.splice(a,1)},lookup(r,e){return r.node_ops.lookup(r,e)},mknod(r,e,t){var n=i.lookupPath(r,{parent:!0}),o=n.node,a=C.basename(r);if(!a||a==="."||a==="..")throw new i.ErrnoError(28);var s=i.mayCreate(o,a);if(s)throw new i.ErrnoError(s);if(!o.node_ops.mknod)throw new i.ErrnoError(63);return o.node_ops.mknod(o,a,e,t)},create(r,e){return e=e!==void 0?e:438,e&=4095,e|=32768,i.mknod(r,e,0)},mkdir(r,e){return e=e!==void 0?e:511,e&=1023,e|=16384,i.mknod(r,e,0)},mkdirTree(r,e){for(var t=r.split("/"),n="",o=0;o<t.length;++o)if(t[o]){n+="/"+t[o];try{i.mkdir(n,e)}catch(a){if(a.errno!=20)throw a}}},mkdev(r,e,t){return typeof t>"u"&&(t=e,e=438),e|=8192,i.mknod(r,e,t)},symlink(r,e){if(!Q.resolve(r))throw new i.ErrnoError(44);var t=i.lookupPath(e,{parent:!0}),n=t.node;if(!n)throw new i.ErrnoError(44);var o=C.basename(e),a=i.mayCreate(n,o);if(a)throw new i.ErrnoError(a);if(!n.node_ops.symlink)throw new i.ErrnoError(63);return n.node_ops.symlink(n,o,r)},rename(r,e){var t=C.dirname(r),n=C.dirname(e),o=C.basename(r),a=C.basename(e),s,u,c;if(s=i.lookupPath(r,{parent:!0}),u=s.node,s=i.lookupPath(e,{parent:!0}),c=s.node,!u||!c)throw new i.ErrnoError(44);if(u.mount!==c.mount)throw new i.ErrnoError(75);var d=i.lookupNode(u,o),v=Q.relative(r,n);if(v.charAt(0)!==".")throw new i.ErrnoError(28);if(v=Q.relative(e,t),v.charAt(0)!==".")throw new i.ErrnoError(55);var E;try{E=i.lookupNode(c,a)}catch{}if(d!==E){var h=i.isDir(d.mode),w=i.mayDelete(u,o,h);if(w)throw new i.ErrnoError(w);if(w=E?i.mayDelete(c,a,h):i.mayCreate(c,a),w)throw new i.ErrnoError(w);if(!u.node_ops.rename)throw new i.ErrnoError(63);if(i.isMountpoint(d)||E&&i.isMountpoint(E))throw new i.ErrnoError(10);if(c!==u&&(w=i.nodePermissions(u,"w"),w))throw new i.ErrnoError(w);i.hashRemoveNode(d);try{u.node_ops.rename(d,c,a)}catch(P){throw P}finally{i.hashAddNode(d)}}},rmdir(r){var e=i.lookupPath(r,{parent:!0}),t=e.node,n=C.basename(r),o=i.lookupNode(t,n),a=i.mayDelete(t,n,!0);if(a)throw new i.ErrnoError(a);if(!t.node_ops.rmdir)throw new i.ErrnoError(63);if(i.isMountpoint(o))throw new i.ErrnoError(10);t.node_ops.rmdir(t,n),i.destroyNode(o)},readdir(r){var e=i.lookupPath(r,{follow:!0}),t=e.node;if(!t.node_ops.readdir)throw new i.ErrnoError(54);return t.node_ops.readdir(t)},unlink(r){var e=i.lookupPath(r,{parent:!0}),t=e.node;if(!t)throw new i.ErrnoError(44);var n=C.basename(r),o=i.lookupNode(t,n),a=i.mayDelete(t,n,!1);if(a)throw new i.ErrnoError(a);if(!t.node_ops.unlink)throw new i.ErrnoError(63);if(i.isMountpoint(o))throw new i.ErrnoError(10);t.node_ops.unlink(t,n),i.destroyNode(o)},readlink(r){var e=i.lookupPath(r),t=e.node;if(!t)throw new i.ErrnoError(44);if(!t.node_ops.readlink)throw new i.ErrnoError(28);return Q.resolve(i.getPath(t.parent),t.node_ops.readlink(t))},stat(r,e){var t=i.lookupPath(r,{follow:!e}),n=t.node;if(!n)throw new i.ErrnoError(44);if(!n.node_ops.getattr)throw new i.ErrnoError(63);return n.node_ops.getattr(n)},lstat(r){return i.stat(r,!0)},chmod(r,e,t){var n;if(typeof r=="string"){var o=i.lookupPath(r,{follow:!t});n=o.node}else n=r;if(!n.node_ops.setattr)throw new i.ErrnoError(63);n.node_ops.setattr(n,{mode:e&4095|n.mode&-4096,timestamp:Date.now()})},lchmod(r,e){i.chmod(r,e,!0)},fchmod(r,e){var t=i.getStreamChecked(r);i.chmod(t.node,e)},chown(r,e,t,n){var o;if(typeof r=="string"){var a=i.lookupPath(r,{follow:!n});o=a.node}else o=r;if(!o.node_ops.setattr)throw new i.ErrnoError(63);o.node_ops.setattr(o,{timestamp:Date.now()})},lchown(r,e,t){i.chown(r,e,t,!0)},fchown(r,e,t){var n=i.getStreamChecked(r);i.chown(n.node,e,t)},truncate(r,e){if(e<0)throw new i.ErrnoError(28);var t;if(typeof r=="string"){var n=i.lookupPath(r,{follow:!0});t=n.node}else t=r;if(!t.node_ops.setattr)throw new i.ErrnoError(63);if(i.isDir(t.mode))throw new i.ErrnoError(31);if(!i.isFile(t.mode))throw new i.ErrnoError(28);var o=i.nodePermissions(t,"w");if(o)throw new i.ErrnoError(o);t.node_ops.setattr(t,{size:e,timestamp:Date.now()})},ftruncate(r,e){var t=i.getStreamChecked(r);if(!(t.flags&2097155))throw new i.ErrnoError(28);i.truncate(t.node,e)},utime(r,e,t){var n=i.lookupPath(r,{follow:!0}),o=n.node;o.node_ops.setattr(o,{timestamp:Math.max(e,t)})},open(r,e,t){if(r==="")throw new i.ErrnoError(44);e=typeof e=="string"?Ft(e):e,t=typeof t>"u"?438:t,e&64?t=t&4095|32768:t=0;var n;if(typeof r=="object")n=r;else{r=C.normalize(r);try{var o=i.lookupPath(r,{follow:!(e&131072)});n=o.node}catch{}}var a=!1;if(e&64)if(n){if(e&128)throw new i.ErrnoError(20)}else n=i.mknod(r,t,0),a=!0;if(!n)throw new i.ErrnoError(44);if(i.isChrdev(n.mode)&&(e&=-513),e&65536&&!i.isDir(n.mode))throw new i.ErrnoError(54);if(!a){var s=i.mayOpen(n,e);if(s)throw new i.ErrnoError(s)}e&512&&!a&&i.truncate(n,0),e&=-131713;var u=i.createStream({node:n,path:i.getPath(n),flags:e,seekable:!0,position:0,stream_ops:n.stream_ops,ungotten:[],error:!1});return u.stream_ops.open&&u.stream_ops.open(u),f.logReadFiles&&!(e&1)&&(i.readFiles||(i.readFiles={}),r in i.readFiles||(i.readFiles[r]=1)),u},close(r){if(i.isClosed(r))throw new i.ErrnoError(8);r.getdents&&(r.getdents=null);try{r.stream_ops.close&&r.stream_ops.close(r)}catch(e){throw e}finally{i.closeStream(r.fd)}r.fd=null},isClosed(r){return r.fd===null},llseek(r,e,t){if(i.isClosed(r))throw new i.ErrnoError(8);if(!r.seekable||!r.stream_ops.llseek)throw new i.ErrnoError(70);if(t!=0&&t!=1&&t!=2)throw new i.ErrnoError(28);return r.position=r.stream_ops.llseek(r,e,t),r.ungotten=[],r.position},read(r,e,t,n,o){if(n<0||o<0)throw new i.ErrnoError(28);if(i.isClosed(r))throw new i.ErrnoError(8);if((r.flags&2097155)===1)throw new i.ErrnoError(8);if(i.isDir(r.node.mode))throw new i.ErrnoError(31);if(!r.stream_ops.read)throw new i.ErrnoError(28);var a=typeof o<"u";if(!a)o=r.position;else if(!r.seekable)throw new i.ErrnoError(70);var s=r.stream_ops.read(r,e,t,n,o);return a||(r.position+=s),s},write(r,e,t,n,o,a){if(n<0||o<0)throw new i.ErrnoError(28);if(i.isClosed(r))throw new i.ErrnoError(8);if(!(r.flags&2097155))throw new i.ErrnoError(8);if(i.isDir(r.node.mode))throw new i.ErrnoError(31);if(!r.stream_ops.write)throw new i.ErrnoError(28);r.seekable&&r.flags&1024&&i.llseek(r,0,2);var s=typeof o<"u";if(!s)o=r.position;else if(!r.seekable)throw new i.ErrnoError(70);var u=r.stream_ops.write(r,e,t,n,o,a);return s||(r.position+=u),u},allocate(r,e,t){if(i.isClosed(r))throw new i.ErrnoError(8);if(e<0||t<=0)throw new i.ErrnoError(28);if(!(r.flags&2097155))throw new i.ErrnoError(8);if(!i.isFile(r.node.mode)&&!i.isDir(r.node.mode))throw new i.ErrnoError(43);if(!r.stream_ops.allocate)throw new i.ErrnoError(138);r.stream_ops.allocate(r,e,t)},mmap(r,e,t,n,o){if(n&2&&!(o&2)&&(r.flags&2097155)!==2)throw new i.ErrnoError(2);if((r.flags&2097155)===1)throw new i.ErrnoError(2);if(!r.stream_ops.mmap)throw new i.ErrnoError(43);return r.stream_ops.mmap(r,e,t,n,o)},msync(r,e,t,n,o){return r.stream_ops.msync?r.stream_ops.msync(r,e,t,n,o):0},ioctl(r,e,t){if(!r.stream_ops.ioctl)throw new i.ErrnoError(59);return r.stream_ops.ioctl(r,e,t)},readFile(r,e={}){if(e.flags=e.flags||0,e.encoding=e.encoding||"binary",e.encoding!=="utf8"&&e.encoding!=="binary")throw new Error(`Invalid encoding type "${e.encoding}"`);var t,n=i.open(r,e.flags),o=i.stat(r),a=o.size,s=new Uint8Array(a);return i.read(n,s,0,a,0),e.encoding==="utf8"?t=dr(s,0):e.encoding==="binary"&&(t=s),i.close(n),t},writeFile(r,e,t={}){t.flags=t.flags||577;var n=i.open(r,t.flags,t.mode);if(typeof e=="string"){var o=new Uint8Array(jr(e)+1),a=qr(e,o,0,o.length);i.write(n,o,0,a,void 0,t.canOwn)}else if(ArrayBuffer.isView(e))i.write(n,e,0,e.byteLength,void 0,t.canOwn);else throw new Error("Unsupported data type");i.close(n)},cwd:()=>i.currentPath,chdir(r){var e=i.lookupPath(r,{follow:!0});if(e.node===null)throw new i.ErrnoError(44);if(!i.isDir(e.node.mode))throw new i.ErrnoError(54);var t=i.nodePermissions(e.node,"x");if(t)throw new i.ErrnoError(t);i.currentPath=e.path},createDefaultDirectories(){i.mkdir("/tmp"),i.mkdir("/home"),i.mkdir("/home/web_user")},createDefaultDevices(){i.mkdir("/dev"),i.registerDevice(i.makedev(1,3),{read:()=>0,write:(n,o,a,s,u)=>s}),i.mkdev("/dev/null",i.makedev(1,3)),tr.register(i.makedev(5,0),tr.default_tty_ops),tr.register(i.makedev(6,0),tr.default_tty1_ops),i.mkdev("/dev/tty",i.makedev(5,0)),i.mkdev("/dev/tty1",i.makedev(6,0));var r=new Uint8Array(1024),e=0,t=()=>(e===0&&(e=le(r).byteLength),r[--e]);i.createDevice("/dev","random",t),i.createDevice("/dev","urandom",t),i.mkdir("/dev/shm"),i.mkdir("/dev/shm/tmp")},createSpecialDirectories(){i.mkdir("/proc");var r=i.mkdir("/proc/self");i.mkdir("/proc/self/fd"),i.mount({mount(){var e=i.createNode(r,"fd",16895,73);return e.node_ops={lookup(t,n){var o=+n,a=i.getStreamChecked(o),s={parent:null,mount:{mountpoint:"fake"},node_ops:{readlink:()=>a.path}};return s.parent=s,s}},e}},{},"/proc/self/fd")},createStandardStreams(){f.stdin?i.createDevice("/dev","stdin",f.stdin):i.symlink("/dev/tty","/dev/stdin"),f.stdout?i.createDevice("/dev","stdout",null,f.stdout):i.symlink("/dev/tty","/dev/stdout"),f.stderr?i.createDevice("/dev","stderr",null,f.stderr):i.symlink("/dev/tty1","/dev/stderr");var r=i.open("/dev/stdin",0),e=i.open("/dev/stdout",1),t=i.open("/dev/stderr",1)},staticInit(){[44].forEach(r=>{i.genericErrors[r]=new i.ErrnoError(r),i.genericErrors[r].stack="<generic error, no stack>"}),i.nameTable=new Array(4096),i.mount(b,{},"/"),i.createDefaultDirectories(),i.createDefaultDevices(),i.createSpecialDirectories(),i.filesystems={MEMFS:b}},init(r,e,t){i.init.initialized=!0,f.stdin=r||f.stdin,f.stdout=e||f.stdout,f.stderr=t||f.stderr,i.createStandardStreams()},quit(){i.init.initialized=!1;for(var r=0;r<i.streams.length;r++){var e=i.streams[r];e&&i.close(e)}},findObject(r,e){var t=i.analyzePath(r,e);return t.exists?t.object:null},analyzePath(r,e){try{var t=i.lookupPath(r,{follow:!e});r=t.path}catch{}var n={isRoot:!1,exists:!1,error:0,name:null,path:null,object:null,parentExists:!1,parentPath:null,parentObject:null};try{var t=i.lookupPath(r,{parent:!0});n.parentExists=!0,n.parentPath=t.path,n.parentObject=t.node,n.name=C.basename(r),t=i.lookupPath(r,{follow:!e}),n.exists=!0,n.path=t.path,n.object=t.node,n.name=t.node.name,n.isRoot=t.path==="/"}catch(o){n.error=o.errno}return n},createPath(r,e,t,n){r=typeof r=="string"?r:i.getPath(r);for(var o=e.split("/").reverse();o.length;){var a=o.pop();if(a){var s=C.join2(r,a);try{i.mkdir(s)}catch{}r=s}}return s},createFile(r,e,t,n,o){var a=C.join2(typeof r=="string"?r:i.getPath(r),e),s=Vr(n,o);return i.create(a,s)},createDataFile(r,e,t,n,o,a){var s=e;r&&(r=typeof r=="string"?r:i.getPath(r),s=e?C.join2(r,e):r);var u=Vr(n,o),c=i.create(s,u);if(t){if(typeof t=="string"){for(var d=new Array(t.length),v=0,E=t.length;v<E;++v)d[v]=t.charCodeAt(v);t=d}i.chmod(c,u|146);var h=i.open(c,577);i.write(h,t,0,t.length,0,a),i.close(h),i.chmod(c,u)}},createDevice(r,e,t,n){var o=C.join2(typeof r=="string"?r:i.getPath(r),e),a=Vr(!!t,!!n);i.createDevice.major||(i.createDevice.major=64);var s=i.makedev(i.createDevice.major++,0);return i.registerDevice(s,{open(u){u.seekable=!1},close(u){n?.buffer?.length&&n(10)},read(u,c,d,v,E){for(var h=0,w=0;w<v;w++){var P;try{P=t()}catch{throw new i.ErrnoError(29)}if(P===void 0&&h===0)throw new i.ErrnoError(6);if(P==null)break;h++,c[d+w]=P}return h&&(u.node.timestamp=Date.now()),h},write(u,c,d,v,E){for(var h=0;h<v;h++)try{n(c[d+h])}catch{throw new i.ErrnoError(29)}return v&&(u.node.timestamp=Date.now()),h}}),i.mkdev(o,a,s)},forceLoadFile(r){if(r.isDevice||r.isFolder||r.link||r.contents)return!0;if(typeof XMLHttpRequest<"u")throw new Error("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.");if(Y)try{r.contents=Lr(Y(r.url),!0),r.usedBytes=r.contents.length}catch{throw new i.ErrnoError(29)}else throw new Error("Cannot load without read() or XMLHttpRequest.")},createLazyFile(r,e,t,n,o){class a{constructor(){this.lengthKnown=!1,this.chunks=[]}get(w){if(!(w>this.length-1||w<0)){var P=w%this.chunkSize,j=w/this.chunkSize|0;return this.getter(j)[P]}}setDataGetter(w){this.getter=w}cacheLength(){var w=new XMLHttpRequest;if(w.open("HEAD",t,!1),w.send(null),!(w.status>=200&&w.status<300||w.status===304))throw new Error("Couldn't load "+t+". Status: "+w.status);var P=Number(w.getResponseHeader("Content-length")),j,$=(j=w.getResponseHeader("Accept-Ranges"))&&j==="bytes",L=(j=w.getResponseHeader("Content-Encoding"))&&j==="gzip",l=1024*1024;$||(l=P);var y=(T,V)=>{if(T>V)throw new Error("invalid range ("+T+", "+V+") or no bytes requested!");if(V>P-1)throw new Error("only "+P+" bytes available! programmer error!");var z=new XMLHttpRequest;if(z.open("GET",t,!1),P!==l&&z.setRequestHeader("Range","bytes="+T+"-"+V),z.responseType="arraybuffer",z.overrideMimeType&&z.overrideMimeType("text/plain; charset=x-user-defined"),z.send(null),!(z.status>=200&&z.status<300||z.status===304))throw new Error("Couldn't load "+t+". Status: "+z.status);return z.response!==void 0?new Uint8Array(z.response||[]):Lr(z.responseText||"",!0)},B=this;B.setDataGetter(T=>{var V=T*l,z=(T+1)*l-1;if(z=Math.min(z,P-1),typeof B.chunks[T]>"u"&&(B.chunks[T]=y(V,z)),typeof B.chunks[T]>"u")throw new Error("doXHR failed!");return B.chunks[T]}),(L||!P)&&(l=P=1,P=this.getter(0).length,l=P,_r("LazyFiles on gzip forces download of the whole file when length is accessed")),this._length=P,this._chunkSize=l,this.lengthKnown=!0}get length(){return this.lengthKnown||this.cacheLength(),this._length}get chunkSize(){return this.lengthKnown||this.cacheLength(),this._chunkSize}}if(typeof XMLHttpRequest<"u"){if(!ir)throw"Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc";var s=new a,u={isDevice:!1,contents:s}}else var u={isDevice:!1,url:t};var c=i.createFile(r,e,u,n,o);u.contents?c.contents=u.contents:u.url&&(c.contents=null,c.url=u.url),Object.defineProperties(c,{usedBytes:{get:function(){return this.contents.length}}});var d={},v=Object.keys(c.stream_ops);v.forEach(h=>{var w=c.stream_ops[h];d[h]=(...P)=>(i.forceLoadFile(c),w(...P))});function E(h,w,P,j,$){var L=h.node.contents;if($>=L.length)return 0;var l=Math.min(L.length-$,j);if(L.slice)for(var y=0;y<l;y++)w[P+y]=L[$+y];else for(var y=0;y<l;y++)w[P+y]=L.get($+y);return l}return d.read=(h,w,P,j,$)=>(i.forceLoadFile(c),E(h,w,P,j,$)),d.mmap=(h,w,P,j,$)=>{i.forceLoadFile(c);var L=ve(w);if(!L)throw new i.ErrnoError(48);return E(h,N,L,w,P),{ptr:L,allocated:!0}},c.stream_ops=d,c}},gr=(r,e)=>r?dr(q,r,e):"",D={DEFAULT_POLLMASK:5,calculateAt(r,e,t){if(C.isAbs(e))return e;var n;if(r===-100)n=i.cwd();else{var o=D.getStreamFromFD(r);n=o.path}if(e.length==0){if(!t)throw new i.ErrnoError(44);return n}return C.join2(n,e)},doStat(r,e,t){var n=r(e);k[t>>2]=n.dev,k[t+4>>2]=n.mode,S[t+8>>2]=n.nlink,k[t+12>>2]=n.uid,k[t+16>>2]=n.gid,k[t+20>>2]=n.rdev,O=[n.size>>>0,(A=n.size,+Math.abs(A)>=1?A>0?+Math.floor(A/4294967296)>>>0:~~+Math.ceil((A-+(~~A>>>0))/4294967296)>>>0:0)],k[t+24>>2]=O[0],k[t+28>>2]=O[1],k[t+32>>2]=4096,k[t+36>>2]=n.blocks;var o=n.atime.getTime(),a=n.mtime.getTime(),s=n.ctime.getTime();return O=[Math.floor(o/1e3)>>>0,(A=Math.floor(o/1e3),+Math.abs(A)>=1?A>0?+Math.floor(A/4294967296)>>>0:~~+Math.ceil((A-+(~~A>>>0))/4294967296)>>>0:0)],k[t+40>>2]=O[0],k[t+44>>2]=O[1],S[t+48>>2]=o%1e3*1e3,O=[Math.floor(a/1e3)>>>0,(A=Math.floor(a/1e3),+Math.abs(A)>=1?A>0?+Math.floor(A/4294967296)>>>0:~~+Math.ceil((A-+(~~A>>>0))/4294967296)>>>0:0)],k[t+56>>2]=O[0],k[t+60>>2]=O[1],S[t+64>>2]=a%1e3*1e3,O=[Math.floor(s/1e3)>>>0,(A=Math.floor(s/1e3),+Math.abs(A)>=1?A>0?+Math.floor(A/4294967296)>>>0:~~+Math.ceil((A-+(~~A>>>0))/4294967296)>>>0:0)],k[t+72>>2]=O[0],k[t+76>>2]=O[1],S[t+80>>2]=s%1e3*1e3,O=[n.ino>>>0,(A=n.ino,+Math.abs(A)>=1?A>0?+Math.floor(A/4294967296)>>>0:~~+Math.ceil((A-+(~~A>>>0))/4294967296)>>>0:0)],k[t+88>>2]=O[0],k[t+92>>2]=O[1],0},doMsync(r,e,t,n,o){if(!i.isFile(e.node.mode))throw new i.ErrnoError(43);if(n&2)return 0;var a=q.slice(r,r+t);i.msync(e,a,o,t,n)},varargs:void 0,get(){var r=k[+D.varargs>>2];return D.varargs+=4,r},getp(){return D.get()},getStr(r){var e=gr(r);return e},getStreamFromFD(r){var e=i.getStreamChecked(r);return e}};function Pt(r){try{return r=D.getStr(r),i.chdir(r),0}catch(e){if(typeof i>"u"||e.name!=="ErrnoError")throw e;return-e.errno}}function Mt(r,e,t,n){try{if(e=D.getStr(e),e=D.calculateAt(r,e),t&-8)return-28;var o=i.lookupPath(e,{follow:!0}),a=o.node;if(!a)return-44;var s="";return t&4&&(s+="r"),t&2&&(s+="w"),t&1&&(s+="x"),s&&i.nodePermissions(a,s)?-2:0}catch(u){if(typeof i>"u"||u.name!=="ErrnoError")throw u;return-u.errno}}function Dt(r,e,t){D.varargs=t;try{var n=D.getStreamFromFD(r);switch(e){case 0:{var o=D.get();if(o<0)return-28;for(;i.streams[o];)o++;var a;return a=i.dupStream(n,o),a.fd}case 1:case 2:return 0;case 3:return n.flags;case 4:{var o=D.get();return n.flags|=o,0}case 12:{var o=D.getp(),s=0;return J[o+s>>1]=2,0}case 13:case 14:return 0}return-28}catch(u){if(typeof i>"u"||u.name!=="ErrnoError")throw u;return-u.errno}}function At(r,e){try{var t=D.getStreamFromFD(r);return D.doStat(i.stat,t.path,e)}catch(n){if(typeof i>"u"||n.name!=="ErrnoError")throw n;return-n.errno}}var he=(r,e,t)=>qr(r,q,e,t);function Rt(r,e){try{if(e===0)return-28;var t=i.cwd(),n=jr(t)+1;return e<n?-68:(he(t,r,e),n)}catch(o){if(typeof i>"u"||o.name!=="ErrnoError")throw o;return-o.errno}}function Ct(r,e,t){D.varargs=t;try{var n=D.getStreamFromFD(r);switch(e){case 21509:return n.tty?0:-59;case 21505:{if(!n.tty)return-59;if(n.tty.ops.ioctl_tcgets){var o=n.tty.ops.ioctl_tcgets(n),a=D.getp();k[a>>2]=o.c_iflag||0,k[a+4>>2]=o.c_oflag||0,k[a+8>>2]=o.c_cflag||0,k[a+12>>2]=o.c_lflag||0;for(var s=0;s<32;s++)N[a+s+17]=o.c_cc[s]||0;return 0}return 0}case 21510:case 21511:case 21512:return n.tty?0:-59;case 21506:case 21507:case 21508:{if(!n.tty)return-59;if(n.tty.ops.ioctl_tcsets){for(var a=D.getp(),u=k[a>>2],c=k[a+4>>2],d=k[a+8>>2],v=k[a+12>>2],E=[],s=0;s<32;s++)E.push(N[a+s+17]);return n.tty.ops.ioctl_tcsets(n.tty,e,{c_iflag:u,c_oflag:c,c_cflag:d,c_lflag:v,c_cc:E})}return 0}case 21519:{if(!n.tty)return-59;var a=D.getp();return k[a>>2]=0,0}case 21520:return n.tty?-28:-59;case 21531:{var a=D.getp();return i.ioctl(n,e,a)}case 21523:{if(!n.tty)return-59;if(n.tty.ops.ioctl_tiocgwinsz){var h=n.tty.ops.ioctl_tiocgwinsz(n.tty),a=D.getp();J[a>>1]=h[0],J[a+2>>1]=h[1]}return 0}case 21524:return n.tty?0:-59;case 21515:return n.tty?0:-59;default:return-28}}catch(w){if(typeof i>"u"||w.name!=="ErrnoError")throw w;return-w.errno}}function xt(r,e,t,n){try{e=D.getStr(e);var o=n&256,a=n&4096;return n=n&-6401,e=D.calculateAt(r,e,a),D.doStat(o?i.lstat:i.stat,e,t)}catch(s){if(typeof i>"u"||s.name!=="ErrnoError")throw s;return-s.errno}}function Tt(r,e,t,n){D.varargs=n;try{e=D.getStr(e),e=D.calculateAt(r,e);var o=n?D.get():0;return i.open(e,t,o).fd}catch(a){if(typeof i>"u"||a.name!=="ErrnoError")throw a;return-a.errno}}function It(r,e){try{return r=D.getStr(r),D.doStat(i.stat,r,e)}catch(t){if(typeof i>"u"||t.name!=="ErrnoError")throw t;return-t.errno}}var Nt=1,jt=()=>Nt,Lt=()=>{ce=!1,pe=0},zt=()=>{throw 1/0},Gr=(r,e)=>e+2097152>>>0<4194305-!!r?(r>>>0)+e*4294967296:NaN;function Ut(r,e,t,n,o,a,s,u){var c=Gr(o,a);try{if(isNaN(c))return 61;var d=D.getStreamFromFD(n),v=i.mmap(d,r,c,e,t),E=v.ptr;return k[s>>2]=v.allocated,S[u>>2]=E,0}catch(h){if(typeof i>"u"||h.name!=="ErrnoError")throw h;return-h.errno}}function Ot(r,e,t,n,o,a,s){var u=Gr(a,s);try{var c=D.getStreamFromFD(o);t&2&&D.doMsync(r,c,e,n,u)}catch(d){if(typeof i>"u"||d.name!=="ErrnoError")throw d;return-d.errno}}var Bt=()=>{Rr("")},Ht=()=>Date.now(),me=()=>2147483648,Wt=()=>me(),_e;_e=()=>performance.now();var Yt=(r,e,t)=>q.copyWithin(r,e,e+t),$t=r=>{var e=fr.buffer,t=(r-e.byteLength+65535)/65536;try{return fr.grow(t),ee(),1}catch{}},Xt=r=>{var e=q.length;r>>>=0;var t=me();if(r>t)return!1;for(var n=(c,d)=>c+(d-c%d)%d,o=1;o<=4;o*=2){var a=e*(1+.2/o);a=Math.min(a,r+100663296);var s=Math.min(t,n(Math.max(r,a),65536)),u=$t(s);if(u)return!0}return!1},Kr={},qt=()=>G||"./this.program",Er=()=>{if(!Er.strings){var r=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",e={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:r,_:qt()};for(var t in Kr)Kr[t]===void 0?delete e[t]:e[t]=Kr[t];var n=[];for(var t in e)n.push(`${t}=${e[t]}`);Er.strings=n}return Er.strings},Vt=(r,e)=>{for(var t=0;t<r.length;++t)N[e++]=r.charCodeAt(t);N[e]=0},Gt=(r,e)=>{var t=0;return Er().forEach((n,o)=>{var a=e+t;S[r+o*4>>2]=a,Vt(n,a),t+=n.length+1}),0},Kt=(r,e)=>{var t=Er();S[r>>2]=t.length;var n=0;return t.forEach(o=>n+=o.length+1),S[e>>2]=n,0},pe=0,Jt=()=>ce||pe>0,we=r=>{or=r,Jt()||(f.onExit?.(r),lr=!0),W(r,new ue(r))},ye=(r,e)=>{or=r,we(r)},Zt=ye;function Qt(r){try{var e=D.getStreamFromFD(r);return i.close(e),0}catch(t){if(typeof i>"u"||t.name!=="ErrnoError")throw t;return t.errno}}var rn=(r,e,t,n)=>{for(var o=0,a=0;a<t;a++){var s=S[e>>2],u=S[e+4>>2];e+=8;var c=i.read(r,N,s,u,n);if(c<0)return-1;if(o+=c,c<u)break;typeof n<"u"&&(n+=c)}return o};function en(r,e,t,n){try{var o=D.getStreamFromFD(r),a=rn(o,e,t);return S[n>>2]=a,0}catch(s){if(typeof i>"u"||s.name!=="ErrnoError")throw s;return s.errno}}function tn(r,e,t,n,o){var a=Gr(e,t);try{if(isNaN(a))return 61;var s=D.getStreamFromFD(r);return i.llseek(s,a,n),O=[s.position>>>0,(A=s.position,+Math.abs(A)>=1?A>0?+Math.floor(A/4294967296)>>>0:~~+Math.ceil((A-+(~~A>>>0))/4294967296)>>>0:0)],k[o>>2]=O[0],k[o+4>>2]=O[1],s.getdents&&a===0&&n===0&&(s.getdents=null),0}catch(u){if(typeof i>"u"||u.name!=="ErrnoError")throw u;return u.errno}}var nn=(r,e,t,n)=>{for(var o=0,a=0;a<t;a++){var s=S[e>>2],u=S[e+4>>2];e+=8;var c=i.write(r,N,s,u,n);if(c<0)return-1;o+=c,typeof n<"u"&&(n+=c)}return o};function on(r,e,t,n){try{var o=D.getStreamFromFD(r),a=nn(o,e,t);return S[n>>2]=a,0}catch(s){if(typeof i>"u"||s.name!=="ErrnoError")throw s;return s.errno}}var an=r=>r,zr=r=>r%4===0&&(r%100!==0||r%400===0),sn=(r,e)=>{for(var t=0,n=0;n<=e;t+=r[n++]);return t},ge=[31,29,31,30,31,30,31,31,30,31,30,31],Ee=[31,28,31,30,31,30,31,31,30,31,30,31],un=(r,e)=>{for(var t=new Date(r.getTime());e>0;){var n=zr(t.getFullYear()),o=t.getMonth(),a=(n?ge:Ee)[o];if(e>a-t.getDate())e-=a-t.getDate()+1,t.setDate(1),o<11?t.setMonth(o+1):(t.setMonth(0),t.setFullYear(t.getFullYear()+1));else return t.setDate(t.getDate()+e),t}return t},cn=(r,e)=>{N.set(r,e)},fn=(r,e,t,n)=>{var o=S[n+40>>2],a={tm_sec:k[n>>2],tm_min:k[n+4>>2],tm_hour:k[n+8>>2],tm_mday:k[n+12>>2],tm_mon:k[n+16>>2],tm_year:k[n+20>>2],tm_wday:k[n+24>>2],tm_yday:k[n+28>>2],tm_isdst:k[n+32>>2],tm_gmtoff:k[n+36>>2],tm_zone:o?gr(o):""},s=gr(t),u={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"};for(var c in u)s=s.replace(new RegExp(c,"g"),u[c]);var d=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],v=["January","February","March","April","May","June","July","August","September","October","November","December"];function E(l,y,B){for(var T=typeof l=="number"?l.toString():l||"";T.length<y;)T=B[0]+T;return T}function h(l,y){return E(l,y,"0")}function w(l,y){function B(V){return V<0?-1:V>0?1:0}var T;return(T=B(l.getFullYear()-y.getFullYear()))===0&&(T=B(l.getMonth()-y.getMonth()))===0&&(T=B(l.getDate()-y.getDate())),T}function P(l){switch(l.getDay()){case 0:return new Date(l.getFullYear()-1,11,29);case 1:return l;case 2:return new Date(l.getFullYear(),0,3);case 3:return new Date(l.getFullYear(),0,2);case 4:return new Date(l.getFullYear(),0,1);case 5:return new Date(l.getFullYear()-1,11,31);case 6:return new Date(l.getFullYear()-1,11,30)}}function j(l){var y=un(new Date(l.tm_year+1900,0,1),l.tm_yday),B=new Date(y.getFullYear(),0,4),T=new Date(y.getFullYear()+1,0,4),V=P(B),z=P(T);return w(V,y)<=0?w(z,y)<=0?y.getFullYear()+1:y.getFullYear():y.getFullYear()-1}var $={"%a":l=>d[l.tm_wday].substring(0,3),"%A":l=>d[l.tm_wday],"%b":l=>v[l.tm_mon].substring(0,3),"%B":l=>v[l.tm_mon],"%C":l=>{var y=l.tm_year+1900;return h(y/100|0,2)},"%d":l=>h(l.tm_mday,2),"%e":l=>E(l.tm_mday,2," "),"%g":l=>j(l).toString().substring(2),"%G":j,"%H":l=>h(l.tm_hour,2),"%I":l=>{var y=l.tm_hour;return y==0?y=12:y>12&&(y-=12),h(y,2)},"%j":l=>h(l.tm_mday+sn(zr(l.tm_year+1900)?ge:Ee,l.tm_mon-1),3),"%m":l=>h(l.tm_mon+1,2),"%M":l=>h(l.tm_min,2),"%n":()=>`
|
|
4
|
-
`,"%p":l=>l.tm_hour>=0&&l.tm_hour<12?"AM":"PM","%S":l=>h(l.tm_sec,2),"%t":()=>" ","%u":l=>l.tm_wday||7,"%U":l=>{var y=l.tm_yday+7-l.tm_wday;return h(Math.floor(y/7),2)},"%V":l=>{var y=Math.floor((l.tm_yday+7-(l.tm_wday+6)%7)/7);if((l.tm_wday+371-l.tm_yday-2)%7<=2&&y++,y){if(y==53){var T=(l.tm_wday+371-l.tm_yday)%7;T!=4&&(T!=3||!zr(l.tm_year))&&(y=1)}}else{y=52;var B=(l.tm_wday+7-l.tm_yday-1)%7;(B==4||B==5&&zr(l.tm_year%400-1))&&y++}return h(y,2)},"%w":l=>l.tm_wday,"%W":l=>{var y=l.tm_yday+7-(l.tm_wday+6)%7;return h(Math.floor(y/7),2)},"%y":l=>(l.tm_year+1900).toString().substring(2),"%Y":l=>l.tm_year+1900,"%z":l=>{var y=l.tm_gmtoff,B=y>=0;return y=Math.abs(y)/60,y=y/60*100+y%60,(B?"+":"-")+("0000"+y).slice(-4)},"%Z":l=>l.tm_zone,"%%":()=>"%"};s=s.replace(/%%/g,"\0\0");for(var c in $)s.includes(c)&&(s=s.replace(new RegExp(c,"g"),$[c](a)));s=s.replace(/\0\0/g,"%");var L=Lr(s,!1);return L.length>e?0:(cn(L,r),L.length-1)},ln=(r,e,t,n,o)=>fn(r,e,t,n),dn=r=>{if(r instanceof ue||r=="unwind")return or;W(1,r)},vn=r=>{var e=jr(r)+1,t=Sr(e);return he(r,t,e),t},hn=r=>{var e=_(),t=r();return p(e),t},mn=r=>hn(()=>{var e=Sr(4),t=Sr(4);be(r,e,t);var n=S[e>>2],o=S[t>>2],a=gr(n);Jr(n);var s;return o&&(s=gr(o),Jr(o)),[a,s]}),_n=r=>mn(r),pn=r=>Qr(r),wn=r=>Zr(r);i.createPreloadedFile=bt,i.staticInit(),f.FS_createPath=i.createPath,f.FS_createDataFile=i.createDataFile,f.FS_createPreloadedFile=i.createPreloadedFile,f.FS_unlink=i.unlink,f.FS_createLazyFile=i.createLazyFile,f.FS_createDevice=i.createDevice;var yn={ka:ot,l:at,t:st,a:ct,h:ft,E:lt,Pa:dt,P:vt,r:ht,ga:mt,d:ut,xa:Pt,ya:Mt,T:Dt,sa:At,pa:Rt,za:Ct,qa:xt,Q:Tt,ra:It,ua:jt,ma:Lt,ha:zt,aa:Ut,ba:Ot,q:Bt,va:Ht,ja:Wt,ta:_e,wa:Yt,ia:Xt,na:Gt,oa:Kt,L:Zt,M:Qt,S:en,ca:tn,R:on,s:An,z:Zn,K:Gn,O:pi,v:Fn,g:Sn,n:Un,b:kn,y:Kn,Na:Yn,e:xn,C:ni,G:Jn,Oa:Wn,p:zn,U:_i,Ma:$n,Da:ci,N:ii,w:Mn,Z:ai,Fa:oi,Ka:qn,A:Nn,La:Xn,Ea:ui,x:On,Qa:Hn,Ja:Vn,J:wi,Y:si,$:ki,_:Si,j:jn,i:bn,D:Qn,Ba:hi,Ca:vi,Ga:ti,c:Dn,Aa:mi,Ha:ei,Ia:ri,f:Rn,k:Tn,W:li,u:Pn,V:di,X:fi,B:Cn,o:In,H:Bn,F:Ln,I:yi,da:Ei,ea:gi,m:an,la:we,fa:ln},I=it(),gn=()=>(gn=I.Sa)(),ke=f._main=(r,e)=>(ke=f._main=I.Ta)(r,e),Jr=r=>(Jr=I.Va)(r),En=r=>(En=I.__cxa_free_exception)(r),kr=r=>(kr=I.Wa)(r),Se=(r,e)=>(Se=I.Xa)(r,e),m=(r,e)=>(m=I.Ya)(r,e),_=()=>(_=I.Za)(),p=r=>(p=I._a)(r),Sr=r=>(Sr=I.$a)(r),Zr=r=>(Zr=I.ab)(r),Qr=r=>(Qr=I.bb)(r),be=(r,e,t)=>(be=I.cb)(r,e,t),Fe=(r,e,t)=>(Fe=I.db)(r,e,t),Pe=r=>(Pe=I.eb)(r),Me=f.dynCall_vij=(r,e,t,n)=>(Me=f.dynCall_vij=I.fb)(r,e,t,n),De=f.dynCall_j=r=>(De=f.dynCall_j=I.gb)(r),Ae=f.dynCall_viijii=(r,e,t,n,o,a,s)=>(Ae=f.dynCall_viijii=I.hb)(r,e,t,n,o,a,s),Re=f.dynCall_jiiii=(r,e,t,n,o)=>(Re=f.dynCall_jiiii=I.ib)(r,e,t,n,o);function kn(r,e,t){var n=_();try{return g(r)(e,t)}catch(o){if(p(n),o!==o+0)throw o;m(1,0)}}function Sn(r,e){var t=_();try{return g(r)(e)}catch(n){if(p(t),n!==n+0)throw n;m(1,0)}}function bn(r,e){var t=_();try{g(r)(e)}catch(n){if(p(t),n!==n+0)throw n;m(1,0)}}function Fn(r){var e=_();try{return g(r)()}catch(t){if(p(e),t!==t+0)throw t;m(1,0)}}function Pn(r,e,t,n,o,a){var s=_();try{g(r)(e,t,n,o,a)}catch(u){if(p(s),u!==u+0)throw u;m(1,0)}}function Mn(r,e,t,n,o,a){var s=_();try{return g(r)(e,t,n,o,a)}catch(u){if(p(s),u!==u+0)throw u;m(1,0)}}function Dn(r,e,t){var n=_();try{g(r)(e,t)}catch(o){if(p(n),o!==o+0)throw o;m(1,0)}}function An(r,e){var t=_();try{return g(r)(e)}catch(n){if(p(t),n!==n+0)throw n;m(1,0)}}function Rn(r,e,t,n){var o=_();try{g(r)(e,t,n)}catch(a){if(p(o),a!==a+0)throw a;m(1,0)}}function Cn(r,e,t,n,o,a,s){var u=_();try{g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function xn(r,e,t,n){var o=_();try{return g(r)(e,t,n)}catch(a){if(p(o),a!==a+0)throw a;m(1,0)}}function Tn(r,e,t,n,o){var a=_();try{g(r)(e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}function In(r,e,t,n,o,a,s,u){var c=_();try{g(r)(e,t,n,o,a,s,u)}catch(d){if(p(c),d!==d+0)throw d;m(1,0)}}function Nn(r,e,t,n,o,a,s){var u=_();try{return g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function jn(r){var e=_();try{g(r)()}catch(t){if(p(e),t!==t+0)throw t;m(1,0)}}function Ln(r,e,t,n,o,a,s,u,c,d,v){var E=_();try{g(r)(e,t,n,o,a,s,u,c,d,v)}catch(h){if(p(E),h!==h+0)throw h;m(1,0)}}function zn(r,e,t,n,o){var a=_();try{return g(r)(e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}function Un(r,e,t){var n=_();try{return g(r)(e,t)}catch(o){if(p(n),o!==o+0)throw o;m(1,0)}}function On(r,e,t,n,o,a,s,u){var c=_();try{return g(r)(e,t,n,o,a,s,u)}catch(d){if(p(c),d!==d+0)throw d;m(1,0)}}function Bn(r,e,t,n,o,a,s,u,c){var d=_();try{g(r)(e,t,n,o,a,s,u,c)}catch(v){if(p(d),v!==v+0)throw v;m(1,0)}}function Hn(r,e,t,n,o,a,s,u,c,d){var v=_();try{return g(r)(e,t,n,o,a,s,u,c,d)}catch(E){if(p(v),E!==E+0)throw E;m(1,0)}}function Wn(r,e,t,n,o,a,s,u){var c=_();try{return g(r)(e,t,n,o,a,s,u)}catch(d){if(p(c),d!==d+0)throw d;m(1,0)}}function Yn(r,e,t,n,o,a){var s=_();try{return g(r)(e,t,n,o,a)}catch(u){if(p(s),u!==u+0)throw u;m(1,0)}}function $n(r,e,t,n,o,a,s){var u=_();try{return g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function Xn(r,e,t,n,o,a,s,u,c){var d=_();try{return g(r)(e,t,n,o,a,s,u,c)}catch(v){if(p(d),v!==v+0)throw v;m(1,0)}}function qn(r,e,t,n,o,a,s,u,c){var d=_();try{return g(r)(e,t,n,o,a,s,u,c)}catch(v){if(p(d),v!==v+0)throw v;m(1,0)}}function Vn(r,e,t,n,o,a,s,u,c,d,v){var E=_();try{return g(r)(e,t,n,o,a,s,u,c,d,v)}catch(h){if(p(E),h!==h+0)throw h;m(1,0)}}function Gn(r,e,t,n){var o=_();try{return g(r)(e,t,n)}catch(a){if(p(o),a!==a+0)throw a;m(1,0)}}function Kn(r,e,t,n){var o=_();try{return g(r)(e,t,n)}catch(a){if(p(o),a!==a+0)throw a;m(1,0)}}function Jn(r,e,t,n,o,a){var s=_();try{return g(r)(e,t,n,o,a)}catch(u){if(p(s),u!==u+0)throw u;m(1,0)}}function Zn(r,e,t){var n=_();try{return g(r)(e,t)}catch(o){if(p(n),o!==o+0)throw o;m(1,0)}}function Qn(r,e,t){var n=_();try{g(r)(e,t)}catch(o){if(p(n),o!==o+0)throw o;m(1,0)}}function ri(r,e,t,n,o,a){var s=_();try{g(r)(e,t,n,o,a)}catch(u){if(p(s),u!==u+0)throw u;m(1,0)}}function ei(r,e,t,n,o){var a=_();try{g(r)(e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}function ti(r,e,t,n,o,a,s,u,c){var d=_();try{g(r)(e,t,n,o,a,s,u,c)}catch(v){if(p(d),v!==v+0)throw v;m(1,0)}}function ni(r,e,t,n,o){var a=_();try{return g(r)(e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}function ii(r,e,t,n,o,a,s){var u=_();try{return g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function oi(r,e,t,n,o,a,s,u){var c=_();try{return g(r)(e,t,n,o,a,s,u)}catch(d){if(p(c),d!==d+0)throw d;m(1,0)}}function ai(r,e,t,n,o,a,s){var u=_();try{return g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function si(r,e,t,n,o,a,s,u,c,d,v,E,h){var w=_();try{return g(r)(e,t,n,o,a,s,u,c,d,v,E,h)}catch(P){if(p(w),P!==P+0)throw P;m(1,0)}}function ui(r,e,t,n,o,a,s,u,c,d,v){var E=_();try{return g(r)(e,t,n,o,a,s,u,c,d,v)}catch(h){if(p(E),h!==h+0)throw h;m(1,0)}}function ci(r,e,t,n,o,a,s,u){var c=_();try{return g(r)(e,t,n,o,a,s,u)}catch(d){if(p(c),d!==d+0)throw d;m(1,0)}}function fi(r,e,t,n,o,a,s,u,c,d){var v=_();try{g(r)(e,t,n,o,a,s,u,c,d)}catch(E){if(p(v),E!==E+0)throw E;m(1,0)}}function li(r,e,t,n,o,a,s){var u=_();try{g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function di(r,e,t,n,o,a,s,u,c){var d=_();try{g(r)(e,t,n,o,a,s,u,c)}catch(v){if(p(d),v!==v+0)throw v;m(1,0)}}function vi(r,e,t,n,o,a,s){var u=_();try{g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function hi(r,e,t,n,o){var a=_();try{g(r)(e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}function mi(r,e,t,n,o){var a=_();try{g(r)(e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}function _i(r,e,t,n,o,a){var s=_();try{return g(r)(e,t,n,o,a)}catch(u){if(p(s),u!==u+0)throw u;m(1,0)}}function pi(r,e,t,n){var o=_();try{return g(r)(e,t,n)}catch(a){if(p(o),a!==a+0)throw a;m(1,0)}}function wi(r,e,t,n,o,a,s,u,c,d,v,E){var h=_();try{return g(r)(e,t,n,o,a,s,u,c,d,v,E)}catch(w){if(p(h),w!==w+0)throw w;m(1,0)}}function yi(r,e,t,n,o,a,s,u,c,d,v,E,h,w,P,j){var $=_();try{g(r)(e,t,n,o,a,s,u,c,d,v,E,h,w,P,j)}catch(L){if(p($),L!==L+0)throw L;m(1,0)}}function gi(r,e,t,n){var o=_();try{Me(r,e,t,n)}catch(a){if(p(o),a!==a+0)throw a;m(1,0)}}function Ei(r,e,t,n,o,a,s){var u=_();try{Ae(r,e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function ki(r){var e=_();try{return De(r)}catch(t){if(p(e),t!==t+0)throw t;m(1,0)}}function Si(r,e,t,n,o){var a=_();try{return Re(r,e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}f.addRunDependency=Ar,f.removeRunDependency=yr,f.FS_createPath=i.createPath,f.FS_createLazyFile=i.createLazyFile,f.FS_createDevice=i.createDevice,f.callMain=Ce,f.incrementExceptionRefcount=pn,f.decrementExceptionRefcount=wn,f.getExceptionMessage=_n,f.FS_createPreloadedFile=i.createPreloadedFile,f.FS=i,f.FS_createDataFile=i.createDataFile,f.FS_unlink=i.unlink;var Ur;wr=function r(){Ur||xe(),Ur||(wr=r)};function Ce(r=[]){var e=ke;r.unshift(G);var t=r.length,n=Sr((t+1)*4),o=n;r.forEach(s=>{S[o>>2]=vn(s),o+=4}),S[o>>2]=0;try{var a=e(t,n);return ye(a,!0),a}catch(s){return dn(s)}}function xe(r=rr){if(ar>0||(Ve(),ar>0))return;function e(){Ur||(Ur=!0,f.calledRun=!0,!lr&&(Ge(),Ke(),H(f),f.onRuntimeInitialized&&f.onRuntimeInitialized(),Te&&Ce(r),Je()))}f.setStatus?(f.setStatus("Running..."),setTimeout(function(){setTimeout(function(){f.setStatus("")},1),e()},1)):e()}if(f.preInit)for(typeof f.preInit=="function"&&(f.preInit=[f.preInit]);f.preInit.length>0;)f.preInit.pop()();var Te=!1;return f.noInitialRun&&(Te=!1),xe(),R.ready}})(),x=null,vr=!1,Fr=null,Or=null,hr=null,Br=null,Hr=null,je=new Promise(function(F,R){Or=F,hr=R}),nr={OPTIMAL:"optimal",INFEASIBLE:"infeasible",UNBOUNDED:"unbounded",TIME_LIMIT:"timelimit",UNKNOWN:"unknown",ERROR:"error"};function Le(F){return F.includes("optimal solution found")?nr.OPTIMAL:F.includes("problem is infeasible")?nr.INFEASIBLE:F.includes("problem is unbounded")?nr.UNBOUNDED:F.includes("time limit reached")?nr.TIME_LIMIT:nr.UNKNOWN}function ze(F){var R={},f={value:null},H=F.match(/objective value:\s*([\d.e+-]+)/i);H&&(f.value=parseFloat(H[1]));for(var M=/^(\w+)\s+([\d.e+-]+)/gm,U,rr=F.split("solution:")[1]||F;(U=M.exec(rr))!==null;){var G=U[1],W=parseFloat(U[2]);!isNaN(W)&&G!=="objective"&&(R[G]=W)}return{variables:R,objective:f}}function Ue(F){var R={solvingTime:null,nodes:null,iterations:null,gap:null},f=F.match(/Solving Time \(sec\)\s*:\s*([\d.]+)/);f&&(R.solvingTime=parseFloat(f[1]));var H=F.match(/Nodes\s*:\s*(\d+)/);H&&(R.nodes=parseInt(H[1]));var M=F.match(/LP Iterations\s*:\s*(\d+)/);M&&(R.iterations=parseInt(M[1]));var U=F.match(/Gap\s*:\s*([\d.]+)\s*%/);return U&&(R.gap=parseFloat(U[1])),R}function Pr(F){return F=F||{},vr?Promise.resolve():Fr||(Fr=new Promise(function(R,f){try{var H=F.wasmPath||br+"scip.wasm";console.log("[SCIP.js] __SCIP_SCRIPT_DIR__:",br),console.log("[SCIP.js] Loading WASM from:",H),fetch(H,{method:"HEAD"}).then(function(M){console.log("[SCIP.js] WASM file check:",M.ok?"OK":"FAILED",M.status)}).catch(function(M){console.error("[SCIP.js] WASM file check failed:",M)}),Ne({locateFile:function(M){return M.endsWith(".wasm")?(console.log("[SCIP.js] locateFile called for:",M,"-> returning:",H),H):M},print:function(M){x&&x.onStdout&&x.onStdout(M)},printErr:function(M){x&&x.onStderr&&x.onStderr(M)},onAbort:function(M){Br=M,console.error("[SCIP WASM Abort]",M)},onExit:function(M){Hr=M,M!==0&&console.error("[SCIP WASM Exit]",M)}}).then(function(M){if(console.log("[SCIP.js] WASM loaded successfully"),x=M,x.FS){try{x.FS.mkdir("/problems")}catch{}try{x.FS.mkdir("/solutions")}catch{}try{x.FS.mkdir("/settings")}catch{}}vr=!0,Or&&Or(),R()}).catch(function(M){console.error("[SCIP.js] WASM loading failed:",M),console.error("[SCIP.js] Attempted WASM path:",H),console.error("[SCIP.js] Make sure the WASM file is accessible at this URL."),console.error("[SCIP.js] You can set window.SCIP_BASE_URL before loading this script to specify a custom path.");var U=new Error("SCIP WASM loading failed: "+(M.message||M)+". WASM path: "+H);hr&&hr(U),f(U)})}catch(M){console.error("[SCIP.js] Initialization error:",M),hr&&hr(M),f(M)}}),Fr)}function Wr(F,R){R=R||{};var f=function(){var H=R.format||"lp",M=R.timeLimit||3600,U=R.gap||null,rr=R.verbose||!1,G=R.parameters||{},W="",ur="";x.onStdout=function(S){W+=S+`
|
|
5
|
-
`,rr&&console.log("[SCIP]",S)},x.onStderr=function(S){ur+=S+`
|
|
6
|
-
`,rr&&console.error("[SCIP Error]",S)};try{var ir={mps:"mps",zpl:"zpl",cip:"cip",lp:"lp"},re=ir[H]||"lp",X="/problems/problem."+re,Mr="/solutions/solution.sol";x.FS.writeFile(X,F);var Y=[];Y.push("set limits time "+M),U!==null&&Y.push("set limits gap "+U);for(var cr in G)G.hasOwnProperty(cr)&&Y.push("set "+cr+" "+G[cr]);Y.push("read "+X),Y.push("optimize"),Y.push("display solution"),Y.push("write solution "+Mr),Y.push("display statistics"),Y.push("quit");var mr=Y.join(`
|
|
7
|
-
`);x.FS.writeFile("/settings/commands.txt",mr);var _r=x.callMain(["-b","/settings/commands.txt"]),K=Le(W),er=ze(W),fr=Ue(W),lr=null;try{lr=x.FS.readFile(Mr,{encoding:"utf8"})}catch{}for(var or=["/problems/problem.lp","/problems/problem.mps","/problems/problem.zpl","/problems/problem.cip","/solutions/solution.sol","/settings/commands.txt"],N=0;N<or.length;N++)try{x.FS.unlink(or[N])}catch{}return{status:K,objective:er.objective.value,variables:er.variables,statistics:fr,exitCode:_r,output:rr?W:void 0,rawSolution:lr}}catch(S){var q=S.message||String(S),J=null;if(typeof S=="number"||/^\d+$/.test(String(S))){var pr=typeof S=="number"?S:parseInt(String(S),10);if(x)try{if(typeof x.getExceptionMessage=="function")J=x.getExceptionMessage(pr),q="WASM Exception: "+J;else if(typeof x.UTF8ToString=="function")try{var k=x.UTF8ToString(pr);k&&k.length>0&&k.length<1e3&&(J=k,q="WASM Exception: "+k)}catch{}}catch(Dr){console.error("[SCIP] Failed to get exception message:",Dr)}J||(q="WASM Exception (ptr: "+pr+"). Enable exception handling in build for details.")}return{status:nr.ERROR,error:q,errorDetails:{rawError:String(S),exceptionInfo:J,abortReason:Br,exitCode:Hr,type:typeof S,stdout:W,stderr:ur},output:W+ur}}Br=null,Hr=null};return vr?Promise.resolve(f()):Pr(R).then(f)}function Oe(F,R){return F.toLowerCase().includes("minimize")||(F=`Minimize
|
|
8
|
-
`+F),Wr(F,R)}function Be(F,R){return F.toLowerCase().includes("maximize")||(F=`Maximize
|
|
9
|
-
`+F),Wr(F,R)}function He(){var F=function(){var R="";return x.onStdout=function(f){R+=f+`
|
|
10
|
-
`},x.callMain(["--version"]),R.trim()};return vr?Promise.resolve(F()):Pr().then(F)}function We(){return vr}var Ye={init:Pr,ready:je,isReady:We,solve:Wr,minimize:Oe,maximize:Be,version:He,Status:nr};Ie.SCIP=Ye,Pr().catch(function(F){console.error("[SCIP.js] Auto-initialization failed:",F.message)})})(typeof self<"u"?self:typeof window<"u"?window:globalThis);
|
|
1
|
+
(function(Ie){"use strict";var br=function(){if(typeof SCIP_BASE_URL<"u"&&SCIP_BASE_URL)return SCIP_BASE_URL+(SCIP_BASE_URL.endsWith("/")?"":"/");if(typeof document<"u"&&document.currentScript&&document.currentScript.src){var F=document.currentScript.src;return F.substring(0,F.lastIndexOf("/")+1)}return"https://cdn.jsdelivr.net/npm/@areb0s/scip.js@1.1.6/dist/"}(),Ne=(()=>{var F=br;return function(R={}){var f=R,H,M;f.ready=new Promise((r,e)=>{H=r,M=e});var U=Object.assign({},f),rr=[],G="./this.program",W=(r,e)=>{throw e},ur=typeof window=="object",ir=typeof importScripts=="function",re=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string",X="";function Mr(r){return f.locateFile?f.locateFile(r,X):X+r}var Y,cr,mr;(ur||ir)&&(ir?X=self.location.href:typeof document<"u"&&document.currentScript&&(X=document.currentScript.src),F&&(X=F),X.startsWith("blob:")?X="":X=X.substr(0,X.replace(/[?#].*/,"").lastIndexOf("/")+1),Y=r=>{var e=new XMLHttpRequest;return e.open("GET",r,!1),e.send(null),e.responseText},ir&&(mr=r=>{var e=new XMLHttpRequest;return e.open("GET",r,!1),e.responseType="arraybuffer",e.send(null),new Uint8Array(e.response)}),cr=(r,e,t)=>{var n=new XMLHttpRequest;n.open("GET",r,!0),n.responseType="arraybuffer",n.onload=()=>{if(n.status==200||n.status==0&&n.response){e(n.response);return}t()},n.onerror=t,n.send(null)});var _r=f.print||console.log.bind(console),K=f.printErr||console.error.bind(console);Object.assign(f,U),U=null,f.arguments&&(rr=f.arguments),f.thisProgram&&(G=f.thisProgram),f.quit&&(W=f.quit);var er;f.wasmBinary&&(er=f.wasmBinary);var fr,lr=!1,or,N,q,J,pr,k,S,Dr,$e;function ee(){var r=fr.buffer;f.HEAP8=N=new Int8Array(r),f.HEAP16=J=new Int16Array(r),f.HEAPU8=q=new Uint8Array(r),f.HEAPU16=pr=new Uint16Array(r),f.HEAP32=k=new Int32Array(r),f.HEAPU32=S=new Uint32Array(r),f.HEAPF32=Dr=new Float32Array(r),f.HEAPF64=$e=new Float64Array(r)}var te=[],ne=[],Xe=[],ie=[],qe=!1;function Ve(){if(f.preRun)for(typeof f.preRun=="function"&&(f.preRun=[f.preRun]);f.preRun.length;)Ze(f.preRun.shift());Cr(te)}function Ge(){qe=!0,!f.noFSInit&&!i.init.initialized&&i.init(),i.ignorePermissions=!1,tr.init(),Cr(ne)}function Ke(){Cr(Xe)}function Je(){if(f.postRun)for(typeof f.postRun=="function"&&(f.postRun=[f.postRun]);f.postRun.length;)rt(f.postRun.shift());Cr(ie)}function Ze(r){te.unshift(r)}function Qe(r){ne.unshift(r)}function rt(r){ie.unshift(r)}var ar=0,Yr=null,wr=null;function bi(r){return r}function Ar(r){ar++,f.monitorRunDependencies?.(ar)}function yr(r){if(ar--,f.monitorRunDependencies?.(ar),ar==0&&(Yr!==null&&(clearInterval(Yr),Yr=null),wr)){var e=wr;wr=null,e()}}function Rr(r){f.onAbort?.(r),r="Aborted("+r+")",K(r),lr=!0,or=1,r+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(r);throw M(e),e}var et="data:application/octet-stream;base64,",oe=r=>r.startsWith(et),sr;f.locateFile?(sr="scip.wasm",oe(sr)||(sr=Mr(sr))):sr=new URL("scip.wasm",br).href;function ae(r){if(r==sr&&er)return new Uint8Array(er);if(mr)return mr(r);throw"both async and sync fetching of the wasm failed"}function tt(r){return!er&&(ur||ir)&&typeof fetch=="function"?fetch(r,{credentials:"same-origin"}).then(e=>{if(!e.ok)throw`failed to load wasm binary file at '${r}'`;return e.arrayBuffer()}).catch(()=>ae(r)):Promise.resolve().then(()=>ae(r))}function se(r,e,t){return tt(r).then(n=>WebAssembly.instantiate(n,e)).then(t,n=>{K(`failed to asynchronously prepare wasm: ${n}`),Rr(n)})}function nt(r,e,t,n){return!r&&typeof WebAssembly.instantiateStreaming=="function"&&!oe(e)&&typeof fetch=="function"?fetch(e,{credentials:"same-origin"}).then(o=>{var a=WebAssembly.instantiateStreaming(o,t);return a.then(n,function(s){return K(`wasm streaming compile failed: ${s}`),K("falling back to ArrayBuffer instantiation"),se(e,t,n)})}):se(e,t,n)}function it(){var r={a:yn};function e(n,o){return I=n.exports,fr=I.Ra,ee(),fe=I.Ua,Qe(I.Sa),yr("wasm-instantiate"),I}Ar("wasm-instantiate");function t(n){e(n.instance)}if(f.instantiateWasm)try{return f.instantiateWasm(r,e)}catch(n){K(`Module.instantiateWasm callback failed with error: ${n}`),M(n)}return nt(er,sr,r,t).catch(M),{}}var A,O;function ue(r){this.name="ExitStatus",this.message=`Program terminated with exit(${r})`,this.status=r}var Cr=r=>{for(;r.length>0;)r.shift()(f)},ce=f.noExitRuntime||!0,xr=[],fe,g=r=>{var e=xr[r];return e||(r>=xr.length&&(xr.length=r+1),xr[r]=e=fe.get(r)),e},ot=(r,e)=>g(r)(e),Tr=[],Ir=0,at=r=>{var e=new $r(r);return e.get_caught()||(e.set_caught(!0),Ir--),e.set_rethrown(!1),Tr.push(e),Qr(e.excPtr),e.get_exception_ptr()},Z=0,st=()=>{m(0,0);var r=Tr.pop();Zr(r.excPtr),Z=0};class $r{constructor(e){this.excPtr=e,this.ptr=e-24}set_type(e){S[this.ptr+4>>2]=e}get_type(){return S[this.ptr+4>>2]}set_destructor(e){S[this.ptr+8>>2]=e}get_destructor(){return S[this.ptr+8>>2]}set_caught(e){e=e?1:0,N[this.ptr+12]=e}get_caught(){return N[this.ptr+12]!=0}set_rethrown(e){e=e?1:0,N[this.ptr+13]=e}get_rethrown(){return N[this.ptr+13]!=0}init(e,t){this.set_adjusted_ptr(0),this.set_type(e),this.set_destructor(t)}set_adjusted_ptr(e){S[this.ptr+16>>2]=e}get_adjusted_ptr(){return S[this.ptr+16>>2]}get_exception_ptr(){var e=Pe(this.get_type());if(e)return S[this.excPtr>>2];var t=this.get_adjusted_ptr();return t!==0?t:this.excPtr}}var ut=r=>{throw Z||(Z=r),Z},Nr=r=>{var e=Z;if(!e)return kr(0),0;var t=new $r(e);t.set_adjusted_ptr(e);var n=t.get_type();if(!n)return kr(0),e;for(var o in r){var a=r[o];if(a===0||a===n)break;var s=t.ptr+16;if(Fe(a,n,s))return kr(a),e}return kr(n),e},ct=()=>Nr([]),ft=r=>Nr([r]),lt=(r,e)=>Nr([r,e]),dt=(r,e,t,n,o)=>Nr([r,e,t,n,o]),vt=()=>{var r=Tr.pop();r||Rr("no exception to throw");var e=r.excPtr;throw r.get_rethrown()||(Tr.push(r),r.set_rethrown(!0),r.set_caught(!1),Ir++),Z=e,Z},ht=(r,e,t)=>{var n=new $r(r);throw n.init(e,t),Z=r,Ir++,Z},mt=()=>Ir,C={isAbs:r=>r.charAt(0)==="/",splitPath:r=>{var e=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;return e.exec(r).slice(1)},normalizeArray:(r,e)=>{for(var t=0,n=r.length-1;n>=0;n--){var o=r[n];o==="."?r.splice(n,1):o===".."?(r.splice(n,1),t++):t&&(r.splice(n,1),t--)}if(e)for(;t;t--)r.unshift("..");return r},normalize:r=>{var e=C.isAbs(r),t=r.substr(-1)==="/";return r=C.normalizeArray(r.split("/").filter(n=>!!n),!e).join("/"),!r&&!e&&(r="."),r&&t&&(r+="/"),(e?"/":"")+r},dirname:r=>{var e=C.splitPath(r),t=e[0],n=e[1];return!t&&!n?".":(n&&(n=n.substr(0,n.length-1)),t+n)},basename:r=>{if(r==="/")return"/";r=C.normalize(r),r=r.replace(/\/$/,"");var e=r.lastIndexOf("/");return e===-1?r:r.substr(e+1)},join:(...r)=>C.normalize(r.join("/")),join2:(r,e)=>C.normalize(r+"/"+e)},_t=()=>{if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function")return r=>crypto.getRandomValues(r);Rr("initRandomDevice")},le=r=>(le=_t())(r),Q={resolve:(...r)=>{for(var e="",t=!1,n=r.length-1;n>=-1&&!t;n--){var o=n>=0?r[n]:i.cwd();if(typeof o!="string")throw new TypeError("Arguments to path.resolve must be strings");if(!o)return"";e=o+"/"+e,t=C.isAbs(o)}return e=C.normalizeArray(e.split("/").filter(a=>!!a),!t).join("/"),(t?"/":"")+e||"."},relative:(r,e)=>{r=Q.resolve(r).substr(1),e=Q.resolve(e).substr(1);function t(d){for(var v=0;v<d.length&&d[v]==="";v++);for(var E=d.length-1;E>=0&&d[E]==="";E--);return v>E?[]:d.slice(v,E-v+1)}for(var n=t(r.split("/")),o=t(e.split("/")),a=Math.min(n.length,o.length),s=a,u=0;u<a;u++)if(n[u]!==o[u]){s=u;break}for(var c=[],u=s;u<n.length;u++)c.push("..");return c=c.concat(o.slice(s)),c.join("/")}},de=typeof TextDecoder<"u"?new TextDecoder("utf8"):void 0,dr=(r,e,t)=>{for(var n=e+t,o=e;r[o]&&!(o>=n);)++o;if(o-e>16&&r.buffer&&de)return de.decode(r.subarray(e,o));for(var a="";e<o;){var s=r[e++];if(!(s&128)){a+=String.fromCharCode(s);continue}var u=r[e++]&63;if((s&224)==192){a+=String.fromCharCode((s&31)<<6|u);continue}var c=r[e++]&63;if((s&240)==224?s=(s&15)<<12|u<<6|c:s=(s&7)<<18|u<<12|c<<6|r[e++]&63,s<65536)a+=String.fromCharCode(s);else{var d=s-65536;a+=String.fromCharCode(55296|d>>10,56320|d&1023)}}return a},Xr=[],jr=r=>{for(var e=0,t=0;t<r.length;++t){var n=r.charCodeAt(t);n<=127?e++:n<=2047?e+=2:n>=55296&&n<=57343?(e+=4,++t):e+=3}return e},qr=(r,e,t,n)=>{if(!(n>0))return 0;for(var o=t,a=t+n-1,s=0;s<r.length;++s){var u=r.charCodeAt(s);if(u>=55296&&u<=57343){var c=r.charCodeAt(++s);u=65536+((u&1023)<<10)|c&1023}if(u<=127){if(t>=a)break;e[t++]=u}else if(u<=2047){if(t+1>=a)break;e[t++]=192|u>>6,e[t++]=128|u&63}else if(u<=65535){if(t+2>=a)break;e[t++]=224|u>>12,e[t++]=128|u>>6&63,e[t++]=128|u&63}else{if(t+3>=a)break;e[t++]=240|u>>18,e[t++]=128|u>>12&63,e[t++]=128|u>>6&63,e[t++]=128|u&63}}return e[t]=0,t-o};function Lr(r,e,t){var n=t>0?t:jr(r)+1,o=new Array(n),a=qr(r,o,0,o.length);return e&&(o.length=a),o}var pt=()=>{if(!Xr.length){var r=null;if(typeof window<"u"&&typeof window.prompt=="function"?(r=window.prompt("Input: "),r!==null&&(r+=`
|
|
2
|
+
`)):typeof readline=="function"&&(r=readline(),r!==null&&(r+=`
|
|
3
|
+
`)),!r)return null;Xr=Lr(r,!0)}return Xr.shift()},tr={ttys:[],init(){},shutdown(){},register(r,e){tr.ttys[r]={input:[],output:[],ops:e},i.registerDevice(r,tr.stream_ops)},stream_ops:{open(r){var e=tr.ttys[r.node.rdev];if(!e)throw new i.ErrnoError(43);r.tty=e,r.seekable=!1},close(r){r.tty.ops.fsync(r.tty)},fsync(r){r.tty.ops.fsync(r.tty)},read(r,e,t,n,o){if(!r.tty||!r.tty.ops.get_char)throw new i.ErrnoError(60);for(var a=0,s=0;s<n;s++){var u;try{u=r.tty.ops.get_char(r.tty)}catch{throw new i.ErrnoError(29)}if(u===void 0&&a===0)throw new i.ErrnoError(6);if(u==null)break;a++,e[t+s]=u}return a&&(r.node.timestamp=Date.now()),a},write(r,e,t,n,o){if(!r.tty||!r.tty.ops.put_char)throw new i.ErrnoError(60);try{for(var a=0;a<n;a++)r.tty.ops.put_char(r.tty,e[t+a])}catch{throw new i.ErrnoError(29)}return n&&(r.node.timestamp=Date.now()),a}},default_tty_ops:{get_char(r){return pt()},put_char(r,e){e===null||e===10?(_r(dr(r.output,0)),r.output=[]):e!=0&&r.output.push(e)},fsync(r){r.output&&r.output.length>0&&(_r(dr(r.output,0)),r.output=[])},ioctl_tcgets(r){return{c_iflag:25856,c_oflag:5,c_cflag:191,c_lflag:35387,c_cc:[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},ioctl_tcsets(r,e,t){return 0},ioctl_tiocgwinsz(r){return[24,80]}},default_tty1_ops:{put_char(r,e){e===null||e===10?(K(dr(r.output,0)),r.output=[]):e!=0&&r.output.push(e)},fsync(r){r.output&&r.output.length>0&&(K(dr(r.output,0)),r.output=[])}}},wt=(r,e)=>(q.fill(0,r,r+e),r),yt=(r,e)=>Math.ceil(r/e)*e,ve=r=>{r=yt(r,65536);var e=Se(65536,r);return e?wt(e,r):0},b={ops_table:null,mount(r){return b.createNode(null,"/",16895,0)},createNode(r,e,t,n){if(i.isBlkdev(t)||i.isFIFO(t))throw new i.ErrnoError(63);b.ops_table||(b.ops_table={dir:{node:{getattr:b.node_ops.getattr,setattr:b.node_ops.setattr,lookup:b.node_ops.lookup,mknod:b.node_ops.mknod,rename:b.node_ops.rename,unlink:b.node_ops.unlink,rmdir:b.node_ops.rmdir,readdir:b.node_ops.readdir,symlink:b.node_ops.symlink},stream:{llseek:b.stream_ops.llseek}},file:{node:{getattr:b.node_ops.getattr,setattr:b.node_ops.setattr},stream:{llseek:b.stream_ops.llseek,read:b.stream_ops.read,write:b.stream_ops.write,allocate:b.stream_ops.allocate,mmap:b.stream_ops.mmap,msync:b.stream_ops.msync}},link:{node:{getattr:b.node_ops.getattr,setattr:b.node_ops.setattr,readlink:b.node_ops.readlink},stream:{}},chrdev:{node:{getattr:b.node_ops.getattr,setattr:b.node_ops.setattr},stream:i.chrdev_stream_ops}});var o=i.createNode(r,e,t,n);return i.isDir(o.mode)?(o.node_ops=b.ops_table.dir.node,o.stream_ops=b.ops_table.dir.stream,o.contents={}):i.isFile(o.mode)?(o.node_ops=b.ops_table.file.node,o.stream_ops=b.ops_table.file.stream,o.usedBytes=0,o.contents=null):i.isLink(o.mode)?(o.node_ops=b.ops_table.link.node,o.stream_ops=b.ops_table.link.stream):i.isChrdev(o.mode)&&(o.node_ops=b.ops_table.chrdev.node,o.stream_ops=b.ops_table.chrdev.stream),o.timestamp=Date.now(),r&&(r.contents[e]=o,r.timestamp=o.timestamp),o},getFileDataAsTypedArray(r){return r.contents?r.contents.subarray?r.contents.subarray(0,r.usedBytes):new Uint8Array(r.contents):new Uint8Array(0)},expandFileStorage(r,e){var t=r.contents?r.contents.length:0;if(!(t>=e)){var n=1024*1024;e=Math.max(e,t*(t<n?2:1.125)>>>0),t!=0&&(e=Math.max(e,256));var o=r.contents;r.contents=new Uint8Array(e),r.usedBytes>0&&r.contents.set(o.subarray(0,r.usedBytes),0)}},resizeFileStorage(r,e){if(r.usedBytes!=e)if(e==0)r.contents=null,r.usedBytes=0;else{var t=r.contents;r.contents=new Uint8Array(e),t&&r.contents.set(t.subarray(0,Math.min(e,r.usedBytes))),r.usedBytes=e}},node_ops:{getattr(r){var e={};return e.dev=i.isChrdev(r.mode)?r.id:1,e.ino=r.id,e.mode=r.mode,e.nlink=1,e.uid=0,e.gid=0,e.rdev=r.rdev,i.isDir(r.mode)?e.size=4096:i.isFile(r.mode)?e.size=r.usedBytes:i.isLink(r.mode)?e.size=r.link.length:e.size=0,e.atime=new Date(r.timestamp),e.mtime=new Date(r.timestamp),e.ctime=new Date(r.timestamp),e.blksize=4096,e.blocks=Math.ceil(e.size/e.blksize),e},setattr(r,e){e.mode!==void 0&&(r.mode=e.mode),e.timestamp!==void 0&&(r.timestamp=e.timestamp),e.size!==void 0&&b.resizeFileStorage(r,e.size)},lookup(r,e){throw i.genericErrors[44]},mknod(r,e,t,n){return b.createNode(r,e,t,n)},rename(r,e,t){if(i.isDir(r.mode)){var n;try{n=i.lookupNode(e,t)}catch{}if(n)for(var o in n.contents)throw new i.ErrnoError(55)}delete r.parent.contents[r.name],r.parent.timestamp=Date.now(),r.name=t,e.contents[t]=r,e.timestamp=r.parent.timestamp,r.parent=e},unlink(r,e){delete r.contents[e],r.timestamp=Date.now()},rmdir(r,e){var t=i.lookupNode(r,e);for(var n in t.contents)throw new i.ErrnoError(55);delete r.contents[e],r.timestamp=Date.now()},readdir(r){var e=[".",".."];for(var t of Object.keys(r.contents))e.push(t);return e},symlink(r,e,t){var n=b.createNode(r,e,41471,0);return n.link=t,n},readlink(r){if(!i.isLink(r.mode))throw new i.ErrnoError(28);return r.link}},stream_ops:{read(r,e,t,n,o){var a=r.node.contents;if(o>=r.node.usedBytes)return 0;var s=Math.min(r.node.usedBytes-o,n);if(s>8&&a.subarray)e.set(a.subarray(o,o+s),t);else for(var u=0;u<s;u++)e[t+u]=a[o+u];return s},write(r,e,t,n,o,a){if(e.buffer===N.buffer&&(a=!1),!n)return 0;var s=r.node;if(s.timestamp=Date.now(),e.subarray&&(!s.contents||s.contents.subarray)){if(a)return s.contents=e.subarray(t,t+n),s.usedBytes=n,n;if(s.usedBytes===0&&o===0)return s.contents=e.slice(t,t+n),s.usedBytes=n,n;if(o+n<=s.usedBytes)return s.contents.set(e.subarray(t,t+n),o),n}if(b.expandFileStorage(s,o+n),s.contents.subarray&&e.subarray)s.contents.set(e.subarray(t,t+n),o);else for(var u=0;u<n;u++)s.contents[o+u]=e[t+u];return s.usedBytes=Math.max(s.usedBytes,o+n),n},llseek(r,e,t){var n=e;if(t===1?n+=r.position:t===2&&i.isFile(r.node.mode)&&(n+=r.node.usedBytes),n<0)throw new i.ErrnoError(28);return n},allocate(r,e,t){b.expandFileStorage(r.node,e+t),r.node.usedBytes=Math.max(r.node.usedBytes,e+t)},mmap(r,e,t,n,o){if(!i.isFile(r.node.mode))throw new i.ErrnoError(43);var a,s,u=r.node.contents;if(!(o&2)&&u.buffer===N.buffer)s=!1,a=u.byteOffset;else{if((t>0||t+e<u.length)&&(u.subarray?u=u.subarray(t,t+e):u=Array.prototype.slice.call(u,t,t+e)),s=!0,a=ve(e),!a)throw new i.ErrnoError(48);N.set(u,a)}return{ptr:a,allocated:s}},msync(r,e,t,n,o){return b.stream_ops.write(r,e,0,n,t,!1),0}}},gt=(r,e,t,n)=>{var o=n?"":`al ${r}`;cr(r,a=>{e(new Uint8Array(a)),o&&yr(o)},a=>{if(t)t();else throw`Loading data file "${r}" failed.`}),o&&Ar(o)},Et=(r,e,t,n,o,a)=>{i.createDataFile(r,e,t,n,o,a)},kt=f.preloadPlugins||[],St=(r,e,t,n)=>{typeof Browser<"u"&&Browser.init();var o=!1;return kt.forEach(a=>{o||a.canHandle(e)&&(a.handle(r,e,t,n),o=!0)}),o},bt=(r,e,t,n,o,a,s,u,c,d)=>{var v=e?Q.resolve(C.join2(r,e)):r,E=`cp ${v}`;function h(w){function P(j){d?.(),u||Et(r,e,j,n,o,c),a?.(),yr(E)}St(w,v,P,()=>{s?.(),yr(E)})||P(w)}Ar(E),typeof t=="string"?gt(t,h,s):h(t)},Ft=r=>{var e={r:0,"r+":2,w:577,"w+":578,a:1089,"a+":1090},t=e[r];if(typeof t>"u")throw new Error(`Unknown file open mode: ${r}`);return t},Vr=(r,e)=>{var t=0;return r&&(t|=365),e&&(t|=146),t},i={root:null,mounts:[],devices:{},streams:[],nextInode:1,nameTable:null,currentPath:"/",initialized:!1,ignorePermissions:!0,ErrnoError:class{constructor(r){this.name="ErrnoError",this.errno=r}},genericErrors:{},filesystems:null,syncFSRequests:0,FSStream:class{constructor(){this.shared={}}get object(){return this.node}set object(r){this.node=r}get isRead(){return(this.flags&2097155)!==1}get isWrite(){return(this.flags&2097155)!==0}get isAppend(){return this.flags&1024}get flags(){return this.shared.flags}set flags(r){this.shared.flags=r}get position(){return this.shared.position}set position(r){this.shared.position=r}},FSNode:class{constructor(r,e,t,n){r||(r=this),this.parent=r,this.mount=r.mount,this.mounted=null,this.id=i.nextInode++,this.name=e,this.mode=t,this.node_ops={},this.stream_ops={},this.rdev=n,this.readMode=365,this.writeMode=146}get read(){return(this.mode&this.readMode)===this.readMode}set read(r){r?this.mode|=this.readMode:this.mode&=~this.readMode}get write(){return(this.mode&this.writeMode)===this.writeMode}set write(r){r?this.mode|=this.writeMode:this.mode&=~this.writeMode}get isFolder(){return i.isDir(this.mode)}get isDevice(){return i.isChrdev(this.mode)}},lookupPath(r,e={}){if(r=Q.resolve(r),!r)return{path:"",node:null};var t={follow_mount:!0,recurse_count:0};if(e=Object.assign(t,e),e.recurse_count>8)throw new i.ErrnoError(32);for(var n=r.split("/").filter(E=>!!E),o=i.root,a="/",s=0;s<n.length;s++){var u=s===n.length-1;if(u&&e.parent)break;if(o=i.lookupNode(o,n[s]),a=C.join2(a,n[s]),i.isMountpoint(o)&&(!u||u&&e.follow_mount)&&(o=o.mounted.root),!u||e.follow)for(var c=0;i.isLink(o.mode);){var d=i.readlink(a);a=Q.resolve(C.dirname(a),d);var v=i.lookupPath(a,{recurse_count:e.recurse_count+1});if(o=v.node,c++>40)throw new i.ErrnoError(32)}}return{path:a,node:o}},getPath(r){for(var e;;){if(i.isRoot(r)){var t=r.mount.mountpoint;return e?t[t.length-1]!=="/"?`${t}/${e}`:t+e:t}e=e?`${r.name}/${e}`:r.name,r=r.parent}},hashName(r,e){for(var t=0,n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return(r+t>>>0)%i.nameTable.length},hashAddNode(r){var e=i.hashName(r.parent.id,r.name);r.name_next=i.nameTable[e],i.nameTable[e]=r},hashRemoveNode(r){var e=i.hashName(r.parent.id,r.name);if(i.nameTable[e]===r)i.nameTable[e]=r.name_next;else for(var t=i.nameTable[e];t;){if(t.name_next===r){t.name_next=r.name_next;break}t=t.name_next}},lookupNode(r,e){var t=i.mayLookup(r);if(t)throw new i.ErrnoError(t);for(var n=i.hashName(r.id,e),o=i.nameTable[n];o;o=o.name_next){var a=o.name;if(o.parent.id===r.id&&a===e)return o}return i.lookup(r,e)},createNode(r,e,t,n){var o=new i.FSNode(r,e,t,n);return i.hashAddNode(o),o},destroyNode(r){i.hashRemoveNode(r)},isRoot(r){return r===r.parent},isMountpoint(r){return!!r.mounted},isFile(r){return(r&61440)===32768},isDir(r){return(r&61440)===16384},isLink(r){return(r&61440)===40960},isChrdev(r){return(r&61440)===8192},isBlkdev(r){return(r&61440)===24576},isFIFO(r){return(r&61440)===4096},isSocket(r){return(r&49152)===49152},flagsToPermissionString(r){var e=["r","w","rw"][r&3];return r&512&&(e+="w"),e},nodePermissions(r,e){return i.ignorePermissions?0:e.includes("r")&&!(r.mode&292)||e.includes("w")&&!(r.mode&146)||e.includes("x")&&!(r.mode&73)?2:0},mayLookup(r){if(!i.isDir(r.mode))return 54;var e=i.nodePermissions(r,"x");return e||(r.node_ops.lookup?0:2)},mayCreate(r,e){try{var t=i.lookupNode(r,e);return 20}catch{}return i.nodePermissions(r,"wx")},mayDelete(r,e,t){var n;try{n=i.lookupNode(r,e)}catch(a){return a.errno}var o=i.nodePermissions(r,"wx");if(o)return o;if(t){if(!i.isDir(n.mode))return 54;if(i.isRoot(n)||i.getPath(n)===i.cwd())return 10}else if(i.isDir(n.mode))return 31;return 0},mayOpen(r,e){return r?i.isLink(r.mode)?32:i.isDir(r.mode)&&(i.flagsToPermissionString(e)!=="r"||e&512)?31:i.nodePermissions(r,i.flagsToPermissionString(e)):44},MAX_OPEN_FDS:4096,nextfd(){for(var r=0;r<=i.MAX_OPEN_FDS;r++)if(!i.streams[r])return r;throw new i.ErrnoError(33)},getStreamChecked(r){var e=i.getStream(r);if(!e)throw new i.ErrnoError(8);return e},getStream:r=>i.streams[r],createStream(r,e=-1){return r=Object.assign(new i.FSStream,r),e==-1&&(e=i.nextfd()),r.fd=e,i.streams[e]=r,r},closeStream(r){i.streams[r]=null},dupStream(r,e=-1){var t=i.createStream(r,e);return t.stream_ops?.dup?.(t),t},chrdev_stream_ops:{open(r){var e=i.getDevice(r.node.rdev);r.stream_ops=e.stream_ops,r.stream_ops.open?.(r)},llseek(){throw new i.ErrnoError(70)}},major:r=>r>>8,minor:r=>r&255,makedev:(r,e)=>r<<8|e,registerDevice(r,e){i.devices[r]={stream_ops:e}},getDevice:r=>i.devices[r],getMounts(r){for(var e=[],t=[r];t.length;){var n=t.pop();e.push(n),t.push(...n.mounts)}return e},syncfs(r,e){typeof r=="function"&&(e=r,r=!1),i.syncFSRequests++,i.syncFSRequests>1&&K(`warning: ${i.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);var t=i.getMounts(i.root.mount),n=0;function o(s){return i.syncFSRequests--,e(s)}function a(s){if(s)return a.errored?void 0:(a.errored=!0,o(s));++n>=t.length&&o(null)}t.forEach(s=>{if(!s.type.syncfs)return a(null);s.type.syncfs(s,r,a)})},mount(r,e,t){var n=t==="/",o=!t,a;if(n&&i.root)throw new i.ErrnoError(10);if(!n&&!o){var s=i.lookupPath(t,{follow_mount:!1});if(t=s.path,a=s.node,i.isMountpoint(a))throw new i.ErrnoError(10);if(!i.isDir(a.mode))throw new i.ErrnoError(54)}var u={type:r,opts:e,mountpoint:t,mounts:[]},c=r.mount(u);return c.mount=u,u.root=c,n?i.root=c:a&&(a.mounted=u,a.mount&&a.mount.mounts.push(u)),c},unmount(r){var e=i.lookupPath(r,{follow_mount:!1});if(!i.isMountpoint(e.node))throw new i.ErrnoError(28);var t=e.node,n=t.mounted,o=i.getMounts(n);Object.keys(i.nameTable).forEach(s=>{for(var u=i.nameTable[s];u;){var c=u.name_next;o.includes(u.mount)&&i.destroyNode(u),u=c}}),t.mounted=null;var a=t.mount.mounts.indexOf(n);t.mount.mounts.splice(a,1)},lookup(r,e){return r.node_ops.lookup(r,e)},mknod(r,e,t){var n=i.lookupPath(r,{parent:!0}),o=n.node,a=C.basename(r);if(!a||a==="."||a==="..")throw new i.ErrnoError(28);var s=i.mayCreate(o,a);if(s)throw new i.ErrnoError(s);if(!o.node_ops.mknod)throw new i.ErrnoError(63);return o.node_ops.mknod(o,a,e,t)},create(r,e){return e=e!==void 0?e:438,e&=4095,e|=32768,i.mknod(r,e,0)},mkdir(r,e){return e=e!==void 0?e:511,e&=1023,e|=16384,i.mknod(r,e,0)},mkdirTree(r,e){for(var t=r.split("/"),n="",o=0;o<t.length;++o)if(t[o]){n+="/"+t[o];try{i.mkdir(n,e)}catch(a){if(a.errno!=20)throw a}}},mkdev(r,e,t){return typeof t>"u"&&(t=e,e=438),e|=8192,i.mknod(r,e,t)},symlink(r,e){if(!Q.resolve(r))throw new i.ErrnoError(44);var t=i.lookupPath(e,{parent:!0}),n=t.node;if(!n)throw new i.ErrnoError(44);var o=C.basename(e),a=i.mayCreate(n,o);if(a)throw new i.ErrnoError(a);if(!n.node_ops.symlink)throw new i.ErrnoError(63);return n.node_ops.symlink(n,o,r)},rename(r,e){var t=C.dirname(r),n=C.dirname(e),o=C.basename(r),a=C.basename(e),s,u,c;if(s=i.lookupPath(r,{parent:!0}),u=s.node,s=i.lookupPath(e,{parent:!0}),c=s.node,!u||!c)throw new i.ErrnoError(44);if(u.mount!==c.mount)throw new i.ErrnoError(75);var d=i.lookupNode(u,o),v=Q.relative(r,n);if(v.charAt(0)!==".")throw new i.ErrnoError(28);if(v=Q.relative(e,t),v.charAt(0)!==".")throw new i.ErrnoError(55);var E;try{E=i.lookupNode(c,a)}catch{}if(d!==E){var h=i.isDir(d.mode),w=i.mayDelete(u,o,h);if(w)throw new i.ErrnoError(w);if(w=E?i.mayDelete(c,a,h):i.mayCreate(c,a),w)throw new i.ErrnoError(w);if(!u.node_ops.rename)throw new i.ErrnoError(63);if(i.isMountpoint(d)||E&&i.isMountpoint(E))throw new i.ErrnoError(10);if(c!==u&&(w=i.nodePermissions(u,"w"),w))throw new i.ErrnoError(w);i.hashRemoveNode(d);try{u.node_ops.rename(d,c,a)}catch(P){throw P}finally{i.hashAddNode(d)}}},rmdir(r){var e=i.lookupPath(r,{parent:!0}),t=e.node,n=C.basename(r),o=i.lookupNode(t,n),a=i.mayDelete(t,n,!0);if(a)throw new i.ErrnoError(a);if(!t.node_ops.rmdir)throw new i.ErrnoError(63);if(i.isMountpoint(o))throw new i.ErrnoError(10);t.node_ops.rmdir(t,n),i.destroyNode(o)},readdir(r){var e=i.lookupPath(r,{follow:!0}),t=e.node;if(!t.node_ops.readdir)throw new i.ErrnoError(54);return t.node_ops.readdir(t)},unlink(r){var e=i.lookupPath(r,{parent:!0}),t=e.node;if(!t)throw new i.ErrnoError(44);var n=C.basename(r),o=i.lookupNode(t,n),a=i.mayDelete(t,n,!1);if(a)throw new i.ErrnoError(a);if(!t.node_ops.unlink)throw new i.ErrnoError(63);if(i.isMountpoint(o))throw new i.ErrnoError(10);t.node_ops.unlink(t,n),i.destroyNode(o)},readlink(r){var e=i.lookupPath(r),t=e.node;if(!t)throw new i.ErrnoError(44);if(!t.node_ops.readlink)throw new i.ErrnoError(28);return Q.resolve(i.getPath(t.parent),t.node_ops.readlink(t))},stat(r,e){var t=i.lookupPath(r,{follow:!e}),n=t.node;if(!n)throw new i.ErrnoError(44);if(!n.node_ops.getattr)throw new i.ErrnoError(63);return n.node_ops.getattr(n)},lstat(r){return i.stat(r,!0)},chmod(r,e,t){var n;if(typeof r=="string"){var o=i.lookupPath(r,{follow:!t});n=o.node}else n=r;if(!n.node_ops.setattr)throw new i.ErrnoError(63);n.node_ops.setattr(n,{mode:e&4095|n.mode&-4096,timestamp:Date.now()})},lchmod(r,e){i.chmod(r,e,!0)},fchmod(r,e){var t=i.getStreamChecked(r);i.chmod(t.node,e)},chown(r,e,t,n){var o;if(typeof r=="string"){var a=i.lookupPath(r,{follow:!n});o=a.node}else o=r;if(!o.node_ops.setattr)throw new i.ErrnoError(63);o.node_ops.setattr(o,{timestamp:Date.now()})},lchown(r,e,t){i.chown(r,e,t,!0)},fchown(r,e,t){var n=i.getStreamChecked(r);i.chown(n.node,e,t)},truncate(r,e){if(e<0)throw new i.ErrnoError(28);var t;if(typeof r=="string"){var n=i.lookupPath(r,{follow:!0});t=n.node}else t=r;if(!t.node_ops.setattr)throw new i.ErrnoError(63);if(i.isDir(t.mode))throw new i.ErrnoError(31);if(!i.isFile(t.mode))throw new i.ErrnoError(28);var o=i.nodePermissions(t,"w");if(o)throw new i.ErrnoError(o);t.node_ops.setattr(t,{size:e,timestamp:Date.now()})},ftruncate(r,e){var t=i.getStreamChecked(r);if(!(t.flags&2097155))throw new i.ErrnoError(28);i.truncate(t.node,e)},utime(r,e,t){var n=i.lookupPath(r,{follow:!0}),o=n.node;o.node_ops.setattr(o,{timestamp:Math.max(e,t)})},open(r,e,t){if(r==="")throw new i.ErrnoError(44);e=typeof e=="string"?Ft(e):e,t=typeof t>"u"?438:t,e&64?t=t&4095|32768:t=0;var n;if(typeof r=="object")n=r;else{r=C.normalize(r);try{var o=i.lookupPath(r,{follow:!(e&131072)});n=o.node}catch{}}var a=!1;if(e&64)if(n){if(e&128)throw new i.ErrnoError(20)}else n=i.mknod(r,t,0),a=!0;if(!n)throw new i.ErrnoError(44);if(i.isChrdev(n.mode)&&(e&=-513),e&65536&&!i.isDir(n.mode))throw new i.ErrnoError(54);if(!a){var s=i.mayOpen(n,e);if(s)throw new i.ErrnoError(s)}e&512&&!a&&i.truncate(n,0),e&=-131713;var u=i.createStream({node:n,path:i.getPath(n),flags:e,seekable:!0,position:0,stream_ops:n.stream_ops,ungotten:[],error:!1});return u.stream_ops.open&&u.stream_ops.open(u),f.logReadFiles&&!(e&1)&&(i.readFiles||(i.readFiles={}),r in i.readFiles||(i.readFiles[r]=1)),u},close(r){if(i.isClosed(r))throw new i.ErrnoError(8);r.getdents&&(r.getdents=null);try{r.stream_ops.close&&r.stream_ops.close(r)}catch(e){throw e}finally{i.closeStream(r.fd)}r.fd=null},isClosed(r){return r.fd===null},llseek(r,e,t){if(i.isClosed(r))throw new i.ErrnoError(8);if(!r.seekable||!r.stream_ops.llseek)throw new i.ErrnoError(70);if(t!=0&&t!=1&&t!=2)throw new i.ErrnoError(28);return r.position=r.stream_ops.llseek(r,e,t),r.ungotten=[],r.position},read(r,e,t,n,o){if(n<0||o<0)throw new i.ErrnoError(28);if(i.isClosed(r))throw new i.ErrnoError(8);if((r.flags&2097155)===1)throw new i.ErrnoError(8);if(i.isDir(r.node.mode))throw new i.ErrnoError(31);if(!r.stream_ops.read)throw new i.ErrnoError(28);var a=typeof o<"u";if(!a)o=r.position;else if(!r.seekable)throw new i.ErrnoError(70);var s=r.stream_ops.read(r,e,t,n,o);return a||(r.position+=s),s},write(r,e,t,n,o,a){if(n<0||o<0)throw new i.ErrnoError(28);if(i.isClosed(r))throw new i.ErrnoError(8);if(!(r.flags&2097155))throw new i.ErrnoError(8);if(i.isDir(r.node.mode))throw new i.ErrnoError(31);if(!r.stream_ops.write)throw new i.ErrnoError(28);r.seekable&&r.flags&1024&&i.llseek(r,0,2);var s=typeof o<"u";if(!s)o=r.position;else if(!r.seekable)throw new i.ErrnoError(70);var u=r.stream_ops.write(r,e,t,n,o,a);return s||(r.position+=u),u},allocate(r,e,t){if(i.isClosed(r))throw new i.ErrnoError(8);if(e<0||t<=0)throw new i.ErrnoError(28);if(!(r.flags&2097155))throw new i.ErrnoError(8);if(!i.isFile(r.node.mode)&&!i.isDir(r.node.mode))throw new i.ErrnoError(43);if(!r.stream_ops.allocate)throw new i.ErrnoError(138);r.stream_ops.allocate(r,e,t)},mmap(r,e,t,n,o){if(n&2&&!(o&2)&&(r.flags&2097155)!==2)throw new i.ErrnoError(2);if((r.flags&2097155)===1)throw new i.ErrnoError(2);if(!r.stream_ops.mmap)throw new i.ErrnoError(43);return r.stream_ops.mmap(r,e,t,n,o)},msync(r,e,t,n,o){return r.stream_ops.msync?r.stream_ops.msync(r,e,t,n,o):0},ioctl(r,e,t){if(!r.stream_ops.ioctl)throw new i.ErrnoError(59);return r.stream_ops.ioctl(r,e,t)},readFile(r,e={}){if(e.flags=e.flags||0,e.encoding=e.encoding||"binary",e.encoding!=="utf8"&&e.encoding!=="binary")throw new Error(`Invalid encoding type "${e.encoding}"`);var t,n=i.open(r,e.flags),o=i.stat(r),a=o.size,s=new Uint8Array(a);return i.read(n,s,0,a,0),e.encoding==="utf8"?t=dr(s,0):e.encoding==="binary"&&(t=s),i.close(n),t},writeFile(r,e,t={}){t.flags=t.flags||577;var n=i.open(r,t.flags,t.mode);if(typeof e=="string"){var o=new Uint8Array(jr(e)+1),a=qr(e,o,0,o.length);i.write(n,o,0,a,void 0,t.canOwn)}else if(ArrayBuffer.isView(e))i.write(n,e,0,e.byteLength,void 0,t.canOwn);else throw new Error("Unsupported data type");i.close(n)},cwd:()=>i.currentPath,chdir(r){var e=i.lookupPath(r,{follow:!0});if(e.node===null)throw new i.ErrnoError(44);if(!i.isDir(e.node.mode))throw new i.ErrnoError(54);var t=i.nodePermissions(e.node,"x");if(t)throw new i.ErrnoError(t);i.currentPath=e.path},createDefaultDirectories(){i.mkdir("/tmp"),i.mkdir("/home"),i.mkdir("/home/web_user")},createDefaultDevices(){i.mkdir("/dev"),i.registerDevice(i.makedev(1,3),{read:()=>0,write:(n,o,a,s,u)=>s}),i.mkdev("/dev/null",i.makedev(1,3)),tr.register(i.makedev(5,0),tr.default_tty_ops),tr.register(i.makedev(6,0),tr.default_tty1_ops),i.mkdev("/dev/tty",i.makedev(5,0)),i.mkdev("/dev/tty1",i.makedev(6,0));var r=new Uint8Array(1024),e=0,t=()=>(e===0&&(e=le(r).byteLength),r[--e]);i.createDevice("/dev","random",t),i.createDevice("/dev","urandom",t),i.mkdir("/dev/shm"),i.mkdir("/dev/shm/tmp")},createSpecialDirectories(){i.mkdir("/proc");var r=i.mkdir("/proc/self");i.mkdir("/proc/self/fd"),i.mount({mount(){var e=i.createNode(r,"fd",16895,73);return e.node_ops={lookup(t,n){var o=+n,a=i.getStreamChecked(o),s={parent:null,mount:{mountpoint:"fake"},node_ops:{readlink:()=>a.path}};return s.parent=s,s}},e}},{},"/proc/self/fd")},createStandardStreams(){f.stdin?i.createDevice("/dev","stdin",f.stdin):i.symlink("/dev/tty","/dev/stdin"),f.stdout?i.createDevice("/dev","stdout",null,f.stdout):i.symlink("/dev/tty","/dev/stdout"),f.stderr?i.createDevice("/dev","stderr",null,f.stderr):i.symlink("/dev/tty1","/dev/stderr");var r=i.open("/dev/stdin",0),e=i.open("/dev/stdout",1),t=i.open("/dev/stderr",1)},staticInit(){[44].forEach(r=>{i.genericErrors[r]=new i.ErrnoError(r),i.genericErrors[r].stack="<generic error, no stack>"}),i.nameTable=new Array(4096),i.mount(b,{},"/"),i.createDefaultDirectories(),i.createDefaultDevices(),i.createSpecialDirectories(),i.filesystems={MEMFS:b}},init(r,e,t){i.init.initialized=!0,f.stdin=r||f.stdin,f.stdout=e||f.stdout,f.stderr=t||f.stderr,i.createStandardStreams()},quit(){i.init.initialized=!1;for(var r=0;r<i.streams.length;r++){var e=i.streams[r];e&&i.close(e)}},findObject(r,e){var t=i.analyzePath(r,e);return t.exists?t.object:null},analyzePath(r,e){try{var t=i.lookupPath(r,{follow:!e});r=t.path}catch{}var n={isRoot:!1,exists:!1,error:0,name:null,path:null,object:null,parentExists:!1,parentPath:null,parentObject:null};try{var t=i.lookupPath(r,{parent:!0});n.parentExists=!0,n.parentPath=t.path,n.parentObject=t.node,n.name=C.basename(r),t=i.lookupPath(r,{follow:!e}),n.exists=!0,n.path=t.path,n.object=t.node,n.name=t.node.name,n.isRoot=t.path==="/"}catch(o){n.error=o.errno}return n},createPath(r,e,t,n){r=typeof r=="string"?r:i.getPath(r);for(var o=e.split("/").reverse();o.length;){var a=o.pop();if(a){var s=C.join2(r,a);try{i.mkdir(s)}catch{}r=s}}return s},createFile(r,e,t,n,o){var a=C.join2(typeof r=="string"?r:i.getPath(r),e),s=Vr(n,o);return i.create(a,s)},createDataFile(r,e,t,n,o,a){var s=e;r&&(r=typeof r=="string"?r:i.getPath(r),s=e?C.join2(r,e):r);var u=Vr(n,o),c=i.create(s,u);if(t){if(typeof t=="string"){for(var d=new Array(t.length),v=0,E=t.length;v<E;++v)d[v]=t.charCodeAt(v);t=d}i.chmod(c,u|146);var h=i.open(c,577);i.write(h,t,0,t.length,0,a),i.close(h),i.chmod(c,u)}},createDevice(r,e,t,n){var o=C.join2(typeof r=="string"?r:i.getPath(r),e),a=Vr(!!t,!!n);i.createDevice.major||(i.createDevice.major=64);var s=i.makedev(i.createDevice.major++,0);return i.registerDevice(s,{open(u){u.seekable=!1},close(u){n?.buffer?.length&&n(10)},read(u,c,d,v,E){for(var h=0,w=0;w<v;w++){var P;try{P=t()}catch{throw new i.ErrnoError(29)}if(P===void 0&&h===0)throw new i.ErrnoError(6);if(P==null)break;h++,c[d+w]=P}return h&&(u.node.timestamp=Date.now()),h},write(u,c,d,v,E){for(var h=0;h<v;h++)try{n(c[d+h])}catch{throw new i.ErrnoError(29)}return v&&(u.node.timestamp=Date.now()),h}}),i.mkdev(o,a,s)},forceLoadFile(r){if(r.isDevice||r.isFolder||r.link||r.contents)return!0;if(typeof XMLHttpRequest<"u")throw new Error("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.");if(Y)try{r.contents=Lr(Y(r.url),!0),r.usedBytes=r.contents.length}catch{throw new i.ErrnoError(29)}else throw new Error("Cannot load without read() or XMLHttpRequest.")},createLazyFile(r,e,t,n,o){class a{constructor(){this.lengthKnown=!1,this.chunks=[]}get(w){if(!(w>this.length-1||w<0)){var P=w%this.chunkSize,j=w/this.chunkSize|0;return this.getter(j)[P]}}setDataGetter(w){this.getter=w}cacheLength(){var w=new XMLHttpRequest;if(w.open("HEAD",t,!1),w.send(null),!(w.status>=200&&w.status<300||w.status===304))throw new Error("Couldn't load "+t+". Status: "+w.status);var P=Number(w.getResponseHeader("Content-length")),j,$=(j=w.getResponseHeader("Accept-Ranges"))&&j==="bytes",L=(j=w.getResponseHeader("Content-Encoding"))&&j==="gzip",l=1024*1024;$||(l=P);var y=(T,V)=>{if(T>V)throw new Error("invalid range ("+T+", "+V+") or no bytes requested!");if(V>P-1)throw new Error("only "+P+" bytes available! programmer error!");var z=new XMLHttpRequest;if(z.open("GET",t,!1),P!==l&&z.setRequestHeader("Range","bytes="+T+"-"+V),z.responseType="arraybuffer",z.overrideMimeType&&z.overrideMimeType("text/plain; charset=x-user-defined"),z.send(null),!(z.status>=200&&z.status<300||z.status===304))throw new Error("Couldn't load "+t+". Status: "+z.status);return z.response!==void 0?new Uint8Array(z.response||[]):Lr(z.responseText||"",!0)},B=this;B.setDataGetter(T=>{var V=T*l,z=(T+1)*l-1;if(z=Math.min(z,P-1),typeof B.chunks[T]>"u"&&(B.chunks[T]=y(V,z)),typeof B.chunks[T]>"u")throw new Error("doXHR failed!");return B.chunks[T]}),(L||!P)&&(l=P=1,P=this.getter(0).length,l=P,_r("LazyFiles on gzip forces download of the whole file when length is accessed")),this._length=P,this._chunkSize=l,this.lengthKnown=!0}get length(){return this.lengthKnown||this.cacheLength(),this._length}get chunkSize(){return this.lengthKnown||this.cacheLength(),this._chunkSize}}if(typeof XMLHttpRequest<"u"){if(!ir)throw"Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc";var s=new a,u={isDevice:!1,contents:s}}else var u={isDevice:!1,url:t};var c=i.createFile(r,e,u,n,o);u.contents?c.contents=u.contents:u.url&&(c.contents=null,c.url=u.url),Object.defineProperties(c,{usedBytes:{get:function(){return this.contents.length}}});var d={},v=Object.keys(c.stream_ops);v.forEach(h=>{var w=c.stream_ops[h];d[h]=(...P)=>(i.forceLoadFile(c),w(...P))});function E(h,w,P,j,$){var L=h.node.contents;if($>=L.length)return 0;var l=Math.min(L.length-$,j);if(L.slice)for(var y=0;y<l;y++)w[P+y]=L[$+y];else for(var y=0;y<l;y++)w[P+y]=L.get($+y);return l}return d.read=(h,w,P,j,$)=>(i.forceLoadFile(c),E(h,w,P,j,$)),d.mmap=(h,w,P,j,$)=>{i.forceLoadFile(c);var L=ve(w);if(!L)throw new i.ErrnoError(48);return E(h,N,L,w,P),{ptr:L,allocated:!0}},c.stream_ops=d,c}},gr=(r,e)=>r?dr(q,r,e):"",D={DEFAULT_POLLMASK:5,calculateAt(r,e,t){if(C.isAbs(e))return e;var n;if(r===-100)n=i.cwd();else{var o=D.getStreamFromFD(r);n=o.path}if(e.length==0){if(!t)throw new i.ErrnoError(44);return n}return C.join2(n,e)},doStat(r,e,t){var n=r(e);k[t>>2]=n.dev,k[t+4>>2]=n.mode,S[t+8>>2]=n.nlink,k[t+12>>2]=n.uid,k[t+16>>2]=n.gid,k[t+20>>2]=n.rdev,O=[n.size>>>0,(A=n.size,+Math.abs(A)>=1?A>0?+Math.floor(A/4294967296)>>>0:~~+Math.ceil((A-+(~~A>>>0))/4294967296)>>>0:0)],k[t+24>>2]=O[0],k[t+28>>2]=O[1],k[t+32>>2]=4096,k[t+36>>2]=n.blocks;var o=n.atime.getTime(),a=n.mtime.getTime(),s=n.ctime.getTime();return O=[Math.floor(o/1e3)>>>0,(A=Math.floor(o/1e3),+Math.abs(A)>=1?A>0?+Math.floor(A/4294967296)>>>0:~~+Math.ceil((A-+(~~A>>>0))/4294967296)>>>0:0)],k[t+40>>2]=O[0],k[t+44>>2]=O[1],S[t+48>>2]=o%1e3*1e3,O=[Math.floor(a/1e3)>>>0,(A=Math.floor(a/1e3),+Math.abs(A)>=1?A>0?+Math.floor(A/4294967296)>>>0:~~+Math.ceil((A-+(~~A>>>0))/4294967296)>>>0:0)],k[t+56>>2]=O[0],k[t+60>>2]=O[1],S[t+64>>2]=a%1e3*1e3,O=[Math.floor(s/1e3)>>>0,(A=Math.floor(s/1e3),+Math.abs(A)>=1?A>0?+Math.floor(A/4294967296)>>>0:~~+Math.ceil((A-+(~~A>>>0))/4294967296)>>>0:0)],k[t+72>>2]=O[0],k[t+76>>2]=O[1],S[t+80>>2]=s%1e3*1e3,O=[n.ino>>>0,(A=n.ino,+Math.abs(A)>=1?A>0?+Math.floor(A/4294967296)>>>0:~~+Math.ceil((A-+(~~A>>>0))/4294967296)>>>0:0)],k[t+88>>2]=O[0],k[t+92>>2]=O[1],0},doMsync(r,e,t,n,o){if(!i.isFile(e.node.mode))throw new i.ErrnoError(43);if(n&2)return 0;var a=q.slice(r,r+t);i.msync(e,a,o,t,n)},varargs:void 0,get(){var r=k[+D.varargs>>2];return D.varargs+=4,r},getp(){return D.get()},getStr(r){var e=gr(r);return e},getStreamFromFD(r){var e=i.getStreamChecked(r);return e}};function Pt(r){try{return r=D.getStr(r),i.chdir(r),0}catch(e){if(typeof i>"u"||e.name!=="ErrnoError")throw e;return-e.errno}}function Mt(r,e,t,n){try{if(e=D.getStr(e),e=D.calculateAt(r,e),t&-8)return-28;var o=i.lookupPath(e,{follow:!0}),a=o.node;if(!a)return-44;var s="";return t&4&&(s+="r"),t&2&&(s+="w"),t&1&&(s+="x"),s&&i.nodePermissions(a,s)?-2:0}catch(u){if(typeof i>"u"||u.name!=="ErrnoError")throw u;return-u.errno}}function Dt(r,e,t){D.varargs=t;try{var n=D.getStreamFromFD(r);switch(e){case 0:{var o=D.get();if(o<0)return-28;for(;i.streams[o];)o++;var a;return a=i.dupStream(n,o),a.fd}case 1:case 2:return 0;case 3:return n.flags;case 4:{var o=D.get();return n.flags|=o,0}case 12:{var o=D.getp(),s=0;return J[o+s>>1]=2,0}case 13:case 14:return 0}return-28}catch(u){if(typeof i>"u"||u.name!=="ErrnoError")throw u;return-u.errno}}function At(r,e){try{var t=D.getStreamFromFD(r);return D.doStat(i.stat,t.path,e)}catch(n){if(typeof i>"u"||n.name!=="ErrnoError")throw n;return-n.errno}}var he=(r,e,t)=>qr(r,q,e,t);function Rt(r,e){try{if(e===0)return-28;var t=i.cwd(),n=jr(t)+1;return e<n?-68:(he(t,r,e),n)}catch(o){if(typeof i>"u"||o.name!=="ErrnoError")throw o;return-o.errno}}function Ct(r,e,t){D.varargs=t;try{var n=D.getStreamFromFD(r);switch(e){case 21509:return n.tty?0:-59;case 21505:{if(!n.tty)return-59;if(n.tty.ops.ioctl_tcgets){var o=n.tty.ops.ioctl_tcgets(n),a=D.getp();k[a>>2]=o.c_iflag||0,k[a+4>>2]=o.c_oflag||0,k[a+8>>2]=o.c_cflag||0,k[a+12>>2]=o.c_lflag||0;for(var s=0;s<32;s++)N[a+s+17]=o.c_cc[s]||0;return 0}return 0}case 21510:case 21511:case 21512:return n.tty?0:-59;case 21506:case 21507:case 21508:{if(!n.tty)return-59;if(n.tty.ops.ioctl_tcsets){for(var a=D.getp(),u=k[a>>2],c=k[a+4>>2],d=k[a+8>>2],v=k[a+12>>2],E=[],s=0;s<32;s++)E.push(N[a+s+17]);return n.tty.ops.ioctl_tcsets(n.tty,e,{c_iflag:u,c_oflag:c,c_cflag:d,c_lflag:v,c_cc:E})}return 0}case 21519:{if(!n.tty)return-59;var a=D.getp();return k[a>>2]=0,0}case 21520:return n.tty?-28:-59;case 21531:{var a=D.getp();return i.ioctl(n,e,a)}case 21523:{if(!n.tty)return-59;if(n.tty.ops.ioctl_tiocgwinsz){var h=n.tty.ops.ioctl_tiocgwinsz(n.tty),a=D.getp();J[a>>1]=h[0],J[a+2>>1]=h[1]}return 0}case 21524:return n.tty?0:-59;case 21515:return n.tty?0:-59;default:return-28}}catch(w){if(typeof i>"u"||w.name!=="ErrnoError")throw w;return-w.errno}}function xt(r,e,t,n){try{e=D.getStr(e);var o=n&256,a=n&4096;return n=n&-6401,e=D.calculateAt(r,e,a),D.doStat(o?i.lstat:i.stat,e,t)}catch(s){if(typeof i>"u"||s.name!=="ErrnoError")throw s;return-s.errno}}function Tt(r,e,t,n){D.varargs=n;try{e=D.getStr(e),e=D.calculateAt(r,e);var o=n?D.get():0;return i.open(e,t,o).fd}catch(a){if(typeof i>"u"||a.name!=="ErrnoError")throw a;return-a.errno}}function It(r,e){try{return r=D.getStr(r),D.doStat(i.stat,r,e)}catch(t){if(typeof i>"u"||t.name!=="ErrnoError")throw t;return-t.errno}}var Nt=1,jt=()=>Nt,Lt=()=>{ce=!1,pe=0},zt=()=>{throw 1/0},Gr=(r,e)=>e+2097152>>>0<4194305-!!r?(r>>>0)+e*4294967296:NaN;function Ut(r,e,t,n,o,a,s,u){var c=Gr(o,a);try{if(isNaN(c))return 61;var d=D.getStreamFromFD(n),v=i.mmap(d,r,c,e,t),E=v.ptr;return k[s>>2]=v.allocated,S[u>>2]=E,0}catch(h){if(typeof i>"u"||h.name!=="ErrnoError")throw h;return-h.errno}}function Ot(r,e,t,n,o,a,s){var u=Gr(a,s);try{var c=D.getStreamFromFD(o);t&2&&D.doMsync(r,c,e,n,u)}catch(d){if(typeof i>"u"||d.name!=="ErrnoError")throw d;return-d.errno}}var Bt=()=>{Rr("")},Ht=()=>Date.now(),me=()=>2147483648,Wt=()=>me(),_e;_e=()=>performance.now();var Yt=(r,e,t)=>q.copyWithin(r,e,e+t),$t=r=>{var e=fr.buffer,t=(r-e.byteLength+65535)/65536;try{return fr.grow(t),ee(),1}catch{}},Xt=r=>{var e=q.length;r>>>=0;var t=me();if(r>t)return!1;for(var n=(c,d)=>c+(d-c%d)%d,o=1;o<=4;o*=2){var a=e*(1+.2/o);a=Math.min(a,r+100663296);var s=Math.min(t,n(Math.max(r,a),65536)),u=$t(s);if(u)return!0}return!1},Kr={},qt=()=>G||"./this.program",Er=()=>{if(!Er.strings){var r=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",e={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:r,_:qt()};for(var t in Kr)Kr[t]===void 0?delete e[t]:e[t]=Kr[t];var n=[];for(var t in e)n.push(`${t}=${e[t]}`);Er.strings=n}return Er.strings},Vt=(r,e)=>{for(var t=0;t<r.length;++t)N[e++]=r.charCodeAt(t);N[e]=0},Gt=(r,e)=>{var t=0;return Er().forEach((n,o)=>{var a=e+t;S[r+o*4>>2]=a,Vt(n,a),t+=n.length+1}),0},Kt=(r,e)=>{var t=Er();S[r>>2]=t.length;var n=0;return t.forEach(o=>n+=o.length+1),S[e>>2]=n,0},pe=0,Jt=()=>ce||pe>0,we=r=>{or=r,Jt()||(f.onExit?.(r),lr=!0),W(r,new ue(r))},ye=(r,e)=>{or=r,we(r)},Zt=ye;function Qt(r){try{var e=D.getStreamFromFD(r);return i.close(e),0}catch(t){if(typeof i>"u"||t.name!=="ErrnoError")throw t;return t.errno}}var rn=(r,e,t,n)=>{for(var o=0,a=0;a<t;a++){var s=S[e>>2],u=S[e+4>>2];e+=8;var c=i.read(r,N,s,u,n);if(c<0)return-1;if(o+=c,c<u)break;typeof n<"u"&&(n+=c)}return o};function en(r,e,t,n){try{var o=D.getStreamFromFD(r),a=rn(o,e,t);return S[n>>2]=a,0}catch(s){if(typeof i>"u"||s.name!=="ErrnoError")throw s;return s.errno}}function tn(r,e,t,n,o){var a=Gr(e,t);try{if(isNaN(a))return 61;var s=D.getStreamFromFD(r);return i.llseek(s,a,n),O=[s.position>>>0,(A=s.position,+Math.abs(A)>=1?A>0?+Math.floor(A/4294967296)>>>0:~~+Math.ceil((A-+(~~A>>>0))/4294967296)>>>0:0)],k[o>>2]=O[0],k[o+4>>2]=O[1],s.getdents&&a===0&&n===0&&(s.getdents=null),0}catch(u){if(typeof i>"u"||u.name!=="ErrnoError")throw u;return u.errno}}var nn=(r,e,t,n)=>{for(var o=0,a=0;a<t;a++){var s=S[e>>2],u=S[e+4>>2];e+=8;var c=i.write(r,N,s,u,n);if(c<0)return-1;o+=c,typeof n<"u"&&(n+=c)}return o};function on(r,e,t,n){try{var o=D.getStreamFromFD(r),a=nn(o,e,t);return S[n>>2]=a,0}catch(s){if(typeof i>"u"||s.name!=="ErrnoError")throw s;return s.errno}}var an=r=>r,zr=r=>r%4===0&&(r%100!==0||r%400===0),sn=(r,e)=>{for(var t=0,n=0;n<=e;t+=r[n++]);return t},ge=[31,29,31,30,31,30,31,31,30,31,30,31],Ee=[31,28,31,30,31,30,31,31,30,31,30,31],un=(r,e)=>{for(var t=new Date(r.getTime());e>0;){var n=zr(t.getFullYear()),o=t.getMonth(),a=(n?ge:Ee)[o];if(e>a-t.getDate())e-=a-t.getDate()+1,t.setDate(1),o<11?t.setMonth(o+1):(t.setMonth(0),t.setFullYear(t.getFullYear()+1));else return t.setDate(t.getDate()+e),t}return t},cn=(r,e)=>{N.set(r,e)},fn=(r,e,t,n)=>{var o=S[n+40>>2],a={tm_sec:k[n>>2],tm_min:k[n+4>>2],tm_hour:k[n+8>>2],tm_mday:k[n+12>>2],tm_mon:k[n+16>>2],tm_year:k[n+20>>2],tm_wday:k[n+24>>2],tm_yday:k[n+28>>2],tm_isdst:k[n+32>>2],tm_gmtoff:k[n+36>>2],tm_zone:o?gr(o):""},s=gr(t),u={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"};for(var c in u)s=s.replace(new RegExp(c,"g"),u[c]);var d=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],v=["January","February","March","April","May","June","July","August","September","October","November","December"];function E(l,y,B){for(var T=typeof l=="number"?l.toString():l||"";T.length<y;)T=B[0]+T;return T}function h(l,y){return E(l,y,"0")}function w(l,y){function B(V){return V<0?-1:V>0?1:0}var T;return(T=B(l.getFullYear()-y.getFullYear()))===0&&(T=B(l.getMonth()-y.getMonth()))===0&&(T=B(l.getDate()-y.getDate())),T}function P(l){switch(l.getDay()){case 0:return new Date(l.getFullYear()-1,11,29);case 1:return l;case 2:return new Date(l.getFullYear(),0,3);case 3:return new Date(l.getFullYear(),0,2);case 4:return new Date(l.getFullYear(),0,1);case 5:return new Date(l.getFullYear()-1,11,31);case 6:return new Date(l.getFullYear()-1,11,30)}}function j(l){var y=un(new Date(l.tm_year+1900,0,1),l.tm_yday),B=new Date(y.getFullYear(),0,4),T=new Date(y.getFullYear()+1,0,4),V=P(B),z=P(T);return w(V,y)<=0?w(z,y)<=0?y.getFullYear()+1:y.getFullYear():y.getFullYear()-1}var $={"%a":l=>d[l.tm_wday].substring(0,3),"%A":l=>d[l.tm_wday],"%b":l=>v[l.tm_mon].substring(0,3),"%B":l=>v[l.tm_mon],"%C":l=>{var y=l.tm_year+1900;return h(y/100|0,2)},"%d":l=>h(l.tm_mday,2),"%e":l=>E(l.tm_mday,2," "),"%g":l=>j(l).toString().substring(2),"%G":j,"%H":l=>h(l.tm_hour,2),"%I":l=>{var y=l.tm_hour;return y==0?y=12:y>12&&(y-=12),h(y,2)},"%j":l=>h(l.tm_mday+sn(zr(l.tm_year+1900)?ge:Ee,l.tm_mon-1),3),"%m":l=>h(l.tm_mon+1,2),"%M":l=>h(l.tm_min,2),"%n":()=>`
|
|
4
|
+
`,"%p":l=>l.tm_hour>=0&&l.tm_hour<12?"AM":"PM","%S":l=>h(l.tm_sec,2),"%t":()=>" ","%u":l=>l.tm_wday||7,"%U":l=>{var y=l.tm_yday+7-l.tm_wday;return h(Math.floor(y/7),2)},"%V":l=>{var y=Math.floor((l.tm_yday+7-(l.tm_wday+6)%7)/7);if((l.tm_wday+371-l.tm_yday-2)%7<=2&&y++,y){if(y==53){var T=(l.tm_wday+371-l.tm_yday)%7;T!=4&&(T!=3||!zr(l.tm_year))&&(y=1)}}else{y=52;var B=(l.tm_wday+7-l.tm_yday-1)%7;(B==4||B==5&&zr(l.tm_year%400-1))&&y++}return h(y,2)},"%w":l=>l.tm_wday,"%W":l=>{var y=l.tm_yday+7-(l.tm_wday+6)%7;return h(Math.floor(y/7),2)},"%y":l=>(l.tm_year+1900).toString().substring(2),"%Y":l=>l.tm_year+1900,"%z":l=>{var y=l.tm_gmtoff,B=y>=0;return y=Math.abs(y)/60,y=y/60*100+y%60,(B?"+":"-")+("0000"+y).slice(-4)},"%Z":l=>l.tm_zone,"%%":()=>"%"};s=s.replace(/%%/g,"\0\0");for(var c in $)s.includes(c)&&(s=s.replace(new RegExp(c,"g"),$[c](a)));s=s.replace(/\0\0/g,"%");var L=Lr(s,!1);return L.length>e?0:(cn(L,r),L.length-1)},ln=(r,e,t,n,o)=>fn(r,e,t,n),dn=r=>{if(r instanceof ue||r=="unwind")return or;W(1,r)},vn=r=>{var e=jr(r)+1,t=Sr(e);return he(r,t,e),t},hn=r=>{var e=_(),t=r();return p(e),t},mn=r=>hn(()=>{var e=Sr(4),t=Sr(4);be(r,e,t);var n=S[e>>2],o=S[t>>2],a=gr(n);Jr(n);var s;return o&&(s=gr(o),Jr(o)),[a,s]}),_n=r=>mn(r),pn=r=>Qr(r),wn=r=>Zr(r);i.createPreloadedFile=bt,i.staticInit(),f.FS_createPath=i.createPath,f.FS_createDataFile=i.createDataFile,f.FS_createPreloadedFile=i.createPreloadedFile,f.FS_unlink=i.unlink,f.FS_createLazyFile=i.createLazyFile,f.FS_createDevice=i.createDevice;var yn={ka:ot,l:at,t:st,a:ct,h:ft,E:lt,Pa:dt,P:vt,r:ht,ga:mt,d:ut,xa:Pt,ya:Mt,T:Dt,sa:At,pa:Rt,za:Ct,qa:xt,Q:Tt,ra:It,ua:jt,ma:Lt,ha:zt,aa:Ut,ba:Ot,q:Bt,va:Ht,ja:Wt,ta:_e,wa:Yt,ia:Xt,na:Gt,oa:Kt,L:Zt,M:Qt,S:en,ca:tn,R:on,s:An,z:Zn,K:Gn,O:pi,v:Fn,g:Sn,n:Un,b:kn,y:Kn,Na:Yn,e:xn,C:ni,G:Jn,Oa:Wn,p:zn,U:_i,Ma:$n,Da:ci,N:ii,w:Mn,Z:ai,Fa:oi,Ka:qn,A:Nn,La:Xn,Ea:ui,x:On,Qa:Hn,Ja:Vn,J:wi,Y:si,$:ki,_:Si,j:jn,i:bn,D:Qn,Ba:hi,Ca:vi,Ga:ti,c:Dn,Aa:mi,Ha:ei,Ia:ri,f:Rn,k:Tn,W:li,u:Pn,V:di,X:fi,B:Cn,o:In,H:Bn,F:Ln,I:yi,da:Ei,ea:gi,m:an,la:we,fa:ln},I=it(),gn=()=>(gn=I.Sa)(),ke=f._main=(r,e)=>(ke=f._main=I.Ta)(r,e),Jr=r=>(Jr=I.Va)(r),En=r=>(En=I.__cxa_free_exception)(r),kr=r=>(kr=I.Wa)(r),Se=(r,e)=>(Se=I.Xa)(r,e),m=(r,e)=>(m=I.Ya)(r,e),_=()=>(_=I.Za)(),p=r=>(p=I._a)(r),Sr=r=>(Sr=I.$a)(r),Zr=r=>(Zr=I.ab)(r),Qr=r=>(Qr=I.bb)(r),be=(r,e,t)=>(be=I.cb)(r,e,t),Fe=(r,e,t)=>(Fe=I.db)(r,e,t),Pe=r=>(Pe=I.eb)(r),Me=f.dynCall_vij=(r,e,t,n)=>(Me=f.dynCall_vij=I.fb)(r,e,t,n),De=f.dynCall_j=r=>(De=f.dynCall_j=I.gb)(r),Ae=f.dynCall_viijii=(r,e,t,n,o,a,s)=>(Ae=f.dynCall_viijii=I.hb)(r,e,t,n,o,a,s),Re=f.dynCall_jiiii=(r,e,t,n,o)=>(Re=f.dynCall_jiiii=I.ib)(r,e,t,n,o);function kn(r,e,t){var n=_();try{return g(r)(e,t)}catch(o){if(p(n),o!==o+0)throw o;m(1,0)}}function Sn(r,e){var t=_();try{return g(r)(e)}catch(n){if(p(t),n!==n+0)throw n;m(1,0)}}function bn(r,e){var t=_();try{g(r)(e)}catch(n){if(p(t),n!==n+0)throw n;m(1,0)}}function Fn(r){var e=_();try{return g(r)()}catch(t){if(p(e),t!==t+0)throw t;m(1,0)}}function Pn(r,e,t,n,o,a){var s=_();try{g(r)(e,t,n,o,a)}catch(u){if(p(s),u!==u+0)throw u;m(1,0)}}function Mn(r,e,t,n,o,a){var s=_();try{return g(r)(e,t,n,o,a)}catch(u){if(p(s),u!==u+0)throw u;m(1,0)}}function Dn(r,e,t){var n=_();try{g(r)(e,t)}catch(o){if(p(n),o!==o+0)throw o;m(1,0)}}function An(r,e){var t=_();try{return g(r)(e)}catch(n){if(p(t),n!==n+0)throw n;m(1,0)}}function Rn(r,e,t,n){var o=_();try{g(r)(e,t,n)}catch(a){if(p(o),a!==a+0)throw a;m(1,0)}}function Cn(r,e,t,n,o,a,s){var u=_();try{g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function xn(r,e,t,n){var o=_();try{return g(r)(e,t,n)}catch(a){if(p(o),a!==a+0)throw a;m(1,0)}}function Tn(r,e,t,n,o){var a=_();try{g(r)(e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}function In(r,e,t,n,o,a,s,u){var c=_();try{g(r)(e,t,n,o,a,s,u)}catch(d){if(p(c),d!==d+0)throw d;m(1,0)}}function Nn(r,e,t,n,o,a,s){var u=_();try{return g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function jn(r){var e=_();try{g(r)()}catch(t){if(p(e),t!==t+0)throw t;m(1,0)}}function Ln(r,e,t,n,o,a,s,u,c,d,v){var E=_();try{g(r)(e,t,n,o,a,s,u,c,d,v)}catch(h){if(p(E),h!==h+0)throw h;m(1,0)}}function zn(r,e,t,n,o){var a=_();try{return g(r)(e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}function Un(r,e,t){var n=_();try{return g(r)(e,t)}catch(o){if(p(n),o!==o+0)throw o;m(1,0)}}function On(r,e,t,n,o,a,s,u){var c=_();try{return g(r)(e,t,n,o,a,s,u)}catch(d){if(p(c),d!==d+0)throw d;m(1,0)}}function Bn(r,e,t,n,o,a,s,u,c){var d=_();try{g(r)(e,t,n,o,a,s,u,c)}catch(v){if(p(d),v!==v+0)throw v;m(1,0)}}function Hn(r,e,t,n,o,a,s,u,c,d){var v=_();try{return g(r)(e,t,n,o,a,s,u,c,d)}catch(E){if(p(v),E!==E+0)throw E;m(1,0)}}function Wn(r,e,t,n,o,a,s,u){var c=_();try{return g(r)(e,t,n,o,a,s,u)}catch(d){if(p(c),d!==d+0)throw d;m(1,0)}}function Yn(r,e,t,n,o,a){var s=_();try{return g(r)(e,t,n,o,a)}catch(u){if(p(s),u!==u+0)throw u;m(1,0)}}function $n(r,e,t,n,o,a,s){var u=_();try{return g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function Xn(r,e,t,n,o,a,s,u,c){var d=_();try{return g(r)(e,t,n,o,a,s,u,c)}catch(v){if(p(d),v!==v+0)throw v;m(1,0)}}function qn(r,e,t,n,o,a,s,u,c){var d=_();try{return g(r)(e,t,n,o,a,s,u,c)}catch(v){if(p(d),v!==v+0)throw v;m(1,0)}}function Vn(r,e,t,n,o,a,s,u,c,d,v){var E=_();try{return g(r)(e,t,n,o,a,s,u,c,d,v)}catch(h){if(p(E),h!==h+0)throw h;m(1,0)}}function Gn(r,e,t,n){var o=_();try{return g(r)(e,t,n)}catch(a){if(p(o),a!==a+0)throw a;m(1,0)}}function Kn(r,e,t,n){var o=_();try{return g(r)(e,t,n)}catch(a){if(p(o),a!==a+0)throw a;m(1,0)}}function Jn(r,e,t,n,o,a){var s=_();try{return g(r)(e,t,n,o,a)}catch(u){if(p(s),u!==u+0)throw u;m(1,0)}}function Zn(r,e,t){var n=_();try{return g(r)(e,t)}catch(o){if(p(n),o!==o+0)throw o;m(1,0)}}function Qn(r,e,t){var n=_();try{g(r)(e,t)}catch(o){if(p(n),o!==o+0)throw o;m(1,0)}}function ri(r,e,t,n,o,a){var s=_();try{g(r)(e,t,n,o,a)}catch(u){if(p(s),u!==u+0)throw u;m(1,0)}}function ei(r,e,t,n,o){var a=_();try{g(r)(e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}function ti(r,e,t,n,o,a,s,u,c){var d=_();try{g(r)(e,t,n,o,a,s,u,c)}catch(v){if(p(d),v!==v+0)throw v;m(1,0)}}function ni(r,e,t,n,o){var a=_();try{return g(r)(e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}function ii(r,e,t,n,o,a,s){var u=_();try{return g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function oi(r,e,t,n,o,a,s,u){var c=_();try{return g(r)(e,t,n,o,a,s,u)}catch(d){if(p(c),d!==d+0)throw d;m(1,0)}}function ai(r,e,t,n,o,a,s){var u=_();try{return g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function si(r,e,t,n,o,a,s,u,c,d,v,E,h){var w=_();try{return g(r)(e,t,n,o,a,s,u,c,d,v,E,h)}catch(P){if(p(w),P!==P+0)throw P;m(1,0)}}function ui(r,e,t,n,o,a,s,u,c,d,v){var E=_();try{return g(r)(e,t,n,o,a,s,u,c,d,v)}catch(h){if(p(E),h!==h+0)throw h;m(1,0)}}function ci(r,e,t,n,o,a,s,u){var c=_();try{return g(r)(e,t,n,o,a,s,u)}catch(d){if(p(c),d!==d+0)throw d;m(1,0)}}function fi(r,e,t,n,o,a,s,u,c,d){var v=_();try{g(r)(e,t,n,o,a,s,u,c,d)}catch(E){if(p(v),E!==E+0)throw E;m(1,0)}}function li(r,e,t,n,o,a,s){var u=_();try{g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function di(r,e,t,n,o,a,s,u,c){var d=_();try{g(r)(e,t,n,o,a,s,u,c)}catch(v){if(p(d),v!==v+0)throw v;m(1,0)}}function vi(r,e,t,n,o,a,s){var u=_();try{g(r)(e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function hi(r,e,t,n,o){var a=_();try{g(r)(e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}function mi(r,e,t,n,o){var a=_();try{g(r)(e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}function _i(r,e,t,n,o,a){var s=_();try{return g(r)(e,t,n,o,a)}catch(u){if(p(s),u!==u+0)throw u;m(1,0)}}function pi(r,e,t,n){var o=_();try{return g(r)(e,t,n)}catch(a){if(p(o),a!==a+0)throw a;m(1,0)}}function wi(r,e,t,n,o,a,s,u,c,d,v,E){var h=_();try{return g(r)(e,t,n,o,a,s,u,c,d,v,E)}catch(w){if(p(h),w!==w+0)throw w;m(1,0)}}function yi(r,e,t,n,o,a,s,u,c,d,v,E,h,w,P,j){var $=_();try{g(r)(e,t,n,o,a,s,u,c,d,v,E,h,w,P,j)}catch(L){if(p($),L!==L+0)throw L;m(1,0)}}function gi(r,e,t,n){var o=_();try{Me(r,e,t,n)}catch(a){if(p(o),a!==a+0)throw a;m(1,0)}}function Ei(r,e,t,n,o,a,s){var u=_();try{Ae(r,e,t,n,o,a,s)}catch(c){if(p(u),c!==c+0)throw c;m(1,0)}}function ki(r){var e=_();try{return De(r)}catch(t){if(p(e),t!==t+0)throw t;m(1,0)}}function Si(r,e,t,n,o){var a=_();try{return Re(r,e,t,n,o)}catch(s){if(p(a),s!==s+0)throw s;m(1,0)}}f.addRunDependency=Ar,f.removeRunDependency=yr,f.FS_createPath=i.createPath,f.FS_createLazyFile=i.createLazyFile,f.FS_createDevice=i.createDevice,f.callMain=Ce,f.incrementExceptionRefcount=pn,f.decrementExceptionRefcount=wn,f.getExceptionMessage=_n,f.FS_createPreloadedFile=i.createPreloadedFile,f.FS=i,f.FS_createDataFile=i.createDataFile,f.FS_unlink=i.unlink;var Ur;wr=function r(){Ur||xe(),Ur||(wr=r)};function Ce(r=[]){var e=ke;r.unshift(G);var t=r.length,n=Sr((t+1)*4),o=n;r.forEach(s=>{S[o>>2]=vn(s),o+=4}),S[o>>2]=0;try{var a=e(t,n);return ye(a,!0),a}catch(s){return dn(s)}}function xe(r=rr){if(ar>0||(Ve(),ar>0))return;function e(){Ur||(Ur=!0,f.calledRun=!0,!lr&&(Ge(),Ke(),H(f),f.onRuntimeInitialized&&f.onRuntimeInitialized(),Te&&Ce(r),Je()))}f.setStatus?(f.setStatus("Running..."),setTimeout(function(){setTimeout(function(){f.setStatus("")},1),e()},1)):e()}if(f.preInit)for(typeof f.preInit=="function"&&(f.preInit=[f.preInit]);f.preInit.length>0;)f.preInit.pop()();var Te=!1;return f.noInitialRun&&(Te=!1),xe(),R.ready}})(),x=null,vr=!1,Fr=null,Or=null,hr=null,Br=null,Hr=null,je=new Promise(function(F,R){Or=F,hr=R}),nr={OPTIMAL:"optimal",INFEASIBLE:"infeasible",UNBOUNDED:"unbounded",TIME_LIMIT:"timelimit",UNKNOWN:"unknown",ERROR:"error"};function Le(F){return F.includes("optimal solution found")?nr.OPTIMAL:F.includes("problem is infeasible")?nr.INFEASIBLE:F.includes("problem is unbounded")?nr.UNBOUNDED:F.includes("time limit reached")?nr.TIME_LIMIT:nr.UNKNOWN}function ze(F){var R={},f={value:null},H=F.match(/objective value:\s*([\d.e+-]+)/i);H&&(f.value=parseFloat(H[1]));for(var M=/^(\w+)\s+([\d.e+-]+)/gm,U,rr=F.split("solution:")[1]||F;(U=M.exec(rr))!==null;){var G=U[1],W=parseFloat(U[2]);!isNaN(W)&&G!=="objective"&&(R[G]=W)}return{variables:R,objective:f}}function Ue(F){var R={solvingTime:null,nodes:null,iterations:null,gap:null},f=F.match(/Solving Time \(sec\)\s*:\s*([\d.]+)/);f&&(R.solvingTime=parseFloat(f[1]));var H=F.match(/Nodes\s*:\s*(\d+)/);H&&(R.nodes=parseInt(H[1]));var M=F.match(/LP Iterations\s*:\s*(\d+)/);M&&(R.iterations=parseInt(M[1]));var U=F.match(/Gap\s*:\s*([\d.]+)\s*%/);return U&&(R.gap=parseFloat(U[1])),R}function Pr(F){return F=F||{},vr?Promise.resolve():Fr||(Fr=new Promise(function(R,f){try{var H=F.wasmPath||br+"scip.wasm";console.log("[SCIP.js] __SCIP_SCRIPT_DIR__:",br),console.log("[SCIP.js] Loading WASM from:",H),fetch(H,{method:"HEAD"}).then(function(M){console.log("[SCIP.js] WASM file check:",M.ok?"OK":"FAILED",M.status)}).catch(function(M){console.error("[SCIP.js] WASM file check failed:",M)}),Ne({locateFile:function(M){return M.endsWith(".wasm")?(console.log("[SCIP.js] locateFile called for:",M,"-> returning:",H),H):M},print:function(M){x&&x.onStdout&&x.onStdout(M)},printErr:function(M){x&&x.onStderr&&x.onStderr(M)},onAbort:function(M){Br=M,console.error("[SCIP WASM Abort]",M)},onExit:function(M){Hr=M,M!==0&&console.error("[SCIP WASM Exit]",M)}}).then(function(M){if(console.log("[SCIP.js] WASM loaded successfully"),x=M,x.FS){try{x.FS.mkdir("/problems")}catch{}try{x.FS.mkdir("/solutions")}catch{}try{x.FS.mkdir("/settings")}catch{}}vr=!0,Or&&Or(),R()}).catch(function(M){console.error("[SCIP.js] WASM loading failed:",M),console.error("[SCIP.js] Attempted WASM path:",H),console.error("[SCIP.js] Make sure the WASM file is accessible at this URL."),console.error("[SCIP.js] You can set window.SCIP_BASE_URL before loading this script to specify a custom path.");var U=new Error("SCIP WASM loading failed: "+(M.message||M)+". WASM path: "+H);hr&&hr(U),f(U)})}catch(M){console.error("[SCIP.js] Initialization error:",M),hr&&hr(M),f(M)}}),Fr)}function Wr(F,R){R=R||{};var f=function(){var H=R.format||"lp",M=R.timeLimit||3600,U=R.gap||null,rr=R.verbose||!1,G=R.parameters||{},W="",ur="";x.onStdout=function(S){W+=S+`
|
|
5
|
+
`,rr&&console.log("[SCIP]",S)},x.onStderr=function(S){ur+=S+`
|
|
6
|
+
`,rr&&console.error("[SCIP Error]",S)};try{var ir={mps:"mps",zpl:"zpl",cip:"cip",lp:"lp"},re=ir[H]||"lp",X="/problems/problem."+re,Mr="/solutions/solution.sol";x.FS.writeFile(X,F);var Y=[];Y.push("set limits time "+M),U!==null&&Y.push("set limits gap "+U);for(var cr in G)G.hasOwnProperty(cr)&&Y.push("set "+cr+" "+G[cr]);Y.push("read "+X),Y.push("optimize"),Y.push("display solution"),Y.push("write solution "+Mr),Y.push("display statistics"),Y.push("quit");var mr=Y.join(`
|
|
7
|
+
`);x.FS.writeFile("/settings/commands.txt",mr);var _r=x.callMain(["-b","/settings/commands.txt"]),K=Le(W),er=ze(W),fr=Ue(W),lr=null;try{lr=x.FS.readFile(Mr,{encoding:"utf8"})}catch{}for(var or=["/problems/problem.lp","/problems/problem.mps","/problems/problem.zpl","/problems/problem.cip","/solutions/solution.sol","/settings/commands.txt"],N=0;N<or.length;N++)try{x.FS.unlink(or[N])}catch{}return{status:K,objective:er.objective.value,variables:er.variables,statistics:fr,exitCode:_r,output:rr?W:void 0,rawSolution:lr}}catch(S){var q=S.message||String(S),J=null;if(typeof S=="number"||/^\d+$/.test(String(S))){var pr=typeof S=="number"?S:parseInt(String(S),10);if(x)try{if(typeof x.getExceptionMessage=="function")J=x.getExceptionMessage(pr),q="WASM Exception: "+J;else if(typeof x.UTF8ToString=="function")try{var k=x.UTF8ToString(pr);k&&k.length>0&&k.length<1e3&&(J=k,q="WASM Exception: "+k)}catch{}}catch(Dr){console.error("[SCIP] Failed to get exception message:",Dr)}J||(q="WASM Exception (ptr: "+pr+"). Enable exception handling in build for details.")}return{status:nr.ERROR,error:q,errorDetails:{rawError:String(S),exceptionInfo:J,abortReason:Br,exitCode:Hr,type:typeof S,stdout:W,stderr:ur},output:W+ur}}Br=null,Hr=null};return vr?Promise.resolve(f()):Pr(R).then(f)}function Oe(F,R){return F.toLowerCase().includes("minimize")||(F=`Minimize
|
|
8
|
+
`+F),Wr(F,R)}function Be(F,R){return F.toLowerCase().includes("maximize")||(F=`Maximize
|
|
9
|
+
`+F),Wr(F,R)}function He(){var F=function(){var R="";return x.onStdout=function(f){R+=f+`
|
|
10
|
+
`},x.callMain(["--version"]),R.trim()};return vr?Promise.resolve(F()):Pr().then(F)}function We(){return vr}var Ye={init:Pr,ready:je,isReady:We,solve:Wr,minimize:Oe,maximize:Be,version:He,Status:nr};Ie.SCIP=Ye,Pr().catch(function(F){console.error("[SCIP.js] Auto-initialization failed:",F.message)})})(typeof self<"u"?self:typeof window<"u"?window:globalThis);
|