// File: /workspace/github_cpp_makefile_star2_O1/dudulu233[P]EMA-Tool/cache_stat.cpp
// Function: StatCache::main_operation(_IoRecord*, bool, int, int, int)
void StatCache::main_operation(IoRecord* ir, bool get_reuse_dis, int cache_size, int sp, int st)
{
	struct SeqNum* sn_new = NULL;
	struct SeqNum* sn_old = NULL;
	if (is_new_day(ir))

	{
		sn_new = (struct SeqNum*)malloc(sizeof(struct SeqNum));
		sn_new->start_total_seq = total_seq;
		sn_new->re_seq = 0;
		sn_new->start_time = ir->alloc_time;
		sn_new->a = (double*)malloc(2 * sizeof(double));
		sn_new->b = (double*)malloc(2 * sizeof(double));
		sn_new->re_retio = (double*)malloc(3 * sizeof(double));
		sn_new->a[0] = sn_new->a[1] = sn_new->b[0] = sn_new->b[1] =
			sn_new->re_retio[0] = sn_new->re_retio[1] = sn_new->re_retio[2] = 0.0;

		seq_map[current_day] = sn_new;

		if (current_day - get_time_day(start_time) > 1) {
			//plot RAR curve of 2 days ago
			struct SeqNum* sn_tmp = seq_map[current_day - 2];
			assert(sn_tmp);
			plot_rar_curve(sn_tmp);
		}
	}
	else
	{
		sn_new = seq_map[current_day];
	}
	if (current_day - get_time_day(start_time) > 0)
	{
		sn_old = seq_map[current_day - 1];
		assert(sn_old);
	}
	assert(sn_new);

	if (is_new_hour(ir)) {
		if (current_hour - get_time_hour(sn_new->start_time) == 1) {
			assert(total_seq - sn_new->start_total_seq != 0);
			sn_new->re_retio[0] = (double)(sn_new->re_seq) / (total_seq - sn_new->start_total_seq);
		}
		if (current_hour - get_time_hour(sn_new->start_time) == 20) {
			assert(total_seq - sn_new->start_total_seq != 0);
			sn_new->re_retio[1] = (double)(sn_new->re_seq) / (total_seq - sn_new->start_total_seq);
		}
		if (NULL != sn_old) {
			if (current_hour - get_time_hour(sn_old->start_time) == 47) {
				assert(total_seq - sn_old->start_total_seq != 0);
				sn_old->re_retio[2] = (double)(sn_old->re_seq) / (total_seq - sn_old->start_total_seq);
			}
		}
	}

	total_seq++;

	auto it = stat_map.find(ir->cache_addr);
	struct BlockStat* bs;
	int reuse_dis = -1;

	if (it == stat_map.end())
	{
		bs = (struct BlockStat*)malloc(sizeof(struct BlockStat));
		bs->last_time = ir->alloc_time;
		bs->last_total_seq = total_seq;
		stat_map[ir->cache_addr] = bs;
		++map_size;
		reuse_dis = 1023;
	}
	else
	{
		bs = it->second;
		re_seq++;
		if (current_day == get_time_day(bs->last_time)) {
			sn_new->re_seq++;
		}
		if ((current_day - get_time_day(bs->last_time) <= 1) && (NULL != sn_old)) {
			sn_old->re_seq++;
		}
		long x = (ir->alloc_time - bs->last_time);
		double re_ratio = get_reuse_curve(x, ir->alloc_time);
		double reuse_tmp = (total_seq - bs->last_total_seq) *
			(1 - re_ratio);
		reuse_dis = (int)(reuse_tmp * sp * cache_size / st / 1024 / 1024);
		if (reuse_dis >= 1024)
		{
			reuse_dis = 1023;
		}
		if (reuse_dis <= 0)
		{
			reuse_dis = 0;
		}
		bs->last_time = ir->alloc_time;
		bs->last_total_seq = total_seq;
	}
	if (get_reuse_dis) {
		reuse_dis_array[reuse_dis]++;
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, 0x24(%rsp)
movl %r8d, 0x1c(%rsp)
movl %ecx, 0x20(%rsp)
movl %edx, %r13d
movq %rsi, %rbp
movq %rdi, %rbx
movq (%rsi), %rcx
leaq 0x7080(%rcx), %rax
movabsq $0x1845c8a0ce512957, %r14 # imm = 0x1845C8A0CE512957
imulq %r14
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xd, %rdx
addq %rax, %rdx
leaq 0x20(%rdi), %r12
movq 0x20(%rdi), %rax
cmpq %rax, %rdx
jle 0x3eaf
movq %rdx, (%r12)
jmp 0x3eb8
jge 0x3eb8
incq %rcx
movq %rcx, (%rbp)
cmpq %rax, %rdx
movl %r13d, 0xc(%rsp)
movq %rbp, 0x10(%rsp)
jle 0x4036
movl $0x30, %edi
callq 0x2310
movq %rax, %r15
movq (%rbx), %rax
movq %rax, 0x20(%r15)
xorl %r14d, %r14d
movq %r14, 0x28(%r15)
movq (%rbp), %rax
movq %rax, 0x18(%r15)
movl $0x10, %edi
callq 0x2310
movq %rax, %rbp
movq %rax, (%r15)
movl $0x10, %edi
callq 0x2310
movq %rax, %r13
movq %rax, 0x8(%r15)
movl $0x18, %edi
callq 0x2310
movq %rax, 0x10(%r15)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq %r14, 0x10(%rax)
movupd %xmm0, (%r13)
leaq 0x2068(%rbx), %r13
movupd %xmm0, (%rbp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x48e8
movq %r15, (%rax)
movl $0x7080, %eax           # imm = 0x7080
addq 0x28(%rbx), %rax
movabsq $-0x1845c8a0ce512957, %rcx # imm = 0xE7BA375F31AED6A9
imulq %rcx
movq 0x20(%rbx), %rax
movq %rdx, %rcx
shrq $0x3f, %rcx
sarq $0xd, %rdx
addq %rcx, %rdx
addq %rax, %rdx
cmpq $0x2, %rdx
jl 0x4025
addq $-0x2, %rax
leaq 0x30(%rsp), %rsi
movq %rax, (%rsi)
movq %r13, %rdi
callq 0x4bbe
movq (%rax), %rax
testq %rax, %rax
je 0x441e
movq (%rax), %rcx
movq 0x10(%rax), %rdx
movsd (%rdx), %xmm1
movsd 0x8(%rdx), %xmm0
movsd 0x10(%rdx), %xmm2
movapd %xmm1, %xmm3
subsd %xmm0, %xmm3
movsd 0x23bd(%rip), %xmm4     # 0x6380
divsd %xmm4, %xmm3
movsd %xmm3, (%rcx)
movapd %xmm2, %xmm3
subsd %xmm0, %xmm3
movsd 0x23ad(%rip), %xmm5     # 0x6388
divsd %xmm5, %xmm3
movsd %xmm3, 0x8(%rcx)
movsd 0x23a4(%rip), %xmm3     # 0x6390
mulsd %xmm3, %xmm1
movsd 0x23a0(%rip), %xmm6     # 0x6398
mulsd %xmm0, %xmm6
addsd %xmm1, %xmm6
divsd %xmm4, %xmm6
movq 0x8(%rax), %rax
movsd %xmm6, (%rax)
mulsd 0x238c(%rip), %xmm0     # 0x63a0
mulsd %xmm3, %xmm2
addsd %xmm2, %xmm0
divsd %xmm5, %xmm0
movsd %xmm0, 0x8(%rax)
movq 0x10(%rsp), %rbp
movabsq $0x1845c8a0ce512957, %r14 # imm = 0x1845C8A0CE512957
jmp 0x4048
leaq 0x2068(%rbx), %rdi
movq %r12, %rsi
callq 0x48e8
movq (%rax), %r15
movq 0x20(%rbx), %rcx
movl $0x7080, %eax           # imm = 0x7080
addq 0x28(%rbx), %rax
imulq %r14
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xd, %rdx
addq %rax, %rdx
cmpq %rdx, %rcx
jle 0x40a9
leaq 0x2068(%rbx), %rdi
decq %rcx
leaq 0x30(%rsp), %rsi
movq %rcx, (%rsi)
callq 0x4bbe
movq (%rax), %rsi
testq %rsi, %rsi
jne 0x40ab
leaq 0x23bc(%rip), %rdi      # 0x644d
leaq 0x2344(%rip), %rsi      # 0x63dc
leaq 0x236e(%rip), %rcx      # 0x640d
movl $0x3c, %edx
callq 0x2150
xorl %esi, %esi
testq %r15, %r15
je 0x43ff
movq (%rbp), %rcx
movabsq $0x48d159e26af37c05, %rdx # imm = 0x48D159E26AF37C05
movq %rcx, %rax
imulq %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xa, %rdx
addq %rax, %rdx
movq 0x18(%rbx), %rax
cmpq %rax, %rdx
jle 0x40e5
movq %rdx, 0x18(%rbx)
jmp 0x40ee
jge 0x40ee
incq %rcx
movq %rcx, (%rbp)
cmpq %rax, %rdx
jle 0x4270
movabsq $-0x48d159e26af37c05, %rax # imm = 0xB72EA61D950C83FB
imulq 0x18(%r15)
movq 0x18(%rbx), %rcx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xa, %rdx
addq %rax, %rdx
addq %rcx, %rdx
cmpq $0x14, %rdx
je 0x418b
cmpq $0x1, %rdx
jne 0x41e7
movq (%rbx), %rax
subq 0x20(%r15), %rax
je 0x445c
movsd 0x28(%r15), %xmm0
movsd 0x1ecb(%rip), %xmm1     # 0x6010
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x1ed0(%rip), %xmm2     # 0x6020
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq %rax, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd %xmm1, %xmm3
movq 0x10(%r15), %rax
movsd %xmm3, (%rax)
cmpq $0x14, %rdx
jne 0x41e7
movq (%rbx), %rax
subq 0x20(%r15), %rax
je 0x443d
movsd 0x28(%r15), %xmm0
movsd 0x1e6a(%rip), %xmm1     # 0x6010
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x1e6f(%rip), %xmm2     # 0x6020
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq %rax, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd %xmm1, %xmm3
movq 0x10(%r15), %rax
movsd %xmm3, 0x8(%rax)
testq %rsi, %rsi
je 0x4270
movabsq $-0x48d159e26af37c05, %rax # imm = 0xB72EA61D950C83FB
imulq 0x18(%rsi)
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xa, %rdx
addq %rax, %rdx
addq %rcx, %rdx
cmpq $0x2f, %rdx
jne 0x4270
movq (%rbx), %rax
subq 0x20(%rsi), %rax
je 0x447b
movsd 0x28(%rsi), %xmm0
movsd 0x1de1(%rip), %xmm1     # 0x6010
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x1de6(%rip), %xmm2     # 0x6020
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq %rax, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd %xmm1, %xmm3
movq 0x10(%rsi), %rax
movsd %xmm3, 0x10(%rax)
movq %r15, 0x28(%rsp)
movq %rsi, %r15
incq (%rbx)
leaq 0x2030(%rbx), %r12
leaq 0x8(%rbp), %r13
movq 0x8(%rbp), %rcx
xorl %ebp, %ebp
movq %rcx, %rax
xorl %edx, %edx
divq 0x2038(%rbx)
movq %r12, %rdi
movq %rdx, %rsi
movq %r13, %rdx
callq 0x4c5e
testq %rax, %rax
je 0x42ae
movq (%rax), %rbp
testq %rbp, %rbp
je 0x43ac
movq 0x10(%rbp), %r12
incq 0x8(%rbx)
movq 0x20(%rbx), %rsi
movq (%r12), %rcx
leaq 0x7080(%rcx), %rax
imulq %r14
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0xd, %rdx
addq %rax, %rdx
subq %rdx, %rsi
jne 0x42ed
movq 0x28(%rsp), %rax
incq 0x28(%rax)
testq %r15, %r15
movq 0x10(%rsp), %r14
movl 0xc(%rsp), %ebp
je 0x4305
cmpq $0x1, %rsi
jg 0x4305
incq 0x28(%r15)
movq (%r14), %rdx
movq %rdx, %rsi
subq %rcx, %rsi
movq %rbx, %rdi
callq 0x45ea
movq (%rbx), %rax
movq %rax, %rcx
subq 0x8(%r12), %rcx
movq %rcx, %xmm1
punpckldq 0x1ce2(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1cea(%rip), %xmm1     # 0x6020
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
movsd 0x205e(%rip), %xmm1     # 0x63a8
subsd %xmm0, %xmm1
mulsd %xmm2, %xmm1
xorps %xmm0, %xmm0
cvtsi2sdl 0x1c(%rsp), %xmm0
mulsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0x20(%rsp), %xmm1
mulsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sdl 0x24(%rsp), %xmm0
divsd %xmm0, %xmm1
movsd 0x202f(%rip), %xmm0     # 0x63b0
mulsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %ecx
movl $0x3ff, %edx            # imm = 0x3FF
cmpl %edx, %ecx
cmovll %ecx, %edx
xorl %ecx, %ecx
testl %edx, %edx
cmovgl %edx, %ecx
movq (%r14), %rdx
movq %rdx, (%r12)
movq %rax, 0x8(%r12)
jmp 0x43e6
movl $0x10, %edi
callq 0x2310
movq %rax, %r15
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, (%r15)
movq (%rbx), %rax
movq %rax, 0x8(%r15)
movq %r12, %rdi
movq %r13, %rsi
callq 0x4ca6
movq %r15, (%rax)
incq 0x10(%rbx)
movl $0x3ff, %ecx            # imm = 0x3FF
movl 0xc(%rsp), %ebp
testb %bpl, %bpl
je 0x43f0
incq 0x30(%rbx,%rcx,8)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x204e(%rip), %rdi      # 0x6454
leaq 0x1fcf(%rip), %rsi      # 0x63dc
leaq 0x1ff9(%rip), %rcx      # 0x640d
movl $0x3e, %edx
callq 0x2150
leaq 0x1fe1(%rip), %rdi      # 0x6406
leaq 0x1fb0(%rip), %rsi      # 0x63dc
leaq 0x1fda(%rip), %rcx      # 0x640d
movl $0x31, %edx
callq 0x2150
leaq 0x2017(%rip), %rdi      # 0x645b
leaq 0x1f91(%rip), %rsi      # 0x63dc
leaq 0x1fbb(%rip), %rcx      # 0x640d
movl $0x46, %edx
callq 0x2150
leaq 0x1ff8(%rip), %rdi      # 0x645b
leaq 0x1f72(%rip), %rsi      # 0x63dc
leaq 0x1f9c(%rip), %rcx      # 0x640d
movl $0x42, %edx
callq 0x2150
leaq 0x2002(%rip), %rdi      # 0x6484
leaq 0x1f53(%rip), %rsi      # 0x63dc
leaq 0x1f7d(%rip), %rcx      # 0x640d
movl $0x4b, %edx
callq 0x2150