oggpack_writeinit:
   39|  2.25k|void oggpack_writeinit(oggpack_buffer *b){
   40|  2.25k|  memset(b,0,sizeof(*b));
   41|  2.25k|  b->ptr=b->buffer=_ogg_malloc(BUFFER_INCREMENT);
  ------------------
  |  |   21|  2.25k|#define _ogg_malloc  malloc
  ------------------
                b->ptr=b->buffer=_ogg_malloc(BUFFER_INCREMENT);
  ------------------
  |  |   25|  2.25k|#define BUFFER_INCREMENT 256
  ------------------
   42|  2.25k|  if (!b->buffer)
  ------------------
  |  Branch (42:7): [True: 0, False: 2.25k]
  ------------------
   43|      0|    return;
   44|  2.25k|  b->buffer[0]='\0';
   45|  2.25k|  b->storage=BUFFER_INCREMENT;
  ------------------
  |  |   25|  2.25k|#define BUFFER_INCREMENT 256
  ------------------
   46|  2.25k|}
oggpackB_writeinit:
   48|  1.12k|void oggpackB_writeinit(oggpack_buffer *b){
   49|  1.12k|  oggpack_writeinit(b);
   50|  1.12k|}
oggpack_write:
   84|  13.4M|void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
   85|  13.4M|  if(bits<0 || bits>32) goto err;
  ------------------
  |  Branch (85:6): [True: 0, False: 13.4M]
  |  Branch (85:16): [True: 0, False: 13.4M]
  ------------------
   86|  13.4M|  if(b->endbyte>=b->storage-4){
  ------------------
  |  Branch (86:6): [True: 17.2k, False: 13.4M]
  ------------------
   87|  17.2k|    void *ret;
   88|  17.2k|    if(!b->ptr)return;
  ------------------
  |  Branch (88:8): [True: 0, False: 17.2k]
  ------------------
   89|  17.2k|    if(b->storage>LONG_MAX-BUFFER_INCREMENT) goto err;
  ------------------
  |  |   25|  17.2k|#define BUFFER_INCREMENT 256
  ------------------
  |  Branch (89:8): [True: 0, False: 17.2k]
  ------------------
   90|  17.2k|    ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  ------------------
  |  |   23|  17.2k|#define _ogg_realloc realloc
  ------------------
                  ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  ------------------
  |  |   25|  17.2k|#define BUFFER_INCREMENT 256
  ------------------
   91|  17.2k|    if(!ret) goto err;
  ------------------
  |  Branch (91:8): [True: 0, False: 17.2k]
  ------------------
   92|  17.2k|    b->buffer=ret;
   93|  17.2k|    b->storage+=BUFFER_INCREMENT;
  ------------------
  |  |   25|  17.2k|#define BUFFER_INCREMENT 256
  ------------------
   94|  17.2k|    b->ptr=b->buffer+b->endbyte;
   95|  17.2k|  }
   96|       |
   97|  13.4M|  value&=mask[bits];
   98|  13.4M|  bits+=b->endbit;
   99|       |
  100|  13.4M|  b->ptr[0]|=value<<b->endbit;
  101|       |
  102|  13.4M|  if(bits>=8){
  ------------------
  |  Branch (102:6): [True: 13.1M, False: 323k]
  ------------------
  103|  13.1M|    b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  104|  13.1M|    if(bits>=16){
  ------------------
  |  Branch (104:8): [True: 1.35M, False: 11.7M]
  ------------------
  105|  1.35M|      b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  106|  1.35M|      if(bits>=24){
  ------------------
  |  Branch (106:10): [True: 1.12M, False: 225k]
  ------------------
  107|  1.12M|        b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  108|  1.12M|        if(bits>=32){
  ------------------
  |  Branch (108:12): [True: 979k, False: 145k]
  ------------------
  109|   979k|          if(b->endbit)
  ------------------
  |  Branch (109:14): [True: 609k, False: 369k]
  ------------------
  110|   609k|            b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  111|   369k|          else
  112|   369k|            b->ptr[4]=0;
  113|   979k|        }
  114|  1.12M|      }
  115|  1.35M|    }
  116|  13.1M|  }
  117|       |
  118|  13.4M|  b->endbyte+=bits/8;
  119|  13.4M|  b->ptr+=bits/8;
  120|  13.4M|  b->endbit=bits&7;
  121|  13.4M|  return;
  122|      0| err:
  123|      0|  oggpack_writeclear(b);
  124|      0|}
oggpackB_write:
  127|  13.4M|void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  128|  13.4M|  if(bits<0 || bits>32) goto err;
  ------------------
  |  Branch (128:6): [True: 0, False: 13.4M]
  |  Branch (128:16): [True: 0, False: 13.4M]
  ------------------
  129|  13.4M|  if(b->endbyte>=b->storage-4){
  ------------------
  |  Branch (129:6): [True: 17.2k, False: 13.4M]
  ------------------
  130|  17.2k|    void *ret;
  131|  17.2k|    if(!b->ptr)return;
  ------------------
  |  Branch (131:8): [True: 0, False: 17.2k]
  ------------------
  132|  17.2k|    if(b->storage>LONG_MAX-BUFFER_INCREMENT) goto err;
  ------------------
  |  |   25|  17.2k|#define BUFFER_INCREMENT 256
  ------------------
  |  Branch (132:8): [True: 0, False: 17.2k]
  ------------------
  133|  17.2k|    ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  ------------------
  |  |   23|  17.2k|#define _ogg_realloc realloc
  ------------------
                  ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  ------------------
  |  |   25|  17.2k|#define BUFFER_INCREMENT 256
  ------------------
  134|  17.2k|    if(!ret) goto err;
  ------------------
  |  Branch (134:8): [True: 0, False: 17.2k]
  ------------------
  135|  17.2k|    b->buffer=ret;
  136|  17.2k|    b->storage+=BUFFER_INCREMENT;
  ------------------
  |  |   25|  17.2k|#define BUFFER_INCREMENT 256
  ------------------
  137|  17.2k|    b->ptr=b->buffer+b->endbyte;
  138|  17.2k|  }
  139|       |
  140|  13.4M|  value=(value&mask[bits])<<(32-bits);
  141|  13.4M|  bits+=b->endbit;
  142|       |
  143|  13.4M|  b->ptr[0]|=value>>(24+b->endbit);
  144|       |
  145|  13.4M|  if(bits>=8){
  ------------------
  |  Branch (145:6): [True: 13.1M, False: 323k]
  ------------------
  146|  13.1M|    b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  147|  13.1M|    if(bits>=16){
  ------------------
  |  Branch (147:8): [True: 1.35M, False: 11.7M]
  ------------------
  148|  1.35M|      b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  149|  1.35M|      if(bits>=24){
  ------------------
  |  Branch (149:10): [True: 1.12M, False: 225k]
  ------------------
  150|  1.12M|        b->ptr[3]=(unsigned char)(value>>(b->endbit));
  151|  1.12M|        if(bits>=32){
  ------------------
  |  Branch (151:12): [True: 979k, False: 145k]
  ------------------
  152|   979k|          if(b->endbit)
  ------------------
  |  Branch (152:14): [True: 609k, False: 369k]
  ------------------
  153|   609k|            b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  154|   369k|          else
  155|   369k|            b->ptr[4]=0;
  156|   979k|        }
  157|  1.12M|      }
  158|  1.35M|    }
  159|  13.1M|  }
  160|       |
  161|  13.4M|  b->endbyte+=bits/8;
  162|  13.4M|  b->ptr+=bits/8;
  163|  13.4M|  b->endbit=bits&7;
  164|  13.4M|  return;
  165|      0| err:
  166|      0|  oggpack_writeclear(b);
  167|      0|}
oggpack_writealign:
  169|  2.43k|void oggpack_writealign(oggpack_buffer *b){
  170|  2.43k|  int bits=8-b->endbit;
  171|  2.43k|  if(bits<8)
  ------------------
  |  Branch (171:6): [True: 585, False: 1.84k]
  ------------------
  172|    585|    oggpack_write(b,0,bits);
  173|  2.43k|}
oggpackB_writealign:
  175|  2.43k|void oggpackB_writealign(oggpack_buffer *b){
  176|  2.43k|  int bits=8-b->endbit;
  177|  2.43k|  if(bits<8)
  ------------------
  |  Branch (177:6): [True: 585, False: 1.84k]
  ------------------
  178|    585|    oggpackB_write(b,0,bits);
  179|  2.43k|}
oggpack_writecopy:
  232|    741|void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  233|    741|  oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  234|    741|}
oggpackB_writecopy:
  236|    741|void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  237|    741|  oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  238|    741|}
