// File: zengfenfei[P]codility/src/MinAvgTwoSlice.cpp
// Function: solution(std::vector<int, std::allocator<int>>&)
int solution(vector<int> &A) {
	int n = A.size();
	int minI = 0;
	double minAvg = (A[0] + A[1]) / 2.0;
	for (int i = 0; i < n - 2; i++) {
		double avg = (A[i] + A[i + 1]) / 2.0;
		if (avg < minAvg) {
			minAvg = avg;
			minI = i;
		}
		avg = (A[i] + A[i + 1] + A[i + 2]) / 3.0;
		if (avg < minAvg) {
			minAvg = avg;
			minI = i;
		}
	}
	if (n > 2) {	// Check the last 2 elements
		double avg = (A[n - 2] + A[n - 1]) / 2.0;
		if (avg < minAvg) {
			minAvg = avg;
			minI = n - 2;
		}
	}
	return minI;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1550
movl %eax, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x1570
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x1570
movq %rax, %rcx
movl -0x34(%rbp), %eax
addl (%rcx), %eax
cvtsi2sd %eax, %xmm0
movsd 0xd85(%rip), %xmm1      # 0x2008
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl -0xc(%rbp), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jge 0x1393
movq -0x8(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x1570
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x1570
movq %rax, %rcx
movl -0x38(%rbp), %eax
addl (%rcx), %eax
cvtsi2sd %eax, %xmm0
movsd 0xd2c(%rip), %xmm1      # 0x2008
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1305
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x1570
movl (%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x1570
movq %rax, %rcx
movl -0x40(%rbp), %eax
addl (%rcx), %eax
movl %eax, -0x3c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
addl $0x2, %eax
movslq %eax, %rsi
callq 0x1570
movq %rax, %rcx
movl -0x3c(%rbp), %eax
addl (%rcx), %eax
cvtsi2sd %eax, %xmm0
movsd 0xcb6(%rip), %xmm1      # 0x2010
divsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1383
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x10(%rbp)
jmp 0x1385
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1293
cmpl $0x2, -0xc(%rbp)
jle 0x1404
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %eax
subl $0x2, %eax
movslq %eax, %rsi
callq 0x1570
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x1570
movq %rax, %rcx
movl -0x44(%rbp), %eax
addl (%rcx), %eax
cvtsi2sd %eax, %xmm0
movsd 0xc32(%rip), %xmm1      # 0x2008
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1402
movsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movl -0xc(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x10(%rbp)
jmp 0x1404
movl -0x10(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)