decContextClearStatus:
   54|  3.04M|decContext *decContextClearStatus(decContext *context, uInt mask) {
   55|  3.04M|  context->status&=~mask;
   56|  3.04M|  return context;
   57|  3.04M|  } // decContextClearStatus
decContextDefault:
   72|      1|decContext * decContextDefault(decContext *context, Int kind) {
   73|       |  // set defaults...
   74|      1|  context->digits=9;                         // 9 digits
   75|      1|  context->emax=DEC_MAX_EMAX;                // 9-digit exponents
  ------------------
  |  |   90|      1|  #define DEC_MAX_EMAX   999999999
  ------------------
   76|      1|  context->emin=DEC_MIN_EMIN;                // .. balanced
  ------------------
  |  |   93|      1|  #define DEC_MIN_EMIN  -999999999
  ------------------
   77|      1|  context->round=DEC_ROUND_HALF_UP;          // 0.5 rises
   78|      1|  context->traps=DEC_Errors;                 // all but informational
  ------------------
  |  |  183|      1|  #define DEC_Errors (DEC_IEEE_754_Division_by_zero |                 \
  |  |  ------------------
  |  |  |  |  167|      1|  #define DEC_IEEE_754_Division_by_zero  (DEC_Division_by_zero)
  |  |  |  |  ------------------
  |  |  |  |  |  |  129|      1|    #define DEC_Division_by_zero     0x00000002
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  184|      1|                      DEC_IEEE_754_Invalid_operation |                \
  |  |  ------------------
  |  |  |  |  173|      1|  #define DEC_IEEE_754_Invalid_operation (DEC_Conversion_syntax |     \
  |  |  |  |  ------------------
  |  |  |  |  |  |  128|      1|    #define DEC_Conversion_syntax    0x00000001
  |  |  |  |  ------------------
  |  |  |  |  174|      1|                                          DEC_Division_impossible |   \
  |  |  |  |  ------------------
  |  |  |  |  |  |  130|      1|    #define DEC_Division_impossible  0x00000004
  |  |  |  |  ------------------
  |  |  |  |  175|      1|                                          DEC_Division_undefined |    \
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|      1|    #define DEC_Division_undefined   0x00000008
  |  |  |  |  ------------------
  |  |  |  |  176|      1|                                          DEC_Insufficient_storage |  \
  |  |  |  |  ------------------
  |  |  |  |  |  |  132|      1|    #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails]  */
  |  |  |  |  ------------------
  |  |  |  |  177|      1|                                          DEC_Invalid_context |       \
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|      1|    #define DEC_Invalid_context      0x00000040
  |  |  |  |  ------------------
  |  |  |  |  178|      1|                                          DEC_Invalid_operation)
  |  |  |  |  ------------------
  |  |  |  |  |  |  135|      1|    #define DEC_Invalid_operation    0x00000080
  |  |  |  |  ------------------
  |  |  ------------------
  |  |  185|      1|                      DEC_IEEE_754_Overflow | DEC_IEEE_754_Underflow)
  |  |  ------------------
  |  |  |  |  179|      1|  #define DEC_IEEE_754_Overflow          (DEC_Overflow)
  |  |  |  |  ------------------
  |  |  |  |  |  |  139|      1|    #define DEC_Overflow             0x00000200
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                                     DEC_IEEE_754_Overflow | DEC_IEEE_754_Underflow)
  |  |  ------------------
  |  |  |  |  180|      1|  #define DEC_IEEE_754_Underflow         (DEC_Underflow)
  |  |  |  |  ------------------
  |  |  |  |  |  |  143|      1|    #define DEC_Underflow            0x00002000
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
   79|      1|  context->status=0;                         // cleared
   80|      1|  context->clamp=0;                          // no clamping
   81|       |  #if DECSUBSET
   82|       |  context->extended=0;                       // cleared
   83|       |  #endif
   84|      1|  switch (kind) {
   85|      1|    case DEC_INIT_BASE:
  ------------------
  |  |  227|      1|  #define DEC_INIT_BASE         0
  ------------------
  |  Branch (85:5): [True: 1, False: 0]
  ------------------
   86|       |      // [use defaults]
   87|      1|      break;
   88|      0|    case DEC_INIT_DECIMAL32:
  ------------------
  |  |  228|      0|  #define DEC_INIT_DECIMAL32   32
  ------------------
  |  Branch (88:5): [True: 0, False: 1]
  ------------------
   89|      0|      context->digits=7;                     // digits
   90|      0|      context->emax=96;                      // Emax
   91|      0|      context->emin=-95;                     // Emin
   92|      0|      context->round=DEC_ROUND_HALF_EVEN;    // 0.5 to nearest even
   93|      0|      context->traps=0;                      // no traps set
   94|      0|      context->clamp=1;                      // clamp exponents
   95|       |      #if DECSUBSET
   96|       |      context->extended=1;                   // set
   97|       |      #endif
   98|      0|      break;
   99|      0|    case DEC_INIT_DECIMAL64:
  ------------------
  |  |  229|      0|  #define DEC_INIT_DECIMAL64   64
  ------------------
  |  Branch (99:5): [True: 0, False: 1]
  ------------------
  100|      0|      context->digits=16;                    // digits
  101|      0|      context->emax=384;                     // Emax
  102|      0|      context->emin=-383;                    // Emin
  103|      0|      context->round=DEC_ROUND_HALF_EVEN;    // 0.5 to nearest even
  104|      0|      context->traps=0;                      // no traps set
  105|      0|      context->clamp=1;                      // clamp exponents
  106|       |      #if DECSUBSET
  107|       |      context->extended=1;                   // set
  108|       |      #endif
  109|      0|      break;
  110|      0|    case DEC_INIT_DECIMAL128:
  ------------------
  |  |  230|      0|  #define DEC_INIT_DECIMAL128 128
  ------------------
  |  Branch (110:5): [True: 0, False: 1]
  ------------------
  111|      0|      context->digits=34;                    // digits
  112|      0|      context->emax=6144;                    // Emax
  113|      0|      context->emin=-6143;                   // Emin
  114|      0|      context->round=DEC_ROUND_HALF_EVEN;    // 0.5 to nearest even
  115|      0|      context->traps=0;                      // no traps set
  116|      0|      context->clamp=1;                      // clamp exponents
  117|       |      #if DECSUBSET
  118|       |      context->extended=1;                   // set
  119|       |      #endif
  120|      0|      break;
  121|       |
  122|      0|    default:                                 // invalid Kind
  ------------------
  |  Branch (122:5): [True: 0, False: 1]
  ------------------
  123|       |      // use defaults, and ..
  124|      0|      decContextSetStatus(context, DEC_Invalid_operation); // trap
  ------------------
  |  |  135|      0|    #define DEC_Invalid_operation    0x00000080
  ------------------
  125|      1|    }
  126|       |
  127|      1|  return context;} // decContextDefault
decContextSetStatus:
  211|  6.69k|decContext * decContextSetStatus(decContext *context, uInt status) {
  212|  6.69k|  context->status|=status;
  213|  6.69k|  if (status & context->traps) raise(SIGFPE);
  ------------------
  |  Branch (213:7): [True: 0, False: 6.69k]
  ------------------
  214|  6.69k|  return context;} // decContextSetStatus

decNumberFromString:
  479|  3.04M|                                decContext *set) {
  480|  3.04M|  Int   exponent=0;                // working exponent [assume 0]
  ------------------
  |  |   92|  3.04M|  #define Int    int32_t
  ------------------
  481|  3.04M|  uByte bits=0;                    // working flags [assume +ve]
  ------------------
  |  |   89|  3.04M|  #define uByte  uint8_t
  ------------------
  482|  3.04M|  Unit  *res;                      // where result will be built
  ------------------
  |  |   94|  3.04M|  #define Unit   decNumberUnit
  |  |  ------------------
  |  |  |  |   59|  3.04M|    #define decNumberUnit uint16_t
  |  |  ------------------
  ------------------
  483|  3.04M|  Unit  resbuff[SD2U(DECBUFFER+9)];// local buffer in case need temporary
  ------------------
  |  |   94|  3.04M|  #define Unit   decNumberUnit
  |  |  ------------------
  |  |  |  |   59|  3.04M|    #define decNumberUnit uint16_t
  |  |  ------------------
  ------------------
  484|       |                                   // [+9 allows for ln() constants]
  485|  3.04M|  Unit  *allocres=NULL;            // -> allocated result, iff allocated
  ------------------
  |  |   94|  3.04M|  #define Unit   decNumberUnit
  |  |  ------------------
  |  |  |  |   59|  3.04M|    #define decNumberUnit uint16_t
  |  |  ------------------
  ------------------
  486|  3.04M|  Int   d=0;                       // count of digits found in decimal part
  ------------------
  |  |   92|  3.04M|  #define Int    int32_t
  ------------------
  487|  3.04M|  const char *dotchar=NULL;        // where dot was found
  488|  3.04M|  const char *cfirst=chars;        // -> first character of decimal part
  489|  3.04M|  const char *last=NULL;           // -> last digit of decimal part
  490|  3.04M|  const char *c;                   // work
  491|  3.04M|  Unit  *up;                       // ..
  ------------------
  |  |   94|  3.04M|  #define Unit   decNumberUnit
  |  |  ------------------
  |  |  |  |   59|  3.04M|    #define decNumberUnit uint16_t
  |  |  ------------------
  ------------------
  492|  3.04M|  #if DECDPUN>1
  493|  3.04M|  Int   cut, out;                  // ..
  ------------------
  |  |   92|  3.04M|  #define Int    int32_t
  ------------------
  494|  3.04M|  #endif
  495|  3.04M|  Int   residue;                   // rounding residue
  ------------------
  |  |   92|  3.04M|  #define Int    int32_t
  ------------------
  496|  3.04M|  uInt  status=0;                  // error code
  ------------------
  |  |   93|  3.04M|  #define uInt   uint32_t
  ------------------
  497|       |
  498|       |  #if DECCHECK
  499|       |  if (decCheckOperands(DECUNRESU, DECUNUSED, DECUNUSED, set))
  500|       |    return decNumberZero(dn);
  501|       |  #endif
  502|       |
  503|  3.04M|  do {                             // status & malloc protection
  504|  29.6M|    for (c=chars;; c++) {          // -> input character
  505|  29.6M|      if (*c>='0' && *c<='9') {    // test for Arabic digit
  ------------------
  |  Branch (505:11): [True: 26.5M, False: 3.04M]
  |  Branch (505:22): [True: 26.5M, False: 9.86k]
  ------------------
  506|  26.5M|        last=c;
  507|  26.5M|        d++;                       // count of real digits
  508|  26.5M|        continue;                  // still in decimal part
  509|  26.5M|        }
  510|  3.05M|      if (*c=='.' && dotchar==NULL) { // first '.'
  ------------------
  |  Branch (510:11): [True: 1.28k, False: 3.05M]
  |  Branch (510:22): [True: 1.28k, False: 1]
  ------------------
  511|  1.28k|        dotchar=c;                 // record offset into decimal part
  512|  1.28k|        if (c==cfirst) cfirst++;   // first digit must follow
  ------------------
  |  Branch (512:13): [True: 348, False: 939]
  ------------------
  513|  1.28k|        continue;}
  514|  3.05M|      if (c==chars) {              // first in string...
  ------------------
  |  Branch (514:11): [True: 7.09k, False: 3.04M]
  ------------------
  515|  7.09k|        if (*c=='-') {             // valid - sign
  ------------------
  |  Branch (515:13): [True: 4.39k, False: 2.69k]
  ------------------
  516|  4.39k|          cfirst++;
  517|  4.39k|          bits=DECNEG;
  ------------------
  |  |   31|  4.39k|  #define DECNEG    0x80      /* Sign; 1=negative, 0=positive or zero */
  ------------------
  518|  4.39k|          continue;}
  519|  2.69k|        if (*c=='+') {             // valid + sign
  ------------------
  |  Branch (519:13): [True: 283, False: 2.41k]
  ------------------
  520|    283|          cfirst++;
  521|    283|          continue;}
  522|  2.69k|        }
  523|       |      // *c is not a digit, or a valid +, -, or '.'
  524|  3.04M|      break;
  525|  3.05M|      } // c
  526|       |
  527|  3.04M|    if (last==NULL) {              // no digits yet
  ------------------
  |  Branch (527:9): [True: 2.44k, False: 3.04M]
  ------------------
  528|  2.44k|      status=DEC_Conversion_syntax;// assume the worst
  ------------------
  |  |  128|  2.44k|    #define DEC_Conversion_syntax    0x00000001
  ------------------
  529|  2.44k|      if (*c=='\0') break;         // and no more to come...
  ------------------
  |  Branch (529:11): [True: 30, False: 2.41k]
  ------------------
  530|       |      #if DECSUBSET
  531|       |      // if subset then infinities and NaNs are not allowed
  532|       |      if (!set->extended) break;   // hopeless
  533|       |      #endif
  534|       |      // Infinities and NaNs are possible, here
  535|  2.41k|      if (dotchar!=NULL) break;    // .. unless had a dot
  ------------------
  |  Branch (535:11): [True: 1, False: 2.41k]
  ------------------
  536|  2.41k|      decNumberZero(dn);           // be optimistic
  537|  2.41k|      if (decBiStr(c, "infinity", "INFINITY")
  ------------------
  |  Branch (537:11): [True: 215, False: 2.20k]
  ------------------
  538|  2.41k|       || decBiStr(c, "inf", "INF")) {
  ------------------
  |  Branch (538:11): [True: 285, False: 1.91k]
  ------------------
  539|    500|        dn->bits=bits | DECINF;
  ------------------
  |  |   32|    500|  #define DECINF    0x40      /* 1=Infinity                           */
  ------------------
  540|    500|        status=0;                  // is OK
  541|    500|        break; // all done
  542|    500|        }
  543|       |      // a NaN expected
  544|       |      // 2003.09.10 NaNs are now permitted to have a sign
  545|  1.91k|      dn->bits=bits | DECNAN;      // assume simple NaN
  ------------------
  |  |   33|  1.91k|  #define DECNAN    0x20      /* 1=NaN                                */
  ------------------
  546|  1.91k|      if (*c=='s' || *c=='S') {    // looks like an sNaN
  ------------------
  |  Branch (546:11): [True: 197, False: 1.71k]
  |  Branch (546:22): [True: 208, False: 1.51k]
  ------------------
  547|    405|        c++;
  548|    405|        dn->bits=bits | DECSNAN;
  ------------------
  |  |   34|    405|  #define DECSNAN   0x10      /* 1=sNaN                               */
  ------------------
  549|    405|        }
  550|  1.91k|      if (*c!='n' && *c!='N') break;    // check caseless "NaN"
  ------------------
  |  Branch (550:11): [True: 1.50k, False: 412]
  |  Branch (550:22): [True: 330, False: 1.17k]
  ------------------
  551|  1.58k|      c++;
  552|  1.58k|      if (*c!='a' && *c!='A') break;    // ..
  ------------------
  |  Branch (552:11): [True: 557, False: 1.02k]
  |  Branch (552:22): [True: 35, False: 522]
  ------------------
  553|  1.55k|      c++;
  554|  1.55k|      if (*c!='n' && *c!='N') break;    // ..
  ------------------
  |  Branch (554:11): [True: 1.03k, False: 511]
  |  Branch (554:22): [True: 30, False: 1.00k]
  ------------------
  555|  1.52k|      c++;
  556|       |      // now either nothing, or nnnn payload, expected
  557|       |      // -> start of integer and skip leading 0s [including plain 0]
  558|  1.71k|      for (cfirst=c; *cfirst=='0';) cfirst++;
  ------------------
  |  Branch (558:22): [True: 195, False: 1.52k]
  ------------------
  559|  1.52k|      if (*cfirst=='\0') {         // "NaN" or "sNaN", maybe with all 0s
  ------------------
  |  Branch (559:11): [True: 1.28k, False: 231]
  ------------------
  560|  1.28k|        status=0;                  // it's good
  561|  1.28k|        break;                     // ..
  562|  1.28k|        }
  563|       |      // something other than 0s; setup last and d as usual [no dots]
  564|   558k|      for (c=cfirst;; c++, d++) {
  565|   558k|        if (*c<'0' || *c>'9') break; // test for Arabic digit
  ------------------
  |  Branch (565:13): [True: 228, False: 558k]
  |  Branch (565:23): [True: 3, False: 558k]
  ------------------
  566|   558k|        last=c;
  567|   558k|        }
  568|    231|      if (*c!='\0') break;         // not all digits
  ------------------
  |  Branch (568:11): [True: 10, False: 221]
  ------------------
  569|    221|      if (d>set->digits-1) {
  ------------------
  |  Branch (569:11): [True: 0, False: 221]
  ------------------
  570|       |        // [NB: payload in a decNumber can be full length unless
  571|       |        // clamped, in which case can only be digits-1]
  572|      0|        if (set->clamp) break;
  ------------------
  |  Branch (572:13): [True: 0, False: 0]
  ------------------
  573|      0|        if (d>set->digits) break;
  ------------------
  |  Branch (573:13): [True: 0, False: 0]
  ------------------
  574|      0|        } // too many digits?
  575|       |      // good; drop through to convert the integer to coefficient
  576|    221|      status=0;                    // syntax is OK
  577|    221|      bits=dn->bits;               // for copy-back
  578|    221|      } // last==NULL
  579|       |
  580|  3.04M|     else if (*c!='\0') {          // more to process...
  ------------------
  |  Branch (580:15): [True: 7.73k, False: 3.03M]
  ------------------
  581|       |      // had some digits; exponent is only valid sequence now
  582|  7.73k|      Flag nege;                   // 1=negative exponent
  ------------------
  |  |   87|  7.73k|  #define Flag   uint8_t
  ------------------
  583|  7.73k|      const char *firstexp;        // -> first significant exponent digit
  584|  7.73k|      status=DEC_Conversion_syntax;// assume the worst
  ------------------
  |  |  128|  7.73k|    #define DEC_Conversion_syntax    0x00000001
  ------------------
  585|  7.73k|      uInt expa=0;                 // accumulator for exponent
  ------------------
  |  |   93|  7.73k|  #define uInt   uint32_t
  ------------------
  586|  7.73k|      if (*c!='e' && *c!='E') break;
  ------------------
  |  Branch (586:11): [True: 6.07k, False: 1.65k]
  |  Branch (586:22): [True: 34, False: 6.04k]
  ------------------
  587|       |      /* Found 'e' or 'E' -- now process explicit exponent */
  588|       |      // 1998.07.11: sign no longer required
  589|  7.69k|      nege=0;
  590|  7.69k|      c++;                         // to (possible) sign
  591|  7.69k|      if (*c=='-') {nege=1; c++;}
  ------------------
  |  Branch (591:11): [True: 5.39k, False: 2.30k]
  ------------------
  592|  2.30k|       else if (*c=='+') c++;
  ------------------
  |  Branch (592:17): [True: 194, False: 2.10k]
  ------------------
  593|  7.69k|      if (*c=='\0') break;
  ------------------
  |  Branch (593:11): [True: 27, False: 7.66k]
  ------------------
  594|       |
  595|  8.08k|      for (; *c=='0' && *(c+1)!='\0';) c++;  // strip insignificant zeros
  ------------------
  |  Branch (595:14): [True: 509, False: 7.57k]
  |  Branch (595:25): [True: 414, False: 95]
  ------------------
  596|  7.66k|      firstexp=c;                            // save exponent digit place
  597|  3.23M|      for (; ;c++) {
  598|  3.23M|        if (*c<'0' || *c>'9') break;         // not a digit
  ------------------
  |  Branch (598:13): [True: 7.66k, False: 3.22M]
  |  Branch (598:23): [True: 5, False: 3.22M]
  ------------------
  599|  3.22M|        expa=X10(expa)+(Int)*c-(Int)'0';
  ------------------
  |  |  163|  3.22M|  #define X10(i)  (((i)<<1)+((i)<<3))
  ------------------
  600|  3.22M|        } // c
  601|       |      // if not now on a '\0', *c must not be a digit
  602|  7.66k|      if (*c!='\0') break;
  ------------------
  |  Branch (602:11): [True: 32, False: 7.63k]
  ------------------
  603|       |
  604|       |      // (this next test must be after the syntax checks)
  605|       |      // if it was too long the exponent may have wrapped, so check
  606|       |      // carefully and set it to a certain overflow if wrap possible
  607|  7.63k|      if (c>=firstexp+9+1) {
  ------------------
  |  Branch (607:11): [True: 6.18k, False: 1.45k]
  ------------------
  608|  6.18k|        if (c>firstexp+9+1 || *firstexp>'1') expa=DECNUMMAXE*2;
  ------------------
  |  |  183|  1.16k|  #define DECNUMMAXE 999999999  /* maximum adjusted exponent ditto    */
  ------------------
  |  Branch (608:13): [True: 230, False: 5.95k]
  |  Branch (608:31): [True: 937, False: 5.01k]
  ------------------
  609|       |        // [up to 1999999999 is OK, for example 1E-1000000998]
  610|  6.18k|        }
  611|  7.63k|      exponent=(Int)expa;               // save exponent
  612|  7.63k|      if (nege) exponent=-exponent;     // was negative
  ------------------
  |  Branch (612:11): [True: 5.38k, False: 2.25k]
  ------------------
  613|  7.63k|      status=0;                         // is OK
  614|  7.63k|      } // stuff after digits
  615|       |
  616|       |    // Here when whole string has been inspected; syntax is good
  617|       |    // cfirst->first digit (never dot), last->last digit (ditto)
  618|       |
  619|       |    // strip leading zeros/dot [leave final 0 if all 0's]
  620|  3.04M|    if (*cfirst=='0') {                 // [cfirst has stepped over .]
  ------------------
  |  Branch (620:9): [True: 396k, False: 2.64M]
  ------------------
  621|   399k|      for (c=cfirst; c<last; c++, cfirst++) {
  ------------------
  |  Branch (621:22): [True: 3.04k, False: 396k]
  ------------------
  622|  3.04k|        if (*c=='.') continue;          // ignore dots
  ------------------
  |  Branch (622:13): [True: 196, False: 2.85k]
  ------------------
  623|  2.85k|        if (*c!='0') break;             // non-zero found
  ------------------
  |  Branch (623:13): [True: 537, False: 2.31k]
  ------------------
  624|  2.31k|        d--;                            // 0 stripped
  625|  2.31k|        } // c
  626|       |      #if DECSUBSET
  627|       |      // make a rapid exit for easy zeros if !extended
  628|       |      if (*cfirst=='0' && !set->extended) {
  629|       |        decNumberZero(dn);              // clean result
  630|       |        break;                          // [could be return]
  631|       |        }
  632|       |      #endif
  633|   396k|      } // at least one leading 0
  634|       |
  635|       |    // Handle decimal point...
  636|  3.04M|    if (dotchar!=NULL && dotchar<last)  // non-trailing '.' found?
  ------------------
  |  Branch (636:9): [True: 1.26k, False: 3.04M]
  |  Branch (636:26): [True: 785, False: 484]
  ------------------
  637|    785|      exponent-=(last-dotchar);         // adjust exponent
  638|       |    // [we can now ignore the .]
  639|       |
  640|       |    // OK, the digits string is good.  Assemble in the decNumber, or in
  641|       |    // a temporary units array if rounding is needed
  642|  3.04M|    if (d<=set->digits) res=dn->lsu;    // fits into supplied decNumber
  ------------------
  |  Branch (642:9): [True: 3.04M, False: 0]
  ------------------
  643|      0|     else {                             // rounding needed
  644|      0|      Int needbytes=D2U(d)*sizeof(Unit);// bytes needed
  ------------------
  |  |   92|      0|  #define Int    int32_t
  ------------------
                    Int needbytes=D2U(d)*sizeof(Unit);// bytes needed
  ------------------
  |  |  264|      0|    #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |  249|      0|  #define DECMAXD2U 49
  |  |  ------------------
  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |   43|      0|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  ------------------
  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |   43|      0|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  ------------------
  |  |  |  Branch (264:21): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  645|      0|      res=resbuff;                      // assume use local buffer
  646|      0|      if (needbytes>(Int)sizeof(resbuff)) { // too big for local
  ------------------
  |  Branch (646:11): [True: 0, False: 0]
  ------------------
  647|      0|        allocres=(Unit *)malloc(needbytes);
  648|      0|        if (allocres==NULL) {status|=DEC_Insufficient_storage; break;}
  ------------------
  |  |  132|      0|    #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails]  */
  ------------------
  |  Branch (648:13): [True: 0, False: 0]
  ------------------
  649|      0|        res=allocres;
  650|      0|        }
  651|      0|      }
  652|       |    // res now -> number lsu, buffer, or allocated storage for Unit array
  653|       |
  654|       |    // Place the coefficient into the selected Unit array
  655|       |    // [this is often 70% of the cost of this function when DECDPUN>1]
  656|  3.04M|    #if DECDPUN>1
  657|  3.04M|    out=0;                         // accumulator
  658|  3.04M|    up=res+D2U(d)-1;               // -> msu
  ------------------
  |  |  264|  3.04M|    #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |  249|  3.04M|  #define DECMAXD2U 49
  |  |  ------------------
  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |   43|  1.10k|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  ------------------
  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |   43|  1.10k|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  ------------------
  |  |  |  Branch (264:21): [True: 3.04M, False: 1.10k]
  |  |  ------------------
  ------------------
  659|  3.04M|    cut=d-(up-res)*DECDPUN;        // digits in top unit
  ------------------
  |  |   43|  3.04M|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
  660|  27.1M|    for (c=cfirst;; c++) {         // along the digits
  661|  27.1M|      if (*c=='.') continue;       // ignore '.' [don't decrement cut]
  ------------------
  |  Branch (661:11): [True: 254, False: 27.1M]
  ------------------
  662|  27.1M|      out=X10(out)+(Int)*c-(Int)'0';
  ------------------
  |  |  163|  27.1M|  #define X10(i)  (((i)<<1)+((i)<<3))
  ------------------
  663|  27.1M|      if (c==last) break;          // done [never get to trailing '.']
  ------------------
  |  Branch (663:11): [True: 3.04M, False: 24.0M]
  ------------------
  664|  24.0M|      cut--;
  665|  24.0M|      if (cut>0) continue;         // more for this unit
  ------------------
  |  Branch (665:11): [True: 16.0M, False: 8.01M]
  ------------------
  666|  8.01M|      *up=(Unit)out;               // write unit
  667|  8.01M|      up--;                        // prepare for unit below..
  668|  8.01M|      cut=DECDPUN;                 // ..
  ------------------
  |  |   43|  8.01M|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
  669|  8.01M|      out=0;                       // ..
  670|  8.01M|      } // c
  671|  3.04M|    *up=(Unit)out;                 // write lsu
  672|       |
  673|       |    #else
  674|       |    // DECDPUN==1
  675|       |    up=res;                        // -> lsu
  676|       |    for (c=last; c>=cfirst; c--) { // over each character, from least
  677|       |      if (*c=='.') continue;       // ignore . [don't step up]
  678|       |      *up=(Unit)((Int)*c-(Int)'0');
  679|       |      up++;
  680|       |      } // c
  681|       |    #endif
  682|       |
  683|  3.04M|    dn->bits=bits;
  684|  3.04M|    dn->exponent=exponent;
  685|  3.04M|    dn->digits=d;
  686|       |
  687|       |    // if not in number (too long) shorten into the number
  688|  3.04M|    if (d>set->digits) {
  ------------------
  |  Branch (688:9): [True: 0, False: 3.04M]
  ------------------
  689|      0|      residue=0;
  690|      0|      decSetCoeff(dn, set, res, d, &residue, &status);
  691|       |      // always check for overflow or subnormal and round as needed
  692|      0|      decFinalize(dn, set, &residue, &status);
  693|      0|      }
  694|  3.04M|     else { // no rounding, but may still have overflow or subnormal
  695|       |      // [these tests are just for performance; finalize repeats them]
  696|  3.04M|      if ((dn->exponent-1<set->emin-dn->digits)
  ------------------
  |  Branch (696:11): [True: 5.12k, False: 3.03M]
  ------------------
  697|  3.04M|       || (dn->exponent-1>set->emax-set->digits)) {
  ------------------
  |  Branch (697:11): [True: 1.53k, False: 3.03M]
  ------------------
  698|  6.65k|        residue=0;
  699|  6.65k|        decFinalize(dn, set, &residue, &status);
  700|  6.65k|        }
  701|  3.04M|      }
  702|       |    // decNumberShow(dn);
  703|  3.04M|    } while(0);                         // [for break]
  ------------------
  |  Branch (703:13): [Folded - Ignored]
  ------------------
  704|       |
  705|  3.04M|  if (allocres!=NULL) free(allocres);   // drop any storage used
  ------------------
  |  Branch (705:7): [True: 0, False: 3.04M]
  ------------------
  706|  3.04M|  if (status!=0) decStatus(dn, status, set);
  ------------------
  |  Branch (706:7): [True: 6.69k, False: 3.03M]
  ------------------
  707|  3.04M|  return dn;
  708|  3.04M|  } /* decNumberFromString */