oggpack_reset:
  240|  15.4k|void oggpack_reset(oggpack_buffer *b){
  241|  15.4k|  if(!b->ptr)return;
  ------------------
  |  Branch (241:6): [True: 0, False: 15.4k]
  ------------------
  242|  15.4k|  b->ptr=b->buffer;
  243|  15.4k|  b->buffer[0]=0;
  244|  15.4k|  b->endbit=b->endbyte=0;
  245|  15.4k|}
oggpackB_reset:
  247|  7.74k|void oggpackB_reset(oggpack_buffer *b){
  248|  7.74k|  oggpack_reset(b);
  249|  7.74k|}
oggpack_writeclear:
  251|  2.25k|void oggpack_writeclear(oggpack_buffer *b){
  252|  2.25k|  if(b->buffer)_ogg_free(b->buffer);
  ------------------
  |  |   24|  2.25k|#define _ogg_free    free
  ------------------
  |  Branch (252:6): [True: 2.25k, False: 0]
  ------------------
  253|  2.25k|  memset(b,0,sizeof(*b));
  254|  2.25k|}
oggpackB_writeclear:
  256|  1.12k|void oggpackB_writeclear(oggpack_buffer *b){
  257|  1.12k|  oggpack_writeclear(b);
  258|  1.12k|}
oggpack_readinit:
  260|  1.92k|void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  261|  1.92k|  memset(b,0,sizeof(*b));
  262|  1.92k|  b->buffer=b->ptr=buf;
  263|  1.92k|  b->storage=bytes;
  264|  1.92k|}
oggpackB_readinit:
  266|    962|void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  267|    962|  oggpack_readinit(b,buf,bytes);
  268|    962|}
oggpack_look:
  271|  9.62k|long oggpack_look(oggpack_buffer *b,int bits){
  272|  9.62k|  unsigned long ret;
  273|  9.62k|  unsigned long m;
  274|       |
  275|  9.62k|  if(bits<0 || bits>32) return -1;
  ------------------
  |  Branch (275:6): [True: 0, False: 9.62k]
  |  Branch (275:16): [True: 0, False: 9.62k]
  ------------------
  276|  9.62k|  m=mask[bits];
  277|  9.62k|  bits+=b->endbit;
  278|       |
  279|  9.62k|  if(b->endbyte >= b->storage-4){
  ------------------
  |  Branch (279:6): [True: 2.09k, False: 7.52k]
  ------------------
  280|       |    /* not the main path */
  281|  2.09k|    if(b->endbyte > b->storage-((bits+7)>>3)) return -1;
  ------------------
  |  Branch (281:8): [True: 1.62k, False: 469]
  ------------------
  282|       |    /* special case to avoid reading b->ptr[0], which might be past the end of
  283|       |        the buffer; also skips some useless accounting */
  284|    469|    else if(!bits)return(0L);
  ------------------
  |  Branch (284:13): [True: 0, False: 469]
  ------------------
  285|  2.09k|  }
  286|       |
  287|  7.99k|  ret=b->ptr[0]>>b->endbit;
  288|  7.99k|  if(bits>8){
  ------------------
  |  Branch (288:6): [True: 7.99k, False: 0]
  ------------------
  289|  7.99k|    ret|=(unsigned long)b->ptr[1]<<(8-b->endbit);
  290|  7.99k|    if(bits>16){
  ------------------
  |  Branch (290:8): [True: 746, False: 7.25k]
  ------------------
  291|    746|      ret|=(unsigned long)b->ptr[2]<<(16-b->endbit);
  292|    746|      if(bits>24){
  ------------------
  |  Branch (292:10): [True: 0, False: 746]
  ------------------
  293|      0|        ret|=(unsigned long)b->ptr[3]<<(24-b->endbit);
  294|      0|        if(bits>32 && b->endbit)
  ------------------
  |  Branch (294:12): [True: 0, False: 0]
  |  Branch (294:23): [True: 0, False: 0]
  ------------------
  295|      0|          ret|=(unsigned long)b->ptr[4]<<(32-b->endbit);
  296|      0|      }
  297|    746|    }
  298|  7.99k|  }
  299|  7.99k|  return(m&ret);
  300|  9.62k|}
oggpackB_look:
  303|  9.62k|long oggpackB_look(oggpack_buffer *b,int bits){
  304|  9.62k|  unsigned long ret;
  305|  9.62k|  int m=32-bits;
  306|       |
  307|  9.62k|  if(m<0 || m>32) return -1;
  ------------------
  |  Branch (307:6): [True: 0, False: 9.62k]
  |  Branch (307:13): [True: 0, False: 9.62k]
  ------------------
  308|  9.62k|  bits+=b->endbit;
  309|       |
  310|  9.62k|  if(b->endbyte >= b->storage-4){
  ------------------
  |  Branch (310:6): [True: 2.09k, False: 7.52k]
  ------------------
  311|       |    /* not the main path */
  312|  2.09k|    if(b->endbyte > b->storage-((bits+7)>>3)) return -1;
  ------------------
  |  Branch (312:8): [True: 1.62k, False: 469]
  ------------------
  313|       |    /* special case to avoid reading b->ptr[0], which might be past the end of
  314|       |        the buffer; also skips some useless accounting */
  315|    469|    else if(!bits)return(0L);
  ------------------
  |  Branch (315:13): [True: 0, False: 469]
  ------------------
  316|  2.09k|  }
  317|       |
  318|  7.99k|  ret=(unsigned long)b->ptr[0]<<(24+b->endbit);
  319|  7.99k|  if(bits>8){
  ------------------
  |  Branch (319:6): [True: 7.99k, False: 0]
  ------------------
  320|  7.99k|    ret|=(unsigned long)b->ptr[1]<<(16+b->endbit);
  321|  7.99k|    if(bits>16){
  ------------------
  |  Branch (321:8): [True: 746, False: 7.25k]
  ------------------
  322|    746|      ret|=(unsigned long)b->ptr[2]<<(8+b->endbit);
  323|    746|      if(bits>24){
  ------------------
  |  Branch (323:10): [True: 0, False: 746]
  ------------------
  324|      0|        ret|=(unsigned long)b->ptr[3]<<(b->endbit);
  325|      0|        if(bits>32 && b->endbit)
  ------------------
  |  Branch (325:12): [True: 0, False: 0]
  |  Branch (325:23): [True: 0, False: 0]
  ------------------
  326|      0|          ret|=b->ptr[4]>>(8-b->endbit);
  327|      0|      }
  328|    746|    }
  329|  7.99k|  }
  330|  7.99k|  return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  331|  9.62k|}
oggpack_adv:
  343|  19.2k|void oggpack_adv(oggpack_buffer *b,int bits){
  344|  19.2k|  bits+=b->endbit;
  345|       |
  346|  19.2k|  if(b->endbyte > b->storage-((bits+7)>>3)) goto overflow;
  ------------------
  |  Branch (346:6): [True: 2.79k, False: 16.4k]
  ------------------
  347|       |
  348|  16.4k|  b->ptr+=bits/8;
  349|  16.4k|  b->endbyte+=bits/8;
  350|  16.4k|  b->endbit=bits&7;
  351|  16.4k|  return;
  352|       |
  353|  2.79k| overflow:
  354|       |  b->ptr=NULL;
  355|  2.79k|  b->endbyte=b->storage;
  356|  2.79k|  b->endbit=1;
  357|  2.79k|}
oggpackB_adv:
  359|  9.62k|void oggpackB_adv(oggpack_buffer *b,int bits){
  360|  9.62k|  oggpack_adv(b,bits);
  361|  9.62k|}
