file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/976469.c
|
#include <unistd.h>
void mx_printchar(char c) {
write(1, &c, 1);
}
/*int main (void) {
mx_printchar('v');
mx_printchar('\n');
}*/
|
the_stack_data/62171.c
|
//@ ltl invariant negative: (<> (AP(x_5 - x_12 >= -15) && ([] AP(x_21 - x_5 >= 6))));
float x_0;
float x_1;
float x_2;
float x_3;
float x_4;
float x_5;
float x_6;
float x_7;
float x_8;
float x_9;
float x_10;
float x_11;
float x_12;
float x_13;
float x_14;
float x_15;
float x_16;
float x_17;
float x_18;
float x_19;
float x_20;
float x_21;
float x_22;
float x_23;
int main()
{
float x_0_;
float x_1_;
float x_2_;
float x_3_;
float x_4_;
float x_5_;
float x_6_;
float x_7_;
float x_8_;
float x_9_;
float x_10_;
float x_11_;
float x_12_;
float x_13_;
float x_14_;
float x_15_;
float x_16_;
float x_17_;
float x_18_;
float x_19_;
float x_20_;
float x_21_;
float x_22_;
float x_23_;
while(1) {
x_0_ = ((((18.0 + x_1) > ((12.0 + x_3) > (2.0 + x_5)? (12.0 + x_3) : (2.0 + x_5))? (18.0 + x_1) : ((12.0 + x_3) > (2.0 + x_5)? (12.0 + x_3) : (2.0 + x_5))) > ((14.0 + x_7) > ((17.0 + x_10) > (11.0 + x_12)? (17.0 + x_10) : (11.0 + x_12))? (14.0 + x_7) : ((17.0 + x_10) > (11.0 + x_12)? (17.0 + x_10) : (11.0 + x_12)))? ((18.0 + x_1) > ((12.0 + x_3) > (2.0 + x_5)? (12.0 + x_3) : (2.0 + x_5))? (18.0 + x_1) : ((12.0 + x_3) > (2.0 + x_5)? (12.0 + x_3) : (2.0 + x_5))) : ((14.0 + x_7) > ((17.0 + x_10) > (11.0 + x_12)? (17.0 + x_10) : (11.0 + x_12))? (14.0 + x_7) : ((17.0 + x_10) > (11.0 + x_12)? (17.0 + x_10) : (11.0 + x_12)))) > (((16.0 + x_14) > ((13.0 + x_16) > (19.0 + x_17)? (13.0 + x_16) : (19.0 + x_17))? (16.0 + x_14) : ((13.0 + x_16) > (19.0 + x_17)? (13.0 + x_16) : (19.0 + x_17))) > ((2.0 + x_18) > ((9.0 + x_20) > (19.0 + x_22)? (9.0 + x_20) : (19.0 + x_22))? (2.0 + x_18) : ((9.0 + x_20) > (19.0 + x_22)? (9.0 + x_20) : (19.0 + x_22)))? ((16.0 + x_14) > ((13.0 + x_16) > (19.0 + x_17)? (13.0 + x_16) : (19.0 + x_17))? (16.0 + x_14) : ((13.0 + x_16) > (19.0 + x_17)? (13.0 + x_16) : (19.0 + x_17))) : ((2.0 + x_18) > ((9.0 + x_20) > (19.0 + x_22)? (9.0 + x_20) : (19.0 + x_22))? (2.0 + x_18) : ((9.0 + x_20) > (19.0 + x_22)? (9.0 + x_20) : (19.0 + x_22))))? (((18.0 + x_1) > ((12.0 + x_3) > (2.0 + x_5)? (12.0 + x_3) : (2.0 + x_5))? (18.0 + x_1) : ((12.0 + x_3) > (2.0 + x_5)? (12.0 + x_3) : (2.0 + x_5))) > ((14.0 + x_7) > ((17.0 + x_10) > (11.0 + x_12)? (17.0 + x_10) : (11.0 + x_12))? (14.0 + x_7) : ((17.0 + x_10) > (11.0 + x_12)? (17.0 + x_10) : (11.0 + x_12)))? ((18.0 + x_1) > ((12.0 + x_3) > (2.0 + x_5)? (12.0 + x_3) : (2.0 + x_5))? (18.0 + x_1) : ((12.0 + x_3) > (2.0 + x_5)? (12.0 + x_3) : (2.0 + x_5))) : ((14.0 + x_7) > ((17.0 + x_10) > (11.0 + x_12)? (17.0 + x_10) : (11.0 + x_12))? (14.0 + x_7) : ((17.0 + x_10) > (11.0 + x_12)? (17.0 + x_10) : (11.0 + x_12)))) : (((16.0 + x_14) > ((13.0 + x_16) > (19.0 + x_17)? (13.0 + x_16) : (19.0 + x_17))? (16.0 + x_14) : ((13.0 + x_16) > (19.0 + x_17)? (13.0 + x_16) : (19.0 + x_17))) > ((2.0 + x_18) > ((9.0 + x_20) > (19.0 + x_22)? (9.0 + x_20) : (19.0 + x_22))? (2.0 + x_18) : ((9.0 + x_20) > (19.0 + x_22)? (9.0 + x_20) : (19.0 + x_22)))? ((16.0 + x_14) > ((13.0 + x_16) > (19.0 + x_17)? (13.0 + x_16) : (19.0 + x_17))? (16.0 + x_14) : ((13.0 + x_16) > (19.0 + x_17)? (13.0 + x_16) : (19.0 + x_17))) : ((2.0 + x_18) > ((9.0 + x_20) > (19.0 + x_22)? (9.0 + x_20) : (19.0 + x_22))? (2.0 + x_18) : ((9.0 + x_20) > (19.0 + x_22)? (9.0 + x_20) : (19.0 + x_22)))));
x_1_ = ((((5.0 + x_0) > ((5.0 + x_2) > (15.0 + x_4)? (5.0 + x_2) : (15.0 + x_4))? (5.0 + x_0) : ((5.0 + x_2) > (15.0 + x_4)? (5.0 + x_2) : (15.0 + x_4))) > ((16.0 + x_5) > ((4.0 + x_6) > (2.0 + x_10)? (4.0 + x_6) : (2.0 + x_10))? (16.0 + x_5) : ((4.0 + x_6) > (2.0 + x_10)? (4.0 + x_6) : (2.0 + x_10)))? ((5.0 + x_0) > ((5.0 + x_2) > (15.0 + x_4)? (5.0 + x_2) : (15.0 + x_4))? (5.0 + x_0) : ((5.0 + x_2) > (15.0 + x_4)? (5.0 + x_2) : (15.0 + x_4))) : ((16.0 + x_5) > ((4.0 + x_6) > (2.0 + x_10)? (4.0 + x_6) : (2.0 + x_10))? (16.0 + x_5) : ((4.0 + x_6) > (2.0 + x_10)? (4.0 + x_6) : (2.0 + x_10)))) > (((13.0 + x_11) > ((8.0 + x_12) > (4.0 + x_14)? (8.0 + x_12) : (4.0 + x_14))? (13.0 + x_11) : ((8.0 + x_12) > (4.0 + x_14)? (8.0 + x_12) : (4.0 + x_14))) > ((17.0 + x_15) > ((17.0 + x_18) > (8.0 + x_20)? (17.0 + x_18) : (8.0 + x_20))? (17.0 + x_15) : ((17.0 + x_18) > (8.0 + x_20)? (17.0 + x_18) : (8.0 + x_20)))? ((13.0 + x_11) > ((8.0 + x_12) > (4.0 + x_14)? (8.0 + x_12) : (4.0 + x_14))? (13.0 + x_11) : ((8.0 + x_12) > (4.0 + x_14)? (8.0 + x_12) : (4.0 + x_14))) : ((17.0 + x_15) > ((17.0 + x_18) > (8.0 + x_20)? (17.0 + x_18) : (8.0 + x_20))? (17.0 + x_15) : ((17.0 + x_18) > (8.0 + x_20)? (17.0 + x_18) : (8.0 + x_20))))? (((5.0 + x_0) > ((5.0 + x_2) > (15.0 + x_4)? (5.0 + x_2) : (15.0 + x_4))? (5.0 + x_0) : ((5.0 + x_2) > (15.0 + x_4)? (5.0 + x_2) : (15.0 + x_4))) > ((16.0 + x_5) > ((4.0 + x_6) > (2.0 + x_10)? (4.0 + x_6) : (2.0 + x_10))? (16.0 + x_5) : ((4.0 + x_6) > (2.0 + x_10)? (4.0 + x_6) : (2.0 + x_10)))? ((5.0 + x_0) > ((5.0 + x_2) > (15.0 + x_4)? (5.0 + x_2) : (15.0 + x_4))? (5.0 + x_0) : ((5.0 + x_2) > (15.0 + x_4)? (5.0 + x_2) : (15.0 + x_4))) : ((16.0 + x_5) > ((4.0 + x_6) > (2.0 + x_10)? (4.0 + x_6) : (2.0 + x_10))? (16.0 + x_5) : ((4.0 + x_6) > (2.0 + x_10)? (4.0 + x_6) : (2.0 + x_10)))) : (((13.0 + x_11) > ((8.0 + x_12) > (4.0 + x_14)? (8.0 + x_12) : (4.0 + x_14))? (13.0 + x_11) : ((8.0 + x_12) > (4.0 + x_14)? (8.0 + x_12) : (4.0 + x_14))) > ((17.0 + x_15) > ((17.0 + x_18) > (8.0 + x_20)? (17.0 + x_18) : (8.0 + x_20))? (17.0 + x_15) : ((17.0 + x_18) > (8.0 + x_20)? (17.0 + x_18) : (8.0 + x_20)))? ((13.0 + x_11) > ((8.0 + x_12) > (4.0 + x_14)? (8.0 + x_12) : (4.0 + x_14))? (13.0 + x_11) : ((8.0 + x_12) > (4.0 + x_14)? (8.0 + x_12) : (4.0 + x_14))) : ((17.0 + x_15) > ((17.0 + x_18) > (8.0 + x_20)? (17.0 + x_18) : (8.0 + x_20))? (17.0 + x_15) : ((17.0 + x_18) > (8.0 + x_20)? (17.0 + x_18) : (8.0 + x_20)))));
x_2_ = ((((13.0 + x_3) > ((13.0 + x_5) > (16.0 + x_6)? (13.0 + x_5) : (16.0 + x_6))? (13.0 + x_3) : ((13.0 + x_5) > (16.0 + x_6)? (13.0 + x_5) : (16.0 + x_6))) > ((16.0 + x_7) > ((7.0 + x_11) > (5.0 + x_13)? (7.0 + x_11) : (5.0 + x_13))? (16.0 + x_7) : ((7.0 + x_11) > (5.0 + x_13)? (7.0 + x_11) : (5.0 + x_13)))? ((13.0 + x_3) > ((13.0 + x_5) > (16.0 + x_6)? (13.0 + x_5) : (16.0 + x_6))? (13.0 + x_3) : ((13.0 + x_5) > (16.0 + x_6)? (13.0 + x_5) : (16.0 + x_6))) : ((16.0 + x_7) > ((7.0 + x_11) > (5.0 + x_13)? (7.0 + x_11) : (5.0 + x_13))? (16.0 + x_7) : ((7.0 + x_11) > (5.0 + x_13)? (7.0 + x_11) : (5.0 + x_13)))) > (((11.0 + x_14) > ((6.0 + x_17) > (1.0 + x_18)? (6.0 + x_17) : (1.0 + x_18))? (11.0 + x_14) : ((6.0 + x_17) > (1.0 + x_18)? (6.0 + x_17) : (1.0 + x_18))) > ((1.0 + x_19) > ((3.0 + x_20) > (17.0 + x_22)? (3.0 + x_20) : (17.0 + x_22))? (1.0 + x_19) : ((3.0 + x_20) > (17.0 + x_22)? (3.0 + x_20) : (17.0 + x_22)))? ((11.0 + x_14) > ((6.0 + x_17) > (1.0 + x_18)? (6.0 + x_17) : (1.0 + x_18))? (11.0 + x_14) : ((6.0 + x_17) > (1.0 + x_18)? (6.0 + x_17) : (1.0 + x_18))) : ((1.0 + x_19) > ((3.0 + x_20) > (17.0 + x_22)? (3.0 + x_20) : (17.0 + x_22))? (1.0 + x_19) : ((3.0 + x_20) > (17.0 + x_22)? (3.0 + x_20) : (17.0 + x_22))))? (((13.0 + x_3) > ((13.0 + x_5) > (16.0 + x_6)? (13.0 + x_5) : (16.0 + x_6))? (13.0 + x_3) : ((13.0 + x_5) > (16.0 + x_6)? (13.0 + x_5) : (16.0 + x_6))) > ((16.0 + x_7) > ((7.0 + x_11) > (5.0 + x_13)? (7.0 + x_11) : (5.0 + x_13))? (16.0 + x_7) : ((7.0 + x_11) > (5.0 + x_13)? (7.0 + x_11) : (5.0 + x_13)))? ((13.0 + x_3) > ((13.0 + x_5) > (16.0 + x_6)? (13.0 + x_5) : (16.0 + x_6))? (13.0 + x_3) : ((13.0 + x_5) > (16.0 + x_6)? (13.0 + x_5) : (16.0 + x_6))) : ((16.0 + x_7) > ((7.0 + x_11) > (5.0 + x_13)? (7.0 + x_11) : (5.0 + x_13))? (16.0 + x_7) : ((7.0 + x_11) > (5.0 + x_13)? (7.0 + x_11) : (5.0 + x_13)))) : (((11.0 + x_14) > ((6.0 + x_17) > (1.0 + x_18)? (6.0 + x_17) : (1.0 + x_18))? (11.0 + x_14) : ((6.0 + x_17) > (1.0 + x_18)? (6.0 + x_17) : (1.0 + x_18))) > ((1.0 + x_19) > ((3.0 + x_20) > (17.0 + x_22)? (3.0 + x_20) : (17.0 + x_22))? (1.0 + x_19) : ((3.0 + x_20) > (17.0 + x_22)? (3.0 + x_20) : (17.0 + x_22)))? ((11.0 + x_14) > ((6.0 + x_17) > (1.0 + x_18)? (6.0 + x_17) : (1.0 + x_18))? (11.0 + x_14) : ((6.0 + x_17) > (1.0 + x_18)? (6.0 + x_17) : (1.0 + x_18))) : ((1.0 + x_19) > ((3.0 + x_20) > (17.0 + x_22)? (3.0 + x_20) : (17.0 + x_22))? (1.0 + x_19) : ((3.0 + x_20) > (17.0 + x_22)? (3.0 + x_20) : (17.0 + x_22)))));
x_3_ = ((((4.0 + x_1) > ((12.0 + x_4) > (2.0 + x_5)? (12.0 + x_4) : (2.0 + x_5))? (4.0 + x_1) : ((12.0 + x_4) > (2.0 + x_5)? (12.0 + x_4) : (2.0 + x_5))) > ((19.0 + x_7) > ((15.0 + x_10) > (2.0 + x_11)? (15.0 + x_10) : (2.0 + x_11))? (19.0 + x_7) : ((15.0 + x_10) > (2.0 + x_11)? (15.0 + x_10) : (2.0 + x_11)))? ((4.0 + x_1) > ((12.0 + x_4) > (2.0 + x_5)? (12.0 + x_4) : (2.0 + x_5))? (4.0 + x_1) : ((12.0 + x_4) > (2.0 + x_5)? (12.0 + x_4) : (2.0 + x_5))) : ((19.0 + x_7) > ((15.0 + x_10) > (2.0 + x_11)? (15.0 + x_10) : (2.0 + x_11))? (19.0 + x_7) : ((15.0 + x_10) > (2.0 + x_11)? (15.0 + x_10) : (2.0 + x_11)))) > (((14.0 + x_16) > ((17.0 + x_17) > (11.0 + x_18)? (17.0 + x_17) : (11.0 + x_18))? (14.0 + x_16) : ((17.0 + x_17) > (11.0 + x_18)? (17.0 + x_17) : (11.0 + x_18))) > ((11.0 + x_19) > ((11.0 + x_20) > (16.0 + x_21)? (11.0 + x_20) : (16.0 + x_21))? (11.0 + x_19) : ((11.0 + x_20) > (16.0 + x_21)? (11.0 + x_20) : (16.0 + x_21)))? ((14.0 + x_16) > ((17.0 + x_17) > (11.0 + x_18)? (17.0 + x_17) : (11.0 + x_18))? (14.0 + x_16) : ((17.0 + x_17) > (11.0 + x_18)? (17.0 + x_17) : (11.0 + x_18))) : ((11.0 + x_19) > ((11.0 + x_20) > (16.0 + x_21)? (11.0 + x_20) : (16.0 + x_21))? (11.0 + x_19) : ((11.0 + x_20) > (16.0 + x_21)? (11.0 + x_20) : (16.0 + x_21))))? (((4.0 + x_1) > ((12.0 + x_4) > (2.0 + x_5)? (12.0 + x_4) : (2.0 + x_5))? (4.0 + x_1) : ((12.0 + x_4) > (2.0 + x_5)? (12.0 + x_4) : (2.0 + x_5))) > ((19.0 + x_7) > ((15.0 + x_10) > (2.0 + x_11)? (15.0 + x_10) : (2.0 + x_11))? (19.0 + x_7) : ((15.0 + x_10) > (2.0 + x_11)? (15.0 + x_10) : (2.0 + x_11)))? ((4.0 + x_1) > ((12.0 + x_4) > (2.0 + x_5)? (12.0 + x_4) : (2.0 + x_5))? (4.0 + x_1) : ((12.0 + x_4) > (2.0 + x_5)? (12.0 + x_4) : (2.0 + x_5))) : ((19.0 + x_7) > ((15.0 + x_10) > (2.0 + x_11)? (15.0 + x_10) : (2.0 + x_11))? (19.0 + x_7) : ((15.0 + x_10) > (2.0 + x_11)? (15.0 + x_10) : (2.0 + x_11)))) : (((14.0 + x_16) > ((17.0 + x_17) > (11.0 + x_18)? (17.0 + x_17) : (11.0 + x_18))? (14.0 + x_16) : ((17.0 + x_17) > (11.0 + x_18)? (17.0 + x_17) : (11.0 + x_18))) > ((11.0 + x_19) > ((11.0 + x_20) > (16.0 + x_21)? (11.0 + x_20) : (16.0 + x_21))? (11.0 + x_19) : ((11.0 + x_20) > (16.0 + x_21)? (11.0 + x_20) : (16.0 + x_21)))? ((14.0 + x_16) > ((17.0 + x_17) > (11.0 + x_18)? (17.0 + x_17) : (11.0 + x_18))? (14.0 + x_16) : ((17.0 + x_17) > (11.0 + x_18)? (17.0 + x_17) : (11.0 + x_18))) : ((11.0 + x_19) > ((11.0 + x_20) > (16.0 + x_21)? (11.0 + x_20) : (16.0 + x_21))? (11.0 + x_19) : ((11.0 + x_20) > (16.0 + x_21)? (11.0 + x_20) : (16.0 + x_21)))));
x_4_ = ((((18.0 + x_0) > ((3.0 + x_4) > (11.0 + x_5)? (3.0 + x_4) : (11.0 + x_5))? (18.0 + x_0) : ((3.0 + x_4) > (11.0 + x_5)? (3.0 + x_4) : (11.0 + x_5))) > ((20.0 + x_9) > ((1.0 + x_11) > (19.0 + x_14)? (1.0 + x_11) : (19.0 + x_14))? (20.0 + x_9) : ((1.0 + x_11) > (19.0 + x_14)? (1.0 + x_11) : (19.0 + x_14)))? ((18.0 + x_0) > ((3.0 + x_4) > (11.0 + x_5)? (3.0 + x_4) : (11.0 + x_5))? (18.0 + x_0) : ((3.0 + x_4) > (11.0 + x_5)? (3.0 + x_4) : (11.0 + x_5))) : ((20.0 + x_9) > ((1.0 + x_11) > (19.0 + x_14)? (1.0 + x_11) : (19.0 + x_14))? (20.0 + x_9) : ((1.0 + x_11) > (19.0 + x_14)? (1.0 + x_11) : (19.0 + x_14)))) > (((10.0 + x_16) > ((3.0 + x_17) > (19.0 + x_18)? (3.0 + x_17) : (19.0 + x_18))? (10.0 + x_16) : ((3.0 + x_17) > (19.0 + x_18)? (3.0 + x_17) : (19.0 + x_18))) > ((2.0 + x_19) > ((9.0 + x_20) > (19.0 + x_21)? (9.0 + x_20) : (19.0 + x_21))? (2.0 + x_19) : ((9.0 + x_20) > (19.0 + x_21)? (9.0 + x_20) : (19.0 + x_21)))? ((10.0 + x_16) > ((3.0 + x_17) > (19.0 + x_18)? (3.0 + x_17) : (19.0 + x_18))? (10.0 + x_16) : ((3.0 + x_17) > (19.0 + x_18)? (3.0 + x_17) : (19.0 + x_18))) : ((2.0 + x_19) > ((9.0 + x_20) > (19.0 + x_21)? (9.0 + x_20) : (19.0 + x_21))? (2.0 + x_19) : ((9.0 + x_20) > (19.0 + x_21)? (9.0 + x_20) : (19.0 + x_21))))? (((18.0 + x_0) > ((3.0 + x_4) > (11.0 + x_5)? (3.0 + x_4) : (11.0 + x_5))? (18.0 + x_0) : ((3.0 + x_4) > (11.0 + x_5)? (3.0 + x_4) : (11.0 + x_5))) > ((20.0 + x_9) > ((1.0 + x_11) > (19.0 + x_14)? (1.0 + x_11) : (19.0 + x_14))? (20.0 + x_9) : ((1.0 + x_11) > (19.0 + x_14)? (1.0 + x_11) : (19.0 + x_14)))? ((18.0 + x_0) > ((3.0 + x_4) > (11.0 + x_5)? (3.0 + x_4) : (11.0 + x_5))? (18.0 + x_0) : ((3.0 + x_4) > (11.0 + x_5)? (3.0 + x_4) : (11.0 + x_5))) : ((20.0 + x_9) > ((1.0 + x_11) > (19.0 + x_14)? (1.0 + x_11) : (19.0 + x_14))? (20.0 + x_9) : ((1.0 + x_11) > (19.0 + x_14)? (1.0 + x_11) : (19.0 + x_14)))) : (((10.0 + x_16) > ((3.0 + x_17) > (19.0 + x_18)? (3.0 + x_17) : (19.0 + x_18))? (10.0 + x_16) : ((3.0 + x_17) > (19.0 + x_18)? (3.0 + x_17) : (19.0 + x_18))) > ((2.0 + x_19) > ((9.0 + x_20) > (19.0 + x_21)? (9.0 + x_20) : (19.0 + x_21))? (2.0 + x_19) : ((9.0 + x_20) > (19.0 + x_21)? (9.0 + x_20) : (19.0 + x_21)))? ((10.0 + x_16) > ((3.0 + x_17) > (19.0 + x_18)? (3.0 + x_17) : (19.0 + x_18))? (10.0 + x_16) : ((3.0 + x_17) > (19.0 + x_18)? (3.0 + x_17) : (19.0 + x_18))) : ((2.0 + x_19) > ((9.0 + x_20) > (19.0 + x_21)? (9.0 + x_20) : (19.0 + x_21))? (2.0 + x_19) : ((9.0 + x_20) > (19.0 + x_21)? (9.0 + x_20) : (19.0 + x_21)))));
x_5_ = ((((20.0 + x_1) > ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))? (20.0 + x_1) : ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))) > ((15.0 + x_5) > ((16.0 + x_7) > (20.0 + x_8)? (16.0 + x_7) : (20.0 + x_8))? (15.0 + x_5) : ((16.0 + x_7) > (20.0 + x_8)? (16.0 + x_7) : (20.0 + x_8)))? ((20.0 + x_1) > ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))? (20.0 + x_1) : ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))) : ((15.0 + x_5) > ((16.0 + x_7) > (20.0 + x_8)? (16.0 + x_7) : (20.0 + x_8))? (15.0 + x_5) : ((16.0 + x_7) > (20.0 + x_8)? (16.0 + x_7) : (20.0 + x_8)))) > (((17.0 + x_10) > ((14.0 + x_11) > (6.0 + x_16)? (14.0 + x_11) : (6.0 + x_16))? (17.0 + x_10) : ((14.0 + x_11) > (6.0 + x_16)? (14.0 + x_11) : (6.0 + x_16))) > ((7.0 + x_19) > ((2.0 + x_20) > (2.0 + x_21)? (2.0 + x_20) : (2.0 + x_21))? (7.0 + x_19) : ((2.0 + x_20) > (2.0 + x_21)? (2.0 + x_20) : (2.0 + x_21)))? ((17.0 + x_10) > ((14.0 + x_11) > (6.0 + x_16)? (14.0 + x_11) : (6.0 + x_16))? (17.0 + x_10) : ((14.0 + x_11) > (6.0 + x_16)? (14.0 + x_11) : (6.0 + x_16))) : ((7.0 + x_19) > ((2.0 + x_20) > (2.0 + x_21)? (2.0 + x_20) : (2.0 + x_21))? (7.0 + x_19) : ((2.0 + x_20) > (2.0 + x_21)? (2.0 + x_20) : (2.0 + x_21))))? (((20.0 + x_1) > ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))? (20.0 + x_1) : ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))) > ((15.0 + x_5) > ((16.0 + x_7) > (20.0 + x_8)? (16.0 + x_7) : (20.0 + x_8))? (15.0 + x_5) : ((16.0 + x_7) > (20.0 + x_8)? (16.0 + x_7) : (20.0 + x_8)))? ((20.0 + x_1) > ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))? (20.0 + x_1) : ((5.0 + x_3) > (8.0 + x_4)? (5.0 + x_3) : (8.0 + x_4))) : ((15.0 + x_5) > ((16.0 + x_7) > (20.0 + x_8)? (16.0 + x_7) : (20.0 + x_8))? (15.0 + x_5) : ((16.0 + x_7) > (20.0 + x_8)? (16.0 + x_7) : (20.0 + x_8)))) : (((17.0 + x_10) > ((14.0 + x_11) > (6.0 + x_16)? (14.0 + x_11) : (6.0 + x_16))? (17.0 + x_10) : ((14.0 + x_11) > (6.0 + x_16)? (14.0 + x_11) : (6.0 + x_16))) > ((7.0 + x_19) > ((2.0 + x_20) > (2.0 + x_21)? (2.0 + x_20) : (2.0 + x_21))? (7.0 + x_19) : ((2.0 + x_20) > (2.0 + x_21)? (2.0 + x_20) : (2.0 + x_21)))? ((17.0 + x_10) > ((14.0 + x_11) > (6.0 + x_16)? (14.0 + x_11) : (6.0 + x_16))? (17.0 + x_10) : ((14.0 + x_11) > (6.0 + x_16)? (14.0 + x_11) : (6.0 + x_16))) : ((7.0 + x_19) > ((2.0 + x_20) > (2.0 + x_21)? (2.0 + x_20) : (2.0 + x_21))? (7.0 + x_19) : ((2.0 + x_20) > (2.0 + x_21)? (2.0 + x_20) : (2.0 + x_21)))));
x_6_ = ((((15.0 + x_0) > ((18.0 + x_1) > (4.0 + x_2)? (18.0 + x_1) : (4.0 + x_2))? (15.0 + x_0) : ((18.0 + x_1) > (4.0 + x_2)? (18.0 + x_1) : (4.0 + x_2))) > ((4.0 + x_3) > ((8.0 + x_4) > (7.0 + x_6)? (8.0 + x_4) : (7.0 + x_6))? (4.0 + x_3) : ((8.0 + x_4) > (7.0 + x_6)? (8.0 + x_4) : (7.0 + x_6)))? ((15.0 + x_0) > ((18.0 + x_1) > (4.0 + x_2)? (18.0 + x_1) : (4.0 + x_2))? (15.0 + x_0) : ((18.0 + x_1) > (4.0 + x_2)? (18.0 + x_1) : (4.0 + x_2))) : ((4.0 + x_3) > ((8.0 + x_4) > (7.0 + x_6)? (8.0 + x_4) : (7.0 + x_6))? (4.0 + x_3) : ((8.0 + x_4) > (7.0 + x_6)? (8.0 + x_4) : (7.0 + x_6)))) > (((8.0 + x_8) > ((15.0 + x_9) > (15.0 + x_10)? (15.0 + x_9) : (15.0 + x_10))? (8.0 + x_8) : ((15.0 + x_9) > (15.0 + x_10)? (15.0 + x_9) : (15.0 + x_10))) > ((14.0 + x_17) > ((4.0 + x_19) > (12.0 + x_20)? (4.0 + x_19) : (12.0 + x_20))? (14.0 + x_17) : ((4.0 + x_19) > (12.0 + x_20)? (4.0 + x_19) : (12.0 + x_20)))? ((8.0 + x_8) > ((15.0 + x_9) > (15.0 + x_10)? (15.0 + x_9) : (15.0 + x_10))? (8.0 + x_8) : ((15.0 + x_9) > (15.0 + x_10)? (15.0 + x_9) : (15.0 + x_10))) : ((14.0 + x_17) > ((4.0 + x_19) > (12.0 + x_20)? (4.0 + x_19) : (12.0 + x_20))? (14.0 + x_17) : ((4.0 + x_19) > (12.0 + x_20)? (4.0 + x_19) : (12.0 + x_20))))? (((15.0 + x_0) > ((18.0 + x_1) > (4.0 + x_2)? (18.0 + x_1) : (4.0 + x_2))? (15.0 + x_0) : ((18.0 + x_1) > (4.0 + x_2)? (18.0 + x_1) : (4.0 + x_2))) > ((4.0 + x_3) > ((8.0 + x_4) > (7.0 + x_6)? (8.0 + x_4) : (7.0 + x_6))? (4.0 + x_3) : ((8.0 + x_4) > (7.0 + x_6)? (8.0 + x_4) : (7.0 + x_6)))? ((15.0 + x_0) > ((18.0 + x_1) > (4.0 + x_2)? (18.0 + x_1) : (4.0 + x_2))? (15.0 + x_0) : ((18.0 + x_1) > (4.0 + x_2)? (18.0 + x_1) : (4.0 + x_2))) : ((4.0 + x_3) > ((8.0 + x_4) > (7.0 + x_6)? (8.0 + x_4) : (7.0 + x_6))? (4.0 + x_3) : ((8.0 + x_4) > (7.0 + x_6)? (8.0 + x_4) : (7.0 + x_6)))) : (((8.0 + x_8) > ((15.0 + x_9) > (15.0 + x_10)? (15.0 + x_9) : (15.0 + x_10))? (8.0 + x_8) : ((15.0 + x_9) > (15.0 + x_10)? (15.0 + x_9) : (15.0 + x_10))) > ((14.0 + x_17) > ((4.0 + x_19) > (12.0 + x_20)? (4.0 + x_19) : (12.0 + x_20))? (14.0 + x_17) : ((4.0 + x_19) > (12.0 + x_20)? (4.0 + x_19) : (12.0 + x_20)))? ((8.0 + x_8) > ((15.0 + x_9) > (15.0 + x_10)? (15.0 + x_9) : (15.0 + x_10))? (8.0 + x_8) : ((15.0 + x_9) > (15.0 + x_10)? (15.0 + x_9) : (15.0 + x_10))) : ((14.0 + x_17) > ((4.0 + x_19) > (12.0 + x_20)? (4.0 + x_19) : (12.0 + x_20))? (14.0 + x_17) : ((4.0 + x_19) > (12.0 + x_20)? (4.0 + x_19) : (12.0 + x_20)))));
x_7_ = ((((15.0 + x_0) > ((2.0 + x_4) > (14.0 + x_5)? (2.0 + x_4) : (14.0 + x_5))? (15.0 + x_0) : ((2.0 + x_4) > (14.0 + x_5)? (2.0 + x_4) : (14.0 + x_5))) > ((19.0 + x_6) > ((7.0 + x_7) > (9.0 + x_9)? (7.0 + x_7) : (9.0 + x_9))? (19.0 + x_6) : ((7.0 + x_7) > (9.0 + x_9)? (7.0 + x_7) : (9.0 + x_9)))? ((15.0 + x_0) > ((2.0 + x_4) > (14.0 + x_5)? (2.0 + x_4) : (14.0 + x_5))? (15.0 + x_0) : ((2.0 + x_4) > (14.0 + x_5)? (2.0 + x_4) : (14.0 + x_5))) : ((19.0 + x_6) > ((7.0 + x_7) > (9.0 + x_9)? (7.0 + x_7) : (9.0 + x_9))? (19.0 + x_6) : ((7.0 + x_7) > (9.0 + x_9)? (7.0 + x_7) : (9.0 + x_9)))) > (((14.0 + x_12) > ((13.0 + x_13) > (8.0 + x_14)? (13.0 + x_13) : (8.0 + x_14))? (14.0 + x_12) : ((13.0 + x_13) > (8.0 + x_14)? (13.0 + x_13) : (8.0 + x_14))) > ((7.0 + x_18) > ((19.0 + x_20) > (4.0 + x_23)? (19.0 + x_20) : (4.0 + x_23))? (7.0 + x_18) : ((19.0 + x_20) > (4.0 + x_23)? (19.0 + x_20) : (4.0 + x_23)))? ((14.0 + x_12) > ((13.0 + x_13) > (8.0 + x_14)? (13.0 + x_13) : (8.0 + x_14))? (14.0 + x_12) : ((13.0 + x_13) > (8.0 + x_14)? (13.0 + x_13) : (8.0 + x_14))) : ((7.0 + x_18) > ((19.0 + x_20) > (4.0 + x_23)? (19.0 + x_20) : (4.0 + x_23))? (7.0 + x_18) : ((19.0 + x_20) > (4.0 + x_23)? (19.0 + x_20) : (4.0 + x_23))))? (((15.0 + x_0) > ((2.0 + x_4) > (14.0 + x_5)? (2.0 + x_4) : (14.0 + x_5))? (15.0 + x_0) : ((2.0 + x_4) > (14.0 + x_5)? (2.0 + x_4) : (14.0 + x_5))) > ((19.0 + x_6) > ((7.0 + x_7) > (9.0 + x_9)? (7.0 + x_7) : (9.0 + x_9))? (19.0 + x_6) : ((7.0 + x_7) > (9.0 + x_9)? (7.0 + x_7) : (9.0 + x_9)))? ((15.0 + x_0) > ((2.0 + x_4) > (14.0 + x_5)? (2.0 + x_4) : (14.0 + x_5))? (15.0 + x_0) : ((2.0 + x_4) > (14.0 + x_5)? (2.0 + x_4) : (14.0 + x_5))) : ((19.0 + x_6) > ((7.0 + x_7) > (9.0 + x_9)? (7.0 + x_7) : (9.0 + x_9))? (19.0 + x_6) : ((7.0 + x_7) > (9.0 + x_9)? (7.0 + x_7) : (9.0 + x_9)))) : (((14.0 + x_12) > ((13.0 + x_13) > (8.0 + x_14)? (13.0 + x_13) : (8.0 + x_14))? (14.0 + x_12) : ((13.0 + x_13) > (8.0 + x_14)? (13.0 + x_13) : (8.0 + x_14))) > ((7.0 + x_18) > ((19.0 + x_20) > (4.0 + x_23)? (19.0 + x_20) : (4.0 + x_23))? (7.0 + x_18) : ((19.0 + x_20) > (4.0 + x_23)? (19.0 + x_20) : (4.0 + x_23)))? ((14.0 + x_12) > ((13.0 + x_13) > (8.0 + x_14)? (13.0 + x_13) : (8.0 + x_14))? (14.0 + x_12) : ((13.0 + x_13) > (8.0 + x_14)? (13.0 + x_13) : (8.0 + x_14))) : ((7.0 + x_18) > ((19.0 + x_20) > (4.0 + x_23)? (19.0 + x_20) : (4.0 + x_23))? (7.0 + x_18) : ((19.0 + x_20) > (4.0 + x_23)? (19.0 + x_20) : (4.0 + x_23)))));
x_8_ = ((((9.0 + x_0) > ((17.0 + x_1) > (7.0 + x_2)? (17.0 + x_1) : (7.0 + x_2))? (9.0 + x_0) : ((17.0 + x_1) > (7.0 + x_2)? (17.0 + x_1) : (7.0 + x_2))) > ((3.0 + x_4) > ((8.0 + x_8) > (8.0 + x_12)? (8.0 + x_8) : (8.0 + x_12))? (3.0 + x_4) : ((8.0 + x_8) > (8.0 + x_12)? (8.0 + x_8) : (8.0 + x_12)))? ((9.0 + x_0) > ((17.0 + x_1) > (7.0 + x_2)? (17.0 + x_1) : (7.0 + x_2))? (9.0 + x_0) : ((17.0 + x_1) > (7.0 + x_2)? (17.0 + x_1) : (7.0 + x_2))) : ((3.0 + x_4) > ((8.0 + x_8) > (8.0 + x_12)? (8.0 + x_8) : (8.0 + x_12))? (3.0 + x_4) : ((8.0 + x_8) > (8.0 + x_12)? (8.0 + x_8) : (8.0 + x_12)))) > (((6.0 + x_13) > ((16.0 + x_14) > (17.0 + x_16)? (16.0 + x_14) : (17.0 + x_16))? (6.0 + x_13) : ((16.0 + x_14) > (17.0 + x_16)? (16.0 + x_14) : (17.0 + x_16))) > ((3.0 + x_18) > ((4.0 + x_20) > (9.0 + x_22)? (4.0 + x_20) : (9.0 + x_22))? (3.0 + x_18) : ((4.0 + x_20) > (9.0 + x_22)? (4.0 + x_20) : (9.0 + x_22)))? ((6.0 + x_13) > ((16.0 + x_14) > (17.0 + x_16)? (16.0 + x_14) : (17.0 + x_16))? (6.0 + x_13) : ((16.0 + x_14) > (17.0 + x_16)? (16.0 + x_14) : (17.0 + x_16))) : ((3.0 + x_18) > ((4.0 + x_20) > (9.0 + x_22)? (4.0 + x_20) : (9.0 + x_22))? (3.0 + x_18) : ((4.0 + x_20) > (9.0 + x_22)? (4.0 + x_20) : (9.0 + x_22))))? (((9.0 + x_0) > ((17.0 + x_1) > (7.0 + x_2)? (17.0 + x_1) : (7.0 + x_2))? (9.0 + x_0) : ((17.0 + x_1) > (7.0 + x_2)? (17.0 + x_1) : (7.0 + x_2))) > ((3.0 + x_4) > ((8.0 + x_8) > (8.0 + x_12)? (8.0 + x_8) : (8.0 + x_12))? (3.0 + x_4) : ((8.0 + x_8) > (8.0 + x_12)? (8.0 + x_8) : (8.0 + x_12)))? ((9.0 + x_0) > ((17.0 + x_1) > (7.0 + x_2)? (17.0 + x_1) : (7.0 + x_2))? (9.0 + x_0) : ((17.0 + x_1) > (7.0 + x_2)? (17.0 + x_1) : (7.0 + x_2))) : ((3.0 + x_4) > ((8.0 + x_8) > (8.0 + x_12)? (8.0 + x_8) : (8.0 + x_12))? (3.0 + x_4) : ((8.0 + x_8) > (8.0 + x_12)? (8.0 + x_8) : (8.0 + x_12)))) : (((6.0 + x_13) > ((16.0 + x_14) > (17.0 + x_16)? (16.0 + x_14) : (17.0 + x_16))? (6.0 + x_13) : ((16.0 + x_14) > (17.0 + x_16)? (16.0 + x_14) : (17.0 + x_16))) > ((3.0 + x_18) > ((4.0 + x_20) > (9.0 + x_22)? (4.0 + x_20) : (9.0 + x_22))? (3.0 + x_18) : ((4.0 + x_20) > (9.0 + x_22)? (4.0 + x_20) : (9.0 + x_22)))? ((6.0 + x_13) > ((16.0 + x_14) > (17.0 + x_16)? (16.0 + x_14) : (17.0 + x_16))? (6.0 + x_13) : ((16.0 + x_14) > (17.0 + x_16)? (16.0 + x_14) : (17.0 + x_16))) : ((3.0 + x_18) > ((4.0 + x_20) > (9.0 + x_22)? (4.0 + x_20) : (9.0 + x_22))? (3.0 + x_18) : ((4.0 + x_20) > (9.0 + x_22)? (4.0 + x_20) : (9.0 + x_22)))));
x_9_ = ((((14.0 + x_0) > ((13.0 + x_2) > (14.0 + x_4)? (13.0 + x_2) : (14.0 + x_4))? (14.0 + x_0) : ((13.0 + x_2) > (14.0 + x_4)? (13.0 + x_2) : (14.0 + x_4))) > ((4.0 + x_7) > ((7.0 + x_9) > (17.0 + x_16)? (7.0 + x_9) : (17.0 + x_16))? (4.0 + x_7) : ((7.0 + x_9) > (17.0 + x_16)? (7.0 + x_9) : (17.0 + x_16)))? ((14.0 + x_0) > ((13.0 + x_2) > (14.0 + x_4)? (13.0 + x_2) : (14.0 + x_4))? (14.0 + x_0) : ((13.0 + x_2) > (14.0 + x_4)? (13.0 + x_2) : (14.0 + x_4))) : ((4.0 + x_7) > ((7.0 + x_9) > (17.0 + x_16)? (7.0 + x_9) : (17.0 + x_16))? (4.0 + x_7) : ((7.0 + x_9) > (17.0 + x_16)? (7.0 + x_9) : (17.0 + x_16)))) > (((2.0 + x_17) > ((17.0 + x_18) > (19.0 + x_19)? (17.0 + x_18) : (19.0 + x_19))? (2.0 + x_17) : ((17.0 + x_18) > (19.0 + x_19)? (17.0 + x_18) : (19.0 + x_19))) > ((5.0 + x_21) > ((16.0 + x_22) > (20.0 + x_23)? (16.0 + x_22) : (20.0 + x_23))? (5.0 + x_21) : ((16.0 + x_22) > (20.0 + x_23)? (16.0 + x_22) : (20.0 + x_23)))? ((2.0 + x_17) > ((17.0 + x_18) > (19.0 + x_19)? (17.0 + x_18) : (19.0 + x_19))? (2.0 + x_17) : ((17.0 + x_18) > (19.0 + x_19)? (17.0 + x_18) : (19.0 + x_19))) : ((5.0 + x_21) > ((16.0 + x_22) > (20.0 + x_23)? (16.0 + x_22) : (20.0 + x_23))? (5.0 + x_21) : ((16.0 + x_22) > (20.0 + x_23)? (16.0 + x_22) : (20.0 + x_23))))? (((14.0 + x_0) > ((13.0 + x_2) > (14.0 + x_4)? (13.0 + x_2) : (14.0 + x_4))? (14.0 + x_0) : ((13.0 + x_2) > (14.0 + x_4)? (13.0 + x_2) : (14.0 + x_4))) > ((4.0 + x_7) > ((7.0 + x_9) > (17.0 + x_16)? (7.0 + x_9) : (17.0 + x_16))? (4.0 + x_7) : ((7.0 + x_9) > (17.0 + x_16)? (7.0 + x_9) : (17.0 + x_16)))? ((14.0 + x_0) > ((13.0 + x_2) > (14.0 + x_4)? (13.0 + x_2) : (14.0 + x_4))? (14.0 + x_0) : ((13.0 + x_2) > (14.0 + x_4)? (13.0 + x_2) : (14.0 + x_4))) : ((4.0 + x_7) > ((7.0 + x_9) > (17.0 + x_16)? (7.0 + x_9) : (17.0 + x_16))? (4.0 + x_7) : ((7.0 + x_9) > (17.0 + x_16)? (7.0 + x_9) : (17.0 + x_16)))) : (((2.0 + x_17) > ((17.0 + x_18) > (19.0 + x_19)? (17.0 + x_18) : (19.0 + x_19))? (2.0 + x_17) : ((17.0 + x_18) > (19.0 + x_19)? (17.0 + x_18) : (19.0 + x_19))) > ((5.0 + x_21) > ((16.0 + x_22) > (20.0 + x_23)? (16.0 + x_22) : (20.0 + x_23))? (5.0 + x_21) : ((16.0 + x_22) > (20.0 + x_23)? (16.0 + x_22) : (20.0 + x_23)))? ((2.0 + x_17) > ((17.0 + x_18) > (19.0 + x_19)? (17.0 + x_18) : (19.0 + x_19))? (2.0 + x_17) : ((17.0 + x_18) > (19.0 + x_19)? (17.0 + x_18) : (19.0 + x_19))) : ((5.0 + x_21) > ((16.0 + x_22) > (20.0 + x_23)? (16.0 + x_22) : (20.0 + x_23))? (5.0 + x_21) : ((16.0 + x_22) > (20.0 + x_23)? (16.0 + x_22) : (20.0 + x_23)))));
x_10_ = ((((9.0 + x_1) > ((4.0 + x_3) > (18.0 + x_8)? (4.0 + x_3) : (18.0 + x_8))? (9.0 + x_1) : ((4.0 + x_3) > (18.0 + x_8)? (4.0 + x_3) : (18.0 + x_8))) > ((3.0 + x_9) > ((18.0 + x_10) > (20.0 + x_13)? (18.0 + x_10) : (20.0 + x_13))? (3.0 + x_9) : ((18.0 + x_10) > (20.0 + x_13)? (18.0 + x_10) : (20.0 + x_13)))? ((9.0 + x_1) > ((4.0 + x_3) > (18.0 + x_8)? (4.0 + x_3) : (18.0 + x_8))? (9.0 + x_1) : ((4.0 + x_3) > (18.0 + x_8)? (4.0 + x_3) : (18.0 + x_8))) : ((3.0 + x_9) > ((18.0 + x_10) > (20.0 + x_13)? (18.0 + x_10) : (20.0 + x_13))? (3.0 + x_9) : ((18.0 + x_10) > (20.0 + x_13)? (18.0 + x_10) : (20.0 + x_13)))) > (((6.0 + x_15) > ((16.0 + x_18) > (17.0 + x_19)? (16.0 + x_18) : (17.0 + x_19))? (6.0 + x_15) : ((16.0 + x_18) > (17.0 + x_19)? (16.0 + x_18) : (17.0 + x_19))) > ((17.0 + x_20) > ((13.0 + x_22) > (16.0 + x_23)? (13.0 + x_22) : (16.0 + x_23))? (17.0 + x_20) : ((13.0 + x_22) > (16.0 + x_23)? (13.0 + x_22) : (16.0 + x_23)))? ((6.0 + x_15) > ((16.0 + x_18) > (17.0 + x_19)? (16.0 + x_18) : (17.0 + x_19))? (6.0 + x_15) : ((16.0 + x_18) > (17.0 + x_19)? (16.0 + x_18) : (17.0 + x_19))) : ((17.0 + x_20) > ((13.0 + x_22) > (16.0 + x_23)? (13.0 + x_22) : (16.0 + x_23))? (17.0 + x_20) : ((13.0 + x_22) > (16.0 + x_23)? (13.0 + x_22) : (16.0 + x_23))))? (((9.0 + x_1) > ((4.0 + x_3) > (18.0 + x_8)? (4.0 + x_3) : (18.0 + x_8))? (9.0 + x_1) : ((4.0 + x_3) > (18.0 + x_8)? (4.0 + x_3) : (18.0 + x_8))) > ((3.0 + x_9) > ((18.0 + x_10) > (20.0 + x_13)? (18.0 + x_10) : (20.0 + x_13))? (3.0 + x_9) : ((18.0 + x_10) > (20.0 + x_13)? (18.0 + x_10) : (20.0 + x_13)))? ((9.0 + x_1) > ((4.0 + x_3) > (18.0 + x_8)? (4.0 + x_3) : (18.0 + x_8))? (9.0 + x_1) : ((4.0 + x_3) > (18.0 + x_8)? (4.0 + x_3) : (18.0 + x_8))) : ((3.0 + x_9) > ((18.0 + x_10) > (20.0 + x_13)? (18.0 + x_10) : (20.0 + x_13))? (3.0 + x_9) : ((18.0 + x_10) > (20.0 + x_13)? (18.0 + x_10) : (20.0 + x_13)))) : (((6.0 + x_15) > ((16.0 + x_18) > (17.0 + x_19)? (16.0 + x_18) : (17.0 + x_19))? (6.0 + x_15) : ((16.0 + x_18) > (17.0 + x_19)? (16.0 + x_18) : (17.0 + x_19))) > ((17.0 + x_20) > ((13.0 + x_22) > (16.0 + x_23)? (13.0 + x_22) : (16.0 + x_23))? (17.0 + x_20) : ((13.0 + x_22) > (16.0 + x_23)? (13.0 + x_22) : (16.0 + x_23)))? ((6.0 + x_15) > ((16.0 + x_18) > (17.0 + x_19)? (16.0 + x_18) : (17.0 + x_19))? (6.0 + x_15) : ((16.0 + x_18) > (17.0 + x_19)? (16.0 + x_18) : (17.0 + x_19))) : ((17.0 + x_20) > ((13.0 + x_22) > (16.0 + x_23)? (13.0 + x_22) : (16.0 + x_23))? (17.0 + x_20) : ((13.0 + x_22) > (16.0 + x_23)? (13.0 + x_22) : (16.0 + x_23)))));
x_11_ = ((((7.0 + x_0) > ((14.0 + x_3) > (4.0 + x_5)? (14.0 + x_3) : (4.0 + x_5))? (7.0 + x_0) : ((14.0 + x_3) > (4.0 + x_5)? (14.0 + x_3) : (4.0 + x_5))) > ((11.0 + x_6) > ((20.0 + x_7) > (7.0 + x_8)? (20.0 + x_7) : (7.0 + x_8))? (11.0 + x_6) : ((20.0 + x_7) > (7.0 + x_8)? (20.0 + x_7) : (7.0 + x_8)))? ((7.0 + x_0) > ((14.0 + x_3) > (4.0 + x_5)? (14.0 + x_3) : (4.0 + x_5))? (7.0 + x_0) : ((14.0 + x_3) > (4.0 + x_5)? (14.0 + x_3) : (4.0 + x_5))) : ((11.0 + x_6) > ((20.0 + x_7) > (7.0 + x_8)? (20.0 + x_7) : (7.0 + x_8))? (11.0 + x_6) : ((20.0 + x_7) > (7.0 + x_8)? (20.0 + x_7) : (7.0 + x_8)))) > (((14.0 + x_9) > ((6.0 + x_10) > (8.0 + x_13)? (6.0 + x_10) : (8.0 + x_13))? (14.0 + x_9) : ((6.0 + x_10) > (8.0 + x_13)? (6.0 + x_10) : (8.0 + x_13))) > ((10.0 + x_18) > ((11.0 + x_21) > (14.0 + x_22)? (11.0 + x_21) : (14.0 + x_22))? (10.0 + x_18) : ((11.0 + x_21) > (14.0 + x_22)? (11.0 + x_21) : (14.0 + x_22)))? ((14.0 + x_9) > ((6.0 + x_10) > (8.0 + x_13)? (6.0 + x_10) : (8.0 + x_13))? (14.0 + x_9) : ((6.0 + x_10) > (8.0 + x_13)? (6.0 + x_10) : (8.0 + x_13))) : ((10.0 + x_18) > ((11.0 + x_21) > (14.0 + x_22)? (11.0 + x_21) : (14.0 + x_22))? (10.0 + x_18) : ((11.0 + x_21) > (14.0 + x_22)? (11.0 + x_21) : (14.0 + x_22))))? (((7.0 + x_0) > ((14.0 + x_3) > (4.0 + x_5)? (14.0 + x_3) : (4.0 + x_5))? (7.0 + x_0) : ((14.0 + x_3) > (4.0 + x_5)? (14.0 + x_3) : (4.0 + x_5))) > ((11.0 + x_6) > ((20.0 + x_7) > (7.0 + x_8)? (20.0 + x_7) : (7.0 + x_8))? (11.0 + x_6) : ((20.0 + x_7) > (7.0 + x_8)? (20.0 + x_7) : (7.0 + x_8)))? ((7.0 + x_0) > ((14.0 + x_3) > (4.0 + x_5)? (14.0 + x_3) : (4.0 + x_5))? (7.0 + x_0) : ((14.0 + x_3) > (4.0 + x_5)? (14.0 + x_3) : (4.0 + x_5))) : ((11.0 + x_6) > ((20.0 + x_7) > (7.0 + x_8)? (20.0 + x_7) : (7.0 + x_8))? (11.0 + x_6) : ((20.0 + x_7) > (7.0 + x_8)? (20.0 + x_7) : (7.0 + x_8)))) : (((14.0 + x_9) > ((6.0 + x_10) > (8.0 + x_13)? (6.0 + x_10) : (8.0 + x_13))? (14.0 + x_9) : ((6.0 + x_10) > (8.0 + x_13)? (6.0 + x_10) : (8.0 + x_13))) > ((10.0 + x_18) > ((11.0 + x_21) > (14.0 + x_22)? (11.0 + x_21) : (14.0 + x_22))? (10.0 + x_18) : ((11.0 + x_21) > (14.0 + x_22)? (11.0 + x_21) : (14.0 + x_22)))? ((14.0 + x_9) > ((6.0 + x_10) > (8.0 + x_13)? (6.0 + x_10) : (8.0 + x_13))? (14.0 + x_9) : ((6.0 + x_10) > (8.0 + x_13)? (6.0 + x_10) : (8.0 + x_13))) : ((10.0 + x_18) > ((11.0 + x_21) > (14.0 + x_22)? (11.0 + x_21) : (14.0 + x_22))? (10.0 + x_18) : ((11.0 + x_21) > (14.0 + x_22)? (11.0 + x_21) : (14.0 + x_22)))));
x_12_ = ((((12.0 + x_2) > ((2.0 + x_6) > (16.0 + x_7)? (2.0 + x_6) : (16.0 + x_7))? (12.0 + x_2) : ((2.0 + x_6) > (16.0 + x_7)? (2.0 + x_6) : (16.0 + x_7))) > ((7.0 + x_11) > ((5.0 + x_13) > (16.0 + x_14)? (5.0 + x_13) : (16.0 + x_14))? (7.0 + x_11) : ((5.0 + x_13) > (16.0 + x_14)? (5.0 + x_13) : (16.0 + x_14)))? ((12.0 + x_2) > ((2.0 + x_6) > (16.0 + x_7)? (2.0 + x_6) : (16.0 + x_7))? (12.0 + x_2) : ((2.0 + x_6) > (16.0 + x_7)? (2.0 + x_6) : (16.0 + x_7))) : ((7.0 + x_11) > ((5.0 + x_13) > (16.0 + x_14)? (5.0 + x_13) : (16.0 + x_14))? (7.0 + x_11) : ((5.0 + x_13) > (16.0 + x_14)? (5.0 + x_13) : (16.0 + x_14)))) > (((13.0 + x_15) > ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))? (13.0 + x_15) : ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))) > ((11.0 + x_19) > ((18.0 + x_22) > (2.0 + x_23)? (18.0 + x_22) : (2.0 + x_23))? (11.0 + x_19) : ((18.0 + x_22) > (2.0 + x_23)? (18.0 + x_22) : (2.0 + x_23)))? ((13.0 + x_15) > ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))? (13.0 + x_15) : ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))) : ((11.0 + x_19) > ((18.0 + x_22) > (2.0 + x_23)? (18.0 + x_22) : (2.0 + x_23))? (11.0 + x_19) : ((18.0 + x_22) > (2.0 + x_23)? (18.0 + x_22) : (2.0 + x_23))))? (((12.0 + x_2) > ((2.0 + x_6) > (16.0 + x_7)? (2.0 + x_6) : (16.0 + x_7))? (12.0 + x_2) : ((2.0 + x_6) > (16.0 + x_7)? (2.0 + x_6) : (16.0 + x_7))) > ((7.0 + x_11) > ((5.0 + x_13) > (16.0 + x_14)? (5.0 + x_13) : (16.0 + x_14))? (7.0 + x_11) : ((5.0 + x_13) > (16.0 + x_14)? (5.0 + x_13) : (16.0 + x_14)))? ((12.0 + x_2) > ((2.0 + x_6) > (16.0 + x_7)? (2.0 + x_6) : (16.0 + x_7))? (12.0 + x_2) : ((2.0 + x_6) > (16.0 + x_7)? (2.0 + x_6) : (16.0 + x_7))) : ((7.0 + x_11) > ((5.0 + x_13) > (16.0 + x_14)? (5.0 + x_13) : (16.0 + x_14))? (7.0 + x_11) : ((5.0 + x_13) > (16.0 + x_14)? (5.0 + x_13) : (16.0 + x_14)))) : (((13.0 + x_15) > ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))? (13.0 + x_15) : ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))) > ((11.0 + x_19) > ((18.0 + x_22) > (2.0 + x_23)? (18.0 + x_22) : (2.0 + x_23))? (11.0 + x_19) : ((18.0 + x_22) > (2.0 + x_23)? (18.0 + x_22) : (2.0 + x_23)))? ((13.0 + x_15) > ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))? (13.0 + x_15) : ((5.0 + x_16) > (7.0 + x_17)? (5.0 + x_16) : (7.0 + x_17))) : ((11.0 + x_19) > ((18.0 + x_22) > (2.0 + x_23)? (18.0 + x_22) : (2.0 + x_23))? (11.0 + x_19) : ((18.0 + x_22) > (2.0 + x_23)? (18.0 + x_22) : (2.0 + x_23)))));
x_13_ = ((((8.0 + x_1) > ((5.0 + x_3) > (17.0 + x_4)? (5.0 + x_3) : (17.0 + x_4))? (8.0 + x_1) : ((5.0 + x_3) > (17.0 + x_4)? (5.0 + x_3) : (17.0 + x_4))) > ((14.0 + x_6) > ((5.0 + x_7) > (6.0 + x_9)? (5.0 + x_7) : (6.0 + x_9))? (14.0 + x_6) : ((5.0 + x_7) > (6.0 + x_9)? (5.0 + x_7) : (6.0 + x_9)))? ((8.0 + x_1) > ((5.0 + x_3) > (17.0 + x_4)? (5.0 + x_3) : (17.0 + x_4))? (8.0 + x_1) : ((5.0 + x_3) > (17.0 + x_4)? (5.0 + x_3) : (17.0 + x_4))) : ((14.0 + x_6) > ((5.0 + x_7) > (6.0 + x_9)? (5.0 + x_7) : (6.0 + x_9))? (14.0 + x_6) : ((5.0 + x_7) > (6.0 + x_9)? (5.0 + x_7) : (6.0 + x_9)))) > (((16.0 + x_11) > ((8.0 + x_13) > (3.0 + x_18)? (8.0 + x_13) : (3.0 + x_18))? (16.0 + x_11) : ((8.0 + x_13) > (3.0 + x_18)? (8.0 + x_13) : (3.0 + x_18))) > ((8.0 + x_19) > ((7.0 + x_20) > (3.0 + x_21)? (7.0 + x_20) : (3.0 + x_21))? (8.0 + x_19) : ((7.0 + x_20) > (3.0 + x_21)? (7.0 + x_20) : (3.0 + x_21)))? ((16.0 + x_11) > ((8.0 + x_13) > (3.0 + x_18)? (8.0 + x_13) : (3.0 + x_18))? (16.0 + x_11) : ((8.0 + x_13) > (3.0 + x_18)? (8.0 + x_13) : (3.0 + x_18))) : ((8.0 + x_19) > ((7.0 + x_20) > (3.0 + x_21)? (7.0 + x_20) : (3.0 + x_21))? (8.0 + x_19) : ((7.0 + x_20) > (3.0 + x_21)? (7.0 + x_20) : (3.0 + x_21))))? (((8.0 + x_1) > ((5.0 + x_3) > (17.0 + x_4)? (5.0 + x_3) : (17.0 + x_4))? (8.0 + x_1) : ((5.0 + x_3) > (17.0 + x_4)? (5.0 + x_3) : (17.0 + x_4))) > ((14.0 + x_6) > ((5.0 + x_7) > (6.0 + x_9)? (5.0 + x_7) : (6.0 + x_9))? (14.0 + x_6) : ((5.0 + x_7) > (6.0 + x_9)? (5.0 + x_7) : (6.0 + x_9)))? ((8.0 + x_1) > ((5.0 + x_3) > (17.0 + x_4)? (5.0 + x_3) : (17.0 + x_4))? (8.0 + x_1) : ((5.0 + x_3) > (17.0 + x_4)? (5.0 + x_3) : (17.0 + x_4))) : ((14.0 + x_6) > ((5.0 + x_7) > (6.0 + x_9)? (5.0 + x_7) : (6.0 + x_9))? (14.0 + x_6) : ((5.0 + x_7) > (6.0 + x_9)? (5.0 + x_7) : (6.0 + x_9)))) : (((16.0 + x_11) > ((8.0 + x_13) > (3.0 + x_18)? (8.0 + x_13) : (3.0 + x_18))? (16.0 + x_11) : ((8.0 + x_13) > (3.0 + x_18)? (8.0 + x_13) : (3.0 + x_18))) > ((8.0 + x_19) > ((7.0 + x_20) > (3.0 + x_21)? (7.0 + x_20) : (3.0 + x_21))? (8.0 + x_19) : ((7.0 + x_20) > (3.0 + x_21)? (7.0 + x_20) : (3.0 + x_21)))? ((16.0 + x_11) > ((8.0 + x_13) > (3.0 + x_18)? (8.0 + x_13) : (3.0 + x_18))? (16.0 + x_11) : ((8.0 + x_13) > (3.0 + x_18)? (8.0 + x_13) : (3.0 + x_18))) : ((8.0 + x_19) > ((7.0 + x_20) > (3.0 + x_21)? (7.0 + x_20) : (3.0 + x_21))? (8.0 + x_19) : ((7.0 + x_20) > (3.0 + x_21)? (7.0 + x_20) : (3.0 + x_21)))));
x_14_ = ((((17.0 + x_1) > ((19.0 + x_3) > (15.0 + x_4)? (19.0 + x_3) : (15.0 + x_4))? (17.0 + x_1) : ((19.0 + x_3) > (15.0 + x_4)? (19.0 + x_3) : (15.0 + x_4))) > ((10.0 + x_5) > ((19.0 + x_6) > (3.0 + x_7)? (19.0 + x_6) : (3.0 + x_7))? (10.0 + x_5) : ((19.0 + x_6) > (3.0 + x_7)? (19.0 + x_6) : (3.0 + x_7)))? ((17.0 + x_1) > ((19.0 + x_3) > (15.0 + x_4)? (19.0 + x_3) : (15.0 + x_4))? (17.0 + x_1) : ((19.0 + x_3) > (15.0 + x_4)? (19.0 + x_3) : (15.0 + x_4))) : ((10.0 + x_5) > ((19.0 + x_6) > (3.0 + x_7)? (19.0 + x_6) : (3.0 + x_7))? (10.0 + x_5) : ((19.0 + x_6) > (3.0 + x_7)? (19.0 + x_6) : (3.0 + x_7)))) > (((5.0 + x_8) > ((17.0 + x_11) > (13.0 + x_12)? (17.0 + x_11) : (13.0 + x_12))? (5.0 + x_8) : ((17.0 + x_11) > (13.0 + x_12)? (17.0 + x_11) : (13.0 + x_12))) > ((10.0 + x_14) > ((6.0 + x_18) > (16.0 + x_19)? (6.0 + x_18) : (16.0 + x_19))? (10.0 + x_14) : ((6.0 + x_18) > (16.0 + x_19)? (6.0 + x_18) : (16.0 + x_19)))? ((5.0 + x_8) > ((17.0 + x_11) > (13.0 + x_12)? (17.0 + x_11) : (13.0 + x_12))? (5.0 + x_8) : ((17.0 + x_11) > (13.0 + x_12)? (17.0 + x_11) : (13.0 + x_12))) : ((10.0 + x_14) > ((6.0 + x_18) > (16.0 + x_19)? (6.0 + x_18) : (16.0 + x_19))? (10.0 + x_14) : ((6.0 + x_18) > (16.0 + x_19)? (6.0 + x_18) : (16.0 + x_19))))? (((17.0 + x_1) > ((19.0 + x_3) > (15.0 + x_4)? (19.0 + x_3) : (15.0 + x_4))? (17.0 + x_1) : ((19.0 + x_3) > (15.0 + x_4)? (19.0 + x_3) : (15.0 + x_4))) > ((10.0 + x_5) > ((19.0 + x_6) > (3.0 + x_7)? (19.0 + x_6) : (3.0 + x_7))? (10.0 + x_5) : ((19.0 + x_6) > (3.0 + x_7)? (19.0 + x_6) : (3.0 + x_7)))? ((17.0 + x_1) > ((19.0 + x_3) > (15.0 + x_4)? (19.0 + x_3) : (15.0 + x_4))? (17.0 + x_1) : ((19.0 + x_3) > (15.0 + x_4)? (19.0 + x_3) : (15.0 + x_4))) : ((10.0 + x_5) > ((19.0 + x_6) > (3.0 + x_7)? (19.0 + x_6) : (3.0 + x_7))? (10.0 + x_5) : ((19.0 + x_6) > (3.0 + x_7)? (19.0 + x_6) : (3.0 + x_7)))) : (((5.0 + x_8) > ((17.0 + x_11) > (13.0 + x_12)? (17.0 + x_11) : (13.0 + x_12))? (5.0 + x_8) : ((17.0 + x_11) > (13.0 + x_12)? (17.0 + x_11) : (13.0 + x_12))) > ((10.0 + x_14) > ((6.0 + x_18) > (16.0 + x_19)? (6.0 + x_18) : (16.0 + x_19))? (10.0 + x_14) : ((6.0 + x_18) > (16.0 + x_19)? (6.0 + x_18) : (16.0 + x_19)))? ((5.0 + x_8) > ((17.0 + x_11) > (13.0 + x_12)? (17.0 + x_11) : (13.0 + x_12))? (5.0 + x_8) : ((17.0 + x_11) > (13.0 + x_12)? (17.0 + x_11) : (13.0 + x_12))) : ((10.0 + x_14) > ((6.0 + x_18) > (16.0 + x_19)? (6.0 + x_18) : (16.0 + x_19))? (10.0 + x_14) : ((6.0 + x_18) > (16.0 + x_19)? (6.0 + x_18) : (16.0 + x_19)))));
x_15_ = ((((12.0 + x_1) > ((6.0 + x_2) > (3.0 + x_3)? (6.0 + x_2) : (3.0 + x_3))? (12.0 + x_1) : ((6.0 + x_2) > (3.0 + x_3)? (6.0 + x_2) : (3.0 + x_3))) > ((20.0 + x_8) > ((5.0 + x_11) > (16.0 + x_12)? (5.0 + x_11) : (16.0 + x_12))? (20.0 + x_8) : ((5.0 + x_11) > (16.0 + x_12)? (5.0 + x_11) : (16.0 + x_12)))? ((12.0 + x_1) > ((6.0 + x_2) > (3.0 + x_3)? (6.0 + x_2) : (3.0 + x_3))? (12.0 + x_1) : ((6.0 + x_2) > (3.0 + x_3)? (6.0 + x_2) : (3.0 + x_3))) : ((20.0 + x_8) > ((5.0 + x_11) > (16.0 + x_12)? (5.0 + x_11) : (16.0 + x_12))? (20.0 + x_8) : ((5.0 + x_11) > (16.0 + x_12)? (5.0 + x_11) : (16.0 + x_12)))) > (((19.0 + x_13) > ((18.0 + x_17) > (11.0 + x_18)? (18.0 + x_17) : (11.0 + x_18))? (19.0 + x_13) : ((18.0 + x_17) > (11.0 + x_18)? (18.0 + x_17) : (11.0 + x_18))) > ((16.0 + x_19) > ((12.0 + x_20) > (5.0 + x_21)? (12.0 + x_20) : (5.0 + x_21))? (16.0 + x_19) : ((12.0 + x_20) > (5.0 + x_21)? (12.0 + x_20) : (5.0 + x_21)))? ((19.0 + x_13) > ((18.0 + x_17) > (11.0 + x_18)? (18.0 + x_17) : (11.0 + x_18))? (19.0 + x_13) : ((18.0 + x_17) > (11.0 + x_18)? (18.0 + x_17) : (11.0 + x_18))) : ((16.0 + x_19) > ((12.0 + x_20) > (5.0 + x_21)? (12.0 + x_20) : (5.0 + x_21))? (16.0 + x_19) : ((12.0 + x_20) > (5.0 + x_21)? (12.0 + x_20) : (5.0 + x_21))))? (((12.0 + x_1) > ((6.0 + x_2) > (3.0 + x_3)? (6.0 + x_2) : (3.0 + x_3))? (12.0 + x_1) : ((6.0 + x_2) > (3.0 + x_3)? (6.0 + x_2) : (3.0 + x_3))) > ((20.0 + x_8) > ((5.0 + x_11) > (16.0 + x_12)? (5.0 + x_11) : (16.0 + x_12))? (20.0 + x_8) : ((5.0 + x_11) > (16.0 + x_12)? (5.0 + x_11) : (16.0 + x_12)))? ((12.0 + x_1) > ((6.0 + x_2) > (3.0 + x_3)? (6.0 + x_2) : (3.0 + x_3))? (12.0 + x_1) : ((6.0 + x_2) > (3.0 + x_3)? (6.0 + x_2) : (3.0 + x_3))) : ((20.0 + x_8) > ((5.0 + x_11) > (16.0 + x_12)? (5.0 + x_11) : (16.0 + x_12))? (20.0 + x_8) : ((5.0 + x_11) > (16.0 + x_12)? (5.0 + x_11) : (16.0 + x_12)))) : (((19.0 + x_13) > ((18.0 + x_17) > (11.0 + x_18)? (18.0 + x_17) : (11.0 + x_18))? (19.0 + x_13) : ((18.0 + x_17) > (11.0 + x_18)? (18.0 + x_17) : (11.0 + x_18))) > ((16.0 + x_19) > ((12.0 + x_20) > (5.0 + x_21)? (12.0 + x_20) : (5.0 + x_21))? (16.0 + x_19) : ((12.0 + x_20) > (5.0 + x_21)? (12.0 + x_20) : (5.0 + x_21)))? ((19.0 + x_13) > ((18.0 + x_17) > (11.0 + x_18)? (18.0 + x_17) : (11.0 + x_18))? (19.0 + x_13) : ((18.0 + x_17) > (11.0 + x_18)? (18.0 + x_17) : (11.0 + x_18))) : ((16.0 + x_19) > ((12.0 + x_20) > (5.0 + x_21)? (12.0 + x_20) : (5.0 + x_21))? (16.0 + x_19) : ((12.0 + x_20) > (5.0 + x_21)? (12.0 + x_20) : (5.0 + x_21)))));
x_16_ = ((((4.0 + x_0) > ((11.0 + x_1) > (19.0 + x_2)? (11.0 + x_1) : (19.0 + x_2))? (4.0 + x_0) : ((11.0 + x_1) > (19.0 + x_2)? (11.0 + x_1) : (19.0 + x_2))) > ((2.0 + x_3) > ((10.0 + x_5) > (1.0 + x_7)? (10.0 + x_5) : (1.0 + x_7))? (2.0 + x_3) : ((10.0 + x_5) > (1.0 + x_7)? (10.0 + x_5) : (1.0 + x_7)))? ((4.0 + x_0) > ((11.0 + x_1) > (19.0 + x_2)? (11.0 + x_1) : (19.0 + x_2))? (4.0 + x_0) : ((11.0 + x_1) > (19.0 + x_2)? (11.0 + x_1) : (19.0 + x_2))) : ((2.0 + x_3) > ((10.0 + x_5) > (1.0 + x_7)? (10.0 + x_5) : (1.0 + x_7))? (2.0 + x_3) : ((10.0 + x_5) > (1.0 + x_7)? (10.0 + x_5) : (1.0 + x_7)))) > (((18.0 + x_11) > ((1.0 + x_12) > (8.0 + x_14)? (1.0 + x_12) : (8.0 + x_14))? (18.0 + x_11) : ((1.0 + x_12) > (8.0 + x_14)? (1.0 + x_12) : (8.0 + x_14))) > ((17.0 + x_19) > ((9.0 + x_22) > (11.0 + x_23)? (9.0 + x_22) : (11.0 + x_23))? (17.0 + x_19) : ((9.0 + x_22) > (11.0 + x_23)? (9.0 + x_22) : (11.0 + x_23)))? ((18.0 + x_11) > ((1.0 + x_12) > (8.0 + x_14)? (1.0 + x_12) : (8.0 + x_14))? (18.0 + x_11) : ((1.0 + x_12) > (8.0 + x_14)? (1.0 + x_12) : (8.0 + x_14))) : ((17.0 + x_19) > ((9.0 + x_22) > (11.0 + x_23)? (9.0 + x_22) : (11.0 + x_23))? (17.0 + x_19) : ((9.0 + x_22) > (11.0 + x_23)? (9.0 + x_22) : (11.0 + x_23))))? (((4.0 + x_0) > ((11.0 + x_1) > (19.0 + x_2)? (11.0 + x_1) : (19.0 + x_2))? (4.0 + x_0) : ((11.0 + x_1) > (19.0 + x_2)? (11.0 + x_1) : (19.0 + x_2))) > ((2.0 + x_3) > ((10.0 + x_5) > (1.0 + x_7)? (10.0 + x_5) : (1.0 + x_7))? (2.0 + x_3) : ((10.0 + x_5) > (1.0 + x_7)? (10.0 + x_5) : (1.0 + x_7)))? ((4.0 + x_0) > ((11.0 + x_1) > (19.0 + x_2)? (11.0 + x_1) : (19.0 + x_2))? (4.0 + x_0) : ((11.0 + x_1) > (19.0 + x_2)? (11.0 + x_1) : (19.0 + x_2))) : ((2.0 + x_3) > ((10.0 + x_5) > (1.0 + x_7)? (10.0 + x_5) : (1.0 + x_7))? (2.0 + x_3) : ((10.0 + x_5) > (1.0 + x_7)? (10.0 + x_5) : (1.0 + x_7)))) : (((18.0 + x_11) > ((1.0 + x_12) > (8.0 + x_14)? (1.0 + x_12) : (8.0 + x_14))? (18.0 + x_11) : ((1.0 + x_12) > (8.0 + x_14)? (1.0 + x_12) : (8.0 + x_14))) > ((17.0 + x_19) > ((9.0 + x_22) > (11.0 + x_23)? (9.0 + x_22) : (11.0 + x_23))? (17.0 + x_19) : ((9.0 + x_22) > (11.0 + x_23)? (9.0 + x_22) : (11.0 + x_23)))? ((18.0 + x_11) > ((1.0 + x_12) > (8.0 + x_14)? (1.0 + x_12) : (8.0 + x_14))? (18.0 + x_11) : ((1.0 + x_12) > (8.0 + x_14)? (1.0 + x_12) : (8.0 + x_14))) : ((17.0 + x_19) > ((9.0 + x_22) > (11.0 + x_23)? (9.0 + x_22) : (11.0 + x_23))? (17.0 + x_19) : ((9.0 + x_22) > (11.0 + x_23)? (9.0 + x_22) : (11.0 + x_23)))));
x_17_ = ((((7.0 + x_1) > ((8.0 + x_2) > (10.0 + x_3)? (8.0 + x_2) : (10.0 + x_3))? (7.0 + x_1) : ((8.0 + x_2) > (10.0 + x_3)? (8.0 + x_2) : (10.0 + x_3))) > ((18.0 + x_4) > ((14.0 + x_5) > (7.0 + x_8)? (14.0 + x_5) : (7.0 + x_8))? (18.0 + x_4) : ((14.0 + x_5) > (7.0 + x_8)? (14.0 + x_5) : (7.0 + x_8)))? ((7.0 + x_1) > ((8.0 + x_2) > (10.0 + x_3)? (8.0 + x_2) : (10.0 + x_3))? (7.0 + x_1) : ((8.0 + x_2) > (10.0 + x_3)? (8.0 + x_2) : (10.0 + x_3))) : ((18.0 + x_4) > ((14.0 + x_5) > (7.0 + x_8)? (14.0 + x_5) : (7.0 + x_8))? (18.0 + x_4) : ((14.0 + x_5) > (7.0 + x_8)? (14.0 + x_5) : (7.0 + x_8)))) > (((2.0 + x_9) > ((17.0 + x_10) > (1.0 + x_16)? (17.0 + x_10) : (1.0 + x_16))? (2.0 + x_9) : ((17.0 + x_10) > (1.0 + x_16)? (17.0 + x_10) : (1.0 + x_16))) > ((1.0 + x_17) > ((10.0 + x_18) > (1.0 + x_21)? (10.0 + x_18) : (1.0 + x_21))? (1.0 + x_17) : ((10.0 + x_18) > (1.0 + x_21)? (10.0 + x_18) : (1.0 + x_21)))? ((2.0 + x_9) > ((17.0 + x_10) > (1.0 + x_16)? (17.0 + x_10) : (1.0 + x_16))? (2.0 + x_9) : ((17.0 + x_10) > (1.0 + x_16)? (17.0 + x_10) : (1.0 + x_16))) : ((1.0 + x_17) > ((10.0 + x_18) > (1.0 + x_21)? (10.0 + x_18) : (1.0 + x_21))? (1.0 + x_17) : ((10.0 + x_18) > (1.0 + x_21)? (10.0 + x_18) : (1.0 + x_21))))? (((7.0 + x_1) > ((8.0 + x_2) > (10.0 + x_3)? (8.0 + x_2) : (10.0 + x_3))? (7.0 + x_1) : ((8.0 + x_2) > (10.0 + x_3)? (8.0 + x_2) : (10.0 + x_3))) > ((18.0 + x_4) > ((14.0 + x_5) > (7.0 + x_8)? (14.0 + x_5) : (7.0 + x_8))? (18.0 + x_4) : ((14.0 + x_5) > (7.0 + x_8)? (14.0 + x_5) : (7.0 + x_8)))? ((7.0 + x_1) > ((8.0 + x_2) > (10.0 + x_3)? (8.0 + x_2) : (10.0 + x_3))? (7.0 + x_1) : ((8.0 + x_2) > (10.0 + x_3)? (8.0 + x_2) : (10.0 + x_3))) : ((18.0 + x_4) > ((14.0 + x_5) > (7.0 + x_8)? (14.0 + x_5) : (7.0 + x_8))? (18.0 + x_4) : ((14.0 + x_5) > (7.0 + x_8)? (14.0 + x_5) : (7.0 + x_8)))) : (((2.0 + x_9) > ((17.0 + x_10) > (1.0 + x_16)? (17.0 + x_10) : (1.0 + x_16))? (2.0 + x_9) : ((17.0 + x_10) > (1.0 + x_16)? (17.0 + x_10) : (1.0 + x_16))) > ((1.0 + x_17) > ((10.0 + x_18) > (1.0 + x_21)? (10.0 + x_18) : (1.0 + x_21))? (1.0 + x_17) : ((10.0 + x_18) > (1.0 + x_21)? (10.0 + x_18) : (1.0 + x_21)))? ((2.0 + x_9) > ((17.0 + x_10) > (1.0 + x_16)? (17.0 + x_10) : (1.0 + x_16))? (2.0 + x_9) : ((17.0 + x_10) > (1.0 + x_16)? (17.0 + x_10) : (1.0 + x_16))) : ((1.0 + x_17) > ((10.0 + x_18) > (1.0 + x_21)? (10.0 + x_18) : (1.0 + x_21))? (1.0 + x_17) : ((10.0 + x_18) > (1.0 + x_21)? (10.0 + x_18) : (1.0 + x_21)))));
x_18_ = ((((5.0 + x_1) > ((8.0 + x_5) > (13.0 + x_8)? (8.0 + x_5) : (13.0 + x_8))? (5.0 + x_1) : ((8.0 + x_5) > (13.0 + x_8)? (8.0 + x_5) : (13.0 + x_8))) > ((3.0 + x_11) > ((8.0 + x_12) > (7.0 + x_13)? (8.0 + x_12) : (7.0 + x_13))? (3.0 + x_11) : ((8.0 + x_12) > (7.0 + x_13)? (8.0 + x_12) : (7.0 + x_13)))? ((5.0 + x_1) > ((8.0 + x_5) > (13.0 + x_8)? (8.0 + x_5) : (13.0 + x_8))? (5.0 + x_1) : ((8.0 + x_5) > (13.0 + x_8)? (8.0 + x_5) : (13.0 + x_8))) : ((3.0 + x_11) > ((8.0 + x_12) > (7.0 + x_13)? (8.0 + x_12) : (7.0 + x_13))? (3.0 + x_11) : ((8.0 + x_12) > (7.0 + x_13)? (8.0 + x_12) : (7.0 + x_13)))) > (((8.0 + x_15) > ((20.0 + x_18) > (1.0 + x_19)? (20.0 + x_18) : (1.0 + x_19))? (8.0 + x_15) : ((20.0 + x_18) > (1.0 + x_19)? (20.0 + x_18) : (1.0 + x_19))) > ((3.0 + x_21) > ((10.0 + x_22) > (18.0 + x_23)? (10.0 + x_22) : (18.0 + x_23))? (3.0 + x_21) : ((10.0 + x_22) > (18.0 + x_23)? (10.0 + x_22) : (18.0 + x_23)))? ((8.0 + x_15) > ((20.0 + x_18) > (1.0 + x_19)? (20.0 + x_18) : (1.0 + x_19))? (8.0 + x_15) : ((20.0 + x_18) > (1.0 + x_19)? (20.0 + x_18) : (1.0 + x_19))) : ((3.0 + x_21) > ((10.0 + x_22) > (18.0 + x_23)? (10.0 + x_22) : (18.0 + x_23))? (3.0 + x_21) : ((10.0 + x_22) > (18.0 + x_23)? (10.0 + x_22) : (18.0 + x_23))))? (((5.0 + x_1) > ((8.0 + x_5) > (13.0 + x_8)? (8.0 + x_5) : (13.0 + x_8))? (5.0 + x_1) : ((8.0 + x_5) > (13.0 + x_8)? (8.0 + x_5) : (13.0 + x_8))) > ((3.0 + x_11) > ((8.0 + x_12) > (7.0 + x_13)? (8.0 + x_12) : (7.0 + x_13))? (3.0 + x_11) : ((8.0 + x_12) > (7.0 + x_13)? (8.0 + x_12) : (7.0 + x_13)))? ((5.0 + x_1) > ((8.0 + x_5) > (13.0 + x_8)? (8.0 + x_5) : (13.0 + x_8))? (5.0 + x_1) : ((8.0 + x_5) > (13.0 + x_8)? (8.0 + x_5) : (13.0 + x_8))) : ((3.0 + x_11) > ((8.0 + x_12) > (7.0 + x_13)? (8.0 + x_12) : (7.0 + x_13))? (3.0 + x_11) : ((8.0 + x_12) > (7.0 + x_13)? (8.0 + x_12) : (7.0 + x_13)))) : (((8.0 + x_15) > ((20.0 + x_18) > (1.0 + x_19)? (20.0 + x_18) : (1.0 + x_19))? (8.0 + x_15) : ((20.0 + x_18) > (1.0 + x_19)? (20.0 + x_18) : (1.0 + x_19))) > ((3.0 + x_21) > ((10.0 + x_22) > (18.0 + x_23)? (10.0 + x_22) : (18.0 + x_23))? (3.0 + x_21) : ((10.0 + x_22) > (18.0 + x_23)? (10.0 + x_22) : (18.0 + x_23)))? ((8.0 + x_15) > ((20.0 + x_18) > (1.0 + x_19)? (20.0 + x_18) : (1.0 + x_19))? (8.0 + x_15) : ((20.0 + x_18) > (1.0 + x_19)? (20.0 + x_18) : (1.0 + x_19))) : ((3.0 + x_21) > ((10.0 + x_22) > (18.0 + x_23)? (10.0 + x_22) : (18.0 + x_23))? (3.0 + x_21) : ((10.0 + x_22) > (18.0 + x_23)? (10.0 + x_22) : (18.0 + x_23)))));
x_19_ = ((((15.0 + x_0) > ((5.0 + x_3) > (13.0 + x_4)? (5.0 + x_3) : (13.0 + x_4))? (15.0 + x_0) : ((5.0 + x_3) > (13.0 + x_4)? (5.0 + x_3) : (13.0 + x_4))) > ((15.0 + x_6) > ((9.0 + x_7) > (9.0 + x_9)? (9.0 + x_7) : (9.0 + x_9))? (15.0 + x_6) : ((9.0 + x_7) > (9.0 + x_9)? (9.0 + x_7) : (9.0 + x_9)))? ((15.0 + x_0) > ((5.0 + x_3) > (13.0 + x_4)? (5.0 + x_3) : (13.0 + x_4))? (15.0 + x_0) : ((5.0 + x_3) > (13.0 + x_4)? (5.0 + x_3) : (13.0 + x_4))) : ((15.0 + x_6) > ((9.0 + x_7) > (9.0 + x_9)? (9.0 + x_7) : (9.0 + x_9))? (15.0 + x_6) : ((9.0 + x_7) > (9.0 + x_9)? (9.0 + x_7) : (9.0 + x_9)))) > (((2.0 + x_10) > ((12.0 + x_14) > (2.0 + x_15)? (12.0 + x_14) : (2.0 + x_15))? (2.0 + x_10) : ((12.0 + x_14) > (2.0 + x_15)? (12.0 + x_14) : (2.0 + x_15))) > ((1.0 + x_16) > ((7.0 + x_18) > (11.0 + x_21)? (7.0 + x_18) : (11.0 + x_21))? (1.0 + x_16) : ((7.0 + x_18) > (11.0 + x_21)? (7.0 + x_18) : (11.0 + x_21)))? ((2.0 + x_10) > ((12.0 + x_14) > (2.0 + x_15)? (12.0 + x_14) : (2.0 + x_15))? (2.0 + x_10) : ((12.0 + x_14) > (2.0 + x_15)? (12.0 + x_14) : (2.0 + x_15))) : ((1.0 + x_16) > ((7.0 + x_18) > (11.0 + x_21)? (7.0 + x_18) : (11.0 + x_21))? (1.0 + x_16) : ((7.0 + x_18) > (11.0 + x_21)? (7.0 + x_18) : (11.0 + x_21))))? (((15.0 + x_0) > ((5.0 + x_3) > (13.0 + x_4)? (5.0 + x_3) : (13.0 + x_4))? (15.0 + x_0) : ((5.0 + x_3) > (13.0 + x_4)? (5.0 + x_3) : (13.0 + x_4))) > ((15.0 + x_6) > ((9.0 + x_7) > (9.0 + x_9)? (9.0 + x_7) : (9.0 + x_9))? (15.0 + x_6) : ((9.0 + x_7) > (9.0 + x_9)? (9.0 + x_7) : (9.0 + x_9)))? ((15.0 + x_0) > ((5.0 + x_3) > (13.0 + x_4)? (5.0 + x_3) : (13.0 + x_4))? (15.0 + x_0) : ((5.0 + x_3) > (13.0 + x_4)? (5.0 + x_3) : (13.0 + x_4))) : ((15.0 + x_6) > ((9.0 + x_7) > (9.0 + x_9)? (9.0 + x_7) : (9.0 + x_9))? (15.0 + x_6) : ((9.0 + x_7) > (9.0 + x_9)? (9.0 + x_7) : (9.0 + x_9)))) : (((2.0 + x_10) > ((12.0 + x_14) > (2.0 + x_15)? (12.0 + x_14) : (2.0 + x_15))? (2.0 + x_10) : ((12.0 + x_14) > (2.0 + x_15)? (12.0 + x_14) : (2.0 + x_15))) > ((1.0 + x_16) > ((7.0 + x_18) > (11.0 + x_21)? (7.0 + x_18) : (11.0 + x_21))? (1.0 + x_16) : ((7.0 + x_18) > (11.0 + x_21)? (7.0 + x_18) : (11.0 + x_21)))? ((2.0 + x_10) > ((12.0 + x_14) > (2.0 + x_15)? (12.0 + x_14) : (2.0 + x_15))? (2.0 + x_10) : ((12.0 + x_14) > (2.0 + x_15)? (12.0 + x_14) : (2.0 + x_15))) : ((1.0 + x_16) > ((7.0 + x_18) > (11.0 + x_21)? (7.0 + x_18) : (11.0 + x_21))? (1.0 + x_16) : ((7.0 + x_18) > (11.0 + x_21)? (7.0 + x_18) : (11.0 + x_21)))));
x_20_ = ((((19.0 + x_0) > ((7.0 + x_1) > (20.0 + x_9)? (7.0 + x_1) : (20.0 + x_9))? (19.0 + x_0) : ((7.0 + x_1) > (20.0 + x_9)? (7.0 + x_1) : (20.0 + x_9))) > ((13.0 + x_10) > ((12.0 + x_11) > (9.0 + x_12)? (12.0 + x_11) : (9.0 + x_12))? (13.0 + x_10) : ((12.0 + x_11) > (9.0 + x_12)? (12.0 + x_11) : (9.0 + x_12)))? ((19.0 + x_0) > ((7.0 + x_1) > (20.0 + x_9)? (7.0 + x_1) : (20.0 + x_9))? (19.0 + x_0) : ((7.0 + x_1) > (20.0 + x_9)? (7.0 + x_1) : (20.0 + x_9))) : ((13.0 + x_10) > ((12.0 + x_11) > (9.0 + x_12)? (12.0 + x_11) : (9.0 + x_12))? (13.0 + x_10) : ((12.0 + x_11) > (9.0 + x_12)? (12.0 + x_11) : (9.0 + x_12)))) > (((16.0 + x_13) > ((13.0 + x_15) > (4.0 + x_17)? (13.0 + x_15) : (4.0 + x_17))? (16.0 + x_13) : ((13.0 + x_15) > (4.0 + x_17)? (13.0 + x_15) : (4.0 + x_17))) > ((2.0 + x_18) > ((12.0 + x_19) > (11.0 + x_22)? (12.0 + x_19) : (11.0 + x_22))? (2.0 + x_18) : ((12.0 + x_19) > (11.0 + x_22)? (12.0 + x_19) : (11.0 + x_22)))? ((16.0 + x_13) > ((13.0 + x_15) > (4.0 + x_17)? (13.0 + x_15) : (4.0 + x_17))? (16.0 + x_13) : ((13.0 + x_15) > (4.0 + x_17)? (13.0 + x_15) : (4.0 + x_17))) : ((2.0 + x_18) > ((12.0 + x_19) > (11.0 + x_22)? (12.0 + x_19) : (11.0 + x_22))? (2.0 + x_18) : ((12.0 + x_19) > (11.0 + x_22)? (12.0 + x_19) : (11.0 + x_22))))? (((19.0 + x_0) > ((7.0 + x_1) > (20.0 + x_9)? (7.0 + x_1) : (20.0 + x_9))? (19.0 + x_0) : ((7.0 + x_1) > (20.0 + x_9)? (7.0 + x_1) : (20.0 + x_9))) > ((13.0 + x_10) > ((12.0 + x_11) > (9.0 + x_12)? (12.0 + x_11) : (9.0 + x_12))? (13.0 + x_10) : ((12.0 + x_11) > (9.0 + x_12)? (12.0 + x_11) : (9.0 + x_12)))? ((19.0 + x_0) > ((7.0 + x_1) > (20.0 + x_9)? (7.0 + x_1) : (20.0 + x_9))? (19.0 + x_0) : ((7.0 + x_1) > (20.0 + x_9)? (7.0 + x_1) : (20.0 + x_9))) : ((13.0 + x_10) > ((12.0 + x_11) > (9.0 + x_12)? (12.0 + x_11) : (9.0 + x_12))? (13.0 + x_10) : ((12.0 + x_11) > (9.0 + x_12)? (12.0 + x_11) : (9.0 + x_12)))) : (((16.0 + x_13) > ((13.0 + x_15) > (4.0 + x_17)? (13.0 + x_15) : (4.0 + x_17))? (16.0 + x_13) : ((13.0 + x_15) > (4.0 + x_17)? (13.0 + x_15) : (4.0 + x_17))) > ((2.0 + x_18) > ((12.0 + x_19) > (11.0 + x_22)? (12.0 + x_19) : (11.0 + x_22))? (2.0 + x_18) : ((12.0 + x_19) > (11.0 + x_22)? (12.0 + x_19) : (11.0 + x_22)))? ((16.0 + x_13) > ((13.0 + x_15) > (4.0 + x_17)? (13.0 + x_15) : (4.0 + x_17))? (16.0 + x_13) : ((13.0 + x_15) > (4.0 + x_17)? (13.0 + x_15) : (4.0 + x_17))) : ((2.0 + x_18) > ((12.0 + x_19) > (11.0 + x_22)? (12.0 + x_19) : (11.0 + x_22))? (2.0 + x_18) : ((12.0 + x_19) > (11.0 + x_22)? (12.0 + x_19) : (11.0 + x_22)))));
x_21_ = ((((6.0 + x_0) > ((19.0 + x_6) > (5.0 + x_9)? (19.0 + x_6) : (5.0 + x_9))? (6.0 + x_0) : ((19.0 + x_6) > (5.0 + x_9)? (19.0 + x_6) : (5.0 + x_9))) > ((13.0 + x_10) > ((12.0 + x_13) > (5.0 + x_14)? (12.0 + x_13) : (5.0 + x_14))? (13.0 + x_10) : ((12.0 + x_13) > (5.0 + x_14)? (12.0 + x_13) : (5.0 + x_14)))? ((6.0 + x_0) > ((19.0 + x_6) > (5.0 + x_9)? (19.0 + x_6) : (5.0 + x_9))? (6.0 + x_0) : ((19.0 + x_6) > (5.0 + x_9)? (19.0 + x_6) : (5.0 + x_9))) : ((13.0 + x_10) > ((12.0 + x_13) > (5.0 + x_14)? (12.0 + x_13) : (5.0 + x_14))? (13.0 + x_10) : ((12.0 + x_13) > (5.0 + x_14)? (12.0 + x_13) : (5.0 + x_14)))) > (((5.0 + x_15) > ((13.0 + x_16) > (2.0 + x_17)? (13.0 + x_16) : (2.0 + x_17))? (5.0 + x_15) : ((13.0 + x_16) > (2.0 + x_17)? (13.0 + x_16) : (2.0 + x_17))) > ((7.0 + x_20) > ((11.0 + x_21) > (12.0 + x_22)? (11.0 + x_21) : (12.0 + x_22))? (7.0 + x_20) : ((11.0 + x_21) > (12.0 + x_22)? (11.0 + x_21) : (12.0 + x_22)))? ((5.0 + x_15) > ((13.0 + x_16) > (2.0 + x_17)? (13.0 + x_16) : (2.0 + x_17))? (5.0 + x_15) : ((13.0 + x_16) > (2.0 + x_17)? (13.0 + x_16) : (2.0 + x_17))) : ((7.0 + x_20) > ((11.0 + x_21) > (12.0 + x_22)? (11.0 + x_21) : (12.0 + x_22))? (7.0 + x_20) : ((11.0 + x_21) > (12.0 + x_22)? (11.0 + x_21) : (12.0 + x_22))))? (((6.0 + x_0) > ((19.0 + x_6) > (5.0 + x_9)? (19.0 + x_6) : (5.0 + x_9))? (6.0 + x_0) : ((19.0 + x_6) > (5.0 + x_9)? (19.0 + x_6) : (5.0 + x_9))) > ((13.0 + x_10) > ((12.0 + x_13) > (5.0 + x_14)? (12.0 + x_13) : (5.0 + x_14))? (13.0 + x_10) : ((12.0 + x_13) > (5.0 + x_14)? (12.0 + x_13) : (5.0 + x_14)))? ((6.0 + x_0) > ((19.0 + x_6) > (5.0 + x_9)? (19.0 + x_6) : (5.0 + x_9))? (6.0 + x_0) : ((19.0 + x_6) > (5.0 + x_9)? (19.0 + x_6) : (5.0 + x_9))) : ((13.0 + x_10) > ((12.0 + x_13) > (5.0 + x_14)? (12.0 + x_13) : (5.0 + x_14))? (13.0 + x_10) : ((12.0 + x_13) > (5.0 + x_14)? (12.0 + x_13) : (5.0 + x_14)))) : (((5.0 + x_15) > ((13.0 + x_16) > (2.0 + x_17)? (13.0 + x_16) : (2.0 + x_17))? (5.0 + x_15) : ((13.0 + x_16) > (2.0 + x_17)? (13.0 + x_16) : (2.0 + x_17))) > ((7.0 + x_20) > ((11.0 + x_21) > (12.0 + x_22)? (11.0 + x_21) : (12.0 + x_22))? (7.0 + x_20) : ((11.0 + x_21) > (12.0 + x_22)? (11.0 + x_21) : (12.0 + x_22)))? ((5.0 + x_15) > ((13.0 + x_16) > (2.0 + x_17)? (13.0 + x_16) : (2.0 + x_17))? (5.0 + x_15) : ((13.0 + x_16) > (2.0 + x_17)? (13.0 + x_16) : (2.0 + x_17))) : ((7.0 + x_20) > ((11.0 + x_21) > (12.0 + x_22)? (11.0 + x_21) : (12.0 + x_22))? (7.0 + x_20) : ((11.0 + x_21) > (12.0 + x_22)? (11.0 + x_21) : (12.0 + x_22)))));
x_22_ = ((((7.0 + x_3) > ((11.0 + x_6) > (7.0 + x_9)? (11.0 + x_6) : (7.0 + x_9))? (7.0 + x_3) : ((11.0 + x_6) > (7.0 + x_9)? (11.0 + x_6) : (7.0 + x_9))) > ((15.0 + x_11) > ((5.0 + x_12) > (2.0 + x_13)? (5.0 + x_12) : (2.0 + x_13))? (15.0 + x_11) : ((5.0 + x_12) > (2.0 + x_13)? (5.0 + x_12) : (2.0 + x_13)))? ((7.0 + x_3) > ((11.0 + x_6) > (7.0 + x_9)? (11.0 + x_6) : (7.0 + x_9))? (7.0 + x_3) : ((11.0 + x_6) > (7.0 + x_9)? (11.0 + x_6) : (7.0 + x_9))) : ((15.0 + x_11) > ((5.0 + x_12) > (2.0 + x_13)? (5.0 + x_12) : (2.0 + x_13))? (15.0 + x_11) : ((5.0 + x_12) > (2.0 + x_13)? (5.0 + x_12) : (2.0 + x_13)))) > (((12.0 + x_15) > ((13.0 + x_16) > (9.0 + x_19)? (13.0 + x_16) : (9.0 + x_19))? (12.0 + x_15) : ((13.0 + x_16) > (9.0 + x_19)? (13.0 + x_16) : (9.0 + x_19))) > ((3.0 + x_21) > ((16.0 + x_22) > (16.0 + x_23)? (16.0 + x_22) : (16.0 + x_23))? (3.0 + x_21) : ((16.0 + x_22) > (16.0 + x_23)? (16.0 + x_22) : (16.0 + x_23)))? ((12.0 + x_15) > ((13.0 + x_16) > (9.0 + x_19)? (13.0 + x_16) : (9.0 + x_19))? (12.0 + x_15) : ((13.0 + x_16) > (9.0 + x_19)? (13.0 + x_16) : (9.0 + x_19))) : ((3.0 + x_21) > ((16.0 + x_22) > (16.0 + x_23)? (16.0 + x_22) : (16.0 + x_23))? (3.0 + x_21) : ((16.0 + x_22) > (16.0 + x_23)? (16.0 + x_22) : (16.0 + x_23))))? (((7.0 + x_3) > ((11.0 + x_6) > (7.0 + x_9)? (11.0 + x_6) : (7.0 + x_9))? (7.0 + x_3) : ((11.0 + x_6) > (7.0 + x_9)? (11.0 + x_6) : (7.0 + x_9))) > ((15.0 + x_11) > ((5.0 + x_12) > (2.0 + x_13)? (5.0 + x_12) : (2.0 + x_13))? (15.0 + x_11) : ((5.0 + x_12) > (2.0 + x_13)? (5.0 + x_12) : (2.0 + x_13)))? ((7.0 + x_3) > ((11.0 + x_6) > (7.0 + x_9)? (11.0 + x_6) : (7.0 + x_9))? (7.0 + x_3) : ((11.0 + x_6) > (7.0 + x_9)? (11.0 + x_6) : (7.0 + x_9))) : ((15.0 + x_11) > ((5.0 + x_12) > (2.0 + x_13)? (5.0 + x_12) : (2.0 + x_13))? (15.0 + x_11) : ((5.0 + x_12) > (2.0 + x_13)? (5.0 + x_12) : (2.0 + x_13)))) : (((12.0 + x_15) > ((13.0 + x_16) > (9.0 + x_19)? (13.0 + x_16) : (9.0 + x_19))? (12.0 + x_15) : ((13.0 + x_16) > (9.0 + x_19)? (13.0 + x_16) : (9.0 + x_19))) > ((3.0 + x_21) > ((16.0 + x_22) > (16.0 + x_23)? (16.0 + x_22) : (16.0 + x_23))? (3.0 + x_21) : ((16.0 + x_22) > (16.0 + x_23)? (16.0 + x_22) : (16.0 + x_23)))? ((12.0 + x_15) > ((13.0 + x_16) > (9.0 + x_19)? (13.0 + x_16) : (9.0 + x_19))? (12.0 + x_15) : ((13.0 + x_16) > (9.0 + x_19)? (13.0 + x_16) : (9.0 + x_19))) : ((3.0 + x_21) > ((16.0 + x_22) > (16.0 + x_23)? (16.0 + x_22) : (16.0 + x_23))? (3.0 + x_21) : ((16.0 + x_22) > (16.0 + x_23)? (16.0 + x_22) : (16.0 + x_23)))));
x_23_ = ((((7.0 + x_1) > ((11.0 + x_2) > (7.0 + x_5)? (11.0 + x_2) : (7.0 + x_5))? (7.0 + x_1) : ((11.0 + x_2) > (7.0 + x_5)? (11.0 + x_2) : (7.0 + x_5))) > ((7.0 + x_6) > ((4.0 + x_7) > (8.0 + x_9)? (4.0 + x_7) : (8.0 + x_9))? (7.0 + x_6) : ((4.0 + x_7) > (8.0 + x_9)? (4.0 + x_7) : (8.0 + x_9)))? ((7.0 + x_1) > ((11.0 + x_2) > (7.0 + x_5)? (11.0 + x_2) : (7.0 + x_5))? (7.0 + x_1) : ((11.0 + x_2) > (7.0 + x_5)? (11.0 + x_2) : (7.0 + x_5))) : ((7.0 + x_6) > ((4.0 + x_7) > (8.0 + x_9)? (4.0 + x_7) : (8.0 + x_9))? (7.0 + x_6) : ((4.0 + x_7) > (8.0 + x_9)? (4.0 + x_7) : (8.0 + x_9)))) > (((17.0 + x_11) > ((12.0 + x_17) > (19.0 + x_18)? (12.0 + x_17) : (19.0 + x_18))? (17.0 + x_11) : ((12.0 + x_17) > (19.0 + x_18)? (12.0 + x_17) : (19.0 + x_18))) > ((13.0 + x_19) > ((8.0 + x_22) > (12.0 + x_23)? (8.0 + x_22) : (12.0 + x_23))? (13.0 + x_19) : ((8.0 + x_22) > (12.0 + x_23)? (8.0 + x_22) : (12.0 + x_23)))? ((17.0 + x_11) > ((12.0 + x_17) > (19.0 + x_18)? (12.0 + x_17) : (19.0 + x_18))? (17.0 + x_11) : ((12.0 + x_17) > (19.0 + x_18)? (12.0 + x_17) : (19.0 + x_18))) : ((13.0 + x_19) > ((8.0 + x_22) > (12.0 + x_23)? (8.0 + x_22) : (12.0 + x_23))? (13.0 + x_19) : ((8.0 + x_22) > (12.0 + x_23)? (8.0 + x_22) : (12.0 + x_23))))? (((7.0 + x_1) > ((11.0 + x_2) > (7.0 + x_5)? (11.0 + x_2) : (7.0 + x_5))? (7.0 + x_1) : ((11.0 + x_2) > (7.0 + x_5)? (11.0 + x_2) : (7.0 + x_5))) > ((7.0 + x_6) > ((4.0 + x_7) > (8.0 + x_9)? (4.0 + x_7) : (8.0 + x_9))? (7.0 + x_6) : ((4.0 + x_7) > (8.0 + x_9)? (4.0 + x_7) : (8.0 + x_9)))? ((7.0 + x_1) > ((11.0 + x_2) > (7.0 + x_5)? (11.0 + x_2) : (7.0 + x_5))? (7.0 + x_1) : ((11.0 + x_2) > (7.0 + x_5)? (11.0 + x_2) : (7.0 + x_5))) : ((7.0 + x_6) > ((4.0 + x_7) > (8.0 + x_9)? (4.0 + x_7) : (8.0 + x_9))? (7.0 + x_6) : ((4.0 + x_7) > (8.0 + x_9)? (4.0 + x_7) : (8.0 + x_9)))) : (((17.0 + x_11) > ((12.0 + x_17) > (19.0 + x_18)? (12.0 + x_17) : (19.0 + x_18))? (17.0 + x_11) : ((12.0 + x_17) > (19.0 + x_18)? (12.0 + x_17) : (19.0 + x_18))) > ((13.0 + x_19) > ((8.0 + x_22) > (12.0 + x_23)? (8.0 + x_22) : (12.0 + x_23))? (13.0 + x_19) : ((8.0 + x_22) > (12.0 + x_23)? (8.0 + x_22) : (12.0 + x_23)))? ((17.0 + x_11) > ((12.0 + x_17) > (19.0 + x_18)? (12.0 + x_17) : (19.0 + x_18))? (17.0 + x_11) : ((12.0 + x_17) > (19.0 + x_18)? (12.0 + x_17) : (19.0 + x_18))) : ((13.0 + x_19) > ((8.0 + x_22) > (12.0 + x_23)? (8.0 + x_22) : (12.0 + x_23))? (13.0 + x_19) : ((8.0 + x_22) > (12.0 + x_23)? (8.0 + x_22) : (12.0 + x_23)))));
x_0 = x_0_;
x_1 = x_1_;
x_2 = x_2_;
x_3 = x_3_;
x_4 = x_4_;
x_5 = x_5_;
x_6 = x_6_;
x_7 = x_7_;
x_8 = x_8_;
x_9 = x_9_;
x_10 = x_10_;
x_11 = x_11_;
x_12 = x_12_;
x_13 = x_13_;
x_14 = x_14_;
x_15 = x_15_;
x_16 = x_16_;
x_17 = x_17_;
x_18 = x_18_;
x_19 = x_19_;
x_20 = x_20_;
x_21 = x_21_;
x_22 = x_22_;
x_23 = x_23_;
}
return 0;
}
|
the_stack_data/45637.c
|
#include <stdio.h>
#include <stdlib.h>
#define MAX 40
int main(void) {
FILE *fp;
char words[MAX];
char new_words[MAX + 1];
int n = 1;
if ((fp = fopen("wordy", "a+")) == NULL) {
fprintf(stdout,"Can't open \"words\" file.\n");
exit(1);
}
puts("Enter words to add to the file; press the Enter");
puts("key at the beginning of a line to terminate.");
while (gets(words) != 0 && words[0] != '\0') {
fprintf(fp, "%d:", n);
fprintf(fp, "%s ", words);
n++;
}
puts("File contents:");
rewind(fp);
n = 1;
while (fscanf(fp, "%s", words) == 1) {
puts(words);
n++;
}
if (fclose(fp) != 0)
fprintf(stderr,"Error closing file\n");
return 0;
}
|
the_stack_data/82437.c
|
#include <signal.h>
int
main(void)
{
raise(SIGTERM);
return 0;
}
|
the_stack_data/115765017.c
|
/**
* Write a PPM image-file.
*
* From RosettaCode:
* http://rosettacode.org/wiki/Category:C
*/
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
const int dimx = 800, dimy = 800;
int i, j;
FILE *imageFile = fopen("c.ppm", "wb"); /* b - binary mode */
(void) fprintf(imageFile, "P6\n%d %d\n255\n", dimx, dimy);
for (j = 0; j < dimy; ++j)
{
for (i = 0; i < dimx; ++i)
{
static unsigned char color[3];
color[0] = i % 256; /* red */
color[1] = j % 256; /* green */
color[2] = (i * j) % 256; /* blue */
(void) fwrite(color, 1, 3, imageFile);
}
}
(void) fclose(imageFile);
return EXIT_SUCCESS;
}
|
the_stack_data/122016435.c
|
#include <assert.h>
#include <stdbool.h>
void test_int() {
volatile int a = 1;
int result = __sync_val_compare_and_swap(&a, 1, 6);
assert(a == 6);
assert(result == 1);
result = __sync_val_compare_and_swap(&a, 123, 8);
assert(a == 6);
assert(result == 6);
}
void test_long() {
volatile long a = 1;
long result = __sync_val_compare_and_swap(&a, 1, 6);
assert(a == 6);
assert(result == 1);
result = __sync_val_compare_and_swap(&a, 123, 8);
assert(a == 6);
assert(result == 6);
}
void test_longlong() {
volatile long long a = 1;
long result = __sync_val_compare_and_swap(&a, 1, 6);
assert(a == 6);
assert(result == 1);
result = __sync_val_compare_and_swap(&a, 123, 8);
assert(a == 6);
assert(result == 6);
}
int main() {
test_int();
test_long();
test_longlong();
return 0;
}
|
the_stack_data/547575.c
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -debug-info-kind=limited -o - %s | \
// RUN: FileCheck %s -check-prefix=CHECK -check-prefix=SSE -check-prefix=NO-AVX512
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -debug-info-kind=limited -o - %s -target-feature +avx | \
// RUN: FileCheck %s -check-prefix=CHECK -check-prefix=AVX -check-prefix=NO-AVX512
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -debug-info-kind=limited -o - %s -target-feature +avx512f | \
// RUN: FileCheck %s -check-prefix=CHECK -check-prefix=AVX -check-prefix=AVX512
#include <stdarg.h>
// CHECK-LABEL: define{{.*}} signext i8 @f0()
char f0(void) {
return 0;
}
// CHECK-LABEL: define{{.*}} signext i16 @f1()
short f1(void) {
return 0;
}
// CHECK-LABEL: define{{.*}} i32 @f2()
int f2(void) {
return 0;
}
// CHECK-LABEL: define{{.*}} float @f3()
float f3(void) {
return 0;
}
// CHECK-LABEL: define{{.*}} double @f4()
double f4(void) {
return 0;
}
// CHECK-LABEL: define{{.*}} x86_fp80 @f5()
long double f5(void) {
return 0;
}
// CHECK-LABEL: define{{.*}} void @f6(i8 noundef signext %a0, i16 noundef signext %a1, i32 noundef %a2, i64 noundef %a3, i8* noundef %a4)
void f6(char a0, short a1, int a2, long long a3, void *a4) {
}
// CHECK-LABEL: define{{.*}} void @f7(i32 noundef %a0)
typedef enum { A, B, C } e7;
void f7(e7 a0) {
}
// Test merging/passing of upper eightbyte with X87 class.
//
// CHECK-LABEL: define{{.*}} void @f8_1(%union.u8* noalias sret(%union.u8) align 16 %agg.result)
// CHECK-LABEL: define{{.*}} void @f8_2(%union.u8* noundef byval(%union.u8) align 16 %a0)
union u8 {
long double a;
int b;
};
union u8 f8_1(void) { while (1) {} }
void f8_2(union u8 a0) {}
// CHECK-LABEL: define{{.*}} i64 @f9()
struct s9 { int a; int b; int : 0; } f9(void) { while (1) {} }
// CHECK-LABEL: define{{.*}} void @f10(i64 %a0.coerce)
struct s10 { int a; int b; int : 0; };
void f10(struct s10 a0) {}
// CHECK-LABEL: define{{.*}} void @f11(%union.anon* noalias sret(%union.anon) align 16 %agg.result)
union { long double a; float b; } f11(void) { while (1) {} }
// CHECK-LABEL: define{{.*}} i32 @f12_0()
// CHECK-LABEL: define{{.*}} void @f12_1(i32 %a0.coerce)
struct s12 { int a __attribute__((aligned(16))); };
struct s12 f12_0(void) { while (1) {} }
void f12_1(struct s12 a0) {}
// Check that sret parameter is accounted for when checking available integer
// registers.
// CHECK: define{{.*}} void @f13(%struct.s13_0* noalias sret(%struct.s13_0) align 8 %agg.result, i32 noundef %a, i32 noundef %b, i32 noundef %c, i32 noundef %d, {{.*}}* noundef byval({{.*}}) align 8 %e, i32 noundef %f)
struct s13_0 { long long f0[3]; };
struct s13_1 { long long f0[2]; };
struct s13_0 f13(int a, int b, int c, int d,
struct s13_1 e, int f) { while (1) {} }
// CHECK: define{{.*}} void @f14({{.*}}, i8 noundef signext %X)
void f14(int a, int b, int c, int d, int e, int f, char X) {}
// CHECK: define{{.*}} void @f15({{.*}}, i8* noundef %X)
void f15(int a, int b, int c, int d, int e, int f, void *X) {}
// CHECK: define{{.*}} void @f16({{.*}}, float noundef %X)
void f16(float a, float b, float c, float d, float e, float f, float g, float h,
float X) {}
// CHECK: define{{.*}} void @f17({{.*}}, x86_fp80 noundef %X)
void f17(float a, float b, float c, float d, float e, float f, float g, float h,
long double X) {}
// Check for valid coercion. The struct should be passed/returned as i32, not
// as i64 for better code quality.
// rdar://8135035
// CHECK-LABEL: define{{.*}} void @f18(i32 noundef %a, i32 %f18_arg1.coerce)
struct f18_s0 { int f0; };
void f18(int a, struct f18_s0 f18_arg1) { while (1) {} }
// Check byval alignment.
// CHECK-LABEL: define{{.*}} void @f19(%struct.s19* noundef byval(%struct.s19) align 16 %x)
struct s19 {
long double a;
};
void f19(struct s19 x) {}
// CHECK-LABEL: define{{.*}} void @f20(%struct.s20* noundef byval(%struct.s20) align 32 %x)
struct __attribute__((aligned(32))) s20 {
int x;
int y;
};
void f20(struct s20 x) {}
struct StringRef {
long x;
const char *Ptr;
};
// rdar://7375902
// CHECK-LABEL: define{{.*}} i8* @f21(i64 %S.coerce0, i8* %S.coerce1)
const char *f21(struct StringRef S) { return S.x+S.Ptr; }
// PR7567
typedef __attribute__ ((aligned(16))) struct f22s { unsigned long long x[2]; } L;
void f22(L x, L y) { }
// CHECK: @f22
// CHECK: %x = alloca{{.*}}, align 16
// CHECK: %y = alloca{{.*}}, align 16
// PR7714
struct f23S {
short f0;
unsigned f1;
int f2;
};
void f23(int A, struct f23S B) {
// CHECK-LABEL: define{{.*}} void @f23(i32 noundef %A, i64 %B.coerce0, i32 %B.coerce1)
}
struct f24s { long a; int b; };
struct f23S f24(struct f23S *X, struct f24s *P2) {
return *X;
// CHECK: define{{.*}} { i64, i32 } @f24(%struct.f23S* noundef %X, %struct.f24s* noundef %P2)
}
// rdar://8248065
typedef float v4f32 __attribute__((__vector_size__(16)));
v4f32 f25(v4f32 X) {
// CHECK-LABEL: define{{.*}} <4 x float> @f25(<4 x float> noundef %X)
// CHECK-NOT: alloca
// CHECK: alloca <4 x float>
// CHECK-NOT: alloca
// CHECK: store <4 x float> %X, <4 x float>*
// CHECK-NOT: store
// CHECK: ret <4 x float>
return X+X;
}
struct foo26 {
int *X;
float *Y;
};
struct foo26 f26(struct foo26 *P) {
// CHECK: define{{.*}} { i32*, float* } @f26(%struct.foo26* noundef %P)
return *P;
}
struct v4f32wrapper {
v4f32 v;
};
struct v4f32wrapper f27(struct v4f32wrapper X) {
// CHECK-LABEL: define{{.*}} <4 x float> @f27(<4 x float> %X.coerce)
return X;
}
// PR22563 - We should unwrap simple structs and arrays to pass
// and return them in the appropriate vector registers if possible.
typedef float v8f32 __attribute__((__vector_size__(32)));
struct v8f32wrapper {
v8f32 v;
};
struct v8f32wrapper f27a(struct v8f32wrapper X) {
// AVX-LABEL: define{{.*}} <8 x float> @f27a(<8 x float> %X.coerce)
return X;
}
struct v8f32wrapper_wrapper {
v8f32 v[1];
};
struct v8f32wrapper_wrapper f27b(struct v8f32wrapper_wrapper X) {
// AVX-LABEL: define{{.*}} <8 x float> @f27b(<8 x float> %X.coerce)
return X;
}
// rdar://5711709
struct f28c {
double x;
int y;
};
void f28(struct f28c C) {
// CHECK-LABEL: define{{.*}} void @f28(double %C.coerce0, i32 %C.coerce1)
}
struct f29a {
struct c {
double x;
int y;
} x[1];
};
void f29a(struct f29a A) {
// CHECK-LABEL: define{{.*}} void @f29a(double %A.coerce0, i32 %A.coerce1)
}
// rdar://8249586
struct S0 { char f0[8]; char f2; char f3; char f4; };
void f30(struct S0 p_4) {
// CHECK-LABEL: define{{.*}} void @f30(i64 %p_4.coerce0, i24 %p_4.coerce1)
}
// Pass the third element as a float when followed by tail padding.
// rdar://8251384
struct f31foo { float a, b, c; };
float f31(struct f31foo X) {
// CHECK-LABEL: define{{.*}} float @f31(<2 x float> %X.coerce0, float %X.coerce1)
return X.c;
}
_Complex float f32(_Complex float A, _Complex float B) {
// rdar://6379669
// CHECK-LABEL: define{{.*}} <2 x float> @f32(<2 x float> noundef %A.coerce, <2 x float> noundef %B.coerce)
return A+B;
}
// rdar://8357396
struct f33s { long x; float c,d; };
void f33(va_list X) {
va_arg(X, struct f33s);
}
typedef unsigned long long v1i64 __attribute__((__vector_size__(8)));
// rdar://8359248
// CHECK-LABEL: define{{.*}} double @f34(double noundef %arg.coerce)
v1i64 f34(v1i64 arg) { return arg; }
// rdar://8358475
// CHECK-LABEL: define{{.*}} double @f35(double noundef %arg.coerce)
typedef unsigned long v1i64_2 __attribute__((__vector_size__(8)));
v1i64_2 f35(v1i64_2 arg) { return arg+arg; }
// rdar://9122143
// CHECK: declare void @func(%struct._str* noundef byval(%struct._str) align 16)
typedef struct _str {
union {
long double a;
long c;
};
} str;
void func(str s);
str ss;
void f9122143(void)
{
func(ss);
}
// CHECK-LABEL: define{{.*}} double @f36(double noundef %arg.coerce)
typedef unsigned v2i32 __attribute((__vector_size__(8)));
v2i32 f36(v2i32 arg) { return arg; }
// AVX: declare void @f38(<8 x float>)
// AVX: declare void @f37(<8 x float> noundef)
// SSE: declare void @f38(%struct.s256* noundef byval(%struct.s256) align 32)
// SSE: declare void @f37(<8 x float>* noundef byval(<8 x float>) align 32)
typedef float __m256 __attribute__ ((__vector_size__ (32)));
typedef struct {
__m256 m;
} s256;
s256 x38;
__m256 x37;
void f38(s256 x);
void f37(__m256 x);
void f39(void) { f38(x38); f37(x37); }
// The two next tests make sure that the struct below is passed
// in the same way regardless of avx being used
// CHECK: declare void @func40(%struct.t128* noundef byval(%struct.t128) align 16)
typedef float __m128 __attribute__ ((__vector_size__ (16)));
typedef struct t128 {
__m128 m;
__m128 n;
} two128;
extern void func40(two128 s);
void func41(two128 s) {
func40(s);
}
// CHECK: declare void @func42(%struct.t128_2* noundef byval(%struct.t128_2) align 16)
typedef struct xxx {
__m128 array[2];
} Atwo128;
typedef struct t128_2 {
Atwo128 x;
} SA;
extern void func42(SA s);
void func43(SA s) {
func42(s);
}
// CHECK-LABEL: define{{.*}} i32 @f44
// CHECK: ptrtoint
// CHECK-NEXT: add i64 %{{[0-9]+}}, 31
// CHECK-NEXT: and i64 %{{[0-9]+}}, -32
// CHECK-NEXT: inttoptr
typedef int T44 __attribute((vector_size(32)));
struct s44 { T44 x; int y; };
int f44(int i, ...) {
__builtin_va_list ap;
__builtin_va_start(ap, i);
struct s44 s = __builtin_va_arg(ap, struct s44);
__builtin_va_end(ap);
return s.y;
}
// Text that vec3 returns the correct LLVM IR type.
// AVX-LABEL: define{{.*}} i32 @foo(<3 x i64> noundef %X)
typedef long long3 __attribute((ext_vector_type(3)));
int foo(long3 X)
{
return 0;
}
// Make sure we don't use a varargs convention for a function without a
// prototype where AVX types are involved.
// AVX: @test45
// AVX: call i32 bitcast (i32 (...)* @f45 to i32 (<8 x float>)*)
int f45();
__m256 x45;
void test45(void) { f45(x45); }
// Make sure we use byval to pass 64-bit vectors in memory; the LLVM call
// lowering can't handle this case correctly because it runs after legalization.
// CHECK: @test46
// CHECK: call void @f46({{.*}}<2 x float>* noundef byval(<2 x float>) align 8 {{.*}}, <2 x float>* noundef byval(<2 x float>) align 8 {{.*}})
typedef float v46 __attribute((vector_size(8)));
void f46(v46,v46,v46,v46,v46,v46,v46,v46,v46,v46);
void test46(void) { v46 x = {1,2}; f46(x,x,x,x,x,x,x,x,x,x); }
// Check that we pass the struct below without using byval, which helps out
// codegen.
//
// CHECK: @test47
// CHECK: call void @f47(i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}}, i32 {{.*}})
struct s47 { unsigned a; };
void f47(int,int,int,int,int,int,struct s47);
void test47(int a, struct s47 b) { f47(a, a, a, a, a, a, b); }
// rdar://12723368
// In the following example, there are holes in T4 at the 3rd byte and the 4th
// byte, however, T2 does not have those holes. T4 is chosen to be the
// representing type for union T1, but we can't use load or store of T4 since
// it will skip the 3rd byte and the 4th byte.
// In general, Since we don't accurately represent the data fields of a union,
// do not use load or store of the representing llvm type for the union.
typedef _Complex int T2;
typedef _Complex char T5;
typedef _Complex int T7;
typedef struct T4 { T5 field0; T7 field1; } T4;
typedef union T1 { T2 field0; T4 field1; } T1;
extern T1 T1_retval;
T1 test48(void) {
// CHECK: @test48
// CHECK: memcpy
// CHECK: memcpy
return T1_retval;
}
void test49_helper(double, ...);
void test49(double d, double e) {
test49_helper(d, e);
}
// CHECK-LABEL: define{{.*}} void @test49(
// CHECK: [[T0:%.*]] = load double, double*
// CHECK-NEXT: [[T1:%.*]] = load double, double*
// CHECK-NEXT: call void (double, ...) @test49_helper(double noundef [[T0]], double noundef [[T1]])
void test50_helper();
void test50(double d, double e) {
test50_helper(d, e);
}
// CHECK-LABEL: define{{.*}} void @test50(
// CHECK: [[T0:%.*]] = load double, double*
// CHECK-NEXT: [[T1:%.*]] = load double, double*
// CHECK-NEXT: call void (double, double, ...) bitcast (void (...)* @test50_helper to void (double, double, ...)*)(double noundef [[T0]], double noundef [[T1]])
struct test51_s { __uint128_t intval; };
void test51(struct test51_s *s, __builtin_va_list argList) {
*s = __builtin_va_arg(argList, struct test51_s);
}
// CHECK-LABEL: define{{.*}} void @test51
// CHECK: [[TMP_ADDR:%.*]] = alloca [[STRUCT_TEST51:%.*]], align 16
// CHECK: br i1
// CHECK: [[REG_SAVE_AREA_PTR:%.*]] = getelementptr inbounds {{.*}}, i32 0, i32 3
// CHECK-NEXT: [[REG_SAVE_AREA:%.*]] = load i8*, i8** [[REG_SAVE_AREA_PTR]]
// CHECK-NEXT: [[VALUE_ADDR:%.*]] = getelementptr i8, i8* [[REG_SAVE_AREA]], i32 {{.*}}
// CHECK-NEXT: [[CASTED_VALUE_ADDR:%.*]] = bitcast i8* [[VALUE_ADDR]] to [[STRUCT_TEST51]]
// CHECK-NEXT: [[CASTED_TMP_ADDR:%.*]] = bitcast [[STRUCT_TEST51]]* [[TMP_ADDR]] to i8*
// CHECK-NEXT: [[RECASTED_VALUE_ADDR:%.*]] = bitcast [[STRUCT_TEST51]]* [[CASTED_VALUE_ADDR]] to i8*
// CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 [[CASTED_TMP_ADDR]], i8* align 8 [[RECASTED_VALUE_ADDR]], i64 16, i1 false)
// CHECK-NEXT: add i32 {{.*}}, 16
// CHECK-NEXT: store i32 {{.*}}, i32* {{.*}}
// CHECK-NEXT: br label
void test52_helper(int, ...);
__m256 x52;
void test52(void) {
test52_helper(0, x52, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0i);
}
// AVX: @test52_helper(i32 noundef 0, <8 x float> noundef {{%[a-zA-Z0-9]+}}, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef {{%[a-zA-Z0-9]+}}, double noundef {{%[a-zA-Z0-9]+}})
void test53(__m256 *m, __builtin_va_list argList) {
*m = __builtin_va_arg(argList, __m256);
}
// AVX-LABEL: define{{.*}} void @test53
// AVX-NOT: br i1
// AVX: ret void
void test54_helper(__m256, ...);
__m256 x54;
void test54(void) {
test54_helper(x54, x54, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0i);
test54_helper(x54, x54, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0i);
}
// AVX: @test54_helper(<8 x float> noundef {{%[a-zA-Z0-9]+}}, <8 x float> noundef {{%[a-zA-Z0-9]+}}, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef {{%[a-zA-Z0-9]+}}, double noundef {{%[a-zA-Z0-9]+}})
// AVX: @test54_helper(<8 x float> noundef {{%[a-zA-Z0-9]+}}, <8 x float> noundef {{%[a-zA-Z0-9]+}}, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, { double, double }* noundef byval({ double, double }) align 8 {{%[^)]+}})
typedef float __m512 __attribute__ ((__vector_size__ (64)));
typedef struct {
__m512 m;
} s512;
s512 x55;
__m512 x56;
// On AVX512, aggregates which contain a __m512 type are classified as SSE/SSEUP
// as per https://github.com/hjl-tools/x86-psABI/commit/30f9c9 3.2.3p2 Rule 1
//
// AVX512: declare void @f55(<16 x float>)
// NO-AVX512: declare void @f55(%struct.s512* noundef byval(%struct.s512) align 64)
void f55(s512 x);
// __m512 has type SSE/SSEUP on AVX512.
//
// AVX512: declare void @f56(<16 x float> noundef)
// NO-AVX512: declare void @f56(<16 x float>* noundef byval(<16 x float>) align 64)
void f56(__m512 x);
void f57(void) { f55(x55); f56(x56); }
// Like for __m128 on AVX, check that the struct below is passed
// in the same way regardless of AVX512 being used.
//
// CHECK: declare void @f58(%struct.t256* noundef byval(%struct.t256) align 32)
typedef struct t256 {
__m256 m;
__m256 n;
} two256;
extern void f58(two256 s);
void f59(two256 s) {
f58(s);
}
// CHECK: declare void @f60(%struct.sat256* noundef byval(%struct.sat256) align 32)
typedef struct at256 {
__m256 array[2];
} Atwo256;
typedef struct sat256 {
Atwo256 x;
} SAtwo256;
extern void f60(SAtwo256 s);
void f61(SAtwo256 s) {
f60(s);
}
// AVX512: @f62_helper(i32 noundef 0, <16 x float> noundef {{%[a-zA-Z0-9]+}}, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef {{%[a-zA-Z0-9]+}}, double noundef {{%[a-zA-Z0-9]+}})
void f62_helper(int, ...);
__m512 x62;
void f62(void) {
f62_helper(0, x62, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0i);
}
// Like for __m256 on AVX, we always pass __m512 in memory, and don't
// need to use the register save area.
//
// AVX512-LABEL: define{{.*}} void @f63
// AVX512-NOT: br i1
// AVX512: ret void
void f63(__m512 *m, __builtin_va_list argList) {
*m = __builtin_va_arg(argList, __m512);
}
// AVX512: @f64_helper(<16 x float> noundef {{%[a-zA-Z0-9]+}}, <16 x float> noundef {{%[a-zA-Z0-9]+}}, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef {{%[a-zA-Z0-9]+}}, double noundef {{%[a-zA-Z0-9]+}})
// AVX512: @f64_helper(<16 x float> noundef {{%[a-zA-Z0-9]+}}, <16 x float> noundef {{%[a-zA-Z0-9]+}}, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, double noundef 1.000000e+00, { double, double }* noundef byval({ double, double }) align 8 {{%[^)]+}})
void f64_helper(__m512, ...);
__m512 x64;
void f64(void) {
f64_helper(x64, x64, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0i);
f64_helper(x64, x64, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0i);
}
struct t65 {
__m256 m;
int : 0;
};
// SSE-LABEL: @f65(%struct.t65* noundef byval(%struct.t65) align 32 %{{[^,)]+}})
// AVX: @f65(<8 x float> %{{[^,)]+}})
void f65(struct t65 a0) {
}
/// The synthesized __va_list_tag does not have file/line fields.
// CHECK: = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "__va_list_tag",
// CHECK-NOT: file:
// CHECK-NOT: line:
// CHECK-SAME: size:
|
the_stack_data/814085.c
|
/*
* CRC32 calculation.
*
* Copyright (C) 2020-2021 LuaVela Authors. See Copyright Notice in COPYRIGHT
* Copyright (C) 2015-2020 IPONWEB Ltd. See Copyright Notice in COPYRIGHT
*/
#include <stdint.h>
/*
* Lookup table for faster CRC32 calculation.
* Was generated by the following program:
*
* #include <stdio.h>
* #include <stdint.h>
*
* typedef uint32_t crc_t;
* #define POLYNOMIAL 0xEDB88320
*
* int main()
* {
* unsigned i, bit;
* crc_t remainder;
* crc_t table[256];
*
* for (i = 0; i < 256; i++) {
* remainder = i;
* for (bit = 8; bit > 0; bit--) {
* if (remainder & 0x1)
* remainder = (remainder >> 1) ^ POLYNOMIAL;
* else
* remainder >>= 1;
* }
* table[i] = remainder;
* }
*
* for (i = 0; i < 256; i++) {
* printf("0x%08x, ", table[i]);
* if ((i + 1) % 4 == 0)
* printf("\n");
* }
* return 0;
* }
*/
static const uint32_t crc_table[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d};
uint32_t uj_crc32(const char *msg)
{
uint32_t crc = (uint32_t)~0;
unsigned i;
for (i = 0; msg[i] != '\0'; i++) {
uint8_t lookup_idx = crc ^ msg[i];
crc = crc_table[lookup_idx] ^ (crc >> 8);
}
return crc ^ ((uint32_t)~0);
}
|
the_stack_data/707727.c
|
#include <stdio.h>
int main(void) {
int n;
while(1)
{
scanf("%d",&n);
if(n==42)
{
break;
}
printf("%d\n",n);
}
return 0;
}
|
the_stack_data/101059.c
|
/* PR middle-end/26632
We used to issue a warning for an implicit cast whose result is not
used. */
/* { dg-do compile } */
/* { dg-options "-Wall" } */
int g (void);
long h (void);
void
f (void)
{
0 ? h () : g (); /* { dg-bogus "value computed is not used" } */
}
|
the_stack_data/100141497.c
|
/* { dg-do compile } */
/* { dg-options "-O2 -fopenmp -fdump-tree-ompexp" } */
/* { dg-final { scan-tree-dump-times "GOMP_loop_start " 3 "ompexp" } } */
/* { dg-final { scan-tree-dump-times "GOMP_loop_end_nowait " 3 "ompexp" } } */
int r;
void
foo (int *a)
{
#pragma omp for nowait lastprivate(conditional: r)
for (int i = 0; i < 64; ++i)
if (a[i])
r = a[i];
}
void
bar (int *a)
{
#pragma omp for nowait lastprivate(conditional: r) schedule (static, 4)
for (int i = 0; i < 64; ++i)
if (a[i])
r = a[i];
}
void
baz (int *a)
{
#pragma omp for nowait lastprivate(conditional: r) schedule (runtime)
for (int i = 0; i < 64; ++i)
if (a[i])
r = a[i];
}
|
the_stack_data/122014966.c
|
extern int _Iutil_main(int argc, char **argv) ;
int main(int argc, char **argv)
{
return _Iutil_main(argc, argv);
}
|
the_stack_data/145452632.c
|
/* Example of an unbuffered and buffered getchar */
#include<unistd.h>
#include<sys/syscall.h>
#include<stdio.h>
#define BUFSIZ 1024
/* unbuffered getchar implementation using read */
int ugetchar(void);
/* buffered getchar implementation using read */
int bgetchar(void);
int main()
{
char c;
while ((c = ugetchar()) != 'x')
{
putchar(c);
}
while ((c = bgetchar()) != 'x')
{
putchar(c);
}
return 0;
}
int ugetchar(void)
{
char c;
return (read(0, &c, 1) == 1) ? (unsigned char) c : EOF;
}
int bgetchar(void)
{
static char buf[BUFSIZ];
static char *bufp = buf;
static int n = 0;
if (n == 0) /* buffer is empty */
{
n = read(0, buf, sizeof buf);
bufp = buf;
}
return (--n >= 0) ? (unsigned char) *bufp++ : EOF;
}
|
the_stack_data/580775.c
|
//
// main.c
// BIRT2PL
//
// Created by jevan on 10/28/18.
// Copyright © 2018 jevan. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// set the number of I and P
#define I_items 30
#define P_persons 2000
//structure
int main(int argc, const char * argv[]) {
//clarification
double Runiform(double rangeLow, double rangeHigh);
double seq(double rangeLow, double rangeHigh);
double RNormal(double miu, double sigma, double min, double max);
double Plogis(double x);
//******************************************************
// Data Preparation
//******************************************************
srand(314159);
// set the fixted item and population parameters
//// discrimination
double a_disc[30];
for (int i = 0; i < I_items; i++) {
a_disc[i] = 1 + Runiform(-0.5, 0.5);
}
//// difficulty
float diff_range_low = -3.0;
float diff_range_high = 3.0;
float interval = (diff_range_high - diff_range_low) / (30.0 - 1.0);
double b_diff[30];
b_diff[29] = diff_range_high;
int i = 29;
while (i) {
b_diff[i - 1] = b_diff[i] - interval;
--i;
}
//// theta
float theta = 0;
float sig_theta = 1.25;
//// generate thetas and the I x P matrix of response probabilities
double theta_abl[P_persons];
for (i = 0; i < P_persons; i++) {
theta_abl[i] = RNormal(theta, sig_theta, -5.0, 5.0);
}
double P_prob[P_persons][I_items];
int p;
double term1,term2;
for (p = 0; p < P_persons; p++) {
for (i = 0; i < I_items; i++) {
term1 = theta_abl[p]*a_disc[i];
term2 = a_disc[i] * b_diff[i];
P_prob[p][i] = Plogis(term1-term2);
}
}
//// generate the 0/1 responses U as a matrix of Bernoulli draws
int U[P_persons][I_items];
for (p = 0; p <P_persons; p++) {
for(i = 0; i < I_items; i++){
float B_draw = Runiform(0, 1);
U[p][i] = (B_draw < P_prob[p][i])?1:0;
printf("%d,",U[p][i]);
}
printf("\n");
}
//******************************************************
// Data Preparation
//******************************************************
}
double Runiform(double rangeLow, double rangeHigh) {
double myRand = rand()/(1.0 + RAND_MAX);
double range = rangeHigh - rangeLow;
double myRand_scaled = (myRand * range) + rangeLow;
return myRand_scaled;
}
double Rbeta(double b)
{
double un;
un=0.0;
while(un<=0.0 || un>=1.0) un=rand()*1.0/RAND_MAX;
return 1.0-exp(1.0/b*log(un));
}
double Normal(double x,double miu,double sigma) //normal density
{
return 1.0/sqrt(2*M_PI*sigma) * exp(-1*(x-miu)*(x-miu)/(2*sigma*sigma));
}
double RNormal(double miu, double sigma, double min, double max)
{
double x;
double dScope;
double y;
do
{
x = Runiform(min,max);
y = Normal(x, miu, sigma);
dScope = Runiform(0, Normal(miu,miu,sigma));
}while( dScope > y);
return x;
}
double Plogis(double x){
double z;
z = 1.0 / (1.0 + exp(-(x - 0.0) / 1.0));
return z;
}
//******************************************************
// MCMC Algorithm Shell
//******************************************************
//blocked.mcmc.update
//******************************************************
// Proposals
//******************************************************
//******************************************************
// Samplers: M-H
//******************************************************
|
the_stack_data/234517740.c
|
#include <stdio.h>
#include <string.h>
int main() {
char x[100];
printf("enter a sentence\n");
gets(x);
int slen=strlen(x);
printf("sentence length after gets:%d\n", slen);
for(int i=0;i<slen;i++){
printf("%x ", x[i]);
}
printf("\nenter the same sentence\n");
fgets(x, 99, stdin); // read max 99 char's.
slen=strlen(x);
printf("sentence length after fgets:%d\n", slen);
for(int i=0;i<slen;i++){
printf("%x ", x[i]);
}
}
|
the_stack_data/80964.c
|
#include <stdio.h>
void main()
{
int a[10][10],n,i,j;
printf("Enter the dimension of array");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(i=1;i<=n;i++)
{
printf("\n");
for(j=1;j<=n;j++)
{
printf("%d\t",a[i][j]);
}
}
}
|
the_stack_data/148579040.c
|
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <getopt.h>
#include <unistd.h>
// Note: This function returns a pointer to a substring of the original string.
// If the given string was allocated dynamically, the caller must not overwrite
// that pointer with the returned value, since the original pointer must be
// deallocated using the same allocator with which it was allocated. The return
// value must NOT be deallocated using free() etc.
char *trimwhitespace(char *str) {
char *end;
// Trim leading space
while (isspace((unsigned char) *str)) str++;
if (*str == 0) // All spaces?
return str;
// Trim trailing space
end = str + strlen(str) - 1;
while (end > str && isspace((unsigned char) *end)) end--;
// Write new null terminator character
end[1] = '\0';
return str;
}
int sms_watch(char *optarg) {
FILE *fp = NULL;
char buff[101];
fp = popen("sms_web get 1001 1", "r");
while (NULL != fgets(buff, 101, fp)) {
char status[2];
memcpy(status, buff + 4, 1);
status[1] = '\0';
if (status[0] != '1') {
continue;
}
char index[5];
memcpy(index, buff, 4);
index[4] = '\0';
trimwhitespace(index);
char phone[41];
memcpy(phone, buff + 5, 40);
phone[40] = '\0';
trimwhitespace(phone);
char exec[100] = {0};
snprintf(exec, sizeof exec, "sms_web set 1008 \"%s\" \"`sms_web get 1004 %s`\r\n来自(%s)\"", optarg, index,
phone);
system(exec);
printf("%s\n", exec);
}
pclose(fp);
return 0;
}
int main(int argc, char *argv[]) {
int opt;
char *phone = NULL;
int time = 30;
while ((opt = getopt(argc, argv, "p:t:")) != -1) {
switch (opt) {
case 'p':
if (optarg == NULL) {
printf("%s\n", "not set phone use -p option");
return 0;
} else {
phone = optarg;
}
break;
case 't':
if (optarg == NULL) {
printf("%s\n", "not set time use -t option");
return 0;
} else {
time = atoi(optarg);
}
break;
case '?': // 输入未定义的选项, 都会将该选项的值变为 ?
printf("unknown option \n");
break;
default:
printf("default \n");
}
}
if (phone == NULL) {
printf("Please specify the forwarding mobile phone number, Use -p option\n");
return 0;
}
while (1) {
sms_watch(phone);
sleep(time);
}
}
|
the_stack_data/127497.c
|
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "Usage: wc2 file1 file2 ...\n");
exit(1);
}
for (int i = 1; i < argc; ++i) {
FILE *fp = fopen(argv[i], "r");
if (fp == NULL) {
perror("fopen");
exit(1);
}
int c;
int lines = 0;
while ((c = fgetc(fp)) != EOF) {
if (c == '\n') {
++lines;
}
}
printf("%5d %s\n", lines, argv[i]);
fclose(fp);
}
return 0;
}
|
the_stack_data/190769343.c
|
/*
Anonymous unions
*/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct CustomFloat {
bool isExtended;
union {
float val;
double valExtended;
};
} CustomFloat;
int main(int argc, char const *argv[]) {
CustomFloat cf, cf2;
cf.isExtended = false;
cf.val = 12.5f;
cf2.isExtended = true;
cf2.valExtended = 0.25;
printf("%f %lf\n", cf.val, cf2.valExtended);
printf("%p %p\n", &cf.val, &cf.valExtended);
printf("%llu\n", sizeof(CustomFloat));
return 0;
}
|
the_stack_data/142326714.c
|
#include <stdio.h>
#include <string.h>
#define MAX_STR 128
int main() {
struct {
char autor[MAX_STR];
char titulo[MAX_STR];
int anyo;
} novela = {"", "El héroe discreto", 2013};
printf("Introduzca el autor de %s, publicado en %d: ", novela.titulo, novela.anyo);
fgets(novela.autor, MAX_STR, stdin);
printf("%s fue escrito por %s en %d.\n", novela.titulo, novela.autor, novela.anyo);
return 0;
}
|
the_stack_data/125141878.c
|
#include <stdio.h>
void foo(int n)
{
if (n == 0)
return;
printf("%i ", n);
foo(n - 1);
}
int main()
{
int n;
scanf("%i", &n);
foo(n);
puts("");
return 0;
}
|
the_stack_data/139653.c
|
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
int main (int argc, char** argv) {
if (argc < 2) {
printf("Usage ./%s <number_of_threads>\n", argv[0]);
exit(0);
}
printf("Number of processors: %d\n", omp_get_num_procs());
const int NUM_TH = atoi(argv[1]);
int th_id, nthreads;
omp_set_num_threads(NUM_TH); // disparar 4 threads pois se trata de uma máquina Quad-Core
#pragma omp parallel private(th_id, nthreads) num_threads(NUM_TH)
{
th_id = omp_get_thread_num();
nthreads = omp_get_num_threads();
printf("Hello World from thread %d of %d threads.\n", th_id, nthreads);
}
getchar();
return EXIT_SUCCESS;
}
|
the_stack_data/32951028.c
|
extern void __VERIFIER_error() __attribute__ ((__noreturn__));
void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } }
#define SIZE 50
/*
From: "On Solving Universally Quantified Horn Clauses"
Bjorner, McMillan, and Rybalchenko
SAS 2013
*/
int main( ) {
int a[SIZE];
int b[SIZE];
int c[SIZE];
int i = 0;
while (i < SIZE) {
c[i] = a[i] - b[i];
i = i + 1;
}
int x;
for ( x = 0 ; x < SIZE ; x++ ) {
__VERIFIER_assert( c[x] == a[x] - b[x] );
}
return 0;
}
|
the_stack_data/304086.c
|
#include<stdio.h>
void main()
{
char country[30] = "Em ware technologies";
printf("%15s\n",country);
printf("%15.6s\n",country);
printf("%-15.7s\n",country);
printf("%15.1s\n",country);
printf("%.3s\n",country);
printf("%s\n",country);
}
|
the_stack_data/117329439.c
|
#include <stdio.h>
#define MULT(A, B) A*B
int main() {
printf("MULT(5,5): %d\n", MULT(5,5));
printf("MULT(2+3,3+2): %d\n", MULT(2+3,3+2));
return 0;
}
|
the_stack_data/67324530.c
|
/*
* $Header$
* $Name$
*
*
* A PTHREADS convenience wrapper intended primarily for use with
* gcc/g77 which does not support an "automatic" (here, meant as a
* compiler-supported) threading mechanism.
*
*/
#ifdef HAVE_PTHREADS
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <pthread.h>
void ptreentry_(int* myThid);
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
int num_threads = 0;
void *
threadfunc(void *parm)
{
int myThid;
int rc;
rc = pthread_mutex_lock(&mutex);
num_threads++;
myThid = num_threads;
rc = pthread_mutex_unlock(&mutex);
ptreentry_(&myThid);
}
void
ptinit_(int* nthreads)
{
int i,j;
int rc;
pthread_t threadids[10];
pthread_attr_t pta;
pthread_attr_init(&pta);
pthread_attr_setdetachstate(&pta, PTHREAD_CREATE_JOINABLE);
/* start the threads */
for (i=0; i<(*nthreads); i++)
rc = pthread_create(&threadids[i], &pta, threadfunc, NULL);
/* wait on thread termination */
for (i=0; i<(*nthreads); i++)
rc = pthread_join(threadids[i], NULL);
}
#endif /* HAVE_PTHREADS */
|
the_stack_data/15764007.c
|
// RUN: %clang_cc1 -triple x86_64-unknown-freebsd10.0 -emit-llvm < %s | FileCheck -check-prefix=FREEBSD %s
// RUN: %clang_cc1 -triple x86_64-pc-win32 -emit-llvm < %s | FileCheck -check-prefix=WIN64 %s
struct foo {
int x;
float y;
char z;
};
// FREEBSD: %[[STRUCT_FOO:.*]] = type { i32, float, i8 }
// WIN64: %[[STRUCT_FOO:.*]] = type { i32, float, i8 }
void __attribute__((ms_abi)) f1(void);
void __attribute__((sysv_abi)) f2(void);
void f3(void) {
// FREEBSD-LABEL: define void @f3()
// WIN64-LABEL: define dso_local void @f3()
f1();
// FREEBSD: call win64cc void @f1()
// WIN64: call void @f1()
f2();
// FREEBSD: call void @f2()
// WIN64: call x86_64_sysvcc void @f2()
}
// FREEBSD: declare win64cc void @f1()
// FREEBSD: declare void @f2()
// WIN64: declare dso_local void @f1()
// WIN64: declare dso_local x86_64_sysvcc void @f2()
// Win64 ABI varargs
void __attribute__((ms_abi)) f4(int a, ...) {
// FREEBSD-LABEL: define win64cc void @f4
// WIN64-LABEL: define dso_local void @f4
__builtin_ms_va_list ap;
__builtin_ms_va_start(ap, a);
// FREEBSD: %[[AP:.*]] = alloca i8*
// FREEBSD: call void @llvm.va_start
// WIN64: %[[AP:.*]] = alloca i8*
// WIN64: call void @llvm.va_start
int b = __builtin_va_arg(ap, int);
// FREEBSD: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
// FREEBSD-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
// FREEBSD-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
// FREEBSD-NEXT: bitcast i8* %[[AP_CUR]] to i32*
// WIN64: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
// WIN64-NEXT: bitcast i8* %[[AP_CUR]] to i32*
// FIXME: These are different now. We probably need __builtin_ms_va_arg.
double _Complex c = __builtin_va_arg(ap, double _Complex);
// FREEBSD: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
// FREEBSD-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 16
// FREEBSD-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
// FREEBSD-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }*
// WIN64: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
// WIN64-NEXT: %[[CUR2:.*]] = bitcast i8* %[[AP_CUR2]] to { double, double }**
// WIN64-NEXT: load { double, double }*, { double, double }** %[[CUR2]]
struct foo d = __builtin_va_arg(ap, struct foo);
// FREEBSD: %[[AP_CUR3:.*]] = load i8*, i8** %[[AP]]
// FREEBSD-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 16
// FREEBSD-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
// FREEBSD-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
// WIN64: %[[AP_CUR3:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
// WIN64-NEXT: %[[CUR3:.*]] = bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
// WIN64-NEXT: load %[[STRUCT_FOO]]*, %[[STRUCT_FOO]]** %[[CUR3]]
__builtin_ms_va_list ap2;
__builtin_ms_va_copy(ap2, ap);
// FREEBSD: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
// FREEBSD-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
// WIN64: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
__builtin_ms_va_end(ap);
// FREEBSD: call void @llvm.va_end
// WIN64: call void @llvm.va_end
}
// Let's verify that normal va_lists work right on Win64, too.
void f5(int a, ...) {
// WIN64-LABEL: define dso_local void @f5
__builtin_va_list ap;
__builtin_va_start(ap, a);
// WIN64: %[[AP:.*]] = alloca i8*
// WIN64: call void @llvm.va_start
int b = __builtin_va_arg(ap, int);
// WIN64: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
// WIN64-NEXT: bitcast i8* %[[AP_CUR]] to i32*
double _Complex c = __builtin_va_arg(ap, double _Complex);
// WIN64: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
// WIN64-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }*
struct foo d = __builtin_va_arg(ap, struct foo);
// WIN64: %[[AP_CUR3:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
// WIN64-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
__builtin_va_list ap2;
__builtin_va_copy(ap2, ap);
// WIN64: call void @llvm.va_copy
__builtin_va_end(ap);
// WIN64: call void @llvm.va_end
}
// Verify that using a Win64 va_list from a System V function works.
void __attribute__((sysv_abi)) f6(__builtin_ms_va_list ap) {
// FREEBSD-LABEL: define void @f6
// FREEBSD: store i8* %ap, i8** %[[AP:.*]]
// WIN64-LABEL: define dso_local x86_64_sysvcc void @f6
// WIN64: store i8* %ap, i8** %[[AP:.*]]
int b = __builtin_va_arg(ap, int);
// FREEBSD: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
// FREEBSD-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
// FREEBSD-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
// FREEBSD-NEXT: bitcast i8* %[[AP_CUR]] to i32*
// WIN64: %[[AP_CUR:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
// WIN64-NEXT: bitcast i8* %[[AP_CUR]] to i32*
double _Complex c = __builtin_va_arg(ap, double _Complex);
// FREEBSD: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
// FREEBSD-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 16
// FREEBSD-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
// FREEBSD-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }*
// WIN64: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
// WIN64-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }*
struct foo d = __builtin_va_arg(ap, struct foo);
// FREEBSD: %[[AP_CUR3:.*]] = load i8*, i8** %[[AP]]
// FREEBSD-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 16
// FREEBSD-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
// FREEBSD-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
// WIN64: %[[AP_CUR3:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 8
// WIN64-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
// WIN64-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
__builtin_ms_va_list ap2;
__builtin_ms_va_copy(ap2, ap);
// FREEBSD: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
// FREEBSD-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
// WIN64: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
// WIN64-NEXT: store i8* %[[AP_VAL]], i8** %[[AP2:.*]]
}
// This test checks if structs are passed according to Win64 calling convention
// when it's enforced by __attribute((ms_abi)).
struct i128 {
unsigned long long a;
unsigned long long b;
};
__attribute__((ms_abi)) struct i128 f7(struct i128 a) {
// WIN64: define dso_local void @f7(%struct.i128* noalias sret align 8 %agg.result, %struct.i128* %a)
// FREEBSD: define win64cc void @f7(%struct.i128* noalias sret align 8 %agg.result, %struct.i128* %a)
return a;
}
|
the_stack_data/61076523.c
|
// Copyright 2018 Dennis Decker Jensen
// Date: 29 April 2018
// Purpose: Minimum difference of pentagon numbers.
// Tectonics: cc -std=c11 -pedantic -Wall -O2 -o euler044 euler044.c
//
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
enum { npentagons = 10000 }; // N.B! Trial and error
unsigned pentagon[npentagons];
int
cmp(const void *a, const void *b)
{
unsigned ua = *(unsigned *)a, ub = *(unsigned *)b;
if (ua < ub) return -1;
else if (ua > ub) return 1;
else return 0;
}
int
main()
{
size_t i, j, m = 0, n = 0, si = 0, di = 0;
unsigned sum = 0, difference = 0, min = UINT_MAX, s, *b;
for (i = 0; i < npentagons; ++i)
pentagon[i] = i * (3 * i - 1) / 2;
for (i = 1; i < npentagons; ++i)
for (j = i + 1; j < npentagons
&& (s = pentagon[i] + pentagon[j])
<= pentagon[npentagons - 1]; ++j) {
b = bsearch(&s, pentagon, npentagons,
sizeof(unsigned), cmp);
if (b == NULL)
continue;
si = b - pentagon;
difference = pentagon[j] - pentagon[i];
b = bsearch(&difference, pentagon, npentagons,
sizeof(unsigned), cmp);
if (b == NULL)
continue;
di = b - pentagon;
if (difference < min) {
min = difference;
sum = s;
m = i;
n = j;
printf(">P%zu - P%zu = %u\n", m, n, min);
printf(">P%zu + P%zu = %u\n", m, n, sum);
}
}
printf("Minimum, P%zu - P%zu = P%zu (%u)\n", m, n, di, min);
printf(" P%zu + P%zu = P%zu (%u)\n", m, n, si, sum);
return 0;
}
|
the_stack_data/165768286.c
|
// Test the 65CE02 CPU
// A program that uses 65CE02 instructions
#pragma cpu(CSG65CE02)
signed char* const SCREEN = (signed char*)0x0400;
void main() {
signed char a = SCREEN[0];
a = -a;
SCREEN[1] = a; // Becomes a NEG
SCREEN[2] = a/4; // Becomes ASR
}
|
the_stack_data/220455180.c
|
/*
* Copyright © 2009 CNRS
* Copyright © 2009-2011 inria. All rights reserved.
* Copyright © 2009, 2012 Université Bordeaux
* Copyright © 2011 Cisco Systems, Inc. All rights reserved.
* See COPYING in top-level directory.
*/
#include <hwloc.h>
#include <assert.h>
/* check misc bitmap stuff */
int main(void)
{
hwloc_bitmap_t set;
/* check an empty bitmap */
set = hwloc_bitmap_alloc();
assert(hwloc_bitmap_to_ulong(set) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL);
/* check a non-empty bitmap */
hwloc_bitmap_from_ith_ulong(set, 4, 0xff);
assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xff);
assert(hwloc_bitmap_to_ulong(set) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL);
/* check a two-long bitmap */
hwloc_bitmap_from_ith_ulong(set, 4, 0xfe);
hwloc_bitmap_set_ith_ulong(set, 6, 0xef);
assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xfe);
assert(hwloc_bitmap_to_ith_ulong(set, 6) == 0xef);
assert(hwloc_bitmap_to_ulong(set) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL);
/* check a zeroed bitmap */
hwloc_bitmap_zero(set);
assert(hwloc_bitmap_to_ulong(set) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL);
hwloc_bitmap_free(set);
/* check a full bitmap */
set = hwloc_bitmap_alloc_full();
assert(hwloc_bitmap_to_ulong(set) == ~0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 0) == ~0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 1) == ~0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 23) == ~0UL);
/* check a almost full bitmap */
hwloc_bitmap_set_ith_ulong(set, 4, 0xff);
assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xff);
assert(hwloc_bitmap_to_ulong(set) == ~0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 0) == ~0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 1) == ~0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 23) == ~0UL);
/* check a almost empty bitmap */
hwloc_bitmap_from_ith_ulong(set, 4, 0xff);
assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xff);
assert(hwloc_bitmap_to_ulong(set) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL);
assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL);
hwloc_bitmap_free(set);
/* check ranges */
set = hwloc_bitmap_alloc();
assert(hwloc_bitmap_weight(set) == 0);
/* 23-45 */
hwloc_bitmap_set_range(set, 23, 45);
assert(hwloc_bitmap_weight(set) == 23);
/* 23-45,78- */
hwloc_bitmap_set_range(set, 78, -1);
assert(hwloc_bitmap_weight(set) == -1);
/* 23- */
hwloc_bitmap_set_range(set, 44, 79);
assert(hwloc_bitmap_weight(set) == -1);
assert(hwloc_bitmap_first(set) == 23);
assert(!hwloc_bitmap_isfull(set));
/* 0- */
hwloc_bitmap_set_range(set, 0, 22);
assert(hwloc_bitmap_weight(set) == -1);
assert(hwloc_bitmap_isfull(set));
/* 0-34,57- */
hwloc_bitmap_clr_range(set, 35, 56);
assert(hwloc_bitmap_weight(set) == -1);
assert(!hwloc_bitmap_isfull(set));
/* 0-34,57 */
hwloc_bitmap_clr_range(set, 58, -1);
assert(hwloc_bitmap_weight(set) == 36);
assert(hwloc_bitmap_last(set) == 57);
assert(hwloc_bitmap_next(set, 34) == 57);
/* 0-34 */
hwloc_bitmap_clr(set, 57);
assert(hwloc_bitmap_weight(set) == 35);
assert(hwloc_bitmap_last(set) == 34);
/* empty */
hwloc_bitmap_clr_range(set, 0, 34);
assert(hwloc_bitmap_weight(set) == 0);
assert(hwloc_bitmap_first(set) == -1);
hwloc_bitmap_free(set);
/* check miscellaneous other functions */
set = hwloc_bitmap_alloc();
/* from_ulong */
hwloc_bitmap_from_ulong(set, 0x0ff0);
assert(hwloc_bitmap_first(set) == 4);
assert(hwloc_bitmap_last(set) == 11);
assert(hwloc_bitmap_weight(set) == 8);
assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0xff0);
assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0);
/* from_ith_ulong */
hwloc_bitmap_zero(set);
assert(hwloc_bitmap_weight(set) == 0);
hwloc_bitmap_from_ith_ulong(set, 2, 0xff00);
assert(hwloc_bitmap_weight(set) == 8);
assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0);
assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0);
assert(hwloc_bitmap_to_ith_ulong(set, 2) == 0xff00);
assert(hwloc_bitmap_to_ith_ulong(set, 3) == 0);
/* allbut and not */
hwloc_bitmap_allbut(set, 153);
assert(hwloc_bitmap_weight(set) == -1);
hwloc_bitmap_not(set, set);
assert(hwloc_bitmap_weight(set) == 1);
assert(hwloc_bitmap_first(set) == 153);
assert(hwloc_bitmap_last(set) == 153);
/* clr_range */
hwloc_bitmap_fill(set);
hwloc_bitmap_clr_range(set, 178, 3589);
hwloc_bitmap_not(set, set);
assert(hwloc_bitmap_weight(set) == 3589-178+1);
assert(hwloc_bitmap_first(set) == 178);
assert(hwloc_bitmap_last(set) == 3589);
/* singlify */
hwloc_bitmap_zero(set);
hwloc_bitmap_set_range(set, 0, 127);
assert(hwloc_bitmap_weight(set) == 128);
hwloc_bitmap_not(set, set);
assert(hwloc_bitmap_weight(set) == -1);
hwloc_bitmap_singlify(set);
assert(hwloc_bitmap_weight(set) == 1);
assert(hwloc_bitmap_first(set) == 128);
assert(hwloc_bitmap_last(set) == 128);
hwloc_bitmap_free(set);
return 0;
}
|
the_stack_data/53629.c
|
/*
D:\C\crculatlnklst.c
Avinal Kumar
December 21, 2018
Circular Linked List Implementation
*/
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
struct circularnode
{
int data;
struct circularnode *next;
};
typedef struct circularnode node;
node *start = NULL;
node *create_cll(node *);
node *display_cll(node *);
node *delete_beg(node *);
node *delete_end(node *);
node *add_beg(node *);
node *add_end(node *);
node *delete_aftr(node *);
node *delete_all(node *);
int main()
{
int choice;
do
{
printf("\n******Circular Linked List Operations******");
printf("\n1. Create a Circular Linked list");
printf("\n2. Display a Circular linked list");
printf("\n3. Insert a node at the beginning");
printf("\n4. Insert a node at the end");
printf("\n5. Delete a node in the beginning");
printf("\n6. Delete a node in the end");
printf("\n7. Delete a node after a given node");
printf("\n8. Delete the Circular linked list");
printf("\n9. EXIT");
printf("\nEnter your Choice");
scanf("%d", &choice);
switch (choice)
{
case 1:
start = create_cll(start);
printf("\nThe list has been created");
break;
case 2:
start = display_cll(start);
break;
case 3:
start = add_beg(start);
printf("\nUpdated list is :\n");
display_cll(start);
break;
case 4:
start = add_end(start);
printf("\nUpdated list is :\n");
display_cll(start);
break;
case 5:
start = delete_beg(start);
printf("\nUpdated list is :\n");
display_cll(start);
break;
case 6:
start = delete_end(start);
printf("\nUpdated list is :\n");
display_cll(start);
break;
case 7:
start = delete_aftr(start);
printf("\nUpdated list is :\n");
display_cll(start);
break;
case 8:
start = delete_all(start);
break;
default:
printf("\nWrong Choice !!!");
break;
}
} while (choice != 9);
}
node *create_cll(node *first)
{
node *var_node, *new_node;
int number;
printf("\nEnter -1 to end");
printf("\nEnter the data");
scanf("%d", &number);
while (number != -1)
{
new_node = (node *)malloc(sizeof(node));
(*new_node).data = number;
if (first == NULL)
{
(*new_node).next = new_node;
first = new_node;
}
else
{
var_node = first;
while ((*var_node).next != first)
{
var_node = (*var_node).next;
}
(*var_node).next = new_node;
(*new_node).next = first;
}
printf("\nEnter the data");
scanf("%d", &number);
}
return (first);
}
node *display_cll(node *first)
{
node *var_node;
var_node = first;
while ((*var_node).next != first)
{
printf("\n%d", (*var_node).data);
var_node = (*var_node).next;
}
printf("\n%d", (*var_node).data);
return (first);
}
node *add_beg(node *first)
{
node *var_node, *new_node;
int number;
printf("\nEnter the data to be inserted");
scanf("%d", &number);
new_node = (node *)malloc(sizeof(node));
(*new_node).data = number;
var_node = first;
while ((*var_node).next != first)
{
var_node = (*var_node).next;
}
(*var_node).next = new_node;
(*new_node).next = first;
first = new_node;
return (first);
}
node *add_end(node *first)
{
node *var_node, *new_node;
int number;
printf("\nEnter the data to be inserted");
scanf("%d", &number);
new_node = (node *)malloc(sizeof(node));
(*new_node).data = number;
var_node = first;
while ((*var_node).next != first)
{
var_node = (*var_node).next;
}
(*var_node).next = new_node;
(*new_node).next = first;
return (first);
}
node *delete_beg(node *first)
{
node *var_node;
var_node = first;
while ((*var_node).next != first)
{
var_node = (*var_node).next;
}
(*var_node).next = (*first).next;
free(first);
first = (*var_node).next;
return (first);
}
node *delete_end(node *first)
{
node *var_node, *pre_node;
var_node = first;
while ((*var_node).next != first)
{
pre_node = var_node;
var_node = (*var_node).next;
}
(*pre_node).next = (*var_node).next;
free(var_node);
return (first);
}
node *delete_aftr(node *first)
{
node *var_node, *pre_node;
int value;
printf("\nEnter value after which node is to be deleted");
scanf("%d", &value);
var_node = first;
pre_node = var_node;
while ((*pre_node).data != value)
{
pre_node = var_node;
var_node = (*var_node).next;
}
(*pre_node).next = (*var_node).next;
free(var_node);
return (first);
}
node *delete_all(node *first)
{
node *var_node;
var_node = first;
while ((*var_node).next != first)
{
first = delete_end(first);
}
free(start);
return start;
}
|
the_stack_data/654493.c
|
// test program:
// simple loop
int xex(int b) {
return b + 9;
}
int main() {
int x = -7;
x++;
for (int i = 0; i < 500; i++)
x = xex(i);
return x;
}
|
the_stack_data/150140941.c
|
/*
* Addon: Revival Plus
* Script: RPL_ChernarusPlus.c
* Author: Tomáš Benedikt; submitted by benedi.kz
*
* © 2020 Tomáš Benedikt
*
* This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
*
* <summary>Script override of ChernarusPlusData class.</summary>
*
*/
//modded class ChernarusPlusData extends WorldData {};
|
the_stack_data/43887288.c
|
#include <stdio.h>
int main() {
printf("LOLCode is \"the\" worst\n");
return 0;
}
|
the_stack_data/94429.c
|
#include <time.h>
#include <fcntl.h>
#include <termios.h>
#include <pthread.h>
#include <semaphore.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
#define NBC 2 // nombre de cabine
#define NBP 4 // nombre de paniers
#define CLIENT_COUNT_MAX 150
#define STATE_DEFAULT 0
#define STATE_WAITING_FOR_PANIER 1
#define STATE_WAITING_FOR_CABINE 2
#define STATE_CHANGING 3
#define STATE_SWIMMING 4
#define STATE_WAITING_FOR_CABINE_AGAIN 5
#define STATE_CHANGING_AGAIN 6
#define STATE_DONE 7
#define MIN_WAIT 10
#define MAX_WAIT 100
#define CHECK(sts,msg) if ((sts) == -1) { perror(msg); exit(sts); }
#define MY_ALEA(min,max) usleep(1000*(rand()%(max-min)+min))
////////////////////////////////////////////////////////////////////////////////
// Structures
////////////////////////////////////////////////////////////////////////////////
typedef struct {
int id;
int stateId;
sem_t * paniers;
sem_t * cabines;
int hasPanier;
int isInCabine;
} Client;
typedef struct {
int id;
int durationMilli;
char bob[8];
} State;
////////////////////////////////////////////////////////////////////////////////
// Affichage
////////////////////////////////////////////////////////////////////////////////
void displaying(Client ** clients, int totalClientCount,
int totalCabineCount, int totalPanierCount, int * go) {
int i = 0;
int panierCount = totalPanierCount;
int cabineCount = totalCabineCount;
int attentes = 0;
int baignades = 0;
while(*go) {
usleep(50*1000);
panierCount = totalPanierCount;
cabineCount = totalCabineCount;
attentes = 0;
baignades = 0;
printf("%10i |", (int)clock());
for(i = 0 ; i < totalClientCount ; i++) {
switch(clients[i]->stateId) {
case STATE_DEFAULT : {
printf(".");
break;
}
case STATE_WAITING_FOR_PANIER : {
attentes++;
printf("%d", clients[i]->stateId);
break;
}
case STATE_WAITING_FOR_CABINE : {
attentes++;
printf("%d", clients[i]->stateId);
break;
}
case STATE_CHANGING : {
printf("%d", clients[i]->stateId);
break;
}
case STATE_SWIMMING : {
baignades++;
printf("%d", clients[i]->stateId);
break;
}
case STATE_WAITING_FOR_CABINE_AGAIN : {
attentes++;
printf("%d", clients[i]->stateId);
break;
}
case STATE_CHANGING_AGAIN : {
printf("%d", clients[i]->stateId);
break;
}
case STATE_DONE : {
printf(" ");
break;
}
default: {
printf("ZZZ %d ZZZ", clients[i]->id);
break;
}
}
panierCount -= clients[i]->hasPanier;
cabineCount -= clients[i]->isInCabine;
}
printf("| P %d/%1i", panierCount, totalPanierCount);
printf(" | C %d/%1i", cabineCount, totalCabineCount);
printf(" | A %2i", attentes);
printf(" | B %2i", baignades);
printf(" |\n");
}
}
////////////////////////////////////////////////////////////////////////////////
// -
////////////////////////////////////////////////////////////////////////////////
void * clientFunction(void * client_) {
Client * client = (Client *)client_;
MY_ALEA(MIN_WAIT, MAX_WAIT*client->id);
client->isInCabine = 0;
client->hasPanier = 0;
client->stateId = STATE_WAITING_FOR_PANIER;
sem_wait(client->paniers);
client->hasPanier = 1;
client->stateId = STATE_WAITING_FOR_CABINE;
sem_wait(client->cabines);
client->isInCabine = 1;
client->stateId = STATE_CHANGING;
MY_ALEA(MIN_WAIT,MAX_WAIT);
sem_post(client->cabines);
client->isInCabine = 0;
client->stateId = STATE_SWIMMING;
MY_ALEA(MIN_WAIT,MAX_WAIT);
client->stateId = STATE_WAITING_FOR_CABINE_AGAIN;
sem_wait(client->cabines);
client->isInCabine = 1;
client->stateId = STATE_CHANGING_AGAIN;
MY_ALEA(MIN_WAIT,MAX_WAIT);
sem_post(client->cabines);
client->isInCabine = 0;
sem_post(client->paniers);
client->hasPanier = 0;
client->stateId = STATE_DONE;
pthread_exit(NULL);
}
void initSemaphores(sem_t * cabines, sem_t * paniers,
int totalCabineCount, int totalPanierCount) {
sem_init(cabines, 0, totalCabineCount);
sem_init(paniers, 0, totalPanierCount);
}
void startThreads(pthread_t * threads, sem_t * cabines, sem_t * paniers,
int totalClientCount, Client ** clients) {
int i = 0;
for(i = 0 ; i < totalClientCount ; i++) {
// Init
clients[i] = malloc(sizeof(Client));
clients[i]->id = i;
clients[i]->stateId = STATE_DEFAULT;
clients[i]->cabines = cabines;
clients[i]->paniers = paniers;
clients[i]->isInCabine = 0;
clients[i]->hasPanier = 0;
// Launch thread
pthread_create(&threads[i],
NULL,
clientFunction,
(void *)(clients[i]));
}
}
////////////////////////////////////////////////////////////////////////////////
// Début du programme
////////////////////////////////////////////////////////////////////////////////
int main (int c, char**v) {
srand(time(NULL));
int totalCabineCount = NBC;
int totalPanierCount = NBP;
int totalClientCount = CLIENT_COUNT_MAX;
int go = 1;
printf("\
********************************\n\
* PRS - CTP V2 - Loïc Bourgois *\n\
********************************\n");
printf("\
Légende \n\
. - Etat initial\n\
1 - En attente d'un panier\n\
2 - En attente d'une cabine\n\
3 - Se change\n\
4 - Se baigne\n\
5 - En attente d'une cabine après baignade\n\
6 - Se change après baignade\n\
- Terminé\n\
P - Paniers disponibles\n\
C - Cabines disponibles\n\
A - Clients en attentes\n\
B - Clients en baignade\n\n");
//sem_t lock;
sem_t cabines;
sem_t paniers;
pthread_t clientThreads[totalClientCount];
Client ** clients = malloc(sizeof(Client)*totalClientCount);
initSemaphores(&cabines, &paniers, totalCabineCount, totalPanierCount);
startThreads(clientThreads, &cabines, &paniers, totalClientCount, clients);
displaying(clients, totalClientCount, totalCabineCount, totalPanierCount, &go);
printf("Tout est bien qui fini bien\n");
return 1;
}
|
the_stack_data/156393623.c
|
/*
* fdopen - convert a (UNIX) file descriptor into a FILE pointer
*/
/* $Id$ */
#include <stdio.h>
#include <stdlib.h>
#if ACKCONF_WANT_O_TEXT_O_BINARY
#include <unistd.h>
#include <fcntl.h>
#endif
#if ACKCONF_WANT_STDIO && ACKCONF_WANT_EMULATED_FILE
FILE* fdopen(int fd, const char* mode)
{
register int i;
FILE* stream;
int flags = 0;
if (fd < 0)
return (FILE*)NULL;
for (i = 0; __iotab[i] != 0; i++)
if (i >= FOPEN_MAX - 1)
return (FILE*)NULL;
switch (*mode++)
{
case 'r':
flags |= _IOREAD | _IOREADING;
break;
case 'a':
flags |= _IOAPPEND;
case 'w':
flags |= _IOWRITE | _IOWRITING;
break;
default:
return (FILE*)NULL;
}
while (*mode)
{
switch (*mode++)
{
case 'b':
#if ACKCONF_WANT_O_TEXT_O_BINARY
flags |= _IOBINARY;
#endif
continue;
case '+':
flags |= _IOREAD | _IOWRITE;
continue;
/* The sequence may be followed by aditional characters */
default:
break;
}
break;
}
if ((stream = (FILE*)malloc(sizeof(FILE))) == NULL)
{
return (FILE*)NULL;
}
if ((flags & _IOREAD) && (flags & _IOWRITE))
flags &= ~(_IOREADING | _IOWRITING);
#if ACKCONF_WANT_O_TEXT_O_BINARY
{
/*
* FIXME: this assumes that any platform that has O_TEXT and
* O_BINARY will also have a _setmode() function.
*/
extern int _setmode(int, int);
_setmode(fd, (flags & _IOBINARY) ? O_BINARY : O_TEXT);
}
#endif
stream->_count = 0;
stream->_fd = fd;
stream->_flags = flags;
stream->_buf = NULL;
__iotab[i] = stream;
return stream;
}
#endif
|
the_stack_data/40762278.c
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#define nil NULL
typedef unsigned char uchar;
typedef unsigned int uint;
typedef uint64_t word;
enum
{
TapeEndF = 022,
TapeEndR = 055,
BlockSpace = 025,
BlockEndF = 026,
BlockEndR = 045,
DataSync = 032, /* rev guard */
BlockSync = 051, /* guard */
DataEndF = 073, /* pre-final, final, ck, rev lock */
DataEndR = 010, /* lock, rev ck, rev final, rev pre-final */
Data = 070,
NUMBLOCKS = 01102,
// DTSIZE = 922512
// 01102 blocks, 2700 word for start/end each + safe zone
DTSIZE = 987288 + 1000
};
FILE*
mustopen(const char *name, const char *mode)
{
FILE *f;
if(f = fopen(name, mode), f == nil){
fprintf(stderr, "couldn't open file: %s\n", name);
exit(1);
}
return f;
}
/* Read raw tape data (forward) */
void
readf(uchar **dtp, uchar *mark, word *wrd)
{
int i;
uchar l;
uchar m;
word w;
m = 0;
w = 0;
for(i = 0; i < 6; i++){
l = *(*dtp)++;
m = (m << 1) | !!(l&010);
w = (w << 3) | l&7;
}
*mark = m;
*wrd = w;
}
/* Write raw tape data (forwad */
void
writef(uchar **p, int mark, int *ck, int data)
{
int i;
uchar d;
if(ck){
*ck ^= ~data & 077;
*ck ^= ~data>>6 & 077;
*ck ^= ~data>>12 & 077;
}
for(i = 0; i < 6; i++){
if(mark)
d = !!(mark & 040) << 3;
else
d = !!(**p & 010) << 3;
if(data & 01000000)
d |= **p & 07;
else{
d |= (data & 0700000) >> 15;
data = (data << 3) & 0777777;
}
mark <<= 1;
**p = d;
(*p)++;
}
}
#define LDB(p, s, w) ((w)>>(p) & (1<<(s))-1)
#define XLDB(ppss, w) LDB((ppss)>>6 & 077, (ppss)&077, w)
#define MASK(p, s) ((1<<(s))-1 << (p))
#define DPB(b, p, s, w) ((w)&~MASK(p,s) | (b)<<(p) & MASK(p,s))
#define XDPB(b, ppss, w) DPB(b, (ppss)>>6 & 077, (ppss)&077, w)
void
writesimh(FILE *f, word w)
{
uchar c[8];
uint l, r;
r = LDB(0, 18, w);
l = LDB(18, 18, w);
c[0] = LDB(0, 8, l);
c[1] = LDB(8, 8, l);
c[2] = LDB(16, 8, l);
c[3] = LDB(24, 8, l);
c[4] = LDB(0, 8, r);
c[5] = LDB(8, 8, r);
c[6] = LDB(16, 8, r);
c[7] = LDB(24, 8, r);
fwrite(c, 1, 8, f);
}
word
readsimh(FILE *f)
{
uchar c[8];
word w[2];
if(fread(c, 1, 8, f) != 8)
return ~0;
w[0] = c[3]<<24 | c[2]<<16 | c[1]<<8 | c[0];
w[1] = c[7]<<24 | c[6]<<16 | c[5]<<8 | c[4];
return (w[0]<<18 | w[1]) & 0777777777777;
}
char*
tostr(int m)
{
return m == TapeEndF ? "End Zone Fwd" :
m == TapeEndR ? "End Zone Rev" :
m == BlockSpace ? "Block Space" :
m == BlockEndF ? "Block End Fwd" :
m == BlockEndR ? "Block End Rev" :
m == DataSync ? "Data Sync" :
m == BlockSync ? "Block Sync" :
m == DataEndF ? "Data End Fwd" :
m == DataEndR ? "Data End Rev" :
m == Data ? "Data" :
"Unknown";
}
void
rawdump(uchar *dtp)
{
uchar mark;
word w;
uchar *end;
end = dtp + DTSIZE;
while(dtp < end){
readf(&dtp, &mark, &w);
printf("%02o[%-13s] %06o\n", mark, tostr(mark), w);
}
}
#define CHKWORD(exp) \
readf(&dtp, &mark, &w); \
if(mark != exp){ \
fprintf(stderr, "expected %s(%02o) got %s(%02o)\n", \
tostr(exp), exp, tostr(mark), mark); \
return 0; \
} \
int
validate(uchar *dtp)
{
uchar mark;
word w;
int i, j;
CHKWORD(TapeEndR);
CHKWORD(TapeEndR);
for(i = 0; i < NUMBLOCKS; i++){
CHKWORD(BlockSpace);
CHKWORD(BlockEndF);
CHKWORD(DataSync);
CHKWORD(DataEndR);
CHKWORD(DataEndR);
CHKWORD(DataEndR);
CHKWORD(DataEndR);
for(j = 1; j < 127; j++){
CHKWORD(Data);
CHKWORD(Data);
}
CHKWORD(DataEndF);
CHKWORD(DataEndF);
CHKWORD(DataEndF);
CHKWORD(DataEndF);
CHKWORD(BlockSync);
CHKWORD(BlockEndR);
CHKWORD(BlockSpace);
}
CHKWORD(TapeEndF);
CHKWORD(TapeEndF);
return 1;
}
void
dumpdta(uchar *dtp, FILE *f)
{
uchar mark;
word w, w2;
int i, j;
readf(&dtp, &mark, &w);
readf(&dtp, &mark, &w);
for(i = 0; i < NUMBLOCKS; i++){
readf(&dtp, &mark, &w);
readf(&dtp, &mark, &w2);
w = w << 18 | w2;
// data unused
readf(&dtp, &mark, &w);
readf(&dtp, &mark, &w2);
w = w << 18 | w2;
readf(&dtp, &mark, &w);
for(j = 0; j < 128; j++){
readf(&dtp, &mark, &w);
readf(&dtp, &mark, &w2);
writesimh(f, w<<18 | w2);
}
readf(&dtp, &mark, &w);
// data unused
readf(&dtp, &mark, &w);
readf(&dtp, &mark, &w2);
w = w << 18 | w2;
// reverse block mark
readf(&dtp, &mark, &w);
readf(&dtp, &mark, &w2);
w = w << 18 | w2;
}
readf(&dtp, &mark, &w);
readf(&dtp, &mark, &w);
}
void
wrf(FILE *f, int mark, int *ck, int data)
{
uchar buf[6], *p;
p = buf;
writef(&p, mark, ck, data);
fwrite(buf, 1, 6, f);
};
void
dumpdtr(word *wp, word *bmp, word *ibp, FILE *f)
{
word w;
int i, j;
int ck;
for(i = 0; i < 2700; i++)
{
wrf(f, TapeEndR, nil, 0);
wrf(f, TapeEndR, nil, 0);
}
for(i = 0; i < NUMBLOCKS; i++){
w = *bmp++;
wrf(f, BlockSpace, nil, LDB(18, 18, w)); // block mark
wrf(f, BlockEndF, nil, LDB(0, 18, w)); // block mark
w = *ibp++;
wrf(f, DataSync, nil, LDB(18, 18, w));
wrf(f, DataEndR, nil, LDB(0, 18, w));
ck = 077;
// wrf(f, DataEndR, nil, 0007777); // rev check
// this seems what 551 actually does
wrf(f, DataEndR, nil, 0000000); // rev check
/* the data */
w = *wp++;
wrf(f, DataEndR, &ck, LDB(18, 18, w));
wrf(f, DataEndR, &ck, LDB(0, 18, w));
for(j = 1; j < 127; j++){
w = *wp++;
wrf(f, Data, &ck, LDB(18, 18, w));
wrf(f, Data, &ck, LDB(0, 18, w));
}
w = *wp++;
wrf(f, DataEndF, &ck, LDB(18, 18, w));
wrf(f, DataEndF, &ck, LDB(0, 18, w));
wrf(f, DataEndF, nil, (ck & 077) << 12 | 07777); // check
w = *ibp++;
wrf(f, DataEndF, nil, LDB(18, 18, w));
wrf(f, BlockSync, nil, LDB(0, 18, w));
w = *bmp++;
wrf(f, BlockEndR, nil, LDB(18, 18, w)); // rev block mark
wrf(f, BlockSpace, nil, LDB(0, 18, w)); // rev block mark
}
for(i = 0; i < 2700; i++)
{
wrf(f, TapeEndF, nil, 0);
wrf(f, TapeEndF, nil, 0);
}
}
uchar*
findstart(uchar *buf)
{
uchar *t;
int i;
word w;
uchar m;
for(i = 0; i < 1000; i++){
t = buf;
readf(&t, &m, &w);
if(m == TapeEndR)
goto found;
buf++;
}
return nil;
found:
while(readf(&buf, &m, &w), m == TapeEndR);
return buf-18;
}
uchar dtbuf[DTSIZE], *dtp;
word blockbuf[NUMBLOCKS*0200];
word bmbuf[NUMBLOCKS*2];
word ibbuf[NUMBLOCKS*2];
/* Fill block mark and interblock word buffers */
void
makefmt(void)
{
int i, j;
word co;
for(i = 0; i < NUMBLOCKS; i++){
/* forward and reverse block number */
bmbuf[i*2] = i;
// last one is 700707070707 really because it can't be written easily
co = 0;
for(j = 0; j < 12; j++)
co |= ((bmbuf[i*2]>>j*3) & 07) << (11-j)*3;
co ^= 0777777777777;
bmbuf[i*2+1] = co;
/* interblock words - used to find block 75 which contains the loader */
/* forward word */
if(i < 075)
ibbuf[i*2] = 0721200220107; // move forward
else if(i == 075)
ibbuf[i*2] = 0577777777777; // nop
else
ibbuf[i*2] = 0721200233107; // move backward
/* reverse word */
// last one is 777077707007 really because it can't be written easily
if(i < 073)
ibbuf[i*2+1] = 0721200223107; // move forward
else
ibbuf[i*2+1] = 0721200230107; // move backward
}
/* Last block isn't written quite correctly. To simulate: */
// ibbuf[01101*2 + 0] = 0077070007000;
// ibbuf[01101*2 + 1] = 0777077707007;
// bmbuf[01101*2 + 1] = 0700707070707;
}
int
readdtr(FILE *f)
{
fread(dtbuf, 1, DTSIZE, f);
fclose(f);
dtp = findstart(dtbuf);
if(dtp == nil){
fprintf(stderr, "no start\n");
return 1;
}
if(!validate(dtp)){
fprintf(stderr, "invalid file format\n");
return 1;
}
return 0;
}
int
readdta(FILE *f)
{
word w;
int n;
n = 0;
while(w = readsimh(f), w != ~0 && n < NUMBLOCKS*0200)
blockbuf[n++] = w;
return n != NUMBLOCKS*0200;
}
int
dtr2dta(void)
{
if(readdtr(stdin))
return 1;
dumpdta(dtp, stdout);
return 0;
}
int
dta2dtr(void)
{
if(readdta(stdin))
return 1;
makefmt();
dumpdtr(blockbuf, bmbuf, ibbuf, stdout);
return 0;
}
int
main(int argc, char *argv[])
{
if(strstr(argv[0], "dtr2dta")) return dtr2dta();
else if(strstr(argv[0], "dta2dtr")) return dta2dtr();
else fprintf(stderr, "Unknown %s\n", argv[0]);
return 0;
}
|
the_stack_data/150142412.c
|
int main()
{
int a = 68;
a = a % a % a % a%a;
return a;
}
|
the_stack_data/279526.c
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char const *argv[])
{
char str[10];
char str2[20];
//get str from input (last character is '\n')
scanf("%s", str);
//get only one character from input
getchar();
//get whole line from input file
gets(str2);
printf("out put sth: %s\n", str);
printf("out put sth: %s\n", str2);
return 0;
}
|
the_stack_data/212642415.c
|
/* 11) Um motorista de táxi deseja calcular o rendimento de seu carro na praça. Escreva um
programa para ler: a marcação do odômetro (Km) no início do dia, a marcação (Km) no
final do dia, o número de litros de combustível gasto, o valor do combustível por litro e o
valor total (R$) recebido dos passageiros. Calcular e escrever: a média do consumo em
Km/L e o lucro (líquido) do dia */
#include <stdio.h>
int main(void)
{
float km_inicial;
float km_final;
float litros_combustivel_gasto;
float valor_combustivel;
float valor_total_recebido;
float media;
float lucro;
printf("Insira a marcação do odometro em km (inicial): ");
scanf("%f", &km_inicial);
printf("Insira a marcação do odometro em km (final: ");
scanf("%f", &km_final);
printf("Insira a quantidade de litros de combustivel gasto: ");
scanf("%f", &litros_combustivel_gasto);
printf("Insira o valor do combustivel por litro: ");
scanf("%f", &valor_combustivel);
printf("Insira o valor total arrecadado R$: ");
scanf("%f", &valor_total_recebido);
media = (km_final - km_inicial) / litros_combustivel_gasto;
lucro = valor_total_recebido - (litros_combustivel_gasto * valor_combustivel);
printf("A media do consumo em KM/L foi de: %.f\n", media);
printf("O lucro liquido do dia foi de R$: %.2f\n", lucro);
system("pause");
return (0);
}
|
the_stack_data/117047.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: evgenkarlson <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 12:33:14 by evgenkarlson #+# #+# */
/* Updated: 2020/09/28 19:01:41 by evgenkarlson ### ########.fr */
/* */
/* ************************************************************************** */
/* ************************************************************************** */
/* команда для компиляции и одновременного запуска */
/* */
/* gcc -Wall -Werror -Wextra test.c && chmod +x ./a.out && ./a.out */
/* ************************************************************************** */
/* Скомпилируй файл тест. В нем можно увидеть как работает эта функция вживую */
#include <unistd.h>
void ft_putchar(char c) /* функция вывода символа */
{
write(1, &c, 1);
}
/*#############################################################################*/
/* Эта функция принимает число int разделяет на кусочки и добавляет каждой к отделенной друг от друга цифре 48 */
/* Зачем мы добавляем к числу 48? По тому что если сразу отправить в ft_putchar отделеное число например ft_putchar(5);
то выведется не символ '5' а с символ '#', который хранится в таблице символов под числом 5 */
/* т.е. чтобы напечетать любое число от 0 до 9 отправляя его в путчар мы:
либо дожны записать его код вот так ft_putchar(53);
либо написать сам символ в кавычках вот так ft_putchar('5');
Но мы будем высчитывать код символа каждую итерацию. Так что вариант нам нужен другой вариант, котрый мы описали ниже.
Мы будем высчитывать код символа за счет прибавления к числу кода нулевого символа. ВОТ ТАК ft_putchar(5 + 48); где 48 -код нулевого символа, ИЛИ ТАК ft_putchar(5 + '0');
Программма при приеме этого вычисления(5 + '0' или 5 + 48) поймет что вы хотите увидеь символ под кодом 53 и наапечатает его.
(число должнобыть не меньше нуля и не больше 9 иначе вычисление не сработает) */
void ft_putnbr(int nb) /* Функция вывода числа */
{
int temp; /* Обьявляем переменную для временного хранения данных переменной 'nb' */
int size; /* Обьявляем переменную для хранения размера числа*/
size = 1; /* Установим ей начальный размер */
if (nb < 0) /* Проверяем яляется полученное нами число в 'nb' отрицательным */
{
ft_putchar('-'); /* Если число отрицательное, то мы печатаем символ минуса '-' */
nb = -nb; /* Делаем содержимое переменной 'nb' положительным, с помощью хитрости(nb = -nb), помня из математики, что минус на минус дает плюс */
}
if (nb == -2147483648)
{
ft_putchar('2');
nb = 147483648;
}
temp = nb; /* Сохраним в переменную 'temp' наше число 'nb' для вычисления размера этого числа */
while ((temp /= 10) > 0) /* Вычисляем размер числа c помощью накопления количества умноженых десяток друг на друга */
size *= 10; /* Если результ деления нашего числа в 'temp' на 10 больше нуля то увеличиваем переменную 'size' умножив ее содержимое на 10 */
/* НУЖО ПОМНИТЬ что при делении целого числа на целое результат сохраняемый в переменной типа 'int' будет без плавающей точки.
** она автоматически отбрасывается */ /* Пример: делим 4 на 10 в итоге результат будет 0.4 но в переменной типа 'int' сохраниться
** только 0, потому что всё после точки в числе отбрасывается и в целочисленную переменную не записывается. */
temp = nb; /* Восстановим расстерзаное делением число в переменную 'temp'. Оно нам снова понадобится
** для того чтобы отделить цифры нужного нам числа и напечатать по отдельности */
while (size) /* проверяем длинну числа если длинна еще не равна нулю (в результате уменьшения на 10 в цикле) то продолжаем работу цикла */
{
ft_putchar((char)((temp / size)) + '0'); /* делим число на размер, который у нас получился */ /* тут тоже хитрость */
/* допустим размер полученогонами числа 345 получисля равным 100 */
/* деля 345 на 100 мы получим 3.45*/ /* 0.45 отбрасывается по тому что идет приведение к целому числу */ /* и остаеться 3 */
/* Так вот мы и отделяем 3 от 45 и уже можем ее напечатать тройку прибавив к ней 48, чтоб полуить код символа '3' */
temp %= size; /* Здесь с помощь деления числа temp (в примере у нас это 345) по модулю на size (в примере у нас это 100) мы получим
** оставшуюся часть без первого символа temp ( т.е у нас получится 45. Тройка канула в лету. Так мы ее отбрасываем чтоб потом,
** на новой итерации цикла напечатать 4 и 5 и т.д по мере отделения и печати чисел, и помере того как size уменьшается */
size /= 10; /* после то как отделили 3 от 45 в числе 345 и после того как оставили себе только 45 для дальнейшего отделения. число 100 нам больше не нужно.
** Так что делим size на 10 чтобы в след итерации число 45 уже делилось на 10 отдавая 4 на печать, и еще 45 делилось по модулю на 10 сохраняя 5
** на следующую итерацию, потом снова уменьшение size на 10 (чтобы можно было работать с temp, которое теперь уже хранит 5).
** Теперь 5 делм на 1 получаем пять отдаем его на печать, 5 деленное по модулю на 1 сохраняет в переменную 0 но это нам уже не нужно.
** Потому что дальше size делится на 10 снова и размер size становится равным нулю. А при след итерации цикл будет проверять размер size
** и если он равен 0 то цикл завершается */
/* И жили они долго и счастливо, конец */
}
}
int main(void)
{
ft_putnbr(345); /* тестим эту функцию */
return (0);
}
|
the_stack_data/130701.c
|
/* ftoc.c */
/*
Fitzpatrick. Computational Physics. 329.pdf
2.15 Command Line Parameters pp. 78
EY suffix means, this is my own changes, to explore what char *argv[] means
"
The main() function may optionally possess special arguments which allow parameters
to be passed to this function from the operating system. There are 2 such arguments,
convetionally called argc and argv.
argc is an integer which is set to the number of parameters passed to main()
argv is an array of pointers to character strings which contain these parameters
In order to pass one or more parameters to a C program when it is executed from the operating system,
parameters must follow the program name on the command line: e.g.
% program-name parameter_1 parameter_2 parameter_3 .. parameter_n
Program name will be stored in the first item in argv, followed by each of the parameters.
Hence, if program name is followed by n parameters there'll be n + 1 entries in argv,
ranging from argv[0] to argv[n]
Furthermore, argc will be automatically set equal to n+1
*/
/*
Program to convert temperature in Fahrenheit input
on command line to temperature in Celsius
*/
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
double deg_f, deg_c;
/* If no parameter passed to program print error
message and exit */
if (argc < 2)
{
printf("Usage: ftoc temperature\n");
exit(1);
}
/* Convert first command line parameter to double */
deg_f = atof(argv[1]);
/* Convert from Fahrenheit to Celsius */
deg_c = (5. /9. ) * (deg_f - 32.);
printf("%f degrees Fahrenheit equals %f degrees Celsius\n",
deg_f, deg_c);
return 0;
}
|
the_stack_data/23575532.c
|
/**
* @file
* Transmission Control Protocol for IP
* See also @ref tcp_raw
*
* @defgroup tcp_raw TCP
* @ingroup callbackstyle_api
* Transmission Control Protocol for IP\n
* @see @ref raw_api and @ref netconn
*
* Common functions for the TCP implementation, such as functinos
* for manipulating the data structures and the TCP timer functions. TCP functions
* related to input and output is found in tcp_in.c and tcp_out.c respectively.\n
*/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <[email protected]>
*
*/
#ifdef LIBOHIBOARD_ETHERNET_LWIP_2_0_3
#include "lwip/opt.h"
#if LWIP_TCP /* don't build if not configured for use in lwipopts.h */
#include "lwip/def.h"
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/tcp.h"
#include "lwip/priv/tcp_priv.h"
#include "lwip/debug.h"
#include "lwip/stats.h"
#include "lwip/ip6.h"
#include "lwip/ip6_addr.h"
#include "lwip/nd6.h"
#include <string.h>
#ifdef LWIP_HOOK_FILENAME
#include LWIP_HOOK_FILENAME
#endif
#ifndef TCP_LOCAL_PORT_RANGE_START
/* From http://www.iana.org/assignments/port-numbers:
"The Dynamic and/or Private Ports are those from 49152 through 65535" */
#define TCP_LOCAL_PORT_RANGE_START 0xc000
#define TCP_LOCAL_PORT_RANGE_END 0xffff
#define TCP_ENSURE_LOCAL_PORT_RANGE(port) ((u16_t)(((port) & ~TCP_LOCAL_PORT_RANGE_START) + TCP_LOCAL_PORT_RANGE_START))
#endif
#if LWIP_TCP_KEEPALIVE
#define TCP_KEEP_DUR(pcb) ((pcb)->keep_cnt * (pcb)->keep_intvl)
#define TCP_KEEP_INTVL(pcb) ((pcb)->keep_intvl)
#else /* LWIP_TCP_KEEPALIVE */
#define TCP_KEEP_DUR(pcb) TCP_MAXIDLE
#define TCP_KEEP_INTVL(pcb) TCP_KEEPINTVL_DEFAULT
#endif /* LWIP_TCP_KEEPALIVE */
/* As initial send MSS, we use TCP_MSS but limit it to 536. */
#if TCP_MSS > 536
#define INITIAL_MSS 536
#else
#define INITIAL_MSS TCP_MSS
#endif
static const char * const tcp_state_str[] = {
"CLOSED",
"LISTEN",
"SYN_SENT",
"SYN_RCVD",
"ESTABLISHED",
"FIN_WAIT_1",
"FIN_WAIT_2",
"CLOSE_WAIT",
"CLOSING",
"LAST_ACK",
"TIME_WAIT"
};
/* last local TCP port */
static u16_t tcp_port = TCP_LOCAL_PORT_RANGE_START;
/* Incremented every coarse grained timer shot (typically every 500 ms). */
u32_t tcp_ticks;
static const u8_t tcp_backoff[13] =
{ 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7};
/* Times per slowtmr hits */
static const u8_t tcp_persist_backoff[7] = { 3, 6, 12, 24, 48, 96, 120 };
/* The TCP PCB lists. */
/** List of all TCP PCBs bound but not yet (connected || listening) */
struct tcp_pcb *tcp_bound_pcbs;
/** List of all TCP PCBs in LISTEN state */
union tcp_listen_pcbs_t tcp_listen_pcbs;
/** List of all TCP PCBs that are in a state in which
* they accept or send data. */
struct tcp_pcb *tcp_active_pcbs;
/** List of all TCP PCBs in TIME-WAIT state */
struct tcp_pcb *tcp_tw_pcbs;
/** An array with all (non-temporary) PCB lists, mainly used for smaller code size */
struct tcp_pcb ** const tcp_pcb_lists[] = {&tcp_listen_pcbs.pcbs, &tcp_bound_pcbs,
&tcp_active_pcbs, &tcp_tw_pcbs};
u8_t tcp_active_pcbs_changed;
/** Timer counter to handle calling slow-timer from tcp_tmr() */
static u8_t tcp_timer;
static u8_t tcp_timer_ctr;
static u16_t tcp_new_port(void);
static err_t tcp_close_shutdown_fin(struct tcp_pcb *pcb);
/**
* Initialize this module.
*/
void
tcp_init(void)
{
#if LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS && defined(LWIP_RAND)
tcp_port = TCP_ENSURE_LOCAL_PORT_RANGE(LWIP_RAND());
#endif /* LWIP_RANDOMIZE_INITIAL_LOCAL_PORTS && defined(LWIP_RAND) */
}
/**
* Called periodically to dispatch TCP timers.
*/
void
tcp_tmr(void)
{
/* Call tcp_fasttmr() every 250 ms */
tcp_fasttmr();
if (++tcp_timer & 1) {
/* Call tcp_slowtmr() every 500 ms, i.e., every other timer
tcp_tmr() is called. */
tcp_slowtmr();
}
}
#if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG
/** Called when a listen pcb is closed. Iterates one pcb list and removes the
* closed listener pcb from pcb->listener if matching.
*/
static void
tcp_remove_listener(struct tcp_pcb *list, struct tcp_pcb_listen *lpcb)
{
struct tcp_pcb *pcb;
for (pcb = list; pcb != NULL; pcb = pcb->next) {
if (pcb->listener == lpcb) {
pcb->listener = NULL;
}
}
}
#endif
/** Called when a listen pcb is closed. Iterates all pcb lists and removes the
* closed listener pcb from pcb->listener if matching.
*/
static void
tcp_listen_closed(struct tcp_pcb *pcb)
{
#if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG
size_t i;
LWIP_ASSERT("pcb != NULL", pcb != NULL);
LWIP_ASSERT("pcb->state == LISTEN", pcb->state == LISTEN);
for (i = 1; i < LWIP_ARRAYSIZE(tcp_pcb_lists); i++) {
tcp_remove_listener(*tcp_pcb_lists[i], (struct tcp_pcb_listen*)pcb);
}
#endif
LWIP_UNUSED_ARG(pcb);
}
#if TCP_LISTEN_BACKLOG
/** @ingroup tcp_raw
* Delay accepting a connection in respect to the listen backlog:
* the number of outstanding connections is increased until
* tcp_backlog_accepted() is called.
*
* ATTENTION: the caller is responsible for calling tcp_backlog_accepted()
* or else the backlog feature will get out of sync!
*
* @param pcb the connection pcb which is not fully accepted yet
*/
void
tcp_backlog_delayed(struct tcp_pcb* pcb)
{
LWIP_ASSERT("pcb != NULL", pcb != NULL);
if ((pcb->flags & TF_BACKLOGPEND) == 0) {
if (pcb->listener != NULL) {
pcb->listener->accepts_pending++;
LWIP_ASSERT("accepts_pending != 0", pcb->listener->accepts_pending != 0);
pcb->flags |= TF_BACKLOGPEND;
}
}
}
/** @ingroup tcp_raw
* A delayed-accept a connection is accepted (or closed/aborted): decreases
* the number of outstanding connections after calling tcp_backlog_delayed().
*
* ATTENTION: the caller is responsible for calling tcp_backlog_accepted()
* or else the backlog feature will get out of sync!
*
* @param pcb the connection pcb which is now fully accepted (or closed/aborted)
*/
void
tcp_backlog_accepted(struct tcp_pcb* pcb)
{
LWIP_ASSERT("pcb != NULL", pcb != NULL);
if ((pcb->flags & TF_BACKLOGPEND) != 0) {
if (pcb->listener != NULL) {
LWIP_ASSERT("accepts_pending != 0", pcb->listener->accepts_pending != 0);
pcb->listener->accepts_pending--;
pcb->flags &= ~TF_BACKLOGPEND;
}
}
}
#endif /* TCP_LISTEN_BACKLOG */
/**
* Closes the TX side of a connection held by the PCB.
* For tcp_close(), a RST is sent if the application didn't receive all data
* (tcp_recved() not called for all data passed to recv callback).
*
* Listening pcbs are freed and may not be referenced any more.
* Connection pcbs are freed if not yet connected and may not be referenced
* any more. If a connection is established (at least SYN received or in
* a closing state), the connection is closed, and put in a closing state.
* The pcb is then automatically freed in tcp_slowtmr(). It is therefore
* unsafe to reference it.
*
* @param pcb the tcp_pcb to close
* @return ERR_OK if connection has been closed
* another err_t if closing failed and pcb is not freed
*/
static err_t
tcp_close_shutdown(struct tcp_pcb *pcb, u8_t rst_on_unacked_data)
{
if (rst_on_unacked_data && ((pcb->state == ESTABLISHED) || (pcb->state == CLOSE_WAIT))) {
if ((pcb->refused_data != NULL) || (pcb->rcv_wnd != TCP_WND_MAX(pcb))) {
/* Not all data received by application, send RST to tell the remote
side about this. */
LWIP_ASSERT("pcb->flags & TF_RXCLOSED", pcb->flags & TF_RXCLOSED);
/* don't call tcp_abort here: we must not deallocate the pcb since
that might not be expected when calling tcp_close */
tcp_rst(pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip,
pcb->local_port, pcb->remote_port);
tcp_pcb_purge(pcb);
TCP_RMV_ACTIVE(pcb);
if (pcb->state == ESTABLISHED) {
/* move to TIME_WAIT since we close actively */
pcb->state = TIME_WAIT;
TCP_REG(&tcp_tw_pcbs, pcb);
} else {
/* CLOSE_WAIT: deallocate the pcb since we already sent a RST for it */
if (tcp_input_pcb == pcb) {
/* prevent using a deallocated pcb: free it from tcp_input later */
tcp_trigger_input_pcb_close();
} else {
memp_free(MEMP_TCP_PCB, pcb);
}
}
return ERR_OK;
}
}
/* - states which free the pcb are handled here,
- states which send FIN and change state are handled in tcp_close_shutdown_fin() */
switch (pcb->state) {
case CLOSED:
/* Closing a pcb in the CLOSED state might seem erroneous,
* however, it is in this state once allocated and as yet unused
* and the user needs some way to free it should the need arise.
* Calling tcp_close() with a pcb that has already been closed, (i.e. twice)
* or for a pcb that has been used and then entered the CLOSED state
* is erroneous, but this should never happen as the pcb has in those cases
* been freed, and so any remaining handles are bogus. */
if (pcb->local_port != 0) {
TCP_RMV(&tcp_bound_pcbs, pcb);
}
memp_free(MEMP_TCP_PCB, pcb);
break;
case LISTEN:
tcp_listen_closed(pcb);
tcp_pcb_remove(&tcp_listen_pcbs.pcbs, pcb);
memp_free(MEMP_TCP_PCB_LISTEN, pcb);
break;
case SYN_SENT:
TCP_PCB_REMOVE_ACTIVE(pcb);
memp_free(MEMP_TCP_PCB, pcb);
MIB2_STATS_INC(mib2.tcpattemptfails);
break;
default:
return tcp_close_shutdown_fin(pcb);
}
return ERR_OK;
}
static err_t
tcp_close_shutdown_fin(struct tcp_pcb *pcb)
{
err_t err;
LWIP_ASSERT("pcb != NULL", pcb != NULL);
switch (pcb->state) {
case SYN_RCVD:
err = tcp_send_fin(pcb);
if (err == ERR_OK) {
tcp_backlog_accepted(pcb);
MIB2_STATS_INC(mib2.tcpattemptfails);
pcb->state = FIN_WAIT_1;
}
break;
case ESTABLISHED:
err = tcp_send_fin(pcb);
if (err == ERR_OK) {
MIB2_STATS_INC(mib2.tcpestabresets);
pcb->state = FIN_WAIT_1;
}
break;
case CLOSE_WAIT:
err = tcp_send_fin(pcb);
if (err == ERR_OK) {
MIB2_STATS_INC(mib2.tcpestabresets);
pcb->state = LAST_ACK;
}
break;
default:
/* Has already been closed, do nothing. */
return ERR_OK;
}
if (err == ERR_OK) {
/* To ensure all data has been sent when tcp_close returns, we have
to make sure tcp_output doesn't fail.
Since we don't really have to ensure all data has been sent when tcp_close
returns (unsent data is sent from tcp timer functions, also), we don't care
for the return value of tcp_output for now. */
tcp_output(pcb);
} else if (err == ERR_MEM) {
/* Mark this pcb for closing. Closing is retried from tcp_tmr. */
pcb->flags |= TF_CLOSEPEND;
/* We have to return ERR_OK from here to indicate to the callers that this
pcb should not be used any more as it will be freed soon via tcp_tmr.
This is OK here since sending FIN does not guarantee a time frime for
actually freeing the pcb, either (it is left in closure states for
remote ACK or timeout) */
return ERR_OK;
}
return err;
}
/**
* @ingroup tcp_raw
* Closes the connection held by the PCB.
*
* Listening pcbs are freed and may not be referenced any more.
* Connection pcbs are freed if not yet connected and may not be referenced
* any more. If a connection is established (at least SYN received or in
* a closing state), the connection is closed, and put in a closing state.
* The pcb is then automatically freed in tcp_slowtmr(). It is therefore
* unsafe to reference it (unless an error is returned).
*
* @param pcb the tcp_pcb to close
* @return ERR_OK if connection has been closed
* another err_t if closing failed and pcb is not freed
*/
err_t
tcp_close(struct tcp_pcb *pcb)
{
LWIP_DEBUGF(TCP_DEBUG, ("tcp_close: closing in "));
tcp_debug_print_state(pcb->state);
if (pcb->state != LISTEN) {
/* Set a flag not to receive any more data... */
pcb->flags |= TF_RXCLOSED;
}
/* ... and close */
return tcp_close_shutdown(pcb, 1);
}
/**
* @ingroup tcp_raw
* Causes all or part of a full-duplex connection of this PCB to be shut down.
* This doesn't deallocate the PCB unless shutting down both sides!
* Shutting down both sides is the same as calling tcp_close, so if it succeds
* (i.e. returns ER_OK), the PCB must not be referenced any more!
*
* @param pcb PCB to shutdown
* @param shut_rx shut down receive side if this is != 0
* @param shut_tx shut down send side if this is != 0
* @return ERR_OK if shutdown succeeded (or the PCB has already been shut down)
* another err_t on error.
*/
err_t
tcp_shutdown(struct tcp_pcb *pcb, int shut_rx, int shut_tx)
{
if (pcb->state == LISTEN) {
return ERR_CONN;
}
if (shut_rx) {
/* shut down the receive side: set a flag not to receive any more data... */
pcb->flags |= TF_RXCLOSED;
if (shut_tx) {
/* shutting down the tx AND rx side is the same as closing for the raw API */
return tcp_close_shutdown(pcb, 1);
}
/* ... and free buffered data */
if (pcb->refused_data != NULL) {
pbuf_free(pcb->refused_data);
pcb->refused_data = NULL;
}
}
if (shut_tx) {
/* This can't happen twice since if it succeeds, the pcb's state is changed.
Only close in these states as the others directly deallocate the PCB */
switch (pcb->state) {
case SYN_RCVD:
case ESTABLISHED:
case CLOSE_WAIT:
return tcp_close_shutdown(pcb, (u8_t)shut_rx);
default:
/* Not (yet?) connected, cannot shutdown the TX side as that would bring us
into CLOSED state, where the PCB is deallocated. */
return ERR_CONN;
}
}
return ERR_OK;
}
/**
* Abandons a connection and optionally sends a RST to the remote
* host. Deletes the local protocol control block. This is done when
* a connection is killed because of shortage of memory.
*
* @param pcb the tcp_pcb to abort
* @param reset boolean to indicate whether a reset should be sent
*/
void
tcp_abandon(struct tcp_pcb *pcb, int reset)
{
u32_t seqno, ackno;
#if LWIP_CALLBACK_API
tcp_err_fn errf;
#endif /* LWIP_CALLBACK_API */
void *errf_arg;
/* pcb->state LISTEN not allowed here */
LWIP_ASSERT("don't call tcp_abort/tcp_abandon for listen-pcbs",
pcb->state != LISTEN);
/* Figure out on which TCP PCB list we are, and remove us. If we
are in an active state, call the receive function associated with
the PCB with a NULL argument, and send an RST to the remote end. */
if (pcb->state == TIME_WAIT) {
tcp_pcb_remove(&tcp_tw_pcbs, pcb);
memp_free(MEMP_TCP_PCB, pcb);
} else {
int send_rst = 0;
u16_t local_port = 0;
enum tcp_state last_state;
seqno = pcb->snd_nxt;
ackno = pcb->rcv_nxt;
#if LWIP_CALLBACK_API
errf = pcb->errf;
#endif /* LWIP_CALLBACK_API */
errf_arg = pcb->callback_arg;
if (pcb->state == CLOSED) {
if (pcb->local_port != 0) {
/* bound, not yet opened */
TCP_RMV(&tcp_bound_pcbs, pcb);
}
} else {
send_rst = reset;
local_port = pcb->local_port;
TCP_PCB_REMOVE_ACTIVE(pcb);
}
if (pcb->unacked != NULL) {
tcp_segs_free(pcb->unacked);
}
if (pcb->unsent != NULL) {
tcp_segs_free(pcb->unsent);
}
#if TCP_QUEUE_OOSEQ
if (pcb->ooseq != NULL) {
tcp_segs_free(pcb->ooseq);
}
#endif /* TCP_QUEUE_OOSEQ */
tcp_backlog_accepted(pcb);
if (send_rst) {
LWIP_DEBUGF(TCP_RST_DEBUG, ("tcp_abandon: sending RST\n"));
tcp_rst(seqno, ackno, &pcb->local_ip, &pcb->remote_ip, local_port, pcb->remote_port);
}
last_state = pcb->state;
memp_free(MEMP_TCP_PCB, pcb);
TCP_EVENT_ERR(last_state, errf, errf_arg, ERR_ABRT);
}
}
/**
* @ingroup tcp_raw
* Aborts the connection by sending a RST (reset) segment to the remote
* host. The pcb is deallocated. This function never fails.
*
* ATTENTION: When calling this from one of the TCP callbacks, make
* sure you always return ERR_ABRT (and never return ERR_ABRT otherwise
* or you will risk accessing deallocated memory or memory leaks!
*
* @param pcb the tcp pcb to abort
*/
void
tcp_abort(struct tcp_pcb *pcb)
{
tcp_abandon(pcb, 1);
}
/**
* @ingroup tcp_raw
* Binds the connection to a local port number and IP address. If the
* IP address is not given (i.e., ipaddr == NULL), the IP address of
* the outgoing network interface is used instead.
*
* @param pcb the tcp_pcb to bind (no check is done whether this pcb is
* already bound!)
* @param ipaddr the local ip address to bind to (use IP4_ADDR_ANY to bind
* to any local address
* @param port the local port to bind to
* @return ERR_USE if the port is already in use
* ERR_VAL if bind failed because the PCB is not in a valid state
* ERR_OK if bound
*/
err_t
tcp_bind(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
{
int i;
int max_pcb_list = NUM_TCP_PCB_LISTS;
struct tcp_pcb *cpcb;
#if LWIP_IPV4
/* Don't propagate NULL pointer (IPv4 ANY) to subsequent functions */
if (ipaddr == NULL) {
ipaddr = IP4_ADDR_ANY;
}
#endif /* LWIP_IPV4 */
/* still need to check for ipaddr == NULL in IPv6 only case */
if ((pcb == NULL) || (ipaddr == NULL)) {
return ERR_VAL;
}
LWIP_ERROR("tcp_bind: can only bind in state CLOSED", pcb->state == CLOSED, return ERR_VAL);
#if SO_REUSE
/* Unless the REUSEADDR flag is set,
we have to check the pcbs in TIME-WAIT state, also.
We do not dump TIME_WAIT pcb's; they can still be matched by incoming
packets using both local and remote IP addresses and ports to distinguish.
*/
if (ip_get_option(pcb, SOF_REUSEADDR)) {
max_pcb_list = NUM_TCP_PCB_LISTS_NO_TIME_WAIT;
}
#endif /* SO_REUSE */
if (port == 0) {
port = tcp_new_port();
if (port == 0) {
return ERR_BUF;
}
} else {
/* Check if the address already is in use (on all lists) */
for (i = 0; i < max_pcb_list; i++) {
for (cpcb = *tcp_pcb_lists[i]; cpcb != NULL; cpcb = cpcb->next) {
if (cpcb->local_port == port) {
#if SO_REUSE
/* Omit checking for the same port if both pcbs have REUSEADDR set.
For SO_REUSEADDR, the duplicate-check for a 5-tuple is done in
tcp_connect. */
if (!ip_get_option(pcb, SOF_REUSEADDR) ||
!ip_get_option(cpcb, SOF_REUSEADDR))
#endif /* SO_REUSE */
{
/* @todo: check accept_any_ip_version */
if ((IP_IS_V6(ipaddr) == IP_IS_V6_VAL(cpcb->local_ip)) &&
(ip_addr_isany(&cpcb->local_ip) ||
ip_addr_isany(ipaddr) ||
ip_addr_cmp(&cpcb->local_ip, ipaddr))) {
return ERR_USE;
}
}
}
}
}
}
if (!ip_addr_isany(ipaddr)) {
ip_addr_set(&pcb->local_ip, ipaddr);
}
pcb->local_port = port;
TCP_REG(&tcp_bound_pcbs, pcb);
LWIP_DEBUGF(TCP_DEBUG, ("tcp_bind: bind to port %"U16_F"\n", port));
return ERR_OK;
}
#if LWIP_CALLBACK_API
/**
* Default accept callback if no accept callback is specified by the user.
*/
static err_t
tcp_accept_null(void *arg, struct tcp_pcb *pcb, err_t err)
{
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(err);
tcp_abort(pcb);
return ERR_ABRT;
}
#endif /* LWIP_CALLBACK_API */
/**
* @ingroup tcp_raw
* Set the state of the connection to be LISTEN, which means that it
* is able to accept incoming connections. The protocol control block
* is reallocated in order to consume less memory. Setting the
* connection to LISTEN is an irreversible process.
*
* @param pcb the original tcp_pcb
* @param backlog the incoming connections queue limit
* @return tcp_pcb used for listening, consumes less memory.
*
* @note The original tcp_pcb is freed. This function therefore has to be
* called like this:
* tpcb = tcp_listen_with_backlog(tpcb, backlog);
*/
struct tcp_pcb *
tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
{
return tcp_listen_with_backlog_and_err(pcb, backlog, NULL);
}
/**
* @ingroup tcp_raw
* Set the state of the connection to be LISTEN, which means that it
* is able to accept incoming connections. The protocol control block
* is reallocated in order to consume less memory. Setting the
* connection to LISTEN is an irreversible process.
*
* @param pcb the original tcp_pcb
* @param backlog the incoming connections queue limit
* @param err when NULL is returned, this contains the error reason
* @return tcp_pcb used for listening, consumes less memory.
*
* @note The original tcp_pcb is freed. This function therefore has to be
* called like this:
* tpcb = tcp_listen_with_backlog_and_err(tpcb, backlog, &err);
*/
struct tcp_pcb *
tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err)
{
struct tcp_pcb_listen *lpcb = NULL;
err_t res;
LWIP_UNUSED_ARG(backlog);
LWIP_ERROR("tcp_listen: pcb already connected", pcb->state == CLOSED, res = ERR_CLSD; goto done);
/* already listening? */
if (pcb->state == LISTEN) {
lpcb = (struct tcp_pcb_listen*)pcb;
res = ERR_ALREADY;
goto done;
}
#if SO_REUSE
if (ip_get_option(pcb, SOF_REUSEADDR)) {
/* Since SOF_REUSEADDR allows reusing a local address before the pcb's usage
is declared (listen-/connection-pcb), we have to make sure now that
this port is only used once for every local IP. */
for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = lpcb->next) {
if ((lpcb->local_port == pcb->local_port) &&
ip_addr_cmp(&lpcb->local_ip, &pcb->local_ip)) {
/* this address/port is already used */
lpcb = NULL;
res = ERR_USE;
goto done;
}
}
}
#endif /* SO_REUSE */
lpcb = (struct tcp_pcb_listen *)memp_malloc(MEMP_TCP_PCB_LISTEN);
if (lpcb == NULL) {
res = ERR_MEM;
goto done;
}
lpcb->callback_arg = pcb->callback_arg;
lpcb->local_port = pcb->local_port;
lpcb->state = LISTEN;
lpcb->prio = pcb->prio;
lpcb->so_options = pcb->so_options;
lpcb->ttl = pcb->ttl;
lpcb->tos = pcb->tos;
#if LWIP_IPV4 && LWIP_IPV6
IP_SET_TYPE_VAL(lpcb->remote_ip, pcb->local_ip.type);
#endif /* LWIP_IPV4 && LWIP_IPV6 */
ip_addr_copy(lpcb->local_ip, pcb->local_ip);
if (pcb->local_port != 0) {
TCP_RMV(&tcp_bound_pcbs, pcb);
}
memp_free(MEMP_TCP_PCB, pcb);
#if LWIP_CALLBACK_API
lpcb->accept = tcp_accept_null;
#endif /* LWIP_CALLBACK_API */
#if TCP_LISTEN_BACKLOG
lpcb->accepts_pending = 0;
tcp_backlog_set(lpcb, backlog);
#endif /* TCP_LISTEN_BACKLOG */
TCP_REG(&tcp_listen_pcbs.pcbs, (struct tcp_pcb *)lpcb);
res = ERR_OK;
done:
if (err != NULL) {
*err = res;
}
return (struct tcp_pcb *)lpcb;
}
/**
* Update the state that tracks the available window space to advertise.
*
* Returns how much extra window would be advertised if we sent an
* update now.
*/
u32_t
tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb)
{
u32_t new_right_edge = pcb->rcv_nxt + pcb->rcv_wnd;
if (TCP_SEQ_GEQ(new_right_edge, pcb->rcv_ann_right_edge + LWIP_MIN((TCP_WND / 2), pcb->mss))) {
/* we can advertise more window */
pcb->rcv_ann_wnd = pcb->rcv_wnd;
return new_right_edge - pcb->rcv_ann_right_edge;
} else {
if (TCP_SEQ_GT(pcb->rcv_nxt, pcb->rcv_ann_right_edge)) {
/* Can happen due to other end sending out of advertised window,
* but within actual available (but not yet advertised) window */
pcb->rcv_ann_wnd = 0;
} else {
/* keep the right edge of window constant */
u32_t new_rcv_ann_wnd = pcb->rcv_ann_right_edge - pcb->rcv_nxt;
#if !LWIP_WND_SCALE
LWIP_ASSERT("new_rcv_ann_wnd <= 0xffff", new_rcv_ann_wnd <= 0xffff);
#endif
pcb->rcv_ann_wnd = (tcpwnd_size_t)new_rcv_ann_wnd;
}
return 0;
}
}
/**
* @ingroup tcp_raw
* This function should be called by the application when it has
* processed the data. The purpose is to advertise a larger window
* when the data has been processed.
*
* @param pcb the tcp_pcb for which data is read
* @param len the amount of bytes that have been read by the application
*/
void
tcp_recved(struct tcp_pcb *pcb, u16_t len)
{
int wnd_inflation;
/* pcb->state LISTEN not allowed here */
LWIP_ASSERT("don't call tcp_recved for listen-pcbs",
pcb->state != LISTEN);
pcb->rcv_wnd += len;
if (pcb->rcv_wnd > TCP_WND_MAX(pcb)) {
pcb->rcv_wnd = TCP_WND_MAX(pcb);
} else if (pcb->rcv_wnd == 0) {
/* rcv_wnd overflowed */
if ((pcb->state == CLOSE_WAIT) || (pcb->state == LAST_ACK)) {
/* In passive close, we allow this, since the FIN bit is added to rcv_wnd
by the stack itself, since it is not mandatory for an application
to call tcp_recved() for the FIN bit, but e.g. the netconn API does so. */
pcb->rcv_wnd = TCP_WND_MAX(pcb);
} else {
LWIP_ASSERT("tcp_recved: len wrapped rcv_wnd\n", 0);
}
}
wnd_inflation = tcp_update_rcv_ann_wnd(pcb);
/* If the change in the right edge of window is significant (default
* watermark is TCP_WND/4), then send an explicit update now.
* Otherwise wait for a packet to be sent in the normal course of
* events (or more window to be available later) */
if (wnd_inflation >= TCP_WND_UPDATE_THRESHOLD) {
tcp_ack_now(pcb);
tcp_output(pcb);
}
LWIP_DEBUGF(TCP_DEBUG, ("tcp_recved: received %"U16_F" bytes, wnd %"TCPWNDSIZE_F" (%"TCPWNDSIZE_F").\n",
len, pcb->rcv_wnd, (u16_t)(TCP_WND_MAX(pcb) - pcb->rcv_wnd)));
}
/**
* Allocate a new local TCP port.
*
* @return a new (free) local TCP port number
*/
static u16_t
tcp_new_port(void)
{
u8_t i;
u16_t n = 0;
struct tcp_pcb *pcb;
again:
if (tcp_port++ == TCP_LOCAL_PORT_RANGE_END) {
tcp_port = TCP_LOCAL_PORT_RANGE_START;
}
/* Check all PCB lists. */
for (i = 0; i < NUM_TCP_PCB_LISTS; i++) {
for (pcb = *tcp_pcb_lists[i]; pcb != NULL; pcb = pcb->next) {
if (pcb->local_port == tcp_port) {
if (++n > (TCP_LOCAL_PORT_RANGE_END - TCP_LOCAL_PORT_RANGE_START)) {
return 0;
}
goto again;
}
}
}
return tcp_port;
}
/**
* @ingroup tcp_raw
* Connects to another host. The function given as the "connected"
* argument will be called when the connection has been established.
*
* @param pcb the tcp_pcb used to establish the connection
* @param ipaddr the remote ip address to connect to
* @param port the remote tcp port to connect to
* @param connected callback function to call when connected (on error,
the err calback will be called)
* @return ERR_VAL if invalid arguments are given
* ERR_OK if connect request has been sent
* other err_t values if connect request couldn't be sent
*/
err_t
tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
tcp_connected_fn connected)
{
err_t ret;
u32_t iss;
u16_t old_local_port;
if ((pcb == NULL) || (ipaddr == NULL)) {
return ERR_VAL;
}
LWIP_ERROR("tcp_connect: can only connect from state CLOSED", pcb->state == CLOSED, return ERR_ISCONN);
LWIP_DEBUGF(TCP_DEBUG, ("tcp_connect to port %"U16_F"\n", port));
ip_addr_set(&pcb->remote_ip, ipaddr);
pcb->remote_port = port;
/* check if we have a route to the remote host */
if (ip_addr_isany(&pcb->local_ip)) {
/* no local IP address set, yet. */
struct netif *netif;
const ip_addr_t *local_ip;
ip_route_get_local_ip(&pcb->local_ip, &pcb->remote_ip, netif, local_ip);
if ((netif == NULL) || (local_ip == NULL)) {
/* Don't even try to send a SYN packet if we have no route
since that will fail. */
return ERR_RTE;
}
/* Use the address as local address of the pcb. */
ip_addr_copy(pcb->local_ip, *local_ip);
}
old_local_port = pcb->local_port;
if (pcb->local_port == 0) {
pcb->local_port = tcp_new_port();
if (pcb->local_port == 0) {
return ERR_BUF;
}
} else {
#if SO_REUSE
if (ip_get_option(pcb, SOF_REUSEADDR)) {
/* Since SOF_REUSEADDR allows reusing a local address, we have to make sure
now that the 5-tuple is unique. */
struct tcp_pcb *cpcb;
int i;
/* Don't check listen- and bound-PCBs, check active- and TIME-WAIT PCBs. */
for (i = 2; i < NUM_TCP_PCB_LISTS; i++) {
for (cpcb = *tcp_pcb_lists[i]; cpcb != NULL; cpcb = cpcb->next) {
if ((cpcb->local_port == pcb->local_port) &&
(cpcb->remote_port == port) &&
ip_addr_cmp(&cpcb->local_ip, &pcb->local_ip) &&
ip_addr_cmp(&cpcb->remote_ip, ipaddr)) {
/* linux returns EISCONN here, but ERR_USE should be OK for us */
return ERR_USE;
}
}
}
}
#endif /* SO_REUSE */
}
iss = tcp_next_iss(pcb);
pcb->rcv_nxt = 0;
pcb->snd_nxt = iss;
pcb->lastack = iss - 1;
pcb->snd_wl2 = iss - 1;
pcb->snd_lbb = iss - 1;
/* Start with a window that does not need scaling. When window scaling is
enabled and used, the window is enlarged when both sides agree on scaling. */
pcb->rcv_wnd = pcb->rcv_ann_wnd = TCPWND_MIN16(TCP_WND);
pcb->rcv_ann_right_edge = pcb->rcv_nxt;
pcb->snd_wnd = TCP_WND;
/* As initial send MSS, we use TCP_MSS but limit it to 536.
The send MSS is updated when an MSS option is received. */
pcb->mss = INITIAL_MSS;
#if TCP_CALCULATE_EFF_SEND_MSS
pcb->mss = tcp_eff_send_mss(pcb->mss, &pcb->local_ip, &pcb->remote_ip);
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
pcb->cwnd = 1;
#if LWIP_CALLBACK_API
pcb->connected = connected;
#else /* LWIP_CALLBACK_API */
LWIP_UNUSED_ARG(connected);
#endif /* LWIP_CALLBACK_API */
/* Send a SYN together with the MSS option. */
ret = tcp_enqueue_flags(pcb, TCP_SYN);
if (ret == ERR_OK) {
/* SYN segment was enqueued, changed the pcbs state now */
pcb->state = SYN_SENT;
if (old_local_port != 0) {
TCP_RMV(&tcp_bound_pcbs, pcb);
}
TCP_REG_ACTIVE(pcb);
MIB2_STATS_INC(mib2.tcpactiveopens);
tcp_output(pcb);
}
return ret;
}
/**
* Called every 500 ms and implements the retransmission timer and the timer that
* removes PCBs that have been in TIME-WAIT for enough time. It also increments
* various timers such as the inactivity timer in each PCB.
*
* Automatically called from tcp_tmr().
*/
void
tcp_slowtmr(void)
{
struct tcp_pcb *pcb, *prev;
tcpwnd_size_t eff_wnd;
u8_t pcb_remove; /* flag if a PCB should be removed */
u8_t pcb_reset; /* flag if a RST should be sent when removing */
err_t err;
err = ERR_OK;
++tcp_ticks;
++tcp_timer_ctr;
tcp_slowtmr_start:
/* Steps through all of the active PCBs. */
prev = NULL;
pcb = tcp_active_pcbs;
if (pcb == NULL) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: no active pcbs\n"));
}
while (pcb != NULL) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: processing active pcb\n"));
LWIP_ASSERT("tcp_slowtmr: active pcb->state != CLOSED\n", pcb->state != CLOSED);
LWIP_ASSERT("tcp_slowtmr: active pcb->state != LISTEN\n", pcb->state != LISTEN);
LWIP_ASSERT("tcp_slowtmr: active pcb->state != TIME-WAIT\n", pcb->state != TIME_WAIT);
if (pcb->last_timer == tcp_timer_ctr) {
/* skip this pcb, we have already processed it */
pcb = pcb->next;
continue;
}
pcb->last_timer = tcp_timer_ctr;
pcb_remove = 0;
pcb_reset = 0;
if (pcb->state == SYN_SENT && pcb->nrtx >= TCP_SYNMAXRTX) {
++pcb_remove;
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: max SYN retries reached\n"));
}
else if (pcb->nrtx >= TCP_MAXRTX) {
++pcb_remove;
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: max DATA retries reached\n"));
} else {
if (pcb->persist_backoff > 0) {
/* If snd_wnd is zero, use persist timer to send 1 byte probes
* instead of using the standard retransmission mechanism. */
u8_t backoff_cnt = tcp_persist_backoff[pcb->persist_backoff-1];
if (pcb->persist_cnt < backoff_cnt) {
pcb->persist_cnt++;
}
if (pcb->persist_cnt >= backoff_cnt) {
if (tcp_zero_window_probe(pcb) == ERR_OK) {
pcb->persist_cnt = 0;
if (pcb->persist_backoff < sizeof(tcp_persist_backoff)) {
pcb->persist_backoff++;
}
}
}
} else {
/* Increase the retransmission timer if it is running */
if (pcb->rtime >= 0) {
++pcb->rtime;
}
if (pcb->unacked != NULL && pcb->rtime >= pcb->rto) {
/* Time for a retransmission. */
LWIP_DEBUGF(TCP_RTO_DEBUG, ("tcp_slowtmr: rtime %"S16_F
" pcb->rto %"S16_F"\n",
pcb->rtime, pcb->rto));
/* Double retransmission time-out unless we are trying to
* connect to somebody (i.e., we are in SYN_SENT). */
if (pcb->state != SYN_SENT) {
u8_t backoff_idx = LWIP_MIN(pcb->nrtx, sizeof(tcp_backoff)-1);
pcb->rto = ((pcb->sa >> 3) + pcb->sv) << tcp_backoff[backoff_idx];
}
/* Reset the retransmission timer. */
pcb->rtime = 0;
/* Reduce congestion window and ssthresh. */
eff_wnd = LWIP_MIN(pcb->cwnd, pcb->snd_wnd);
pcb->ssthresh = eff_wnd >> 1;
if (pcb->ssthresh < (tcpwnd_size_t)(pcb->mss << 1)) {
pcb->ssthresh = (pcb->mss << 1);
}
pcb->cwnd = pcb->mss;
LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_slowtmr: cwnd %"TCPWNDSIZE_F
" ssthresh %"TCPWNDSIZE_F"\n",
pcb->cwnd, pcb->ssthresh));
/* The following needs to be called AFTER cwnd is set to one
mss - STJ */
tcp_rexmit_rto(pcb);
}
}
}
/* Check if this PCB has stayed too long in FIN-WAIT-2 */
if (pcb->state == FIN_WAIT_2) {
/* If this PCB is in FIN_WAIT_2 because of SHUT_WR don't let it time out. */
if (pcb->flags & TF_RXCLOSED) {
/* PCB was fully closed (either through close() or SHUT_RDWR):
normal FIN-WAIT timeout handling. */
if ((u32_t)(tcp_ticks - pcb->tmr) >
TCP_FIN_WAIT_TIMEOUT / TCP_SLOW_INTERVAL) {
++pcb_remove;
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in FIN-WAIT-2\n"));
}
}
}
/* Check if KEEPALIVE should be sent */
if (ip_get_option(pcb, SOF_KEEPALIVE) &&
((pcb->state == ESTABLISHED) ||
(pcb->state == CLOSE_WAIT))) {
if ((u32_t)(tcp_ticks - pcb->tmr) >
(pcb->keep_idle + TCP_KEEP_DUR(pcb)) / TCP_SLOW_INTERVAL)
{
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: KEEPALIVE timeout. Aborting connection to "));
ip_addr_debug_print(TCP_DEBUG, &pcb->remote_ip);
LWIP_DEBUGF(TCP_DEBUG, ("\n"));
++pcb_remove;
++pcb_reset;
} else if ((u32_t)(tcp_ticks - pcb->tmr) >
(pcb->keep_idle + pcb->keep_cnt_sent * TCP_KEEP_INTVL(pcb))
/ TCP_SLOW_INTERVAL)
{
err = tcp_keepalive(pcb);
if (err == ERR_OK) {
pcb->keep_cnt_sent++;
}
}
}
/* If this PCB has queued out of sequence data, but has been
inactive for too long, will drop the data (it will eventually
be retransmitted). */
#if TCP_QUEUE_OOSEQ
if (pcb->ooseq != NULL &&
(u32_t)tcp_ticks - pcb->tmr >= pcb->rto * TCP_OOSEQ_TIMEOUT) {
tcp_segs_free(pcb->ooseq);
pcb->ooseq = NULL;
LWIP_DEBUGF(TCP_CWND_DEBUG, ("tcp_slowtmr: dropping OOSEQ queued data\n"));
}
#endif /* TCP_QUEUE_OOSEQ */
/* Check if this PCB has stayed too long in SYN-RCVD */
if (pcb->state == SYN_RCVD) {
if ((u32_t)(tcp_ticks - pcb->tmr) >
TCP_SYN_RCVD_TIMEOUT / TCP_SLOW_INTERVAL) {
++pcb_remove;
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in SYN-RCVD\n"));
}
}
/* Check if this PCB has stayed too long in LAST-ACK */
if (pcb->state == LAST_ACK) {
if ((u32_t)(tcp_ticks - pcb->tmr) > 2 * TCP_MSL / TCP_SLOW_INTERVAL) {
++pcb_remove;
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: removing pcb stuck in LAST-ACK\n"));
}
}
/* If the PCB should be removed, do it. */
if (pcb_remove) {
struct tcp_pcb *pcb2;
#if LWIP_CALLBACK_API
tcp_err_fn err_fn = pcb->errf;
#endif /* LWIP_CALLBACK_API */
void *err_arg;
enum tcp_state last_state;
tcp_pcb_purge(pcb);
/* Remove PCB from tcp_active_pcbs list. */
if (prev != NULL) {
LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_active_pcbs", pcb != tcp_active_pcbs);
prev->next = pcb->next;
} else {
/* This PCB was the first. */
LWIP_ASSERT("tcp_slowtmr: first pcb == tcp_active_pcbs", tcp_active_pcbs == pcb);
tcp_active_pcbs = pcb->next;
}
if (pcb_reset) {
tcp_rst(pcb->snd_nxt, pcb->rcv_nxt, &pcb->local_ip, &pcb->remote_ip,
pcb->local_port, pcb->remote_port);
}
err_arg = pcb->callback_arg;
last_state = pcb->state;
pcb2 = pcb;
pcb = pcb->next;
memp_free(MEMP_TCP_PCB, pcb2);
tcp_active_pcbs_changed = 0;
TCP_EVENT_ERR(last_state, err_fn, err_arg, ERR_ABRT);
if (tcp_active_pcbs_changed) {
goto tcp_slowtmr_start;
}
} else {
/* get the 'next' element now and work with 'prev' below (in case of abort) */
prev = pcb;
pcb = pcb->next;
/* We check if we should poll the connection. */
++prev->polltmr;
if (prev->polltmr >= prev->pollinterval) {
prev->polltmr = 0;
LWIP_DEBUGF(TCP_DEBUG, ("tcp_slowtmr: polling application\n"));
tcp_active_pcbs_changed = 0;
TCP_EVENT_POLL(prev, err);
if (tcp_active_pcbs_changed) {
goto tcp_slowtmr_start;
}
/* if err == ERR_ABRT, 'prev' is already deallocated */
if (err == ERR_OK) {
tcp_output(prev);
}
}
}
}
/* Steps through all of the TIME-WAIT PCBs. */
prev = NULL;
pcb = tcp_tw_pcbs;
while (pcb != NULL) {
LWIP_ASSERT("tcp_slowtmr: TIME-WAIT pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
pcb_remove = 0;
/* Check if this PCB has stayed long enough in TIME-WAIT */
if ((u32_t)(tcp_ticks - pcb->tmr) > 2 * TCP_MSL / TCP_SLOW_INTERVAL) {
++pcb_remove;
}
/* If the PCB should be removed, do it. */
if (pcb_remove) {
struct tcp_pcb *pcb2;
tcp_pcb_purge(pcb);
/* Remove PCB from tcp_tw_pcbs list. */
if (prev != NULL) {
LWIP_ASSERT("tcp_slowtmr: middle tcp != tcp_tw_pcbs", pcb != tcp_tw_pcbs);
prev->next = pcb->next;
} else {
/* This PCB was the first. */
LWIP_ASSERT("tcp_slowtmr: first pcb == tcp_tw_pcbs", tcp_tw_pcbs == pcb);
tcp_tw_pcbs = pcb->next;
}
pcb2 = pcb;
pcb = pcb->next;
memp_free(MEMP_TCP_PCB, pcb2);
} else {
prev = pcb;
pcb = pcb->next;
}
}
}
/**
* Is called every TCP_FAST_INTERVAL (250 ms) and process data previously
* "refused" by upper layer (application) and sends delayed ACKs.
*
* Automatically called from tcp_tmr().
*/
void
tcp_fasttmr(void)
{
struct tcp_pcb *pcb;
++tcp_timer_ctr;
tcp_fasttmr_start:
pcb = tcp_active_pcbs;
while (pcb != NULL) {
if (pcb->last_timer != tcp_timer_ctr) {
struct tcp_pcb *next;
pcb->last_timer = tcp_timer_ctr;
/* send delayed ACKs */
if (pcb->flags & TF_ACK_DELAY) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_fasttmr: delayed ACK\n"));
tcp_ack_now(pcb);
tcp_output(pcb);
pcb->flags &= ~(TF_ACK_DELAY | TF_ACK_NOW);
}
/* send pending FIN */
if (pcb->flags & TF_CLOSEPEND) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_fasttmr: pending FIN\n"));
pcb->flags &= ~(TF_CLOSEPEND);
tcp_close_shutdown_fin(pcb);
}
next = pcb->next;
/* If there is data which was previously "refused" by upper layer */
if (pcb->refused_data != NULL) {
tcp_active_pcbs_changed = 0;
tcp_process_refused_data(pcb);
if (tcp_active_pcbs_changed) {
/* application callback has changed the pcb list: restart the loop */
goto tcp_fasttmr_start;
}
}
pcb = next;
} else {
pcb = pcb->next;
}
}
}
/** Call tcp_output for all active pcbs that have TF_NAGLEMEMERR set */
void
tcp_txnow(void)
{
struct tcp_pcb *pcb;
for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
if (pcb->flags & TF_NAGLEMEMERR) {
tcp_output(pcb);
}
}
}
/** Pass pcb->refused_data to the recv callback */
err_t
tcp_process_refused_data(struct tcp_pcb *pcb)
{
#if TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
struct pbuf *rest;
while (pcb->refused_data != NULL)
#endif /* TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
{
err_t err;
u8_t refused_flags = pcb->refused_data->flags;
/* set pcb->refused_data to NULL in case the callback frees it and then
closes the pcb */
struct pbuf *refused_data = pcb->refused_data;
#if TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
pbuf_split_64k(refused_data, &rest);
pcb->refused_data = rest;
#else /* TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
pcb->refused_data = NULL;
#endif /* TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
/* Notify again application with data previously received. */
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: notify kept packet\n"));
TCP_EVENT_RECV(pcb, refused_data, ERR_OK, err);
if (err == ERR_OK) {
/* did refused_data include a FIN? */
if (refused_flags & PBUF_FLAG_TCP_FIN
#if TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
&& (rest == NULL)
#endif /* TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
) {
/* correct rcv_wnd as the application won't call tcp_recved()
for the FIN's seqno */
if (pcb->rcv_wnd != TCP_WND_MAX(pcb)) {
pcb->rcv_wnd++;
}
TCP_EVENT_CLOSED(pcb, err);
if (err == ERR_ABRT) {
return ERR_ABRT;
}
}
} else if (err == ERR_ABRT) {
/* if err == ERR_ABRT, 'pcb' is already deallocated */
/* Drop incoming packets because pcb is "full" (only if the incoming
segment contains data). */
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: drop incoming packets, because pcb is \"full\"\n"));
return ERR_ABRT;
} else {
/* data is still refused, pbuf is still valid (go on for ACK-only packets) */
#if TCP_QUEUE_OOSEQ && LWIP_WND_SCALE
if (rest != NULL) {
pbuf_cat(refused_data, rest);
}
#endif /* TCP_QUEUE_OOSEQ && LWIP_WND_SCALE */
pcb->refused_data = refused_data;
return ERR_INPROGRESS;
}
}
return ERR_OK;
}
/**
* Deallocates a list of TCP segments (tcp_seg structures).
*
* @param seg tcp_seg list of TCP segments to free
*/
void
tcp_segs_free(struct tcp_seg *seg)
{
while (seg != NULL) {
struct tcp_seg *next = seg->next;
tcp_seg_free(seg);
seg = next;
}
}
/**
* Frees a TCP segment (tcp_seg structure).
*
* @param seg single tcp_seg to free
*/
void
tcp_seg_free(struct tcp_seg *seg)
{
if (seg != NULL) {
if (seg->p != NULL) {
pbuf_free(seg->p);
#if TCP_DEBUG
seg->p = NULL;
#endif /* TCP_DEBUG */
}
memp_free(MEMP_TCP_SEG, seg);
}
}
/**
* Sets the priority of a connection.
*
* @param pcb the tcp_pcb to manipulate
* @param prio new priority
*/
void
tcp_setprio(struct tcp_pcb *pcb, u8_t prio)
{
pcb->prio = prio;
}
#if TCP_QUEUE_OOSEQ
/**
* Returns a copy of the given TCP segment.
* The pbuf and data are not copied, only the pointers
*
* @param seg the old tcp_seg
* @return a copy of seg
*/
struct tcp_seg *
tcp_seg_copy(struct tcp_seg *seg)
{
struct tcp_seg *cseg;
cseg = (struct tcp_seg *)memp_malloc(MEMP_TCP_SEG);
if (cseg == NULL) {
return NULL;
}
SMEMCPY((u8_t *)cseg, (const u8_t *)seg, sizeof(struct tcp_seg));
pbuf_ref(cseg->p);
return cseg;
}
#endif /* TCP_QUEUE_OOSEQ */
#if LWIP_CALLBACK_API
/**
* Default receive callback that is called if the user didn't register
* a recv callback for the pcb.
*/
err_t
tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
LWIP_UNUSED_ARG(arg);
if (p != NULL) {
tcp_recved(pcb, p->tot_len);
pbuf_free(p);
} else if (err == ERR_OK) {
return tcp_close(pcb);
}
return ERR_OK;
}
#endif /* LWIP_CALLBACK_API */
/**
* Kills the oldest active connection that has the same or lower priority than
* 'prio'.
*
* @param prio minimum priority
*/
static void
tcp_kill_prio(u8_t prio)
{
struct tcp_pcb *pcb, *inactive;
u32_t inactivity;
u8_t mprio;
mprio = LWIP_MIN(TCP_PRIO_MAX, prio);
/* We kill the oldest active connection that has lower priority than prio. */
inactivity = 0;
inactive = NULL;
for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
if (pcb->prio <= mprio &&
(u32_t)(tcp_ticks - pcb->tmr) >= inactivity) {
inactivity = tcp_ticks - pcb->tmr;
inactive = pcb;
mprio = pcb->prio;
}
}
if (inactive != NULL) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_prio: killing oldest PCB %p (%"S32_F")\n",
(void *)inactive, inactivity));
tcp_abort(inactive);
}
}
/**
* Kills the oldest connection that is in specific state.
* Called from tcp_alloc() for LAST_ACK and CLOSING if no more connections are available.
*/
static void
tcp_kill_state(enum tcp_state state)
{
struct tcp_pcb *pcb, *inactive;
u32_t inactivity;
LWIP_ASSERT("invalid state", (state == CLOSING) || (state == LAST_ACK));
inactivity = 0;
inactive = NULL;
/* Go through the list of active pcbs and get the oldest pcb that is in state
CLOSING/LAST_ACK. */
for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
if (pcb->state == state) {
if ((u32_t)(tcp_ticks - pcb->tmr) >= inactivity) {
inactivity = tcp_ticks - pcb->tmr;
inactive = pcb;
}
}
}
if (inactive != NULL) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_closing: killing oldest %s PCB %p (%"S32_F")\n",
tcp_state_str[state], (void *)inactive, inactivity));
/* Don't send a RST, since no data is lost. */
tcp_abandon(inactive, 0);
}
}
/**
* Kills the oldest connection that is in TIME_WAIT state.
* Called from tcp_alloc() if no more connections are available.
*/
static void
tcp_kill_timewait(void)
{
struct tcp_pcb *pcb, *inactive;
u32_t inactivity;
inactivity = 0;
inactive = NULL;
/* Go through the list of TIME_WAIT pcbs and get the oldest pcb. */
for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
if ((u32_t)(tcp_ticks - pcb->tmr) >= inactivity) {
inactivity = tcp_ticks - pcb->tmr;
inactive = pcb;
}
}
if (inactive != NULL) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_kill_timewait: killing oldest TIME-WAIT PCB %p (%"S32_F")\n",
(void *)inactive, inactivity));
tcp_abort(inactive);
}
}
/**
* Allocate a new tcp_pcb structure.
*
* @param prio priority for the new pcb
* @return a new tcp_pcb that initially is in state CLOSED
*/
struct tcp_pcb *
tcp_alloc(u8_t prio)
{
struct tcp_pcb *pcb;
pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
if (pcb == NULL) {
/* Try killing oldest connection in TIME-WAIT. */
LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest TIME-WAIT connection\n"));
tcp_kill_timewait();
/* Try to allocate a tcp_pcb again. */
pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
if (pcb == NULL) {
/* Try killing oldest connection in LAST-ACK (these wouldn't go to TIME-WAIT). */
LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest LAST-ACK connection\n"));
tcp_kill_state(LAST_ACK);
/* Try to allocate a tcp_pcb again. */
pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
if (pcb == NULL) {
/* Try killing oldest connection in CLOSING. */
LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing off oldest CLOSING connection\n"));
tcp_kill_state(CLOSING);
/* Try to allocate a tcp_pcb again. */
pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
if (pcb == NULL) {
/* Try killing active connections with lower priority than the new one. */
LWIP_DEBUGF(TCP_DEBUG, ("tcp_alloc: killing connection with prio lower than %d\n", prio));
tcp_kill_prio(prio);
/* Try to allocate a tcp_pcb again. */
pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
if (pcb != NULL) {
/* adjust err stats: memp_malloc failed multiple times before */
MEMP_STATS_DEC(err, MEMP_TCP_PCB);
}
}
if (pcb != NULL) {
/* adjust err stats: memp_malloc failed multiple times before */
MEMP_STATS_DEC(err, MEMP_TCP_PCB);
}
}
if (pcb != NULL) {
/* adjust err stats: memp_malloc failed multiple times before */
MEMP_STATS_DEC(err, MEMP_TCP_PCB);
}
}
if (pcb != NULL) {
/* adjust err stats: memp_malloc failed above */
MEMP_STATS_DEC(err, MEMP_TCP_PCB);
}
}
if (pcb != NULL) {
/* zero out the whole pcb, so there is no need to initialize members to zero */
memset(pcb, 0, sizeof(struct tcp_pcb));
pcb->prio = prio;
pcb->snd_buf = TCP_SND_BUF;
/* Start with a window that does not need scaling. When window scaling is
enabled and used, the window is enlarged when both sides agree on scaling. */
pcb->rcv_wnd = pcb->rcv_ann_wnd = TCPWND_MIN16(TCP_WND);
pcb->ttl = TCP_TTL;
/* As initial send MSS, we use TCP_MSS but limit it to 536.
The send MSS is updated when an MSS option is received. */
pcb->mss = INITIAL_MSS;
pcb->rto = 3000 / TCP_SLOW_INTERVAL;
pcb->sv = 3000 / TCP_SLOW_INTERVAL;
pcb->rtime = -1;
pcb->cwnd = 1;
pcb->tmr = tcp_ticks;
pcb->last_timer = tcp_timer_ctr;
/* RFC 5681 recommends setting ssthresh abritrarily high and gives an example
of using the largest advertised receive window. We've seen complications with
receiving TCPs that use window scaling and/or window auto-tuning where the
initial advertised window is very small and then grows rapidly once the
connection is established. To avoid these complications, we set ssthresh to the
largest effective cwnd (amount of in-flight data) that the sender can have. */
pcb->ssthresh = TCP_SND_BUF;
#if LWIP_CALLBACK_API
pcb->recv = tcp_recv_null;
#endif /* LWIP_CALLBACK_API */
/* Init KEEPALIVE timer */
pcb->keep_idle = TCP_KEEPIDLE_DEFAULT;
#if LWIP_TCP_KEEPALIVE
pcb->keep_intvl = TCP_KEEPINTVL_DEFAULT;
pcb->keep_cnt = TCP_KEEPCNT_DEFAULT;
#endif /* LWIP_TCP_KEEPALIVE */
}
return pcb;
}
/**
* @ingroup tcp_raw
* Creates a new TCP protocol control block but doesn't place it on
* any of the TCP PCB lists.
* The pcb is not put on any list until binding using tcp_bind().
*
* @internal: Maybe there should be a idle TCP PCB list where these
* PCBs are put on. Port reservation using tcp_bind() is implemented but
* allocated pcbs that are not bound can't be killed automatically if wanting
* to allocate a pcb with higher prio (@see tcp_kill_prio())
*
* @return a new tcp_pcb that initially is in state CLOSED
*/
struct tcp_pcb *
tcp_new(void)
{
return tcp_alloc(TCP_PRIO_NORMAL);
}
/**
* @ingroup tcp_raw
* Creates a new TCP protocol control block but doesn't
* place it on any of the TCP PCB lists.
* The pcb is not put on any list until binding using tcp_bind().
*
* @param type IP address type, see @ref lwip_ip_addr_type definitions.
* If you want to listen to IPv4 and IPv6 (dual-stack) connections,
* supply @ref IPADDR_TYPE_ANY as argument and bind to @ref IP_ANY_TYPE.
* @return a new tcp_pcb that initially is in state CLOSED
*/
struct tcp_pcb *
tcp_new_ip_type(u8_t type)
{
struct tcp_pcb * pcb;
pcb = tcp_alloc(TCP_PRIO_NORMAL);
#if LWIP_IPV4 && LWIP_IPV6
if (pcb != NULL) {
IP_SET_TYPE_VAL(pcb->local_ip, type);
IP_SET_TYPE_VAL(pcb->remote_ip, type);
}
#else
LWIP_UNUSED_ARG(type);
#endif /* LWIP_IPV4 && LWIP_IPV6 */
return pcb;
}
/**
* @ingroup tcp_raw
* Used to specify the argument that should be passed callback
* functions.
*
* @param pcb tcp_pcb to set the callback argument
* @param arg void pointer argument to pass to callback functions
*/
void
tcp_arg(struct tcp_pcb *pcb, void *arg)
{
/* This function is allowed to be called for both listen pcbs and
connection pcbs. */
if (pcb != NULL) {
pcb->callback_arg = arg;
}
}
#if LWIP_CALLBACK_API
/**
* @ingroup tcp_raw
* Used to specify the function that should be called when a TCP
* connection receives data.
*
* @param pcb tcp_pcb to set the recv callback
* @param recv callback function to call for this pcb when data is received
*/
void
tcp_recv(struct tcp_pcb *pcb, tcp_recv_fn recv)
{
if (pcb != NULL) {
LWIP_ASSERT("invalid socket state for recv callback", pcb->state != LISTEN);
pcb->recv = recv;
}
}
/**
* @ingroup tcp_raw
* Used to specify the function that should be called when TCP data
* has been successfully delivered to the remote host.
*
* @param pcb tcp_pcb to set the sent callback
* @param sent callback function to call for this pcb when data is successfully sent
*/
void
tcp_sent(struct tcp_pcb *pcb, tcp_sent_fn sent)
{
if (pcb != NULL) {
LWIP_ASSERT("invalid socket state for sent callback", pcb->state != LISTEN);
pcb->sent = sent;
}
}
/**
* @ingroup tcp_raw
* Used to specify the function that should be called when a fatal error
* has occurred on the connection.
*
* @note The corresponding pcb is already freed when this callback is called!
*
* @param pcb tcp_pcb to set the err callback
* @param err callback function to call for this pcb when a fatal error
* has occurred on the connection
*/
void
tcp_err(struct tcp_pcb *pcb, tcp_err_fn err)
{
if (pcb != NULL) {
LWIP_ASSERT("invalid socket state for err callback", pcb->state != LISTEN);
pcb->errf = err;
}
}
/**
* @ingroup tcp_raw
* Used for specifying the function that should be called when a
* LISTENing connection has been connected to another host.
*
* @param pcb tcp_pcb to set the accept callback
* @param accept callback function to call for this pcb when LISTENing
* connection has been connected to another host
*/
void
tcp_accept(struct tcp_pcb *pcb, tcp_accept_fn accept)
{
if ((pcb != NULL) && (pcb->state == LISTEN)) {
struct tcp_pcb_listen *lpcb = (struct tcp_pcb_listen*)pcb;
lpcb->accept = accept;
}
}
#endif /* LWIP_CALLBACK_API */
/**
* @ingroup tcp_raw
* Used to specify the function that should be called periodically
* from TCP. The interval is specified in terms of the TCP coarse
* timer interval, which is called twice a second.
*
*/
void
tcp_poll(struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval)
{
LWIP_ASSERT("invalid socket state for poll", pcb->state != LISTEN);
#if LWIP_CALLBACK_API
pcb->poll = poll;
#else /* LWIP_CALLBACK_API */
LWIP_UNUSED_ARG(poll);
#endif /* LWIP_CALLBACK_API */
pcb->pollinterval = interval;
}
/**
* Purges a TCP PCB. Removes any buffered data and frees the buffer memory
* (pcb->ooseq, pcb->unsent and pcb->unacked are freed).
*
* @param pcb tcp_pcb to purge. The pcb itself is not deallocated!
*/
void
tcp_pcb_purge(struct tcp_pcb *pcb)
{
if (pcb->state != CLOSED &&
pcb->state != TIME_WAIT &&
pcb->state != LISTEN) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge\n"));
tcp_backlog_accepted(pcb);
if (pcb->refused_data != NULL) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->refused_data\n"));
pbuf_free(pcb->refused_data);
pcb->refused_data = NULL;
}
if (pcb->unsent != NULL) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: not all data sent\n"));
}
if (pcb->unacked != NULL) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->unacked\n"));
}
#if TCP_QUEUE_OOSEQ
if (pcb->ooseq != NULL) {
LWIP_DEBUGF(TCP_DEBUG, ("tcp_pcb_purge: data left on ->ooseq\n"));
}
tcp_segs_free(pcb->ooseq);
pcb->ooseq = NULL;
#endif /* TCP_QUEUE_OOSEQ */
/* Stop the retransmission timer as it will expect data on unacked
queue if it fires */
pcb->rtime = -1;
tcp_segs_free(pcb->unsent);
tcp_segs_free(pcb->unacked);
pcb->unacked = pcb->unsent = NULL;
#if TCP_OVERSIZE
pcb->unsent_oversize = 0;
#endif /* TCP_OVERSIZE */
}
}
/**
* Purges the PCB and removes it from a PCB list. Any delayed ACKs are sent first.
*
* @param pcblist PCB list to purge.
* @param pcb tcp_pcb to purge. The pcb itself is NOT deallocated!
*/
void
tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
{
TCP_RMV(pcblist, pcb);
tcp_pcb_purge(pcb);
/* if there is an outstanding delayed ACKs, send it */
if (pcb->state != TIME_WAIT &&
pcb->state != LISTEN &&
pcb->flags & TF_ACK_DELAY) {
pcb->flags |= TF_ACK_NOW;
tcp_output(pcb);
}
if (pcb->state != LISTEN) {
LWIP_ASSERT("unsent segments leaking", pcb->unsent == NULL);
LWIP_ASSERT("unacked segments leaking", pcb->unacked == NULL);
#if TCP_QUEUE_OOSEQ
LWIP_ASSERT("ooseq segments leaking", pcb->ooseq == NULL);
#endif /* TCP_QUEUE_OOSEQ */
}
pcb->state = CLOSED;
/* reset the local port to prevent the pcb from being 'bound' */
pcb->local_port = 0;
LWIP_ASSERT("tcp_pcb_remove: tcp_pcbs_sane()", tcp_pcbs_sane());
}
/**
* Calculates a new initial sequence number for new connections.
*
* @return u32_t pseudo random sequence number
*/
u32_t
tcp_next_iss(struct tcp_pcb *pcb)
{
#ifdef LWIP_HOOK_TCP_ISN
return LWIP_HOOK_TCP_ISN(&pcb->local_ip, pcb->local_port, &pcb->remote_ip, pcb->remote_port);
#else /* LWIP_HOOK_TCP_ISN */
static u32_t iss = 6510;
LWIP_UNUSED_ARG(pcb);
iss += tcp_ticks; /* XXX */
return iss;
#endif /* LWIP_HOOK_TCP_ISN */
}
#if TCP_CALCULATE_EFF_SEND_MSS
/**
* Calculates the effective send mss that can be used for a specific IP address
* by using ip_route to determine the netif used to send to the address and
* calculating the minimum of TCP_MSS and that netif's mtu (if set).
*/
u16_t
tcp_eff_send_mss_impl(u16_t sendmss, const ip_addr_t *dest
#if LWIP_IPV6 || LWIP_IPV4_SRC_ROUTING
, const ip_addr_t *src
#endif /* LWIP_IPV6 || LWIP_IPV4_SRC_ROUTING */
)
{
u16_t mss_s;
struct netif *outif;
s16_t mtu;
outif = ip_route(src, dest);
#if LWIP_IPV6
#if LWIP_IPV4
if (IP_IS_V6(dest))
#endif /* LWIP_IPV4 */
{
/* First look in destination cache, to see if there is a Path MTU. */
mtu = nd6_get_destination_mtu(ip_2_ip6(dest), outif);
}
#if LWIP_IPV4
else
#endif /* LWIP_IPV4 */
#endif /* LWIP_IPV6 */
#if LWIP_IPV4
{
if (outif == NULL) {
return sendmss;
}
mtu = outif->mtu;
}
#endif /* LWIP_IPV4 */
if (mtu != 0) {
#if LWIP_IPV6
#if LWIP_IPV4
if (IP_IS_V6(dest))
#endif /* LWIP_IPV4 */
{
mss_s = mtu - IP6_HLEN - TCP_HLEN;
}
#if LWIP_IPV4
else
#endif /* LWIP_IPV4 */
#endif /* LWIP_IPV6 */
#if LWIP_IPV4
{
mss_s = mtu - IP_HLEN - TCP_HLEN;
}
#endif /* LWIP_IPV4 */
/* RFC 1122, chap 4.2.2.6:
* Eff.snd.MSS = min(SendMSS+20, MMS_S) - TCPhdrsize - IPoptionsize
* We correct for TCP options in tcp_write(), and don't support IP options.
*/
sendmss = LWIP_MIN(sendmss, mss_s);
}
return sendmss;
}
#endif /* TCP_CALCULATE_EFF_SEND_MSS */
/** Helper function for tcp_netif_ip_addr_changed() that iterates a pcb list */
static void
tcp_netif_ip_addr_changed_pcblist(const ip_addr_t* old_addr, struct tcp_pcb* pcb_list)
{
struct tcp_pcb *pcb;
pcb = pcb_list;
while (pcb != NULL) {
/* PCB bound to current local interface address? */
if (ip_addr_cmp(&pcb->local_ip, old_addr)
#if LWIP_AUTOIP
/* connections to link-local addresses must persist (RFC3927 ch. 1.9) */
&& (!IP_IS_V4_VAL(pcb->local_ip) || !ip4_addr_islinklocal(ip_2_ip4(&pcb->local_ip)))
#endif /* LWIP_AUTOIP */
) {
/* this connection must be aborted */
struct tcp_pcb *next = pcb->next;
LWIP_DEBUGF(NETIF_DEBUG | LWIP_DBG_STATE, ("netif_set_ipaddr: aborting TCP pcb %p\n", (void *)pcb));
tcp_abort(pcb);
pcb = next;
} else {
pcb = pcb->next;
}
}
}
/** This function is called from netif.c when address is changed or netif is removed
*
* @param old_addr IP address of the netif before change
* @param new_addr IP address of the netif after change or NULL if netif has been removed
*/
void
tcp_netif_ip_addr_changed(const ip_addr_t* old_addr, const ip_addr_t* new_addr)
{
struct tcp_pcb_listen *lpcb, *next;
if (!ip_addr_isany(old_addr)) {
tcp_netif_ip_addr_changed_pcblist(old_addr, tcp_active_pcbs);
tcp_netif_ip_addr_changed_pcblist(old_addr, tcp_bound_pcbs);
if (!ip_addr_isany(new_addr)) {
/* PCB bound to current local interface address? */
for (lpcb = tcp_listen_pcbs.listen_pcbs; lpcb != NULL; lpcb = next) {
next = lpcb->next;
/* PCB bound to current local interface address? */
if (ip_addr_cmp(&lpcb->local_ip, old_addr)) {
/* The PCB is listening to the old ipaddr and
* is set to listen to the new one instead */
ip_addr_copy(lpcb->local_ip, *new_addr);
}
}
}
}
}
const char*
tcp_debug_state_str(enum tcp_state s)
{
return tcp_state_str[s];
}
#if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUG
/**
* Print a tcp header for debugging purposes.
*
* @param tcphdr pointer to a struct tcp_hdr
*/
void
tcp_debug_print(struct tcp_hdr *tcphdr)
{
LWIP_DEBUGF(TCP_DEBUG, ("TCP header:\n"));
LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
LWIP_DEBUGF(TCP_DEBUG, ("| %5"U16_F" | %5"U16_F" | (src port, dest port)\n",
lwip_ntohs(tcphdr->src), lwip_ntohs(tcphdr->dest)));
LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
LWIP_DEBUGF(TCP_DEBUG, ("| %010"U32_F" | (seq no)\n",
lwip_ntohl(tcphdr->seqno)));
LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
LWIP_DEBUGF(TCP_DEBUG, ("| %010"U32_F" | (ack no)\n",
lwip_ntohl(tcphdr->ackno)));
LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
LWIP_DEBUGF(TCP_DEBUG, ("| %2"U16_F" | |%"U16_F"%"U16_F"%"U16_F"%"U16_F"%"U16_F"%"U16_F"| %5"U16_F" | (hdrlen, flags (",
TCPH_HDRLEN(tcphdr),
(u16_t)(TCPH_FLAGS(tcphdr) >> 5 & 1),
(u16_t)(TCPH_FLAGS(tcphdr) >> 4 & 1),
(u16_t)(TCPH_FLAGS(tcphdr) >> 3 & 1),
(u16_t)(TCPH_FLAGS(tcphdr) >> 2 & 1),
(u16_t)(TCPH_FLAGS(tcphdr) >> 1 & 1),
(u16_t)(TCPH_FLAGS(tcphdr) & 1),
lwip_ntohs(tcphdr->wnd)));
tcp_debug_print_flags(TCPH_FLAGS(tcphdr));
LWIP_DEBUGF(TCP_DEBUG, ("), win)\n"));
LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
LWIP_DEBUGF(TCP_DEBUG, ("| 0x%04"X16_F" | %5"U16_F" | (chksum, urgp)\n",
lwip_ntohs(tcphdr->chksum), lwip_ntohs(tcphdr->urgp)));
LWIP_DEBUGF(TCP_DEBUG, ("+-------------------------------+\n"));
}
/**
* Print a tcp state for debugging purposes.
*
* @param s enum tcp_state to print
*/
void
tcp_debug_print_state(enum tcp_state s)
{
LWIP_DEBUGF(TCP_DEBUG, ("State: %s\n", tcp_state_str[s]));
}
/**
* Print tcp flags for debugging purposes.
*
* @param flags tcp flags, all active flags are printed
*/
void
tcp_debug_print_flags(u8_t flags)
{
if (flags & TCP_FIN) {
LWIP_DEBUGF(TCP_DEBUG, ("FIN "));
}
if (flags & TCP_SYN) {
LWIP_DEBUGF(TCP_DEBUG, ("SYN "));
}
if (flags & TCP_RST) {
LWIP_DEBUGF(TCP_DEBUG, ("RST "));
}
if (flags & TCP_PSH) {
LWIP_DEBUGF(TCP_DEBUG, ("PSH "));
}
if (flags & TCP_ACK) {
LWIP_DEBUGF(TCP_DEBUG, ("ACK "));
}
if (flags & TCP_URG) {
LWIP_DEBUGF(TCP_DEBUG, ("URG "));
}
if (flags & TCP_ECE) {
LWIP_DEBUGF(TCP_DEBUG, ("ECE "));
}
if (flags & TCP_CWR) {
LWIP_DEBUGF(TCP_DEBUG, ("CWR "));
}
LWIP_DEBUGF(TCP_DEBUG, ("\n"));
}
/**
* Print all tcp_pcbs in every list for debugging purposes.
*/
void
tcp_debug_print_pcbs(void)
{
struct tcp_pcb *pcb;
struct tcp_pcb_listen *pcbl;
LWIP_DEBUGF(TCP_DEBUG, ("Active PCB states:\n"));
for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
LWIP_DEBUGF(TCP_DEBUG, ("Local port %"U16_F", foreign port %"U16_F" snd_nxt %"U32_F" rcv_nxt %"U32_F" ",
pcb->local_port, pcb->remote_port,
pcb->snd_nxt, pcb->rcv_nxt));
tcp_debug_print_state(pcb->state);
}
LWIP_DEBUGF(TCP_DEBUG, ("Listen PCB states:\n"));
for (pcbl = tcp_listen_pcbs.listen_pcbs; pcbl != NULL; pcbl = pcbl->next) {
LWIP_DEBUGF(TCP_DEBUG, ("Local port %"U16_F" ", pcbl->local_port));
tcp_debug_print_state(pcbl->state);
}
LWIP_DEBUGF(TCP_DEBUG, ("TIME-WAIT PCB states:\n"));
for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
LWIP_DEBUGF(TCP_DEBUG, ("Local port %"U16_F", foreign port %"U16_F" snd_nxt %"U32_F" rcv_nxt %"U32_F" ",
pcb->local_port, pcb->remote_port,
pcb->snd_nxt, pcb->rcv_nxt));
tcp_debug_print_state(pcb->state);
}
}
/**
* Check state consistency of the tcp_pcb lists.
*/
s16_t
tcp_pcbs_sane(void)
{
struct tcp_pcb *pcb;
for (pcb = tcp_active_pcbs; pcb != NULL; pcb = pcb->next) {
LWIP_ASSERT("tcp_pcbs_sane: active pcb->state != CLOSED", pcb->state != CLOSED);
LWIP_ASSERT("tcp_pcbs_sane: active pcb->state != LISTEN", pcb->state != LISTEN);
LWIP_ASSERT("tcp_pcbs_sane: active pcb->state != TIME-WAIT", pcb->state != TIME_WAIT);
}
for (pcb = tcp_tw_pcbs; pcb != NULL; pcb = pcb->next) {
LWIP_ASSERT("tcp_pcbs_sane: tw pcb->state == TIME-WAIT", pcb->state == TIME_WAIT);
}
return 1;
}
#endif /* TCP_DEBUG */
#endif /* LWIP_TCP */
#endif /* LIBOHIBOARD_ETHERNET_LWIP_2_0_3 */
|
the_stack_data/131489.c
|
/* APPLE LOCAL file pointer casts */
/* Test that casts of pointer to unsigned long long aren't sign extended */
/* Author: Matt Austern <[email protected]> */
/* { dg-do run } */
/* { dg-options "-Wno-error -w" } */
int main () {
/* Note: test assumes sizeof(long long) >= sizeof(void*) */
unsigned long x1 = 0x80000000ul;
void* p = (void*) x1;
unsigned long long x2 = (unsigned long long) p;
return !(x1 == x2);
}
|
the_stack_data/39138.c
|
// read a file and count no of characters, no of words and no of lines in the file.
//File Handling
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
int check_v(char a){
int chk=0;
a = tolower(a);
if(a=='a' ||a=='e' ||a=='i'||a=='o'||a=='u')
chk=1;
return chk;
}
void main(){
int v=0,w=0,i=0,z,l=0;
// OPENING A FILE AND READING FROM IT
FILE *rptr;
char ch;
rptr = fopen("text.txt","r");
if(rptr == NULL){
printf("\n\nFile not Found, Create a File in local directory and then run the program\n\n");
exit(1);
}
printf("Content of File is : ");
while((ch = getc(rptr)) != EOF){
z=check_v(ch);
if(z==1)
v++;
i++;
if(((ch<'a')||(ch>'z'))&&((ch<'A')||(ch>'Z')))
w++;
printf("%c",ch);
if(ch == '.')
l++;
}
if(l==0)
l++;
printf("\nNo of vowels is %d\nNo of characters is %d\nNo of white spaces are %d\nNo of lines are %d\n",v,i,w-1,l);
fclose(rptr);
}
|
the_stack_data/459696.c
|
int main()
{
int a = 5;
a += 6+9*8;
return a;
}
|
the_stack_data/248580483.c
|
/* Check calling convention in the vector ABI for single element vectors. */
/* { dg-do compile { target { lp64 } } } */
/* { dg-options "-O3 -mzarch -march=z13" } */
/* { dg-final { scan-assembler-times "vlr\t%v24,%v26" 1 } } */
typedef int __attribute__((vector_size(16))) v4si;
typedef __int128_t __attribute__((vector_size(16))) v1ti;
v1ti foo (v4si a, v1ti b) { return b; }
|
the_stack_data/729133.c
|
/*
* nbtest.c: read and write in non-blocking mode
* This should run with any Unix
*
* Copyright (C) 2001 Alessandro Rubini and Jonathan Corbet
* Copyright (C) 2001 O'Reilly & Associates
*
* The source code in this file can be freely used, adapted,
* and redistributed in source or binary form, so long as an
* acknowledgment appears in derived source files. The citation
* should list that the code comes from the book "Linux Device
* Drivers" by Alessandro Rubini and Jonathan Corbet, published
* by O'Reilly & Associates. No warranty is attached;
* we cannot take responsibility for errors or fitness for use.
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
char buffer[4096];
int main(int argc, char **argv)
{
int delay=1, n, m=0;
if (argc>1) delay=atoi(argv[1]);
fcntl(0, F_SETFL, fcntl(0,F_GETFL) | O_NONBLOCK); /* stdin */
fcntl(1, F_SETFL, fcntl(1,F_GETFL) | O_NONBLOCK); /* stdout */
while (1) {
n=read(0, buffer, 4096);
if (n>=0)
m=write(1, buffer, n);
if ((n<0 || m<0) && (errno != EAGAIN))
break;
sleep(delay);
}
perror( n<0 ? "stdin" : "stdout");
exit(1);
}
|
the_stack_data/25137366.c
|
#ifndef IN_GENERATED_CCODE
#define IN_GENERATED_CCODE
#define U_DISABLE_RENAMING 1
#include "unicode/umachine.h"
#endif
U_CDECL_BEGIN
const struct {
double bogus;
uint8_t bytes[3008];
} icudt57l_ibm_1124_P100_1996_cnv={ 0.0, {
128,0,218,39,20,0,0,0,0,0,2,0,99,110,118,116,
6,2,0,0,57,1,0,0,32,67,111,112,121,114,105,103,
104,116,32,40,67,41,32,50,48,49,54,44,32,73,110,116,
101,114,110,97,116,105,111,110,97,108,32,66,117,115,105,110,
101,115,115,32,77,97,99,104,105,110,101,115,32,67,111,114,
112,111,114,97,116,105,111,110,32,97,110,100,32,111,116,104,
101,114,115,46,32,65,108,108,32,82,105,103,104,116,115,32,
82,101,115,101,114,118,101,100,46,32,0,0,0,0,0,0,
100,0,0,0,105,98,109,45,49,49,50,52,95,80,49,48,
48,45,49,57,57,54,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
100,4,0,0,0,2,1,1,127,0,0,0,1,0,1,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,4,4,31,0,1,0,0,0,0,0,0,0,
32,4,0,0,32,4,0,0,162,6,0,0,0,0,0,0,
48,4,0,0,0,0,0,128,1,0,0,128,2,0,0,128,
3,0,0,128,4,0,0,128,5,0,0,128,6,0,0,128,
7,0,0,128,8,0,0,128,9,0,0,128,10,0,0,128,
11,0,0,128,12,0,0,128,13,0,0,128,14,0,0,128,
15,0,0,128,16,0,0,128,17,0,0,128,18,0,0,128,
19,0,0,128,20,0,0,128,21,0,0,128,22,0,0,128,
23,0,0,128,24,0,0,128,25,0,0,128,26,0,0,128,
27,0,0,128,28,0,0,128,29,0,0,128,30,0,0,128,
31,0,0,128,32,0,0,128,33,0,0,128,34,0,0,128,
35,0,0,128,36,0,0,128,37,0,0,128,38,0,0,128,
39,0,0,128,40,0,0,128,41,0,0,128,42,0,0,128,
43,0,0,128,44,0,0,128,45,0,0,128,46,0,0,128,
47,0,0,128,48,0,0,128,49,0,0,128,50,0,0,128,
51,0,0,128,52,0,0,128,53,0,0,128,54,0,0,128,
55,0,0,128,56,0,0,128,57,0,0,128,58,0,0,128,
59,0,0,128,60,0,0,128,61,0,0,128,62,0,0,128,
63,0,0,128,64,0,0,128,65,0,0,128,66,0,0,128,
67,0,0,128,68,0,0,128,69,0,0,128,70,0,0,128,
71,0,0,128,72,0,0,128,73,0,0,128,74,0,0,128,
75,0,0,128,76,0,0,128,77,0,0,128,78,0,0,128,
79,0,0,128,80,0,0,128,81,0,0,128,82,0,0,128,
83,0,0,128,84,0,0,128,85,0,0,128,86,0,0,128,
87,0,0,128,88,0,0,128,89,0,0,128,90,0,0,128,
91,0,0,128,92,0,0,128,93,0,0,128,94,0,0,128,
95,0,0,128,96,0,0,128,97,0,0,128,98,0,0,128,
99,0,0,128,100,0,0,128,101,0,0,128,102,0,0,128,
103,0,0,128,104,0,0,128,105,0,0,128,106,0,0,128,
107,0,0,128,108,0,0,128,109,0,0,128,110,0,0,128,
111,0,0,128,112,0,0,128,113,0,0,128,114,0,0,128,
115,0,0,128,116,0,0,128,117,0,0,128,118,0,0,128,
119,0,0,128,120,0,0,128,121,0,0,128,122,0,0,128,
123,0,0,128,124,0,0,128,125,0,0,128,126,0,0,128,
127,0,0,128,128,0,0,128,129,0,0,128,130,0,0,128,
131,0,0,128,132,0,0,128,133,0,0,128,134,0,0,128,
135,0,0,128,136,0,0,128,137,0,0,128,138,0,0,128,
139,0,0,128,140,0,0,128,141,0,0,128,142,0,0,128,
143,0,0,128,144,0,0,128,145,0,0,128,146,0,0,128,
147,0,0,128,148,0,0,128,149,0,0,128,150,0,0,128,
151,0,0,128,152,0,0,128,153,0,0,128,154,0,0,128,
155,0,0,128,156,0,0,128,157,0,0,128,158,0,0,128,
159,0,0,128,160,0,0,128,1,4,0,128,2,4,0,128,
144,4,0,128,4,4,0,128,5,4,0,128,6,4,0,128,
7,4,0,128,8,4,0,128,9,4,0,128,10,4,0,128,
11,4,0,128,12,4,0,128,173,0,0,128,14,4,0,128,
15,4,0,128,16,4,0,128,17,4,0,128,18,4,0,128,
19,4,0,128,20,4,0,128,21,4,0,128,22,4,0,128,
23,4,0,128,24,4,0,128,25,4,0,128,26,4,0,128,
27,4,0,128,28,4,0,128,29,4,0,128,30,4,0,128,
31,4,0,128,32,4,0,128,33,4,0,128,34,4,0,128,
35,4,0,128,36,4,0,128,37,4,0,128,38,4,0,128,
39,4,0,128,40,4,0,128,41,4,0,128,42,4,0,128,
43,4,0,128,44,4,0,128,45,4,0,128,46,4,0,128,
47,4,0,128,48,4,0,128,49,4,0,128,50,4,0,128,
51,4,0,128,52,4,0,128,53,4,0,128,54,4,0,128,
55,4,0,128,56,4,0,128,57,4,0,128,58,4,0,128,
59,4,0,128,60,4,0,128,61,4,0,128,62,4,0,128,
63,4,0,128,64,4,0,128,65,4,0,128,66,4,0,128,
67,4,0,128,68,4,0,128,69,4,0,128,70,4,0,128,
71,4,0,128,72,4,0,128,73,4,0,128,74,4,0,128,
75,4,0,128,76,4,0,128,77,4,0,128,78,4,0,128,
79,4,0,128,22,33,0,128,81,4,0,128,82,4,0,128,
145,4,0,128,84,4,0,128,85,4,0,128,86,4,0,128,
87,4,0,128,88,4,0,128,89,4,0,128,90,4,0,128,
91,4,0,128,92,4,0,128,167,0,0,128,94,4,0,128,
95,4,0,128,128,0,192,0,64,0,64,0,64,0,64,0,
64,0,64,0,239,0,64,0,64,0,64,0,64,0,64,0,
64,0,64,0,64,0,64,0,64,0,64,0,64,0,64,0,
64,0,64,0,64,0,64,0,64,0,64,0,64,0,64,0,
64,0,64,0,64,0,64,0,64,0,64,0,64,0,64,0,
64,0,64,0,64,0,64,0,64,0,64,0,64,0,64,0,
64,0,64,0,64,0,64,0,64,0,64,0,64,0,64,0,
64,0,64,0,64,0,64,0,64,0,64,0,64,0,64,0,
64,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,64,0,80,0,96,0,112,0,128,0,144,0,
160,0,176,0,192,0,208,0,224,0,240,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,255,0,15,1,31,1,47,1,63,1,79,1,
95,1,111,1,111,1,127,1,143,1,159,1,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,169,1,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,184,1,200,1,216,1,232,1,248,1,
8,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,15,1,15,2,15,3,15,4,15,
5,15,6,15,7,15,8,15,9,15,10,15,11,15,12,15,
13,15,14,15,15,15,16,15,17,15,18,15,19,15,20,15,
21,15,22,15,23,15,24,15,25,15,26,15,27,15,28,15,
29,15,30,15,31,15,32,15,33,15,34,15,35,15,36,15,
37,15,38,15,39,15,40,15,41,15,42,15,43,15,44,15,
45,15,46,15,47,15,48,15,49,15,50,15,51,15,52,15,
53,15,54,15,55,15,56,15,57,15,58,15,59,15,60,15,
61,15,62,15,63,15,64,15,65,15,66,15,67,15,68,15,
69,15,70,15,71,15,72,15,73,15,74,15,75,15,76,15,
77,15,78,15,79,15,80,15,81,15,82,15,83,15,84,15,
85,15,86,15,87,15,88,15,89,15,90,15,91,15,92,15,
93,15,94,15,95,15,96,15,97,15,98,15,99,15,100,15,
101,15,102,15,103,15,104,15,105,15,106,15,107,15,108,15,
109,15,110,15,111,15,112,15,113,15,114,15,115,15,116,15,
117,15,118,15,119,15,120,15,121,15,122,15,123,15,124,15,
125,15,126,15,127,15,128,15,129,15,130,15,131,15,132,15,
133,15,134,15,135,15,136,15,137,15,138,15,139,15,140,15,
141,15,142,15,143,15,144,15,145,15,146,15,147,15,148,15,
149,15,150,15,151,15,152,15,153,15,154,15,155,15,156,15,
157,15,158,15,159,15,160,15,0,0,0,0,0,0,0,0,
0,0,0,0,253,15,0,0,0,0,0,0,0,0,0,0,
173,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,161,15,162,15,0,0,164,15,165,15,
166,15,167,15,168,15,169,15,170,15,171,15,172,15,0,0,
174,15,175,15,176,15,177,15,178,15,179,15,180,15,181,15,
182,15,183,15,184,15,185,15,186,15,187,15,188,15,189,15,
190,15,191,15,192,15,193,15,194,15,195,15,196,15,197,15,
198,15,199,15,200,15,201,15,202,15,203,15,204,15,205,15,
206,15,207,15,208,15,209,15,210,15,211,15,212,15,213,15,
214,15,215,15,216,15,217,15,218,15,219,15,220,15,221,15,
222,15,223,15,224,15,225,15,226,15,227,15,228,15,229,15,
230,15,231,15,232,15,233,15,234,15,235,15,236,15,237,15,
238,15,239,15,0,0,241,15,242,15,0,0,244,15,245,15,
246,15,247,15,248,15,249,15,250,15,251,15,252,15,0,0,
254,15,255,15,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,163,15,243,15,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,240,15,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,33,8,34,8,35,8,36,8,
37,8,38,8,39,8,40,8,41,8,42,8,43,8,44,8,
45,8,46,8,47,8,48,8,49,8,50,8,51,8,52,8,
53,8,54,8,55,8,56,8,57,8,58,8,59,8,60,8,
61,8,62,8,63,8,64,8,65,8,66,8,67,8,68,8,
69,8,70,8,71,8,72,8,73,8,74,8,75,8,76,8,
77,8,78,8,79,8,80,8,81,8,82,8,83,8,84,8,
85,8,86,8,87,8,88,8,89,8,90,8,91,8,92,8,
93,8,94,8,95,8,96,8,97,8,98,8,99,8,100,8,
101,8,102,8,103,8,104,8,105,8,106,8,107,8,108,8,
109,8,110,8,111,8,112,8,113,8,114,8,115,8,116,8,
117,8,118,8,119,8,120,8,121,8,122,8,123,8,124,8,
125,8,126,8,0,0,170,170,170,170,170,170,170,170,170,170
}
};
U_CDECL_END
|
the_stack_data/460314.c
|
/*
Given numRows, generate the first numRows of Pascal’s triangle.
Pascal’s triangle : To generate A[C] in row R, sum up A’[C] and A’[C-1] from previous row R - 1.
Example:
Given numRows = 5,
Return
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
*/
/**
* @input A : Integer
*
* @Output 2D int array. You need to malloc memory. Fill in len1 as row, len2 as columns
*/
int ** solve(int A, int *len1, int *len2) {
int** a=(int **)malloc(sizeof(int*)*A);
int i,j;
for(i=0;i<len1;i++)
{
a[i]=(int *)malloc(sizeof(int)*i+1);
for(j=0;j<=i;j++)
{
if(j==0||j==i)
{
a[i][j]=1;
}
else
a[i][j]=a[i-1][j-1]+a[i-1][j];
}
}
*len1=A;
*len2=A;
return a;
}
|
the_stack_data/589627.c
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_str_is_uppercase.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jdos-san <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/01 16:03:02 by jdos-san #+# #+# */
/* Updated: 2020/12/01 16:04:23 by jdos-san ### ########.fr */
/* */
/* ************************************************************************** */
int ft_str_is_uppercase(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
if (str[i] < 'A' || str[i] > 'Z')
{
return (0);
}
i++;
}
return (1);
}
|
the_stack_data/89836.c
|
extern float __VERIFIER_nondet_float(void);
extern int __VERIFIER_nondet_int(void);
typedef enum {false, true} bool;
bool __VERIFIER_nondet_bool(void) {
return __VERIFIER_nondet_int() != 0;
}
int main()
{
float _diverge_delta, _x__diverge_delta;
float delta, _x_delta;
float r_x, _x_r_x;
bool s3_evt1, _x_s3_evt1;
bool s3_evt0, _x_s3_evt0;
bool r_l, _x_r_l;
float s1_z, _x_s1_z;
int r_counter, _x_r_counter;
bool _J1601, _x__J1601;
float s1_y, _x_s1_y;
bool _J1595, _x__J1595;
bool _J1589, _x__J1589;
bool _J1583, _x__J1583;
bool _EL_U_1557, _x__EL_U_1557;
bool _EL_U_1559, _x__EL_U_1559;
bool _EL_U_1561, _x__EL_U_1561;
bool s4_l1, _x_s4_l1;
bool s1_evt1, _x_s1_evt1;
bool s4_l0, _x_s4_l0;
int r_evt_id, _x_r_evt_id;
bool s4_l2, _x_s4_l2;
bool s1_evt0, _x_s1_evt0;
bool _EL_U_1563, _x__EL_U_1563;
float s4_x, _x_s4_x;
bool r_event0, _x_r_event0;
bool r_event1, _x_r_event1;
bool s2_l1, _x_s2_l1;
float s4_z, _x_s4_z;
bool s2_l0, _x_s2_l0;
float s4_y, _x_s4_y;
bool s2_l2, _x_s2_l2;
float s2_x, _x_s2_x;
bool s0_l1, _x_s0_l1;
bool s0_l0, _x_s0_l0;
bool s0_l2, _x_s0_l2;
bool s4_evt1, _x_s4_evt1;
bool s4_evt0, _x_s4_evt0;
float s0_x, _x_s0_x;
float s2_z, _x_s2_z;
float s2_y, _x_s2_y;
bool s5_l1, _x_s5_l1;
float s0_z, _x_s0_z;
bool s5_l0, _x_s5_l0;
float s0_y, _x_s0_y;
bool s5_l2, _x_s5_l2;
bool s2_evt1, _x_s2_evt1;
bool s2_evt0, _x_s2_evt0;
float s5_x, _x_s5_x;
bool s3_l1, _x_s3_l1;
bool s0_evt1, _x_s0_evt1;
float s5_z, _x_s5_z;
bool s0_evt0, _x_s0_evt0;
float s5_y, _x_s5_y;
bool s5_evt1, _x_s5_evt1;
bool s3_l0, _x_s3_l0;
bool s3_l2, _x_s3_l2;
float s3_x, _x_s3_x;
float s3_z, _x_s3_z;
float s3_y, _x_s3_y;
bool s1_l1, _x_s1_l1;
bool s1_l0, _x_s1_l0;
bool s5_evt0, _x_s5_evt0;
bool s1_l2, _x_s1_l2;
float s1_x, _x_s1_x;
int __steps_to_fair = __VERIFIER_nondet_int();
_diverge_delta = __VERIFIER_nondet_float();
delta = __VERIFIER_nondet_float();
r_x = __VERIFIER_nondet_float();
s3_evt1 = __VERIFIER_nondet_bool();
s3_evt0 = __VERIFIER_nondet_bool();
r_l = __VERIFIER_nondet_bool();
s1_z = __VERIFIER_nondet_float();
r_counter = __VERIFIER_nondet_int();
_J1601 = __VERIFIER_nondet_bool();
s1_y = __VERIFIER_nondet_float();
_J1595 = __VERIFIER_nondet_bool();
_J1589 = __VERIFIER_nondet_bool();
_J1583 = __VERIFIER_nondet_bool();
_EL_U_1557 = __VERIFIER_nondet_bool();
_EL_U_1559 = __VERIFIER_nondet_bool();
_EL_U_1561 = __VERIFIER_nondet_bool();
s4_l1 = __VERIFIER_nondet_bool();
s1_evt1 = __VERIFIER_nondet_bool();
s4_l0 = __VERIFIER_nondet_bool();
r_evt_id = __VERIFIER_nondet_int();
s4_l2 = __VERIFIER_nondet_bool();
s1_evt0 = __VERIFIER_nondet_bool();
_EL_U_1563 = __VERIFIER_nondet_bool();
s4_x = __VERIFIER_nondet_float();
r_event0 = __VERIFIER_nondet_bool();
r_event1 = __VERIFIER_nondet_bool();
s2_l1 = __VERIFIER_nondet_bool();
s4_z = __VERIFIER_nondet_float();
s2_l0 = __VERIFIER_nondet_bool();
s4_y = __VERIFIER_nondet_float();
s2_l2 = __VERIFIER_nondet_bool();
s2_x = __VERIFIER_nondet_float();
s0_l1 = __VERIFIER_nondet_bool();
s0_l0 = __VERIFIER_nondet_bool();
s0_l2 = __VERIFIER_nondet_bool();
s4_evt1 = __VERIFIER_nondet_bool();
s4_evt0 = __VERIFIER_nondet_bool();
s0_x = __VERIFIER_nondet_float();
s2_z = __VERIFIER_nondet_float();
s2_y = __VERIFIER_nondet_float();
s5_l1 = __VERIFIER_nondet_bool();
s0_z = __VERIFIER_nondet_float();
s5_l0 = __VERIFIER_nondet_bool();
s0_y = __VERIFIER_nondet_float();
s5_l2 = __VERIFIER_nondet_bool();
s2_evt1 = __VERIFIER_nondet_bool();
s2_evt0 = __VERIFIER_nondet_bool();
s5_x = __VERIFIER_nondet_float();
s3_l1 = __VERIFIER_nondet_bool();
s0_evt1 = __VERIFIER_nondet_bool();
s5_z = __VERIFIER_nondet_float();
s0_evt0 = __VERIFIER_nondet_bool();
s5_y = __VERIFIER_nondet_float();
s5_evt1 = __VERIFIER_nondet_bool();
s3_l0 = __VERIFIER_nondet_bool();
s3_l2 = __VERIFIER_nondet_bool();
s3_x = __VERIFIER_nondet_float();
s3_z = __VERIFIER_nondet_float();
s3_y = __VERIFIER_nondet_float();
s1_l1 = __VERIFIER_nondet_bool();
s1_l0 = __VERIFIER_nondet_bool();
s5_evt0 = __VERIFIER_nondet_bool();
s1_l2 = __VERIFIER_nondet_bool();
s1_x = __VERIFIER_nondet_float();
bool __ok = (((((((((((( !s5_evt0) && ( !s5_evt1)) || (s5_evt0 && ( !s5_evt1))) || ((s5_evt1 && ( !s5_evt0)) || (s5_evt0 && s5_evt1))) && ((((( !s5_l2) && (( !s5_l0) && ( !s5_l1))) || (( !s5_l2) && (s5_l0 && ( !s5_l1)))) || ((( !s5_l2) && (s5_l1 && ( !s5_l0))) || (( !s5_l2) && (s5_l0 && s5_l1)))) || ((s5_l2 && (( !s5_l0) && ( !s5_l1))) || (s5_l2 && (s5_l0 && ( !s5_l1)))))) && (((( !s5_l2) && (( !s5_l0) && ( !s5_l1))) && (s5_x == 0.0)) && ((s5_y == 0.0) && (s5_z == 0.0)))) && ((s5_x <= 20.0) || ( !(( !s5_l2) && (s5_l0 && ( !s5_l1)))))) && ((s5_x <= 120.0) || ( !(( !s5_l2) && (s5_l1 && ( !s5_l0)))))) && ((s5_x <= 120.0) || ( !(s5_l2 && (s5_l0 && ( !s5_l1)))))) && (((((((((( !s4_evt0) && ( !s4_evt1)) || (s4_evt0 && ( !s4_evt1))) || ((s4_evt1 && ( !s4_evt0)) || (s4_evt0 && s4_evt1))) && ((((( !s4_l2) && (( !s4_l0) && ( !s4_l1))) || (( !s4_l2) && (s4_l0 && ( !s4_l1)))) || ((( !s4_l2) && (s4_l1 && ( !s4_l0))) || (( !s4_l2) && (s4_l0 && s4_l1)))) || ((s4_l2 && (( !s4_l0) && ( !s4_l1))) || (s4_l2 && (s4_l0 && ( !s4_l1)))))) && (((( !s4_l2) && (( !s4_l0) && ( !s4_l1))) && (s4_x == 0.0)) && ((s4_y == 0.0) && (s4_z == 0.0)))) && ((s4_x <= 20.0) || ( !(( !s4_l2) && (s4_l0 && ( !s4_l1)))))) && ((s4_x <= 120.0) || ( !(( !s4_l2) && (s4_l1 && ( !s4_l0)))))) && ((s4_x <= 120.0) || ( !(s4_l2 && (s4_l0 && ( !s4_l1)))))) && (((((((((( !s3_evt0) && ( !s3_evt1)) || (s3_evt0 && ( !s3_evt1))) || ((s3_evt1 && ( !s3_evt0)) || (s3_evt0 && s3_evt1))) && ((((( !s3_l2) && (( !s3_l0) && ( !s3_l1))) || (( !s3_l2) && (s3_l0 && ( !s3_l1)))) || ((( !s3_l2) && (s3_l1 && ( !s3_l0))) || (( !s3_l2) && (s3_l0 && s3_l1)))) || ((s3_l2 && (( !s3_l0) && ( !s3_l1))) || (s3_l2 && (s3_l0 && ( !s3_l1)))))) && (((( !s3_l2) && (( !s3_l0) && ( !s3_l1))) && (s3_x == 0.0)) && ((s3_y == 0.0) && (s3_z == 0.0)))) && ((s3_x <= 20.0) || ( !(( !s3_l2) && (s3_l0 && ( !s3_l1)))))) && ((s3_x <= 120.0) || ( !(( !s3_l2) && (s3_l1 && ( !s3_l0)))))) && ((s3_x <= 120.0) || ( !(s3_l2 && (s3_l0 && ( !s3_l1)))))) && (((((((((( !s2_evt0) && ( !s2_evt1)) || (s2_evt0 && ( !s2_evt1))) || ((s2_evt1 && ( !s2_evt0)) || (s2_evt0 && s2_evt1))) && ((((( !s2_l2) && (( !s2_l0) && ( !s2_l1))) || (( !s2_l2) && (s2_l0 && ( !s2_l1)))) || ((( !s2_l2) && (s2_l1 && ( !s2_l0))) || (( !s2_l2) && (s2_l0 && s2_l1)))) || ((s2_l2 && (( !s2_l0) && ( !s2_l1))) || (s2_l2 && (s2_l0 && ( !s2_l1)))))) && (((( !s2_l2) && (( !s2_l0) && ( !s2_l1))) && (s2_x == 0.0)) && ((s2_y == 0.0) && (s2_z == 0.0)))) && ((s2_x <= 20.0) || ( !(( !s2_l2) && (s2_l0 && ( !s2_l1)))))) && ((s2_x <= 120.0) || ( !(( !s2_l2) && (s2_l1 && ( !s2_l0)))))) && ((s2_x <= 120.0) || ( !(s2_l2 && (s2_l0 && ( !s2_l1)))))) && (((((((((( !s1_evt0) && ( !s1_evt1)) || (s1_evt0 && ( !s1_evt1))) || ((s1_evt1 && ( !s1_evt0)) || (s1_evt0 && s1_evt1))) && ((((( !s1_l2) && (( !s1_l0) && ( !s1_l1))) || (( !s1_l2) && (s1_l0 && ( !s1_l1)))) || ((( !s1_l2) && (s1_l1 && ( !s1_l0))) || (( !s1_l2) && (s1_l0 && s1_l1)))) || ((s1_l2 && (( !s1_l0) && ( !s1_l1))) || (s1_l2 && (s1_l0 && ( !s1_l1)))))) && (((( !s1_l2) && (( !s1_l0) && ( !s1_l1))) && (s1_x == 0.0)) && ((s1_y == 0.0) && (s1_z == 0.0)))) && ((s1_x <= 20.0) || ( !(( !s1_l2) && (s1_l0 && ( !s1_l1)))))) && ((s1_x <= 120.0) || ( !(( !s1_l2) && (s1_l1 && ( !s1_l0)))))) && ((s1_x <= 120.0) || ( !(s1_l2 && (s1_l0 && ( !s1_l1)))))) && (((((((((( !s0_evt0) && ( !s0_evt1)) || (s0_evt0 && ( !s0_evt1))) || ((s0_evt1 && ( !s0_evt0)) || (s0_evt0 && s0_evt1))) && ((((( !s0_l2) && (( !s0_l0) && ( !s0_l1))) || (( !s0_l2) && (s0_l0 && ( !s0_l1)))) || ((( !s0_l2) && (s0_l1 && ( !s0_l0))) || (( !s0_l2) && (s0_l0 && s0_l1)))) || ((s0_l2 && (( !s0_l0) && ( !s0_l1))) || (s0_l2 && (s0_l0 && ( !s0_l1)))))) && (((( !s0_l2) && (( !s0_l0) && ( !s0_l1))) && (s0_x == 0.0)) && ((s0_y == 0.0) && (s0_z == 0.0)))) && ((s0_x <= 20.0) || ( !(( !s0_l2) && (s0_l0 && ( !s0_l1)))))) && ((s0_x <= 120.0) || ( !(( !s0_l2) && (s0_l1 && ( !s0_l0)))))) && ((s0_x <= 120.0) || ( !(s0_l2 && (s0_l0 && ( !s0_l1)))))) && ((((((r_l && ((r_counter == 0) && (r_x == 0.0))) && ((( !r_event0) && ( !r_event1)) || ((r_event0 && ( !r_event1)) || (r_event1 && ( !r_event0))))) && ((((((r_evt_id == 0) || (r_evt_id == 1)) || (r_evt_id == 2)) || (r_evt_id == 3)) || (r_evt_id == 4)) || (r_evt_id == 5))) && ((((((r_counter == 0) || (r_counter == 1)) || (r_counter == 2)) || (r_counter == 3)) || (r_counter == 4)) || (r_counter == 5))) && (( !r_l) || (r_x <= 0.0))) && (0.0 <= delta)))))))) && (delta == _diverge_delta)) && ((((( !(( !(_EL_U_1563 || ( !((s0_l2 && (s0_l0 && ( !s0_l1))) || _EL_U_1561)))) || (_EL_U_1559 || ( !((1.0 <= _diverge_delta) || _EL_U_1557))))) && ( !_J1583)) && ( !_J1589)) && ( !_J1595)) && ( !_J1601)));
while (__steps_to_fair >= 0 && __ok) {
if ((((_J1583 && _J1589) && _J1595) && _J1601)) {
__steps_to_fair = __VERIFIER_nondet_int();
} else {
__steps_to_fair--;
}
_x__diverge_delta = __VERIFIER_nondet_float();
_x_delta = __VERIFIER_nondet_float();
_x_r_x = __VERIFIER_nondet_float();
_x_s3_evt1 = __VERIFIER_nondet_bool();
_x_s3_evt0 = __VERIFIER_nondet_bool();
_x_r_l = __VERIFIER_nondet_bool();
_x_s1_z = __VERIFIER_nondet_float();
_x_r_counter = __VERIFIER_nondet_int();
_x__J1601 = __VERIFIER_nondet_bool();
_x_s1_y = __VERIFIER_nondet_float();
_x__J1595 = __VERIFIER_nondet_bool();
_x__J1589 = __VERIFIER_nondet_bool();
_x__J1583 = __VERIFIER_nondet_bool();
_x__EL_U_1557 = __VERIFIER_nondet_bool();
_x__EL_U_1559 = __VERIFIER_nondet_bool();
_x__EL_U_1561 = __VERIFIER_nondet_bool();
_x_s4_l1 = __VERIFIER_nondet_bool();
_x_s1_evt1 = __VERIFIER_nondet_bool();
_x_s4_l0 = __VERIFIER_nondet_bool();
_x_r_evt_id = __VERIFIER_nondet_int();
_x_s4_l2 = __VERIFIER_nondet_bool();
_x_s1_evt0 = __VERIFIER_nondet_bool();
_x__EL_U_1563 = __VERIFIER_nondet_bool();
_x_s4_x = __VERIFIER_nondet_float();
_x_r_event0 = __VERIFIER_nondet_bool();
_x_r_event1 = __VERIFIER_nondet_bool();
_x_s2_l1 = __VERIFIER_nondet_bool();
_x_s4_z = __VERIFIER_nondet_float();
_x_s2_l0 = __VERIFIER_nondet_bool();
_x_s4_y = __VERIFIER_nondet_float();
_x_s2_l2 = __VERIFIER_nondet_bool();
_x_s2_x = __VERIFIER_nondet_float();
_x_s0_l1 = __VERIFIER_nondet_bool();
_x_s0_l0 = __VERIFIER_nondet_bool();
_x_s0_l2 = __VERIFIER_nondet_bool();
_x_s4_evt1 = __VERIFIER_nondet_bool();
_x_s4_evt0 = __VERIFIER_nondet_bool();
_x_s0_x = __VERIFIER_nondet_float();
_x_s2_z = __VERIFIER_nondet_float();
_x_s2_y = __VERIFIER_nondet_float();
_x_s5_l1 = __VERIFIER_nondet_bool();
_x_s0_z = __VERIFIER_nondet_float();
_x_s5_l0 = __VERIFIER_nondet_bool();
_x_s0_y = __VERIFIER_nondet_float();
_x_s5_l2 = __VERIFIER_nondet_bool();
_x_s2_evt1 = __VERIFIER_nondet_bool();
_x_s2_evt0 = __VERIFIER_nondet_bool();
_x_s5_x = __VERIFIER_nondet_float();
_x_s3_l1 = __VERIFIER_nondet_bool();
_x_s0_evt1 = __VERIFIER_nondet_bool();
_x_s5_z = __VERIFIER_nondet_float();
_x_s0_evt0 = __VERIFIER_nondet_bool();
_x_s5_y = __VERIFIER_nondet_float();
_x_s5_evt1 = __VERIFIER_nondet_bool();
_x_s3_l0 = __VERIFIER_nondet_bool();
_x_s3_l2 = __VERIFIER_nondet_bool();
_x_s3_x = __VERIFIER_nondet_float();
_x_s3_z = __VERIFIER_nondet_float();
_x_s3_y = __VERIFIER_nondet_float();
_x_s1_l1 = __VERIFIER_nondet_bool();
_x_s1_l0 = __VERIFIER_nondet_bool();
_x_s5_evt0 = __VERIFIER_nondet_bool();
_x_s1_l2 = __VERIFIER_nondet_bool();
_x_s1_x = __VERIFIER_nondet_float();
__ok = (((((((((((((((((((((((((((((((((((( !_x_s5_evt0) && ( !_x_s5_evt1)) || (_x_s5_evt0 && ( !_x_s5_evt1))) || ((_x_s5_evt1 && ( !_x_s5_evt0)) || (_x_s5_evt0 && _x_s5_evt1))) && ((((( !_x_s5_l2) && (( !_x_s5_l0) && ( !_x_s5_l1))) || (( !_x_s5_l2) && (_x_s5_l0 && ( !_x_s5_l1)))) || ((( !_x_s5_l2) && (_x_s5_l1 && ( !_x_s5_l0))) || (( !_x_s5_l2) && (_x_s5_l0 && _x_s5_l1)))) || ((_x_s5_l2 && (( !_x_s5_l0) && ( !_x_s5_l1))) || (_x_s5_l2 && (_x_s5_l0 && ( !_x_s5_l1)))))) && ((_x_s5_x <= 20.0) || ( !(( !_x_s5_l2) && (_x_s5_l0 && ( !_x_s5_l1)))))) && ((_x_s5_x <= 120.0) || ( !(( !_x_s5_l2) && (_x_s5_l1 && ( !_x_s5_l0)))))) && ((_x_s5_x <= 120.0) || ( !(_x_s5_l2 && (_x_s5_l0 && ( !_x_s5_l1)))))) && ((delta <= 0.0) || ((((delta + (s5_x + (-1.0 * _x_s5_x))) == 0.0) && ((delta + (s5_y + (-1.0 * _x_s5_y))) == 0.0)) && ((((s5_l0 == _x_s5_l0) && (s5_l1 == _x_s5_l1)) && (s5_l2 == _x_s5_l2)) && ((delta + (s5_z + (-1.0 * _x_s5_z))) == 0.0))))) && ((((((s5_l0 == _x_s5_l0) && (s5_l1 == _x_s5_l1)) && (s5_l2 == _x_s5_l2)) && ((delta + (s5_x + (-1.0 * _x_s5_x))) == 0.0)) && (((delta + (s5_y + (-1.0 * _x_s5_y))) == 0.0) && ((delta + (s5_z + (-1.0 * _x_s5_z))) == 0.0))) || ( !(( !s5_evt0) && ( !s5_evt1))))) && (((((s5_evt0 && s5_evt1) && (( !_x_s5_l2) && (_x_s5_l0 && ( !_x_s5_l1)))) && ((_x_s5_x == 0.0) && (_x_s5_y == 0.0))) && (s5_z == _x_s5_z)) || ( !((( !s5_l2) && (( !s5_l0) && ( !s5_l1))) && ((delta == 0.0) && ( !(( !s5_evt0) && ( !s5_evt1)))))))) && (((((( !_x_s5_l2) && (_x_s5_l1 && ( !_x_s5_l0))) || (( !_x_s5_l2) && (_x_s5_l0 && _x_s5_l1))) && (s5_x == _x_s5_x)) && ((s5_z == _x_s5_z) && (s5_y == _x_s5_y))) || ( !((( !s5_l2) && (s5_l0 && ( !s5_l1))) && ((delta == 0.0) && ( !(( !s5_evt0) && ( !s5_evt1)))))))) && (((s5_evt0 && ( !s5_evt1)) && ((20.0 <= s5_x) && ( !(120.0 <= s5_z)))) || ( !(((delta == 0.0) && ( !(( !s5_evt0) && ( !s5_evt1)))) && ((( !s5_l2) && (s5_l0 && ( !s5_l1))) && (( !_x_s5_l2) && (_x_s5_l1 && ( !_x_s5_l0)))))))) && (((s5_evt1 && ( !s5_evt0)) && ((20.0 <= s5_x) && (120.0 <= s5_z))) || ( !(((delta == 0.0) && ( !(( !s5_evt0) && ( !s5_evt1)))) && ((( !s5_l2) && (s5_l0 && ( !s5_l1))) && (( !_x_s5_l2) && (_x_s5_l0 && _x_s5_l1))))))) && (((s5_z == _x_s5_z) && (((s5_evt1 && ( !s5_evt0)) && (( !_x_s5_l2) && (_x_s5_l0 && _x_s5_l1))) && ((s5_x == _x_s5_x) && (s5_y == _x_s5_y)))) || ( !((( !s5_l2) && (s5_l1 && ( !s5_l0))) && ((delta == 0.0) && ( !(( !s5_evt0) && ( !s5_evt1)))))))) && (((((s5_evt0 && s5_evt1) && (_x_s5_l2 && (( !_x_s5_l0) && ( !_x_s5_l1)))) && ((_x_s5_x == 0.0) && (s5_y == _x_s5_y))) && (_x_s5_z == 0.0)) || ( !((( !s5_l2) && (s5_l0 && s5_l1)) && ((delta == 0.0) && ( !(( !s5_evt0) && ( !s5_evt1)))))))) && ((((s5_x == _x_s5_x) && (s5_y == _x_s5_y)) && ((s5_z == _x_s5_z) && ((( !_x_s5_l2) && (( !_x_s5_l0) && ( !_x_s5_l1))) || (_x_s5_l2 && (_x_s5_l0 && ( !_x_s5_l1)))))) || ( !((s5_l2 && (( !s5_l0) && ( !s5_l1))) && ((delta == 0.0) && ( !(( !s5_evt0) && ( !s5_evt1)))))))) && (((s5_evt0 && ( !s5_evt1)) && ((20.0 <= s5_x) && ( !(120.0 <= s5_y)))) || ( !(((delta == 0.0) && ( !(( !s5_evt0) && ( !s5_evt1)))) && ((s5_l2 && (( !s5_l0) && ( !s5_l1))) && (_x_s5_l2 && (_x_s5_l0 && ( !_x_s5_l1)))))))) && (((s5_evt1 && ( !s5_evt0)) && ((20.0 <= s5_x) && (120.0 <= s5_y))) || ( !(((delta == 0.0) && ( !(( !s5_evt0) && ( !s5_evt1)))) && ((( !_x_s5_l2) && (( !_x_s5_l0) && ( !_x_s5_l1))) && (s5_l2 && (( !s5_l0) && ( !s5_l1)))))))) && (((s5_z == _x_s5_z) && (((s5_x == _x_s5_x) && (s5_y == _x_s5_y)) && ((s5_evt1 && ( !s5_evt0)) && (( !_x_s5_l2) && (( !_x_s5_l0) && ( !_x_s5_l1)))))) || ( !((s5_l2 && (s5_l0 && ( !s5_l1))) && ((delta == 0.0) && ( !(( !s5_evt0) && ( !s5_evt1)))))))) && ((((((((((((((((((((( !_x_s4_evt0) && ( !_x_s4_evt1)) || (_x_s4_evt0 && ( !_x_s4_evt1))) || ((_x_s4_evt1 && ( !_x_s4_evt0)) || (_x_s4_evt0 && _x_s4_evt1))) && ((((( !_x_s4_l2) && (( !_x_s4_l0) && ( !_x_s4_l1))) || (( !_x_s4_l2) && (_x_s4_l0 && ( !_x_s4_l1)))) || ((( !_x_s4_l2) && (_x_s4_l1 && ( !_x_s4_l0))) || (( !_x_s4_l2) && (_x_s4_l0 && _x_s4_l1)))) || ((_x_s4_l2 && (( !_x_s4_l0) && ( !_x_s4_l1))) || (_x_s4_l2 && (_x_s4_l0 && ( !_x_s4_l1)))))) && ((_x_s4_x <= 20.0) || ( !(( !_x_s4_l2) && (_x_s4_l0 && ( !_x_s4_l1)))))) && ((_x_s4_x <= 120.0) || ( !(( !_x_s4_l2) && (_x_s4_l1 && ( !_x_s4_l0)))))) && ((_x_s4_x <= 120.0) || ( !(_x_s4_l2 && (_x_s4_l0 && ( !_x_s4_l1)))))) && ((delta <= 0.0) || ((((delta + (s4_x + (-1.0 * _x_s4_x))) == 0.0) && ((delta + (s4_y + (-1.0 * _x_s4_y))) == 0.0)) && ((((s4_l0 == _x_s4_l0) && (s4_l1 == _x_s4_l1)) && (s4_l2 == _x_s4_l2)) && ((delta + (s4_z + (-1.0 * _x_s4_z))) == 0.0))))) && ((((((s4_l0 == _x_s4_l0) && (s4_l1 == _x_s4_l1)) && (s4_l2 == _x_s4_l2)) && ((delta + (s4_x + (-1.0 * _x_s4_x))) == 0.0)) && (((delta + (s4_y + (-1.0 * _x_s4_y))) == 0.0) && ((delta + (s4_z + (-1.0 * _x_s4_z))) == 0.0))) || ( !(( !s4_evt0) && ( !s4_evt1))))) && (((((s4_evt0 && s4_evt1) && (( !_x_s4_l2) && (_x_s4_l0 && ( !_x_s4_l1)))) && ((_x_s4_x == 0.0) && (_x_s4_y == 0.0))) && (s4_z == _x_s4_z)) || ( !((( !s4_l2) && (( !s4_l0) && ( !s4_l1))) && ((delta == 0.0) && ( !(( !s4_evt0) && ( !s4_evt1)))))))) && (((((( !_x_s4_l2) && (_x_s4_l1 && ( !_x_s4_l0))) || (( !_x_s4_l2) && (_x_s4_l0 && _x_s4_l1))) && (s4_x == _x_s4_x)) && ((s4_z == _x_s4_z) && (s4_y == _x_s4_y))) || ( !((( !s4_l2) && (s4_l0 && ( !s4_l1))) && ((delta == 0.0) && ( !(( !s4_evt0) && ( !s4_evt1)))))))) && (((s4_evt0 && ( !s4_evt1)) && ((20.0 <= s4_x) && ( !(120.0 <= s4_z)))) || ( !(((delta == 0.0) && ( !(( !s4_evt0) && ( !s4_evt1)))) && ((( !s4_l2) && (s4_l0 && ( !s4_l1))) && (( !_x_s4_l2) && (_x_s4_l1 && ( !_x_s4_l0)))))))) && (((s4_evt1 && ( !s4_evt0)) && ((20.0 <= s4_x) && (120.0 <= s4_z))) || ( !(((delta == 0.0) && ( !(( !s4_evt0) && ( !s4_evt1)))) && ((( !s4_l2) && (s4_l0 && ( !s4_l1))) && (( !_x_s4_l2) && (_x_s4_l0 && _x_s4_l1))))))) && (((s4_z == _x_s4_z) && (((s4_evt1 && ( !s4_evt0)) && (( !_x_s4_l2) && (_x_s4_l0 && _x_s4_l1))) && ((s4_x == _x_s4_x) && (s4_y == _x_s4_y)))) || ( !((( !s4_l2) && (s4_l1 && ( !s4_l0))) && ((delta == 0.0) && ( !(( !s4_evt0) && ( !s4_evt1)))))))) && (((((s4_evt0 && s4_evt1) && (_x_s4_l2 && (( !_x_s4_l0) && ( !_x_s4_l1)))) && ((_x_s4_x == 0.0) && (s4_y == _x_s4_y))) && (_x_s4_z == 0.0)) || ( !((( !s4_l2) && (s4_l0 && s4_l1)) && ((delta == 0.0) && ( !(( !s4_evt0) && ( !s4_evt1)))))))) && ((((s4_x == _x_s4_x) && (s4_y == _x_s4_y)) && ((s4_z == _x_s4_z) && ((( !_x_s4_l2) && (( !_x_s4_l0) && ( !_x_s4_l1))) || (_x_s4_l2 && (_x_s4_l0 && ( !_x_s4_l1)))))) || ( !((s4_l2 && (( !s4_l0) && ( !s4_l1))) && ((delta == 0.0) && ( !(( !s4_evt0) && ( !s4_evt1)))))))) && (((s4_evt0 && ( !s4_evt1)) && ((20.0 <= s4_x) && ( !(120.0 <= s4_y)))) || ( !(((delta == 0.0) && ( !(( !s4_evt0) && ( !s4_evt1)))) && ((s4_l2 && (( !s4_l0) && ( !s4_l1))) && (_x_s4_l2 && (_x_s4_l0 && ( !_x_s4_l1)))))))) && (((s4_evt1 && ( !s4_evt0)) && ((20.0 <= s4_x) && (120.0 <= s4_y))) || ( !(((delta == 0.0) && ( !(( !s4_evt0) && ( !s4_evt1)))) && ((( !_x_s4_l2) && (( !_x_s4_l0) && ( !_x_s4_l1))) && (s4_l2 && (( !s4_l0) && ( !s4_l1)))))))) && (((s4_z == _x_s4_z) && (((s4_x == _x_s4_x) && (s4_y == _x_s4_y)) && ((s4_evt1 && ( !s4_evt0)) && (( !_x_s4_l2) && (( !_x_s4_l0) && ( !_x_s4_l1)))))) || ( !((s4_l2 && (s4_l0 && ( !s4_l1))) && ((delta == 0.0) && ( !(( !s4_evt0) && ( !s4_evt1)))))))) && ((((((((((((((((((((( !_x_s3_evt0) && ( !_x_s3_evt1)) || (_x_s3_evt0 && ( !_x_s3_evt1))) || ((_x_s3_evt1 && ( !_x_s3_evt0)) || (_x_s3_evt0 && _x_s3_evt1))) && ((((( !_x_s3_l2) && (( !_x_s3_l0) && ( !_x_s3_l1))) || (( !_x_s3_l2) && (_x_s3_l0 && ( !_x_s3_l1)))) || ((( !_x_s3_l2) && (_x_s3_l1 && ( !_x_s3_l0))) || (( !_x_s3_l2) && (_x_s3_l0 && _x_s3_l1)))) || ((_x_s3_l2 && (( !_x_s3_l0) && ( !_x_s3_l1))) || (_x_s3_l2 && (_x_s3_l0 && ( !_x_s3_l1)))))) && ((_x_s3_x <= 20.0) || ( !(( !_x_s3_l2) && (_x_s3_l0 && ( !_x_s3_l1)))))) && ((_x_s3_x <= 120.0) || ( !(( !_x_s3_l2) && (_x_s3_l1 && ( !_x_s3_l0)))))) && ((_x_s3_x <= 120.0) || ( !(_x_s3_l2 && (_x_s3_l0 && ( !_x_s3_l1)))))) && ((delta <= 0.0) || ((((delta + (s3_x + (-1.0 * _x_s3_x))) == 0.0) && ((delta + (s3_y + (-1.0 * _x_s3_y))) == 0.0)) && ((((s3_l0 == _x_s3_l0) && (s3_l1 == _x_s3_l1)) && (s3_l2 == _x_s3_l2)) && ((delta + (s3_z + (-1.0 * _x_s3_z))) == 0.0))))) && ((((((s3_l0 == _x_s3_l0) && (s3_l1 == _x_s3_l1)) && (s3_l2 == _x_s3_l2)) && ((delta + (s3_x + (-1.0 * _x_s3_x))) == 0.0)) && (((delta + (s3_y + (-1.0 * _x_s3_y))) == 0.0) && ((delta + (s3_z + (-1.0 * _x_s3_z))) == 0.0))) || ( !(( !s3_evt0) && ( !s3_evt1))))) && (((((s3_evt0 && s3_evt1) && (( !_x_s3_l2) && (_x_s3_l0 && ( !_x_s3_l1)))) && ((_x_s3_x == 0.0) && (_x_s3_y == 0.0))) && (s3_z == _x_s3_z)) || ( !((( !s3_l2) && (( !s3_l0) && ( !s3_l1))) && ((delta == 0.0) && ( !(( !s3_evt0) && ( !s3_evt1)))))))) && (((((( !_x_s3_l2) && (_x_s3_l1 && ( !_x_s3_l0))) || (( !_x_s3_l2) && (_x_s3_l0 && _x_s3_l1))) && (s3_x == _x_s3_x)) && ((s3_z == _x_s3_z) && (s3_y == _x_s3_y))) || ( !((( !s3_l2) && (s3_l0 && ( !s3_l1))) && ((delta == 0.0) && ( !(( !s3_evt0) && ( !s3_evt1)))))))) && (((s3_evt0 && ( !s3_evt1)) && ((20.0 <= s3_x) && ( !(120.0 <= s3_z)))) || ( !(((delta == 0.0) && ( !(( !s3_evt0) && ( !s3_evt1)))) && ((( !s3_l2) && (s3_l0 && ( !s3_l1))) && (( !_x_s3_l2) && (_x_s3_l1 && ( !_x_s3_l0)))))))) && (((s3_evt1 && ( !s3_evt0)) && ((20.0 <= s3_x) && (120.0 <= s3_z))) || ( !(((delta == 0.0) && ( !(( !s3_evt0) && ( !s3_evt1)))) && ((( !s3_l2) && (s3_l0 && ( !s3_l1))) && (( !_x_s3_l2) && (_x_s3_l0 && _x_s3_l1))))))) && (((s3_z == _x_s3_z) && (((s3_evt1 && ( !s3_evt0)) && (( !_x_s3_l2) && (_x_s3_l0 && _x_s3_l1))) && ((s3_x == _x_s3_x) && (s3_y == _x_s3_y)))) || ( !((( !s3_l2) && (s3_l1 && ( !s3_l0))) && ((delta == 0.0) && ( !(( !s3_evt0) && ( !s3_evt1)))))))) && (((((s3_evt0 && s3_evt1) && (_x_s3_l2 && (( !_x_s3_l0) && ( !_x_s3_l1)))) && ((_x_s3_x == 0.0) && (s3_y == _x_s3_y))) && (_x_s3_z == 0.0)) || ( !((( !s3_l2) && (s3_l0 && s3_l1)) && ((delta == 0.0) && ( !(( !s3_evt0) && ( !s3_evt1)))))))) && ((((s3_x == _x_s3_x) && (s3_y == _x_s3_y)) && ((s3_z == _x_s3_z) && ((( !_x_s3_l2) && (( !_x_s3_l0) && ( !_x_s3_l1))) || (_x_s3_l2 && (_x_s3_l0 && ( !_x_s3_l1)))))) || ( !((s3_l2 && (( !s3_l0) && ( !s3_l1))) && ((delta == 0.0) && ( !(( !s3_evt0) && ( !s3_evt1)))))))) && (((s3_evt0 && ( !s3_evt1)) && ((20.0 <= s3_x) && ( !(120.0 <= s3_y)))) || ( !(((delta == 0.0) && ( !(( !s3_evt0) && ( !s3_evt1)))) && ((s3_l2 && (( !s3_l0) && ( !s3_l1))) && (_x_s3_l2 && (_x_s3_l0 && ( !_x_s3_l1)))))))) && (((s3_evt1 && ( !s3_evt0)) && ((20.0 <= s3_x) && (120.0 <= s3_y))) || ( !(((delta == 0.0) && ( !(( !s3_evt0) && ( !s3_evt1)))) && ((( !_x_s3_l2) && (( !_x_s3_l0) && ( !_x_s3_l1))) && (s3_l2 && (( !s3_l0) && ( !s3_l1)))))))) && (((s3_z == _x_s3_z) && (((s3_x == _x_s3_x) && (s3_y == _x_s3_y)) && ((s3_evt1 && ( !s3_evt0)) && (( !_x_s3_l2) && (( !_x_s3_l0) && ( !_x_s3_l1)))))) || ( !((s3_l2 && (s3_l0 && ( !s3_l1))) && ((delta == 0.0) && ( !(( !s3_evt0) && ( !s3_evt1)))))))) && ((((((((((((((((((((( !_x_s2_evt0) && ( !_x_s2_evt1)) || (_x_s2_evt0 && ( !_x_s2_evt1))) || ((_x_s2_evt1 && ( !_x_s2_evt0)) || (_x_s2_evt0 && _x_s2_evt1))) && ((((( !_x_s2_l2) && (( !_x_s2_l0) && ( !_x_s2_l1))) || (( !_x_s2_l2) && (_x_s2_l0 && ( !_x_s2_l1)))) || ((( !_x_s2_l2) && (_x_s2_l1 && ( !_x_s2_l0))) || (( !_x_s2_l2) && (_x_s2_l0 && _x_s2_l1)))) || ((_x_s2_l2 && (( !_x_s2_l0) && ( !_x_s2_l1))) || (_x_s2_l2 && (_x_s2_l0 && ( !_x_s2_l1)))))) && ((_x_s2_x <= 20.0) || ( !(( !_x_s2_l2) && (_x_s2_l0 && ( !_x_s2_l1)))))) && ((_x_s2_x <= 120.0) || ( !(( !_x_s2_l2) && (_x_s2_l1 && ( !_x_s2_l0)))))) && ((_x_s2_x <= 120.0) || ( !(_x_s2_l2 && (_x_s2_l0 && ( !_x_s2_l1)))))) && ((delta <= 0.0) || ((((delta + (s2_x + (-1.0 * _x_s2_x))) == 0.0) && ((delta + (s2_y + (-1.0 * _x_s2_y))) == 0.0)) && ((((s2_l0 == _x_s2_l0) && (s2_l1 == _x_s2_l1)) && (s2_l2 == _x_s2_l2)) && ((delta + (s2_z + (-1.0 * _x_s2_z))) == 0.0))))) && ((((((s2_l0 == _x_s2_l0) && (s2_l1 == _x_s2_l1)) && (s2_l2 == _x_s2_l2)) && ((delta + (s2_x + (-1.0 * _x_s2_x))) == 0.0)) && (((delta + (s2_y + (-1.0 * _x_s2_y))) == 0.0) && ((delta + (s2_z + (-1.0 * _x_s2_z))) == 0.0))) || ( !(( !s2_evt0) && ( !s2_evt1))))) && (((((s2_evt0 && s2_evt1) && (( !_x_s2_l2) && (_x_s2_l0 && ( !_x_s2_l1)))) && ((_x_s2_x == 0.0) && (_x_s2_y == 0.0))) && (s2_z == _x_s2_z)) || ( !((( !s2_l2) && (( !s2_l0) && ( !s2_l1))) && ((delta == 0.0) && ( !(( !s2_evt0) && ( !s2_evt1)))))))) && (((((( !_x_s2_l2) && (_x_s2_l1 && ( !_x_s2_l0))) || (( !_x_s2_l2) && (_x_s2_l0 && _x_s2_l1))) && (s2_x == _x_s2_x)) && ((s2_z == _x_s2_z) && (s2_y == _x_s2_y))) || ( !((( !s2_l2) && (s2_l0 && ( !s2_l1))) && ((delta == 0.0) && ( !(( !s2_evt0) && ( !s2_evt1)))))))) && (((s2_evt0 && ( !s2_evt1)) && ((20.0 <= s2_x) && ( !(120.0 <= s2_z)))) || ( !(((delta == 0.0) && ( !(( !s2_evt0) && ( !s2_evt1)))) && ((( !s2_l2) && (s2_l0 && ( !s2_l1))) && (( !_x_s2_l2) && (_x_s2_l1 && ( !_x_s2_l0)))))))) && (((s2_evt1 && ( !s2_evt0)) && ((20.0 <= s2_x) && (120.0 <= s2_z))) || ( !(((delta == 0.0) && ( !(( !s2_evt0) && ( !s2_evt1)))) && ((( !s2_l2) && (s2_l0 && ( !s2_l1))) && (( !_x_s2_l2) && (_x_s2_l0 && _x_s2_l1))))))) && (((s2_z == _x_s2_z) && (((s2_evt1 && ( !s2_evt0)) && (( !_x_s2_l2) && (_x_s2_l0 && _x_s2_l1))) && ((s2_x == _x_s2_x) && (s2_y == _x_s2_y)))) || ( !((( !s2_l2) && (s2_l1 && ( !s2_l0))) && ((delta == 0.0) && ( !(( !s2_evt0) && ( !s2_evt1)))))))) && (((((s2_evt0 && s2_evt1) && (_x_s2_l2 && (( !_x_s2_l0) && ( !_x_s2_l1)))) && ((_x_s2_x == 0.0) && (s2_y == _x_s2_y))) && (_x_s2_z == 0.0)) || ( !((( !s2_l2) && (s2_l0 && s2_l1)) && ((delta == 0.0) && ( !(( !s2_evt0) && ( !s2_evt1)))))))) && ((((s2_x == _x_s2_x) && (s2_y == _x_s2_y)) && ((s2_z == _x_s2_z) && ((( !_x_s2_l2) && (( !_x_s2_l0) && ( !_x_s2_l1))) || (_x_s2_l2 && (_x_s2_l0 && ( !_x_s2_l1)))))) || ( !((s2_l2 && (( !s2_l0) && ( !s2_l1))) && ((delta == 0.0) && ( !(( !s2_evt0) && ( !s2_evt1)))))))) && (((s2_evt0 && ( !s2_evt1)) && ((20.0 <= s2_x) && ( !(120.0 <= s2_y)))) || ( !(((delta == 0.0) && ( !(( !s2_evt0) && ( !s2_evt1)))) && ((s2_l2 && (( !s2_l0) && ( !s2_l1))) && (_x_s2_l2 && (_x_s2_l0 && ( !_x_s2_l1)))))))) && (((s2_evt1 && ( !s2_evt0)) && ((20.0 <= s2_x) && (120.0 <= s2_y))) || ( !(((delta == 0.0) && ( !(( !s2_evt0) && ( !s2_evt1)))) && ((( !_x_s2_l2) && (( !_x_s2_l0) && ( !_x_s2_l1))) && (s2_l2 && (( !s2_l0) && ( !s2_l1)))))))) && (((s2_z == _x_s2_z) && (((s2_x == _x_s2_x) && (s2_y == _x_s2_y)) && ((s2_evt1 && ( !s2_evt0)) && (( !_x_s2_l2) && (( !_x_s2_l0) && ( !_x_s2_l1)))))) || ( !((s2_l2 && (s2_l0 && ( !s2_l1))) && ((delta == 0.0) && ( !(( !s2_evt0) && ( !s2_evt1)))))))) && ((((((((((((((((((((( !_x_s1_evt0) && ( !_x_s1_evt1)) || (_x_s1_evt0 && ( !_x_s1_evt1))) || ((_x_s1_evt1 && ( !_x_s1_evt0)) || (_x_s1_evt0 && _x_s1_evt1))) && ((((( !_x_s1_l2) && (( !_x_s1_l0) && ( !_x_s1_l1))) || (( !_x_s1_l2) && (_x_s1_l0 && ( !_x_s1_l1)))) || ((( !_x_s1_l2) && (_x_s1_l1 && ( !_x_s1_l0))) || (( !_x_s1_l2) && (_x_s1_l0 && _x_s1_l1)))) || ((_x_s1_l2 && (( !_x_s1_l0) && ( !_x_s1_l1))) || (_x_s1_l2 && (_x_s1_l0 && ( !_x_s1_l1)))))) && ((_x_s1_x <= 20.0) || ( !(( !_x_s1_l2) && (_x_s1_l0 && ( !_x_s1_l1)))))) && ((_x_s1_x <= 120.0) || ( !(( !_x_s1_l2) && (_x_s1_l1 && ( !_x_s1_l0)))))) && ((_x_s1_x <= 120.0) || ( !(_x_s1_l2 && (_x_s1_l0 && ( !_x_s1_l1)))))) && ((delta <= 0.0) || ((((delta + (s1_x + (-1.0 * _x_s1_x))) == 0.0) && ((delta + (s1_y + (-1.0 * _x_s1_y))) == 0.0)) && ((((s1_l0 == _x_s1_l0) && (s1_l1 == _x_s1_l1)) && (s1_l2 == _x_s1_l2)) && ((delta + (s1_z + (-1.0 * _x_s1_z))) == 0.0))))) && ((((((s1_l0 == _x_s1_l0) && (s1_l1 == _x_s1_l1)) && (s1_l2 == _x_s1_l2)) && ((delta + (s1_x + (-1.0 * _x_s1_x))) == 0.0)) && (((delta + (s1_y + (-1.0 * _x_s1_y))) == 0.0) && ((delta + (s1_z + (-1.0 * _x_s1_z))) == 0.0))) || ( !(( !s1_evt0) && ( !s1_evt1))))) && (((((s1_evt0 && s1_evt1) && (( !_x_s1_l2) && (_x_s1_l0 && ( !_x_s1_l1)))) && ((_x_s1_x == 0.0) && (_x_s1_y == 0.0))) && (s1_z == _x_s1_z)) || ( !((( !s1_l2) && (( !s1_l0) && ( !s1_l1))) && ((delta == 0.0) && ( !(( !s1_evt0) && ( !s1_evt1)))))))) && (((((( !_x_s1_l2) && (_x_s1_l1 && ( !_x_s1_l0))) || (( !_x_s1_l2) && (_x_s1_l0 && _x_s1_l1))) && (s1_x == _x_s1_x)) && ((s1_z == _x_s1_z) && (s1_y == _x_s1_y))) || ( !((( !s1_l2) && (s1_l0 && ( !s1_l1))) && ((delta == 0.0) && ( !(( !s1_evt0) && ( !s1_evt1)))))))) && (((s1_evt0 && ( !s1_evt1)) && ((20.0 <= s1_x) && ( !(120.0 <= s1_z)))) || ( !(((delta == 0.0) && ( !(( !s1_evt0) && ( !s1_evt1)))) && ((( !s1_l2) && (s1_l0 && ( !s1_l1))) && (( !_x_s1_l2) && (_x_s1_l1 && ( !_x_s1_l0)))))))) && (((s1_evt1 && ( !s1_evt0)) && ((20.0 <= s1_x) && (120.0 <= s1_z))) || ( !(((delta == 0.0) && ( !(( !s1_evt0) && ( !s1_evt1)))) && ((( !s1_l2) && (s1_l0 && ( !s1_l1))) && (( !_x_s1_l2) && (_x_s1_l0 && _x_s1_l1))))))) && (((s1_z == _x_s1_z) && (((s1_evt1 && ( !s1_evt0)) && (( !_x_s1_l2) && (_x_s1_l0 && _x_s1_l1))) && ((s1_x == _x_s1_x) && (s1_y == _x_s1_y)))) || ( !((( !s1_l2) && (s1_l1 && ( !s1_l0))) && ((delta == 0.0) && ( !(( !s1_evt0) && ( !s1_evt1)))))))) && (((((s1_evt0 && s1_evt1) && (_x_s1_l2 && (( !_x_s1_l0) && ( !_x_s1_l1)))) && ((_x_s1_x == 0.0) && (s1_y == _x_s1_y))) && (_x_s1_z == 0.0)) || ( !((( !s1_l2) && (s1_l0 && s1_l1)) && ((delta == 0.0) && ( !(( !s1_evt0) && ( !s1_evt1)))))))) && ((((s1_x == _x_s1_x) && (s1_y == _x_s1_y)) && ((s1_z == _x_s1_z) && ((( !_x_s1_l2) && (( !_x_s1_l0) && ( !_x_s1_l1))) || (_x_s1_l2 && (_x_s1_l0 && ( !_x_s1_l1)))))) || ( !((s1_l2 && (( !s1_l0) && ( !s1_l1))) && ((delta == 0.0) && ( !(( !s1_evt0) && ( !s1_evt1)))))))) && (((s1_evt0 && ( !s1_evt1)) && ((20.0 <= s1_x) && ( !(120.0 <= s1_y)))) || ( !(((delta == 0.0) && ( !(( !s1_evt0) && ( !s1_evt1)))) && ((s1_l2 && (( !s1_l0) && ( !s1_l1))) && (_x_s1_l2 && (_x_s1_l0 && ( !_x_s1_l1)))))))) && (((s1_evt1 && ( !s1_evt0)) && ((20.0 <= s1_x) && (120.0 <= s1_y))) || ( !(((delta == 0.0) && ( !(( !s1_evt0) && ( !s1_evt1)))) && ((( !_x_s1_l2) && (( !_x_s1_l0) && ( !_x_s1_l1))) && (s1_l2 && (( !s1_l0) && ( !s1_l1)))))))) && (((s1_z == _x_s1_z) && (((s1_x == _x_s1_x) && (s1_y == _x_s1_y)) && ((s1_evt1 && ( !s1_evt0)) && (( !_x_s1_l2) && (( !_x_s1_l0) && ( !_x_s1_l1)))))) || ( !((s1_l2 && (s1_l0 && ( !s1_l1))) && ((delta == 0.0) && ( !(( !s1_evt0) && ( !s1_evt1)))))))) && ((((((((((((((((((((( !_x_s0_evt0) && ( !_x_s0_evt1)) || (_x_s0_evt0 && ( !_x_s0_evt1))) || ((_x_s0_evt1 && ( !_x_s0_evt0)) || (_x_s0_evt0 && _x_s0_evt1))) && ((((( !_x_s0_l2) && (( !_x_s0_l0) && ( !_x_s0_l1))) || (( !_x_s0_l2) && (_x_s0_l0 && ( !_x_s0_l1)))) || ((( !_x_s0_l2) && (_x_s0_l1 && ( !_x_s0_l0))) || (( !_x_s0_l2) && (_x_s0_l0 && _x_s0_l1)))) || ((_x_s0_l2 && (( !_x_s0_l0) && ( !_x_s0_l1))) || (_x_s0_l2 && (_x_s0_l0 && ( !_x_s0_l1)))))) && ((_x_s0_x <= 20.0) || ( !(( !_x_s0_l2) && (_x_s0_l0 && ( !_x_s0_l1)))))) && ((_x_s0_x <= 120.0) || ( !(( !_x_s0_l2) && (_x_s0_l1 && ( !_x_s0_l0)))))) && ((_x_s0_x <= 120.0) || ( !(_x_s0_l2 && (_x_s0_l0 && ( !_x_s0_l1)))))) && ((delta <= 0.0) || ((((delta + (s0_x + (-1.0 * _x_s0_x))) == 0.0) && ((delta + (s0_y + (-1.0 * _x_s0_y))) == 0.0)) && ((((s0_l0 == _x_s0_l0) && (s0_l1 == _x_s0_l1)) && (s0_l2 == _x_s0_l2)) && ((delta + (s0_z + (-1.0 * _x_s0_z))) == 0.0))))) && ((((((s0_l0 == _x_s0_l0) && (s0_l1 == _x_s0_l1)) && (s0_l2 == _x_s0_l2)) && ((delta + (s0_x + (-1.0 * _x_s0_x))) == 0.0)) && (((delta + (s0_y + (-1.0 * _x_s0_y))) == 0.0) && ((delta + (s0_z + (-1.0 * _x_s0_z))) == 0.0))) || ( !(( !s0_evt0) && ( !s0_evt1))))) && (((((s0_evt0 && s0_evt1) && (( !_x_s0_l2) && (_x_s0_l0 && ( !_x_s0_l1)))) && ((_x_s0_x == 0.0) && (_x_s0_y == 0.0))) && (s0_z == _x_s0_z)) || ( !((( !s0_l2) && (( !s0_l0) && ( !s0_l1))) && ((delta == 0.0) && ( !(( !s0_evt0) && ( !s0_evt1)))))))) && (((((( !_x_s0_l2) && (_x_s0_l1 && ( !_x_s0_l0))) || (( !_x_s0_l2) && (_x_s0_l0 && _x_s0_l1))) && (s0_x == _x_s0_x)) && ((s0_z == _x_s0_z) && (s0_y == _x_s0_y))) || ( !((( !s0_l2) && (s0_l0 && ( !s0_l1))) && ((delta == 0.0) && ( !(( !s0_evt0) && ( !s0_evt1)))))))) && (((s0_evt0 && ( !s0_evt1)) && ((20.0 <= s0_x) && ( !(120.0 <= s0_z)))) || ( !(((delta == 0.0) && ( !(( !s0_evt0) && ( !s0_evt1)))) && ((( !s0_l2) && (s0_l0 && ( !s0_l1))) && (( !_x_s0_l2) && (_x_s0_l1 && ( !_x_s0_l0)))))))) && (((s0_evt1 && ( !s0_evt0)) && ((20.0 <= s0_x) && (120.0 <= s0_z))) || ( !(((delta == 0.0) && ( !(( !s0_evt0) && ( !s0_evt1)))) && ((( !s0_l2) && (s0_l0 && ( !s0_l1))) && (( !_x_s0_l2) && (_x_s0_l0 && _x_s0_l1))))))) && (((s0_z == _x_s0_z) && (((s0_evt1 && ( !s0_evt0)) && (( !_x_s0_l2) && (_x_s0_l0 && _x_s0_l1))) && ((s0_x == _x_s0_x) && (s0_y == _x_s0_y)))) || ( !((( !s0_l2) && (s0_l1 && ( !s0_l0))) && ((delta == 0.0) && ( !(( !s0_evt0) && ( !s0_evt1)))))))) && (((((s0_evt0 && s0_evt1) && (_x_s0_l2 && (( !_x_s0_l0) && ( !_x_s0_l1)))) && ((_x_s0_x == 0.0) && (s0_y == _x_s0_y))) && (_x_s0_z == 0.0)) || ( !((( !s0_l2) && (s0_l0 && s0_l1)) && ((delta == 0.0) && ( !(( !s0_evt0) && ( !s0_evt1)))))))) && ((((s0_x == _x_s0_x) && (s0_y == _x_s0_y)) && ((s0_z == _x_s0_z) && ((( !_x_s0_l2) && (( !_x_s0_l0) && ( !_x_s0_l1))) || (_x_s0_l2 && (_x_s0_l0 && ( !_x_s0_l1)))))) || ( !((s0_l2 && (( !s0_l0) && ( !s0_l1))) && ((delta == 0.0) && ( !(( !s0_evt0) && ( !s0_evt1)))))))) && (((s0_evt0 && ( !s0_evt1)) && ((20.0 <= s0_x) && ( !(120.0 <= s0_y)))) || ( !(((delta == 0.0) && ( !(( !s0_evt0) && ( !s0_evt1)))) && ((s0_l2 && (( !s0_l0) && ( !s0_l1))) && (_x_s0_l2 && (_x_s0_l0 && ( !_x_s0_l1)))))))) && (((s0_evt1 && ( !s0_evt0)) && ((20.0 <= s0_x) && (120.0 <= s0_y))) || ( !(((delta == 0.0) && ( !(( !s0_evt0) && ( !s0_evt1)))) && ((( !_x_s0_l2) && (( !_x_s0_l0) && ( !_x_s0_l1))) && (s0_l2 && (( !s0_l0) && ( !s0_l1)))))))) && (((s0_z == _x_s0_z) && (((s0_x == _x_s0_x) && (s0_y == _x_s0_y)) && ((s0_evt1 && ( !s0_evt0)) && (( !_x_s0_l2) && (( !_x_s0_l0) && ( !_x_s0_l1)))))) || ( !((s0_l2 && (s0_l0 && ( !s0_l1))) && ((delta == 0.0) && ( !(( !s0_evt0) && ( !s0_evt1)))))))) && ((((((((((((((_x_r_evt_id == 0) || (_x_r_evt_id == 1)) || (_x_r_evt_id == 2)) || (_x_r_evt_id == 3)) || (_x_r_evt_id == 4)) || (_x_r_evt_id == 5)) && ((((((_x_r_counter == 0) || (_x_r_counter == 1)) || (_x_r_counter == 2)) || (_x_r_counter == 3)) || (_x_r_counter == 4)) || (_x_r_counter == 5))) && (( !_x_r_l) || (_x_r_x <= 0.0))) && ((delta <= 0.0) || (((delta + (r_x + (-1.0 * _x_r_x))) == 0.0) && ((r_l == _x_r_l) && (r_counter == _x_r_counter))))) && (((r_l == _x_r_l) && (((delta + (r_x + (-1.0 * _x_r_x))) == 0.0) && (r_counter == _x_r_counter))) || ( !(( !r_event0) && ( !r_event1))))) && (((((r_event1 && ( !r_event0)) && (r_x <= 0.0)) && (( !_x_r_l) && (r_evt_id == r_counter))) && ((r_counter == _x_r_counter) && (r_x == _x_r_x))) || ( !(r_l && (( !(( !r_event0) && ( !r_event1))) && (delta == 0.0)))))) && ((_x_r_l && (((r_event0 && ( !r_event1)) && (r_evt_id == r_counter)) && ((_x_r_x == 0.0) && ((r_counter + (-1 * _x_r_counter)) == -1)))) || ( !((( !(( !r_event0) && ( !r_event1))) && (delta == 0.0)) && (( !r_l) && ( !(5 <= r_counter))))))) && ((_x_r_l && (((r_event0 && ( !r_event1)) && (r_evt_id == r_counter)) && ((_x_r_counter == 0) && (_x_r_x == 0.0)))) || ( !((( !(( !r_event0) && ( !r_event1))) && (delta == 0.0)) && (( !r_l) && (r_counter == 5)))))) && (0.0 <= _x_delta)))))))) && ((( !(( !s5_evt0) && ( !s5_evt1))) || (( !(( !s4_evt0) && ( !s4_evt1))) || (( !(( !s3_evt0) && ( !s3_evt1))) || (( !(( !s2_evt0) && ( !s2_evt1))) || (( !(( !s1_evt0) && ( !s1_evt1))) || (( !(( !r_event0) && ( !r_event1))) || ( !(( !s0_evt0) && ( !s0_evt1))))))))) || ( !(delta == 0.0)))) && (( !(delta == 0.0)) || ((s0_evt1 && ( !s0_evt0)) == ((r_event0 && ( !r_event1)) && (r_evt_id == 0))))) && (( !(delta == 0.0)) || ((s0_evt0 && s0_evt1) == ((r_event1 && ( !r_event0)) && (r_evt_id == 0))))) && (( !(delta == 0.0)) || ((s1_evt1 && ( !s1_evt0)) == ((r_event0 && ( !r_event1)) && (r_evt_id == 1))))) && (( !(delta == 0.0)) || ((s1_evt0 && s1_evt1) == ((r_event1 && ( !r_event0)) && (r_evt_id == 1))))) && (( !(delta == 0.0)) || ((s2_evt1 && ( !s2_evt0)) == ((r_event0 && ( !r_event1)) && (r_evt_id == 2))))) && (( !(delta == 0.0)) || ((s2_evt0 && s2_evt1) == ((r_event1 && ( !r_event0)) && (r_evt_id == 2))))) && (( !(delta == 0.0)) || ((s3_evt1 && ( !s3_evt0)) == ((r_event0 && ( !r_event1)) && (r_evt_id == 3))))) && (( !(delta == 0.0)) || ((s3_evt0 && s3_evt1) == ((r_event1 && ( !r_event0)) && (r_evt_id == 3))))) && (( !(delta == 0.0)) || ((s4_evt1 && ( !s4_evt0)) == ((r_event0 && ( !r_event1)) && (r_evt_id == 4))))) && (( !(delta == 0.0)) || ((s4_evt0 && s4_evt1) == ((r_event1 && ( !r_event0)) && (r_evt_id == 4))))) && (( !(delta == 0.0)) || ((s5_evt1 && ( !s5_evt0)) == ((r_event0 && ( !r_event1)) && (r_evt_id == 5))))) && (( !(delta == 0.0)) || ((s5_evt0 && s5_evt1) == ((r_event1 && ( !r_event0)) && (r_evt_id == 5))))) && (((delta == _x__diverge_delta) || ( !(1.0 <= _diverge_delta))) && ((1.0 <= _diverge_delta) || ((delta + (_diverge_delta + (-1.0 * _x__diverge_delta))) == 0.0)))) && ((((((_EL_U_1559 == (_x__EL_U_1559 || ( !(_x__EL_U_1557 || (1.0 <= _x__diverge_delta))))) && ((_EL_U_1557 == (_x__EL_U_1557 || (1.0 <= _x__diverge_delta))) && ((_EL_U_1561 == ((_x_s0_l2 && (_x_s0_l0 && ( !_x_s0_l1))) || _x__EL_U_1561)) && (_EL_U_1563 == (_x__EL_U_1563 || ( !((_x_s0_l2 && (_x_s0_l0 && ( !_x_s0_l1))) || _x__EL_U_1561))))))) && (_x__J1583 == (( !(((_J1583 && _J1589) && _J1595) && _J1601)) && ((((_J1583 && _J1589) && _J1595) && _J1601) || (((s0_l2 && (s0_l0 && ( !s0_l1))) || ( !((s0_l2 && (s0_l0 && ( !s0_l1))) || _EL_U_1561))) || _J1583))))) && (_x__J1589 == (( !(((_J1583 && _J1589) && _J1595) && _J1601)) && ((((_J1583 && _J1589) && _J1595) && _J1601) || ((( !((s0_l2 && (s0_l0 && ( !s0_l1))) || _EL_U_1561)) || ( !(_EL_U_1563 || ( !((s0_l2 && (s0_l0 && ( !s0_l1))) || _EL_U_1561))))) || _J1589))))) && (_x__J1595 == (( !(((_J1583 && _J1589) && _J1595) && _J1601)) && ((((_J1583 && _J1589) && _J1595) && _J1601) || (((1.0 <= _diverge_delta) || ( !((1.0 <= _diverge_delta) || _EL_U_1557))) || _J1595))))) && (_x__J1601 == (( !(((_J1583 && _J1589) && _J1595) && _J1601)) && ((((_J1583 && _J1589) && _J1595) && _J1601) || ((( !((1.0 <= _diverge_delta) || _EL_U_1557)) || ( !(_EL_U_1559 || ( !((1.0 <= _diverge_delta) || _EL_U_1557))))) || _J1601))))));
_diverge_delta = _x__diverge_delta;
delta = _x_delta;
r_x = _x_r_x;
s3_evt1 = _x_s3_evt1;
s3_evt0 = _x_s3_evt0;
r_l = _x_r_l;
s1_z = _x_s1_z;
r_counter = _x_r_counter;
_J1601 = _x__J1601;
s1_y = _x_s1_y;
_J1595 = _x__J1595;
_J1589 = _x__J1589;
_J1583 = _x__J1583;
_EL_U_1557 = _x__EL_U_1557;
_EL_U_1559 = _x__EL_U_1559;
_EL_U_1561 = _x__EL_U_1561;
s4_l1 = _x_s4_l1;
s1_evt1 = _x_s1_evt1;
s4_l0 = _x_s4_l0;
r_evt_id = _x_r_evt_id;
s4_l2 = _x_s4_l2;
s1_evt0 = _x_s1_evt0;
_EL_U_1563 = _x__EL_U_1563;
s4_x = _x_s4_x;
r_event0 = _x_r_event0;
r_event1 = _x_r_event1;
s2_l1 = _x_s2_l1;
s4_z = _x_s4_z;
s2_l0 = _x_s2_l0;
s4_y = _x_s4_y;
s2_l2 = _x_s2_l2;
s2_x = _x_s2_x;
s0_l1 = _x_s0_l1;
s0_l0 = _x_s0_l0;
s0_l2 = _x_s0_l2;
s4_evt1 = _x_s4_evt1;
s4_evt0 = _x_s4_evt0;
s0_x = _x_s0_x;
s2_z = _x_s2_z;
s2_y = _x_s2_y;
s5_l1 = _x_s5_l1;
s0_z = _x_s0_z;
s5_l0 = _x_s5_l0;
s0_y = _x_s0_y;
s5_l2 = _x_s5_l2;
s2_evt1 = _x_s2_evt1;
s2_evt0 = _x_s2_evt0;
s5_x = _x_s5_x;
s3_l1 = _x_s3_l1;
s0_evt1 = _x_s0_evt1;
s5_z = _x_s5_z;
s0_evt0 = _x_s0_evt0;
s5_y = _x_s5_y;
s5_evt1 = _x_s5_evt1;
s3_l0 = _x_s3_l0;
s3_l2 = _x_s3_l2;
s3_x = _x_s3_x;
s3_z = _x_s3_z;
s3_y = _x_s3_y;
s1_l1 = _x_s1_l1;
s1_l0 = _x_s1_l0;
s5_evt0 = _x_s5_evt0;
s1_l2 = _x_s1_l2;
s1_x = _x_s1_x;
}
}
|
the_stack_data/109283.c
|
//
// main.c
// Exercise 4
//
// Created by Zhehao Li on 2020/2/12.
// Copyright © 2020 Zhehao Li. All rights reserved.
//
#include <stdio.h>
#include <math.h>
void printnumber(int n);
int main(int argc, const char * argv[]) {
int n = -342383102;
printnumber(n);
return 0;
}
void printnumber(int n){
if (n < 0) {
putchar('-');
n = - n;
}
if (n / 10 != 0)
printnumber(n / 10); // recursive
putchar((n % 10) + '0');
}
|
the_stack_data/61074870.c
|
/* inform.c */
/* implements Logging.h for C stdout/stderr */
/* (C)2009 Kenneth Boyd, license: MIT.txt */
#include <stddef.h>
#include <stdio.h>
void _inform(const char* const B, size_t len)
{
fwrite(B,len,1,stderr);
fwrite("\n",1,1,stderr);
}
|
the_stack_data/26074.c
|
#include<stdio.h>
void main()
{
int i,j,row;
printf("Enter the number of rows\n");
scanf("%d",&row);
for(i = 1; i <= row;i++)
{
for(j = 1;j <= i;j++)
{
printf("* ");
}
printf("\n");
}
}
|
the_stack_data/813249.c
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define A_MEGABYTE (1024 * 1024)
#define A_KILOBYTE (1024)
#define PHY_MEM_MEGS (1024 * 200)
int main() {
char *mem_pointer;
int size_to_allocate = A_KILOBYTE;
int megs_allocated = 0;
while (1) {
for (int i = 0; i < A_MEGABYTE / A_KILOBYTE; i++) {
mem_pointer = (char *)malloc(size_to_allocate);
if (mem_pointer == NULL)
return EXIT_FAILURE;
sprintf(mem_pointer, "Hello world!");
}
megs_allocated++;
printf("Allocated %d", megs_allocated);
}
return 0;
}
|
the_stack_data/1091477.c
|
#include<stdio.h>
#include<stdlib.h>
long v = 0;
int main(int argc,char *argv[]){
int temp = 409;
if(argc > 1){
temp = atoi(argv[1]);
}
printf("temp is %d\n", temp);
printf("the v address is %p\n", &v);
printf("Now the v is %ld\n", v);
printf("Change the val of v by write int to mtest\n");
FILE* fp;
if((fp=fopen("/proc/mtest","w"))==NULL)
{
printf("The file %s can not be opened.\n","/proc/mtest");
return -1;
}
// long temp =(long) &v;
printf("writeval %p %x\n", &v, temp);
fprintf(fp, "writeval %p %x", &v, temp);
fflush(fp);
printf("Now the v is %ld\n", v);
return 0;
}
|
the_stack_data/29062.c
|
int main() {
return !0;
}
|
the_stack_data/407940.c
|
#include <stdio.h>
int search(int arr[], int initial, int last)
{
while (initial <= last) {
int mid = (initial + last) / 2;
if (arr[mid] == 1 && (mid == 0 || arr[mid - 1] == 0))
return mid;
else if (arr[mid] == 1)
last = mid - 1;
else
initial = mid + 1;
}
return -1;
}
int main()
{
int size, i;
printf("Enter size of array ");
scanf("%d",&size);
int a[size];
for(i=0;i<size;i++)
{
printf("Enter element no %d ",i+1);
scanf("%d",&a[i]);
}
int z;
z=search(a,0,size-1);
if(z==-1)
{
printf("No 1");
}
else
{
printf("%d",z);
}
return 0;
}
|
the_stack_data/31388298.c
|
#include <stdio.h>
typedef long long int64;
// прямоугольник
struct rectangle {
int64 x, y; // ширина, высота
};
struct rectangle r;
double area(struct rectangle r) {
return (double) (r.x * r.y);
}
int main() {
r.x = 5;
r.y = 10;
double p;
p = area(r);
printf("%f\n", p);
return 0;
}
|
the_stack_data/106295.c
|
/*
* IMPLEMENTING GAUSSIAN ELIMINATION METHOD
* FOR SOLVING SYSTEM OF LINEAR EQUATION
*
* A: CO-EFFICIENT MATRIX
* B: CONSTANT TERMS
* X: LIST OF VARIABLES
*/
#include <stdio.h>
void Gauss(int N, double[N][N], double[N], double[N]);
int main(void) {
int N;
printf("Enter the number of variables: ");
scanf("%d", &N);
double A[N][N], B[N], X[N];
for (int i = 0, j = 0; j < N || (j = 0, ++i) < N; j++){
printf("Enter co-efficient a(%d, %d): ", i + 1, j + 1);
scanf("%lf", &A[i][j]);
}
for (int i = 0; i < N; i++){
printf("Enter constant b(%d): ", i + 1);
scanf("%lf", B + i);
}
Gauss(N, A, B, X);
for (int i = 0; i < N || !putchar('\n'); i++)
printf("x(%d): %.4lf\t", i + 1, X[i]);
return 0;
}
void Gauss(int N, double A[N][N], double B[N], double X[N]) {
double mul, sum;
for (int j = 0; j < N; j++)
for (int i = j + 1; i < N; i++) {
mul = -(A[i][j] / A[j][j]);
for (int k = j; k < N; k++)
A[i][k] += mul * A[j][k];
B[i] += mul * B[j];
}
for (int j = N - 1; j > 0; j--)
for (int i = j - 1; i >= 0; i--) {
mul = -(A[i][j] / A[j][j]);
for (int k = j; k < N; k++)
A[i][k] += mul * A[j][k];
B[i] += mul * B[j];
}
for (int i = 0; i < N; i++)
X[i] = B[i] / A[i][i];
}
|
the_stack_data/86820.c
|
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
int
main (void)
{
void *handle = dlopen ("nodel2mod3.so", RTLD_LAZY);
if (handle == NULL)
{
printf ("%s\n", dlerror ());
exit (1);
}
dlclose (handle);
exit (1);
}
|
the_stack_data/1198402.c
|
int main() {
int *p;
return sizeof(*p);
}
|
the_stack_data/82950494.c
|
#include <stdio.h>
#include <time.h>
#include <stdbool.h>
#include <stdlib.h>
#define ARRAY_SIZE 20
#define RANGE 1001
void swap(int* first, int* second)
{
const int temporary = *first;
*first = *second;
*second = temporary;
}
int comparator(const void* first, const void* second)
{
return *(int*)first - *(int*)second;
}
void mySelectionSort(int* sortingArray, int arraySize)
{
int minIndex = 0;
for (int i = 0; i < arraySize - 1; i++)
{
minIndex = i;
for (int j = i + 1; j < arraySize; j++)
{
if (sortingArray[j] < sortingArray[minIndex])
minIndex = j;
}
swap(&sortingArray[i], &sortingArray[minIndex]);
}
}
bool checkEqual(int* sortingArray, int* correctArray, int arraySize)
{
for (int i = 0; i < arraySize; ++i)
{
if (sortingArray[i] != correctArray[i])
{
return false;
}
}
return true;
}
bool testCorrectCase()
{
int correctArray[ARRAY_SIZE] = { 0 };
int randomArray[ARRAY_SIZE] = { 0 };
srand((unsigned int)time(NULL));
for (int i = 0; i < ARRAY_SIZE; ++i)
{
const int randomElement = -ARRAY_SIZE / 2 + rand() % RANGE;
correctArray[i] = randomElement;
randomArray[i] = randomElement;
}
qsort(correctArray, ARRAY_SIZE, sizeof(int), comparator);
mySelectionSort(randomArray, ARRAY_SIZE);
return checkEqual(randomArray, correctArray, ARRAY_SIZE);
}
bool testEqualCase()
{
int randomArray[ARRAY_SIZE] = { -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5 };
int correctArray[ARRAY_SIZE] = { -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5 };
mySelectionSort(randomArray, ARRAY_SIZE);
return checkEqual(randomArray, correctArray, ARRAY_SIZE);
}
int main()
{
if (!testCorrectCase() || !testEqualCase())
{
printf("Tests failed.");
return 1;
}
printf("Size of array = 10\n");
printf("Enter elements of array: \n");
const int arraySize = 10;
int* inputArray = (int*)calloc(arraySize, sizeof(int));
if (inputArray == NULL)
{
printf("Calloc function broke :(");
return -1;
}
int randomElement = 0;
for (int i = 0; i < arraySize; ++i)
{
scanf("%d", &randomElement);
inputArray[i] = randomElement;
}
mySelectionSort(inputArray, arraySize);
printf("\nArray after using selection sort: \n");
for (int i = 0; i < arraySize; ++i)
{
printf("%d ", inputArray[i]);
}
free(inputArray);
}
|
the_stack_data/680912.c
|
/**
* 一个尾调用的测试程序。
*
* 使用:
* 通过clang -S tail.c -o tail.s -O2 生成汇编文件。
*
*/
int bar(int a, int b);
/**
* 用foo函数调用bar函数。foo函数的设计,是让它使用较多的栈桢空间,以便测试尾调用复用Caller栈桢的效果。
* 看看编译器是怎么为第二个bar调用来生成汇编代码的。
*/
int foo(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8){
int x1 = p1*p2;
int x2 = p3*p4;
int x3 = x1 + x2 + p5*p6 + bar(p7, p8);
return bar(x2,x3);
}
/**
* 如果参数数量超过了6个,那么就没办法复用栈桢了,因为要通过栈桢传参。
* */
int foo2(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8){
int x1 = p1*p2;
int x2 = p3*p4;
return foo1(x1,x2,3,4,5,6,7,8);
}
/**
* foo3复杂化了一些,有多个return分支。
* 这个时候,编译器要能够为尾调用生成jmp指令,而为其他的return语句生成ret指令。
*/
int foo3(int p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8){
int x1 = p1*p2;
int x2 = p3*p4;
int x3 = x1 + x2 + p5*p6 + bar(p7, p8);
if(x2 > x3){
return x2;
}
else{
return bar(x2,x3);
}
}
|
the_stack_data/184519267.c
|
/*
*/
#include <stdio.h>
#include <stdlib.h>
long long area(long long x1,long long y1,long long x2,long long y2,long long x3,long long y3)
{
return ((x2-x1)*(y3-y1) - (y2-y1)*(x3-x1));
}
int main()
{
FILE * in = fopen("INPUT.TXT", "r");
FILE * out = fopen("OUTPUT.TXT", "w");
long long x1 = 0;
long long y1 = 0;
long long x2 = 0;
long long y2 = 0;
long long x3 = 0;
long long y3 = 0;
long long S = 0;
fscanf(in,"%lld %lld %lld %lld %lld %lld", &x1, &y1, &x2, &y2, &x3, &y3);
S = area(x1, y1, x2, y2, x3, y3);
if(S < 0) S*= -1;
if(S%2 == 0)
fprintf(out, "%lld", S/2);
else
fprintf(out, "%.1f", (double)S/2.0);
fclose(in);
fclose(out);
return 0;
}
|
the_stack_data/95449653.c
|
/*
** EPITECH PROJECT, 2020
** getnbr.c
** File description:
** parse numbers
*/
#include <stdbool.h>
static bool detect_overflow(int *nb, int add, int sign)
{
if (sign == 1) {
if (*nb + add < 0)
return (false);
*nb = *nb + add;
return (true);
}
if ((*nb + add) * -1 > 0)
return (false);
*nb = *nb + add;
return (true);
}
static bool detect_sign(char const *str, int *i, int *sign)
{
while (!(str[*i] >= '0' && str[*i] <= '9')) {
if ((str[*i] == '+' || str[*i] == '-') || str[*i] == ' ') {
if (str[*i] == '-')
*sign *= -1;
} else {
return (false);
}
(*i)++;
}
return (true);
}
int my_getnbr(char const *str)
{
int i = 0;
int sign = 1;
int nb = 0;
if (detect_sign(str, &i, &sign) == 0)
return (0);
while (str[i] >= '0' && str[i] <= '9') {
if (nb * sign == -2147483640 && str[i] - '0' == 8)
return (-2147483648);
if (!detect_overflow(&nb, str[i] - '0', sign))
return (0);
if (str[i + 1] >= '0' && str[i + 1] <= '9')
nb *= 10;
i++;
}
return (sign * nb);
}
|
the_stack_data/31389110.c
|
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int* pi = (int*) malloc(sizeof(int));
*(pi) = 5;
printf("*pi = %d\n", *(pi));
free(pi);
return EXIT_SUCCESS;
}
|
the_stack_data/360409.c
|
#include <stdio.h>
int main() {
int hi, hf, total;
scanf("%d",&hi);
scanf("%d",&hf);
if(hi>hf){
total=24- (hi-hf);
printf("O JOGO DUROU %d HORA(S)\n", total);
}
else{
if(hf>hi){
total=hf-hi;
printf("O JOGO DUROU %d HORA(S)\n", total);
}
else{
printf("O JOGO DUROU 24 HORA(S)\n");
}
}
return 0;
}
|
the_stack_data/25138370.c
|
/* SPDX-License-Identifier: Apache-2.0
* Copyright(c) 2017 Intel Corporation
*/
#include <stdint.h>
void generate_teid(uint32_t ue, uint8_t bearer_id,
uint32_t max_ue_sess, uint32_t *teid)
{
*teid = max_ue_sess - ue + bearer_id;
}
|
the_stack_data/511879.c
|
/*
Copyright (c) 2014, Alexey Frunze
2-clause BSD license.
*/
#include <unistd.h>
#ifdef _DOS
#ifdef __HUGE__
static
int __DosSeek(int handle, unsigned short offset[2], int whence)
{
asm("mov ah, 0x42\n"
"mov bx, [bp + 8]\n"
"mov esi, [bp + 12]\n"
"ror esi, 4\n"
"mov ds, si\n"
"shr esi, 28");
asm("mov dx, [si]\n"
"mov cx, [si + 2]\n"
"mov al, [bp + 16]\n"
"int 0x21");
asm("mov bx, ax\n"
"cmc\n"
"sbb ax, ax\n"
"and dx, ax\n"
"and eax, 1");
asm("mov [si], bx\n" // offset[0] will have error code on failure
"mov [si + 2], dx"); // else offset[] will be replaced with new position
}
#endif
#ifdef __SMALLER_C_16__
static
int __DosSeek(int handle, unsigned short offset[2], int whence)
{
asm("mov ah, 0x42\n"
"mov bx, [bp + 4]\n"
"mov si, [bp + 6]");
asm("mov dx, [si]\n"
"mov cx, [si + 2]\n"
"mov al, [bp + 8]\n"
"int 0x21");
asm("mov bx, ax\n"
"cmc\n"
"sbb ax, ax\n"
"and dx, ax\n"
"and ax, 1");
asm("mov [si], bx\n" // offset[0] will have error code on failure
"mov [si + 2], dx"); // else offset[] will be replaced with new position
}
#endif
int __lseek(int fd, fpos_t* offset, int whence)
{
fpos_t o = *offset;
if (__DosSeek(fd, &o, whence))
{
*offset = o;
return 0;
}
return -1;
}
#endif // _DOS
|
the_stack_data/922436.c
|
/*******************************************************************************
* Copyright (c) 2015, http://www.jbox.dk/
* All rights reserved. Released under the BSD license.
* httpsrv.c 1.0 01/01/2016 (Simple Http Server)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <sys/socket.h>
#define PORT 80
#define SERVER "httpsrv/1.0"
#define PROTOCOL "HTTP/1.0"
#define RFC1123FMT "%a, %d %b %Y %H:%M:%S GMT"
char *get_mime_type(char *name) {
char *ext = strrchr(name, '.');
if (!ext) return NULL;
if (strcmp(ext, ".html") == 0) return "text/html";
if (strcmp(ext, ".htm") == 0) return "text/html";
if (strcmp(ext, ".txt") == 0) return "text/html";
if (strcmp(ext, ".jpg") == 0) return "image/jpeg";
if (strcmp(ext, ".jpeg") == 0) return "image/jpeg";
if (strcmp(ext, ".gif") == 0) return "image/gif";
if (strcmp(ext, ".png") == 0) return "image/png";
if (strcmp(ext, ".css") == 0) return "text/css";
if (strcmp(ext, ".au") == 0) return "audio/basic";
if (strcmp(ext, ".wav") == 0) return "audio/wav";
if (strcmp(ext, ".avi") == 0) return "video/x-msvideo";
if (strcmp(ext, ".mpeg") == 0) return "video/mpeg";
if (strcmp(ext, ".mpg") == 0) return "video/mpeg";
if (strcmp(ext, ".mp3") == 0) return "audio/mpeg";
if (strcmp(ext, ".svg") == 0) return "image/svg+xml";
if (strcmp(ext, ".pdf") == 0) return "application/pdf";
return NULL;
}
void send_headers(FILE *f, int status, char *title, char *extra, char *mime, int length, time_t date) {
time_t now;
char timebuf[128];
fprintf(f, "%s %d %s\r\n", PROTOCOL, status, title);
fprintf(f, "Server: %s\r\n", SERVER);
now = time(NULL);
strftime(timebuf, sizeof (timebuf), RFC1123FMT, gmtime(&now));
fprintf(f, "Date: %s\r\n", timebuf);
if (extra) fprintf(f, "%s\r\n", extra);
if (mime) fprintf(f, "Content-Type: %s\r\n", mime);
if (length >= 0) fprintf(f, "Content-Length: %d\r\n", length);
if (date != -1) {
strftime(timebuf, sizeof (timebuf), RFC1123FMT, gmtime(&date));
fprintf(f, "Last-Modified: %s\r\n", timebuf);
}
fprintf(f, "Connection: close\r\n");
fprintf(f, "\r\n");
}
void send_error(FILE *f, int status, char *title, char *extra, char *text) {
send_headers(f, status, title, extra, "text/html", -1, -1);
fprintf(f, "<HTML><HEAD><TITLE>%d %s</TITLE></HEAD>\r\n", status, title);
fprintf(f, "<BODY><H4>%d %s</H4>\r\n", status, title);
fprintf(f, "%s\r\n", text);
fprintf(f, "</BODY></HTML>\r\n");
}
void send_file(FILE *f, char *path, struct stat *statbuf) {
int n;
char data[4096];
FILE *file = fopen(path, "r");
if (!file) {
send_error(f, 403, "Forbidden", NULL, "Access denied.");
} else {
int length = S_ISREG(statbuf->st_mode) ? statbuf->st_size : -1;
send_headers(f, 200, "OK", NULL, get_mime_type(path), length, statbuf->st_mtime);
while ((n = fread(data, 1, sizeof (data), file)) > 0) fwrite(data, 1, n, f);
fclose(file);
}
}
int process(FILE *f) {
char buf[4096];
char *method;
char *path;
char *protocol;
struct stat statbuf;
char pathbuf[4096];
int len;
if (!fgets(buf, sizeof (buf), f)) return -1;
printf("URL: %s", buf);
method = strtok(buf, " ");
path = strtok(NULL, " ");
protocol = strtok(NULL, "\r");
if (!method || !path || !protocol) return -1;
fseek(f, 0, SEEK_CUR); // Force change of stream direction
if (strcasecmp(method, "GET") != 0) {
send_error(f, 501, "Not supported", NULL, "Method is not supported.");
} else if (stat(path, &statbuf) < 0) {
send_error(f, 404, "Not Found", NULL, "File not found.");
} else if (S_ISDIR(statbuf.st_mode)) {
len = strlen(path);
if (len == 0 || path[len - 1] != '/') {
snprintf(pathbuf, sizeof (pathbuf), "Location: %s/", path);
send_error(f, 302, "Found", pathbuf, "Directories must end with a slash.");
} else {
snprintf(pathbuf, sizeof (pathbuf), "%sindex.html", path);
if (stat(pathbuf, &statbuf) >= 0) {
send_file(f, pathbuf, &statbuf);
} else {
DIR *dir;
struct dirent *de;
send_headers(f, 200, "OK", NULL, "text/html", -1, statbuf.st_mtime);
fprintf(f, "<HTML><HEAD><TITLE>Index of %s</TITLE></HEAD>\r\n<BODY>", path);
fprintf(f, "<H4>Index of %s</H4>\r\n<PRE>\n", path);
fprintf(f, "Name Last Modified Size\r\n");
fprintf(f, "<HR>\r\n");
if (len > 1) fprintf(f, "<A HREF=\"..\">..</A>\r\n");
dir = opendir(path);
while ((de = readdir(dir)) != NULL) {
char timebuf[32];
struct tm *tm;
strcpy(pathbuf, path);
strcat(pathbuf, de->d_name);
stat(pathbuf, &statbuf);
tm = gmtime(&statbuf.st_mtime);
strftime(timebuf, sizeof (timebuf), "%d-%b-%Y %H:%M:%S", tm);
fprintf(f, "<A HREF=\"%s%s\">", de->d_name, S_ISDIR(statbuf.st_mode) ? "/" : "");
fprintf(f, "%s%s", de->d_name, S_ISDIR(statbuf.st_mode) ? "/</A>" : "</A> ");
if (strlen(de->d_name) < 32) fprintf(f, "%*s", 32 - strlen(de->d_name), "");
if (S_ISDIR(statbuf.st_mode)) {
fprintf(f, "%s\r\n", timebuf);
} else {
fprintf(f, "%s %10d\r\n", timebuf, statbuf.st_size);
}
}
closedir(dir);
fprintf(f, "</PRE>\r\n<HR>\r\n<ADDRESS>%s</ADDRESS>\r\n</BODY></HTML>\r\n", SERVER);
}
}
} else {
send_file(f, path, &statbuf);
}
return 0;
}
int main(int argc, char *argv[]) {
int sock;
struct sockaddr_in sin;
sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(PORT);
bind(sock, (struct sockaddr *) &sin, sizeof (sin));
listen(sock, 5);
printf("HTTP server listening on port %d\n", PORT);
while (1) {
int s;
FILE *f;
s = accept(sock, NULL, NULL);
if (s < 0) break;
f = fdopen(s, "a+");
process(f);
fclose(f);
}
close(sock);
return 0;
}
|
the_stack_data/905370.c
|
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#define LOGFILE "/tmp/logfile"
#define FIFOFILE "/tmp/fifo"
void daemonize(void) {
pid_t pid;
pid = fork();
if (pid < 0) {
printf("Cannot create child,%s\n",strerror(errno));
exit(1);
}
if (pid > 0) {
printf("Success in creating child. Exiting\n");
exit(0);
}
if (setsid() < 0) {
printf("Cannot create a new session. %s",strerror(errno));
exit(1);
}
if(chdir("/") < 0) {
printf("Cannot change working directory. %s",strerror(errno));
exit(1);
}
umask(0);
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
}
int main(int argc,char **argv) {
int fifofd,n;
int logfile;
char buffer[255];
daemonize();
logfile = open(LOGFILE,O_WRONLY|O_APPEND|O_CREAT,0777);
n = mkfifo(FIFOFILE, 0777);
while(1) {
fifofd=open(FIFOFILE,O_RDONLY);
do {
memset(buffer,0,255);
n = read(fifofd,buffer,255);
if (n>0) {
write(logfile,buffer,strlen(buffer));
}
} while(n > 0);
close(fifofd);
}
return 0;
}
|
the_stack_data/11668.c
|
/*
Área Superior
https://www.urionlinejudge.com.br/judge/pt/problems/view/1187
*/
#include <stdio.h>
#define LINHAS 12
#define COLUNAS 12
void preencherMatriz(double matriz[][COLUNAS]);
double computarOperacao(char operacao, double matriz[][COLUNAS]);
int main (void) {
char operacao;
double matriz[LINHAS][COLUNAS];
scanf("%c", &operacao);
preencherMatriz(matriz);
printf("%.1f\n", computarOperacao(operacao, matriz));
return 0;
}
void preencherMatriz(double matriz[][COLUNAS]) {
size_t i,
j;
for (i = 0; i < LINHAS; i++) {
for (j = 0; j < COLUNAS; j++) {
scanf("%lf", &matriz[i][j]);
}
}
}
double computarOperacao(char operacao, double matriz[][COLUNAS]) {
double soma = 0;
size_t i,
j,
posicoesSomadas = 0;
for (i = 0; i < LINHAS / 2; i++) {
for (j = i + 1; j < COLUNAS - 1 - i; j++) {
// printf("[%d, %d] ", i, j);
soma += matriz[i][j];
posicoesSomadas++;
}
// printf("\n");
}
if (operacao == 'S') {
return soma;
}
else {
return soma / posicoesSomadas;
}
}
|
the_stack_data/97013263.c
|
/* This testcase is part of GDB, the GNU debugger.
Copyright 2017-2019 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <pthread.h>
#include <unistd.h>
#define NTHREADS 3
static void *
test (void *arg)
{
/* Let's hope this is long enough for GDB to enable tracing and check that
everything is working as expected. */
sleep (10);
return arg;
}
int
main (void)
{
pthread_t th[NTHREADS];
int i;
for (i = 0; i < NTHREADS; ++i)
pthread_create (&th[i], NULL, test, NULL);
test (NULL); /* bp.1 */
for (i = 0; i < NTHREADS; ++i)
pthread_join (th[i], NULL);
return 0;
}
|
the_stack_data/1209569.c
|
/*
* POK header
*
* The following file is a part of the POK project. Any modification should
* be made according to the POK licence. You CANNOT use this file or a part
* of a file for your own project.
*
* For more information on the POK licence, please see our LICENCE FILE
*
* Please follow the coding guidelines described in doc/CODING_GUIDELINES
*
* Copyright (c) 2007-2020 POK team
*/
/* e_scalbf.c -- float version of e_scalb.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected].
*/
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#ifdef POK_NEEDS_LIBMATH
#include "math_private.h"
#include <libm.h>
#ifdef _SCALB_INT
float __ieee754_scalbf(float x, int fn)
#else
float __ieee754_scalbf(float x, float fn)
#endif
{
#ifdef _SCALB_INT
return scalbnf(x, fn);
#else
if (isnanf(x) || isnanf(fn))
return x * fn;
if (!finitef(fn)) {
if (fn > (float)0.0)
return x * fn;
else
return x / (-fn);
}
if (rintf(fn) != fn)
return (fn - fn) / (fn - fn);
if (fn > (float)65000.0)
return scalbnf(x, 65000);
if (-fn > (float)65000.0)
return scalbnf(x, -65000);
return scalbnf(x, (int)fn);
#endif
}
#endif
|
the_stack_data/118051.c
|
/**
* Description : House Robber
* You are a professional robber to rob houses along a street.
* Each house has a certain amount of money stashed, the only
* constraint stopping you from robbing each of them is that
* adjacent houses have security system connected and it will
* automatically contact the police if two adjacent houses were
* broken into on the same night. Given a list of non-negative
* integers representing the amount of money of each house, deter-
* mine the maximum amount of money you can rob tonight without
* alerting the police.
* Author : Evan Lau
* Date : 2016/04/12
*/
#include <stdio.h>
int rob(int* nums, int numsSize)
{
if (numsSize == 0)
{
return 0;
}
if (numsSize == 1)
{
return nums[0];
}
int arr[numsSize];
int i;
for (int i = 0; i < numsSize; i++)
{
arr[i] = 0;
}
for (i = 0; i < numsSize; i++)
{
if (i - 2 < 0 && i - 3 < 0)
{
arr[i] = nums[i];
}
else
{
if (i - 3 < 0)
{
arr[i] = arr[i - 2] + nums[i];
}
else
{
if (arr[i - 2] > arr[i - 3])
{
arr[i] = arr[i - 2] + nums[i];
}
else
{
arr[i] = arr[i - 3] + nums[i];
}
}
}
}
if (arr[i - 1] > arr[i - 2])
{
return arr[i - 1];
}
else
{
return arr[i - 2];
}
}
int main(void)
{
int arr1[] = {1, 3, 2, 4, 5, 8, 7};
int arr2[] = {1, 1, 1};
int arr3[] = {0};
printf("%d\n", rob(arr1, 7));
printf("%d\n", rob(arr2, 3));
printf("%d\n", rob(arr3, 1));
return 0;
}
|
the_stack_data/242330687.c
|
#include<stdio.h>
#include<math.h>
int main (){
float a,b,c,media;
printf("Digite tres numeros cualesquiera: ");
scanf("%f %f %f",&a,&b,&c);
media = cbrt(a*b*c);
printf("La media geometrica es: %f",media);
return 0;
}
|
the_stack_data/155006.c
|
#include <stdio.h>
int main()
{
int tamanho, menor, posi;
scanf("%i", &tamanho);
int num[tamanho], repeat;
for (repeat = 0; repeat < tamanho; repeat ++)
{
scanf("%i", &num[repeat]);
if (repeat == 0 || num[repeat] < menor)
{
menor = num[repeat];
posi = repeat;
}
}
printf("Menor valor: %i\nPosicao: %i\n", menor, posi);
return(0);
}
|
the_stack_data/193894033.c
|
#ifdef SUPPORT_SNAT
/*
* Distributed under the terms of the GNU GPL version 2.
* Copyright (c) 2008 Nicira Networks
*/
#include <linux/netdevice.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/in.h>
#include <net/ip.h>
#include <linux/icmp.h>
#include <linux/if_ether.h>
#include <net/arp.h>
#include <net/route.h>
#include "forward.h"
#include "dp_act.h"
#include "nx_act_snat.h"
/* We need these fake structures to make netfilter happy --
* lots of places assume that skb->dst != NULL, which isn't
* all that unreasonable.
*
* Currently, we fill in the PMTU entry because netfilter
* refragmentation needs it, and the rt_flags entry because
* ipt_REJECT needs it. Future netfilter modules might
* require us to fill additional fields. */
static struct net_device __fake_net_device = {
.hard_header_len = ETH_HLEN
};
static struct rtable __fake_rtable = {
.u = {
.dst = {
.__refcnt = ATOMIC_INIT(1),
.dev = &__fake_net_device,
.path = &__fake_rtable.u.dst,
.metrics = {[RTAX_MTU - 1] = 1500},
.flags = DST_NOXFRM,
}
},
.rt_flags = 0,
};
/* Define ARP for IP since the Linux headers don't do it cleanly. */
struct ip_arphdr {
uint16_t ar_hrd;
uint16_t ar_pro;
uint8_t ar_hln;
uint8_t ar_pln;
uint16_t ar_op;
uint8_t ar_sha[ETH_ALEN];
uint32_t ar_sip;
uint8_t ar_tha[ETH_ALEN];
uint32_t ar_tip;
} __attribute__((packed));
OFP_ASSERT(sizeof(struct ip_arphdr) == 28);
/* Push the Ethernet header back on and tranmit the packet. */
static int
dp_xmit_skb_push(struct sk_buff *skb)
{
skb_push(skb, ETH_HLEN);
return dp_xmit_skb(skb);
}
/* Perform maintainence related to a SNAT'd interface. Currently, this only
* checks whether MAC->IP bindings have expired.
*
* Called with the RCU read lock */
void
snat_maint(struct net_bridge_port *p)
{
struct snat_conf *sc;
struct snat_mapping *m, *n;
unsigned long flags;
unsigned long timeout;
spin_lock_irqsave(&p->lock, flags);
sc = p->snat;
if (!sc)
goto done;
timeout = sc->mac_timeout * HZ;
list_for_each_entry_safe (m, n, &sc->mappings, node) {
if (time_after(jiffies, m->used + timeout)) {
list_del(&m->node);
kfree(m);
}
}
done:
spin_unlock_irqrestore(&p->lock, flags);
}
/* When the packet is bound for a local interface, strip off the fake
* routing table.
*/
void snat_local_in(struct sk_buff *skb)
{
if (skb->dst == (struct dst_entry *)&__fake_rtable) {
dst_release(skb->dst);
skb->dst = NULL;
}
}
/* Check whether destination IP's address is in the IP->MAC mappings.
* If it is, then overwrite the destination MAC with the value from the
* cache.
*
* Returns -1 if there is a problem, otherwise 0. */
static int
dnat_mac(struct net_bridge_port *p, struct sk_buff *skb)
{
struct snat_conf *sc = p->snat;
struct iphdr *iph = ip_hdr(skb);
struct ethhdr *eh = eth_hdr(skb);
struct snat_mapping *m;
if (skb->protocol != htons(ETH_P_IP))
return 0;
list_for_each_entry (m, &sc->mappings, node) {
if (m->ip_addr == iph->daddr){
/* Found it! */
if (!make_writable(&skb)) {
if (net_ratelimit())
printk("make_writable failed\n");
return -EINVAL;
}
m->used = jiffies;
memcpy(eh->h_dest, m->hw_addr, ETH_ALEN);
break;
}
}
return 0;
}
static int
__snat_this_address(struct snat_conf *sc, u32 ip_addr)
{
if (sc) {
u32 h_ip_addr = ntohl(ip_addr);
return (h_ip_addr >= sc->ip_addr_start &&
h_ip_addr <= sc->ip_addr_end);
}
return 0;
}
static int
snat_this_address(struct net_bridge_port *p, u32 ip_addr)
{
unsigned long int flags;
int retval;
spin_lock_irqsave(&p->lock, flags);
retval = __snat_this_address(p->snat, ip_addr);
spin_unlock_irqrestore(&p->lock, flags);
return retval;
}
static int
snat_pre_route_finish(struct sk_buff *skb)
{
struct net_bridge_port *p = skb->dev->br_port;
struct snat_conf *sc;
struct iphdr *iph = ip_hdr(skb);
unsigned long flags;
skb->dst = (struct dst_entry *)&__fake_rtable;
dst_hold(skb->dst);
/* Don't process packets that were not translated due to NAT */
spin_lock_irqsave(&p->lock, flags);
sc = p->snat;
if (!__snat_this_address(sc, iph->daddr)) {
/* If SNAT is configured for this input device, check the
* IP->MAC mappings to see if we should update the destination
* MAC. */
if (sc)
dnat_mac(skb->dev->br_port, skb);
}
spin_unlock_irqrestore(&p->lock, flags);
/* Pass the translated packet as input to the OpenFlow stack, which
* consumes it. */
skb_push(skb, ETH_HLEN);
skb_reset_mac_header(skb);
fwd_port_input(p->dp->chain, skb, p);
return 0;
}
/* Checks whether 'skb' is an ARP request for an SNAT'd interface. If
* so, it will generate a response.
*
* Returns 0 if the packet was not handled. Otherwise, -1 is returned
* and the caller is responsible for freeing 'skb'. */
static int
handle_arp_snat(struct sk_buff *skb)
{
struct net_bridge_port *p = skb->dev->br_port;
struct ip_arphdr *ah;
if (!pskb_may_pull(skb, sizeof *ah))
return 0;
ah = (struct ip_arphdr *)arp_hdr(skb);
if ((ah->ar_op != htons(ARPOP_REQUEST))
|| ah->ar_hln != ETH_ALEN
|| ah->ar_pro != htons(ETH_P_IP)
|| ah->ar_pln != 4)
return 0;
/* We're only interested in addresses we rewrite. */
if (!snat_this_address(p, ah->ar_tip)) {
return 0;
}
arp_send(ARPOP_REPLY, ETH_P_ARP, ah->ar_sip, skb->dev, ah->ar_tip,
ah->ar_sha, p->dp->netdev->dev_addr, ah->ar_sha);
return -1;
}
/* Checks whether 'skb' is a ping request for an SNAT'd interface. If
* so, it will generate a response.
*
* Returns 0 if the packet was not handled. Otherwise, -1 is returned
* and the caller is responsible for freeing 'skb'. */
static int
handle_icmp_snat(struct sk_buff *skb)
{
struct net_bridge_port *p = skb->dev->br_port;
struct ethhdr *eh;
struct iphdr *iph;
struct icmphdr *icmph;
uint8_t tmp_eth[ETH_ALEN];
uint32_t tmp_ip;
struct sk_buff *nskb;
/* We're only interested in addresses we rewrite. */
iph = ip_hdr(skb);
if (!snat_this_address(p, iph->daddr)) {
return 0;
}
/* Drop fragments and packets not long enough to hold the ICMP
* header. */
if ((ntohs(iph->frag_off) & IP_OFFSET) != 0 ||
!pskb_may_pull(skb, skb_transport_offset(skb) + 4))
return 0;
/* We only respond to echo requests to our address. Continue
* processing replies and other ICMP messages since they may be
* intended for NAT'd hosts. */
icmph = icmp_hdr(skb);
if (icmph->type != ICMP_ECHO)
return 0;
/* Send an echo reply in response */
nskb = skb_copy(skb, GFP_ATOMIC);
if (!nskb) {
if (net_ratelimit())
printk("skb copy failed for icmp reply\n");
return -1;
}
/* Update Ethernet header. */
eh = eth_hdr(nskb);
memcpy(tmp_eth, eh->h_dest, ETH_ALEN);
memcpy(eh->h_dest, eh->h_source, ETH_ALEN);
memcpy(eh->h_source, tmp_eth, ETH_ALEN);
/* Update IP header.
* This is kind of busted, at least in that it doesn't check that the
* echoed IP options make sense. */
iph = ip_hdr(nskb);
iph->id = 0;
iph->frag_off = 0;
iph->ttl = IPDEFTTL;
iph->check = 0;
tmp_ip = iph->daddr;
iph->daddr = iph->saddr;
iph->saddr = tmp_ip;
iph->check = ip_fast_csum(iph, iph->ihl);
/* Update ICMP header. */
icmph = icmp_hdr(nskb);
icmph->type = ICMP_ECHOREPLY;
icmph->checksum = 0;
icmph->checksum = ip_compute_csum(icmph,
nskb->tail - nskb->transport_header);
dp_xmit_skb_push(nskb);
return -1;
}
/* Check if any SNAT maintenance needs to be done on 'skb' before it's
* checked against the datapath's tables. This includes DNAT
* modification based on prior SNAT action and responding to ARP and
* echo requests for the SNAT interface.
*
* Returns -1 if the packet was handled and consumed, 0 if the caller
* should continue to process 'skb'.
*/
int
snat_pre_route(struct sk_buff *skb)
{
struct iphdr *iph;
int len;
WARN_ON_ONCE(skb_network_offset(skb));
if (skb->protocol == htons(ETH_P_ARP)) {
if (handle_arp_snat(skb))
goto consume;
return 0;
}
else if (skb->protocol != htons(ETH_P_IP))
return 0;
if (!pskb_may_pull(skb, sizeof *iph))
goto consume;
iph = ip_hdr(skb);
if (iph->ihl < 5 || iph->version != 4)
goto consume;
if (!pskb_may_pull(skb, ip_hdrlen(skb)))
goto consume;
skb_set_transport_header(skb, ip_hdrlen(skb));
/* Check if we need to echo reply for this address */
iph = ip_hdr(skb);
if ((iph->protocol == IPPROTO_ICMP) && (handle_icmp_snat(skb)))
goto consume;
iph = ip_hdr(skb);
if (unlikely(ip_fast_csum(iph, iph->ihl)))
goto consume;
len = ntohs(iph->tot_len);
if ((skb->len < len) || len < (iph->ihl*4))
goto consume;
if (pskb_trim_rcsum(skb, len))
goto consume;
NF_HOOK(PF_INET, NF_INET_PRE_ROUTING, skb, skb->dev, NULL,
snat_pre_route_finish);
return -1;
consume:
kfree_skb(skb);
return -1;
}
static int
snat_skb_finish(struct sk_buff *skb)
{
NF_HOOK(PF_INET, NF_INET_POST_ROUTING, skb, NULL, skb->dev,
dp_xmit_skb_push);
return 0;
}
/* Update the MAC->IP mappings for the private side of the SNAT'd
* interface. */
static void
update_mapping(struct net_bridge_port *p, const struct sk_buff *skb)
{
unsigned long flags;
struct snat_conf *sc;
const struct iphdr *iph = ip_hdr(skb);
const struct ethhdr *eh = eth_hdr(skb);
struct snat_mapping *m;
spin_lock_irqsave(&p->lock, flags);
sc = p->snat;
if (!sc)
goto done;
list_for_each_entry (m, &sc->mappings, node) {
if (m->ip_addr == iph->saddr){
memcpy(m->hw_addr, eh->h_source, ETH_ALEN);
m->used = jiffies;
goto done;
}
}
m = kmalloc(sizeof *m, GFP_ATOMIC);
if (!m)
goto done;
m->ip_addr = iph->saddr;
memcpy(m->hw_addr, eh->h_source, ETH_ALEN);
m->used = jiffies;
list_add(&m->node, &sc->mappings);
done:
spin_unlock_irqrestore(&p->lock, flags);
}
/* Perform SNAT modification on 'skb' and send out 'out_port'. If the
* port was not configured for SNAT, it will be sent through the interface
* unmodified. 'skb' is not consumed, so caller will need to free it.
*/
void
snat_skb(struct datapath *dp, const struct sk_buff *skb, int out_port)
{
struct net_bridge_port *p = dp->ports[out_port];
struct sk_buff *nskb;
if (!p)
return;
/* FIXME: Expensive. Just need to skb_clone() here?
* (However, the skb_copy() does linearize and ensure that the headers
* are accessible.) */
nskb = skb_copy(skb, GFP_ATOMIC);
if (!nskb)
return;
nskb->dev = p->dev;
/* We only SNAT IP, so just send it on its way if not */
if (skb->protocol != htons(ETH_P_IP)) {
dp_xmit_skb(nskb);
return;
}
/* Set the source MAC to the OF interface */
memcpy(eth_hdr(nskb)->h_source, dp->netdev->dev_addr, ETH_ALEN);
update_mapping(p, skb);
/* Take the Ethernet header back off for netfilter hooks. */
skb_pull(nskb, ETH_HLEN);
NF_HOOK(PF_INET, NF_INET_FORWARD, nskb, skb->dev, nskb->dev,
snat_skb_finish);
}
/* Remove SNAT configuration on port 'p'.
*
* NB: The caller must hold the port's spinlock. */
int
snat_free_conf(struct net_bridge_port *p)
{
struct snat_conf *sc = p->snat;
if (!sc)
return -EINVAL;
/* Free existing mapping entries */
while (!list_empty(&sc->mappings)) {
struct snat_mapping *m = list_entry(sc->mappings.next,
struct snat_mapping, node);
list_del(&m->node);
kfree(m);
}
kfree(p->snat);
p->snat = NULL;
return 0;
}
/* Remove SNAT configuration from an interface. */
static int
snat_del_port(struct datapath *dp, uint16_t port)
{
unsigned long flags;
struct net_bridge_port *p = dp->ports[port];
if (!p) {
if (net_ratelimit())
printk("Attempt to remove snat on non-existent port: %d\n", port);
return -EINVAL;
}
spin_lock_irqsave(&p->lock, flags);
if (snat_free_conf(p)) {
/* SNAT not configured on this port */
spin_unlock_irqrestore(&p->lock, flags);
if (net_ratelimit())
printk("Attempt to remove snat on non-snat port: %d\n", port);
return -EINVAL;
}
spin_unlock_irqrestore(&p->lock, flags);
return 0;
}
/* Add SNAT configuration to an interface. */
static int
snat_add_port(struct datapath *dp, uint16_t port,
uint32_t ip_addr_start, uint32_t ip_addr_end,
uint16_t mac_timeout)
{
unsigned long flags;
struct net_bridge_port *p = dp->ports[port];
struct snat_conf *sc;
if (mac_timeout == 0)
mac_timeout = MAC_TIMEOUT_DEFAULT;
if (!p) {
if (net_ratelimit())
printk("Attempt to add snat on non-existent port: %d\n", port);
return -EINVAL;
}
/* If SNAT is already configured on the port, check whether the same
* IP addresses are used. If so, just update the mac timeout
* configuration. Otherwise, drop all SNAT configuration and
* reconfigure it. */
spin_lock_irqsave(&p->lock, flags);
if (p->snat) {
if ((p->snat->ip_addr_start == ip_addr_start)
&& (p->snat->ip_addr_end == ip_addr_end)) {
p->snat->mac_timeout = mac_timeout;
spin_unlock_irqrestore(&p->lock, flags);
return 0;
}
/* Free the existing configuration and mappings. */
snat_free_conf(p);
}
sc = kzalloc(sizeof *sc, GFP_ATOMIC);
if (!sc) {
spin_unlock_irqrestore(&p->lock, flags);
return -ENOMEM;
}
sc->ip_addr_start = ip_addr_start;
sc->ip_addr_end = ip_addr_end;
sc->mac_timeout = mac_timeout;
INIT_LIST_HEAD(&sc->mappings);
p->snat = sc;
spin_unlock_irqrestore(&p->lock, flags);
return 0;
}
/* Handle a SNAT configuration message.
*
* Returns 0 if no problems are found. Otherwise, a negative errno. */
int
snat_mod_config(struct datapath *dp, const struct nx_act_config *nac)
{
int n_entries = (ntohs(nac->header.header.length) - sizeof *nac)
/ sizeof (struct nx_snat_config);
int ret = 0;
int i;
for (i=0; i<n_entries; i++) {
const struct nx_snat_config *sc = &nac->snat[i];
uint16_t port = ntohs(sc->port);
int r = 0;
if (sc->command == NXSC_ADD)
r = snat_add_port(dp, port,
ntohl(sc->ip_addr_start), ntohl(sc->ip_addr_end),
ntohs(sc->mac_timeout));
else
r = snat_del_port(dp, port);
if (r)
ret = r;
}
return ret;
}
#endif
|
the_stack_data/43889116.c
|
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
// #define TRACE
typedef int32_t subleq_word;
typedef struct {
char* type;
char* value;
} MagicComment;
int run_subleq_bytes(subleq_word *code, subleq_word length){
subleq_word pc = 0;
while (pc < length - 2){
subleq_word a = code[pc];
subleq_word b = code[pc + 1];
subleq_word c = code[pc + 2];
if (a < -1 || a >= length){
printf("%d %d %d\n", a, b, c);
fprintf(stderr, "Value of a = %d is outside of range %d (at loc %d)\n", a, length, pc);
return 1;
} else if (b < -1 || b >= length){
printf("%d %d %d\n", a, b, c);
fprintf(stderr, "Value of b = %d is outside of range %d (at loc %d)\n", b, length, pc);
return 1;
} else if (c >= length - 2){
printf("%d %d %d\n", a, b, c);
fprintf(stderr, "Value of c = %d is outside of range %d (at loc %d)\n", c, length, pc);
return 1;
}
#ifdef TRACE
if (pc > 17994564 - 100 && pc < 17994564){
printf("loc: %d (%d), [%d] = %d, [%d] = %d, goto %d\n", pc, code[pc + 3], a, code[a], b, code[b], c);
printf("A: %d B: %d C:%d D:%d SP:%d BP:%d PC:%d\n",
code[3], code[4], code[5], code[6], code[7], code[8], code[9]);
}
#endif
if (a == -1){
code[b] = getchar();
} else if (b == -1){
putchar((char)(code[a] & 255));
} else if (c <= -1 && code[b] - code[a] <= 0){
return 0;
} else {
code[b] -= code[a];
if (code[b] <= 0){
pc = c - 3;
}
}
pc += 3;
}
return 0;
}
void skip_whitespace(FILE* fp){
char c = getc(fp);
while (c == ' ' || c == '\n' || c == '\r' || c == '\t'){
c = getc(fp);
}
ungetc(c, fp);
}
void skip_to_newline(FILE* fp){
while (getc(fp) != '\n' && !feof(fp)) continue;
}
MagicComment* parse_magic_comment(FILE* fp){
getc(fp); // Discard first '{'
MagicComment* mc = (MagicComment*)malloc(sizeof(MagicComment));
char* buf = (char*)calloc(43, sizeof(char));
if (!fgets(buf, 42, fp)) return 0;
buf[strcspn(buf, "\n")] = 0;
buf[strcspn(buf, "}")] = 0;
mc->type = strtok(buf, ":");
mc->value = strtok(NULL, ":");
return mc;
}
int assemble_run_subleq(FILE* fp){
#ifdef TRACE
printf("Converting to int32[]...\n");
#endif
subleq_word *code = (subleq_word*)calloc(30, sizeof(subleq_word));
subleq_word current_size = 30;
subleq_word loc = 0;
char c = ' ';
while (c != EOF){
skip_whitespace(fp);
c = getc(fp);
if (c == EOF){
break;
}
switch (c){
case '#':
c = getc(fp);
ungetc(c, fp);
if (c == '{'){
MagicComment* mc = parse_magic_comment(fp);
if (!mc || strcmp("loc_skip", mc->type) == 0) {
int amnt = atoi(mc->value);
loc += amnt - 1;
fseek(fp, amnt * 2 - 1, SEEK_CUR);
} else {
fprintf(stderr, "Invalid magic comment {%s:%s}\n", mc->type, mc->value);
return 1;
}
} else {
skip_to_newline(fp);
}
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
ungetc(c, fp);
if (fscanf(fp, "%d", &code[loc++]) != 1) goto err;
break;
default:
err:
fprintf(stderr, "Invalid character %c (char code %d) at pos %ld", c, c, ftell(fp));
return 1;
}
while (loc >= current_size){
code = (subleq_word*)realloc(code, (current_size * 2) * sizeof(subleq_word));
current_size *= 2;
if (code == NULL){
fprintf(stderr, "Couldn't allocate enough memory");
return 1;
}
}
}
code = (subleq_word*)realloc(code, loc * sizeof(subleq_word));
#ifdef TRACE
printf("Done.\n");
#endif
return run_subleq_bytes(code, loc);
}
int main(int argc, char* argv[]){
FILE* fp;
if (argc == 2){
fp = fopen(argv[1], "r");
} else {
fprintf(stderr, "Too many arguments");
return 1;
}
if (fp == NULL){
fprintf(stderr, "Failed to load subleq file");
return 1;
}
int error_code = assemble_run_subleq(fp);
fclose(fp);
return error_code;
}
|
the_stack_data/4738.c
|
// Test recovery mode.
//
// RUN: %clang_asan -fsanitize-recover=address %s -o %t
//
// RUN: env not %run %t 2>&1 | FileCheck %s
// RUN: %env_asan_opts=halt_on_error=true not %run %t 2>&1 | FileCheck %s
// RUN: %env_asan_opts=halt_on_error=false %run %t 2>&1 | FileCheck %s --check-prefix CHECK-RECOVER
#include <string.h>
volatile int ten = 10;
int main() {
char x[10];
// CHECK: WRITE of size 11
// CHECK-RECOVER: WRITE of size 11
memset(x, 0, 11);
// CHECK-NOT: READ of size 1
// CHECK-RECOVER: READ of size 1
volatile int res = x[ten];
// CHECK-NOT: WRITE of size 1
// CHECK-RECOVER: WRITE of size 1
x[ten] = res + 3;
// CHECK-NOT: READ of size 1
// CHECK-RECOVER: READ of size 1
res = x[ten];
return 0;
}
|
the_stack_data/51699181.c
|
/* Generated by CIL v. 1.7.0 */
/* print_CIL_Input is false */
struct _IO_FILE;
struct timeval;
extern void signal(int sig , void *func ) ;
extern float strtof(char const *str , char const *endptr ) ;
typedef struct _IO_FILE FILE;
extern int atoi(char const *s ) ;
extern double strtod(char const *str , char const *endptr ) ;
extern int fclose(void *stream ) ;
extern void *fopen(char const *filename , char const *mode ) ;
extern void abort() ;
extern void exit(int status ) ;
extern int raise(int sig ) ;
extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ;
extern int strcmp(char const *a , char const *b ) ;
extern int rand() ;
extern unsigned long strtoul(char const *str , char const *endptr , int base ) ;
void RandomFunc(unsigned short input[1] , unsigned short output[1] ) ;
extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ;
extern int gettimeofday(struct timeval *tv , void *tz , ...) ;
extern int printf(char const *format , ...) ;
int main(int argc , char *argv[] ) ;
void megaInit(void) ;
extern unsigned long strlen(char const *s ) ;
extern long strtol(char const *str , char const *endptr , int base ) ;
extern unsigned long strnlen(char const *s , unsigned long maxlen ) ;
extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ;
struct timeval {
long tv_sec ;
long tv_usec ;
};
extern void *malloc(unsigned long size ) ;
extern int scanf(char const *format , ...) ;
void megaInit(void)
{
{
}
}
void RandomFunc(unsigned short input[1] , unsigned short output[1] )
{
unsigned short state[1] ;
unsigned short local1 ;
char copy11 ;
char copy12 ;
char copy14 ;
{
state[0UL] = (input[0UL] + 914778474UL) * (unsigned short)64278;
local1 = 0UL;
while (local1 < (unsigned short)0) {
if (state[0UL] < local1) {
if (state[0UL] != local1) {
copy11 = *((char *)(& state[local1]) + 0);
*((char *)(& state[local1]) + 0) = *((char *)(& state[local1]) + 1);
*((char *)(& state[local1]) + 1) = copy11;
copy11 = *((char *)(& state[local1]) + 1);
*((char *)(& state[local1]) + 1) = *((char *)(& state[local1]) + 0);
*((char *)(& state[local1]) + 0) = copy11;
copy12 = *((char *)(& state[0UL]) + 0);
*((char *)(& state[0UL]) + 0) = *((char *)(& state[0UL]) + 1);
*((char *)(& state[0UL]) + 1) = copy12;
copy12 = *((char *)(& state[0UL]) + 1);
*((char *)(& state[0UL]) + 1) = *((char *)(& state[0UL]) + 0);
*((char *)(& state[0UL]) + 0) = copy12;
} else {
state[local1] = state[0UL] - state[local1];
}
} else {
copy14 = *((char *)(& state[0UL]) + 0);
*((char *)(& state[0UL]) + 0) = *((char *)(& state[0UL]) + 1);
*((char *)(& state[0UL]) + 1) = copy14;
state[local1] += state[local1];
}
local1 ++;
}
output[0UL] = (state[0UL] + 681723154UL) + (unsigned short)54612;
}
}
int main(int argc , char *argv[] )
{
unsigned short input[1] ;
unsigned short output[1] ;
int randomFuns_i5 ;
unsigned short randomFuns_value6 ;
int randomFuns_main_i7 ;
{
megaInit();
if (argc != 2) {
printf("Call this program with %i arguments\n", 1);
exit(-1);
} else {
}
randomFuns_i5 = 0;
while (randomFuns_i5 < 1) {
randomFuns_value6 = (unsigned short )strtoul(argv[randomFuns_i5 + 1], 0, 10);
input[randomFuns_i5] = randomFuns_value6;
randomFuns_i5 ++;
}
RandomFunc(input, output);
if (output[0] == (unsigned short)31026) {
printf("You win!\n");
} else {
}
randomFuns_main_i7 = 0;
while (randomFuns_main_i7 < 1) {
printf("%u\n", output[randomFuns_main_i7]);
randomFuns_main_i7 ++;
}
}
}
|
the_stack_data/405413.c
|
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* based on @(#)enc_des.c 8.1 (Berkeley) 6/4/93 */
#ifdef ENCRYPTION
#include "telnet_arpa.h"
#include <stdio.h>
#include <stdlib.h>
#include "telnet.h"
#include "encrypt.h"
#define CFB 0
#define OFB 1
#define NO_SEND_IV 1
#define NO_RECV_IV 2
#define NO_KEYID 4
#define IN_PROGRESS (NO_SEND_IV|NO_RECV_IV|NO_KEYID)
#define SUCCESS 0
#define xFAILED -1
struct fb {
Block krbdes_key;
Schedule krbdes_sched;
Block temp_feed;
unsigned char fb_feed[64];
int need_start;
int state[2];
int keyid[2];
int once;
struct stinfo {
Block str_output;
Block str_feed;
Block str_iv;
Block str_ikey;
Schedule str_sched;
int str_index;
int str_flagshift;
} streams[2];
};
static struct fb fb[2];
struct keyidlist {
char *keyid;
int keyidlen;
char *key;
int keylen;
int flags;
} keyidlist [] = {
{ "\0", 1, 0, 0, 0 }, /* default key of zero */
{ 0, 0, 0, 0, 0 }
};
#define KEYFLAG_MASK 03
#define KEYFLAG_NOINIT 00
#define KEYFLAG_INIT 01
#define KEYFLAG_OK 02
#define KEYFLAG_BAD 03
#define KEYFLAG_SHIFT 2
#define SHIFT_VAL(a,b) (KEYFLAG_SHIFT*((a)+((b)*2)))
#define FB64_IV 1
#define FB64_IV_OK 2
#define FB64_IV_BAD 3
extern kstream EncryptKSGlobalHack;
void fb64_stream_iv (Block, struct stinfo *);
void fb64_init (struct fb *);
static int fb64_start (struct fb *, int, int);
int fb64_is (unsigned char *, int, struct fb *);
int fb64_reply (unsigned char *, int, struct fb *);
static void fb64_session (Session_Key *, int, struct fb *);
void fb64_stream_key (Block, struct stinfo *);
int fb64_keyid (int, unsigned char *, int *, struct fb *);
void
cfb64_init(server)
int server;
{
fb64_init(&fb[CFB]);
fb[CFB].fb_feed[4] = ENCTYPE_DES_CFB64;
fb[CFB].streams[0].str_flagshift = SHIFT_VAL(0, CFB);
fb[CFB].streams[1].str_flagshift = SHIFT_VAL(1, CFB);
}
void
ofb64_init(server)
int server;
{
fb64_init(&fb[OFB]);
fb[OFB].fb_feed[4] = ENCTYPE_DES_OFB64;
fb[CFB].streams[0].str_flagshift = SHIFT_VAL(0, OFB);
fb[CFB].streams[1].str_flagshift = SHIFT_VAL(1, OFB);
}
void
fb64_init(fbp)
register struct fb *fbp;
{
memset((void *)fbp, 0, sizeof(*fbp));
fbp->state[0] = fbp->state[1] = xFAILED;
fbp->fb_feed[0] = IAC;
fbp->fb_feed[1] = SB;
fbp->fb_feed[2] = TELOPT_ENCRYPT;
fbp->fb_feed[3] = ENCRYPT_IS;
}
/*
* Returns:
* -1: some error. Negotiation is done, encryption not ready.
* 0: Successful, initial negotiation all done.
* 1: successful, negotiation not done yet.
* 2: Not yet. Other things (like getting the key from
* Kerberos) have to happen before we can continue.
*/
int
cfb64_start(dir, server)
int dir;
int server;
{
return(fb64_start(&fb[CFB], dir, server));
}
int
ofb64_start(dir, server)
int dir;
int server;
{
return(fb64_start(&fb[OFB], dir, server));
}
static int
fb64_start(fbp, dir, server)
struct fb *fbp;
int dir;
int server;
{
int x;
unsigned char *p;
register int state;
switch (dir) {
case DIR_DECRYPT:
/*
* This is simply a request to have the other side
* start output (our input). He will negotiate an
* IV so we need not look for it.
*/
state = fbp->state[dir-1];
if (state == xFAILED)
state = IN_PROGRESS;
break;
case DIR_ENCRYPT:
state = fbp->state[dir-1];
if (state == xFAILED)
state = IN_PROGRESS;
else if ((state & NO_SEND_IV) == 0)
break;
if (!VALIDKEY(fbp->krbdes_key)) {
fbp->need_start = 1;
break;
}
state &= ~NO_SEND_IV;
state |= NO_RECV_IV;
/*
* Create a random feed and send it over.
*/
des_new_random_key(fbp->temp_feed);
des_ecb_encrypt(fbp->temp_feed, fbp->temp_feed,
fbp->krbdes_sched, 1);
p = fbp->fb_feed + 3;
*p++ = ENCRYPT_IS;
p++;
*p++ = FB64_IV;
for (x = 0; x < sizeof(Block); ++x) {
if ((*p++ = fbp->temp_feed[x]) == IAC)
*p++ = IAC;
}
*p++ = IAC;
*p++ = SE;
#ifdef DEBUG
printsub('>', &fbp->fb_feed[2], p - &fbp->fb_feed[2]);
#endif
TelnetSend(EncryptKSGlobalHack, fbp->fb_feed, p - fbp->fb_feed, 0);
break;
default:
return(xFAILED);
}
return(fbp->state[dir-1] = state);
}
/*
* Returns:
* -1: some error. Negotiation is done, encryption not ready.
* 0: Successful, initial negotiation all done.
* 1: successful, negotiation not done yet.
*/
int
cfb64_is(data, cnt)
unsigned char *data;
int cnt;
{
return(fb64_is(data, cnt, &fb[CFB]));
}
int
ofb64_is(data, cnt)
unsigned char *data;
int cnt;
{
return(fb64_is(data, cnt, &fb[OFB]));
}
int
fb64_is(data, cnt, fbp)
unsigned char *data;
int cnt;
struct fb *fbp;
{
unsigned char *p;
register int state = fbp->state[DIR_DECRYPT-1];
if (cnt-- < 1)
goto failure;
switch (*data++) {
case FB64_IV:
if (cnt != sizeof(Block)) {
#ifdef DEBUG
if (encrypt_debug_mode)
printf("CFB64: initial vector failed on size\r\n");
#endif
state = xFAILED;
goto failure;
}
#ifdef DEBUG
if (encrypt_debug_mode) {
printf("CFB64: initial vector received\r\n");
printf("Initializing Decrypt stream\r\n");
}
#endif
fb64_stream_iv((void *)data, &fbp->streams[DIR_DECRYPT-1]);
p = fbp->fb_feed + 3;
*p++ = ENCRYPT_REPLY;
p++;
*p++ = FB64_IV_OK;
*p++ = IAC;
*p++ = SE;
#ifdef DEBUG
printsub('>', &fbp->fb_feed[2], p - &fbp->fb_feed[2]);
#endif
TelnetSend(EncryptKSGlobalHack, fbp->fb_feed, p - fbp->fb_feed, 0);
state = fbp->state[DIR_DECRYPT-1] = IN_PROGRESS;
break;
default:
#if 0
if (encrypt_debug_mode) {
printf("Unknown option type: %d\r\n", *(data-1));
printd(data, cnt);
printf("\r\n");
}
#endif
/* FALL THROUGH */
failure:
/*
* We failed. Send an FB64_IV_BAD option
* to the other side so it will know that
* things failed.
*/
p = fbp->fb_feed + 3;
*p++ = ENCRYPT_REPLY;
p++;
*p++ = FB64_IV_BAD;
*p++ = IAC;
*p++ = SE;
#ifdef DEBUG
printsub('>', &fbp->fb_feed[2], p - &fbp->fb_feed[2]);
#endif
TelnetSend(EncryptKSGlobalHack, fbp->fb_feed, p - fbp->fb_feed, 0);
break;
}
return(fbp->state[DIR_DECRYPT-1] = state);
}
/*
* Returns:
* -1: some error. Negotiation is done, encryption not ready.
* 0: Successful, initial negotiation all done.
* 1: successful, negotiation not done yet.
*/
int
cfb64_reply(data, cnt)
unsigned char *data;
int cnt;
{
return(fb64_reply(data, cnt, &fb[CFB]));
}
int
ofb64_reply(data, cnt)
unsigned char *data;
int cnt;
{
return(fb64_reply(data, cnt, &fb[OFB]));
}
int
fb64_reply(data, cnt, fbp)
unsigned char *data;
int cnt;
struct fb *fbp;
{
register int state = fbp->state[DIR_ENCRYPT-1];
if (cnt-- < 1)
goto failure;
switch (*data++) {
case FB64_IV_OK:
fb64_stream_iv(fbp->temp_feed, &fbp->streams[DIR_ENCRYPT-1]);
if (state == xFAILED)
state = IN_PROGRESS;
state &= ~NO_RECV_IV;
encrypt_send_keyid(DIR_ENCRYPT, (unsigned char *)"\0", 1, 1);
break;
case FB64_IV_BAD:
memset(fbp->temp_feed, 0, sizeof(Block));
fb64_stream_iv(fbp->temp_feed, &fbp->streams[DIR_ENCRYPT-1]);
state = xFAILED;
break;
default:
#if 0
if (encrypt_debug_mode) {
printf("Unknown option type: %d\r\n", data[-1]);
printd(data, cnt);
printf("\r\n");
}
#endif
/* FALL THROUGH */
failure:
state = xFAILED;
break;
}
return(fbp->state[DIR_ENCRYPT-1] = state);
}
void
cfb64_session(key, server)
Session_Key *key;
int server;
{
fb64_session(key, server, &fb[CFB]);
}
void
ofb64_session(key, server)
Session_Key *key;
int server;
{
fb64_session(key, server, &fb[OFB]);
}
static void
fb64_session(key, server, fbp)
Session_Key *key;
int server;
struct fb *fbp;
{
if (!key || key->type != SK_DES) {
#ifdef DEBUG
if (encrypt_debug_mode)
printf("Can't set krbdes's session key (%d != %d)\r\n",
key ? key->type : -1, SK_DES);
#endif
return;
}
memcpy((void *)fbp->krbdes_key, (void *)key->data, sizeof(Block));
fb64_stream_key(fbp->krbdes_key, &fbp->streams[DIR_ENCRYPT-1]);
fb64_stream_key(fbp->krbdes_key, &fbp->streams[DIR_DECRYPT-1]);
if (fbp->once == 0) {
des_init_random_number_generator(fbp->krbdes_key);
fbp->once = 1;
}
des_key_sched(fbp->krbdes_key, fbp->krbdes_sched);
/*
* Now look to see if krbdes_start() was was waiting for
* the key to show up. If so, go ahead an call it now
* that we have the key.
*/
if (fbp->need_start) {
fbp->need_start = 0;
fb64_start(fbp, DIR_ENCRYPT, server);
}
}
/*
* We only accept a keyid of 0. If we get a keyid of
* 0, then mark the state as SUCCESS.
*/
int
cfb64_keyid(dir, kp, lenp)
int dir, *lenp;
unsigned char *kp;
{
return(fb64_keyid(dir, kp, lenp, &fb[CFB]));
}
int
ofb64_keyid(dir, kp, lenp)
int dir, *lenp;
unsigned char *kp;
{
return(fb64_keyid(dir, kp, lenp, &fb[OFB]));
}
int
fb64_keyid(dir, kp, lenp, fbp)
int dir, *lenp;
unsigned char *kp;
struct fb *fbp;
{
register int state = fbp->state[dir-1];
if (*lenp != 1 || (*kp != '\0')) {
*lenp = 0;
return(state);
}
if (state == xFAILED)
state = IN_PROGRESS;
state &= ~NO_KEYID;
return(fbp->state[dir-1] = state);
}
#if 0
void
fb64_printsub(data, cnt, buf, buflen, type)
unsigned char *data, *buf, *type;
int cnt, buflen;
{
char lbuf[32];
register int i;
char *cp;
buf[buflen-1] = '\0'; /* make sure it's NULL terminated */
buflen -= 1;
switch(data[2]) {
case FB64_IV:
sprintf(lbuf, "%s_IV", type);
cp = lbuf;
goto common;
case FB64_IV_OK:
sprintf(lbuf, "%s_IV_OK", type);
cp = lbuf;
goto common;
case FB64_IV_BAD:
sprintf(lbuf, "%s_IV_BAD", type);
cp = lbuf;
goto common;
default:
sprintf(lbuf, " %d (unknown)", data[2]);
cp = lbuf;
common:
for (; (buflen > 0) && (*buf = *cp++); buf++)
buflen--;
for (i = 3; i < cnt; i++) {
sprintf(lbuf, " %d", data[i]);
for (cp = lbuf; (buflen > 0) && (*buf = *cp++); buf++)
buflen--;
}
break;
}
}
void
cfb64_printsub(data, cnt, buf, buflen)
unsigned char *data, *buf;
int cnt, buflen;
{
fb64_printsub(data, cnt, buf, buflen, "CFB64");
}
void
ofb64_printsub(data, cnt, buf, buflen)
unsigned char *data, *buf;
int cnt, buflen;
{
fb64_printsub(data, cnt, buf, buflen, "OFB64");
}
#endif
void
fb64_stream_iv(seed, stp)
Block seed;
register struct stinfo *stp;
{
memcpy((void *)stp->str_iv, (void *)seed, sizeof(Block));
memcpy((void *)stp->str_output, (void *)seed, sizeof(Block));
des_key_sched(stp->str_ikey, stp->str_sched);
stp->str_index = sizeof(Block);
}
void
fb64_stream_key(key, stp)
Block key;
register struct stinfo *stp;
{
memcpy((void *)stp->str_ikey, (void *)key, sizeof(Block));
des_key_sched(key, stp->str_sched);
memcpy((void *)stp->str_output, (void *)stp->str_iv, sizeof(Block));
stp->str_index = sizeof(Block);
}
/*
* DES 64 bit Cipher Feedback
*
* key --->+-----+
* +->| DES |--+
* | +-----+ |
* | v
* INPUT --(--------->(+)+---> DATA
* | |
* +-------------+
*
*
* Given:
* iV: Initial vector, 64 bits (8 bytes) long.
* Dn: the nth chunk of 64 bits (8 bytes) of data to encrypt (decrypt).
* On: the nth chunk of 64 bits (8 bytes) of encrypted (decrypted) output.
*
* V0 = DES(iV, key)
* On = Dn ^ Vn
* V(n+1) = DES(On, key)
*/
void
cfb64_encrypt(s, c)
register unsigned char *s;
int c;
{
register struct stinfo *stp = &fb[CFB].streams[DIR_ENCRYPT-1];
register int index;
index = stp->str_index;
while (c-- > 0) {
if (index == sizeof(Block)) {
Block b;
des_ecb_encrypt(stp->str_output, b, stp->str_sched, 1);
memcpy((void *)stp->str_feed,(void *)b,sizeof(Block));
index = 0;
}
/* On encryption, we store (feed ^ data) which is cypher */
*s = stp->str_output[index] = (stp->str_feed[index] ^ *s);
s++;
index++;
}
stp->str_index = index;
}
int
cfb64_decrypt(data)
int data;
{
register struct stinfo *stp = &fb[CFB].streams[DIR_DECRYPT-1];
int index;
if (data == -1) {
/*
* Back up one byte. It is assumed that we will
* never back up more than one byte. If we do, this
* may or may not work.
*/
if (stp->str_index)
--stp->str_index;
return(0);
}
index = stp->str_index++;
if (index == sizeof(Block)) {
Block b;
des_ecb_encrypt(stp->str_output, b, stp->str_sched, 1);
memcpy((void *)stp->str_feed, (void *)b, sizeof(Block));
stp->str_index = 1; /* Next time will be 1 */
index = 0; /* But now use 0 */
}
/* On decryption we store (data) which is cypher. */
stp->str_output[index] = data;
return(data ^ stp->str_feed[index]);
}
/*
* DES 64 bit Output Feedback
*
* key --->+-----+
* +->| DES |--+
* | +-----+ |
* +-----------+
* v
* INPUT -------->(+) ----> DATA
*
* Given:
* iV: Initial vector, 64 bits (8 bytes) long.
* Dn: the nth chunk of 64 bits (8 bytes) of data to encrypt (decrypt).
* On: the nth chunk of 64 bits (8 bytes) of encrypted (decrypted) output.
*
* V0 = DES(iV, key)
* V(n+1) = DES(Vn, key)
* On = Dn ^ Vn
*/
void
ofb64_encrypt(s, c)
register unsigned char *s;
int c;
{
register struct stinfo *stp = &fb[OFB].streams[DIR_ENCRYPT-1];
register int index;
index = stp->str_index;
while (c-- > 0) {
if (index == sizeof(Block)) {
Block b;
des_ecb_encrypt(stp->str_feed, b, stp->str_sched, 1);
memcpy((void *)stp->str_feed,(void *)b,sizeof(Block));
index = 0;
}
*s++ ^= stp->str_feed[index];
index++;
}
stp->str_index = index;
}
int
ofb64_decrypt(data)
int data;
{
register struct stinfo *stp = &fb[OFB].streams[DIR_DECRYPT-1];
int index;
if (data == -1) {
/*
* Back up one byte. It is assumed that we will
* never back up more than one byte. If we do, this
* may or may not work.
*/
if (stp->str_index)
--stp->str_index;
return(0);
}
index = stp->str_index++;
if (index == sizeof(Block)) {
Block b;
des_ecb_encrypt(stp->str_feed, b, stp->str_sched, 1);
memcpy((void *)stp->str_feed, (void *)b, sizeof(Block));
stp->str_index = 1; /* Next time will be 1 */
index = 0; /* But now use 0 */
}
return(data ^ stp->str_feed[index]);
}
#endif /* ENCRYPTION */
|
the_stack_data/84573.c
|
extern void __VERIFIER_error() __attribute__ ((__noreturn__));
extern void __VERIFIER_assume(int);
void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } }
extern int __VERIFIER_nondet_int(void);
int N;
int main()
{
N = __VERIFIER_nondet_int();
if(N <= 0) return 1;
int i;
int sum[1];
int a[N];
int c[N];
sum[0] = 0;
for(i=0; i<N; i++)
{
sum[0] = sum[0] + i;
}
for(i=0; i<N; i++)
{
a[i] = N*(N+1)/2;
}
for(i=0; i<N; i++)
{
if(i != 2 && N % (i-2) == 1)
{
c[i] = sum[0];
} else {
c[i] = a[i];
}
}
for(i=0; i<N; i++)
{
__VERIFIER_assert(c[i] == N*(N+1)/2);
}
return 1;
}
|
the_stack_data/123880.c
|
#include <stdio.h>
#include <stdlib.h>
int global_var;
int global_initialized_var = 5;
void function()
{
int stack_var;
printf("The function's stack_var is at address %p\n", &stack_var);
}
int main()
{
int stack_var;
static int static_initialized_var = 5;
static int static_var;
int *heap_var_ptr;
heap_var_ptr = (int *) malloc(4);
//Data segment
printf("global_initialized_var is at address %p\n", &global_initialized_var);
printf("static_initialized_var is at address %p\n\n", &static_initialized_var);
//BSS segment
printf("static_var is at address %p\n", &static_var);
printf("global_var is at address %p\n\n", &global_var);
//Heap segment
printf("heap_var is at address %p\n\n", heap_var_ptr);
//Stack segment
printf("stack_var is at address %p\n", &stack_var);
function();
return 0;
}
|
the_stack_data/165767290.c
|
#include<stdio.h>
#define MAX 100
int main(void)
{
int n,i,j,v[MAX][MAX],soma[MAX],aux,cont[MAX];
scanf("%d", &n);
while(n !=0)
{
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d", &v[i][j]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
soma[j] = soma[j] + v[i][j];
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(soma[i] < soma[j])
{
aux = soma[i];
soma[i] = soma[j];
soma[j] = aux;
cont[i] = j;
printf("%d", cont[i]);
}
for(i=n-1;i >= 0;i--)
printf("%d ", cont[i]);
printf("\n");
scanf("%d", &n);
}
}
|
the_stack_data/64035.c
|
#include <stdio.h>
#define MAX (1000)
int main(void)
{
int TC, tc;
int N, M, weight[MAX + 1];
int i, j, k, answer;
freopen("sample_input.txt", "r", stdin);
setbuf(stdout, NULL);
scanf("%d", &TC);
for (tc = 1; tc <= TC; ++tc) {
scanf("%d %d\n", &N, &M);
answer = -1;
for (i = 0; i < N; ++i) {
scanf("%d\n", &weight[i]);
for (j = 0; (answer < M) && (j < i); ++j) {
k = weight[i] + weight[j];
if ((k <= M) && (answer < k)) {
answer = k;
}
}
}
printf("#%d %d\n", tc, answer);
}
return 0;
}
|
the_stack_data/43773.c
|
// UVa 10340
#include <stdio.h>
#include <string.h>
#define MAXS 1000000
char s[MAXS];
char t[MAXS];
void input()
{
scanf("%s", t);
scanf("%s", s);
//printf("%s\n", s);
//printf("%s\n", t);
}
int solve()
{
int ls = strlen(s);
int lt = strlen(t);
int p = 0;
for (int i = 0; i < ls; i++) {
if (t[p] == s[i]) p++;
}
if (p == lt) return 1;
else return 0;
}
int main()
{
int c;
while ((c = getchar()) != EOF) {
ungetc(c, stdin);
//printf("%c\n", c);
input();
//printf("%s %s\n", s, t);
int result = solve();
if (result) printf("Yes\n");
else printf("No\n");
getchar();
}
}
|
the_stack_data/165766118.c
|
// adapted from https://stackoverflow.com/a/54267342/12887845
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define MESSAGE "on second thought...\n"
#define MSGLEN 21
static volatile sig_atomic_t keep_running = 1;
static void sig_handler(int this_signal) {
if (this_signal == SIGINT){
write(STDOUT_FILENO, MESSAGE, MSGLEN);
keep_running = 0;
}
}
int main(void) {
unsigned long counter = 0;
int sleep_result;
signal(SIGINT, sig_handler);
while (keep_running) {
printf("look I can count to %ld\n", counter);
counter++;
sleep_result = usleep(250000); // 250 ms
if(sleep_result != 0 ){
perror("usleep failed:");
}
}
return EXIT_SUCCESS;
}
|
the_stack_data/107056.c
|
#include <stdio.h>
int main()
{
int i;
int n,d;
int c=0,wins=0,k=0;
char days[101];
scanf("%d %d",&n,&d);
while(d--)
{
scanf("%s",days);
c=0;
for(i=0;i<n;i++)
{
if(days[i]=='1')
c++;
}
if(c<n)
k++;
if(wins<k)
wins=k;
if(c==n)
k=0;
}
printf("%d\n",wins);
return 0;
}
|
the_stack_data/95449718.c
|
int f()
{
int i = 3;
{
int i = 4;
{
int i = 2;
}
}
return i;
}
|
the_stack_data/120710.c
|
#include <stdio.h>
int main()
{
int n = 0, i = 0;
double x = 0, x1 = 0;
int b = 1;
if ((scanf("%d", &n) == 1))
{
for (i = 0; i < n; i++)
{
if (scanf("%lf", &x) == 1)
{
if(i != 0)
{
if(x1 < x)
{
b = 0;
break;
}
}
}
else
{
printf("Ошибка ввода\n");
break;
}
x1 = x;
}
printf("%d\n", b);
}
else
{
printf("Ошибка ввода\n");
}
return 0;
}
|
the_stack_data/121498.c
|
#if defined _Static_assert
# error Should not be defined, but valid to ask for it
#endif
#include <assert.h>
/* NOT actually on OpenBSD! (This is a bug) */
#ifdef __OpenBSD__
#define static_assert _Static_assert
#endif
_Static_assert('a' < 'b', "Alphabet error");
int foo(char a) {
_Static_assert(sizeof(a) == 1, "Hello");
return 0;
}
int main(void) {
return foo(42);
}
static_assert(1, "");
|
the_stack_data/48576285.c
|
// Test containing bad code to check whether VeriFast catches it.
/*@
predicate pred<a>(list<a> l);
@*/
typedef void fun_t/*@<a> @*/();
//@ requires pred<a>(?l);
//@ ensures pred<a>(l);
void fun()
//@ : fun_t<int>
//@ requires pred<char>(?l); //~ should-fail
//@ ensures pred<char>(l);
{
}
|
the_stack_data/29129.c
|
/*------------------------------------------------------------------------------
*
* Copyright (c) 2011-2022, EURid vzw. All rights reserved.
* The YADIFA TM software product is provided under the BSD 3-clause license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of EURid nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*------------------------------------------------------------------------------
*
*/
/** @defgroup
* @ingroup
* @brief
*
*
*
* @{
*
*----------------------------------------------------------------------------*/
const char *journal_ix = "journal-ix disabled";
/** @} */
|
the_stack_data/90766186.c
|
//1487 - Six Flags
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef struct brinquedo
{
unsigned short tempo;
unsigned short qtsPontos;
double razaoPontoTempo;
} brinquedo;
int compara(brinquedo *a, brinquedo *b);
int main()
{
unsigned short i, cont, aux, qtsAtracoes, limiteTempo, pontoTotal, tempoTotal;
cont = 0;
while (1)
{
scanf("%hu %hu", &qtsAtracoes, &limiteTempo);
if (qtsAtracoes == 0)
break;
brinquedo brinquedos[qtsAtracoes];
for (i = 0; i < qtsAtracoes; ++i)
{
scanf("%hu %hu", &brinquedos[i].tempo, &brinquedos[i].qtsPontos);
brinquedos[i].razaoPontoTempo = (brinquedos[i].qtsPontos / brinquedos[i].tempo);
}
qsort(brinquedos, qtsAtracoes, sizeof(brinquedo), compara);
i = 0;
pontoTotal = tempoTotal = 0;
while (i < qtsAtracoes)
{
aux = tempoTotal + brinquedos[i].tempo;
if (aux <= limiteTempo)
{
pontoTotal += brinquedos[i].qtsPontos;
tempoTotal = aux;
}
else
i++;
}
printf("Instancia %hu\n%hu\n\n", ++cont, pontoTotal);
}
}
int compara(brinquedo *a, brinquedo *b)
{
if (a->razaoPontoTempo == b->razaoPontoTempo)
return 0;
else if (a->razaoPontoTempo > b->razaoPontoTempo)
return -1;
else
return 1;
}
|
the_stack_data/111076824.c
|
// memstream test program from C technical report
// zcc +cpm -vn -O3 -clib=new fmemopen.c -o fmemopen
// zcc +cpm -vn -SO3 -clib=sdcc_iy --max-allocs-per-node200000 fmemopen.c -o fmemopen
// zcc +zx -vn -O3 -clib=new fmemopen.c -o fmemopen
// zcc +zx -vn -SO3 -clib=sdcc_ix --reserve-regs-iy --max-allocs-per-node200000 fmemopen.c -o fmemopen
// appmake +zx -b fmemopen_CODE.bin -o fmem.tap --org 32768 --blockname fmem
#include <stdio.h>
#include <string.h>
static char buffer[] = "foobar";
int main(void)
{
int ch;
FILE *stream;
stream = fmemopen(buffer, strlen(buffer), "r");
if (stream == NULL)
perror("fmemopen");
else
{
while ((ch = fgetc(stream)) != EOF)
printf("Got %c\n", ch);
fclose(stream);
}
return 0;
}
|
the_stack_data/813302.c
|
/* APPLE LOCAL file v7 merge */
/* { dg-do compile } */
/* { dg-require-effective-target arm_vfp_ok } */
/* { dg-options "-O2 -mfpu=vfp -mfloat-abi=softfp" } */
extern void bar (double);
void
foo (double *p, double a, int n)
{
do
bar (*p++ + a);
while (n--);
}
/* { dg-final { scan-assembler "fldmiad" } } */
|
the_stack_data/153267321.c
|
/* NetHack 3.6 nttty.c $NHDT-Date: 1554215932 2019/04/02 14:38:52 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.99 $ */
/* Copyright (c) NetHack PC Development Team 1993 */
/* NetHack may be freely redistributed. See license for details. */
/* tty.c - (Windows NT) version */
/*
* Initial Creation M. Allison 1993/01/31
* Switch to low level console output routines M. Allison 2003/10/01
* Restrict cursor movement until input pending M. Lehotay 2003/10/02
* Call Unicode version of output API on NT R. Chason 2005/10/28
* Use of back buffer to improve performance B. House 2018/05/06
*
*/
#ifdef WIN32
#define NEED_VARARGS /* Uses ... */
#include "win32api.h"
#include "winos.h"
#include "hack.h"
#include "wintty.h"
#include <sys\types.h>
#include <sys\stat.h>
extern boolean getreturn_enabled; /* from sys/share/pcsys.c */
extern int redirect_stdout;
#ifdef TTY_GRAPHICS
/*
* Console Buffer Flipping Support
*
* To minimize the number of calls into the WriteConsoleOutputXXX methods,
* we implement a notion of a console back buffer which keeps the next frame
* of console output as it is being composed. When ready to show the new
* frame, we compare this next frame to what is currently being output and
* only call WriteConsoleOutputXXX for those console values that need to
* change.
*
*/
#define CONSOLE_CLEAR_ATTRIBUTE (FOREGROUND_RED | FOREGROUND_GREEN \
| FOREGROUND_BLUE)
#define CONSOLE_CLEAR_CHARACTER (' ')
#define CONSOLE_UNDEFINED_ATTRIBUTE (0)
#define CONSOLE_UNDEFINED_CHARACTER ('\0')
typedef struct {
WCHAR character;
WORD attribute;
} cell_t;
cell_t clear_cell = { CONSOLE_CLEAR_CHARACTER, CONSOLE_CLEAR_ATTRIBUTE };
cell_t undefined_cell = { CONSOLE_UNDEFINED_CHARACTER,
CONSOLE_UNDEFINED_ATTRIBUTE };
/*
* The following WIN32 Console API routines are used in this file.
*
* CreateFile
* GetConsoleScreenBufferInfo
* GetStdHandle
* SetConsoleCursorPosition
* SetConsoleTextAttribute
* SetConsoleCtrlHandler
* PeekConsoleInput
* ReadConsoleInput
* WriteConsoleOutputCharacter
* FillConsoleOutputAttribute
* GetConsoleOutputCP
*/
static BOOL FDECL(CtrlHandler, (DWORD));
static void FDECL(xputc_core, (char));
void FDECL(cmov, (int, int));
void FDECL(nocmov, (int, int));
int FDECL(process_keystroke,
(INPUT_RECORD *, boolean *, BOOLEAN_P numberpad, int portdebug));
static void NDECL(init_ttycolor);
static void NDECL(really_move_cursor);
static void NDECL(check_and_set_font);
static boolean NDECL(check_font_widths);
static void NDECL(set_known_good_console_font);
static void NDECL(restore_original_console_font);
extern void NDECL(safe_routines);
/* Win32 Screen buffer,coordinate,console I/O information */
COORD ntcoord;
INPUT_RECORD ir;
static boolean orig_QuickEdit;
/* Support for changing console font if existing glyph widths are too wide */
/* Flag for whether NetHack was launched via the GUI, not the command line.
* The reason we care at all, is so that we can get
* a final RETURN at the end of the game when launched from the GUI
* to prevent the scoreboard (or panic message :-|) from vanishing
* immediately after it is displayed, yet not bother when started
* from the command line.
*/
int GUILaunched = FALSE;
/* Flag for whether unicode is supported */
static boolean init_ttycolor_completed;
#ifdef PORT_DEBUG
static boolean display_cursor_info = FALSE;
#endif
#ifdef CHANGE_COLOR
static void NDECL(adjust_palette);
static int FDECL(match_color_name, (const char *));
typedef HWND(WINAPI *GETCONSOLEWINDOW)();
static HWND GetConsoleHandle(void);
static HWND GetConsoleHwnd(void);
static boolean altered_palette;
static COLORREF UserDefinedColors[CLR_MAX];
static COLORREF NetHackColors[CLR_MAX] = {
0x00000000, 0x00c80000, 0x0000c850, 0x00b4b432, 0x000000d2, 0x00800080,
0x000064b4, 0x00c0c0c0, 0x00646464, 0x00f06464, 0x0000ff00, 0x00ffff00,
0x000000ff, 0x00ff00ff, 0x0000ffff, 0x00ffffff
};
static COLORREF DefaultColors[CLR_MAX] = {
0x00000000, 0x00800000, 0x00008000, 0x00808000, 0x00000080, 0x00800080,
0x00008080, 0x00c0c0c0, 0x00808080, 0x00ff0000, 0x0000ff00, 0x00ffff00,
0x000000ff, 0x00ff00ff, 0x0000ffff, 0x00ffffff
};
#endif
struct console_t {
WORD background;
WORD foreground;
WORD attr;
int current_nhcolor;
int current_nhattr[ATR_INVERSE+1];
COORD cursor;
HANDLE hConOut;
HANDLE hConIn;
CONSOLE_SCREEN_BUFFER_INFO origcsbi;
int width;
int height;
boolean has_unicode;
int buffer_size;
cell_t * front_buffer;
cell_t * back_buffer;
WCHAR cpMap[256];
boolean font_changed;
CONSOLE_FONT_INFOEX original_font_info;
UINT original_code_page;
} console = {
0,
(FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED),
(FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED),
NO_COLOR,
{FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE},
{0, 0},
NULL,
NULL,
{ 0 },
0,
0,
FALSE,
0,
NULL,
NULL,
{ 0 },
FALSE,
{ 0 },
0
};
static DWORD ccount, acount;
#ifndef CLR_MAX
#define CLR_MAX 16
#endif
int ttycolors[CLR_MAX];
int ttycolors_inv[CLR_MAX];
#define MAX_OVERRIDES 256
unsigned char key_overrides[MAX_OVERRIDES];
static char nullstr[] = "";
char erase_char, kill_char;
#define DEFTEXTCOLOR ttycolors[7]
/* dynamic keystroke handling .DLL support */
typedef int(__stdcall *PROCESS_KEYSTROKE)(HANDLE, INPUT_RECORD *, boolean *,
BOOLEAN_P, int);
typedef int(__stdcall *NHKBHIT)(HANDLE, INPUT_RECORD *);
typedef int(__stdcall *CHECKINPUT)(HANDLE, INPUT_RECORD *, DWORD *, BOOLEAN_P,
int, int *, coord *);
typedef int(__stdcall *SOURCEWHERE)(char **);
typedef int(__stdcall *SOURCEAUTHOR)(char **);
typedef int(__stdcall *KEYHANDLERNAME)(char **, int);
typedef struct {
char * name; // name without DLL extension
HANDLE hLibrary;
PROCESS_KEYSTROKE pProcessKeystroke;
NHKBHIT pNHkbhit;
CHECKINPUT pCheckInput;
SOURCEWHERE pSourceWhere;
SOURCEAUTHOR pSourceAuthor;
KEYHANDLERNAME pKeyHandlerName;
} keyboard_handler_t;
keyboard_handler_t keyboard_handler;
/* Console buffer flipping support */
static void back_buffer_flip()
{
cell_t * back = console.back_buffer;
cell_t * front = console.front_buffer;
COORD pos;
DWORD unused;
for (pos.Y = 0; pos.Y < console.height; pos.Y++) {
for (pos.X = 0; pos.X < console.width; pos.X++) {
if (back->attribute != front->attribute) {
WriteConsoleOutputAttribute(console.hConOut, &back->attribute,
1, pos, &unused);
front->attribute = back->attribute;
}
if (back->character != front->character) {
if (console.has_unicode) {
WriteConsoleOutputCharacterW(console.hConOut,
&back->character, 1, pos, &unused);
} else {
char ch = (char)back->character;
WriteConsoleOutputCharacterA(console.hConOut, &ch, 1, pos,
&unused);
}
*front = *back;
}
back++;
front++;
}
}
}
void buffer_fill_to_end(cell_t * buffer, cell_t * fill, int x, int y)
{
nhassert(x >= 0 && x < console.width);
nhassert(y >= 0 && ((y < console.height) || (y == console.height &&
x == 0)));
cell_t * dst = buffer + console.width * y + x;
cell_t * sentinel = buffer + console.buffer_size;
while (dst != sentinel)
*dst++ = *fill;
if (iflags.debug.immediateflips && buffer == console.back_buffer)
back_buffer_flip();
}
static void buffer_clear_to_end_of_line(cell_t * buffer, int x, int y)
{
nhassert(x >= 0 && x < console.width);
nhassert(y >= 0 && ((y < console.height) || (y == console.height &&
x == 0)));
cell_t * dst = buffer + console.width * y + x;
cell_t *sentinel = buffer + console.width * (y + 1);
while (dst != sentinel)
*dst++ = clear_cell;
if (iflags.debug.immediateflips)
back_buffer_flip();
}
void buffer_write(cell_t * buffer, cell_t * cell, COORD pos)
{
nhassert(pos.X >= 0 && pos.X < console.width);
nhassert(pos.Y >= 0 && pos.Y < console.height);
cell_t * dst = buffer + (console.width * pos.Y) + pos.X;
*dst = *cell;
if (iflags.debug.immediateflips && buffer == console.back_buffer)
back_buffer_flip();
}
/*
* Called after returning from ! or ^Z
*/
void
gettty()
{
#ifndef TEXTCOLOR
int k;
#endif
erase_char = '\b';
kill_char = 21; /* cntl-U */
iflags.cbreak = TRUE;
#ifdef TEXTCOLOR
init_ttycolor();
#else
for (k = 0; k < CLR_MAX; ++k)
ttycolors[k] = NO_COLOR;
#endif
}
/* reset terminal to original state */
void
settty(s)
const char *s;
{
cmov(ttyDisplay->curx, ttyDisplay->cury);
end_screen();
if (s)
raw_print(s);
restore_original_console_font();
if (orig_QuickEdit) {
DWORD cmode;
GetConsoleMode(console.hConIn, &cmode);
cmode |= (ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS);
SetConsoleMode(console.hConIn, cmode);
}
}
/* called by init_nhwindows() and resume_nhwindows() */
void
setftty()
{
#ifdef CHANGE_COLOR
if (altered_palette)
adjust_palette();
#endif
start_screen();
}
void
tty_startup(wid, hgt)
int *wid, *hgt;
{
*wid = console.width;
*hgt = console.height;
set_option_mod_status("mouse_support", SET_IN_GAME);
}
void
tty_number_pad(state)
int state;
{
// do nothing
}
void
tty_start_screen()
{
if (iflags.num_pad)
tty_number_pad(1); /* make keypad send digits */
}
void
tty_end_screen()
{
clear_screen();
really_move_cursor();
buffer_fill_to_end(console.back_buffer, &clear_cell, 0, 0);
back_buffer_flip();
FlushConsoleInputBuffer(console.hConIn);
}
static BOOL
CtrlHandler(ctrltype)
DWORD ctrltype;
{
switch (ctrltype) {
/* case CTRL_C_EVENT: */
case CTRL_BREAK_EVENT:
clear_screen();
case CTRL_CLOSE_EVENT:
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
getreturn_enabled = FALSE;
#ifndef NOSAVEONHANGUP
hangup(0);
#endif
#if defined(SAFERHANGUP)
CloseHandle(console.hConIn); /* trigger WAIT_FAILED */
return TRUE;
#endif
default:
return FALSE;
}
}
/* called by pcmain() and process_options() */
void
nttty_open(mode)
int mode; // unused
{
DWORD cmode;
/* Initialize the function pointer that points to
* the kbhit() equivalent, in this TTY case nttty_kbhit()
*/
nt_kbhit = nttty_kbhit;
if (!SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE)) {
/* Unable to set control handler */
cmode = 0; /* just to have a statement to break on for debugger */
}
LI = console.height;
CO = console.width;
really_move_cursor();
}
void
nttty_exit()
{
/* go back to using the safe routines */
safe_routines();
}
int
process_keystroke(ir, valid, numberpad, portdebug)
INPUT_RECORD *ir;
boolean *valid;
boolean numberpad;
int portdebug;
{
int ch;
#ifdef QWERTZ_SUPPORT
if (Cmd.swap_yz)
numberpad |= 0x10;
#endif
ch = keyboard_handler.pProcessKeystroke(
console.hConIn, ir, valid, numberpad, portdebug);
#ifdef QWERTZ_SUPPORT
numberpad &= ~0x10;
#endif
/* check for override */
if (ch && ch < MAX_OVERRIDES && key_overrides[ch])
ch = key_overrides[ch];
return ch;
}
int
nttty_kbhit()
{
return keyboard_handler.pNHkbhit(console.hConIn, &ir);
}
int
tgetch()
{
int mod;
coord cc;
DWORD count;
boolean numpad = iflags.num_pad;
really_move_cursor();
if (iflags.debug_fuzzer)
return randomkey();
#ifdef QWERTZ_SUPPORT
if (Cmd.swap_yz)
numpad |= 0x10;
#endif
return (program_state.done_hup)
? '\033'
: keyboard_handler.pCheckInput(
console.hConIn, &ir, &count, numpad, 0, &mod, &cc);
}
int
ntposkey(x, y, mod)
int *x, *y, *mod;
{
int ch;
coord cc;
DWORD count;
boolean numpad = iflags.num_pad;
really_move_cursor();
if (iflags.debug_fuzzer)
return randomkey();
#ifdef QWERTZ_SUPPORT
if (Cmd.swap_yz)
numpad |= 0x10;
#endif
ch = (program_state.done_hup)
? '\033'
: keyboard_handler.pCheckInput(
console.hConIn, &ir, &count, numpad, 1, mod, &cc);
#ifdef QWERTZ_SUPPORT
numpad &= ~0x10;
#endif
if (!ch) {
*x = cc.x;
*y = cc.y;
}
return ch;
}
static void set_console_cursor(int x, int y)
{
nhassert(x >= 0 && x < console.width);
nhassert(y >= 0 && y < console.height);
console.cursor.X = max(0, min(console.width - 1, x));
console.cursor.Y = max(0, min(console.height - 1, y));
}
static void
really_move_cursor()
{
#ifdef PORT_DEBUG
char oldtitle[BUFSZ], newtitle[BUFSZ];
if (display_cursor_info && wizard) {
oldtitle[0] = '\0';
if (GetConsoleTitle(oldtitle, BUFSZ)) {
oldtitle[39] = '\0';
}
Sprintf(newtitle, "%-55s tty=(%02d,%02d) nttty=(%02d,%02d)", oldtitle,
ttyDisplay->curx, ttyDisplay->cury,
console.cursor.X, console.cursor.Y);
(void) SetConsoleTitle(newtitle);
}
#endif
if (ttyDisplay)
set_console_cursor(ttyDisplay->curx, ttyDisplay->cury);
back_buffer_flip();
SetConsoleCursorPosition(console.hConOut, console.cursor);
}
void
cmov(x, y)
register int x, y;
{
ttyDisplay->cury = y;
ttyDisplay->curx = x;
set_console_cursor(x, y);
}
void
nocmov(x, y)
int x, y;
{
ttyDisplay->curx = x;
ttyDisplay->cury = y;
set_console_cursor(x, y);
}
/* same signature as 'putchar()' with potential failure result ignored */
int
xputc(ch)
int ch;
{
set_console_cursor(ttyDisplay->curx, ttyDisplay->cury);
xputc_core((char) ch);
return 0;
}
void
xputs(s)
const char *s;
{
int k;
int slen = (int) strlen(s);
if (ttyDisplay)
set_console_cursor(ttyDisplay->curx, ttyDisplay->cury);
if (s) {
for (k = 0; k < slen && s[k]; ++k)
xputc_core(s[k]);
}
}
/* xputc_core() and g_putch() are the only
* two routines that actually place output
* on the display.
*/
void
xputc_core(ch)
char ch;
{
nhassert(console.cursor.X >= 0 && console.cursor.X < console.width);
nhassert(console.cursor.Y >= 0 && console.cursor.Y < console.height);
boolean inverse = FALSE;
cell_t cell;
switch (ch) {
case '\n':
if (console.cursor.Y < console.height - 1)
console.cursor.Y++;
/* fall through */
case '\r':
console.cursor.X = 1;
break;
case '\b':
if (console.cursor.X > 1) {
console.cursor.X--;
} else if(console.cursor.Y > 0) {
console.cursor.X = console.width - 1;
console.cursor.Y--;
}
break;
default:
inverse = (console.current_nhattr[ATR_INVERSE] && iflags.wc_inverse);
console.attr = (inverse) ?
ttycolors_inv[console.current_nhcolor] :
ttycolors[console.current_nhcolor];
if (console.current_nhattr[ATR_BOLD])
console.attr |= (inverse) ?
BACKGROUND_INTENSITY : FOREGROUND_INTENSITY;
cell.attribute = console.attr;
cell.character = (console.has_unicode ? console.cpMap[ch] : ch);
buffer_write(console.back_buffer, &cell, console.cursor);
if (console.cursor.X == console.width - 1) {
if (console.cursor.Y < console.height - 1) {
console.cursor.X = 1;
console.cursor.Y++;
}
} else {
console.cursor.X++;
}
}
nhassert(console.cursor.X >= 0 && console.cursor.X < console.width);
nhassert(console.cursor.Y >= 0 && console.cursor.Y < console.height);
}
/*
* Overrides wintty.c function of the same name
* for win32. It is used for glyphs only, not text.
*/
void
g_putch(in_ch)
int in_ch;
{
boolean inverse = FALSE;
unsigned char ch = (unsigned char) in_ch;
set_console_cursor(ttyDisplay->curx, ttyDisplay->cury);
inverse = (console.current_nhattr[ATR_INVERSE] && iflags.wc_inverse);
console.attr = (console.current_nhattr[ATR_INVERSE] && iflags.wc_inverse) ?
ttycolors_inv[console.current_nhcolor] :
ttycolors[console.current_nhcolor];
if (console.current_nhattr[ATR_BOLD])
console.attr |= (inverse) ? BACKGROUND_INTENSITY : FOREGROUND_INTENSITY;
cell_t cell;
cell.attribute = console.attr;
cell.character = (console.has_unicode ? cp437[ch] : ch);
buffer_write(console.back_buffer, &cell, console.cursor);
}
void
cl_end()
{
set_console_cursor(ttyDisplay->curx, ttyDisplay->cury);
buffer_clear_to_end_of_line(console.back_buffer, console.cursor.X,
console.cursor.Y);
tty_curs(BASE_WINDOW, (int) ttyDisplay->curx + 1, (int) ttyDisplay->cury);
}
void
raw_clear_screen()
{
if (WINDOWPORT("tty")) {
cell_t * back = console.back_buffer;
cell_t * front = console.front_buffer;
COORD pos;
DWORD unused;
for (pos.Y = 0; pos.Y < console.height; pos.Y++) {
for (pos.X = 0; pos.X < console.width; pos.X++) {
WriteConsoleOutputAttribute(console.hConOut, &back->attribute,
1, pos, &unused);
front->attribute = back->attribute;
if (console.has_unicode) {
WriteConsoleOutputCharacterW(console.hConOut,
&back->character, 1, pos, &unused);
} else {
char ch = (char)back->character;
WriteConsoleOutputCharacterA(console.hConOut, &ch, 1, pos,
&unused);
}
*front = *back;
back++;
front++;
}
}
}
}
void
clear_screen()
{
buffer_fill_to_end(console.back_buffer, &clear_cell, 0, 0);
home();
}
void
home()
{
ttyDisplay->curx = ttyDisplay->cury = 0;
set_console_cursor(ttyDisplay->curx, ttyDisplay->cury);
}
void
backsp()
{
set_console_cursor(ttyDisplay->curx, ttyDisplay->cury);
xputc_core('\b');
}
void
cl_eos()
{
buffer_fill_to_end(console.back_buffer, &clear_cell, ttyDisplay->curx,
ttyDisplay->cury);
tty_curs(BASE_WINDOW, (int) ttyDisplay->curx + 1, (int) ttyDisplay->cury);
}
void
tty_nhbell()
{
if (flags.silent || iflags.debug_fuzzer)
return;
Beep(8000, 500);
}
volatile int junk; /* prevent optimizer from eliminating loop below */
void
tty_delay_output()
{
/* delay 50 ms - uses ANSI C clock() function now */
clock_t goal;
int k;
goal = 50 + clock();
back_buffer_flip();
if (iflags.debug_fuzzer)
return;
while (goal > clock()) {
k = junk; /* Do nothing */
}
}
/*
* CLR_BLACK 0
* CLR_RED 1
* CLR_GREEN 2
* CLR_BROWN 3 low-intensity yellow
* CLR_BLUE 4
* CLR_MAGENTA 5
* CLR_CYAN 6
* CLR_GRAY 7 low-intensity white
* NO_COLOR 8
* CLR_ORANGE 9
* CLR_BRIGHT_GREEN 10
* CLR_YELLOW 11
* CLR_BRIGHT_BLUE 12
* CLR_BRIGHT_MAGENTA 13
* CLR_BRIGHT_CYAN 14
* CLR_WHITE 15
* CLR_MAX 16
* BRIGHT 8
*/
static void
init_ttycolor()
{
#ifdef TEXTCOLOR
ttycolors[CLR_BLACK] = FOREGROUND_INTENSITY; /* fix by Quietust */
ttycolors[CLR_RED] = FOREGROUND_RED;
ttycolors[CLR_GREEN] = FOREGROUND_GREEN;
ttycolors[CLR_BROWN] = FOREGROUND_GREEN | FOREGROUND_RED;
ttycolors[CLR_BLUE] = FOREGROUND_BLUE;
ttycolors[CLR_MAGENTA] = FOREGROUND_BLUE | FOREGROUND_RED;
ttycolors[CLR_CYAN] = FOREGROUND_GREEN | FOREGROUND_BLUE;
ttycolors[CLR_GRAY] = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE;
ttycolors[NO_COLOR] = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED;
ttycolors[CLR_ORANGE] = FOREGROUND_RED | FOREGROUND_INTENSITY;
ttycolors[CLR_BRIGHT_GREEN] = FOREGROUND_GREEN | FOREGROUND_INTENSITY;
ttycolors[CLR_YELLOW] = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY;
ttycolors[CLR_BRIGHT_BLUE] = FOREGROUND_BLUE | FOREGROUND_INTENSITY;
ttycolors[CLR_BRIGHT_MAGENTA]=FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY;
ttycolors[CLR_BRIGHT_CYAN] = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
ttycolors[CLR_WHITE] = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED
| FOREGROUND_INTENSITY;
ttycolors_inv[CLR_BLACK] = BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_RED
| BACKGROUND_INTENSITY;
ttycolors_inv[CLR_RED] = BACKGROUND_RED | BACKGROUND_INTENSITY;
ttycolors_inv[CLR_GREEN] = BACKGROUND_GREEN;
ttycolors_inv[CLR_BROWN] = BACKGROUND_GREEN | BACKGROUND_RED;
ttycolors_inv[CLR_BLUE] = BACKGROUND_BLUE | BACKGROUND_INTENSITY;
ttycolors_inv[CLR_MAGENTA] = BACKGROUND_BLUE | BACKGROUND_RED;
ttycolors_inv[CLR_CYAN] = BACKGROUND_GREEN | BACKGROUND_BLUE;
ttycolors_inv[CLR_GRAY] = BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE;
ttycolors_inv[NO_COLOR] = BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_RED;
ttycolors_inv[CLR_ORANGE] = BACKGROUND_RED | BACKGROUND_INTENSITY;
ttycolors_inv[CLR_BRIGHT_GREEN]= BACKGROUND_GREEN | BACKGROUND_INTENSITY;
ttycolors_inv[CLR_YELLOW] = BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY;
ttycolors_inv[CLR_BRIGHT_BLUE] = BACKGROUND_BLUE | BACKGROUND_INTENSITY;
ttycolors_inv[CLR_BRIGHT_MAGENTA] =BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_INTENSITY;
ttycolors_inv[CLR_BRIGHT_CYAN] = BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY;
ttycolors_inv[CLR_WHITE] = BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_RED
| BACKGROUND_INTENSITY;
#else
int k;
ttycolors[0] = FOREGROUND_INTENSITY;
ttycolors_inv[0] = BACKGROUND_INTENSITY;
for (k = 1; k < SIZE(ttycolors); ++k) {
ttycolors[k] = FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED;
ttycolors_inv[k] = BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_RED;
}
#endif
init_ttycolor_completed = TRUE;
}
#if 0
int
has_color(int color) /* this function is commented out */
{
#ifdef TEXTCOLOR
if ((color >= 0) && (color < CLR_MAX))
return 1;
#else
if ((color == CLR_BLACK) || (color == CLR_WHITE) || (color == NO_COLOR))
return 1;
#endif
else
return 0;
}
#endif
int
term_attr_fixup(int attrmask)
{
return attrmask;
}
void
term_start_attr(int attrib)
{
console.current_nhattr[attrib] = TRUE;
if (attrib) console.current_nhattr[ATR_NONE] = FALSE;
}
void
term_end_attr(int attrib)
{
int k;
switch (attrib) {
case ATR_INVERSE:
case ATR_ULINE:
case ATR_BLINK:
case ATR_BOLD:
break;
}
console.current_nhattr[attrib] = FALSE;
console.current_nhattr[ATR_NONE] = TRUE;
/* re-evaluate all attr now for performance at output time */
for (k=ATR_NONE; k <= ATR_INVERSE; ++k) {
if (console.current_nhattr[k])
console.current_nhattr[ATR_NONE] = FALSE;
}
}
void
term_end_raw_bold(void)
{
term_end_attr(ATR_BOLD);
}
void
term_start_raw_bold(void)
{
term_start_attr(ATR_BOLD);
}
void
term_start_color(int color)
{
#ifdef TEXTCOLOR
if (color >= 0 && color < CLR_MAX) {
console.current_nhcolor = color;
} else
#endif
console.current_nhcolor = NO_COLOR;
}
void
term_end_color(void)
{
#ifdef TEXTCOLOR
console.foreground = DEFTEXTCOLOR;
#endif
console.attr = (console.foreground | console.background);
console.current_nhcolor = NO_COLOR;
}
void
standoutbeg()
{
term_start_attr(ATR_BOLD);
}
void
standoutend()
{
term_end_attr(ATR_BOLD);
}
#ifndef NO_MOUSE_ALLOWED
void
toggle_mouse_support()
{
static int qeinit = 0;
DWORD cmode;
GetConsoleMode(console.hConIn, &cmode);
if (!qeinit) {
qeinit = 1;
orig_QuickEdit = ((cmode & ENABLE_QUICK_EDIT_MODE) != 0);
}
switch(iflags.wc_mouse_support) {
case 2:
cmode |= ENABLE_MOUSE_INPUT;
break;
case 1:
cmode |= ENABLE_MOUSE_INPUT;
cmode &= ~ENABLE_QUICK_EDIT_MODE;
cmode |= ENABLE_EXTENDED_FLAGS;
break;
case 0:
/*FALLTHRU*/
default:
cmode &= ~ENABLE_MOUSE_INPUT;
if (orig_QuickEdit)
cmode |= (ENABLE_QUICK_EDIT_MODE | ENABLE_EXTENDED_FLAGS);
}
SetConsoleMode(console.hConIn, cmode);
}
#endif
/* handle tty options updates here */
void
nttty_preference_update(pref)
const char *pref;
{
if (stricmp(pref, "mouse_support") == 0) {
#ifndef NO_MOUSE_ALLOWED
toggle_mouse_support();
#endif
}
if (stricmp(pref, "symset") == 0)
check_and_set_font();
return;
}
#ifdef PORT_DEBUG
void
win32con_debug_keystrokes()
{
DWORD count;
boolean valid = 0;
int ch;
xputs("\n");
while (!valid || ch != 27) {
nocmov(ttyDisplay->curx, ttyDisplay->cury);
ReadConsoleInput(console.hConIn, &ir, 1, &count);
if ((ir.EventType == KEY_EVENT) && ir.Event.KeyEvent.bKeyDown)
ch = process_keystroke(&ir, &valid, iflags.num_pad, 1);
}
(void) doredraw();
}
void
win32con_handler_info()
{
char *buf;
int ci;
if (!keyboard_handler.pSourceAuthor && !keyboard_handler.pSourceWhere)
pline("Keyboard handler source info and author unavailable.");
else {
if (keyboard_handler.pKeyHandlerName &&
keyboard_handler.pKeyHandlerName(&buf, 1)) {
xputs("\n");
xputs("Keystroke handler loaded: \n ");
xputs(buf);
}
if (keyboard_handler.pSourceAuthor &&
keyboard_handler.pSourceAuthor(&buf)) {
xputs("\n");
xputs("Keystroke handler Author: \n ");
xputs(buf);
}
if (keyboard_handler.pSourceWhere &&
keyboard_handler.pSourceWhere(&buf)) {
xputs("\n");
xputs("Keystroke handler source code available at:\n ");
xputs(buf);
}
xputs("\nPress any key to resume.");
ci = nhgetch();
(void) doredraw();
}
}
void
win32con_toggle_cursor_info()
{
display_cursor_info = !display_cursor_info;
}
#endif
void
map_subkeyvalue(op)
register char *op;
{
char digits[] = "0123456789";
int length, i, idx, val;
char *kp;
idx = -1;
val = -1;
kp = index(op, '/');
if (kp) {
*kp = '\0';
kp++;
length = strlen(kp);
if (length < 1 || length > 3)
return;
for (i = 0; i < length; i++)
if (!index(digits, kp[i]))
return;
val = atoi(kp);
length = strlen(op);
if (length < 1 || length > 3)
return;
for (i = 0; i < length; i++)
if (!index(digits, op[i]))
return;
idx = atoi(op);
}
if (idx >= MAX_OVERRIDES || idx < 0 || val >= MAX_OVERRIDES || val < 1)
return;
key_overrides[idx] = val;
}
void unload_keyboard_handler()
{
nhassert(keyboard_handler.hLibrary != NULL);
FreeLibrary(keyboard_handler.hLibrary);
memset(&keyboard_handler, 0, sizeof(keyboard_handler_t));
}
boolean
load_keyboard_handler(const char * inName)
{
char path[MAX_ALTKEYHANDLER + 4];
strcpy(path, inName);
strcat(path, ".dll");
HANDLE hLibrary = LoadLibrary(path);
if (hLibrary == NULL)
return FALSE;
PROCESS_KEYSTROKE pProcessKeystroke = (PROCESS_KEYSTROKE) GetProcAddress(
hLibrary, TEXT("ProcessKeystroke"));
NHKBHIT pNHkbhit = (NHKBHIT) GetProcAddress(
hLibrary, TEXT("NHkbhit"));
CHECKINPUT pCheckInput =
(CHECKINPUT) GetProcAddress(hLibrary, TEXT("CheckInput"));
if (!pProcessKeystroke || !pNHkbhit || !pCheckInput)
{
return FALSE;
} else {
if (keyboard_handler.hLibrary != NULL)
unload_keyboard_handler();
keyboard_handler.hLibrary = hLibrary;
keyboard_handler.pProcessKeystroke = pProcessKeystroke;
keyboard_handler.pNHkbhit = pNHkbhit;
keyboard_handler.pCheckInput = pCheckInput;
keyboard_handler.pSourceWhere =
(SOURCEWHERE) GetProcAddress(hLibrary, TEXT("SourceWhere"));
keyboard_handler.pSourceAuthor =
(SOURCEAUTHOR) GetProcAddress(hLibrary, TEXT("SourceAuthor"));
keyboard_handler.pKeyHandlerName = (KEYHANDLERNAME) GetProcAddress(
hLibrary, TEXT("KeyHandlerName"));
}
return TRUE;
}
void set_altkeyhandler(const char * inName)
{
if (strlen(inName) >= MAX_ALTKEYHANDLER) {
config_error_add("altkeyhandler name '%s' is too long", inName);
return;
}
char name[MAX_ALTKEYHANDLER];
strcpy(name, inName);
/* We support caller mistakenly giving name with '.dll' extension */
char * ext = strchr(name, '.');
if (ext != NULL) *ext = '\0';
if (load_keyboard_handler(name))
strcpy(iflags.altkeyhandler, name);
else {
config_error_add("unable to load altkeyhandler '%s'", name);
return;
}
return;
}
/* fatal error */
/*VARARGS1*/
void nttty_error
VA_DECL(const char *, s)
{
char buf[BUFSZ];
VA_START(s);
VA_INIT(s, const char *);
/* error() may get called before tty is initialized */
if (iflags.window_inited)
end_screen();
buf[0] = '\n';
(void) vsnprintf(&buf[1], sizeof buf - 1, s, VA_ARGS);
msmsg(buf);
really_move_cursor();
VA_END();
exit(EXIT_FAILURE);
}
void
synch_cursor()
{
really_move_cursor();
}
#ifdef CHANGE_COLOR
void
tty_change_color(color_number, rgb, reverse)
int color_number, reverse;
long rgb;
{
/* Map NetHack color index to NT Console palette index */
int idx, win32_color_number[] = {
0, /* CLR_BLACK 0 */
4, /* CLR_RED 1 */
2, /* CLR_GREEN 2 */
6, /* CLR_BROWN 3 */
1, /* CLR_BLUE 4 */
5, /* CLR_MAGENTA 5 */
3, /* CLR_CYAN 6 */
7, /* CLR_GRAY 7 */
8, /* NO_COLOR 8 */
12, /* CLR_ORANGE 9 */
10, /* CLR_BRIGHT_GREEN 10 */
14, /* CLR_YELLOW 11 */
9, /* CLR_BRIGHT_BLUE 12 */
13, /* CLR_BRIGHT_MAGENTA 13 */
11, /* CLR_BRIGHT_CYAN 14 */
15 /* CLR_WHITE 15 */
};
int k;
if (color_number < 0) { /* indicates OPTIONS=palette with no value */
/* copy the NetHack palette into UserDefinedColors */
for (k = 0; k < CLR_MAX; k++)
UserDefinedColors[k] = NetHackColors[k];
} else if (color_number >= 0 && color_number < CLR_MAX) {
if (!altered_palette) {
/* make sure a full suite is available */
for (k = 0; k < CLR_MAX; k++)
UserDefinedColors[k] = DefaultColors[k];
}
idx = win32_color_number[color_number];
UserDefinedColors[idx] = rgb;
}
altered_palette = TRUE;
}
char *
tty_get_color_string()
{
return "";
}
int
match_color_name(c)
const char *c;
{
const struct others {
int idx;
const char *colorname;
} othernames[] = {
{ CLR_MAGENTA, "purple" },
{ CLR_BRIGHT_MAGENTA, "bright purple" },
{ NO_COLOR, "dark gray" },
{ NO_COLOR, "dark grey" },
{ CLR_GRAY, "grey" },
};
int cnt;
for (cnt = 0; cnt < CLR_MAX; ++cnt) {
if (!strcmpi(c, c_obj_colors[cnt]))
return cnt;
}
for (cnt = 0; cnt < SIZE(othernames); ++cnt) {
if (!strcmpi(c, othernames[cnt].colorname))
return othernames[cnt].idx;
}
return -1;
}
/*
* Returns 0 if badoption syntax
*/
int
alternative_palette(op)
char *op;
{
/*
* palette:color-R-G-B
* OPTIONS=palette:green-4-3-1, palette:0-0-0-0
*/
int fieldcnt, color_number, rgb, red, green, blue;
char *fields[4], *cp;
if (!op) {
change_color(-1, 0, 0); /* indicates palette option with
no value meaning "load an entire
hard-coded NetHack palette." */
return 1;
}
cp = fields[0] = op;
for (fieldcnt = 1; fieldcnt < 4; ++fieldcnt) {
cp = index(cp, '-');
if (!cp)
return 0;
fields[fieldcnt] = cp;
cp++;
}
for (fieldcnt = 1; fieldcnt < 4; ++fieldcnt) {
*(fields[fieldcnt]) = '\0';
++fields[fieldcnt];
}
rgb = 0;
for (fieldcnt = 0; fieldcnt < 4; ++fieldcnt) {
if (fieldcnt == 0 && isalpha(*(fields[0]))) {
color_number = match_color_name(fields[0]);
if (color_number == -1)
return 0;
} else {
int dcount = 0, cval = 0;
cp = fields[fieldcnt];
if (*cp == '\\' && index("0123456789xXoO", cp[1])) {
const char *dp, *hex = "00112233445566778899aAbBcCdDeEfF";
cp++;
if (*cp == 'x' || *cp == 'X')
for (++cp; (dp = index(hex, *cp)) && (dcount++ < 2); cp++)
cval = (int) ((cval * 16) + (dp - hex) / 2);
else if (*cp == 'o' || *cp == 'O')
for (++cp; (index("01234567", *cp)) && (dcount++ < 3);
cp++)
cval = (cval * 8) + (*cp - '0');
else
return 0;
} else {
for (; *cp && (index("0123456789", *cp)) && (dcount++ < 3);
cp++)
cval = (cval * 10) + (*cp - '0');
}
switch (fieldcnt) {
case 0:
color_number = cval;
break;
case 1:
red = cval;
break;
case 2:
green = cval;
break;
case 3:
blue = cval;
break;
}
}
}
rgb = RGB(red, green, blue);
if (color_number >= 0 && color_number < CLR_MAX)
change_color(color_number, rgb, 0);
return 1;
}
/*
* This uses an undocumented method to set console attributes
* at runtime including console palette
*
* VOID WINAPI SetConsolePalette(COLORREF palette[16])
*
* Author: James Brown at www.catch22.net
*
* Set palette of current console.
* Palette should be of the form:
*
* COLORREF DefaultColors[CLR_MAX] =
* {
* 0x00000000, 0x00800000, 0x00008000, 0x00808000,
* 0x00000080, 0x00800080, 0x00008080, 0x00c0c0c0,
* 0x00808080, 0x00ff0000, 0x0000ff00, 0x00ffff00,
* 0x000000ff, 0x00ff00ff, 0x0000ffff, 0x00ffffff
* };
*/
#pragma pack(push, 1)
/*
* Structure to send console via WM_SETCONSOLEINFO
*/
typedef struct _CONSOLE_INFO {
ULONG Length;
COORD ScreenBufferSize;
COORD WindowSize;
ULONG WindowPosX;
ULONG WindowPosY;
COORD FontSize;
ULONG FontFamily;
ULONG FontWeight;
WCHAR FaceName[32];
ULONG CursorSize;
ULONG FullScreen;
ULONG QuickEdit;
ULONG AutoPosition;
ULONG InsertMode;
USHORT ScreenColors;
USHORT PopupColors;
ULONG HistoryNoDup;
ULONG HistoryBufferSize;
ULONG NumberOfHistoryBuffers;
COLORREF ColorTable[16];
ULONG CodePage;
HWND Hwnd;
WCHAR ConsoleTitle[0x100];
} CONSOLE_INFO;
#pragma pack(pop)
BOOL SetConsoleInfo(HWND hwndConsole, CONSOLE_INFO *pci);
static void GetConsoleSizeInfo(CONSOLE_INFO *pci);
VOID WINAPI SetConsolePalette(COLORREF crPalette[16]);
void
adjust_palette(VOID_ARGS)
{
SetConsolePalette(UserDefinedColors);
altered_palette = 0;
}
/*
/* only in Win2k+ (use FindWindow for NT4) */
/* HWND WINAPI GetConsoleWindow(); */
/* Undocumented console message */
#define WM_SETCONSOLEINFO (WM_USER + 201)
VOID WINAPI
SetConsolePalette(COLORREF palette[16])
{
CONSOLE_INFO ci = { sizeof(ci) };
int i;
HWND hwndConsole = GetConsoleHandle();
/* get current size/position settings rather than using defaults.. */
GetConsoleSizeInfo(&ci);
/* set these to zero to keep current settings */
ci.FontSize.X = 0; /* def = 8 */
ci.FontSize.Y = 0; /* def = 12 */
ci.FontFamily = 0; /* def = 0x30 = FF_MODERN|FIXED_PITCH */
ci.FontWeight = 0; /* 0x400; */
/* lstrcpyW(ci.FaceName, L"Terminal"); */
ci.FaceName[0] = L'\0';
ci.CursorSize = 25;
ci.FullScreen = FALSE;
ci.QuickEdit = TRUE;
ci.AutoPosition = 0x10000;
ci.InsertMode = TRUE;
ci.ScreenColors = MAKEWORD(0x7, 0x0);
ci.PopupColors = MAKEWORD(0x5, 0xf);
ci.HistoryNoDup = FALSE;
ci.HistoryBufferSize = 50;
ci.NumberOfHistoryBuffers = 4;
// colour table
for (i = 0; i < 16; i++)
ci.ColorTable[i] = palette[i];
ci.CodePage = GetConsoleOutputCP();
ci.Hwnd = hwndConsole;
lstrcpyW(ci.ConsoleTitle, L"");
SetConsoleInfo(hwndConsole, &ci);
}
/*
* Wrapper around WM_SETCONSOLEINFO. We need to create the
* necessary section (file-mapping) object in the context of the
* process which owns the console, before posting the message
*/
BOOL
SetConsoleInfo(HWND hwndConsole, CONSOLE_INFO *pci)
{
DWORD dwConsoleOwnerPid;
HANDLE hProcess;
HANDLE hSection, hDupSection;
PVOID ptrView = 0;
HANDLE hThread;
/*
* Open the process which "owns" the console
*/
GetWindowThreadProcessId(hwndConsole, &dwConsoleOwnerPid);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwConsoleOwnerPid);
/*
* Create a SECTION object backed by page-file, then map a view of
* this section into the owner process so we can write the contents
* of the CONSOLE_INFO buffer into it
*/
hSection = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0,
pci->Length, 0);
/*
* Copy our console structure into the section-object
*/
ptrView = MapViewOfFile(hSection, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0,
pci->Length);
memcpy(ptrView, pci, pci->Length);
UnmapViewOfFile(ptrView);
/*
* Map the memory into owner process
*/
DuplicateHandle(GetCurrentProcess(), hSection, hProcess, &hDupSection, 0,
FALSE, DUPLICATE_SAME_ACCESS);
/* Send console window the "update" message */
SendMessage(hwndConsole, WM_SETCONSOLEINFO, (WPARAM) hDupSection, 0);
/*
* clean up
*/
hThread = CreateRemoteThread(hProcess, 0, 0,
(LPTHREAD_START_ROUTINE) CloseHandle,
hDupSection, 0, 0);
CloseHandle(hThread);
CloseHandle(hSection);
CloseHandle(hProcess);
return TRUE;
}
/*
* Fill the CONSOLE_INFO structure with information
* about the current console window
*/
static void
GetConsoleSizeInfo(CONSOLE_INFO *pci)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsoleOut, &csbi);
pci->ScreenBufferSize = csbi.dwSize;
pci->WindowSize.X = csbi.srWindow.Right - csbi.srWindow.Left + 1;
pci->WindowSize.Y = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
pci->WindowPosX = csbi.srWindow.Left;
pci->WindowPosY = csbi.srWindow.Top;
}
static HWND
GetConsoleHandle(void)
{
HMODULE hMod = GetModuleHandle("kernel32.dll");
GETCONSOLEWINDOW pfnGetConsoleWindow =
(GETCONSOLEWINDOW) GetProcAddress(hMod, "GetConsoleWindow");
if (pfnGetConsoleWindow)
return pfnGetConsoleWindow();
else
return GetConsoleHwnd();
}
static HWND
GetConsoleHwnd(void)
{
int iterations = 0;
HWND hwndFound = 0;
char OldTitle[1024], NewTitle[1024], TestTitle[1024];
/* Get current window title */
GetConsoleTitle(OldTitle, sizeof OldTitle);
(void) sprintf(NewTitle, "NETHACK%d/%d", GetTickCount(),
GetCurrentProcessId());
SetConsoleTitle(NewTitle);
GetConsoleTitle(TestTitle, sizeof TestTitle);
while (strcmp(TestTitle, NewTitle) != 0) {
iterations++;
/* sleep(0); */
GetConsoleTitle(TestTitle, sizeof TestTitle);
}
hwndFound = FindWindow(NULL, NewTitle);
SetConsoleTitle(OldTitle);
/* printf("%d iterations\n", iterations); */
return hwndFound;
}
#endif /*CHANGE_COLOR*/
static int CALLBACK EnumFontCallback(
const LOGFONTW * lf, const TEXTMETRICW * tm, DWORD fontType, LPARAM lParam)
{
LOGFONTW * lf_ptr = (LOGFONTW *) lParam;
*lf_ptr = *lf;
return 0;
}
/* check_and_set_font ensures that the current font will render the symbols
* that are currently being used correctly. If they will not be rendered
* correctly, then it will change the font to a known good font.
*/
void
check_and_set_font()
{
if (!check_font_widths()) {
raw_print("WARNING: glyphs too wide in console font."
" Changing code page to 437 and font to Consolas\n");
set_known_good_console_font();
}
}
/* check_font_widths returns TRUE if all glyphs in current console font
* fit within the width of a single console cell.
*/
boolean
check_font_widths()
{
CONSOLE_FONT_INFOEX console_font_info;
console_font_info.cbSize = sizeof(console_font_info);
BOOL success = GetCurrentConsoleFontEx(console.hConOut, FALSE,
&console_font_info);
/* get console window and DC
* NOTE: the DC from the console window does not have the correct
* font selected at this point.
*/
HWND hWnd = GetConsoleWindow();
HDC hDC = GetDC(hWnd);
LOGFONTW logical_font;
logical_font.lfCharSet = DEFAULT_CHARSET;
wcscpy(logical_font.lfFaceName, console_font_info.FaceName);
logical_font.lfPitchAndFamily = 0;
/* getting matching console font */
LOGFONTW matching_log_font = { 0 };
EnumFontFamiliesExW(hDC, &logical_font, EnumFontCallback,
(LPARAM) &matching_log_font, 0);
if (matching_log_font.lfHeight == 0) {
raw_print("Unable to enumerate system fonts\n");
return FALSE;
}
/* create font matching console font */
LOGFONTW console_font_log_font = matching_log_font;
console_font_log_font.lfWeight = console_font_info.FontWeight;
console_font_log_font.lfHeight = console_font_info.dwFontSize.Y;
console_font_log_font.lfWidth = console_font_info.dwFontSize.X;
HFONT console_font = CreateFontIndirectW(&console_font_log_font);
if (console_font == NULL) {
raw_print("Unable to create console font\n");
return FALSE;
}
/* select font */
HGDIOBJ saved_font = SelectObject(hDC, console_font);
/* determine whether it is a true type font */
TEXTMETRICA tm;
success = GetTextMetricsA(hDC, &tm);
if (!success) {
raw_print("Unable to get console font text metrics\n");
goto clean_up;
}
boolean isTrueType = (tm.tmPitchAndFamily & TMPF_TRUETYPE) != 0;
/* determine which glyphs are used */
boolean used[256];
memset(used, 0, sizeof(used));
for (int i = 0; i < SYM_MAX; i++) {
used[primary_syms[i]] = TRUE;
used[rogue_syms[i]] = TRUE;
}
int wcUsedCount = 0;
wchar_t wcUsed[256];
for (int i = 0; i < sizeof(used); i++)
if (used[i])
wcUsed[wcUsedCount++] = cp437[i];
/* measure the set of used glyphs to ensure they fit */
boolean all_glyphs_fit = TRUE;
for (int i = 0; i < wcUsedCount; i++) {
int width;
if (isTrueType) {
ABC abc;
success = GetCharABCWidthsW(hDC, wcUsed[i], wcUsed[i], &abc);
width = abc.abcA + abc.abcB + abc.abcC;
} else {
success = GetCharWidthW(hDC, wcUsed[i], wcUsed[i], &width);
}
if (success && width > console_font_info.dwFontSize.X) {
all_glyphs_fit = FALSE;
break;
}
}
clean_up:
SelectObject(hDC, saved_font);
DeleteObject(console_font);
return all_glyphs_fit;
}
/* set_known_good_console_font sets the code page and font used by the console
* to settings know to work well with NetHack. It also saves the original
* settings so that they can be restored prior to NetHack exit.
*/
void
set_known_good_console_font()
{
CONSOLE_FONT_INFOEX console_font_info;
console_font_info.cbSize = sizeof(console_font_info);
BOOL success = GetCurrentConsoleFontEx(console.hConOut, FALSE,
&console_font_info);
console.font_changed = TRUE;
console.original_font_info = console_font_info;
console.original_code_page = GetConsoleOutputCP();
wcscpy_s(console_font_info.FaceName,
sizeof(console_font_info.FaceName)
/ sizeof(console_font_info.FaceName[0]),
L"Consolas");
success = SetConsoleOutputCP(437);
nhassert(success);
success = SetCurrentConsoleFontEx(console.hConOut, FALSE, &console_font_info);
nhassert(success);
}
/* restore_original_console_font will restore the console font and code page
* settings to what they were when NetHack was launched.
*/
void
restore_original_console_font()
{
if (console.font_changed) {
BOOL success;
raw_print("Restoring original font and code page\n");
success = SetConsoleOutputCP(console.original_code_page);
if (!success)
raw_print("Unable to restore original code page\n");
success = SetCurrentConsoleFontEx(console.hConOut, FALSE,
&console.original_font_info);
if (!success)
raw_print("Unable to restore original font\n");
console.font_changed = FALSE;
}
}
/* set_cp_map() creates a mapping of every possible character of a code
* page to its corresponding WCHAR. This is necessary due to the high
* cost of making calls to MultiByteToWideChar() for every character we
* wish to print to the console.
*/
void set_cp_map()
{
if (console.has_unicode) {
UINT codePage = GetConsoleOutputCP();
if (codePage == 437) {
memcpy(console.cpMap, cp437, sizeof(console.cpMap));
} else {
for (int i = 0; i < 256; i++) {
char c = (char)i;
int count = MultiByteToWideChar(codePage, 0, &c, 1,
&console.cpMap[i], 1);
nhassert(count == 1);
// If a character was mapped to unicode control codes,
// remap to the appropriate unicode character per our
// code page 437 mappings.
if (console.cpMap[i] < 32)
console.cpMap[i] = cp437[console.cpMap[i]];
}
}
}
}
#if 0
/* early_raw_print() is used during early game intialization prior to the
* setting up of the windowing system. This allows early errors and panics
* to have there messages displayed.
*
* early_raw_print() eventually gets replaced by tty_raw_print().
*
*/
void early_raw_print(const char *s)
{
if (console.hConOut == NULL)
return;
nhassert(console.cursor.X >= 0 && console.cursor.X < console.width);
nhassert(console.cursor.Y >= 0 && console.cursor.Y < console.height);
WORD attribute = FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE;
DWORD unused;
while (*s != '\0') {
switch (*s) {
case '\n':
if (console.cursor.Y < console.height - 1)
console.cursor.Y++;
/* fall through */
case '\r':
console.cursor.X = 1;
break;
case '\b':
if (console.cursor.X > 1) {
console.cursor.X--;
} else if(console.cursor.Y > 0) {
console.cursor.X = console.width - 1;
console.cursor.Y--;
}
break;
default:
WriteConsoleOutputAttribute(console.hConOut, &attribute,
1, console.cursor, &unused);
WriteConsoleOutputCharacterA(console.hConOut, s,
1, console.cursor, &unused);
if (console.cursor.X == console.width - 1) {
if (console.cursor.Y < console.height - 1) {
console.cursor.X = 1;
console.cursor.Y++;
}
} else {
console.cursor.X++;
}
}
s++;
}
nhassert(console.cursor.X >= 0 && console.cursor.X < console.width);
nhassert(console.cursor.Y >= 0 && console.cursor.Y < console.height);
SetConsoleCursorPosition(console.hConOut, console.cursor);
}
#endif
/* nethack_enter_nttty() is the first thing that is called from main
* once the tty port is confirmed.
*
* We initialize all console state to support rendering to the console
* through out flipping support at this time. This allows us to support
* raw_print prior to our returning.
*
* During this early initialization, we also determine the width and
* height of the console that will be used. This width and height will
* not later change.
*
* We also check and set the console font to a font that we know will work
* well with nethack.
*
* The intent of this early initialization is to get all state that is
* not dependent upon game options initialized allowing us to simplify
* any additional initialization that might be needed when we are actually
* asked to open.
*
* Other then the call below which clears the entire console buffer, no
* other code outputs directly to the console other then the code that
* handles flipping the back buffer.
*
*/
void nethack_enter_nttty()
{
#if 0
/* set up state needed by early_raw_print() */
windowprocs.win_raw_print = early_raw_print;
#endif
console.hConOut = GetStdHandle(STD_OUTPUT_HANDLE);
nhassert(console.hConOut != NULL); // NOTE: this assert will not print
GetConsoleScreenBufferInfo(console.hConOut, &console.origcsbi);
/* Testing of widths != COLNO has not turned up any problems. Need
* to do a bit more testing and then we are likely to enable having
* console width match window width.
*/
#if 0
console.width = console.origcsbi.srWindow.Right -
console.origcsbi.srWindow.Left + 1;
console.Width = max(console.Width, COLNO);
#else
console.width = COLNO;
#endif
console.height = console.origcsbi.srWindow.Bottom -
console.origcsbi.srWindow.Top + 1;
console.height = max(console.height, ROWNO + 3);
console.buffer_size = console.width * console.height;
/* clear the entire console buffer */
int size = console.origcsbi.dwSize.X * console.origcsbi.dwSize.Y;
DWORD unused;
set_console_cursor(0, 0);
FillConsoleOutputAttribute(
console.hConOut, CONSOLE_CLEAR_ATTRIBUTE,
size, console.cursor, &unused);
FillConsoleOutputCharacter(
console.hConOut, CONSOLE_CLEAR_CHARACTER,
size, console.cursor, &unused);
set_console_cursor(1, 0);
SetConsoleCursorPosition(console.hConOut, console.cursor);
/* At this point early_raw_print will work */
console.hConIn = GetStdHandle(STD_INPUT_HANDLE);
nhassert(console.hConIn != NULL);
/* grow the size of the console buffer if it is not wide enough */
if (console.origcsbi.dwSize.X < console.width) {
COORD size = {
size.Y = console.origcsbi.dwSize.Y,
size.X = console.width
};
SetConsoleScreenBufferSize(console.hConOut, size);
}
/* setup front and back buffers */
int buffer_size_bytes = sizeof(cell_t) * console.buffer_size;
console.front_buffer = (cell_t *)malloc(buffer_size_bytes);
buffer_fill_to_end(console.front_buffer, &undefined_cell, 0, 0);
console.back_buffer = (cell_t *)malloc(buffer_size_bytes);
buffer_fill_to_end(console.back_buffer, &clear_cell, 0, 0);
/* determine whether OS version has unicode support */
console.has_unicode = ((GetVersion() & 0x80000000) == 0);
/* check the font before we capture the code page map */
check_and_set_font();
set_cp_map();
/* Set console mode */
DWORD cmode, mask;
GetConsoleMode(console.hConIn, &cmode);
#ifdef NO_MOUSE_ALLOWED
mask = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | ENABLE_MOUSE_INPUT
| ENABLE_ECHO_INPUT | ENABLE_WINDOW_INPUT;
#else
mask = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT
| ENABLE_WINDOW_INPUT;
#endif
/* Turn OFF the settings specified in the mask */
cmode &= ~mask;
#ifndef NO_MOUSE_ALLOWED
cmode |= ENABLE_MOUSE_INPUT;
#endif
SetConsoleMode(console.hConIn, cmode);
/* load default keyboard handler */
HKL keyboard_layout = GetKeyboardLayout(0);
DWORD primary_language = (UINT_PTR) keyboard_layout & 0x3f;
/* This was overriding the handler that had already
been loaded during options parsing. Needs to
check first */
if (!iflags.altkeyhandler[0]) {
if (primary_language == LANG_ENGLISH) {
if (!load_keyboard_handler("nhdefkey"))
error("Unable to load nhdefkey.dll");
} else {
if (!load_keyboard_handler("nhraykey"))
error("Unable to load nhraykey.dll");
}
}
}
#endif /* TTY_GRAPHICS */
/* this is used as a printf() replacement when the window
* system isn't initialized yet
*/
void msmsg
VA_DECL(const char *, fmt)
{
char buf[ROWNO * COLNO]; /* worst case scenario */
VA_START(fmt);
VA_INIT(fmt, const char *);
(void) vsnprintf(buf, sizeof buf, fmt, VA_ARGS);
if (redirect_stdout)
fprintf(stdout, "%s", buf);
else {
#ifdef TTY_GRAPHICS
if(!init_ttycolor_completed)
init_ttycolor();
/* if we have generated too many messages ... ask the user to
* confirm and then clear.
*/
if (console.cursor.Y > console.height - 4) {
xputs("Hit <Enter> to continue.");
while (pgetchar() != '\n')
;
raw_clear_screen();
set_console_cursor(1, 0);
}
xputs(buf);
if (ttyDisplay)
curs(BASE_WINDOW, console.cursor.X + 1, console.cursor.Y);
#else
fprintf(stdout, "%s", buf);
#endif
}
VA_END();
return;
}
#endif /* WIN32 */
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.