decNumberZero:
 3588|  3.48k|decNumber * decNumberZero(decNumber *dn) {
 3589|       |
 3590|       |  #if DECCHECK
 3591|       |  if (decCheckOperands(dn, DECUNUSED, DECUNUSED, DECUNCONT)) return dn;
 3592|       |  #endif
 3593|       |
 3594|  3.48k|  dn->bits=0;
 3595|  3.48k|  dn->exponent=0;
 3596|  3.48k|  dn->digits=1;
 3597|  3.48k|  dn->lsu[0]=0;
 3598|  3.48k|  return dn;
 3599|  3.48k|  } // decNumberZero
decNumber.c:decUnitAddSub:
 6339|  1.99k|                         Unit *c, Int m) {
 6340|  1.99k|  const Unit *alsu=a;              // A lsu [need to remember it]
 6341|  1.99k|  Unit *clsu=c;                    // C ditto
  ------------------
  |  |   94|  1.99k|  #define Unit   decNumberUnit
  |  |  ------------------
  |  |  |  |   59|  1.99k|    #define decNumberUnit uint16_t
  |  |  ------------------
  ------------------
 6342|  1.99k|  Unit *minC;                      // low water mark for C
  ------------------
  |  |   94|  1.99k|  #define Unit   decNumberUnit
  |  |  ------------------
  |  |  |  |   59|  1.99k|    #define decNumberUnit uint16_t
  |  |  ------------------
  ------------------
 6343|  1.99k|  Unit *maxC;                      // high water mark for C
  ------------------
  |  |   94|  1.99k|  #define Unit   decNumberUnit
  |  |  ------------------
  |  |  |  |   59|  1.99k|    #define decNumberUnit uint16_t
  |  |  ------------------
  ------------------
 6344|  1.99k|  eInt carry=0;                    // carry integer (could be Long)
  ------------------
  |  |  203|  1.99k|  #define eInt  Int           // extended integer
  |  |  ------------------
  |  |  |  |   92|  1.99k|  #define Int    int32_t
  |  |  ------------------
  ------------------
 6345|  1.99k|  Int  add;                        // work
  ------------------
  |  |   92|  1.99k|  #define Int    int32_t
  ------------------
 6346|  1.99k|  #if DECDPUN<=4                   // myriadal, millenary, etc.
 6347|  1.99k|  Int  est;                        // estimated quotient
  ------------------
  |  |   92|  1.99k|  #define Int    int32_t
  ------------------
 6348|  1.99k|  #endif
 6349|       |
 6350|       |  #if DECTRACE
 6351|       |  if (alength<1 || blength<1)
 6352|       |    printf("decUnitAddSub: alen blen m %ld %ld [%ld]\n", alength, blength, m);
 6353|       |  #endif
 6354|       |
 6355|  1.99k|  maxC=c+alength;                  // A is usually the longer
 6356|  1.99k|  minC=c+blength;                  // .. and B the shorter
 6357|  1.99k|  if (bshift!=0) {                 // B is shifted; low As copy across
  ------------------
  |  Branch (6357:7): [True: 0, False: 1.99k]
  ------------------
 6358|      0|    minC+=bshift;
 6359|       |    // if in place [common], skip copy unless there's a gap [rare]
 6360|      0|    if (a==c && bshift<=alength) {
  ------------------
  |  Branch (6360:9): [True: 0, False: 0]
  |  Branch (6360:17): [True: 0, False: 0]
  ------------------
 6361|      0|      c+=bshift;
 6362|      0|      a+=bshift;
 6363|      0|      }
 6364|      0|     else for (; c<clsu+bshift; a++, c++) {  // copy needed
  ------------------
  |  Branch (6364:18): [True: 0, False: 0]
  ------------------
 6365|      0|      if (a<alsu+alength) *c=*a;
  ------------------
  |  Branch (6365:11): [True: 0, False: 0]
  ------------------
 6366|      0|       else *c=0;
 6367|      0|      }
 6368|      0|    }
 6369|  1.99k|  if (minC>maxC) { // swap
  ------------------
  |  Branch (6369:7): [True: 0, False: 1.99k]
  ------------------
 6370|      0|    Unit *hold=minC;
  ------------------
  |  |   94|      0|  #define Unit   decNumberUnit
  |  |  ------------------
  |  |  |  |   59|      0|    #define decNumberUnit uint16_t
  |  |  ------------------
  ------------------
 6371|      0|    minC=maxC;
 6372|      0|    maxC=hold;
 6373|      0|    }
 6374|       |
 6375|       |  // For speed, do the addition as two loops; the first where both A
 6376|       |  // and B contribute, and the second (if necessary) where only one or
 6377|       |  // other of the numbers contribute.
 6378|       |  // Carry handling is the same (i.e., duplicated) in each case.
 6379|  3.98k|  for (; c<minC; c++) {
  ------------------
  |  Branch (6379:10): [True: 1.99k, False: 1.99k]
  ------------------
 6380|  1.99k|    carry+=*a;
 6381|  1.99k|    a++;
 6382|  1.99k|    carry+=((eInt)*b)*m;                // [special-casing m=1/-1
 6383|  1.99k|    b++;                                // here is not a win]
 6384|       |    // here carry is new Unit of digits; it could be +ve or -ve
 6385|  1.99k|    if ((ueInt)carry<=DECDPUNMAX) {     // fastpath 0-DECDPUNMAX
  ------------------
  |  |  209|  1.99k|    #define DECDPUNMAX 999
  ------------------
  |  Branch (6385:9): [True: 1.66k, False: 332]
  ------------------
 6386|  1.66k|      *c=(Unit)carry;
 6387|  1.66k|      carry=0;
 6388|  1.66k|      continue;
 6389|  1.66k|      }
 6390|       |    #if DECDPUN==4                           // use divide-by-multiply
 6391|       |      if (carry>=0) {
 6392|       |        est=(((ueInt)carry>>11)*53687)>>18;
 6393|       |        *c=(Unit)(carry-est*(DECDPUNMAX+1)); // remainder
 6394|       |        carry=est;                           // likely quotient [89%]
 6395|       |        if (*c<DECDPUNMAX+1) continue;       // estimate was correct
 6396|       |        carry++;
 6397|       |        *c-=DECDPUNMAX+1;
 6398|       |        continue;
 6399|       |        }
 6400|       |      // negative case
 6401|       |      carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); // make positive
 6402|       |      est=(((ueInt)carry>>11)*53687)>>18;
 6403|       |      *c=(Unit)(carry-est*(DECDPUNMAX+1));
 6404|       |      carry=est-(DECDPUNMAX+1);              // correctly negative
 6405|       |      if (*c<DECDPUNMAX+1) continue;         // was OK
 6406|       |      carry++;
 6407|       |      *c-=DECDPUNMAX+1;
 6408|       |    #elif DECDPUN==3
 6409|    332|      if (carry>=0) {
  ------------------
  |  Branch (6409:11): [True: 332, False: 0]
  ------------------
 6410|    332|        est=(((ueInt)carry>>3)*16777)>>21;
 6411|    332|        *c=(Unit)(carry-est*(DECDPUNMAX+1)); // remainder
  ------------------
  |  |  209|    332|    #define DECDPUNMAX 999
  ------------------
 6412|    332|        carry=est;                           // likely quotient [99%]
 6413|    332|        if (*c<DECDPUNMAX+1) continue;       // estimate was correct
  ------------------
  |  |  209|    332|    #define DECDPUNMAX 999
  ------------------
  |  Branch (6413:13): [True: 0, False: 332]
  ------------------
 6414|    332|        carry++;
 6415|    332|        *c-=DECDPUNMAX+1;
  ------------------
  |  |  209|    332|    #define DECDPUNMAX 999
  ------------------
 6416|    332|        continue;
 6417|    332|        }
 6418|       |      // negative case
 6419|      0|      carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); // make positive
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
                    carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); // make positive
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
 6420|      0|      est=(((ueInt)carry>>3)*16777)>>21;
 6421|      0|      *c=(Unit)(carry-est*(DECDPUNMAX+1));
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
 6422|      0|      carry=est-(DECDPUNMAX+1);              // correctly negative
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
 6423|      0|      if (*c<DECDPUNMAX+1) continue;         // was OK
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
  |  Branch (6423:11): [True: 0, False: 0]
  ------------------
 6424|      0|      carry++;
 6425|      0|      *c-=DECDPUNMAX+1;
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
 6426|       |    #elif DECDPUN<=2
 6427|       |      // Can use QUOT10 as carry <= 4 digits
 6428|       |      if (carry>=0) {
 6429|       |        est=QUOT10(carry, DECDPUN);
 6430|       |        *c=(Unit)(carry-est*(DECDPUNMAX+1)); // remainder
 6431|       |        carry=est;                           // quotient
 6432|       |        continue;
 6433|       |        }
 6434|       |      // negative case
 6435|       |      carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); // make positive
 6436|       |      est=QUOT10(carry, DECDPUN);
 6437|       |      *c=(Unit)(carry-est*(DECDPUNMAX+1));
 6438|       |      carry=est-(DECDPUNMAX+1);              // correctly negative
 6439|       |    #else
 6440|       |      // remainder operator is undefined if negative, so must test
 6441|       |      if ((ueInt)carry<(DECDPUNMAX+1)*2) {   // fastpath carry +1
 6442|       |        *c=(Unit)(carry-(DECDPUNMAX+1));     // [helps additions]
 6443|       |        carry=1;
 6444|       |        continue;
 6445|       |        }
 6446|       |      if (carry>=0) {
 6447|       |        *c=(Unit)(carry%(DECDPUNMAX+1));
 6448|       |        carry=carry/(DECDPUNMAX+1);
 6449|       |        continue;
 6450|       |        }
 6451|       |      // negative case
 6452|       |      carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); // make positive
 6453|       |      *c=(Unit)(carry%(DECDPUNMAX+1));
 6454|       |      carry=carry/(DECDPUNMAX+1)-(DECDPUNMAX+1);
 6455|       |    #endif
 6456|      0|    } // c
 6457|       |
 6458|       |  // now may have one or other to complete
 6459|       |  // [pretest to avoid loop setup/shutdown]
 6460|  2.49M|  if (c<maxC) for (; c<maxC; c++) {
  ------------------
  |  Branch (6460:7): [True: 717, False: 1.27k]
  |  Branch (6460:22): [True: 2.49M, False: 717]
  ------------------
 6461|  2.49M|    if (a<alsu+alength) {               // still in A
  ------------------
  |  Branch (6461:9): [True: 2.49M, False: 0]
  ------------------
 6462|  2.49M|      carry+=*a;
 6463|  2.49M|      a++;
 6464|  2.49M|      }
 6465|      0|     else {                             // inside B
 6466|      0|      carry+=((eInt)*b)*m;
 6467|      0|      b++;
 6468|      0|      }
 6469|       |    // here carry is new Unit of digits; it could be +ve or -ve and
 6470|       |    // magnitude up to DECDPUNMAX squared
 6471|  2.49M|    if ((ueInt)carry<=DECDPUNMAX) {     // fastpath 0-DECDPUNMAX
  ------------------
  |  |  209|  2.49M|    #define DECDPUNMAX 999
  ------------------
  |  Branch (6471:9): [True: 2.03M, False: 464k]
  ------------------
 6472|  2.03M|      *c=(Unit)carry;
 6473|  2.03M|      carry=0;
 6474|  2.03M|      continue;
 6475|  2.03M|      }
 6476|       |    // result for this unit is negative or >DECDPUNMAX
 6477|       |    #if DECDPUN==4                           // use divide-by-multiply
 6478|       |      if (carry>=0) {
 6479|       |        est=(((ueInt)carry>>11)*53687)>>18;
 6480|       |        *c=(Unit)(carry-est*(DECDPUNMAX+1)); // remainder
 6481|       |        carry=est;                           // likely quotient [79.7%]
 6482|       |        if (*c<DECDPUNMAX+1) continue;       // estimate was correct
 6483|       |        carry++;
 6484|       |        *c-=DECDPUNMAX+1;
 6485|       |        continue;
 6486|       |        }
 6487|       |      // negative case
 6488|       |      carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); // make positive
 6489|       |      est=(((ueInt)carry>>11)*53687)>>18;
 6490|       |      *c=(Unit)(carry-est*(DECDPUNMAX+1));
 6491|       |      carry=est-(DECDPUNMAX+1);              // correctly negative
 6492|       |      if (*c<DECDPUNMAX+1) continue;         // was OK
 6493|       |      carry++;
 6494|       |      *c-=DECDPUNMAX+1;
 6495|       |    #elif DECDPUN==3
 6496|   464k|      if (carry>=0) {
  ------------------
  |  Branch (6496:11): [True: 464k, False: 0]
  ------------------
 6497|   464k|        est=(((ueInt)carry>>3)*16777)>>21;
 6498|   464k|        *c=(Unit)(carry-est*(DECDPUNMAX+1)); // remainder
  ------------------
  |  |  209|   464k|    #define DECDPUNMAX 999
  ------------------
 6499|   464k|        carry=est;                           // likely quotient [99%]
 6500|   464k|        if (*c<DECDPUNMAX+1) continue;       // estimate was correct
  ------------------
  |  |  209|   464k|    #define DECDPUNMAX 999
  ------------------
  |  Branch (6500:13): [True: 0, False: 464k]
  ------------------
 6501|   464k|        carry++;
 6502|   464k|        *c-=DECDPUNMAX+1;
  ------------------
  |  |  209|   464k|    #define DECDPUNMAX 999
  ------------------
 6503|   464k|        continue;
 6504|   464k|        }
 6505|       |      // negative case
 6506|      0|      carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); // make positive
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
                    carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); // make positive
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
 6507|      0|      est=(((ueInt)carry>>3)*16777)>>21;
 6508|      0|      *c=(Unit)(carry-est*(DECDPUNMAX+1));
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
 6509|      0|      carry=est-(DECDPUNMAX+1);              // correctly negative
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
 6510|      0|      if (*c<DECDPUNMAX+1) continue;         // was OK
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
  |  Branch (6510:11): [True: 0, False: 0]
  ------------------
 6511|      0|      carry++;
 6512|      0|      *c-=DECDPUNMAX+1;
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
 6513|       |    #elif DECDPUN<=2
 6514|       |      if (carry>=0) {
 6515|       |        est=QUOT10(carry, DECDPUN);
 6516|       |        *c=(Unit)(carry-est*(DECDPUNMAX+1)); // remainder
 6517|       |        carry=est;                           // quotient
 6518|       |        continue;
 6519|       |        }
 6520|       |      // negative case
 6521|       |      carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); // make positive
 6522|       |      est=QUOT10(carry, DECDPUN);
 6523|       |      *c=(Unit)(carry-est*(DECDPUNMAX+1));
 6524|       |      carry=est-(DECDPUNMAX+1);              // correctly negative
 6525|       |    #else
 6526|       |      if ((ueInt)carry<(DECDPUNMAX+1)*2){    // fastpath carry 1
 6527|       |        *c=(Unit)(carry-(DECDPUNMAX+1));
 6528|       |        carry=1;
 6529|       |        continue;
 6530|       |        }
 6531|       |      // remainder operator is undefined if negative, so must test
 6532|       |      if (carry>=0) {
 6533|       |        *c=(Unit)(carry%(DECDPUNMAX+1));
 6534|       |        carry=carry/(DECDPUNMAX+1);
 6535|       |        continue;
 6536|       |        }
 6537|       |      // negative case
 6538|       |      carry=carry+(eInt)(DECDPUNMAX+1)*(DECDPUNMAX+1); // make positive
 6539|       |      *c=(Unit)(carry%(DECDPUNMAX+1));
 6540|       |      carry=carry/(DECDPUNMAX+1)-(DECDPUNMAX+1);
 6541|       |    #endif
 6542|      0|    } // c
 6543|       |
 6544|       |  // OK, all A and B processed; might still have carry or borrow
 6545|       |  // return number of Units in the result, negated if a borrow
 6546|  1.99k|  if (carry==0) return c-clsu;     // no carry, so no more to do
  ------------------
  |  Branch (6546:7): [True: 1.99k, False: 0]
  ------------------
 6547|      0|  if (carry>0) {                   // positive carry
  ------------------
  |  Branch (6547:7): [True: 0, False: 0]
  ------------------
 6548|      0|    *c=(Unit)carry;                // place as new unit
 6549|      0|    c++;                           // ..
 6550|      0|    return c-clsu;
 6551|      0|    }
 6552|       |  // -ve carry: it's a borrow; complement needed
 6553|      0|  add=1;                           // temporary carry...
 6554|      0|  for (c=clsu; c<maxC; c++) {
  ------------------
  |  Branch (6554:16): [True: 0, False: 0]
  ------------------
 6555|      0|    add=DECDPUNMAX+add-*c;
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
 6556|      0|    if (add<=DECDPUNMAX) {
  ------------------
  |  |  209|      0|    #define DECDPUNMAX 999
  ------------------
  |  Branch (6556:9): [True: 0, False: 0]
  ------------------
 6557|      0|      *c=(Unit)add;
 6558|      0|      add=0;
 6559|      0|      }
 6560|      0|     else {
 6561|      0|      *c=0;
 6562|      0|      add=1;
 6563|      0|      }
 6564|      0|    }
 6565|       |  // add an extra unit iff it would be non-zero
 6566|       |  #if DECTRACE
 6567|       |    printf("UAS borrow: add %ld, carry %ld\n", add, carry);
 6568|       |  #endif
 6569|      0|  if ((add-carry-1)!=0) {
  ------------------
  |  Branch (6569:7): [True: 0, False: 0]
  ------------------
 6570|      0|    *c=(Unit)(add-carry-1);
 6571|      0|    c++;                      // interesting, include it
 6572|      0|    }
 6573|      0|  return clsu-c;              // -ve result indicates borrowed
 6574|      0|  } // decUnitAddSub
