#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;
  unsigned char *next_out;
  scalar_t__ total_out;
  void *avail_out;
  scalar_t__ total_in;
  void *avail_in;
  void *zfree;
  void *zalloc;
};
typedef TYPE_1__ z_stream;
typedef void *uint32_t;

/* Variables and functions */
int /*<<< orphan*/ Z_FINISH;
int Z_OK;
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
int jffs2_zlib_decompress(unsigned char *data_in, unsigned char *cpage_out,
                          uint32_t srclen, uint32_t destlen) {
  z_stream strm;
  int ret;
  strm.zalloc = (void *)0;
  strm.zfree = (void *)0;
  if (Z_OK != inflateInit(&strm)) {
    return 1;
  }
  strm.next_in = data_in;
  strm.avail_in = srclen;
  strm.total_in = 0;
  strm.next_out = cpage_out;
  strm.avail_out = destlen;
  strm.total_out = 0;
  while ((ret = inflate(&strm, Z_FINISH)) == Z_OK)
    ;
  inflateEnd(&strm);
  return 0;
}


x86 assembly (clang, -O0):
<jffs2_zlib_decompress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
lea    -0x68(%rbp),%rdi
call   1040 <inflateInit@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%eax
cmp    %ecx,%eax
je     1186 <jffs2_zlib_decompress+0x56>
movl   $0x1,-0x4(%rbp)
jmp    11ef <jffs2_zlib_decompress+0xbf>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
movq   $0x0,-0x58(%rbp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x6c(%rbp)
mov    0x2e1e(%rip),%rcx
cmp    (%rcx),%eax
jne    11df <jffs2_zlib_decompress+0xaf>
jmp    11b6 <jffs2_zlib_decompress+0x86>
lea    -0x68(%rbp),%rdi
call   1050 <inflateEnd@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jffs2_zlib_decompress>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movups %xmm0,0x38(%rsp)
mov    0x2e97(%rip),%r13
mov    0x0(%r13),%ebp
lea    0x8(%rsp),%rdi
call   1040 <inflateInit@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%ebp
jne    11cd <jffs2_zlib_decompress+0x9d>
mov    %rbx,0x8(%rsp)
mov    %r12,0x30(%rsp)
movq   $0x0,0x28(%rsp)
mov    %r15,0x10(%rsp)
mov    %r14,0x20(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x2e39(%rip),%r14
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14),%esi
mov    %rbx,%rdi
call   1030 <inflate@plt>
cmp    0x0(%r13),%eax
je     11b0 <jffs2_zlib_decompress+0x80>
lea    0x8(%rsp),%rdi
call   1050 <inflateEnd@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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