oggpack_read:
  376|  9.62k|long oggpack_read(oggpack_buffer *b,int bits){
  377|  9.62k|  long ret;
  378|  9.62k|  unsigned long m;
  379|       |
  380|  9.62k|  if(bits<0 || bits>32) goto err;
  ------------------
  |  Branch (380:6): [True: 0, False: 9.62k]
  |  Branch (380:16): [True: 0, False: 9.62k]
  ------------------
  381|  9.62k|  m=mask[bits];
  382|  9.62k|  bits+=b->endbit;
  383|       |
  384|  9.62k|  if(b->endbyte >= b->storage-4){
  ------------------
  |  Branch (384:6): [True: 2.10k, False: 7.51k]
  ------------------
  385|       |    /* not the main path */
  386|  2.10k|    if(b->endbyte > b->storage-((bits+7)>>3)) goto overflow;
  ------------------
  |  Branch (386:8): [True: 1.61k, False: 487]
  ------------------
  387|       |    /* special case to avoid reading b->ptr[0], which might be past the end of
  388|       |        the buffer; also skips some useless accounting */
  389|    487|    else if(!bits)return(0L);
  ------------------
  |  Branch (389:13): [True: 0, False: 487]
  ------------------
  390|  2.10k|  }
  391|       |
  392|  8.00k|  ret=b->ptr[0]>>b->endbit;
  393|  8.00k|  if(bits>8){
  ------------------
  |  Branch (393:6): [True: 7.25k, False: 754]
  ------------------
  394|  7.25k|    ret|=(unsigned long)b->ptr[1]<<(8-b->endbit);
  395|  7.25k|    if(bits>16){
  ------------------
  |  Branch (395:8): [True: 0, False: 7.25k]
  ------------------
  396|      0|      ret|=(unsigned long)b->ptr[2]<<(16-b->endbit);
  397|      0|      if(bits>24){
  ------------------
  |  Branch (397:10): [True: 0, False: 0]
  ------------------
  398|      0|        ret|=(unsigned long)b->ptr[3]<<(24-b->endbit);
  399|      0|        if(bits>32 && b->endbit){
  ------------------
  |  Branch (399:12): [True: 0, False: 0]
  |  Branch (399:23): [True: 0, False: 0]
  ------------------
  400|      0|          ret|=(unsigned long)b->ptr[4]<<(32-b->endbit);
  401|      0|        }
  402|      0|      }
  403|      0|    }
  404|  7.25k|  }
  405|  8.00k|  ret&=m;
  406|  8.00k|  b->ptr+=bits/8;
  407|  8.00k|  b->endbyte+=bits/8;
  408|  8.00k|  b->endbit=bits&7;
  409|  8.00k|  return ret;
  410|       |
  411|  1.61k| overflow:
  412|  1.61k| err:
  413|       |  b->ptr=NULL;
  414|  1.61k|  b->endbyte=b->storage;
  415|  1.61k|  b->endbit=1;
  416|  1.61k|  return -1L;
  417|  1.61k|}
oggpackB_read:
  420|  9.62k|long oggpackB_read(oggpack_buffer *b,int bits){
  421|  9.62k|  long ret;
  422|  9.62k|  long m=32-bits;
  423|       |
  424|  9.62k|  if(m<0 || m>32) goto err;
  ------------------
  |  Branch (424:6): [True: 0, False: 9.62k]
  |  Branch (424:13): [True: 0, False: 9.62k]
  ------------------
  425|  9.62k|  bits+=b->endbit;
  426|       |
  427|  9.62k|  if(b->endbyte+4>=b->storage){
  ------------------
  |  Branch (427:6): [True: 2.10k, False: 7.51k]
  ------------------
  428|       |    /* not the main path */
  429|  2.10k|    if(b->endbyte > b->storage-((bits+7)>>3)) goto overflow;
  ------------------
  |  Branch (429:8): [True: 1.61k, False: 487]
  ------------------
  430|       |    /* special case to avoid reading b->ptr[0], which might be past the end of
  431|       |        the buffer; also skips some useless accounting */
  432|    487|    else if(!bits)return(0L);
  ------------------
  |  Branch (432:13): [True: 0, False: 487]
  ------------------
  433|  2.10k|  }
  434|       |
  435|  8.00k|  ret=(unsigned long)b->ptr[0]<<(24+b->endbit);
  436|  8.00k|  if(bits>8){
  ------------------
  |  Branch (436:6): [True: 7.25k, False: 754]
  ------------------
  437|  7.25k|    ret|=(unsigned long)b->ptr[1]<<(16+b->endbit);
  438|  7.25k|    if(bits>16){
  ------------------
  |  Branch (438:8): [True: 0, False: 7.25k]
  ------------------
  439|      0|      ret|=(unsigned long)b->ptr[2]<<(8+b->endbit);
  440|      0|      if(bits>24){
  ------------------
  |  Branch (440:10): [True: 0, False: 0]
  ------------------
  441|      0|        ret|=(unsigned long)b->ptr[3]<<(b->endbit);
  442|      0|        if(bits>32 && b->endbit)
  ------------------
  |  Branch (442:12): [True: 0, False: 0]
  |  Branch (442:23): [True: 0, False: 0]
  ------------------
  443|      0|          ret|=b->ptr[4]>>(8-b->endbit);
  444|      0|      }
  445|      0|    }
  446|  7.25k|  }
  447|  8.00k|  ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  448|       |
  449|  8.00k|  b->ptr+=bits/8;
  450|  8.00k|  b->endbyte+=bits/8;
  451|  8.00k|  b->endbit=bits&7;
  452|  8.00k|  return ret;
  453|       |
  454|  1.61k| overflow:
  455|  1.61k| err:
  456|       |  b->ptr=NULL;
  457|  1.61k|  b->endbyte=b->storage;
  458|  1.61k|  b->endbit=1;
  459|  1.61k|  return -1L;
  460|  1.61k|}
oggpack_bytes:
  504|  2.25k|long oggpack_bytes(oggpack_buffer *b){
  505|  2.25k|  return(b->endbyte+(b->endbit+7)/8);
  506|  2.25k|}
oggpackB_bytes:
  512|  1.12k|long oggpackB_bytes(oggpack_buffer *b){
  513|  1.12k|  return oggpack_bytes(b);
  514|  1.12k|}
oggpack_get_buffer:
  520|  2.25k|unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  521|  2.25k|  return(b->buffer);
  522|  2.25k|}
oggpackB_get_buffer:
  524|  1.12k|unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  525|  1.12k|  return oggpack_get_buffer(b);
  526|  1.12k|}
bitwise.c:oggpack_writecopy_helper:
  187|  1.48k|                                     int msb){
  188|  1.48k|  unsigned char *ptr=(unsigned char *)source;
  189|       |
  190|  1.48k|  long bytes=bits/8;
  191|  1.48k|  long pbytes=(b->endbit+bits)/8;
  192|  1.48k|  bits-=bytes*8;
  193|       |
  194|       |  /* expand storage up-front */
  195|  1.48k|  if(b->endbyte+pbytes>=b->storage){
  ------------------
  |  Branch (195:6): [True: 888, False: 594]
  ------------------
  196|    888|    void *ret;
  197|    888|    if(!b->ptr) goto err;
  ------------------
  |  Branch (197:8): [True: 0, False: 888]
  ------------------
  198|    888|    if(b->storage>b->endbyte+pbytes+BUFFER_INCREMENT) goto err;
  ------------------
  |  |   25|    888|#define BUFFER_INCREMENT 256
  ------------------
  |  Branch (198:8): [True: 0, False: 888]
  ------------------
  199|    888|    b->storage=b->endbyte+pbytes+BUFFER_INCREMENT;
  ------------------
  |  |   25|    888|#define BUFFER_INCREMENT 256
  ------------------
  200|    888|    ret=_ogg_realloc(b->buffer,b->storage);
  ------------------
  |  |   23|    888|#define _ogg_realloc realloc
  ------------------
  201|    888|    if(!ret) goto err;
  ------------------
  |  Branch (201:8): [True: 0, False: 888]
  ------------------
  202|    888|    b->buffer=ret;
  203|    888|    b->ptr=b->buffer+b->endbyte;
  204|    888|  }
  205|       |
  206|       |  /* copy whole octets */
  207|  1.48k|  if(b->endbit){
  ------------------
  |  Branch (207:6): [True: 346, False: 1.13k]
  ------------------
  208|    346|    int i;
  209|       |    /* unaligned copy.  Do it the hard way. */
  210|  23.1M|    for(i=0;i<bytes;i++)
  ------------------
  |  Branch (210:13): [True: 23.1M, False: 346]
  ------------------
  211|  23.1M|      w(b,(unsigned long)(ptr[i]),8);
  212|  1.13k|  }else{
  213|       |    /* aligned block copy */
  214|  1.13k|    memmove(b->ptr,source,bytes);
  215|  1.13k|    b->ptr+=bytes;
  216|  1.13k|    b->endbyte+=bytes;
  217|  1.13k|    *b->ptr=0;
  218|  1.13k|  }
  219|       |
  220|       |  /* copy trailing bits */
  221|  1.48k|  if(bits){
  ------------------
  |  Branch (221:6): [True: 0, False: 1.48k]
  ------------------
  222|      0|    if(msb)
  ------------------
  |  Branch (222:8): [True: 0, False: 0]
  ------------------
  223|      0|      w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  224|      0|    else
  225|      0|      w(b,(unsigned long)(ptr[bytes]),bits);
  226|      0|  }
  227|  1.48k|  return;
  228|      0| err:
  229|      0|  oggpack_writeclear(b);
  230|      0|}

