// File: 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
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
addq $0x38, %rdi
callq 0x4470
movq 0xadf6(%rip), %rdi      # 0xffd0
leaq 0x5f4a(%rip), %rsi      # 0xb12b
callq 0x3290
movq %rax, %rdi
movq 0xadc8(%rip), %rsi      # 0xffb8
callq 0x32d0
movq -0x2a8(%rbp), %rsi
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, -0x2a0(%rbp)
callq 0x3460
movq -0x2a0(%rbp), %rdx
leaq 0x5e9a(%rip), %rsi      # 0xb0e4
leaq -0x240(%rbp), %rdi
callq 0x7630
jmp 0x5258
leaq -0x241(%rbp), %rdi
callq 0x32f0
movq -0x2a8(%rbp), %rdi
addq $0x20, %rdi
callq 0x8110
movq %rax, -0x260(%rbp)
movq -0x210(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x210(%rbp,%rax), %rdi
callq 0x3130
movb %al, -0x2a9(%rbp)
jmp 0x529b
movb -0x2a9(%rbp), %al
testb $0x1, %al
jne 0x52a7
jmp 0x5321
movq 0xad42(%rip), %rdi      # 0xfff0
leaq 0x5e84(%rip), %rsi      # 0xb139
callq 0x3290
movq %rax, -0x2b8(%rbp)
jmp 0x52c3
movq -0x2b8(%rbp), %rdi
movq 0xace7(%rip), %rsi      # 0xffb8
callq 0x32d0
jmp 0x52d8
movl $0x1, -0x264(%rbp)
jmp 0x5448
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
leaq -0x241(%rbp), %rdi
callq 0x32f0
jmp 0x5475
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x5469
jmp 0x5323
leaq -0x210(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x3070
movq %rax, -0x2c0(%rbp)
jmp 0x533f
movq -0x2c0(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x3360
movb %al, -0x2c1(%rbp)
jmp 0x535d
movb -0x2c1(%rbp), %al
testb $0x1, %al
jne 0x536c
jmp 0x543e
leaq -0x288(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x3100
jmp 0x5381
leaq -0x288(%rbp), %rax
movq %rax, -0x290(%rbp)
movq 0xac3a(%rip), %rdi      # 0xffd0
leaq 0x5d21(%rip), %rsi      # 0xb0be
callq 0x3290
movq %rax, -0x2d0(%rbp)
jmp 0x53ab
movq -0x2d0(%rbp), %rdi
leaq -0x240(%rbp), %rsi
callq 0x3270
movq %rax, -0x2d8(%rbp)
jmp 0x53c7
movq -0x2d8(%rbp), %rdi
movq 0xabe3(%rip), %rsi      # 0xffb8
callq 0x32d0
jmp 0x53dc
movq -0x2a8(%rbp), %rdi
movq -0x290(%rbp), %rsi
movq -0x220(%rbp), %rdx
movq -0x260(%rbp), %rax
movq %rax, -0x298(%rbp)
movq -0x298(%rbp), %rcx
callq 0x66d0
jmp 0x540d
leaq -0x288(%rbp), %rdi
callq 0x31c0
jmp 0x5323
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
leaq -0x288(%rbp), %rdi
callq 0x31c0
jmp 0x5469
movl $0x0, -0x264(%rbp)
leaq -0x240(%rbp), %rdi
callq 0x31c0
leaq -0x210(%rbp), %rdi
callq 0x3080
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
leaq -0x240(%rbp), %rdi
callq 0x31c0
leaq -0x210(%rbp), %rdi
callq 0x3080
movq -0x250(%rbp), %rdi
callq 0x3450
nopl (%rax)