#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*/ _comp_header_set_data(unsigned char *, int,
                                         int /*<<< orphan*/, unsigned long);
unsigned long lzf_compress(unsigned char *, unsigned long, unsigned char *,
                           unsigned long);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned long);
unsigned long comp_exec(unsigned char *ind, unsigned long inl,
                        unsigned char *outd) {
  unsigned long ret;
  int header_len;
  unsigned long lzf_ret;
  int data_size;
  if (inl > 65500)
    data_size = 4;
  else if (inl > 240)
    data_size = 2;
  else
    data_size = 1;
  header_len = 1 + data_size;
  lzf_ret = 0;
  if (inl > 2) {
    lzf_ret = lzf_compress(ind, inl, outd + header_len, inl - header_len - 1);
  }
  if (lzf_ret == 0) {
    header_len = 1;
    outd[0] = (0 << 4) | (data_size & 0x7);
    memcpy(outd + header_len, ind, inl);
    ret = header_len + inl;
  } else {
    outd[0] = (1 << 4) | (data_size & 0x7);
    _comp_header_set_data(outd, data_size, 0, inl);
    ret = header_len + lzf_ret;
  }
  return ret;
}


x86 assembly (clang, -O0):
<comp_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0xffdc,-0x10(%rbp)
jbe    115e <comp_exec+0x2e>
movl   $0x4,-0x34(%rbp)
jmp    1184 <comp_exec+0x54>
cmpq   $0xf0,-0x10(%rbp)
jbe    1178 <comp_exec+0x48>
movl   $0x2,-0x34(%rbp)
jmp    117f <comp_exec+0x4f>
movl   $0x1,-0x34(%rbp)
jmp    1184 <comp_exec+0x54>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
movq   $0x0,-0x30(%rbp)
cmpq   $0x2,-0x10(%rbp)
jbe    11cb <comp_exec+0x9b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
movslq -0x24(%rbp),%rax
add    %rax,%rdx
mov    -0x10(%rbp),%rcx
movslq -0x24(%rbp),%rax
sub    %rax,%rcx
sub    $0x1,%rcx
call   1050 <lzf_compress@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1217 <comp_exec+0xe7>
movl   $0x1,-0x24(%rbp)
mov    -0x34(%rbp),%eax
and    $0x7,%eax
or     $0x0,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <memcpy@plt>
movslq -0x24(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1246 <comp_exec+0x116>
mov    -0x34(%rbp),%eax
and    $0x7,%eax
or     $0x10,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x10(%rbp),%rcx
xor    %edx,%edx
call   1030 <_comp_header_set_data@plt>
movslq -0x24(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<comp_exec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
cmp    $0xf1,%rsi
mov    $0x1,%eax
sbb    $0xffffffff,%eax
cmp    $0xffdd,%rsi
mov    $0x4,%ebp
cmovb  %eax,%ebp
cmp    $0x3,%rsi
jb     11b1 <comp_exec+0x81>
mov    %ebp,%r13d
lea    (%r14,%r13,1),%rdx
add    $0x1,%rdx
add    $0x1,%r13
mov    %r13,%rcx
not    %rcx
add    %rbx,%rcx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <lzf_compress@plt>
test   %rax,%rax
je     11b1 <comp_exec+0x81>
mov    %rax,%r12
mov    %ebp,%eax
or     $0x10,%al
mov    %al,(%r14)
mov    %r14,%rdi
mov    %ebp,%esi
xor    %edx,%edx
mov    %rbx,%rcx
call   1030 <_comp_header_set_data@plt>
add    %r13,%r12
mov    %r12,%rbx
jmp    11ca <comp_exec+0x9a>
mov    %bpl,(%r14)
add    $0x1,%r14
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <memcpy@plt>
add    $0x1,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @comp_exec(i8* %0, i64 %1, i8* %2) {
%4 = icmp ugt i64 %1, 65500
%5 = icmp ugt i64 %1, 240
%6 = select i1 %5, i32 2, i32 1
%7 = select i1 %4, i32 4, i32 %6
%8 = icmp ugt i64 %1, 2
br i1 %8, label %9, label %17
9: ; preds = %3
%10 = add nuw nsw i32 %7, 1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %2, i64 %11
%13 = xor i64 %11, -1
%14 = add i64 %13, %1
%15 = tail call i64 @lzf_compress(i8* %0, i64 %1, i8* %12, i64 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %3, %9
%18 = trunc i32 %7 to i8
store i8 %18, i8* %2
%19 = getelementptr inbounds i8, i8* %2, i64 1
%20 = tail call i32 @memcpy(i8* %19, i8* %0, i64 %1)
%21 = add i64 %1, 1
br label %27
22: ; preds = %9
%23 = trunc i32 %7 to i8
%24 = or i8 %23, 16
store i8 %24, i8* %2
%25 = tail call i32 @_comp_header_set_data(i8* %2, i32 %7, i32 0, i64 %1)
%26 = add i64 %15, %11
br label %27
27: ; preds = %22, %17
%28 = phi i64 [ %21, %17 ], [ %26, %22 ]
ret i64 %28
}