1/* Duff's device is legal C; test to make sure the compiler 2 doesn't complain about it. 3 4 Jason Thorpe <thorpej@wasabisystems.com> 5 Derived from the BSD Telnet Kerberos 4 checksum routine. 6 See also PR 5230. */ 7 8/* { dg-do run } */ 9/* { dg-options "-O2" } */ 10 11extern void abort (void); 12extern void exit (int); 13 14#if __INT_MAX__ >= 2147483647 15/* At least 32-bit integers. */ 16typedef int type32; 17#else 18typedef long type32; 19#endif 20 21type32 22cksum (const unsigned char *src, unsigned long size) 23{ 24 type32 ck = 0; 25 26 switch (size & 3) 27 { 28 while (size > 0) 29 { 30 case 0: 31 ck ^= (type32)*src++ << 24; 32 --size; 33 case 3: 34 ck ^= (type32)*src++ << 16; 35 --size; 36 case 2: 37 ck ^= (type32)*src++ << 8; 38 --size; 39 case 1: 40 ck ^= (type32)*src++; 41 --size; 42 } 43 } 44 45 return ck; 46} 47 48const char testpat[] = "The quick brown fox jumped over the lazy dog."; 49 50int 51main() 52{ 53 type32 ck; 54 55 ck = cksum ((const unsigned char *) testpat, sizeof (testpat)); 56 if (ck != 925902908) 57 abort (); 58 59 exit (0); 60} 61