// File: /workspace/github_c_makefile_star2_O0/anuwu[P]ERPLAG-Compiler/codegen.c
// Function: print
void print (astNode *node, moduleST *lst)
{
	int start_label, end_label ;
	int reserveLabel[2] ;

	char valReg[5] ;
	#if defined __linux__ || defined __MACH__
		strcpy (valReg, "SI") ;
	#endif
	#ifdef _WIN64
		strcpy (valReg, "DX") ;
	#endif

	varST *searchedVar ;
	if (node->id == TK_ID)
		searchedVar = searchVar (lst, node->tok->lexeme) ;
	else
	{
		if (node->id == TK_NUM)
		{
			tf |= 1 << printInteger ;
			codePrint ("\t\tMOV %s, %s\n", valReg, node->tok->lexeme) ;
			codePrint ("\t\tCALL @printInteger\n\n") ;
		}
		else if (node->id == TK_TRUE || node->id == TK_FALSE)
		{
			tf |= 1 << printBoolean ;
			codePrint ("\t\tMOV %s, %d\n", valReg, node->tok->lexeme[0]=='t'?1:0) ;
			codePrint ("\t\tCALL @printBoolean\n\n") ;
		}

		return ;
	}

	if (searchedVar->datatype == TK_INTEGER)
	{
		tf |= 1 << printInteger ;
		codePrint ("\t\tMOV %s, [RBP%s]\n", valReg, getOffsetStr(searchedVar->offset)) ;
		codePrint ("\t\tCALL @printInteger\n\n") ;
	}
	else if (searchedVar->datatype == TK_BOOLEAN)
	{
		tf |= 1 << printBoolean ;
		codePrint ("\t\tMOV %s, [RBP%s]\n", valReg, getOffsetStr(searchedVar->offset)) ;
		codePrint ("\t\tCALL @printBoolean\n\n") ;
	}
	else // Array type
	{	
		if (node->child != NULL)
		{
			// Special Case
			if (node->child->id == TK_NUM && isVarStaticArr (searchedVar))
				codePrint ("\t\tMOV %s, [RBP%s]\n", valReg, getOffsetStr(getStaticOffset(searchedVar,node,2))) ;
			else
			{
				// General case of static array with dynamic indices, or dynamic array
				arrBoundCheck (node, lst, searchedVar) ;
				codePrint ("\t\tMOV %s, [RDI + RBX]\n", valReg) ;
			}

			if (searchedVar->arrayIndices->type == TK_INTEGER)
			{
				tf |= 1 << printInteger ;
				codePrint ("\t\tCALL @printInteger\n\n") ;
			}
			else
			{
				tf |= 1 << printBoolean ;
				codePrint ("\t\tCALL @printBoolean\n\n") ;
			}
		}
		else
		{
			loadArrBase (searchedVar, "RDI") ;

			#if defined __linux__ || defined __MACH__
				loadRegLeftLim (searchedVar, "CX") ;
				loadRegRightLim (searchedVar, "DX") ;
				codePrint ("\t\tSUB DX, CX\n") ;
				codePrint ("\t\tADD DX, 1\n") ;
				codePrint ("\t\tADD DX, DX\n") ;
			#endif
			#ifdef _WIN64
				loadRegLeftLim (searchedVar, "AX") ;
				loadRegRightLim (searchedVar, "BX") ;
				codePrint ("\t\tSUB BX, AX\n") ;
				codePrint ("\t\tADD BX, 1\n") ;
				codePrint ("\t\tADD BX, BX\n") ;
			#endif

			if (searchedVar->arrayIndices->type == TK_INTEGER)
			{
				tf |= 1 << printIntegerArr ;
				codePrint ("\t\tCALL @printIntegerArr\n\n") ;
			}
			else
			{
				tf |= 1 << printBooleanArr ;
				codePrint ("\t\tCALL @printBooleanArr\n\n") ;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x25(%rbp), %rdi
leaq 0x13611(%rip), %rsi     # 0x15c5c
callq 0x1040
movq -0x8(%rbp), %rax
cmpl $0x40, (%rax)
jne 0x2677
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x10ba0
movq %rax, -0x30(%rbp)
jmp 0x274d
movq -0x8(%rbp), %rax
cmpl $0x71, (%rax)
jne 0x26d3
movl 0x1acc2(%rip), %eax     # 0x1d348
orl $0x200, %eax            # imm = 0x200
movl %eax, 0x1acb7(%rip)     # 0x1d348
leaq 0x1ac90(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x25(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rcx
leaq 0x12cfa(%rip), %rsi     # 0x153ac
movb $0x0, %al
callq 0x10d0
leaq 0x1ac68(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12f49(%rip), %rsi     # 0x15613
movb $0x0, %al
callq 0x10d0
jmp 0x2748
movq -0x8(%rbp), %rax
cmpl $0x48, (%rax)
je 0x26e5
movq -0x8(%rbp), %rax
cmpl $0x49, (%rax)
jne 0x2746
movl 0x1ac5d(%rip), %eax     # 0x1d348
orl $0x400, %eax            # imm = 0x400
movl %eax, 0x1ac52(%rip)     # 0x1d348
leaq 0x1ac2b(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x25(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rax
movsbl (%rax), %esi
xorl %ecx, %ecx
movl $0x1, %eax
cmpl $0x74, %esi
cmovel %eax, %ecx
leaq 0x12f03(%rip), %rsi     # 0x1562a
movb $0x0, %al
callq 0x10d0
leaq 0x1abf3(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12ef9(%rip), %rsi     # 0x15638
movb $0x0, %al
callq 0x10d0
jmp 0x2748
jmp 0x2a19
movq -0x30(%rbp), %rax
cmpl $0x37, 0x8(%rax)
jne 0x27c0
movl 0x1abeb(%rip), %eax     # 0x1d348
orl $0x200, %eax            # imm = 0x200
movl %eax, 0x1abe0(%rip)     # 0x1d348
leaq 0x1abb9(%rip), %rax     # 0x1d328
movq (%rax), %rax
movq %rax, -0x40(%rbp)
leaq -0x25(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movl 0x1c(%rax), %edi
callq 0x1730
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq %rax, %rcx
leaq 0x13416(%rip), %rsi     # 0x15bb2
movb $0x0, %al
callq 0x10d0
leaq 0x1ab7e(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12e5f(%rip), %rsi     # 0x15613
movb $0x0, %al
callq 0x10d0
jmp 0x2a19
movq -0x30(%rbp), %rax
cmpl $0x39, 0x8(%rax)
jne 0x2833
movl 0x1ab78(%rip), %eax     # 0x1d348
orl $0x400, %eax            # imm = 0x400
movl %eax, 0x1ab6d(%rip)     # 0x1d348
leaq 0x1ab46(%rip), %rax     # 0x1d328
movq (%rax), %rax
movq %rax, -0x50(%rbp)
leaq -0x25(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movl 0x1c(%rax), %edi
callq 0x1730
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rdx
movq %rax, %rcx
leaq 0x133a3(%rip), %rsi     # 0x15bb2
movb $0x0, %al
callq 0x10d0
leaq 0x1ab0b(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12e11(%rip), %rsi     # 0x15638
movb $0x0, %al
callq 0x10d0
jmp 0x2a17
movq -0x8(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x293a
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
cmpl $0x71, (%rax)
jne 0x28a7
movq -0x30(%rbp), %rdi
callq 0x13fc0
cmpl $0x0, %eax
je 0x28a7
leaq 0x1aac4(%rip), %rax     # 0x1d328
movq (%rax), %rax
movq %rax, -0x60(%rbp)
leaq -0x25(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl $0x2, %edx
callq 0x19f0
movl %eax, %edi
callq 0x1730
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rdx
movq %rax, %rcx
leaq 0x13314(%rip), %rsi     # 0x15bb2
movb $0x0, %al
callq 0x10d0
jmp 0x28d4
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x1a60
leaq 0x1aa69(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x25(%rbp), %rdx
leaq 0x12d82(%rip), %rsi     # 0x1564f
movb $0x0, %al
callq 0x10d0
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
cmpl $0x37, (%rax)
jne 0x290c
movl 0x1aa61(%rip), %eax     # 0x1d348
orl $0x200, %eax            # imm = 0x200
movl %eax, 0x1aa56(%rip)     # 0x1d348
leaq 0x1aa2f(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12d10(%rip), %rsi     # 0x15613
movb $0x0, %al
callq 0x10d0
jmp 0x2935
movl 0x1aa36(%rip), %eax     # 0x1d348
orl $0x400, %eax            # imm = 0x400
movl %eax, 0x1aa2b(%rip)     # 0x1d348
leaq 0x1aa04(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12d0a(%rip), %rsi     # 0x15638
movb $0x0, %al
callq 0x10d0
jmp 0x2a15
movq -0x30(%rbp), %rdi
leaq 0x12b40(%rip), %rsi     # 0x15485
callq 0x1900
movq -0x30(%rbp), %rdi
leaq 0x13337(%rip), %rsi     # 0x15c8c
callq 0x17e0
movq -0x30(%rbp), %rdi
leaq 0x12a93(%rip), %rsi     # 0x153f8
callq 0x1870
leaq 0x1a9b7(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12ceb(%rip), %rsi     # 0x15666
movb $0x0, %al
callq 0x10d0
leaq 0x1a99f(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12ce1(%rip), %rsi     # 0x15674
movb $0x0, %al
callq 0x10d0
leaq 0x1a987(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12cd6(%rip), %rsi     # 0x15681
movb $0x0, %al
callq 0x10d0
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
cmpl $0x37, (%rax)
jne 0x29ea
movl 0x1a983(%rip), %eax     # 0x1d348
orl $0x800, %eax            # imm = 0x800
movl %eax, 0x1a978(%rip)     # 0x1d348
leaq 0x1a951(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12cae(%rip), %rsi     # 0x1568f
movb $0x0, %al
callq 0x10d0
jmp 0x2a13
movl 0x1a958(%rip), %eax     # 0x1d348
orl $0x1000, %eax           # imm = 0x1000
movl %eax, 0x1a94d(%rip)     # 0x1d348
leaq 0x1a926(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12c9d(%rip), %rsi     # 0x156a9
movb $0x0, %al
callq 0x10d0
jmp 0x2a15
jmp 0x2a17
jmp 0x2a19
addq $0x60, %rsp
popq %rbp
retq
nop