#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 */
scalar_t__ Z_DATA_ERROR;
scalar_t__ _inflate(void const *, long, void *, long);
int /*<<< orphan*/ free(void *);
void *malloc(long);
int gu_decompress_mem(const void *src, long src_size, void **dst,
                      long *dst_size) {
  *dst_size = *(long *)&((unsigned char *)src)[src_size - 4];
  *dst = malloc(*dst_size);
  if (Z_DATA_ERROR == _inflate(src, src_size, *dst, *dst_size)) {
    free(*dst);
    *dst = (void *)src;
    *dst_size = src_size;
  }
  return 0;
}


x86 assembly (clang, -O0):
<gu_decompress_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x4,%rcx
mov    (%rax,%rcx,1),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2e74(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
call   1050 <_inflate@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jne    11d0 <gu_decompress_mem+0xa0>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gu_decompress_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
mov    -0x4(%rsi,%rdi,1),%rbx
mov    %rbx,(%rcx)
mov    %rbx,%rdi
call   1040 <malloc@plt>
mov    %rax,(%r15)
mov    0x2e8f(%rip),%rcx
mov    (%rcx),%rbp
mov    %r13,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1050 <_inflate@plt>
cmp    %rax,%rbp
jne    1188 <gu_decompress_mem+0x58>
mov    (%r15),%rdi
call   1030 <free@plt>
mov    %r13,(%r15)
mov    %r12,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@Z_DATA_ERROR = global i64 0
define i32 @gu_decompress_mem(i8* %0, i64 %1, i8** %2, i64* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8**
%8 = alloca i64*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8** %2, i8*** %7
store i64* %3, i64** %8
%9 = load i8*, i8** %5
%10 = load i64, i64* %6
%11 = sub nsw i64 %10, 4
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = bitcast i8* %12 to i64*
%14 = load i64, i64* %13
%15 = load i64*, i64** %8
store i64 %14, i64* %15
%16 = load i64*, i64** %8
%17 = load i64, i64* %16
%18 = call i8* @malloc(i64 %17)
%19 = load i8**, i8*** %7
store i8* %18, i8** %19
%20 = load i64, i64* @Z_DATA_ERROR
%21 = load i8*, i8** %5
%22 = load i64, i64* %6
%23 = load i8**, i8*** %7
%24 = load i8*, i8** %23
%25 = load i64*, i64** %8
%26 = load i64, i64* %25
%27 = call i64 @_inflate(i8* %21, i64 %22, i8* %24, i64 %26)
%28 = icmp eq i64 %20, %27
br i1 %28, label %29, label %37
29: ; preds = %4
%30 = load i8**, i8*** %7
%31 = load i8*, i8** %30
%32 = call i32 @free(i8* %31)
%33 = load i8*, i8** %5
%34 = load i8**, i8*** %7
store i8* %33, i8** %34
%35 = load i64, i64* %6
%36 = load i64*, i64** %8
store i64 %35, i64* %36
br label %37
37: ; preds = %29, %4
ret i32 0
}

LLVM IR (-O2):
@Z_DATA_ERROR = global i64 0
define i32 @gu_decompress_mem(i8* %0, i64 %1, i8** nocapture %2, i64* nocapture writeonly %3) {
%5 = add nsw i64 %1, -4
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = bitcast i8* %6 to i64*
%8 = load i64, i64* %7
store i64 %8, i64* %3
%9 = tail call i8* @malloc(i64 %8)
store i8* %9, i8** %2
%10 = load i64, i64* @Z_DATA_ERROR
%11 = tail call i64 @_inflate(i8* %0, i64 %1, i8* %9, i64 %8)
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = load i8*, i8** %2
%15 = tail call i32 @free(i8* %14)
store i8* %0, i8** %2
store i64 %1, i64* %3
br label %16
16: ; preds = %13, %4
ret i32 0
}