// File: /workspace/github_cpp_makefile_star2_O1/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 0x3907(%rip), %rsi      # 0x60c0
leaq 0x390a(%rip), %rdx      # 0x60ca
leaq 0x70(%rsp), %r15
movq %r15, %rdi
callq 0x3c32
leaq 0x90(%rsp), %r14
leaq 0xa0(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x38e3(%rip), %rsi      # 0x60cb
leaq 0x38e6(%rip), %rdx      # 0x60d5
movq %r14, %rdi
callq 0x3c32
leaq 0xb0(%rsp), %r14
leaq 0xc0(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x38c4(%rip), %rsi      # 0x60d6
leaq 0x38c7(%rip), %rdx      # 0x60e0
movq %r14, %rdi
callq 0x3c32
leaq 0xd0(%rsp), %r14
leaq 0xe0(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x38a5(%rip), %rsi      # 0x60e1
leaq 0x38a8(%rip), %rdx      # 0x60eb
movq %r14, %rdi
callq 0x3c32
leaq 0xf0(%rsp), %r14
leaq 0x100(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3886(%rip), %rsi      # 0x60ec
leaq 0x3892(%rip), %rdx      # 0x60ff
movq %r14, %rdi
callq 0x3c32
leaq 0x110(%rsp), %r14
leaq 0x120(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3870(%rip), %rsi      # 0x6100
leaq 0x387a(%rip), %rdx      # 0x6111
movq %r14, %rdi
callq 0x3c32
leaq 0x130(%rsp), %r14
leaq 0x140(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3858(%rip), %rsi      # 0x6112
leaq 0x3862(%rip), %rdx      # 0x6123
movq %r14, %rdi
callq 0x3c32
leaq 0x150(%rsp), %r14
leaq 0x160(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3840(%rip), %rsi      # 0x6124
leaq 0x3847(%rip), %rdx      # 0x6132
movq %r14, %rdi
callq 0x3c32
leaq 0x170(%rsp), %r14
leaq 0x180(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x3825(%rip), %rsi      # 0x6133
leaq 0x382a(%rip), %rdx      # 0x613f
movq %r14, %rdi
callq 0x3c32
leaq 0x1a0(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x3c81(%rip), %rdx      # 0x65b1
leaq 0x190(%rsp), %rdi
movq %rdx, %rsi
callq 0x3c32
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 0x2945
leaq 0x4b8(%rsp), %rdi
callq 0x22c0
leaq 0x4b8(%rsp), %rdi
movq %r12, %rsi
movl $0x18, %edx
callq 0x21f0
movq %rbx, 0x8(%rsp)
leaq 0x538(%rsp), %rdi
callq 0x20a0
testb %al, %al
je 0x2ed7
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 0x2220
movsbl %al, %ecx
movl $0x80, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2430
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 0x3c32
movq %r12, %rdi
movl $0x3d, %esi
xorl %edx, %edx
callq 0x22f0
cmpq $-0x1, %rax
je 0x2ec1
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x2270
movq 0x78(%rsp,%r14), %rdx
cmpq 0x38(%rsp), %rdx
jne 0x2eb8
testq %rdx, %rdx
je 0x2a72
movq 0x30(%rsp), %rsi
movq 0x70(%rsp,%r14), %rdi
callq 0x2260
testl %eax, %eax
jne 0x2eb8
incq %rbx
movq %rbp, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq $-0x1, %rcx
callq 0x2270
leaq (%rsp,%r14), %rdi
addq $0x190, %rdi            # imm = 0x190
movq %rbp, %rsi
callq 0x22e0
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
leaq 0x4b8(%rsp), %rbx
je 0x2ab9
callq 0x2210
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2acd
callq 0x2210
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x2ae1
callq 0x2210
addq $0x20, %r14
cmpq $0x120, %r14            # imm = 0x120
jne 0x29c4
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 0x2330
cmpq %rbx, (%r15)
je 0x2ee0
movslq %eax, %rcx
cmpq %rax, %rcx
jne 0x2eec
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x2eec
testl %ecx, %ecx
jne 0x2b69
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 0x2330
cmpq %rbx, (%r15)
je 0x2ef8
movabsq $-0x100000000, %r12     # imm = 0xFFFFFFFF00000000
leaq -0x80000000(%rax), %rcx
cmpq %r12, %rcx
jb 0x2f04
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x2f04
testl %ecx, %ecx
jne 0x2bd1
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 0x2330
cmpq %rbx, (%r15)
je 0x2f10
leaq -0x80000000(%rax), %rcx
cmpq %r12, %rcx
jb 0x2f1c
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x2f1c
testl %ecx, %ecx
jne 0x2c2f
movl %ebp, (%r14)
movq 0x8(%rsp), %rbx
movl %eax, 0x28(%rbx)
movq 0x210(%rsp), %rdi
callq 0x26f7
movq %rax, 0x38(%rbx)
movq 0x230(%rsp), %rdi
callq 0x26f7
movq %rax, 0x40(%rbx)
movq 0x250(%rsp), %rdi
callq 0x26f7
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 0x2330
cmpq %rbx, (%r15)
je 0x2f28
leaq -0x80000000(%rax), %rcx
cmpq %r12, %rcx
jb 0x2f34
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x2f34
testl %ecx, %ecx
jne 0x2cc0
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 0x2330
cmpq %rbx, (%r15)
je 0x2f40
leaq -0x80000000(%rax), %rcx
cmpq %r12, %rcx
jb 0x2f4c
movl (%r14), %ecx
cmpl $0x22, %ecx
je 0x2f4c
testl %ecx, %ecx
jne 0x2d1e
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 0x2e29
movq (%r12), %rsi
leaq 0x2b0(%rsp), %r15
movq %r15, %rdi
movl $0x8, %edx
callq 0x2400
xorl %r14d, %r14d
leaq 0x10(%rsp), %rbx
movq 0x2b0(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2220
movsbl %al, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2420
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2da7
incq %r14
jmp 0x2d6d
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 0x322a(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x3232(%rip), %xmm0     # 0x6020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x322e(%rip), %xmm1     # 0x6030
addsd 0x322e(%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 0x2e3d
callq 0x2210
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 0x2e6b
callq 0x2210
addq $-0x20, %r14
cmpq $-0x120, %r14           # imm = 0xFEE0
jne 0x2e55
leaq 0x180(%rsp), %rbx
xorl %r14d, %r14d
movq 0x170(%rsp,%r14), %rdi
leaq (%rbx,%r14), %rax
cmpq %rdi, %rax
je 0x2e99
callq 0x2210
addq $-0x20, %r14
cmpq $-0x120, %r14           # imm = 0xFEE0
jne 0x2e83
addq $0x6c8, %rsp            # imm = 0x6C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3388(%rip), %rdi      # 0x6247
jmp 0x2ec8
leaq 0x339c(%rip), %rdi      # 0x6264
callq 0x2380
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x22d0
leaq 0x334b(%rip), %rdi      # 0x6229
jmp 0x2ec8
leaq 0x3313(%rip), %rdi      # 0x61fa
callq 0x2140
leaq 0x3307(%rip), %rdi      # 0x61fa
callq 0x2350
leaq 0x32fb(%rip), %rdi      # 0x61fa
callq 0x2140
leaq 0x32ef(%rip), %rdi      # 0x61fa
callq 0x2350
leaq 0x32e3(%rip), %rdi      # 0x61fa
callq 0x2140
leaq 0x32d7(%rip), %rdi      # 0x61fa
callq 0x2350
leaq 0x32cb(%rip), %rdi      # 0x61fa
callq 0x2140
leaq 0x32bf(%rip), %rdi      # 0x61fa
callq 0x2350
leaq 0x32b3(%rip), %rdi      # 0x61fa
callq 0x2140
leaq 0x32a7(%rip), %rdi      # 0x61fa
callq 0x2350
jmp 0x2ff8
jmp 0x2ff3
movq %rax, %rbx
jmp 0x302e
movq %rax, %rbx
jmp 0x3055
jmp 0x2f80
jmp 0x2f80
jmp 0x2f80
jmp 0x2f80
jmp 0x2f80
jmp 0x2f80
jmp 0x2f80
movq %rax, %rbx
cmpq %r14, %r15
je 0x3074
addq $-0x10, %r14
leaq 0x70(%rsp), %r15
movq -0x10(%r14), %rdi
cmpq %rdi, %r14
je 0x2fa3
callq 0x2210
leaq -0x20(%r14), %rax
addq $-0x10, %r14
cmpq %r15, %r14
movq %rax, %r14
jne 0x2f95
jmp 0x3074
movq %rax, %rbx
movq %r15, %r14
jmp 0x2f83
jmp 0x2fc8
jmp 0x2fc8
jmp 0x2fc8
jmp 0x2fc8
movq %rax, %rbx
cmpl $0x0, (%r14)
jne 0x3021
movl %ebp, (%r14)
jmp 0x3021
jmp 0x301e
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x3008
callq 0x2210
jmp 0x3008
jmp 0x301e
movq %rax, %rbx
jmp 0x3008
movq %rax, %rbx
leaq 0x2b0(%rsp), %rdi
callq 0x20b0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3021
callq 0x2210
jmp 0x3021
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 0x304b
callq 0x2210
addq $-0x20, %r15
addq $0x20, %r14
jne 0x303d
movq $-0x120, %r14           # imm = 0xFEE0
movq -0x10(%r13), %rdi
cmpq %rdi, %r13
je 0x306a
callq 0x2210
addq $-0x20, %r13
addq $0x20, %r14
jne 0x305c
movq %rbx, %rdi
callq 0x23d0