// File: /workspace/github_cpp_makefile_star2_O1/arinaschwartz[P]KNN-MNIST/MNISTDataset.cpp
// Function: MNISTDataset::MNISTDataset(std::istream&, std::istream&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
MNISTDataset::MNISTDataset(istream &imageFile, istream &labelFile, string type)
{
	uint32 magic, numLabels;

	magic = readUInt32(imageFile);

	if(magic!=2051)
		throw MNISTFileException("Magic number in image file is not 2051");

	this->numImages = readUInt32(imageFile);
	this->numRows = readUInt32(imageFile);
	this->numCols = readUInt32(imageFile);

	magic = readUInt32(labelFile);
	if(magic!=2049)
		throw MNISTFileException("Magic number in label file is not 2049");

	numLabels = readUInt32(labelFile);

	if (numLabels != this->numImages)
		throw MNISTFileException("Number of images doesn't match the number of labels");

	imgs = new MNISTImage*[this->numImages];

	for(uint32 i=0; i<this->numImages; i++)
	{
		uint8 img[this->numCols*this->numRows];
		uint8 label;

		label = readUInt8(labelFile);
		readUInt8Array(imageFile, img, numCols*numRows);

		imgs[i] = createImage(img, label, type);
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, -0x40(%rbp)
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r12
leaq -0x2c(%rbp), %r14
movl $0x4, %edx
movq %rsi, %rdi
movq %r14, %rsi
callq 0x21f0
movl (%r14), %eax
bswapl %eax
cmpl $0x803, %eax            # imm = 0x803
jne 0x26ce
movl $0x4, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21f0
movl (%r14), %eax
bswapl %eax
movl %eax, 0x8(%r12)
movl $0x4, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21f0
movl (%r14), %eax
bswapl %eax
movl %eax, 0xc(%r12)
movl $0x4, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21f0
movl (%r14), %eax
bswapl %eax
movl %eax, 0x10(%r12)
movl $0x4, %edx
movq %r15, %rdi
movq %r14, %rsi
callq 0x21f0
movl (%r14), %eax
bswapl %eax
cmpl $0x801, %eax            # imm = 0x801
jne 0x26eb
movq %rbx, -0x38(%rbp)
movl $0x4, %edx
movq %r15, %rbx
movq %r15, %rdi
movq %r14, %rsi
callq 0x21f0
movl (%r14), %eax
bswapl %eax
movl 0x8(%r12), %edi
cmpl %edi, %eax
jne 0x2708
shlq $0x3, %rdi
callq 0x2030
movq %rax, (%r12)
cmpl $0x0, 0x8(%r12)
je 0x26bf
movq %rbx, %rdi
xorl %r13d, %r13d
movq %rsp, -0x48(%rbp)
movl 0xc(%r12), %eax
imull 0x10(%r12), %eax
addq $0xf, %rax
andq $-0x10, %rax
movq %rsp, %r14
subq %rax, %r14
movq %r14, %rsp
movl $0x1, %edx
movq %rdi, %r15
leaq -0x2c(%rbp), %rsi
callq 0x21f0
movzbl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl 0xc(%r12), %edx
imull 0x10(%r12), %edx
movq -0x38(%rbp), %rdi
movq %r14, %rsi
callq 0x21f0
leaq -0x58(%rbp), %rbx
movq %rbx, -0x68(%rbp)
movq -0x40(%rbp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x2ab8
movq %r12, %rdi
movq %r14, %rsi
movl -0x30(%rbp), %edx
leaq -0x68(%rbp), %rcx
callq 0x27b4
movq (%r12), %rcx
movq %rax, (%rcx,%r13,8)
movq -0x68(%rbp), %rdi
cmpq %rbx, %rdi
je 0x26a7
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x21b0
movq -0x48(%rbp), %rsp
incq %r13
movl 0x8(%r12), %eax
cmpq %rax, %r13
movq %r15, %rdi
jb 0x260a
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x10, %edi
callq 0x20f0
leaq 0x44d1(%rip), %rcx      # 0x6bb0
movq %rcx, (%rax)
leaq 0x191b(%rip), %rcx      # 0x4004
jmp 0x2723
movl $0x10, %edi
callq 0x20f0
leaq 0x44b4(%rip), %rcx      # 0x6bb0
movq %rcx, (%rax)
leaq 0x1925(%rip), %rcx      # 0x402b
jmp 0x2723
movl $0x10, %edi
callq 0x20f0
leaq 0x4497(%rip), %rcx      # 0x6bb0
movq %rcx, (%rax)
leaq 0x192f(%rip), %rcx      # 0x4052
movq %rcx, 0x8(%rax)
leaq 0x449a(%rip), %rsi      # 0x6bc8
movq 0x48a3(%rip), %rdx      # 0x6fd8
movq %rax, %rdi
callq 0x2260
movq %rax, %r14
movq -0x68(%rbp), %rdi
cmpq %rbx, %rdi
je 0x2755
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x21b0
movq %r14, %rdi
callq 0x2280
nop