#include <perms.h>

                                                                //      1  %BEGIN
int main(int argc, char **argv) {
  _imp_initialise(argc, argv);
                                                                //      2  
                                                                //      3  
                                                                //      4  %BYTEINTEGERARRAY DEAL(1:52)
unsigned char DEAL[52];
                                                                //      5  %BYTEINTEGERARRAY HAND(0:3,2:14)
unsigned char HAND[4][13];
                                                                //      6  %OWNBYTEINTEGERARRAY S(0:3)='S','H','D','C'
static unsigned char S[4] = { 83, 72, 68, 67,  };
                                                                //      7  %INTEGER POINTS,BALANCE,LIMIT,CUT
int POINTS;
int BALANCE;
int LIMIT;
int CUT;
                                                                //      8  %INTEGERARRAY DIST,PTS(0:3)
int DIST[4];
int PTS[4];
                                                                //      9  %OWNINTEGER HANDCOUNT=0
static int HANDCOUNT = 0;
                                                                //     10  
                                                                //     11  %ROUTINE INITIALISE; ! INITIALISES PACK
void INITIALISE( void )
{
                                                                //     12     %INTEGER I,J,K
int I;
int J;
int K;
                                                                //     13     K=-1
K = (-1);
                                                                //     14     %CYCLE I=0,16,48; ! SUIT
I = (-16);
if ((((48)-(0)) % (16)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 0, 16, 48");
L_0002:;
if (I == 48) goto L_0003;
I += 16;
                                                                //     15         %CYCLE J=2,1,14; ! VALUE
J = 1;
if ((((14)-(2)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle J = 2, 1, 14");
L_0005:;
if (J == 14) goto L_0006;
J += 1;
                                                                //     16             DEAL(K+J)=I+J
DEAL[(((int)((((int)(K)) + (J)))) - (1))] = (((int)(I)) + (J));
                                                                //     17         %REPEAT; K=K+13; %REPEAT
goto L_0005;
L_0006:;
K = (((int)(K)) + (13));
goto L_0002;
L_0003:;
                                                                //     18     %END; ! OF INITIALISE
/* Remove %on %event handler here if present for this block */
return;
} // End of block INITIALISE at level 2
                                                                //     19  
                                                                //     20  %ROUTINE SHUFFLE; ! SHUFFLES AND CUTS PACK
void SHUFFLE( void )
{
                                                                //     21     %BYTEINTEGERARRAY A(1:52)
unsigned char A[52];
                                                                //     22     %INTEGER I,J
int I;
int J;
                                                                //     23     %CYCLE I=1,1,26
I = 0;
if ((((26)-(1)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 1, 1, 26");
L_0008:;
if (I == 26) goto L_0009;
I += 1;
                                                                //     24        A(2*I-1)=DEAL(I); A(2*I)=DEAL(53-I)
A[(((int)((((int)((((int)(2)) * (I)))) - (1)))) - (1))] = DEAL[(((int)(I)) - (1))];
A[(((int)((((int)(2)) * (I)))) - (1))] = DEAL[(((int)((((int)(53)) - (I)))) - (1))];
                                                                //     25        %REPEAT
goto L_0008;
L_0009:;
                                                                //     26     CUT=CUT+11
CUT = (((int)(CUT)) + (11));
                                                                //     27     %IF CUT>=52 %THEN CUT=CUT-52
if (((CUT) < (52))) goto L_000b;
CUT = (((int)(CUT)) - (52));
L_000b:;
                                                                //     28     %IF CUT=0 %THEN CUT=1
if (((CUT) != (0))) goto L_000c;
CUT = 1;
L_000c:;
                                                                //     29     %CYCLE I=1,1,CUT
{static int _initial, _increment, _final, _control;
_initial = 1; _increment = 1; _final = CUT; I = _control = _initial;
if (((_final-_initial) % _increment) != 0) _imp_signal(5,1,0,"Illegal cycle I = 1, 1, CUT");
I -= _increment; _control -= _increment;
L_000d:;
if (I == _final) goto L_000e;
I += _increment; _control += _increment;
if (I != _control) _imp_signal(4,2,0,"Corrupt control variable I"); /* FOR loop control variable corrupted */
}
                                                                //     30        DEAL(52-CUT+I)=A(I); %REPEAT
DEAL[(((int)((((int)((((int)(52)) - (CUT)))) + (I)))) - (1))] = A[(((int)(I)) - (1))];
goto L_000d;
L_000e:;
                                                                //     31     %CYCLE I=CUT+1,1,52
I = (((int)((((int)(CUT)) + (1)))) - (1));
if ((((52)-((((int)(CUT)) + (1)))) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = (((int)(CUT)) + (1)), 1, 52");
L_0010:;
if (I == 52) goto L_0011;
I += 1;
                                                                //     32        DEAL(I-CUT)=A(I); %REPEAT
DEAL[(((int)((((int)(I)) - (CUT)))) - (1))] = A[(((int)(I)) - (1))];
goto L_0010;
L_0011:;
                                                                //     33     %END; ! OF SHUFFLE
/* Remove %on %event handler here if present for this block */
return;
} // End of block SHUFFLE at level 2
                                                                //     34  
                                                                //     35  %ROUTINE DEALPACK
void DEALPACK( void )
{
                                                                //     36     %OWNBYTEINTEGERARRAY T(11:14)='J','Q','K','A'
static unsigned char T[4] = { 74, 81, 75, 65,  };
                                                                //     37     %INTEGER I,J,K,M
int I;
int J;
int K;
int M;
                                                                //     38     POINTS=0;BALANCE=0
POINTS = 0;
BALANCE = 0;
                                                                //     39     %IF HANDCOUNT&7=0 %THENSTART
if (((((HANDCOUNT) & (7))) != (0))) goto L_0013;
                                                                //     40        NEWPAGE; print string("BRIDGEHANDS")
_imp_NEWPAGE();
_imp_PRINTSTRING(_imp_str_literal("BRIDGEHANDS"));
                                                                //     41        NEWLINES(3); %FINISH
_imp_NEWLINES(3);
L_0013:;
                                                                //     42     %CYCLE I=0,1,3
I = (-1);
if ((((3)-(0)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 0, 1, 3");
L_0014:;
if (I == 3) goto L_0015;
I += 1;
                                                                //     43        %CYCLE J=2,1,14
J = 1;
if ((((14)-(2)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle J = 2, 1, 14");
L_0017:;
if (J == 14) goto L_0018;
J += 1;
                                                                //     44           HAND(I,J)=0; %REPEAT; %REPEAT
HAND[(((int)(I)) - (2))][J] = 0;
goto L_0017;
L_0018:;
goto L_0014;
L_0015:;
                                                                //     45     %CYCLE I=1,4,49
I = (-3);
if ((((49)-(1)) % (4)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 1, 4, 49");
L_001a:;
if (I == 49) goto L_001b;
I += 4;
                                                                //     46        HAND(DEAL(I)>>4,DEAL(I)&15)=1
HAND[(((int)((unsigned char)((((unsigned char)(DEAL[(((int)(I)) - (1))])) >> (4))))) - (2))][((DEAL[(((int)(I)) - (1))]) & (15))] = 1;
                                                                //     47        %REPEAT
goto L_001a;
L_001b:;
                                                                //     48     %CYCLE I=0,1,3
I = (-1);
if ((((3)-(0)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 0, 1, 3");
L_001d:;
if (I == 3) goto L_001e;
I += 1;
                                                                //     49        K=0; PRINTSYMBOL(S(I)); SPACES(3)
K = 0;
_imp_PRINTSYMBOL(S[I]);
_imp_SPACES(3);
                                                                //     50        M=0; ! COUNTS POINTS
M = 0;
                                                                //     51        %CYCLE J=14,-1,11
J = 15;
if ((((11)-(14)) % ((-1))) != 0) _imp_signal(5,1,0,"Illegal cycle J = 14, (-1), 11");
L_0020:;
if (J == 11) goto L_0021;
J += (-1);
                                                                //     52           ->L1 %IF HAND(I,J)=0
if (((HAND[(((int)(I)) - (2))][J]) != (0))) goto L_0023;
goto U_1000;
L_0023:;
                                                                //     53           SPACE;PRINTSYMBOL(T(J));K=K+1;M=M+J-10
_imp_SPACE();
_imp_PRINTSYMBOL((T-11)[J]);
K = (((int)(K)) + (1));
M = (((int)((((int)(M)) + (J)))) - (10));
                                                                //     54    L1:    %REPEAT
U_1000:;
goto L_0020;
L_0021:;
                                                                //     55        %IF HAND(I,10)#0 %THENSTART
if (((HAND[(((int)(I)) - (2))][10]) == (0))) goto L_0024;
                                                                //     56           WRITE(10,2); K=K+1; %FINISH
_imp_WRITE(10, 2);
K = (((int)(K)) + (1));
L_0024:;
                                                                //     57        %CYCLE J=9,-1,2
J = 10;
if ((((2)-(9)) % ((-1))) != 0) _imp_signal(5,1,0,"Illegal cycle J = 9, (-1), 2");
L_0025:;
if (J == 2) goto L_0026;
J += (-1);
                                                                //     58           ->L2 %IF HAND(I,J)=0
if (((HAND[(((int)(I)) - (2))][J]) != (0))) goto L_0028;
goto U_1001;
L_0028:;
                                                                //     59           K=K+1; WRITE(J,1)
K = (((int)(K)) + (1));
_imp_WRITE(J, 1);
                                                                //     60    L2:     %REPEAT
U_1001:;
goto L_0025;
L_0026:;
                                                                //     61        %IF K=0 %THEN print string(" --")
if (((K) != (0))) goto L_0029;
_imp_PRINTSTRING(_imp_str_literal(" --"));
L_0029:;
                                                                //     62        %IF 1<=M<=3 %AND K=1 %THEN M=M-1
if ((((1) > (M))) || (((M) > (3)))) goto L_002a;
if (((K) != (1))) goto L_002a;
M = (((int)(M)) - (1));
L_002a:;
                                                                //     63        PTS(I)=M; POINTS=POINTS+M; DIST(I)=K
PTS[I] = M;
POINTS = (((int)(POINTS)) + (M));
DIST[I] = K;
                                                                //     64        %IF K>5 %THEN BALANCE=BALANCE+K-5
if (((K) <= (5))) goto L_002b;
BALANCE = (((int)((((int)(BALANCE)) + (K)))) - (5));
L_002b:;
                                                                //     65                 %IF K<2 %THEN BALANCE=BALANCE+2{-???}
if (((K) >= (2))) goto L_002c;
BALANCE = (((int)(BALANCE)) + (2));
L_002c:;
                                                                //     66              NEWLINE; %REPEAT
_imp_NEWLINE();
goto L_001d;
L_001e:;
                                                                //     67           HANDCOUNT=HANDCOUNT+1
HANDCOUNT = (((int)(HANDCOUNT)) + (1));
                                                                //     68           %END; ! OF DEAL
/* Remove %on %event handler here if present for this block */
return;
} // End of block DEALPACK at level 2
                                                                //     69  
                                                                //     70        INITIALISE; READ(CUT); READ(LIMIT)
INITIALISE();
_imp_READ(&CUT);
_imp_READ(&LIMIT);
                                                                //     71        ->L2 %IF 0<=CUT<=52
if ((((0) > (CUT))) || (((CUT) > (52)))) goto L_002d;
goto U_1002;
L_002d:;
                                                                //     72        print string( "INVALID CUT"); %STOP
_imp_PRINTSTRING(_imp_str_literal("INVALID CUT"));
exit(0);
                                                                //     73  L2:   SHUFFLE; SHUFFLE; SHUFFLE; SHUFFLE
U_1002:;
SHUFFLE();
SHUFFLE();
SHUFFLE();
SHUFFLE();
                                                                //     74  L1:   SHUFFLE; DEALPACK
U_1003:;
SHUFFLE();
DEALPACK();
                                                                //     75        %BEGIN; ! BIDDING BLOCK
void _BLOCK_1_LEVEL_1_(void) {
                                                                //     76           %INTEGER LS,NO,SUITPTS
int LS;
int NO;
int SUITPTS;
                                                                //     77                    %SWITCH B(0:20)
static int sw1_B_idx;
static const void * /*SWITCH*/ sw1_B[21] = { &&sw1_B_0, &&sw1_B_1, &&sw1_B_2, &&sw1_B_3, &&sw1_B_4, &&sw1_B_5, &&sw1_B_6, &&sw1_B_7, &&sw1_B_8, &&sw1_B_9, &&sw1_B_10, &&sw1_B_11, &&sw1_B_12, &&sw1_B_13, &&sw1_B_14, &&sw1_B_15, &&sw1_B_16, &&sw1_B_17, &&sw1_B_18, &&sw1_B_19, &&sw1_B_20,  };
                                                                //     78           %INTEGER I,N
int I;
int N;
                                                                //     79           %ROUTINE BIDSUIT(%INTEGER I)
void BIDSUIT( int I )
{
                                                                //     80              WRITE(I,1); SPACE; PRINTSYMBOL(S(LS))
_imp_WRITE(I, 1);
_imp_SPACE();
_imp_PRINTSYMBOL(S[LS]);
                                                                //     81              %END
/* Remove %on %event handler here if present for this block */
return;
} // End of block BIDSUIT at level 3
                                                                //     82  
                                                                //     83           %ROUTINE NT(%INTEGER I)
void NT( int I )
{
                                                                //     84              WRITE(I,1); print string(" NT")
_imp_WRITE(I, 1);
_imp_PRINTSTRING(_imp_str_literal(" NT"));
                                                                //     85              %END
/* Remove %on %event handler here if present for this block */
return;
} // End of block NT at level 3
                                                                //     86  
                                                                //     87           NO=3
NO = 3;
                                                                //     88           %CYCLE I=0,1,3
I = (-1);
if ((((3)-(0)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I = 0, 1, 3");
L_002e:;
if (I == 3) goto L_002f;
I += 1;
                                                                //     89              %IF DIST(I)>NO %THENSTART
if (((DIST[I]) <= (NO))) goto L_0031;
                                                                //     90                 LS=I; NO=DIST(I)
LS = I;
NO = DIST[I];
                                                                //     91                 %FINISH; %REPEAT
L_0031:;
goto L_002e;
L_002f:;
                                                                //     92           %IF LS=0 %AND DIST(3)=NO %THEN LS=3
if (((LS) != (0))) goto L_0032;
if (((DIST[3]) != (NO))) goto L_0032;
LS = 3;
L_0032:;
                                                                //     93           SUITPTS=PTS(LS)+5*(NO-4); SPACES(18)
SUITPTS = ((PTS[LS]) + ((int)(((5) * ((int)((((int)(NO)) - (4))))))));
_imp_SPACES(18);
                                                                //     94           N=BALANCE; %IF N>3 %THEN BALANCE=3
N = BALANCE;
if (((N) <= (3))) goto L_0033;
BALANCE = 3;
L_0033:;
                                                                //     95           ->B(BALANCE)
sw1_B_idx = BALANCE; if ((0 <= sw1_B_idx) && (sw1_B_idx <= 20)) goto *sw1_B[sw1_B_idx]; else {
   /*_imp_signal(8, 2, sw1_B_idx);*/
   fprintf(stderr, "%%SWITCH index B(%d) not in range 0:20 at %s:%d\n",
           sw1_B_idx, (_imp_current_file != 0 ? _imp_current_file : __FILE__),
           (_imp_current_line != 0 ? _imp_current_line : __LINE__));
           exit(1);
}
                                                                //     96     B(0): ->L2 %IF POINTS>=12
sw1_B_0:;
if (((POINTS) < (12))) goto L_0034;
goto U_1004;
L_0034:;
                                                                //     97     NB:            print string(" NO BID"); ->L1
U_1005:;
_imp_PRINTSTRING(_imp_str_literal(" NO BID"));
goto U_1006;
                                                                //     98    L2:     %IF POINTS<=15 %THENSTART
U_1004:;
if (((POINTS) > (15))) goto L_0035;
                                                                //     99               ->L3 %IF SUITPTS>10
if (((SUITPTS) <= (10))) goto L_0036;
goto U_1007;
L_0036:;
                                                                //    100               NT(1); ->L1; %FINISH
NT(1);
goto U_1006;
L_0035:;
                                                                //    101            %IF POINTS<20 %THENSTART
if (((POINTS) >= (20))) goto L_0037;
                                                                //    102        L3:    BIDSUIT(1); ->L1; %FINISH
U_1007:;
BIDSUIT(1);
goto U_1006;
L_0037:;
                                                                //    103            %IF POINTS>=23 %THEN ->TC
if (((POINTS) < (23))) goto L_0038;
goto U_1008;
L_0038:;
                                                                //    104            %IF SUITPTS>=15 %THEN BIDSUIT(2) %ELSE NT(2)
if (((SUITPTS) < (15))) goto L_0039;
BIDSUIT(2);
goto L_003a;
L_0039:;
NT(2);
L_003a:;
                                                                //    105            ->L1
goto U_1006;
                                                                //    106     B(1):  %IF POINTS=11 %AND SUITPTS>10 %THEN ->L3
sw1_B_1:;
if (((POINTS) != (11))) goto L_003b;
if (((SUITPTS) <= (10))) goto L_003b;
goto U_1007;
L_003b:;
                                                                //    107            ->NB %IF POINTS<=11
if (((POINTS) > (11))) goto L_003c;
goto U_1005;
L_003c:;
                                                                //    108            ->L3 %IF POINTS<=18
if (((POINTS) > (18))) goto L_003d;
goto U_1007;
L_003d:;
                                                                //    109            ->L7 %IF POINTS<22
if (((POINTS) >= (22))) goto L_003e;
goto U_1009;
L_003e:;
                                                                //    110     TC:    print string(" 2 C(ACOL)"); ->L1
U_1008:;
_imp_PRINTSTRING(_imp_str_literal(" 2 C(ACOL)"));
goto U_1006;
                                                                //    111     B(2):  ->PR %IF POINTS<10
sw1_B_2:;
if (((POINTS) >= (10))) goto L_003f;
goto U_100a;
L_003f:;
                                                                //    112            ->L6 %IF POINTS>=12
if (((POINTS) < (12))) goto L_0040;
goto U_100b;
L_0040:;
                                                                //    113            ->L3 %IF SUITPTS>10; ->NB
if (((SUITPTS) <= (10))) goto L_0041;
goto U_1007;
L_0041:;
goto U_1005;
                                                                //    114     B(3):  ->PR %IF POINTS<8
sw1_B_3:;
if (((POINTS) >= (8))) goto L_0042;
goto U_100a;
L_0042:;
                                                                //    115    L6:     ->L3 %IF POINTS<=18-N
U_100b:;
if (((POINTS) > ((((int)(18)) - (N))))) goto L_0043;
goto U_1007;
L_0043:;
                                                                //    116            ->TC %IF POINTS>=22-N
if (((POINTS) < ((((int)(22)) - (N))))) goto L_0044;
goto U_1008;
L_0044:;
                                                                //    117    L7:     %IF SUITPTS>15 %THEN I=2 %ELSE I=1
U_1009:;
if (((SUITPTS) <= (15))) goto L_0045;
I = 2;
goto L_0046;
L_0045:;
I = 1;
L_0046:;
                                                                //    118            ->L8
goto U_100c;
                                                                //    119     PR:    SUITPTS=5*(NO-4)+POINTS
U_100a:;
SUITPTS = (((int)(((5) * ((int)((((int)(NO)) - (4))))))) + (POINTS));
                                                                //    120            ->NB %IF SUITPTS <=20; ->L9 %IF LS<2
if (((SUITPTS) > (20))) goto L_0047;
goto U_1005;
L_0047:;
if (((LS) >= (2))) goto L_0048;
goto U_100d;
L_0048:;
                                                                //    121    L9:     %IF SUITPTS<=27 %THEN I=3 %ELSE I=4
U_100d:;
if (((SUITPTS) > (27))) goto L_0049;
I = 3;
goto L_004a;
L_0049:;
I = 4;
L_004a:;
                                                                //    122            ->NB %IF SUITPTS <=22
if (((SUITPTS) > (22))) goto L_004b;
goto U_1005;
L_004b:;
                                                                //    123            %IF SUITPTS >30 %THENSTART
if (((SUITPTS) <= (30))) goto L_004c;
                                                                //    124               I=5; ->L8; %FINISH
I = 5;
goto U_100c;
L_004c:;
                                                                //    125    L8:     BIDSUIT(I)
U_100c:;
BIDSUIT(I);
                                                                //    126    L1:     %END; ! OF BIDDING BLOCK
U_1006:;
return;
sw1_B_4:;
sw1_B_5:;
sw1_B_6:;
sw1_B_7:;
sw1_B_8:;
sw1_B_9:;
sw1_B_10:;
sw1_B_11:;
sw1_B_12:;
sw1_B_13:;
sw1_B_14:;
sw1_B_15:;
sw1_B_16:;
sw1_B_17:;
sw1_B_18:;
sw1_B_19:;
sw1_B_20:;
/*_imp_signal(6,3,sw1_B_idx,"SWITCH LABEL NOT SET - sw1_B");*/
fprintf(stderr, "%%SWITCH LABEL NOT SET - sw1_B(%d): at line %s:%d", sw1_B_idx, (_imp_current_file != 0 ? _imp_current_file : __FILE__), (_imp_current_line != 0 ? _imp_current_line : __LINE__));
exit(1);
} // End of block _BLOCK_1_LEVEL_1_ at level 2
_BLOCK_1_LEVEL_1_();
                                                                //    127  
                                                                //    128                   NEWLINES(3)
_imp_NEWLINES(3);
                                                                //    129         ->L1 %IF HANDCOUNT<LIMIT
if (((HANDCOUNT) >= (LIMIT))) goto L_004d;
goto U_1003;
L_004d:;
                                                                //    130         %ENDOFPROGRAM
/* Remove %on %event handler here if present for this block */
return 0;
} // End of block _imp_main at level 1
// End of file
