// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r8d, %r15d
movl %ecx, %r12d
movq %rdx, %r13
movl %esi, %r14d
cmpl $0xc, %esi
je 0x14d8a
cmpl $0xb, %r14d
jne 0x14dc6
movq %rdi, -0x30(%rbp)
movq %r13, %rdi
callq 0x40e0
movq %rax, %rbx
incl %eax
movl %r12d, %esi
sarl $0x1f, %esi
andl %eax, %esi
addl %r12d, %esi
js 0x14dd8
cmpl %ebx, %esi
jg 0x14dd8
movl %r15d, %edx
sarl $0x1f, %edx
andl %eax, %edx
addl %r15d, %edx
js 0x14e54
cmpl %ebx, %edx
jg 0x14e54
movq %r13, %rdi
callq 0x1762d
jmp 0x14dc3
movl 0x4(%r13), %ebx
leal 0x1(%rbx), %eax
movl %r12d, %esi
sarl $0x1f, %esi
andl %eax, %esi
addl %r12d, %esi
js 0x14e13
cmpl %ebx, %esi
jg 0x14e13
movl %r15d, %edx
sarl $0x1f, %edx
andl %eax, %edx
addl %r15d, %edx
js 0x14e8f
cmpl %ebx, %edx
jg 0x14e8f
movq %r13, %rdi
callq 0x17697
movq %rax, %rdx
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x175e8
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
leaq 0x168cf(%rip), %rdx     # 0x2b6d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movb $0x0, 0x10(%r14)
jmp 0x14e4a
movq %rdi, %r13
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq %r13, %r15
movq 0x30(%r13), %rdi
callq 0x175e8
movq 0x8(%r15), %rcx
leaq 0x16896(%rip), %rdx     # 0x2b6d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movb $0x1, 0x10(%r14)
movl %ebx, 0x14(%r14)
movl %r12d, 0x18(%r14)
jmp 0x14ecf
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x175e8
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
leaq 0x16853(%rip), %rdx     # 0x2b6d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movb $0x0, 0x10(%r14)
jmp 0x14ec7
movq %rdi, %r13
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq %r13, %r12
movq 0x30(%r13), %rdi
callq 0x175e8
movq 0x8(%r12), %rcx
leaq 0x16819(%rip), %rdx     # 0x2b6d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movb $0x1, 0x10(%r14)
movl %ebx, 0x14(%r14)
movl %r15d, 0x18(%r14)
movq %rcx, 0x1c(%r14)
leaq 0x1681e(%rip), %rsi     # 0x2b6f8
movq 0x170f7(%rip), %rdx     # 0x2bfd8
movq %r14, %rdi
callq 0x4350
jmp 0x14eef
jmp 0x14eef
jmp 0x14eef
movq %rax, %rbx
movq %r14, %rdi
callq 0x4190
movq %rbx, %rdi
callq 0x4380