#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_6__ TYPE_1__;

/* Type definitions */
struct TYPE_6__ {
  size_t avail_in;
  void *next_in;
  size_t avail_out;
  void *next_out;
};
typedef TYPE_1__ z_stream;

/* Variables and functions */
int /*<<< orphan*/ Z_DEFAULT_STRATEGY;
int /*<<< orphan*/ Z_DEFLATED;
int /*<<< orphan*/ Z_FINISH;
int /*<<< orphan*/ deflate(TYPE_1__ *, int /*<<< orphan*/);
size_t deflateBound(TYPE_1__ *, size_t);
int /*<<< orphan*/ deflateEnd(TYPE_1__ *);
int /*<<< orphan*/ deflateInit2(TYPE_1__ *, int, int /*<<< orphan*/, int, int,
                                int /*<<< orphan*/);
void *malloc(size_t);
void *Gzip_deflate(void *src, size_t *len) {
  z_stream stream = {
      .avail_in = *len,
      .next_in = src,
  };
  size_t dst_len;
  void *dst;
  deflateInit2(&stream, 9, Z_DEFLATED, 15 + 16, 8, Z_DEFAULT_STRATEGY);
  dst_len = deflateBound(&stream, *len);
  dst = malloc(dst_len);
  stream.avail_out = dst_len;
  stream.next_out = dst;
  deflate(&stream, Z_FINISH);
  *len = dst_len - stream.avail_out;
  deflateEnd(&stream);
  return dst;
}


x86 assembly (clang, -O0):
<Gzip_deflate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
mov    0x2e35(%rip),%rax
mov    (%rax),%r9d
lea    -0x30(%rbp),%rdi
mov    $0x9,%esi
mov    $0x1f,%ecx
mov    $0x8,%r8d
call   1070 <deflateInit2@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    -0x30(%rbp),%rdi
call   1040 <deflateBound@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdi
call   1030 <deflate@plt>
mov    -0x38(%rbp),%rcx
sub    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x30(%rbp),%rdi
call   1060 <deflateEnd@plt>
mov    -0x40(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Gzip_deflate>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r15
mov    (%rsi),%rax
mov    %rax,0x8(%rsp)
mov    %rdi,0x10(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
mov    0x2e66(%rip),%rax
mov    (%rax),%edx
mov    0x2e45(%rip),%rax
mov    (%rax),%r9d
lea    0x8(%rsp),%r14
mov    %r14,%rdi
mov    $0x9,%esi
mov    $0x1f,%ecx
mov    $0x8,%r8d
call   1070 <deflateInit2@plt>
mov    (%r15),%rsi
mov    %r14,%rdi
call   1040 <deflateBound@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %rbx,0x18(%rsp)
mov    %rax,0x20(%rsp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1030 <deflate@plt>
sub    0x18(%rsp),%rbx
mov    %rbx,(%r15)
mov    %r14,%rdi
call   1060 <deflateEnd@plt>
mov    %r12,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_6__ = type { i64, i8*, i64, i8* }
@Z_DEFLATED = global i32 0
@Z_DEFAULT_STRATEGY = global i32 0
@Z_FINISH = global i32 0
define i8* @Gzip_deflate(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca %struct.TYPE_6__
%6 = alloca i64
%7 = alloca i8*
store i8* %0, i8** %3
store i64* %1, i64** %4
%8 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 0
%9 = load i64*, i64** %4
%10 = load i64, i64* %9
store i64 %10, i64* %8
%11 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 1
%12 = load i8*, i8** %3
store i8* %12, i8** %11
%13 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 2
store i64 0, i64* %13
%14 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 3
store i8* null, i8** %14
%15 = load i32, i32* @Z_DEFLATED
%16 = load i32, i32* @Z_DEFAULT_STRATEGY
%17 = call i32 @deflateInit2(%struct.TYPE_6__* %5, i32 9, i32 %15, i32 31, i32 8, i32 %16)
%18 = load i64*, i64** %4
%19 = load i64, i64* %18
%20 = call i64 @deflateBound(%struct.TYPE_6__* %5, i64 %19)
store i64 %20, i64* %6
%21 = load i64, i64* %6
%22 = call i8* @malloc(i64 %21)
store i8* %22, i8** %7
%23 = load i64, i64* %6
%24 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 2
store i64 %23, i64* %24
%25 = load i8*, i8** %7
%26 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 3
store i8* %25, i8** %26
%27 = load i32, i32* @Z_FINISH
%28 = call i32 @deflate(%struct.TYPE_6__* %5, i32 %27)
%29 = load i64, i64* %6
%30 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %5, i32 0, i32 2
%31 = load i64, i64* %30
%32 = sub i64 %29, %31
%33 = load i64*, i64** %4
store i64 %32, i64* %33
%34 = call i32 @deflateEnd(%struct.TYPE_6__* %5)
%35 = load i8*, i8** %7
ret i8* %35
}

LLVM IR (-O2):
%struct.TYPE_6__ = type { i64, i8*, i64, i8* }
@Z_DEFLATED = global i32 0
@Z_DEFAULT_STRATEGY = global i32 0
@Z_FINISH = global i32 0
define i8* @Gzip_deflate(i8* %0, i64* nocapture %1) {
%3 = alloca %struct.TYPE_6__
%4 = bitcast %struct.TYPE_6__* %3 to i8*
%5 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 0
%6 = load i64, i64* %1
store i64 %6, i64* %5
%7 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 1
store i8* %0, i8** %7
%8 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 2
%9 = getelementptr inbounds %struct.TYPE_6__, %struct.TYPE_6__* %3, i64 0, i32 3
%10 = bitcast i64* %8 to i8*
%11 = load i32, i32* @Z_DEFLATED
%12 = load i32, i32* @Z_DEFAULT_STRATEGY
%13 = call i32 @deflateInit2(%struct.TYPE_6__* %3, i32 9, i32 %11, i32 31, i32 8, i32 %12)
%14 = load i64, i64* %1
%15 = call i64 @deflateBound(%struct.TYPE_6__* %3, i64 %14)
%16 = call i8* @malloc(i64 %15)
store i64 %15, i64* %8
store i8* %16, i8** %9
%17 = load i32, i32* @Z_FINISH
%18 = call i32 @deflate(%struct.TYPE_6__* %3, i32 %17)
%19 = load i64, i64* %8
%20 = sub i64 %15, %19
store i64 %20, i64* %1
%21 = call i32 @deflateEnd(%struct.TYPE_6__* %3)
ret i8* %16
}