// File: /workspace/github_c_makefile_star2_O3/anuwu[P]ERPLAG-Compiler/symbolTable.c
// Function: getSize
int getSize(varST * thisVar) 
{
	if(thisVar->datatype == TK_INTEGER)
		return 2 ;
	else if (thisVar->datatype == TK_BOOLEAN)
		return 2 ;
	else if(thisVar->datatype == TK_REAL)
	{
		realPresent = 1 ;
		return 4 ;
	}	
	else // Array type 
	{
		int left, right ;
		char *parentModule = getParentModuleName ((moduleST *)thisVar->scope) ;

		if (thisVar->arrayIndices->type == TK_REAL)
			realPresent = 1 ;

		if (isVarStaticArr(thisVar))
		{
			int sz ;

			left = atoi(thisVar->arrayIndices->tokLeft->lexeme) ;
			right = atoi(thisVar->arrayIndices->tokRight->lexeme) ;


			if (thisVar->arrayIndices->type == TK_INTEGER)
				sz = 2 ;
			else if (thisVar->arrayIndices->type == TK_BOOLEAN)
				sz = 2 ;
			else if (thisVar->arrayIndices->type == TK_REAL)
				sz = 4 ;
			
			
			sz *= (right - left + 1) ;

			if (sz <= 0)
			{
				errSemantic () ;
				#ifdef _WIN64
					printf ("In module \"%s\" at line %d, the declaration of array variable \"%s\" must have left limit <= right limit\n", parentModule, thisVar->arrayIndices->tokLeft->lineNumber, thisVar->lexeme) ;
				#endif
				#if defined __linux__ || __MACH__
					printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", the declaration of " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " must have left limit <= right limit\n", parentModule, thisVar->arrayIndices->tokLeft->lineNumber, thisVar->lexeme) ;
				#endif
				realBase->semanticError = 1 ;
				return -1 ;
			}
			else
			{
				if (thisVar->varType != VAR_INPUT)
					return sz  ;
				else
					return 8 ;
			}
		}
		else if (thisVar->varType != VAR_INPUT)		//dynamic array but not input to a module
		{
			// dynamic array index checks
			int indexErrorFlag = 0 ;
			varST *searchedVarLeft, *searchedVarRight ;

			if (!isLeftLimStatic(thisVar))
			{
				searchedVarLeft = searchVar ((moduleST *)thisVar->scope, thisVar->arrayIndices->tokLeft->lexeme) ;
				if (searchedVarLeft == NULL)
				{
					errSemantic () ;
					#ifdef _WIN64
						printf ("In module \"%s\" at line %d, left index variable \"%s\" of array variable \"%s\" is undeclared\n", parentModule, thisVar->arrayIndices->tokLeft->lineNumber, thisVar->arrayIndices->tokLeft->lexeme, thisVar->lexeme) ;
					#endif
					#if defined __linux__ || __MACH__
						printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", left " ANSI_BOLD ANSI_BLACK "index" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " of " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " is undeclared\n", parentModule, thisVar->arrayIndices->tokLeft->lineNumber, thisVar->arrayIndices->tokLeft->lexeme, thisVar->lexeme) ;
					#endif
					realBase->semanticError = 1 ;
					indexErrorFlag = 1 ;
				}
				else if (searchedVarLeft->datatype != TK_INTEGER)
				{
					errSemantic () ;
					#ifdef _WIN64
						printf ("In module \"%s\" at line %d, left index variable \"%s\" of array variable \"%s\" must be of integer type\n", parentModule, thisVar->arrayIndices->tokLeft->lineNumber, thisVar->arrayIndices->tokLeft->lexeme, thisVar->lexeme) ;
					#endif
					#if defined __linux__ || __MACH__
						printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", left " ANSI_BOLD ANSI_BLACK "index" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " of " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " must be of " ANSI_BOLD ANSI_GREEN "integer" ANSI_RESET " type\n", parentModule, thisVar->arrayIndices->tokLeft->lineNumber, thisVar->arrayIndices->tokLeft->lexeme, thisVar->lexeme) ;
					#endif
					realBase->semanticError = 1 ;
					indexErrorFlag = 1 ;
				}
				else if (((moduleST*)thisVar->scope)->tableType == SWITCH_ST && thisVar->scope == searchedVarLeft->scope)
				{
					errSemantic () ;
					#ifdef _WIN64
						printf ("In module \"%s\" at line %d, declaration of left index variable \"%s\" of array variable \"%s\", and the array itself, appear in the same switch scope\n", parentModule, thisVar->arrayIndices->tokLeft->lineNumber, thisVar->arrayIndices->tokLeft->lexeme, thisVar->lexeme) ;
					#endif
					#if defined __linux__ || __MACH__
						printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", declaration of left " ANSI_BOLD ANSI_BLACK "index" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " of " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET ", and the array itself, appear in the same switch scope\n", parentModule, thisVar->arrayIndices->tokLeft->lineNumber, thisVar->arrayIndices->tokLeft->lexeme, thisVar->lexeme) ;
					#endif
					realBase->semanticError = 1 ;
					indexErrorFlag = 1 ;
				}
			}

			if (!isRightLimStatic (thisVar))
			{
				searchedVarRight = searchVar ((moduleST *)thisVar->scope, thisVar->arrayIndices->tokRight->lexeme) ;
				if (searchedVarRight == NULL)
				{
					errSemantic () ;
					#ifdef _WIN64
						printf ("In module \"%s\" at line %d, right index variable \"%s\" of array variable \"%s\" is undeclared\n", parentModule, thisVar->arrayIndices->tokRight->lineNumber ,thisVar->arrayIndices->tokRight->lexeme, thisVar->lexeme) ;
					#endif
					#if defined __linux__ || __MACH__
						printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", right " ANSI_BOLD ANSI_BLACK "index" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " of " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " is undeclared\n", parentModule, thisVar->arrayIndices->tokRight->lineNumber ,thisVar->arrayIndices->tokRight->lexeme, thisVar->lexeme) ;
					#endif
					realBase->semanticError = 1 ;
					indexErrorFlag = 1 ;
				}
				else if (searchedVarRight->datatype != TK_INTEGER)
				{
					errSemantic () ;
					#ifdef _WIN64
						printf ("In module \"%s\" at line %d, right index variable \"%s\" of array variable \"%s\" must be of integer type\n", parentModule, thisVar->arrayIndices->tokRight->lineNumber, thisVar->arrayIndices->tokRight->lexeme, thisVar->lexeme) ;
					#endif
					#if defined __linux__ || __MACH__
						printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", right " ANSI_BOLD ANSI_BLACK "index" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " of " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " must be of " ANSI_BOLD ANSI_GREEN "integer" ANSI_RESET " type\n", parentModule, thisVar->arrayIndices->tokRight->lineNumber, thisVar->arrayIndices->tokRight->lexeme, thisVar->lexeme) ;
					#endif
					realBase->semanticError = 1 ;
					indexErrorFlag = 1 ;
				}
				else if (((moduleST*)thisVar->scope)->tableType == SWITCH_ST && thisVar->scope == searchedVarRight->scope)
				{
					errSemantic () ;
					#ifdef _WIN64
						printf ("In module \"%s\" at line %d, declaration of right index variable \"%s\" of array variable \"%s\", and the array itself, appear in the same switch scope\n", parentModule, thisVar->arrayIndices->tokRight->lineNumber, thisVar->arrayIndices->tokRight->lexeme, thisVar->lexeme) ;
					#endif
					#if defined __linux__ || __MACH__
						printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", declaration of right " ANSI_BOLD ANSI_BLACK "index" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " of " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET ", and the array itself, appear in the same switch scope\n", parentModule, thisVar->arrayIndices->tokRight->lineNumber, thisVar->arrayIndices->tokRight->lexeme, thisVar->lexeme) ;
					#endif
					realBase->semanticError = 1 ;
					indexErrorFlag = 1 ;
				}
			}

			if (indexErrorFlag)
				return -2 ;		// incorect dynamic array

			insertVar ((moduleST *) thisVar->scope, thisVar, INSERT_DYNAMIC) ;
			return 12 ;		// correct dynamic array
		}
		else		// dynamic array and input to a module
		{
			int indexErrorFlag = 0 ;
			varST *searchedVarLeft, *searchedVarRight ;
			int leftDigit , rightDigit ;
			moduleST *scope ;

			leftDigit = isLeftLimStatic (thisVar);
			rightDigit = isRightLimStatic(thisVar) ;
			scope = (moduleST *)thisVar->scope ;

			// Left limit
			if (!leftDigit)
			{
				searchedVarLeft = searchVar (scope, thisVar->arrayIndices->tokLeft->lexeme) ;
				
				if (searchedVarLeft != NULL)
				{
					errSemantic () ;
					#ifdef _WIN64
						printf ("In module \"%s\" at line %d, index variable \"%s\" of input array variable \"%s\" is already defined\n", parentModule, thisVar->arrayIndices->tokLeft->lineNumber, thisVar->arrayIndices->tokLeft->lexeme, thisVar->lexeme) ;
					#endif
					#if defined __linux__ || __MACH__
						printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", " ANSI_BOLD ANSI_BLACK "index" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " of " ANSI_BOLD ANSI_BLACK "input array" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " is already defined\n", parentModule, thisVar->arrayIndices->tokLeft->lineNumber, thisVar->arrayIndices->tokLeft->lexeme, thisVar->lexeme) ;
					#endif
					realBase->semanticError = 1 ;
					indexErrorFlag = 1 ;
				}
				else
				{
					searchedVarLeft = createVarST (thisVar->arrayIndices->tokLeft->lexeme, scope, VAR_PLACEHOLDER, TK_INTEGER) ;
					searchedVarLeft->offset = -(scope->currOffset + 10) ;
					searchedVarLeft->size = 2 ;
					insertVar (scope, searchedVarLeft, INSERT_INPUT) ;
				}
			}

			// Right limit
			if (!rightDigit)
			{
				searchedVarRight = searchVar (scope, thisVar->arrayIndices->tokRight->lexeme) ;

				if (searchedVarRight != NULL)
				{
					errSemantic () ;
					#ifdef _WIN64
						printf ("In module \"%s\" at line %d, index variable \"%s\" of input array variable \"%s\" is already defined\n", parentModule, thisVar->arrayIndices->tokRight->lineNumber, thisVar->arrayIndices->tokRight->lexeme, thisVar->lexeme) ;
					#endif
					#if defined __linux__ || __MACH__
						printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", " ANSI_BOLD ANSI_BLACK "index" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " of " ANSI_BOLD ANSI_BLACK "input array" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " is already defined\n", parentModule, thisVar->arrayIndices->tokRight->lineNumber, thisVar->arrayIndices->tokRight->lexeme, thisVar->lexeme) ;
					#endif
					realBase->semanticError = 1 ;
					indexErrorFlag = 1 ;
				}
				else
				{
					searchedVarRight = createVarST (thisVar->arrayIndices->tokRight->lexeme, scope, VAR_PLACEHOLDER, TK_INTEGER) ;
					searchedVarRight->offset = -(scope->currOffset + 8) ;
					searchedVarRight->size = 2 ;
					insertVar (scope, searchedVarRight, INSERT_INPUT) ;
				}
			}

			if (indexErrorFlag)
				return -2 ;
			else
				return 12 ;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x8(%rdi), %eax
