use strict;
my $f = 0;
my %sym;
my %adrs;
my %radr;
my @dis;
my $section;
my $s_vaddr;
while(<>){
	my @l = split;
	if($l[0] eq 'r_vaddr'){
		my $num = pop @l;
		push @l, $sym{$num};
		$adrs{oct($l[2])} = $sym{$num};
		print oct($l[2]);
		print join(' ', @l) . "\n";
	} elsif($f == 1){
		if(substr($_, 0, 1) ne 'R'){
			chop $l[0];
			if($l[1] ne '.bf' && $l[1] ne '.ef'){
				if(substr($l[1], 0, 1) eq '.'){
					$l[1] .= '#' . $l[0];
				}
				$sym{$l[0]} = $l[1];
				my $r1;
				if(substr($l[2], 0, 1) eq '('){
					splice @l, 2, 1;
				}
				$r1 = substr($l[2], 8) . '@' . oct(substr($l[5], 1));
				$radr{$r1} = $l[1];
				print "@@ $r1 = $l[1] @@\n";
			}
			print $_;
		} else {
			$f = 0;
			print "End\n";
			print $_;
		}
	} elsif(/SYMBOL TABLE ENTRIES/){
		print "Start\n";
		$f = 1;
	} elsif(substr($l[0], 0, 2) eq '0x') {
		push @dis, $_;
	} elsif($l[4] eq 'HEADER'){
		$section = $l[0];
		chop $section;
		print $section . "@@ \n";
		print $_;
	} elsif($l[0] eq 's_vaddr'){
		$s_vaddr = oct($l[2]);
		print $_;
	} elsif($l[0] eq 'READING'){
		my $line;
		foreach $line (@dis){
			my $adr = oct(substr($line, 0, 10));
			my $radr = $section . '@' . ($adr - $s_vaddr);
			my $rsym = $radr{$radr};
			if(defined($rsym)){
				print $rsym . "\n";
			}
			my $sym = $adrs{$adr};
			if(defined($sym)){
				chop $line;
				print $line . "\t\# $sym\n";
			} else {
				print $line;
			}
		}
		undef @dis;
	} else {
		print $_;
	}
}