#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 */
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ calloc(long, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
long fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ smaz_compress_ref(char *, long, char *, long);
void bench_old_smaz() {
  FILE *infile;
  char *in;
  char *comp_out;
  char *de_comp_out;
  long numbytes;
  int num_loops = 1000;
  infile = fopen("war_of_the_worlds.txt", "r");
  if (infile == NULL) {
    printf("Missing war of the worlds text, you can download the text here: "
           "http://www.gutenberg.org/ebooks/36 and save it as "
           "war_of_the_worlds.txt\n");
    exit(1);
  }
  fseek(infile, 0L, SEEK_END);
  numbytes = ftell(infile);
  printf("Processing %d bytes, %d times\n", (int)numbytes, num_loops);
  fseek(infile, 0L, SEEK_SET);
  in = (char *)calloc(numbytes, sizeof(char));
  comp_out = (char *)calloc(numbytes, sizeof(char));
  de_comp_out = (char *)calloc(numbytes, sizeof(char));
  numbytes = fread(in, sizeof(char), numbytes, infile);
  fclose(infile);
  {
    struct timeval t1, t2;
    int x;
    gettimeofday(&t1, NULL);
    for (x = 0; x < num_loops; x++) {
      smaz_compress_ref(in, numbytes, comp_out, numbytes);
    }
    gettimeofday(&t2, NULL);
    printf("time = %u.%06u\n", (unsigned int)t1.tv_sec,
           (unsigned int)t1.tv_usec);
    printf("time = %u.%06u\n", (unsigned int)t2.tv_sec,
           (unsigned int)t2.tv_usec);
  }
  free(in);
  free(comp_out);
  free(de_comp_out);
}


x86 assembly (clang, -O0):
<bench_old_smaz>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x3e8,-0x2c(%rbp)
lea    0xe3a(%rip),%rdi
lea    0xe49(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11f9 <bench_old_smaz+0x49>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1090 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,%esi
mov    -0x2c(%rbp),%edx
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    0x2d9a(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <fseek@plt>
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
mov    $0x1,%esi
call   1080 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x54(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    12e5 <bench_old_smaz+0x135>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   10d0 <smaz_compress_ref@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    12b6 <bench_old_smaz+0x106>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
mov    -0x38(%rbp),%rax
mov    %eax,%esi
mov    -0x40(%rbp),%rax
mov    %eax,%edx
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x48(%rbp),%rax
mov    %eax,%esi
mov    -0x50(%rbp),%rax
mov    %eax,%edx
lea    0xda1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bench_old_smaz>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xece(%rip),%rdi
lea    0xe24(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1315 <bench_old_smaz+0x155>
mov    %rax,%r12
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r12,%rdi
call   10a0 <ftell@plt>
mov    %rax,%r13
lea    0xdf0(%rip),%rdi
mov    $0x3e8,%r15d
mov    %r13d,%esi
mov    $0x3e8,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   10b0 <fseek@plt>
mov    %r13,%rdi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,%rbp
mov    %r13,%rdi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,%r14
mov    %r13,%rdi
mov    $0x1,%esi
call   1090 <calloc@plt>
mov    %rax,(%rsp)
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
mov    %r12,%rcx
call   1050 <fread@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   1060 <fclose@plt>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   10e0 <smaz_compress_ref@plt>
add    $0xffffffff,%r15d
jne    12a0 <bench_old_smaz+0xe0>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
mov    0x18(%rsp),%edx
mov    0x20(%rsp),%esi
lea    0xd4f(%rip),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rsp),%edx
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xd15(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [22 x i8] c"war_of_the_worlds.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [137 x i8] c"Missing war of the worlds text, you can download the text here: http://www.gutenberg.org/ebooks/36 and save it as war_of_the_worlds.txt\0A\00"
@SEEK_END = global i32 0
@.str.3 = [31 x i8] c"Processing %d bytes, %d times\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [16 x i8] c"time = %u.%06u\0A\00"
define void @bench_old_smaz() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca %struct.timeval
%8 = alloca %struct.timeval
%9 = alloca i32
store i32 1000, i32* %6
%10 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %1
%11 = load i32*, i32** %1
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = load i32*, i32** %1
%18 = load i32, i32* @SEEK_END
%19 = call i32 @fseek(i32* %17, i64 0, i32 %18)
%20 = load i32*, i32** %1
%21 = call i64 @ftell(i32* %20)
store i64 %21, i64* %5
%22 = load i64, i64* %5
%23 = trunc i64 %22 to i32
%24 = load i32, i32* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %23, i32 %24)
%26 = load i32*, i32** %1
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %26, i64 0, i32 %27)
%29 = load i64, i64* %5
%30 = call i64 @calloc(i64 %29, i32 1)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %2
%32 = load i64, i64* %5
%33 = call i64 @calloc(i64 %32, i32 1)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %3
%35 = load i64, i64* %5
%36 = call i64 @calloc(i64 %35, i32 1)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %4
%38 = load i8*, i8** %2
%39 = load i64, i64* %5
%40 = load i32*, i32** %1
%41 = call i64 @fread(i8* %38, i32 1, i64 %39, i32* %40)
store i64 %41, i64* %5
%42 = load i32*, i32** %1
%43 = call i32 @fclose(i32* %42)
%44 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
store i32 0, i32* %9
br label %45
45: ; preds = %55, %16
%46 = load i32, i32* %9
%47 = load i32, i32* %6
%48 = icmp slt i32 %46, %47
br i1 %48, label %49, label %58
49: ; preds = %45
%50 = load i8*, i8** %2
%51 = load i64, i64* %5
%52 = load i8*, i8** %3
%53 = load i64, i64* %5
%54 = call i32 @smaz_compress_ref(i8* %50, i64 %51, i8* %52, i64 %53)
br label %55
55: ; preds = %49
%56 = load i32, i32* %9
%57 = add nsw i32 %56, 1
store i32 %57, i32* %9
br label %45
58: ; preds = %45
%59 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%60 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%61 = load i64, i64* %60
%62 = trunc i64 %61 to i32
%63 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%64 = load i64, i64* %63
%65 = trunc i64 %64 to i32
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %62, i32 %65)
%67 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%68 = load i64, i64* %67
%69 = trunc i64 %68 to i32
%70 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%71 = load i64, i64* %70
%72 = trunc i64 %71 to i32
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %69, i32 %72)
%74 = load i8*, i8** %2
%75 = call i32 @free(i8* %74)
%76 = load i8*, i8** %3
%77 = call i32 @free(i8* %76)
%78 = load i8*, i8** %4
%79 = call i32 @free(i8* %78)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [22 x i8] c"war_of_the_worlds.txt\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@.str.3 = [31 x i8] c"Processing %d bytes, %d times\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [16 x i8] c"time = %u.%06u\0A\00"
@str = [136 x i8] c"Missing war of the worlds text, you can download the text here: http://www.gutenberg.org/ebooks/36 and save it as war_of_the_worlds.txt\00"
define void @bench_old_smaz() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([136 x i8], [136 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %3, i64 0, i32 %9)
%11 = tail call i64 @ftell(i32* %3)
%12 = trunc i64 %11 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %12, i32 1000)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %3, i64 0, i32 %14)
%16 = tail call i64 @calloc(i64 %11, i32 1)
%17 = inttoptr i64 %16 to i8*
%18 = tail call i64 @calloc(i64 %11, i32 1)
%19 = inttoptr i64 %18 to i8*
%20 = tail call i64 @calloc(i64 %11, i32 1)
%21 = tail call i64 @fread(i8* %17, i32 1, i64 %11, i32* %3)
%22 = tail call i32 @fclose(i32* %3)
%23 = bitcast %struct.timeval* %1 to i8*
%24 = bitcast %struct.timeval* %2 to i8*
%25 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
br label %26
26: ; preds = %8, %26
%27 = phi i32 [ 0, %8 ], [ %29, %26 ]
%28 = tail call i32 @smaz_compress_ref(i8* %17, i64 %21, i8* %19, i64 %21)
%29 = add nuw nsw i32 %27, 1
%30 = icmp eq i32 %29, 1000
br i1 %30, label %31, label %26
31: ; preds = %26
%32 = inttoptr i64 %20 to i8*
%33 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%35 = load i64, i64* %34
%36 = trunc i64 %35 to i32
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%38 = load i64, i64* %37
%39 = trunc i64 %38 to i32
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %36, i32 %39)
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%42 = load i64, i64* %41
%43 = trunc i64 %42 to i32
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%45 = load i64, i64* %44
%46 = trunc i64 %45 to i32
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %43, i32 %46)
%48 = tail call i32 @free(i8* %17)
%49 = tail call i32 @free(i8* %19)
%50 = tail call i32 @free(i8* %32)
ret void
}