#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__ {
  size_t avail_in;
  unsigned char *next_in;
  size_t avail_out;
  int /*<<< orphan*/ *next_out;
  void *opaque;
  void *zfree;
  void *zalloc;
};
typedef TYPE_1__ z_stream;
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ Bytef;

/* Variables and functions */
int /*<<< orphan*/ Z_FINISH;
void *Z_NULL;
scalar_t__ Z_OK;
scalar_t__ Z_STREAM_ERROR;
scalar_t__ inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
scalar_t__ inflateInit(TYPE_1__ *);
int /*<<< orphan*/ memcpy(void *, char const *, size_t);
int cl_zlib_decompress_data(void *out_data, size_t out_size,
                            const void *in_data, size_t in_size) {
  z_stream strm;
  if (!((uint8_t *)in_data)[0]) {
    memcpy(out_data, ((const char *)in_data) + 1, in_size - 1);
    return in_size - 1;
  }
  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 -1;
  strm.avail_in = in_size - 1;
  strm.next_in = ((unsigned char *)in_data) + 1;
  strm.avail_out = out_size;
  strm.next_out = (Bytef *)out_data;
  if (inflate(&strm, Z_FINISH) == Z_STREAM_ERROR) {
    inflateEnd(&strm);
    return -2;
  }
  return out_size - strm.avail_out;
}


x86 assembly (clang, -O0):
<cl_zlib_decompress_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jne    118e <cl_zlib_decompress_data+0x4e>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
mov    -0x28(%rbp),%rdx
sub    $0x1,%rdx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x4(%rbp)
jmp    125d <cl_zlib_decompress_data+0x11d>
mov    0x2e3b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x60(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
lea    -0x60(%rbp),%rdi
call   1040 <inflateInit@plt>
mov    0x2e12(%rip),%rcx
cmp    (%rcx),%rax
je     11f3 <cl_zlib_decompress_data+0xb3>
movl   $0xffffffff,-0x4(%rbp)
jmp    125d <cl_zlib_decompress_data+0x11d>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
lea    -0x60(%rbp),%rdi
call   1030 <inflate@plt>
mov    0x2da4(%rip),%rcx
cmp    (%rcx),%rax
jne    1252 <cl_zlib_decompress_data+0x112>
lea    -0x60(%rbp),%rdi
call   1060 <inflateEnd@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    125d <cl_zlib_decompress_data+0x11d>
mov    -0x18(%rbp),%rax
sub    -0x50(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cl_zlib_decompress_data>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rdi,%r12
cmpl   $0x0,(%rdx)
je     11e9 <cl_zlib_decompress_data+0xa9>
mov    %rsi,%r14
mov    0x2e69(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
mov    %rax,0x28(%rsp)
mov    %rax,0x20(%rsp)
movq   $0x0,(%rsp)
mov    %rax,0x8(%rsp)
mov    %rsp,%rdi
call   1040 <inflateInit@plt>
mov    %rax,%rcx
mov    0x2e58(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%rcx
jne    120c <cl_zlib_decompress_data+0xcc>
add    $0xffffffffffffffff,%r15
mov    %r15,(%rsp)
add    $0x1,%rbx
mov    %rbx,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %r12,0x18(%rsp)
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1030 <inflate@plt>
mov    0x2e03(%rip),%rcx
cmp    (%rcx),%rax
jne    1204 <cl_zlib_decompress_data+0xc4>
mov    %rsp,%rdi
call   1060 <inflateEnd@plt>
mov    $0xfffffffe,%eax
jmp    120c <cl_zlib_decompress_data+0xcc>
add    $0x1,%rbx
add    $0xffffffffffffffff,%r15
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
mov    %r15d,%eax
jmp    120c <cl_zlib_decompress_data+0xcc>
sub    0x10(%rsp),%r14d
mov    %r14d,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i64, i8*, i64, i32*, i8*, i8*, i8* }
@Z_NULL = global i8* null
@Z_OK = global i64 0
@Z_FINISH = global i32 0
@Z_STREAM_ERROR = global i64 0
define i32 @cl_zlib_decompress_data(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca %struct.TYPE_5__
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%11 = load i8*, i8** %8
%12 = bitcast i8* %11 to i32*
%13 = getelementptr inbounds i32, i32* %12, i64 0
%14 = load i32, i32* %13
%15 = icmp ne i32 %14, 0
br i1 %15, label %26, label %16
16: ; preds = %4
%17 = load i8*, i8** %6
%18 = load i8*, i8** %8
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i64, i64* %9
%21 = sub i64 %20, 1
%22 = call i32 @memcpy(i8* %17, i8* %19, i64 %21)
%23 = load i64, i64* %9
%24 = sub i64 %23, 1
%25 = trunc i64 %24 to i32
store i32 %25, i32* %5
br label %64
26: ; preds = %4
%27 = load i8*, i8** @Z_NULL
%28 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 6
store i8* %27, i8** %28
%29 = load i8*, i8** @Z_NULL
%30 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 5
store i8* %29, i8** %30
%31 = load i8*, i8** @Z_NULL
%32 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 4
store i8* %31, i8** %32
%33 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 0
store i64 0, i64* %33
%34 = load i8*, i8** @Z_NULL
%35 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 1
store i8* %34, i8** %35
%36 = call i64 @inflateInit(%struct.TYPE_5__* %10)
%37 = load i64, i64* @Z_OK
%38 = icmp ne i64 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %26
store i32 -1, i32* %5
br label %64
40: ; preds = %26
%41 = load i64, i64* %9
%42 = sub i64 %41, 1
%43 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 0
store i64 %42, i64* %43
%44 = load i8*, i8** %8
%45 = getelementptr inbounds i8, i8* %44, i64 1
%46 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 1
store i8* %45, i8** %46
%47 = load i64, i64* %7
%48 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 2
store i64 %47, i64* %48
%49 = load i8*, i8** %6
%50 = bitcast i8* %49 to i32*
%51 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 3
store i32* %50, i32** %51
%52 = load i32, i32* @Z_FINISH
%53 = call i64 @inflate(%struct.TYPE_5__* %10, i32 %52)
%54 = load i64, i64* @Z_STREAM_ERROR
%55 = icmp eq i64 %53, %54
br i1 %55, label %56, label %58
56: ; preds = %40
%57 = call i32 @inflateEnd(%struct.TYPE_5__* %10)
store i32 -2, i32* %5
br label %64
58: ; preds = %40
%59 = load i64, i64* %7
%60 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 2
%61 = load i64, i64* %60
%62 = sub i64 %59, %61
%63 = trunc i64 %62 to i32
store i32 %63, i32* %5
br label %64
64: ; preds = %58, %56, %39, %16
%65 = load i32, i32* %5
ret i32 %65
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i64, i8*, i64, i32*, i8*, i8*, i8* }
@Z_NULL = global i8* null
@Z_OK = global i64 0
@Z_FINISH = global i32 0
@Z_STREAM_ERROR = global i64 0
define i32 @cl_zlib_decompress_data(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca %struct.TYPE_5__
%6 = bitcast %struct.TYPE_5__* %5 to i8*
%7 = bitcast i8* %2 to i32*
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %4
%11 = getelementptr inbounds i8, i8* %2, i64 1
%12 = add i64 %3, -1
%13 = tail call i32 @memcpy(i8* %0, i8* %11, i64 %12)
%14 = trunc i64 %12 to i32
br label %41
15: ; preds = %4
%16 = load i8*, i8** @Z_NULL
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 6
store i8* %16, i8** %17
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 5
store i8* %16, i8** %18
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 4
store i8* %16, i8** %19
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 0
store i64 0, i64* %20
%21 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 1
store i8* %16, i8** %21
%22 = call i64 @inflateInit(%struct.TYPE_5__* %5)
%23 = load i64, i64* @Z_OK
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %41
25: ; preds = %15
%26 = add i64 %3, -1
store i64 %26, i64* %20
%27 = getelementptr inbounds i8, i8* %2, i64 1
store i8* %27, i8** %21
%28 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 2
store i64 %1, i64* %28
%29 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 3
%30 = bitcast i32** %29 to i8**
store i8* %0, i8** %30
%31 = load i32, i32* @Z_FINISH
%32 = call i64 @inflate(%struct.TYPE_5__* %5, i32 %31)
%33 = load i64, i64* @Z_STREAM_ERROR
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %25
%36 = call i32 @inflateEnd(%struct.TYPE_5__* %5)
br label %41
37: ; preds = %25
%38 = load i64, i64* %28
%39 = sub i64 %1, %38
%40 = trunc i64 %39 to i32
br label %41
41: ; preds = %15, %37, %35, %10
%42 = phi i32 [ -2, %35 ], [ %40, %37 ], [ %14, %10 ], [ -1, %15 ]
ret i32 %42
}