// File: /workspace/github_c_makefile_star2_O2/anuwu[P]ERPLAG-Compiler/codegen.c
// Function: getValue
void getValue (moduleST *lst, varST *vst)
{		
	int rspAlign ;
	df |= 1 << inputInt ;
	char promptReg[5] ;

	#if defined __linux__ || defined __MACH__
		strcpy (promptReg, "RDI") ;
	#endif
	#ifdef _WIN64
		strcpy (promptReg, "RCX") ;
	#endif

	if (vst->datatype == TK_INTEGER || vst->datatype == TK_BOOLEAN)
	{
		if (vst->datatype == TK_INTEGER)
		{
			df |= 1 << inputIntPrompt ;
			codePrint ("\n\t\tMOV %s, @inputIntPrompt", promptReg) ;
		}
		else if (vst->datatype == TK_BOOLEAN)
		{
			df |= 1 << inputBoolPrompt ;
			codePrint ("\n\t\tMOV %s, @inputBoolPrompt", promptReg) ;
		}
		codeComment (9, "get_value") ;


		tf |= 1 << getValuePrimitive ;
		codePrint ("\t\tMOV RBX, -%d\n", vst->offset) ;
		codePrint ("\t\tCALL @getValuePrimitive\n\n") ;		
 	}
	else // Array type
	{	
		if (vst->arrayIndices->type == TK_INTEGER)
		{
			df |= 1 << inputIntArrPrompt ;
			codePrint ("\t\tMOV %s, @inputIntArrPrompt\n", promptReg) ;
		}
		else
		{
			df |= 1 << inputBoolArrPrompt ;
			codePrint ("\t\tMOV %s, @inputBoolArrPrompt\n", promptReg) ;
		}

		tf |= 1 << printGetArrPrompt ;
		tf |= 1 << getArr ;

		#if defined __linux__ || defined __MACH__
			loadRegLeftLim (vst, "BX") ;
			loadRegRightLim (vst, "CX") ;
		#endif
		#ifdef _WIN64
			loadRegLeftLim (vst, "SI") ;
			loadRegRightLim (vst, "DI") ;
		#endif
		codePrint ("\t\tCALL @printGetArrPrompt\n\n") ;

		#if defined __linux__ || defined __MACH__		
			codePrint ("\t\tMOV DX, CX\n") ;
			codePrint ("\t\tSUB DX, BX\n") ;
			codePrint ("\t\tADD DX, 1\n") ;
			codePrint ("\t\tADD DX, DX\n") ;
			codePrint ("\t\tMOVSX RDX, DX\n") ;
		#endif
		#ifdef _WIN64
			codePrint ("\t\tMOV BX, DI\n") ;
			codePrint ("\t\tSUB BX, SI\n") ;
			codePrint ("\t\tADD BX, 1\n") ;
			codePrint ("\t\tADD BX, BX\n") ;
			codePrint ("\t\tMOVSX RBX, BX\n") ;
		#endif

		loadArrBase (vst, "RDI") ;
		codePrint ("\t\tCALL @getArr\n\n") ;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movl 0x13eea(%rip), %eax     # 0x1635c
movl %eax, %ecx
orl $0x100000, %ecx         # imm = 0x100000
movl %ecx, 0x13edc(%rip)     # 0x1635c
movl $0x494452, -0x28(%rbp)  # imm = 0x494452
movl 0x8(%rsi), %ecx
cmpl $0x37, %ecx
je 0x24a2
cmpl $0x39, %ecx
jne 0x250a
leaq 0xc14a(%rip), %rsi      # 0xe5e5
movl $0x108000, %ecx         # imm = 0x108000
jmp 0x24ae
leaq 0xc121(%rip), %rsi      # 0xe5ca
movl $0x104000, %ecx         # imm = 0x104000
orl %ecx, %eax
movl %eax, 0x13ea6(%rip)     # 0x1635c
leaq 0x13e7b(%rip), %r14     # 0x16338
movq (%r14), %rdi
leaq -0x28(%rbp), %rdx
xorl %eax, %eax
callq 0x10f0
leaq 0xc12f(%rip), %rsi      # 0xe601
pushq $0x9
popq %rdi
callq 0x151a
orb $-0x80, 0x13e77(%rip)   # 0x16358
movq (%r14), %rdi
movl 0x1c(%rbx), %edx
leaq 0xc11d(%rip), %rsi      # 0xe60b
xorl %eax, %eax
callq 0x10f0
movq (%r14), %rcx
leaq 0xc11c(%rip), %rdi      # 0xe61b
pushq $0x1b
popq %rsi
pushq $0x1
popq %rdx
jmp 0x2627
movq 0x10(%rbx), %rcx
xorl %edx, %edx
cmpl $0x37, (%rcx)
setne %dl
leaq 0xc11a(%rip), %rcx      # 0xe637
leaq 0xc131(%rip), %rsi      # 0xe655
cmoveq %rcx, %rsi
shll $0x10, %edx
addl $0x110000, %edx         # imm = 0x110000
orl %edx, %eax
movl %eax, 0x13e23(%rip)     # 0x1635c
leaq 0x13df8(%rip), %r12     # 0x16338
movq (%r12), %rdi
leaq -0x28(%rbp), %rdx
xorl %eax, %eax
callq 0x10f0
orl $0x140, 0x13dff(%rip)   # imm = 0x140
leaq 0xc1fa(%rip), %rsi      # 0xe75a
movq %rbx, %rdi
callq 0x15ee
leaq 0xc5a7(%rip), %rsi      # 0xeb16
movq %rbx, %rdi
callq 0x1657
movq (%r12), %rcx
leaq 0xc0f2(%rip), %rdi      # 0xe674
pushq $0x1b
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
callq 0x1160
movq (%r12), %rcx
leaq 0xc0f4(%rip), %rdi      # 0xe690
pushq $0xd
popq %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0x1160
movq (%r12), %rcx
leaq 0xc0e8(%rip), %rdi      # 0xe69e
movq %r15, %rsi
movq %r14, %rdx
callq 0x1160
movq (%r12), %rcx
leaq 0xbf32(%rip), %rdi      # 0xe4fe
pushq $0xc
popq %rsi
movq %r14, %rdx
callq 0x1160
movq (%r12), %rcx
leaq 0xbf29(%rip), %rdi      # 0xe50b
movq %r15, %rsi
movq %r14, %rdx
callq 0x1160
movq (%r12), %rcx
leaq 0xc0b4(%rip), %rdi      # 0xe6ac
pushq $0x10
popq %r15
movq %r15, %rsi
movq %r14, %rdx
callq 0x1160
leaq 0xbd01(%rip), %rsi      # 0xe30f
movq %rbx, %rdi
callq 0x16c0
movq (%r12), %rcx
leaq 0xc09c(%rip), %rdi      # 0xe6bd
movq %r15, %rsi
movq %r14, %rdx
callq 0x1160
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq