#!/usr/bin/perl
my $var = '';
my $found = 0;
while (my $line = <>) {
  if ($line =~ /(\w+) = (new |((UTF8)?ToNewUnicode|ToNew(C|UTF8)String)\s*\()/) {
    $var = $1;
    $found = 1;
  }
  elsif ($found) {
    my $pre = '(if\s*\(\s*)';
    my $post = '(?!\w)';
    $line =~ s/$pre(\!\s*$var)$post/$1NS_UNLIKELY\($2\)/;
    $line =~ s/$pre($var == nsnull)$post/$1NS_UNLIKELY\($2\)/;
    $line =~ s/$pre(nsnull == $var)$post/$1NS_UNLIKELY\($2\)/;
    $line =~ s/$pre($var == 0)$post/$1NS_UNLIKELY\($2\)/;
    $line =~ s/$pre(0 == $var)$post/$1NS_UNLIKELY\($2\)/;
    $found = 0;
  }
  print $line;
}
1;
