// File: /workspace/github_c_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %r14
movb $0x0, -0x24(%rbp)
movw $0x4953, -0x26(%rbp)    # imm = 0x4953
movl (%rdi), %eax
leal -0x48(%rax), %ecx
cmpl $0x2, %ecx
jb 0x2108
cmpl $0x71, %eax
je 0x214a
cmpl $0x40, %eax
jne 0x2279
movq %rsi, %r15
movq 0x8(%r14), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0xac19
movq %rax, %rbx
movl 0x8(%rax), %eax
cmpl $0x37, %eax
je 0x217d
cmpl $0x39, %eax
jne 0x21ba
orb $0x4, 0x14284(%rip)     # 0x16359
leaq 0x1425c(%rip), %r15     # 0x16338
movq (%r15), %r14
movl 0x1c(%rbx), %edi
callq 0x156f
leaq 0xc94e(%rip), %rsi      # 0xea3c
leaq 0x1426b(%rip), %rcx     # 0x16360
leaq -0x26(%rbp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x10f0
movq (%r15), %rcx
jmp 0x213e
orb $0x4, 0x1424a(%rip)     # 0x16359
leaq 0x14222(%rip), %rbx     # 0x16338
movq (%rbx), %rdi
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
xorl %ecx, %ecx
cmpb $0x74, (%rax)
sete %cl
leaq 0xc384(%rip), %rsi      # 0xe4b4
leaq -0x26(%rbp), %rdx
xorl %eax, %eax
callq 0x10f0
movq (%rbx), %rcx
leaq 0xc37d(%rip), %rdi      # 0xe4c2
jmp 0x226e
orb $0x2, 0x14208(%rip)     # 0x16359
leaq 0x141e0(%rip), %rbx     # 0x16338
movq (%rbx), %rdi
movq 0x8(%r14), %rax
movq 0x8(%rax), %rcx
leaq 0xc0cc(%rip), %rsi      # 0xe236
leaq -0x26(%rbp), %rdx
xorl %eax, %eax
callq 0x10f0
movq (%rbx), %rcx
jmp 0x2267
orb $0x2, 0x141d5(%rip)     # 0x16359
leaq 0x141ad(%rip), %r15     # 0x16338
movq (%r15), %r14
movl 0x1c(%rbx), %edi
callq 0x156f
leaq 0xc89f(%rip), %rsi      # 0xea3c
leaq 0x141bc(%rip), %rcx     # 0x16360
leaq -0x26(%rbp), %rdx
movq %r14, %rdi
xorl %eax, %eax
callq 0x10f0
movq (%r15), %rcx
jmp 0x2267
movq 0x30(%r14), %rax
testq %rax, %rax
je 0x2286
cmpl $0x71, (%rax)
jne 0x2215
movq %rbx, %rdi
callq 0xcd66
testl %eax, %eax
je 0x2215
leaq 0x14159(%rip), %rax     # 0x16338
movq (%rax), %r15
pushq $0x2
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1757
movl %eax, %edi
callq 0x156f
leaq 0xc83e(%rip), %rsi      # 0xea3c
leaq 0x1415b(%rip), %rcx     # 0x16360
leaq -0x26(%rbp), %rdx
movq %r15, %rdi
xorl %eax, %eax
callq 0x10f0
jmp 0x223f
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x17a2
leaq 0x1410e(%rip), %rax     # 0x16338
movq (%rax), %rdi
leaq 0xc2a5(%rip), %rsi      # 0xe4d9
leaq -0x26(%rbp), %rdx
xorl %eax, %eax
callq 0x10f0
movq 0x10(%rbx), %rax
cmpl $0x37, (%rax)
movl 0x1410c(%rip), %eax     # 0x16358
jne 0x232b
orl $0x200, %eax            # imm = 0x200
movl %eax, 0x140fb(%rip)     # 0x16358
leaq 0x140d4(%rip), %rax     # 0x16338
movq (%rax), %rcx
leaq 0xc22f(%rip), %rdi      # 0xe49d
pushq $0x16
popq %rsi
pushq $0x1
popq %rdx
callq 0x1160
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc082(%rip), %rsi      # 0xe30f
movq %rbx, %rdi
callq 0x16c0
leaq 0xc87a(%rip), %rsi      # 0xeb16
movq %rbx, %rdi
callq 0x15ee
leaq 0xbfd7(%rip), %rsi      # 0xe282
movq %rbx, %rdi
callq 0x1657
leaq 0x1407e(%rip), %r12     # 0x16338
movq (%r12), %rcx
leaq 0xc22b(%rip), %rdi      # 0xe4f0
pushq $0xd
popq %r14
pushq $0x1
popq %r15
movq %r14, %rsi
movq %r15, %rdx
callq 0x1160
movq (%r12), %rcx
leaq 0xc21b(%rip), %rdi      # 0xe4fe
pushq $0xc
popq %rsi
movq %r15, %rdx
callq 0x1160
movq (%r12), %rcx
leaq 0xc212(%rip), %rdi      # 0xe50b
movq %r14, %rsi
movq %r15, %rdx
callq 0x1160
movq 0x10(%rbx), %rax
cmpl $0x37, (%rax)
movl 0x14047(%rip), %eax     # 0x16358
jne 0x2345
orl $0x800, %eax            # imm = 0x800
movl %eax, 0x1403a(%rip)     # 0x16358
movq (%r12), %rcx
leaq 0xc1f0(%rip), %rdi      # 0xe519
jmp 0x235b
orl $0x400, %eax            # imm = 0x400
movl %eax, 0x14022(%rip)     # 0x16358
leaq 0x13ffb(%rip), %rax     # 0x16338
movq (%rax), %rcx
jmp 0x213e
orl $0x1000, %eax           # imm = 0x1000
movl %eax, 0x14008(%rip)     # 0x16358
movq (%r12), %rcx
leaq 0xc1d8(%rip), %rdi      # 0xe533
pushq $0x19
popq %rsi
pushq $0x1
popq %rdx
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x1160