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

/* Variables and functions */
int /*<<< orphan*/ Z_DEFAULT_COMPRESSION;
int /*<<< orphan*/ Z_FINISH;
void *Z_NULL;
scalar_t__ Z_OK;
scalar_t__ Z_STREAM_ERROR;
scalar_t__ deflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ deflateEnd(TYPE_1__ *);
scalar_t__ deflateInit(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, void const *, size_t);
int cl_zlib_compress_data(void *out_data, const void *in_data, size_t in_size) {
  uint8_t status;
  size_t out_len;
  z_stream strm;
  strm.zalloc = Z_NULL;
  strm.zfree = Z_NULL;
  strm.opaque = Z_NULL;
  if (deflateInit(&strm, Z_DEFAULT_COMPRESSION) != Z_OK)
    return -1;
  strm.next_in = (unsigned char *)in_data;
  strm.avail_in = in_size;
  strm.avail_out = in_size;
  strm.next_out = ((unsigned char *)out_data) + 1;
  if (deflate(&strm, Z_FINISH) == Z_STREAM_ERROR) {
    deflateEnd(&strm);
    return -2;
  }
  deflateEnd(&strm);
  out_len = in_size - strm.avail_out;
  if (out_len >= in_size) {
    memcpy(((char *)out_data) + 1, in_data, in_size);
    out_len = in_size;
    status = 0;
  } else {
    status = 1;
  }
  ((uint8_t *)out_data)[0] = status;
  return out_len + 1;
}