ogg_page_version:
   33|  5.85k|int ogg_page_version(const ogg_page *og){
   34|  5.85k|  return((int)(og->header[4]));
   35|  5.85k|}
ogg_page_continued:
   37|  5.85k|int ogg_page_continued(const ogg_page *og){
   38|  5.85k|  return((int)(og->header[5]&0x01));
   39|  5.85k|}
ogg_page_bos:
   41|  5.85k|int ogg_page_bos(const ogg_page *og){
   42|  5.85k|  return((int)(og->header[5]&0x02));
   43|  5.85k|}
ogg_page_eos:
   45|  5.85k|int ogg_page_eos(const ogg_page *og){
   46|  5.85k|  return((int)(og->header[5]&0x04));
   47|  5.85k|}
ogg_page_granulepos:
   49|  5.85k|ogg_int64_t ogg_page_granulepos(const ogg_page *og){
   50|  5.85k|  unsigned char *page=og->header;
   51|  5.85k|  ogg_uint64_t granulepos=page[13]&(0xff);
   52|  5.85k|  granulepos= (granulepos<<8)|(page[12]&0xff);
   53|  5.85k|  granulepos= (granulepos<<8)|(page[11]&0xff);
   54|  5.85k|  granulepos= (granulepos<<8)|(page[10]&0xff);
   55|  5.85k|  granulepos= (granulepos<<8)|(page[9]&0xff);
   56|  5.85k|  granulepos= (granulepos<<8)|(page[8]&0xff);
   57|  5.85k|  granulepos= (granulepos<<8)|(page[7]&0xff);
   58|  5.85k|  granulepos= (granulepos<<8)|(page[6]&0xff);
   59|  5.85k|  return((ogg_int64_t)granulepos);
   60|  5.85k|}
ogg_page_serialno:
   62|  5.85k|int ogg_page_serialno(const ogg_page *og){
   63|  5.85k|  return((int)((ogg_uint32_t)og->header[14]) |
   64|  5.85k|              ((ogg_uint32_t)og->header[15]<<8) |
   65|  5.85k|              ((ogg_uint32_t)og->header[16]<<16) |
   66|  5.85k|              ((ogg_uint32_t)og->header[17]<<24));
   67|  5.85k|}
ogg_page_pageno:
   69|  5.85k|long ogg_page_pageno(const ogg_page *og){
   70|  5.85k|  return((long)((ogg_uint32_t)og->header[18]) |
   71|  5.85k|               ((ogg_uint32_t)og->header[19]<<8) |
   72|  5.85k|               ((ogg_uint32_t)og->header[20]<<16) |
   73|  5.85k|               ((ogg_uint32_t)og->header[21]<<24));
   74|  5.85k|}
ogg_stream_init:
  133|  1.12k|int ogg_stream_init(ogg_stream_state *os,int serialno){
  134|  1.12k|  if(os){
  ------------------
  |  Branch (134:6): [True: 1.12k, False: 0]
  ------------------
  135|  1.12k|    memset(os,0,sizeof(*os));
  136|  1.12k|    os->body_storage=16*1024;
  137|  1.12k|    os->lacing_storage=1024;
  138|       |
  139|  1.12k|    os->body_data=_ogg_malloc(os->body_storage*sizeof(*os->body_data));
  ------------------
  |  |   21|  1.12k|#define _ogg_malloc  malloc
  ------------------
  140|  1.12k|    os->lacing_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  ------------------
  |  |   21|  1.12k|#define _ogg_malloc  malloc
  ------------------
  141|  1.12k|    os->granule_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  ------------------
  |  |   21|  1.12k|#define _ogg_malloc  malloc
  ------------------
  142|       |
  143|  1.12k|    if(!os->body_data || !os->lacing_vals || !os->granule_vals){
  ------------------
  |  Branch (143:8): [True: 0, False: 1.12k]
  |  Branch (143:26): [True: 0, False: 1.12k]
  |  Branch (143:46): [True: 0, False: 1.12k]
  ------------------
  144|      0|      ogg_stream_clear(os);
  145|      0|      return -1;
  146|      0|    }
  147|       |
  148|  1.12k|    os->serialno=serialno;
  149|       |
  150|  1.12k|    return(0);
  151|  1.12k|  }
  152|      0|  return(-1);
  153|  1.12k|}
ogg_stream_check:
  156|  20.8k|int ogg_stream_check(ogg_stream_state *os){
  157|  20.8k|  if(!os || !os->body_data) return -1;
  ------------------
  |  Branch (157:6): [True: 0, False: 20.8k]
  |  Branch (157:13): [True: 0, False: 20.8k]
  ------------------
  158|  20.8k|  return 0;
  159|  20.8k|}
ogg_stream_clear:
  162|  1.12k|int ogg_stream_clear(ogg_stream_state *os){
  163|  1.12k|  if(os){
  ------------------
  |  Branch (163:6): [True: 1.12k, False: 0]
  ------------------
  164|  1.12k|    if(os->body_data)_ogg_free(os->body_data);
  ------------------
  |  |   24|  1.12k|#define _ogg_free    free
  ------------------
  |  Branch (164:8): [True: 1.12k, False: 0]
  ------------------
  165|  1.12k|    if(os->lacing_vals)_ogg_free(os->lacing_vals);
  ------------------
  |  |   24|  1.12k|#define _ogg_free    free
  ------------------
  |  Branch (165:8): [True: 1.12k, False: 0]
  ------------------
  166|  1.12k|    if(os->granule_vals)_ogg_free(os->granule_vals);
  ------------------
  |  |   24|  1.12k|#define _ogg_free    free
  ------------------
  |  Branch (166:8): [True: 1.12k, False: 0]
  ------------------
  167|       |
  168|  1.12k|    memset(os,0,sizeof(*os));
  169|  1.12k|  }
  170|  1.12k|  return(0);
  171|  1.12k|}
ogg_page_checksum_set:
  255|  5.85k|void ogg_page_checksum_set(ogg_page *og){
  256|  5.85k|  if(og){
  ------------------
  |  Branch (256:6): [True: 5.85k, False: 0]
  ------------------
  257|  5.85k|    ogg_uint32_t crc_reg=0;
  258|       |
  259|       |    /* safety; needed for API behavior, but not framing code */
  260|  5.85k|    og->header[22]=0;
  261|  5.85k|    og->header[23]=0;
  262|  5.85k|    og->header[24]=0;
  263|  5.85k|    og->header[25]=0;
  264|       |
  265|  5.85k|    crc_reg=_os_update_crc(crc_reg,og->header,og->header_len);
  266|  5.85k|    crc_reg=_os_update_crc(crc_reg,og->body,og->body_len);
  267|       |
  268|  5.85k|    og->header[22]=(unsigned char)(crc_reg&0xff);
  269|  5.85k|    og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  270|  5.85k|    og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  271|  5.85k|    og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  272|  5.85k|  }
  273|  5.85k|}
ogg_sync_init:
  558|  1.12k|int ogg_sync_init(ogg_sync_state *oy){
  559|  1.12k|  if(oy){
  ------------------
  |  Branch (559:6): [True: 1.12k, False: 0]
  ------------------
  560|  1.12k|    oy->storage = -1; /* used as a readiness flag */
  561|  1.12k|    memset(oy,0,sizeof(*oy));
  562|  1.12k|  }
  563|  1.12k|  return(0);
  564|  1.12k|}
ogg_sync_clear:
  567|  1.12k|int ogg_sync_clear(ogg_sync_state *oy){
  568|  1.12k|  if(oy){
  ------------------
  |  Branch (568:6): [True: 1.12k, False: 0]
  ------------------
  569|  1.12k|    if(oy->data)_ogg_free(oy->data);
  ------------------
  |  |   24|  1.12k|#define _ogg_free    free
  ------------------
  |  Branch (569:8): [True: 1.12k, False: 0]
  ------------------
  570|  1.12k|    memset(oy,0,sizeof(*oy));
  571|  1.12k|  }
  572|  1.12k|  return(0);
  573|  1.12k|}
ogg_sync_check:
  583|  16.2k|int ogg_sync_check(ogg_sync_state *oy){
  584|  16.2k|  if(oy->storage<0) return -1;
  ------------------
  |  Branch (584:6): [True: 0, False: 16.2k]
  ------------------
  585|  16.2k|  return 0;
  586|  16.2k|}