decNumber.c:decApplyRound:
 7071|  4.44k|                          uInt *status) {
 7072|  4.44k|  Int  bump;                  // 1 if coefficient needs to be incremented
  ------------------
  |  |   92|  4.44k|  #define Int    int32_t
  ------------------
 7073|       |                              // -1 if coefficient needs to be decremented
 7074|       |
 7075|  4.44k|  if (residue==0) return;     // nothing to apply
  ------------------
  |  Branch (7075:7): [True: 573, False: 3.87k]
  ------------------
 7076|       |
 7077|  3.87k|  bump=0;                     // assume a smooth ride
 7078|       |
 7079|       |  // now decide whether, and how, to round, depending on mode
 7080|  3.87k|  switch (set->round) {
 7081|      0|    case DEC_ROUND_05UP: {    // round zero or five up (for reround)
  ------------------
  |  Branch (7081:5): [True: 0, False: 3.87k]
  ------------------
 7082|       |      // This is the same as DEC_ROUND_DOWN unless there is a
 7083|       |      // positive residue and the lsd of dn is 0 or 5, in which case
 7084|       |      // it is bumped; when residue is <0, the number is therefore
 7085|       |      // bumped down unless the final digit was 1 or 6 (in which
 7086|       |      // case it is bumped down and then up -- a no-op)
 7087|      0|      Int lsd5=*dn->lsu%5;     // get lsd and quintate
  ------------------
  |  |   92|      0|  #define Int    int32_t
  ------------------
 7088|      0|      if (residue<0 && lsd5!=1) bump=-1;
  ------------------
  |  Branch (7088:11): [True: 0, False: 0]
  |  Branch (7088:24): [True: 0, False: 0]
  ------------------
 7089|      0|       else if (residue>0 && lsd5==0) bump=1;
  ------------------
  |  Branch (7089:17): [True: 0, False: 0]
  |  Branch (7089:30): [True: 0, False: 0]
  ------------------
 7090|       |      // [bump==1 could be applied directly; use common path for clarity]
 7091|      0|      break;} // r-05
 7092|       |
 7093|      0|    case DEC_ROUND_DOWN: {
  ------------------
  |  Branch (7093:5): [True: 0, False: 3.87k]
  ------------------
 7094|       |      // no change, except if negative residue
 7095|      0|      if (residue<0) bump=-1;
  ------------------
  |  Branch (7095:11): [True: 0, False: 0]
  ------------------
 7096|      0|      break;} // r-d
 7097|       |
 7098|      0|    case DEC_ROUND_HALF_DOWN: {
  ------------------
  |  Branch (7098:5): [True: 0, False: 3.87k]
  ------------------
 7099|      0|      if (residue>5) bump=1;
  ------------------
  |  Branch (7099:11): [True: 0, False: 0]
  ------------------
 7100|      0|      break;} // r-h-d
 7101|       |
 7102|      0|    case DEC_ROUND_HALF_EVEN: {
  ------------------
  |  Branch (7102:5): [True: 0, False: 3.87k]
  ------------------
 7103|      0|      if (residue>5) bump=1;            // >0.5 goes up
  ------------------
  |  Branch (7103:11): [True: 0, False: 0]
  ------------------
 7104|      0|       else if (residue==5) {           // exactly 0.5000...
  ------------------
  |  Branch (7104:17): [True: 0, False: 0]
  ------------------
 7105|       |        // 0.5 goes up iff [new] lsd is odd
 7106|      0|        if (*dn->lsu & 0x01) bump=1;
  ------------------
  |  Branch (7106:13): [True: 0, False: 0]
  ------------------
 7107|      0|        }
 7108|      0|      break;} // r-h-e
 7109|       |
 7110|  3.87k|    case DEC_ROUND_HALF_UP: {
  ------------------
  |  Branch (7110:5): [True: 3.87k, False: 0]
  ------------------
 7111|  3.87k|      if (residue>=5) bump=1;
  ------------------
  |  Branch (7111:11): [True: 3.10k, False: 763]
  ------------------
 7112|  3.87k|      break;} // r-h-u
 7113|       |
 7114|      0|    case DEC_ROUND_UP: {
  ------------------
  |  Branch (7114:5): [True: 0, False: 3.87k]
  ------------------
 7115|      0|      if (residue>0) bump=1;
  ------------------
  |  Branch (7115:11): [True: 0, False: 0]
  ------------------
 7116|      0|      break;} // r-u
 7117|       |
 7118|      0|    case DEC_ROUND_CEILING: {
  ------------------
  |  Branch (7118:5): [True: 0, False: 3.87k]
  ------------------
 7119|       |      // same as _UP for positive numbers, and as _DOWN for negatives
 7120|       |      // [negative residue cannot occur on 0]
 7121|      0|      if (decNumberIsNegative(dn)) {
  ------------------
  |  |  173|      0|  #define decNumberIsNegative(dn)  (((dn)->bits&DECNEG)!=0)
  |  |  ------------------
  |  |  |  |   31|      0|  #define DECNEG    0x80      /* Sign; 1=negative, 0=positive or zero */
  |  |  ------------------
  |  |  |  Branch (173:36): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 7122|      0|        if (residue<0) bump=-1;
  ------------------
  |  Branch (7122:13): [True: 0, False: 0]
  ------------------
 7123|      0|        }
 7124|      0|       else {
 7125|      0|        if (residue>0) bump=1;
  ------------------
  |  Branch (7125:13): [True: 0, False: 0]
  ------------------
 7126|      0|        }
 7127|      0|      break;} // r-c
 7128|       |
 7129|      0|    case DEC_ROUND_FLOOR: {
  ------------------
  |  Branch (7129:5): [True: 0, False: 3.87k]
  ------------------
 7130|       |      // same as _UP for negative numbers, and as _DOWN for positive
 7131|       |      // [negative residue cannot occur on 0]
 7132|      0|      if (!decNumberIsNegative(dn)) {
  ------------------
  |  |  173|      0|  #define decNumberIsNegative(dn)  (((dn)->bits&DECNEG)!=0)
  |  |  ------------------
  |  |  |  |   31|      0|  #define DECNEG    0x80      /* Sign; 1=negative, 0=positive or zero */
  |  |  ------------------
  ------------------
  |  Branch (7132:11): [True: 0, False: 0]
  ------------------
 7133|      0|        if (residue<0) bump=-1;
  ------------------
  |  Branch (7133:13): [True: 0, False: 0]
  ------------------
 7134|      0|        }
 7135|      0|       else {
 7136|      0|        if (residue>0) bump=1;
  ------------------
  |  Branch (7136:13): [True: 0, False: 0]
  ------------------
 7137|      0|        }
 7138|      0|      break;} // r-f
 7139|       |
 7140|      0|    default: {      // e.g., DEC_ROUND_MAX
  ------------------
  |  Branch (7140:5): [True: 0, False: 3.87k]
  ------------------
 7141|      0|      *status|=DEC_Invalid_context;
  ------------------
  |  |  134|      0|    #define DEC_Invalid_context      0x00000040
  ------------------
 7142|       |      #if DECTRACE || (DECCHECK && DECVERB)
 7143|       |      printf("Unknown rounding mode: %d\n", set->round);
 7144|       |      #endif
 7145|      0|      break;}
 7146|  3.87k|    } // switch
 7147|       |
 7148|       |  // now bump the number, up or down, if need be
 7149|  3.87k|  if (bump==0) return;                       // no action required
  ------------------
  |  Branch (7149:7): [True: 763, False: 3.10k]
  ------------------
 7150|       |
 7151|       |  // Simply use decUnitAddSub unless bumping up and the number is
 7152|       |  // all nines.  In this special case set to 100... explicitly
 7153|       |  // and adjust the exponent by one (as otherwise could overflow
 7154|       |  // the array)
 7155|       |  // Similarly handle all-nines result if bumping down.
 7156|  3.10k|  if (bump>0) {
  ------------------
  |  Branch (7156:7): [True: 3.10k, False: 0]
  ------------------
 7157|  3.10k|    Unit *up;                                // work
  ------------------
  |  |   94|  3.10k|  #define Unit   decNumberUnit
  |  |  ------------------
  |  |  |  |   59|  3.10k|    #define decNumberUnit uint16_t
  |  |  ------------------
  ------------------
 7158|  3.10k|    uInt count=dn->digits;                   // digits to be checked
  ------------------
  |  |   93|  3.10k|  #define uInt   uint32_t
  ------------------
 7159|  3.09M|    for (up=dn->lsu; ; up++) {
 7160|  3.09M|      if (count<=DECDPUN) {
  ------------------
  |  |   43|  3.09M|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
  |  Branch (7160:11): [True: 2.59k, False: 3.09M]
  ------------------
 7161|       |        // this is the last Unit (the msu)
 7162|  2.59k|        if (*up!=powers[count]-1) break;     // not still 9s
  ------------------
  |  |  177|  2.59k|#define powers      DECPOWERS      // old internal name
  ------------------
  |  Branch (7162:13): [True: 1.47k, False: 1.11k]
  ------------------
 7163|       |        // here if it, too, is all nines
 7164|  1.11k|        *up=(Unit)powers[count-1];           // here 999 -> 100 etc.
  ------------------
  |  |  177|  1.11k|#define powers      DECPOWERS      // old internal name
  ------------------
 7165|  2.62M|        for (up=up-1; up>=dn->lsu; up--) *up=0; // others all to 0
  ------------------
  |  Branch (7165:23): [True: 2.62M, False: 1.11k]
  ------------------
 7166|  1.11k|        dn->exponent++;                      // and bump exponent
 7167|       |        // [which, very rarely, could cause Overflow...]
 7168|  1.11k|        if ((dn->exponent+dn->digits)>set->emax+1) {
  ------------------
  |  Branch (7168:13): [True: 0, False: 1.11k]
  ------------------
 7169|      0|          decSetOverflow(dn, set, status);
 7170|      0|          }
 7171|  1.11k|        return;                              // done
 7172|  2.59k|        }
 7173|       |      // a full unit to check, with more to come
 7174|  3.09M|      if (*up!=DECDPUNMAX) break;            // not still 9s
  ------------------
  |  |  209|  3.09M|    #define DECDPUNMAX 999
  ------------------
  |  Branch (7174:11): [True: 515, False: 3.09M]
  ------------------
 7175|  3.09M|      count-=DECDPUN;
  ------------------
  |  |   43|  3.09M|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
 7176|  3.09M|      } // up
 7177|  3.10k|    } // bump>0
 7178|      0|   else {                                    // -1
 7179|       |    // here checking for a pre-bump of 1000... (leading 1, all
 7180|       |    // other digits zero)
 7181|      0|    Unit *up, *sup;                          // work
  ------------------
  |  |   94|      0|  #define Unit   decNumberUnit
  |  |  ------------------
  |  |  |  |   59|      0|    #define decNumberUnit uint16_t
  |  |  ------------------
  ------------------
 7182|      0|    uInt count=dn->digits;                   // digits to be checked
  ------------------
  |  |   93|      0|  #define uInt   uint32_t
  ------------------
 7183|      0|    for (up=dn->lsu; ; up++) {
 7184|      0|      if (count<=DECDPUN) {
  ------------------
  |  |   43|      0|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
  |  Branch (7184:11): [True: 0, False: 0]
  ------------------
 7185|       |        // this is the last Unit (the msu)
 7186|      0|        if (*up!=powers[count-1]) break;     // not 100..
  ------------------
  |  |  177|      0|#define powers      DECPOWERS      // old internal name
  ------------------
  |  Branch (7186:13): [True: 0, False: 0]
  ------------------
 7187|       |        // here if have the 1000... case
 7188|      0|        sup=up;                              // save msu pointer
 7189|      0|        *up=(Unit)powers[count]-1;           // here 100 in msu -> 999
  ------------------
  |  |  177|      0|#define powers      DECPOWERS      // old internal name
  ------------------
 7190|       |        // others all to all-nines, too
 7191|      0|        for (up=up-1; up>=dn->lsu; up--) *up=(Unit)powers[DECDPUN]-1;
  ------------------
  |  |  177|      0|#define powers      DECPOWERS      // old internal name
  ------------------
                      for (up=up-1; up>=dn->lsu; up--) *up=(Unit)powers[DECDPUN]-1;
  ------------------
  |  |   43|      0|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
  |  Branch (7191:23): [True: 0, False: 0]
  ------------------
 7192|      0|        dn->exponent--;                      // and bump exponent
 7193|       |
 7194|       |        // iff the number was at the subnormal boundary (exponent=etiny)
 7195|       |        // then the exponent is now out of range, so it will in fact get
 7196|       |        // clamped to etiny and the final 9 dropped.
 7197|       |        // printf(">> emin=%d exp=%d sdig=%d\n", set->emin,
 7198|       |        //        dn->exponent, set->digits);
 7199|      0|        if (dn->exponent+1==set->emin-set->digits+1) {
  ------------------
  |  Branch (7199:13): [True: 0, False: 0]
  ------------------
 7200|      0|          if (count==1 && dn->digits==1) *sup=0;  // here 9 -> 0[.9]
  ------------------
  |  Branch (7200:15): [True: 0, False: 0]
  |  Branch (7200:27): [True: 0, False: 0]
  ------------------
 7201|      0|           else {
 7202|      0|            *sup=(Unit)powers[count-1]-1;    // here 999.. in msu -> 99..
  ------------------
  |  |  177|      0|#define powers      DECPOWERS      // old internal name
  ------------------
 7203|      0|            dn->digits--;
 7204|      0|            }
 7205|      0|          dn->exponent++;
 7206|      0|          *status|=DEC_Underflow | DEC_Subnormal | DEC_Inexact | DEC_Rounded;
  ------------------
  |  |  143|      0|    #define DEC_Underflow            0x00002000
  ------------------
                        *status|=DEC_Underflow | DEC_Subnormal | DEC_Inexact | DEC_Rounded;
  ------------------
  |  |  142|      0|    #define DEC_Subnormal            0x00001000
  ------------------
                        *status|=DEC_Underflow | DEC_Subnormal | DEC_Inexact | DEC_Rounded;
  ------------------
  |  |  133|      0|    #define DEC_Inexact              0x00000020
  ------------------
                        *status|=DEC_Underflow | DEC_Subnormal | DEC_Inexact | DEC_Rounded;
  ------------------
  |  |  141|      0|    #define DEC_Rounded              0x00000800
  ------------------
 7207|      0|          }
 7208|      0|        return;                              // done
 7209|      0|        }
 7210|       |
 7211|       |      // a full unit to check, with more to come
 7212|      0|      if (*up!=0) break;                     // not still 0s
  ------------------
  |  Branch (7212:11): [True: 0, False: 0]
  ------------------
 7213|      0|      count-=DECDPUN;
  ------------------
  |  |   43|      0|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
 7214|      0|      } // up
 7215|       |
 7216|      0|    } // bump<0
 7217|       |
 7218|       |  // Actual bump needed.  Do it.
 7219|  1.99k|  decUnitAddSub(dn->lsu, D2U(dn->digits), uarrone, 1, 0, dn->lsu, bump);
  ------------------
  |  |  264|  1.99k|    #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |  249|  1.99k|  #define DECMAXD2U 49
  |  |  ------------------
  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |   43|    256|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  ------------------
  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |   43|    256|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  ------------------
  |  |  |  Branch (264:21): [True: 1.73k, False: 256]
  |  |  ------------------
  ------------------
 7220|  1.99k|  } // decApplyRound
decNumber.c:decSetOverflow:
 7348|  1.28k|static void decSetOverflow(decNumber *dn, decContext *set, uInt *status) {
 7349|  1.28k|  Flag needmax=0;                  // result is maximum finite value
  ------------------
  |  |   87|  1.28k|  #define Flag   uint8_t
  ------------------
 7350|  1.28k|  uByte sign=dn->bits&DECNEG;      // clean and save sign bit
  ------------------
  |  |   89|  1.28k|  #define uByte  uint8_t
  ------------------
                uByte sign=dn->bits&DECNEG;      // clean and save sign bit
  ------------------
  |  |   31|  1.28k|  #define DECNEG    0x80      /* Sign; 1=negative, 0=positive or zero */
  ------------------
 7351|       |
 7352|  1.28k|  if (ISZERO(dn)) {                // zero does not overflow magnitude
  ------------------
  |  |  255|  1.28k|  #define ISZERO(dn) decNumberIsZero(dn)     /* now just a local name */
  |  |  ------------------
  |  |  |  |  177|  1.28k|  #define decNumberIsZero(dn)      (*(dn)->lsu==0 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (177:37): [True: 960, False: 325]
  |  |  |  |  ------------------
  |  |  |  |  178|  1.28k|                                    && (dn)->digits==1 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:40): [True: 746, False: 214]
  |  |  |  |  ------------------
  |  |  |  |  179|  1.28k|                                    && (((dn)->bits&DECSPECIAL)==0))
  |  |  |  |  ------------------
  |  |  |  |  |  |   36|    746|  #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value     */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   32|    746|  #define DECINF    0x40      /* 1=Infinity                           */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |                 #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value     */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   33|    746|  #define DECNAN    0x20      /* 1=NaN                                */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |                 #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value     */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   34|    746|  #define DECSNAN   0x10      /* 1=sNaN                               */
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (179:40): [True: 746, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7353|    746|    Int emax=set->emax;                      // limit value
  ------------------
  |  |   92|    746|  #define Int    int32_t
  ------------------
 7354|    746|    if (set->clamp) emax-=set->digits-1;     // lower if clamping
  ------------------
  |  Branch (7354:9): [True: 0, False: 746]
  ------------------
 7355|    746|    if (dn->exponent>emax) {                 // clamp required
  ------------------
  |  Branch (7355:9): [True: 746, False: 0]
  ------------------
 7356|    746|      dn->exponent=emax;
 7357|    746|      *status|=DEC_Clamped;
  ------------------
  |  |  140|    746|    #define DEC_Clamped              0x00000400
  ------------------
 7358|    746|      }
 7359|    746|    return;
 7360|    746|    }
 7361|       |
 7362|    539|  decNumberZero(dn);
 7363|    539|  switch (set->round) {
 7364|      0|    case DEC_ROUND_DOWN: {
  ------------------
  |  Branch (7364:5): [True: 0, False: 539]
  ------------------
 7365|      0|      needmax=1;                   // never Infinity
 7366|      0|      break;} // r-d
 7367|      0|    case DEC_ROUND_05UP: {
  ------------------
  |  Branch (7367:5): [True: 0, False: 539]
  ------------------
 7368|      0|      needmax=1;                   // never Infinity
 7369|      0|      break;} // r-05
 7370|      0|    case DEC_ROUND_CEILING: {
  ------------------
  |  Branch (7370:5): [True: 0, False: 539]
  ------------------
 7371|      0|      if (sign) needmax=1;         // Infinity if non-negative
  ------------------
  |  Branch (7371:11): [True: 0, False: 0]
  ------------------
 7372|      0|      break;} // r-c
 7373|      0|    case DEC_ROUND_FLOOR: {
  ------------------
  |  Branch (7373:5): [True: 0, False: 539]
  ------------------
 7374|      0|      if (!sign) needmax=1;        // Infinity if negative
  ------------------
  |  Branch (7374:11): [True: 0, False: 0]
  ------------------
 7375|      0|      break;} // r-f
 7376|    539|    default: break;                // Infinity in all other cases
  ------------------
  |  Branch (7376:5): [True: 539, False: 0]
  ------------------
 7377|    539|    }
 7378|    539|  if (needmax) {
  ------------------
  |  Branch (7378:7): [True: 0, False: 539]
  ------------------
 7379|      0|    decSetMaxValue(dn, set);
 7380|      0|    dn->bits=sign;                 // set sign
 7381|      0|    }
 7382|    539|   else dn->bits=sign|DECINF;      // Value is +/-Infinity
  ------------------
  |  |   32|    539|  #define DECINF    0x40      /* 1=Infinity                           */
  ------------------
 7383|    539|  *status|=DEC_Overflow | DEC_Inexact | DEC_Rounded;
  ------------------
  |  |  139|    539|    #define DEC_Overflow             0x00000200
  ------------------
                *status|=DEC_Overflow | DEC_Inexact | DEC_Rounded;
  ------------------
  |  |  133|    539|    #define DEC_Inexact              0x00000020
  ------------------
                *status|=DEC_Overflow | DEC_Inexact | DEC_Rounded;
  ------------------
  |  |  141|    539|    #define DEC_Rounded              0x00000800
  ------------------
 7384|    539|  } // decSetOverflow
decNumber.c:decShiftToMost:
 6685|  1.11k|static Int decShiftToMost(Unit *uar, Int digits, Int shift) {
 6686|  1.11k|  Unit  *target, *source, *first;  // work
  ------------------
  |  |   94|  1.11k|  #define Unit   decNumberUnit
  |  |  ------------------
  |  |  |  |   59|  1.11k|    #define decNumberUnit uint16_t
  |  |  ------------------
  ------------------
 6687|  1.11k|  Int   cut;                       // odd 0's to add
  ------------------
  |  |   92|  1.11k|  #define Int    int32_t
  ------------------
 6688|  1.11k|  uInt  next;                      // work
  ------------------
  |  |   93|  1.11k|  #define uInt   uint32_t
  ------------------
 6689|       |
 6690|  1.11k|  if (shift==0) return digits;     // [fastpath] nothing to do
  ------------------
  |  Branch (6690:7): [True: 0, False: 1.11k]
  ------------------
 6691|  1.11k|  if ((digits+shift)<=DECDPUN) {   // [fastpath] single-unit case
  ------------------
  |  |   43|  1.11k|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
  |  Branch (6691:7): [True: 233, False: 882]
  ------------------
 6692|    233|    *uar=(Unit)(*uar*powers[shift]);
  ------------------
  |  |  177|    233|#define powers      DECPOWERS      // old internal name
  ------------------
 6693|    233|    return digits+shift;
 6694|    233|    }
 6695|       |
 6696|    882|  next=0;                          // all paths
 6697|    882|  source=uar+D2U(digits)-1;        // where msu comes from
  ------------------
  |  |  264|    882|    #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |  249|    882|  #define DECMAXD2U 49
  |  |  ------------------
  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |   43|    294|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  ------------------
  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |   43|    294|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  ------------------
  |  |  |  Branch (264:21): [True: 588, False: 294]
  |  |  ------------------
  ------------------
 6698|    882|  target=source+D2U(shift);        // where upper part of first cut goes
  ------------------
  |  |  264|    882|    #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |  249|    882|  #define DECMAXD2U 49
  |  |  ------------------
  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |   43|      0|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  ------------------
  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |   43|      0|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  ------------------
  |  |  |  Branch (264:21): [True: 882, False: 0]
  |  |  ------------------
  ------------------
 6699|    882|  cut=DECDPUN-MSUDIGITS(shift);    // where to slice
  ------------------
  |  |   43|    882|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
                cut=DECDPUN-MSUDIGITS(shift);    // where to slice
  ------------------
  |  |  271|    882|  #define MSUDIGITS(d) ((d)-(D2U(d)-1)*DECDPUN)
  |  |  ------------------
  |  |  |  |  264|    882|    #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  |  |  ------------------
  |  |  |  |  |  |  249|    882|  #define DECMAXD2U 49
  |  |  |  |  ------------------
  |  |  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  |  |  ------------------
  |  |  |  |  |  |   43|      0|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  |  |  ------------------
  |  |  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  |  |  ------------------
  |  |  |  |  |  |   43|      0|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (264:21): [True: 882, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  |  |                 #define MSUDIGITS(d) ((d)-(D2U(d)-1)*DECDPUN)
  |  |  ------------------
  |  |  |  |   43|    882|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  ------------------
  ------------------
 6700|    882|  if (cut==0) {                    // unit-boundary case
  ------------------
  |  Branch (6700:7): [True: 0, False: 882]
  ------------------
 6701|      0|    for (; source>=uar; source--, target--) *target=*source;
  ------------------
  |  Branch (6701:12): [True: 0, False: 0]
  ------------------
 6702|      0|    }
 6703|    882|   else {
 6704|    882|    first=uar+D2U(digits+shift)-1; // where msu of source will end up
  ------------------
  |  |  264|    882|    #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |  249|    882|  #define DECMAXD2U 49
  |  |  ------------------
  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |   43|    468|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  ------------------
  |  |                   #define D2U(d) ((d)<=DECMAXD2U?d2utable[d]:((d)+DECDPUN-1)/DECDPUN)
  |  |  ------------------
  |  |  |  |   43|    468|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  |  |  ------------------
  |  |  |  Branch (264:21): [True: 414, False: 468]
  |  |  ------------------
  ------------------
 6705|  2.62M|    for (; source>=uar; source--, target--) {
  ------------------
  |  Branch (6705:12): [True: 2.62M, False: 882]
  ------------------
 6706|       |      // split the source Unit and accumulate remainder for next
 6707|  2.62M|      #if DECDPUN<=4
 6708|  2.62M|        uInt quot=QUOT10(*source, cut);
  ------------------
  |  |   93|  2.62M|  #define uInt   uint32_t
  ------------------
                      uInt quot=QUOT10(*source, cut);
  ------------------
  |  |  210|  2.62M|  #define QUOT10(u, n) ((((uInt)(u)>>(n))*multies[n])>>17)
  ------------------
 6709|  2.62M|        uInt rem=*source-quot*powers[cut];
  ------------------
  |  |   93|  2.62M|  #define uInt   uint32_t
  ------------------
                      uInt rem=*source-quot*powers[cut];
  ------------------
  |  |  177|  2.62M|#define powers      DECPOWERS      // old internal name
  ------------------
 6710|  2.62M|        next+=quot;
 6711|       |      #else
 6712|       |        uInt rem=*source%powers[cut];
 6713|       |        next+=*source/powers[cut];
 6714|       |      #endif
 6715|  2.62M|      if (target<=first) *target=(Unit)next;   // write to target iff valid
  ------------------
  |  Branch (6715:11): [True: 2.62M, False: 693]
  ------------------
 6716|  2.62M|      next=rem*powers[DECDPUN-cut];            // save remainder for next Unit
  ------------------
  |  |  177|  2.62M|#define powers      DECPOWERS      // old internal name
  ------------------
                    next=rem*powers[DECDPUN-cut];            // save remainder for next Unit
  ------------------
  |  |   43|  2.62M|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
 6717|  2.62M|      }
 6718|    882|    } // shift-move
 6719|       |
 6720|       |  // propagate any partial unit to one below and clear the rest
 6721|  1.76k|  for (; target>=uar; target--) {
  ------------------
  |  Branch (6721:10): [True: 882, False: 882]
  ------------------
 6722|    882|    *target=(Unit)next;
 6723|    882|    next=0;
 6724|    882|    }
 6725|    882|  return digits+shift;
 6726|  1.11k|  } // decShiftToMost
decNumber.c:decSetCoeff:
 6890|  4.44k|                        Int len, Int *residue, uInt *status) {
 6891|  4.44k|  Int   discard;              // number of digits to discard
  ------------------
  |  |   92|  4.44k|  #define Int    int32_t
  ------------------
 6892|  4.44k|  uInt  cut;                  // cut point in Unit
  ------------------
  |  |   93|  4.44k|  #define uInt   uint32_t
  ------------------
 6893|  4.44k|  const Unit *up;             // work
 6894|  4.44k|  Unit  *target;              // ..
  ------------------
  |  |   94|  4.44k|  #define Unit   decNumberUnit
  |  |  ------------------
  |  |  |  |   59|  4.44k|    #define decNumberUnit uint16_t
  |  |  ------------------
  ------------------
 6895|  4.44k|  Int   count;                // ..
  ------------------
  |  |   92|  4.44k|  #define Int    int32_t
  ------------------
 6896|  4.44k|  #if DECDPUN<=4
 6897|  4.44k|  uInt  temp;                 // ..
  ------------------
  |  |   93|  4.44k|  #define uInt   uint32_t
  ------------------
 6898|  4.44k|  #endif
 6899|       |
 6900|  4.44k|  discard=len-set->digits;    // digits to discard
 6901|  4.44k|  if (discard<=0) {           // no digits are being discarded
  ------------------
  |  Branch (6901:7): [True: 0, False: 4.44k]
  ------------------
 6902|      0|    if (dn->lsu!=lsu) {       // copy needed
  ------------------
  |  Branch (6902:9): [True: 0, False: 0]
  ------------------
 6903|       |      // copy the coefficient array to the result number; no shift needed
 6904|      0|      count=len;              // avoids D2U
 6905|      0|      up=lsu;
 6906|      0|      for (target=dn->lsu; count>0; target++, up++, count-=DECDPUN)
  ------------------
  |  |   43|      0|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
  |  Branch (6906:28): [True: 0, False: 0]
  ------------------
 6907|      0|        *target=*up;
 6908|      0|      dn->digits=len;         // set the new length
 6909|      0|      }
 6910|       |    // dn->exponent and residue are unchanged, record any inexactitude
 6911|      0|    if (*residue!=0) *status|=(DEC_Inexact | DEC_Rounded);
  ------------------
  |  |  133|      0|    #define DEC_Inexact              0x00000020
  ------------------
                  if (*residue!=0) *status|=(DEC_Inexact | DEC_Rounded);
  ------------------
  |  |  141|      0|    #define DEC_Rounded              0x00000800
  ------------------
  |  Branch (6911:9): [True: 0, False: 0]
  ------------------
 6912|      0|    return;
 6913|      0|    }
 6914|       |
 6915|       |  // some digits must be discarded ...
 6916|  4.44k|  dn->exponent+=discard;      // maintain numerical value
 6917|  4.44k|  *status|=DEC_Rounded;       // accumulate Rounded status
  ------------------
  |  |  141|  4.44k|    #define DEC_Rounded              0x00000800
  ------------------
 6918|  4.44k|  if (*residue>1) *residue=1; // previous residue now to right, so reduce
  ------------------
  |  Branch (6918:7): [True: 0, False: 4.44k]
  ------------------
 6919|       |
 6920|  4.44k|  if (discard>len) {          // everything, +1, is being discarded
  ------------------
  |  Branch (6920:7): [True: 436, False: 4.00k]
  ------------------
 6921|       |    // guard digit is 0
 6922|       |    // residue is all the number [NB could be all 0s]
 6923|    436|    if (*residue<=0) {        // not already positive
  ------------------
  |  Branch (6923:9): [True: 436, False: 0]
  ------------------
 6924|    436|      count=len;              // avoids D2U
 6925|   249k|      for (up=lsu; count>0; up++, count-=DECDPUN) if (*up!=0) { // found non-0
  ------------------
  |  |   43|   248k|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
  |  Branch (6925:20): [True: 249k, False: 0]
  |  Branch (6925:55): [True: 436, False: 248k]
  ------------------
 6926|    436|        *residue=1;
 6927|    436|        break;                // no need to check any others
 6928|    436|        }
 6929|    436|      }
 6930|    436|    if (*residue!=0) *status|=DEC_Inexact; // record inexactitude
  ------------------
  |  |  133|    436|    #define DEC_Inexact              0x00000020
  ------------------
  |  Branch (6930:9): [True: 436, False: 0]
  ------------------
 6931|    436|    *dn->lsu=0;               // coefficient will now be 0
 6932|    436|    dn->digits=1;             // ..
 6933|    436|    return;
 6934|    436|    } // total discard
 6935|       |
 6936|       |  // partial discard [most common case]
 6937|       |  // here, at least the first (most significant) discarded digit exists
 6938|       |
 6939|       |  // spin up the number, noting residue during the spin, until get to
 6940|       |  // the Unit with the first discarded digit.  When reach it, extract
 6941|       |  // it and remember its position
 6942|  4.00k|  count=0;
 6943|   589k|  for (up=lsu;; up++) {
 6944|   589k|    count+=DECDPUN;
  ------------------
  |  |   43|   589k|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
 6945|   589k|    if (count>=discard) break; // full ones all checked
  ------------------
  |  Branch (6945:9): [True: 4.00k, False: 585k]
  ------------------
 6946|   585k|    if (*up!=0) *residue=1;
  ------------------
  |  Branch (6946:9): [True: 51.7k, False: 534k]
  ------------------
 6947|   585k|    } // up
 6948|       |
 6949|       |  // here up -> Unit with first discarded digit
 6950|  4.00k|  cut=discard-(count-DECDPUN)-1;
  ------------------
  |  |   43|  4.00k|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
 6951|  4.00k|  if (cut==DECDPUN-1) {       // unit-boundary case (fast)
  ------------------
  |  |   43|  4.00k|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
  |  Branch (6951:7): [True: 1.41k, False: 2.59k]
  ------------------
 6952|  1.41k|    Unit half=(Unit)powers[DECDPUN]>>1;
  ------------------
  |  |   94|  1.41k|  #define Unit   decNumberUnit
  |  |  ------------------
  |  |  |  |   59|  1.41k|    #define decNumberUnit uint16_t
  |  |  ------------------
  ------------------
                  Unit half=(Unit)powers[DECDPUN]>>1;
  ------------------
  |  |  177|  1.41k|#define powers      DECPOWERS      // old internal name
  ------------------
                  Unit half=(Unit)powers[DECDPUN]>>1;
  ------------------
  |  |   43|  1.41k|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
 6953|       |    // set residue directly
 6954|  1.41k|    if (*up>=half) {
  ------------------
  |  Branch (6954:9): [True: 1.00k, False: 411]
  ------------------
 6955|  1.00k|      if (*up>half) *residue=7;
  ------------------
  |  Branch (6955:11): [True: 615, False: 385]
  ------------------
 6956|    385|      else *residue+=5;       // add sticky bit
 6957|  1.00k|      }
 6958|    411|     else { // <half
 6959|    411|      if (*up!=0) *residue=3; // [else is 0, leave as sticky bit]
  ------------------
  |  Branch (6959:11): [True: 209, False: 202]
  ------------------
 6960|    411|      }
 6961|  1.41k|    if (set->digits<=0) {     // special for Quantize/Subnormal :-(
  ------------------
  |  Branch (6961:9): [True: 600, False: 811]
  ------------------
 6962|    600|      *dn->lsu=0;             // .. result is 0
 6963|    600|      dn->digits=1;           // ..
 6964|    600|      }
 6965|    811|     else {                   // shift to least
 6966|    811|      count=set->digits;      // now digits to end up with
 6967|    811|      dn->digits=count;       // set the new length
 6968|    811|      up++;                   // move to next
 6969|       |      // on unit boundary, so shift-down copy loop is simple
 6970|  3.48M|      for (target=dn->lsu; count>0; target++, up++, count-=DECDPUN)
  ------------------
  |  |   43|  3.48M|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
  |  Branch (6970:28): [True: 3.48M, False: 811]
  ------------------
 6971|  3.48M|        *target=*up;
 6972|    811|      }
 6973|  1.41k|    } // unit-boundary case
 6974|       |
 6975|  2.59k|   else { // discard digit is in low digit(s), and not top digit
 6976|  2.59k|    uInt  discard1;                // first discarded digit
  ------------------
  |  |   93|  2.59k|  #define uInt   uint32_t
  ------------------
 6977|  2.59k|    uInt  quot, rem;               // for divisions
  ------------------
  |  |   93|  2.59k|  #define uInt   uint32_t
  ------------------
 6978|  2.59k|    if (cut==0) quot=*up;          // is at bottom of unit
  ------------------
  |  Branch (6978:9): [True: 2.04k, False: 554]
  ------------------
 6979|    554|     else /* cut>0 */ {            // it's not at bottom of unit
 6980|    554|      #if DECDPUN<=4
 6981|    554|        quot=QUOT10(*up, cut);
  ------------------
  |  |  210|    554|  #define QUOT10(u, n) ((((uInt)(u)>>(n))*multies[n])>>17)
  ------------------
 6982|    554|        rem=*up-quot*powers[cut];
  ------------------
  |  |  177|    554|#define powers      DECPOWERS      // old internal name
  ------------------
 6983|       |      #else
 6984|       |        rem=*up%powers[cut];
 6985|       |        quot=*up/powers[cut];
 6986|       |      #endif
 6987|    554|      if (rem!=0) *residue=1;
  ------------------
  |  Branch (6987:11): [True: 267, False: 287]
  ------------------
 6988|    554|      }
 6989|       |    // discard digit is now at bottom of quot
 6990|  2.59k|    #if DECDPUN<=4
 6991|  2.59k|      temp=(quot*6554)>>16;        // fast /10
 6992|       |      // Vowels algorithm here not a win (9 instructions)
 6993|  2.59k|      discard1=quot-X10(temp);
  ------------------
  |  |  163|  2.59k|  #define X10(i)  (((i)<<1)+((i)<<3))
  ------------------
 6994|  2.59k|      quot=temp;
 6995|       |    #else
 6996|       |      discard1=quot%10;
 6997|       |      quot=quot/10;
 6998|       |    #endif
 6999|       |    // here, discard1 is the guard digit, and residue is everything
 7000|       |    // else [use mapping array to accumulate residue safely]
 7001|  2.59k|    *residue+=resmap[discard1];
 7002|  2.59k|    cut++;                         // update cut
 7003|       |    // here: up -> Unit of the array with bottom digit
 7004|       |    //       cut is the division point for each Unit
 7005|       |    //       quot holds the uncut high-order digits for the current unit
 7006|  2.59k|    if (set->digits<=0) {          // special for Quantize/Subnormal :-(
  ------------------
  |  Branch (7006:9): [True: 758, False: 1.84k]
  ------------------
 7007|    758|      *dn->lsu=0;                  // .. result is 0
 7008|    758|      dn->digits=1;                // ..
 7009|    758|      }
 7010|  1.84k|     else {                        // shift to least needed
 7011|  1.84k|      count=set->digits;           // now digits to end up with
 7012|  1.84k|      dn->digits=count;            // set the new length
 7013|       |      // shift-copy the coefficient array to the result number
 7014|  2.40M|      for (target=dn->lsu; ; target++) {
 7015|  2.40M|        *target=(Unit)quot;
 7016|  2.40M|        count-=(DECDPUN-cut);
  ------------------
  |  |   43|  2.40M|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
 7017|  2.40M|        if (count<=0) break;
  ------------------
  |  Branch (7017:13): [True: 1.45k, False: 2.40M]
  ------------------
 7018|  2.40M|        up++;
 7019|  2.40M|        quot=*up;
 7020|  2.40M|        #if DECDPUN<=4
 7021|  2.40M|          quot=QUOT10(quot, cut);
  ------------------
  |  |  210|  2.40M|  #define QUOT10(u, n) ((((uInt)(u)>>(n))*multies[n])>>17)
  ------------------
 7022|  2.40M|          rem=*up-quot*powers[cut];
  ------------------
  |  |  177|  2.40M|#define powers      DECPOWERS      // old internal name
  ------------------
 7023|       |        #else
 7024|       |          rem=quot%powers[cut];
 7025|       |          quot=quot/powers[cut];
 7026|       |        #endif
 7027|  2.40M|        *target=(Unit)(*target+rem*powers[DECDPUN-cut]);
  ------------------
  |  |  177|  2.40M|#define powers      DECPOWERS      // old internal name
  ------------------
                      *target=(Unit)(*target+rem*powers[DECDPUN-cut]);
  ------------------
  |  |   43|  2.40M|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
 7028|  2.40M|        count-=cut;
 7029|  2.40M|        if (count<=0) break;
  ------------------
  |  Branch (7029:13): [True: 382, False: 2.40M]
  ------------------
 7030|  2.40M|        } // shift-copy loop
 7031|  1.84k|      } // shift to least
 7032|  2.59k|    } // not unit boundary
 7033|       |
 7034|  4.00k|  if (*residue!=0) *status|=DEC_Inexact; // record inexactitude
  ------------------
  |  |  133|  3.43k|    #define DEC_Inexact              0x00000020
  ------------------
  |  Branch (7034:7): [True: 3.43k, False: 573]
  ------------------
 7035|  4.00k|  return;
 7036|  4.44k|  } // decSetCoeff
