require '_h2ph_pre.ph';

unless(defined(&_SYS_ENDIAN_H_)) {
    eval 'sub _SYS_ENDIAN_H_ () {1;}' unless defined(&_SYS_ENDIAN_H_);
    unless(defined(&_POSIX_SOURCE)) {
	require 'sys/cdefs.ph';
	eval 'sub LITTLE_ENDIAN () {1234;}' unless defined(&LITTLE_ENDIAN);
	eval 'sub BIG_ENDIAN () {4321;}' unless defined(&BIG_ENDIAN);
	eval 'sub PDP_ENDIAN () {3412;}' unless defined(&PDP_ENDIAN);
	if(defined(&__GNUC__)) {
	    eval 'sub __swap16gen {
	        local($x) = @_;
    		eval q(({  &u_int16_t  &__swap16gen_x = ; (( &__swap16gen_x & 0xff) << 8| ( &__swap16gen_x & 0xff00) >> 8); }));
	    }' unless defined(&__swap16gen);
	    eval 'sub __swap32gen {
	        local($x) = @_;
    		eval q(({  &u_int32_t  &__swap32gen_x = ; (( &__swap32gen_x & 0xff) << 24| ( &__swap32gen_x & 0xff00) << 8| ( &__swap32gen_x & 0xff0000) >> 8| ( &__swap32gen_x & 0xff000000) >> 24); }));
	    }' unless defined(&__swap32gen);
	} else {
	    eval 'sub __swap16gen {
	        local($x) = @_;
    		eval q((( & 0xff) << 8| (($x) & 0xff00) >> 8));
	    }' unless defined(&__swap16gen);
	    eval 'sub __swap32gen {
	        local($x) = @_;
    		eval q((( & 0xff) << 24| ( & 0xff00) << 8| ( & 0xff0000) >> 8| (($x) & 0xff000000) >> 24));
	    }' unless defined(&__swap32gen);
	}
	if(defined(&MD_SWAP)) {
	    if((defined(&__GNUC__) ? &__GNUC__ : 0)) {
		eval 'sub swap16 {
		    local($x) = @_;
    		    eval q(({  &u_int16_t  &__swap16_x = ($x);  &__builtin_constant_p($x) ?  &__swap16gen( &__swap16_x) :  &__swap16md( &__swap16_x); }));
		}' unless defined(&swap16);
		eval 'sub swap32 {
		    local($x) = @_;
    		    eval q(({  &u_int32_t  &__swap32_x = ($x);  &__builtin_constant_p($x) ?  &__swap32gen( &__swap32_x) :  &__swap32md( &__swap32_x); }));
		}' unless defined(&swap32);
	    }
	} else {
	    eval 'sub swap16 () { &__swap16gen;}' unless defined(&swap16);
	    eval 'sub swap32 () { &__swap32gen;}' unless defined(&swap32);
	}
	eval 'sub swap16_multi {
	    local($v, $n) = @_;
    	    eval q( &do {  &size_t  &__swap16_multi_n = ($n);  &u_int16_t * &__swap16_multi_v = ($v);  &while ( &__swap16_multi_n) { * &__swap16_multi_v =  &swap16(* &__swap16_multi_v);  &__swap16_multi_v++;  &__swap16_multi_n--; } }  &while (0));
	}' unless defined(&swap16_multi);
	if((defined(&BYTE_ORDER) ? &BYTE_ORDER : 0) == (defined(&LITTLE_ENDIAN) ? &LITTLE_ENDIAN : 0)) {
	    unless(defined(&_QUAD_HIGHWORD)) {
		eval 'sub _QUAD_HIGHWORD () {1;}' unless defined(&_QUAD_HIGHWORD);
	    }
	    unless(defined(&_QUAD_LOWWORD)) {
		eval 'sub _QUAD_LOWWORD () {0;}' unless defined(&_QUAD_LOWWORD);
	    }
	    eval 'sub htobe16 () { &swap16;}' unless defined(&htobe16);
	    eval 'sub htobe32 () { &swap32;}' unless defined(&htobe32);
	    eval 'sub betoh16 () { &swap16;}' unless defined(&betoh16);
	    eval 'sub betoh32 () { &swap32;}' unless defined(&betoh32);
	    eval 'sub htole16 {
	        local($x) = @_;
    		eval q(($x));
	    }' unless defined(&htole16);
	    eval 'sub htole32 {
	        local($x) = @_;
    		eval q(($x));
	    }' unless defined(&htole32);
	    eval 'sub letoh16 {
	        local($x) = @_;
    		eval q(($x));
	    }' unless defined(&letoh16);
	    eval 'sub letoh32 {
	        local($x) = @_;
    		eval q(($x));
	    }' unless defined(&letoh32);
	}
	if((defined(&BYTE_ORDER) ? &BYTE_ORDER : 0) == (defined(&BIG_ENDIAN) ? &BIG_ENDIAN : 0)) {
	    unless(defined(&_QUAD_HIGHWORD)) {
		eval 'sub _QUAD_HIGHWORD () {0;}' unless defined(&_QUAD_HIGHWORD);
	    }
	    unless(defined(&_QUAD_LOWWORD)) {
		eval 'sub _QUAD_LOWWORD () {1;}' unless defined(&_QUAD_LOWWORD);
	    }
	    eval 'sub htole16 () { &swap16;}' unless defined(&htole16);
	    eval 'sub htole32 () { &swap32;}' unless defined(&htole32);
	    eval 'sub letoh16 () { &swap16;}' unless defined(&letoh16);
	    eval 'sub letoh32 () { &swap32;}' unless defined(&letoh32);
	    eval 'sub htobe16 {
	        local($x) = @_;
    		eval q(($x));
	    }' unless defined(&htobe16);
	    eval 'sub htobe32 {
	        local($x) = @_;
    		eval q(($x));
	    }' unless defined(&htobe32);
	    eval 'sub betoh16 {
	        local($x) = @_;
    		eval q(($x));
	    }' unless defined(&betoh16);
	    eval 'sub betoh32 {
	        local($x) = @_;
    		eval q(($x));
	    }' unless defined(&betoh32);
	}
	eval 'sub htons () { &htobe16;}' unless defined(&htons);
	eval 'sub htonl () { &htobe32;}' unless defined(&htonl);
	eval 'sub ntohs () { &betoh16;}' unless defined(&ntohs);
	eval 'sub ntohl () { &betoh32;}' unless defined(&ntohl);
	eval 'sub NTOHL {
	    local($x) = @_;
    	    eval q( =  &ntohl(($x)));
	}' unless defined(&NTOHL);
	eval 'sub NTOHS {
	    local($x) = @_;
    	    eval q( =  &ntohs(($x)));
	}' unless defined(&NTOHS);
	eval 'sub HTONL {
	    local($x) = @_;
    	    eval q( =  &htonl(($x)));
	}' unless defined(&HTONL);
	eval 'sub HTONS {
	    local($x) = @_;
    	    eval q( =  &htons(($x)));
	}' unless defined(&HTONS);
    }
}
1;
