#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_6__ TYPE_1__;

/* Type definitions */
struct TYPE_6__ {
  unsigned char *next_in;
  int avail_out;
  unsigned char *next_out;
  scalar_t__ avail_in;
  void *opaque;
  void *zfree;
  void *zalloc;
};
typedef TYPE_1__ z_stream;
struct string {
  int dummy;
};
typedef int /*<<< orphan*/ strm;
typedef int /*<<< orphan*/ outbuf;

/* Variables and functions */
#define Z_DATA_ERROR 131
int /*<<< orphan*/ Z_FINISH;
#define Z_MEM_ERROR 130
#define Z_NEED_DICT 129
void *Z_NULL;
scalar_t__ Z_OK;
int Z_STREAM_END;
#define Z_STREAM_ERROR 128
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
scalar_t__ inflateInit(TYPE_1__ *);
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ string_concatb(struct string *, char *, int);
scalar_t__ string_get(struct string *);
scalar_t__ string_length(struct string *);
bool uncompress_inflate(struct string *compressed,
                        struct string *uncompressed) {
  int retval;
  z_stream strm;
  unsigned char outbuf[1024];
  int have;
  memset(&strm, 0, sizeof(strm));
  strm.zalloc = Z_NULL;
  strm.zfree = Z_NULL;
  strm.opaque = Z_NULL;
  strm.avail_in = 0;
  strm.next_in = Z_NULL;
  if (inflateInit(&strm) != Z_OK)
    return false;
  strm.avail_in = string_length(compressed);
  strm.next_in = (unsigned char *)string_get(compressed);
  do {
    strm.avail_out = sizeof(outbuf);
    strm.next_out = outbuf;
    retval = inflate(&strm, Z_FINISH);
    switch (retval) {
    case Z_STREAM_ERROR:
      return false;
      break;
    case Z_NEED_DICT:
      retval = Z_DATA_ERROR;
    case Z_DATA_ERROR:
    case Z_MEM_ERROR:
      (void)inflateEnd(&strm);
      return false;
    }
    have = sizeof(outbuf) - strm.avail_out;
    string_concatb(uncompressed, (char *)outbuf, have);
  } while (strm.avail_out == 0);
  (void)inflateEnd(&strm);
  if (retval != Z_STREAM_END) {
    fprintf(stderr, "decompression failed\n");
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<uncompress_inflate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    0x2dec(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
lea    -0x58(%rbp),%rdi
call   1050 <inflateInit@plt>
mov    0x2dfd(%rip),%rcx
cmp    (%rcx),%rax
je     1208 <uncompress_inflate+0x88>
movl   $0x0,-0x4(%rbp)
jmp    132e <uncompress_inflate+0x1ae>
mov    -0x10(%rbp),%rdi
call   1090 <string_length@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <string_get@plt>
mov    %rax,-0x58(%rbp)
movl   $0x400,-0x50(%rbp)
lea    -0x460(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d85(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x468(%rbp)
sub    $0x80,%eax
je     1291 <uncompress_inflate+0x111>
jmp    1262 <uncompress_inflate+0xe2>
mov    -0x468(%rbp),%eax
sub    $0x81,%eax
je     129d <uncompress_inflate+0x11d>
jmp    1278 <uncompress_inflate+0xf8>
mov    -0x468(%rbp),%eax
add    $0xffffff7e,%eax
sub    $0x2,%eax
jb     12a4 <uncompress_inflate+0x124>
jmp    12b9 <uncompress_inflate+0x139>
movl   $0x0,-0x4(%rbp)
jmp    132e <uncompress_inflate+0x1ae>
movl   $0x83,-0x1c(%rbp)
lea    -0x58(%rbp),%rdi
call   1070 <inflateEnd@plt>
movl   $0x0,-0x4(%rbp)
jmp    132e <uncompress_inflate+0x1ae>
movslq -0x50(%rbp),%rcx
mov    $0x400,%eax
sub    %rcx,%rax
mov    %eax,-0x464(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x460(%rbp),%rsi
mov    -0x464(%rbp),%edx
call   10a0 <string_concatb@plt>
cmpl   $0x0,-0x50(%rbp)
je     1222 <uncompress_inflate+0xa2>
lea    -0x58(%rbp),%rdi
call   1070 <inflateEnd@plt>
mov    -0x1c(%rbp),%eax
mov    0x2ce2(%rip),%rcx
cmp    (%rcx),%eax
je     1327 <uncompress_inflate+0x1a7>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
lea    0xcea(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    132e <uncompress_inflate+0x1ae>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<uncompress_inflate>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x448,%rsp
mov    %rsi,%r12
mov    %rdi,%rbp
lea    0x8(%rsp),%rbx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x38(%rsp)
mov    %rax,0x30(%rsp)
mov    %rax,0x28(%rsp)
movq   $0x0,0x20(%rsp)
mov    %rax,0x8(%rsp)
mov    %rbx,%rdi
call   1050 <inflateInit@plt>
mov    0x2e0c(%rip),%rcx
cmp    (%rcx),%rax
jne    12a8 <uncompress_inflate+0x128>
mov    %rbp,%rdi
call   1090 <string_length@plt>
mov    %rax,0x20(%rsp)
mov    %rbp,%rdi
call   1080 <string_get@plt>
mov    %rax,0x8(%rsp)
lea    0x40(%rsp),%rbp
mov    0x2dad(%rip),%r13
lea    0x8(%rsp),%r15
nopl   0x0(%rax,%rax,1)
movl   $0x400,0x10(%rsp)
mov    %rbp,0x18(%rsp)
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1030 <inflate@plt>
mov    %eax,%ebx
lea    -0x81(%rbx),%eax
cmp    $0x3,%eax
jb     129b <uncompress_inflate+0x11b>
cmp    $0x80,%ebx
je     12a8 <uncompress_inflate+0x128>
mov    $0x400,%edx
sub    0x10(%rsp),%edx
mov    %r12,%rdi
mov    %rbp,%rsi
call   10a0 <string_concatb@plt>
cmpl   $0x0,0x10(%rsp)
je     1220 <uncompress_inflate+0xa0>
lea    0x8(%rsp),%rdi
call   1070 <inflateEnd@plt>
mov    0x2d66(%rip),%rax
mov    $0x1,%r14d
cmp    (%rax),%ebx
je     12a8 <uncompress_inflate+0x128>
mov    0x2d45(%rip),%rax
mov    (%rax),%edi
lea    0xd6c(%rip),%rsi
call   1060 <fprintf@plt>
jmp    12a5 <uncompress_inflate+0x125>
lea    0x8(%rsp),%rdi
call   1070 <inflateEnd@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x448,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.string = type { i32 }
%struct.TYPE_6__ = type { i8*, i32, i8*, i64, i8*, i8*, i8* }
@Z_NULL = global i8* null
@Z_OK = global i64 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"decompression failed\0A\00"
define i32 @uncompress_inflate(%struct.string* %0, %struct.string* %1) {
%3 = alloca i32
%4 = alloca %struct.string*
%5 = alloca %struct.string*
%6 = alloca i32
%7 = alloca %struct.TYPE_6__
%8 = alloca [1024 x i8]
%9 = alloca i32
store %struct.string* %0, %struct.string** %4
store %struct.string* %1, %struct.string** %5
%10 = call i32 @memset(%struct.TYPE_6__* %7, i32 0, i32 56)
%11 = load i8*, i8** @Z_NULL
%12 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 6
store i8* %11, i8** %12
%13 = load i8*, i8** @Z_NULL
%14 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 5
store i8* %13, i8** %14
%15 = load i8*, i8** @Z_NULL
%16 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 4
store i8* %15, i8** %16
%17 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 3
store i64 0, i64* %17
%18 = load i8*, i8** @Z_NULL
%19 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 0
store i8* %18, i8** %19
%20 = call i64 @inflateInit(%struct.TYPE_6__* %7)
%21 = load i64, i64* @Z_OK
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %2
store i32 0, i32* %3
br label %66
24: ; preds = %2
%25 = load %struct.string*, %struct.string** %4
%26 = call i64 @string_length(%struct.string* %25)
%27 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 3
store i64 %26, i64* %27
%28 = load %struct.string*, %struct.string** %4
%29 = call i64 @string_get(%struct.string* %28)
%30 = inttoptr i64 %29 to i8*
%31 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 0
store i8* %30, i8** %31
br label %32
32: ; preds = %53, %24
%33 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
store i32 1024, i32* %33
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%35 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 2
store i8* %34, i8** %35
%36 = load i32, i32* @Z_FINISH
%37 = call i32 @inflate(%struct.TYPE_6__* %7, i32 %36)
store i32 %37, i32* %6
%38 = load i32, i32* %6
switch i32 %38, label %43 [
i32 128, label %39
i32 129, label %40
i32 131, label %41
i32 130, label %41
]
39: ; preds = %32
store i32 0, i32* %3
br label %66
40: ; preds = %32
store i32 131, i32* %6
br label %41
41: ; preds = %32, %32, %40
%42 = call i32 @inflateEnd(%struct.TYPE_6__* %7)
store i32 0, i32* %3
br label %66
43: ; preds = %32
%44 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%45 = load i32, i32* %44
%46 = sext i32 %45 to i64
%47 = sub i64 1024, %46
%48 = trunc i64 %47 to i32
store i32 %48, i32* %9
%49 = load %struct.string*, %struct.string** %5
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%51 = load i32, i32* %9
%52 = call i32 @string_concatb(%struct.string* %49, i8* %50, i32 %51)
br label %53
53: ; preds = %43
%54 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %7, i32 0, i32 1
%55 = load i32, i32* %54
%56 = icmp eq i32 %55, 0
br i1 %56, label %32, label %57
57: ; preds = %53
%58 = call i32 @inflateEnd(%struct.TYPE_6__* %7)
%59 = load i32, i32* %6
%60 = load i32, i32* @Z_STREAM_END
%61 = icmp ne i32 %59, %60
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = load i32, i32* @stderr
%64 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %66
65: ; preds = %57
store i32 1, i32* %3
br label %66
66: ; preds = %65, %62, %41, %39, %23
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
%struct.string = type { i32 }
%struct.TYPE_6__ = type { i8*, i32, i8*, i64, i8*, i8*, i8* }
@Z_NULL = global i8* null
@Z_OK = global i64 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"decompression failed\0A\00"
define i32 @uncompress_inflate(%struct.string* %0, %struct.string* %1) {
%3 = alloca %struct.TYPE_6__
%4 = alloca [1024 x i8]
%5 = bitcast %struct.TYPE_6__* %3 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(%struct.TYPE_6__* %3, i32 0, i32 56)
%8 = load i8*, i8** @Z_NULL
%9 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 6
store i8* %8, i8** %9
%10 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 5
store i8* %8, i8** %10
%11 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 4
store i8* %8, i8** %11
%12 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 3
store i64 0, i64* %12
%13 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 0
store i8* %8, i8** %13
%14 = call i64 @inflateInit(%struct.TYPE_6__* %3)
%15 = load i64, i64* @Z_OK
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %41
17: ; preds = %2
%18 = call i64 @string_length(%struct.string* %0)
store i64 %18, i64* %12
%19 = call i64 @string_get(%struct.string* %0)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %13
%21 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 2
br label %23
23: ; preds = %28, %17
store i32 1024, i32* %21
store i8* %6, i8** %22
%24 = load i32, i32* @Z_FINISH
%25 = call i32 @inflate(%struct.TYPE_6__* %3, i32 %24)
switch i32 %25, label %28 [
i32 128, label %41
i32 129, label %26
i32 131, label %26
i32 130, label %26
]
26: ; preds = %23, %23, %23
%27 = call i32 @inflateEnd(%struct.TYPE_6__* %3)
br label %41
28: ; preds = %23
%29 = load i32, i32* %21
%30 = sub i32 1024, %29
%31 = call i32 @string_concatb(%struct.string* %1, i8* %6, i32 %30)
%32 = load i32, i32* %21
%33 = icmp eq i32 %32, 0
br i1 %33, label %23, label %34
34: ; preds = %28
%35 = call i32 @inflateEnd(%struct.TYPE_6__* %3)
%36 = load i32, i32* @Z_STREAM_END
%37 = icmp eq i32 %25, %36
br i1 %37, label %41, label %38
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %41
41: ; preds = %23, %34, %2, %38, %26
%42 = phi i32 [ 0, %38 ], [ 0, %26 ], [ 0, %2 ], [ 1, %34 ], [ 0, %23 ]
ret i32 %42
}