decNumber.c:decFinalize:
 7275|  6.65k|                        uInt *status) {
 7276|  6.65k|  Int shift;                            // shift needed if clamping
  ------------------
  |  |   92|  6.65k|  #define Int    int32_t
  ------------------
 7277|  6.65k|  Int tinyexp=set->emin-dn->digits+1;   // precalculate subnormal boundary
  ------------------
  |  |   92|  6.65k|  #define Int    int32_t
  ------------------
 7278|       |
 7279|       |  // Must be careful, here, when checking the exponent as the
 7280|       |  // adjusted exponent could overflow 31 bits [because it may already
 7281|       |  // be up to twice the expected].
 7282|       |
 7283|       |  // First test for subnormal.  This must be done before any final
 7284|       |  // round as the result could be rounded to Nmin or 0.
 7285|  6.65k|  if (dn->exponent<=tinyexp) {          // prefilter
  ------------------
  |  Branch (7285:7): [True: 5.12k, False: 1.53k]
  ------------------
 7286|  5.12k|    Int comp;
  ------------------
  |  |   92|  5.12k|  #define Int    int32_t
  ------------------
 7287|  5.12k|    decNumber nmin;
 7288|       |    // A very nasty case here is dn == Nmin and residue<0
 7289|  5.12k|    if (dn->exponent<tinyexp) {
  ------------------
  |  Branch (7289:9): [True: 5.12k, False: 0]
  ------------------
 7290|       |      // Go handle subnormals; this will apply round if needed.
 7291|  5.12k|      decSetSubnormal(dn, set, residue, status);
 7292|  5.12k|      return;
 7293|  5.12k|      }
 7294|       |    // Equals case: only subnormal if dn=Nmin and negative residue
 7295|      0|    decNumberZero(&nmin);
 7296|      0|    nmin.lsu[0]=1;
 7297|      0|    nmin.exponent=set->emin;
 7298|      0|    comp=decCompare(dn, &nmin, 1);                // (signless compare)
 7299|      0|    if (comp==BADINT) {                           // oops
  ------------------
  |  |  194|      0|#define BADINT  (Int)0x80000000    // most-negative Int; error indicator
  ------------------
  |  Branch (7299:9): [True: 0, False: 0]
  ------------------
 7300|      0|      *status|=DEC_Insufficient_storage;          // abandon...
  ------------------
  |  |  132|      0|    #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails]  */
  ------------------
 7301|      0|      return;
 7302|      0|      }
 7303|      0|    if (*residue<0 && comp==0) {                  // neg residue and dn==Nmin
  ------------------
  |  Branch (7303:9): [True: 0, False: 0]
  |  Branch (7303:23): [True: 0, False: 0]
  ------------------
 7304|      0|      decApplyRound(dn, set, *residue, status);   // might force down
 7305|      0|      decSetSubnormal(dn, set, residue, status);
 7306|      0|      return;
 7307|      0|      }
 7308|      0|    }
 7309|       |
 7310|       |  // now apply any pending round (this could raise overflow).
 7311|  1.53k|  if (*residue!=0) decApplyRound(dn, set, *residue, status);
  ------------------
  |  Branch (7311:7): [True: 0, False: 1.53k]
  ------------------
 7312|       |
 7313|       |  // Check for overflow [redundant in the 'rare' case] or clamp
 7314|  1.53k|  if (dn->exponent<=set->emax-set->digits+1) return;   // neither needed
  ------------------
  |  Branch (7314:7): [True: 0, False: 1.53k]
  ------------------
 7315|       |
 7316|       |
 7317|       |  // here when might have an overflow or clamp to do
 7318|  1.53k|  if (dn->exponent>set->emax-dn->digits+1) {           // too big
  ------------------
  |  Branch (7318:7): [True: 1.28k, False: 248]
  ------------------
 7319|  1.28k|    decSetOverflow(dn, set, status);
 7320|  1.28k|    return;
 7321|  1.28k|    }
 7322|       |  // here when the result is normal but in clamp range
 7323|    248|  if (!set->clamp) return;
  ------------------
  |  Branch (7323:7): [True: 248, False: 0]
  ------------------
 7324|       |
 7325|       |  // here when need to apply the IEEE exponent clamp (fold-down)
 7326|      0|  shift=dn->exponent-(set->emax-set->digits+1);
 7327|       |
 7328|       |  // shift coefficient (if non-zero)
 7329|      0|  if (!ISZERO(dn)) {
  ------------------
  |  |  255|      0|  #define ISZERO(dn) decNumberIsZero(dn)     /* now just a local name */
  |  |  ------------------
  |  |  |  |  177|      0|  #define decNumberIsZero(dn)      (*(dn)->lsu==0 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (177:37): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  178|      0|                                    && (dn)->digits==1 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:40): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  |  |  179|      0|                                    && (((dn)->bits&DECSPECIAL)==0))
  |  |  |  |  ------------------
  |  |  |  |  |  |   36|      0|  #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value     */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   32|      0|  #define DECINF    0x40      /* 1=Infinity                           */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |                 #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value     */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   33|      0|  #define DECNAN    0x20      /* 1=NaN                                */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |                 #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value     */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   34|      0|  #define DECSNAN   0x10      /* 1=sNaN                               */
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (179:40): [True: 0, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7330|      0|    dn->digits=decShiftToMost(dn->lsu, dn->digits, shift);
 7331|      0|    }
 7332|      0|  dn->exponent-=shift;   // adjust the exponent to match
 7333|      0|  *status|=DEC_Clamped;  // and record the dirty deed
  ------------------
  |  |  140|      0|    #define DEC_Clamped              0x00000400
  ------------------
 7334|      0|  return;
 7335|    248|  } // decFinalize
decNumber.c:decSetSubnormal:
 7429|  5.12k|                            uInt *status) {
 7430|  5.12k|  decContext workset;         // work
 7431|  5.12k|  Int        etiny, adjust;   // ..
  ------------------
  |  |   92|  5.12k|  #define Int    int32_t
  ------------------
 7432|       |
 7433|       |  #if DECSUBSET
 7434|       |  // simple set to zero and 'hard underflow' for subset
 7435|       |  if (!set->extended) {
 7436|       |    decNumberZero(dn);
 7437|       |    // always full overflow
 7438|       |    *status|=DEC_Underflow | DEC_Subnormal | DEC_Inexact | DEC_Rounded;
 7439|       |    return;
 7440|       |    }
 7441|       |  #endif
 7442|       |
 7443|       |  // Full arithmetic -- allow subnormals, rounded to minimum exponent
 7444|       |  // (Etiny) if needed
 7445|  5.12k|  etiny=set->emin-(set->digits-1);      // smallest allowed exponent
 7446|       |
 7447|  5.12k|  if ISZERO(dn) {                       // value is zero
  ------------------
  |  |  255|  5.12k|  #define ISZERO(dn) decNumberIsZero(dn)     /* now just a local name */
  |  |  ------------------
  |  |  |  |  177|  5.12k|  #define decNumberIsZero(dn)      (*(dn)->lsu==0 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (177:37): [True: 856, False: 4.26k]
  |  |  |  |  ------------------
  |  |  |  |  178|  5.12k|                                    && (dn)->digits==1 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:40): [True: 446, False: 410]
  |  |  |  |  ------------------
  |  |  |  |  179|  5.12k|                                    && (((dn)->bits&DECSPECIAL)==0))
  |  |  |  |  ------------------
  |  |  |  |  |  |   36|    446|  #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value     */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   32|    446|  #define DECINF    0x40      /* 1=Infinity                           */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |                 #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value     */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   33|    446|  #define DECNAN    0x20      /* 1=NaN                                */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |                 #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value     */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   34|    446|  #define DECSNAN   0x10      /* 1=sNaN                               */
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (179:40): [True: 446, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 7448|       |    // residue can never be non-zero here
 7449|       |    #if DECCHECK
 7450|       |      if (*residue!=0) {
 7451|       |        printf("++ Subnormal 0 residue %ld\n", (LI)*residue);
 7452|       |        *status|=DEC_Invalid_operation;
 7453|       |        }
 7454|       |    #endif
 7455|    446|    if (dn->exponent<etiny) {           // clamp required
  ------------------
  |  Branch (7455:9): [True: 204, False: 242]
  ------------------
 7456|    204|      dn->exponent=etiny;
 7457|    204|      *status|=DEC_Clamped;
  ------------------
  |  |  140|    204|    #define DEC_Clamped              0x00000400
  ------------------
 7458|    204|      }
 7459|    446|    return;
 7460|    446|    }
 7461|       |
 7462|  4.67k|  *status|=DEC_Subnormal;               // have a non-zero subnormal
  ------------------
  |  |  142|  4.67k|    #define DEC_Subnormal            0x00001000
  ------------------
 7463|  4.67k|  adjust=etiny-dn->exponent;            // calculate digits to remove
 7464|  4.67k|  if (adjust<=0) {                      // not out of range; unrounded
  ------------------
  |  Branch (7464:7): [True: 231, False: 4.44k]
  ------------------
 7465|       |    // residue can never be non-zero here, except in the Nmin-residue
 7466|       |    // case (which is a subnormal result), so can take fast-path here
 7467|       |    // it may already be inexact (from setting the coefficient)
 7468|    231|    if (*status&DEC_Inexact) *status|=DEC_Underflow;
  ------------------
  |  |  133|    231|    #define DEC_Inexact              0x00000020
  ------------------
                  if (*status&DEC_Inexact) *status|=DEC_Underflow;
  ------------------
  |  |  143|      0|    #define DEC_Underflow            0x00002000
  ------------------
  |  Branch (7468:9): [True: 0, False: 231]
  ------------------
 7469|    231|    return;
 7470|    231|    }
 7471|       |
 7472|       |  // adjust>0, so need to rescale the result so exponent becomes Etiny
 7473|       |  // [this code is similar to that in rescale]
 7474|  4.44k|  workset=*set;                         // clone rounding, etc.
 7475|  4.44k|  workset.digits=dn->digits-adjust;     // set requested length
 7476|  4.44k|  workset.emin-=adjust;                 // and adjust emin to match
 7477|       |  // [note that the latter can be <1, here, similar to Rescale case]
 7478|  4.44k|  decSetCoeff(dn, &workset, dn->lsu, dn->digits, residue, status);
 7479|  4.44k|  decApplyRound(dn, &workset, *residue, status);
 7480|       |
 7481|       |  // Use 754 default rule: Underflow is set iff Inexact
 7482|       |  // [independent of whether trapped]
 7483|  4.44k|  if (*status&DEC_Inexact) *status|=DEC_Underflow;
  ------------------
  |  |  133|  4.44k|    #define DEC_Inexact              0x00000020
  ------------------
                if (*status&DEC_Inexact) *status|=DEC_Underflow;
  ------------------
  |  |  143|  3.87k|    #define DEC_Underflow            0x00002000
  ------------------
  |  Branch (7483:7): [True: 3.87k, False: 573]
  ------------------
 7484|       |
 7485|       |  // if rounded up a 999s case, exponent will be off by one; adjust
 7486|       |  // back if so [it will fit, because it was shortened earlier]
 7487|  4.44k|  if (dn->exponent>etiny) {
  ------------------
  |  Branch (7487:7): [True: 1.11k, False: 3.33k]
  ------------------
 7488|  1.11k|    dn->digits=decShiftToMost(dn->lsu, dn->digits, 1);
 7489|  1.11k|    dn->exponent--;                     // (re)adjust the exponent.
 7490|  1.11k|    }
 7491|       |
 7492|       |  // if rounded to zero, it is by definition clamped...
 7493|  4.44k|  if (ISZERO(dn)) *status|=DEC_Clamped;
  ------------------
  |  |  255|  4.44k|  #define ISZERO(dn) decNumberIsZero(dn)     /* now just a local name */
  |  |  ------------------
  |  |  |  |  177|  4.44k|  #define decNumberIsZero(dn)      (*(dn)->lsu==0 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (177:37): [True: 1.84k, False: 2.59k]
  |  |  |  |  ------------------
  |  |  |  |  178|  4.44k|                                    && (dn)->digits==1 \
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (178:40): [True: 607, False: 1.24k]
  |  |  |  |  ------------------
  |  |  |  |  179|  4.44k|                                    && (((dn)->bits&DECSPECIAL)==0))
  |  |  |  |  ------------------
  |  |  |  |  |  |   36|    607|  #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value     */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   32|    607|  #define DECINF    0x40      /* 1=Infinity                           */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |                 #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value     */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   33|    607|  #define DECNAN    0x20      /* 1=NaN                                */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |                 #define DECSPECIAL (DECINF|DECNAN|DECSNAN) /* any special value     */
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   34|    607|  #define DECSNAN   0x10      /* 1=sNaN                               */
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (179:40): [True: 607, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                if (ISZERO(dn)) *status|=DEC_Clamped;
  ------------------
  |  |  140|    607|    #define DEC_Clamped              0x00000400
  ------------------
 7494|  4.44k|  } // decSetSubnormal
decNumber.c:decBiStr:
 7667|  4.61k|static Flag decBiStr(const char *targ, const char *str1, const char *str2) {
 7668|  8.14k|  for (;;targ++, str1++, str2++) {
 7669|  8.14k|    if (*targ!=*str1 && *targ!=*str2) return 0;
  ------------------
  |  Branch (7669:9): [True: 5.39k, False: 2.75k]
  |  Branch (7669:25): [True: 4.11k, False: 1.27k]
  ------------------
 7670|       |    // *targ has a match in one (or both, if terminator)
 7671|  4.03k|    if (*targ=='\0') break;
  ------------------
  |  Branch (7671:9): [True: 500, False: 3.53k]
  ------------------
 7672|  4.03k|    } // forever
 7673|    500|  return 1;
 7674|  4.61k|  } // decBiStr
decNumber.c:decStatus:
 7741|  6.69k|static void decStatus(decNumber *dn, uInt status, decContext *set) {
 7742|  6.69k|  if (status & DEC_NaNs) {              // error status -> NaN
  ------------------
  |  |  187|  6.69k|  #define DEC_NaNs    DEC_IEEE_754_Invalid_operation
  |  |  ------------------
  |  |  |  |  173|  6.69k|  #define DEC_IEEE_754_Invalid_operation (DEC_Conversion_syntax |     \
  |  |  |  |  ------------------
  |  |  |  |  |  |  128|  6.69k|    #define DEC_Conversion_syntax    0x00000001
  |  |  |  |  ------------------
  |  |  |  |  174|  6.69k|                                          DEC_Division_impossible |   \
  |  |  |  |  ------------------
  |  |  |  |  |  |  130|  6.69k|    #define DEC_Division_impossible  0x00000004
  |  |  |  |  ------------------
  |  |  |  |  175|  6.69k|                                          DEC_Division_undefined |    \
  |  |  |  |  ------------------
  |  |  |  |  |  |  131|  6.69k|    #define DEC_Division_undefined   0x00000008
  |  |  |  |  ------------------
  |  |  |  |  176|  6.69k|                                          DEC_Insufficient_storage |  \
  |  |  |  |  ------------------
  |  |  |  |  |  |  132|  6.69k|    #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails]  */
  |  |  |  |  ------------------
  |  |  |  |  177|  6.69k|                                          DEC_Invalid_context |       \
  |  |  |  |  ------------------
  |  |  |  |  |  |  134|  6.69k|    #define DEC_Invalid_context      0x00000040
  |  |  |  |  ------------------
  |  |  |  |  178|  6.69k|                                          DEC_Invalid_operation)
  |  |  |  |  ------------------
  |  |  |  |  |  |  135|  6.69k|    #define DEC_Invalid_operation    0x00000080
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (7742:7): [True: 529, False: 6.16k]
  ------------------
 7743|       |    // if cause was an sNaN, clear and propagate [NaN is already set up]
 7744|    529|    if (status & DEC_sNaN) status&=~DEC_sNaN;
  ------------------
  |  |  193|    529|#define DEC_sNaN     0x40000000    // local status: sNaN signal
  ------------------
                  if (status & DEC_sNaN) status&=~DEC_sNaN;
  ------------------
  |  |  193|      0|#define DEC_sNaN     0x40000000    // local status: sNaN signal
  ------------------
  |  Branch (7744:9): [True: 0, False: 529]
  ------------------
 7745|    529|     else {
 7746|    529|      decNumberZero(dn);                // other error: clean throughout
 7747|    529|      dn->bits=DECNAN;                  // and make a quiet NaN
  ------------------
  |  |   33|    529|  #define DECNAN    0x20      /* 1=NaN                                */
  ------------------
 7748|    529|      }
 7749|    529|    }
 7750|  6.69k|  decContextSetStatus(set, status);     // [may not return]
 7751|  6.69k|  return;
 7752|  6.69k|  } // decStatus

jv_get_kind:
   98|  47.4M|jv_kind jv_get_kind(jv x) {
   99|  47.4M|  return JVP_KIND(x);
  ------------------
  |  |   86|  47.4M|#define JVP_KIND(j)   (JVP_FLAGS(j) & KIND_MASK)
  |  |  ------------------
  |  |  |  |   85|  47.4M|#define JVP_FLAGS(j)  ((j).kind_flags)
  |  |  ------------------
  |  |               #define JVP_KIND(j)   (JVP_FLAGS(j) & KIND_MASK)
  |  |  ------------------
  |  |  |  |   73|  47.4M|#define KIND_MASK   0xF
  |  |  ------------------
  ------------------
  100|  47.4M|}
jv_true:
  122|    254|jv jv_true() {
  123|    254|  return JV_TRUE;
  124|    254|}
jv_false:
  126|    250|jv jv_false() {
  127|    250|  return JV_FALSE;
  128|    250|}
jv_null:
  130|    573|jv jv_null() {
  131|    573|  return JV_NULL;
  132|    573|}
jv_invalid_with_msg:
  149|  3.83k|jv jv_invalid_with_msg(jv err) {
  150|  3.83k|  jvp_invalid* i = jv_mem_alloc(sizeof(jvp_invalid));
  151|  3.83k|  i->refcnt = JV_REFCNT_INIT;
  152|  3.83k|  i->errmsg = err;
  153|       |
  154|  3.83k|  jv x = {JVP_FLAGS_INVALID_MSG, 0, 0, 0, {&i->refcnt}};
  ------------------
  |  |  142|  3.83k|#define JVP_FLAGS_INVALID_MSG   JVP_MAKE_FLAGS(JV_KIND_INVALID, JVP_PAYLOAD_ALLOCATED)
  |  |  ------------------
  |  |  |  |   83|  3.83k|#define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   73|  3.83k|#define KIND_MASK   0xF
  |  |  |  |  ------------------
  |  |  |  |               #define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   74|  3.83k|#define PFLAGS_MASK 0xF0
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  155|  3.83k|  return x;
  156|  3.83k|}
jv_invalid:
  158|  3.09M|jv jv_invalid() {
  159|  3.09M|  return JV_INVALID;
  160|  3.09M|}
jv_invalid_get_msg:
  162|  1.91k|jv jv_invalid_get_msg(jv inv) {
  163|  1.91k|  assert(JVP_HAS_KIND(inv, JV_KIND_INVALID));
  164|       |
  165|  1.91k|  jv x;
  166|  1.91k|  if (JVP_HAS_FLAGS(inv, JVP_FLAGS_INVALID_MSG)) {
  ------------------
  |  |   88|  1.91k|#define JVP_HAS_FLAGS(j, flags) (JVP_FLAGS(j) == flags)
  |  |  ------------------
  |  |  |  |   85|  1.91k|#define JVP_FLAGS(j)  ((j).kind_flags)
  |  |  ------------------
  |  |  |  Branch (88:33): [True: 1.91k, False: 0]
  |  |  ------------------
  ------------------
  167|  1.91k|    x = jv_copy(((jvp_invalid*)inv.u.ptr)->errmsg);
  168|  1.91k|  }
  169|      0|  else {
  170|      0|    x = jv_null();
  171|      0|  }
  172|       |
  173|  1.91k|  jv_free(inv);
  174|  1.91k|  return x;
  175|  1.91k|}
jv_invalid_has_msg:
  177|  4.90k|int jv_invalid_has_msg(jv inv) {
  178|  4.90k|  assert(JVP_HAS_KIND(inv, JV_KIND_INVALID));
  179|  4.90k|  int r = JVP_HAS_FLAGS(inv, JVP_FLAGS_INVALID_MSG);
  ------------------
  |  |   88|  4.90k|#define JVP_HAS_FLAGS(j, flags) (JVP_FLAGS(j) == flags)
  |  |  ------------------
  |  |  |  |   85|  4.90k|#define JVP_FLAGS(j)  ((j).kind_flags)
  |  |  ------------------
  ------------------
  180|  4.90k|  jv_free(inv);
  181|  4.90k|  return r;
  182|  4.90k|}
jv_tsd_dec_ctx_fini:
  500|      1|void jv_tsd_dec_ctx_fini() {
  501|      1|  jv_mem_free(pthread_getspecific(dec_ctx_key));
  502|      1|  jv_mem_free(pthread_getspecific(dec_ctx_dbl_key));
  503|      1|  pthread_setspecific(dec_ctx_key, NULL);
  504|      1|  pthread_setspecific(dec_ctx_dbl_key, NULL);
  505|      1|}
jv_tsd_dec_ctx_init:
  507|      1|void jv_tsd_dec_ctx_init() {
  508|      1|  if (pthread_key_create(&dec_ctx_key, jv_mem_free) != 0) {
  ------------------
  |  Branch (508:7): [True: 0, False: 1]
  ------------------
  509|      0|    fprintf(stderr, "error: cannot create thread specific key");
  510|      0|    abort();
  511|      0|  }
  512|      1|  if (pthread_key_create(&dec_ctx_dbl_key, jv_mem_free) != 0) {
  ------------------
  |  Branch (512:7): [True: 0, False: 1]
  ------------------
  513|      0|    fprintf(stderr, "error: cannot create thread specific key");
  514|      0|    abort();
  515|      0|  }
  516|      1|  atexit(jv_tsd_dec_ctx_fini);
  517|      1|}
jv_number_with_literal:
  674|  3.04M|jv jv_number_with_literal(const char * literal) {
  675|  3.04M|  return jvp_literal_number_new(literal);
  676|  3.04M|}
