oggpack_writeinit:
   39|  2.22k|void oggpack_writeinit(oggpack_buffer *b){
   40|  2.22k|  memset(b,0,sizeof(*b));
   41|  2.22k|  b->ptr=b->buffer=_ogg_malloc(BUFFER_INCREMENT);
  ------------------
  |  |   21|  2.22k|#define _ogg_malloc  malloc
  ------------------
                b->ptr=b->buffer=_ogg_malloc(BUFFER_INCREMENT);
  ------------------
  |  |   25|  2.22k|#define BUFFER_INCREMENT 256
  ------------------
   42|  2.22k|  if (!b->buffer)
  ------------------
  |  Branch (42:7): [True: 0, False: 2.22k]
  ------------------
   43|      0|    return;
   44|  2.22k|  b->buffer[0]='\0';
   45|  2.22k|  b->storage=BUFFER_INCREMENT;
  ------------------
  |  |   25|  2.22k|#define BUFFER_INCREMENT 256
  ------------------
   46|  2.22k|}
oggpackB_writeinit:
   48|  1.11k|void oggpackB_writeinit(oggpack_buffer *b){
   49|  1.11k|  oggpack_writeinit(b);
   50|  1.11k|}
oggpack_write:
   84|  14.6M|void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
   85|  14.6M|  if(bits<0 || bits>32) goto err;
  ------------------
  |  Branch (85:6): [True: 0, False: 14.6M]
  |  Branch (85:16): [True: 0, False: 14.6M]
  ------------------
   86|  14.6M|  if(b->endbyte>=b->storage-4){
  ------------------
  |  Branch (86:6): [True: 14.6k, False: 14.5M]
  ------------------
   87|  14.6k|    void *ret;
   88|  14.6k|    if(!b->ptr)return;
  ------------------
  |  Branch (88:8): [True: 0, False: 14.6k]
  ------------------
   89|  14.6k|    if(b->storage>LONG_MAX-BUFFER_INCREMENT) goto err;
  ------------------
  |  |   25|  14.6k|#define BUFFER_INCREMENT 256
  ------------------
  |  Branch (89:8): [True: 0, False: 14.6k]
  ------------------
   90|  14.6k|    ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  ------------------
  |  |   23|  14.6k|#define _ogg_realloc realloc
  ------------------
                  ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  ------------------
  |  |   25|  14.6k|#define BUFFER_INCREMENT 256
  ------------------
   91|  14.6k|    if(!ret) goto err;
  ------------------
  |  Branch (91:8): [True: 0, False: 14.6k]
  ------------------
   92|  14.6k|    b->buffer=ret;
   93|  14.6k|    b->storage+=BUFFER_INCREMENT;
  ------------------
  |  |   25|  14.6k|#define BUFFER_INCREMENT 256
  ------------------
   94|  14.6k|    b->ptr=b->buffer+b->endbyte;
   95|  14.6k|  }
   96|       |
   97|  14.6M|  value&=mask[bits];
   98|  14.6M|  bits+=b->endbit;
   99|       |
  100|  14.6M|  b->ptr[0]|=value<<b->endbit;
  101|       |
  102|  14.6M|  if(bits>=8){
  ------------------
  |  Branch (102:6): [True: 14.4M, False: 157k]
  ------------------
  103|  14.4M|    b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  104|  14.4M|    if(bits>=16){
  ------------------
  |  Branch (104:8): [True: 1.07M, False: 13.3M]
  ------------------
  105|  1.07M|      b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  106|  1.07M|      if(bits>=24){
  ------------------
  |  Branch (106:10): [True: 989k, False: 89.8k]
  ------------------
  107|   989k|        b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  108|   989k|        if(bits>=32){
  ------------------
  |  Branch (108:12): [True: 839k, False: 150k]
  ------------------
  109|   839k|          if(b->endbit)
  ------------------
  |  Branch (109:14): [True: 507k, False: 332k]
  ------------------
  110|   507k|            b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  111|   332k|          else
  112|   332k|            b->ptr[4]=0;
  113|   839k|        }
  114|   989k|      }
  115|  1.07M|    }
  116|  14.4M|  }
  117|       |
  118|  14.6M|  b->endbyte+=bits/8;
  119|  14.6M|  b->ptr+=bits/8;
  120|  14.6M|  b->endbit=bits&7;
  121|  14.6M|  return;
  122|      0| err:
  123|      0|  oggpack_writeclear(b);
  124|      0|}
oggpackB_write:
  127|  14.6M|void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  128|  14.6M|  if(bits<0 || bits>32) goto err;
  ------------------
  |  Branch (128:6): [True: 0, False: 14.6M]
  |  Branch (128:16): [True: 0, False: 14.6M]
  ------------------
  129|  14.6M|  if(b->endbyte>=b->storage-4){
  ------------------
  |  Branch (129:6): [True: 14.6k, False: 14.5M]
  ------------------
  130|  14.6k|    void *ret;
  131|  14.6k|    if(!b->ptr)return;
  ------------------
  |  Branch (131:8): [True: 0, False: 14.6k]
  ------------------
  132|  14.6k|    if(b->storage>LONG_MAX-BUFFER_INCREMENT) goto err;
  ------------------
  |  |   25|  14.6k|#define BUFFER_INCREMENT 256
  ------------------
  |  Branch (132:8): [True: 0, False: 14.6k]
  ------------------
  133|  14.6k|    ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  ------------------
  |  |   23|  14.6k|#define _ogg_realloc realloc
  ------------------
                  ret=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  ------------------
  |  |   25|  14.6k|#define BUFFER_INCREMENT 256
  ------------------
  134|  14.6k|    if(!ret) goto err;
  ------------------
  |  Branch (134:8): [True: 0, False: 14.6k]
  ------------------
  135|  14.6k|    b->buffer=ret;
  136|  14.6k|    b->storage+=BUFFER_INCREMENT;
  ------------------
  |  |   25|  14.6k|#define BUFFER_INCREMENT 256
  ------------------
  137|  14.6k|    b->ptr=b->buffer+b->endbyte;
  138|  14.6k|  }
  139|       |
  140|  14.6M|  value=(value&mask[bits])<<(32-bits);
  141|  14.6M|  bits+=b->endbit;
  142|       |
  143|  14.6M|  b->ptr[0]|=value>>(24+b->endbit);
  144|       |
  145|  14.6M|  if(bits>=8){
  ------------------
  |  Branch (145:6): [True: 14.4M, False: 157k]
  ------------------
  146|  14.4M|    b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  147|  14.4M|    if(bits>=16){
  ------------------
  |  Branch (147:8): [True: 1.07M, False: 13.3M]
  ------------------
  148|  1.07M|      b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  149|  1.07M|      if(bits>=24){
  ------------------
  |  Branch (149:10): [True: 989k, False: 89.8k]
  ------------------
  150|   989k|        b->ptr[3]=(unsigned char)(value>>(b->endbit));
  151|   989k|        if(bits>=32){
  ------------------
  |  Branch (151:12): [True: 839k, False: 150k]
  ------------------
  152|   839k|          if(b->endbit)
  ------------------
  |  Branch (152:14): [True: 507k, False: 332k]
  ------------------
  153|   507k|            b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  154|   332k|          else
  155|   332k|            b->ptr[4]=0;
  156|   839k|        }
  157|   989k|      }
  158|  1.07M|    }
  159|  14.4M|  }
  160|       |
  161|  14.6M|  b->endbyte+=bits/8;
  162|  14.6M|  b->ptr+=bits/8;
  163|  14.6M|  b->endbit=bits&7;
  164|  14.6M|  return;
  165|      0| err:
  166|      0|  oggpack_writeclear(b);
  167|      0|}
