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

/* Variables and functions */
int /*<<< orphan*/ Z_FINISH;
int Z_OK;
int /*<<< orphan*/ Z_PARTIAL_FLUSH;
int Z_STREAM_END;
int deflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ deflateEnd(TYPE_1__ *);
int deflateInit(TYPE_1__ *, int);
int jffs2_zlib_compress(unsigned char *data_in, unsigned char *cpage_out,
                        uint32_t *sourcelen, uint32_t *dstlen, void *model) {
  z_stream strm;
  int ret;
  if (*dstlen <= 12)
    return -1;
  strm.zalloc = (void *)0;
  strm.zfree = (void *)0;
  if (Z_OK != deflateInit(&strm, 3)) {
    return -1;
  }
  strm.next_in = data_in;
  strm.total_in = 0;
  strm.next_out = cpage_out;
  strm.total_out = 0;
  while (strm.total_out + 12 < *dstlen && strm.total_in < *sourcelen) {
    strm.avail_out = *dstlen - (strm.total_out + 12);
    strm.avail_in = (((unsigned)(*sourcelen - strm.total_in)) < (strm.avail_out)
                         ? ((unsigned)(*sourcelen - strm.total_in))
                         : (strm.avail_out));
    ret = deflate(&strm, Z_PARTIAL_FLUSH);
    if (ret != Z_OK) {
      deflateEnd(&strm);
      return -1;
    }
  }
  strm.avail_out += 12;
  strm.avail_in = 0;
  ret = deflate(&strm, Z_FINISH);
  if (ret != Z_STREAM_END) {
    deflateEnd(&strm);
    return -1;
  }
  deflateEnd(&strm);
  if (strm.total_out >= strm.total_in)
    return -1;
  *dstlen = strm.total_out;
  *sourcelen = strm.total_in;
  return 0;
}


