#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, void *model) {
  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    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <inflateInit@plt>
mov    %eax,%ecx
mov    -0x78(%rbp),%eax
cmp    %ecx,%eax
je     118d <jffs2_zlib_decompress+0x5d>
movl   $0x1,-0x4(%rbp)
jmp    11f6 <jffs2_zlib_decompress+0xc6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
movq   $0x0,-0x60(%rbp)
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    -0x70(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x74(%rbp)
mov    0x2e17(%rip),%rcx
cmp    (%rcx),%eax
jne    11e6 <jffs2_zlib_decompress+0xb6>
jmp    11bd <jffs2_zlib_decompress+0x8d>
lea    -0x70(%rbp),%rdi
call   1050 <inflateEnd@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%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, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca %struct.TYPE_5__
%13 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 7
store i8* null, i8** %14
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 6
store i8* null, i8** %15
%16 = load i32, i32* @Z_OK
%17 = call i32 @inflateInit(%struct.TYPE_5__* %12)
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %5
store i32 1, i32* %6
br label %39
20: ; preds = %5
%21 = load i8*, i8** %7
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 0
store i8* %21, i8** %22
%23 = load i8*, i8** %9
%24 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 5
store i8* %23, i8** %24
%25 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 4
store i64 0, i64* %25
%26 = load i8*, i8** %8
%27 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
store i8* %26, i8** %27
%28 = load i8*, i8** %10
%29 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 3
store i8* %28, i8** %29
%30 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 2
store i64 0, i64* %30
br label %31
31: ; preds = %36, %20
%32 = load i32, i32* @Z_FINISH
%33 = call i32 @inflate(%struct.TYPE_5__* %12, i32 %32)
store i32 %33, i32* %13
%34 = load i32, i32* @Z_OK
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %37
36: ; preds = %31
br label %31
37: ; preds = %31
%38 = call i32 @inflateEnd(%struct.TYPE_5__* %12)
store i32 0, i32* %6
br label %39
39: ; preds = %37, %19
%40 = load i32, i32* %6
ret i32 %40
}

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