// File: /workspace/github_cpp_makefile_star2_O1/czmccrory[P]ManchesterBaby/assembler.cpp
// Function: Assembler::assembleSecondPass()
void Assembler::assembleSecondPass()
{
	// prints complete symbol table for reference
	sTable.printTable();

	cout << "\nSECOND PASS:" << endl;

	ifstream ifs(filePath);
	int counter = 0;
	int* lineCounter = &counter;
	string line = "";
	list<string>::iterator it = buffer.begin();

	if (! ifs)
	{
		cerr << "error: invalid filename" << endl;
		return;
	}

	while (getline(ifs, line))
	{
		string lineCopy = line;
		string* linePtr = &lineCopy;

		cout << "assembling line: " << line << endl;
	 	assembleLineSecondPass(linePtr, lineCounter, it);
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rdi, %rbx
addq $0x38, %rdi
callq 0x2df0
movq 0x6724(%rip), %r14      # 0x9fd0
leaq 0x3894(%rip), %rsi      # 0x7147
movl $0xd, %edx
movq %r14, %rdi
callq 0x2230
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
movq %rbx, 0x28(%rsp)
leaq 0x50(%rbx), %rsi
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movl $0x8, %edx
callq 0x22e0
movl $0x0, 0x4(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x37e6(%rip), %rdx      # 0x7100
leaq 0x8(%rsp), %rdi
movq %rdx, %rsi
callq 0x6088
movq 0x50(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x70(%rsp,%rax)
je 0x39b5
movq 0x66b2(%rip), %rbx      # 0x9ff0
leaq 0x3810(%rip), %rsi      # 0x7155
movl $0x17, %edx
movq %rbx, %rdi
callq 0x2230
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq 0x6680(%rip), %rdi      # 0x9ff0
callq 0x2030
movq %rax, %rdi
callq 0x2130
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x3999
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x50(%rsp), %rdi
callq 0x2060
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%rsp), %rax
movq 0x20(%rax), %r15
leaq 0x40(%rsp), %rbx
leaq 0x30(%rsp), %r13
movq 0x6601(%rip), %rbp      # 0x9fd0
movq 0x50(%rsp), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %edx
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x2360
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x397d
movq %rbx, 0x30(%rsp)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x5ee4
movl $0x11, %edx
movq %rbp, %rdi
leaq 0x36aa(%rip), %rsi      # 0x70da
callq 0x2230
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rbp, %rdi
callq 0x2230
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r12, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
movq 0x28(%rsp), %rdi
movq %r13, %rsi
leaq 0x4(%rsp), %rdx
movq %r15, %rcx
callq 0x4b24
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0x39cf
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x39cf
movq %rax, %r14
jmp 0x3aea
jmp 0x3aaf
jmp 0x3aaf
movq %rax, %r14
jmp 0x3ace
movq %rax, %r14
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3ace
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x3aea
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x50(%rsp), %rdi
callq 0x2060
movq %r14, %rdi
callq 0x2330