// File: 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
subq $0x290, %rsp            # imm = 0x290
movq %rsi, -0x238(%rbp)
movq %rdi, %rax
movq -0x238(%rbp), %rdi
movq %rdi, -0x230(%rbp)
movq %rax, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x228(%rbp)
movl $0x69, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x34d0
cmpq $-0x1, %rax
jne 0xf189
movq -0x230(%rbp), %rdi
movl $0x49, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x34d0
cmpq $-0x1, %rax
je 0xf4da
movq -0x228(%rbp), %rdi
callq 0xe690
movq -0x228(%rbp), %rax
movq -0x230(%rbp), %rdi
movq $0x0, 0x8(%rax)
callq 0x3550
movq %rax, %rdi
addq $0x1, %rdi
callq 0x3030
movq -0x230(%rbp), %rdi
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x248(%rbp)
callq 0x3170
movq -0x230(%rbp), %rdi
movq %rax, -0x240(%rbp)
callq 0x3550
movq -0x248(%rbp), %rdi
movq -0x240(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x31f0
leaq 0xc202(%rip), %rax      # 0x1b40d
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3580
movq %rax, -0x28(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0xc207(%rip), %rsi      # 0x1b432
callq 0x3580
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0xf4b8
leaq -0x68(%rbp), %rdi
callq 0xe5d0
movq -0x228(%rbp), %rsi
addq $0x18, %rsi
leaq -0x50(%rbp), %rdi
callq 0x3040
jmp 0xf25e
leaq 0xc1ac(%rip), %rax      # 0x1b411
movq %rax, -0x80(%rbp)
movq -0x28(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x3580
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0xf407
movq -0x88(%rbp), %rax
movq %rax, -0x258(%rbp)
leaq -0xb9(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x3640
movq -0x258(%rbp), %rsi
movq -0x250(%rbp), %rdx
leaq -0xb8(%rbp), %rdi
callq 0xab40
jmp 0xf2c8
leaq -0xb8(%rbp), %rdi
callq 0xf950
movsd %xmm1, -0x268(%rbp)
movsd %xmm0, -0x260(%rbp)
jmp 0xf2e6
movsd -0x268(%rbp), %xmm0
movsd -0x260(%rbp), %xmm1
movsd %xmm1, -0x98(%rbp)
movsd %xmm0, -0x90(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x3270
leaq -0xb9(%rbp), %rdi
callq 0x3410
leaq -0xf8(%rbp), %rdi
callq 0xe5d0
jmp 0xf32c
movups -0x98(%rbp), %xmm0
movaps %xmm0, -0x140(%rbp)
movsd -0x140(%rbp), %xmm0
movsd -0x138(%rbp), %xmm1
leaq -0x130(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0xfec0
jmp 0xf35f
leaq -0x130(%rbp), %rdi
callq 0xe650
leaq -0x68(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0xff30
jmp 0xf37d
movq -0x80(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x3580
movq %rax, -0x88(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0xe650
jmp 0xf27d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xf4aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xf3d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x3270
leaq -0xb9(%rbp), %rdi
callq 0x3410
jmp 0xf4aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0xe650
jmp 0xf4aa
cmpl $0x0, -0x64(%rbp)
jle 0xf43c
movq -0x228(%rbp), %rcx
movl -0x64(%rbp), %eax
cmpl 0x4(%rcx), %eax
je 0xf428
movq -0x228(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xf43c
movq -0x228(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x101b0
jmp 0xf43a
jmp 0xf43c
movq -0x228(%rbp), %rcx
movl -0x64(%rbp), %eax
cmpl 0x4(%rcx), %eax
je 0xf477
movl $0x8, %edi
callq 0x31c0
movq %rax, %rdi
leaq 0xbfb6(%rip), %rax      # 0x1b415
movq %rax, (%rdi)
movq 0x12b5f(%rip), %rsi     # 0x21fc8
xorl %eax, %eax
movl %eax, %edx
callq 0x35f0
jmp 0xf791
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3580
movq %rax, -0x28(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0xbf9f(%rip), %rsi      # 0x1b432
callq 0x3580
movq %rax, -0x30(%rbp)
leaq -0x68(%rbp), %rdi
callq 0xe650
jmp 0xf234
leaq -0x68(%rbp), %rdi
callq 0xe650
jmp 0xf788
movq -0x18(%rbp), %rax
movq %rax, -0x270(%rbp)
cmpq $0x0, %rax
je 0xf4d5
movq -0x270(%rbp), %rdi
callq 0x34b0
jmp 0xf77f
movq -0x228(%rbp), %rdi
callq 0xe690
movq -0x230(%rbp), %rdi
callq 0x3550
movq %rax, %rdi
addq $0x1, %rdi
callq 0x3030
movq -0x230(%rbp), %rdi
movq %rax, -0x148(%rbp)
movq -0x148(%rbp), %rax
movq %rax, -0x280(%rbp)
callq 0x3170
movq -0x230(%rbp), %rdi
movq %rax, -0x278(%rbp)
callq 0x3550
movq -0x280(%rbp), %rdi
movq -0x278(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x31f0
leaq 0xbeba(%rip), %rax      # 0x1b40d
movq %rax, -0x150(%rbp)
movq -0x148(%rbp), %rdi
movq -0x150(%rbp), %rsi
callq 0x3580
movq %rax, -0x158(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0xbeb3(%rip), %rsi      # 0x1b432
callq 0x3580
movq %rax, -0x160(%rbp)
cmpq $0x0, -0x158(%rbp)
je 0xf75d
leaq -0x198(%rbp), %rdi
callq 0xe5d0
leaq 0xbe65(%rip), %rax      # 0x1b411
movq %rax, -0x1a0(%rbp)
movq -0x158(%rbp), %rdi
movq -0x1a0(%rbp), %rsi
callq 0x3580
movq %rax, -0x1a8(%rbp)
cmpq $0x0, -0x1a8(%rbp)
je 0xf691
movq -0x1a8(%rbp), %rdi
callq 0x3470
movsd %xmm0, -0x1b0(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0xe5d0
jmp 0xf5fd
movsd -0x1b0(%rbp), %xmm0
leaq -0x220(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x10430
jmp 0xf61a
leaq -0x220(%rbp), %rdi
callq 0xe650
leaq -0x198(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0xff30
jmp 0xf63b
movq -0x1a0(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
callq 0x3580
movq %rax, -0x1a8(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0xe650
jmp 0xf5cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0xf74f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x1e8(%rbp), %rdi
callq 0xe650
jmp 0xf74f
cmpl $0x0, -0x194(%rbp)
jle 0xf6cf
movq -0x228(%rbp), %rcx
movl -0x194(%rbp), %eax
cmpl 0x4(%rcx), %eax
je 0xf6b8
movq -0x228(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xf6cf
movq -0x228(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x101b0
jmp 0xf6cd
jmp 0xf6cf
movq -0x228(%rbp), %rcx
movl -0x194(%rbp), %eax
cmpl 0x4(%rcx), %eax
je 0xf70d
movl $0x8, %edi
callq 0x31c0
movq %rax, %rdi
leaq 0xbd20(%rip), %rax      # 0x1b415
movq %rax, (%rdi)
movq 0x128c9(%rip), %rsi     # 0x21fc8
xorl %eax, %eax
movl %eax, %edx
callq 0x35f0
jmp 0xf791
movq -0x160(%rbp), %rdi
movq -0x150(%rbp), %rsi
callq 0x3580
movq %rax, -0x158(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0xbd00(%rip), %rsi      # 0x1b432
callq 0x3580
movq %rax, -0x160(%rbp)
leaq -0x198(%rbp), %rdi
callq 0xe650
jmp 0xf58b
leaq -0x198(%rbp), %rdi
callq 0xe650
jmp 0xf788
movq -0x148(%rbp), %rax
movq %rax, -0x288(%rbp)
cmpq $0x0, %rax
je 0xf77d
movq -0x288(%rbp), %rdi
callq 0x34b0
jmp 0xf77f
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x3630
nopw %cs:(%rax,%rax)