// File: /workspace/github_cpp_makefile_star2_O2/bothaynahazem[P]AsuMathLabG13/Matrix2017.cpp
// Function: Matrix::copy(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Matrix::copy(string s)
{
	if (s.find('i') != -1 || s.find('I') != -1)
	{
		reset();
		values = NULL;
		char* buffer = new char[s.length() + 1];
		strncpy(buffer, s.c_str(), s.length() + 1); //copying the input string to a buffer because strtok will destruct it.

		const char* lineSeparators = ";\r\n"; //separators used to indicate a ln has been terminated
		char* line = strtok(buffer, lineSeparators); //tokenizes the first ln
		char* Remainlines = strtok(NULL, ""); //tokenizes the remaining lns

		while (line) //line here is my token
		{
			Matrix row; //empty matrix
			row.type = type;
			const char* separators = " []"; //row separator is space
											//while [] are used for the first and last rows only (as they have to be removed)
			char* token = strtok(line, separators); //tokenizes the line into numbers (still in a string form)

			while (token) //the token here is the ln I'm extracting numbers from
			{
				const complex<double> token_value = complex_parser(token); //converts the tokens into doubles

				Matrix item;
				item = (const complex<double>)token_value; //filling the matrix with numbers
				row.addColumn(item); //add each item in its correct column in the (row) matrix

				token = strtok(NULL, separators); //gets the next token (or number in our case)

			}

			if ((row.nColumns>0) && (row.nColumns == nColumns || nRows == 0)) //if there were no rows before in the "this" matrix
				addRow(row); //add this row to "this"
if(row.nColumns!=this->nColumns)
    {
        throw("Invalid Matrix Dimensions");
    }
			line = strtok(Remainlines, lineSeparators); //tokenizing the next ln
			Remainlines = strtok(NULL, ""); //tokenizing the ln next to it
		}

		delete[] buffer;
	}
	else {
		reset();

		char* buffer = new char[s.length() + 1];
		strncpy(buffer, s.c_str(), s.length() + 1); //copying the input string to a buffer because strtok will destruct it.

		const char* lineSeparators = ";\r\n"; //separators used to indicate a ln has been terminated
		char* line = strtok(buffer, lineSeparators); //tokenizes the first ln
		char* Remainlines = strtok(NULL, ""); //tokenizes the remaining lns

		while (line) //line here is my token
		{
			Matrix row; //empty matrix
			const char* separators = " []"; //row separator is space
											//while [] are used for the first and last rows only (as they have to be removed)
			char* token = strtok(line, separators); //tokenizes the line into numbers (still in a string form)

			while (token) //the token here is the ln I'm extracting numbers from
			{
				const double token_value = atof(token); //converts the tokens into doubles

				Matrix item;
				item = (const double)token_value; //filling the matrix with numbers
				row.addColumn(item); //add each item in its correct column in the (row) matrix

				token = strtok(NULL, separators); //gets the next token (or number in our case)

			}

			if ((row.nColumns>0) && (row.nColumns == nColumns || nRows == 0)) //if there were no rows before in the "this" matrix
				addRow(row); //add this row to "this"
if(row.nColumns!=this->nColumns)
    {
        throw("Invalid Matrix Dimensions");
    }
			line = strtok(Remainlines, lineSeparators); //tokenizing the next ln
			Remainlines = strtok(NULL, ""); //tokenizing the ln next to it
		}

		delete[] buffer;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rsi, %rbx
movq %rdi, %r14
pushq $0x69
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x33e0
cmpq $-0x1, %rax
movq %r14, -0x30(%rbp)
jne 0x909a
pushq $0x49
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x33e0
cmpq $-0x1, %rax
je 0x9230
movq %r14, %rdi
callq 0x8a44
andq $0x0, 0x8(%r14)
movq %r14, %r15
movq 0x8(%rbx), %r14
incq %r14
movq %r14, %rdi
callq 0x3030
movq %rax, %r12
movq (%rbx), %rsi
movq %rax, %rdi
movq %r14, %rdx
callq 0x31d0
leaq 0x612c(%rip), %rsi      # 0xf1fd
movq %r12, -0x48(%rbp)
movq %r12, %rdi
callq 0x3470
movq %rax, %r12
leaq 0x613b(%rip), %rsi      # 0xf222
xorl %edi, %edi
callq 0x3470
movq %rax, -0x50(%rbp)
leaq 0x18(%r15), %rax
movq %rax, -0x58(%rbp)
leaq -0x90(%rbp), %r15
leaq -0xe8(%rbp), %r14
leaq -0xc8(%rbp), %r13
leaq -0x158(%rbp), %rbx
testq %r12, %r12
je 0x9376
movq %r15, %rdi
callq 0x89d6
leaq -0x78(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x3200
movq %r12, %rdi
leaq 0x60c3(%rip), %rsi      # 0xf201
callq 0x3470
movq %rax, %r12
testq %r12, %r12
je 0x91be
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x7844
movq %r14, %rdi
callq 0x94ea
movsd %xmm1, -0x38(%rbp)
movsd %xmm0, -0x40(%rbp)
movq %r14, %rdi
callq 0x3170
movq %r13, %rdi
callq 0x89d6
movq %rbx, %rdi
movq %r13, %rsi
movsd -0x40(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
callq 0x979c
movq %rbx, %rdi
callq 0x8a24
movq %r15, %rdi
movq %r13, %rsi
callq 0x97c4
xorl %edi, %edi
leaq 0x6055(%rip), %rsi      # 0xf201
callq 0x3470
movq %rax, %r12
movq %r13, %rdi
callq 0x8a24
jmp 0x9146
movl -0x8c(%rbp), %eax
movq -0x30(%rbp), %rcx
movl 0x4(%rcx), %ecx
testl %eax, %eax
jle 0x91f6
cmpl %ecx, %eax
je 0x91dc
movq -0x30(%rbp), %rdx
cmpl $0x0, (%rdx)
jne 0x91f6
movq -0x30(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x9914
movl -0x8c(%rbp), %eax
movl 0x4(%r12), %ecx
cmpl %ecx, %eax
jne 0x9391
movq -0x50(%rbp), %rdi
leaq 0x5ff4(%rip), %rsi      # 0xf1fd
callq 0x3470
movq %rax, %r12
xorl %edi, %edi
leaq 0x6008(%rip), %rsi      # 0xf222
callq 0x3470
movq %rax, -0x50(%rbp)
movq %r15, %rdi
callq 0x8a24
jmp 0x9116
movq %r14, %rdi
callq 0x8a44
movq 0x8(%rbx), %r14
incq %r14
movq %r14, %rdi
callq 0x3030
movq %rax, %r15
movq (%rbx), %rsi
movq %rax, %rdi
movq %r14, %rdx
callq 0x31d0
leaq 0x5f9e(%rip), %rsi      # 0xf1fd
movq %r15, -0x48(%rbp)
movq %r15, %rdi
callq 0x3470
movq %rax, %r14
leaq 0x5fad(%rip), %rsi      # 0xf222
xorl %edi, %edi
callq 0x3470
movq %rax, -0x38(%rbp)
leaq -0x90(%rbp), %r15
leaq 0x5f73(%rip), %r12      # 0xf201
leaq -0xc8(%rbp), %r13
leaq -0x120(%rbp), %rbx
testq %r14, %r14
je 0x9376
movq %r15, %rdi
callq 0x89d6
movq %r14, %rdi
movq %r12, %rsi
callq 0x3470
movq %rax, %r14
testq %r14, %r14
je 0x930f
movq %r14, %rdi
callq 0x3390
movsd %xmm0, -0x40(%rbp)
movq %r13, %rdi
callq 0x89d6
movq %rbx, %rdi
movq %r13, %rsi
movsd -0x40(%rbp), %xmm0
callq 0x9a62
movq %rbx, %rdi
callq 0x8a24
movq %r15, %rdi
movq %r13, %rsi
callq 0x97c4
xorl %edi, %edi
movq %r12, %rsi
callq 0x3470
movq %rax, %r14
movq %r13, %rdi
callq 0x8a24
jmp 0x92bb
movl -0x8c(%rbp), %eax
movq -0x30(%rbp), %r14
movl 0x4(%r14), %ecx
testl %eax, %eax
jle 0x9340
cmpl %ecx, %eax
je 0x932b
cmpl $0x0, (%r14)
jne 0x9340
movq %r14, %rdi
movq %r15, %rsi
callq 0x9914
movl -0x8c(%rbp), %eax
movl 0x4(%r14), %ecx
cmpl %ecx, %eax
jne 0x93b6
movq -0x38(%rbp), %rdi
leaq 0x5eae(%rip), %rsi      # 0xf1fd
callq 0x3470
movq %rax, %r14
xorl %edi, %edi
leaq 0x5ec2(%rip), %rsi      # 0xf222
callq 0x3470
movq %rax, -0x38(%rbp)
movq %r15, %rdi
callq 0x8a24
jmp 0x929c
movq -0x48(%rbp), %rdi
callq 0x33c0
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x8
popq %rdi
callq 0x31a0
leaq 0x5e65(%rip), %rcx      # 0xf205
movq %rcx, (%rax)
movq 0xac1e(%rip), %rsi      # 0x13fc8
movq %rax, %rdi
xorl %edx, %edx
callq 0x34e0
jmp 0x93d9
pushq $0x8
popq %rdi
callq 0x31a0
leaq 0x5e40(%rip), %rcx      # 0xf205
movq %rcx, (%rax)
movq 0xabf9(%rip), %rsi      # 0x13fc8
movq %rax, %rdi
xorl %edx, %edx
callq 0x34e0
jmp 0x93fa
jmp 0x93fa
jmp 0x93fa
jmp 0x93fa
jmp 0x93fa
jmp 0x93fa
jmp 0x93ff
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x3170
jmp 0x940e
jmp 0x93fa
movq %rax, %rbx
jmp 0x940e
movq %rax, %rbx
leaq -0xc8(%rbp), %rdi
callq 0x8a24
leaq -0x90(%rbp), %rdi
callq 0x8a24
movq %rbx, %rdi
callq 0x3520