// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %ecx, 0x44(%rsp)
movsd %xmm2, 0x50(%rsp)
movsd %xmm1, 0x58(%rsp)
movl %edx, (%rsp)
movsd %xmm0, 0x30(%rsp)
movl %esi, %r15d
movq %rdi, %r14
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x60(%rsp), %r12
andq $0x0, 0x10(%r12)
movapd %xmm0, (%r12)
xorl %ebx, %ebx
movabsq $0x3ff0000000000000, %rdi # imm = 0x3FF0000000000000
leaq 0x8(%rsp), %rbp
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x3, %rax
cmpq %rbx, %rax
jb 0x4031c
testq %rbx, %rbx
je 0x402e5
andq $0x0, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x307a4
andq $0x0, 0x8(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x307a4
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq 0x10(%rsp), %rdx
cmpq %rbx, %rcx
cmovbeq %rbx, %rcx
movq %rbx, %rsi
movabsq $0x3ff0000000000000, %rdi # imm = 0x3FF0000000000000
cmpq %rsi, %rcx
je 0x40314
movsd (%rax,%rsi,8), %xmm0
addsd (%rdx,%rbx,8), %xmm0
movsd %xmm0, (%rdx,%rbx,8)
incq %rsi
jmp 0x402cc
movq %rdi, 0x8(%rsp)
movq %rdi, %r13
leaq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x307a4
movq %r13, 0x8(%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x307a4
movabsq $0x3ff0000000000000, %rdi # imm = 0x3FF0000000000000
incq %rbx
jmp 0x40268
cvtsi2sdl (%rsp), %xmm0
movsd %xmm0, (%rsp)
movl %r15d, %r13d
cvtsi2sd %r13, %xmm1
movsd 0x30(%rsp), %xmm0
movsd %xmm1, 0x48(%rsp)
mulsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
leal 0x1(%r15), %r12d
movsd 0x8480(%rip), %xmm0     # 0x487d0
xorl %ebp, %ebp
cmpl 0x44(%rsp), %ebp
jge 0x4049b
ucomisd 0x50(%rsp), %xmm0
jbe 0x4049b
xorpd %xmm1, %xmm1
pushq $0x1
popq %rbx
cmpl %r15d, %ebx
ja 0x4039e
movl %ebx, %eax
movq 0x10(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
movsd %xmm1, 0x38(%rsp)
movsd (%rsp), %xmm1
callq 0x75c0
movsd 0x38(%rsp), %xmm1
addsd %xmm0, %xmm1
incl %ebx
jmp 0x4036f
movsd 0x48(%rsp), %xmm0
subsd %xmm1, %xmm0
xorpd 0x6d90(%rip), %xmm0     # 0x47140
movapd %xmm0, 0x80(%rsp)
pushq $0x1
popq %rbx
cmpq %r13, %rbx
jae 0x40430
movq 0x10(%rsp), %rax
movsd (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd (%rsp), %xmm1
callq 0x75c0
movsd 0x573d(%rip), %xmm1     # 0x45b20
subsd %xmm0, %xmm1
movl %ebx, %eax
cvtsi2sd %rax, %xmm0
movq 0x10(%rsp), %rax
movsd (%rax,%rbx,8), %xmm2
subsd 0x8(%rax,%rbx,8), %xmm2
mulsd %xmm0, %xmm2
divsd 0x30(%rsp), %xmm2
mulsd 0x80(%rsp), %xmm2
addsd %xmm1, %xmm2
mulsd 0x58(%rsp), %xmm2
addsd 0x38(%rsp), %xmm2
movq 0x60(%rsp), %rax
movsd %xmm2, (%rax,%rbx,8)
incq %rbx
jmp 0x403bc
movq 0x60(%rsp), %rax
movsd (%rax), %xmm0
movq 0x10(%rsp), %rcx
subsd (%rcx), %xmm0
andpd 0x5fb6(%rip), %xmm0     # 0x46400
pushq $0x1
popq %rdx
cmpq %rdx, %r12
je 0x40471
movsd (%rax,%rdx,8), %xmm1
subsd (%rcx,%rdx,8), %xmm1
andpd 0x5f9c(%rip), %xmm1     # 0x46400
maxsd %xmm0, %xmm1
incq %rdx
movapd %xmm1, %xmm0
jmp 0x4044d
movq 0x18(%rsp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
pushq $0x1
popq %rsi
cmpq %rsi, %rdx
jbe 0x40494
movsd (%rax,%rsi,8), %xmm1
movsd %xmm1, (%rcx,%rsi,8)
incq %rsi
jmp 0x40480
incl %ebp
jmp 0x40352
movq 0x10(%rsp), %rax
movq (%r14), %rcx
negq %r12
pushq $0x1
popq %rdx
leaq (%r12,%rdx), %rsi
cmpq $0x1, %rsi
je 0x404cb
movsd -0x8(%rax,%rdx,8), %xmm0
movl %edx, %esi
subsd (%rax,%rsi,8), %xmm0
movsd %xmm0, -0x8(%rcx,%rdx,8)
incq %rdx
jmp 0x404a9
leaq 0x60(%rsp), %rdi
callq 0x2803e
leaq 0x10(%rsp), %rdi
callq 0x2803e
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x404f7
jmp 0x404f7
jmp 0x404f7
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x2803e
leaq 0x10(%rsp), %rdi
callq 0x2803e
movq %rbx, %rdi
callq 0x75d0
nop