oggpack_writealign:
  169|  6.19k|void oggpack_writealign(oggpack_buffer *b){
  170|  6.19k|  int bits=8-b->endbit;
  171|  6.19k|  if(bits<8)
  ------------------
  |  Branch (171:6): [True: 372, False: 5.82k]
  ------------------
  172|    372|    oggpack_write(b,0,bits);
  173|  6.19k|}
oggpackB_writealign:
  175|  6.19k|void oggpackB_writealign(oggpack_buffer *b){
  176|  6.19k|  int bits=8-b->endbit;
  177|  6.19k|  if(bits<8)
  ------------------
  |  Branch (177:6): [True: 372, False: 5.82k]
  ------------------
  178|    372|    oggpackB_write(b,0,bits);
  179|  6.19k|}
oggpack_writecopy:
  232|    755|void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  233|    755|  oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  234|    755|}
oggpackB_writecopy:
  236|    755|void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  237|    755|  oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  238|    755|}
oggpack_reset:
  240|  14.8k|void oggpack_reset(oggpack_buffer *b){
  241|  14.8k|  if(!b->ptr)return;
  ------------------
  |  Branch (241:6): [True: 0, False: 14.8k]
  ------------------
  242|  14.8k|  b->ptr=b->buffer;
  243|  14.8k|  b->buffer[0]=0;
  244|  14.8k|  b->endbit=b->endbyte=0;
  245|  14.8k|}
oggpackB_reset:
  247|  7.41k|void oggpackB_reset(oggpack_buffer *b){
  248|  7.41k|  oggpack_reset(b);
  249|  7.41k|}
oggpack_writeclear:
  251|  2.22k|void oggpack_writeclear(oggpack_buffer *b){
  252|  2.22k|  if(b->buffer)_ogg_free(b->buffer);
  ------------------
  |  |   24|  2.22k|#define _ogg_free    free
  ------------------
  |  Branch (252:6): [True: 2.22k, False: 0]
  ------------------
  253|  2.22k|  memset(b,0,sizeof(*b));
  254|  2.22k|}
oggpackB_writeclear:
  256|  1.11k|void oggpackB_writeclear(oggpack_buffer *b){
  257|  1.11k|  oggpack_writeclear(b);
  258|  1.11k|}
oggpack_readinit:
  260|  1.91k|void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  261|  1.91k|  memset(b,0,sizeof(*b));
  262|  1.91k|  b->buffer=b->ptr=buf;
  263|  1.91k|  b->storage=bytes;
  264|  1.91k|}
oggpackB_readinit:
  266|    955|void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  267|    955|  oggpack_readinit(b,buf,bytes);
  268|    955|}
