#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 */
int /*<<< orphan*/ freeDHBuf(char *);
char *inflateCpy(char *, unsigned int, unsigned int, unsigned int *);
int /*<<< orphan*/ memcpy(char *, char *, unsigned int);
int inflateInplace(char *buf, unsigned buflen_comp, unsigned bufsize) {
  unsigned uncmp_sz = 0;
  char *altbuf = inflateCpy(buf, buflen_comp, bufsize, &uncmp_sz);
  if (!altbuf || uncmp_sz > bufsize) {
    freeDHBuf(altbuf);
    return -1;
  }
  memcpy(buf, altbuf, uncmp_sz);
  freeDHBuf(altbuf);
  return uncmp_sz;
}


x86 assembly (clang, -O0):
<inflateInplace>:
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
mov    -0x18(%rbp),%edx
lea    -0x1c(%rbp),%rcx
call   1050 <inflateCpy@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1177 <inflateInplace+0x47>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jbe    118c <inflateInplace+0x5c>
mov    -0x28(%rbp),%rdi
call   1040 <freeDHBuf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <inflateInplace+0x7b>
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):
<inflateInplace>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %rdi,%r14
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rcx
call   1050 <inflateCpy@plt>
mov    %rax,%rbx
test   %rax,%rax
je     115f <inflateInplace+0x2f>
mov    0xc(%rsp),%edx
cmp    %ebp,%edx
jbe    116e <inflateInplace+0x3e>
mov    %rbx,%rdi
call   1040 <freeDHBuf@plt>
mov    $0xffffffff,%eax
jmp    1185 <inflateInplace+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 @inflateInplace(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 = load i32, i32* %7
%13 = call i8* @inflateCpy(i8* %10, i32 %11, i32 %12, i32* %8)
store i8* %13, i8** %9
%14 = load i8*, i8** %9
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32, i32* %8
%18 = load i32, i32* %7
%19 = icmp ugt i32 %17, %18
br i1 %19, label %20, label %23
20: ; preds = %16, %3
%21 = load i8*, i8** %9
%22 = call i32 @freeDHBuf(i8* %21)
store i32 -1, i32* %4
br label %31
23: ; preds = %16
%24 = load i8*, i8** %5
%25 = load i8*, i8** %9
%26 = load i32, i32* %8
%27 = call i32 @memcpy(i8* %24, i8* %25, i32 %26)
%28 = load i8*, i8** %9
%29 = call i32 @freeDHBuf(i8* %28)
%30 = load i32, i32* %8
store i32 %30, i32* %4
br label %31
31: ; preds = %23, %20
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
define i32 @inflateInplace(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%6 = call i8* @inflateCpy(i8* %0, i32 %1, i32 %2, 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
}