// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %r14
movb $0x0, -0x1c(%rbp)
movw $0x4953, -0x1e(%rbp)    # imm = 0x4953
movl (%rdi), %eax
leal -0x48(%rax), %ecx
cmpl $0x2, %ecx
jb 0x215c
cmpl $0x71, %eax
je 0x219e
cmpl $0x40, %eax
jne 0x22d3
movq %rsi, %r15
movq 0x8(%r14), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0xc430
movq %rax, %rbx
movl 0x8(%rax), %eax
cmpl $0x37, %eax
je 0x21d1
cmpl $0x39, %eax
jne 0x220e
orb $0x4, 0x16240(%rip)     # 0x18369
leaq 0x16218(%rip), %r15     # 0x18348
movq (%r15), %r14
movl 0x1c(%rbx), %edi
callq 0x158c
leaq 0xe8fa(%rip), %rsi      # 0x10a3c
leaq 0x16227(%rip), %rcx     # 0x18370
leaq -0x1e(%rbp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1100
movq (%r15), %rcx
jmp 0x2192
orb $0x4, 0x16206(%rip)     # 0x18369
leaq 0x161de(%rip), %rbx     # 0x18348
movq (%rbx), %rdi
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
xorl %ecx, %ecx
cmpb $0x74, (%rax)
sete %cl
leaq 0xe330(%rip), %rsi      # 0x104b4
leaq -0x1e(%rbp), %rdx
xorl %eax, %eax
callq 0x1100
movq (%rbx), %rcx
leaq 0xe329(%rip), %rdi      # 0x104c2
jmp 0x22c4
orb $0x2, 0x161c4(%rip)     # 0x18369
leaq 0x1619c(%rip), %rbx     # 0x18348
movq (%rbx), %rdi
movq 0x8(%r14), %rax
movq 0x8(%rax), %rcx
leaq 0xe078(%rip), %rsi      # 0x10236
leaq -0x1e(%rbp), %rdx
xorl %eax, %eax
callq 0x1100
movq (%rbx), %rcx
jmp 0x22bd
orb $0x2, 0x16191(%rip)     # 0x18369
leaq 0x16169(%rip), %r15     # 0x18348
movq (%r15), %r14
movl 0x1c(%rbx), %edi
callq 0x158c
leaq 0xe84b(%rip), %rsi      # 0x10a3c
leaq 0x16178(%rip), %rcx     # 0x18370
leaq -0x1e(%rbp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1100
movq (%r15), %rcx
jmp 0x22bd
movq 0x30(%r14), %rax
testq %rax, %rax
je 0x22de
cmpl $0x71, (%rax)
jne 0x226b
movq %rbx, %rdi
callq 0xe88a
testl %eax, %eax
je 0x226b
leaq 0x16115(%rip), %rax     # 0x18348
movq (%rax), %r15
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0x1778
movl %eax, %edi
callq 0x158c
leaq 0xe7e8(%rip), %rsi      # 0x10a3c
leaq 0x16115(%rip), %rcx     # 0x18370
leaq -0x1e(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0x1100
jmp 0x2295
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x17c3
leaq 0x160c8(%rip), %rax     # 0x18348
movq (%rax), %rdi
leaq 0xe24f(%rip), %rsi      # 0x104d9
leaq -0x1e(%rbp), %rdx
xorl %eax, %eax
callq 0x1100
movq 0x10(%rbx), %rax
cmpl $0x37, (%rax)
movl 0x160c6(%rip), %eax     # 0x18368
jne 0x2383
orl $0x200, %eax            # imm = 0x200
movl %eax, 0x160b5(%rip)     # 0x18368
leaq 0x1608e(%rip), %rax     # 0x18348
movq (%rax), %rcx
leaq 0xe1d9(%rip), %rdi      # 0x1049d
movl $0x16, %esi
movl $0x1, %edx
callq 0x1170
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe02a(%rip), %rsi      # 0x1030f
movq %rbx, %rdi
callq 0x16e1
leaq 0xe822(%rip), %rsi      # 0x10b16
movq %rbx, %rdi
callq 0x160f
leaq 0xdf7f(%rip), %rsi      # 0x10282
movq %rbx, %rdi
callq 0x1678
leaq 0x16036(%rip), %r14     # 0x18348
movq (%r14), %rcx
leaq 0xe1d4(%rip), %rdi      # 0x104f0
movl $0xd, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rcx
leaq 0xe1c9(%rip), %rdi      # 0x104fe
movl $0xc, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rcx
leaq 0xe1bd(%rip), %rdi      # 0x1050b
movl $0xd, %esi
movl $0x1, %edx
callq 0x1170
movq 0x10(%rbx), %rax
cmpl $0x37, (%rax)
movl 0x15ffe(%rip), %eax     # 0x18368
jne 0x239d
orl $0x800, %eax            # imm = 0x800
movl %eax, 0x15ff1(%rip)     # 0x18368
movq (%r14), %rcx
leaq 0xe198(%rip), %rdi      # 0x10519
jmp 0x23b2
orl $0x400, %eax            # imm = 0x400
movl %eax, 0x15fda(%rip)     # 0x18368
leaq 0x15fb3(%rip), %rax     # 0x18348
movq (%rax), %rcx
jmp 0x2192
orl $0x1000, %eax           # imm = 0x1000
movl %eax, 0x15fc0(%rip)     # 0x18368
movq (%r14), %rcx
leaq 0xe181(%rip), %rdi      # 0x10533
movl $0x19, %esi
movl $0x1, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1170