// File: /workspace/github_c_makefile_star2_O3/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 0x2150
cmpl $0x71, %eax
je 0x2192
cmpl $0x40, %eax
jne 0x22c7
movq %rsi, %r15
movq 0x8(%r14), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0xb8e8
movq %rax, %rbx
movl 0x8(%rax), %eax
cmpl $0x37, %eax
je 0x21c5
cmpl $0x39, %eax
jne 0x2202
orb $0x4, 0x1524c(%rip)     # 0x17369
leaq 0x15224(%rip), %r15     # 0x17348
movq (%r15), %r14
movl 0x1c(%rbx), %edi
callq 0x1580
leaq 0xd906(%rip), %rsi      # 0xfa3c
leaq 0x15233(%rip), %rcx     # 0x17370
leaq -0x1e(%rbp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1100
movq (%r15), %rcx
jmp 0x2186
orb $0x4, 0x15212(%rip)     # 0x17369
leaq 0x151ea(%rip), %rbx     # 0x17348
movq (%rbx), %rdi
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
xorl %ecx, %ecx
cmpb $0x74, (%rax)
sete %cl
leaq 0xd33c(%rip), %rsi      # 0xf4b4
leaq -0x1e(%rbp), %rdx
xorl %eax, %eax
callq 0x1100
movq (%rbx), %rcx
leaq 0xd335(%rip), %rdi      # 0xf4c2
jmp 0x22b8
orb $0x2, 0x151d0(%rip)     # 0x17369
leaq 0x151a8(%rip), %rbx     # 0x17348
movq (%rbx), %rdi
movq 0x8(%r14), %rax
movq 0x8(%rax), %rcx
leaq 0xd084(%rip), %rsi      # 0xf236
leaq -0x1e(%rbp), %rdx
xorl %eax, %eax
callq 0x1100
movq (%rbx), %rcx
jmp 0x22b1
orb $0x2, 0x1519d(%rip)     # 0x17369
leaq 0x15175(%rip), %r15     # 0x17348
movq (%r15), %r14
movl 0x1c(%rbx), %edi
callq 0x1580
leaq 0xd857(%rip), %rsi      # 0xfa3c
leaq 0x15184(%rip), %rcx     # 0x17370
leaq -0x1e(%rbp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x1100
movq (%r15), %rcx
jmp 0x22b1
movq 0x30(%r14), %rax
testq %rax, %rax
je 0x22d2
cmpl $0x71, (%rax)
jne 0x225f
movq %rbx, %rdi
callq 0xe01a
testl %eax, %eax
je 0x225f
leaq 0x15121(%rip), %rax     # 0x17348
movq (%rax), %r15
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2, %edx
callq 0x176c
movl %eax, %edi
callq 0x1580
leaq 0xd7f4(%rip), %rsi      # 0xfa3c
leaq 0x15121(%rip), %rcx     # 0x17370
leaq -0x1e(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0x1100
jmp 0x2289
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x17b7
leaq 0x150d4(%rip), %rax     # 0x17348
movq (%rax), %rdi
leaq 0xd25b(%rip), %rsi      # 0xf4d9
leaq -0x1e(%rbp), %rdx
xorl %eax, %eax
callq 0x1100
movq 0x10(%rbx), %rax
cmpl $0x37, (%rax)
movl 0x150d2(%rip), %eax     # 0x17368
jne 0x2377
orl $0x200, %eax            # imm = 0x200
movl %eax, 0x150c1(%rip)     # 0x17368
leaq 0x1509a(%rip), %rax     # 0x17348
movq (%rax), %rcx
leaq 0xd1e5(%rip), %rdi      # 0xf49d
movl $0x16, %esi
movl $0x1, %edx
callq 0x1170
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd036(%rip), %rsi      # 0xf30f
movq %rbx, %rdi
callq 0x16d5
leaq 0xd82e(%rip), %rsi      # 0xfb16
movq %rbx, %rdi
callq 0x1603
leaq 0xcf8b(%rip), %rsi      # 0xf282
movq %rbx, %rdi
callq 0x166c
leaq 0x15042(%rip), %r14     # 0x17348
movq (%r14), %rcx
leaq 0xd1e0(%rip), %rdi      # 0xf4f0
movl $0xd, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rcx
leaq 0xd1d5(%rip), %rdi      # 0xf4fe
movl $0xc, %esi
movl $0x1, %edx
callq 0x1170
movq (%r14), %rcx
leaq 0xd1c9(%rip), %rdi      # 0xf50b
movl $0xd, %esi
movl $0x1, %edx
callq 0x1170
movq 0x10(%rbx), %rax
cmpl $0x37, (%rax)
movl 0x1500a(%rip), %eax     # 0x17368
jne 0x2391
orl $0x800, %eax            # imm = 0x800
movl %eax, 0x14ffd(%rip)     # 0x17368
movq (%r14), %rcx
leaq 0xd1a4(%rip), %rdi      # 0xf519
jmp 0x23a6
orl $0x400, %eax            # imm = 0x400
movl %eax, 0x14fe6(%rip)     # 0x17368
leaq 0x14fbf(%rip), %rax     # 0x17348
movq (%rax), %rcx
jmp 0x2186
orl $0x1000, %eax           # imm = 0x1000
movl %eax, 0x14fcc(%rip)     # 0x17368
movq (%r14), %rcx
leaq 0xd18d(%rip), %rdi      # 0xf533
movl $0x19, %esi
movl $0x1, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1170