// File: czmccrory[P]ManchesterBaby/assembler.cpp
// Function: Assembler::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*)
string Assembler::parse(string* line)
{
	string parsed = "";
	// is there a comment, if there is remove it
	if(line->find(";") != string::npos)
	{
		size_t semiColonIndex = line->find(";");

		if (semiColonIndex == 0)
		{
			return ""; //theres nothing useful on the line
		}
		else
		{
			(*line) = line->substr(0, semiColonIndex);
		}

	}

	// find first non whitespace character
	if(line->find_first_not_of(" ") != string::npos)
	{
		size_t firstIndex = line->find_first_not_of(" ");
		(*line) = line->substr(firstIndex, line->length() - firstIndex);


		// 2 cases being there is a space, word is end of line
		if(line->find(" ") != string::npos)
		{
			size_t whiteSpaceIndex = line->find(" ");

			parsed = line->substr(0, whiteSpaceIndex);

			(*line) = line->substr(whiteSpaceIndex, line->length() - whiteSpaceIndex);

			return parsed;
		}
		else
		{
			parsed = (*line);

			(*line) = "";
			return parsed;

		}
	}
	throw (AssemblerException("Expected Operand"));
	return "";
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdi, -0x130(%rbp)
movq %rdi, %rax
movq %rax, -0x128(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x3460
movq -0x120(%rbp), %rdx
leaq 0x51fe(%rip), %rsi      # 0xb0e4
leaq -0x38(%rbp), %rdi
callq 0x7630
jmp 0x5ef1
leaq -0x39(%rbp), %rdi
callq 0x32f0
movq -0x18(%rbp), %rdi
leaq 0x5269(%rip), %rsi      # 0xb16e
xorl %eax, %eax
movl %eax, %edx
callq 0x34c0
cmpq $-0x1, %rax
je 0x5fee
movq -0x18(%rbp), %rdi
leaq 0x524b(%rip), %rsi      # 0xb16e
xorl %eax, %eax
movl %eax, %edx
callq 0x34c0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x5fac
leaq -0x59(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x3460
movq -0x130(%rbp), %rdi
movq -0x138(%rbp), %rdx
leaq 0x5188(%rip), %rsi      # 0xb0e4
callq 0x7630
jmp 0x5f63
leaq -0x59(%rbp), %rdi
callq 0x32f0
movl $0x1, -0x60(%rbp)
jmp 0x6293
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x32f0
jmp 0x62b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x32f0
jmp 0x62ac
movq -0x18(%rbp), %rsi
movq -0x58(%rbp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x80(%rbp), %rdi
callq 0x32c0
jmp 0x5fc3
movq -0x18(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x3330
leaq -0x80(%rbp), %rdi
callq 0x31c0
jmp 0x5fec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x62ac
jmp 0x5fee
movq -0x18(%rbp), %rdi
leaq 0x5052(%rip), %rsi      # 0xb04b
xorl %eax, %eax
movl %eax, %edx
callq 0x3180
cmpq $-0x1, %rax
je 0x61c9
movq -0x18(%rbp), %rdi
leaq 0x5034(%rip), %rsi      # 0xb04b
xorl %eax, %eax
movl %eax, %edx
callq 0x3180
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rdi
movq %rdi, -0x148(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x140(%rbp)
callq 0x33d0
movq -0x148(%rbp), %rsi
movq -0x140(%rbp), %rdx
movq %rax, %rcx
movq -0x88(%rbp), %rax
subq %rax, %rcx
leaq -0xa8(%rbp), %rdi
callq 0x32c0
jmp 0x606e
movq -0x18(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3330
leaq -0xa8(%rbp), %rdi
callq 0x31c0
movq -0x18(%rbp), %rdi
leaq 0x4fb6(%rip), %rsi      # 0xb04b
xorl %eax, %eax
movl %eax, %edx
callq 0x34c0
cmpq $-0x1, %rax
je 0x618c
movq -0x18(%rbp), %rdi
leaq 0x4f98(%rip), %rsi      # 0xb04b
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x150(%rbp)
callq 0x34c0
movq -0x150(%rbp), %rdx
movq %rax, -0xb0(%rbp)
movq -0x18(%rbp), %rsi
movq -0xb0(%rbp), %rcx
leaq -0xd0(%rbp), %rdi
callq 0x32c0
jmp 0x60ea
leaq -0x38(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
movq %rsi, -0x168(%rbp)
callq 0x3330
movq -0x168(%rbp), %rdi
callq 0x31c0
movq -0x18(%rbp), %rdi
movq %rdi, -0x160(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x158(%rbp)
callq 0x33d0
movq -0x160(%rbp), %rsi
movq -0x158(%rbp), %rdx
movq %rax, %rcx
movq -0xb0(%rbp), %rax
subq %rax, %rcx
leaq -0xf0(%rbp), %rdi
callq 0x32c0
jmp 0x6154
movq -0x18(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x3330
leaq -0xf0(%rbp), %rdi
callq 0x31c0
movq -0x130(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3190
movl $0x1, -0x60(%rbp)
jmp 0x6293
movq -0x18(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x3030
jmp 0x619b
movq -0x18(%rbp), %rdi
leaq 0x4f3e(%rip), %rsi      # 0xb0e4
callq 0x3380
jmp 0x61ad
movq -0x130(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3190
movl $0x1, -0x60(%rbp)
jmp 0x6293
movb $0x1, -0x112(%rbp)
movl $0x28, %edi
callq 0x3140
movq %rax, -0x178(%rbp)
leaq -0x111(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x3460
movq -0x170(%rbp), %rdx
leaq 0x4f6e(%rip), %rsi      # 0xb170
leaq -0x110(%rbp), %rdi
callq 0x7630
jmp 0x6210
movq -0x178(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x8040
jmp 0x6225
movq -0x178(%rbp), %rdi
movb $0x0, -0x112(%rbp)
leaq 0x9b26(%rip), %rsi      # 0xfd60
leaq 0x1dbf(%rip), %rdx      # 0x8000
callq 0x3430
jmp 0x62be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x626e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x31c0
leaq -0x111(%rbp), %rdi
callq 0x32f0
testb $0x1, -0x112(%rbp)
jne 0x6285
jmp 0x6291
movq -0x178(%rbp), %rdi
callq 0x3210
jmp 0x62ac
leaq -0x38(%rbp), %rdi
callq 0x31c0
movq -0x128(%rbp), %rax
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x31c0
movq -0x48(%rbp), %rdi
callq 0x3450
nop