#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 long htonl(unsigned long);
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 long 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 long) * 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    $0x10a0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x4,-0x1078(%rbp)
mov    -0x1078(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x1058(%rbp)
cmp    $0x0,%rax
jne    11f3 <lz77_compress+0x53>
movl   $0xffffffff,-0x4(%rbp)
jmp    15ee <lz77_compress+0x44e>
mov    -0x1058(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1080 <memcpy@plt>
lea    -0x1030(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
lea    -0x1050(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
movl   $0x0,-0x107c(%rbp)
movl   $0x0,-0x1088(%rbp)
xor    %eax,%eax
cmpl   $0x20,-0x1088(%rbp)
mov    %al,-0x1089(%rbp)
jge    1269 <lz77_compress+0xc9>
mov    -0x107c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setl   %al
mov    %al,-0x1089(%rbp)
mov    -0x1089(%rbp),%al
test   $0x1,%al
jne    127c <lz77_compress+0xdc>
jmp    12bb <lz77_compress+0x11b>
mov    -0x10(%rbp),%rax
movslq -0x107c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x1088(%rbp),%rax
mov    %cl,-0x1050(%rbp,%rax,1)
mov    -0x107c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x107c(%rbp)
mov    -0x1088(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1088(%rbp)
jmp    1242 <lz77_compress+0xa2>
mov    -0x1078(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0x1080(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x1070(%rbp)
cmpl   $0x0,-0x1070(%rbp)
jle    15c9 <lz77_compress+0x429>
lea    -0x1030(%rbp),%rdi
lea    -0x1050(%rbp),%rsi
lea    -0x1068(%rbp),%rdx
lea    -0x1061(%rbp),%rcx
call   1070 <compare_win@plt>
mov    %eax,-0x106c(%rbp)
cmp    $0x0,%eax
je     1367 <lz77_compress+0x1c7>
movq   $0x2000000,-0x28(%rbp)
02
mov    -0x28(%rbp),%rax
mov    -0x1068(%rbp),%ecx
shl    $0xd,%ecx
movslq %ecx,%rcx
or     %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x106c(%rbp),%ecx
shl    $0x8,%ecx
movslq %ecx,%rcx
or     %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movzbl -0x1061(%rbp),%ecx
or     %rcx,%rax
mov    %rax,-0x28(%rbp)
movl   $0x1a,-0x1074(%rbp)
jmp    138b <lz77_compress+0x1eb>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movzbl -0x1061(%rbp),%ecx
or     %rcx,%rax
mov    %rax,-0x28(%rbp)
movl   $0x9,-0x1074(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <htonl@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1088(%rbp)
mov    -0x1088(%rbp),%eax
cmp    -0x1074(%rbp),%eax
jge    14a0 <lz77_compress+0x300>
mov    -0x1080(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1421 <lz77_compress+0x281>
mov    -0x1058(%rbp),%rdi
mov    -0x1080(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
add    $0x1,%esi
call   10b0 <realloc@plt>
mov    %rax,-0x1060(%rbp)
cmp    $0x0,%rax
jne    1413 <lz77_compress+0x273>
mov    -0x1058(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15ee <lz77_compress+0x44e>
mov    -0x1060(%rbp),%rax
mov    %rax,-0x1058(%rbp)
movslq -0x1074(%rbp),%rcx
mov    $0x40,%eax
sub    %rcx,%rax
movslq -0x1088(%rbp),%rcx
add    %rcx,%rax
mov    %eax,-0x1084(%rbp)
mov    -0x1058(%rbp),%rax
mov    %rax,-0x1098(%rbp)
mov    -0x1080(%rbp),%eax
mov    %eax,-0x1090(%rbp)
lea    -0x28(%rbp),%rdi
mov    -0x1084(%rbp),%esi
call   1040 <bit_get@plt>
mov    -0x1098(%rbp),%rdi
mov    -0x1090(%rbp),%esi
mov    %eax,%edx
call   10a0 <bit_set@plt>
mov    -0x1080(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1080(%rbp)
mov    -0x1088(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1088(%rbp)
jmp    13a2 <lz77_compress+0x202>
mov    -0x106c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x106c(%rbp)
lea    -0x1030(%rbp),%rdi
movslq -0x106c(%rbp),%rax
lea    -0x1030(%rbp),%rsi
add    %rax,%rsi
mov    $0x1000,%edx
sub    -0x106c(%rbp),%edx
call   10c0 <memmove@plt>
mov    $0x1000,%eax
sub    -0x106c(%rbp),%eax
cltq
lea    -0x1030(%rbp),%rdi
add    %rax,%rdi
lea    -0x1050(%rbp),%rsi
mov    -0x106c(%rbp),%edx
call   10c0 <memmove@plt>
lea    -0x1050(%rbp),%rdi
movslq -0x106c(%rbp),%rax
lea    -0x1050(%rbp),%rsi
add    %rax,%rsi
mov    $0x20,%edx
sub    -0x106c(%rbp),%edx
call   10c0 <memmove@plt>
mov    $0x20,%eax
sub    -0x106c(%rbp),%eax
mov    %eax,-0x1088(%rbp)
xor    %eax,%eax
cmpl   $0x20,-0x1088(%rbp)
mov    %al,-0x1099(%rbp)
jge    1560 <lz77_compress+0x3c0>
mov    -0x107c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
setl   %al
mov    %al,-0x1099(%rbp)
mov    -0x1099(%rbp),%al
test   $0x1,%al
jne    1573 <lz77_compress+0x3d3>
jmp    15b2 <lz77_compress+0x412>
mov    -0x10(%rbp),%rax
movslq -0x107c(%rbp),%rcx
mov    (%rax,%rcx,1),%cl
movslq -0x1088(%rbp),%rax
mov    %cl,-0x1050(%rbp,%rax,1)
mov    -0x107c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x107c(%rbp)
mov    -0x1088(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1088(%rbp)
jmp    1539 <lz77_compress+0x399>
mov    -0x1070(%rbp),%eax
sub    -0x106c(%rbp),%eax
mov    %eax,-0x1070(%rbp)
jmp    12d3 <lz77_compress+0x133>
mov    -0x1058(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1080(%rbp),%eax
sub    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10a0,%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,0x10(%rsp)
mov    %edx,0x4(%rsp)
movq   $0x0,(%rsi)
mov    $0x4,%edi
call   1090 <malloc@plt>
mov    %rax,%r13
mov    $0xffffffff,%eax
test   %r13,%r13
je     1448 <lz77_compress+0x2a8>
lea    0x4(%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    0x4(%rsp),%r14d
test   %r14d,%r14d
jle    1432 <lz77_compress+0x292>
mov    %rbx,0x28(%rsp)
lea    -0x1(%r14),%r12d
cmp    $0x1f,%r12d
mov    $0x1f,%eax
cmovae %eax,%r12d
add    $0x1,%r12d
lea    0x40(%rsp),%r15
mov    %r15,%rdi
mov    0x10(%rsp),%rsi
mov    %r12,%rdx
call   1080 <memcpy@plt>
jmp    1275 <lz77_compress+0xd5>
nopw   0x0(%rax,%rax,1)
mov    0x38(%rsp),%r14
sub    0x8(%rsp),%r14d
lea    0x40(%rsp),%r15
jle    145a <lz77_compress+0x2ba>
lea    0x60(%rsp),%rdi
mov    %r15,%rsi
lea    0xc(%rsp),%rdx
lea    0x3(%rsp),%rcx
call   1070 <compare_win@plt>
test   %eax,%eax
mov    %rax,0x18(%rsp)
je     12c0 <lz77_compress+0x120>
mov    0xc(%rsp),%edx
shl    $0xd,%edx
mov    %eax,%ecx
shl    $0x8,%ecx
or     %edx,%ecx
or     $0x2000000,%ecx
movslq %ecx,%rax
movzbl 0x3(%rsp),%edi
or     %rax,%rdi
mov    $0x1a,%eax
jmp    12ca <lz77_compress+0x12a>
nopl   0x0(%rax,%rax,1)
movzbl 0x3(%rsp),%edi
mov    $0x9,%eax
mov    $0x40,%ebx
sub    %eax,%ebx
mov    %rdi,0x20(%rsp)
call   1050 <htonl@plt>
mov    %rax,0x20(%rsp)
jmp    1316 <lz77_compress+0x176>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%r13
lea    0x20(%rsp),%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    $0x40,%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    1423 <lz77_compress+0x283>
nopl   0x0(%rax)
mov    %r14,0x38(%rsp)
mov    %r15,%r14
mov    0x18(%rsp),%r15
lea    0x1(%r15),%eax
mov    %eax,0x8(%rsp)
movslq %r15d,%rax
mov    %rax,0x30(%rsp)
lea    (%rsp,%rax,1),%rsi
add    $0x61,%rsi
mov    $0xfff,%ebx
sub    %r15d,%ebx
lea    0x60(%rsp),%rdi
mov    %ebx,%edx
call   10c0 <memmove@plt>
movslq %ebx,%rax
lea    (%rsp,%rax,1),%rdi
add    $0x60,%rdi
mov    %r14,%rsi
mov    0x8(%rsp),%edx
call   10c0 <memmove@plt>
mov    0x30(%rsp),%rax
lea    (%rsp,%rax,1),%rsi
add    $0x41,%rsi
mov    $0x1f,%ebx
sub    %r15d,%ebx
mov    %r14,%rdi
mov    %ebx,%edx
call   10c0 <memmove@plt>
cmp    $0x1f,%ebx
jg     1260 <lz77_compress+0xc0>
mov    0x4(%rsp),%eax
cmp    %eax,%r12d
jge    1260 <lz77_compress+0xc0>
movslq %eax,%r15
movslq %r12d,%r14
mov    0x10(%rsp),%rcx
lea    (%rcx,%r14,1),%rsi
mov    %r12d,%edx
not    %edx
add    %eax,%edx
mov    0x18(%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
nop
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     1400 <lz77_compress+0x260>
jmp    1260 <lz77_compress+0xc0>
mov    %r13,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%eax
jmp    1448 <lz77_compress+0x2a8>
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    1437 <lz77_compress+0x297>

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 i64
%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 %194
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 = %183, %59
%64 = load i32, i32* %16
%65 = icmp sgt i32 %64, 0
br i1 %65, label %66, label %187
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 %86
71: ; preds = %66
store i64 33554432, i64* %8
%72 = load i64, i64* %8
%73 = load i32, i32* %14
%74 = shl i32 %73, 13
%75 = sext i32 %74 to i64
%76 = or i64 %72, %75
store i64 %76, i64* %8
%77 = load i64, i64* %8
%78 = load i32, i32* %15
%79 = shl i32 %78, 8
%80 = sext i32 %79 to i64
%81 = or i64 %77, %80
store i64 %81, i64* %8
%82 = load i64, i64* %8
%83 = load i8, i8* %13
%84 = zext i8 %83 to i64
%85 = or i64 %82, %84
store i64 %85, i64* %8
store i32 26, i32* %17
br label %91
86: ; preds = %66
store i64 0, i64* %8
%87 = load i64, i64* %8
%88 = load i8, i8* %13
%89 = zext i8 %88 to i64
%90 = or i64 %87, %89
store i64 %90, i64* %8
store i32 9, i32* %17
br label %91
91: ; preds = %86, %71
%92 = load i64, i64* %8
%93 = call i64 @htonl(i64 %92)
store i64 %93, i64* %8
store i32 0, i32* %22
br label %94
94: ; preds = %131, %91
%95 = load i32, i32* %22
%96 = load i32, i32* %17
%97 = icmp slt i32 %95, %96
br i1 %97, label %98, label %134
98: ; preds = %94
%99 = load i32, i32* %20
%100 = srem i32 %99, 8
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %115
102: ; preds = %98
%103 = load i8*, i8** %11
%104 = load i32, i32* %20
%105 = sdiv i32 %104, 8
%106 = add nsw i32 %105, 1
%107 = call i64 @realloc(i8* %103, i32 %106)
%108 = inttoptr i64 %107 to i8*
store i8* %108, i8** %12
%109 = icmp eq i8* %108, null
br i1 %109, label %110, label %113
110: ; preds = %102
%111 = load i8*, i8** %11
%112 = call i32 @free(i8* %111)
store i32 -1, i32* %4
br label %194
113: ; preds = %102
%114 = load i8*, i8** %12
store i8* %114, i8** %11
br label %115
115: ; preds = %113, %98
%116 = load i32, i32* %17
%117 = sext i32 %116 to i64
%118 = sub i64 64, %117
%119 = load i32, i32* %22
%120 = sext i32 %119 to i64
%121 = add i64 %118, %120
%122 = trunc i64 %121 to i32
store i32 %122, i32* %21
%123 = load i8*, i8** %11
%124 = load i32, i32* %20
%125 = bitcast i64* %8 to i8*
%126 = load i32, i32* %21
%127 = call i32 @bit_get(i8* %125, i32 %126)
%128 = call i32 @bit_set(i8* %123, i32 %124, i32 %127)
%129 = load i32, i32* %20
%130 = add nsw i32 %129, 1
store i32 %130, i32* %20
br label %131
131: ; preds = %115
%132 = load i32, i32* %22
%133 = add nsw i32 %132, 1
store i32 %133, i32* %22
br label %94
134: ; preds = %94
%135 = load i32, i32* %15
%136 = add nsw i32 %135, 1
store i32 %136, i32* %15
%137 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%138 = load i32, i32* %15
%139 = sext i32 %138 to i64
%140 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 %139
%141 = load i32, i32* %15
%142 = sub nsw i32 4096, %141
%143 = call i32 @memmove(i8* %137, i8* %140, i32 %142)
%144 = load i32, i32* %15
%145 = sub nsw i32 4096, %144
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 %146
%148 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%149 = load i32, i32* %15
%150 = call i32 @memmove(i8* %147, i8* %148, i32 %149)
%151 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%152 = load i32, i32* %15
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 %153
%155 = load i32, i32* %15
%156 = sub nsw i32 32, %155
%157 = call i32 @memmove(i8* %151, i8* %154, i32 %156)
%158 = load i32, i32* %15
%159 = sub nsw i32 32, %158
store i32 %159, i32* %22
br label %160
160: ; preds = %180, %134
%161 = load i32, i32* %22
%162 = icmp slt i32 %161, 32
br i1 %162, label %163, label %167
163: ; preds = %160
%164 = load i32, i32* %19
%165 = load i32, i32* %7
%166 = icmp slt i32 %164, %165
br label %167
167: ; preds = %163, %160
%168 = phi i1 [ false, %160 ], [ %166, %163 ]
br i1 %168, label %169, label %183
169: ; preds = %167
%170 = load i8*, i8** %5
%171 = load i32, i32* %19
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds i8, i8* %170, i64 %172
%174 = load i8, i8* %173
%175 = load i32, i32* %22
%176 = sext i32 %175 to i64
%177 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 %176
store i8 %174, i8* %177
%178 = load i32, i32* %19
%179 = add nsw i32 %178, 1
store i32 %179, i32* %19
br label %180
180: ; preds = %169
%181 = load i32, i32* %22
%182 = add nsw i32 %181, 1
store i32 %182, i32* %22
br label %160
183: ; preds = %167
%184 = load i32, i32* %16
%185 = load i32, i32* %15
%186 = sub nsw i32 %184, %185
store i32 %186, i32* %16
br label %63
187: ; preds = %63
%188 = load i8*, i8** %11
%189 = load i8**, i8*** %6
store i8* %188, i8** %189
%190 = load i32, i32* %20
%191 = sub nsw i32 %190, 1
%192 = sdiv i32 %191, 8
%193 = add nsw i32 %192, 1
store i32 %193, i32* %4
br label %194
194: ; preds = %187, %110, %28
%195 = load i32, i32* %4
ret i32 %195
}

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