// File: navrajsaini[P]PL_Compiler_design_project/BlockTable.cpp
// Function: BlockTable::find_all_level(int)
TableEntry BlockTable::find_all_level (int index)
{
   TableEntry a;

   for (auto it = table[blockLevel].begin(); it != table[blockLevel].end(); ++it)
   //looks through the current block level
   {
      if (it -> idindex == index)
      //if the index is found returns the table entry
      //and set inScope to true to make sure the variable is declared
      {
	       a.idindex = it -> idindex;
	       a.kind = it -> kind;
	       a.type = it -> type;
	       a.size = it -> size;
	       a.value = it -> value;
	       a.disp = it -> disp;
	       a.procLabel = it -> procLabel;
	       inScope = true;
	       return a;
      }
   }
   inScope = false;
   //if the variable is not found in the current block level
   //search all the block levels up to the current one
   for (int i = blockLevel; i >= 0; i--)
   {
      for (auto it = table[i].begin(); it != table[i].end(); ++it)
      {
    	 if (it -> idindex == index)
    	 {
    	    a.idindex = it -> idindex;
    	    a.kind = it -> kind;
    	    a.type = it -> type;
    	    a.size = it -> size;
    	    a.value = it -> value;
    	    a.disp = it -> disp;
    	    a.procLabel = it -> procLabel;
    	    inScope = true;
    	    return a;
    	 }
      }
   }
   inScope = false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x50(%rbp)
movq %rdi, -0x48(%rbp)
movq %rsi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq %rax, %rdi
addq $0x8, %rdi
movslq 0xf8(%rax), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x1ab80
movq %rax, -0x18(%rbp)
movq -0x40(%rbp), %rax
movq %rax, %rdi
addq $0x8, %rdi
movslq 0xf8(%rax), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x1abf0
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x1abb0
testb $0x1, %al
jne 0x1a8e5
jmp 0x1a9ad
leaq -0x18(%rbp), %rdi
callq 0x1ac20
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x1a99d
leaq -0x18(%rbp), %rdi
callq 0x1ac20
movq %rax, %rcx
movq -0x50(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, (%rax)
leaq -0x18(%rbp), %rdi
callq 0x1ac20
movq %rax, %rcx
movq -0x50(%rbp), %rax
movl 0x4(%rcx), %ecx
movl %ecx, 0x4(%rax)
leaq -0x18(%rbp), %rdi
callq 0x1ac20
movq %rax, %rcx
movq -0x50(%rbp), %rax
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
leaq -0x18(%rbp), %rdi
callq 0x1ac20
movq %rax, %rcx
movq -0x50(%rbp), %rax
movl 0xc(%rcx), %ecx
movl %ecx, 0xc(%rax)
leaq -0x18(%rbp), %rdi
callq 0x1ac20
movq %rax, %rcx
movq -0x50(%rbp), %rax
movl 0x10(%rcx), %ecx
movl %ecx, 0x10(%rax)
leaq -0x18(%rbp), %rdi
callq 0x1ac20
movq %rax, %rcx
movq -0x50(%rbp), %rax
movl 0x14(%rcx), %ecx
movl %ecx, 0x14(%rax)
leaq -0x18(%rbp), %rdi
callq 0x1ac20
movq -0x50(%rbp), %rcx
movq %rax, %rdx
movq -0x40(%rbp), %rax
movl 0x18(%rdx), %edx
movl %edx, 0x18(%rcx)
movb $0x1, (%rax)
jmp 0x1aaf3
jmp 0x1a99f
leaq -0x18(%rbp), %rdi
callq 0x1ac40
jmp 0x1a8ad
movq -0x40(%rbp), %rax
movb $0x0, (%rax)
movl 0xf8(%rax), %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x1aaea
movq -0x40(%rbp), %rdi
addq $0x8, %rdi
movslq -0x24(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x1ab80
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rdi
addq $0x8, %rdi
movslq -0x24(%rbp), %rax
imulq $0x18, %rax, %rax
addq %rax, %rdi
callq 0x1abf0
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1abb0
testb $0x1, %al
jne 0x1aa15
jmp 0x1aada
leaq -0x30(%rbp), %rdi
callq 0x1ac20
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x1aaca
leaq -0x30(%rbp), %rdi
callq 0x1ac20
movq %rax, %rcx
movq -0x50(%rbp), %rax
movl (%rcx), %ecx
movl %ecx, (%rax)
leaq -0x30(%rbp), %rdi
callq 0x1ac20
movq %rax, %rcx
movq -0x50(%rbp), %rax
movl 0x4(%rcx), %ecx
movl %ecx, 0x4(%rax)
leaq -0x30(%rbp), %rdi
callq 0x1ac20
movq %rax, %rcx
movq -0x50(%rbp), %rax
movl 0x8(%rcx), %ecx
movl %ecx, 0x8(%rax)
leaq -0x30(%rbp), %rdi
callq 0x1ac20
movq %rax, %rcx
movq -0x50(%rbp), %rax
movl 0xc(%rcx), %ecx
movl %ecx, 0xc(%rax)
leaq -0x30(%rbp), %rdi
callq 0x1ac20
movq %rax, %rcx
movq -0x50(%rbp), %rax
movl 0x10(%rcx), %ecx
movl %ecx, 0x10(%rax)
leaq -0x30(%rbp), %rdi
callq 0x1ac20
movq %rax, %rcx
movq -0x50(%rbp), %rax
movl 0x14(%rcx), %ecx
movl %ecx, 0x14(%rax)
leaq -0x30(%rbp), %rdi
callq 0x1ac20
movq -0x50(%rbp), %rcx
movq %rax, %rdx
movq -0x40(%rbp), %rax
movl 0x18(%rdx), %edx
movl %edx, 0x18(%rcx)
movb $0x1, (%rax)
jmp 0x1aaf3
jmp 0x1aacc
leaq -0x30(%rbp), %rdi
callq 0x1ac40
jmp 0x1a9e3
jmp 0x1aadc
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1a9bd
movq -0x40(%rbp), %rax
movb $0x0, (%rax)
ud2
movq -0x48(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)