// File: czmccrory[P]ManchesterBaby/assembler.cpp
// Function: Assembler::assembleFirstPass()
void Assembler::assembleFirstPass()
{
	ifstream ifs(filePath);
	int counter = 0;
	int* lineCounter = &counter;
	string line = "";

	if (! ifs)
	{
		throw AssemblerException("Invalid filename");
	}

	cout << "FIRST PASS:" << endl;

	try
	{
		while (getline(ifs, line)) //while nextLine exists
		{
			string lineCopy = line;
			string* linePtr = &lineCopy;
			cout << "assembling line: " << line << endl;
		 	assembleLineFirstPass(linePtr, lineCounter);
		}
	}
	catch (AssemblerException &e)
	{
		cout << "\033[1;31mAssembler Error: \033[0m" << e.what() << endl;
		exit (0);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
movq %rsi, -0x2c0(%rbp)
addq $0x50, %rsi
leaq -0x210(%rbp), %rdi
movl $0x8, %edx
callq 0x3410
movl $0x0, -0x214(%rbp)
leaq -0x214(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x241(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x3460
movq -0x2b8(%rbp), %rdx
leaq 0x62dc(%rip), %rsi      # 0xb0e4
leaq -0x240(%rbp), %rdi
callq 0x7630
jmp 0x4e16
leaq -0x241(%rbp), %rdi
callq 0x32f0
movq -0x210(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x210(%rbp,%rax), %rdi
callq 0x3130
movb %al, -0x2c1(%rbp)
jmp 0x4e42
movb -0x2c1(%rbp), %al
testb $0x1, %al
jne 0x4e51
jmp 0x4f67
movb $0x1, -0x27a(%rbp)
movl $0x28, %edi
callq 0x3140
movq %rax, -0x2d8(%rbp)
leaq -0x279(%rbp), %rdi
movq %rdi, -0x2d0(%rbp)
callq 0x3460
movq -0x2d0(%rbp), %rdx
leaq 0x6217(%rip), %rsi      # 0xb0a1
leaq -0x278(%rbp), %rdi
callq 0x7630
jmp 0x4e98
movq -0x2d8(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x8040
jmp 0x4ead
movq -0x2d8(%rbp), %rdi
movb $0x0, -0x27a(%rbp)
leaq 0xae9e(%rip), %rsi      # 0xfd60
leaq 0x3137(%rip), %rdx      # 0x8000
callq 0x3430
jmp 0x51a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
leaq -0x241(%rbp), %rdi
callq 0x32f0
jmp 0x5182
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x5176
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x4f3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x31c0
leaq -0x279(%rbp), %rdi
callq 0x32f0
testb $0x1, -0x27a(%rbp)
jne 0x4f56
jmp 0x4f62
movq -0x2d8(%rbp), %rdi
callq 0x3210
jmp 0x5176
movq 0xb062(%rip), %rdi      # 0xffd0
leaq 0x613d(%rip), %rsi      # 0xb0b2
callq 0x3290
movq %rax, -0x2e0(%rbp)
jmp 0x4f83
movq -0x2e0(%rbp), %rdi
movq 0xb027(%rip), %rsi      # 0xffb8
callq 0x32d0
jmp 0x4f98
jmp 0x4f9a
leaq -0x210(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x3070
movq %rax, -0x2e8(%rbp)
jmp 0x4fb6
movq -0x2e8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3360
movb %al, -0x2e9(%rbp)
jmp 0x4fd4
movb -0x2e9(%rbp), %al
testb $0x1, %al
jne 0x4fe3
jmp 0x5138
leaq -0x2a0(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x3100
jmp 0x4ff8
leaq -0x2a0(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movq 0xafc3(%rip), %rdi      # 0xffd0
leaq 0x60aa(%rip), %rsi      # 0xb0be
callq 0x3290
movq %rax, -0x2f8(%rbp)
jmp 0x5022
movq -0x2f8(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x3270
movq %rax, -0x300(%rbp)
jmp 0x503e
movq -0x300(%rbp), %rdi
movq 0xaf6c(%rip), %rsi      # 0xffb8
callq 0x32d0
jmp 0x5053
movq -0x2c0(%rbp), %rdi
movq -0x2a8(%rbp), %rsi
movq -0x220(%rbp), %rdx
callq 0x5670
jmp 0x506f
leaq -0x2a0(%rbp), %rdi
callq 0x31c0
jmp 0x4f9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x50b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
leaq -0x2a0(%rbp), %rdi
callq 0x31c0
movl -0x254(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x5176
movq -0x250(%rbp), %rdi
callq 0x30e0
movq %rax, -0x2b0(%rbp)
movq 0xaef1(%rip), %rdi      # 0xffd0
leaq 0x5f9e(%rip), %rsi      # 0xb084
callq 0x3290
movq %rax, -0x308(%rbp)
jmp 0x50f4
movq -0x2b0(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0x308(%rbp), %rdi
movq %rax, %rsi
callq 0x3290
movq %rax, -0x310(%rbp)
jmp 0x511c
movq -0x310(%rbp), %rdi
movq 0xae8e(%rip), %rsi      # 0xffb8
callq 0x32d0
jmp 0x5131
xorl %edi, %edi
callq 0x3320
jmp 0x5155
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
callq 0x3420
jmp 0x5153
jmp 0x5176
leaq -0x240(%rbp), %rdi
callq 0x31c0
leaq -0x210(%rbp), %rdi
callq 0x3080
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
leaq -0x240(%rbp), %rdi
callq 0x31c0
leaq -0x210(%rbp), %rdi
callq 0x3080
movq -0x250(%rbp), %rdi
callq 0x3450
movq %rax, %rdi
callq 0x7fd0
nopw %cs:(%rax,%rax)