CreateZStream (gint compress, guchar gzip, gint (*read_write_func) (guchar *, gint, void *) func, void * gchandle)
{
  struct ZStream * D.6208;
  int iftmp.0;
  int iftmp.1;
  unsigned char D.6222;
  void * D.6223;
  struct z_stream * z;
  gint retval;
  struct ZStream * result;

  if (func == 0B) goto <D.6206>; else goto <D.6207>;
  <D.6206>:
  D.6208 = 0B;
  return D.6208;
  <D.6207>:
  z = monoeg_malloc0 (112);
  if (compress != 0) goto <D.6209>; else goto <D.6210>;
  <D.6209>:
  if (gzip != 0) goto <D.6212>; else goto <D.6213>;
  <D.6212>:
  iftmp.0 = 31;
  goto <D.6214>;
  <D.6213>:
  iftmp.0 = -15;
  <D.6214>:
  retval = deflateInit2_ (z, -1, 8, iftmp.0, 8, 0, "1.2.5", 112);
  goto <D.6215>;
  <D.6210>:
  if (gzip != 0) goto <D.6217>; else goto <D.6218>;
  <D.6217>:
  iftmp.1 = 31;
  goto <D.6219>;
  <D.6218>:
  iftmp.1 = -15;
  <D.6219>:
  retval = inflateInit2_ (z, iftmp.1, "1.2.5", 112);
  <D.6215>:
  if (retval != 0) goto <D.6220>; else goto <D.6221>;
  <D.6220>:
  monoeg_g_free (z);
  D.6208 = 0B;
  return D.6208;
  <D.6221>:
  z->zalloc = z_alloc;
  z->zfree = z_free;
  result = monoeg_malloc0 (40);
  result->stream = z;
  result->func = func;
  result->gchandle = gchandle;
  D.6222 = (unsigned char) compress;
  result->compress = D.6222;
  D.6223 = monoeg_malloc (4096);
  result->buffer = D.6223;
  D.6208 = result;
  return D.6208;
}


z_free (void * opaque, void * ptr)
{
  monoeg_g_free (ptr);
}


z_alloc (void * opaque, gsize nitems, gsize item_size)
{
  void * D.6225;
  long unsigned int D.6226;

  D.6226 = nitems * item_size;
  D.6225 = monoeg_malloc0 (D.6226);
  return D.6225;
}


CloseZStream (struct ZStream * zstream)
{
  gint D.6230;
  unsigned char D.6231;
  struct z_stream * D.6234;
  long unsigned int D.6235;
  guchar * D.6241;
  gint status;
  gint flush_status;

  if (zstream == 0B) goto <D.6228>; else goto <D.6229>;
  <D.6228>:
  D.6230 = -10;
  return D.6230;
  <D.6229>:
  status = 0;
  D.6231 = zstream->compress;
  if (D.6231 != 0) goto <D.6232>; else goto <D.6233>;
  <D.6232>:
  D.6234 = zstream->stream;
  D.6235 = D.6234->total_in;
  if (D.6235 != 0) goto <D.6236>; else goto <D.6237>;
  <D.6236>:
  <D.6168>:
  D.6234 = zstream->stream;
  status = deflate (D.6234, 4);
  flush_status = flush_internal (zstream, 1);
  if (status == 0) goto <D.6168>; else goto <D.6169>;
  <D.6169>:
  if (status == 1) goto <D.6238>; else goto <D.6239>;
  <D.6238>:
  status = flush_status;
  <D.6239>:
  <D.6237>:
  D.6234 = zstream->stream;
  deflateEnd (D.6234);
  goto <D.6240>;
  <D.6233>:
  D.6234 = zstream->stream;
  inflateEnd (D.6234);
  <D.6240>:
  D.6241 = zstream->buffer;
  monoeg_g_free (D.6241);
  D.6234 = zstream->stream;
  monoeg_g_free (D.6234);
  memset (zstream, 0, 40);
  monoeg_g_free (zstream);
  D.6230 = status;
  return D.6230;
}


flush_internal (struct ZStream * stream, gboolean is_final)
{
  unsigned char D.6243;
  gint D.6246;
  struct z_stream * D.6249;
  unsigned int status.2;
  gint status;

  D.6243 = stream->compress;
  if (D.6243 == 0) goto <D.6244>; else goto <D.6245>;
  <D.6244>:
  D.6246 = 0;
  return D.6246;
  <D.6245>:
  if (is_final == 0) goto <D.6247>; else goto <D.6248>;
  <D.6247>:
  D.6249 = stream->stream;
  status = deflate (D.6249, 1);
  status.2 = (unsigned int) status;
  if (status.2 > 1) goto <D.6251>; else goto <D.6252>;
  <D.6251>:
  D.6246 = status;
  return D.6246;
  <D.6252>:
  <D.6248>:
  D.6246 = write_to_managed (stream);
  return D.6246;
}


write_to_managed (struct ZStream * stream)
{
  unsigned int D.6254;
  gint (*<T11bf>) (guchar *, gint, void *) D.6257;
  void * D.6258;
  unsigned int D.6259;
  int D.6260;
  guchar * D.6261;
  gint D.6264;
  gint n;
  struct z_stream * zs;

  zs = stream->stream;
  D.6254 = zs->avail_out;
  if (D.6254 != 4096) goto <D.6255>; else goto <D.6256>;
  <D.6255>:
  D.6257 = stream->func;
  D.6258 = stream->gchandle;
  D.6254 = zs->avail_out;
  D.6259 = 4096 - D.6254;
  D.6260 = (int) D.6259;
  D.6261 = stream->buffer;
  n = D.6257 (D.6261, D.6260, D.6258);
  D.6261 = stream->buffer;
  zs->next_out = D.6261;
  zs->avail_out = 4096;
  if (n < 0) goto <D.6262>; else goto <D.6263>;
  <D.6262>:
  D.6264 = -11;
  return D.6264;
  <D.6263>:
  <D.6256>:
  D.6264 = 0;
  return D.6264;
}


memset (void * __dest, int __ch, size_t __len)
{
  int D.6268;
  int D.6273;
  void * D.6275;
  long unsigned int D.6276;

  D.6268 = __builtin_constant_p (__len);
  if (D.6268 != 0) goto <D.6269>; else goto <D.6270>;
  <D.6269>:
  if (__len == 0) goto <D.6271>; else goto <D.6272>;
  <D.6271>:
  D.6273 = __builtin_constant_p (__ch);
  if (D.6273 == 0) goto <D.6266>; else goto <D.6274>;
  <D.6274>:
  if (__ch != 0) goto <D.6266>; else goto <D.6267>;
  <D.6266>:
  __warn_memset_zero_len ();
  D.6275 = __dest;
  return D.6275;
  <D.6267>:
  <D.6272>:
  <D.6270>:
  D.6276 = __builtin_object_size (__dest, 0);
  D.6275 = __builtin___memset_chk (__dest, __ch, __len, D.6276);
  return D.6275;
}


Flush (struct ZStream * stream)
{
  gint D.6278;

  D.6278 = flush_internal (stream, 0);
  return D.6278;
}


ReadZStream (struct ZStream * stream, guchar * buffer, gint length)
{
  _Bool D.6282;
  _Bool D.6283;
  _Bool D.6284;
  gint D.6286;
  unsigned char D.6287;
  unsigned int length.3;
  unsigned int D.6291;
  gint (*<T11bf>) (guchar *, gint, void *) D.6294;
  void * D.6295;
  guchar * D.6296;
  unsigned int n.4;
  struct z_stream * D.6300;
  unsigned int D.6305;
  unsigned int D.6306;
  gint n;
  gint status;
  struct z_stream * zs;

  D.6282 = stream == 0B;
  D.6283 = buffer == 0B;
  D.6284 = D.6282 | D.6283;
  if (D.6284 != 0) goto <D.6280>; else goto <D.6285>;
  <D.6285>:
  if (length < 0) goto <D.6280>; else goto <D.6281>;
  <D.6280>:
  D.6286 = -10;
  return D.6286;
  <D.6281>:
  D.6287 = stream->eof;
  if (D.6287 != 0) goto <D.6288>; else goto <D.6289>;
  <D.6288>:
  D.6286 = 0;
  return D.6286;
  <D.6289>:
  zs = stream->stream;
  zs->next_out = buffer;
  length.3 = (unsigned int) length;
  zs->avail_out = length.3;
  goto <D.6193>;
  <D.6192>:
  D.6291 = zs->avail_in;
  if (D.6291 == 0) goto <D.6292>; else goto <D.6293>;
  <D.6292>:
  D.6294 = stream->func;
  D.6295 = stream->gchandle;
  D.6296 = stream->buffer;
  n = D.6294 (D.6296, 4096, D.6295);
  if (n <= 0) goto <D.6297>; else goto <D.6298>;
  <D.6297>:
  stream->eof = 1;
  goto <D.6191>;
  <D.6298>:
  D.6296 = stream->buffer;
  zs->next_in = D.6296;
  n.4 = (unsigned int) n;
  zs->avail_in = n.4;
  <D.6293>:
  D.6300 = stream->stream;
  status = inflate (D.6300, 2);
  if (status == 1) goto <D.6301>; else goto <D.6302>;
  <D.6301>:
  stream->eof = 1;
  goto <D.6191>;
  <D.6302>:
  if (status != 0) goto <D.6303>; else goto <D.6304>;
  <D.6303>:
  D.6286 = status;
  return D.6286;
  <D.6304>:
  <D.6193>:
  D.6305 = zs->avail_out;
  if (D.6305 != 0) goto <D.6192>; else goto <D.6191>;
  <D.6191>:
  length.3 = (unsigned int) length;
  D.6305 = zs->avail_out;
  D.6306 = length.3 - D.6305;
  D.6286 = (gint) D.6306;
  return D.6286;
}


WriteZStream (struct ZStream * stream, guchar * buffer, gint length)
{
  _Bool D.6310;
  _Bool D.6311;
  _Bool D.6312;
  gint D.6314;
  unsigned char D.6315;
  unsigned int length.5;
  unsigned int D.6319;
  guchar * D.6322;
  struct z_stream * D.6323;
  unsigned int status.6;
  unsigned int D.6331;
  gint n;
  gint status;
  struct z_stream * zs;

  D.6310 = stream == 0B;
  D.6311 = buffer == 0B;
  D.6312 = D.6310 | D.6311;
  if (D.6312 != 0) goto <D.6308>; else goto <D.6313>;
  <D.6313>:
  if (length < 0) goto <D.6308>; else goto <D.6309>;
  <D.6308>:
  D.6314 = -10;
  return D.6314;
  <D.6309>:
  D.6315 = stream->eof;
  if (D.6315 != 0) goto <D.6316>; else goto <D.6317>;
  <D.6316>:
  D.6314 = -11;
  return D.6314;
  <D.6317>:
  zs = stream->stream;
  zs->next_in = buffer;
  length.5 = (unsigned int) length;
  zs->avail_in = length.5;
  goto <D.6203>;
  <D.6202>:
  D.6319 = zs->avail_out;
  if (D.6319 == 0) goto <D.6320>; else goto <D.6321>;
  <D.6320>:
  D.6322 = stream->buffer;
  zs->next_out = D.6322;
  zs->avail_out = 4096;
  <D.6321>:
  D.6323 = stream->stream;
  status = deflate (D.6323, 0);
  status.6 = (unsigned int) status;
  if (status.6 > 1) goto <D.6325>; else goto <D.6326>;
  <D.6325>:
  D.6314 = status;
  return D.6314;
  <D.6326>:
  D.6319 = zs->avail_out;
  if (D.6319 == 0) goto <D.6327>; else goto <D.6328>;
  <D.6327>:
  n = write_to_managed (stream);
  if (n < 0) goto <D.6329>; else goto <D.6330>;
  <D.6329>:
  D.6314 = n;
  return D.6314;
  <D.6330>:
  <D.6328>:
  <D.6203>:
  D.6331 = zs->avail_in;
  if (D.6331 != 0) goto <D.6202>; else goto <D.6204>;
  <D.6204>:
  D.6314 = length;
  return D.6314;
}


