use warnings;


use Inline C => <<'EOC';

AV * sum(SV * x, ...) {
	Inline_Stack_Vars;
	long array_size, i;
	// create array that will be returned to perl
	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);

	for(i = 1; i <= array_size; i++) {
		unsigned long int x_i = SvUV(Inline_Stack_Item(i));
		unsigned long int y_i = SvUV(Inline_Stack_Item(i + array_size));
		av_push(ret, newSVuv(x_i + y_i));
	}
	
	return ret;
}

EOC

my @num1 = (2, 3, 4, 5);
my @num2 = (6, 7, 8, 9);

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

print "@$arref\n";

