// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x30f0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x58(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq *%rax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x11c54
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x4c(%rbp), %rdx
callq 0x5460
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x11c4b
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x5460
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x11c49
cmpq $0x0, -0x38(%rbp)
je 0x11c2e
movq -0x38(%rbp), %rax
movsbl 0x14(%rax), %eax
cmpl $0x2, %eax
jne 0x11b1b
movq -0x38(%rbp), %rax
movl 0x40(%rax), %eax
movl %eax, -0x48(%rbp)
jmp 0x11b25
movq -0x38(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x4c(%rbp)
jl 0x11c12
cmpl $0x0, -0x50(%rbp)
jl 0x11c12
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl -0x50(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jl 0x11c12
movl -0x4c(%rbp), %eax
addl -0x50(%rbp), %eax
cmpl -0x48(%rbp), %eax
jg 0x11c12
movl -0x50(%rbp), %edi
callq 0x39b0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x11c00
movq -0x38(%rbp), %rax
movsbl 0x14(%rax), %eax
cmpl $0x2, %eax
jne 0x11bce
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0x11bcc
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
addl -0x4c(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movslq -0x44(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x11b9c
jmp 0x11bf2
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rsi
movslq -0x4c(%rbp), %rax
addq %rax, %rsi
movslq -0x50(%rbp), %rdx
shlq $0x0, %rdx
callq 0x3170
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x11c10
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
callq 0x5f20
movl %eax, -0x5c(%rbp)
jmp 0x11c2c
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl -0x4c(%rbp), %edx
leaq 0xa8a2(%rip), %rcx      # 0x1c4c6
callq 0x4330
movl %eax, -0x5c(%rbp)
jmp 0x11c47
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
xorl %edx, %edx
leaq 0xa89c(%rip), %rcx      # 0x1c4db
callq 0x4330
movl %eax, -0x5c(%rbp)
jmp 0x11c49
jmp 0x11c4b
leaq -0x40(%rbp), %rdi
callq 0x3ce0
movl -0x5c(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)