oggpack_look:
  271|  9.55k|long oggpack_look(oggpack_buffer *b,int bits){
  272|  9.55k|  unsigned long ret;
  273|  9.55k|  unsigned long m;
  274|       |
  275|  9.55k|  if(bits<0 || bits>32) return -1;
  ------------------
  |  Branch (275:6): [True: 0, False: 9.55k]
  |  Branch (275:16): [True: 0, False: 9.55k]
  ------------------
  276|  9.55k|  m=mask[bits];
  277|  9.55k|  bits+=b->endbit;
  278|       |
  279|  9.55k|  if(b->endbyte >= b->storage-4){
  ------------------
  |  Branch (279:6): [True: 1.96k, False: 7.58k]
  ------------------
  280|       |    /* not the main path */
  281|  1.96k|    if(b->endbyte > b->storage-((bits+7)>>3)) return -1;
  ------------------
  |  Branch (281:8): [True: 1.49k, False: 467]
  ------------------
  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|    467|    else if(!bits)return(0L);
  ------------------
  |  Branch (284:13): [True: 0, False: 467]
  ------------------
  285|  1.96k|  }
  286|       |
  287|  8.05k|  ret=b->ptr[0]>>b->endbit;
  288|  8.05k|  if(bits>8){
  ------------------
  |  Branch (288:6): [True: 8.05k, False: 0]
  ------------------
  289|  8.05k|    ret|=(unsigned long)b->ptr[1]<<(8-b->endbit);
  290|  8.05k|    if(bits>16){
  ------------------
  |  Branch (290:8): [True: 752, False: 7.30k]
  ------------------
  291|    752|      ret|=(unsigned long)b->ptr[2]<<(16-b->endbit);
  292|    752|      if(bits>24){
  ------------------
  |  Branch (292:10): [True: 0, False: 752]
  ------------------
  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|    752|    }
  298|  8.05k|  }
  299|  8.05k|  return(m&ret);
  300|  9.55k|}
oggpackB_look:
  303|  9.55k|long oggpackB_look(oggpack_buffer *b,int bits){
  304|  9.55k|  unsigned long ret;
  305|  9.55k|  int m=32-bits;
  306|       |
  307|  9.55k|  if(m<0 || m>32) return -1;
  ------------------
  |  Branch (307:6): [True: 0, False: 9.55k]
  |  Branch (307:13): [True: 0, False: 9.55k]
  ------------------
  308|  9.55k|  bits+=b->endbit;
  309|       |
  310|  9.55k|  if(b->endbyte >= b->storage-4){
  ------------------
  |  Branch (310:6): [True: 1.96k, False: 7.58k]
  ------------------
  311|       |    /* not the main path */
  312|  1.96k|    if(b->endbyte > b->storage-((bits+7)>>3)) return -1;
  ------------------
  |  Branch (312:8): [True: 1.49k, False: 467]
  ------------------
  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|    467|    else if(!bits)return(0L);
  ------------------
  |  Branch (315:13): [True: 0, False: 467]
  ------------------
  316|  1.96k|  }
  317|       |
  318|  8.05k|  ret=(unsigned long)b->ptr[0]<<(24+b->endbit);
  319|  8.05k|  if(bits>8){
  ------------------
  |  Branch (319:6): [True: 8.05k, False: 0]
  ------------------
  320|  8.05k|    ret|=(unsigned long)b->ptr[1]<<(16+b->endbit);
  321|  8.05k|    if(bits>16){
  ------------------
  |  Branch (321:8): [True: 752, False: 7.30k]
  ------------------
  322|    752|      ret|=(unsigned long)b->ptr[2]<<(8+b->endbit);
  323|    752|      if(bits>24){
  ------------------
  |  Branch (323:10): [True: 0, False: 752]
  ------------------
  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|    752|    }
  329|  8.05k|  }
  330|  8.05k|  return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  331|  9.55k|}
oggpack_adv:
  343|  19.1k|void oggpack_adv(oggpack_buffer *b,int bits){
  344|  19.1k|  bits+=b->endbit;
  345|       |
  346|  19.1k|  if(b->endbyte > b->storage-((bits+7)>>3)) goto overflow;
  ------------------
  |  Branch (346:6): [True: 2.56k, False: 16.5k]
  ------------------
  347|       |
  348|  16.5k|  b->ptr+=bits/8;
  349|  16.5k|  b->endbyte+=bits/8;
  350|  16.5k|  b->endbit=bits&7;
  351|  16.5k|  return;
  352|       |
  353|  2.56k| overflow:
  354|       |  b->ptr=NULL;
  355|  2.56k|  b->endbyte=b->storage;
  356|  2.56k|  b->endbit=1;
  357|  2.56k|}
oggpackB_adv:
  359|  9.55k|void oggpackB_adv(oggpack_buffer *b,int bits){
  360|  9.55k|  oggpack_adv(b,bits);
  361|  9.55k|}
oggpack_read:
  376|  9.55k|long oggpack_read(oggpack_buffer *b,int bits){
  377|  9.55k|  long ret;
  378|  9.55k|  unsigned long m;
  379|       |
  380|  9.55k|  if(bits<0 || bits>32) goto err;
  ------------------
  |  Branch (380:6): [True: 0, False: 9.55k]
  |  Branch (380:16): [True: 0, False: 9.55k]
  ------------------
  381|  9.55k|  m=mask[bits];
  382|  9.55k|  bits+=b->endbit;
  383|       |
  384|  9.55k|  if(b->endbyte >= b->storage-4){
  ------------------
  |  Branch (384:6): [True: 1.97k, False: 7.57k]
  ------------------
  385|       |    /* not the main path */
  386|  1.97k|    if(b->endbyte > b->storage-((bits+7)>>3)) goto overflow;
  ------------------
  |  Branch (386:8): [True: 1.48k, False: 493]
  ------------------
  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|    493|    else if(!bits)return(0L);
  ------------------
  |  Branch (389:13): [True: 0, False: 493]
  ------------------
  390|  1.97k|  }
  391|       |
  392|  8.06k|  ret=b->ptr[0]>>b->endbit;
  393|  8.06k|  if(bits>8){
  ------------------
  |  Branch (393:6): [True: 7.30k, False: 761]
  ------------------
  394|  7.30k|    ret|=(unsigned long)b->ptr[1]<<(8-b->endbit);
  395|  7.30k|    if(bits>16){
  ------------------
  |  Branch (395:8): [True: 0, False: 7.30k]
  ------------------
  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.30k|  }
  405|  8.06k|  ret&=m;
  406|  8.06k|  b->ptr+=bits/8;
  407|  8.06k|  b->endbyte+=bits/8;
  408|  8.06k|  b->endbit=bits&7;
  409|  8.06k|  return ret;
  410|       |
  411|  1.48k| overflow:
  412|  1.48k| err:
  413|       |  b->ptr=NULL;
  414|  1.48k|  b->endbyte=b->storage;
  415|  1.48k|  b->endbit=1;
  416|  1.48k|  return -1L;
  417|  1.48k|}
oggpackB_read:
  420|  9.55k|long oggpackB_read(oggpack_buffer *b,int bits){
  421|  9.55k|  long ret;
  422|  9.55k|  long m=32-bits;
  423|       |
  424|  9.55k|  if(m<0 || m>32) goto err;
  ------------------
  |  Branch (424:6): [True: 0, False: 9.55k]
  |  Branch (424:13): [True: 0, False: 9.55k]
  ------------------
  425|  9.55k|  bits+=b->endbit;
  426|       |
  427|  9.55k|  if(b->endbyte+4>=b->storage){
  ------------------
  |  Branch (427:6): [True: 1.97k, False: 7.57k]
  ------------------
  428|       |    /* not the main path */
  429|  1.97k|    if(b->endbyte > b->storage-((bits+7)>>3)) goto overflow;
  ------------------
  |  Branch (429:8): [True: 1.48k, False: 493]
  ------------------
  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|    493|    else if(!bits)return(0L);
  ------------------
  |  Branch (432:13): [True: 0, False: 493]
  ------------------
  433|  1.97k|  }
  434|       |
  435|  8.06k|  ret=(unsigned long)b->ptr[0]<<(24+b->endbit);
  436|  8.06k|  if(bits>8){
  ------------------
  |  Branch (436:6): [True: 7.30k, False: 761]
  ------------------
  437|  7.30k|    ret|=(unsigned long)b->ptr[1]<<(16+b->endbit);
  438|  7.30k|    if(bits>16){
  ------------------
  |  Branch (438:8): [True: 0, False: 7.30k]
  ------------------
  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.30k|  }
  447|  8.06k|  ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  448|       |
  449|  8.06k|  b->ptr+=bits/8;
  450|  8.06k|  b->endbyte+=bits/8;
  451|  8.06k|  b->endbit=bits&7;
  452|  8.06k|  return ret;
  453|       |
  454|  1.48k| overflow:
  455|  1.48k| err:
  456|       |  b->ptr=NULL;
  457|  1.48k|  b->endbyte=b->storage;
  458|  1.48k|  b->endbit=1;
  459|  1.48k|  return -1L;
  460|  1.48k|}
oggpack_bytes:
  504|  2.22k|long oggpack_bytes(oggpack_buffer *b){
  505|  2.22k|  return(b->endbyte+(b->endbit+7)/8);
  506|  2.22k|}
oggpackB_bytes:
  512|  1.11k|long oggpackB_bytes(oggpack_buffer *b){
  513|  1.11k|  return oggpack_bytes(b);
  514|  1.11k|}
oggpack_get_buffer:
  520|  2.22k|unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  521|  2.22k|  return(b->buffer);
  522|  2.22k|}
oggpackB_get_buffer:
  524|  1.11k|unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  525|  1.11k|  return oggpack_get_buffer(b);
  526|  1.11k|}
bitwise.c:oggpack_writecopy_helper:
  187|  1.51k|                                     int msb){
  188|  1.51k|  unsigned char *ptr=(unsigned char *)source;
  189|       |
  190|  1.51k|  long bytes=bits/8;
  191|  1.51k|  long pbytes=(b->endbit+bits)/8;
  192|  1.51k|  bits-=bytes*8;
  193|       |
  194|       |  /* expand storage up-front */
  195|  1.51k|  if(b->endbyte+pbytes>=b->storage){
  ------------------
  |  Branch (195:6): [True: 900, False: 610]
  ------------------
  196|    900|    void *ret;
  197|    900|    if(!b->ptr) goto err;
  ------------------
  |  Branch (197:8): [True: 0, False: 900]
  ------------------
  198|    900|    if(b->storage>b->endbyte+pbytes+BUFFER_INCREMENT) goto err;
  ------------------
  |  |   25|    900|#define BUFFER_INCREMENT 256
  ------------------
  |  Branch (198:8): [True: 0, False: 900]
  ------------------
  199|    900|    b->storage=b->endbyte+pbytes+BUFFER_INCREMENT;
  ------------------
  |  |   25|    900|#define BUFFER_INCREMENT 256
  ------------------
  200|    900|    ret=_ogg_realloc(b->buffer,b->storage);
  ------------------
  |  |   23|    900|#define _ogg_realloc realloc
  ------------------
  201|    900|    if(!ret) goto err;
  ------------------
  |  Branch (201:8): [True: 0, False: 900]
  ------------------
  202|    900|    b->buffer=ret;
  203|    900|    b->ptr=b->buffer+b->endbyte;
  204|    900|  }
  205|       |
  206|       |  /* copy whole octets */
  207|  1.51k|  if(b->endbit){
  ------------------
  |  Branch (207:6): [True: 370, False: 1.14k]
  ------------------
  208|    370|    int i;
  209|       |    /* unaligned copy.  Do it the hard way. */
  210|  26.5M|    for(i=0;i<bytes;i++)
  ------------------
  |  Branch (210:13): [True: 26.5M, False: 370]
  ------------------
  211|  26.5M|      w(b,(unsigned long)(ptr[i]),8);
  212|  1.14k|  }else{
  213|       |    /* aligned block copy */
  214|  1.14k|    memmove(b->ptr,source,bytes);
  215|  1.14k|    b->ptr+=bytes;
  216|  1.14k|    b->endbyte+=bytes;
  217|  1.14k|    *b->ptr=0;
  218|  1.14k|  }
  219|       |
  220|       |  /* copy trailing bits */
  221|  1.51k|  if(bits){
  ------------------
  |  Branch (221:6): [True: 0, False: 1.51k]
  ------------------
  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.51k|  return;
  228|      0| err:
  229|      0|  oggpack_writeclear(b);
  230|      0|}

ogg_page_version:
   33|  6.22k|int ogg_page_version(const ogg_page *og){
   34|  6.22k|  return((int)(og->header[4]));
   35|  6.22k|}
ogg_page_continued:
   37|  6.22k|int ogg_page_continued(const ogg_page *og){
   38|  6.22k|  return((int)(og->header[5]&0x01));
   39|  6.22k|}
ogg_page_bos:
   41|  6.22k|int ogg_page_bos(const ogg_page *og){
   42|  6.22k|  return((int)(og->header[5]&0x02));
   43|  6.22k|}
ogg_page_eos:
   45|  6.22k|int ogg_page_eos(const ogg_page *og){
   46|  6.22k|  return((int)(og->header[5]&0x04));
   47|  6.22k|}
ogg_page_granulepos:
   49|  6.22k|ogg_int64_t ogg_page_granulepos(const ogg_page *og){
   50|  6.22k|  unsigned char *page=og->header;
   51|  6.22k|  ogg_uint64_t granulepos=page[13]&(0xff);
   52|  6.22k|  granulepos= (granulepos<<8)|(page[12]&0xff);
   53|  6.22k|  granulepos= (granulepos<<8)|(page[11]&0xff);
   54|  6.22k|  granulepos= (granulepos<<8)|(page[10]&0xff);
   55|  6.22k|  granulepos= (granulepos<<8)|(page[9]&0xff);
   56|  6.22k|  granulepos= (granulepos<<8)|(page[8]&0xff);
   57|  6.22k|  granulepos= (granulepos<<8)|(page[7]&0xff);
   58|  6.22k|  granulepos= (granulepos<<8)|(page[6]&0xff);
   59|  6.22k|  return((ogg_int64_t)granulepos);
   60|  6.22k|}
ogg_page_serialno:
   62|  6.22k|int ogg_page_serialno(const ogg_page *og){
   63|  6.22k|  return((int)((ogg_uint32_t)og->header[14]) |
   64|  6.22k|              ((ogg_uint32_t)og->header[15]<<8) |
   65|  6.22k|              ((ogg_uint32_t)og->header[16]<<16) |
   66|  6.22k|              ((ogg_uint32_t)og->header[17]<<24));
   67|  6.22k|}
ogg_page_pageno:
   69|  6.22k|long ogg_page_pageno(const ogg_page *og){
   70|  6.22k|  return((long)((ogg_uint32_t)og->header[18]) |
   71|  6.22k|               ((ogg_uint32_t)og->header[19]<<8) |
   72|  6.22k|               ((ogg_uint32_t)og->header[20]<<16) |
   73|  6.22k|               ((ogg_uint32_t)og->header[21]<<24));
   74|  6.22k|}
ogg_stream_init:
  133|  1.11k|int ogg_stream_init(ogg_stream_state *os,int serialno){
  134|  1.11k|  if(os){
  ------------------
  |  Branch (134:6): [True: 1.11k, False: 0]
  ------------------
  135|  1.11k|    memset(os,0,sizeof(*os));
  136|  1.11k|    os->body_storage=16*1024;
  137|  1.11k|    os->lacing_storage=1024;
  138|       |
  139|  1.11k|    os->body_data=_ogg_malloc(os->body_storage*sizeof(*os->body_data));
  ------------------
  |  |   21|  1.11k|#define _ogg_malloc  malloc
  ------------------
  140|  1.11k|    os->lacing_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  ------------------
  |  |   21|  1.11k|#define _ogg_malloc  malloc
  ------------------
  141|  1.11k|    os->granule_vals=_ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  ------------------
  |  |   21|  1.11k|#define _ogg_malloc  malloc
  ------------------
  142|       |
  143|  1.11k|    if(!os->body_data || !os->lacing_vals || !os->granule_vals){
  ------------------
  |  Branch (143:8): [True: 0, False: 1.11k]
  |  Branch (143:26): [True: 0, False: 1.11k]
  |  Branch (143:46): [True: 0, False: 1.11k]
  ------------------
  144|      0|      ogg_stream_clear(os);
  145|      0|      return -1;
  146|      0|    }
  147|       |
  148|  1.11k|    os->serialno=serialno;
  149|       |
  150|  1.11k|    return(0);
  151|  1.11k|  }
  152|      0|  return(-1);
  153|  1.11k|}
ogg_stream_check:
  156|  21.1k|int ogg_stream_check(ogg_stream_state *os){
  157|  21.1k|  if(!os || !os->body_data) return -1;
  ------------------
  |  Branch (157:6): [True: 0, False: 21.1k]
  |  Branch (157:13): [True: 0, False: 21.1k]
  ------------------
  158|  21.1k|  return 0;
  159|  21.1k|}
ogg_stream_clear:
  162|  1.11k|int ogg_stream_clear(ogg_stream_state *os){
  163|  1.11k|  if(os){
  ------------------
  |  Branch (163:6): [True: 1.11k, False: 0]
  ------------------
  164|  1.11k|    if(os->body_data)_ogg_free(os->body_data);
  ------------------
  |  |   24|  1.11k|#define _ogg_free    free
  ------------------
  |  Branch (164:8): [True: 1.11k, False: 0]
  ------------------
  165|  1.11k|    if(os->lacing_vals)_ogg_free(os->lacing_vals);
  ------------------
  |  |   24|  1.11k|#define _ogg_free    free
  ------------------
  |  Branch (165:8): [True: 1.11k, False: 0]
  ------------------
  166|  1.11k|    if(os->granule_vals)_ogg_free(os->granule_vals);
  ------------------
  |  |   24|  1.11k|#define _ogg_free    free
  ------------------
  |  Branch (166:8): [True: 1.11k, False: 0]
  ------------------
  167|       |
  168|  1.11k|    memset(os,0,sizeof(*os));
  169|  1.11k|  }
  170|  1.11k|  return(0);
  171|  1.11k|}
ogg_page_checksum_set:
  255|  6.22k|void ogg_page_checksum_set(ogg_page *og){
  256|  6.22k|  if(og){
  ------------------
  |  Branch (256:6): [True: 6.22k, False: 0]
  ------------------
  257|  6.22k|    ogg_uint32_t crc_reg=0;
  258|       |
  259|       |    /* safety; needed for API behavior, but not framing code */
  260|  6.22k|    og->header[22]=0;
  261|  6.22k|    og->header[23]=0;
  262|  6.22k|    og->header[24]=0;
  263|  6.22k|    og->header[25]=0;
  264|       |
  265|  6.22k|    crc_reg=_os_update_crc(crc_reg,og->header,og->header_len);
  266|  6.22k|    crc_reg=_os_update_crc(crc_reg,og->body,og->body_len);
  267|       |
  268|  6.22k|    og->header[22]=(unsigned char)(crc_reg&0xff);
  269|  6.22k|    og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  270|  6.22k|    og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  271|  6.22k|    og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  272|  6.22k|  }
  273|  6.22k|}
ogg_sync_init:
  558|  1.11k|int ogg_sync_init(ogg_sync_state *oy){
  559|  1.11k|  if(oy){
  ------------------
  |  Branch (559:6): [True: 1.11k, False: 0]
  ------------------
  560|  1.11k|    oy->storage = -1; /* used as a readiness flag */
  561|  1.11k|    memset(oy,0,sizeof(*oy));
  562|  1.11k|  }
  563|  1.11k|  return(0);
  564|  1.11k|}
ogg_sync_clear:
  567|  1.11k|int ogg_sync_clear(ogg_sync_state *oy){
  568|  1.11k|  if(oy){
  ------------------
  |  Branch (568:6): [True: 1.11k, False: 0]
  ------------------
  569|  1.11k|    if(oy->data)_ogg_free(oy->data);
  ------------------
  |  |   24|  1.11k|#define _ogg_free    free
  ------------------
  |  Branch (569:8): [True: 1.11k, False: 0]
  ------------------
  570|  1.11k|    memset(oy,0,sizeof(*oy));
  571|  1.11k|  }
  572|  1.11k|  return(0);
  573|  1.11k|}
ogg_sync_check:
  583|  16.9k|int ogg_sync_check(ogg_sync_state *oy){
  584|  16.9k|  if(oy->storage<0) return -1;
  ------------------
  |  Branch (584:6): [True: 0, False: 16.9k]
  ------------------
  585|  16.9k|  return 0;
  586|  16.9k|}
ogg_sync_buffer:
  588|  1.11k|char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  589|  1.11k|  if(ogg_sync_check(oy)) return NULL;
  ------------------
  |  Branch (589:6): [True: 0, False: 1.11k]
  ------------------
  590|       |
  591|       |  /* first, clear out any space that has been previously returned */
  592|  1.11k|  if(oy->returned){
  ------------------
  |  Branch (592:6): [True: 0, False: 1.11k]
  ------------------
  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.11k|  if(size>oy->storage-oy->fill){
  ------------------
  |  Branch (599:6): [True: 1.11k, False: 0]
  ------------------
  600|       |    /* We need to extend the internal buffer */
  601|  1.11k|    long newsize;
  602|  1.11k|    void *ret;
  603|       |
  604|  1.11k|    if(size>INT_MAX-4096-oy->fill){
  ------------------
  |  Branch (604:8): [True: 0, False: 1.11k]
  ------------------
  605|      0|      ogg_sync_clear(oy);
  606|      0|      return NULL;
  607|      0|    }
  608|  1.11k|    newsize=size+oy->fill+4096; /* an extra page to be nice */
  609|  1.11k|    if(oy->data)
  ------------------
  |  Branch (609:8): [True: 0, False: 1.11k]
  ------------------
  610|      0|      ret=_ogg_realloc(oy->data,newsize);
  ------------------
  |  |   23|      0|#define _ogg_realloc realloc
  ------------------
  611|  1.11k|    else
  612|  1.11k|      ret=_ogg_malloc(newsize);
  ------------------
  |  |   21|  1.11k|#define _ogg_malloc  malloc
  ------------------
  613|  1.11k|    if(!ret){
  ------------------
  |  Branch (613:8): [True: 0, False: 1.11k]
  ------------------
  614|      0|      ogg_sync_clear(oy);
  615|      0|      return NULL;
  616|      0|    }
  617|  1.11k|    oy->data=ret;
  618|  1.11k|    oy->storage=newsize;
  619|  1.11k|  }
  620|       |
  621|       |  /* expose a segment at least as large as requested at the fill mark */
  622|  1.11k|  return((char *)oy->data+oy->fill);
  623|  1.11k|}
ogg_sync_wrote:
  625|  1.11k|int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  626|  1.11k|  if(ogg_sync_check(oy))return -1;
  ------------------
  |  Branch (626:6): [True: 0, False: 1.11k]
  ------------------
  627|  1.11k|  if(oy->fill+bytes>oy->storage)return -1;
  ------------------
  |  Branch (627:6): [True: 0, False: 1.11k]
  ------------------
  628|  1.11k|  oy->fill+=bytes;
  629|  1.11k|  return(0);
  630|  1.11k|}
ogg_sync_pageseek:
  642|  7.34k|long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  643|  7.34k|  unsigned char *page;
  644|  7.34k|  unsigned char *next;
  645|  7.34k|  long bytes;
  646|       |
  647|  7.34k|  if(ogg_sync_check(oy))return 0;
  ------------------
  |  Branch (647:6): [True: 0, False: 7.34k]
  ------------------
  648|       |
  649|  7.34k|  page=oy->data+oy->returned;
  650|  7.34k|  bytes=oy->fill-oy->returned;
  651|       |
  652|  7.34k|  if(oy->headerbytes==0){
  ------------------
  |  Branch (652:6): [True: 7.34k, False: 0]
  ------------------
  653|  7.34k|    int headerbytes,i;
  654|  7.34k|    if(bytes<27)return(0); /* not enough for a header */
  ------------------
  |  Branch (654:8): [True: 713, False: 6.62k]
  ------------------
  655|       |
  656|       |    /* verify capture pattern */
  657|  6.62k|    if(memcmp(page,"OggS",4))goto sync_fail;
  ------------------
  |  Branch (657:8): [True: 344, False: 6.28k]
  ------------------
  658|       |
  659|  6.28k|    headerbytes=page[26]+27;
  660|  6.28k|    if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  ------------------
  |  Branch (660:8): [True: 12, False: 6.27k]
  ------------------
  661|       |
  662|       |    /* count up body length in the segment table */
  663|       |
  664|  36.8k|    for(i=0;i<page[26];i++)
  ------------------
  |  Branch (664:13): [True: 30.5k, False: 6.27k]
  ------------------
  665|  30.5k|      oy->bodybytes+=page[27+i];
  666|  6.27k|    oy->headerbytes=headerbytes;
  667|  6.27k|  }
  668|       |
  669|  6.27k|  if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  ------------------
  |  Branch (669:6): [True: 43, False: 6.22k]
  ------------------
  670|       |
  671|       |  /* The whole test page is buffered.  Verify the checksum */
  672|  6.22k|  {
  673|       |    /* Grab the checksum bytes, set the header field to zero */
  674|  6.22k|    char chksum[4];
  675|  6.22k|    ogg_page log;
  676|       |
  677|  6.22k|    memcpy(chksum,page+22,4);
  678|  6.22k|    memset(page+22,0,4);
  679|       |
  680|       |    /* set up a temp page struct and recompute the checksum */
  681|  6.22k|    log.header=page;
  682|  6.22k|    log.header_len=oy->headerbytes;
  683|  6.22k|    log.body=page+oy->headerbytes;
  684|  6.22k|    log.body_len=oy->bodybytes;
  685|  6.22k|    ogg_page_checksum_set(&log);
  686|       |
  687|       |    /* Compare */
  688|  6.22k|    if(memcmp(chksum,page+22,4)){
  ------------------
  |  Branch (688:8): [True: 5.88k, False: 343]
  ------------------
  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.88k|      memcpy(page+22,chksum,4);
  693|       |
  694|       |#ifndef DISABLE_CRC
  695|       |      /* Bad checksum. Lose sync */
  696|       |      goto sync_fail;
  697|       |#endif
  698|  5.88k|    }
  699|  6.22k|  }
  700|       |
  701|       |  /* yes, have a whole page all ready to go */
  702|  6.22k|  {
  703|  6.22k|    if(og){
  ------------------
  |  Branch (703:8): [True: 6.22k, False: 0]
  ------------------
  704|  6.22k|      og->header=page;
  705|  6.22k|      og->header_len=oy->headerbytes;
  706|  6.22k|      og->body=page+oy->headerbytes;
  707|  6.22k|      og->body_len=oy->bodybytes;
  708|  6.22k|    }
  709|       |
  710|  6.22k|    oy->unsynced=0;
  711|  6.22k|    oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  712|  6.22k|    oy->headerbytes=0;
  713|  6.22k|    oy->bodybytes=0;
  714|  6.22k|    return(bytes);
  715|  6.27k|  }
  716|       |
  717|    344| sync_fail:
  718|       |
  719|    344|  oy->headerbytes=0;
  720|    344|  oy->bodybytes=0;
  721|       |
  722|       |  /* search for possible capture */
  723|    344|  next=memchr(page+1,'O',bytes-1);
  724|    344|  if(!next)
  ------------------
  |  Branch (724:6): [True: 173, False: 171]
  ------------------
  725|    173|    next=oy->data+oy->fill;
  726|       |
  727|    344|  oy->returned=(int)(next-oy->data);
  728|    344|  return((long)-(next-page));
  729|  6.27k|}
