// File: /workspace/github_c_makefile_star2_O2/martincameron[P]towntalk/optimizer.c
// Function: compile_arithmetic_expression
static struct instruction* compile_arithmetic_expression( struct arithmetic_statement *stmt, struct expression *expr, int top, char *message ) {
	struct instruction *insn;
	struct expression *parameter;
	enum arithmetic_op oper = get_arithmetic_op( expr );
	if( top > 6 ) {
		insn = add_instruction( &stmt->insns, PUSH_EXPR, 0, expr, message );
	} else if( oper ) {
		parameter = expr->parameters;
		insn = compile_arithmetic_expression( stmt, parameter, top, message );
		while( insn && parameter->next ) {
			parameter = parameter->next;
			insn = compile_arithmetic_expression( stmt, parameter, top + 1, message );
			if( insn ) {
				if( insn->oper == PUSH_CONST ) {
					insn->oper = oper + AND_CONST - AND_STACK;
				} else if( insn->oper == PUSH_LOCAL ) {
					insn->oper = oper + AND_LOCAL - AND_STACK;
				} else {
					insn = add_instruction( &stmt->insns, oper, 0, parameter, message );
				}
			}
		}
	} else if( expr->evaluate == evaluate_number_literal_expression ) {
		insn = add_instruction( &stmt->insns, PUSH_CONST, expr->index, expr, message );
		if( insn ) {
			insn->value = ( ( struct value_expression * ) expr )->num;
		}
	} else if( expr->evaluate == evaluate_local ) {
		insn = add_instruction( &stmt->insns, PUSH_LOCAL, expr->index, expr, message );
	} else if( expr->evaluate == evaluate_local_post_inc ) {
		insn = add_instruction( &stmt->insns, PUSH_LOCAL_PI, expr->index, expr, message );
	} else if( expr->evaluate == evaluate_local_post_dec ) {
		insn = add_instruction( &stmt->insns, PUSH_LOCAL_PD, expr->index, expr, message );
	} else if( expr->evaluate == evaluate_index_expression && expr->parameters->evaluate == evaluate_local ) {
		insn = compile_arithmetic_expression( stmt, expr->parameters->next, top, message );
		if( insn ) {
			insn = add_instruction( &stmt->insns, PUSH_ARRAY, expr->parameters->index, expr, message );
		}
	} else if( expr->evaluate == evaluate_chr_expression && expr->parameters->evaluate == evaluate_local ) {
		insn = compile_arithmetic_expression( stmt, expr->parameters->next, top, message );
		if( insn ) {
			insn = add_instruction( &stmt->insns, PUSH_STRING, expr->parameters->index, expr, message );
		}
	} else if( expr->evaluate == evaluate_unpack_expression && expr->parameters->evaluate == evaluate_global ) {
		insn = compile_arithmetic_expression( stmt, expr->parameters->next, top, message );
		if( insn ) {
			insn = add_instruction( &stmt->insns, PUSH_UNPACK, 0, expr->parameters, message );
		}
	} else if( expr->evaluate == evaluate_global ) {
		insn = add_instruction( &stmt->insns, PUSH_GLOBAL, 0, expr, message );
	} else {
		insn = add_instruction( &stmt->insns, PUSH_EXPR, 0, expr, message );
	}
	return insn;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %rbx
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %r14
movq 0x18(%rsi), %r13
xorl %r12d, %r12d
cmpq 0x9ed1(%rip), %r13      # 0x17fd0
jne 0xe128
movl 0x4(%r15), %esi
leaq 0x4178(%rip), %rdi      # 0x12284
pushq $0xc
popq %rdx
callq 0x3110
testq %rax, %rax
je 0xe128
leaq 0x4164(%rip), %rcx      # 0x12284
subl %ecx, %eax
addl $0x17, %eax
movl %eax, %r12d
cmpl $0x7, %ebp
jl 0xe152
addq $0x28, %r14
pushq $0xb
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
movq %r15, %rcx
movq %rbx, %r8
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xe37e
testl %r12d, %r12d
je 0xe1ea
movq 0x8(%r15), %r15
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %rbx, %rcx
callq 0xe0db
incl %ebp
leal 0x16(%r12), %ecx
movl %ecx, 0x4(%rsp)
leal 0xb(%r12), %ecx
movl %ecx, (%rsp)
leaq 0x28(%r14), %r13
testq %rax, %rax
je 0xe36d
movq 0x10(%r15), %r15
testq %r15, %r15
je 0xe36f
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
movq %rbx, %rcx
callq 0xe0db
movq %rax, %rcx
movl $0x0, %eax
testq %rcx, %rcx
je 0xe186
movl (%rcx), %eax
cmpl $0x2, %eax
je 0xe1ca
cmpl $0x1, %eax
jne 0xe1d5
movl (%rsp), %eax
jmp 0xe1ce
movl 0x4(%rsp), %eax
movl %eax, (%rcx)
movq %rcx, %rax
jmp 0xe186
movq %r13, %rdi
movl %r12d, %esi
xorl %edx, %edx
movq %r15, %rcx
movq %rbx, %r8
callq 0xe37e
jmp 0xe186
cmpq 0x9dcf(%rip), %r13      # 0x17fc0
je 0xe259
cmpq 0x9dae(%rip), %r13      # 0x17fa8
je 0xe287
cmpq 0x9d89(%rip), %r13      # 0x17f90
je 0xe293
cmpq 0x9d6c(%rip), %r13      # 0x17f80
je 0xe29f
cmpq 0x9dcf(%rip), %r13      # 0x17ff0
je 0xe2b2
cmpq 0x9d5a(%rip), %r13      # 0x17f88
je 0xe2f0
cmpq 0x9d3d(%rip), %r13      # 0x17f78
je 0xe32d
cmpq 0x9d80(%rip), %r13      # 0x17fc8
jne 0xe12d
addq $0x28, %r14
pushq $0x4
jmp 0xe133
addq $0x28, %r14
movl 0x4(%r15), %edx
pushq $0x1
popq %rsi
movq %r14, %rdi
movq %r15, %rcx
movq %rbx, %r8
callq 0xe37e
testq %rax, %rax
je 0xe36d
movl 0x28(%r15), %ecx
movl %ecx, 0x10(%rax)
jmp 0xe36f
addq $0x28, %r14
movl 0x4(%r15), %edx
pushq $0x2
jmp 0xe2a9
addq $0x28, %r14
movl 0x4(%r15), %edx
pushq $0x7
jmp 0xe2a9
addq $0x28, %r14
movl 0x4(%r15), %edx
pushq $0x9
popq %rsi
movq %r14, %rdi
jmp 0xe139
movq 0x8(%r15), %rax
movq 0x18(%rax), %rcx
cmpq 0x9ce7(%rip), %rcx      # 0x17fa8
jne 0xe12d
movq 0x10(%rax), %rsi
movq %r14, %rdi
movl %ebp, %edx
movq %rbx, %rcx
callq 0xe0db
testq %rax, %rax
je 0xe36d
addq $0x28, %r14
movq 0x8(%r15), %rax
movl 0x4(%rax), %edx
pushq $0xd
jmp 0xe2a9
movq 0x8(%r15), %rax
movq 0x18(%rax), %rcx
cmpq 0x9ca9(%rip), %rcx      # 0x17fa8
jne 0xe12d
movq 0x10(%rax), %rsi
movq %r14, %rdi
movl %ebp, %edx
movq %rbx, %rcx
callq 0xe0db
testq %rax, %rax
je 0xe36d
addq $0x28, %r14
movq 0x8(%r15), %rax
movl 0x4(%rax), %edx
pushq $0xf
jmp 0xe2a9
movq 0x8(%r15), %rax
movq 0x18(%rax), %rcx
cmpq 0x9c8c(%rip), %rcx      # 0x17fc8
jne 0xe12d
movq 0x10(%rax), %rsi
movq %r14, %rdi
movl %ebp, %edx
movq %rbx, %rcx
callq 0xe0db
testq %rax, %rax
je 0xe36d
addq $0x28, %r14
movq 0x8(%r15), %rcx
pushq $0x10
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
jmp 0xe13c
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq