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

/* Variables and functions */
int Z_BUF_ERROR;
int /*<<< orphan*/ Z_FINISH;
void *Z_NULL;
int Z_OK;
int Z_STREAM_END;
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int inflateEnd(TYPE_1__ *);
int inflateInit2(TYPE_1__ *, int);
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
int decompress_gzip(unsigned char *out, size_t *outLen, const unsigned char *in,
                    size_t inLen) {
  z_stream gz;
  int err;
  int window_size = 15 + 0x20;
  memset(&gz, 0, sizeof(gz));
  gz.next_in = (unsigned char *)in;
  gz.avail_in = inLen;
  gz.next_out = out;
  gz.avail_out = *outLen;
  gz.zalloc = Z_NULL;
  gz.zfree = Z_NULL;
  gz.opaque = Z_NULL;
  err = inflateInit2(&gz, window_size);
  if (err == Z_OK) {
    err = inflate(&gz, Z_FINISH);
    if (err != Z_STREAM_END) {
      inflateEnd(&gz);
    }
    if ((err == Z_BUF_ERROR) || (err == Z_STREAM_END)) {
      *outLen = gz.total_out;
      err = inflateEnd(&gz);
    };
  };
  return (err);
}


x86 assembly (clang, -O0):
<decompress_gzip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x2f,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x68(%rbp),%esi
lea    -0x60(%rbp),%rdi
call   1040 <inflateInit2@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%eax
jne    124d <decompress_gzip+0x10d>
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
lea    -0x60(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    0x2de4(%rip),%rcx
cmp    (%rcx),%eax
je     120d <decompress_gzip+0xcd>
lea    -0x60(%rbp),%rdi
call   1060 <inflateEnd@plt>
mov    -0x64(%rbp),%eax
mov    0x2dc1(%rip),%rcx
cmp    (%rcx),%eax
je     1231 <decompress_gzip+0xf1>
mov    -0x64(%rbp),%eax
mov    0x2db7(%rip),%rcx
cmp    (%rcx),%eax
jne    1248 <decompress_gzip+0x108>
mov    -0x40(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x60(%rbp),%rdi
call   1060 <inflateEnd@plt>
mov    %eax,-0x64(%rbp)
jmp    124d <decompress_gzip+0x10d>
mov    -0x64(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decompress_gzip>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%rbp
mov    %rsp,%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
mov    %rbx,(%rsp)
mov    %r15,0x8(%rsp)
mov    %rbp,0x10(%rsp)
mov    (%r14),%rax
mov    %rax,0x18(%rsp)
mov    0x2e41(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x38(%rsp)
mov    %rax,0x30(%rsp)
mov    %rax,0x28(%rsp)
mov    %r12,%rdi
mov    $0x2f,%esi
call   1040 <inflateInit2@plt>
mov    %eax,%ebp
mov    0x2e41(%rip),%rax
cmp    (%rax),%ebp
jne    11fc <decompress_gzip+0xbc>
mov    0x2e06(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1030 <inflate@plt>
mov    0x2e15(%rip),%rbx
cmp    (%rbx),%eax
jne    11e3 <decompress_gzip+0xa3>
mov    0x20(%rsp),%rax
mov    %rax,(%r14)
mov    %rsp,%rdi
call   1060 <inflateEnd@plt>
mov    %eax,%ebp
jmp    11fc <decompress_gzip+0xbc>
mov    %eax,%ebp
mov    %rsp,%rdi
call   1060 <inflateEnd@plt>
mov    0x2de4(%rip),%rax
cmp    (%rax),%ebp
je     11cf <decompress_gzip+0x8f>
cmp    (%rbx),%ebp
je     11cf <decompress_gzip+0x8f>
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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