// File: /workspace/github_cpp_makefile_star2_O3/nikosgalanis[P]Vectors-Similarity-Search-and-Clustering/programs/common/io_utils.cc
// Function: parse_input(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
vector<vector<double>> parse_input(string filename) {
	// open the dataset
	ifstream input(filename, ios::binary);

	// read the magic number of the image
	int magic_number = 0;
	input.read((char*)&magic_number, sizeof(int));
	magic_number = our_math::big_to_litte_endian(magic_number);
	// find out how many images we are going to parse
	int n_of_images;
	input.read((char*)&n_of_images, sizeof(int));
	n_of_images = our_math::big_to_litte_endian(n_of_images);

	// create a list of vectors to return
	vector<vector<double>> list_of_vectors;
	// read the dimensions
	int rows = 0;
	input.read((char*)&rows, sizeof(int));
	rows = our_math::big_to_litte_endian(rows);
	int cols;
	input.read((char*)&cols, sizeof(int));
	cols = our_math::big_to_litte_endian(cols);

	double x;
	// for each image start filling the vectors
	for (int i = 0; i < n_of_images; i++) {
		// create a vector to store our image data
		vector<double> vec;
		// store each byte of the image in the vector, by parsing boh of the image's dimensions
		for (int j = 0; j < rows; j++) {
			for (int k = 0; k < cols; k++) {
				// the pixels are from 0-255, so an unsinged char type is enough
				unsigned char pixel = 0;
				input.read((char*)(&pixel), sizeof(pixel));
				// change its value to double
				x = (double)pixel;
				// push the byte into the vector
				vec.push_back(x);
			}
		}
		// push the vector in our list
		list_of_vectors.push_back(vec);
	}
	
	input.close();
	// return the list of vectors that we created
	return list_of_vectors;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rdi, 0x20(%rsp)
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movl $0x4, %edx
callq 0x2360
leaq 0x1c(%rsp), %rsi
movl $0x0, (%rsi)
movl $0x4, %edx
movq %r14, %rdi
callq 0x22a0
movl 0x1c(%rsp), %eax
bswapl %eax
movl %eax, 0x1c(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movl $0x4, %edx
callq 0x22a0
movl 0x18(%rsp), %eax
bswapl %eax
movl %eax, 0x18(%rsp)
xorpd %xmm0, %xmm0
movq 0x20(%rsp), %rax
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
leaq 0x14(%rsp), %rsi
movl $0x0, (%rsi)
leaq 0x50(%rsp), %rdi
movl $0x4, %edx
callq 0x22a0
movl 0x14(%rsp), %eax
bswapl %eax
movl %eax, 0x14(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl $0x4, %edx
callq 0x22a0
movl 0x10(%rsp), %eax
bswapl %eax
movl %eax, 0x10(%rsp)
cmpl $0x0, 0x18(%rsp)
jle 0x27f4
xorl %ebx, %ebx
leaq 0x50(%rsp), %r14
leaq 0xf(%rsp), %r15
leaq 0x30(%rsp), %r12
leaq 0x48(%rsp), %r13
movl %ebx, 0x2c(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movl 0x14(%rsp), %eax
testl %eax, %eax
jle 0x27c8
xorl %ebx, %ebx
movl 0x10(%rsp), %ecx
testl %ecx, %ecx
jle 0x27c2
xorl %ebp, %ebp
movb $0x0, 0xf(%rsp)
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x22a0
movzbl 0xf(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x48(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x27a9
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x27b4
movq %r12, %rdi
movq %r13, %rdx
callq 0x3616
incl %ebp
movl 0x10(%rsp), %ecx
cmpl %ecx, %ebp
jl 0x2767
movl 0x14(%rsp), %eax
incl %ebx
cmpl %eax, %ebx
jl 0x2761
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x359a
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
movl 0x2c(%rsp), %ebx
je 0x27e8
callq 0x2220
incl %ebx
cmpl 0x18(%rsp), %ebx
jl 0x273c
leaq 0x50(%rsp), %rdi
callq 0x2070
leaq 0x50(%rsp), %rdi
callq 0x2080
movq 0x20(%rsp), %rax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2823
jmp 0x2823
movq %rax, %r14
jmp 0x2843
jmp 0x282a
movq %rax, %r14
jmp 0x284d
jmp 0x2831
movq %rax, %r14
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2843
callq 0x2220
movq 0x20(%rsp), %rdi
callq 0x35c6
leaq 0x50(%rsp), %rdi
callq 0x2080
movq %r14, %rdi
callq 0x2400