#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
struct TYPE_5__ {
  unsigned int avail_in;
  int avail_out;
  int /*<<< orphan*/ *next_out;
  int /*<<< orphan*/ *next_in;
  void *opaque;
  void *zfree;
  void *zalloc;
};
typedef TYPE_1__ z_stream;
typedef int /*<<< orphan*/ Bytef;

/* Variables and functions */
#define Z_DATA_ERROR 131
#define Z_MEM_ERROR 130
#define Z_NEED_DICT 129
int /*<<< orphan*/ Z_NO_FLUSH;
void *Z_NULL;
int Z_OK;
#define Z_STREAM_ERROR 128
int /*<<< orphan*/ err_msg(char *, ...);
int fwrite(char *, int, int, int /*<<< orphan*/);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
int /*<<< orphan*/ stdout;
int dump_zipped_text(char *zipped_text, unsigned int zipped_length) {
  z_stream strm;
  int result;
  char unzipped_text[4096];
  strm.zalloc = Z_NULL;
  strm.zfree = Z_NULL;
  strm.opaque = Z_NULL;
  strm.avail_in = zipped_length;
  strm.next_in = (Bytef *)zipped_text;
  result = inflateInit(&strm);
  if (result != Z_OK) {
    err_msg("can't decompress text: inflateInit() returned %d\n", result);
    return -1;
  }
  do {
    strm.avail_out = 4096;
    strm.next_out = (Bytef *)unzipped_text;
    result = inflate(&strm, Z_NO_FLUSH);
    switch (result) {
    case Z_STREAM_ERROR:
    case Z_NEED_DICT:
    case Z_DATA_ERROR:
    case Z_MEM_ERROR:
      err_msg("can't decompress text: inflate() returned %d\n", result);
      (void)inflateEnd(&strm);
      return -1;
    }
    if (fwrite(unzipped_text, 4096 - strm.avail_out, 1, stdout) != 1) {
      err_msg("can't decompress text: fwrite() failed\n");
      (void)inflateEnd(&strm);
      return -1;
    }
  } while (strm.avail_out == 0);
  (void)inflateEnd(&strm);
  return 0;
}


x86 assembly (clang, -O0):
<dump_zipped_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x48(%rbp),%rdi
call   1040 <inflateInit@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%eax
je     11d5 <dump_zipped_text+0x85>
mov    -0x4c(%rbp),%esi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1060 <err_msg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a8 <dump_zipped_text+0x158>
jmp    11da <dump_zipped_text+0x8a>
movl   $0x1000,-0x44(%rbp)
lea    -0x1050(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2de5(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
add    $0xffffff80,%eax
sub    $0x3,%eax
ja     123b <dump_zipped_text+0xeb>
jmp    1215 <dump_zipped_text+0xc5>
mov    -0x4c(%rbp),%esi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1060 <err_msg@plt>
lea    -0x48(%rbp),%rdi
call   1050 <inflateEnd@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a8 <dump_zipped_text+0x158>
lea    -0x1050(%rbp),%rdi
mov    $0x1000,%esi
sub    -0x44(%rbp),%esi
mov    0x2d77(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
je     1289 <dump_zipped_text+0x139>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1060 <err_msg@plt>
lea    -0x48(%rbp),%rdi
call   1050 <inflateEnd@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a8 <dump_zipped_text+0x158>
jmp    128e <dump_zipped_text+0x13e>
cmpl   $0x0,-0x44(%rbp)
je     11da <dump_zipped_text+0x8a>
lea    -0x48(%rbp),%rdi
call   1050 <inflateEnd@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_zipped_text>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1038,%rsp
mov    0x2e6b(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x28(%rsp)
mov    %rax,0x20(%rsp)
mov    %rax,0x18(%rsp)
mov    %esi,(%rsp)
mov    %rdi,0x10(%rsp)
mov    %rsp,%rdi
call   1040 <inflateInit@plt>
mov    0x2e62(%rip),%rcx
cmp    (%rcx),%eax
jne    1207 <dump_zipped_text+0xb7>
lea    0x30(%rsp),%rbx
mov    0x2e3a(%rip),%r15
mov    %rsp,%r14
mov    0x2e20(%rip),%r12
nopl   0x0(%rax,%rax,1)
movl   $0x1000,0x4(%rsp)
mov    %rbx,0x8(%rsp)
mov    (%r15),%esi
mov    %r14,%rdi
call   1030 <inflate@plt>
mov    %eax,%ecx
and    $0xfffffffc,%ecx
cmp    $0x80,%ecx
je     1219 <dump_zipped_text+0xc9>
mov    $0x1000,%esi
sub    0x4(%rsp),%esi
mov    (%r12),%ecx
mov    %rbx,%rdi
mov    $0x1,%edx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
jne    122b <dump_zipped_text+0xdb>
cmpl   $0x0,0x4(%rsp)
je     11b0 <dump_zipped_text+0x60>
mov    %rsp,%rdi
call   1050 <inflateEnd@plt>
xor    %eax,%eax
jmp    1246 <dump_zipped_text+0xf6>
lea    0xdf2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <err_msg@plt>
jmp    1241 <dump_zipped_text+0xf1>
lea    0xe12(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <err_msg@plt>
jmp    1239 <dump_zipped_text+0xe9>
lea    0xe2e(%rip),%rdi
xor    %eax,%eax
call   1060 <err_msg@plt>
mov    %rsp,%rdi
call   1050 <inflateEnd@plt>
mov    $0xffffffff,%eax
add    $0x1038,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i32, i32*, i32*, i8*, i8*, i8* }
@Z_NULL = global i8* null
@Z_OK = global i32 0
@.str = [50 x i8] c"can't decompress text: inflateInit() returned %d\0A\00"
@Z_NO_FLUSH = global i32 0
@.str.1 = [46 x i8] c"can't decompress text: inflate() returned %d\0A\00"
@stdout = global i32 0
@.str.2 = [40 x i8] c"can't decompress text: fwrite() failed\0A\00"
define i32 @dump_zipped_text(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.TYPE_5__
%7 = alloca i32
%8 = alloca [4096 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** @Z_NULL
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 6
store i8* %9, i8** %10
%11 = load i8*, i8** @Z_NULL
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 5
store i8* %11, i8** %12
%13 = load i8*, i8** @Z_NULL
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 4
store i8* %13, i8** %14
%15 = load i32, i32* %5
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 0
store i32 %15, i32* %16
%17 = load i8*, i8** %4
%18 = bitcast i8* %17 to i32*
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 3
store i32* %18, i32** %19
%20 = call i32 @inflateInit(%struct.TYPE_5__* %6)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = load i32, i32* @Z_OK
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %27
24: ; preds = %2
%25 = load i32, i32* %7
%26 = call i32 (i8*, ...) @err_msg(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %25)
store i32 -1, i32* %3
br label %58
27: ; preds = %2
br label %28
28: ; preds = %52, %27
%29 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
store i32 4096, i32* %29
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%31 = bitcast i8* %30 to i32*
%32 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 2
store i32* %31, i32** %32
%33 = load i32, i32* @Z_NO_FLUSH
%34 = call i32 @inflate(%struct.TYPE_5__* %6, i32 %33)
store i32 %34, i32* %7
%35 = load i32, i32* %7
switch i32 %35, label %40 [
i32 128, label %36
i32 129, label %36
i32 131, label %36
i32 130, label %36
]
36: ; preds = %28, %28, %28, %28
%37 = load i32, i32* %7
%38 = call i32 (i8*, ...) @err_msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = call i32 @inflateEnd(%struct.TYPE_5__* %6)
store i32 -1, i32* %3
br label %58
40: ; preds = %28
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%42 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
%43 = load i32, i32* %42
%44 = sub nsw i32 4096, %43
%45 = load i32, i32* @stdout
%46 = call i32 @fwrite(i8* %41, i32 %44, i32 1, i32 %45)
%47 = icmp ne i32 %46, 1
br i1 %47, label %48, label %51
48: ; preds = %40
%49 = call i32 (i8*, ...) @err_msg(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @inflateEnd(%struct.TYPE_5__* %6)
store i32 -1, i32* %3
br label %58
51: ; preds = %40
br label %52
52: ; preds = %51
%53 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i32 0, i32 1
%54 = load i32, i32* %53
%55 = icmp eq i32 %54, 0
br i1 %55, label %28, label %56
56: ; preds = %52
%57 = call i32 @inflateEnd(%struct.TYPE_5__* %6)
store i32 0, i32* %3
br label %58
58: ; preds = %56, %48, %36, %24
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i32, i32*, i32*, i8*, i8*, i8* }
@Z_NULL = global i8* null
@Z_OK = global i32 0
@.str = [50 x i8] c"can't decompress text: inflateInit() returned %d\0A\00"
@Z_NO_FLUSH = global i32 0
@.str.1 = [46 x i8] c"can't decompress text: inflate() returned %d\0A\00"
@stdout = global i32 0
@.str.2 = [40 x i8] c"can't decompress text: fwrite() failed\0A\00"
define i32 @dump_zipped_text(i8* %0, i32 %1) {
%3 = alloca %struct.TYPE_5__
%4 = alloca [4096 x i8]
%5 = bitcast %struct.TYPE_5__* %3 to i8*
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = load i8*, i8** @Z_NULL
%8 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 6
store i8* %7, i8** %8
%9 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 5
store i8* %7, i8** %9
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 4
store i8* %7, i8** %10
%11 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 0
store i32 %1, i32* %11
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 3
%13 = bitcast i32** %12 to i8**
store i8* %0, i8** %13
%14 = call i32 @inflateInit(%struct.TYPE_5__* %3)
%15 = load i32, i32* @Z_OK
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 1
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i64 0, i32 2
%20 = bitcast i32** %19 to [4096 x i8]**
br label %23
21: ; preds = %2
%22 = call i32 (i8*, ...) @err_msg(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %14)
br label %45
23: ; preds = %17, %40
store i32 4096, i32* %18
store [4096 x i8]* %4, [4096 x i8]** %20
%24 = load i32, i32* @Z_NO_FLUSH
%25 = call i32 @inflate(%struct.TYPE_5__* %3, i32 %24)
%26 = and i32 %25, -4
%27 = icmp eq i32 %26, 128
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = call i32 (i8*, ...) @err_msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%30 = call i32 @inflateEnd(%struct.TYPE_5__* %3)
br label %45
31: ; preds = %23
%32 = load i32, i32* %18
%33 = sub nsw i32 4096, %32
%34 = load i32, i32* @stdout
%35 = call i32 @fwrite(i8* %6, i32 %33, i32 1, i32 %34)
%36 = icmp eq i32 %35, 1
br i1 %36, label %40, label %37
37: ; preds = %31
%38 = call i32 (i8*, ...) @err_msg(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @inflateEnd(%struct.TYPE_5__* %3)
br label %45
40: ; preds = %31
%41 = load i32, i32* %18
%42 = icmp eq i32 %41, 0
br i1 %42, label %23, label %43
43: ; preds = %40
%44 = call i32 @inflateEnd(%struct.TYPE_5__* %3)
br label %45
45: ; preds = %43, %37, %28, %21
%46 = phi i32 [ -1, %21 ], [ -1, %37 ], [ 0, %43 ], [ -1, %28 ]
ret i32 %46
}