/* [MS-XLSB] 2.4.651 BrtFmt
352369
function parse_BrtFmt(data, length) {
	var ifmt = data.read_shift(2);
	var stFmtCode = parse_XLWideString(data,length-2);
	return [ifmt, stFmtCode];
}
1112530
function parse_PtgFunc(blob, length, opts) {
	var ptg = blob[blob.l] & 0x1F;
	var type = (blob[blob.l] & 0x60)>>5;
	blob.l += 1;
	var iftab = blob.read_shift(opts && opts.biff <= 3 ? 1 : 2);
	return [FtabArgc[iftab], Ftab[iftab], type];
}
1249845
function b64utob64(s) {
    if (s.length % 4 == 2) s = s + "==";
    else if (s.length % 4 == 3) s = s + "=";
    s = s.replace(/-/g, "+");
    s = s.replace(/_/g, "/");
    return s;
}
314313
function rstr2b64(input) {
    var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var output = "";
    var len = input.length;
    for (var i = 0; i < len; i += 3) {
        var triplet = (input.charCodeAt(i) << 16)
            | (i + 1 < len ? input.charCodeAt(i + 1) << 8 : 0)
            | (i + 2 < len ? input.charCodeAt(i + 2) : 0);
        for (var j = 0; j < 4; j++) {
            if (i * 8 + j * 6 > input.length * 8) output += b64pad;
            else output += tab.charAt((triplet >>> 6 * (3 - j)) & 0x3F);
        }
    }
    return output;
}
1205546
function invertBmp(range) {
        var output = '';
        var lastEnd = -1;

        XRegExp.forEach(
            range,
            /(\\x..|\\u....|\\?[\s\S])(?:-(\\x..|\\u....|\\?[\s\S]))?/,
            function(m) {
                var start = charCode(m[1]);
                if (start > (lastEnd + 1)) {
                    output += '\\u' + pad4(hex(lastEnd + 1));
                    if (start > (lastEnd + 2)) {
                        output += '-\\u' + pad4(hex(start - 1));
                    }
                }
                lastEnd = charCode(m[2] || m[1]);
            }
        );

        if (lastEnd < 0xFFFF) {
            output += '\\u' + pad4(hex(lastEnd + 1));
            if (lastEnd < 0xFFFE) {
                output += '-\\uFFFF';
            }
        }

        return output;
    }
68407
function b64toBA(s) {
  //piggyback on b64tohex for now, optimize later
  var h = b64tohex(s);
  var i;
  var a = new Array();
  for(i = 0; 2*i < h.length; ++i) {
    a[i] = parseInt(h.substring(2*i,2*i+2),16);
  }
  return a;
}
476125
function ltrim(str, targetStr) {
    var retStr = "";
    var regStr;

    if (typeof str != "string") {
        return retStr;
    }

    if (typeof targetStr != "string" || !targetStr) {
        targetStr = "\\s";
    }

    regStr = "^" + targetStr + "*(.*?)";
    regStr = new RegExp(regStr);

    str = str.replace(regStr, "$1");
    return str;
}
505565
function parse_PtgMemArea(blob, length, opts) {
	var type = (blob.read_shift(1) >>> 5) & 0x03;
	blob.l += (opts && opts.biff == 2 ? 3 : 4);
	var cce = blob.read_shift(opts && opts.biff == 2 ? 1 : 2);
	return [type, cce];
}
1237800
function bnpFromRadix(s, b)
{
  this.fromInt(0);
  if (b == null) b = 10;
  var cs = this.chunkSize(b);
  var d = Math.pow(b, cs),
    mi = false,
    j = 0,
    w = 0;
  for (var i = 0; i < s.length; ++i)
  {
    var x = intAt(s, i);
    if (x < 0)
    {
      if (s.charAt(i) == "-" && this.signum() == 0) mi = true;
      continue;
    }
    w = b * w + x;
    if (++j >= cs)
    {
      this.dMultiply(d);
      this.dAddOffset(w, 0);
      j = 0;
      w = 0;
    }
  }
  if (j > 0)
  {
    this.dMultiply(Math.pow(b, j));
    this.dAddOffset(w, 0);
  }
  if (mi) Int128.ZERO.subTo(this, this);
}
95311
function _base256_lshift(&$x, $shift)
    {
        if ($shift == 0) {
            return;
        }

        $num_bytes = $shift >> 3; // eg. floor($shift/8)
        $shift &= 7; // eg. $shift % 8

        $carry = 0;
        for ($i = strlen($x) - 1; $i >= 0; --$i) {
            $temp = ord($x[$i]) << $shift | $carry;
            $x[$i] = chr($temp);
            $carry = $temp >> 8;
        }
        $carry = ($carry != 0) ? chr($carry) : '';
        $x = $carry . $x . str_repeat(chr(0), $num_bytes);
    }
1206365
function write_BrtCellIgnoreEC(ref) {
	var o = new_buf(24);
	o.write_shift(4, 4);
	o.write_shift(4, 1);
	write_UncheckedRfX(ref, o);
	return o;
}
1116540
function parse_BIFF2STR(blob, length, opts) {
	var cell = parse_XLSCell(blob, 6);
	++blob.l;
	var str = parse_XLUnicodeString2(blob, length-7, opts);
	cell.t = 'str';
	cell.val = str;
	return cell;
}
591385
function bcryptAsm(stdlib, foreign, heap) {
        "use asm";

        var HEAP32 = new stdlib.Uint32Array(heap);

        var BLOWFISH_NUM_ROUNDS = 16;
        var S_offset = 0x0000;          // length 0x1000 octets
        var S1_offset = 0x0400;
        var S2_offset = 0x0800;
        var S3_offset = 0x0C00;
        var P_offset = 0x1000;          // length 0x0048 (72) octets
        var P_last_offset = 0x1044;
        var crypt_ciphertext_offset = 0x1048;    // length 0x0018 (24) octets
        var LR_offset = 0x01060;        // length 8 octets
        var password_offset = 0x1068;   // length 0x0048 (72) octets
        var salt_offset = 0x10b0;       // length 0x0048 (72) octets, 18 uint32
        var P_LEN = 18;
        var S_LEN = 1024;

        function encrypt(offset) {
            offset = offset|0;
            var i = 0;
            var n = 0;
            var L = 0;
            var R = 0;
            var imax = 0;
            imax = P_offset | BLOWFISH_NUM_ROUNDS << 2;
            
            L = HEAP32[offset >> 2]|0;
            R = HEAP32[offset + 4 >> 2]|0;

            L = L ^ HEAP32[P_offset>>2];
            for (i = P_offset; (i|0) < (imax|0);) {
                // Feistel substitution on left word
                i = (i + 4)>>>0;
                R = R ^ (
                    ((HEAP32[(L >>> 22)>>2] >>> 0) +
                    (HEAP32[(S1_offset | (L >>> 14 & 0x3ff))>>2] >>> 0) ^
                    (HEAP32[(S2_offset | (L >>> 6 & 0x3ff))>>2])) +
                    (HEAP32[(S3_offset | (L << 2 & 0x3ff))>>2] >>> 0)
                ) ^ HEAP32[i>>2];

                // Feistel substitution on right word
                i = (i + 4)>>>0;
                L = L ^ (
                    ((HEAP32[(R >>> 22)>>2] >>> 0) +
                    (HEAP32[(S1_offset | (R >>> 14 & 0x3ff))>>2] >>> 0) ^
                    (HEAP32[(S2_offset | (R >>> 6 & 0x3ff))>>2])) +
                    (HEAP32[(S3_offset | (R << 2 & 0x3ff))>>2] >>> 0)
                ) ^ HEAP32[i>>2];
            }
            HEAP32[offset>>2] = R ^ HEAP32[P_last_offset>>2];
            HEAP32[(offset+4)>>2] = L;
        }

        function expandKey(offset) {
            offset = offset|0;
            var i = 0;
            var off = 0;

            off = P_offset|0;
            for (i = 0; (i|0) < (P_LEN|0); i = (i+1)|0) {
                HEAP32[off >> 2] = HEAP32[off >> 2] ^ HEAP32[offset >> 2];
                offset = (offset + 4)|0;
                off = (off + 4)|0;
            }

            HEAP32[LR_offset >> 2] = 0;
            HEAP32[LR_offset + 4 >> 2] = 0;

            off = P_offset;
            for (i = 0; (i|0) < (P_LEN|0); i = (i+2)|0) {
                encrypt(LR_offset);
                HEAP32[off >> 2] = HEAP32[LR_offset >> 2];
                HEAP32[off + 4 >> 2] = HEAP32[LR_offset + 4 >> 2];
                off = (off + 8)|0;
            }

            off = S_offset;
            for (i = 0; (i|0) < (S_LEN|0); i = (i+2)|0) {
                encrypt(LR_offset);
                HEAP32[off >> 2] = HEAP32[LR_offset >> 2];
                HEAP32[off + 4 >> 2] = HEAP32[LR_offset + 4 >> 2];
                off = (off + 8)|0;
            }
        }

        function expandLoop(i, counterEnd, maxIterations) {
            i = i|0;
            counterEnd = counterEnd|0;
            maxIterations = maxIterations|0;
            var j = 0;

            for (j = 0; (j|0) <= (maxIterations|0); j = (j+1)|0) {
                if ((i>>>0) > (counterEnd>>>0)) break;
                expandKey(password_offset);
                expandKey(salt_offset);
                i = (i+1)>>>0;
            }
            return i|0;
        }

        return {
            encrypt: encrypt,
            expandLoop: expandLoop
        };
    }
1305127
function parse_BrtBeginComment(data, length) {
	var out = {};
	out.iauthor = data.read_shift(4);
	var rfx = parse_UncheckedRfX(data, 16);
	out.rfx = rfx.s;
	out.ref = encode_cell(rfx.s);
	data.l += 16; /*var guid = parse_GUID(data); */
	return out;
}
582470
function BRK() {
		var high, low;

		PC += 1;
		push( (PC & HIGH) >> 8 );
		push( PC & LOW );

		setP();
		push( P|0x10 );

		low = peek(0xfffe);
		high = peek(0xffff) << 8;
		PC = high | low;
	}
950284
function write_BrtCalcProp(data, o) {
	if(!o) o = new_buf(26);
	o.write_shift(4,0); /* force recalc */
	o.write_shift(4,1);
	o.write_shift(4,0);
	write_Xnum(0, o);
	o.write_shift(-4, 1023);
	o.write_shift(1, 0x33);
	o.write_shift(1, 0x00);
	return o;
}
540481
function pss_mgf1_str(seed, len, hash) {
    var mask = '', i = 0;

    while (mask.length < len) {
        mask += hextorstr(hash(rstrtohex(seed + String.fromCharCode.apply(String, [
                (i & 0xff000000) >> 24,
                (i & 0x00ff0000) >> 16,
                (i & 0x0000ff00) >> 8,
                i & 0x000000ff]))));
        i += 1;
    }

    return mask;
}