/* "@(#)ccccc.c	6.1	1/6/87" */
extern int externfunc();
int failcnt = 0;
int a = 13;
int array[3] = {27,28,29};
int *ip = &a;
struct structx {
    int s1,s2,s3;
} stru = {111,112,113};

struct structy {
    short s1,s2,s3;
};

struct structz {
    short zshort;
    long zlong;
    char zchar[7];
};

struct little_struct {
    char c1;
    char c2;
} global_little_struct;

struct toto {
    long l;
    short s;
} titi = {0,18};

main()
{
    int i;
    short s;
    char c;

    struct structy stru2;

    struct structx *st;
    struct structy *st2 = &stru2;

    stru2.s1 = 89;
    stru2.s2 = 90;
    stru2.s3 = 91;

    i = a;
    s = a;
    c = a;
    if (i!=13 || s!=13 || c!=13) fail(1);
    
    s = (short) a;
    c = (char) a;
    if (s!=13 || c!=13) fail(2);

    i = 1;
    s = array[i];
    c = array[i];
    if (s!=28 || c!=28) fail(3);

    s = (short) array[i];
    c = (char) array[i];
/*  if (s!=28 || c!=28) fail(4); */
    if (s!=28) failx("4a");
    if (c!=28) failx("4b");

    s = stru.s2;
    c = stru.s2;
    if (s!=112 || c!=112) fail(5);

    s = (short) stru.s2;
    c = (char) stru.s2;
/*  if (s!=112 || c!=112) fail(6); */
    if (s!=112) failx("6a");
    if (c!=112) failx("6b");

    st = &stru;
    i = st->s2;
    s = st->s2;
    c = st->s2;
    if (i!=112) failx("7a");
    if (s!=112) failx("7b");
    if (c!=112) failx("7c");
    if (st2->s2!=90) failx("7d");
    if (stru2.s2!=90) failx("7e");
    if (check1(stru2)) failx("7f");

    s = (short) st->s2;
    c = (char) st->s2;
    if (s!=112) failx("8a");
    if (c!=112) failx("8b");

    part2();
    part3();
    part4(13);
    part5();
    part6();
    part7();
    global_little_struct.c1 = 13;
    global_little_struct.c2 = 27;
    part8(global_little_struct);
    part9();
    part10();
    part11();
    part12();
    part13();
    part14();
    part15(13);
    part16();
    part17_a();
    part18();

    if (!failcnt) printf("pass\n");
}

part2()
{
    struct structz z, *zp;
    z.zshort = 99;
    z.zlong = 1999;
    strcpy(z.zchar, "frogs");
    if (z.zshort != 99 || z.zlong != 1999) fail(10);
    if (check2(z)) fail(11);
    zp = &z;
    zp->zlong = 13;
    zp->zshort = zp->zlong;
    if (z.zshort != 13 || z.zlong != 13) fail(12);
}

part3()
{
    struct {
	struct {
	    short a,b;
	}x;
	struct {
	    short a,b;
	}y;
    } s;

    s.x.a = 1;
    s.x.b = 2;
    s.y.a = 3;
    s.y.b = 4;
    if (identity(s.x.a) != 1)
	failx("part3 x.a");
    if (identity(s.x.b) != 2)
	failx("part3 x.b");
    if (identity(s.y.a) != 3)
	failx("part3 y.a");
    if (identity(s.y.b) != 4)
	failx("part3 y.b");
}

part4(n)
int n;
{
    char c = (char) n;
    short s = (short) n;
    if (c != 13) failx("part4 1");
    if (s != 13) failx("part4 2");
    c = n;
    s = n;
    if (c != 13) failx("part4 3");
    if (s != 13) failx("part4 4");
}

part5()
{
    char c;
    c = (char) *ip;
    if (c != a) failx("part5 1");
    c = *ip;
    if (c != a) failx("part5 2");
}

struct {
    char name[4];
} *part6_x = 0;

part6()
{

    if (!(part6_x->name == 0))
	failx("part6 1");
    if (!(!part6_x->name))
	failx("part6 2");
}

/* check unsigned short to signed long conversions.
 * the memory -> memory test fails on pre- v1.8a compilers.
 */
int sl;
unsigned short us = 0xffff;
part7()
{
    register int rsl;
    register unsigned short rus = 0xffff;

    rsl = rus;
    if (rsl != 0xffff)
	failx("part7 1");

    sl = us;
    if (sl != 0xffff)
	failx("part7 2");
}

part8(x)
struct little_struct x;
{
    struct little_struct y;

    if (x.c1 != global_little_struct.c1 || x.c2 != global_little_struct.c2)
	failx("part8 1");
    y = x;
    if (y.c1 != global_little_struct.c1 || y.c2 != global_little_struct.c2)
	failx("part8 2");
}

#define SNUM -32748	/* 32788 */
#define UNUM 32788

short part9_s = SNUM;
unsigned short part9_u = UNUM;
part9()
{
    register short s = SNUM;
    register unsigned short u = UNUM;
    unsigned short u1=699, u2=700;
    float f, f1 = -0.1;

    if (s == u)
	failx("part9 1");
    if (part9_s == part9_u)
	failx("part9 2");
    f = (u1 - u2) / 10.0;
    if (f != f1)
	failx("part9 3");
}

