// File: 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:
subq $0xe8, %rsp
movq %rsi, 0x40(%rsp)
movq %rdx, 0x30(%rsp)
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
movl %ecx, 0xcc(%rsp)
movq 0xe0(%rsp), %rax
movq %rax, 0x38(%rsp)
movl $0x10, %edi
callq 0x2160
movq 0x40(%rsp), %rsi
movq %rax, 0x48(%rsp)
movb $0x1, 0x93(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x20b0
jmp 0x2df8
movq 0x48(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x36f0
jmp 0x2e0c
movb $0x0, 0x93(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x2308
movq 0x48(%rsp), %rax
movq %rax, 0xc0(%rsp)
movl $0x10, %edi
callq 0x2160
movq 0x30(%rsp), %rsi
movq %rax, 0x28(%rsp)
movb $0x1, 0x67(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x20b0
jmp 0x2e53
movq 0x28(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x36f0
jmp 0x2e64
movb $0x0, 0x67(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x2308
movq 0x28(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0xc0(%rsp), %rdi
callq 0x39d0
movl %eax, 0x24(%rsp)
movq 0x88(%rsp), %rdi
callq 0x39d0
movl %eax, %ecx
movl 0x24(%rsp), %eax
cmpl %ecx, %eax
je 0x2f80
movq 0x513d(%rip), %rdi      # 0x7ff0
leaq 0x31ca(%rip), %rsi      # 0x6084
callq 0x2150
movq %rax, %rdi
movq 0x50ef(%rip), %rsi      # 0x7fb8
callq 0x2180
movl $0x1, %edi
callq 0x21d0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
jmp 0x2f0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x2308
testb $0x1, 0x93(%rsp)
jne 0x2f1b
jmp 0x2f2a
movq 0x48(%rsp), %rdi
movl $0x10, %esi
callq 0x2170
jmp 0x32f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
jmp 0x2f63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x98(%rsp)
movl %eax, 0x94(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x2308
testb $0x1, 0x67(%rsp)
jne 0x2f6c
jmp 0x2f7b
movq 0x28(%rsp), %rdi
movl $0x10, %esi
callq 0x2170
jmp 0x32f7
movq 0xc0(%rsp), %rdi
callq 0x39d0
movl %eax, %ecx
movq 0x38(%rsp), %rax
movl %ecx, (%rax)
movq 0xc0(%rsp), %rdi
callq 0x39e0
movl %eax, %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x4(%rax)
movl 0xcc(%rsp), %eax
movl %eax, 0x20(%rsp)
testl %eax, %eax
je 0x2fd4
jmp 0x2fbe
movl 0x20(%rsp), %eax
subl $0x1, %eax
je 0x2fe2
jmp 0x2fc9
movl 0x20(%rsp), %eax
subl $0x2, %eax
je 0x2ff0
jmp 0x2ffe
movq 0x38(%rsp), %rax
movl $0x8, 0x8(%rax)
jmp 0x3048
movq 0x38(%rsp), %rax
movl $0x4, 0x8(%rax)
jmp 0x3048
movq 0x38(%rsp), %rax
movl $0xa, 0x8(%rax)
jmp 0x3048
movq 0x4feb(%rip), %rdi      # 0x7ff0
leaq 0x30a5(%rip), %rsi      # 0x60b1
callq 0x2150
movq %rax, %rdi
movl 0xcc(%rsp), %esi
callq 0x2260
movq %rax, %rdi
leaq 0x309f(%rip), %rsi      # 0x60c9
callq 0x2150
movq %rax, %rdi
movq 0x4f7f(%rip), %rsi      # 0x7fb8
callq 0x2180
movl $0x1, %edi
callq 0x21d0
movq 0x38(%rsp), %rax
movslq (%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x10(%rax)
movslq (%rax), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x18(%rax)
movslq (%rax), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x20(%rax)
movl $0x0, 0x60(%rsp)
movq 0x38(%rsp), %rcx
movl 0x60(%rsp), %eax
cmpl (%rcx), %eax
jge 0x3297
movq 0x88(%rsp), %rdi
movl 0x60(%rsp), %esi
callq 0x39f0
movq %rax, %rcx
movq 0x38(%rsp), %rax
movzbl (%rcx), %edx
movq 0x20(%rax), %rax
movslq 0x60(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0xcc(%rsp), %eax
movl %eax, 0x1c(%rsp)
testl %eax, %eax
je 0x3148
jmp 0x312f
movl 0x1c(%rsp), %eax
subl $0x1, %eax
je 0x3175
jmp 0x313a
movl 0x1c(%rsp), %eax
subl $0x2, %eax
je 0x31a2
jmp 0x31cd
movq 0x38(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x60(%rsp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x27a0
movq %rax, %rdx
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x60(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x31cd
movq 0x38(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x60(%rsp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x2870
movq %rax, %rdx
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x60(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x31cd
movq 0x38(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x60(%rsp), %rcx
movl (%rax,%rcx,4), %edi
callq 0x2940
movq %rax, %rdx
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x60(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0xc0(%rsp), %rdi
callq 0x39e0
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, %rdx
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x60(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0xc0(%rsp), %rdi
movl 0x60(%rsp), %esi
callq 0x39f0
movq %rax, 0x58(%rsp)
movl $0x0, 0x54(%rsp)
movq 0x38(%rsp), %rcx
movl 0x54(%rsp), %eax
cmpl 0x4(%rcx), %eax
jge 0x3285
movq 0x38(%rsp), %rax
movq 0x58(%rsp), %rcx
movslq 0x54(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
cvtsi2sd %ecx, %xmm0
movsd 0x2dbb(%rip), %xmm1     # 0x6018
divsd %xmm1, %xmm0
movq 0x10(%rax), %rax
movslq 0x60(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x54(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x3230
jmp 0x3287
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x30e5
movq 0xc0(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x32c3
movq 0x10(%rsp), %rdi
callq 0x39a0
movq 0x10(%rsp), %rdi
movl $0x10, %esi
callq 0x2170
movq 0x88(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x32ef
movq 0x8(%rsp), %rdi
callq 0x39a0
movq 0x8(%rsp), %rdi
movl $0x10, %esi
callq 0x2170
addq $0xe8, %rsp
retq
movq 0x98(%rsp), %rdi
callq 0x2270
nopw %cs:(%rax,%rax)