// File: /workspace/github_cpp_makefile_star2_O2/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 0x18(%rdi), %rsi
leaq -0x48(%rbp), %rdi
callq 0x4290
movq 0x38(%rbx), %rdi
movq (%rdi), %rax
callq *(%rax)
movq %rdx, %r14
cmpb $0x1, 0x50(%rbx)
jne 0x15100
leaq -0x88(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x4290
leaq -0x88(%rbp), %rsi
movq %r15, %rdi
callq 0x14476
movq %rdx, %r15
leaq -0x88(%rbp), %rdi
callq 0x40e0
movl 0x4(%r15), %r13d
movl %r14d, %r12d
sarl $0x1f, %r12d
andl %r13d, %r12d
addl %r14d, %r12d
js 0x1516c
cmpl %r13d, %r12d
jge 0x1516c
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 0x15154
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x4290
leaq -0x68(%rbp), %rsi
movq %r15, %rdi
callq 0x14476
movq %rdx, %r15
leaq -0x68(%rbp), %rdi
callq 0x40e0
movq %r15, %rdi
callq 0x40c0
movq %rax, %r12
movl %r14d, %r13d
sarl $0x1f, %r13d
andl %r12d, %r13d
addl %r14d, %r13d
js 0x151b6
cmpl %r12d, %r13d
jge 0x151b6
movq 0x40(%rbx), %rdi
movq (%rdi), %rax
callq *(%rax)
movl %r13d, %eax
movb %dl, (%r15,%rax)
leaq -0x48(%rbp), %rdi
callq 0x40e0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x28
popq %rdi
callq 0x4110
movq 0x8(%rbx), %rcx
movq 0x48(%rbx), %rdx
leaq 0x1554d(%rip), %rsi     # 0x2a6d0
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 0x15553(%rip), %rsi     # 0x2a6f8
movq 0x15e2c(%rip), %rdx     # 0x2afd8
movq %rax, %rdi
callq 0x4310
jmp 0x151fe
pushq $0x28
popq %rdi
callq 0x4110
movq 0x8(%rbx), %rcx
movq 0x48(%rbx), %rdx
leaq 0x15503(%rip), %rsi     # 0x2a6d0
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 0x15509(%rip), %rsi     # 0x2a6f8
movq 0x15de2(%rip), %rdx     # 0x2afd8
movq %rax, %rdi
callq 0x4310
jmp 0x15224
jmp 0x15224
jmp 0x15224
jmp 0x15224
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
jmp 0x15219
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x40e0
jmp 0x15227
jmp 0x15224
jmp 0x15224
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x40e0
movq %rbx, %rdi
callq 0x4340