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

/* Variables and functions */
int /*<<< orphan*/ Z_FINISH;
void *Z_NULL;
int Z_OK;
int Z_STREAM_END;
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
int inflateInit2(TYPE_1__ *, int);
int ungz(char *dst, const uint32_t dstLen, char *src, const uint32_t srcLen) {
  int err = -1;
  int ret = -1;
  z_stream strm = {0};
  strm.total_in = strm.avail_in = srcLen;
  strm.total_out = strm.avail_out = dstLen;
  strm.next_in = (unsigned char *)src;
  strm.next_out = (unsigned char *)dst;
  strm.zalloc = Z_NULL;
  strm.zfree = Z_NULL;
  strm.opaque = Z_NULL;
  err = inflateInit2(&strm, 47);
  if (err == Z_OK) {
    err = inflate(&strm, Z_FINISH);
    if (err == Z_STREAM_END)
      ret = strm.total_out;
    else {
      inflateEnd(&strm);
      return err;
    }
  } else {
    inflateEnd(&strm);
    return err;
  }
  inflateEnd(&strm);
  return ret;
}


x86 assembly (clang, -O0):
<ungz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movl   $0xffffffff,-0x28(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    %eax,-0x70(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    %eax,-0x68(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <inflateInit2@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2e15(%rip),%rcx
cmp    (%rcx),%eax
jne    122e <ungz+0xee>
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
lea    -0x70(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    0x2dde(%rip),%rcx
cmp    (%rcx),%eax
jne    1215 <ungz+0xd5>
mov    -0x68(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1229 <ungz+0xe9>
lea    -0x70(%rbp),%rdi
call   1060 <inflateEnd@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1251 <ungz+0x111>
jmp    1242 <ungz+0x102>
lea    -0x70(%rbp),%rdi
call   1060 <inflateEnd@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1251 <ungz+0x111>
lea    -0x70(%rbp),%rdi
call   1060 <inflateEnd@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ungz>:
push   %rbx
sub    $0x40,%rsp
movq   $0x0,0x38(%rsp)
mov    %ecx,0x4(%rsp)
mov    %ecx,(%rsp)
mov    %esi,0xc(%rsp)
mov    %esi,0x8(%rsp)
mov    %rdx,0x10(%rsp)
mov    %rdi,0x18(%rsp)
mov    0x2e72(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
mov    %rax,0x28(%rsp)
mov    %rax,0x20(%rsp)
mov    %rsp,%rdi
mov    $0x2f,%esi
call   1040 <inflateInit2@plt>
mov    %eax,%ebx
mov    0x2e6a(%rip),%rax
cmp    (%rax),%ebx
jne    11ac <ungz+0x7c>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1030 <inflate@plt>
mov    %eax,%ebx
mov    0x2e3c(%rip),%rax
cmp    (%rax),%ebx
jne    11ac <ungz+0x7c>
mov    0x8(%rsp),%ebx
mov    %rsp,%rdi
call   1050 <inflateEnd@plt>
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i32, i32, i32, i8*, i8*, i8*, i8*, i8*, i32 }
@Z_NULL = global i8* null
@Z_OK = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
define i32 @ungz(i8* %0, i32 %1, i8* %2, i32 %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 9
%8 = bitcast i32* %7 to i64*
store i64 0, i64* %8
%9 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 1
store i32 %3, i32* %9
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 0
store i32 %3, i32* %10
%11 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 3
store i32 %1, i32* %11
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 2
store i32 %1, i32* %12
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 4
store i8* %2, i8** %13
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 5
store i8* %0, i8** %14
%15 = load i8*, i8** @Z_NULL
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 8
store i8* %15, i8** %16
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 7
store i8* %15, i8** %17
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %5, i64 0, i32 6
store i8* %15, i8** %18
%19 = call i32 @inflateInit2(%struct.TYPE_5__* %5, i32 47)
%20 = load i32, i32* @Z_OK
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %29
22: ; preds = %4
%23 = load i32, i32* @Z_FINISH
%24 = call i32 @inflate(%struct.TYPE_5__* %5, i32 %23)
%25 = load i32, i32* @Z_STREAM_END
%26 = icmp eq i32 %24, %25
%27 = load i32, i32* %12
%28 = select i1 %26, i32 %27, i32 %24
br label %29
29: ; preds = %22, %4
%30 = phi i32 [ %19, %4 ], [ %28, %22 ]
%31 = call i32 @inflateEnd(%struct.TYPE_5__* %5)
ret i32 %30
}