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

/* Variables and functions */
int /*<<< orphan*/ Z_FINISH;
void *Z_NULL;
int Z_OK;
int Z_STREAM_END;
int Z_STREAM_ERROR;
int /*<<< orphan*/ assert(int);
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
int fbx_array_decompress(const void *src, int srclen, void *dst, int dstlen) {
  int err = -1, ret = -1;
  z_stream strm;
  memset(&strm, 0, sizeof(strm));
  strm.total_in = strm.avail_in = srclen;
  strm.total_out = strm.avail_out = dstlen;
  strm.next_in = (Bytef *)src;
  strm.next_out = (Bytef *)dst;
  strm.zalloc = Z_NULL;
  strm.zfree = Z_NULL;
  strm.opaque = Z_NULL;
  err = inflateInit(&strm);
  if (err == Z_OK) {
    err = inflate(&strm, Z_FINISH);
    assert(err != Z_STREAM_ERROR);
    if (err == Z_STREAM_END)
      ret = strm.total_out;
  }
  inflateEnd(&strm);
  return ret;
}


x86 assembly (clang, -O0):
<fbx_array_decompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0xffffffff,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    %eax,-0x60(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    %eax,-0x58(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
lea    -0x60(%rbp),%rdi
call   1050 <inflateInit@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2e0a(%rip),%rcx
cmp    (%rcx),%eax
jne    1239 <fbx_array_decompress+0xe9>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
lea    -0x60(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2dc3(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x20(%rbp),%eax
mov    0x2dba(%rip),%rcx
cmp    (%rcx),%eax
jne    1234 <fbx_array_decompress+0xe4>
mov    -0x58(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1239 <fbx_array_decompress+0xe9>
lea    -0x60(%rbp),%rdi
call   1070 <inflateEnd@plt>
mov    -0x24(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fbx_array_decompress>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
lea    0x8(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x38,%edx
call   1040 <memset@plt>
mov    %ebp,0xc(%rsp)
mov    %ebp,0x8(%rsp)
mov    %ebx,0x14(%rsp)
mov    %ebx,0x10(%rsp)
mov    %r15,0x38(%rsp)
mov    %r14,0x30(%rsp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x28(%rsp)
mov    %rax,0x20(%rsp)
mov    %rax,0x18(%rsp)
mov    %r12,%rdi
call   1050 <inflateInit@plt>
mov    0x2e34(%rip),%rcx
mov    $0xffffffff,%ebx
cmp    (%rcx),%eax
jne    1202 <fbx_array_decompress+0xb2>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdi
call   1030 <inflate@plt>
mov    %eax,%ebp
mov    0x2def(%rip),%rax
xor    %edi,%edi
cmp    (%rax),%ebp
setne  %dil
call   1060 <assert@plt>
mov    0x2deb(%rip),%rax
mov    $0xffffffff,%ebx
cmp    (%rax),%ebp
jne    1202 <fbx_array_decompress+0xb2>
mov    0x10(%rsp),%ebx
lea    0x8(%rsp),%rdi
call   1070 <inflateEnd@plt>
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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