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

/* Variables and functions */
int /*<<< orphan*/ Z_FINISH;
scalar_t__ Z_OK;
int /*<<< orphan*/ inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
scalar_t__ inflateInit(TYPE_1__ *);
void *malloc(unsigned int);
unsigned int ntohl(unsigned int);
int gzip_decompress(const void *src, const unsigned int src_len, void **dst,
                    unsigned int *dst_len) {
  z_stream stream;
  *dst_len = ntohl(*(unsigned int *)src);
  src = (const unsigned char *)src + sizeof(unsigned int);
  *dst = malloc(*dst_len);
  if (*dst == NULL)
    return 0;
  stream.zalloc = NULL;
  stream.zfree = NULL;
  stream.opaque = NULL;
  if (inflateInit(&stream) != Z_OK)
    return 0;
  stream.next_in = (Bytef *)src;
  stream.avail_in = src_len;
  stream.next_out = *dst;
  stream.avail_out = *dst_len;
  inflate(&stream, Z_FINISH);
  inflateEnd(&stream);
  return 1;
}


x86 assembly (clang, -O0):
<gzip_decompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1070 <ntohl@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11b5 <gzip_decompress+0x65>
movl   $0x0,-0x4(%rbp)
jmp    1236 <gzip_decompress+0xe6>
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
lea    -0x58(%rbp),%rdi
call   1040 <inflateInit@plt>
mov    0x2e13(%rip),%rcx
cmp    (%rcx),%rax
je     11f2 <gzip_decompress+0xa2>
movl   $0x0,-0x4(%rbp)
jmp    1236 <gzip_decompress+0xe6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
lea    -0x58(%rbp),%rdi
call   1030 <inflate@plt>
lea    -0x58(%rbp),%rdi
call   1050 <inflateEnd@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gzip_decompress>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %esi,%r15d
mov    %rdi,%rbp
mov    (%rdi),%edi
call   1070 <ntohl@plt>
mov    %eax,(%r14)
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,(%r12)
xor    %ebx,%ebx
test   %rax,%rax
je     11e7 <gzip_decompress+0x97>
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
movq   $0x0,0x28(%rsp)
mov    %rsp,%rdi
call   1040 <inflateInit@plt>
mov    0x2e4c(%rip),%rcx
cmp    (%rcx),%rax
jne    11e7 <gzip_decompress+0x97>
add    $0x4,%rbp
mov    %rbp,0x10(%rsp)
mov    %r15d,(%rsp)
mov    (%r12),%rax
mov    %rax,0x8(%rsp)
mov    (%r14),%eax
mov    %eax,0x4(%rsp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <inflate@plt>
mov    %rbx,%rdi
call   1050 <inflateEnd@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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