// File: btbujiangjun[P]abcdl/include/utils/MnistHelper.h
// Function: abcdl::utils::MnistHelper<float>::read_vec_labels(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, abcdl::algebra::MatrixSet<float>&, int, unsigned long)
bool MnistHelper<T>::read_vec_labels(const std::string& label_file,
                                     abcdl::algebra::MatrixSet<T>& out_matrix_set,
                                     const int limit,
                                     const size_t vec_size){
    size_t count = 0;
    auto label_buffer = read_mnist_file(label_file, 0x801, &count);
    if(!label_buffer || count == 0){
        return false;
    }

    if( limit > 0 && limit < (int)count){
        count = limit;
    }

    //read label data
    auto label_data_buffer = reinterpret_cast<unsigned char*>(label_buffer.get() + 8);

    T* labels = new T[vec_size];
    for(size_t i = 0; i < count; i++){
        memset(labels, 0, sizeof(T) * vec_size);
        auto label = static_cast<size_t>(*label_data_buffer++);
        labels[label] = 1;
        out_matrix_set.push_back(abcdl::algebra::Matrix<T>(labels, 1, vec_size));
    }
    delete[] labels;

    return true;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movq %rsi, 0xa0(%rsp)
movq %rdx, 0x98(%rsp)
movl %ecx, 0x94(%rsp)
movq %r8, 0x88(%rsp)
movq 0xa8(%rsp), %rsi
movq $0x0, 0x80(%rsp)
movq 0xa0(%rsp), %rdx
leaq 0x78(%rsp), %rdi
movl $0x801, %ecx            # imm = 0x801
leaq 0x80(%rsp), %r8
callq 0x18db0
leaq 0x78(%rsp), %rdi
callq 0x192c0
testb $0x1, %al
jne 0x1a651
jmp 0x1a65c
cmpq $0x0, 0x80(%rsp)
jne 0x1a671
movb $0x0, 0xb7(%rsp)
movl $0x1, 0x74(%rsp)
jmp 0x1a7ed
cmpl $0x0, 0x94(%rsp)
jle 0x1a69e
movl 0x94(%rsp), %eax
movq 0x80(%rsp), %rcx
cmpl %ecx, %eax
jge 0x1a69e
movslq 0x94(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x19350
addq $0x8, %rax
movq %rax, 0x68(%rsp)
movq 0x88(%rsp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x9030
movq %rax, 0x10(%rsp)
jmp 0x1a6db
movq 0x10(%rsp), %rax
movq %rax, 0x60(%rsp)
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %rax
cmpq 0x80(%rsp), %rax
jae 0x1a7c5
movq 0x60(%rsp), %rdi
movq 0x88(%rsp), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x9210
movq 0x68(%rsp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, 0x68(%rsp)
movzbl (%rax), %eax
movq %rax, 0x40(%rsp)
movq 0x60(%rsp), %rax
movq 0x40(%rsp), %rcx
movl $0x3f800000, (%rax,%rcx,4) # imm = 0x3F800000
movq 0x98(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %rsi
movq 0x88(%rsp), %rcx
leaq 0x18(%rsp), %rdi
movl $0x1, %edx
callq 0x33d20
jmp 0x1a76d
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x19390
jmp 0x1a77e
leaq 0x18(%rsp), %rdi
callq 0x33e80
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x1a6ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0x1a808
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x33e80
jmp 0x1a808
movq 0x60(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x1a7dd
movq (%rsp), %rdi
callq 0x9540
movb $0x1, 0xb7(%rsp)
movl $0x1, 0x74(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x19470
movb 0xb7(%rsp), %al
andb $0x1, %al
addq $0xb8, %rsp
retq
leaq 0x78(%rsp), %rdi
callq 0x19470
movq 0x58(%rsp), %rdi
callq 0x9700
nopl (%rax)