// File: /workspace/github_cpp_makefile_star2_O1/AshOlogn[P]ash-language-interpreter/src/executor.cpp
// Function: executeArrayAssignmentStatement(ArrayAssignmentStatementNode*)
void executeArrayAssignmentStatement(ArrayAssignmentStatementNode* node) {

	//get stuff out of the node first
	SymbolTable* symbolTable = node->symbolTable;
	std::string variable = node->variable;
	int32_t index = (int32_t) node->index->evaluate().value.integer;

	if(node->isArray) {

		//get array from the symbol table
		Array* array = (Array*) (symbolTable->get(variable)).value.allocated;
		int32_t length = (int32_t) array->length;

		//if negative index
		int32_t finalIndex = (index < 0) ? index + length : index;

		//if out of bounds, throw an exception
		if(finalIndex < 0 || finalIndex > length-1)
			throw OutOfBoundsException(true, length, index, node->context, node->startLine, node->endLine);

		ParseData value = node->value->evaluate();

		//do the assignment
		array->values[finalIndex] = value;

	} else {

		char* str = (char*) (symbolTable->get(variable)).value.allocated;
		int32_t length = (int32_t) strlen(str);

		//if negative index
		int32_t finalIndex = (index < 0) ? index + length : index;

		//if out of bounds, throw an exception
		if(finalIndex < 0 || finalIndex > length-1)
			throw OutOfBoundsException(false, length, index, node->context, node->startLine, node->endLine);

		ParseData value = node->value->evaluate();

		//do the assignment
		str[finalIndex] = (unsigned char) value.value.integer;
	}

	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movq 0x10(%rdi), %r15
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x18(%rdi), %rsi
movq 0x20(%rdi), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x8ac2
movq 0x38(%rbx), %rdi
movq (%rdi), %rax
callq *(%rax)
movq %rdx, %r14
cmpb $0x1, 0x50(%rbx)
jne 0x1745a
leaq -0x78(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %rdi
callq 0x8ac2
leaq -0x88(%rbp), %rsi
movq %r15, %rdi
callq 0x1669a
movq %rdx, %r15
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0x1741c
callq 0x41e0
movl 0x4(%r15), %r13d
movl %r14d, %r12d
sarl $0x1f, %r12d
andl %r13d, %r12d
addl %r14d, %r12d
js 0x174e8
cmpl %r13d, %r12d
jge 0x174e8
movq 0x40(%rbx), %rdi
movq (%rdi), %rax
callq *(%rax)
movq 0x8(%r15), %rcx
movl %r12d, %esi
shlq $0x4, %rsi
movl %eax, (%rcx,%rsi)
movq %rdx, 0x8(%rcx,%rsi)
jmp 0x174c7
leaq -0x58(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x8ac2
leaq -0x68(%rbp), %rsi
movq %r15, %rdi
callq 0x1669a
movq %rdx, %r15
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x17494
callq 0x41e0
movq %r15, %rdi
callq 0x40e0
movq %rax, %r12
movl %r14d, %r13d
sarl $0x1f, %r13d
andl %r12d, %r13d
addl %r14d, %r13d
js 0x17534
cmpl %r12d, %r13d
jge 0x17534
movq 0x40(%rbx), %rdi
movq (%rdi), %rax
callq *(%rax)
movl %r13d, %eax
movb %dl, (%r15,%rax)
leaq -0x38(%rbp), %rax
movq -0x48(%rbp), %rdi
cmpq %rax, %rdi
je 0x174d9
callq 0x41e0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x28, %edi
callq 0x4110
movq 0x8(%rbx), %rcx
movq 0x48(%rbx), %rdx
leaq 0x141cf(%rip), %rsi     # 0x2b6d0
addq $0x10, %rsi
movq %rsi, (%rax)
movq %rdx, 0x8(%rax)
movb $0x1, 0x10(%rax)
movl %r13d, 0x14(%rax)
movl %r14d, 0x18(%rax)
movq %rcx, 0x1c(%rax)
leaq 0x141d5(%rip), %rsi     # 0x2b6f8
movq 0x14aae(%rip), %rdx     # 0x2bfd8
movq %rax, %rdi
callq 0x4350
jmp 0x1757e
movl $0x28, %edi
callq 0x4110
movq 0x8(%rbx), %rcx
movq 0x48(%rbx), %rdx
leaq 0x14183(%rip), %rsi     # 0x2b6d0
addq $0x10, %rsi
movq %rsi, (%rax)
movq %rdx, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl %r12d, 0x14(%rax)
movl %r14d, 0x18(%rax)
movq %rcx, 0x1c(%rax)
leaq 0x14189(%rip), %rsi     # 0x2b6f8
movq 0x14a62(%rip), %rdx     # 0x2bfd8
movq %rax, %rdi
callq 0x4350
jmp 0x175a9
jmp 0x175a9
jmp 0x175a9
jmp 0x175a9
movq %rax, %rbx
movq -0x68(%rbp), %rdi
jmp 0x17599
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0x175ac
callq 0x41e0
jmp 0x175ac
jmp 0x175a9
jmp 0x175a9
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x175be
callq 0x41e0
movq %rbx, %rdi
callq 0x4380