#!/usr/bin/perl -w
my $s;
$\=$/='OggS';
while (<>) {
    chomp;
    print,next if !$_;
    my ($l,$c,$d)=(23,0,1);
    map $l+=$_,unpack'C*',substr$_,22,1+unpack'C',substr$_,22;
    next unless eof;
    ($l-length)?$_=$s:print$s;
    local$\;
    $_^=v0.4; # flip EOS
    $c<<=1,$c^=$d*79764919,$d=1&$c>>31
	for 14..8*length;
    substr($_,18,4)^=pack'V',$c; # CRC fixup
    print,last;
} continue {
    print $s if $s;
    $s=$_;
}