part10()
{
    int i = 97;
    char c;

    c = (char) i;
    if (c != 'a')
	failx("part10");
    part10_f(&i);
}

part10_f()
{
}
#undef SNUM
#undef UNUM

#define Ssize 3
typedef struct { int a,b } S;
S Sarray1[Ssize] = {3,6,9,13,15,18};
S Sarray2[Ssize];
part11()
{
    int Sn;
    int failed;

/*---------------------------------------------------------------------------*/
    S *Sp1 = &Sarray1[0];
    S *Sp2 = &Sarray2[0];
    for (Sn = 0; Sn < Ssize; Sn++)
	*Sp2++ = *Sp1++;
    failed = 0;
    for (Sn = 0; Sn < Ssize; Sn++)
	if ((Sarray1[Sn].a != Sarray2[Sn].a)||(Sarray1[Sn].b != Sarray2[Sn].b))
	    failed = 1;
    if (failed)
	failx("part11 1");

/*---------------------------------------------------------------------------*/

    Sp1 = &Sarray1[0];
    Sp2 = &Sarray2[0];
    Sp1--;
    Sp2--;
    for (Sn = 0; Sn < Ssize; Sn++)
	*(++Sp2) = *(++Sp1);
    failed = 0;
    for (Sn = 0; Sn < Ssize; Sn++)
	if ((Sarray1[Sn].a != Sarray2[Sn].a)||(Sarray1[Sn].b != Sarray2[Sn].b))
	    failed = 1;
    if (failed)
	failx("part11 2");

/*---------------------------------------------------------------------------*/

    Sp1 = &Sarray1[3];
    Sp2 = &Sarray2[3];
    for (Sn = 0; Sn < Ssize; Sn++)
	*Sp2-- = *Sp1--;
    failed = 0;
    for (Sn = 0; Sn < Ssize; Sn++)
	if ((Sarray1[Sn].a != Sarray2[Sn].a)||(Sarray1[Sn].b != Sarray2[Sn].b))
	    failed = 1;
    if (failed)
	failx("part11 3");
/*---------------------------------------------------------------------------*/

    Sp1 = &Sarray1[4];
    Sp2 = &Sarray2[4];
    for (Sn = 0; Sn < Ssize; Sn++)
	*(--Sp2) = *(--Sp1);
    failed = 0;
    for (Sn = 0; Sn < Ssize; Sn++)
	if ((Sarray1[Sn].a != Sarray2[Sn].a)||(Sarray1[Sn].b != Sarray2[Sn].b))
	    failed = 1;
    if (failed)
	failx("part11 4");

/*---------------------------------------------------------------------------*/
}

part12()
{
    int totalread = 1;
    int ijc = 1;
    
    if (!comparedoubles((float)(((float)totalread*8.0)/(float)ijc), 8.0))
	failx("part12");
}

part13()
{
    if ((int)&(((struct structz *)0)->zlong) != 4)
	failx("part13");
}

/* smr #1583 */
part14()
{
    if ((int)externfunc - (int)externfunc != 0)
	failx("part14");
}

part15(s)
short s;
{
    char c = s;
    if (c != s)
	failx("part15");
}

part16()
{
    char c;
    struct toto *p;
    p = &titi;
    c = p->s;
    if (c != 18)
	failx("part16");
}

struct outer {

    struct {
	int i1: 1;
	int i2: 15;
	int i3: 2;
	int i4: 1;
	int i5: 7;
	int i6: 6;
    } inner0;
} *outerx;

part17_c(n)
int n;
{
    if (n != 13)
	failx("part17");
}

dummy_fun()
{
}

part17_b()
{
    register int r0,r8,r9,r10,r11,r12,r13,one;
    struct outer *tmp;
    one = 1;
    r8 = r9 = r10 = r11 = r12 = r13 =13;
	
    tmp = outerx;
    for (r0=0; r0 < one; r0++) {
	part17_c(tmp->inner0.i5);
	tmp++;
    }
    dummy_fun(r0,r8,r9,r10,r11,r12,r13);
}

part17_a()
{
    struct outer x;
    x.inner0.i5 = 13;
    *outerx = x;
    part17_b();
}

part18()
{
    struct {
	int a:8,
	    b:16,
	    c:8;
    } *x,y;
    x = &y;
    y.b = 123;
    x->b += 3;
    x->b++;
    if (y.b != x->b || y.b != 127 || x->b != 127)
	failx("part18");
}


comparedoubles(d1, d2)
double d1,d2;
{
    return(d1 == d2);
}

identity(n)
{
    return(n);
}

fail(n)
int n;
{
    printf("fail %d\n", n);
    failcnt++;
}

failx(str)
char *str;
{
    printf("fail %s\n", str);
    failcnt++;
}

check1(s)
struct structy s;
{
    if (s.s2 == 90)
	return 0;
    else
	return 1;
}

check2(z)
struct structz z;
{
    if (z.zshort != 99 || z.zlong != 1999)
	return 1;
    else
	return 0;
}

externfunc(){}
