// File: 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:
subq $0x658, %rsp            # imm = 0x658
movq %rdi, 0x648(%rsp)
movq %rsi, 0x640(%rsp)
movq %rdx, 0x638(%rsp)
movq %rcx, 0x630(%rsp)
movq 0x640(%rsp), %rsi
leaq 0x428(%rsp), %rdi
movl $0x8, %edx
callq 0x9660
movq 0x428(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x428(%rsp,%rax), %rdi
callq 0x91b0
movb %al, 0x2f(%rsp)
jmp 0x2c300
movb 0x2f(%rsp), %al
testb $0x1, %al
jne 0x2c30d
jmp 0x2c3f6
leaq 0x64099(%rip), %rsi     # 0x903ad
leaq 0x290(%rsp), %rdi
movl $0xa0, %edx
movl $0x3, %ecx
callq 0x89860
jmp 0x2c32d
movq 0x640(%rsp), %rdx
leaq 0x6408d(%rip), %rsi     # 0x903c9
leaq 0x270(%rsp), %rdi
callq 0x2f5a0
jmp 0x2c34b
leaq 0x290(%rsp), %rdi
leaq 0x270(%rsp), %rsi
callq 0x2c230
jmp 0x2c362
leaq 0x270(%rsp), %rdi
callq 0x9260
leaq 0x290(%rsp), %rdi
callq 0x89c20
movb $0x0, 0x657(%rsp)
movl $0x1, 0x26c(%rsp)
jmp 0x2c7e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x420(%rsp)
movl %eax, 0x41c(%rsp)
jmp 0x2c800
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x420(%rsp)
movl %eax, 0x41c(%rsp)
jmp 0x2c3e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x420(%rsp)
movl %eax, 0x41c(%rsp)
leaq 0x270(%rsp), %rdi
callq 0x9260
leaq 0x290(%rsp), %rdi
callq 0x89c20
jmp 0x2c800
movq $0x0, 0x260(%rsp)
movq 0x630(%rsp), %rdi
callq 0x92a0
movq %rax, 0x18(%rsp)
leaq 0x23f(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x9710
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rcx
leaq 0x240(%rsp), %rdi
movl $0x20, %edx
callq 0x9280
jmp 0x2c444
leaq 0x23f(%rsp), %rdi
callq 0x9470
leaq 0x428(%rsp), %rdi
leaq 0x240(%rsp), %rsi
callq 0x9510
jmp 0x2c468
movq 0x630(%rsp), %rsi
leaq 0x240(%rsp), %rdi
callq 0x2f6d0
testb $0x1, %al
jne 0x2c486
jmp 0x2c555
leaq 0x63f20(%rip), %rsi     # 0x903ad
leaq 0xb0(%rsp), %rdi
movl $0xaa, %edx
movl $0x3, %ecx
callq 0x89860
jmp 0x2c4a6
leaq 0x63f31(%rip), %rsi     # 0x903de
leaq 0xb0(%rsp), %rdi
callq 0x2f700
jmp 0x2c4bc
leaq 0xb0(%rsp), %rdi
callq 0x89c20
leaq 0x428(%rsp), %rdi
callq 0x90b0
jmp 0x2c4d8
movb $0x0, 0x657(%rsp)
movl $0x1, 0x26c(%rsp)
jmp 0x2c7c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x420(%rsp)
movl %eax, 0x41c(%rsp)
leaq 0x23f(%rsp), %rdi
callq 0x9470
jmp 0x2c800
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x420(%rsp)
movl %eax, 0x41c(%rsp)
jmp 0x2c7d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x420(%rsp)
movl %eax, 0x41c(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x89c20
jmp 0x2c7d3
leaq 0x428(%rsp), %rdi
leaq 0x260(%rsp), %rsi
callq 0x95d0
jmp 0x2c56c
leaq 0x98(%rsp), %rdi
callq 0x2f730
movq $0x0, 0x90(%rsp)
movq 0x90(%rsp), %rax
cmpq 0x260(%rsp), %rax
je 0x2c625
leaq 0x428(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x9560
jmp 0x2c5af
leaq 0x80(%rsp), %rsi
leaq 0x428(%rsp), %rdi
callq 0x95d0
jmp 0x2c5c6
leaq 0x88(%rsp), %rsi
leaq 0x428(%rsp), %rdi
callq 0x95d0
jmp 0x2c5dd
leaq 0x98(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x2f740
jmp 0x2c5f1
jmp 0x2c5f3
movq 0x90(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x90(%rsp)
jmp 0x2c585
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x420(%rsp)
movl %eax, 0x41c(%rsp)
jmp 0x2c7b5
movq 0x638(%rsp), %rdi
callq 0x2c940
movq $0x0, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpq 0x260(%rsp), %rax
je 0x2c784
movq 0x70(%rsp), %rsi
leaq 0x98(%rsp), %rdi
callq 0x2f7b0
movq 0x10(%rax), %rcx
movq %rcx, 0x60(%rsp)
movups (%rax), %xmm0
movaps %xmm0, 0x50(%rsp)
movq 0x58(%rsp), %rax
movq 0x60(%rsp), %rcx
imulq %rcx, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x9030
movq %rax, 0x10(%rsp)
jmp 0x2c6ab
movq 0x10(%rsp), %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x48(%rsp), %rax
jae 0x2c6f9
movq 0x40(%rsp), %rax
movq 0x38(%rsp), %rcx
leaq (%rax,%rcx,4), %rsi
leaq 0x428(%rsp), %rdi
callq 0x90a0
jmp 0x2c6e7
jmp 0x2c6e9
movq 0x38(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x38(%rsp)
jmp 0x2c6be
movl $0x28, %edi
callq 0x9430
movq %rax, 0x8(%rsp)
jmp 0x2c70a
movq 0x8(%rsp), %rdi
callq 0x33a40
jmp 0x2c716
movq 0x8(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
callq 0x34360
jmp 0x2c73b
movq 0x638(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2f7d0
jmp 0x2c74f
jmp 0x2c751
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x2c63b
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x420(%rsp)
movl %eax, 0x41c(%rsp)
callq 0x9410
jmp 0x2c7b5
leaq 0x428(%rsp), %rdi
callq 0x90b0
jmp 0x2c793
movb $0x1, 0x657(%rsp)
movl $0x1, 0x26c(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x2f840
jmp 0x2c7c4
leaq 0x98(%rsp), %rdi
callq 0x2f840
jmp 0x2c7d3
leaq 0x240(%rsp), %rdi
callq 0x9260
jmp 0x2c7e2
leaq 0x240(%rsp), %rdi
callq 0x9260
jmp 0x2c800
leaq 0x428(%rsp), %rdi
callq 0x90e0
movb 0x657(%rsp), %al
andb $0x1, %al
addq $0x658, %rsp            # imm = 0x658
retq
leaq 0x428(%rsp), %rdi
callq 0x90e0
movq 0x420(%rsp), %rdi
callq 0x9700
nopw (%rax,%rax)