ogg_sync_buffer:
  588|  1.12k|char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  589|  1.12k|  if(ogg_sync_check(oy)) return NULL;
  ------------------
  |  Branch (589:6): [True: 0, False: 1.12k]
  ------------------
  590|       |
  591|       |  /* first, clear out any space that has been previously returned */
  592|  1.12k|  if(oy->returned){
  ------------------
  |  Branch (592:6): [True: 0, False: 1.12k]
  ------------------
  593|      0|    oy->fill-=oy->returned;
  594|      0|    if(oy->fill>0)
  ------------------
  |  Branch (594:8): [True: 0, False: 0]
  ------------------
  595|      0|      memmove(oy->data,oy->data+oy->returned,oy->fill);
  596|      0|    oy->returned=0;
  597|      0|  }
  598|       |
  599|  1.12k|  if(size>oy->storage-oy->fill){
  ------------------
  |  Branch (599:6): [True: 1.12k, False: 0]
  ------------------
  600|       |    /* We need to extend the internal buffer */
  601|  1.12k|    long newsize;
  602|  1.12k|    void *ret;
  603|       |
  604|  1.12k|    if(size>INT_MAX-4096-oy->fill){
  ------------------
  |  Branch (604:8): [True: 0, False: 1.12k]
  ------------------
  605|      0|      ogg_sync_clear(oy);
  606|      0|      return NULL;
  607|      0|    }
  608|  1.12k|    newsize=size+oy->fill+4096; /* an extra page to be nice */
  609|  1.12k|    if(oy->data)
  ------------------
  |  Branch (609:8): [True: 0, False: 1.12k]
  ------------------
  610|      0|      ret=_ogg_realloc(oy->data,newsize);
  ------------------
  |  |   23|      0|#define _ogg_realloc realloc
  ------------------
  611|  1.12k|    else
  612|  1.12k|      ret=_ogg_malloc(newsize);
  ------------------
  |  |   21|  1.12k|#define _ogg_malloc  malloc
  ------------------
  613|  1.12k|    if(!ret){
  ------------------
  |  Branch (613:8): [True: 0, False: 1.12k]
  ------------------
  614|      0|      ogg_sync_clear(oy);
  615|      0|      return NULL;
  616|      0|    }
  617|  1.12k|    oy->data=ret;
  618|  1.12k|    oy->storage=newsize;
  619|  1.12k|  }
  620|       |
  621|       |  /* expose a segment at least as large as requested at the fill mark */
  622|  1.12k|  return((char *)oy->data+oy->fill);
  623|  1.12k|}
ogg_sync_wrote:
  625|  1.12k|int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  626|  1.12k|  if(ogg_sync_check(oy))return -1;
  ------------------
  |  Branch (626:6): [True: 0, False: 1.12k]
  ------------------
  627|  1.12k|  if(oy->fill+bytes>oy->storage)return -1;
  ------------------
  |  Branch (627:6): [True: 0, False: 1.12k]
  ------------------
  628|  1.12k|  oy->fill+=bytes;
  629|  1.12k|  return(0);
  630|  1.12k|}
ogg_sync_pageseek:
  642|  6.98k|long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  643|  6.98k|  unsigned char *page;
  644|  6.98k|  unsigned char *next;
  645|  6.98k|  long bytes;
  646|       |
  647|  6.98k|  if(ogg_sync_check(oy))return 0;
  ------------------
  |  Branch (647:6): [True: 0, False: 6.98k]
  ------------------
  648|       |
  649|  6.98k|  page=oy->data+oy->returned;
  650|  6.98k|  bytes=oy->fill-oy->returned;
  651|       |
  652|  6.98k|  if(oy->headerbytes==0){
  ------------------
  |  Branch (652:6): [True: 6.98k, False: 0]
  ------------------
  653|  6.98k|    int headerbytes,i;
  654|  6.98k|    if(bytes<27)return(0); /* not enough for a header */
  ------------------
  |  Branch (654:8): [True: 730, False: 6.25k]
  ------------------
  655|       |
  656|       |    /* verify capture pattern */
  657|  6.25k|    if(memcmp(page,"OggS",4))goto sync_fail;
  ------------------
  |  Branch (657:8): [True: 341, False: 5.91k]
  ------------------
  658|       |
  659|  5.91k|    headerbytes=page[26]+27;
  660|  5.91k|    if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  ------------------
  |  Branch (660:8): [True: 14, False: 5.90k]
  ------------------
  661|       |
  662|       |    /* count up body length in the segment table */
  663|       |
  664|  35.9k|    for(i=0;i<page[26];i++)
  ------------------
  |  Branch (664:13): [True: 30.0k, False: 5.90k]
  ------------------
  665|  30.0k|      oy->bodybytes+=page[27+i];
  666|  5.90k|    oy->headerbytes=headerbytes;
  667|  5.90k|  }
  668|       |
  669|  5.90k|  if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  ------------------
  |  Branch (669:6): [True: 43, False: 5.85k]
  ------------------
  670|       |
  671|       |  /* The whole test page is buffered.  Verify the checksum */
  672|  5.85k|  {
  673|       |    /* Grab the checksum bytes, set the header field to zero */
  674|  5.85k|    char chksum[4];
  675|  5.85k|    ogg_page log;
  676|       |
  677|  5.85k|    memcpy(chksum,page+22,4);
  678|  5.85k|    memset(page+22,0,4);
  679|       |
  680|       |    /* set up a temp page struct and recompute the checksum */
  681|  5.85k|    log.header=page;
  682|  5.85k|    log.header_len=oy->headerbytes;
  683|  5.85k|    log.body=page+oy->headerbytes;
  684|  5.85k|    log.body_len=oy->bodybytes;
  685|  5.85k|    ogg_page_checksum_set(&log);
  686|       |
  687|       |    /* Compare */
  688|  5.85k|    if(memcmp(chksum,page+22,4)){
  ------------------
  |  Branch (688:8): [True: 5.42k, False: 437]
  ------------------
  689|       |      /* D'oh.  Mismatch! Corrupt page (or miscapture and not a page
  690|       |         at all) */
  691|       |      /* replace the computed checksum with the one actually read in */
  692|  5.42k|      memcpy(page+22,chksum,4);
  693|       |
  694|       |#ifndef DISABLE_CRC
  695|       |      /* Bad checksum. Lose sync */
  696|       |      goto sync_fail;
  697|       |#endif
  698|  5.42k|    }
  699|  5.85k|  }
  700|       |
  701|       |  /* yes, have a whole page all ready to go */
  702|  5.85k|  {
  703|  5.85k|    if(og){
  ------------------
  |  Branch (703:8): [True: 5.85k, False: 0]
  ------------------
  704|  5.85k|      og->header=page;
  705|  5.85k|      og->header_len=oy->headerbytes;
  706|  5.85k|      og->body=page+oy->headerbytes;
  707|  5.85k|      og->body_len=oy->bodybytes;
  708|  5.85k|    }
  709|       |
  710|  5.85k|    oy->unsynced=0;
  711|  5.85k|    oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  712|  5.85k|    oy->headerbytes=0;
  713|  5.85k|    oy->bodybytes=0;
  714|  5.85k|    return(bytes);
  715|  5.90k|  }
  716|       |
  717|    341| sync_fail:
  718|       |
  719|    341|  oy->headerbytes=0;
  720|    341|  oy->bodybytes=0;
  721|       |
  722|       |  /* search for possible capture */
  723|    341|  next=memchr(page+1,'O',bytes-1);
  724|    341|  if(!next)
  ------------------
  |  Branch (724:6): [True: 175, False: 166]
  ------------------
  725|    175|    next=oy->data+oy->fill;
  726|       |
  727|    341|  oy->returned=(int)(next-oy->data);
  728|    341|  return((long)-(next-page));
  729|  5.90k|}
ogg_sync_pageout:
  742|  6.98k|int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  743|       |
  744|  6.98k|  if(ogg_sync_check(oy))return 0;
  ------------------
  |  Branch (744:6): [True: 0, False: 6.98k]
  ------------------
  745|       |
  746|       |  /* all we need to do is verify a page at the head of the stream
  747|       |     buffer.  If it doesn't verify, we look for the next potential
  748|       |     frame */
  749|       |
  750|  6.98k|  for(;;){
  751|  6.98k|    long ret=ogg_sync_pageseek(oy,og);
  752|  6.98k|    if(ret>0){
  ------------------
  |  Branch (752:8): [True: 5.85k, False: 1.12k]
  ------------------
  753|       |      /* have a page */
  754|  5.85k|      return(1);
  755|  5.85k|    }
  756|  1.12k|    if(ret==0){
  ------------------
  |  Branch (756:8): [True: 787, False: 341]
  ------------------
  757|       |      /* need more data */
  758|    787|      return(0);
  759|    787|    }
  760|       |
  761|       |    /* head did not start a synced page... skipped some bytes */
  762|    341|    if(!oy->unsynced){
  ------------------
  |  Branch (762:8): [True: 341, False: 0]
  ------------------
  763|    341|      oy->unsynced=1;
  764|    341|      return(-1);
  765|    341|    }
  766|       |
  767|       |    /* loop. keep looking */
  768|       |
  769|    341|  }
  770|  6.98k|}
