// File: /workspace/github_cpp_makefile_star2_O3/ghulette[P]neural-net-openmp/dataset.cpp
// Function: DataSet::DataSet(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
DataSet::DataSet(std::string idx_image_file, std::string idx_label_file, int output_enc) {
	using namespace std;
	
	IdxData *image_idx = new IdxData(idx_image_file);
	IdxData *label_idx = new IdxData(idx_label_file);
	
	if(image_idx->num_records() != label_idx->num_records()) {
		cerr << "Image and label files have differing lengths" << endl;
		exit(1);
	}
	num_entries = image_idx->num_records();
	image_data_length = image_idx->record_size();
	
	switch(output_enc) {
		case OUTPUT_ASCII:
			label_data_length = ASCII_LENGTH;
			break;
		case OUTPUT_PACKED:
			label_data_length = PACKED_LENGTH;
			break;
		case OUTPUT_FULL:
			label_data_length = FULL_LENGTH;
			break;
		default:
			cerr << "Error: Output encoding " << output_enc << " not supported." << endl;
			exit(1);
	}
	
	image_data = new double *[num_entries];
	label_data = new double *[num_entries];
	labels = new int[num_entries];
	
	for(int i=0; i < num_entries; i ++) {
		// Label digit
		labels[i] = int(label_idx->record(i)[0]);
		
		// Label output vector
		switch(output_enc) {
			case OUTPUT_ASCII:
				label_data[i] = vector_for_label_ascii(labels[i]);
				break;
			case OUTPUT_PACKED:
				label_data[i] = vector_for_label_packed(labels[i]);
				break;
			case OUTPUT_FULL:
				label_data[i] = vector_for_label_full(labels[i]);
				break;
		}
		
		// Image vector (rescaled from 0-255 to 0.0-1.0)
		image_data[i] = new double[image_idx->record_size()];
		unsigned char *idx_img = image_idx->record(i);
		for(int j=0; j < image_data_length; j++) {
			image_data[i][j] = double(idx_img[j]) / 255.0;
		}
	}
	
	delete image_idx;
	delete label_idx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %ecx, %ebp
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %r14
movl $0x10, %edi
callq 0x2130
movq %rax, %rbx
leaq 0x38(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x32dc
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x3374
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x2c6b
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2140
movl $0x10, %edi
callq 0x2130
movq %rax, %r15
leaq 0x18(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x32dc
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x3374
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x2cbb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2140
movq %rbx, %rdi
callq 0x35b8
movl %eax, %r12d
movq %r15, %rdi
callq 0x35b8
cmpl %eax, %r12d
jne 0x2f04
movq %r15, (%rsp)
movq %rbx, %rdi
callq 0x35b8
movl %eax, (%r14)
movq %rbx, %rdi
callq 0x35bc
movl %eax, 0x4(%r14)
cmpl $0x3, %ebp
jae 0x2f14
movl %ebp, %eax
leaq 0x2438(%rip), %rcx      # 0x513c
movl (%rcx,%rax,4), %eax
movl %eax, 0x8(%r14)
movslq (%r14), %r15
leaq (,%r15,8), %r12
testq %r15, %r15
movq $-0x1, %rax
cmovsq %rax, %r12
leaq (,%r15,4), %r13
cmovsq %rax, %r13
movq %r12, %rdi
callq 0x2030
movq %rax, 0x10(%r14)
movq %r12, %rdi
callq 0x2030
movq %rax, 0x18(%r14)
movq %r13, %rdi
callq 0x2030
movq %rax, 0x20(%r14)
testq %r15, %r15
movq (%rsp), %r15
jle 0x2ecb
xorl %r12d, %r12d
movq %r15, %rdi
movl %r12d, %esi
callq 0x35c0
movzbl (%rax), %r13d
movq 0x20(%r14), %rax
movl %r13d, (%rax,%r12,4)
cmpl $0x2, %ebp
je 0x2df4
cmpl $0x1, %ebp
je 0x2dc4
testl %ebp, %ebp
jne 0x2e52
movl $0x40, %edi
callq 0x2030
addl $0x30, %r13d
xorl %ecx, %ecx
movl %r13d, %edx
andl $0x1, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd %xmm0, (%rax,%rcx,8)
shrl %r13d
andl $0x7f, %r13d
incq %rcx
cmpq $0x8, %rcx
jne 0x2d9d
jmp 0x2e4a
movl $0x20, %edi
callq 0x2030
xorl %ecx, %ecx
movl %r13d, %edx
andl $0x1, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movsbl %r13b, %r13d
sarl %r13d
incq %rcx
cmpq $0x4, %rcx
jne 0x2dd0
jmp 0x2e4a
movl $0x50, %edi
callq 0x2030
movd %r13d, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
xorl %ecx, %ecx
movdqa 0x220e(%rip), %xmm1     # 0x5020
movdqa 0x2216(%rip), %xmm4     # 0x5030
movdqa 0x221e(%rip), %xmm5     # 0x5040
movdqa %xmm1, %xmm2
pcmpeqd %xmm0, %xmm2
pshufd $0xb1, %xmm2, %xmm3     # xmm3 = xmm2[1,0,3,2]
pand %xmm2, %xmm3
pand %xmm4, %xmm3
movdqu %xmm3, (%rax,%rcx,8)
addq $0x2, %rcx
paddq %xmm5, %xmm1
cmpq $0xa, %rcx
jne 0x2e22
movq 0x18(%r14), %rcx
movq %rax, (%rcx,%r12,8)
movq %rbx, %rdi
callq 0x35bc
movl %eax, %edi
shlq $0x3, %rdi
testl %eax, %eax
movq $-0x1, %rax
cmovsq %rax, %rdi
callq 0x2030
movq 0x10(%r14), %rcx
movq %rax, (%rcx,%r12,8)
movq %rbx, %rdi
movl %r12d, %esi
callq 0x35c0
movslq 0x4(%r14), %rcx
testq %rcx, %rcx
movsd 0x217c(%rip), %xmm1     # 0x5010
jle 0x2ebc
movq 0x10(%r14), %rdx
movq (%rdx,%r12,8), %rdx
xorl %esi, %esi
movzbl (%rax,%rsi), %edi
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %rcx
jne 0x2ea0
incq %r12
movslq (%r14), %rax
cmpq %rax, %r12
jl 0x2d64
movq %rbx, %rdi
callq 0x35aa
movl $0x10, %esi
movq %rbx, %rdi
callq 0x2140
movq %r15, %rdi
callq 0x35aa
movl $0x10, %esi
movq %r15, %rdi
callq 0x2140
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x40e5(%rip), %rdi      # 0x6ff0
leaq 0x219a(%rip), %rsi      # 0x50ac
jmp 0x2f3b
movq 0x40d5(%rip), %rdi      # 0x6ff0
leaq 0x21b7(%rip), %rsi      # 0x50d9
callq 0x2120
movq %rax, %rdi
movl %ebp, %esi
callq 0x21b0
leaq 0x21b9(%rip), %rsi      # 0x50f1
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x20a0
movl $0x1, %edi
callq 0x2160
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x2f71
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2140
jmp 0x2f71
movq %rax, %r14
movq %r15, %rbx
jmp 0x2f95
movq %rax, %r14
movq 0x28(%rsp), %rdi
cmpq %r13, %rdi
je 0x2f95
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2140
jmp 0x2f95
movq %rax, %r14
movl $0x10, %esi
movq %rbx, %rdi
callq 0x2140
movq %r14, %rdi
callq 0x21c0