// File: /workspace/github_c_makefile_star2_O2/martincameron[P]towntalk/towntalk.c
// Function: evaluate_sub_expression
static enum result evaluate_sub_expression( struct expression *this,
	struct variables *vars, struct variable *result ) {
	char *data;
	number *arr;
	struct string *str;
	struct variable var = { 0, NULL };
	int offset, length, idx, len;
	struct expression *parameter = this->parameters;
	enum result ret = parameter->evaluate( parameter, vars, &var );
	if( ret ) {
		parameter = parameter->next;
		ret = evaluate_integer( parameter, vars, &idx );
		if( ret ) {
			parameter = parameter->next;
			ret = evaluate_integer( parameter, vars, &len );
			if( ret ) {
				if( var.string_value ) {
					if( var.string_value->type == ARRAY ) {
						length = ( ( struct array * ) var.string_value )->length;
					} else {
						length = var.string_value->length;
					}
					if( idx >= 0 && len >= 0 && MAX_INTEGER - len >= idx && idx + len <= length ) {
						str = new_string( len );
						if( str ) {
							if( var.string_value->type == ARRAY ) {
								data = str->string;
								arr = ( ( struct array * ) var.string_value )->number_values;
								offset = 0;
								while( offset < len ) {
									data[ offset ] = arr[ offset + idx ];
									offset++;
								}
							} else {
								memcpy( str->string, &var.string_value->string[ idx ], sizeof( char ) * len );
							}
							result->string_value = str;
						} else {
							ret = throw_out_of_memory( vars, this );
						}
					} else {
						ret = throw( vars, this, idx, "Range out of bounds." );
					}
				} else {
					ret = throw( vars, this, 0, "Not a string or array." );
				}
			}
		}
		dispose_temporary( &var );
	}
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r14
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdx
movaps %xmm0, (%rdx)
movq 0x8(%rdi), %rbx
movq %rbx, %rdi
callq *0x18(%rbx)
testl %eax, %eax
je 0xc1a1
movq 0x10(%rbx), %rbx
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4514
xorl %ebp, %ebp
testl %eax, %eax
je 0xc1fc
movq 0x10(%rbx), %rdi
leaq 0x8(%rsp), %rdx
movq %r15, %rsi
callq 0x4514
testl %eax, %eax
je 0xc1fc
movq 0x18(%rsp), %rcx
testq %rcx, %rcx
je 0xc1a5
movl %eax, %r12d
movq %r13, 0x20(%rsp)
leaq 0x10(%rcx), %rax
leaq 0x40(%rcx), %rdx
cmpb $0x2, 0x14(%rcx)
cmoveq %rdx, %rax
movl 0xc(%rsp), %ebx
testl %ebx, %ebx
js 0xc1b8
movl 0x8(%rsp), %r13d
testl %r13d, %r13d
js 0xc1b8
movl %r13d, %ecx
xorl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ebx, %ecx
jl 0xc1b8
movl %ebx, %ecx
addl %r13d, %ecx
cmpl (%rax), %ecx
jg 0xc1b8
movl %r13d, %edi
callq 0x3723
testq %rax, %rax
je 0xc1ce
movq %rax, %rsi
movq 0x18(%rsp), %rcx
cmpb $0x2, 0x14(%rcx)
movq 0x8(%rax), %rdi
jne 0xc1db
leaq (,%rbx,4), %rax
addq 0x18(%rcx), %rax
xorl %ecx, %ecx
cmpq %rcx, %r13
je 0xc1f0
movb (%rax,%rcx,4), %dl
movb %dl, (%rdi,%rcx)
incq %rcx
jmp 0xc191
xorl %ebp, %ebp
jmp 0xc206
leaq 0x5ea1(%rip), %rcx      # 0x1204d
xorl %ebp, %ebp
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
jmp 0xc1c7
leaq 0x5e79(%rip), %rcx      # 0x12038
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x3bb2
jmp 0xc1fc
movq %r15, %rdi
movq %r14, %rsi
callq 0x4c90
jmp 0xc1fc
movq %rsi, %r14
movq 0x8(%rcx), %rsi
addq %rbx, %rsi
movq %r13, %rdx
callq 0x3180
movq %r14, %rsi
movq 0x20(%rsp), %rax
movq %rsi, 0x8(%rax)
movl %r12d, %ebp
leaq 0x10(%rsp), %rdi
callq 0x3988
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq