#!/bin/sh

if test $# -ne 1; then
	echo "usage: mprpc a.out" >&2
	exit 1
fi

if file $1 | grep ELF >/dev/null 2>&1; then
	start=_start
else
	start=__entry
fi

nm -n $1 |

awk '
	BEGIN {
		for (i=0; i<10; i++) hexv[i""]=i
		hexv["a"]=10; hexv["b"]=11; hexv["c"]=12
		hexv["d"]=13; hexv["e"]=14; hexv["f"]=15
	}
	function hex(h, d,l) {
		d=0; l=length(h)
		for (i=1; i<=l; i++)
			d = d*16 + hexv[substr(h, i, 1)]
		return d
	}

	NF==3 && $2 ~ /T|t/ && $3 ~ /^'$start'$/ {
		a=$1
		getline
		printf "%d:%d", hex(a), hex($1)-1
		exit 0
	}'

exit 0
