// File: /workspace/github_cpp_makefile_star2_O3/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 0x897a
movq 0x38(%rbx), %rdi
movq (%rdi), %rax
callq *(%rax)
movq %rdx, %r14
cmpb $0x1, 0x50(%rbx)
jne 0x17392
leaq -0x78(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x88(%rbp), %rdi
callq 0x897a
leaq -0x88(%rbp), %rsi
movq %r15, %rdi
callq 0x165ec
movq %rdx, %r15
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0x17354
callq 0x41e0
movl 0x4(%r15), %r13d
movl %r14d, %r12d
sarl $0x1f, %r12d
andl %r13d, %r12d
addl %r14d, %r12d
js 0x17420
cmpl %r13d, %r12d
jge 0x17420
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 0x173ff
leaq -0x58(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x897a
leaq -0x68(%rbp), %rsi
movq %r15, %rdi
callq 0x165ec
movq %rdx, %r15
movq -0x68(%rbp), %rdi
cmpq %r12, %rdi
je 0x173cc
callq 0x41e0
movq %r15, %rdi
callq 0x40e0
movq %rax, %r12
movl %r14d, %r13d
sarl $0x1f, %r13d
andl %r12d, %r13d
addl %r14d, %r13d
js 0x1746c
cmpl %r12d, %r13d
jge 0x1746c
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 0x17411
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 0x14297(%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 0x1429d(%rip), %rsi     # 0x2b6f8
movq 0x14b76(%rip), %rdx     # 0x2bfd8
movq %rax, %rdi
callq 0x4350
jmp 0x174b6
movl $0x28, %edi
callq 0x4110
movq 0x8(%rbx), %rcx
movq 0x48(%rbx), %rdx
leaq 0x1424b(%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 0x14251(%rip), %rsi     # 0x2b6f8
movq 0x14b2a(%rip), %rdx     # 0x2bfd8
movq %rax, %rdi
callq 0x4350
jmp 0x174e1
jmp 0x174e1
jmp 0x174e1
jmp 0x174e1
movq %rax, %rbx
movq -0x68(%rbp), %rdi
jmp 0x174d1
movq %rax, %rbx
movq -0x88(%rbp), %rdi
cmpq %r12, %rdi
je 0x174e4
callq 0x41e0
jmp 0x174e4
jmp 0x174e1
jmp 0x174e1
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x174f6
callq 0x41e0
movq %rbx, %rdi
callq 0x4380