x86 assembly (clang, -O0):
<jffs2_zlib_compress>:
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    -0x28(%rbp),%rax
cmpl   $0xc,(%rax)
jg     1168 <jffs2_zlib_compress+0x38>
movl   $0xffffffff,-0x4(%rbp)
jmp    1306 <jffs2_zlib_compress+0x1d6>
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
lea    -0x68(%rbp),%rdi
mov    $0x3,%esi
call   1040 <deflateInit@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%eax
cmp    %ecx,%eax
je     11ab <jffs2_zlib_compress+0x7b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1306 <jffs2_zlib_compress+0x1d6>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
movl   $0x0,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%ecx
add    $0xc,%ecx
mov    -0x28(%rbp),%rdx
xor    %eax,%eax
cmp    (%rdx),%ecx
mov    %al,-0x71(%rbp)
jge    11ef <jffs2_zlib_compress+0xbf>
mov    -0x60(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
setl   %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
test   $0x1,%al
jne    11ff <jffs2_zlib_compress+0xcf>
jmp    1280 <jffs2_zlib_compress+0x150>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    -0x50(%rbp),%ecx
add    $0xc,%ecx
sub    %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
sub    -0x60(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jae    1233 <jffs2_zlib_compress+0x103>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
sub    -0x60(%rbp),%eax
mov    %eax,-0x78(%rbp)
jmp    1239 <jffs2_zlib_compress+0x109>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdi
call   1030 <deflate@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    0x2d92(%rip),%rcx
cmp    (%rcx),%eax
je     127b <jffs2_zlib_compress+0x14b>
lea    -0x68(%rbp),%rdi
call   1050 <deflateEnd@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1306 <jffs2_zlib_compress+0x1d6>
jmp    11c9 <jffs2_zlib_compress+0x99>
mov    -0x4c(%rbp),%eax
add    $0xc,%eax
mov    %eax,-0x4c(%rbp)
movl   $0x0,-0x48(%rbp)
mov    0x2d31(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdi
call   1030 <deflate@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    0x2d29(%rip),%rcx
cmp    (%rcx),%eax
je     12cc <jffs2_zlib_compress+0x19c>
lea    -0x68(%rbp),%rdi
call   1050 <deflateEnd@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1306 <jffs2_zlib_compress+0x1d6>
lea    -0x68(%rbp),%rdi
call   1050 <deflateEnd@plt>
mov    -0x50(%rbp),%eax
cmp    -0x60(%rbp),%eax
jl     12ed <jffs2_zlib_compress+0x1bd>
movl   $0xffffffff,-0x4(%rbp)
jmp    1306 <jffs2_zlib_compress+0x1d6>
mov    -0x50(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x60(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jffs2_zlib_compress>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    $0xffffffff,%r14d
cmpl   $0xd,(%rcx)
jl     1251 <jffs2_zlib_compress+0x121>
mov    %rcx,%rbp
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movups %xmm0,0x28(%rsp)
mov    0x2e88(%rip),%rax
mov    (%rax),%r13d
mov    %rsp,%rdi
mov    $0x3,%esi
call   1040 <deflateInit@plt>
cmp    %eax,%r13d
jne    1251 <jffs2_zlib_compress+0x121>
mov    %rbx,(%rsp)
movl   $0x0,0x8(%rsp)
mov    %r15,0x10(%rsp)
movl   $0x0,0x18(%rsp)
mov    0x0(%rbp),%eax
cmp    $0xd,%eax
mov    0x2e49(%rip),%rbx
jl     11f7 <jffs2_zlib_compress+0xc7>
mov    $0xc,%ecx
mov    0x2e2b(%rip),%r13
mov    %rsp,%r15
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edx
sub    0x8(%rsp),%edx
jle    11f7 <jffs2_zlib_compress+0xc7>
sub    %ecx,%eax
mov    %eax,0x1c(%rsp)
cmp    %eax,%edx
cmovb  %edx,%eax
mov    %eax,0x20(%rsp)
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   1030 <deflate@plt>
cmp    (%rbx),%eax
jne    1249 <jffs2_zlib_compress+0x119>
mov    0x18(%rsp),%ecx
add    $0xc,%ecx
mov    0x0(%rbp),%eax
cmp    %ecx,%eax
jg     11c0 <jffs2_zlib_compress+0x90>
addl   $0xc,0x1c(%rsp)
movl   $0x0,0x20(%rsp)
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r15
mov    %r15,%rdi
call   1030 <deflate@plt>
mov    %eax,%r13d
mov    0x2db6(%rip),%rax
mov    (%rax),%ebx
mov    %r15,%rdi
call   1050 <deflateEnd@plt>
cmp    %ebx,%r13d
jne    1251 <jffs2_zlib_compress+0x121>
mov    0x8(%rsp),%eax
mov    0x18(%rsp),%ecx
cmp    %eax,%ecx
jge    1251 <jffs2_zlib_compress+0x121>
mov    %ecx,0x0(%rbp)
mov    %eax,(%r12)
xor    %r14d,%r14d
jmp    1251 <jffs2_zlib_compress+0x121>
mov    %rsp,%rdi
call   1050 <deflateEnd@plt>
mov    %r14d,%eax
add    $0x38,%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, i32, i32, i8*, i8* }
@Z_OK = global i32 0
@Z_PARTIAL_FLUSH = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
define i32 @jffs2_zlib_compress(i8* %0, i8* %1, i32* %2, i32* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca %struct.TYPE_5__
%13 = alloca i32
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store i8* %4, i8** %11
%14 = load i32*, i32** %10
%15 = load i32, i32* %14
%16 = icmp sle i32 %15, 12
br i1 %16, label %17, label %18
17: ; preds = %5
store i32 -1, i32* %6
br label %110
18: ; preds = %5
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 7
store i8* null, i8** %19
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 6
store i8* null, i8** %20
%21 = load i32, i32* @Z_OK
%22 = call i32 @deflateInit(%struct.TYPE_5__* %12, i32 3)
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 -1, i32* %6
br label %110
25: ; preds = %18
%26 = load i8*, i8** %7
%27 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 0
store i8* %26, i8** %27
%28 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
store i32 0, i32* %28
%29 = load i8*, i8** %8
%30 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 2
store i8* %29, i8** %30
%31 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 3
store i32 0, i32* %31
br label %32
32: ; preds = %82, %25
%33 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 3
%34 = load i32, i32* %33
%35 = add nsw i32 %34, 12
%36 = load i32*, i32** %10
%37 = load i32, i32* %36
%38 = icmp slt i32 %35, %37
br i1 %38, label %39, label %45
39: ; preds = %32
%40 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
%41 = load i32, i32* %40
%42 = load i32*, i32** %9
%43 = load i32, i32* %42
%44 = icmp slt i32 %41, %43
br label %45
45: ; preds = %39, %32
%46 = phi i1 [ false, %32 ], [ %44, %39 ]
br i1 %46, label %47, label %83
47: ; preds = %45
%48 = load i32*, i32** %10
%49 = load i32, i32* %48
%50 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 3
%51 = load i32, i32* %50
%52 = add nsw i32 %51, 12
%53 = sub nsw i32 %49, %52
%54 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 4
store i32 %53, i32* %54
%55 = load i32*, i32** %9
%56 = load i32, i32* %55
%57 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
%58 = load i32, i32* %57
%59 = sub nsw i32 %56, %58
%60 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 4
%61 = load i32, i32* %60
%62 = icmp ult i32 %59, %61
br i1 %62, label %63, label %69
63: ; preds = %47
%64 = load i32*, i32** %9
%65 = load i32, i32* %64
%66 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
%67 = load i32, i32* %66
%68 = sub nsw i32 %65, %67
br label %72
69: ; preds = %47
%70 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 4
%71 = load i32, i32* %70
br label %72
72: ; preds = %69, %63
%73 = phi i32 [ %68, %63 ], [ %71, %69 ]
%74 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 5
store i32 %73, i32* %74
%75 = load i32, i32* @Z_PARTIAL_FLUSH
%76 = call i32 @deflate(%struct.TYPE_5__* %12, i32 %75)
store i32 %76, i32* %13
%77 = load i32, i32* %13
%78 = load i32, i32* @Z_OK
%79 = icmp ne i32 %77, %78
br i1 %79, label %80, label %82
80: ; preds = %72
%81 = call i32 @deflateEnd(%struct.TYPE_5__* %12)
store i32 -1, i32* %6
br label %110
82: ; preds = %72
br label %32
83: ; preds = %45
%84 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 4
%85 = load i32, i32* %84
%86 = add nsw i32 %85, 12
store i32 %86, i32* %84
%87 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 5
store i32 0, i32* %87
%88 = load i32, i32* @Z_FINISH
%89 = call i32 @deflate(%struct.TYPE_5__* %12, i32 %88)
store i32 %89, i32* %13
%90 = load i32, i32* %13
%91 = load i32, i32* @Z_STREAM_END
%92 = icmp ne i32 %90, %91
br i1 %92, label %93, label %95
93: ; preds = %83
%94 = call i32 @deflateEnd(%struct.TYPE_5__* %12)
store i32 -1, i32* %6
br label %110
95: ; preds = %83
%96 = call i32 @deflateEnd(%struct.TYPE_5__* %12)
%97 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 3
%98 = load i32, i32* %97
%99 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
%100 = load i32, i32* %99
%101 = icmp sge i32 %98, %100
br i1 %101, label %102, label %103
102: ; preds = %95
store i32 -1, i32* %6
br label %110
103: ; preds = %95
%104 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 3
%105 = load i32, i32* %104
%106 = load i32*, i32** %10
store i32 %105, i32* %106
%107 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
%108 = load i32, i32* %107
%109 = load i32*, i32** %9
store i32 %108, i32* %109
store i32 0, i32* %6
br label %110
110: ; preds = %103, %102, %93, %80, %24, %17
%111 = load i32, i32* %6
ret i32 %111
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i8*, i32, i8*, i32, i32, i32, i8*, i8* }
@Z_OK = global i32 0
@Z_PARTIAL_FLUSH = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
define i32 @jffs2_zlib_compress(i8* %0, i8* %1, i32* nocapture %2, i32* nocapture %3, i8* nocapture readnone %4) {
%6 = alloca %struct.TYPE_5__
%7 = bitcast %struct.TYPE_5__* %6 to i8*
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 13
br i1 %9, label %60, label %10
10: ; preds = %5
%11 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i64 0, i32 6
%12 = bitcast i8** %11 to i8*
%13 = load i32, i32* @Z_OK
%14 = call i32 @deflateInit(%struct.TYPE_5__* %6, i32 3)
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %60
16: ; preds = %10
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i64 0, i32 0
store i8* %0, i8** %17
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i64 0, i32 1
store i32 0, i32* %18
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i64 0, i32 2
store i8* %1, i8** %19
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i64 0, i32 3
store i32 0, i32* %20
%21 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i64 0, i32 4
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %6, i64 0, i32 5
%23 = load i32, i32* %3
%24 = icmp sgt i32 %23, 12
br i1 %24, label %25, label %47
25: ; preds = %16, %40
%26 = phi i32 [ %43, %40 ], [ %23, %16 ]
%27 = phi i32 [ %42, %40 ], [ 12, %16 ]
%28 = load i32, i32* %18
%29 = load i32, i32* %2
%30 = icmp sgt i32 %29, %28
br i1 %30, label %31, label %47
31: ; preds = %25
%32 = sub nsw i32 %26, %27
store i32 %32, i32* %21
%33 = sub nsw i32 %29, %28
%34 = icmp ult i32 %33, %32
%35 = select i1 %34, i32 %33, i32 %32
store i32 %35, i32* %22
%36 = load i32, i32* @Z_PARTIAL_FLUSH
%37 = call i32 @deflate(%struct.TYPE_5__* %6, i32 %36)
%38 = load i32, i32* @Z_OK
%39 = icmp eq i32 %37, %38
br i1 %39, label %40, label %45
40: ; preds = %31
%41 = load i32, i32* %20
%42 = add nsw i32 %41, 12
%43 = load i32, i32* %3
%44 = icmp sgt i32 %43, %42
br i1 %44, label %25, label %47
45: ; preds = %31
%46 = call i32 @deflateEnd(%struct.TYPE_5__* %6)
br label %60
47: ; preds = %25, %40, %16
%48 = load i32, i32* %21
%49 = add nsw i32 %48, 12
store i32 %49, i32* %21
store i32 0, i32* %22
%50 = load i32, i32* @Z_FINISH
%51 = call i32 @deflate(%struct.TYPE_5__* %6, i32 %50)
%52 = load i32, i32* @Z_STREAM_END
%53 = icmp eq i32 %51, %52
%54 = call i32 @deflateEnd(%struct.TYPE_5__* %6)
br i1 %53, label %55, label %60
55: ; preds = %47
%56 = load i32, i32* %20
%57 = load i32, i32* %18
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %60
59: ; preds = %55
store i32 %56, i32* %3
store i32 %57, i32* %2
br label %60
60: ; preds = %47, %55, %10, %5, %59, %45
%61 = phi i32 [ -1, %45 ], [ 0, %59 ], [ -1, %5 ], [ -1, %10 ], [ -1, %55 ], [ -1, %47 ]
ret i32 %61
}