#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_FINISH;
int /*<<< orphan*/ Z_NULL;
int Z_OK;
int Z_STREAM_END;
int inflate(TYPE_1__ *, int /*<<< orphan*/);
int /*<<< orphan*/ inflateEnd(TYPE_1__ *);
int inflateInit(TYPE_1__ *);
int /*<<< orphan*/ printf(char *, ...);
int decompress_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 = inflateInit(&defstream)) != Z_OK) {
    printf("dRIP1\n");
    return 0;
  }
  res = inflate(&defstream, Z_FINISH);
  inflateEnd(&defstream);
  if (res != Z_STREAM_END) {
    printf("dRIP2: %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):
<decompress_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    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
call   1050 <inflateInit@plt>
mov    %eax,-0x20(%rbp)
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%eax
je     11d0 <decompress_data+0x90>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    123d <decompress_data+0xfd>
mov    0x2df1(%rip),%rax
mov    (%rax),%esi
lea    -0x50(%rbp),%rdi
call   1030 <inflate@plt>
mov    %eax,-0x20(%rbp)
lea    -0x50(%rbp),%rdi
call   1060 <inflateEnd@plt>
mov    -0x20(%rbp),%eax
mov    0x2de8(%rip),%rcx
cmp    (%rcx),%eax
je     1231 <decompress_data+0xf1>
mov    -0x20(%rbp),%esi
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%esi
mov    -0x4c(%rbp),%edx
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    123d <decompress_data+0xfd>
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):
<decompress_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    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
mov    %eax,0x2c(%rsp)
mov    %eax,0x30(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <inflateInit@plt>
mov    0x2e5d(%rip),%rcx
cmp    (%rcx),%eax
jne    11c8 <decompress_data+0x78>
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <inflate@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <inflateEnd@plt>
mov    0x2e22(%rip),%rax
cmp    (%rax),%ebp
jne    11d8 <decompress_data+0x88>
mov    0x10(%rsp),%ebx
jmp    1200 <decompress_data+0xb0>
lea    0xe56(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
jmp    1200 <decompress_data+0xb0>
lea    0xe21(%rip),%rdi
xor    %ebx,%ebx
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe12(%rip),%rdi
xor    %eax,%eax
call   1050 <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_OK = global i32 0
@.str = [7 x i8] c"dRIP1\0A\00"
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@.str.1 = [11 x i8] c"dRIP2: %d\0A\00"
@.str.2 = [26 x i8] c"availin %d availaout: %d\0A\00"
define i32 @decompress_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 = call i32 @inflateInit(%struct.TYPE_5__* %9)
store i32 %26, i32* %8
%27 = load i32, i32* @Z_OK
%28 = icmp ne i32 %26, %27
br i1 %28, label %29, label %31
29: ; preds = %3
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %50
31: ; preds = %3
%32 = load i32, i32* @Z_FINISH
%33 = call i32 @inflate(%struct.TYPE_5__* %9, i32 %32)
store i32 %33, i32* %8
%34 = call i32 @inflateEnd(%struct.TYPE_5__* %9)
%35 = load i32, i32* %8
%36 = load i32, i32* @Z_STREAM_END
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %46
38: ; preds = %31
%39 = load i32, i32* %8
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 1
%44 = load i32, i32* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %42, i32 %44)
store i32 0, i32* %4
br label %50
46: ; preds = %31
%47 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %9, i32 0, i32 2
%48 = load i32, i32* %47
store i32 %48, i32* %8
%49 = load i32, i32* %8
store i32 %49, i32* %4
br label %50
50: ; preds = %46, %38, %29
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i32, i32, i32, i32*, i32*, i32, i32, i32 }
@Z_NULL = global i32 0
@Z_OK = global i32 0
@Z_FINISH = global i32 0
@Z_STREAM_END = global i32 0
@.str.1 = [11 x i8] c"dRIP2: %d\0A\00"
@.str.2 = [26 x i8] c"availin %d availaout: %d\0A\00"
@str = [6 x i8] c"dRIP1\00"
define i32 @decompress_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 = call i32 @inflateInit(%struct.TYPE_5__* %4)
%18 = load i32, i32* @Z_OK
%19 = icmp eq i32 %17, %18
br i1 %19, label %22, label %20
20: ; preds = %3
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %35
22: ; preds = %3
%23 = load i32, i32* @Z_FINISH
%24 = call i32 @inflate(%struct.TYPE_5__* %4, i32 %23)
%25 = call i32 @inflateEnd(%struct.TYPE_5__* %4)
%26 = load i32, i32* @Z_STREAM_END
%27 = icmp eq i32 %24, %26
br i1 %27, label %33, label %28
28: ; preds = %22
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%30 = load i32, i32* %6
%31 = load i32, i32* %7
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %31)
br label %35
33: ; preds = %22
%34 = load i32, i32* %8
br label %35
35: ; preds = %33, %28, %20
%36 = phi i32 [ 0, %20 ], [ 0, %28 ], [ %34, %33 ]
ret i32 %36
}