#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 int /*<<< orphan*/ dest;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(unsigned char *, int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int rubin_compress(unsigned char *, unsigned char *, int *, int *);
int /*<<< orphan*/ rubin_decompress(unsigned char *, unsigned char *, int, int);
void main() {
  unsigned char source[4096];
  unsigned char compr[40960];
  unsigned char dest[4096];
  int result;
  int i;
  int len, maxlen;
  FILE *file;
  memset(dest, 0xA5, sizeof(dest));
  for (i = 0; i < 4096; i++)
    source[i] = i;
  file = fopen("asd", "r");
  while (!feof(file)) {
    fread(source, 1, 4096, file);
    len = 4096;
    maxlen = 40960;
    result = rubin_compress(source, compr, &len, &maxlen);
    if (result) {
      printf("result is %d, exiting\n", result);
      exit(0);
    }
    printf("Compressed to %i bytes \n", maxlen);
    if (maxlen > 4096)
      continue;
    rubin_decompress(compr, dest, 4096, 4096);
    for (i = 0; i < 4096; i++)
      if (source[i] != dest[i]) {
        printf("Mismatch at position %i: %i -> %i \n", i, source[i], dest[i]);
      }
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc020,%rsp
lea    -0xc000(%rbp),%rdi
mov    $0xa5,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
movl   $0x0,-0xc008(%rbp)
cmpl   $0x1000,-0xc008(%rbp)
jge    11f5 <main+0x65>
mov    -0xc008(%rbp),%eax
mov    %al,%cl
movslq -0xc008(%rbp),%rax
mov    %cl,-0x1000(%rbp,%rax,1)
mov    -0xc008(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc008(%rbp)
jmp    11bb <main+0x2b>
lea    0xe04(%rip),%rdi
lea    0xe01(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0xc018(%rbp)
mov    -0xc018(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1230 <main+0xa0>
jmp    1383 <main+0x1f3>
lea    -0x1000(%rbp),%rdi
mov    -0xc018(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
movl   $0x1000,-0xc00c(%rbp)
movl   $0xa000,-0xc010(%rbp)
lea    -0x1000(%rbp),%rdi
lea    -0xb000(%rbp),%rsi
lea    -0xc00c(%rbp),%rdx
lea    -0xc010(%rbp),%rcx
call   10b0 <rubin_compress@plt>
mov    %eax,-0xc004(%rbp)
cmpl   $0x0,-0xc004(%rbp)
je     12b0 <main+0x120>
mov    -0xc004(%rbp),%esi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0xc010(%rbp),%esi
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x1000,-0xc010(%rbp)
jle    12d9 <main+0x149>
jmp    120f <main+0x7f>
lea    -0xb000(%rbp),%rdi
lea    -0xc000(%rbp),%rsi
mov    $0x1000,%ecx
mov    %ecx,%edx
call   1080 <rubin_decompress@plt>
movl   $0x0,-0xc008(%rbp)
cmpl   $0x1000,-0xc008(%rbp)
jge    137e <main+0x1ee>
movslq -0xc008(%rbp),%rax
movzbl -0x1000(%rbp,%rax,1),%eax
ff
movslq -0xc008(%rbp),%rcx
movzbl -0xc000(%rbp,%rcx,1),%ecx
ff
cmp    %ecx,%eax
je     1365 <main+0x1d5>
mov    -0xc008(%rbp),%esi
movslq -0xc008(%rbp),%rax
movzbl -0x1000(%rbp,%rax,1),%edx
ff
movslq -0xc008(%rbp),%rax
movzbl -0xc000(%rbp,%rax,1),%ecx
ff
lea    0xcd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    136a <main+0x1da>
mov    -0xc008(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc008(%rbp)
jmp    12fd <main+0x16d>
jmp    120f <main+0x7f>
mov    -0xc018(%rbp),%rdi
call   1040 <fclose@plt>
add    $0xc020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc018,%rsp
lea    0x1010(%rsp),%rdi
mov    $0xa5,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
movdqa 0xe40(%rip),%xmm2
xor    %eax,%eax
movdqa 0xe45(%rip),%xmm8
movdqa 0xe4c(%rip),%xmm9
movdqa 0xe54(%rip),%xmm3
movdqa 0xe5c(%rip),%xmm4
movdqa 0xe64(%rip),%xmm5
movdqa 0xe6c(%rip),%xmm6
movdqa 0xe74(%rip),%xmm7
movdqa 0xe7c(%rip),%xmm1
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movdqa %xmm2,0x10(%rsp,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm8,%xmm0
movdqa %xmm0,0x20(%rsp,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm9,%xmm0
movdqa %xmm0,0x30(%rsp,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm3,%xmm0
movdqa %xmm0,0x40(%rsp,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm4,%xmm0
movdqa %xmm0,0x50(%rsp,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm5,%xmm0
movdqa %xmm0,0x60(%rsp,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm6,%xmm0
movdqa %xmm0,0x70(%rsp,%rax,1)
movdqa %xmm2,%xmm0
paddb  %xmm7,%xmm0
movdqa %xmm0,0x80(%rsp,%rax,1)
sub    $0xffffffffffffff80,%rax
pxor   %xmm1,%xmm2
cmp    $0x1000,%rax
jne    1210 <main+0x80>
lea    0xdfc(%rip),%rdi
lea    0xdf9(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     12c9 <main+0x139>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0xc018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%r14
lea    0x2010(%rsp),%r15
lea    0xdd0(%rip),%rbp
lea    0xde2(%rip),%r12
jmp    12fc <main+0x16c>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    12af <main+0x11f>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
movl   $0x1000,0xc(%rsp)
movl   $0xa000,0x8(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   10b0 <rubin_compress@plt>
test   %eax,%eax
jne    13b3 <main+0x223>
mov    0x8(%rsp),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
cmpl   $0x1001,0x8(%rsp)
jge    12f0 <main+0x160>
mov    %r15,%rdi
lea    0x1010(%rsp),%rsi
mov    $0x1000,%edx
mov    $0x1000,%ecx
call   1080 <rubin_decompress@plt>
xor    %r13d,%r13d
jmp    1391 <main+0x201>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
cmp    $0x1000,%r13
je     12f0 <main+0x160>
movzbl 0x10(%rsp,%r13,1),%edx
movzbl 0x1010(%rsp,%r13,1),%ecx
cmp    %cl,%dl
je     1380 <main+0x1f0>
mov    %r12,%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1380 <main+0x1f0>
lea    0xcdc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"asd\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"result is %d, exiting\0A\00"
@.str.3 = [25 x i8] c"Compressed to %i bytes \0A\00"
@.str.4 = [36 x i8] c"Mismatch at position %i: %i -> %i \0A\00"
define void @main() {
%1 = alloca [4096 x i8]
%2 = alloca [40960 x i8]
%3 = alloca [4096 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 165, i32 4096)
store i32 0, i32* %5
br label %11
11: ; preds = %20, %0
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 4096
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = load i32, i32* %5
%16 = trunc i32 %15 to i8
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %18
store i8 %16, i8* %19
br label %20
20: ; preds = %14
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %11
23: ; preds = %11
%24 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %8
br label %25
25: ; preds = %85, %48, %23
%26 = load i32*, i32** %8
%27 = call i32 @feof(i32* %26)
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
br i1 %29, label %30, label %86
30: ; preds = %25
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%32 = load i32*, i32** %8
%33 = call i32 @fread(i8* %31, i32 1, i32 4096, i32* %32)
store i32 4096, i32* %6
store i32 40960, i32* %7
%34 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%35 = getelementptr inbounds [40960 x i8], [40960 x i8]* %2, i64 0, i64 0
%36 = call i32 @rubin_compress(i8* %34, i8* %35, i32* %6, i32* %7)
store i32 %36, i32* %4
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %30
%40 = load i32, i32* %4
%41 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %30
%44 = load i32, i32* %7
%45 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = load i32, i32* %7
%47 = icmp sgt i32 %46, 4096
br i1 %47, label %48, label %49
48: ; preds = %43
br label %25
49: ; preds = %43
%50 = getelementptr inbounds [40960 x i8], [40960 x i8]* %2, i64 0, i64 0
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%52 = call i32 @rubin_decompress(i8* %50, i8* %51, i32 4096, i32 4096)
store i32 0, i32* %5
br label %53
53: ; preds = %82, %49
%54 = load i32, i32* %5
%55 = icmp slt i32 %54, 4096
br i1 %55, label %56, label %85
56: ; preds = %53
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = zext i8 %60 to i32
%62 = load i32, i32* %5
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %63
%65 = load i8, i8* %64
%66 = zext i8 %65 to i32
%67 = icmp ne i32 %61, %66
br i1 %67, label %68, label %81
68: ; preds = %56
%69 = load i32, i32* %5
%70 = load i32, i32* %5
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %71
%73 = load i8, i8* %72
%74 = zext i8 %73 to i32
%75 = load i32, i32* %5
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = zext i8 %78 to i32
%80 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %69, i32 %74, i32 %79)
br label %81
81: ; preds = %68, %56
br label %82
82: ; preds = %81
%83 = load i32, i32* %5
%84 = add nsw i32 %83, 1
store i32 %84, i32* %5
br label %53
85: ; preds = %53
br label %25
86: ; preds = %25
%87 = load i32*, i32** %8
%88 = call i32 @fclose(i32* %87)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"asd\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"result is %d, exiting\0A\00"
@.str.3 = [25 x i8] c"Compressed to %i bytes \0A\00"
@.str.4 = [36 x i8] c"Mismatch at position %i: %i -> %i \0A\00"
define void @main() {
%1 = alloca [4096 x i8]
%2 = alloca [40960 x i8]
%3 = alloca [4096 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [40960 x i8], [40960 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%9 = bitcast i32* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = call i32 @memset(i8* %8, i32 165, i32 4096)
br label %12
12: ; preds = %12, %0
%13 = phi i64 [ 0, %0 ], [ %45, %12 ]
%14 = phi <16 x i8> [ <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, %0 ], [ %46, %12 ]
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %13
%16 = bitcast i8* %15 to <16 x i8>*
store <16 x i8> %14, <16 x i8>* %16
%17 = or i64 %13, 16
%18 = add <16 x i8> %14, <i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16>
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %17
%20 = bitcast i8* %19 to <16 x i8>*
store <16 x i8> %18, <16 x i8>* %20
%21 = or i64 %13, 32
%22 = add <16 x i8> %14, <i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32>
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %21
%24 = bitcast i8* %23 to <16 x i8>*
store <16 x i8> %22, <16 x i8>* %24
%25 = or i64 %13, 48
%26 = add <16 x i8> %14, <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %25
%28 = bitcast i8* %27 to <16 x i8>*
store <16 x i8> %26, <16 x i8>* %28
%29 = or i64 %13, 64
%30 = add <16 x i8> %14, <i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64>
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %29
%32 = bitcast i8* %31 to <16 x i8>*
store <16 x i8> %30, <16 x i8>* %32
%33 = or i64 %13, 80
%34 = add <16 x i8> %14, <i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80, i8 80>
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %33
%36 = bitcast i8* %35 to <16 x i8>*
store <16 x i8> %34, <16 x i8>* %36
%37 = or i64 %13, 96
%38 = add <16 x i8> %14, <i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96, i8 96>
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %37
%40 = bitcast i8* %39 to <16 x i8>*
store <16 x i8> %38, <16 x i8>* %40
%41 = or i64 %13, 112
%42 = add <16 x i8> %14, <i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112, i8 112>
%43 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %41
%44 = bitcast i8* %43 to <16 x i8>*
store <16 x i8> %42, <16 x i8>* %44
%45 = add nuw nsw i64 %13, 128
%46 = xor <16 x i8> %14, <i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128, i8 -128>
%47 = icmp eq i64 %45, 4096
br i1 %47, label %48, label %12
48: ; preds = %12
%49 = call i32* @fopen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%50 = call i32 @feof(i32* %49)
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %84
52: ; preds = %48, %64
%53 = call i32 @fread(i8* %6, i32 1, i32 4096, i32* %49)
store i32 4096, i32* %4
store i32 40960, i32* %5
%54 = call i32 @rubin_compress(i8* %6, i8* %7, i32* %4, i32* %5)
%55 = icmp eq i32 %54, 0
br i1 %55, label %59, label %56
56: ; preds = %52
%57 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%58 = call i32 @exit(i32 0)
unreachable
59: ; preds = %52
%60 = load i32, i32* %5
%61 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %60)
%62 = load i32, i32* %5
%63 = icmp sgt i32 %62, 4096
br i1 %63, label %64, label %67
64: ; preds = %81, %59
%65 = call i32 @feof(i32* %49)
%66 = icmp eq i32 %65, 0
br i1 %66, label %52, label %84
67: ; preds = %59
%68 = call i32 @rubin_decompress(i8* %7, i8* %8, i32 4096, i32 4096)
br label %69
69: ; preds = %67, %81
%70 = phi i64 [ 0, %67 ], [ %82, %81 ]
%71 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 %70
%72 = load i8, i8* %71
%73 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %70
%74 = load i8, i8* %73
%75 = icmp eq i8 %72, %74
br i1 %75, label %81, label %76
76: ; preds = %69
%77 = zext i8 %74 to i32
%78 = zext i8 %72 to i32
%79 = trunc i64 %70 to i32
%80 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %79, i32 %78, i32 %77)
br label %81
81: ; preds = %69, %76
%82 = add nuw nsw i64 %70, 1
%83 = icmp eq i64 %82, 4096
br i1 %83, label %64, label %69
84: ; preds = %64, %48
%85 = call i32 @fclose(i32* %49)
ret void
}