// File: CMU-SAFARI[P]MQSim/src/utils/Helper_Functions.cpp
// Function: Utils::Euler_estimation(std::vector<double, std::allocator<double>>&, unsigned int, double, int, double, double, int)
void Euler_estimation(std::vector<double>& mu, unsigned int b, double rho, int d, double h, double max_diff, int itr_max)
	{
		std::vector<double> w_0, w;
		for (int i = 0; i <= mu.size(); i++) {
			if (i == 0) {
				w_0.push_back(1);
				w.push_back(1);
			} else {
				w_0.push_back(0);
				w.push_back(0);
				for (int j = i; j < mu.size(); j++)
					w_0[i] += mu[j];
			}
		}

		double t = h;
		int itr = 0;
		double diff = 100000000000000;
		while (itr < itr_max && diff > max_diff) {
			double sigma = 0;
			for (unsigned int j = 1; j <= b; j++) {
				sigma += std::pow(w_0[j], d);
			}

			for (unsigned int i = 1; i < b; i++) {
				w[i] = w_0[i] + h * (1 - std::pow(w_0[i], d) - (b - sigma) * ((i * (w_0[i] - w_0[i + 1])) / (b * rho)));
			}

			diff = std::abs(w[0] - w_0[0]);
			for (unsigned int i = 1; i <= b; i++) {
				if (std::abs(w[i] - w_0[i]) > diff) {
					diff = std::abs(w[i] - w_0[i]);
				}
			}

			for (int i = 1; i < w_0.size(); i++) {
				w_0[i] = w[i];
			}

			t += h;
			itr++;
		}

		for (unsigned int i = 0; i <= b; i++) {
			mu[i] = w_0[i] - w_0[i + 1];
		}
	}

