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

/* Variables and functions */
int /*<<< orphan*/ Z_FINISH;
void *Z_NULL;
int Z_OK;
int Z_STREAM_END;
int deflate(TYPE_1__ *, int /*<<< orphan*/);
int deflateInit(TYPE_1__ *, int);
int deflateReset(TYPE_1__ *);
void *malloc(int);
int gzip_compress(void **strm, char *d, char *s, int size, int block_size,
                  int *error) {
  int res = 0;
  z_stream *stream = *strm;
  if (stream == NULL) {
    if ((stream = *strm = malloc(sizeof(z_stream))) == NULL)
      goto failed;
    stream->zalloc = Z_NULL;
    stream->zfree = Z_NULL;
    stream->opaque = 0;
    if ((res = deflateInit(stream, 9)) != Z_OK)
      goto failed;
  } else if ((res = deflateReset(stream)) != Z_OK)
    goto failed;
  stream->next_in = (unsigned char *)s;
  stream->avail_in = size;
  stream->next_out = (unsigned char *)d;
  stream->avail_out = block_size;
  res = deflate(stream, Z_FINISH);
  if (res == Z_STREAM_END)
    return (int)stream->total_out;
  if (res == Z_OK)
    return 0;
failed:
  *error = res;
  return -1;
}


x86 assembly (clang, -O0):
<gzip_compress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11fa <gzip_compress+0xba>
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11a0 <gzip_compress+0x60>
jmp    12a4 <gzip_compress+0x164>
mov    0x2e29(%rip),%rax
mov    (%rax),%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,0x38(%rax)
mov    0x2e17(%rip),%rax
mov    (%rax),%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,0x30(%rax)
mov    -0x40(%rbp),%rax
movq   $0x0,0x28(%rax)
mov    -0x40(%rbp),%rdi
mov    $0x9,%esi
call   1050 <deflateInit@plt>
mov    %eax,-0x34(%rbp)
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%eax
je     11f5 <gzip_compress+0xb5>
jmp    12a4 <gzip_compress+0x164>
jmp    121f <gzip_compress+0xdf>
mov    -0x40(%rbp),%rdi
call   1030 <deflateReset@plt>
mov    %eax,-0x34(%rbp)
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%eax
je     121a <gzip_compress+0xda>
jmp    12a4 <gzip_compress+0x164>
jmp    121f <gzip_compress+0xdf>
mov    -0x20(%rbp),%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x28(%rbp),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,0x18(%rax)
mov    -0x40(%rbp),%rdi
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
call   1040 <deflate@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    0x2d77(%rip),%rcx
cmp    (%rcx),%eax
jne    1281 <gzip_compress+0x141>
mov    -0x40(%rbp),%rax
mov    0x20(%rax),%rax
mov    %eax,-0x4(%rbp)
jmp    12b4 <gzip_compress+0x174>
mov    -0x34(%rbp),%eax
mov    0x2d65(%rip),%rcx
cmp    (%rcx),%eax
jne    129f <gzip_compress+0x15f>
movl   $0x0,-0x4(%rbp)
jmp    12b4 <gzip_compress+0x174>
jmp    12a4 <gzip_compress+0x164>
mov    -0x34(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gzip_compress>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
mov    %r8d,%r15d
mov    %ecx,%r12d
mov    %rdx,%rbp
mov    %rsi,%r13
mov    (%rdi),%rbx
test   %rbx,%rbx
je     116d <gzip_compress+0x2d>
mov    %rbx,%rdi
call   1030 <deflateReset@plt>
jmp    11ac <gzip_compress+0x6c>
mov    %rdi,%r14
mov    $0x40,%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11f6 <gzip_compress+0xb6>
mov    %rax,%rbx
mov    0x2e44(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x38(%rbx)
mov    %rax,0x30(%rbx)
movq   $0x0,0x28(%rbx)
mov    %rbx,%rdi
mov    $0x9,%esi
call   1050 <deflateInit@plt>
mov    0x2e3d(%rip),%rcx
cmp    (%rcx),%eax
jne    11f8 <gzip_compress+0xb8>
mov    %rbp,(%rbx)
mov    %r12d,0x8(%rbx)
mov    %r13,0x10(%rbx)
mov    %r15d,0x18(%rbx)
mov    0x2dfb(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <deflate@plt>
mov    0x2e02(%rip),%rcx
cmp    (%rcx),%eax
jne    11e7 <gzip_compress+0xa7>
mov    0x20(%rbx),%ecx
jmp    1203 <gzip_compress+0xc3>
mov    0x2e02(%rip),%rdx
xor    %ecx,%ecx
cmp    (%rdx),%eax
jne    11f8 <gzip_compress+0xb8>
jmp    1203 <gzip_compress+0xc3>
xor    %eax,%eax
mov    (%rsp),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x8,%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, i64, i64, i8*, i8* }
@Z_NULL = global i8* null
@Z_OK = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
define i32 @gzip_compress(i8** %0, i8* %1, i8* %2, i32 %3, i32 %4, i32* %5) {
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca %struct.TYPE_5__*
store i8** %0, i8*** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32* %5, i32** %13
store i32 0, i32* %14
%16 = load i8**, i8*** %8
%17 = load i8*, i8** %16
%18 = bitcast i8* %17 to %struct.TYPE_5__*
store %struct.TYPE_5__* %18, %struct.TYPE_5__** %15
%19 = load %struct.TYPE_5__*, %struct.TYPE_5__** %15
%20 = icmp eq %struct.TYPE_5__* %19, null
br i1 %20, label %21, label %42
21: ; preds = %6
%22 = call i8* @malloc(i32 64)
%23 = load i8**, i8*** %8
store i8* %22, i8** %23
%24 = bitcast i8* %22 to %struct.TYPE_5__*
store %struct.TYPE_5__* %24, %struct.TYPE_5__** %15
%25 = icmp eq %struct.TYPE_5__* %24, null
br i1 %25, label %26, label %27
26: ; preds = %21
br label %79
27: ; preds = %21
%28 = load i8*, i8** @Z_NULL
%29 = load %struct.TYPE_5__*, %struct.TYPE_5__** %15
%30 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %29, i32 0, i32 7
store i8* %28, i8** %30
%31 = load i8*, i8** @Z_NULL
%32 = load %struct.TYPE_5__*, %struct.TYPE_5__** %15
%33 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %32, i32 0, i32 6
store i8* %31, i8** %33
%34 = load %struct.TYPE_5__*, %struct.TYPE_5__** %15
%35 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %34, i32 0, i32 5
store i64 0, i64* %35
%36 = load %struct.TYPE_5__*, %struct.TYPE_5__** %15
%37 = call i32 @deflateInit(%struct.TYPE_5__* %36, i32 9)
store i32 %37, i32* %14
%38 = load i32, i32* @Z_OK
%39 = icmp ne i32 %37, %38
br i1 %39, label %40, label %41
40: ; preds = %27
br label %79
41: ; preds = %27
br label %49
42: ; preds = %6
%43 = load %struct.TYPE_5__*, %struct.TYPE_5__** %15
%44 = call i32 @deflateReset(%struct.TYPE_5__* %43)
store i32 %44, i32* %14
%45 = load i32, i32* @Z_OK
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %42
br label %79
48: ; preds = %42
br label %49
49: ; preds = %48, %41
%50 = load i8*, i8** %10
%51 = load %struct.TYPE_5__*, %struct.TYPE_5__** %15
%52 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %51, i32 0, i32 0
store i8* %50, i8** %52
%53 = load i32, i32* %11
%54 = load %struct.TYPE_5__*, %struct.TYPE_5__** %15
%55 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %54, i32 0, i32 1
store i32 %53, i32* %55
%56 = load i8*, i8** %9
%57 = load %struct.TYPE_5__*, %struct.TYPE_5__** %15
%58 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %57, i32 0, i32 2
store i8* %56, i8** %58
%59 = load i32, i32* %12
%60 = load %struct.TYPE_5__*, %struct.TYPE_5__** %15
%61 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %60, i32 0, i32 3
store i32 %59, i32* %61
%62 = load %struct.TYPE_5__*, %struct.TYPE_5__** %15
%63 = load i32, i32* @Z_FINISH
%64 = call i32 @deflate(%struct.TYPE_5__* %62, i32 %63)
store i32 %64, i32* %14
%65 = load i32, i32* %14
%66 = load i32, i32* @Z_STREAM_END
%67 = icmp eq i32 %65, %66
br i1 %67, label %68, label %73
68: ; preds = %49
%69 = load %struct.TYPE_5__*, %struct.TYPE_5__** %15
%70 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %69, i32 0, i32 4
%71 = load i64, i64* %70
%72 = trunc i64 %71 to i32
store i32 %72, i32* %7
br label %82
73: ; preds = %49
%74 = load i32, i32* %14
%75 = load i32, i32* @Z_OK
%76 = icmp eq i32 %74, %75
br i1 %76, label %77, label %78
77: ; preds = %73
store i32 0, i32* %7
br label %82
78: ; preds = %73
br label %79
79: ; preds = %78, %47, %40, %26
%80 = load i32, i32* %14
%81 = load i32*, i32** %13
store i32 %80, i32* %81
store i32 -1, i32* %7
br label %82
82: ; preds = %79, %77, %68
%83 = load i32, i32* %7
ret i32 %83
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i8*, i32, i8*, i32, i64, i64, i8*, i8* }
@Z_NULL = global i8* null
@Z_OK = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
define i32 @gzip_compress(i8** nocapture %0, i8* %1, i8* %2, i32 %3, i32 %4, i32* nocapture writeonly %5) {
%7 = bitcast i8** %0 to %struct.TYPE_5__**
%8 = load %struct.TYPE_5__*, %struct.TYPE_5__** %7
%9 = icmp eq %struct.TYPE_5__* %8, null
br i1 %9, label %10, label %22
10: ; preds = %6
%11 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
store i8* %11, i8** %0
%12 = bitcast i8* %11 to %struct.TYPE_5__*
%13 = icmp eq i8* %11, null
br i1 %13, label %43, label %14
14: ; preds = %10
%15 = load i8*, i8** @Z_NULL
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i64 0, i32 7
store i8* %15, i8** %16
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i64 0, i32 6
store i8* %15, i8** %17
%18 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %12, i64 0, i32 5
store i64 0, i64* %18
%19 = tail call i32 @deflateInit(%struct.TYPE_5__* %12, i32 9)
%20 = load i32, i32* @Z_OK
%21 = icmp eq i32 %19, %20
br i1 %21, label %26, label %43
22: ; preds = %6
%23 = tail call i32 @deflateReset(%struct.TYPE_5__* %8)
%24 = load i32, i32* @Z_OK
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %43
26: ; preds = %22, %14
%27 = phi %struct.TYPE_5__* [ %12, %14 ], [ %8, %22 ]
%28 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %27, i64 0, i32 0
store i8* %2, i8** %28
%29 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %27, i64 0, i32 1
store i32 %3, i32* %29
%30 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %27, i64 0, i32 2
store i8* %1, i8** %30
%31 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %27, i64 0, i32 3
store i32 %4, i32* %31
%32 = load i32, i32* @Z_FINISH
%33 = tail call i32 @deflate(%struct.TYPE_5__* %27, i32 %32)
%34 = load i32, i32* @Z_STREAM_END
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %40
36: ; preds = %26
%37 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %27, i64 0, i32 4
%38 = load i64, i64* %37
%39 = trunc i64 %38 to i32
br label %45
40: ; preds = %26
%41 = load i32, i32* @Z_OK
%42 = icmp eq i32 %33, %41
br i1 %42, label %45, label %43
43: ; preds = %40, %22, %14, %10
%44 = phi i32 [ 0, %10 ], [ %19, %14 ], [ %33, %40 ], [ %23, %22 ]
store i32 %44, i32* %5
br label %45
45: ; preds = %40, %43, %36
%46 = phi i32 [ -1, %43 ], [ %39, %36 ], [ 0, %40 ]
ret i32 %46
}