#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;
  size_t avail_out;
  int /*<<< orphan*/ *next_out;
  int /*<<< orphan*/ *next_in;
};
typedef TYPE_1__ z_stream;
typedef int /*<<< orphan*/ uint8_t;
typedef size_t ptrdiff_t;

/* Variables and functions */
int Z_BUF_ERROR;
int /*<<< orphan*/ Z_FINISH;
int Z_OK;
int Z_STREAM_END;
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
int inflateInit2(TYPE_1__ *, int);
int decompress_buffer(uint8_t *dst, size_t dst_size, const uint8_t *src,
                      size_t src_size) {
  ptrdiff_t out_len;
  int ret;
  z_stream strm = {
      .next_in = (uint8_t *)src,
      .avail_in = src_size,
      .next_out = dst,
      .avail_out = dst_size,
  };
  ret = inflateInit2(&strm, -12);
  if (ret != Z_OK)
    return -1;
  ret = inflate(&strm, Z_FINISH);
  out_len = strm.next_out - dst;
  if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) || out_len != dst_size) {
    inflateEnd(&strm);
    return -1;
  }
  inflateEnd(&strm);
  return 0;
}


x86 assembly (clang, -O0):
<decompress_buffer>:
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    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    -0x58(%rbp),%rdi
mov    $0xfffffff4,%esi
call   1040 <inflateInit2@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%eax
je     1197 <decompress_buffer+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <decompress_buffer+0xe6>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x34(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
sar    $0x2,%rax
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2e17(%rip),%rcx
cmp    (%rcx),%eax
je     11e3 <decompress_buffer+0xb3>
mov    -0x34(%rbp),%eax
mov    0x2dfd(%rip),%rcx
cmp    (%rcx),%eax
jne    11f1 <decompress_buffer+0xc1>
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1206 <decompress_buffer+0xd6>
lea    -0x58(%rbp),%rdi
call   1050 <inflateEnd@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <decompress_buffer+0xe6>
lea    -0x58(%rbp),%rdi
call   1050 <inflateEnd@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decompress_buffer>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rcx,(%rsp)
mov    %rsi,0x8(%rsp)
mov    %rdi,0x10(%rsp)
mov    %rdx,0x18(%rsp)
mov    %rsp,%rdi
mov    $0xfffffff4,%esi
call   1040 <inflateInit2@plt>
mov    %eax,%ecx
mov    0x2e88(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%ecx
jne    11c0 <decompress_buffer+0x90>
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r15
mov    %r15,%rdi
call   1030 <inflate@plt>
mov    0x10(%rsp),%rcx
sub    %rbx,%rcx
sar    $0x2,%rcx
mov    0x2e48(%rip),%rdx
cmp    (%rdx),%eax
setne  %dl
mov    0x2e34(%rip),%rsi
cmp    (%rsi),%eax
setne  %al
and    %dl,%al
cmp    %r14,%rcx
setne  %bl
or     %al,%bl
mov    %r15,%rdi
call   1050 <inflateEnd@plt>
movzbl %bl,%eax
neg    %eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i64, i64, i32*, i32* }
@Z_OK = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@Z_BUF_ERROR = global i32 0
define i32 @decompress_buffer(i32* %0, i64 %1, i32* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca %struct.TYPE_5__
store i32* %0, i32** %6
store i64 %1, i64* %7
store i32* %2, i32** %8
store i64 %3, i64* %9
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 0
%14 = load i64, i64* %9
store i64 %14, i64* %13
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
%16 = load i64, i64* %7
store i64 %16, i64* %15
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 2
%18 = load i32*, i32** %6
store i32* %18, i32** %17
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 3
%20 = load i32*, i32** %8
store i32* %20, i32** %19
%21 = call i32 @inflateInit2(%struct.TYPE_5__* %12, i32 -12)
store i32 %21, i32* %11
%22 = load i32, i32* %11
%23 = load i32, i32* @Z_OK
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %4
store i32 -1, i32* %5
br label %51
26: ; preds = %4
%27 = load i32, i32* @Z_FINISH
%28 = call i32 @inflate(%struct.TYPE_5__* %12, i32 %27)
store i32 %28, i32* %11
%29 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 2
%30 = load i32*, i32** %29
%31 = load i32*, i32** %6
%32 = ptrtoint i32* %30 to i64
%33 = ptrtoint i32* %31 to i64
%34 = sub i64 %32, %33
%35 = sdiv exact i64 %34, 4
store i64 %35, i64* %10
%36 = load i32, i32* %11
%37 = load i32, i32* @Z_STREAM_END
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %43
39: ; preds = %26
%40 = load i32, i32* %11
%41 = load i32, i32* @Z_BUF_ERROR
%42 = icmp ne i32 %40, %41
br i1 %42, label %47, label %43
43: ; preds = %39, %26
%44 = load i64, i64* %10
%45 = load i64, i64* %7
%46 = icmp ne i64 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %43, %39
%48 = call i32 @inflateEnd(%struct.TYPE_5__* %12)
store i32 -1, i32* %5
br label %51
49: ; preds = %43
%50 = call i32 @inflateEnd(%struct.TYPE_5__* %12)
store i32 0, i32* %5
br label %51
51: ; preds = %49, %47, %25
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i64, i64, i32*, i32* }
@Z_OK = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@Z_BUF_ERROR = global i32 0
define i32 @decompress_buffer(i32* %0, i64 %1, i32* %2, i64 %3) {
%5 = alloca %struct.TYPE_5__
%6 = bitcast %struct.TYPE_5__* %5 to i8*
%7 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 0
store i64 %3, i64* %7
%8 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 1
store i64 %1, i64* %8
%9 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 2
store i32* %0, i32** %9
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 3
store i32* %2, i32** %10
%11 = call i32 @inflateInit2(%struct.TYPE_5__* %5, i32 -12)
%12 = load i32, i32* @Z_OK
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %31
14: ; preds = %4
%15 = load i32, i32* @Z_FINISH
%16 = call i32 @inflate(%struct.TYPE_5__* %5, i32 %15)
%17 = load i32*, i32** %9
%18 = ptrtoint i32* %17 to i64
%19 = ptrtoint i32* %0 to i64
%20 = sub i64 %18, %19
%21 = ashr exact i64 %20, 2
%22 = load i32, i32* @Z_STREAM_END
%23 = icmp ne i32 %16, %22
%24 = load i32, i32* @Z_BUF_ERROR
%25 = icmp ne i32 %16, %24
%26 = select i1 %23, i1 %25, i1 false
%27 = icmp ne i64 %21, %1
%28 = select i1 %26, i1 true, i1 %27
%29 = call i32 @inflateEnd(%struct.TYPE_5__* %5)
%30 = sext i1 %28 to i32
br label %31
31: ; preds = %14, %4
%32 = phi i32 [ -1, %4 ], [ %30, %14 ]
ret i32 %32
}