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

/* Variables and functions */
int Z_MEM_ERROR;
int /*<<< orphan*/ Z_NO_FLUSH;
int Z_OK;
int Z_STREAM_END;
int /*<<< orphan*/ free(char *);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
scalar_t__ inflateInit2(TYPE_1__ *, int);
char *realloc(char *, int);
extern uint8_t *gzinflatebuf(uint8_t *buf_in, int buf_size, uint32_t *len) {
  z_stream zdat;
  uint8_t *buf = NULL, *tmp;
  int res;
  zdat.opaque = NULL;
  zdat.zalloc = NULL;
  zdat.zfree = NULL;
  zdat.next_in = buf_in;
  zdat.avail_in = buf_size;
  zdat.next_out = buf;
  zdat.avail_out = 0;
  zdat.total_out = 0;
  if (inflateInit2(&zdat, 31)) {
    return NULL;
  }
  do {
    if (!(tmp = realloc(buf, zdat.total_out + (zdat.avail_in * 5) + 1))) {
      res = Z_MEM_ERROR;
      break;
    } else {
      buf = tmp;
    }
    buf[zdat.total_out] = '\0';
    zdat.next_out = &buf[zdat.total_out];
    zdat.avail_out += zdat.avail_in * 5;
  } while ((res = inflate(&zdat, Z_NO_FLUSH)) == Z_OK);
  if (res == Z_STREAM_END) {
    buf = realloc(buf, zdat.total_out);
    *len = zdat.total_out;
  } else {
    free(buf);
    *len = 0;
    buf = NULL;
  }
  inflateEnd(&zdat);
  return buf;
}


