// File: /workspace/github_c_makefile_star2_O2/martincameron[P]towntalk/towntalk.c
// Function: evaluate_array_expression
static enum result evaluate_array_expression( struct expression *this,
	struct variables *vars, struct variable *result ) {
	struct expression prev, *param = this->parameters, *expr = param->next;
	int idx, len, buf = this->index == 'B';
	struct variable var = { 0, NULL };
	struct structure *struc = NULL;
	char msg[ 128 ] = "";
	struct array *arr;
	enum result ret = param->evaluate( param, vars, &var );
	prev.next = NULL;
	if( ret ) {
		if( var.string_value ) {
			if( var.string_value->type == ELEMENT ) {
				if( expr == NULL ) {
					parse_expressions( ( struct element * ) var.string_value, vars->func, NULL, 0, &prev, &len, msg );
					if( msg[ 0 ] == 0 ) {
						expr = prev.next;
						if( param->evaluate != evaluate_string_literal_expression ) {
							expr_set_line( expr, this->line );
						}
					} else {
						ret = throw( vars, this, 0, msg );
					}
				} else {
					ret = throw( vars, expr, 0, "Unexpected expression." );
				}
			} else if( var.string_value->type == STRUCT && !buf ) {
				struc = ( struct structure * ) var.string_value;
				len = struc->length;
			} else {
				ret = to_int( &var, &len, vars, param );
			}
		} else {
			len = var.number_value;
		}
	}
	if( ret ) {
		if( len >= 0 ) {
			if( buf ) {
				arr = new_buffer( len );
			} else {
				arr = new_array( vars->func->env, len, 0 );
				if( arr ) {
					arr->str.string = "[Array]";
					arr->str.length = 7;
				}
			}
			if( arr ) {
				idx = 0;
				while( expr && ret ) {
					if( idx < len ) {
						dispose_variable( &var );
						ret = expr->evaluate( expr, vars, &var );
						if( ret ) {
							ret = assign_array_variable( &var, arr, idx++, vars, expr );
						}
					} else {
						ret = throw( vars, this, idx, "Array index out of bounds." );
					}
					expr = expr->next;
				}
				if( ret ) {
					arr->structure = struc;
					result->string_value = &arr->str;
				} else {
					unref_string( &arr->str );
				}
			} else {
				ret = throw_out_of_memory( vars, this );
			}
		} else {
			ret = throw( vars, this, var.number_value, "Invalid array length." );
		}
	}
	dispose_temporary( &var );
	if( prev.next ) {
		dispose_expressions( prev.next );
	}
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdx, %r13
movq %rsi, %rbx
movq 0x8(%rdi), %r15
movq 0x10(%r15), %r12
movq %rdi, 0x28(%rsp)
movl 0x4(%rdi), %r14d
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0xd0(%rsp)
movaps %xmm0, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movq %r15, %rdi
callq *0x18(%r15)
andq $0x0, 0x50(%rsp)
testl %eax, %eax
je 0x92cc
movl %eax, %ebp
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x92d6
movb 0x14(%rdi), %al
cmpb $0x1, %al
jne 0x92e8
testq %r12, %r12
je 0x9332
leaq 0x8964(%rip), %rcx      # 0x11c22
xorl %r13d, %r13d
movq %rbx, %rdi
movq %r12, %rsi
jmp 0x9372
xorl %ebx, %ebx
xorl %r13d, %r13d
jmp 0x9513
movl %r14d, %ecx
movl 0x30(%rsp), %r14d
movl %r14d, 0x14(%rsp)
jmp 0x93b1
cmpl $0x42, %r14d
sete %cl
cmpb $0x3, %al
setne %al
orb %cl, %al
je 0x931c
leaq 0x30(%rsp), %rdi
leaq 0x14(%rsp), %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x4333
movl %eax, %ebp
testl %eax, %eax
jne 0x93a9
jmp 0x950b
movl %r14d, %ecx
movq %rdi, 0x18(%rsp)
movl 0x18(%rdi), %r14d
movl %r14d, 0x14(%rsp)
jmp 0x93ba
movl %r14d, 0x18(%rsp)
movq %r13, 0x20(%rsp)
movq 0x18(%rbx), %rsi
leaq 0x60(%rsp), %r14
movq %r14, (%rsp)
xorl %r13d, %r13d
leaq 0x40(%rsp), %r8
leaq 0x14(%rsp), %r9
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x7b36
cmpb $0x0, (%r14)
je 0x937e
leaq 0x60(%rsp), %rcx
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0x3bb2
jmp 0x950e
movq 0x50(%rsp), %r12
leaq -0x59b6(%rip), %rax     # 0x39d4
cmpq %rax, 0x18(%r15)
je 0x939f
movq 0x28(%rsp), %rax
movl (%rax), %esi
movq %r12, %rdi
callq 0x953f
movq 0x20(%rsp), %r13
movl 0x18(%rsp), %r14d
movl %r14d, %ecx
movl 0x14(%rsp), %r14d
movq $0x0, 0x18(%rsp)
testl %r14d, %r14d
js 0x9415
cmpl $0x42, %ecx
jne 0x9432
movl %r14d, %eax
leaq 0x48(,%rax,4), %rsi
pushq $0x1
popq %rdi
callq 0x3130
testq %rax, %rax
je 0x94f4
movq %rax, %r15
movq %r13, 0x20(%rsp)
addq $0x48, %rax
movq %rax, 0x18(%r15)
leaq 0x8860(%rip), %rax      # 0x11c57
movq %rax, 0x8(%r15)
movl $0x8, 0x10(%r15)
movq $0x1, (%r15)
movb $0x2, 0x14(%r15)
movl %r14d, 0x40(%r15)
jmp 0x9468
movl 0x30(%rsp), %edx
leaq 0x8821(%rip), %rcx      # 0x11c41
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0x3bb2
jmp 0x950b
movq 0x18(%rbx), %rax
movq 0x40(%rax), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x3675
testq %rax, %rax
je 0x94f4
movq %rax, %r15
movq %r13, 0x20(%rsp)
leaq 0x87dd(%rip), %rax      # 0x11c39
movq %rax, 0x8(%r15)
movl $0x7, 0x10(%r15)
xorl %r14d, %r14d
testq %r12, %r12
je 0x94d9
testl %ebp, %ebp
je 0x94d9
cmpl 0x14(%rsp), %r14d
jge 0x94b9
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
callq 0x3896
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq *0x18(%r12)
testl %eax, %eax
je 0x94d0
leal 0x1(%r14), %r13d
movq %rbp, %rdi
movq %r15, %rsi
movl %r14d, %edx
movq %rbx, %rcx
movq %r12, %r8
callq 0x43df
movl %eax, %ebp
movl %r13d, %r14d
jmp 0x94d2
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
movl %r14d, %edx
leaq 0x7d44(%rip), %rcx      # 0x1120f
callq 0x3bb2
xorl %ebp, %ebp
movq 0x10(%r12), %r12
jmp 0x946b
testl %ebp, %ebp
je 0x9503
movq 0x18(%rsp), %rax
movq %rax, 0x28(%r15)
movq 0x20(%rsp), %rax
movq %r15, 0x8(%rax)
movl %ebp, %r13d
jmp 0x950e
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0x4c90
jmp 0x950b
movq %r15, %rdi
callq 0x38b2
xorl %r13d, %r13d
movq 0x50(%rsp), %rbx
leaq 0x30(%rsp), %rdi
callq 0x3988
testq %rbx, %rbx
je 0x952a
movq %rbx, %rdi
callq 0x3a26
movl %r13d, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq