#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 */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ Z_BEST_COMPRESSION;
int compress2(unsigned char *, unsigned long *, unsigned char const *,
              unsigned long, int /*<<< orphan*/);
unsigned long compressBound(unsigned long);
unsigned char *malloc(unsigned long);
int zlib_compress(unsigned char **dst, unsigned long *dstlen,
                  const unsigned char *src, unsigned long srclen) {
  *dstlen = compressBound(srclen);
  *dst = malloc(*dstlen);
  if (*dst == NULL)
    return -1;
  return compress2(*dst, dstlen, src, srclen, Z_BEST_COMPRESSION);
}


x86 assembly (clang, -O0):
<zlib_compress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <compressBound@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    118b <zlib_compress+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b0 <zlib_compress+0x80>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    0x2e43(%rip),%rax
mov    (%rax),%r8d
call   1050 <compress2@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zlib_compress>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rcx,%rdi
call   1030 <compressBound@plt>
mov    %rax,(%rbx)
mov    %rax,%rdi
call   1040 <malloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     1186 <zlib_compress+0x56>
mov    0x2e81(%rip),%rcx
mov    (%rcx),%r8d
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <compress2@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@Z_BEST_COMPRESSION = global i32 0
define i32 @zlib_compress(i8** %0, i64* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i64
store i8** %0, i8*** %6
store i64* %1, i64** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%10 = load i64, i64* %9
%11 = call i64 @compressBound(i64 %10)
%12 = load i64*, i64** %7
store i64 %11, i64* %12
%13 = load i64*, i64** %7
%14 = load i64, i64* %13
%15 = call i8* @malloc(i64 %14)
%16 = load i8**, i8*** %6
store i8* %15, i8** %16
%17 = load i8**, i8*** %6
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 -1, i32* %5
br label %29
21: ; preds = %4
%22 = load i8**, i8*** %6
%23 = load i8*, i8** %22
%24 = load i64*, i64** %7
%25 = load i8*, i8** %8
%26 = load i64, i64* %9
%27 = load i32, i32* @Z_BEST_COMPRESSION
%28 = call i32 @compress2(i8* %23, i64* %24, i8* %25, i64 %26, i32 %27)
store i32 %28, i32* %5
br label %29
29: ; preds = %21, %20
%30 = load i32, i32* %5
ret i32 %30
}

LLVM IR (-O2):
@Z_BEST_COMPRESSION = global i32 0
define i32 @zlib_compress(i8** nocapture writeonly %0, i64* %1, i8* %2, i64 %3) {
%5 = tail call i64 @compressBound(i64 %3)
store i64 %5, i64* %1
%6 = tail call i8* @malloc(i64 %5)
store i8* %6, i8** %0
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %4
%9 = load i32, i32* @Z_BEST_COMPRESSION
%10 = tail call i32 @compress2(i8* %6, i64* %1, i8* %2, i64 %3, i32 %9)
br label %11
11: ; preds = %4, %8
%12 = phi i32 [ %10, %8 ], [ -1, %4 ]
ret i32 %12
}