x86 assembly (clang, -O0):
<gzinflatebuf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x0,-0x48(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x1f,%esi
call   1050 <inflateInit2@plt>
cmp    $0x0,%rax
je     11d0 <gzinflatebuf+0x80>
movq   $0x0,-0x8(%rbp)
jmp    12ba <gzinflatebuf+0x16a>
jmp    11d5 <gzinflatebuf+0x85>
mov    -0x68(%rbp),%rdi
mov    -0x48(%rbp),%esi
imul   $0x5,-0x58(%rbp),%eax
add    %eax,%esi
add    $0x1,%esi
call   1070 <realloc@plt>
mov    %rax,-0x70(%rbp)
cmp    $0x0,%rax
jne    1209 <gzinflatebuf+0xb9>
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
jmp    125e <gzinflatebuf+0x10e>
mov    -0x70(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
movslq -0x48(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x68(%rbp),%rax
movslq -0x48(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
imul   $0x5,-0x58(%rbp),%eax
cltq
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%esi
lea    -0x60(%rbp),%rdi
call   1040 <inflate@plt>
mov    %eax,-0x74(%rbp)
mov    0x2d9a(%rip),%rcx
cmp    (%rcx),%eax
je     11d5 <gzinflatebuf+0x85>
mov    -0x74(%rbp),%eax
mov    0x2d70(%rip),%rcx
cmp    (%rcx),%eax
jne    128e <gzinflatebuf+0x13e>
mov    -0x68(%rbp),%rdi
mov    -0x48(%rbp),%esi
call   1070 <realloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x48(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    12a9 <gzinflatebuf+0x159>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movq   $0x0,-0x68(%rbp)
lea    -0x60(%rbp),%rdi
call   1060 <inflateEnd@plt>
mov    -0x68(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gzinflatebuf>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r14
xorps  %xmm0,%xmm0
movups %xmm0,0x30(%rsp)
movq   $0x0,0x40(%rsp)
mov    %rdi,0x8(%rsp)
mov    %esi,0x10(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x28(%rsp)
movl   $0x0,0x20(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x1f,%esi
call   1050 <inflateInit2@plt>
test   %rax,%rax
je     11b0 <gzinflatebuf+0x60>
xor    %ebx,%ebx
jmp    1270 <gzinflatebuf+0x120>
xor    %r12d,%r12d
mov    0x2e0e(%rip),%r13
lea    0x8(%rsp),%r15
mov    0x2e2a(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    0x10(%rsp),%eax
mov    0x20(%rsp),%ecx
lea    (%rax,%rax,4),%eax
lea    (%rcx,%rax,1),%esi
add    $0x1,%esi
mov    %r12,%rdi
call   1070 <realloc@plt>
test   %rax,%rax
je     122e <gzinflatebuf+0xde>
mov    %rax,%rbx
movslq 0x20(%rsp),%rax
movb   $0x0,(%rbx,%rax,1)
movslq 0x20(%rsp),%rax
add    %rbx,%rax
mov    %rax,0x18(%rsp)
movslq 0x10(%rsp),%rax
lea    (%rax,%rax,4),%rax
add    %rax,0x28(%rsp)
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1040 <inflate@plt>
mov    %rbx,%r12
cmp    0x0(%rbp),%eax
je     11d0 <gzinflatebuf+0x80>
mov    %rbx,%r12
jmp    1237 <gzinflatebuf+0xe7>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    0x2d9a(%rip),%rcx
cmp    (%rcx),%eax
jne    1257 <gzinflatebuf+0x107>
mov    0x20(%rsp),%esi
mov    %r12,%rdi
call   1070 <realloc@plt>
mov    %rax,%rbx
mov    0x20(%rsp),%eax
jmp    1263 <gzinflatebuf+0x113>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
xor    %ebx,%ebx
mov    %eax,(%r14)
lea    0x8(%rsp),%rdi
call   1060 <inflateEnd@plt>
mov    %rbx,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i8*, i32, i8*, i32, i64, i32*, i32*, i32* }
@Z_MEM_ERROR = global i32 0
@Z_NO_FLUSH = global i32 0
@Z_OK = global i32 0
@Z_STREAM_END = global i32 0
define i8* @gzinflatebuf(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.TYPE_5__
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i8* null, i8** %9
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 7
store i32* null, i32** %12
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 6
store i32* null, i32** %13
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 5
store i32* null, i32** %14
%15 = load i8*, i8** %5
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 0
store i8* %15, i8** %16
%17 = load i32, i32* %6
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 1
store i32 %17, i32* %18
%19 = load i8*, i8** %9
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 2
store i8* %19, i8** %20
%21 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 4
store i64 0, i64* %21
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 3
store i32 0, i32* %22
%23 = call i64 @inflateInit2(%struct.TYPE_5__* %8, i32 31)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %3
store i8* null, i8** %4
br label %85
26: ; preds = %3
br label %27
27: ; preds = %61, %26
%28 = load i8*, i8** %9
%29 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 3
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 1
%32 = load i32, i32* %31
%33 = mul nsw i32 %32, 5
%34 = add nsw i32 %30, %33
%35 = add nsw i32 %34, 1
%36 = call i8* @realloc(i8* %28, i32 %35)
store i8* %36, i8** %10
%37 = icmp ne i8* %36, null
br i1 %37, label %40, label %38
38: ; preds = %27
%39 = load i32, i32* @Z_MEM_ERROR
store i32 %39, i32* %11
br label %66
40: ; preds = %27
%41 = load i8*, i8** %10
store i8* %41, i8** %9
br label %42
42: ; preds = %40
%43 = load i8*, i8** %9
%44 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 3
%45 = load i32, i32* %44
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
store i8 0, i8* %47
%48 = load i8*, i8** %9
%49 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 3
%50 = load i32, i32* %49
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %48, i64 %51
%53 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 2
store i8* %52, i8** %53
%54 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 1
%55 = load i32, i32* %54
%56 = mul nsw i32 %55, 5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 4
%59 = load i64, i64* %58
%60 = add nsw i64 %59, %57
store i64 %60, i64* %58
br label %61
61: ; preds = %42
%62 = load i32, i32* @Z_NO_FLUSH
%63 = call i32 @inflate(%struct.TYPE_5__* %8, i32 %62)
store i32 %63, i32* %11
%64 = load i32, i32* @Z_OK
%65 = icmp eq i32 %63, %64
br i1 %65, label %27, label %66
66: ; preds = %61, %38
%67 = load i32, i32* %11
%68 = load i32, i32* @Z_STREAM_END
%69 = icmp eq i32 %67, %68
br i1 %69, label %70, label %78
70: ; preds = %66
%71 = load i8*, i8** %9
%72 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 3
%73 = load i32, i32* %72
%74 = call i8* @realloc(i8* %71, i32 %73)
store i8* %74, i8** %9
%75 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %8, i32 0, i32 3
%76 = load i32, i32* %75
%77 = load i32*, i32** %7
store i32 %76, i32* %77
br label %82
78: ; preds = %66
%79 = load i8*, i8** %9
%80 = call i32 @free(i8* %79)
%81 = load i32*, i32** %7
store i32 0, i32* %81
store i8* null, i8** %9
br label %82
82: ; preds = %78, %70
%83 = call i32 @inflateEnd(%struct.TYPE_5__* %8)
%84 = load i8*, i8** %9
store i8* %84, i8** %4
br label %85
85: ; preds = %82, %25
%86 = load i8*, i8** %4
ret i8* %86
}

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