movl $0x2, %r15d
cmpl $0x37, %eax
je 0xc94f
cmpl $0x39, %eax
je 0xc94f
cmpl $0x38, %eax
jne 0xc5af
movl $0x1, 0x24a80(%rip)     # 0x31024
movl $0x4, %r15d
jmp 0xc94f
movq %rdi, %rbx
movq 0x28(%rdi), %rdx
movq 0x24a6b(%rip), %rcx     # 0x31028
movq %rdx, %rax
movq 0x10(%rdx), %rdx
cmpq %rcx, %rdx
jne 0xc5bd
movq 0x10(%rbx), %rcx
cmpl $0x38, (%rcx)
jne 0xc5dc
movl $0x1, 0x24a48(%rip)     # 0x31024
movq (%rax), %r14
movq %rbx, %rdi
callq 0xe01a
testl %eax, %eax
je 0xc63d
movq 0x10(%rbx), %r13
movq 0x8(%r13), %rax
movq 0x8(%rax), %rdi
callq 0x1140
movl %eax, %r12d
movq 0x10(%r13), %rax
movq 0x8(%rax), %rdi
callq 0x1140
movl %eax, %r15d
cmpl $0x38, (%r13)
sete %cl
subl %r12d, %r15d
incl %r15d
incb %cl
shll %cl, %r15d
testl %r15d, %r15d
jle 0xc6ad
cmpl $0x0, 0x30(%rbx)
movl $0x8, %eax
cmovel %eax, %r15d
jmp 0xc94f
movl 0x30(%rbx), %r15d
movq %rbx, %rdi
callq 0xdfb8
movl %eax, %r12d
testl %r15d, %r15d
je 0xc6ef
movb $0x1, %r13b
testl %r12d, %r12d
jne 0xc7c1
movq 0x10(%rbx), %rax
movq 0x28(%rbx), %r15
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0xb8e8
testq %rax, %rax
je 0xc777
cmpl $0x37, 0x8(%rax)
jne 0xc780
cmpl $0x4, 0x8(%r15)
jne 0xc7c1
cmpq 0x28(%rax), %r15
jne 0xc7c1
leaq 0x5a40(%rip), %r15      # 0x120e8
jmp 0xc787
xorl %eax, %eax
callq 0xe989
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
leaq 0x583c(%rip), %rdi      # 0x11f05
movq %r14, %rsi
xorl %eax, %eax
callq 0x10b0
movq 0x2494e(%rip), %rax     # 0x31028
movl $0x1, 0xd8(%rax)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0xc94f
movq %rbx, %rdi
callq 0xdfe9
movq 0x28(%rbx), %r13
movl $0xc, %r15d
testl %r12d, %r12d
movq %r13, -0x38(%rbp)
jne 0xc8ea
movl %eax, -0x2c(%rbp)
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0xb8e8
testq %rax, %rax
je 0xc897
xorl %eax, %eax
callq 0xe989
movq (%rbx), %r8
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
leaq 0x5c95(%rip), %rdi      # 0x123e6
movq %r14, %rsi
xorl %eax, %eax
callq 0x10b0
movq 0x248c6(%rip), %rax     # 0x31028
movl $0x1, 0xd8(%rax)
movl $0xfffffffe, %r15d      # imm = 0xFFFFFFFE
jmp 0xc8e7
leaq 0x5819(%rip), %r15      # 0x11f97
jmp 0xc787
leaq 0x58ad(%rip), %r15      # 0x12034
xorl %r13d, %r13d
xorl %eax, %eax
callq 0xe989
movq (%rbx), %r8
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
movq %r15, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x10b0
movq 0x24871(%rip), %rax     # 0x31028
movl $0x1, 0xd8(%rax)
movq %rbx, %rdi
callq 0xdfe9
testl %eax, %eax
je 0xc7f8
movl $0xfffffffe, %r15d      # imm = 0xFFFFFFFE
testb %r13b, %r13b
je 0xc94f
movq 0x28(%rbx), %rdi
movq %rbx, %rsi
movl $0x3, %edx
callq 0xb68b
movl $0xc, %r15d
jmp 0xc94f
movq 0x10(%rbx), %rax
movq 0x28(%rbx), %r15
movq 0x10(%rax), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0xb8e8
testq %rax, %rax
je 0xc84d
cmpl $0x37, 0x8(%rax)
jne 0xc872
cmpl $0x4, 0x8(%r15)
jne 0xc7cd
cmpq 0x28(%rax), %r15
jne 0xc7cd
xorl %eax, %eax
callq 0xe989
movq (%rbx), %r8
movq 0x10(%rbx), %rax
movq 0x10(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
leaq 0x5ac8(%rip), %rdi      # 0x12310
jmp 0xc92e
xorl %eax, %eax
callq 0xe989
movq (%rbx), %r8
movq 0x10(%rbx), %rax
movq 0x10(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
leaq 0x5950(%rip), %rdi      # 0x121bd
jmp 0xc92e
xorl %eax, %eax
callq 0xe989
movq (%rbx), %r8
movq 0x10(%rbx), %rax
movq 0x10(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
leaq 0x59c9(%rip), %rdi      # 0x1225b
jmp 0xc92e
movl $0x38, %edi
callq 0x1120
movq %r12, (%rax)
movl $0x37, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl $0x0, 0x20(%rax)
movq %r13, 0x28(%rax)
movl $0x1, 0x30(%rax)
movl $0xfffffff6, %ecx       # imm = 0xFFFFFFF6
subl 0x10c(%r13), %ecx
movl %ecx, 0x1c(%rax)
movl $0x2, 0x18(%rax)
movq %r13, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0xb68b
movl -0x2c(%rbp), %eax
testl %eax, %eax
jne 0xc94f
movq 0x10(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %r12
movq -0x38(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0xb8e8
testq %rax, %rax
je 0xc961
xorl %eax, %eax
callq 0xe989
movq (%rbx), %r8
movq 0x10(%rbx), %rax
movq 0x10(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
leaq 0x5ab8(%rip), %rdi      # 0x123e6
movq %r14, %rsi
xorl %eax, %eax
callq 0x10b0
movq 0x246e9(%rip), %rax     # 0x31028
movl $0x1, 0xd8(%rax)
movl $0xfffffffe, %r15d      # imm = 0xFFFFFFFE
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x38, %edi
callq 0x1120
movq %r12, (%rax)
movl $0x37, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl $0x0, 0x20(%rax)
movq %r13, 0x28(%rax)
movl $0x1, 0x30(%rax)
movl $0xfffffff8, %ecx       # imm = 0xFFFFFFF8
subl 0x10c(%r13), %ecx
movl %ecx, 0x1c(%rax)
movl $0x2, 0x18(%rax)
movq %r13, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0xb68b
jmp 0xc94f