// File: /workspace/github_cpp_makefile_star2_O1/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, -0x48(%rbp)
jne 0xa868
movq %rbx, %rdi
movl $0x49, %esi
xorl %edx, %edx
callq 0x33b0
cmpq $-0x1, %rax
je 0xaa50
movq %r14, %rdi
callq 0xa0f2
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 0x695b(%rip), %rsi      # 0x111fd
movq %r12, %rdi
callq 0x3460
movq %rax, %r14
leaq 0x696e(%rip), %rsi      # 0x11222
xorl %edi, %edi
callq 0x3460
testq %r14, %r14
je 0xaa36
movq %rax, -0x50(%rbp)
movq %r12, -0x38(%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 0xa052
leaq -0x98(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x31c0
movq %r14, %rdi
leaq 0x68f2(%rip), %rsi      # 0x11201
callq 0x3460
testq %rax, %rax
je 0xa9c4
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 0x9334
movq %r15, %rdi
callq 0xad32
movsd %xmm0, -0x40(%rbp)
movsd %xmm1, -0x30(%rbp)
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xa96a
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3300
movq %rbx, %rdi
callq 0xa052
movq %rbx, %rdi
movsd -0x40(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
callq 0x10492
movq %r12, %rdi
movq %rbx, %rsi
callq 0xa4f6
movq %r12, %rdi
callq 0xa0be
movq %r13, %rdi
movq %rbx, %rsi
callq 0xb09e
xorl %edi, %edi
leaq 0x6856(%rip), %rsi      # 0x11201
callq 0x3460
movq %rax, %r14
movq %rbx, %rdi
callq 0xa0be
testq %r14, %r14
jne 0xa920
movl -0xac(%rbp), %eax
testl %eax, %eax
movq -0x48(%rbp), %r14
jle 0xa9e9
cmpl 0x4(%r14), %eax
je 0xa9de
cmpl $0x0, (%r14)
jne 0xa9e9
movq %r14, %rdi
movq %r13, %rsi
callq 0xb220
movl -0xac(%rbp), %eax
cmpl 0x4(%r14), %eax
jne 0xaba3
movq -0x50(%rbp), %rdi
leaq 0x67f9(%rip), %rsi      # 0x111fd
callq 0x3460
movq %rax, %r14
xorl %edi, %edi
leaq 0x680d(%rip), %rsi      # 0x11222
callq 0x3460
movq %rax, -0x50(%rbp)
movq %r13, %rdi
callq 0xa0be
movq %r13, %rdi
testq %r14, %r14
jne 0xa8ed
movq -0x38(%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 0xa0f2
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 0x677e(%rip), %rsi      # 0x111fd
movq %r12, %rdi
callq 0x3460
movq %rax, %r13
leaq 0x6791(%rip), %rsi      # 0x11222
xorl %edi, %edi
callq 0x3460
testq %r13, %r13
je 0xaa36
movq %rax, -0x30(%rbp)
movq %r12, -0x38(%rbp)
leaq -0xb0(%rbp), %rbx
leaq 0x674e(%rip), %r14      # 0x11201
leaq -0xe8(%rbp), %r15
leaq -0x120(%rbp), %r12
movq %rbx, %rdi
callq 0xa052
movq %r13, %rdi
movq %r14, %rsi
callq 0x3460
testq %rax, %rax
je 0xab36
movq %rax, %r13
movq %r13, %rdi
callq 0x3370
movsd %xmm0, -0x40(%rbp)
movq %r15, %rdi
callq 0xa052
movq %r15, %rdi
movsd -0x40(%rbp), %xmm0
callq 0xac9e
movq %r12, %rdi
movq %r15, %rsi
callq 0xa4f6
movq %r12, %rdi
callq 0xa0be
movq %rbx, %rdi
movq %r15, %rsi
callq 0xb09e
xorl %edi, %edi
movq %r14, %rsi
callq 0x3460
movq %rax, %r13
movq %r15, %rdi
callq 0xa0be
testq %r13, %r13
jne 0xaadc
movl -0xac(%rbp), %eax
testl %eax, %eax
movq -0x48(%rbp), %r13
jle 0xab5c
cmpl 0x4(%r13), %eax
je 0xab51
cmpl $0x0, (%r13)
jne 0xab5c
movq %r13, %rdi
movq %rbx, %rsi
callq 0xb220
movl -0xac(%rbp), %eax
cmpl 0x4(%r13), %eax
jne 0xabca
movq -0x30(%rbp), %rdi
leaq 0x668a(%rip), %rsi      # 0x111fd
callq 0x3460
movq %rax, %r13
xorl %edi, %edi
leaq 0x669e(%rip), %rsi      # 0x11222
callq 0x3460
movq %rax, -0x30(%rbp)
movq %rbx, %rdi
callq 0xa0be
testq %r13, %r13
jne 0xaac1
jmp 0xaa32
movl $0x8, %edi
callq 0x3170
leaq 0x6651(%rip), %rcx      # 0x11205
movq %rcx, (%rax)
movq 0xb402(%rip), %rsi      # 0x15fc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x34d0
jmp 0xabef
movl $0x8, %edi
callq 0x3170
leaq 0x662a(%rip), %rcx      # 0x11205
movq %rcx, (%rax)
movq 0xb3db(%rip), %rsi      # 0x15fc0
movq %rax, %rdi
xorl %edx, %edx
callq 0x34d0
jmp 0xac1d
jmp 0xac1d
jmp 0xac1d
jmp 0xac1d
jmp 0xac1d
jmp 0xac1d
jmp 0xac22
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xac31
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x3300
jmp 0xac31
jmp 0xac1d
movq %rax, %rbx
jmp 0xac31
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0xa0be
leaq -0xb0(%rbp), %rdi
callq 0xa0be
movq %rbx, %rdi
callq 0x3520
nop