ogg_sync_pageout:
  742|  7.34k|int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  743|       |
  744|  7.34k|  if(ogg_sync_check(oy))return 0;
  ------------------
  |  Branch (744:6): [True: 0, False: 7.34k]
  ------------------
  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|  7.34k|  for(;;){
  751|  7.34k|    long ret=ogg_sync_pageseek(oy,og);
  752|  7.34k|    if(ret>0){
  ------------------
  |  Branch (752:8): [True: 6.22k, False: 1.11k]
  ------------------
  753|       |      /* have a page */
  754|  6.22k|      return(1);
  755|  6.22k|    }
  756|  1.11k|    if(ret==0){
  ------------------
  |  Branch (756:8): [True: 768, False: 344]
  ------------------
  757|       |      /* need more data */
  758|    768|      return(0);
  759|    768|    }
  760|       |
  761|       |    /* head did not start a synced page... skipped some bytes */
  762|    344|    if(!oy->unsynced){
  ------------------
  |  Branch (762:8): [True: 344, False: 0]
  ------------------
  763|    344|      oy->unsynced=1;
  764|    344|      return(-1);
  765|    344|    }
  766|       |
  767|       |    /* loop. keep looking */
  768|       |
  769|    344|  }
  770|  7.34k|}
ogg_stream_pagein:
  775|  6.22k|int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  776|  6.22k|  unsigned char *header=og->header;
  777|  6.22k|  unsigned char *body=og->body;
  778|  6.22k|  long           bodysize=og->body_len;
  779|  6.22k|  int            segptr=0;
  780|       |
  781|  6.22k|  int version=ogg_page_version(og);
  782|  6.22k|  int continued=ogg_page_continued(og);
  783|  6.22k|  int bos=ogg_page_bos(og);
  784|  6.22k|  int eos=ogg_page_eos(og);
  785|  6.22k|  ogg_int64_t granulepos=ogg_page_granulepos(og);
  786|  6.22k|  int serialno=ogg_page_serialno(og);
  787|  6.22k|  long pageno=ogg_page_pageno(og);
  788|  6.22k|  int segments=header[26];
  789|       |
  790|  6.22k|  if(ogg_stream_check(os)) return -1;
  ------------------
  |  Branch (790:6): [True: 0, False: 6.22k]
  ------------------
  791|       |
  792|       |  /* clean up 'returned data' */
  793|  6.22k|  {
  794|  6.22k|    long lr=os->lacing_returned;
  795|  6.22k|    long br=os->body_returned;
  796|       |
  797|       |    /* body data */
  798|  6.22k|    if(br){
  ------------------
  |  Branch (798:8): [True: 1.05k, False: 5.17k]
  ------------------
  799|  1.05k|      os->body_fill-=br;
  800|  1.05k|      if(os->body_fill)
  ------------------
  |  Branch (800:10): [True: 637, False: 419]
  ------------------
  801|    637|        memmove(os->body_data,os->body_data+br,os->body_fill);
  802|  1.05k|      os->body_returned=0;
  803|  1.05k|    }
  804|       |
  805|  6.22k|    if(lr){
  ------------------
  |  Branch (805:8): [True: 3.65k, False: 2.57k]
  ------------------
  806|       |      /* segment table */
  807|  3.65k|      if(os->lacing_fill-lr){
  ------------------
  |  Branch (807:10): [True: 1.69k, False: 1.96k]
  ------------------
  808|  1.69k|        memmove(os->lacing_vals,os->lacing_vals+lr,
  809|  1.69k|                (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  810|  1.69k|        memmove(os->granule_vals,os->granule_vals+lr,
  811|  1.69k|                (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  812|  1.69k|      }
  813|  3.65k|      os->lacing_fill-=lr;
  814|  3.65k|      os->lacing_packet-=lr;
  815|  3.65k|      os->lacing_returned=0;
  816|  3.65k|    }
  817|  6.22k|  }
  818|       |
  819|       |  /* check the serial number */
  820|  6.22k|  if(serialno!=os->serialno)return(-1);
  ------------------
  |  Branch (820:6): [True: 1.22k, False: 5.00k]
  ------------------
  821|  5.00k|  if(version>0)return(-1);
  ------------------
  |  Branch (821:6): [True: 278, False: 4.72k]
  ------------------
  822|       |
  823|  4.72k|  if(_os_lacing_expand(os,segments+1)) return -1;
  ------------------
  |  Branch (823:6): [True: 0, False: 4.72k]
  ------------------
  824|       |
  825|       |  /* are we in sequence? */
  826|  4.72k|  if(pageno!=os->pageno){
  ------------------
  |  Branch (826:6): [True: 3.54k, False: 1.17k]
  ------------------
  827|  3.54k|    int i;
  828|       |
  829|       |    /* unroll previous partial packet (if any) */
  830|  4.41k|    for(i=os->lacing_packet;i<os->lacing_fill;i++)
  ------------------
  |  Branch (830:29): [True: 870, False: 3.54k]
  ------------------
  831|    870|      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.72k|  if(continued){
  ------------------
  |  Branch (843:6): [True: 2.46k, False: 2.26k]
  ------------------
  844|  2.46k|    if(os->lacing_fill<1 ||
  ------------------
  |  Branch (844:8): [True: 549, False: 1.91k]
  ------------------
  845|  1.91k|       (os->lacing_vals[os->lacing_fill-1]&0xff)<255 ||
  ------------------
  |  Branch (845:8): [True: 1.69k, False: 214]
  ------------------
  846|  2.24k|       os->lacing_vals[os->lacing_fill-1]==0x400){
  ------------------
  |  Branch (846:8): [True: 0, False: 214]
  ------------------
  847|  2.24k|      bos=0;
  848|  2.75k|      for(;segptr<segments;segptr++){
  ------------------
  |  Branch (848:12): [True: 1.39k, False: 1.35k]
  ------------------
  849|  1.39k|        int val=header[27+segptr];
  850|  1.39k|        body+=val;
  851|  1.39k|        bodysize-=val;
  852|  1.39k|        if(val<255){
  ------------------
  |  Branch (852:12): [True: 895, False: 504]
  ------------------
  853|    895|          segptr++;
  854|    895|          break;
  855|    895|        }
  856|  1.39k|      }
  857|  2.24k|    }
  858|  2.46k|  }
  859|       |
  860|  4.72k|  if(bodysize){
  ------------------
  |  Branch (860:6): [True: 1.61k, False: 3.10k]
  ------------------
  861|  1.61k|    if(_os_body_expand(os,bodysize)) return -1;
  ------------------
  |  Branch (861:8): [True: 0, False: 1.61k]
  ------------------
  862|  1.61k|    memcpy(os->body_data+os->body_fill,body,bodysize);
  863|  1.61k|    os->body_fill+=bodysize;
  864|  1.61k|  }
  865|       |
  866|  4.72k|  {
  867|  4.72k|    int saved=-1;
  868|  26.5k|    while(segptr<segments){
  ------------------
  |  Branch (868:11): [True: 21.8k, False: 4.72k]
  ------------------
  869|  21.8k|      int val=header[27+segptr];
  870|  21.8k|      os->lacing_vals[os->lacing_fill]=val;
  871|  21.8k|      os->granule_vals[os->lacing_fill]=-1;
  872|       |
  873|  21.8k|      if(bos){
  ------------------
  |  Branch (873:10): [True: 1.11k, False: 20.7k]
  ------------------
  874|  1.11k|        os->lacing_vals[os->lacing_fill]|=0x100;
  875|  1.11k|        bos=0;
  876|  1.11k|      }
  877|       |
  878|  21.8k|      if(val<255)saved=os->lacing_fill;
  ------------------
  |  Branch (878:10): [True: 15.7k, False: 6.08k]
  ------------------
  879|       |
  880|  21.8k|      os->lacing_fill++;
  881|  21.8k|      segptr++;
  882|       |
  883|  21.8k|      if(val<255)os->lacing_packet=os->lacing_fill;
  ------------------
  |  Branch (883:10): [True: 15.7k, False: 6.08k]
  ------------------
  884|  21.8k|    }
  885|       |
  886|       |    /* set the granulepos on the last granuleval of the last full packet */
  887|  4.72k|    if(saved!=-1){
  ------------------
  |  Branch (887:8): [True: 2.16k, False: 2.55k]
  ------------------
  888|  2.16k|      os->granule_vals[saved]=granulepos;
  889|  2.16k|    }
  890|       |
  891|  4.72k|  }
  892|       |
  893|  4.72k|  if(eos){
  ------------------
  |  Branch (893:6): [True: 2.99k, False: 1.73k]
  ------------------
  894|  2.99k|    os->e_o_s=1;
  895|  2.99k|    if(os->lacing_fill>0)
  ------------------
  |  Branch (895:8): [True: 2.58k, False: 409]
  ------------------
  896|  2.58k|      os->lacing_vals[os->lacing_fill-1]|=0x200;
  897|  2.99k|  }
  898|       |
  899|  4.72k|  os->pageno=pageno+1;
  900|       |
  901|  4.72k|  return(0);
  902|  4.72k|}
ogg_stream_packetout:
  998|  14.9k|int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  999|  14.9k|  if(ogg_stream_check(os)) return 0;
  ------------------
  |  Branch (999:6): [True: 0, False: 14.9k]
  ------------------
 1000|  14.9k|  return _packetout(os,op,1);
 1001|  14.9k|}
framing.c:_os_update_crc:
  237|  12.4k|static ogg_uint32_t _os_update_crc(ogg_uint32_t crc, unsigned char *buffer, int size){
  238|   342k|  while (size>=8){
  ------------------
  |  Branch (238:10): [True: 330k, False: 12.4k]
  ------------------
  239|   330k|    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|   330k|    crc=crc_lookup[7][ crc>>24      ]^crc_lookup[6][(crc>>16)&0xFF]^
  242|   330k|        crc_lookup[5][(crc>> 8)&0xFF]^crc_lookup[4][ crc     &0xFF]^
  243|   330k|        crc_lookup[3][buffer[4]     ]^crc_lookup[2][buffer[5]     ]^
  244|   330k|        crc_lookup[1][buffer[6]     ]^crc_lookup[0][buffer[7]     ];
  245|       |
  246|   330k|    buffer+=8;
  247|   330k|    size-=8;
  248|   330k|  }
  249|       |
  250|  41.4k|  while (size--)
  ------------------
  |  Branch (250:10): [True: 29.0k, False: 12.4k]
  ------------------
  251|  29.0k|    crc=(crc<<8)^crc_lookup[0][((crc >> 24)&0xff)^*buffer++];
  252|  12.4k|  return crc;
  253|  12.4k|}
framing.c:_os_body_expand:
  184|  1.61k|static int _os_body_expand(ogg_stream_state *os,long needed){
  185|  1.61k|  if(os->body_storage-needed<=os->body_fill){
  ------------------
  |  Branch (185:6): [True: 58, False: 1.55k]
  ------------------
  186|     58|    long body_storage;
  187|     58|    void *ret;
  188|     58|    if(os->body_storage>LONG_MAX-needed){
  ------------------
  |  Branch (188:8): [True: 0, False: 58]
  ------------------
  189|      0|      ogg_stream_clear(os);
  190|      0|      return -1;
  191|      0|    }
  192|     58|    body_storage=os->body_storage+needed;
  193|     58|    if(body_storage<LONG_MAX-1024)body_storage+=1024;
  ------------------
  |  Branch (193:8): [True: 58, False: 0]
  ------------------
  194|     58|    ret=_ogg_realloc(os->body_data,body_storage*sizeof(*os->body_data));
  ------------------
  |  |   23|     58|#define _ogg_realloc realloc
  ------------------
  195|     58|    if(!ret){
  ------------------
  |  Branch (195:8): [True: 0, False: 58]
  ------------------
  196|      0|      ogg_stream_clear(os);
  197|      0|      return -1;
  198|      0|    }
  199|     58|    os->body_storage=body_storage;
  200|     58|    os->body_data=ret;
  201|     58|  }
  202|  1.61k|  return 0;
  203|  1.61k|}
framing.c:_os_lacing_expand:
  205|  4.72k|static int _os_lacing_expand(ogg_stream_state *os,long needed){
  206|  4.72k|  if(os->lacing_storage-needed<=os->lacing_fill){
  ------------------
  |  Branch (206:6): [True: 0, False: 4.72k]
  ------------------
  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.72k|  return 0;
  231|  4.72k|}
framing.c:_packetout:
  944|  14.9k|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|  14.9k|  int ptr=os->lacing_returned;
  951|       |
  952|  14.9k|  if(os->lacing_packet<=ptr)return(0);
  ------------------
  |  Branch (952:6): [True: 2.68k, False: 12.2k]
  ------------------
  953|       |
  954|  12.2k|  if(os->lacing_vals[ptr]&0x400){
  ------------------
  |  Branch (954:6): [True: 3.54k, False: 8.71k]
  ------------------
  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|  8.71k|  if(!op && !adv)return(1); /* just using peek as an inexpensive way
  ------------------
  |  Branch (962:6): [True: 0, False: 8.71k]
  |  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|  8.71k|  {
  968|  8.71k|    int size=os->lacing_vals[ptr]&0xff;
  969|  8.71k|    long bytes=size;
  970|  8.71k|    int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  971|  8.71k|    int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  972|       |
  973|  11.1k|    while(size==255){
  ------------------
  |  Branch (973:11): [True: 2.40k, False: 8.71k]
  ------------------
  974|  2.40k|      int val=os->lacing_vals[++ptr];
  975|  2.40k|      size=val&0xff;
  976|  2.40k|      if(val&0x200)eos=0x200;
  ------------------
  |  Branch (976:10): [True: 205, False: 2.20k]
  ------------------
  977|  2.40k|      bytes+=size;
  978|  2.40k|    }
  979|       |
  980|  8.71k|    if(op){
  ------------------
  |  Branch (980:8): [True: 8.71k, False: 0]
  ------------------
  981|  8.71k|      op->e_o_s=eos;
  982|  8.71k|      op->b_o_s=bos;
  983|  8.71k|      op->packet=os->body_data+os->body_returned;
  984|  8.71k|      op->packetno=os->packetno;
  985|  8.71k|      op->granulepos=os->granule_vals[ptr];
  986|  8.71k|      op->bytes=bytes;
  987|  8.71k|    }
  988|       |
  989|  8.71k|    if(adv){
  ------------------
  |  Branch (989:8): [True: 8.71k, False: 0]
  ------------------
  990|  8.71k|      os->body_returned+=bytes;
  991|  8.71k|      os->lacing_returned=ptr+1;
  992|  8.71k|      os->packetno++;
  993|  8.71k|    }
  994|  8.71k|  }
  995|  8.71k|  return(1);
  996|  8.71k|}

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

