// File: /workspace/github_cpp_makefile_star2_O3/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 0x2dc4
movq 0x6742(%rip), %r14      # 0x9fd0
leaq 0x3896(%rip), %rsi      # 0x712b
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
leaq 0x50(%rbx), %rsi
leaq 0x50(%rsp), %rdi
movl $0x8, %edx
callq 0x22e0
movl $0x0, 0xc(%rsp)
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x37f0(%rip), %rdx      # 0x70e4
leaq 0x10(%rsp), %rdi
movq %rdx, %rsi
callq 0x605e
movq 0x50(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x70(%rsp,%rax)
je 0x398f
movq 0x66d8(%rip), %rbx      # 0x9ff0
leaq 0x381a(%rip), %rsi      # 0x7139
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 0x66a6(%rip), %rdi      # 0x9ff0
callq 0x2030
movq %rax, %rdi
callq 0x2130
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3973
movq 0x20(%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 0x20(%rbx), %r14
leaq 0x40(%rsp), %r12
leaq 0x30(%rsp), %r13
movq 0x662c(%rip), %rbp      # 0x9fd0
leaq (%rsp,%rax), %rdi
addq $0x50, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %edx
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2360
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3957
movq %r12, 0x30(%rsp)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x5ebe
movl $0x11, %edx
movq %rbp, %rdi
leaq 0x36bf(%rip), %rsi      # 0x70be
callq 0x2230
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %rbp, %rdi
callq 0x2230
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2130
movq %rbx, %rdi
movq %r13, %rsi
leaq 0xc(%rsp), %rdx
movq %r14, %rcx
callq 0x4ad4
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x3a6a
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x50(%rsp), %rax
movq -0x18(%rax), %rax
jmp 0x39a4
movq %rax, %rbx
jmp 0x3abc
jmp 0x3a81
jmp 0x3a81
movq %rax, %rbx
jmp 0x3aa0
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x3aa0
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x3abc
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x50(%rsp), %rdi
callq 0x2060
movq %rbx, %rdi
callq 0x2330