#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 char *next_in;
  size_t avail_in;
  char *msg;
  unsigned char *next_out;
  size_t avail_out;
  void *opaque;
  void *zfree;
  void *zalloc;
};
typedef TYPE_1__ z_stream;

/* Variables and functions */
void *Z_NULL;
int Z_OK;
int /*<<< orphan*/ Z_SYNC_FLUSH;
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
bool inflate_to_buffer(const unsigned char *buffer, size_t len,
                       unsigned char *out_buffer, size_t out_len,
                       char **err_msg) {
  z_stream d_stream;
  int ret;
  d_stream.zalloc = Z_NULL;
  d_stream.zfree = Z_NULL;
  d_stream.opaque = Z_NULL;
  d_stream.next_in = (unsigned char *)buffer;
  d_stream.avail_in = len;
  ret = inflateInit(&d_stream);
  if (ret != Z_OK) {
    *err_msg = d_stream.msg;
    return false;
  }
  d_stream.next_out = out_buffer;
  d_stream.avail_out = out_len;
  ret = inflate(&d_stream, Z_SYNC_FLUSH);
  if (ret < 0) {
    *err_msg = d_stream.msg;
    return false;
  } else
    inflateEnd(&d_stream);
  return true;
}


x86 assembly (clang, -O0):
<inflate_to_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <inflateInit@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    0x2e51(%rip),%rcx
cmp    (%rcx),%eax
je     11be <inflate_to_buffer+0x8e>
mov    -0x60(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1214 <inflate_to_buffer+0xe4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
lea    -0x70(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jge    1204 <inflate_to_buffer+0xd4>
mov    -0x60(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1214 <inflate_to_buffer+0xe4>
lea    -0x70(%rbp),%rdi
call   1050 <inflateEnd@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inflate_to_buffer>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%rbx
mov    0x2e87(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x38(%rsp)
mov    %rax,0x30(%rsp)
mov    %rax,0x28(%rsp)
mov    %rdi,(%rsp)
mov    %rsi,0x8(%rsp)
mov    %rsp,%rdi
call   1040 <inflateInit@plt>
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%eax
jne    11a5 <inflate_to_buffer+0x75>
mov    %rbx,0x18(%rsp)
mov    %r15,0x20(%rsp)
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1030 <inflate@plt>
test   %eax,%eax
js     11a5 <inflate_to_buffer+0x75>
mov    %rsp,%rdi
call   1050 <inflateEnd@plt>
mov    $0x1,%eax
jmp    11af <inflate_to_buffer+0x7f>
mov    0x10(%rsp),%rax
mov    %rax,(%r14)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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