x86 assembly (clang, -O0):
<cl_zlib_compress_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdi
call   1050 <deflateInit@plt>
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%rax
je     11ac <cl_zlib_compress_data+0x6c>
movl   $0xffffffff,-0x4(%rbp)
jmp    126e <cl_zlib_compress_data+0x12e>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
lea    -0x68(%rbp),%rdi
call   1030 <deflate@plt>
mov    0x2def(%rip),%rcx
cmp    (%rcx),%rax
jne    1207 <cl_zlib_compress_data+0xc7>
lea    -0x68(%rbp),%rdi
call   1060 <deflateEnd@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    126e <cl_zlib_compress_data+0x12e>
lea    -0x68(%rbp),%rdi
call   1060 <deflateEnd@plt>
mov    -0x20(%rbp),%rax
sub    -0x58(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x20(%rbp),%rax
jb     1253 <cl_zlib_compress_data+0x113>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
jmp    125a <cl_zlib_compress_data+0x11a>
movl   $0x1,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cl_zlib_compress_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    0x2e6a(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x40(%rsp)
mov    %rax,0x38(%rsp)
mov    %rax,0x30(%rsp)
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1050 <deflateInit@plt>
mov    %rax,%rcx
mov    0x2e63(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%rcx
jne    1216 <cl_zlib_compress_data+0xd6>
mov    %rbx,0x10(%rsp)
mov    %r12,0x18(%rsp)
mov    %r12,0x20(%rsp)
lea    0x1(%rbp),%rax
mov    %rax,0x8(%rsp)
mov    %rax,0x28(%rsp)
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%r13
mov    %r13,%rdi
call   1030 <deflate@plt>
mov    %rax,%r15
mov    0x2e04(%rip),%rax
mov    (%rax),%r14
mov    %r13,%rdi
call   1060 <deflateEnd@plt>
mov    $0xfffffffe,%eax
cmp    %r14,%r15
je     1216 <cl_zlib_compress_data+0xd6>
mov    %r12,%rax
sub    0x20(%rsp),%rax
mov    $0x1,%ecx
cmp    %r12,%rax
jb     1210 <cl_zlib_compress_data+0xd0>
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
xor    %ecx,%ecx
mov    %r12,%rax
mov    %ecx,0x0(%rbp)
add    $0x1,%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*, i64, i64, i8*, i8*, i8*, i8* }
@Z_NULL = global i8* null
@Z_DEFAULT_COMPRESSION = global i32 0
@Z_OK = global i64 0
@Z_FINISH = global i32 0
@Z_STREAM_ERROR = global i64 0
define i32 @cl_zlib_compress_data(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca %struct.TYPE_5__
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%11 = load i8*, i8** @Z_NULL
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 6
store i8* %11, i8** %12
%13 = load i8*, i8** @Z_NULL
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 5
store i8* %13, i8** %14
%15 = load i8*, i8** @Z_NULL
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 4
store i8* %15, i8** %16
%17 = load i32, i32* @Z_DEFAULT_COMPRESSION
%18 = call i64 @deflateInit(%struct.TYPE_5__* %10, i32 %17)
%19 = load i64, i64* @Z_OK
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %3
store i32 -1, i32* %4
br label %63
22: ; preds = %3
%23 = load i8*, i8** %6
%24 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 0
store i8* %23, i8** %24
%25 = load i64, i64* %7
%26 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 1
store i64 %25, i64* %26
%27 = load i64, i64* %7
%28 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 2
store i64 %27, i64* %28
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 3
store i8* %30, i8** %31
%32 = load i32, i32* @Z_FINISH
%33 = call i64 @deflate(%struct.TYPE_5__* %10, i32 %32)
%34 = load i64, i64* @Z_STREAM_ERROR
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %22
%37 = call i32 @deflateEnd(%struct.TYPE_5__* %10)
store i32 -2, i32* %4
br label %63
38: ; preds = %22
%39 = call i32 @deflateEnd(%struct.TYPE_5__* %10)
%40 = load i64, i64* %7
%41 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %10, i32 0, i32 2
%42 = load i64, i64* %41
%43 = sub i64 %40, %42
store i64 %43, i64* %9
%44 = load i64, i64* %9
%45 = load i64, i64* %7
%46 = icmp uge i64 %44, %45
br i1 %46, label %47, label %54
47: ; preds = %38
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = load i8*, i8** %6
%51 = load i64, i64* %7
%52 = call i32 @memcpy(i8* %49, i8* %50, i64 %51)
%53 = load i64, i64* %7
store i64 %53, i64* %9
store i32 0, i32* %8
br label %55
54: ; preds = %38
store i32 1, i32* %8
br label %55
55: ; preds = %54, %47
%56 = load i32, i32* %8
%57 = load i8*, i8** %5
%58 = bitcast i8* %57 to i32*
%59 = getelementptr inbounds i32, i32* %58, i64 0
store i32 %56, i32* %59
%60 = load i64, i64* %9
%61 = add i64 %60, 1
%62 = trunc i64 %61 to i32
store i32 %62, i32* %4
br label %63
63: ; preds = %55, %36, %21
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i8*, i64, i64, i8*, i8*, i8*, i8* }
@Z_NULL = global i8* null
@Z_DEFAULT_COMPRESSION = global i32 0
@Z_OK = global i64 0
@Z_FINISH = global i32 0
@Z_STREAM_ERROR = global i64 0
define i32 @cl_zlib_compress_data(i8* %0, i8* %1, i64 %2) {
%4 = alloca %struct.TYPE_5__
%5 = bitcast %struct.TYPE_5__* %4 to i8*
%6 = load i8*, i8** @Z_NULL
%7 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 6
store i8* %6, i8** %7
%8 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 5
store i8* %6, i8** %8
%9 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 4
store i8* %6, i8** %9
%10 = load i32, i32* @Z_DEFAULT_COMPRESSION
%11 = call i64 @deflateInit(%struct.TYPE_5__* %4, i32 %10)
%12 = load i64, i64* @Z_OK
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %37
14: ; preds = %3
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 0
store i8* %1, i8** %15
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 1
store i64 %2, i64* %16
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 2
store i64 %2, i64* %17
%18 = getelementptr inbounds i8, i8* %0, i64 1
%19 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 3
store i8* %18, i8** %19
%20 = load i32, i32* @Z_FINISH
%21 = call i64 @deflate(%struct.TYPE_5__* %4, i32 %20)
%22 = load i64, i64* @Z_STREAM_ERROR
%23 = icmp eq i64 %21, %22
%24 = call i32 @deflateEnd(%struct.TYPE_5__* %4)
br i1 %23, label %37, label %25
25: ; preds = %14
%26 = load i64, i64* %17
%27 = sub i64 %2, %26
%28 = icmp ult i64 %27, %2
br i1 %28, label %31, label %29
29: ; preds = %25
%30 = call i32 @memcpy(i8* %18, i8* %1, i64 %2)
br label %31
31: ; preds = %25, %29
%32 = phi i32 [ 0, %29 ], [ 1, %25 ]
%33 = phi i64 [ %2, %29 ], [ %27, %25 ]
%34 = bitcast i8* %0 to i32*
store i32 %32, i32* %34
%35 = trunc i64 %33 to i32
%36 = add i32 %35, 1
br label %37
37: ; preds = %14, %3, %31
%38 = phi i32 [ %36, %31 ], [ -1, %3 ], [ -2, %14 ]
ret i32 %38
}