// File: /workspace/github_cpp_makefile_star2_O1/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 0x14dba
cmpl $0xb, %r14d
jne 0x14df6
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 0x14e08
cmpl %ebx, %esi
jg 0x14e08
movl %r15d, %edx
sarl $0x1f, %edx
andl %eax, %edx
addl %r15d, %edx
js 0x14e84
cmpl %ebx, %edx
jg 0x14e84
movq %r13, %rdi
callq 0x176f5
jmp 0x14df3
movl 0x4(%r13), %ebx
leal 0x1(%rbx), %eax
movl %r12d, %esi
sarl $0x1f, %esi
andl %eax, %esi
addl %r12d, %esi
js 0x14e43
cmpl %ebx, %esi
jg 0x14e43
movl %r15d, %edx
sarl $0x1f, %edx
andl %eax, %edx
addl %r15d, %edx
js 0x14ebf
cmpl %ebx, %edx
jg 0x14ebf
movq %r13, %rdi
callq 0x17766
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 0x176b0
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
leaq 0x1689f(%rip), %rdx     # 0x2b6d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movb $0x0, 0x10(%r14)
jmp 0x14e7a
movq %rdi, %r13
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq %r13, %r15
movq 0x30(%r13), %rdi
callq 0x176b0
movq 0x8(%r15), %rcx
leaq 0x16866(%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 0x14eff
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x176b0
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
leaq 0x16823(%rip), %rdx     # 0x2b6d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movb $0x0, 0x10(%r14)
jmp 0x14ef7
movq %rdi, %r13
movl $0x28, %edi
callq 0x4110
movq %rax, %r14
movq %r13, %r12
movq 0x30(%r13), %rdi
callq 0x176b0
movq 0x8(%r12), %rcx
leaq 0x167e9(%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 0x167ee(%rip), %rsi     # 0x2b6f8
movq 0x170c7(%rip), %rdx     # 0x2bfd8
movq %r14, %rdi
callq 0x4350
jmp 0x14f1f
jmp 0x14f1f
jmp 0x14f1f
movq %rax, %rbx
movq %r14, %rdi
callq 0x4190
movq %rbx, %rdi
callq 0x4380