#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*/ lzw_expand(unsigned char *, unsigned char *, unsigned long);
scalar_t__ malloc(unsigned long);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned long);
unsigned char *mi_unpack(unsigned char *bufferin, unsigned long sizein,
                         unsigned char *bufferout, unsigned long sizeout) {
  unsigned char *buffer;
  buffer = (unsigned char *)malloc(sizeout + 100);
  if (bufferin[0] & 0x01) {
    lzw_expand(bufferin + 1, buffer, sizeout);
  } else {
    memcpy(buffer, bufferin + 1, sizeout);
  }
  return buffer;
}


x86 assembly (clang, -O0):
<mi_unpack>:
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    -0x20(%rbp),%rdi
add    $0x64,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1186 <mi_unpack+0x56>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <lzw_expand@plt>
jmp    119b <mi_unpack+0x6b>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x1,%rsi
mov    -0x20(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mi_unpack>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r15
mov    %rdi,%rbx
lea    0x64(%rcx),%rdi
call   1040 <malloc@plt>
mov    %rax,%r14
lea    0x1(%rbx),%rsi
testb  $0x1,(%rbx)
jne    115d <mi_unpack+0x2d>
mov    %r14,%rdi
mov    %r15,%rdx
call   1030 <memcpy@plt>
jmp    116b <mi_unpack+0x3b>
mov    %rsi,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <lzw_expand@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @mi_unpack(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%10 = load i64, i64* %8
%11 = add i64 %10, 100
%12 = call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %9
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 0
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = and i32 %17, 1
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %4
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = load i8*, i8** %9
%24 = load i64, i64* %8
%25 = call i32 @lzw_expand(i8* %22, i8* %23, i64 %24)
br label %32
26: ; preds = %4
%27 = load i8*, i8** %9
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i64, i64* %8
%31 = call i32 @memcpy(i8* %27, i8* %29, i64 %30)
br label %32
32: ; preds = %26, %20
%33 = load i8*, i8** %9
ret i8* %33
}

LLVM IR (-O2):
define i8* @mi_unpack(i8* %0, i64 %1, i8* nocapture readnone %2, i64 %3) {
%5 = add i64 %3, 100
%6 = tail call i64 @malloc(i64 %5)
%7 = inttoptr i64 %6 to i8*
%8 = load i8, i8* %0
%9 = and i8 %8, 1
%10 = icmp eq i8 %9, 0
%11 = getelementptr inbounds i8, i8* %0, i64 1
br i1 %10, label %14, label %12
12: ; preds = %4
%13 = tail call i32 @lzw_expand(i8* %11, i8* %7, i64 %3)
br label %16
14: ; preds = %4
%15 = tail call i32 @memcpy(i8* %7, i8* %11, i64 %3)
br label %16
16: ; preds = %14, %12
ret i8* %7
}