// File: /workspace/github_c_makefile_star2_O1/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:
movl 0x8(%rdi), %ecx
movl $0x2, %eax
cmpl $0x37, %ecx
je 0xcfc5
cmpl $0x39, %ecx
je 0xcfc5
cmpl $0x38, %ecx
jne 0xcfc6
movl $0x1, 0x25064(%rip)     # 0x32024
movl $0x4, %eax
retq
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x28(%rdi), %rdi
callq 0xcb84
movq %rax, %r14
movq 0x10(%rbx), %rax
cmpl $0x38, (%rax)
jne 0xcff6
movl $0x1, 0x2502e(%rip)     # 0x32024
movq %rbx, %rdi
callq 0xe88a
testl %eax, %eax
je 0xd048
movq 0x10(%rbx), %r12
movq 0x8(%r12), %rax
movq 0x8(%rax), %rdi
callq 0x1140
movl %eax, %r15d
movq 0x10(%r12), %rax
movq 0x8(%rax), %rdi
callq 0x1140
cmpl $0x38, (%r12)
sete %cl
subl %r15d, %eax
incl %eax
incb %cl
shll %cl, %eax
testl %eax, %eax
jle 0xd0b8
cmpl $0x0, 0x30(%rbx)
movl $0x8, %ecx
jmp 0xd3ad
movl 0x30(%rbx), %r15d
movq %rbx, %rdi
callq 0xe828
movl %eax, %r13d
testl %r15d, %r15d
je 0xd0f9
xorl %r12d, %r12d
testl %r13d, %r13d
jne 0xd1cd
movq 0x10(%rbx), %rax
movq 0x28(%rbx), %r15
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0xc430
testq %rax, %rax
je 0xd180
cmpl $0x37, 0x8(%rax)
jne 0xd189
cmpl $0x4, 0x8(%r15)
jne 0xd1cd
cmpq 0x28(%rax), %r15
jne 0xd1cd
leaq 0x6025(%rip), %r15      # 0x130d8
jmp 0xd190
xorl %eax, %eax
callq 0xf205
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
leaq 0x5e21(%rip), %rdi      # 0x12ef5
movq %r14, %rsi
xorl %eax, %eax
callq 0x10b0
movq 0x24f43(%rip), %rax     # 0x32028
movl $0x1, 0xd8(%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xd3b0
movq %rbx, %rdi
callq 0xe859
movl %eax, %r12d
movq 0x28(%rbx), %rcx
xorl %r15d, %r15d
testl %r13d, %r13d
jne 0xd2e5
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %r13
movq %rcx, %r15
movq %rcx, %rdi
movq %r13, %rsi
callq 0xc430
testq %rax, %rax
je 0xd28c
xorl %eax, %eax
callq 0xf205
movq (%rbx), %r8
movq 0x10(%rbx), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
leaq 0x627f(%rip), %rdi      # 0x133d6
movq %r14, %rsi
xorl %eax, %eax
callq 0x10b0
movq 0x24ec0(%rip), %rax     # 0x32028
movl $0x1, 0xd8(%rax)
movq %r15, %rcx
movl $0x1, %r15d
jmp 0xd2e5
leaq 0x5e00(%rip), %r15      # 0x12f87
jmp 0xd190
leaq 0x5e94(%rip), %r15      # 0x13024
xorl %eax, %eax
callq 0xf205
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 0x24e6b(%rip), %rax     # 0x32028
movl $0x1, 0xd8(%rax)
movl $0x1, %r12d
movq %rbx, %rdi
callq 0xe859
testl %eax, %eax
jne 0xd263
movq 0x10(%rbx), %rax
movq 0x28(%rbx), %r15
movq 0x10(%rax), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0xc430
testq %rax, %rax
je 0xd216
cmpl $0x37, 0x8(%rax)
jne 0xd21f
cmpl $0x4, 0x8(%r15)
jne 0xd263
cmpq 0x28(%rax), %r15
jne 0xd263
leaq 0x60ec(%rip), %r15      # 0x13300
jmp 0xd226
leaq 0x5f90(%rip), %r15      # 0x131ad
jmp 0xd226
leaq 0x6025(%rip), %r15      # 0x1324b
xorl %eax, %eax
callq 0xf205
movq (%rbx), %r8
movq 0x10(%rbx), %rax
movq 0x10(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
movq %r15, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x10b0
movq 0x24dd5(%rip), %rax     # 0x32028
movl $0x1, 0xd8(%rax)
movl $0x1, %r12d
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
testl %r12d, %r12d
jne 0xd3b0
movq 0x28(%rbx), %rdi
movq %rbx, %rsi
movl $0x3, %edx
callq 0xc1d3
movl $0xc, %eax
jmp 0xd3b0
movl $0x38, %edi
callq 0x1120
movq %r13, (%rax)
movl $0x37, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl $0x0, 0x20(%rax)
movq %r15, 0x28(%rax)
movl $0x1, 0x30(%rax)
movl $0xfffffff6, %ecx       # imm = 0xFFFFFFF6
subl 0x10c(%r15), %ecx
movl %ecx, 0x1c(%rax)
movl $0x2, 0x18(%rax)
movq %r15, %r13
xorl %r15d, %r15d
movq %r13, %rdi
movq %rax, %rsi
xorl %edx, %edx
callq 0xc1d3
movq %r13, %rcx
testl %r12d, %r12d
jne 0xd3a0
movq 0x10(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %r12
movq %rcx, %r13
movq %rcx, %rdi
movq %r12, %rsi
callq 0xc430
testq %rax, %rax
je 0xd350
xorl %eax, %eax
callq 0xf205
movq (%rbx), %r8
movq 0x10(%rbx), %rax
movq 0x10(%rax), %rax
movl 0x10(%rax), %edx
movq 0x8(%rax), %rcx
leaq 0x60a9(%rip), %rdi      # 0x133d6
movq %r14, %rsi
xorl %eax, %eax
callq 0x10b0
movq 0x24cea(%rip), %rax     # 0x32028
movl $0x1, 0xd8(%rax)
movl $0x1, %r15d
jmp 0xd3a0
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 0xc1d3
testl %r15d, %r15d
movl $0xc, %ecx
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
cmovel %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq