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

/* Variables and functions */
int /*<<< orphan*/ Z_BEST_COMPRESSION;
int /*<<< orphan*/ Z_FINISH;
int /*<<< orphan*/ Z_NULL;
int Z_OK;
int Z_STREAM_END;
int deflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ deflateEnd(TYPE_1__ *);
int deflateInit(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int compress_data(char *buf, char *data, uint32_t dataSize) {
  int res;
  z_stream defstream = {.zalloc = Z_NULL,
                        .zfree = Z_NULL,
                        .opaque = Z_NULL,
                        .avail_in = dataSize,
                        .next_in = (Bytef *)data,
                        .avail_out = 131072,
                        .next_out = (Bytef *)buf};
  if ((res = deflateInit(&defstream, Z_BEST_COMPRESSION)) != Z_OK) {
    printf("cRIP1");
    return 0;
  }
  res = deflate(&defstream, Z_FINISH);
  deflateEnd(&defstream);
  if (res != Z_STREAM_END) {
    printf("cRIP2: %d\n", res);
    printf("availin %d availaout: %d\n", defstream.avail_in,
           defstream.avail_out);
    return 0;
  }
  res = defstream.total_out;
  return res;
}


x86 assembly (clang, -O0):
<compress_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x50(%rbp)
movl   $0x20000,-0x4c(%rbp)
movl   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdi
call   1050 <deflateInit@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%eax
je     11d9 <compress_data+0x99>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1246 <compress_data+0x106>
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdi
call   1040 <deflate@plt>
mov    %eax,-0x20(%rbp)
lea    -0x50(%rbp),%rdi
call   1060 <deflateEnd@plt>
mov    -0x20(%rbp),%eax
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%eax
je     123a <compress_data+0xfa>
mov    -0x20(%rbp),%esi
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%esi
mov    -0x4c(%rbp),%edx
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1246 <compress_data+0x106>
mov    -0x48(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compress_data>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %edx,0x8(%rsp)
movq   $0x20000,0xc(%rsp)
mov    %rdi,0x18(%rsp)
mov    %rsi,0x20(%rsp)
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
mov    %eax,0x2c(%rsp)
mov    %eax,0x30(%rsp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdi
call   1050 <deflateInit@plt>
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%eax
jne    11c1 <compress_data+0x81>
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <deflate@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <deflateEnd@plt>
mov    0x2e29(%rip),%rax
cmp    (%rax),%ebp
jne    11d3 <compress_data+0x93>
mov    0x10(%rsp),%ebx
jmp    11fb <compress_data+0xbb>
lea    0xe38(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11fb <compress_data+0xbb>
lea    0xe2c(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i32, i32, i32, i32*, i32*, i32, i32, i32 }
@Z_NULL = global i32 0
@Z_BEST_COMPRESSION = global i32 0
@Z_OK = global i32 0
@.str = [6 x i8] c"cRIP1\00"
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@.str.1 = [11 x i8] c"cRIP2: %d\0A\00"
@.str.2 = [26 x i8] c"availin %d availaout: %d\0A\00"
define i32 @compress_data(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.TYPE_5__
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 0
%11 = load i32, i32* %7
store i32 %11, i32* %10
%12 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 1
store i32 131072, i32* %12
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 2
store i32 0, i32* %13
%14 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 3
%15 = load i8*, i8** %5
%16 = bitcast i8* %15 to i32*
store i32* %16, i32** %14
%17 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 4
%18 = load i8*, i8** %6
%19 = bitcast i8* %18 to i32*
store i32* %19, i32** %17
%20 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 5
%21 = load i32, i32* @Z_NULL
store i32 %21, i32* %20
%22 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 6
%23 = load i32, i32* @Z_NULL
store i32 %23, i32* %22
%24 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 7
%25 = load i32, i32* @Z_NULL
store i32 %25, i32* %24
%26 = load i32, i32* @Z_BEST_COMPRESSION
%27 = call i32 @deflateInit(%struct.TYPE_5__* %9, i32 %26)
store i32 %27, i32* %8
%28 = load i32, i32* @Z_OK
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %32
30: ; preds = %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %51
32: ; preds = %3
%33 = load i32, i32* @Z_FINISH
%34 = call i32 @deflate(%struct.TYPE_5__* %9, i32 %33)
store i32 %34, i32* %8
%35 = call i32 @deflateEnd(%struct.TYPE_5__* %9)
%36 = load i32, i32* %8
%37 = load i32, i32* @Z_STREAM_END
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %47
39: ; preds = %32
%40 = load i32, i32* %8
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 0
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 1
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %43, i32 %45)
store i32 0, i32* %4
br label %51
47: ; preds = %32
%48 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 2
%49 = load i32, i32* %48
store i32 %49, i32* %8
%50 = load i32, i32* %8
store i32 %50, i32* %4
br label %51
51: ; preds = %47, %39, %30
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i32, i32, i32*, i32*, i32, i32, i32 }
@Z_NULL = global i32 0
@Z_BEST_COMPRESSION = global i32 0
@Z_OK = global i32 0
@.str = [6 x i8] c"cRIP1\00"
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@.str.1 = [11 x i8] c"cRIP2: %d\0A\00"
@.str.2 = [26 x i8] c"availin %d availaout: %d\0A\00"
define i32 @compress_data(i8* %0, i8* %1, i32 %2) {
%4 = alloca %struct.TYPE_5__
%5 = bitcast %struct.TYPE_5__* %4 to i8*
%6 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 0
store i32 %2, i32* %6
%7 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 1
store i32 131072, i32* %7
%8 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 2
store i32 0, i32* %8
%9 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 3
%10 = bitcast i32** %9 to i8**
store i8* %0, i8** %10
%11 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 4
%12 = bitcast i32** %11 to i8**
store i8* %1, i8** %12
%13 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 5
%14 = load i32, i32* @Z_NULL
store i32 %14, i32* %13
%15 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 6
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %4, i64 0, i32 7
store i32 %14, i32* %16
%17 = load i32, i32* @Z_BEST_COMPRESSION
%18 = call i32 @deflateInit(%struct.TYPE_5__* %4, i32 %17)
%19 = load i32, i32* @Z_OK
%20 = icmp eq i32 %18, %19
br i1 %20, label %23, label %21
21: ; preds = %3
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %36
23: ; preds = %3
%24 = load i32, i32* @Z_FINISH
%25 = call i32 @deflate(%struct.TYPE_5__* %4, i32 %24)
%26 = call i32 @deflateEnd(%struct.TYPE_5__* %4)
%27 = load i32, i32* @Z_STREAM_END
%28 = icmp eq i32 %25, %27
br i1 %28, label %34, label %29
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %32)
br label %36
34: ; preds = %23
%35 = load i32, i32* %8
br label %36
36: ; preds = %34, %29, %21
%37 = phi i32 [ 0, %21 ], [ 0, %29 ], [ %35, %34 ]
ret i32 %37
}