PageRenderTime 172ms CodeModel.GetById 19ms app.highlight 84ms RepoModel.GetById 1ms app.codeStats 6ms

/EmTutor/disk_harmonic_map.js

https://github.com/cfwen/extremal
JavaScript | 8820 lines | 6000 code | 2235 blank | 585 comment | 1569 complexity | c7972acae3b376c706ee2722441c2e98 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1// Note: For maximum-speed code, see "Optimizing Code" on the Emscripten wiki, https://github.com/kripken/emscripten/wiki/Optimizing-Code
   2// Note: Some Emscripten settings may limit the speed of the generated code.
   3// The Module object: Our interface to the outside world. We import
   4// and export values on it, and do the work to get that through
   5// closure compiler if necessary. There are various ways Module can be used:
   6// 1. Not defined. We create it here
   7// 2. A function parameter, function(Module) { ..generated code.. }
   8// 3. pre-run appended it, var Module = {}; ..generated code..
   9// 4. External script tag defines var Module.
  10// We need to do an eval in order to handle the closure compiler
  11// case, where this code here is minified but Module was defined
  12// elsewhere (e.g. case 4 above). We also need to check if Module
  13// already exists (e.g. case 3 above).
  14// Note that if you want to run closure, and also to use Module
  15// after the generated code, you will need to define   var Module = {};
  16// before the code. Then that object will be used in the code, and you
  17// can continue to use Module afterwards as well.
  18var Module;
  19if (!Module) Module = eval('(function() { try { return Module || {} } catch(e) { return {} } })()');
  20
  21// Sometimes an existing Module object exists with properties
  22// meant to overwrite the default module functionality. Here
  23// we collect those properties and reapply _after_ we configure
  24// the current environment's defaults to avoid having to be so
  25// defensive during initialization.
  26var moduleOverrides = {};
  27for (var key in Module) {
  28  if (Module.hasOwnProperty(key)) {
  29    moduleOverrides[key] = Module[key];
  30  }
  31}
  32
  33// The environment setup code below is customized to use Module.
  34// *** Environment setup code ***
  35var ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof require === 'function';
  36var ENVIRONMENT_IS_WEB = typeof window === 'object';
  37var ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
  38var ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
  39
  40if (ENVIRONMENT_IS_NODE) {
  41  // Expose functionality in the same simple way that the shells work
  42  // Note that we pollute the global namespace here, otherwise we break in node
  43  if (!Module['print']) Module['print'] = function print(x) {
  44    process['stdout'].write(x + '\n');
  45  };
  46  if (!Module['printErr']) Module['printErr'] = function printErr(x) {
  47    process['stderr'].write(x + '\n');
  48  };
  49
  50  var nodeFS = require('fs');
  51  var nodePath = require('path');
  52
  53  Module['read'] = function read(filename, binary) {
  54    filename = nodePath['normalize'](filename);
  55    var ret = nodeFS['readFileSync'](filename);
  56    // The path is absolute if the normalized version is the same as the resolved.
  57    if (!ret && filename != nodePath['resolve'](filename)) {
  58      filename = path.join(__dirname, '..', 'src', filename);
  59      ret = nodeFS['readFileSync'](filename);
  60    }
  61    if (ret && !binary) ret = ret.toString();
  62    return ret;
  63  };
  64
  65  Module['readBinary'] = function readBinary(filename) { return Module['read'](filename, true) };
  66
  67  Module['load'] = function load(f) {
  68    globalEval(read(f));
  69  };
  70
  71  Module['arguments'] = process['argv'].slice(2);
  72
  73  module['exports'] = Module;
  74}
  75else if (ENVIRONMENT_IS_SHELL) {
  76  if (!Module['print']) Module['print'] = print;
  77  if (typeof printErr != 'undefined') Module['printErr'] = printErr; // not present in v8 or older sm
  78
  79  if (typeof read != 'undefined') {
  80    Module['read'] = read;
  81  } else {
  82    Module['read'] = function read() { throw 'no read() available (jsc?)' };
  83  }
  84
  85  Module['readBinary'] = function readBinary(f) {
  86    return read(f, 'binary');
  87  };
  88
  89  if (typeof scriptArgs != 'undefined') {
  90    Module['arguments'] = scriptArgs;
  91  } else if (typeof arguments != 'undefined') {
  92    Module['arguments'] = arguments;
  93  }
  94
  95  this['Module'] = Module;
  96
  97  eval("if (typeof gc === 'function' && gc.toString().indexOf('[native code]') > 0) var gc = undefined"); // wipe out the SpiderMonkey shell 'gc' function, which can confuse closure (uses it as a minified name, and it is then initted to a non-falsey value unexpectedly)
  98}
  99else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
 100  Module['read'] = function read(url) {
 101    var xhr = new XMLHttpRequest();
 102    xhr.open('GET', url, false);
 103    xhr.send(null);
 104    return xhr.responseText;
 105  };
 106
 107  if (typeof arguments != 'undefined') {
 108    Module['arguments'] = arguments;
 109  }
 110
 111  if (typeof console !== 'undefined') {
 112    if (!Module['print']) Module['print'] = function print(x) {
 113      console.log(x);
 114    };
 115    if (!Module['printErr']) Module['printErr'] = function printErr(x) {
 116      console.log(x);
 117    };
 118  } else {
 119    // Probably a worker, and without console.log. We can do very little here...
 120    var TRY_USE_DUMP = false;
 121    if (!Module['print']) Module['print'] = (TRY_USE_DUMP && (typeof(dump) !== "undefined") ? (function(x) {
 122      dump(x);
 123    }) : (function(x) {
 124      // self.postMessage(x); // enable this if you want stdout to be sent as messages
 125    }));
 126  }
 127
 128  if (ENVIRONMENT_IS_WEB) {
 129    this['Module'] = Module;
 130  } else {
 131    Module['load'] = importScripts;
 132  }
 133}
 134else {
 135  // Unreachable because SHELL is dependant on the others
 136  throw 'Unknown runtime environment. Where are we?';
 137}
 138
 139function globalEval(x) {
 140  eval.call(null, x);
 141}
 142if (!Module['load'] == 'undefined' && Module['read']) {
 143  Module['load'] = function load(f) {
 144    globalEval(Module['read'](f));
 145  };
 146}
 147if (!Module['print']) {
 148  Module['print'] = function(){};
 149}
 150if (!Module['printErr']) {
 151  Module['printErr'] = Module['print'];
 152}
 153if (!Module['arguments']) {
 154  Module['arguments'] = [];
 155}
 156// *** Environment setup code ***
 157
 158// Closure helpers
 159Module.print = Module['print'];
 160Module.printErr = Module['printErr'];
 161
 162// Callbacks
 163Module['preRun'] = [];
 164Module['postRun'] = [];
 165
 166// Merge back in the overrides
 167for (var key in moduleOverrides) {
 168  if (moduleOverrides.hasOwnProperty(key)) {
 169    Module[key] = moduleOverrides[key];
 170  }
 171}
 172
 173
 174
 175// === Auto-generated preamble library stuff ===
 176
 177//========================================
 178// Runtime code shared with compiler
 179//========================================
 180
 181var Runtime = {
 182  stackSave: function () {
 183    return STACKTOP;
 184  },
 185  stackRestore: function (stackTop) {
 186    STACKTOP = stackTop;
 187  },
 188  forceAlign: function (target, quantum) {
 189    quantum = quantum || 4;
 190    if (quantum == 1) return target;
 191    if (isNumber(target) && isNumber(quantum)) {
 192      return Math.ceil(target/quantum)*quantum;
 193    } else if (isNumber(quantum) && isPowerOfTwo(quantum)) {
 194      return '(((' +target + ')+' + (quantum-1) + ')&' + -quantum + ')';
 195    }
 196    return 'Math.ceil((' + target + ')/' + quantum + ')*' + quantum;
 197  },
 198  isNumberType: function (type) {
 199    return type in Runtime.INT_TYPES || type in Runtime.FLOAT_TYPES;
 200  },
 201  isPointerType: function isPointerType(type) {
 202  return type[type.length-1] == '*';
 203},
 204  isStructType: function isStructType(type) {
 205  if (isPointerType(type)) return false;
 206  if (isArrayType(type)) return true;
 207  if (/<?\{ ?[^}]* ?\}>?/.test(type)) return true; // { i32, i8 } etc. - anonymous struct types
 208  // See comment in isStructPointerType()
 209  return type[0] == '%';
 210},
 211  INT_TYPES: {"i1":0,"i8":0,"i16":0,"i32":0,"i64":0},
 212  FLOAT_TYPES: {"float":0,"double":0},
 213  or64: function (x, y) {
 214    var l = (x | 0) | (y | 0);
 215    var h = (Math.round(x / 4294967296) | Math.round(y / 4294967296)) * 4294967296;
 216    return l + h;
 217  },
 218  and64: function (x, y) {
 219    var l = (x | 0) & (y | 0);
 220    var h = (Math.round(x / 4294967296) & Math.round(y / 4294967296)) * 4294967296;
 221    return l + h;
 222  },
 223  xor64: function (x, y) {
 224    var l = (x | 0) ^ (y | 0);
 225    var h = (Math.round(x / 4294967296) ^ Math.round(y / 4294967296)) * 4294967296;
 226    return l + h;
 227  },
 228  getNativeTypeSize: function (type) {
 229    switch (type) {
 230      case 'i1': case 'i8': return 1;
 231      case 'i16': return 2;
 232      case 'i32': return 4;
 233      case 'i64': return 8;
 234      case 'float': return 4;
 235      case 'double': return 8;
 236      default: {
 237        if (type[type.length-1] === '*') {
 238          return Runtime.QUANTUM_SIZE; // A pointer
 239        } else if (type[0] === 'i') {
 240          var bits = parseInt(type.substr(1));
 241          assert(bits % 8 === 0);
 242          return bits/8;
 243        } else {
 244          return 0;
 245        }
 246      }
 247    }
 248  },
 249  getNativeFieldSize: function (type) {
 250    return Math.max(Runtime.getNativeTypeSize(type), Runtime.QUANTUM_SIZE);
 251  },
 252  dedup: function dedup(items, ident) {
 253  var seen = {};
 254  if (ident) {
 255    return items.filter(function(item) {
 256      if (seen[item[ident]]) return false;
 257      seen[item[ident]] = true;
 258      return true;
 259    });
 260  } else {
 261    return items.filter(function(item) {
 262      if (seen[item]) return false;
 263      seen[item] = true;
 264      return true;
 265    });
 266  }
 267},
 268  set: function set() {
 269  var args = typeof arguments[0] === 'object' ? arguments[0] : arguments;
 270  var ret = {};
 271  for (var i = 0; i < args.length; i++) {
 272    ret[args[i]] = 0;
 273  }
 274  return ret;
 275},
 276  STACK_ALIGN: 8,
 277  getAlignSize: function (type, size, vararg) {
 278    // we align i64s and doubles on 64-bit boundaries, unlike x86
 279    if (vararg) return 8;
 280    if (!vararg && (type == 'i64' || type == 'double')) return 8;
 281    if (!type) return Math.min(size, 8); // align structures internally to 64 bits
 282    return Math.min(size || (type ? Runtime.getNativeFieldSize(type) : 0), Runtime.QUANTUM_SIZE);
 283  },
 284  calculateStructAlignment: function calculateStructAlignment(type) {
 285    type.flatSize = 0;
 286    type.alignSize = 0;
 287    var diffs = [];
 288    var prev = -1;
 289    var index = 0;
 290    type.flatIndexes = type.fields.map(function(field) {
 291      index++;
 292      var size, alignSize;
 293      if (Runtime.isNumberType(field) || Runtime.isPointerType(field)) {
 294        size = Runtime.getNativeTypeSize(field); // pack char; char; in structs, also char[X]s.
 295        alignSize = Runtime.getAlignSize(field, size);
 296      } else if (Runtime.isStructType(field)) {
 297        if (field[1] === '0') {
 298          // this is [0 x something]. When inside another structure like here, it must be at the end,
 299          // and it adds no size
 300          // XXX this happens in java-nbody for example... assert(index === type.fields.length, 'zero-length in the middle!');
 301          size = 0;
 302          if (Types.types[field]) {
 303            alignSize = Runtime.getAlignSize(null, Types.types[field].alignSize);
 304          } else {
 305            alignSize = type.alignSize || QUANTUM_SIZE;
 306          }
 307        } else {
 308          size = Types.types[field].flatSize;
 309          alignSize = Runtime.getAlignSize(null, Types.types[field].alignSize);
 310        }
 311      } else if (field[0] == 'b') {
 312        // bN, large number field, like a [N x i8]
 313        size = field.substr(1)|0;
 314        alignSize = 1;
 315      } else if (field[0] === '<') {
 316        // vector type
 317        size = alignSize = Types.types[field].flatSize; // fully aligned
 318      } else if (field[0] === 'i') {
 319        // illegal integer field, that could not be legalized because it is an internal structure field
 320        // it is ok to have such fields, if we just use them as markers of field size and nothing more complex
 321        size = alignSize = parseInt(field.substr(1))/8;
 322        assert(size % 1 === 0, 'cannot handle non-byte-size field ' + field);
 323      } else {
 324        assert(false, 'invalid type for calculateStructAlignment');
 325      }
 326      if (type.packed) alignSize = 1;
 327      type.alignSize = Math.max(type.alignSize, alignSize);
 328      var curr = Runtime.alignMemory(type.flatSize, alignSize); // if necessary, place this on aligned memory
 329      type.flatSize = curr + size;
 330      if (prev >= 0) {
 331        diffs.push(curr-prev);
 332      }
 333      prev = curr;
 334      return curr;
 335    });
 336    if (type.name_ && type.name_[0] === '[') {
 337      // arrays have 2 elements, so we get the proper difference. then we scale here. that way we avoid
 338      // allocating a potentially huge array for [999999 x i8] etc.
 339      type.flatSize = parseInt(type.name_.substr(1))*type.flatSize/2;
 340    }
 341    type.flatSize = Runtime.alignMemory(type.flatSize, type.alignSize);
 342    if (diffs.length == 0) {
 343      type.flatFactor = type.flatSize;
 344    } else if (Runtime.dedup(diffs).length == 1) {
 345      type.flatFactor = diffs[0];
 346    }
 347    type.needsFlattening = (type.flatFactor != 1);
 348    return type.flatIndexes;
 349  },
 350  generateStructInfo: function (struct, typeName, offset) {
 351    var type, alignment;
 352    if (typeName) {
 353      offset = offset || 0;
 354      type = (typeof Types === 'undefined' ? Runtime.typeInfo : Types.types)[typeName];
 355      if (!type) return null;
 356      if (type.fields.length != struct.length) {
 357        printErr('Number of named fields must match the type for ' + typeName + ': possibly duplicate struct names. Cannot return structInfo');
 358        return null;
 359      }
 360      alignment = type.flatIndexes;
 361    } else {
 362      var type = { fields: struct.map(function(item) { return item[0] }) };
 363      alignment = Runtime.calculateStructAlignment(type);
 364    }
 365    var ret = {
 366      __size__: type.flatSize
 367    };
 368    if (typeName) {
 369      struct.forEach(function(item, i) {
 370        if (typeof item === 'string') {
 371          ret[item] = alignment[i] + offset;
 372        } else {
 373          // embedded struct
 374          var key;
 375          for (var k in item) key = k;
 376          ret[key] = Runtime.generateStructInfo(item[key], type.fields[i], alignment[i]);
 377        }
 378      });
 379    } else {
 380      struct.forEach(function(item, i) {
 381        ret[item[1]] = alignment[i];
 382      });
 383    }
 384    return ret;
 385  },
 386  dynCall: function (sig, ptr, args) {
 387    if (args && args.length) {
 388      if (!args.splice) args = Array.prototype.slice.call(args);
 389      args.splice(0, 0, ptr);
 390      return Module['dynCall_' + sig].apply(null, args);
 391    } else {
 392      return Module['dynCall_' + sig].call(null, ptr);
 393    }
 394  },
 395  functionPointers: [],
 396  addFunction: function (func) {
 397    for (var i = 0; i < Runtime.functionPointers.length; i++) {
 398      if (!Runtime.functionPointers[i]) {
 399        Runtime.functionPointers[i] = func;
 400        return 2*(1 + i);
 401      }
 402    }
 403    throw 'Finished up all reserved function pointers. Use a higher value for RESERVED_FUNCTION_POINTERS.';
 404  },
 405  removeFunction: function (index) {
 406    Runtime.functionPointers[(index-2)/2] = null;
 407  },
 408  getAsmConst: function (code, numArgs) {
 409    // code is a constant string on the heap, so we can cache these
 410    if (!Runtime.asmConstCache) Runtime.asmConstCache = {};
 411    var func = Runtime.asmConstCache[code];
 412    if (func) return func;
 413    var args = [];
 414    for (var i = 0; i < numArgs; i++) {
 415      args.push(String.fromCharCode(36) + i); // $0, $1 etc
 416    }
 417    code = Pointer_stringify(code);
 418    if (code[0] === '"') {
 419      // tolerate EM_ASM("..code..") even though EM_ASM(..code..) is correct
 420      if (code.indexOf('"', 1) === code.length-1) {
 421        code = code.substr(1, code.length-2);
 422      } else {
 423        // something invalid happened, e.g. EM_ASM("..code($0)..", input)
 424        abort('invalid EM_ASM input |' + code + '|. Please use EM_ASM(..code..) (no quotes) or EM_ASM({ ..code($0).. }, input) (to input values)');
 425      }
 426    }
 427    return Runtime.asmConstCache[code] = eval('(function(' + args.join(',') + '){ ' + code + ' })'); // new Function does not allow upvars in node
 428  },
 429  warnOnce: function (text) {
 430    if (!Runtime.warnOnce.shown) Runtime.warnOnce.shown = {};
 431    if (!Runtime.warnOnce.shown[text]) {
 432      Runtime.warnOnce.shown[text] = 1;
 433      Module.printErr(text);
 434    }
 435  },
 436  funcWrappers: {},
 437  getFuncWrapper: function (func, sig) {
 438    assert(sig);
 439    if (!Runtime.funcWrappers[func]) {
 440      Runtime.funcWrappers[func] = function dynCall_wrapper() {
 441        return Runtime.dynCall(sig, func, arguments);
 442      };
 443    }
 444    return Runtime.funcWrappers[func];
 445  },
 446  UTF8Processor: function () {
 447    var buffer = [];
 448    var needed = 0;
 449    this.processCChar = function (code) {
 450      code = code & 0xFF;
 451
 452      if (buffer.length == 0) {
 453        if ((code & 0x80) == 0x00) {        // 0xxxxxxx
 454          return String.fromCharCode(code);
 455        }
 456        buffer.push(code);
 457        if ((code & 0xE0) == 0xC0) {        // 110xxxxx
 458          needed = 1;
 459        } else if ((code & 0xF0) == 0xE0) { // 1110xxxx
 460          needed = 2;
 461        } else {                            // 11110xxx
 462          needed = 3;
 463        }
 464        return '';
 465      }
 466
 467      if (needed) {
 468        buffer.push(code);
 469        needed--;
 470        if (needed > 0) return '';
 471      }
 472
 473      var c1 = buffer[0];
 474      var c2 = buffer[1];
 475      var c3 = buffer[2];
 476      var c4 = buffer[3];
 477      var ret;
 478      if (buffer.length == 2) {
 479        ret = String.fromCharCode(((c1 & 0x1F) << 6)  | (c2 & 0x3F));
 480      } else if (buffer.length == 3) {
 481        ret = String.fromCharCode(((c1 & 0x0F) << 12) | ((c2 & 0x3F) << 6)  | (c3 & 0x3F));
 482      } else {
 483        // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
 484        var codePoint = ((c1 & 0x07) << 18) | ((c2 & 0x3F) << 12) |
 485                        ((c3 & 0x3F) << 6)  | (c4 & 0x3F);
 486        ret = String.fromCharCode(
 487          Math.floor((codePoint - 0x10000) / 0x400) + 0xD800,
 488          (codePoint - 0x10000) % 0x400 + 0xDC00);
 489      }
 490      buffer.length = 0;
 491      return ret;
 492    }
 493    this.processJSString = function processJSString(string) {
 494      string = unescape(encodeURIComponent(string));
 495      var ret = [];
 496      for (var i = 0; i < string.length; i++) {
 497        ret.push(string.charCodeAt(i));
 498      }
 499      return ret;
 500    }
 501  },
 502  stackAlloc: function (size) { var ret = STACKTOP;STACKTOP = (STACKTOP + size)|0;STACKTOP = (((STACKTOP)+7)&-8); return ret; },
 503  staticAlloc: function (size) { var ret = STATICTOP;STATICTOP = (STATICTOP + size)|0;STATICTOP = (((STATICTOP)+7)&-8); return ret; },
 504  dynamicAlloc: function (size) { var ret = DYNAMICTOP;DYNAMICTOP = (DYNAMICTOP + size)|0;DYNAMICTOP = (((DYNAMICTOP)+7)&-8); if (DYNAMICTOP >= TOTAL_MEMORY) enlargeMemory();; return ret; },
 505  alignMemory: function (size,quantum) { var ret = size = Math.ceil((size)/(quantum ? quantum : 8))*(quantum ? quantum : 8); return ret; },
 506  makeBigInt: function (low,high,unsigned) { var ret = (unsigned ? ((+((low>>>0)))+((+((high>>>0)))*(+4294967296))) : ((+((low>>>0)))+((+((high|0)))*(+4294967296)))); return ret; },
 507  GLOBAL_BASE: 8,
 508  QUANTUM_SIZE: 4,
 509  __dummy__: 0
 510}
 511
 512
 513Module['Runtime'] = Runtime;
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523//========================================
 524// Runtime essentials
 525//========================================
 526
 527var __THREW__ = 0; // Used in checking for thrown exceptions.
 528
 529var ABORT = false; // whether we are quitting the application. no code should run after this. set in exit() and abort()
 530var EXITSTATUS = 0;
 531
 532var undef = 0;
 533// tempInt is used for 32-bit signed values or smaller. tempBigInt is used
 534// for 32-bit unsigned values or more than 32 bits. TODO: audit all uses of tempInt
 535var tempValue, tempInt, tempBigInt, tempInt2, tempBigInt2, tempPair, tempBigIntI, tempBigIntR, tempBigIntS, tempBigIntP, tempBigIntD, tempDouble, tempFloat;
 536var tempI64, tempI64b;
 537var tempRet0, tempRet1, tempRet2, tempRet3, tempRet4, tempRet5, tempRet6, tempRet7, tempRet8, tempRet9;
 538
 539function assert(condition, text) {
 540  if (!condition) {
 541    abort('Assertion failed: ' + text);
 542  }
 543}
 544
 545var globalScope = this;
 546
 547// C calling interface. A convenient way to call C functions (in C files, or
 548// defined with extern "C").
 549//
 550// Note: LLVM optimizations can inline and remove functions, after which you will not be
 551//       able to call them. Closure can also do so. To avoid that, add your function to
 552//       the exports using something like
 553//
 554//         -s EXPORTED_FUNCTIONS='["_main", "_myfunc"]'
 555//
 556// @param ident      The name of the C function (note that C++ functions will be name-mangled - use extern "C")
 557// @param returnType The return type of the function, one of the JS types 'number', 'string' or 'array' (use 'number' for any C pointer, and
 558//                   'array' for JavaScript arrays and typed arrays; note that arrays are 8-bit).
 559// @param argTypes   An array of the types of arguments for the function (if there are no arguments, this can be ommitted). Types are as in returnType,
 560//                   except that 'array' is not possible (there is no way for us to know the length of the array)
 561// @param args       An array of the arguments to the function, as native JS values (as in returnType)
 562//                   Note that string arguments will be stored on the stack (the JS string will become a C string on the stack).
 563// @return           The return value, as a native JS value (as in returnType)
 564function ccall(ident, returnType, argTypes, args) {
 565  return ccallFunc(getCFunc(ident), returnType, argTypes, args);
 566}
 567Module["ccall"] = ccall;
 568
 569// Returns the C function with a specified identifier (for C++, you need to do manual name mangling)
 570function getCFunc(ident) {
 571  try {
 572    var func = Module['_' + ident]; // closure exported function
 573    if (!func) func = eval('_' + ident); // explicit lookup
 574  } catch(e) {
 575  }
 576  assert(func, 'Cannot call unknown function ' + ident + ' (perhaps LLVM optimizations or closure removed it?)');
 577  return func;
 578}
 579
 580// Internal function that does a C call using a function, not an identifier
 581function ccallFunc(func, returnType, argTypes, args) {
 582  var stack = 0;
 583  function toC(value, type) {
 584    if (type == 'string') {
 585      if (value === null || value === undefined || value === 0) return 0; // null string
 586      value = intArrayFromString(value);
 587      type = 'array';
 588    }
 589    if (type == 'array') {
 590      if (!stack) stack = Runtime.stackSave();
 591      var ret = Runtime.stackAlloc(value.length);
 592      writeArrayToMemory(value, ret);
 593      return ret;
 594    }
 595    return value;
 596  }
 597  function fromC(value, type) {
 598    if (type == 'string') {
 599      return Pointer_stringify(value);
 600    }
 601    assert(type != 'array');
 602    return value;
 603  }
 604  var i = 0;
 605  var cArgs = args ? args.map(function(arg) {
 606    return toC(arg, argTypes[i++]);
 607  }) : [];
 608  var ret = fromC(func.apply(null, cArgs), returnType);
 609  if (stack) Runtime.stackRestore(stack);
 610  return ret;
 611}
 612
 613// Returns a native JS wrapper for a C function. This is similar to ccall, but
 614// returns a function you can call repeatedly in a normal way. For example:
 615//
 616//   var my_function = cwrap('my_c_function', 'number', ['number', 'number']);
 617//   alert(my_function(5, 22));
 618//   alert(my_function(99, 12));
 619//
 620function cwrap(ident, returnType, argTypes) {
 621  var func = getCFunc(ident);
 622  return function() {
 623    return ccallFunc(func, returnType, argTypes, Array.prototype.slice.call(arguments));
 624  }
 625}
 626Module["cwrap"] = cwrap;
 627
 628// Sets a value in memory in a dynamic way at run-time. Uses the
 629// type data. This is the same as makeSetValue, except that
 630// makeSetValue is done at compile-time and generates the needed
 631// code then, whereas this function picks the right code at
 632// run-time.
 633// Note that setValue and getValue only do *aligned* writes and reads!
 634// Note that ccall uses JS types as for defining types, while setValue and
 635// getValue need LLVM types ('i8', 'i32') - this is a lower-level operation
 636function setValue(ptr, value, type, noSafe) {
 637  type = type || 'i8';
 638  if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
 639    switch(type) {
 640      case 'i1': HEAP8[(ptr)]=value; break;
 641      case 'i8': HEAP8[(ptr)]=value; break;
 642      case 'i16': HEAP16[((ptr)>>1)]=value; break;
 643      case 'i32': HEAP32[((ptr)>>2)]=value; break;
 644      case 'i64': (tempI64 = [value>>>0,(tempDouble=value,(+(Math_abs(tempDouble))) >= (+1) ? (tempDouble > (+0) ? ((Math_min((+(Math_floor((tempDouble)/(+4294967296)))), (+4294967295)))|0)>>>0 : (~~((+(Math_ceil((tempDouble - +(((~~(tempDouble)))>>>0))/(+4294967296))))))>>>0) : 0)],HEAP32[((ptr)>>2)]=tempI64[0],HEAP32[(((ptr)+(4))>>2)]=tempI64[1]); break;
 645      case 'float': HEAPF32[((ptr)>>2)]=value; break;
 646      case 'double': HEAPF64[((ptr)>>3)]=value; break;
 647      default: abort('invalid type for setValue: ' + type);
 648    }
 649}
 650Module['setValue'] = setValue;
 651
 652// Parallel to setValue.
 653function getValue(ptr, type, noSafe) {
 654  type = type || 'i8';
 655  if (type.charAt(type.length-1) === '*') type = 'i32'; // pointers are 32-bit
 656    switch(type) {
 657      case 'i1': return HEAP8[(ptr)];
 658      case 'i8': return HEAP8[(ptr)];
 659      case 'i16': return HEAP16[((ptr)>>1)];
 660      case 'i32': return HEAP32[((ptr)>>2)];
 661      case 'i64': return HEAP32[((ptr)>>2)];
 662      case 'float': return HEAPF32[((ptr)>>2)];
 663      case 'double': return HEAPF64[((ptr)>>3)];
 664      default: abort('invalid type for setValue: ' + type);
 665    }
 666  return null;
 667}
 668Module['getValue'] = getValue;
 669
 670var ALLOC_NORMAL = 0; // Tries to use _malloc()
 671var ALLOC_STACK = 1; // Lives for the duration of the current function call
 672var ALLOC_STATIC = 2; // Cannot be freed
 673var ALLOC_DYNAMIC = 3; // Cannot be freed except through sbrk
 674var ALLOC_NONE = 4; // Do not allocate
 675Module['ALLOC_NORMAL'] = ALLOC_NORMAL;
 676Module['ALLOC_STACK'] = ALLOC_STACK;
 677Module['ALLOC_STATIC'] = ALLOC_STATIC;
 678Module['ALLOC_DYNAMIC'] = ALLOC_DYNAMIC;
 679Module['ALLOC_NONE'] = ALLOC_NONE;
 680
 681// allocate(): This is for internal use. You can use it yourself as well, but the interface
 682//             is a little tricky (see docs right below). The reason is that it is optimized
 683//             for multiple syntaxes to save space in generated code. So you should
 684//             normally not use allocate(), and instead allocate memory using _malloc(),
 685//             initialize it with setValue(), and so forth.
 686// @slab: An array of data, or a number. If a number, then the size of the block to allocate,
 687//        in *bytes* (note that this is sometimes confusing: the next parameter does not
 688//        affect this!)
 689// @types: Either an array of types, one for each byte (or 0 if no type at that position),
 690//         or a single type which is used for the entire block. This only matters if there
 691//         is initial data - if @slab is a number, then this does not matter at all and is
 692//         ignored.
 693// @allocator: How to allocate memory, see ALLOC_*
 694function allocate(slab, types, allocator, ptr) {
 695  var zeroinit, size;
 696  if (typeof slab === 'number') {
 697    zeroinit = true;
 698    size = slab;
 699  } else {
 700    zeroinit = false;
 701    size = slab.length;
 702  }
 703
 704  var singleType = typeof types === 'string' ? types : null;
 705
 706  var ret;
 707  if (allocator == ALLOC_NONE) {
 708    ret = ptr;
 709  } else {
 710    ret = [_malloc, Runtime.stackAlloc, Runtime.staticAlloc, Runtime.dynamicAlloc][allocator === undefined ? ALLOC_STATIC : allocator](Math.max(size, singleType ? 1 : types.length));
 711  }
 712
 713  if (zeroinit) {
 714    var ptr = ret, stop;
 715    assert((ret & 3) == 0);
 716    stop = ret + (size & ~3);
 717    for (; ptr < stop; ptr += 4) {
 718      HEAP32[((ptr)>>2)]=0;
 719    }
 720    stop = ret + size;
 721    while (ptr < stop) {
 722      HEAP8[((ptr++)|0)]=0;
 723    }
 724    return ret;
 725  }
 726
 727  if (singleType === 'i8') {
 728    if (slab.subarray || slab.slice) {
 729      HEAPU8.set(slab, ret);
 730    } else {
 731      HEAPU8.set(new Uint8Array(slab), ret);
 732    }
 733    return ret;
 734  }
 735
 736  var i = 0, type, typeSize, previousType;
 737  while (i < size) {
 738    var curr = slab[i];
 739
 740    if (typeof curr === 'function') {
 741      curr = Runtime.getFunctionIndex(curr);
 742    }
 743
 744    type = singleType || types[i];
 745    if (type === 0) {
 746      i++;
 747      continue;
 748    }
 749
 750    if (type == 'i64') type = 'i32'; // special case: we have one i32 here, and one i32 later
 751
 752    setValue(ret+i, curr, type);
 753
 754    // no need to look up size unless type changes, so cache it
 755    if (previousType !== type) {
 756      typeSize = Runtime.getNativeTypeSize(type);
 757      previousType = type;
 758    }
 759    i += typeSize;
 760  }
 761
 762  return ret;
 763}
 764Module['allocate'] = allocate;
 765
 766function Pointer_stringify(ptr, /* optional */ length) {
 767  // TODO: use TextDecoder
 768  // Find the length, and check for UTF while doing so
 769  var hasUtf = false;
 770  var t;
 771  var i = 0;
 772  while (1) {
 773    t = HEAPU8[(((ptr)+(i))|0)];
 774    if (t >= 128) hasUtf = true;
 775    else if (t == 0 && !length) break;
 776    i++;
 777    if (length && i == length) break;
 778  }
 779  if (!length) length = i;
 780
 781  var ret = '';
 782
 783  if (!hasUtf) {
 784    var MAX_CHUNK = 1024; // split up into chunks, because .apply on a huge string can overflow the stack
 785    var curr;
 786    while (length > 0) {
 787      curr = String.fromCharCode.apply(String, HEAPU8.subarray(ptr, ptr + Math.min(length, MAX_CHUNK)));
 788      ret = ret ? ret + curr : curr;
 789      ptr += MAX_CHUNK;
 790      length -= MAX_CHUNK;
 791    }
 792    return ret;
 793  }
 794
 795  var utf8 = new Runtime.UTF8Processor();
 796  for (i = 0; i < length; i++) {
 797    t = HEAPU8[(((ptr)+(i))|0)];
 798    ret += utf8.processCChar(t);
 799  }
 800  return ret;
 801}
 802Module['Pointer_stringify'] = Pointer_stringify;
 803
 804// Given a pointer 'ptr' to a null-terminated UTF16LE-encoded string in the emscripten HEAP, returns
 805// a copy of that string as a Javascript String object.
 806function UTF16ToString(ptr) {
 807  var i = 0;
 808
 809  var str = '';
 810  while (1) {
 811    var codeUnit = HEAP16[(((ptr)+(i*2))>>1)];
 812    if (codeUnit == 0)
 813      return str;
 814    ++i;
 815    // fromCharCode constructs a character from a UTF-16 code unit, so we can pass the UTF16 string right through.
 816    str += String.fromCharCode(codeUnit);
 817  }
 818}
 819Module['UTF16ToString'] = UTF16ToString;
 820
 821// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
 822// null-terminated and encoded in UTF16LE form. The copy will require at most (str.length*2+1)*2 bytes of space in the HEAP.
 823function stringToUTF16(str, outPtr) {
 824  for(var i = 0; i < str.length; ++i) {
 825    // charCodeAt returns a UTF-16 encoded code unit, so it can be directly written to the HEAP.
 826    var codeUnit = str.charCodeAt(i); // possibly a lead surrogate
 827    HEAP16[(((outPtr)+(i*2))>>1)]=codeUnit;
 828  }
 829  // Null-terminate the pointer to the HEAP.
 830  HEAP16[(((outPtr)+(str.length*2))>>1)]=0;
 831}
 832Module['stringToUTF16'] = stringToUTF16;
 833
 834// Given a pointer 'ptr' to a null-terminated UTF32LE-encoded string in the emscripten HEAP, returns
 835// a copy of that string as a Javascript String object.
 836function UTF32ToString(ptr) {
 837  var i = 0;
 838
 839  var str = '';
 840  while (1) {
 841    var utf32 = HEAP32[(((ptr)+(i*4))>>2)];
 842    if (utf32 == 0)
 843      return str;
 844    ++i;
 845    // Gotcha: fromCharCode constructs a character from a UTF-16 encoded code (pair), not from a Unicode code point! So encode the code point to UTF-16 for constructing.
 846    if (utf32 >= 0x10000) {
 847      var ch = utf32 - 0x10000;
 848      str += String.fromCharCode(0xD800 | (ch >> 10), 0xDC00 | (ch & 0x3FF));
 849    } else {
 850      str += String.fromCharCode(utf32);
 851    }
 852  }
 853}
 854Module['UTF32ToString'] = UTF32ToString;
 855
 856// Copies the given Javascript String object 'str' to the emscripten HEAP at address 'outPtr',
 857// null-terminated and encoded in UTF32LE form. The copy will require at most (str.length+1)*4 bytes of space in the HEAP,
 858// but can use less, since str.length does not return the number of characters in the string, but the number of UTF-16 code units in the string.
 859function stringToUTF32(str, outPtr) {
 860  var iChar = 0;
 861  for(var iCodeUnit = 0; iCodeUnit < str.length; ++iCodeUnit) {
 862    // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code unit, not a Unicode code point of the character! We must decode the string to UTF-32 to the heap.
 863    var codeUnit = str.charCodeAt(iCodeUnit); // possibly a lead surrogate
 864    if (codeUnit >= 0xD800 && codeUnit <= 0xDFFF) {
 865      var trailSurrogate = str.charCodeAt(++iCodeUnit);
 866      codeUnit = 0x10000 + ((codeUnit & 0x3FF) << 10) | (trailSurrogate & 0x3FF);
 867    }
 868    HEAP32[(((outPtr)+(iChar*4))>>2)]=codeUnit;
 869    ++iChar;
 870  }
 871  // Null-terminate the pointer to the HEAP.
 872  HEAP32[(((outPtr)+(iChar*4))>>2)]=0;
 873}
 874Module['stringToUTF32'] = stringToUTF32;
 875
 876function demangle(func) {
 877  try {
 878    // Special-case the entry point, since its name differs from other name mangling.
 879    if (func == 'Object._main' || func == '_main') {
 880      return 'main()';
 881    }
 882    if (typeof func === 'number') func = Pointer_stringify(func);
 883    if (func[0] !== '_') return func;
 884    if (func[1] !== '_') return func; // C function
 885    if (func[2] !== 'Z') return func;
 886    switch (func[3]) {
 887      case 'n': return 'operator new()';
 888      case 'd': return 'operator delete()';
 889    }
 890    var i = 3;
 891    // params, etc.
 892    var basicTypes = {
 893      'v': 'void',
 894      'b': 'bool',
 895      'c': 'char',
 896      's': 'short',
 897      'i': 'int',
 898      'l': 'long',
 899      'f': 'float',
 900      'd': 'double',
 901      'w': 'wchar_t',
 902      'a': 'signed char',
 903      'h': 'unsigned char',
 904      't': 'unsigned short',
 905      'j': 'unsigned int',
 906      'm': 'unsigned long',
 907      'x': 'long long',
 908      'y': 'unsigned long long',
 909      'z': '...'
 910    };
 911    function dump(x) {
 912      //return;
 913      if (x) Module.print(x);
 914      Module.print(func);
 915      var pre = '';
 916      for (var a = 0; a < i; a++) pre += ' ';
 917      Module.print (pre + '^');
 918    }
 919    var subs = [];
 920    function parseNested() {
 921      i++;
 922      if (func[i] === 'K') i++; // ignore const
 923      var parts = [];
 924      while (func[i] !== 'E') {
 925        if (func[i] === 'S') { // substitution
 926          i++;
 927          var next = func.indexOf('_', i);
 928          var num = func.substring(i, next) || 0;
 929          parts.push(subs[num] || '?');
 930          i = next+1;
 931          continue;
 932        }
 933        if (func[i] === 'C') { // constructor
 934          parts.push(parts[parts.length-1]);
 935          i += 2;
 936          continue;
 937        }
 938        var size = parseInt(func.substr(i));
 939        var pre = size.toString().length;
 940        if (!size || !pre) { i--; break; } // counter i++ below us
 941        var curr = func.substr(i + pre, size);
 942        parts.push(curr);
 943        subs.push(curr);
 944        i += pre + size;
 945      }
 946      i++; // skip E
 947      return parts;
 948    }
 949    var first = true;
 950    function parse(rawList, limit, allowVoid) { // main parser
 951      limit = limit || Infinity;
 952      var ret = '', list = [];
 953      function flushList() {
 954        return '(' + list.join(', ') + ')';
 955      }
 956      var name;
 957      if (func[i] === 'N') {
 958        // namespaced N-E
 959        name = parseNested().join('::');
 960        limit--;
 961        if (limit === 0) return rawList ? [name] : name;
 962      } else {
 963        // not namespaced
 964        if (func[i] === 'K' || (first && func[i] === 'L')) i++; // ignore const and first 'L'
 965        var size = parseInt(func.substr(i));
 966        if (size) {
 967          var pre = size.toString().length;
 968          name = func.substr(i + pre, size);
 969          i += pre + size;
 970        }
 971      }
 972      first = false;
 973      if (func[i] === 'I') {
 974        i++;
 975        var iList = parse(true);
 976        var iRet = parse(true, 1, true);
 977        ret += iRet[0] + ' ' + name + '<' + iList.join(', ') + '>';
 978      } else {
 979        ret = name;
 980      }
 981      paramLoop: while (i < func.length && limit-- > 0) {
 982        //dump('paramLoop');
 983        var c = func[i++];
 984        if (c in basicTypes) {
 985          list.push(basicTypes[c]);
 986        } else {
 987          switch (c) {
 988            case 'P': list.push(parse(true, 1, true)[0] + '*'); break; // pointer
 989            case 'R': list.push(parse(true, 1, true)[0] + '&'); break; // reference
 990            case 'L': { // literal
 991              i++; // skip basic type
 992              var end = func.indexOf('E', i);
 993              var size = end - i;
 994              list.push(func.substr(i, size));
 995              i += size + 2; // size + 'EE'
 996              break;
 997            }
 998            case 'A': { // array
 999              var size = parseInt(func.substr(i));
1000              i += size.toString().length;
1001              if (func[i] !== '_') throw '?';
1002              i++; // skip _
1003              list.push(parse(true, 1, true)[0] + ' [' + size + ']');
1004              break;
1005            }
1006            case 'E': break paramLoop;
1007            default: ret += '?' + c; break paramLoop;
1008          }
1009        }
1010      }
1011      if (!allowVoid && list.length === 1 && list[0] === 'void') list = []; // avoid (void)
1012      return rawList ? list : ret + flushList();
1013    }
1014    return parse();
1015  } catch(e) {
1016    return func;
1017  }
1018}
1019
1020function demangleAll(text) {
1021  return text.replace(/__Z[\w\d_]+/g, function(x) { var y = demangle(x); return x === y ? x : (x + ' [' + y + ']') });
1022}
1023
1024function stackTrace() {
1025  var stack = new Error().stack;
1026  return stack ? demangleAll(stack) : '(no stack trace available)'; // Stack trace is not available at least on IE10 and Safari 6.
1027}
1028
1029// Memory management
1030
1031var PAGE_SIZE = 4096;
1032function alignMemoryPage(x) {
1033  return (x+4095)&-4096;
1034}
1035
1036var HEAP;
1037var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
1038
1039var STATIC_BASE = 0, STATICTOP = 0, staticSealed = false; // static area
1040var STACK_BASE = 0, STACKTOP = 0, STACK_MAX = 0; // stack area
1041var DYNAMIC_BASE = 0, DYNAMICTOP = 0; // dynamic area handled by sbrk
1042
1043function enlargeMemory() {
1044  abort('Cannot enlarge memory arrays in asm.js. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value ' + TOTAL_MEMORY + ', or (2) set Module.TOTAL_MEMORY before the program runs.');
1045}
1046
1047var TOTAL_STACK = Module['TOTAL_STACK'] || 5242880;
1048var TOTAL_MEMORY = Module['TOTAL_MEMORY'] || 419430400;
1049var FAST_MEMORY = Module['FAST_MEMORY'] || 2097152;
1050
1051var totalMemory = 4096;
1052while (totalMemory < TOTAL_MEMORY || totalMemory < 2*TOTAL_STACK) {
1053  if (totalMemory < 16*1024*1024) {
1054    totalMemory *= 2;
1055  } else {
1056    totalMemory += 16*1024*1024
1057  }
1058}
1059if (totalMemory !== TOTAL_MEMORY) {
1060  Module.printErr('increasing TOTAL_MEMORY to ' + totalMemory + ' to be more reasonable');
1061  TOTAL_MEMORY = totalMemory;
1062}
1063
1064// Initialize the runtime's memory
1065// check for full engine support (use string 'subarray' to avoid closure compiler confusion)
1066assert(typeof Int32Array !== 'undefined' && typeof Float64Array !== 'undefined' && !!(new Int32Array(1)['subarray']) && !!(new Int32Array(1)['set']),
1067       'Cannot fallback to non-typed array case: Code is too specialized');
1068
1069var buffer = new ArrayBuffer(TOTAL_MEMORY);
1070HEAP8 = new Int8Array(buffer);
1071HEAP16 = new Int16Array(buffer);
1072HEAP32 = new Int32Array(buffer);
1073HEAPU8 = new Uint8Array(buffer);
1074HEAPU16 = new Uint16Array(buffer);
1075HEAPU32 = new Uint32Array(buffer);
1076HEAPF32 = new Float32Array(buffer);
1077HEAPF64 = new Float64Array(buffer);
1078
1079// Endianness check (note: assumes compiler arch was little-endian)
1080HEAP32[0] = 255;
1081assert(HEAPU8[0] === 255 && HEAPU8[3] === 0, 'Typed arrays 2 must be run on a little-endian system');
1082
1083Module['HEAP'] = HEAP;
1084Module['HEAP8'] = HEAP8;
1085Module['HEAP16'] = HEAP16;
1086Module['HEAP32'] = HEAP32;
1087Module['HEAPU8'] = HEAPU8;
1088Module['HEAPU16'] = HEAPU16;
1089Module['HEAPU32'] = HEAPU32;
1090Module['HEAPF32'] = HEAPF32;
1091Module['HEAPF64'] = HEAPF64;
1092
1093function callRuntimeCallbacks(callbacks) {
1094  while(callbacks.length > 0) {
1095    var callback = callbacks.shift();
1096    if (typeof callback == 'function') {
1097      callback();
1098      continue;
1099    }
1100    var func = callback.func;
1101    if (typeof func === 'number') {
1102      if (callback.arg === undefined) {
1103        Runtime.dynCall('v', func);
1104      } else {
1105        Runtime.dynCall('vi', func, [callback.arg]);
1106      }
1107    } else {
1108      func(callback.arg === undefined ? null : callback.arg);
1109    }
1110  }
1111}
1112
1113var __ATPRERUN__  = []; // functions called before the runtime is initialized
1114var __ATINIT__    = []; // functions called during startup
1115var __ATMAIN__    = []; // functions called when main() is to be run
1116var __ATEXIT__    = []; // functions called during shutdown
1117var __ATPOSTRUN__ = []; // functions called after the runtime has exited
1118
1119var runtimeInitialized = false;
1120
1121function preRun() {
1122  // compatibility - merge in anything from Module['preRun'] at this time
1123  if (Module['preRun']) {
1124    if (typeof Module['preRun'] == 'function') Module['preRun'] = [Module['preRun']];
1125    while (Module['preRun'].length) {
1126      addOnPreRun(Module['preRun'].shift());
1127    }
1128  }
1129  callRuntimeCallbacks(__ATPRERUN__);
1130}
1131
1132function ensureInitRuntime() {
1133  if (runtimeInitialized) return;
1134  runtimeInitialized = true;
1135  callRuntimeCallbacks(__ATINIT__);
1136}
1137
1138function preMain() {
1139  callRuntimeCallbacks(__ATMAIN__);
1140}
1141
1142function exitRuntime() {
1143  callRuntimeCallbacks(__ATEXIT__);
1144}
1145
1146function postRun() {
1147  // compatibility - merge in anything from Module['postRun'] at this time
1148  if (Module['postRun']) {
1149    if (typeof Module['postRun'] == 'function') Module['postRun'] = [Module['postRun']];
1150    while (Module['postRun'].length) {
1151      addOnPostRun(Module['postRun'].shift());
1152    }
1153  }
1154  callRuntimeCallbacks(__ATPOSTRUN__);
1155}
1156
1157function addOnPreRun(cb) {
1158  __ATPRERUN__.unshift(cb);
1159}
1160Module['addOnPreRun'] = Module.addOnPreRun = addOnPreRun;
1161
1162function addOnInit(cb) {
1163  __ATINIT__.unshift(cb);
1164}
1165Module['addOnInit'] = Module.addOnInit = addOnInit;
1166
1167function addOnPreMain(cb) {
1168  __ATMAIN__.unshift(cb);
1169}
1170Module['addOnPreMain'] = Module.addOnPreMain = addOnPreMain;
1171
1172function addOnExit(cb) {
1173  __ATEXIT__.unshift(cb);
1174}
1175Module['addOnExit'] = Module.addOnExit = addOnExit;
1176
1177function addOnPostRun(cb) {
1178  __ATPOSTRUN__.unshift(cb);
1179}
1180Module['addOnPostRun'] = Module.addOnPostRun = addOnPostRun;
1181
1182// Tools
1183
1184// This processes a JS string into a C-line array of numbers, 0-terminated.
1185// For LLVM-originating strings, see parser.js:parseLLVMString function
1186function intArrayFromString(stringy, dontAddNull, length /* optional */) {
1187  var ret = (new Runtime.UTF8Processor()).processJSString(stringy);
1188  if (length) {
1189    ret.length = length;
1190  }
1191  if (!dontAddNull) {
1192    ret.push(0);
1193  }
1194  return ret;
1195}
1196Module['intArrayFromString'] = intArrayFromString;
1197
1198function intArrayToString(array) {
1199  var ret = [];
1200  for (var i = 0; i < array.length; i++) {
1201    var chr = array[i];
1202    if (chr > 0xFF) {
1203      chr &= 0xFF;
1204    }
1205    ret.push(String.fromCharCode(chr));
1206  }
1207  return ret.join('');
1208}
1209Module['intArrayToString'] = intArrayToString;
1210
1211// Write a Javascript array to somewhere in the heap
1212function writeStringToMemory(string, buffer, dontAddNull) {
1213  var array = intArrayFromString(string, dontAddNull);
1214  var i = 0;
1215  while (i < array.length) {
1216    var chr = array[i];
1217    HEAP8[(((buffer)+(i))|0)]=chr;
1218    i = i + 1;
1219  }
1220}
1221Module['writeStringToMemory'] = writeStringToMemory;
1222
1223function writeArrayToMemory(array, buffer) {
1224  for (var i = 0; i < array.length; i++) {
1225    HEAP8[(((buffer)+(i))|0)]=array[i];
1226  }
1227}
1228Module['writeArrayToMemory'] = writeArrayToMemory;
1229
1230function writeAsciiToMemory(str, buffer, dontAddNull) {
1231  for (var i = 0; i < str.length; i++) {
1232    HEAP8[(((buffer)+(i))|0)]=str.charCodeAt(i);
1233  }
1234  if (!dontAddNull) HEAP8[(((buffer)+(str.length))|0)]=0;
1235}
1236Module['writeAsciiToMemory'] = writeAsciiToMemory;
1237
1238function unSign(value, bits, ignore) {
1239  if (value >= 0) {
1240    return value;
1241  }
1242  return bits <= 32 ? 2*Math.abs(1 << (bits-1)) + value // Need some trickery, since if bits == 32, we are right at the limit of the bits JS uses in bitshifts
1243                    : Math.pow(2, bits)         + value;
1244}
1245function reSign(value, bits, ignore) {
1246  if (value <= 0) {
1247    return value;
1248  }
1249  var half = bits <= 32 ? Math.abs(1 << (bits-1)) // abs is needed if bits == 32
1250                        : Math.pow(2, bits-1);
1251  if (value >= half && (bits <= 32 || value > half)) { // for huge values, we can hit the precision limit and always get true here. so don't do that
1252                                                       // but, in general there is no perfect solution here. With 64-bit ints, we get rounding and errors
1253                                                       // TODO: In i64 mode 1, resign the two parts separately and safely
1254    value = -2*half + value; // Cannot bitshift half, as it may be at the limit of the bits JS uses in bitshifts
1255  }
1256  return value;
1257}
1258
1259// check for imul support, and also for correctness ( https://bugs.webkit.org/show_bug.cgi?id=126345 )
1260if (!Math['imul'] || Math['imul'](0xffffffff, 5) !== -5) Math['imul'] = function imul(a, b) {
1261  var ah  = a >>> 16;
1262  var al = a & 0xffff;
1263  var bh  = b >>> 16;
1264  var bl = b & 0xffff;
1265  return (al*bl + ((ah*bl + al*bh) << 16))|0;
1266};
1267Math.imul = Math['imul'];
1268
1269
1270var Math_abs = Math.abs;
1271var Math_cos = Math.cos;
1272var Math_sin = Math.sin;
1273var Math_tan = Math.tan;
1274var Math_acos = Math.acos;
1275var Math_asin = Math.asin;
1276var Math_atan = Math.atan;
1277var Math_atan2 = Math.atan2;
1278var Math_exp = Math.exp;
1279var Math_log = Math.log;
1280var Math_sqrt = Math.sqrt;
1281var Math_ceil = Math.ceil;
1282var Math_floor = Math.floor;
1283var Math_pow = Math.pow;
1284var Math_imul = Math.imul;
1285var Math_fround = Math.fround;
1286var Math_min = Math.min;
1287
1288// A counter of dependencies for calling run(). If we need to
1289// do asynchronous work before running, increment this and
1290// decrement it. Incrementing must happen in a place like
1291// PRE_RUN_ADDITIONS (used by emcc to add file preloading).
1292// Note that you can add dependencies in preRun, even though
1293// it happens right before run - run will be postponed until
1294// the dependencies are met.
1295var runDependencies = 0;
1296var runDependencyWatcher = null;
1297var dependenciesFulfilled = null; // overridden to take different actions when all run dependencies are fulfilled
1298
1299function addRunDependency(id) {
1300  runDependencies++;
1301  if (Module['monitorRunDependencies']) {
1302    Module['monitorRunDependencies'](runDependencies);
1303  }
1304}
1305Module['addRunDependency'] = addRunDependency;
1306function removeRunDependency(id) {
1307  runDependencies--;
1308  if (Module['monitorRunDependencies']) {
1309    Module['monitorRunDependencies'](runDependencies);
1310  }
1311  if (runDependencies == 0) {
1312    if (runDependencyWatcher !== null) {
1313      clearInterval(runDependencyWatcher);
1314      runDependencyWatcher = null;
1315    }
1316    if (dependenciesFulfilled) {
1317      var callback = dependenciesFulfilled;
1318      dependenciesFulfilled = null;
1319      callback(); // can add another dependenciesFulfilled
1320    }
1321  }
1322}
1323Module['removeRunDependency'] = removeRunDependency;
1324
1325Module["preloadedImages"] = {}; // maps url to image data
1326Module["preloadedAudios"] = {}; // maps url to audio data
1327
1328
1329var memoryInitializer = null;
1330
1331// === Body ===
1332
1333
1334
1335STATIC_BASE = 8;
1336
1337STATICTOP = STATIC_BASE + 28152;
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347var _stdout;
1348var _stdout=_stdout=allocate(1, "i32*", ALLOC_STATIC);
1349var _stdin;
1350var _stdin=_stdin=allocate(1, "i32*", ALLOC_STATIC);
1351var _stderr;
1352var _stderr=_stderr=allocate(1, "i32*", ALLOC_STATIC);
1353
1354
1355
1356/* global initializers */ __ATINIT__.push({ func: function() { runPostSets() } },{ func: function() { __GLOBAL__I_a() } });
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282var ___dso_handle;
2283var ___dso_handle=___dso_handle=allocate(1, "i32*", ALLOC_STATIC);
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442var __ZTVN10__cxxabiv120__si_class_type_infoE;
2443__ZTVN10__cxxabiv120__si_class_type_infoE=allocate([0,0,0,0,104,89,0,0,16,1,0,0,10,1,0,0,70,0,0,0,166,0,0,0,10,0,0,0,10,0,0,0,2,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0], "i8", ALLOC_STATIC);;
2444var __ZTVN10__cxxabiv117__class_type_infoE;
2445__ZTVN10__cxxabiv117__class_type_infoE=allocate([0,0,0,0,120,89,0,0,16,1,0,0,90,0,0,0,70,0,0,0,166,0,0,0,10,0,0,0,30,0,0,0,4,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0], "i8", ALLOC_STATIC);;
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026var __ZNSt13runtime_errorC1EPKc;
3027var __ZNSt13runtime_errorD1Ev;
3028var __ZNSt12length_errorD1Ev;
3029var __ZNSt3__16localeC1Ev;
3030var __ZNSt3__16localeC1ERKS0_;
3031var __ZNSt3__16localeD1Ev;
3032var __ZNSt8bad_castC1Ev;
3033var __ZNSt8bad_castD1Ev;
3034var __ZNSt9bad_allocC1Ev;
3035var __ZNSt9bad_allocD1Ev;
3036/* memory initializer */ allocate([105,110,102,111,58,32,102,97,99,116,111,114,105,122,97,116,105,111,110,32,105,115,32,110,111,116,32,115,117,99,99,101,115,115,102,117,108,0,0,0,78,111,116,32,101,110,111,117,103,104,32,109,101,109,111,114,121,32,116,111,32,112,101,114,102,111,114,109,32,102,97,99,116,111,114,105,122,97,116,105,111,110,46,0,0,0,0,0,101,114,114,111,114,32,111,99,99,117,114,114,101,100,32,105,110,32,116,101,99,104,109,117,108,108,101,114,95,109,97,112,95,119,105,116,104,95,98,111,117,110,100,97,114,121,46,0,100,97,116,97,32,97,114,101,32,110,111,116,32,105,110,32,114,105,103,104,116,32,115,105,122,101,44,32,112,108,101,97,115,101,32,99,104,101,99,107,46,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

Large files files are truncated, but you can click here to view the full file