// File: gvaumour[P]cache-simulator/src/common.cc
// Function: resize_image(std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>>&)
vector< vector<int> > 
resize_image(vector< vector<int> >& img)
{

	int width =img[0].size();
	vector<vector<int > > result = vector< vector<int> >(img.size() , vector<int>());
	int factor = ceil ( (double)width / (double) IMG_WIDTH );

	for(unsigned i = 0 ; i < img.size() ; i++)
	{
		for(unsigned j = 0 ; j < img[i].size() ; j+= factor)
		{
			int index = factor + j >= img[i].size() ? img[i].size() : factor+j; 
			int sum = 0;
			for(int k = j ; k < index; k++)
				sum += img[i][k];
				
//			cout << "result[" << i << "].push_back " << sum << " / " << factor << " = " <<  sum / factor << endl;
			result[i].push_back(sum / factor);
		}
	}	
	return result;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0x30(%rsp)
movq %rdi, %rax
movq %rax, 0x28(%rsp)
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq 0xa8(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
callq 0x11020
movl %eax, 0xa4(%rsp)
movb $0x0, 0xa3(%rsp)
movq 0xa8(%rsp), %rdi
callq 0xfb20
movq %rax, 0x38(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movq $0x0, 0x90(%rsp)
leaq 0x80(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0xe8d0
leaq 0x7f(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0xedc0
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
callq 0xedd0
jmp 0x66231
leaq 0x7f(%rsp), %rdi
callq 0xeef0
leaq 0x80(%rsp), %rdi
callq 0xef00
cvtsi2sdl 0xa4(%rsp), %xmm0
movsd 0xdd0f(%rip), %xmm1     # 0x73f68
divsd %xmm1, %xmm0
callq 0x50b0
cvttsd2si %xmm0, %eax
movl %eax, 0x68(%rsp)
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
movq %rax, 0x20(%rsp)
movq 0xa8(%rsp), %rdi
callq 0xfb20
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0x6642f
movl $0x0, 0x60(%rsp)
movl 0x60(%rsp), %eax
movq %rax, 0x18(%rsp)
movq 0xa8(%rsp), %rdi
movl 0x64(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
callq 0x11020
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
jae 0x6641d
movl 0x68(%rsp), %eax
addl 0x60(%rsp), %eax
movl %eax, %eax
movq %rax, 0x10(%rsp)
movq 0xa8(%rsp), %rdi
movl 0x64(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
callq 0x11020
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jb 0x6632f
movq 0xa8(%rsp), %rdi
movl 0x64(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
callq 0x11020
movq %rax, 0x8(%rsp)
jmp 0x6633e
movl 0x68(%rsp), %eax
addl 0x60(%rsp), %eax
movl %eax, %eax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
movl %eax, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movl 0x60(%rsp), %eax
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jge 0x663c2
movq 0xa8(%rsp), %rdi
movl 0x64(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
movslq 0x54(%rsp), %rsi
callq 0xef90
movl (%rax), %eax
addl 0x58(%rsp), %eax
movl %eax, 0x58(%rsp)
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x66357
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
leaq 0x7f(%rsp), %rdi
callq 0xeef0
leaq 0x80(%rsp), %rdi
callq 0xef00
jmp 0x66458
movq 0x30(%rsp), %rdi
movl 0x64(%rsp), %eax
movl %eax, %esi
callq 0xef70
movq %rax, %rdi
movl 0x58(%rsp), %eax
movl 0x68(%rsp), %ecx
cltd
idivl %ecx
movl %eax, 0x50(%rsp)
leaq 0x50(%rsp), %rsi
callq 0x20450
jmp 0x663f0
jmp 0x663f2
movl 0x68(%rsp), %eax
addl 0x60(%rsp), %eax
movl %eax, 0x60(%rsp)
jmp 0x662a1
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
callq 0xee90
jmp 0x66458
jmp 0x6641f
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x66272
movb $0x1, 0xa3(%rsp)
testb $0x1, 0xa3(%rsp)
jne 0x6644b
movq 0x30(%rsp), %rdi
callq 0xee90
movq 0x28(%rsp), %rax
addq $0xb8, %rsp
retq
movq 0x70(%rsp), %rdi
callq 0x5690
nopw %cs:(%rax,%rax)