jv_array_sized:
  962|  9.28k|jv jv_array_sized(int n) {
  963|  9.28k|  return jvp_array_new(n);
  964|  9.28k|}
jv_array:
  966|  9.28k|jv jv_array() {
  967|  9.28k|  return jv_array_sized(16);
  968|  9.28k|}
jv_array_length:
  970|  3.04M|int jv_array_length(jv j) {
  971|  3.04M|  assert(JVP_HAS_KIND(j, JV_KIND_ARRAY));
  972|  3.04M|  int len = jvp_array_length(j);
  973|  3.04M|  jv_free(j);
  974|  3.04M|  return len;
  975|  3.04M|}
jv_array_set:
  990|  3.04M|jv jv_array_set(jv j, int idx, jv val) {
  991|  3.04M|  assert(JVP_HAS_KIND(j, JV_KIND_ARRAY));
  992|       |
  993|  3.04M|  if (idx < 0)
  ------------------
  |  Branch (993:7): [True: 0, False: 3.04M]
  ------------------
  994|      0|    idx = jvp_array_length(j) + idx;
  995|  3.04M|  if (idx < 0) {
  ------------------
  |  Branch (995:7): [True: 0, False: 3.04M]
  ------------------
  996|      0|    jv_free(j);
  997|      0|    jv_free(val);
  998|      0|    return jv_invalid_with_msg(jv_string("Out of bounds negative array index"));
  999|      0|  }
 1000|       |  // copy/free of val,j coalesced
 1001|  3.04M|  jv* slot = jvp_array_write(&j, idx);
 1002|  3.04M|  jv_free(*slot);
 1003|  3.04M|  *slot = val;
 1004|  3.04M|  return j;
 1005|  3.04M|}
jv_array_append:
 1007|  3.04M|jv jv_array_append(jv j, jv val) {
 1008|       |  // copy/free of val,j coalesced
 1009|  3.04M|  return jv_array_set(j, jv_array_length(jv_copy(j)), val);
 1010|  3.04M|}
jv_string_sized:
 1245|  14.2k|jv jv_string_sized(const char* str, int len) {
 1246|  14.2k|  return
 1247|  14.2k|    jvp_utf8_is_valid(str, str+len) ?
  ------------------
  |  Branch (1247:5): [True: 10.9k, False: 3.29k]
  ------------------
 1248|  10.9k|    jvp_string_new(str, len) :
 1249|  14.2k|    jvp_string_copy_replace_bad(str, len);
 1250|  14.2k|}
jv_string:
 1256|     89|jv jv_string(const char* str) {
 1257|     89|  return jv_string_sized(str, strlen(str));
 1258|     89|}
jv_string_value:
 1375|  1.91k|const char* jv_string_value(jv j) {
 1376|  1.91k|  assert(JVP_HAS_KIND(j, JV_KIND_STRING));
 1377|  1.91k|  return jvp_string_ptr(j)->data;
 1378|  1.91k|}
jv_string_vfmt:
 1457|  3.74k|jv jv_string_vfmt(const char* fmt, va_list ap) {
 1458|  3.74k|  int size = 1024;
 1459|  3.97k|  while (1) {
  ------------------
  |  Branch (1459:10): [Folded - Ignored]
  ------------------
 1460|  3.97k|    char* buf = jv_mem_alloc(size);
 1461|  3.97k|    va_list ap2;
 1462|  3.97k|    va_copy(ap2, ap);
 1463|  3.97k|    int n = vsnprintf(buf, size, fmt, ap2);
 1464|  3.97k|    va_end(ap2);
 1465|       |    /*
 1466|       |     * NOTE: here we support old vsnprintf()s that return -1 because the
 1467|       |     * buffer is too small.
 1468|       |     */
 1469|  3.97k|    if (n >= 0 && n < size) {
  ------------------
  |  Branch (1469:9): [True: 3.97k, False: 0]
  |  Branch (1469:19): [True: 3.74k, False: 228]
  ------------------
 1470|  3.74k|      jv ret = jv_string_sized(buf, n);
 1471|  3.74k|      jv_mem_free(buf);
 1472|  3.74k|      return ret;
 1473|  3.74k|    } else {
 1474|    228|      jv_mem_free(buf);
 1475|    228|      size = (n > 0) ? /* standard */ (n * 2) : /* not standard */ (size * 2);
  ------------------
  |  Branch (1475:14): [True: 228, False: 0]
  ------------------
 1476|    228|    }
 1477|  3.97k|  }
 1478|  3.74k|}
jv_string_fmt:
 1480|  1.91k|jv jv_string_fmt(const char* fmt, ...) {
 1481|  1.91k|  va_list args;
 1482|  1.91k|  va_start(args, fmt);
 1483|  1.91k|  jv res = jv_string_vfmt(fmt, args);
 1484|  1.91k|  va_end(args);
 1485|  1.91k|  return res;
 1486|  1.91k|}
jv_object:
 1747|  7.62k|jv jv_object() {
 1748|  7.62k|  return jvp_object_new(8);
 1749|  7.62k|}
jv_object_set:
 1776|  8.16k|jv jv_object_set(jv object, jv key, jv value) {
 1777|  8.16k|  assert(JVP_HAS_KIND(object, JV_KIND_OBJECT));
 1778|  8.16k|  assert(JVP_HAS_KIND(key, JV_KIND_STRING));
 1779|       |  // copy/free of object, key, value coalesced
 1780|  8.16k|  jv* slot = jvp_object_write(&object, key);
 1781|  8.16k|  jv_free(*slot);
 1782|  8.16k|  *slot = value;
 1783|  8.16k|  return object;
 1784|  8.16k|}
jv_object_length:
 1794|    828|int jv_object_length(jv object) {
 1795|    828|  assert(JVP_HAS_KIND(object, JV_KIND_OBJECT));
 1796|    828|  int n = jvp_object_length(object);
 1797|    828|  jv_free(object);
 1798|    828|  return n;
 1799|    828|}
jv_copy:
 1872|  10.7M|jv jv_copy(jv j) {
 1873|  10.7M|  if (JVP_IS_ALLOCATED(j)) {
  ------------------
  |  |   91|  10.7M|#define JVP_IS_ALLOCATED(j) (j.kind_flags & JVP_PAYLOAD_ALLOCATED)
  |  |  ------------------
  |  |  |  Branch (91:29): [True: 10.7M, False: 2.62k]
  |  |  ------------------
  ------------------
 1874|  10.7M|    jvp_refcnt_inc(j.u.ptr);
 1875|  10.7M|  }
 1876|  10.7M|  return j;
 1877|  10.7M|}
jv_free:
 1879|  19.9M|void jv_free(jv j) {
 1880|  19.9M|  switch(JVP_KIND(j)) {
  ------------------
  |  |   86|  19.9M|#define JVP_KIND(j)   (JVP_FLAGS(j) & KIND_MASK)
  |  |  ------------------
  |  |  |  |   85|  19.9M|#define JVP_FLAGS(j)  ((j).kind_flags)
  |  |  ------------------
  |  |               #define JVP_KIND(j)   (JVP_FLAGS(j) & KIND_MASK)
  |  |  ------------------
  |  |  |  |   73|  19.9M|#define KIND_MASK   0xF
  |  |  ------------------
  |  |  |  Branch (86:23): [True: 3.04M, False: 16.8M]
  |  |  ------------------
  ------------------
 1881|  3.05M|    case JV_KIND_ARRAY:
  ------------------
  |  Branch (1881:5): [True: 3.05M, False: 16.8M]
  ------------------
 1882|  3.05M|      jvp_array_free(j);
 1883|  3.05M|      break;
 1884|  9.93k|    case JV_KIND_STRING:
  ------------------
  |  Branch (1884:5): [True: 9.93k, False: 19.9M]
  ------------------
 1885|  9.93k|      jvp_string_free(j);
 1886|  9.93k|      break;
 1887|  9.68k|    case JV_KIND_OBJECT:
  ------------------
  |  Branch (1887:5): [True: 9.68k, False: 19.9M]
  ------------------
 1888|  9.68k|      jvp_object_free(j);
 1889|  9.68k|      break;
 1890|  3.09M|    case JV_KIND_INVALID:
  ------------------
  |  Branch (1890:5): [True: 3.09M, False: 16.8M]
  ------------------
 1891|  3.09M|      jvp_invalid_free(j);
 1892|  3.09M|      break;
 1893|  10.7M|    case JV_KIND_NUMBER:
  ------------------
  |  Branch (1893:5): [True: 10.7M, False: 9.21M]
  ------------------
 1894|  10.7M|      jvp_number_free(j);
 1895|  10.7M|      break;
 1896|  19.9M|  }
 1897|  19.9M|}
jv.c:jvp_literal_number_new:
  591|  3.04M|static jv jvp_literal_number_new(const char * literal) {
  592|       |
  593|  3.04M|  jvp_literal_number * n = jvp_literal_number_alloc(strlen(literal));
  594|       |
  595|  3.04M|  n->refcnt = JV_REFCNT_INIT;
  596|  3.04M|  n->literal_data = NULL;
  597|  3.04M|  decContext *ctx = DEC_CONTEXT();
  ------------------
  |  |  495|  3.04M|#define DEC_CONTEXT() tsd_dec_ctx_get(&dec_ctx_key)
  ------------------
  598|  3.04M|  decContextClearStatus(ctx, DEC_Conversion_syntax);
  ------------------
  |  |  128|  3.04M|    #define DEC_Conversion_syntax    0x00000001
  ------------------
  599|  3.04M|  decNumberFromString(&n->num_decimal, literal, ctx);
  600|  3.04M|  n->num_double = NAN;
  601|       |
  602|  3.04M|  if (ctx->status & DEC_Conversion_syntax) {
  ------------------
  |  |  128|  3.04M|    #define DEC_Conversion_syntax    0x00000001
  ------------------
  |  Branch (602:7): [True: 529, False: 3.04M]
  ------------------
  603|    529|    jv_mem_free(n);
  604|    529|    return JV_INVALID;
  605|    529|  }
  606|       |
  607|  3.04M|  jv r = {JVP_FLAGS_NUMBER_LITERAL, 0, 0, JV_NUMBER_SIZE_INIT, {&n->refcnt}};
  ------------------
  |  |  213|  3.04M|#define JVP_FLAGS_NUMBER_LITERAL      JVP_MAKE_FLAGS(JV_KIND_NUMBER, JVP_MAKE_PFLAGS(JVP_NUMBER_DECIMAL, 1))
  |  |  ------------------
  |  |  |  |   83|  6.09M|#define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   73|  3.04M|#define KIND_MASK   0xF
  |  |  |  |  ------------------
  |  |  |  |               #define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   74|  3.04M|#define PFLAGS_MASK 0xF0
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (83:61): [Folded - Ignored]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
                jv r = {JVP_FLAGS_NUMBER_LITERAL, 0, 0, JV_NUMBER_SIZE_INIT, {&n->refcnt}};
  ------------------
  |  |  209|  3.04M|#define JV_NUMBER_SIZE_INIT      (0)
  ------------------
  608|  3.04M|  return r;
  609|  3.04M|}
jv.c:jvp_literal_number_alloc:
  578|  3.04M|static jvp_literal_number* jvp_literal_number_alloc(unsigned literal_length) {
  579|       |
  580|       |  /* The number of units needed is ceil(DECNUMDIGITS/DECDPUN)         */
  581|  3.04M|  int units = ((literal_length+DECDPUN-1)/DECDPUN);
  ------------------
  |  |   43|  3.04M|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
                int units = ((literal_length+DECDPUN-1)/DECDPUN);
  ------------------
  |  |   43|  3.04M|  #define DECDPUN 3           /* DECimal Digits Per UNit [must be >0  */
  ------------------
  582|       |
  583|  3.04M|  jvp_literal_number* n = jv_mem_alloc(
  584|  3.04M|    sizeof(jvp_literal_number)
  585|  3.04M|    + sizeof(decNumberUnit) * units
  586|  3.04M|  );
  587|       |
  588|  3.04M|  return n;
  589|  3.04M|}
jv.c:jvp_literal_number_ptr:
  568|  3.04M|static jvp_literal_number* jvp_literal_number_ptr(jv j) {
  569|  3.04M|  assert(JVP_HAS_FLAGS(j, JVP_FLAGS_NUMBER_LITERAL));
  570|  3.04M|  return (jvp_literal_number*)j.u.ptr;
  571|  3.04M|}
jv.c:tsd_dec_ctx_get:
  519|  3.04M|static decContext* tsd_dec_ctx_get(pthread_key_t *key) {
  520|  3.04M|  pthread_once(&dec_ctx_once, jv_tsd_dec_ctx_init); // cannot fail
  521|  3.04M|  decContext *ctx = (decContext*)pthread_getspecific(*key);
  522|  3.04M|  if (ctx) {
  ------------------
  |  Branch (522:7): [True: 3.04M, False: 1]
  ------------------
  523|  3.04M|    return ctx;
  524|  3.04M|  }
  525|       |
  526|      1|  ctx = malloc(sizeof(decContext));
  527|      1|  if (ctx) {
  ------------------
  |  Branch (527:7): [True: 1, False: 0]
  ------------------
  528|      1|    if (key == &dec_ctx_key)
  ------------------
  |  Branch (528:9): [True: 1, False: 0]
  ------------------
  529|      1|    {
  530|      1|      decContextDefault(ctx, DEC_INIT_BASE);
  ------------------
  |  |  227|      1|  #define DEC_INIT_BASE         0
  ------------------
  531|       |      // make sure (Int)D2U(rhs->exponent-lhs->exponent) does not overflow
  532|      1|      ctx->digits = MIN(DEC_MAX_DIGITS,
  ------------------
  |  |   53|      1|  ({ __typeof__ (a) _a = (a); \
  |  |   54|      1|   __typeof__ (b) _b = (b); \
  |  |   55|      1|   _a < _b ? _a : _b; })
  |  |  ------------------
  |  |  |  Branch (55:4): [True: 0, False: 1]
  |  |  ------------------
  ------------------
  533|      1|          INT32_MAX - (DECDPUN - 1) - (ctx->emax - ctx->emin - 1));
  534|      1|      ctx->traps = 0; /*no errors*/
  535|      1|    }
  536|      0|    else if (key == &dec_ctx_dbl_key)
  ------------------
  |  Branch (536:14): [True: 0, False: 0]
  ------------------
  537|      0|    {
  538|      0|      decContextDefault(ctx, DEC_INIT_DECIMAL64);
  ------------------
  |  |  229|      0|  #define DEC_INIT_DECIMAL64   64
  ------------------
  539|       |      // just to make sure we got this right
  540|      0|      assert(ctx->digits <= DEC_NUBMER_DOUBLE_PRECISION);
  541|      0|    }
  542|      1|    if (pthread_setspecific(*key, ctx) != 0) {
  ------------------
  |  Branch (542:9): [True: 0, False: 1]
  ------------------
  543|      0|      fprintf(stderr, "error: cannot store thread specific data");
  544|      0|      abort();
  545|      0|    }
  546|      1|  }
  547|      1|  return ctx;
  548|      1|}
jv.c:jvp_array_new:
  813|  9.28k|static jv jvp_array_new(unsigned size) {
  814|  9.28k|  jv r = {JVP_FLAGS_ARRAY, 0, 0, 0, {&jvp_array_alloc(size)->refcnt}};
  ------------------
  |  |  786|  9.28k|#define JVP_FLAGS_ARRAY   JVP_MAKE_FLAGS(JV_KIND_ARRAY, JVP_PAYLOAD_ALLOCATED)
  |  |  ------------------
  |  |  |  |   83|  9.28k|#define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   73|  9.28k|#define KIND_MASK   0xF
  |  |  |  |  ------------------
  |  |  |  |               #define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   74|  9.28k|#define PFLAGS_MASK 0xF0
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  815|  9.28k|  return r;
  816|  9.28k|}
jv.c:jvp_array_alloc:
  805|  11.0k|static jvp_array* jvp_array_alloc(unsigned size) {
  806|  11.0k|  jvp_array* a = jv_mem_alloc(sizeof(jvp_array) + sizeof(jv) * size);
  807|  11.0k|  a->refcnt.count = 1;
  808|  11.0k|  a->length = 0;
  809|  11.0k|  a->alloc_length = size;
  810|  11.0k|  return a;
  811|  11.0k|}
jv.c:jvp_array_length:
  829|  10.7M|static int jvp_array_length(jv a) {
  830|  10.7M|  assert(JVP_HAS_KIND(a, JV_KIND_ARRAY));
  831|  10.7M|  return a.size;
  832|  10.7M|}
jv.c:jvp_array_ptr:
  800|  3.05M|static jvp_array* jvp_array_ptr(jv a) {
  801|  3.05M|  assert(JVP_HAS_KIND(a, JV_KIND_ARRAY));
  802|  3.05M|  return (jvp_array*)a.u.ptr;
  803|  3.05M|}
jv.c:jvp_array_offset:
  834|  10.7M|static int jvp_array_offset(jv a) {
  835|  10.7M|  assert(JVP_HAS_KIND(a, JV_KIND_ARRAY));
  836|  10.7M|  return a.offset;
  837|  10.7M|}
jv.c:jvp_array_write:
  850|  3.04M|static jv* jvp_array_write(jv* a, int i) {
  851|  3.04M|  assert(i >= 0);
  852|  3.04M|  jvp_array* array = jvp_array_ptr(*a);
  853|       |
  854|  3.04M|  int pos = i + jvp_array_offset(*a);
  855|  3.04M|  if (pos < array->alloc_length && jvp_refcnt_unshared(a->u.ptr)) {
  ------------------
  |  Branch (855:7): [True: 3.04M, False: 1.72k]
  |  Branch (855:36): [True: 3.04M, False: 0]
  ------------------
  856|       |    // use existing array space
  857|  6.08M|    for (int j = array->length; j <= pos; j++) {
  ------------------
  |  Branch (857:33): [True: 3.04M, False: 3.04M]
  ------------------
  858|  3.04M|      array->elements[j] = JV_NULL;
  859|  3.04M|    }
  860|  3.04M|    array->length = imax(pos + 1, array->length);
  861|  3.04M|    a->size = imax(i + 1, a->size);
  862|  3.04M|    return &array->elements[pos];
  863|  3.04M|  } else {
  864|       |    // allocate a new array
  865|  1.72k|    int new_length = imax(i + 1, jvp_array_length(*a));
  866|  1.72k|    jvp_array* new_array = jvp_array_alloc(ARRAY_SIZE_ROUND_UP(new_length));
  ------------------
  |  |  785|  1.72k|#define ARRAY_SIZE_ROUND_UP(n) (((n)*3)/2)
  ------------------
  867|  1.72k|    int j;
  868|  7.67M|    for (j = 0; j < jvp_array_length(*a); j++) {
  ------------------
  |  Branch (868:17): [True: 7.66M, False: 1.72k]
  ------------------
  869|  7.66M|      new_array->elements[j] =
  870|  7.66M|        jv_copy(array->elements[j + jvp_array_offset(*a)]);
  871|  7.66M|    }
  872|  3.45k|    for (; j < new_length; j++) {
  ------------------
  |  Branch (872:12): [True: 1.72k, False: 1.72k]
  ------------------
  873|  1.72k|      new_array->elements[j] = JV_NULL;
  874|  1.72k|    }
  875|  1.72k|    new_array->length = new_length;
  876|  1.72k|    jvp_array_free(*a);
  877|  1.72k|    jv new_jv = {JVP_FLAGS_ARRAY, 0, 0, new_length, {&new_array->refcnt}};
  ------------------
  |  |  786|  1.72k|#define JVP_FLAGS_ARRAY   JVP_MAKE_FLAGS(JV_KIND_ARRAY, JVP_PAYLOAD_ALLOCATED)
  |  |  ------------------
  |  |  |  |   83|  1.72k|#define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   73|  1.72k|#define KIND_MASK   0xF
  |  |  |  |  ------------------
  |  |  |  |               #define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   74|  1.72k|#define PFLAGS_MASK 0xF0
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  878|  1.72k|    *a = new_jv;
  879|  1.72k|    return &new_array->elements[i];
  880|  1.72k|  }
  881|  3.04M|}
jv.c:jvp_refcnt_unshared:
   68|  3.05M|static int jvp_refcnt_unshared(jv_refcnt* c) {
   69|  3.05M|  assert(c->count > 0);
   70|  3.05M|  return c->count == 1;
   71|  3.05M|}
jv.c:imax:
  788|  6.08M|static int imax(int a, int b) {
  789|  6.08M|  if (a>b) return a;
  ------------------
  |  Branch (789:7): [True: 6.08M, False: 0]
  ------------------
  790|      0|  else return b;
  791|  6.08M|}
jv.c:jvp_string_new:
 1105|  10.9k|static jv jvp_string_new(const char* data, uint32_t length) {
 1106|  10.9k|  jvp_string* s = jvp_string_alloc(length);
 1107|  10.9k|  s->length_hashed = length << 1;
 1108|  10.9k|  if (data != NULL)
  ------------------
  |  Branch (1108:7): [True: 9.07k, False: 1.84k]
  ------------------
 1109|  9.07k|    memcpy(s->data, data, length);
 1110|  10.9k|  s->data[length] = 0;
 1111|  10.9k|  jv r = {JVP_FLAGS_STRING, 0, 0, 0, {&s->refcnt}};
  ------------------
  |  | 1055|  10.9k|#define JVP_FLAGS_STRING  JVP_MAKE_FLAGS(JV_KIND_STRING, JVP_PAYLOAD_ALLOCATED)
  |  |  ------------------
  |  |  |  |   83|  10.9k|#define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   73|  10.9k|#define KIND_MASK   0xF
  |  |  |  |  ------------------
  |  |  |  |               #define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   74|  10.9k|#define PFLAGS_MASK 0xF0
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1112|  10.9k|  return r;
 1113|  10.9k|}
jv.c:jvp_string_alloc:
 1072|  14.2k|static jvp_string* jvp_string_alloc(uint32_t size) {
 1073|  14.2k|  jvp_string* s = jv_mem_alloc(sizeof(jvp_string) + size + 1);
 1074|  14.2k|  s->refcnt.count = 1;
 1075|  14.2k|  s->alloc_length = size;
 1076|  14.2k|  return s;
 1077|  14.2k|}
jv.c:jvp_string_copy_replace_bad:
 1080|  3.29k|static jv jvp_string_copy_replace_bad(const char* data, uint32_t length) {
 1081|  3.29k|  const char* end = data + length;
 1082|  3.29k|  const char* i = data;
 1083|  3.29k|  const char* cstart;
 1084|       |
 1085|  3.29k|  uint32_t maxlength = length * 3 + 1; // worst case: all bad bytes, each becomes a 3-byte U+FFFD
 1086|  3.29k|  jvp_string* s = jvp_string_alloc(maxlength);
 1087|  3.29k|  char* out = s->data;
 1088|  3.29k|  int c = 0;
 1089|       |
 1090|  24.2M|  while ((i = jvp_utf8_next((cstart = i), end, &c))) {
  ------------------
  |  Branch (1090:10): [True: 24.2M, False: 3.29k]
  ------------------
 1091|  24.2M|    if (c == -1) {
  ------------------
  |  Branch (1091:9): [True: 8.48M, False: 15.7M]
  ------------------
 1092|  8.48M|      c = 0xFFFD; // U+FFFD REPLACEMENT CHARACTER
 1093|  8.48M|    }
 1094|  24.2M|    out += jvp_utf8_encode(c, out);
 1095|  24.2M|    assert(out < s->data + maxlength);
 1096|  24.2M|  }
 1097|  3.29k|  length = out - s->data;
 1098|  3.29k|  s->data[length] = 0;
 1099|  3.29k|  s->length_hashed = length << 1;
 1100|  3.29k|  jv r = {JVP_FLAGS_STRING, 0, 0, 0, {&s->refcnt}};
  ------------------
  |  | 1055|  3.29k|#define JVP_FLAGS_STRING  JVP_MAKE_FLAGS(JV_KIND_STRING, JVP_PAYLOAD_ALLOCATED)
  |  |  ------------------
  |  |  |  |   83|  3.29k|#define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   73|  3.29k|#define KIND_MASK   0xF
  |  |  |  |  ------------------
  |  |  |  |               #define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   74|  3.29k|#define PFLAGS_MASK 0xF0
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1101|  3.29k|  return r;
 1102|  3.29k|}
jv.c:jvp_string_length:
 1131|  15.4k|static uint32_t jvp_string_length(jvp_string* s) {
 1132|  15.4k|  return s->length_hashed >> 1;
 1133|  15.4k|}
jv.c:jvp_string_ptr:
 1067|  67.6k|static jvp_string* jvp_string_ptr(jv a) {
 1068|  67.6k|  assert(JVP_HAS_KIND(a, JV_KIND_STRING));
 1069|  67.6k|  return (jvp_string*)a.u.ptr;
 1070|  67.6k|}
jv.c:jvp_string_hash:
 1173|  42.6k|static uint32_t jvp_string_hash(jv jstr) {
 1174|  42.6k|  jvp_string* str = jvp_string_ptr(jstr);
 1175|  42.6k|  if (str->length_hashed & 1)
  ------------------
  |  Branch (1175:7): [True: 34.4k, False: 8.16k]
  ------------------
 1176|  34.4k|    return str->hash;
 1177|       |
 1178|       |  /* The following is based on MurmurHash3.
 1179|       |     MurmurHash3 was written by Austin Appleby, and is placed
 1180|       |     in the public domain. */
 1181|       |
 1182|  8.16k|  const uint8_t* data = (const uint8_t*)str->data;
 1183|  8.16k|  int len = (int)jvp_string_length(str);
 1184|  8.16k|  const int nblocks = len / 4;
 1185|       |
 1186|  8.16k|  uint32_t h1 = HASH_SEED;
 1187|       |
 1188|  8.16k|  const uint32_t c1 = 0xcc9e2d51;
 1189|  8.16k|  const uint32_t c2 = 0x1b873593;
 1190|  8.16k|  const uint32_t* blocks = (const uint32_t *)(data + nblocks*4);
 1191|       |
 1192|  2.13M|  for(int i = -nblocks; i; i++) {
  ------------------
  |  Branch (1192:25): [True: 2.12M, False: 8.16k]
  ------------------
 1193|  2.12M|    uint32_t k1 = blocks[i]; //FIXME: endianness/alignment
 1194|       |
 1195|  2.12M|    k1 *= c1;
 1196|  2.12M|    k1 = rotl32(k1,15);
 1197|  2.12M|    k1 *= c2;
 1198|       |
 1199|  2.12M|    h1 ^= k1;
 1200|  2.12M|    h1 = rotl32(h1,13);
 1201|  2.12M|    h1 = h1*5+0xe6546b64;
 1202|  2.12M|  }
 1203|       |
 1204|  8.16k|  const uint8_t* tail = (const uint8_t*)(data + nblocks*4);
 1205|       |
 1206|  8.16k|  uint32_t k1 = 0;
 1207|       |
 1208|  8.16k|  switch(len & 3) {
  ------------------
  |  Branch (1208:10): [True: 2.06k, False: 6.09k]
  ------------------
 1209|    865|  case 3: k1 ^= tail[2] << 16;
  ------------------
  |  Branch (1209:3): [True: 865, False: 7.29k]
  ------------------
 1210|    865|          JQ_FALLTHROUGH;
  ------------------
  |  |   10|    865|# define JQ_FALLTHROUGH __attribute__((fallthrough))
  ------------------
 1211|  1.84k|  case 2: k1 ^= tail[1] << 8;
  ------------------
  |  Branch (1211:3): [True: 980, False: 7.18k]
  ------------------
 1212|  1.84k|          JQ_FALLTHROUGH;
  ------------------
  |  |   10|  1.84k|# define JQ_FALLTHROUGH __attribute__((fallthrough))
  ------------------
 1213|  6.09k|  case 1: k1 ^= tail[0];
  ------------------
  |  Branch (1213:3): [True: 4.24k, False: 3.91k]
  ------------------
 1214|  6.09k|          k1 *= c1; k1 = rotl32(k1,15); k1 *= c2; h1 ^= k1;
 1215|  8.16k|  }
 1216|       |
 1217|  8.16k|  h1 ^= len;
 1218|       |
 1219|  8.16k|  h1 ^= h1 >> 16;
 1220|  8.16k|  h1 *= 0x85ebca6b;
 1221|  8.16k|  h1 ^= h1 >> 13;
 1222|  8.16k|  h1 *= 0xc2b2ae35;
 1223|  8.16k|  h1 ^= h1 >> 16;
 1224|       |
 1225|  8.16k|  str->length_hashed |= 1;
 1226|  8.16k|  str->hash = h1;
 1227|       |
 1228|  8.16k|  return h1;
 1229|  8.16k|}
