// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x2
popq %r15
cmpl $0x37, %eax
je 0xb84c
cmpl $0x39, %eax
je 0xb84c
cmpl $0x38, %eax
jne 0xb7d2
movl $0x1, 0x24848(%rip)     # 0x30014
pushq $0x4
popq %r15
jmp 0xb84c
movq %rdi, %r14
movq 0x28(%rdi), %rdi
callq 0xb395
movq %rax, %rbx
movq 0x10(%r14), %rax
cmpl $0x38, (%rax)
jne 0xb7f4
movl $0x1, 0x24820(%rip)     # 0x30014
movq %r14, %rdi
callq 0xcd66
testl %eax, %eax
je 0xb85e
movq 0x10(%r14), %r13
movq 0x8(%r13), %rax
movq 0x8(%rax), %rdi
callq 0x1130
movl %eax, %r12d
movq 0x10(%r13), %rax
movq 0x8(%rax), %rdi
callq 0x1130
movl %eax, %r15d
cmpl $0x38, (%r13)
sete %cl
subl %r12d, %r15d
incl %r15d
incb %cl
shll %cl, %r15d
testl %r15d, %r15d
jle 0xb8ce
cmpl $0x0, 0x30(%r14)
pushq $0x8
popq %rax
cmovel %eax, %r15d
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x30(%r14), %r15d
movq %r14, %rdi
callq 0xcd04
movl %eax, %r12d
testl %r15d, %r15d
je 0xb90c
movb $0x1, %r13b
testl %r12d, %r12d
jne 0xb9da
movq 0x10(%r14), %rax
movq 0x28(%r14), %r15
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0xac19
testq %rax, %rax
je 0xb990
cmpl $0x37, 0x8(%rax)
jne 0xb999
cmpl $0x4, 0x8(%r15)
jne 0xb9da
cmpq 0x28(%rax), %r15
jne 0xb9da
leaq 0x580f(%rip), %r15      # 0x110d8
jmp 0xb9a0
xorl %eax, %eax
callq 0xd671
movq (%r14), %rcx
movq 0x10(%r14), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
leaq 0x560b(%rip), %rdi      # 0x10ef5
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10b0
movq 0x2471d(%rip), %rax     # 0x30018
movl $0x1, 0xd8(%rax)
pushq $-0x1
jmp 0xb7ce
movq %r14, %rdi
callq 0xcd35
movq 0x28(%r14), %r13
pushq $0xc
popq %r15
testl %r12d, %r12d
movq %r13, -0x38(%rbp)
jne 0xbad6
movl %eax, -0x2c(%rbp)
movq 0x10(%r14), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0xac19
testq %rax, %rax
je 0xbaa1
xorl %eax, %eax
callq 0xd671
movq (%r14), %r8
movq 0x10(%r14), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
leaq 0x5a6a(%rip), %rdi      # 0x113d6
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10b0
movq 0x2469b(%rip), %rax     # 0x30018
movl $0x1, 0xd8(%rax)
pushq $-0x2
popq %r15
jmp 0xbad3
leaq 0x55f0(%rip), %r15      # 0x10f87
jmp 0xb9a0
leaq 0x5684(%rip), %r15      # 0x11024
xorl %r13d, %r13d
xorl %eax, %eax
callq 0xd671
movq (%r14), %r8
movq 0x10(%r14), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
movq %r15, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10b0
movq 0x24648(%rip), %rax     # 0x30018
movl $0x1, 0xd8(%rax)
movq %r14, %rdi
callq 0xcd35
testl %eax, %eax
je 0xba05
testb %r13b, %r13b
je 0xbb39
movq 0x28(%r14), %rdi
pushq $0x3
popq %rdx
movq %r14, %rsi
callq 0xaa65
pushq $0xc
jmp 0xb7ce
movq 0x10(%r14), %rax
movq 0x28(%r14), %r15
movq 0x10(%rax), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0xac19
testq %rax, %rax
je 0xba5a
cmpl $0x37, 0x8(%rax)
jne 0xba7f
cmpl $0x4, 0x8(%r15)
jne 0xb9e6
cmpq 0x28(%rax), %r15
jne 0xb9e6
xorl %eax, %eax
callq 0xd671
movq (%r14), %r8
movq 0x10(%r14), %rax
movq 0x10(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
leaq 0x58ab(%rip), %rdi      # 0x11300
jmp 0xbb1e
xorl %eax, %eax
callq 0xd671
movq (%r14), %r8
movq 0x10(%r14), %rax
movq 0x10(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
leaq 0x5733(%rip), %rdi      # 0x111ad
jmp 0xbb1e
xorl %eax, %eax
callq 0xd671
movq (%r14), %r8
movq 0x10(%r14), %rax
movq 0x10(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
leaq 0x57ac(%rip), %rdi      # 0x1124b
jmp 0xbb1e
pushq $0x1
popq %rdx
pushq $0x37
popq %rcx
movq %r12, %rdi
movq %r13, %rsi
callq 0xa95c
pushq $-0xa
popq %rcx
subl 0x10c(%r13), %ecx
movl %ecx, 0x1c(%rax)
movl $0x2, 0x18(%rax)
movq %r13, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0xaa65
movl -0x2c(%rbp), %eax
testl %eax, %eax
jne 0xb84c
movq 0x10(%r14), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %r12
movq -0x38(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0xac19
testq %rax, %rax
je 0xbb40
xorl %eax, %eax
callq 0xd671
movq (%r14), %r8
movq 0x10(%r14), %rax
movq 0x10(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
leaq 0x58b8(%rip), %rdi      # 0x113d6
movq %rbx, %rsi
xorl %eax, %eax
callq 0x10b0
movq 0x244e9(%rip), %rax     # 0x30018
movl $0x1, 0xd8(%rax)
pushq $-0x2
jmp 0xb7ce
pushq $0x1
popq %rdx
pushq $0x37
popq %rcx
movq %r12, %rdi
movq %r13, %rsi
callq 0xa95c
pushq $-0x8
popq %rcx
subl 0x10c(%r13), %ecx
movl %ecx, 0x1c(%rax)
movl $0x2, 0x18(%rax)
movq %r13, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0xaa65
jmp 0xb84c