#include <perms.h>
static const int Maxperm = 54;
static const int Perms[733 /*1:733*/] = {
    0x0037, 0x018E, 0x019A, 0x01A4, 0x01B8, 0x024B, 0x01EE, 0x01FB, 0x01CF, 0x0000, 0x0084, 0x00A3, 0x00C6, 0x0046,
    0x00DB, 0x0000, 0x0000, 0x02C4, 0x02B5, 0x02A6, 0x029E, 0x0298, 0x0292, 0x0282, 0x0210, 0x003C, 0x005E, 0x0059,
    0x0218, 0x0141, 0x0184, 0x0050, 0x004B, 0x0077, 0x0070, 0x0069, 0x0063, 0x007F, 0x0041, 0x0169, 0x0220, 0x0225,
    0x022A, 0x022F, 0x024E, 0x0055, 0x0057, 0x0235, 0x023A, 0x023F, 0x0245, 0x016E, 0x017A, 0x026F, 0x0004, 0x2440,
    0x583D, 0x0004, 0x0303, 0x0004, 0x2441, 0x583D, 0x0004, 0x0303, 0x0004, 0x2445, 0x583D, 0x0004, 0x0303, 0x0004,
    0x2442, 0x583D, 0x0004, 0x0303, 0x0004, 0x2443, 0x583D, 0x0004, 0x0303, 0x0004, 0x2444, 0x583D, 0x0004, 0x0303,
    0x0001, 0x0000, 0x0001, 0x0000, 0x0004, 0x2449, 0x583D, 0x0004, 0x0303, 0x0004, 0x244A, 0x583D, 0x0004, 0x0303,
    0x0005, 0x246A, 0x2445, 0x583D, 0x0004, 0x0303, 0x0006, 0x0856, 0x246A, 0x2447, 0x583D, 0x0004, 0x0303, 0x0006,
    0xC860, 0x0020, 0x2445, 0x583D, 0x0004, 0x0303, 0x0007, 0x0856, 0xC860, 0x0020, 0x2447, 0x583D, 0x0004, 0x0303,
    0x0004, 0x2446, 0x583D, 0x0004, 0x0303, 0x001E, 0x4801, 0x0000, 0xC500, 0x8080, 0x2135, 0x2401, 0x2410, 0x8888,
    0x0001, 0x9400, 0x9330, 0x1001, 0x2188, 0xD301, 0x4300, 0x0000, 0xD202, 0x4300, 0x0000, 0x2308, 0x2731, 0x4801,
    0x4300, 0x0000, 0x4002, 0x4300, 0x0000, 0x2732, 0x2217, 0x0308, 0x0022, 0x4801, 0x0000, 0xC500, 0x8080, 0x2135,
    0x2401, 0x2410, 0x8888, 0x0001, 0x9400, 0x9300, 0xD352, 0x0000, 0x0865, 0x0A62, 0x0A50, 0xC550, 0x00FF, 0x2325,
    0x2405, 0x241C, 0x8888, 0x0001, 0xD252, 0x0000, 0x2701, 0x0218, 0x2661, 0x2611, 0xD331, 0x0000, 0xD236, 0x0000,
    0x2208, 0x0014, 0x0862, 0xD301, 0x0000, 0xD352, 0x0000, 0x0B50, 0x2318, 0x0A05, 0x2306, 0xD336, 0x0000, 0xD431,
    0x0000, 0x0238, 0x2611, 0x2661, 0x2701, 0x2218, 0x0855, 0x0308, 0x005D, 0xD0B7, 0x0100, 0x08B2, 0x48D1, 0x0000,
    0xC5D0, 0x8080, 0x2338, 0x94DD, 0x93DD, 0x4802, 0x0000, 0xC500, 0x8080, 0x2135, 0x2401, 0x2410, 0x8888, 0x0001,
    0x9400, 0x9300, 0x0B0D, 0x4210, 0x8022, 0x08CB, 0x08E1, 0x08FD, 0x27F1, 0x4210, 0x801E, 0x26C1, 0x26E1, 0xD33C,
    0x0000, 0xD43E, 0x0000, 0x2239, 0x26B1, 0x2701, 0x4300, 0xFFDa, 0xD1B7, 0x0100, 0x0801, 0x0308, 0x0866, 0x2135,
    0x05B2, 0x2037, 0x4300, 0x801C, 0x083B, 0x0B32, 0xD236, 0x0000, 0x08CC, 0x05BC, 0x2338, 0x2661, 0x26C1, 0xD336,
    0x0000, 0xD23C, 0x0000, 0x2208, 0x0855, 0x2136, 0x0800, 0x4230, 0xFFC6, 0x4300, 0x8022, 0x0ABD, 0xD302, 0x0000,
    0x0A02, 0x0830, 0x0B3B, 0xD235, 0x0000, 0x05B0, 0x2338, 0x26B1, 0x2651, 0xD335, 0x0000, 0xD23B, 0x0000, 0x2208,
    0xD1B7, 0x0000, 0x05DD, 0x0308, 0x0007, 0x0827, 0xC810, 0x0100, 0x9261, 0x4012, 0x0000, 0x0308, 0x0027, 0x4836,
    0x0000, 0xC530, 0x8080, 0x2135, 0x2401, 0x2410, 0x8888, 0x0001, 0x9433, 0x9333, 0x0855, 0x2328, 0x5807, 0x002C,
    0x0503, 0x2124, 0x0B05, 0x2601, 0x2315, 0x2405, 0x2419, 0x8888, 0x0001, 0xC837, 0x002C, 0x0813, 0xD203, 0x0000,
    0x0A65, 0x2701, 0x0218, 0x2631, 0xD326, 0x0000, 0xD223, 0x0000, 0x2661, 0x2208, 0x0004, 0x2448, 0x583D, 0x0004,
    0x0303, 0x000B, 0x6827, 0x002C, 0x5867, 0x0030, 0x5857, 0x0034, 0xC840, 0x0016, 0x583D, 0x0004, 0x0303, 0x0009,
    0x6827, 0x002C, 0x5867, 0x0030, 0xC840, 0x0017, 0x583D, 0x0004, 0x0303, 0x0009, 0x5867, 0x002C, 0x5857, 0x0030,
    0xC840, 0x0015, 0x583D, 0x0004, 0x0303, 0x000B, 0x0830, 0x0A33, 0x2734, 0x0218, 0x5801, 0x4300, 0x0000, 0x5002,
    0x4300, 0x0000, 0x2208, 0x0009, 0x0830, 0x0A33, 0x2400, 0x2734, 0x0218, 0x5002, 0x4300, 0x0000, 0x2205, 0x0013,
    0x0831, 0x4932, 0x0002, 0x212B, 0x4B32, 0x0000, 0x2118, 0x0A33, 0x7333, 0x4200, 0x0004, 0x2333, 0x0A3E, 0x0233,
    0x0821, 0x2405, 0x2414, 0x8888, 0x0001, 0x0016, 0x5016, 0x0008, 0x5036, 0x0004, 0x5056, 0x0000, 0xCB35, 0xFFFF,
    0x2125, 0x2405, 0x2416, 0x8888, 0x0001, 0x1C21, 0x1C05, 0x2400, 0x0B01, 0xC813, 0x0003, 0xC410, 0xFFFC, 0x0308,
    0x001E, 0x5073, 0x0000, 0x5103, 0x0000, 0x5063, 0x0004, 0x0827, 0x0A71, 0x583D, 0x0000, 0xC973, 0xFE00, 0x2327,
    0x0B71, 0x0821, 0x2402, 0x2410, 0x8888, 0x0001, 0x585E, 0x0010, 0xF550, 0x8080, 0x8080, 0x0238, 0x5051, 0x42FF,
    0xFFFC, 0x2714, 0x2035, 0x000C, 0x0833, 0x2316, 0x0823, 0x2405, 0x241A, 0x8888, 0x0001, 0x2411, 0x2731, 0x0218,
    0x1C02, 0x2203, 0x000D, 0x2401, 0x2F00, 0x0801, 0x2316, 0x2D02, 0x2820, 0x2400, 0xCB01, 0x0001, 0x0338, 0x2C02,
    0x2701, 0x2203, 0x0002, 0x0816, 0x0308, 0x0003, 0x0816, 0x0A15, 0x0308, 0x0007, 0xC817, 0x002C, 0xC840, 0x0011,
    0x583D, 0x0004, 0x0303, 0x0007, 0xC817, 0x002C, 0xC840, 0x0012, 0x583D, 0x0004, 0x0303, 0x0004, 0x244D, 0x583D,
    0x0004, 0x0303, 0x0004, 0x244E, 0x583D, 0x0004, 0x0303, 0x0004, 0x244F, 0x583D, 0x0004, 0x0303, 0x0005, 0xC840,
    0x0010, 0x583D, 0x0004, 0x0303, 0x0004, 0x244B, 0x583D, 0x0004, 0x0303, 0x0004, 0x244C, 0x583D, 0x0004, 0x0303,
    0x0005, 0xC840, 0x0013, 0x583D, 0x0004, 0x0303, 0x0005, 0xC840, 0x0014, 0x583D, 0x0004, 0x0303, 0x0002, 0x2F01,
    0x0308, 0x0008, 0x581D, 0x0000, 0x0B17, 0x0318, 0x2402, 0x2410, 0x8888, 0x0001, 0x000B, 0x6807, 0x002C, 0xF810,
    0x4080, 0x0000, 0x5017, 0x002C, 0x6A07, 0x002C, 0x2E10, 0x0308, 0x0004, 0x6807, 0x002C, 0x2E10, 0x0308, 0x0006,
    0x6807, 0x002C, 0x2E10, 0x2F21, 0x2B02, 0x0308, 0x0012, 0x5817, 0x002C, 0xC460, 0x000F, 0x1164, 0xC660, 0xE101,
    0x4067, 0x0000, 0x2460, 0x4067, 0x0002, 0xC860, 0x0308, 0x4067, 0x0004, 0x4307, 0x0000, 0x000F, 0x0822, 0x233A,
    0x0B10, 0x0801, 0xEE00, 0x001F, 0x1D02, 0x2611, 0x2113, 0x0800, 0x0338, 0x2405, 0x2411, 0x8888, 0x0001, 0x0005,
    0x0338, 0x2406, 0x2411, 0x8888, 0x0001, 0x0005, 0x0348, 0x2406, 0x2411, 0x8888, 0x0001, 0x0007, 0xD401, 0x0000,
    0x0388, 0x2406, 0x2411, 0x8888, 0x0001, 0x000E, 0x5912, 0x0000, 0x2117, 0x5912, 0x0004, 0x2124, 0x5C02, 0x0008,
    0x0308, 0x0821, 0x2406, 0x2412, 0x8888, 0x0001, 0x000E, 0x4A78, 0x0000, 0x580D, 0x0000, 0xC507, 0x0200, 0x4388,
    0x0002, 0x4B78, 0x0000, 0x2402, 0x2410, 0x8888, 0x0001, 0x0019, 0x0847, 0x4A48, 0x0000, 0x4A78, 0x0002, 0x580D,
    0x0000, 0xC507, 0x0200, 0x2387, 0x4B78, 0x0002, 0x2402, 0x2410, 0x8888, 0x0001, 0x580E, 0x0010, 0x5004, 0x0000,
    0x2644, 0x0547, 0x2224, 0x4308, 0x0004};
