// File: /workspace/github_cpp_makefile_star2_O3/dudulu233[P]EMA-Tool/ema_tool.cpp
// Function: get_cfg(char const*, Config_ema*)
void get_cfg(const char* cfg_path, cfg_ema* cfg) {

	string key[9] = { "cache_file","cache_size",
					"sampling_P","sampling_T",
					"io_trace_start_time","re_dis_start_time","io_trace_end_time",
					"fixed_mem_size","unique_ratio" };
	string value[9] = { "" };
	int index = 0;
	fstream cfg_file;
	cfg_file.open(cfg_path);
	if (!cfg_file.is_open()) {
		printf("error! config file open fail!\n");
		exit(-1);
	}
	while (index < 9)
	{
		char tmp[128];
		cfg_file.getline(tmp, 128);//128 probably enough
		string line(tmp);

		size_t pos = line.find('=');//find the location of "=",get the key and value
		if (pos == string::npos) {
			printf("error! config format incorrect!\n");
			exit(-1);
		}

		string tmpKey = line.substr(0, pos);//get key
		if (key[index] != tmpKey)
		{
			printf("error! config key incorrect!\n");
			exit(-1);
		}
		value[index] = line.substr(pos + 1);//get value
		++index;

	}
	cfg_file.close();

	cfg->cache_file = value[0];
	cfg->cache_size = stoi(value[1]);
	cfg->sampling_P = stoi(value[2]);
	cfg->sampling_T = stoi(value[3]);
	cfg->io_trace_start_time = StringToDatetime(value[4].c_str());
	cfg->re_dis_start_time = StringToDatetime(value[5].c_str());
	cfg->io_trace_end_time = StringToDatetime(value[6].c_str());
	cfg->fixed_mem_size = stoi(value[7]);
	cfg->unique_ratio = stoi(value[8]);
	
	uint64 trace_line = 0;
	string tmp_str;
	if(cfg->fixed_mem_size > 0){
		ifstream tmp_file(cfg->cache_file.c_str());
		while(getline(tmp_file,tmp_str)){
			trace_line++;
		}
		tmp_file.close();
		//limit_trace_line = 13500·fixed_mem_size - 8888
		//sampling_P = trace_line / limit_trace_line / unique_ratio
		cfg->sampling_P = trace_line / (13500 * cfg->fixed_mem_size - 8888) / cfg->unique_ratio * 1.05 + 0.6;
		cfg->sampling_T = 1;

	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x6c8, %rsp            # imm = 0x6C8
movq %rsi, %rbx
movq %rdi, %r12
leaq 0x80(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x38f7(%rip), %rsi      # 0x60c0
leaq 0x38fa(%rip), %rdx      # 0x60ca
leaq 0x70(%rsp), %r14
movq %r14, %rdi
callq 0x3c28
leaq 0x90(%rsp), %r15
leaq 0xa0(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x38d3(%rip), %rsi      # 0x60cb
leaq 0x38d6(%rip), %rdx      # 0x60d5
movq %r15, %rdi
callq 0x3c28
leaq 0xb0(%rsp), %r15
leaq 0xc0(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x38b4(%rip), %rsi      # 0x60d6
leaq 0x38b7(%rip), %rdx      # 0x60e0
movq %r15, %rdi
callq 0x3c28
leaq 0xd0(%rsp), %r15
leaq 0xe0(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3895(%rip), %rsi      # 0x60e1
leaq 0x3898(%rip), %rdx      # 0x60eb
movq %r15, %rdi
callq 0x3c28
leaq 0xf0(%rsp), %r15
leaq 0x100(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3876(%rip), %rsi      # 0x60ec
leaq 0x3882(%rip), %rdx      # 0x60ff
movq %r15, %rdi
callq 0x3c28
leaq 0x110(%rsp), %r15
leaq 0x120(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3860(%rip), %rsi      # 0x6100
leaq 0x386a(%rip), %rdx      # 0x6111
movq %r15, %rdi
callq 0x3c28
leaq 0x130(%rsp), %r15
leaq 0x140(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3848(%rip), %rsi      # 0x6112
leaq 0x3852(%rip), %rdx      # 0x6123
movq %r15, %rdi
callq 0x3c28
leaq 0x150(%rsp), %r15
leaq 0x160(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3830(%rip), %rsi      # 0x6124
leaq 0x3837(%rip), %rdx      # 0x6132
movq %r15, %rdi
callq 0x3c28
leaq 0x170(%rsp), %r15
leaq 0x180(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x3815(%rip), %rsi      # 0x6133
leaq 0x381a(%rip), %rdx      # 0x613f
movq %r15, %rdi
callq 0x3c28
leaq 0x1a0(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3c71(%rip), %rdx      # 0x65b1
leaq 0x190(%rsp), %rdi
movq %rdx, %rsi
callq 0x3c28
movl $0x30, %eax
leaq (%rsp,%rax), %rcx
addq $0x190, %rcx            # imm = 0x190
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x130, %rax            # imm = 0x130
jne 0x2955
leaq 0x4b8(%rsp), %rdi
callq 0x22d0
leaq 0x4b8(%rsp), %rdi
movq %r12, %rsi
movl $0x18, %edx
callq 0x2200
movq %rbx, 0x8(%rsp)
leaq 0x538(%rsp), %rdi
callq 0x20a0
testb %al, %al
je 0x2ee7
xorl %r14d, %r14d
leaq 0x2b0(%rsp), %r15
leaq 0x10(%rsp), %r12
leaq 0x50(%rsp), %rbp
leaq 0x4b8(%rsp), %rbx
movq 0x4b8(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2230
movsbl %al, %ecx
movl $0x80, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2440
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r15, %rdi
callq 0x2110
leaq (%rsp,%rax), %rdx
addq $0x2b0, %rdx            # imm = 0x2B0
movq %r12, %rdi
movq %r15, %rsi
callq 0x3c28
movq %r12, %rdi
movl $0x3d, %esi
xorl %edx, %edx
callq 0x2300
cmpq $-0x1, %rax
je 0x2ed1
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x2280
movq 0x78(%rsp,%r14), %rdx
cmpq 0x38(%rsp), %rdx
jne 0x2ec8
testq %rdx, %rdx
je 0x2a82
movq 0x30(%rsp), %rsi
movq 0x70(%rsp,%r14), %rdi
callq 0x2270
testl %eax, %eax
jne 0x2ec8
incq %rbx
movq %rbp, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq $-0x1, %rcx
callq 0x2280
leaq (%rsp,%r14), %rdi
addq $0x190, %rdi            # imm = 0x190
movq %rbp, %rsi
callq 0x22f0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
leaq 0x4b8(%rsp), %rbx
je 0x2ac9
callq 0x2220
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2add
callq 0x2220
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2af1
callq 0x2220
addq $0x20, %r14
cmpq $0x120, %r14            # imm = 0x120
jne 0x29d4
leaq 0x4b8(%rsp), %rdi
callq 0x2050
movq 0x8(%rsp), %rdi
leaq 0x190(%rsp), %rsi
callq 0x2120
movq 0x1b0(%rsp), %rbx
callq 0x2030
movq %rax, %r14
movl (%rax), %ebp
movl $0x0, (%rax)
leaq 0x2b0(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
movl $0xa, %edx
callq 0x2340
cmpq %rbx, (%r15)
je 0x2ef0
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x2efc
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x2efc
testl %ecx, %ecx
jne 0x2b79
movl %ebp, (%r14)
movq 0x8(%rsp), %rcx
movl %eax, 0x20(%rcx)
movq 0x1d0(%rsp), %rbx
movl (%r14), %ebp
movl $0x0, (%r14)
leaq 0x2b0(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
movl $0xa, %edx
callq 0x2340
cmpq %rbx, (%r15)
je 0x2f08
movabsq $-0x100000000, %r12     # imm = 0xFFFFFFFF00000000
leaq -0x80000000(%rax), %rcx
cmpq %r12, %rcx
jb 0x2f14
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x2f14
testl %ecx, %ecx
jne 0x2be1
movl %ebp, (%r14)
movq 0x8(%rsp), %rcx
movl %eax, 0x24(%rcx)
movq 0x1f0(%rsp), %rbx
movl (%r14), %ebp
movl $0x0, (%r14)
leaq 0x2b0(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
movl $0xa, %edx
callq 0x2340
cmpq %rbx, (%r15)
je 0x2f20
leaq -0x80000000(%rax), %rcx
cmpq %r12, %rcx
jb 0x2f2c
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x2f2c
testl %ecx, %ecx
jne 0x2c3f
movl %ebp, (%r14)
movq 0x8(%rsp), %rbx
movl %eax, 0x28(%rbx)
movq 0x210(%rsp), %rdi
callq 0x2707
movq %rax, 0x38(%rbx)
movq 0x230(%rsp), %rdi
callq 0x2707
movq %rax, 0x40(%rbx)
movq 0x250(%rsp), %rdi
callq 0x2707
movq %rax, 0x48(%rbx)
movq 0x270(%rsp), %rbx
movl (%r14), %ebp
movl $0x0, (%r14)
leaq 0x2b0(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
movl $0xa, %edx
callq 0x2340
cmpq %rbx, (%r15)
je 0x2f38
leaq -0x80000000(%rax), %rcx
cmpq %r12, %rcx
jb 0x2f44
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x2f44
testl %ecx, %ecx
jne 0x2cd0
movl %ebp, (%r14)
movq 0x8(%rsp), %rcx
movl %eax, 0x2c(%rcx)
movq 0x290(%rsp), %rbx
movl (%r14), %ebp
movl $0x0, (%r14)
leaq 0x2b0(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
movl $0xa, %edx
callq 0x2340
cmpq %rbx, (%r15)
je 0x2f50
leaq -0x80000000(%rax), %rcx
cmpq %r12, %rcx
jb 0x2f5c
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x2f5c
testl %ecx, %ecx
jne 0x2d2e
movl %ebp, (%r14)
movq 0x8(%rsp), %r12
movl %eax, 0x30(%r12)
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
cmpl $0x0, 0x2c(%r12)
jle 0x2e4d
movq (%r12), %rsi
leaq 0x2b0(%rsp), %r15
movq %r15, %rdi
movl $0x8, %edx
callq 0x2410
xorl %r14d, %r14d
leaq 0x10(%rsp), %rbx
movq 0x2b0(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2230
movsbl %al, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2430
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2db7
incq %r14
jmp 0x2d7d
leaq 0x2b0(%rsp), %rdi
callq 0x2080
movslq 0x2c(%r12), %rax
imulq $0x34bc, %rax, %rcx     # imm = 0x34BC
addq $-0x22b8, %rcx          # imm = 0xDD48
movq %r14, %rax
xorl %edx, %edx
divq %rcx
movslq 0x30(%r12), %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %xmm0
punpckldq 0x321a(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x3222(%rip), %xmm0     # 0x6020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x321e(%rip), %xmm1     # 0x6030
addsd 0x321e(%rip), %xmm1     # 0x6038
cvttsd2si %xmm1, %eax
movl %eax, 0x24(%r12)
movl $0x1, 0x28(%r12)
leaq 0x2b0(%rsp), %rdi
callq 0x20b0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2e4d
callq 0x2220
leaq 0x4b8(%rsp), %rdi
callq 0x2090
leaq 0x2a0(%rsp), %rbx
xorl %r14d, %r14d
movq 0x290(%rsp,%r14), %rdi
leaq (%rbx,%r14), %rax
cmpq %rdi, %rax
je 0x2e7b
callq 0x2220
addq $-0x20, %r14
cmpq $-0x120, %r14           # imm = 0xFEE0
jne 0x2e65
leaq 0x180(%rsp), %rbx
xorl %r14d, %r14d
movq 0x170(%rsp,%r14), %rdi
leaq (%rbx,%r14), %rax
cmpq %rdi, %rax
je 0x2ea9
callq 0x2220
addq $-0x20, %r14
cmpq $-0x120, %r14           # imm = 0xFEE0
jne 0x2e93
addq $0x6c8, %rsp            # imm = 0x6C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3378(%rip), %rdi      # 0x6247
jmp 0x2ed8
leaq 0x338c(%rip), %rdi      # 0x6264
callq 0x2390
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22e0
leaq 0x333b(%rip), %rdi      # 0x6229
jmp 0x2ed8
leaq 0x3303(%rip), %rdi      # 0x61fa
callq 0x2140
leaq 0x32f7(%rip), %rdi      # 0x61fa
callq 0x2360
leaq 0x32eb(%rip), %rdi      # 0x61fa
callq 0x2140
leaq 0x32df(%rip), %rdi      # 0x61fa
callq 0x2360
leaq 0x32d3(%rip), %rdi      # 0x61fa
callq 0x2140
leaq 0x32c7(%rip), %rdi      # 0x61fa
callq 0x2360
leaq 0x32bb(%rip), %rdi      # 0x61fa
callq 0x2140
leaq 0x32af(%rip), %rdi      # 0x61fa
callq 0x2360
leaq 0x32a3(%rip), %rdi      # 0x61fa
callq 0x2140
leaq 0x3297(%rip), %rdi      # 0x61fa
callq 0x2360
jmp 0x2fef
jmp 0x2fea
movq %rax, %rbx
jmp 0x3025
movq %rax, %rbx
jmp 0x304c
jmp 0x2f8d
jmp 0x2f8d
jmp 0x2f8d
jmp 0x2f8d
jmp 0x2f8d
jmp 0x2f8d
jmp 0x2f8d
movq %rax, %rbx
addq $-0x10, %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x2fa2
callq 0x2220
leaq -0x20(%r15), %rax
addq $-0x10, %r15
cmpq %r14, %r15
movq %rax, %r15
jne 0x2f94
jmp 0x306b
jmp 0x2fbf
jmp 0x2fbf
jmp 0x2fbf
jmp 0x2fbf
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x3018
movl %ebp, (%r14)
jmp 0x3018
jmp 0x3015
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2fff
callq 0x2220
jmp 0x2fff
jmp 0x3015
movq %rax, %rbx
jmp 0x2fff
movq %rax, %rbx
leaq 0x2b0(%rsp), %rdi
callq 0x20b0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3018
callq 0x2220
jmp 0x3018
movq %rax, %rbx
leaq 0x4b8(%rsp), %rdi
callq 0x2090
movq $-0x120, %r14           # imm = 0xFEE0
leaq 0x2a0(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %rdi, %r15
je 0x3042
callq 0x2220
addq $-0x20, %r15
addq $0x20, %r14
jne 0x3034
movq $-0x120, %r14           # imm = 0xFEE0
movq -0x10(%r13), %rdi
cmpq %rdi, %r13
je 0x3061
callq 0x2220
addq $-0x20, %r13
addq $0x20, %r14
jne 0x3053
movq %rbx, %rdi
callq 0x23e0