// File: /workspace/github_cpp_makefile_star2_O2/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, %rbx
movl %esi, %r14d
cmpl $0xc, %esi
je 0x13080
cmpl $0xb, %r14d
jne 0x130bf
movq %rdi, -0x30(%rbp)
movq %rbx, %rdi
callq 0x40c0
movq %rax, %r13
incl %eax
movl %r12d, %esi
sarl $0x1f, %esi
andl %eax, %esi
addl %r12d, %esi
js 0x130d1
cmpl %r13d, %esi
jg 0x130d1
movl %r15d, %edx
sarl $0x1f, %edx
andl %eax, %edx
addl %r15d, %edx
js 0x13149
cmpl %r13d, %edx
jg 0x13149
movq %rbx, %rdi
callq 0x15329
jmp 0x130bc
movl 0x4(%rbx), %r13d
leal 0x1(%r13), %eax
movl %r12d, %esi
sarl $0x1f, %esi
andl %eax, %esi
addl %r12d, %esi
js 0x1310a
cmpl %r13d, %esi
jg 0x1310a
movl %r15d, %edx
sarl $0x1f, %edx
andl %eax, %edx
addl %r15d, %edx
js 0x13182
cmpl %r13d, %edx
jg 0x13182
movq %rbx, %rdi
callq 0x1538f
movq %rax, %rdx
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x28
popq %rdi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x152e4
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
leaq 0x175d8(%rip), %rdx     # 0x2a6d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movb $0x0, 0x10(%r14)
jmp 0x1313f
movq %rdi, %r15
pushq $0x28
popq %rdi
callq 0x4110
movq %rax, %r14
movq %r15, %rbx
movq 0x30(%r15), %rdi
callq 0x152e4
movq 0x8(%rbx), %rcx
leaq 0x175a1(%rip), %rdx     # 0x2a6d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movb $0x1, 0x10(%r14)
movl %r13d, 0x14(%r14)
movl %r12d, 0x18(%r14)
jmp 0x131c0
pushq $0x28
popq %rdi
callq 0x4110
movq %rax, %r14
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x152e4
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
leaq 0x17560(%rip), %rdx     # 0x2a6d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movb $0x0, 0x10(%r14)
jmp 0x131b8
movq %rdi, %r12
pushq $0x28
popq %rdi
callq 0x4110
movq %rax, %r14
movq %r12, %rbx
movq 0x30(%r12), %rdi
callq 0x152e4
movq 0x8(%rbx), %rcx
leaq 0x17528(%rip), %rdx     # 0x2a6d0
addq $0x10, %rdx
movq %rdx, (%r14)
movq %rax, 0x8(%r14)
movb $0x1, 0x10(%r14)
movl %r13d, 0x14(%r14)
movl %r15d, 0x18(%r14)
movq %rcx, 0x1c(%r14)
leaq 0x1752d(%rip), %rsi     # 0x2a6f8
movq 0x17e06(%rip), %rdx     # 0x2afd8
movq %r14, %rdi
callq 0x4310
jmp 0x131e0
jmp 0x131e0
jmp 0x131e0
movq %rax, %rbx
movq %r14, %rdi
callq 0x4180
movq %rbx, %rdi
callq 0x4340