// File: /workspace/github_c_makefile_star2_O0/hughbarney[P]zepl/lisp.c
// Function: stringSubstring
Object *stringSubstring(Object ** args, GC_PARAM)
{
	Object *first = (*args)->car;
	Object *second = (*args)->cdr->car;
	Object *third = (*args)->cdr->cdr->car;

	if (first->type != TYPE_STRING)
	    exceptionWithObject(first, "is not a string");
	if (second->type != TYPE_NUMBER)
	    exceptionWithObject(second, "is not a number");  
	if (third->type != TYPE_NUMBER)
	    exceptionWithObject(third, "is not a number");  

	int start = (int)(second->number);
	int end = (int)(third->number);
	int len = strlen(first->string);

	if (start < 0 || start > len -1)
	    exceptionWithObject(second, "is out of bounds");
	if (end < 0 || end > len -1)
	    exceptionWithObject(third, "is out of bounds");
	if (start > end)
	    exceptionWithObject(second, "start index greater than end index");

	char *sub = strdup(first->string);
	int newlen = end - start + 1;

	memcpy(sub, (first->string + start), newlen);
	*(sub + newlen) = '\0';
	Object *obj = newStringWithLength(sub, newlen, GC_ROOTS);
	free(sub);

	return obj;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1, (%rax)
je 0x7bc4
movq -0x18(%rbp), %rdi
leaq 0x3b5a(%rip), %rsi      # 0xb717
movb $0x0, %al
callq 0x50e0
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x7bdf
movq -0x20(%rbp), %rdi
leaq 0x3b4f(%rip), %rsi      # 0xb727
movb $0x0, %al
callq 0x50e0
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x7bfa
movq -0x28(%rbp), %rdi
leaq 0x3b34(%rip), %rsi      # 0xb727
movb $0x0, %al
callq 0x50e0
movq -0x20(%rbp), %rax
cvttsd2si 0x10(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
cvttsd2si 0x10(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
callq 0x20f0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x2c(%rbp)
jl 0x7c35
movl -0x2c(%rbp), %eax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x7c47
movq -0x20(%rbp), %rdi
leaq 0x3af7(%rip), %rsi      # 0xb737
movb $0x0, %al
callq 0x50e0
cmpl $0x0, -0x30(%rbp)
jl 0x7c5a
movl -0x30(%rbp), %eax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x7c6c
movq -0x28(%rbp), %rdi
leaq 0x3ad2(%rip), %rsi      # 0xb737
movb $0x0, %al
callq 0x50e0
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jle 0x7c86
movq -0x20(%rbp), %rdi
leaq 0x3ac9(%rip), %rsi      # 0xb748
movb $0x0, %al
callq 0x50e0
movq -0x18(%rbp), %rdi
addq $0x10, %rdi
callq 0x2310
movq %rax, -0x40(%rbp)
movl -0x30(%rbp), %eax
subl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x10, %rsi
movslq -0x2c(%rbp), %rax
addq %rax, %rsi
movslq -0x44(%rbp), %rdx
callq 0x2210
movq -0x40(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x40(%rbp), %rdi
movslq -0x44(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0x5ac0
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rdi
callq 0x2050
movq -0x50(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)