// File: /workspace/github_cpp_makefile_star2_O2/AndrewAlbert[P]Compiler-Theory/SourceCode/codeGenerator.cpp
// Function: codeGenerator::reg2mm[abi:cxx11](int, int, int, int, int, bool, bool, int, bool)
string codeGenerator::reg2mm(int regType, int memType, int regSize, int memSize, int FPoffset, bool isGlobal, bool indirect, int indirect_type, bool useSP ){
	if( !ShouldGenerate() ) return "";
	int index;
	string reg, mem, indirect_reg, pointer;

	if( useSP ) pointer = "SP_reg";
	else pointer = "FP_reg";
	
	if( regSize == 0 ) regSize++;
	if( memSize == 0 ) memSize++;
	
	for( index = 0; index < regSize; index++ ){
		reg = popStack('E', regType);
		pushStack( reg, 'R', regType );
	}

	if( indirect ){
		if(savedArgument.set == false) cout << "not a saved argument" << endl;
		reg = popStack('R', regType);
		indirect_reg = popStack('E', indirect_type);
		comment("indirect off " + indirect_reg);
		fprintf( oFile, "   TP_reg = %s + %d;\n", pointer.c_str(), FPoffset );
		fprintf( oFile, "   MM[TP_reg + %s] = %s;\n", indirect_reg.c_str(), reg.c_str() );
	}
	else{
		if( isGlobal ) comment("Global Variable: Reg to MM");
		else comment("Variable: Reg to MM");
		
		if( regSize > 1 && regSize == memSize ){
			for( index = 0; index < memSize; index++ ){
				reg = popStack('R', regType);
				if( isGlobal ){
					mem = "MM[" + to_string(FPoffset + index) + "]";
				}
				else{
					mem = "MM[" + pointer + " + " + to_string(FPoffset + index) + "]";
				}
				if( memType == TYPE_FLOAT) fprintf( oFile, "   memcpy( &%s, &%s, sizeof(int) );\n", mem.c_str(), reg.c_str() );
				else fprintf( oFile, "   %s = %s;\n", mem.c_str(), reg.c_str() );
			}
		}
		else if ( regSize == 1 ){
			reg = popStack('R', regType);
			for( index = 0; index < memSize; index++ ){
				if( isGlobal ){
					mem = "MM[" + to_string(FPoffset + index) + "]";
				}
				else{
					mem = "MM[" + pointer + " + " + to_string(FPoffset + index) + "]";
				}
				if( memType == TYPE_FLOAT) fprintf( oFile, "   memcpy( &%s, &%s, sizeof(int) );\n", mem.c_str(), reg.c_str() );
				else fprintf( oFile, "   %s = %s;\n", mem.c_str(), reg.c_str() );
			}
		}
	}
	return "";
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movl %edx, 0x4(%rsp)
movq %rdi, %rbx
cmpb $0x0, 0x330(%rsi)
je 0xe479
movl %r9d, %ebp
movl %r8d, %r12d
movq %rsi, %r15
movl %ecx, 0x10(%rsp)
movq %rbx, 0x80(%rsp)
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %r14d, %r14d
leaq 0x70(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb %r14b, (%rax)
movb %r14b, (%rcx)
leaq 0x138(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq 0x98(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb 0x220(%rsp), %dl
movb %r14b, (%rax)
movb %r14b, (%rcx)
leaq 0x45fa(%rip), %rax      # 0x129b1
leaq 0x45ec(%rip), %rsi      # 0x129aa
testb %dl, %dl
cmovneq %rax, %rsi
leaq 0x88(%rsp), %rdi
callq 0x2370
cmpl $0x1, %r12d
movl %r12d, 0x1c(%rsp)
adcl $0x0, %r12d
movl 0x200(%rsp), %eax
movl %eax, (%rsp)
cmpl $0x1, %ebp
adcl $0x0, %ebp
movl %ebp, 0x14(%rsp)
movq %r15, %rbp
leaq 0x180(%r15), %rax
movq %rax, 0x8(%rsp)
testl %r12d, %r12d
movl %r12d, 0x18(%rsp)
cmovgl %r12d, %r14d
leaq 0x20(%rsp), %rbx
pushq $0x45
popq %r12
leaq 0x40(%rsp), %r13
leaq 0x1a8(%rsp), %r15
subl $0x1, %r14d
jb 0xe492
movq %rbx, %rdi
movq %rbp, %rsi
movl %r12d, %edx
movl 0x4(%rsp), %ecx
callq 0xc92c
movq %r13, %rdi
movq %rbx, %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x20f0
movq %r15, %rdi
movq %r13, %rsi
callq 0x2270
cmpb $0x1, 0x330(%rbp)
jne 0xe46f
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0xfbc6
movq %r15, %rdi
callq 0x20f0
jmp 0xe423
leaq 0x44bd(%rip), %rsi      # 0x1293d
leaq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x36b8
jmp 0xe9a4
cmpb $0x0, 0x210(%rsp)
je 0xe5a8
cmpb $0x0, 0x2b6(%rbp)
jne 0xe4c4
movq 0xcb20(%rip), %rdi      # 0x1afd0
leaq 0x4aaf(%rip), %rsi      # 0x12f66
callq 0x21c0
movq %rax, %rdi
callq 0x2100
leaq 0x20(%rsp), %rdi
pushq $0x52
popq %rdx
movq %rbp, %rsi
movl 0x4(%rsp), %ecx
callq 0xc92c
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x20f0
leaq 0x20(%rsp), %rdi
pushq $0x45
popq %rdx
movq %rbp, %rsi
movl 0x218(%rsp), %ecx
callq 0xc92c
leaq 0x128(%rsp), %rbx
leaq 0x20(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2240
movq %r15, %rdi
callq 0x20f0
leaq 0x49cb(%rip), %rsi      # 0x12efb
leaq 0x188(%rsp), %rdi
movq %rbx, %rdx
callq 0x970c
leaq 0x188(%rsp), %rbx
movq %rbp, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0xbf98
movq %rbx, %rdi
callq 0x20f0
movq 0x308(%rbp), %rdi
movq 0x88(%rsp), %rdx
leaq 0x4996(%rip), %rsi      # 0x12f09
movl 0x200(%rsp), %ecx
xorl %eax, %eax
callq 0x2280
movq 0x308(%rbp), %rdi
movq 0x128(%rsp), %rdx
movq 0x40(%rsp), %rcx
leaq 0x49df(%rip), %rsi      # 0x12f7b
xorl %eax, %eax
callq 0x2280
jmp 0xe95a
cmpb $0x0, 0x208(%rsp)
je 0xe5d5
leaq 0x49dc(%rip), %rsi      # 0x12f95
leaq 0x168(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x36b8
leaq 0x168(%rsp), %rbx
jmp 0xe5f6
leaq 0x49c0(%rip), %rsi      # 0x12f9c
leaq 0x148(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x36b8
leaq 0x148(%rsp), %rbx
movq %rbp, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0xbf98
movq %rbx, %rdi
callq 0x20f0
movl 0x18(%rsp), %ecx
cmpl $0x2, %ecx
setl %al
cmpl 0x14(%rsp), %ecx
setne %cl
orb %al, %cl
leaq 0x491c(%rip), %r12      # 0x12f41
leaq 0x4834(%rip), %r13      # 0x12e60
jne 0xe7b8
cmpl $0x10b, 0x10(%rsp)      # imm = 0x10B
cmoveq %r12, %r13
movq %r13, 0x8(%rsp)
leaq 0x20(%rsp), %rbx
leaq 0xe8(%rsp), %r13
leaq 0x108(%rsp), %r12
subl $0x1, 0x18(%rsp)
jb 0xe95a
movq %rbx, %rdi
movq %rbp, %rsi
pushq $0x52
popq %rdx
movl 0x4(%rsp), %ecx
callq 0xc92c
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x20f0
cmpb $0x0, 0x208(%rsp)
je 0xe6ed
movq %r13, %rdi
movl (%rsp), %esi
callq 0x96b3
movq %r12, %rdi
leaq 0x4890(%rip), %rsi      # 0x12f39
movq %r13, %rdx
callq 0x968f
movq 0x8(%rsp), %r14
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x2a03(%rip), %rdx      # 0x110c6
callq 0x9670
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x20f0
movq %r13, %rdi
jmp 0xe790
leaq 0xc8(%rsp), %r14
movq %r14, %rdi
leaq 0x483a(%rip), %rsi      # 0x12f39
leaq 0x88(%rsp), %rdx
callq 0x970c
movq %r13, %rdi
movq %r14, %rsi
leaq 0x4824(%rip), %rdx      # 0x12f3d
callq 0x9670
movq 0x8(%rsp), %r14
leaq 0xa8(%rsp), %r15
movq %r15, %rdi
movl (%rsp), %esi
callq 0x96b3
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x9871
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x2975(%rip), %rdx      # 0x110c6
callq 0x9670
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x20f0
leaq 0xa8(%rsp), %rdi
callq 0x20f0
movq %r13, %rdi
callq 0x20f0
leaq 0xc8(%rsp), %rdi
callq 0x20f0
movq 0x308(%rbp), %rdi
movq 0x60(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq %r14, %rsi
xorl %eax, %eax
callq 0x2280
incl (%rsp)
jmp 0xe658
movq %r13, 0x8(%rsp)
cmpl $0x1, 0x1c(%rsp)
ja 0xe95a
leaq 0x20(%rsp), %rdi
pushq $0x52
popq %rdx
movq %rbp, %rsi
movl 0x4(%rsp), %ecx
callq 0xc92c
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x20f0
xorl %eax, %eax
movl 0x14(%rsp), %r14d
testl %r14d, %r14d
cmovlel %eax, %r14d
cmpl $0x10b, 0x10(%rsp)      # imm = 0x10B
movq 0x8(%rsp), %rax
cmoveq %r12, %rax
movq %rax, 0x8(%rsp)
leaq 0xe8(%rsp), %r15
leaq 0x108(%rsp), %r12
subl $0x1, %r14d
jb 0xe95a
cmpb $0x0, 0x208(%rsp)
je 0xe892
movq %r15, %rdi
movl (%rsp), %esi
callq 0x96b3
movq %r12, %rdi
leaq 0x46e6(%rip), %rsi      # 0x12f39
movq %r15, %rdx
callq 0x968f
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x285e(%rip), %rdx      # 0x110c6
callq 0x9670
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x20f0
movq %r15, %rdi
jmp 0xe930
leaq 0xc8(%rsp), %r13
movq %r13, %rdi
leaq 0x4695(%rip), %rsi      # 0x12f39
leaq 0x88(%rsp), %rdx
callq 0x970c
movq %r15, %rdi
movq %r13, %rsi
leaq 0x467f(%rip), %rdx      # 0x12f3d
callq 0x9670
leaq 0xa8(%rsp), %r13
movq %r13, %rdi
movl (%rsp), %esi
callq 0x96b3
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x9871
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x27d5(%rip), %rdx      # 0x110c6
callq 0x9670
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x2240
movq %rbx, %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x20f0
leaq 0xa8(%rsp), %rdi
callq 0x20f0
movq %r15, %rdi
callq 0x20f0
leaq 0xc8(%rsp), %rdi
callq 0x20f0
movq 0x308(%rbp), %rdi
movq 0x60(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq 0x8(%rsp), %rsi
xorl %eax, %eax
callq 0x2280
incl (%rsp)
jmp 0xe82a
leaq 0x3fdc(%rip), %rsi      # 0x1293d
leaq 0x20(%rsp), %rdx
movq 0x80(%rsp), %rbx
movq %rbx, %rdi
callq 0x36b8
leaq 0x88(%rsp), %rdi
callq 0x20f0
leaq 0x128(%rsp), %rdi
callq 0x20f0
leaq 0x60(%rsp), %rdi
callq 0x20f0
leaq 0x40(%rsp), %rdi
callq 0x20f0
movq %rbx, %rax
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xea6b
jmp 0xea6b
jmp 0xea6b
jmp 0xea6b
jmp 0xea6b
jmp 0xea6b
jmp 0xea6b
jmp 0xea6b
jmp 0xe9f1
jmp 0xe9f6
jmp 0xea08
jmp 0xea0d
jmp 0xea12
jmp 0xea6b
jmp 0xea3b
jmp 0xea6b
movq %rax, %rbx
jmp 0xea22
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x20f0
jmp 0xea15
movq %rax, %rbx
jmp 0xea4b
movq %rax, %rbx
jmp 0xea2f
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x20f0
leaq 0xe8(%rsp), %rdi
callq 0x20f0
leaq 0xc8(%rsp), %rdi
jmp 0xea62
jmp 0xea6b
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x20f0
leaq 0xe8(%rsp), %rdi
jmp 0xea62
jmp 0xea6b
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
callq 0x20f0
jmp 0xea6e
jmp 0xea6b
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x20f0
leaq 0x128(%rsp), %rdi
callq 0x20f0
leaq 0x60(%rsp), %rdi
callq 0x20f0
leaq 0x40(%rsp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2310