// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rsi, %rdi
movl $0x69, %esi
xorl %edx, %edx
callq 0x33b0
cmpq $-0x1, %rax
movq %r14, -0x30(%rbp)
jne 0xa93c
movq %rbx, %rdi
movl $0x49, %esi
xorl %edx, %edx
callq 0x33b0
cmpq $-0x1, %rax
je 0xab28
movq %r14, %rdi
callq 0xa1ba
movq $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 0x3190
leaq 0x6887(%rip), %rsi      # 0x111fd
movq %r12, %rdi
callq 0x3460
movq %rax, %r14
leaq 0x689a(%rip), %rsi      # 0x11222
xorl %edi, %edi
callq 0x3460
testq %r14, %r14
je 0xab0e
movq %rax, -0x50(%rbp)
movq %r12, -0x40(%rbp)
leaq 0x18(%r15), %rax
movq %rax, -0x78(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x70(%rbp), %r15
leaq -0xe8(%rbp), %rbx
leaq -0x158(%rbp), %r12
movq %rdi, %r13
callq 0xa11a
leaq -0x98(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x31c0
movq %r14, %rdi
leaq 0x681e(%rip), %rsi      # 0x11201
callq 0x3460
testq %rax, %rax
je 0xaa98
movq %rax, %r14
leaq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
movq %r14, %rdi
callq 0x3150
leaq (%rax,%r14), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x93ea
movq %r15, %rdi
callq 0xae0c
movsd %xmm0, -0x48(%rbp)
movsd %xmm1, -0x38(%rbp)
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xaa3e
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3300
movq %rbx, %rdi
callq 0xa11a
movq %rbx, %rdi
movsd -0x48(%rbp), %xmm0
movsd -0x38(%rbp), %xmm1
callq 0x1065a
movq %r12, %rdi
movq %rbx, %rsi
callq 0xa5a6
movq %r12, %rdi
callq 0xa186
movq %r13, %rdi
movq %rbx, %rsi
callq 0xb178
xorl %edi, %edi
leaq 0x6782(%rip), %rsi      # 0x11201
callq 0x3460
movq %rax, %r14
movq %rbx, %rdi
callq 0xa186
testq %r14, %r14
jne 0xa9f4
movl -0xac(%rbp), %eax
movq -0x30(%rbp), %r14
movl 0x4(%r14), %ecx
testl %eax, %eax
jle 0xaac9
cmpl %ecx, %eax
je 0xaab4
cmpl $0x0, (%r14)
jne 0xaac9
movq %r14, %rdi
movq %r13, %rsi
callq 0xb2fa
movl -0xac(%rbp), %eax
movl 0x4(%r14), %ecx
cmpl %ecx, %eax
jne 0xac84
movq -0x50(%rbp), %rdi
leaq 0x6721(%rip), %rsi      # 0x111fd
callq 0x3460
movq %rax, %r14
xorl %edi, %edi
leaq 0x6735(%rip), %rsi      # 0x11222
callq 0x3460
movq %rax, -0x50(%rbp)
movq %r13, %rdi
callq 0xa186
movq %r13, %rdi
testq %r14, %r14
jne 0xa9c1
movq -0x40(%rbp), %r12
movq %r12, %rdi
callq 0x33a0
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0xa1ba
movq 0x8(%rbx), %r14
incq %r14
movq %r14, %rdi
callq 0x3030
movq %rax, %r12
movq (%rbx), %rsi
movq %rax, %rdi
movq %r14, %rdx
callq 0x3190
leaq 0x66a6(%rip), %rsi      # 0x111fd
movq %r12, %rdi
callq 0x3460
movq %rax, %r13
leaq 0x66b9(%rip), %rsi      # 0x11222
xorl %edi, %edi
callq 0x3460
testq %r13, %r13
je 0xab0e
movq %rax, -0x38(%rbp)
movq %r12, -0x40(%rbp)
leaq -0xb0(%rbp), %rbx
leaq 0x6676(%rip), %r14      # 0x11201
leaq -0xe8(%rbp), %r15
leaq -0x120(%rbp), %r12
movq %rbx, %rdi
callq 0xa11a
movq %r13, %rdi
movq %r14, %rsi
callq 0x3460
testq %rax, %rax
je 0xac0e
movq %rax, %r13
movq %r13, %rdi
callq 0x3370
movsd %xmm0, -0x48(%rbp)
movq %r15, %rdi
callq 0xa11a
movq %r15, %rdi
movsd -0x48(%rbp), %xmm0
callq 0xad7e
movq %r12, %rdi
movq %r15, %rsi
callq 0xa5a6
movq %r12, %rdi
callq 0xa186
movq %rbx, %rdi
movq %r15, %rsi
callq 0xb178
xorl %edi, %edi
movq %r14, %rsi
callq 0x3460
movq %rax, %r13
movq %r15, %rdi
callq 0xa186
testq %r13, %r13
jne 0xabb4
movl -0xac(%rbp), %eax
movq -0x30(%rbp), %rcx
movl 0x4(%rcx), %ecx
testl %eax, %eax
jle 0xac45
cmpl %ecx, %eax
je 0xac2c
movq -0x30(%rbp), %rdx
cmpl $0x0, (%rdx)
jne 0xac45
movq -0x30(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0xb2fa
movl -0xac(%rbp), %eax
movl 0x4(%r13), %ecx
cmpl %ecx, %eax
jne 0xacab
movq -0x38(%rbp), %rdi
leaq 0x65a9(%rip), %rsi      # 0x111fd
callq 0x3460
movq %rax, %r13
xorl %edi, %edi
leaq 0x65bd(%rip), %rsi      # 0x11222
callq 0x3460
movq %rax, -0x38(%rbp)
movq %rbx, %rdi
callq 0xa186
testq %r13, %r13
jne 0xab99
jmp 0xab0a
movl $0x8, %edi
callq 0x3170
leaq 0x6570(%rip), %rcx      # 0x11205
movq %rcx, (%rax)
movq 0xb321(%rip), %rsi      # 0x15fc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x34d0
jmp 0xacd0
movl $0x8, %edi
callq 0x3170
leaq 0x6549(%rip), %rcx      # 0x11205
movq %rcx, (%rax)
movq 0xb2fa(%rip), %rsi      # 0x15fc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x34d0
jmp 0xacfe
jmp 0xacfe
jmp 0xacfe
jmp 0xacfe
jmp 0xacfe
jmp 0xacfe
jmp 0xad03
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xad12
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3300
jmp 0xad12
jmp 0xacfe
movq %rax, %rbx
jmp 0xad12
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0xa186
leaq -0xb0(%rbp), %rdi
callq 0xa186
movq %rbx, %rdi
callq 0x3520