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

/* Variables and functions */
int Z_BUF_ERROR;
int /*<<< orphan*/ Z_FINISH;
void *Z_NULL;
int Z_OK;
int Z_STREAM_END;
int deflate(TYPE_1__ *, int /*<<< orphan*/);
int deflateEnd(TYPE_1__ *);
int deflateInit(TYPE_1__ *, int);
int compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
              uLong sourceLen, int level) {
  z_stream stream;
  int err;
  stream.next_in = (Bytef *)source;
  stream.avail_in = (uInt)sourceLen;
  stream.next_out = dest;
  stream.avail_out = (uInt)*destLen;
  if ((uLong)stream.avail_out != *destLen)
    return Z_BUF_ERROR;
  stream.zalloc = Z_NULL;
  stream.zfree = Z_NULL;
  stream.opaque = (voidpf)0;
  err = deflateInit(&stream, level);
  if (err != Z_OK)
    return err;
  err = deflate(&stream, Z_FINISH);
  if (err != Z_STREAM_END) {
    deflateEnd(&stream);
    return err == Z_OK ? Z_BUF_ERROR : err;
  }
  *destLen = stream.total_out;
  err = deflateEnd(&stream);
  return err;
}


x86 assembly (clang, -O0):
<compress2>:
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    %r8d,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
je     1194 <compress2+0x64>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1265 <compress2+0x135>
mov    0x2e2d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x68(%rbp)
mov    -0x2c(%rbp),%esi
lea    -0x70(%rbp),%rdi
call   1040 <deflateInit@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%eax
je     11e4 <compress2+0xb4>
mov    -0x74(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1265 <compress2+0x135>
mov    0x2dd5(%rip),%rax
mov    (%rax),%esi
lea    -0x70(%rbp),%rdi
call   1030 <deflate@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    0x2ddd(%rip),%rcx
cmp    (%rcx),%eax
je     1248 <compress2+0x118>
lea    -0x70(%rbp),%rdi
call   1050 <deflateEnd@plt>
mov    -0x74(%rbp),%eax
mov    0x2dd2(%rip),%rcx
cmp    (%rcx),%eax
jne    1237 <compress2+0x107>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
jmp    123d <compress2+0x10d>
mov    -0x74(%rbp),%eax
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1265 <compress2+0x135>
mov    -0x70(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x70(%rbp),%rdi
call   1050 <deflateEnd@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress2>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%rbx
mov    %rdx,0x38(%rsp)
mov    %rcx,0x30(%rsp)
mov    %rdi,0x28(%rsp)
mov    (%rsi),%rax
mov    %rax,0x20(%rsp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
mov    %rax,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rdi
mov    %r8d,%esi
call   1040 <deflateInit@plt>
mov    %eax,%ebp
mov    0x2e6d(%rip),%r14
cmp    (%r14),%eax
jne    11cf <compress2+0x9f>
mov    0x2e31(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1030 <deflate@plt>
mov    %eax,%ebp
mov    0x2e3e(%rip),%rax
cmp    (%rax),%ebp
jne    11b9 <compress2+0x89>
mov    (%rsp),%rax
mov    %rax,(%rbx)
mov    %rsp,%rdi
call   1050 <deflateEnd@plt>
mov    %eax,%ebp
jmp    11cf <compress2+0x9f>
mov    %rsp,%rdi
call   1050 <deflateEnd@plt>
cmp    (%r14),%ebp
jne    11cf <compress2+0x9f>
mov    0x2e0b(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i64, i64, i8*, i8*, i8*, i32*, i8*, i32* }
@Z_BUF_ERROR = global i32 0
@Z_NULL = global i8* null
@Z_OK = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
define i32 @compress2(i32* %0, i64* %1, i32* %2, i64 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i64*
%9 = alloca i32*
%10 = alloca i64
%11 = alloca i32
%12 = alloca %struct.TYPE_5__
%13 = alloca i32
store i32* %0, i32** %7
store i64* %1, i64** %8
store i32* %2, i32** %9
store i64 %3, i64* %10
store i32 %4, i32* %11
%14 = load i32*, i32** %9
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 7
store i32* %14, i32** %15
%16 = load i64, i64* %10
%17 = inttoptr i64 %16 to i8*
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 6
store i8* %17, i8** %18
%19 = load i32*, i32** %7
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 5
store i32* %19, i32** %20
%21 = load i64*, i64** %8
%22 = load i64, i64* %21
%23 = inttoptr i64 %22 to i8*
%24 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 4
store i8* %23, i8** %24
%25 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 4
%26 = load i8*, i8** %25
%27 = ptrtoint i8* %26 to i64
%28 = load i64*, i64** %8
%29 = load i64, i64* %28
%30 = icmp ne i64 %27, %29
br i1 %30, label %31, label %33
31: ; preds = %5
%32 = load i32, i32* @Z_BUF_ERROR
store i32 %32, i32* %6
br label %69
33: ; preds = %5
%34 = load i8*, i8** @Z_NULL
%35 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 3
store i8* %34, i8** %35
%36 = load i8*, i8** @Z_NULL
%37 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 2
store i8* %36, i8** %37
%38 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 1
store i64 0, i64* %38
%39 = load i32, i32* %11
%40 = call i32 @deflateInit(%struct.TYPE_5__* %12, i32 %39)
store i32 %40, i32* %13
%41 = load i32, i32* %13
%42 = load i32, i32* @Z_OK
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %33
%45 = load i32, i32* %13
store i32 %45, i32* %6
br label %69
46: ; preds = %33
%47 = load i32, i32* @Z_FINISH
%48 = call i32 @deflate(%struct.TYPE_5__* %12, i32 %47)
store i32 %48, i32* %13
%49 = load i32, i32* %13
%50 = load i32, i32* @Z_STREAM_END
%51 = icmp ne i32 %49, %50
br i1 %51, label %52, label %63
52: ; preds = %46
%53 = call i32 @deflateEnd(%struct.TYPE_5__* %12)
%54 = load i32, i32* %13
%55 = load i32, i32* @Z_OK
%56 = icmp eq i32 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = load i32, i32* @Z_BUF_ERROR
br label %61
59: ; preds = %52
%60 = load i32, i32* %13
br label %61
61: ; preds = %59, %57
%62 = phi i32 [ %58, %57 ], [ %60, %59 ]
store i32 %62, i32* %6
br label %69
63: ; preds = %46
%64 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i32 0, i32 0
%65 = load i64, i64* %64
%66 = load i64*, i64** %8
store i64 %65, i64* %66
%67 = call i32 @deflateEnd(%struct.TYPE_5__* %12)
store i32 %67, i32* %13
%68 = load i32, i32* %13
store i32 %68, i32* %6
br label %69
69: ; preds = %63, %61, %44, %31
%70 = load i32, i32* %6
ret i32 %70
}

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