// File: /workspace/github_c_makefile_star2_O1/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, %r14
movq %rsi, %r15
movq 0x8(%rdi), %rbx
movq 0x10(%rbx), %r12
movq %rdi, 0x18(%rsp)
movl 0x4(%rdi), %r13d
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 %rbx, %rdi
callq *0x18(%rbx)
movl %eax, %ebp
movq $0x0, 0x50(%rsp)
xorl %eax, %eax
testl %ebp, %ebp
je 0x9bfa
movq 0x28(%rsp), %rax
testq %rax, %rax
je 0x9c01
movq %rax, %rdi
movb 0x14(%rax), %al
cmpb $0x1, %al
jne 0x9c0b
testq %r12, %r12
je 0x9c42
leaq 0x8ffb(%rip), %rcx      # 0x12be6
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x3cc3
xorl %eax, %eax
xorl %ebp, %ebp
jmp 0x9c91
movl 0x20(%rsp), %eax
movl %eax, 0x14(%rsp)
jmp 0x9c32
cmpl $0x42, %r13d
sete %cl
cmpb $0x3, %al
setne %al
orb %cl, %al
je 0x9c36
leaq 0x20(%rsp), %rdi
leaq 0x14(%rsp), %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x4522
movl %eax, %ebp
xorl %eax, %eax
jmp 0x9c91
movl 0x18(%rdi), %eax
movl %eax, 0x14(%rsp)
movq %rdi, %rax
jmp 0x9c91
movq %r14, 0x30(%rsp)
movq 0x18(%r15), %rsi
leaq 0x60(%rsp), %r14
movq %r14, (%rsp)
xorl %r12d, %r12d
leaq 0x40(%rsp), %r8
leaq 0x14(%rsp), %r9
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x8314
cmpb $0x0, (%r14)
je 0x9e5a
leaq 0x60(%rsp), %rcx
movq %r15, %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x3cc3
xorl %eax, %eax
xorl %ebp, %ebp
movq 0x30(%rsp), %r14
testl %ebp, %ebp
je 0x9e26
movq %r14, 0x30(%rsp)
movslq 0x14(%rsp), %r14
testq %r14, %r14
js 0x9cfb
movq %rax, 0x38(%rsp)
cmpl $0x42, %r13d
jne 0x9d18
leaq 0x48(,%r14,4), %rsi
movl $0x1, %edi
callq 0x3130
movq %rax, %rbx
testq %rax, %rax
je 0x9d46
movq %rbx, %rax
addq $0x48, %rax
movq %rax, 0x18(%rbx)
leaq 0x8f3c(%rip), %rax      # 0x12c1b
movq %rax, 0x8(%rbx)
movl $0x8, 0x10(%rbx)
movq $0x1, (%rbx)
movb $0x2, 0x14(%rbx)
movl %r14d, 0x40(%rbx)
jmp 0x9d46
movl 0x20(%rsp), %edx
leaq 0x8eff(%rip), %rcx      # 0x12c05
movq %r15, %rdi
movq 0x18(%rsp), %rsi
callq 0x3cc3
jmp 0x9e26
movq 0x18(%r15), %rax
movq 0x40(%rax), %rdi
xorl %ebx, %ebx
movl %r14d, %esi
xorl %edx, %edx
callq 0x36e0
testq %rax, %rax
je 0x9d46
leaq 0x8ec5(%rip), %rcx      # 0x12bfd
movq %rcx, 0x8(%rax)
movl $0x7, 0x10(%rax)
movq %rax, %rbx
testq %rbx, %rbx
je 0x9dea
testq %r12, %r12
je 0x9e04
xorl %r14d, %r14d
cmpl 0x14(%rsp), %r14d
jge 0x9db8
movl $0x0, 0x20(%rsp)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x9d82
callq 0x3979
movq $0x0, 0x28(%rsp)
movq %r12, %rdi
movq %r15, %rsi
leaq 0x20(%rsp), %rbp
movq %rbp, %rdx
callq *0x18(%r12)
testl %eax, %eax
je 0x9dcf
leal 0x1(%r14), %r13d
movq %rbp, %rdi
movq %rbx, %rsi
movl %r14d, %edx
movq %r15, %rcx
movq %r12, %r8
callq 0x45cd
movl %eax, %ebp
movl %r13d, %r14d
jmp 0x9dd1
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movl %r14d, %edx
leaq 0x83fd(%rip), %rcx      # 0x121c7
callq 0x3cc3
xorl %ebp, %ebp
movq 0x10(%r12), %r12
testl %ebp, %ebp
setne %al
testq %r12, %r12
je 0x9e06
testl %ebp, %ebp
jne 0x9d5b
jmp 0x9e06
movq 0xf37f(%rip), %rcx      # 0x19170
xorl %ebp, %ebp
movq %r15, %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x3cc3
jmp 0x9e28
movb $0x1, %al
testb %al, %al
je 0x9e1e
movq 0x38(%rsp), %rax
movq %rax, 0x28(%rbx)
movq 0x30(%rsp), %rax
movq %rbx, 0x8(%rax)
jmp 0x9e28
movq %rbx, %rdi
callq 0x3979
xorl %ebp, %ebp
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x9e37
callq 0x3979
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x9e46
callq 0x3b29
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x50(%rsp), %r12
leaq -0x6391(%rip), %rax     # 0x3ad5
cmpq %rax, 0x18(%rbx)
movq 0x30(%rsp), %r14
je 0x9c32
movq 0x18(%rsp), %rax
movl (%rax), %esi
movq %r12, %rdi
callq 0x9e89
jmp 0x9c32