// File: /workspace/github_c_makefile_star2_O0/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
subq $0x100, %rsp            # imm = 0x100
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x1, -0x61(%rbp)
movb $0x0, -0x62(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x21c0
cmpl $0x5, -0x8(%rbp)
je 0x2a62
movq 0x45ee(%rip), %rdi      # 0x6fd8
leaq 0x161f(%rip), %rsi      # 0x4010
callq 0x2140
movq %rax, -0xa8(%rbp)
jmp 0x29ff
movq -0xa8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
callq 0x2140
jmp 0x2a14
movq 0x45bd(%rip), %rdi      # 0x6fd8
leaq 0x15f6(%rip), %rsi      # 0x4018
callq 0x2140
jmp 0x2a29
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x98(%rbp)
jmp 0x2dbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x20d0
jmp 0x2dd3
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
leaq 0x1605(%rip), %rsi      # 0x4076
callq 0x21d0
cmpl $0x0, %eax
jne 0x2a7f
movb $0x1, -0x62(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq 0x454a(%rip), %rdi      # 0x6fd8
callq 0x2140
movq %rax, -0xb0(%rbp)
jmp 0x2a9c
movq -0xb0(%rbp), %rdi
leaq 0x156b(%rip), %rsi      # 0x4015
callq 0x2140
jmp 0x2ab1
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x18(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x2580
movl %eax, -0xb4(%rbp)
jmp 0x2ace
movl -0xb4(%rbp), %eax
cmpl $0x0, %eax
jne 0x2afd
leaq 0x159c(%rip), %rdi      # 0x407c
callq 0x2110
jmp 0x2ae7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x98(%rbp)
jmp 0x2dbb
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x20(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x2580
movl %eax, -0xb8(%rbp)
jmp 0x2b1a
movl -0xb8(%rbp), %eax
cmpl $0x0, %eax
jne 0x2b49
leaq 0x1550(%rip), %rdi      # 0x407c
callq 0x2110
jmp 0x2b33
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x98(%rbp)
jmp 0x2dbb
movq -0x18(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x2de0
movl %eax, -0xbc(%rbp)
jmp 0x2b5d
movl -0xbc(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xc8(%rbp)
movl -0x2c(%rbp), %edi
callq 0x2e80
movl %eax, -0xc0(%rbp)
jmp 0x2b81
movq -0xc8(%rbp), %rax
movl -0xc0(%rbp), %ecx
movslq %ecx, %rcx
imulq %rcx, %rax
movq %rax, %rcx
addq $0x7, %rcx
testq %rax, %rax
cmovsq %rcx, %rax
sarq $0x3, %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x2de0
movl %eax, -0xcc(%rbp)
jmp 0x2bbf
movl -0xcc(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl -0x30(%rbp), %edi
callq 0x2e80
movl %eax, -0xd0(%rbp)
jmp 0x2be3
movq -0xd8(%rbp), %rax
movl -0xd0(%rbp), %ecx
movslq %ecx, %rcx
imulq %rcx, %rax
movl $0x8, %ecx
cqto
idivq %rcx
movq %rax, -0x50(%rbp)
cvtsi2sdq -0x48(%rbp), %xmm0
cvtsi2sdq -0x38(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
testb $0x1, -0x62(%rbp)
jne 0x2cde
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x2580
movl %eax, -0xdc(%rbp)
jmp 0x2c41
movl -0xdc(%rbp), %eax
cmpl $0x0, %eax
jne 0x2c70
leaq 0x1429(%rip), %rdi      # 0x407c
callq 0x2110
jmp 0x2c5a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x98(%rbp)
jmp 0x2dbb
movq -0x38(%rbp), %rax
cmpq -0x58(%rbp), %rax
je 0x2c7e
movb $0x0, -0x61(%rbp)
testb $0x1, -0x61(%rbp)
je 0x2cdc
movq $0x0, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0x2cda
movq -0x18(%rbp), %rax
movq -0xa0(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x28(%rbp), %rcx
movq -0xa0(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x2cc4
movb $0x0, -0x61(%rbp)
jmp 0x2cda
jmp 0x2cc6
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
jmp 0x2c8f
jmp 0x2cdc
jmp 0x2cde
testb $0x1, -0x61(%rbp)
je 0x2d34
movq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdx
movl -0x2c(%rbp), %ecx
movq -0x48(%rbp), %r8
movq -0x50(%rbp), %r9
movl -0x30(%rbp), %edi
movsd -0x60(%rbp), %xmm0
movsd 0x1301(%rip), %xmm2     # 0x4008
mulsd %xmm2, %xmm0
cvtsi2sd %r9, %xmm1
mulsd %xmm2, %xmm1
cvtsi2sd %rdx, %xmm2
divsd %xmm2, %xmm1
movq %rsp, %rax
movl %edi, (%rax)
leaq 0x1363(%rip), %rdi      # 0x408c
movb $0x2, %al
callq 0x2040
jmp 0x2d32
jmp 0x2d4b
movq 0x429d(%rip), %rdi      # 0x6fd8
leaq 0x1381(%rip), %rsi      # 0x40c3
callq 0x2140
jmp 0x2d49
jmp 0x2d4b
movq -0x18(%rbp), %rax
movq %rax, -0xe8(%rbp)
cmpq $0x0, %rax
je 0x2d68
movq -0xe8(%rbp), %rdi
callq 0x2130
movq -0x20(%rbp), %rax
movq %rax, -0xf0(%rbp)
cmpq $0x0, %rax
je 0x2d85
movq -0xf0(%rbp), %rdi
callq 0x2130
testb $0x1, -0x62(%rbp)
jne 0x2daa
movq -0x28(%rbp), %rax
movq %rax, -0xf8(%rbp)
cmpq $0x0, %rax
je 0x2da8
movq -0xf8(%rbp), %rdi
callq 0x2130
jmp 0x2daa
movl $0x0, -0x4(%rbp)
movl $0x1, -0x98(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x20d0
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x2220
nop