// File: /workspace/github_c_makefile_star2_O0/anuwu[P]ERPLAG-Compiler/codegen.c
// Function: dynamicDeclaration
void dynamicDeclaration (moduleST *lst, varST *vst, int declCount)
{
	RSPAlign () ;
	dynamicDeclarationCheck (lst, vst) ;

	codePrint ("\t\tPUSH BX") ;
	codeComment (12, "saving register for malloc") ;
	codePrint ("\t\tPUSH AX") ;
	codeComment (12, "saving register for malloc") ;

	int RSPsub ;

	if (declCount > 1)
	{
		char counterReg[3], mallocReg[5] ;
		
		#if defined __linux__ || defined __MACH__
			strcpy (counterReg, "CX") ;
			strcpy (mallocReg, "RDI") ;
			RSPsub = 10 ;
		#endif
		#ifdef _WIN64
			strcpy (counterReg, "AX") ;
			strcpy (mallocReg, "RCX") ;
			RSPsub = 42 ;
		#endif

		codePrint ("\t\tMOV RBX, %d\n", -vst->offset) ;
		codePrint ("\n\t\tMOV %s, 0\n", counterReg) ;

		codePrint ("\n\t.declLoop:\n") ;

		codePrint ("\t\tPUSH %s\n", counterReg) ;
		codePrint ("\t\tPUSH %s\n", mallocReg) ;
		codePrint ("\t\tPUSH RBX\n") ;
		codePrint ("\t\tSUB RSP, %d\n", RSPsub) ;

		#if defined __linux__ || defined _WIN64
			codePrint ("\t\tCALL malloc\n") ;
		#endif
		#ifdef __MACH__
			codePrint ("\t\tCALL _malloc\n") ;
		#endif

		codePrint ("\t\tADD RSP, %d\n", RSPsub) ;	
		codePrint ("\t\tPOP RBX\n") ;
		codePrint ("\t\tMOV [RBP + RBX], RAX\n") ;
		codePrint ("\t\tPOP %s\n", mallocReg) ;
		codePrint ("\t\tPOP %s\n", counterReg) ;
		
		codePrint ("\t\tPOP SI\n") ;
		codePrint ("\t\tMOV [RBP + RBX + 10], SI\n") ;
		codePrint ("\t\tPOP DI\n") ;
		codePrint ("\t\tMOV [RBP + RBX + 8], DI\n") ;
		codePrint ("\t\tPUSH DI\n") ;
		codePrint ("\t\tPUSH SI\n") ;
		codePrint ("\t\tADD RBX, 12\n") ;

		codePrint ("\t\tINC %s\n", counterReg) ;
		codePrint ("\t\tCMP %s, %d\n", counterReg, declCount) ;

		codePrint ("\t\tJL .declLoop\n") ;

		codePrint ("\t\tADD RSP, 4") ;
		codeComment (8, "Restoring array limits") ;
	}
	else
	{
		#if defined __linux__ || defined __MACH__
			RSPsub = 12 ;
		#endif
		#ifdef _WIN64
			RSPsub = 44 ;
		#endif

		codePrint ("\t\tSUB RSP, %d\n", RSPsub) ;

		#if defined __linux__ || defined _WIN64
			codePrint ("\t\tCALL malloc\n") ;
		#endif
		#ifdef __MACH__
			codePrint ("\t\tCALL _malloc\n") ;
		#endif

		codePrint ("\t\tADD RSP, %d\n", RSPsub) ;

		codePrint ("\t\tMOV [RBP%s], RAX\n", getOffsetStr(vst->offset)) ;
		codePrint ("\t\tPOP SI\n") ;
		codePrint ("\t\tMOV [RBP%s], SI\n", getOffsetStr(vst->offset - 10)) ;
		codePrint ("\t\tPOP DI\n") ;
		codePrint ("\t\tMOV [RBP%s], DI\n\n", getOffsetStr(vst->offset - 8)) ;
	}

	RSPRestore () ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
callq 0x2a20
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x2d80
leaq 0x1a3ec(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12983(%rip), %rsi     # 0x158c9
movb $0x0, %al
callq 0x10d0
movl $0xc, %edi
leaq 0x1297a(%rip), %rsi     # 0x158d3
callq 0x16c0
leaq 0x1a3c3(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x1297f(%rip), %rsi     # 0x158ee
movb $0x0, %al
callq 0x10d0
movl $0xc, %edi
leaq 0x12951(%rip), %rsi     # 0x158d3
callq 0x16c0
cmpl $0x1, -0x14(%rbp)
jle 0x323c
leaq -0x1b(%rbp), %rdi
leaq 0x12cf0(%rip), %rsi     # 0x15c8c
callq 0x1040
leaq -0x20(%rbp), %rdi
leaq 0x124d9(%rip), %rsi     # 0x15485
callq 0x1040
movl $0xa, -0x18(%rbp)
leaq 0x1a369(%rip), %rax     # 0x1d328
movq (%rax), %rdi
movq -0x10(%rbp), %rax
xorl %edx, %edx
subl 0x1c(%rax), %edx
leaq 0x12926(%rip), %rsi     # 0x158f8
movb $0x0, %al
callq 0x10d0
leaq 0x1a348(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x1b(%rbp), %rdx
leaq 0x12919(%rip), %rsi     # 0x15907
movb $0x0, %al
callq 0x10d0
leaq 0x1a32c(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x1290f(%rip), %rsi     # 0x15915
movb $0x0, %al
callq 0x10d0
leaq 0x1a314(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x1b(%rbp), %rdx
leaq 0x124d7(%rip), %rsi     # 0x154f9
movb $0x0, %al
callq 0x10d0
leaq 0x1a2f8(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x20(%rbp), %rdx
leaq 0x124bb(%rip), %rsi     # 0x154f9
movb $0x0, %al
callq 0x10d0
leaq 0x1a2dc(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x128cd(%rip), %rsi     # 0x15923
movb $0x0, %al
callq 0x10d0
leaq 0x1a2c4(%rip), %rax     # 0x1d328
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x128be(%rip), %rsi     # 0x1592f
movb $0x0, %al
callq 0x10d0
leaq 0x1a2a9(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x128b5(%rip), %rsi     # 0x1593e
movb $0x0, %al
callq 0x10d0
leaq 0x1a291(%rip), %rax     # 0x1d328
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x128a9(%rip), %rsi     # 0x1594d
movb $0x0, %al
callq 0x10d0
leaq 0x1a276(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x128a0(%rip), %rsi     # 0x1595c
movb $0x0, %al
callq 0x10d0
leaq 0x1a25e(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12893(%rip), %rsi     # 0x15967
movb $0x0, %al
callq 0x10d0
leaq 0x1a246(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x20(%rbp), %rdx
leaq 0x1288f(%rip), %rsi     # 0x1597f
movb $0x0, %al
callq 0x10d0
leaq 0x1a22a(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x1b(%rbp), %rdx
leaq 0x12873(%rip), %rsi     # 0x1597f
movb $0x0, %al
callq 0x10d0
leaq 0x1a20e(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12865(%rip), %rsi     # 0x15989
movb $0x0, %al
callq 0x10d0
leaq 0x1a1f6(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12857(%rip), %rsi     # 0x15993
movb $0x0, %al
callq 0x10d0
leaq 0x1a1de(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x1285b(%rip), %rsi     # 0x159af
movb $0x0, %al
callq 0x10d0
leaq 0x1a1c6(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x1284d(%rip), %rsi     # 0x159b9
movb $0x0, %al
callq 0x10d0
leaq 0x1a1ae(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12850(%rip), %rsi     # 0x159d4
movb $0x0, %al
callq 0x10d0
leaq 0x1a196(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12843(%rip), %rsi     # 0x159df
movb $0x0, %al
callq 0x10d0
leaq 0x1a17e(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12836(%rip), %rsi     # 0x159ea
movb $0x0, %al
callq 0x10d0
leaq 0x1a166(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x1b(%rbp), %rdx
leaq 0x12829(%rip), %rsi     # 0x159f9
movb $0x0, %al
callq 0x10d0
leaq 0x1a14a(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq -0x1b(%rbp), %rdx
movl -0x14(%rbp), %ecx
leaq 0x12814(%rip), %rsi     # 0x15a03
movb $0x0, %al
callq 0x10d0
leaq 0x1a12b(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x1280a(%rip), %rsi     # 0x15a11
movb $0x0, %al
callq 0x10d0
leaq 0x1a113(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12802(%rip), %rsi     # 0x15a21
movb $0x0, %al
callq 0x10d0
movl $0x8, %edi
leaq 0x127fc(%rip), %rsi     # 0x15a2e
callq 0x16c0
jmp 0x3354
movl $0xc, -0x18(%rbp)
leaq 0x1a0de(%rip), %rax     # 0x1d328
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x126d8(%rip), %rsi     # 0x1592f
movb $0x0, %al
callq 0x10d0
leaq 0x1a0c3(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x126cf(%rip), %rsi     # 0x1593e
movb $0x0, %al
callq 0x10d0
leaq 0x1a0ab(%rip), %rax     # 0x1d328
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x126c3(%rip), %rsi     # 0x1594d
movb $0x0, %al
callq 0x10d0
leaq 0x1a090(%rip), %rax     # 0x1d328
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %edi
callq 0x1730
movq -0x38(%rbp), %rdi
movq %rax, %rdx
leaq 0x1278c(%rip), %rsi     # 0x15a45
movb $0x0, %al
callq 0x10d0
leaq 0x1a061(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x126b8(%rip), %rsi     # 0x15989
movb $0x0, %al
callq 0x10d0
leaq 0x1a049(%rip), %rax     # 0x1d328
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %edi
subl $0xa, %edi
callq 0x1730
movq -0x30(%rbp), %rdi
movq %rax, %rdx
leaq 0x12756(%rip), %rsi     # 0x15a59
movb $0x0, %al
callq 0x10d0
leaq 0x1a017(%rip), %rax     # 0x1d328
movq (%rax), %rdi
leaq 0x12694(%rip), %rsi     # 0x159af
movb $0x0, %al
callq 0x10d0
leaq 0x19fff(%rip), %rax     # 0x1d328
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %edi
subl $0x8, %edi
callq 0x1730
movq -0x28(%rbp), %rdi
movq %rax, %rdx
leaq 0x1271f(%rip), %rsi     # 0x15a6c
movb $0x0, %al
callq 0x10d0
callq 0x2ab0
addq $0x40, %rsp
popq %rbp
retq
nop