// File: 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
movq %rsp, %rbp
subq $0x950, %rsp            # imm = 0x950
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x1, -0x155(%rbp)
leaq -0x130(%rbp), %rax
movq %rax, -0x7d0(%rbp)
movq %rax, -0x138(%rbp)
leaq -0x139(%rbp), %rdi
movq %rdi, -0x7c8(%rbp)
callq 0x3470
movq -0x7d0(%rbp), %rdi
movq -0x7c8(%rbp), %rdx
leaq 0x87d1(%rip), %rsi      # 0xc078
callq 0x3390
jmp 0x38ae
leaq -0x110(%rbp), %rax
movq %rax, -0x7e0(%rbp)
movq %rax, -0x138(%rbp)
leaq -0x14d(%rbp), %rdi
movq %rdi, -0x7d8(%rbp)
callq 0x3470
movq -0x7e0(%rbp), %rdi
movq -0x7d8(%rbp), %rdx
leaq 0x8798(%rip), %rsi      # 0xc083
callq 0x3390
jmp 0x38f2
leaq -0xf0(%rbp), %rax
movq %rax, -0x7f0(%rbp)
movq %rax, -0x138(%rbp)
leaq -0x14e(%rbp), %rdi
movq %rdi, -0x7e8(%rbp)
callq 0x3470
movq -0x7f0(%rbp), %rdi
movq -0x7e8(%rbp), %rdx
leaq 0x875f(%rip), %rsi      # 0xc08e
callq 0x3390
jmp 0x3936
leaq -0xd0(%rbp), %rax
movq %rax, -0x800(%rbp)
movq %rax, -0x138(%rbp)
leaq -0x14f(%rbp), %rdi
movq %rdi, -0x7f8(%rbp)
callq 0x3470
movq -0x800(%rbp), %rdi
movq -0x7f8(%rbp), %rdx
leaq 0x8726(%rip), %rsi      # 0xc099
callq 0x3390
jmp 0x397a
leaq -0xb0(%rbp), %rax
movq %rax, -0x810(%rbp)
movq %rax, -0x138(%rbp)
leaq -0x150(%rbp), %rdi
movq %rdi, -0x808(%rbp)
callq 0x3470
movq -0x810(%rbp), %rdi
movq -0x808(%rbp), %rdx
leaq 0x86ed(%rip), %rsi      # 0xc0a4
callq 0x3390
jmp 0x39be
leaq -0x90(%rbp), %rax
movq %rax, -0x820(%rbp)
movq %rax, -0x138(%rbp)
leaq -0x151(%rbp), %rdi
movq %rdi, -0x818(%rbp)
callq 0x3470
movq -0x820(%rbp), %rdi
movq -0x818(%rbp), %rdx
leaq 0x86bd(%rip), %rsi      # 0xc0b8
callq 0x3390
jmp 0x3a02
leaq -0x70(%rbp), %rax
movq %rax, -0x830(%rbp)
movq %rax, -0x138(%rbp)
leaq -0x152(%rbp), %rdi
movq %rdi, -0x828(%rbp)
callq 0x3470
movq -0x830(%rbp), %rdi
movq -0x828(%rbp), %rdx
leaq 0x868e(%rip), %rsi      # 0xc0ca
callq 0x3390
jmp 0x3a43
leaq -0x50(%rbp), %rax
movq %rax, -0x840(%rbp)
movq %rax, -0x138(%rbp)
leaq -0x153(%rbp), %rdi
movq %rdi, -0x838(%rbp)
callq 0x3470
movq -0x840(%rbp), %rdi
movq -0x838(%rbp), %rdx
leaq 0x865f(%rip), %rsi      # 0xc0dc
callq 0x3390
jmp 0x3a84
leaq -0x30(%rbp), %rax
movq %rax, -0x850(%rbp)
movq %rax, -0x138(%rbp)
leaq -0x154(%rbp), %rdi
movq %rdi, -0x848(%rbp)
callq 0x3470
movq -0x850(%rbp), %rdi
movq -0x848(%rbp), %rdx
leaq 0x862d(%rip), %rsi      # 0xc0eb
callq 0x3390
jmp 0x3ac5
movb $0x0, -0x155(%rbp)
leaq -0x154(%rbp), %rdi
callq 0x32e0
leaq -0x153(%rbp), %rdi
callq 0x32e0
leaq -0x152(%rbp), %rdi
callq 0x32e0
leaq -0x151(%rbp), %rdi
callq 0x32e0
leaq -0x150(%rbp), %rdi
callq 0x32e0
leaq -0x14f(%rbp), %rdi
callq 0x32e0
leaq -0x14e(%rbp), %rdi
callq 0x32e0
leaq -0x14d(%rbp), %rdi
callq 0x32e0
leaq -0x139(%rbp), %rdi
callq 0x32e0
movb $0x1, -0x28a(%rbp)
leaq -0x280(%rbp), %rax
movq %rax, -0x860(%rbp)
movq %rax, -0x288(%rbp)
leaq -0x289(%rbp), %rdi
movq %rdi, -0x858(%rbp)
callq 0x3470
movq -0x860(%rbp), %rdi
movq -0x858(%rbp), %rdx
leaq 0x859a(%rip), %rsi      # 0xc116
callq 0x3390
jmp 0x3b83
leaq -0x280(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x288(%rbp)
leaq -0x280(%rbp), %rcx
addq $0x120, %rcx            # imm = 0x120
movq %rcx, -0x870(%rbp)
movq %rax, -0x868(%rbp)
movq -0x868(%rbp), %rdi
movq %rdi, -0x878(%rbp)
callq 0x33a0
movq -0x878(%rbp), %rax
movq -0x870(%rbp), %rcx
addq $0x20, %rax
movq %rax, -0x288(%rbp)
cmpq %rcx, %rax
movq %rax, -0x868(%rbp)
jne 0x3bb1
movb $0x0, -0x28a(%rbp)
leaq -0x289(%rbp), %rdi
callq 0x32e0
movl $0x0, -0x290(%rbp)
leaq -0x4a0(%rbp), %rdi
callq 0x3310
jmp 0x3c14
movq -0x8(%rbp), %rax
movq %rax, -0x888(%rbp)
movl $0x8, %edi
movl $0x10, %esi
callq 0x53b0
movl %eax, -0x87c(%rbp)
jmp 0x3c36
movl -0x87c(%rbp), %edx
movq -0x888(%rbp), %rsi
leaq -0x4a0(%rbp), %rdi
callq 0x3260
jmp 0x3c51
leaq -0x4a0(%rbp), %rdi
callq 0x3450
movb %al, -0x889(%rbp)
jmp 0x3c65
movb -0x889(%rbp), %al
testb $0x1, %al
jne 0x3ebf
jmp 0x3c75
leaq 0x847c(%rip), %rdi      # 0xc0f8
xorl %eax, %eax
callq 0x3050
jmp 0x3c85
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3320
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x3dad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x3da1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x3d95
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x3d89
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x3d7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x3d71
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x3d65
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x3d59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x154(%rbp), %rdi
callq 0x32e0
leaq -0x153(%rbp), %rdi
callq 0x32e0
leaq -0x152(%rbp), %rdi
callq 0x32e0
leaq -0x151(%rbp), %rdi
callq 0x32e0
leaq -0x150(%rbp), %rdi
callq 0x32e0
leaq -0x14f(%rbp), %rdi
callq 0x32e0
leaq -0x14e(%rbp), %rdi
callq 0x32e0
leaq -0x14d(%rbp), %rdi
callq 0x32e0
leaq -0x139(%rbp), %rdi
callq 0x32e0
testb $0x1, -0x155(%rbp)
jne 0x3dc4
jmp 0x3e11
movq -0x138(%rbp), %rax
leaq -0x130(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x898(%rbp)
je 0x3e0f
movq -0x898(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x8a0(%rbp)
callq 0x31b0
movq -0x8a0(%rbp), %rax
leaq -0x130(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x898(%rbp)
jne 0x3dde
jmp 0x3e11
jmp 0x44ea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x289(%rbp), %rdi
callq 0x32e0
testb $0x1, -0x28a(%rbp)
jne 0x3e3f
jmp 0x3e8c
movq -0x288(%rbp), %rax
leaq -0x280(%rbp), %rcx
cmpq %rax, %rcx
movq %rax, -0x8a8(%rbp)
je 0x3e8a
movq -0x8a8(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x8b0(%rbp)
callq 0x31b0
movq -0x8b0(%rbp), %rax
leaq -0x280(%rbp), %rcx
cmpq %rcx, %rax
movq %rax, -0x8a8(%rbp)
jne 0x3e59
jmp 0x3e8c
jmp 0x449c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x444e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x4442
jmp 0x3ec1
cmpl $0x9, -0x290(%rbp)
jge 0x40ae
leaq -0x4a0(%rbp), %rdi
leaq -0x520(%rbp), %rsi
movl $0x80, %edx
callq 0x30f0
jmp 0x3ee8
leaq -0x541(%rbp), %rdi
movq %rdi, -0x8b8(%rbp)
callq 0x3470
movq -0x8b8(%rbp), %rdx
leaq -0x540(%rbp), %rdi
leaq -0x520(%rbp), %rsi
callq 0x3390
jmp 0x3f17
leaq -0x541(%rbp), %rdi
callq 0x32e0
leaq -0x540(%rbp), %rdi
movl $0x3d, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3360
movq %rax, -0x550(%rbp)
cmpq $-0x1, -0x550(%rbp)
jne 0x3f9d
leaq 0x81c7(%rip), %rdi      # 0xc117
xorl %eax, %eax
callq 0x3050
jmp 0x3f59
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3320
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x541(%rbp), %rdi
callq 0x32e0
jmp 0x4442
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x409d
movq -0x550(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x570(%rbp), %rdi
leaq -0x540(%rbp), %rsi
callq 0x32d0
jmp 0x3fbd
movslq -0x290(%rbp), %rax
leaq -0x130(%rbp), %rdi
shlq $0x5, %rax
addq %rax, %rdi
leaq -0x570(%rbp), %rsi
callq 0x53d0
testb $0x1, %al
jne 0x3fe4
jmp 0x401e
leaq 0x814d(%rip), %rdi      # 0xc138
xorl %eax, %eax
callq 0x3050
jmp 0x3ff4
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3320
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x570(%rbp), %rdi
callq 0x31b0
jmp 0x409d
movq -0x550(%rbp), %rdx
incq %rdx
leaq -0x590(%rbp), %rdi
leaq -0x540(%rbp), %rsi
movq $-0x1, %rcx
callq 0x32d0
jmp 0x4044
movslq -0x290(%rbp), %rax
leaq -0x280(%rbp), %rdi
shlq $0x5, %rax
addq %rax, %rdi
leaq -0x590(%rbp), %rsi
callq 0x3330
leaq -0x590(%rbp), %rdi
callq 0x31b0
movl -0x290(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x290(%rbp)
leaq -0x570(%rbp), %rdi
callq 0x31b0
leaq -0x540(%rbp), %rdi
callq 0x31b0
jmp 0x3ec1
leaq -0x540(%rbp), %rdi
callq 0x31b0
jmp 0x4442
leaq -0x4a0(%rbp), %rdi
callq 0x3060
jmp 0x40bc
movq -0x10(%rbp), %rdi
leaq -0x280(%rbp), %rsi
callq 0x3030
jmp 0x40ce
leaq -0x260(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x5400
movl %eax, -0x8bc(%rbp)
jmp 0x40eb
movl -0x8bc(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x20(%rax)
leaq -0x240(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x5400
movl %eax, -0x8c0(%rbp)
jmp 0x4115
movl -0x8c0(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
leaq -0x220(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x5400
movl %eax, -0x8c4(%rbp)
jmp 0x413f
movl -0x8c4(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
leaq -0x200(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
callq 0x37c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x38(%rax)
leaq -0x1e0(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
callq 0x37c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
leaq -0x1c0(%rbp), %rdi
callq 0x3130
movq %rax, %rdi
callq 0x37c0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
leaq -0x1a0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x5400
movl %eax, -0x8c8(%rbp)
jmp 0x41c6
movl -0x8c8(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x2c(%rax)
leaq -0x180(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0xa, %edx
callq 0x5400
movl %eax, -0x8cc(%rbp)
jmp 0x41f0
movl -0x8cc(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
movq $0x0, -0x598(%rbp)
leaq -0x5b8(%rbp), %rdi
callq 0x33a0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
jle 0x437d
movq -0x10(%rbp), %rdi
callq 0x3130
movq %rax, %rsi
leaq -0x7c0(%rbp), %rdi
movl $0x8, %edx
callq 0x3490
jmp 0x4241
jmp 0x4243
leaq -0x7c0(%rbp), %rdi
leaq -0x5b8(%rbp), %rsi
callq 0x3080
movq %rax, -0x8d8(%rbp)
jmp 0x425f
movq -0x8d8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3340
movb %al, -0x8d9(%rbp)
jmp 0x427d
movb -0x8d9(%rbp), %al
testb $0x1, %al
jne 0x4289
jmp 0x42d7
movq -0x598(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x598(%rbp)
jmp 0x4243
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
jmp 0x4436
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x7c0(%rbp), %rdi
callq 0x30d0
jmp 0x4436
leaq -0x7c0(%rbp), %rdi
callq 0x30a0
jmp 0x42e5
movq -0x598(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x2c(%rcx), %edx
imull $0x34bc, %edx, %edx     # imm = 0x34BC
addl $0xffffdd48, %edx       # imm = 0xFFFFDD48
movslq %edx, %rsi
xorl %edx, %edx
movq %rdx, -0x8e8(%rbp)
divq %rsi
movq -0x8e8(%rbp), %rdx
movslq 0x30(%rcx), %rcx
divq %rcx
movq %rax, %xmm0
movaps 0x7cf8(%rip), %xmm1     # 0xc020
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x7cfc(%rip), %xmm1     # 0xc030
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x7cbd(%rip), %xmm1     # 0xc008
mulsd %xmm1, %xmm0
movsd 0x7cb9(%rip), %xmm1     # 0xc010
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x28(%rax)
leaq -0x7c0(%rbp), %rdi
callq 0x30d0
leaq -0x5b8(%rbp), %rdi
callq 0x31b0
leaq -0x4a0(%rbp), %rdi
callq 0x30b0
leaq -0x280(%rbp), %rax
movq %rax, -0x8f8(%rbp)
addq $0x120, %rax            # imm = 0x120
movq %rax, -0x8f0(%rbp)
movq -0x8f0(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x900(%rbp)
callq 0x31b0
movq -0x8f8(%rbp), %rcx
movq -0x900(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x8f0(%rbp)
jne 0x43b0
leaq -0x130(%rbp), %rax
movq %rax, -0x910(%rbp)
addq $0x120, %rax            # imm = 0x120
movq %rax, -0x908(%rbp)
movq -0x908(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x918(%rbp)
callq 0x31b0
movq -0x910(%rbp), %rcx
movq -0x918(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x908(%rbp)
jne 0x43fc
addq $0x950, %rsp            # imm = 0x950
popq %rbp
retq
leaq -0x5b8(%rbp), %rdi
callq 0x31b0
leaq -0x4a0(%rbp), %rdi
callq 0x30b0
leaq -0x280(%rbp), %rax
movq %rax, -0x928(%rbp)
addq $0x120, %rax            # imm = 0x120
movq %rax, -0x920(%rbp)
movq -0x920(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x930(%rbp)
callq 0x31b0
movq -0x928(%rbp), %rcx
movq -0x930(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x920(%rbp)
jne 0x4469
jmp 0x449c
leaq -0x130(%rbp), %rax
movq %rax, -0x940(%rbp)
addq $0x120, %rax            # imm = 0x120
movq %rax, -0x938(%rbp)
movq -0x938(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x948(%rbp)
callq 0x31b0
movq -0x940(%rbp), %rcx
movq -0x948(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x938(%rbp)
jne 0x44b7
jmp 0x44ea
movq -0x148(%rbp), %rdi
callq 0x3460
nopw %cs:(%rax,%rax)