// File: AshOlogn[P]ash-language-interpreter/src/memberaccesseval.cpp
// Function: sliceHelper(ArrayAccessNode*, ParseData, int, int)
ParseData sliceHelper(ArrayAccessNode* node, ParseData arr, int32_t startIndex, int32_t endIndex) {
  
  ParseData d;
	ParseDataType type = arr.type;
  d.type = type;
  
	if(type == STRING_T) {

		char* str = (char*) arr.value.allocated;
		int32_t len = strlen(str);
		int32_t start = startIndex;
		int32_t pastEnd = endIndex;

		//calculate actual indices (with negative case)
		if(start < 0)
			start += len + 1;

		if(start < 0 || start > len) {
			throw OutOfBoundsException(false, len, startIndex, copyString(node->context), node->startLine, node->endLine);
		}

		if(pastEnd < 0)
			pastEnd += len + 1;

		if(pastEnd < 0 || pastEnd > len) {
			throw OutOfBoundsException(false, len, endIndex, copyString(node->context), node->startLine, node->endLine);
		}
		
		d.value.allocated = copySubstring((char*) arr.value.allocated, start, pastEnd);

	} else if(type == ARRAY_T) {

		Array* array = (Array*) arr.value.allocated;
		int32_t len = (int32_t) array->length;
		int32_t start = startIndex;
		int32_t pastEnd = endIndex;

		//calculate actual indices (with negative case)
		if(start < 0)
			start += len+1;

		if(start < 0 || start > len) {
			throw OutOfBoundsException(true, len, startIndex, copyString(node->context), node->startLine, node->endLine);
		}

		if(pastEnd < 0)
			pastEnd += len+1;

		if(pastEnd < 0 || pastEnd > len) {
			throw OutOfBoundsException(true, len, endIndex, copyString(node->context), node->startLine, node->endLine);
		}
		
		d.value.allocated = copySubarray(array, start, pastEnd);
	}
  
  return d;   
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movl %esi, -0x20(%rbp)
movq %rdx, -0x18(%rbp)
movq %rdi, -0x28(%rbp)
movl %ecx, -0x2c(%rbp)
movl %r8d, -0x30(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x10(%rbp)
cmpl $0xb, -0x34(%rbp)
jne 0x29693
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
callq 0x4100
movl %eax, -0x44(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x48(%rbp)
jge 0x29505
movl -0x44(%rbp), %eax
addl $0x1, %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
jl 0x29517
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jle 0x295b4
movl $0x28, %edi
callq 0x4130
movq %rax, -0x90(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x84(%rbp)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2fb10
movq %rax, -0x80(%rbp)
jmp 0x2954d
movq -0x80(%rbp), %r8
movl -0x84(%rbp), %ecx
movl -0x88(%rbp), %edx
movq -0x90(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %r9d
movl 0xc(%rax), %esi
movq %rsp, %rax
movl %esi, (%rax)
xorl %esi, %esi
callq 0x1d170
jmp 0x2957d
movq -0x90(%rbp), %rdi
leaq 0x2a21d(%rip), %rsi     # 0x537a8
leaq -0x21f02(%rip), %rdx    # 0x7690
callq 0x43f0
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x41d0
jmp 0x29871
cmpl $0x0, -0x4c(%rbp)
jge 0x295c6
movl -0x44(%rbp), %eax
addl $0x1, %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jl 0x295d8
movl -0x4c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jle 0x2967b
movl $0x28, %edi
callq 0x4130
movq %rax, -0xa8(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0xa0(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x9c(%rbp)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2fb10
movq %rax, -0x98(%rbp)
jmp 0x29611
movq -0x98(%rbp), %r8
movl -0x9c(%rbp), %ecx
movl -0xa0(%rbp), %edx
movq -0xa8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %r9d
movl 0xc(%rax), %esi
movq %rsp, %rax
movl %esi, (%rax)
xorl %esi, %esi
callq 0x1d170
jmp 0x29644
movq -0xa8(%rbp), %rdi
leaq 0x2a156(%rip), %rsi     # 0x537a8
leaq -0x21fc9(%rip), %rdx    # 0x7690
callq 0x43f0
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x41d0
jmp 0x29871
movq -0x18(%rbp), %rdi
movl -0x48(%rbp), %esi
movl -0x4c(%rbp), %edx
callq 0x2fb70
movq %rax, -0x8(%rbp)
jmp 0x29861
cmpl $0xc, -0x34(%rbp)
jne 0x2985f
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x6c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x70(%rbp)
jge 0x296cd
movl -0x6c(%rbp), %eax
addl $0x1, %eax
addl -0x70(%rbp), %eax
movl %eax, -0x70(%rbp)
cmpl $0x0, -0x70(%rbp)
jl 0x296df
movl -0x70(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jle 0x29785
movl $0x28, %edi
callq 0x4130
movq %rax, -0xc0(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0xb8(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0xb4(%rbp)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2fb10
movq %rax, -0xb0(%rbp)
jmp 0x29718
movq -0xb0(%rbp), %r8
movl -0xb4(%rbp), %ecx
movl -0xb8(%rbp), %edx
movq -0xc0(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %r9d
movl 0xc(%rax), %esi
movq %rsp, %rax
movl %esi, (%rax)
movl $0x1, %esi
callq 0x1d170
jmp 0x2974e
movq -0xc0(%rbp), %rdi
leaq 0x2a04c(%rip), %rsi     # 0x537a8
leaq -0x220d3(%rip), %rdx    # 0x7690
callq 0x43f0
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x41d0
jmp 0x29871
cmpl $0x0, -0x74(%rbp)
jge 0x29797
movl -0x6c(%rbp), %eax
addl $0x1, %eax
addl -0x74(%rbp), %eax
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x74(%rbp)
jl 0x297a9
movl -0x74(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jle 0x2984c
movl $0x28, %edi
callq 0x4130
movq %rax, -0xd8(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0xd0(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0xcc(%rbp)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2fb10
movq %rax, -0xc8(%rbp)
jmp 0x297e2
movq -0xc8(%rbp), %r8
movl -0xcc(%rbp), %ecx
movl -0xd0(%rbp), %edx
movq -0xd8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %r9d
movl 0xc(%rax), %esi
movq %rsp, %rax
movl %esi, (%rax)
movl $0x1, %esi
callq 0x1d170
jmp 0x29818
movq -0xd8(%rbp), %rdi
leaq 0x29f82(%rip), %rsi     # 0x537a8
leaq -0x2219d(%rip), %rdx    # 0x7690
callq 0x43f0
movq -0xd8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x41d0
jmp 0x29871
movq -0x68(%rbp), %rdi
movl -0x70(%rbp), %esi
movl -0x74(%rbp), %edx
callq 0x2fc30
movq %rax, -0x8(%rbp)
jmp 0x29861
movl -0x10(%rbp), %eax
movq -0x8(%rbp), %rdx
addq $0xe0, %rsp
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x4420
nopw (%rax,%rax)