// File: /workspace/github_cpp_makefile_star2_O3/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, 0x2c(%rsp)
movsd %xmm2, 0x58(%rsp)
movsd %xmm1, 0x78(%rsp)
movl %edx, 0x20(%rsp)
movsd %xmm0, 0x38(%rsp)
movl %esi, %r14d
movq %rdi, %r15
xorpd %xmm0, %xmm0
movq %rsp, %rax
movapd %xmm0, (%rax)
xorl %ebx, %ebx
movq %rbx, 0x10(%rax)
leaq 0x40(%rsp), %r13
movq %rbx, 0x10(%r13)
movapd %xmm0, (%r13)
movabsq $0x3ff0000000000000, %r12 # imm = 0x3FF0000000000000
leaq 0x30(%rsp), %rbp
testq %rbx, %rbx
je 0x51f65
movq $0x0, 0x30(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x51f84
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x51f8f
movq %r12, 0x30(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x51ff4
movq %r12, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rsp)
jmp 0x51fff
movq %rsp, %rdi
movq %rbp, %rdx
callq 0x3c27a
movq $0x0, 0x30(%rsp)
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0x51fb6
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x48(%rsp)
jmp 0x51fc1
movq %r13, %rdi
movq %rbp, %rdx
callq 0x3c27a
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
jbe 0x52037
movq (%rsp), %rdx
movsd (%rdx,%rbx,8), %xmm0
movq %rbx, %rsi
addsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rdx,%rbx,8)
incq %rsi
cmpq %rsi, %rcx
ja 0x51fe0
jmp 0x52037
movq %rsp, %rdi
movq %rbp, %rdx
callq 0x3c27a
movq %r12, 0x30(%rsp)
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0x5201e
movq %r12, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x48(%rsp)
jmp 0x52029
movq %r13, %rdi
movq %rbp, %rdx
callq 0x3c27a
movq (%r15), %rax
movq 0x8(%r15), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
leaq 0x1(%rbx), %rdx
cmpq %rbx, %rcx
movq %rdx, %rbx
ja 0x51f39
cmpl $0x0, 0x2c(%rsp)
jle 0x52225
movsd 0x88be(%rip), %xmm0     # 0x5a918
ucomisd 0x58(%rsp), %xmm0
jbe 0x52225
cvtsi2sdl 0x20(%rsp), %xmm1
movl %r14d, %r13d
cvtsi2sd %r13, %xmm2
movsd 0x38(%rsp), %xmm0
movsd %xmm2, 0x70(%rsp)
mulsd %xmm2, %xmm0
movsd %xmm0, 0x38(%rsp)
leal 0x1(%r14), %eax
cmpl $0x3, %eax
movl $0x2, %ebp
movq %rax, 0x68(%rsp)
cmovael %eax, %ebp
xorl %ebx, %ebx
movsd %xmm1, 0x60(%rsp)
testl %r14d, %r14d
je 0x52193
xorpd %xmm2, %xmm2
movl $0x1, %r12d
movsd %xmm2, 0x20(%rsp)
movl %r12d, %eax
movq (%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
callq 0x7610
movsd 0x20(%rsp), %xmm2
movsd 0x60(%rsp), %xmm1
addsd %xmm0, %xmm2
incl %r12d
cmpl %r14d, %r12d
jbe 0x520b9
cmpl $0x1, %r14d
jbe 0x52193
movsd 0x70(%rsp), %xmm0
subsd %xmm2, %xmm0
xorpd 0x716c(%rip), %xmm0     # 0x59270
movapd %xmm0, 0x80(%rsp)
movl $0x1, %r12d
movq (%rsp), %rdi
movsd (%rdi,%r12,8), %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x7610
movsd 0x5ae0(%rip), %xmm4     # 0x57c10
movl %r12d, %eax
xorps %xmm2, %xmm2
cvtsi2sd %rax, %xmm2
movq (%rsp), %rdi
movsd (%rdi,%r12,8), %xmm3
subsd 0x8(%rdi,%r12,8), %xmm3
subsd %xmm0, %xmm4
mulsd %xmm2, %xmm3
movsd 0x60(%rsp), %xmm1
divsd 0x38(%rsp), %xmm3
mulsd 0x80(%rsp), %xmm3
addsd %xmm4, %xmm3
mulsd 0x78(%rsp), %xmm3
addsd 0x20(%rsp), %xmm3
movq 0x40(%rsp), %rax
movsd %xmm3, (%rax,%r12,8)
leaq 0x1(%r12), %rcx
movq %rcx, %r12
cmpq %rcx, %r13
jne 0x52117
jmp 0x5219c
movq 0x40(%rsp), %rax
movq (%rsp), %rdi
movsd (%rax), %xmm2
subsd (%rdi), %xmm2
movapd 0x6384(%rip), %xmm3     # 0x58530
andpd %xmm3, %xmm2
testl %r14d, %r14d
je 0x521da
movl $0x1, %ecx
movsd (%rax,%rcx,8), %xmm0
subsd (%rdi,%rcx,8), %xmm0
andpd %xmm3, %xmm0
maxsd %xmm2, %xmm0
incq %rcx
movapd %xmm0, %xmm2
cmpq %rcx, %rbp
jne 0x521ba
jmp 0x521de
movapd %xmm2, %xmm0
movq 0x8(%rsp), %rcx
subq %rdi, %rcx
sarq $0x3, %rcx
cmpq $0x2, %rcx
jb 0x52207
movl $0x1, %edx
movsd (%rax,%rdx,8), %xmm2
movsd %xmm2, (%rdi,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x521f5
incl %ebx
cmpl 0x2c(%rsp), %ebx
jge 0x5221b
ucomisd 0x58(%rsp), %xmm0
ja 0x520a6
movq (%r15), %rax
movq 0x68(%rsp), %r14
jmp 0x5222c
movq (%rsp), %rdi
incl %r14d
cmpl $0x1, %r14d
adcl $0x0, %r14d
xorl %ecx, %ecx
movsd (%rdi,%rcx,8), %xmm0
subsd 0x8(%rdi,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
leaq 0x1(%rcx), %rdx
movq %rdx, %rcx
cmpq %rdx, %r14
jne 0x52236
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x5226d
movq %rax, %rdi
callq 0x7370
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x52272
callq 0x7370
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5228a
jmp 0x5228a
jmp 0x5228a
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x5229c
callq 0x7370
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x522aa
callq 0x7370
movq %rbx, %rdi
callq 0x7620
nop