ogg_stream_pagein:
  775|  5.85k|int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  776|  5.85k|  unsigned char *header=og->header;
  777|  5.85k|  unsigned char *body=og->body;
  778|  5.85k|  long           bodysize=og->body_len;
  779|  5.85k|  int            segptr=0;
  780|       |
  781|  5.85k|  int version=ogg_page_version(og);
  782|  5.85k|  int continued=ogg_page_continued(og);
  783|  5.85k|  int bos=ogg_page_bos(og);
  784|  5.85k|  int eos=ogg_page_eos(og);
  785|  5.85k|  ogg_int64_t granulepos=ogg_page_granulepos(og);
  786|  5.85k|  int serialno=ogg_page_serialno(og);
  787|  5.85k|  long pageno=ogg_page_pageno(og);
  788|  5.85k|  int segments=header[26];
  789|       |
  790|  5.85k|  if(ogg_stream_check(os)) return -1;
  ------------------
  |  Branch (790:6): [True: 0, False: 5.85k]
  ------------------
  791|       |
  792|       |  /* clean up 'returned data' */
  793|  5.85k|  {
  794|  5.85k|    long lr=os->lacing_returned;
  795|  5.85k|    long br=os->body_returned;
  796|       |
  797|       |    /* body data */
  798|  5.85k|    if(br){
  ------------------
  |  Branch (798:8): [True: 1.00k, False: 4.84k]
  ------------------
  799|  1.00k|      os->body_fill-=br;
  800|  1.00k|      if(os->body_fill)
  ------------------
  |  Branch (800:10): [True: 631, False: 378]
  ------------------
  801|    631|        memmove(os->body_data,os->body_data+br,os->body_fill);
  802|  1.00k|      os->body_returned=0;
  803|  1.00k|    }
  804|       |
  805|  5.85k|    if(lr){
  ------------------
  |  Branch (805:8): [True: 3.60k, False: 2.25k]
  ------------------
  806|       |      /* segment table */
  807|  3.60k|      if(os->lacing_fill-lr){
  ------------------
  |  Branch (807:10): [True: 1.61k, False: 1.99k]
  ------------------
  808|  1.61k|        memmove(os->lacing_vals,os->lacing_vals+lr,
  809|  1.61k|                (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  810|  1.61k|        memmove(os->granule_vals,os->granule_vals+lr,
  811|  1.61k|                (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  812|  1.61k|      }
  813|  3.60k|      os->lacing_fill-=lr;
  814|  3.60k|      os->lacing_packet-=lr;
  815|  3.60k|      os->lacing_returned=0;
  816|  3.60k|    }
  817|  5.85k|  }
  818|       |
  819|       |  /* check the serial number */
  820|  5.85k|  if(serialno!=os->serialno)return(-1);
  ------------------
  |  Branch (820:6): [True: 803, False: 5.05k]
  ------------------
  821|  5.05k|  if(version>0)return(-1);
  ------------------
  |  Branch (821:6): [True: 225, False: 4.83k]
  ------------------
  822|       |
  823|  4.83k|  if(_os_lacing_expand(os,segments+1)) return -1;
  ------------------
  |  Branch (823:6): [True: 0, False: 4.83k]
  ------------------
  824|       |
  825|       |  /* are we in sequence? */
  826|  4.83k|  if(pageno!=os->pageno){
  ------------------
  |  Branch (826:6): [True: 3.54k, False: 1.28k]
  ------------------
  827|  3.54k|    int i;
  828|       |
  829|       |    /* unroll previous partial packet (if any) */
  830|  4.43k|    for(i=os->lacing_packet;i<os->lacing_fill;i++)
  ------------------
  |  Branch (830:29): [True: 890, False: 3.54k]
  ------------------
  831|    890|      os->body_fill-=os->lacing_vals[i]&0xff;
  832|  3.54k|    os->lacing_fill=os->lacing_packet;
  833|       |
  834|       |    /* make a note of dropped data in segment table */
  835|  3.54k|    if(os->pageno!=-1){
  ------------------
  |  Branch (835:8): [True: 3.54k, False: 0]
  ------------------
  836|  3.54k|      os->lacing_vals[os->lacing_fill++]=0x400;
  837|  3.54k|      os->lacing_packet++;
  838|  3.54k|    }
  839|  3.54k|  }
  840|       |
  841|       |  /* are we a 'continued packet' page?  If so, we may need to skip
  842|       |     some segments */
  843|  4.83k|  if(continued){
  ------------------
  |  Branch (843:6): [True: 2.65k, False: 2.17k]
  ------------------
  844|  2.65k|    if(os->lacing_fill<1 ||
  ------------------
  |  Branch (844:8): [True: 668, False: 1.98k]
  ------------------
  845|  1.98k|       (os->lacing_vals[os->lacing_fill-1]&0xff)<255 ||
  ------------------
  |  Branch (845:8): [True: 1.77k, False: 209]
  ------------------
  846|  2.44k|       os->lacing_vals[os->lacing_fill-1]==0x400){
  ------------------
  |  Branch (846:8): [True: 0, False: 209]
  ------------------
  847|  2.44k|      bos=0;
  848|  3.01k|      for(;segptr<segments;segptr++){
  ------------------
  |  Branch (848:12): [True: 1.38k, False: 1.63k]
  ------------------
  849|  1.38k|        int val=header[27+segptr];
  850|  1.38k|        body+=val;
  851|  1.38k|        bodysize-=val;
  852|  1.38k|        if(val<255){
  ------------------
  |  Branch (852:12): [True: 813, False: 574]
  ------------------
  853|    813|          segptr++;
  854|    813|          break;
  855|    813|        }
  856|  1.38k|      }
  857|  2.44k|    }
  858|  2.65k|  }
  859|       |
  860|  4.83k|  if(bodysize){
  ------------------
  |  Branch (860:6): [True: 1.60k, False: 3.23k]
  ------------------
  861|  1.60k|    if(_os_body_expand(os,bodysize)) return -1;
  ------------------
  |  Branch (861:8): [True: 0, False: 1.60k]
  ------------------
  862|  1.60k|    memcpy(os->body_data+os->body_fill,body,bodysize);
  863|  1.60k|    os->body_fill+=bodysize;
  864|  1.60k|  }
  865|       |
  866|  4.83k|  {
  867|  4.83k|    int saved=-1;
  868|  26.5k|    while(segptr<segments){
  ------------------
  |  Branch (868:11): [True: 21.7k, False: 4.83k]
  ------------------
  869|  21.7k|      int val=header[27+segptr];
  870|  21.7k|      os->lacing_vals[os->lacing_fill]=val;
  871|  21.7k|      os->granule_vals[os->lacing_fill]=-1;
  872|       |
  873|  21.7k|      if(bos){
  ------------------
  |  Branch (873:10): [True: 1.05k, False: 20.6k]
  ------------------
  874|  1.05k|        os->lacing_vals[os->lacing_fill]|=0x100;
  875|  1.05k|        bos=0;
  876|  1.05k|      }
  877|       |
  878|  21.7k|      if(val<255)saved=os->lacing_fill;
  ------------------
  |  Branch (878:10): [True: 15.6k, False: 6.07k]
  ------------------
  879|       |
  880|  21.7k|      os->lacing_fill++;
  881|  21.7k|      segptr++;
  882|       |
  883|  21.7k|      if(val<255)os->lacing_packet=os->lacing_fill;
  ------------------
  |  Branch (883:10): [True: 15.6k, False: 6.07k]
  ------------------
  884|  21.7k|    }
  885|       |
  886|       |    /* set the granulepos on the last granuleval of the last full packet */
  887|  4.83k|    if(saved!=-1){
  ------------------
  |  Branch (887:8): [True: 2.09k, False: 2.73k]
  ------------------
  888|  2.09k|      os->granule_vals[saved]=granulepos;
  889|  2.09k|    }
  890|       |
  891|  4.83k|  }
  892|       |
  893|  4.83k|  if(eos){
  ------------------
  |  Branch (893:6): [True: 3.16k, False: 1.66k]
  ------------------
  894|  3.16k|    os->e_o_s=1;
  895|  3.16k|    if(os->lacing_fill>0)
  ------------------
  |  Branch (895:8): [True: 2.65k, False: 507]
  ------------------
  896|  2.65k|      os->lacing_vals[os->lacing_fill-1]|=0x200;
  897|  3.16k|  }
  898|       |
  899|  4.83k|  os->pageno=pageno+1;
  900|       |
  901|  4.83k|  return(0);
  902|  4.83k|}
ogg_stream_packetout:
  998|  15.0k|int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  999|  15.0k|  if(ogg_stream_check(os)) return 0;
  ------------------
  |  Branch (999:6): [True: 0, False: 15.0k]
  ------------------
 1000|  15.0k|  return _packetout(os,op,1);
 1001|  15.0k|}
framing.c:_os_update_crc:
  237|  11.7k|static ogg_uint32_t _os_update_crc(ogg_uint32_t crc, unsigned char *buffer, int size){
  238|   352k|  while (size>=8){
  ------------------
  |  Branch (238:10): [True: 340k, False: 11.7k]
  ------------------
  239|   340k|    crc^=((ogg_uint32_t)buffer[0]<<24)|((ogg_uint32_t)buffer[1]<<16)|((ogg_uint32_t)buffer[2]<<8)|((ogg_uint32_t)buffer[3]);
  240|       |
  241|   340k|    crc=crc_lookup[7][ crc>>24      ]^crc_lookup[6][(crc>>16)&0xFF]^
  242|   340k|        crc_lookup[5][(crc>> 8)&0xFF]^crc_lookup[4][ crc     &0xFF]^
  243|   340k|        crc_lookup[3][buffer[4]     ]^crc_lookup[2][buffer[5]     ]^
  244|   340k|        crc_lookup[1][buffer[6]     ]^crc_lookup[0][buffer[7]     ];
  245|       |
  246|   340k|    buffer+=8;
  247|   340k|    size-=8;
  248|   340k|  }
  249|       |
  250|  39.7k|  while (size--)
  ------------------
  |  Branch (250:10): [True: 28.0k, False: 11.7k]
  ------------------
  251|  28.0k|    crc=(crc<<8)^crc_lookup[0][((crc >> 24)&0xff)^*buffer++];
  252|  11.7k|  return crc;
  253|  11.7k|}
framing.c:_os_body_expand:
  184|  1.60k|static int _os_body_expand(ogg_stream_state *os,long needed){
  185|  1.60k|  if(os->body_storage-needed<=os->body_fill){
  ------------------
  |  Branch (185:6): [True: 62, False: 1.53k]
  ------------------
  186|     62|    long body_storage;
  187|     62|    void *ret;
  188|     62|    if(os->body_storage>LONG_MAX-needed){
  ------------------
  |  Branch (188:8): [True: 0, False: 62]
  ------------------
  189|      0|      ogg_stream_clear(os);
  190|      0|      return -1;
  191|      0|    }
  192|     62|    body_storage=os->body_storage+needed;
  193|     62|    if(body_storage<LONG_MAX-1024)body_storage+=1024;
  ------------------
  |  Branch (193:8): [True: 62, False: 0]
  ------------------
  194|     62|    ret=_ogg_realloc(os->body_data,body_storage*sizeof(*os->body_data));
  ------------------
  |  |   23|     62|#define _ogg_realloc realloc
  ------------------
  195|     62|    if(!ret){
  ------------------
  |  Branch (195:8): [True: 0, False: 62]
  ------------------
  196|      0|      ogg_stream_clear(os);
  197|      0|      return -1;
  198|      0|    }
  199|     62|    os->body_storage=body_storage;
  200|     62|    os->body_data=ret;
  201|     62|  }
  202|  1.60k|  return 0;
  203|  1.60k|}
framing.c:_os_lacing_expand:
  205|  4.83k|static int _os_lacing_expand(ogg_stream_state *os,long needed){
  206|  4.83k|  if(os->lacing_storage-needed<=os->lacing_fill){
  ------------------
  |  Branch (206:6): [True: 0, False: 4.83k]
  ------------------
  207|      0|    long lacing_storage;
  208|      0|    void *ret;
  209|      0|    if(os->lacing_storage>LONG_MAX-needed){
  ------------------
  |  Branch (209:8): [True: 0, False: 0]
  ------------------
  210|      0|      ogg_stream_clear(os);
  211|      0|      return -1;
  212|      0|    }
  213|      0|    lacing_storage=os->lacing_storage+needed;
  214|      0|    if(lacing_storage<LONG_MAX-32)lacing_storage+=32;
  ------------------
  |  Branch (214:8): [True: 0, False: 0]
  ------------------
  215|      0|    ret=_ogg_realloc(os->lacing_vals,lacing_storage*sizeof(*os->lacing_vals));
  ------------------
  |  |   23|      0|#define _ogg_realloc realloc
  ------------------
  216|      0|    if(!ret){
  ------------------
  |  Branch (216:8): [True: 0, False: 0]
  ------------------
  217|      0|      ogg_stream_clear(os);
  218|      0|      return -1;
  219|      0|    }
  220|      0|    os->lacing_vals=ret;
  221|      0|    ret=_ogg_realloc(os->granule_vals,lacing_storage*
  ------------------
  |  |   23|      0|#define _ogg_realloc realloc
  ------------------
  222|      0|                     sizeof(*os->granule_vals));
  223|      0|    if(!ret){
  ------------------
  |  Branch (223:8): [True: 0, False: 0]
  ------------------
  224|      0|      ogg_stream_clear(os);
  225|      0|      return -1;
  226|      0|    }
  227|      0|    os->granule_vals=ret;
  228|      0|    os->lacing_storage=lacing_storage;
  229|      0|  }
  230|  4.83k|  return 0;
  231|  4.83k|}
framing.c:_packetout:
  944|  15.0k|static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  945|       |
  946|       |  /* The last part of decode. We have the stream broken into packet
  947|       |     segments.  Now we need to group them into packets (or return the
  948|       |     out of sync markers) */
  949|       |
  950|  15.0k|  int ptr=os->lacing_returned;
  951|       |
  952|  15.0k|  if(os->lacing_packet<=ptr)return(0);
  ------------------
  |  Branch (952:6): [True: 2.31k, False: 12.7k]
  ------------------
  953|       |
  954|  12.7k|  if(os->lacing_vals[ptr]&0x400){
  ------------------
  |  Branch (954:6): [True: 3.54k, False: 9.17k]
  ------------------
  955|       |    /* we need to tell the codec there's a gap; it might need to
  956|       |       handle previous packet dependencies. */
  957|  3.54k|    os->lacing_returned++;
  958|  3.54k|    os->packetno++;
  959|  3.54k|    return(-1);
  960|  3.54k|  }
  961|       |
  962|  9.17k|  if(!op && !adv)return(1); /* just using peek as an inexpensive way
  ------------------
  |  Branch (962:6): [True: 0, False: 9.17k]
  |  Branch (962:13): [True: 0, False: 0]
  ------------------
  963|       |                               to ask if there's a whole packet
  964|       |                               waiting */
  965|       |
  966|       |  /* Gather the whole packet. We'll have no holes or a partial packet */
  967|  9.17k|  {
  968|  9.17k|    int size=os->lacing_vals[ptr]&0xff;
  969|  9.17k|    long bytes=size;
  970|  9.17k|    int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  971|  9.17k|    int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  972|       |
  973|  11.5k|    while(size==255){
  ------------------
  |  Branch (973:11): [True: 2.37k, False: 9.17k]
  ------------------
  974|  2.37k|      int val=os->lacing_vals[++ptr];
  975|  2.37k|      size=val&0xff;
  976|  2.37k|      if(val&0x200)eos=0x200;
  ------------------
  |  Branch (976:10): [True: 204, False: 2.17k]
  ------------------
  977|  2.37k|      bytes+=size;
  978|  2.37k|    }
  979|       |
  980|  9.17k|    if(op){
  ------------------
  |  Branch (980:8): [True: 9.17k, False: 0]
  ------------------
  981|  9.17k|      op->e_o_s=eos;
  982|  9.17k|      op->b_o_s=bos;
  983|  9.17k|      op->packet=os->body_data+os->body_returned;
  984|  9.17k|      op->packetno=os->packetno;
  985|  9.17k|      op->granulepos=os->granule_vals[ptr];
  986|  9.17k|      op->bytes=bytes;
  987|  9.17k|    }
  988|       |
  989|  9.17k|    if(adv){
  ------------------
  |  Branch (989:8): [True: 9.17k, False: 0]
  ------------------
  990|  9.17k|      os->body_returned+=bytes;
  991|  9.17k|      os->lacing_returned=ptr+1;
  992|  9.17k|      os->packetno++;
  993|  9.17k|    }
  994|  9.17k|  }
  995|  9.17k|  return(1);
  996|  9.17k|}

LLVMFuzzerTestOneInput:
   21|  1.13k|extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
   22|  1.13k|  if (size < 10) return 0;
  ------------------
  |  Branch (22:7): [True: 6, False: 1.12k]
  ------------------
   23|       |
   24|       |  // Use the first few bytes to decide what to do
   25|  1.12k|  uint8_t action = data[0];
   26|  1.12k|  uint32_t serial = (data[1] << 24) | (data[2] << 16) | (data[3] << 8) | data[4];
   27|  1.12k|  const uint8_t *fuzz_data = data + 5;
   28|  1.12k|  size_t fuzz_size = size - 5;
   29|       |
   30|       |  // Fuzz ogg_sync and ogg_stream
   31|  1.12k|  ogg_sync_state oy;
   32|  1.12k|  ogg_stream_state os;
   33|  1.12k|  ogg_sync_init(&oy);
   34|  1.12k|  ogg_stream_init(&os, serial);
   35|       |
   36|  1.12k|  char *buf = ogg_sync_buffer(&oy, fuzz_size);
   37|  1.12k|  if (buf) {
  ------------------
  |  Branch (37:7): [True: 1.12k, False: 0]
  ------------------
   38|  1.12k|    memcpy(buf, fuzz_data, fuzz_size);
   39|  1.12k|    ogg_sync_wrote(&oy, fuzz_size);
   40|  1.12k|  }
   41|       |
   42|  1.12k|  ogg_page og;
   43|  6.98k|  while (ogg_sync_pageout(&oy, &og) == 1) {
  ------------------
  |  Branch (43:10): [True: 5.85k, False: 1.12k]
  ------------------
   44|  5.85k|    ogg_stream_pagein(&os, &og);
   45|  5.85k|    ogg_packet op;
   46|  15.0k|    while (ogg_stream_packetout(&os, &op) == 1) {
  ------------------
  |  Branch (46:12): [True: 9.17k, False: 5.85k]
  ------------------
   47|       |      // Successfully extracted a packet
   48|  9.17k|    }
   49|  5.85k|  }
   50|       |
   51|  1.12k|  ogg_stream_clear(&os);
   52|  1.12k|  ogg_sync_clear(&oy);
   53|       |
   54|       |  // Fuzz oggpack (bitwise) - LSb
   55|  1.12k|  oggpack_buffer opb;
   56|  1.12k|  oggpack_writeinit(&opb);
   57|       |  
   58|  1.12k|  size_t pos = 0;
   59|  1.88M|  while (pos + 5 <= fuzz_size) {
  ------------------
  |  Branch (59:10): [True: 1.88M, False: 1.12k]
  ------------------
   60|  1.88M|    uint8_t op_choice = fuzz_data[pos++];
   61|  1.88M|    uint32_t val = (fuzz_data[pos] << 24) | (fuzz_data[pos+1] << 16) | (fuzz_data[pos+2] << 8) | fuzz_data[pos+3];
   62|  1.88M|    pos += 4;
   63|       |    
   64|  1.88M|    switch (op_choice % 4) {
  ------------------
  |  Branch (64:13): [True: 1.88M, False: 0]
  ------------------
   65|  1.87M|      case 0:
  ------------------
  |  Branch (65:7): [True: 1.87M, False: 10.9k]
  ------------------
   66|  1.87M|        oggpack_write(&opb, val, fuzz_data[pos-1] % 33);
   67|  1.87M|        break;
   68|  2.43k|      case 1:
  ------------------
  |  Branch (68:7): [True: 2.43k, False: 1.88M]
  ------------------
   69|  2.43k|        oggpack_writealign(&opb);
   70|  2.43k|        break;
   71|    741|      case 2:
  ------------------
  |  Branch (71:7): [True: 741, False: 1.88M]
  ------------------
   72|    741|        oggpack_writecopy(&opb, (void*)(fuzz_data + pos), (fuzz_size - pos) * 8);
   73|    741|        pos = fuzz_size; // consume rest
   74|    741|        break;
   75|  7.74k|      case 3:
  ------------------
  |  Branch (75:7): [True: 7.74k, False: 1.87M]
  ------------------
   76|  7.74k|        oggpack_reset(&opb);
   77|  7.74k|        break;
   78|  1.88M|    }
   79|  1.88M|  }
   80|       |  
   81|       |  // Read back what we wrote
   82|  1.12k|  unsigned char *out_buf = oggpack_get_buffer(&opb);
   83|  1.12k|  long out_bytes = oggpack_bytes(&opb);
   84|  1.12k|  if (out_buf && out_bytes > 0) {
  ------------------
  |  Branch (84:7): [True: 1.12k, False: 0]
  |  Branch (84:18): [True: 962, False: 166]
  ------------------
   85|    962|    oggpack_buffer opr;
   86|    962|    oggpack_readinit(&opr, out_buf, out_bytes);
   87|  10.5k|    for (int i = 0; i < 10; ++i) {
  ------------------
  |  Branch (87:21): [True: 9.62k, False: 962]
  ------------------
   88|  9.62k|        oggpack_look(&opr, 10);
   89|  9.62k|        oggpack_adv(&opr, 1);
   90|  9.62k|        oggpack_read(&opr, 8);
   91|  9.62k|    }
   92|    962|  }
   93|  1.12k|  oggpack_writeclear(&opb);
   94|       |
   95|       |  // Fuzz oggpackB (bitwise) - MSb
   96|  1.12k|  oggpackB_writeinit(&opb);
   97|  1.12k|  pos = 0;
   98|  1.88M|  while (pos + 5 <= fuzz_size) {
  ------------------
  |  Branch (98:10): [True: 1.88M, False: 1.12k]
  ------------------
   99|  1.88M|    uint8_t op_choice = fuzz_data[pos++];
  100|  1.88M|    uint32_t val = (fuzz_data[pos] << 24) | (fuzz_data[pos+1] << 16) | (fuzz_data[pos+2] << 8) | fuzz_data[pos+3];
  101|  1.88M|    pos += 4;
  102|       |    
  103|  1.88M|    switch (op_choice % 4) {
  ------------------
  |  Branch (103:13): [True: 1.88M, False: 0]
  ------------------
  104|  1.87M|      case 0:
  ------------------
  |  Branch (104:7): [True: 1.87M, False: 10.9k]
  ------------------
  105|  1.87M|        oggpackB_write(&opb, val, fuzz_data[pos-1] % 33);
  106|  1.87M|        break;
  107|  2.43k|      case 1:
  ------------------
  |  Branch (107:7): [True: 2.43k, False: 1.88M]
  ------------------
  108|  2.43k|        oggpackB_writealign(&opb);
  109|  2.43k|        break;
  110|    741|      case 2:
  ------------------
  |  Branch (110:7): [True: 741, False: 1.88M]
  ------------------
  111|    741|        oggpackB_writecopy(&opb, (void*)(fuzz_data + pos), (fuzz_size - pos) * 8);
  112|    741|        pos = fuzz_size; // consume rest
  113|    741|        break;
  114|  7.74k|      case 3:
  ------------------
  |  Branch (114:7): [True: 7.74k, False: 1.87M]
  ------------------
  115|  7.74k|        oggpackB_reset(&opb);
  116|  7.74k|        break;
  117|  1.88M|    }
  118|  1.88M|  }
  119|  1.12k|  out_buf = oggpackB_get_buffer(&opb);
  120|  1.12k|  out_bytes = oggpackB_bytes(&opb);
  121|  1.12k|  if (out_buf && out_bytes > 0) {
  ------------------
  |  Branch (121:7): [True: 1.12k, False: 0]
  |  Branch (121:18): [True: 962, False: 166]
  ------------------
  122|    962|    oggpack_buffer opr;
  123|    962|    oggpackB_readinit(&opr, out_buf, out_bytes);
  124|  10.5k|    for (int i = 0; i < 10; ++i) {
  ------------------
  |  Branch (124:21): [True: 9.62k, False: 962]
  ------------------
  125|  9.62k|        oggpackB_look(&opr, 10);
  126|  9.62k|        oggpackB_adv(&opr, 1);
  127|  9.62k|        oggpackB_read(&opr, 8);
  128|  9.62k|    }
  129|    962|  }
  130|  1.12k|  oggpackB_writeclear(&opb);
  131|       |
  132|  1.12k|  return 0;
  133|  1.12k|}