static const int Pseudoobj = 2;
static const int Direct = 3;
static const int Report = 0;
static const int Object = 2;
static const int Not[13 /*0:12*/] = {1, 0, 5, 4, 3, 2, 7, 6, 11, 10, 9, 8, 12};
static const int Sb[13 /*0:12*/] = {0x2230, 0x2030, 0x2010, 0x2020, 0x2220, 0x2210, 0x2230,
                                    0x2030, 0x2020, 0x2010, 0x2210, 0x2220, 0x2200};
static const int Sf[13 /*0:12*/] = {0x2330, 0x2130, 0x2110, 0x2120, 0x2320, 0x2310, 0x2330,
                                    0x2130, 0x2120, 0x2110, 0x2310, 0x2320, 0x2300};
static const int Lj[13 /*0:12*/] = {0x433E, 0x423E, 0x421E, 0x422E, 0x432E, 0x431E, 0x433E,
                                    0x423E, 0x422E, 0x421E, 0x431E, 0x432E, 0x430E};
static const int Maxpatch = 450;
static const int Maxjumps = 3000;
static const int Maxlabels = 2000;
int _imp_mainep(int _imp_argc, char **_imp_argv) {
  typedef struct Pfm {
    int What;
    int Where;
  } Pfm;
  typedef struct Lfm {
    int Lab;
    int Ca;
  } Lfm;
  Lfm Jump[3001 /*1:3001*/];
  Pfm Patch[450 /*1:450*/];
  int Lab[2001 /*0:2000*/];
  int Ltemp[10 /*0:9*/];
  int Pep[54 /*1:54*/];
  int Paddr[54 /*1:54*/];
  int Ca;
  int Ga;
  int La;
  int Da;
  int Linesize;
  int Codesize;
  int Glasize;
  int Loadsize;
  int Permsize;
  int Diagsize;
  static const int Emark = 0x8888;
  static const int Never = 0x7FFF;
  static const int Long = 0x800000;
  static const int Cond = 0x400000;
  static const int Perm = 0x200000;
  static const int Rt = 0x100000;
  static const int Very = 0x080000;
  static const int Label = 0xFFFF;
  static int Maxlabel = 1;
  static int Initgla = 0;
  int Refextra;
  int Ignore;
  int Flag;
  int Refs;
  int Currentline;
  int J;
  int K;
  int L;
  int Z;
  int Cp;
  int Gp;
  int Code;
  int Tag;
  int Extra;
  Pfm *Pat;
  int Ctag;
  int Cca;
  int Uca;
  int Defmod;
  int Last;
  int Mode;
  int Caddr;
  int Cval;
  int Gaddr;
  int Gval;
  static int D_sw;
  static void *D[8 /*1:8*/] = {
      &&D_1, &&D_2, &&D_3, &&D_4, &&D_5, &&D_6, &&D_7, &&D_8,
  };
  static int C_sw;
  static void *C[10 /*2:11*/] = {
      &&C_2, &&C_3, &&C_4, &&C_5, &&C_6, &&C_7, &&C_8, &&C_9, &&C_10, &&C_11,
  };
  Lfm *Uref;
  Lfm *Cref;
  Lfm *R;
  Lfm *B;
  int *V;
  int Phase;
  int Rx1;
  int Rx2;
  int Rx3;
  int Sj;
  Rx1 = 0;
  Rx2 = 0;
  Rx3 = 0;
  Sj = 0;
  int Rtncalls;
  int Permcalls;
  Rtncalls = 0;
  Permcalls = 0;
  short Cbp;
  short Gbp;
  short Lbp;
  short Dbp;
  short Tbp;
  static const int Codebuffsize = 200;
  static const int Glabuffsize = 256;
  static const int Ldbuffsize = 200;
  static const int Diagbuffsize = 256;
  short Tbuff[256 /*1:256*/];
  short Dbuff[256 /*1:256*/];
  short Cbuff[200 /*1:200*/];
  short Gbuff[256 /*1:256*/];
  short Lbuff[200 /*1:200*/];
  static const int Endoffileblock = 0;
  static const int Nondiagcodeblock = 1;
  static const int Diagcodeblock = 2;
  static const int Staticdatablock = 3;
  static const int Diagsdatablock = 4;
  static const int Diagtable = 5;
  static const int Entrypointblock = 6;
  static const int Externalrefblock = 7;
  static const int Segmentsizeblock = 15;
  void Get(int *N) {
    int S;
    Readsymbol(*N);
    Readsymbol(S);
    *N = *N << 8 | S;
  }
  void Puthalf(short N) {
    Printsymbol(((unsigned)N >> 8) & 255);
    Printsymbol(N & 255);
  }
  void Putblock(short Header, short Block) {
    short I;
    short J;
    Puthalf(Header);
    for (I = 1; I <= ((unsigned)Header >> 4) & 0x0FFF; I++) {
      J = Block;
      Header += J;
      Puthalf(J);
    }
    Puthalf(-Header - 1);
  }
  void Copyblock(short Header) {
    short I;
    int N;
    Puthalf(Header);
    for (I = 1; I <= ((unsigned)Header >> 4) & 0x0FFF; I++) {
      Get(N);
      Header += N;
      Puthalf(N);
    }
    Puthalf(-Header - 1);
  }
  void Cflush(void) {
    if (Cbp != 1) Putblock((Cbp << 4) | Diagcodeblock, Cbuff);
    Cbp = 1;
    Cbuff[1] = Currentline;
  }
  void Gflush(void) {
    if (Gbp) Putblock((Gbp << 4) | Staticdatablock, Gbuff);
    Gbp = 0;
  }
  void Lflush(void) {
    if (Lbp) Putblock((Lbp << 4) | Externalrefblock, Lbuff);
    Lbp = 0;
  }
  void Dflush(void) {
    if (!Dbp) return;
    Putblock((Dbp << 4) + Diagsdatablock, Dbuff);
    Dbp = 0;
  }
  void Tflush(void) {
    if (Tbp) Putblock((Tbp << 4) | Diagtable, Tbuff);
    Tbp = 0;
  }
  void Cput(short N) {
    Cbp++;
    Cbuff[Cbp] = N;
    Ca += 2;
  }
  void Gput(short N) {
    if (Gbp == Glabuffsize) Gflush();
    Gbp++;
    Gbuff[Gbp] = N;
    Ga += 2;
  }
  void Lput(short N) {
    if (Lbp == Ldbuffsize) Lflush();
    Lbp++;
    Lbuff[Lbp] = N;
    La += 2;
  }
  void Lsym(short N) {
    static int Flag;
    static int V;
    Flag = ~Flag;
    if (!Flag)
      Lput((N << 8) + V);
    else
      V = N;
  }
  void Dput(short N) {
    Dbp++;
    Dbuff[Dbp] = N;
    if (Dbp == Diagbuffsize) Dflush();
    Da += 2;
  }
  void Diagline(void) {
    static int Here = 0;
    if (Here == Currentline) return;
    Here = Currentline;
    Dput(Currentline);
    Dput(Ca);
  }
  void Tput(short V) {
    Tbp++;
    Tbuff[Tbp] = V;
    if (Tbp == Diagbuffsize) Tflush();
  }
  void Closeobjectfile(void) {
    Cflush();
    Gflush();
    Lflush();
    Dput(0);
    Dput(0);
    Dflush();
    Tput(0x8800);
    Tput(Ca + 2);
    Tput(0);
    Tput(0);
    Tput(0);
    Tput(0);
    Tput(0);
    Tput(0);
    Tflush();
    Puthalf((0 << 4) | Endoffileblock);
    Puthalf(-Endoffileblock - 1);
  }
  void Monitor(int N) {
    Selectoutput(Report);
    Printstring(_imp_str_literal("FAULT"));
    Write(N, 1);
    Printstring(_imp_str_literal("   PHASE"));
    Write(Phase, 1);
    Newline();
    Write(Refs, 1);
    Printstring(_imp_str_literal(" REFS"));
    Newline();
    Printstring(_imp_str_literal("MAX LABEL"));
    Write(Maxlabel, 1);
    Newline();
    _imp_signal(15, 15, 0, _imp_str_literal(""));
  }
  void Sort(int From, int To) {
    int Flag;
    int J;
    int T;
    Pfm *A;
    Pfm *B;
    while (To > From) {
      Flag = 0;
      A = &Patch[From];
      for (J = From + 1; J <= To; J++) {
        B = &Patch[J];
        if (A->Where > B->Where) {
          T = A->Where;
          A->Where = B->Where;
          B->Where = T;
          T = B->What;
          B->What = A->What;
          A->What = T;
          Flag = 1;
        } else if (A->Where == B->Where) {
          Flag = 1;
          A->Where = -10;
        }
        A = B;
      }
      if (!Flag) break;
      To--;
    }
  }
  void Nextcode(void) {
    static int P = 1;
    static int J = 1;
    int C;
    int Bv;
    Pfm *Pp;
    C = Never;
    Bv = Never;
    Mode = Never;
    if (P <= Cp) {
      for (;;) {
        Pp = &Patch[P];
        if (Pp->Where != -10) break;
        P++;
      }
      C = (unsigned)Pp->Where >> 1;
    }
    if (J < Refs) {
      B = &Jump[J];
      Bv = (unsigned)B->Ca >> 1;
    }
    Caddr = Never;
    if (Bv == Never && Never == C) return;
    if (Bv > C) {
      P++;
      Caddr = Pp->Where;
      Cval = Pp->What;
      return;
    }
    if (C > Bv) {
      J++;
      Mode = 0;
      Caddr = B->Ca;
      return;
    }
    Monitor(1);
  }
  void Nextgla(void) {
    if (Gp > Maxpatch) {
      Gaddr = Never;
      return;
    }
    do {
      Pat = &Patch[Gp];
      Gp++;
    } while (Pat->Where < 0);
    Gaddr = Pat->Where;
    Gval = Pat->What;
  }
  void Setperm(int N) {
    int J;
    int K;
    if (Pep[N] != 1) return;
    Pep[N] = 2;
    K = Perms[N];
    if (!K) {
      Selectoutput(Report);
      Printstring(_imp_str_literal("NO ENTRY FOR PERM"));
      Write(N, 1);
      Newline();
      Pep[N] = 0;
      Selectoutput(Object);
      return;
    }
    for (J = 1; J <= Perms[K]; J++) {
      K++;
      if (Perms[K] == Emark) {
        N = Perms[K + 1];
        if (Pep[N] != 2) {
          Pep[N] = 1;
          Setperm(N);
        }
      }
    }
  }
  void Plantlongjump(void) {
    int N;
    if (!(B->Lab & Very)) {
      N = Tag - (Ca + 4);
      if (-16 * 1024 <= N && N < 16 * 1024) {
        L = L & 0xFFF0;
        Cput(L);
        Cput(N | 0x8000);
        Rx2++;
      } else {
        Cput(L);
        Cput(Tag);
        Rx1++;
      }
    } else {
      Cput(L);
      Cput(((unsigned)Tag >> 16 & 0xFF) + 0x4000);
      Cput(Tag);
      Rx3++;
    }
  }
  Phase = 1;
  for (J = 1; J <= Maxperm; J++) {
    Pep[J] = 0;
    Paddr[J] = 0;
  }
  Cp = 0;
  Gp = Maxpatch + 1;
  Refs = 0;
  Defmod = 0;
  Uca = 0;
  Cca = 0;
  Ctag = 0;
  for (J = 1; J <= Maxlabels; J++) Lab[J] = 0;
  Selectinput(Direct);
  Readsymbol(Initgla);
  for (;;) {
    Readsymbol(Code);
    goto *D[D_sw = (Code)-1];
  D_1:;
    Get(Tag);
    Get(Ca);
    if (Tag > Maxlabels) Monitor(2);
    if (Tag > Maxlabel) Maxlabel = Tag;
    if (Tag == Ctag && Cca == Ca && Uca == Ca) {
      Defmod += 2;
      Uref->Lab = Uref->Lab | Perm | Cond;
      Cref->Lab = Cref->Lab | Very | Rt;
      Ctag = Uref->Lab & Label;
      Cref = Uref;
      Cca = Ca + 2;
    } else
      Ctag = 0;
    Lab[Tag] = Ca;
    continue;
  D_2:;
    Flag = Cond;
    goto Curp;
  D_3:;
    Flag = 0;
    goto Curp;
  D_4:;
    Flag = Rt + Long;
    Rtncalls++;
    goto Curp;
  D_5:;
    Flag = Perm + Long;
    Permcalls++;
  Curp:
    Get(Tag);
    Get(Ca);
    Refs++;
    R = &Jump[Refs];
    if (Refs > Maxjumps) Monitor(1);
    R->Lab = Tag + Flag;
    R->Ca = Ca;
    if (!Flag) {
      Uca = Ca + 2;
      Uref = R;
    } else if (Flag == Cond) {
      Cca = Ca + 4;
      Ctag = Tag;
      Cref = R;
    }
    if (Flag & Perm)
      if (Tag > Maxperm || Perms[Tag] == 0) {
        Selectoutput(Report);
        Printstring(_imp_str_literal("NO PERM"));
        Write(Tag, 1);
        Newline();
        Selectoutput(Object);
      } else
        Pep[Tag] = 1;
    continue;
  D_6:;
    Gp--;
    Pat = &Patch[Gp];
    goto Pww;
  D_7:;
    Cp++;
    Pat = &Patch[Cp];
  Pww:
    Get(Tag);
    Get(Ca);
    Pat->What = Tag;
    Pat->Where = Ca;
    if (Cp == Gp) Monitor(4);
  }
D_8:;
  Get(Codesize);
  Get(Glasize);
  Get(Linesize);
  Get(Diagsize);
  Codesize -= Defmod;
  Refs++;
  Jump[Refs] = 0;
  if (Defmod) {
    Refextra = 0;
    for (L = 1; L <= Refs - 1; L++) {
      R = &Jump[L];
      R->Ca = R->Ca - Refextra;
      if ((R->Lab & Cond) != 0 && (R->Lab & Rt) != 0) {
        Refextra += 2;
        for (K = 1; K <= Cp; K++) {
          Pat = &Patch[K];
          if (Pat->Where > R->Ca) Pat->Where = Pat->Where - 2;
        }
        if (Gp <= Maxpatch)
          for (K = Gp; K <= Maxpatch; K++) {
            Pat = &Patch[K];
            if (Pat->What > R->Ca) Pat->What = Pat->What - 2;
            if ((Pat->Where & 1) != 0 && Pat->Where > R->Ca) Pat->Where = Pat->Where - 2;
          }
        for (K = 1; K <= Maxlabel; K++)
          if (Lab[K] > R->Ca) Lab[K] = Lab[K] - 2;
        Defmod -= 2;
      }
    }
    if (Defmod) Monitor(5);
  }
  Permsize = 0;
  for (J = 1; J <= Maxperm; J++) Setperm(J);
  for (J = 1; J <= Maxperm; J++)
    if (Pep[J]) {
      Paddr[J] = Codesize;
      L = Perms[Perms[J]] * 2;
      Codesize += L;
      Permsize += L;
    }
  Phase = 2;
  if (Refs > 1) do {
      Flag = 0;
      Refextra = 0;
      for (L = 1; L <= Refs - 1; L++) {
        R = &Jump[L];
        R->Ca = R->Ca + Refextra;
        if (R->Lab & Very) continue;
        Extra = 0;
        J = R->Lab & Label;
        if ((R->Lab & Perm) == 0 || (R->Lab & Cond) != 0)
          K = Lab[J];
        else
          K = Paddr[J];
        if (-30 > K - R->Ca || K - R->Ca > 30) {
          if (!(R->Lab & Long))
            if (K < 16 * 1024 || -16 * 1024 <= K - (R->Ca + 4) && K - (R->Ca + 4) < 16 * 1024) {
              Extra = 2;
              R->Lab = R->Lab | Long;
            } else {
              Extra = 4;
              R->Lab = R->Lab | Very;
            }
          else if (K >= 16 * 1024 && (-16 * 1024 > K - (R->Ca + 4) || K - (R->Ca + 4) >= 16 * 1024)) {
            Extra = 2;
            R->Lab = R->Lab ^ (Long | Very);
          }
          if (!Extra) continue;
          Flag = 1;
          if (Cp > 0)
            for (K = 1; K <= Cp; K++) {
              Pat = &Patch[K];
              if (Pat->Where > R->Ca) Pat->Where = Pat->Where + Extra;
            }
          if (Gp <= Maxpatch)
            for (K = Gp; K <= Maxpatch; K++) {
              Pat = &Patch[K];
              if (Pat->What > R->Ca) Pat->What = Pat->What + Extra;
            }
          for (K = 1; K <= Maxlabel; K++) {
            V = &Lab[K];
            if (*V > R->Ca) *V = *V + Extra;
          }
          for (K = 1; K <= Maxperm; K++)
            if (Paddr[K]) Paddr[K] = Paddr[K] + Extra;
          Refextra += Extra;
          Codesize += Extra;
        }
      }
    } while (Flag);
  Phase = 3;
  J = Maxpatch + 1;
  K = J;
  while (J > Gp) {
    J--;
    Pat = &Patch[J];
    if (Pat->Where & 1) {
      Pat->Where = Pat->Where & (~1);
      Cp++;
      Patch[Cp] = *Pat;
    } else {
      K--;
      Patch[K] = *Pat;
    }
  }
  Gp = K;
  Sort(1, Cp);
  Sort(Gp, Maxpatch);
  Selectoutput(Object);
  Puthalf(0x8282);
  Gbuff[1] = (unsigned)(Codesize + 1) >> 1;
  Gbuff[2] = (unsigned)(Glasize + 1) >> 1;
  Gbuff[3] = (unsigned)(Diagsize + 16) >> 1;
  Gbuff[4] = (unsigned)(Linesize + 16) >> 1;
  Putblock((4 << 4) | Segmentsizeblock, Gbuff);
  Selectinput(Pseudoobj);
  Ca = 0;
  Ga = Initgla;
  La = 0;
  Da = 0;
  Currentline = 0;
  Cbp = 1;
  Cflush();
  Gbp = (unsigned)Initgla >> 1;
  Lbp = 0;
  Dbp = 0;
  Tbp = 0;
  Nextcode();
  Nextgla();
  Readsymbol(Code);
  Ignore = 0;
  Last = 0;
  for (;;) {
    Readsymbol(Code);
    goto *C[C_sw = (Code + Ignore) - 2];
  C_2:;
    Get(L);
    if (Ca == Caddr) {
      if (Mode)
        Cput(Cval);
      else {
        Tag = Lab[B->Lab & Label];
        if ((B->Lab & (Perm | Rt)) == 0 || (B->Lab & Cond) != 0) {
          if (B->Lab & (Perm | Rt)) {
            if (B->Lab & Rt) {
              if (!Last) Last = L;
              Last = Not[Last & 15] | 0x8000;
              Nextcode();
              continue;
            }
            L = Last;
            Last = 0;
          }
          L = L & 15;
          if (!(B->Lab & (Long | Very))) {
            J = (Tag - Ca) / 2;
            if (-15 > J || J > 15) Monitor(5);
            if (J < 0)
              Cput(Sb[L] - J);
            else
              Cput(Sf[L] + J);
            Sj++;
          } else {
            L = Lj[L];
            Plantlongjump();
          }
        } else {
          Diagline();
          Ignore = 5;
          if (B->Lab & Perm) Tag = Paddr[B->Lab & Label];
          Plantlongjump();
        }
      }
      Nextcode();
    } else
      Cput(L);
    continue;
  C_11:
    Get(J);
    if (J == 0xFFFF) {
      Get(J);
      Tput(0x4000);
      Tput(Ca);
      continue;
    }
    Tput(J);
    Get(K);
    if (J & 0x8000) K = Ca;
    Tput(K);
    Get(K);
    Tput(K);
    Get(K);
    Tput(K);
    Get(K);
    Tput(K);
    Get(K);
    Tput(K);
    continue;
  C_10:
    Diagline();
    continue;
  C_4:;
  C_9:
    Currentline++;
    Cflush();
    continue;
  C_7:
    Ignore = 0;
    Get(L);
    continue;
  C_6:
    L = Nl;
    J = 0;
    for (K = 1; K <= 9; K++)
      if (L) {
        Readsymbol(L);
        J++;
        Ltemp[J] = L;
      }
    while (L) Readsymbol(L);
    J--;
    Ltemp[0] = J;
    for (J = 0; J <= 8; J++) Lsym(Ltemp[J]);
    Get(K);
    Readsymbol(L);
    Lsym(L);
    Lput(K);
    continue;
  C_8:;
  C_3:;
    Get(L);
    if (Ga == Gaddr) {
      L = Gval;
      Nextgla();
    }
    Gput(L);
  }
C_5:;
  for (J = 1; J <= Maxperm; J++)
    if (Pep[J]) {
      K = Perms[J];
      if (!K) Monitor(6);
      L = Paddr[J];
      if (Ca != L) Monitor(7);
      if (Cbp + Perms[K] > Codebuffsize) Cflush();
      L = K;
      Z = K + Perms[K];
      while (L != Z) {
        L++;
        Tag = Perms[L];
        if (Tag == Emark) {
          Cput(0x4300);
          L++;
          Cput((Paddr[Perms[L]] - Ca - 2) | 0x8000);
        } else
          Cput(Tag);
      }
    }
  Closeobjectfile();
  if (Caddr != Never) Monitor(9);
  if (Gaddr != Never) Monitor(10);
  Selectoutput(Report);
  Da += Diagsize;
  Printstring(_imp_str_literal("CODE"));
  Write(Codesize - Permsize, 1);
  Printstring(_imp_str_literal(" + GLA"));
  Write(Glasize, 1);
  Printstring(_imp_str_literal(" + PERM"));
  Write(Permsize, 1);
  Printstring(_imp_str_literal(" + DIAGS"));
  Write(Da, 1);
  Printstring(_imp_str_literal(" ="));
  Write(Codesize + Glasize + Da, 1);
  Printstring(_imp_str_literal(" BYTES"));
  Newline();
  Newline();
  Printstring(_imp_str_literal("JUMPS:"));
  Write(Sj, 1);
  Printstring(_imp_str_literal(" SHORT,"));
  Write(Rx1, 1);
  Printstring(_imp_str_literal(" RX1,"));
  Write(Rx2, 1);
  Printstring(_imp_str_literal(" RX2,"));
  Write(Rx3, 1);
  Printstring(_imp_str_literal(" RX3"));
  Newline();
  Printstring(_imp_str_literal("...INCLUDING"));
  Write(Permcalls, 1);
  Printstring(_imp_str_literal(" PERMCALLS AND"));
  Write(Rtncalls, 1);
  Printstring(_imp_str_literal(" CALLS ON USER-DEFINED ROUTINES"));
  Newlines(2);
  exit(0);
  return (1);
}
