// File: AshOlogn[P]ash-language-interpreter/src/arithmeticeval.cpp
// Function: ParseData additionHelper<Array*, Array*>(Array*, Array*, ParseDataType)
ParseData additionHelper<Array*, Array*>(Array* a1, Array* a2, ParseDataType type) {

	//get fields out of the array structs
	uint32_t len1 = a1->length;
	uint32_t len2 = a2->length;
	ParseDataType type1 = a1->subtype;
	ParseDataType type2 = a2->subtype;
	ParseData* values1 = a1->values;
	ParseData* values2 = a2->values;

	uint32_t length = len1 + len2;
	ParseDataType finalType = getTypeArithmeticExpression(ADD_OP, type1, type2);
	ParseData* values = (ParseData*) malloc(sizeof(ParseData) * length);

	for(uint32_t i = 0; i < len1; i++) {
		values[i] = castHelper(values1[i], finalType);
	}

	for(uint32_t i = 0; i < len2; i++) {
		values[i+len1] = castHelper(values2[i], finalType);
	}

	Array* arr = (Array*) malloc(sizeof(Array));
	arr->length = length;
	arr->subtype = finalType;
	arr->values = values;

	ParseData d;
	d.type = ARRAY_T;
	d.value.allocated = (void*) arr;

	return d;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movl -0x28(%rbp), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
movl $0xf, %edi
callq 0x2ba60
movl %eax, -0x50(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, %edi
shlq $0x4, %rdi
callq 0x4310
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jae 0xf6fc
movq -0x40(%rbp), %rax
movl -0x5c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x80(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x78(%rbp)
movl -0x50(%rbp), %edx
movl -0x80(%rbp), %edi
movq -0x78(%rbp), %rsi
callq 0x29c10
movl %eax, -0x70(%rbp)
movq %rdx, -0x68(%rbp)
movq -0x58(%rbp), %rax
movl -0x5c(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x70(%rbp), %rcx
movq %rcx, (%rax)
movq -0x68(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xf699
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0xf79c
movq -0x48(%rbp), %rax
movl -0x84(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0xa8(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0xa0(%rbp)
movl -0x50(%rbp), %edx
movl -0xa8(%rbp), %edi
movq -0xa0(%rbp), %rsi
callq 0x29c10
movl %eax, -0x98(%rbp)
movq %rdx, -0x90(%rbp)
movq -0x58(%rbp), %rax
movl -0x84(%rbp), %ecx
addl -0x28(%rbp), %ecx
movl %ecx, %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x98(%rbp), %rcx
movq %rcx, (%rax)
movq -0x90(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0xf706
movl $0x10, %edi
callq 0x4310
movq %rax, -0xb0(%rbp)
movl -0x4c(%rbp), %ecx
movq -0xb0(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x50(%rbp), %ecx
movq -0xb0(%rbp), %rax
movl %ecx, (%rax)
movq -0x58(%rbp), %rcx
movq -0xb0(%rbp), %rax
movq %rcx, 0x8(%rax)
movl $0xc, -0x10(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x8(%rbp)
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rdx
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)