// File: /workspace/github_cpp_makefile_star2_O3/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 $0x3e8, %rsp            # imm = 0x3E8
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r15
leaq 0x1e0(%rsp), %r12
movq %r12, %rdi
movl $0x8, %edx
callq 0x9550
movq (%r12), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x200(%rsp,%rax)
je 0x16f06
leaq 0x25547(%rip), %rsi     # 0x3c3ed
leaq 0x50(%rsp), %rdi
movl $0xa0, %edx
movl $0x3, %ecx
callq 0x387b6
leaq 0x25548(%rip), %rsi     # 0x3c409
leaq 0x8(%rsp), %rdi
movq %r15, %rdx
callq 0x17da9
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x50(%rsp), %rdi
callq 0x93b0
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x16ef5
callq 0x9350
leaq 0x50(%rsp), %rdi
callq 0x389de
xorl %ebx, %ebx
jmp 0x17174
movq $0x0, (%rsp)
movq 0x8(%r14), %rsi
leaq 0x18(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x8(%rsp), %rdi
movl $0x20, %edx
callq 0x93c0
leaq 0x1e0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x9400
movq 0x10(%rsp), %rdx
cmpq 0x8(%r14), %rdx
jne 0x16f5d
testq %rdx, %rdx
je 0x16fac
movq (%r14), %rsi
movq 0x8(%rsp), %rdi
callq 0x9380
testl %eax, %eax
je 0x16fac
leaq 0x25489(%rip), %rsi     # 0x3c3ed
leaq 0x50(%rsp), %rdi
movl $0xaa, %edx
movl $0x3, %ecx
callq 0x387b6
leaq 0x2549f(%rip), %rsi     # 0x3c41e
leaq 0x50(%rsp), %rdi
movl $0x2e, %edx
callq 0x93b0
leaq 0x50(%rsp), %rdi
callq 0x389de
leaq 0x1e0(%rsp), %rdi
callq 0x9090
xorl %ebx, %ebx
jmp 0x17165
leaq 0x1e0(%rsp), %rdi
movq %rsp, %rsi
callq 0x91c0
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
cmpq $0x0, (%rsp)
movq %rbx, 0x28(%rsp)
je 0x17062
leaq 0x38(%rsp), %r14
leaq 0x40(%rsp), %r15
xorl %ebx, %ebx
leaq 0x1e0(%rsp), %r12
leaq 0x30(%rsp), %r13
leaq 0x50(%rsp), %rbp
movq %r12, %rdi
movq %r13, %rsi
callq 0x9430
movq %r12, %rdi
movq %r14, %rsi
callq 0x91c0
movq %r12, %rdi
movq %r15, %rsi
callq 0x91c0
movq 0x58(%rsp), %rsi
cmpq 0x60(%rsp), %rsi
je 0x17041
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsi)
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x18, 0x58(%rsp)
jmp 0x1704c
movq %rbp, %rdi
movq %r13, %rdx
callq 0x17e2a
incq %rbx
cmpq (%rsp), %rbx
jne 0x16ffb
testq %rbx, %rbx
sete %al
movq 0x28(%rsp), %rbx
jmp 0x17064
movb $0x1, %al
movq (%rbx), %rcx
cmpq %rcx, 0x8(%rbx)
je 0x17071
movq %rcx, 0x8(%rbx)
testb %al, %al
jne 0x17142
xorl %ebx, %ebx
leaq 0x1e0(%rsp), %r15
movq 0x50(%rsp), %rax
leaq (%rbx,%rbx,2), %rcx
movq 0x8(%rax,%rcx,8), %r12
movq 0x10(%rax,%rcx,8), %r13
movq %r13, 0x48(%rsp)
imulq %r12, %r13
movq %r13, %rax
shrq $0x3e, %rax
leaq (,%r13,4), %rcx
negq %rax
movl $0x0, %edi
sbbq %rdi, %rdi
orq %rcx, %rdi
callq 0x9030
movq %rax, %r14
movq %rax, %rbp
testq %r13, %r13
je 0x170e0
movq %r15, %rdi
movq %rbp, %rsi
callq 0x9670
addq $0x4, %rbp
decq %r13
jne 0x170cc
movl $0x28, %edi
callq 0x9370
movq %rax, %rbp
movq %rax, %rdi
callq 0x197e0
movq %rbp, 0x30(%rsp)
movq %rbp, %rdi
movq %r14, %rsi
movq %r12, %rdx
movq 0x48(%rsp), %rcx
callq 0x19db2
movq 0x28(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x1712b
movq 0x30(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x17135
leaq 0x30(%rsp), %rdx
callq 0x17f98
incq %rbx
cmpq (%rsp), %rbx
jne 0x17083
leaq 0x1e0(%rsp), %rdi
callq 0x9090
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
leaq 0x18(%rsp), %r15
je 0x17163
callq 0x9350
movb $0x1, %bl
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
je 0x17174
callq 0x9350
leaq 0x1e0(%rsp), %rdi
callq 0x90b0
movl %ebx, %eax
addq $0x3e8, %rsp            # imm = 0x3E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x171ee
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x389de
jmp 0x17200
jmp 0x171d6
jmp 0x171d1
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x171c5
callq 0x9350
jmp 0x171c5
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x389de
jmp 0x17214
movq %rax, %rbx
jmp 0x17214
movq %rax, %rbx
jmp 0x17200
movq %rax, %rbx
movq %rbp, %rdi
callq 0x9350
jmp 0x171f1
jmp 0x171ee
jmp 0x171ee
jmp 0x171ee
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x17200
callq 0x9350
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x17214
callq 0x9350
leaq 0x1e0(%rsp), %rdi
callq 0x90b0
movq %rbx, %rdi
callq 0x95d0
nop