// File: /workspace/github_cpp_makefile_star2_O3/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 0x16d6(%rip), %rsi      # 0x6179
leaq 0x16db(%rip), %rdx      # 0x6185
leaq 0x10(%rsp), %rdi
callq 0x3e4e
testl %ebp, %ebp
je 0x4ad0
movl $0xea60, %ebp           # imm = 0xEA60
leaq 0x16c2(%rip), %rsi      # 0x6186
leaq 0x10(%rsp), %rdi
callq 0x2340
jmp 0x4ae6
movl $0x2710, %ebp           # imm = 0x2710
leaq 0x16c2(%rip), %rsi      # 0x619e
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 0x4bb1
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 0x4bfe
movl 0x8(%rsp), %eax
bswapl %eax
cmpl %ebp, %eax
jne 0x4bfe
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 0x4b9b
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x4ba6
movq %rbx, %rdi
movq %r12, %rdx
callq 0x5136
decl %ebp
jne 0x4b6c
xorl %ebx, %ebx
jmp 0x4c49
movq 0x4420(%rip), %rbx      # 0x8fd8
leaq 0x15f6(%rip), %rsi      # 0x61b5
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 0x43ee(%rip), %rdi      # 0x8fd8
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2150
jmp 0x4c49
movq 0x43d3(%rip), %rbx      # 0x8fd8
leaq 0x15c9(%rip), %rsi      # 0x61d5
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 0x43a1(%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 0x4c6a
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 0x4c80
movq %rax, %rbx
jmp 0x4c98
jmp 0x4c8b
jmp 0x4c8b
jmp 0x4c8b
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x2070
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x4caf
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x2310