use warnings;

use Inline C => <<'EOC';

AV * sum(SV * x, ...) {
	Inline_Stack_Vars;
	long array_size, i;
	AV * ret = newAV();

	array_size = SvUV(Inline_Stack_Item(0));

	if (Inline_Stack_Items != (2 * array_size) + 1) {
		croak("bad number of arguments supplied to sum");
	}

	// for efficiency, make the array big enough 
     av_extend(ret, array_size - 1);

	/* multiply corresponding array elements and push the result into ret */
	for(i = 1; i <= array_size; i++) {
		double x_i = SvNV(Inline_Stack_Item(i));
		double y_i = SvNV(Inline_Stack_Item(i + array_size));
		
		av_push(ret, newSVnv(x_i + y_i));
	}
	return ret;
}
EOC

my @num1 = (2.2, 3.3, 4.4,5.5);
my @num2 = (6.6, 7.7, 8.8, 9.9);

$arref = sum(scalar(@num1), @num1, @num2);

print "@$arref\n";

