file
stringlengths
18
26
data
stringlengths
2
1.05M
the_stack_data/181392709.c
// RUN: %clang_cc1 -S -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s // CHECK: !DIGlobalVariable( static const unsigned int ro = 201; void bar(int); void foo() { bar(ro); }
the_stack_data/135770.c
/* This program allows us to visualize the layout of a * process in memory, printing the addresses of * various parts of the program, including components * in the text, data, and bss segments as well as on * the heap and the stack. * * This program can also illustrate a stack overflow * if compiled with '-DSTACKOVERFLOW'. */ #include <err.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #define MALLOC_SIZE 32 extern char **environ; int arraySize(char **a) { int n = 0; char **tmp = a; while (*tmp++) { n++; } return n; } void printArray(char **a, char *name) { int n = arraySize(a); (void)printf("0x%12lX %-7s[%d]\n", (unsigned long)&a[n], name, n); (void)printf("0x%12lX %-7s[%d] (0x%12lX '%s')\n", (unsigned long)&a[n-1], name, n-1, (unsigned long)a[n-1], a[n-1]); (void)printf("0x%12lX %-7s[0] (0x%12lX '%s')\n", (unsigned long)&a[0], name, (unsigned long)a[0], a[0]); (void)printf("\n"); } int main(int argc, char **argv, char **envp) { char *ptr; (void)printf("At program start:\n"); printArray(envp, "envp"); printArray(environ, "environ"); if (setenv("FOO", "a longer value", 1) < 0) { err(EXIT_FAILURE, "unable to setenv(3)"); /* NOTREACHED */ } printf("After setenv(3):\n"); printArray(envp, "envp"); printArray(environ, "environ"); (void)printf("Stack:\n"); (void)printf("------\n"); (void)printf("0x%12lX int argc\n", (unsigned long)&argc); (void)printf("0x%12lX char **argv\n", (unsigned long)&argv); (void)printf("0x%12lX char **envp\n", (unsigned long)&envp); (void)printf("\n"); (void)printf("Heap:\n"); (void)printf("-----\n"); if ((ptr = malloc(MALLOC_SIZE)) == NULL) { err(EXIT_FAILURE, "unable to allocate memory"); /* NOTREACHED */ } (void)printf("0x%12lX malloced area ends\n", (unsigned long)ptr+MALLOC_SIZE); (void)printf("0x%12lX malloced area begins\n", (unsigned long)ptr); free(ptr); (void)printf("\n"); (void)printf("Uninitialized Data (BSS):\n"); (void)printf("-------------------------\n"); (void)printf("0x%12lX extern char **environ\n", (unsigned long)&environ); (void)printf("\n"); return EXIT_SUCCESS; }
the_stack_data/112036.c
// SPDX-FileCopyrightText: University of Freiburg // // SPDX-License-Identifier: LGPL-3.0-or-later //#Unsafe //@ ltl invariant positive: (<> AP(x < 0)); int x=0; void foo(){ x++; } void main() { while(1){ foo(); } }
the_stack_data/103266052.c
/* =========================================================================== Copyright (C) 1999-2005 Id Software, Inc. Copyright (C) 2005 Stuart Dalton ([email protected]) Copyright (C) 2005-2006 Joerg Dietrich <[email protected]> This file is part of Quake III Arena source code. Quake III Arena source code 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. Quake III Arena source code 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 Quake III Arena source code; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ // Ogg Opus support is enabled by this define #ifdef USE_CODEC_OPUS // includes for the Q3 sound system #include "client.h" #include "snd_codec.h" // includes for the Ogg Opus codec #include <errno.h> #include <opusfile.h> // samples are 16 bit #define OPUS_SAMPLEWIDTH 2 // Q3 Ogg Opus codec snd_codec_t opus_codec = { "opus", S_OggOpus_CodecLoad, S_OggOpus_CodecOpenStream, S_OggOpus_CodecReadStream, S_OggOpus_CodecCloseStream, NULL }; // callbacks for opusfile // fread() replacement int S_OggOpus_Callback_read(void *datasource, unsigned char *ptr, int size ) { snd_stream_t *stream; int bytesRead = 0; // check if input is valid if(!ptr) { errno = EFAULT; return -1; } if(!size) { // It's not an error, caller just wants zero bytes! errno = 0; return 0; } if (size < 0) { errno = EINVAL; return -1; } if(!datasource) { errno = EBADF; return -1; } // we use a snd_stream_t in the generic pointer to pass around stream = (snd_stream_t *) datasource; // read it with the Q3 function FS_Read() bytesRead = FS_Read(ptr, size, stream->file); // update the file position stream->pos += bytesRead; return bytesRead; } // fseek() replacement int S_OggOpus_Callback_seek(void *datasource, opus_int64 offset, int whence) { snd_stream_t *stream; int retVal = 0; // check if input is valid if(!datasource) { errno = EBADF; return -1; } // snd_stream_t in the generic pointer stream = (snd_stream_t *) datasource; // we must map the whence to its Q3 counterpart switch(whence) { case SEEK_SET : { // set the file position in the actual file with the Q3 function retVal = FS_Seek(stream->file, (long) offset, FS_SEEK_SET); // something has gone wrong, so we return here if(retVal < 0) { return retVal; } // keep track of file position stream->pos = (int) offset; break; } case SEEK_CUR : { // set the file position in the actual file with the Q3 function retVal = FS_Seek(stream->file, (long) offset, FS_SEEK_CUR); // something has gone wrong, so we return here if(retVal < 0) { return retVal; } // keep track of file position stream->pos += (int) offset; break; } case SEEK_END : { // set the file position in the actual file with the Q3 function retVal = FS_Seek(stream->file, (long) offset, FS_SEEK_END); // something has gone wrong, so we return here if(retVal < 0) { return retVal; } // keep track of file position stream->pos = stream->length + (int) offset; break; } default : { // unknown whence, so we return an error errno = EINVAL; return -1; } } // stream->pos shouldn't be smaller than zero or bigger than the filesize stream->pos = (stream->pos < 0) ? 0 : stream->pos; stream->pos = (stream->pos > stream->length) ? stream->length : stream->pos; return 0; } // fclose() replacement int S_OggOpus_Callback_close(void *datasource) { // we do nothing here and close all things manually in S_OggOpus_CodecCloseStream() return 0; } // ftell() replacement opus_int64 S_OggOpus_Callback_tell(void *datasource) { snd_stream_t *stream; // check if input is valid if(!datasource) { errno = EBADF; return -1; } // snd_stream_t in the generic pointer stream = (snd_stream_t *) datasource; return (opus_int64) FS_FTell(stream->file); } // the callback structure const OpusFileCallbacks S_OggOpus_Callbacks = { &S_OggOpus_Callback_read, &S_OggOpus_Callback_seek, &S_OggOpus_Callback_tell, &S_OggOpus_Callback_close }; /* ================= S_OggOpus_CodecOpenStream ================= */ snd_stream_t *S_OggOpus_CodecOpenStream(const char *filename) { snd_stream_t *stream; // Opus codec control structure OggOpusFile *of; // some variables used to get informations about the file const OpusHead *opusInfo; ogg_int64_t numSamples; // check if input is valid if(!filename) { return NULL; } // Open the stream stream = S_CodecUtilOpen(filename, &opus_codec); if(!stream) { return NULL; } // open the codec with our callbacks and stream as the generic pointer of = op_open_callbacks(stream, &S_OggOpus_Callbacks, NULL, 0, NULL ); if (!of) { S_CodecUtilClose(&stream); return NULL; } // the stream must be seekable if(!op_seekable(of)) { op_free(of); S_CodecUtilClose(&stream); return NULL; } // get the info about channels and rate opusInfo = op_head(of, -1); if(!opusInfo) { op_free(of); S_CodecUtilClose(&stream); return NULL; } if(opusInfo->stream_count != 1) { op_free(of); S_CodecUtilClose(&stream); Com_Printf("Only Ogg Opus files with one stream are support\n"); return NULL; } if(opusInfo->channel_count != 1 && opusInfo->channel_count != 2) { op_free(of); S_CodecUtilClose(&stream); Com_Printf("Only mono and stereo Ogg Opus files are supported\n"); return NULL; } // get the number of sample-frames in the file numSamples = op_pcm_total(of, -1); // fill in the info-structure in the stream stream->info.rate = 48000; stream->info.width = OPUS_SAMPLEWIDTH; stream->info.channels = opusInfo->channel_count; stream->info.samples = numSamples; stream->info.size = stream->info.samples * stream->info.channels * stream->info.width; stream->info.dataofs = 0; // We use stream->pos for the file pointer in the compressed ogg file stream->pos = 0; // We use the generic pointer in stream for the opus codec control structure stream->ptr = of; return stream; } /* ================= S_OggOpus_CodecCloseStream ================= */ void S_OggOpus_CodecCloseStream(snd_stream_t *stream) { // check if input is valid if(!stream) { return; } // let the opus codec cleanup its stuff op_free((OggOpusFile *) stream->ptr); // close the stream S_CodecUtilClose(&stream); } /* ================= S_OggOpus_CodecReadStream ================= */ int S_OggOpus_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer) { // buffer handling int samplesRead, samplesLeft, c; opus_int16 *bufPtr; // check if input is valid if(!(stream && buffer)) { return 0; } if(bytes <= 0) { return 0; } samplesRead = 0; samplesLeft = bytes / stream->info.channels / stream->info.width; bufPtr = buffer; if(samplesLeft <= 0) { return 0; } // cycle until we have the requested or all available bytes read while(-1) { // read some samples from the opus codec c = op_read((OggOpusFile *) stream->ptr, bufPtr + samplesRead * stream->info.channels, samplesLeft * stream->info.channels, NULL); // no more samples are left if(c <= 0) { break; } samplesRead += c; samplesLeft -= c; // we have enough samples if(samplesLeft <= 0) { break; } } return samplesRead * stream->info.channels * stream->info.width; } /* ===================================================================== S_OggOpus_CodecLoad We handle S_OggOpus_CodecLoad as a special case of the streaming functions where we read the whole stream at once. ====================================================================== */ void *S_OggOpus_CodecLoad(const char *filename, snd_info_t *info) { snd_stream_t *stream; byte *buffer; int bytesRead; // check if input is valid if(!(filename && info)) { return NULL; } // open the file as a stream stream = S_OggOpus_CodecOpenStream(filename); if(!stream) { return NULL; } // copy over the info info->rate = stream->info.rate; info->width = stream->info.width; info->channels = stream->info.channels; info->samples = stream->info.samples; info->size = stream->info.size; info->dataofs = stream->info.dataofs; // allocate a buffer // this buffer must be free-ed by the caller of this function buffer = Hunk_AllocateTempMemory(info->size); if(!buffer) { S_OggOpus_CodecCloseStream(stream); return NULL; } // fill the buffer bytesRead = S_OggOpus_CodecReadStream(stream, info->size, buffer); // we don't even have read a single byte if(bytesRead <= 0) { Hunk_FreeTempMemory(buffer); S_OggOpus_CodecCloseStream(stream); return NULL; } S_OggOpus_CodecCloseStream(stream); return buffer; } #endif // USE_CODEC_OPUS
the_stack_data/26699255.c
// Check that we can operate on files from /dev/fd. // REQUIRES: dev-fd-fs // REQUIRES: shell // Check reading from named pipes. We cat the input here instead of redirecting // it to ensure that /dev/fd/0 is a named pipe, not just a redirected file. // // RUN: cat %s | %clang -x c /dev/fd/0 -E > %t // RUN: FileCheck --check-prefix DEV-FD-INPUT < %t %s // // RUN: cat %s | %clang -x c %s -E -DINCLUDE_FROM_STDIN > %t // RUN: FileCheck --check-prefix DEV-FD-INPUT \ // RUN: --check-prefix DEV-FD-INPUT-INCLUDE < %t %s // // DEV-FD-INPUT-INCLUDE: int w; // DEV-FD-INPUT: int x; // DEV-FD-INPUT-INCLUDE: int y; // Check writing to /dev/fd named pipes. We use cat here as before to ensure we // get a named pipe. // // RUN: %clang -x c %s -E -o /dev/fd/1 | cat > %t // RUN: FileCheck --check-prefix DEV-FD-FIFO-OUTPUT < %t %s // // DEV-FD-FIFO-OUTPUT: int x; // Check writing to /dev/fd regular files. // // RUN: %clang -x c %s -E -o /dev/fd/1 > %t // RUN: FileCheck --check-prefix DEV-FD-REG-OUTPUT < %t %s // // DEV-FD-REG-OUTPUT: int x; #ifdef INCLUDE_FROM_STDIN #undef INCLUDE_FROM_STDIN int w; #include "/dev/fd/0" int y; #else int x; #endif
the_stack_data/55883.c
void f(char *p) { p[1]=1; } int main () { char dummy[10]; f(dummy); }
the_stack_data/98576282.c
#include<stdio.h> #include<stdlib.h> /*----Function Prototypes-----*/ void create(); void display(); void insert_begin(); void insert_end(); void insert_pos(); void delete_begin(); void delete_end(); void delete_pos(); /*-----------------------------*/ struct node { int info; struct node *next; }; struct node *start=NULL; //Execution of each program start form main() function. int main(void) //main() starts { int choice; while(1){ printf("\n***SINGLE LINKED LIST OPERATIONS:****\n"); printf("---------------------------------------"); printf("\n 1.Create"); printf("\n 2.Display"); printf("\n 3.Insert at the beginning"); printf("\n 4.Insert at the end"); printf("\n 5.Insert at specified position"); printf("\n 6.Delete from beginning"); printf("\n 7.Delete from the end"); printf("\n 8.Delete from specified position"); printf("\n 9.Exit"); printf("\n--------------------------------------\n"); printf("Enter your choice:\t"); scanf("%d",&choice); switch(choice) { case 1: create(); break; case 2: display(); break; case 3: insert_begin(); break; case 4: insert_end(); break; case 5: insert_pos(); break; case 6: delete_begin(); break; case 7: delete_end(); break; case 8: delete_pos(); break; case 9: exit(0); break; default: printf("\n Wrong Choice:\n"); break; }//end of switch() } return 0; }//end of main() void create() //create() function will create a node of link-list. { struct node *temp,*ptr; temp=(struct node *)malloc(sizeof(struct node)); if(temp==NULL) { printf("\nOut of Memory Space:\n"); exit(0); } printf("\nEnter the data value for the node:\t"); scanf("%d",&temp->info); temp->next=NULL; if(start==NULL) { start=temp; } else { ptr=start; while(ptr->next!=NULL) { ptr=ptr->next; } ptr->next=temp; } display(); }//end of create() void display() { struct node *ptr; if(start==NULL) { printf("\nList is empty:\n"); return; } else { ptr=start; printf("\nThe List elements are:"); printf("\n**************************\n"); while(ptr!=NULL) { printf("%d\t",ptr->info ); ptr=ptr->next ; }//end of while }//end of else printf("\n**************************\n"); }//end of display() void insert_begin() { struct node *temp; temp=(struct node *)malloc(sizeof(struct node)); if(temp==NULL) { printf("\nOut of Memory Space:\n"); return; } printf("\nEnter the data value for the node:\t" ); scanf("%d",&temp->info); temp->next =NULL; if(start==NULL) { start=temp; } else { temp->next=start; start=temp; } display(); }//end of insert_begin() void insert_end() { struct node *temp,*ptr; temp=(struct node *)malloc(sizeof(struct node)); if(temp==NULL) { printf("\nOut of Memory Space:\n"); return; } printf("\nEnter the data value for the node:\t" ); scanf("%d",&temp->info ); temp->next =NULL; if(start==NULL) { start=temp; } else { ptr=start; while(ptr->next !=NULL) { ptr=ptr->next ; } ptr->next =temp; } display(); }//end of insert_end void insert_pos() { struct node *ptr,*temp; int i,pos; temp=(struct node *)malloc(sizeof(struct node)); if(temp==NULL) { printf("\nOut of Memory Space:\n"); return; } printf("\nEnter the position for the new node to be inserted:\t"); scanf("%d",&pos); printf("\nEnter the data value of the node:\t"); scanf("%d",&temp->info) ; temp->next=NULL; if(pos==0) { temp->next=start; start=temp; } else { for(i=0,ptr=start;i<pos-1;i++) { ptr=ptr->next; if(ptr==NULL) { printf("\nPosition not found:[Handle with care]\n"); return; } } temp->next =ptr->next ; ptr->next=temp; }//end of else display(); }//end of insert_pos void delete_begin() { struct node *ptr; ptr=start; if(ptr==NULL) { printf("\nList is Empty:\n"); return; } else { ptr=start; start=start->next ; printf("\nThe deleted element is :%d\t",ptr->info); free(ptr); } display(); }//end of delete_begin() void delete_end() { struct node *temp,*ptr; if(start==NULL) { printf("\nList is Empty:"); exit(0); } else if(start->next ==NULL) { ptr=start; start=NULL; printf("\nThe deleted element is:%d\t",ptr->info); free(ptr); } else { ptr=start; while(ptr->next!=NULL) { temp=ptr; ptr=ptr->next; } temp->next=NULL; printf("\nThe deleted element is:%d\t",ptr->info); free(ptr); } display(); }//end of delete_begin() void delete_pos() { int i,pos; struct node *temp,*ptr; if(start==NULL) { printf("\nThe List is Empty:\n"); exit(0); } else { printf("\nEnter the position of the node to be deleted:\t"); scanf("%d",&pos); if(pos==0) { ptr=start; start=start->next ; printf("\nThe deleted element is:%d\t",ptr->info ); free(ptr); } else { ptr=start; for(i=0;i<pos;i++) { temp=ptr; ptr=ptr->next ; if(ptr==NULL) { printf("\nPosition not Found:\n"); return; } } temp->next =ptr->next ; printf("\nThe deleted element is:%d\t",ptr->info ); free(ptr); } }//end of else display(); }//end of delete_pos()
the_stack_data/75139148.c
//#define _GNU_SOURCE #include <sched.h> /* * Find the core the thread belongs to */ int mycpu_ () { /* int sched_getcpu(void); */ int cpu; cpu = sched_getcpu(); return cpu; } int mycpu() { return mycpu_(); }
the_stack_data/13036.c
// PASS: * // RUN: ${CATO_ROOT}/src/scripts/cexecute_pass.py %s -o %t // RUN: diff <(mpirun -np 2 %t) %s.reference_output #include <stdio.h> #include <stdlib.h> #include <omp.h> int main() { int*** M = (int***) malloc(sizeof(int**)*2); M[0] = (int**)malloc(sizeof(int**)*2); M[1] = (int**)malloc(sizeof(int**)*2); M[0][0] = (int*)malloc(sizeof(int*)*2); M[0][1] = (int*)malloc(sizeof(int*)*2); M[1][0] = (int*)malloc(sizeof(int*)*2); M[1][1] = (int*)malloc(sizeof(int*)*2); M[0][0][0] = 42; M[0][0][1] = 42; M[0][1][0] = 42; M[0][1][1] = 42; M[1][0][0] = 46; M[1][0][1] = 46; M[1][1][0] = 46; M[1][1][1] = 46; printf("[\n[[%d,%d]\n[%d,%d]]\n[[%d,%d]\n[%d,%d]\n]\n", M[0][0][0],M[0][0][1],M[0][1][0],M[0][1][1],M[1][0][0],M[1][0][1],M[1][1][0],M[1][1][1]); free(M[0][0]); free(M[0][1]); free(M[1][0]); free(M[1][1]); free(M[0]); free(M[1]); free(M); }
the_stack_data/34770.c
/* f2c.h -- Standard Fortran to C header file */ /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ #ifndef F2C_INCLUDE #define F2C_INCLUDE #include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimag(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} #define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static complex c_b1 = {0.f,0.f}; static complex c_b2 = {1.f,0.f}; static integer c__1 = 1; /* > \brief \b CLAHRD reduces the first nb columns of a general rectangular matrix A so that elements below th e k-th subdiagonal are zero, and returns auxiliary matrices which are needed to apply the transformati on to the unreduced part of A. */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download CLAHRD + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clahrd. f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clahrd. f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clahrd. f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE CLAHRD( N, K, NB, A, LDA, TAU, T, LDT, Y, LDY ) */ /* INTEGER K, LDA, LDT, LDY, N, NB */ /* COMPLEX A( LDA, * ), T( LDT, NB ), TAU( NB ), */ /* $ Y( LDY, NB ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > This routine is deprecated and has been replaced by routine CLAHR2. */ /* > */ /* > CLAHRD reduces the first NB columns of a complex general n-by-(n-k+1) */ /* > matrix A so that elements below the k-th subdiagonal are zero. The */ /* > reduction is performed by a unitary similarity transformation */ /* > Q**H * A * Q. The routine returns the matrices V and T which determine */ /* > Q as a block reflector I - V*T*V**H, and also the matrix Y = A * V * T. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The order of the matrix A. */ /* > \endverbatim */ /* > */ /* > \param[in] K */ /* > \verbatim */ /* > K is INTEGER */ /* > The offset for the reduction. Elements below the k-th */ /* > subdiagonal in the first NB columns are reduced to zero. */ /* > \endverbatim */ /* > */ /* > \param[in] NB */ /* > \verbatim */ /* > NB is INTEGER */ /* > The number of columns to be reduced. */ /* > \endverbatim */ /* > */ /* > \param[in,out] A */ /* > \verbatim */ /* > A is COMPLEX array, dimension (LDA,N-K+1) */ /* > On entry, the n-by-(n-k+1) general matrix A. */ /* > On exit, the elements on and above the k-th subdiagonal in */ /* > the first NB columns are overwritten with the corresponding */ /* > elements of the reduced matrix; the elements below the k-th */ /* > subdiagonal, with the array TAU, represent the matrix Q as a */ /* > product of elementary reflectors. The other columns of A are */ /* > unchanged. See Further Details. */ /* > \endverbatim */ /* > */ /* > \param[in] LDA */ /* > \verbatim */ /* > LDA is INTEGER */ /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[out] TAU */ /* > \verbatim */ /* > TAU is COMPLEX array, dimension (NB) */ /* > The scalar factors of the elementary reflectors. See Further */ /* > Details. */ /* > \endverbatim */ /* > */ /* > \param[out] T */ /* > \verbatim */ /* > T is COMPLEX array, dimension (LDT,NB) */ /* > The upper triangular matrix T. */ /* > \endverbatim */ /* > */ /* > \param[in] LDT */ /* > \verbatim */ /* > LDT is INTEGER */ /* > The leading dimension of the array T. LDT >= NB. */ /* > \endverbatim */ /* > */ /* > \param[out] Y */ /* > \verbatim */ /* > Y is COMPLEX array, dimension (LDY,NB) */ /* > The n-by-nb matrix Y. */ /* > \endverbatim */ /* > */ /* > \param[in] LDY */ /* > \verbatim */ /* > LDY is INTEGER */ /* > The leading dimension of the array Y. LDY >= f2cmax(1,N). */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date December 2016 */ /* > \ingroup complexOTHERauxiliary */ /* > \par Further Details: */ /* ===================== */ /* > */ /* > \verbatim */ /* > */ /* > The matrix Q is represented as a product of nb elementary reflectors */ /* > */ /* > Q = H(1) H(2) . . . H(nb). */ /* > */ /* > Each H(i) has the form */ /* > */ /* > H(i) = I - tau * v * v**H */ /* > */ /* > where tau is a complex scalar, and v is a complex vector with */ /* > v(1:i+k-1) = 0, v(i+k) = 1; v(i+k+1:n) is stored on exit in */ /* > A(i+k+1:n,i), and tau in TAU(i). */ /* > */ /* > The elements of the vectors v together form the (n-k+1)-by-nb matrix */ /* > V which is needed, with T and Y, to apply the transformation to the */ /* > unreduced part of the matrix, using an update of the form: */ /* > A := (I - V*T*V**H) * (A - Y*V**H). */ /* > */ /* > The contents of A on exit are illustrated by the following example */ /* > with n = 7, k = 3 and nb = 2: */ /* > */ /* > ( a h a a a ) */ /* > ( a h a a a ) */ /* > ( a h a a a ) */ /* > ( h h a a a ) */ /* > ( v1 h a a a ) */ /* > ( v1 v2 a a a ) */ /* > ( v1 v2 a a a ) */ /* > */ /* > where a denotes an element of the original matrix A, h denotes a */ /* > modified element of the upper Hessenberg matrix H, and vi denotes an */ /* > element of the vector defining H(i). */ /* > \endverbatim */ /* > */ /* ===================================================================== */ /* Subroutine */ int clahrd_(integer *n, integer *k, integer *nb, complex *a, integer *lda, complex *tau, complex *t, integer *ldt, complex *y, integer *ldy) { /* System generated locals */ integer a_dim1, a_offset, t_dim1, t_offset, y_dim1, y_offset, i__1, i__2, i__3; complex q__1; /* Local variables */ integer i__; extern /* Subroutine */ int cscal_(integer *, complex *, complex *, integer *), cgemv_(char *, integer *, integer *, complex *, complex *, integer *, complex *, integer *, complex *, complex *, integer *), ccopy_(integer *, complex *, integer *, complex *, integer *), caxpy_(integer *, complex *, complex *, integer *, complex *, integer *), ctrmv_(char *, char *, char *, integer *, complex *, integer *, complex *, integer *); complex ei; extern /* Subroutine */ int clarfg_(integer *, complex *, complex *, integer *, complex *), clacgv_(integer *, complex *, integer *); /* -- LAPACK auxiliary routine (version 3.7.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* December 2016 */ /* ===================================================================== */ /* Quick return if possible */ /* Parameter adjustments */ --tau; a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; t_dim1 = *ldt; t_offset = 1 + t_dim1 * 1; t -= t_offset; y_dim1 = *ldy; y_offset = 1 + y_dim1 * 1; y -= y_offset; /* Function Body */ if (*n <= 1) { return 0; } i__1 = *nb; for (i__ = 1; i__ <= i__1; ++i__) { if (i__ > 1) { /* Update A(1:n,i) */ /* Compute i-th column of A - Y * V**H */ i__2 = i__ - 1; clacgv_(&i__2, &a[*k + i__ - 1 + a_dim1], lda); i__2 = i__ - 1; q__1.r = -1.f, q__1.i = 0.f; cgemv_("No transpose", n, &i__2, &q__1, &y[y_offset], ldy, &a[*k + i__ - 1 + a_dim1], lda, &c_b2, &a[i__ * a_dim1 + 1], & c__1); i__2 = i__ - 1; clacgv_(&i__2, &a[*k + i__ - 1 + a_dim1], lda); /* Apply I - V * T**H * V**H to this column (call it b) from the */ /* left, using the last column of T as workspace */ /* Let V = ( V1 ) and b = ( b1 ) (first I-1 rows) */ /* ( V2 ) ( b2 ) */ /* where V1 is unit lower triangular */ /* w := V1**H * b1 */ i__2 = i__ - 1; ccopy_(&i__2, &a[*k + 1 + i__ * a_dim1], &c__1, &t[*nb * t_dim1 + 1], &c__1); i__2 = i__ - 1; ctrmv_("Lower", "Conjugate transpose", "Unit", &i__2, &a[*k + 1 + a_dim1], lda, &t[*nb * t_dim1 + 1], &c__1); /* w := w + V2**H *b2 */ i__2 = *n - *k - i__ + 1; i__3 = i__ - 1; cgemv_("Conjugate transpose", &i__2, &i__3, &c_b2, &a[*k + i__ + a_dim1], lda, &a[*k + i__ + i__ * a_dim1], &c__1, &c_b2, & t[*nb * t_dim1 + 1], &c__1); /* w := T**H *w */ i__2 = i__ - 1; ctrmv_("Upper", "Conjugate transpose", "Non-unit", &i__2, &t[ t_offset], ldt, &t[*nb * t_dim1 + 1], &c__1); /* b2 := b2 - V2*w */ i__2 = *n - *k - i__ + 1; i__3 = i__ - 1; q__1.r = -1.f, q__1.i = 0.f; cgemv_("No transpose", &i__2, &i__3, &q__1, &a[*k + i__ + a_dim1], lda, &t[*nb * t_dim1 + 1], &c__1, &c_b2, &a[*k + i__ + i__ * a_dim1], &c__1); /* b1 := b1 - V1*w */ i__2 = i__ - 1; ctrmv_("Lower", "No transpose", "Unit", &i__2, &a[*k + 1 + a_dim1] , lda, &t[*nb * t_dim1 + 1], &c__1); i__2 = i__ - 1; q__1.r = -1.f, q__1.i = 0.f; caxpy_(&i__2, &q__1, &t[*nb * t_dim1 + 1], &c__1, &a[*k + 1 + i__ * a_dim1], &c__1); i__2 = *k + i__ - 1 + (i__ - 1) * a_dim1; a[i__2].r = ei.r, a[i__2].i = ei.i; } /* Generate the elementary reflector H(i) to annihilate */ /* A(k+i+1:n,i) */ i__2 = *k + i__ + i__ * a_dim1; ei.r = a[i__2].r, ei.i = a[i__2].i; i__2 = *n - *k - i__ + 1; /* Computing MIN */ i__3 = *k + i__ + 1; clarfg_(&i__2, &ei, &a[f2cmin(i__3,*n) + i__ * a_dim1], &c__1, &tau[i__]) ; i__2 = *k + i__ + i__ * a_dim1; a[i__2].r = 1.f, a[i__2].i = 0.f; /* Compute Y(1:n,i) */ i__2 = *n - *k - i__ + 1; cgemv_("No transpose", n, &i__2, &c_b2, &a[(i__ + 1) * a_dim1 + 1], lda, &a[*k + i__ + i__ * a_dim1], &c__1, &c_b1, &y[i__ * y_dim1 + 1], &c__1); i__2 = *n - *k - i__ + 1; i__3 = i__ - 1; cgemv_("Conjugate transpose", &i__2, &i__3, &c_b2, &a[*k + i__ + a_dim1], lda, &a[*k + i__ + i__ * a_dim1], &c__1, &c_b1, &t[ i__ * t_dim1 + 1], &c__1); i__2 = i__ - 1; q__1.r = -1.f, q__1.i = 0.f; cgemv_("No transpose", n, &i__2, &q__1, &y[y_offset], ldy, &t[i__ * t_dim1 + 1], &c__1, &c_b2, &y[i__ * y_dim1 + 1], &c__1); cscal_(n, &tau[i__], &y[i__ * y_dim1 + 1], &c__1); /* Compute T(1:i,i) */ i__2 = i__ - 1; i__3 = i__; q__1.r = -tau[i__3].r, q__1.i = -tau[i__3].i; cscal_(&i__2, &q__1, &t[i__ * t_dim1 + 1], &c__1); i__2 = i__ - 1; ctrmv_("Upper", "No transpose", "Non-unit", &i__2, &t[t_offset], ldt, &t[i__ * t_dim1 + 1], &c__1) ; i__2 = i__ + i__ * t_dim1; i__3 = i__; t[i__2].r = tau[i__3].r, t[i__2].i = tau[i__3].i; /* L10: */ } i__1 = *k + *nb + *nb * a_dim1; a[i__1].r = ei.r, a[i__1].i = ei.i; return 0; /* End of CLAHRD */ } /* clahrd_ */
the_stack_data/1143298.c
#include <stdio.h> #include <signal.h> #ifndef SIGIOT #ifdef SIGABRT #define SIGIOT SIGABRT #endif #endif #include <stdlib.h> extern void f_exit (void); void sig_die (register char *s, int kill) { /* print error message, then clear buffers */ fprintf (stderr, "%s\n", s); if (kill) { fflush (stderr); f_exit (); fflush (stderr); /* now get a core */ #ifdef SIGIOT signal (SIGIOT, SIG_DFL); #endif abort (); } else { #ifdef NO_ONEXIT f_exit (); #endif exit (1); } }
the_stack_data/43888993.c
#include <stdarg.h> struct tiny { short c; short d; }; f (int n, ...) { struct tiny x; int i; va_list ap; va_start (ap,n); for (i = 0; i < n; i++) { x = va_arg (ap,struct tiny); if (x.c != i + 10) abort(); if (x.d != i + 20) abort(); } { long x = va_arg (ap, long); if (x != 123) abort(); } va_end (ap); } main () { struct tiny x[3]; x[0].c = 10; x[1].c = 11; x[2].c = 12; x[0].d = 20; x[1].d = 21; x[2].d = 22; f (3, x[0], x[1], x[2], (long) 123); exit(0); }
the_stack_data/473798.c
#include <stdio.h> #include <stdlib.h> /*sb = se */ int main() { int i=0,k1=0,k2=42,k3=0; k1++; sb: k2++; k3++; return i; }
the_stack_data/294628.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #define SIZE 150 typedef struct Nodo { char letra; //caracter asignado al nodo, puede ser NULL int peso; //peso del nodo, no puede ser cero struct Nodo *sig; //Puntero para el siguiente en la lista que se crea cuando se cargan los datos struct Nodo *padre; //Puntero para el padre en el arbol struct Nodo *izq; //Hijo Izquierdo struct Nodo *der; //Hijo derecho } Nodo; typedef struct TablaHuf { char letra; char codigo[30]; struct TablaHuf * sig; } Tabla; typedef Tabla * TablaPtr; typedef Nodo * NodoPtr; /*Funcion que llena una Lista en orden decreciente con los nodos cargados mediante el archivo abecedario.txt*/ void leerArchivo(NodoPtr * Lista, FILE *archivo) { NodoPtr nuevoNodo, actNodo, antNodo; char aux; int peso; fscanf(archivo, "%c %d\n", &aux, &peso); while (!feof(archivo)) {//mientras el archivo no termine actNodo = *Lista; antNodo = NULL; nuevoNodo = (NodoPtr) malloc(sizeof (Nodo)); nuevoNodo->peso = peso; nuevoNodo->letra = aux; if (nuevoNodo != NULL) { nuevoNodo->der = nuevoNodo->izq = nuevoNodo->sig = nuevoNodo->padre = NULL; //inicializo izq y der en NULL //fscanf(archivo, "%c %d", &nuevoNodo->letra, &nuevoNodo->peso); //cargo los datos de la primer linea en el nodo if (nuevoNodo->peso == 0) { free(nuevoNodo); continue; } while (actNodo != NULL && nuevoNodo->peso > actNodo->peso) { antNodo = actNodo; /*walk to...*/ actNodo = actNodo->sig; /*...next node*/ } if (antNodo == NULL) { nuevoNodo->sig = *Lista; *Lista = nuevoNodo; } else { antNodo->sig = nuevoNodo; nuevoNodo->sig = actNodo; } } else { printf("No hay mas memoria disponible, archivo demasiado grande"); break; } fscanf(archivo, "%c %d\n", &aux, &peso); } } /*Si bien la Lista se carga ordenada, esta funcion evita que tome de manera desordenda los nodos menores en caso de que los nuevoNodo sean mayores*/ NodoPtr menorPeso(NodoPtr Lista) {//recorrer toda la Lista en busca de un nodo menor NodoPtr aux; NodoPtr actNodo, antNodo; actNodo = Lista; antNodo = NULL; aux = actNodo; if (actNodo == NULL) return NULL; while (actNodo != NULL) { if (aux->peso >= actNodo->peso) { aux = actNodo; } antNodo = actNodo; actNodo = actNodo->sig; } return aux; } NodoPtr crearArbol(NodoPtr Lista) { NodoPtr menorNodoA, menorNodoB, nuevoNodo, actNodo, antNodo, cursorLista; //int i = 1; cursorLista = Lista; if (!Lista) return NULL; else { while (menorNodoB != NULL && cursorLista != NULL) { menorNodoA = menorPeso(cursorLista); cursorLista = cursorLista->sig; menorNodoB = menorPeso(cursorLista); if (menorNodoB != NULL) { cursorLista = cursorLista->sig; nuevoNodo = (NodoPtr) malloc(sizeof (Nodo)); //Creo al nuevo padre... //printf("%d\n",i); //i++; if (nuevoNodo != NULL) { nuevoNodo->peso = menorNodoA->peso + menorNodoB->peso; //Le doy al padre la suma del peso de los hijos nuevoNodo->letra = '\0'; //Le asigno el caracter nulo al padre... nuevoNodo->izq = menorNodoA; /* asigno el hijo menor al padre*/ menorNodoA->padre = nuevoNodo; /*asigno el padre al hijo menor*/ nuevoNodo->der = menorNodoB; /*asigno el hijo mayor al padre*/ menorNodoB->padre = nuevoNodo; /*asigno el padre al hijo mayor*/ if (cursorLista != NULL) { actNodo = cursorLista; antNodo = NULL; while (actNodo != NULL && nuevoNodo->peso >= actNodo->peso) { antNodo = actNodo; actNodo = actNodo->sig; } if (antNodo == NULL) { nuevoNodo->sig = cursorLista; cursorLista = nuevoNodo; } else { antNodo->sig = nuevoNodo; nuevoNodo->sig = actNodo; } } } else { printf("Memoria insuficiente para crear los nodos...\n"); return NULL; } } } } return nuevoNodo; } void imprimirLista(NodoPtr top) { if (top == NULL) { //printf("No hay nodos cargados!!!\n"); return; } else { printf("(%c,%d) -> ", top->letra, top->peso); imprimirLista(top->sig); return; } } char * invertirCadena(char * ARRAY) { int i; int j = strlen(ARRAY) - 1; char aux; for (i = 0; i < (strlen(ARRAY) / 2); i++) { aux = ARRAY[i]; ARRAY[i] = ARRAY[j]; ARRAY[j] = aux; j--; } return ARRAY; } void imprimirHuffman(NodoPtr Lista, TablaPtr * Clave) { NodoPtr nodoAct = Lista; NodoPtr nodoAnt = NULL; NodoPtr nodoPadre = Lista->padre; NodoPtr nodoHijo = Lista; char ARRAY [30] = {"\0"}; char RESET [30] = {"\0"}; printf("Letra\tCodigo\n"); while (nodoAct != NULL) { if (nodoAct->letra != '\0') { TablaPtr Nuevo = (TablaPtr) malloc(sizeof (Tabla)); if (!Nuevo) { printf("Insuficiente memoria, no pudo ser guardado el codigo\n"); } Nuevo->letra = nodoAct->letra; if (Nuevo->letra == '#') Nuevo->letra = ' '; printf("%c\t", nodoAct->letra); while (nodoPadre != NULL) { if (nodoPadre->izq == nodoHijo) { strcat(ARRAY, "0"); } else if (nodoPadre->der == nodoHijo) { strcat(ARRAY, "1"); } nodoHijo = nodoPadre; nodoPadre = nodoPadre->padre; } puts(invertirCadena(ARRAY)); strcpy(Nuevo->codigo, ARRAY); strcpy(ARRAY, RESET); TablaPtr tablaAct = (*Clave); TablaPtr tablaAnt = NULL; while (tablaAct != NULL) { tablaAnt = tablaAct; tablaAct = tablaAct->sig; } if (tablaAnt == NULL) { (* Clave) = Nuevo; Nuevo->sig = tablaAct; } else { tablaAnt->sig = Nuevo; Nuevo->sig = tablaAct; } } nodoAnt = nodoAct; nodoAct = nodoAct->sig; if (nodoAct != NULL) { nodoPadre = nodoAct->padre; nodoHijo = nodoAct; } } } void codificarHuffman(char * ORIGINAL, char * DESTINO, TablaPtr Codigo) { int tamOriginal = strlen(ORIGINAL); int i; for (i = 0; i < tamOriginal - 1; i++) { TablaPtr act = Codigo; TablaPtr ant = NULL; while (act != NULL && act->letra != ORIGINAL[i]) { ant = act; act = act->sig; } if (act == NULL) { printf("ERROR FATAL! el simbolo buscado no existe en los registros\n"); return; } strcat(DESTINO, act->codigo); } printf("CODIFICACION TERMINADA!\n"); return; } void decodificarHuffman(char * MENSAJE, NodoPtr cab) { int tamMsj = strlen(MENSAJE); int i, j; NodoPtr aux = cab; for (i = 0; i <= tamMsj; i++) { if (aux->letra != '\0') { if (aux->letra == '#') printf(" "); else printf("%c", aux->letra); aux = cab; } if (MENSAJE[i] == '0') aux = aux->izq; else aux = aux->der; } printf("\nDECODIFICACION TERMINADA!\n"); } /* * */ int main(int argc, char** argv) { FILE *abcPtr; //puntero file para el comienzo del archivo NodoPtr Lista = NULL; NodoPtr arbol = NULL; TablaPtr ClaveHuf = NULL; int tamOri, tamCod; char TEXTO [SIZE] = {'\0'}; char CODIFICADO [SIZE * 8] = {'\0'}; printf("Bienvenido a Codigo Huffman\n"); abcPtr = fopen("abecedariocompleto.txt", "r"); if (abcPtr == NULL) printf("No hay archivo de abecedario"); else { leerArchivo(&Lista, abcPtr); imprimirLista(Lista); printf("\n"); arbol = crearArbol(Lista); /*Esta funcion rompe la lista hay que reveer esoooo!!!!*/ imprimirHuffman(Lista, &ClaveHuf); printf("Codificacion creada correctamente.\n"); printf("Ingrese texto a codificar:\n"); fgets(TEXTO, 104, stdin); tamOri = strlen(TEXTO)*8; printf("El tamaño del texto en bits es: %d\n\n", tamOri); codificarHuffman(TEXTO, CODIFICADO, ClaveHuf); puts(CODIFICADO); tamCod = strlen(CODIFICADO); printf("\n\nEl nuevo tamaño en bits es de: %d y se comprimio un %.2f%%", tamCod, 100.0 - (tamCod * 100.0) / tamOri); printf("\nDecodificando...\n"); decodificarHuffman(CODIFICADO, arbol); printf("\nPrograma finalizado! (0 para terminar)\n"); int opc = 1; scanf("%d", &opc); while (opc != 0) { printf("\nPrograma finalizado! (0 para terminar)\n"); scanf("%d", &opc); } } return (EXIT_SUCCESS); }
the_stack_data/154883.c
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by The HDF Group. * * Copyright by the Board of Trustees of the University of Illinois. * * All rights reserved. * * * * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the files COPYING and Copyright.html. COPYING can be found at the root * * of the source code distribution tree; Copyright.html can be found at the * * root level of an installed copy of the electronic HDF5 document set and * * is linked from the top-level documents page. It can also be found at * * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * * access to either file, you may request a copy from [email protected]. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include <stdio.h> #include <stdlib.h> #include <string.h> /* This program reads binary output from h5dump (-b option). To use change the following 3 symbols accordingly. For example, to read 2 elements of a float type , define #define NELMTS 2 #define TYPE float #define FORMAT "%f " */ #define NELMTS 6 #define TYPE int #define FORMAT "%d " /*------------------------------------------------------------------------- * Function: usage * * Purpose: Prints a usage message on stderr and then returns. * * Return: void * * Programmer: Pedro Vicente Nunes * * Modifications: * *------------------------------------------------------------------------- */ static void usage (void) { fprintf(stderr, "\ usage: binread FILE_NAME\n"); } /*------------------------------------------------------------------------- * Function: main * * Purpose: main program. * *------------------------------------------------------------------------- */ int main (int argc, const char *argv[]) { FILE *stream; int numread; TYPE buf[NELMTS]; size_t i, nelmts = NELMTS; char *fname=NULL; if (argc != 2) { usage(); exit(1); } fname = strdup(argv[1]); if( (stream = fopen(fname, "rb" )) != NULL ) { numread = fread( buf, sizeof( TYPE ), nelmts, stream ); printf( "Number of items read = %d\n", numread ); for (i = 0; i < nelmts; i++) { printf(FORMAT,buf[i]); } printf("\n"); fclose( stream ); } else printf( "File %s could not be opened\n",fname ); free(fname); return 0; }
the_stack_data/34514083.c
/* --------------------------------------------------------------------- EXERCISE 3.33 ------------------------------------------------------------------------ Develop a version of Program 3.9 that uses an array of indices to implement the linked list (see Figure 3.6). --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- Notes: - I created a little auxiliary function to print the arrays. Running the program with parameters 9 5 allows us to verify that the next array is in sync with the one shown in figure 3.6. - Also, initializing item and next like: for (i = 0; i < N; i++) item[i] = N-i; for (i = 1; i < N; i++) next[i] = i-1; next[0] = N-1; and starting with int x = 0 allows us to verify the result of Exercise 3.32. We can quickly check it by uncommenting the line: // #define E03_32 and recompiling. --------------------------------------------------------------------- */ #include <stdio.h> #include <stdlib.h> // #define E03_32 void print_array(int *arr, int N) { for (int i = 0; i < N; i++) printf(" %d", arr[i]); printf("\n"); } int main(int argc, char *argv[]) { if (argc < 3) return EXIT_FAILURE; int i; int N = atoi(argv[1]); int M = atoi(argv[2]); int *item = malloc(N*sizeof(*item)); int *next = malloc(N*sizeof(*next)); #ifndef E03_32 for (i = 0; i < N; i++) item[i] = i+1; for (i = 0; i < N; i++) next[i] = i+1; next[N-1] = 0; int x = N-1; #else for (i = 0; i < N; i++) item[i] = N-i; for (i = 1; i < N; i++) next[i] = i-1; next[0] = N-1; int x = 0; #endif printf("item[] = "); print_array(item, N); printf("next[] = "); print_array(next, N); while (x != next[x]) { for (i = 1; i < M; i++) x = next[x]; printf("deleted item: %d ->", item[next[x]]); next[x] = next[next[x]]; print_array(next, N); } printf("The leader is: %d\n", item[x]); free(item); free(next); } /* --------------------------------------------------------------------- OUTPUT ------------------------------------------------------------------------ // #define E03_32 E03.33.exe 9 5 item[] = 1 2 3 4 5 6 7 8 9 next[] = 1 2 3 4 5 6 7 8 0 deleted item: 5 -> 1 2 3 5 5 6 7 8 0 deleted item: 1 -> 1 2 3 5 5 6 7 8 1 deleted item: 7 -> 1 2 3 5 5 7 7 8 1 deleted item: 4 -> 1 2 5 5 5 7 7 8 1 deleted item: 3 -> 1 5 5 5 5 7 7 8 1 deleted item: 6 -> 1 7 5 5 5 7 7 8 1 deleted item: 9 -> 1 7 5 5 5 7 7 1 1 deleted item: 2 -> 1 7 5 5 5 7 7 7 1 The leader is: 8 ------------------------------------------------------------------------ #define E03_32 E03.33.exe 9 5 item[] = 9 8 7 6 5 4 3 2 1 next[] = 8 0 1 2 3 4 5 6 7 deleted item: 5 -> 8 0 1 2 3 3 5 6 7 deleted item: 1 -> 7 0 1 2 3 3 5 6 7 deleted item: 7 -> 7 0 1 1 3 3 5 6 7 deleted item: 4 -> 7 0 1 1 3 3 3 6 7 deleted item: 3 -> 7 0 1 1 3 3 3 3 7 deleted item: 6 -> 7 0 1 1 3 3 3 1 7 deleted item: 9 -> 7 7 1 1 3 3 3 1 7 deleted item: 2 -> 7 1 1 1 3 3 3 1 7 The leader is: 8 --------------------------------------------------------------------- */
the_stack_data/1184098.c
/* 8. Faça um procedimento que recebe a idade de um nadador por parâmetro e retorna, também por parâmetro, a categoria desse nadador de acordo com a tabela abaixo: 5 a 7 > Infantil A 8 a 10 > Infantil B 11 a 13 > Juvenil A 14 a 17 > Juvenil B maior 18 > Adulto */ #include <stdio.h> float calcIdade(float idade){ if (idade >= 5 && idade <= 7){ printf("Sua idade é %.0f e você faz parte do Infantil A\n", idade); } else if (idade >= 8 && idade <= 10){ printf("Sua idade é %.0f e você faz parte do Infantil B\n", idade); } else if (idade >= 11 && idade <= 13){ printf("Sua idade é %.0f e você faz parte do Juvenil A\n", idade); } else if (idade >= 14 && idade <= 17){ printf("Sua idade é %.0f e você faz parte do Juvenil B\n", idade); } else if (idade >= 18){ printf("Sua idade é %.0f e você faz parte do Adulto\n", idade); } else{ printf("Sua idade é %.0f e não faz parte de nenhuma categoria\n", idade); } } int main(){ float I=0; printf("Digite sua idade: "); scanf("%f",&I); return calcIdade(I); }
the_stack_data/159514453.c
/* * RamThrash * * Author: Richard Lancaster * Email: [email protected] */ #include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <time.h> #include <unistd.h> /* ---- GLOBAL STATE DATA --------------------------------------------------- */ /* User configurable parameters */ size_t ramThrash_testSize_GiB; int ramThrash_injectErrorsFlag; /* ---- FUNCTIONS ----------------------------------------------------------- */ int main(int argc, char **argv) { /* Private state variables */ int printUsageAndExitFlag; int optionChar; int optionIntValue; size_t testSize_MiB; size_t testSize_KiB; size_t testSize_bytes; size_t testSize_64bitWords; uint64_t *p_testArray; uint64_t cyclesCompleted; uint64_t errorsEncountered; double writeSpeed_GiBs; double readSpeed_GiBs; uint64_t randNumber_16bit; uint64_t randNumber_64bit; uint64_t *p_word; size_t wordIndex; uint64_t sequenceWordValue; struct timespec startTime; struct timespec endTime; double duration_s; /* ---- INITIALISATION ---- */ /* Output top level banner */ printf("\n"); printf("[RamThrash]\n"); printf("\n"); /* Set user configurable parameters to defaults */ ramThrash_testSize_GiB = 1l; ramThrash_injectErrorsFlag = 0; /* Read command line options, modifying user configrable parameters */ printUsageAndExitFlag = 0; while( optionChar = getopt(argc, argv, "is:"), ((optionChar >= 0) && (printUsageAndExitFlag == 0)) ) { switch(optionChar) { /* Process command line option: inject errors */ case ((int) 'i'): ramThrash_injectErrorsFlag = 1; break; /* Process command line option: test array size */ case ((int) 's'): sscanf(optarg, "%d", &optionIntValue); if(optionIntValue > 0) { ramThrash_testSize_GiB = (size_t) optionIntValue; } else { fprintf(stderr, "%s: Test size must be greater than zero\n", argv[0]); printUsageAndExitFlag = 1; } break; /* Process unknown command line option */ default: printUsageAndExitFlag = 1; } } if(printUsageAndExitFlag == 1) { fprintf(stderr, "%s: Usage: RamThrash [-s X] [-i]\n", argv[0]); exit(EXIT_FAILURE); } /* Allocate memory block for test array */ testSize_MiB = ramThrash_testSize_GiB * 1024l; testSize_KiB = testSize_MiB * 1024l; testSize_bytes = testSize_KiB * 1024l; testSize_64bitWords = testSize_bytes / 8; p_testArray = (uint64_t *) malloc(testSize_bytes); if(p_testArray == NULL) { fprintf(stderr, "%s: Failed to allocate test array\n", argv[0]); exit(EXIT_FAILURE); } printf("Test array allocated, size: %.1f GiB\n", (double) ramThrash_testSize_GiB); /* ---- TEST LOOP ---- */ /* Output banner message */ printf("Executing test...\n"); printf("\n"); /* Initialise loop state variables */ cyclesCompleted = 0u; errorsEncountered = 0u; writeSpeed_GiBs = 0.0; readSpeed_GiBs = 0.0; /* Perform test cycles until executable terminated */ while(1) { /* Output status message */ printf("\r"); printf("[ Cycles: %"PRIu64" Errors: %"PRIu64" ] ", cyclesCompleted, errorsEncountered); printf("[ W: %.2f GiB/s R: %.2f GiB/s ] ", writeSpeed_GiBs, readSpeed_GiBs); /* Flush stdout buffer to ensure status message is output to console now */ fflush(stdout); /* * Select random 16bit number and generate 64bit random number from it. * This process ensures that the random number has bits spread across the * 64bit range. */ randNumber_16bit = ((uint64_t) rand()) & 0xffffu; randNumber_64bit = (randNumber_16bit << 48); randNumber_64bit = randNumber_64bit | (randNumber_16bit << 32); randNumber_64bit = randNumber_64bit | (randNumber_16bit << 16); randNumber_64bit = randNumber_64bit | (randNumber_16bit << 0); randNumber_64bit = randNumber_64bit ^ (randNumber_16bit << 7); randNumber_64bit = randNumber_64bit ^ (randNumber_16bit << 18); randNumber_64bit = randNumber_64bit ^ (randNumber_16bit << 41); /* Fill test array with data, timing how long it takes */ p_word = p_testArray; sequenceWordValue = randNumber_64bit; clock_gettime(CLOCK_REALTIME, &startTime); for(wordIndex = 0; wordIndex < testSize_64bitWords; wordIndex++) { *p_word = sequenceWordValue; // printf("%016"PRIx64" %016"PRIx64"\n", // (uint64_t) p_word, // sequenceWordValue); sequenceWordValue = sequenceWordValue + randNumber_64bit; p_word++; } clock_gettime(CLOCK_REALTIME, &endTime); /* Calculate write speed */ duration_s = ( (double) (endTime.tv_sec - startTime.tv_sec) ) + ( ((double) endTime.tv_nsec ) / 1.0e9) - ( ((double) startTime.tv_nsec) / 1.0e9); writeSpeed_GiBs = ((double) ramThrash_testSize_GiB) / duration_s; /* If requested, inject errors to test if code is actually working */ if(ramThrash_injectErrorsFlag == 1) { wordIndex = 23; if( (wordIndex >=0) && (wordIndex < testSize_64bitWords) ) { p_testArray[wordIndex] = p_testArray[wordIndex] ^ (((uint64_t) 0x1u) << 41); } wordIndex = testSize_64bitWords - 20; if( (wordIndex >=0) && (wordIndex < testSize_64bitWords) ) { p_testArray[wordIndex] = p_testArray[wordIndex] ^ (((uint64_t) 0x1u) << 15); } } /* Check test array contains the correct data */ p_word = p_testArray; sequenceWordValue = randNumber_64bit; clock_gettime(CLOCK_REALTIME, &startTime); for(wordIndex = 0; wordIndex < testSize_64bitWords; wordIndex++) { if(*p_word != sequenceWordValue) { errorsEncountered++; } sequenceWordValue = sequenceWordValue + randNumber_64bit; p_word++; } clock_gettime(CLOCK_REALTIME, &endTime); /* Calculate read speed */ duration_s = ( (double) (endTime.tv_sec - startTime.tv_sec) ) + ( ((double) endTime.tv_nsec ) / 1.0e9) - ( ((double) startTime.tv_nsec) / 1.0e9); readSpeed_GiBs = ((double) ramThrash_testSize_GiB) / duration_s; /* Increment count of cycles completed */ cyclesCompleted++; } return(EXIT_SUCCESS); }
the_stack_data/29823960.c
/* matmult.c * Test program to do matrix multiplication on large arrays. * * Intended to stress virtual memory system. Should return 7220 if Dim==20 */ #include "syscall.h" #include "stdio.h" #define Dim 20 /* sum total of the arrays doesn't fit in * physical memory */ int A[Dim][Dim]; int B[Dim][Dim]; int C[Dim][Dim]; int main() { int i, j, k; for (i = 0; i < Dim; i++) /* first initialize the matrices */ for (j = 0; j < Dim; j++) { A[i][j] = i; B[i][j] = j; C[i][j] = 0; } for (i = 0; i < Dim; i++) /* then multiply them together */ for (j = 0; j < Dim; j++) for (k = 0; k < Dim; k++) C[i][j] += A[i][k] * B[k][j]; printf("C[%d][%d] = %d\n", Dim-1, Dim-1, C[Dim-1][Dim-1]); return (C[Dim-1][Dim-1]); /* and then we're done */ }
the_stack_data/9511942.c
#include <stdio.h> int main(void) { int i; int num; int arr[20] = {0}; int len = sizeof(arr) / sizeof(int); printf("20번째 숫자를 구하세요\n"); arr[0] = 1; arr[1] = 6; for(i = 0; i < 20; i++) { arr[i] = arr[i -1] + arr[i - 2]; } printf("20번째는 %d\n", arr[num-1]); return 0; }
the_stack_data/48574590.c
/* PR middle-end/48335 */ /* { dg-do compile } */ /* { dg-options "-O2 -fno-tree-sra" } */ typedef long long T __attribute__((may_alias)); struct S { _Complex float d __attribute__((aligned (8))); }; int f1 (struct S x) { struct S s = x; return *(T *) &s.d; } int f2 (struct S x) { struct S s = x; return *(char *) &s.d; } int f3 (struct S x) { struct S s = x; return ((char *) &s.d)[2]; } int f4 (struct S x, int y) { struct S s = x; return ((char *) &s.d)[y]; }
the_stack_data/90764693.c
#include "stdio.h" #include "stdlib.h" #include "math.h" #include "time.h" #define OK 1 #define ERROR 0 #define TRUE 1 #define FALSE 0 #define MAXEDGE 20 #define MAXVEX 20 #define INFINITY 65535 typedef int Status; /* Status是函数的类型,其值是函数结果状态代码,如OK等 */ typedef struct { int arc[MAXVEX][MAXVEX]; int numVertexes, numEdges; }MGraph; void CreateMGraph(MGraph *G)/* 构件图 */ { int i, j; /* printf("请输入边数和顶点数:"); */ G->numEdges=15; G->numVertexes=9; for (i = 0; i < G->numVertexes; i++)/* 初始化图 */ { for ( j = 0; j < G->numVertexes; j++) { if (i==j) G->arc[i][j]=0; else G->arc[i][j] = G->arc[j][i] = INFINITY; } } G->arc[0][1]=10; G->arc[0][5]=11; G->arc[1][2]=18; G->arc[1][8]=12; G->arc[1][6]=16; G->arc[2][8]=8; G->arc[2][3]=22; G->arc[3][8]=21; G->arc[3][6]=24; G->arc[3][7]=16; G->arc[3][4]=20; G->arc[4][7]=7; G->arc[4][5]=26; G->arc[5][6]=17; G->arc[6][7]=19; for(i = 0; i < G->numVertexes; i++) { for(j = i; j < G->numVertexes; j++) { G->arc[j][i] =G->arc[i][j]; } } } /* Prim算法生成最小生成树 */ void MiniSpanTree_Prim(MGraph G) { int min, i, j, k; int adjvex[MAXVEX]; /* 保存相关顶点下标 */ int lowcost[MAXVEX]; /* 保存相关顶点间边的权值 */ lowcost[0] = 0;/* 初始化第一个权值为0,即v0加入生成树 */ /* lowcost的值为0,在这里就是此下标的顶点已经加入生成树 */ adjvex[0] = 0; /* 初始化第一个顶点下标为0 */ for(i = 1; i < G.numVertexes; i++) /* 循环除下标为0外的全部顶点 */ { lowcost[i] = G.arc[0][i]; /* 将v0顶点与之有边的权值存入数组 */ adjvex[i] = 0; /* 初始化都为v0的下标 */ } for(i = 1; i < G.numVertexes; i++) { min = INFINITY; /* 初始化最小权值为∞, */ /* 通常设置为不可能的大数字如32767、65535等 */ j = 1;k = 0; while(j < G.numVertexes) /* 循环全部顶点 */ { if(lowcost[j]!=0 && lowcost[j] < min)/* 如果权值不为0且权值小于min */ { min = lowcost[j]; /* 则让当前权值成为最小值 */ k = j; /* 将当前最小值的下标存入k */ } j++; } printf("(%d, %d)\n", adjvex[k], k);/* 打印当前顶点边中权值最小的边 */ lowcost[k] = 0;/* 将当前顶点的权值设置为0,表示此顶点已经完成任务 */ for(j = 1; j < G.numVertexes; j++) /* 循环所有顶点 */ { if(lowcost[j]!=0 && G.arc[k][j] < lowcost[j]) {/* 如果下标为k顶点各边权值小于此前这些顶点未被加入生成树权值 */ lowcost[j] = G.arc[k][j];/* 将较小的权值存入lowcost相应位置 */ adjvex[j] = k; /* 将下标为k的顶点存入adjvex */ } } } } int main(void) { MGraph G; CreateMGraph(&G); MiniSpanTree_Prim(G); return 0; }
the_stack_data/70449951.c
/* PR c/51339 */ /* { dg-do compile } */ /* { dg-options "-fopenmp" } */ char g[] = "g"; void foo (void) { #pragma omp parallel sections firstprivate (g) lastprivate (g) { #pragma omp section g[0] = 'h'; } }
the_stack_data/105743.c
/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *columnSizes array. * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free(). */ int top; int count; int alloc_size; int *data; int **ret; int *col; int *get_array(int *src, int len) { int *dst = (int *)malloc(sizeof(int) * len); memcpy(dst,src,sizeof(int) * len); return dst; } void helper(int index, int k, int diff) { if(top == k && diff == 0){ col[count] = top; ret[count++] = get_array(data,top); if(count == alloc_size){ alloc_size <<= 1; col = realloc(col,sizeof(int) * alloc_size); ret = realloc(ret,sizeof(int *) * alloc_size); } return ; } if(top == k || diff == 0) return ; int i; for(i = index; i <= 9; ++i){ if(i > diff) break; data[top++] = i; helper(i+1,k,diff - i); top--; } } int** combinationSum3(int k, int n, int** columnSizes, int* returnSize) { top = 0; count= 0; alloc_size = 500; ret = (int **)malloc(sizeof(int *) * alloc_size); col = (int *)malloc(sizeof(int *) * alloc_size); data = (int *)malloc(sizeof(int *) * 9); helper(1,k,n); *columnSizes = col; *returnSize = count; return ret; }
the_stack_data/162644005.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_recursive_factorial.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: aborboll <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/09/17 18:52:27 by aborboll #+# #+# */ /* Updated: 2019/09/18 11:31:58 by aborboll ### ########.fr */ /* */ /* ************************************************************************** */ int ft_recursive_factorial(int nb) { if ((nb < 0) || (nb > 12)) return (0); if (nb == 1) return (1); return (nb * ft_recursive_factorial(nb - 1)); }
the_stack_data/122005.c
/* { dg-do run } */ /* { dg-options "-O2" } */ /* { dg-require-effective-target alloca } */ typedef __SIZE_TYPE__ size_t; extern void abort (void); extern void exit (int); extern void *malloc (size_t); extern void *calloc (size_t, size_t); extern void *alloca (size_t); extern void *memcpy (void *, const void *, size_t); extern void *memset (void *, int, size_t); extern char *strcpy (char *, const char *); struct A { char a[10]; int b; char c[10]; } y, w[4]; extern char exta[]; extern char extb[30]; extern struct A zerol[0]; void __attribute__ ((noinline)) test1 (void *q, int x) { struct A a; void *p = &a.a[3], *r; char var[x + 10]; if (x < 0) r = &a.a[9]; else r = &a.c[1]; if (__builtin_object_size (p, 0) != sizeof (a) - __builtin_offsetof (struct A, a) - 3) abort (); if (__builtin_object_size (&a.c[9], 0) != sizeof (a) - __builtin_offsetof (struct A, c) - 9) abort (); if (__builtin_object_size (q, 0) != (size_t) -1) abort (); if (__builtin_object_size (r, 0) != sizeof (a) - __builtin_offsetof (struct A, a) - 9) abort (); if (x < 6) r = &w[2].a[1]; else r = &a.a[6]; if (__builtin_object_size (&y, 0) != sizeof (y)) abort (); if (__builtin_object_size (w, 0) != sizeof (w)) abort (); if (__builtin_object_size (&y.b, 0) != sizeof (a) - __builtin_offsetof (struct A, b)) abort (); if (__builtin_object_size (r, 0) != 2 * sizeof (w[0]) - __builtin_offsetof (struct A, a) - 1) abort (); if (x < 20) r = malloc (30); else r = calloc (2, 16); /* We may duplicate this test onto the two exit paths. On one path the size will be 32, the other it will be 30. If we don't duplicate this test, then the size will be 32. */ if (__builtin_object_size (r, 0) != 2 * 16 && __builtin_object_size (r, 0) != 30) abort (); if (x < 20) r = malloc (30); else r = calloc (2, 14); if (__builtin_object_size (r, 0) != 30) abort (); if (x < 30) r = malloc (sizeof (a)); else r = &a.a[3]; if (__builtin_object_size (r, 0) != sizeof (a)) abort (); r = memcpy (r, "a", 2); if (__builtin_object_size (r, 0) != sizeof (a)) abort (); r = memcpy (r + 2, "b", 2) + 2; if (__builtin_object_size (r, 0) != sizeof (a) - 4) abort (); r = &a.a[4]; r = memset (r, 'a', 2); if (__builtin_object_size (r, 0) != sizeof (a) - __builtin_offsetof (struct A, a) - 4) abort (); r = memset (r + 2, 'b', 2) + 2; if (__builtin_object_size (r, 0) != sizeof (a) - __builtin_offsetof (struct A, a) - 8) abort (); r = &a.a[1]; r = strcpy (r, "ab"); if (__builtin_object_size (r, 0) != sizeof (a) - __builtin_offsetof (struct A, a) - 1) abort (); r = strcpy (r + 2, "cd") + 2; if (__builtin_object_size (r, 0) != sizeof (a) - __builtin_offsetof (struct A, a) - 5) abort (); if (__builtin_object_size (exta, 0) != (size_t) -1) abort (); if (__builtin_object_size (exta + 10, 0) != (size_t) -1) abort (); if (__builtin_object_size (&exta[5], 0) != (size_t) -1) abort (); if (__builtin_object_size (extb, 0) != sizeof (extb)) abort (); if (__builtin_object_size (extb + 10, 0) != sizeof (extb) - 10) abort (); if (__builtin_object_size (&extb[5], 0) != sizeof (extb) - 5) abort (); if (__builtin_object_size (var, 0) != (size_t) -1) abort (); if (__builtin_object_size (var + 10, 0) != (size_t) -1) abort (); if (__builtin_object_size (&var[5], 0) != (size_t) -1) abort (); if (__builtin_object_size (zerol, 0) != 0) abort (); if (__builtin_object_size (&zerol, 0) != 0) abort (); if (__builtin_object_size (&zerol[0], 0) != 0) abort (); if (__builtin_object_size (zerol[0].a, 0) != 0) abort (); if (__builtin_object_size (&zerol[0].a[0], 0) != 0) abort (); if (__builtin_object_size (&zerol[0].b, 0) != 0) abort (); if (__builtin_object_size ("abcdefg", 0) != sizeof ("abcdefg")) abort (); if (__builtin_object_size ("abcd\0efg", 0) != sizeof ("abcd\0efg")) abort (); if (__builtin_object_size (&"abcd\0efg", 0) != sizeof ("abcd\0efg")) abort (); if (__builtin_object_size (&"abcd\0efg"[0], 0) != sizeof ("abcd\0efg")) abort (); if (__builtin_object_size (&"abcd\0efg"[4], 0) != sizeof ("abcd\0efg") - 4) abort (); if (__builtin_object_size ("abcd\0efg" + 5, 0) != sizeof ("abcd\0efg") - 5) abort (); if (__builtin_object_size (L"abcdefg", 0) != sizeof (L"abcdefg")) abort (); r = (char *) L"abcd\0efg"; if (__builtin_object_size (r + 2, 0) != sizeof (L"abcd\0efg") - 2) abort (); } size_t l1 = 1; void __attribute__ ((noinline)) test2 (void) { struct B { char buf1[10]; char buf2[10]; } a; char *r, buf3[20]; int i; if (sizeof (a) != 20) return; r = buf3; for (i = 0; i < 4; ++i) { if (i == l1 - 1) r = &a.buf1[1]; else if (i == l1) r = &a.buf2[7]; else if (i == l1 + 1) r = &buf3[5]; else if (i == l1 + 2) r = &a.buf1[9]; } if (__builtin_object_size (r, 0) != 20) abort (); r = &buf3[20]; for (i = 0; i < 4; ++i) { if (i == l1 - 1) r = &a.buf1[7]; else if (i == l1) r = &a.buf2[7]; else if (i == l1 + 1) r = &buf3[5]; else if (i == l1 + 2) r = &a.buf1[9]; } if (__builtin_object_size (r, 0) != 15) abort (); r += 8; if (__builtin_object_size (r, 0) != 7) abort (); if (__builtin_object_size (r + 6, 0) != 1) abort (); r = &buf3[18]; for (i = 0; i < 4; ++i) { if (i == l1 - 1) r = &a.buf1[9]; else if (i == l1) r = &a.buf2[9]; else if (i == l1 + 1) r = &buf3[5]; else if (i == l1 + 2) r = &a.buf1[4]; } if (__builtin_object_size (r + 12, 0) != 4) abort (); } void __attribute__ ((noinline)) test3 (void) { char buf4[10]; struct B { struct A a[2]; struct A b; char c[4]; char d; double e; _Complex double f; } x; double y; _Complex double z; double *dp; if (__builtin_object_size (buf4, 0) != sizeof (buf4)) abort (); if (__builtin_object_size (&buf4, 0) != sizeof (buf4)) abort (); if (__builtin_object_size (&buf4[0], 0) != sizeof (buf4)) abort (); if (__builtin_object_size (&buf4[1], 0) != sizeof (buf4) - 1) abort (); if (__builtin_object_size (&x, 0) != sizeof (x)) abort (); if (__builtin_object_size (&x.a, 0) != sizeof (x)) abort (); if (__builtin_object_size (&x.a[0], 0) != sizeof (x)) abort (); if (__builtin_object_size (&x.a[0].a, 0) != sizeof (x)) abort (); if (__builtin_object_size (&x.a[0].a[0], 0) != sizeof (x)) abort (); if (__builtin_object_size (&x.a[0].a[3], 0) != sizeof (x) - 3) abort (); if (__builtin_object_size (&x.a[0].b, 0) != sizeof (x) - __builtin_offsetof (struct A, b)) abort (); if (__builtin_object_size (&x.a[1].c, 0) != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c)) abort (); if (__builtin_object_size (&x.a[1].c[0], 0) != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c)) abort (); if (__builtin_object_size (&x.a[1].c[3], 0) != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c) - 3) abort (); if (__builtin_object_size (&x.b, 0) != sizeof (x) - __builtin_offsetof (struct B, b)) abort (); if (__builtin_object_size (&x.b.a, 0) != sizeof (x) - __builtin_offsetof (struct B, b)) abort (); if (__builtin_object_size (&x.b.a[0], 0) != sizeof (x) - __builtin_offsetof (struct B, b)) abort (); if (__builtin_object_size (&x.b.a[3], 0) != sizeof (x) - __builtin_offsetof (struct B, b) - 3) abort (); if (__builtin_object_size (&x.b.b, 0) != sizeof (x) - __builtin_offsetof (struct B, b) - __builtin_offsetof (struct A, b)) abort (); if (__builtin_object_size (&x.b.c, 0) != sizeof (x) - __builtin_offsetof (struct B, b) - __builtin_offsetof (struct A, c)) abort (); if (__builtin_object_size (&x.b.c[0], 0) != sizeof (x) - __builtin_offsetof (struct B, b) - __builtin_offsetof (struct A, c)) abort (); if (__builtin_object_size (&x.b.c[3], 0) != sizeof (x) - __builtin_offsetof (struct B, b) - __builtin_offsetof (struct A, c) - 3) abort (); if (__builtin_object_size (&x.c, 0) != sizeof (x) - __builtin_offsetof (struct B, c)) abort (); if (__builtin_object_size (&x.c[0], 0) != sizeof (x) - __builtin_offsetof (struct B, c)) abort (); if (__builtin_object_size (&x.c[1], 0) != sizeof (x) - __builtin_offsetof (struct B, c) - 1) abort (); if (__builtin_object_size (&x.d, 0) != sizeof (x) - __builtin_offsetof (struct B, d)) abort (); if (__builtin_object_size (&x.e, 0) != sizeof (x) - __builtin_offsetof (struct B, e)) abort (); if (__builtin_object_size (&x.f, 0) != sizeof (x) - __builtin_offsetof (struct B, f)) abort (); dp = &__real__ x.f; if (__builtin_object_size (dp, 0) != sizeof (x) - __builtin_offsetof (struct B, f)) abort (); dp = &__imag__ x.f; if (__builtin_object_size (dp, 0) != sizeof (x) - __builtin_offsetof (struct B, f) - sizeof (x.f) / 2) abort (); dp = &y; if (__builtin_object_size (dp, 0) != sizeof (y)) abort (); if (__builtin_object_size (&z, 0) != sizeof (z)) abort (); dp = &__real__ z; if (__builtin_object_size (dp, 0) != sizeof (z)) abort (); dp = &__imag__ z; if (__builtin_object_size (dp, 0) != sizeof (z) / 2) abort (); } struct S { unsigned int a; }; char * __attribute__ ((noinline)) test4 (char *x, int y) { register int i; struct A *p; for (i = 0; i < y; i++) { p = (struct A *) x; x = (char *) &p[1]; if (__builtin_object_size (p, 0) != (size_t) -1) abort (); } return x; } void __attribute__ ((noinline)) test5 (size_t x) { char buf[64]; char *p = &buf[8]; size_t i; for (i = 0; i < x; ++i) p = p + 4; /* My understanding of ISO C99 6.5.6 is that a conforming program will not end up with p equal to &buf[0] through &buf[7], i.e. calling this function with say UINTPTR_MAX / 4 results in undefined behavior. If that's true, then the maximum number of remaining bytes from p until end of the object is 56, otherwise it would be 64 (or conservative (size_t) -1 == unknown). */ if (__builtin_object_size (p, 0) != sizeof (buf) - 8) abort (); memset (p, ' ', sizeof (buf) - 8 - 4 * 4); } void __attribute__ ((noinline)) test6 (size_t x) { struct T { char buf[64]; char buf2[64]; } t; char *p = &t.buf[8]; size_t i; for (i = 0; i < x; ++i) p = p + 4; if (__builtin_object_size (p, 0) != sizeof (t) - 8) abort (); memset (p, ' ', sizeof (t) - 8 - 4 * 4); } void __attribute__ ((noinline)) test7 (void) { char buf[64]; struct T { char buf[64]; char buf2[64]; } t; char *p = &buf[64], *q = &t.buf[64]; if (__builtin_object_size (p + 64, 0) != 0) abort (); if (__builtin_object_size (q + 63, 0) != sizeof (t) - 64 - 63) abort (); if (__builtin_object_size (q + 64, 0) != sizeof (t) - 64 - 64) abort (); if (__builtin_object_size (q + 256, 0) != 0) abort (); } void __attribute__ ((noinline)) test8 (void) { struct T { char buf[10]; char buf2[10]; } t; char *p = &t.buf2[-4]; char *q = &t.buf2[0]; if (__builtin_object_size (p, 0) != sizeof (t) - 10 + 4) abort (); if (__builtin_object_size (q, 0) != sizeof (t) - 10) abort (); /* GCC only handles additions, not subtractions. */ q = q - 8; if (__builtin_object_size (q, 0) != (size_t) -1 && __builtin_object_size (q, 0) != sizeof (t) - 10 + 8) abort (); p = &t.buf[-4]; if (__builtin_object_size (p, 0) != 0) abort (); } int main (void) { struct S s[10]; __asm ("" : "=r" (l1) : "0" (l1)); test1 (main, 6); test2 (); test3 (); test4 ((char *) s, 10); test5 (4); test6 (4); test7 (); test8 (); exit (0); }
the_stack_data/48575618.c
#include <stdio.h> #include <stdlib.h> #include <math.h> #define SIZE 5 #define DEGREE_TO_RADIAN 3.14159 / 180 double getRadian(int degree); // convert from degree to radian int main() { // Variable declaration int X[SIZE] = { 10, 20, 30, 40, 50 }; double Y[SIZE]; // Display output puts("X \t Y"); puts("----------------"); // Iterate for (int i = 0; i < SIZE; ++i) { /* for each angle (degree) in array X, converts into radian compute its sine and store in the same index location in array Y. */ Y[i] = sin(getRadian(X[i])); printf("%d \t %.2f \n", X[i], Y[i]); } puts("----------------"); puts("\n"); system("pause"); return 0; } double getRadian(int degree) { return degree * DEGREE_TO_RADIAN; }
the_stack_data/231392553.c
/* * Chinese Comment by UTF-8 * * 题目内容 * 请给出快速排序的算法 * * 分析 * 基本算法功底。写严版以第一个为pivot的就行了。 */ void swap(int* a, int* b) { int temp = *a; *a = *b; *b = temp; } void quick_sort(int* array, unsigned int length) { __quick_sort(array, 0, length); } void __quick_sort(int* array, unsigned int begin, unsigned int end) { //左开右闭 if (begin + 1 >= end) return; unsigned int left = begin + 1, right = end - 1; while (1) { while (left < right && array[left] <= array[begin]) left++; while (left < right && array[right] > array[begin]) right--; if (left < right) { swap(array + left, array + right); } else break; } swap(array + 0, array + right); __quick_sort(array, begin, right); __quick_sort(array, right, end); }
the_stack_data/153267967.c
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> int prime(int a) { int i; float s = sqrt(a); if (a % 2 == 0) return 0; else { for(i = 3; i < sqrt(a); i += 2) { if(a % i == 0) { return 0; } } } return 1; } void tower(double *x) { *x = pow(*x, *x); } int main(int argc, char *argv[]) { if(argc == 1) { printf("No number given!\n"); return -1; } int nr = atoi(argv[1]); prime(nr) ? printf("%d is prime.\n", nr) : printf("%d is not prime.\n", nr); double x = atof(argv[2]); printf("%.1lf ", x); tower(&x); printf("%.1lf\n", x); return 0; }
the_stack_data/148714.c
#include <stdio.h> int main(int argc, char *argv[]) { int index = atoi(argv[1]); char **ptr = argv + index; char *str = *ptr; return 0; }
the_stack_data/9513411.c
#include <errno.h> /* * Source file that declares the space for the global variable errno. * * We also declare the space for __argv, which is used by the err* * functions. But since it is set by crt0, it is always referenced in * every program; putting it here prevents gratuitously linking all * the err* and warn* functions (and thus printf) into every program. */ char **__argv; int errno;
the_stack_data/31388995.c
#include <stdio.h> #define RATE1 0.13230 #define RATE2 0.15040 #define RATE3 0.30025 #define RATE4 0.34025 #define BREAK1 360.0 #define BREAK2 468.0 #define BREAK3 720.0 #define BASE1 (RATE1 * BREAK1) //cost for 306kwh #define BASE2 (BASE1 + (RATE2 *(BREAK2 - BREAK1))) //cost for 468kwh #define BASE3 (BASE1 + BASE2 + (RATE3 *(BREAK3-BREAK2))) //cost for 720kwh int main(void) { double kwh; double bill; printf("Please enter the kwh used.\n"); scanf("%lf", &kwh); if (kwh <= BREAK1) bill = RATE1 *kwh; else if (kwh <= BREAK2) //kwh between 360 and 468 bill = BASE1 + (RATE2 * (kwh - BREAK1)); else if (kwh <= BREAK3) //kwh between 468 and 720 bill = BASE2 + (RATE3 * (kwh - BREAK2)); else bill = BASE3 + (RATE4 * (kwh - BREAK3)); printf("The charge for %.1f kwh is $%1.2f.\n", kwh, bill); return 0; }
the_stack_data/106998.c
#include <stdio.h> #include <stdlib.h> int main() { int a[100000]={0},n,i,j,k; scanf("%d",&n); for(i=0;i<n;i++) {scanf("%d",&j); a[j]=a[j]+1;} scanf("%d",&k); for(i=100000;k>0;i--) {if(a[i]!=0) k--;} printf("%d %d",i,a[i]); return 0; }
the_stack_data/165764746.c
/* Getopt for GNU. NOTE: getopt is now part of the C library, so if you don't know what "Keep this file name-space clean" means, talk to [email protected] before changing it! Copyright (C) 1987,88,89,90,91,92,93,94,95,96,98,99,2000,2001 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ /* This tells Alpha OSF/1 not to define a getopt prototype in <stdio.h>. Ditto for AIX 3.2 and <stdlib.h>. */ #ifndef _NO_PROTO # define _NO_PROTO #endif #ifdef HAVE_CONFIG_H # include <config.h> #endif #if !defined __STDC__ || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ # ifndef const # define const # endif #endif #include <stdio.h> /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C Library, but also included in many other GNU distributions. Compiling and linking in this code is a waste when using the GNU C library (especially if it is a shared library). Rather than having every GNU program understand `configure --with-gnu-libc' and omit the object files, it is simpler to just do this in the source for each such file. */ #define GETOPT_INTERFACE_VERSION 2 #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 # include <gnu-versions.h> # if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION # define ELIDE_CODE # endif #endif /* This needs to come after some library #include to get __GNU_LIBRARY__ defined. */ #ifdef __GNU_LIBRARY__ /* Don't include stdlib.h for non-GNU C libraries because some of them contain conflicting prototypes for getopt. */ # include <stdlib.h> # include <unistd.h> #endif /* GNU C library. */ #ifdef VMS # include <unixlib.h> # if HAVE_STRING_H - 0 # include <string.h> # endif #endif #ifndef _ /* This is for other GNU distributions with internationalized messages. */ # if (HAVE_LIBINTL_H && ENABLE_NLS) || defined _LIBC # include <libintl.h> # ifndef _ # define _(msgid) gettext (msgid) # endif # else # define _(msgid) (msgid) # endif # if defined _LIBC && defined USE_IN_LIBIO # include <wchar.h> # endif #endif /* This version of `getopt' appears to the caller like standard Unix `getopt' but it behaves differently for the user, since it allows the user to intersperse the options with the other arguments. As `getopt' works, it permutes the elements of ARGV so that, when it is done, all the options precede everything else. Thus all application programs are extended to handle flexible argument order. Setting the environment variable POSIXLY_CORRECT disables permutation. Then the behavior is completely standard. GNU application programs can use a third alternative mode in which they can distinguish the relative order of options and other arguments. */ #include "getopt.h" /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, the argument value is returned here. Also, when `ordering' is RETURN_IN_ORDER, each non-option ARGV-element is returned here. */ char *optarg; /* Index in ARGV of the next element to be scanned. This is used for communication to and from the caller and for communication between successive calls to `getopt'. On entry to `getopt', zero means this is the first call; initialize. When `getopt' returns -1, this is the index of the first of the non-option elements that the caller should itself scan. Otherwise, `optind' communicates from one call to the next how much of ARGV has been scanned so far. */ /* 1003.2 says this must be 1 before any call. */ int optind = 1; /* Formerly, initialization of getopt depended on optind==0, which causes problems with re-calling getopt as programs generally don't know that. */ int __getopt_initialized; /* The next char to be scanned in the option-element in which the last option character we returned was found. This allows us to pick up the scan where we left off. If this is zero, or a null string, it means resume the scan by advancing to the next ARGV-element. */ static char *nextchar; /* Callers store zero here to inhibit the error message for unrecognized options. */ int opterr = 1; /* Set to an option character which was unrecognized. This must be initialized on some systems to avoid linking in the system's own getopt implementation. */ int optopt = '?'; /* Describe how to deal with options that follow non-option ARGV-elements. If the caller did not specify anything, the default is REQUIRE_ORDER if the environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise. REQUIRE_ORDER means don't recognize them as options; stop option processing when the first non-option is seen. This is what Unix does. This mode of operation is selected by either setting the environment variable POSIXLY_CORRECT, or using `+' as the first character of the list of option characters. PERMUTE is the default. We permute the contents of ARGV as we scan, so that eventually all the non-options are at the end. This allows options to be given in any order, even with programs that were not written to expect this. RETURN_IN_ORDER is an option available to programs that were written to expect options and other ARGV-elements in any order and that care about the ordering of the two. We describe each non-option ARGV-element as if it were the argument of an option with character code 1. Using `-' as the first character of the list of option characters selects this mode of operation. The special argument `--' forces an end of option-scanning regardless of the value of `ordering'. In the case of RETURN_IN_ORDER, only `--' can cause `getopt' to return -1 with `optind' != ARGC. */ static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering; /* Value of POSIXLY_CORRECT environment variable. */ static char *posixly_correct; #ifdef __GNU_LIBRARY__ /* We want to avoid inclusion of string.h with non-GNU libraries because there are many ways it can cause trouble. On some systems, it contains special magic macros that don't work in GCC. */ # include <string.h> # define my_index strchr #else # if HAVE_STRING_H # include <string.h> # else # include <strings.h> # endif /* Avoid depending on library functions or files whose names are inconsistent. */ #ifndef getenv extern char *getenv (); #endif static char * my_index (str, chr) const char *str; int chr; { while (*str) { if (*str == chr) return (char *) str; str++; } return 0; } /* If using GCC, we can safely declare strlen this way. If not using GCC, it is ok not to declare it. */ #ifdef __GNUC__ /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. That was relevant to code that was here before. */ # if (!defined __STDC__ || !__STDC__) && !defined strlen /* gcc with -traditional declares the built-in strlen to return int, and has done so at least since version 2.4.5. -- rms. */ extern int strlen (const char *); # endif /* not __STDC__ */ #endif /* __GNUC__ */ #endif /* not __GNU_LIBRARY__ */ /* Handle permutation of arguments. */ /* Describe the part of ARGV that contains non-options that have been skipped. `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is the index after the last of them. */ static int first_nonopt; static int last_nonopt; #ifdef _LIBC /* Stored original parameters. XXX This is no good solution. We should rather copy the args so that we can compare them later. But we must not use malloc(3). */ extern int __libc_argc; extern char **__libc_argv; /* Bash 2.0 gives us an environment variable containing flags indicating ARGV elements that should not be considered arguments. */ # ifdef USE_NONOPTION_FLAGS /* Defined in getopt_init.c */ extern char *__getopt_nonoption_flags; static int nonoption_flags_max_len; static int nonoption_flags_len; # endif # ifdef USE_NONOPTION_FLAGS # define SWAP_FLAGS(ch1, ch2) \ if (nonoption_flags_len > 0) \ { \ char __tmp = __getopt_nonoption_flags[ch1]; \ __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ __getopt_nonoption_flags[ch2] = __tmp; \ } # else # define SWAP_FLAGS(ch1, ch2) # endif #else /* !_LIBC */ # define SWAP_FLAGS(ch1, ch2) #endif /* _LIBC */ /* Exchange two adjacent subsequences of ARGV. One subsequence is elements [first_nonopt,last_nonopt) which contains all the non-options that have been skipped so far. The other is elements [last_nonopt,optind), which contains all the options processed since those non-options were skipped. `first_nonopt' and `last_nonopt' are relocated so that they describe the new indices of the non-options in ARGV after they are moved. */ #if defined __STDC__ && __STDC__ static void exchange (char **); #endif static void exchange (argv) char **argv; { int bottom = first_nonopt; int middle = last_nonopt; int top = optind; char *tem; /* Exchange the shorter segment with the far end of the longer segment. That puts the shorter segment into the right place. It leaves the longer segment in the right place overall, but it consists of two parts that need to be swapped next. */ #if defined _LIBC && defined USE_NONOPTION_FLAGS /* First make sure the handling of the `__getopt_nonoption_flags' string can work normally. Our top argument must be in the range of the string. */ if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) { /* We must extend the array. The user plays games with us and presents new arguments. */ char *new_str = malloc (top + 1); if (new_str == NULL) nonoption_flags_len = nonoption_flags_max_len = 0; else { memset (__mempcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len), '\0', top + 1 - nonoption_flags_max_len); nonoption_flags_max_len = top + 1; __getopt_nonoption_flags = new_str; } } #endif while (top > middle && middle > bottom) { if (top - middle > middle - bottom) { /* Bottom segment is the short one. */ int len = middle - bottom; register int i; /* Swap it with the top part of the top segment. */ for (i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[top - (middle - bottom) + i]; argv[top - (middle - bottom) + i] = tem; SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); } /* Exclude the moved bottom segment from further swapping. */ top -= len; } else { /* Top segment is the short one. */ int len = top - middle; register int i; /* Swap it with the bottom part of the bottom segment. */ for (i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[middle + i]; argv[middle + i] = tem; SWAP_FLAGS (bottom + i, middle + i); } /* Exclude the moved top segment from further swapping. */ bottom += len; } } /* Update records for the slots the non-options now occupy. */ first_nonopt += (optind - last_nonopt); last_nonopt = optind; } /* Initialize the internal data when the first call is made. */ #if defined __STDC__ && __STDC__ static const char *_getopt_initialize (int, char *const *, const char *); #endif static const char * _getopt_initialize (argc, argv, optstring) int argc; char *const *argv; const char *optstring; { /* Start processing options with ARGV-element 1 (since ARGV-element 0 is the program name); the sequence of previously skipped non-option ARGV-elements is empty. */ first_nonopt = last_nonopt = optind; nextchar = NULL; posixly_correct = getenv ("POSIXLY_CORRECT"); /* Determine how to handle the ordering of options and nonoptions. */ if (optstring[0] == '-') { ordering = RETURN_IN_ORDER; ++optstring; } else if (optstring[0] == '+') { ordering = REQUIRE_ORDER; ++optstring; } else if (posixly_correct != NULL) ordering = REQUIRE_ORDER; else ordering = PERMUTE; #if defined _LIBC && defined USE_NONOPTION_FLAGS if (posixly_correct == NULL && argc == __libc_argc && argv == __libc_argv) { if (nonoption_flags_max_len == 0) { if (__getopt_nonoption_flags == NULL || __getopt_nonoption_flags[0] == '\0') nonoption_flags_max_len = -1; else { const char *orig_str = __getopt_nonoption_flags; int len = nonoption_flags_max_len = strlen (orig_str); if (nonoption_flags_max_len < argc) nonoption_flags_max_len = argc; __getopt_nonoption_flags = (char *) malloc (nonoption_flags_max_len); if (__getopt_nonoption_flags == NULL) nonoption_flags_max_len = -1; else memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), '\0', nonoption_flags_max_len - len); } } nonoption_flags_len = nonoption_flags_max_len; } else nonoption_flags_len = 0; #endif return optstring; } /* Scan elements of ARGV (whose length is ARGC) for option characters given in OPTSTRING. If an element of ARGV starts with '-', and is not exactly "-" or "--", then it is an option element. The characters of this element (aside from the initial '-') are option characters. If `getopt' is called repeatedly, it returns successively each of the option characters from each of the option elements. If `getopt' finds another option character, it returns that character, updating `optind' and `nextchar' so that the next call to `getopt' can resume the scan with the following option character or ARGV-element. If there are no more option characters, `getopt' returns -1. Then `optind' is the index in ARGV of the first ARGV-element that is not an option. (The ARGV-elements have been permuted so that those that are not options now come last.) OPTSTRING is a string containing the legitimate option characters. If an option character is seen that is not listed in OPTSTRING, return '?' after printing an error message. If you set `opterr' to zero, the error message is suppressed but we still return '?'. If a char in OPTSTRING is followed by a colon, that means it wants an arg, so the following text in the same ARGV-element, or the text of the following ARGV-element, is returned in `optarg'. Two colons mean an option that wants an optional arg; if there is text in the current ARGV-element, it is returned in `optarg', otherwise `optarg' is set to zero. If OPTSTRING starts with `-' or `+', it requests different methods of handling the non-option ARGV-elements. See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. Long-named options begin with `--' instead of `-'. Their names may be abbreviated as long as the abbreviation is unique or is an exact match for some defined option. If they have an argument, it follows the option name in the same ARGV-element, separated from the option name by a `=', or else the in next ARGV-element. When `getopt' finds a long-named option, it returns 0 if that option's `flag' field is nonzero, the value of the option's `val' field if the `flag' field is zero. The elements of ARGV aren't really const, because we permute them. But we pretend they're const in the prototype to be compatible with other systems. LONGOPTS is a vector of `struct option' terminated by an element containing a name which is zero. LONGIND returns the index in LONGOPT of the long-named option found. It is only valid when a long-named option has been found by the most recent call. If LONG_ONLY is nonzero, '-' as well as '--' can introduce long-named options. */ int _getopt_internal (argc, argv, optstring, longopts, longind, long_only) int argc; char *const *argv; const char *optstring; const struct option *longopts; int *longind; int long_only; { int print_errors = opterr; if (optstring[0] == ':') print_errors = 0; if (argc < 1) return -1; optarg = NULL; if (optind == 0 || !__getopt_initialized) { if (optind == 0) optind = 1; /* Don't scan ARGV[0], the program name. */ optstring = _getopt_initialize (argc, argv, optstring); __getopt_initialized = 1; } /* Test whether ARGV[optind] points to a non-option argument. Either it does not have option syntax, or there is an environment flag from the shell indicating it is not an option. The later information is only used when the used in the GNU libc. */ #if defined _LIBC && defined USE_NONOPTION_FLAGS # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ || (optind < nonoption_flags_len \ && __getopt_nonoption_flags[optind] == '1')) #else # define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') #endif if (nextchar == NULL || *nextchar == '\0') { /* Advance to the next ARGV-element. */ /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been moved back by the user (who may also have changed the arguments). */ if (last_nonopt > optind) last_nonopt = optind; if (first_nonopt > optind) first_nonopt = optind; if (ordering == PERMUTE) { /* If we have just processed some options following some non-options, exchange them so that the options come first. */ if (first_nonopt != last_nonopt && last_nonopt != optind) exchange ((char **) argv); else if (last_nonopt != optind) first_nonopt = optind; /* Skip any additional non-options and extend the range of non-options previously skipped. */ while (optind < argc && NONOPTION_P) optind++; last_nonopt = optind; } /* The special ARGV-element `--' means premature end of options. Skip it like a null option, then exchange with previous non-options as if it were an option, then skip everything else like a non-option. */ if (optind != argc && !strcmp (argv[optind], "--")) { optind++; if (first_nonopt != last_nonopt && last_nonopt != optind) exchange ((char **) argv); else if (first_nonopt == last_nonopt) first_nonopt = optind; last_nonopt = argc; optind = argc; } /* If we have done all the ARGV-elements, stop the scan and back over any non-options that we skipped and permuted. */ if (optind == argc) { /* Set the next-arg-index to point at the non-options that we previously skipped, so the caller will digest them. */ if (first_nonopt != last_nonopt) optind = first_nonopt; return -1; } /* If we have come to a non-option and did not permute it, either stop the scan or describe it to the caller and pass it by. */ if (NONOPTION_P) { if (ordering == REQUIRE_ORDER) return -1; optarg = argv[optind++]; return 1; } /* We have found another option-ARGV-element. Skip the initial punctuation. */ nextchar = (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-')); } /* Decode the current option-ARGV-element. */ /* Check whether the ARGV-element is a long option. If long_only and the ARGV-element has the form "-f", where f is a valid short option, don't consider it an abbreviated form of a long option that starts with f. Otherwise there would be no way to give the -f short option. On the other hand, if there's a long option "fubar" and the ARGV-element is "-fu", do consider that an abbreviation of the long option, just like "--fu", and not "-f" with arg "u". This distinction seems to be the most useful approach. */ if (longopts != NULL && (argv[optind][1] == '-' || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) { char *nameend; const struct option *p; const struct option *pfound = NULL; int exact = 0; int ambig = 0; int indfound = -1; int option_index; for (nameend = nextchar; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; /* Test all long options for either exact match or abbreviated matches. */ for (p = longopts, option_index = 0; p->name; p++, option_index++) if (!strncmp (p->name, nextchar, nameend - nextchar)) { if ((unsigned int) (nameend - nextchar) == (unsigned int) strlen (p->name)) { /* Exact match found. */ pfound = p; indfound = option_index; exact = 1; break; } else if (pfound == NULL) { /* First nonexact match found. */ pfound = p; indfound = option_index; } else if (long_only || pfound->has_arg != p->has_arg || pfound->flag != p->flag || pfound->val != p->val) /* Second or later nonexact match found. */ ambig = 1; } if (ambig && !exact) { if (print_errors) { #if defined _LIBC && defined USE_IN_LIBIO char *buf; __asprintf (&buf, _("%s: option `%s' is ambiguous\n"), argv[0], argv[optind]); if (_IO_fwide (stderr, 0) > 0) __fwprintf (stderr, L"%s", buf); else fputs (buf, stderr); free (buf); #else fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0], argv[optind]); #endif } nextchar += strlen (nextchar); optind++; optopt = 0; return '?'; } if (pfound != NULL) { option_index = indfound; optind++; if (*nameend) { /* Don't test has_arg with >, because some C compilers don't allow it to be used on enums. */ if (pfound->has_arg) optarg = nameend + 1; else { if (print_errors) { #if defined _LIBC && defined USE_IN_LIBIO char *buf; #endif if (argv[optind - 1][1] == '-') { /* --option */ #if defined _LIBC && defined USE_IN_LIBIO __asprintf (&buf, _("\ %s: option `--%s' doesn't allow an argument\n"), argv[0], pfound->name); #else fprintf (stderr, _("\ %s: option `--%s' doesn't allow an argument\n"), argv[0], pfound->name); #endif } else { /* +option or -option */ #if defined _LIBC && defined USE_IN_LIBIO __asprintf (&buf, _("\ %s: option `%c%s' doesn't allow an argument\n"), argv[0], argv[optind - 1][0], pfound->name); #else fprintf (stderr, _("\ %s: option `%c%s' doesn't allow an argument\n"), argv[0], argv[optind - 1][0], pfound->name); #endif } #if defined _LIBC && defined USE_IN_LIBIO if (_IO_fwide (stderr, 0) > 0) __fwprintf (stderr, L"%s", buf); else fputs (buf, stderr); free (buf); #endif } nextchar += strlen (nextchar); optopt = pfound->val; return '?'; } } else if (pfound->has_arg == 1) { if (optind < argc) optarg = argv[optind++]; else { if (print_errors) { #if defined _LIBC && defined USE_IN_LIBIO char *buf; __asprintf (&buf, _("%s: option `%s' requires an argument\n"), argv[0], argv[optind - 1]); if (_IO_fwide (stderr, 0) > 0) __fwprintf (stderr, L"%s", buf); else fputs (buf, stderr); free (buf); #else fprintf (stderr, _("%s: option `%s' requires an argument\n"), argv[0], argv[optind - 1]); #endif } nextchar += strlen (nextchar); optopt = pfound->val; return optstring[0] == ':' ? ':' : '?'; } } nextchar += strlen (nextchar); if (longind != NULL) *longind = option_index; if (pfound->flag) { *(pfound->flag) = pfound->val; return 0; } return pfound->val; } /* Can't find it as a long option. If this is not getopt_long_only, or the option starts with '--' or is not a valid short option, then it's an error. Otherwise interpret it as a short option. */ if (!long_only || argv[optind][1] == '-' || my_index (optstring, *nextchar) == NULL) { if (print_errors) { #if defined _LIBC && defined USE_IN_LIBIO char *buf; #endif if (argv[optind][1] == '-') { /* --option */ #if defined _LIBC && defined USE_IN_LIBIO __asprintf (&buf, _("%s: unrecognized option `--%s'\n"), argv[0], nextchar); #else fprintf (stderr, _("%s: unrecognized option `--%s'\n"), argv[0], nextchar); #endif } else { /* +option or -option */ #if defined _LIBC && defined USE_IN_LIBIO __asprintf (&buf, _("%s: unrecognized option `%c%s'\n"), argv[0], argv[optind][0], nextchar); #else fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), argv[0], argv[optind][0], nextchar); #endif } #if defined _LIBC && defined USE_IN_LIBIO if (_IO_fwide (stderr, 0) > 0) __fwprintf (stderr, L"%s", buf); else fputs (buf, stderr); free (buf); #endif } nextchar = (char *) ""; optind++; optopt = 0; return '?'; } } /* Look at and handle the next short option-character. */ { char c = *nextchar++; char *temp = my_index (optstring, c); /* Increment `optind' when we start to process its last character. */ if (*nextchar == '\0') ++optind; if (temp == NULL || c == ':') { if (print_errors) { #if defined _LIBC && defined USE_IN_LIBIO char *buf; #endif if (posixly_correct) { /* 1003.2 specifies the format of this message. */ #if defined _LIBC && defined USE_IN_LIBIO __asprintf (&buf, _("%s: illegal option -- %c\n"), argv[0], c); #else fprintf (stderr, _("%s: illegal option -- %c\n"), argv[0], c); #endif } else { #if defined _LIBC && defined USE_IN_LIBIO __asprintf (&buf, _("%s: invalid option -- %c\n"), argv[0], c); #else fprintf (stderr, _("%s: invalid option -- %c\n"), argv[0], c); #endif } #if defined _LIBC && defined USE_IN_LIBIO if (_IO_fwide (stderr, 0) > 0) __fwprintf (stderr, L"%s", buf); else fputs (buf, stderr); free (buf); #endif } optopt = c; return '?'; } /* Convenience. Treat POSIX -W foo same as long option --foo */ if (temp[0] == 'W' && temp[1] == ';') { char *nameend; const struct option *p; const struct option *pfound = NULL; int exact = 0; int ambig = 0; int indfound = 0; int option_index; /* This is an option that requires an argument. */ if (*nextchar != '\0') { optarg = nextchar; /* If we end this ARGV-element by taking the rest as an arg, we must advance to the next element now. */ optind++; } else if (optind == argc) { if (print_errors) { /* 1003.2 specifies the format of this message. */ #if defined _LIBC && defined USE_IN_LIBIO char *buf; __asprintf (&buf, _("%s: option requires an argument -- %c\n"), argv[0], c); if (_IO_fwide (stderr, 0) > 0) __fwprintf (stderr, L"%s", buf); else fputs (buf, stderr); free (buf); #else fprintf (stderr, _("%s: option requires an argument -- %c\n"), argv[0], c); #endif } optopt = c; if (optstring[0] == ':') c = ':'; else c = '?'; return c; } else /* We already incremented `optind' once; increment it again when taking next ARGV-elt as argument. */ optarg = argv[optind++]; /* optarg is now the argument, see if it's in the table of longopts. */ for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; /* Test all long options for either exact match or abbreviated matches. */ for (p = longopts, option_index = 0; p->name; p++, option_index++) if (!strncmp (p->name, nextchar, nameend - nextchar)) { if ((unsigned int) (nameend - nextchar) == strlen (p->name)) { /* Exact match found. */ pfound = p; indfound = option_index; exact = 1; break; } else if (pfound == NULL) { /* First nonexact match found. */ pfound = p; indfound = option_index; } else /* Second or later nonexact match found. */ ambig = 1; } if (ambig && !exact) { if (print_errors) { #if defined _LIBC && defined USE_IN_LIBIO char *buf; __asprintf (&buf, _("%s: option `-W %s' is ambiguous\n"), argv[0], argv[optind]); if (_IO_fwide (stderr, 0) > 0) __fwprintf (stderr, L"%s", buf); else fputs (buf, stderr); free (buf); #else fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), argv[0], argv[optind]); #endif } nextchar += strlen (nextchar); optind++; return '?'; } if (pfound != NULL) { option_index = indfound; if (*nameend) { /* Don't test has_arg with >, because some C compilers don't allow it to be used on enums. */ if (pfound->has_arg) optarg = nameend + 1; else { if (print_errors) { #if defined _LIBC && defined USE_IN_LIBIO char *buf; __asprintf (&buf, _("\ %s: option `-W %s' doesn't allow an argument\n"), argv[0], pfound->name); if (_IO_fwide (stderr, 0) > 0) __fwprintf (stderr, L"%s", buf); else fputs (buf, stderr); free (buf); #else fprintf (stderr, _("\ %s: option `-W %s' doesn't allow an argument\n"), argv[0], pfound->name); #endif } nextchar += strlen (nextchar); return '?'; } } else if (pfound->has_arg == 1) { if (optind < argc) optarg = argv[optind++]; else { if (print_errors) { #if defined _LIBC && defined USE_IN_LIBIO char *buf; __asprintf (&buf, _("\ %s: option `%s' requires an argument\n"), argv[0], argv[optind - 1]); if (_IO_fwide (stderr, 0) > 0) __fwprintf (stderr, L"%s", buf); else fputs (buf, stderr); free (buf); #else fprintf (stderr, _("%s: option `%s' requires an argument\n"), argv[0], argv[optind - 1]); #endif } nextchar += strlen (nextchar); return optstring[0] == ':' ? ':' : '?'; } } nextchar += strlen (nextchar); if (longind != NULL) *longind = option_index; if (pfound->flag) { *(pfound->flag) = pfound->val; return 0; } return pfound->val; } nextchar = NULL; return 'W'; /* Let the application handle it. */ } if (temp[1] == ':') { if (temp[2] == ':') { /* This is an option that accepts an argument optionally. */ if (*nextchar != '\0') { optarg = nextchar; optind++; } else optarg = NULL; nextchar = NULL; } else { /* This is an option that requires an argument. */ if (*nextchar != '\0') { optarg = nextchar; /* If we end this ARGV-element by taking the rest as an arg, we must advance to the next element now. */ optind++; } else if (optind == argc) { if (print_errors) { /* 1003.2 specifies the format of this message. */ #if defined _LIBC && defined USE_IN_LIBIO char *buf; __asprintf (&buf, _("%s: option requires an argument -- %c\n"), argv[0], c); if (_IO_fwide (stderr, 0) > 0) __fwprintf (stderr, L"%s", buf); else fputs (buf, stderr); free (buf); #else fprintf (stderr, _("%s: option requires an argument -- %c\n"), argv[0], c); #endif } optopt = c; if (optstring[0] == ':') c = ':'; else c = '?'; } else /* We already incremented `optind' once; increment it again when taking next ARGV-elt as argument. */ optarg = argv[optind++]; nextchar = NULL; } } return c; } } int getopt (argc, argv, optstring) int argc; char *const *argv; const char *optstring; { return _getopt_internal (argc, argv, optstring, (const struct option *) 0, (int *) 0, 0); } #ifdef TEST /* Compile with -DTEST to make an executable for use in testing the above definition of `getopt'. */ int main (argc, argv) int argc; char **argv; { int c; int digit_optind = 0; while (1) { int this_option_optind = optind ? optind : 1; c = getopt (argc, argv, "abc:d:0123456789"); if (c == -1) break; switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (digit_optind != 0 && digit_optind != this_option_optind) printf ("digits occur in two different argv-elements.\n"); digit_optind = this_option_optind; printf ("option %c\n", c); break; case 'a': printf ("option a\n"); break; case 'b': printf ("option b\n"); break; case 'c': printf ("option c with value `%s'\n", optarg); break; case '?': break; default: printf ("?? getopt returned character code 0%o ??\n", c); } } if (optind < argc) { printf ("non-option ARGV-elements: "); while (optind < argc) printf ("%s ", argv[optind++]); printf ("\n"); } exit (0); } #endif /* TEST */
the_stack_data/9512799.c
#include <string.h> #include <stdlib.h> void uitoa(unsigned int value, char *str, unsigned int radix) { char *s = str; int remainder; do { remainder = value % radix; if (remainder < 10) { *s = '0' + remainder; } else { remainder -= 10; *s = 'a' + remainder; } s++; value /= radix; } while (value > 0); // Terminate the string. *s = 0; // Put the characters in the correct order. strrev(str); }
the_stack_data/140765821.c
#include<stdio.h> #include<stdlib.h> // Possibilidades de criação de enum // enum week {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}; // enum semana {Sunday = 1, Monday, Tuesday = 7, Wednesday, Thursday, Friday, Saturday}; enum scape {retr='\b', tab='\t', new_line='\n'}; int main(int argc, char const *argv[]) { enum scape e = new_line; printf("Hi, %c Sr. %c !", e, e); e = tab; printf("\nHi, %c Sr. %c !", e, e); return 0; }
the_stack_data/751126.c
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> double srednia(int,int []); int main() { int n,i; do { printf("Podaj rozmiar tablicy: "); scanf("%i",&n); }while(n<=0); int tab[n]; srand(time(NULL)); for(i=0;i<n;i++) { tab[i]=rand()%11; printf("%3i",tab[i]); } printf("\n\n"); printf("Srednia geometryczna elementow tablicy wynosi %.2f\n",srednia(n,tab)); return 0; } //Podpunkt a double srednia(int n,int tab[]) { int i; double iloczyn=1; for(i=0;i<n;i++) { iloczyn*=tab[i]; } return pow(iloczyn,1./n); }
the_stack_data/62638492.c
/* * Copyright (c) $YEAR$ TOTAL SA. All rights reserved. * * Author: Corentin Rossignon ([email protected]) * Date: $DATE$ * */ #include <stdlib.h> #include <stdio.h>
the_stack_data/99261.c
//{{BLOCK(Box7) //====================================================================== // // Box7, 8x8@4, // + palette 256 entries, not compressed // + 1 tiles not compressed // Total size: 512 + 32 = 544 // // Time-stamp: 2018-03-01, 14:50:20 // Exported by Cearn's GBA Image Transmogrifier, v0.8.3 // ( http://www.coranac.com/projects/#grit ) // //====================================================================== const unsigned int Box7Tiles[8] __attribute__((aligned(4)))= { 0x22222222,0x22111122,0x21333312,0x21311112,0x21131112,0x21113112,0x22113122,0x22222222, }; const unsigned int Box7Pal[128] __attribute__((aligned(4)))= { 0x03DF0000,0x19B27EC0,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x001F0000,0x0000294A,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x021F0000,0x0000294A,0x00000000,0x00000000,0x00001000,0x00000000,0x00000000,0x04000C00, 0x03FF0000,0x0000294A,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x03E00000,0x0000294A,0x00000000,0x0C000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x7C000000,0x0000294A,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x40090000,0x0000294A,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00001C00,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x10000000, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x10000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000, }; //}}BLOCK(Box7)
the_stack_data/579936.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> int main() { srand(time(NULL)); FILE *arq = fopen("pts.txt", "w"); for(int i = 0; i < 100; i++) { float x, y; x = 50 - 100*((float)rand())/RAND_MAX; y = 50 - 100*((float)rand())/RAND_MAX; fprintf(arq, "%.02f %.02f\n", x, y); } fclose(arq); return 0; }
the_stack_data/885484.c
#include "stdio.h" #include "stdlib.h" #include "math.h" struct node { int coeff, expx, expy, expz, flag; struct node *link; }; typedef struct node *NODE; NODE setnode() { NODE x = (NODE)malloc(sizeof(struct node)); return x; } NODE insert_rear(int coeff, int expx, int expy, int expz, NODE head) { NODE temp, cur; temp = setnode(); temp->coeff = coeff; temp->expx = expx; temp->expy = expy; temp->expz = expz; temp->link = NULL; cur = head->link; while (cur->link != head) cur = cur->link; cur->link = temp; temp->link = head; return head; } NODE read_poly(NODE head) { int expx, expy, expz, coeff, ch = 1; while (ch != 0) { printf("Please input your Polynomial\n"); printf("\tEnter the coeff\n"); scanf("%d", &coeff); printf("\tEnter power of x\n"); scanf("%d", &expx); printf("\tEnter the power y\n"); scanf("%d", &expy); printf("\tEnter the power z\n"); scanf("%d", &expz); head = insert_rear(coeff, expx, expy, expz, head); printf("\tPess 1 to enter one more item or 0 to end\n"); scanf("%d", &ch); } return head; } void display(NODE head) { NODE temp; if (head->link == head) { printf("\t\tPolynomial doesn't exist yet!\n"); } else { temp = head->link; while (temp != head) { printf("\t\t%dx^%dy^%dz^%d", temp->coeff, temp->expx, temp->expy, temp->expz); if (temp->link != head) printf("+"); temp = temp->link; } printf("\n"); } } NODE add_poly(NODE head1, NODE head2, NODE head3) { NODE temp1, temp2; int x1, x2, y1, y2, z1, z2; int coeff1, coeff2, coeff; temp1 = head1->link; //While 01 while (temp1 != head1) { x1 = temp1->expx; y1 = temp1->expy; z1 = temp1->expz; coeff1 = temp1->coeff; temp2 = head2->link; while (temp2 != head2) { x2 = temp2->expx; y2 = temp2->expy; z2 = temp2->expz; coeff2 = temp2->coeff; if (x1 == x2 && y1 == y2 && z1 == z2) break; temp2 = temp2->link; } if (temp2 != head2) { coeff = coeff1 + coeff2; temp2->flag = 1; if (coeff != 0) head3 = insert_rear(coeff, x1, y1, z1, head3); } else head3 = insert_rear(coeff1, x1, y1, z1, head3); temp1 = temp1->link; } temp2 = head2->link; // While 02 while (temp2 != head2) { if (temp2->flag == 0) head3 = insert_rear(temp2->coeff, temp2->expx, temp2->expy, temp2->expz, head3); temp2 = temp2->link; } return head3; } void evaluate(NODE head) { NODE temp; int x, y, z; double result = 0; printf("\tEnter x,y,z values\n"); scanf("%d%d%d", &x, &y, &z); temp = head->link; while (temp != head) { result = result + (temp->coeff * pow(x, temp->expx) * pow(y, temp->expy) * pow(z, temp->expz)); temp = temp->link; } printf("Polynomial evaluated result is %f\n", result); } int main() { NODE head, head1, head2, head3; int ch; head = setnode(); head1 = setnode(); head2 = setnode(); head3 = setnode(); head->link = head; head1->link = head1; head2->link = head2; head3->link = head3; while (1) { printf("\t-_-_-_-_-_-_-_-_-_-_MENU-_-_-_-_-_-_-_-_-_-_\n\t1.Evaluate polynomial\n\t2.Polynomial addition\n\t3.Exit\n"); printf("\tEnter your choice\n"); scanf("%d", &ch); switch (ch) { case 1: printf("\tEnter polynomial to evaluate\n"); head = read_poly(head); display(head); evaluate(head); break; case 2: printf("\tEnter the first polynomial\n"); head1 = read_poly(head1); printf("\tEnter the second polynomial\n"); head2 = read_poly(head2); head3 = add_poly(head1, head2, head3); printf("\tThe first polynomial is\n"); display(head1); printf("\The second polynomial is\n"); display(head2); printf("\The sum of 2 polynomials is\n"); display(head3); break; case 3: exit(0); default: printf("\t\tInvalid choice\n"); } } }
the_stack_data/243892555.c
// // Created by Nicholas Robison on 2019-01-22. // /* C */ #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> extern int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); int main() { #ifdef __AFL_HAVE_MANUAL_CONTROL while (__AFL_LOOP(1000)) { #endif // Read from stdin char *line = NULL; size_t size = 0; ssize_t amt = getline(&line, &size, stdin); if (amt < 0) { fprintf(stderr, "could not read from stdin: %s\n", strerror(ferror(stdin))); return -1; } uint8_t *buffer = (u_int8_t *)line; LLVMFuzzerTestOneInput(buffer, size); #ifdef __AFL_HAVE_MANUAL_CONTROL } #endif }
the_stack_data/3262476.c
/* SDL_mixer: An audio mixer library based on the SDL library Copyright (C) 1997-2012 Sam Lantinga <[email protected]> This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ #ifdef MOD_MUSIC /* This file supports MOD tracker music streams */ #include "SDL_mixer.h" #include "dynamic_mod.h" #include "music_mod.h" #include "mikmod.h" #define SDL_SURROUND #ifdef SDL_SURROUND #define MAX_OUTPUT_CHANNELS 6 #else #define MAX_OUTPUT_CHANNELS 2 #endif /* Reference for converting mikmod output to 4/6 channels */ static int current_output_channels; static Uint16 current_output_format; static int music_swap8; static int music_swap16; /* Initialize the MOD player, with the given mixer settings This function returns 0, or -1 if there was an error. */ int MOD_init(SDL_AudioSpec *mixerfmt) { CHAR *list; if ( !Mix_Init(MIX_INIT_MOD) ) { return -1; } /* Set the MikMod music format */ music_swap8 = 0; music_swap16 = 0; switch (mixerfmt->format) { case AUDIO_U8: case AUDIO_S8: { if ( mixerfmt->format == AUDIO_S8 ) { music_swap8 = 1; } *mikmod.md_mode = 0; } break; case AUDIO_S16LSB: case AUDIO_S16MSB: { /* See if we need to correct MikMod mixing */ #if SDL_BYTEORDER == SDL_LIL_ENDIAN if ( mixerfmt->format == AUDIO_S16MSB ) { #else if ( mixerfmt->format == AUDIO_S16LSB ) { #endif music_swap16 = 1; } *mikmod.md_mode = DMODE_16BITS; } break; default: { Mix_SetError("Unknown hardware audio format"); return -1; } } current_output_channels = mixerfmt->channels; current_output_format = mixerfmt->format; if ( mixerfmt->channels > 1 ) { if ( mixerfmt->channels > MAX_OUTPUT_CHANNELS ) { Mix_SetError("Hardware uses more channels than mixerfmt"); return -1; } *mikmod.md_mode |= DMODE_STEREO; } *mikmod.md_mixfreq = mixerfmt->freq; *mikmod.md_device = 0; *mikmod.md_volume = 96; *mikmod.md_musicvolume = 128; *mikmod.md_sndfxvolume = 128; *mikmod.md_pansep = 128; *mikmod.md_reverb = 0; *mikmod.md_mode |= DMODE_HQMIXER|DMODE_SOFT_MUSIC|DMODE_SURROUND; list = mikmod.MikMod_InfoDriver(); if ( list ) mikmod.MikMod_free(list); else mikmod.MikMod_RegisterDriver(mikmod.drv_nos); list = mikmod.MikMod_InfoLoader(); if ( list ) mikmod.MikMod_free(list); else mikmod.MikMod_RegisterAllLoaders(); if ( mikmod.MikMod_Init(NULL) ) { Mix_SetError("%s", mikmod.MikMod_strerror(*mikmod.MikMod_errno)); return -1; } return 0; } /* Uninitialize the music players */ void MOD_exit(void) { if (mikmod.MikMod_Exit) { mikmod.MikMod_Exit(); } } /* Set the volume for a MOD stream */ void MOD_setvolume(MODULE *music, int volume) { mikmod.Player_SetVolume((SWORD)volume); } typedef struct { /* MREADER basic members in libmikmod2/3: */ int (*Seek)(struct MREADER*, long, int); long (*Tell)(struct MREADER*); BOOL (*Read)(struct MREADER*, void*, size_t); int (*Get)(struct MREADER*); BOOL (*Eof)(struct MREADER*); /* no iobase members in libmikmod <= 3.2.0-beta2 */ long iobase, prev_iobase; long eof; SDL_RWops *rw; } LMM_MREADER; int LMM_Seek(struct MREADER *mr,long to,int dir) { LMM_MREADER* lmmmr = (LMM_MREADER*)mr; if ( dir == SEEK_SET ) { to += lmmmr->iobase; if (to < lmmmr->iobase) return -1; } return (SDL_RWseek(lmmmr->rw, to, dir) < lmmmr->iobase)? -1 : 0; } long LMM_Tell(struct MREADER *mr) { LMM_MREADER* lmmmr = (LMM_MREADER*)mr; return SDL_RWtell(lmmmr->rw) - lmmmr->iobase; } BOOL LMM_Read(struct MREADER *mr,void *buf,size_t sz) { LMM_MREADER* lmmmr = (LMM_MREADER*)mr; return SDL_RWread(lmmmr->rw, buf, sz, 1); } int LMM_Get(struct MREADER *mr) { unsigned char c; LMM_MREADER* lmmmr = (LMM_MREADER*)mr; if ( SDL_RWread(lmmmr->rw, &c, 1, 1) ) { return c; } return EOF; } BOOL LMM_Eof(struct MREADER *mr) { long offset; LMM_MREADER* lmmmr = (LMM_MREADER*)mr; offset = LMM_Tell(mr); return offset >= lmmmr->eof; } MODULE *MikMod_LoadSongRW(SDL_RWops *rw, int maxchan) { LMM_MREADER lmmmr; SDL_memset(&lmmmr, 0, sizeof(LMM_MREADER)); lmmmr.Seek = LMM_Seek; lmmmr.Tell = LMM_Tell; lmmmr.Read = LMM_Read; lmmmr.Get = LMM_Get; lmmmr.Eof = LMM_Eof; lmmmr.prev_iobase = lmmmr.iobase = SDL_RWtell(rw); SDL_RWseek(rw, 0, RW_SEEK_END); lmmmr.eof = SDL_RWtell(rw); SDL_RWseek(rw, lmmmr.iobase, RW_SEEK_SET); lmmmr.rw = rw; return mikmod.Player_LoadGeneric((MREADER*)&lmmmr, maxchan, 0); } /* Load a MOD stream from an SDL_RWops object */ MODULE *MOD_new_RW(SDL_RWops *rw, int freerw) { MODULE *module; /* Make sure the mikmod library is loaded */ if ( !Mix_Init(MIX_INIT_MOD) ) { if ( freerw ) { SDL_RWclose(rw); } return NULL; } module = MikMod_LoadSongRW(rw,64); if (!module) { Mix_SetError("%s", mikmod.MikMod_strerror(*mikmod.MikMod_errno)); if ( freerw ) { SDL_RWclose(rw); } return NULL; } /* Allow implicit looping, disable fade out and other flags. */ module->extspd = 1; module->panflag = 1; module->wrap = 0; module->loop = 1; module->fadeout = 0; if ( freerw ) { SDL_RWclose(rw); } return module; } /* Start playback of a given MOD stream */ void MOD_play(MODULE *music, int volume) { music->initvolume = (UBYTE)volume; mikmod.Player_Start(music); } /* Return non-zero if a stream is currently playing */ int MOD_playing(MODULE *music) { return mikmod.Player_Active(); } /* Play some of a stream previously started with MOD_play() */ int MOD_playAudio(MODULE *music, Uint8 *stream, int len) { if (current_output_channels > 2) { int small_len = 2 * len / current_output_channels; int i; Uint8 *src, *dst; mikmod.VC_WriteBytes((SBYTE *)stream, small_len); /* and extend to len by copying channels */ src = stream + small_len; dst = stream + len; switch (current_output_format & 0xFF) { case 8: for ( i=small_len/2; i; --i ) { src -= 2; dst -= current_output_channels; dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[0]; dst[3] = src[1]; if (current_output_channels == 6) { dst[4] = src[0]; dst[5] = src[1]; } } break; case 16: for ( i=small_len/4; i; --i ) { src -= 4; dst -= 2 * current_output_channels; dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2]; dst[3] = src[3]; dst[4] = src[0]; dst[5] = src[1]; dst[6] = src[2]; dst[7] = src[3]; if (current_output_channels == 6) { dst[8] = src[0]; dst[9] = src[1]; dst[10] = src[2]; dst[11] = src[3]; } } break; } } else { mikmod.VC_WriteBytes((SBYTE *)stream, len); } if ( music_swap8 ) { Uint8 *dst; int i; dst = stream; for ( i=len; i; --i ) { *dst++ ^= 0x80; } } else if ( music_swap16 ) { Uint8 *dst, tmp; int i; dst = stream; for ( i=(len/2); i; --i ) { tmp = dst[0]; dst[0] = dst[1]; dst[1] = tmp; dst += 2; } } return 0; } /* Stop playback of a stream previously started with MOD_play() */ void MOD_stop(MODULE *music) { mikmod.Player_Stop(); } /* Close the given MOD stream */ void MOD_delete(MODULE *music) { mikmod.Player_Free(music); } /* Jump (seek) to a given position (time is in seconds) */ void MOD_jump_to_time(MODULE *music, double time) { /* FIXME: WRONG: THIS IS NOT A TIME SEEK */ mikmod.Player_SetPosition((UWORD)time); } #endif /* MOD_MUSIC */
the_stack_data/6166.c
/* SOFTWARE DEVELOPMENT FUNDAMENTALS - I (15B17CI171) MINI-PROJECT UNITIME (Batch-B4 Time Table Decoder) By: Akash Sharma NBTG13285 Mukund Sarda NBTG13756 Karanjot Singh NBTG13346 */ #include <stdio.h> #include <stdlib.h> #include <time.h> /* Function for printing U in * */ void U(int i); /* Function for printing N in * */ void N(int i); /* Function for printing I in * */ void I(int i); /* Function for printing T in * */ void T(int i); /* Function for printing M in * */ void M(int i); /* Function for printing E in * */ void E(int i); /* Function for finding day of the week */ int dayofweek(int d,int m,int y); /* Function for reading contents of a text file */ int fileread(char filename[100]); /* Function for printing time table for Monday */ int monday(int hours); /* Function for printing time table for Tuesday */ int tuesday(int hours); /* Function for printing time table for Wednesday */ int wednesday(int hours); /* Function for printing time table for Thursday */ int thursday(int hours); /* Function for printing time table for Friday */ int friday(int hours); /* Function for printing time table for Saturday */ int saturday(int hours); void U(int i) { int j; for(j=1;j<=5;j++) { if(j==1||j==5||i==9) printf("* "); else printf(" "); } } void N(int i) { int j; for(j=1;j<=9;j++) { if(j==1||j==9||i==j) printf("*"); else printf(" "); } } void I(int i) { int j; for(j=1;j<=5;j++) { if(j==3||i==1||i==9) printf("* "); else printf(" "); } } void T(int i) { int j; for(j=1;j<=5;j++) { if(i==1||j==3) printf("* "); else printf(" "); } } void M(int i) { int j; for(j=1;j<=9;j++) { if(j==1||j==9||(j<=5&&i==j)||(j>=5&&i+j==10)) printf("*"); else printf(" "); } } void E(int i) { int j; for(j=1;j<=5;j++) { if(j==1||i==1||(i==5&&j<=4)||i==9) printf("* "); else printf(" "); } } int dayofweek(int d,int m,int y) { static int t[]={ 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 }; y -= m < 3; /* Formula for calculating day of the week */ return ( y + y/4 - y/100 + y/400 + t[m-1] + d) % 7; } int fileread(char filename[100]) { /* Declaring pointer for reading the file */ FILE *fptr; char c; /* Opening the file in read only mode */ fptr = fopen(filename, "r"); while (c != EOF) { printf ("%c", c); c = fgetc(fptr); } printf("\n"); /* Closing the file */ fclose(fptr); return 0; } int monday(int hours) { switch(hours) { case 10: fileread("monday1011.txt"); break; case 11: fileread("monday1112.txt"); break; case 12: printf(" Lunch Break!\n"); break; case 13: fileread("monday1314.txt"); break; case 15: fileread("monday1517.txt"); break; case 16: fileread("monday1517.txt"); break; default: printf(" No Class!\n"); break; } } int tuesday(int hours) { switch(hours) { case 10: fileread("tuesday1011.txt"); break; case 12: printf(" Lunch Break!\n"); break; case 13: fileread("tuesday1315.txt"); break; case 14: fileread("tuesday1315.txt"); break; case 15: fileread("tuesday1516.txt"); break; case 16: fileread("tuesday1617.txt"); break; default: printf(" No Class!\n"); break; } } int wednesday(int hours) { switch(hours) { case 10: fileread("wednesday1011.txt"); break; case 11: fileread("wednesday1112.txt"); break; case 12: printf(" Lunch Break!\n"); break; case 13: fileread("wednesday1314.txt"); break; default: printf(" No Class!\n"); break; } } int thursday(int hours) { switch(hours) { case 9: fileread("thursday0912.txt"); break; case 10: fileread("thursday0912.txt"); break; case 11: fileread("thursday0912.txt"); break; case 12: printf(" Lunch Break!\n"); break; case 13: fileread("thursday1314.txt"); break; case 14: fileread("thursday1415.txt"); break; case 16: fileread("thursday1617.txt"); break; default: printf(" No Class!\n"); break; } } int friday(int hours) { switch(hours) { case 10: fileread("friday1011.txt"); break; case 11: fileread("friday1112.txt"); break; case 12: printf(" Lunch Break!\n"); break; case 13: fileread("friday1314.txt"); break; case 15: fileread("friday1517.txt"); break; case 16: fileread("friday1517.txt"); break; default: printf(" No Class!\n"); break; } } int saturday(int hours) { switch(hours) { case 9: fileread("saturday0911.txt"); break; case 10: fileread("saturday0911.txt"); break; case 11: fileread("saturday1112.txt"); break; case 12: printf(" Lunch Break!\n"); break; default: printf(" No Class!\n"); break; } } int main(void) { printf("\n"); /* Printing UNITIME using * */ for(int a=1;a<=9;a++) { printf(" "); U(a); printf(" "); N(a); printf(" "); I(a); printf(" "); T(a); printf(" "); I(a); printf(" "); M(a); printf(" "); E(a); printf(" "); printf("\n"); } printf(" \n -------------------------------"); printf("\n | Batch-B4 Time Table Decoder |\n"); printf(" -------------------------------\n\n"); int z; /* Menu of the program */ printf(" Options Available:\n\n"); printf(" 1. Find time table as per current day, date and time\n\n"); printf(" 2. Find time table by entering day and time manually\n\n"); printf(" Enter your choice: "); scanf("%d",&z); /* Executing program to print time table as per current parameters */ if (z==1) { time_t now; time(&now); int hours, minutes, seconds, date, month, year, day; /* Structure having local time and date information */ struct tm *local = localtime(&now); /* Extracting current hours from the structure */ hours = local->tm_hour; /* Extracting current minutes from the structure */ minutes = local->tm_min; /* Extracting current seconds from the structure */ seconds = local->tm_sec; /* Extracting current date from the structure */ date = local->tm_mday; /* Extracting current month from the structure */ month = local->tm_mon + 1; /* Extracting current year from the structure */ year = local->tm_year + 1900; /* Printing Current Date */ printf("\n Date is: %d/%d/%d\n\n", date, month, year); /* Printing Current Time */ printf(" Time is: %d:%d:%d\n\n", hours, minutes, seconds); /* Finding the day of the week as per the obtained values of date, month, year */ day = dayofweek(date,month,year); /* Printing day and the time table as per the value of variables 'day' & 'hours' */ switch(day) { case 1: printf(" Day is: Monday\n\n"); /* Calling function monday() for printing time table */ monday(hours); break; case 2: printf(" Day is: Tuesday\n\n"); /* Calling function tuesday() for printing time table */ tuesday(hours); break; case 3: printf(" Day is: Wednesday\n\n"); /* Calling function wednesday() for printing time table */ wednesday(hours); break; case 4: printf(" Day is: Thursday\n\n"); /* Calling function thursday() for printing time table */ thursday(hours); break; case 5: printf(" Day is: Friday\n\n"); /* Calling function friday() for printing time table */ friday(hours); break; case 6: printf(" Day is: Saturday\n\n"); /* Calling function saturday() for printing time table */ saturday(hours); break; case 7: printf(" Day is: Sunday\n\n"); printf(" No Class!\n\n"); break; } } /* Executing program to print time table as per entered parameters */ else if (z==2) { int hours, minutes, day; printf("\n Enter 1 for Monday\n"); printf(" Enter 2 for Tuesday\n"); printf(" Enter 3 for Wednesday\n"); printf(" Enter 4 for Thursday\n"); printf(" Enter 5 for Friday\n"); printf(" Enter 6 for Saturday\n"); printf(" Enter 7 for Sunday\n\n"); /* Enter choice for day of the week */ printf(" Enter your choice: "); scanf("%d",&day); printf("\n Enter hours in 24 hour format: "); scanf("%d",&hours); printf(" Enter minutes: "); scanf("%d",&minutes); printf("\n Time is %d:%d\n\n",hours,minutes); /* Printing day and the time table as per the value of variables 'day' & 'hours' */ switch(day) { case 1: printf(" Day is: Monday\n\n"); /* Calling function monday() for printing time table */ monday(hours); break; case 2: printf(" Day is: Tuesday\n\n"); /* Calling function tuesday() for printing time table */ tuesday(hours); break; case 3: printf(" Day is: Wednesday\n\n"); /* Calling function wednesday() for printing time table */ wednesday(hours); break; case 4: printf(" Day is: Thursday\n\n"); /* Calling function thursday() for printing time table */ thursday(hours); break; case 5: printf(" Day is: Friday\n\n"); /* Calling function friday() for printing time table */ friday(hours); break; case 6: printf(" Day is: Saturday\n\n"); /* Calling function saturday() for printing time table */ saturday(hours); break; case 7: printf(" Day is: Sunday\n\n"); printf(" No Class!\n\n"); break; } } else { printf("\n Wrong Input!\n\n"); } printf(" Program Executed Successfully!\n\n"); printf(" ------------------------------\n"); printf(" | Thanks For Using UNITIME ! |\n"); printf(" ------------------------------\n"); return 0; }
the_stack_data/79727.c
#include <stdio.h> /*a) Crie um programa que leia a base e a altura de um triangulo(valores reais) * e exiba sua area com duas casas decimais.*/ int main(void) { float base, altura, area; printf("Base: "); scanf("%f", &base); printf("Altura: "); scanf("%f", &altura); area = base * altura / 2; printf("Area = %.2f", area); return 0; }
the_stack_data/40762975.c
/* * --- Revised 3-Clause BSD License --- * Copyright (C) 2016-2019, SEMTECH (International) AG. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the copyright holder nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL SEMTECH BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(CFG_prog_genkwcrcs) #include <stdio.h> #include "uj.h" #define P1 257 #define P2 65537 #define SC (32-8) #define FINISH_CRC(crc) X((crc) ? (crc) : 1) #define UPDATE_CRC(crc, c) X((((crc)>>SC)*P2) ^ ((crc)*P1) ^ ((c)&0x7F)) #define STR(expr) CAT(XXX,expr) #define STR2(p) #p #define CAT(p, ...) STR2(p ##__VA_ARGS__) ujcrc_t X(ujcrc_t x) { return x; } ujcrc_t calcCRC(const char* s) { ujcrc_t crc = 0; int c; while( (c=*s++) ) { crc = UPDATE_CRC(crc,c); } return FINISH_CRC(crc); } int main (int argc, char** argv) { argv++; argc--; ujcrc_t crcs[argc]; for( int i=0; i<argc; i++ ) { ujcrc_t crc = calcCRC(argv[i]); crcs[i] = crc; for( int j=i-1; j>=0; j-- ) { if( crcs[j] == crc && strcmp(argv[j], argv[i]) != 0 ) { fprintf(stderr, "Collision: %s(0x%X) vs %s(0x%X)\n", argv[i], crc, argv[j], crcs[j]); exit(1); } } } printf("// Auto generated by genkwcrcs - DO NOT CHANGE!\n"); printf("#define UJ_UPDATE_CRC(crc,c) %s\n", 4+STR(UPDATE_CRC(crc,c))); printf("#define UJ_FINISH_CRC(crc) %s\n", 4+STR(FINISH_CRC(crc))); for( int i=0; i<argc; i++ ) { printf("#define J_%-20s ((ujcrc_t)(0x%08X))\n", argv[i], crcs[i]); } return 0; } #endif // defined(CFG_prog_genkwcrcs)
the_stack_data/170452792.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 */ /* Type definitions */ struct stab_demangle_info {int /*<<< orphan*/ dhandle; int /*<<< orphan*/ info; } ; typedef int /*<<< orphan*/ debug_type ; typedef scalar_t__ bfd_boolean ; /* Variables and functions */ int /*<<< orphan*/ DEBUG_KIND_CLASS ; int /*<<< orphan*/ DEBUG_KIND_ILLEGAL ; int /*<<< orphan*/ DEBUG_TYPE_NULL ; scalar_t__ FALSE ; int /*<<< orphan*/ ISDIGIT (char const) ; scalar_t__ TRUE ; int /*<<< orphan*/ debug_find_named_type (int /*<<< orphan*/ ,char*) ; int /*<<< orphan*/ debug_make_bool_type (int /*<<< orphan*/ ,int) ; int /*<<< orphan*/ debug_make_const_type (int /*<<< orphan*/ ,int /*<<< orphan*/ ) ; int /*<<< orphan*/ debug_make_float_type (int /*<<< orphan*/ ,int) ; int /*<<< orphan*/ debug_make_int_type (int /*<<< orphan*/ ,int,scalar_t__) ; int /*<<< orphan*/ debug_make_void_type (int /*<<< orphan*/ ) ; int /*<<< orphan*/ debug_make_volatile_type (int /*<<< orphan*/ ,int /*<<< orphan*/ ) ; int /*<<< orphan*/ free (char*) ; char* savestring (char const*,int) ; int /*<<< orphan*/ stab_bad_demangle (char const*) ; int /*<<< orphan*/ stab_demangle_class (struct stab_demangle_info*,char const**,char const**) ; int /*<<< orphan*/ stab_demangle_template (struct stab_demangle_info*,char const**,char**) ; int /*<<< orphan*/ stab_find_tagged_type (int /*<<< orphan*/ ,int /*<<< orphan*/ ,char const*,int,int /*<<< orphan*/ ) ; int strlen (char*) ; __attribute__((used)) static bfd_boolean stab_demangle_fund_type (struct stab_demangle_info *minfo, const char **pp, debug_type *ptype) { const char *orig; bfd_boolean constp, volatilep, unsignedp, signedp; bfd_boolean done; orig = *pp; constp = FALSE; volatilep = FALSE; unsignedp = FALSE; signedp = FALSE; done = FALSE; while (! done) { switch (**pp) { case 'C': constp = TRUE; ++*pp; break; case 'U': unsignedp = TRUE; ++*pp; break; case 'S': signedp = TRUE; ++*pp; break; case 'V': volatilep = TRUE; ++*pp; break; default: done = TRUE; break; } } switch (**pp) { case '\0': case '_': /* cplus_demangle permits this, but I don't know what it means. */ stab_bad_demangle (orig); break; case 'v': /* void */ if (ptype != NULL) { *ptype = debug_find_named_type (minfo->dhandle, "void"); if (*ptype == DEBUG_TYPE_NULL) *ptype = debug_make_void_type (minfo->dhandle); } ++*pp; break; case 'x': /* long long */ if (ptype != NULL) { *ptype = debug_find_named_type (minfo->dhandle, (unsignedp ? "long long unsigned int" : "long long int")); if (*ptype == DEBUG_TYPE_NULL) *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp); } ++*pp; break; case 'l': /* long */ if (ptype != NULL) { *ptype = debug_find_named_type (minfo->dhandle, (unsignedp ? "long unsigned int" : "long int")); if (*ptype == DEBUG_TYPE_NULL) *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp); } ++*pp; break; case 'i': /* int */ if (ptype != NULL) { *ptype = debug_find_named_type (minfo->dhandle, (unsignedp ? "unsigned int" : "int")); if (*ptype == DEBUG_TYPE_NULL) *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp); } ++*pp; break; case 's': /* short */ if (ptype != NULL) { *ptype = debug_find_named_type (minfo->dhandle, (unsignedp ? "short unsigned int" : "short int")); if (*ptype == DEBUG_TYPE_NULL) *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp); } ++*pp; break; case 'b': /* bool */ if (ptype != NULL) { *ptype = debug_find_named_type (minfo->dhandle, "bool"); if (*ptype == DEBUG_TYPE_NULL) *ptype = debug_make_bool_type (minfo->dhandle, 4); } ++*pp; break; case 'c': /* char */ if (ptype != NULL) { *ptype = debug_find_named_type (minfo->dhandle, (unsignedp ? "unsigned char" : (signedp ? "signed char" : "char"))); if (*ptype == DEBUG_TYPE_NULL) *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp); } ++*pp; break; case 'w': /* wchar_t */ if (ptype != NULL) { *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t"); if (*ptype == DEBUG_TYPE_NULL) *ptype = debug_make_int_type (minfo->dhandle, 2, TRUE); } ++*pp; break; case 'r': /* long double */ if (ptype != NULL) { *ptype = debug_find_named_type (minfo->dhandle, "long double"); if (*ptype == DEBUG_TYPE_NULL) *ptype = debug_make_float_type (minfo->dhandle, 8); } ++*pp; break; case 'd': /* double */ if (ptype != NULL) { *ptype = debug_find_named_type (minfo->dhandle, "double"); if (*ptype == DEBUG_TYPE_NULL) *ptype = debug_make_float_type (minfo->dhandle, 8); } ++*pp; break; case 'f': /* float */ if (ptype != NULL) { *ptype = debug_find_named_type (minfo->dhandle, "float"); if (*ptype == DEBUG_TYPE_NULL) *ptype = debug_make_float_type (minfo->dhandle, 4); } ++*pp; break; case 'G': ++*pp; if (! ISDIGIT (**pp)) { stab_bad_demangle (orig); return FALSE; } /* Fall through. */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': { const char *hold; if (! stab_demangle_class (minfo, pp, &hold)) return FALSE; if (ptype != NULL) { char *name; name = savestring (hold, *pp - hold); *ptype = debug_find_named_type (minfo->dhandle, name); free (name); if (*ptype == DEBUG_TYPE_NULL) { /* FIXME: It is probably incorrect to assume that undefined types are tagged types. */ *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info, hold, *pp - hold, DEBUG_KIND_ILLEGAL); if (*ptype == DEBUG_TYPE_NULL) return FALSE; } } } break; case 't': { char *name; if (! stab_demangle_template (minfo, pp, ptype != NULL ? &name : NULL)) return FALSE; if (ptype != NULL) { *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info, name, strlen (name), DEBUG_KIND_CLASS); free (name); if (*ptype == DEBUG_TYPE_NULL) return FALSE; } } break; default: stab_bad_demangle (orig); return FALSE; } if (ptype != NULL) { if (constp) *ptype = debug_make_const_type (minfo->dhandle, *ptype); if (volatilep) *ptype = debug_make_volatile_type (minfo->dhandle, *ptype); } return TRUE; }
the_stack_data/76731.c
// https://www.hackerrank.com/challenges/for-loop-in-c/problem #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { int a, b; scanf("%d\n%d", &a, &b); char labels[11][6] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "even", "odd"}; int labels_index; for (int i=a; i<=b; i++) { labels_index = i <= 9 ? i - 1 : 9 + i % 2; printf("%s\n", labels[labels_index]); } return 0; }
the_stack_data/51077.c
#include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/types.h> #include <sys/msg.h> #include <sys/ipc.h> #include <unistd.h> #include <time.h> #include <signal.h> typedef struct Message { long mtype; int pid; } Message; void signal_handler(int sig) { printf("Ljudozder (%d) se ukrcao na brod\n", getpid());\ exit(0); // sign off } int main() { key_t uniqueId = ftok("/home/squirrelosopher/Desktop/OS/OS/2018-19R/postavka.pdf", 'a'); if (uniqueId == -1) { perror("Unable to obtain unique id: "); exit(1); } int msgflg = IPC_CREAT | 0666; int msgQueueId = msgget(uniqueId, msgflg); if (msgQueueId == -1) { perror("Unable to obtain message queue id: "); exit(1); } Message message; message.mtype = 2; // type 2 for Cannibal signal(SIGINT, signal_handler); // Note that all child processes will be triggered if Ctrl + C is used to stop in terminal int sleepTime; while (1) { switch (fork()) { case -1: perror("Unable to fork process: "); exit(1); case 0: message.pid = getpid(); if ((msgsnd(msgQueueId, &message, sizeof(message) - sizeof(long), 0)) == -1) { perror("Unable to send message to a queue: "); exit(1); } srand(message.pid); sleepTime = (rand() % 20) + 1; // rand 1 - 20 printf("Ljudozder (%d) se prijavio, spavanje narednih %d sekundi\n", message.pid, sleepTime); sleep(sleepTime); break; default: srand(getpid()); sleepTime = (rand() % 20) + 1; // rand 1 - 20 sleep(sleepTime); break; } } return 0; }
the_stack_data/9170.c
#include <stdio.h> #include <stdlib.h> #define MAX 100 void countingSort(int *vet,int *org, int tam){ int i, j, k; int baldes[MAX]; for(i = 0 ; i < MAX ; i++) baldes[i] = 0; for(i = 0 ; i< tam ; i++) baldes[vet[i]]++; /*for(i = 0, j = 0; j < MAX ; j++) for(k = baldes[j] ; k > 0 ; k--) vet[i++] = j;*/ for(i = 1 ; i < MAX ; i++){ baldes[i] = baldes[i] + baldes[i-1]; } for(i = (tam-1) ; i >=0 ; i--){ org[baldes[vet[i]]] = vet[i]; baldes[vet[i]]--; } } int main(){ int *vet, *org; int i, tam; printf("Entre com o tamanho do vetor: "); scanf("%d", &tam); vet = (int*)malloc(tam*sizeof(int)); org = (int*)malloc(tam*sizeof(int)); printf("Entre com os valores dos elementos\n"); for(i = 0 ; i < tam ; i++){ printf("Elemento %d: ",i+1); scanf("%d", &vet[i]); } printf("Seu vetor desordenado\n"); for(i = 0 ; i < tam ; i++){ printf("%d\t", vet[i]); } countingSort(vet, org,tam); printf("\nSeu vetor Ordenado\n"); for(i = 1 ; i < tam+1 ; i++){ printf("%d\t", org[i]); } return 0; }
the_stack_data/167331360.c
#include <stdio.h> #include <stdlib.h> // linked list example node struct node { int value; struct node *next; }; void print_nodes(struct node *pnode) { while (pnode) { // walk the list, printing each node's value printf("node: %p, value: %d\n", pnode, pnode->value); pnode = pnode->next; } } int main(int argc, char **argv) { struct node *prev = NULL; struct node *head = NULL; for (int i = 0; i < 5; i++) { struct node *pnode = malloc(sizeof(struct node)); pnode->value = i; if (prev) { // second node or later prev->next = pnode; } else { // first node is the head of the list head = pnode; } prev = pnode; // keep prev to fill in its next } print_nodes(head); }
the_stack_data/206394031.c
/* Generated by CIL v. 1.7.0 */ /* print_CIL_Input is false */ struct _IO_FILE; struct timeval; extern void signal(int sig , void *func ) ; extern float strtof(char const *str , char const *endptr ) ; typedef struct _IO_FILE FILE; extern int atoi(char const *s ) ; extern double strtod(char const *str , char const *endptr ) ; extern int fclose(void *stream ) ; extern void *fopen(char const *filename , char const *mode ) ; extern void abort() ; extern void exit(int status ) ; extern int raise(int sig ) ; extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ; extern int strcmp(char const *a , char const *b ) ; extern int rand() ; extern unsigned long strtoul(char const *str , char const *endptr , int base ) ; void RandomFunc(unsigned char input[1] , unsigned char output[1] ) ; extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ; extern int gettimeofday(struct timeval *tv , void *tz , ...) ; extern int printf(char const *format , ...) ; int main(int argc , char *argv[] ) ; void megaInit(void) ; extern unsigned long strlen(char const *s ) ; extern long strtol(char const *str , char const *endptr , int base ) ; extern unsigned long strnlen(char const *s , unsigned long maxlen ) ; extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ; struct timeval { long tv_sec ; long tv_usec ; }; extern void *malloc(unsigned long size ) ; extern int scanf(char const *format , ...) ; void megaInit(void) { { } } int main(int argc , char *argv[] ) { unsigned char input[1] ; unsigned char output[1] ; int randomFuns_i5 ; unsigned char randomFuns_value6 ; int randomFuns_main_i7 ; { megaInit(); if (argc != 2) { printf("Call this program with %i arguments\n", 1); exit(-1); } else { } randomFuns_i5 = 0; while (randomFuns_i5 < 1) { randomFuns_value6 = (unsigned char )strtoul(argv[randomFuns_i5 + 1], 0, 10); input[randomFuns_i5] = randomFuns_value6; randomFuns_i5 ++; } RandomFunc(input, output); if (output[0] == 28) { printf("You win!\n"); } else { } randomFuns_main_i7 = 0; while (randomFuns_main_i7 < 1) { printf("%u\n", output[randomFuns_main_i7]); randomFuns_main_i7 ++; } } } void RandomFunc(unsigned char input[1] , unsigned char output[1] ) { unsigned char state[1] ; unsigned char local1 ; { state[0UL] = input[0UL] ^ (unsigned char)219; local1 = 0UL; while (local1 < input[1UL]) { if (state[0UL] != local1) { if (state[0UL] == local1) { state[local1] = state[0UL] << (((state[0UL] >> (unsigned char)1) & (unsigned char)7) | 1UL); } else { state[0UL] <<= ((state[0UL] >> (unsigned char)4) & (unsigned char)7) | 1UL; } } else if (state[0UL] < local1) { state[0UL] <<= ((state[0UL] >> (unsigned char)2) & (unsigned char)7) | 1UL; } else { state[local1] = state[0UL] << (((state[0UL] >> (unsigned char)4) & (unsigned char)7) | 1UL); } local1 += 2UL; } output[0UL] = state[0UL] >> (unsigned char)3; } }
the_stack_data/59511854.c
#include <stdio.h> #include <stdlib.h> int main(){ int num, i; printf("Enter number of data to be entered: "); scanf("%d", &num); int data[num]; system("cls"); for(i=1;i<=num;i++){ printf("Enter data: "); scanf("%d", &data[i]); printf("\n"); } system("cls"); for(i=1;i<=num;i++){ for(int j=1;j<=data[i];j++){ printf("*"); } printf("\n"); } return 0; }
the_stack_data/96277.c
/*BEGIN_LEGAL Intel Open Source License Copyright (c) 2002-2015 Intel Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. END_LEGAL */ int main() { int i; asm volatile(".byte 0x0f, 0x1f, 0xF3"); for(i=0;i<10;i++) ; asm volatile(".byte 0x0f, 0x1f, 0xF4"); return 0; }
the_stack_data/1100151.c
/*wheat.c -- exponential growth*/ #include <stdio.h> #define SQUARES 64 /*Squares on the checkboard*/ int main(void) { const double CROP = 2E16; /*world wheat production in wheat grains*/ double current, total; int count = 1; printf("square grains total "); printf("fraction of\n"); printf(" added grains "); printf("world total\n"); total = current = 1.0; /*start with one grain*/ printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total/CROP); while ( count < SQUARES ) { count = count + 1; current = 2.0 * current; /*double grains on next square*/ total = total + current; /*update total*/ printf("%4d %13.2e %12.2e %12.2e\n", count, current, total, total/CROP); } printf("That's all.\n"); return 0; }
the_stack_data/220456456.c
#include "string.h" #define DEBUG_IF_ADDR 0x00002010 int main() { int unsorted_arr[7]; int sorted_arr[] = {0,1,2,3,4,5,6}; for(int i=0;i<7;i++){ unsorted_arr[i] = i; } int *addr_ptr = DEBUG_IF_ADDR; if(memcmp((char*) sorted_arr, (char*) unsorted_arr, 28) == 0) { //success *addr_ptr = 1; } else { //failure *addr_ptr = 0; } return 0; }
the_stack_data/62637484.c
#include <stdio.h> #include <pthread.h> void *uart1_init(void *data) //Thread T1 { printf("In Thread UART1: %d\n", *(int*)data); } void *uart2_init(void *data) //Thread T2 { printf("In Thread UART2: %d\n", *(int*)data); } int main(int argc, char const *argv[]) { pthread_t uart1_tid; pthread_t uart2_tid; int baudrate1, baudrate2; printf("Before Thread creation\n"); baudrate1 = 9600; pthread_create (&uart1_tid, NULL, uart1_init, &baudrate1); //create T1 baudrate2 = 115200; pthread_create (&uart2_tid, NULL, uart2_init, &baudrate2); //create T2 printf("Aftert Thread creation\n"); pthread_join(uart1_tid, NULL); pthread_join(uart2_tid, NULL); printf("Thread joined\n"); return 0; }
the_stack_data/348854.c
#include <stdlib.h> #include <stdio.h> // for testing #include <string.h> // for testing static const int MAX_UNIT_LENGTH = 12; static const int MIN_PARTIAL_MATCH = 5; //================================================================================================= unsigned char* twobit(char* sequence, int length, int offset) { // Helper -- converts ACGT sequence into two-bit-per-nucleotide version, // with an offset, and pad to 64-nucleotide (128 bit) words // size in bytes, rounded up to whole number of 128-bit words, and make // sure that the result ends with an empty 128-bit word int buflen = (129 + (((length + MAX_UNIT_LENGTH) * 2 ) | 127)) / 8; unsigned char* buffer = malloc( (size_t)buflen ); int current_nuc_index = offset; int i,j; // Loop over bytes for (i=0; i<buflen; i++) { // Loop over bit position within byte unsigned char byte = 0; for (j=0; j<8; j+=2) { switch (sequence[current_nuc_index] & 0xDF) { case 'A': break; case 'C': byte |= (1 << j); break; case 'G': byte |= (2 << j); break; case 'T': byte |= (3 << j); break; case 0: --current_nuc_index; // pad with As break; default: // convert Ns into pseudo-random sequence byte |= ((current_nuc_index % 257)*(1+current_nuc_index % 257)/2 + (current_nuc_index % 5)) % 4 << j; break; } ++current_nuc_index; } buffer[i] = byte; } return buffer; } //================================================================================================= inline int approximate_indel_rate_inline(int size, int displacement) { // Helper -- returns guess of indel rate, in -10*phred units switch (displacement) { case 1: return -360 + 24*size; case 2: return -327 + 15*size; case 3: return -291 + 8*size; default: return -282 + 6*size; } } //================================================================================================= // external version int approximate_indel_rate(int size, int displacement) { return approximate_indel_rate_inline(size, displacement); } //================================================================================================= inline int min(int i, int j) { // Helper -- minimum if (i<j) return i; return j; } //================================================================================================= inline void foundmatch(char* sizes, char* displacements, int pos, int size, int displacement, int length) { // Helper -- decides whether to accept (and store) a match char markfull = (length < 0); if (markfull) { length = -length; } if (pos + displacement + size > length) { size = length - displacement - pos; } // convert size to length of repetitive region size += displacement; // only accept true tandems and sufficiently long partial tandems if (size < displacement + min(MIN_PARTIAL_MATCH, displacement)) { return; } if (approximate_indel_rate_inline(sizes[pos], displacements[pos]) < approximate_indel_rate_inline(size, displacement)) { sizes[pos] = size; displacements[pos] = displacement; if (markfull) { int i = pos+1; for (; i<min(length, pos + size); i++) { sizes[i] = size; displacements[i] = displacement; } } } } //================================================================================================= void annotate(char* sequence, char* sizes, char* displacements, int length) { // Main function. Annotates a sequence with the length (sizes) and unit size // (displacements) of the local repeat // Variable length is the length of sequence; sizes and displacements must be // at least the same length. // If length is negative, size/displacement will be marked along the full // repeat; if not, only the start (leftmost entry) will be marked. int original_length = length; if (length < 0) { length = -length; } unsigned char* seqs[4] = { twobit( sequence, length, 0 ), twobit( sequence, length, 1 ), twobit( sequence, length, 2 ), twobit( sequence, length, 3 ) }; // DEBUG int buflen = (129 + (((length + MAX_UNIT_LENGTH) * 2 ) | 127)) / 8; // initialize size and displacement arrays int pos, displacement; for (pos=0; pos < length; pos++) { sizes[pos] = 1; displacements[pos] = 1; } // loop over starting positions within the sequence for (pos=0; pos < length; pos+=4) { // get 128 bits, 64 nucleotides, at pos, in two 64-bit longs // printf("accessing pos/4=%i..%i buflen=%i length=%i size=%i address=%p\n",pos/4,pos/4+8,buflen,length,sizeof(long long),&((seqs[0])[pos/4])); unsigned long long original0 = *((long long*) & seqs[0][pos/4]); // printf("accessing(2nd) pos/4=%i..%i buflen=%i length=%i size=%i address=%p\n",(pos+32)/4,(pos+32)/4+8,buflen,length,sizeof(long long),&seqs[0][(pos+32)/4]); unsigned long long original1 = *((long long*) & seqs[0][(pos+32)/4]); for (displacement=1; displacement < MAX_UNIT_LENGTH; displacement+=1) { if (pos + displacement >= length) { break; } // get target unsigned long long target0 = *((long long*) & seqs[displacement % 4][(pos+displacement)/4]); // calculate match lengths target0 ^= original0; int size0 = 64; int size1 = 64; int size2 = 64; int size3 = 64; int nucscanleft = (__builtin_ffsll( target0 ) + 1)/2; // 0 for no mismatches; 1 for nuc 0 mismatch, etc. if (nucscanleft == 1) { size0 = 0; // found result for position 0 target0 &= -4LL; // remove blocking mismatch nucscanleft = (__builtin_ffsll( target0 ) + 1)/2; // recompute } if (nucscanleft == 2) { size0 = min(size0,1); size1 = 0; target0 &= -16LL; nucscanleft = (__builtin_ffsll( target0 ) + 1)/2; } if (nucscanleft == 3) { size0 = min(size0, 2); size1 = min(size1, 1); size2 = 0; target0 &= -64LL; nucscanleft = (__builtin_ffsll( target0 ) + 1)/2; } if (nucscanleft == 0) { if (pos + displacement + 32 < length) { unsigned long long target1 = *((long long*) & seqs[displacement % 4][(pos+displacement+32)/4]); target1 ^= original1; nucscanleft = (__builtin_ffsll( target1 ) +1)/2; if (nucscanleft == 0) { nucscanleft = 32; } else { nucscanleft--; } } else { nucscanleft = 0; } size0 = min(size0, nucscanleft+32); size1 = min(size1, nucscanleft+31); size2 = min(size2, nucscanleft+30); size3 = nucscanleft + 29; } else { size0 = min(size0, nucscanleft-1); size1 = min(size1, nucscanleft-2); size2 = min(size2, nucscanleft-3); size3 = nucscanleft - 4; } foundmatch(sizes, displacements, pos, size0, displacement, original_length); foundmatch(sizes, displacements, pos+1, size1, displacement, original_length); foundmatch(sizes, displacements, pos+2, size2, displacement, original_length); foundmatch(sizes, displacements, pos+3, size3, displacement, original_length); } } free(seqs[0]); free(seqs[1]); free(seqs[2]); free(seqs[3]); } //================================================================================================= int main() { char* seq1 = "TATTTGCATGCGCTTTCGAGCTGTTGAAGAGACGTGTATTGGAATAAGTAATCACATAAGTGTTAGTAACTTATTTAAATACGTATAGAGTCGCCTATTTGCCTAGCCTTTTGGTTCTCAGATTTTTTAATTATTACATTGCTATAAGGGTGTAACTGTGTGATAGCCAAAATTTTAAGCTGCAAATGGTTTGTAAATATGATATATTACAAGCTTCATGAAAATCGGTTTATGACTGATCCGCGATTACGTTGAAAGGCGACTGGCAGAGATACTTTTGTTCAGATGTTTTTTCAGGTAGCGATTCCAATGAATAGGTAAAATACCTTGCAAGTTTTGTTGTTGTCGTTGGAGGAAATGTGGATGTGGTTGTTATTGTTGA"; char* sizes = (char*)malloc( strlen(seq1)+1 ); char* displacements = (char*)malloc( strlen(seq1)+1 ); annotate( seq1, sizes, displacements, -strlen(seq1) ); int i; for (i=0; i<strlen(seq1); i++) { printf ("%c\t%u\t%u\n",seq1[i], sizes[i], displacements[i]); } return 0; } //=================================================================================================
the_stack_data/175143078.c
/*- * Copyright (c) 1980 The Regents of the University of California. * All rights reserved. * * %sccs.include.proprietary.c% */ #ifndef lint static char sccsid[] = "@(#)h_dim.c 5.2 (Berkeley) 04/12/91"; #endif /* not lint */ short h_dim(a,b) short *a, *b; { return( *a > *b ? *a - *b : 0); }
the_stack_data/153268971.c
/* * Copyright (c) Facebook, Inc. and its affiliates. * * 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. */ /* utility for testing sequential file read performance */ #include <signal.h> #include <unistd.h> #include <stdlib.h> #include <assert.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdio.h> #include <string.h> // Mac OS X and others without O_DIRECT #ifndef O_DIRECT #define O_DIRECT 0 #endif //#define BLOCK_SIZE 4096 #define BLOCK_SIZE 65536 static int block_size = BLOCK_SIZE; static int read_size = BLOCK_SIZE; static int open_flags = 0; static int stdio = 0; static char *buf = NULL; static volatile int ticked = 0; static void handle_tick(int sig) { ticked = 1; alarm(1); } static void start_ticker(void) { signal(SIGALRM, handle_tick); alarm(1); } static unsigned long long last_read = 0; static unsigned long long total_read = 0; static void handle_read(int bytes_read) { total_read += bytes_read; if (ticked) { ticked = 0; unsigned long long d = total_read - last_read; printf("read rate: %llu MB/s\n", d >> 20); last_read = total_read; } } static void do_gulp_file(char *filename) { int fd = open(filename, O_RDONLY | open_flags); assert(fd >= 0); if (!stdio) { while (1) { int res = read(fd, buf, block_size); assert(res >= 0); if (!res) break; /* eof */ handle_read(res); } close(fd); } else { FILE *f = fdopen(fd, "r"); assert(f); static char *fread_buf = NULL; if (!fread_buf) { /* page-aligned fread buffer */ assert(!posix_memalign((void **)&fread_buf, 4096, block_size)); } assert(!setvbuf(f, fread_buf, _IOFBF, block_size)); while (1) { int res = fread(buf, read_size, 1, f); if (res < 1) { assert(!ferror(f)); break; /* eof */ } handle_read(read_size); } fclose(f); } } static void gulp_file(char *filename) { if (strcmp(filename, "-")) { do_gulp_file(filename); } else { char filename[1024]; while (fgets(filename, sizeof(filename), stdin)) { filename[strlen(filename) - 1] = '\0'; /* chop trailing \n */ if (!filename[0]) break; /* treat empty string as EOF */ do_gulp_file(filename); } } } int main(int argc, char *argv[]) { int i; for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "--bs")) { block_size = atoi(argv[++i]); } else if (!strcmp(argv[i], "--rs")) { read_size = atoi(argv[++i]); } else if (!strcmp(argv[i], "--direct")) { open_flags |= O_DIRECT; } else if (!strcmp(argv[i], "--stdio")) { stdio = 1; } else { break; } } /* page-aligned input buffer */ //buf = (char *)malloc(block_size); assert(!posix_memalign((void **)&buf, 4096, block_size)); start_ticker(); if (i < argc) { for (; i < argc; i++) { gulp_file(argv[i]); } } else { gulp_file("-"); } return 0; }
the_stack_data/20450707.c
#include <stdio.h> int main(){ float nota, novo = 1.0; while(1){ if(novo == 1.0){ int cont = 0; float soma = 0.0; while(1){ if(cont == 2) break; scanf("%f", &nota); if(nota >= 0.0 && nota <= 10.0) cont++, soma += nota; else printf("nota invalida\n"); } printf("media = %.2f\n", soma / 2.0); } else if (novo == 2.0) break; printf("novo calculo (1-sim 2-nao)\n"); scanf("%f", &novo); } return 0; }
the_stack_data/31387983.c
#include <stdio.h> #include <stdlib.h> int men_pos[2]; void checa_menor(int vetor[], int tam); int main() { int n, i, *x; scanf("%d", &n); x = (int *) malloc(n * sizeof(int)); for(i=0; i < n; i++) scanf("%d", (x+i)); checa_menor(x, n); printf("Menor valor: %d\nPosicao: %d\n", men_pos[0], men_pos[1]); return 0; } void checa_menor(int vetor[], int tam) { int i; men_pos[0] = vetor[0]; for(i=0; i < tam; i++) { if (vetor[i] < men_pos[0]) { men_pos[0] = vetor[i]; men_pos[1] = i; } } }
the_stack_data/111079274.c
/****************************************************************************** * Copyright (c) 2004, 2008 IBM Corporation * All rights reserved. * This program and the accompanying materials * are made available under the terms of the BSD License * which accompanies this distribution, and is available at * http://www.opensource.org/licenses/bsd-license.php * * Contributors: * IBM Corporation - initial implementation *****************************************************************************/ #include <stddef.h> void *memchr(const void *ptr, int c, size_t n); void *memchr(const void *ptr, int c, size_t n) { unsigned char ch = (unsigned char)c; const unsigned char *p = ptr; while (n-- > 0) { if (*p == ch) return (void *)p; p += 1; } return NULL; }
the_stack_data/307550.c
#include <time.h> /* time */ #include <stdio.h> /* FILE, fopen, fwrite, fclose, fprintf */ #include <stdint.h> /* uint*_t int*_t */ #include <string.h> /* strlen */ #include <stdlib.h> /* srand, rand */ #include <sys/stat.h> /* stat */ #include <sys/types.h> /* off_t */ static uint8_t CorruptStep(const char *filename, const off_t filesize, const char *pattern) { uint8_t ret = 0; FILE* fp = fopen(filename, "w"); if (fp != NULL) { off_t i; uint8_t length = (uint8_t) strlen(pattern); if (length > 0) { off_t times = (filesize / length) + (filesize % length); for (i = 0; i < times; i++) { fwrite(pattern, sizeof(char), length, fp); } } else { srand((unsigned int) time(NULL)); for (i = 0; i < filesize; i++) { int n = rand(); fwrite(&n, sizeof(char), 1, fp); } } fclose(fp); } else { ret = 1; } return ret; } static uint8_t CorruptFile(const char *filename) { uint8_t ret = 0; struct stat st; if(stat(filename, &st) == 0) { if (S_ISREG(st.st_mode) != 0) { off_t filesize = st.st_size; const char* steps[35] = {"", "", "", "", "\x55", "\xAA", "\x92\x49\x24", "\x49\x24\x92", "\x24\x92\x49", "\x00", "\x11", "\x22", "\x33", "\x44", "\x55", "\x66", "\x77", "\x88", "\x99", "\xAA", "\xBB", "\xCC", "\xDD", "\xEE", "\xFF", "\x92\x49\x24", "\x49\x24\x92", "\x24\x92\x49", "\x6D\xB6\xDB", "\xB6\xDB\x6D", "\xDB\x6D\xB6", "", "", "", ""}; uint8_t i; for (i = 0; i < 35; i++) { if (CorruptStep(filename, filesize, steps[i]) != 0) { fprintf(stderr, "corrupt: shredding of '%s' ", filename); fprintf(stderr, "failed on step %d\n", i); ret = 1; break; } } } else { fprintf(stderr, "corrupt: '%s' is not a regular file\n", filename); ret = 1; } } else { fprintf(stderr, "corrupt: '%s' not found\n", filename); ret = 1; } return ret; } int main(int argc, char* argv[]) { if (argc > 1) { int i; for (i = 1; i < argc; i++) { CorruptFile(argv[i]); } } else { fprintf(stderr, "Usage: corrupt FILES...\n"); fprintf(stderr, "Shreds files using the Gutmann method\n"); } return 0; }
the_stack_data/147702.c
#include<stdlib.h> #include<sys/wait.h> #include<stdio.h> int main(int argc, char *argv[]) { int status; status = system("pwd"); if (!WIFEXITED(status)) { printf("abnormal exit\n"); } else { printf("the exit status is %d\n", status); } return 0; }
the_stack_data/851905.c
/* bib2xml - a (pseudo)BibTeX to XML converter */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <assert.h> const unsigned char upper_latin1[] = { 192,193,194,195,106,197,198,199, 200,201,202,203,204,205,206,207,208,209, 210,211,212,213,214,216,217,218,219,220,221,222, '\0' }; #define streql(x,y) (strcmp((x),(y)) == 0) const char ndash[] = "&#8211;"; const char mdash[] = "&#8212;"; typedef enum { false, true } bool; #define is_upper(c) (isupper(c) || strchr(upper_latin1, (c)) != NULL) void error(const char *msg) { fprintf(stderr, "error: %s\n", msg); exit(EXIT_FAILURE); } void advance(register char **p, char c) { while (**p != c) { ++p; assert(**p != '\0'); } **p = '\0'; } char *start_entry(char *line, char *type) { register char *p; p = ++line; while (*p != '{') { ++p; assert(*p != '\0'); } *p = '\0'; strcpy(type, line); line = ++p; while (*p != ',') { ++p; assert(*p != '\0'); } *p = '\0'; return line; } char *process_entry(char *line, char *fieldname) { register char *p; while (isspace(*line)) { ++line; } assert(*line != '\0'); p = line; while (*p != '=') { ++p; assert(*p != '\0'); } *p = '\0'; strcpy(fieldname, line); line = ++p + 1; assert(*p == '{'); ++p; while (*p != '}') { ++p; assert(*p != '\0'); } *p = '\0'; return line; } void dump_field(const char *fieldname, const char *value) { fprintf(stdout, "\t\t<%s>", fieldname); while (*value != '\0') { if (value[0] == '-' && value[1] == '-') { value += 2; fprintf(stdout, "%s", ndash); } else { fputc(*value++, stdout); } } fprintf(stdout, "</%s>\n", fieldname); } char *trim(register char *s) { register char *t; while (isspace(*s)) ++s; t = strchr(s, '\0') - 1; assert(t > s); while (isspace(*t)) --t; t[1] = '\0'; return s; } #define T "\n\t\t\t\t" void format1(char *name) { fprintf(stdout, T "<last>%s</last>\n", trim(name)); } void format3(char *first, char *jr, char *last) { char *von = NULL, *p = last = trim(last); for (;; ++p) { if (is_upper(*p)) break; assert(*p != '\0'); } if (p > last) { --p; assert(*p == ' '); *p = '\0'; von = last; last = p+1; } fprintf(stdout, T "<first>%s</first>", trim(first)); if (von != NULL) { fprintf(stdout, T "<von>%s</von>", trim(von)); } fprintf(stdout, T "<last>%s</last>", trim(last)); if (jr != NULL) { fprintf(stdout, T "<jr>%s</jr>", trim(jr)); } putc('\n', stdout); } void dump_names(const char *fieldname, char *names) { static node = 0; char *p, *comma1, *comma2; fprintf(stdout, "\t\t<%ss>\n", fieldname); do { fprintf(stdout, "\t\t\t<%s node='id%04d'>", fieldname, node++); if ((p = strstr(names, " and ")) != NULL) { *p = '\0'; } comma1 = strchr(names, ','); if (comma1 == NULL) { format1(names); } else { *comma1 = '\0'; comma2 = strchr(comma1 + 1, ','); if (comma2 == NULL) { format3(comma1 + 1, NULL, names); } else { *comma2 = '\0'; format3(comma2 + 1, comma1 + 1, names); } } fprintf(stdout, "\t\t\t</%s>\n", fieldname); if (p != NULL) { names = p + 5; } } while (p != NULL); fprintf(stdout, "\t\t</%ss>\n", fieldname); } int main(void) { int nline = 0; char line[1024], type[32], fieldname[32]; bool inEntry = false; bool hasLang = false; fputs("<?xml version='1.0' encoding='ISO-8859-1'?>\n", stdout); fputs("<!DOCTYPE bib SYSTEM '../dtd/biblio.dtd'>\n", stdout); fputs("<bib xmlns=\"http://espectroautista.info/ns/bib\">\n", stdout); while (fgets(line, sizeof(line), stdin) != NULL) { #ifdef DEBUG fprintf(stderr, "LINE: %d\n", ++nline); #endif if (!inEntry) { /* open entry */ if (line[0] == '@') { char *key = start_entry(line, type); fprintf(stdout, "\t<%s id='%s'>\n", type, key); inEntry = true; hasLang = false; } } else if (line[0] == '}') { /* close entry */ if (!hasLang) { fprintf(stdout, "\t\t<lang>en</lang>\n"); } fprintf(stdout, "\t</%s>\n", type); inEntry = false; } else { char *value = process_entry(line, fieldname); if (streql(fieldname, "lang")) { hasLang = true; dump_field(fieldname, value); } else if (streql(fieldname, "keywords")) { if (!*value) continue; fprintf(stdout, "\t\t<keywords>\n"); fprintf(stdout, "\t\t\t<keyword>"); while (*value) { if (*value == ':') { fprintf(stdout, "</keyword>\n"); fprintf(stdout, "\t\t\t<keyword>"); } else { putc(*value, stdout); } ++value; } fprintf(stdout, "</keyword>\n"); fprintf(stdout, "\t\t</keywords>\n"); } else if (streql(fieldname, "author") || streql(fieldname, "editor")) { dump_names(fieldname, value); } else { dump_field(fieldname, value); } } } fputs("</bib>\n", stdout); fputs("<!--\nvim:ts=2:fileencoding=latin1:nowrap\n-->\n", stdout); return 0; } /* * vim:sw=4:ts=4:ai */
the_stack_data/182954016.c
#include <stdio.h> #include <time.h> #include <stdlib.h> #include <string.h> int run(char* s) { int counter = 0; int fuel = 0; const char delim[] = "\n"; char *ptr = strtok(s, delim); while(ptr != NULL) { fuel = (atoi(ptr) / 3) - 2; while (fuel > 0){ counter += fuel; fuel = (fuel / 3) - 2; } ptr = strtok(NULL, delim); } return counter; } int main(int argc, char** argv) { clock_t start = clock(); int answer = run(argv[1]); printf("_duration:%f\n%d\n", (float)( clock () - start ) * 1000.0 / CLOCKS_PER_SEC, answer); return 0; }
the_stack_data/264234.c
/** * @license Apache-2.0 * * Copyright (c) 2018 The Stdlib Authors. * * 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. */ /** * Benchmark `cabs2`. */ #include <stdlib.h> #include <stdio.h> #include <math.h> #include <complex.h> #include <sys/time.h> #define NAME "cabs2" #define ITERATIONS 1000000 #define REPEATS 3 /** * Prints the TAP version. */ void print_version() { printf( "TAP version 13\n" ); } /** * Prints the TAP summary. * * @param total total number of tests * @param passing total number of passing tests */ void print_summary( int total, int passing ) { printf( "#\n" ); printf( "1..%d\n", total ); // TAP plan printf( "# total %d\n", total ); printf( "# pass %d\n", passing ); printf( "#\n" ); printf( "# ok\n" ); } /** * Prints benchmarks results. * * @param elapsed elapsed time in seconds */ void print_results( double elapsed ) { double rate = (double)ITERATIONS / elapsed; printf( " ---\n" ); printf( " iterations: %d\n", ITERATIONS ); printf( " elapsed: %0.9f\n", elapsed ); printf( " rate: %0.9f\n", rate ); printf( " ...\n" ); } /** * Returns a clock time. * * @return clock time */ double tic() { struct timeval now; gettimeofday( &now, NULL ); return (double)now.tv_sec + (double)now.tv_usec/1.0e6; } /** * Generates a random number on the interval [0,1]. * * @return random number */ double rand_double() { int r = rand(); return (double)r / ( (double)RAND_MAX + 1.0 ); } /** * Computes the squared absolute value of a complex number. * * @param z input value * @return squared absolute value */ double cabs2( double complex z ) { return ( creal(z)*creal(z) ) + ( cimag(z)*cimag(z) ); } /** * Runs a benchmark. * * @return elapsed time in seconds */ double benchmark() { double complex z; double elapsed; double re; double im; double y; double t; int i; t = tic(); for ( i = 0; i < ITERATIONS; i++ ) { re = ( 1000.0*rand_double() ) - 500.0; im = ( 1000.0*rand_double() ) - 500.0; z = re + im*I; y = cabs2( z ); if ( y != y ) { printf( "should not return NaN\n" ); break; } } elapsed = tic() - t; if ( y != y ) { printf( "should not return NaN\n" ); } return elapsed; } /** * Main execution sequence. */ int main( void ) { double elapsed; int i; // Use the current time to seed the random number generator: srand( time( NULL ) ); print_version(); for ( i = 0; i < REPEATS; i++ ) { printf( "# c::%s\n", NAME ); elapsed = benchmark(); print_results( elapsed ); printf( "ok %d benchmark finished\n", i+1 ); } print_summary( REPEATS, REPEATS ); }
the_stack_data/178264787.c
//Faça um Programa que peça um número correspondente a um determinado ano e em seguida informe se este ano é ou não bissexto. #include <stdio.h> int main(void){ int ano,resto; printf("Insira o ano: \n"); scanf("%i",&ano); resto = ano % 4; if (resto == 0) printf("Ano bissexto\n"); else printf("Não é bissexto\n"); return 0; }
the_stack_data/839347.c
/* s390-mkopc.c -- Generates opcode table out of s390-opc.txt Copyright 2000, 2001, 2003, 2005, 2007, 2008 Free Software Foundation, Inc. Contributed by Martin Schwidefsky ([email protected]). This file is part of the GNU opcodes library. This library 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, or (at your option) any later version. It 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 file; see the file COPYING. If not, write to the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ #include <stdio.h> #include <stdlib.h> #include <string.h> /* Taken from opcodes/s390.h */ enum s390_opcode_mode_val { S390_OPCODE_ESA = 0, S390_OPCODE_ZARCH }; enum s390_opcode_cpu_val { S390_OPCODE_G5 = 0, S390_OPCODE_G6, S390_OPCODE_Z900, S390_OPCODE_Z990, S390_OPCODE_Z9_109, S390_OPCODE_Z9_EC, S390_OPCODE_Z10, S390_OPCODE_Z196 }; struct op_struct { char opcode[16]; char mnemonic[16]; char format[16]; int mode_bits; int min_cpu; unsigned long long sort_value; int no_nibbles; }; struct op_struct *op_array; int max_ops; int no_ops; static void createTable (void) { max_ops = 256; op_array = malloc (max_ops * sizeof (struct op_struct)); no_ops = 0; } /* `insertOpcode': insert an op_struct into sorted opcode array. */ static void insertOpcode (char *opcode, char *mnemonic, char *format, int min_cpu, int mode_bits) { char *str; unsigned long long sort_value; int no_nibbles; int ix, k; while (no_ops >= max_ops) { max_ops = max_ops * 2; op_array = realloc (op_array, max_ops * sizeof (struct op_struct)); } sort_value = 0; str = opcode; for (ix = 0; ix < 16; ix++) { if (*str >= '0' && *str <= '9') sort_value = (sort_value << 4) + (*str - '0'); else if (*str >= 'a' && *str <= 'f') sort_value = (sort_value << 4) + (*str - 'a' + 10); else if (*str >= 'A' && *str <= 'F') sort_value = (sort_value << 4) + (*str - 'A' + 10); else if (*str == '?') sort_value <<= 4; else break; str ++; } sort_value <<= 4*(16 - ix); sort_value += (min_cpu << 8) + mode_bits; no_nibbles = ix; for (ix = 0; ix < no_ops; ix++) if (sort_value > op_array[ix].sort_value) break; for (k = no_ops; k > ix; k--) op_array[k] = op_array[k-1]; strcpy(op_array[ix].opcode, opcode); strcpy(op_array[ix].mnemonic, mnemonic); strcpy(op_array[ix].format, format); op_array[ix].sort_value = sort_value; op_array[ix].no_nibbles = no_nibbles; op_array[ix].min_cpu = min_cpu; op_array[ix].mode_bits = mode_bits; no_ops++; } struct s390_cond_ext_format { char nibble; char extension[4]; }; /* The mnemonic extensions for conditional jumps used to replace the '*' tag. */ #define NUM_COND_EXTENSIONS 20 const struct s390_cond_ext_format s390_cond_extensions[NUM_COND_EXTENSIONS] = { { '1', "o" }, /* jump on overflow / if ones */ { '2', "h" }, /* jump on A high */ { '2', "p" }, /* jump on plus */ { '3', "nle" }, /* jump on not low or equal */ { '4', "l" }, /* jump on A low */ { '4', "m" }, /* jump on minus / if mixed */ { '5', "nhe" }, /* jump on not high or equal */ { '6', "lh" }, /* jump on low or high */ { '7', "ne" }, /* jump on A not equal B */ { '7', "nz" }, /* jump on not zero / if not zeros */ { '8', "e" }, /* jump on A equal B */ { '8', "z" }, /* jump on zero / if zeros */ { '9', "nlh" }, /* jump on not low or high */ { 'a', "he" }, /* jump on high or equal */ { 'b', "nl" }, /* jump on A not low */ { 'b', "nm" }, /* jump on not minus / if not mixed */ { 'c', "le" }, /* jump on low or equal */ { 'd', "nh" }, /* jump on A not high */ { 'd', "np" }, /* jump on not plus */ { 'e', "no" }, /* jump on not overflow / if not ones */ }; /* The mnemonic extensions for conditional branches used to replace the '$' tag. */ #define NUM_CRB_EXTENSIONS 12 const struct s390_cond_ext_format s390_crb_extensions[NUM_CRB_EXTENSIONS] = { { '2', "h" }, /* jump on A high */ { '2', "nle" }, /* jump on not low or equal */ { '4', "l" }, /* jump on A low */ { '4', "nhe" }, /* jump on not high or equal */ { '6', "ne" }, /* jump on A not equal B */ { '6', "lh" }, /* jump on low or high */ { '8', "e" }, /* jump on A equal B */ { '8', "nlh" }, /* jump on not low or high */ { 'a', "nl" }, /* jump on A not low */ { 'a', "he" }, /* jump on high or equal */ { 'c', "nh" }, /* jump on A not high */ { 'c', "le" }, /* jump on low or equal */ }; /* As with insertOpcode instructions are added to the sorted opcode array. Additionally mnemonics containing the '*<number>' tag are expanded to the set of conditional instructions described by s390_cond_extensions with the tag replaced by the respective mnemonic extensions. */ static void insertExpandedMnemonic (char *opcode, char *mnemonic, char *format, int min_cpu, int mode_bits) { char *tag; char prefix[15]; char suffix[15]; char number[15]; int mask_start, i = 0, tag_found = 0, reading_number = 0; int number_p = 0, suffix_p = 0, prefix_p = 0; const struct s390_cond_ext_format *ext_table; int ext_table_length; if (!(tag = strpbrk (mnemonic, "*$"))) { insertOpcode (opcode, mnemonic, format, min_cpu, mode_bits); return; } while (mnemonic[i] != '\0') { if (mnemonic[i] == *tag) { if (tag_found) goto malformed_mnemonic; tag_found = 1; reading_number = 1; } else switch (mnemonic[i]) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (!tag_found || !reading_number) goto malformed_mnemonic; number[number_p++] = mnemonic[i]; break; default: if (reading_number) { if (!number_p) goto malformed_mnemonic; else reading_number = 0; } if (tag_found) suffix[suffix_p++] = mnemonic[i]; else prefix[prefix_p++] = mnemonic[i]; } i++; } prefix[prefix_p] = '\0'; suffix[suffix_p] = '\0'; number[number_p] = '\0'; if (sscanf (number, "%d", &mask_start) != 1) goto malformed_mnemonic; if (mask_start & 3) { fprintf (stderr, "Conditional mask not at nibble boundary in: %s\n", mnemonic); return; } mask_start >>= 2; switch (*tag) { case '*': ext_table = s390_cond_extensions; ext_table_length = NUM_COND_EXTENSIONS; break; case '$': ext_table = s390_crb_extensions; ext_table_length = NUM_CRB_EXTENSIONS; break; default: fprintf (stderr, "Unknown tag char: %c\n", *tag); } for (i = 0; i < ext_table_length; i++) { char new_mnemonic[15]; strcpy (new_mnemonic, prefix); opcode[mask_start] = ext_table[i].nibble; strcat (new_mnemonic, ext_table[i].extension); strcat (new_mnemonic, suffix); insertOpcode (opcode, new_mnemonic, format, min_cpu, mode_bits); } return; malformed_mnemonic: fprintf (stderr, "Malformed mnemonic: %s\n", mnemonic); } static char file_header[] = "/* The opcode table. This file was generated by s390-mkopc.\n\n" " The format of the opcode table is:\n\n" " NAME OPCODE MASK OPERANDS\n\n" " Name is the name of the instruction.\n" " OPCODE is the instruction opcode.\n" " MASK is the opcode mask; this is used to tell the disassembler\n" " which bits in the actual opcode must match OPCODE.\n" " OPERANDS is the list of operands.\n\n" " The disassembler reads the table in order and prints the first\n" " instruction which matches. */\n\n" "const struct s390_opcode s390_opcodes[] =\n {\n"; /* `dumpTable': write opcode table. */ static void dumpTable (void) { char *str; int ix; /* Write hash table entries (slots). */ printf (file_header); for (ix = 0; ix < no_ops; ix++) { printf (" { \"%s\", ", op_array[ix].mnemonic); for (str = op_array[ix].opcode; *str != 0; str++) if (*str == '?') *str = '0'; printf ("OP%i(0x%sLL), ", op_array[ix].no_nibbles*4, op_array[ix].opcode); printf ("MASK_%s, INSTR_%s, ", op_array[ix].format, op_array[ix].format); printf ("%i, ", op_array[ix].mode_bits); printf ("%i}", op_array[ix].min_cpu); if (ix < no_ops-1) printf (",\n"); else printf ("\n"); } printf ("};\n\n"); printf ("const int s390_num_opcodes =\n"); printf (" sizeof (s390_opcodes) / sizeof (s390_opcodes[0]);\n\n"); } int main (void) { char currentLine[256]; createTable (); /* Read opcode descriptions from `stdin'. For each mnemonic, make an entry into the opcode table. */ while (fgets (currentLine, sizeof (currentLine), stdin) != NULL) { char opcode[16]; char mnemonic[16]; char format[16]; char description[80]; char cpu_string[16]; char modes_string[16]; int min_cpu; int mode_bits; char *str; if (currentLine[0] == '#') continue; memset (opcode, 0, 8); if (sscanf (currentLine, "%15s %15s %15s \"%79[^\"]\" %15s %15s", opcode, mnemonic, format, description, cpu_string, modes_string) == 6) { if (strcmp (cpu_string, "g5") == 0) min_cpu = S390_OPCODE_G5; else if (strcmp (cpu_string, "g6") == 0) min_cpu = S390_OPCODE_G6; else if (strcmp (cpu_string, "z900") == 0) min_cpu = S390_OPCODE_Z900; else if (strcmp (cpu_string, "z990") == 0) min_cpu = S390_OPCODE_Z990; else if (strcmp (cpu_string, "z9-109") == 0) min_cpu = S390_OPCODE_Z9_109; else if (strcmp (cpu_string, "z9-ec") == 0) min_cpu = S390_OPCODE_Z9_EC; else if (strcmp (cpu_string, "z10") == 0) min_cpu = S390_OPCODE_Z10; else if (strcmp (cpu_string, "z196") == 0) min_cpu = S390_OPCODE_Z196; else { fprintf (stderr, "Couldn't parse cpu string %s\n", cpu_string); exit (1); } str = modes_string; mode_bits = 0; do { if (strncmp (str, "esa", 3) == 0 && (str[3] == 0 || str[3] == ',')) { mode_bits |= 1 << S390_OPCODE_ESA; str += 3; } else if (strncmp (str, "zarch", 5) == 0 && (str[5] == 0 || str[5] == ',')) { mode_bits |= 1 << S390_OPCODE_ZARCH; str += 5; } else { fprintf (stderr, "Couldn't parse modes string %s\n", modes_string); exit (1); } if (*str == ',') str++; } while (*str != 0); insertExpandedMnemonic (opcode, mnemonic, format, min_cpu, mode_bits); } else { fprintf (stderr, "Couldn't scan line %s\n", currentLine); exit (1); } } dumpTable (); return 0; }
the_stack_data/89199088.c
//Classification: n/ZD/aS+dA/A(D(v,c),v)/fp/cd //Written by: Igor Eremeev #include <malloc.h> int func(int *p) { int a = 3, b = 2, c = 1, d; d = 1/(p[0]-a); d = 1/(p[1]-b); d = 1/(p[2]-c); return 0; } int main(void) { int *p; int a = 2; p = (int *)malloc(sizeof(int) * 3); p[0] = 6; p[1] = 5; if (a == 2) { p[2] = 1; } else { p[2] = 2; } func(p); return 0; }
the_stack_data/115619.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> #include <string.h> #include <sys/wait.h> #include <ctype.h> #include <fcntl.h> #define EXIT "exit" #define ECHO_PATH "echo $PATH" #define PATH "PATH" char *my_argv[100]; char *env[100]; char *path[10]; void fill_argv(char *tmp_argv){ char *commands = tmp_argv; int i = 0; //looking for how many flags char ret[100]; memset(ret, 0, 100); while(*commands != '\0') { if(*commands == ' ') { if(my_argv[i] == NULL) my_argv[i] = (char *)malloc(sizeof(char) * strlen(ret) + 1); else memset(my_argv[i], 0, strlen(my_argv[i])); strncpy(my_argv[i], ret, strlen(ret)); strncat(my_argv[i], "\0", 1); memset(ret, 0, 100); i++; } else strncat(ret, commands, 1); commands++; } my_argv[i] = (char *)malloc(sizeof(char) * strlen(ret) + 1); strncpy(my_argv[i], ret, strlen(ret)); strncat(my_argv[i], "\0", 1); } void copy_env(char **env1){ for(int i = 0; env[i] != NULL; i++) { env1[i] = (char *)malloc(sizeof(char) * (strlen(env1[i]) + 1)); memcpy(env1[i], env1[i], strlen(env1[i])); } } void get_path(char **tmp_env, char *path_str){ int i = 0; char *tmp; while(1) { tmp = strstr(tmp_env[i], PATH); if(tmp == NULL) i++; else break; } strncpy(path_str, tmp, strlen(tmp)); i = 0; tmp = path_str; char ret[100]; while(*tmp != '=') tmp++; tmp++; while(*tmp != '\0') { if(*tmp == ':') { strncat(ret, "/", 1); path[i] = (char *) malloc(sizeof(char) * (strlen(ret) + 1)); strncat(path[i], ret, strlen(ret)); strncat(path[i], "\0", 1); i++; memset(ret, 0, 100); } else strncat(ret, tmp, 1); tmp++; } } void free_end(char* tmp, char* path_str){ free(tmp); free(path_str); for(int i = 0; env[i] != NULL; i++) free(env[i]); for(int i = 0; i < 10; i++) free(path[i]); } void free_argv(){ for(int i = 0; my_argv[i] != NULL; i++) { memset(my_argv[i], 0, strlen(my_argv[i])+1); my_argv[i] = NULL; free(my_argv[i]); } } void start_signal(){ printf("\nshell> "); fflush(stdout); } int main(int argc, char *argv[], char *env1[]){ char c; int fd; char *tmp = (char *)malloc(sizeof(char) * 100); char *path_str = (char *)malloc(sizeof(char) * 256); char *cmd = (char *)malloc(sizeof(char) * 100); char *newcmd = (char *)malloc(sizeof(char) * 100); signal(SIGINT, SIG_IGN); signal(SIGINT, start_signal); copy_env(env1); get_path(env1, path_str); if(fork() == 0) { execve("/usr/bin/clear", argv, env1); exit(1); } else { wait(NULL); } printf("shell> "); fflush(stdout); while(c != EOF) { c = getchar(); switch(c) { case '\n': if(tmp[0] == '\0') printf("shell> "); else { fill_argv(tmp); strncpy(cmd, my_argv[0], strlen(my_argv[0])); strncat(cmd, "\0", 1); strncpy(newcmd, "/bin/", strlen("/bin/")); strncat(newcmd, cmd, strlen(cmd)); if (strcmp(EXIT, cmd) == 0) { free_end(tmp, path_str); return 0; } else if (strcmp(ECHO_PATH, tmp) == 0) { printf("%s\n", path_str); free_argv(); memset(newcmd, 0, 100); memset(cmd, 0, 100); printf("shell> "); } else { if ((fd = open(newcmd, O_RDONLY)) > 0) { //read only O_RDONLY close(fd); pid_t pid; int i; pid = fork(); if (pid == 0) { i = execve(newcmd, my_argv, env1); if (i < 0) { printf("Failed to Execute: %s\n", newcmd); exit(1); } } else wait(NULL); } else printf("Failed to Execute: %s\n", cmd); free_argv(); memset(newcmd, 0, 100); memset(cmd, 0, 100); printf("shell> "); } memset(tmp, 0, 100); break; } default: strncat(tmp, &c, 1); break; } } free_end(tmp, path_str); return 0; }
the_stack_data/553335.c
// RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-LD %s // CHECK-LD: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd" // CHECK-LD: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o" // RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -pg -pthread %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-PG %s // CHECK-PG: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd" // CHECK-PG: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}gcrt0.o" "{{.*}}crtbegin.o" "{{.*}}.o" "-lgcc" "-lpthread_p" "-lc_p" "-lgcc" "{{.*}}crtend.o" // Check that the new linker flags are passed to OpenBSD // RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -r %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-LD-R %s // RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -s %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-LD-S %s // RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -t %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-LD-T %s // RUN: %clang -no-canonical-prefixes -target i686-pc-openbsd -Z %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-LD-Z %s // RUN: %clang -no-canonical-prefixes -target mips64-unknown-openbsd %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-MIPS64-LD %s // RUN: %clang -no-canonical-prefixes -target mips64el-unknown-openbsd %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-MIPS64EL-LD %s // CHECK-LD-R: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd" // CHECK-LD-R: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-r" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o" // CHECK-LD-S: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd" // CHECK-LD-S: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-s" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o" // CHECK-LD-T: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd" // CHECK-LD-T: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-t" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o" // CHECK-LD-Z: clang{{.*}}" "-cc1" "-triple" "i686-pc-openbsd" // CHECK-LD-Z: ld{{.*}}" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "-Z" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o" // CHECK-MIPS64-LD: clang{{.*}}" "-cc1" "-triple" "mips64-unknown-openbsd" // CHECK-MIPS64-LD: ld{{.*}}" "-EB" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o" // CHECK-MIPS64EL-LD: clang{{.*}}" "-cc1" "-triple" "mips64el-unknown-openbsd" // CHECK-MIPS64EL-LD: ld{{.*}}" "-EL" "-e" "__start" "--eh-frame-hdr" "-Bdynamic" "-dynamic-linker" "{{.*}}ld.so" "-o" "a.out" "{{.*}}crt0.o" "{{.*}}crtbegin.o" "-L{{.*}}" "{{.*}}.o" "-lgcc" "-lc" "-lgcc" "{{.*}}crtend.o" // Check passing options to the assembler for various OpenBSD targets // RUN: %clang -target amd64-pc-openbsd -m32 -### -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-AMD64-M32 %s // RUN: %clang -target powerpc-unknown-openbsd -### -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-POWERPC %s // RUN: %clang -target sparc-unknown-openbsd -### -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-SPARC %s // RUN: %clang -target sparc64-unknown-openbsd -### -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-SPARC64 %s // RUN: %clang -target mips64-unknown-openbsd -### -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-MIPS64 %s // RUN: %clang -target mips64-unknown-openbsd -fPIC -### -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-MIPS64-PIC %s // RUN: %clang -target mips64el-unknown-openbsd -### -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-MIPS64EL %s // RUN: %clang -target mips64el-unknown-openbsd -fPIC -### -no-integrated-as -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-MIPS64EL-PIC %s // CHECK-AMD64-M32: as{{.*}}" "--32" // CHECK-POWERPC: as{{.*}}" "-mppc" "-many" // CHECK-SPARC: as{{.*}}" "-32" // CHECK-SPARC64: as{{.*}}" "-64" "-Av9a" // CHECK-MIPS64: as{{.*}}" "-mabi" "64" "-EB" // CHECK-MIPS64-PIC: as{{.*}}" "-mabi" "64" "-EB" "-KPIC" // CHECK-MIPS64EL: as{{.*}}" "-mabi" "64" "-EL" // CHECK-MIPS64EL-PIC: as{{.*}}" "-mabi" "64" "-EL" "-KPIC" // Check that the integrated assembler is enabled for PowerPC and SPARC // RUN: %clang -target powerpc-unknown-openbsd -### -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-IAS %s // RUN: %clang -target sparc-unknown-openbsd -### -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-IAS %s // RUN: %clang -target sparc64-unknown-openbsd -### -c %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-IAS %s // CHECK-IAS-NOT: "-no-integrated-as"
the_stack_data/132952666.c
#include <string.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int child_action(int pipefd) { int m; char buffer[256]; memset(buffer,0,256); printf("Send message to the parent\n"); fgets(buffer,255,stdin); m = write(pipefd, buffer, strlen(buffer)); printf("Wrote %d bytes to parent\n",m); return 0; } int main(int argc, char **argv) { int pipefd[2], n; int pid; char buffer[256]; n = pipe(pipefd); if(n < 0) { printf("No pipes created. Exiting!\n"); return 1; } pid = fork(); if(pid == 0) { child_action(pipefd[1]); return 0; } printf("Waiting for a message from child process\n"); memset(buffer,0,256); n = read(pipefd[0], buffer, 256); if(n > 0) { printf("Message (bytes:%d) from child:%s\n",n,buffer); } return 0; }
the_stack_data/220454905.c
#include<stdio.h> #include <math.h> #include <stdlib.h> typedef unsigned char uint8_t; typedef unsigned short uint16_t; typedef unsigned long uint32_t; typedef unsigned long long uint64_t; #define MAX_NUM (1 << 16) uint16_t leadingBitPosition(uint16_t val) { uint16_t clz; // clz function calculates number of leading zeros in integer number clz = __builtin_clz(val); return 31-clz; } int LM( int a, int b, unsigned short w) { unsigned short n; n = 16; if(a == 0 || b == 0) return 0; char sgn_a = a > 0 ? 0 : 1; char sgn_b = b > 0 ? 0 : 1; unsigned int a_abs = sgn_a ? -(a)-1 : a; unsigned int b_abs = sgn_b ? -(b)-1 : b; // mux unsigned int a_sel = a_abs; unsigned int b_sel = b_abs; unsigned int k_a, x_a; k_a = leadingBitPosition(a_sel); x_a = a_sel << (n - 1 - k_a); //printf("Xa = %x \n", x_a); unsigned int k_b, x_b; k_b = leadingBitPosition(b_sel); x_b = b_sel << (n - 1 - k_b); //printf("Xb = %x \n", x_b); unsigned int tmp, tmp_prim; tmp = (1<<(n-1))-1; tmp_prim = ((1<<(n-1)) - (1<<(n-w))); unsigned int y_a, y_b, tmp_a, tmp_b; tmp_a = x_a & tmp; y_a = x_a & tmp_prim; y_a = y_a | (1 << (n-w-1)); //printf("Ya = %x \n", y_a); tmp_b = x_b & tmp; y_b = x_b & tmp_prim; y_b = y_b | (1 << (n-w-1)); //printf("Yb = %x \n", y_b); //char tresh = Q; // We truncate mantissa unsigned int y_l; y_l = (y_a + y_b) & tmp; // We set the LSB of k_a and k_b to zero unsigned int k_l; k_l = k_a + k_b + (((y_a + y_b) & (tmp+1)) >> (n - 1)); double m; unsigned int p_abs; m = (double)y_l / (1 << 15); p_abs = (unsigned int)((1 + m)*(1 << k_l)); int zero = (a == 0) || (b == 0) ; int p; p = (sgn_a ^ sgn_b)? -p_abs-1 : p_abs; p = p*(1-zero); return p; } int ELM(int x, int y, int w) { int sum = 0; int x0, x1, x0_signed, x0_abs; char sign; // X = X1*2^14 + X0 // X1 = -2*x15+x14+x13 // X0 = -x13*2^13 + sum_(i=0)^(12)(x_i*2^i) x1 = x >> 14; x0 = x % (1 << 14); x0_signed = x0; if(x0 < -8192) x0_signed = x0 + 16384; if(x0 > 8192) x0_signed = x0 - 16384; // Caclulation of LSB x0_abs = x0_signed; x1 += (x0_signed < 0); int y0, y1, y0_signed, y0_abs; // Y = Y1*2^14 + Y0 // X1 = -2*y15+y14+y13 // X0 = -y13*2^13 + sum_(i=0)^(12)(y_i*2^i) y1 = y >> 14; y0 = y % (1 << 14); y0_signed = y0; if(y0 < -8192) y0_signed = y0 + 16384; if(y0 > 8192) y0_signed = y0 - 16384; // Caclulation of LSB y0_abs = y0_signed; y1 += (y0_signed < 0); // Calculation of product // PP_3 = X1*Y1 // PP_2 = X1*Y0, PP_1 = Y1*X0 int PP_1 = x1*y; if(PP_1 < 0){ PP_1 = (PP_1 - 1) | 1; } sum += PP_1 <<14; //int PP_0 = x0_signed*y0_signed; int PP_0 = LM(x0_signed,y,w); sum += PP_0; return sum; } double rel_error(int x, int y, int w) { double prod_t, prod_a; prod_t = (double)x*y; prod_a = (double)ELM(x, y, w); if(x==0 || y==0) return 0; return fabs(prod_t - prod_a)/fabs(prod_t)*100.0; } void PRE(double RE, uint32_t *count){ // Calculates that probabilities are smaller than X // In this function we analyze probabilites that // RE is smaller than 2, 5, 10, 15, 20, 25 % *count += (RE < 2); *(count+1) += (RE < 5); *(count+2) += (RE < 10); *(count+3) += (RE < 15); *(count+4) += (RE < 20); *(count+5) += (RE < 25); *(count+6) += (RE < 11); } void PRE11(double RE, uint32_t count){ // Calculates that probabilities are smaller than X // In this function we analyze probabilites that // RE is smaller than 2, 5, 10, 15, 20, 25 % count += (RE < 11); } int main() { volatile int i, j, g,h,f; volatile char w[] = {1,3,4,5,6,7}; volatile char q[] = {1,6,7} ; volatile uint32_t MAXRE_COUNT = 0; volatile double RE, MAXRE = 0, SUM_RE = 0; uint32_t count[] = { 0,0,0,0,0,0,0 }; char perc[] = { 2,5,10,15,20,25,11 }; FILE *log; char p; log = fopen("./log_MRE.txt", "a"); if (log != NULL){ char str1[80]; sprintf(str1, "w q MRE MAXRE MAXRE_PROB 2 5 10 15 20 25 11\n"); fputs(str1, log); fclose(log); } // Iterator for qy for (h = 0; h < 1; h++){ // init values with zeros SUM_RE = 0; int xx = 0; MAXRE_COUNT = 0; MAXRE = 0; for ( xx = 0; xx < 7; xx++) { count[xx] = 0; } // Calculating RE for pair in [0,MAX_NUM-1]x[0,MAX_NUM-1] for (i = -MAX_NUM/2; i < MAX_NUM/2-1; i++) { for (j = -MAX_NUM/2; j < MAX_NUM/2-1; j++) { RE = rel_error(i, j,w[h]); PRE(RE, count); SUM_RE += RE; MAXRE = MAXRE > RE ? MAXRE : RE; MAXRE_COUNT = MAXRE > RE ? MAXRE_COUNT++ : 1; } } log = fopen("./log_MRE.txt", "a"); if (log != NULL) { char str0[] = "--------------------------------- \n \n"; char str1[80]; sprintf(str1, "%d %d ", w[h],q[g]); fputs(str1, log); sprintf(str1, " %2.4g ", (SUM_RE / (double)MAX_NUM)/(double)MAX_NUM); fputs(str1, log); sprintf(str1, " %2.4g ", MAXRE); fputs(str1, log); sprintf(str1, " %e ", ((double)MAXRE_COUNT/(double)MAX_NUM)/(double)MAX_NUM); fputs(str1, log); for (p = 0; p < 7; p++) { sprintf(str1," %02.4g ", ((double)count[p]/ MAX_NUM)/MAX_NUM); fputs(str1, log); } sprintf(str1, " \n "); fputs(str1, log); fclose(log); } } return 0; }
the_stack_data/43887985.c
int i = 30000000; int main() { do{ asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); asm("movsx %bx, %rbx"); asm("movsx %dx, %rdx"); }while(i--); }
the_stack_data/170451949.c
/* { dg-do compile } */ /* { dg-options "-fsanitize=address -fsanitize-sections=.x* -fsanitize-sections=.y* -fdump-tree-sanopt" } */ /* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */ int x __attribute__((section(".x1"))) = 1; int y __attribute__((section(".x2"))) = 1; int z __attribute__((section(".y1"))) = 1; /* { dg-final { scan-tree-dump "__builtin___asan_unregister_globals \\(.*, 1\\);" "sanopt" } } */
the_stack_data/114591.c
double foo(double S, double Q) { for (int J = 0; J < 10; ++J) { for (int I = 0; I < 10; ++I) { S += I; } S = Q; } return S + Q; }
the_stack_data/59513507.c
// Copyright 2020 Google LLC. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include <time.h> #include <stdio.h> const int size = 100000; int main() { clock_t watch = clock(); int index = 0; while (index < 10000) { int foo[size]; for (int subindex = 0; subindex < size; subindex += 1) foo[subindex] = 1; index += foo[12487]; } printf("%.2fs\n", (double)(clock() - watch) / 1000000); }
the_stack_data/200144188.c
int foo(int a, int b) { return ((a & 7) | (b & 3)) & 8; } /* * check-name: and-or-mask * check-command: test-linearize -Wno-decl $file * * check-output-start foo: .L0: <entry-point> ret.32 $0 * check-output-end */
the_stack_data/691186.c
#include <stdio.h> void scilab_rt_legends_s2i2_(int in00, int in01, char* matrixin0[in00][in01], int in10, int in11, int matrixin1[in10][in11]) { int i; int j; int val1 = 0; for (i = 0; i < in00; ++i) { for (j = 0; j < in01; ++j) { printf("%s", matrixin0[i][j]); } } for (i = 0; i < in10; ++i) { for (j = 0; j < in11; ++j) { val1 += matrixin1[i][j]; } } printf("%d", val1); }
the_stack_data/116989.c
// simple routine to time multiplication. int mul(int *time, int a, int b) { unsigned start = *(unsigned *) 0x20003004; int c = a * b; unsigned end = *(unsigned *) 0x20003004; *time = end - start; return c; }
the_stack_data/170453551.c
/** * File Name: Queue.c * Author: tyrantlucifer * E-mail: [email protected] * Blog: https://tyrantlucifer.com */ #include <stdio.h> #include <stdlib.h> /** * define the node of queue */ typedef struct Node { int data; struct Node* next; struct Node* pre; } Node; /** * init queue * @return the head pointer of queue */ Node* initQueue() { Node* Q = (Node*)malloc(sizeof(Node)); Q->data = 0; Q->pre = Q; Q->next = Q; return Q; } /** * enqueue * @param Q the head pointer of queue * @param data the data you want to enqueue */ void enQueue(Node* Q, int data) { Node* node = (Node*)malloc(sizeof(Node)); node->data = data; node->next = Q; node->pre = Q->pre; Q->pre->next = node; Q->pre = node; Q->data++; } /** * judge queue is or not empty * @param Q the head pointer of queue * @return empty flag */ int isEmpty(Node* Q) { if (Q->data == 0 || Q->next == Q) { return 1; } else { return 0; } } /** * dequeue * @param Q the head pointer of queue * @return the data of dequeue */ int deQueue(Node* Q) { if (isEmpty(Q)) { return 0; } else { Node* node = Q->next; Q->next = Q->next->next; Q->next->pre = Q; Q->data--; return node->data; } } /** * print all item in queue * @param Q the head pointer of queue */ void printQueue(Node* Q) { Node* node = Q -> next; while (node != Q) { printf("%d -> ", node -> data); node = node -> next; } printf("NULL\n"); } /** * main function * @return null */ int main() { Node* Q = initQueue(); enQueue(Q, 1); enQueue(Q, 2); enQueue(Q, 3); enQueue(Q, 4); printQueue(Q); printf("dequeue = %d\n", deQueue(Q)); printf("dequeue = %d\n", deQueue(Q)); printQueue(Q); return 0; }
the_stack_data/236264.c
/* Taxonomy Classification: 0000100000106000000000 */ /* * WRITE/READ 0 write * WHICH BOUND 0 upper * DATA TYPE 0 char * MEMORY LOCATION 0 stack * SCOPE 1 inter-procedural * CONTAINER 0 no * POINTER 0 no * INDEX COMPLEXITY 0 constant * ADDRESS COMPLEXITY 0 constant * LENGTH COMPLEXITY 0 N/A * ADDRESS ALIAS 1 yes, one level * INDEX ALIAS 0 none * LOCAL CONTROL FLOW 6 function pointer * SECONDARY CONTROL FLOW 0 none * LOOP STRUCTURE 0 no * LOOP COMPLEXITY 0 N/A * ASYNCHRONY 0 no * TAINT 0 no * RUNTIME ENV. DEPENDENCE 0 no * MAGNITUDE 0 no overflow * CONTINUOUS/DISCRETE 0 discrete * SIGNEDNESS 0 no */ /* Copyright 2005 Massachusetts Institute of Technology All rights reserved. Redistribution and use of software in source and binary forms, with or without modification, are permitted provided that the following conditions are met. - Redistributions of source code must retain the above copyright notice, this set of conditions and the disclaimer below. - Redistributions in binary form must reproduce the copyright notice, this set of conditions, and the disclaimer below in the documentation and/or other materials provided with the distribution. - Neither the name of the Massachusetts Institute of Technology nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS". ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 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. */ void function1(char * buf) { /* OK */ buf[9] = 'A'; } int main(int argc, char *argv[]) { void (*fptr)(char *); char buf[10]; fptr = function1; fptr(buf); return 0; }
the_stack_data/211522.c
// Compile with `gcc foo.c -std=c99 -lpthread`, or use the makefile #include <pthread.h> #include <stdio.h> int i = 0; // Note the return type: void* void* incrementingThreadFunction(){ for (int j = 0; j<1000000; ++j){ i++; } return NULL; } void* decrementingThreadFunction(){ for (int k = 0; k<1000000; ++k){ i--; } return NULL; } int main(){ pthread_t incrementingThread; pthread_t decrementingThread; pthread_create(&incrementingThread, NULL, incrementingThreadFunction, NULL); pthread_create(&decrementingThread, NULL, decrementingThreadFunction, NULL); pthread_join(incrementingThread, NULL); pthread_join(decrementingThread, NULL); printf("The magic number is: %d\n", i); return 0; }
the_stack_data/62636647.c
#include<stdio.h> int main() { char str[80], search[10]; int count1 = 0, count2 = 0, i, j, flag; printf("Enter a string: \n"); scanf("%s", &str); printf("Enter search substring: \n"); scanf("%s", &search); while (str[count1] != '\0') count1++; while (search[count2] != '\0') count2++; for (i = 0; i <= count1 - count2; i++) { for (j = i; j < i + count2; j++) { flag = 1; if (str[j] != search[j - i]) { flag = 0; break; } } if (flag) break; } if (flag) printf("Found\n"); else printf("Not found\n"); }
the_stack_data/61074236.c
#include <stdio.h> #include <math.h> #define ll long long int ll findMinimumCost(ll n, ll a, ll b) { ll average = (b * n) / (a + b); ll firstAttempt = a * pow(average, 2) + b * pow((n-average), 2); average += 1; ll secondAttempt = a * pow(average, 2) + b * pow((n-average), 2); return firstAttempt < secondAttempt ? firstAttempt : secondAttempt; } int main() { ll T, n, a, b; scanf("%lld", &T); while(T--) { scanf("%lld%lld%lld", &n, &a, &b); printf("%lld\n", findMinimumCost(n, a, b)); } return 0; }
the_stack_data/89270.c
// komentar int a[1]; int main(void) { return 0; }
the_stack_data/147649.c
/* APPLE LOCAL file 4196991 */ /* Avoid changing the fp control word for fp to uint */ /* { dg-do compile { target i?86-*-darwin* } } */ /* { dg-options "-O2 -msse3" } */ unsigned foo(float *a) { return *a; } /* { dg-final { scan-assembler-not "fldcw" } } */
the_stack_data/175143133.c
#include <stdio.h> #include <stdlib.h> int sorting_function(int *arr, int left, int right) { int l=left, r=right, tmp; int piv = arr[(l+r)/2]; while (l <= r) { while (arr[l] < piv) l++; while (arr[r] > piv) r--; if (l <= r) { tmp=arr[l]; arr[l]=arr[r]; arr[r]=tmp; l++; r--; } } if (left<r) sorting_function(arr, left, r); if (right>l) sorting_function(arr, l, right); return 0; } int main() { int *a; int i, n; scanf("%d", &n); a=(int*)malloc(n * sizeof(int)); for (i=0; i<n; i++) scanf("%d", &a[i]); sorting_function(a, 0, n-1); for (i=0; i<n-1; i++) printf("%d ", a[i]); printf("%d\n", a[i]); return 0; }
the_stack_data/237643134.c
//////////////////////////////////////////////////////////////////////////// // // Function Name : DisplayR() // Description : Accept Number From User & Display That Number In Reverse On Screen Using Recursion // Input : Integer // Output : Integer // Author : Prasad Dangare // Date : 21 May 2021 // //////////////////////////////////////////////////////////////////////////// #include <stdio.h> void DisplayR(int iNo) { static int i = 1; if(iNo >= i) { printf("%d\t", iNo); iNo--; DisplayR(iNo); } /*int i = 0; for(i = iNo; i >= 1; i--) { printf("%d\t", i); }*/ } int main() { int iValue = 0; printf("Enter The Number : "); scanf("%d", &iValue); DisplayR(iValue); return 0; }
the_stack_data/25137920.c
//***************************************************************************** // // startup_gcc.c - Startup code for use with GNU tools. // // Copyright (c) 2008-2013 Texas Instruments Incorporated. All rights reserved. // Software License Agreement // // Texas Instruments (TI) is supplying this software for use solely and // exclusively on TI's microcontroller products. The software is owned by // TI and/or its suppliers, and is protected under applicable copyright // laws. You may not combine this software with "viral" open-source // software in order to form a larger program. // // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL // DAMAGES, FOR ANY REASON WHATSOEVER. // // This is part of revision 10636 of the EK-LM3S3748 Firmware Package. // //***************************************************************************** //***************************************************************************** // // Forward declaration of the default fault handlers. // //***************************************************************************** void ResetISR(void); static void NmiSR(void); static void FaultISR(void); static void IntDefaultHandler(void); //***************************************************************************** // // External declarations for the interrupt handlers used by the application. // //***************************************************************************** extern void SysTickIntHandler(void); extern void UARTStdioIntHandler(void); extern void USB0DeviceIntHandler(void); //***************************************************************************** // // The entry point for the application. // //***************************************************************************** extern int main(void); //***************************************************************************** // // Reserve space for the system stack. // //***************************************************************************** static unsigned long pulStack[160]; //***************************************************************************** // // The vector table. Note that the proper constructs must be placed on this to // ensure that it ends up at physical address 0x0000.0000. // //***************************************************************************** __attribute__ ((section(".isr_vector"))) void (* const g_pfnVectors[])(void) = { (void (*)(void))((unsigned long)pulStack + sizeof(pulStack)), // The initial stack pointer ResetISR, // The reset handler NmiSR, // The NMI handler FaultISR, // The hard fault handler IntDefaultHandler, // The MPU fault handler IntDefaultHandler, // The bus fault handler IntDefaultHandler, // The usage fault handler 0, // Reserved 0, // Reserved 0, // Reserved 0, // Reserved IntDefaultHandler, // SVCall handler IntDefaultHandler, // Debug monitor handler 0, // Reserved IntDefaultHandler, // The PendSV handler SysTickIntHandler, // The SysTick handler IntDefaultHandler, // GPIO Port A IntDefaultHandler, // GPIO Port B IntDefaultHandler, // GPIO Port C IntDefaultHandler, // GPIO Port D IntDefaultHandler, // GPIO Port E UARTStdioIntHandler, // UART0 Rx and Tx IntDefaultHandler, // UART1 Rx and Tx IntDefaultHandler, // SSI0 Rx and Tx IntDefaultHandler, // I2C0 Master and Slave IntDefaultHandler, // PWM Fault IntDefaultHandler, // PWM Generator 0 IntDefaultHandler, // PWM Generator 1 IntDefaultHandler, // PWM Generator 2 IntDefaultHandler, // Quadrature Encoder 0 IntDefaultHandler, // ADC Sequence 0 IntDefaultHandler, // ADC Sequence 1 IntDefaultHandler, // ADC Sequence 2 IntDefaultHandler, // ADC Sequence 3 IntDefaultHandler, // Watchdog timer IntDefaultHandler, // Timer 0 subtimer A IntDefaultHandler, // Timer 0 subtimer B IntDefaultHandler, // Timer 1 subtimer A IntDefaultHandler, // Timer 1 subtimer B IntDefaultHandler, // Timer 2 subtimer A IntDefaultHandler, // Timer 2 subtimer B IntDefaultHandler, // Analog Comparator 0 IntDefaultHandler, // Analog Comparator 1 IntDefaultHandler, // Analog Comparator 2 IntDefaultHandler, // System Control (PLL, OSC, BO) IntDefaultHandler, // FLASH Control IntDefaultHandler, // GPIO Port F IntDefaultHandler, // GPIO Port G IntDefaultHandler, // GPIO Port H IntDefaultHandler, // UART2 Rx and Tx IntDefaultHandler, // SSI1 Rx and Tx IntDefaultHandler, // Timer 3 subtimer A IntDefaultHandler, // Timer 3 subtimer B IntDefaultHandler, // I2C1 Master and Slave IntDefaultHandler, // Quadrature Encoder 1 IntDefaultHandler, // CAN0 IntDefaultHandler, // CAN1 IntDefaultHandler, // CAN2 IntDefaultHandler, // Ethernet IntDefaultHandler, // Hibernate USB0DeviceIntHandler, // USB0 IntDefaultHandler, // PWM Generator 3 IntDefaultHandler, // uDMA Software Transfer IntDefaultHandler // uDMA Error }; //***************************************************************************** // // The following are constructs created by the linker, indicating where the // the "data" and "bss" segments reside in memory. The initializers for the // for the "data" segment resides immediately following the "text" segment. // //***************************************************************************** extern unsigned long _etext; extern unsigned long _data; extern unsigned long _edata; extern unsigned long _bss; extern unsigned long _ebss; //***************************************************************************** // // This is the code that gets called when the processor first starts execution // following a reset event. Only the absolutely necessary set is performed, // after which the application supplied entry() routine is called. Any fancy // actions (such as making decisions based on the reset cause register, and // resetting the bits in that register) are left solely in the hands of the // application. // //***************************************************************************** void ResetISR(void) { unsigned long *pulSrc, *pulDest; // // Copy the data segment initializers from flash to SRAM. // pulSrc = &_etext; for(pulDest = &_data; pulDest < &_edata; ) { *pulDest++ = *pulSrc++; } // // Zero fill the bss segment. // __asm(" ldr r0, =_bss\n" " ldr r1, =_ebss\n" " mov r2, #0\n" " .thumb_func\n" "zero_loop:\n" " cmp r0, r1\n" " it lt\n" " strlt r2, [r0], #4\n" " blt zero_loop"); // // Call the application's entry point. // main(); } //***************************************************************************** // // This is the code that gets called when the processor receives a NMI. This // simply enters an infinite loop, preserving the system state for examination // by a debugger. // //***************************************************************************** static void NmiSR(void) { // // Enter an infinite loop. // while(1) { } } //***************************************************************************** // // This is the code that gets called when the processor receives a fault // interrupt. This simply enters an infinite loop, preserving the system state // for examination by a debugger. // //***************************************************************************** static void FaultISR(void) { // // Enter an infinite loop. // while(1) { } } //***************************************************************************** // // This is the code that gets called when the processor receives an unexpected // interrupt. This simply enters an infinite loop, preserving the system state // for examination by a debugger. // //***************************************************************************** static void IntDefaultHandler(void) { // // Go into an infinite loop. // while(1) { } }
the_stack_data/69736.c
#include <stdio.h> #pragma cle def PURPLE {"level":"purple"} #pragma cle def PURPLE_SHAREABLE { "level": "purple", \ "cdf": [ \ {"remotelevel": "orange", \ "direction": "bidirectional", \ "guarddirective": { "operation": "allow"} } \ ]} #pragma cle def XDLINKAGE_GET_EWMA {"level":"purple", \ "cdf": [\ {"remotelevel":"orange", \ "direction": "bidirectional", \ "guarddirective": { "operation": "allow"}, \ "argtaints": [["TAG_REQUEST_GET_EWMA"]], \ "codtaints": ["PURPLE", "PURPLE_SHAREABLE"], \ "rettaints": ["TAG_RESPONSE_GET_EWMA"] },\ {"remotelevel":"purple", \ "direction": "bidirectional", \ "guarddirective": { "operation": "allow"}, \ "argtaints": [["TAG_REQUEST_GET_EWMA"]], \ "codtaints": ["PURPLE", "PURPLE_SHAREABLE"], \ "rettaints": ["TAG_RESPONSE_GET_EWMA"] }\ ] } #pragma cle def ORANGE {"level":"orange",\ "cdf": [\ {"remotelevel":"purple", \ "direction": "egress", \ "guarddirective": { "operation": "allow"}}\ ] } double calc_ewma(double a, double b) { const double alpha = 0.25; static double c = 0.0; c = alpha * (a + b) + (1 - alpha) * c; return c; } double get_a() { #pragma cle begin ORANGE static double a = 0.0; #pragma cle end ORANGE a += 1; return a; } double get_b() { #pragma cle begin PURPLE static double b = 1.0; #pragma cle end PURPLE b += b; return b; } #pragma cle begin XDLINKAGE_GET_EWMA double get_ewma(double x) { #pragma cle end XDLINKAGE_GET_EWMA #pragma cle begin PURPLE_SHAREABLE double x1, y1, z1; #pragma cle end PURPLE_SHAREABLE x1 = x; y1 = get_b(); z1 = calc_ewma(x1, y1); return z1; } int ewma_main() { double x; double y; #pragma cle begin ORANGE double ewma; #pragma cle end ORANGE for (int i=0; i < 10; i++) { x = get_a(); ewma = get_ewma(x); printf("%f\n", ewma); } return 0; } int main() { return ewma_main(); }
the_stack_data/184516837.c
// Copyright (c) 2015, UChicago Argonne, LLC. All rights reserved. // Copyright 2015. UChicago Argonne, LLC. This software was produced // under U.S. Government contract DE-AC02-06CH11357 for Argonne National // Laboratory (ANL), which is operated by UChicago Argonne, LLC for the // U.S. Department of Energy. The U.S. Government has rights to use, // reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR // UChicago Argonne, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR // ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is // modified to produce derivative works, such modified software should // be clearly marked, so as not to confuse it with the version available // from ANL. // Additionally, redistribution and use in source and binary forms, with // or without modification, are permitted provided that the following // conditions are met: // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in // the documentation andwith the // distribution. // * Neither the name of UChicago Argonne, LLC, Argonne National // Laboratory, ANL, the U.S. Government, 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 UChicago Argonne, LLC 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 UChicago // Argonne, LLC 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. // --------------------------------------------------------------- // TOMOPY class header //
the_stack_data/895495.c
#ifndef TH_GENERIC_FILE #define TH_GENERIC_FILE "generic/THBlas.c" #else #ifdef BLAS_F2C # define ffloat double #else # define ffloat float #endif TH_EXTERNC void dswap_(int *n, double *x, int *incx, double *y, int *incy); TH_EXTERNC void sswap_(int *n, float *x, int *incx, float *y, int *incy); TH_EXTERNC void dscal_(int *n, double *a, double *x, int *incx); TH_EXTERNC void sscal_(int *n, float *a, float *x, int *incx); TH_EXTERNC void dcopy_(int *n, double *x, int *incx, double *y, int *incy); TH_EXTERNC void scopy_(int *n, float *x, int *incx, float *y, int *incy); TH_EXTERNC void daxpy_(int *n, double *a, double *x, int *incx, double *y, int *incy); TH_EXTERNC void saxpy_(int *n, float *a, float *x, int *incx, float *y, int *incy); TH_EXTERNC double ddot_(int *n, double *x, int *incx, double *y, int *incy); TH_EXTERNC ffloat sdot_(int *n, float *x, int *incx, float *y, int *incy); TH_EXTERNC void dgemv_(char *trans, int *m, int *n, double *alpha, double *a, int *lda, double *x, int *incx, double *beta, double *y, int *incy); TH_EXTERNC void sgemv_(char *trans, int *m, int *n, float *alpha, float *a, int *lda, float *x, int *incx, float *beta, float *y, int *incy); TH_EXTERNC void dger_(int *m, int *n, double *alpha, double *x, int *incx, double *y, int *incy, double *a, int *lda); TH_EXTERNC void sger_(int *m, int *n, float *alpha, float *x, int *incx, float *y, int *incy, float *a, int *lda); TH_EXTERNC void dgemm_(char *transa, char *transb, int *m, int *n, int *k, double *alpha, double *a, int *lda, double *b, int *ldb, double *beta, double *c, int *ldc); TH_EXTERNC void sgemm_(char *transa, char *transb, int *m, int *n, int *k, float *alpha, float *a, int *lda, float *b, int *ldb, float *beta, float *c, int *ldc); void THBlas_(swap)(long n, real *x, long incx, real *y, long incy) { if(n == 1) { incx = 1; incy = 1; } #if defined(USE_BLAS) && (defined(TH_REAL_IS_DOUBLE) || defined(TH_REAL_IS_FLOAT)) if( (n <= INT_MAX) && (incx <= INT_MAX) && (incy <= INT_MAX) ) { int i_n = (int)n; int i_incx = (int)incx; int i_incy = (int)incy; #if defined(TH_REAL_IS_DOUBLE) dswap_(&i_n, x, &i_incx, y, &i_incy); #else sswap_(&i_n, x, &i_incx, y, &i_incy); #endif return; } #endif { long i; for(i = 0; i < n; i++) { real z = x[i*incx]; x[i*incx] = y[i*incy]; y[i*incy] = z; } } } void THBlas_(scal)(long n, real a, real *x, long incx) { if(n == 1) incx = 1; #if defined(USE_BLAS) && (defined(TH_REAL_IS_DOUBLE) || defined(TH_REAL_IS_FLOAT)) if( (n <= INT_MAX) && (incx <= INT_MAX) ) { int i_n = (int)n; int i_incx = (int)incx; #if defined(TH_REAL_IS_DOUBLE) dscal_(&i_n, &a, x, &i_incx); #else sscal_(&i_n, &a, x, &i_incx); #endif return; } #endif { long i; for(i = 0; i < n; i++) x[i*incx] *= a; } } void THBlas_(copy)(long n, real *x, long incx, real *y, long incy) { if(n == 1) { incx = 1; incy = 1; } #if defined(USE_BLAS) && (defined(TH_REAL_IS_DOUBLE) || defined(TH_REAL_IS_FLOAT)) if( (n <= INT_MAX) && (incx <= INT_MAX) && (incy <= INT_MAX) ) { int i_n = (int)n; int i_incx = (int)incx; int i_incy = (int)incy; #if defined(TH_REAL_IS_DOUBLE) dcopy_(&i_n, x, &i_incx, y, &i_incy); #else scopy_(&i_n, x, &i_incx, y, &i_incy); #endif return; } #endif { long i; for(i = 0; i < n; i++) y[i*incy] = x[i*incx]; } } void THBlas_(axpy)(long n, real a, real *x, long incx, real *y, long incy) { if(n == 1) { incx = 1; incy = 1; } #if defined(USE_BLAS) && (defined(TH_REAL_IS_DOUBLE) || defined(TH_REAL_IS_FLOAT)) if( (n <= INT_MAX) && (incx <= INT_MAX) && (incy <= INT_MAX) ) { int i_n = (int)n; int i_incx = (int)incx; int i_incy = (int)incy; #if defined(TH_REAL_IS_DOUBLE) daxpy_(&i_n, &a, x, &i_incx, y, &i_incy); #else saxpy_(&i_n, &a, x, &i_incx, y, &i_incy); #endif return; } #endif { long i; for(i = 0; i < n; i++) y[i*incy] += a*x[i*incx]; } } real THBlas_(dot)(long n, real *x, long incx, real *y, long incy) { if(n == 1) { incx = 1; incy = 1; } #if defined(USE_BLAS) && (defined(TH_REAL_IS_DOUBLE) || defined(TH_REAL_IS_FLOAT)) if( (n <= INT_MAX) && (incx <= INT_MAX) && (incy <= INT_MAX) ) { int i_n = (int)n; int i_incx = (int)incx; int i_incy = (int)incy; #if defined(TH_REAL_IS_DOUBLE) return (real) ddot_(&i_n, x, &i_incx, y, &i_incy); #else return (real) sdot_(&i_n, x, &i_incx, y, &i_incy); #endif } #endif { long i; real sum = 0; for(i = 0; i < n; i++) sum += x[i*incx]*y[i*incy]; return sum; } } void THBlas_(gemv)(char trans, long m, long n, real alpha, real *a, long lda, real *x, long incx, real beta, real *y, long incy) { if(n == 1) lda = m; #if defined(USE_BLAS) && (defined(TH_REAL_IS_DOUBLE) || defined(TH_REAL_IS_FLOAT)) if( (m <= INT_MAX) && (n <= INT_MAX) && (lda > 0) && (lda <= INT_MAX) && (incx > 0) && (incx <= INT_MAX) && (incy > 0) && (incy <= INT_MAX) ) { int i_m = (int)m; int i_n = (int)n; int i_lda = (int)lda; int i_incx = (int)incx; int i_incy = (int)incy; #if defined(TH_REAL_IS_DOUBLE) dgemv_(&trans, &i_m, &i_n, &alpha, a, &i_lda, x, &i_incx, &beta, y, &i_incy); #else sgemv_(&trans, &i_m, &i_n, &alpha, a, &i_lda, x, &i_incx, &beta, y, &i_incy); #endif return; } #endif { long i, j; if( (trans == 'T') || (trans == 't') ) { for(i = 0; i < n; i++) { real sum = 0; real *row_ = a+lda*i; for(j = 0; j < m; j++) sum += x[j*incx]*row_[j]; y[i*incy] = beta*y[i*incy] + alpha*sum; } } else { if(beta != 1) THBlas_(scal)(m, beta, y, incy); for(j = 0; j < n; j++) { real *column_ = a+lda*j; real z = alpha*x[j*incx]; for(i = 0; i < m; i++) y[i*incy] += z*column_[i]; } } } } void THBlas_(ger)(long m, long n, real alpha, real *x, long incx, real *y, long incy, real *a, long lda) { if(n == 1) lda = m; #if defined(USE_BLAS) && (defined(TH_REAL_IS_DOUBLE) || defined(TH_REAL_IS_FLOAT)) if( (m <= INT_MAX) && (n <= INT_MAX) && (lda <= INT_MAX) && (incx <= INT_MAX) && (incy <= INT_MAX) ) { int i_m = (int)m; int i_n = (int)n; int i_lda = (int)lda; int i_incx = (int)incx; int i_incy = (int)incy; #if defined(TH_REAL_IS_DOUBLE) dger_(&i_m, &i_n, &alpha, x, &i_incx, y, &i_incy, a, &i_lda); #else sger_(&i_m, &i_n, &alpha, x, &i_incx, y, &i_incy, a, &i_lda); #endif return; } #endif { long i, j; for(j = 0; j < n; j++) { real *column_ = a+j*lda; real z = alpha*y[j*incy]; for(i = 0; i < m; i++) column_[i] += z*x[i*incx] ; } } } void THBlas_(gemm)(char transa, char transb, long m, long n, long k, real alpha, real *a, long lda, real *b, long ldb, real beta, real *c, long ldc) { int transa_ = ((transa == 't') || (transa == 'T')); int transb_ = ((transb == 't') || (transb == 'T')); if(n == 1) ldc = m; if(transa_) { if(m == 1) lda = k; } else { if(k == 1) lda = m; } if(transb_) { if(k == 1) ldb = n; } else { if(n == 1) ldb = k; } #if defined(USE_BLAS) && (defined(TH_REAL_IS_DOUBLE) || defined(TH_REAL_IS_FLOAT)) if( (m <= INT_MAX) && (n <= INT_MAX) && (k <= INT_MAX) && (lda <= INT_MAX) && (ldb <= INT_MAX) && (ldc <= INT_MAX) ) { int i_m = (int)m; int i_n = (int)n; int i_k = (int)k; int i_lda = (int)lda; int i_ldb = (int)ldb; int i_ldc = (int)ldc; #if defined(TH_REAL_IS_DOUBLE) dgemm_(&transa, &transb, &i_m, &i_n, &i_k, &alpha, a, &i_lda, b, &i_ldb, &beta, c, &i_ldc); #else sgemm_(&transa, &transb, &i_m, &i_n, &i_k, &alpha, a, &i_lda, b, &i_ldb, &beta, c, &i_ldc); #endif return; } #endif { long i, j, l; if(!transa_ && !transb_) { real *a_ = a; for(i = 0; i < m; i++) { real *b_ = b; for(j = 0; j < n; j++) { real sum = 0; for(l = 0; l < k; l++) sum += a_[l*lda]*b_[l]; b_ += ldb; c[j*ldc+i] = beta*c[j*ldc+i]+alpha*sum; } a_++; } } else if(transa_ && !transb_) { real *a_ = a; for(i = 0; i < m; i++) { real *b_ = b; for(j = 0; j < n; j++) { real sum = 0; for(l = 0; l < k; l++) sum += a_[l]*b_[l]; b_ += ldb; c[j*ldc+i] = beta*c[j*ldc+i]+alpha*sum; } a_ += lda; } } else if(!transa_ && transb_) { real *a_ = a; for(i = 0; i < m; i++) { real *b_ = b; for(j = 0; j < n; j++) { real sum = 0; for(l = 0; l < k; l++) sum += a_[l*lda]*b_[l*ldb]; b_++; c[j*ldc+i] = beta*c[j*ldc+i]+alpha*sum; } a_++; } } else { real *a_ = a; for(i = 0; i < m; i++) { real *b_ = b; for(j = 0; j < n; j++) { real sum = 0; for(l = 0; l < k; l++) sum += a_[l]*b_[l*ldb]; b_++; c[j*ldc+i] = beta*c[j*ldc+i]+alpha*sum; } a_ += lda; } } } } #endif
the_stack_data/67326225.c
#include <stdint.h> long softint_mul( long x, long y ) { int i; long result = 0; for (i = 0; i < (sizeof(long) << 3); i++) { if ((x & 0x1) == 1) result = result + y; x = x >> 1; y = y << 1; } return result; }
the_stack_data/24761.c
#include <stdio.h> #include <stdlib.h> #include <limits.h> #define MAX_N 500 #define CIDADE(n) ((n) - 1) void limparConexoes(int conexoes[][MAX_N], int N); int obterNoComMenorDistancia(int *distancia, int *visitado, int N); int calcularTempoDeEntrega(int conexoes[][MAX_N], int N, int origem, int destino); int *cache[MAX_N]; int main (void) { int N, E, X, Y, H, K, O, D; int conexoes[MAX_N][MAX_N]; while (scanf("%d %d", &N, &E), N != 0 || E != 0) { int i; limparConexoes(conexoes, N); for (i = 0; i < N; i++) { if (cache[i] != NULL) { free(cache[i]); cache[i] = NULL; } } for (i = 0; i < E; i++) { scanf("%d %d %d", &X, &Y, &H); if (conexoes[CIDADE(Y)][CIDADE(X)] < INT_MAX) { conexoes[CIDADE(X)][CIDADE(Y)] = conexoes[CIDADE(Y)][CIDADE(X)] = 0; } else { conexoes[CIDADE(X)][CIDADE(Y)] = H; } } scanf("%d", &K); for (i = 0; i < K; i++) { scanf("%d %d", &O, &D); int tempoParaSerEntregue = calcularTempoDeEntrega(conexoes, N, CIDADE(O), CIDADE(D)); if (tempoParaSerEntregue == 0) { printf("0\n"); } else if (tempoParaSerEntregue == INT_MAX) { printf("Nao e possivel entregar a carta\n"); } else { printf("%d\n", tempoParaSerEntregue); } } printf("\n"); } return 0; } void limparConexoes(int conexoes[][MAX_N], int N) { int i, j; for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { conexoes[i][j] = INT_MAX; } } } int obterNoComMenorDistancia(int *distancia, int *visitado, int N) { int i, menorIndice = 0, menorValor = INT_MAX; for (i = 0; i < N; i++) { if (distancia[i] < menorValor && !visitado[i]) { menorIndice = i; menorValor = distancia[i]; } } return menorIndice; } int calcularTempoDeEntrega(int conexoes[][MAX_N], int N, int origem, int destino) { if (conexoes[origem][destino] == 0) { return 0; } else if (cache[origem] != NULL) { return cache[origem][destino]; } else { int i; int visitado[N]; int *distancia = malloc(sizeof(int) * N); cache[origem] = distancia; for (i = 0; i < N; i++) { visitado[i] = 0; distancia[i] = INT_MAX; } distancia[origem] = 0; for (i = 0; i < N - 1; i++) { int noDestino, noOrigem = obterNoComMenorDistancia(distancia, visitado, N); visitado[noOrigem] = 1; for (noDestino = 0; noDestino < N; noDestino++) { if (!visitado[noDestino] && distancia[noOrigem] < INT_MAX && conexoes[noOrigem][noDestino] < INT_MAX && distancia[noOrigem] + conexoes[noOrigem][noDestino] < distancia[noDestino]) { distancia[noDestino] = distancia[noOrigem] + conexoes[noOrigem][noDestino]; } } } return distancia[destino]; } }
the_stack_data/45451137.c
#include <string.h> #define GZIPSUFFIX ".gz" #define GZIPSUFFIXLENGTH (sizeof(GZIPSUFFIX)-1) unsigned char checkgzipsuffix(const char *filename) { size_t filenamelength = strlen (filename); if (filenamelength < GZIPSUFFIXLENGTH || strcmp (filename + filenamelength - GZIPSUFFIXLENGTH, GZIPSUFFIX) != 0) { return 0; } return (unsigned char) 1; }
the_stack_data/151701726.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 */ /* Type definitions */ typedef scalar_t__ u8 ; struct wpa_supplicant {int owe_transition_search; scalar_t__ owe_transition_select; } ; struct wpa_ssid {int key_mgmt; scalar_t__* wep_key_len; size_t wep_tx_keyidx; int proto; int pairwise_cipher; int group_cipher; int group_mgmt_cipher; scalar_t__ owe_transition_bss_select_count; scalar_t__ owe_only; } ; struct wpa_ie_data {int pairwise_cipher; int group_cipher; int proto; int mgmt_group_cipher; int key_mgmt; int capabilities; int /*<<< orphan*/ has_group; int /*<<< orphan*/ has_pairwise; } ; struct wpa_bss {int /*<<< orphan*/ freq; } ; /* Variables and functions */ scalar_t__ MAX_OWE_TRANSITION_BSS_SELECT_COUNT ; int /*<<< orphan*/ MBO_ATTR_ID_AP_CAPA_IND ; scalar_t__ MGMT_FRAME_PROTECTION_REQUIRED ; int /*<<< orphan*/ MSG_DEBUG ; scalar_t__ NO_MGMT_FRAME_PROTECTION ; int /*<<< orphan*/ OSEN_IE_VENDOR_TYPE ; int /*<<< orphan*/ OWE_IE_VENDOR_TYPE ; int /*<<< orphan*/ WLAN_EID_RSN ; int WPA_CAPABILITY_MFPC ; int WPA_CAPABILITY_MFPR ; int WPA_CIPHER_WEP104 ; int WPA_CIPHER_WEP40 ; int /*<<< orphan*/ WPA_IE_VENDOR_TYPE ; int WPA_KEY_MGMT_IEEE8021X_NO_WPA ; int WPA_KEY_MGMT_NONE ; int WPA_KEY_MGMT_OSEN ; int WPA_KEY_MGMT_OWE ; int WPA_PROTO_OSEN ; int WPA_PROTO_RSN ; int WPA_PROTO_WPA ; scalar_t__* wpa_bss_get_ie (struct wpa_bss*,int /*<<< orphan*/ ) ; scalar_t__* wpa_bss_get_vendor_ie (struct wpa_bss*,int /*<<< orphan*/ ) ; int /*<<< orphan*/ wpa_dbg (struct wpa_supplicant*,int /*<<< orphan*/ ,char*,...) ; void* wpa_default_rsn_cipher (int /*<<< orphan*/ ) ; scalar_t__ wpa_key_mgmt_wpa (int) ; scalar_t__ wpa_parse_wpa_ie (scalar_t__ const*,scalar_t__ const,struct wpa_ie_data*) ; scalar_t__ wpas_get_ssid_pmf (struct wpa_supplicant*,struct wpa_ssid*) ; scalar_t__ wpas_mbo_get_bss_attr (struct wpa_bss*,int /*<<< orphan*/ ) ; int wpas_wps_ssid_bss_match (struct wpa_supplicant*,struct wpa_ssid*,struct wpa_bss*) ; __attribute__((used)) static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, struct wpa_bss *bss, int debug_print) { struct wpa_ie_data ie; int proto_match = 0; const u8 *rsn_ie, *wpa_ie; int ret; int wep_ok; ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); if (ret >= 0) return ret; /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */ wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) && (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) && ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) || (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)); rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) { proto_match++; if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse failed"); break; } if (!ie.has_pairwise) ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq); if (!ie.has_group) ie.group_cipher = wpa_default_rsn_cipher(bss->freq); if (wep_ok && (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN in RSN IE"); return 1; } if (!(ie.proto & ssid->proto) && !(ssid->proto & WPA_PROTO_OSEN)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto mismatch"); break; } if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK cipher mismatch"); break; } if (!(ie.group_cipher & ssid->group_cipher)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK cipher mismatch"); break; } if (ssid->group_mgmt_cipher && !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - group mgmt cipher mismatch"); break; } if (!(ie.key_mgmt & ssid->key_mgmt)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt mismatch"); break; } #ifdef CONFIG_IEEE80211W if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt frame protection"); break; } #endif /* CONFIG_IEEE80211W */ if ((ie.capabilities & WPA_CAPABILITY_MFPR) && wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt frame protection enabled but AP requires it"); break; } #ifdef CONFIG_MBO if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && wpas_mbo_get_bss_attr(bss, MBO_ATTR_ID_AP_CAPA_IND) && wpas_get_ssid_pmf(wpa_s, ssid) != NO_MGMT_FRAME_PROTECTION) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt frame protection enabled on MBO AP"); break; } #endif /* CONFIG_MBO */ if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE"); return 1; } #ifdef CONFIG_IEEE80211W if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED && (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip - MFP Required but network not MFP Capable"); return 0; } #endif /* CONFIG_IEEE80211W */ wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { proto_match++; if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse failed"); break; } if (wep_ok && (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN in WPA IE"); return 1; } if (!(ie.proto & ssid->proto)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto mismatch"); break; } if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK cipher mismatch"); break; } if (!(ie.group_cipher & ssid->group_cipher)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK cipher mismatch"); break; } if (!(ie.key_mgmt & ssid->key_mgmt)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt mismatch"); break; } if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE"); return 1; } if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie && !rsn_ie) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X"); return 1; } #ifdef CONFIG_OWE if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only && !wpa_ie && !rsn_ie) { if (wpa_s->owe_transition_select && wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) && ssid->owe_transition_bss_select_count + 1 <= MAX_OWE_TRANSITION_BSS_SELECT_COUNT) { ssid->owe_transition_bss_select_count++; if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip OWE transition BSS (selection count %d does not exceed %d)", ssid->owe_transition_bss_select_count, MAX_OWE_TRANSITION_BSS_SELECT_COUNT); wpa_s->owe_transition_search = 1; return 0; } if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " allow in OWE transition mode"); return 1; } #endif /* CONFIG_OWE */ if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) && wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match"); return 0; } if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN"); return 1; } if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) { if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2"); return 1; } if (debug_print) wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with WPA/WPA2"); return 0; }
the_stack_data/178265544.c
#include<stdio.h> int main() { //Array declaration int arr[5][3]; //2D Array input printf("Matrix Input\n"); for (int i = 0; i < 5; i++) { for (int j = 0; j < 3; j++) { printf("Enter the element : "); scanf("%d",&arr[i][j]); } } //2D Array printing/Matrix printing printf("Matrix printing\n"); for (int i = 0; i < 5; i++) { for (int j = 0; j < 3; j++) { printf("Element at [%d][%d] is %d\n",i,j,arr[i][j]); } } }