// File: /workspace/github_cpp_makefile_star2_O2/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, 0x18(%rsp)
leaq 0x50(%rsp), %r14
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0x22f0
leaq 0x14(%rsp), %rsi
andl $0x0, (%rsi)
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0x2230
movl 0x14(%rsp), %eax
bswapl %eax
movl %eax, 0x14(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x2230
movl 0x10(%rsp), %eax
bswapl %eax
movl %eax, 0x10(%rsp)
xorpd %xmm0, %xmm0
movq 0x18(%rsp), %rax
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0xc(%rsp), %rsi
andl $0x0, (%rsi)
leaq 0x50(%rsp), %rdi
pushq $0x4
popq %rdx
callq 0x2230
movl 0xc(%rsp), %eax
bswapl %eax
movl %eax, 0xc(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x2230
movl 0x8(%rsp), %eax
bswapl %eax
movl %eax, 0x8(%rsp)
xorl %ebx, %ebx
leaq 0x7(%rsp), %r15
pushq $0x1
popq %r12
leaq 0x30(%rsp), %r13
leaq 0x28(%rsp), %rbp
cmpl 0x10(%rsp), %ebx
jge 0x2641
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
xorl %r14d, %r14d
movl %ebx, 0x24(%rsp)
cmpl 0xc(%rsp), %r14d
jge 0x2625
xorl %ebx, %ebx
cmpl 0x8(%rsp), %ebx
jge 0x261c
movb $0x0, 0x7(%rsp)
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x2230
movzbl 0x7(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x28(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2e90
incl %ebx
jmp 0x25e3
incl %r14d
movl 0x24(%rsp), %ebx
jmp 0x25da
movq 0x18(%rsp), %rdi
movq %r13, %rsi
callq 0x2eb2
movq %r13, %rdi
callq 0x2f56
incl %ebx
jmp 0x25bd
leaq 0x50(%rsp), %rdi
callq 0x2060
leaq 0x50(%rsp), %rdi
callq 0x2070
movq 0x18(%rsp), %rax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2670
jmp 0x2670
movq %rax, %r14
jmp 0x268b
jmp 0x2677
movq %rax, %r14
jmp 0x2695
jmp 0x267e
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x2f56
movq 0x18(%rsp), %rdi
callq 0x2ede
leaq 0x50(%rsp), %rdi
callq 0x2070
movq %r14, %rdi
callq 0x2380