// File: Krymancer[P]Matrix-cpp/src/Matrix.cpp
// Function: Matrix::Matrix(char const*)
Matrix::Matrix(const char *fileName) {
    std::ifstream file_A(fileName);
    int colSize = 0;
    int rowSize = 0;
    std::string line_A;
    int idx = 0;
    double element_A;
    double *vector_A = nullptr;

    if (fileName == "Error") {
        std::cout << "The dimentions of Matrix are wrong for this operation!\n";
    } else {
        if (file_A.is_open() && file_A.good()) {
            // cout << "File A.txt is open. \n";
            while (getline(file_A, line_A)) {
                rowSize += 1;
                std::stringstream stream_A(line_A);
                colSize = 0;
                while (1) {
                    stream_A >> element_A;
                    if (!stream_A)
                        break;
                    colSize += 1;
                    double *tempArr = new double[idx + 1];
                    std::copy(vector_A, vector_A + idx, tempArr);
                    tempArr[idx] = element_A;
                    vector_A = tempArr;
                    idx += 1;
                }
            }
        } else {
            std::cout << " Failed to open.\n";
        }
    }
    int j;
    idx = 0;
    data.resize(rowSize);
    for (unsigned i = 0; i < data.size(); i++) {
        data[i].resize(colSize);
    }
    for (int i = 0; i < rowSize; i++) {
        for (j = 0; j < colSize; j++) {
            this->data[i][j] = vector_A[idx];
            idx++;
        }
    }
    cols = colSize;
    rows = rowSize;
    delete[] vector_A;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x460, %rsp            # imm = 0x460
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x418(%rbp)
addq $0x8, %rdi
movq %rdi, -0x410(%rbp)
callq 0x4e90
movq -0x10(%rbp), %rsi
leaq -0x218(%rbp), %rdi
movl $0x8, %edx
callq 0x2390
jmp 0x2695
movl $0x0, -0x228(%rbp)
movl $0x0, -0x22c(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x22b0
movl $0x0, -0x254(%rbp)
movq $0x0, -0x268(%rbp)
leaq 0xa997(%rip), %rax      # 0xd068
cmpq %rax, -0x10(%rbp)
jne 0x271f
movq 0x108fa(%rip), %rdi     # 0x12fd8
leaq 0xa989(%rip), %rsi      # 0xd06e
callq 0x21d0
jmp 0x26ec
jmp 0x2944
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x2b01
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
jmp 0x2ae9
leaq -0x218(%rbp), %rdi
callq 0x2300
movb %al, -0x419(%rbp)
jmp 0x2733
movb -0x419(%rbp), %al
testb $0x1, %al
jne 0x2742
jmp 0x292b
movq -0x218(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x218(%rbp,%rax), %rdi
callq 0x2340
movb %al, -0x41a(%rbp)
jmp 0x2762
movb -0x41a(%rbp), %al
testb $0x1, %al
jne 0x2771
jmp 0x292b
jmp 0x2773
leaq -0x218(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x2060
movq %rax, -0x428(%rbp)
jmp 0x278f
movq -0x428(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2280
movb %al, -0x429(%rbp)
jmp 0x27ad
movb -0x429(%rbp), %al
testb $0x1, %al
jne 0x27bc
jmp 0x2929
movl -0x22c(%rbp), %eax
incl %eax
movl %eax, -0x22c(%rbp)
movl $0x10, %edi
movl $0x8, %esi
callq 0x50a0
movl %eax, -0x430(%rbp)
jmp 0x27e1
movl -0x430(%rbp), %edx
leaq -0x3f0(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x22f0
jmp 0x27fc
movl $0x0, -0x228(%rbp)
jmp 0x2808
leaq -0x3f0(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x2190
jmp 0x281d
movq -0x3f0(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x3f0(%rbp,%rax), %rdi
callq 0x20c0
movb %al, -0x431(%rbp)
jmp 0x283d
movb -0x431(%rbp), %al
testb $0x1, %al
jne 0x2849
jmp 0x2871
jmp 0x2918
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x220(%rbp)
movl %eax, -0x224(%rbp)
leaq -0x3f0(%rbp), %rdi
callq 0x2160
jmp 0x2ae9
movl -0x228(%rbp), %eax
incl %eax
movl %eax, -0x228(%rbp)
movl -0x254(%rbp), %eax
incl %eax
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x2030
movq %rax, -0x440(%rbp)
jmp 0x28ad
movq -0x440(%rbp), %rax
movq %rax, -0x3f8(%rbp)
movq -0x268(%rbp), %rdi
movslq -0x254(%rbp), %rax
leaq (%rdi,%rax,8), %rsi
movq -0x3f8(%rbp), %rdx
callq 0x50c0
jmp 0x28db
movsd -0x260(%rbp), %xmm0
movq -0x3f8(%rbp), %rax
movslq -0x254(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x3f8(%rbp), %rax
movq %rax, -0x268(%rbp)
movl -0x254(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x254(%rbp)
jmp 0x2806
leaq -0x3f0(%rbp), %rdi
callq 0x2160
jmp 0x2773
jmp 0x2942
movq 0x106a6(%rip), %rdi     # 0x12fd8
leaq 0xa76d(%rip), %rsi      # 0xd0a6
callq 0x21d0
jmp 0x2940
jmp 0x2942
jmp 0x2944
movq -0x418(%rbp), %rdi
movl $0x0, -0x254(%rbp)
addq $0x8, %rdi
movslq -0x22c(%rbp), %rsi
callq 0x4eb0
jmp 0x2967
movl $0x0, -0x400(%rbp)
movq -0x418(%rbp), %rdi
movl -0x400(%rbp), %eax
movq %rax, -0x448(%rbp)
addq $0x8, %rdi
callq 0x4f40
movq %rax, %rcx
movq -0x448(%rbp), %rax
cmpq %rcx, %rax
jae 0x29d9
movq -0x418(%rbp), %rdi
addq $0x8, %rdi
movl -0x400(%rbp), %eax
movl %eax, %esi
callq 0x4f70
movq %rax, %rdi
movslq -0x228(%rbp), %rsi
callq 0x5100
jmp 0x29c6
jmp 0x29c8
movl -0x400(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x400(%rbp)
jmp 0x2971
movl $0x0, -0x404(%rbp)
movl -0x404(%rbp), %eax
cmpl -0x22c(%rbp), %eax
jge 0x2a90
movl $0x0, -0x3fc(%rbp)
movl -0x3fc(%rbp), %eax
cmpl -0x228(%rbp), %eax
jge 0x2a7a
movq -0x418(%rbp), %rdi
movq -0x268(%rbp), %rax
movslq -0x254(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x450(%rbp)
addq $0x8, %rdi
movslq -0x404(%rbp), %rsi
callq 0x4f70
movq %rax, %rdi
movslq -0x3fc(%rbp), %rsi
callq 0x5190
movsd -0x450(%rbp), %xmm0
movsd %xmm0, (%rax)
movl -0x254(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x254(%rbp)
movl -0x3fc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3fc(%rbp)
jmp 0x29ff
jmp 0x2a7c
movl -0x404(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x404(%rbp)
jmp 0x29e3
movq -0x418(%rbp), %rax
movl -0x228(%rbp), %ecx
movl %ecx, 0x4(%rax)
movl -0x22c(%rbp), %ecx
movl %ecx, (%rax)
movq -0x268(%rbp), %rax
movq %rax, -0x458(%rbp)
cmpq $0x0, %rax
je 0x2ac8
movq -0x458(%rbp), %rdi
callq 0x2290
leaq -0x250(%rbp), %rdi
callq 0x2100
leaq -0x218(%rbp), %rdi
callq 0x2070
addq $0x460, %rsp            # imm = 0x460
popq %rbp
retq
leaq -0x250(%rbp), %rdi
callq 0x2100
leaq -0x218(%rbp), %rdi
callq 0x2070
movq -0x410(%rbp), %rdi
callq 0x5040
movq -0x220(%rbp), %rdi
callq 0x2350
nopl (%rax)