jv.c:rotl32:
 1169|  4.25M|static uint32_t rotl32 (uint32_t x, int8_t r){
 1170|  4.25M|  return (x << r) | (x >> (32 - r));
 1171|  4.25M|}
jv.c:jvp_object_new:
 1509|  8.14k|static jv jvp_object_new(int size) {
 1510|       |  // Allocates an object of (size) slots and (size*2) hash buckets.
 1511|       |
 1512|       |  // size must be a power of two
 1513|  8.14k|  assert(size > 0 && (size & (size - 1)) == 0);
 1514|       |
 1515|  8.14k|  jvp_object* obj = jv_mem_alloc(sizeof(jvp_object) +
 1516|  8.14k|                                 sizeof(struct object_slot) * size +
 1517|  8.14k|                                 sizeof(int) * (size * 2));
 1518|  8.14k|  obj->refcnt.count = 1;
 1519|  82.0k|  for (int i=0; i<size; i++) {
  ------------------
  |  Branch (1519:17): [True: 73.9k, False: 8.14k]
  ------------------
 1520|  73.9k|    obj->elements[i].next = i - 1;
 1521|  73.9k|    obj->elements[i].string = JV_NULL;
 1522|  73.9k|    obj->elements[i].hash = 0;
 1523|  73.9k|    obj->elements[i].value = JV_NULL;
 1524|  73.9k|  }
 1525|  8.14k|  obj->next_free = 0;
 1526|  8.14k|  int* hashbuckets = (int*)(&obj->elements[size]);
 1527|   156k|  for (int i=0; i<size*2; i++) {
  ------------------
  |  Branch (1527:17): [True: 147k, False: 8.14k]
  ------------------
 1528|   147k|    hashbuckets[i] = -1;
 1529|   147k|  }
 1530|  8.14k|  jv r = {JVP_FLAGS_OBJECT, 0, 0, size, {&obj->refcnt}};
  ------------------
  |  | 1492|  8.14k|#define JVP_FLAGS_OBJECT  JVP_MAKE_FLAGS(JV_KIND_OBJECT, JVP_PAYLOAD_ALLOCATED)
  |  |  ------------------
  |  |  |  |   83|  8.14k|#define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   73|  8.14k|#define KIND_MASK   0xF
  |  |  |  |  ------------------
  |  |  |  |               #define JVP_MAKE_FLAGS(kind, pflags) ((kind & KIND_MASK) | (pflags & PFLAGS_MASK))
  |  |  |  |  ------------------
  |  |  |  |  |  |   74|  8.14k|#define PFLAGS_MASK 0xF0
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1531|  8.14k|  return r;
 1532|  8.14k|}
jv.c:jvp_object_find_bucket:
 1553|  15.1k|static int* jvp_object_find_bucket(jv object, jv key) {
 1554|  15.1k|  return jvp_object_buckets(object) + (jvp_object_mask(object) & jvp_string_hash(key));
 1555|  15.1k|}
jv.c:jvp_object_buckets:
 1549|  15.1k|static int* jvp_object_buckets(jv o) {
 1550|  15.1k|  return (int*)(&jvp_object_ptr(o)->elements[o.size]);
 1551|  15.1k|}
jv.c:jvp_object_ptr:
 1534|   136k|static jvp_object* jvp_object_ptr(jv o) {
 1535|   136k|  assert(JVP_HAS_KIND(o, JV_KIND_OBJECT));
 1536|   136k|  return (jvp_object*)o.u.ptr;
 1537|   136k|}
jv.c:jvp_object_mask:
 1539|  15.1k|static uint32_t jvp_object_mask(jv o) {
 1540|  15.1k|  assert(JVP_HAS_KIND(o, JV_KIND_OBJECT));
 1541|  15.1k|  return (o.size * 2) - 1;
 1542|  15.1k|}
jv.c:jvp_object_find_slot:
 1567|  15.1k|static struct object_slot* jvp_object_find_slot(jv object, jv keystr, int* bucket) {
 1568|  15.1k|  uint32_t hash = jvp_string_hash(keystr);
 1569|  15.1k|  for (struct object_slot* curr = jvp_object_get_slot(object, *bucket);
 1570|  19.9k|       curr;
  ------------------
  |  Branch (1570:8): [True: 7.12k, False: 12.8k]
  ------------------
 1571|  15.1k|       curr = jvp_object_next_slot(object, curr)) {
 1572|  7.12k|    if (curr->hash == hash && jvp_string_equal(keystr, curr->string)) {
  ------------------
  |  Branch (1572:9): [True: 2.51k, False: 4.60k]
  |  Branch (1572:31): [True: 2.29k, False: 228]
  ------------------
 1573|  2.29k|      return curr;
 1574|  2.29k|    }
 1575|  7.12k|  }
 1576|  12.8k|  return 0;
 1577|  15.1k|}
jv.c:jvp_object_next_slot:
 1563|  4.83k|static struct object_slot* jvp_object_next_slot(jv object, struct object_slot* slot) {
 1564|  4.83k|  return jvp_object_get_slot(object, slot->next);
 1565|  4.83k|}
jv.c:jvp_object_write:
 1659|  8.16k|static jv* jvp_object_write(jv* object, jv key) {
 1660|  8.16k|  *object = jvp_object_unshare(*object);
 1661|  8.16k|  int* bucket = jvp_object_find_bucket(*object, key);
 1662|  8.16k|  struct object_slot* slot = jvp_object_find_slot(*object, key, bucket);
 1663|  8.16k|  if (slot) {
  ------------------
  |  Branch (1663:7): [True: 2.29k, False: 5.87k]
  ------------------
 1664|       |    // already has the key
 1665|  2.29k|    jvp_string_free(key);
 1666|  2.29k|    return &slot->value;
 1667|  2.29k|  }
 1668|  5.87k|  slot = jvp_object_add_slot(*object, key, bucket);
 1669|  5.87k|  if (slot) {
  ------------------
  |  Branch (1669:7): [True: 5.35k, False: 517]
  ------------------
 1670|  5.35k|    slot->value = jv_invalid();
 1671|  5.35k|  } else {
 1672|    517|    *object = jvp_object_rehash(*object);
 1673|    517|    bucket = jvp_object_find_bucket(*object, key);
 1674|    517|    assert(!jvp_object_find_slot(*object, key, bucket));
 1675|    517|    slot = jvp_object_add_slot(*object, key, bucket);
 1676|    517|    assert(slot);
 1677|    517|    slot->value = jv_invalid();
 1678|    517|  }
 1679|  5.87k|  return &slot->value;
 1680|  5.87k|}
jv.c:jvp_object_unshare:
 1633|  8.16k|static jv jvp_object_unshare(jv object) {
 1634|  8.16k|  assert(JVP_HAS_KIND(object, JV_KIND_OBJECT));
 1635|  8.16k|  if (jvp_refcnt_unshared(object.u.ptr))
  ------------------
  |  Branch (1635:7): [True: 8.16k, False: 0]
  ------------------
 1636|  8.16k|    return object;
 1637|       |
 1638|      0|  jv new_object = jvp_object_new(jvp_object_size(object));
 1639|      0|  jvp_object_ptr(new_object)->next_free = jvp_object_ptr(object)->next_free;
 1640|      0|  for (int i=0; i<jvp_object_size(new_object); i++) {
  ------------------
  |  Branch (1640:17): [True: 0, False: 0]
  ------------------
 1641|      0|    struct object_slot* old_slot = jvp_object_get_slot(object, i);
 1642|      0|    struct object_slot* new_slot = jvp_object_get_slot(new_object, i);
 1643|      0|    *new_slot = *old_slot;
 1644|      0|    if (jv_get_kind(old_slot->string) != JV_KIND_NULL) {
  ------------------
  |  Branch (1644:9): [True: 0, False: 0]
  ------------------
 1645|      0|      new_slot->string = jv_copy(old_slot->string);
 1646|      0|      new_slot->value = jv_copy(old_slot->value);
 1647|      0|    }
 1648|      0|  }
 1649|       |
 1650|      0|  int* old_buckets = jvp_object_buckets(object);
 1651|      0|  int* new_buckets = jvp_object_buckets(new_object);
 1652|      0|  memcpy(new_buckets, old_buckets, sizeof(int) * jvp_object_size(new_object)*2);
 1653|       |
 1654|      0|  jvp_object_free(object);
 1655|      0|  assert(jvp_refcnt_unshared(new_object.u.ptr));
 1656|      0|  return new_object;
 1657|      0|}
jv.c:jvp_object_add_slot:
 1579|  12.8k|static struct object_slot* jvp_object_add_slot(jv object, jv key, int* bucket) {
 1580|  12.8k|  jvp_object* o = jvp_object_ptr(object);
 1581|  12.8k|  int newslot_idx = o->next_free;
 1582|  12.8k|  if (newslot_idx == jvp_object_size(object)) return 0;
  ------------------
  |  Branch (1582:7): [True: 517, False: 12.3k]
  ------------------
 1583|  12.3k|  struct object_slot* newslot = jvp_object_get_slot(object, newslot_idx);
 1584|  12.3k|  o->next_free++;
 1585|  12.3k|  newslot->next = *bucket;
 1586|  12.3k|  *bucket = newslot_idx;
 1587|  12.3k|  newslot->hash = jvp_string_hash(key);
 1588|  12.3k|  newslot->string = key;
 1589|  12.3k|  return newslot;
 1590|  12.8k|}
jv.c:jvp_object_rehash:
 1614|    517|static jv jvp_object_rehash(jv object) {
 1615|    517|  assert(JVP_HAS_KIND(object, JV_KIND_OBJECT));
 1616|    517|  assert(jvp_refcnt_unshared(object.u.ptr));
 1617|    517|  int size = jvp_object_size(object);
 1618|    517|  jv new_object = jvp_object_new(size * 2);
 1619|  6.98k|  for (int i=0; i<size; i++) {
  ------------------
  |  Branch (1619:17): [True: 6.47k, False: 517]
  ------------------
 1620|  6.47k|    struct object_slot* slot = jvp_object_get_slot(object, i);
 1621|  6.47k|    if (jv_get_kind(slot->string) == JV_KIND_NULL) continue;
  ------------------
  |  Branch (1621:9): [True: 0, False: 6.47k]
  ------------------
 1622|  6.47k|    int* new_bucket = jvp_object_find_bucket(new_object, slot->string);
 1623|  6.47k|    assert(!jvp_object_find_slot(new_object, slot->string, new_bucket));
 1624|  6.47k|    struct object_slot* new_slot = jvp_object_add_slot(new_object, slot->string, new_bucket);
 1625|  6.47k|    assert(new_slot);
 1626|  6.47k|    new_slot->value = slot->value;
 1627|  6.47k|  }
 1628|       |  // references are transported, just drop the old table
 1629|    517|  jv_mem_free(jvp_object_ptr(object));
 1630|    517|  return new_object;
 1631|    517|}
jv.c:jvp_object_length:
 1703|    828|static int jvp_object_length(jv object) {
 1704|    828|  int n = 0;
 1705|  7.57k|  for (int i=0; i<jvp_object_size(object); i++) {
  ------------------
  |  Branch (1705:17): [True: 6.74k, False: 828]
  ------------------
 1706|  6.74k|    struct object_slot* slot = jvp_object_get_slot(object, i);
 1707|  6.74k|    if (jv_get_kind(slot->string) != JV_KIND_NULL) n++;
  ------------------
  |  Branch (1707:9): [True: 193, False: 6.55k]
  ------------------
 1708|  6.74k|  }
 1709|    828|  return n;
 1710|    828|}
jv.c:jvp_object_size:
 1544|   196k|static int jvp_object_size(jv o) {
 1545|   196k|  assert(JVP_HAS_KIND(o, JV_KIND_OBJECT));
 1546|   196k|  return o.size;
 1547|   196k|}
jv.c:jvp_object_get_slot:
 1557|   113k|static struct object_slot* jvp_object_get_slot(jv object, int slot) {
 1558|   113k|  assert(slot == -1 || (slot >= 0 && slot < jvp_object_size(object)));
 1559|   113k|  if (slot == -1) return 0;
  ------------------
  |  Branch (1559:7): [True: 12.8k, False: 100k]
  ------------------
 1560|   100k|  else return &jvp_object_ptr(object)->elements[slot];
 1561|   113k|}
jv.c:jvp_refcnt_inc:
   59|  10.7M|static void jvp_refcnt_inc(jv_refcnt* c) {
   60|  10.7M|  c->count++;
   61|  10.7M|}
jv.c:jvp_array_free:
  818|  3.05M|static void jvp_array_free(jv a) {
  819|  3.05M|  assert(JVP_HAS_KIND(a, JV_KIND_ARRAY));
  820|  3.05M|  if (jvp_refcnt_dec(a.u.ptr)) {
  ------------------
  |  Branch (820:7): [True: 11.0k, False: 3.04M]
  ------------------
  821|  11.0k|    jvp_array* array = jvp_array_ptr(a);
  822|  10.7M|    for (int i=0; i<array->length; i++) {
  ------------------
  |  Branch (822:19): [True: 10.7M, False: 11.0k]
  ------------------
  823|  10.7M|      jv_free(array->elements[i]);
  824|  10.7M|    }
  825|  11.0k|    jv_mem_free(array);
  826|  11.0k|  }
  827|  3.05M|}
jv.c:jvp_refcnt_dec:
   63|  13.7M|static int jvp_refcnt_dec(jv_refcnt* c) {
   64|  13.7M|  c->count--;
   65|  13.7M|  return c->count == 0;
   66|  13.7M|}
jv.c:jvp_string_free:
 1124|  18.1k|static void jvp_string_free(jv js) {
 1125|  18.1k|  jvp_string* s = jvp_string_ptr(js);
 1126|  18.1k|  if (jvp_refcnt_dec(&s->refcnt)) {
  ------------------
  |  Branch (1126:7): [True: 14.2k, False: 3.88k]
  ------------------
 1127|  14.2k|    jv_mem_free(s);
 1128|  14.2k|  }
 1129|  18.1k|}
jv.c:jvp_object_free:
 1600|  9.68k|static void jvp_object_free(jv o) {
 1601|  9.68k|  assert(JVP_HAS_KIND(o, JV_KIND_OBJECT));
 1602|  9.68k|  if (jvp_refcnt_dec(o.u.ptr)) {
  ------------------
  |  Branch (1602:7): [True: 7.62k, False: 2.06k]
  ------------------
 1603|  75.1k|    for (int i=0; i<jvp_object_size(o); i++) {
  ------------------
  |  Branch (1603:19): [True: 67.4k, False: 7.62k]
  ------------------
 1604|  67.4k|      struct object_slot* slot = jvp_object_get_slot(o, i);
 1605|  67.4k|      if (jv_get_kind(slot->string) != JV_KIND_NULL) {
  ------------------
  |  Branch (1605:11): [True: 5.87k, False: 61.6k]
  ------------------
 1606|  5.87k|        jvp_string_free(slot->string);
 1607|  5.87k|        jv_free(slot->value);
 1608|  5.87k|      }
 1609|  67.4k|    }
 1610|  7.62k|    jv_mem_free(jvp_object_ptr(o));
 1611|  7.62k|  }
 1612|  9.68k|}
jv.c:jvp_invalid_free:
  184|  3.09M|static void jvp_invalid_free(jv x) {
  185|  3.09M|  assert(JVP_HAS_KIND(x, JV_KIND_INVALID));
  186|  3.09M|  if (JVP_HAS_FLAGS(x, JVP_FLAGS_INVALID_MSG) && jvp_refcnt_dec(x.u.ptr)) {
  ------------------
  |  |   88|  6.19M|#define JVP_HAS_FLAGS(j, flags) (JVP_FLAGS(j) == flags)
  |  |  ------------------
  |  |  |  |   85|  3.09M|#define JVP_FLAGS(j)  ((j).kind_flags)
  |  |  ------------------
  |  |  |  Branch (88:33): [True: 7.59k, False: 3.08M]
  |  |  ------------------
  ------------------
  |  Branch (186:50): [True: 3.83k, False: 3.76k]
  ------------------
  187|  3.83k|    jv_free(((jvp_invalid*)x.u.ptr)->errmsg);
  188|  3.83k|    jv_mem_free(x.u.ptr);
  189|  3.83k|  }
  190|  3.09M|}
jv.c:jvp_number_free:
  691|  10.7M|static void jvp_number_free(jv j) {
  692|  10.7M|  assert(JVP_HAS_KIND(j, JV_KIND_NUMBER));
  693|  10.7M|#ifdef USE_DECNUM
  694|  10.7M|  if (JVP_HAS_FLAGS(j, JVP_FLAGS_NUMBER_LITERAL) && jvp_refcnt_dec(j.u.ptr)) {
  ------------------
  |  |   88|  21.4M|#define JVP_HAS_FLAGS(j, flags) (JVP_FLAGS(j) == flags)
  |  |  ------------------
  |  |  |  |   85|  10.7M|#define JVP_FLAGS(j)  ((j).kind_flags)
  |  |  ------------------
  |  |  |  Branch (88:33): [True: 10.7M, False: 0]
  |  |  |  Branch (88:50): [Folded - Ignored]
  |  |  ------------------
  ------------------
  |  Branch (694:53): [True: 3.04M, False: 7.66M]
  ------------------
  695|  3.04M|    jvp_literal_number* n = jvp_literal_number_ptr(j);
  696|  3.04M|    if (n->literal_data) {
  ------------------
  |  Branch (696:9): [True: 0, False: 3.04M]
  ------------------
  697|      0|      jv_mem_free(n->literal_data);
  698|      0|    }
  699|  3.04M|    jv_mem_free(n);
  700|  3.04M|  }
  701|  10.7M|#endif
  702|  10.7M|}
jv.c:jvp_string_equal:
 1232|  2.51k|static int jvp_string_equal(jv a, jv b) {
 1233|  2.51k|  assert(JVP_HAS_KIND(a, JV_KIND_STRING));
 1234|  2.51k|  assert(JVP_HAS_KIND(b, JV_KIND_STRING));
 1235|  2.51k|  jvp_string* stra = jvp_string_ptr(a);
 1236|  2.51k|  jvp_string* strb = jvp_string_ptr(b);
 1237|  2.51k|  if (jvp_string_length(stra) != jvp_string_length(strb)) return 0;
  ------------------
  |  Branch (1237:7): [True: 228, False: 2.29k]
  ------------------
 1238|  2.29k|  return memcmp(stra->data, strb->data, jvp_string_length(stra)) == 0;
 1239|  2.51k|}

jv_parse.c:jv_is_valid:
   48|  41.2M|static int jv_is_valid(jv x) { return jv_get_kind(x) != JV_KIND_INVALID; }

jv_mem_alloc:
  140|  3.08M|void* jv_mem_alloc(size_t sz) {
  141|  3.08M|  void* p = malloc(sz);
  142|  3.08M|  if (!p) {
  ------------------
  |  Branch (142:7): [True: 0, False: 3.08M]
  ------------------
  143|      0|    memory_exhausted();
  144|      0|  }
  145|  3.08M|  return p;
  146|  3.08M|}
jv_mem_free:
  176|  3.09M|void jv_mem_free(void* p) {
  177|  3.09M|  free(p);
  178|  3.09M|}
jv_mem_realloc:
  180|  6.37k|void* jv_mem_realloc(void* p, size_t sz) {
  181|  6.37k|  p = realloc(p, sz);
  182|  6.37k|  if (!p) {
  ------------------
  |  Branch (182:7): [True: 0, False: 6.37k]
  ------------------
  183|      0|    memory_exhausted();
  184|      0|  }
  185|  6.37k|  return p;
  186|  6.37k|}

jvp_dtoa_context_init:
  522|  3.02k|void jvp_dtoa_context_init(struct dtoa_context* C) {
  523|  3.02k|  int i;
  524|  27.1k|  for (i=0; i<(int)(sizeof(C->freelist)/sizeof(C->freelist[0])); i++) {
  ------------------
  |  Branch (524:13): [True: 24.1k, False: 3.02k]
  ------------------
  525|  24.1k|    C->freelist[i] = 0;
  526|  24.1k|  }
  527|  3.02k|  C->p5s = 0;
  528|  3.02k|}
jvp_dtoa_context_free:
  569|  3.02k|void jvp_dtoa_context_free(struct dtoa_context* C) {
  570|  3.02k|  int k;
  571|  3.02k|  while (C->p5s) {
  ------------------
  |  Branch (571:10): [True: 0, False: 3.02k]
  ------------------
  572|      0|    Bigint* p5 = C->p5s;
  573|      0|    C->p5s = p5->next;
  574|      0|    Bfree(C, p5);
  575|      0|  }
  576|  27.1k|  for (k=0; k<(int)(sizeof(C->freelist)/sizeof(C->freelist[0])); k++) {
  ------------------
  |  Branch (576:13): [True: 24.1k, False: 3.02k]
  ------------------
  577|  24.1k|    while (C->freelist[k]) {
  ------------------
  |  Branch (577:12): [True: 0, False: 24.1k]
  ------------------
  578|      0|      Bigint* v = C->freelist[k];
  579|      0|      C->freelist[k] = v->next;
  580|      0|      FREE(v);
  ------------------
  |  |  200|      0|#define FREE jv_mem_free
  ------------------
  581|      0|    }
  582|  24.1k|  }
  583|  3.02k|}

jv_parser_set_buf:
  728|  3.02k|void jv_parser_set_buf(struct jv_parser* p, const char* buf, int length, int is_partial) {
  729|  3.02k|  assert((p->curr_buf == 0 || p->curr_buf_pos == p->curr_buf_length)
  730|  3.02k|         && "previous buffer not exhausted");
  731|  6.06k|  while (length > 0 && p->bom_strip_position < sizeof(UTF8_BOM)) {
  ------------------
  |  Branch (731:10): [True: 6.06k, False: 4]
  |  Branch (731:24): [True: 3.04k, False: 3.01k]
  ------------------
  732|  3.04k|    if ((unsigned char)*buf == UTF8_BOM[p->bom_strip_position]) {
  ------------------
  |  Branch (732:9): [True: 27, False: 3.01k]
  ------------------
  733|       |      // matched a BOM character
  734|     27|      buf++;
  735|     27|      length--;
  736|     27|      p->bom_strip_position++;
  737|  3.01k|    } else {
  738|  3.01k|      if (p->bom_strip_position == 0) {
  ------------------
  |  Branch (738:11): [True: 2.99k, False: 19]
  ------------------
  739|       |        // no BOM in this document
  740|  2.99k|        p->bom_strip_position = sizeof(UTF8_BOM);
  741|  2.99k|      } else {
  742|       |        // malformed BOM (prefix present, rest missing)
  743|     19|        p->bom_strip_position = 0xff;
  744|     19|      }
  745|  3.01k|    }
  746|  3.04k|  }
  747|  3.02k|  p->curr_buf = buf;
  748|  3.02k|  p->curr_buf_length = length;
  749|  3.02k|  p->curr_buf_pos = 0;
  750|  3.02k|  p->curr_buf_is_partial = is_partial;
  751|  3.02k|}
