// File: 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
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rsi
addq $0x18, %rsi
leaq -0x30(%rbp), %rdi
callq 0x40f0
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movq %rdx, -0x108(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x2f47b
movq -0x108(%rbp), %rax
movl -0xfc(%rbp), %ecx
movl %ecx, -0x48(%rbp)
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
testb $0x1, 0x50(%rax)
je 0x2f685
movq -0x10(%rbp), %rax
movq %rax, -0x110(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x40f0
jmp 0x2f4c1
movq -0x110(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x2c020
movq %rdx, -0x120(%rbp)
movl %eax, -0x114(%rbp)
jmp 0x2f4e3
movq -0x120(%rbp), %rax
movl -0x114(%rbp), %ecx
movl %ecx, -0x70(%rbp)
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x4170
movq -0x128(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x94(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x2f53d
movl -0x34(%rbp), %eax
addl -0x94(%rbp), %eax
movl %eax, -0x12c(%rbp)
jmp 0x2f546
movl -0x34(%rbp), %eax
movl %eax, -0x12c(%rbp)
movl -0x12c(%rbp), %eax
movl %eax, -0x98(%rbp)
cmpl $0x0, -0x98(%rbp)
jl 0x2f572
movl -0x98(%rbp), %eax
movl -0x94(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x2f61c
movl $0x28, %edi
callq 0x4130
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x138(%rbp)
movl -0x94(%rbp), %edx
movl -0x34(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x48(%rax), %r8
movl 0x8(%rax), %r9d
movl 0xc(%rax), %esi
movq %rsp, %rax
movl %esi, (%rax)
movl $0x1, %esi
callq 0x1d170
jmp 0x2f5b2
movq -0x138(%rbp), %rdi
leaq 0x241e8(%rip), %rsi     # 0x537a8
leaq -0x27f37(%rip), %rdx    # 0x7690
callq 0x43f0
jmp 0x2f86b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2f859
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x4170
jmp 0x2f859
movq -0x138(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0x41d0
jmp 0x2f859
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movq %rdx, -0x148(%rbp)
movl %eax, -0x13c(%rbp)
jmp 0x2f63b
movq -0x148(%rbp), %rax
movl -0x13c(%rbp), %ecx
movl %ecx, -0xa8(%rbp)
movq %rax, -0xa0(%rbp)
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x98(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0xa8(%rbp), %rcx
movq %rcx, (%rax)
movq -0xa0(%rbp), %rcx
movq %rcx, 0x8(%rax)
jmp 0x2f847
movq -0x10(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x40f0
jmp 0x2f6a2
movq -0x150(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x2c020
movq %rdx, -0x160(%rbp)
movl %eax, -0x154(%rbp)
jmp 0x2f6c4
movq -0x160(%rbp), %rax
movl -0x154(%rbp), %ecx
movl %ecx, -0xc0(%rbp)
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x4170
movq -0x168(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
callq 0x4100
movl %eax, -0xe4(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x2f72f
movl -0x34(%rbp), %eax
addl -0xe4(%rbp), %eax
movl %eax, -0x16c(%rbp)
jmp 0x2f738
movl -0x34(%rbp), %eax
movl %eax, -0x16c(%rbp)
movl -0x16c(%rbp), %eax
movl %eax, -0xe8(%rbp)
cmpl $0x0, -0xe8(%rbp)
jl 0x2f764
movl -0xe8(%rbp), %eax
movl -0xe4(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x2f7f4
movl $0x28, %edi
callq 0x4130
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x178(%rbp)
movl -0xe4(%rbp), %edx
movl -0x34(%rbp), %ecx
movq -0x8(%rbp), %rax
movq 0x48(%rax), %r8
movl 0x8(%rax), %r9d
movl 0xc(%rax), %esi
movq %rsp, %rax
movl %esi, (%rax)
xorl %esi, %esi
callq 0x1d170
jmp 0x2f7a1
movq -0x178(%rbp), %rdi
leaq 0x23ff9(%rip), %rsi     # 0x537a8
leaq -0x28126(%rip), %rdx    # 0x7690
callq 0x43f0
jmp 0x2f86b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x4170
jmp 0x2f859
movq -0x178(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0x41d0
jmp 0x2f859
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rdi
movq (%rdi), %rax
movq (%rax), %rax
callq *%rax
movq %rdx, -0x188(%rbp)
movl %eax, -0x17c(%rbp)
jmp 0x2f813
movq -0x188(%rbp), %rax
movl -0x17c(%rbp), %ecx
movl %ecx, -0xf8(%rbp)
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
movb %al, %dl
movq -0xb0(%rbp), %rax
movslq -0xe8(%rbp), %rcx
movb %dl, (%rax,%rcx)
leaq -0x30(%rbp), %rdi
callq 0x4170
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
leaq -0x30(%rbp), %rdi
callq 0x4170
movq -0x50(%rbp), %rdi
callq 0x4420
nopl (%rax,%rax)