// File: /workspace/github_cpp_makefile_star2_O2/btbujiangjun[P]abcdl/include/utils/ModelLoader.h
// Function: bool abcdl::utils::ModelLoader::read<float>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<abcdl::algebra::Matrix<float>*, std::allocator<abcdl::algebra::Matrix<float>*>>*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
bool ModelLoader::read(const std::string& path,
                       std::vector<abcdl::algebra::Matrix<T>*>* models,
                       const std::string& signature){
    //std::ifstream in_file(path, std::ios::binary);
    std::ifstream in_file(path, std::ios::in);
    if(!in_file){
        LOG(FATAL) << "Can't open Filename:" + path;
        return false;
    }

    size_t num_models = 0;
    std::string read_signature(signature.size(), ' ');

    in_file >> read_signature;
    //in_file.read(&read_signature[0], sizeof(char) * signature.size());
    if(read_signature != signature){
        LOG(FATAL) << "ModelLoader read model error:[signature error]";
        in_file.close();
        return false;
    }

    //in_file.read((char*)(&num_models), sizeof(size_t));
    in_file >> num_models;

    std::vector<ModelInfo> infos;
    for(size_t i = 0; i != num_models; i++){
        ModelInfo info;
        //in_file.read(&info.type, sizeof(char));
        //in_file.read((char*)(&info.rows), sizeof(size_t));
        //in_file.read((char*)(&info.cols), sizeof(size_t));
        in_file >> info.type;
        in_file >> info.rows;
        in_file >> info.cols;
        infos.push_back(info);
    }

    models->clear();
    for(size_t i = 0; i != num_models; i++){
        ModelInfo info = infos[i];
        size_t size      = info.rows * info.cols;
        
        T* data = new T[size];
        //in_file.read((char*)data, sizeof(T) * size);
        for(size_t j = 0; j < size; j++){
            in_file >> data[j];
        }
        auto mat = new abcdl::algebra::Matrix<T>();
        mat->set_shallow_data(data, info.rows, info.cols);
        models->push_back(mat);
    }

    in_file.close();
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3f8, %rsp            # imm = 0x3F8
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
leaq 0x1f0(%rsp), %r12
pushq $0x8
popq %rdx
movq %r12, %rdi
callq 0x9560
movq (%r12), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x210(%rsp,%rax)
je 0x1592c
leaq 0x1caf1(%rip), %rsi     # 0x323cd
leaq 0x60(%rsp), %rdi
pushq $0x3
popq %rcx
movl $0xa0, %edx
callq 0x2ee18
leaq 0x1caf4(%rip), %rsi     # 0x323e9
leaq 0x20(%rsp), %rdi
movq %r15, %rdx
callq 0x164d1
leaq 0x60(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x9320
leaq 0x20(%rsp), %rdi
callq 0x9160
leaq 0x60(%rsp), %rdi
callq 0x2f054
xorl %ebx, %ebx
jmp 0x15b29
movq %r14, 0x18(%rsp)
andq $0x0, 0x8(%rsp)
movq 0x8(%rbx), %rsi
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x20(%rsp), %rdi
pushq $0x20
popq %rdx
callq 0x93b0
leaq 0x1f0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x9400
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x16547
movl %eax, %ebx
testb %al, %al
je 0x159bc
leaq 0x1ca50(%rip), %rsi     # 0x323cd
leaq 0x60(%rsp), %rdi
pushq $0x3
popq %rcx
movl $0xaa, %edx
callq 0x2ee18
leaq 0x1ca68(%rip), %rsi     # 0x323fe
leaq 0x60(%rsp), %rdi
callq 0x9370
leaq 0x60(%rsp), %rdi
callq 0x2f054
leaq 0x1f0(%rsp), %rdi
callq 0x9080
jmp 0x15b1c
leaq 0x1f0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x91d0
movl %ebx, 0x14(%rsp)
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0x50(%rsp), %r14
leaq 0x58(%rsp), %r12
xorl %r15d, %r15d
leaq 0x1f0(%rsp), %r13
leaq 0x48(%rsp), %rbp
cmpq 0x8(%rsp), %r15
je 0x15a34
movq %r13, %rdi
movq %rbp, %rsi
callq 0x9440
movq %r13, %rdi
movq %r14, %rsi
callq 0x91d0
movq %r13, %rdi
movq %r12, %rsi
callq 0x91d0
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x16552
incq %r15
jmp 0x159fc
movq 0x18(%rsp), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0x15a46
movq %rax, 0x8(%rcx)
xorl %ecx, %ecx
leaq 0x1f0(%rsp), %r13
cmpq %r15, %rcx
je 0x15b01
movq 0x60(%rsp), %rax
movq %rcx, 0x40(%rsp)
imulq $0x18, %rcx, %rcx
movq 0x8(%rax,%rcx), %rbp
movq 0x10(%rax,%rcx), %r14
movq %r14, %rbx
imulq %rbp, %rbx
movq %rbx, %rax
shrq $0x3e, %rax
leaq (,%rbx,4), %rcx
negq %rax
movl $0x0, %edi
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0x9030
movq %rax, %r12
movq %rax, %r15
subq $0x1, %rbx
jb 0x15ab7
movq %r13, %rdi
movq %r15, %rsi
callq 0x9690
addq $0x4, %r15
jmp 0x15aa0
pushq $0x28
popq %rdi
callq 0x9380
movq %rax, %r15
movq %rax, %rdi
callq 0x17dac
movq %r15, 0x48(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r14, %rcx
callq 0x1823e
movq 0x18(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x16578
movq 0x40(%rsp), %rcx
incq %rcx
movq 0x8(%rsp), %r15
jmp 0x15a50
leaq 0x1f0(%rsp), %rdi
callq 0x9080
leaq 0x60(%rsp), %rdi
callq 0x16860
movl 0x14(%rsp), %ebx
xorb $0x1, %bl
leaq 0x20(%rsp), %rdi
callq 0x9160
leaq 0x1f0(%rsp), %rdi
callq 0x90a0
movl %ebx, %eax
addq $0x3f8, %rsp            # imm = 0x3F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x15b9a
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x2f054
jmp 0x15ba7
jmp 0x15b82
jmp 0x15b7d
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x9160
jmp 0x15b71
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x2f054
jmp 0x15bb1
movq %rax, %rbx
jmp 0x15bb1
movq %rax, %rbx
jmp 0x15ba7
movq %rax, %rbx
movq %r15, %rdi
callq 0x9360
jmp 0x15b9d
jmp 0x15b9a
jmp 0x15b9a
jmp 0x15b9a
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x16860
leaq 0x20(%rsp), %rdi
callq 0x9160
leaq 0x1f0(%rsp), %rdi
callq 0x90a0
movq %rbx, %rdi
callq 0x95e0