jv_parser_next:
  765|  4.68k|jv jv_parser_next(struct jv_parser* p) {
  766|  4.68k|  if (p->eof)
  ------------------
  |  Branch (766:7): [True: 875, False: 3.80k]
  ------------------
  767|    875|    return jv_invalid();
  768|  3.80k|  if (!p->curr_buf)
  ------------------
  |  Branch (768:7): [True: 0, False: 3.80k]
  ------------------
  769|      0|    return jv_invalid(); // Need a buffer
  770|  3.80k|  if (p->bom_strip_position == 0xff) {
  ------------------
  |  Branch (770:7): [True: 19, False: 3.79k]
  ------------------
  771|     19|    if (!(p->flags & JV_PARSE_SEQ))
  ------------------
  |  Branch (771:9): [True: 19, False: 0]
  ------------------
  772|     19|      return jv_invalid_with_msg(jv_string("Malformed BOM"));
  773|      0|    p->st =JV_PARSER_WAITING_FOR_RS;
  774|      0|    parser_reset(p);
  775|      0|  }
  776|  3.79k|  jv value = jv_invalid();
  777|  3.79k|  if ((p->flags & JV_PARSE_STREAMING) && stream_check_done(p, &value))
  ------------------
  |  Branch (777:7): [True: 0, False: 3.79k]
  |  Branch (777:42): [True: 0, False: 0]
  ------------------
  778|      0|    return value;
  779|  3.79k|  char ch;
  780|  3.79k|  presult msg = 0;
  781|  50.6M|  while (!msg && p->curr_buf_pos < p->curr_buf_length) {
  ------------------
  |  Branch (781:10): [True: 50.6M, False: 1.13k]
  |  Branch (781:18): [True: 50.6M, False: 2.65k]
  ------------------
  782|  50.6M|    ch = p->curr_buf[p->curr_buf_pos++];
  783|  50.6M|    if (p->st == JV_PARSER_WAITING_FOR_RS) {
  ------------------
  |  Branch (783:9): [True: 0, False: 50.6M]
  ------------------
  784|      0|      if (ch == '\n') {
  ------------------
  |  Branch (784:11): [True: 0, False: 0]
  ------------------
  785|      0|        p->line++;
  786|      0|        p->column = 0;
  787|      0|      } else {
  788|      0|        p->column++;
  789|      0|      }
  790|      0|      if (ch == '\036')
  ------------------
  |  Branch (790:11): [True: 0, False: 0]
  ------------------
  791|      0|        p->st = JV_PARSER_NORMAL;
  792|      0|      continue; // need to resync, wait for RS
  793|      0|    }
  794|  50.6M|    msg = scan(p, ch, &value);
  795|  50.6M|  }
  796|  3.79k|  if (msg == OK) {
  ------------------
  |  Branch (796:7): [True: 800, False: 2.99k]
  ------------------
  797|    800|    return value;
  798|  2.99k|  } else if (msg) {
  ------------------
  |  Branch (798:14): [True: 336, False: 2.65k]
  ------------------
  799|    336|    jv_free(value);
  800|    336|    if (ch != '\036' && (p->flags & JV_PARSE_SEQ)) {
  ------------------
  |  Branch (800:9): [True: 336, False: 0]
  |  Branch (800:25): [True: 0, False: 336]
  ------------------
  801|       |      // Skip to the next RS
  802|      0|      p->st = JV_PARSER_WAITING_FOR_RS;
  803|      0|      value = make_error(p, "%s at line %d, column %d (need RS to resync)", msg, p->line, p->column);
  804|      0|      parser_reset(p);
  805|      0|      return value;
  806|      0|    }
  807|    336|    value = make_error(p, "%s at line %d, column %d", msg, p->line, p->column);
  808|    336|    parser_reset(p);
  809|    336|    if (!(p->flags & JV_PARSE_SEQ)) {
  ------------------
  |  Branch (809:9): [True: 336, False: 0]
  ------------------
  810|       |      // We're not parsing a JSON text sequence; throw this buffer away.
  811|       |      // XXX We should fail permanently here.
  812|    336|      p->curr_buf = 0;
  813|    336|      p->curr_buf_pos = 0;
  814|    336|    } // Else ch must be RS; don't clear buf so we can start parsing again after this ch
  815|    336|    return value;
  816|  2.65k|  } else if (p->curr_buf_is_partial) {
  ------------------
  |  Branch (816:14): [True: 0, False: 2.65k]
  ------------------
  817|      0|    assert(p->curr_buf_pos == p->curr_buf_length);
  818|       |    // need another buffer
  819|      0|    return jv_invalid();
  820|  2.65k|  } else {
  821|       |    // at EOF
  822|  2.65k|    p->eof = 1;
  823|  2.65k|    assert(p->curr_buf_pos == p->curr_buf_length);
  824|  2.65k|    jv_free(value);
  825|  2.65k|    if (p->st == JV_PARSER_WAITING_FOR_RS)
  ------------------
  |  Branch (825:9): [True: 0, False: 2.65k]
  ------------------
  826|      0|      return make_error(p, "Unfinished abandoned text at EOF at line %d, column %d", p->line, p->column);
  827|  2.65k|    if (p->st != JV_PARSER_NORMAL) {
  ------------------
  |  Branch (827:9): [True: 90, False: 2.56k]
  ------------------
  828|     90|      value = make_error(p, "Unfinished string at EOF at line %d, column %d", p->line, p->column);
  829|     90|      parser_reset(p);
  830|     90|      p->st = JV_PARSER_WAITING_FOR_RS;
  831|     90|      return value;
  832|     90|    }
  833|  2.56k|    if ((msg = check_literal(p))) {
  ------------------
  |  Branch (833:9): [True: 602, False: 1.96k]
  ------------------
  834|    602|      value = make_error(p, "%s at EOF at line %d, column %d", msg, p->line, p->column);
  835|    602|      parser_reset(p);
  836|    602|      p->st = JV_PARSER_WAITING_FOR_RS;
  837|    602|      return value;
  838|    602|    }
  839|  1.96k|    if (((p->flags & JV_PARSE_STREAMING) && p->stacklen != 0) ||
  ------------------
  |  Branch (839:10): [True: 0, False: 1.96k]
  |  Branch (839:45): [True: 0, False: 0]
  ------------------
  840|  1.96k|        (!(p->flags & JV_PARSE_STREAMING) && p->stackpos != 0)) {
  ------------------
  |  Branch (840:10): [True: 1.96k, False: 0]
  |  Branch (840:46): [True: 800, False: 1.16k]
  ------------------
  841|    800|      value = make_error(p, "Unfinished JSON term at EOF at line %d, column %d", p->line, p->column);
  842|    800|      parser_reset(p);
  843|    800|      p->st = JV_PARSER_WAITING_FOR_RS;
  844|    800|      return value;
  845|    800|    }
  846|       |    // p->next is either invalid (nothing here, but no syntax error)
  847|       |    // or valid (this is the value). either way it's the thing to return
  848|  1.16k|    if ((p->flags & JV_PARSE_STREAMING) && jv_is_valid(p->next)) {
  ------------------
  |  Branch (848:9): [True: 0, False: 1.16k]
  |  Branch (848:44): [True: 0, False: 0]
  ------------------
  849|      0|      value = JV_ARRAY(jv_copy(p->path), p->next); // except in streaming mode we've got to make it [path,value]
  ------------------
  |  |  105|      0|  JV_ARRAY_IDX(__VA_ARGS__, JV_ARRAY_9, JV_ARRAY_8, JV_ARRAY_7, JV_ARRAY_6, JV_ARRAY_5, JV_ARRAY_4, JV_ARRAY_3, JV_ARRAY_2, JV_ARRAY_1, dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  103|      0|#define JV_ARRAY_IDX(_1,_2,_3,_4,_5,_6,_7,_8,_9,NAME,...) NAME
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|      0|  JV_ARRAY_IDX(__VA_ARGS__, JV_ARRAY_9, JV_ARRAY_8, JV_ARRAY_7, JV_ARRAY_6, JV_ARRAY_5, JV_ARRAY_4, JV_ARRAY_3, JV_ARRAY_2, JV_ARRAY_1, dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   95|      0|#define JV_ARRAY_2(e1,e2) (jv_array_append(JV_ARRAY_1(e1),e2))
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   94|      0|#define JV_ARRAY_1(e) (jv_array_append(jv_array(),e))
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  850|  1.16k|    } else {
  851|  1.16k|      value = p->next;
  852|  1.16k|    }
  853|  1.16k|    p->next = jv_invalid();
  854|  1.16k|    if ((p->flags & JV_PARSE_SEQ) && !p->last_ch_was_ws && jv_get_kind(value) == JV_KIND_NUMBER) {
  ------------------
  |  Branch (854:9): [True: 0, False: 1.16k]
  |  Branch (854:38): [True: 0, False: 0]
  |  Branch (854:60): [True: 0, False: 0]
  ------------------
  855|      0|      jv_free(value);
  856|      0|      return make_error(p, "Potentially truncated top-level numeric value at EOF at line %d, column %d", p->line, p->column);
  857|      0|    }
  858|  1.16k|    return value;
  859|  1.16k|  }
  860|  3.79k|}
jv_parse_sized:
  862|  3.02k|jv jv_parse_sized(const char* string, int length) {
  863|  3.02k|  struct jv_parser parser;
  864|  3.02k|  parser_init(&parser, 0);
  865|  3.02k|  jv_parser_set_buf(&parser, string, length, 0);
  866|  3.02k|  jv value = jv_parser_next(&parser);
  867|  3.02k|  if (jv_is_valid(value)) {
  ------------------
  |  Branch (867:7): [True: 1.66k, False: 1.36k]
  ------------------
  868|  1.66k|    jv next = jv_parser_next(&parser);
  869|  1.66k|    if (jv_is_valid(next)) {
  ------------------
  |  Branch (869:9): [True: 34, False: 1.62k]
  ------------------
  870|       |      // multiple JSON values, we only wanted one
  871|     34|      jv_free(value);
  872|     34|      jv_free(next);
  873|     34|      value = jv_invalid_with_msg(jv_string("Unexpected extra JSON values"));
  874|  1.62k|    } else if (jv_invalid_has_msg(jv_copy(next))) {
  ------------------
  |  Branch (874:16): [True: 523, False: 1.10k]
  ------------------
  875|       |      // parser error after the first JSON value
  876|    523|      jv_free(value);
  877|    523|      value = next;
  878|  1.10k|    } else {
  879|       |      // a single valid JSON value
  880|  1.10k|      jv_free(next);
  881|  1.10k|    }
  882|  1.66k|  } else if (jv_invalid_has_msg(jv_copy(value))) {
  ------------------
  |  Branch (882:14): [True: 1.32k, False: 36]
  ------------------
  883|       |    // parse error, we'll return it
  884|  1.32k|  } else {
  885|       |    // no value at all
  886|     36|    jv_free(value);
  887|     36|    value = jv_invalid_with_msg(jv_string("Expected JSON value"));
  888|     36|  }
  889|  3.02k|  parser_free(&parser);
  890|       |
  891|  3.02k|  if (!jv_is_valid(value) && jv_invalid_has_msg(jv_copy(value))) {
  ------------------
  |  Branch (891:7): [True: 1.91k, False: 1.10k]
  |  Branch (891:30): [True: 1.91k, False: 0]
  ------------------
  892|  1.91k|    jv msg = jv_invalid_get_msg(value);
  893|  1.91k|    value = jv_invalid_with_msg(jv_string_fmt("%s (while parsing '%s')",
  894|  1.91k|                                              jv_string_value(msg),
  895|  1.91k|                                              string));
  896|  1.91k|    jv_free(msg);
  897|  1.91k|  }
  898|  3.02k|  return value;
  899|  3.02k|}
jv_parse:
  901|  3.02k|jv jv_parse(const char* string) {
  902|  3.02k|  return jv_parse_sized(string, strlen(string));
  903|  3.02k|}
jv_parse.c:parser_init:
   69|  3.02k|static void parser_init(struct jv_parser* p, int flags) {
   70|  3.02k|  p->flags = flags;
   71|  3.02k|  if ((p->flags & JV_PARSE_STREAMING)) {
  ------------------
  |  Branch (71:7): [True: 0, False: 3.02k]
  ------------------
   72|      0|    p->path = jv_array();
   73|  3.02k|  } else {
   74|  3.02k|    p->path = jv_invalid();
   75|  3.02k|    p->flags &= ~(JV_PARSE_STREAM_ERRORS);
   76|  3.02k|  }
   77|  3.02k|  p->stack = 0;
   78|  3.02k|  p->stacklen = p->stackpos = 0;
   79|  3.02k|  p->last_seen = JV_LAST_NONE;
   80|  3.02k|  p->output = jv_invalid();
   81|  3.02k|  p->next = jv_invalid();
   82|  3.02k|  p->tokenbuf = 0;
   83|  3.02k|  p->tokenlen = p->tokenpos = 0;
   84|  3.02k|  if ((p->flags & JV_PARSE_SEQ))
  ------------------
  |  Branch (84:7): [True: 0, False: 3.02k]
  ------------------
   85|      0|    p->st = JV_PARSER_WAITING_FOR_RS;
   86|  3.02k|  else
   87|  3.02k|    p->st = JV_PARSER_NORMAL;
   88|  3.02k|  p->eof = 0;
   89|  3.02k|  p->curr_buf = 0;
   90|  3.02k|  p->curr_buf_length = p->curr_buf_pos = p->curr_buf_is_partial = 0;
   91|  3.02k|  p->bom_strip_position = 0;
   92|  3.02k|  p->last_ch_was_ws = 0;
   93|  3.02k|  p->line = 1;
   94|  3.02k|  p->column = 0;
   95|  3.02k|  jvp_dtoa_context_init(&p->dtoa);
   96|  3.02k|}
jv_parse.c:parser_free:
  116|  3.02k|static void parser_free(struct jv_parser* p) {
  117|  3.02k|  parser_reset(p);
  118|  3.02k|  jv_free(p->path);
  119|  3.02k|  jv_free(p->output);
  120|  3.02k|  jv_mem_free(p->stack);
  121|  3.02k|  jv_mem_free(p->tokenbuf);
  122|  3.02k|  jvp_dtoa_context_free(&p->dtoa);
  123|  3.02k|}
jv_parse.c:parser_reset:
   98|  4.85k|static void parser_reset(struct jv_parser* p) {
   99|  4.85k|  if ((p->flags & JV_PARSE_STREAMING)) {
  ------------------
  |  Branch (99:7): [True: 0, False: 4.85k]
  ------------------
  100|      0|    jv_free(p->path);
  101|      0|    p->path = jv_array();
  102|      0|    p->stacklen = 0;
  103|      0|  }
  104|  4.85k|  p->last_seen = JV_LAST_NONE;
  105|  4.85k|  jv_free(p->output);
  106|  4.85k|  p->output = jv_invalid();
  107|  4.85k|  jv_free(p->next);
  108|  4.85k|  p->next = jv_invalid();
  109|  16.6k|  for (int i=0; i<p->stackpos; i++)
  ------------------
  |  Branch (109:17): [True: 11.8k, False: 4.85k]
  ------------------
  110|  11.8k|    jv_free(p->stack[i]);
  111|  4.85k|  p->stackpos = 0;
  112|  4.85k|  p->tokenpos = 0;
  113|  4.85k|  p->st = JV_PARSER_NORMAL;
  114|  4.85k|}
jv_parse.c:scan:
  642|  50.6M|static pfunc scan(struct jv_parser* p, char ch, jv* out) {
  643|  50.6M|  p->column++;
  644|  50.6M|  if (ch == '\n') {
  ------------------
  |  Branch (644:7): [True: 2.59k, False: 50.6M]
  ------------------
  645|  2.59k|    p->line++;
  646|  2.59k|    p->column = 0;
  647|  2.59k|  }
  648|  50.6M|  if ((p->flags & JV_PARSE_SEQ)
  ------------------
  |  Branch (648:7): [True: 0, False: 50.6M]
  ------------------
  649|  50.6M|      && ch == '\036' /* ASCII RS; see draft-ietf-json-sequence-07 */) {
  ------------------
  |  Branch (649:10): [True: 0, False: 0]
  ------------------
  650|      0|    if (check_truncation(p)) {
  ------------------
  |  |  637|      0|   (((p)->flags & JV_PARSE_STREAMING) ? stream_seq_check_truncation((p)) : seq_check_truncation((p)))
  |  |  ------------------
  |  |  |  Branch (637:4): [True: 0, False: 0]
  |  |  |  Branch (637:5): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  651|      0|      if (check_literal(p) == 0 && is_top_num(p))
  ------------------
  |  |  640|      0|   (((p)->flags & JV_PARSE_STREAMING) ? stream_is_top_num((p)) : parse_is_top_num((p)))
  |  |  ------------------
  |  |  |  Branch (640:4): [True: 0, False: 0]
  |  |  |  Branch (640:5): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (651:11): [True: 0, False: 0]
  ------------------
  652|      0|        return "Potentially truncated top-level numeric value";
  653|      0|      return "Truncated value";
  654|      0|    }
  655|      0|    TRY(check_literal(p));
  ------------------
  |  |   17|      0|#define TRY(x) do {presult msg__ = (x); if (msg__) return msg__; } while(0)
  |  |  ------------------
  |  |  |  Branch (17:45): [True: 0, False: 0]
  |  |  |  Branch (17:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  656|      0|    if (p->st == JV_PARSER_NORMAL && check_done(p, out))
  ------------------
  |  |  631|      0|   (((p)->flags & JV_PARSE_STREAMING) ? stream_check_done((p), (o)) : parse_check_done((p), (o)))
  |  |  ------------------
  |  |  |  Branch (631:4): [True: 0, False: 0]
  |  |  |  Branch (631:5): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  |  Branch (656:9): [True: 0, False: 0]
  ------------------
  657|      0|      return OK;
  658|       |    // shouldn't happen?
  659|      0|    assert(!jv_is_valid(*out));
  660|      0|    parser_reset(p);
  661|      0|    jv_free(*out);
  662|      0|    *out = jv_invalid();
  663|      0|    return OK;
  664|      0|  }
  665|  50.6M|  presult answer = 0;
  666|  50.6M|  p->last_ch_was_ws = 0;
  667|  50.6M|  if (p->st == JV_PARSER_NORMAL) {
  ------------------
  |  Branch (667:7): [True: 43.9M, False: 6.70M]
  ------------------
  668|  43.9M|    chclass cls = classify(ch);
  669|  43.9M|    if (cls == WHITESPACE)
  ------------------
  |  Branch (669:9): [True: 16.2k, False: 43.8M]
  ------------------
  670|  16.2k|      p->last_ch_was_ws = 1;
  671|  43.9M|    if (cls != LITERAL) {
  ------------------
  |  Branch (671:9): [True: 3.10M, False: 40.8M]
  ------------------
  672|  3.10M|      TRY(check_literal(p));
  ------------------
  |  |   17|  3.10M|#define TRY(x) do {presult msg__ = (x); if (msg__) return msg__; } while(0)
  |  |  ------------------
  |  |  |  Branch (17:45): [True: 22, False: 3.10M]
  |  |  |  Branch (17:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  673|  3.10M|      if (check_done(p, out)) answer = OK;
  ------------------
  |  |  631|  3.10M|   (((p)->flags & JV_PARSE_STREAMING) ? stream_check_done((p), (o)) : parse_check_done((p), (o)))
  |  |  ------------------
  |  |  |  Branch (631:4): [True: 416, False: 3.10M]
  |  |  |  Branch (631:5): [True: 0, False: 3.10M]
  |  |  ------------------
  ------------------
  674|  3.10M|    }
  675|  43.9M|    switch (cls) {
  ------------------
  |  Branch (675:13): [True: 0, False: 43.9M]
  ------------------
  676|  40.8M|    case LITERAL:
  ------------------
  |  Branch (676:5): [True: 40.8M, False: 3.10M]
  ------------------
  677|  40.8M|      tokenadd(p, ch);
  678|  40.8M|      break;
  679|  16.2k|    case WHITESPACE:
  ------------------
  |  Branch (679:5): [True: 16.2k, False: 43.8M]
  ------------------
  680|  16.2k|      break;
  681|  10.6k|    case QUOTE:
  ------------------
  |  Branch (681:5): [True: 10.6k, False: 43.8M]
  ------------------
  682|  10.6k|      p->st = JV_PARSER_STRING;
  683|  10.6k|      break;
  684|  3.07M|    case STRUCTURE:
  ------------------
  |  Branch (684:5): [True: 3.07M, False: 40.8M]
  ------------------
  685|  3.07M|      TRY(token(p, ch));
  ------------------
  |  |   17|  6.15M|#define TRY(x) do {presult msg__ = (x); if (msg__) return msg__; } while(0)
  |  |  ------------------
  |  |  |  Branch (17:37): [True: 0, False: 3.07M]
  |  |  |  Branch (17:45): [True: 129, False: 3.07M]
  |  |  |  Branch (17:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  686|  3.07M|      break;
  687|  3.07M|    case INVALID:
  ------------------
  |  Branch (687:5): [True: 0, False: 43.9M]
  ------------------
  688|      0|      return "Invalid character";
  689|  43.9M|    }
  690|  43.9M|    if (check_done(p, out)) answer = OK;
  ------------------
  |  |  631|  43.9M|   (((p)->flags & JV_PARSE_STREAMING) ? stream_check_done((p), (o)) : parse_check_done((p), (o)))
  |  |  ------------------
  |  |  |  Branch (631:4): [True: 94, False: 43.9M]
  |  |  |  Branch (631:5): [True: 0, False: 43.9M]
  |  |  ------------------
  ------------------
  691|  43.9M|  } else {
  692|  6.70M|    if (ch == '"' && p->st == JV_PARSER_STRING) {
  ------------------
  |  Branch (692:9): [True: 10.9k, False: 6.69M]
  |  Branch (692:22): [True: 10.5k, False: 402]
  ------------------
  693|  10.5k|      TRY(found_string(p));
  ------------------
  |  |   17|  10.5k|#define TRY(x) do {presult msg__ = (x); if (msg__) return msg__; } while(0)
  |  |  ------------------
  |  |  |  Branch (17:45): [True: 185, False: 10.3k]
  |  |  |  Branch (17:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  694|  10.3k|      p->st = JV_PARSER_NORMAL;
  695|  10.3k|      if (check_done(p, out)) answer = OK;
  ------------------
  |  |  631|  10.3k|   (((p)->flags & JV_PARSE_STREAMING) ? stream_check_done((p), (o)) : parse_check_done((p), (o)))
  |  |  ------------------
  |  |  |  Branch (631:4): [True: 298, False: 10.0k]
  |  |  |  Branch (631:5): [True: 0, False: 10.3k]
  |  |  ------------------
  ------------------
  696|  6.69M|    } else {
  697|  6.69M|      tokenadd(p, ch);
  698|  6.69M|      if (ch == '\\' && p->st == JV_PARSER_STRING) {
  ------------------
  |  Branch (698:11): [True: 6.86k, False: 6.68M]
  |  Branch (698:25): [True: 6.25k, False: 614]
  ------------------
  699|  6.25k|        p->st = JV_PARSER_STRING_ESCAPE;
  700|  6.68M|      } else {
  701|  6.68M|        p->st = JV_PARSER_STRING;
  702|  6.68M|      }
  703|  6.69M|    }
  704|  6.70M|  }
  705|  50.6M|  return answer;
  706|  50.6M|}
jv_parse.c:parse_check_done:
  581|  47.0M|static int parse_check_done(struct jv_parser* p, jv* out) {
  582|  47.0M|  if (p->stackpos == 0 && jv_is_valid(p->next)) {
  ------------------
  |  Branch (582:7): [True: 35.0M, False: 11.9M]
  |  Branch (582:27): [True: 808, False: 35.0M]
  ------------------
  583|    808|    *out = p->next;
  584|    808|    p->next = jv_invalid();
  585|    808|    return 1;
  586|  47.0M|  } else {
  587|  47.0M|    return 0;
  588|  47.0M|  }
  589|  47.0M|}
jv_parse.c:classify:
  557|  43.9M|static chclass classify(char c) {
  558|  43.9M|  switch (c) {
  559|    700|  case ' ':
  ------------------
  |  Branch (559:3): [True: 700, False: 43.9M]
  ------------------
  560|    985|  case '\t':
  ------------------
  |  Branch (560:3): [True: 285, False: 43.9M]
  ------------------
  561|  16.0k|  case '\r':
  ------------------
  |  Branch (561:3): [True: 15.0k, False: 43.8M]
  ------------------
  562|  16.2k|  case '\n':
  ------------------
  |  Branch (562:3): [True: 223, False: 43.9M]
  ------------------
  563|  16.2k|    return WHITESPACE;
  564|  10.6k|  case '"':
  ------------------
  |  Branch (564:3): [True: 10.6k, False: 43.8M]
  ------------------
  565|  10.6k|    return QUOTE;
  566|  9.29k|  case '[':
  ------------------
  |  Branch (566:3): [True: 9.29k, False: 43.9M]
  ------------------
  567|  3.05M|  case ',':
  ------------------
  |  Branch (567:3): [True: 3.04M, False: 40.8M]
  ------------------
  568|  3.06M|  case ']':
  ------------------
  |  Branch (568:3): [True: 4.26k, False: 43.9M]
  ------------------
  569|  3.06M|  case '{':
  ------------------
  |  Branch (569:3): [True: 7.63k, False: 43.9M]
  ------------------
  570|  3.07M|  case ':':
  ------------------
  |  Branch (570:3): [True: 8.61k, False: 43.9M]
  ------------------
  571|  3.07M|  case '}':
  ------------------
  |  Branch (571:3): [True: 1.34k, False: 43.9M]
  ------------------
  572|  3.07M|    return STRUCTURE;
  573|  40.8M|  default:
  ------------------
  |  Branch (573:3): [True: 40.8M, False: 3.10M]
  ------------------
  574|  40.8M|    return LITERAL;
  575|  43.9M|  }
  576|  43.9M|}
jv_parse.c:tokenadd:
  421|  47.4M|static void tokenadd(struct jv_parser* p, char c) {
  422|  47.4M|  assert(p->tokenpos <= p->tokenlen);
  423|  47.4M|  if (p->tokenpos >= (p->tokenlen - 1)) {
  ------------------
  |  Branch (423:7): [True: 4.78k, False: 47.4M]
  ------------------
  424|  4.78k|    p->tokenlen = p->tokenlen*2 + 256;
  425|  4.78k|    p->tokenbuf = jv_mem_realloc(p->tokenbuf, p->tokenlen);
  426|  4.78k|  }
  427|  47.4M|  assert(p->tokenpos < p->tokenlen);
  428|  47.4M|  p->tokenbuf[p->tokenpos++] = c;
  429|  47.4M|}
jv_parse.c:parse_token:
  156|  3.07M|static pfunc parse_token(struct jv_parser* p, char ch) {
  157|  3.07M|  switch (ch) {
  ------------------
  |  Branch (157:11): [True: 0, False: 3.07M]
  ------------------
  158|  9.29k|  case '[':
  ------------------
  |  Branch (158:3): [True: 9.29k, False: 3.06M]
  ------------------
  159|  9.29k|    if (p->stackpos >= MAX_PARSING_DEPTH) return "Exceeds depth limit for parsing";
  ------------------
  |  |   14|  9.29k|#define MAX_PARSING_DEPTH (256)
  ------------------
  |  Branch (159:9): [True: 1, False: 9.29k]
  ------------------
  160|  9.29k|    if (jv_is_valid(p->next)) return "Expected separator between values";
  ------------------
  |  Branch (160:9): [True: 4, False: 9.28k]
  ------------------
  161|  9.28k|    push(p, jv_array());
  162|  9.28k|    break;
  163|       |
  164|  7.63k|  case '{':
  ------------------
  |  Branch (164:3): [True: 7.63k, False: 3.07M]
  ------------------
  165|  7.63k|    if (p->stackpos >= MAX_PARSING_DEPTH) return "Exceeds depth limit for parsing";
  ------------------
  |  |   14|  7.63k|#define MAX_PARSING_DEPTH (256)
  ------------------
  |  Branch (165:9): [True: 1, False: 7.63k]
  ------------------
  166|  7.63k|    if (jv_is_valid(p->next)) return "Expected separator between values";
  ------------------
  |  Branch (166:9): [True: 4, False: 7.62k]
  ------------------
  167|  7.62k|    push(p, jv_object());
  168|  7.62k|    break;
  169|       |
  170|  8.61k|  case ':':
  ------------------
  |  Branch (170:3): [True: 8.61k, False: 3.07M]
  ------------------
  171|  8.61k|    if (!jv_is_valid(p->next))
  ------------------
  |  Branch (171:9): [True: 10, False: 8.60k]
  ------------------
  172|     10|      return "Expected string key before ':'";
  173|  8.60k|    if (p->stackpos == 0 || jv_get_kind(p->stack[p->stackpos-1]) != JV_KIND_OBJECT)
  ------------------
  |  Branch (173:9): [True: 0, False: 8.60k]
  |  Branch (173:29): [True: 4, False: 8.59k]
  ------------------
  174|      4|      return "':' not as part of an object";
  175|  8.59k|    if (jv_get_kind(p->next) != JV_KIND_STRING)
  ------------------
  |  Branch (175:9): [True: 11, False: 8.58k]
  ------------------
  176|     11|      return "Object keys must be strings";
  177|  8.58k|    push(p, p->next);
  178|  8.58k|    p->next = jv_invalid();
  179|  8.58k|    break;
  180|       |
  181|  3.04M|  case ',':
  ------------------
  |  Branch (181:3): [True: 3.04M, False: 31.1k]
  ------------------
  182|  3.04M|    if (!jv_is_valid(p->next))
  ------------------
  |  Branch (182:9): [True: 11, False: 3.04M]
  ------------------
  183|     11|      return "Expected value before ','";
  184|  3.04M|    if (p->stackpos == 0)
  ------------------
  |  Branch (184:9): [True: 0, False: 3.04M]
  ------------------
  185|      0|      return "',' not as part of an object or array";
  186|  3.04M|    if (jv_get_kind(p->stack[p->stackpos-1]) == JV_KIND_ARRAY) {
  ------------------
  |  Branch (186:9): [True: 3.03M, False: 7.66k]
  ------------------
  187|  3.03M|      p->stack[p->stackpos-1] = jv_array_append(p->stack[p->stackpos-1], p->next);
  188|  3.03M|      p->next = jv_invalid();
  189|  3.03M|    } else if (jv_get_kind(p->stack[p->stackpos-1]) == JV_KIND_STRING) {
  ------------------
  |  Branch (189:16): [True: 7.66k, False: 3]
  ------------------
  190|  7.66k|      assert(p->stackpos > 1 && jv_get_kind(p->stack[p->stackpos-2]) == JV_KIND_OBJECT);
  191|  7.66k|      p->stack[p->stackpos-2] = jv_object_set(p->stack[p->stackpos-2],
  192|  7.66k|                                              p->stack[p->stackpos-1], p->next);
  193|  7.66k|      p->stackpos--;
  194|  7.66k|      p->next = jv_invalid();
  195|  7.66k|    } else {
  196|       |      // this case hits on input like {"a", "b"}
  197|      3|      return "Objects must consist of key:value pairs";
  198|      3|    }
  199|  3.04M|    break;
  200|       |
  201|  3.04M|  case ']':
  ------------------
  |  Branch (201:3): [True: 4.26k, False: 3.07M]
  ------------------
  202|  4.26k|    if (p->stackpos == 0 || jv_get_kind(p->stack[p->stackpos-1]) != JV_KIND_ARRAY)
  ------------------
  |  Branch (202:9): [True: 13, False: 4.25k]
  |  Branch (202:29): [True: 5, False: 4.24k]
  ------------------
  203|     18|      return "Unmatched ']'";
  204|  4.24k|    if (jv_is_valid(p->next)) {
  ------------------
  |  Branch (204:9): [True: 3.57k, False: 676]
  ------------------
  205|  3.57k|      p->stack[p->stackpos-1] = jv_array_append(p->stack[p->stackpos-1], p->next);
  206|  3.57k|      p->next = jv_invalid();
  207|  3.57k|    } else {
  208|    676|      if (jv_array_length(jv_copy(p->stack[p->stackpos-1])) != 0) {
  ------------------
  |  Branch (208:11): [True: 32, False: 644]
  ------------------
  209|       |        // this case hits on input like [1,2,3,]
  210|     32|        return "Expected another array element";
  211|     32|      }
  212|    676|    }
  213|  4.21k|    jv_free(p->next);
  214|  4.21k|    p->next = p->stack[--p->stackpos];
  215|  4.21k|    break;
  216|       |
  217|  1.34k|  case '}':
  ------------------
  |  Branch (217:3): [True: 1.34k, False: 3.07M]
  ------------------
  218|  1.34k|    if (p->stackpos == 0)
  ------------------
  |  Branch (218:9): [True: 5, False: 1.34k]
  ------------------
  219|      5|      return "Unmatched '}'";
  220|  1.34k|    if (jv_is_valid(p->next)) {
  ------------------
  |  Branch (220:9): [True: 508, False: 832]
  ------------------
  221|    508|      if (jv_get_kind(p->stack[p->stackpos-1]) != JV_KIND_STRING)
  ------------------
  |  Branch (221:11): [True: 8, False: 500]
  ------------------
  222|      8|        return "Objects must consist of key:value pairs";
  223|    500|      assert(p->stackpos > 1 && jv_get_kind(p->stack[p->stackpos-2]) == JV_KIND_OBJECT);
  224|    500|      p->stack[p->stackpos-2] = jv_object_set(p->stack[p->stackpos-2],
  225|    500|                                              p->stack[p->stackpos-1], p->next);
  226|    500|      p->stackpos--;
  227|    500|      p->next = jv_invalid();
  228|    832|    } else {
  229|    832|      if (jv_get_kind(p->stack[p->stackpos-1]) != JV_KIND_OBJECT)
  ------------------
  |  Branch (229:11): [True: 4, False: 828]
  ------------------
  230|      4|        return "Unmatched '}'";
  231|    828|      if (jv_object_length(jv_copy(p->stack[p->stackpos-1])) != 0)
  ------------------
  |  Branch (231:11): [True: 13, False: 815]
  ------------------
  232|     13|        return "Expected another key-value pair";
  233|    828|    }
  234|  1.31k|    jv_free(p->next);
  235|  1.31k|    p->next = p->stack[--p->stackpos];
  236|  1.31k|    break;
  237|  3.07M|  }
  238|  3.07M|  return 0;
  239|  3.07M|}
jv_parse.c:push:
  146|  25.5k|static void push(struct jv_parser* p, jv v) {
  147|  25.5k|  assert(p->stackpos <= p->stacklen);
  148|  25.5k|  if (p->stackpos == p->stacklen) {
  ------------------
  |  Branch (148:7): [True: 1.59k, False: 23.9k]
  ------------------
  149|  1.59k|    p->stacklen = p->stacklen * 2 + 10;
  150|  1.59k|    p->stack = jv_mem_realloc(p->stack, p->stacklen * sizeof(jv));
  151|  1.59k|  }
  152|  25.5k|  assert(p->stackpos < p->stacklen);
  153|  25.5k|  p->stack[p->stackpos++] = v;
  154|  25.5k|}
jv_parse.c:found_string:
  446|  10.5k|static pfunc found_string(struct jv_parser* p) {
  447|  10.5k|  char* in = p->tokenbuf;
  448|  10.5k|  char* out = p->tokenbuf;
  449|  10.5k|  char* end = p->tokenbuf + p->tokenpos;
  450|       |
  451|  4.60M|  while (in < end) {
  ------------------
  |  Branch (451:10): [True: 4.59M, False: 10.3k]
  ------------------
  452|  4.59M|    char c = *in++;
  453|  4.59M|    if (c == '\\') {
  ------------------
  |  Branch (453:9): [True: 4.39k, False: 4.58M]
  ------------------
  454|  4.39k|      if (in >= end)
  ------------------
  |  Branch (454:11): [True: 0, False: 4.39k]
  ------------------
  455|      0|        return "Expected escape character at end of string";
  456|  4.39k|      c = *in++;
  457|  4.39k|      switch (c) {
  458|    233|      case '\\':
  ------------------
  |  Branch (458:7): [True: 233, False: 4.16k]
  ------------------
  459|    431|      case '"':
  ------------------
  |  Branch (459:7): [True: 198, False: 4.20k]
  ------------------
  460|    689|      case '/': *out++ = c;    break;
  ------------------
  |  Branch (460:7): [True: 258, False: 4.14k]
  ------------------
  461|    919|      case 'b': *out++ = '\b'; break;
  ------------------
  |  Branch (461:7): [True: 919, False: 3.47k]
  ------------------
  462|  1.07k|      case 'f': *out++ = '\f'; break;
  ------------------
  |  Branch (462:7): [True: 1.07k, False: 3.32k]
  ------------------
  463|    194|      case 't': *out++ = '\t'; break;
  ------------------
  |  Branch (463:7): [True: 194, False: 4.20k]
  ------------------
  464|    194|      case 'n': *out++ = '\n'; break;
  ------------------
  |  Branch (464:7): [True: 194, False: 4.20k]
  ------------------
  465|    194|      case 'r': *out++ = '\r'; break;
  ------------------
  |  Branch (465:7): [True: 194, False: 4.20k]
  ------------------
  466|       |
  467|  1.13k|      case 'u':
  ------------------
  |  Branch (467:7): [True: 1.13k, False: 3.26k]
  ------------------
  468|       |        /* ahh, the complicated case */
  469|  1.13k|        if (in + 4 > end)
  ------------------
  |  Branch (469:13): [True: 1, False: 1.13k]
  ------------------
  470|      1|          return "Invalid \\uXXXX escape";
  471|  1.13k|        int hexvalue = unhex4(in);
  472|  1.13k|        if (hexvalue < 0)
  ------------------
  |  Branch (472:13): [True: 28, False: 1.10k]
  ------------------
  473|     28|          return "Invalid characters in \\uXXXX escape";
  474|  1.10k|        unsigned long codepoint = (unsigned long)hexvalue;
  475|  1.10k|        in += 4;
  476|  1.10k|        if (0xD800 <= codepoint && codepoint <= 0xDBFF) {
  ------------------
  |  Branch (476:13): [True: 792, False: 311]
  |  Branch (476:36): [True: 526, False: 266]
  ------------------
  477|       |          /* who thought UTF-16 surrogate pairs were a good idea? */
  478|    526|          if (in + 6 > end || in[0] != '\\' || in[1] != 'u')
  ------------------
  |  Branch (478:15): [True: 9, False: 517]
  |  Branch (478:31): [True: 10, False: 507]
  |  Branch (478:48): [True: 6, False: 501]
  ------------------
  479|     25|            return "Invalid \\uXXXX\\uXXXX surrogate pair escape";
  480|    501|          unsigned long surrogate = unhex4(in+2);
  481|    501|          if (!(0xDC00 <= surrogate && surrogate <= 0xDFFF))
  ------------------
  |  Branch (481:17): [True: 481, False: 20]
  |  Branch (481:40): [True: 449, False: 32]
  ------------------
  482|     52|            return "Invalid \\uXXXX\\uXXXX surrogate pair escape";
  483|    449|          in += 6;
  484|    449|          codepoint = 0x10000 + (((codepoint - 0xD800) << 10)
  485|    449|                                 |(surrogate - 0xDC00));
  486|    449|        }
  487|  1.02k|        if (codepoint > 0x10FFFF)
  ------------------
  |  Branch (487:13): [True: 0, False: 1.02k]
  ------------------
  488|      0|          codepoint = 0xFFFD; // U+FFFD REPLACEMENT CHARACTER
  489|  1.02k|        out += jvp_utf8_encode(codepoint, out);
  490|  1.02k|        break;
  491|       |
  492|      1|      default:
  ------------------
  |  Branch (492:7): [True: 1, False: 4.39k]
  ------------------
  493|      1|        return "Invalid escape";
  494|  4.39k|      }
  495|  4.58M|    } else {
  496|  4.58M|      if (c > 0 && c < 0x001f)
  ------------------
  |  Branch (496:11): [True: 1.86M, False: 2.72M]
  |  Branch (496:20): [True: 50, False: 1.86M]
  ------------------
  497|     50|        return "Invalid string: control characters from U+0000 through U+001F must be escaped";
  498|  4.58M|      *out++ = c;
  499|  4.58M|    }
  500|  4.59M|  }
  501|  10.3k|  TRY(value(p, jv_string_sized(p->tokenbuf, out - p->tokenbuf)));
  ------------------
  |  |   17|  10.3k|#define TRY(x) do {presult msg__ = (x); if (msg__) return msg__; } while(0)
  |  |  ------------------
  |  |  |  Branch (17:45): [True: 28, False: 10.3k]
  |  |  |  Branch (17:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  502|  10.3k|  p->tokenpos = 0;
  503|  10.3k|  return 0;
  504|  10.3k|}
jv_parse.c:unhex4:
  431|  1.63k|static int unhex4(char* hex) {
  432|  1.63k|  int r = 0;
  433|  8.01k|  for (int i=0; i<4; i++) {
  ------------------
  |  Branch (433:17): [True: 6.43k, False: 1.57k]
  ------------------
  434|  6.43k|    char c = *hex++;
  435|  6.43k|    int n;
  436|  6.43k|    if ('0' <= c && c <= '9') n = c - '0';
  ------------------
  |  Branch (436:9): [True: 6.41k, False: 22]
  |  Branch (436:21): [True: 2.45k, False: 3.95k]
  ------------------
  437|  3.97k|    else if ('a' <= c && c <= 'f') n = c - 'a' + 10;
  ------------------
  |  Branch (437:14): [True: 2.20k, False: 1.77k]
  |  Branch (437:26): [True: 2.19k, False: 10]
  ------------------
  438|  1.78k|    else if ('A' <= c && c <= 'F') n = c - 'A' + 10;
  ------------------
  |  Branch (438:14): [True: 1.75k, False: 30]
  |  Branch (438:26): [True: 1.73k, False: 24]
  ------------------
  439|     54|    else return -1;
  440|  6.37k|    r <<= 4;
  441|  6.37k|    r |= n;
  442|  6.37k|  }
  443|  1.57k|  return r;
  444|  1.63k|}
jv_parse.c:value:
  125|  3.05M|static pfunc value(struct jv_parser* p, jv val) {
  126|  3.05M|  if ((p->flags & JV_PARSE_STREAMING)) {
  ------------------
  |  Branch (126:7): [True: 0, False: 3.05M]
  ------------------
  127|      0|    if (jv_is_valid(p->next) || p->last_seen == JV_LAST_VALUE) {
  ------------------
  |  Branch (127:9): [True: 0, False: 0]
  |  Branch (127:33): [True: 0, False: 0]
  ------------------
  128|      0|      jv_free(val);
  129|      0|      return "Expected separator between values";
  130|      0|    }
  131|      0|    if (p->stacklen > 0)
  ------------------
  |  Branch (131:9): [True: 0, False: 0]
  ------------------
  132|      0|      p->last_seen = JV_LAST_VALUE;
  133|      0|    else
  134|      0|      p->last_seen = JV_LAST_NONE;
  135|  3.05M|  } else {
  136|  3.05M|    if (jv_is_valid(p->next)) {
  ------------------
  |  Branch (136:9): [True: 51, False: 3.05M]
  ------------------
  137|     51|      jv_free(val);
  138|     51|      return "Expected separator between values";
  139|     51|    }
  140|  3.05M|  }
  141|  3.05M|  jv_free(p->next);
  142|  3.05M|  p->next = val;
  143|  3.05M|  return 0;
  144|  3.05M|}
jv_parse.c:make_error:
  755|  1.82k|static jv make_error(struct jv_parser* p, const char *fmt, ...) {
  756|  1.82k|  va_list ap;
  757|  1.82k|  va_start(ap, fmt);
  758|  1.82k|  jv e = jv_string_vfmt(fmt, ap);
  759|  1.82k|  va_end(ap);
  760|  1.82k|  if ((p->flags & JV_PARSE_STREAM_ERRORS))
  ------------------
  |  Branch (760:7): [True: 0, False: 1.82k]
  ------------------
  761|      0|    return JV_ARRAY(e, jv_copy(p->path));
  ------------------
  |  |  105|      0|  JV_ARRAY_IDX(__VA_ARGS__, JV_ARRAY_9, JV_ARRAY_8, JV_ARRAY_7, JV_ARRAY_6, JV_ARRAY_5, JV_ARRAY_4, JV_ARRAY_3, JV_ARRAY_2, JV_ARRAY_1, dummy)(__VA_ARGS__)
  |  |  ------------------
  |  |  |  |  103|      0|#define JV_ARRAY_IDX(_1,_2,_3,_4,_5,_6,_7,_8,_9,NAME,...) NAME
  |  |  |  |  ------------------
  |  |  |  |  |  |  105|      0|  JV_ARRAY_IDX(__VA_ARGS__, JV_ARRAY_9, JV_ARRAY_8, JV_ARRAY_7, JV_ARRAY_6, JV_ARRAY_5, JV_ARRAY_4, JV_ARRAY_3, JV_ARRAY_2, JV_ARRAY_1, dummy)(__VA_ARGS__)
  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |   95|      0|#define JV_ARRAY_2(e1,e2) (jv_array_append(JV_ARRAY_1(e1),e2))
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  |  |  |  |   94|      0|#define JV_ARRAY_1(e) (jv_array_append(jv_array(),e))
  |  |  |  |  |  |  |  |  ------------------
  |  |  |  |  |  |  ------------------
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  762|  1.82k|  return jv_invalid_with_msg(e);
  763|  1.82k|}
jv_parse.c:check_literal:
  506|  3.10M|static pfunc check_literal(struct jv_parser* p) {
  507|  3.10M|  if (p->tokenpos == 0) return 0;
  ------------------
  |  Branch (507:7): [True: 61.0k, False: 3.04M]
  ------------------
  508|       |
  509|  3.04M|  const char* pattern = 0;
  510|  3.04M|  int plen;
  511|  3.04M|  jv v;
  512|  3.04M|  switch (p->tokenbuf[0]) {
  ------------------
  |  Branch (512:11): [True: 3.04M, False: 1.40k]
  ------------------
  513|    254|  case 't': pattern = "true"; plen = 4; v = jv_true(); break;
  ------------------
  |  Branch (513:3): [True: 254, False: 3.04M]
  ------------------
  514|    250|  case 'f': pattern = "false"; plen = 5; v = jv_false(); break;
  ------------------
  |  Branch (514:3): [True: 250, False: 3.04M]
  ------------------
  515|    905|  case 'n':
  ------------------
  |  Branch (515:3): [True: 905, False: 3.04M]
  ------------------
  516|       |    // if it starts with 'n', it could be a literal "nan"
  517|    905|    if (p->tokenpos != 3) {
  ------------------
  |  Branch (517:9): [True: 573, False: 332]
  ------------------
  518|    573|      pattern = "null"; plen = 4; v = jv_null();
  519|    573|    }
  520|  3.04M|  }
  521|  3.04M|  if (pattern) {
  ------------------
  |  Branch (521:7): [True: 1.07k, False: 3.04M]
  ------------------
  522|  1.07k|    if (p->tokenpos != plen) return "Invalid literal";
  ------------------
  |  Branch (522:9): [True: 68, False: 1.00k]
  ------------------
  523|  5.27k|    for (int i=0; i<plen; i++)
  ------------------
  |  Branch (523:19): [True: 4.26k, False: 1.00k]
  ------------------
  524|  4.26k|      if (p->tokenbuf[i] != pattern[i])
  ------------------
  |  Branch (524:11): [True: 4, False: 4.26k]
  ------------------
  525|      4|        return "Invalid literal";
  526|  1.00k|    TRY(value(p, v));
  ------------------
  |  |   17|  1.00k|#define TRY(x) do {presult msg__ = (x); if (msg__) return msg__; } while(0)
  |  |  ------------------
  |  |  |  Branch (17:45): [True: 2, False: 1.00k]
  |  |  |  Branch (17:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  527|  3.04M|  } else {
  528|       |    // FIXME: better parser
  529|  3.04M|    p->tokenbuf[p->tokenpos] = 0;
  530|  3.04M|#ifdef USE_DECNUM
  531|  3.04M|    jv number = jv_number_with_literal(p->tokenbuf);
  532|  3.04M|    if (jv_get_kind(number) == JV_KIND_INVALID) {
  ------------------
  |  Branch (532:9): [True: 529, False: 3.04M]
  ------------------
  533|    529|      return "Invalid numeric literal";
  534|    529|    }
  535|  3.04M|    TRY(value(p, number));
  ------------------
  |  |   17|  3.04M|#define TRY(x) do {presult msg__ = (x); if (msg__) return msg__; } while(0)
  |  |  ------------------
  |  |  |  Branch (17:45): [True: 21, False: 3.04M]
  |  |  |  Branch (17:74): [Folded - Ignored]
  |  |  ------------------
  ------------------
  536|       |#else
  537|       |    char *end = 0;
  538|       |    double d = jvp_strtod(&p->dtoa, p->tokenbuf, &end);
  539|       |    if (end == 0 || *end != 0) {
  540|       |      return "Invalid numeric literal";
  541|       |    }
  542|       |    TRY(value(p, jv_number(d)));
  543|       |#endif
  544|  3.04M|  }
  545|  3.04M|  p->tokenpos = 0;
  546|  3.04M|  return 0;
  547|  3.04M|}

jvp_utf8_next:
   29|  36.1M|const char* jvp_utf8_next(const char* in, const char* end, int* codepoint_ret) {
   30|  36.1M|  assert(in <= end);
   31|  36.1M|  if (in == end) {
  ------------------
  |  Branch (31:7): [True: 14.2k, False: 36.1M]
  ------------------
   32|  14.2k|    return 0;
   33|  14.2k|  }
   34|  36.1M|  int codepoint = -1;
   35|  36.1M|  unsigned char first = (unsigned char)in[0];
   36|  36.1M|  int length = utf8_coding_length[first];
   37|  36.1M|  if ((first & 0x80) == 0) {
  ------------------
  |  Branch (37:7): [True: 27.6M, False: 8.50M]
  ------------------
   38|       |    /* Fast-path for ASCII */
   39|  27.6M|    codepoint = first;
   40|  27.6M|    length = 1;
   41|  27.6M|  } else if (length == 0 || length == UTF8_CONTINUATION_BYTE) {
  ------------------
  |  |    1|  6.68M|#define UTF8_CONTINUATION_BYTE ((unsigned char)255)
  ------------------
  |  Branch (41:14): [True: 1.81M, False: 6.68M]
  |  Branch (41:29): [True: 6.44M, False: 245k]
  ------------------
   42|       |    /* Bad single byte - either an invalid byte or an out-of-place continuation byte */
   43|  8.25M|    length = 1;
   44|  8.25M|  } else if (in + length > end) {
  ------------------
  |  Branch (44:14): [True: 1.48k, False: 243k]
  ------------------
   45|       |    /* String ends before UTF8 sequence ends */
   46|  1.48k|    length = end - in;
   47|   243k|  } else {
   48|   243k|    codepoint = ((unsigned)in[0]) & utf8_coding_bits[first];
   49|   277k|    for (int i=1; i<length; i++) {
  ------------------
  |  Branch (49:19): [True: 260k, False: 16.5k]
  ------------------
   50|   260k|      unsigned ch = (unsigned char)in[i];
   51|   260k|      if (utf8_coding_length[ch] != UTF8_CONTINUATION_BYTE){
  ------------------
  |  |    1|   260k|#define UTF8_CONTINUATION_BYTE ((unsigned char)255)
  ------------------
  |  Branch (51:11): [True: 227k, False: 33.5k]
  ------------------
   52|       |        /* Invalid UTF8 sequence - not followed by the right number of continuation bytes */
   53|   227k|        codepoint = -1;
   54|   227k|        length = i;
   55|   227k|        break;
   56|   227k|      }
   57|  33.5k|      codepoint = (codepoint << 6) | (ch & 0x3f);
   58|  33.5k|    }
   59|   243k|    if (codepoint < utf8_first_codepoint[length]) {
  ------------------
  |  Branch (59:9): [True: 227k, False: 16.5k]
  ------------------
   60|       |      /* Overlong UTF8 sequence */
   61|   227k|      codepoint = -1;
   62|   227k|    }
   63|   243k|    if (0xD800 <= codepoint && codepoint <= 0xDFFF) {
  ------------------
  |  Branch (63:9): [True: 6.73k, False: 236k]
  |  Branch (63:32): [True: 331, False: 6.40k]
  ------------------
   64|       |      /* Surrogate codepoints can't be encoded in UTF8 */
   65|    331|      codepoint = -1;
   66|    331|    }
   67|   243k|    if (codepoint > 0x10FFFF) {
  ------------------
  |  Branch (67:9): [True: 222, False: 243k]
  ------------------
   68|       |      /* Outside Unicode range */
   69|    222|      codepoint = -1;
   70|    222|    }
   71|   243k|  }
   72|  36.1M|  assert(length > 0);
   73|  36.1M|  *codepoint_ret = codepoint;
   74|  36.1M|  return in + length;
   75|  36.1M|}
jvp_utf8_is_valid:
   77|  14.2k|int jvp_utf8_is_valid(const char* in, const char* end) {
   78|  14.2k|  int codepoint;
   79|  11.9M|  while ((in = jvp_utf8_next(in, end, &codepoint))) {
  ------------------
  |  Branch (79:10): [True: 11.9M, False: 10.9k]
  ------------------
   80|  11.9M|    if (codepoint == -1) return 0;
  ------------------
  |  Branch (80:9): [True: 3.29k, False: 11.9M]
  ------------------
   81|  11.9M|  }
   82|  10.9k|  return 1;
   83|  14.2k|}
jvp_utf8_encode_length:
   93|  24.2M|int jvp_utf8_encode_length(int codepoint) {
   94|  24.2M|  if (codepoint <= 0x7F) return 1;
  ------------------
  |  Branch (94:7): [True: 15.7M, False: 8.49M]
  ------------------
   95|  8.49M|  else if (codepoint <= 0x7FF) return 2;
  ------------------
  |  Branch (95:12): [True: 5.61k, False: 8.49M]
  ------------------
   96|  8.49M|  else if (codepoint <= 0xFFFF) return 3;
  ------------------
  |  Branch (96:12): [True: 8.48M, False: 5.72k]
  ------------------
   97|  5.72k|  else return 4;
   98|  24.2M|}
jvp_utf8_encode:
  100|  24.2M|int jvp_utf8_encode(int codepoint, char* out) {
  101|  24.2M|  assert(codepoint >= 0 && codepoint <= 0x10FFFF);
  102|  24.2M|  char* start = out;
  103|  24.2M|  if (codepoint <= 0x7F) {
  ------------------
  |  Branch (103:7): [True: 15.7M, False: 8.49M]
  ------------------
  104|  15.7M|    *out++ = codepoint;
  105|  15.7M|  } else if (codepoint <= 0x7FF) {
  ------------------
  |  Branch (105:14): [True: 5.61k, False: 8.49M]
  ------------------
  106|  5.61k|    *out++ = 0xC0 + ((codepoint & 0x7C0) >> 6);
  107|  5.61k|    *out++ = 0x80 + ((codepoint & 0x03F));
  108|  8.49M|  } else if(codepoint <= 0xFFFF) {
  ------------------
  |  Branch (108:13): [True: 8.48M, False: 5.72k]
  ------------------
  109|  8.48M|    *out++ = 0xE0 + ((codepoint & 0xF000) >> 12);
  110|  8.48M|    *out++ = 0x80 + ((codepoint & 0x0FC0) >> 6);
  111|  8.48M|    *out++ = 0x80 + ((codepoint & 0x003F));
  112|  8.48M|  } else {
  113|  5.72k|    *out++ = 0xF0 + ((codepoint & 0x1C0000) >> 18);
  114|  5.72k|    *out++ = 0x80 + ((codepoint & 0x03F000) >> 12);
  115|  5.72k|    *out++ = 0x80 + ((codepoint & 0x000FC0) >> 6);
  116|  5.72k|    *out++ = 0x80 + ((codepoint & 0x00003F));
  117|  5.72k|  }
  118|  24.2M|  assert(out - start == jvp_utf8_encode_length(codepoint));
  119|  24.2M|  return out - start;
  120|  24.2M|}

LLVMFuzzerTestOneInput:
    7|  3.02k|int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
    8|       |  // Creat null-terminated string
    9|  3.02k|  char *null_terminated = (char *)malloc(size + 1);
   10|  3.02k|  memcpy(null_terminated, (char *)data, size);
   11|  3.02k|  null_terminated[size] = '\0';
   12|       |
   13|       |  // Fuzzer entrypoint
   14|  3.02k|  jv res = jv_parse(null_terminated);
   15|  3.02k|  jv_free(res);
   16|       |
   17|       |  // Free the null-terminated string
   18|  3.02k|  free(null_terminated);
   19|       |
   20|  3.02k|  return 0;
   21|  3.02k|}

