#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 */
typedef scalar_t__ uint8_t;
typedef int uint64_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ uLongf;

/* Variables and functions */
int compress2(scalar_t__ *, int /*<<< orphan*/ *, scalar_t__ *, int, int);
int inflate_multi_pass(scalar_t__ *, int, scalar_t__ *, int *);
scalar_t__ memcmp(scalar_t__ *, scalar_t__ *, int);
int /*<<< orphan*/ printf(char *, ...);
int test(uint8_t *compressed_stream, uint64_t *compressed_length,
         uint8_t *uncompressed_stream, uint32_t uncompressed_length,
         uint8_t *uncompressed_test_stream,
         uint32_t uncompressed_test_stream_length) {
  int ret;
  ret = compress2(compressed_stream, (uLongf *)compressed_length,
                  uncompressed_stream, uncompressed_length, 6);
  if (ret) {
    printf("Failed compressing input with exit code %d", ret);
    return ret;
  }
  ret = inflate_multi_pass(compressed_stream + 2, *compressed_length - 2 - 4,
                           uncompressed_test_stream,
                           &uncompressed_test_stream_length);
  switch (ret) {
  case 0:
    break;
  case 1:
    printf(" did not decompress all input\n");
    return 1;
    break;
  case -1:
    printf("  invalid header\n");
    return -1;
    break;
  case -2:
    printf(" invalid symbol\n");
    return -2;
    break;
  case 2:
    printf(" out buffer overflow\n");
    return 2;
    break;
  case -3:
    printf("Invalid lookback distance");
    return -3;
    break;
  default:
    printf(" error\n");
    return -1;
    break;
  }
  if (uncompressed_test_stream_length != uncompressed_length) {
    printf("incorrect amount of data was decompressed from compressed data\n");
    printf("%d decompressed of %d compressed", uncompressed_test_stream_length,
           uncompressed_length);
    return -1;
  }
  if (memcmp(uncompressed_stream, uncompressed_test_stream,
             uncompressed_length)) {
    int i;
    for (i = 0; i < uncompressed_length; i++) {
      if (uncompressed_stream[i] != uncompressed_test_stream[i]) {
        printf("first error at %d, 0x%x != 0x%x\n", i, uncompressed_stream[i],
               uncompressed_test_stream[i]);
      }
    }
    printf(" decompressed data is not the same as the compressed data\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9d,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    $0x6,%r8d
call   1060 <compress2@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     11a2 <test+0x62>
mov    -0x38(%rbp),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    136f <test+0x22f>
mov    -0x10(%rbp),%rdi
add    $0x10,%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
add    $0xfffffffa,%esi
mov    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   1050 <inflate_multi_pass@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
add    $0x3,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0x5,%eax
ja     1273 <test+0x133>
mov    -0x48(%rbp),%rax
lea    0xe1d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
jmp    128d <test+0x14d>
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    136f <test+0x22f>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    136f <test+0x22f>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    136f <test+0x22f>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    136f <test+0x22f>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xfffffffd,-0x4(%rbp)
jmp    136f <test+0x22f>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    136f <test+0x22f>
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
je     12c7 <test+0x187>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x34(%rbp),%esi
mov    -0x24(%rbp),%edx
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    136f <test+0x22f>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     1368 <test+0x228>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    134e <test+0x20e>
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    -0x30(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
cmp    (%rcx,%rdx,8),%rax
je     133b <test+0x1fb>
mov    -0x3c(%rbp),%esi
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1340 <test+0x200>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12e8 <test+0x1a8>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    136f <test+0x22f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%rbp
mov    %r9d,0x4(%rsp)
mov    $0x6,%r8d
call   1070 <compress2@plt>
test   %eax,%eax
je     11a1 <test+0x51>
mov    %eax,%ebx
lea    0xe91(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x10,%rbp
mov    0x0(%r13),%esi
add    $0xfffffffa,%esi
lea    0x4(%rsp),%rcx
mov    %rbp,%rdi
mov    %r14,%rdx
call   1060 <inflate_multi_pass@plt>
add    $0x3,%eax
cmp    $0x5,%eax
ja     11e9 <test+0x99>
lea    0xe35(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe68(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xfffffffd,%ebx
jmp    1190 <test+0x40>
lea    0xf7c(%rip),%rdi
jmp    12ca <test+0x17a>
lea    0xeb8(%rip),%rdi
call   1030 <puts@plt>
mov    $0xfffffffe,%ebx
jmp    1190 <test+0x40>
lea    0xeb5(%rip),%rdi
jmp    12ca <test+0x17a>
cmp    %r12d,0x4(%rsp)
jne    12a0 <test+0x150>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
je     12d9 <test+0x189>
test   %r12d,%r12d
jle    12c3 <test+0x173>
mov    %r12d,%ebx
lea    0xe35(%rip),%r12
xor    %ebp,%ebp
jmp    1259 <test+0x109>
nopl   (%rax)
add    $0x1,%rbp
cmp    %rbp,%rbx
je     12c3 <test+0x173>
mov    (%r15,%rbp,8),%rdx
mov    (%r14,%rbp,8),%rcx
cmp    %rcx,%rdx
je     1250 <test+0x100>
mov    %r12,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1250 <test+0x100>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    1190 <test+0x40>
lea    0xe0e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%ebx
jmp    1190 <test+0x40>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%esi
lea    0xda6(%rip),%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12cf <test+0x17f>
lea    0xe29(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1190 <test+0x40>
xor    %ebx,%ebx
jmp    1190 <test+0x40>

LLVM IR (-O0):
@.str = [43 x i8] c"Failed compressing input with exit code %d\00"
@.str.1 = [31 x i8] c" did not decompress all input\0A\00"
@.str.2 = [18 x i8] c" invalid header\0A\00"
@.str.3 = [17 x i8] c" invalid symbol\0A\00"
@.str.4 = [22 x i8] c" out buffer overflow\0A\00"
@.str.5 = [26 x i8] c"Invalid lookback distance\00"
@.str.6 = [8 x i8] c" error\0A\00"
@.str.7 = [64 x i8] c"incorrect amount of data was decompressed from compressed data\0A\00"
@.str.8 = [33 x i8] c"%d decompressed of %d compressed\00"
@.str.9 = [33 x i8] c"first error at %d, 0x%x != 0x%x\0A\00"
@.str.10 = [59 x i8] c" decompressed data is not the same as the compressed data\0A\00"
define i32 @test(i64* %0, i32* %1, i64* %2, i32 %3, i64* %4, i32 %5) {
%7 = alloca i32
%8 = alloca i64*
%9 = alloca i32*
%10 = alloca i64*
%11 = alloca i32
%12 = alloca i64*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i64* %0, i64** %8
store i32* %1, i32** %9
store i64* %2, i64** %10
store i32 %3, i32* %11
store i64* %4, i64** %12
store i32 %5, i32* %13
%16 = load i64*, i64** %8
%17 = load i32*, i32** %9
%18 = load i64*, i64** %10
%19 = load i32, i32* %11
%20 = call i32 @compress2(i64* %16, i32* %17, i64* %18, i32 %19, i32 6)
store i32 %20, i32* %14
%21 = load i32, i32* %14
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %6
%24 = load i32, i32* %14
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %14
store i32 %26, i32* %7
br label %102
27: ; preds = %6
%28 = load i64*, i64** %8
%29 = getelementptr inbounds i64, i64* %28, i64 2
%30 = load i32*, i32** %9
%31 = load i32, i32* %30
%32 = sub nsw i32 %31, 2
%33 = sub nsw i32 %32, 4
%34 = load i64*, i64** %12
%35 = call i32 @inflate_multi_pass(i64* %29, i32 %33, i64* %34, i32* %13)
store i32 %35, i32* %14
%36 = load i32, i32* %14
switch i32 %36, label %48 [
i32 0, label %37
i32 1, label %38
i32 -1, label %40
i32 -2, label %42
i32 2, label %44
i32 -3, label %46
]
37: ; preds = %27
br label %50
38: ; preds = %27
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %7
br label %102
40: ; preds = %27
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %7
br label %102
42: ; preds = %27
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 -2, i32* %7
br label %102
44: ; preds = %27
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
store i32 2, i32* %7
br label %102
46: ; preds = %27
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
store i32 -3, i32* %7
br label %102
48: ; preds = %27
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %7
br label %102
50: ; preds = %37
%51 = load i32, i32* %13
%52 = load i32, i32* %11
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.7, i64 0, i64 0))
%56 = load i32, i32* %13
%57 = load i32, i32* %11
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %56, i32 %57)
store i32 -1, i32* %7
br label %102
59: ; preds = %50
%60 = load i64*, i64** %10
%61 = load i64*, i64** %12
%62 = load i32, i32* %11
%63 = call i64 @memcmp(i64* %60, i64* %61, i32 %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %101
65: ; preds = %59
store i32 0, i32* %15
br label %66
66: ; preds = %96, %65
%67 = load i32, i32* %15
%68 = load i32, i32* %11
%69 = icmp slt i32 %67, %68
br i1 %69, label %70, label %99
70: ; preds = %66
%71 = load i64*, i64** %10
%72 = load i32, i32* %15
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i64, i64* %71, i64 %73
%75 = load i64, i64* %74
%76 = load i64*, i64** %12
%77 = load i32, i32* %15
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i64, i64* %76, i64 %78
%80 = load i64, i64* %79
%81 = icmp ne i64 %75, %80
br i1 %81, label %82, label %95
82: ; preds = %70
%83 = load i32, i32* %15
%84 = load i64*, i64** %10
%85 = load i32, i32* %15
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i64, i64* %84, i64 %86
%88 = load i64, i64* %87
%89 = load i64*, i64** %12
%90 = load i32, i32* %15
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i64, i64* %89, i64 %91
%93 = load i64, i64* %92
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i32 %83, i64 %88, i64 %93)
br label %95
95: ; preds = %82, %70
br label %96
96: ; preds = %95
%97 = load i32, i32* %15
%98 = add nsw i32 %97, 1
store i32 %98, i32* %15
br label %66
99: ; preds = %66
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.10, i64 0, i64 0))
store i32 -1, i32* %7
br label %102
101: ; preds = %59
store i32 0, i32* %7
br label %102
102: ; preds = %101, %99, %54, %48, %46, %44, %42, %40, %38, %23
%103 = load i32, i32* %7
ret i32 %103
}

LLVM IR (-O2):
@.str = [43 x i8] c"Failed compressing input with exit code %d\00"
@.str.5 = [26 x i8] c"Invalid lookback distance\00"
@.str.8 = [33 x i8] c"%d decompressed of %d compressed\00"
@.str.9 = [33 x i8] c"first error at %d, 0x%x != 0x%x\0A\00"
@str = [21 x i8] c" out buffer overflow\00"
@str.11 = [16 x i8] c" invalid symbol\00"
@str.12 = [17 x i8] c" invalid header\00"
@str.13 = [30 x i8] c" did not decompress all input\00"
@str.14 = [58 x i8] c" decompressed data is not the same as the compressed data\00"
@str.15 = [63 x i8] c"incorrect amount of data was decompressed from compressed data\00"
@str.16 = [7 x i8] c" error\00"
define i32 @test(i64* %0, i32* %1, i64* %2, i32 %3, i64* %4, i32 %5) {
%7 = alloca i32
store i32 %5, i32* %7
%8 = tail call i32 @compress2(i64* %0, i32* %1, i64* %2, i32 %3, i32 6)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %58
12: ; preds = %6
%13 = getelementptr inbounds i64, i64* %0, i64 2
%14 = load i32, i32* %1
%15 = add nsw i32 %14, -6
%16 = call i32 @inflate_multi_pass(i64* %13, i32 %15, i64* %4, i32* %7)
switch i32 %16, label %27 [
i32 0, label %29
i32 1, label %17
i32 -1, label %19
i32 -2, label %21
i32 2, label %23
i32 -3, label %25
]
17: ; preds = %12
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.13, i64 0, i64 0))
br label %58
19: ; preds = %12
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.12, i64 0, i64 0))
br label %58
21: ; preds = %12
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.11, i64 0, i64 0))
br label %58
23: ; preds = %12
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %58
25: ; preds = %12
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
br label %58
27: ; preds = %12
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str.16, i64 0, i64 0))
br label %58
29: ; preds = %12
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, %3
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str.15, i64 0, i64 0))
%34 = load i32, i32* %7
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i64 0, i64 0), i32 %34, i32 %3)
br label %58
36: ; preds = %29
%37 = call i64 @memcmp(i64* %2, i64* %4, i32 %3)
%38 = icmp eq i64 %37, 0
br i1 %38, label %58, label %39
39: ; preds = %36
%40 = icmp sgt i32 %3, 0
br i1 %40, label %41, label %56
41: ; preds = %39
%42 = zext i32 %3 to i64
br label %43
43: ; preds = %41, %53
%44 = phi i64 [ 0, %41 ], [ %54, %53 ]
%45 = getelementptr inbounds i64, i64* %2, i64 %44
%46 = load i64, i64* %45
%47 = getelementptr inbounds i64, i64* %4, i64 %44
%48 = load i64, i64* %47
%49 = icmp eq i64 %46, %48
br i1 %49, label %53, label %50
50: ; preds = %43
%51 = trunc i64 %44 to i32
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0), i32 %51, i64 %46, i64 %48)
br label %53
53: ; preds = %43, %50
%54 = add nuw nsw i64 %44, 1
%55 = icmp eq i64 %54, %42
br i1 %55, label %56, label %43
56: ; preds = %53, %39
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str.14, i64 0, i64 0))
br label %58
58: ; preds = %36, %56, %32, %27, %25, %23, %21, %19, %17, %10
%59 = phi i32 [ %8, %10 ], [ -1, %27 ], [ -3, %25 ], [ 2, %23 ], [ -2, %21 ], [ -1, %19 ], [ 1, %17 ], [ -1, %32 ], [ -1, %56 ], [ 0, %36 ]
ret i32 %59
}