#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*/ FILE;

/* Variables and functions */
int compare(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ test_compress(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int, int);
int /*<<< orphan*/ test_decompress(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int, int);
int main(int argc, char *argv[]) {
  enum {
    MESSAGE_MAX_BYTES = 1024,
    RING_BUFFER_BYTES = 1024 * 256 + MESSAGE_MAX_BYTES,
  };
  char inpFilename[256] = {0};
  char lz4Filename[256] = {0};
  char decFilename[256] = {0};
  if (argc < 2) {
    printf("Please specify input filename\n");
    return 0;
  }
  sprintf(inpFilename, "%s", argv[1]);
  sprintf(lz4Filename, "%s.lz4s", argv[1]);
  sprintf(decFilename, "%s.lz4s.dec", argv[1]);
  printf("inp = [%s]\n", inpFilename);
  printf("lz4 = [%s]\n", lz4Filename);
  printf("dec = [%s]\n", decFilename);
  {
    FILE *inpFp = fopen(inpFilename, "rb");
    FILE *outFp = fopen(lz4Filename, "wb");
    test_compress(outFp, inpFp, MESSAGE_MAX_BYTES, RING_BUFFER_BYTES);
    fclose(outFp);
    fclose(inpFp);
  }
  {
    FILE *inpFp = fopen(lz4Filename, "rb");
    FILE *outFp = fopen(decFilename, "wb");
    test_decompress(outFp, inpFp, MESSAGE_MAX_BYTES, RING_BUFFER_BYTES);
    fclose(outFp);
    fclose(inpFp);
  }
  {
    FILE *inpFp = fopen(inpFilename, "rb");
    FILE *decFp = fopen(decFilename, "rb");
    const int cmp = compare(inpFp, decFp);
    if (0 == cmp)
      printf("Verify : OK\n");
    else
      printf("Verify : NG\n");
    fclose(decFp);
    fclose(inpFp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x310(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11f6 <main+0x76>
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    13f3 <main+0x273>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe13(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdfb(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x310(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xde8(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x110(%rbp),%rsi
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x210(%rbp),%rsi
lea    0xdd8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x310(%rbp),%rsi
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
lea    0xdc6(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x318(%rbp)
lea    -0x210(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x320(%rbp)
mov    -0x320(%rbp),%rdi
mov    -0x318(%rbp),%rsi
mov    $0x400,%edx
mov    $0x40400,%ecx
call   10a0 <test_compress@plt>
mov    -0x320(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x318(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x210(%rbp),%rdi
lea    0xd5d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x328(%rbp)
lea    -0x310(%rbp),%rdi
lea    0xd46(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x330(%rbp)
mov    -0x330(%rbp),%rdi
mov    -0x328(%rbp),%rsi
mov    $0x400,%edx
mov    $0x40400,%ecx
call   1060 <test_decompress@plt>
mov    -0x330(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x328(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x110(%rbp),%rdi
lea    0xcf4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x338(%rbp)
lea    -0x310(%rbp),%rdi
lea    0xcda(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x340(%rbp)
mov    -0x338(%rbp),%rdi
mov    -0x340(%rbp),%rsi
call   1090 <compare@plt>
mov    %eax,-0x344(%rbp)
xor    %eax,%eax
cmp    -0x344(%rbp),%eax
jne    13c6 <main+0x246>
lea    0xca6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    13d4 <main+0x254>
lea    0xca0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x340(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x338(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x308,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movaps %xmm0,0x2f0(%rsp)
movaps %xmm0,0x2e0(%rsp)
movaps %xmm0,0x2d0(%rsp)
movaps %xmm0,0x2c0(%rsp)
movaps %xmm0,0x2b0(%rsp)
movaps %xmm0,0x2a0(%rsp)
movaps %xmm0,0x290(%rsp)
movaps %xmm0,0x280(%rsp)
movaps %xmm0,0x270(%rsp)
movaps %xmm0,0x260(%rsp)
movaps %xmm0,0x250(%rsp)
movaps %xmm0,0x240(%rsp)
movaps %xmm0,0x230(%rsp)
movaps %xmm0,0x220(%rsp)
movaps %xmm0,0x210(%rsp)
movaps %xmm0,0x200(%rsp)
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
cmp    $0x1,%edi
jg     1321 <main+0x191>
lea    0xd3f(%rip),%rdi
call   1040 <puts@plt>
jmp    1485 <main+0x2f5>
mov    %rsi,%r12
mov    0x8(%rsi),%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xcc3(%rip),%rsi
lea    0x200(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rdx
call   1090 <sprintf@plt>
mov    0x8(%r12),%rdx
lea    0xcac(%rip),%rsi
lea    0x100(%rsp),%rbp
mov    %rbp,%rdi
call   1090 <sprintf@plt>
lea    0xca1(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc9c(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc97(%rip),%rdi
mov    %rbp,%rsi
mov    %rbp,%rbx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xc8f(%rip),%r12
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbp
lea    0xc7d(%rip),%r13
mov    %r15,%rdi
mov    %r13,%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbp,%rsi
mov    $0x400,%edx
mov    $0x40400,%ecx
call   10b0 <test_compress@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbp
mov    %rbx,%r14
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
mov    $0x400,%edx
mov    $0x40400,%ecx
call   1070 <test_decompress@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %rsp,%rdi
mov    %r12,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <fopen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %rax,%rsi
call   10a0 <compare@plt>
test   %eax,%eax
lea    0xbe5(%rip),%rax
lea    0xbd2(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x308,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Please specify input filename\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [8 x i8] c"%s.lz4s\00"
@.str.3 = [12 x i8] c"%s.lz4s.dec\00"
@.str.4 = [12 x i8] c"inp = [%s]\0A\00"
@.str.5 = [12 x i8] c"lz4 = [%s]\0A\00"
@.str.6 = [12 x i8] c"dec = [%s]\0A\00"
@.str.7 = [3 x i8] c"rb\00"
@.str.8 = [3 x i8] c"wb\00"
@.str.9 = [13 x i8] c"Verify : OK\0A\00"
@.str.10 = [13 x i8] c"Verify : NG\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = bitcast [256 x i8]* %6 to i8*
%17 = bitcast [256 x i8]* %7 to i8*
%18 = bitcast [256 x i8]* %8 to i8*
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %85
23: ; preds = %2
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %37)
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %39)
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %41)
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %43)
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32* %46, i32** %9
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%48 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %48, i32** %10
%49 = load i32*, i32** %10
%50 = load i32*, i32** %9
%51 = call i32 @test_compress(i32* %49, i32* %50, i32 1024, i32 263168)
%52 = load i32*, i32** %10
%53 = call i32 @fclose(i32* %52)
%54 = load i32*, i32** %9
%55 = call i32 @fclose(i32* %54)
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%57 = call i32* @fopen(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32* %57, i32** %11
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%59 = call i32* @fopen(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %59, i32** %12
%60 = load i32*, i32** %12
%61 = load i32*, i32** %11
%62 = call i32 @test_decompress(i32* %60, i32* %61, i32 1024, i32 263168)
%63 = load i32*, i32** %12
%64 = call i32 @fclose(i32* %63)
%65 = load i32*, i32** %11
%66 = call i32 @fclose(i32* %65)
%67 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%68 = call i32* @fopen(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32* %68, i32** %13
%69 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%70 = call i32* @fopen(i8* %69, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32* %70, i32** %14
%71 = load i32*, i32** %13
%72 = load i32*, i32** %14
%73 = call i32 @compare(i32* %71, i32* %72)
store i32 %73, i32* %15
%74 = load i32, i32* %15
%75 = icmp eq i32 0, %74
br i1 %75, label %76, label %78
76: ; preds = %23
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
br label %80
78: ; preds = %23
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0))
br label %80
80: ; preds = %78, %76
%81 = load i32*, i32** %14
%82 = call i32 @fclose(i32* %81)
%83 = load i32*, i32** %13
%84 = call i32 @fclose(i32* %83)
store i32 0, i32* %3
br label %85
85: ; preds = %80, %21
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
@.str.2 = [8 x i8] c"%s.lz4s\00"
@.str.3 = [12 x i8] c"%s.lz4s.dec\00"
@.str.4 = [12 x i8] c"inp = [%s]\0A\00"
@.str.5 = [12 x i8] c"lz4 = [%s]\0A\00"
@.str.6 = [12 x i8] c"dec = [%s]\0A\00"
@.str.7 = [3 x i8] c"rb\00"
@.str.8 = [3 x i8] c"wb\00"
@str = [12 x i8] c"Verify : NG\00"
@str.11 = [12 x i8] c"Verify : OK\00"
@str.12 = [30 x i8] c"Please specify input filename\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%9 = icmp slt i32 %0, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.12, i64 0, i64 0))
br label %40
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = call i8* @strcpy(i8* %6, i8* dereferenceable(1) %14)
%16 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%17 = load i8*, i8** %13
%18 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %7)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %8)
%22 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%23 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%24 = call i32 @test_compress(i32* %23, i32* %22, i32 1024, i32 263168)
%25 = call i32 @fclose(i32* %23)
%26 = call i32 @fclose(i32* %22)
%27 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%28 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%29 = call i32 @test_decompress(i32* %28, i32* %27, i32 1024, i32 263168)
%30 = call i32 @fclose(i32* %28)
%31 = call i32 @fclose(i32* %27)
%32 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%33 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%34 = call i32 @compare(i32* %32, i32* %33)
%35 = icmp eq i32 %34, 0
%36 = select i1 %35, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str.11, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0)
%37 = call i32 @puts(i8* dereferenceable(1) %36)
%38 = call i32 @fclose(i32* %33)
%39 = call i32 @fclose(i32* %32)
br label %40
40: ; preds = %12, %10
ret i32 0
}