// File: /workspace/github_cpp_makefile_star2_O3/navrajsaini[P]PL_Compiler_design_project/Assembler.cpp
// Function: Assembler::firstPass()
void Assembler::firstPass()
{
   // Start at address 0 (not 1 as I had previously thought)
   currentAddress = 0;
   string nextop;
   (*insource) >> nextop;
   // Loop until we find the ENDPROG operation.
   for (;;) {
      // Record the current address in the label table.
      if (nextop == "DEFADDR") {
	 int index;
	 (*insource) >> index;
	 labelTable[index] = currentAddress;
	 (*insource) >> nextop;
      }
      // Record the associated value in the label table.
      else if (nextop == "DEFARG") {
	 int index, value;
	 (*insource) >> index >> value;
	 labelTable[index] = value;
	 (*insource) >> nextop;
      }
      // Stop when we find ENDPROG.
      else if (nextop == "ENDPROG")
	 return;
      else if (nextop == "ARROW" || nextop == "ASSIGN" || nextop == "BAR" ||
	       nextop == "CONSTANT" || nextop == "FI" || nextop == "READ" ||
	       nextop == "WRITE") {
	 // Skip one machine words.
	 (*insource) >> nextop;
	 (*insource) >> nextop;
	 currentAddress += 2;
      }
      else if (nextop == "CALL" || nextop == "INDEX" || nextop == "PROC" ||
	       nextop == "PROG" || nextop == "VARIABLE") {
	 // Skip two machine words.
	 (*insource) >> nextop;
	 (*insource) >> nextop;
	 (*insource) >> nextop;
	 currentAddress += 3;
      }
      else {
	 // just get the next machine word.
	 (*insource) >> nextop;
	 currentAddress++;
      }
   }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movl $0x0, 0x7d0(%rdi)
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x7d8(%rdi), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2250
leaq 0x2a05(%rip), %r14      # 0x136b3
leaq -0x50(%rbp), %r15
leaq -0x2c(%rbp), %r12
leaq 0x29ef(%rip), %r13      # 0x136ac
movq %r15, %rdi
movq %r14, %rsi
callq 0x2080
testl %eax, %eax
je 0x10e28
movq %r15, %rdi
movq %r13, %rsi
callq 0x2080
testl %eax, %eax
je 0x10e82
movq %r15, %rdi
leaq 0x29b7(%rip), %rsi      # 0x136a4
callq 0x2080
testl %eax, %eax
je 0x10ef4
movq %r15, %rdi
leaq 0x2b2e(%rip), %rsi      # 0x13832
callq 0x2080
testl %eax, %eax
je 0x10e58
movq %r15, %rdi
leaq 0x2ace(%rip), %rsi      # 0x137e9
callq 0x2080
testl %eax, %eax
je 0x10e58
movq %r15, %rdi
leaq 0x2b06(%rip), %rsi      # 0x13838
callq 0x2080
testl %eax, %eax
je 0x10e58
movq %r15, %rdi
leaq 0x2b4d(%rip), %rsi      # 0x13896
callq 0x2080
testl %eax, %eax
je 0x10e58
movq %r15, %rdi
leaq 0x2abd(%rip), %rsi      # 0x1381d
callq 0x2080
testl %eax, %eax
je 0x10e58
movq %r15, %rdi
leaq 0x2a51(%rip), %rsi      # 0x137c8
callq 0x2080
testl %eax, %eax
je 0x10e58
movq %r15, %rdi
leaq 0x2a4b(%rip), %rsi      # 0x137d9
callq 0x2080
testl %eax, %eax
je 0x10e58
movq %r15, %rdi
leaq 0x2a70(%rip), %rsi      # 0x13815
callq 0x2080
testl %eax, %eax
je 0x10ebb
movq %r15, %rdi
leaq 0x2b1c(%rip), %rsi      # 0x138d8
callq 0x2080
testl %eax, %eax
je 0x10ebb
movq %r15, %rdi
leaq 0x29ea(%rip), %rsi      # 0x137bd
callq 0x2080
testl %eax, %eax
je 0x10ebb
movq %r15, %rdi
leaq 0x28bd(%rip), %rsi      # 0x136a7
callq 0x2080
testl %eax, %eax
je 0x10ebb
movq %r15, %rdi
leaq 0x2aab(%rip), %rsi      # 0x138ac
callq 0x2080
testl %eax, %eax
je 0x10ebb
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
incl 0x7d0(%rbx)
jmp 0x10cbd
movq 0x7d8(%rbx), %rdi
movq %r12, %rsi
callq 0x2120
movl 0x7d0(%rbx), %eax
movslq -0x2c(%rbp), %rcx
movl %eax, (%rbx,%rcx,4)
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
jmp 0x10cbd
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
addl $0x2, 0x7d0(%rbx)
jmp 0x10cbd
movq 0x7d8(%rbx), %rdi
movq %r12, %rsi
callq 0x2120
movq %rax, %rdi
leaq -0x30(%rbp), %rsi
callq 0x2120
movl -0x30(%rbp), %eax
movslq -0x2c(%rbp), %rcx
movl %eax, (%rbx,%rcx,4)
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
jmp 0x10cbd
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
movq 0x7d8(%rbx), %rdi
movq %r15, %rsi
callq 0x2250
addl $0x3, 0x7d0(%rbx)
jmp 0x10cbd
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x10f06
callq 0x21b0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x10f1b
jmp 0x10f1b
jmp 0x10f1b
movq %rax, %rbx
leaq -0x40(%rbp), %rax
movq -0x50(%rbp), %rdi
cmpq %rax, %rdi
je 0x10f30
callq 0x21b0
movq %rbx, %rdi
callq 0x2310