// File: /workspace/github_c_makefile_star2_O3/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, 0x38(%rsp)
movq %rsi, %rbx
movq 0x8(%rdi), %r13
movq 0x10(%r13), %r12
movq %rdi, 0x18(%rsp)
movl 0x4(%rdi), %r14d
xorps %xmm0, %xmm0
leaq 0x20(%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 %r13, %rdi
callq *0x18(%r13)
movq $0x0, 0x50(%rsp)
xorl %r15d, %r15d
testl %eax, %eax
je 0x9c9c
movl %eax, %ebp
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x9a81
movb 0x14(%rdi), %al
cmpb $0x1, %al
jne 0x9a90
testq %r12, %r12
je 0x9acb
leaq 0x916f(%rip), %rcx      # 0x12be2
xorl %r15d, %r15d
movq %rbx, %rdi
movq %r12, %rsi
jmp 0x9c71
movl 0x20(%rsp), %r13d
movl %r13d, 0x14(%rsp)
jmp 0x9b25
cmpl $0x42, %r14d
sete %cl
cmpb $0x3, %al
setne %al
orb %cl, %al
je 0x9ac0
leaq 0x20(%rsp), %rdi
leaq 0x14(%rsp), %rsi
movq %rbx, %rdx
movq %r13, %rcx
callq 0x44f1
movl %eax, %ebp
testl %eax, %eax
jne 0x9b20
jmp 0x9c9c
movl 0x18(%rdi), %r13d
movl %r13d, 0x14(%rsp)
jmp 0x9b27
movq 0x18(%rbx), %rsi
leaq 0x60(%rsp), %r12
movq %r12, (%rsp)
xorl %r15d, %r15d
leaq 0x40(%rsp), %r8
leaq 0x14(%rsp), %r9
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x8142
cmpb $0x0, (%r12)
je 0x9aff
leaq 0x60(%rsp), %rcx
jmp 0x9c69
movq 0x50(%rsp), %r12
leaq -0x6066(%rip), %rax     # 0x3aa5
cmpq %rax, 0x18(%r13)
je 0x9b20
movq 0x18(%rsp), %rax
movl (%rax), %esi
movq %r12, %rdi
callq 0x9ccf
movl 0x14(%rsp), %r13d
xorl %edi, %edi
testl %r13d, %r13d
js 0x9b85
movq %rdi, 0x30(%rsp)
cmpl $0x42, %r14d
jne 0x9ba2
movl %r13d, %eax
leaq 0x48(,%rax,4), %rsi
movl $0x1, %edi
callq 0x3130
testq %rax, %rax
je 0x9c5f
movq %rax, %r15
addq $0x48, %rax
movq %rax, 0x18(%r15)
leaq 0x90b0(%rip), %rax      # 0x12c17
movq %rax, 0x8(%r15)
movl $0x8, 0x10(%r15)
movq $0x1, (%r15)
movb $0x2, 0x14(%r15)
movl %r13d, 0x40(%r15)
jmp 0x9bd3
movl 0x20(%rsp), %edx
leaq 0x9071(%rip), %rcx      # 0x12c01
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x3c96
jmp 0x9c99
movq 0x18(%rbx), %rax
movq 0x40(%rax), %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x36cd
testq %rax, %rax
je 0x9c5f
movq %rax, %r15
leaq 0x9032(%rip), %rax      # 0x12bf9
movq %rax, 0x8(%r15)
movl $0x7, 0x10(%r15)
testq %r12, %r12
je 0x9c48
xorl %r13d, %r13d
leaq 0x20(%rsp), %r14
cmpl 0x14(%rsp), %r13d
jge 0x9c7a
movl $0x0, 0x20(%rsp)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x9c0b
callq 0x394d
movq $0x0, 0x28(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq *0x18(%r12)
testl %eax, %eax
je 0x9c91
movq %r14, %rdi
movq %r15, %rsi
movl %r13d, %edx
movq %rbx, %rcx
movq %r12, %r8
callq 0x45a1
movl %eax, %ebp
movq 0x10(%r12), %r12
testq %r12, %r12
je 0x9c44
incl %r13d
testl %ebp, %ebp
jne 0x9be0
testl %ebp, %ebp
je 0x9c91
movq 0x30(%rsp), %rax
movq %rax, 0x28(%r15)
movq 0x38(%rsp), %rax
movq %r15, 0x8(%rax)
movl %ebp, %r15d
jmp 0x9c9c
movq 0xf50a(%rip), %rcx      # 0x19170
xorl %r15d, %r15d
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x3c96
jmp 0x9c9c
leaq 0x854e(%rip), %rcx      # 0x121cf
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movl %r13d, %edx
callq 0x3c96
movq %r15, %rdi
callq 0x394d
xorl %r15d, %r15d
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x9cab
callq 0x394d
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x9cba
callq 0x3af9
movl %r15d, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq