#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__ malloc(int const);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
char *UpnpDecompressString(unsigned char *CurrentCompressed,
                           const int bufferLength,
                           const int DecompressedLength) {
  unsigned char *RetVal = (char *)malloc(DecompressedLength + 1);
  unsigned char *CurrentUnCompressed = RetVal;
  unsigned char *EndPtr = RetVal + DecompressedLength;
  int offset, length;
  do {
    memcpy(CurrentUnCompressed, CurrentCompressed + 1, (int)*CurrentCompressed);
    CurrentUnCompressed += (int)*CurrentCompressed;
    CurrentCompressed += 1 + ((int)*CurrentCompressed);
    length = (unsigned short)((*(CurrentCompressed)) & 63);
    offset = ((unsigned short)(*(CurrentCompressed + 1)) << 2) +
             (((unsigned short)(*(CurrentCompressed))) >> 6);
    memcpy(CurrentUnCompressed, CurrentUnCompressed - offset, length);
    CurrentCompressed += 2;
    CurrentUnCompressed += length;
  } while (CurrentUnCompressed < EndPtr);
  RetVal[DecompressedLength] = 0;
  return (RetVal);
}


x86 assembly (clang, -O0):
<UpnpDecompressString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edi
add    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x1,%rsi
mov    -0x8(%rbp),%rax
movzbl (%rax),%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rax
movzbl (%rax),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%ecx
add    $0x1,%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0x3f,%eax
movzwl %ax,%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
movzwl %ax,%eax
shl    $0x2,%eax
mov    -0x8(%rbp),%rcx
movzbl (%rcx),%ecx
movzwl %cx,%ecx
sar    $0x6,%ecx
add    %ecx,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x20(%rbp),%rsi
movslq -0x2c(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rsi
mov    -0x30(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x30(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jb     1158 <UpnpDecompressString+0x38>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UpnpDecompressString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %rdi,%r15
lea    0x1(%rbx),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
movslq %ebx,%r13
add    %rax,%r13
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x1(%r15),%rsi
movzbl (%r15),%edx
mov    %rbx,%rdi
call   1030 <memcpy@plt>
movzbl (%r15),%ebp
add    %rbp,%rbx
movzbl 0x1(%rbp,%r15,1),%eax
mov    %eax,%r12d
and    $0x3f,%r12d
movzbl 0x2(%rbp,%r15,1),%ecx
shr    $0x6,%rax
lea    (%rax,%rcx,4),%rax
mov    %rbx,%rsi
sub    %rax,%rsi
mov    %rbx,%rdi
mov    %r12d,%edx
call   1030 <memcpy@plt>
add    %rbp,%r15
add    $0x3,%r15
add    %r12,%rbx
cmp    %r13,%rbx
jb     1150 <UpnpDecompressString+0x30>
movb   $0x0,0x0(%r13)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @UpnpDecompressString(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 1
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %7
%16 = load i8*, i8** %7
store i8* %16, i8** %8
%17 = load i8*, i8** %7
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
store i8* %20, i8** %9
br label %21
21: ; preds = %74, %3
%22 = load i8*, i8** %8
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = call i32 @memcpy(i8* %22, i8* %24, i32 %27)
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = load i8*, i8** %8
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %32, i64 %33
store i8* %34, i8** %8
%35 = load i8*, i8** %4
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = add nsw i32 1, %37
%39 = load i8*, i8** %4
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8, i8* %39, i64 %40
store i8* %41, i8** %4
%42 = load i8*, i8** %4
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
%45 = and i32 %44, 63
%46 = trunc i32 %45 to i16
%47 = zext i16 %46 to i32
store i32 %47, i32* %11
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i64 1
%50 = load i8, i8* %49
%51 = zext i8 %50 to i16
%52 = zext i16 %51 to i32
%53 = shl i32 %52, 2
%54 = load i8*, i8** %4
%55 = load i8, i8* %54
%56 = zext i8 %55 to i16
%57 = zext i16 %56 to i32
%58 = ashr i32 %57, 6
%59 = add nsw i32 %53, %58
store i32 %59, i32* %10
%60 = load i8*, i8** %8
%61 = load i8*, i8** %8
%62 = load i32, i32* %10
%63 = sext i32 %62 to i64
%64 = sub i64 0, %63
%65 = getelementptr inbounds i8, i8* %61, i64 %64
%66 = load i32, i32* %11
%67 = call i32 @memcpy(i8* %60, i8* %65, i32 %66)
%68 = load i8*, i8** %4
%69 = getelementptr inbounds i8, i8* %68, i64 2
store i8* %69, i8** %4
%70 = load i32, i32* %11
%71 = load i8*, i8** %8
%72 = sext i32 %70 to i64
%73 = getelementptr inbounds i8, i8* %71, i64 %72
store i8* %73, i8** %8
br label %74
74: ; preds = %21
%75 = load i8*, i8** %8
%76 = load i8*, i8** %9
%77 = icmp ult i8* %75, %76
br i1 %77, label %21, label %78
78: ; preds = %74
%79 = load i8*, i8** %7
%80 = load i32, i32* %6
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds i8, i8* %79, i64 %81
store i8 0, i8* %82
%83 = load i8*, i8** %7
ret i8* %83
}

LLVM IR (-O2):
define i8* @UpnpDecompressString(i8* %0, i32 %1, i32 %2) {
%4 = add nsw i32 %2, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = sext i32 %2 to i64
%8 = getelementptr inbounds i8, i8* %6, i64 %7
br label %9
9: ; preds = %9, %3
%10 = phi i8* [ %6, %3 ], [ %35, %9 ]
%11 = phi i8* [ %0, %3 ], [ %33, %9 ]
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %11
%14 = zext i8 %13 to i32
%15 = tail call i32 @memcpy(i8* %10, i8* %12, i32 %14)
%16 = load i8, i8* %11
%17 = zext i8 %16 to i64
%18 = getelementptr inbounds i8, i8* %10, i64 %17
%19 = add nuw nsw i64 %17, 1
%20 = getelementptr inbounds i8, i8* %11, i64 %19
%21 = load i8, i8* %20
%22 = and i8 %21, 63
%23 = zext i8 %22 to i32
%24 = getelementptr inbounds i8, i8* %20, i64 1
%25 = load i8, i8* %24
%26 = zext i8 %25 to i64
%27 = mul nsw i64 %26, -4
%28 = lshr i8 %21, 6
%29 = zext i8 %28 to i64
%30 = sub nsw i64 %27, %29
%31 = getelementptr inbounds i8, i8* %18, i64 %30
%32 = tail call i32 @memcpy(i8* %18, i8* %31, i32 %23)
%33 = getelementptr inbounds i8, i8* %20, i64 2
%34 = zext i8 %22 to i64
%35 = getelementptr inbounds i8, i8* %18, i64 %34
%36 = icmp ult i8* %35, %8
br i1 %36, label %9, label %37
37: ; preds = %9
store i8 0, i8* %8
ret i8* %6
}