// File: /workspace/github_cpp_makefile_star2_O1/ghulette[P]neural-net-openmp/idx.cpp
// Function: IdxData::IdxData(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
IdxData::IdxData(std::string file) {
	using namespace std;
	
	cout << "Reading IDX file: " << file << endl;
	
	ifstream ifs(file.c_str(), ios::in | ios::binary);
	if(ifs.is_open()) {
		int magic = read_int(ifs);
		int num_dims = (magic - 0x800) - 1;
		n_records = read_int(ifs);
		record_len = 1;
		for(int i=0; i < num_dims; i++) {
			record_len *= read_int(ifs);
		}
		//cout << "  found " << n_records << " records of size " << record_len << endl;
		data = new unsigned char[n_records * record_len];
		for(int i=0; i < n_records; i++) {
			ifs.read((char *)&data[i * record_len], record_len);
			if(ifs.bad()) {
				cerr << "Error reading data" << endl;
			}
		}
		ifs.close();
	}
	else cerr << "Could not open file " << file << endl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x210, %rsp            # imm = 0x210
movq %rsi, %r14
movq %rdi, %rbx
movq 0x3c48(%rip), %r15      # 0x6fd0
leaq 0x1db9(%rip), %rsi      # 0x5148
movl $0x12, %edx
movq %r15, %rdi
callq 0x2150
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq %r15, %rdi
callq 0x2150
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20b0
movq (%r14), %rsi
leaq 0x8(%rsp), %rdi
movl $0xc, %edx
callq 0x21f0
leaq 0x80(%rsp), %rdi
callq 0x2060
testb %al, %al
je 0x3510
leaq 0x8(%rsp), %rdi
leaq 0x4(%rsp), %rsi
movl $0x4, %edx
callq 0x2170
leaq 0x4(%rsp), %rsi
movl (%rsi), %ebp
leaq 0x8(%rsp), %rdi
movl $0x4, %edx
callq 0x2170
bswapl %ebp
movl 0x4(%rsp), %eax
bswapl %eax
movl %eax, 0x8(%rbx)
movl $0x1, 0xc(%rbx)
cmpl $0x802, %ebp            # imm = 0x802
jl 0x3471
addl $0xfffff7ff, %ebp       # imm = 0xFFFFF7FF
leaq 0x8(%rsp), %r14
leaq 0x4(%rsp), %r15
movl $0x4, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2170
movl 0x4(%rsp), %eax
bswapl %eax
imull 0xc(%rbx), %eax
movl %eax, 0xc(%rbx)
decl %ebp
jne 0x3450
movslq 0x8(%rbx), %rax
movslq 0xc(%rbx), %rdi
imulq %rax, %rdi
callq 0x2030
movq %rax, (%rbx)
cmpl $0x0, 0x8(%rbx)
jle 0x3504
xorl %ebp, %ebp
leaq 0x8(%rsp), %r14
movq 0x3b57(%rip), %r15      # 0x6ff0
leaq 0x1cbb(%rip), %r12      # 0x515b
movslq 0xc(%rbx), %rdx
movslq %ebp, %rsi
imulq %rdx, %rsi
addq (%rbx), %rsi
movq %r14, %rdi
callq 0x2170
movq 0x8(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x1, 0x28(%rsp,%rax)
je 0x34fd
movl $0x12, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2150
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20b0
incl %ebp
cmpl 0x8(%rbx), %ebp
jl 0x34a0
leaq 0x8(%rsp), %rdi
callq 0x2050
jmp 0x3565
movq 0x3ad9(%rip), %rdi      # 0x6ff0
leaq 0x1c50(%rip), %rsi      # 0x516e
movl $0x14, %edx
callq 0x2150
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x3aba(%rip), %rdi      # 0x6ff0
callq 0x2150
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20b0
leaq 0x8(%rsp), %rdi
callq 0x2070
addq $0x210, %rsp            # imm = 0x210
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3587
jmp 0x3587
jmp 0x3587
jmp 0x3587
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x21c0