// File: yuansliu[P]HiRGC/hirgc.cpp
// Function: compressSet(char*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&)
int compressSet(char *ref_fold, vector<string> &fold_list, vector<string> &chr_name_list) {//hirgc refFold tarFold
	char ref[1024], tar[1024], res[1024];
	char cmd[1024]; 
	char temp[1024];
	
	int fold_size = fold_list.size();

	for (int ti = 0; ti < fold_size; ti++) {
		sprintf(temp, "%s_ref_%s", fold_list[ti].c_str(), ref_fold);
		sprintf(cmd, "rm -r %s", temp);
		system(cmd);
		sprintf(cmd, "mkdir %s", temp);
		system(cmd);
	}

	initial(); //important*************

	int size = chr_name_list.size();
	for (int i = 0; i < size; i++) {

		sprintf(ref, "%s/%s", ref_fold, chr_name_list[i].c_str());

		readRefFile(ref);
		preProcessRef();

		for (int ti = 0; ti < fold_size; ti++) {
			sprintf(temp, "%s_ref_%s", fold_list[ti].c_str(), ref_fold);

			sprintf(tar, "%s/%s", fold_list[ti].c_str(), chr_name_list[i].c_str());
			readTarFile(tar);

			printf("compressing %s ...\n", tar);

			sprintf(res, "%s/%s", temp, chr_name_list[i].c_str());
			// compressFile(ref, tar, res);
			searchMatch(res);
		}
	}

	for (int ti = 0; ti < fold_size; ti++) {
		sprintf(temp, "%s_ref_%s", fold_list[ti].c_str(), ref_fold);

		sprintf(cmd, "./7za a %s.7z %s -m0=PPMd", temp, temp);
		system(cmd);

		sprintf(cmd, "rm -r %s", temp);
		system(cmd);
	}
	clear();
	return 0;
}

// Assembly:
subq $0x1478, %rsp           # imm = 0x1478
movq %rdi, 0x1470(%rsp)
movq %rsi, 0x1468(%rsp)
movq %rdx, 0x1460(%rsp)
movq 0x1468(%rsp), %rdi
callq 0x5520
movl %eax, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movl 0x58(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jge 0x4618
leaq 0x60(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x1468(%rsp), %rdi
movslq 0x58(%rsp), %rsi
callq 0x5540
movq %rax, %rdi
callq 0x20b0
movq 0x40(%rsp), %rdi
movq %rax, %rdx
movq 0x1470(%rsp), %rcx
leaq 0x3ac8(%rip), %rsi      # 0x8079
movb $0x0, %al
callq 0x2060
leaq 0x460(%rsp), %rdi
leaq 0x60(%rsp), %rdx
leaq 0x3ad7(%rip), %rsi      # 0x80a3
movb $0x0, %al
callq 0x2060
leaq 0x460(%rsp), %rdi
callq 0x2140
leaq 0x460(%rsp), %rdi
leaq 0x60(%rsp), %rdx
leaq 0x3ab8(%rip), %rsi      # 0x80ac
movb $0x0, %al
callq 0x2060
leaq 0x460(%rsp), %rdi
callq 0x2140
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x4568
callq 0x52f0
movq 0x1460(%rsp), %rdi
callq 0x5520
movl %eax, 0x54(%rsp)
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
cmpl 0x54(%rsp), %eax
jge 0x47fc
leaq 0x1060(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x1470(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x1460(%rsp), %rdi
movslq 0x50(%rsp), %rsi
callq 0x5540
movq %rax, %rdi
callq 0x20b0
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rdx
movq %rax, %rcx
leaq 0x3a29(%rip), %rsi      # 0x80b5
movb $0x0, %al
callq 0x2060
leaq 0x1060(%rsp), %rdi
callq 0x31c0
callq 0x3d10
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jge 0x47ea
leaq 0x60(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x1468(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0x5540
movq %rax, %rdi
callq 0x20b0
movq 0x8(%rsp), %rdi
movq %rax, %rdx
movq 0x1470(%rsp), %rcx
leaq 0x3983(%rip), %rsi      # 0x8079
movb $0x0, %al
callq 0x2060
leaq 0xc60(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x1468(%rsp), %rdi
movslq 0x4c(%rsp), %rsi
callq 0x5540
movq %rax, %rdi
callq 0x20b0
movq %rax, 0x18(%rsp)
movq 0x1460(%rsp), %rdi
movslq 0x50(%rsp), %rsi
callq 0x5540
movq %rax, %rdi
callq 0x20b0
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
leaq 0x395e(%rip), %rsi      # 0x80b5
movb $0x0, %al
callq 0x2060
leaq 0xc60(%rsp), %rdi
callq 0x3310
leaq 0xc60(%rsp), %rsi
leaq 0x3951(%rip), %rdi      # 0x80cb
movb $0x0, %al
callq 0x2040
leaq 0x860(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x60(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x1460(%rsp), %rdi
movslq 0x50(%rsp), %rsi
callq 0x5540
movq %rax, %rdi
callq 0x20b0
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rdx
movq %rax, %rcx
leaq 0x38ef(%rip), %rsi      # 0x80b5
movb $0x0, %al
callq 0x2060
leaq 0x860(%rsp), %rdi
callq 0x3e90
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x46ad
jmp 0x47ec
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x4636
movl $0x0, 0x48(%rsp)
movl 0x48(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jge 0x48b7
leaq 0x60(%rsp), %rax
movq %rax, (%rsp)
movq 0x1468(%rsp), %rdi
movslq 0x48(%rsp), %rsi
callq 0x5540
movq %rax, %rdi
callq 0x20b0
movq (%rsp), %rdi
movq %rax, %rdx
movq 0x1470(%rsp), %rcx
leaq 0x382e(%rip), %rsi      # 0x8079
movb $0x0, %al
callq 0x2060
leaq 0x460(%rsp), %rdi
leaq 0x60(%rsp), %rdx
leaq 0x60(%rsp), %rcx
leaq 0x3818(%rip), %rsi      # 0x8083
movb $0x0, %al
callq 0x2060
leaq 0x460(%rsp), %rdi
callq 0x2140
leaq 0x460(%rsp), %rdi
leaq 0x60(%rsp), %rdx
leaq 0x3810(%rip), %rsi      # 0x80a3
movb $0x0, %al
callq 0x2060
leaq 0x460(%rsp), %rdi
callq 0x2140
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x4804
callq 0x53f0
xorl %eax, %eax
addq $0x1478, %rsp           # imm = 0x1478
retq
nopw %cs:(%rax,%rax)