// File: /workspace/github_cpp_makefile_star2_O1/wkohlenberg[P]simple_NN/src/mnist.cpp
// Function: readLabels(std::vector<int, std::allocator<int>>&, bool)
int readLabels(vector<int>&vLabels, bool training)
{
	string	filePath = "../database/";
	int samples = 0;

	if (training)
	{
		filePath.append("train-labels-idx1-ubyte");
		samples = 60000;
	}
	else
	{
		filePath.append("t10k-labels-idx1-ubyte");
		samples = 10000;
	}

	// Open the label file, training or test
	ifstream labelFile;
	labelFile.open(filePath.c_str());
	if (!labelFile.is_open())
	{
		cout << "Couldn't open or find the file." << endl;
		return 1;
	}

	// Read the header
	uint32_t magic;
	uint32_t nLabels;
	uint8_t label;
	labelFile.read(reinterpret_cast<char *>(&magic), sizeof(magic));
	labelFile.read(reinterpret_cast<char *>(&nLabels), sizeof(nLabels));

	if (!((endianSwap(magic) == 2049) && (endianSwap(nLabels) == samples)))
	{
		cout << "No corresponding header..." << endl;
		return 2;
	}

	for (int i = 0; i < samples; i++)
	{
		labelFile.read(reinterpret_cast<char *>(&label), sizeof(label));
		vLabels.push_back(int(label));
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x20(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x16ae(%rip), %rsi      # 0x6149
leaq 0x16b3(%rip), %rdx      # 0x6155
leaq 0x10(%rsp), %rdi
callq 0x3e42
testl %ebp, %ebp
je 0x4ac8
movl $0xea60, %ebp           # imm = 0xEA60
leaq 0x169a(%rip), %rsi      # 0x6156
leaq 0x10(%rsp), %rdi
callq 0x2340
jmp 0x4ade
movl $0x2710, %ebp           # imm = 0x2710
leaq 0x169a(%rip), %rsi      # 0x616e
leaq 0x10(%rsp), %rdi
callq 0x2340
leaq 0x30(%rsp), %rdi
callq 0x2200
movq 0x10(%rsp), %rsi
leaq 0x30(%rsp), %rdi
movl $0x8, %edx
callq 0x2120
leaq 0xa8(%rsp), %rdi
callq 0x2060
testb %al, %al
je 0x4ba9
leaq 0x30(%rsp), %rdi
leaq 0xc(%rsp), %rsi
movl $0x4, %edx
callq 0x2220
leaq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x4, %edx
callq 0x2220
cmpl $0x1080000, 0xc(%rsp)   # imm = 0x1080000
jne 0x4bf6
movl 0x8(%rsp), %eax
bswapl %eax
cmpl %ebp, %eax
jne 0x4bf6
leaq 0x30(%rsp), %r14
leaq 0x3(%rsp), %r15
leaq 0x4(%rsp), %r12
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2220
movzbl 0x3(%rsp), %eax
movl %eax, 0x4(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x4b93
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x4b9e
movq %rbx, %rdi
movq %r12, %rdx
callq 0x5130
decl %ebp
jne 0x4b64
xorl %ebx, %ebx
jmp 0x4c41
movq 0x4428(%rip), %rbx      # 0x8fd8
leaq 0x15ce(%rip), %rsi      # 0x6185
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq 0x43f6(%rip), %rdi      # 0x8fd8
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2150
jmp 0x4c41
movq 0x43db(%rip), %rbx      # 0x8fd8
leaq 0x15a1(%rip), %rsi      # 0x61a5
movl $0x1a, %edx
movq %rbx, %rdi
callq 0x2210
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq 0x43a9(%rip), %rdi      # 0x8fd8
callq 0x2030
movl $0x2, %ebx
movq %rax, %rdi
callq 0x2150
leaq 0x30(%rsp), %rdi
callq 0x2070
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x4c62
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
movl %ebx, %eax
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4c78
movq %rax, %rbx
jmp 0x4c90
jmp 0x4c83
jmp 0x4c83
jmp 0x4c83
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2070
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x4ca7
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x2310