// File: /workspace/github_cpp_makefile_star2_O1/AshOlogn[P]ash-language-interpreter/src/assignmenteval.cpp
// Function: evaluateArrayAssignmentExpression(ArrayAssignmentExpressionNode*)
ParseData evaluateArrayAssignmentExpression(ArrayAssignmentExpressionNode* node) {

	//extract instance fields
	SymbolTable* symbolTable = node->symbolTable;
	int32_t index = (int32_t) node->index->evaluate().value.integer;

	if(node->array->evalType == ARRAY_T) {

		Array* arr = (Array*) node->array->evaluate().value.allocated;
		int32_t length = (int32_t) arr->length;

		//calculate final index and throw exception if out of bounds
		int32_t finalIndex = (index < 0) ? index + length : index;
		if(finalIndex < 0 || finalIndex > length-1)
			throw OutOfBoundsException(true, length, index, node->context, node->startLine, node->endLine);

		ParseData value = node->value->evaluate();

		//assign array index
		arr->values[finalIndex] = value;

		//return a deep copy of assigned value
		ParseData retValue;
		retValue.type = value.type;

		if(value.type == STRING_T) {
			retValue.value.allocated = (void*) copyString((char*) value.value.allocated);
		} else if(value.type == DOUBLE_T) {
			retValue.value.floatingPoint = value.value.floatingPoint;
		} else {
			retValue.value.integer = value.value.integer;
		}

		return retValue;

	} else {

		char* str = (char*) node->array->evaluate().value.allocated;
		int32_t length = strlen(str);

		//calculate final index and throw exception if out of bounds
		int32_t finalIndex = (index < 0) ? index + length : index;
		if(finalIndex < 0 || finalIndex > length-1)
			throw OutOfBoundsException(false, length, index, node->context, node->startLine, node->endLine);

		ParseData value = node->value->evaluate();
		str[finalIndex] = (unsigned char) value.value.integer;

		return value;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
movq 0x20(%rdi), %rdi
movq (%rdi), %rax
callq *(%rax)
movq %rdx, %rbx
movq 0x18(%r14), %rdi
movl 0x10(%rdi), %r12d
movq (%rdi), %rax
callq *(%rax)
movq %rdx, %r15
cmpl $0xc, %r12d
jne 0x10e33
movl 0x4(%r15), %r12d
movl %ebx, %r13d
sarl $0x1f, %r13d
andl %r12d, %r13d
addl %ebx, %r13d
js 0x10e75
cmpl %r12d, %r13d
jge 0x10e75
movq 0x28(%r14), %rdi
movq (%rdi), %rax
callq *(%rax)
movl %eax, %ebx
movq 0x8(%r15), %rax
movl %r13d, %ecx
shlq $0x4, %rcx
movl %ebx, (%rax,%rcx)
movq %rdx, 0x8(%rax,%rcx)
cmpl $0xb, %ebx
jne 0x10e64
movq %rdx, %rdi
callq 0x176b0
movq %rax, %rdx
jmp 0x10e64
movq %r15, %rdi
callq 0x40e0
movq %rax, %r12
movl %ebx, %r13d
sarl $0x1f, %r13d
andl %r12d, %r13d
addl %ebx, %r13d
js 0x10ea3
cmpl %r12d, %r13d
jge 0x10ea3
movq 0x28(%r14), %rdi
movq (%rdi), %rax
callq *(%rax)
movl %eax, %ebx
movl %r13d, %eax
movb %dl, (%r15,%rax)
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x28, %edi
callq 0x4110
movq 0x8(%r14), %rcx
movq 0x30(%r14), %rdx
leaq 0x1a842(%rip), %rsi     # 0x2b6d0
addq $0x10, %rsi
movq %rsi, (%rax)
movq %rdx, 0x8(%rax)
movb $0x1, 0x10(%rax)
movl %r12d, 0x14(%rax)
jmp 0x10ecf
movl $0x28, %edi
callq 0x4110
movq 0x8(%r14), %rcx
movq 0x30(%r14), %rdx
leaq 0x1a814(%rip), %rsi     # 0x2b6d0
addq $0x10, %rsi
movq %rsi, (%rax)
movq %rdx, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl %r12d, 0x14(%rax)
movl %ebx, 0x18(%rax)
movq %rcx, 0x1c(%rax)
leaq 0x1a81b(%rip), %rsi     # 0x2b6f8
movq 0x1b0f4(%rip), %rdx     # 0x2bfd8
movq %rax, %rdi
callq 0x4350