// Assembly:
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdi, 0x1b0(%rsp)
movl %esi, 0x1ac(%rsp)
movsd %xmm0, 0x1a0(%rsp)
movl %edx, 0x19c(%rsp)
movsd %xmm1, 0x190(%rsp)
movsd %xmm2, 0x188(%rsp)
movl %ecx, 0x184(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x59cd0
leaq 0x150(%rsp), %rdi
callq 0x59cd0
movl $0x0, 0x14c(%rsp)
movslq 0x14c(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0x1b0(%rsp), %rdi
callq 0x61ec0
movq %rax, %rcx
movq 0xd0(%rsp), %rax
cmpq %rcx, %rax
ja 0xa4f36
cmpl $0x0, 0x14c(%rsp)
jne 0xa4e3d
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x140(%rsp)
leaq 0x168(%rsp), %rdi
leaq 0x140(%rsp), %rsi
callq 0x78a90
jmp 0xa4ddc
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x128(%rsp)
leaq 0x150(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x78a90
jmp 0xa4e05
jmp 0xa4f1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x59fd0
leaq 0x168(%rsp), %rdi
callq 0x59fd0
jmp 0xa54c4
movq $0x0, 0x120(%rsp)
leaq 0x168(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x78a90
jmp 0xa4e60
movq $0x0, 0x118(%rsp)
leaq 0x150(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0x78a90
jmp 0xa4e83
movl 0x14c(%rsp), %eax
movl %eax, 0x114(%rsp)
movslq 0x114(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0x1b0(%rsp), %rdi
callq 0x61ec0
movq %rax, %rcx
movq 0xc8(%rsp), %rax
cmpq %rcx, %rax
jae 0xa4f1c
movq 0x1b0(%rsp), %rdi
movslq 0x114(%rsp), %rsi
callq 0x59ce0
movsd (%rax), %xmm0
movsd %xmm0, 0xc0(%rsp)
movslq 0x14c(%rsp), %rsi
leaq 0x168(%rsp), %rdi
callq 0x59ce0
movsd 0xc0(%rsp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movl 0x114(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x114(%rsp)
jmp 0xa4e91
jmp 0xa4f1e
jmp 0xa4f20
movl 0x14c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14c(%rsp)
jmp 0xa4d74
movsd 0x190(%rsp), %xmm0
movsd %xmm0, 0x108(%rsp)
movl $0x0, 0x104(%rsp)
movsd 0x9c1d(%rip), %xmm0     # 0xaeb78
movsd %xmm0, 0xf8(%rsp)
movl 0x104(%rsp), %ecx
xorl %eax, %eax
cmpl 0x184(%rsp), %ecx
movb %al, 0xbf(%rsp)
jge 0xa4f99
movsd 0xf8(%rsp), %xmm0
ucomisd 0x188(%rsp), %xmm0
seta %al
movb %al, 0xbf(%rsp)
movb 0xbf(%rsp), %al
testb $0x1, %al
jne 0xa4fa9
jmp 0xa5402
xorps %xmm0, %xmm0
movsd %xmm0, 0xf0(%rsp)
movl $0x1, 0xec(%rsp)
movl 0xec(%rsp), %eax
cmpl 0x1ac(%rsp), %eax
ja 0xa502f
movl 0xec(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x59ce0
movsd (%rax), %xmm0
movl 0x19c(%rsp), %edi
callq 0x98780
movsd %xmm0, 0xb0(%rsp)
jmp 0xa5001
movsd 0xb0(%rsp), %xmm0
addsd 0xf0(%rsp), %xmm0
movsd %xmm0, 0xf0(%rsp)
movl 0xec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xec(%rsp)
jmp 0xa4fc0
movl $0x1, 0xe8(%rsp)
movl 0xe8(%rsp), %eax
cmpl 0x1ac(%rsp), %eax
jae 0xa51f9
movl 0xe8(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x59ce0
movq 0x90(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x98(%rsp)
movsd 0x190(%rsp), %xmm0
movsd %xmm0, 0xa0(%rsp)
movl 0xe8(%rsp), %eax
movl %eax, %esi
callq 0x59ce0
movsd (%rax), %xmm0
movl 0x19c(%rsp), %edi
callq 0x98780
movsd %xmm0, 0xa8(%rsp)
jmp 0xa50bc
movsd 0xa8(%rsp), %xmm1
movsd 0x6bf3(%rip), %xmm0     # 0xabcc0
subsd %xmm1, %xmm0
movsd %xmm0, 0x80(%rsp)
movl 0x1ac(%rsp), %eax
cvtsi2sd %rax, %xmm0
movsd 0xf0(%rsp), %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
movl 0xe8(%rsp), %eax
movl %eax, %esi
cvtsi2sd %rsi, %xmm0
movsd %xmm0, 0x70(%rsp)
leaq 0x168(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x59ce0
movq 0x60(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x68(%rsp)
movl 0xe8(%rsp), %eax
incl %eax
movl %eax, %esi
callq 0x59ce0
movsd 0x68(%rsp), %xmm5
movsd 0x70(%rsp), %xmm4
movsd 0x78(%rsp), %xmm2
movsd 0x80(%rsp), %xmm3
movsd 0xa0(%rsp), %xmm0
movsd 0x98(%rsp), %xmm1
movsd (%rax), %xmm6
subsd %xmm6, %xmm5
mulsd %xmm5, %xmm4
movl 0x1ac(%rsp), %eax
cvtsi2sd %rax, %xmm5
mulsd 0x1a0(%rsp), %xmm5
divsd %xmm5, %xmm4
movq %xmm2, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm2
mulsd %xmm4, %xmm2
addsd %xmm3, %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x88(%rsp)
movl 0xe8(%rsp), %eax
movl %eax, %esi
leaq 0x150(%rsp), %rdi
callq 0x59ce0
movsd 0x88(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0xe8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe8(%rsp)
jmp 0xa503a
xorl %eax, %eax
movl %eax, %esi
movq %rsi, 0x48(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x59ce0
movq 0x48(%rsp), %rsi
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x59ce0
movsd 0x50(%rsp), %xmm0
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
callq 0x59d70
movsd %xmm0, 0x58(%rsp)
jmp 0xa5246
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0xf8(%rsp)
movl $0x1, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
cmpl 0x1ac(%rsp), %eax
ja 0xa534e
movl 0xe4(%rsp), %eax
movl %eax, %esi
leaq 0x150(%rsp), %rdi
callq 0x59ce0
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movl 0xe4(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x59ce0
movsd 0x38(%rsp), %xmm0
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
callq 0x59d70
movsd %xmm0, 0x40(%rsp)
jmp 0xa52c5
movsd 0x40(%rsp), %xmm0
ucomisd 0xf8(%rsp), %xmm0
jbe 0xa5336
movl 0xe4(%rsp), %eax
movl %eax, %esi
leaq 0x150(%rsp), %rdi
callq 0x59ce0
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movl 0xe4(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x59ce0
movsd 0x28(%rsp), %xmm0
movsd (%rax), %xmm1
subsd %xmm1, %xmm0
callq 0x59d70
movsd %xmm0, 0x30(%rsp)
jmp 0xa5327
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0xf8(%rsp)
jmp 0xa5338
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0xa5260
movl $0x1, 0xe0(%rsp)
movslq 0xe0(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x61ec0
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0xa53d1
movslq 0xe0(%rsp), %rsi
leaq 0x150(%rsp), %rdi
callq 0x59ce0
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movslq 0xe0(%rsp), %rsi
leaq 0x168(%rsp), %rdi
callq 0x59ce0
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0xe0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe0(%rsp)
jmp 0xa5359
movsd 0x190(%rsp), %xmm0
addsd 0x108(%rsp), %xmm0
movsd %xmm0, 0x108(%rsp)
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0xa4f64
movl $0x0, 0xdc(%rsp)
movl 0xdc(%rsp), %eax
cmpl 0x1ac(%rsp), %eax
ja 0xa54a2
movl 0xdc(%rsp), %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x59ce0
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x59ce0
movsd 0x8(%rsp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x1b0(%rsp), %rdi
movl 0xdc(%rsp), %eax
movl %eax, %esi
callq 0x59ce0
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0xa540d
leaq 0x150(%rsp), %rdi
callq 0x59fd0
leaq 0x168(%rsp), %rdi
callq 0x59fd0
addq $0x1b8, %rsp            # imm = 0x1B8
retq
movq 0x138(%rsp), %rdi
callq 0x8770
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)