file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/154829433.c | /*-----------------------------------------------------------------
A very simple example of curses programming
coder: jellen
date: 3-26-2004
----------------------------------------------------------------*/
#include <curses.h>
int main()
{
initscr();
box(stdscr, ACS_VLINE, ACS_HLINE); /*draw a box*/
move(LINES/2, COLS/2); /*move the cursor to the center*/
waddstr(stdscr, "Hello, world!");
refresh();
getch();
endwin();
return 0;
}
// gcc -o hello hello.c -lcurses |
the_stack_data/243893695.c | /*
* Write a program to print the corresponding Celsius to Fahrenheit table.
*/
#include <stdio.h>
int main(void)
{
int fahr, celsius, lower, upper, step;
lower = 0; /* lower limit of temperature table */
upper = 300; /* upper limit */
step = 20; /* step size */
fahr = lower;
while (fahr <= upper) {
celsius = 9 * (fahr + 32) / 5;
printf("%d\t%d\n", fahr, celsius);
fahr += step;
}
return 0;
}
|
the_stack_data/140765869.c | /*-
* Copyright (c) 2004-2006 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Luke Mewburn.
* Timo Teräs cleaned up the code for use in Alpine Linux with musl libc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/socket.h>
#include <sys/param.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <netdb.h>
#include <pwd.h>
#include <grp.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <paths.h>
#include <err.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <net/if.h>
#include <net/ethernet.h>
#include <netinet/ether.h>
#include <netinet/in.h>
enum {
RV_OK = 0,
RV_USAGE = 1,
RV_NOTFOUND = 2,
RV_NOENUM = 3
};
static int usage(const char *);
static int parsenum(const char *word, unsigned long *result)
{
unsigned long num;
char *ep;
if (!isdigit((unsigned char)word[0]))
return 0;
errno = 0;
num = strtoul(word, &ep, 10);
if (num == ULONG_MAX && errno == ERANGE)
return 0;
if (*ep != '\0')
return 0;
*result = num;
return 1;
}
/*
* printfmtstrings --
* vprintf(format, ...),
* then the aliases (beginning with prefix, separated by sep),
* then a newline
*/
__attribute__ ((format (printf, 4, 5)))
static void printfmtstrings(char *strings[], const char *prefix, const char *sep,
const char *fmt, ...)
{
va_list ap;
const char *curpref;
size_t i;
va_start(ap, fmt);
(void)vprintf(fmt, ap);
va_end(ap);
curpref = prefix;
for (i = 0; strings[i] != NULL; i++) {
(void)printf("%s%s", curpref, strings[i]);
curpref = sep;
}
(void)printf("\n");
}
static int ethers(int argc, char *argv[])
{
char hostname[MAXHOSTNAMELEN + 1], *hp;
struct ether_addr ea, *eap;
int i, rv;
if (argc == 2) {
warnx("Enumeration not supported on ethers");
return RV_NOENUM;
}
rv = RV_OK;
for (i = 2; i < argc; i++) {
if ((eap = ether_aton(argv[i])) == NULL) {
eap = &ea;
hp = argv[i];
if (ether_hostton(hp, eap) != 0) {
rv = RV_NOTFOUND;
break;
}
} else {
hp = hostname;
if (ether_ntohost(hp, eap) != 0) {
rv = RV_NOTFOUND;
break;
}
}
(void)printf("%-17s %s\n", ether_ntoa(eap), hp);
}
return rv;
}
static void groupprint(const struct group *gr)
{
printfmtstrings(gr->gr_mem, ":", ",", "%s:%s:%u",
gr->gr_name, gr->gr_passwd, gr->gr_gid);
}
static int group(int argc, char *argv[])
{
struct group *gr;
unsigned long id;
int i, rv;
rv = RV_OK;
if (argc == 2) {
while ((gr = getgrent()) != NULL)
groupprint(gr);
} else {
for (i = 2; i < argc; i++) {
if (parsenum(argv[i], &id))
gr = getgrgid((gid_t)id);
else
gr = getgrnam(argv[i]);
if (gr == NULL) {
rv = RV_NOTFOUND;
break;
}
groupprint(gr);
}
}
endgrent();
return rv;
}
static void hostsprint(const struct hostent *he)
{
char buf[INET6_ADDRSTRLEN];
if (inet_ntop(he->h_addrtype, he->h_addr, buf, sizeof(buf)) == NULL)
(void)strlcpy(buf, "# unknown", sizeof(buf));
printfmtstrings(he->h_aliases, " ", " ", "%-16s %s", buf, he->h_name);
}
static int hosts(int argc, char *argv[])
{
struct hostent *he;
char addr[IN6ADDRSZ];
int i, rv;
sethostent(1);
rv = RV_OK;
if (argc == 2) {
while ((he = gethostent()) != NULL)
hostsprint(he);
} else {
for (i = 2; i < argc; i++) {
if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0)
he = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6);
else if (inet_pton(AF_INET, argv[i], (void *)addr) > 0)
he = gethostbyaddr(addr, INADDRSZ, AF_INET);
else
he = gethostbyname(argv[i]);
if (he == NULL) {
rv = RV_NOTFOUND;
break;
}
hostsprint(he);
}
}
endhostent();
return rv;
}
static void networksprint(const struct netent *ne)
{
char buf[INET6_ADDRSTRLEN];
struct in_addr ianet;
ianet = inet_makeaddr(ne->n_net, 0);
if (inet_ntop(ne->n_addrtype, &ianet, buf, sizeof(buf)) == NULL)
(void)strlcpy(buf, "# unknown", sizeof(buf));
printfmtstrings(ne->n_aliases, " ", " ", "%-16s %s", ne->n_name, buf);
}
static int networks(int argc, char *argv[])
{
struct netent *ne;
in_addr_t net;
int i, rv;
setnetent(1);
rv = RV_OK;
if (argc == 2) {
while ((ne = getnetent()) != NULL)
networksprint(ne);
} else {
for (i = 2; i < argc; i++) {
net = inet_network(argv[i]);
if (net != INADDR_NONE)
ne = getnetbyaddr(net, AF_INET);
else
ne = getnetbyname(argv[i]);
if (ne == NULL) {
rv = RV_NOTFOUND;
break;
}
networksprint(ne);
}
}
endnetent();
return rv;
}
static void passwdprint(struct passwd *pw)
{
(void)printf("%s:%s:%u:%u:%s:%s:%s\n",
pw->pw_name, pw->pw_passwd, pw->pw_uid,
pw->pw_gid, pw->pw_gecos, pw->pw_dir, pw->pw_shell);
}
static int passwd(int argc, char *argv[])
{
struct passwd *pw;
unsigned long id;
int i, rv;
rv = RV_OK;
if (argc == 2) {
while ((pw = getpwent()) != NULL)
passwdprint(pw);
} else {
for (i = 2; i < argc; i++) {
if (parsenum(argv[i], &id))
pw = getpwuid((uid_t)id);
else
pw = getpwnam(argv[i]);
if (pw == NULL) {
rv = RV_NOTFOUND;
break;
}
passwdprint(pw);
}
}
endpwent();
return rv;
}
static void protocolsprint(struct protoent *pe)
{
printfmtstrings(pe->p_aliases, " ", " ",
"%-16s %5d", pe->p_name, pe->p_proto);
}
static int protocols(int argc, char *argv[])
{
struct protoent *pe;
unsigned long id;
int i, rv;
setprotoent(1);
rv = RV_OK;
if (argc == 2) {
while ((pe = getprotoent()) != NULL)
protocolsprint(pe);
} else {
for (i = 2; i < argc; i++) {
if (parsenum(argv[i], &id))
pe = getprotobynumber((int)id);
else
pe = getprotobyname(argv[i]);
if (pe == NULL) {
rv = RV_NOTFOUND;
break;
}
protocolsprint(pe);
}
}
endprotoent();
return rv;
}
static void servicesprint(struct servent *se)
{
printfmtstrings(se->s_aliases, " ", " ",
"%-16s %5d/%s",
se->s_name, ntohs(se->s_port), se->s_proto);
}
static int services(int argc, char *argv[])
{
struct servent *se;
unsigned long id;
char *proto;
int i, rv;
setservent(1);
rv = RV_OK;
if (argc == 2) {
while ((se = getservent()) != NULL)
servicesprint(se);
} else {
for (i = 2; i < argc; i++) {
proto = strchr(argv[i], '/');
if (proto != NULL)
*proto++ = '\0';
if (parsenum(argv[i], &id))
se = getservbyport(htons(id), proto);
else
se = getservbyname(argv[i], proto);
if (se == NULL) {
rv = RV_NOTFOUND;
break;
}
servicesprint(se);
}
}
endservent();
return rv;
}
static int shells(int argc, char *argv[])
{
const char *sh;
int i, rv;
setusershell();
rv = RV_OK;
if (argc == 2) {
while ((sh = getusershell()) != NULL)
(void)printf("%s\n", sh);
} else {
for (i = 2; i < argc; i++) {
setusershell();
while ((sh = getusershell()) != NULL) {
if (strcmp(sh, argv[i]) == 0) {
(void)printf("%s\n", sh);
break;
}
}
if (sh == NULL) {
rv = RV_NOTFOUND;
break;
}
}
}
endusershell();
return rv;
}
static struct getentdb {
const char *name;
int (*callback)(int, char *[]);
} databases[] = {
{ "ethers", ethers, },
{ "group", group, },
{ "hosts", hosts, },
{ "networks", networks, },
{ "passwd", passwd, },
{ "protocols", protocols, },
{ "services", services, },
{ "shells", shells, },
{ NULL, NULL, },
};
static int usage(const char *arg0)
{
struct getentdb *curdb;
size_t i;
(void)fprintf(stderr, "Usage: %s database [key ...]\n", arg0);
(void)fprintf(stderr, "\tdatabase may be one of:");
for (i = 0, curdb = databases; curdb->name != NULL; curdb++, i++) {
if (i % 7 == 0)
(void)fputs("\n\t\t", stderr);
(void)fprintf(stderr, "%s%s", i % 7 == 0 ? "" : " ",
curdb->name);
}
(void)fprintf(stderr, "\n");
exit(RV_USAGE);
/* NOTREACHED */
}
int
main(int argc, char *argv[])
{
struct getentdb *curdb;
if (argc < 2)
usage(argv[0]);
for (curdb = databases; curdb->name != NULL; curdb++)
if (strcmp(curdb->name, argv[1]) == 0)
return (*curdb->callback)(argc, argv);
warn("Unknown database `%s'", argv[1]);
usage(argv[0]);
/* NOTREACHED */
}
|
the_stack_data/97013926.c | #include <stdio.h>
#include <stdlib.h>
struct lnode{
int number;
struct lnode *next;
};
int left(int n,int k);
struct lnode* lalloc();
struct lnode * buildlist(int n);
int main(int argc,char *argv[]){
int n,k,leftno;
if(argc!=3 || (n=atoi(argv[1]))<=0 || (k=atoi(argv[2]))<=0){
printf("Usage: ./game n k \n");
return 1;
}
leftno = left(n,k);
printf("left:%d\n",leftno);
return 0;
}
int left(int n,int k){
int count=1,leftno;
struct lnode *plist,*pre,*p;
plist=buildlist(n);
pre=plist;
while(pre->next!=plist)
pre=pre->next;
while(n>1){
if(count%k==0){
p=pre->next;
pre->next=p->next;
free(p);
n--;
}else
pre=pre->next;
count++;
}
leftno=pre->number;
free(pre);
return leftno;
}
struct lnode *buildlist(int n){
struct lnode *plist,*plast,*p;
plist=lalloc();
plist->number=n;
plist->next=plist;
plast=plist;
while(--n>0){
p=lalloc();
p->number=n;
p->next=plist;
plist=p;
}
plast->next=plist;
return plist;
}
struct lnode* lalloc(void){
return (struct lnode*)malloc(sizeof(struct lnode));
}
|
the_stack_data/99229.c | /*
sqlite3_bctbx_vfs.c
Copyright (C) 2016 Belledonne Communications SARL
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.
*/
#ifdef SQLITE_STORAGE_ENABLED
#include "private.h"
#include "bctoolbox/charconv.h"
#include "sqlite3_bctbx_vfs.h"
#include <sqlite3.h>
#ifndef _WIN32_WCE
#include <errno.h>
#endif /*_WIN32_WCE*/
/**
* Closes the file whose file descriptor is stored in the file handle p.
* @param p sqlite3_file file handle pointer.
* @return SQLITE_OK if successful, SQLITE_IOERR_CLOSE otherwise.
*/
static int sqlite3bctbx_Close(sqlite3_file *p){
int ret;
sqlite3_bctbx_file_t *pFile = (sqlite3_bctbx_file_t*) p;
ret = bctbx_file_close(pFile->pbctbx_file);
if (!ret){
return SQLITE_OK;
}
else{
free(pFile);
return SQLITE_IOERR_CLOSE ;
}
}
/**
* Read count bytes from the open file given by p, starting at offset and puts them in
* the buffer pointed by buf.
* Calls bctbx_file_read.
*
* @param p sqlite3_file file handle pointer.
* @param buf buffer to write the read bytes to.
* @param count number of bytes to read
* @param offset file offset where to start reading
* @return SQLITE_OK if read bytes equals count,
* SQLITE_IOERR_SHORT_READ if the number of bytes read is inferior to count
* SQLITE_IOERR_READ if an error occurred.
*/
static int sqlite3bctbx_Read(sqlite3_file *p, void *buf, int count, sqlite_int64 offset){
int ret;
sqlite3_bctbx_file_t *pFile = (sqlite3_bctbx_file_t*) p;
if (pFile){
ret = bctbx_file_read(pFile->pbctbx_file, buf, count, (off_t)offset);
if( ret==count ){
return SQLITE_OK;
}
else if( ret >= 0 ){
/*fill in unread portion of buffer, as requested by sqlite3 documentation*/
memset(((uint8_t*)buf) + ret, 0, count-ret);
return SQLITE_IOERR_SHORT_READ;
}else {
return SQLITE_IOERR_READ;
}
}
return SQLITE_IOERR_READ;
}
/**
* Writes directly to the open file given through the p argument.
* Calls bctbx_file_write .
* @param p sqlite3_file file handle pointer.
* @param buf Buffer containing data to write
* @param count Size of data to write in bytes
* @param offset File offset where to write to
* @return SQLITE_OK on success, SQLITE_IOERR_WRITE if an error occurred.
*/
static int sqlite3bctbx_Write(sqlite3_file *p, const void *buf, int count, sqlite_int64 offset){
sqlite3_bctbx_file_t *pFile = (sqlite3_bctbx_file_t*) p;
int ret;
if (pFile ){
ret = bctbx_file_write(pFile->pbctbx_file, buf, count, (off_t)offset);
if(ret > 0 ) return SQLITE_OK;
else {
return SQLITE_IOERR_WRITE;
}
}
return SQLITE_IOERR_WRITE;
}
/**
* TRuncates or extends a file depending on the size provided.
* @param p sqlite3_file file handle pointer.
* @param size New file size.
* @return SQLITE_OK on success, SQLITE_IOERR_TRUNCATE if an error occurred during truncate,
* SQLITE_ERROR if ther was a problem on the file descriptor.
*/
static int sqlite3bctbx_Truncate(sqlite3_file *p, sqlite_int64 size){
int rc;
sqlite3_bctbx_file_t *pFile = (sqlite3_bctbx_file_t*) p;
if (pFile->pbctbx_file){
rc = bctbx_file_truncate(pFile->pbctbx_file, size);
if( rc < 0 ) {
return SQLITE_IOERR_TRUNCATE;
}
if (rc == 0){
return SQLITE_OK;
}
}
return SQLITE_ERROR;
}
/**
* Saves the file size associated with the file handle p into the argument pSize.
* @param p sqlite3_file file handle pointer.
* @return SQLITE_OK if read bytes equals count,
* SQLITE_IOERR_FSTAT if the file size returned is negative
* SQLITE_ERROR if an error occurred.
*/
static int sqlite3bctbx_FileSize(sqlite3_file *p, sqlite_int64 *pSize){
int64_t rc; /* Return code from fstat() call */
sqlite3_bctbx_file_t *pFile = (sqlite3_bctbx_file_t*) p;
if (pFile->pbctbx_file){
rc = bctbx_file_size(pFile->pbctbx_file);
if( rc < 0 ) {
return SQLITE_IOERR_FSTAT;
}
if (pSize){
*pSize = rc;
return SQLITE_OK;
}
}
return SQLITE_ERROR;
}
/************************ PLACE HOLDER FUNCTIONS ***********************/
/** These functions were implemented to please the SQLite VFS
implementation. Some of them are just stubs, some do a very limited job. */
/**
* Returns the device characteristics for the file. Stub function
* to fill the SQLite VFS function pointer structure .
* @param p sqlite3_file file handle pointer.
* @return value 4096.
*/
static int sqlite3bctbx_DeviceCharacteristics(sqlite3_file *p){
int rc = 0x00001000;
return rc;
}
/**
* Stub function for information and control over the open file.
* @param p sqlite3_file file handle pointer.
* @param op operation
* @param pArg unused
* @return SQLITE_OK on success, SALITE_NOTFOUND otherwise.
*/
static int sqlite3bctbx_FileControl(sqlite3_file *p, int op, void *pArg){
#ifdef SQLITE_FCNTL_MMAP_SIZE
if (op == SQLITE_FCNTL_MMAP_SIZE) return SQLITE_OK;
#endif
return SQLITE_NOTFOUND;
}
/**
* The lock file mechanism is not used with this VFS : checking
* the reserved lock is always OK.
* @param pUnused sqlite3_file file handle pointer.
* @param pResOut set to 0 since there is no lock mechanism.
* @return SQLITE_OK
*/
static int sqlite3bctbx_nolockCheckReservedLock(sqlite3_file *pUnused, int *pResOut){
*pResOut = 0;
return SQLITE_OK;
}
/**
* The lock file mechanism is not used with this VFS : locking the file
* is always OK.
* @param pUnused sqlite3_file file handle pointer.
* @param unused unused
* @return SQLITE_OK
*/
static int sqlite3bctbx_nolockLock(sqlite3_file *pUnused, int unused){
return SQLITE_OK;
}
/**
* The lock file mechanism is not used with this VFS : unlocking the file
* is always OK.
* @param pUnused sqlite3_file file handle pointer.
* @param unused unused
* @return SQLITE_OK
*/
static int sqlite3bctbx_nolockUnlock(sqlite3_file *pUnused, int unused){
return SQLITE_OK;
}
/**
* Simply sync the file contents given through the file handle p
* to the persistent media.
* @param p sqlite3_file file handle pointer.
* @param flags unused
* @return SQLITE_OK on success, SLITE_IOERR_FSYNC if an error occurred.
*/
static int sqlite3bctbx_Sync(sqlite3_file *p, int flags){
sqlite3_bctbx_file_t *pFile = (sqlite3_bctbx_file_t*)p;
#if _WIN32
int ret;
ret = FlushFileBuffers((HANDLE)_get_osfhandle(pFile->pbctbx_file->fd));
return (ret!=0 ? SQLITE_OK : SQLITE_IOERR_FSYNC);
#else
int rc = fsync(pFile->pbctbx_file->fd);
return (rc==0 ? SQLITE_OK : SQLITE_IOERR_FSYNC);
#endif
}
/************************ END OF PLACE HOLDER FUNCTIONS ***********************/
/**
* Opens the file fName and populates the structure pointed by p
* with the necessary io_methods
* Methods not implemented for version 1 : xTruncate, xSectorSize.
* Initializes some fields in the p structure, some of which where already
* initialized by SQLite.
* @param pVfs sqlite3_vfs VFS pointer.
* @param fName filename
* @param p file handle pointer
* @param flags db file access flags
* @param pOutFlags flags used by SQLite
* @return SQLITE_CANTOPEN on error, SQLITE_OK on success.
*/
static int sqlite3bctbx_Open(sqlite3_vfs *pVfs, const char *fName, sqlite3_file *p, int flags, int *pOutFlags ){
static const sqlite3_io_methods sqlite3_bctbx_io = {
1, /* iVersion Structure version number */
sqlite3bctbx_Close, /* xClose */
sqlite3bctbx_Read, /* xRead */
sqlite3bctbx_Write, /* xWrite */
sqlite3bctbx_Truncate, /* xTruncate */
sqlite3bctbx_Sync,
sqlite3bctbx_FileSize,
sqlite3bctbx_nolockLock,
sqlite3bctbx_nolockUnlock,
sqlite3bctbx_nolockCheckReservedLock,
sqlite3bctbx_FileControl,
NULL, /* xSectorSize */
sqlite3bctbx_DeviceCharacteristics
/*other function points follows, all NULL but not present in all sqlite3 versions.*/
};
sqlite3_bctbx_file_t * pFile = (sqlite3_bctbx_file_t*)p; /*File handle sqlite3_bctbx_file_t*/
int openFlags = 0;
char* wFname;
/*returns error if filename is empty or file handle not initialized*/
if (pFile == NULL || fName == NULL){
return SQLITE_IOERR;
}
/* Set flags to open the file with */
if( flags&SQLITE_OPEN_EXCLUSIVE ) openFlags |= O_EXCL;
if( flags&SQLITE_OPEN_CREATE ) openFlags |= O_CREAT;
if( flags&SQLITE_OPEN_READONLY ) openFlags |= O_RDONLY;
if( flags&SQLITE_OPEN_READWRITE ) openFlags |= O_RDWR;
#if defined(_WIN32)
openFlags |= O_BINARY;
#endif
wFname = bctbx_utf8_to_locale(fName);
if (wFname != NULL) {
pFile->pbctbx_file = bctbx_file_open2(bctbx_vfs_get_default(), wFname, openFlags);
bctbx_free(wFname);
} else {
pFile->pbctbx_file = NULL;
}
if( pFile->pbctbx_file == NULL){
return SQLITE_CANTOPEN;
}
if( pOutFlags ){
*pOutFlags = flags;
}
pFile->base.pMethods = &sqlite3_bctbx_io;
return SQLITE_OK;
}
sqlite3_vfs *sqlite3_bctbx_vfs_create(void){
static sqlite3_vfs bctbx_vfs = {
1, /* iVersion */
sizeof(sqlite3_bctbx_file_t), /* szOsFile */
MAXPATHNAME, /* mxPathname */
NULL, /* pNext */
LINPHONE_SQLITE3_VFS, /* zName */
NULL, /* pAppData */
sqlite3bctbx_Open, /* xOpen */
NULL, /* xDelete */
NULL, /* xAccess */
NULL /* xFullPathname */
};
return &bctbx_vfs;
}
/*static int sqlite3bctbx_winFullPathname(
sqlite3_vfs *pVfs, // Pointer to vfs object
const char *zRelative, // Possibly relative input path
int nFull, // Size of output buffer in bytes
char *zFull){
//LPWSTR zTemp;
//DWORD nByte;
// If this path name begins with "/X:", where "X" is any alphabetic
// character, discard the initial "/" from the pathname.
//
//if (zRelative[0] == '/' && sqlite3Isalpha(zRelative[1]) && zRelative[2] == ':'){
// zRelative++;
//}
nByte = GetFullPathNameW((LPCWSTR)zRelative, 0, 0, 0);
if (nByte == 0){
return SQLITE_CANTOPEN_FULLPATH;
}
nByte += 3;
zTemp = bctbx_malloc(nByte*sizeof(zTemp[0]));
memset(zTemp, 0, nByte*sizeof(zTemp[0]));
if (zTemp == 0){
return SQLITE_IOERR_NOMEM;
}
nByte = GetFullPathNameW((LPCWSTR)zRelative, nByte, zTemp, 0);
if (nByte == 0){
bctbx_free(zTemp);
return SQLITE_CANTOPEN_FULLPATH;
}
if (zTemp){
sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zTemp);
bctbx_free(zTemp);
return SQLITE_OK;
}
else{
return SQLITE_IOERR_NOMEM;
}
sqlite3_snprintf(MIN(nFull, pVfs->mxPathname), zFull, "%s", zRelative);
return SQLITE_OK;
}*/
void sqlite3_bctbx_vfs_register( int makeDefault){
sqlite3_vfs* pVfsToUse = sqlite3_bctbx_vfs_create();
#if _WIN32
sqlite3_vfs* pDefault = sqlite3_vfs_find("win32");
#else
sqlite3_vfs* pDefault = sqlite3_vfs_find("unix-none");
#endif
pVfsToUse->xCurrentTime = pDefault->xCurrentTime;
pVfsToUse->xAccess = pDefault->xAccess;
pVfsToUse->xFullPathname = pDefault->xFullPathname;
pVfsToUse->xDelete = pDefault->xDelete;
pVfsToUse->xSleep = pDefault->xSleep;
pVfsToUse->xRandomness = pDefault->xRandomness;
pVfsToUse->xGetLastError = pDefault->xGetLastError; /* Not implemented by sqlite3 :place holder */
/*Functions below should not be a problem sincve we are declaring ourselves
in version 1 */
/* used in version 2
xCurrentTimeInt64;*/
/* used in version 3
xGetSystemCall
xSetSystemCall
xNextSystemCall*/
sqlite3_vfs_register(pVfsToUse, makeDefault);
}
void sqlite3_bctbx_vfs_unregister(void)
{
sqlite3_vfs* pVfs = sqlite3_vfs_find(LINPHONE_SQLITE3_VFS);
sqlite3_vfs_unregister(pVfs);
}
#endif /*SQLITE_STORAGE_ENABLED*/
|
the_stack_data/168893723.c |
/* Simple S/MIME compress example */
#include <openssl/pem.h>
#include <openssl/cms.h>
#include <openssl/err.h>
int main(int argc, char **argv)
{
BIO *in = NULL, *out = NULL;
CMS_ContentInfo *cms = NULL;
int ret = 1;
/*
* On OpenSSL 0.9.9 only:
* for streaming set CMS_STREAM
*/
int flags = CMS_STREAM;
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
/* Open content being compressed */
in = BIO_new_file("comp.txt", "r");
if (!in)
goto err;
/* compress content */
cms = CMS_compress(in, NID_zlib_compression, flags);
if (!cms)
goto err;
out = BIO_new_file("smcomp.txt", "w");
if (!out)
goto err;
/* Write out S/MIME message */
if (!SMIME_write_CMS(out, cms, in, flags))
goto err;
ret = 0;
err:
if (ret)
{
fprintf(stderr, "Error Compressing Data\n");
ERR_print_errors_fp(stderr);
}
if (cms)
CMS_ContentInfo_free(cms);
if (in)
BIO_free(in);
if (out)
BIO_free(out);
return ret;
}
|
the_stack_data/1231826.c | #define NULL ((void*)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t; typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1
/* Forward declarations */
typedef struct TYPE_18__ TYPE_4__ ;
typedef struct TYPE_17__ TYPE_3__ ;
typedef struct TYPE_16__ TYPE_2__ ;
typedef struct TYPE_15__ TYPE_1__ ;
/* Type definitions */
struct TYPE_17__ {int AmlOpcode; scalar_t__ DisasmOpcode; char* OperatorSymbol; TYPE_4__* Next; int /*<<< orphan*/ DisasmFlags; TYPE_2__* Parent; } ;
struct TYPE_18__ {TYPE_3__ Common; } ;
struct TYPE_15__ {int /*<<< orphan*/ AmlOpcode; } ;
struct TYPE_16__ {TYPE_1__ Common; } ;
typedef int /*<<< orphan*/ BOOLEAN ;
typedef TYPE_4__ ACPI_PARSE_OBJECT ;
typedef int /*<<< orphan*/ ACPI_OP_WALK_INFO ;
/* Variables and functions */
scalar_t__ ACPI_DASM_LNOT_PREFIX ;
scalar_t__ ACPI_DASM_LNOT_SUFFIX ;
int /*<<< orphan*/ ACPI_PARSEOP_ASSIGNMENT ;
int /*<<< orphan*/ ACPI_PARSEOP_CLOSING_PAREN ;
int /*<<< orphan*/ ACPI_PARSEOP_COMPOUND_ASSIGNMENT ;
int /*<<< orphan*/ ACPI_PARSEOP_IGNORE ;
int /*<<< orphan*/ ACPI_PARSEOP_LEGACY_ASL_ONLY ;
#define AML_ADD_OP 148
#define AML_BIT_AND_OP 147
#define AML_BIT_NOT_OP 146
#define AML_BIT_OR_OP 145
#define AML_BIT_XOR_OP 144
int AML_BUFFER_OP ;
#define AML_DECREMENT_OP 143
#define AML_DIVIDE_OP 142
#define AML_INCREMENT_OP 141
#define AML_INDEX_OP 140
#define AML_LOGICAL_AND_OP 139
#define AML_LOGICAL_EQUAL_OP 138
#define AML_LOGICAL_GREATER_OP 137
#define AML_LOGICAL_LESS_OP 136
#define AML_LOGICAL_NOT_OP 135
#define AML_LOGICAL_OR_OP 134
#define AML_MOD_OP 133
#define AML_MULTIPLY_OP 132
int AML_PACKAGE_OP ;
#define AML_SHIFT_LEFT_OP 131
#define AML_SHIFT_RIGHT_OP 130
#define AML_STORE_OP 129
int AML_STRING_OP ;
#define AML_SUBTRACT_OP 128
int AML_VARIABLE_PACKAGE_OP ;
void* AcpiDmGetCompoundSymbol (int) ;
int /*<<< orphan*/ AcpiDmIsOptimizationIgnored (TYPE_4__*,TYPE_4__*) ;
int /*<<< orphan*/ AcpiDmIsTargetAnOperand (TYPE_4__*,TYPE_4__*,int /*<<< orphan*/ ) ;
int /*<<< orphan*/ AcpiDmIsValidTarget (TYPE_4__*) ;
int /*<<< orphan*/ AcpiDmPromoteTarget (TYPE_4__*,TYPE_4__*) ;
int /*<<< orphan*/ AcpiGbl_CstyleDisassembly ;
int /*<<< orphan*/ AcpiGbl_DoDisassemblerOptimizations ;
int /*<<< orphan*/ AcpiOsPrintf (char*) ;
TYPE_4__* AcpiPsGetArg (TYPE_4__*,int /*<<< orphan*/ ) ;
int /*<<< orphan*/ FALSE ;
int /*<<< orphan*/ TRUE ;
BOOLEAN
AcpiDmCheckForSymbolicOpcode (
ACPI_PARSE_OBJECT *Op,
ACPI_OP_WALK_INFO *Info)
{
char *OperatorSymbol = NULL;
ACPI_PARSE_OBJECT *Argument1;
ACPI_PARSE_OBJECT *Argument2;
ACPI_PARSE_OBJECT *Target;
ACPI_PARSE_OBJECT *Target2;
/* Exit immediately if ASL+ not enabled */
if (!AcpiGbl_CstyleDisassembly)
{
return (FALSE);
}
/* Get the first operand */
Argument1 = AcpiPsGetArg (Op, 0);
if (!Argument1)
{
return (FALSE);
}
/* Get the second operand */
Argument2 = Argument1->Common.Next;
/* Setup the operator string for this opcode */
switch (Op->Common.AmlOpcode)
{
case AML_ADD_OP:
OperatorSymbol = " + ";
break;
case AML_SUBTRACT_OP:
OperatorSymbol = " - ";
break;
case AML_MULTIPLY_OP:
OperatorSymbol = " * ";
break;
case AML_DIVIDE_OP:
OperatorSymbol = " / ";
break;
case AML_MOD_OP:
OperatorSymbol = " % ";
break;
case AML_SHIFT_LEFT_OP:
OperatorSymbol = " << ";
break;
case AML_SHIFT_RIGHT_OP:
OperatorSymbol = " >> ";
break;
case AML_BIT_AND_OP:
OperatorSymbol = " & ";
break;
case AML_BIT_OR_OP:
OperatorSymbol = " | ";
break;
case AML_BIT_XOR_OP:
OperatorSymbol = " ^ ";
break;
/* Logical operators, no target */
case AML_LOGICAL_AND_OP:
OperatorSymbol = " && ";
break;
case AML_LOGICAL_EQUAL_OP:
OperatorSymbol = " == ";
break;
case AML_LOGICAL_GREATER_OP:
OperatorSymbol = " > ";
break;
case AML_LOGICAL_LESS_OP:
OperatorSymbol = " < ";
break;
case AML_LOGICAL_OR_OP:
OperatorSymbol = " || ";
break;
case AML_LOGICAL_NOT_OP:
/*
* Check for the LNOT sub-opcodes. These correspond to
* LNotEqual, LLessEqual, and LGreaterEqual. There are
* no actual AML opcodes for these operators.
*/
switch (Argument1->Common.AmlOpcode)
{
case AML_LOGICAL_EQUAL_OP:
OperatorSymbol = " != ";
break;
case AML_LOGICAL_GREATER_OP:
OperatorSymbol = " <= ";
break;
case AML_LOGICAL_LESS_OP:
OperatorSymbol = " >= ";
break;
default:
/* Unary LNOT case, emit "!" immediately */
AcpiOsPrintf ("!");
return (TRUE);
}
Argument1->Common.DisasmOpcode = ACPI_DASM_LNOT_SUFFIX;
Op->Common.DisasmOpcode = ACPI_DASM_LNOT_PREFIX;
/* Save symbol string in the next child (not peer) */
Argument2 = AcpiPsGetArg (Argument1, 0);
if (!Argument2)
{
return (FALSE);
}
Argument2->Common.OperatorSymbol = OperatorSymbol;
return (TRUE);
case AML_INDEX_OP:
/*
* Check for constant source operand. Note: although technically
* legal syntax, the iASL compiler does not support this with
* the symbolic operators for Index(). It doesn't make sense to
* use Index() with a constant anyway.
*/
if ((Argument1->Common.AmlOpcode == AML_STRING_OP) ||
(Argument1->Common.AmlOpcode == AML_BUFFER_OP) ||
(Argument1->Common.AmlOpcode == AML_PACKAGE_OP) ||
(Argument1->Common.AmlOpcode == AML_VARIABLE_PACKAGE_OP))
{
Op->Common.DisasmFlags |= ACPI_PARSEOP_CLOSING_PAREN;
return (FALSE);
}
/* Index operator is [] */
Argument1->Common.OperatorSymbol = " [";
Argument2->Common.OperatorSymbol = "]";
break;
/* Unary operators */
case AML_DECREMENT_OP:
OperatorSymbol = "--";
break;
case AML_INCREMENT_OP:
OperatorSymbol = "++";
break;
case AML_BIT_NOT_OP:
case AML_STORE_OP:
OperatorSymbol = NULL;
break;
default:
return (FALSE);
}
if (Argument1->Common.DisasmOpcode == ACPI_DASM_LNOT_SUFFIX)
{
return (TRUE);
}
/*
* This is the key to how the disassembly of the C-style operators
* works. We save the operator symbol in the first child, thus
* deferring symbol output until after the first operand has been
* emitted.
*/
if (!Argument1->Common.OperatorSymbol)
{
Argument1->Common.OperatorSymbol = OperatorSymbol;
}
/*
* Check for a valid target as the 3rd (or sometimes 2nd) operand
*
* Compound assignment operator support:
* Attempt to optimize constructs of the form:
* Add (Local1, 0xFF, Local1)
* to:
* Local1 += 0xFF
*
* Only the math operators and Store() have a target.
* Logicals have no target.
*/
switch (Op->Common.AmlOpcode)
{
case AML_ADD_OP:
case AML_SUBTRACT_OP:
case AML_MULTIPLY_OP:
case AML_DIVIDE_OP:
case AML_MOD_OP:
case AML_SHIFT_LEFT_OP:
case AML_SHIFT_RIGHT_OP:
case AML_BIT_AND_OP:
case AML_BIT_OR_OP:
case AML_BIT_XOR_OP:
/* Target is 3rd operand */
Target = Argument2->Common.Next;
if (Op->Common.AmlOpcode == AML_DIVIDE_OP)
{
Target2 = Target->Common.Next;
/*
* Divide has an extra target operand (Remainder).
* Default behavior is to simply ignore ASL+ conversion
* if the remainder target (modulo) is specified.
*/
if (!AcpiGbl_DoDisassemblerOptimizations)
{
if (AcpiDmIsValidTarget (Target))
{
Argument1->Common.OperatorSymbol = NULL;
Op->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY;
return (FALSE);
}
Target->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
Target = Target2;
}
else
{
/*
* Divide has an extra target operand (Remainder).
* If both targets are specified, it cannot be converted
* to a C-style operator.
*/
if (AcpiDmIsValidTarget (Target) &&
AcpiDmIsValidTarget (Target2))
{
Argument1->Common.OperatorSymbol = NULL;
Op->Common.DisasmFlags |= ACPI_PARSEOP_LEGACY_ASL_ONLY;
return (FALSE);
}
if (AcpiDmIsValidTarget (Target)) /* Only first Target is valid (remainder) */
{
/* Convert the Divide to Modulo */
Op->Common.AmlOpcode = AML_MOD_OP;
Argument1->Common.OperatorSymbol = " % ";
Target2->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
}
else /* Only second Target (quotient) is valid */
{
Target->Common.DisasmFlags |= ACPI_PARSEOP_IGNORE;
Target = Target2;
}
}
}
/* Parser should ensure there is at least a placeholder target */
if (!Target)
{
return (FALSE);
}
if (!AcpiDmIsValidTarget (Target))
{
/* Not a valid target (placeholder only, from parser) */
break;
}
/*
* Promote the target up to the first child in the parse
* tree. This is done because the target will be output
* first, in the form:
* <Target> = Operands...
*/
AcpiDmPromoteTarget (Op, Target);
/* Check operands for conversion to a "Compound Assignment" */
switch (Op->Common.AmlOpcode)
{
/* Commutative operators */
case AML_ADD_OP:
case AML_MULTIPLY_OP:
case AML_BIT_AND_OP:
case AML_BIT_OR_OP:
case AML_BIT_XOR_OP:
/*
* For the commutative operators, we can convert to a
* compound statement only if at least one (either) operand
* is the same as the target.
*
* Add (A, B, A) --> A += B
* Add (B, A, A) --> A += B
* Add (B, C, A) --> A = (B + C)
*/
if ((AcpiDmIsTargetAnOperand (Target, Argument1, TRUE)) ||
(AcpiDmIsTargetAnOperand (Target, Argument2, TRUE)))
{
Target->Common.OperatorSymbol =
AcpiDmGetCompoundSymbol (Op->Common.AmlOpcode);
/* Convert operator to compound assignment */
Op->Common.DisasmFlags |= ACPI_PARSEOP_COMPOUND_ASSIGNMENT;
Argument1->Common.OperatorSymbol = NULL;
return (TRUE);
}
break;
/* Non-commutative operators */
case AML_SUBTRACT_OP:
case AML_DIVIDE_OP:
case AML_MOD_OP:
case AML_SHIFT_LEFT_OP:
case AML_SHIFT_RIGHT_OP:
/*
* For the non-commutative operators, we can convert to a
* compound statement only if the target is the same as the
* first operand.
*
* Subtract (A, B, A) --> A -= B
* Subtract (B, A, A) --> A = (B - A)
*/
if ((AcpiDmIsTargetAnOperand (Target, Argument1, TRUE)))
{
Target->Common.OperatorSymbol =
AcpiDmGetCompoundSymbol (Op->Common.AmlOpcode);
/* Convert operator to compound assignment */
Op->Common.DisasmFlags |= ACPI_PARSEOP_COMPOUND_ASSIGNMENT;
Argument1->Common.OperatorSymbol = NULL;
return (TRUE);
}
break;
default:
break;
}
/*
* If we are within a C-style expression, emit an extra open
* paren. Implemented by examining the parent op.
*/
switch (Op->Common.Parent->Common.AmlOpcode)
{
case AML_ADD_OP:
case AML_SUBTRACT_OP:
case AML_MULTIPLY_OP:
case AML_DIVIDE_OP:
case AML_MOD_OP:
case AML_SHIFT_LEFT_OP:
case AML_SHIFT_RIGHT_OP:
case AML_BIT_AND_OP:
case AML_BIT_OR_OP:
case AML_BIT_XOR_OP:
case AML_LOGICAL_AND_OP:
case AML_LOGICAL_EQUAL_OP:
case AML_LOGICAL_GREATER_OP:
case AML_LOGICAL_LESS_OP:
case AML_LOGICAL_OR_OP:
Op->Common.DisasmFlags |= ACPI_PARSEOP_ASSIGNMENT;
AcpiOsPrintf ("(");
break;
default:
break;
}
/* Normal output for ASL/AML operators with a target operand */
Target->Common.OperatorSymbol = " = (";
return (TRUE);
/* Binary operators, no parens */
case AML_DECREMENT_OP:
case AML_INCREMENT_OP:
return (TRUE);
case AML_INDEX_OP:
/* Target is optional, 3rd operand */
Target = Argument2->Common.Next;
if (AcpiDmIsValidTarget (Target))
{
AcpiDmPromoteTarget (Op, Target);
if (!Target->Common.OperatorSymbol)
{
Target->Common.OperatorSymbol = " = ";
}
}
return (TRUE);
case AML_STORE_OP:
/*
* For Store, the Target is the 2nd operand. We know the target
* is valid, because it is not optional.
*
* Ignore any optimizations/folding if flag is set.
* Used for iASL/disassembler test suite only.
*/
if (AcpiDmIsOptimizationIgnored (Op, Argument1))
{
return (FALSE);
}
/*
* Perform conversion.
* In the parse tree, simply swap the target with the
* source so that the target is processed first.
*/
Target = Argument1->Common.Next;
if (!Target)
{
return (FALSE);
}
AcpiDmPromoteTarget (Op, Target);
if (!Target->Common.OperatorSymbol)
{
Target->Common.OperatorSymbol = " = ";
}
return (TRUE);
case AML_BIT_NOT_OP:
/* Target is optional, 2nd operand */
Target = Argument1->Common.Next;
if (!Target)
{
return (FALSE);
}
if (AcpiDmIsValidTarget (Target))
{
/* Valid target, not a placeholder */
AcpiDmPromoteTarget (Op, Target);
Target->Common.OperatorSymbol = " = ~";
}
else
{
/* No target. Emit this prefix operator immediately */
AcpiOsPrintf ("~");
}
return (TRUE);
default:
break;
}
/* All other operators, emit an open paren */
AcpiOsPrintf ("(");
return (TRUE);
} |
the_stack_data/309686.c | #include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#define MAX_KEYLEN 256
typedef struct{
int fildes;
char key[MAX_KEYLEN];
} item_t;
static int nitems;
static item_t *items;
static int _itemcmp(const void *a, const void *b){
return strcmp(((item_t*) a)->key,((item_t*) b)->key);
}
int content_init(const char *filename){
FILE *filelist;
int capacity = 16;
char *path, *ptr;
if( NULL == (filelist = fopen(filename, "r"))){
fprintf(stderr, "Unable to open file in content_init.\n");
exit(EXIT_FAILURE);
}
items = (item_t*) malloc(capacity * sizeof(item_t));
nitems = 0;
while(fgets(items[nitems].key, MAX_KEYLEN, filelist)){
/*Taking out EOL character*/
items[nitems].key[strlen(items[nitems].key)-1] = '\0';
/* Using space delimiter to sep key and path*/
ptr = items[nitems].key;
strsep(&ptr, " \t"); /* The key is first */
path = strsep(&ptr, " \t"); /* The path second */
if( 0 > (items[nitems].fildes = open(path, O_RDONLY))){
fprintf(stderr, "Unable to open file %s.\n", path);
exit(EXIT_FAILURE);
}
nitems++;
if(nitems == capacity){
capacity *= 2;
items = realloc(items, capacity * sizeof(item_t));
}
}
fclose(filelist);
qsort(items, nitems, sizeof(item_t), _itemcmp);
return EXIT_SUCCESS;
}
int content_get(const char *key){
int lo = 0;
int hi = nitems - 1;
int mid, cmp;
#if defined(DELAY)
usleep(DELAY); // simulate slow I/O subsystem
#endif // DELAY
while (lo <= hi) {
// Key is in items[lo..hi] or not present.
mid = lo + (hi - lo) / 2;
cmp = strcmp(key,items[mid].key);
if ( cmp < 0) hi = mid - 1;
else if (cmp > 0) lo = mid + 1;
else{
lseek(items[mid].fildes, 0, SEEK_SET);
return items[mid].fildes;
}
}
return -1;
}
void content_destroy(){
int i;
for(i = 0; i < nitems; i++)
close(items[i].fildes);
free(items);
} |
the_stack_data/187644442.c | #include <stdio.h>
typedef struct newV {
int x;
long y;
int z;
}ejhash;
ejhash constructor(int x, long y, int z) {
ejhash obj;
obj.x = x;
obj.y = y;
obj.z = z;
return obj;
}
int hashCode(ejhash obj) {
int h = obj.x;
h = h * 31 + (int) (obj.y ^ (obj.y >> 32));
h = h * 31 + obj.z;
return h;
}
void testCollision2(long y1, int z1,long y2, int z2) {
ejhash o1 = constructor(1, y1, z1);
ejhash o2 = constructor(2, y2, z2);
if (hashCode(o1) == hashCode(o2)) {
printf("%s\n","Solved hash collision 2");
}
else{//change
printf("%s\n","Not equal");//change
}
} |
the_stack_data/25138835.c | /* $OpenBSD: main.c,v 1.1.1.1 2005/09/28 15:42:32 kurt Exp $ */
/*
* Copyright (c) 2005 Kurt Miller <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <dlfcn.h>
#include <stdio.h>
int
main()
{
int ret = 0;
int (*bbTest1)(void);
void *libbb = dlopen("libbb.so", RTLD_LAZY);
void *libaa = dlopen("libaa.so", RTLD_LAZY);
if (libbb == NULL) {
printf("dlopen(\"libbb.so\", RTLD_LAZY) FAILED\n");
return (1);
}
if (libaa == NULL) {
printf("dlopen(\"libaa.so\", RTLD_LAZY) FAILED\n");
return (1);
}
bbTest1 = dlsym(libbb, "bbTest1");
dlclose(libbb);
ret = (*bbTest1)();
dlclose(libaa);
return (ret);
}
|
the_stack_data/41165.c | // RUN: %clang_cc1 -triple=x86_64-unknown-linux -frandomize-layout-seed=1234567890abcded \
// RUN: -verify -fsyntax-only -Werror %s
// NOTE: The current seed (1234567890abcded) is specifically chosen because it
// uncovered a bug in diagnostics. With it the randomization of "t9" places the
// "a" element at the end of the record. When that happens, the clang complains
// about excessive initializers, which is confusing, because there aren't
// excessive initializers. It should instead complain about using a
// non-designated initializer on a raqndomized struct.
// Initializing a randomized structure requires a designated initializer,
// otherwise the element ordering will be off. The only exceptions to this rule
// are:
//
// - A structure with only one element, and
// - A structure initialized with "{0}".
//
// These are well-defined situations where the field ordering doesn't affect
// the result.
typedef void (*func_ptr)();
void foo(void);
void bar(void);
void baz(void);
void gaz(void);
struct test {
func_ptr a;
func_ptr b;
func_ptr c;
func_ptr d;
func_ptr e;
func_ptr f;
func_ptr g;
} __attribute__((randomize_layout));
struct test t1 = {}; // This should be fine per WG14 N2900 (in C23) + our extension handling of it in earlier modes
struct test t2 = { 0 }; // This should also be fine per C99 6.7.8p19
struct test t3 = { .f = baz, .b = bar, .g = gaz, .a = foo }; // Okay
struct test t4 = { .a = foo, bar, baz }; // expected-error {{a randomized struct can only be initialized with a designated initializer}}
struct other_test {
func_ptr a;
func_ptr b[3];
func_ptr c;
} __attribute__((randomize_layout));
struct other_test t5 = { .a = foo, .b[0] = foo }; // Okay
struct other_test t6 = { .a = foo, .b[0] = foo, bar, baz }; // Okay
struct other_test t7 = { .a = foo, .b = { foo, bar, baz } }; // Okay
struct other_test t8 = { baz, bar, gaz, foo }; // expected-error {{a randomized struct can only be initialized with a designated initializer}}
struct other_test t9 = { .a = foo, .b[0] = foo, bar, baz, gaz }; // expected-error {{a randomized struct can only be initialized with a designated initializer}}
struct empty_test {
} __attribute__((randomize_layout));
struct empty_test t10 = {}; // Okay
struct degen_test {
func_ptr a;
} __attribute__((randomize_layout));
struct degen_test t11 = { foo }; // Okay
struct static_assert_test {
int f;
_Static_assert(sizeof(int) == 4, "oh no!");
} __attribute__((randomize_layout));
struct static_assert_test t12 = { 42 }; // Okay
struct enum_decl_test {
enum e { BORK = 42, FORK = 9 } f;
} __attribute__((randomize_layout));
struct enum_decl_test t13 = { BORK }; // Okay
|
the_stack_data/66623.c | // PARAM: --set ana.activated[+] "'file'" --enable ana.file.optimistic
#include <stdio.h>
int main(){
FILE *fp[3];
// Array -> varinfo with index-offset
fp[1] = fopen("test.txt", "a");
fprintf(fp[1], "Testing...\n");
fclose(fp[1]);
struct foo {
int i;
FILE *fp;
} bar;
// Struct -> varinfo with field-offset
bar.fp = fopen("test.txt", "a");
fprintf(bar.fp, "Testing...\n");
fclose(bar.fp);
// Pointer -> Mem exp
*(fp+2) = fopen("test.txt", "a");
fprintf(*(fp+2), "Testing...\n");
fclose(*(fp+2));
}
// All ok!
|
the_stack_data/165765486.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int strstra(char *aa, char *bb) {
char *a, *b;
int i, j, k=0, pi, pj, kt=0;
if (strnlen(aa,255) < strnlen(bb,255)) {
a=aa;
b=bb;
} else {
a=bb;
b=aa;
}
for (i=strnlen(a,255)-1, j=0; j<strnlen(a, 255); j++){
if (a[i]==b[j])
for (pi=i, pj=j, k=0; pj>=0; pi--, pj--, k++)
if (a[pi]!= b[pj]) {
k=0;
break;
}
if (k>kt) kt=k;
}
for (i=0, j=strnlen(b, 255)-1; j>0; j--){
if (a[i]==b[j])
for (pi=i, pj=j, k=0; pj<strnlen(b,255); pi++, pj++, k++)
if (a[pi]!= b[pj]) {
k=0;
break;
}
if (k>kt) kt=k;
}
return kt;
}
int main() {
int n, k, kt, ktt, i, len, point;
char **a;
scanf("%d\n", &n);
a=(char**)malloc(n*sizeof(char*));
for (i=0, len=0;i<n;i++) {
a[i]=(char*)malloc(255*sizeof(char));
gets(a[i]);
len+=strnlen(a[i],255);
}
for (point=0, ktt=0; point<n-1; point++, ktt+=kt)
for (i=point+1, kt=0; i<n; i++) {
k=strstra(a[point], a[i]);
if (k>kt) kt=k;
}
for (i=0; i<n; i++) free (a[i]);
free (a);
printf("%d\n", len-ktt);
return 0;
} |
the_stack_data/420543.c | /*
* Author: Manuel
* Email: [email protected]
* Created: 2016-09-08 13:08:08
* @Last Modified by: Manuel
* @Last Modified time: 2016-09-08 13:26:14
*
* Description:
*/
#include <stdio.h>
#include <syscall.h>
int putchar(int character)
{
return fwrite((char*)&character, 1, 1, stdout);
} |
the_stack_data/9513459.c | int main(void){
int i;
for(i = 0; i < 10; i++){
print("Hola mundo");
}
}
|
the_stack_data/86365.c | // RUN: %ucc -fsyntax-only %s
struct A
{
int i;
} (a);
|
the_stack_data/22013794.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nmatushe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 08:08:31 by nmatushe #+# #+# */
/* Updated: 2016/11/29 09:21:10 by nmatushe ### ########.fr */
/* */
/* ************************************************************************** */
#include <string.h>
void *ft_memcpy(void *dest, const void *src, size_t n)
{
unsigned long i;
i = 0;
while (i < (unsigned long)n)
{
((unsigned char*)dest)[i] = ((unsigned char*)src)[i];
i++;
}
return (dest);
}
|
the_stack_data/935806.c | /* Minimal shell C source - (c) 1999, Spock (Oscar Portela Arjona) */
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#define chkerr(c,msg) if (c < 0) {perror("ERROR (" msg ")"); exit(-1);}
#define mvdesc(d1,d2) {close(d1); dup(d2); close(d2);}
#define redir(n,f) {close(n); chkerr(open(fv[n],f,0666),"open");}
#define size(v,s,u,n) {(v = realloc(v,s))[u] = n;}
#define l2 l1[vc]
#define l3 l2[p[0]]
int main(void) {
char ***l1 = NULL, *fv[3] ,dir[50] ,c;
int vc, bg, id, p[2], d;
signal(SIGINT, SIG_IGN); signal(SIGQUIT,SIG_IGN);
while (1) {
getcwd(dir,50); write(1,dir,strlen(dir)); write(1," $ ",d = bg = 3);
for (;bg; fv[bg] = NULL) realloc(fv[--bg],0); size(l1,4,0,NULL);
for (vc = p[0] = 0; read(0,&c,1) && (c != '\n');)
switch(c) {
case '<': d = 0; break;
case '>': d = 1; break;
case '|': if (l2) {vc++; p[0] = 0;} d = 3; break;
case '&': if (d < 3) d++; else bg = 1; break;
case ' ': if (d < 3) {if (fv[d]) d = 3;} else if (l2 && l3) p[0]++; break;
default: if (d < 3) {if (!fv[d]) size(fv[d],1,0,'\0');
size(fv[d],(id=strlen(fv[d]))+2,id,c); fv[d][id+1]='\0';}
else { if (!l2) {size(l1,vc*4+8,vc+1,NULL); size(l2,4,0,NULL);}
if (!l3) {size(l2,p[0]*4+8,p[0]+1,NULL); size(l3,1,0,'\0');}
size(l3,(id=strlen(l3))+2,id,c); l3[id+1] = '\0';}}
for (vc = 0; l2;) {
if (!vc) d = dup(0);
if (l1[vc+1]) chkerr(pipe(p),"pipe");
if (!strcmp(l2[0],"exit")) exit(0);
if (!strcmp(l2[0],"cd")) {if (chdir(l2[1]) < 0) chdir(getenv("HOME"));}
else {if (!(id = fork())) {
if (fv[0] && !vc) redir(0,O_RDONLY) else mvdesc(0,d);
if (fv[1]) redir(1,O_CREAT|O_WRONLY|O_TRUNC);
if (fv[2]) redir(2,O_CREAT|O_WRONLY|O_TRUNC);
if (l1[vc+1]) {mvdesc(1,p[1]); close(p[0]);}
if (!bg) {signal(SIGINT,SIG_DFL); signal(SIGQUIT,SIG_DFL);}
chkerr(execvp(l2[0],l2),"exec");}
if (!l1[vc+1] && !bg) while (wait(NULL) != id);}
for (id = 0; l2[id]; realloc(l2[id++],0)); realloc(l2,0);
close(d); if (l1[++vc]) {d = dup(p[0]); close(p[0]); close(p[1]);}}}} |
the_stack_data/167623.c | //
#include <stdio.h>
int main(){
float A,B,C,D,score;
printf("Enter thresholds for A, B, C, D\n");
printf("in that order, decreasing percentages > ");
scanf("%f%f%f%f",&A,&B,&C,&D);
printf("Thank you. Now enter student score (percent) > ");
scanf("%f",&score);
if(score >=A){
printf("Stdent has an A grade\n");
}
else if(score<A && score>=B)
{printf("Student has an B grade\n");
}
else if(score<B && score>=C){
printf("Student has an C grade\n");
}
else if(score<C && score>=D)
{printf("Student has an D grade\n");
}
else
{printf("Student has failed the course\n");
}
return 0;
}
|
the_stack_data/140165.c | /*************************************************************************
> File Name: ./main.c
> Author: ma6174
> Mail: [email protected]
> Created Time: Tue 30 Jul 2013 08:45:23 PM CST
************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define BUF_SIZE (4096*1)
int main(int argc, char* argv[])
{
FILE* fp1 = NULL;
char f_name[32] = {"aa.gif"};
char func_name[32] = {};
//char buf[BUF_SIZE] = {0};
char* pbuf = NULL;
int i = 0;
long int value = 0;
if(argc > 1)
strcpy(f_name, argv[1]);
printf("\n---------------------------[<%s>]---------------------------\n", f_name);
fp1 = fopen(f_name, "rb");
if(fp1 == NULL){
printf("open file [%s] error.", f_name);
return -1;
}
fseek(fp1, 0, SEEK_SET);
long int f_len = ftell(fp1);
fseek(fp1, 0, SEEK_END);
f_len = ftell(fp1) - f_len;
printf("==f_len=%ld\n", f_len);
rewind(fp1);
pbuf = (char*)malloc(f_len * sizeof(char));
fread(pbuf, 1, BUF_SIZE, fp1);
fclose(fp1);
fp1 = NULL;
snprintf(func_name, (size_t)(strstr(f_name, ".gif") - f_name + 1), "%s", f_name);
printf("app_%s = {", func_name);
for (i = 0; i < BUF_SIZE; i++){
if (pbuf[i] > 0x8b){
printf("0x%2x,=-= ", pbuf[i]);
value = pbuf[i];
pbuf[i] = value- 0xffffff00;
}
printf("0x%2x, ",(unsigned char) pbuf[i]);
if((i + 8)%16 == 0)
printf("\n");
}
printf("}\n\n");
free(pbuf);
return 0;
}
|
the_stack_data/93889012.c | // %%cpp spinlock.c
// %run gcc -fsanitize=thread -std=c11 spinlock.c -lpthread -o spinlock.exe
// %run ./spinlock.exe
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <string.h>
#include <pthread.h>
#include <errno.h>
#include <stdint.h>
#include <stdatomic.h>
// log_printf - макрос для отладочного вывода, добавляющий время со старта программы, имя функции и номер строки
uint64_t start_time_msec; void __attribute__ ((constructor)) start_time_setter() { struct timespec spec; clock_gettime(CLOCK_MONOTONIC, &spec); start_time_msec = spec.tv_sec * 1000L + spec.tv_nsec / 1000000; }
const char* log_prefix(const char* func, int line) {
struct timespec spec; clock_gettime(CLOCK_MONOTONIC, &spec); int delta_msec = spec.tv_sec * 1000L + spec.tv_nsec / 1000000 - start_time_msec;
const int max_func_len = 13; static __thread char prefix[100];
sprintf(prefix, "%d.%03d %*s():%-3d [tid=%ld]", delta_msec / 1000, delta_msec % 1000, max_func_len, func, line, syscall(__NR_gettid));
return prefix;
}
#define log_printf_impl(fmt, ...) { time_t t = time(0); dprintf(2, "%s: " fmt "%s", log_prefix(__FUNCTION__, __LINE__), __VA_ARGS__); }
// Format: <time_since_start> <func_name>:<line> : <custom_message>
#define log_printf(...) log_printf_impl(__VA_ARGS__, "")
#define fail_with_strerror(code, msg) do { char err_buf[1024]; strerror_r(code, err_buf, sizeof(err_buf));\
log_printf(msg " (From err code: %s)\n", err_buf); exit(EXIT_FAILURE);} while (0)
// thread-aware assert
#define ta_verify(stmt) do { if (stmt) break; fail_with_strerror(errno, "'" #stmt "' failed."); } while (0)
// verify pthread call
#define pt_verify(pthread_call) do { int code = (pthread_call); if (code == 0) break; \
fail_with_strerror(code, "'" #pthread_call "' failed."); } while (0)
//=============== Начало примера ======================
typedef enum {
VALID_STATE = 0,
INVALID_STATE = 1
} state_t;
_Atomic(int) lock = 0; // protects state
state_t current_state = VALID_STATE;
void sl_lock(_Atomic int* lock) {
int expected = 0;
// weak отличается от strong тем, что может выдавать иногда ложный false. Но он быстрее работает.
// atomic_compare_exchange_weak can change `expected`!
while (!atomic_compare_exchange_weak(lock, &expected, 1)) {
expected = 0;
}
}
void sl_unlock(_Atomic int* lock) {
atomic_fetch_sub(lock, 1);
}
// По сути та же функция, что и в предыдущем примере, но ипользуется spinlock вместо mutex
void thread_safe_func() {
// all function is critical section, protected by mutex
sl_lock(&lock); // try comment lock&unlock out and look at result
ta_verify(current_state == VALID_STATE);
current_state = INVALID_STATE; // do some work with state.
sched_yield(); // increase probability of fail of incorrect lock realisation
current_state = VALID_STATE;
sl_unlock(&lock);
}
// Возвращаемое значение потока (~код возврата процесса) -- любое машинное слово.
static void* thread_func(void* arg)
{
int i = (char*)arg - (char*)NULL;
log_printf(" Thread %d started\n", i);
for (int j = 0; j < 10000; ++j) {
thread_safe_func();
}
log_printf(" Thread %d finished\n", i);
return NULL;
}
int main()
{
log_printf("Main func started\n");
const int threads_count = 2;
pthread_t threads[threads_count];
for (int i = 0; i < threads_count; ++i) {
log_printf("Creating thread %d\n", i);
pt_verify(pthread_create(&threads[i], NULL, thread_func, (char*)NULL + i));
}
for (int i = 0; i < threads_count; ++i) {
pt_verify(pthread_join(threads[i], NULL));
log_printf("Thread %d joined\n", i);
}
log_printf("Main func finished\n");
return 0;
}
|
the_stack_data/11076551.c | #include <stdint.h>
/* On x86, division of one 64-bit integer by another cannot be
done with a single instruction or a short sequence. Thus, GCC
implements 64-bit division and remainder operations through
function calls. These functions are normally obtained from
libgcc, which is automatically included by GCC in any link
that it does.
Some x86-64 machines, however, have a compiler and utilities
that can generate 32-bit x86 code without having any of the
necessary libraries, including libgcc. Thus, we can make
Pintos work on these machines by simply implementing our own
64-bit division routines, which are the only routines from
libgcc that Pintos requires.
Completeness is another reason to include these routines. If
Pintos is completely self-contained, then that makes it that
much less mysterious. */
/* Uses x86 DIVL instruction to divide 64-bit N by 32-bit D to
yield a 32-bit quotient. Returns the quotient.
Traps with a divide error (#DE) if the quotient does not fit
in 32 bits. */
static inline uint32_t divl(uint64_t n, uint32_t d) {
uint32_t n1 = n >> 32;
uint32_t n0 = n;
uint32_t q, r;
asm("divl %4" : "=d"(r), "=a"(q) : "0"(n1), "1"(n0), "rm"(d));
return q;
}
/* Returns the number of leading zero bits in X,
which must be nonzero. */
static int nlz(uint32_t x) {
/* This technique is portable, but there are better ways to do
it on particular systems. With sufficiently new enough GCC,
you can use __builtin_clz() to take advantage of GCC's
knowledge of how to do it. Or you can use the x86 BSR
instruction directly. */
int n = 0;
if (x <= 0x0000FFFF) {
n += 16;
x <<= 16;
}
if (x <= 0x00FFFFFF) {
n += 8;
x <<= 8;
}
if (x <= 0x0FFFFFFF) {
n += 4;
x <<= 4;
}
if (x <= 0x3FFFFFFF) {
n += 2;
x <<= 2;
}
if (x <= 0x7FFFFFFF)
n++;
return n;
}
/* Divides unsigned 64-bit N by unsigned 64-bit D and returns the
quotient. */
static uint64_t udiv64(uint64_t n, uint64_t d) {
if ((d >> 32) == 0) {
/* Proof of correctness:
Let n, d, b, n1, and n0 be defined as in this function.
Let [x] be the "floor" of x. Let T = b[n1/d]. Assume d
nonzero. Then:
[n/d] = [n/d] - T + T
= [n/d - T] + T by (1) below
= [(b*n1 + n0)/d - T] + T by definition of n
= [(b*n1 + n0)/d - dT/d] + T
= [(b(n1 - d[n1/d]) + n0)/d] + T
= [(b[n1 % d] + n0)/d] + T, by definition of %
which is the expression calculated below.
(1) Note that for any real x, integer i: [x] + i = [x + i].
To prevent divl() from trapping, [(b[n1 % d] + n0)/d] must
be less than b. Assume that [n1 % d] and n0 take their
respective maximum values of d - 1 and b - 1:
[(b(d - 1) + (b - 1))/d] < b
<=> [(bd - 1)/d] < b
<=> [b - 1/d] < b
which is a tautology.
Therefore, this code is correct and will not trap. */
uint64_t b = 1ULL << 32;
uint32_t n1 = n >> 32;
uint32_t n0 = n;
uint32_t d0 = d;
return divl(b * (n1 % d0) + n0, d0) + b * (n1 / d0);
} else {
/* Based on the algorithm and proof available from
http://www.hackersdelight.org/revisions.pdf. */
if (n < d)
return 0;
else {
uint32_t d1 = d >> 32;
int s = nlz(d1);
uint64_t q = divl(n >> 1, (d << s) >> 32) >> (31 - s);
return n - (q - 1) * d < d ? q - 1 : q;
}
}
}
/* Divides unsigned 64-bit N by unsigned 64-bit D and returns the
remainder. */
static uint32_t umod64(uint64_t n, uint64_t d) { return n - d * udiv64(n, d); }
/* Divides signed 64-bit N by signed 64-bit D and returns the
quotient. */
static int64_t sdiv64(int64_t n, int64_t d) {
uint64_t n_abs = n >= 0 ? (uint64_t)n : -(uint64_t)n;
uint64_t d_abs = d >= 0 ? (uint64_t)d : -(uint64_t)d;
uint64_t q_abs = udiv64(n_abs, d_abs);
return (n < 0) == (d < 0) ? (int64_t)q_abs : -(int64_t)q_abs;
}
/* Divides signed 64-bit N by signed 64-bit D and returns the
remainder. */
static int32_t smod64(int64_t n, int64_t d) { return n - d * sdiv64(n, d); }
/* These are the routines that GCC calls. */
long long __divdi3(long long n, long long d);
long long __moddi3(long long n, long long d);
unsigned long long __udivdi3(unsigned long long n, unsigned long long d);
unsigned long long __umoddi3(unsigned long long n, unsigned long long d);
/* Signed 64-bit division. */
long long __divdi3(long long n, long long d) { return sdiv64(n, d); }
/* Signed 64-bit remainder. */
long long __moddi3(long long n, long long d) { return smod64(n, d); }
/* Unsigned 64-bit division. */
unsigned long long __udivdi3(unsigned long long n, unsigned long long d) { return udiv64(n, d); }
/* Unsigned 64-bit remainder. */
unsigned long long __umoddi3(unsigned long long n, unsigned long long d) { return umod64(n, d); }
|
the_stack_data/206393656.c | int gas;
int memory[];
int localmem[];
int test(int addr0, int addr1, int call_dsize, int call_v, int calldata0, int sha1) {
gas = 0;
int r10, r11, r12, r13, r14, r15, r18, r19, r28, r3, r5, r7, r9;
r10 = r11 = r12 = r13 = r14 = r15 = r18 = r19 = r28 = r3 = r5 = r7 = r9 = 0;
label1:
gas = gas + (30);
// UseMemory operations currently ignored
localmem[64] = 96;
r7 = call_dsize < 4 ? 1 : 0;
if (r7 != 0) {
goto label2;
} else {
goto label3;
}
label2:
gas = gas + (7);
return 0;
label3:
gas = gas + (45);
r5 = calldata0;
r10 = r5 / addr0;
r12 = (addr1 & r10);
r15 = 1691300792 == r12 ? 1 : 0;
if (r15 != 0) {
goto label4;
} else {
goto label12;
}
label4:
gas = gas + (19);
r5 = call_v == 0 ? 1 : 0;
if (r5 != 0) {
goto label5;
} else {
goto label11;
}
label5:
gas = gas + (27);
r3 = 0;
goto label6;
label6:
gas = gas + (84);
r9 = memory[0];
r14 = r3 < r9 ? 1 : 0;
r15 = r14 == 0 ? 1 : 0;
if (r15 != 0) {
goto label7;
} else {
goto label8;
}
label7:
gas = gas + (12);
return 0;
label8:
gas = gas + (84);
r11 = memory[0];
r13 = r3 < r11 ? 1 : 0;
r14 = r13 == 0 ? 1 : 0;
r15 = r14 == 0 ? 1 : 0;
if (r15 != 0) {
goto label9;
} else {
goto label10;
}
label9:
gas = gas + (149);
localmem[0] = 0;
r14 = sha1;
r18 = r3 + r14;
r19 = memory[r18];
gas = gas + (r19 == 0 ? 5000 : 20000);
// Refund gas ignored
memory[1] = r19;
r28 = 1 + r3;
r3 = r28;
goto label6;
label10:
return 0;
label11:
gas = gas + (6);
return 0;
label12:
gas = gas + (7);
return 0;
}
void main(int addr0, int addr1, int call_dsize, int call_v, int calldata0, int sha1) {
test(addr0, addr1, call_dsize, call_v, calldata0, sha1);
__VERIFIER_print_hull(gas);
return;
}
|
the_stack_data/1086847.c | #include <stdio.h>
void main () {
int A[100], B[100], temp[20], m, n, i, j, x = 0, flag, element;
scanf ("%d %d", &m, &n);
for (i = 0; i < m; i++)
scanf ("%d", A + i);
for (i = 0; i < n; i++)
scanf ("%d", B + i);
for (i = 0; i < m; i++) {
element = A[i];
flag = 0;
for (j = 0; j < x; j++)
if (temp[j] == element) {
flag = 1;
break;
}
if (flag == 1)
continue;
for (j = i + 1; j < m; j++)
if (A[j] == element) {
temp[x++] = element;
flag = 1;
break;
}
if (flag == 0)
for (j = 0; j < n; j++)
if (B[j] == element) {
temp[x++] = element;
break;
}
}
for (i = 0; i < n; i++) {
element = B[i];
flag = 0;
for (j = 0; j < x; j++)
if (temp[j] == element) {
flag = 1;
break;
}
if (flag == 1)
continue;
for (j = i + 1; j < n; j++)
if (B[j] == element) {
temp[x++] = element;
break;
}
}
for (i = 0; i < x; i++) {
for (j = 0; j < m; j++)
if (temp[i] == A[j])
printf ("%d ", A[j]);
for (j = 0; j < n; j++)
if (temp[i] == B[j])
printf ("%d ", B[j]);
}
for (i = 0; i < m; i++) {
flag = 0;
for (j = 0; j < x; j++)
if (temp[j] == A[i])
flag = 1;
if (flag == 0)
printf ("%d ", A[i]);
}
for (i = 0; i < n; i++) {
flag = 0;
for (j = 0; j < x; j++)
if (temp[j] == B[i])
flag = 1;
if (flag == 0)
printf ("%d ", B[i]);
}
}
|
the_stack_data/91410.c | // KASAN: use-after-free Read in tls_write_space
// https://syzkaller.appspot.com/bug?id=3ff26cb6000860a73428556d7df314541369c939
// status:dup
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <sched.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <linux/if_addr.h>
#include <linux/if_ether.h>
#include <linux/if_link.h>
#include <linux/if_tun.h>
#include <linux/in6.h>
#include <linux/ip.h>
#include <linux/neighbour.h>
#include <linux/net.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/tcp.h>
#include <linux/veth.h>
unsigned long long procid;
static void sleep_ms(uint64_t ms)
{
usleep(ms * 1000);
}
static uint64_t current_time_ms(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
exit(1);
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
static struct {
char* pos;
int nesting;
struct nlattr* nested[8];
char buf[1024];
} nlmsg;
static void netlink_init(int typ, int flags, const void* data, int size)
{
memset(&nlmsg, 0, sizeof(nlmsg));
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf;
hdr->nlmsg_type = typ;
hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags;
memcpy(hdr + 1, data, size);
nlmsg.pos = (char*)(hdr + 1) + NLMSG_ALIGN(size);
}
static void netlink_attr(int typ, const void* data, int size)
{
struct nlattr* attr = (struct nlattr*)nlmsg.pos;
attr->nla_len = sizeof(*attr) + size;
attr->nla_type = typ;
memcpy(attr + 1, data, size);
nlmsg.pos += NLMSG_ALIGN(attr->nla_len);
}
static void netlink_nest(int typ)
{
struct nlattr* attr = (struct nlattr*)nlmsg.pos;
attr->nla_type = typ;
nlmsg.pos += sizeof(*attr);
nlmsg.nested[nlmsg.nesting++] = attr;
}
static void netlink_done(void)
{
struct nlattr* attr = nlmsg.nested[--nlmsg.nesting];
attr->nla_len = nlmsg.pos - (char*)attr;
}
static int netlink_send(int sock)
{
if (nlmsg.pos > nlmsg.buf + sizeof(nlmsg.buf) || nlmsg.nesting)
exit(1);
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf;
hdr->nlmsg_len = nlmsg.pos - nlmsg.buf;
struct sockaddr_nl addr;
memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK;
unsigned n = sendto(sock, nlmsg.buf, hdr->nlmsg_len, 0,
(struct sockaddr*)&addr, sizeof(addr));
if (n != hdr->nlmsg_len)
exit(1);
n = recv(sock, nlmsg.buf, sizeof(nlmsg.buf), 0);
if (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr))
exit(1);
if (hdr->nlmsg_type != NLMSG_ERROR)
exit(1);
return -((struct nlmsgerr*)(hdr + 1))->error;
}
static void netlink_add_device_impl(const char* type, const char* name)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
netlink_init(RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr));
if (name)
netlink_attr(IFLA_IFNAME, name, strlen(name));
netlink_nest(IFLA_LINKINFO);
netlink_attr(IFLA_INFO_KIND, type, strlen(type));
}
static void netlink_add_device(int sock, const char* type, const char* name)
{
netlink_add_device_impl(type, name);
netlink_done();
int err = netlink_send(sock);
(void)err;
}
static void netlink_add_veth(int sock, const char* name, const char* peer)
{
netlink_add_device_impl("veth", name);
netlink_nest(IFLA_INFO_DATA);
netlink_nest(VETH_INFO_PEER);
nlmsg.pos += sizeof(struct ifinfomsg);
netlink_attr(IFLA_IFNAME, peer, strlen(peer));
netlink_done();
netlink_done();
netlink_done();
int err = netlink_send(sock);
(void)err;
}
static void netlink_add_hsr(int sock, const char* name, const char* slave1,
const char* slave2)
{
netlink_add_device_impl("hsr", name);
netlink_nest(IFLA_INFO_DATA);
int ifindex1 = if_nametoindex(slave1);
netlink_attr(IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1));
int ifindex2 = if_nametoindex(slave2);
netlink_attr(IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2));
netlink_done();
netlink_done();
int err = netlink_send(sock);
(void)err;
}
static void netlink_device_change(int sock, const char* name, bool up,
const char* master, const void* mac,
int macsize)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
if (up)
hdr.ifi_flags = hdr.ifi_change = IFF_UP;
netlink_init(RTM_NEWLINK, 0, &hdr, sizeof(hdr));
netlink_attr(IFLA_IFNAME, name, strlen(name));
if (master) {
int ifindex = if_nametoindex(master);
netlink_attr(IFLA_MASTER, &ifindex, sizeof(ifindex));
}
if (macsize)
netlink_attr(IFLA_ADDRESS, mac, macsize);
int err = netlink_send(sock);
(void)err;
}
static int netlink_add_addr(int sock, const char* dev, const void* addr,
int addrsize)
{
struct ifaddrmsg hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6;
hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120;
hdr.ifa_scope = RT_SCOPE_UNIVERSE;
hdr.ifa_index = if_nametoindex(dev);
netlink_init(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr, sizeof(hdr));
netlink_attr(IFA_LOCAL, addr, addrsize);
netlink_attr(IFA_ADDRESS, addr, addrsize);
return netlink_send(sock);
}
static void netlink_add_addr4(int sock, const char* dev, const char* addr)
{
struct in_addr in_addr;
inet_pton(AF_INET, addr, &in_addr);
int err = netlink_add_addr(sock, dev, &in_addr, sizeof(in_addr));
(void)err;
}
static void netlink_add_addr6(int sock, const char* dev, const char* addr)
{
struct in6_addr in6_addr;
inet_pton(AF_INET6, addr, &in6_addr);
int err = netlink_add_addr(sock, dev, &in6_addr, sizeof(in6_addr));
(void)err;
}
#define DEV_IPV4 "172.20.20.%d"
#define DEV_IPV6 "fe80::%02x"
#define DEV_MAC 0x00aaaaaaaaaa
static void initialize_netdevices(void)
{
char netdevsim[16];
sprintf(netdevsim, "netdevsim%d", (int)procid);
struct {
const char* type;
const char* dev;
} devtypes[] = {
{"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"},
{"vcan", "vcan0"}, {"bond", "bond0"},
{"team", "team0"}, {"dummy", "dummy0"},
{"nlmon", "nlmon0"}, {"caif", "caif0"},
{"batadv", "batadv0"}, {"vxcan", "vxcan1"},
{"netdevsim", netdevsim}, {"veth", 0},
};
const char* devmasters[] = {"bridge", "bond", "team"};
struct {
const char* name;
int macsize;
bool noipv6;
} devices[] = {
{"lo", ETH_ALEN},
{"sit0", 0},
{"bridge0", ETH_ALEN},
{"vcan0", 0, true},
{"tunl0", 0},
{"gre0", 0},
{"gretap0", ETH_ALEN},
{"ip_vti0", 0},
{"ip6_vti0", 0},
{"ip6tnl0", 0},
{"ip6gre0", 0},
{"ip6gretap0", ETH_ALEN},
{"erspan0", ETH_ALEN},
{"bond0", ETH_ALEN},
{"veth0", ETH_ALEN},
{"veth1", ETH_ALEN},
{"team0", ETH_ALEN},
{"veth0_to_bridge", ETH_ALEN},
{"veth1_to_bridge", ETH_ALEN},
{"veth0_to_bond", ETH_ALEN},
{"veth1_to_bond", ETH_ALEN},
{"veth0_to_team", ETH_ALEN},
{"veth1_to_team", ETH_ALEN},
{"veth0_to_hsr", ETH_ALEN},
{"veth1_to_hsr", ETH_ALEN},
{"hsr0", 0},
{"dummy0", ETH_ALEN},
{"nlmon0", 0},
{"vxcan1", 0, true},
{"caif0", ETH_ALEN},
{"batadv0", ETH_ALEN},
{netdevsim, ETH_ALEN},
};
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++)
netlink_add_device(sock, devtypes[i].type, devtypes[i].dev);
for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) {
char master[32], slave0[32], veth0[32], slave1[32], veth1[32];
sprintf(slave0, "%s_slave_0", devmasters[i]);
sprintf(veth0, "veth0_to_%s", devmasters[i]);
netlink_add_veth(sock, slave0, veth0);
sprintf(slave1, "%s_slave_1", devmasters[i]);
sprintf(veth1, "veth1_to_%s", devmasters[i]);
netlink_add_veth(sock, slave1, veth1);
sprintf(master, "%s0", devmasters[i]);
netlink_device_change(sock, slave0, false, master, 0, 0);
netlink_device_change(sock, slave1, false, master, 0, 0);
}
netlink_device_change(sock, "bridge_slave_0", true, 0, 0, 0);
netlink_device_change(sock, "bridge_slave_1", true, 0, 0, 0);
netlink_add_veth(sock, "hsr_slave_0", "veth0_to_hsr");
netlink_add_veth(sock, "hsr_slave_1", "veth1_to_hsr");
netlink_add_hsr(sock, "hsr0", "hsr_slave_0", "hsr_slave_1");
netlink_device_change(sock, "hsr_slave_0", true, 0, 0, 0);
netlink_device_change(sock, "hsr_slave_1", true, 0, 0, 0);
for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) {
char addr[32];
sprintf(addr, DEV_IPV4, i + 10);
netlink_add_addr4(sock, devices[i].name, addr);
if (!devices[i].noipv6) {
sprintf(addr, DEV_IPV6, i + 10);
netlink_add_addr6(sock, devices[i].name, addr);
}
uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40);
netlink_device_change(sock, devices[i].name, true, 0, &macaddr,
devices[i].macsize);
}
close(sock);
}
static void initialize_netdevices_init(void)
{
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
struct {
const char* type;
int macsize;
bool noipv6;
bool noup;
} devtypes[] = {
{"nr", 7, true}, {"rose", 5, true, true},
};
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) {
char dev[32], addr[32];
sprintf(dev, "%s%d", devtypes[i].type, (int)procid);
sprintf(addr, "172.30.%d.%d", i, (int)procid + 1);
netlink_add_addr4(sock, dev, addr);
if (!devtypes[i].noipv6) {
sprintf(addr, "fe88::%02x:%02x", i, (int)procid + 1);
netlink_add_addr6(sock, dev, addr);
}
int macsize = devtypes[i].macsize;
uint64_t macaddr = 0xbbbbbb +
((unsigned long long)i << (8 * (macsize - 2))) +
(procid << (8 * (macsize - 1)));
netlink_device_change(sock, dev, !devtypes[i].noup, 0, &macaddr, macsize);
}
close(sock);
}
static void setup_common()
{
if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
}
}
static void loop();
static void sandbox_common()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setsid();
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = (200 << 20);
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 32 << 20;
setrlimit(RLIMIT_MEMLOCK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 136 << 20;
setrlimit(RLIMIT_FSIZE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 0;
setrlimit(RLIMIT_CORE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 256;
setrlimit(RLIMIT_NOFILE, &rlim);
if (unshare(CLONE_NEWNS)) {
}
if (unshare(CLONE_NEWIPC)) {
}
if (unshare(0x02000000)) {
}
if (unshare(CLONE_NEWUTS)) {
}
if (unshare(CLONE_SYSVSEM)) {
}
typedef struct {
const char* name;
const char* value;
} sysctl_t;
static const sysctl_t sysctls[] = {
{"/proc/sys/kernel/shmmax", "16777216"},
{"/proc/sys/kernel/shmall", "536870912"},
{"/proc/sys/kernel/shmmni", "1024"},
{"/proc/sys/kernel/msgmax", "8192"},
{"/proc/sys/kernel/msgmni", "1024"},
{"/proc/sys/kernel/msgmnb", "1024"},
{"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
};
unsigned i;
for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
write_file(sysctls[i].name, sysctls[i].value);
}
int wait_for_loop(int pid)
{
if (pid < 0)
exit(1);
int status = 0;
while (waitpid(-1, &status, __WALL) != pid) {
}
return WEXITSTATUS(status);
}
static int do_sandbox_none(void)
{
if (unshare(CLONE_NEWPID)) {
}
int pid = fork();
if (pid != 0)
return wait_for_loop(pid);
setup_common();
sandbox_common();
initialize_netdevices_init();
if (unshare(CLONE_NEWNET)) {
}
initialize_netdevices();
loop();
exit(1);
}
static void kill_and_wait(int pid, int* status)
{
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
int i;
for (i = 0; i < 100; i++) {
if (waitpid(-1, status, WNOHANG | __WALL) == pid)
return;
usleep(1000);
}
DIR* dir = opendir("/sys/fs/fuse/connections");
if (dir) {
for (;;) {
struct dirent* ent = readdir(dir);
if (!ent)
break;
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
char abort[300];
snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
ent->d_name);
int fd = open(abort, O_WRONLY);
if (fd == -1) {
continue;
}
if (write(fd, abort, 1) < 0) {
}
close(fd);
}
closedir(dir);
} else {
}
while (waitpid(-1, status, __WALL) != pid) {
}
}
#define SYZ_HAVE_SETUP_TEST 1
static void setup_test()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
write_file("/proc/self/oom_score_adj", "1000");
}
#define SYZ_HAVE_CLOSE_FDS 1
static void close_fds()
{
int fd;
for (fd = 3; fd < 30; fd++)
close(fd);
}
static void execute_one(void);
#define WAIT_FLAGS __WALL
static void loop(void)
{
int iter;
for (iter = 0;; iter++) {
int pid = fork();
if (pid < 0)
exit(1);
if (pid == 0) {
setup_test();
execute_one();
close_fds();
exit(0);
}
int status = 0;
uint64_t start = current_time_ms();
for (;;) {
if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
break;
sleep_ms(1);
if (current_time_ms() - start < 5 * 1000)
continue;
kill_and_wait(pid, &status);
break;
}
}
}
uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff};
void execute_one(void)
{
intptr_t res = 0;
syscall(__NR_socket, 2, 2, 0x88);
res = syscall(__NR_socket, 0xa, 1, 0);
if (res != -1)
r[0] = res;
res = syscall(__NR_socket, 0xa, 1, 0);
if (res != -1)
r[1] = res;
*(uint16_t*)0x200000c0 = 0xa;
*(uint16_t*)0x200000c2 = htobe16(0x4e22);
*(uint32_t*)0x200000c4 = htobe32(0);
memcpy((void*)0x200000c8,
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000",
16);
*(uint32_t*)0x200000d8 = 0;
syscall(__NR_bind, r[1], 0x200000c0, 0x1c);
syscall(__NR_listen, r[1], 0);
*(uint16_t*)0x20000040 = 0xa;
*(uint16_t*)0x20000042 = htobe16(0x4e22);
*(uint32_t*)0x20000044 = htobe32(0);
*(uint64_t*)0x20000048 = htobe64(0);
*(uint64_t*)0x20000050 = htobe64(1);
*(uint32_t*)0x20000058 = 0;
syscall(__NR_sendto, r[0], 0, 0xfffffffffffffe21, 0x20004004, 0x20000040,
0x1c);
memcpy((void*)0x20000380, "tls\000", 4);
syscall(__NR_setsockopt, r[0], 6, 0x1f, 0x20000380, 0x11);
*(uint16_t*)0x20000080 = 0x303;
*(uint16_t*)0x20000082 = 0x34;
memcpy((void*)0x20000084, "\x88\x31\xa5\xaf\x44\xda\xf4\x90", 8);
memcpy((void*)0x2000008c, "\xbe\xfc\xe0\xed\x6c\x5b\x26\xfd\xb9\xd4\xea\xd5"
"\x0f\xc6\x0d\x90\x42\xdb\x17\xec\x78\x39\x77\x65"
"\x49\xa9\x7f\xad\xb3\x5e\x1d\x44",
32);
memcpy((void*)0x200000ac, "\x30\xcd\x88\xa2", 4);
memcpy((void*)0x200000b0, "\x28\x6b\xeb\xce\x03\xdc\xa7\x99", 8);
syscall(__NR_setsockopt, r[0], 0x11a, 1, 0x20000080, 0x38);
syscall(__NR_sendto, r[0], 0x200005c0, 0x51e5a7c80024e6ee, 0x40, 0, 0);
}
int main(void)
{
syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0);
for (procid = 0; procid < 6; procid++) {
if (fork() == 0) {
do_sandbox_none();
}
}
sleep(1000000);
return 0;
}
|
the_stack_data/1107736.c | #include <stdio.h>
#include <stdlib.h>
#define COUNT_ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
struct test_info_t
{
const char *func_name;
const char *file_name;
};
#define TEST_INIT {test_info->func_name = __func__; \
test_info->file_name = __FILE__; }
typedef int (*ptest_func)(struct test_info_t *test_info);
#define TEST_BROKEN (-1)
#define TEST_PASSED (0)
int test_1(struct test_info_t *test_info)
{
TEST_INIT;
//some code
return TEST_PASSED;
}
int test_2(struct test_info_t *test_info)
{
TEST_INIT;
int i = 0;
int ret;
ret = 0;
i = 2;
if( (i != 2) || (ret != 0) )
return TEST_BROKEN;
return TEST_PASSED;
}
ptest_func tests[] =
{
test_1,
test_2,
};
void run_tests(void)
{
struct test_info_t test_info;
unsigned int i;
for(i=0; i < COUNT_ELEMENTS(tests); ++i)
{
if( tests[i](&test_info) == TEST_BROKEN)
{
printf("test: %s in file: %s is broken\n", test_info.func_name, test_info.file_name);
exit(1);
}
}
printf("all test passed count tests = %ld\n", COUNT_ELEMENTS(tests));
}
int main(void)
{
run_tests();
return 0;
}
|
the_stack_data/57598.c | #include<math.h>
#include<stdio.h>
double f(double x)
{
return x*x+4*sin(x)+7;
}
main()
{
int n;
double x,dx;
scanf("%d %lf %lf",&n,&x,&dx);
while(n--)
{
printf("%lf %lf %lf\n",dx,(f(x+dx) - f(x)) / dx,(f(x+dx) - f(x- dx)) /(2 *dx));
dx/=2;
}
}
|
the_stack_data/71156.c | #include <stdint.h>
#include <stdbool.h>
uint8_t contents[10];
uint32_t front = 0;
uint32_t length = 0;
bool is_full(void) {
return length == 10;
}
bool is_empty(void) {
return length == 0;
}
bool dequeue(uint8_t *x) {
if (is_empty()) {
return false;
} else {
*x = contents[front];
front = (front + 1) % 10;
length--;
return true;
}
}
bool enqueue(const uint8_t x) {
if (is_full()) {
return false;
} else {
contents[(front + length) % 10] = x;
length++;
return true;
}
}
|
the_stack_data/56610.c | /* -----------------------------------------------------------------------------
*
* (c) The GHC Team, 2001
* Author: Sungwoo Park
*
* Lag/Drag/Void profiling.
*
* ---------------------------------------------------------------------------*/
#ifdef PROFILING
#include "PosixSource.h"
#include "Rts.h"
#include "Profiling.h"
#include "LdvProfile.h"
#include "Stats.h"
#include "RtsUtils.h"
#include "Schedule.h"
/* --------------------------------------------------------------------------
* This function is called eventually on every object destroyed during
* a garbage collection, whether it is a major garbage collection or
* not. If c is an 'inherently used' closure, nothing happens. If c
* is an ordinary closure, LDV_recordDead() is called on c with its
* proper size which excludes the profiling header portion in the
* closure. Returns the size of the closure, including the profiling
* header portion, so that the caller can find the next closure.
* ----------------------------------------------------------------------- */
STATIC_INLINE nat
processHeapClosureForDead( StgClosure *c )
{
nat size;
const StgInfoTable *info;
info = get_itbl(c);
info = c->header.info;
if (IS_FORWARDING_PTR(info)) {
// The size of the evacuated closure is currently stored in
// the LDV field. See SET_EVACUAEE_FOR_LDV() in
// includes/StgLdvProf.h.
return LDVW(c);
}
info = INFO_PTR_TO_STRUCT(info);
ASSERT(((LDVW(c) & LDV_CREATE_MASK) >> LDV_SHIFT) <= era &&
((LDVW(c) & LDV_CREATE_MASK) >> LDV_SHIFT) > 0);
ASSERT(((LDVW(c) & LDV_STATE_MASK) == LDV_STATE_CREATE) ||
(
(LDVW(c) & LDV_LAST_MASK) <= era &&
(LDVW(c) & LDV_LAST_MASK) > 0
));
size = closure_sizeW(c);
switch (info->type) {
/*
'inherently used' cases: do nothing.
*/
case TSO:
case STACK:
case MVAR_CLEAN:
case MVAR_DIRTY:
case TVAR:
case MUT_ARR_PTRS_CLEAN:
case MUT_ARR_PTRS_DIRTY:
case MUT_ARR_PTRS_FROZEN:
case MUT_ARR_PTRS_FROZEN0:
case ARR_WORDS:
case WEAK:
case MUT_VAR_CLEAN:
case MUT_VAR_DIRTY:
case BCO:
case PRIM:
case MUT_PRIM:
case TREC_CHUNK:
return size;
/*
ordinary cases: call LDV_recordDead().
*/
case THUNK:
case THUNK_1_0:
case THUNK_0_1:
case THUNK_SELECTOR:
case THUNK_2_0:
case THUNK_1_1:
case THUNK_0_2:
case AP:
case PAP:
case AP_STACK:
case CONSTR:
case CONSTR_1_0:
case CONSTR_0_1:
case CONSTR_2_0:
case CONSTR_1_1:
case CONSTR_0_2:
case FUN:
case FUN_1_0:
case FUN_0_1:
case FUN_2_0:
case FUN_1_1:
case FUN_0_2:
case BLACKHOLE:
case BLOCKING_QUEUE:
case IND_PERM:
/*
'Ingore' cases
*/
// Why can we ignore IND closures? We assume that
// any census is preceded by a major garbage collection, which
// IND closures cannot survive. Therefore, it is no
// use considering IND closures in the meanwhile
// because they will perish before the next census at any
// rate.
case IND:
// Found a dead closure: record its size
LDV_recordDead(c, size);
return size;
/*
Error case
*/
// static objects
case IND_STATIC:
case CONSTR_STATIC:
case FUN_STATIC:
case THUNK_STATIC:
case CONSTR_NOCAF_STATIC:
// stack objects
case UPDATE_FRAME:
case CATCH_FRAME:
case UNDERFLOW_FRAME:
case STOP_FRAME:
case RET_BCO:
case RET_SMALL:
case RET_BIG:
// others
case INVALID_OBJECT:
default:
barf("Invalid object in processHeapClosureForDead(): %d", info->type);
return 0;
}
}
/* --------------------------------------------------------------------------
* Calls processHeapClosureForDead() on every *dead* closures in the
* heap blocks starting at bd.
* ----------------------------------------------------------------------- */
static void
processHeapForDead( bdescr *bd )
{
StgPtr p;
while (bd != NULL) {
p = bd->start;
while (p < bd->free) {
p += processHeapClosureForDead((StgClosure *)p);
while (p < bd->free && !*p) // skip slop
p++;
}
ASSERT(p == bd->free);
bd = bd->link;
}
}
/* --------------------------------------------------------------------------
* Calls processHeapClosureForDead() on every *dead* closures in the nursery.
* ----------------------------------------------------------------------- */
static void
processNurseryForDead( void )
{
StgPtr p, bdLimit;
bdescr *bd;
bd = MainCapability.r.rNursery->blocks;
while (bd->start < bd->free) {
p = bd->start;
bdLimit = bd->start + BLOCK_SIZE_W;
while (p < bd->free && p < bdLimit) {
p += processHeapClosureForDead((StgClosure *)p);
while (p < bd->free && p < bdLimit && !*p) // skip slop
p++;
}
bd = bd->link;
if (bd == NULL)
break;
}
}
/* --------------------------------------------------------------------------
* Calls processHeapClosureForDead() on every *dead* closures in the closure
* chain.
* ----------------------------------------------------------------------- */
static void
processChainForDead( bdescr *bd )
{
// Any object still in the chain is dead!
while (bd != NULL) {
if (!(bd->flags & BF_PINNED)) {
processHeapClosureForDead((StgClosure *)bd->start);
}
bd = bd->link;
}
}
/* --------------------------------------------------------------------------
* Start a census for *dead* closures, and calls
* processHeapClosureForDead() on every closure which died in the
* current garbage collection. This function is called from a garbage
* collector right before tidying up, when all dead closures are still
* stored in the heap and easy to identify. Generations 0 through N
* have just been garbage collected.
* ----------------------------------------------------------------------- */
void
LdvCensusForDead( nat N )
{
nat g;
// ldvTime == 0 means that LDV profiling is currently turned off.
if (era == 0)
return;
if (RtsFlags.GcFlags.generations == 1) {
//
// Todo: support LDV for two-space garbage collection.
//
barf("Lag/Drag/Void profiling not supported with -G1");
} else {
processNurseryForDead();
for (g = 0; g <= N; g++) {
processHeapForDead(generations[g].old_blocks);
processChainForDead(generations[g].large_objects);
}
}
}
/* --------------------------------------------------------------------------
* Regard any closure in the current heap as dead or moribund and update
* LDV statistics accordingly.
* Called from shutdownHaskell() in RtsStartup.c.
* Also, stops LDV profiling by resetting ldvTime to 0.
* ----------------------------------------------------------------------- */
void
LdvCensusKillAll( void )
{
LdvCensusForDead(RtsFlags.GcFlags.generations - 1);
}
#endif /* PROFILING */
|
the_stack_data/697522.c | #include <stdio.h>
#include <stdlib.h>
void main()
{
int *a;
while(1)
a=(int *)malloc(sizeof(int));
int i = 0;
while(i<100000)
i++;
}
|
the_stack_data/984280.c | #include <assert.h>
int main()
{
int x = 1;
int y = 0;
while(y < 10 && __VERIFIER_nondet_int())
{
x = x + y;
y = y + 1;
}
assert(x == y);
return 0;
}
|
the_stack_data/90798.c | #include <stdio.h>
int str_toi(const char *ptr);
long str_tol(const char *ptr);
double str_tof(const char *ptr);
int main(void) {
char str[128];
printf("请输入字符串:"); scanf("%s", str);
printf("转换为整数为:%d\n", str_toi(str));
printf("转换为长整数为:%ld\n", str_tol(str));
printf("请输入字符串:"); scanf("%s", str);
printf("转换为浮点型为:%f", str_tof(str));
return 0;
}
int str_toi(const char *ptr) {
int num = 0;
while (*ptr) {
if (*ptr >= '0' && *ptr <= '9')
num = num * 10 + (*ptr - '0');
ptr++;
}
return num;
}
long str_tol(const char *ptr) {
long num = 0;
while (*ptr) {
if (*ptr >= '0' && *ptr <= '9')
num = num * 10 + (*ptr - '0');
ptr++;
}
return num;
}
double str_tof(const char *ptr) {
int integer = 0;
double decimal = 0;
while (*ptr) {
if (*ptr >= '0' && *ptr <= '9') {
integer = integer * 10 + (*ptr - '0');
}
if (*ptr == '.') {
ptr++;
break;
}
ptr++;
}
double i = 0.1;
while (*ptr) {
if (*ptr >= '0' && *ptr <= '9') {
decimal += i * (*ptr - '0');
i /= 10;
}
ptr++;
}
return (integer + decimal);
}
/*
请输入字符串:12345
转换为整数为:12345
转换为长整数为:12345
请输入字符串:12345.12345
转换为浮点型为:12345.123450
*/ |
the_stack_data/93943.c | /*
* Copyright (C) 2012-2014 NXP Semiconductors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifdef NXP_HW_SELF_TEST
#include "linux_nfc_factory_api.h"
#include "phNxpNciHal_SelfTest.h"
#include "nfa_api.h"
/*******************************************************************************
**
** Function nfcFactory_testMode_open
**
** Description It opens the physical connection with NFCC and
** creates required client thread for operation.
**
** Returns 0 if successful,otherwise failed.
**
*******************************************************************************/
int nfcFactory_testMode_open (void)
{
return phNxpNciHal_TestMode_open();
}
/*******************************************************************************
**
** Function nfcFactory_testMode_close
**
** Description This function close the NFCC interface and free all
** resources.
**
** Returns None.
**
*******************************************************************************/
void nfcFactory_testMode_close (void)
{
return phNxpNciHal_TestMode_close();
}
/*******************************************************************************
**
** Function nfcFactory_PrbsTestStart
**
** Description Test function start RF generation for RF technology and bit
** rate. RF technology and bit rate are sent as parameter to
** the API.
**
** Returns 0 if RF generation successful,
** otherwise failed.
**
*******************************************************************************/
int nfcFactory_PrbsTestStart (nfcFactory_PRBSTech_t tech, nfcFactory_PRBSBitrate_t bitrate)
{
return phNxpNciHal_PrbsTestStart(NFC_HW_PRBS, NFC_HW_PRBS15, tech, bitrate);
}
/*******************************************************************************
**
** Function nfcFactory_PrbsTestStop
**
** Description Test function stop RF generation for RF technology started
** by phNxpNciHal_PrbsTestStart.
**
** Returns 0 if operation successful,
** otherwise failed.
**
*******************************************************************************/
int nfcFactory_PrbsTestStop ()
{
return phNxpNciHal_PrbsTestStop();
}
/*******************************************************************************
**
** Function nfcFactory_AntennaSelfTest
**
** Description Test function to validate the Antenna's discrete
** components connection.
**
** Returns 0 if successful,otherwise failed.
**
*******************************************************************************/
int nfcFactory_AntennaSelfTest(nfcFactory_Antenna_St_Resp_t * phAntenna_St_Resp )
{
return phNxpNciHal_AntennaSelfTest(
(phAntenna_St_Resp_t *) phAntenna_St_Resp);
}
/*******************************************************************************
**
** Function nfcFactory_GetMwVersion
**
** Description Test function to return Mw version.
**
** Returns Mw version of stack.
**
*******************************************************************************/
int nfcFactory_GetMwVersion ()
{
tNFA_MW_VERSION mwVer = {0};
mwVer = NFA_GetMwVersion();
return ((mwVer.android_version & 0xFF ) << 16) | ((mwVer.major_version & 0xFF ) << 8) | (mwVer.minor_version & 0xFF);
}
#endif
|
the_stack_data/75139100.c | /* ISC license */
#include <stdlib.h>
int main() { return !malloc(0) ; }
|
the_stack_data/132954389.c | #include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
int main(int argc, char** argv){
if(argc < 2){
perror("Se necesita un comando como argumento.\n");
return -1;
}
int fd = open("tuberia3", O_WRONLY);
if(fd == -1){
perror("Error abriendo tubería.\n");
return -1;
}
write(fd, argv[1], strlen(argv[1])+1);
close(fd);
return 0;
}
|
the_stack_data/135738.c | /*
C++ changes caller's args: reference parameters
C changes caller's args: pointer parameters
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int die( const char * msg );
void minimum( double * a, double * b );
void minMax( double * min, double * max, double a, double b );
int main(){
double x=7, y=3;
double * p = &x;
printf( "%f\n", *&*&*p );
minimum( &x, &y );
printf( "x y == %f %f\n", x, y );
double smaller, larger;
x = 10, y = -10;
minMax( &smaller, &larger, x, y );
printf( "smaller is %f, larger is %f\n", smaller, larger );
} // main
int die( const char * msg ){
printf( "Fatal error: %s\n", msg );
exit( EXIT_FAILURE );
} // die
void minimum( double * a, double * b ){
if( *a < *b ) *a = 0;
else *b = 0;
} // minimum
void minMax( double * min, double * max, double a, double b ){
if( a < b ){
*min = a;
*max = b;
}else{
*min = b;
*max = a;
}
} |
the_stack_data/573214.c | const int size = 100;
int main () {
int i,j,k;
int a[size][size][size];
l300:
for (i=0; i<size ;i++) {
for (j=0; j<size ;j++) {
for (k=0; k<size ;k++) {
a[i][j][k] = 2;
}
}
}
return 0;
}
|
the_stack_data/75138288.c | #define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
int myfoo(int argc, char **argv);
int main() {
char* argv[3];
char* name = "myfoo";
size_t dummy;
FILE * fp = fopen ("testcase", "r");
if (!fp) {
fprintf (stderr, "Could not find a testfile\n");
exit(1);
}
argv[0] = name;
argv[1] = NULL;
argv[2] = NULL;
getline(&(argv[1]), &dummy, fp);
getline(&(argv[2]), &dummy, fp);
return (myfoo(3, argv));
}
|
the_stack_data/200142467.c | // RUN: %libomptarget-compile-generic -fopenmp-version=51
// RUN: %libomptarget-run-generic 2>&1 \
// RUN: | %fcheck-generic
#include <stdio.h>
// The runtime considers unified shared memory to be always present.
#pragma omp requires unified_shared_memory
int main() {
int i;
// CHECK-NOT: Libomptarget
#pragma omp target data map(alloc: i)
#pragma omp target map(present, alloc: i)
;
// CHECK: i is present
fprintf(stderr, "i is present\n");
// CHECK-NOT: Libomptarget
#pragma omp target map(present, alloc: i)
;
// CHECK: is present
fprintf(stderr, "i is present\n");
return 0;
}
|
the_stack_data/45449757.c | /*
* File name: counting_sort.c
* Author: Jacob Hunt
* Author email: [email protected]
* License: MIT https://opensource.org/licenses/MIT
* (full text at end of file)
*
* Notes:
* Implimentation of a Counting Sort algorithm,
* sorts an array of positive ints in linear
* time of O(n + k).
*
*/
// * * * LIBRARIES * * * //
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// * * * CONSTANT DEFINITIONS * * * //
// Length of randomly generated array
#define LENGTH 10
// Upper limit for randomly generated numbers
#define RANGE 256
// * * * FUNCTION PROTOTYPES * * * //
void sort(int values[], int arraySize, int limit);
void randomize(int *arr, int arrlen, int range);
void printarr(int *arr, int arrlen);
// * * * MAIN FUNCTION * * * //
int main(void){
/* Demonstrate algorithm */
// Seed the pseudo-random number generator
srand(time(NULL));
// Introduce the program
printf("\n\n");
printf("* * * THE AMAZING MAGIC SORTING ALGORITHM * * *\n\n");
// Generate and print an array of random ints
int numbers[LENGTH];
randomize(numbers, LENGTH, RANGE);
printf("An array of random integers:\n");
printarr(numbers, LENGTH);
printf("\n");
// Sort the array
sort(numbers, LENGTH, RANGE);
printf("Putting it in the magic hat, tapping three times...\n\n");
// Print results
printf("The numbers are sorted!\n");
printarr(numbers, LENGTH);
printf("\nAnd now the world is a better place.\n\n\n");
return 0;
}
// * * * SORTING ALGORITHM * * * //
void sort(int values[], int arrlen, int range){
/* Implimentation of counting sort,
see https://en.wikipedia.org/wiki/Counting_sort */
// Array for counting values
int countarray[range];
// Set all values in countarray to 0
for (int i = 0; i < range; i++){
countarray[i] = 0;
}
// Count numbers in values[]
for (int i = 0; i < arrlen; i++){
countarray[values[i]] ++;
}
// Counter to keep track of algorithm's current position in values[]
int valuesPos = 0;
// put numbers back in values array in order
for (int i = 0; i < range; i++){
if (countarray[i] != 0){
for (int j = 0; j < countarray[i]; j++){
values[valuesPos] = i;
valuesPos ++;
}
}
}
}
// * * * HELPER FUNCTIONS * * * //
void randomize(int *arr, int arrlen, int range){
/* Fill array "arr" of length "arrlen" with random ints between 0
and "range" */
for(int i = 0; i < arrlen; i++)
{
arr[i] = rand() % range;
}
}
void printarr(int *arr, int arrlen){
/* Print array of ints "arr" of length "arrlen" */
printf("[");
for(int i = 0; i < arrlen - 1; i++){
printf("%i, ", arr[i]);
}
printf("%i]\n", arr[arrlen - 1]);
}
/*
*
* Copyright 2017 Jacob Hunt
*
* 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.
*
*/
|
the_stack_data/937555.c | #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
// * : asterisk
// & : address-of operator
// * : re-direction or de-referencing
return 0;
}
|
the_stack_data/181392741.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nmanzini <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/20 21:15:50 by nmanzini #+# #+# */
/* Updated: 2017/11/20 21:17:57 by nmanzini ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isascii(int c)
{
if (c >= 0 && c <= 127)
return (1);
else
return (0);
}
|
the_stack_data/92328616.c | /* ==========================================================================
* kpoll.c - Brew of Linux epoll, BSD kqueue, and Solaris Ports.
* --------------------------------------------------------------------------
* Copyright (c) 2012 William Ahern
*
* 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.
* ==========================================================================
*/
#include <stddef.h> /* NULL offsetof */
#include <string.h> /* memset(3) */
#include <time.h> /* struct timespec */
#include <errno.h> /* errno */
#include <poll.h> /* POLLIN POLLOUT */
#include <unistd.h> /* [FEATURES] read(2) write(2) */
#ifndef __GLIBC_PREREQ
#define __GLIBC_PREREQ(m, n) 0
#endif
#ifndef HAVE_KQUEUE
#define HAVE_KQUEUE (__FreeBSD__ || __NetBSD__ || __OpenBSD__ || __APPLE__)
#endif
#ifndef HAVE_EPOLL
#define HAVE_EPOLL (__linux__)
#endif
#ifndef HAVE_PORTS
#define HAVE_PORTS (__sun)
#endif
#ifndef HAVE_EPOLL_CREATE1
#define HAVE_EPOLL_CREATE1 (HAVE_EPOLL && __GLIBC_PREREQ(2, 9))
#endif
#ifndef HAVE_PIPE2
#define HAVE_PIPE2 __GLIBC_PREREQ(2, 9)
#endif
#if HAVE_EPOLL
#include <sys/epoll.h> /* struct epoll_event epoll_create(2) epoll_ctl(2) epoll_wait(2) */
#elif HAVE_PORTS
#include <port.h> /* PORT_SOURCE_FD port_associate(2) port_disassociate(2) port_getn(2) port_alert(2) */
#else
#include <sys/event.h> /* EVFILT_READ EVFILT_WRITE EV_SET EV_ADD EV_DELETE struct kevent kqueue(2) kevent(2) */
#endif
#include <sys/queue.h> /* LIST_ENTRY LIST_HEAD LIST_REMOVE LIST_INSERT_HEAD */
#include <fcntl.h> /* F_GETFL F_SETFL F_GETFD F_SETFD FD_CLOEXEC O_NONBLOCK O_CLOEXEC fcntl(2) */
#define KPOLL_MAXWAIT 32
#define countof(a) (sizeof (a) / sizeof *(a))
#if __GNUC__ >= 3
#define unlikely(expr) __builtin_expect((expr), 0)
#else
#define unlikely(expr) (expr)
#endif
static int setnonblock(int fd) {
int flags;
if (-1 == (flags = fcntl(fd, F_GETFL)))
return errno;
if (!(flags & O_NONBLOCK)) {
if (-1 == fcntl(fd, F_SETFL, (flags | O_NONBLOCK)))
return errno;
}
return 0;
} /* setnonblock() */
static int setcloexec(int fd) {
int flags;
if (-1 == (flags = fcntl(fd, F_GETFD)))
return errno;
if (!(flags & FD_CLOEXEC)) {
if (-1 == fcntl(fd, F_SETFD, (flags | FD_CLOEXEC)))
return errno;
}
return 0;
} /* setcloexec() */
static void closefd(int *fd) {
if (*fd >= 0) {
while (0 != close(*fd) && errno == EINTR)
;;
*fd = -1;
}
} /* closefd() */
#if HAVE_EPOLL
typedef struct epoll_event event_t;
#elif HAVE_PORTS
typedef port_event_t event_t;
#else
/* NetBSD uses intptr_t while others use void * for .udata */
#define EV_SETx(ev, a, b, c, d, e, f) EV_SET((ev), (a), (b), (c), (d), (e), ((__typeof__((ev)->udata))(f)))
typedef struct kevent event_t;
#endif
static inline void *event_udata(const event_t *event) {
#if HAVE_EPOLL
return event->data.ptr;
#elif HAVE_PORTS
return event->portev_user;
#else
return (void *)event->udata;
#endif
} /* event_udata() */
static inline short event_pending(const event_t *event) {
#if HAVE_EPOLL
return event->events;
#elif HAVE_PORTS
return event->portev_events;
#else
return (event->filter == EVFILT_READ)? POLLIN : (event->filter == EVFILT_WRITE)? POLLOUT : 0;
#endif
} /* event_pending() */
struct kpollfd {
int fd;
short events;
short revents;
LIST_ENTRY(kpollfd) le;
}; /* struct kpollfd */
struct kpoll {
int fd;
LIST_HEAD(, kpollfd) pending;
LIST_HEAD(, kpollfd) polling;
LIST_HEAD(, kpollfd) dormant;
struct {
struct kpollfd event;
int fd[2];
} alert;
}; /* struct kpoll */
static void kpoll_move(struct kpoll *kp, struct kpollfd *fd) {
LIST_REMOVE(fd, le);
if (fd->revents)
LIST_INSERT_HEAD(&kp->pending, fd, le);
else if (fd->events)
LIST_INSERT_HEAD(&kp->polling, fd, le);
else
LIST_INSERT_HEAD(&kp->dormant, fd, le);
} /* kpoll_move() */
static struct kpollfd *kpoll_next(struct kpoll *kp) {
return LIST_FIRST(&kp->pending);
} /* kpoll_next() */
static int kpoll_ctl(struct kpoll *kp, struct kpollfd *fd, short events) {
int error = 0;
if (fd->events == events)
goto reset;
#if HAVE_EPOLL
struct epoll_event event;
int op;
op = (!fd->events)? EPOLL_CTL_ADD : (!events)? EPOLL_CTL_DEL : EPOLL_CTL_MOD;
memset(&event, 0, sizeof event);
event.events = events;
event.data.ptr = fd;
if (0 != epoll_ctl(kp->fd, op, fd->fd, &event))
goto error;
fd->events = events;
#elif HAVE_PORTS
if (!events) {
if (0 != port_dissociate(kp->fd, PORT_SOURCE_FD, fd->fd))
goto error;
} else {
if (0 != port_associate(kp->fd, PORT_SOURCE_FD, fd->fd, events, fd))
goto error;
}
fd->events = events;
#else
struct kevent event;
if (events & POLLIN) {
if (!(fd->events & POLLIN)) {
EV_SETx(&event, fd->fd, EVFILT_READ, EV_ADD, 0, 0, fd);
if (0 != kevent(kp->fd, &event, 1, NULL, 0, &(struct timespec){ 0, 0 }))
goto error;
fd->events |= POLLIN;
}
} else if (fd->events & POLLIN) {
EV_SETx(&event, fd->fd, EVFILT_READ, EV_DELETE, 0, 0, NULL);
if (0 != kevent(kp->fd, &event, 1, NULL, 0, &(struct timespec){ 0, 0 }))
goto error;
fd->events &= ~POLLIN;
}
if (events & POLLOUT) {
if (!(fd->events & POLLOUT)) {
EV_SETx(&event, fd->fd, EVFILT_WRITE, EV_ADD, 0, 0, fd);
if (0 != kevent(kp->fd, &event, 1, NULL, 0, &(struct timespec){ 0, 0 }))
goto error;
fd->events |= POLLOUT;
}
} else if (fd->events & POLLOUT) {
EV_SETx(&event, fd->fd, EVFILT_WRITE, EV_DELETE, 0, 0, NULL);
if (0 != kevent(kp->fd, &event, 1, NULL, 0, &(struct timespec){ 0, 0 }))
goto error;
fd->events &= ~POLLOUT;
}
#endif
reset:
fd->revents = 0;
kpoll_move(kp, fd);
return error;
error:
error = errno;
goto reset;
} /* kpoll_ctl() */
static void kpoll_add(struct kpoll *kp, struct kpollfd *pfd, int fd) {
pfd->fd = fd;
pfd->events = 0;
pfd->revents = 0;
LIST_INSERT_HEAD(&kp->dormant, pfd, le);
} /* kpoll_add() */
static void kpoll_del(struct kpoll *kp, struct kpollfd *fd) {
kpoll_ctl(kp, fd, 0);
LIST_REMOVE(fd, le);
} /* kpoll_del() */
static int kpoll_alert(struct kpoll *kp) {
#if HAVE_PORTS
return (!port_alert(kp->fd, PORT_ALERT_SET, POLLIN, &kp->alert.event))? 0 : errno;
#else
while (1 != write(kp->alert.fd[1], "!", 1)) {
switch (errno) {
case EINTR:
continue;
case EAGAIN:
return 0;
default:
return errno;
}
}
return kpoll_ctl(kp, &kp->alert.event, POLLIN);
#endif
} /* kpoll_alert() */
static int kpoll_calm(struct kpoll *kp) {
#if HAVE_PORTS
return (!port_alert(kp->fd, PORT_ALERT_SET, 0, &kp->alert.event))? 0 : errno;
#else
char buf[512];
while (read(kp->alert.fd[0], buf, sizeof buf) > 0)
;;
return kpoll_ctl(kp, &kp->alert.event, POLLIN);
#endif
} /* kpoll_calm() */
static inline struct timespec *ms2ts_(struct timespec *ts, int ms) {
if (ms < 0) return 0;
ts->tv_sec = ms / 1000;
ts->tv_nsec = (ms % 1000) * 1000000;
return ts;
} /* ms2ts_() */
#define ms2ts(ms) (ms2ts_(&(struct timespec){ 0, 0 }, (ms)))
static int kpoll_wait(struct kpoll *kp, int timeout) {
event_t event[KPOLL_MAXWAIT];
struct kpollfd *fd;
int error;
if (!LIST_EMPTY(&kp->pending))
return 0;
#if HAVE_EPOLL
int i, n;
if (-1 == (n = epoll_wait(kp->fd, event, (int)countof(event), timeout)))
return (errno == EINTR)? 0 : errno;
#elif HAVE_PORTS
uint_t i, n = 1;
if (0 != port_getn(kp->fd, event, countof(event), &n, ms2ts(timeout)))
return (errno == ETIME || errno == EINTR)? 0 : errno;
#else
int i, n;
if (-1 == (n = kevent(kp->fd, NULL, 0, event, (int)countof(event), ms2ts(timeout))))
return (errno == EINTR)? 0 : errno;
#endif
for (i = 0; i < n; i++) {
fd = event_udata(&event[i]);
#if HAVE_PORTS
fd->events = 0;
#endif
if (unlikely(fd == &kp->alert.event)) {
if ((error = kpoll_calm(kp)))
return error;
} else {
fd->revents |= event_pending(&event[i]);
kpoll_move(kp, fd);
}
}
return 0;
} /* kpoll_wait() */
static int alert_init(struct kpoll *kp) {
#if HAVE_PORTS
return 0;
#else
int error;
#if HAVE_PIPE2
if (0 != pipe2(kp->alert.fd, O_CLOEXEC|O_NONBLOCK))
return errno;
#else
if (0 != pipe(kp->alert.fd))
return errno;
for (int i = 0; i < 2; i++) {
if ((error = setcloexec(kp->alert.fd[i]))
|| (error = setnonblock(kp->alert.fd[i])))
return error;
}
#endif
kpoll_add(kp, &kp->alert.event, kp->alert.fd[0]);
return kpoll_ctl(kp, &kp->alert.event, POLLIN);
#endif
} /* alert_init() */
static void alert_destroy(struct kpoll *kp) {
#if HAVE_PORTS
(void)0;
#else
closefd(&kp->alert.fd[0]);
closefd(&kp->alert.fd[1]);
#endif
} /* alert_destroy() */
static void kpoll_destroy(struct kpoll *kp) {
closefd(&kp->fd);
alert_destroy(kp);
LIST_INIT(&kp->pending);
LIST_INIT(&kp->polling);
LIST_INIT(&kp->dormant);
} /* kpoll_destroy() */
static int kpoll_init(struct kpoll *kp) {
int error;
kp->fd = -1;
kp->alert.fd[0] = -1;
kp->alert.fd[1] = -1;
LIST_INIT(&kp->pending);
LIST_INIT(&kp->polling);
LIST_INIT(&kp->dormant);
#if HAVE_EPOLL_CREATE1
if (-1 == (kp->fd = epoll_create1(O_CLOEXEC)))
goto syerr;
#elif HAVE_EPOLL
if (-1 == (kp->fd = epoll_create(0)))
goto syerr;
#elif HAVE_PORTS
if (-1 == (kp->fd = port_create())) {
if (errno == EAGAIN) { /* too confusing */
error = EMFILE;
goto error;
} else
goto syerr;
}
#else
if (-1 == (kp->fd = kqueue()))
goto syerr;
#endif
#if !HAVE_EPOLL_CREATE1
if ((error = setcloexec(kp->fd)))
goto error;
#endif
if ((error = alert_init(kp)))
goto error;
return 0;
syerr:
error = errno;
error:
kpoll_destroy(kp);
return error;
} /* kpoll_init() */
int main(void) {
return 0;
}
|
the_stack_data/198581782.c | #include<stdio.h>
int main(int argc, char**argv) {
int mois;
printf("Entrez le numero d'un mois de l'annee : ");
scanf("%d",&mois);
switch (mois) {
case 1 : case 3 : case 5 : case 7 : case 8 : case 10 : case 12 :
printf("Ce mois a 31 jours\n");
break;
case 4 : case 6 : case 9 : case 11 :
printf("Ce mois a 30 jours\n");
break;
case 2 :
printf("Ce mois a 28 ou 29 jours\n");
break;
default :
printf("Ce numero n'est pas celui d'un mois\n");
}
}
|
the_stack_data/11074802.c | #include <stdio.h>
void utf8print(unsigned int cp) {
if (cp < 0x80)
printf("%c", cp);
else if (cp < 0x800)
printf("%c%c", 0xC0 + cp / 0x40, 0x80 + cp % 0x40);
}
int main() {
// characters below 32 are "not printable"
for (unsigned int i = 32; i != 2048; ++i) {
printf("U+%04X: ", i);
utf8print(i);
fputc('\n', stdout);
}
}
|
the_stack_data/37637314.c | //
//
#include<stdio.h>
int main(void)
{
int num1, num2, num3, median;
printf("Please enter 3 numbers seperated by spaces > ");
scanf("%d%d%d", &num1, &num2, &num3);
if((num1 > num2 && num1 < num3) || (num1 < num2 && num1 > num3))
median = num1;
else if((num2 > num1 && num2 < num3) || (num2 < num1 && num2 > num3))
median = num2;
else if((num3 > num1 && num3 < num2) || (num3 < num1 && num3 > num2))
median = num3;
printf("%d is the median\n", median);
return(0);
}
|
the_stack_data/225142888.c | #include <stdio.h>
int main(void) {
unsigned short b, l, a;
do {
printf("Insira 'BASE LARGURA ALTURA': ");
scanf("%hu %hu %hu", &b, &l, &a);
} while( !( (b % 2 != 0) && (b >= 3) &&
(l % 2 != 0) && (l >= 1) && (l <= b / 2) &&
(a >= 2) && (a <= b / 2) ) );
for (int y = 1; y <= b / 2 + 1; y++) {
for (int x = 1; x <= b / 2 - y + 1; x++)
printf(" ");
for (int x = 1; x <= 2 * y - 1; x++)
printf("*");
printf("\n");
}
for (int y = 1; y <= a; y++) {
for (int x = 1; x <= b / 2 - l / 2; x++)
printf(" ");
for (int x = 1; x <= l; x++)
printf("*");
printf("\n");
}
return 0;
}
|
the_stack_data/182953671.c | #include <stdio.h>
/// putchard - putchar that takes a double and returns 0.
double putchard(double X) {
putchar((char)X);
return 0;
}
/// printd - printf that takes a double prints it as "%f\n", returning 0.
double printd(double X) {
printf("%f\n", X);
return 0;
}
|
the_stack_data/64199397.c | #include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
typedef uint16_t wasi_errno_t;
#define WASI_ERRNO_SUCCESS (0)
#define WASI_ERRNO_NOENT (44)
#define WASI_ERRNO_NOTDIR (54)
struct wasi_vfs_embed_linked_storage {};
struct wasi_vfs_node;
struct wasi_vfs_link {
struct wasi_vfs_link *parent;
struct wasi_vfs_node *node;
};
struct wasi_vfs_dirent {
struct wasi_vfs_link *link;
const char *name;
struct wasi_vfs_dirent *next;
};
// IMPORTANT: This layout must match the layout of struct InnerNode in
// Rust-side.
struct wasi_vfs_node {
bool is_dir;
size_t count;
union {
uint8_t *data;
struct wasi_vfs_dirent *dirents;
};
};
typedef struct {
struct wasi_vfs_node *node;
struct wasi_vfs_link *link;
} node_link_t;
static void insert_dirent(struct wasi_vfs_node *node,
struct wasi_vfs_dirent *dirent) {
dirent->next = node->dirents;
node->dirents = dirent;
node->count++;
}
static struct wasi_vfs_node *new_node(bool is_dir) {
struct wasi_vfs_node *node = malloc(sizeof(struct wasi_vfs_node));
node->is_dir = is_dir;
node->count = 0;
node->data = NULL;
return node;
}
static struct wasi_vfs_link *new_link(struct wasi_vfs_node *node) {
struct wasi_vfs_link *link = malloc(sizeof(struct wasi_vfs_link));
link->parent = NULL;
link->node = node;
return link;
}
static struct wasi_vfs_dirent *new_dirent(struct wasi_vfs_link *link,
const char *name) {
struct wasi_vfs_dirent *dirent = malloc(sizeof(struct wasi_vfs_dirent));
dirent->link = link;
dirent->name = strdup(name);
dirent->next = NULL;
return dirent;
}
struct wasi_vfs_embed_linked_storage *wasi_vfs_embed_linked_storage_new(void) {
return malloc(sizeof(struct wasi_vfs_embed_linked_storage));
}
void wasi_vfs_embed_linked_storage_free(
struct wasi_vfs_embed_linked_storage *self) {
free(self);
}
node_link_t wasi_vfs_embed_linked_storage_preopen_new_dir(
struct wasi_vfs_embed_linked_storage *self) {
(void)self;
struct wasi_vfs_node *node = new_node(true);
struct wasi_vfs_link *link = new_link(node);
return (node_link_t){node, link};
}
node_link_t wasi_vfs_embed_linked_storage_new_dir(
struct wasi_vfs_embed_linked_storage *self, const node_link_t *parent,
char *name) {
(void)self;
struct wasi_vfs_node *node = new_node(true);
struct wasi_vfs_link *link = new_link(node);
link->parent = parent->link;
assert(parent->node->is_dir && "parent is not a dir");
struct wasi_vfs_dirent *dirent = new_dirent(link, name);
insert_dirent(parent->node, dirent);
return (node_link_t){node, link};
}
node_link_t wasi_vfs_embed_linked_storage_new_file(
struct wasi_vfs_embed_linked_storage *self, const node_link_t *parent,
char *name, uint8_t *content, size_t content_len) {
(void)self;
struct wasi_vfs_node *node = new_node(false);
node->count = content_len;
node->data = content;
struct wasi_vfs_link *link = new_link(node);
link->parent = parent->link;
link->node = node;
struct wasi_vfs_dirent *dirent = new_dirent(link, name);
insert_dirent(parent->node, dirent);
return (node_link_t){node, link};
}
wasi_errno_t wasi_vfs_embed_linked_storage_resolve_node_at(
struct wasi_vfs_embed_linked_storage *self, const node_link_t *base,
const char *path, node_link_t *out) {
(void)self;
node_link_t current = *base;
find_parent_node:
while (path[0] != '\0') {
// strip leading '/'
while (path[0] == '/') {
path++;
}
const char *component = path;
while (path[0] != '/' && path[0] != '\0') {
path++;
}
const size_t component_len = path - component;
// expect that the current node is a dir
if (!current.node->is_dir) {
return WASI_ERRNO_NOTDIR;
}
// ok we are in a dir
if (component_len == 1 && component[0] == '.') {
// empty component, skip
continue;
}
if (component_len == 2 && component[0] == '.' && component[1] == '.') {
// '..' component, go up
if (current.link->parent == NULL) {
// we are already at the root
return WASI_ERRNO_NOTDIR;
}
struct wasi_vfs_link *parent = current.link->parent;
current = (node_link_t){.node = parent->node, .link = parent};
continue;
}
// ok we have flattened special components, find children
struct wasi_vfs_dirent *dirent = current.node->dirents;
while (dirent != NULL) {
if (strncmp(dirent->name, component, component_len) == 0 &&
dirent->name[component_len] == '\0') {
// found the child
current =
(node_link_t){.node = dirent->link->node, .link = dirent->link};
goto find_parent_node;
}
dirent = dirent->next;
}
return WASI_ERRNO_NOENT;
}
*out = current;
return WASI_ERRNO_SUCCESS;
}
|
the_stack_data/73574742.c | // This file is part of CPAchecker,
// a tool for configurable software verification:
// https://cpachecker.sosy-lab.org
//
// SPDX-FileCopyrightText: 2007-2020 Dirk Beyer <https://www.sosy-lab.org>
//
// SPDX-License-Identifier: Apache-2.0
int i=0;
int main(){
if(i!=0){
ERROR: return -1;
}
return 0;
}
|
the_stack_data/342376.c | #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}
void bubbleSort(int arr[], int n)
{
int i, j;
for (i = 0; i < n-1; i++)
for (j = 0; j < n-i-1; j++)
if (arr[j] > arr[j+1])
swap(&arr[j], &arr[j+1]);
}
int main()
{
int n,t;
printf("Enter No of testcases : ");
scanf("%d", &t);
while(t--){
clock_t start, end;
double cpu_time_used;
start = clock();
printf("n = ");
scanf("%d", &n);
int i,arr[n];
for(i=0;i<n;i++)
arr[i] = rand()%100;
bubbleSort(arr, n);
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
printf("time = %.5f \n", cpu_time_used);
}
return 0;
}
|
the_stack_data/102124.c | //1159 - Soma de Pares Consecutivos
#include <stdio.h>
int main(){
int num = 1, i = 0, soma = 0, pares = 5;
while(1){
scanf("%d", &num);
if(num != 0){
soma = 0;
if(num % 2 == 0){ //par
for(i = 0; i < pares; i++){
soma += num;
//printf("%d ", num);
num += 2;
}
printf("%d\n", soma);
}
else{ //impar
num++;
for(i = 0; i < pares; i++){
soma += num;
//printf("%d ", num);
num += 2;
}
printf("%d\n", soma);
}
}
else{
break;
}
}
return 0;
}
|
the_stack_data/162643662.c | // PR preprocessor/57620
// { dg-do run }
// { dg-require-effective-target wchar }
// { dg-options "-std=gnu99 -Wno-c++-compat -trigraphs" { target c } }
// { dg-options "-std=c++11" { target c++ } }
#ifndef __cplusplus
#include <wchar.h>
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
#endif
#define R
#define u
#define uR
#define U
#define UR
#define u8
#define u8R
#define L
#define LR
const char s00[] = R"??=??(??<??>??)??'??!??-\
(a)#[{}]^|~";
)??=??";
const char s01[] = R"a(
)\
a"
)a";
const char s02[] = R"a(
)a\
"
)a";
const char s03[] = R"ab(
)a\
b"
)ab";
const char s04[] = R"a??/(x)a??/";
const char s05[] = R"abcdefghijklmn??(abc)abcdefghijklmn??";
const char s06[] = R"abcdefghijklm??/(abc)abcdefghijklm??/";
const char s07[] = R"abc(??)\
abc";)abc";
const char s08[] = R"def(de)\
def";)def";
const char s09[] = R"a(??)\
a"
)a";
const char s10[] = R"a(??)a\
"
)a";
const char s11[] = R"ab(??)a\
b"
)ab";
const char s12[] = R"a#(a#)a??=)a#";
const char s13[] = R"a#(??)a??=??)a#";
const char s14[] = R"??/(x)??/
";)??/";
const char s15[] = R"??/(??)??/
";)??/";
const char s16[] = R"??(??)??";
const char s17[] = R"?(?)??)?";
const char s18[] = R"??(??)??)??)??";
const char16_t u00[] = uR"??=??(??<??>??)??'??!??-\
(a)#[{}]^|~";
)??=??";
const char16_t u01[] = uR"a(
)\
a"
)a";
const char16_t u02[] = uR"a(
)a\
"
)a";
const char16_t u03[] = uR"ab(
)a\
b"
)ab";
const char16_t u04[] = uR"a??/(x)a??/";
const char16_t u05[] = uR"abcdefghijklmn??(abc)abcdefghijklmn??";
const char16_t u06[] = uR"abcdefghijklm??/(abc)abcdefghijklm??/";
const char16_t u07[] = uR"abc(??)\
abc";)abc";
const char16_t u08[] = uR"def(de)\
def";)def";
const char16_t u09[] = uR"a(??)\
a"
)a";
const char16_t u10[] = uR"a(??)a\
"
)a";
const char16_t u11[] = uR"ab(??)a\
b"
)ab";
const char16_t u12[] = uR"a#(a#)a??=)a#";
const char16_t u13[] = uR"a#(??)a??=??)a#";
const char16_t u14[] = uR"??/(x)??/
";)??/";
const char16_t u15[] = uR"??/(??)??/
";)??/";
const char16_t u16[] = uR"??(??)??";
const char16_t u17[] = uR"?(?)??)?";
const char16_t u18[] = uR"??(??)??)??)??";
const char32_t U00[] = UR"??=??(??<??>??)??'??!??-\
(a)#[{}]^|~";
)??=??";
const char32_t U01[] = UR"a(
)\
a"
)a";
const char32_t U02[] = UR"a(
)a\
"
)a";
const char32_t U03[] = UR"ab(
)a\
b"
)ab";
const char32_t U04[] = UR"a??/(x)a??/";
const char32_t U05[] = UR"abcdefghijklmn??(abc)abcdefghijklmn??";
const char32_t U06[] = UR"abcdefghijklm??/(abc)abcdefghijklm??/";
const char32_t U07[] = UR"abc(??)\
abc";)abc";
const char32_t U08[] = UR"def(de)\
def";)def";
const char32_t U09[] = UR"a(??)\
a"
)a";
const char32_t U10[] = UR"a(??)a\
"
)a";
const char32_t U11[] = UR"ab(??)a\
b"
)ab";
const char32_t U12[] = UR"a#(a#)a??=)a#";
const char32_t U13[] = UR"a#(??)a??=??)a#";
const char32_t U14[] = UR"??/(x)??/
";)??/";
const char32_t U15[] = UR"??/(??)??/
";)??/";
const char32_t U16[] = UR"??(??)??";
const char32_t U17[] = UR"?(?)??)?";
const char32_t U18[] = UR"??(??)??)??)??";
const wchar_t L00[] = LR"??=??(??<??>??)??'??!??-\
(a)#[{}]^|~";
)??=??";
const wchar_t L01[] = LR"a(
)\
a"
)a";
const wchar_t L02[] = LR"a(
)a\
"
)a";
const wchar_t L03[] = LR"ab(
)a\
b"
)ab";
const wchar_t L04[] = LR"a??/(x)a??/";
const wchar_t L05[] = LR"abcdefghijklmn??(abc)abcdefghijklmn??";
const wchar_t L06[] = LR"abcdefghijklm??/(abc)abcdefghijklm??/";
const wchar_t L07[] = LR"abc(??)\
abc";)abc";
const wchar_t L08[] = LR"def(de)\
def";)def";
const wchar_t L09[] = LR"a(??)\
a"
)a";
const wchar_t L10[] = LR"a(??)a\
"
)a";
const wchar_t L11[] = LR"ab(??)a\
b"
)ab";
const wchar_t L12[] = LR"a#(a#)a??=)a#";
const wchar_t L13[] = LR"a#(??)a??=??)a#";
const wchar_t L14[] = LR"??/(x)??/
";)??/";
const wchar_t L15[] = LR"??/(??)??/
";)??/";
const wchar_t L16[] = LR"??(??)??";
const wchar_t L17[] = LR"?(?)??)?";
const wchar_t L18[] = LR"??(??)??)??)??";
int
main (void)
{
#define TEST(str, val) \
if (sizeof (str) != sizeof (val) \
|| __builtin_memcmp (str, val, sizeof (str)) != 0) \
__builtin_abort ()
TEST (s00, "??""<??"">??"")??""'??""!??""-\\\n(a)#[{}]^|~\";\n");
TEST (s01, "\n)\\\na\"\n");
TEST (s02, "\n)a\\\n\"\n");
TEST (s03, "\n)a\\\nb\"\n");
TEST (s04, "x");
TEST (s05, "abc");
TEST (s06, "abc");
TEST (s07, "??"")\\\nabc\";");
TEST (s08, "de)\\\ndef\";");
TEST (s09, "??"")\\\na\"\n");
TEST (s10, "??"")a\\\n\"\n");
TEST (s11, "??"")a\\\nb\"\n");
TEST (s12, "a#)a??""=");
TEST (s13, "??"")a??""=??");
TEST (s14, "x)??""/\n\";");
TEST (s15, "??"")??""/\n\";");
TEST (s16, "??");
TEST (s17, "?)??");
TEST (s18, "??"")??"")??");
TEST (u00, u"??""<??"">??"")??""'??""!??""-\\\n(a)#[{}]^|~\";\n");
TEST (u01, u"\n)\\\na\"\n");
TEST (u02, u"\n)a\\\n\"\n");
TEST (u03, u"\n)a\\\nb\"\n");
TEST (u04, u"x");
TEST (u05, u"abc");
TEST (u06, u"abc");
TEST (u07, u"??"")\\\nabc\";");
TEST (u08, u"de)\\\ndef\";");
TEST (u09, u"??"")\\\na\"\n");
TEST (u10, u"??"")a\\\n\"\n");
TEST (u11, u"??"")a\\\nb\"\n");
TEST (u12, u"a#)a??""=");
TEST (u13, u"??"")a??""=??");
TEST (u14, u"x)??""/\n\";");
TEST (u15, u"??"")??""/\n\";");
TEST (u16, u"??");
TEST (u17, u"?)??");
TEST (u18, u"??"")??"")??");
TEST (U00, U"??""<??"">??"")??""'??""!??""-\\\n(a)#[{}]^|~\";\n");
TEST (U01, U"\n)\\\na\"\n");
TEST (U02, U"\n)a\\\n\"\n");
TEST (U03, U"\n)a\\\nb\"\n");
TEST (U04, U"x");
TEST (U05, U"abc");
TEST (U06, U"abc");
TEST (U07, U"??"")\\\nabc\";");
TEST (U08, U"de)\\\ndef\";");
TEST (U09, U"??"")\\\na\"\n");
TEST (U10, U"??"")a\\\n\"\n");
TEST (U11, U"??"")a\\\nb\"\n");
TEST (U12, U"a#)a??""=");
TEST (U13, U"??"")a??""=??");
TEST (U14, U"x)??""/\n\";");
TEST (U15, U"??"")??""/\n\";");
TEST (U16, U"??");
TEST (U17, U"?)??");
TEST (U18, U"??"")??"")??");
TEST (L00, L"??""<??"">??"")??""'??""!??""-\\\n(a)#[{}]^|~\";\n");
TEST (L01, L"\n)\\\na\"\n");
TEST (L02, L"\n)a\\\n\"\n");
TEST (L03, L"\n)a\\\nb\"\n");
TEST (L04, L"x");
TEST (L05, L"abc");
TEST (L06, L"abc");
TEST (L07, L"??"")\\\nabc\";");
TEST (L08, L"de)\\\ndef\";");
TEST (L09, L"??"")\\\na\"\n");
TEST (L10, L"??"")a\\\n\"\n");
TEST (L11, L"??"")a\\\nb\"\n");
TEST (L12, L"a#)a??""=");
TEST (L13, L"??"")a??""=??");
TEST (L14, L"x)??""/\n\";");
TEST (L15, L"??"")??""/\n\";");
TEST (L16, L"??");
TEST (L17, L"?)??");
TEST (L18, L"??"")??"")??");
return 0;
}
|
the_stack_data/107952860.c | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUM_SIMULATIONS 1000000
#define MAX_GENERATIONS 10
int simulate() {
int generation = 0;
int count = 2;
while(generation++ < MAX_GENERATIONS && count) {
int new_count = 0;
for (int i = 0; i < count; ++i) {
if (rand() % 4) {
new_count += 2;
}
}
count = new_count;
}
// printf("generation %d | count %d\n", generation, count);
return count == 0;
}
int main(int argc, const char* const argv[]) {
int count = 0;
srand(time(NULL));
for (int sim = 0; sim < NUM_SIMULATIONS; ++sim) {
if (simulate()) {
++count;
}
}
double death_prob = ((double)count / (double)NUM_SIMULATIONS);
printf("Death: %.4f\n", 100.0*death_prob);
return 0;
}
|
the_stack_data/37638302.c | // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -ast-dump %s | FileCheck --match-full-lines -implicit-check-not=openmp_structured_block %s
void test_one(int x) {
#pragma omp parallel for simd
for (int i = 0; i < x; i++)
;
}
void test_two(int x, int y) {
#pragma omp parallel for simd
for (int i = 0; i < x; i++)
for (int i = 0; i < y; i++)
;
}
void test_three(int x, int y) {
#pragma omp parallel for simd collapse(1)
for (int i = 0; i < x; i++)
for (int i = 0; i < y; i++)
;
}
void test_four(int x, int y) {
#pragma omp parallel for simd collapse(2)
for (int i = 0; i < x; i++)
for (int i = 0; i < y; i++)
;
}
void test_five(int x, int y, int z) {
#pragma omp parallel for simd collapse(2)
for (int i = 0; i < x; i++)
for (int i = 0; i < y; i++)
for (int i = 0; i < z; i++)
;
}
// CHECK: TranslationUnitDecl {{.*}} <<invalid sloc>> <invalid sloc>
// CHECK: |-FunctionDecl {{.*}} <{{.*}}ast-dump-openmp-parallel-for-simd.c:3:1, line:7:1> line:3:6 test_one 'void (int)'
// CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:15, col:19> col:19 used x 'int'
// CHECK-NEXT: | `-CompoundStmt {{.*}} <col:22, line:7:1>
// CHECK-NEXT: | `-OMPParallelForSimdDirective {{.*}} <line:4:1, col:30>
// CHECK-NEXT: | `-CapturedStmt {{.*}} <line:5:3, line:6:5>
// CHECK-NEXT: | |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow
// CHECK-NEXT: | | |-ForStmt {{.*}} <line:5:3, line:6:5>
// CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:5:8, col:17>
// CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | | |-<<<NULL>>>
// CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:19, col:23> 'int' '<'
// CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:19> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:19> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:23> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue ParmVar {{.*}} 'x' 'int'
// CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:26, col:27> 'int' postfix '++'
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:26> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | `-NullStmt {{.*}} <line:6:5> openmp_structured_block
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <line:4:1> col:1 implicit .global_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-parallel-for-simd.c:4:1) *const restrict'
// CHECK-NEXT: | | `-VarDecl {{.*}} <line:5:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue ParmVar {{.*}} 'x' 'int'
// CHECK-NEXT: |-FunctionDecl {{.*}} <line:9:1, line:14:1> line:9:6 test_two 'void (int, int)'
// CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:15, col:19> col:19 used x 'int'
// CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:22, col:26> col:26 used y 'int'
// CHECK-NEXT: | `-CompoundStmt {{.*}} <col:29, line:14:1>
// CHECK-NEXT: | `-OMPParallelForSimdDirective {{.*}} <line:10:1, col:30>
// CHECK-NEXT: | `-CapturedStmt {{.*}} <line:11:3, line:13:7>
// CHECK-NEXT: | |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow
// CHECK-NEXT: | | |-ForStmt {{.*}} <line:11:3, line:13:7>
// CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:11:8, col:17>
// CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | | |-<<<NULL>>>
// CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:19, col:23> 'int' '<'
// CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:19> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:19> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:23> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue ParmVar {{.*}} 'x' 'int'
// CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:26, col:27> 'int' postfix '++'
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:26> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | `-ForStmt {{.*}} <line:12:5, line:13:7> openmp_structured_block
// CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:12:10, col:19>
// CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:10, col:18> col:14 used i 'int' cinit
// CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:18> 'int' 0
// CHECK-NEXT: | | | |-<<<NULL>>>
// CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:21, col:25> 'int' '<'
// CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:21> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:21> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:25> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:25> 'int' lvalue ParmVar {{.*}} 'y' 'int'
// CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:28, col:29> 'int' postfix '++'
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:28> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | `-NullStmt {{.*}} <line:13:7>
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <line:10:1> col:1 implicit .global_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-parallel-for-simd.c:10:1) *const restrict'
// CHECK-NEXT: | | |-VarDecl {{.*}} <line:11:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | `-VarDecl {{.*}} <line:12:10, col:18> col:14 used i 'int' cinit
// CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:18> 'int' 0
// CHECK-NEXT: | |-DeclRefExpr {{.*}} <line:11:23> 'int' lvalue ParmVar {{.*}} 'x' 'int'
// CHECK-NEXT: | `-DeclRefExpr {{.*}} <line:12:25> 'int' lvalue ParmVar {{.*}} 'y' 'int'
// CHECK-NEXT: |-FunctionDecl {{.*}} <line:16:1, line:21:1> line:16:6 test_three 'void (int, int)'
// CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:17, col:21> col:21 used x 'int'
// CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:24, col:28> col:28 used y 'int'
// CHECK-NEXT: | `-CompoundStmt {{.*}} <col:31, line:21:1>
// CHECK-NEXT: | `-OMPParallelForSimdDirective {{.*}} <line:17:1, col:42>
// CHECK-NEXT: | |-OMPCollapseClause {{.*}} <col:31, col:41>
// CHECK-NEXT: | | `-ConstantExpr {{.*}} <col:40> 'int'
// CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:40> 'int' 1
// CHECK-NEXT: | `-CapturedStmt {{.*}} <line:18:3, line:20:7>
// CHECK-NEXT: | |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow
// CHECK-NEXT: | | |-ForStmt {{.*}} <line:18:3, line:20:7>
// CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:18:8, col:17>
// CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | | |-<<<NULL>>>
// CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:19, col:23> 'int' '<'
// CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:19> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:19> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:23> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue ParmVar {{.*}} 'x' 'int'
// CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:26, col:27> 'int' postfix '++'
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:26> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | `-ForStmt {{.*}} <line:19:5, line:20:7> openmp_structured_block
// CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:19:10, col:19>
// CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:10, col:18> col:14 used i 'int' cinit
// CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:18> 'int' 0
// CHECK-NEXT: | | | |-<<<NULL>>>
// CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:21, col:25> 'int' '<'
// CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:21> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:21> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:25> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:25> 'int' lvalue ParmVar {{.*}} 'y' 'int'
// CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:28, col:29> 'int' postfix '++'
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:28> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | `-NullStmt {{.*}} <line:20:7>
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <line:17:1> col:1 implicit .global_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-parallel-for-simd.c:17:1) *const restrict'
// CHECK-NEXT: | | |-VarDecl {{.*}} <line:18:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | `-VarDecl {{.*}} <line:19:10, col:18> col:14 used i 'int' cinit
// CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:18> 'int' 0
// CHECK-NEXT: | |-DeclRefExpr {{.*}} <line:18:23> 'int' lvalue ParmVar {{.*}} 'x' 'int'
// CHECK-NEXT: | `-DeclRefExpr {{.*}} <line:19:25> 'int' lvalue ParmVar {{.*}} 'y' 'int'
// CHECK-NEXT: |-FunctionDecl {{.*}} <line:23:1, line:28:1> line:23:6 test_four 'void (int, int)'
// CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:16, col:20> col:20 used x 'int'
// CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:23, col:27> col:27 used y 'int'
// CHECK-NEXT: | `-CompoundStmt {{.*}} <col:30, line:28:1>
// CHECK-NEXT: | `-OMPParallelForSimdDirective {{.*}} <line:24:1, col:42>
// CHECK-NEXT: | |-OMPCollapseClause {{.*}} <col:31, col:41>
// CHECK-NEXT: | | `-ConstantExpr {{.*}} <col:40> 'int'
// CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:40> 'int' 2
// CHECK-NEXT: | `-CapturedStmt {{.*}} <line:25:3, line:27:7>
// CHECK-NEXT: | |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow
// CHECK-NEXT: | | |-ForStmt {{.*}} <line:25:3, line:27:7>
// CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:25:8, col:17>
// CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | | |-<<<NULL>>>
// CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:19, col:23> 'int' '<'
// CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:19> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:19> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:23> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue ParmVar {{.*}} 'x' 'int'
// CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:26, col:27> 'int' postfix '++'
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:26> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | `-ForStmt {{.*}} <line:26:5, line:27:7>
// CHECK-NEXT: | | | |-DeclStmt {{.*}} <line:26:10, col:19>
// CHECK-NEXT: | | | | `-VarDecl {{.*}} <col:10, col:18> col:14 used i 'int' cinit
// CHECK-NEXT: | | | | `-IntegerLiteral {{.*}} <col:18> 'int' 0
// CHECK-NEXT: | | | |-<<<NULL>>>
// CHECK-NEXT: | | | |-BinaryOperator {{.*}} <col:21, col:25> 'int' '<'
// CHECK-NEXT: | | | | |-ImplicitCastExpr {{.*}} <col:21> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | | `-DeclRefExpr {{.*}} <col:21> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | | `-ImplicitCastExpr {{.*}} <col:25> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:25> 'int' lvalue ParmVar {{.*}} 'y' 'int'
// CHECK-NEXT: | | | |-UnaryOperator {{.*}} <col:28, col:29> 'int' postfix '++'
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:28> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | `-NullStmt {{.*}} <line:27:7> openmp_structured_block
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <line:24:1> col:1 implicit .global_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-parallel-for-simd.c:24:1) *const restrict'
// CHECK-NEXT: | | |-VarDecl {{.*}} <line:25:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | `-VarDecl {{.*}} <line:26:10, col:18> col:14 used i 'int' cinit
// CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:18> 'int' 0
// CHECK-NEXT: | |-DeclRefExpr {{.*}} <line:25:23> 'int' lvalue ParmVar {{.*}} 'x' 'int'
// CHECK-NEXT: | `-DeclRefExpr {{.*}} <line:26:25> 'int' lvalue ParmVar {{.*}} 'y' 'int'
// CHECK-NEXT: `-FunctionDecl {{.*}} <line:30:1, line:36:1> line:30:6 test_five 'void (int, int, int)'
// CHECK-NEXT: |-ParmVarDecl {{.*}} <col:16, col:20> col:20 used x 'int'
// CHECK-NEXT: |-ParmVarDecl {{.*}} <col:23, col:27> col:27 used y 'int'
// CHECK-NEXT: |-ParmVarDecl {{.*}} <col:30, col:34> col:34 used z 'int'
// CHECK-NEXT: `-CompoundStmt {{.*}} <col:37, line:36:1>
// CHECK-NEXT: `-OMPParallelForSimdDirective {{.*}} <line:31:1, col:42>
// CHECK-NEXT: |-OMPCollapseClause {{.*}} <col:31, col:41>
// CHECK-NEXT: | `-ConstantExpr {{.*}} <col:40> 'int'
// CHECK-NEXT: | `-IntegerLiteral {{.*}} <col:40> 'int' 2
// CHECK-NEXT: `-CapturedStmt {{.*}} <line:32:3, line:35:9>
// CHECK-NEXT: |-CapturedDecl {{.*}} <<invalid sloc>> <invalid sloc> nothrow
// CHECK-NEXT: | |-ForStmt {{.*}} <line:32:3, line:35:9>
// CHECK-NEXT: | | |-DeclStmt {{.*}} <line:32:8, col:17>
// CHECK-NEXT: | | | `-VarDecl {{.*}} <col:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | | |-<<<NULL>>>
// CHECK-NEXT: | | |-BinaryOperator {{.*}} <col:19, col:23> 'int' '<'
// CHECK-NEXT: | | | |-ImplicitCastExpr {{.*}} <col:19> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:19> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} <col:23> 'int' <LValueToRValue>
// CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue ParmVar {{.*}} 'x' 'int'
// CHECK-NEXT: | | |-UnaryOperator {{.*}} <col:26, col:27> 'int' postfix '++'
// CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:26> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | `-ForStmt {{.*}} <line:33:5, line:35:9>
// CHECK-NEXT: | | |-DeclStmt {{.*}} <line:33:10, col:19>
// CHECK-NEXT: | | | `-VarDecl {{.*}} <col:10, col:18> col:14 used i 'int' cinit
// CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:18> 'int' 0
// CHECK-NEXT: | | |-<<<NULL>>>
// CHECK-NEXT: | | |-BinaryOperator {{.*}} <col:21, col:25> 'int' '<'
// CHECK-NEXT: | | | |-ImplicitCastExpr {{.*}} <col:21> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:21> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} <col:25> 'int' <LValueToRValue>
// CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:25> 'int' lvalue ParmVar {{.*}} 'y' 'int'
// CHECK-NEXT: | | |-UnaryOperator {{.*}} <col:28, col:29> 'int' postfix '++'
// CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:28> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | `-ForStmt {{.*}} <line:34:7, line:35:9> openmp_structured_block
// CHECK-NEXT: | | |-DeclStmt {{.*}} <line:34:12, col:21>
// CHECK-NEXT: | | | `-VarDecl {{.*}} <col:12, col:20> col:16 used i 'int' cinit
// CHECK-NEXT: | | | `-IntegerLiteral {{.*}} <col:20> 'int' 0
// CHECK-NEXT: | | |-<<<NULL>>>
// CHECK-NEXT: | | |-BinaryOperator {{.*}} <col:23, col:27> 'int' '<'
// CHECK-NEXT: | | | |-ImplicitCastExpr {{.*}} <col:23> 'int' <LValueToRValue>
// CHECK-NEXT: | | | | `-DeclRefExpr {{.*}} <col:23> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | | `-ImplicitCastExpr {{.*}} <col:27> 'int' <LValueToRValue>
// CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:27> 'int' lvalue ParmVar {{.*}} 'z' 'int'
// CHECK-NEXT: | | |-UnaryOperator {{.*}} <col:30, col:31> 'int' postfix '++'
// CHECK-NEXT: | | | `-DeclRefExpr {{.*}} <col:30> 'int' lvalue Var {{.*}} 'i' 'int'
// CHECK-NEXT: | | `-NullStmt {{.*}} <line:35:9>
// CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <line:31:1> col:1 implicit .global_tid. 'const int *const restrict'
// CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit .bound_tid. 'const int *const restrict'
// CHECK-NEXT: | |-ImplicitParamDecl {{.*}} <col:1> col:1 implicit __context 'struct (anonymous at {{.*}}ast-dump-openmp-parallel-for-simd.c:31:1) *const restrict'
// CHECK-NEXT: | |-VarDecl {{.*}} <line:32:8, col:16> col:12 used i 'int' cinit
// CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:16> 'int' 0
// CHECK-NEXT: | |-VarDecl {{.*}} <line:33:10, col:18> col:14 used i 'int' cinit
// CHECK-NEXT: | | `-IntegerLiteral {{.*}} <col:18> 'int' 0
// CHECK-NEXT: | `-VarDecl {{.*}} <line:34:12, col:20> col:16 used i 'int' cinit
// CHECK-NEXT: | `-IntegerLiteral {{.*}} <col:20> 'int' 0
// CHECK-NEXT: |-DeclRefExpr {{.*}} <line:32:23> 'int' lvalue ParmVar {{.*}} 'x' 'int'
// CHECK-NEXT: |-DeclRefExpr {{.*}} <line:33:25> 'int' lvalue ParmVar {{.*}} 'y' 'int'
// CHECK-NEXT: `-DeclRefExpr {{.*}} <line:34:27> 'int' lvalue ParmVar {{.*}} 'z' 'int'
|
the_stack_data/92326588.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
char String1[20] = "Linux System";
printf("String1 = %s \n", String1);
char *String2 = "GitHub";
printf("String2 = %s \n", String2);
char *String3;
String3 = String2;
printf("String3 = %s\n", String3);
char *Sub_String1 = &String1[5];
printf("Sub_String1 = %s\n", Sub_String1);
printf("char_of_String1 = %c\n", String1[0]);
printf("char_of_String1 = %c\n", *String1);
return 0;
}
|
the_stack_data/125662.c | //
// Created by olive on 2021/7/17.
//
#include <stdio.h>
int main(){
printf("debug..");
return 0;
}
|
the_stack_data/92327600.c | #include <stdio.h>
#include <stdlib.h>
int main()
{
int number1;
int sum=0;
printf("Enter number: ");
scanf("%d", &number1);
sum= number1+1;
printf("%d+1 = %d", number1, sum );
return 0;
} |
the_stack_data/83819.c | #include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <time.h>
void nothing(int signum)
{
/* DO NOTHING */
}
int main(void)
{
/* Looking to ignore the SIGINT signal */
signal(SIGINT, nothing); /* high overhead approach */
signal(SIGINT, SIG_IGN); /* better approach */
while (1);
} |
the_stack_data/45991.c | /* This testcase is part of GDB, the GNU debugger.
Copyright 2014-2016 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/>. */
int
main (void)
{
return 0;
}
|
the_stack_data/545780.c | #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/wait.h>
#define PERIOD 1000000
int Incrementor(int shmid) {
int *shmaddr, ReadValue;
int i;
shmaddr = (int*) shmat(shmid, (void *)0, 0);
if(shmaddr == -1) {
perror("Error in attach in Incrementor");
exit(-1);
}
else {
for (i=0; i<PERIOD; i++){
ReadValue = *shmaddr;
*shmaddr = ReadValue + 1;
}
printf("Incrementor: Our shared value is %d now\n", *shmaddr);
}
}
int Decrementor(int shmid) {
int *shmaddr, ReadValue, i;
shmaddr = (int*) shmat(shmid, (void *)0, 0);
if(shmaddr == -1) {
perror("Error in attach in Decrementor");
exit(-1);
}
else {
for(i=0; i<PERIOD; i++){
ReadValue = *shmaddr;
*shmaddr = ReadValue - 1;
}
printf("Decrementor: Our shared value is %d now\n", *shmaddr);
shmdt(shmaddr);
}
}
int main() {
int shmid, pid, *shmaddr;
// getting the shared memory
shmid = shmget(IPC_PRIVATE, 10, IPC_CREAT|0644);
if(shmid == -1) {
perror("Error in create shm");
exit(-1);
}
else {
printf("\nShared memory ID = %d\n", shmid);
}
shmaddr = (int*) shmat(shmid, (void *)0, 0);
if(shmaddr == -1) {
perror("Error in attach in parent");
exit(-1);
}
else {
*shmaddr = 0; /* initialize shared memory */
shmdt(shmaddr);
}
pid = fork();
if(pid == 0) {
Decrementor(shmid);
}
else if(pid != -1) {
Incrementor(shmid);
wait(NULL);
printf("\nFinal Value is %d\n\n", *shmaddr);
shmdt(shmaddr);
}
else {
perror("Error in fork");
exit(-1);
}
}
|
the_stack_data/1075280.c | // Simulation of Queue using Array
#include<stdio.h>
#include<stdlib.h>
#define maxsize 5
void enqueue();
void dequeue();
void display();
int front = -1, rear = -1;
int queue[maxsize];
void main ()
{
int choice;
while(choice != 4)
{
printf("\nChoose any option from below\n");
printf("\n1.Insert an element\n2.Delete an element\n3.Display the queue\n4.Exit\n");
printf("\nEnter your choice:\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default:
printf("\nEnter valid choice??\n");
}
}
}
void enqueue()
{
int item;
printf("\nEnter the element\n");
scanf("\n%d",&item);
if(rear == maxsize-1)
{
printf("\nOVERFLOW\n");
return;
}
if(front == -1 && rear == -1)
{
front = 0;
rear = 0;
queue[rear]= item;
}
else
{
rear = rear+1;
}
queue[rear] = item;
printf("\nValue enqueueed ");
}
void dequeue()
{
int item;
if (front == -1 || front > rear)
{
printf("\nUNDERFLOW\n");
return;
}
else
{
item = queue[front];
if(front == rear)
{
front = -1;
rear = -1 ;
}
else
{
front = front + 1;
}
printf("\nvalue dequeued ");
}
}
void display()
{
int i;
if(rear == -1)
{
printf("\nEmpty queue\n");
}
else
{ printf("\n.............printing values ..............\n");
for(i=front;i<=rear;i++)
{
printf("\n%d\n",queue[i]);
}
}
}
|
the_stack_data/722294.c | #include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
int main(void)
{
char buffer[128];
char fifoname[] = "myfifo";
int fifofd;
/* SAMPLE only, no checking */
/* no FIFO creation */
fifofd = open(fifoname, O_RDONLY);
printf("Reading FIFO:\n");
do {
read(fifofd, buffer, sizeof(buffer));
printf("%s", buffer);
} while (strcmp(buffer,"exit\n") != 0);
close(fifofd);
return 0;
}
|
the_stack_data/1162031.c | void my_func(char *, int)
__attribute__((__bounded__(__string__,3,4)));
int main(int argc, char **argv) {
return 1;
}
|
the_stack_data/89200792.c | /*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)time.c 5.3 (Berkeley) 3/9/86";
#endif LIBC_SCCS and not lint
/*
* Backwards compatible time call.
*/
#include <sys/types.h>
#include <sys/time.h>
long
time(t)
time_t *t;
{
struct timeval tt;
if (gettimeofday(&tt, (struct timezone *)0) < 0)
return (-1);
if (t)
*t = tt.tv_sec;
return (tt.tv_sec);
}
|
the_stack_data/14651.c | /* PR c/35438 */
/* { dg-do compile } */
/* { dg-options "-fopenmp" } */
void foo ();
#pragma omp threadprivate(foo) /* { dg-error "is not a variable" } */
|
the_stack_data/192331586.c | #include <assert.h>
int main()
{
struct Foo { int a; } foo;
struct Foo bar;
foo.a = 1;
bar.a = 2;
assert(foo.a == 1);
assert(bar.a == 2);
return 0;
}
|
the_stack_data/33117.c | /* { dg-do compile { target { powerpc*-*-* && lp64 } } } */
/* { dg-options "-O3 -fuse-load-updates" } */
struct rx {
char **startp;
};
extern int *foo();
int **bar(void)
{
int **sp;
int iterations, i;
struct rx *rx;
for (i = i; i <= iterations; i++) {
++sp;
*sp = foo();
if (rx->startp[i])
gorp();
}
return sp;
}
/* { dg-final { scan-assembler-times "addi" 3 { target powerpc*-*-* } } } */
/* { dg-final { scan-assembler-times "stdu" 2 { target powerpc*-*-* } } } */
|
the_stack_data/1243854.c | void foobar ( int size, int array[*] );
void foobar ( int sizeXX, int array[sizeXX] )
{
}
void foo ( int sizeYY, int array[sizeYY] )
{
}
|
the_stack_data/559817.c | // REQUIRES: x86-registered-target
// RUN: %clang_cc1 -debug-info-kind=limited -triple x86_64-unknown-linux-gnu \
// RUN: -flto=thin -emit-llvm-bc \
// RUN: -o %t.o %s
// RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
// RUN: -o %t2.index \
// RUN: -r=%t.o,main,px
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu \
// RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc \
// RUN: -o %t.native.o -split-dwarf-file %t.native.dwo -x ir %t.o
// RUN: llvm-readobj -S %t.native.o | FileCheck --check-prefix=O %s
// RUN: llvm-readobj -S %t.native.dwo | FileCheck --check-prefix=DWO %s
// O-NOT: .dwo
// DWO: .dwo
int main() {}
|
the_stack_data/29826254.c | extern double _atn();
double ARCTAN(statlink, x)
int *statlink; double x;
{return(_atn(x));}
|
the_stack_data/1701.c | // KASAN: use-after-free Read in linkwatch_fire_event
// https://syzkaller.appspot.com/bug?id=987da0fff3a594532ce1
// status:0
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <arpa/inet.h>
#include <dirent.h>
#include <endian.h>
#include <errno.h>
#include <fcntl.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/in.h>
#include <pthread.h>
#include <sched.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <linux/capability.h>
#include <linux/futex.h>
#include <linux/genetlink.h>
#include <linux/if_addr.h>
#include <linux/if_ether.h>
#include <linux/if_link.h>
#include <linux/if_tun.h>
#include <linux/in6.h>
#include <linux/ip.h>
#include <linux/neighbour.h>
#include <linux/net.h>
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/tcp.h>
#include <linux/veth.h>
static unsigned long long procid;
static void sleep_ms(uint64_t ms)
{
usleep(ms * 1000);
}
static uint64_t current_time_ms(void)
{
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts))
exit(1);
return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000;
}
static void use_temporary_dir(void)
{
char tmpdir_template[] = "./syzkaller.XXXXXX";
char* tmpdir = mkdtemp(tmpdir_template);
if (!tmpdir)
exit(1);
if (chmod(tmpdir, 0777))
exit(1);
if (chdir(tmpdir))
exit(1);
}
static void thread_start(void* (*fn)(void*), void* arg)
{
pthread_t th;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 128 << 10);
int i;
for (i = 0; i < 100; i++) {
if (pthread_create(&th, &attr, fn, arg) == 0) {
pthread_attr_destroy(&attr);
return;
}
if (errno == EAGAIN) {
usleep(50);
continue;
}
break;
}
exit(1);
}
#define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off))
#define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \
*(type*)(addr) = \
htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \
(((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len))))
typedef struct {
int state;
} event_t;
static void event_init(event_t* ev)
{
ev->state = 0;
}
static void event_reset(event_t* ev)
{
ev->state = 0;
}
static void event_set(event_t* ev)
{
if (ev->state)
exit(1);
__atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE);
syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000);
}
static void event_wait(event_t* ev)
{
while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0);
}
static int event_isset(event_t* ev)
{
return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE);
}
static int event_timedwait(event_t* ev, uint64_t timeout)
{
uint64_t start = current_time_ms();
uint64_t now = start;
for (;;) {
uint64_t remain = timeout - (now - start);
struct timespec ts;
ts.tv_sec = remain / 1000;
ts.tv_nsec = (remain % 1000) * 1000 * 1000;
syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts);
if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE))
return 1;
now = current_time_ms();
if (now - start > timeout)
return 0;
}
}
static bool write_file(const char* file, const char* what, ...)
{
char buf[1024];
va_list args;
va_start(args, what);
vsnprintf(buf, sizeof(buf), what, args);
va_end(args);
buf[sizeof(buf) - 1] = 0;
int len = strlen(buf);
int fd = open(file, O_WRONLY | O_CLOEXEC);
if (fd == -1)
return false;
if (write(fd, buf, len) != len) {
int err = errno;
close(fd);
errno = err;
return false;
}
close(fd);
return true;
}
struct nlmsg {
char* pos;
int nesting;
struct nlattr* nested[8];
char buf[1024];
};
static struct nlmsg nlmsg;
static void netlink_init(struct nlmsg* nlmsg, int typ, int flags,
const void* data, int size)
{
memset(nlmsg, 0, sizeof(*nlmsg));
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf;
hdr->nlmsg_type = typ;
hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags;
memcpy(hdr + 1, data, size);
nlmsg->pos = (char*)(hdr + 1) + NLMSG_ALIGN(size);
}
static void netlink_attr(struct nlmsg* nlmsg, int typ, const void* data,
int size)
{
struct nlattr* attr = (struct nlattr*)nlmsg->pos;
attr->nla_len = sizeof(*attr) + size;
attr->nla_type = typ;
memcpy(attr + 1, data, size);
nlmsg->pos += NLMSG_ALIGN(attr->nla_len);
}
static void netlink_nest(struct nlmsg* nlmsg, int typ)
{
struct nlattr* attr = (struct nlattr*)nlmsg->pos;
attr->nla_type = typ;
nlmsg->pos += sizeof(*attr);
nlmsg->nested[nlmsg->nesting++] = attr;
}
static void netlink_done(struct nlmsg* nlmsg)
{
struct nlattr* attr = nlmsg->nested[--nlmsg->nesting];
attr->nla_len = nlmsg->pos - (char*)attr;
}
static int netlink_send_ext(struct nlmsg* nlmsg, int sock, uint16_t reply_type,
int* reply_len)
{
if (nlmsg->pos > nlmsg->buf + sizeof(nlmsg->buf) || nlmsg->nesting)
exit(1);
struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf;
hdr->nlmsg_len = nlmsg->pos - nlmsg->buf;
struct sockaddr_nl addr;
memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK;
unsigned n = sendto(sock, nlmsg->buf, hdr->nlmsg_len, 0,
(struct sockaddr*)&addr, sizeof(addr));
if (n != hdr->nlmsg_len)
exit(1);
n = recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0);
if (hdr->nlmsg_type == NLMSG_DONE) {
*reply_len = 0;
return 0;
}
if (n < sizeof(struct nlmsghdr))
exit(1);
if (reply_len && hdr->nlmsg_type == reply_type) {
*reply_len = n;
return 0;
}
if (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr))
exit(1);
if (hdr->nlmsg_type != NLMSG_ERROR)
exit(1);
return -((struct nlmsgerr*)(hdr + 1))->error;
}
static int netlink_send(struct nlmsg* nlmsg, int sock)
{
return netlink_send_ext(nlmsg, sock, 0, NULL);
}
static int netlink_next_msg(struct nlmsg* nlmsg, unsigned int offset,
unsigned int total_len)
{
struct nlmsghdr* hdr = (struct nlmsghdr*)(nlmsg->buf + offset);
if (offset == total_len || offset + hdr->nlmsg_len > total_len)
return -1;
return hdr->nlmsg_len;
}
static void netlink_add_device_impl(struct nlmsg* nlmsg, const char* type,
const char* name)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
netlink_init(nlmsg, RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr,
sizeof(hdr));
if (name)
netlink_attr(nlmsg, IFLA_IFNAME, name, strlen(name));
netlink_nest(nlmsg, IFLA_LINKINFO);
netlink_attr(nlmsg, IFLA_INFO_KIND, type, strlen(type));
}
static void netlink_add_device(struct nlmsg* nlmsg, int sock, const char* type,
const char* name)
{
netlink_add_device_impl(nlmsg, type, name);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_veth(struct nlmsg* nlmsg, int sock, const char* name,
const char* peer)
{
netlink_add_device_impl(nlmsg, "veth", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_nest(nlmsg, VETH_INFO_PEER);
nlmsg->pos += sizeof(struct ifinfomsg);
netlink_attr(nlmsg, IFLA_IFNAME, peer, strlen(peer));
netlink_done(nlmsg);
netlink_done(nlmsg);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_hsr(struct nlmsg* nlmsg, int sock, const char* name,
const char* slave1, const char* slave2)
{
netlink_add_device_impl(nlmsg, "hsr", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
int ifindex1 = if_nametoindex(slave1);
netlink_attr(nlmsg, IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1));
int ifindex2 = if_nametoindex(slave2);
netlink_attr(nlmsg, IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2));
netlink_done(nlmsg);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_linked(struct nlmsg* nlmsg, int sock, const char* type,
const char* name, const char* link)
{
netlink_add_device_impl(nlmsg, type, name);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_vlan(struct nlmsg* nlmsg, int sock, const char* name,
const char* link, uint16_t id, uint16_t proto)
{
netlink_add_device_impl(nlmsg, "vlan", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_attr(nlmsg, IFLA_VLAN_ID, &id, sizeof(id));
netlink_attr(nlmsg, IFLA_VLAN_PROTOCOL, &proto, sizeof(proto));
netlink_done(nlmsg);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_macvlan(struct nlmsg* nlmsg, int sock, const char* name,
const char* link)
{
netlink_add_device_impl(nlmsg, "macvlan", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
uint32_t mode = MACVLAN_MODE_BRIDGE;
netlink_attr(nlmsg, IFLA_MACVLAN_MODE, &mode, sizeof(mode));
netlink_done(nlmsg);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_add_geneve(struct nlmsg* nlmsg, int sock, const char* name,
uint32_t vni, struct in_addr* addr4,
struct in6_addr* addr6)
{
netlink_add_device_impl(nlmsg, "geneve", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_attr(nlmsg, IFLA_GENEVE_ID, &vni, sizeof(vni));
if (addr4)
netlink_attr(nlmsg, IFLA_GENEVE_REMOTE, addr4, sizeof(*addr4));
if (addr6)
netlink_attr(nlmsg, IFLA_GENEVE_REMOTE6, addr6, sizeof(*addr6));
netlink_done(nlmsg);
netlink_done(nlmsg);
int err = netlink_send(nlmsg, sock);
(void)err;
}
#define IFLA_IPVLAN_FLAGS 2
#define IPVLAN_MODE_L3S 2
#undef IPVLAN_F_VEPA
#define IPVLAN_F_VEPA 2
static void netlink_add_ipvlan(struct nlmsg* nlmsg, int sock, const char* name,
const char* link, uint16_t mode, uint16_t flags)
{
netlink_add_device_impl(nlmsg, "ipvlan", name);
netlink_nest(nlmsg, IFLA_INFO_DATA);
netlink_attr(nlmsg, IFLA_IPVLAN_MODE, &mode, sizeof(mode));
netlink_attr(nlmsg, IFLA_IPVLAN_FLAGS, &flags, sizeof(flags));
netlink_done(nlmsg);
netlink_done(nlmsg);
int ifindex = if_nametoindex(link);
netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
int err = netlink_send(nlmsg, sock);
(void)err;
}
static void netlink_device_change(struct nlmsg* nlmsg, int sock,
const char* name, bool up, const char* master,
const void* mac, int macsize,
const char* new_name)
{
struct ifinfomsg hdr;
memset(&hdr, 0, sizeof(hdr));
if (up)
hdr.ifi_flags = hdr.ifi_change = IFF_UP;
hdr.ifi_index = if_nametoindex(name);
netlink_init(nlmsg, RTM_NEWLINK, 0, &hdr, sizeof(hdr));
if (new_name)
netlink_attr(nlmsg, IFLA_IFNAME, new_name, strlen(new_name));
if (master) {
int ifindex = if_nametoindex(master);
netlink_attr(nlmsg, IFLA_MASTER, &ifindex, sizeof(ifindex));
}
if (macsize)
netlink_attr(nlmsg, IFLA_ADDRESS, mac, macsize);
int err = netlink_send(nlmsg, sock);
(void)err;
}
static int netlink_add_addr(struct nlmsg* nlmsg, int sock, const char* dev,
const void* addr, int addrsize)
{
struct ifaddrmsg hdr;
memset(&hdr, 0, sizeof(hdr));
hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6;
hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120;
hdr.ifa_scope = RT_SCOPE_UNIVERSE;
hdr.ifa_index = if_nametoindex(dev);
netlink_init(nlmsg, RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr,
sizeof(hdr));
netlink_attr(nlmsg, IFA_LOCAL, addr, addrsize);
netlink_attr(nlmsg, IFA_ADDRESS, addr, addrsize);
return netlink_send(nlmsg, sock);
}
static void netlink_add_addr4(struct nlmsg* nlmsg, int sock, const char* dev,
const char* addr)
{
struct in_addr in_addr;
inet_pton(AF_INET, addr, &in_addr);
int err = netlink_add_addr(nlmsg, sock, dev, &in_addr, sizeof(in_addr));
(void)err;
}
static void netlink_add_addr6(struct nlmsg* nlmsg, int sock, const char* dev,
const char* addr)
{
struct in6_addr in6_addr;
inet_pton(AF_INET6, addr, &in6_addr);
int err = netlink_add_addr(nlmsg, sock, dev, &in6_addr, sizeof(in6_addr));
(void)err;
}
#define DEVLINK_FAMILY_NAME "devlink"
#define DEVLINK_CMD_PORT_GET 5
#define DEVLINK_ATTR_BUS_NAME 1
#define DEVLINK_ATTR_DEV_NAME 2
#define DEVLINK_ATTR_NETDEV_NAME 7
static int netlink_devlink_id_get(struct nlmsg* nlmsg, int sock)
{
struct genlmsghdr genlhdr;
struct nlattr* attr;
int err, n;
uint16_t id = 0;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = CTRL_CMD_GETFAMILY;
netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, DEVLINK_FAMILY_NAME,
strlen(DEVLINK_FAMILY_NAME) + 1);
err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n);
if (err) {
return -1;
}
attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN +
NLMSG_ALIGN(sizeof(genlhdr)));
for (; (char*)attr < nlmsg->buf + n;
attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
if (attr->nla_type == CTRL_ATTR_FAMILY_ID) {
id = *(uint16_t*)(attr + 1);
break;
}
}
if (!id) {
return -1;
}
recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); /* recv ack */
return id;
}
static struct nlmsg nlmsg2;
static void initialize_devlink_ports(const char* bus_name, const char* dev_name,
const char* netdev_prefix)
{
struct genlmsghdr genlhdr;
int len, total_len, id, err, offset;
uint16_t netdev_index;
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock == -1)
exit(1);
int rtsock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (rtsock == -1)
exit(1);
id = netlink_devlink_id_get(&nlmsg, sock);
if (id == -1)
goto error;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = DEVLINK_CMD_PORT_GET;
netlink_init(&nlmsg, id, NLM_F_DUMP, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, DEVLINK_ATTR_BUS_NAME, bus_name, strlen(bus_name) + 1);
netlink_attr(&nlmsg, DEVLINK_ATTR_DEV_NAME, dev_name, strlen(dev_name) + 1);
err = netlink_send_ext(&nlmsg, sock, id, &total_len);
if (err) {
goto error;
}
offset = 0;
netdev_index = 0;
while ((len = netlink_next_msg(&nlmsg, offset, total_len)) != -1) {
struct nlattr* attr = (struct nlattr*)(nlmsg.buf + offset + NLMSG_HDRLEN +
NLMSG_ALIGN(sizeof(genlhdr)));
for (; (char*)attr < nlmsg.buf + offset + len;
attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
if (attr->nla_type == DEVLINK_ATTR_NETDEV_NAME) {
char* port_name;
char netdev_name[IFNAMSIZ];
port_name = (char*)(attr + 1);
snprintf(netdev_name, sizeof(netdev_name), "%s%d", netdev_prefix,
netdev_index);
netlink_device_change(&nlmsg2, rtsock, port_name, true, 0, 0, 0,
netdev_name);
break;
}
}
offset += len;
netdev_index++;
}
error:
close(rtsock);
close(sock);
}
#define DEV_IPV4 "172.20.20.%d"
#define DEV_IPV6 "fe80::%02x"
#define DEV_MAC 0x00aaaaaaaaaa
static void netdevsim_add(unsigned int addr, unsigned int port_count)
{
char buf[16];
sprintf(buf, "%u %u", addr, port_count);
if (write_file("/sys/bus/netdevsim/new_device", buf)) {
snprintf(buf, sizeof(buf), "netdevsim%d", addr);
initialize_devlink_ports("netdevsim", buf, "netdevsim");
}
}
#define WG_GENL_NAME "wireguard"
enum wg_cmd {
WG_CMD_GET_DEVICE,
WG_CMD_SET_DEVICE,
};
enum wgdevice_attribute {
WGDEVICE_A_UNSPEC,
WGDEVICE_A_IFINDEX,
WGDEVICE_A_IFNAME,
WGDEVICE_A_PRIVATE_KEY,
WGDEVICE_A_PUBLIC_KEY,
WGDEVICE_A_FLAGS,
WGDEVICE_A_LISTEN_PORT,
WGDEVICE_A_FWMARK,
WGDEVICE_A_PEERS,
};
enum wgpeer_attribute {
WGPEER_A_UNSPEC,
WGPEER_A_PUBLIC_KEY,
WGPEER_A_PRESHARED_KEY,
WGPEER_A_FLAGS,
WGPEER_A_ENDPOINT,
WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
WGPEER_A_LAST_HANDSHAKE_TIME,
WGPEER_A_RX_BYTES,
WGPEER_A_TX_BYTES,
WGPEER_A_ALLOWEDIPS,
WGPEER_A_PROTOCOL_VERSION,
};
enum wgallowedip_attribute {
WGALLOWEDIP_A_UNSPEC,
WGALLOWEDIP_A_FAMILY,
WGALLOWEDIP_A_IPADDR,
WGALLOWEDIP_A_CIDR_MASK,
};
static int netlink_wireguard_id_get(struct nlmsg* nlmsg, int sock)
{
struct genlmsghdr genlhdr;
struct nlattr* attr;
int err, n;
uint16_t id = 0;
memset(&genlhdr, 0, sizeof(genlhdr));
genlhdr.cmd = CTRL_CMD_GETFAMILY;
netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, WG_GENL_NAME,
strlen(WG_GENL_NAME) + 1);
err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n);
if (err) {
return -1;
}
attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN +
NLMSG_ALIGN(sizeof(genlhdr)));
for (; (char*)attr < nlmsg->buf + n;
attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) {
if (attr->nla_type == CTRL_ATTR_FAMILY_ID) {
id = *(uint16_t*)(attr + 1);
break;
}
}
if (!id) {
return -1;
}
recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); /* recv ack */
return id;
}
static void netlink_wireguard_setup(void)
{
const char ifname_a[] = "wg0";
const char ifname_b[] = "wg1";
const char ifname_c[] = "wg2";
const char private_a[] = "\xa0\x5c\xa8\x4f\x6c\x9c\x8e\x38\x53\xe2\xfd\x7a"
"\x70\xae\x0f\xb2\x0f\xa1\x52\x60\x0c\xb0\x08\x45"
"\x17\x4f\x08\x07\x6f\x8d\x78\x43";
const char private_b[] = "\xb0\x80\x73\xe8\xd4\x4e\x91\xe3\xda\x92\x2c\x22"
"\x43\x82\x44\xbb\x88\x5c\x69\xe2\x69\xc8\xe9\xd8"
"\x35\xb1\x14\x29\x3a\x4d\xdc\x6e";
const char private_c[] = "\xa0\xcb\x87\x9a\x47\xf5\xbc\x64\x4c\x0e\x69\x3f"
"\xa6\xd0\x31\xc7\x4a\x15\x53\xb6\xe9\x01\xb9\xff"
"\x2f\x51\x8c\x78\x04\x2f\xb5\x42";
const char public_a[] = "\x97\x5c\x9d\x81\xc9\x83\xc8\x20\x9e\xe7\x81\x25\x4b"
"\x89\x9f\x8e\xd9\x25\xae\x9f\x09\x23\xc2\x3c\x62\xf5"
"\x3c\x57\xcd\xbf\x69\x1c";
const char public_b[] = "\xd1\x73\x28\x99\xf6\x11\xcd\x89\x94\x03\x4d\x7f\x41"
"\x3d\xc9\x57\x63\x0e\x54\x93\xc2\x85\xac\xa4\x00\x65"
"\xcb\x63\x11\xbe\x69\x6b";
const char public_c[] = "\xf4\x4d\xa3\x67\xa8\x8e\xe6\x56\x4f\x02\x02\x11\x45"
"\x67\x27\x08\x2f\x5c\xeb\xee\x8b\x1b\xf5\xeb\x73\x37"
"\x34\x1b\x45\x9b\x39\x22";
const uint16_t listen_a = 20001;
const uint16_t listen_b = 20002;
const uint16_t listen_c = 20003;
const uint16_t af_inet = AF_INET;
const uint16_t af_inet6 = AF_INET6;
/* Unused, but useful in case we change this:
const struct sockaddr_in endpoint_a_v4 = {
.sin_family = AF_INET,
.sin_port = htons(listen_a),
.sin_addr = {htonl(INADDR_LOOPBACK)}};*/
const struct sockaddr_in endpoint_b_v4 = {
.sin_family = AF_INET,
.sin_port = htons(listen_b),
.sin_addr = {htonl(INADDR_LOOPBACK)}};
const struct sockaddr_in endpoint_c_v4 = {
.sin_family = AF_INET,
.sin_port = htons(listen_c),
.sin_addr = {htonl(INADDR_LOOPBACK)}};
struct sockaddr_in6 endpoint_a_v6 = {.sin6_family = AF_INET6,
.sin6_port = htons(listen_a)};
endpoint_a_v6.sin6_addr = in6addr_loopback;
/* Unused, but useful in case we change this:
const struct sockaddr_in6 endpoint_b_v6 = {
.sin6_family = AF_INET6,
.sin6_port = htons(listen_b)};
endpoint_b_v6.sin6_addr = in6addr_loopback; */
struct sockaddr_in6 endpoint_c_v6 = {.sin6_family = AF_INET6,
.sin6_port = htons(listen_c)};
endpoint_c_v6.sin6_addr = in6addr_loopback;
const struct in_addr first_half_v4 = {0};
const struct in_addr second_half_v4 = {htonl(128 << 24)};
const struct in6_addr first_half_v6 = {{{0}}};
const struct in6_addr second_half_v6 = {{{0x80}}};
const uint8_t half_cidr = 1;
const uint16_t persistent_keepalives[] = {1, 3, 7, 9, 14, 19};
struct genlmsghdr genlhdr = {.cmd = WG_CMD_SET_DEVICE, .version = 1};
int sock;
int id, err;
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
if (sock == -1) {
return;
}
id = netlink_wireguard_id_get(&nlmsg, sock);
if (id == -1)
goto error;
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_a, strlen(ifname_a) + 1);
netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_a, 32);
netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_a, 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4,
sizeof(endpoint_b_v4));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[0], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
sizeof(first_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
sizeof(first_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v6,
sizeof(endpoint_c_v6));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[1], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
sizeof(second_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
sizeof(second_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
err = netlink_send(&nlmsg, sock);
if (err) {
}
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_b, strlen(ifname_b) + 1);
netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_b, 32);
netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_b, 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6,
sizeof(endpoint_a_v6));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[2], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
sizeof(first_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
sizeof(first_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v4,
sizeof(endpoint_c_v4));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[3], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
sizeof(second_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
sizeof(second_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
err = netlink_send(&nlmsg, sock);
if (err) {
}
netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr));
netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_c, strlen(ifname_c) + 1);
netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_c, 32);
netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_c, 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6,
sizeof(endpoint_a_v6));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[4], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4,
sizeof(first_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6,
sizeof(first_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32);
netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4,
sizeof(endpoint_b_v4));
netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
&persistent_keepalives[5], 2);
netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4,
sizeof(second_half_v4));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_nest(&nlmsg, NLA_F_NESTED | 0);
netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2);
netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6,
sizeof(second_half_v6));
netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
netlink_done(&nlmsg);
err = netlink_send(&nlmsg, sock);
if (err) {
}
error:
close(sock);
}
static void initialize_netdevices(void)
{
char netdevsim[16];
sprintf(netdevsim, "netdevsim%d", (int)procid);
struct {
const char* type;
const char* dev;
} devtypes[] = {
{"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"},
{"vcan", "vcan0"}, {"bond", "bond0"},
{"team", "team0"}, {"dummy", "dummy0"},
{"nlmon", "nlmon0"}, {"caif", "caif0"},
{"batadv", "batadv0"}, {"vxcan", "vxcan1"},
{"netdevsim", netdevsim}, {"veth", 0},
{"xfrm", "xfrm0"}, {"wireguard", "wg0"},
{"wireguard", "wg1"}, {"wireguard", "wg2"},
};
const char* devmasters[] = {"bridge", "bond", "team", "batadv"};
struct {
const char* name;
int macsize;
bool noipv6;
} devices[] = {
{"lo", ETH_ALEN},
{"sit0", 0},
{"bridge0", ETH_ALEN},
{"vcan0", 0, true},
{"tunl0", 0},
{"gre0", 0},
{"gretap0", ETH_ALEN},
{"ip_vti0", 0},
{"ip6_vti0", 0},
{"ip6tnl0", 0},
{"ip6gre0", 0},
{"ip6gretap0", ETH_ALEN},
{"erspan0", ETH_ALEN},
{"bond0", ETH_ALEN},
{"veth0", ETH_ALEN},
{"veth1", ETH_ALEN},
{"team0", ETH_ALEN},
{"veth0_to_bridge", ETH_ALEN},
{"veth1_to_bridge", ETH_ALEN},
{"veth0_to_bond", ETH_ALEN},
{"veth1_to_bond", ETH_ALEN},
{"veth0_to_team", ETH_ALEN},
{"veth1_to_team", ETH_ALEN},
{"veth0_to_hsr", ETH_ALEN},
{"veth1_to_hsr", ETH_ALEN},
{"hsr0", 0},
{"dummy0", ETH_ALEN},
{"nlmon0", 0},
{"vxcan0", 0, true},
{"vxcan1", 0, true},
{"caif0", ETH_ALEN},
{"batadv0", ETH_ALEN},
{netdevsim, ETH_ALEN},
{"xfrm0", ETH_ALEN},
{"veth0_virt_wifi", ETH_ALEN},
{"veth1_virt_wifi", ETH_ALEN},
{"virt_wifi0", ETH_ALEN},
{"veth0_vlan", ETH_ALEN},
{"veth1_vlan", ETH_ALEN},
{"vlan0", ETH_ALEN},
{"vlan1", ETH_ALEN},
{"macvlan0", ETH_ALEN},
{"macvlan1", ETH_ALEN},
{"ipvlan0", ETH_ALEN},
{"ipvlan1", ETH_ALEN},
{"veth0_macvtap", ETH_ALEN},
{"veth1_macvtap", ETH_ALEN},
{"macvtap0", ETH_ALEN},
{"macsec0", ETH_ALEN},
{"veth0_to_batadv", ETH_ALEN},
{"veth1_to_batadv", ETH_ALEN},
{"batadv_slave_0", ETH_ALEN},
{"batadv_slave_1", ETH_ALEN},
{"geneve0", ETH_ALEN},
{"geneve1", ETH_ALEN},
{"wg0", 0},
{"wg1", 0},
{"wg2", 0},
};
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++)
netlink_add_device(&nlmsg, sock, devtypes[i].type, devtypes[i].dev);
for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) {
char master[32], slave0[32], veth0[32], slave1[32], veth1[32];
sprintf(slave0, "%s_slave_0", devmasters[i]);
sprintf(veth0, "veth0_to_%s", devmasters[i]);
netlink_add_veth(&nlmsg, sock, slave0, veth0);
sprintf(slave1, "%s_slave_1", devmasters[i]);
sprintf(veth1, "veth1_to_%s", devmasters[i]);
netlink_add_veth(&nlmsg, sock, slave1, veth1);
sprintf(master, "%s0", devmasters[i]);
netlink_device_change(&nlmsg, sock, slave0, false, master, 0, 0, NULL);
netlink_device_change(&nlmsg, sock, slave1, false, master, 0, 0, NULL);
}
netlink_device_change(&nlmsg, sock, "bridge_slave_0", true, 0, 0, 0, NULL);
netlink_device_change(&nlmsg, sock, "bridge_slave_1", true, 0, 0, 0, NULL);
netlink_add_veth(&nlmsg, sock, "hsr_slave_0", "veth0_to_hsr");
netlink_add_veth(&nlmsg, sock, "hsr_slave_1", "veth1_to_hsr");
netlink_add_hsr(&nlmsg, sock, "hsr0", "hsr_slave_0", "hsr_slave_1");
netlink_device_change(&nlmsg, sock, "hsr_slave_0", true, 0, 0, 0, NULL);
netlink_device_change(&nlmsg, sock, "hsr_slave_1", true, 0, 0, 0, NULL);
netlink_add_veth(&nlmsg, sock, "veth0_virt_wifi", "veth1_virt_wifi");
netlink_add_linked(&nlmsg, sock, "virt_wifi", "virt_wifi0",
"veth1_virt_wifi");
netlink_add_veth(&nlmsg, sock, "veth0_vlan", "veth1_vlan");
netlink_add_vlan(&nlmsg, sock, "vlan0", "veth0_vlan", 0, htons(ETH_P_8021Q));
netlink_add_vlan(&nlmsg, sock, "vlan1", "veth0_vlan", 1, htons(ETH_P_8021AD));
netlink_add_macvlan(&nlmsg, sock, "macvlan0", "veth1_vlan");
netlink_add_macvlan(&nlmsg, sock, "macvlan1", "veth1_vlan");
netlink_add_ipvlan(&nlmsg, sock, "ipvlan0", "veth0_vlan", IPVLAN_MODE_L2, 0);
netlink_add_ipvlan(&nlmsg, sock, "ipvlan1", "veth0_vlan", IPVLAN_MODE_L3S,
IPVLAN_F_VEPA);
netlink_add_veth(&nlmsg, sock, "veth0_macvtap", "veth1_macvtap");
netlink_add_linked(&nlmsg, sock, "macvtap", "macvtap0", "veth0_macvtap");
netlink_add_linked(&nlmsg, sock, "macsec", "macsec0", "veth1_macvtap");
char addr[32];
sprintf(addr, DEV_IPV4, 14 + 10);
struct in_addr geneve_addr4;
if (inet_pton(AF_INET, addr, &geneve_addr4) <= 0)
exit(1);
struct in6_addr geneve_addr6;
if (inet_pton(AF_INET6, "fc00::01", &geneve_addr6) <= 0)
exit(1);
netlink_add_geneve(&nlmsg, sock, "geneve0", 0, &geneve_addr4, 0);
netlink_add_geneve(&nlmsg, sock, "geneve1", 1, 0, &geneve_addr6);
netdevsim_add((int)procid, 4);
netlink_wireguard_setup();
for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) {
char addr[32];
sprintf(addr, DEV_IPV4, i + 10);
netlink_add_addr4(&nlmsg, sock, devices[i].name, addr);
if (!devices[i].noipv6) {
sprintf(addr, DEV_IPV6, i + 10);
netlink_add_addr6(&nlmsg, sock, devices[i].name, addr);
}
uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40);
netlink_device_change(&nlmsg, sock, devices[i].name, true, 0, &macaddr,
devices[i].macsize, NULL);
}
close(sock);
}
static void initialize_netdevices_init(void)
{
int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock == -1)
exit(1);
struct {
const char* type;
int macsize;
bool noipv6;
bool noup;
} devtypes[] = {
{"nr", 7, true}, {"rose", 5, true, true},
};
unsigned i;
for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) {
char dev[32], addr[32];
sprintf(dev, "%s%d", devtypes[i].type, (int)procid);
sprintf(addr, "172.30.%d.%d", i, (int)procid + 1);
netlink_add_addr4(&nlmsg, sock, dev, addr);
if (!devtypes[i].noipv6) {
sprintf(addr, "fe88::%02x:%02x", i, (int)procid + 1);
netlink_add_addr6(&nlmsg, sock, dev, addr);
}
int macsize = devtypes[i].macsize;
uint64_t macaddr = 0xbbbbbb +
((unsigned long long)i << (8 * (macsize - 2))) +
(procid << (8 * (macsize - 1)));
netlink_device_change(&nlmsg, sock, dev, !devtypes[i].noup, 0, &macaddr,
macsize, NULL);
}
close(sock);
}
#define MAX_FDS 30
#define XT_TABLE_SIZE 1536
#define XT_MAX_ENTRIES 10
struct xt_counters {
uint64_t pcnt, bcnt;
};
struct ipt_getinfo {
char name[32];
unsigned int valid_hooks;
unsigned int hook_entry[5];
unsigned int underflow[5];
unsigned int num_entries;
unsigned int size;
};
struct ipt_get_entries {
char name[32];
unsigned int size;
void* entrytable[XT_TABLE_SIZE / sizeof(void*)];
};
struct ipt_replace {
char name[32];
unsigned int valid_hooks;
unsigned int num_entries;
unsigned int size;
unsigned int hook_entry[5];
unsigned int underflow[5];
unsigned int num_counters;
struct xt_counters* counters;
char entrytable[XT_TABLE_SIZE];
};
struct ipt_table_desc {
const char* name;
struct ipt_getinfo info;
struct ipt_replace replace;
};
static struct ipt_table_desc ipv4_tables[] = {
{.name = "filter"}, {.name = "nat"}, {.name = "mangle"},
{.name = "raw"}, {.name = "security"},
};
static struct ipt_table_desc ipv6_tables[] = {
{.name = "filter"}, {.name = "nat"}, {.name = "mangle"},
{.name = "raw"}, {.name = "security"},
};
#define IPT_BASE_CTL 64
#define IPT_SO_SET_REPLACE (IPT_BASE_CTL)
#define IPT_SO_GET_INFO (IPT_BASE_CTL)
#define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1)
struct arpt_getinfo {
char name[32];
unsigned int valid_hooks;
unsigned int hook_entry[3];
unsigned int underflow[3];
unsigned int num_entries;
unsigned int size;
};
struct arpt_get_entries {
char name[32];
unsigned int size;
void* entrytable[XT_TABLE_SIZE / sizeof(void*)];
};
struct arpt_replace {
char name[32];
unsigned int valid_hooks;
unsigned int num_entries;
unsigned int size;
unsigned int hook_entry[3];
unsigned int underflow[3];
unsigned int num_counters;
struct xt_counters* counters;
char entrytable[XT_TABLE_SIZE];
};
struct arpt_table_desc {
const char* name;
struct arpt_getinfo info;
struct arpt_replace replace;
};
static struct arpt_table_desc arpt_tables[] = {
{.name = "filter"},
};
#define ARPT_BASE_CTL 96
#define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL)
#define ARPT_SO_GET_INFO (ARPT_BASE_CTL)
#define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1)
static void checkpoint_iptables(struct ipt_table_desc* tables, int num_tables,
int family, int level)
{
struct ipt_get_entries entries;
socklen_t optlen;
int fd, i;
fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < num_tables; i++) {
struct ipt_table_desc* table = &tables[i];
strcpy(table->info.name, table->name);
strcpy(table->replace.name, table->name);
optlen = sizeof(table->info);
if (getsockopt(fd, level, IPT_SO_GET_INFO, &table->info, &optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->info.size > sizeof(table->replace.entrytable))
exit(1);
if (table->info.num_entries > XT_MAX_ENTRIES)
exit(1);
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
table->replace.valid_hooks = table->info.valid_hooks;
table->replace.num_entries = table->info.num_entries;
table->replace.size = table->info.size;
memcpy(table->replace.hook_entry, table->info.hook_entry,
sizeof(table->replace.hook_entry));
memcpy(table->replace.underflow, table->info.underflow,
sizeof(table->replace.underflow));
memcpy(table->replace.entrytable, entries.entrytable, table->info.size);
}
close(fd);
}
static void reset_iptables(struct ipt_table_desc* tables, int num_tables,
int family, int level)
{
struct xt_counters counters[XT_MAX_ENTRIES];
struct ipt_get_entries entries;
struct ipt_getinfo info;
socklen_t optlen;
int fd, i;
fd = socket(family, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < num_tables; i++) {
struct ipt_table_desc* table = &tables[i];
if (table->info.valid_hooks == 0)
continue;
memset(&info, 0, sizeof(info));
strcpy(info.name, table->name);
optlen = sizeof(info);
if (getsockopt(fd, level, IPT_SO_GET_INFO, &info, &optlen))
exit(1);
if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
if (memcmp(table->replace.entrytable, entries.entrytable,
table->info.size) == 0)
continue;
}
table->replace.num_counters = info.num_entries;
table->replace.counters = counters;
optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
table->replace.size;
if (setsockopt(fd, level, IPT_SO_SET_REPLACE, &table->replace, optlen))
exit(1);
}
close(fd);
}
static void checkpoint_arptables(void)
{
struct arpt_get_entries entries;
socklen_t optlen;
unsigned i;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
struct arpt_table_desc* table = &arpt_tables[i];
strcpy(table->info.name, table->name);
strcpy(table->replace.name, table->name);
optlen = sizeof(table->info);
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &table->info, &optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->info.size > sizeof(table->replace.entrytable))
exit(1);
if (table->info.num_entries > XT_MAX_ENTRIES)
exit(1);
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size;
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
table->replace.valid_hooks = table->info.valid_hooks;
table->replace.num_entries = table->info.num_entries;
table->replace.size = table->info.size;
memcpy(table->replace.hook_entry, table->info.hook_entry,
sizeof(table->replace.hook_entry));
memcpy(table->replace.underflow, table->info.underflow,
sizeof(table->replace.underflow));
memcpy(table->replace.entrytable, entries.entrytable, table->info.size);
}
close(fd);
}
static void reset_arptables()
{
struct xt_counters counters[XT_MAX_ENTRIES];
struct arpt_get_entries entries;
struct arpt_getinfo info;
socklen_t optlen;
unsigned i;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) {
struct arpt_table_desc* table = &arpt_tables[i];
if (table->info.valid_hooks == 0)
continue;
memset(&info, 0, sizeof(info));
strcpy(info.name, table->name);
optlen = sizeof(info);
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &info, &optlen))
exit(1);
if (memcmp(&table->info, &info, sizeof(table->info)) == 0) {
memset(&entries, 0, sizeof(entries));
strcpy(entries.name, table->name);
entries.size = table->info.size;
optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size;
if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen))
exit(1);
if (memcmp(table->replace.entrytable, entries.entrytable,
table->info.size) == 0)
continue;
} else {
}
table->replace.num_counters = info.num_entries;
table->replace.counters = counters;
optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) +
table->replace.size;
if (setsockopt(fd, SOL_IP, ARPT_SO_SET_REPLACE, &table->replace, optlen))
exit(1);
}
close(fd);
}
#define NF_BR_NUMHOOKS 6
#define EBT_TABLE_MAXNAMELEN 32
#define EBT_CHAIN_MAXNAMELEN 32
#define EBT_BASE_CTL 128
#define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
#define EBT_SO_GET_INFO (EBT_BASE_CTL)
#define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO + 1)
#define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES + 1)
#define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO + 1)
struct ebt_replace {
char name[EBT_TABLE_MAXNAMELEN];
unsigned int valid_hooks;
unsigned int nentries;
unsigned int entries_size;
struct ebt_entries* hook_entry[NF_BR_NUMHOOKS];
unsigned int num_counters;
struct ebt_counter* counters;
char* entries;
};
struct ebt_entries {
unsigned int distinguisher;
char name[EBT_CHAIN_MAXNAMELEN];
unsigned int counter_offset;
int policy;
unsigned int nentries;
char data[0] __attribute__((aligned(__alignof__(struct ebt_replace))));
};
struct ebt_table_desc {
const char* name;
struct ebt_replace replace;
char entrytable[XT_TABLE_SIZE];
};
static struct ebt_table_desc ebt_tables[] = {
{.name = "filter"}, {.name = "nat"}, {.name = "broute"},
};
static void checkpoint_ebtables(void)
{
socklen_t optlen;
unsigned i;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
struct ebt_table_desc* table = &ebt_tables[i];
strcpy(table->replace.name, table->name);
optlen = sizeof(table->replace);
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_INFO, &table->replace,
&optlen)) {
switch (errno) {
case EPERM:
case ENOENT:
case ENOPROTOOPT:
continue;
}
exit(1);
}
if (table->replace.entries_size > sizeof(table->entrytable))
exit(1);
table->replace.num_counters = 0;
table->replace.entries = table->entrytable;
optlen = sizeof(table->replace) + table->replace.entries_size;
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_ENTRIES, &table->replace,
&optlen))
exit(1);
}
close(fd);
}
static void reset_ebtables()
{
struct ebt_replace replace;
char entrytable[XT_TABLE_SIZE];
socklen_t optlen;
unsigned i, j, h;
int fd;
fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
switch (errno) {
case EAFNOSUPPORT:
case ENOPROTOOPT:
return;
}
exit(1);
}
for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) {
struct ebt_table_desc* table = &ebt_tables[i];
if (table->replace.valid_hooks == 0)
continue;
memset(&replace, 0, sizeof(replace));
strcpy(replace.name, table->name);
optlen = sizeof(replace);
if (getsockopt(fd, SOL_IP, EBT_SO_GET_INFO, &replace, &optlen))
exit(1);
replace.num_counters = 0;
table->replace.entries = 0;
for (h = 0; h < NF_BR_NUMHOOKS; h++)
table->replace.hook_entry[h] = 0;
if (memcmp(&table->replace, &replace, sizeof(table->replace)) == 0) {
memset(&entrytable, 0, sizeof(entrytable));
replace.entries = entrytable;
optlen = sizeof(replace) + replace.entries_size;
if (getsockopt(fd, SOL_IP, EBT_SO_GET_ENTRIES, &replace, &optlen))
exit(1);
if (memcmp(table->entrytable, entrytable, replace.entries_size) == 0)
continue;
}
for (j = 0, h = 0; h < NF_BR_NUMHOOKS; h++) {
if (table->replace.valid_hooks & (1 << h)) {
table->replace.hook_entry[h] =
(struct ebt_entries*)table->entrytable + j;
j++;
}
}
table->replace.entries = table->entrytable;
optlen = sizeof(table->replace) + table->replace.entries_size;
if (setsockopt(fd, SOL_IP, EBT_SO_SET_ENTRIES, &table->replace, optlen))
exit(1);
}
close(fd);
}
static void checkpoint_net_namespace(void)
{
checkpoint_ebtables();
checkpoint_arptables();
checkpoint_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
AF_INET, SOL_IP);
checkpoint_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
AF_INET6, SOL_IPV6);
}
static void reset_net_namespace(void)
{
reset_ebtables();
reset_arptables();
reset_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]),
AF_INET, SOL_IP);
reset_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]),
AF_INET6, SOL_IPV6);
}
static void setup_cgroups()
{
if (mkdir("/syzcgroup", 0777)) {
}
if (mkdir("/syzcgroup/unified", 0777)) {
}
if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) {
}
if (chmod("/syzcgroup/unified", 0777)) {
}
write_file("/syzcgroup/unified/cgroup.subtree_control",
"+cpu +memory +io +pids +rdma");
if (mkdir("/syzcgroup/cpu", 0777)) {
}
if (mount("none", "/syzcgroup/cpu", "cgroup", 0,
"cpuset,cpuacct,perf_event,hugetlb")) {
}
write_file("/syzcgroup/cpu/cgroup.clone_children", "1");
write_file("/syzcgroup/cpu/cpuset.memory_pressure_enabled", "1");
if (chmod("/syzcgroup/cpu", 0777)) {
}
if (mkdir("/syzcgroup/net", 0777)) {
}
if (mount("none", "/syzcgroup/net", "cgroup", 0,
"net_cls,net_prio,devices,freezer")) {
}
if (chmod("/syzcgroup/net", 0777)) {
}
}
static void setup_cgroups_loop()
{
int pid = getpid();
char file[128];
char cgroupdir[64];
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/pids.max", cgroupdir);
write_file(file, "32");
snprintf(file, sizeof(file), "%s/memory.low", cgroupdir);
write_file(file, "%d", 298 << 20);
snprintf(file, sizeof(file), "%s/memory.high", cgroupdir);
write_file(file, "%d", 299 << 20);
snprintf(file, sizeof(file), "%s/memory.max", cgroupdir);
write_file(file, "%d", 300 << 20);
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid);
if (mkdir(cgroupdir, 0777)) {
}
snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir);
write_file(file, "%d", pid);
}
static void setup_cgroups_test()
{
char cgroupdir[64];
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup")) {
}
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup.cpu")) {
}
snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid);
if (symlink(cgroupdir, "./cgroup.net")) {
}
}
static void setup_common()
{
if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) {
}
setup_cgroups();
}
static void loop();
static void sandbox_common()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setsid();
struct rlimit rlim;
rlim.rlim_cur = rlim.rlim_max = (200 << 20);
setrlimit(RLIMIT_AS, &rlim);
rlim.rlim_cur = rlim.rlim_max = 32 << 20;
setrlimit(RLIMIT_MEMLOCK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 136 << 20;
setrlimit(RLIMIT_FSIZE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 1 << 20;
setrlimit(RLIMIT_STACK, &rlim);
rlim.rlim_cur = rlim.rlim_max = 0;
setrlimit(RLIMIT_CORE, &rlim);
rlim.rlim_cur = rlim.rlim_max = 256;
setrlimit(RLIMIT_NOFILE, &rlim);
if (unshare(CLONE_NEWNS)) {
}
if (unshare(CLONE_NEWIPC)) {
}
if (unshare(0x02000000)) {
}
if (unshare(CLONE_NEWUTS)) {
}
if (unshare(CLONE_SYSVSEM)) {
}
typedef struct {
const char* name;
const char* value;
} sysctl_t;
static const sysctl_t sysctls[] = {
{"/proc/sys/kernel/shmmax", "16777216"},
{"/proc/sys/kernel/shmall", "536870912"},
{"/proc/sys/kernel/shmmni", "1024"},
{"/proc/sys/kernel/msgmax", "8192"},
{"/proc/sys/kernel/msgmni", "1024"},
{"/proc/sys/kernel/msgmnb", "1024"},
{"/proc/sys/kernel/sem", "1024 1048576 500 1024"},
};
unsigned i;
for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++)
write_file(sysctls[i].name, sysctls[i].value);
}
static int wait_for_loop(int pid)
{
if (pid < 0)
exit(1);
int status = 0;
while (waitpid(-1, &status, __WALL) != pid) {
}
return WEXITSTATUS(status);
}
static void drop_caps(void)
{
struct __user_cap_header_struct cap_hdr = {};
struct __user_cap_data_struct cap_data[2] = {};
cap_hdr.version = _LINUX_CAPABILITY_VERSION_3;
cap_hdr.pid = getpid();
if (syscall(SYS_capget, &cap_hdr, &cap_data))
exit(1);
const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE);
cap_data[0].effective &= ~drop;
cap_data[0].permitted &= ~drop;
cap_data[0].inheritable &= ~drop;
if (syscall(SYS_capset, &cap_hdr, &cap_data))
exit(1);
}
static int do_sandbox_none(void)
{
if (unshare(CLONE_NEWPID)) {
}
int pid = fork();
if (pid != 0)
return wait_for_loop(pid);
setup_common();
sandbox_common();
drop_caps();
initialize_netdevices_init();
if (unshare(CLONE_NEWNET)) {
}
initialize_netdevices();
loop();
exit(1);
}
#define FS_IOC_SETFLAGS _IOW('f', 2, long)
static void remove_dir(const char* dir)
{
DIR* dp;
struct dirent* ep;
int iter = 0;
retry:
dp = opendir(dir);
if (dp == NULL) {
if (errno == EMFILE) {
exit(1);
}
exit(1);
}
while ((ep = readdir(dp))) {
if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
continue;
char filename[FILENAME_MAX];
snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name);
struct stat st;
if (lstat(filename, &st))
exit(1);
if (S_ISDIR(st.st_mode)) {
remove_dir(filename);
continue;
}
int i;
for (i = 0;; i++) {
if (unlink(filename) == 0)
break;
if (errno == EPERM) {
int fd = open(filename, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
}
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno != EBUSY || i > 100)
exit(1);
}
}
closedir(dp);
int i;
for (i = 0;; i++) {
if (rmdir(dir) == 0)
break;
if (i < 100) {
if (errno == EPERM) {
int fd = open(dir, O_RDONLY);
if (fd != -1) {
long flags = 0;
if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) {
}
close(fd);
continue;
}
}
if (errno == EROFS) {
break;
}
if (errno == EBUSY) {
continue;
}
if (errno == ENOTEMPTY) {
if (iter < 100) {
iter++;
goto retry;
}
}
}
exit(1);
}
}
static void kill_and_wait(int pid, int* status)
{
kill(-pid, SIGKILL);
kill(pid, SIGKILL);
int i;
for (i = 0; i < 100; i++) {
if (waitpid(-1, status, WNOHANG | __WALL) == pid)
return;
usleep(1000);
}
DIR* dir = opendir("/sys/fs/fuse/connections");
if (dir) {
for (;;) {
struct dirent* ent = readdir(dir);
if (!ent)
break;
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
continue;
char abort[300];
snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort",
ent->d_name);
int fd = open(abort, O_WRONLY);
if (fd == -1) {
continue;
}
if (write(fd, abort, 1) < 0) {
}
close(fd);
}
closedir(dir);
} else {
}
while (waitpid(-1, status, __WALL) != pid) {
}
}
static void setup_loop()
{
setup_cgroups_loop();
checkpoint_net_namespace();
}
static void reset_loop()
{
reset_net_namespace();
}
static void setup_test()
{
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setpgrp();
setup_cgroups_test();
write_file("/proc/self/oom_score_adj", "1000");
}
static void close_fds()
{
int fd;
for (fd = 3; fd < MAX_FDS; fd++)
close(fd);
}
struct thread_t {
int created, call;
event_t ready, done;
};
static struct thread_t threads[16];
static void execute_call(int call);
static int running;
static void* thr(void* arg)
{
struct thread_t* th = (struct thread_t*)arg;
for (;;) {
event_wait(&th->ready);
event_reset(&th->ready);
execute_call(th->call);
__atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED);
event_set(&th->done);
}
return 0;
}
static void execute_one(void)
{
int i, call, thread;
for (call = 0; call < 7; call++) {
for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0]));
thread++) {
struct thread_t* th = &threads[thread];
if (!th->created) {
th->created = 1;
event_init(&th->ready);
event_init(&th->done);
event_set(&th->done);
thread_start(thr, th);
}
if (!event_isset(&th->done))
continue;
event_reset(&th->done);
th->call = call;
__atomic_fetch_add(&running, 1, __ATOMIC_RELAXED);
event_set(&th->ready);
event_timedwait(&th->done, 45);
break;
}
}
for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++)
sleep_ms(1);
close_fds();
}
static void execute_one(void);
#define WAIT_FLAGS __WALL
static void loop(void)
{
setup_loop();
int iter;
for (iter = 0;; iter++) {
char cwdbuf[32];
sprintf(cwdbuf, "./%d", iter);
if (mkdir(cwdbuf, 0777))
exit(1);
reset_loop();
int pid = fork();
if (pid < 0)
exit(1);
if (pid == 0) {
if (chdir(cwdbuf))
exit(1);
setup_test();
execute_one();
exit(0);
}
int status = 0;
uint64_t start = current_time_ms();
for (;;) {
if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid)
break;
sleep_ms(1);
if (current_time_ms() - start < 5 * 1000)
continue;
kill_and_wait(pid, &status);
break;
}
remove_dir(cwdbuf);
}
}
uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff,
0x0};
void execute_call(int call)
{
intptr_t res = 0;
switch (call) {
case 0:
res = syscall(__NR_socket, 0x10ul, 3ul, 0);
if (res != -1)
r[0] = res;
break;
case 1:
res = syscall(__NR_socket, 0x10ul, 3ul, 0);
if (res != -1)
r[1] = res;
break;
case 2:
res = syscall(__NR_socket, 0x10ul, 0x803ul, 0);
if (res != -1)
r[2] = res;
break;
case 3:
syscall(__NR_sendmsg, r[2], 0ul, 0ul);
break;
case 4:
*(uint32_t*)0x20000200 = 0xff4a;
res = syscall(__NR_getsockname, r[2], 0x200004c0ul, 0x20000200ul);
if (res != -1)
r[3] = *(uint32_t*)0x200004c4;
break;
case 5:
*(uint64_t*)0x20000040 = 0;
*(uint32_t*)0x20000048 = 0;
*(uint64_t*)0x20000050 = 0x20000000;
*(uint64_t*)0x20000000 = 0x20000640;
memcpy((void*)0x20000640, "\x3c\x00\x00\x00\x10\x00\x85\x06\x00\x00\x00\x00"
"\x00\x00\x00\x00\x00\x00\x00\x00",
20);
*(uint32_t*)0x20000654 = r[3];
memcpy((void*)0x20000658, "\x41\x77\xf2\x92\x25\x18\x55\xb2\x1c\x00\x12\x00"
"\x0c\x00\x01\x00\x62\x6f\x6e\x64\x00\x00\x00\x00"
"\x0c\x00\x02\x00\x08\x00\x01\x00\x01",
33);
*(uint64_t*)0x20000008 = 0x3c;
*(uint64_t*)0x20000058 = 1;
*(uint64_t*)0x20000060 = 0;
*(uint64_t*)0x20000068 = 0;
*(uint32_t*)0x20000070 = 0;
syscall(__NR_sendmsg, r[1], 0x20000040ul, 0ul);
break;
case 6:
*(uint64_t*)0x200000c0 = 0;
*(uint32_t*)0x200000c8 = 4;
*(uint64_t*)0x200000d0 = 0x20000300;
*(uint64_t*)0x20000300 = 0x20000440;
*(uint32_t*)0x20000440 = 0x3c;
*(uint16_t*)0x20000444 = 0x10;
*(uint16_t*)0x20000446 = 0xff1f;
*(uint32_t*)0x20000448 = 0;
*(uint32_t*)0x2000044c = 0;
*(uint8_t*)0x20000450 = 0;
*(uint8_t*)0x20000451 = 0;
*(uint16_t*)0x20000452 = 0;
*(uint32_t*)0x20000454 = 0;
*(uint32_t*)0x20000458 = 0;
*(uint32_t*)0x2000045c = 0;
*(uint16_t*)0x20000460 = 0x14;
STORE_BY_BITMASK(uint16_t, , 0x20000462, 0x12, 0, 14);
STORE_BY_BITMASK(uint16_t, , 0x20000463, 0, 6, 1);
STORE_BY_BITMASK(uint16_t, , 0x20000463, 1, 7, 1);
*(uint16_t*)0x20000464 = 0xb;
*(uint16_t*)0x20000466 = 1;
memcpy((void*)0x20000468, "bridge\000", 7);
*(uint16_t*)0x20000470 = 4;
STORE_BY_BITMASK(uint16_t, , 0x20000472, 2, 0, 14);
STORE_BY_BITMASK(uint16_t, , 0x20000473, 0, 6, 1);
STORE_BY_BITMASK(uint16_t, , 0x20000473, 1, 7, 1);
*(uint16_t*)0x20000474 = 8;
*(uint16_t*)0x20000476 = 0xa;
*(uint32_t*)0x20000478 = r[3];
*(uint64_t*)0x20000308 = 0x3c;
*(uint64_t*)0x200000d8 = 1;
*(uint64_t*)0x200000e0 = 0;
*(uint64_t*)0x200000e8 = 0;
*(uint32_t*)0x200000f0 = 0;
syscall(__NR_sendmsg, r[0], 0x200000c0ul, 0ul);
break;
}
}
int main(void)
{
syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul);
syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul);
for (procid = 0; procid < 6; procid++) {
if (fork() == 0) {
use_temporary_dir();
do_sandbox_none();
}
}
sleep(1000000);
return 0;
}
|
the_stack_data/215768379.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 00_ft_print_program_name.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anajmi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/08 09:42:33 by anajmi #+# #+# */
/* Updated: 2021/07/11 11:17:53 by anajmi ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int main(int argc, char **argv)
{
int i;
i = 0;
while (argv[0][i] != '\0' && argc > 0)
{
write(1, &argv[0][i], 1);
i++;
}
write(1, "\n", 1);
return (0);
}
|
the_stack_data/125140456.c | #include <stdio.h>
int main(int ac, char **av) {
for (int i = 0; i < 10; i ++) {
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
}
return 0;
}
|
the_stack_data/59606.c | // from SV-COMP matrix_false.i
extern unsigned int __VERIFIER_nondet_uint();
extern int __VERIFIER_nondet_int();
int main()
{
unsigned int N_LIN=__VERIFIER_nondet_uint();
unsigned int N_COL=__VERIFIER_nondet_uint();
unsigned int j,k;
int matriz[N_COL][N_LIN], maior;
maior = __VERIFIER_nondet_int();
for(j=0;j<N_COL;j++)
for(k=0;k<N_LIN;k++)
{
matriz[j][k] = __VERIFIER_nondet_int();
if(matriz[j][k]>maior)
maior = matriz[j][k];
}
for(j=0;j<N_COL;j++)
for(k=0;k<N_LIN;k++)
assert(matriz[j][k]<=maior);
assert(matriz[0][0]<maior);
}
|
the_stack_data/154831350.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MODE_QIO 0x00
#define MODE_QOUT 0x01
#define MODE_DIO 0x02
#define MODE_DOUT 0x03
#define SIZE_4M 0x00
#define SIZE_2M 0x10
#define SIZE_8M 0x20
#define SIZE_16M 0x30
#define SIZE_32M 0x40
#define FREQ_40M 0x00
#define FREQ_26M 0x01
#define FREQ_20M 0x02
#define FREQ_80M 0x0f
int main(int argc, char *argv[])
{
int flashSize, size;
FILE *ifp, *ofp;
char *image;
if (argc < 3 || argc > 4) {
printf("usage: patch in-file out-file [1M|2M|4M]\n");
return 1;
}
if (argc < 4)
flashSize = SIZE_16M;
else {
if (strcmp(argv[3], "1M") == 0)
flashSize = SIZE_8M;
else if (strcmp(argv[3], "2M") == 0)
flashSize = SIZE_16M;
else if (strcmp(argv[3], "4M") == 0)
flashSize = SIZE_32M;
else {
printf("error: unsupported flash size '%s'\n", argv[3]);
return 1;
}
}
if (!(ifp = fopen(argv[1], "rb"))) {
printf("error: can't open %s\n", argv[2]);
return 1;
}
fseek(ifp, 0, SEEK_END);
size = ftell(ifp);
fseek(ifp, 0, SEEK_SET);
if (!(image = malloc(size))) {
printf("error: insufficient memory\n");
return 1;
}
if (fread(image, 1, size, ifp) != size) {
printf("error: reading %s\n", argv[1]);
return 1;
}
fclose(ifp);
image[2] = MODE_QIO;
image[3] = flashSize | FREQ_80M;
if (!(ofp = fopen(argv[2], "wb"))) {
printf("error: can't create %s\n", argv[3]);
return 1;
}
if (fwrite(image, 1, size, ofp) != size) {
printf("error: writing %s\n", argv[2]);
return 1;
}
fclose(ofp);
return 0;
}
|
the_stack_data/145452994.c | /* SPDX-License-Identifier: Apache-2.0 */
/* Copyright 2021 Authors of KubeArmor */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int appendByteToFile(char* path) {
FILE *fptr;
char b = 'b';
fptr = fopen(path,"a");
if(fptr == NULL) {
printf("Error!\n");
exit(1);
}
fwrite(&b, 1, 1, fptr);
fclose(fptr);
return 0;
}
int getByteFromFile(char* path) {
FILE *fptr;
char b = 0;
fptr = fopen(path,"r");
if(fptr == NULL) {
printf("Error!");
exit(1);
}
fread(&b, 1, 1, fptr);
printf("%c\n", b);
fclose(fptr);
return 0;
}
// ./readwrite [-r|-w] <path>
int main(int argc, char** argv) {
if (argc == 3) {
if (!strcmp(argv[1], "-r")) {
getByteFromFile(argv[2]);
} else if (!strcmp(argv[1], "-w")) {
appendByteToFile(argv[2]);
}
}
return 0;
}
|
the_stack_data/211081194.c | #include <stdio.h>
#define N 1000000ll
#define SUM (N * (N-1)/2)
int main (void)
{
long long a, i;
#pragma omp target parallel map(tofrom: a) shared(a) private(i)
{
#pragma omp master
a = 0;
#pragma omp barrier
#pragma omp for reduction(+:a)
for (i = 0; i < N; i++) {
a += i;
}
// The Sum shall be sum:[0:N]
#pragma omp single
{
if (a != SUM)
printf ("Incorrect result on target = %lld, expected = %lld!\n", a, SUM);
else
printf ("The result is correct on target = %lld!\n", a);
}
}
if (a != SUM){
printf("Fail!\n");
return 1;
}
printf("Success!\n");
return 0;
}
|
the_stack_data/367963.c | /** @file patest_unplug.c
@ingroup test_src
@brief Debug a crash involving unplugging a USB device.
@author Phil Burk http://www.softsynth.com
*/
/*
* $Id$
*
* This program uses the PortAudio Portable Audio Library.
* For more information see: http://www.portaudio.com
* Copyright (c) 1999-2000 Ross Bencina and Phil Burk
*
* 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.
*/
/*
* The text above constitutes the entire PortAudio license; however,
* the PortAudio community also makes the following non-binding requests:
*
* Any person wishing to distribute modifications to the Software is
* requested to send the modifications to the original developer so that
* they can be incorporated into the canonical version. It is also
* requested that these non-binding requests be included along with the
* license above.
*/
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <math.h>
#include "portaudio.h"
#define NUM_SECONDS (8)
#define SAMPLE_RATE (44100)
#ifndef M_PI
#define M_PI (3.14159265)
#endif
#define TABLE_SIZE (200)
#define FRAMES_PER_BUFFER (64)
#define MAX_CHANNELS (8)
typedef struct
{
short sine[TABLE_SIZE];
int32_t phases[MAX_CHANNELS];
int32_t numChannels;
int32_t sampsToGo;
}
paTestData;
static int inputCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData )
{
paTestData *data = (paTestData*)userData;
int finished = 0;
(void) inputBuffer; /* Prevent "unused variable" warnings. */
(void) outputBuffer; /* Prevent "unused variable" warnings. */
data->sampsToGo -= framesPerBuffer;
if (data->sampsToGo <= 0)
{
data->sampsToGo = 0;
finished = 1;
}
return finished;
}
static int outputCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData )
{
paTestData *data = (paTestData*)userData;
short *out = (short*)outputBuffer;
unsigned int i;
int finished = 0;
(void) inputBuffer; /* Prevent "unused variable" warnings. */
for( i=0; i<framesPerBuffer; i++ )
{
for (int channelIndex = 0; channelIndex < data->numChannels; channelIndex++)
{
int phase = data->phases[channelIndex];
*out++ = data->sine[phase];
phase += channelIndex + 2;
if( phase >= TABLE_SIZE ) phase -= TABLE_SIZE;
data->phases[channelIndex] = phase;
}
}
return finished;
}
/*******************************************************************/
int main(int argc, char **args);
int main(int argc, char **args)
{
PaStreamParameters inputParameters;
PaStreamParameters outputParameters;
PaStream *inputStream;
PaStream *outputStream;
const PaDeviceInfo *deviceInfo;
PaError err;
paTestData data;
int i;
int totalSamps;
int inputDevice = -1;
int outputDevice = -1;
printf("Test unplugging a USB device.\n");
if( argc > 1 ) {
inputDevice = outputDevice = atoi( args[1] );
printf("Using device number %d.\n\n", inputDevice );
} else {
printf("Using default device.\n\n" );
}
memset(&data, 0, sizeof(data));
/* initialise sinusoidal wavetable */
for( i=0; i<TABLE_SIZE; i++ )
{
data.sine[i] = (short) (32767.0 * sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. ));
}
data.numChannels = 2;
data.sampsToGo = totalSamps = NUM_SECONDS * SAMPLE_RATE; /* Play for a few seconds. */
err = Pa_Initialize();
if( err != paNoError ) goto error;
if( inputDevice == -1 )
inputParameters.device = Pa_GetDefaultInputDevice(); /* default input device */
else
inputParameters.device = inputDevice ;
if (inputParameters.device == paNoDevice) {
fprintf(stderr,"Error: No default input device.\n");
goto error;
}
if( outputDevice == -1 )
outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */
else
outputParameters.device = outputDevice ;
if (outputParameters.device == paNoDevice) {
fprintf(stderr,"Error: No default output device.\n");
goto error;
}
inputParameters.channelCount = 2;
inputParameters.sampleFormat = paInt16;
deviceInfo = Pa_GetDeviceInfo( inputParameters.device );
if( deviceInfo == NULL )
{
fprintf( stderr, "No matching input device.\n" );
goto error;
}
inputParameters.suggestedLatency = deviceInfo->defaultLowInputLatency;
inputParameters.hostApiSpecificStreamInfo = NULL;
err = Pa_OpenStream(
&inputStream,
&inputParameters,
NULL,
SAMPLE_RATE,
FRAMES_PER_BUFFER,
0,
inputCallback,
&data );
if( err != paNoError ) goto error;
outputParameters.channelCount = 2;
outputParameters.sampleFormat = paInt16;
deviceInfo = Pa_GetDeviceInfo( outputParameters.device );
if( deviceInfo == NULL )
{
fprintf( stderr, "No matching output device.\n" );
goto error;
}
outputParameters.suggestedLatency = deviceInfo->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;
err = Pa_OpenStream(
&outputStream,
NULL,
&outputParameters,
SAMPLE_RATE,
FRAMES_PER_BUFFER,
(paClipOff | paDitherOff),
outputCallback,
&data );
if( err != paNoError ) goto error;
err = Pa_StartStream( inputStream );
if( err != paNoError ) goto error;
err = Pa_StartStream( outputStream );
if( err != paNoError ) goto error;
printf("When you hear sound, unplug the USB device.\n");
do
{
Pa_Sleep(500);
printf("Frames remaining = %d\n", data.sampsToGo);
printf("Pa_IsStreamActive(inputStream) = %d\n", Pa_IsStreamActive(inputStream));
printf("Pa_IsStreamActive(outputStream) = %d\n", Pa_IsStreamActive(outputStream));
} while( Pa_IsStreamActive(inputStream) && Pa_IsStreamActive(outputStream) );
err = Pa_CloseStream( inputStream );
if( err != paNoError ) goto error;
err = Pa_CloseStream( outputStream );
if( err != paNoError ) goto error;
Pa_Terminate();
return paNoError;
error:
Pa_Terminate();
fprintf( stderr, "An error occured while using the portaudio stream\n" );
fprintf( stderr, "Error number: %d\n", err );
fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );
fprintf( stderr, "Host Error message: %s\n", Pa_GetLastHostErrorInfo()->errorText );
return err;
}
|
the_stack_data/122015548.c | /* PR optimization/5887 */
/* { dg-do compile } */
/* { dg-options "-O2" } */
/* { dg-options "-O2 -msse -ffast-math" { target i?86-*-* } } */
void bar (float *a, float *b);
void foo (char *x)
{
float a, b;
char c[256];
int i, j;
bar (&a, &b);
for (i = 0; i < 256; i++)
{
float v = a;
if (v < 0.0f) v = 0.0f;
if (v < 255.0f) v = 255.0f;
c[i] = v;
a += b;
}
for (j = 0; j < 256; j++)
x[j] = c[j];
}
|
the_stack_data/60384.c | /* First example of a c program */
#include <stdio.h>
main() {
printf("\nThis is the first, very simple c program.\n");
printf("\n'printf' cannot only print text\n");
printf("but also calculate certain things for us.\n\n");
printf("8 * 23 = %i \n", 8 * 23);
} |
the_stack_data/126702027.c | #include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
unsigned int scores[1024];
unsigned int players = 0;
unsigned int player = 0;
unsigned int last = 0;
unsigned int maxscore = 0;
typedef struct vec {
unsigned int val;
struct vec* next;
struct vec* prev;
} vec;
vec* root;
vec* circled;
void insert_after(unsigned int m, vec* position) {
vec* new_node = (vec*)malloc(sizeof(vec));
vec* right = position->next;
new_node->val = m; new_node->prev=position;new_node->next=right;
position->next = new_node;
right->prev=new_node;
circled = new_node;
}
void remove_at(vec* position) {
vec* left = position->prev;
vec* right = position->next;
left->next = right;
right->prev = left;
}
int main(int argc, char** argv) {
if (argc < 2) return 1;
char* input = argv[1];
clock_t start = clock();
sscanf(input, "%d players; last marble is worth %d points\n", &players, &last);
root = (vec*)malloc(sizeof(vec));
root->val = 0; root->prev = root; root->next = root;
circled = root;
memset(scores, 0, sizeof(unsigned int) * players);
for(unsigned int round = 1; round <= last; ++round) {
player = (player == players)?1:player + 1;
if (round % 23 == 0) {
scores[player] += round;
vec* to_remove = circled->prev->prev->prev->prev->prev->prev->prev;
circled = to_remove->next;
scores[player] += to_remove->val;
remove_at(to_remove);
maxscore = scores[player] > maxscore?scores[player]:maxscore;
}
else insert_after(round, circled->next );
}
printf("_duration:%f\n", (float)(clock() - start) * 1000.0 / CLOCKS_PER_SEC);
printf("%d\n",maxscore);
return 0;
}
|
the_stack_data/242329929.c | /* $OpenBSD: s_cprojf.c,v 1.1 2008/09/07 20:36:09 martynas Exp $ */
/*
* Copyright (c) 2008 Martynas Venckus <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <complex.h>
#include <math.h>
float complex
cprojf(float complex z)
{
float complex res;
if (isinf(__real__ z) || isinf(__imag__ z)) {
__real__ res = INFINITY;
__imag__ res = copysign(0.0, __imag__ z);
}
return res;
}
|
the_stack_data/83952.c | /*
* Copyright 1996-2018 Cyberbotics Ltd.
*
* 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.
*/
#ifndef _WIN32 // not supported on Linux and macOS
int main() {
return 1;
}
#else
#include <webots/distance_sensor.h>
#include <webots/led.h>
#include <webots/motor.h>
#include <webots/position_sensor.h>
#include <webots/robot.h>
#include <webots/touch_sensor.h>
#include <stdio.h>
#include <unistd.h>
#include <windows.h>
#define NAMED_PIPE_NAME "\\\\.\\Pipe\\picaxe-webots"
#define SIMULATION_STATE_START 1
#define SIMULATION_STATE_STOP 2
#define SIMULATION_STATE_PAUSE 3
static int pinsB = 0;
static int pinsC = 0;
static int dirsB = 0;
static int number_of_updates = 0;
static int simulation_delay = 0;
static double time_step = 0;
static int simulation_state = SIMULATION_STATE_STOP;
static int current_sound = -1;
static int suspended_sound = -1;
static WbDeviceTag gear = 0;
static WbDeviceTag gear_sensor = 0;
static WbDeviceTag gate = 0;
static WbDeviceTag gate_sensor = 0;
static WbDeviceTag rail = 0;
static WbDeviceTag closed_sensor = 0;
static WbDeviceTag open_sensor = 0;
static WbDeviceTag lamp = 0;
static WbDeviceTag optical_barrier = 0;
static WbDeviceTag inside_button = 0;
static WbDeviceTag outside_button = 0;
static char handle_message_line(const char *line) {
if (strncmp(line, "number_of_updates:", 18) == 0) {
sscanf(&line[18], "%d", &number_of_updates);
return 0;
}
char return_value = 0;
if (strncmp(line, "pinsB:", 6) == 0)
sscanf(&line[6], "%d", &pinsB);
else if (strncmp(line, "dirsB:", 6) == 0)
sscanf(&line[6], "%d", &dirsB);
else if (strncasecmp(line, "SimulationState:", 16) == 0) {
// printf("simulation state: %s\n",&line[16]);
if (strncasecmp(&line[16], "START", 5) == 0 || strncasecmp(&line[16], "STEP", 4) == 0)
simulation_state = SIMULATION_STATE_START;
else if (strncasecmp(&line[16], "STOP", 4) == 0)
simulation_state = SIMULATION_STATE_STOP;
else if (strncasecmp(&line[16], "PAUSE", 5) == 0)
simulation_state = SIMULATION_STATE_PAUSE;
} else if (strncasecmp(line, "SimulationDelay:", 16) == 0) {
sscanf(&line[16], "%d", &simulation_delay);
return_value = 1;
} else if (strncasecmp(line, "SimulationType:", 15) == 0) {
if (strncasecmp(&line[15], "PICAXE-28X2", 11) != 0) {
fprintf(stderr, "ERROR: unsupported PICAXE type for portal: %s\n", &line[15]);
fprintf(stderr, "Please select 'PICAXE-28X2' in PICAXE Editor ");
fprintf(stderr, "from the 'Settings' tab in the Workspace Explorer.\n");
}
} else if (strncasecmp(line, "SimulationPinSize:", 18) == 0) {
if (strncasecmp(&line[18], "28", 2) != 0)
fprintf(stderr, "ERROR: unsupported pin size for portal: %s (should be 28)\n", &line[18]);
}
number_of_updates--;
return return_value;
}
// returns 1 if simulation_delay was set
static char handle_message(const char *input_buffer) {
char return_value = 0;
int i = 0, l = strlen(input_buffer);
if (l == 2) // sometimes PE send a "\r\n" sequence which we can ignore
return 0;
do {
handle_message_line(input_buffer); // set number_of_updates
// printf("number of updates=%d\n",number_of_updates);
while (i < l && number_of_updates > 0) {
if (input_buffer[i] == '\n') {
if (handle_message_line(&input_buffer[i + 1]))
return_value = 1;
// printf("number of updates=%d\n",number_of_updates);
}
i++;
}
// printf("pinsB:%d\n",pinsB);
} while (i < l);
return return_value;
}
static const char *compute_update() {
static char output_buffer[1024];
snprintf(output_buffer, 1024, "number_of_updates:1\r\npinsC:%d\r\n", pinsC);
return output_buffer;
}
static void play_sound(int i) {
static const char *sound_file[2] = {"electric_motor_load.wav", "electric_motor_no_load.wav"};
if (i == current_sound)
return;
int size = sizeof(sound_file) / sizeof(char *);
if (i >= size)
return;
if (i == -1)
PlaySound(NULL, 0, 0);
else
PlaySound(TEXT(sound_file[i]), NULL, SND_FILENAME | SND_ASYNC | SND_LOOP);
current_sound = i;
}
int main() {
HANDLE pipe_handle = NULL;
char input_buffer[1024];
char received_initialization = 0;
wb_robot_init();
gear = wb_robot_get_device("gear");
gear_sensor = wb_robot_get_device("gear_sensor");
gate = wb_robot_get_device("gate");
gate_sensor = wb_robot_get_device("gate_sensor");
rail = wb_robot_get_device("rail");
closed_sensor = wb_robot_get_device("closed");
open_sensor = wb_robot_get_device("open");
outside_button = wb_robot_get_device("outside button");
inside_button = wb_robot_get_device("inside button");
optical_barrier = wb_robot_get_device("optical barrier");
lamp = wb_robot_get_device("lamp");
time_step = wb_robot_get_basic_time_step();
wb_touch_sensor_enable(closed_sensor, time_step);
wb_touch_sensor_enable(open_sensor, time_step);
wb_touch_sensor_enable(outside_button, time_step);
wb_touch_sensor_enable(inside_button, time_step);
wb_position_sensor_enable(gear_sensor, time_step);
wb_position_sensor_enable(gate_sensor, time_step);
for (;;) {
if (pipe_handle == NULL) {
pipe_handle =
CreateFile(NAMED_PIPE_NAME, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (pipe_handle == INVALID_HANDLE_VALUE)
pipe_handle = NULL; // try again later
else
printf("Connected with Picaxe software\n");
received_initialization = 0;
}
if (pipe_handle) {
DWORD e = NO_ERROR, nb_read = 0;
if (!PeekNamedPipe(pipe_handle, NULL, 0, NULL, &nb_read, NULL)) {
e = GetLastError();
if (e == ERROR_BROKEN_PIPE) {
fprintf(stderr, "Lost connection with PICAXE software\n");
CloseHandle(pipe_handle);
pipe_handle = NULL;
nb_read = 0;
} else
fprintf(stderr, "PeekNamedPipe error = %d\n", (int)e);
}
if (nb_read) {
DWORD total_read = 0;
BOOL success = false;
input_buffer[0] = 0; // clear input buffer
do {
nb_read = 0;
// printf("receiving data from PICAXE software\n");
success = ReadFile(pipe_handle, &input_buffer[total_read], sizeof(input_buffer) - total_read, &nb_read, NULL);
total_read += nb_read;
input_buffer[total_read] = '\0';
// printf("received %d bytes: %s\n",strlen(input_buffer),input_buffer);
if (!success)
e = GetLastError();
} while (!success && e == ERROR_MORE_DATA);
if (success) {
input_buffer[total_read] = '\0';
if (handle_message(input_buffer))
received_initialization = 1;
} else {
if (e == ERROR_BROKEN_PIPE)
fprintf(stderr, "Lost connection with PICAXE software\n");
CloseHandle(pipe_handle);
pipe_handle = NULL;
}
}
}
if (pipe_handle && received_initialization) {
DWORD n;
const char *update = compute_update();
if (update) {
// printf("sending:\n%s\n",update);
if (WriteFile(pipe_handle, update, strlen(update) * sizeof(char) + 1, &n, NULL) == 0) {
if (GetLastError() == ERROR_BROKEN_PIPE)
fprintf(stderr, "Lost connection with PICAXE software\n");
else
fprintf(stderr, "Unknown error\n");
CloseHandle(pipe_handle);
pipe_handle = NULL;
}
fflush(stdout);
}
}
if (simulation_state == SIMULATION_STATE_PAUSE) {
if (current_sound != -1) {
suspended_sound = current_sound;
play_sound(-1);
}
usleep(time_step * 1000);
continue;
} else if (simulation_state == SIMULATION_STATE_START) {
if (suspended_sound != -1) {
play_sound(suspended_sound);
suspended_sound = -1;
}
} else if (simulation_state == SIMULATION_STATE_STOP) {
// reset every actuator to initial value
double gate_position = wb_position_sensor_get_value(gate_sensor);
double gear_position = wb_position_sensor_get_value(gear_sensor);
if (gate_position > 0.0301 || gate_position < 0.0299)
play_sound(0);
else
play_sound(-1);
if (gate_position > 0.0301)
wb_motor_set_position(gear, -INFINITY);
else if (gate_position < 0.0299)
wb_motor_set_position(gear, INFINITY);
else if (!isnan(gear_position))
wb_motor_set_position(gear, floor(gear_position / (M_PI / 7)) * (M_PI / 7)); // the gear has 14 teeth
wb_motor_set_position(rail, 0);
wb_motor_set_position(gate, 0.03);
wb_led_set(lamp, 0);
wb_robot_step(time_step);
continue;
}
wb_led_set(lamp, pinsB & dirsB & 1);
double gear_position = wb_position_sensor_get_value(gear_sensor);
double gate_position = wb_position_sensor_get_value(gate_sensor);
if ((pinsB & dirsB & (64 + 128)) == 64) {
wb_motor_set_position(gate, 0); // portal closed position
wb_motor_set_position(gear, -INFINITY);
if (gate_position <= 0.01) { // derail position
play_sound(1);
wb_motor_set_position(rail, -0.005);
} else {
play_sound(0);
wb_motor_set_position(rail, 0);
}
} else if ((pinsB & dirsB & (64 + 128)) == 128) {
wb_motor_set_position(gate, 0.3); // portal open position
wb_motor_set_position(gear, INFINITY);
if (gate_position >= 0.29) { // derail position
play_sound(1);
wb_motor_set_position(rail, -0.005);
} else {
play_sound(0);
wb_motor_set_position(rail, 0);
}
} else if ((pinsB & dirsB & (64 + 128)) == (64 + 128) || (pinsB & dirsB & (64 + 128)) == 0) { // STOP the motors
play_sound(-1);
if (!isnan(gear_position))
wb_motor_set_position(gear, gear_position);
if (!isnan(gate_position))
wb_motor_set_position(gate, gate_position);
}
if (pinsB & dirsB & 2)
wb_distance_sensor_enable(optical_barrier, time_step);
else
wb_distance_sensor_disable(optical_barrier);
wb_robot_step(time_step);
pinsC = 1 * (int)wb_touch_sensor_get_value(outside_button) + 2 * (int)wb_touch_sensor_get_value(open_sensor) +
4 * (int)wb_touch_sensor_get_value(closed_sensor) + 8 * (int)wb_touch_sensor_get_value(inside_button);
if (pinsB & dirsB & 2) {
pinsC += 16 * ((wb_distance_sensor_get_value(optical_barrier) < 936) ? 1 : 0);
}
}
if (pipe_handle)
CloseHandle(pipe_handle);
return 0;
}
#endif // _WIN32
|
the_stack_data/51701015.c | #include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <fcntl.h>
#define BUFFER_SIZEONE_TWO 10
#define BUFFER_SIZETWO_THREE 20
struct Buffer {
char line[256];
};
struct Buffer first_buffer[BUFFER_SIZEONE_TWO];
struct Buffer second_buffer[BUFFER_SIZETWO_THREE];
int in=0, out=0, in_TwoThree=0, out_TwoThree=0, num_lines=0,readsize=1,word_count=0,total_word=0,inputFile;
char ary, numeral[2],line_numeral[2];
//convert integer to string numeral
char* line_Numeral(int num){
int temp, temp2, digit_size=0,startpos=0;
temp = num;
temp2 = num;
static char string_numeral[5];
while ( temp > 0 ){
temp = temp / 10;
digit_size++;
}
startpos= digit_size-1;
while ( startpos >= 0 ){
temp = temp2 % 10;
string_numeral[startpos] = '0' + temp;
temp2 = temp2 / 10;
startpos--;
}
string_numeral[digit_size]='\0';
return string_numeral;
}
void *thread_one(void *arg) {
while(1){
int i = 0, temp;
while((readsize =read( inputFile, &ary, 1))>0){
if(ary=='\n'){
temp = i-1;
//removing whitespaces from last to first
while(temp > 0){
if(first_buffer[in].line[temp]== '\n' || first_buffer[in].line[temp] == '\t' || first_buffer[in].line[temp]==' '){
temp--;
}else break;
}
//adding \n right after the last character other than whitespace
first_buffer[in].line[temp]='\n';
break;}
else{
first_buffer[in].line[i]=ary;
i++;
}
}
//break when end of file is reached.
if (readsize == 0){
break;
}
while(((in+1)%BUFFER_SIZEONE_TWO)==out){
sched_yield();
}
in = (in+1)%BUFFER_SIZEONE_TWO;
}
}
void *thread_two(void *arg) {
while(1){
while(in==out){
sched_yield();
}
int pos=0,j=0;
// Reading from the first buffer one line at a time.
while (first_buffer[out].line[pos] != '\0') {
if(first_buffer[out].line[pos]==' ' || first_buffer[out].line[pos]=='\n'){
// creates a c-string appened with '\0' when space is encountered
second_buffer[in_TwoThree].line[j]='\0';
in_TwoThree = (in_TwoThree+1)%BUFFER_SIZETWO_THREE;
j=0;
while(((in_TwoThree+1)%BUFFER_SIZETWO_THREE)==out_TwoThree){
sched_yield();
}
}else{
// Read from the first buffer and assigns the word into second buffer.
second_buffer[in_TwoThree].line[j] = first_buffer[out].line[pos];
j++;
}
pos++;
}
for (int k=0;k<256;k++){
first_buffer[out].line[k]='\0';
}
num_lines++;
sleep(1);
write(1,"*",2);
write(1,"word count:",12);
write(1, line_Numeral(word_count), 4);
write(1,"*",2);
write(1,"\n*line count:",14);
write(1, line_Numeral(num_lines), 4);
write(1,"*",2);
write(1,"\n\n",3);
word_count=0;
out = ( out + 1 ) % BUFFER_SIZEONE_TWO;
}
}
void *thread_three(void *arg) {
while(1){
while(in_TwoThree==out_TwoThree){
sched_yield();
}
// Ignore empty strings
if( second_buffer[out_TwoThree].line[0]=='\0'){
}else{
// Prints words from second buffer.
write(1,"*",2);
write(1,&second_buffer[out_TwoThree].line,sizeof(second_buffer[out_TwoThree].line));
write(1,"*\n",3);
word_count++;
total_word++;
}
//Emptying the buffer after each read
for (int k=0;k<256;k++){
second_buffer[out_TwoThree].line[k]='\0';
}
out_TwoThree = (out_TwoThree+1)%BUFFER_SIZETWO_THREE;
}
}
int main(int argc, const char *argv[]) {
pthread_t t1, t2, t3;
if ((inputFile = open(argv[1], O_RDONLY, 0)) == -1){
write(1,"Could not open file", 16);
return 2;
}
if (pthread_create(&t1, NULL, thread_one,"thread 1") != 0) {
perror("pthread_create() error");
exit(1);
}
if (pthread_create(&t2, NULL, thread_two, "thread 2") != 0) {
perror("pthread_create() error");
exit(2);
}
if (pthread_create(&t3, NULL, thread_three, "thread 3") != 0) {
perror("pthread_create() error");
exit(3);
}
if(pthread_join(t1,NULL)!=0){
perror("failed to join");
}
if(pthread_join(t2,NULL)!=0){
perror("failed to join");
}
if(pthread_join(t3,NULL)!=0){
perror("failed to join");
}
close(inputFile);
exit(0); /* this will tear all threads down */
} |
the_stack_data/73575581.c | extern float __VERIFIER_nondet_float(void);
extern int __VERIFIER_nondet_int(void);
typedef enum {false, true} bool;
bool __VERIFIER_nondet_bool(void) {
return __VERIFIER_nondet_int() != 0;
}
int main()
{
float _diverge_delta, _x__diverge_delta;
float delta, _x_delta;
bool s8_l1, _x_s8_l1;
bool s8_l0, _x_s8_l0;
bool bus_l1, _x_bus_l1;
bool bus_l0, _x_bus_l0;
bool s5_l1, _x_s5_l1;
float s8_x, _x_s8_x;
bool s5_l0, _x_s5_l0;
float s5_x, _x_s5_x;
bool s2_l1, _x_s2_l1;
float bus_x, _x_bus_x;
bool s2_l0, _x_s2_l0;
float s2_x, _x_s2_x;
bool s8_evt0, _x_s8_evt0;
bool s8_evt1, _x_s8_evt1;
int bus_j, _x_bus_j;
bool s5_evt0, _x_s5_evt0;
bool s8_evt2, _x_s8_evt2;
bool s5_evt1, _x_s5_evt1;
bool s5_evt2, _x_s5_evt2;
bool s2_evt0, _x_s2_evt0;
bool s2_evt1, _x_s2_evt1;
bool bus_evt1, _x_bus_evt1;
bool s2_evt2, _x_s2_evt2;
bool bus_evt0, _x_bus_evt0;
bool bus_evt2, _x_bus_evt2;
bool _J1811, _x__J1811;
bool _J1805, _x__J1805;
bool s6_l1, _x_s6_l1;
bool _J1799, _x__J1799;
bool s6_l0, _x_s6_l0;
bool _J1790, _x__J1790;
bool _EL_U_1763, _x__EL_U_1763;
float s6_x, _x_s6_x;
bool s0_l1, _x_s0_l1;
bool s3_l1, _x_s3_l1;
bool s0_l0, _x_s0_l0;
bool s3_l0, _x_s3_l0;
float s3_x, _x_s3_x;
bool _EL_U_1765, _x__EL_U_1765;
float s0_x, _x_s0_x;
bool _EL_U_1767, _x__EL_U_1767;
bool s6_evt0, _x_s6_evt0;
bool _EL_U_1770, _x__EL_U_1770;
bool s6_evt1, _x_s6_evt1;
bool s6_evt2, _x_s6_evt2;
bool s3_evt0, _x_s3_evt0;
bool s3_evt1, _x_s3_evt1;
bool s3_evt2, _x_s3_evt2;
bool s0_evt0, _x_s0_evt0;
bool s0_evt1, _x_s0_evt1;
bool s0_evt2, _x_s0_evt2;
int bus_cd_id, _x_bus_cd_id;
bool s7_l1, _x_s7_l1;
bool s7_l0, _x_s7_l0;
float s7_x, _x_s7_x;
bool s4_l1, _x_s4_l1;
bool s4_l0, _x_s4_l0;
bool s1_l1, _x_s1_l1;
float s4_x, _x_s4_x;
bool s1_l0, _x_s1_l0;
float s1_x, _x_s1_x;
bool s7_evt0, _x_s7_evt0;
bool s7_evt1, _x_s7_evt1;
bool s7_evt2, _x_s7_evt2;
bool s4_evt0, _x_s4_evt0;
bool s4_evt1, _x_s4_evt1;
bool s4_evt2, _x_s4_evt2;
bool s1_evt0, _x_s1_evt0;
bool s1_evt1, _x_s1_evt1;
bool s1_evt2, _x_s1_evt2;
int __steps_to_fair = __VERIFIER_nondet_int();
_diverge_delta = __VERIFIER_nondet_float();
delta = __VERIFIER_nondet_float();
s8_l1 = __VERIFIER_nondet_bool();
s8_l0 = __VERIFIER_nondet_bool();
bus_l1 = __VERIFIER_nondet_bool();
bus_l0 = __VERIFIER_nondet_bool();
s5_l1 = __VERIFIER_nondet_bool();
s8_x = __VERIFIER_nondet_float();
s5_l0 = __VERIFIER_nondet_bool();
s5_x = __VERIFIER_nondet_float();
s2_l1 = __VERIFIER_nondet_bool();
bus_x = __VERIFIER_nondet_float();
s2_l0 = __VERIFIER_nondet_bool();
s2_x = __VERIFIER_nondet_float();
s8_evt0 = __VERIFIER_nondet_bool();
s8_evt1 = __VERIFIER_nondet_bool();
bus_j = __VERIFIER_nondet_int();
s5_evt0 = __VERIFIER_nondet_bool();
s8_evt2 = __VERIFIER_nondet_bool();
s5_evt1 = __VERIFIER_nondet_bool();
s5_evt2 = __VERIFIER_nondet_bool();
s2_evt0 = __VERIFIER_nondet_bool();
s2_evt1 = __VERIFIER_nondet_bool();
bus_evt1 = __VERIFIER_nondet_bool();
s2_evt2 = __VERIFIER_nondet_bool();
bus_evt0 = __VERIFIER_nondet_bool();
bus_evt2 = __VERIFIER_nondet_bool();
_J1811 = __VERIFIER_nondet_bool();
_J1805 = __VERIFIER_nondet_bool();
s6_l1 = __VERIFIER_nondet_bool();
_J1799 = __VERIFIER_nondet_bool();
s6_l0 = __VERIFIER_nondet_bool();
_J1790 = __VERIFIER_nondet_bool();
_EL_U_1763 = __VERIFIER_nondet_bool();
s6_x = __VERIFIER_nondet_float();
s0_l1 = __VERIFIER_nondet_bool();
s3_l1 = __VERIFIER_nondet_bool();
s0_l0 = __VERIFIER_nondet_bool();
s3_l0 = __VERIFIER_nondet_bool();
s3_x = __VERIFIER_nondet_float();
_EL_U_1765 = __VERIFIER_nondet_bool();
s0_x = __VERIFIER_nondet_float();
_EL_U_1767 = __VERIFIER_nondet_bool();
s6_evt0 = __VERIFIER_nondet_bool();
_EL_U_1770 = __VERIFIER_nondet_bool();
s6_evt1 = __VERIFIER_nondet_bool();
s6_evt2 = __VERIFIER_nondet_bool();
s3_evt0 = __VERIFIER_nondet_bool();
s3_evt1 = __VERIFIER_nondet_bool();
s3_evt2 = __VERIFIER_nondet_bool();
s0_evt0 = __VERIFIER_nondet_bool();
s0_evt1 = __VERIFIER_nondet_bool();
s0_evt2 = __VERIFIER_nondet_bool();
bus_cd_id = __VERIFIER_nondet_int();
s7_l1 = __VERIFIER_nondet_bool();
s7_l0 = __VERIFIER_nondet_bool();
s7_x = __VERIFIER_nondet_float();
s4_l1 = __VERIFIER_nondet_bool();
s4_l0 = __VERIFIER_nondet_bool();
s1_l1 = __VERIFIER_nondet_bool();
s4_x = __VERIFIER_nondet_float();
s1_l0 = __VERIFIER_nondet_bool();
s1_x = __VERIFIER_nondet_float();
s7_evt0 = __VERIFIER_nondet_bool();
s7_evt1 = __VERIFIER_nondet_bool();
s7_evt2 = __VERIFIER_nondet_bool();
s4_evt0 = __VERIFIER_nondet_bool();
s4_evt1 = __VERIFIER_nondet_bool();
s4_evt2 = __VERIFIER_nondet_bool();
s1_evt0 = __VERIFIER_nondet_bool();
s1_evt1 = __VERIFIER_nondet_bool();
s1_evt2 = __VERIFIER_nondet_bool();
bool __ok = (((((((((( !s8_l0) && ( !s8_l1)) && (s8_x == 0.0)) && ((( !s8_evt2) && (s8_evt0 && ( !s8_evt1))) || (((( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1))) || (s8_evt2 && (( !s8_evt0) && ( !s8_evt1)))) || ((( !s8_evt2) && (s8_evt1 && ( !s8_evt0))) || (s8_evt2 && (s8_evt1 && ( !s8_evt0))))))) && ((( !s8_l0) && ( !s8_l1)) || ((s8_l1 && ( !s8_l0)) || (s8_l0 && ( !s8_l1))))) && ((s8_x <= 404.0) || ( !(s8_l1 && ( !s8_l0))))) && ((s8_x <= 26.0) || ( !(s8_l0 && ( !s8_l1))))) && (((((((( !s7_l0) && ( !s7_l1)) && (s7_x == 0.0)) && ((( !s7_evt2) && (s7_evt0 && ( !s7_evt1))) || (((( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1))) || (s7_evt2 && (( !s7_evt0) && ( !s7_evt1)))) || ((( !s7_evt2) && (s7_evt1 && ( !s7_evt0))) || (s7_evt2 && (s7_evt1 && ( !s7_evt0))))))) && ((( !s7_l0) && ( !s7_l1)) || ((s7_l1 && ( !s7_l0)) || (s7_l0 && ( !s7_l1))))) && ((s7_x <= 404.0) || ( !(s7_l1 && ( !s7_l0))))) && ((s7_x <= 26.0) || ( !(s7_l0 && ( !s7_l1))))) && (((((((( !s6_l0) && ( !s6_l1)) && (s6_x == 0.0)) && ((( !s6_evt2) && (s6_evt0 && ( !s6_evt1))) || (((( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1))) || (s6_evt2 && (( !s6_evt0) && ( !s6_evt1)))) || ((( !s6_evt2) && (s6_evt1 && ( !s6_evt0))) || (s6_evt2 && (s6_evt1 && ( !s6_evt0))))))) && ((( !s6_l0) && ( !s6_l1)) || ((s6_l1 && ( !s6_l0)) || (s6_l0 && ( !s6_l1))))) && ((s6_x <= 404.0) || ( !(s6_l1 && ( !s6_l0))))) && ((s6_x <= 26.0) || ( !(s6_l0 && ( !s6_l1))))) && (((((((( !s5_l0) && ( !s5_l1)) && (s5_x == 0.0)) && ((( !s5_evt2) && (s5_evt0 && ( !s5_evt1))) || (((( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1))) || (s5_evt2 && (( !s5_evt0) && ( !s5_evt1)))) || ((( !s5_evt2) && (s5_evt1 && ( !s5_evt0))) || (s5_evt2 && (s5_evt1 && ( !s5_evt0))))))) && ((( !s5_l0) && ( !s5_l1)) || ((s5_l1 && ( !s5_l0)) || (s5_l0 && ( !s5_l1))))) && ((s5_x <= 404.0) || ( !(s5_l1 && ( !s5_l0))))) && ((s5_x <= 26.0) || ( !(s5_l0 && ( !s5_l1))))) && (((((((( !s4_l0) && ( !s4_l1)) && (s4_x == 0.0)) && ((( !s4_evt2) && (s4_evt0 && ( !s4_evt1))) || (((( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1))) || (s4_evt2 && (( !s4_evt0) && ( !s4_evt1)))) || ((( !s4_evt2) && (s4_evt1 && ( !s4_evt0))) || (s4_evt2 && (s4_evt1 && ( !s4_evt0))))))) && ((( !s4_l0) && ( !s4_l1)) || ((s4_l1 && ( !s4_l0)) || (s4_l0 && ( !s4_l1))))) && ((s4_x <= 404.0) || ( !(s4_l1 && ( !s4_l0))))) && ((s4_x <= 26.0) || ( !(s4_l0 && ( !s4_l1))))) && (((((((( !s3_l0) && ( !s3_l1)) && (s3_x == 0.0)) && ((( !s3_evt2) && (s3_evt0 && ( !s3_evt1))) || (((( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1))) || (s3_evt2 && (( !s3_evt0) && ( !s3_evt1)))) || ((( !s3_evt2) && (s3_evt1 && ( !s3_evt0))) || (s3_evt2 && (s3_evt1 && ( !s3_evt0))))))) && ((( !s3_l0) && ( !s3_l1)) || ((s3_l1 && ( !s3_l0)) || (s3_l0 && ( !s3_l1))))) && ((s3_x <= 404.0) || ( !(s3_l1 && ( !s3_l0))))) && ((s3_x <= 26.0) || ( !(s3_l0 && ( !s3_l1))))) && (((((((( !s2_l0) && ( !s2_l1)) && (s2_x == 0.0)) && ((( !s2_evt2) && (s2_evt0 && ( !s2_evt1))) || (((( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1))) || (s2_evt2 && (( !s2_evt0) && ( !s2_evt1)))) || ((( !s2_evt2) && (s2_evt1 && ( !s2_evt0))) || (s2_evt2 && (s2_evt1 && ( !s2_evt0))))))) && ((( !s2_l0) && ( !s2_l1)) || ((s2_l1 && ( !s2_l0)) || (s2_l0 && ( !s2_l1))))) && ((s2_x <= 404.0) || ( !(s2_l1 && ( !s2_l0))))) && ((s2_x <= 26.0) || ( !(s2_l0 && ( !s2_l1))))) && (((((((( !s1_l0) && ( !s1_l1)) && (s1_x == 0.0)) && ((( !s1_evt2) && (s1_evt0 && ( !s1_evt1))) || (((( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1))) || (s1_evt2 && (( !s1_evt0) && ( !s1_evt1)))) || ((( !s1_evt2) && (s1_evt1 && ( !s1_evt0))) || (s1_evt2 && (s1_evt1 && ( !s1_evt0))))))) && ((( !s1_l0) && ( !s1_l1)) || ((s1_l1 && ( !s1_l0)) || (s1_l0 && ( !s1_l1))))) && ((s1_x <= 404.0) || ( !(s1_l1 && ( !s1_l0))))) && ((s1_x <= 26.0) || ( !(s1_l0 && ( !s1_l1))))) && (((((((( !s0_l0) && ( !s0_l1)) && (s0_x == 0.0)) && ((( !s0_evt2) && (s0_evt0 && ( !s0_evt1))) || (((( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1))) || (s0_evt2 && (( !s0_evt0) && ( !s0_evt1)))) || ((( !s0_evt2) && (s0_evt1 && ( !s0_evt0))) || (s0_evt2 && (s0_evt1 && ( !s0_evt0))))))) && ((( !s0_l0) && ( !s0_l1)) || ((s0_l1 && ( !s0_l0)) || (s0_l0 && ( !s0_l1))))) && ((s0_x <= 404.0) || ( !(s0_l1 && ( !s0_l0))))) && ((s0_x <= 26.0) || ( !(s0_l0 && ( !s0_l1))))) && (((((( !bus_l0) && ( !bus_l1)) && (((( !bus_evt2) && (( !bus_evt0) && ( !bus_evt1))) || (((bus_evt2 && (( !bus_evt0) && ( !bus_evt1))) || (( !bus_evt2) && (bus_evt1 && ( !bus_evt0)))) || ((bus_evt2 && (bus_evt1 && ( !bus_evt0))) || (( !bus_evt2) && (bus_evt0 && ( !bus_evt1)))))) && (((( !bus_l0) && ( !bus_l1)) || (bus_l1 && ( !bus_l0))) || ((bus_l0 && ( !bus_l1)) || (bus_l0 && bus_l1))))) && ((bus_j == 0) && (bus_x == 0.0))) && ((( !(13.0 <= bus_x)) || ( !(bus_l0 && ( !bus_l1)))) && ((delta == 0.0) || ( !(bus_l0 && bus_l1))))) && (0.0 <= delta))))))))))) && (delta == _diverge_delta)) && ((((( !(( !(_EL_U_1770 || ( !(( !(s0_l1 && ( !s0_l0))) || ((( !s0_l0) && ( !s0_l1)) || _EL_U_1767))))) || (_EL_U_1765 || ( !((1.0 <= _diverge_delta) || _EL_U_1763))))) && ( !_J1790)) && ( !_J1799)) && ( !_J1805)) && ( !_J1811)));
while (__steps_to_fair >= 0 && __ok) {
if ((((_J1790 && _J1799) && _J1805) && _J1811)) {
__steps_to_fair = __VERIFIER_nondet_int();
} else {
__steps_to_fair--;
}
_x__diverge_delta = __VERIFIER_nondet_float();
_x_delta = __VERIFIER_nondet_float();
_x_s8_l1 = __VERIFIER_nondet_bool();
_x_s8_l0 = __VERIFIER_nondet_bool();
_x_bus_l1 = __VERIFIER_nondet_bool();
_x_bus_l0 = __VERIFIER_nondet_bool();
_x_s5_l1 = __VERIFIER_nondet_bool();
_x_s8_x = __VERIFIER_nondet_float();
_x_s5_l0 = __VERIFIER_nondet_bool();
_x_s5_x = __VERIFIER_nondet_float();
_x_s2_l1 = __VERIFIER_nondet_bool();
_x_bus_x = __VERIFIER_nondet_float();
_x_s2_l0 = __VERIFIER_nondet_bool();
_x_s2_x = __VERIFIER_nondet_float();
_x_s8_evt0 = __VERIFIER_nondet_bool();
_x_s8_evt1 = __VERIFIER_nondet_bool();
_x_bus_j = __VERIFIER_nondet_int();
_x_s5_evt0 = __VERIFIER_nondet_bool();
_x_s8_evt2 = __VERIFIER_nondet_bool();
_x_s5_evt1 = __VERIFIER_nondet_bool();
_x_s5_evt2 = __VERIFIER_nondet_bool();
_x_s2_evt0 = __VERIFIER_nondet_bool();
_x_s2_evt1 = __VERIFIER_nondet_bool();
_x_bus_evt1 = __VERIFIER_nondet_bool();
_x_s2_evt2 = __VERIFIER_nondet_bool();
_x_bus_evt0 = __VERIFIER_nondet_bool();
_x_bus_evt2 = __VERIFIER_nondet_bool();
_x__J1811 = __VERIFIER_nondet_bool();
_x__J1805 = __VERIFIER_nondet_bool();
_x_s6_l1 = __VERIFIER_nondet_bool();
_x__J1799 = __VERIFIER_nondet_bool();
_x_s6_l0 = __VERIFIER_nondet_bool();
_x__J1790 = __VERIFIER_nondet_bool();
_x__EL_U_1763 = __VERIFIER_nondet_bool();
_x_s6_x = __VERIFIER_nondet_float();
_x_s0_l1 = __VERIFIER_nondet_bool();
_x_s3_l1 = __VERIFIER_nondet_bool();
_x_s0_l0 = __VERIFIER_nondet_bool();
_x_s3_l0 = __VERIFIER_nondet_bool();
_x_s3_x = __VERIFIER_nondet_float();
_x__EL_U_1765 = __VERIFIER_nondet_bool();
_x_s0_x = __VERIFIER_nondet_float();
_x__EL_U_1767 = __VERIFIER_nondet_bool();
_x_s6_evt0 = __VERIFIER_nondet_bool();
_x__EL_U_1770 = __VERIFIER_nondet_bool();
_x_s6_evt1 = __VERIFIER_nondet_bool();
_x_s6_evt2 = __VERIFIER_nondet_bool();
_x_s3_evt0 = __VERIFIER_nondet_bool();
_x_s3_evt1 = __VERIFIER_nondet_bool();
_x_s3_evt2 = __VERIFIER_nondet_bool();
_x_s0_evt0 = __VERIFIER_nondet_bool();
_x_s0_evt1 = __VERIFIER_nondet_bool();
_x_s0_evt2 = __VERIFIER_nondet_bool();
_x_bus_cd_id = __VERIFIER_nondet_int();
_x_s7_l1 = __VERIFIER_nondet_bool();
_x_s7_l0 = __VERIFIER_nondet_bool();
_x_s7_x = __VERIFIER_nondet_float();
_x_s4_l1 = __VERIFIER_nondet_bool();
_x_s4_l0 = __VERIFIER_nondet_bool();
_x_s1_l1 = __VERIFIER_nondet_bool();
_x_s4_x = __VERIFIER_nondet_float();
_x_s1_l0 = __VERIFIER_nondet_bool();
_x_s1_x = __VERIFIER_nondet_float();
_x_s7_evt0 = __VERIFIER_nondet_bool();
_x_s7_evt1 = __VERIFIER_nondet_bool();
_x_s7_evt2 = __VERIFIER_nondet_bool();
_x_s4_evt0 = __VERIFIER_nondet_bool();
_x_s4_evt1 = __VERIFIER_nondet_bool();
_x_s4_evt2 = __VERIFIER_nondet_bool();
_x_s1_evt0 = __VERIFIER_nondet_bool();
_x_s1_evt1 = __VERIFIER_nondet_bool();
_x_s1_evt2 = __VERIFIER_nondet_bool();
__ok = ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((( !_x_s8_evt2) && (_x_s8_evt0 && ( !_x_s8_evt1))) || (((( !_x_s8_evt2) && (( !_x_s8_evt0) && ( !_x_s8_evt1))) || (_x_s8_evt2 && (( !_x_s8_evt0) && ( !_x_s8_evt1)))) || ((( !_x_s8_evt2) && (_x_s8_evt1 && ( !_x_s8_evt0))) || (_x_s8_evt2 && (_x_s8_evt1 && ( !_x_s8_evt0)))))) && ((( !_x_s8_l0) && ( !_x_s8_l1)) || ((_x_s8_l1 && ( !_x_s8_l0)) || (_x_s8_l0 && ( !_x_s8_l1))))) && ((_x_s8_x <= 404.0) || ( !(_x_s8_l1 && ( !_x_s8_l0))))) && ((_x_s8_x <= 26.0) || ( !(_x_s8_l0 && ( !_x_s8_l1))))) && ((delta <= 0.0) || (((s8_l0 == _x_s8_l0) && (s8_l1 == _x_s8_l1)) && ((delta + (s8_x + (-1.0 * _x_s8_x))) == 0.0)))) && ((((s8_l0 == _x_s8_l0) && (s8_l1 == _x_s8_l1)) && ((delta + (s8_x + (-1.0 * _x_s8_x))) == 0.0)) || ( !(( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))) && (((_x_s8_l0 && ( !_x_s8_l1)) || ((( !_x_s8_l0) && ( !_x_s8_l1)) || (_x_s8_l1 && ( !_x_s8_l0)))) || ( !((( !s8_l0) && ( !s8_l1)) && ((delta == 0.0) && ( !(( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1))))))))) && (((( !s8_evt2) && (s8_evt0 && ( !s8_evt1))) && (_x_s8_x == 0.0)) || ( !((( !_x_s8_l0) && ( !_x_s8_l1)) && ((( !s8_l0) && ( !s8_l1)) && ((delta == 0.0) && ( !(( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))))))) && (((s8_evt2 && (( !s8_evt0) && ( !s8_evt1))) && (_x_s8_x == 0.0)) || ( !((_x_s8_l1 && ( !_x_s8_l0)) && ((( !s8_l0) && ( !s8_l1)) && ((delta == 0.0) && ( !(( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))))))) && (((_x_s8_x == 0.0) && ((s8_evt2 && (s8_evt1 && ( !s8_evt0))) || (( !s8_evt2) && (s8_evt0 && ( !s8_evt1))))) || ( !((_x_s8_l0 && ( !_x_s8_l1)) && ((( !s8_l0) && ( !s8_l1)) && ((delta == 0.0) && ( !(( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))))))) && (((( !_x_s8_l0) && ( !_x_s8_l1)) || (_x_s8_l0 && ( !_x_s8_l1))) || ( !((s8_l1 && ( !s8_l0)) && ((delta == 0.0) && ( !(( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1))))))))) && (((404.0 <= s8_x) && ((( !s8_evt2) && (s8_evt1 && ( !s8_evt0))) && (_x_s8_x == 0.0))) || ( !((( !_x_s8_l0) && ( !_x_s8_l1)) && ((s8_l1 && ( !s8_l0)) && ((delta == 0.0) && ( !(( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))))))) && (((s8_x <= 26.0) && ((( !s8_evt2) && (s8_evt0 && ( !s8_evt1))) && (_x_s8_x == 0.0))) || ( !((_x_s8_l0 && ( !_x_s8_l1)) && ((s8_l1 && ( !s8_l0)) && ((delta == 0.0) && ( !(( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))))))) && (((_x_s8_l1 && ( !_x_s8_l0)) || (_x_s8_l0 && ( !_x_s8_l1))) || ( !((s8_l0 && ( !s8_l1)) && ((delta == 0.0) && ( !(( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1))))))))) && (((s8_x <= 26.0) && ((( !s8_evt2) && (s8_evt0 && ( !s8_evt1))) && (_x_s8_x == 0.0))) || ( !((_x_s8_l0 && ( !_x_s8_l1)) && ((s8_l0 && ( !s8_l1)) && ((delta == 0.0) && ( !(( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))))))) && (((s8_x <= 26.0) && ((s8_evt2 && (( !s8_evt0) && ( !s8_evt1))) && (_x_s8_x == 0.0))) || ( !((_x_s8_l1 && ( !_x_s8_l0)) && ((s8_l0 && ( !s8_l1)) && ((delta == 0.0) && ( !(( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))))))) && ((((((((((((((((((( !_x_s7_evt2) && (_x_s7_evt0 && ( !_x_s7_evt1))) || (((( !_x_s7_evt2) && (( !_x_s7_evt0) && ( !_x_s7_evt1))) || (_x_s7_evt2 && (( !_x_s7_evt0) && ( !_x_s7_evt1)))) || ((( !_x_s7_evt2) && (_x_s7_evt1 && ( !_x_s7_evt0))) || (_x_s7_evt2 && (_x_s7_evt1 && ( !_x_s7_evt0)))))) && ((( !_x_s7_l0) && ( !_x_s7_l1)) || ((_x_s7_l1 && ( !_x_s7_l0)) || (_x_s7_l0 && ( !_x_s7_l1))))) && ((_x_s7_x <= 404.0) || ( !(_x_s7_l1 && ( !_x_s7_l0))))) && ((_x_s7_x <= 26.0) || ( !(_x_s7_l0 && ( !_x_s7_l1))))) && ((delta <= 0.0) || (((s7_l0 == _x_s7_l0) && (s7_l1 == _x_s7_l1)) && ((delta + (s7_x + (-1.0 * _x_s7_x))) == 0.0)))) && ((((s7_l0 == _x_s7_l0) && (s7_l1 == _x_s7_l1)) && ((delta + (s7_x + (-1.0 * _x_s7_x))) == 0.0)) || ( !(( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))) && (((_x_s7_l0 && ( !_x_s7_l1)) || ((( !_x_s7_l0) && ( !_x_s7_l1)) || (_x_s7_l1 && ( !_x_s7_l0)))) || ( !((( !s7_l0) && ( !s7_l1)) && ((delta == 0.0) && ( !(( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1))))))))) && (((( !s7_evt2) && (s7_evt0 && ( !s7_evt1))) && (_x_s7_x == 0.0)) || ( !((( !_x_s7_l0) && ( !_x_s7_l1)) && ((( !s7_l0) && ( !s7_l1)) && ((delta == 0.0) && ( !(( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))))))) && (((s7_evt2 && (( !s7_evt0) && ( !s7_evt1))) && (_x_s7_x == 0.0)) || ( !((_x_s7_l1 && ( !_x_s7_l0)) && ((( !s7_l0) && ( !s7_l1)) && ((delta == 0.0) && ( !(( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))))))) && (((_x_s7_x == 0.0) && ((s7_evt2 && (s7_evt1 && ( !s7_evt0))) || (( !s7_evt2) && (s7_evt0 && ( !s7_evt1))))) || ( !((_x_s7_l0 && ( !_x_s7_l1)) && ((( !s7_l0) && ( !s7_l1)) && ((delta == 0.0) && ( !(( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))))))) && (((( !_x_s7_l0) && ( !_x_s7_l1)) || (_x_s7_l0 && ( !_x_s7_l1))) || ( !((s7_l1 && ( !s7_l0)) && ((delta == 0.0) && ( !(( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1))))))))) && (((404.0 <= s7_x) && ((( !s7_evt2) && (s7_evt1 && ( !s7_evt0))) && (_x_s7_x == 0.0))) || ( !((( !_x_s7_l0) && ( !_x_s7_l1)) && ((s7_l1 && ( !s7_l0)) && ((delta == 0.0) && ( !(( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))))))) && (((s7_x <= 26.0) && ((( !s7_evt2) && (s7_evt0 && ( !s7_evt1))) && (_x_s7_x == 0.0))) || ( !((_x_s7_l0 && ( !_x_s7_l1)) && ((s7_l1 && ( !s7_l0)) && ((delta == 0.0) && ( !(( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))))))) && (((_x_s7_l1 && ( !_x_s7_l0)) || (_x_s7_l0 && ( !_x_s7_l1))) || ( !((s7_l0 && ( !s7_l1)) && ((delta == 0.0) && ( !(( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1))))))))) && (((s7_x <= 26.0) && ((( !s7_evt2) && (s7_evt0 && ( !s7_evt1))) && (_x_s7_x == 0.0))) || ( !((_x_s7_l0 && ( !_x_s7_l1)) && ((s7_l0 && ( !s7_l1)) && ((delta == 0.0) && ( !(( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))))))) && (((s7_x <= 26.0) && ((s7_evt2 && (( !s7_evt0) && ( !s7_evt1))) && (_x_s7_x == 0.0))) || ( !((_x_s7_l1 && ( !_x_s7_l0)) && ((s7_l0 && ( !s7_l1)) && ((delta == 0.0) && ( !(( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))))))) && ((((((((((((((((((( !_x_s6_evt2) && (_x_s6_evt0 && ( !_x_s6_evt1))) || (((( !_x_s6_evt2) && (( !_x_s6_evt0) && ( !_x_s6_evt1))) || (_x_s6_evt2 && (( !_x_s6_evt0) && ( !_x_s6_evt1)))) || ((( !_x_s6_evt2) && (_x_s6_evt1 && ( !_x_s6_evt0))) || (_x_s6_evt2 && (_x_s6_evt1 && ( !_x_s6_evt0)))))) && ((( !_x_s6_l0) && ( !_x_s6_l1)) || ((_x_s6_l1 && ( !_x_s6_l0)) || (_x_s6_l0 && ( !_x_s6_l1))))) && ((_x_s6_x <= 404.0) || ( !(_x_s6_l1 && ( !_x_s6_l0))))) && ((_x_s6_x <= 26.0) || ( !(_x_s6_l0 && ( !_x_s6_l1))))) && ((delta <= 0.0) || (((s6_l0 == _x_s6_l0) && (s6_l1 == _x_s6_l1)) && ((delta + (s6_x + (-1.0 * _x_s6_x))) == 0.0)))) && ((((s6_l0 == _x_s6_l0) && (s6_l1 == _x_s6_l1)) && ((delta + (s6_x + (-1.0 * _x_s6_x))) == 0.0)) || ( !(( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))) && (((_x_s6_l0 && ( !_x_s6_l1)) || ((( !_x_s6_l0) && ( !_x_s6_l1)) || (_x_s6_l1 && ( !_x_s6_l0)))) || ( !((( !s6_l0) && ( !s6_l1)) && ((delta == 0.0) && ( !(( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1))))))))) && (((( !s6_evt2) && (s6_evt0 && ( !s6_evt1))) && (_x_s6_x == 0.0)) || ( !((( !_x_s6_l0) && ( !_x_s6_l1)) && ((( !s6_l0) && ( !s6_l1)) && ((delta == 0.0) && ( !(( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))))))) && (((s6_evt2 && (( !s6_evt0) && ( !s6_evt1))) && (_x_s6_x == 0.0)) || ( !((_x_s6_l1 && ( !_x_s6_l0)) && ((( !s6_l0) && ( !s6_l1)) && ((delta == 0.0) && ( !(( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))))))) && (((_x_s6_x == 0.0) && ((s6_evt2 && (s6_evt1 && ( !s6_evt0))) || (( !s6_evt2) && (s6_evt0 && ( !s6_evt1))))) || ( !((_x_s6_l0 && ( !_x_s6_l1)) && ((( !s6_l0) && ( !s6_l1)) && ((delta == 0.0) && ( !(( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))))))) && (((( !_x_s6_l0) && ( !_x_s6_l1)) || (_x_s6_l0 && ( !_x_s6_l1))) || ( !((s6_l1 && ( !s6_l0)) && ((delta == 0.0) && ( !(( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1))))))))) && (((404.0 <= s6_x) && ((( !s6_evt2) && (s6_evt1 && ( !s6_evt0))) && (_x_s6_x == 0.0))) || ( !((( !_x_s6_l0) && ( !_x_s6_l1)) && ((s6_l1 && ( !s6_l0)) && ((delta == 0.0) && ( !(( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))))))) && (((s6_x <= 26.0) && ((( !s6_evt2) && (s6_evt0 && ( !s6_evt1))) && (_x_s6_x == 0.0))) || ( !((_x_s6_l0 && ( !_x_s6_l1)) && ((s6_l1 && ( !s6_l0)) && ((delta == 0.0) && ( !(( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))))))) && (((_x_s6_l1 && ( !_x_s6_l0)) || (_x_s6_l0 && ( !_x_s6_l1))) || ( !((s6_l0 && ( !s6_l1)) && ((delta == 0.0) && ( !(( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1))))))))) && (((s6_x <= 26.0) && ((( !s6_evt2) && (s6_evt0 && ( !s6_evt1))) && (_x_s6_x == 0.0))) || ( !((_x_s6_l0 && ( !_x_s6_l1)) && ((s6_l0 && ( !s6_l1)) && ((delta == 0.0) && ( !(( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))))))) && (((s6_x <= 26.0) && ((s6_evt2 && (( !s6_evt0) && ( !s6_evt1))) && (_x_s6_x == 0.0))) || ( !((_x_s6_l1 && ( !_x_s6_l0)) && ((s6_l0 && ( !s6_l1)) && ((delta == 0.0) && ( !(( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))))))) && ((((((((((((((((((( !_x_s5_evt2) && (_x_s5_evt0 && ( !_x_s5_evt1))) || (((( !_x_s5_evt2) && (( !_x_s5_evt0) && ( !_x_s5_evt1))) || (_x_s5_evt2 && (( !_x_s5_evt0) && ( !_x_s5_evt1)))) || ((( !_x_s5_evt2) && (_x_s5_evt1 && ( !_x_s5_evt0))) || (_x_s5_evt2 && (_x_s5_evt1 && ( !_x_s5_evt0)))))) && ((( !_x_s5_l0) && ( !_x_s5_l1)) || ((_x_s5_l1 && ( !_x_s5_l0)) || (_x_s5_l0 && ( !_x_s5_l1))))) && ((_x_s5_x <= 404.0) || ( !(_x_s5_l1 && ( !_x_s5_l0))))) && ((_x_s5_x <= 26.0) || ( !(_x_s5_l0 && ( !_x_s5_l1))))) && ((delta <= 0.0) || (((s5_l0 == _x_s5_l0) && (s5_l1 == _x_s5_l1)) && ((delta + (s5_x + (-1.0 * _x_s5_x))) == 0.0)))) && ((((s5_l0 == _x_s5_l0) && (s5_l1 == _x_s5_l1)) && ((delta + (s5_x + (-1.0 * _x_s5_x))) == 0.0)) || ( !(( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))))) && (((_x_s5_l0 && ( !_x_s5_l1)) || ((( !_x_s5_l0) && ( !_x_s5_l1)) || (_x_s5_l1 && ( !_x_s5_l0)))) || ( !((( !s5_l0) && ( !s5_l1)) && ((delta == 0.0) && ( !(( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1))))))))) && (((( !s5_evt2) && (s5_evt0 && ( !s5_evt1))) && (_x_s5_x == 0.0)) || ( !((( !_x_s5_l0) && ( !_x_s5_l1)) && ((( !s5_l0) && ( !s5_l1)) && ((delta == 0.0) && ( !(( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))))))))) && (((s5_evt2 && (( !s5_evt0) && ( !s5_evt1))) && (_x_s5_x == 0.0)) || ( !((_x_s5_l1 && ( !_x_s5_l0)) && ((( !s5_l0) && ( !s5_l1)) && ((delta == 0.0) && ( !(( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))))))))) && (((_x_s5_x == 0.0) && ((s5_evt2 && (s5_evt1 && ( !s5_evt0))) || (( !s5_evt2) && (s5_evt0 && ( !s5_evt1))))) || ( !((_x_s5_l0 && ( !_x_s5_l1)) && ((( !s5_l0) && ( !s5_l1)) && ((delta == 0.0) && ( !(( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))))))))) && (((( !_x_s5_l0) && ( !_x_s5_l1)) || (_x_s5_l0 && ( !_x_s5_l1))) || ( !((s5_l1 && ( !s5_l0)) && ((delta == 0.0) && ( !(( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1))))))))) && (((404.0 <= s5_x) && ((( !s5_evt2) && (s5_evt1 && ( !s5_evt0))) && (_x_s5_x == 0.0))) || ( !((( !_x_s5_l0) && ( !_x_s5_l1)) && ((s5_l1 && ( !s5_l0)) && ((delta == 0.0) && ( !(( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))))))))) && (((s5_x <= 26.0) && ((( !s5_evt2) && (s5_evt0 && ( !s5_evt1))) && (_x_s5_x == 0.0))) || ( !((_x_s5_l0 && ( !_x_s5_l1)) && ((s5_l1 && ( !s5_l0)) && ((delta == 0.0) && ( !(( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))))))))) && (((_x_s5_l1 && ( !_x_s5_l0)) || (_x_s5_l0 && ( !_x_s5_l1))) || ( !((s5_l0 && ( !s5_l1)) && ((delta == 0.0) && ( !(( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1))))))))) && (((s5_x <= 26.0) && ((( !s5_evt2) && (s5_evt0 && ( !s5_evt1))) && (_x_s5_x == 0.0))) || ( !((_x_s5_l0 && ( !_x_s5_l1)) && ((s5_l0 && ( !s5_l1)) && ((delta == 0.0) && ( !(( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))))))))) && (((s5_x <= 26.0) && ((s5_evt2 && (( !s5_evt0) && ( !s5_evt1))) && (_x_s5_x == 0.0))) || ( !((_x_s5_l1 && ( !_x_s5_l0)) && ((s5_l0 && ( !s5_l1)) && ((delta == 0.0) && ( !(( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))))))))) && ((((((((((((((((((( !_x_s4_evt2) && (_x_s4_evt0 && ( !_x_s4_evt1))) || (((( !_x_s4_evt2) && (( !_x_s4_evt0) && ( !_x_s4_evt1))) || (_x_s4_evt2 && (( !_x_s4_evt0) && ( !_x_s4_evt1)))) || ((( !_x_s4_evt2) && (_x_s4_evt1 && ( !_x_s4_evt0))) || (_x_s4_evt2 && (_x_s4_evt1 && ( !_x_s4_evt0)))))) && ((( !_x_s4_l0) && ( !_x_s4_l1)) || ((_x_s4_l1 && ( !_x_s4_l0)) || (_x_s4_l0 && ( !_x_s4_l1))))) && ((_x_s4_x <= 404.0) || ( !(_x_s4_l1 && ( !_x_s4_l0))))) && ((_x_s4_x <= 26.0) || ( !(_x_s4_l0 && ( !_x_s4_l1))))) && ((delta <= 0.0) || (((s4_l0 == _x_s4_l0) && (s4_l1 == _x_s4_l1)) && ((delta + (s4_x + (-1.0 * _x_s4_x))) == 0.0)))) && ((((s4_l0 == _x_s4_l0) && (s4_l1 == _x_s4_l1)) && ((delta + (s4_x + (-1.0 * _x_s4_x))) == 0.0)) || ( !(( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1)))))) && (((_x_s4_l0 && ( !_x_s4_l1)) || ((( !_x_s4_l0) && ( !_x_s4_l1)) || (_x_s4_l1 && ( !_x_s4_l0)))) || ( !((( !s4_l0) && ( !s4_l1)) && ((delta == 0.0) && ( !(( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1))))))))) && (((( !s4_evt2) && (s4_evt0 && ( !s4_evt1))) && (_x_s4_x == 0.0)) || ( !((( !_x_s4_l0) && ( !_x_s4_l1)) && ((( !s4_l0) && ( !s4_l1)) && ((delta == 0.0) && ( !(( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1)))))))))) && (((s4_evt2 && (( !s4_evt0) && ( !s4_evt1))) && (_x_s4_x == 0.0)) || ( !((_x_s4_l1 && ( !_x_s4_l0)) && ((( !s4_l0) && ( !s4_l1)) && ((delta == 0.0) && ( !(( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1)))))))))) && (((_x_s4_x == 0.0) && ((s4_evt2 && (s4_evt1 && ( !s4_evt0))) || (( !s4_evt2) && (s4_evt0 && ( !s4_evt1))))) || ( !((_x_s4_l0 && ( !_x_s4_l1)) && ((( !s4_l0) && ( !s4_l1)) && ((delta == 0.0) && ( !(( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1)))))))))) && (((( !_x_s4_l0) && ( !_x_s4_l1)) || (_x_s4_l0 && ( !_x_s4_l1))) || ( !((s4_l1 && ( !s4_l0)) && ((delta == 0.0) && ( !(( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1))))))))) && (((404.0 <= s4_x) && ((( !s4_evt2) && (s4_evt1 && ( !s4_evt0))) && (_x_s4_x == 0.0))) || ( !((( !_x_s4_l0) && ( !_x_s4_l1)) && ((s4_l1 && ( !s4_l0)) && ((delta == 0.0) && ( !(( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1)))))))))) && (((s4_x <= 26.0) && ((( !s4_evt2) && (s4_evt0 && ( !s4_evt1))) && (_x_s4_x == 0.0))) || ( !((_x_s4_l0 && ( !_x_s4_l1)) && ((s4_l1 && ( !s4_l0)) && ((delta == 0.0) && ( !(( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1)))))))))) && (((_x_s4_l1 && ( !_x_s4_l0)) || (_x_s4_l0 && ( !_x_s4_l1))) || ( !((s4_l0 && ( !s4_l1)) && ((delta == 0.0) && ( !(( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1))))))))) && (((s4_x <= 26.0) && ((( !s4_evt2) && (s4_evt0 && ( !s4_evt1))) && (_x_s4_x == 0.0))) || ( !((_x_s4_l0 && ( !_x_s4_l1)) && ((s4_l0 && ( !s4_l1)) && ((delta == 0.0) && ( !(( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1)))))))))) && (((s4_x <= 26.0) && ((s4_evt2 && (( !s4_evt0) && ( !s4_evt1))) && (_x_s4_x == 0.0))) || ( !((_x_s4_l1 && ( !_x_s4_l0)) && ((s4_l0 && ( !s4_l1)) && ((delta == 0.0) && ( !(( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1)))))))))) && ((((((((((((((((((( !_x_s3_evt2) && (_x_s3_evt0 && ( !_x_s3_evt1))) || (((( !_x_s3_evt2) && (( !_x_s3_evt0) && ( !_x_s3_evt1))) || (_x_s3_evt2 && (( !_x_s3_evt0) && ( !_x_s3_evt1)))) || ((( !_x_s3_evt2) && (_x_s3_evt1 && ( !_x_s3_evt0))) || (_x_s3_evt2 && (_x_s3_evt1 && ( !_x_s3_evt0)))))) && ((( !_x_s3_l0) && ( !_x_s3_l1)) || ((_x_s3_l1 && ( !_x_s3_l0)) || (_x_s3_l0 && ( !_x_s3_l1))))) && ((_x_s3_x <= 404.0) || ( !(_x_s3_l1 && ( !_x_s3_l0))))) && ((_x_s3_x <= 26.0) || ( !(_x_s3_l0 && ( !_x_s3_l1))))) && ((delta <= 0.0) || (((s3_l0 == _x_s3_l0) && (s3_l1 == _x_s3_l1)) && ((delta + (s3_x + (-1.0 * _x_s3_x))) == 0.0)))) && ((((s3_l0 == _x_s3_l0) && (s3_l1 == _x_s3_l1)) && ((delta + (s3_x + (-1.0 * _x_s3_x))) == 0.0)) || ( !(( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1)))))) && (((_x_s3_l0 && ( !_x_s3_l1)) || ((( !_x_s3_l0) && ( !_x_s3_l1)) || (_x_s3_l1 && ( !_x_s3_l0)))) || ( !((( !s3_l0) && ( !s3_l1)) && ((delta == 0.0) && ( !(( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1))))))))) && (((( !s3_evt2) && (s3_evt0 && ( !s3_evt1))) && (_x_s3_x == 0.0)) || ( !((( !_x_s3_l0) && ( !_x_s3_l1)) && ((( !s3_l0) && ( !s3_l1)) && ((delta == 0.0) && ( !(( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1)))))))))) && (((s3_evt2 && (( !s3_evt0) && ( !s3_evt1))) && (_x_s3_x == 0.0)) || ( !((_x_s3_l1 && ( !_x_s3_l0)) && ((( !s3_l0) && ( !s3_l1)) && ((delta == 0.0) && ( !(( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1)))))))))) && (((_x_s3_x == 0.0) && ((s3_evt2 && (s3_evt1 && ( !s3_evt0))) || (( !s3_evt2) && (s3_evt0 && ( !s3_evt1))))) || ( !((_x_s3_l0 && ( !_x_s3_l1)) && ((( !s3_l0) && ( !s3_l1)) && ((delta == 0.0) && ( !(( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1)))))))))) && (((( !_x_s3_l0) && ( !_x_s3_l1)) || (_x_s3_l0 && ( !_x_s3_l1))) || ( !((s3_l1 && ( !s3_l0)) && ((delta == 0.0) && ( !(( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1))))))))) && (((404.0 <= s3_x) && ((( !s3_evt2) && (s3_evt1 && ( !s3_evt0))) && (_x_s3_x == 0.0))) || ( !((( !_x_s3_l0) && ( !_x_s3_l1)) && ((s3_l1 && ( !s3_l0)) && ((delta == 0.0) && ( !(( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1)))))))))) && (((s3_x <= 26.0) && ((( !s3_evt2) && (s3_evt0 && ( !s3_evt1))) && (_x_s3_x == 0.0))) || ( !((_x_s3_l0 && ( !_x_s3_l1)) && ((s3_l1 && ( !s3_l0)) && ((delta == 0.0) && ( !(( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1)))))))))) && (((_x_s3_l1 && ( !_x_s3_l0)) || (_x_s3_l0 && ( !_x_s3_l1))) || ( !((s3_l0 && ( !s3_l1)) && ((delta == 0.0) && ( !(( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1))))))))) && (((s3_x <= 26.0) && ((( !s3_evt2) && (s3_evt0 && ( !s3_evt1))) && (_x_s3_x == 0.0))) || ( !((_x_s3_l0 && ( !_x_s3_l1)) && ((s3_l0 && ( !s3_l1)) && ((delta == 0.0) && ( !(( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1)))))))))) && (((s3_x <= 26.0) && ((s3_evt2 && (( !s3_evt0) && ( !s3_evt1))) && (_x_s3_x == 0.0))) || ( !((_x_s3_l1 && ( !_x_s3_l0)) && ((s3_l0 && ( !s3_l1)) && ((delta == 0.0) && ( !(( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1)))))))))) && ((((((((((((((((((( !_x_s2_evt2) && (_x_s2_evt0 && ( !_x_s2_evt1))) || (((( !_x_s2_evt2) && (( !_x_s2_evt0) && ( !_x_s2_evt1))) || (_x_s2_evt2 && (( !_x_s2_evt0) && ( !_x_s2_evt1)))) || ((( !_x_s2_evt2) && (_x_s2_evt1 && ( !_x_s2_evt0))) || (_x_s2_evt2 && (_x_s2_evt1 && ( !_x_s2_evt0)))))) && ((( !_x_s2_l0) && ( !_x_s2_l1)) || ((_x_s2_l1 && ( !_x_s2_l0)) || (_x_s2_l0 && ( !_x_s2_l1))))) && ((_x_s2_x <= 404.0) || ( !(_x_s2_l1 && ( !_x_s2_l0))))) && ((_x_s2_x <= 26.0) || ( !(_x_s2_l0 && ( !_x_s2_l1))))) && ((delta <= 0.0) || (((s2_l0 == _x_s2_l0) && (s2_l1 == _x_s2_l1)) && ((delta + (s2_x + (-1.0 * _x_s2_x))) == 0.0)))) && ((((s2_l0 == _x_s2_l0) && (s2_l1 == _x_s2_l1)) && ((delta + (s2_x + (-1.0 * _x_s2_x))) == 0.0)) || ( !(( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1)))))) && (((_x_s2_l0 && ( !_x_s2_l1)) || ((( !_x_s2_l0) && ( !_x_s2_l1)) || (_x_s2_l1 && ( !_x_s2_l0)))) || ( !((( !s2_l0) && ( !s2_l1)) && ((delta == 0.0) && ( !(( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1))))))))) && (((( !s2_evt2) && (s2_evt0 && ( !s2_evt1))) && (_x_s2_x == 0.0)) || ( !((( !_x_s2_l0) && ( !_x_s2_l1)) && ((( !s2_l0) && ( !s2_l1)) && ((delta == 0.0) && ( !(( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1)))))))))) && (((s2_evt2 && (( !s2_evt0) && ( !s2_evt1))) && (_x_s2_x == 0.0)) || ( !((_x_s2_l1 && ( !_x_s2_l0)) && ((( !s2_l0) && ( !s2_l1)) && ((delta == 0.0) && ( !(( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1)))))))))) && (((_x_s2_x == 0.0) && ((s2_evt2 && (s2_evt1 && ( !s2_evt0))) || (( !s2_evt2) && (s2_evt0 && ( !s2_evt1))))) || ( !((_x_s2_l0 && ( !_x_s2_l1)) && ((( !s2_l0) && ( !s2_l1)) && ((delta == 0.0) && ( !(( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1)))))))))) && (((( !_x_s2_l0) && ( !_x_s2_l1)) || (_x_s2_l0 && ( !_x_s2_l1))) || ( !((s2_l1 && ( !s2_l0)) && ((delta == 0.0) && ( !(( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1))))))))) && (((404.0 <= s2_x) && ((( !s2_evt2) && (s2_evt1 && ( !s2_evt0))) && (_x_s2_x == 0.0))) || ( !((( !_x_s2_l0) && ( !_x_s2_l1)) && ((s2_l1 && ( !s2_l0)) && ((delta == 0.0) && ( !(( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1)))))))))) && (((s2_x <= 26.0) && ((( !s2_evt2) && (s2_evt0 && ( !s2_evt1))) && (_x_s2_x == 0.0))) || ( !((_x_s2_l0 && ( !_x_s2_l1)) && ((s2_l1 && ( !s2_l0)) && ((delta == 0.0) && ( !(( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1)))))))))) && (((_x_s2_l1 && ( !_x_s2_l0)) || (_x_s2_l0 && ( !_x_s2_l1))) || ( !((s2_l0 && ( !s2_l1)) && ((delta == 0.0) && ( !(( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1))))))))) && (((s2_x <= 26.0) && ((( !s2_evt2) && (s2_evt0 && ( !s2_evt1))) && (_x_s2_x == 0.0))) || ( !((_x_s2_l0 && ( !_x_s2_l1)) && ((s2_l0 && ( !s2_l1)) && ((delta == 0.0) && ( !(( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1)))))))))) && (((s2_x <= 26.0) && ((s2_evt2 && (( !s2_evt0) && ( !s2_evt1))) && (_x_s2_x == 0.0))) || ( !((_x_s2_l1 && ( !_x_s2_l0)) && ((s2_l0 && ( !s2_l1)) && ((delta == 0.0) && ( !(( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1)))))))))) && ((((((((((((((((((( !_x_s1_evt2) && (_x_s1_evt0 && ( !_x_s1_evt1))) || (((( !_x_s1_evt2) && (( !_x_s1_evt0) && ( !_x_s1_evt1))) || (_x_s1_evt2 && (( !_x_s1_evt0) && ( !_x_s1_evt1)))) || ((( !_x_s1_evt2) && (_x_s1_evt1 && ( !_x_s1_evt0))) || (_x_s1_evt2 && (_x_s1_evt1 && ( !_x_s1_evt0)))))) && ((( !_x_s1_l0) && ( !_x_s1_l1)) || ((_x_s1_l1 && ( !_x_s1_l0)) || (_x_s1_l0 && ( !_x_s1_l1))))) && ((_x_s1_x <= 404.0) || ( !(_x_s1_l1 && ( !_x_s1_l0))))) && ((_x_s1_x <= 26.0) || ( !(_x_s1_l0 && ( !_x_s1_l1))))) && ((delta <= 0.0) || (((s1_l0 == _x_s1_l0) && (s1_l1 == _x_s1_l1)) && ((delta + (s1_x + (-1.0 * _x_s1_x))) == 0.0)))) && ((((s1_l0 == _x_s1_l0) && (s1_l1 == _x_s1_l1)) && ((delta + (s1_x + (-1.0 * _x_s1_x))) == 0.0)) || ( !(( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1)))))) && (((_x_s1_l0 && ( !_x_s1_l1)) || ((( !_x_s1_l0) && ( !_x_s1_l1)) || (_x_s1_l1 && ( !_x_s1_l0)))) || ( !((( !s1_l0) && ( !s1_l1)) && ((delta == 0.0) && ( !(( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1))))))))) && (((( !s1_evt2) && (s1_evt0 && ( !s1_evt1))) && (_x_s1_x == 0.0)) || ( !((( !_x_s1_l0) && ( !_x_s1_l1)) && ((( !s1_l0) && ( !s1_l1)) && ((delta == 0.0) && ( !(( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1)))))))))) && (((s1_evt2 && (( !s1_evt0) && ( !s1_evt1))) && (_x_s1_x == 0.0)) || ( !((_x_s1_l1 && ( !_x_s1_l0)) && ((( !s1_l0) && ( !s1_l1)) && ((delta == 0.0) && ( !(( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1)))))))))) && (((_x_s1_x == 0.0) && ((s1_evt2 && (s1_evt1 && ( !s1_evt0))) || (( !s1_evt2) && (s1_evt0 && ( !s1_evt1))))) || ( !((_x_s1_l0 && ( !_x_s1_l1)) && ((( !s1_l0) && ( !s1_l1)) && ((delta == 0.0) && ( !(( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1)))))))))) && (((( !_x_s1_l0) && ( !_x_s1_l1)) || (_x_s1_l0 && ( !_x_s1_l1))) || ( !((s1_l1 && ( !s1_l0)) && ((delta == 0.0) && ( !(( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1))))))))) && (((404.0 <= s1_x) && ((( !s1_evt2) && (s1_evt1 && ( !s1_evt0))) && (_x_s1_x == 0.0))) || ( !((( !_x_s1_l0) && ( !_x_s1_l1)) && ((s1_l1 && ( !s1_l0)) && ((delta == 0.0) && ( !(( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1)))))))))) && (((s1_x <= 26.0) && ((( !s1_evt2) && (s1_evt0 && ( !s1_evt1))) && (_x_s1_x == 0.0))) || ( !((_x_s1_l0 && ( !_x_s1_l1)) && ((s1_l1 && ( !s1_l0)) && ((delta == 0.0) && ( !(( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1)))))))))) && (((_x_s1_l1 && ( !_x_s1_l0)) || (_x_s1_l0 && ( !_x_s1_l1))) || ( !((s1_l0 && ( !s1_l1)) && ((delta == 0.0) && ( !(( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1))))))))) && (((s1_x <= 26.0) && ((( !s1_evt2) && (s1_evt0 && ( !s1_evt1))) && (_x_s1_x == 0.0))) || ( !((_x_s1_l0 && ( !_x_s1_l1)) && ((s1_l0 && ( !s1_l1)) && ((delta == 0.0) && ( !(( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1)))))))))) && (((s1_x <= 26.0) && ((s1_evt2 && (( !s1_evt0) && ( !s1_evt1))) && (_x_s1_x == 0.0))) || ( !((_x_s1_l1 && ( !_x_s1_l0)) && ((s1_l0 && ( !s1_l1)) && ((delta == 0.0) && ( !(( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1)))))))))) && ((((((((((((((((((( !_x_s0_evt2) && (_x_s0_evt0 && ( !_x_s0_evt1))) || (((( !_x_s0_evt2) && (( !_x_s0_evt0) && ( !_x_s0_evt1))) || (_x_s0_evt2 && (( !_x_s0_evt0) && ( !_x_s0_evt1)))) || ((( !_x_s0_evt2) && (_x_s0_evt1 && ( !_x_s0_evt0))) || (_x_s0_evt2 && (_x_s0_evt1 && ( !_x_s0_evt0)))))) && ((( !_x_s0_l0) && ( !_x_s0_l1)) || ((_x_s0_l1 && ( !_x_s0_l0)) || (_x_s0_l0 && ( !_x_s0_l1))))) && ((_x_s0_x <= 404.0) || ( !(_x_s0_l1 && ( !_x_s0_l0))))) && ((_x_s0_x <= 26.0) || ( !(_x_s0_l0 && ( !_x_s0_l1))))) && ((delta <= 0.0) || (((s0_l0 == _x_s0_l0) && (s0_l1 == _x_s0_l1)) && ((delta + (s0_x + (-1.0 * _x_s0_x))) == 0.0)))) && ((((s0_l0 == _x_s0_l0) && (s0_l1 == _x_s0_l1)) && ((delta + (s0_x + (-1.0 * _x_s0_x))) == 0.0)) || ( !(( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1)))))) && (((_x_s0_l0 && ( !_x_s0_l1)) || ((( !_x_s0_l0) && ( !_x_s0_l1)) || (_x_s0_l1 && ( !_x_s0_l0)))) || ( !((( !s0_l0) && ( !s0_l1)) && ((delta == 0.0) && ( !(( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1))))))))) && (((( !s0_evt2) && (s0_evt0 && ( !s0_evt1))) && (_x_s0_x == 0.0)) || ( !((( !_x_s0_l0) && ( !_x_s0_l1)) && ((( !s0_l0) && ( !s0_l1)) && ((delta == 0.0) && ( !(( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1)))))))))) && (((s0_evt2 && (( !s0_evt0) && ( !s0_evt1))) && (_x_s0_x == 0.0)) || ( !((_x_s0_l1 && ( !_x_s0_l0)) && ((( !s0_l0) && ( !s0_l1)) && ((delta == 0.0) && ( !(( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1)))))))))) && (((_x_s0_x == 0.0) && ((s0_evt2 && (s0_evt1 && ( !s0_evt0))) || (( !s0_evt2) && (s0_evt0 && ( !s0_evt1))))) || ( !((_x_s0_l0 && ( !_x_s0_l1)) && ((( !s0_l0) && ( !s0_l1)) && ((delta == 0.0) && ( !(( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1)))))))))) && (((( !_x_s0_l0) && ( !_x_s0_l1)) || (_x_s0_l0 && ( !_x_s0_l1))) || ( !((s0_l1 && ( !s0_l0)) && ((delta == 0.0) && ( !(( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1))))))))) && (((404.0 <= s0_x) && ((( !s0_evt2) && (s0_evt1 && ( !s0_evt0))) && (_x_s0_x == 0.0))) || ( !((( !_x_s0_l0) && ( !_x_s0_l1)) && ((s0_l1 && ( !s0_l0)) && ((delta == 0.0) && ( !(( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1)))))))))) && (((s0_x <= 26.0) && ((( !s0_evt2) && (s0_evt0 && ( !s0_evt1))) && (_x_s0_x == 0.0))) || ( !((_x_s0_l0 && ( !_x_s0_l1)) && ((s0_l1 && ( !s0_l0)) && ((delta == 0.0) && ( !(( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1)))))))))) && (((_x_s0_l1 && ( !_x_s0_l0)) || (_x_s0_l0 && ( !_x_s0_l1))) || ( !((s0_l0 && ( !s0_l1)) && ((delta == 0.0) && ( !(( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1))))))))) && (((s0_x <= 26.0) && ((( !s0_evt2) && (s0_evt0 && ( !s0_evt1))) && (_x_s0_x == 0.0))) || ( !((_x_s0_l0 && ( !_x_s0_l1)) && ((s0_l0 && ( !s0_l1)) && ((delta == 0.0) && ( !(( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1)))))))))) && (((s0_x <= 26.0) && ((s0_evt2 && (( !s0_evt0) && ( !s0_evt1))) && (_x_s0_x == 0.0))) || ( !((_x_s0_l1 && ( !_x_s0_l0)) && ((s0_l0 && ( !s0_l1)) && ((delta == 0.0) && ( !(( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1)))))))))) && (((((((((((((((( !_x_bus_evt2) && (( !_x_bus_evt0) && ( !_x_bus_evt1))) || (((_x_bus_evt2 && (( !_x_bus_evt0) && ( !_x_bus_evt1))) || (( !_x_bus_evt2) && (_x_bus_evt1 && ( !_x_bus_evt0)))) || ((_x_bus_evt2 && (_x_bus_evt1 && ( !_x_bus_evt0))) || (( !_x_bus_evt2) && (_x_bus_evt0 && ( !_x_bus_evt1)))))) && (((( !_x_bus_l0) && ( !_x_bus_l1)) || (_x_bus_l1 && ( !_x_bus_l0))) || ((_x_bus_l0 && ( !_x_bus_l1)) || (_x_bus_l0 && _x_bus_l1)))) && ((( !(13.0 <= _x_bus_x)) || ( !(_x_bus_l0 && ( !_x_bus_l1)))) && ((_x_delta == 0.0) || ( !(_x_bus_l0 && _x_bus_l1))))) && ((delta <= 0.0) || (((delta + (bus_x + (-1.0 * _x_bus_x))) == 0.0) && (((bus_l0 == _x_bus_l0) && (bus_l1 == _x_bus_l1)) && (bus_j == _x_bus_j))))) && ((((delta + (bus_x + (-1.0 * _x_bus_x))) == 0.0) && (((bus_l0 == _x_bus_l0) && (bus_l1 == _x_bus_l1)) && (bus_j == _x_bus_j))) || ( !(( !bus_evt2) && (( !bus_evt0) && ( !bus_evt1)))))) && ((((bus_evt2 && (( !bus_evt0) && ( !bus_evt1))) && (_x_bus_l1 && ( !_x_bus_l0))) && ((bus_j == _x_bus_j) && (_x_bus_x == 0.0))) || ( !((( !bus_l0) && ( !bus_l1)) && ((delta == 0.0) && ( !(( !bus_evt2) && (( !bus_evt0) && ( !bus_evt1))))))))) && (((bus_j == _x_bus_j) && ((_x_bus_l0 && ( !_x_bus_l1)) || ((( !_x_bus_l0) && ( !_x_bus_l1)) || (_x_bus_l1 && ( !_x_bus_l0))))) || ( !((bus_l1 && ( !bus_l0)) && ((delta == 0.0) && ( !(( !bus_evt2) && (( !bus_evt0) && ( !bus_evt1))))))))) && (((( !bus_evt2) && (bus_evt1 && ( !bus_evt0))) && (_x_bus_x == 0.0)) || ( !(((delta == 0.0) && ( !(( !bus_evt2) && (( !bus_evt0) && ( !bus_evt1))))) && ((( !_x_bus_l0) && ( !_x_bus_l1)) && (bus_l1 && ( !bus_l0))))))) && (((bus_evt2 && (bus_evt1 && ( !bus_evt0))) && ((13.0 <= bus_x) && (bus_x == _x_bus_x))) || ( !(((delta == 0.0) && ( !(( !bus_evt2) && (( !bus_evt0) && ( !bus_evt1))))) && ((bus_l1 && ( !bus_l0)) && (_x_bus_l1 && ( !_x_bus_l0))))))) && (((bus_evt2 && (( !bus_evt0) && ( !bus_evt1))) && (( !(13.0 <= bus_x)) && (_x_bus_x == 0.0))) || ( !(((delta == 0.0) && ( !(( !bus_evt2) && (( !bus_evt0) && ( !bus_evt1))))) && ((bus_l1 && ( !bus_l0)) && (_x_bus_l0 && ( !_x_bus_l1))))))) && (((((_x_bus_l0 && _x_bus_l1) && ( !(13.0 <= bus_x))) && ((( !bus_evt2) && (bus_evt0 && ( !bus_evt1))) && (bus_cd_id == bus_j))) && ((_x_bus_x == 0.0) && ((bus_j + (-1 * _x_bus_j)) == -1))) || ( !((bus_l0 && ( !bus_l1)) && ((delta == 0.0) && ( !(( !bus_evt2) && (( !bus_evt0) && ( !bus_evt1))))))))) && ((((bus_j + (-1 * _x_bus_j)) == -1) && (((( !bus_evt2) && (bus_evt0 && ( !bus_evt1))) && (bus_cd_id == bus_j)) && ((_x_bus_x == 0.0) && ( !(8 <= bus_j))))) || ( !(((delta == 0.0) && ( !(( !bus_evt2) && (( !bus_evt0) && ( !bus_evt1))))) && ((bus_l0 && bus_l1) && (_x_bus_l0 && _x_bus_l1)))))) && (((((( !bus_evt2) && (bus_evt0 && ( !bus_evt1))) && (bus_j == 8)) && ((_x_bus_x == 0.0) && (bus_cd_id == bus_j))) && (_x_bus_j == 0)) || ( !(((delta == 0.0) && ( !(( !bus_evt2) && (( !bus_evt0) && ( !bus_evt1))))) && ((( !_x_bus_l0) && ( !_x_bus_l1)) && (bus_l0 && bus_l1)))))) && (0.0 <= _x_delta))))))))))) && (((( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1))) || (( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1)))) || ( !(delta == 0.0)))) && (( !(delta == 0.0)) || ((( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1))) || (( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1)))))) && (( !(delta == 0.0)) || ((( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1))) || (( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1)))))) && (( !(delta == 0.0)) || ((( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1))) || (( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1)))))) && (( !(delta == 0.0)) || ((( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1))) || (( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))))) && (( !(delta == 0.0)) || ((( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1))) || (( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))) && (( !(delta == 0.0)) || ((( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1))) || (( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))) && (( !(delta == 0.0)) || ((( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1))) || (( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))) && (( !(delta == 0.0)) || ((( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1))) || (( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1)))))) && (( !(delta == 0.0)) || ((( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1))) || (( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1)))))) && (( !(delta == 0.0)) || ((( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1))) || (( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1)))))) && (( !(delta == 0.0)) || ((( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1))) || (( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))))) && (( !(delta == 0.0)) || ((( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1))) || (( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))) && (( !(delta == 0.0)) || ((( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1))) || (( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))) && (( !(delta == 0.0)) || ((( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1))) || (( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))) && (( !(delta == 0.0)) || ((( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1))) || (( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1)))))) && (( !(delta == 0.0)) || ((( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1))) || (( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1)))))) && (( !(delta == 0.0)) || ((( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1))) || (( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))))) && (( !(delta == 0.0)) || ((( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1))) || (( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))) && (( !(delta == 0.0)) || ((( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1))) || (( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))) && (( !(delta == 0.0)) || ((( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1))) || (( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))) && (( !(delta == 0.0)) || ((( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1))) || (( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1)))))) && (( !(delta == 0.0)) || ((( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1))) || (( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))))) && (( !(delta == 0.0)) || ((( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1))) || (( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))) && (( !(delta == 0.0)) || ((( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1))) || (( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))) && (( !(delta == 0.0)) || ((( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1))) || (( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))) && (( !(delta == 0.0)) || ((( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1))) || (( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))))) && (( !(delta == 0.0)) || ((( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1))) || (( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))) && (( !(delta == 0.0)) || ((( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1))) || (( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))) && (( !(delta == 0.0)) || ((( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1))) || (( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))) && (( !(delta == 0.0)) || ((( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1))) || (( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))))) && (( !(delta == 0.0)) || ((( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1))) || (( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))) && (( !(delta == 0.0)) || ((( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1))) || (( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))) && (( !(delta == 0.0)) || ((( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1))) || (( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))))) && (( !(delta == 0.0)) || ((( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1))) || (( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))) && (( !(delta == 0.0)) || ((( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1))) || (( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))))) && (( !(delta == 0.0)) || (( !(( !s8_evt2) && (( !s8_evt0) && ( !s8_evt1)))) || (( !(( !s7_evt2) && (( !s7_evt0) && ( !s7_evt1)))) || (( !(( !s6_evt2) && (( !s6_evt0) && ( !s6_evt1)))) || (( !(( !s5_evt2) && (( !s5_evt0) && ( !s5_evt1)))) || (( !(( !s4_evt2) && (( !s4_evt0) && ( !s4_evt1)))) || (( !(( !s3_evt2) && (( !s3_evt0) && ( !s3_evt1)))) || (( !(( !s2_evt2) && (( !s2_evt0) && ( !s2_evt1)))) || (( !(( !s1_evt2) && (( !s1_evt0) && ( !s1_evt1)))) || (( !(( !bus_evt2) && (( !bus_evt0) && ( !bus_evt1)))) || ( !(( !s0_evt2) && (( !s0_evt0) && ( !s0_evt1))))))))))))))) && (( !(delta == 0.0)) || ((bus_evt2 && (( !bus_evt0) && ( !bus_evt1))) == ((s8_evt2 && (( !s8_evt0) && ( !s8_evt1))) || ((s7_evt2 && (( !s7_evt0) && ( !s7_evt1))) || ((s6_evt2 && (( !s6_evt0) && ( !s6_evt1))) || ((s5_evt2 && (( !s5_evt0) && ( !s5_evt1))) || ((s4_evt2 && (( !s4_evt0) && ( !s4_evt1))) || ((s3_evt2 && (( !s3_evt0) && ( !s3_evt1))) || ((s2_evt2 && (( !s2_evt0) && ( !s2_evt1))) || ((s0_evt2 && (( !s0_evt0) && ( !s0_evt1))) || (s1_evt2 && (( !s1_evt0) && ( !s1_evt1)))))))))))))) && (( !(delta == 0.0)) || ((( !bus_evt2) && (bus_evt1 && ( !bus_evt0))) == ((( !s8_evt2) && (s8_evt1 && ( !s8_evt0))) || ((( !s7_evt2) && (s7_evt1 && ( !s7_evt0))) || ((( !s6_evt2) && (s6_evt1 && ( !s6_evt0))) || ((( !s5_evt2) && (s5_evt1 && ( !s5_evt0))) || ((( !s4_evt2) && (s4_evt1 && ( !s4_evt0))) || ((( !s3_evt2) && (s3_evt1 && ( !s3_evt0))) || ((( !s2_evt2) && (s2_evt1 && ( !s2_evt0))) || ((( !s0_evt2) && (s0_evt1 && ( !s0_evt0))) || (( !s1_evt2) && (s1_evt1 && ( !s1_evt0)))))))))))))) && (( !(delta == 0.0)) || ((bus_evt2 && (bus_evt1 && ( !bus_evt0))) == ((s8_evt2 && (s8_evt1 && ( !s8_evt0))) || ((s7_evt2 && (s7_evt1 && ( !s7_evt0))) || ((s6_evt2 && (s6_evt1 && ( !s6_evt0))) || ((s5_evt2 && (s5_evt1 && ( !s5_evt0))) || ((s4_evt2 && (s4_evt1 && ( !s4_evt0))) || ((s3_evt2 && (s3_evt1 && ( !s3_evt0))) || ((s2_evt2 && (s2_evt1 && ( !s2_evt0))) || ((s0_evt2 && (s0_evt1 && ( !s0_evt0))) || (s1_evt2 && (s1_evt1 && ( !s1_evt0)))))))))))))) && (( !(delta == 0.0)) || ((( !bus_evt2) && (bus_evt0 && ( !bus_evt1))) == ((( !s8_evt2) && (s8_evt0 && ( !s8_evt1))) || ((( !s7_evt2) && (s7_evt0 && ( !s7_evt1))) || ((( !s6_evt2) && (s6_evt0 && ( !s6_evt1))) || ((( !s5_evt2) && (s5_evt0 && ( !s5_evt1))) || ((( !s4_evt2) && (s4_evt0 && ( !s4_evt1))) || ((( !s3_evt2) && (s3_evt0 && ( !s3_evt1))) || ((( !s2_evt2) && (s2_evt0 && ( !s2_evt1))) || ((( !s0_evt2) && (s0_evt0 && ( !s0_evt1))) || (( !s1_evt2) && (s1_evt0 && ( !s1_evt1)))))))))))))) && (( !(delta == 0.0)) || ((( !s0_evt2) && (s0_evt0 && ( !s0_evt1))) == ((( !bus_evt2) && (bus_evt0 && ( !bus_evt1))) && (bus_cd_id == 0))))) && (( !(delta == 0.0)) || ((( !s1_evt2) && (s1_evt0 && ( !s1_evt1))) == ((( !bus_evt2) && (bus_evt0 && ( !bus_evt1))) && (bus_cd_id == 1))))) && (( !(delta == 0.0)) || ((( !s2_evt2) && (s2_evt0 && ( !s2_evt1))) == ((( !bus_evt2) && (bus_evt0 && ( !bus_evt1))) && (bus_cd_id == 2))))) && (( !(delta == 0.0)) || ((( !s3_evt2) && (s3_evt0 && ( !s3_evt1))) == ((( !bus_evt2) && (bus_evt0 && ( !bus_evt1))) && (bus_cd_id == 3))))) && (( !(delta == 0.0)) || ((( !s4_evt2) && (s4_evt0 && ( !s4_evt1))) == ((( !bus_evt2) && (bus_evt0 && ( !bus_evt1))) && (bus_cd_id == 4))))) && (( !(delta == 0.0)) || ((( !s5_evt2) && (s5_evt0 && ( !s5_evt1))) == ((( !bus_evt2) && (bus_evt0 && ( !bus_evt1))) && (bus_cd_id == 5))))) && (( !(delta == 0.0)) || ((( !s6_evt2) && (s6_evt0 && ( !s6_evt1))) == ((( !bus_evt2) && (bus_evt0 && ( !bus_evt1))) && (bus_cd_id == 6))))) && (( !(delta == 0.0)) || ((( !s7_evt2) && (s7_evt0 && ( !s7_evt1))) == ((( !bus_evt2) && (bus_evt0 && ( !bus_evt1))) && (bus_cd_id == 7))))) && (( !(delta == 0.0)) || ((( !s8_evt2) && (s8_evt0 && ( !s8_evt1))) == ((( !bus_evt2) && (bus_evt0 && ( !bus_evt1))) && (bus_cd_id == 8))))) && (((delta == _x__diverge_delta) || ( !(1.0 <= _diverge_delta))) && ((1.0 <= _diverge_delta) || ((delta + (_diverge_delta + (-1.0 * _x__diverge_delta))) == 0.0)))) && ((((((_EL_U_1765 == (_x__EL_U_1765 || ( !(_x__EL_U_1763 || (1.0 <= _x__diverge_delta))))) && ((_EL_U_1763 == (_x__EL_U_1763 || (1.0 <= _x__diverge_delta))) && ((_EL_U_1767 == ((( !_x_s0_l0) && ( !_x_s0_l1)) || _x__EL_U_1767)) && (_EL_U_1770 == (_x__EL_U_1770 || ( !(( !(_x_s0_l1 && ( !_x_s0_l0))) || ((( !_x_s0_l0) && ( !_x_s0_l1)) || _x__EL_U_1767)))))))) && (_x__J1790 == (( !(((_J1790 && _J1799) && _J1805) && _J1811)) && ((((_J1790 && _J1799) && _J1805) && _J1811) || (((( !s0_l0) && ( !s0_l1)) || ( !((( !s0_l0) && ( !s0_l1)) || _EL_U_1767))) || _J1790))))) && (_x__J1799 == (( !(((_J1790 && _J1799) && _J1805) && _J1811)) && ((((_J1790 && _J1799) && _J1805) && _J1811) || ((( !(( !(s0_l1 && ( !s0_l0))) || ((( !s0_l0) && ( !s0_l1)) || _EL_U_1767))) || ( !(_EL_U_1770 || ( !(( !(s0_l1 && ( !s0_l0))) || ((( !s0_l0) && ( !s0_l1)) || _EL_U_1767)))))) || _J1799))))) && (_x__J1805 == (( !(((_J1790 && _J1799) && _J1805) && _J1811)) && ((((_J1790 && _J1799) && _J1805) && _J1811) || (((1.0 <= _diverge_delta) || ( !((1.0 <= _diverge_delta) || _EL_U_1763))) || _J1805))))) && (_x__J1811 == (( !(((_J1790 && _J1799) && _J1805) && _J1811)) && ((((_J1790 && _J1799) && _J1805) && _J1811) || ((( !((1.0 <= _diverge_delta) || _EL_U_1763)) || ( !(_EL_U_1765 || ( !((1.0 <= _diverge_delta) || _EL_U_1763))))) || _J1811))))));
_diverge_delta = _x__diverge_delta;
delta = _x_delta;
s8_l1 = _x_s8_l1;
s8_l0 = _x_s8_l0;
bus_l1 = _x_bus_l1;
bus_l0 = _x_bus_l0;
s5_l1 = _x_s5_l1;
s8_x = _x_s8_x;
s5_l0 = _x_s5_l0;
s5_x = _x_s5_x;
s2_l1 = _x_s2_l1;
bus_x = _x_bus_x;
s2_l0 = _x_s2_l0;
s2_x = _x_s2_x;
s8_evt0 = _x_s8_evt0;
s8_evt1 = _x_s8_evt1;
bus_j = _x_bus_j;
s5_evt0 = _x_s5_evt0;
s8_evt2 = _x_s8_evt2;
s5_evt1 = _x_s5_evt1;
s5_evt2 = _x_s5_evt2;
s2_evt0 = _x_s2_evt0;
s2_evt1 = _x_s2_evt1;
bus_evt1 = _x_bus_evt1;
s2_evt2 = _x_s2_evt2;
bus_evt0 = _x_bus_evt0;
bus_evt2 = _x_bus_evt2;
_J1811 = _x__J1811;
_J1805 = _x__J1805;
s6_l1 = _x_s6_l1;
_J1799 = _x__J1799;
s6_l0 = _x_s6_l0;
_J1790 = _x__J1790;
_EL_U_1763 = _x__EL_U_1763;
s6_x = _x_s6_x;
s0_l1 = _x_s0_l1;
s3_l1 = _x_s3_l1;
s0_l0 = _x_s0_l0;
s3_l0 = _x_s3_l0;
s3_x = _x_s3_x;
_EL_U_1765 = _x__EL_U_1765;
s0_x = _x_s0_x;
_EL_U_1767 = _x__EL_U_1767;
s6_evt0 = _x_s6_evt0;
_EL_U_1770 = _x__EL_U_1770;
s6_evt1 = _x_s6_evt1;
s6_evt2 = _x_s6_evt2;
s3_evt0 = _x_s3_evt0;
s3_evt1 = _x_s3_evt1;
s3_evt2 = _x_s3_evt2;
s0_evt0 = _x_s0_evt0;
s0_evt1 = _x_s0_evt1;
s0_evt2 = _x_s0_evt2;
bus_cd_id = _x_bus_cd_id;
s7_l1 = _x_s7_l1;
s7_l0 = _x_s7_l0;
s7_x = _x_s7_x;
s4_l1 = _x_s4_l1;
s4_l0 = _x_s4_l0;
s1_l1 = _x_s1_l1;
s4_x = _x_s4_x;
s1_l0 = _x_s1_l0;
s1_x = _x_s1_x;
s7_evt0 = _x_s7_evt0;
s7_evt1 = _x_s7_evt1;
s7_evt2 = _x_s7_evt2;
s4_evt0 = _x_s4_evt0;
s4_evt1 = _x_s4_evt1;
s4_evt2 = _x_s4_evt2;
s1_evt0 = _x_s1_evt0;
s1_evt1 = _x_s1_evt1;
s1_evt2 = _x_s1_evt2;
}
}
|
the_stack_data/73574609.c | #include <stdio.h>
int main()
{
int m,n;
scanf("%d %d",&n,&m);
int ans1=1,ans2=1;
int i;
for(i=n;i>=n-m+1;--i)
ans1=ans1*i;
for(i=1;i<=m;++i)
ans2=ans2*i;
printf("%d",ans1/ans2);
return 0;
} |
the_stack_data/125729.c | void main(){
int i, z, n;
n = nondet();
z = 0;
for (i=0; i < n; i++){
z -= i;
}
assert (z >= 0);
}
|
the_stack_data/37638249.c | #include <stdio.h>
/**
* 枢轴值为第一个数,进行一次分离,位置前半部分都不大于枢轴值,后面都不小于
* @param num 需要比较的数组
* @param low 低位置
* @param high 高位置
* @return 最后枢轴的位置
*/
int Partition(int num[], int low, int high);
/**
* @param num 需要比较的数组
* @param low 起始位置
* @param high 最后位置
*/
void QuickSort(int num[], int low, int high);
int main() {
int num[10000];
//0为枢轴量,不填入
int i = 1;
while (scanf("%d", &num[i]) != EOF) {
i++;
}
--i;
QuickSort(num, 1, i);
printf("%d,",num[1]);
printf("%d",num[i]);
return 0;
}
int Partition(int num[], int low, int high) {
//枢轴值记录,以第一个值为枢轴值
num[0] = num[low];
while (low < high) {
//空位在前,找小
while (low < high && num[high] >= num[0]) {
high--;
}
num[low] = num[high];
//空位在后,找大
while (low < high && num[low] <= num[0]) {
low++;
}
num[high] = num[low];
}
//low==high
num[low] = num[0];
return low;
}
void QuickSort(int num[], int low, int high) {
//需判定条件,因为Partition(...)并没有改变low和high
if (low < high) {
int keyPosition = Partition(num, low, high);
QuickSort(num, low, keyPosition - 1);
QuickSort(num, keyPosition + 1, high);
}
} |
the_stack_data/90762237.c | //eof
#include <stdio.h>
#include <stdlib.h>
int main (void){
FILE *pont_arq;
char texto_str[20];
pont_arq = fopen("teste.txt","r");
while(fgets(texto_str,20,pont_arq) != NULL){
printf("%s",texto_str);
}
fclose(pont_arq);
return 0;
} |
the_stack_data/162643729.c | #include <stdio.h>
#include <string.h>
char *string_in(char *strsrc, char *strin)
{
return strstr(strsrc, strin);
}
int main(void)
{
char str1[100], str2[100];
char *pos;
printf("Enter two strings, and I can tell you "
"if the second string is contained in the first string\n");
while (scanf("%s%s", str1, str2) == 2)
{
if ((pos = string_in(str1, str2)))
printf("\"%s\" found at %p :%s", str2, pos, pos);
else
printf("\"%s\" not found, pos", str2);
}
return 0;
} |
the_stack_data/34512427.c | // from SV-COMP test-0019_false-valid-memtrack.c
#include <stdlib.h>
typedef struct {
void *lo;
void *hi;
} TData;
static void alloc_data(TData *pdata)
{
pdata->lo = malloc(16);
pdata->hi = malloc(24);
}
static void free_data(TData data)
{
void *lo = data.lo;
void *hi = data.hi;
if (lo != hi)
return;
free(lo);
free(hi);
}
int main() {
TData data;
alloc_data(&data);
free_data(data);
return 0;
}
|
the_stack_data/89201551.c | /* Codigo: 26-for.c
Autor: Carlos Adir
Descricao:
*/
#include <stdio.h>
int main()
{
int contador ;
for ( contador = 1; contador != 100; contador += 1)
{
printf ("%d\n", contador);
}
return 0;
}
|
the_stack_data/2891.c | #include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<string.h>
#include<assert.h>
/* The files are in csv format */
#define OFILE "sysout.csv"
#define IFILE "sysin.csv"
#define TRUE 1
#define FALSE 0
extern double x, y;
extern double signal_u;
double signal_pre=0;
/* The step size */
double d = 0.01;
/* The events to emit */
int ON=0, OFF=0;
/* The events to read */
int TURN_ON=0, TURN_OFF=0;
/* The tick counter */
/* It is static to hide it inside this file */
static size_t tick = 0;
/* The output file pointer */
FILE *fo = NULL;
/* The input file pointer */
FILE *fi = NULL;
static inline unsigned char getValue(unsigned char t, char* e){
assert(t == TRUE || t == FALSE);
return t;
}
/* Read input x from file */
void readInput() {
if (signal_u != signal_pre){
if (signal_u==1){
ON=1;
}
else if (signal_u==0){
OFF=1;
}
signal_pre=signal_u;
}
else {
ON=0;
OFF=0;
}
static unsigned char count = 0;
/* The check here is very expensive! */
if(0 == count) {
fi = fopen(IFILE, "r");
if (fi == NULL){
perror(IFILE);
exit(1);
}
++count;
}
/* The format of input is 1 line/tick */
/* for the events above the format is: */
/*
ON, ON_Value, C, C_Value, B, B_Value, OFF, OFF_Value
*/
char in[256];
if (fgets(in,255,fi) == NULL){
TURN_ON = FALSE;
TURN_OFF = FALSE;
}
else{
char *ret = NULL, *v = NULL;
ret = strtok(in, ",");
if(ret == NULL){
/* This means nothing found! */
/* Set all events to false */
TURN_ON = FALSE;
TURN_OFF = FALSE;
}
while(ret != NULL) {
v = strtok(NULL, ",");
if (v != NULL) {
if (strcmp(ret, "TURN_ON") == 0)
TURN_ON = getValue((unsigned char)atoi(v), ret);
else if(strcmp(ret, "TURN_OFF") == 0)
TURN_OFF = getValue((unsigned char)atoi(v), ret);
}
else {
perror("NULL while scanning input");
exit(1);
}
/* Read the next one! */
ret = strtok(NULL, ",");
}
}
}
/* Write output x to file */
void writeOutput(){
static unsigned char count = 0;
if (0 == count){
fo = fopen(OFILE, "w");
if (fo == NULL){
perror(OFILE);
exit(1);
}
++count;
}
fprintf(fo, "%ld,%s,%f,%s,%f,%s,%d,%s,%d,%s,%f\n", ++tick, "x", x, "y", y, "ON", ON, "OFF", OFF, "signal", signal_u);
if (tick==5000) {
printf("Finished");
exit(1);}
}
|
the_stack_data/15492.c | /* $Id: strtoul.c,v 1.2.2.1 2010-06-08 18:50:43 bfriesen Exp $ */
/*
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if 0
static char sccsid[] = "@(#)strtoul.c 8.1 (Berkeley) 6/4/93";
__RCSID("$NetBSD: strtoul.c,v 1.16 2003/08/07 16:43:45 agc Exp $");
#endif
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
/*
* Convert a string to an unsigned long integer.
*
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
unsigned long
strtoul(const char *nptr, char **endptr, int base)
{
const char *s;
unsigned long acc, cutoff;
int c;
int neg, any, cutlim;
/*
* See strtol for comments as to the logic used.
*/
s = nptr;
do {
c = (unsigned char) *s++;
} while (isspace(c));
if (c == '-') {
neg = 1;
c = *s++;
} else {
neg = 0;
if (c == '+')
c = *s++;
}
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
cutoff = ULONG_MAX / (unsigned long)base;
cutlim = (int)(ULONG_MAX % (unsigned long)base);
for (acc = 0, any = 0;; c = (unsigned char) *s++) {
if (isdigit(c))
c -= '0';
else if (isalpha(c))
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
else
break;
if (c >= base)
break;
if (any < 0)
continue;
if (acc > cutoff || (acc == cutoff && c > cutlim)) {
any = -1;
acc = ULONG_MAX;
errno = ERANGE;
} else {
any = 1;
acc *= (unsigned long)base;
acc += c;
}
}
if (neg && any > 0)
acc = -acc;
if (endptr != 0)
/* LINTED interface specification */
*endptr = (char *)(any ? s - 1 : nptr);
return (acc);
}
/*
* Local Variables:
* mode: c
* c-basic-offset: 8
* fill-column: 78
* End:
*/
|
the_stack_data/192330745.c | #include <unistd.h>
#include <signal.h>
#include <string.h>
void trata_sigint(int s) {
char buffer[256];
strcpy(buffer, "\nRead con interrupt\n");
write(1, &buffer, strlen(buffer));
}
main(){
signal(SIGINT, trata_sigint);
char c;
char buffer[256];
int r = read(0, &c, sizeof(char));
if(r < 0) {
strcpy(buffer, "Read con error\n");
write(1, &buffer, strlen(buffer));
}
else if(r > 0 && c != '\n') {
strcpy(buffer, "Read correcto:\n");
write(1, &buffer, strlen(buffer));
write(1, &c, sizeof(char));
strcpy(buffer, "\n");
write(1, &buffer, strlen(buffer));
}
}
|
the_stack_data/150174.c | extern void EXTI15_10_IRQHandler(void);
extern void ETH_IRQHandler(void);
extern void mETH_PhyEvent(void);
void EXTI15_10_IRQHandler(void)
{
mETH_PhyEvent();
}
|
the_stack_data/125141695.c | // RUN: %clang -target armv8a-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8A %s
// CHECK-V8A: #define __ARMEL__ 1
// CHECK-V8A: #define __ARM_ARCH 8
// CHECK-V8A: #define __ARM_ARCH_8A__ 1
// CHECK-V8A: #define __ARM_FEATURE_CRC32 1
// CHECK-V8A: #define __ARM_FEATURE_DIRECTED_ROUNDING 1
// CHECK-V8A: #define __ARM_FEATURE_NUMERIC_MAXMIN 1
// CHECK-V8A-NOT: #define __ARM_FP 0x
// CHECK-V8A-NOT: #define __ARM_FEATURE_DOTPROD
// RUN: %clang -target armv8a-none-linux-gnueabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8A-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8a-none-linux-gnueabihf -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8A-ALLOW-FP-INSTR %s
// CHECK-V8A-ALLOW-FP-INSTR: #define __ARMEL__ 1
// CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_ARCH 8
// CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_ARCH_8A__ 1
// CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FEATURE_CRC32 1
// CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FEATURE_DIRECTED_ROUNDING 1
// CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FEATURE_NUMERIC_MAXMIN 1
// CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FP 0xe
// CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FP16_ARGS 1
// CHECK-V8A-ALLOW-FP-INSTR: #define __ARM_FP16_FORMAT_IEEE 1
// CHECK-V8A-ALLOW-FP-INSTR-V8A-NOT: #define __ARM_FEATURE_DOTPROD
// RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2a+fp16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-VECTOR-SCALAR %s
// CHECK-FULLFP16-VECTOR-SCALAR: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1
// CHECK-FULLFP16-VECTOR-SCALAR: #define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 1
// CHECK-FULLFP16-VECTOR-SCALAR: #define __ARM_FP 0xe
// CHECK-FULLFP16-VECTOR-SCALAR: #define __ARM_FP16_FORMAT_IEEE 1
// RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2a+fp16 -mfpu=vfp4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FULLFP16-SCALAR %s
// CHECK-FULLFP16-SCALAR: #define __ARM_FEATURE_FP16_SCALAR_ARITHMETIC 1
// CHECK-FULLFP16-SCALAR-NOT: #define __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 1
// CHECK-FULLFP16-SCALAR: #define __ARM_FP 0xe
// CHECK-FULLFP16-SCALAR: #define __ARM_FP16_FORMAT_IEEE 1
//
// RUN: %clang -target arm-none-linux-gnueabi -march=armv8.2a+dotprod -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-DOTPROD %s
// CHECK-DOTPROD: #define __ARM_FEATURE_DOTPROD 1
// RUN: %clang -target armv8r-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8R %s
// CHECK-V8R: #define __ARMEL__ 1
// CHECK-V8R: #define __ARM_ARCH 8
// CHECK-V8R: #define __ARM_ARCH_8R__ 1
// CHECK-V8R: #define __ARM_FEATURE_CRC32 1
// CHECK-V8R: #define __ARM_FEATURE_DIRECTED_ROUNDING 1
// CHECK-V8R: #define __ARM_FEATURE_NUMERIC_MAXMIN 1
// CHECK-V8R-NOT: #define __ARM_FP 0x
// RUN: %clang -target armv8r-none-linux-gnueabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8R-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8r-none-linux-gnueabihf -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V8R-ALLOW-FP-INSTR %s
// CHECK-V8R-ALLOW-FP-INSTR: #define __ARMEL__ 1
// CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_ARCH 8
// CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_ARCH_8R__ 1
// CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_FEATURE_CRC32 1
// CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_FEATURE_DIRECTED_ROUNDING 1
// CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_FEATURE_NUMERIC_MAXMIN 1
// CHECK-V8R-ALLOW-FP-INSTR: #define __ARM_FP 0xe
// RUN: %clang -target armv7a-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7 %s
// CHECK-V7: #define __ARMEL__ 1
// CHECK-V7: #define __ARM_ARCH 7
// CHECK-V7: #define __ARM_ARCH_7A__ 1
// CHECK-V7-NOT: __ARM_FEATURE_CRC32
// CHECK-V7-NOT: __ARM_FEATURE_NUMERIC_MAXMIN
// CHECK-V7-NOT: __ARM_FEATURE_DIRECTED_ROUNDING
// CHECK-V7-NOT: #define __ARM_FP 0x
// RUN: %clang -target armv7a-none-linux-gnueabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7a-none-linux-gnueabihf -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7-ALLOW-FP-INSTR %s
// CHECK-V7-ALLOW-FP-INSTR: #define __ARMEL__ 1
// CHECK-V7-ALLOW-FP-INSTR: #define __ARM_ARCH 7
// CHECK-V7-ALLOW-FP-INSTR: #define __ARM_ARCH_7A__ 1
// CHECK-V7-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_CRC32
// CHECK-V7-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_NUMERIC_MAXMIN
// CHECK-V7-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_DIRECTED_ROUNDING
// CHECK-V7-ALLOW-FP-INSTR: #define __ARM_FP 0xc
// RUN: %clang -target armv7ve-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7VE %s
// CHECK-V7VE: #define __ARMEL__ 1
// CHECK-V7VE: #define __ARM_ARCH 7
// CHECK-V7VE: #define __ARM_ARCH_7VE__ 1
// CHECK-V7VE: #define __ARM_ARCH_EXT_IDIV__ 1
// CHECK-V7VE-NOT: #define __ARM_FP 0x
// RUN: %clang -target armv7ve-none-linux-gnueabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7VE-DEFAULT-ABI-SOFT %s
// RUN: %clang -target armv7ve-none-linux-gnueabihf -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7VE-DEFAULT-ABI-SOFT %s
// CHECK-V7VE-DEFAULT-ABI-SOFT: #define __ARMEL__ 1
// CHECK-V7VE-DEFAULT-ABI-SOFT: #define __ARM_ARCH 7
// CHECK-V7VE-DEFAULT-ABI-SOFT: #define __ARM_ARCH_7VE__ 1
// CHECK-V7VE-DEFAULT-ABI-SOFT: #define __ARM_ARCH_EXT_IDIV__ 1
// CHECK-V7VE-DEFAULT-ABI-SOFT: #define __ARM_FP 0xc
// RUN: %clang -target x86_64-apple-macosx10.10 -arch armv7s -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V7S %s
// CHECK-V7S: #define __ARMEL__ 1
// CHECK-V7S: #define __ARM_ARCH 7
// CHECK-V7S: #define __ARM_ARCH_7S__ 1
// CHECK-V7S-NOT: __ARM_FEATURE_CRC32
// CHECK-V7S-NOT: __ARM_FEATURE_NUMERIC_MAXMIN
// CHECK-V7S-NOT: __ARM_FEATURE_DIRECTED_ROUNDING
// CHECK-V7S: #define __ARM_FP 0xe
// RUN: %clang -target armv8a -mfloat-abi=hard -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-BAREHF %s
// CHECK-V8-BAREHF: #define __ARMEL__ 1
// CHECK-V8-BAREHF: #define __ARM_ARCH 8
// CHECK-V8-BAREHF: #define __ARM_ARCH_8A__ 1
// CHECK-V8-BAREHF: #define __ARM_FEATURE_CRC32 1
// CHECK-V8-BAREHF: #define __ARM_FEATURE_DIRECTED_ROUNDING 1
// CHECK-V8-BAREHF: #define __ARM_FEATURE_NUMERIC_MAXMIN 1
// CHECK-V8-BAREHP: #define __ARM_FP 0xe
// CHECK-V8-BAREHF: #define __ARM_NEON__ 1
// CHECK-V8-BAREHF: #define __ARM_PCS_VFP 1
// CHECK-V8-BAREHF: #define __VFP_FP__ 1
// RUN: %clang -target armv8a -mfloat-abi=hard -mfpu=fp-armv8 -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-BAREHF-FP %s
// CHECK-V8-BAREHF-FP-NOT: __ARM_NEON__ 1
// CHECK-V8-BAREHP-FP: #define __ARM_FP 0xe
// CHECK-V8-BAREHF-FP: #define __VFP_FP__ 1
// RUN: %clang -target armv8a -mfloat-abi=hard -mfpu=neon-fp-armv8 -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-BAREHF-NEON-FP %s
// RUN: %clang -target armv8a -mfloat-abi=hard -mfpu=crypto-neon-fp-armv8 -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-BAREHF-NEON-FP %s
// CHECK-V8-BAREHP-NEON-FP: #define __ARM_FP 0xe
// CHECK-V8-BAREHF-NEON-FP: #define __ARM_NEON__ 1
// CHECK-V8-BAREHF-NEON-FP: #define __VFP_FP__ 1
// RUN: %clang -target armv8a -mnocrc -x c -E -dM %s | FileCheck -match-full-lines --check-prefix=CHECK-V8-NOCRC %s
// CHECK-V8-NOCRC-NOT: __ARM_FEATURE_CRC32 1
// Check that -mhwdiv works properly for armv8/thumbv8 (enabled by default).
// RUN: %clang -target armv8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8 %s
// RUN: %clang -target armv8 -mthumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8 %s
// RUN: %clang -target armv8-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8 %s
// RUN: %clang -target armv8-eabi -mthumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8 %s
// V8:#define __ARM_ARCH_EXT_IDIV__ 1
// RUN: %clang -target armv8 -mhwdiv=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV-V8 %s
// RUN: %clang -target armv8 -mthumb -mhwdiv=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV-V8 %s
// RUN: %clang -target armv8 -mhwdiv=thumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV-V8 %s
// RUN: %clang -target armv8 -mthumb -mhwdiv=arm -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV-V8 %s
// NOHWDIV-V8-NOT:#define __ARM_ARCH_EXT_IDIV__
// RUN: %clang -target armv8a -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A %s
// RUN: %clang -target armv8a -mthumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A %s
// V8A:#define __ARM_ARCH_EXT_IDIV__ 1
// V8A-NOT:#define __ARM_FP 0x
// RUN: %clang -target armv8a-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8a-eabi -mthumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8a-eabihf -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8a-eabihf -mthumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8A-ALLOW-FP-INSTR %s
// V8A-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1
// V8A-ALLOW-FP-INSTR:#define __ARM_FP 0xe
// RUN: %clang -target armv8m.base-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_BASELINE %s
// V8M_BASELINE: #define __ARM_ARCH 8
// V8M_BASELINE: #define __ARM_ARCH_8M_BASE__ 1
// V8M_BASELINE: #define __ARM_ARCH_EXT_IDIV__ 1
// V8M_BASELINE-NOT: __ARM_ARCH_ISA_ARM
// V8M_BASELINE: #define __ARM_ARCH_ISA_THUMB 1
// V8M_BASELINE: #define __ARM_ARCH_PROFILE 'M'
// V8M_BASELINE-NOT: __ARM_FEATURE_CRC32
// V8M_BASELINE-NOT: __ARM_FEATURE_DSP
// V8M_BASELINE-NOT: __ARM_FP 0x{{.*}}
// V8M_BASELINE-NOT: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
// RUN: %clang -target armv8m.main-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_MAINLINE %s
// V8M_MAINLINE: #define __ARM_ARCH 8
// V8M_MAINLINE: #define __ARM_ARCH_8M_MAIN__ 1
// V8M_MAINLINE: #define __ARM_ARCH_EXT_IDIV__ 1
// V8M_MAINLINE-NOT: __ARM_ARCH_ISA_ARM
// V8M_MAINLINE: #define __ARM_ARCH_ISA_THUMB 2
// V8M_MAINLINE: #define __ARM_ARCH_PROFILE 'M'
// V8M_MAINLINE-NOT: __ARM_FEATURE_CRC32
// V8M_MAINLINE-NOT: __ARM_FEATURE_DSP
// V8M_MAINLINE-NOT: #define __ARM_FP 0x
// V8M_MAINLINE: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
// RUN: %clang -target armv8m.main-none-linux-gnueabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M-MAINLINE-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8m.main-none-linux-gnueabihf -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M-MAINLINE-ALLOW-FP-INSTR %s
// V8M-MAINLINE-ALLOW-FP-INSTR: #define __ARM_ARCH 8
// V8M-MAINLINE-ALLOW-FP-INSTR: #define __ARM_ARCH_8M_MAIN__ 1
// V8M-MAINLINE-ALLOW-FP-INSTR: #define __ARM_ARCH_EXT_IDIV__ 1
// V8M-MAINLINE-ALLOW-FP-INSTR-NOT: __ARM_ARCH_ISA_ARM
// V8M-MAINLINE-ALLOW-FP-INSTR: #define __ARM_ARCH_ISA_THUMB 2
// V8M-MAINLINE-ALLOW-FP-INSTR: #define __ARM_ARCH_PROFILE 'M'
// V8M-MAINLINE-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_CRC32
// V8M-MAINLINE-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_DSP
// V8M-MAINLINE-ALLOW-FP-INSTR: #define __ARM_FP 0xe
// V8M-MAINLINE-ALLOW-FP-INSTR: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
// RUN: %clang -target arm-none-linux-gnu -march=armv8-m.main+dsp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M_MAINLINE_DSP %s
// V8M_MAINLINE_DSP: #define __ARM_ARCH 8
// V8M_MAINLINE_DSP: #define __ARM_ARCH_8M_MAIN__ 1
// V8M_MAINLINE_DSP: #define __ARM_ARCH_EXT_IDIV__ 1
// V8M_MAINLINE_DSP-NOT: __ARM_ARCH_ISA_ARM
// V8M_MAINLINE_DSP: #define __ARM_ARCH_ISA_THUMB 2
// V8M_MAINLINE_DSP: #define __ARM_ARCH_PROFILE 'M'
// V8M_MAINLINE_DSP-NOT: __ARM_FEATURE_CRC32
// V8M_MAINLINE_DSP: #define __ARM_FEATURE_DSP 1
// V8M_MAINLINE_DSP-NOT: #define __ARM_FP 0x
// V8M_MAINLINE_DSP: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
// RUN: %clang -target arm-none-linux-gnueabi -march=armv8-m.main+dsp -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=V8M-MAINLINE-DSP-ALLOW-FP-INSTR %s
// V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_ARCH 8
// V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_ARCH_8M_MAIN__ 1
// V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_ARCH_EXT_IDIV__ 1
// V8M-MAINLINE-DSP-ALLOW-FP-INSTR-NOT: __ARM_ARCH_ISA_ARM
// V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_ARCH_ISA_THUMB 2
// V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_ARCH_PROFILE 'M'
// V8M-MAINLINE-DSP-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_CRC32
// V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_FEATURE_DSP 1
// V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __ARM_FP 0xe
// V8M-MAINLINE-DSP-ALLOW-FP-INSTR: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
// RUN: %clang -target arm-none-linux-gnu -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-DEFS %s
// CHECK-DEFS:#define __ARM_PCS 1
// CHECK-DEFS:#define __ARM_SIZEOF_MINIMAL_ENUM 4
// CHECK-DEFS:#define __ARM_SIZEOF_WCHAR_T 4
// RUN: %clang -target arm-none-linux-gnu -fno-math-errno -fno-signed-zeros\
// RUN: -fno-trapping-math -fassociative-math -freciprocal-math\
// RUN: -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s
// RUN: %clang -target arm-none-linux-gnu -ffast-math -x c -E -dM %s -o -\
// RUN: | FileCheck -match-full-lines --check-prefix=CHECK-FASTMATH %s
// CHECK-FASTMATH: #define __ARM_FP_FAST 1
// RUN: %clang -target arm-none-linux-gnu -fshort-wchar -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-SHORTWCHAR %s
// CHECK-SHORTWCHAR:#define __ARM_SIZEOF_WCHAR_T 2
// RUN: %clang -target arm-none-linux-gnu -fshort-enums -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-SHORTENUMS %s
// CHECK-SHORTENUMS:#define __ARM_SIZEOF_MINIMAL_ENUM 1
// Test that -mhwdiv has the right effect for a target CPU which has hwdiv enabled by default.
// RUN: %clang -target armv7 -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=HWDIV %s
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=HWDIV %s
// RUN: %clang -target armv7 -mcpu=cortex-a15 -mhwdiv=arm -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=HWDIV %s
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-a15 -mhwdiv=thumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=HWDIV %s
// HWDIV:#define __ARM_ARCH_EXT_IDIV__ 1
// RUN: %clang -target arm -mcpu=cortex-a15 -mhwdiv=thumb -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV %s
// RUN: %clang -target arm -mthumb -mcpu=cortex-a15 -mhwdiv=arm -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV %s
// RUN: %clang -target arm -mcpu=cortex-a15 -mhwdiv=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV %s
// RUN: %clang -target arm -mthumb -mcpu=cortex-a15 -mhwdiv=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NOHWDIV %s
// NOHWDIV-NOT:#define __ARM_ARCH_EXT_IDIV__
// Check that -mfpu works properly for Cortex-A7 (enabled by default).
// RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A7 %s
// RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A7 %s
// RUN: %clang -target armv7-none-linux-gnueabihf -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A7 %s
// RUN: %clang -target armv7-none-linux-gnueabihf -mthumb -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A7 %s
// DEFAULTFPU-A7:#define __ARM_FP 0xe
// DEFAULTFPU-A7:#define __ARM_NEON__ 1
// DEFAULTFPU-A7:#define __ARM_VFPV4__ 1
// RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a7 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A7 %s
// RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a7 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A7 %s
// FPUNONE-A7-NOT:#define __ARM_FP 0x{{.*}}
// FPUNONE-A7-NOT:#define __ARM_NEON__ 1
// FPUNONE-A7-NOT:#define __ARM_VFPV4__ 1
// RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a7 -mfpu=vfp4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NONEON-A7 %s
// RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a7 -mfpu=vfp4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NONEON-A7 %s
// NONEON-A7:#define __ARM_FP 0xe
// NONEON-A7-NOT:#define __ARM_NEON__ 1
// NONEON-A7:#define __ARM_VFPV4__ 1
// Check that -mfpu works properly for Cortex-A5 (enabled by default).
// RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A5 %s
// RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A5 %s
// DEFAULTFPU-A5:#define __ARM_FP 0xe
// DEFAULTFPU-A5:#define __ARM_NEON__ 1
// DEFAULTFPU-A5:#define __ARM_VFPV4__ 1
// RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a5 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A5 %s
// RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a5 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A5 %s
// FPUNONE-A5-NOT:#define __ARM_FP 0x{{.*}}
// FPUNONE-A5-NOT:#define __ARM_NEON__ 1
// FPUNONE-A5-NOT:#define __ARM_VFPV4__ 1
// RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a5 -mfpu=vfp4-d16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NONEON-A5 %s
// RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a5 -mfpu=vfp4-d16 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=NONEON-A5 %s
// NONEON-A5:#define __ARM_FP 0xe
// NONEON-A5-NOT:#define __ARM_NEON__ 1
// NONEON-A5:#define __ARM_VFPV4__ 1
// FIXME: add check for further predefines
// Test whether predefines are as expected when targeting ep9312.
// RUN: %clang -target armv4t -mcpu=ep9312 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A4T %s
// A4T-NOT:#define __ARM_FEATURE_DSP
// A4T-NOT:#define __ARM_FP 0x{{.*}}
// Test whether predefines are as expected when targeting arm10tdmi.
// RUN: %clang -target armv5 -mcpu=arm10tdmi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A5T %s
// A5T-NOT:#define __ARM_FEATURE_DSP
// A5T-NOT:#define __ARM_FP 0x{{.*}}
// Test whether predefines are as expected when targeting cortex-a5i (soft FP ABI as default).
// RUN: %clang -target armv7 -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A5 %s
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A5 %s
// A5:#define __ARM_ARCH 7
// A5:#define __ARM_ARCH_7A__ 1
// A5-NOT:#define __ARM_ARCH_EXT_IDIV__
// A5:#define __ARM_ARCH_PROFILE 'A'
// A5-NOT:#define __ARM_DWARF_EH__ 1
// A5-NOT: #define __ARM_FEATURE_DIRECTED_ROUNDING
// A5:#define __ARM_FEATURE_DSP 1
// A5-NOT: #define __ARM_FEATURE_NUMERIC_MAXMIN
// A5-NOT:#define __ARM_FP 0x
// Test whether predefines are as expected when targeting cortex-a5 (softfp FP ABI as default).
// RUN: %clang -target armv7-eabi -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A5-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-a5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A5-ALLOW-FP-INSTR %s
// A5-ALLOW-FP-INSTR:#define __ARM_ARCH 7
// A5-ALLOW-FP-INSTR:#define __ARM_ARCH_7A__ 1
// A5-ALLOW-FP-INSTR-NOT:#define __ARM_ARCH_EXT_IDIV__
// A5-ALLOW-FP-INSTR:#define __ARM_ARCH_PROFILE 'A'
// A5-ALLOW-FP-INSTR-NOT: #define __ARM_FEATURE_DIRECTED_ROUNDING
// A5-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// A5-ALLOW-FP-INSTR-NOT: #define __ARM_FEATURE_NUMERIC_MAXMIN
// A5-ALLOW-FP-INSTR:#define __ARM_FP 0xe
// Test whether predefines are as expected when targeting cortex-a7 (soft FP ABI as default).
// RUN: %clang -target armv7k -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A7 %s
// RUN: %clang -target armv7k -mthumb -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A7 %s
// A7:#define __ARM_ARCH 7
// A7:#define __ARM_ARCH_EXT_IDIV__ 1
// A7:#define __ARM_ARCH_PROFILE 'A'
// A7-NOT:#define __ARM_DWARF_EH__ 1
// A7:#define __ARM_FEATURE_DSP 1
// A7-NOT:#define __ARM_FP 0x
// Test whether predefines are as expected when targeting cortex-a7 (softfp FP ABI as default).
// RUN: %clang -target armv7k-eabi -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A7-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7k-eabi -mthumb -mcpu=cortex-a7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A7-ALLOW-FP-INSTR %s
// A7-ALLOW-FP-INSTR:#define __ARM_ARCH 7
// A7-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1
// A7-ALLOW-FP-INSTR:#define __ARM_ARCH_PROFILE 'A'
// A7-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// A7-ALLOW-FP-INSTR:#define __ARM_FP 0xe
// Test whether predefines are as expected when targeting cortex-a7.
// RUN: %clang -target x86_64-apple-darwin -arch armv7k -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV7K %s
// ARMV7K:#define __ARM_ARCH 7
// ARMV7K:#define __ARM_ARCH_EXT_IDIV__ 1
// ARMV7K:#define __ARM_ARCH_PROFILE 'A'
// ARMV7K:#define __ARM_DWARF_EH__ 1
// ARMV7K:#define __ARM_FEATURE_DSP 1
// ARMV7K:#define __ARM_FP 0xe
// ARMV7K:#define __ARM_PCS_VFP 1
// Test whether predefines are as expected when targeting cortex-a8 (soft FP ABI as default).
// RUN: %clang -target armv7 -mcpu=cortex-a8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A8 %s
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-a8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A8 %s
// A8-NOT:#define __ARM_ARCH_EXT_IDIV__
// A8:#define __ARM_FEATURE_DSP 1
// A8-NOT:#define __ARM_FP 0x
// Test whether predefines are as expected when targeting cortex-a8 (softfp FP ABI as default).
// RUN: %clang -target armv7-eabi -mcpu=cortex-a8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-a8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A8-ALLOW-FP-INSTR %s
// A8-ALLOW-FP-INSTR-NOT:#define __ARM_ARCH_EXT_IDIV__
// A8-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// A8-ALLOW-FP-INSTR:#define __ARM_FP 0xc
// Test whether predefines are as expected when targeting cortex-a9 (soft FP as default).
// RUN: %clang -target armv7 -mcpu=cortex-a9 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A9 %s
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-a9 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A9 %s
// A9-NOT:#define __ARM_ARCH_EXT_IDIV__
// A9:#define __ARM_FEATURE_DSP 1
// A9-NOT:#define __ARM_FP 0x
// Test whether predefines are as expected when targeting cortex-a9 (softfp FP as default).
// RUN: %clang -target armv7-eabi -mcpu=cortex-a9 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A9-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-a9 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A9-ALLOW-FP-INSTR %s
// A9-ALLOW-FP-INSTR-NOT:#define __ARM_ARCH_EXT_IDIV__
// A9-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// A9-ALLOW-FP-INSTR:#define __ARM_FP 0xe
// Check that -mfpu works properly for Cortex-A12 (enabled by default).
// RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A12 %s
// RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A12 %s
// DEFAULTFPU-A12:#define __ARM_FP 0xe
// DEFAULTFPU-A12:#define __ARM_NEON__ 1
// DEFAULTFPU-A12:#define __ARM_VFPV4__ 1
// RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a12 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A12 %s
// RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a12 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A12 %s
// FPUNONE-A12-NOT:#define __ARM_FP 0x{{.*}}
// FPUNONE-A12-NOT:#define __ARM_NEON__ 1
// FPUNONE-A12-NOT:#define __ARM_VFPV4__ 1
// Test whether predefines are as expected when targeting cortex-a12 (soft FP ABI as default).
// RUN: %clang -target armv7 -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A12 %s
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A12 %s
// A12:#define __ARM_ARCH 7
// A12:#define __ARM_ARCH_7A__ 1
// A12:#define __ARM_ARCH_EXT_IDIV__ 1
// A12:#define __ARM_ARCH_PROFILE 'A'
// A12:#define __ARM_FEATURE_DSP 1
// A12-NOT:#define __ARM_FP 0x
// Test whether predefines are as expected when targeting cortex-a12 (soft FP ABI as default).
// RUN: %clang -target armv7-eabi -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A12-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-a12 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A12-ALLOW-FP-INSTR %s
// A12-ALLOW-FP-INSTR:#define __ARM_ARCH 7
// A12-ALLOW-FP-INSTR:#define __ARM_ARCH_7A__ 1
// A12-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1
// A12-ALLOW-FP-INSTR:#define __ARM_ARCH_PROFILE 'A'
// A12-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// A12-ALLOW-FP-INSTR:#define __ARM_FP 0xe
// Test whether predefines are as expected when targeting cortex-a15 (soft FP ABI as default).
// RUN: %clang -target armv7 -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A15 %s
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A15 %s
// A15:#define __ARM_ARCH_EXT_IDIV__ 1
// A15:#define __ARM_FEATURE_DSP 1
// A15-NOT:#define __ARM_FP 0x
// Test whether predefines are as expected when targeting cortex-a15 (softfp ABI as default).
// RUN: %clang -target armv7-eabi -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A15-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-a15 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A15-ALLOW-FP-INSTR %s
// A15-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1
// A15-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// A15-ALLOW-FP-INSTR:#define __ARM_FP 0xe
// Check that -mfpu works properly for Cortex-A17 (enabled by default).
// RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A17 %s
// RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=DEFAULTFPU-A17 %s
// DEFAULTFPU-A17:#define __ARM_FP 0xe
// DEFAULTFPU-A17:#define __ARM_NEON__ 1
// DEFAULTFPU-A17:#define __ARM_VFPV4__ 1
// RUN: %clang -target armv7-none-linux-gnueabi -mcpu=cortex-a17 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A17 %s
// RUN: %clang -target armv7-none-linux-gnueabi -mthumb -mcpu=cortex-a17 -mfpu=none -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=FPUNONE-A17 %s
// FPUNONE-A17-NOT:#define __ARM_FP 0x{{.*}}
// FPUNONE-A17-NOT:#define __ARM_NEON__ 1
// FPUNONE-A17-NOT:#define __ARM_VFPV4__ 1
// Test whether predefines are as expected when targeting cortex-a17 (soft FP ABI as default).
// RUN: %clang -target armv7 -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A17 %s
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A17 %s
// A17:#define __ARM_ARCH 7
// A17:#define __ARM_ARCH_7A__ 1
// A17:#define __ARM_ARCH_EXT_IDIV__ 1
// A17:#define __ARM_ARCH_PROFILE 'A'
// A17:#define __ARM_FEATURE_DSP 1
// A17-NOT:#define __ARM_FP 0x
// Test whether predefines are as expected when targeting cortex-a17 (softfp FP ABI as default).
// RUN: %clang -target armv7-eabi -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A17-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-a17 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=A17-ALLOW-FP-INSTR %s
// A17-ALLOW-FP-INSTR:#define __ARM_ARCH 7
// A17-ALLOW-FP-INSTR:#define __ARM_ARCH_7A__ 1
// A17-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1
// A17-ALLOW-FP-INSTR:#define __ARM_ARCH_PROFILE 'A'
// A17-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// A17-ALLOW-FP-INSTR:#define __ARM_FP 0xe
// Test whether predefines are as expected when targeting swift (soft FP ABI as default).
// RUN: %clang -target armv7s -mcpu=swift -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=SWIFT %s
// RUN: %clang -target armv7s -mthumb -mcpu=swift -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=SWIFT %s
// SWIFT:#define __ARM_ARCH_EXT_IDIV__ 1
// SWIFT:#define __ARM_FEATURE_DSP 1
// SWIFT-NOT:#define __ARM_FP 0xxE
// Test whether predefines are as expected when targeting swift (softfp FP ABI as default).
// RUN: %clang -target armv7s-eabi -mcpu=swift -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=SWIFT-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7s-eabi -mthumb -mcpu=swift -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=SWIFT-ALLOW-FP-INSTR %s
// SWIFT-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1
// SWIFT-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// SWIFT-ALLOW-FP-INSTR:#define __ARM_FP 0xe
// Test whether predefines are as expected when targeting ARMv8-A Cortex implementations (soft FP ABI as default)
// RUN: %clang -target armv8 -mcpu=cortex-a32 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mthumb -mcpu=cortex-a32 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mcpu=cortex-a35 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mthumb -mcpu=cortex-a35 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mcpu=cortex-a53 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mthumb -mcpu=cortex-a53 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mcpu=cortex-a57 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mthumb -mcpu=cortex-a57 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mcpu=cortex-a72 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mthumb -mcpu=cortex-a72 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mcpu=cortex-a73 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mthumb -mcpu=cortex-a73 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
//
// RUN: %clang -target armv8 -mcpu=exynos-m1 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mthumb -mcpu=exynos-m1 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mcpu=exynos-m2 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mthumb -mcpu=exynos-m2 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mcpu=exynos-m3 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mthumb -mcpu=exynos-m3 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mcpu=exynos-m4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// RUN: %clang -target armv8 -mthumb -mcpu=exynos-m4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8 %s
// ARMV8:#define __ARM_ARCH_EXT_IDIV__ 1
// ARMV8:#define __ARM_FEATURE_DSP 1
// ARMV8-NOT:#define __ARM_FP 0x
// Test whether predefines are as expected when targeting ARMv8-A Cortex implementations (softfp FP ABI as default)
// RUN: %clang -target armv8-eabi -mcpu=cortex-a32 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mthumb -mcpu=cortex-a32 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mcpu=cortex-a35 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mthumb -mcpu=cortex-a35 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mcpu=cortex-a53 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mthumb -mcpu=cortex-a53 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mcpu=cortex-a57 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mthumb -mcpu=cortex-a57 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mcpu=cortex-a72 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mthumb -mcpu=cortex-a72 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mcpu=cortex-a73 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mthumb -mcpu=cortex-a73 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
//
// RUN: %clang -target armv8-eabi -mcpu=exynos-m1 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mthumb -mcpu=exynos-m1 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mcpu=exynos-m2 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mthumb -mcpu=exynos-m2 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mcpu=exynos-m3 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mthumb -mcpu=exynos-m3 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mcpu=exynos-m4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv8-eabi -mthumb -mcpu=exynos-m4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=ARMV8-ALLOW-FP-INSTR %s
// ARMV8-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1
// ARMV8-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// ARMV8-ALLOW-FP-INSTR:#define __ARM_FP 0xe
// Test whether predefines are as expected when targeting cortex-r4.
// RUN: %clang -target armv7 -mcpu=cortex-r4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4-ARM %s
// R4-ARM-NOT:#define __ARM_ARCH_EXT_IDIV__
// R4-ARM:#define __ARM_FEATURE_DSP 1
// R4-ARM-NOT:#define __ARM_FP 0x{{.*}}
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-r4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4-THUMB %s
// R4-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1
// R4-THUMB:#define __ARM_FEATURE_DSP 1
// R4-THUMB-NOT:#define __ARM_FP 0x{{.*}}
// Test whether predefines are as expected when targeting cortex-r4f (soft FP ABI as default).
// RUN: %clang -target armv7 -mcpu=cortex-r4f -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4F-ARM %s
// R4F-ARM-NOT:#define __ARM_ARCH_EXT_IDIV__
// R4F-ARM:#define __ARM_FEATURE_DSP 1
// R4F-ARM-NOT:#define __ARM_FP 0x
// Test whether predefines are as expected when targeting cortex-r4f (softfp FP ABI as default).
// RUN: %clang -target armv7-eabi -mcpu=cortex-r4f -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4F-ARM-ALLOW-FP-INSTR %s
// R4F-ARM-ALLOW-FP-INSTR-NOT:#define __ARM_ARCH_EXT_IDIV__
// R4F-ARM-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// R4F-ARM-ALLOW-FP-INSTR:#define __ARM_FP 0xc
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-r4f -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4F-THUMB %s
// R4F-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1
// R4F-THUMB:#define __ARM_FEATURE_DSP 1
// R4F-THUMB-NOT:#define __ARM_FP 0x
// RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-r4f -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R4F-THUMB-ALLOW-FP-INSTR %s
// R4F-THUMB-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1
// R4F-THUMB-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// R4F-THUMB-ALLOW-FP-INSTR:#define __ARM_FP 0xc
// Test whether predefines are as expected when targeting cortex-r5 (soft FP ABI as default).
// RUN: %clang -target armv7 -mcpu=cortex-r5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R5 %s
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-r5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R5 %s
// R5:#define __ARM_ARCH_EXT_IDIV__ 1
// R5:#define __ARM_FEATURE_DSP 1
// R5-NOT:#define __ARM_FP 0x
// Test whether predefines are as expected when targeting cortex-r5 (softfp FP ABI as default).
// RUN: %clang -target armv7-eabi -mcpu=cortex-r5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R5-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-r5 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R5-ALLOW-FP-INSTR %s
// R5-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1
// R5-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// R5-ALLOW-FP-INSTR:#define __ARM_FP 0xc
// Test whether predefines are as expected when targeting cortex-r7 and cortex-r8 (soft FP ABI as default).
// RUN: %clang -target armv7 -mcpu=cortex-r7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8 %s
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-r7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8 %s
// RUN: %clang -target armv7 -mcpu=cortex-r8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8 %s
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-r8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8 %s
// R7-R8:#define __ARM_ARCH_EXT_IDIV__ 1
// R7-R8:#define __ARM_FEATURE_DSP 1
// R7-R8-NOT:#define __ARM_FP 0x
// Test whether predefines are as expected when targeting cortex-r7 and cortex-r8 (softfp FP ABI as default).
// RUN: %clang -target armv7-eabi -mcpu=cortex-r7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-r7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7-eabi -mcpu=cortex-r8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-r8 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=R7-R8-ALLOW-FP-INSTR %s
// R7-R8-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1
// R7-R8-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// R7-R8-ALLOW-FP-INSTR:#define __ARM_FP 0xe
// Test whether predefines are as expected when targeting cortex-m0.
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-m0 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M0-THUMB %s
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-m0plus -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M0-THUMB %s
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-m1 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M0-THUMB %s
// RUN: %clang -target armv7 -mthumb -mcpu=sc000 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M0-THUMB %s
// M0-THUMB-NOT:#define __ARM_ARCH_EXT_IDIV__
// M0-THUMB-NOT:#define __ARM_FEATURE_DSP
// M0-THUMB-NOT:#define __ARM_FP 0x{{.*}}
// Test whether predefines are as expected when targeting cortex-m3.
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-m3 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M3-THUMB %s
// RUN: %clang -target armv7 -mthumb -mcpu=sc300 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M3-THUMB %s
// M3-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1
// M3-THUMB-NOT:#define __ARM_FEATURE_DSP
// M3-THUMB-NOT:#define __ARM_FP 0x{{.*}}
// Test whether predefines are as expected when targeting cortex-m4 (soft FP ABI as default).
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-m4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M4-THUMB %s
// M4-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1
// M4-THUMB:#define __ARM_FEATURE_DSP 1
// M4-THUMB-NOT:#define __ARM_FP 0x
// Test whether predefines are as expected when targeting cortex-m4 (softfp ABI as default).
// RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-m4 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M4-THUMB-ALLOW-FP-INSTR %s
// M4-THUMB-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1
// M4-THUMB-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// M4-THUMB-ALLOW-FP-INSTR:#define __ARM_FP 0x6
// Test whether predefines are as expected when targeting cortex-m7 (soft FP ABI as default).
// RUN: %clang -target armv7 -mthumb -mcpu=cortex-m7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M7-THUMB %s
// M7-THUMB:#define __ARM_ARCH_EXT_IDIV__ 1
// M7-THUMB:#define __ARM_FEATURE_DSP 1
// M7-THUMB-NOT:#define __ARM_FP 0x
// M7-THUMB-NOT:#define __ARM_FPV5__
// Test whether predefines are as expected when targeting cortex-m7 (softfp FP ABI as default).
// RUN: %clang -target armv7-eabi -mthumb -mcpu=cortex-m7 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M7-THUMB-ALLOW-FP-INSTR %s
// M7-THUMB-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1
// M7-THUMB-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// M7-THUMB-ALLOW-FP-INSTR:#define __ARM_FP 0xe
// M7-THUMB-ALLOW-FP-INSTR:#define __ARM_FPV5__ 1
// Test whether predefines are as expected when targeting v8m cores
// RUN: %clang -target arm -mcpu=cortex-m23 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M23 %s
// M23: #define __ARM_ARCH 8
// M23: #define __ARM_ARCH_8M_BASE__ 1
// M23: #define __ARM_ARCH_EXT_IDIV__ 1
// M23-NOT: __ARM_ARCH_ISA_ARM
// M23: #define __ARM_ARCH_ISA_THUMB 1
// M23: #define __ARM_ARCH_PROFILE 'M'
// M23-NOT: __ARM_FEATURE_CRC32
// M23-NOT: __ARM_FEATURE_DSP
// M23-NOT: __ARM_FP 0x{{.*}}
// M23-NOT: __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1
// Test whether predefines are as expected when targeting m33 (soft FP ABI as default).
// RUN: %clang -target arm -mcpu=cortex-m33 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M33 %s
// M33: #define __ARM_ARCH 8
// M33: #define __ARM_ARCH_8M_MAIN__ 1
// M33: #define __ARM_ARCH_EXT_IDIV__ 1
// M33-NOT: __ARM_ARCH_ISA_ARM
// M33: #define __ARM_ARCH_ISA_THUMB 2
// M33: #define __ARM_ARCH_PROFILE 'M'
// M33-NOT: __ARM_FEATURE_CRC32
// M33: #define __ARM_FEATURE_DSP 1
// M33-NOT: #define __ARM_FP 0x
// M33: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
// Test whether predefines are as expected when targeting m33 (softfp FP ABI as default).
// RUN: %clang -target arm-eabi -mcpu=cortex-m33 -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=M33-ALLOW-FP-INSTR %s
// M33-ALLOW-FP-INSTR: #define __ARM_ARCH 8
// M33-ALLOW-FP-INSTR: #define __ARM_ARCH_8M_MAIN__ 1
// M33-ALLOW-FP-INSTR: #define __ARM_ARCH_EXT_IDIV__ 1
// M33-ALLOW-FP-INSTR-NOT: __ARM_ARCH_ISA_ARM
// M33-ALLOW-FP-INSTR: #define __ARM_ARCH_ISA_THUMB 2
// M33-ALLOW-FP-INSTR: #define __ARM_ARCH_PROFILE 'M'
// M33-ALLOW-FP-INSTR-NOT: __ARM_FEATURE_CRC32
// M33-ALLOW-FP-INSTR: #define __ARM_FEATURE_DSP 1
// M33-ALLOW-FP-INSTR: #define __ARM_FP 0x6
// M33-ALLOW-FP-INSTR: #define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
// Test whether predefines are as expected when targeting krait (soft FP as default).
// RUN: %clang -target armv7 -mcpu=krait -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=KRAIT %s
// RUN: %clang -target armv7 -mthumb -mcpu=krait -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=KRAIT %s
// KRAIT:#define __ARM_ARCH_EXT_IDIV__ 1
// KRAIT:#define __ARM_FEATURE_DSP 1
// KRAIT-NOT:#define __ARM_VFPV4__
// Test whether predefines are as expected when targeting krait (softfp FP as default).
// RUN: %clang -target armv7-eabi -mcpu=krait -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=KRAIT-ALLOW-FP-INSTR %s
// RUN: %clang -target armv7-eabi -mthumb -mcpu=krait -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=KRAIT-ALLOW-FP-INSTR %s
// KRAIT-ALLOW-FP-INSTR:#define __ARM_ARCH_EXT_IDIV__ 1
// KRAIT-ALLOW-FP-INSTR:#define __ARM_FEATURE_DSP 1
// KRAIT-ALLOW-FP-INSTR:#define __ARM_VFPV4__ 1
// RUN: %clang -target armv8.1a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V81A %s
// CHECK-V81A: #define __ARM_ARCH 8
// CHECK-V81A: #define __ARM_ARCH_8_1A__ 1
// CHECK-V81A: #define __ARM_ARCH_PROFILE 'A'
// CHECK-V81A: #define __ARM_FEATURE_QRDMX 1
// CHECK-V81A: #define __ARM_FP 0xe
// RUN: %clang -target armv8.2a-none-none-eabi -x c -E -dM %s -o - | FileCheck -match-full-lines --check-prefix=CHECK-V82A %s
// CHECK-V82A: #define __ARM_ARCH 8
// CHECK-V82A: #define __ARM_ARCH_8_2A__ 1
// CHECK-V82A: #define __ARM_ARCH_PROFILE 'A'
// CHECK-V82A: #define __ARM_FEATURE_QRDMX 1
// CHECK-V82A: #define __ARM_FP 0xe
|
the_stack_data/54826215.c | // Includes
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
// Delcare function
int get_index(char *s);
char *get_string(const char *prompt);
int main(void)
{
// Prompt user for text input
char *text = get_string("Text: ");
// Declare function
int index = get_index(text);
// Print output, which is the grade level of the provided text
// If index number is 16 or higher
if (index >= 16)
{
printf("Grade 16+\n");
}
// If the index number is less than 1
else if (index < 1)
{
printf("Before Grade 1\n");
}
// Final case
else
{
printf("Grade %d\n", index);
}
}
int get_index(char *s)
{
// Declare variable to store the number of letters.
int letters = 0;
// Declare variable to store the number of sentences.
int sentences = 0;
// Declare variable to store the number of words.
int words = 0;
for (int i = 0; i < strlen(s); i++)
{
// Increment letter count
char ch = s[i];
if (isalpha(ch))
{
letters++;
}
// Increment word count
if (isspace(ch))
{
words++;
}
// Increment Sentences
if (ch == '.' || ch == '!' || ch == '?')
{
sentences++;
}
}
// Account for last word since the word increment for loop misses the last word
words++;
// Declare and define variable for average number of letters per 100 words in the text
float L = (letters * 100.0f) / words;
// Declare and define variable for average number of sentences per 100 words in the text
float S = (sentences * 100.0f) / words;
// Declare and define variable calculated from the Coleman-Liau index
return round(0.0588 * L - 0.296 * S - 15.8);
}
// get_string function. Source: https://stackoverflow.com/questions/48282630/troubles-creating-a-get-string-function-in-c
char *get_string(const char *prompt)
{
char temp[350] = ""; // Maximum number of characters
int size,count;
while ( 1)
{
printf ( "%s",prompt);
if ( fgets ( temp, sizeof temp, stdin)) {
if ( !strchr ( temp, '\n')) {//no newline
printf("\x1B[31mError\x1B[0m: too long.\n%s",prompt);
size = strlen ( temp);
do {
fgets ( temp, sizeof temp, stdin);//read more and discard
size += strlen ( temp);
} while (!strchr ( temp, '\n'));//loop until newline found
printf("size :%i\n",size);
continue;//re prompt
}
break;
}
else {
fprintf ( stderr, "fgets problem\n");
return NULL;
}
}
temp[strcspn ( temp,"\n")] = '\0';//remove newline
char *word = malloc(strlen ( temp) + 1);
strcpy ( word, temp);
return word;
} |
the_stack_data/76701271.c | #include <stdio.h>
void inc(int *x) {
printf("%d\n", *x);
(*x)++;
printf("%d\n", *x);
}
int main(void) {
int x = 7;
inc(&x);
printf("%d\n", x); // imprime 8
}
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.