#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*/ bit_get(unsigned char *, int);
int /*<<< orphan*/ bit_set(unsigned char *, int, int /*<<< orphan*/);
int compare_win(unsigned char *, unsigned char *, int *, unsigned char *);
int /*<<< orphan*/ free(unsigned char *);
unsigned int htonl(unsigned int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, int *, int);
int /*<<< orphan*/ memmove(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
scalar_t__ realloc(unsigned char *, int);
int lz77_compress(const unsigned char *original, unsigned char **compressed,
                  int size) {
  unsigned int token;
  unsigned char window[4096], buffer[32], *comp, *temp, next;
  int offset, length, remaining, tbits, hsize, ipos, opos, tpos, i;
  *compressed = NULL;
  hsize = sizeof(int);
  if ((comp = (unsigned char *)malloc(hsize)) == NULL)
    return -1;
  memcpy(comp, &size, sizeof(int));
  memset(window, 0, 4096);
  memset(buffer, 0, 32);
  ipos = 0;
  for (i = 0; i < 32 && ipos < size; i++) {
    buffer[i] = original[ipos];
    ipos++;
  }
  opos = hsize * 8;
  remaining = size;
  while (remaining > 0) {
    if ((length = compare_win(window, buffer, &offset, &next)) != 0) {
      token = 0x00000001 << ((1 + 12 + 8 + 5) - 1);
      token = token | (offset << ((1 + 12 + 8 + 5) - 1 - 12));
      token = token | (length << ((1 + 12 + 8 + 5) - 1 - 12 - 5));
      token = token | next;
      tbits = (1 + 12 + 8 + 5);
    } else {
      token = 0x00000000;
      token = token | next;
      tbits = (1 + 8);
    }
    token = htonl(token);
    for (i = 0; i < tbits; i++) {
      if (opos % 8 == 0) {
        if ((temp = (unsigned char *)realloc(comp, (opos / 8) + 1)) == NULL) {
          free(comp);
          return -1;
        }
        comp = temp;
      }
      tpos = (sizeof(unsigned int) * 8) - tbits + i;
      bit_set(comp, opos, bit_get((unsigned char *)&token, tpos));
      opos++;
    }
    length++;
    memmove(&window[0], &window[length], 4096 - length);
    memmove(&window[4096 - length], &buffer[0], length);
    memmove(&buffer[0], &buffer[length], 32 - length);
    for (i = 32 - length; i < 32 && ipos < size; i++) {
      buffer[i] = original[ipos];
      ipos++;
    }
    remaining = remaining - length;
  }
  *compressed = comp;
  return ((opos - 1) / 8) + 1;
}


x86 assembly (clang, -O0):
<lz77_compress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1090,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x4,-0x1068(%rbp)
mov    -0x1068(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x1048(%rbp)
cmp    $0x0,%rax
jne    11f3 <lz77_compress+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d8 <lz77_compress+0x438>
mov    -0x1048(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
lea    -0x1040(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
movl   $0x0,-0x106c(%rbp)
movl   $0x0,-0x1078(%rbp)
xor    %eax,%eax
cmpl   $0x20,-0x1078(%rbp)
mov    %al,-0x1079(%rbp)
jge    1269 <lz77_compress+0xc9>
mov    -0x106c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setl   %al
mov    %al,-0x1079(%rbp)
mov    -0x1079(%rbp),%al
test   $0x1,%al
jne    127c <lz77_compress+0xdc>
jmp    12bb <lz77_compress+0x11b>
mov    -0x10(%rbp),%rax
movslq -0x106c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x1078(%rbp),%rax
mov    %cl,-0x1040(%rbp,%rax,1)
mov    -0x106c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x106c(%rbp)
mov    -0x1078(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1078(%rbp)
jmp    1242 <lz77_compress+0xa2>
mov    -0x1068(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0x1070(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x1060(%rbp)
cmpl   $0x0,-0x1060(%rbp)
jle    15b3 <lz77_compress+0x413>
lea    -0x1020(%rbp),%rdi
lea    -0x1040(%rbp),%rsi
lea    -0x1058(%rbp),%rdx
lea    -0x1051(%rbp),%rcx
call   1070 <compare_win@plt>
mov    %eax,-0x105c(%rbp)
cmp    $0x0,%eax
je     1357 <lz77_compress+0x1b7>
movl   $0x2000000,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x1058(%rbp),%ecx
shl    $0xd,%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x105c(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
movzbl -0x1051(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
movl   $0x1a,-0x1064(%rbp)
jmp    1377 <lz77_compress+0x1d7>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
movzbl -0x1051(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x20(%rbp)
movl   $0x9,-0x1064(%rbp)
mov    -0x20(%rbp),%edi
call   1050 <htonl@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1078(%rbp)
mov    -0x1078(%rbp),%eax
cmp    -0x1064(%rbp),%eax
jge    148a <lz77_compress+0x2ea>
mov    -0x1070(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    140b <lz77_compress+0x26b>
mov    -0x1048(%rbp),%rdi
mov    -0x1070(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
add    $0x1,%esi
call   10b0 <realloc@plt>
mov    %rax,-0x1050(%rbp)
cmp    $0x0,%rax
jne    13fd <lz77_compress+0x25d>
mov    -0x1048(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15d8 <lz77_compress+0x438>
mov    -0x1050(%rbp),%rax
mov    %rax,-0x1048(%rbp)
movslq -0x1064(%rbp),%rcx
mov    $0x20,%eax
sub    %rcx,%rax
movslq -0x1078(%rbp),%rcx
add    %rcx,%rax
mov    %eax,-0x1074(%rbp)
mov    -0x1048(%rbp),%rax
mov    %rax,-0x1088(%rbp)
mov    -0x1070(%rbp),%eax
mov    %eax,-0x1080(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x1074(%rbp),%esi
call   1040 <bit_get@plt>
mov    -0x1088(%rbp),%rdi
mov    -0x1080(%rbp),%esi
mov    %eax,%edx
call   10a0 <bit_set@plt>
mov    -0x1070(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1070(%rbp)
mov    -0x1078(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1078(%rbp)
jmp    138c <lz77_compress+0x1ec>
mov    -0x105c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x105c(%rbp)
lea    -0x1020(%rbp),%rdi
movslq -0x105c(%rbp),%rax
lea    -0x1020(%rbp),%rsi
add    %rax,%rsi
mov    $0x1000,%edx
sub    -0x105c(%rbp),%edx
call   10c0 <memmove@plt>
mov    $0x1000,%eax
sub    -0x105c(%rbp),%eax
cltq
lea    -0x1020(%rbp),%rdi
add    %rax,%rdi
lea    -0x1040(%rbp),%rsi
mov    -0x105c(%rbp),%edx
call   10c0 <memmove@plt>
lea    -0x1040(%rbp),%rdi
movslq -0x105c(%rbp),%rax
lea    -0x1040(%rbp),%rsi
add    %rax,%rsi
mov    $0x20,%edx
sub    -0x105c(%rbp),%edx
call   10c0 <memmove@plt>
mov    $0x20,%eax
sub    -0x105c(%rbp),%eax
mov    %eax,-0x1078(%rbp)
xor    %eax,%eax
cmpl   $0x20,-0x1078(%rbp)
mov    %al,-0x1089(%rbp)
jge    154a <lz77_compress+0x3aa>
mov    -0x106c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setl   %al
mov    %al,-0x1089(%rbp)
mov    -0x1089(%rbp),%al
test   $0x1,%al
jne    155d <lz77_compress+0x3bd>
jmp    159c <lz77_compress+0x3fc>
mov    -0x10(%rbp),%rax
movslq -0x106c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x1078(%rbp),%rax
mov    %cl,-0x1040(%rbp,%rax,1)
mov    -0x106c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x106c(%rbp)
mov    -0x1078(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1078(%rbp)
jmp    1523 <lz77_compress+0x383>
mov    -0x1060(%rbp),%eax
sub    -0x105c(%rbp),%eax
mov    %eax,-0x1060(%rbp)
jmp    12d3 <lz77_compress+0x133>
mov    -0x1048(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1070(%rbp),%eax
sub    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1090,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lz77_compress>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1068,%rsp
mov    %rsi,%rbx
mov    %rdi,0x18(%rsp)
mov    %edx,0x8(%rsp)
movq   $0x0,(%rsi)
mov    $0x4,%edi
call   1090 <malloc@plt>
mov    %rax,%r13
mov    $0xffffffff,%eax
test   %r13,%r13
je     1458 <lz77_compress+0x2b8>
lea    0x8(%rsp),%rsi
mov    %r13,%rdi
mov    $0x4,%edx
call   1080 <memcpy@plt>
lea    0x60(%rsp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
lea    0x40(%rsp),%rdi
mov    $0x20,%ebp
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    0x8(%rsp),%r15d
test   %r15d,%r15d
jle    1442 <lz77_compress+0x2a2>
mov    %rbx,0x28(%rsp)
lea    -0x1(%r15),%r12d
cmp    $0x1f,%r12d
mov    $0x1f,%eax
cmovae %eax,%r12d
add    $0x1,%r12d
lea    0x40(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    %r12,%rdx
call   1080 <memcpy@plt>
jmp    1270 <lz77_compress+0xd0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x38(%rsp),%r15
sub    0xc(%rsp),%r15d
jle    146a <lz77_compress+0x2ca>
lea    0x60(%rsp),%rdi
lea    0x40(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x7(%rsp),%rcx
call   1070 <compare_win@plt>
test   %eax,%eax
mov    %rax,0x20(%rsp)
je     12c0 <lz77_compress+0x120>
mov    0x10(%rsp),%edx
shl    $0xd,%edx
mov    %eax,%ecx
shl    $0x8,%ecx
or     %edx,%ecx
movzbl 0x7(%rsp),%edi
or     %ecx,%edi
or     $0x2000000,%edi
mov    $0x1a,%r14d
jmp    12cb <lz77_compress+0x12b>
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x7(%rsp),%edi
mov    $0x9,%r14d
call   1050 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    $0x20,%ebx
sub    %r14d,%ebx
lea    0x14(%rsp),%r14
jmp    1314 <lz77_compress+0x174>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%r13
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <bit_get@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   10a0 <bit_set@plt>
add    $0x1,%ebp
add    $0x1,%ebx
cmp    $0x20,%ebx
je     1340 <lz77_compress+0x1a0>
test   $0x7,%bpl
jne    12f3 <lz77_compress+0x153>
lea    0x7(%rbp),%esi
test   %ebp,%ebp
cmovns %ebp,%esi
sar    $0x3,%esi
add    $0x1,%esi
mov    %r13,%rdi
call   10b0 <realloc@plt>
test   %rax,%rax
jne    12f0 <lz77_compress+0x150>
jmp    1433 <lz77_compress+0x293>
nopw   0x0(%rax,%rax,1)
mov    %r15,0x38(%rsp)
mov    0x20(%rsp),%r14
lea    0x1(%r14),%eax
mov    %eax,0xc(%rsp)
movslq %r14d,%rax
mov    %rax,0x30(%rsp)
lea    (%rsp,%rax,1),%rsi
add    $0x61,%rsi
mov    $0xfff,%ebx
sub    %r14d,%ebx
lea    0x60(%rsp),%rdi
mov    %ebx,%edx
call   10c0 <memmove@plt>
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x60,%rdi
lea    0x40(%rsp),%r15
mov    %r15,%rsi
mov    0xc(%rsp),%edx
call   10c0 <memmove@plt>
mov    0x30(%rsp),%rax
lea    (%rsp,%rax,1),%rsi
add    $0x41,%rsi
mov    $0x1f,%ebx
sub    %r14d,%ebx
mov    %r15,%rdi
mov    %ebx,%edx
call   10c0 <memmove@plt>
cmp    $0x1f,%ebx
jg     1260 <lz77_compress+0xc0>
mov    0x8(%rsp),%eax
cmp    %eax,%r12d
jge    1260 <lz77_compress+0xc0>
movslq %eax,%r15
movslq %r12d,%r14
mov    0x18(%rsp),%rcx
lea    (%rcx,%r14,1),%rsi
mov    %r12d,%edx
not    %edx
add    %eax,%edx
mov    0x20(%rsp),%rax
cmp    %eax,%edx
cmovae %eax,%edx
test   %eax,%eax
movslq %ebx,%rbx
lea    0x40(%rsp,%rbx,1),%rdi
cmove  %eax,%edx
add    $0x1,%rdx
call   1080 <memcpy@plt>
add    $0x1,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r12d
cmp    $0x1e,%rbx
jg     1260 <lz77_compress+0xc0>
add    $0x1,%rbx
lea    0x1(%r14),%rax
cmp    %r15,%r14
mov    %rax,%r14
jl     1410 <lz77_compress+0x270>
jmp    1260 <lz77_compress+0xc0>
mov    %r13,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
jmp    1458 <lz77_compress+0x2b8>
mov    $0x1f,%ebp
mov    %r13,(%rbx)
lea    0x7(%rbp),%eax
test   %ebp,%ebp
cmovns %ebp,%eax
sar    $0x3,%eax
add    $0x1,%eax
add    $0x1068,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0xffffffff,%ebp
mov    0x28(%rsp),%rbx
jmp    1447 <lz77_compress+0x2a7>

LLVM IR (-O0):
define i32 @lz77_compress(i8* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4096 x i8]
%10 = alloca [32 x i8]
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
%23 = load i8**, i8*** %6
store i8* null, i8** %23
store i32 4, i32* %18
%24 = load i32, i32* %18
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %11
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %29
28: ; preds = %3
store i32 -1, i32* %4
br label %192
29: ; preds = %3
%30 = load i8*, i8** %11
%31 = call i32 @memcpy(i8* %30, i32* %7, i32 4)
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%33 = call i32 @memset(i8* %32, i32 0, i32 4096)
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%35 = call i32 @memset(i8* %34, i32 0, i32 32)
store i32 0, i32* %19
store i32 0, i32* %22
br label %36
36: ; preds = %56, %29
%37 = load i32, i32* %22
%38 = icmp slt i32 %37, 32
br i1 %38, label %39, label %43
39: ; preds = %36
%40 = load i32, i32* %19
%41 = load i32, i32* %7
%42 = icmp slt i32 %40, %41
br label %43
43: ; preds = %39, %36
%44 = phi i1 [ false, %36 ], [ %42, %39 ]
br i1 %44, label %45, label %59
45: ; preds = %43
%46 = load i8*, i8** %5
%47 = load i32, i32* %19
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = load i32, i32* %22
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 %52
store i8 %50, i8* %53
%54 = load i32, i32* %19
%55 = add nsw i32 %54, 1
store i32 %55, i32* %19
br label %56
56: ; preds = %45
%57 = load i32, i32* %22
%58 = add nsw i32 %57, 1
store i32 %58, i32* %22
br label %36
59: ; preds = %43
%60 = load i32, i32* %18
%61 = mul nsw i32 %60, 8
store i32 %61, i32* %20
%62 = load i32, i32* %7
store i32 %62, i32* %16
br label %63
63: ; preds = %181, %59
%64 = load i32, i32* %16
%65 = icmp sgt i32 %64, 0
br i1 %65, label %66, label %185
66: ; preds = %63
%67 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%68 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%69 = call i32 @compare_win(i8* %67, i8* %68, i32* %14, i8* %13)
store i32 %69, i32* %15
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %84
71: ; preds = %66
store i32 33554432, i32* %8
%72 = load i32, i32* %8
%73 = load i32, i32* %14
%74 = shl i32 %73, 13
%75 = or i32 %72, %74
store i32 %75, i32* %8
%76 = load i32, i32* %8
%77 = load i32, i32* %15
%78 = shl i32 %77, 8
%79 = or i32 %76, %78
store i32 %79, i32* %8
%80 = load i32, i32* %8
%81 = load i8, i8* %13
%82 = zext i8 %81 to i32
%83 = or i32 %80, %82
store i32 %83, i32* %8
store i32 26, i32* %17
br label %89
84: ; preds = %66
store i32 0, i32* %8
%85 = load i32, i32* %8
%86 = load i8, i8* %13
%87 = zext i8 %86 to i32
%88 = or i32 %85, %87
store i32 %88, i32* %8
store i32 9, i32* %17
br label %89
89: ; preds = %84, %71
%90 = load i32, i32* %8
%91 = call i32 @htonl(i32 %90)
store i32 %91, i32* %8
store i32 0, i32* %22
br label %92
92: ; preds = %129, %89
%93 = load i32, i32* %22
%94 = load i32, i32* %17
%95 = icmp slt i32 %93, %94
br i1 %95, label %96, label %132
96: ; preds = %92
%97 = load i32, i32* %20
%98 = srem i32 %97, 8
%99 = icmp eq i32 %98, 0
br i1 %99, label %100, label %113
100: ; preds = %96
%101 = load i8*, i8** %11
%102 = load i32, i32* %20
%103 = sdiv i32 %102, 8
%104 = add nsw i32 %103, 1
%105 = call i64 @realloc(i8* %101, i32 %104)
%106 = inttoptr i64 %105 to i8*
store i8* %106, i8** %12
%107 = icmp eq i8* %106, null
br i1 %107, label %108, label %111
108: ; preds = %100
%109 = load i8*, i8** %11
%110 = call i32 @free(i8* %109)
store i32 -1, i32* %4
br label %192
111: ; preds = %100
%112 = load i8*, i8** %12
store i8* %112, i8** %11
br label %113
113: ; preds = %111, %96
%114 = load i32, i32* %17
%115 = sext i32 %114 to i64
%116 = sub i64 32, %115
%117 = load i32, i32* %22
%118 = sext i32 %117 to i64
%119 = add i64 %116, %118
%120 = trunc i64 %119 to i32
store i32 %120, i32* %21
%121 = load i8*, i8** %11
%122 = load i32, i32* %20
%123 = bitcast i32* %8 to i8*
%124 = load i32, i32* %21
%125 = call i32 @bit_get(i8* %123, i32 %124)
%126 = call i32 @bit_set(i8* %121, i32 %122, i32 %125)
%127 = load i32, i32* %20
%128 = add nsw i32 %127, 1
store i32 %128, i32* %20
br label %129
129: ; preds = %113
%130 = load i32, i32* %22
%131 = add nsw i32 %130, 1
store i32 %131, i32* %22
br label %92
132: ; preds = %92
%133 = load i32, i32* %15
%134 = add nsw i32 %133, 1
store i32 %134, i32* %15
%135 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%136 = load i32, i32* %15
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 %137
%139 = load i32, i32* %15
%140 = sub nsw i32 4096, %139
%141 = call i32 @memmove(i8* %135, i8* %138, i32 %140)
%142 = load i32, i32* %15
%143 = sub nsw i32 4096, %142
%144 = sext i32 %143 to i64
%145 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 %144
%146 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%147 = load i32, i32* %15
%148 = call i32 @memmove(i8* %145, i8* %146, i32 %147)
%149 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%150 = load i32, i32* %15
%151 = sext i32 %150 to i64
%152 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 %151
%153 = load i32, i32* %15
%154 = sub nsw i32 32, %153
%155 = call i32 @memmove(i8* %149, i8* %152, i32 %154)
%156 = load i32, i32* %15
%157 = sub nsw i32 32, %156
store i32 %157, i32* %22
br label %158
158: ; preds = %178, %132
%159 = load i32, i32* %22
%160 = icmp slt i32 %159, 32
br i1 %160, label %161, label %165
161: ; preds = %158
%162 = load i32, i32* %19
%163 = load i32, i32* %7
%164 = icmp slt i32 %162, %163
br label %165
165: ; preds = %161, %158
%166 = phi i1 [ false, %158 ], [ %164, %161 ]
br i1 %166, label %167, label %181
167: ; preds = %165
%168 = load i8*, i8** %5
%169 = load i32, i32* %19
%170 = sext i32 %169 to i64
%171 = getelementptr inbounds i8, i8* %168, i64 %170
%172 = load i8, i8* %171
%173 = load i32, i32* %22
%174 = sext i32 %173 to i64
%175 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 %174
store i8 %172, i8* %175
%176 = load i32, i32* %19
%177 = add nsw i32 %176, 1
store i32 %177, i32* %19
br label %178
178: ; preds = %167
%179 = load i32, i32* %22
%180 = add nsw i32 %179, 1
store i32 %180, i32* %22
br label %158
181: ; preds = %165
%182 = load i32, i32* %16
%183 = load i32, i32* %15
%184 = sub nsw i32 %182, %183
store i32 %184, i32* %16
br label %63
185: ; preds = %63
%186 = load i8*, i8** %11
%187 = load i8**, i8*** %6
store i8* %186, i8** %187
%188 = load i32, i32* %20
%189 = sub nsw i32 %188, 1
%190 = sdiv i32 %189, 8
%191 = add nsw i32 %190, 1
store i32 %191, i32* %4
br label %192
192: ; preds = %185, %108, %28
%193 = load i32, i32* %4
ret i32 %193
}

LLVM IR (-O2):
define i32 @lz77_compress(i8* nocapture %0, i8** nocapture writeonly %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4096 x i8]
%7 = alloca [32 x i8]
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%9 = alloca i8
%10 = alloca i32
store i32 %2, i32* %4
%11 = bitcast i32* %5 to i8*
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%14 = bitcast i32* %10 to i8*
store i8* null, i8** %1
%15 = tail call i64 @malloc(i32 4)
%16 = inttoptr i64 %15 to i8*
%17 = icmp eq i64 %15, 0
br i1 %17, label %123, label %18
18: ; preds = %3
%19 = call i32 @memcpy(i8* %16, i32* %4, i32 4)
%20 = call i32 @memset(i8* %12, i32 0, i32 4096)
%21 = call i32 @memset(i8* %13, i32 0, i32 32)
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %118
24: ; preds = %18
%25 = add nsw i32 %22, -1
%26 = call i32 @llvm.umin.i32(i32 %25, i32 31)
%27 = add nuw nsw i32 %26, 1
%28 = zext i32 %27 to i64
br label %29
29: ; preds = %24, %114
%30 = phi i32 [ %73, %114 ], [ 32, %24 ]
%31 = phi i32 [ %115, %114 ], [ %27, %24 ]
%32 = phi i8* [ %69, %114 ], [ %16, %24 ]
%33 = phi i32 [ %116, %114 ], [ %22, %24 ]
%34 = call i32 @compare_win(i8* %12, i8* %13, i32* %10, i8* %9)
%35 = icmp eq i32 %34, 0
br i1 %35, label %45, label %36
36: ; preds = %29
%37 = load i32, i32* %10
%38 = shl i32 %37, 13
%39 = shl i32 %34, 8
%40 = or i32 %39, %38
%41 = load i8, i8* %9
%42 = zext i8 %41 to i32
%43 = or i32 %40, %42
%44 = or i32 %43, 33554432
br label %48
45: ; preds = %29
%46 = load i8, i8* %9
%47 = zext i8 %46 to i32
br label %48
48: ; preds = %45, %36
%49 = phi i32 [ %47, %45 ], [ %44, %36 ]
%50 = phi i32 [ 9, %45 ], [ 26, %36 ]
%51 = call i32 @htonl(i32 %49)
store i32 %51, i32* %5
%52 = sub nuw nsw i32 32, %50
br label %53
53: ; preds = %48, %68
%54 = phi i32 [ 0, %48 ], [ %74, %68 ]
%55 = phi i32 [ %30, %48 ], [ %73, %68 ]
%56 = phi i8* [ %32, %48 ], [ %69, %68 ]
%57 = and i32 %55, 7
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %68
59: ; preds = %53
%60 = sdiv i32 %55, 8
%61 = add nsw i32 %60, 1
%62 = call i64 @realloc(i8* %56, i32 %61)
%63 = icmp eq i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %59
%65 = call i32 @free(i8* %56)
br label %123
66: ; preds = %59
%67 = inttoptr i64 %62 to i8*
br label %68
68: ; preds = %66, %53
%69 = phi i8* [ %67, %66 ], [ %56, %53 ]
%70 = add nuw nsw i32 %52, %54
%71 = call i32 @bit_get(i8* %11, i32 %70)
%72 = call i32 @bit_set(i8* %69, i32 %55, i32 %71)
%73 = add nsw i32 %55, 1
%74 = add nuw nsw i32 %54, 1
%75 = icmp eq i32 %74, %50
br i1 %75, label %76, label %53
76: ; preds = %68
%77 = add nsw i32 %34, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %78
%80 = sub i32 4095, %34
%81 = call i32 @memmove(i8* %12, i8* %79, i32 %80)
%82 = sext i32 %80 to i64
%83 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %82
%84 = call i32 @memmove(i8* %83, i8* %13, i32 %77)
%85 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 %78
%86 = sub i32 31, %34
%87 = call i32 @memmove(i8* %13, i8* %85, i32 %86)
%88 = load i32, i32* %4
%89 = icmp slt i32 %86, 32
%90 = icmp slt i32 %31, %88
%91 = select i1 %89, i1 %90, i1 false
br i1 %91, label %92, label %114
92: ; preds = %76
%93 = sext i32 %86 to i64
%94 = getelementptr [32 x i8], [32 x i8]* %7, i64 0, i64 %93
%95 = sext i32 %31 to i64
%96 = getelementptr i8, i8* %0, i64 %95
%97 = xor i32 %31, -1
%98 = add i32 %88, %97
%99 = call i32 @llvm.umin.i32(i32 %98, i32 %34)
%100 = select i1 %35, i32 0, i32 %99
%101 = zext i32 %100 to i64
%102 = add nuw nsw i64 %101, 1
%103 = sext i32 %88 to i64
br label %104
104: ; preds = %92, %104
%105 = phi i64 [ %95, %92 ], [ %107, %104 ]
%106 = phi i64 [ %93, %92 ], [ %108, %104 ]
%107 = add nsw i64 %105, 1
%108 = add nsw i64 %106, 1
%109 = icmp slt i64 %106, 31
%110 = icmp slt i64 %107, %103
%111 = select i1 %109, i1 %110, i1 false
br i1 %111, label %104, label %112
112: ; preds = %104
%113 = trunc i64 %107 to i32
br label %114
114: ; preds = %112, %76
%115 = phi i32 [ %31, %76 ], [ %113, %112 ]
%116 = sub nsw i32 %33, %77
%117 = icmp sgt i32 %116, 0
br i1 %117, label %29, label %118
118: ; preds = %114, %18
%119 = phi i8* [ %16, %18 ], [ %69, %114 ]
%120 = phi i32 [ 31, %18 ], [ %55, %114 ]
store i8* %119, i8** %1
%121 = sdiv i32 %120, 8
%122 = add nsw i32 %121, 1
br label %123
123: ; preds = %3, %118, %64
%124 = phi i32 [ -1, %64 ], [ %122, %118 ], [ -1, %3 ]
ret i32 %124
}