file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/50138004.c | *a, *e;
b, c, d, f;
g() {
int h;
for (;;) {
for (; b;) {
e = a;
break;
}
if (e)
break;
h++;
}
for (; c;) {
f = &d + h;
i();
h++;
}
f = &d + h;
j(f, h);
}
|
the_stack_data/11074661.c | /*
* NTP_Client.c
*
* Created on: 2016年11月20日
* Author: morris
* 要求:
* 网络编程之---NTP客户端程序
* 本程序需要使用超级用户权限运行,测试方法:
* a. 为本地设定一个错误的时间:sudo date -s "2001-01-01 1:00:00"
* b. 运行本程序
* ********************************************************************s
*/
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
#define NTP_PORT_STR "123"//NTP协议专用端口号
#define NTP_SERVER_ADDR_STR "ntp.suda.edu.cn"//NTP服务器地址
#define TIME_OUT (10)//一次NTP时间同步延迟最长时间10s
#define NTP_PCK_LEN (48)//NTP协议数据报长度
#define LI (0)//警告在当月的最后一天的最终时刻插入的迫近闰秒
#define VN (3)//版本号
#define MODE (3)//工作模式
#define STRATUM (0)//对本地时钟的整体识别
#define POLL (4)//连续信息间的最大间隔
#define PREC (-6)//本地时钟精确度
#define JAN_1970 (0x83aa7e80)//从1900年到1970年的时间秒数
#define NTPFRAC(x) (4294*(x)-759*((((x)>>10)+32768)>>16))
#define USEC(x) (((x)>>12)-759*((((x)>>10)+32768)>>16))
typedef struct _ntp_time {
unsigned int coarse;
unsigned int fine;
} ntp_time;
struct ntp_packet {
unsigned char leap_ver_mode;
unsigned char startum;
char poll;
char precision;
int root_delay;
int root_dispersion;
int reference_identifier;
ntp_time reference_timestamp;
ntp_time originage_timestamp;
ntp_time receive_timestamp;
ntp_time transmit_timestamp;
};
/* 构造NTP协议包 */
int construct_packet(char* packet) {
long tmp_wrd;
time_t timer;
memset(packet, 0, NTP_PCK_LEN);
/* 设置16字节的包头 */
tmp_wrd = htonl(
(LI << 30) | (VN << 27) | (MODE << 24) | (STRATUM << 16)
| (POLL << 8) | (PREC & 0xff));
memcpy(packet, &tmp_wrd, sizeof(tmp_wrd));
/* 设置Root Delay,Root Dispersion和Reference Indentifier */
tmp_wrd = htonl(1 << 16);
memcpy(&packet[4], &tmp_wrd, sizeof(tmp_wrd));
memcpy(&packet[8], &tmp_wrd, sizeof(tmp_wrd));
/* 设置Timestamp部分 */
time(&timer);
/* 设置Transmit Timestamp coarse */
tmp_wrd = htonl(JAN_1970 + (long) timer);
memcpy(&packet[40], &tmp_wrd, sizeof(tmp_wrd));
/* 设置Transmit Timestamp fine */
tmp_wrd = htonl((long) NTPFRAC(timer));
memcpy(&packet[44], &tmp_wrd, sizeof(tmp_wrd));
return NTP_PCK_LEN;
}
/* 通过网络从NTP服务器获取NTP时间 */
int get_ntp_time(int socket_fd, struct addrinfo* addr,
struct ntp_packet *ret_time) {
fd_set inset;
struct timeval tv;
char buf[NTP_PCK_LEN * 2];
int addr_len = addr->ai_addrlen;
int packet_len;
int real_send, real_read;
int ret;
/* 构造NTP协议包 */
packet_len = construct_packet(buf);
if (packet_len == 0) {
printf("construct_packet error\r\n");
return -1;
}
/* 将NTP协议数据包发送给NTP服务器 */
real_send = sendto(socket_fd, buf, packet_len, 0, addr->ai_addr, addr_len);
if (real_send < 0) {
perror("sendto");
return -1;
}
/* 使用select函数监听,设定超时时间 */
FD_ZERO(&inset);
FD_SET(socket_fd, &inset);
tv.tv_sec = TIME_OUT;
tv.tv_usec = 0;
ret = select(socket_fd + 1, &inset, NULL, NULL, &tv);
if (ret < 0) {
perror("select");
return -1;
} else if (ret == 0) {
printf("Time-out\r\n");
return -1;
}
/* 接收服务器的响应数据 */
real_read = recvfrom(socket_fd, buf, sizeof(buf), 0, addr->ai_addr,
(socklen_t*) &addr_len);
if (real_read < 0) {
printf("recvfrom error\r\n");
return -1;
}
if (real_read < NTP_PCK_LEN) {
printf("Receive packet wrong\r\n");
return -1;
}
/* 设置接收NTP协议数据包的数据结构 */
ret_time->leap_ver_mode = ntohl(buf[0]);
ret_time->startum = ntohl(buf[1]);
ret_time->poll = ntohl(buf[2]);
ret_time->precision = ntohl(buf[3]);
ret_time->root_delay = ntohl(*(int*) &(buf[4]));
ret_time->root_dispersion = ntohl(*(int*) &(buf[8]));
ret_time->reference_identifier = ntohl(*(int*) &(buf[12]));
ret_time->reference_timestamp.coarse = ntohl(*(int*) &(buf[16]));
ret_time->reference_timestamp.fine = ntohl(*(int*) &(buf[20]));
ret_time->originage_timestamp.coarse = ntohl(*(int*) &(buf[24]));
ret_time->originage_timestamp.fine = ntohl(*(int*) &(buf[28]));
ret_time->receive_timestamp.coarse = ntohl(*(int*) &(buf[32]));
ret_time->receive_timestamp.fine = ntohl(*(int*) &(buf[36]));
ret_time->transmit_timestamp.coarse = ntohl(*(int*) &(buf[40]));
ret_time->transmit_timestamp.fine = ntohl(*(int*) &(buf[44]));
return 0;
}
/* 根据NTP数据包信息更新本地的当前时间 */
int set_local_time(struct ntp_packet* pnew_time_packet) {
struct timeval tv;
tv.tv_sec = pnew_time_packet->transmit_timestamp.coarse - JAN_1970;
tv.tv_usec = USEC(pnew_time_packet->transmit_timestamp.fine);
return settimeofday(&tv, NULL);
}
int main(int argc, char **argv) {
int sockfd;
struct addrinfo hints, *res = NULL;
struct ntp_packet new_time_packet;
int ret;
/* 获取NTP服务器地址信息 */
hints.ai_family = AF_UNSPEC; //IPV4,IPv6都行
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP;
ret = getaddrinfo(NTP_SERVER_ADDR_STR, NTP_PORT_STR, &hints, &res);
if (ret != 0) {
perror("getaddrinfo");
exit(1);
}
/* 打印NTP服务器的IP地址信息 */
printf("NTP server address:%s\r\n",
inet_ntoa(((struct sockaddr_in*) res->ai_addr)->sin_addr));
/* 创建套接字 */
sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
if (sockfd < 0) {
perror("socket");
exit(1);
}
/* 从NTP服务器获取时间 */
ret = get_ntp_time(sockfd, res, &new_time_packet);
if (ret < 0) {
printf("get_ntp_time error\r\n");
exit(1);
}
/* 调整本地时间 */
ret = set_local_time(&new_time_packet);
if (ret == 0) {
printf("NTP client success\r\n");
} else {
printf("set_local_time error,try sudo...\r\n");
exit(1);
}
close(sockfd);
return 0;
}
|
the_stack_data/161079768.c | /* f2c.h -- Standard Fortran to C header file */
/** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
- From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
#ifndef F2C_INCLUDE
#define F2C_INCLUDE
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimag(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle() continue;
#define myceiling(w) {ceil(w)}
#define myhuge(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* Table of constant values */
static integer c__1 = 1;
static integer c_n1 = -1;
static integer c__3 = 3;
static integer c__2 = 2;
/* > \brief \b STZRZF */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download STZRZF + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/stzrzf.
f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/stzrzf.
f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/stzrzf.
f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* SUBROUTINE STZRZF( M, N, A, LDA, TAU, WORK, LWORK, INFO ) */
/* INTEGER INFO, LDA, LWORK, M, N */
/* REAL A( LDA, * ), TAU( * ), WORK( * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > STZRZF reduces the M-by-N ( M<=N ) real upper trapezoidal matrix A */
/* > to upper triangular form by means of orthogonal transformations. */
/* > */
/* > The upper trapezoidal matrix A is factored as */
/* > */
/* > A = ( R 0 ) * Z, */
/* > */
/* > where Z is an N-by-N orthogonal matrix and R is an M-by-M upper */
/* > triangular matrix. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] M */
/* > \verbatim */
/* > M is INTEGER */
/* > The number of rows of the matrix A. M >= 0. */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The number of columns of the matrix A. N >= M. */
/* > \endverbatim */
/* > */
/* > \param[in,out] A */
/* > \verbatim */
/* > A is REAL array, dimension (LDA,N) */
/* > On entry, the leading M-by-N upper trapezoidal part of the */
/* > array A must contain the matrix to be factorized. */
/* > On exit, the leading M-by-M upper triangular part of A */
/* > contains the upper triangular matrix R, and elements M+1 to */
/* > N of the first M rows of A, with the array TAU, represent the */
/* > orthogonal matrix Z as a product of M elementary reflectors. */
/* > \endverbatim */
/* > */
/* > \param[in] LDA */
/* > \verbatim */
/* > LDA is INTEGER */
/* > The leading dimension of the array A. LDA >= f2cmax(1,M). */
/* > \endverbatim */
/* > */
/* > \param[out] TAU */
/* > \verbatim */
/* > TAU is REAL array, dimension (M) */
/* > The scalar factors of the elementary reflectors. */
/* > \endverbatim */
/* > */
/* > \param[out] WORK */
/* > \verbatim */
/* > WORK is REAL array, dimension (MAX(1,LWORK)) */
/* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
/* > \endverbatim */
/* > */
/* > \param[in] LWORK */
/* > \verbatim */
/* > LWORK is INTEGER */
/* > The dimension of the array WORK. LWORK >= f2cmax(1,M). */
/* > For optimum performance LWORK >= M*NB, where NB is */
/* > the optimal blocksize. */
/* > */
/* > If LWORK = -1, then a workspace query is assumed; the routine */
/* > only calculates the optimal size of the WORK array, returns */
/* > this value as the first entry of the WORK array, and no error */
/* > message related to LWORK is issued by XERBLA. */
/* > \endverbatim */
/* > */
/* > \param[out] INFO */
/* > \verbatim */
/* > INFO is INTEGER */
/* > = 0: successful exit */
/* > < 0: if INFO = -i, the i-th argument had an illegal value */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date April 2012 */
/* > \ingroup realOTHERcomputational */
/* > \par Contributors: */
/* ================== */
/* > */
/* > A. Petitet, Computer Science Dept., Univ. of Tenn., Knoxville, USA */
/* > \par Further Details: */
/* ===================== */
/* > */
/* > \verbatim */
/* > */
/* > The N-by-N matrix Z can be computed by */
/* > */
/* > Z = Z(1)*Z(2)* ... *Z(M) */
/* > */
/* > where each N-by-N Z(k) is given by */
/* > */
/* > Z(k) = I - tau(k)*v(k)*v(k)**T */
/* > */
/* > with v(k) is the kth row vector of the M-by-N matrix */
/* > */
/* > V = ( I A(:,M+1:N) ) */
/* > */
/* > I is the M-by-M identity matrix, A(:,M+1:N) */
/* > is the output stored in A on exit from DTZRZF, */
/* > and tau(k) is the kth element of the array TAU. */
/* > */
/* > \endverbatim */
/* > */
/* ===================================================================== */
/* Subroutine */ int stzrzf_(integer *m, integer *n, real *a, integer *lda,
real *tau, real *work, integer *lwork, integer *info)
{
/* System generated locals */
integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5;
/* Local variables */
integer i__, nbmin, m1, ib, nb, ki, kk, mu, nx;
extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen);
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
integer *, integer *, ftnlen, ftnlen);
extern /* Subroutine */ int slarzb_(char *, char *, char *, char *,
integer *, integer *, integer *, integer *, real *, integer *,
real *, integer *, real *, integer *, real *, integer *);
integer lwkmin, ldwork, lwkopt;
logical lquery;
extern /* Subroutine */ int slarzt_(char *, char *, integer *, integer *,
real *, integer *, real *, real *, integer *),
slatrz_(integer *, integer *, integer *, real *, integer *, real *
, real *);
integer iws;
/* -- LAPACK computational routine (version 3.7.0) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* April 2012 */
/* ===================================================================== */
/* Test the input arguments */
/* Parameter adjustments */
a_dim1 = *lda;
a_offset = 1 + a_dim1 * 1;
a -= a_offset;
--tau;
--work;
/* Function Body */
*info = 0;
lquery = *lwork == -1;
if (*m < 0) {
*info = -1;
} else if (*n < *m) {
*info = -2;
} else if (*lda < f2cmax(1,*m)) {
*info = -4;
}
if (*info == 0) {
if (*m == 0 || *m == *n) {
lwkopt = 1;
lwkmin = 1;
} else {
/* Determine the block size. */
nb = ilaenv_(&c__1, "SGERQF", " ", m, n, &c_n1, &c_n1, (ftnlen)6,
(ftnlen)1);
lwkopt = *m * nb;
lwkmin = f2cmax(1,*m);
}
work[1] = (real) lwkopt;
if (*lwork < lwkmin && ! lquery) {
*info = -7;
}
}
if (*info != 0) {
i__1 = -(*info);
xerbla_("STZRZF", &i__1, (ftnlen)6);
return 0;
} else if (lquery) {
return 0;
}
/* Quick return if possible */
if (*m == 0) {
return 0;
} else if (*m == *n) {
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
tau[i__] = 0.f;
/* L10: */
}
return 0;
}
nbmin = 2;
nx = 1;
iws = *m;
if (nb > 1 && nb < *m) {
/* Determine when to cross over from blocked to unblocked code. */
/* Computing MAX */
i__1 = 0, i__2 = ilaenv_(&c__3, "SGERQF", " ", m, n, &c_n1, &c_n1, (
ftnlen)6, (ftnlen)1);
nx = f2cmax(i__1,i__2);
if (nx < *m) {
/* Determine if workspace is large enough for blocked code. */
ldwork = *m;
iws = ldwork * nb;
if (*lwork < iws) {
/* Not enough workspace to use optimal NB: reduce NB and */
/* determine the minimum value of NB. */
nb = *lwork / ldwork;
/* Computing MAX */
i__1 = 2, i__2 = ilaenv_(&c__2, "SGERQF", " ", m, n, &c_n1, &
c_n1, (ftnlen)6, (ftnlen)1);
nbmin = f2cmax(i__1,i__2);
}
}
}
if (nb >= nbmin && nb < *m && nx < *m) {
/* Use blocked code initially. */
/* The last kk rows are handled by the block method. */
/* Computing MIN */
i__1 = *m + 1;
m1 = f2cmin(i__1,*n);
ki = (*m - nx - 1) / nb * nb;
/* Computing MIN */
i__1 = *m, i__2 = ki + nb;
kk = f2cmin(i__1,i__2);
i__1 = *m - kk + 1;
i__2 = -nb;
for (i__ = *m - kk + ki + 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1;
i__ += i__2) {
/* Computing MIN */
i__3 = *m - i__ + 1;
ib = f2cmin(i__3,nb);
/* Compute the TZ factorization of the current block */
/* A(i:i+ib-1,i:n) */
i__3 = *n - i__ + 1;
i__4 = *n - *m;
slatrz_(&ib, &i__3, &i__4, &a[i__ + i__ * a_dim1], lda, &tau[i__],
&work[1]);
if (i__ > 1) {
/* Form the triangular factor of the block reflector */
/* H = H(i+ib-1) . . . H(i+1) H(i) */
i__3 = *n - *m;
slarzt_("Backward", "Rowwise", &i__3, &ib, &a[i__ + m1 *
a_dim1], lda, &tau[i__], &work[1], &ldwork);
/* Apply H to A(1:i-1,i:n) from the right */
i__3 = i__ - 1;
i__4 = *n - i__ + 1;
i__5 = *n - *m;
slarzb_("Right", "No transpose", "Backward", "Rowwise", &i__3,
&i__4, &ib, &i__5, &a[i__ + m1 * a_dim1], lda, &work[
1], &ldwork, &a[i__ * a_dim1 + 1], lda, &work[ib + 1],
&ldwork)
;
}
/* L20: */
}
mu = i__ + nb - 1;
} else {
mu = *m;
}
/* Use unblocked code to factor the last or only block */
if (mu > 0) {
i__2 = *n - *m;
slatrz_(&mu, n, &i__2, &a[a_offset], lda, &tau[1], &work[1]);
}
work[1] = (real) lwkopt;
return 0;
/* End of STZRZF */
} /* stzrzf_ */
|
the_stack_data/15762086.c | /*
* This code was written by Rich Felker in 2010; no copyright is claimed.
* This code is in the public domain. Attribution is appreciated but
* unnecessary.
*/
#include <stdlib.h>
int mblen(const char *s, size_t n)
{
return mbtowc(0, s, n);
}
|
the_stack_data/225143563.c | //a program in c to check alphabet or not
//testcase1,2,3: input:A input:a input:?
// output:ALPHABET output:ALPHABET output: NOT AN ALPHABET
#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
printf("%c ALPHABET", c);
else
printf("%c NOT AN ALPHABET.", c);
return 0;
} |
the_stack_data/104828365.c | /******************************************************************************/
/* */
/* Copyright (c) 2009 FUJITSU LIMITED */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
/* the GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
/* */
/* Author: Miao Xie <[email protected]> */
/* Restructure for LTP: Shi Weihua <[email protected]> */
/* */
/******************************************************************************/
/*++ simple_echo.c
*
* DESCRIPTION:
* The command "echo" can't return the errno. So we write this program to
* instead of "echo".
*
* Author:
* -------
* 2008/04/17 created by Miao Xie@FNST
*
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int fd = 1;
if (argc != 2 && argc != 3) {
fprintf(stderr, "usage: %s STRING [ostream]\n",
basename(argv[0]));
exit(1);
}
if (argc == 3)
if ((fd = open(argv[2], O_RDWR | O_SYNC)) == -1)
err(errno, "%s", argv[2]);
if (write(fd, argv[1], strlen(argv[1])) == -1)
err(errno, "write error");
if (fd != 1)
if (close(fd) == -1)
err(errno, "close error");
return 0;
}
|
the_stack_data/142255.c | /* Example: analysis of text */
#include <stdio.h>
#include <string.h>
#define MAX 1000 /* The maximum number of characters in a line of input */
main()
{
char text[MAX], c;
int i;
int lowercase, uppercase, digits, other;
puts("Type some text (then ENTER):");
/* Save typed characters in text[]: */
fgets(text, MAX, stdin);
/* Analyse contents of text[]: */
for (i = lowercase = uppercase = digits = other = 0; i < MAX; i++)
{
c = text[i];
if (c >= 'a' && c <= 'z')
lowercase++;
else if (c >= 'A' && c <= 'Z')
uppercase++;
else if (c >= '0' && c <= '9')
digits++;
else
{
if (c == '\n')
break;
other++;
}
}
puts("\nYou typed:");
printf("A string with %d characters\n", (int) strlen(text) - 1);
printf("\t%d lower case letters\n", lowercase);
printf("\t%d upper case letters\n", uppercase);
printf("\t%d digits\n", digits);
printf("\t%d others\n", other);
}
|
the_stack_data/181392922.c | //CS 539, At home practice midterm 2 speed programming for study. 1 hour started already. Rob Lamog
#include <stdio.h>
#include <stdlib.h>
double boxArea(double length, double width, double height);
void stats(double * mn, double * av, double * mx, double x, double y, double z);
double aveOdd(const unsigned a[], unsigned els);
void reverse(double * begin, double * end);
unsigned howMany(char c, const char * s);
int die (const char* msg);
int main() {
double a, b, c;
unsigned d[] = {1, 22, 3, 44, 5, 1};
double e[] = {1.1, 2.2, 3.3};
char* s = "Jack and Jill.";
printf("%lf\n", boxArea(3, 3, 3));
stats(&a, &b, &c, 7, 2, 3);
printf("%lf %lf %lf\n", a, b, c);
printf("%lf\n", aveOdd(d, 6));
reverse(e, e + 3);
printf("%lf %lf %lf\n", e[0], e[1], e[2]);
printf("%u\n", howMany('J', s));
return 0;
}
double boxArea(double length, double width, double height){
return 2 * ((length * width) + (width * height) + (height * length));
}
void stats(double * mn, double * av, double * mx, double x, double y, double z){
if ((x < y) && (x < z)) *mn = x;
else if ((y < x) && (y < z)) *mn = y;
else *mn = z;
*av = (x + y + z) / 3;
if ((x > y) && (x > z)) *mx = x;
else if ((y > x) && (y > z)) *mx = y;
else *mx = z;
}
double aveOdd(const unsigned a[], unsigned els){
double average = 0.0;
unsigned oddCount = 0;
unsigned i = 0;
for (i; i < els; ++i){
if (a[i] % 2 != 0){
average += a[i];
oddCount++;
}
}
return average / oddCount;
}
void reverse(double * begin, double * end){ //Brute force it. Loop through and flip each location. end - begin == number of elements
double temp = 0;
unsigned els = end - begin;
unsigned i = 0;
for (i; i < els / 2; ++i){
temp = *(begin + i);
*(begin + i) = *(begin + (els - 1 - i));
*(begin + (els - 1 - i)) = temp;
}
}
unsigned howMany(char c, const char * s){
static unsigned retVal; //Must remember to use static var
if (*s){
if (*s == c) retVal++;
howMany(c, (s + 1));
}
return retVal;
}
int die(const char* msg){
printf("Fatal error: %s.\n", msg);
exit(EXIT_FAILURE);
} |
the_stack_data/92328875.c | #include <stdio.h>
void bubble_sort(int arr[], int N)
{
int round, i, temp, flag;
for (round = 1; round < N - 1; round++)
{
flag = 0;
for (i = 0; i <= N - 1 - round; i++)
{
if (arr[i] > arr[i + 1])
{
flag = 1;
temp = arr[i];
arr[i] = arr[i + 1];
arr[i + 1] = temp;
}
}
if (flag == 0)
return;
}
}
int main()
{
int arr[] = {9, 11, 24, 36, 58, 49, 35, 28, 65, 8, 69, 55};
int i;
int size = sizeof(arr) / sizeof(arr[0]);
bubble_sort(arr, 12);
for (i = 0; i <= 11; i++)
printf(" %d ", arr[i]);
return 0;
}
|
the_stack_data/7951408.c | /*
The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given array.
1) The subarray which is already sorted.
2) Remaining subarray which is unsorted.
In every iteration of selection sort, the minimum element (considering ascending order) from the unsorted subarray is picked and moved to the sorted subarray.
*/
#include <stdio.h>
//This will swap the values of the two variables passed to the function
void swaping(int *a, int *b)
{
int tmp = *a;
*a = *b;
*b = tmp;
}
void selection_sort(int *a, int n)
{
int i, j, index;
// One by one move of element
for (i = 0; i < n - 1; i++)
{
// Find the minimum element in unsorted array
index = i;
for (j = i + 1; j < n; j++)
{
if (a[j] < a[index])
index = j;
}
// Swap the found minimum element with the first element
swaping(&a[index], &a[i]);
}
}
int main()
{
int n, i;
printf("Enter the no of element:");
scanf("%d", &n);
int a[n];
//Taking array input's
printf("Enter the element of array:-\n");
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
selection_sort(a, n);
//Array after sorting is done
printf("Sorted Array:\n");
for (i = 0; i < n; i++)
printf("%d ", a[i]);
}
/*
Time Complexity: O(n*2)
Space Complexity: O(1)
Output:
Enter the no of element:10
Enter the element of array:-
32 323 4 34 341291 343483 32323 34 446
Sorted Array:
4 32 34 34 323 446 7856 32323 341291
*/ |
the_stack_data/128544.c | /**
******************************************************************************
* @file stm32l1xx_ll_usart.c
* @author MCD Application Team
* @brief USART LL module driver.
******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
*
* 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 STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
#if defined(USE_FULL_LL_DRIVER)
/* Includes ------------------------------------------------------------------*/
#include "stm32l1xx_ll_usart.h"
#include "stm32l1xx_ll_rcc.h"
#include "stm32l1xx_ll_bus.h"
#ifdef USE_FULL_ASSERT
#include "stm32_assert.h"
#else
#define assert_param(expr) ((void)0U)
#endif
/** @addtogroup STM32L1xx_LL_Driver
* @{
*/
#if defined (USART1) || defined (USART2) || defined (USART3) || defined (UART4) || defined (UART5)
/** @addtogroup USART_LL
* @{
*/
/* Private types -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private constants ---------------------------------------------------------*/
/** @addtogroup USART_LL_Private_Constants
* @{
*/
/**
* @}
*/
/* Private macros ------------------------------------------------------------*/
/** @addtogroup USART_LL_Private_Macros
* @{
*/
/* __BAUDRATE__ The maximum Baud Rate is derived from the maximum clock available
* divided by the smallest oversampling used on the USART (i.e. 8) */
#define IS_LL_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 10000000U)
#define IS_LL_USART_DIRECTION(__VALUE__) (((__VALUE__) == LL_USART_DIRECTION_NONE) \
|| ((__VALUE__) == LL_USART_DIRECTION_RX) \
|| ((__VALUE__) == LL_USART_DIRECTION_TX) \
|| ((__VALUE__) == LL_USART_DIRECTION_TX_RX))
#define IS_LL_USART_PARITY(__VALUE__) (((__VALUE__) == LL_USART_PARITY_NONE) \
|| ((__VALUE__) == LL_USART_PARITY_EVEN) \
|| ((__VALUE__) == LL_USART_PARITY_ODD))
#define IS_LL_USART_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_USART_DATAWIDTH_8B) \
|| ((__VALUE__) == LL_USART_DATAWIDTH_9B))
#define IS_LL_USART_OVERSAMPLING(__VALUE__) (((__VALUE__) == LL_USART_OVERSAMPLING_16) \
|| ((__VALUE__) == LL_USART_OVERSAMPLING_8))
#define IS_LL_USART_LASTBITCLKOUTPUT(__VALUE__) (((__VALUE__) == LL_USART_LASTCLKPULSE_NO_OUTPUT) \
|| ((__VALUE__) == LL_USART_LASTCLKPULSE_OUTPUT))
#define IS_LL_USART_CLOCKPHASE(__VALUE__) (((__VALUE__) == LL_USART_PHASE_1EDGE) \
|| ((__VALUE__) == LL_USART_PHASE_2EDGE))
#define IS_LL_USART_CLOCKPOLARITY(__VALUE__) (((__VALUE__) == LL_USART_POLARITY_LOW) \
|| ((__VALUE__) == LL_USART_POLARITY_HIGH))
#define IS_LL_USART_CLOCKOUTPUT(__VALUE__) (((__VALUE__) == LL_USART_CLOCK_DISABLE) \
|| ((__VALUE__) == LL_USART_CLOCK_ENABLE))
#define IS_LL_USART_STOPBITS(__VALUE__) (((__VALUE__) == LL_USART_STOPBITS_0_5) \
|| ((__VALUE__) == LL_USART_STOPBITS_1) \
|| ((__VALUE__) == LL_USART_STOPBITS_1_5) \
|| ((__VALUE__) == LL_USART_STOPBITS_2))
#define IS_LL_USART_HWCONTROL(__VALUE__) (((__VALUE__) == LL_USART_HWCONTROL_NONE) \
|| ((__VALUE__) == LL_USART_HWCONTROL_RTS) \
|| ((__VALUE__) == LL_USART_HWCONTROL_CTS) \
|| ((__VALUE__) == LL_USART_HWCONTROL_RTS_CTS))
/**
* @}
*/
/* Private function prototypes -----------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
/** @addtogroup USART_LL_Exported_Functions
* @{
*/
/** @addtogroup USART_LL_EF_Init
* @{
*/
/**
* @brief De-initialize USART registers (Registers restored to their default values).
* @param USARTx USART Instance
* @retval An ErrorStatus enumeration value:
* - SUCCESS: USART registers are de-initialized
* - ERROR: USART registers are not de-initialized
*/
ErrorStatus LL_USART_DeInit(USART_TypeDef *USARTx)
{
ErrorStatus status = SUCCESS;
/* Check the parameters */
assert_param(IS_UART_INSTANCE(USARTx));
if (USARTx == USART1)
{
/* Force reset of USART clock */
LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_USART1);
/* Release reset of USART clock */
LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_USART1);
}
else if (USARTx == USART2)
{
/* Force reset of USART clock */
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART2);
/* Release reset of USART clock */
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART2);
}
else if (USARTx == USART3)
{
/* Force reset of USART clock */
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_USART3);
/* Release reset of USART clock */
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_USART3);
}
#if defined(UART4)
else if (USARTx == UART4)
{
/* Force reset of UART clock */
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART4);
/* Release reset of UART clock */
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART4);
}
#endif /* UART4 */
#if defined(UART5)
else if (USARTx == UART5)
{
/* Force reset of UART clock */
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_UART5);
/* Release reset of UART clock */
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_UART5);
}
#endif /* UART5 */
else
{
status = ERROR;
}
return (status);
}
/**
* @brief Initialize USART registers according to the specified
* parameters in USART_InitStruct.
* @note As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0),
* USART IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
* @note Baud rate value stored in USART_InitStruct BaudRate field, should be valid (different from 0).
* @param USARTx USART Instance
* @param USART_InitStruct: pointer to a LL_USART_InitTypeDef structure
* that contains the configuration information for the specified USART peripheral.
* @retval An ErrorStatus enumeration value:
* - SUCCESS: USART registers are initialized according to USART_InitStruct content
* - ERROR: Problem occurred during USART Registers initialization
*/
ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, LL_USART_InitTypeDef *USART_InitStruct)
{
ErrorStatus status = ERROR;
uint32_t periphclk = LL_RCC_PERIPH_FREQUENCY_NO;
LL_RCC_ClocksTypeDef rcc_clocks;
/* Check the parameters */
assert_param(IS_UART_INSTANCE(USARTx));
assert_param(IS_LL_USART_BAUDRATE(USART_InitStruct->BaudRate));
assert_param(IS_LL_USART_DATAWIDTH(USART_InitStruct->DataWidth));
assert_param(IS_LL_USART_STOPBITS(USART_InitStruct->StopBits));
assert_param(IS_LL_USART_PARITY(USART_InitStruct->Parity));
assert_param(IS_LL_USART_DIRECTION(USART_InitStruct->TransferDirection));
assert_param(IS_LL_USART_HWCONTROL(USART_InitStruct->HardwareFlowControl));
assert_param(IS_LL_USART_OVERSAMPLING(USART_InitStruct->OverSampling));
/* USART needs to be in disabled state, in order to be able to configure some bits in
CRx registers */
if (LL_USART_IsEnabled(USARTx) == 0U)
{
/*---------------------------- USART CR1 Configuration -----------------------
* Configure USARTx CR1 (USART Word Length, Parity, Mode and Oversampling bits) with parameters:
* - DataWidth: USART_CR1_M bits according to USART_InitStruct->DataWidth value
* - Parity: USART_CR1_PCE, USART_CR1_PS bits according to USART_InitStruct->Parity value
* - TransferDirection: USART_CR1_TE, USART_CR1_RE bits according to USART_InitStruct->TransferDirection value
* - Oversampling: USART_CR1_OVER8 bit according to USART_InitStruct->OverSampling value.
*/
MODIFY_REG(USARTx->CR1,
(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS |
USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8),
(USART_InitStruct->DataWidth | USART_InitStruct->Parity |
USART_InitStruct->TransferDirection | USART_InitStruct->OverSampling));
/*---------------------------- USART CR2 Configuration -----------------------
* Configure USARTx CR2 (Stop bits) with parameters:
* - Stop Bits: USART_CR2_STOP bits according to USART_InitStruct->StopBits value.
* - CLKEN, CPOL, CPHA and LBCL bits are to be configured using LL_USART_ClockInit().
*/
LL_USART_SetStopBitsLength(USARTx, USART_InitStruct->StopBits);
/*---------------------------- USART CR3 Configuration -----------------------
* Configure USARTx CR3 (Hardware Flow Control) with parameters:
* - HardwareFlowControl: USART_CR3_RTSE, USART_CR3_CTSE bits according to USART_InitStruct->HardwareFlowControl value.
*/
LL_USART_SetHWFlowCtrl(USARTx, USART_InitStruct->HardwareFlowControl);
/*---------------------------- USART BRR Configuration -----------------------
* Retrieve Clock frequency used for USART Peripheral
*/
LL_RCC_GetSystemClocksFreq(&rcc_clocks);
if (USARTx == USART1)
{
periphclk = rcc_clocks.PCLK2_Frequency;
}
else if (USARTx == USART2)
{
periphclk = rcc_clocks.PCLK1_Frequency;
}
else if (USARTx == USART3)
{
periphclk = rcc_clocks.PCLK1_Frequency;
}
#if defined(UART4)
else if (USARTx == UART4)
{
periphclk = rcc_clocks.PCLK1_Frequency;
}
#endif /* UART4 */
#if defined(UART5)
else if (USARTx == UART5)
{
periphclk = rcc_clocks.PCLK1_Frequency;
}
#endif /* UART5 */
else
{
/* Nothing to do, as error code is already assigned to ERROR value */
}
/* Configure the USART Baud Rate :
- valid baud rate value (different from 0) is required
- Peripheral clock as returned by RCC service, should be valid (different from 0).
*/
if ((periphclk != LL_RCC_PERIPH_FREQUENCY_NO)
&& (USART_InitStruct->BaudRate != 0U))
{
status = SUCCESS;
LL_USART_SetBaudRate(USARTx,
periphclk,
USART_InitStruct->OverSampling,
USART_InitStruct->BaudRate);
}
}
/* Endif (=> USART not in Disabled state => return ERROR) */
return (status);
}
/**
* @brief Set each @ref LL_USART_InitTypeDef field to default value.
* @param USART_InitStruct: pointer to a @ref LL_USART_InitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct)
{
/* Set USART_InitStruct fields to default values */
USART_InitStruct->BaudRate = 9600U;
USART_InitStruct->DataWidth = LL_USART_DATAWIDTH_8B;
USART_InitStruct->StopBits = LL_USART_STOPBITS_1;
USART_InitStruct->Parity = LL_USART_PARITY_NONE ;
USART_InitStruct->TransferDirection = LL_USART_DIRECTION_TX_RX;
USART_InitStruct->HardwareFlowControl = LL_USART_HWCONTROL_NONE;
USART_InitStruct->OverSampling = LL_USART_OVERSAMPLING_16;
}
/**
* @brief Initialize USART Clock related settings according to the
* specified parameters in the USART_ClockInitStruct.
* @note As some bits in USART configuration registers can only be written when the USART is disabled (USART_CR1_UE bit =0),
* USART IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
* @param USARTx USART Instance
* @param USART_ClockInitStruct: pointer to a @ref LL_USART_ClockInitTypeDef structure
* that contains the Clock configuration information for the specified USART peripheral.
* @retval An ErrorStatus enumeration value:
* - SUCCESS: USART registers related to Clock settings are initialized according to USART_ClockInitStruct content
* - ERROR: Problem occurred during USART Registers initialization
*/
ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct)
{
ErrorStatus status = SUCCESS;
/* Check USART Instance and Clock signal output parameters */
assert_param(IS_UART_INSTANCE(USARTx));
assert_param(IS_LL_USART_CLOCKOUTPUT(USART_ClockInitStruct->ClockOutput));
/* USART needs to be in disabled state, in order to be able to configure some bits in
CRx registers */
if (LL_USART_IsEnabled(USARTx) == 0U)
{
/*---------------------------- USART CR2 Configuration -----------------------*/
/* If Clock signal has to be output */
if (USART_ClockInitStruct->ClockOutput == LL_USART_CLOCK_DISABLE)
{
/* Deactivate Clock signal delivery :
* - Disable Clock Output: USART_CR2_CLKEN cleared
*/
LL_USART_DisableSCLKOutput(USARTx);
}
else
{
/* Ensure USART instance is USART capable */
assert_param(IS_USART_INSTANCE(USARTx));
/* Check clock related parameters */
assert_param(IS_LL_USART_CLOCKPOLARITY(USART_ClockInitStruct->ClockPolarity));
assert_param(IS_LL_USART_CLOCKPHASE(USART_ClockInitStruct->ClockPhase));
assert_param(IS_LL_USART_LASTBITCLKOUTPUT(USART_ClockInitStruct->LastBitClockPulse));
/*---------------------------- USART CR2 Configuration -----------------------
* Configure USARTx CR2 (Clock signal related bits) with parameters:
* - Enable Clock Output: USART_CR2_CLKEN set
* - Clock Polarity: USART_CR2_CPOL bit according to USART_ClockInitStruct->ClockPolarity value
* - Clock Phase: USART_CR2_CPHA bit according to USART_ClockInitStruct->ClockPhase value
* - Last Bit Clock Pulse Output: USART_CR2_LBCL bit according to USART_ClockInitStruct->LastBitClockPulse value.
*/
MODIFY_REG(USARTx->CR2,
USART_CR2_CLKEN | USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL,
USART_CR2_CLKEN | USART_ClockInitStruct->ClockPolarity |
USART_ClockInitStruct->ClockPhase | USART_ClockInitStruct->LastBitClockPulse);
}
}
/* Else (USART not in Disabled state => return ERROR */
else
{
status = ERROR;
}
return (status);
}
/**
* @brief Set each field of a @ref LL_USART_ClockInitTypeDef type structure to default value.
* @param USART_ClockInitStruct: pointer to a @ref LL_USART_ClockInitTypeDef structure
* whose fields will be set to default values.
* @retval None
*/
void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct)
{
/* Set LL_USART_ClockInitStruct fields with default values */
USART_ClockInitStruct->ClockOutput = LL_USART_CLOCK_DISABLE;
USART_ClockInitStruct->ClockPolarity = LL_USART_POLARITY_LOW; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */
USART_ClockInitStruct->ClockPhase = LL_USART_PHASE_1EDGE; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */
USART_ClockInitStruct->LastBitClockPulse = LL_USART_LASTCLKPULSE_NO_OUTPUT; /* Not relevant when ClockOutput = LL_USART_CLOCK_DISABLE */
}
/**
* @}
*/
/**
* @}
*/
/**
* @}
*/
#endif /* USART1 || USART2|| USART3 || UART4 || UART5 */
/**
* @}
*/
#endif /* USE_FULL_LL_DRIVER */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
the_stack_data/234518693.c | /*
* Benchmarks contributed by Divyesh Unadkat[1,2], Supratik Chakraborty[1], Ashutosh Gupta[1]
* [1] Indian Institute of Technology Bombay, Mumbai
* [2] TCS Innovation labs, Pune
*
*/
extern void __VERIFIER_error() __attribute__ ((__noreturn__));
extern void __VERIFIER_assume(int);
void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } }
extern int __VERIFIER_nondet_int();
int N;
int main ( ) {
N = __VERIFIER_nondet_int();
if(N <= 0) return 1;
__VERIFIER_assume(N <= 2147483647/sizeof(int));
int sum[1];
int i;
sum[0] = 0;
for(i = 0; i < N; i++)
{
sum[0] = sum[0] + N*N*N;
}
__VERIFIER_assert(sum[0] == N*N*N*N);
return 0;
}
|
the_stack_data/935665.c | #include <assert.h>
int main()
{
int i=0, j=2;
while(i < 50)
{
i++;
j++;
}
__CPROVER_assert(i < 51, "i<51");
}
|
the_stack_data/1118819.c | int dep(int a[100], int b[100], int c[100], int d[100])
{
int i, j, k;
//BEGIN_FPGA_dep_to_export
for(i = 0; i < 100; i++)
{
a[i] = d[i];
c[i] = a[i-1] + 1;
}
//END_FPGA_dep_to_export
return 0;
}
int main(int argc, char* args)
{
int a[100], b[100], c[100], d[100];
dep(a, b, c, d);
return 0;
}
|
the_stack_data/190767118.c | #include <stdio.h>
int main ()
{
int map[200][200] = {{0}}, dyn[200][200] = {{0}}, i, j, n, max;
i = 0;
while (1)
{
i++;
for (j=1; j<=i; j++)
if (!scanf("%d", &map[i][j]))
goto outside;
}
if (0)
outside: n = i - 1;
for (i=1; i<=n; i++)
for (j=1; j<=i; j++)
dyn[i][j] = map[i][j] + \
(dyn[i-1][j] > dyn[i-1][j-1] ? dyn[i-1][j] : dyn[i-1][j-1]);
max = 0;
for (i=1; i<=n; i++)
if (max < dyn[n][i])
max = dyn[n][i];
printf("%d\n", max);
return 0;
}
|
the_stack_data/7950780.c | int main() {
return (5 == 5);
}
|
the_stack_data/56873.c | /* PR optimization/15296. The delayed-branch scheduler caused code that
SEGV:d for CRIS; a register was set to -1 in a delay-slot for the
fall-through code, while that register held a pointer used in code at
the branch target. */
typedef int __attribute__ ((mode (__pointer__))) intptr_t;
typedef intptr_t W;
union u0
{
union u0 *r;
W i;
};
struct s1
{
union u0 **m0;
union u0 m1[4];
};
void f (void *, struct s1 *, const union u0 *, W, W, W)
__attribute__ ((__noinline__));
void g (void *, char *) __attribute__ ((__noinline__));
void
f (void *a, struct s1 *b, const union u0 *h, W v0, W v1, W v4)
{
union u0 *e = 0;
union u0 *k = 0;
union u0 **v5 = b->m0;
union u0 *c = b->m1;
union u0 **d = &v5[0];
l0:;
if (v0 < v1)
goto l0;
if (v0 == 0)
goto l3;
v0 = v4;
if (v0 != 0)
goto l3;
c[0].r = *d;
v1 = -1;
e = c[0].r;
if (e != 0)
g (a, "");
k = e + 3;
k->i = v1;
goto l4;
l3:;
c[0].i = v0;
e = c[1].r;
if (e != 0)
g (a, "");
e = c[0].r;
if (e == 0)
g (a, "");
k = e + 2;
k->r = c[1].r;
l4:;
}
void g (void *a, char *b) { abort (); }
int
main ()
{
union u0 uv[] = {{ .i = 111 }, { .i = 222 }, { .i = 333 }, { .i = 444 }};
struct s1 s = { 0, {{ .i = 555 }, { .i = 0 }, { .i = 999 }, { .i = 777 }}};
f (0, &s, 0, 20000, 10000, (W) uv);
if (s.m1[0].i != (W) uv || s.m1[1].i != 0 || s.m1[2].i != 999
|| s.m1[3].i != 777 || uv[0].i != 111 || uv[1].i != 222
|| uv[2].i != 0 || uv[3].i != 444)
abort ();
exit (0);
}
|
the_stack_data/137408.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 10
#define MAX_LEN 10000
int overlap(char *str1, char *str2) {
int l=0;
char *p1, *p2;
p1=str1;
p2=str2;
while(*p1) {
if (*p1==*p2) {
l++;
p2++;
}
else {
p1-=l;
l=0;
p2=str2;
}
p1++;
}
return l;
}
void shift(int *arr) {
int i, tmp;
tmp = arr[1];
for(i=2; i<arr[0]; i++)
arr[i-1]=arr[i];
arr[arr[0]-1]=tmp;
}
int main() {
int i, k, n;
int overlaps[MAX][MAX], allow[MAX][MAX], arr[MAX];
int max, maxi, maxk;
int *p;
int sum=0;
char strs[MAX][MAX_LEN];
scanf("%d", &n);
for(i=0; i<n; i++) scanf("%s", strs[i]);
for(i=0; i<n; i++)
for(k=0; k<n; k++) {
if (i==k) {
overlaps[i][k]=0;
}
else {
overlaps[i][k]=overlap(strs[i], strs[k]);
}
allow[i][k] = 1;
}
p=arr;
while (1) {
max=-1;
maxi=-1;
maxk=-1;
for(i=0; i<n; i++) {
for(k=0; k<n; k++) {
if (allow[i][k] && (overlaps[i][k]>max)) {
maxi=i;
maxk=k;
max=overlaps[i][k];
}
}
}
if(max==-1) {
break;
}
*p++=max;
for(i=0; i<n; i++) {
allow[maxi][i] = 0;
allow[i][maxk] = 0;
}
}
for(i=0; i<n-1; i++)
sum+=strlen(strs[i])-arr[i];
sum+=strlen(strs[n-1]);
printf("%d\n", sum);
return 0;
} |
the_stack_data/28263245.c | /* { dg-do run } */
/* { dg-options "-O2" } */
/* { dg-additional-sources "tailcall-8.c" } */
struct s { int x; };
int expected;
struct s *last_ptr;
struct s tmp;
void
start (int val, struct s *initial_last_ptr)
{
expected = val;
tmp.x = val;
last_ptr = initial_last_ptr;
}
void
f_direct (struct s param)
{
if (param.x != expected)
__builtin_abort ();
}
void
f_indirect (struct s *ptr)
{
if (ptr->x != expected)
__builtin_abort ();
last_ptr = ptr;
ptr->x += 100;
}
void
f_void (void)
{
if (last_ptr->x != expected + 100)
__builtin_abort ();
}
void g1 (struct s);
void g2 (struct s *);
void g3 (struct s *);
void g4 (struct s *);
void g5 (struct s);
void g6 (struct s);
void g7 (struct s);
void g8 (struct s *);
void g9 (struct s *);
int
main (void)
{
struct s g6_s = { 106 };
start (1, 0);
g1 (tmp);
start (2, 0);
g2 (&tmp);
start (3, 0);
g3 (&tmp);
start (4, 0);
g4 (&tmp);
start (5, 0);
g5 (tmp);
start (6, &g6_s);
g6 (tmp);
start (7, 0);
g7 (tmp);
start (8, 0);
g8 (&tmp);
start (9, 0);
g9 (&tmp);
return 0;
}
|
the_stack_data/98575272.c | /* Sysdep esound sound dsp driver
Copyright 2000 Hans de Goede
This file and the acompanying files in this directory are free software;
you can redistribute them and/or modify them under the terms of the GNU
Library General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.
These files are distributed in the hope that they will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with these files; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* Changelog
Version 0.1, January 2000
-initial release, based on the driver submitted by riq <[email protected]>,
amongst others (Hans de Goede)
*/
#ifdef SYSDEP_DSP_ESOUND
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <esd.h>
#include "sysdep/sysdep_dsp.h"
#include "sysdep/sysdep_dsp_priv.h"
#include "sysdep/plugin_manager.h"
#if 1 /* QUASI88 */
extern int verbose_proc;
#define fprintf if (verbose_proc) fprintf
#endif /* QUASI88 */
/* #define ESOUND_DEBUG */
/* our per instance private data struct */
struct esound_dsp_priv_data {
int fd;
};
/* public methods prototypes (static but exported through the sysdep_dsp or
plugin struct) */
static void *esound_dsp_create(const void *flags);
static void esound_dsp_destroy(struct sysdep_dsp_struct *dsp);
static int esound_dsp_write(struct sysdep_dsp_struct *dsp, unsigned char *data,
int count);
/* public variables */
const struct plugin_struct sysdep_dsp_esound = {
"esound",
"sysdep_dsp",
"Esound DSP plugin",
NULL, /* no options */
NULL, /* no init */
NULL, /* no exit */
esound_dsp_create,
2 /* lower priority as direct device access */
};
/* private variables */
static int esound_dsp_bytes_per_sample[4] = SYSDEP_DSP_BYTES_PER_SAMPLE;
/* public methods (static but exported through the sysdep_dsp or plugin
struct) */
static void *esound_dsp_create(const void *flags)
{
#ifdef ESOUND_DEBUG
int server_fd;
esd_server_info_t *info = NULL;
#endif
struct esound_dsp_priv_data *priv = NULL;
struct sysdep_dsp_struct *dsp = NULL;
const struct sysdep_dsp_create_params *params = flags;
esd_format_t esd_format;
/* allocate the dsp struct */
if (!(dsp = calloc(1, sizeof(struct sysdep_dsp_struct))))
{
fprintf(stderr,
"error malloc failed for struct sysdep_dsp_struct\n");
return NULL;
}
/* alloc private data */
if(!(priv = calloc(1, sizeof(struct esound_dsp_priv_data))))
{
fprintf(stderr,
"error malloc failed for struct esound_dsp_priv_data\n");
esound_dsp_destroy(dsp);
return NULL;
}
/* fill in the functions and some data */
priv->fd = -1;
dsp->_priv = priv;
dsp->write = esound_dsp_write;
dsp->destroy = esound_dsp_destroy;
dsp->hw_info.type = params->type;
dsp->hw_info.samplerate = params->samplerate;
/* open the sound device */
esd_format = ESD_STREAM | ESD_PLAY ;
esd_format |= (dsp->hw_info.type & SYSDEP_DSP_16BIT)?
ESD_BITS16 : ESD_BITS8;
esd_format |= (dsp->hw_info.type & SYSDEP_DSP_STEREO)?
ESD_STEREO : ESD_MONO;
#ifdef ESOUND_DEBUG
if((server_fd = esd_open_sound(params->device)) < 0)
{
fprintf(stderr, "error: esound server open failed\n");
esound_dsp_destroy(dsp);
return NULL;
}
if(!(info = esd_get_server_info(server_fd)))
{
fprintf(stderr, "error: esound get server info failed\n");
esd_close(server_fd);
esound_dsp_destroy(dsp);
return NULL;
}
esd_print_server_info(info);
esd_free_server_info(info);
esd_close(server_fd);
#endif
if((priv->fd = esd_play_stream(esd_format, dsp->hw_info.samplerate,
params->device, "mame esound")) < 0)
{
fprintf(stderr, "error: esound open stream failed\n");
esound_dsp_destroy(dsp);
return NULL;
}
/* set non-blocking mode if selected */
if(params->flags & SYSDEP_DSP_O_NONBLOCK)
{
long flags = fcntl(priv->fd, F_GETFL);
if((flags < 0) || (fcntl(priv->fd, F_SETFL, flags|O_NONBLOCK) < 0))
{
perror("Esound-driver, error: fnctl");
esound_dsp_destroy(dsp);
return NULL;
}
}
return dsp;
}
static void esound_dsp_destroy(struct sysdep_dsp_struct *dsp)
{
struct esound_dsp_priv_data *priv = dsp->_priv;
if(priv)
{
if(priv->fd >= 0)
close(priv->fd);
free(priv);
}
free(dsp);
}
static int esound_dsp_write(struct sysdep_dsp_struct *dsp, unsigned char *data,
int count)
{
int result;
struct esound_dsp_priv_data *priv = dsp->_priv;
result = write(priv->fd, data, count *
esound_dsp_bytes_per_sample[dsp->hw_info.type]);
if (result < 0)
{
fprintf(stderr, "error: esound write to stream failed\n");
return -1;
}
return result / esound_dsp_bytes_per_sample[dsp->hw_info.type];
}
#endif /* ifdef SYSDEP_DSP_ESOUND */
|
the_stack_data/36074405.c | /* This testcase is part of GDB, the GNU debugger.
Copyright 2009-2020 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
#include <unistd.h>
static void
hangout_loop (void)
{
}
int
main(int argc, char *argv[])
{
int i;
alarm (30);
for (i = 0; i < argc; ++i)
{
printf("Arg %d is %s\n", i, argv[i]);
}
while (1)
{
hangout_loop ();
usleep (20);
}
}
|
the_stack_data/14200191.c | #include<stdio.h>
#include <math.h>
void fun(long long a);
int main()
{
int q;
int i;
if(scanf("%d",&q)>1000)
{
return -1;
}
long long a[q];
for(i=0;i<q;i++)
{
scanf("%lld",&a[i]);
if( a[i]>=1 && a[i]<=pow(10,18))
{
fun(a[i]);
}
}
}
void fun(long long a)
{
int i=0;
while(a!=1&&i!=-1)
{
if(a%3==0)
{
a=(a/3)*2;
i++;
}
else if(a%5==0)
{
a=(a/5)*4;
i++;
}
else if(a%2==0)
{
a=a/2;
i++;
}
else
{
i=-1;
}
}
printf("%d\n",i);
i=0;
}
|
the_stack_data/136780.c | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define N 10 /* N次正方行列 */
#define EPS pow(10.0, -8.0) /* 誤差の設定 */
#define KMAX 300 /* 最大反復回数 */
/* 行列の入力 */
void input_matrix( double **a, char c, FILE *fin, FILE *fout);
/* ベクトルの入力 */
void input_vector( double *b, char c, FILE *fin, FILE *fout);
/* 行列の領域確保 */
double **dmatrix(int nr1, int nr2, int nl1, int nl2);
/* 行列の領域解放 */
void free_dmatrix(double **a, int nr1, int nr2, int nl1, int nl2);
/* ベクトル領域の確保 */
double *dvector(int i, int j);
/* 領域の解放 */
void free_dvector(double *a, int i);
/* 比較関数 */
int double_comp( const void *s1 , const void *s2 );
/* 最大値ノルムの計算 a[m...n] */
double vector_norm_max( double *a, int m, int n );
/* SOR法 */
double *sor(double **a, double *b, double *x, double omega);
int main(void)
{
FILE *fin, *fout;
double **a, *b, *x;
double omega = 1.73;
int i;
printf("omega = %f\n",omega);
/* 行列およびベクトルの領域確保 */
a = dmatrix(1, N, 1, N); /* 行列 a[1...N][1...N] */
b = dvector(1,N); /* b[1...N] */
x = dvector(1,N); /* x[1...N] */
/* ファイルのオープン */
if ( (fin = fopen( "input_matrix.dat", "r")) == NULL )
{
printf("ファイルが見つかりません : input_matrix.dat \n");
exit(1);
}
if( (fout = fopen( "output_SOR.dat", "w")) == NULL )
{
printf("ファイルが作成できません : output_SOR.dat \n");
exit(1);
}
input_matrix( a, 'A', fin, fout ); /* 行列Aの入出力 */
input_vector( b, 'b', fin, fout ); /* ベクトルbの入出力 */
input_vector( x, 'x', fin, fout ); /* 初期ベクトルx0の入出力 */
x = sor( a, b, x, omega ); /* SOR法 */
/* 結果の出力 */
fprintf( fout, "Ax=bの解は次の通りです\n");
for( i = 1 ; i <= N ; i++ )
{
fprintf(fout, "%f\n", x[i]);
}
fclose(fin); fclose(fout); /* ファイルのクローズ */
/* 領域の解放 */
free_dmatrix( a, 1, N, 1, N ); free_dvector( b, 1 ); free_dvector( x, 1 );
return 0;
}
/* SOR法 */
double *sor(double **a, double *b, double *x, double omega)
{
double eps, *xo, s, t;
int i, j, k=0;
xo = dvector(1,N); /* xo[1...N] */
do
{
/* xo <- x_k, x <- x_{k+1} */
for( i = 1; i <= N; i++ ) xo[i] = x[i]; /* x_k に x_(k+1)を代入 */
/* i=1の処理 */
t = 0.0;
for( j = 2; j <= N; j++ ) t += a[1][j]*xo[j];
x[1] = ( b[1] - t )/a[1][1];
/* i=2,3,...Nの処理 */
for( i = 2; i <= N; i++ )
{
s = 0.0; t = 0.0;
for( j = 1; j < i; j++) s += a[i][j]*x[j]; /* i-1列までの和 */
for( j = i+1; j <= N; j++) t += a[i][j]*xo[j]; /* i+1列以降の和 */
x[i] = ( b[i] - s - t )/a[i][i];
}
/* SOR法 */
for( i = 1; i <= N; i++ )
{
x[i] = xo[i] + omega * ( x[i] - xo[i] ); /* 補正 */
}
for( i = 1; i <= N; i++ ) xo[i] = xo[i]-x[i];
eps = vector_norm_max(xo, 1, N);
k++;
printf("%d %10.8f \n",k,xo[1]);
}while(eps > EPS && k < KMAX);
free_dvector( xo, 1 ); /* 領域の解放 */
if ( k == KMAX )
{
printf("答えが見つかりませんでした\n");
exit(1);
}
else
{
printf("反復回数は%d回です\n", k); /* 反復回数を画面に表示 */
return x;
}
}
/* a[1...N][1...N]の入力 */
void input_matrix( double **a, char c, FILE *fin, FILE *fout)
{
int i,j;
fprintf( fout, "行列%cは次の通りです\n", c);
for( i = 1 ; i <= N ; i++)
{
for( j = 1 ; j <= N ; j++)
{
fscanf(fin, "%lf", &a[i][j]);
fprintf(fout, "%5.2f\t", a[i][j]);
}
fprintf( fout, "\n");
}
}
/* b[1...N]の入力 */
void input_vector( double *b, char c, FILE *fin, FILE *fout)
{
int i;
fprintf( fout, "ベクトル%cは次の通りです\n", c);
for( i = 1 ; i <= N ; i++)
{
fscanf(fin, "%lf", &b[i]);
fprintf(fout, "%5.2f\t", b[i]);
fprintf(fout, "\n");
}
}
double **dmatrix(int nr1, int nr2, int nl1, int nl2)
{
int i, nrow, ncol;
double **a;
nrow = nr2 - nr1 + 1 ; /* 行の数 */
ncol = nl2 - nl1 + 1 ; /* 列の数 */
/* 行の確保 */
if ( ( a=(double **)malloc( nrow*sizeof(double *) ) ) == NULL )
{
printf("メモリが確保できません(行列a)\n");
exit(1);
}
a = a - nr1; /* 行をずらす */
/* 列の確保 */
for( i=nr1; i<=nr2; i++) a[i] = (double *)malloc(ncol*sizeof(double));
for( i=nr1; i<=nr2; i++) a[i] = a[i]-nl1; /* 列をずらす */
return(a);
}
void free_dmatrix(double **a, int nr1, int nr2, int nl1, int nl2)
{
int i;
/* メモリの解放 */
for ( i = nr1 ; i <= nr2 ; i++) free((void *)(a[i]+nl1));
free((void *)(a+nr1));
}
double *dvector(int i, int j) /* a[i]~a[i+j]の領域を確保 */
{
double *a;
if ( (a=(double *)malloc( ((j-i+1)*sizeof(double))) ) == NULL )
{
printf("メモリが確保できません(from dvector) \n");
exit(1);
}
return(a-i);
}
void free_dvector(double *a, int i)
{
free( (void *)(a + i) );
}
/* 最大値ノルムの計算 a[m...n] */
double vector_norm_max( double *a, int m, int n )
{
int i, tmp;
tmp = n-m+1 ; /* 全要素数の計算 */
for ( i = m ; i <= n; i++) a[i] = fabs(a[i]);
/* 並べ換え */
qsort(a+m, tmp, sizeof(a[0]), double_comp);
return a[n];
}
int double_comp( const void *s1 , const void *s2 )
{
const double a1 = *((double *)s1);
const double a2 = *((double *)s2);
if( a1 < a2 )
{
return -1;
}
else if( a1 == a2 )
{
return 0;
}
else
{
return 1;
}
} |
the_stack_data/19577.c | /*
* PointersConst.c
*
* Created on: May 26, 2020
* Author: akshaybodla
*/
#include <stdio.h>
#include <stdlib.h>
void pointersConst() {
puts("There are two types of pointer constants: 1) keep the value \nof the pointer constant 2) keep the pointer address constant");
puts("\nType 1: Declare const modifier @ the beginning of the pointer");
puts("Syntax: const datatype * pName = &varName");
double ex1 = 3.14;
printf("Ex: const *double pPi = &pi\n");
const double * pEx1 = &ex1; //Ensures the value of the pointer is constant
// printf("%p\n", pEx1);
puts("Meaning: The value of pEx1 (*pEx1) can not be changed");
puts("\nType 2: Declare the const modifier between the datatype and \npointer");
puts("Syntax: datatype * const pName = &varName");
printf("Ex: double * const pEx2 = &ex2\n");
double ex2 = 2.718;
double * const pEx2 = &ex2; //Pointer always points to the same memory address
puts("Meaning: the address of pEx2 will not change");
puts("\n\nCombining Type 1 & Type 2");
puts("Syntax: const datatype *const pName = &varName");
puts("Meaning: the variable and address can not be changed through \nthe pointer");
puts("However varName can be changed directly");
}
|
the_stack_data/247017306.c | int main(){
int x = 7;
if(1) {
int x = 11;
}
return x;} |
the_stack_data/14201219.c | /* Copyright (c) 2018 Peter Teichman */
#ifdef ROTO_TEST
#include "greatest.h"
#include "vibrato.h"
GREATEST_SUITE(vibrato_suite) {
}
#endif
|
the_stack_data/212644494.c | /* Test function */
int expect(int a, int b)
{
if (!(a == b)) {
printf("Failed\n");
printf(" %d expected, but got %d\n", a, b);
exit(1);
}
}
int t1()
{
return 77;
}
int t2(int a)
{
expect(79, a);
}
int t3(int a, int b, int c, int d, int e, int f)
{
expect(1, a);
expect(2, b);
expect(3, c);
expect(4, d);
expect(5, e);
expect(6, f);
}
int t4a(int *p)
{
return *p;
}
int t4()
{
int a[] = {98};
expect(98, t4a(a));
}
int t5a(int *p)
{
expect(99, *p);
p = p + 1;
expect(98, *p);
p = p + 1;
expect(97, *p);
}
int t5b(int p[])
{
expect(99, *p);
p = p + 1;
expect(98, *p);
p = p + 1;
expect(97, *p);
}
int t5()
{
int a[] = {1, 2, 3};
int *p = a;
*p = 99;
p = p + 1;
*p = 98;
p = p + 1;
*p = 97;
t5a(a);
t5b(a);
}
int main()
{
expect(77, t1());
t2(79);
t3(1, 2, 3, 4, 5, 6);
t4();
t5();
return 0;
}
|
the_stack_data/206393835.c | #include<stdio.h>
int GetPalindrome(int num);
int main()
{
int i,j=0,n,flagPalin=0,lenPalin;
printf("Enter number of elements in an array\n");
scanf("%d",&n);
int a[n],palindrome[n];
printf("Enter numbers\n");
for(i=0;i<n;i++)
{
flagPalin=0;
scanf("%d",&a[i]);
flagPalin=GetPalindrome(a[i]);
if(flagPalin==1)
{
palindrome[j]=a[i];
j++;
}
}
lenPalin=j;
printf("Number of Palindromes in array=%d\n",lenPalin);
if(lenPalin!=0)
{
printf("Palindrome numbers in array are:\n");
for(i=0;i<lenPalin;i++)
{
printf("%d\n",palindrome[i]);
}
}
return 0;
}
int GetPalindrome(int num)
{
int dummy,rev=0,x;
dummy=num;
while(num>0)
{
x=num%10;
rev=rev*10+x;
num=num/10;
}
if(dummy==rev)
return 1;
else
return 0;
} |
the_stack_data/150144493.c |
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
void insert_by_priority(int);
void delete_by_priority(int);
void create();
void check(int);
void display_pqueue();
int pri_que[MAX];
int front, rear;
void main()
{
int n, ch;
printf("\n1 - Insert an element into queue");
printf("\n2 - Delete an element from queue");
printf("\n3 - Display queue elements");
printf("\n4 - Exit");
create();
while (1)
{
printf("\nEnter your choice : ");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("\nEnter value to be inserted : ");
scanf("%d",&n);
insert_by_priority(n);
break;
case 2:
printf("\nEnter value to delete : ");
scanf("%d",&n);
delete_by_priority(n);
break;
case 3:
display_pqueue();
break;
case 4:
exit(0);
default:
printf("\nChoice is incorrect, Enter a correct choice");
}
}
}
/* Function to create an empty priority queue */
void create()
{
front = rear = -1;
}
/* Function to insert value into priority queue */
void insert_by_priority(int data)
{
if (rear >= MAX - 1)
{
printf("\nQueue overflow no more elements can be inserted");
return;
}
if ((front == -1) && (rear == -1))
{
front++;
rear++;
pri_que[rear] = data;
return;
}
else
check(data);
rear++;
}
/* Function to check priority and place element */
void check(int data)
{
int i,j;
for (i = 0; i <= rear; i++)
{
if (data >= pri_que[i])
{
for (j = rear + 1; j > i; j--)
{
pri_que[j] = pri_que[j - 1];
}
pri_que[i] = data;
return;
}
}
pri_que[i] = data;
}
/* Function to delete an element from queue */
void delete_by_priority(int data)
{
int i;
if ((front==-1) && (rear==-1))
{
printf("\nQueue is empty no elements to delete");
return;
}
for (i = 0; i <= rear; i++)
{
if (data == pri_que[i])
{
for (; i < rear; i++)
{
pri_que[i] = pri_que[i + 1];
}
pri_que[i] = -99;
rear--;
if (rear == -1)
front = -1;
return;
}
}
printf("\n%d not found in queue to delete", data);
}
/* Function to display queue elements */
void display_pqueue()
{
if ((front == -1) && (rear == -1))
{
printf("\nQueue is empty");
return;
}
for (; front <= rear; front++)
{
printf(" %d ", pri_que[front]);
}
front = 0;
}
|
the_stack_data/182952694.c |
int main(){
int p,j1,j2,r,a,ganha;
scanf("%d %d %d %d %d", &p, &j1, &j2, &r, &a);
if(p){
if((j1+j2)%2==0){
ganha = 1;
}else{
ganha = 2; }
}else{
if((j1+j2)%2==0){
ganha = 2;
}else{
ganha = 1; }
}
if(r&&a){
ganha = 2;
}else if(r&&!a){
ganha = 1;}
else if(!r&&a){
ganha = 1;
}
printf("Jogador %d ganha!\n",ganha);
return 0;
}
|
the_stack_data/744825.c | // RUN: %clang -fsanitize=pointer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-C --implicit-check-not="pointer-overflow"
// RUN: %clangxx -fsanitize=pointer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-CPP --implicit-check-not="pointer-overflow"
#include <stdlib.h>
int main(int argc, char *argv[]) {
char *base, *result;
base = (char *)0;
result = base + 0;
// CHECK-C: pointer-overflow
base = (char *)0;
result = base + 1;
// CHECK: pointer-overflow
base = (char *)1;
result = base - 1;
// CHECK: pointer-overflow
return 0;
}
|
the_stack_data/1013831.c | #include <netinet/in.h>
const struct in6_addr in6addr_any =
{ { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } };
const struct in6_addr in6addr_loopback =
{ { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } };
|
the_stack_data/23320.c | #include <stdio.h>
#include <stdlib.h>
void value(int val){
val = 5;
printf("%d\n", val);
}
void value2(int *val){
*val = 6;
printf("%d\n", *val);
}
int main(int argc, char *argv[]){
int *ptr = malloc(sizeof(int));
*ptr = 4;
value2(ptr);
value(*ptr);
printf("%d\n", *ptr);
free(ptr);
return 0;
}
|
the_stack_data/198580767.c | #include <stdio.h>
#define MAX 100
double modulo(double valor);
void imprimir(int k, double x1, double x2, double x3, double x4, double erro);
int main() {
// X inicial
double x1 = 0.35, x2 = -2.08, x3 = 5.00, x4 = -0.2;
// Conjunto solução
double resultado1, resultado2, resultado3, resultado4;
double resultadoX[4], resultadoXK[4];
double erro, maiorXK, maiorX;
int i = 1, j = 0;
printf("k | x1 | x2 | x3 | x4 | erro \n");
while (i < MAX) {
resultado1 = (0.7 - x2 + 0.1 * x3 - 0.5 * x4) / 2;
resultado2 = (-7.7 - 0.6 * x1 + 0.6 * x3 + 0.1 * x4) / 3.7;
resultado3 = (5 + 0.1 * x1 + 0.2 * x2 - 0.3 * x4);
resultado4 = (-1 - x1 - 1.2 * x2 - 0.2 * x3) / 5;
// xk
resultadoXK[0] = resultado1;
resultadoXK[1] = resultado2;
resultadoXK[2] = resultado3;
resultadoXK[3] = resultado4;
// xk - (xk-1)
resultadoX[0] = resultado1 - x1;
resultadoX[1] = resultado2 - x2;
resultadoX[2] = resultado3 - x3;
resultadoX[3] = resultado4 - x4;
// Maior entre xk - (xk-1)
maiorX = modulo(resultadoX[0]);
for (j = 1; j < 4; j++) {
if (maiorX < modulo(resultadoX[j])) {
maiorX = modulo(resultadoX[j]);
}
}
// Maior entre xk
maiorXK = modulo(resultadoXK[0]);
for (j = 1; j < 4; j++) {
if (maiorXK < modulo(resultadoXK[j])) {
maiorXK = modulo(resultadoXK[j]);
}
}
erro = maiorX / maiorXK;
imprimir(i, resultado1, resultado2, resultado3, resultado4, erro);
if (erro < 0.001) {
break;
}
i++;
x1 = resultado1;
x2 = resultado2;
x3 = resultado3;
x4 = resultado4;
}
return 1;
}
double modulo(double valor) {
if (valor < 0) {
return valor * (-1);
} else {
return valor;
}
}
void imprimir(int k, double x1, double x2, double x3, double x4, double erro) {
if (k == 1) {
printf("%d | %.4lf | %.4lf | %.4lf | %.4lf | %.6lf \n", k, x1, x2, x3, x4, erro);
} else {
printf("%d | %.4lf | %.4lf | %.4lf | %.4lf | %.6lf \n", k, x1, x2, x3, x4, erro);
}
} |
the_stack_data/1172206.c | #include <stdio.h>
#include <string.h>
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
void
genPerm(uint8_t * key, size_t keylen, uint8_t * perm) {
for (uint32_t i = 0; i < 256; i++)
perm[i] = i;
uint8_t j = 0;
for (size_t i = 0; i < 256; i++) {
j = j + perm[i] + key[i % keylen];
// swap perm[i] and perm[j]
uint8_t tmp = perm[i];
perm[i] = perm[j];
perm[j] = tmp;
}
}
uint8_t
getNextPass(uint8_t * perm, uint8_t * i, uint8_t * j) {
*i += 1;
*j += perm[*i];
// swap perm[i] and perm[j]
uint8_t tmp = perm[*i];
perm[*i] = perm[*j];
perm[*j] = tmp;
return perm[(perm[*i] + perm[*j]) % 256];
}
void
cypherstream(uint8_t * key, size_t keylen) {
uint8_t perm[256];
genPerm(key, keylen, perm);
uint8_t i, j;
i = j = 0;
FILE * inputstream = freopen(NULL, "rb", stdin);
while(1) {
uint8_t xorbyte = getNextPass(perm, &i, &j);
uint8_t input;
if (fread(&input, sizeof(input), 1, inputstream) == 0)
break;
printf("%c", input ^ xorbyte);
}
fclose(inputstream);
}
int
main(int argc, char ** argv) {
if (argc != 2) {
fprintf(stderr, "must contain password as argument\n");
return 1;
}
size_t keylen = strlen(argv[1]);
cypherstream(argv[1], keylen);
return 0;
}
|
the_stack_data/37637079.c | /* Generated by CIL v. 1.7.0 */
/* print_CIL_Input is false */
struct _IO_FILE;
struct timeval;
extern float strtof(char const *str , char const *endptr ) ;
extern void signal(int sig , void *func ) ;
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 int input[1] , unsigned int output[1] ) ;
extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ;
extern int gettimeofday(struct timeval *tv , void *tz , ...) ;
extern int printf(char const *format , ...) ;
int main(int argc , char *argv[] ) ;
void megaInit(void) ;
extern unsigned long strlen(char const *s ) ;
extern long strtol(char const *str , char const *endptr , int base ) ;
extern unsigned long strnlen(char const *s , unsigned long maxlen ) ;
extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ;
struct timeval {
long tv_sec ;
long tv_usec ;
};
extern void *malloc(unsigned long size ) ;
extern int scanf(char const *format , ...) ;
void megaInit(void)
{
{
}
}
int main(int argc , char *argv[] )
{
unsigned int input[1] ;
unsigned int output[1] ;
int randomFuns_i5 ;
unsigned int 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 int )strtoul(argv[randomFuns_i5 + 1], 0, 10);
input[randomFuns_i5] = randomFuns_value6;
randomFuns_i5 ++;
}
RandomFunc(input, output);
if (output[0] == 1115442821U) {
printf("You win!\n");
} else {
}
randomFuns_main_i7 = 0;
while (randomFuns_main_i7 < 1) {
printf("%u\n", output[randomFuns_main_i7]);
randomFuns_main_i7 ++;
}
}
}
void RandomFunc(unsigned int input[1] , unsigned int output[1] )
{
unsigned int state[1] ;
unsigned int local2 ;
unsigned int local1 ;
{
state[0UL] = input[0UL] + 4284877637U;
local1 = 0UL;
while (local1 < 1UL) {
local2 = 0UL;
while (local2 < 1UL) {
state[local1] = state[0UL] * state[0UL];
local2 += 2UL;
}
local1 += 2UL;
}
output[0UL] = state[0UL] - 935265151U;
}
}
|
the_stack_data/151706367.c | #include <limits.h>
#include <stdio.h>
#include <string.h>
#define BUFFER_SIZE 1000
static unsigned long long buffer[BUFFER_SIZE];
unsigned long long fibonacci(int index)
{
if (buffer[index] == ULLONG_MAX)
{
return buffer[index] = fibonacci(index - 1) + fibonacci(index - 2);
}
else
{
return buffer[index];
}
}
int main()
{
memset(buffer, 0xFF, sizeof(unsigned long long) * BUFFER_SIZE);
buffer[0] = 0;
buffer[1] = 1;
while (1)
{
printf("Index(Exit: -1): ");
int index;
scanf(" %d", &index);
if (index == -1)
{
break;
}
printf("%llu\n", fibonacci(index));
}
return 0;
} |
the_stack_data/206391868.c | // Copyright 2017 The Australian National University
//
// 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.
#include <stdint.h>
uint64_t fib(uint64_t n) {
if(n <= 1)
return n;
return fib(n - 2) + fib(n - 1);
} |
the_stack_data/200143482.c | /* The bit-field below would have a problem if __INT_MAX__ is too
small. */
#if __INT_MAX__ < 2147483647
int a;
#else
struct s {
int f1 : 26;
int f2 : 8;
};
f (struct s *x)
{
return x->f2++ == 0;
}
#endif
|
the_stack_data/36076458.c | /*
* Joltik=/=-80-48 Reference C Implementation
*
* Copyright 2014:
* Jeremy Jean <[email protected]>
* Ivica Nikolic <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
*/
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define GETU64(pt) ((((uint64_t)(pt)[0])<<56ULL)^(((uint64_t)(pt)[1])<<48ULL)^(((uint64_t)(pt)[2])<<40ULL)^(((uint64_t)(pt)[3])<<32ULL)^(((uint64_t)(pt)[4])<<24ULL)^(((uint64_t)(pt)[5])<<16ULL)^(((uint64_t)(pt)[6])<<8ULL)^((uint64_t)(pt)[7]))
#define PUTU64(ct, st) do { \
(ct)[0] = (uint8_t)((st) >> 56ULL); \
(ct)[1] = (uint8_t)((st) >> 48ULL); \
(ct)[2] = (uint8_t)((st) >> 40ULL); \
(ct)[3] = (uint8_t)((st) >> 32ULL); \
(ct)[4] = (uint8_t)((st) >> 24ULL); \
(ct)[5] = (uint8_t)((st) >> 16ULL); \
(ct)[6] = (uint8_t)((st) >> 8ULL); \
(ct)[7] = (uint8_t)((st) ); \
} while(0)
static const uint32_t TeH[256] = {
0x33dd, 0xd968, 0x4616, 0x6feb, 0x2e32, 0x855e, 0xed7a, 0xc487,
0xaca3, 0x07cf, 0x1a20, 0x7204, 0x5bf9, 0xb14c, 0x98b1, 0xf095,
0x9d86, 0x7733, 0xe84d, 0xc1b0, 0x8069, 0x2b05, 0x4321, 0x6adc,
0x02f8, 0xa994, 0xb47b, 0xdc5f, 0xf5a2, 0x1f17, 0x36ea, 0x5ece,
0x6461, 0x8ed4, 0x11aa, 0x3857, 0x798e, 0xd2e2, 0xbac6, 0x933b,
0xfb1f, 0x5073, 0x4d9c, 0x25b8, 0x0c45, 0xe6f0, 0xcf0d, 0xa729,
0xf6be, 0x1c0b, 0x8375, 0xaa88, 0xeb51, 0x403d, 0x2819, 0x01e4,
0x69c0, 0xc2ac, 0xdf43, 0xb767, 0x9e9a, 0x742f, 0x5dd2, 0x35f6,
0xe223, 0x0896, 0x97e8, 0xbe15, 0xffcc, 0x54a0, 0x3c84, 0x1579,
0x7d5d, 0xd631, 0xcbde, 0xa3fa, 0x8a07, 0x60b2, 0x494f, 0x216b,
0x58e5, 0xb250, 0x2d2e, 0x04d3, 0x450a, 0xee66, 0x8642, 0xafbf,
0xc79b, 0x6cf7, 0x7118, 0x193c, 0x30c1, 0xda74, 0xf389, 0x9bad,
0xdea7, 0x3412, 0xab6c, 0x8291, 0xc348, 0x6824, 0x0000, 0x29fd,
0x41d9, 0xeab5, 0xf75a, 0x9f7e, 0xb683, 0x5c36, 0x75cb, 0x1def,
0x4c78, 0xa6cd, 0x39b3, 0x104e, 0x5197, 0xfafb, 0x92df, 0xbb22,
0xd306, 0x786a, 0x6585, 0x0da1, 0x245c, 0xcee9, 0xe714, 0x8f30,
0xca3a, 0x208f, 0xbff1, 0x960c, 0xd7d5, 0x7cb9, 0x149d, 0x3d60,
0x5544, 0xfe28, 0xe3c7, 0x8be3, 0xa21e, 0x48ab, 0x6156, 0x0972,
0x70fc, 0x9a49, 0x0537, 0x2cca, 0x6d13, 0xc67f, 0xae5b, 0x87a6,
0xef82, 0x44ee, 0x5901, 0x3125, 0x18d8, 0xf26d, 0xdb90, 0xb3b4,
0xa102, 0x4bb7, 0xd4c9, 0xfd34, 0xbced, 0x1781, 0x7fa5, 0x5658,
0x3e7c, 0x9510, 0x88ff, 0xe0db, 0xc926, 0x2393, 0x0a6e, 0x624a,
0x2740, 0xcdf5, 0x528b, 0x7b76, 0x3aaf, 0x91c3, 0xf9e7, 0xd01a,
0xb83e, 0x1352, 0x0ebd, 0x6699, 0x4f64, 0xa5d1, 0x8c2c, 0xe408,
0xb59f, 0x5f2a, 0xc054, 0xe9a9, 0xa870, 0x031c, 0x6b38, 0x42c5,
0x2ae1, 0x818d, 0x9c62, 0xf446, 0xddbb, 0x370e, 0x1ef3, 0x76d7,
0x1bc4, 0xf171, 0x6e0f, 0x47f2, 0x062b, 0xad47, 0xc563, 0xec9e,
0x84ba, 0x2fd6, 0x3239, 0x5a1d, 0x73e0, 0x9955, 0xb0a8, 0xd88c,
0x891b, 0x63ae, 0xfcd0, 0xd52d, 0x94f4, 0x3f98, 0x57bc, 0x7e41,
0x1665, 0xbd09, 0xa0e6, 0xc8c2, 0xe13f, 0x0b8a, 0x2277, 0x4a53,
0x0f59, 0xe5ec, 0x7a92, 0x536f, 0x12b6, 0xb9da, 0xd1fe, 0xf803,
0x9027, 0x3b4b, 0x26a4, 0x4e80, 0x677d, 0x8dc8, 0xa435, 0xcc11,
};
static const uint32_t TeL[256] = {
0xdd33, 0x68d9, 0x1646, 0xeb6f, 0x322e, 0x5e85, 0x7aed, 0x87c4,
0xa3ac, 0xcf07, 0x201a, 0x0472, 0xf95b, 0x4cb1, 0xb198, 0x95f0,
0x869d, 0x3377, 0x4de8, 0xb0c1, 0x6980, 0x052b, 0x2143, 0xdc6a,
0xf802, 0x94a9, 0x7bb4, 0x5fdc, 0xa2f5, 0x171f, 0xea36, 0xce5e,
0x6164, 0xd48e, 0xaa11, 0x5738, 0x8e79, 0xe2d2, 0xc6ba, 0x3b93,
0x1ffb, 0x7350, 0x9c4d, 0xb825, 0x450c, 0xf0e6, 0x0dcf, 0x29a7,
0xbef6, 0x0b1c, 0x7583, 0x88aa, 0x51eb, 0x3d40, 0x1928, 0xe401,
0xc069, 0xacc2, 0x43df, 0x67b7, 0x9a9e, 0x2f74, 0xd25d, 0xf635,
0x23e2, 0x9608, 0xe897, 0x15be, 0xccff, 0xa054, 0x843c, 0x7915,
0x5d7d, 0x31d6, 0xdecb, 0xfaa3, 0x078a, 0xb260, 0x4f49, 0x6b21,
0xe558, 0x50b2, 0x2e2d, 0xd304, 0x0a45, 0x66ee, 0x4286, 0xbfaf,
0x9bc7, 0xf76c, 0x1871, 0x3c19, 0xc130, 0x74da, 0x89f3, 0xad9b,
0xa7de, 0x1234, 0x6cab, 0x9182, 0x48c3, 0x2468, 0x0000, 0xfd29,
0xd941, 0xb5ea, 0x5af7, 0x7e9f, 0x83b6, 0x365c, 0xcb75, 0xef1d,
0x784c, 0xcda6, 0xb339, 0x4e10, 0x9751, 0xfbfa, 0xdf92, 0x22bb,
0x06d3, 0x6a78, 0x8565, 0xa10d, 0x5c24, 0xe9ce, 0x14e7, 0x308f,
0x3aca, 0x8f20, 0xf1bf, 0x0c96, 0xd5d7, 0xb97c, 0x9d14, 0x603d,
0x4455, 0x28fe, 0xc7e3, 0xe38b, 0x1ea2, 0xab48, 0x5661, 0x7209,
0xfc70, 0x499a, 0x3705, 0xca2c, 0x136d, 0x7fc6, 0x5bae, 0xa687,
0x82ef, 0xee44, 0x0159, 0x2531, 0xd818, 0x6df2, 0x90db, 0xb4b3,
0x02a1, 0xb74b, 0xc9d4, 0x34fd, 0xedbc, 0x8117, 0xa57f, 0x5856,
0x7c3e, 0x1095, 0xff88, 0xdbe0, 0x26c9, 0x9323, 0x6e0a, 0x4a62,
0x4027, 0xf5cd, 0x8b52, 0x767b, 0xaf3a, 0xc391, 0xe7f9, 0x1ad0,
0x3eb8, 0x5213, 0xbd0e, 0x9966, 0x644f, 0xd1a5, 0x2c8c, 0x08e4,
0x9fb5, 0x2a5f, 0x54c0, 0xa9e9, 0x70a8, 0x1c03, 0x386b, 0xc542,
0xe12a, 0x8d81, 0x629c, 0x46f4, 0xbbdd, 0x0e37, 0xf31e, 0xd776,
0xc41b, 0x71f1, 0x0f6e, 0xf247, 0x2b06, 0x47ad, 0x63c5, 0x9eec,
0xba84, 0xd62f, 0x3932, 0x1d5a, 0xe073, 0x5599, 0xa8b0, 0x8cd8,
0x1b89, 0xae63, 0xd0fc, 0x2dd5, 0xf494, 0x983f, 0xbc57, 0x417e,
0x6516, 0x09bd, 0xe6a0, 0xc2c8, 0x3fe1, 0x8a0b, 0x7722, 0x534a,
0x590f, 0xece5, 0x927a, 0x6f53, 0xb612, 0xdab9, 0xfed1, 0x03f8,
0x2790, 0x4b3b, 0xa426, 0x804e, 0x7d67, 0xc88d, 0x35a4, 0x11cc,
};
static const uint32_t TdH[256] = {
0xddbb, 0x031c, 0xa870, 0x5f2a, 0x2ae1, 0xb59f, 0x370e, 0x818d,
0x1ef3, 0x9c62, 0x42c5, 0xe9a9, 0x76d7, 0xf446, 0x6b38, 0xc054,
0x30c1, 0xee66, 0x450a, 0xb250, 0xc79b, 0x58e5, 0xda74, 0x6cf7,
0xf389, 0x7118, 0xafbf, 0x04d3, 0x9bad, 0x193c, 0x8642, 0x2d2e,
0x8a07, 0x54a0, 0xffcc, 0x0896, 0x7d5d, 0xe223, 0x60b2, 0xd631,
0x494f, 0xcbde, 0x1579, 0xbe15, 0x216b, 0xa3fa, 0x3c84, 0x97e8,
0xf5a2, 0x2b05, 0x8069, 0x7733, 0x02f8, 0x9d86, 0x1f17, 0xa994,
0x36ea, 0xb47b, 0x6adc, 0xc1b0, 0x5ece, 0xdc5f, 0x4321, 0xe84d,
0xa21e, 0x7cb9, 0xd7d5, 0x208f, 0x5544, 0xca3a, 0x48ab, 0xfe28,
0x6156, 0xe3c7, 0x3d60, 0x960c, 0x0972, 0x8be3, 0x149d, 0xbff1,
0x5bf9, 0x855e, 0x2e32, 0xd968, 0xaca3, 0x33dd, 0xb14c, 0x07cf,
0x98b1, 0x1a20, 0xc487, 0x6feb, 0xf095, 0x7204, 0xed7a, 0x4616,
0x73e0, 0xad47, 0x062b, 0xf171, 0x84ba, 0x1bc4, 0x9955, 0x2fd6,
0xb0a8, 0x3239, 0xec9e, 0x47f2, 0xd88c, 0x5a1d, 0xc563, 0x6e0f,
0x18d8, 0xc67f, 0x6d13, 0x9a49, 0xef82, 0x70fc, 0xf26d, 0x44ee,
0xdb90, 0x5901, 0x87a6, 0x2cca, 0xb3b4, 0x3125, 0xae5b, 0x0537,
0xe13f, 0x3f98, 0x94f4, 0x63ae, 0x1665, 0x891b, 0x0b8a, 0xbd09,
0x2277, 0xa0e6, 0x7e41, 0xd52d, 0x4a53, 0xc8c2, 0x57bc, 0xfcd0,
0xc926, 0x1781, 0xbced, 0x4bb7, 0x3e7c, 0xa102, 0x2393, 0x9510,
0x0a6e, 0x88ff, 0x5658, 0xfd34, 0x624a, 0xe0db, 0x7fa5, 0xd4c9,
0x245c, 0xfafb, 0x5197, 0xa6cd, 0xd306, 0x4c78, 0xcee9, 0x786a,
0xe714, 0x6585, 0xbb22, 0x104e, 0x8f30, 0x0da1, 0x92df, 0x39b3,
0x9e9a, 0x403d, 0xeb51, 0x1c0b, 0x69c0, 0xf6be, 0x742f, 0xc2ac,
0x5dd2, 0xdf43, 0x01e4, 0xaa88, 0x35f6, 0xb767, 0x2819, 0x8375,
0x677d, 0xb9da, 0x12b6, 0xe5ec, 0x9027, 0x0f59, 0x8dc8, 0x3b4b,
0xa435, 0x26a4, 0xf803, 0x536f, 0xcc11, 0x4e80, 0xd1fe, 0x7a92,
0x4f64, 0x91c3, 0x3aaf, 0xcdf5, 0xb83e, 0x2740, 0xa5d1, 0x1352,
0x8c2c, 0x0ebd, 0xd01a, 0x7b76, 0xe408, 0x6699, 0xf9e7, 0x528b,
0xb683, 0x6824, 0xc348, 0x3412, 0x41d9, 0xdea7, 0x5c36, 0xeab5,
0x75cb, 0xf75a, 0x29fd, 0x8291, 0x1def, 0x9f7e, 0x0000, 0xab6c,
0x0c45, 0xd2e2, 0x798e, 0x8ed4, 0xfb1f, 0x6461, 0xe6f0, 0x5073,
0xcf0d, 0x4d9c, 0x933b, 0x3857, 0xa729, 0x25b8, 0xbac6, 0x11aa,
};
static const uint32_t TdL[256] = {
0xbbdd, 0x1c03, 0x70a8, 0x2a5f, 0xe12a, 0x9fb5, 0x0e37, 0x8d81,
0xf31e, 0x629c, 0xc542, 0xa9e9, 0xd776, 0x46f4, 0x386b, 0x54c0,
0xc130, 0x66ee, 0x0a45, 0x50b2, 0x9bc7, 0xe558, 0x74da, 0xf76c,
0x89f3, 0x1871, 0xbfaf, 0xd304, 0xad9b, 0x3c19, 0x4286, 0x2e2d,
0x078a, 0xa054, 0xccff, 0x9608, 0x5d7d, 0x23e2, 0xb260, 0x31d6,
0x4f49, 0xdecb, 0x7915, 0x15be, 0x6b21, 0xfaa3, 0x843c, 0xe897,
0xa2f5, 0x052b, 0x6980, 0x3377, 0xf802, 0x869d, 0x171f, 0x94a9,
0xea36, 0x7bb4, 0xdc6a, 0xb0c1, 0xce5e, 0x5fdc, 0x2143, 0x4de8,
0x1ea2, 0xb97c, 0xd5d7, 0x8f20, 0x4455, 0x3aca, 0xab48, 0x28fe,
0x5661, 0xc7e3, 0x603d, 0x0c96, 0x7209, 0xe38b, 0x9d14, 0xf1bf,
0xf95b, 0x5e85, 0x322e, 0x68d9, 0xa3ac, 0xdd33, 0x4cb1, 0xcf07,
0xb198, 0x201a, 0x87c4, 0xeb6f, 0x95f0, 0x0472, 0x7aed, 0x1646,
0xe073, 0x47ad, 0x2b06, 0x71f1, 0xba84, 0xc41b, 0x5599, 0xd62f,
0xa8b0, 0x3932, 0x9eec, 0xf247, 0x8cd8, 0x1d5a, 0x63c5, 0x0f6e,
0xd818, 0x7fc6, 0x136d, 0x499a, 0x82ef, 0xfc70, 0x6df2, 0xee44,
0x90db, 0x0159, 0xa687, 0xca2c, 0xb4b3, 0x2531, 0x5bae, 0x3705,
0x3fe1, 0x983f, 0xf494, 0xae63, 0x6516, 0x1b89, 0x8a0b, 0x09bd,
0x7722, 0xe6a0, 0x417e, 0x2dd5, 0x534a, 0xc2c8, 0xbc57, 0xd0fc,
0x26c9, 0x8117, 0xedbc, 0xb74b, 0x7c3e, 0x02a1, 0x9323, 0x1095,
0x6e0a, 0xff88, 0x5856, 0x34fd, 0x4a62, 0xdbe0, 0xa57f, 0xc9d4,
0x5c24, 0xfbfa, 0x9751, 0xcda6, 0x06d3, 0x784c, 0xe9ce, 0x6a78,
0x14e7, 0x8565, 0x22bb, 0x4e10, 0x308f, 0xa10d, 0xdf92, 0xb339,
0x9a9e, 0x3d40, 0x51eb, 0x0b1c, 0xc069, 0xbef6, 0x2f74, 0xacc2,
0xd25d, 0x43df, 0xe401, 0x88aa, 0xf635, 0x67b7, 0x1928, 0x7583,
0x7d67, 0xdab9, 0xb612, 0xece5, 0x2790, 0x590f, 0xc88d, 0x4b3b,
0x35a4, 0xa426, 0x03f8, 0x6f53, 0x11cc, 0x804e, 0xfed1, 0x927a,
0x644f, 0xc391, 0xaf3a, 0xf5cd, 0x3eb8, 0x4027, 0xd1a5, 0x5213,
0x2c8c, 0xbd0e, 0x1ad0, 0x767b, 0x08e4, 0x9966, 0xe7f9, 0x8b52,
0x83b6, 0x2468, 0x48c3, 0x1234, 0xd941, 0xa7de, 0x365c, 0xb5ea,
0xcb75, 0x5af7, 0xfd29, 0x9182, 0xef1d, 0x7e9f, 0x0000, 0x6cab,
0x450c, 0xe2d2, 0x8e79, 0xd48e, 0x1ffb, 0x6164, 0xf0e6, 0x7350,
0x0dcf, 0x9c4d, 0x3b93, 0x5738, 0x29a7, 0xb825, 0xc6ba, 0xaa11,
};
static const uint32_t TmcH[256] = {
0x0000, 0x41d9, 0x8291, 0xc348, 0x3412, 0x75cb, 0xb683, 0xf75a,
0x6824, 0x29fd, 0xeab5, 0xab6c, 0x5c36, 0x1def, 0xdea7, 0x9f7e,
0x149d, 0x5544, 0x960c, 0xd7d5, 0x208f, 0x6156, 0xa21e, 0xe3c7,
0x7cb9, 0x3d60, 0xfe28, 0xbff1, 0x48ab, 0x0972, 0xca3a, 0x8be3,
0x2819, 0x69c0, 0xaa88, 0xeb51, 0x1c0b, 0x5dd2, 0x9e9a, 0xdf43,
0x403d, 0x01e4, 0xc2ac, 0x8375, 0x742f, 0x35f6, 0xf6be, 0xb767,
0x3c84, 0x7d5d, 0xbe15, 0xffcc, 0x0896, 0x494f, 0x8a07, 0xcbde,
0x54a0, 0x1579, 0xd631, 0x97e8, 0x60b2, 0x216b, 0xe223, 0xa3fa,
0x4321, 0x02f8, 0xc1b0, 0x8069, 0x7733, 0x36ea, 0xf5a2, 0xb47b,
0x2b05, 0x6adc, 0xa994, 0xe84d, 0x1f17, 0x5ece, 0x9d86, 0xdc5f,
0x57bc, 0x1665, 0xd52d, 0x94f4, 0x63ae, 0x2277, 0xe13f, 0xa0e6,
0x3f98, 0x7e41, 0xbd09, 0xfcd0, 0x0b8a, 0x4a53, 0x891b, 0xc8c2,
0x6b38, 0x2ae1, 0xe9a9, 0xa870, 0x5f2a, 0x1ef3, 0xddbb, 0x9c62,
0x031c, 0x42c5, 0x818d, 0xc054, 0x370e, 0x76d7, 0xb59f, 0xf446,
0x7fa5, 0x3e7c, 0xfd34, 0xbced, 0x4bb7, 0x0a6e, 0xc926, 0x88ff,
0x1781, 0x5658, 0x9510, 0xd4c9, 0x2393, 0x624a, 0xa102, 0xe0db,
0x8642, 0xc79b, 0x04d3, 0x450a, 0xb250, 0xf389, 0x30c1, 0x7118,
0xee66, 0xafbf, 0x6cf7, 0x2d2e, 0xda74, 0x9bad, 0x58e5, 0x193c,
0x92df, 0xd306, 0x104e, 0x5197, 0xa6cd, 0xe714, 0x245c, 0x6585,
0xfafb, 0xbb22, 0x786a, 0x39b3, 0xcee9, 0x8f30, 0x4c78, 0x0da1,
0xae5b, 0xef82, 0x2cca, 0x6d13, 0x9a49, 0xdb90, 0x18d8, 0x5901,
0xc67f, 0x87a6, 0x44ee, 0x0537, 0xf26d, 0xb3b4, 0x70fc, 0x3125,
0xbac6, 0xfb1f, 0x3857, 0x798e, 0x8ed4, 0xcf0d, 0x0c45, 0x4d9c,
0xd2e2, 0x933b, 0x5073, 0x11aa, 0xe6f0, 0xa729, 0x6461, 0x25b8,
0xc563, 0x84ba, 0x47f2, 0x062b, 0xf171, 0xb0a8, 0x73e0, 0x3239,
0xad47, 0xec9e, 0x2fd6, 0x6e0f, 0x9955, 0xd88c, 0x1bc4, 0x5a1d,
0xd1fe, 0x9027, 0x536f, 0x12b6, 0xe5ec, 0xa435, 0x677d, 0x26a4,
0xb9da, 0xf803, 0x3b4b, 0x7a92, 0x8dc8, 0xcc11, 0x0f59, 0x4e80,
0xed7a, 0xaca3, 0x6feb, 0x2e32, 0xd968, 0x98b1, 0x5bf9, 0x1a20,
0x855e, 0xc487, 0x07cf, 0x4616, 0xb14c, 0xf095, 0x33dd, 0x7204,
0xf9e7, 0xb83e, 0x7b76, 0x3aaf, 0xcdf5, 0x8c2c, 0x4f64, 0x0ebd,
0x91c3, 0xd01a, 0x1352, 0x528b, 0xa5d1, 0xe408, 0x2740, 0x6699,
};
static const uint32_t TmcL[256] = {
0x0000, 0xd941, 0x9182, 0x48c3, 0x1234, 0xcb75, 0x83b6, 0x5af7,
0x2468, 0xfd29, 0xb5ea, 0x6cab, 0x365c, 0xef1d, 0xa7de, 0x7e9f,
0x9d14, 0x4455, 0x0c96, 0xd5d7, 0x8f20, 0x5661, 0x1ea2, 0xc7e3,
0xb97c, 0x603d, 0x28fe, 0xf1bf, 0xab48, 0x7209, 0x3aca, 0xe38b,
0x1928, 0xc069, 0x88aa, 0x51eb, 0x0b1c, 0xd25d, 0x9a9e, 0x43df,
0x3d40, 0xe401, 0xacc2, 0x7583, 0x2f74, 0xf635, 0xbef6, 0x67b7,
0x843c, 0x5d7d, 0x15be, 0xccff, 0x9608, 0x4f49, 0x078a, 0xdecb,
0xa054, 0x7915, 0x31d6, 0xe897, 0xb260, 0x6b21, 0x23e2, 0xfaa3,
0x2143, 0xf802, 0xb0c1, 0x6980, 0x3377, 0xea36, 0xa2f5, 0x7bb4,
0x052b, 0xdc6a, 0x94a9, 0x4de8, 0x171f, 0xce5e, 0x869d, 0x5fdc,
0xbc57, 0x6516, 0x2dd5, 0xf494, 0xae63, 0x7722, 0x3fe1, 0xe6a0,
0x983f, 0x417e, 0x09bd, 0xd0fc, 0x8a0b, 0x534a, 0x1b89, 0xc2c8,
0x386b, 0xe12a, 0xa9e9, 0x70a8, 0x2a5f, 0xf31e, 0xbbdd, 0x629c,
0x1c03, 0xc542, 0x8d81, 0x54c0, 0x0e37, 0xd776, 0x9fb5, 0x46f4,
0xa57f, 0x7c3e, 0x34fd, 0xedbc, 0xb74b, 0x6e0a, 0x26c9, 0xff88,
0x8117, 0x5856, 0x1095, 0xc9d4, 0x9323, 0x4a62, 0x02a1, 0xdbe0,
0x4286, 0x9bc7, 0xd304, 0x0a45, 0x50b2, 0x89f3, 0xc130, 0x1871,
0x66ee, 0xbfaf, 0xf76c, 0x2e2d, 0x74da, 0xad9b, 0xe558, 0x3c19,
0xdf92, 0x06d3, 0x4e10, 0x9751, 0xcda6, 0x14e7, 0x5c24, 0x8565,
0xfbfa, 0x22bb, 0x6a78, 0xb339, 0xe9ce, 0x308f, 0x784c, 0xa10d,
0x5bae, 0x82ef, 0xca2c, 0x136d, 0x499a, 0x90db, 0xd818, 0x0159,
0x7fc6, 0xa687, 0xee44, 0x3705, 0x6df2, 0xb4b3, 0xfc70, 0x2531,
0xc6ba, 0x1ffb, 0x5738, 0x8e79, 0xd48e, 0x0dcf, 0x450c, 0x9c4d,
0xe2d2, 0x3b93, 0x7350, 0xaa11, 0xf0e6, 0x29a7, 0x6164, 0xb825,
0x63c5, 0xba84, 0xf247, 0x2b06, 0x71f1, 0xa8b0, 0xe073, 0x3932,
0x47ad, 0x9eec, 0xd62f, 0x0f6e, 0x5599, 0x8cd8, 0xc41b, 0x1d5a,
0xfed1, 0x2790, 0x6f53, 0xb612, 0xece5, 0x35a4, 0x7d67, 0xa426,
0xdab9, 0x03f8, 0x4b3b, 0x927a, 0xc88d, 0x11cc, 0x590f, 0x804e,
0x7aed, 0xa3ac, 0xeb6f, 0x322e, 0x68d9, 0xb198, 0xf95b, 0x201a,
0x5e85, 0x87c4, 0xcf07, 0x1646, 0x4cb1, 0x95f0, 0xdd33, 0x0472,
0xe7f9, 0x3eb8, 0x767b, 0xaf3a, 0xf5cd, 0x2c8c, 0x644f, 0xbd0e,
0xc391, 0x1ad0, 0x5213, 0x8b52, 0xd1a5, 0x08e4, 0x4027, 0x9966,
};
static const uint8_t mul2 [16]={0x0,0x2,0x4,0x6,0x8,0xa,0xc,0xe,0x3,0x1,0x7,0x5,0xb,0x9,0xf,0xd};
static const uint8_t mul4 [16]={0x0,0x4,0x8,0xc,0x3,0x7,0xb,0xf,0x6,0x2,0xe,0xa,0x5,0x1,0xd,0x9};
static const uint8_t perm[16] = {1,6,11,12,5,10,15,0,9,14,3,4,13,2,7,8};
static const uint64_t rcon[33] = {
0x0123010100000000ULL,
0x0123030300000000ULL,
0x0123070700000000ULL,
0x0123171700000000ULL,
0x0123373700000000ULL,
0x0123767600000000ULL,
0x0123757500000000ULL,
0x0123737300000000ULL,
0x0123676700000000ULL,
0x0123575700000000ULL,
0x0123363600000000ULL,
0x0123747400000000ULL,
0x0123717100000000ULL,
0x0123636300000000ULL,
0x0123474700000000ULL,
0x0123161600000000ULL,
0x0123353500000000ULL,
0x0123727200000000ULL,
0x0123656500000000ULL,
0x0123535300000000ULL,
0x0123262600000000ULL,
0x0123545400000000ULL,
0x0123303000000000ULL,
0x0123606000000000ULL,
0x0123414100000000ULL,
0x0123020200000000ULL,
0x0123050500000000ULL,
0x0123131300000000ULL,
0x0123272700000000ULL,
0x0123565600000000ULL,
0x0123343400000000ULL,
0x0123707000000000ULL,
0x0123616100000000ULL,
};
/*
** Multiplication by alpha in GF(256)/0x11b, for alpha \in {1,2,4}
*/
uint8_t multi (uint8_t x, uint8_t alpha) {
if( 1 == alpha ) return x;
if( 2 == alpha ) return mul2[x];
if( 4 == alpha ) return mul4[x];
printf("Incorrect alpha (%d) passed to the function g in the tweakey schedule. Exiting...\n", alpha); exit(2);
}
/*
** Function G from the specifications
*/
uint64_t G (uint64_t tweakey, uint8_t alpha) {
uint64_t i;
uint64_t shift;
uint8_t tmp;
for(i=0; i<16; i++) {
shift=4ULL*i;
tmp=(tweakey>>shift)&0xf;
tweakey&=0xffffffffffffffffULL^(0xfULL<<shift);
tmp=multi(tmp, alpha);
tweakey^=((uint64_t)tmp)<<shift;
}
return tweakey;
}
/*
** Function H from the specifications
*/
uint64_t H(uint64_t tweakey) {
uint64_t i;
uint64_t shiftIn;
uint64_t shiftOut;
uint64_t res=0;
for (i=0; i<16; i++) {
shiftIn=60ULL-4ULL*i;
shiftOut=60ULL-4ULL*perm[i];
res^=((tweakey>>shiftIn)&0xf)<<shiftOut;
}
return res;
}
/*
** Prepare the round subtweakeys for the encryption process
*/
int joltikKeySetupEnc128(uint64_t* rtweakey,
const uint8_t* Tweakey,
const int no_tweakeys)
{
int r;
uint64_t tweakey[3];
uint8_t alpha[3];
int Nr;
tweakey[0]=GETU64(Tweakey+0);
tweakey[1]=GETU64(Tweakey+8);
tweakey[2]=0;
if( 2 == no_tweakeys ){
alpha[0] = 1; /* key */
alpha[1] = 2; /* tweak */
/* Number of rounds is 24 for Joltik-BC-128 */
Nr=24;
} else if( 3 == no_tweakeys ){
tweakey[2]=GETU64(Tweakey+16);
alpha[0] = 1; /* key 1 */
alpha[1] = 2; /* key 2 */
alpha[2] = 4; /* tweak */
/* Number of rounds is 36 for Joltik-BC-192 */
Nr=32;
} else {
printf("The #tweakeys is %d, and it should be either 2 or 3. Exiting...\n", no_tweakeys);
exit(1);
}
/* For each rounds */
for(r=0; r<=Nr; r++) {
/* Produce the round tweakey */
rtweakey[r] = tweakey[0] ^ tweakey[1] ^ tweakey[2] ^ rcon[r];
/* Apply H and G functions */
tweakey[0]=H(tweakey[0]);
tweakey[0]=G(tweakey[0], alpha[0]);
tweakey[1]=H(tweakey[1]);
tweakey[1]=G(tweakey[1], alpha[1]);
if (3 == no_tweakeys) {
tweakey[2]=H(tweakey[2]);
tweakey[2]=G(tweakey[2], alpha[2]);
}
}/*r*/
return Nr;
}
/*
** Prepare the round subtweakeys for the decryption process
*/
int joltikKeySetupDec128(uint64_t* rtweakey,
const uint8_t* Tweakey,
int no_tweakeys)
{
int i;
int j;
int Nr;
uint64_t temp;
uint64_t s;
uint32_t s0;
uint32_t s1;
uint32_t s2;
uint32_t s3;
uint32_t s4;
uint32_t s5;
uint32_t s6;
uint32_t s7;
/* Produce the round tweakeys used for the encryption */
Nr=joltikKeySetupEnc128 (rtweakey, Tweakey, no_tweakeys);
/* invert their order */
for (i = 0, j = Nr; i < j; ++i, --j) {
temp = rtweakey[i];
rtweakey[i] = rtweakey[j];
rtweakey[j] = temp;
}
/* apply the inverse MixColumn transform to all round keys but the first and the last */
for (i = 1; i <= Nr; i++) {
s=rtweakey[i];
s0 = (s>>56ULL)&0xff;
s1 = (s>>48ULL)&0xff;
s2 = (s>>40ULL)&0xff;
s3 = (s>>32ULL)&0xff;
s4 = (s>>24ULL)&0xff;
s5 = (s>>16ULL)&0xff;
s6 = (s>> 8ULL)&0xff;
s7 = (s>> 0ULL)&0xff;
s = (((uint64_t)(TmcH[s0]^TmcL[s1]))<<48ULL) ^
(((uint64_t)(TmcH[s2]^TmcL[s3]))<<32ULL) ^
(((uint64_t)(TmcH[s4]^TmcL[s5]))<<16ULL) ^
(((uint64_t)(TmcH[s6]^TmcL[s7]))<< 0ULL);
rtweakey[i]=s;
}
return Nr;
}
/*
** Tweakable block cipher encryption function
*/
void aesTweakEncrypt(uint32_t tweakey_size,
const uint8_t pt[8],
uint8_t key[],
uint8_t ct[8]) {
int i;
int Nr;
uint64_t s;
uint32_t s0;
uint32_t s1;
uint32_t s2;
uint32_t s3;
uint32_t s4;
uint32_t s5;
uint32_t s6;
uint32_t s7;
uint64_t rk[33];
/* Produce the round tweakeys */
Nr=joltikKeySetupEnc128 (rk, key, tweakey_size/64);
/* Get the plaintext + key/tweak prewhitening */
s=GETU64(pt) ^ rk[0];
for(i=1; i<=Nr; ++i) {
/* round i: */
s0 = (((s>>56ULL)&0xf0))^((s>>40ULL)&0xf);
s1 = (((s>>16ULL)&0xf0))^((s>> 0ULL)&0xf);
s2 = (((s>>40ULL)&0xf0))^((s>>24ULL)&0xf);
s3 = (((s>> 0ULL)&0xf0))^((s>>48ULL)&0xf);
s4 = (((s>>24ULL)&0xf0))^((s>> 8ULL)&0xf);
s5 = (((s>>48ULL)&0xf0))^((s>>32ULL)&0xf);
s6 = (((s>> 8ULL)&0xf0))^((s>>56ULL)&0xf);
s7 = (((s>>32ULL)&0xf0))^((s>>16ULL)&0xf);
s = (((uint64_t)(TeH[s0]^TeL[s1]))<<48ULL) ^
(((uint64_t)(TeH[s2]^TeL[s3]))<<32ULL) ^
(((uint64_t)(TeH[s4]^TeL[s5]))<<16ULL) ^
(((uint64_t)(TeH[s6]^TeL[s7]))<< 0ULL) ^ rk[i];
}
/* Put the state into the ciphertext */
PUTU64(ct, s);
}
/*
** Tweakable block cipher decryption function
*/
void aesTweakDecrypt(uint32_t tweakey_size,
const uint8_t ct[8],
const uint8_t key[],
uint8_t pt[8])
{
int i;
int Nr;
uint64_t s;
uint32_t s0;
uint32_t s1;
uint32_t s2;
uint32_t s3;
uint32_t s4;
uint32_t s5;
uint32_t s6;
uint32_t s7;
uint64_t rk[33];
/* Produce the round tweakeys */
Nr=joltikKeySetupDec128 (rk, key, tweakey_size/64);
/* Get the ciphertext + key/tweak prewhitening */
s=GETU64(ct) ^ rk[0];
s0 = (s>>56ULL)&0xff;
s1 = (s>>48ULL)&0xff;
s2 = (s>>40ULL)&0xff;
s3 = (s>>32ULL)&0xff;
s4 = (s>>24ULL)&0xff;
s5 = (s>>16ULL)&0xff;
s6 = (s>> 8ULL)&0xff;
s7 = (s>> 0ULL)&0xff;
s = (((uint64_t)(TmcH[s0]^TmcL[s1]))<<48ULL) ^
(((uint64_t)(TmcH[s2]^TmcL[s3]))<<32ULL) ^
(((uint64_t)(TmcH[s4]^TmcL[s5]))<<16ULL) ^
(((uint64_t)(TmcH[s6]^TmcL[s7]))<< 0ULL);
for(i=1; i<=Nr; ++i) {
/* round i: */
s0 = (((s>>56ULL)&0xf0))^((s>> 8ULL)&0xf);
s1 = (((s>>16ULL)&0xf0))^((s>>32ULL)&0xf);
s2 = (((s>>40ULL)&0xf0))^((s>>56ULL)&0xf);
s3 = (((s>> 0ULL)&0xf0))^((s>>16ULL)&0xf);
s4 = (((s>>24ULL)&0xf0))^((s>>40ULL)&0xf);
s5 = (((s>>48ULL)&0xf0))^((s>> 0ULL)&0xf);
s6 = (((s>> 8ULL)&0xf0))^((s>>24ULL)&0xf);
s7 = (((s>>32ULL)&0xf0))^((s>>48ULL)&0xf);
s = (((uint64_t)(TdH[s0]^TdL[s1]))<<48ULL) ^
(((uint64_t)(TdH[s2]^TdL[s3]))<<32ULL) ^
(((uint64_t)(TdH[s4]^TdL[s5]))<<16ULL) ^
(((uint64_t)(TdH[s6]^TdL[s7]))<< 0ULL) ^ rk[i];
}
/* Apply the MixColum to invert the last one performed in the Td table */
s0 = (s>>56ULL)&0xff;
s1 = (s>>48ULL)&0xff;
s2 = (s>>40ULL)&0xff;
s3 = (s>>32ULL)&0xff;
s4 = (s>>24ULL)&0xff;
s5 = (s>>16ULL)&0xff;
s6 = (s>> 8ULL)&0xff;
s7 = (s>> 0ULL)&0xff;
s = (((uint64_t)(TmcH[s0]^TmcL[s1]))<<48ULL) ^
(((uint64_t)(TmcH[s2]^TmcL[s3]))<<32ULL) ^
(((uint64_t)(TmcH[s4]^TmcL[s5]))<<16ULL) ^
(((uint64_t)(TmcH[s6]^TmcL[s7]))<< 0ULL);
/* Put the state into the plaintext */
PUTU64(pt, s);
}
|
the_stack_data/26699170.c | /*
*
* Program to compare to numbers.
* Also determine if odd or even.
*
*/
#include <stdio.h>
// Uncomment the line below if executing on Windows.
//#include <conio.h>
int main()
{
/*
* Declare two variables to store the numbers.
*/
int a,b;
/*
* Ask the user to input two numbers.
*/
printf("Enter two integers: ");
scanf("%d %d", &a, &b);
/*
* Compare the numbers.
*/
if (a > b)
{
printf("%d is greater than %d\n", a, b);
}
else if (b > a)
{
printf("%d is smaller than %d\n", a, b);
}
else
{
printf("%d is equal to %d\n", a, b);
}
/*
* Check if numbers are odd or even.
*/
if (a % 2 == 0)
{
printf("%d is an even number.\n", a);
}
else
{
printf("%d is an odd number.\n", b);
}
if (b % 2 == 0)
{
printf("%d is an even number.\n", a);
}
else
{
printf("%d is an odd number.\n", b);
}
// Uncomment the line below if compiling on Windows.
//getch();
return 0;
} |
the_stack_data/103266377.c | #include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main (){
setlocale(LC_ALL,"");
FILE *file;
file = fopen("string.txt", "a");
if(file == NULL){
printf("o arquivo nao existe e nao pode ser aberto");
return 0;}
fprintf(file, "NA TESTE\n");
char frase [] = "PEGA A SEJUANE SHRIMP\n";
fputs(frase, file);
char caractere = '3';
fputc(caractere, file);
fclose(file);
return 0;}
|
the_stack_data/135455.c | /*===- StandaloneFuzzTargetMain.c - standalone main() for fuzz targets. ---===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// This main() function can be linked to a fuzz target (i.e. a library
// that exports LLVMFuzzerTestOneInput() and possibly LLVMFuzzerInitialize())
// instead of libFuzzer. This main() function will not perform any fuzzing
// but will simply feed all input files one by one to the fuzz target.
//
// Use this file to provide reproducers for bugs when linking against libFuzzer
// or other fuzzing engine is undesirable.
//===----------------------------------------------------------------------===*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
__attribute__((weak)) extern int LLVMFuzzerInitialize(int *argc, char ***argv);
int main(int argc, char **argv) {
fprintf(stderr, "StandaloneFuzzTargetMain: running %d inputs\n", argc - 1);
if (LLVMFuzzerInitialize)
LLVMFuzzerInitialize(&argc, &argv);
for (int i = 1; i < argc; i++) {
fprintf(stderr, "Running: %s\n", argv[i]);
FILE *f = fopen(argv[i], "r");
assert(f);
fseek(f, 0, SEEK_END);
size_t len = ftell(f);
fseek(f, 0, SEEK_SET);
unsigned char *buf = (unsigned char*)malloc(len);
size_t n_read = fread(buf, 1, len, f);
assert(n_read == len);
LLVMFuzzerTestOneInput(buf, len);
free(buf);
fprintf(stderr, "Done: %s: (%zd bytes)\n", argv[i], n_read);
}
}
|
the_stack_data/112313.c | #include <stdio.h>
#include <string.h>
#include <stdlib.h>
int compareVersion(char *version1, char *version2)
{
int i1, i2, j1, j2, l1, l2;
long long res;
l1 = strlen(version1);
l2 = strlen(version2);
i1 = 0;
i2 = 0;
while (1) {
for (j1 = i1; version1[i1] && version1[i1] != '.'; i1++)
if (version1[j1] == '0')
j1++;
for (j2 = i2; version2[i2] && version2[i2] != '.'; i2++)
if (version2[j2] == '0')
j2++;
version1[i1] = version2[i2] = 0;
res = atoll(version1 + j1) - atoll(version2 + j2);
/* res = strcmp(version1 + j1, version2 + j2); */
if (res > 0)
return(1);
if (res < 0)
return(-1);
if (i1 == l1 && i2 == l2)
break;
if (i1 != l1)
i1++;
if (i2 != l2)
i2++;
}
return(0);
}
int main(void)
{
char v1[] = "1";
char v2[] = "1.1";
printf("%d\n", compareVersion(v1, v2));
return(0);
}
|
the_stack_data/170454110.c | #include <stdio.h>
/**
* main - entry point for program
*
* Description: print lower and uppercase chars
*
* Return: always 0 (success)
*/
int main(void)
{
int i;
for (i = 97; i < 123; i++)
putchar(i);
for (i = 65; i < 91; i++)
putchar(i);
putchar('\n');
return (0);
}
|
the_stack_data/19879.c | /*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2016 - 2018 Glenn Ruben Bakke
*
* 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.
*/
#if BLUETOOTH_SD
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "py/runtime.h"
#include "ble_drv.h"
#include "nrf_sdm.h"
#include "ble_gap.h"
#include "ble.h" // sd_ble_uuid_encode
#include "drivers/flash.h"
#include "mphalport.h"
#if MICROPY_HW_USB_CDC
#include "usb_cdc.h"
#endif
#define BLE_DRIVER_VERBOSE 0
#if BLE_DRIVER_VERBOSE
#define BLE_DRIVER_LOG printf
#else
#define BLE_DRIVER_LOG(...)
#endif
#define BLE_ADV_LENGTH_FIELD_SIZE 1
#define BLE_ADV_AD_TYPE_FIELD_SIZE 1
#define BLE_AD_TYPE_FLAGS_DATA_SIZE 1
#define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION))
#define UNIT_0_625_MS (625)
#define UNIT_10_MS (10000)
#define APP_CFG_NON_CONN_ADV_TIMEOUT 0 // Disable timeout.
#define NON_CONNECTABLE_ADV_INTERVAL MSEC_TO_UNITS(100, UNIT_0_625_MS)
#define BLE_MIN_CONN_INTERVAL MSEC_TO_UNITS(12, UNIT_0_625_MS)
#define BLE_MAX_CONN_INTERVAL MSEC_TO_UNITS(12, UNIT_0_625_MS)
#define BLE_SLAVE_LATENCY 0
#define BLE_CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS)
#if (BLUETOOTH_SD == 110)
#define MAX_TX_IN_PROGRESS (6)
#else
#define MAX_TX_IN_PROGRESS (10)
#endif
#if !defined(GATT_MTU_SIZE_DEFAULT) && defined(BLE_GATT_ATT_MTU_DEFAULT)
#define GATT_MTU_SIZE_DEFAULT BLE_GATT_ATT_MTU_DEFAULT
#endif
#define SD_TEST_OR_ENABLE() \
if (ble_drv_stack_enabled() == 0) { \
(void)ble_drv_stack_enable(); \
}
static volatile bool m_adv_in_progress;
static volatile uint8_t m_tx_in_progress;
static ble_drv_gap_evt_callback_t gap_event_handler;
static ble_drv_gatts_evt_callback_t gatts_event_handler;
static mp_obj_t mp_gap_observer;
static mp_obj_t mp_gatts_observer;
#if (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
static volatile bool m_primary_service_found;
static volatile bool m_characteristic_found;
static volatile bool m_write_done;
static volatile ble_drv_adv_evt_callback_t adv_event_handler;
static volatile ble_drv_gattc_evt_callback_t gattc_event_handler;
static volatile ble_drv_disc_add_service_callback_t disc_add_service_handler;
static volatile ble_drv_disc_add_char_callback_t disc_add_char_handler;
static volatile ble_drv_gattc_char_data_callback_t gattc_char_data_handle;
static mp_obj_t mp_adv_observer;
static mp_obj_t mp_gattc_observer;
static mp_obj_t mp_gattc_disc_service_observer;
static mp_obj_t mp_gattc_disc_char_observer;
static mp_obj_t mp_gattc_char_data_observer;
#endif
#if (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
#include "nrf_nvic.h"
#define BLE_GAP_ADV_MAX_SIZE 31
#define BLE_DRV_CONN_CONFIG_TAG 1
static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
static uint8_t m_scan_buffer[BLE_GAP_SCAN_BUFFER_MIN];
nrf_nvic_state_t nrf_nvic_state = {{0}, 0};
#endif
#if (BLUETOOTH_SD == 110)
void softdevice_assert_handler(uint32_t pc, uint16_t line_number, const uint8_t * p_file_name) {
BLE_DRIVER_LOG("ERROR: SoftDevice assert!!!");
}
#else
void softdevice_assert_handler(uint32_t id, uint32_t pc, uint32_t info) {
BLE_DRIVER_LOG("ERROR: SoftDevice assert!!!");
}
#endif
uint32_t ble_drv_stack_enable(void) {
m_adv_in_progress = false;
m_tx_in_progress = 0;
#if (BLUETOOTH_SD == 110)
#if BLUETOOTH_LFCLK_RC
uint32_t err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_RC_250_PPM_250MS_CALIBRATION,
softdevice_assert_handler);
#else
uint32_t err_code = sd_softdevice_enable(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM,
softdevice_assert_handler);
#endif // BLUETOOTH_LFCLK_RC
#endif // (BLUETOOTH_SD == 110)
#if (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
#if BLUETOOTH_LFCLK_RC
nrf_clock_lf_cfg_t clock_config = {
.source = NRF_CLOCK_LF_SRC_RC,
.rc_ctiv = 16,
.rc_temp_ctiv = 2,
.accuracy = NRF_CLOCK_LF_ACCURACY_250_PPM
};
#else
nrf_clock_lf_cfg_t clock_config = {
.source = NRF_CLOCK_LF_SRC_XTAL,
.rc_ctiv = 0,
.rc_temp_ctiv = 0,
.accuracy = NRF_CLOCK_LF_ACCURACY_20_PPM
};
#endif // BLUETOOTH_LFCLK_RC
uint32_t err_code = sd_softdevice_enable(&clock_config,
softdevice_assert_handler);
#endif // (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
BLE_DRIVER_LOG("SoftDevice enable status: " UINT_FMT "\n", (uint16_t)err_code);
err_code = sd_nvic_EnableIRQ(SD_EVT_IRQn);
BLE_DRIVER_LOG("IRQ enable status: " UINT_FMT "\n", (uint16_t)err_code);
#if (BLUETOOTH_SD == 110)
ble_enable_params_t ble_enable_params;
memset(&ble_enable_params, 0x00, sizeof(ble_enable_params));
ble_enable_params.gatts_enable_params.attr_tab_size = BLE_GATTS_ATTR_TAB_SIZE_DEFAULT;
ble_enable_params.gatts_enable_params.service_changed = 0;
#else
ble_cfg_t ble_conf;
uint32_t app_ram_start_cfg = 0x200039c0;
ble_conf.conn_cfg.conn_cfg_tag = BLE_DRV_CONN_CONFIG_TAG;
ble_conf.conn_cfg.params.gap_conn_cfg.conn_count = 2;
ble_conf.conn_cfg.params.gap_conn_cfg.event_length = 3;
err_code = sd_ble_cfg_set(BLE_CONN_CFG_GAP, &ble_conf, app_ram_start_cfg);
BLE_DRIVER_LOG("BLE_CONN_CFG_GAP status: " UINT_FMT "\n", (uint16_t)err_code);
memset(&ble_conf, 0, sizeof(ble_conf));
ble_conf.gap_cfg.role_count_cfg.periph_role_count = 1;
ble_conf.gap_cfg.role_count_cfg.central_role_count = 1;
ble_conf.gap_cfg.role_count_cfg.central_sec_count = 0;
err_code = sd_ble_cfg_set(BLE_GAP_CFG_ROLE_COUNT, &ble_conf, app_ram_start_cfg);
BLE_DRIVER_LOG("BLE_GAP_CFG_ROLE_COUNT status: " UINT_FMT "\n", (uint16_t)err_code);
memset(&ble_conf, 0, sizeof(ble_conf));
ble_conf.conn_cfg.conn_cfg_tag = BLE_DRV_CONN_CONFIG_TAG;
ble_conf.conn_cfg.params.gatts_conn_cfg.hvn_tx_queue_size = MAX_TX_IN_PROGRESS;
err_code = sd_ble_cfg_set(BLE_CONN_CFG_GATTS, &ble_conf, app_ram_start_cfg);
BLE_DRIVER_LOG("BLE_CONN_CFG_GATTS status: " UINT_FMT "\n", (uint16_t)err_code);
#endif
#if (BLUETOOTH_SD == 110)
err_code = sd_ble_enable(&ble_enable_params);
#else
uint32_t app_ram_start = 0x200039c0;
err_code = sd_ble_enable(&app_ram_start); // 8K SD headroom from linker script.
BLE_DRIVER_LOG("BLE ram size: " UINT_FMT "\n", (uint16_t)app_ram_start);
#endif
BLE_DRIVER_LOG("BLE enable status: " UINT_FMT "\n", (uint16_t)err_code);
// set up security mode
ble_gap_conn_params_t gap_conn_params;
ble_gap_conn_sec_mode_t sec_mode;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
const char device_name[] = "micr";
if ((err_code = sd_ble_gap_device_name_set(&sec_mode,
(const uint8_t *)device_name,
strlen(device_name))) != 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't apply GAP parameters"));
}
// set connection parameters
memset(&gap_conn_params, 0, sizeof(gap_conn_params));
gap_conn_params.min_conn_interval = BLE_MIN_CONN_INTERVAL;
gap_conn_params.max_conn_interval = BLE_MAX_CONN_INTERVAL;
gap_conn_params.slave_latency = BLE_SLAVE_LATENCY;
gap_conn_params.conn_sup_timeout = BLE_CONN_SUP_TIMEOUT;
if (sd_ble_gap_ppcp_set(&gap_conn_params) != 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't set PPCP parameters"));
}
return err_code;
}
void ble_drv_stack_disable(void) {
sd_softdevice_disable();
}
uint8_t ble_drv_stack_enabled(void) {
uint8_t is_enabled;
uint32_t err_code = sd_softdevice_is_enabled(&is_enabled);
(void)err_code;
BLE_DRIVER_LOG("Is enabled status: " UINT_FMT "\n", (uint16_t)err_code);
return is_enabled;
}
void ble_drv_address_get(ble_drv_addr_t * p_addr) {
SD_TEST_OR_ENABLE();
ble_gap_addr_t local_ble_addr;
#if (BLUETOOTH_SD == 110)
uint32_t err_code = sd_ble_gap_address_get(&local_ble_addr);
#else
uint32_t err_code = sd_ble_gap_addr_get(&local_ble_addr);
#endif
if (err_code != 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't query for the device address"));
}
BLE_DRIVER_LOG("ble address, type: " HEX2_FMT ", " \
"address: " HEX2_FMT ":" HEX2_FMT ":" HEX2_FMT ":" \
HEX2_FMT ":" HEX2_FMT ":" HEX2_FMT "\n", \
local_ble_addr.addr_type, \
local_ble_addr.addr[5], local_ble_addr.addr[4], local_ble_addr.addr[3], \
local_ble_addr.addr[2], local_ble_addr.addr[1], local_ble_addr.addr[0]);
p_addr->addr_type = local_ble_addr.addr_type;
memcpy(p_addr->addr, local_ble_addr.addr, 6);
}
bool ble_drv_uuid_add_vs(uint8_t * p_uuid, uint8_t * idx) {
SD_TEST_OR_ENABLE();
if (sd_ble_uuid_vs_add((ble_uuid128_t const *)p_uuid, idx) != 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't add Vendor Specific 128-bit UUID"));
}
return true;
}
bool ble_drv_service_add(ubluepy_service_obj_t * p_service_obj) {
SD_TEST_OR_ENABLE();
if (p_service_obj->p_uuid->type > BLE_UUID_TYPE_BLE) {
ble_uuid_t uuid;
uuid.type = p_service_obj->p_uuid->uuid_vs_idx;
uuid.uuid = p_service_obj->p_uuid->value[0];
uuid.uuid += p_service_obj->p_uuid->value[1] << 8;
if (sd_ble_gatts_service_add(p_service_obj->type,
&uuid,
&p_service_obj->handle) != 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't add Service"));
}
} else if (p_service_obj->p_uuid->type == BLE_UUID_TYPE_BLE) {
BLE_DRIVER_LOG("adding service\n");
ble_uuid_t uuid;
uuid.type = p_service_obj->p_uuid->type;
uuid.uuid = p_service_obj->p_uuid->value[0];
uuid.uuid += p_service_obj->p_uuid->value[1] << 8;
if (sd_ble_gatts_service_add(p_service_obj->type,
&uuid,
&p_service_obj->handle) != 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't add Service"));
}
}
return true;
}
bool ble_drv_characteristic_add(ubluepy_characteristic_obj_t * p_char_obj) {
ble_gatts_char_md_t char_md;
ble_gatts_attr_md_t cccd_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t uuid;
ble_gatts_attr_md_t attr_md;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.broadcast = (p_char_obj->props & UBLUEPY_PROP_BROADCAST) ? 1 : 0;
char_md.char_props.read = (p_char_obj->props & UBLUEPY_PROP_READ) ? 1 : 0;
char_md.char_props.write_wo_resp = (p_char_obj->props & UBLUEPY_PROP_WRITE_WO_RESP) ? 1 : 0;
char_md.char_props.write = (p_char_obj->props & UBLUEPY_PROP_WRITE) ? 1 : 0;
char_md.char_props.notify = (p_char_obj->props & UBLUEPY_PROP_NOTIFY) ? 1 : 0;
char_md.char_props.indicate = (p_char_obj->props & UBLUEPY_PROP_INDICATE) ? 1 : 0;
#if 0
char_md.char_props.auth_signed_wr = (p_char_obj->props & UBLUEPY_PROP_NOTIFY) ? 1 : 0;
#endif
char_md.p_char_user_desc = NULL;
char_md.p_char_pf = NULL;
char_md.p_user_desc_md = NULL;
char_md.p_sccd_md = NULL;
// if cccd
if (p_char_obj->attrs & UBLUEPY_ATTR_CCCD) {
memset(&cccd_md, 0, sizeof(cccd_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
cccd_md.vloc = BLE_GATTS_VLOC_STACK;
char_md.p_cccd_md = &cccd_md;
} else {
char_md.p_cccd_md = NULL;
}
uuid.type = p_char_obj->p_uuid->type;
uuid.uuid = p_char_obj->p_uuid->value[0];
uuid.uuid += p_char_obj->p_uuid->value[1] << 8;
memset(&attr_md, 0, sizeof(attr_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.rd_auth = 0;
attr_md.wr_auth = 0;
attr_md.vlen = 1;
memset(&attr_char_value, 0, sizeof(attr_char_value));
attr_char_value.p_uuid = &uuid;
attr_char_value.p_attr_md = &attr_md;
attr_char_value.init_len = sizeof(uint8_t);
attr_char_value.init_offs = 0;
attr_char_value.max_len = (GATT_MTU_SIZE_DEFAULT - 3);
ble_gatts_char_handles_t handles;
if (sd_ble_gatts_characteristic_add(p_char_obj->service_handle,
&char_md,
&attr_char_value,
&handles) != 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't add Characteristic"));
}
// apply handles to object instance
p_char_obj->handle = handles.value_handle;
p_char_obj->user_desc_handle = handles.user_desc_handle;
p_char_obj->cccd_handle = handles.cccd_handle;
p_char_obj->sccd_handle = handles.sccd_handle;
return true;
}
bool ble_drv_advertise_data(ubluepy_advertise_data_t * p_adv_params) {
SD_TEST_OR_ENABLE();
uint8_t byte_pos = 0;
static uint8_t adv_data[BLE_GAP_ADV_MAX_SIZE];
if (p_adv_params->device_name_len > 0) {
ble_gap_conn_sec_mode_t sec_mode;
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);
if (sd_ble_gap_device_name_set(&sec_mode,
p_adv_params->p_device_name,
p_adv_params->device_name_len) != 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't apply device name in the stack"));
}
BLE_DRIVER_LOG("Device name applied\n");
adv_data[byte_pos] = (BLE_ADV_AD_TYPE_FIELD_SIZE + p_adv_params->device_name_len);
byte_pos += BLE_ADV_LENGTH_FIELD_SIZE;
adv_data[byte_pos] = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME;
byte_pos += BLE_ADV_AD_TYPE_FIELD_SIZE;
memcpy(&adv_data[byte_pos], p_adv_params->p_device_name, p_adv_params->device_name_len);
// increment position counter to see if it fits, and in case more content should
// follow in this adv packet.
byte_pos += p_adv_params->device_name_len;
}
// Add FLAGS only if manually controlled data has not been used.
if (p_adv_params->data_len == 0) {
// set flags, default to disc mode
adv_data[byte_pos] = (BLE_ADV_AD_TYPE_FIELD_SIZE + BLE_AD_TYPE_FLAGS_DATA_SIZE);
byte_pos += BLE_ADV_LENGTH_FIELD_SIZE;
adv_data[byte_pos] = BLE_GAP_AD_TYPE_FLAGS;
byte_pos += BLE_AD_TYPE_FLAGS_DATA_SIZE;
adv_data[byte_pos] = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;
byte_pos += 1;
}
if (p_adv_params->num_of_services > 0) {
bool type_16bit_present = false;
bool type_128bit_present = false;
for (uint8_t i = 0; i < p_adv_params->num_of_services; i++) {
ubluepy_service_obj_t * p_service = (ubluepy_service_obj_t *)p_adv_params->p_services[i];
if (p_service->p_uuid->type == UBLUEPY_UUID_16_BIT) {
type_16bit_present = true;
}
if (p_service->p_uuid->type == UBLUEPY_UUID_128_BIT) {
type_128bit_present = true;
}
}
if (type_16bit_present) {
uint8_t size_byte_pos = byte_pos;
// skip length byte for now, apply total length post calculation
byte_pos += BLE_ADV_LENGTH_FIELD_SIZE;
adv_data[byte_pos] = BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE;
byte_pos += BLE_ADV_AD_TYPE_FIELD_SIZE;
uint8_t uuid_total_size = 0;
uint8_t encoded_size = 0;
for (uint8_t i = 0; i < p_adv_params->num_of_services; i++) {
ubluepy_service_obj_t * p_service = (ubluepy_service_obj_t *)p_adv_params->p_services[i];
ble_uuid_t uuid;
uuid.type = p_service->p_uuid->type;
uuid.uuid = p_service->p_uuid->value[0];
uuid.uuid += p_service->p_uuid->value[1] << 8;
// calculate total size of uuids
if (sd_ble_uuid_encode(&uuid, &encoded_size, NULL) != 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't encode UUID, to check length"));
}
// do encoding into the adv buffer
if (sd_ble_uuid_encode(&uuid, &encoded_size, &adv_data[byte_pos]) != 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't encode UUID into advertisment packet"));
}
BLE_DRIVER_LOG("encoded uuid for service %u: ", 0);
for (uint8_t j = 0; j < encoded_size; j++) {
BLE_DRIVER_LOG(HEX2_FMT " ", adv_data[byte_pos + j]);
}
BLE_DRIVER_LOG("\n");
uuid_total_size += encoded_size; // size of entry
byte_pos += encoded_size; // relative to adv data packet
BLE_DRIVER_LOG("ADV: uuid size: %u, type: %u, uuid: %x%x, vs_idx: %u\n",
encoded_size, p_service->p_uuid->type,
p_service->p_uuid->value[1],
p_service->p_uuid->value[0],
p_service->p_uuid->uuid_vs_idx);
}
adv_data[size_byte_pos] = (BLE_ADV_AD_TYPE_FIELD_SIZE + uuid_total_size);
}
if (type_128bit_present) {
uint8_t size_byte_pos = byte_pos;
// skip length byte for now, apply total length post calculation
byte_pos += BLE_ADV_LENGTH_FIELD_SIZE;
adv_data[byte_pos] = BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE;
byte_pos += BLE_ADV_AD_TYPE_FIELD_SIZE;
uint8_t uuid_total_size = 0;
uint8_t encoded_size = 0;
for (uint8_t i = 0; i < p_adv_params->num_of_services; i++) {
ubluepy_service_obj_t * p_service = (ubluepy_service_obj_t *)p_adv_params->p_services[i];
ble_uuid_t uuid;
uuid.type = p_service->p_uuid->uuid_vs_idx;
uuid.uuid = p_service->p_uuid->value[0];
uuid.uuid += p_service->p_uuid->value[1] << 8;
// calculate total size of uuids
if (sd_ble_uuid_encode(&uuid, &encoded_size, NULL) != 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't encode UUID, to check length"));
}
// do encoding into the adv buffer
if (sd_ble_uuid_encode(&uuid, &encoded_size, &adv_data[byte_pos]) != 0) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't encode UUID into advertisment packet"));
}
BLE_DRIVER_LOG("encoded uuid for service %u: ", 0);
for (uint8_t j = 0; j < encoded_size; j++) {
BLE_DRIVER_LOG(HEX2_FMT " ", adv_data[byte_pos + j]);
}
BLE_DRIVER_LOG("\n");
uuid_total_size += encoded_size; // size of entry
byte_pos += encoded_size; // relative to adv data packet
BLE_DRIVER_LOG("ADV: uuid size: %u, type: %x%x, uuid: %u, vs_idx: %u\n",
encoded_size, p_service->p_uuid->type,
p_service->p_uuid->value[1],
p_service->p_uuid->value[0],
p_service->p_uuid->uuid_vs_idx);
}
adv_data[size_byte_pos] = (BLE_ADV_AD_TYPE_FIELD_SIZE + uuid_total_size);
}
}
if ((p_adv_params->data_len > 0) && (p_adv_params->p_data != NULL)) {
if (p_adv_params->data_len + byte_pos > BLE_GAP_ADV_MAX_SIZE) {
mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("can't fit data into advertisment packet"));
}
memcpy(adv_data, p_adv_params->p_data, p_adv_params->data_len);
byte_pos += p_adv_params->data_len;
}
// scan response data not set
uint32_t err_code;
#if (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
const ble_gap_adv_data_t m_adv_data = {
.adv_data.p_data = adv_data,
.adv_data.len = byte_pos,
.scan_rsp_data.p_data = NULL,
.scan_rsp_data.len = 0
};
#endif
static ble_gap_adv_params_t m_adv_params;
memset(&m_adv_params, 0, sizeof(m_adv_params));
// initialize advertising params
if (p_adv_params->connectable) {
#if (BLUETOOTH_SD == 110)
m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND;
#else
m_adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
#endif
} else {
#if (BLUETOOTH_SD == 110)
m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_NONCONN_IND;
#else
m_adv_params.properties.type = BLE_GAP_ADV_TYPE_NONCONNECTABLE_SCANNABLE_UNDIRECTED;
#endif
}
#if (BLUETOOTH_SD == 110)
m_adv_params.fp = BLE_GAP_ADV_FP_ANY;
m_adv_params.timeout = 0; // infinite advertisment
#else
m_adv_params.properties.anonymous = 0;
m_adv_params.properties.include_tx_power = 0;
m_adv_params.filter_policy = 0;
m_adv_params.max_adv_evts = 0; // infinite advertisment
m_adv_params.primary_phy = BLE_GAP_PHY_AUTO;
m_adv_params.secondary_phy = BLE_GAP_PHY_AUTO;
m_adv_params.scan_req_notification = 0; // Do not raise scan request notifications when scanned.
#endif
m_adv_params.p_peer_addr = NULL; // undirected advertisement
m_adv_params.interval = MSEC_TO_UNITS(100, UNIT_0_625_MS); // approx 8 ms
#if (BLUETOOTH_SD == 110)
if ((err_code = sd_ble_gap_adv_data_set(adv_data, byte_pos, NULL, 0)) != 0) {
mp_raise_msg_varg(&mp_type_OSError,
MP_ERROR_TEXT("Can not apply advertisment data. status: 0x" HEX2_FMT), (uint16_t)err_code);
}
#else
if ((err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params)) != 0) {
mp_raise_msg_varg(&mp_type_OSError,
MP_ERROR_TEXT("Can not apply advertisment data. status: 0x" HEX2_FMT), (uint16_t)err_code);
}
#endif
BLE_DRIVER_LOG("Set Adv data size: " UINT_FMT "\n", byte_pos);
ble_drv_advertise_stop();
#if (BLUETOOTH_SD == 110)
err_code = sd_ble_gap_adv_start(&m_adv_params);
#else
uint8_t conf_tag = BLE_DRV_CONN_CONFIG_TAG; // Could also be set to tag from sd_ble_cfg_set
err_code = sd_ble_gap_adv_start(m_adv_handle, conf_tag);
#endif
if (err_code != 0) {
mp_raise_msg_varg(&mp_type_OSError,
MP_ERROR_TEXT("Can not start advertisment. status: 0x" HEX2_FMT), (uint16_t)err_code);
}
m_adv_in_progress = true;
return true;
}
void ble_drv_advertise_stop(void) {
if (m_adv_in_progress == true) {
uint32_t err_code;
#if (BLUETOOTH_SD == 110)
if ((err_code = sd_ble_gap_adv_stop()) != 0) {
mp_raise_msg_varg(&mp_type_OSError,
MP_ERROR_TEXT("Can not stop advertisment. status: 0x" HEX2_FMT), (uint16_t)err_code);
}
#else
if ((err_code = sd_ble_gap_adv_stop(m_adv_handle)) != 0) {
mp_raise_msg_varg(&mp_type_OSError,
MP_ERROR_TEXT("Can not stop advertisment. status: 0x" HEX2_FMT), (uint16_t)err_code);
}
#endif
}
m_adv_in_progress = false;
}
void ble_drv_attr_s_read(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data) {
ble_gatts_value_t gatts_value;
memset(&gatts_value, 0, sizeof(gatts_value));
gatts_value.len = len;
gatts_value.offset = 0;
gatts_value.p_value = p_data;
uint32_t err_code = sd_ble_gatts_value_get(conn_handle,
handle,
&gatts_value);
if (err_code != 0) {
mp_raise_msg_varg(&mp_type_OSError,
MP_ERROR_TEXT("Can not read attribute value. status: 0x" HEX2_FMT), (uint16_t)err_code);
}
}
void ble_drv_attr_s_write(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data) {
ble_gatts_value_t gatts_value;
memset(&gatts_value, 0, sizeof(gatts_value));
gatts_value.len = len;
gatts_value.offset = 0;
gatts_value.p_value = p_data;
uint32_t err_code = sd_ble_gatts_value_set(conn_handle, handle, &gatts_value);
if (err_code != 0) {
mp_raise_msg_varg(&mp_type_OSError,
MP_ERROR_TEXT("Can not write attribute value. status: 0x" HEX2_FMT), (uint16_t)err_code);
}
}
void ble_drv_attr_s_notify(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data) {
uint16_t hvx_len = len;
ble_gatts_hvx_params_t hvx_params;
memset(&hvx_params, 0, sizeof(hvx_params));
hvx_params.handle = handle;
hvx_params.type = BLE_GATT_HVX_NOTIFICATION;
hvx_params.offset = 0;
hvx_params.p_len = &hvx_len;
hvx_params.p_data = p_data;
while (m_tx_in_progress > MAX_TX_IN_PROGRESS) {
;
}
BLE_DRIVER_LOG("Request TX, m_tx_in_progress: %u\n", m_tx_in_progress);
uint32_t err_code;
if ((err_code = sd_ble_gatts_hvx(conn_handle, &hvx_params)) != 0) {
mp_raise_msg_varg(&mp_type_OSError,
MP_ERROR_TEXT("Can not notify attribute value. status: 0x" HEX2_FMT), (uint16_t)err_code);
}
m_tx_in_progress++;
BLE_DRIVER_LOG("Queued TX, m_tx_in_progress: %u\n", m_tx_in_progress);
}
void ble_drv_gap_event_handler_set(mp_obj_t obj, ble_drv_gap_evt_callback_t evt_handler) {
mp_gap_observer = obj;
gap_event_handler = evt_handler;
}
void ble_drv_gatts_event_handler_set(mp_obj_t obj, ble_drv_gatts_evt_callback_t evt_handler) {
mp_gatts_observer = obj;
gatts_event_handler = evt_handler;
}
#if (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
void ble_drv_gattc_event_handler_set(mp_obj_t obj, ble_drv_gattc_evt_callback_t evt_handler) {
mp_gattc_observer = obj;
gattc_event_handler = evt_handler;
}
void ble_drv_adv_report_handler_set(mp_obj_t obj, ble_drv_adv_evt_callback_t evt_handler) {
mp_adv_observer = obj;
adv_event_handler = evt_handler;
}
void ble_drv_attr_c_read(uint16_t conn_handle, uint16_t handle, mp_obj_t obj, ble_drv_gattc_char_data_callback_t cb) {
mp_gattc_char_data_observer = obj;
gattc_char_data_handle = cb;
uint32_t err_code = sd_ble_gattc_read(conn_handle,
handle,
0);
if (err_code != 0) {
mp_raise_msg_varg(&mp_type_OSError,
MP_ERROR_TEXT("Can not read attribute value. status: 0x" HEX2_FMT), (uint16_t)err_code);
}
while (gattc_char_data_handle != NULL) {
;
}
}
void ble_drv_attr_c_write(uint16_t conn_handle, uint16_t handle, uint16_t len, uint8_t * p_data, bool w_response) {
ble_gattc_write_params_t write_params;
if (w_response) {
write_params.write_op = BLE_GATT_OP_WRITE_REQ;
} else {
write_params.write_op = BLE_GATT_OP_WRITE_CMD;
}
write_params.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_CANCEL;
write_params.handle = handle;
write_params.offset = 0;
write_params.len = len;
write_params.p_value = p_data;
m_write_done = !w_response;
uint32_t err_code = sd_ble_gattc_write(conn_handle, &write_params);
if (err_code != 0) {
mp_raise_msg_varg(&mp_type_OSError,
MP_ERROR_TEXT("Can not write attribute value. status: 0x" HEX2_FMT), (uint16_t)err_code);
}
while (m_write_done != true) {
;
}
}
void ble_drv_scan_start(bool cont) {
SD_TEST_OR_ENABLE();
ble_gap_scan_params_t scan_params;
memset(&scan_params, 0, sizeof(ble_gap_scan_params_t));
scan_params.extended = 0;
scan_params.active = 1;
scan_params.interval = MSEC_TO_UNITS(100, UNIT_0_625_MS);
scan_params.window = MSEC_TO_UNITS(100, UNIT_0_625_MS);
scan_params.timeout = 0; // Infinite
ble_data_t scan_buffer = {
.p_data = m_scan_buffer,
.len = BLE_GAP_SCAN_BUFFER_MIN
};
uint32_t err_code;
ble_gap_scan_params_t * p_scan_params = &scan_params;
if (cont) {
p_scan_params = NULL;
}
if ((err_code = sd_ble_gap_scan_start(p_scan_params, &scan_buffer)) != 0) {
mp_raise_msg_varg(&mp_type_OSError,
MP_ERROR_TEXT("Can not start scanning. status: 0x" HEX2_FMT), (uint16_t)err_code);
}
}
void ble_drv_scan_stop(void) {
sd_ble_gap_scan_stop();
}
void ble_drv_connect(uint8_t * p_addr, uint8_t addr_type) {
SD_TEST_OR_ENABLE();
ble_gap_scan_params_t scan_params;
memset(&scan_params, 0, sizeof(ble_gap_scan_params_t));
scan_params.extended = 0;
scan_params.active = 1;
scan_params.interval = MSEC_TO_UNITS(100, UNIT_0_625_MS);
scan_params.window = MSEC_TO_UNITS(100, UNIT_0_625_MS);
scan_params.timeout = 0; // infinite
ble_gap_addr_t addr;
memset(&addr, 0, sizeof(addr));
addr.addr_type = addr_type;
memcpy(addr.addr, p_addr, 6);
BLE_DRIVER_LOG("GAP CONNECTING: "HEX2_FMT":"HEX2_FMT":"HEX2_FMT":"HEX2_FMT":"HEX2_FMT":"HEX2_FMT", type: %d\n",
addr.addr[0], addr.addr[1], addr.addr[2], addr.addr[3], addr.addr[4], addr.addr[5], addr.addr_type);
ble_gap_conn_params_t conn_params;
// set connection parameters
memset(&conn_params, 0, sizeof(conn_params));
conn_params.min_conn_interval = BLE_MIN_CONN_INTERVAL;
conn_params.max_conn_interval = BLE_MAX_CONN_INTERVAL;
conn_params.slave_latency = BLE_SLAVE_LATENCY;
conn_params.conn_sup_timeout = BLE_CONN_SUP_TIMEOUT;
uint8_t conn_tag = BLE_DRV_CONN_CONFIG_TAG;
uint32_t err_code;
if ((err_code = sd_ble_gap_connect(&addr,
&scan_params,
&conn_params,
conn_tag)) != 0) {
mp_raise_msg_varg(&mp_type_OSError,
MP_ERROR_TEXT("Can not connect. status: 0x" HEX2_FMT), (uint16_t)err_code);
}
}
bool ble_drv_discover_services(mp_obj_t obj, uint16_t conn_handle, uint16_t start_handle, ble_drv_disc_add_service_callback_t cb) {
BLE_DRIVER_LOG("Discover primary services. Conn handle: 0x" HEX2_FMT "\n",
conn_handle);
mp_gattc_disc_service_observer = obj;
disc_add_service_handler = cb;
m_primary_service_found = false;
uint32_t err_code;
err_code = sd_ble_gattc_primary_services_discover(conn_handle,
start_handle,
NULL);
if (err_code != 0) {
return false;
}
// busy loop until last service has been iterated
while (disc_add_service_handler != NULL) {
;
}
if (m_primary_service_found) {
return true;
} else {
return false;
}
}
bool ble_drv_discover_characteristic(mp_obj_t obj,
uint16_t conn_handle,
uint16_t start_handle,
uint16_t end_handle,
ble_drv_disc_add_char_callback_t cb) {
BLE_DRIVER_LOG("Discover characteristicts. Conn handle: 0x" HEX2_FMT "\n",
conn_handle);
mp_gattc_disc_char_observer = obj;
disc_add_char_handler = cb;
ble_gattc_handle_range_t handle_range;
handle_range.start_handle = start_handle;
handle_range.end_handle = end_handle;
m_characteristic_found = false;
uint32_t err_code;
err_code = sd_ble_gattc_characteristics_discover(conn_handle, &handle_range);
if (err_code != 0) {
return false;
}
// busy loop until last service has been iterated
while (disc_add_char_handler != NULL) {
;
}
if (m_characteristic_found) {
return true;
} else {
return false;
}
}
void ble_drv_discover_descriptors(void) {
}
#endif // (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
static void sd_evt_handler(uint32_t evt_id) {
switch (evt_id) {
#if MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE || MICROPY_MBFS
case NRF_EVT_FLASH_OPERATION_SUCCESS:
flash_operation_finished(FLASH_STATE_SUCCESS);
break;
case NRF_EVT_FLASH_OPERATION_ERROR:
flash_operation_finished(FLASH_STATE_ERROR);
break;
#endif
default:
// unhandled event!
break;
}
#if MICROPY_HW_USB_CDC
// Farward SOC events to USB CDC driver.
usb_cdc_sd_event_handler(evt_id);
#endif
}
static void ble_evt_handler(ble_evt_t * p_ble_evt) {
// S132 event ranges.
// Common 0x01 -> 0x0F
// GAP 0x10 -> 0x2F
// GATTC 0x30 -> 0x4F
// GATTS 0x50 -> 0x6F
// L2CAP 0x70 -> 0x8F
switch (p_ble_evt->header.evt_id) {
case BLE_GAP_EVT_CONNECTED:
BLE_DRIVER_LOG("GAP CONNECT\n");
m_adv_in_progress = false;
gap_event_handler(mp_gap_observer, p_ble_evt->header.evt_id, p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->header.evt_len - (2 * sizeof(uint16_t)), NULL);
ble_gap_conn_params_t conn_params;
(void)sd_ble_gap_ppcp_get(&conn_params);
(void)sd_ble_gap_conn_param_update(p_ble_evt->evt.gap_evt.conn_handle, &conn_params);
break;
case BLE_GAP_EVT_DISCONNECTED:
BLE_DRIVER_LOG("GAP DISCONNECT\n");
gap_event_handler(mp_gap_observer, p_ble_evt->header.evt_id, p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->header.evt_len - (2 * sizeof(uint16_t)), NULL);
break;
case BLE_GATTS_EVT_HVC:
gatts_event_handler(mp_gatts_observer, p_ble_evt->header.evt_id, p_ble_evt->evt.gatts_evt.params.hvc.handle, p_ble_evt->header.evt_len - (2 * sizeof(uint16_t)), NULL);
break;
case BLE_GATTS_EVT_WRITE:
BLE_DRIVER_LOG("GATTS write\n");
uint16_t handle = p_ble_evt->evt.gatts_evt.params.write.handle;
uint16_t data_len = p_ble_evt->evt.gatts_evt.params.write.len;
uint8_t * p_data = &p_ble_evt->evt.gatts_evt.params.write.data[0];
gatts_event_handler(mp_gatts_observer, p_ble_evt->header.evt_id, handle, data_len, p_data);
break;
case BLE_GAP_EVT_CONN_PARAM_UPDATE:
BLE_DRIVER_LOG("GAP CONN PARAM UPDATE\n");
break;
case BLE_GATTS_EVT_SYS_ATTR_MISSING:
// No system attributes have been stored.
(void)sd_ble_gatts_sys_attr_set(p_ble_evt->evt.gatts_evt.conn_handle, NULL, 0, 0);
break;
#if (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
case BLE_GATTS_EVT_HVN_TX_COMPLETE:
#else
case BLE_EVT_TX_COMPLETE:
#endif
BLE_DRIVER_LOG("BLE EVT TX COMPLETE\n");
#if (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
BLE_DRIVER_LOG("HVN_TX_COMPLETE, count: %u\n", p_ble_evt->evt.gatts_evt.params.hvn_tx_complete.count);
m_tx_in_progress -= p_ble_evt->evt.gatts_evt.params.hvn_tx_complete.count;
BLE_DRIVER_LOG("TX_COMPLETE, m_tx_in_progress: %u\n", m_tx_in_progress);
#else
BLE_DRIVER_LOG("TX_COMPLETE, count: %u\n", p_ble_evt->evt.common_evt.params.tx_complete.count);
m_tx_in_progress -= p_ble_evt->evt.common_evt.params.tx_complete.count;
BLE_DRIVER_LOG("TX_COMPLETE, m_tx_in_progress: %u\n", m_tx_in_progress);
#endif
break;
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
BLE_DRIVER_LOG("BLE EVT SEC PARAMS REQUEST\n");
// pairing not supported
(void)sd_ble_gap_sec_params_reply(p_ble_evt->evt.gatts_evt.conn_handle,
BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP,
NULL, NULL);
break;
#if (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
case BLE_GAP_EVT_ADV_REPORT:
BLE_DRIVER_LOG("BLE EVT ADV REPORT\n");
ble_drv_adv_data_t adv_data = {
.p_peer_addr = p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr,
.addr_type = p_ble_evt->evt.gap_evt.params.adv_report.peer_addr.addr_type,
.is_scan_resp = p_ble_evt->evt.gap_evt.params.adv_report.type.scan_response,
.rssi = p_ble_evt->evt.gap_evt.params.adv_report.rssi,
.data_len = p_ble_evt->evt.gap_evt.params.adv_report.data.len,
.p_data = p_ble_evt->evt.gap_evt.params.adv_report.data.p_data,
// .adv_type =
};
// TODO: Fix unsafe callback to possible undefined callback...
adv_event_handler(mp_adv_observer,
p_ble_evt->header.evt_id,
&adv_data);
break;
case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST:
BLE_DRIVER_LOG("BLE EVT CONN PARAM UPDATE REQUEST\n");
(void)sd_ble_gap_conn_param_update(p_ble_evt->evt.gap_evt.conn_handle,
&p_ble_evt->evt.gap_evt.params.conn_param_update_request.conn_params);
break;
case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:
BLE_DRIVER_LOG("BLE EVT PRIMARY SERVICE DISCOVERY RESPONSE\n");
BLE_DRIVER_LOG(">>> service count: %d\n", p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.count);
for (uint16_t i = 0; i < p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.count; i++) {
ble_gattc_service_t * p_service = &p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.services[i];
ble_drv_service_data_t service;
service.uuid_type = p_service->uuid.type;
service.uuid = p_service->uuid.uuid;
service.start_handle = p_service->handle_range.start_handle;
service.end_handle = p_service->handle_range.end_handle;
disc_add_service_handler(mp_gattc_disc_service_observer, &service);
}
if (p_ble_evt->evt.gattc_evt.params.prim_srvc_disc_rsp.count > 0) {
m_primary_service_found = true;
}
// mark end of service discovery
disc_add_service_handler = NULL;
break;
case BLE_GATTC_EVT_CHAR_DISC_RSP:
BLE_DRIVER_LOG("BLE EVT CHAR DISCOVERY RESPONSE\n");
BLE_DRIVER_LOG(">>> characteristic count: %d\n", p_ble_evt->evt.gattc_evt.params.char_disc_rsp.count);
for (uint16_t i = 0; i < p_ble_evt->evt.gattc_evt.params.char_disc_rsp.count; i++) {
ble_gattc_char_t * p_char = &p_ble_evt->evt.gattc_evt.params.char_disc_rsp.chars[i];
ble_drv_char_data_t char_data;
char_data.uuid_type = p_char->uuid.type;
char_data.uuid = p_char->uuid.uuid;
char_data.decl_handle = p_char->handle_decl;
char_data.value_handle = p_char->handle_value;
char_data.props = (p_char->char_props.broadcast) ? UBLUEPY_PROP_BROADCAST : 0;
char_data.props |= (p_char->char_props.read) ? UBLUEPY_PROP_READ : 0;
char_data.props |= (p_char->char_props.write_wo_resp) ? UBLUEPY_PROP_WRITE_WO_RESP : 0;
char_data.props |= (p_char->char_props.write) ? UBLUEPY_PROP_WRITE : 0;
char_data.props |= (p_char->char_props.notify) ? UBLUEPY_PROP_NOTIFY : 0;
char_data.props |= (p_char->char_props.indicate) ? UBLUEPY_PROP_INDICATE : 0;
#if 0
char_data.props |= (p_char->char_props.auth_signed_wr) ? UBLUEPY_PROP_NOTIFY : 0;
#endif
disc_add_char_handler(mp_gattc_disc_char_observer, &char_data);
}
if (p_ble_evt->evt.gattc_evt.params.char_disc_rsp.count > 0) {
m_characteristic_found = true;
}
// mark end of characteristic discovery
disc_add_char_handler = NULL;
break;
case BLE_GATTC_EVT_READ_RSP:
BLE_DRIVER_LOG("BLE EVT READ RESPONSE, offset: 0x"HEX2_FMT", length: 0x"HEX2_FMT"\n",
p_ble_evt->evt.gattc_evt.params.read_rsp.offset,
p_ble_evt->evt.gattc_evt.params.read_rsp.len);
gattc_char_data_handle(mp_gattc_char_data_observer,
p_ble_evt->evt.gattc_evt.params.read_rsp.len,
p_ble_evt->evt.gattc_evt.params.read_rsp.data);
// mark end of read
gattc_char_data_handle = NULL;
break;
case BLE_GATTC_EVT_WRITE_RSP:
BLE_DRIVER_LOG("BLE EVT WRITE RESPONSE\n");
m_write_done = true;
break;
case BLE_GATTC_EVT_HVX:
BLE_DRIVER_LOG("BLE EVT HVX RESPONSE\n");
break;
case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
BLE_DRIVER_LOG("GATTS EVT EXCHANGE MTU REQUEST\n");
(void)sd_ble_gatts_exchange_mtu_reply(p_ble_evt->evt.gatts_evt.conn_handle, 23); // MAX MTU size
break;
case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST:
BLE_DRIVER_LOG("BLE GAP EVT DATA LENGTH UPDATE REQUEST\n");
sd_ble_gap_data_length_update(p_ble_evt->evt.gap_evt.conn_handle, NULL, NULL);
break;
case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
BLE_DRIVER_LOG("BLE_GAP_EVT_PHY_UPDATE_REQUEST\n");
ble_gap_phys_t const phys =
{
BLE_GAP_PHY_AUTO,
BLE_GAP_PHY_AUTO,
};
sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
break;
case BLE_GAP_EVT_PHY_UPDATE:
BLE_DRIVER_LOG("BLE_GAP_EVT_PHY_UPDATE -- unhandled!\n");
break;
case BLE_GAP_EVT_DATA_LENGTH_UPDATE:
BLE_DRIVER_LOG("BLE_GAP_EVT_DATA_LENGTH_UPDATE -- unhandled!\n");
break;
#endif // (BLUETOOTH_SD == 132) || (BLUETOOTH_SD == 140)
default:
BLE_DRIVER_LOG(">>> unhandled evt: 0x" HEX2_FMT "\n", p_ble_evt->header.evt_id);
break;
}
}
static uint8_t m_ble_evt_buf[sizeof(ble_evt_t) + (GATT_MTU_SIZE_DEFAULT)] __attribute__ ((aligned (4)));
#ifdef NRF51
void SWI2_IRQHandler(void) {
#else
void SWI2_EGU2_IRQHandler(void) {
#endif
uint32_t evt_id;
while (sd_evt_get(&evt_id) != NRF_ERROR_NOT_FOUND) {
sd_evt_handler(evt_id);
}
while (1) {
uint16_t evt_len = sizeof(m_ble_evt_buf);
uint32_t err_code = sd_ble_evt_get(m_ble_evt_buf, &evt_len);
if (err_code != NRF_SUCCESS) {
// Possible error conditions:
// * NRF_ERROR_NOT_FOUND: no events left, break
// * NRF_ERROR_DATA_SIZE: retry with a bigger data buffer
// (currently not handled, TODO)
// * NRF_ERROR_INVALID_ADDR: pointer is not aligned, should
// not happen.
// In all cases, it's best to simply stop now.
if (err_code == NRF_ERROR_DATA_SIZE) {
BLE_DRIVER_LOG("NRF_ERROR_DATA_SIZE\n");
}
break;
}
ble_evt_handler((ble_evt_t *)m_ble_evt_buf);
}
}
#endif // BLUETOOTH_SD
|
the_stack_data/137906.c | /**************************************************************
* Copyright (C) 2014-2018 All rights reserved.
* @Version: 1.0
* @Created: 2018-08-10 23:37
* @Author: SamLiu - [email protected]
* @Description:
*
* @History:
**************************************************************/
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct msgbuf {
long mtype;
char mtext[255];
};
int main() {
// 1. 获取消息队列
int msg_id = msgget(123, IPC_CREAT | 0666);
if (msg_id != -1) {
struct msgbuf mybuf;
// 2. 接收第一条消息,存到 mybuf 中
for(;;)
{
if (msgrcv(msg_id, &mybuf, sizeof(mybuf.mtext), 0, IPC_NOWAIT) != -1) {
printf("read success: %s\n", mybuf.mtext);
// 3. 接收完就删除这个消息队列
} else {
perror("msgsnd:");
}
}
if (msgctl(msg_id, IPC_RMID, 0) != -1)
printf("delete msg success\n");
} else {
perror("msgget:");
}
return 0;
}
|
the_stack_data/1121095.c | /*****************************************************************************
* mpegdemux *
*****************************************************************************/
/*****************************************************************************
* File name: mpeg_parse.c *
* Created: 2003-02-01 by Hampa Hug <[email protected]> *
* Last modified: 2003-09-10 by Hampa Hug <[email protected]> *
* Copyright: (C) 2003 by Hampa Hug <[email protected]> *
*****************************************************************************/
/*****************************************************************************
* This program is free software. You can redistribute it and / or modify it *
* under the terms of the GNU General Public License version 2 as published *
* by the Free Software Foundation. *
* *
* This program is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY, without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General *
* Public License for more details. *
*****************************************************************************/
/* $Id: mpeg_parse.c 67 2004-01-02 18:20:15Z hampa $ */
// The code has been modified to use file descriptors instead of FILE streams.
// Only functionality needed in MediaTomb remains, all extra features are
// stripped out.
#ifdef HAVE_CONFIG_H
#include "autoconfig.h"
#endif
#ifdef HAVE_LIBDVDNAV
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "mpeg_parse.h"
mpeg_demux_t *mpegd_open_fd (mpeg_demux_t *mpeg, int fd, int close_file)
{
if (mpeg == NULL) {
mpeg = (mpeg_demux_t *) malloc (sizeof (mpeg_demux_t));
if (mpeg == NULL) {
return (NULL);
}
mpeg->free = 1;
}
else {
mpeg->free = 0;
}
mpeg->fd = fd;
mpeg->close = close_file;
mpeg->ofs = 0;
mpeg->buf_i = 0;
mpeg->buf_n = 0;
mpeg->ext = -1;
mpeg->mpeg_skip = NULL;
mpeg->mpeg_system_header = NULL;
mpeg->mpeg_packet = NULL;
mpeg->mpeg_packet_check = NULL;
mpeg->mpeg_pack = NULL;
mpeg->mpeg_end = NULL;
mpegd_reset_stats (mpeg);
return (mpeg);
}
mpeg_demux_t *mpegd_open (mpeg_demux_t *mpeg, const char *fname)
{
int fd;
fd = open (fname, O_RDONLY);
if (fd == -1) {
return (NULL);
}
mpeg = mpegd_open_fd (mpeg, fd, 1);
return (mpeg);
}
void mpegd_close (mpeg_demux_t *mpeg)
{
if (mpeg->close) {
close (mpeg->fd);
}
if (mpeg->free) {
free (mpeg);
}
}
void mpegd_reset_stats (mpeg_demux_t *mpeg)
{
unsigned i;
mpeg->shdr_cnt = 0;
mpeg->pack_cnt = 0;
mpeg->packet_cnt = 0;
mpeg->end_cnt = 0;
mpeg->skip_cnt = 0;
for (i = 0; i < 256; i++) {
mpeg->streams[i].packet_cnt = 0;
mpeg->streams[i].size = 0;
mpeg->substreams[i].packet_cnt = 0;
mpeg->substreams[i].size = 0;
}
}
static
int mpegd_buffer_fill (mpeg_demux_t *mpeg)
{
unsigned i, n;
size_t r;
if ((mpeg->buf_i > 0) && (mpeg->buf_n > 0)) {
for (i = 0; i < mpeg->buf_n; i++) {
mpeg->buf[i] = mpeg->buf[mpeg->buf_i + i];
}
}
mpeg->buf_i = 0;
n = MPEG_DEMUX_BUFFER - mpeg->buf_n;
if (n > 0) {
r = read (mpeg->fd, mpeg->buf + mpeg->buf_n, n);
if (r < 0) {
return (1);
}
mpeg->buf_n += (unsigned) r;
}
return (0);
}
static
int mpegd_need_bits (mpeg_demux_t *mpeg, unsigned n)
{
n = (n + 7) / 8;
if (n > mpeg->buf_n) {
mpegd_buffer_fill (mpeg);
}
if (n > mpeg->buf_n) {
return (1);
}
return (0);
}
unsigned long mpegd_get_bits (mpeg_demux_t *mpeg, unsigned i, unsigned n)
{
unsigned long r;
unsigned long v, m;
unsigned b_i, b_n;
unsigned char *buf;
if (mpegd_need_bits (mpeg, i + n)) {
return (0);
}
buf = mpeg->buf + mpeg->buf_i;
r = 0;
/* aligned bytes */
if (((i | n) & 7) == 0) {
i = i / 8;
n = n / 8;
while (n > 0) {
r = (r << 8) | buf[i];
i += 1;
n -= 1;
}
return (r);
}
while (n > 0) {
b_n = 8 - (i & 7);
if (b_n > n) {
b_n = n;
}
b_i = 8 - (i & 7) - b_n;
m = (1 << b_n) - 1;
v = (buf[i >> 3] >> b_i) & m;
r = (r << b_n) | v;
i += b_n;
n -= b_n;
}
return (r);
}
int mpegd_skip (mpeg_demux_t *mpeg, unsigned n)
{
size_t r;
mpeg->ofs += n;
if (n <= mpeg->buf_n) {
mpeg->buf_i += n;
mpeg->buf_n -= n;
return (0);
}
n -= mpeg->buf_n;
mpeg->buf_i = 0;
mpeg->buf_n = 0;
while (n > 0) {
if (n <= MPEG_DEMUX_BUFFER) {
r = read (mpeg->fd ,mpeg->buf, n);
}
else {
r = read (mpeg->fd, mpeg->buf, MPEG_DEMUX_BUFFER);
}
if (r <= 0) {
return (1);
}
n -= (unsigned) r;
}
return (0);
}
unsigned mpegd_read (mpeg_demux_t *mpeg, void *buf, unsigned n)
{
unsigned ret;
unsigned i;
unsigned char *tmp;
tmp = (unsigned char *) buf;
i = (n < mpeg->buf_n) ? n : mpeg->buf_n;
ret = i;
if (i > 0) {
memcpy (tmp, &mpeg->buf[mpeg->buf_i], i);
tmp += i;
mpeg->buf_i += i;
mpeg->buf_n -= i;
n -= i;
}
if (n > 0) {
ret += read (mpeg->fd, tmp, n);
}
mpeg->ofs += ret;
return (ret);
}
int mpegd_set_offset (mpeg_demux_t *mpeg, unsigned long long ofs)
{
if (ofs == mpeg->ofs) {
return (0);
}
if (ofs > mpeg->ofs) {
return (mpegd_skip (mpeg, (unsigned long) (ofs - mpeg->ofs)));
}
return (1);
}
static
int mpegd_seek_header (mpeg_demux_t *mpeg)
{
unsigned long long ofs;
while (mpegd_get_bits (mpeg, 0, 24) != 1) {
ofs = mpeg->ofs + 1;
if (mpeg->mpeg_skip != NULL) {
if (mpeg->mpeg_skip (mpeg)) {
return (1);
}
}
if (mpegd_set_offset (mpeg, ofs)) {
return (1);
}
mpeg->skip_cnt += 1;
}
return (0);
}
static
int mpegd_parse_system_header (mpeg_demux_t *mpeg)
{
unsigned long long ofs;
mpeg->shdr.size = mpegd_get_bits (mpeg, 32, 16) + 6;
mpeg->shdr.fixed = mpegd_get_bits (mpeg, 78, 1);
mpeg->shdr.csps = mpegd_get_bits (mpeg, 79, 1);
mpeg->shdr_cnt += 1;
ofs = mpeg->ofs + mpeg->shdr.size;
if (mpeg->mpeg_system_header != NULL) {
if (mpeg->mpeg_system_header (mpeg)) {
return (1);
}
}
mpegd_set_offset (mpeg, ofs);
return (0);
}
static
int mpegd_parse_packet1 (mpeg_demux_t *mpeg, unsigned i)
{
unsigned val;
unsigned long long tmp;
mpeg->packet.type = 1;
if (mpegd_get_bits (mpeg, i, 2) == 0x01) {
i += 16;
}
val = mpegd_get_bits (mpeg, i, 8);
if ((val & 0xf0) == 0x20) {
tmp = mpegd_get_bits (mpeg, i + 4, 3);
tmp = (tmp << 15) | mpegd_get_bits (mpeg, i + 8, 15);
tmp = (tmp << 15) | mpegd_get_bits (mpeg, i + 24, 15);
mpeg->packet.have_pts = 1;
mpeg->packet.pts = tmp;
i += 40;
}
else if ((val & 0xf0) == 0x30) {
tmp = mpegd_get_bits (mpeg, i + 4, 3);
tmp = (tmp << 15) | mpegd_get_bits (mpeg, i + 8, 15);
tmp = (tmp << 15) | mpegd_get_bits (mpeg, i + 24, 15);
mpeg->packet.have_pts = 1;
mpeg->packet.pts = tmp;
tmp = mpegd_get_bits (mpeg, i + 44, 3);
tmp = (tmp << 15) | mpegd_get_bits (mpeg, i + 48, 15);
tmp = (tmp << 15) | mpegd_get_bits (mpeg, i + 64, 15);
mpeg->packet.have_dts = 1;
mpeg->packet.dts = tmp;
i += 80;
}
else if (val == 0x0f) {
i += 8;
}
mpeg->packet.offset = i / 8;
return (0);
}
static
int mpegd_parse_packet2 (mpeg_demux_t *mpeg, unsigned i)
{
unsigned pts_dts_flag;
unsigned cnt;
unsigned long long tmp;
mpeg->packet.type = 2;
pts_dts_flag = mpegd_get_bits (mpeg, i + 8, 2);
cnt = mpegd_get_bits (mpeg, i + 16, 8);
if (pts_dts_flag == 0x02) {
if (mpegd_get_bits (mpeg, i + 24, 4) == 0x02) {
tmp = mpegd_get_bits (mpeg, i + 28, 3);
tmp = (tmp << 15) | mpegd_get_bits (mpeg, i + 32, 15);
tmp = (tmp << 15) | mpegd_get_bits (mpeg, i + 48, 15);
mpeg->packet.have_pts = 1;
mpeg->packet.pts = tmp;
}
}
else if ((pts_dts_flag & 0x03) == 0x03) {
if (mpegd_get_bits (mpeg, i + 24, 4) == 0x03) {
tmp = mpegd_get_bits (mpeg, i + 28, 3);
tmp = (tmp << 15) | mpegd_get_bits (mpeg, i + 32, 15);
tmp = (tmp << 15) | mpegd_get_bits (mpeg, i + 48, 15);
mpeg->packet.have_pts = 1;
mpeg->packet.pts = tmp;
}
if (mpegd_get_bits (mpeg, i + 64, 4) == 0x01) {
tmp = mpegd_get_bits (mpeg, i + 68, 3);
tmp = (tmp << 15) | mpegd_get_bits (mpeg, i + 72, 15);
tmp = (tmp << 15) | mpegd_get_bits (mpeg, i + 88, 15);
mpeg->packet.have_dts = 1;
mpeg->packet.dts = tmp;
}
}
i += 8 * (cnt + 3);
mpeg->packet.offset = i / 8;
return (0);
}
static
int mpegd_parse_packet (mpeg_demux_t *mpeg)
{
unsigned i;
unsigned sid, ssid;
unsigned long long ofs;
mpeg->packet.type = 0;
sid = mpegd_get_bits (mpeg, 24, 8);
ssid = 0;
mpeg->packet.sid = sid;
mpeg->packet.ssid = ssid;
mpeg->packet.size = mpegd_get_bits (mpeg, 32, 16) + 6;
mpeg->packet.offset = 6;
mpeg->packet.have_pts = 0;
mpeg->packet.pts = 0;
mpeg->packet.have_dts = 0;
mpeg->packet.dts = 0;
i = 48;
if (((sid >= 0xc0) && (sid < 0xf0)) || (sid == 0xbd)) {
while (mpegd_get_bits (mpeg, i, 8) == 0xff) {
if (i > (48 + 16 * 8)) {
break;
}
i += 8;
}
if (mpegd_get_bits (mpeg, i, 2) == 0x02) {
if (mpegd_parse_packet2 (mpeg, i)) {
return (1);
}
}
else {
if (mpegd_parse_packet1 (mpeg, i)) {
return (1);
}
}
}
else if (sid == 0xbe) {
mpeg->packet.type = 1;
}
if (sid == 0xbd) {
ssid = mpegd_get_bits (mpeg, 8 * mpeg->packet.offset, 8);
mpeg->packet.ssid = ssid;
}
if ((mpeg->mpeg_packet_check != NULL) && mpeg->mpeg_packet_check (mpeg)) {
if (mpegd_skip (mpeg, 1)) {
return (1);
}
}
else {
mpeg->packet_cnt += 1;
mpeg->streams[sid].packet_cnt += 1;
mpeg->streams[sid].size += mpeg->packet.size - mpeg->packet.offset;
if (sid == 0xbd) {
mpeg->substreams[ssid].packet_cnt += 1;
mpeg->substreams[ssid].size += mpeg->packet.size - mpeg->packet.offset;
}
ofs = mpeg->ofs + mpeg->packet.size;
if (mpeg->mpeg_packet != NULL) {
if (mpeg->mpeg_packet (mpeg)) {
return (1);
}
}
mpegd_set_offset (mpeg, ofs);
}
return (0);
}
static
int mpegd_parse_pack (mpeg_demux_t *mpeg)
{
unsigned sid;
unsigned long long ofs;
if (mpegd_get_bits (mpeg, 32, 4) == 0x02) {
mpeg->pack.type = 1;
mpeg->pack.scr = mpegd_get_bits (mpeg, 36, 3);
mpeg->pack.scr = (mpeg->pack.scr << 15) | mpegd_get_bits (mpeg, 40, 15);
mpeg->pack.scr = (mpeg->pack.scr << 15) | mpegd_get_bits (mpeg, 56, 15);
mpeg->pack.mux_rate = mpegd_get_bits (mpeg, 73, 22);
mpeg->pack.stuff = 0;
mpeg->pack.size = 12;
}
else if (mpegd_get_bits (mpeg, 32, 2) == 0x01) {
mpeg->pack.type = 2;
mpeg->pack.scr = mpegd_get_bits (mpeg, 34, 3);
mpeg->pack.scr = (mpeg->pack.scr << 15) | mpegd_get_bits (mpeg, 38, 15);
mpeg->pack.scr = (mpeg->pack.scr << 15) | mpegd_get_bits (mpeg, 54, 15);
mpeg->pack.mux_rate = mpegd_get_bits (mpeg, 80, 22);
mpeg->pack.stuff = mpegd_get_bits (mpeg, 109, 3);
mpeg->pack.size = 14 + mpeg->pack.stuff;
}
else {
mpeg->pack.type = 0;
mpeg->pack.scr = 0;
mpeg->pack.mux_rate = 0;
mpeg->pack.size = 4;
}
ofs = mpeg->ofs + mpeg->pack.size;
mpeg->pack_cnt += 1;
if (mpeg->mpeg_pack != NULL) {
if (mpeg->mpeg_pack (mpeg)) {
return (1);
}
}
mpegd_set_offset (mpeg, ofs);
mpegd_seek_header (mpeg);
if (mpegd_get_bits (mpeg, 0, 32) == MPEG_SYSTEM_HEADER) {
if (mpegd_parse_system_header (mpeg)) {
return (1);
}
mpegd_seek_header (mpeg);
}
while (mpegd_get_bits (mpeg, 0, 24) == MPEG_PACKET_START) {
sid = mpegd_get_bits (mpeg, 24, 8);
if ((sid == 0xba) || (sid == 0xb9) || (sid == 0xbb)) {
break;
}
else {
mpegd_parse_packet (mpeg);
}
mpegd_seek_header (mpeg);
}
return (0);
}
int mpegd_parse (mpeg_demux_t *mpeg)
{
unsigned long long ofs;
while (1) {
if (mpegd_seek_header (mpeg)) {
return (0);
}
switch (mpegd_get_bits (mpeg, 0, 32)) {
case MPEG_PACK_START:
if (mpegd_parse_pack (mpeg)) {
return (1);
}
break;
case MPEG_END_CODE:
mpeg->end_cnt += 1;
ofs = mpeg->ofs + 4;
if (mpeg->mpeg_end != NULL) {
if (mpeg->mpeg_end (mpeg)) {
return (1);
}
}
if (mpegd_set_offset (mpeg, ofs)) {
return (1);
}
break;
default:
ofs = mpeg->ofs + 1;
if (mpeg->mpeg_skip != NULL) {
if (mpeg->mpeg_skip (mpeg)) {
return (1);
}
}
if (mpegd_set_offset (mpeg, ofs)) {
return (0);
}
break;
}
}
return (0);
}
#endif//HAVE_LIBDVDNAV
|
the_stack_data/215767002.c | /* f2c.h -- Standard Fortran to C header file */
/** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
- From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
#ifndef F2C_INCLUDE
#define F2C_INCLUDE
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimag(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle() continue;
#define myceiling(w) {ceil(w)}
#define myhuge(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* > \brief \b SORGL2 */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download SORGL2 + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sorgl2.
f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sorgl2.
f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sorgl2.
f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* SUBROUTINE SORGL2( M, N, K, A, LDA, TAU, WORK, INFO ) */
/* INTEGER INFO, K, LDA, M, N */
/* REAL A( LDA, * ), TAU( * ), WORK( * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > SORGL2 generates an m by n real matrix Q with orthonormal rows, */
/* > which is defined as the first m rows of a product of k elementary */
/* > reflectors of order n */
/* > */
/* > Q = H(k) . . . H(2) H(1) */
/* > */
/* > as returned by SGELQF. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] M */
/* > \verbatim */
/* > M is INTEGER */
/* > The number of rows of the matrix Q. M >= 0. */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The number of columns of the matrix Q. N >= M. */
/* > \endverbatim */
/* > */
/* > \param[in] K */
/* > \verbatim */
/* > K is INTEGER */
/* > The number of elementary reflectors whose product defines the */
/* > matrix Q. M >= K >= 0. */
/* > \endverbatim */
/* > */
/* > \param[in,out] A */
/* > \verbatim */
/* > A is REAL array, dimension (LDA,N) */
/* > On entry, the i-th row must contain the vector which defines */
/* > the elementary reflector H(i), for i = 1,2,...,k, as returned */
/* > by SGELQF in the first k rows of its array argument A. */
/* > On exit, the m-by-n matrix Q. */
/* > \endverbatim */
/* > */
/* > \param[in] LDA */
/* > \verbatim */
/* > LDA is INTEGER */
/* > The first dimension of the array A. LDA >= f2cmax(1,M). */
/* > \endverbatim */
/* > */
/* > \param[in] TAU */
/* > \verbatim */
/* > TAU is REAL array, dimension (K) */
/* > TAU(i) must contain the scalar factor of the elementary */
/* > reflector H(i), as returned by SGELQF. */
/* > \endverbatim */
/* > */
/* > \param[out] WORK */
/* > \verbatim */
/* > WORK is REAL array, dimension (M) */
/* > \endverbatim */
/* > */
/* > \param[out] INFO */
/* > \verbatim */
/* > INFO is INTEGER */
/* > = 0: successful exit */
/* > < 0: if INFO = -i, the i-th argument has an illegal value */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date December 2016 */
/* > \ingroup realOTHERcomputational */
/* ===================================================================== */
/* Subroutine */ int sorgl2_(integer *m, integer *n, integer *k, real *a,
integer *lda, real *tau, real *work, integer *info)
{
/* System generated locals */
integer a_dim1, a_offset, i__1, i__2;
real r__1;
/* Local variables */
integer i__, j, l;
extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *),
slarf_(char *, integer *, integer *, real *, integer *, real *,
real *, integer *, real *), xerbla_(char *, integer *, ftnlen);
/* -- LAPACK computational routine (version 3.7.0) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* December 2016 */
/* ===================================================================== */
/* Test the input arguments */
/* Parameter adjustments */
a_dim1 = *lda;
a_offset = 1 + a_dim1 * 1;
a -= a_offset;
--tau;
--work;
/* Function Body */
*info = 0;
if (*m < 0) {
*info = -1;
} else if (*n < *m) {
*info = -2;
} else if (*k < 0 || *k > *m) {
*info = -3;
} else if (*lda < f2cmax(1,*m)) {
*info = -5;
}
if (*info != 0) {
i__1 = -(*info);
xerbla_("SORGL2", &i__1, (ftnlen)6);
return 0;
}
/* Quick return if possible */
if (*m <= 0) {
return 0;
}
if (*k < *m) {
/* Initialise rows k+1:m to rows of the unit matrix */
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
i__2 = *m;
for (l = *k + 1; l <= i__2; ++l) {
a[l + j * a_dim1] = 0.f;
/* L10: */
}
if (j > *k && j <= *m) {
a[j + j * a_dim1] = 1.f;
}
/* L20: */
}
}
for (i__ = *k; i__ >= 1; --i__) {
/* Apply H(i) to A(i:m,i:n) from the right */
if (i__ < *n) {
if (i__ < *m) {
a[i__ + i__ * a_dim1] = 1.f;
i__1 = *m - i__;
i__2 = *n - i__ + 1;
slarf_("Right", &i__1, &i__2, &a[i__ + i__ * a_dim1], lda, &
tau[i__], &a[i__ + 1 + i__ * a_dim1], lda, &work[1]);
}
i__1 = *n - i__;
r__1 = -tau[i__];
sscal_(&i__1, &r__1, &a[i__ + (i__ + 1) * a_dim1], lda);
}
a[i__ + i__ * a_dim1] = 1.f - tau[i__];
/* Set A(i,1:i-1) to zero */
i__1 = i__ - 1;
for (l = 1; l <= i__1; ++l) {
a[i__ + l * a_dim1] = 0.f;
/* L30: */
}
/* L40: */
}
return 0;
/* End of SORGL2 */
} /* sorgl2_ */
|
the_stack_data/100139344.c | /*
Subhashis Suara
UCSE19012
*/
#include <stdio.h>
int size = 10; // This is also the number of queens
int chessboard[10][10];
int canAttack(int i,int j)
{
int k, l;
// Checking rows and columns
for(k = 0;k < size;k++)
{
if((chessboard[i][k] == 1) || (chessboard[k][j] == 1))
return 1;
}
// Checking diagonals
for(k = 0;k < size;k++)
{
for(l = 0;l < size;l++)
{
if(((k + l) == (i + j)) || ((k - l) == (i - j)))
{
if(chessboard[k][l] == 1)
return 1;
}
}
}
return 0;
}
int nQueen(int queen)
{
/*
- If all returns are 0 then solution is completed
- If even one of the returns in 1 then that queen
is removed and checking continues (backtracking)
*/
int i, j;
if(queen == 0) // queen = 0 means solution is completed as all queens have been placed successfully
return 0;
for(i = 0;i < size;i++)
{
for(j = 0;j < size;j++)
{
if((!canAttack(i,j)) && (chessboard[i][j] != 1))
{
chessboard[i][j] = 1;
if(nQueen(queen - 1) == 0) // Trying to place other queens with the current one(s)
return 0;
chessboard[i][j] = 0;
}
}
}
return 1;
}
int main()
{
int i, j;
for(i = 0;i < size;i++)
for(j = 0;j < size;j++)
chessboard[i][j]=0;
nQueen(size);
/*
Output:
1 -> Queen
0 -> Empty
*/
for(i = 0;i < size;i++)
{
for(j = 0;j < size;j++)
printf("%d ", chessboard[i][j]);
printf("\n");
}
return 0;
}
|
the_stack_data/176706103.c | // Really weird code submitted by Serge Guelton, not likely to survive
// a gcc -c -Wall -Werror. Besides, the options used for PIPS means it
// should have been places in Semantics-New. return added in
// hs_set_r() to display precondition resulting from call to
// vhs_set_r().
//
// Issues potentially leading to an unusual control path in PIPS:
//
// 1. Typedef used only to declare an enum
//
// 2. Useless argument o for vhs_set_r()
//
// 3. Unitialized variable o in hs_set_r()
//
// See bug description below
typedef enum a {
HS_PARSE_ONLY,
} ;
int vhs_set_r(enum a o) {
return 1;
}
/* replacing enum a by an int works fine */
void hs_set_r() {
enum a o;
int res = vhs_set_r(o);
return;
}
|
the_stack_data/140208.c | #include <stdio.h>
#define PAGE 959
int main(void){
printf("*0123456789*\n");
printf("*%d*\n", PAGE);
printf("*%2d*\n", PAGE);
printf("*%10d*\n", PAGE);
printf("*%-10d*\n", PAGE);
printf("*%+10d*\n", PAGE);
printf("*% 10d*\n", PAGE);
printf("*%.10d*\n", PAGE);
return 0;
} |
the_stack_data/428017.c | /*
* Copyright (C) 1988 Research Institute for Advanced Computer Science.
* All rights reserved. The RIACS Software Policy contains specific
* terms and conditions on the use of this software, and must be
* distributed with any copies. This file may be redistributed. This
* copyright and notice must be preserved in all copies made of this file.
*/
/*
* rletoabA62
* ----------
*
* This program converts Utah Raster Toolkit files into the dump format of the
* Abekas A62 video storage disk.
*
* Options:
* -N ... do no digital filtering.
* -n N ... N specifies the number for frames to write
* -f N ... N specifies the first frame number (1-4) to write.
* -b R G B ... clear background to this color
*
* Author/Status:
* Bob Brown [email protected]
* First write: 29 Jan 1988
*
* The interface to the particular raster format used is mostly separated from
* the logic of the conversion code. Two routines define the interface:
*
* rasterInit(fd, width, height)
*
* This specifies the integer file descriptor for the input file,
* the width and the height of the image. It is called exactly once.
*
* rasterGetRow(red, green, blue)
*
* This is called to return the next row of the raster. The parameters
* point to arrays of unsigned char to hold the RGB values.
*/
static char rcsid[] = "$Header$";
/*
rletoabA62() Tag the file.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
typedef char bool;
/*
* Dimensions of the raster image within the A62
*/
#define WIDTH 768
#define HEIGHT 512
/*
* Global variables are always capitalized.
*
* These are globals set by program arguments. The static initializations are
* the default values.
*/
int Width = WIDTH; /* Width of the output image */
int Height = HEIGHT; /* Height of the output image */
int Debug = 0;
bool NoFilter = FALSE;
int Frame = 1;
int NumFrames = 2;
int BkgRed = 0;
int BkgBlue = 0;
int BkgGreen= 0;
extern char *optarg; /* interface to getopt() */
extern int optind; /* interface to getopt() */
typedef struct {
char y, i, q;
} yiq_t;
#ifdef USE_PROTOTYPES
extern void rasterInit(int fd, int width, int height);
extern void rasterRowGet(unsigned char *red, unsigned char *green, unsigned char *blue);
extern void rasterDone(void);
extern void filterY(float *yVal, float c0, float c1, float c2);
extern void filterIQ(float *iqVal, float c0, float c1, float c2, int start, int stride);
extern void dump1(register yiq_t **raster, int start);
extern void dump2(register yiq_t **raster, int start);
#else
extern void rasterInit();
extern void rasterRowGet(), rasterDone();
extern void filterY();
extern void filterIQ();
extern void dump1();
extern void dump2();
#endif
/*
* Main entry...
*/
int
main(int argc,char *argv[])
{
register int i, j;
int errors, c, file;
float rTOy[256], gTOy[256], bTOy[256];
float rTOi[256], gTOi[256], bTOi[256];
float rTOq[256], gTOq[256], bTOq[256];
float *iVal, *yVal, *qVal, *tmpVal;
unsigned char *red, *green, *blue;
int r, g, b;
yiq_t **raster;
/*
* Parse program arguments...
*
* The -w and -h args should actually not be used.
*/
errors = 0;
while ((c = getopt(argc, argv, "Nn:f:w:h:d:D:b")) != EOF) {
switch (c) {
case 'b':
BkgRed = atoi(argv[optind++]);
BkgGreen = atoi(argv[optind++]);
BkgBlue = atoi(argv[optind++]);
break;
case 'N':
NoFilter = TRUE;
break;
case 'w':
Width = atoi(optarg);
break;
case 'f':
Frame = atoi(optarg);
break;
case 'n':
NumFrames = atoi(optarg);
break;
case 'h':
Height = atoi(optarg);
break;
case 'D':
Debug = atoi(optarg);
break;
case '?':
errors++;
}
}
if (errors > 0) {
fprintf(stderr, "Usage: %s [-n] [-D debug-level] [file]\n", argv[0]);
exit(1);
}
if (optind < argc) {
if ((file = open(argv[optind], 0)) < 0) {
perror(argv[optind]);
exit(1);
}
} else {
file = 0;
}
/*
* Initialize the type manager for Utah RLE files
*/
rasterInit(file, Width, Height, BkgRed, BkgGreen, BkgBlue);
/*
* Allocate storage for the RGB inputs, the computed YIQ, and the
* results. This is all dynamically allocated because the dimensions of
* the framestore are only decided at run time.
*
* The YIQ arrays are extended two entries at either end to simplify the
* filtering code. The effect is that the iVal and qVal arrays can be
* indexed [-2 .. Width+2] and yVal [-4 .. Width+4] (the stuff at the
* end of the yVal array isn't used).
*/
red = (unsigned char *) calloc(Width, sizeof *red);
green = (unsigned char *) calloc(Width, sizeof *green);
blue = (unsigned char *) calloc(Width, sizeof *blue);
tmpVal = (float *) calloc(Width + 8, sizeof *yVal);
yVal = tmpVal + 4;
tmpVal = (float *) calloc(Width + 4, sizeof *iVal);
iVal = tmpVal + 2;
tmpVal = (float *) calloc(Width + 4, sizeof *qVal);
qVal = tmpVal + 2;
/*
* Allocate storage to hold the 8-bit YIQ values for the entire
* picture.
*/
raster = (yiq_t **) calloc(Height, sizeof *raster);
for (i = 0; i < Height; i++) {
raster[i] = (yiq_t *) calloc(Width, sizeof **raster);
}
/*
* Build the mappings from R,G,B to Y,I,Q. The pedastal is factored
* into this mapping.
*/
for (i = 0; i < 256; i++) {
rTOy[i] = ((float) i / 255.0 * 0.925 + 0.075) * 0.299;
gTOy[i] = ((float) i / 255.0 * 0.925 + 0.075) * 0.587;
bTOy[i] = ((float) i / 255.0 * 0.925 + 0.075) * 0.114;
rTOi[i] = ((float) i / 255.0 * 0.925 + 0.075) * 0.596;
gTOi[i] = ((float) i / 255.0 * 0.925 + 0.075) * -0.274;
bTOi[i] = ((float) i / 255.0 * 0.925 + 0.075) * -0.322;
rTOq[i] = ((float) i / 255.0 * 0.925 + 0.075) * 0.211;
gTOq[i] = ((float) i / 255.0 * 0.925 + 0.075) * -0.523;
bTOq[i] = ((float) i / 255.0 * 0.925 + 0.075) * 0.312;
}
/*
* process the input raster line by raster line
*/
for (i = 0; i < Height; i++) {
rasterRowGet(red, green, blue);
yVal[-4] = yVal[-3] = yVal[-2] = yVal[-1] = 0;
iVal[-2] = iVal[-1] = 0;
qVal[-2] = qVal[-1] = 0;
yVal[Width + 3] = yVal[Width + 2] = yVal[Width + 1] = yVal[Width + 0] = 0;
iVal[Width + 0] = iVal[Width + 1] = 0;
qVal[Width + 0] = qVal[Width + 1] = 0;
/*
* Convert RGB to YIQ. The multiplication is done by table lookup
* into the [rgb]TO[yiq] arrays.
*/
for (j = 0; j < Width; j++) {
r = red[j];
g = green[j];
b = blue[j];
yVal[j] = rTOy[r] + gTOy[g] + bTOy[b];
iVal[j] = rTOi[r] + gTOi[g] + bTOi[b];
qVal[j] = rTOq[r] + gTOq[g] + bTOq[b];
}
if (!NoFilter) {
filterY(yVal, 0.62232, 0.21732, -0.02848);
filterIQ(iVal, 0.42354, 0.25308, 0.03515, 0, 2);
filterIQ(qVal, 0.34594, 0.25122, 0.07581, 1, 2);
}
/*
* Build the YIQ raster
*/
for (j = 0; j < Width; j++) {
raster[Height - i - 1][j].y = yVal[j] * 140.0;
raster[Height - i - 1][j].i = iVal[j] * 140.0;
raster[Height - i - 1][j].q = qVal[j] * 140.0;
}
}
/*
* Dump the raster as four color fields.
*
* Assert that Width%4 ==0 and Height%4 == 0
*
* Despite what the A62 SCSI manual says, for frames I and IV, the even
* numbered lines (starting with line 0) begin Y-I and the others begin
* Y+I.
*/
for (i = 0; i < NumFrames; i++) {
switch ((i + Frame - 1) % 4 + 1) {
case 1:
dump2(raster, 0); /* even lines, starts Y-I */
break;
case 2:
dump1(raster, 1); /* odd lines, starts Y+I */
break;
case 3:
dump1(raster, 0); /* even lines, starts Y+I */
break;
case 4:
dump2(raster, 1); /* odd lines, starts Y-I */
break;
}
}
return 0;
}
/*
* filterY
* -------
*
* Apply and RIF filter to the luminance data. The signal is shifted two pixels
* to the right in the process.
*
* The multiplier arrays m0, m1, and m2 exist to reduce the number of floating
* point multiplications and to allow the filtering to occur in place.
*/
void
filterY(yVal, c0, c1, c2)
float *yVal, c0, c1, c2;
{
static float *m0 = NULL;
static float *m1 = NULL;
static float *m2 = NULL;
register int i;
if (m1 == NULL) {
m0 = (float *) calloc(Width + 8, sizeof(float));
m1 = (float *) calloc(Width + 8, sizeof(float));
m2 = (float *) calloc(Width + 8, sizeof(float));
}
for (i = -4; i < Width + 4; i++) {
m0[i] = c0 * yVal[i];
m1[i] = c1 * yVal[i];
m2[i] = c2 * yVal[i];
}
for (i = 0; i < Width; i++) {
yVal[i] = m2[i - 4] + m1[i - 3] + m0[i - 2] + m1[i - 1] + m2[i];
}
}
/*
* filterIQ
* --------
*
* Apply and RIF filter to the color difference data.
*
* The multiplier arrays m0, m1, and m2 exist to reduce the number of floating
* point multiplications and to allow the filtering to occur in place.
*
* The "start" and "stride" parameters are used to reduce the number of
* computations because I and Q are only used every other pixel.
*
* This is different from the manual in than the filtering is done on adjacent
* pixels, rather than every other pixel. This may be a problem...
*/
void
filterIQ(iqVal, c0, c1, c2, start, stride)
float *iqVal, c0, c1, c2;
int start, stride;
{
static float *m0 = NULL;
static float *m1 = NULL;
static float *m2 = NULL;
register int i;
if (m1 == NULL) {
m0 = (float *) calloc(Width + 4, sizeof(float));
m1 = (float *) calloc(Width + 4, sizeof(float));
m2 = (float *) calloc(Width + 4, sizeof(float));
}
for (i = -2; i < Width + 2; i++) {
m0[i] = c0 * iqVal[i];
m1[i] = c1 * iqVal[i];
m2[i] = c2 * iqVal[i];
}
for (i = start; i < Width; i += stride) {
iqVal[i] = m2[i - 2] + m1[i - 1] + m0[i] + m1[i + 1] + m2[i + 2];
}
}
/*
* dump1
* -----
*
* Dumps the raster starting with the sequence Y+I Y+Q Y-I Y-Q
*
* This routine also adds 60 to put the data in the 60 .. 200 range.
*/
#define OUT(y, OP, iq) putc((char) (raster[i][j + 0].y OP raster[i][j + 0].iq + 60), stdout);
void
dump1(raster, start)
register yiq_t **raster;
int start;
{
register int i, j;
for (i = start; i < Height; i += 4) { /* field I */
for (j = 0; j < Width; j += 4) {
putc((char) (raster[i][j + 0].y + raster[i][j + 0].i + 60), stdout);
putc((char) (raster[i][j + 1].y + raster[i][j + 1].q + 60), stdout);
putc((char) (raster[i][j + 2].y - raster[i][j + 2].i + 60), stdout);
putc((char) (raster[i][j + 3].y - raster[i][j + 3].q + 60), stdout);
}
for (j = 0; j < Width; j += 4) {
putc((char) (raster[i + 2][j + 0].y - raster[i + 2][j + 0].i + 60), stdout);
putc((char) (raster[i + 2][j + 1].y - raster[i + 2][j + 1].q + 60), stdout);
putc((char) (raster[i + 2][j + 2].y + raster[i + 2][j + 2].i + 60), stdout);
putc((char) (raster[i + 2][j + 3].y + raster[i + 2][j + 3].q + 60), stdout);
}
}
}
/*
* dump2
* -----
*
* Dumps the raster starting with the sequence Y-I Y-Q Y+I Y+Q
*
* This routine also adds 60 to put the data in the 60 .. 200 range.
*/
void
dump2(raster, start)
register yiq_t **raster;
int start;
{
register int i, j;
for (i = start; i < Height; i += 4) { /* field I */
for (j = 0; j < Width; j += 4) {
putc((char) (raster[i][j + 0].y - raster[i][j + 0].i + 60), stdout);
putc((char) (raster[i][j + 1].y - raster[i][j + 1].q + 60), stdout);
putc((char) (raster[i][j + 2].y + raster[i][j + 2].i + 60), stdout);
putc((char) (raster[i][j + 3].y + raster[i][j + 3].q + 60), stdout);
}
for (j = 0; j < Width; j += 4) {
putc((char) (raster[i + 2][j + 0].y + raster[i + 2][j + 0].i + 60), stdout);
putc((char) (raster[i + 2][j + 1].y + raster[i + 2][j + 1].q + 60), stdout);
putc((char) (raster[i + 2][j + 2].y - raster[i + 2][j + 2].i + 60), stdout);
putc((char) (raster[i + 2][j + 3].y - raster[i + 2][j + 3].q + 60), stdout);
}
}
}
|
the_stack_data/237644575.c | #include <stdio.h>
#include <stdlib.h>
int main()
{
int status = system("sh");
if (status == -1)
printf("Failed\n");
return status;
}
|
the_stack_data/506724.c | #include <stdio.h>
int a[23][23];
void swap(int *x, int *y){
int t = *x;
*x = *y;
*y = t;
}
int main()
{
int x, y, i, j, n, m;
char s[23];
scanf("%s", s);
//if(s[0] == 'I' || s[0] == 'S')
scanf("%d%d", &n, &m);
for(i = 1; i <= n; i++)
for(j = 1; j <= m; j++)
a[i][j] = m*i - m + j;
while(scanf("%s", s) == 1){
if(s[0] == 'S'){
scanf("%d%d", &x, &y);
if(s[1] == 'R'){
for(i = 1; i <= m; i++){
swap(&a[x][i], &a[y][i]);
// t = a[x][i];
// a[x][i] = a[y][i];
// a[y][i] = t;
}
}else{
for(i = 1; i <= n; i++){
swap(&a[i][x], &a[i][y]);
// t = a[x][i];
// a[x][i] = a[y][i];
// a[y][i] = t;
}
}
}else if(s[0] == 'T'){
int t, r;
if(n > m){
t = n;
r = m;
}else{
t = m;
r = n;
}
for(i = 1; i <= r; i++)
for(j = i; j <= t; j++)
swap(&a[i][j], &a[j][i]);
swap(&n, &m);
}else if(s[0] == 'F'){
if(s[1] == 'R'){
for(i = 1; i <= n >> 1; i++)
for(j = 1; j <= m; j++)
swap(&a[i][j], &a[n - i + 1][j]);
}else{
for(i = 1; i <= m >> 1; i++)
for(j = 1; j <= n; j++)
swap(&a[j][i], &a[j][m - i + 1]);
}
}else{
for(i = 1; i <= n; i++){
for(j = 1; j <= m; j++)
printf("%d ", a[i][j]);
printf("\n");
}
putchar('\n');
}
}
return 0;
} |
the_stack_data/167329726.c | int __cost;
//int lg_n_helper(int n) {
// int i;
// int r = 0;
// int j;
// //__VERIFIER_assume(n > 0);
// for(i = 1; i != n; i *= 2) {
// r ++;
// }
// return r;
//}
int recursive(int n) {
__VERIFIER_assume(n >= 2);
if (n == 2) { return 0; }
recursive(n/2);
return recursive(n/2) + 1;
}
void main(int n) {
__VERIFIER_assume(n > 2);
__cost = recursive(n);
//int bound = lg_n_helper(n);
//if (__VERIFIER_nondet_int()) {
// __VERIFIER_assert(__cost <= bound);
//}
}
|
the_stack_data/141180.c | #include <signal.h>
#include <unistd.h>
static void
handler(int signum) {
static const char Message[] = "Got Ctrl+C\n";
write(1, Message, sizeof(Message)-1);
}
int main() {
sigaction(SIGINT,
&(struct sigaction)
{.sa_handler=handler, .sa_flags=SA_RESTART},
NULL);
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGINT);
while (1) {
sigprocmask(SIG_BLOCK, &mask, NULL);
sleep(10);
sigprocmask(SIG_UNBLOCK, &mask, NULL);
}
}
|
the_stack_data/49431.c | /**********************
* Indirection alphabet *
* George Koskeridis *
**********************/
#include <stdio.h>
void single_indir(void *x, int arr_sz);
void double_indir(void **x, int arr_sz);
void triple_indir(void ***x, int arr_sz);
void quadruple_indir(void ****x, int arr_sz);
void quintuple_indir(void *****x, int arr_sz);
void sextuple_indir(void ******x, int arr_sz);
void septuple_indir(void *******x, int arr_sz);
void octuple_indir(void ********x, int arr_sz);
void nonuple_indir(void *********x, int arr_sz);
void decuple_indir(void **********x, int arr_sz);
void undecuple_indir(void ***********x, int arr_sz);
void duodecuple_indir(void ************x, int arr_sz);
void tredecuple_indir(void *************x, int arr_sz);
void quattuordecuple_indir(void **************x, int arr_sz);
void quindecuple_indir(void ***************x, int arr_sz);
void sexdecuple_indir(void ****************x, int arr_sz);
void septendecuple_indir(void *****************x, int arr_sz);
void octodecuple_indir(void ******************x, int arr_sz);
void novemdecuple_indir(void *******************x, int arr_sz);
void vigintuple_indir(void ********************x, int arr_sz);
void unvigintuple_indir(void *********************x, int arr_sz);
void duovigintuple_indir(void **********************x, int arr_sz);
void trevigintuple_indir(void ***********************x, int arr_sz);
void quattuorvigintuple_indir(void ************************x, int arr_sz);
void quinvigintuple_indir(void *************************x, int arr_sz);
void sexvigintuple_indir(void **************************x, int arr_sz);
int main(void)
{
#define ARR_SIZE 10
int arr[ARR_SIZE] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
int *a = arr;
int **b = &a;
int ***c = &b;
int ****d = &c;
int *****e = &d;
int ******f = &e;
int *******g = &f;
int ********h = &g;
int *********i = &h;
int **********j = &i;
int ***********k = &j;
int ************l = &k;
int *************m = &l;
int **************n = &m;
int ***************o = &n;
int ****************p = &o;
int *****************q = &p;
int ******************r = &q;
int *******************s = &r;
int ********************t = &s;
int *********************u = &t;
int **********************v = &u;
int ***********************w = &v;
int ************************x = &w;
int *************************y = &x;
int **************************z = &y;
printf("one level indirection\n");
single_indir((void*)&arr, ARR_SIZE);
single_indir((void*)a, ARR_SIZE);
printf("\ntwo levels indirection\n");
double_indir((void**)&a, ARR_SIZE);
double_indir((void**)b, ARR_SIZE);
printf("\nthree levels indirection\n");
triple_indir((void***)&b, ARR_SIZE);
triple_indir((void***)c, ARR_SIZE);
printf("\nfour levels indirection\n");
quadruple_indir((void****)&c, ARR_SIZE);
quadruple_indir((void****)d, ARR_SIZE);
printf("\nfive levels indirection\n");
quintuple_indir((void*****)&d, ARR_SIZE);
quintuple_indir((void*****)e, ARR_SIZE);
printf("\nsix levels indirection\n");
sextuple_indir((void******)&e, ARR_SIZE);
sextuple_indir((void******)f, ARR_SIZE);
printf("\nseven levels indirection\n");
septuple_indir((void*******)&f, ARR_SIZE);
septuple_indir((void*******)g, ARR_SIZE);
printf("\neight levels indirection\n");
octuple_indir((void********)&g, ARR_SIZE);
octuple_indir((void********)h, ARR_SIZE);
printf("\nnine levels indirection\n");
nonuple_indir((void*********)&h, ARR_SIZE);
nonuple_indir((void*********)i, ARR_SIZE);
printf("\nten levels indirection\n");
decuple_indir((void**********)&i, ARR_SIZE);
decuple_indir((void**********)j, ARR_SIZE);
printf("\neleven levels indirection\n");
undecuple_indir((void***********)&j, ARR_SIZE);
undecuple_indir((void***********)k, ARR_SIZE);
printf("\ntwelve levels indirection\n");
duodecuple_indir((void************)&k, ARR_SIZE);
duodecuple_indir((void************)l, ARR_SIZE);
printf("\nthirteen levels indirection\n");
tredecuple_indir((void*************)&l, ARR_SIZE);
tredecuple_indir((void*************)m, ARR_SIZE);
printf("\nfourteen levels indirection\n");
quattuordecuple_indir((void**************)&m, ARR_SIZE);
quattuordecuple_indir((void**************)n, ARR_SIZE);
printf("\nfifteen levels indirection\n");
quindecuple_indir((void***************)&n, ARR_SIZE);
quindecuple_indir((void***************)o, ARR_SIZE);
printf("\nsixteen levels indirection\n");
sexdecuple_indir((void****************)&o, ARR_SIZE);
sexdecuple_indir((void****************)p, ARR_SIZE);
printf("\nseventeen levels indirection\n");
septendecuple_indir((void*****************)&p, ARR_SIZE);
septendecuple_indir((void*****************)q, ARR_SIZE);
printf("\neighteen levels indirection\n");
octodecuple_indir((void******************)&q, ARR_SIZE);
octodecuple_indir((void******************)r, ARR_SIZE);
printf("\nnineteen levels indirection\n");
novemdecuple_indir((void*******************)&r, ARR_SIZE);
novemdecuple_indir((void*******************)s, ARR_SIZE);
printf("\ntwenty levels indirection\n");
vigintuple_indir((void********************)&s, ARR_SIZE);
vigintuple_indir((void********************)t, ARR_SIZE);
printf("\ntwentyone levels indirection\n");
unvigintuple_indir((void*********************)&t, ARR_SIZE);
unvigintuple_indir((void*********************)u, ARR_SIZE);
printf("\ntwentytwo levels indirection\n");
duovigintuple_indir((void**********************)&u, ARR_SIZE);
duovigintuple_indir((void**********************)v, ARR_SIZE);
printf("\ntwentythree levels indirection\n");
trevigintuple_indir((void***********************)&v, ARR_SIZE);
trevigintuple_indir((void***********************)w, ARR_SIZE);
printf("\ntwentyfour levels indirection\n");
quattuorvigintuple_indir((void************************)&w, ARR_SIZE);
quattuorvigintuple_indir((void************************)x, ARR_SIZE);
printf("\ntwentyfive levels indirection\n");
quinvigintuple_indir((void*************************)&x, ARR_SIZE);
quinvigintuple_indir((void*************************)y, ARR_SIZE);
printf("\ntwentysix levels indirection\n");
sexvigintuple_indir((void**************************)&y, ARR_SIZE);
sexvigintuple_indir((void**************************)z, ARR_SIZE);
return 0;
}
void single_indir(void *x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *((int*)x + i));
}
putchar('\n');
}
void double_indir(void **x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *((int*)*x + i));
}
putchar('\n');
}
void triple_indir(void ***x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(int**)*x + i));
}
putchar('\n');
}
void quadruple_indir(void ****x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(int***)*x) + i));
}
putchar('\n');
}
void quintuple_indir(void *****x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(int****)*x)) + i));
}
putchar('\n');
}
void sextuple_indir(void ******x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(int*****)*x))) + i));
}
putchar('\n');
}
void septuple_indir(void *******x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(int******)*x)))) + i));
}
putchar('\n');
}
void octuple_indir(void ********x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(int*******)*x))))) + i));
}
putchar('\n');
}
void nonuple_indir(void *********x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(int********)*x)))))) + i));
}
putchar('\n');
}
void decuple_indir(void **********x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(int*********)*x))))))) + i));
}
putchar('\n');
}
void undecuple_indir(void ***********x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(int**********)*x)))))))) + i));
}
putchar('\n');
}
void duodecuple_indir(void ************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(int***********)*x))))))))) + i));
}
putchar('\n');
}
void tredecuple_indir(void *************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(int************)*x)))))))))) + i));
}
putchar('\n');
}
void quattuordecuple_indir(void **************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(*(int*************)*x))))))))))) + i));
}
putchar('\n');
}
void quindecuple_indir(void ***************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(*(*(int**************)*x)))))))))))) + i));
}
putchar('\n');
}
void sexdecuple_indir(void ****************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(*(*(*(int***************)*x))))))))))))) + i));
}
putchar('\n');
}
void septendecuple_indir(void *****************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(int****************)*x)))))))))))))) + i));
}
putchar('\n');
}
void octodecuple_indir(void ******************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(int*****************)*x))))))))))))))) + i));
}
putchar('\n');
}
void novemdecuple_indir(void *******************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(int******************)*x)))))))))))))))) + i));
}
putchar('\n');
}
void vigintuple_indir(void ********************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(int*******************)*x))))))))))))))))) + i));
}
putchar('\n');
}
void unvigintuple_indir(void *********************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(int********************)*x)))))))))))))))))) + i));
}
putchar('\n');
}
void duovigintuple_indir(void **********************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(int*********************)*x))))))))))))))))))) + i));
}
putchar('\n');
}
void trevigintuple_indir(void ***********************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(int**********************)*x)))))))))))))))))))) + i));
}
putchar('\n');
}
void quattuorvigintuple_indir(void ************************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(int***********************)*x))))))))))))))))))))) + i));
}
putchar('\n');
}
void quinvigintuple_indir(void *************************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(int************************)*x)))))))))))))))))))))) + i));
}
putchar('\n');
}
void sexvigintuple_indir(void **************************x, int arr_sz)
{
int i;
for (i = 0; (i < arr_sz) && x; i++) {
printf("%d ", *(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(*(int*************************)*x))))))))))))))))))))))) + i));
}
putchar('\n');
}
|
the_stack_data/22012771.c | #include<stdint.h>
#include<stdio.h>
#include<string.h>
int int32_sum(int32_t *X, int n, int64_t *ptr_sum)
{
int status = 0;
int i;
/* printf("\nAdded called witharray sz %d", n);
printf("\nArray is:");
for (i = 0; i < n; i++)
printf("%d, ", X[i]);*/
int64_t sum = 0;
for (i= 0; i < n; i++ ) {
sum += X[i];
}
*ptr_sum = sum;
//printf("\nSum = %llu", *ptr_sum); //prints the sum calculated here
return status;
}
int int8_sum(int8_t *X, int n, int16_t *ptr_sum)
{
int status = 0;
int i;
/*printf("\nAdded called witharray sz %d", n);
printf("\nArray is:");
for (i = 0; i < n; i++)
printf("%d, ", X[i]);*/
int16_t sum = 0;
for (i= 0; i < n; i++ ) {
sum += X[i];
}
*ptr_sum = sum;
//printf("\nSum = %d", *ptr_sum);
return status;
}
int int16_sum(int16_t *X, int n, int32_t *ptr_sum)
{
int status = 0;
int i;
/* printf("\nAdded called witharray sz %d", n);
printf("\nArray is:");
for (i = 0; i < n; i++)
printf("%d, ", X[i]);*/
int32_t sum = 0;
for (i= 0; i < n; i++ ) {
sum += X[i];
}
*ptr_sum = sum;
//printf("\nSum = %d", *ptr_sum);
return status;
}
int int64_sum(int64_t *X, int n, int64_t *ptr_sum)
{
int status = 0;
int i;
/* printf("\nAdded called witharray sz %d", n);
printf("\nArray is:");
for (i = 0; i < n; i++)
printf("%llu, ", X[i]);*/
int64_t sum = 0;
for (i= 0; i < n; i++ ) {
sum += X[i];
}
*ptr_sum = sum;
//printf("\nSum = %llu", *ptr_sum);
return status;
}
int uint8_sum(uint8_t *X, int n, uint16_t *ptr_sum)
{
int status = 0;
int i;
/* printf("\nAdded called witharray sz %d", n);
printf("\nArray is:");
for (i= 0; i < n; i++)
printf("%u, ", X[i]);*/
uint16_t sum = 0;
for (i = 0; i < n; i++ ) {
sum += X[i];
}
*ptr_sum = sum;
//printf("\nSum = %u", *ptr_sum);
return status;
}
int uint16_sum(uint16_t *X, int n, uint32_t *ptr_sum)
{
int status = 0;
int i;
/* printf("\nAdded called witharray sz %d", n);
printf("\nArray is:");
for (i= 0; i < n; i++)
printf("%u, ", X[i]);*/
uint32_t sum = 0;
for (i = 0; i < n; i++ ) {
sum += X[i];
}
*ptr_sum = sum;
//printf("\nSum = %u", *ptr_sum);
return status;
}
int uint32_sum(uint32_t *X, int n, uint64_t *ptr_sum)
{
int status = 0;
int i;
/* printf("Added called witharray sz %d", n);
printf("\nArray is:");
for (i= 0; i < n; i++)
printf("%u, ", X[i]);*/
uint64_t sum = 0;
for (i = 0; i < n; i++ ) {
sum += X[i];
}
*ptr_sum = sum;
//printf("\nSum = %llu", *ptr_sum);
return status;
}
int uint64_sum(uint64_t *X, int n, uint64_t *ptr_sum)
{
int status = 0;
int i;
/* printf("\nAdded called witharray sz %d", n);
printf("\nArray is:");
for (i= 0; i < n; i++)
printf("%llu, ", X[i]);*/
uint64_t sum = 0;
for (i = 0; i < n; i++ ) {
sum += X[i];
}
*ptr_sum = sum;
//printf("\nSum = %llu ", *ptr_sum);
return status;
}
int float_sum(float *X, int n, float *ptr_sum)
{
int status = 0;
int i;
/* printf("\nAdded called witharray sz %d", n);
printf("\nArray is:");
for (i= 0; i < n; i++)
printf("%f, ", X[i]);*/
float sum = 0;
for (i = 0; i < n; i++ ) {
sum += X[i];
}
*ptr_sum = sum;
//printf("\nSum = %2.10f", *ptr_sum);
return status;
}
int double_sum(double *X, int n, double *ptr_sum)
{
int status = 0;
int i;
/* printf("\nAdded called witharray sz %d", n);
printf("\nArray is:");
for (i= 0; i < n; i++)
printf("%2.10lf, ", X[i]);*/
float sum = 0;
for (i = 0; i < n; i++ ) {
sum += X[i];
}
*ptr_sum = sum;
//printf("\nSum = %2.10lf", *ptr_sum);
return status;
}
int char_sum(char *X, int n, char *ptr_sum)
{
int status = 0;
int i;
/* printf("\nAdded called witharray sz %d", n);
printf("\nArray is:");
for (i= 0; i < n; i++)
printf("%d, ", X[i]);*/
char sum = 0;
for (i = 0; i < n; i++ ) {
sum += X[i];
}
*ptr_sum = sum;
//printf("\nSum = %d", *ptr_sum);
return status;
} |
the_stack_data/46427.c | /*Exercise 4 - Functions
Implement the three functions minimum(), maximum() and multiply() below the main() function.
Do not change the code given in the main() function when you are implementing your solution.*/
#include <stdio.h>
int main() {
int no1, no2;
printf("Enter a value for no 1 : ");
scanf("%d", &no1);
printf("Enter a value for no 2 : ");
scanf("%d", &no2);
printf("%d", minimum(no1,no2));
printf("%d", maximum(no1,no2));
printf("%d", multiply(no1,no2));
return 0;
}
int minimum ( int no1, int no2 )
{
if( no1 > no2 )
{
return no2;
}
else if ( no2 > no1 )
{
return no1;
}
}
int maximum ( int no1, int no2 )
{
if( no1 > no2 )
{
return no1;
}
else if ( no2 > no1 )
{
return no2;
}
}
int multiply ( int no1, int no2 )
{
return no1 * no2;
}
|
the_stack_data/187643100.c | #include<stdio.h>
int main()
{
return 0;
} |
the_stack_data/61361.c | #include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdint.h>
#define MAX_BUFF_SIZE 10
//in_offs = tail
//out_offs = head
typedef struct{
int data[MAX_BUFF_SIZE];
int out_offs;
int in_offs;
int *start;
bool full;
}circular_buffer;
void push_buffer(circular_buffer* buff, int data){
//Check for full buffer here
if(buff->full == true){
// printf("Buffer is full!\n");
buff->data[buff->in_offs] = data;
buff->in_offs++;
buff->out_offs++;
return;
}
buff->data[buff->in_offs] = data;
buff->in_offs++; //careful with this
//If in_offs reaches end, roll back
if(buff->in_offs == MAX_BUFF_SIZE)
buff->in_offs = 0;
//Check if full,either out_offs == in_offs
if(buff->in_offs == buff->out_offs)
buff->full = true;
}
int pop_buffer(circular_buffer* buff){
//If buffer is empty, send nothing
if((buff->out_offs == buff->in_offs) && (!buff->full)){
printf("buffer is empty cant pop!\n");
return -1;
}
//get the value, increment the out_offs and unset the flag
int ret_val = buff->data[buff->out_offs];
buff->data[buff->out_offs] = 0;
buff->out_offs++; //careful with this
buff->full = false; //will be immediately unfulled if out_offs goes aout_offs
//If out_offs reaches end, roll back
if(buff->out_offs == MAX_BUFF_SIZE)
buff->out_offs = 0;
return ret_val;
}
void print_buffer(circular_buffer* buff){
for(int i=0;i<MAX_BUFF_SIZE;i++){
printf("%d ",buff->data[i]);
}
printf("\n");
}
int main(void)
{
circular_buffer buffer;
//initialize the buffer
memset(&buffer,0,sizeof(circular_buffer));
//initialize the buffer parameters
buffer.full = false;
//pop_buffer(&buffer);
push_buffer(&buffer, 1);
push_buffer(&buffer, 2);
push_buffer(&buffer, 3);
push_buffer(&buffer, 4);
push_buffer(&buffer, 5);
push_buffer(&buffer, 6);
push_buffer(&buffer, 7);
push_buffer(&buffer, 8);
push_buffer(&buffer, 9);
push_buffer(&buffer, 10);
pop_buffer(&buffer);
pop_buffer(&buffer);
push_buffer(&buffer, 11);
// push_buffer(&buffer, 12);
push_buffer(&buffer, 13);
push_buffer(&buffer, 14);
push_buffer(&buffer, 15);
print_buffer(&buffer);
return 0;
} |
the_stack_data/1116689.c | #include<stdlib.h>
#include<stdio.h>
int main(void){
void *p,*q,*w,*e;
p = malloc(1);
q = malloc(1);
w = malloc(1);
e = malloc(1);
printf("%p\n",p);
printf("%p\n",q);
printf("%p\n",w);
printf("%p\n",e);
free(p);
free(q);
free(w);
free(e);
return 0;
} |
the_stack_data/168894261.c | // ==============================================================
// File generated by Vivado(TM) HLS - High-Level Synthesis from C, C++ and SystemC
// Version: 2016.1
// Copyright (C) 1986-2016 Xilinx, Inc. All Rights Reserved.
//
// ==============================================================
#ifndef __linux__
#include "xstatus.h"
#include "xparameters.h"
#include "xtrace_cntrl.h"
extern XTrace_cntrl_Config XTrace_cntrl_ConfigTable[];
XTrace_cntrl_Config *XTrace_cntrl_LookupConfig(u16 DeviceId) {
XTrace_cntrl_Config *ConfigPtr = NULL;
int Index;
for (Index = 0; Index < XPAR_XTRACE_CNTRL_NUM_INSTANCES; Index++) {
if (XTrace_cntrl_ConfigTable[Index].DeviceId == DeviceId) {
ConfigPtr = &XTrace_cntrl_ConfigTable[Index];
break;
}
}
return ConfigPtr;
}
int XTrace_cntrl_Initialize(XTrace_cntrl *InstancePtr, u16 DeviceId) {
XTrace_cntrl_Config *ConfigPtr;
Xil_AssertNonvoid(InstancePtr != NULL);
ConfigPtr = XTrace_cntrl_LookupConfig(DeviceId);
if (ConfigPtr == NULL) {
InstancePtr->IsReady = 0;
return (XST_DEVICE_NOT_FOUND);
}
return XTrace_cntrl_CfgInitialize(InstancePtr, ConfigPtr);
}
#endif
|
the_stack_data/81627.c | #include <pthread.h>
#include <stdio.h>
#define NLOOP 5000
/* increment by threads */
int counter;
void *doit(void *vptr)
{
int i, val;
for (i=0; i<NLOOP; i++) {
val = counter;
printf("%x: %d\n", (unsigned int)pthread_self(), val+1);
counter = val + 1;
}
return NULL;
}
int main()
{
pthread_t tidA, tidB;
pthread_create(&tidA, NULL, doit, NULL);
pthread_create(&tidB, NULL, doit, NULL);
/* wait for both threads to terminate */
pthread_join(tidA, NULL);
pthread_join(tidB, NULL);
return 0;
}
|
the_stack_data/187642288.c | /*
version 20081011
Matthew Dempsky
Public domain.
Derived from public domain code by D. J. Bernstein.
Changes by Pedro A. Hortas:
- Minor changes were performed to allow smooth integration with libpsec.
*/
static void add(unsigned int out[32],const unsigned int a[32],const unsigned int b[32])
{
unsigned int j;
unsigned int u;
u = 0;
for (j = 0;j < 31;++j) { u += a[j] + b[j]; out[j] = u & 255; u >>= 8; }
u += a[31] + b[31]; out[31] = u;
}
static void sub(unsigned int out[32],const unsigned int a[32],const unsigned int b[32])
{
unsigned int j;
unsigned int u;
u = 218;
for (j = 0;j < 31;++j) {
u += a[j] + 65280 - b[j];
out[j] = u & 255;
u >>= 8;
}
u += a[31] - b[31];
out[31] = u;
}
static void squeeze(unsigned int a[32])
{
unsigned int j;
unsigned int u;
u = 0;
for (j = 0;j < 31;++j) { u += a[j]; a[j] = u & 255; u >>= 8; }
u += a[31]; a[31] = u & 127;
u = 19 * (u >> 7);
for (j = 0;j < 31;++j) { u += a[j]; a[j] = u & 255; u >>= 8; }
u += a[31]; a[31] = u;
}
static const unsigned int minusp[32] = {
19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128
} ;
static void freeze(unsigned int a[32])
{
unsigned int aorig[32];
unsigned int j;
unsigned int negative;
for (j = 0;j < 32;++j) aorig[j] = a[j];
add(a,a,minusp);
negative = -((a[31] >> 7) & 1);
for (j = 0;j < 32;++j) a[j] ^= negative & (aorig[j] ^ a[j]);
}
static void mult(unsigned int out[32],const unsigned int a[32],const unsigned int b[32])
{
unsigned int i;
unsigned int j;
unsigned int u;
for (i = 0;i < 32;++i) {
u = 0;
for (j = 0;j <= i;++j) u += a[j] * b[i - j];
for (j = i + 1;j < 32;++j) u += 38 * a[j] * b[i + 32 - j];
out[i] = u;
}
squeeze(out);
}
static void mult121665(unsigned int out[32],const unsigned int a[32])
{
unsigned int j;
unsigned int u;
u = 0;
for (j = 0;j < 31;++j) { u += 121665 * a[j]; out[j] = u & 255; u >>= 8; }
u += 121665 * a[31]; out[31] = u & 127;
u = 19 * (u >> 7);
for (j = 0;j < 31;++j) { u += out[j]; out[j] = u & 255; u >>= 8; }
u += out[j]; out[j] = u;
}
static void square(unsigned int out[32],const unsigned int a[32])
{
unsigned int i;
unsigned int j;
unsigned int u;
for (i = 0;i < 32;++i) {
u = 0;
for (j = 0;j < i - j;++j) u += a[j] * a[i - j];
for (j = i + 1;j < i + 32 - j;++j) u += 38 * a[j] * a[i + 32 - j];
u *= 2;
if ((i & 1) == 0) {
u += a[i / 2] * a[i / 2];
u += 38 * a[i / 2 + 16] * a[i / 2 + 16];
}
out[i] = u;
}
squeeze(out);
}
static void select(unsigned int p[64],unsigned int q[64],const unsigned int r[64],const unsigned int s[64],unsigned int b)
{
unsigned int j;
unsigned int t;
unsigned int bminus1;
bminus1 = b - 1;
for (j = 0;j < 64;++j) {
t = bminus1 & (r[j] ^ s[j]);
p[j] = s[j] ^ t;
q[j] = r[j] ^ t;
}
}
static void mainloop(unsigned int work[64],const unsigned char e[32])
{
unsigned int xzm1[64];
unsigned int xzm[64];
unsigned int xzmb[64];
unsigned int xzm1b[64];
unsigned int xznb[64];
unsigned int xzn1b[64];
unsigned int a0[64];
unsigned int a1[64];
unsigned int b0[64];
unsigned int b1[64];
unsigned int c1[64];
unsigned int r[32];
unsigned int s[32];
unsigned int t[32];
unsigned int u[32];
/* unsigned int i; */
unsigned int j;
unsigned int b;
int pos;
for (j = 0;j < 32;++j) xzm1[j] = work[j];
xzm1[32] = 1;
for (j = 33;j < 64;++j) xzm1[j] = 0;
xzm[0] = 1;
for (j = 1;j < 64;++j) xzm[j] = 0;
for (pos = 254;pos >= 0;--pos) {
b = e[pos / 8] >> (pos & 7);
b &= 1;
select(xzmb,xzm1b,xzm,xzm1,b);
add(a0,xzmb,xzmb + 32);
sub(a0 + 32,xzmb,xzmb + 32);
add(a1,xzm1b,xzm1b + 32);
sub(a1 + 32,xzm1b,xzm1b + 32);
square(b0,a0);
square(b0 + 32,a0 + 32);
mult(b1,a1,a0 + 32);
mult(b1 + 32,a1 + 32,a0);
add(c1,b1,b1 + 32);
sub(c1 + 32,b1,b1 + 32);
square(r,c1 + 32);
sub(s,b0,b0 + 32);
mult121665(t,s);
add(u,t,b0);
mult(xznb,b0,b0 + 32);
mult(xznb + 32,s,u);
square(xzn1b,c1);
mult(xzn1b + 32,r,work);
select(xzm,xzm1,xznb,xzn1b,b);
}
for (j = 0;j < 64;++j) work[j] = xzm[j];
}
static void recip(unsigned int out[32],const unsigned int z[32])
{
unsigned int z2[32];
unsigned int z9[32];
unsigned int z11[32];
unsigned int z2_5_0[32];
unsigned int z2_10_0[32];
unsigned int z2_20_0[32];
unsigned int z2_50_0[32];
unsigned int z2_100_0[32];
unsigned int t0[32];
unsigned int t1[32];
int i;
/* 2 */ square(z2,z);
/* 4 */ square(t1,z2);
/* 8 */ square(t0,t1);
/* 9 */ mult(z9,t0,z);
/* 11 */ mult(z11,z9,z2);
/* 22 */ square(t0,z11);
/* 2^5 - 2^0 = 31 */ mult(z2_5_0,t0,z9);
/* 2^6 - 2^1 */ square(t0,z2_5_0);
/* 2^7 - 2^2 */ square(t1,t0);
/* 2^8 - 2^3 */ square(t0,t1);
/* 2^9 - 2^4 */ square(t1,t0);
/* 2^10 - 2^5 */ square(t0,t1);
/* 2^10 - 2^0 */ mult(z2_10_0,t0,z2_5_0);
/* 2^11 - 2^1 */ square(t0,z2_10_0);
/* 2^12 - 2^2 */ square(t1,t0);
/* 2^20 - 2^10 */ for (i = 2;i < 10;i += 2) { square(t0,t1); square(t1,t0); }
/* 2^20 - 2^0 */ mult(z2_20_0,t1,z2_10_0);
/* 2^21 - 2^1 */ square(t0,z2_20_0);
/* 2^22 - 2^2 */ square(t1,t0);
/* 2^40 - 2^20 */ for (i = 2;i < 20;i += 2) { square(t0,t1); square(t1,t0); }
/* 2^40 - 2^0 */ mult(t0,t1,z2_20_0);
/* 2^41 - 2^1 */ square(t1,t0);
/* 2^42 - 2^2 */ square(t0,t1);
/* 2^50 - 2^10 */ for (i = 2;i < 10;i += 2) { square(t1,t0); square(t0,t1); }
/* 2^50 - 2^0 */ mult(z2_50_0,t0,z2_10_0);
/* 2^51 - 2^1 */ square(t0,z2_50_0);
/* 2^52 - 2^2 */ square(t1,t0);
/* 2^100 - 2^50 */ for (i = 2;i < 50;i += 2) { square(t0,t1); square(t1,t0); }
/* 2^100 - 2^0 */ mult(z2_100_0,t1,z2_50_0);
/* 2^101 - 2^1 */ square(t1,z2_100_0);
/* 2^102 - 2^2 */ square(t0,t1);
/* 2^200 - 2^100 */ for (i = 2;i < 100;i += 2) { square(t1,t0); square(t0,t1); }
/* 2^200 - 2^0 */ mult(t1,t0,z2_100_0);
/* 2^201 - 2^1 */ square(t0,t1);
/* 2^202 - 2^2 */ square(t1,t0);
/* 2^250 - 2^50 */ for (i = 2;i < 50;i += 2) { square(t0,t1); square(t1,t0); }
/* 2^250 - 2^0 */ mult(t0,t1,z2_50_0);
/* 2^251 - 2^1 */ square(t1,t0);
/* 2^252 - 2^2 */ square(t0,t1);
/* 2^253 - 2^3 */ square(t1,t0);
/* 2^254 - 2^4 */ square(t0,t1);
/* 2^255 - 2^5 */ square(t1,t0);
/* 2^255 - 21 */ mult(out,t1,z11);
}
int crypto_scalarmult_curve25519_ref(
unsigned char *q,
const unsigned char *n,
const unsigned char *p)
{
unsigned int work[96];
unsigned char e[32];
unsigned int i;
for (i = 0;i < 32;++i) e[i] = n[i];
e[0] &= 248;
e[31] &= 127;
e[31] |= 64;
for (i = 0;i < 32;++i) work[i] = p[i];
mainloop(work,e);
recip(work + 32,work + 32);
mult(work + 64,work,work + 32);
freeze(work + 64);
for (i = 0;i < 32;++i) q[i] = work[64 + i];
return 0;
}
|
the_stack_data/167326730.c | #include <stdio.h>
int main (void)
{
printf("Hello, World!");
}
|
the_stack_data/115766207.c | /* This File is Part of LibFalcon.
* Copyright (c) 2018, Syed Nasim
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 LibFalcon nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if defined(__cplusplus)
extern "C" {
#endif
#include <ctype.h>
#include <stdint.h>
int32_t mul(const int32_t a, const int32_t b) {
return a * b;
}
#if defined(__cplusplus)
}
#endif
|
the_stack_data/211080171.c | /*
* random_exercise.c --- Test program which exercises an ext2
* filesystem. It creates a lot of random files in the current
* directory, while holding some files open while they are being
* deleted. This exercises the orphan list code, as well as
* creating lots of fodder for the ext3 journal.
*
* Copyright (C) 2000 Theodore Ts'o.
*
* %Begin-Header%
* This file may be redistributed under the terms of the GNU Public
* License.
* %End-Header%
*/
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define MAXFDS 128
struct state {
char name[16];
int state;
int isdir;
};
#define STATE_CLEAR 0
#define STATE_CREATED 1
#define STATE_DELETED 2
struct state state_array[MAXFDS];
#define DATA_SIZE 65536
char data_buffer[DATA_SIZE];
void clear_state_array()
{
int i;
for (i = 0; i < MAXFDS; i++)
state_array[i].state = STATE_CLEAR;
}
int get_random_fd()
{
int fd;
while (1) {
fd = ((int) random()) % MAXFDS;
if (fd > 2)
return fd;
}
}
unsigned int get_inode_num(int fd)
{
struct stat st;
if (fstat(fd, &st) < 0) {
perror("fstat");
return 0;
}
return st.st_ino;
}
void create_random_file()
{
char template[16] = "EX.XXXXXX";
int fd;
int isdir = 0;
int size;
mktemp(template);
isdir = random() & 1;
if (isdir) {
if (mkdir(template, 0700) < 0)
return;
fd = open(template, O_RDONLY, 0600);
printf("Created temp directory %s, fd = %d\n",
template, fd);
} else {
size = random() & (DATA_SIZE-1);
fd = open(template, O_CREAT|O_RDWR, 0600);
write(fd, data_buffer, size);
printf("Created temp file %s, fd = %d, size=%d\n",
template, fd, size);
}
state_array[fd].isdir = isdir;
if (fd < 0)
return;
state_array[fd].isdir = isdir;
state_array[fd].state = STATE_CREATED;
strcpy(state_array[fd].name, template);
}
void truncate_file(int fd)
{
int size;
size = random() & (DATA_SIZE-1);
if (state_array[fd].isdir)
return;
ftruncate(fd, size);
printf("Truncating temp file %s, fd = %d, ino=%u, size=%d\n",
state_array[fd].name, fd, get_inode_num(fd), size);
}
void unlink_file(int fd)
{
char *filename = state_array[fd].name;
printf("Deleting %s, fd = %d, ino = %u\n", filename, fd,
get_inode_num(fd));
if (state_array[fd].isdir)
rmdir(filename);
else
unlink(filename);
state_array[fd].state = STATE_DELETED;
}
void close_file(int fd)
{
char *filename = state_array[fd].name;
printf("Closing %s, fd = %d, ino = %u\n", filename, fd,
get_inode_num(fd));
close(fd);
state_array[fd].state = STATE_CLEAR;
}
main(int argc, char **argv)
{
int i, fd;
memset(data_buffer, 0, sizeof(data_buffer));
sprintf(data_buffer, "This is a test file created by the "
"random_exerciser program\n");
for (i=0; i < 100000; i++) {
fd = get_random_fd();
switch (state_array[fd].state) {
case STATE_CLEAR:
create_random_file();
break;
case STATE_CREATED:
if ((state_array[fd].isdir == 0) &&
(random() & 2))
truncate_file(fd);
else
unlink_file(fd);
break;
case STATE_DELETED:
close_file(fd);
break;
}
}
}
|
the_stack_data/145453971.c | /*Q5 - Pass by value:(passing parameters by value)*/
#include <stdio.h>
/* Declare Prototype */
void pass_by_value (int);
main()
{
int initial_number = 1;
printf("initial_number is %d\n", initial_number);
getchar();
/*Call function pass_by_value()*/
pass_by_value(initial_number);
getchar();
printf("\ninitial_number is still %d\n", initial_number);
getchar();
flushall();
}/*end main*/
/*Implement any_function()*/
void pass_by_value(int new_number)
{
new_number++;
printf("\nnew_number is %d\n", new_number);
}/*end function*/ |
the_stack_data/122015625.c | /*
* Test R5900-specific three-operand MADDU and MADDU1.
*/
#include <stdio.h>
#include <inttypes.h>
#include <assert.h>
uint64_t maddu(uint64_t a, uint32_t rs, uint32_t rt)
{
uint32_t lo = a;
uint32_t hi = a >> 32;
uint32_t rd;
uint64_t r;
__asm__ __volatile__ (
" mtlo %5\n"
" mthi %6\n"
" maddu %0, %3, %4\n"
" mflo %1\n"
" mfhi %2\n"
: "=r" (rd), "=r" (lo), "=r" (hi)
: "r" (rs), "r" (rt), "r" (lo), "r" (hi));
r = ((uint64_t)hi << 32) | (uint32_t)lo;
assert(a + (uint64_t)rs * rt == r);
assert(rd == lo);
return r;
}
uint64_t maddu1(uint64_t a, uint32_t rs, uint32_t rt)
{
uint32_t lo = a;
uint32_t hi = a >> 32;
uint32_t rd;
uint64_t r;
__asm__ __volatile__ (
" mtlo1 %5\n"
" mthi1 %6\n"
" maddu1 %0, %3, %4\n"
" mflo1 %1\n"
" mfhi1 %2\n"
: "=r" (rd), "=r" (lo), "=r" (hi)
: "r" (rs), "r" (rt), "r" (lo), "r" (hi));
r = ((uint64_t)hi << 32) | (uint32_t)lo;
assert(a + (uint64_t)rs * rt == r);
assert(rd == lo);
return r;
}
static int64_t maddu_variants(int64_t a, int32_t rs, int32_t rt)
{
int64_t rd = maddu(a, rs, rt);
int64_t rd1 = maddu1(a, rs, rt);
assert(rd == rd1);
return rd;
}
int main()
{
assert(maddu_variants(13, 17, 19) == 336);
return 0;
}
|
the_stack_data/215768014.c | /*
* POK header
*
* The following file is a part of the POK project. Any modification should
* made according to the POK licence. You CANNOT use this file or a part of
* this file is this 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-2009 POK team
*
* Created by julien on Fri Jan 16 17:13:16 2009
*/
#if defined(POK_NEEDS_ERROR_HANDLING) && (!defined(POK_USE_GENERATED_ERROR_HANDLER))
#include <core/error.h>
#include <core/thread.h>
#include <core/partition.h>
/*
* This is a default error handler and it is used
* when no error handled is defined.
* Most of the time, the generated code provides
* its own error handler.
*/
void pok_error_handler_worker() {
uint32_t thread = 0;
uint32_t error = 0;
pok_error_handler_set_ready(&thread, &error);
while (1) {
pok_partition_set_mode(POK_PARTITION_STATE_STOPPED);
}
}
#endif
|
the_stack_data/138910.c | int main(void) {
unsigned int x = 0;
unsigned int y = 1;
while (x < 6) {
x++;
y *= 2;
}
__VERIFIER_assert(x != 6);
}
|
the_stack_data/29826139.c | /*
gcc -std=c17 -lc -lm -pthread -o ../_build/c/numeric_math_asin.exe ./c/numeric_math_asin.c && (cd ../_build/c/;./numeric_math_asin.exe)
https://en.cppreference.com/w/c/numeric/math/asin
*/
#include <math.h>
#include <stdio.h>
#include <errno.h>
#include <fenv.h>
#include <string.h>
#pragma STDC FENV_ACCESS ON
int main(void)
{
printf("asin( 1.0) = %+f, 2*asin( 1.0)=%+f\n", asin(1), 2*asin(1));
printf("asin(-0.5) = %+f, 6*asin(-0.5)=%+f\n", asin(-0.5), 6*asin(-0.5));
// special values
printf("asin(0.0) = %1f, asin(-0.0)=%f\n", asin(+0.0), asin(-0.0));
// error handling
errno = 0; feclearexcept(FE_ALL_EXCEPT);
printf("asin(1.1) = %f\n", asin(1.1));
if(errno == EDOM) perror(" errno == EDOM");
if(fetestexcept(FE_INVALID)) puts(" FE_INVALID raised");
}
|
the_stack_data/150352.c | /***
* This code is a part of EvoApproxLib library (ehw.fit.vutbr.cz/approxlib) distributed under The MIT License.
* When used, please cite the following article(s): V. Mrazek, L. Sekanina, Z. Vasicek "Libraries of Approximate Circuits: Automated Design and Application in CNN Accelerators" IEEE Journal on Emerging and Selected Topics in Circuits and Systems, Vol 10, No 4, 2020
* This file contains a circuit from a sub-set of pareto optimal circuits with respect to the pwr and mse parameters
***/
// MAE% = 2.98 %
// MAE = 488
// WCE% = 11.68 %
// WCE = 1913
// WCRE% = 301.56 %
// EP% = 97.93 %
// MRE% = 34.19 %
// MSE = 376281
// PDK45_PWR = 0.025 mW
// PDK45_AREA = 78.4 um2
// PDK45_DELAY = 0.45 ns
#include <stdint.h>
#include <stdlib.h>
uint64_t mul8x6u_0SQ(const uint64_t A /* 8-bit unsigned operand */, const uint64_t B /* 6-bit unsigned operand */)
{
uint64_t dout_44, dout_45, dout_52, dout_53, dout_59, dout_60, dout_61, dout_120, dout_122, dout_123, dout_124, dout_125, dout_126, dout_127, dout_128, dout_129, dout_149, dout_196, dout_199, dout_201, dout_202, dout_204, dout_217, dout_219, dout_220, dout_221, dout_222, dout_233, dout_237, dout_238, dout_297, dout_305;
uint64_t O;
dout_44=((A >> 6)&1)&((B >> 3)&1);
dout_45=((A >> 7)&1)&((B >> 3)&1);
dout_52=((A >> 6)&1)&((B >> 4)&1);
dout_53=((A >> 7)&1)&((B >> 4)&1);
dout_59=((A >> 5)&1)&((B >> 5)&1);
dout_60=((A >> 6)&1)&((B >> 5)&1);
dout_61=((A >> 7)&1)&((B >> 5)&1);
dout_120=((B >> 5)&1)&((A >> 4)&1);
dout_122=dout_44|dout_120;
dout_123=dout_45^dout_52;
dout_124=dout_45&dout_52;
dout_125=dout_123&dout_59;
dout_126=dout_123^dout_59;
dout_127=dout_124|dout_125;
dout_128=dout_53&dout_60;
dout_129=dout_53^dout_60;
dout_149=((B >> 4)&1)&((A >> 5)&1);
dout_196=dout_126|dout_122;
dout_199=dout_196^dout_122;
dout_201=dout_129&dout_127;
dout_202=dout_129^dout_127;
dout_204=dout_61^dout_128;
dout_217=dout_199|dout_149;
dout_219=dout_202^dout_122;
dout_220=dout_202&dout_122;
dout_221=dout_204^dout_201;
dout_222=dout_204&dout_201;
dout_233=dout_128|dout_222;
dout_237=((A >> 7)&1)&dout_220;
dout_238=dout_221^dout_220;
dout_297=dout_237|dout_233;
dout_305=((A >> 7)&1)&((B >> 2)&1);
O = 0;
O |= (dout_204&1) << 0;
O |= (dout_128&1) << 1;
O |= (0&1) << 2;
O |= (dout_219&1) << 3;
O |= (dout_128&1) << 4;
O |= (dout_217&1) << 5;
O |= (dout_128&1) << 6;
O |= (dout_126&1) << 7;
O |= (dout_126&1) << 8;
O |= (dout_305&1) << 9;
O |= (dout_217&1) << 10;
O |= (dout_219&1) << 11;
O |= (dout_238&1) << 12;
O |= (dout_297&1) << 13;
return O;
}
|
the_stack_data/82949857.c | /* Copyright (C) 1991, 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sys/resource.h>
#include <sys/time.h>
#include <time.h>
#ifdef __GNUC__
__inline
#endif
static clock_t
timeval_to_clock_t (const struct timeval *tv)
{
return (clock_t) ((tv->tv_sec * CLOCKS_PER_SEC) +
(tv->tv_usec * CLOCKS_PER_SEC / 1000000));
}
/* Return the time used by the program so far (user time + system time). */
clock_t
clock (void)
{
struct rusage usage;
if (__getrusage (RUSAGE_SELF, &usage) < 0)
return (clock_t) -1;
return (timeval_to_clock_t (&usage.ru_stime) +
timeval_to_clock_t (&usage.ru_utime));
}
|
the_stack_data/76701057.c | /*
** EPITECH PROJECT, 2019
** my_print_alpha.c
** File description:
** print the alphabet in ascending order
*/
char *my_strlowcase(char *str)
{
int i = 0;
if (str == 0)
return (0);
while (str[i] != '\0') {
if (str[i] >= 'A' && str[i] <= 'Z') {
str[i] = str[i] + 32;
}
i++;
}
return (str);
} |
the_stack_data/54826033.c | #include<stdio.h>
#define MAX 10
void selection_sort(int[],int);
void min(int[],int,int,int*);
int main()
{
int a[MAX],n,i;
printf("Enter no. of elements: ");
scanf("%d",&n);
printf("Enter %d elements:\n",n);
for(i=0;i<n;i++)
scanf("%d",a+i);
printf("\nGiven Array:-\n");
for(i=0;i<n;i++)
printf(" %d",*(a+i));
selection_sort(a,n);
printf("\n\nSorted Array:-\n");
for(i=0;i<n;i++)
printf(" %d",*(a+i));
printf("\n\n");
return 0;
}
void selection_sort(int a[],int n)
{
int i,loc,temp;
for(i=0;i<n;i++)
{
min(a,n,i,&loc);
temp=a[i];
a[i]=a[loc];
a[loc]=temp;
}
return;
}
void min(int a[],int n,int k,int *loc)
{
int temp,j;
temp=a[k];*loc=k;
for(j=k+1;j<n;j++)
{
if(a[j]<temp)
{
temp=a[j];
*loc=j;
}
}
return;
}
|
the_stack_data/1001438.c | #include <math.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <complex.h>
#ifdef complex
#undef complex
#endif
#ifdef I
#undef I
#endif
#if defined(_WIN64)
typedef long long BLASLONG;
typedef unsigned long long BLASULONG;
#else
typedef long BLASLONG;
typedef unsigned long BLASULONG;
#endif
#ifdef LAPACK_ILP64
typedef BLASLONG blasint;
#if defined(_WIN64)
#define blasabs(x) llabs(x)
#else
#define blasabs(x) labs(x)
#endif
#else
typedef int blasint;
#define blasabs(x) abs(x)
#endif
typedef blasint integer;
typedef unsigned int uinteger;
typedef char *address;
typedef short int shortint;
typedef float real;
typedef double doublereal;
typedef struct { real r, i; } complex;
typedef struct { doublereal r, i; } doublecomplex;
#ifdef _MSC_VER
static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
#else
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
#endif
#define pCf(z) (*_pCf(z))
#define pCd(z) (*_pCd(z))
typedef int logical;
typedef short int shortlogical;
typedef char logical1;
typedef char integer1;
#define TRUE_ (1)
#define FALSE_ (0)
/* Extern is for use with -E */
#ifndef Extern
#define Extern extern
#endif
/* I/O stuff */
typedef int flag;
typedef int ftnlen;
typedef int ftnint;
/*external read, write*/
typedef struct
{ flag cierr;
ftnint ciunit;
flag ciend;
char *cifmt;
ftnint cirec;
} cilist;
/*internal read, write*/
typedef struct
{ flag icierr;
char *iciunit;
flag iciend;
char *icifmt;
ftnint icirlen;
ftnint icirnum;
} icilist;
/*open*/
typedef struct
{ flag oerr;
ftnint ounit;
char *ofnm;
ftnlen ofnmlen;
char *osta;
char *oacc;
char *ofm;
ftnint orl;
char *oblnk;
} olist;
/*close*/
typedef struct
{ flag cerr;
ftnint cunit;
char *csta;
} cllist;
/*rewind, backspace, endfile*/
typedef struct
{ flag aerr;
ftnint aunit;
} alist;
/* inquire */
typedef struct
{ flag inerr;
ftnint inunit;
char *infile;
ftnlen infilen;
ftnint *inex; /*parameters in standard's order*/
ftnint *inopen;
ftnint *innum;
ftnint *innamed;
char *inname;
ftnlen innamlen;
char *inacc;
ftnlen inacclen;
char *inseq;
ftnlen inseqlen;
char *indir;
ftnlen indirlen;
char *infmt;
ftnlen infmtlen;
char *inform;
ftnint informlen;
char *inunf;
ftnlen inunflen;
ftnint *inrecl;
ftnint *innrec;
char *inblank;
ftnlen inblanklen;
} inlist;
#define VOID void
union Multitype { /* for multiple entry points */
integer1 g;
shortint h;
integer i;
/* longint j; */
real r;
doublereal d;
complex c;
doublecomplex z;
};
typedef union Multitype Multitype;
struct Vardesc { /* for Namelist */
char *name;
char *addr;
ftnlen *dims;
int type;
};
typedef struct Vardesc Vardesc;
struct Namelist {
char *name;
Vardesc **vars;
int nvars;
};
typedef struct Namelist Namelist;
#define abs(x) ((x) >= 0 ? (x) : -(x))
#define dabs(x) (fabs(x))
#define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
#define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
#define dmin(a,b) (f2cmin(a,b))
#define dmax(a,b) (f2cmax(a,b))
#define bit_test(a,b) ((a) >> (b) & 1)
#define bit_clear(a,b) ((a) & ~((uinteger)1 << (b)))
#define bit_set(a,b) ((a) | ((uinteger)1 << (b)))
#define abort_() { sig_die("Fortran abort routine called", 1); }
#define c_abs(z) (cabsf(Cf(z)))
#define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
#ifdef _MSC_VER
#define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
#define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/Cd(b)._Val[1]);}
#else
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
#endif
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
//#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
#define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
#define d_abs(x) (fabs(*(x)))
#define d_acos(x) (acos(*(x)))
#define d_asin(x) (asin(*(x)))
#define d_atan(x) (atan(*(x)))
#define d_atn2(x, y) (atan2(*(x),*(y)))
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
#define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
#define d_cos(x) (cos(*(x)))
#define d_cosh(x) (cosh(*(x)))
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
#define d_exp(x) (exp(*(x)))
#define d_imag(z) (cimag(Cd(z)))
#define r_imag(z) (cimagf(Cf(z)))
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
#define d_log(x) (log(*(x)))
#define d_mod(x, y) (fmod(*(x), *(y)))
#define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
#define d_nint(x) u_nint(*(x))
#define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
#define d_sign(a,b) u_sign(*(a),*(b))
#define r_sign(a,b) u_sign(*(a),*(b))
#define d_sin(x) (sin(*(x)))
#define d_sinh(x) (sinh(*(x)))
#define d_sqrt(x) (sqrt(*(x)))
#define d_tan(x) (tan(*(x)))
#define d_tanh(x) (tanh(*(x)))
#define i_abs(x) abs(*(x))
#define i_dnnt(x) ((integer)u_nint(*(x)))
#define i_len(s, n) (n)
#define i_nint(x) ((integer)u_nint(*(x)))
#define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
#define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
#define pow_si(B,E) spow_ui(*(B),*(E))
#define pow_ri(B,E) spow_ui(*(B),*(E))
#define pow_di(B,E) dpow_ui(*(B),*(E))
#define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
#define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
#define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
#define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; }
#define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
#define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
#define sig_die(s, kill) { exit(1); }
#define s_stop(s, n) {exit(0);}
static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
#define z_abs(z) (cabs(Cd(z)))
#define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
#define myexit_() break;
#define mycycle_() continue;
#define myceiling_(w) {ceil(w)}
#define myhuge_(w) {HUGE_VAL}
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
#define mymaxloc_(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
/* procedure parameter types for -A and -C++ */
#define F2C_proc_par_types 1
#ifdef __cplusplus
typedef logical (*L_fp)(...);
#else
typedef logical (*L_fp)();
#endif
static float spow_ui(float x, integer n) {
float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static double dpow_ui(double x, integer n) {
double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#ifdef _MSC_VER
static _Fcomplex cpow_ui(complex x, integer n) {
complex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
for(u = n; ; ) {
if(u & 01) pow.r *= x.r, pow.i *= x.i;
if(u >>= 1) x.r *= x.r, x.i *= x.i;
else break;
}
}
_Fcomplex p={pow.r, pow.i};
return p;
}
#else
static _Complex float cpow_ui(_Complex float x, integer n) {
_Complex float pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
#ifdef _MSC_VER
static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
_Dcomplex pow={1.0,0.0}; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
for(u = n; ; ) {
if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
else break;
}
}
_Dcomplex p = {pow._Val[0], pow._Val[1]};
return p;
}
#else
static _Complex double zpow_ui(_Complex double x, integer n) {
_Complex double pow=1.0; unsigned long int u;
if(n != 0) {
if(n < 0) n = -n, x = 1/x;
for(u = n; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
#endif
static integer pow_ii(integer x, integer n) {
integer pow; unsigned long int u;
if (n <= 0) {
if (n == 0 || x == 1) pow = 1;
else if (x != -1) pow = x == 0 ? 1/x : 0;
else n = -n;
}
if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
u = n;
for(pow = 1; ; ) {
if(u & 01) pow *= x;
if(u >>= 1) x *= x;
else break;
}
}
return pow;
}
static integer dmaxloc_(double *w, integer s, integer e, integer *n)
{
double m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static integer smaxloc_(float *w, integer s, integer e, integer *n)
{
float m; integer i, mi;
for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
if (w[i-1]>m) mi=i ,m=w[i-1];
return mi-s+1;
}
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Fcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
}
}
pCf(z) = zdotc;
}
#else
_Complex float zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i]) * Cf(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
}
}
pCf(z) = zdotc;
}
#endif
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
integer n = *n_, incx = *incx_, incy = *incy_, i;
#ifdef _MSC_VER
_Dcomplex zdotc = {0.0, 0.0};
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
}
}
pCd(z) = zdotc;
}
#else
_Complex double zdotc = 0.0;
if (incx == 1 && incy == 1) {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i]) * Cd(&y[i]);
}
} else {
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
}
}
pCd(z) = zdotc;
}
#endif
/* -- translated by f2c (version 20000121).
You must link the resulting object file with the libraries:
-lf2c -lm (in that order)
*/
/* Table of constant values */
static integer c__10 = 10;
static integer c__1 = 1;
static integer c__2 = 2;
static integer c__3 = 3;
static integer c__4 = 4;
static integer c_n1 = -1;
/* > \brief <b> ZHEEVR_2STAGE computes the eigenvalues and, optionally, the left and/or right eigenvectors for
HE matrices</b> */
/* @precisions fortran z -> s d c */
/* =========== DOCUMENTATION =========== */
/* Online html documentation available at */
/* http://www.netlib.org/lapack/explore-html/ */
/* > \htmlonly */
/* > Download ZHEEVR_2STAGE + dependencies */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zheevr_
2stage.f"> */
/* > [TGZ]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zheevr_
2stage.f"> */
/* > [ZIP]</a> */
/* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zheevr_
2stage.f"> */
/* > [TXT]</a> */
/* > \endhtmlonly */
/* Definition: */
/* =========== */
/* SUBROUTINE ZHEEVR_2STAGE( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, */
/* IL, IU, ABSTOL, M, W, Z, LDZ, ISUPPZ, */
/* WORK, LWORK, RWORK, LRWORK, IWORK, */
/* LIWORK, INFO ) */
/* IMPLICIT NONE */
/* CHARACTER JOBZ, RANGE, UPLO */
/* INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LRWORK, LWORK, */
/* $ M, N */
/* DOUBLE PRECISION ABSTOL, VL, VU */
/* INTEGER ISUPPZ( * ), IWORK( * ) */
/* DOUBLE PRECISION RWORK( * ), W( * ) */
/* COMPLEX*16 A( LDA, * ), WORK( * ), Z( LDZ, * ) */
/* > \par Purpose: */
/* ============= */
/* > */
/* > \verbatim */
/* > */
/* > ZHEEVR_2STAGE computes selected eigenvalues and, optionally, eigenvectors */
/* > of a complex Hermitian matrix A using the 2stage technique for */
/* > the reduction to tridiagonal. Eigenvalues and eigenvectors can */
/* > be selected by specifying either a range of values or a range of */
/* > indices for the desired eigenvalues. */
/* > */
/* > ZHEEVR_2STAGE first reduces the matrix A to tridiagonal form T with a call */
/* > to ZHETRD. Then, whenever possible, ZHEEVR_2STAGE calls ZSTEMR to compute */
/* > eigenspectrum using Relatively Robust Representations. ZSTEMR */
/* > computes eigenvalues by the dqds algorithm, while orthogonal */
/* > eigenvectors are computed from various "good" L D L^T representations */
/* > (also known as Relatively Robust Representations). Gram-Schmidt */
/* > orthogonalization is avoided as far as possible. More specifically, */
/* > the various steps of the algorithm are as follows. */
/* > */
/* > For each unreduced block (submatrix) of T, */
/* > (a) Compute T - sigma I = L D L^T, so that L and D */
/* > define all the wanted eigenvalues to high relative accuracy. */
/* > This means that small relative changes in the entries of D and L */
/* > cause only small relative changes in the eigenvalues and */
/* > eigenvectors. The standard (unfactored) representation of the */
/* > tridiagonal matrix T does not have this property in general. */
/* > (b) Compute the eigenvalues to suitable accuracy. */
/* > If the eigenvectors are desired, the algorithm attains full */
/* > accuracy of the computed eigenvalues only right before */
/* > the corresponding vectors have to be computed, see steps c) and d). */
/* > (c) For each cluster of close eigenvalues, select a new */
/* > shift close to the cluster, find a new factorization, and refine */
/* > the shifted eigenvalues to suitable accuracy. */
/* > (d) For each eigenvalue with a large enough relative separation compute */
/* > the corresponding eigenvector by forming a rank revealing twisted */
/* > factorization. Go back to (c) for any clusters that remain. */
/* > */
/* > The desired accuracy of the output can be specified by the input */
/* > parameter ABSTOL. */
/* > */
/* > For more details, see DSTEMR's documentation and: */
/* > - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations */
/* > to compute orthogonal eigenvectors of symmetric tridiagonal matrices," */
/* > Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004. */
/* > - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and */
/* > Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25, */
/* > 2004. Also LAPACK Working Note 154. */
/* > - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric */
/* > tridiagonal eigenvalue/eigenvector problem", */
/* > Computer Science Division Technical Report No. UCB/CSD-97-971, */
/* > UC Berkeley, May 1997. */
/* > */
/* > */
/* > Note 1 : ZHEEVR_2STAGE calls ZSTEMR when the full spectrum is requested */
/* > on machines which conform to the ieee-754 floating point standard. */
/* > ZHEEVR_2STAGE calls DSTEBZ and ZSTEIN on non-ieee machines and */
/* > when partial spectrum requests are made. */
/* > */
/* > Normal execution of ZSTEMR may create NaNs and infinities and */
/* > hence may abort due to a floating point exception in environments */
/* > which do not handle NaNs and infinities in the ieee standard default */
/* > manner. */
/* > \endverbatim */
/* Arguments: */
/* ========== */
/* > \param[in] JOBZ */
/* > \verbatim */
/* > JOBZ is CHARACTER*1 */
/* > = 'N': Compute eigenvalues only; */
/* > = 'V': Compute eigenvalues and eigenvectors. */
/* > Not available in this release. */
/* > \endverbatim */
/* > */
/* > \param[in] RANGE */
/* > \verbatim */
/* > RANGE is CHARACTER*1 */
/* > = 'A': all eigenvalues will be found. */
/* > = 'V': all eigenvalues in the half-open interval (VL,VU] */
/* > will be found. */
/* > = 'I': the IL-th through IU-th eigenvalues will be found. */
/* > For RANGE = 'V' or 'I' and IU - IL < N - 1, DSTEBZ and */
/* > ZSTEIN are called */
/* > \endverbatim */
/* > */
/* > \param[in] UPLO */
/* > \verbatim */
/* > UPLO is CHARACTER*1 */
/* > = 'U': Upper triangle of A is stored; */
/* > = 'L': Lower triangle of A is stored. */
/* > \endverbatim */
/* > */
/* > \param[in] N */
/* > \verbatim */
/* > N is INTEGER */
/* > The order of the matrix A. N >= 0. */
/* > \endverbatim */
/* > */
/* > \param[in,out] A */
/* > \verbatim */
/* > A is COMPLEX*16 array, dimension (LDA, N) */
/* > On entry, the Hermitian matrix A. If UPLO = 'U', the */
/* > leading N-by-N upper triangular part of A contains the */
/* > upper triangular part of the matrix A. If UPLO = 'L', */
/* > the leading N-by-N lower triangular part of A contains */
/* > the lower triangular part of the matrix A. */
/* > On exit, the lower triangle (if UPLO='L') or the upper */
/* > triangle (if UPLO='U') of A, including the diagonal, is */
/* > destroyed. */
/* > \endverbatim */
/* > */
/* > \param[in] LDA */
/* > \verbatim */
/* > LDA is INTEGER */
/* > The leading dimension of the array A. LDA >= f2cmax(1,N). */
/* > \endverbatim */
/* > */
/* > \param[in] VL */
/* > \verbatim */
/* > VL is DOUBLE PRECISION */
/* > If RANGE='V', the lower bound of the interval to */
/* > be searched for eigenvalues. VL < VU. */
/* > Not referenced if RANGE = 'A' or 'I'. */
/* > \endverbatim */
/* > */
/* > \param[in] VU */
/* > \verbatim */
/* > VU is DOUBLE PRECISION */
/* > If RANGE='V', the upper bound of the interval to */
/* > be searched for eigenvalues. VL < VU. */
/* > Not referenced if RANGE = 'A' or 'I'. */
/* > \endverbatim */
/* > */
/* > \param[in] IL */
/* > \verbatim */
/* > IL is INTEGER */
/* > If RANGE='I', the index of the */
/* > smallest eigenvalue to be returned. */
/* > 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
/* > Not referenced if RANGE = 'A' or 'V'. */
/* > \endverbatim */
/* > */
/* > \param[in] IU */
/* > \verbatim */
/* > IU is INTEGER */
/* > If RANGE='I', the index of the */
/* > largest eigenvalue to be returned. */
/* > 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0. */
/* > Not referenced if RANGE = 'A' or 'V'. */
/* > \endverbatim */
/* > */
/* > \param[in] ABSTOL */
/* > \verbatim */
/* > ABSTOL is DOUBLE PRECISION */
/* > The absolute error tolerance for the eigenvalues. */
/* > An approximate eigenvalue is accepted as converged */
/* > when it is determined to lie in an interval [a,b] */
/* > of width less than or equal to */
/* > */
/* > ABSTOL + EPS * f2cmax( |a|,|b| ) , */
/* > */
/* > where EPS is the machine precision. If ABSTOL is less than */
/* > or equal to zero, then EPS*|T| will be used in its place, */
/* > where |T| is the 1-norm of the tridiagonal matrix obtained */
/* > by reducing A to tridiagonal form. */
/* > */
/* > See "Computing Small Singular Values of Bidiagonal Matrices */
/* > with Guaranteed High Relative Accuracy," by Demmel and */
/* > Kahan, LAPACK Working Note #3. */
/* > */
/* > If high relative accuracy is important, set ABSTOL to */
/* > DLAMCH( 'Safe minimum' ). Doing so will guarantee that */
/* > eigenvalues are computed to high relative accuracy when */
/* > possible in future releases. The current code does not */
/* > make any guarantees about high relative accuracy, but */
/* > future releases will. See J. Barlow and J. Demmel, */
/* > "Computing Accurate Eigensystems of Scaled Diagonally */
/* > Dominant Matrices", LAPACK Working Note #7, for a discussion */
/* > of which matrices define their eigenvalues to high relative */
/* > accuracy. */
/* > \endverbatim */
/* > */
/* > \param[out] M */
/* > \verbatim */
/* > M is INTEGER */
/* > The total number of eigenvalues found. 0 <= M <= N. */
/* > If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1. */
/* > \endverbatim */
/* > */
/* > \param[out] W */
/* > \verbatim */
/* > W is DOUBLE PRECISION array, dimension (N) */
/* > The first M elements contain the selected eigenvalues in */
/* > ascending order. */
/* > \endverbatim */
/* > */
/* > \param[out] Z */
/* > \verbatim */
/* > Z is COMPLEX*16 array, dimension (LDZ, f2cmax(1,M)) */
/* > If JOBZ = 'V', then if INFO = 0, the first M columns of Z */
/* > contain the orthonormal eigenvectors of the matrix A */
/* > corresponding to the selected eigenvalues, with the i-th */
/* > column of Z holding the eigenvector associated with W(i). */
/* > If JOBZ = 'N', then Z is not referenced. */
/* > Note: the user must ensure that at least f2cmax(1,M) columns are */
/* > supplied in the array Z; if RANGE = 'V', the exact value of M */
/* > is not known in advance and an upper bound must be used. */
/* > \endverbatim */
/* > */
/* > \param[in] LDZ */
/* > \verbatim */
/* > LDZ is INTEGER */
/* > The leading dimension of the array Z. LDZ >= 1, and if */
/* > JOBZ = 'V', LDZ >= f2cmax(1,N). */
/* > \endverbatim */
/* > */
/* > \param[out] ISUPPZ */
/* > \verbatim */
/* > ISUPPZ is INTEGER array, dimension ( 2*f2cmax(1,M) ) */
/* > The support of the eigenvectors in Z, i.e., the indices */
/* > indicating the nonzero elements in Z. The i-th eigenvector */
/* > is nonzero only in elements ISUPPZ( 2*i-1 ) through */
/* > ISUPPZ( 2*i ). This is an output of ZSTEMR (tridiagonal */
/* > matrix). The support of the eigenvectors of A is typically */
/* > 1:N because of the unitary transformations applied by ZUNMTR. */
/* > Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1 */
/* > \endverbatim */
/* > */
/* > \param[out] WORK */
/* > \verbatim */
/* > WORK is COMPLEX*16 array, dimension (MAX(1,LWORK)) */
/* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */
/* > \endverbatim */
/* > */
/* > \param[in] LWORK */
/* > \verbatim */
/* > LWORK is INTEGER */
/* > The dimension of the array WORK. */
/* > If JOBZ = 'N' and N > 1, LWORK must be queried. */
/* > LWORK = MAX(1, 26*N, dimension) where */
/* > dimension = f2cmax(stage1,stage2) + (KD+1)*N + N */
/* > = N*KD + N*f2cmax(KD+1,FACTOPTNB) */
/* > + f2cmax(2*KD*KD, KD*NTHREADS) */
/* > + (KD+1)*N + N */
/* > where KD is the blocking size of the reduction, */
/* > FACTOPTNB is the blocking used by the QR or LQ */
/* > algorithm, usually FACTOPTNB=128 is a good choice */
/* > NTHREADS is the number of threads used when */
/* > openMP compilation is enabled, otherwise =1. */
/* > If JOBZ = 'V' and N > 1, LWORK must be queried. Not yet available */
/* > */
/* > If LWORK = -1, then a workspace query is assumed; the routine */
/* > only calculates the optimal sizes of the WORK, RWORK and */
/* > IWORK arrays, returns these values as the first entries of */
/* > the WORK, RWORK and IWORK arrays, and no error message */
/* > related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
/* > \endverbatim */
/* > */
/* > \param[out] RWORK */
/* > \verbatim */
/* > RWORK is DOUBLE PRECISION array, dimension (MAX(1,LRWORK)) */
/* > On exit, if INFO = 0, RWORK(1) returns the optimal */
/* > (and minimal) LRWORK. */
/* > \endverbatim */
/* > */
/* > \param[in] LRWORK */
/* > \verbatim */
/* > LRWORK is INTEGER */
/* > The length of the array RWORK. LRWORK >= f2cmax(1,24*N). */
/* > */
/* > If LRWORK = -1, then a workspace query is assumed; the */
/* > routine only calculates the optimal sizes of the WORK, RWORK */
/* > and IWORK arrays, returns these values as the first entries */
/* > of the WORK, RWORK and IWORK arrays, and no error message */
/* > related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
/* > \endverbatim */
/* > */
/* > \param[out] IWORK */
/* > \verbatim */
/* > IWORK is INTEGER array, dimension (MAX(1,LIWORK)) */
/* > On exit, if INFO = 0, IWORK(1) returns the optimal */
/* > (and minimal) LIWORK. */
/* > \endverbatim */
/* > */
/* > \param[in] LIWORK */
/* > \verbatim */
/* > LIWORK is INTEGER */
/* > The dimension of the array IWORK. LIWORK >= f2cmax(1,10*N). */
/* > */
/* > If LIWORK = -1, then a workspace query is assumed; the */
/* > routine only calculates the optimal sizes of the WORK, RWORK */
/* > and IWORK arrays, returns these values as the first entries */
/* > of the WORK, RWORK and IWORK arrays, and no error message */
/* > related to LWORK or LRWORK or LIWORK is issued by XERBLA. */
/* > \endverbatim */
/* > */
/* > \param[out] INFO */
/* > \verbatim */
/* > INFO is INTEGER */
/* > = 0: successful exit */
/* > < 0: if INFO = -i, the i-th argument had an illegal value */
/* > > 0: Internal error */
/* > \endverbatim */
/* Authors: */
/* ======== */
/* > \author Univ. of Tennessee */
/* > \author Univ. of California Berkeley */
/* > \author Univ. of Colorado Denver */
/* > \author NAG Ltd. */
/* > \date June 2016 */
/* > \ingroup complex16HEeigen */
/* > \par Contributors: */
/* ================== */
/* > */
/* > Inderjit Dhillon, IBM Almaden, USA \n */
/* > Osni Marques, LBNL/NERSC, USA \n */
/* > Ken Stanley, Computer Science Division, University of */
/* > California at Berkeley, USA \n */
/* > Jason Riedy, Computer Science Division, University of */
/* > California at Berkeley, USA \n */
/* > */
/* > \par Further Details: */
/* ===================== */
/* > */
/* > \verbatim */
/* > */
/* > All details about the 2stage techniques are available in: */
/* > */
/* > Azzam Haidar, Hatem Ltaief, and Jack Dongarra. */
/* > Parallel reduction to condensed forms for symmetric eigenvalue problems */
/* > using aggregated fine-grained and memory-aware kernels. In Proceedings */
/* > of 2011 International Conference for High Performance Computing, */
/* > Networking, Storage and Analysis (SC '11), New York, NY, USA, */
/* > Article 8 , 11 pages. */
/* > http://doi.acm.org/10.1145/2063384.2063394 */
/* > */
/* > A. Haidar, J. Kurzak, P. Luszczek, 2013. */
/* > An improved parallel singular value algorithm and its implementation */
/* > for multicore hardware, In Proceedings of 2013 International Conference */
/* > for High Performance Computing, Networking, Storage and Analysis (SC '13). */
/* > Denver, Colorado, USA, 2013. */
/* > Article 90, 12 pages. */
/* > http://doi.acm.org/10.1145/2503210.2503292 */
/* > */
/* > A. Haidar, R. Solca, S. Tomov, T. Schulthess and J. Dongarra. */
/* > A novel hybrid CPU-GPU generalized eigensolver for electronic structure */
/* > calculations based on fine-grained memory aware tasks. */
/* > International Journal of High Performance Computing Applications. */
/* > Volume 28 Issue 2, Pages 196-209, May 2014. */
/* > http://hpc.sagepub.com/content/28/2/196 */
/* > */
/* > \endverbatim */
/* ===================================================================== */
/* Subroutine */ int zheevr_2stage_(char *jobz, char *range, char *uplo,
integer *n, doublecomplex *a, integer *lda, doublereal *vl,
doublereal *vu, integer *il, integer *iu, doublereal *abstol, integer
*m, doublereal *w, doublecomplex *z__, integer *ldz, integer *isuppz,
doublecomplex *work, integer *lwork, doublereal *rwork, integer *
lrwork, integer *iwork, integer *liwork, integer *info)
{
/* System generated locals */
integer a_dim1, a_offset, z_dim1, z_offset, i__1, i__2;
doublereal d__1, d__2;
/* Local variables */
extern integer ilaenv2stage_(integer *, char *, char *, integer *,
integer *, integer *, integer *);
doublereal anrm;
integer imax;
doublereal rmin, rmax;
logical test;
integer itmp1, i__, j;
extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *,
integer *);
integer indrd, indre;
doublereal sigma;
extern logical lsame_(char *, char *);
integer iinfo;
extern /* Subroutine */ int zhetrd_2stage_(char *, char *, integer *,
doublecomplex *, integer *, doublereal *, doublereal *,
doublecomplex *, doublecomplex *, integer *, doublecomplex *,
integer *, integer *);
char order[1];
integer indwk, lhtrd;
extern /* Subroutine */ int dcopy_(integer *, doublereal *, integer *,
doublereal *, integer *);
integer lwmin;
logical lower;
integer lwtrd;
logical wantz;
extern /* Subroutine */ int zswap_(integer *, doublecomplex *, integer *,
doublecomplex *, integer *);
integer ib, kd, jj;
extern doublereal dlamch_(char *);
logical alleig, indeig;
integer iscale, ieeeok, indibl, indrdd, indifl, indree;
logical valeig;
doublereal safmin;
extern integer ilaenv_(integer *, char *, char *, integer *, integer *,
integer *, integer *, ftnlen, ftnlen);
extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), zdscal_(
integer *, doublereal *, doublecomplex *, integer *);
doublereal abstll, bignum;
integer indtau, indisp;
extern /* Subroutine */ int dsterf_(integer *, doublereal *, doublereal *,
integer *);
integer indiwo, indwkn;
extern /* Subroutine */ int dstebz_(char *, char *, integer *, doublereal
*, doublereal *, integer *, integer *, doublereal *, doublereal *,
doublereal *, integer *, integer *, doublereal *, integer *,
integer *, doublereal *, integer *, integer *);
integer indrwk, liwmin;
logical tryrac;
integer lrwmin, llwrkn, llwork, nsplit;
doublereal smlnum;
extern /* Subroutine */ int zstein_(integer *, doublereal *, doublereal *,
integer *, doublereal *, integer *, integer *, doublecomplex *,
integer *, doublereal *, integer *, integer *, integer *);
logical lquery;
extern doublereal zlansy_(char *, char *, integer *, doublecomplex *,
integer *, doublereal *);
extern /* Subroutine */ int zstemr_(char *, char *, integer *, doublereal
*, doublereal *, doublereal *, doublereal *, integer *, integer *,
integer *, doublereal *, doublecomplex *, integer *, integer *,
integer *, logical *, doublereal *, integer *, integer *, integer
*, integer *), zunmtr_(char *, char *, char *,
integer *, integer *, doublecomplex *, integer *, doublecomplex *,
doublecomplex *, integer *, doublecomplex *, integer *, integer *
);
doublereal eps, vll, vuu;
integer indhous, llrwork;
doublereal tmp1;
/* -- LAPACK driver routine (version 3.8.0) -- */
/* -- LAPACK is a software package provided by Univ. of Tennessee, -- */
/* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
/* June 2016 */
/* ===================================================================== */
/* Test the input parameters. */
/* Parameter adjustments */
a_dim1 = *lda;
a_offset = 1 + a_dim1 * 1;
a -= a_offset;
--w;
z_dim1 = *ldz;
z_offset = 1 + z_dim1 * 1;
z__ -= z_offset;
--isuppz;
--work;
--rwork;
--iwork;
/* Function Body */
ieeeok = ilaenv_(&c__10, "ZHEEVR", "N", &c__1, &c__2, &c__3, &c__4, (
ftnlen)6, (ftnlen)1);
lower = lsame_(uplo, "L");
wantz = lsame_(jobz, "V");
alleig = lsame_(range, "A");
valeig = lsame_(range, "V");
indeig = lsame_(range, "I");
lquery = *lwork == -1 || *lrwork == -1 || *liwork == -1;
kd = ilaenv2stage_(&c__1, "ZHETRD_2STAGE", jobz, n, &c_n1, &c_n1, &c_n1);
ib = ilaenv2stage_(&c__2, "ZHETRD_2STAGE", jobz, n, &kd, &c_n1, &c_n1);
lhtrd = ilaenv2stage_(&c__3, "ZHETRD_2STAGE", jobz, n, &kd, &ib, &c_n1);
lwtrd = ilaenv2stage_(&c__4, "ZHETRD_2STAGE", jobz, n, &kd, &ib, &c_n1);
lwmin = *n + lhtrd + lwtrd;
/* Computing MAX */
i__1 = 1, i__2 = *n * 24;
lrwmin = f2cmax(i__1,i__2);
/* Computing MAX */
i__1 = 1, i__2 = *n * 10;
liwmin = f2cmax(i__1,i__2);
*info = 0;
if (! lsame_(jobz, "N")) {
*info = -1;
} else if (! (alleig || valeig || indeig)) {
*info = -2;
} else if (! (lower || lsame_(uplo, "U"))) {
*info = -3;
} else if (*n < 0) {
*info = -4;
} else if (*lda < f2cmax(1,*n)) {
*info = -6;
} else {
if (valeig) {
if (*n > 0 && *vu <= *vl) {
*info = -8;
}
} else if (indeig) {
if (*il < 1 || *il > f2cmax(1,*n)) {
*info = -9;
} else if (*iu < f2cmin(*n,*il) || *iu > *n) {
*info = -10;
}
}
}
if (*info == 0) {
if (*ldz < 1 || wantz && *ldz < *n) {
*info = -15;
}
}
if (*info == 0) {
work[1].r = (doublereal) lwmin, work[1].i = 0.;
rwork[1] = (doublereal) lrwmin;
iwork[1] = liwmin;
if (*lwork < lwmin && ! lquery) {
*info = -18;
} else if (*lrwork < lrwmin && ! lquery) {
*info = -20;
} else if (*liwork < liwmin && ! lquery) {
*info = -22;
}
}
if (*info != 0) {
i__1 = -(*info);
xerbla_("ZHEEVR_2STAGE", &i__1, (ftnlen)13);
return 0;
} else if (lquery) {
return 0;
}
/* Quick return if possible */
*m = 0;
if (*n == 0) {
work[1].r = 1., work[1].i = 0.;
return 0;
}
if (*n == 1) {
work[1].r = 2., work[1].i = 0.;
if (alleig || indeig) {
*m = 1;
i__1 = a_dim1 + 1;
w[1] = a[i__1].r;
} else {
i__1 = a_dim1 + 1;
i__2 = a_dim1 + 1;
if (*vl < a[i__1].r && *vu >= a[i__2].r) {
*m = 1;
i__1 = a_dim1 + 1;
w[1] = a[i__1].r;
}
}
if (wantz) {
i__1 = z_dim1 + 1;
z__[i__1].r = 1., z__[i__1].i = 0.;
isuppz[1] = 1;
isuppz[2] = 1;
}
return 0;
}
/* Get machine constants. */
safmin = dlamch_("Safe minimum");
eps = dlamch_("Precision");
smlnum = safmin / eps;
bignum = 1. / smlnum;
rmin = sqrt(smlnum);
/* Computing MIN */
d__1 = sqrt(bignum), d__2 = 1. / sqrt(sqrt(safmin));
rmax = f2cmin(d__1,d__2);
/* Scale matrix to allowable range, if necessary. */
iscale = 0;
abstll = *abstol;
if (valeig) {
vll = *vl;
vuu = *vu;
}
anrm = zlansy_("M", uplo, n, &a[a_offset], lda, &rwork[1]);
if (anrm > 0. && anrm < rmin) {
iscale = 1;
sigma = rmin / anrm;
} else if (anrm > rmax) {
iscale = 1;
sigma = rmax / anrm;
}
if (iscale == 1) {
if (lower) {
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
i__2 = *n - j + 1;
zdscal_(&i__2, &sigma, &a[j + j * a_dim1], &c__1);
/* L10: */
}
} else {
i__1 = *n;
for (j = 1; j <= i__1; ++j) {
zdscal_(&j, &sigma, &a[j * a_dim1 + 1], &c__1);
/* L20: */
}
}
if (*abstol > 0.) {
abstll = *abstol * sigma;
}
if (valeig) {
vll = *vl * sigma;
vuu = *vu * sigma;
}
}
/* Initialize indices into workspaces. Note: The IWORK indices are */
/* used only if DSTERF or ZSTEMR fail. */
/* WORK(INDTAU:INDTAU+N-1) stores the complex scalar factors of the */
/* elementary reflectors used in ZHETRD. */
indtau = 1;
/* INDWK is the starting offset of the remaining complex workspace, */
/* and LLWORK is the remaining complex workspace size. */
indhous = indtau + *n;
indwk = indhous + lhtrd;
llwork = *lwork - indwk + 1;
/* RWORK(INDRD:INDRD+N-1) stores the real tridiagonal's diagonal */
/* entries. */
indrd = 1;
/* RWORK(INDRE:INDRE+N-1) stores the off-diagonal entries of the */
/* tridiagonal matrix from ZHETRD. */
indre = indrd + *n;
/* RWORK(INDRDD:INDRDD+N-1) is a copy of the diagonal entries over */
/* -written by ZSTEMR (the DSTERF path copies the diagonal to W). */
indrdd = indre + *n;
/* RWORK(INDREE:INDREE+N-1) is a copy of the off-diagonal entries over */
/* -written while computing the eigenvalues in DSTERF and ZSTEMR. */
indree = indrdd + *n;
/* INDRWK is the starting offset of the left-over real workspace, and */
/* LLRWORK is the remaining workspace size. */
indrwk = indree + *n;
llrwork = *lrwork - indrwk + 1;
/* IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in DSTEBZ and */
/* stores the block indices of each of the M<=N eigenvalues. */
indibl = 1;
/* IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in DSTEBZ and */
/* stores the starting and finishing indices of each block. */
indisp = indibl + *n;
/* IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors */
/* that corresponding to eigenvectors that fail to converge in */
/* ZSTEIN. This information is discarded; if any fail, the driver */
/* returns INFO > 0. */
indifl = indisp + *n;
/* INDIWO is the offset of the remaining integer workspace. */
indiwo = indifl + *n;
/* Call ZHETRD_2STAGE to reduce Hermitian matrix to tridiagonal form. */
zhetrd_2stage_(jobz, uplo, n, &a[a_offset], lda, &rwork[indrd], &rwork[
indre], &work[indtau], &work[indhous], &lhtrd, &work[indwk], &
llwork, &iinfo);
/* If all eigenvalues are desired */
/* then call DSTERF or ZSTEMR and ZUNMTR. */
test = FALSE_;
if (indeig) {
if (*il == 1 && *iu == *n) {
test = TRUE_;
}
}
if ((alleig || test) && ieeeok == 1) {
if (! wantz) {
dcopy_(n, &rwork[indrd], &c__1, &w[1], &c__1);
i__1 = *n - 1;
dcopy_(&i__1, &rwork[indre], &c__1, &rwork[indree], &c__1);
dsterf_(n, &w[1], &rwork[indree], info);
} else {
i__1 = *n - 1;
dcopy_(&i__1, &rwork[indre], &c__1, &rwork[indree], &c__1);
dcopy_(n, &rwork[indrd], &c__1, &rwork[indrdd], &c__1);
if (*abstol <= *n * 2. * eps) {
tryrac = TRUE_;
} else {
tryrac = FALSE_;
}
zstemr_(jobz, "A", n, &rwork[indrdd], &rwork[indree], vl, vu, il,
iu, m, &w[1], &z__[z_offset], ldz, n, &isuppz[1], &tryrac,
&rwork[indrwk], &llrwork, &iwork[1], liwork, info);
/* Apply unitary matrix used in reduction to tridiagonal */
/* form to eigenvectors returned by ZSTEMR. */
if (wantz && *info == 0) {
indwkn = indwk;
llwrkn = *lwork - indwkn + 1;
zunmtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau]
, &z__[z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
}
}
if (*info == 0) {
*m = *n;
goto L30;
}
*info = 0;
}
/* Otherwise, call DSTEBZ and, if eigenvectors are desired, ZSTEIN. */
/* Also call DSTEBZ and ZSTEIN if ZSTEMR fails. */
if (wantz) {
*(unsigned char *)order = 'B';
} else {
*(unsigned char *)order = 'E';
}
dstebz_(range, order, n, &vll, &vuu, il, iu, &abstll, &rwork[indrd], &
rwork[indre], m, &nsplit, &w[1], &iwork[indibl], &iwork[indisp], &
rwork[indrwk], &iwork[indiwo], info);
if (wantz) {
zstein_(n, &rwork[indrd], &rwork[indre], m, &w[1], &iwork[indibl], &
iwork[indisp], &z__[z_offset], ldz, &rwork[indrwk], &iwork[
indiwo], &iwork[indifl], info);
/* Apply unitary matrix used in reduction to tridiagonal */
/* form to eigenvectors returned by ZSTEIN. */
indwkn = indwk;
llwrkn = *lwork - indwkn + 1;
zunmtr_("L", uplo, "N", n, m, &a[a_offset], lda, &work[indtau], &z__[
z_offset], ldz, &work[indwkn], &llwrkn, &iinfo);
}
/* If matrix was scaled, then rescale eigenvalues appropriately. */
L30:
if (iscale == 1) {
if (*info == 0) {
imax = *m;
} else {
imax = *info - 1;
}
d__1 = 1. / sigma;
dscal_(&imax, &d__1, &w[1], &c__1);
}
/* If eigenvalues are not in order, then sort them, along with */
/* eigenvectors. */
if (wantz) {
i__1 = *m - 1;
for (j = 1; j <= i__1; ++j) {
i__ = 0;
tmp1 = w[j];
i__2 = *m;
for (jj = j + 1; jj <= i__2; ++jj) {
if (w[jj] < tmp1) {
i__ = jj;
tmp1 = w[jj];
}
/* L40: */
}
if (i__ != 0) {
itmp1 = iwork[indibl + i__ - 1];
w[i__] = w[j];
iwork[indibl + i__ - 1] = iwork[indibl + j - 1];
w[j] = tmp1;
iwork[indibl + j - 1] = itmp1;
zswap_(n, &z__[i__ * z_dim1 + 1], &c__1, &z__[j * z_dim1 + 1],
&c__1);
}
/* L50: */
}
}
/* Set WORK(1) to optimal workspace size. */
work[1].r = (doublereal) lwmin, work[1].i = 0.;
rwork[1] = (doublereal) lrwmin;
iwork[1] = liwmin;
return 0;
/* End of ZHEEVR_2STAGE */
} /* zheevr_2stage__ */
|
the_stack_data/34513589.c | /* { dg-do compile } */
/* { dg-options "-fno-common" } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?a" } } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?b" } } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?c" } } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?d" } } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?e" } } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?g" } } */
/* { dg-final { scan-assembler-not "weak\[^ \t\]*\[ \t\]_?i" } } */
/* { dg-final { scan-assembler "weak\[^ \t\]*\[ \t\]_?j" } } */
#pragma weak a
int a;
int b;
#pragma weak b
#pragma weak c
extern int c;
int c;
extern int d;
#pragma weak d
int d;
#pragma weak e
void e(void) { }
#if 0
/* This permutation is illegal. */
void f(void) { }
#pragma weak f
#endif
#pragma weak g
int g = 1;
#if 0
/* This permutation is illegal. */
int h = 1;
#pragma weak h
#endif
#pragma weak i
extern int i;
#pragma weak j
extern int j;
int use_j() { return j; }
|
the_stack_data/192330563.c | /* original parser id follows */
/* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */
/* (use YYMAJOR/YYMINOR for ifdefs dependent of parser version) */
#define YYBYACC 1
#define YYMAJOR 1
#define YYMINOR 9
#define YYCHECK "yyyymmdd"
#define YYEMPTY (-1)
#define yyclearin (yychar = YYEMPTY)
#define yyerrok (yyerrflag = 0)
#define YYRECOVERING() (yyerrflag != 0)
#define YYENOMEM (-2)
#define YYEOF 0
#undef YYBTYACC
#define YYBTYACC 1
#define YYDEBUGSTR (yytrial ? YYPREFIX "debug(trial)" : YYPREFIX "debug")
#ifndef yyparse
#define yyparse destroy1_parse
#endif /* yyparse */
#ifndef yylex
#define yylex destroy1_lex
#endif /* yylex */
#ifndef yyerror
#define yyerror destroy1_error
#endif /* yyerror */
#ifndef yychar
#define yychar destroy1_char
#endif /* yychar */
#ifndef yyval
#define yyval destroy1_val
#endif /* yyval */
#ifndef yylval
#define yylval destroy1_lval
#endif /* yylval */
#ifndef yydebug
#define yydebug destroy1_debug
#endif /* yydebug */
#ifndef yynerrs
#define yynerrs destroy1_nerrs
#endif /* yynerrs */
#ifndef yyerrflag
#define yyerrflag destroy1_errflag
#endif /* yyerrflag */
#ifndef yylhs
#define yylhs destroy1_lhs
#endif /* yylhs */
#ifndef yylen
#define yylen destroy1_len
#endif /* yylen */
#ifndef yydefred
#define yydefred destroy1_defred
#endif /* yydefred */
#ifndef yystos
#define yystos destroy1_stos
#endif /* yystos */
#ifndef yydgoto
#define yydgoto destroy1_dgoto
#endif /* yydgoto */
#ifndef yysindex
#define yysindex destroy1_sindex
#endif /* yysindex */
#ifndef yyrindex
#define yyrindex destroy1_rindex
#endif /* yyrindex */
#ifndef yygindex
#define yygindex destroy1_gindex
#endif /* yygindex */
#ifndef yytable
#define yytable destroy1_table
#endif /* yytable */
#ifndef yycheck
#define yycheck destroy1_check
#endif /* yycheck */
#ifndef yyname
#define yyname destroy1_name
#endif /* yyname */
#ifndef yyrule
#define yyrule destroy1_rule
#endif /* yyrule */
#if YYBTYACC
#ifndef yycindex
#define yycindex destroy1_cindex
#endif /* yycindex */
#ifndef yyctable
#define yyctable destroy1_ctable
#endif /* yyctable */
#endif /* YYBTYACC */
#define YYPREFIX "destroy1_"
#define YYPURE 0
#line 4 "btyacc_destroy1.y"
#include <stdlib.h>
typedef enum {cGLOBAL, cLOCAL} class;
typedef enum {tREAL, tINTEGER} type;
typedef char * name;
struct symbol { class c; type t; name id; };
typedef struct symbol symbol;
struct namelist { symbol *s; struct namelist *next; };
typedef struct namelist namelist;
struct parser_param {
int *rtrn;
symbol ss;
};
extern symbol *mksymbol(type t, class c, name id);
#ifdef YYBISON
#define YYLEX_DECL() yylex(void)
#define YYERROR_DECL() yyerror(const char *s)
#endif
#line 50 "btyacc_destroy1.y"
#ifdef YYSTYPE
#undef YYSTYPE_IS_DECLARED
#define YYSTYPE_IS_DECLARED 1
#endif
#ifndef YYSTYPE_IS_DECLARED
#define YYSTYPE_IS_DECLARED 1
typedef union
{
class cval;
type tval;
namelist * nlist;
name id;
} YYSTYPE;
#endif /* !YYSTYPE_IS_DECLARED */
#line 160 "btyacc_destroy1.tab.c"
/* compatibility with bison */
#ifdef YYPARSE_PARAM
/* compatibility with FreeBSD */
# ifdef YYPARSE_PARAM_TYPE
# define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM)
# else
# define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM)
# endif
#else
# define YYPARSE_DECL() yyparse(struct parser_param *param, int flag)
#endif
/* Parameters sent to lex. */
#ifdef YYLEX_PARAM
# define YYLEX_DECL() yylex(void *YYLEX_PARAM)
# define YYLEX yylex(YYLEX_PARAM)
#else
# define YYLEX_DECL() yylex(void)
# define YYLEX yylex()
#endif
/* Parameters sent to yyerror. */
#ifndef YYERROR_DECL
#define YYERROR_DECL() yyerror(struct parser_param *param, int flag, const char *s)
#endif
#ifndef YYERROR_CALL
#define YYERROR_CALL(msg) yyerror(param, flag, msg)
#endif
#ifndef YYDESTRUCT_DECL
#define YYDESTRUCT_DECL() yydestruct(const char *msg, int psymb, YYSTYPE *val, struct parser_param *param, int flag)
#endif
#ifndef YYDESTRUCT_CALL
#define YYDESTRUCT_CALL(msg, psymb, val) yydestruct(msg, psymb, val, param, flag)
#endif
extern int YYPARSE_DECL();
#define GLOBAL 257
#define LOCAL 258
#define REAL 259
#define INTEGER 260
#define NAME 261
#define YYERRCODE 256
typedef short YYINT;
static const YYINT destroy1_lhs[] = { -1,
0, 0, 2, 2, 3, 3, 4, 4, 1,
};
static const YYINT destroy1_len[] = { 2,
8, 5, 1, 1, 1, 1, 2, 1, 6,
};
static const YYINT destroy1_defred[] = { 0,
3, 4, 5, 6, 0, 0, 0, 0, 8, 0,
0, 0, 0, 7, 0, 0, 0, 0, 0, 2,
0, 0, 0, 0, 9, 1,
};
static const YYINT destroy1_stos[] = { 0,
257, 258, 259, 260, 263, 265, 266, 266, 261, 264,
267, 267, 40, 261, 40, 40, 265, 258, 265, 41,
44, 44, 266, 266, 41, 41,
};
static const YYINT destroy1_dgoto[] = { 5,
10, 6, 7, 11,
};
static const YYINT destroy1_sindex[] = { -254,
0, 0, 0, 0, 0, -251, -248, -248, 0, -26,
-40, -39, -246, 0, -243, -246, -25, -24, -23, 0,
-251, -251, -22, -19, 0, 0,
};
static const YYINT destroy1_rindex[] = { 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
};
#if YYBTYACC
static const YYINT destroy1_cindex[] = { 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
};
#endif
static const YYINT destroy1_gindex[] = { 0,
0, -6, -4, 15,
};
#define YYTABLESIZE 222
static const YYINT destroy1_table[] = { 15,
16, 8, 1, 2, 3, 4, 17, 3, 4, 19,
1, 2, 9, 13, 18, 20, 23, 24, 25, 21,
22, 26, 12, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
14, 14,
};
static const YYINT destroy1_check[] = { 40,
40, 6, 257, 258, 259, 260, 13, 259, 260, 16,
257, 258, 261, 40, 258, 41, 21, 22, 41, 44,
44, 41, 8, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
261, 261,
};
#if YYBTYACC
static const YYINT destroy1_ctable[] = { -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1,
};
#endif
#define YYFINAL 5
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 261
#define YYUNDFTOKEN 268
#define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a))
#if YYDEBUG
static const char *const destroy1_name[] = {
"$end",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,"'('","')'",0,0,"','",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"error","GLOBAL","LOCAL",
"REAL","INTEGER","NAME","$accept","declaration","locnamelist","class","type",
"namelist","illegal-symbol",
};
static const char *const destroy1_rule[] = {
"$accept : declaration",
"declaration : class type namelist '(' class ',' type ')'",
"declaration : type locnamelist '(' class ')'",
"class : GLOBAL",
"class : LOCAL",
"type : REAL",
"type : INTEGER",
"namelist : namelist NAME",
"namelist : NAME",
"locnamelist : namelist '(' LOCAL ',' type ')'",
};
#endif
int yydebug;
int yynerrs;
int yyerrflag;
int yychar;
YYSTYPE yyval;
YYSTYPE yylval;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
YYLTYPE yyloc; /* position returned by actions */
YYLTYPE yylloc; /* position from the lexer */
#endif
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
#ifndef YYLLOC_DEFAULT
#define YYLLOC_DEFAULT(loc, rhs, n) \
do \
{ \
if (n == 0) \
{ \
(loc).first_line = ((rhs)[-1]).last_line; \
(loc).first_column = ((rhs)[-1]).last_column; \
(loc).last_line = ((rhs)[-1]).last_line; \
(loc).last_column = ((rhs)[-1]).last_column; \
} \
else \
{ \
(loc).first_line = ((rhs)[ 0 ]).first_line; \
(loc).first_column = ((rhs)[ 0 ]).first_column; \
(loc).last_line = ((rhs)[n-1]).last_line; \
(loc).last_column = ((rhs)[n-1]).last_column; \
} \
} while (0)
#endif /* YYLLOC_DEFAULT */
#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
#if YYBTYACC
#ifndef YYLVQUEUEGROWTH
#define YYLVQUEUEGROWTH 32
#endif
#endif /* YYBTYACC */
/* define the initial stack-sizes */
#ifdef YYSTACKSIZE
#undef YYMAXDEPTH
#define YYMAXDEPTH YYSTACKSIZE
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 10000
#define YYMAXDEPTH 10000
#endif
#endif
#ifndef YYINITSTACKSIZE
#define YYINITSTACKSIZE 200
#endif
typedef struct {
unsigned stacksize;
short *s_base;
short *s_mark;
short *s_last;
YYSTYPE *l_base;
YYSTYPE *l_mark;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
YYLTYPE *p_base;
YYLTYPE *p_mark;
#endif
} YYSTACKDATA;
#if YYBTYACC
struct YYParseState_s
{
struct YYParseState_s *save; /* Previously saved parser state */
YYSTACKDATA yystack; /* saved parser stack */
int state; /* saved parser state */
int errflag; /* saved error recovery status */
int lexeme; /* saved index of the conflict lexeme in the lexical queue */
YYINT ctry; /* saved index in yyctable[] for this conflict */
};
typedef struct YYParseState_s YYParseState;
#endif /* YYBTYACC */
/* variables for the parser stack */
static YYSTACKDATA yystack;
#if YYBTYACC
/* Current parser state */
static YYParseState *yyps = 0;
/* yypath != NULL: do the full parse, starting at *yypath parser state. */
static YYParseState *yypath = 0;
/* Base of the lexical value queue */
static YYSTYPE *yylvals = 0;
/* Current position at lexical value queue */
static YYSTYPE *yylvp = 0;
/* End position of lexical value queue */
static YYSTYPE *yylve = 0;
/* The last allocated position at the lexical value queue */
static YYSTYPE *yylvlim = 0;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
/* Base of the lexical position queue */
static YYLTYPE *yylpsns = 0;
/* Current position at lexical position queue */
static YYLTYPE *yylpp = 0;
/* End position of lexical position queue */
static YYLTYPE *yylpe = 0;
/* The last allocated position at the lexical position queue */
static YYLTYPE *yylplim = 0;
#endif
/* Current position at lexical token queue */
static short *yylexp = 0;
static short *yylexemes = 0;
#endif /* YYBTYACC */
#line 89 "btyacc_destroy1.y"
extern int YYLEX_DECL();
extern void YYERROR_DECL();
#line 487 "btyacc_destroy1.tab.c"
/* Release memory associated with symbol. */
#if ! defined YYDESTRUCT_IS_DECLARED
static void
YYDESTRUCT_DECL()
{
switch (psymb)
{
case 263:
#line 41 "btyacc_destroy1.y"
{
namelist *p = (*val).nlist;
while (p != NULL)
{ namelist *pp = p;
p = p->next;
free(pp->s); free(pp);
}
}
break;
#line 507 "btyacc_destroy1.tab.c"
}
}
#define YYDESTRUCT_IS_DECLARED 1
#endif
/* For use in generated program */
#define yydepth (int)(yystack.s_mark - yystack.s_base)
#if YYBTYACC
#define yytrial (yyps->save)
#endif /* YYBTYACC */
#if YYDEBUG
#include <stdio.h> /* needed for printf */
#endif
#include <stdlib.h> /* needed for malloc, etc */
#include <string.h> /* needed for memset */
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
static int yygrowstack(YYSTACKDATA *data)
{
int i;
unsigned newsize;
short *newss;
YYSTYPE *newvs;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
YYLTYPE *newps;
#endif
if ((newsize = data->stacksize) == 0)
newsize = YYINITSTACKSIZE;
else if (newsize >= YYMAXDEPTH)
return YYENOMEM;
else if ((newsize *= 2) > YYMAXDEPTH)
newsize = YYMAXDEPTH;
i = (int) (data->s_mark - data->s_base);
newss = (short *)realloc(data->s_base, newsize * sizeof(*newss));
if (newss == 0)
return YYENOMEM;
data->s_base = newss;
data->s_mark = newss + i;
newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs));
if (newvs == 0)
return YYENOMEM;
data->l_base = newvs;
data->l_mark = newvs + i;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
newps = (YYLTYPE *)realloc(data->p_base, newsize * sizeof(*newps));
if (newps == 0)
return YYENOMEM;
data->p_base = newps;
data->p_mark = newps + i;
#endif
data->stacksize = newsize;
data->s_last = data->s_base + newsize - 1;
#if YYDEBUG
if (yydebug)
fprintf(stderr, "%sdebug: stack size increased to %d\n", YYPREFIX, newsize);
#endif
return 0;
}
#if YYPURE || defined(YY_NO_LEAKS)
static void yyfreestack(YYSTACKDATA *data)
{
free(data->s_base);
free(data->l_base);
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
free(data->p_base);
#endif
memset(data, 0, sizeof(*data));
}
#else
#define yyfreestack(data) /* nothing */
#endif /* YYPURE || defined(YY_NO_LEAKS) */
#if YYBTYACC
static YYParseState *
yyNewState(unsigned size)
{
YYParseState *p = (YYParseState *) malloc(sizeof(YYParseState));
if (p == NULL) return NULL;
p->yystack.stacksize = size;
if (size == 0)
{
p->yystack.s_base = NULL;
p->yystack.l_base = NULL;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
p->yystack.p_base = NULL;
#endif
return p;
}
p->yystack.s_base = (short *) malloc(size * sizeof(short));
if (p->yystack.s_base == NULL) return NULL;
p->yystack.l_base = (YYSTYPE *) malloc(size * sizeof(YYSTYPE));
if (p->yystack.l_base == NULL) return NULL;
memset(p->yystack.l_base, 0, size * sizeof(YYSTYPE));
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
p->yystack.p_base = (YYLTYPE *) malloc(size * sizeof(YYLTYPE));
if (p->yystack.p_base == NULL) return NULL;
memset(p->yystack.p_base, 0, size * sizeof(YYLTYPE));
#endif
return p;
}
static void
yyFreeState(YYParseState *p)
{
yyfreestack(&p->yystack);
free(p);
}
#endif /* YYBTYACC */
#define YYABORT goto yyabort
#define YYREJECT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
#if YYBTYACC
#define YYVALID do { if (yyps->save) goto yyvalid; } while(0)
#define YYVALID_NESTED do { if (yyps->save && \
yyps->save->save == 0) goto yyvalid; } while(0)
#endif /* YYBTYACC */
int
YYPARSE_DECL()
{
int yym, yyn, yystate, yyresult;
#if YYBTYACC
int yynewerrflag;
YYParseState *yyerrctx = NULL;
#endif /* YYBTYACC */
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
YYLTYPE yyerror_loc_range[2]; /* position of error start & end */
#endif
#if YYDEBUG
const char *yys;
if ((yys = getenv("YYDEBUG")) != 0)
{
yyn = *yys;
if (yyn >= '0' && yyn <= '9')
yydebug = yyn - '0';
}
if (yydebug)
fprintf(stderr, "%sdebug[<# of symbols on state stack>]\n", YYPREFIX);
#endif
#if YYBTYACC
yyps = yyNewState(0); if (yyps == 0) goto yyenomem;
yyps->save = 0;
#endif /* YYBTYACC */
yynerrs = 0;
yyerrflag = 0;
yychar = YYEMPTY;
yystate = 0;
#if YYPURE
memset(&yystack, 0, sizeof(yystack));
#endif
if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
yystack.s_mark = yystack.s_base;
yystack.l_mark = yystack.l_base;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yystack.p_mark = yystack.p_base;
#endif
yystate = 0;
*yystack.s_mark = 0;
yyloop:
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
if (yychar < 0)
{
#if YYBTYACC
do {
if (yylvp < yylve)
{
/* we're currently re-reading tokens */
yylval = *yylvp++;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yylloc = *yylpp++;
#endif
yychar = *yylexp++;
break;
}
if (yyps->save)
{
/* in trial mode; save scanner results for future parse attempts */
if (yylvp == yylvlim)
{ /* Enlarge lexical value queue */
size_t p = (size_t) (yylvp - yylvals);
size_t s = (size_t) (yylvlim - yylvals);
s += YYLVQUEUEGROWTH;
if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL) goto yyenomem;
if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL) goto yyenomem;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL) goto yyenomem;
#endif
yylvp = yylve = yylvals + p;
yylvlim = yylvals + s;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yylpp = yylpe = yylpsns + p;
yylplim = yylpsns + s;
#endif
yylexp = yylexemes + p;
}
*yylexp = (short) YYLEX;
*yylvp++ = yylval;
yylve++;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
*yylpp++ = yylloc;
yylpe++;
#endif
yychar = *yylexp++;
break;
}
/* normal operation, no conflict encountered */
#endif /* YYBTYACC */
yychar = YYLEX;
#if YYBTYACC
} while (0);
#endif /* YYBTYACC */
if (yychar < 0) yychar = YYEOF;
/* if ((yychar = YYLEX) < 0) yychar = YYEOF; */
#if YYDEBUG
if (yydebug)
{
yys = yyname[YYTRANSLATE(yychar)];
fprintf(stderr, "%s[%d]: state %d, reading token %d (%s)",
YYDEBUGSTR, yydepth, yystate, yychar, yys);
#ifdef YYSTYPE_TOSTRING
#if YYBTYACC
if (!yytrial)
#endif /* YYBTYACC */
fprintf(stderr, " <%s>", YYSTYPE_TOSTRING(yychar, yylval));
#endif
fputc('\n', stderr);
}
#endif
}
#if YYBTYACC
/* Do we have a conflict? */
if (((yyn = yycindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
{
YYINT ctry;
if (yypath)
{
YYParseState *save;
#if YYDEBUG
if (yydebug)
fprintf(stderr, "%s[%d]: CONFLICT in state %d: following successful trial parse\n",
YYDEBUGSTR, yydepth, yystate);
#endif
/* Switch to the next conflict context */
save = yypath;
yypath = save->save;
save->save = NULL;
ctry = save->ctry;
if (save->state != yystate) YYABORT;
yyFreeState(save);
}
else
{
/* Unresolved conflict - start/continue trial parse */
YYParseState *save;
#if YYDEBUG
if (yydebug)
{
fprintf(stderr, "%s[%d]: CONFLICT in state %d. ", YYDEBUGSTR, yydepth, yystate);
if (yyps->save)
fputs("ALREADY in conflict, continuing trial parse.\n", stderr);
else
fputs("Starting trial parse.\n", stderr);
}
#endif
save = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
if (save == NULL) goto yyenomem;
save->save = yyps->save;
save->state = yystate;
save->errflag = yyerrflag;
save->yystack.s_mark = save->yystack.s_base + (yystack.s_mark - yystack.s_base);
memcpy (save->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
save->yystack.l_mark = save->yystack.l_base + (yystack.l_mark - yystack.l_base);
memcpy (save->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
save->yystack.p_mark = save->yystack.p_base + (yystack.p_mark - yystack.p_base);
memcpy (save->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
#endif
ctry = yytable[yyn];
if (yyctable[ctry] == -1)
{
#if YYDEBUG
if (yydebug && yychar >= YYEOF)
fprintf(stderr, "%s[%d]: backtracking 1 token\n", YYDEBUGSTR, yydepth);
#endif
ctry++;
}
save->ctry = ctry;
if (yyps->save == NULL)
{
/* If this is a first conflict in the stack, start saving lexemes */
if (!yylexemes)
{
yylexemes = (short *) malloc((YYLVQUEUEGROWTH) * sizeof(short));
if (yylexemes == NULL) goto yyenomem;
yylvals = (YYSTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYSTYPE));
if (yylvals == NULL) goto yyenomem;
yylvlim = yylvals + YYLVQUEUEGROWTH;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yylpsns = (YYLTYPE *) malloc((YYLVQUEUEGROWTH) * sizeof(YYLTYPE));
if (yylpsns == NULL) goto yyenomem;
yylplim = yylpsns + YYLVQUEUEGROWTH;
#endif
}
if (yylvp == yylve)
{
yylvp = yylve = yylvals;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yylpp = yylpe = yylpsns;
#endif
yylexp = yylexemes;
if (yychar >= YYEOF)
{
*yylve++ = yylval;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
*yylpe++ = yylloc;
#endif
*yylexp = (short) yychar;
yychar = YYEMPTY;
}
}
}
if (yychar >= YYEOF)
{
yylvp--;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yylpp--;
#endif
yylexp--;
yychar = YYEMPTY;
}
save->lexeme = (int) (yylvp - yylvals);
yyps->save = save;
}
if (yytable[yyn] == ctry)
{
#if YYDEBUG
if (yydebug)
fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
YYDEBUGSTR, yydepth, yystate, yyctable[ctry]);
#endif
if (yychar < 0)
{
yylvp++;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yylpp++;
#endif
yylexp++;
}
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM)
goto yyoverflow;
yystate = yyctable[ctry];
*++yystack.s_mark = (short) yystate;
*++yystack.l_mark = yylval;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
*++yystack.p_mark = yylloc;
#endif
yychar = YYEMPTY;
if (yyerrflag > 0) --yyerrflag;
goto yyloop;
}
else
{
yyn = yyctable[ctry];
goto yyreduce;
}
} /* End of code dealing with conflicts */
#endif /* YYBTYACC */
if (((yyn = yysindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
{
#if YYDEBUG
if (yydebug)
fprintf(stderr, "%s[%d]: state %d, shifting to state %d\n",
YYDEBUGSTR, yydepth, yystate, yytable[yyn]);
#endif
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
yystate = yytable[yyn];
*++yystack.s_mark = yytable[yyn];
*++yystack.l_mark = yylval;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
*++yystack.p_mark = yylloc;
#endif
yychar = YYEMPTY;
if (yyerrflag > 0) --yyerrflag;
goto yyloop;
}
if (((yyn = yyrindex[yystate]) != 0) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yychar)
{
yyn = yytable[yyn];
goto yyreduce;
}
if (yyerrflag != 0) goto yyinrecovery;
#if YYBTYACC
yynewerrflag = 1;
goto yyerrhandler;
goto yyerrlab;
yyerrlab:
yynewerrflag = 0;
yyerrhandler:
while (yyps->save)
{
int ctry;
YYParseState *save = yyps->save;
#if YYDEBUG
if (yydebug)
fprintf(stderr, "%s[%d]: ERROR in state %d, CONFLICT BACKTRACKING to state %d, %d tokens\n",
YYDEBUGSTR, yydepth, yystate, yyps->save->state,
(int)(yylvp - yylvals - yyps->save->lexeme));
#endif
/* Memorize most forward-looking error state in case it's really an error. */
if (yyerrctx == NULL || yyerrctx->lexeme < yylvp - yylvals)
{
/* Free old saved error context state */
if (yyerrctx) yyFreeState(yyerrctx);
/* Create and fill out new saved error context state */
yyerrctx = yyNewState((unsigned)(yystack.s_mark - yystack.s_base + 1));
if (yyerrctx == NULL) goto yyenomem;
yyerrctx->save = yyps->save;
yyerrctx->state = yystate;
yyerrctx->errflag = yyerrflag;
yyerrctx->yystack.s_mark = yyerrctx->yystack.s_base + (yystack.s_mark - yystack.s_base);
memcpy (yyerrctx->yystack.s_base, yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
yyerrctx->yystack.l_mark = yyerrctx->yystack.l_base + (yystack.l_mark - yystack.l_base);
memcpy (yyerrctx->yystack.l_base, yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yyerrctx->yystack.p_mark = yyerrctx->yystack.p_base + (yystack.p_mark - yystack.p_base);
memcpy (yyerrctx->yystack.p_base, yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
#endif
yyerrctx->lexeme = (int) (yylvp - yylvals);
}
yylvp = yylvals + save->lexeme;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yylpp = yylpsns + save->lexeme;
#endif
yylexp = yylexemes + save->lexeme;
yychar = YYEMPTY;
yystack.s_mark = yystack.s_base + (save->yystack.s_mark - save->yystack.s_base);
memcpy (yystack.s_base, save->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
yystack.l_mark = yystack.l_base + (save->yystack.l_mark - save->yystack.l_base);
memcpy (yystack.l_base, save->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yystack.p_mark = yystack.p_base + (save->yystack.p_mark - save->yystack.p_base);
memcpy (yystack.p_base, save->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
#endif
ctry = ++save->ctry;
yystate = save->state;
/* We tried shift, try reduce now */
if ((yyn = yyctable[ctry]) >= 0) goto yyreduce;
yyps->save = save->save;
save->save = NULL;
yyFreeState(save);
/* Nothing left on the stack -- error */
if (!yyps->save)
{
#if YYDEBUG
if (yydebug)
fprintf(stderr, "%sdebug[%d,trial]: trial parse FAILED, entering ERROR mode\n",
YYPREFIX, yydepth);
#endif
/* Restore state as it was in the most forward-advanced error */
yylvp = yylvals + yyerrctx->lexeme;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yylpp = yylpsns + yyerrctx->lexeme;
#endif
yylexp = yylexemes + yyerrctx->lexeme;
yychar = yylexp[-1];
yylval = yylvp[-1];
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yylloc = yylpp[-1];
#endif
yystack.s_mark = yystack.s_base + (yyerrctx->yystack.s_mark - yyerrctx->yystack.s_base);
memcpy (yystack.s_base, yyerrctx->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
yystack.l_mark = yystack.l_base + (yyerrctx->yystack.l_mark - yyerrctx->yystack.l_base);
memcpy (yystack.l_base, yyerrctx->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yystack.p_mark = yystack.p_base + (yyerrctx->yystack.p_mark - yyerrctx->yystack.p_base);
memcpy (yystack.p_base, yyerrctx->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
#endif
yystate = yyerrctx->state;
yyFreeState(yyerrctx);
yyerrctx = NULL;
}
yynewerrflag = 1;
}
if (yynewerrflag == 0) goto yyinrecovery;
#endif /* YYBTYACC */
YYERROR_CALL("syntax error");
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yyerror_loc_range[0] = yylloc; /* lookahead position is error start position */
#endif
#if !YYBTYACC
goto yyerrlab;
yyerrlab:
#endif
++yynerrs;
yyinrecovery:
if (yyerrflag < 3)
{
yyerrflag = 3;
for (;;)
{
if (((yyn = yysindex[*yystack.s_mark]) != 0) && (yyn += YYERRCODE) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) YYERRCODE)
{
#if YYDEBUG
if (yydebug)
fprintf(stderr, "%s[%d]: state %d, error recovery shifting to state %d\n",
YYDEBUGSTR, yydepth, *yystack.s_mark, yytable[yyn]);
#endif
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
yystate = yytable[yyn];
*++yystack.s_mark = yytable[yyn];
*++yystack.l_mark = yylval;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
/* lookahead position is error end position */
yyerror_loc_range[1] = yylloc;
YYLLOC_DEFAULT(yyloc, yyerror_loc_range, 2); /* position of error span */
*++yystack.p_mark = yyloc;
#endif
goto yyloop;
}
else
{
#if YYDEBUG
if (yydebug)
fprintf(stderr, "%s[%d]: error recovery discarding state %d\n",
YYDEBUGSTR, yydepth, *yystack.s_mark);
#endif
if (yystack.s_mark <= yystack.s_base) goto yyabort;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
/* the current TOS position is the error start position */
yyerror_loc_range[0] = *yystack.p_mark;
#endif
#if defined(YYDESTRUCT_CALL)
#if YYBTYACC
if (!yytrial)
#endif /* YYBTYACC */
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
YYDESTRUCT_CALL("error: discarding state",
yystos[*yystack.s_mark], yystack.l_mark, yystack.p_mark);
#else
YYDESTRUCT_CALL("error: discarding state",
yystos[*yystack.s_mark], yystack.l_mark);
#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
#endif /* defined(YYDESTRUCT_CALL) */
--yystack.s_mark;
--yystack.l_mark;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
--yystack.p_mark;
#endif
}
}
}
else
{
if (yychar == YYEOF) goto yyabort;
#if YYDEBUG
if (yydebug)
{
yys = yyname[YYTRANSLATE(yychar)];
fprintf(stderr, "%s[%d]: state %d, error recovery discarding token %d (%s)\n",
YYDEBUGSTR, yydepth, yystate, yychar, yys);
}
#endif
#if defined(YYDESTRUCT_CALL)
#if YYBTYACC
if (!yytrial)
#endif /* YYBTYACC */
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
YYDESTRUCT_CALL("error: discarding token", yychar, &yylval, &yylloc);
#else
YYDESTRUCT_CALL("error: discarding token", yychar, &yylval);
#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
#endif /* defined(YYDESTRUCT_CALL) */
yychar = YYEMPTY;
goto yyloop;
}
yyreduce:
yym = yylen[yyn];
#if YYDEBUG
if (yydebug)
{
fprintf(stderr, "%s[%d]: state %d, reducing by rule %d (%s)",
YYDEBUGSTR, yydepth, yystate, yyn, yyrule[yyn]);
#ifdef YYSTYPE_TOSTRING
#if YYBTYACC
if (!yytrial)
#endif /* YYBTYACC */
if (yym > 0)
{
int i;
fputc('<', stderr);
for (i = yym; i > 0; i--)
{
if (i != yym) fputs(", ", stderr);
fputs(YYSTYPE_TOSTRING(yystos[yystack.s_mark[1-i]],
yystack.l_mark[1-i]), stderr);
}
fputc('>', stderr);
}
#endif
fputc('\n', stderr);
}
#endif
if (yym > 0)
yyval = yystack.l_mark[1-yym];
else
memset(&yyval, 0, sizeof yyval);
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
/* Perform position reduction */
memset(&yyloc, 0, sizeof(yyloc));
#if YYBTYACC
if (!yytrial)
#endif /* YYBTYACC */
{
YYLLOC_DEFAULT(yyloc, &yystack.p_mark[1-yym], yym);
/* just in case YYERROR is invoked within the action, save
the start of the rhs as the error start position */
yyerror_loc_range[0] = yystack.p_mark[1-yym];
}
#endif
switch (yyn)
{
case 1:
if (!yytrial)
#line 62 "btyacc_destroy1.y"
{ yyval.nlist = yystack.l_mark[-5].nlist; }
break;
case 2:
if (!yytrial)
#line 64 "btyacc_destroy1.y"
{ yyval.nlist = yystack.l_mark[-3].nlist; }
break;
case 3:
if (!yytrial)
#line 67 "btyacc_destroy1.y"
{ yyval.cval = cGLOBAL; }
break;
case 4:
if (!yytrial)
#line 68 "btyacc_destroy1.y"
{ yyval.cval = cLOCAL; }
break;
case 5:
if (!yytrial)
#line 71 "btyacc_destroy1.y"
{ yyval.tval = tREAL; }
break;
case 6:
if (!yytrial)
#line 72 "btyacc_destroy1.y"
{ yyval.tval = tINTEGER; }
break;
case 7:
if (!yytrial)
#line 76 "btyacc_destroy1.y"
{ yyval.nlist->s = mksymbol(yystack.l_mark[-2].tval, yystack.l_mark[-2].cval, yystack.l_mark[0].id);
yyval.nlist->next = yystack.l_mark[-1].nlist;
}
break;
case 8:
if (!yytrial)
#line 80 "btyacc_destroy1.y"
{ yyval.nlist->s = mksymbol(0, 0, yystack.l_mark[0].id);
yyval.nlist->next = NULL;
}
break;
case 9:
if (!yytrial)
#line 86 "btyacc_destroy1.y"
{ yyval.nlist = yystack.l_mark[-5].nlist; }
break;
#line 1217 "btyacc_destroy1.tab.c"
default:
break;
}
yystack.s_mark -= yym;
yystate = *yystack.s_mark;
yystack.l_mark -= yym;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yystack.p_mark -= yym;
#endif
yym = yylhs[yyn];
if (yystate == 0 && yym == 0)
{
#if YYDEBUG
if (yydebug)
{
fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
#ifdef YYSTYPE_TOSTRING
#if YYBTYACC
if (!yytrial)
#endif /* YYBTYACC */
fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[YYFINAL], yyval));
#endif
fprintf(stderr, "shifting from state 0 to final state %d\n", YYFINAL);
}
#endif
yystate = YYFINAL;
*++yystack.s_mark = YYFINAL;
*++yystack.l_mark = yyval;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
*++yystack.p_mark = yyloc;
#endif
if (yychar < 0)
{
#if YYBTYACC
do {
if (yylvp < yylve)
{
/* we're currently re-reading tokens */
yylval = *yylvp++;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yylloc = *yylpp++;
#endif
yychar = *yylexp++;
break;
}
if (yyps->save)
{
/* in trial mode; save scanner results for future parse attempts */
if (yylvp == yylvlim)
{ /* Enlarge lexical value queue */
size_t p = (size_t) (yylvp - yylvals);
size_t s = (size_t) (yylvlim - yylvals);
s += YYLVQUEUEGROWTH;
if ((yylexemes = (short *) realloc(yylexemes, s * sizeof(short))) == NULL)
goto yyenomem;
if ((yylvals = (YYSTYPE *) realloc(yylvals, s * sizeof(YYSTYPE))) == NULL)
goto yyenomem;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
if ((yylpsns = (YYLTYPE *) realloc(yylpsns, s * sizeof(YYLTYPE))) == NULL)
goto yyenomem;
#endif
yylvp = yylve = yylvals + p;
yylvlim = yylvals + s;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yylpp = yylpe = yylpsns + p;
yylplim = yylpsns + s;
#endif
yylexp = yylexemes + p;
}
*yylexp = (short) YYLEX;
*yylvp++ = yylval;
yylve++;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
*yylpp++ = yylloc;
yylpe++;
#endif
yychar = *yylexp++;
break;
}
/* normal operation, no conflict encountered */
#endif /* YYBTYACC */
yychar = YYLEX;
#if YYBTYACC
} while (0);
#endif /* YYBTYACC */
if (yychar < 0) yychar = YYEOF;
/* if ((yychar = YYLEX) < 0) yychar = YYEOF; */
#if YYDEBUG
if (yydebug)
{
yys = yyname[YYTRANSLATE(yychar)];
fprintf(stderr, "%s[%d]: state %d, reading %d (%s)\n",
YYDEBUGSTR, yydepth, YYFINAL, yychar, yys);
}
#endif
}
if (yychar == YYEOF) goto yyaccept;
goto yyloop;
}
if (((yyn = yygindex[yym]) != 0) && (yyn += yystate) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == (YYINT) yystate)
yystate = yytable[yyn];
else
yystate = yydgoto[yym];
#if YYDEBUG
if (yydebug)
{
fprintf(stderr, "%s[%d]: after reduction, ", YYDEBUGSTR, yydepth);
#ifdef YYSTYPE_TOSTRING
#if YYBTYACC
if (!yytrial)
#endif /* YYBTYACC */
fprintf(stderr, "result is <%s>, ", YYSTYPE_TOSTRING(yystos[yystate], yyval));
#endif
fprintf(stderr, "shifting from state %d to state %d\n", *yystack.s_mark, yystate);
}
#endif
if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow;
*++yystack.s_mark = (short) yystate;
*++yystack.l_mark = yyval;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
*++yystack.p_mark = yyloc;
#endif
goto yyloop;
#if YYBTYACC
/* Reduction declares that this path is valid. Set yypath and do a full parse */
yyvalid:
if (yypath) YYABORT;
while (yyps->save)
{
YYParseState *save = yyps->save;
yyps->save = save->save;
save->save = yypath;
yypath = save;
}
#if YYDEBUG
if (yydebug)
fprintf(stderr, "%s[%d]: state %d, CONFLICT trial successful, backtracking to state %d, %d tokens\n",
YYDEBUGSTR, yydepth, yystate, yypath->state, (int)(yylvp - yylvals - yypath->lexeme));
#endif
if (yyerrctx)
{
yyFreeState(yyerrctx);
yyerrctx = NULL;
}
yylvp = yylvals + yypath->lexeme;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yylpp = yylpsns + yypath->lexeme;
#endif
yylexp = yylexemes + yypath->lexeme;
yychar = YYEMPTY;
yystack.s_mark = yystack.s_base + (yypath->yystack.s_mark - yypath->yystack.s_base);
memcpy (yystack.s_base, yypath->yystack.s_base, (size_t) (yystack.s_mark - yystack.s_base + 1) * sizeof(short));
yystack.l_mark = yystack.l_base + (yypath->yystack.l_mark - yypath->yystack.l_base);
memcpy (yystack.l_base, yypath->yystack.l_base, (size_t) (yystack.l_mark - yystack.l_base + 1) * sizeof(YYSTYPE));
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
yystack.p_mark = yystack.p_base + (yypath->yystack.p_mark - yypath->yystack.p_base);
memcpy (yystack.p_base, yypath->yystack.p_base, (size_t) (yystack.p_mark - yystack.p_base + 1) * sizeof(YYLTYPE));
#endif
yystate = yypath->state;
goto yyloop;
#endif /* YYBTYACC */
yyoverflow:
YYERROR_CALL("yacc stack overflow");
#if YYBTYACC
goto yyabort_nomem;
yyenomem:
YYERROR_CALL("memory exhausted");
yyabort_nomem:
#endif /* YYBTYACC */
yyresult = 2;
goto yyreturn;
yyabort:
yyresult = 1;
goto yyreturn;
yyaccept:
#if YYBTYACC
if (yyps->save) goto yyvalid;
#endif /* YYBTYACC */
yyresult = 0;
yyreturn:
#if defined(YYDESTRUCT_CALL)
if (yychar != YYEOF && yychar != YYEMPTY)
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval, &yylloc);
#else
YYDESTRUCT_CALL("cleanup: discarding token", yychar, &yylval);
#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
{
YYSTYPE *pv;
#if defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED)
YYLTYPE *pp;
for (pv = yystack.l_base, pp = yystack.p_base; pv <= yystack.l_mark; ++pv, ++pp)
YYDESTRUCT_CALL("cleanup: discarding state",
yystos[*(yystack.s_base + (pv - yystack.l_base))], pv, pp);
#else
for (pv = yystack.l_base; pv <= yystack.l_mark; ++pv)
YYDESTRUCT_CALL("cleanup: discarding state",
yystos[*(yystack.s_base + (pv - yystack.l_base))], pv);
#endif /* defined(YYLTYPE) || defined(YYLTYPE_IS_DECLARED) */
}
#endif /* defined(YYDESTRUCT_CALL) */
#if YYBTYACC
if (yyerrctx)
{
yyFreeState(yyerrctx);
yyerrctx = NULL;
}
while (yyps)
{
YYParseState *save = yyps;
yyps = save->save;
save->save = NULL;
yyFreeState(save);
}
while (yypath)
{
YYParseState *save = yypath;
yypath = save->save;
save->save = NULL;
yyFreeState(save);
}
#endif /* YYBTYACC */
yyfreestack(&yystack);
return (yyresult);
}
|
the_stack_data/175947.c | char str[] = "z";
|
the_stack_data/927762.c | int main() {
for (;;) {}
return 0;
}
|
the_stack_data/34512601.c | #include <emmintrin.h>
#include <stdio.h>
__m128 foo (__v4si a, __v4si b)
{
return (__m128)__builtin_ia32_packssdw128(a, b);
}
int main (void)
{
__v4si a = { 0, 0, 0, 0};
__v4si b = { 0, 0, 0, 0};
__v16qi c = (__v16qi)foo(a, b);
if (__builtin_ia32_vec_ext_v4si((__v4si)c, 0) == 0)
printf("packssdw-1 passed\n");
else
printf("packssdw-1 failed\n");
return 0;
}
|
the_stack_data/613786.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkate <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 14:35:50 by jkate #+# #+# */
/* Updated: 2020/11/02 21:45:04 by jkate ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isprint(int arg)
{
if (arg >= 32 && arg <= 126)
return (1);
return (0);
}
|
the_stack_data/544765.c | /*
* Copyright (C) 2013 Red Hat
* Author: Rob Clark <[email protected]>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* For debugging crashes, userspace can:
*
* tail -f /sys/kernel/debug/dri/<minor>/rd > logfile.rd
*
* to log the cmdstream in a format that is understood by freedreno/cffdump
* utility. By comparing the last successfully completed fence #, to the
* cmdstream for the next fence, you can narrow down which process and submit
* caused the gpu crash/lockup.
*
* Additionally:
*
* tail -f /sys/kernel/debug/dri/<minor>/hangrd > logfile.rd
*
* will capture just the cmdstream from submits which triggered a GPU hang.
*
* This bypasses drm_debugfs_create_files() mainly because we need to use
* our own fops for a bit more control. In particular, we don't want to
* do anything if userspace doesn't have the debugfs file open.
*
* The module-param "rd_full", which defaults to false, enables snapshotting
* all (non-written) buffers in the submit, rather than just cmdstream bo's.
* This is useful to capture the contents of (for example) vbo's or textures,
* or shader programs (if not emitted inline in cmdstream).
*/
#ifdef CONFIG_DEBUG_FS
#include <linux/kfifo.h>
#include <linux/debugfs.h>
#include <linux/circ_buf.h>
#include <linux/wait.h>
#include "msm_drv.h"
#include "msm_gpu.h"
#include "msm_gem.h"
static bool rd_full = false;
MODULE_PARM_DESC(rd_full, "If true, $debugfs/.../rd will snapshot all buffer contents");
module_param_named(rd_full, rd_full, bool, 0600);
enum rd_sect_type {
RD_NONE,
RD_TEST, /* ascii text */
RD_CMD, /* ascii text */
RD_GPUADDR, /* u32 gpuaddr, u32 size */
RD_CONTEXT, /* raw dump */
RD_CMDSTREAM, /* raw dump */
RD_CMDSTREAM_ADDR, /* gpu addr of cmdstream */
RD_PARAM, /* u32 param_type, u32 param_val, u32 bitlen */
RD_FLUSH, /* empty, clear previous params */
RD_PROGRAM, /* shader program, raw dump */
RD_VERT_SHADER,
RD_FRAG_SHADER,
RD_BUFFER_CONTENTS,
RD_GPU_ID,
};
#define BUF_SZ 512 /* should be power of 2 */
/* space used: */
#define circ_count(circ) \
(CIRC_CNT((circ)->head, (circ)->tail, BUF_SZ))
#define circ_count_to_end(circ) \
(CIRC_CNT_TO_END((circ)->head, (circ)->tail, BUF_SZ))
/* space available: */
#define circ_space(circ) \
(CIRC_SPACE((circ)->head, (circ)->tail, BUF_SZ))
#define circ_space_to_end(circ) \
(CIRC_SPACE_TO_END((circ)->head, (circ)->tail, BUF_SZ))
struct msm_rd_state {
struct drm_device *dev;
bool open;
/* current submit to read out: */
struct msm_gem_submit *submit;
/* fifo access is synchronized on the producer side by
* struct_mutex held by submit code (otherwise we could
* end up w/ cmds logged in different order than they
* were executed). And read_lock synchronizes the reads
*/
struct mutex read_lock;
wait_queue_head_t fifo_event;
struct circ_buf fifo;
char buf[BUF_SZ];
};
static void rd_write(struct msm_rd_state *rd, const void *buf, int sz)
{
struct circ_buf *fifo = &rd->fifo;
const char *ptr = buf;
while (sz > 0) {
char *fptr = &fifo->buf[fifo->head];
int n;
wait_event(rd->fifo_event, circ_space(&rd->fifo) > 0 || !rd->open);
if (!rd->open)
return;
/* Note that smp_load_acquire() is not strictly required
* as CIRC_SPACE_TO_END() does not access the tail more
* than once.
*/
n = min(sz, circ_space_to_end(&rd->fifo));
memcpy(fptr, ptr, n);
smp_store_release(&fifo->head, (fifo->head + n) & (BUF_SZ - 1));
sz -= n;
ptr += n;
wake_up_all(&rd->fifo_event);
}
}
static void rd_write_section(struct msm_rd_state *rd,
enum rd_sect_type type, const void *buf, int sz)
{
rd_write(rd, &type, 4);
rd_write(rd, &sz, 4);
rd_write(rd, buf, sz);
}
static ssize_t rd_read(struct file *file, char __user *buf,
size_t sz, loff_t *ppos)
{
struct msm_rd_state *rd = file->private_data;
struct circ_buf *fifo = &rd->fifo;
const char *fptr = &fifo->buf[fifo->tail];
int n = 0, ret = 0;
mutex_lock(&rd->read_lock);
ret = wait_event_interruptible(rd->fifo_event,
circ_count(&rd->fifo) > 0);
if (ret)
goto out;
/* Note that smp_load_acquire() is not strictly required
* as CIRC_CNT_TO_END() does not access the head more than
* once.
*/
n = min_t(int, sz, circ_count_to_end(&rd->fifo));
if (copy_to_user(buf, fptr, n)) {
ret = -EFAULT;
goto out;
}
smp_store_release(&fifo->tail, (fifo->tail + n) & (BUF_SZ - 1));
*ppos += n;
wake_up_all(&rd->fifo_event);
out:
mutex_unlock(&rd->read_lock);
if (ret)
return ret;
return n;
}
static int rd_open(struct inode *inode, struct file *file)
{
struct msm_rd_state *rd = inode->i_private;
struct drm_device *dev = rd->dev;
struct msm_drm_private *priv = dev->dev_private;
struct msm_gpu *gpu = priv->gpu;
uint64_t val;
uint32_t gpu_id;
int ret = 0;
mutex_lock(&dev->struct_mutex);
if (rd->open || !gpu) {
ret = -EBUSY;
goto out;
}
file->private_data = rd;
rd->open = true;
/* the parsing tools need to know gpu-id to know which
* register database to load.
*/
gpu->funcs->get_param(gpu, MSM_PARAM_GPU_ID, &val);
gpu_id = val;
rd_write_section(rd, RD_GPU_ID, &gpu_id, sizeof(gpu_id));
out:
mutex_unlock(&dev->struct_mutex);
return ret;
}
static int rd_release(struct inode *inode, struct file *file)
{
struct msm_rd_state *rd = inode->i_private;
rd->open = false;
wake_up_all(&rd->fifo_event);
return 0;
}
static const struct file_operations rd_debugfs_fops = {
.owner = THIS_MODULE,
.open = rd_open,
.read = rd_read,
.llseek = no_llseek,
.release = rd_release,
};
static void rd_cleanup(struct msm_rd_state *rd)
{
if (!rd)
return;
mutex_destroy(&rd->read_lock);
kfree(rd);
}
static struct msm_rd_state *rd_init(struct drm_minor *minor, const char *name)
{
struct msm_rd_state *rd;
struct dentry *ent;
int ret = 0;
rd = kzalloc(sizeof(*rd), GFP_KERNEL);
if (!rd)
return ERR_PTR(-ENOMEM);
rd->dev = minor->dev;
rd->fifo.buf = rd->buf;
mutex_init(&rd->read_lock);
init_waitqueue_head(&rd->fifo_event);
ent = debugfs_create_file(name, S_IFREG | S_IRUGO,
minor->debugfs_root, rd, &rd_debugfs_fops);
if (!ent) {
DRM_ERROR("Cannot create /sys/kernel/debug/dri/%pd/%s\n",
minor->debugfs_root, name);
ret = -ENOMEM;
goto fail;
}
return rd;
fail:
rd_cleanup(rd);
return ERR_PTR(ret);
}
int msm_rd_debugfs_init(struct drm_minor *minor)
{
struct msm_drm_private *priv = minor->dev->dev_private;
struct msm_rd_state *rd;
int ret;
/* only create on first minor: */
if (priv->rd)
return 0;
rd = rd_init(minor, "rd");
if (IS_ERR(rd)) {
ret = PTR_ERR(rd);
goto fail;
}
priv->rd = rd;
rd = rd_init(minor, "hangrd");
if (IS_ERR(rd)) {
ret = PTR_ERR(rd);
goto fail;
}
priv->hangrd = rd;
return 0;
fail:
msm_rd_debugfs_cleanup(priv);
return ret;
}
void msm_rd_debugfs_cleanup(struct msm_drm_private *priv)
{
rd_cleanup(priv->rd);
priv->rd = NULL;
rd_cleanup(priv->hangrd);
priv->hangrd = NULL;
}
static void snapshot_buf(struct msm_rd_state *rd,
struct msm_gem_submit *submit, int idx,
uint64_t iova, uint32_t size)
{
struct msm_gem_object *obj = submit->bos[idx].obj;
unsigned offset = 0;
const char *buf;
if (iova) {
offset = iova - submit->bos[idx].iova;
} else {
iova = submit->bos[idx].iova;
size = obj->base.size;
}
/*
* Always write the GPUADDR header so can get a complete list of all the
* buffers in the cmd
*/
rd_write_section(rd, RD_GPUADDR,
(uint32_t[3]){ iova, size, iova >> 32 }, 12);
/* But only dump the contents of buffers marked READ */
if (!(submit->bos[idx].flags & MSM_SUBMIT_BO_READ))
return;
buf = msm_gem_get_vaddr_active(&obj->base);
if (IS_ERR(buf))
return;
buf += offset;
rd_write_section(rd, RD_BUFFER_CONTENTS, buf, size);
msm_gem_put_vaddr(&obj->base);
}
static bool
should_dump(struct msm_gem_submit *submit, int idx)
{
return rd_full || (submit->bos[idx].flags & MSM_SUBMIT_BO_DUMP);
}
/* called under struct_mutex */
void msm_rd_dump_submit(struct msm_rd_state *rd, struct msm_gem_submit *submit,
const char *fmt, ...)
{
struct drm_device *dev = submit->dev;
struct task_struct *task;
char msg[256];
int i, n;
if (!rd->open)
return;
/* writing into fifo is serialized by caller, and
* rd->read_lock is used to serialize the reads
*/
WARN_ON(!mutex_is_locked(&dev->struct_mutex));
if (fmt) {
va_list args;
va_start(args, fmt);
n = vscnprintf(msg, sizeof(msg), fmt, args);
va_end(args);
rd_write_section(rd, RD_CMD, msg, ALIGN(n, 4));
}
rcu_read_lock();
task = pid_task(submit->pid, PIDTYPE_PID);
if (task) {
n = scnprintf(msg, sizeof(msg), "%.*s/%d: fence=%u",
TASK_COMM_LEN, task->comm,
pid_nr(submit->pid), submit->seqno);
} else {
n = scnprintf(msg, sizeof(msg), "???/%d: fence=%u",
pid_nr(submit->pid), submit->seqno);
}
rcu_read_unlock();
rd_write_section(rd, RD_CMD, msg, ALIGN(n, 4));
for (i = 0; i < submit->nr_bos; i++)
if (should_dump(submit, i))
snapshot_buf(rd, submit, i, 0, 0);
for (i = 0; i < submit->nr_cmds; i++) {
uint64_t iova = submit->cmd[i].iova;
uint32_t szd = submit->cmd[i].size; /* in dwords */
/* snapshot cmdstream bo's (if we haven't already): */
if (!should_dump(submit, i)) {
snapshot_buf(rd, submit, submit->cmd[i].idx,
submit->cmd[i].iova, szd * 4);
}
switch (submit->cmd[i].type) {
case MSM_SUBMIT_CMD_IB_TARGET_BUF:
/* ignore IB-targets, we've logged the buffer, the
* parser tool will follow the IB based on the logged
* buffer/gpuaddr, so nothing more to do.
*/
break;
case MSM_SUBMIT_CMD_CTX_RESTORE_BUF:
case MSM_SUBMIT_CMD_BUF:
rd_write_section(rd, RD_CMDSTREAM_ADDR,
(uint32_t[3]){ iova, szd, iova >> 32 }, 12);
break;
}
}
}
#endif
|
the_stack_data/1213771.c | #include<stdio.h>
#include<string.h>
int main()
{
int i;
char s1[100],s2[100];
printf("\nEnter first string, s1: ");
scanf("%s",s1);
printf("\nEnter second string, s2: ");
scanf("%s",s2);
if(strlen(s1)==strlen(s2))
printf("\nBoth the string lengths of above given strings, s1 and s2 are same.");
else if(strlen(s1)>strlen(s2))
printf("\nThe longest string between %s and %s is: %s",s1,s2,s1);
else
printf("\nThe longest string between %s and %s is: %s",s1,s2,s2);
return 0;
}
|
the_stack_data/723271.c | char *version_string = "@(#)GNU Awk 3.0";
/* 1.02 fixed /= += *= etc to return the new Left Hand Side instead
of the Right Hand Side */
/* 1.03 Fixed split() to treat strings of space and tab as FS if
the split char is ' '.
Added -v option to print version number
Fixed bug that caused rounding when printing large numbers */
/* 2.00beta Incorporated the functionality of the "new" awk as described
the book (reference not handy). Extensively tested, but no
doubt still buggy. Badly needs tuning and cleanup, in
particular in memory management which is currently almost
non-existent. */
/* 2.01 JF: Modified to compile under GCC, and fixed a few
bugs while I was at it. I hope I didn't add any more.
I modified parse.y to reduce the number of reduce/reduce
conflicts. There are still a few left. */
/* 2.02 Fixed JF's bugs; improved memory management, still needs
lots of work. */
/* 2.10 Major grammar rework and lots of bug fixes from David.
Major changes for performance enhancements from David.
A number of minor bug fixes and new features from Arnold.
Changes for MSDOS from Conrad Kwok and Scott Garfinkle.
The gawk.texinfo and info files included! */
/* 2.11 Bug fix release to 2.10. Lots of changes for portability,
speed, and configurability. */
/* 2.12 Lots of changes for portability, speed, and configurability.
Several bugs fixed. POSIX compliance. Removal of last set
of hard-wired limits. Atari and VMS ports added. */
/* 2.13 Public release of 2.12 */
/* 2.14 Mostly bug fixes. */
/* 2.15 Bug fixes plus intermixing of command-line source and files,
GNU long options, ARGIND, ERRNO and Plan 9 style /dev/ files.
`delete array'. OS/2 port added. */
/* 3.0 RS as regexp, RT variable, FS = "", fflush builtin, posix
regexps, IGNORECASE applies to all comparison, autoconf, source
code cleanup. See the NEWS file. */
|
the_stack_data/102249.c | #include <stdio.h>
#define INF 10000
int arr[INF];
int count = 0;
void addBack(int data) {
// 가장 뒤에 입력 후 길이 추가
arr[count] = data;
count++;
};
void addFirst(int data) {
// 모든 값 하나씩 밀어내고 가장 앞에 값 추가
for (int i = count; i >=1 ; i--) {
arr[i] = arr[i - 1]; // a[3] = a[2], a[2] = a[1], a[1] == a[0]
}
arr[0] = data; // 새 값으로 덮어쓰기
count++;
};
void removeAt(int index) {
for (int i = index; i < count - 1; i++) {
// 지정한 인덱스부터 뒤에서 하나씩 밀어내기
arr[i] = arr[i + 1];
}
// 리스트 길이 하나 줄임
count--;
}
void insertAt(int index, int value) {
for (int i = count; i >= index; i--) {
arr[i] = arr[i - 1];
}
arr[index] = value;
count++;
}
void show() {
for (int i = 0; i < count; i++) {
printf("%d ", arr[i]);
}
printf("\n");
}
int main(void) {
addFirst(4);
addFirst(5);
addBack(3);
addBack(5);
show();
removeAt(2);
show();
insertAt(1, 2);
show();
return 0;
}
/*
5 4 3 5
5 4 5
5 2 4 5
*/
|
the_stack_data/90762011.c | #include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <strings.h>
#include <string.h>
#include <ctype.h>
#include <arpa/inet.h>
#define SERV_PORT 9527
int main(void)
{
int sfd, cfd;
int len, i;
char buf[BUFSIZ], clie_IP[BUFSIZ];
struct sockaddr_in serv_addr, clie_addr;
socklen_t clie_addr_len;
/*创建一个socket 指定IPv4协议族 TCP协议*/
sfd = socket(AF_INET, SOCK_STREAM, 0);
/*初始化一个地址结构 man 7 ip 查看对应信息*/
bzero(&serv_addr, sizeof(serv_addr)); //将整个结构体清零
serv_addr.sin_family = AF_INET; //选择协议族为IPv4
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); //监听本地所有IP地址
serv_addr.sin_port = htons(SERV_PORT); //绑定端口号
/*绑定服务器地址结构*/
bind(sfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
/*设定链接上限,注意此处不阻塞*/
listen(sfd, 64); //同一时刻允许向服务器发起链接请求的数量
printf("wait for client connect ...\n");
/*获取客户端地址结构大小*/
clie_addr_len = sizeof(clie_addr_len);
/*参数1是sfd; 参2传出参数, 参3传入传入参数, 全部是client端的参数*/
cfd = accept(sfd, (struct sockaddr *)&clie_addr, &clie_addr_len); /*监听客户端链接, 会阻塞*/
printf("client IP:%s\tport:%d\n",
inet_ntop(AF_INET, &clie_addr.sin_addr.s_addr, clie_IP, sizeof(clie_IP)),
ntohs(clie_addr.sin_port));
while (1) {
/*读取客户端发送数据*/
len = read(cfd, buf, sizeof(buf));
write(STDOUT_FILENO, buf, len);
/*处理客户端数据*/
for (i = 0; i < len; i++)
buf[i] = toupper(buf[i]);
/*处理完数据回写给客户端*/
write(cfd, buf, len);
}
/*关闭链接*/
close(sfd);
close(cfd);
return 0;
}
|
the_stack_data/44974.c | #include <stdio.h>
int main(){
int tipo[4] = {0,0,0,0} , N;
scanf(" %d" , &N);
while(N!=4){
switch(N){
case 1: tipo[0]++; break;
case 2: tipo[1]++; break;
case 3: tipo[2]++; break;
}
scanf(" %d" , &N);
}
printf("MUITO OBRIGADO\nAlcool: %d\nGasolina: %d\nDiesel: %d\n", tipo[0] , tipo[1] , tipo[2]);
return 0;
} |
the_stack_data/124687.c | // SKIP PARAM: --set solver td3 --enable ana.int.interval --enable exp.partition-arrays.enabled --set ana.activated "['base','threadid','threadflag','expRelation','apron','mallocWrapper']" --set exp.privatization none
// These examples were cases were we saw issues of not reaching a fixpoint during development of the octagon domain. Since those issues might
// resurface, these tests without asserts are included
int main(int argc, char const *argv[])
{
int l;
int r = 42;
while(1) {
if (l-r <= 0) {
r--;
} else {
break;
}
}
return 0;
}
|
the_stack_data/51701233.c | /*****************************
* @Createdby likelove
* @contact [email protected]
* @date 2021/3/2
* @desc ${desc}
******************************/
#include <stdio.h>
int main() {
int ch = 0;
// eof 文件结束标志
// while ((ch = getchar() != EOF)) {
// putchar(ch);
// }
int i = 0, k = 0;
for (int i = 0, k = 0; (0); k++, i++) {
k++;
}
printf("%d", k);
return 0;
} |
the_stack_data/90763399.c | #include <stdio.h>
#include <string.h>
static char str[] = "Computer Science";
int main(void)
{
int i = 0, j = 0, len = 0;
char *p = str;
len = strlen(str);
for (i = 0; i < len; i++) {
if (*(p + i) == ' ') {
for (j = i; j <= len; j++) {
*(p + j) = *(p + j + 1);
}
}
}
for(i = 0; i < len; i++) {
if ((i) % 2 == 0) {
printf("%c", *(p + i));
}
}
printf("\n");
return 0;
} |
the_stack_data/107953885.c | // RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -o - %s | FileCheck %s
// END.
static long long llfoo;
static int intfoo;
static short shortfoo;
static char charfoo;
// CHECK: private unnamed_addr constant [13 x i8] {{.*}}annotation_a{{.*}} section "llvm.metadata"
// CHECK-NOT: {{.*}}annotation_a{{.*}}
static int foo(int a) {
return a + 1;
}
int main(int argc, char **argv) {
char barray[16];
char *b = (char *) __builtin_annotation((int)barray, "annotation_a");
// CHECK: ptrtoint i8* {{.*}} to i32
// CHECK-NEXT: call i32 @llvm.annotation.i32
// CHECK: inttoptr {{.*}} to i8*
int call = __builtin_annotation(foo(argc), "annotation_a");
// CHECK: call {{.*}} @foo
// CHECK: call i32 @llvm.annotation.i32
long long lla = __builtin_annotation(llfoo, "annotation_a");
// CHECK: call i64 @llvm.annotation.i64
int inta = __builtin_annotation(intfoo, "annotation_a");
// CHECK: load i32, i32* @intfoo
// CHECK-NEXT: call i32 @llvm.annotation.i32
// CHECK-NEXT: store
short shorta = __builtin_annotation(shortfoo, "annotation_a");
// CHECK: call i16 @llvm.annotation.i16
char chara = __builtin_annotation(charfoo, "annotation_a");
// CHECK: call i8 @llvm.annotation.i8
char **arg = (char**) __builtin_annotation((int) argv, "annotation_a");
// CHECK: ptrtoint i8** {{.*}} to
// CHECK: call i32 @llvm.annotation.i32
// CHECK: inttoptr {{.*}} to i8**
return 0;
int after_return = __builtin_annotation(argc, "annotation_a");
// CHECK-NOT: call i32 @llvm.annotation.i32
}
|
the_stack_data/162642687.c | // Exercice 4-2
// Modifier le programme afin d’afficher à chaque réception du signal le PID du processus distant qui
// envoie le signal. Rajouter au programme la possibilité de rediriger le traitement de CTRL C pour écrire un message
// de fin.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
// Action effectuée lors de la réception du signal
void handle_ctrl_c (int sig) {
printf("Signal SIGUSR1 reçu de %d\n", sig);
}
int main(int argc, char* argv[]) {
struct sigaction sa;
sa.sa_handler=&handle_ctrl_c; // warnings mais c'est pas grave
sa.sa_flags = SA_RESTART;
sigaction(SIGUSR1, &sa, NULL);
for (int i = 0; i < 1000; i++)
{
printf("Hélène a tjs raison !\n");
sleep(2);
}
} |
the_stack_data/234516948.c | #include <stdio.h>
void Leitura(int v[], int n){
int i;
for(i = 0; i < n; i++){
printf("Digite o numero: ");
scanf("%d", &v[i]);
}
}
void Mostrar(int v[], int n){
int i, impares = 0, pares = 0;
for(i = 0; i < n; i++){
if(v[i] % 2 == 0)
pares++;
else
impares++;
}
printf("Impares = %d Pares = %d\n", impares, pares);
}
int main(void){
int v[20], n;
printf("Quantidade de numeros: ");
scanf("%d", &n);
while(n > -1){
Leitura(v,n);
Mostrar(v,n);
printf("Quantidade de numeros(max=20): ");
scanf("%d", &n);
}
return 0;
} |
the_stack_data/92325975.c | #include <stdio.h>
#include <stdlib.h>
/* func: our one and only data type; it holds either a pointer to
a function call, or an integer. Also carry a func pointer to
a potential parameter, to simulate closure */
typedef struct func_t *func;
typedef struct func_t {
func (*func) (func, func), _;
int num;
} func_t;
func new(func(*f)(func, func), func _) {
func x = malloc(sizeof(func_t));
x->func = f;
x->_ = _; /* closure, sort of */
x->num = 0;
return x;
}
func call(func f, func g) {
return f->func(f, g);
}
func Y(func(*f)(func, func)) {
func _(func x, func y) { return call(x->_, y); }
func_t __ = { _ };
func g = call(new(f, 0), &__);
g->_ = g;
return g;
}
func num(int n) {
func x = new(0, 0);
x->num = n;
return x;
}
func fac(func f, func _null) {
func _(func self, func n) {
int nn = n->num;
return nn > 1 ? num(nn * call(self->_, num(nn - 1))->num)
: num(1);
}
return new(_, f);
}
func fib(func f, func _null) {
func _(func self, func n) {
int nn = n->num;
return nn > 1
? num( call(self->_, num(nn - 1))->num +
call(self->_, num(nn - 2))->num )
: num(1);
}
return new(_, f);
}
void show(func n) { printf(" %d", n->num); }
int main() {
int i;
func f = Y(fac);
printf("fac: ");
for (i = 1; i < 10; i++)
show( call(f, num(i)) );
printf("\n");
f = Y(fib);
printf("fib: ");
for (i = 1; i < 10; i++)
show( call(f, num(i)) );
printf("\n");
return 0;
}
|
the_stack_data/9514050.c | #include<stdio.h>
#include<math.h>
int main()
{
int i,j,k,t;
long long int n,sum=0;
scanf("%d",&t);
for(i=0;i<t;i++)
{
scanf("%lld",&n);
n=n%(int)(pow(10,9)+7);
sum=n*n%(int)(pow(10,9)+7);
printf("%lld\n",sum);
sum=0;
}
return 0;
}
|
the_stack_data/126702201.c | /* Generated by CIL v. 1.7.0 */
/* print_CIL_Input is false */
struct _IO_FILE;
struct timeval;
extern float strtof(char const *str , char const *endptr ) ;
extern void signal(int sig , void *func ) ;
typedef struct _IO_FILE FILE;
extern int atoi(char const *s ) ;
extern double strtod(char const *str , char const *endptr ) ;
extern int fclose(void *stream ) ;
extern void *fopen(char const *filename , char const *mode ) ;
extern void abort() ;
extern void exit(int status ) ;
extern int raise(int sig ) ;
extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ;
extern int strcmp(char const *a , char const *b ) ;
extern int rand() ;
extern unsigned long strtoul(char const *str , char const *endptr , int base ) ;
void RandomFunc(unsigned short input[1] , unsigned short output[1] ) ;
extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ;
extern int gettimeofday(struct timeval *tv , void *tz , ...) ;
extern int printf(char const *format , ...) ;
int main(int argc , char *argv[] ) ;
void megaInit(void) ;
extern unsigned long strlen(char const *s ) ;
extern long strtol(char const *str , char const *endptr , int base ) ;
extern unsigned long strnlen(char const *s , unsigned long maxlen ) ;
extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ;
struct timeval {
long tv_sec ;
long tv_usec ;
};
extern void *malloc(unsigned long size ) ;
extern int scanf(char const *format , ...) ;
void RandomFunc(unsigned short input[1] , unsigned short output[1] )
{
unsigned short state[1] ;
char copy13 ;
{
state[0UL] = input[0UL] + (unsigned short)2885;
if ((state[0UL] >> (unsigned short)4) & (unsigned short)1) {
state[0UL] += state[0UL];
} else {
copy13 = *((char *)(& state[0UL]) + 1);
*((char *)(& state[0UL]) + 1) = *((char *)(& state[0UL]) + 0);
*((char *)(& state[0UL]) + 0) = copy13;
}
output[0UL] = state[0UL] * 45871808UL;
}
}
void megaInit(void)
{
{
}
}
int main(int argc , char *argv[] )
{
unsigned short input[1] ;
unsigned short output[1] ;
int randomFuns_i5 ;
unsigned short randomFuns_value6 ;
int randomFuns_main_i7 ;
{
megaInit();
if (argc != 2) {
printf("Call this program with %i arguments\n", 1);
exit(-1);
} else {
}
randomFuns_i5 = 0;
while (randomFuns_i5 < 1) {
randomFuns_value6 = (unsigned short )strtoul(argv[randomFuns_i5 + 1], 0, 10);
input[randomFuns_i5] = randomFuns_value6;
randomFuns_i5 ++;
}
RandomFunc(input, output);
if (output[0] == (unsigned short)31026) {
printf("You win!\n");
} else {
}
randomFuns_main_i7 = 0;
while (randomFuns_main_i7 < 1) {
printf("%u\n", output[randomFuns_main_i7]);
randomFuns_main_i7 ++;
}
}
}
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.