// File: /workspace/github_c_makefile_star2_O2/ijleesw[P]data-compression/src/checker/main.cpp
// Function: main
int main(int argc, char** argv)
{
	uchar* original;
	uchar* compressed;
	uchar* decompressed;
	int o_numofsymbols;
	int c_numofsymbols;
	long o_length, o_actual_length;
	long c_length, c_actual_length;
	long d_length;
	double ratio;
	bool is_same = true;
	bool skip = false;
	string result;


	if (argc != 5) {
		cout << "Usage: "<<argv[0];
		cout << " <data name> <original file path> <compressed file path> <decompressed file path (or -skip)>\n";
		return -1;
	}
	if (strcmp(argv[4], "-skip") == 0) skip = true;

	cout << argv[1] << ": ";

	if (!readbyte2buf(argv[2], original, &o_length)) {
		perror("File open error");
		return -1;
	}
	if (!readbyte2buf(argv[3], compressed, &c_length)) {
		perror("File open error");
		return -1;
	}

	o_numofsymbols = symbol_counter(original, o_length);
	o_actual_length = o_length * ceil_log2(o_numofsymbols) / 8;
	c_numofsymbols = symbol_counter(compressed, c_length);
	c_actual_length = c_length * ceil_log2(c_numofsymbols) / 8;

	ratio = (double)c_length/o_length;

	if (!skip){
		if (!readbyte2buf(argv[4], decompressed, &d_length)) {
			perror("File open error");
			return -1;
		}

		if (o_length != d_length) is_same = false;

		if (is_same) {
		for (long i = 0; i < o_length; i++) {
			if (original[i] != decompressed[i]) {
				is_same = false;
				break;
			}
		}
		}
	}

	if (is_same) {
		printf("%ld(%ld, %d) -> %ld(%ld, %d)   Ratio: %.3f%% (%.3f%%)\n",
			    o_length, o_actual_length, o_numofsymbols, c_length, c_actual_length, c_numofsymbols,
			    100*ratio, (double)100*c_actual_length/o_actual_length);
	/*
		printf("%ld(%ld) -> %ld   Ratio: %.3f%% (%.3f%%)\n",
			    o_length, o_actual_length, c_length,
			    100*ratio, (double)100*c_length/o_actual_length);	
	*/
	}
	else cout << "decompressed file not identical to the original file.\n";


	delete original;
	delete compressed;
	if (!skip) delete decompressed;

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
leaq -0x88(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rsi, %r14
movb $0x0, (%rax)
cmpl $0x5, %edi
jne 0x2835
movq 0x20(%r14), %rdi
leaq 0x960(%rip), %rsi       # 0x3076
callq 0x21d0
movl %eax, -0x34(%rbp)
movq 0x8(%r14), %rsi
movq 0x28af(%rip), %rdi      # 0x4fd8
callq 0x2160
leaq 0x8e0(%rip), %rsi       # 0x3015
movq %rax, %rdi
callq 0x2160
movq 0x10(%r14), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x2472
testl %eax, %eax
je 0x28fa
movq 0x18(%r14), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x2472
testl %eax, %eax
je 0x28fa
movq -0x78(%rbp), %r15
movq -0x68(%rbp), %r13
movq %r15, %rdi
movl %r13d, %esi
callq 0x2922
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %edi
callq 0x299b
cltq
imulq %r13, %rax
pushq $0x8
popq %r12
cqto
idivq %r12
movq %rax, -0x48(%rbp)
movq -0x70(%rbp), %rdi
movq -0x60(%rbp), %rbx
movq %rdi, -0x50(%rbp)
movl %ebx, %esi
callq 0x2922
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %edi
callq 0x299b
cltq
imulq %rbx, %rax
cqto
idivq %r12
movq %rax, %r12
cmpl $0x0, -0x34(%rbp)
je 0x286b
movq 0x20(%r14), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x2472
testl %eax, %eax
je 0x28fa
cmpq -0x58(%rbp), %r13
jne 0x281d
movq -0x40(%rbp), %rax
xorl %ecx, %ecx
testq %r13, %r13
movl $0x0, %edx
cmovgq %r13, %rdx
cmpq %rcx, %rdx
je 0x286b
movb (%r15,%rcx), %sil
leaq 0x1(%rcx), %rdi
cmpb (%rax,%rcx), %sil
movq %rdi, %rcx
je 0x2807
movq 0x27b4(%rip), %rdi      # 0x4fd8
leaq 0x898(%rip), %rsi       # 0x30c3
callq 0x2160
jmp 0x28bb
movq 0x279c(%rip), %rdi      # 0x4fd8
leaq 0x7cd(%rip), %rsi       # 0x3010
callq 0x2160
movq (%r14), %rsi
movq %rax, %rdi
callq 0x2160
movq 0x277e(%rip), %rdi      # 0x4fd8
leaq 0x7b7(%rip), %rsi       # 0x3018
callq 0x2160
pushq $-0x1
popq %rbx
jmp 0x28dd
cvtsi2sd %rbx, %xmm0
cvtsi2sd %r13, %xmm1
divsd %xmm1, %xmm0
movsd 0x787(%rip), %xmm2      # 0x3008
mulsd %xmm2, %xmm0
cvtsi2sd %r12, %xmm1
mulsd %xmm2, %xmm1
movq -0x48(%rbp), %rdx
cvtsi2sd %rdx, %xmm2
divsd %xmm2, %xmm1
movl -0x2c(%rbp), %eax
movl %eax, (%rsp)
leaq 0x7e4(%rip), %rdi       # 0x308c
movq %r13, %rsi
movl -0x30(%rbp), %ecx
movq %rbx, %r8
movq %r12, %r9
movb $0x2, %al
callq 0x2040
movq %r15, %rdi
callq 0x2140
movq -0x50(%rbp), %rdi
callq 0x2140
xorl %ebx, %ebx
cmpl $0x0, -0x34(%rbp)
je 0x28dd
movq -0x40(%rbp), %rdi
callq 0x2140
leaq -0x98(%rbp), %rdi
callq 0x20d0
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x77b(%rip), %rdi       # 0x307c
callq 0x2120
jmp 0x2866
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x20d0
movq %rbx, %rdi
callq 0x2210