#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 */
char *deflateCpy(char *, unsigned int, unsigned int *);
int /*<<< orphan*/ freeDHBuf(char *);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
int deflateInplace(char *buf, unsigned buflen, unsigned buftotal) {
  unsigned cmp_sz = 0;
  char *altbuf = deflateCpy(buf, buflen, &cmp_sz);
  if (!altbuf || cmp_sz > buftotal) {
    freeDHBuf(altbuf);
    return -1;
  }
  memcpy(buf, altbuf, cmp_sz);
  freeDHBuf(altbuf);
  return cmp_sz;
}


x86 assembly (clang, -O0):
<deflateInplace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x1c(%rbp),%rdx
call   1050 <deflateCpy@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1174 <deflateInplace+0x44>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jbe    1189 <deflateInplace+0x59>
mov    -0x28(%rbp),%rdi
call   1040 <freeDHBuf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a8 <deflateInplace+0x78>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1040 <freeDHBuf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deflateInplace>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rdi,%r14
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdx
call   1050 <deflateCpy@plt>
mov    %rax,%rbx
test   %rax,%rax
je     115f <deflateInplace+0x2f>
mov    0xc(%rsp),%edx
cmp    %ebp,%edx
jbe    116e <deflateInplace+0x3e>
mov    %rbx,%rdi
call   1040 <freeDHBuf@plt>
mov    $0xffffffff,%eax
jmp    1185 <deflateInplace+0x55>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <memcpy@plt>
mov    %rbx,%rdi
call   1040 <freeDHBuf@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @deflateInplace(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %8
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = call i8* @deflateCpy(i8* %10, i32 %11, i32* %8)
store i8* %12, i8** %9
%13 = load i8*, i8** %9
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = icmp ugt i32 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %15, %3
%20 = load i8*, i8** %9
%21 = call i32 @freeDHBuf(i8* %20)
store i32 -1, i32* %4
br label %30
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = load i8*, i8** %9
%25 = load i32, i32* %8
%26 = call i32 @memcpy(i8* %23, i8* %24, i32 %25)
%27 = load i8*, i8** %9
%28 = call i32 @freeDHBuf(i8* %27)
%29 = load i32, i32* %8
store i32 %29, i32* %4
br label %30
30: ; preds = %22, %19
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @deflateInplace(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%6 = call i8* @deflateCpy(i8* %0, i32 %1, i32* %4)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = load i32, i32* %4
%10 = icmp ugt i32 %9, %2
br i1 %10, label %11, label %13
11: ; preds = %8, %3
%12 = call i32 @freeDHBuf(i8* %6)
br label %17
13: ; preds = %8
%14 = call i32 @memcpy(i8* %0, i8* %6, i32 %9)
%15 = call i32 @freeDHBuf(i8* %6)
%16 = load i32, i32* %4
br label %17
17: ; preds = %13, %11
%18 = phi i32 [ -1, %11 ], [ %16, %13 ]
ret i32 %18
}