// File: /workspace/github_c_makefile_star2_O0/anuwu[P]ERPLAG-Compiler/typeChecker.c
// Function: assignmentTypeCheck
void assignmentTypeCheck (moduleST *baseModule, astNode *assignopASTNode)
{
	varST *searchedVarLeft, *searchedVarRight ;
	tokenID typeLeft, typeRight ;

	if (assignopASTNode->child->next->child == NULL && assignopASTNode->child->next->id == TK_ID) // Simple assignment with RHS also as ID
	{	
		typeLeft = validateVar (baseModule, assignopASTNode->child, &searchedVarLeft) ;
		typeRight = validateVar (baseModule, assignopASTNode->child->next, &searchedVarRight) ;

		if (typeLeft == TK_ARRAY && typeRight == TK_ARRAY) 	// Array assignment
		{
			if (searchedVarLeft->arrayIndices->type == searchedVarRight->arrayIndices->type)
			{
				if (isVarStaticArr (searchedVarLeft) && isVarStaticArr (searchedVarRight))
				{
					int leftLim1, rightLim1, leftLim2, rightLim2 ;	
					leftLim1 = atoi (searchedVarLeft->arrayIndices->tokLeft->lexeme) ;
					rightLim1 = atoi (searchedVarLeft->arrayIndices->tokRight->lexeme) ;
					leftLim2 = atoi (searchedVarRight->arrayIndices->tokLeft->lexeme) ;
					rightLim2 = atoi (searchedVarRight->arrayIndices->tokRight->lexeme) ;

					if (leftLim1 != leftLim2 || rightLim1 != rightLim2)
					{
						errSemantic () ;
						#ifdef _WIN64
							printf ("In module \"%s\" at line %d, array variables \"%s\" and \"%s\" do not have matching bounds for assignment\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, searchedVarLeft->lexeme, searchedVarRight->lexeme) ;
						#endif
						#if defined __linux__ || defined __MACH__
							printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variables " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " and " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " do not have matching bounds for assignment\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, searchedVarLeft->lexeme, searchedVarRight->lexeme) ;
						#endif
						realBase->semanticError = 1 ;
					}
				}
			}
			else
			{
				errSemantic () ;
				#ifdef _WIN64
					printf ("In module \"%s\" at line %d, array variables \"%s\" and \"%s\" do not have the same base type\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, searchedVarLeft->lexeme, searchedVarRight->lexeme) ;
				#endif
				#if defined __linux__ || defined __MACH__
					printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variables " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " and " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " do not have the same base type\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, searchedVarLeft->lexeme, searchedVarRight->lexeme) ;
				#endif
				realBase->semanticError = 1 ;
			}
		}
		else if (typeLeft != 0 && typeRight != 0)
		{
			if (typeLeft != TK_ARRAY && typeRight == TK_ARRAY)
			{
				errSemantic () ;
				#ifdef _WIN64
					printf ("In module \"%s\" at line %d, array variable \"%s\" cannot be assigned to primitive variable \"%s\"\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, searchedVarRight->lexeme, searchedVarLeft->lexeme) ;
				#endif
				#if defined __linux__ || defined __MACH__
					printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " cannot be assigned to " ANSI_BOLD ANSI_BLACK "primitive" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET "\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, searchedVarRight->lexeme, searchedVarLeft->lexeme) ;
				#endif
				realBase->semanticError = 1 ;
			}
			else if (typeRight != TK_ARRAY && typeLeft == TK_ARRAY)
			{
				errSemantic () ;
				#ifdef _WIN64
					printf ("In module \"%s\" at line %d, primitive variable \"%s\" cannot be assigned to array variable \"%s\"\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, searchedVarRight->lexeme, searchedVarLeft->lexeme) ;
				#endif
				#if defined __linux__ || defined __MACH__
					printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", " ANSI_BOLD ANSI_BLACK "primitive" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " cannot be assigned to " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET "\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, searchedVarRight->lexeme, searchedVarLeft->lexeme) ;
				#endif
				realBase->semanticError = 1 ;

			}
			else if (typeLeft != typeRight)
			{
				errSemantic () ;
				#ifdef _WIN64
					printf ("In module \"%s\" at line %d, assignment of \"%s\" to \"%s\" are in type conflict\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, searchedVarRight->lexeme, searchedVarLeft->lexeme) ;
				#endif
				#if defined __linux__ || defined __MACH__
					printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", assignment of " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " to " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " are in type conflict\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, searchedVarRight->lexeme, searchedVarLeft->lexeme) ;
				#endif
				realBase->semanticError = 1 ;
			}

			tinkerVar (baseModule, searchedVarLeft, assignopASTNode->child) ;
		}

		return ;
	}
	else if (assignopASTNode->child->next->child != NULL && assignopASTNode->child->next->child->next == NULL && (assignopASTNode->child->next->id == TK_PLUS || assignopASTNode->child->next->id == TK_MINUS)) // <U>
		typeRight = getExpressionType (baseModule, assignopASTNode->child->next->child) ;
	else	// expression_new
		typeRight = getExpressionType (baseModule, assignopASTNode->child->next) ;

	/* ------------------------------------------------------------------------------------------------------------------*/

	typeLeft = validateVar (baseModule, assignopASTNode->child, &searchedVarLeft) ;
	if (!typeLeft)
		return ;
	else
	{ 
		tinkerVar (baseModule, searchedVarLeft, assignopASTNode->child) ;
		if (typeLeft == TK_ARRAY)
		{
			errSemantic () ;
			#ifdef _WIN64
				printf ("In module \"%s\" at line %d, the assignment of an expression to array variable \"%s\" cannot be made\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, assignopASTNode->child->tok->lexeme) ;
			#endif
			#if defined __linux__ || defined __MACH__
				printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", the assignment of an expression to " ANSI_BOLD ANSI_BLACK "array" ANSI_RESET " variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " cannot be made\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, assignopASTNode->child->tok->lexeme) ;
			#endif
			realBase->semanticError = 1 ;
			return ;
		}
	}

	if (!typeRight)
		return ;
	else if (typeLeft != typeRight)
	{
		errSemantic () ;
		#ifdef _WIN64
			printf ("In module \"%s\" at line %d, assignment of expression of type \"%s\" to the variable \"%s\" of type \"%s\" cannot be made\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, typeIDToString(typeRight), assignopASTNode->child->tok->lexeme, typeIDToString(typeLeft)) ;
		#endif
		#if defined __linux__ || defined __MACH__
			printf ("In module " ANSI_BOLD "%s" ANSI_RESET " at line " ANSI_BOLD ANSI_CYAN "%d" ANSI_RESET ", assignment of expression of type " ANSI_BOLD ANSI_GREEN "%s" ANSI_RESET " to the variable " ANSI_BOLD ANSI_RED "%s" ANSI_RESET " of type " ANSI_BOLD ANSI_GREEN "%s" ANSI_RESET " cannot be made\n", getParentModuleName (baseModule), assignopASTNode->tok->lineNumber, typeIDToString(typeRight), assignopASTNode->child->tok->lexeme, typeIDToString(typeLeft)) ;
		#endif
		realBase->semanticError = 1 ;
		return ;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x38(%rax), %rax
cmpq $0x0, 0x30(%rax)
jne 0x14a9c
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x38(%rax), %rax
cmpl $0x40, (%rax)
jne 0x14a9c
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
leaq -0x18(%rbp), %rdx
callq 0x14200
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x38(%rax), %rsi
leaq -0x20(%rbp), %rdx
callq 0x14200
movl %eax, -0x28(%rbp)
cmpl $0x3b, -0x24(%rbp)
jne 0x14957
cmpl $0x3b, -0x28(%rbp)
jne 0x14957
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl (%rax), %eax
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rcx
cmpl (%rcx), %eax
jne 0x14904
movq -0x18(%rbp), %rdi
callq 0x13fc0
cmpl $0x0, %eax
je 0x14902
movq -0x20(%rbp), %rdi
callq 0x13fc0
cmpl $0x0, %eax
je 0x14902
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x1100
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x1100
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x1100
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x1100
movl %eax, -0x38(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x148b2
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
je 0x14900
movb $0x0, %al
callq 0x14d10
movq -0x8(%rbp), %rdi
callq 0x116e0
movq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq (%rax), %r8
leaq 0x4ba5(%rip), %rdi      # 0x1948a
movb $0x0, %al
callq 0x1090
leaq 0x22715(%rip), %rax     # 0x37008
movq (%rax), %rax
movl $0x1, 0xd8(%rax)
jmp 0x14902
jmp 0x14952
movb $0x0, %al
callq 0x14d10
movq -0x8(%rbp), %rdi
callq 0x116e0
movq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
movq -0x18(%rbp), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq (%rax), %r8
leaq 0x4bee(%rip), %rdi      # 0x19525
movb $0x0, %al
callq 0x1090
leaq 0x226c3(%rip), %rax     # 0x37008
movq (%rax), %rax
movl $0x1, 0xd8(%rax)
jmp 0x14a97
cmpl $0x0, -0x24(%rbp)
je 0x14a95
cmpl $0x0, -0x28(%rbp)
je 0x14a95
cmpl $0x3b, -0x24(%rbp)
je 0x149ca
cmpl $0x3b, -0x28(%rbp)
jne 0x149ca
movb $0x0, %al
callq 0x14d10
movq -0x8(%rbp), %rdi
callq 0x116e0
movq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %r8
leaq 0x4c0a(%rip), %rdi      # 0x195b4
movb $0x0, %al
callq 0x1090
leaq 0x22650(%rip), %rax     # 0x37008
movq (%rax), %rax
movl $0x1, 0xd8(%rax)
jmp 0x14a80
cmpl $0x3b, -0x28(%rbp)
je 0x14a26
cmpl $0x3b, -0x24(%rbp)
jne 0x14a26
movb $0x0, %al
callq 0x14d10
movq -0x8(%rbp), %rdi
callq 0x116e0
movq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %r8
leaq 0x4c4c(%rip), %rdi      # 0x19655
movb $0x0, %al
callq 0x1090
leaq 0x225f1(%rip), %rax     # 0x37008
movq (%rax), %rax
movl $0x1, 0xd8(%rax)
jmp 0x14a7e
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
je 0x14a7c
movb $0x0, %al
callq 0x14d10
movq -0x8(%rbp), %rdi
callq 0x116e0
movq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq -0x18(%rbp), %rax
movq (%rax), %r8
leaq 0x4c95(%rip), %rdi      # 0x196f6
movb $0x0, %al
callq 0x1090
leaq 0x22599(%rip), %rax     # 0x37008
movq (%rax), %rax
movl $0x1, 0xd8(%rax)
jmp 0x14a7e
jmp 0x14a80
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdx
callq 0x12460
jmp 0x14a97
jmp 0x14c4e
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x38(%rax), %rax
cmpq $0x0, 0x30(%rax)
je 0x14b06
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x38(%rax), %rax
movq 0x30(%rax), %rax
cmpq $0x0, 0x38(%rax)
jne 0x14b06
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x38(%rax), %rax
cmpl $0x57, (%rax)
je 0x14ae8
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x38(%rax), %rax
cmpl $0x58, (%rax)
jne 0x14b06
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x38(%rax), %rax
movq 0x30(%rax), %rsi
callq 0x144e0
movl %eax, -0x28(%rbp)
jmp 0x14b1e
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x38(%rax), %rsi
callq 0x144e0
movl %eax, -0x28(%rbp)
jmp 0x14b20
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rsi
leaq -0x18(%rbp), %rdx
callq 0x14200
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jne 0x14b43
jmp 0x14c4e
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdx
callq 0x12460
cmpl $0x3b, -0x24(%rbp)
jne 0x14bb3
movb $0x0, %al
callq 0x14d10
movq -0x8(%rbp), %rdi
callq 0x116e0
movq %rax, %rsi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %edx
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rcx
leaq 0x4bd8(%rip), %rdi      # 0x1976b
movb $0x0, %al
callq 0x1090
leaq 0x22467(%rip), %rax     # 0x37008
movq (%rax), %rax
movl $0x1, 0xd8(%rax)
jmp 0x14c4e
jmp 0x14bb5
cmpl $0x0, -0x28(%rbp)
jne 0x14bc0
jmp 0x14c4e
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
je 0x14c4c
movb $0x0, %al
callq 0x14d10
movq -0x8(%rbp), %rdi
callq 0x116e0
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x10(%rax), %eax
movl %eax, -0x4c(%rbp)
movl -0x28(%rbp), %edi
callq 0x12370
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movl -0x24(%rbp), %edi
callq 0x12370
movq -0x58(%rbp), %rsi
movl -0x4c(%rbp), %edx
movq -0x48(%rbp), %rcx
movq -0x40(%rbp), %r8
movq %rax, %r9
leaq 0x4bc9(%rip), %rdi      # 0x197f8
movb $0x0, %al
callq 0x1090
leaq 0x223cb(%rip), %rax     # 0x37008
movq (%rax), %rax
movl $0x1, 0xd8(%rax)
jmp 0x14c4e
jmp 0x14c4e
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop