file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/25138387.c
// TODO // alocati global un vector vect de n elemente de tip struct particle // cate elemente puteti aloca maxim (aproximativ)? // -> porniti de la 1.000.000 elemente; inmultiti cu 10 #include <math.h> #include <stddef.h> #include <stdio.h> #include <stdint.h> // provides int8_t, uint8_t, int16_t etc. #include <stdlib.h> // bss pentru NMAX 1000000000: 3 000 000 032 -> merge // bss pentru NMAX 10000000000: 30 000 000 032 -> da segfault #define NMAX 10000000000 struct particle { int8_t v_x, v_y, v_z; }; // global struct particle vect[NMAX]; int main(int argc, char* argv[]) { if(argc < 2) { printf("apelati cu %s <n>\n", argv[0]); return -1; } long n = atol(argv[1]); // generate some particles for(long i = 0; i < n; ++i) { vect[i].v_x = (uint8_t)rand(); vect[i].v_y = (uint8_t)rand(); vect[i].v_z = (uint8_t)rand(); } // compute max particle speed float max_speed = 0.0f; for(long i = 0; i < n; ++i) { float speed = sqrt(vect[i].v_x * vect[i].v_x + vect[i].v_y * vect[i].v_y + vect[i].v_z * vect[i].v_z); if(max_speed < speed) max_speed = speed; } // print result printf("viteza maxima este: %f\n", max_speed); return 0; }
the_stack_data/82950463.c
#include<stdio.h> int test(int a){ if(a==1){ return 3; } else { return 2*test(a-1)+1; } } int main() { int d; scanf("%d",&d); int b=test(d); printf("%d",b); getchar(); getchar(); }
the_stack_data/812136.c
#include <stdio.h> #include <fcntl.h> #include <unistd.h> #include <stdlib.h> #define BUFFERSIZE 20 #define MODE 0664 int main() { int fd1_count; int fd2_count; int fd3_count; char buf1[BUFFERSIZE]; char buf3[BUFFERSIZE]; const char file_path[] = "./test"; int in_fd; if ((in_fd = creat(file_path, MODE)) == -1) { perror("Cannot create test file"); exit(1); } // operation1 if ((fd1_count = read(in_fd, buf1, BUFFERSIZE)) == -1) { perror("fail to read in 1"); } printf("%s in 1\n", buf1); // operation2 if ((fd2_count = write(in_fd, "testing...", BUFFERSIZE)) == -1) { perror("fail to write in 2"); } // operation3 if ((fd3_count = read(in_fd, buf3, BUFFERSIZE)) == -1) { perror("Cannot open in 3"); } printf("%s in 3\n", buf3); return 0; }
the_stack_data/7914.c
/* Copyright (c) 2008, Lawrence E. Bassham, National Institute of Standards and Technology (NIST), for the original version (available at http://csrc.nist.gov/groups/ST/hash/sha-3/documents/KAT1.zip) 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 NIST nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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. */ /* Contributions were made by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni, Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby denoted as "the implementer". For more information, feedback or questions, please refer to our websites: http://keccak.noekeon.org/ http://keyak.noekeon.org/ http://ketje.noekeon.org/ To the extent possible under law, the implementer has waived all copyright and related or neighboring rights to the contributed source code in this file. http://creativecommons.org/publicdomain/zero/1.0/ */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <ctype.h> void Keccak(int rate, int capacity, const unsigned char *input, unsigned long long int inputByteLen, unsigned char delimitedSuffix, unsigned char *output, unsigned long long int outputByteLen); typedef unsigned char BitSequence; typedef size_t BitLength; typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2 } HashReturn; #define MAX_MARKER_LEN 50 #define SUBMITTER_INFO_LEN 128 typedef enum { KAT_SUCCESS = 0, KAT_FILE_OPEN_ERROR = 1, KAT_HEADER_ERROR = 2, KAT_DATA_ERROR = 3, KAT_HASH_ERROR = 4 } STATUS_CODES; #define ExcludeExtremelyLong #define SqueezingOutputLength 4096 STATUS_CODES genShortMsgHash(unsigned int rate, unsigned int capacity, unsigned char delimitedSuffix, unsigned int hashbitlen, unsigned int squeezedOutputLength, const char *fileName, const char *description); int FindMarker(FILE *infile, const char *marker); int ReadHex(FILE *infile, BitSequence *A, int Length, char *str); void fprintBstr(FILE *fp, char *S, BitSequence *A, int L); void convertShortMsgToPureLSB(void); STATUS_CODES genKAT_main(void) { /* The following instances are from the FIPS 202 standard. */ /* http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.202.pdf */ /* */ /* Note: "SakuraSequential" translates into "input followed by 11", */ /* see http://keccak.noekeon.org/Sakura.pdf for more details. */ /* */ genShortMsgHash(1344, 256, 0x1F, 0, 4096, "ShortMsgKAT_SHAKE128.txt", "Keccak(SakuraSequential|11)[r=1344, c=256], or SHAKE128 as in FIPS 202 standard"); genShortMsgHash(1088, 512, 0x1F, 0, 4096, "ShortMsgKAT_SHAKE256.txt", "Keccak(SakuraSequential|11)[r=1088, c=512], or SHAKE256 as in FIPS 202 standard"); genShortMsgHash(1152, 448, 0x06, 224, 0, "ShortMsgKAT_SHA3-224.txt", "Keccak(input|01)[r=1152, c=448] truncated to 224 bits, or SHA3-224 as in FIPS 202 standard"); genShortMsgHash(1088, 512, 0x06, 256, 0, "ShortMsgKAT_SHA3-256.txt", "Keccak(input|01)[r=1088, c=512] truncated to 256 bits, or SHA3-256 as in FIPS 202 standard"); genShortMsgHash(832, 768, 0x06, 384, 0, "ShortMsgKAT_SHA3-384.txt", "Keccak(input|01)[r=832, c=768] truncated to 384 bits, or SHA3-384 as in FIPS 202 standard"); genShortMsgHash(576, 1024, 0x06, 512, 0, "ShortMsgKAT_SHA3-512.txt", "Keccak(input|01)[r=576, c=1024] truncated to 512 bits, or SHA3-512 as in FIPS 202 standard"); return KAT_SUCCESS; } STATUS_CODES genShortMsgHash(unsigned int rate, unsigned int capacity, unsigned char delimitedSuffix, unsigned int hashbitlen, unsigned int squeezedOutputLength, const char *fileName, const char *description) { int msglen, msgbytelen; BitSequence Msg[256]; BitSequence Squeezed[SqueezingOutputLength/8]; FILE *fp_in, *fp_out; if ((squeezedOutputLength > SqueezingOutputLength) || (hashbitlen > SqueezingOutputLength)) { printf("Requested output length too long.\n"); return KAT_HASH_ERROR; } if ( (fp_in = fopen("ShortMsgKAT.txt", "r")) == NULL ) { printf("Couldn't open <ShortMsgKAT.txt> for read\n"); return KAT_FILE_OPEN_ERROR; } if ( (fp_out = fopen(fileName, "w")) == NULL ) { printf("Couldn't open <%s> for write\n", fileName); return KAT_FILE_OPEN_ERROR; } fprintf(fp_out, "# %s\n", description); do { if ( FindMarker(fp_in, "Len = ") ) fscanf(fp_in, "%d", &msglen); else { break; } msgbytelen = (msglen+7)/8; if ( !ReadHex(fp_in, Msg, msgbytelen, "Msg = ") ) { printf("ERROR: unable to read 'Msg' from <ShortMsgKAT.txt>\n"); return KAT_DATA_ERROR; } if ((msglen % 8) == 0) { fprintf(fp_out, "\nLen = %d\n", msglen); fprintBstr(fp_out, "Msg = ", Msg, msgbytelen); if (hashbitlen > 0) { Keccak(rate, capacity, Msg, msglen/8, delimitedSuffix, Squeezed, hashbitlen/8); fprintBstr(fp_out, "MD = ", Squeezed, hashbitlen/8); } else { Keccak(rate, capacity, Msg, msglen/8, delimitedSuffix, Squeezed, squeezedOutputLength/8); fprintBstr(fp_out, "Squeezed = ", Squeezed, squeezedOutputLength/8); } } } while ( 1 ); printf("finished ShortMsgKAT for <%s>\n", fileName); fclose(fp_in); fclose(fp_out); return KAT_SUCCESS; } /* */ /* ALLOW TO READ HEXADECIMAL ENTRY (KEYS, DATA, TEXT, etc.) */ /* */ int FindMarker(FILE *infile, const char *marker) { char line[MAX_MARKER_LEN]; int i, len; len = (int)strlen(marker); if ( len > MAX_MARKER_LEN-1 ) len = MAX_MARKER_LEN-1; for ( i=0; i<len; i++ ) if ( (line[i] = fgetc(infile)) == EOF ) return 0; line[len] = '\0'; while ( 1 ) { if ( !strncmp(line, marker, len) ) return 1; for ( i=0; i<len-1; i++ ) line[i] = line[i+1]; if ( (line[len-1] = fgetc(infile)) == EOF ) return 0; line[len] = '\0'; } /* shouldn't get here */ return 0; } /* */ /* ALLOW TO READ HEXADECIMAL ENTRY (KEYS, DATA, TEXT, etc.) */ /* */ int ReadHex(FILE *infile, BitSequence *A, int Length, char *str) { int i, ch, started; BitSequence ich = '\0'; if ( Length == 0 ) { A[0] = 0x00; return 1; } memset(A, 0x00, Length); started = 0; if ( FindMarker(infile, str) ) while ( (ch = fgetc(infile)) != EOF ) { if ( !isxdigit(ch) ) { if ( !started ) { if ( ch == '\n' ) break; else continue; } else break; } started = 1; if ( (ch >= '0') && (ch <= '9') ) ich = ch - '0'; else if ( (ch >= 'A') && (ch <= 'F') ) ich = ch - 'A' + 10; else if ( (ch >= 'a') && (ch <= 'f') ) ich = ch - 'a' + 10; for ( i=0; i<Length-1; i++ ) A[i] = (A[i] << 4) | (A[i+1] >> 4); A[Length-1] = (A[Length-1] << 4) | ich; } else return 0; return 1; } void fprintBstr(FILE *fp, char *S, BitSequence *A, int L) { int i; fprintf(fp, "%s", S); for ( i=0; i<L; i++ ) fprintf(fp, "%02X", A[i]); if ( L == 0 ) fprintf(fp, "00"); fprintf(fp, "\n"); }
the_stack_data/97013294.c
/*Exercise 2 - Selection Write a program to calculate the amount to be paid for a rented vehicle. • Input the distance the van has travelled • The first 30 km is at a rate of 50/= per km. • The remaining distance is calculated at the rate of 40/= per km. e.g. Distance -> 20 Amount = 20 x 50 = 1000 Distance -> 50 Amount = 30 x 50 + (50-30) x 40 = 2300*/ #include <stdio.h> int main() { int dis, amount = 0; printf("Enter distance : "); scanf("%d", &dis); if(dis < 30) { amount = 50 * dis; } else { amount = (50 * 30) + 40 * (dis-30); } printf("The Amount is : %d", amount); return 0; }
the_stack_data/211079803.c
/* * font8x16.c * * Standard VGA 8x16 font, code page 437. * * This is free and unencumbered software released into the public domain. * See the file COPYING for more details, or visit <http://unlicense.org>. */ const char font8x16[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0x81, 0xbd, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xff, 0xdb, 0xff, 0xff, 0xc3, 0xe7, 0xff, 0xff, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0xfe, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0xe7, 0xe7, 0xe7, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x7e, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x1e, 0x0e, 0x1a, 0x32, 0x78, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x33, 0x3f, 0x30, 0x30, 0x30, 0x30, 0x70, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x63, 0x7f, 0x63, 0x63, 0x63, 0x63, 0x67, 0xe7, 0xe6, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0xdb, 0x3c, 0xe7, 0x3c, 0xdb, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfe, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x0e, 0x1e, 0x3e, 0xfe, 0x3e, 0x1e, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xdb, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x60, 0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x38, 0x0c, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x6c, 0xfe, 0x6c, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x7c, 0x7c, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7c, 0xc6, 0xc2, 0xc0, 0x7c, 0x06, 0x06, 0x86, 0xc6, 0x7c, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc2, 0xc6, 0x0c, 0x18, 0x30, 0x60, 0xc6, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x76, 0xdc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xd6, 0xd6, 0xc6, 0xc6, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x06, 0x06, 0x3c, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1c, 0x3c, 0x6c, 0xcc, 0xfe, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xfc, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x60, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0x06, 0x06, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x06, 0x06, 0x0c, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x0c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xde, 0xde, 0xde, 0xdc, 0xc0, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x66, 0x66, 0x66, 0x66, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x6c, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x6c, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x62, 0x66, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xde, 0xc6, 0xc6, 0x66, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe6, 0x66, 0x66, 0x6c, 0x78, 0x78, 0x6c, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x62, 0x66, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xee, 0xfe, 0xfe, 0xd6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xde, 0x7c, 0x0c, 0x0e, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x6c, 0x66, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x60, 0x38, 0x0c, 0x06, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x5a, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xfe, 0xee, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0x6c, 0x7c, 0x38, 0x38, 0x7c, 0x6c, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0x86, 0x0c, 0x18, 0x30, 0x60, 0xc2, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x60, 0x60, 0x78, 0x6c, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x0c, 0x0c, 0x3c, 0x6c, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x36, 0x32, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0xcc, 0x78, 0x00, 0x00, 0x00, 0xe0, 0x60, 0x60, 0x6c, 0x76, 0x66, 0x66, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x0e, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0xe0, 0x60, 0x60, 0x66, 0x6c, 0x78, 0x78, 0x6c, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0xfe, 0xd6, 0xd6, 0xd6, 0xd6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0x0c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x76, 0x66, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x60, 0x38, 0x0c, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x36, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xfe, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x6c, 0x38, 0x38, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x0c, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xcc, 0x18, 0x30, 0x60, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x18, 0x18, 0x18, 0x70, 0x18, 0x18, 0x18, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x18, 0x18, 0x18, 0x0e, 0x18, 0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2, 0x66, 0x3c, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x38, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x18, 0x70, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x66, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x38, 0x10, 0x38, 0x6c, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x00, 0xfe, 0x66, 0x62, 0x68, 0x78, 0x68, 0x62, 0x66, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0x36, 0x36, 0x7e, 0xd8, 0xd8, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x6c, 0xcc, 0xcc, 0xfe, 0xcc, 0xcc, 0xcc, 0xcc, 0xce, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x0c, 0x78, 0x00, 0x00, 0xc6, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x64, 0x60, 0xf0, 0x60, 0x60, 0x60, 0x60, 0xe6, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xcc, 0xcc, 0xf8, 0xc4, 0xcc, 0xde, 0xcc, 0xcc, 0xcc, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x1b, 0x18, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x18, 0xd8, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x6c, 0x6c, 0x3e, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x60, 0xc0, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xe0, 0x62, 0x66, 0x6c, 0x18, 0x30, 0x60, 0xdc, 0x86, 0x0c, 0x18, 0x3e, 0x00, 0x00, 0x00, 0x60, 0xe0, 0x62, 0x66, 0x6c, 0x18, 0x30, 0x66, 0xce, 0x9a, 0x3f, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x6c, 0xd8, 0x6c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x6c, 0x36, 0x6c, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x06, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0xd8, 0xd8, 0xd8, 0xdc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0xd8, 0xcc, 0xc6, 0xc6, 0xc6, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0x60, 0x30, 0x18, 0x18, 0x30, 0x60, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x18, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0x6c, 0x6c, 0x6c, 0x6c, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x30, 0x18, 0x0c, 0x3e, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xdb, 0xdb, 0xdb, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x7e, 0xdb, 0xdb, 0xf3, 0x7e, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x30, 0x60, 0x60, 0x7c, 0x60, 0x60, 0x60, 0x30, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x1b, 0x1b, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x7e, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xec, 0x6c, 0x6c, 0x3c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x0c, 0x18, 0x32, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; /* * Local variables: * mode: C * c-file-style: "Linux" * c-basic-offset: 4 * tab-width: 4 * indent-tabs-mode: nil * End: */
the_stack_data/1048444.c
/* * Data: 2009-05-05 * Data modyfikacji: 2019-05-23 * Autor: Jakub Gasior <[email protected]> * Zmodyfikował: Marcin Kurdziel <https://github.com/Kot97> * Kompilacja: clang -o digest digest.c -lcrypto * Uruchamianie: ./digest <nazwa funkcji> * ./digest <nazwa funkcji> < NAZWA_PLIKU */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/err.h> #include <openssl/evp.h> int main(int argc, char **argv) { /* Wartosc zwracana przez funkcje: */ int retval; /* Wiadomosc: */ char message[64]; /* Skrot wiadomosci: */ unsigned char digest[EVP_MAX_MD_SIZE]; /* Rozmiar tekstu i szyfrogramu: */ unsigned int message_len, digest_len; const EVP_MD* md; if (argc != 2) { fprintf(stderr, "Invocation: %s <DIGEST NAME>\n", argv[0]); return 1; } /* Zaladowanie tekstowych opisow bledow: */ ERR_load_crypto_strings(); /* * Zaladowanie nazw funkcji skrotu do pamieci. * Wymagane przez EVP_get_digestbyname(): */ OpenSSL_add_all_digests(); md = EVP_get_digestbyname(argv[1]); if (!md) { fprintf(stderr, "Unknown message digest: %s\n", argv[1]); return 1; } /* Pobranie maksymalnie 64 znakow ze standardowego wejscia: */ if (fgets(message, 64, stdin) == NULL) { fprintf(stderr, "fgets() failed!\n"); return 1; } message_len = strlen(message); /* Kontekst: */ EVP_MD_CTX *ctx = EVP_MD_CTX_new(); /* Inicjalizacja kontekstu: */ EVP_MD_CTX_init(ctx); /* Parametry funkcji skrotu: */ fprintf(stdout, "Digest parameters:\n"); fprintf(stdout, "Block size: %d bits\n", EVP_MD_block_size(md)); fprintf(stdout, "Digest size: %d bytes\n\n", EVP_MD_size(md)); /* Konfiguracja kontekstu: */ retval = EVP_DigestInit_ex(ctx, md, NULL); if (!retval) { ERR_print_errors_fp(stderr); return 1; } /* Obliczenie skrotu: */ retval = EVP_DigestUpdate(ctx, message, message_len); if (!retval) { ERR_print_errors_fp(stderr); return 1; } /*Zapisanie skrotu w buforze 'digest': */ retval = EVP_DigestFinal_ex(ctx, digest, &digest_len); if (!retval) { ERR_print_errors_fp(stderr); return 1; } /* * Usuwa wszystkie informacje z kontekstu i zwalnia pamiec zwiazana * z kontekstem: */ EVP_MD_CTX_free(ctx); /* Usuniecie nazw funkcji skrotu z pamieci. */ EVP_cleanup(); fprintf(stdout, "Digest (hex): "); for (int i = 0; i < digest_len; ++i) fprintf(stdout, "%02x", digest[i]); fprintf(stdout, "\n"); if (ctx) free(ctx); /* Zwolnienie tekstowych opisow bledow: */ ERR_free_strings(); exit(EXIT_SUCCESS); }
the_stack_data/10517.c
#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> int main(int argc, char *argv[]) { int fd; char line[100]; fgets(line, 100, stdin); printf("%s",line ); fgets(line, 100, stdin); printf("%s",line ); fgets(line, 100, stdin); printf("%s",line ); close(0); fd = open("/etc/passwd", O_RDONLY); if(fd != 0) { fprintf(stderr, "Could not open data as fd 0\n"); exit(1); } fgets(line, 100, stdin); printf("%s",line ); fgets(line, 100, stdin); printf("%s",line ); fgets(line, 100, stdin); printf("%s",line ); return 0; }
the_stack_data/491477.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 long input[1] , unsigned long output[1] ) ; extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ; extern int gettimeofday(struct timeval *tv , void *tz , ...) ; extern int printf(char const *format , ...) ; int main(int argc , char *argv[] ) ; void megaInit(void) ; extern unsigned long strlen(char const *s ) ; extern long strtol(char const *str , char const *endptr , int base ) ; extern unsigned long strnlen(char const *s , unsigned long maxlen ) ; extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ; struct timeval { long tv_sec ; long tv_usec ; }; extern void *malloc(unsigned long size ) ; extern int scanf(char const *format , ...) ; void RandomFunc(unsigned long input[1] , unsigned long output[1] ) { unsigned long state[1] ; unsigned short copy12 ; unsigned int copy13 ; unsigned short copy14 ; { state[0UL] = (input[0UL] | 51238316UL) >> 3UL; if ((state[0UL] >> 3UL) & 1UL) { if ((state[0UL] >> 4UL) & 1UL) { copy12 = *((unsigned short *)(& state[0UL]) + 3); *((unsigned short *)(& state[0UL]) + 3) = *((unsigned short *)(& state[0UL]) + 1); *((unsigned short *)(& state[0UL]) + 1) = copy12; } else { state[0UL] <<= ((state[0UL] >> 3UL) & 7UL) | 1UL; copy13 = *((unsigned int *)(& state[0UL]) + 0); *((unsigned int *)(& state[0UL]) + 0) = *((unsigned int *)(& state[0UL]) + 1); *((unsigned int *)(& state[0UL]) + 1) = copy13; } } else { state[0UL] <<= (state[0UL] & 7UL) | 1UL; copy14 = *((unsigned short *)(& state[0UL]) + 1); *((unsigned short *)(& state[0UL]) + 1) = *((unsigned short *)(& state[0UL]) + 2); *((unsigned short *)(& state[0UL]) + 2) = copy14; } output[0UL] = (state[0UL] & 649724710UL) << 3UL; } } int main(int argc , char *argv[] ) { unsigned long input[1] ; unsigned long output[1] ; int randomFuns_i5 ; unsigned long 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 = strtoul(argv[randomFuns_i5 + 1], 0, 10); input[randomFuns_i5] = randomFuns_value6; randomFuns_i5 ++; } RandomFunc(input, output); if (output[0] == 4242424242UL) { printf("You win!\n"); } else { } randomFuns_main_i7 = 0; while (randomFuns_main_i7 < 1) { printf("%lu\n", output[randomFuns_main_i7]); randomFuns_main_i7 ++; } } } void megaInit(void) { { } }
the_stack_data/37251.c
#include <stdio.h> int main() { unsigned short n; scanf("%hu", &n); for(unsigned char i = 1; i <= 10; i++) printf("%u\n", n * i); return 0; }
the_stack_data/242330670.c
#include <stdio.h> void arrange(int,int); int array[100], array1[100]; int i, j, temp, max, count, maxdigits = 0, c = 0; void main() { int t1, t2, k, t, n = 1; printf("Enter size of array :"); scanf("%d", &count); printf("Enter elements into array :"); for (i = 0; i < count; i++) { scanf("%d", &array[i]); array1[i] = array[i]; } for (i = 0; i < count; i++) { t = array[i]; /*first element in t */ while(t > 0) { c++; t = t / 10; /* Find MSB */ } if (maxdigits < c) maxdigits = c; /* number of digits of a each number */ c = 0; } while(--maxdigits) n = n * 10; for (i = 0; i < count; i++) { max = array[i] / n; /* MSB - Dividnng by perticular base */ t = i; for (j = i + 1; j < count;j++) { if (max > (array[j] / n)) { max = array[j] / n; /* greatest MSB */ t = j; } } temp = array1[t]; array1[t] = array1[i]; array1[i] = temp; temp = array[t]; array[t] = array[i]; array[i] = temp; } while (n >= 1) { for (i = 0; i < count;) { t1 = array[i] / n; for (j = i + 1; t1 == (array[j] / n); j++); arrange(i, j); i = j; } n = n / 10; } printf("\nSorted Array (Postman sort) :"); for (i = 0; i < count; i++) printf("%d ", array1[i]); printf("\n"); } /* Function to arrange the of sequence having same base */ void arrange(int k,int n) { for (i = k; i < n - 1; i++) { for (j = i + 1; j < n; j++) { if (array1[i] > array1[j]) { temp = array1[i]; array1[i] = array1[j]; array1[j] = temp; temp = (array[i] % 10); array[i] = (array[j] % 10); array[j] = temp; } } } }
the_stack_data/38247.c
/* * Copyright (c) 2020 Antti Tiihala * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * ttf.c * TrueType glyph rendering (Dancy TTF) */ #include <limits.h> #include <stddef.h> int ttf_create(void **instance); int ttf_delete(void *ttf); int ttf_get_kerning(void *ttf, const unsigned int code_points[2], int *value); int ttf_open(void *ttf, size_t size, const void *ttf_file); int ttf_set_bitmap(void *ttf, size_t size, void *bitmap); int ttf_set_shades(void *ttf, unsigned int number); int ttf_render(void *ttf, unsigned int code_point, unsigned int *width); extern void free(void *ptr); extern void *malloc(size_t size); extern void *memcpy(void *s1, const void *s2, size_t n); extern void *memset(void *s, int c, size_t n); #if CHAR_BIT != 8 || INT_MAX < 2147483647 #error "Unsupported implementation-defined characteristics" #endif #define B8(a,b,c) (((unsigned int)((a)[(b)]) & 0xFFu) << (c)) #define BE16(a) (B8((a),0,8) | B8((a),1,0)) #define BE32(a) (B8((a),0,24) | B8((a),1,16) | B8((a),2,8) | B8((a),3,0)) #define W_BE16(a,d) ( \ *((a) + 1) = (unsigned char)(((unsigned int)(d) >> 0) & 0xFFu), \ *((a) + 0) = (unsigned char)(((unsigned int)(d) >> 8) & 0xFFu)) #define BE16_TO_INT(a) \ (((a) >= 0x8000u) ? -((int)((~(a) + 1u) & 0xFFFFu)) : (int)(a)) #define TTF_TABLE_CMAP (0x636D6170u) #define TTF_TABLE_GLYF (0x676C7966u) #define TTF_TABLE_HEAD (0x68656164u) #define TTF_TABLE_HHEA (0x68686561u) #define TTF_TABLE_HMTX (0x686D7478u) #define TTF_TABLE_KERN (0x6B65726Eu) #define TTF_TABLE_LOCA (0x6C6F6361u) #define TTF_TABLE_MAXP (0x6D617870u) struct ttf_glyph { unsigned int code_pnt; unsigned int loca_idx; unsigned int adv_width; unsigned int size; unsigned char *data; }; struct ttf_instance { struct ttf_glyph *glyph_array; unsigned char *bitmap; unsigned char *buffer; unsigned char *glyf; unsigned char *kern; size_t bitmap_size; size_t glyf_size; unsigned int em_value; unsigned int glyph_entries; unsigned int maxp_glyphs; unsigned int shades; unsigned int square; }; #define this_ttf ((struct ttf_instance *)(ttf)) int ttf_create(void **instance) { struct ttf_instance *ttf; const size_t buffer_size = 262144; unsigned char *buffer; ttf = malloc(sizeof(*ttf)); if ((*instance = ttf) == NULL) return 1; buffer = malloc(buffer_size); if (buffer == NULL) return free(ttf), 1; memset(ttf, 0, sizeof(*ttf)); memset(buffer, 0, buffer_size); ttf->glyph_array = NULL; ttf->bitmap = NULL; ttf->buffer = buffer; ttf->glyf = NULL; ttf->kern = NULL; return 0; } int ttf_delete(void *ttf) { if (ttf == NULL) return 1; free(this_ttf->glyph_array); free(this_ttf->buffer); free(this_ttf->glyf); free(this_ttf->kern); free(ttf); return 0; } static int handle_head(void *ttf, size_t size, const unsigned char *table) { unsigned int xmin, ymin, xmax, ymax; if (size != 54 || BE16(&table[18]) != 2048) return 1; xmin = BE16(&table[36]); ymin = (BE16(&table[38]) + 512) & 0xFFFFu; xmax = BE16(&table[40]); ymax = (BE16(&table[42]) + 512) & 0xFFFFu; if (xmin > xmax || xmax > 2048) return 1; if (ymin > ymax || ymax > 2048) return 1; if (BE16(&table[50]) != 1) return 1; return (void)ttf, 0; } static int handle_maxp(void *ttf, size_t size, const unsigned char *table) { unsigned int glyphs = (size == 32) ? BE16(&table[4]) : 0u; this_ttf->maxp_glyphs = glyphs; return (glyphs != 0) ? 0 : 1; } static int handle_hhea(void *ttf, size_t size, const unsigned char *table) { if (size != 36 || BE16(&table[34]) != this_ttf->maxp_glyphs) return 1; return 0; } static int handle_cmap(void *ttf, size_t size, const unsigned char *table) { const unsigned char *subtable = NULL; unsigned int i, val, offset = 0; struct cmap { unsigned int pnt; unsigned int idx; }; struct cmap *cmap_array = NULL; unsigned int cmap_points = 0; val = BE16(&table[2]); if (size < (val * 8 + 4)) return 1; for (i = 0; i < val; i++) { const unsigned char *p = &table[i * 8 + 4]; if (BE32(&p[4]) > size - 4) return 1; if (BE16(&p[0]) == 0) { unsigned int cmap_off = BE32(&p[4]); const unsigned char *cmap_sub = table + cmap_off; if (BE16(&cmap_sub[0]) == 12) { offset = cmap_off; subtable = cmap_sub; break; } } } if (subtable != NULL) { unsigned int add, len, groups; if (BE16(&subtable[2]) != 0) return 1; if (offset > size - 16) return 1; len = BE32(&subtable[4]); if (len < 16 || len > size - offset) return 1; groups = BE32(&subtable[12]); if (groups == 0 || ((len - 16) / 12) < groups) return 1; for (i = 0; i < groups; i++) { const unsigned char *p = subtable + (i * 12) + 16; unsigned int t1, t2; t1 = BE32(&p[0]); t2 = BE32(&p[4]); if (t1 > t2) return 1; add = (t2 - t1) + 1; if (!(cmap_points < UINT_MAX - add)) return 1; cmap_points += add; } if (cmap_points == 0 || cmap_points > 0x10FFFF) return 1; cmap_array = malloc(cmap_points * sizeof(struct cmap)); if (cmap_array == NULL) return 1; for (add = 0, i = 0; i < groups; i++) { const unsigned char *p = subtable + (i * 12) + 16; unsigned int t1, t2; unsigned int c, glyph_idx; t1 = BE32(&p[0]); t2 = BE32(&p[4]); glyph_idx = BE32(&p[8]); for (c = t1; c <= t2; c++) { if (glyph_idx >= this_ttf->maxp_glyphs) return free(cmap_array), 1; if (add >= cmap_points) return free(cmap_array), 1; cmap_array[add].pnt = c; cmap_array[add].idx = glyph_idx++; add += 1; } } if (add != cmap_points) return free(cmap_array), 1; } if (cmap_points == 0) return free(cmap_array), 1; size = (cmap_points + 1) * sizeof(struct ttf_glyph); this_ttf->glyph_array = malloc(size); if (this_ttf->glyph_array == NULL) return free(cmap_array), 1; memset(this_ttf->glyph_array, 0, size); this_ttf->glyph_array[0].data = NULL; for (i = 0; i < cmap_points; i++) { this_ttf->glyph_array[i + 1].code_pnt = cmap_array[i].pnt; this_ttf->glyph_array[i + 1].loca_idx = cmap_array[i].idx; this_ttf->glyph_array[i + 1].data = NULL; } this_ttf->glyph_entries = cmap_points + 1; return free(cmap_array), 0; } static int handle_glyf(void *ttf, size_t size, const unsigned char *table) { this_ttf->glyf = (size != 0) ? malloc(size) : NULL; if (this_ttf->glyf == NULL) return 1; memcpy(this_ttf->glyf, table, size); this_ttf->glyf_size = size; return 0; } static int handle_loca(void *ttf, size_t size, const unsigned char *table) { unsigned char *glyf = this_ttf->glyf; size_t glyf_size = this_ttf->glyf_size; unsigned int glyph_entries = this_ttf->glyph_entries; unsigned int loca_entries = (unsigned int)(size / 4); unsigned int i; if (loca_entries != (this_ttf->maxp_glyphs + 1)) return 1; for (i = 0; i < glyph_entries; i++) { unsigned int loca_idx = this_ttf->glyph_array[i].loca_idx; const unsigned char *p = table; unsigned int t1, t2; if (loca_entries < loca_idx + 1) return 1; p += loca_idx * 4; t1 = BE32(&p[0]); t2 = BE32(&p[4]); if (t1 > t2) return 1; if (t2 > glyf_size) return 1; this_ttf->glyph_array[i].data = &glyf[t1]; this_ttf->glyph_array[i].size = t2 - t1; } return 0; } static int handle_kern(void *ttf, size_t size, const unsigned char *table) { unsigned int pairs, subtable_size; if (size < 18) return 1; if (BE16(&table[0]) != 0) return 1; if (BE16(&table[2]) != 1) return 1; if (BE16(&table[4]) != 0) return 1; subtable_size = BE16(&table[6]); if (subtable_size != (unsigned long)(size - 4)) return 1; if (subtable_size < 14) return 1; if (BE16(&table[8]) != 1) return 1; pairs = BE16(&table[10]); if (subtable_size != (pairs * 6) + 14) return 1; this_ttf->kern = malloc(size); if (this_ttf->kern == NULL) return 1; memcpy(this_ttf->kern, table, size); return 0; } static int handle_hmtx(void *ttf, size_t size, const unsigned char *table) { unsigned int glyph_entries = this_ttf->glyph_entries; unsigned int maxp_glyphs = this_ttf->maxp_glyphs; unsigned int i; if (size == 0 || size != maxp_glyphs * 4) return 1; for (i = 0; i < glyph_entries; i++) { const unsigned char *p = table; unsigned int loca_idx = this_ttf->glyph_array[i].loca_idx; if (loca_idx >= maxp_glyphs) return 1; p += loca_idx * 4; this_ttf->glyph_array[i].adv_width = BE16(&p[0]); } return 0; } int ttf_get_kerning(void *ttf, const unsigned int code_points[2], int *value) { const unsigned char *kern = this_ttf->kern; unsigned int glyph_entries = this_ttf->glyph_entries; unsigned int c0 = code_points[0], c1 = code_points[1]; unsigned int i0 = UINT_MAX, i1 = UINT_MAX; unsigned int adv_width = 0; unsigned int i, pairs; if (value != NULL) *value = 0; if (kern == NULL) return 1; for (i = 1; i < glyph_entries; i++) { unsigned int code_pnt = this_ttf->glyph_array[i].code_pnt; if (code_pnt == c0) { adv_width = this_ttf->glyph_array[i].adv_width; i0 = this_ttf->glyph_array[i].loca_idx; } if (code_pnt == c1) { i1 = this_ttf->glyph_array[i].loca_idx; } if (i0 != UINT_MAX && i1 != UINT_MAX) break; } if (i0 == UINT_MAX || i1 == UINT_MAX || adv_width > 2048) return 2; pairs = BE16(&kern[10]); kern += 18; for (i = 0; i < pairs; i++) { unsigned int k = BE16(&kern[0]); if (k == i0 && BE16(&kern[2]) == i1) { unsigned int u = BE16(&kern[4]); int v = BE16_TO_INT(u); if (((int)adv_width + v) < 0) return 2; if (((int)adv_width + v) > 2048) return 2; if (value != NULL) { int em_value = (int)this_ttf->em_value; *value = (v * em_value) / 2048; } return 0; } if (k > i0) break; kern += 6; } return 2; } int ttf_open(void *ttf, size_t size, const void *ttf_file) { const unsigned char *p = ttf_file; struct { unsigned int name; unsigned int required; int (*func)(void *, size_t, const unsigned char *); } tables[] = { { TTF_TABLE_HEAD, 1, handle_head }, { TTF_TABLE_MAXP, 1, handle_maxp }, { TTF_TABLE_HHEA, 1, handle_hhea }, { TTF_TABLE_CMAP, 1, handle_cmap }, { TTF_TABLE_GLYF, 1, handle_glyf }, { TTF_TABLE_LOCA, 1, handle_loca }, { TTF_TABLE_KERN, 0, handle_kern }, { TTF_TABLE_HMTX, 1, handle_hmtx } }; const unsigned int required_tables = 7; unsigned int handled_tables = 0; size_t dir_end; size_t i, j; if (this_ttf->glyph_array != NULL) free(this_ttf->glyph_array); this_ttf->glyph_array = NULL; this_ttf->glyph_entries = 0; if (this_ttf->glyf != NULL) free(this_ttf->glyf); if (this_ttf->kern != NULL) free(this_ttf->kern); this_ttf->glyf = NULL; this_ttf->kern = NULL; this_ttf->glyf_size = 0; if (size < 12 || p == NULL) return this_ttf->glyph_entries = 0, 1; if (BE32(&p[0]) != 0x00010000) return this_ttf->glyph_entries = 0, 1; dir_end = (size_t)((BE16(&p[4]) * 16) + 12); if (size < dir_end) return this_ttf->glyph_entries = 0, 1; for (i = 0; i < sizeof(tables) / sizeof(tables[0]); i++) { for (j = 12; j < dir_end; j++) { if (BE32(&p[j]) == tables[i].name) { unsigned int off = BE32(&p[j + 8]); unsigned int len = BE32(&p[j + 12]); if (!(off < UINT_MAX - len)) return this_ttf->glyph_entries = 0, 1; if (off + len > size) return this_ttf->glyph_entries = 0, 1; if (tables[i].func(ttf, (size_t)len, p + off)) return this_ttf->glyph_entries = 0, 2; handled_tables += tables[i].required; break; } } } if (handled_tables != required_tables) return this_ttf->glyph_entries = 0, 3; return 0; } int ttf_set_bitmap(void *ttf, size_t size, void *bitmap) { size_t em_scale, em_value, square; for (em_value = 16; em_value <= 256; em_value++) { if (em_value * em_value == size) { this_ttf->bitmap = bitmap; this_ttf->bitmap_size = size; this_ttf->em_value = (unsigned int)em_value; for (em_scale = 2; em_scale <= 32; em_scale += 2) { square = em_value * em_scale; if ((square * square) > 262144) break; this_ttf->square = (unsigned int)square; if (square >= 256) break; } return 0; } } this_ttf->bitmap = NULL; this_ttf->bitmap_size = 0; this_ttf->em_value = 0; this_ttf->square = 0; return 1; } int ttf_set_shades(void *ttf, unsigned int number) { if (number < 2 || number > 256) return 1; this_ttf->shades = number; return 0; } static void bresenham(void *ttf, int x0, int y0, int x1, int y1, int y_dir) { unsigned int square = this_ttf->square; unsigned int color = ((y_dir == 0) ? 4u : ((y_dir < 0) ? 5u : 6u)); int dx, dy; int sx, sy; int t1, t2; if (x0 < x1) dx = (x1 - x0), sx = 1; else dx = (x0 - x1), sx = -1; if (y0 < y1) dy = -(y1 - y0), sy = 1; else dy = -(y0 - y1), sy = -1; t1 = dx + dy; for (;;) { unsigned int x = (unsigned int)x0 / 8u; unsigned int y = (unsigned int)y0 / 8u; unsigned int offset = (x + (y * square)) & 0x3FFFFu; unsigned int c = this_ttf->buffer[offset]; this_ttf->buffer[offset] = (unsigned char)(c | color); t2 = t1 * 2; if (t2 >= dy) { if (x0 == x1) break; x0 += sx; t1 += dy; } if (t2 <= dx) { if (y0 == y1) break; y0 += sy; t1 += dx; } } } static void bezier(void *ttf, int x0, int y0, int x1, int y1, int x2, int y2) { int prev_y = y0 * 1024; int line_x0 = x0, line_y0 = y0; int line_x1, line_y1; int y_dir = 1; int i; if (y0 == y1 && y1 == y2) y_dir = 0; else if (y0 < y1 || (y0 == y1 && y1 < y2)) y_dir = -1; for (i = 1; i < 32; i++) { int t1 = (i * 32) / 32; int t2 = 32 - t1; int t3 = t2 * t2; int t4 = 2 * t2 * t1; int t5 = t1 * t1; int x = t3 * x0 + t4 * x1 + t5 * x2; int y = t3 * y0 + t4 * y1 + t5 * y2; line_x1 = x / 1024; line_y1 = y / 1024; if (y_dir != 0) y_dir = (prev_y < y) ? -1 : 1; bresenham(ttf, line_x0, line_y0, line_x1, line_y1, y_dir); prev_y = y; line_x0 = line_x1; line_y0 = line_y1; } line_x1 = x2; line_y1 = y2; bresenham(ttf, line_x0, line_y0, line_x1, line_y1, y_dir); } static int draw_glyph(void *ttf, int points, const unsigned char *p) { int square = (int)this_ttf->square; const unsigned char *px = p + points; const unsigned char *py = p + (points * 3); int contour_start = 0; int x0, y0, x1, y1, x2, y2; int i, j; memset(this_ttf->buffer, 0, (size_t)(square * square)); for (i = 0; i < points; i++) { unsigned int flag = p[i]; int prev = (i > 0) ? i - 1 : 0; int next = (i + 1) % points; if (contour_start == i) { for (j = i; j < points; j++) { if ((p[prev] & 0x80u) != 0) break; prev = j; } } if ((flag & 0x80u) != 0) { next = contour_start; contour_start = i + 1; } if ((flag & 0x01u) == 0) { x0 = (int)BE16(&px[prev * 2]); y0 = (int)BE16(&py[prev * 2]); x1 = (int)BE16(&px[i * 2]); y1 = (int)BE16(&py[i * 2]); if ((p[prev] & 0x01u) == 0) { x0 = x0 + ((x1 - x0) / 2); y0 = y0 + ((y1 - y0) / 2); } x2 = (int)BE16(&px[next * 2]); y2 = (int)BE16(&py[next * 2]); if ((p[next] & 0x01u) == 0) { x2 = x1 + ((x2 - x1) / 2); y2 = y1 + ((y2 - y1) / 2); } x0 = (square * x0) / 256; y0 = (square * y0) / 256; x1 = (square * x1) / 256; y1 = (square * y1) / 256; x2 = (square * x2) / 256; y2 = (square * y2) / 256; bezier(ttf, x0, y0, x1, y1, x2, y2); } else if ((p[next] & 0x01u) != 0) { int y_dir; x0 = (int)BE16(&px[i * 2]); y0 = (int)BE16(&py[i * 2]); x1 = (int)BE16(&px[next * 2]); y1 = (int)BE16(&py[next * 2]); x0 = (square * x0) / 256; y0 = (square * y0) / 256; x1 = (square * x1) / 256; y1 = (square * y1) / 256; y_dir = (y0 == y1) ? 0 : ((y0 < y1) ? -1 : 1); bresenham(ttf, x0, y0, x1, y1, y_dir); } } return 0; } static void fill_contours(void *ttf) { unsigned int square = this_ttf->square; unsigned int i, j, k; for (i = 0; i < square; i++) { unsigned char *line = this_ttf->buffer + (i * square); for (j = 0; j < square; j++) { if (line[j] != 0) break; } while (j < square) { unsigned int size = 1; if (line[j] == 0) { unsigned int color = 0; int add = 0, state = 0; for (k = j + 1; k < square; k++) { if (line[k] != 0) break; size += 1; } for (k = j + 1; k < square; k++) { if (color != 0 && line[k] == 0) { if (add != 0x7FFF) { if (add < 0) state -= 1; else if (add > 0) state += 1; } add = 0; } if (color != line[k]) { color = (unsigned int)line[k]; if (add != 0x7FFF) { if (color == 5) add -= 1; else if (color == 6) add += 1; else if (color == 7) add = 0x7FFF; } } } if (state != 0) memset(&line[j], 0x08, (size_t)size); } j += size; } } } int ttf_render(void *ttf, unsigned int code_point, unsigned int *width) { unsigned int em_value = this_ttf->em_value; unsigned int glyph_entries = this_ttf->glyph_entries; unsigned int is_processed = 0; unsigned int offset = 0, last_point = 0; unsigned int adv_width; unsigned int contours; unsigned int i; unsigned char *glyph; size_t size; if (width != NULL) *width = 0; if (this_ttf->bitmap_size != 0) memset(this_ttf->bitmap, 0, this_ttf->bitmap_size); if (this_ttf->glyph_entries == 0) return 1; glyph = this_ttf->glyph_array[0].data; size = this_ttf->glyph_array[0].size; adv_width = this_ttf->glyph_array[0].adv_width; for (i = 1; i < glyph_entries; i++) { if (this_ttf->glyph_array[i].code_pnt == code_point) { glyph = this_ttf->glyph_array[i].data; size = this_ttf->glyph_array[i].size; adv_width = this_ttf->glyph_array[i].adv_width; break; } } if (adv_width > 2048 || em_value == 0 || em_value > 256) return 1; if (width != NULL) *width = (adv_width * em_value) / 2048; if (size < 2 || this_ttf->bitmap_size == 0 || this_ttf->square < 256) return 0; if ((contours = BE16(&glyph[0])) >= 0x8000ul) return 1; if (size < (12 + contours * 2)) return 1; if (contours == 0) return 0; offset += 10; /* * Find the last point index. */ for (i = 0; i < contours; i++) { unsigned char *p = &glyph[offset]; if (last_point < BE16(&p[0])) last_point = BE16(&p[0]); offset += 2; } if (last_point == 0) return 0; /* * Check instructions. */ if (BE16(&glyph[offset]) != 0) return 1; offset += 2; if (size != offset + (last_point + 1) * 5) return 1; /* * Check flags. Bit 7 is used internally. */ for (i = 0; i <= last_point; i++) { unsigned int flg = glyph[offset + i]; if ((flg & 0x80u) != 0) { is_processed = 1; flg &= 0x7Fu; } if (flg > 1) return 1; } /* * Use bit 7 for "last points of each contour" and translate all * point coordinates. If X or Y is exactly 2048, it is changed to * 2040 so that the range is from 0 to 2040 and when divided by 8, * the ranges are from 0 to 255. */ if (is_processed == 0) { unsigned int points = last_point + 1; unsigned int x = 0, y = 512; for (i = 0; i < contours; i++) { unsigned char *p = glyph + (10 + (i * 2)); unsigned int pnt = BE16(&p[0]); unsigned int flg = glyph[offset + pnt]; glyph[offset + pnt] = (unsigned char)(flg | 0x80u); } for (i = 0; i < points; i++) { unsigned char *px, *py; unsigned int wx, wy; px = glyph + (offset + (points * 1) + (i * 2)); wx = x = (x + BE16(&px[0])) & 0xFFFFu; py = glyph + (offset + (points * 3) + (i * 2)); wy = y = (y + BE16(&py[0])) & 0xFFFFu; if ((x & 0xF807u) != 0) { if (x != 2048) return glyph[offset] = 0x7F, 1; wx = 2040; } if ((y & 0xF807u) != 0) { if (y != 2048) return glyph[offset] = 0x7F, 1; wy = 2040; } W_BE16(px, wx); W_BE16(py, wy); } } if (draw_glyph(ttf, (int)(last_point + 1), &glyph[offset])) return 1; fill_contours(ttf); if (this_ttf->shades < 2 || this_ttf->shades > 256) this_ttf->shades = 256; /* * Copy the glyph image (monochrome). */ if (this_ttf->shades == 2) { const unsigned char *src = this_ttf->buffer; unsigned char *dst = this_ttf->bitmap; int square = (int)this_ttf->square; int x_em = (int)(adv_width * em_value) / 2048; int y_em = (int)em_value; int s0 = (square / y_em); int s1 = ((s0 % 2) == 1) ? (s0 / 2) : ((s0 / 2) - 1); int s2 = ((s0 % 2) == 0) ? (s0 / 2) : s1; int x0, x1, x2; int y0, y1, y2; int x, y; if (s0 < 2) return 1; for (y = y_em - 1; y >= 0; y--) { y0 = (y * square) / y_em; y1 = (y0 + s1) * square; y2 = (y0 + s2) * square; for (x = 0; x < x_em; x++) { x0 = (x * square) / y_em; x1 = x0 + s1; x2 = x0 + s2; if (src[x1 + y1] != 0) dst[x] = 1; if (src[x2 + y1] != 0) dst[x] = 1; if (src[x1 + y2] != 0) dst[x] = 1; if (src[x2 + y2] != 0) dst[x] = 1; } dst += em_value; } } /* * Copy the glyph image ("anti-aliasing"). */ if (this_ttf->shades > 2) { const unsigned char *src = this_ttf->buffer; unsigned char *dst = this_ttf->bitmap; int square = (int)this_ttf->square; int x_em = (int)(adv_width * em_value) / 2048; int y_em = (int)em_value; int s0 = (int)this_ttf->shades - 1; int s1 = (square / y_em); int s2 = (s1 * s1); int x0, x1; int y0, y1; int c, x, y; for (y = y_em - 1; y >= 0; y--) { y0 = ((y * square) / y_em) * square; for (x = 0; x < x_em; x++) { x0 = (x * square) / y_em; src = &src[x0 + y0]; for (c = 0, y1 = 0; y1 < s1; y1++) { for (x1 = 0; x1 < s1; x1++) { if (src[x1] != 0) c += 1; } src += square; } src = this_ttf->buffer; dst[x] = (unsigned char)((c * s0) / s2); } dst += em_value; } } return 0; }
the_stack_data/1206588.c
/* ヘッダファイルのインクルード */ #include <stdio.h> /* 標準入出力 */ #include <unistd.h> /* UNIX標準 */ /* main関数の定義 */ int main(void){ /* 変数の宣言 */ int result; /* symlinkの戻り値result. */ /* シンボリックリンクを作成する. */ result = symlink("test1/test1.txt", "test1_symlink"); /* symlinkで"test1/test1.txt"のシンボリックリンクを"test1_symlink"に作成. */ if (result == 0){ /* 成功 */ printf("create test1_symlink success!\n"); /* "create test1_symlink success!"と出力. */ return 0; /* 0を返して正常終了. */ } else{ /* 失敗 */ printf("create test1_symlink failed!\n"); /* "create test1_symlink failed!"と出力. */ perror("symlink"); /* perrorで"link"のエラー出力. */ return -1; /* -1を返して異常終了. */ } }
the_stack_data/116338.c
#include<stdio.h> #include<stdlib.h> typedef struct node{ //define the details of the structure int data; struct node *next; }NODE; void printList(NODE *);//function to print the solution NODE* input();//Function to take input NODE* solve(NODE*,int);//function to solve the problem //define any function prototype you want to use int main(){ NODE* head; head=input(); int k; scanf("%d", &k); printList(solve(head,k)); return 0; } /*Do not modify the main function *Define the structure NODE properly *Write the body of the above mentioned function*/ //Write the body for all function definitions below NODE *input() { NODE *head = (NODE *)malloc(sizeof(NODE)); NODE *ptr = (NODE *)malloc(sizeof(NODE)); head = NULL; ptr = NULL; int val; scanf("%d",&val); while(val!=-1) { NODE *new = (NODE *)malloc(sizeof(NODE)); new->data = val; new->next = NULL; if(head==NULL) { head = new; ptr = new; } else { ptr->next = new; ptr = new; } scanf("%d",&val); } return head; } void printList(NODE *head) { NODE *ptr = (NODE *)malloc(sizeof(NODE)); ptr = head; while(ptr!=NULL) { printf("%d ",ptr->data); ptr = ptr->next; } } NODE *solve(NODE *head, int n) { NODE *ptr = (NODE *)malloc(sizeof(NODE)); ptr = head; int count = 0; while(ptr!=NULL) { count++; ptr = ptr->next; } if(n==0) return head; n = n%count; ptr = head; while(count-n>=2) { count--; // printf("%d %d\n",count+1-n,head->data); head = head->next; } // printf("%d\n",head->data); NODE *ptr2 = (NODE *)malloc(sizeof(NODE)); ptr2 = head; head = head->next; // printf("%d\n",head->data); ptr2->next = NULL; // printf("%d\n",ptr2->data); ptr2 = head; while(ptr2->next!=NULL) { ptr2 = ptr2->next; } // printf("%d\n",ptr2->data); // printf("%d\n",ptr->data); ptr2->next = ptr; return head; }
the_stack_data/8902.c
#include<stdio.h> int main(void){ int n, maior, menor, flag=0; printf("Informe um numero:\n"); scanf("%d",&n); maior = n; menor = n; do { printf("Informe um numero:\n"); scanf("%d",&n); if (flag==0){ maior = 0; menor = 0; flag = 1; } if (n>-2){ if (n>maior){ maior = n; }else if(n<menor && n!=-1){ menor = n; } }else{ printf("\nNumero invalido!\n"); } }while(n!=-1); printf("Maior: %d\n",maior); printf("Menor: %d\n",menor); }
the_stack_data/50805.c
#include <stdio.h> #include <stdlib.h> #include <string.h> int a = 0; // 全局初始化区 char *p1; // 全局未初始化区 int main() { int b; // 栈区 char s[] = "abc";// 栈区 char * p2;// 栈区 char * p3 = "12345xyz";//"12345xyz"// 在文字常量区, p3 在栈区 static int c = 0; // 全局(静态)初始化区 p1 = (char *)malloc(10); p2 = (char *)malloc(20);// 堆区 strcpy(p1, p3); return 0; }
the_stack_data/550614.c
#include <stdlib.h> #include <stdio.h> #include <string.h> int main(void) { int q, r, i; int c; printf("string (\n"); printf("[-]>[-]\n"); while ((c = getchar()) != EOF) { if (c == 0) continue; //notation if (c == 32) printf(" SPC "); else if (c == 10) printf(" LF "); else if (c >= 127 || c < 32) printf(" %4d ", c); else printf("%c %4d ", c, c); //end of notation if (c < 0x10) { for (i = 0; i < c; i++) putchar('+'); printf(">[-]"); } else if (c < 0x20) { q = c / 4; r = c % 4; for (i = 0; i < r; i++) putchar('+'); printf(">[-]"); for (i = 0; i < q; i++) putchar('+'); printf("[<++++>-]"); } else if (c < 0x40) { q = c / 8; r = c % 8; char x = '+'; if (r > 4) { r = 8 - r; q++; x = '-'; } for (i = 0; i < r; i++) putchar(x); printf(">[-]"); for (i = 0; i < q; i++) putchar('+'); printf("[<++++++++>-]"); } else { q = c / 16; r = c % 16; char x = '+'; if (r > 8) { r = 16 - r; q++; x = '-'; } for (i = 0; i < r; i++) putchar(x); printf(">[-]"); for (i = 0; i < q; i++) putchar('+'); printf("[<++++++++++++++++>-]"); } putchar(10); //newline } printf("<[<]\n"); printf(")\n"); return 0; }
the_stack_data/40763107.c
/* Servos library */
the_stack_data/173577550.c
/* dlarrv.f -- translated by f2c (version 20061008) */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <math.h> #include <float.h> #include <assert.h> #define imax(a,b) ( (a) > (b) ? (a) : (b) ) #define imin(a,b) ( (a) < (b) ? (a) : (b) ) #define TRUE_ (1) #define FALSE_ (0) /* Table of constant values */ static double c_b5 = 0.; static int c__1 = 1; static int c__2 = 2; /* Subroutine */ int odrrv_(int *n, double *vl, double *vu, double *d__, double *l, double *pivmin, int *isplit, int *m, int *dol, int *dou, double *minrgp, double *rtol1, double *rtol2, double *w, double *werr, double *wgap, int *iblock, int *indexw, double *gers, double *z__, int *ldz, int *isuppz, double *work, int *iwork, int *info) { /* System generated locals */ int z_dim1, z_offset, i__1, i__2, i__3, i__4, i__5; double d__1, d__2; int L__1; /* Builtin functions */ // double log(double); /* Local variables */ int minwsize, i__, j, k, p, q, miniwsize, ii; double gl; int im, in; double gu, gap, eps, tau, tol, tmp; int zto; double ztz; int iend, jblk; double lgap; int done; double rgap, left; int wend, iter; double bstw; int itmp1; extern /* Subroutine */ int odscl_(int *, double *, double *, int *); int indld; double fudge; int idone; double sigma; int iinfo, iindr; double resid; int eskip; double right; extern /* Subroutine */ int odcpy_(int *, double *, int *, double *, int *); int nclus, zfrom; double rqtol; int iindc1, iindc2; extern /* Subroutine */ int odr1v_(int *, int *, int *, double *, double *, double *, double *, double *, double *, double *, double *, int *, int *, double *, double *, int *, int *, double *, double *, double *, double *); int stp2ii; double lambda; // extern double odmch_(char *); int ibegin, indeig; int needbs; int indlld; double sgndef, mingma; extern /* Subroutine */ int odrrb_(int *, double *, double *, int *, int *, double *, double *, int *, double *, double *, double *, double *, int *, double *, double *, int *, int *); int oldien, oldncl, wbegin; double spdiam; int negcnt; extern /* Subroutine */ int odrrf_(int *, double *, double *, double *, int *, int *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, double *, int *); int oldcls; double savgap; int ndepth; double ssigma; extern /* Subroutine */ int odset_(char *, int *, int *, double *, double *, double *, int *); int usedbs; int iindwk, offset; double gaptol; int newcls, oldfst, indwrk, windex, oldlst; int usedrq; int newfst, newftt, parity, windmn, windpl, isupmn, newlst, zusedl; double bstres; int newsiz, zusedu, zusedw; double nrminv, rqcorr; int tryrqc; int isupmx; /* -- LAPACK auxiliary routine (version 3.2) -- */ /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ /* November 2006 */ /* .. Scalar Arguments .. */ /* .. */ /* .. Array Arguments .. */ /* .. */ /* Purpose */ /* ======= */ /* ODRRV computes the eigenvectors of the tridiagonal matrix */ /* T = L D L^T given L, D and APPROXIMATIONS to the eigenvalues of L D L^T. */ /* The input eigenvalues should have been computed by DLARRE. */ /* Arguments */ /* ========= */ /* N (input) INT */ /* The order of the matrix. N >= 0. */ /* VL (input) DOUBLE PRECISION */ /* VU (input) DOUBLE PRECISION */ /* Lower and upper bounds of the interval that contains the desired */ /* eigenvalues. VL < VU. Needed to compute gaps on the left or right */ /* end of the extremal eigenvalues in the desired RANGE. */ /* D (input/output) DOUBLE PRECISION array, dimension (N) */ /* On entry, the N diagonal elements of the diagonal matrix D. */ /* On exit, D may be overwritten. */ /* L (input/output) DOUBLE PRECISION array, dimension (N) */ /* On entry, the (N-1) subdiagonal elements of the unit */ /* bidiagonal matrix L are in elements 1 to N-1 of L */ /* (if the matrix is not splitted.) At the end of each block */ /* is stored the corresponding shift as given by DLARRE. */ /* On exit, L is overwritten. */ /* PIVMIN (in) DOUBLE PRECISION */ /* The minimum pivot allowed in the Sturm sequence. */ /* ISPLIT (input) INT array, dimension (N) */ /* The splitting points, at which T breaks up into blocks. */ /* The first block consists of rows/columns 1 to */ /* ISPLIT( 1 ), the second of rows/columns ISPLIT( 1 )+1 */ /* through ISPLIT( 2 ), etc. */ /* M (input) INT */ /* The total number of input eigenvalues. 0 <= M <= N. */ /* DOL (input) INT */ /* DOU (input) INT */ /* If the user wants to compute only selected eigenvectors from all */ /* the eigenvalues supplied, he can specify an index range DOL:DOU. */ /* Or else the setting DOL=1, DOU=M should be applied. */ /* Note that DOL and DOU refer to the order in which the eigenvalues */ /* are stored in W. */ /* If the user wants to compute only selected eigenpairs, then */ /* the columns DOL-1 to DOU+1 of the eigenvector space Z contain the */ /* computed eigenvectors. All other columns of Z are set to zero. */ /* MINRGP (input) DOUBLE PRECISION */ /* RTOL1 (input) DOUBLE PRECISION */ /* RTOL2 (input) DOUBLE PRECISION */ /* Parameters for bisection. */ /* An interval [LEFT,RIGHT] has converged if */ /* RIGHT-LEFT.LT.MAX( RTOL1*GAP, RTOL2*MAX(|LEFT|,|RIGHT|) ) */ /* W (input/output) DOUBLE PRECISION array, dimension (N) */ /* The first M elements of W contain the APPROXIMATE eigenvalues for */ /* which eigenvectors are to be computed. The eigenvalues */ /* should be grouped by split-off block and ordered from */ /* smallest to largest within the block ( The output array */ /* W from DLARRE is expected here ). Furthermore, they are with */ /* respect to the shift of the corresponding root representation */ /* for their block. On exit, W holds the eigenvalues of the */ /* UNshifted matrix. */ /* WERR (input/output) DOUBLE PRECISION array, dimension (N) */ /* The first M elements contain the semiwidth of the uncertainty */ /* interval of the corresponding eigenvalue in W */ /* WGAP (input/output) DOUBLE PRECISION array, dimension (N) */ /* The separation from the right neighbor eigenvalue in W. */ /* IBLOCK (input) INT array, dimension (N) */ /* The indices of the blocks (submatrices) associated with the */ /* corresponding eigenvalues in W; IBLOCK(i)=1 if eigenvalue */ /* W(i) belongs to the first block from the top, =2 if W(i) */ /* belongs to the second block, etc. */ /* INDEXW (input) INT array, dimension (N) */ /* The indices of the eigenvalues within each block (submatrix); */ /* for example, INDEXW(i)= 10 and IBLOCK(i)=2 imply that the */ /* i-th eigenvalue W(i) is the 10-th eigenvalue in the second block. */ /* GERS (input) DOUBLE PRECISION array, dimension (2*N) */ /* The N Gerschgorin intervals (the i-th Gerschgorin interval */ /* is (GERS(2*i-1), GERS(2*i)). The Gerschgorin intervals should */ /* be computed from the original UNshifted matrix. */ /* Z (output) DOUBLE PRECISION array, dimension (LDZ, max(1,M) ) */ /* If INFO = 0, the first M columns of Z contain the */ /* orthonormal eigenvectors of the matrix T */ /* corresponding to the input eigenvalues, with the i-th */ /* column of Z holding the eigenvector associated with W(i). */ /* Note: the user must ensure that at least max(1,M) columns are */ /* supplied in the array Z. */ /* LDZ (input) INT */ /* The leading dimension of the array Z. LDZ >= 1, and if */ /* JOBZ = 'V', LDZ >= max(1,N). */ /* ISUPPZ (output) INT array, dimension ( 2*max(1,M) ) */ /* The support of the eigenvectors in Z, i.e., the indices */ /* indicating the nonzero elements in Z. The I-th eigenvector */ /* is nonzero only in elements ISUPPZ( 2*I-1 ) through */ /* ISUPPZ( 2*I ). */ /* WORK (workspace) DOUBLE PRECISION array, dimension (12*N) */ /* IWORK (workspace) INT array, dimension (7*N) */ /* INFO (output) INT */ /* = 0: successful exit */ /* > 0: A problem occured in ODRRV. */ /* < 0: One of the called subroutines signaled an internal problem. */ /* Needs inspection of the corresponding parameter IINFO */ /* for further information. */ /* =-1: Problem in ODRRB when refining a child's eigenvalues. */ /* =-2: Problem in ODRRF when computing the RRR of a child. */ /* When a child is inside a tight cluster, it can be difficult */ /* to find an RRR. A partial remedy from the user's point of */ /* view is to make the parameter MINRGP smaller and recompile. */ /* However, as the orthogonality of the computed vectors is */ /* proportional to 1/MINRGP, the user should be aware that */ /* he might be trading in precision when he decreases MINRGP. */ /* =-3: Problem in ODRRB when refining a single eigenvalue */ /* after the Rayleigh correction was rejected. */ /* = 5: The Rayleigh Quotient Iteration failed to converge to */ /* full accuracy in MAXITR steps. */ /* Further Details */ /* =============== */ /* Based on contributions by */ /* Beresford Parlett, University of California, Berkeley, USA */ /* Jim Demmel, University of California, Berkeley, USA */ /* Inderjit Dhillon, University of Texas, Austin, USA */ /* Osni Marques, LBNL/NERSC, USA */ /* Christof Voemel, University of California, Berkeley, USA */ /* ===================================================================== */ /* .. Parameters .. */ /* .. */ /* .. Local Scalars .. */ /* .. */ /* .. External Functions .. */ /* .. */ /* .. External Subroutines .. */ /* .. */ /* .. Intrinsic Functions .. */ /* .. */ /* .. Executable Statements .. */ /* .. */ /* The first N entries of WORK are reserved for the eigenvalues */ /* Parameter adjustments */ --d__; --l; --isplit; --w; --werr; --wgap; --iblock; --indexw; --gers; z_dim1 = *ldz; z_offset = 1 + z_dim1; z__ -= z_offset; --isuppz; --work; --iwork; /* Function Body */ indld = *n + 1; indlld = (*n << 1) + 1; indwrk = *n * 3 + 1; minwsize = *n * 12; i__1 = minwsize; for (i__ = 1; i__ <= i__1; ++i__) { work[i__] = 0.; /* L5: */ } /* IWORK(IINDR+1:IINDR+N) hold the twist indices R for the */ /* factorization used to compute the FP vector */ iindr = 0; /* IWORK(IINDC1+1:IINC2+N) are used to store the clusters of the current */ /* layer and the one above. */ iindc1 = *n; iindc2 = *n << 1; iindwk = *n * 3 + 1; miniwsize = *n * 7; i__1 = miniwsize; for (i__ = 1; i__ <= i__1; ++i__) { iwork[i__] = 0; /* L10: */ } zusedl = 1; if (*dol > 1) { /* Set lower bound for use of Z */ zusedl = *dol - 1; } zusedu = *m; if (*dou < *m) { /* Set lower bound for use of Z */ zusedu = *dou + 1; } /* The width of the part of Z that is used */ zusedw = zusedu - zusedl + 1; odset_("Full", n, &zusedw, &c_b5, &c_b5, &z__[zusedl * z_dim1 + 1], ldz); eps = DBL_EPSILON; // eps = odmch_("Precision"); rqtol = eps * 2.; /* Set expert flags for standard code. */ tryrqc = TRUE_; if (*dol == 1 && *dou == *m) { } else { /* Only selected eigenpairs are computed. Since the other evalues */ /* are not refined by RQ iteration, bisection has to compute to full */ /* accuracy. */ *rtol1 = eps * 4.; *rtol2 = eps * 4.; } /* The entries WBEGIN:WEND in W, WERR, WGAP correspond to the */ /* desired eigenvalues. The support of the nonzero eigenvector */ /* entries is contained in the interval IBEGIN:IEND. */ /* Remark that if k eigenpairs are desired, then the eigenvectors */ /* are stored in k contiguous columns of Z. */ /* DONE is the number of eigenvectors already computed */ done = 0; ibegin = 1; wbegin = 1; i__1 = iblock[*m]; for (jblk = 1; jblk <= i__1; ++jblk) { iend = isplit[jblk]; sigma = l[iend]; /* Find the eigenvectors of the submatrix indexed IBEGIN */ /* through IEND. */ wend = wbegin - 1; L15: if (wend < *m) { if (iblock[wend + 1] == jblk) { ++wend; goto L15; } } if (wend < wbegin) { ibegin = iend + 1; goto L170; } else if (wend < *dol || wbegin > *dou) { ibegin = iend + 1; wbegin = wend + 1; goto L170; } /* Find local spectral diameter of the block */ gl = gers[(ibegin << 1) - 1]; gu = gers[ibegin * 2]; i__2 = iend; for (i__ = ibegin + 1; i__ <= i__2; ++i__) { /* Computing MIN */ d__1 = gers[(i__ << 1) - 1]; gl = fmin(d__1,gl); /* Computing MAX */ d__1 = gers[i__ * 2]; gu = fmax(d__1,gu); /* L20: */ } spdiam = gu - gl; /* OLDIEN is the last index of the previous block */ oldien = ibegin - 1; /* Calculate the size of the current block */ in = iend - ibegin + 1; /* The number of eigenvalues in the current block */ im = wend - wbegin + 1; /* This is for a 1x1 block */ if (ibegin == iend) { ++done; z__[ibegin + wbegin * z_dim1] = 1.; isuppz[(wbegin << 1) - 1] = ibegin; isuppz[wbegin * 2] = ibegin; w[wbegin] += sigma; work[wbegin] = w[wbegin]; ibegin = iend + 1; ++wbegin; goto L170; } /* The desired (shifted) eigenvalues are stored in W(WBEGIN:WEND) */ /* Note that these can be approximations, in this case, the corresp. */ /* entries of WERR give the size of the uncertainty interval. */ /* The eigenvalue approximations will be refined when necessary as */ /* high relative accuracy is required for the computation of the */ /* corresponding eigenvectors. */ odcpy_(&im, &w[wbegin], &c__1, &work[wbegin], &c__1); /* We store in W the eigenvalue approximations w.r.t. the original */ /* matrix T. */ i__2 = im; for (i__ = 1; i__ <= i__2; ++i__) { w[wbegin + i__ - 1] += sigma; /* L30: */ } /* NDEPTH is the current depth of the representation tree */ ndepth = 0; /* PARITY is either 1 or 0 */ parity = 1; /* NCLUS is the number of clusters for the next level of the */ /* representation tree, we start with NCLUS = 1 for the root */ nclus = 1; iwork[iindc1 + 1] = 1; iwork[iindc1 + 2] = im; /* IDONE is the number of eigenvectors already computed in the current */ /* block */ idone = 0; /* loop while( IDONE.LT.IM ) */ /* generate the representation tree for the current block and */ /* compute the eigenvectors */ L40: if (idone < im) { /* This is a crude protection against infinitely deep trees */ if (ndepth > *m) { *info = -2; return 0; } /* breadth first processing of the current level of the representation */ /* tree: OLDNCL = number of clusters on current level */ oldncl = nclus; /* reset NCLUS to count the number of child clusters */ nclus = 0; parity = 1 - parity; if (parity == 0) { oldcls = iindc1; newcls = iindc2; } else { oldcls = iindc2; newcls = iindc1; } /* Process the clusters on the current level */ i__2 = oldncl; for (i__ = 1; i__ <= i__2; ++i__) { j = oldcls + (i__ << 1); /* OLDFST, OLDLST = first, last index of current cluster. */ /* cluster indices start with 1 and are relative */ /* to WBEGIN when accessing W, WGAP, WERR, Z */ oldfst = iwork[j - 1]; oldlst = iwork[j]; if (ndepth > 0) { /* Retrieve relatively robust representation (RRR) of cluster */ /* that has been computed at the previous level */ /* The RRR is stored in Z and overwritten once the eigenvectors */ /* have been computed or when the cluster is refined */ if (*dol == 1 && *dou == *m) { /* Get representation from location of the leftmost evalue */ /* of the cluster */ j = wbegin + oldfst - 1; } else { if (wbegin + oldfst - 1 < *dol) { /* Get representation from the left end of Z array */ j = *dol - 1; } else if (wbegin + oldfst - 1 > *dou) { /* Get representation from the right end of Z array */ j = *dou; } else { j = wbegin + oldfst - 1; } } odcpy_(&in, &z__[ibegin + j * z_dim1], &c__1, &d__[ibegin] , &c__1); i__3 = in - 1; odcpy_(&i__3, &z__[ibegin + (j + 1) * z_dim1], &c__1, &l[ ibegin], &c__1); sigma = z__[iend + (j + 1) * z_dim1]; /* Set the corresponding entries in Z to zero */ odset_("Full", &in, &c__2, &c_b5, &c_b5, &z__[ibegin + j * z_dim1], ldz); } /* Compute DL and DLL of current RRR */ i__3 = iend - 1; for (j = ibegin; j <= i__3; ++j) { tmp = d__[j] * l[j]; work[indld - 1 + j] = tmp; work[indlld - 1 + j] = tmp * l[j]; /* L50: */ } if (ndepth > 0) { /* P and Q are index of the first and last eigenvalue to compute */ /* within the current block */ p = indexw[wbegin - 1 + oldfst]; q = indexw[wbegin - 1 + oldlst]; /* Offset for the arrays WORK, WGAP and WERR, i.e., th P-OFFSET */ /* thru' Q-OFFSET elements of these arrays are to be used. */ /* OFFSET = P-OLDFST */ offset = indexw[wbegin] - 1; /* perform limited bisection (if necessary) to get approximate */ /* eigenvalues to the precision needed. */ odrrb_(&in, &d__[ibegin], &work[indlld + ibegin - 1], &p, &q, rtol1, rtol2, &offset, &work[wbegin], &wgap[ wbegin], &werr[wbegin], &work[indwrk], &iwork[ iindwk], pivmin, &spdiam, &in, &iinfo); if (iinfo != 0) { *info = -1; return 0; } /* We also recompute the extremal gaps. W holds all eigenvalues */ /* of the unshifted matrix and must be used for computation */ /* of WGAP, the entries of WORK might stem from RRRs with */ /* different shifts. The gaps from WBEGIN-1+OLDFST to */ /* WBEGIN-1+OLDLST are correctly computed in ODRRB. */ /* However, we only allow the gaps to become greater since */ /* this is what should happen when we decrease WERR */ if (oldfst > 1) { /* Computing MAX */ d__1 = wgap[wbegin + oldfst - 2], d__2 = w[wbegin + oldfst - 1] - werr[wbegin + oldfst - 1] - w[ wbegin + oldfst - 2] - werr[wbegin + oldfst - 2]; wgap[wbegin + oldfst - 2] = fmax(d__1,d__2); } if (wbegin + oldlst - 1 < wend) { /* Computing MAX */ d__1 = wgap[wbegin + oldlst - 1], d__2 = w[wbegin + oldlst] - werr[wbegin + oldlst] - w[wbegin + oldlst - 1] - werr[wbegin + oldlst - 1]; wgap[wbegin + oldlst - 1] = fmax(d__1,d__2); } /* Each time the eigenvalues in WORK get refined, we store */ /* the newly found approximation with all shifts applied in W */ i__3 = oldlst; for (j = oldfst; j <= i__3; ++j) { w[wbegin + j - 1] = work[wbegin + j - 1] + sigma; /* L53: */ } } /* Process the current node. */ newfst = oldfst; i__3 = oldlst; for (j = oldfst; j <= i__3; ++j) { if (j == oldlst) { /* we are at the right end of the cluster, this is also the */ /* boundary of the child cluster */ newlst = j; } else if (wgap[wbegin + j - 1] >= *minrgp * (d__1 = work[ wbegin + j - 1], fabs(d__1))) { /* the right relative gap is big enough, the child cluster */ /* (NEWFST,..,NEWLST) is well separated from the following */ newlst = j; } else { /* inside a child cluster, the relative gap is not */ /* big enough. */ goto L140; } /* Compute size of child cluster found */ newsiz = newlst - newfst + 1; /* NEWFTT is the place in Z where the new RRR or the computed */ /* eigenvector is to be stored */ if (*dol == 1 && *dou == *m) { /* Store representation at location of the leftmost evalue */ /* of the cluster */ newftt = wbegin + newfst - 1; } else { if (wbegin + newfst - 1 < *dol) { /* Store representation at the left end of Z array */ newftt = *dol - 1; } else if (wbegin + newfst - 1 > *dou) { /* Store representation at the right end of Z array */ newftt = *dou; } else { newftt = wbegin + newfst - 1; } } if (newsiz > 1) { /* Current child is not a singleton but a cluster. */ /* Compute and store new representation of child. */ /* Compute left and right cluster gap. */ /* LGAP and RGAP are not computed from WORK because */ /* the eigenvalue approximations may stem from RRRs */ /* different shifts. However, W hold all eigenvalues */ /* of the unshifted matrix. Still, the entries in WGAP */ /* have to be computed from WORK since the entries */ /* in W might be of the same order so that gaps are not */ /* exhibited correctly for very close eigenvalues. */ if (newfst == 1) { /* Computing MAX */ d__1 = 0., d__2 = w[wbegin] - werr[wbegin] - *vl; lgap = fmax(d__1,d__2); } else { lgap = wgap[wbegin + newfst - 2]; } rgap = wgap[wbegin + newlst - 1]; /* Compute left- and rightmost eigenvalue of child */ /* to high precision in order to shift as close */ /* as possible and obtain as large relative gaps */ /* as possible */ for (k = 1; k <= 2; ++k) { if (k == 1) { p = indexw[wbegin - 1 + newfst]; } else { p = indexw[wbegin - 1 + newlst]; } offset = indexw[wbegin] - 1; odrrb_(&in, &d__[ibegin], &work[indlld + ibegin - 1], &p, &p, &rqtol, &rqtol, &offset, & work[wbegin], &wgap[wbegin], &werr[wbegin] , &work[indwrk], &iwork[iindwk], pivmin, & spdiam, &in, &iinfo); /* L55: */ } if (wbegin + newlst - 1 < *dol || wbegin + newfst - 1 > *dou) { /* if the cluster contains no desired eigenvalues */ /* skip the computation of that branch of the rep. tree */ /* We could skip before the refinement of the extremal */ /* eigenvalues of the child, but then the representation */ /* tree could be different from the one when nothing is */ /* skipped. For this reason we skip at this place. */ idone = idone + newlst - newfst + 1; goto L139; } /* Compute RRR of child cluster. */ /* Note that the new RRR is stored in Z */ /* ODRRF needs LWORK = 2*N */ odrrf_(&in, &d__[ibegin], &l[ibegin], &work[indld + ibegin - 1], &newfst, &newlst, &work[wbegin], &wgap[wbegin], &werr[wbegin], &spdiam, &lgap, &rgap, pivmin, &tau, &z__[ibegin + newftt * z_dim1], &z__[ibegin + (newftt + 1) * z_dim1], &work[indwrk], &iinfo); if (iinfo == 0) { /* a new RRR for the cluster was found by ODRRF */ /* update shift and store it */ ssigma = sigma + tau; z__[iend + (newftt + 1) * z_dim1] = ssigma; /* WORK() are the midpoints and WERR() the semi-width */ /* Note that the entries in W are unchanged. */ i__4 = newlst; for (k = newfst; k <= i__4; ++k) { fudge = eps * 3. * (d__1 = work[wbegin + k - 1], fabs(d__1)); work[wbegin + k - 1] -= tau; fudge += eps * 4. * (d__1 = work[wbegin + k - 1], fabs(d__1)); /* Fudge errors */ werr[wbegin + k - 1] += fudge; /* Gaps are not fudged. Provided that WERR is small */ /* when eigenvalues are close, a zero gap indicates */ /* that a new representation is needed for resolving */ /* the cluster. A fudge could lead to a wrong decision */ /* of judging eigenvalues 'separated' which in */ /* reality are not. This could have a negative impact */ /* on the orthogonality of the computed eigenvectors. */ /* L116: */ } ++nclus; k = newcls + (nclus << 1); iwork[k - 1] = newfst; iwork[k] = newlst; } else { *info = -2; return 0; } } else { /* Compute eigenvector of singleton */ iter = 0; tol = log((double) in) * 4. * eps; k = newfst; windex = wbegin + k - 1; /* Computing MAX */ i__4 = windex - 1; windmn = imax(i__4,1); /* Computing MIN */ i__4 = windex + 1; windpl = imin(i__4,*m); lambda = work[windex]; ++done; /* Check if eigenvector computation is to be skipped */ if (windex < *dol || windex > *dou) { eskip = TRUE_; goto L125; } else { eskip = FALSE_; } left = work[windex] - werr[windex]; right = work[windex] + werr[windex]; indeig = indexw[windex]; /* Note that since we compute the eigenpairs for a child, */ /* all eigenvalue approximations are w.r.t the same shift. */ /* In this case, the entries in WORK should be used for */ /* computing the gaps since they exhibit even very small */ /* differences in the eigenvalues, as opposed to the */ /* entries in W which might "look" the same. */ if (k == 1) { /* In the case RANGE='I' and with not much initial */ /* accuracy in LAMBDA and VL, the formula */ /* LGAP = MAX( ZERO, (SIGMA - VL) + LAMBDA ) */ /* can lead to an overestimation of the left gap and */ /* thus to inadequately early RQI 'convergence'. */ /* Prevent this by forcing a small left gap. */ /* Computing MAX */ d__1 = fabs(left), d__2 = fabs(right); lgap = eps * fmax(d__1,d__2); } else { lgap = wgap[windmn]; } if (k == im) { /* In the case RANGE='I' and with not much initial */ /* accuracy in LAMBDA and VU, the formula */ /* can lead to an overestimation of the right gap and */ /* thus to inadequately early RQI 'convergence'. */ /* Prevent this by forcing a small right gap. */ /* Computing MAX */ d__1 = fabs(left), d__2 = fabs(right); rgap = eps * fmax(d__1,d__2); } else { rgap = wgap[windex]; } gap = fmin(lgap,rgap); if (k == 1 || k == im) { /* The eigenvector support can become wrong */ /* because significant entries could be cut off due to a */ /* large GAPTOL parameter in LAR1V. Prevent this. */ gaptol = 0.; } else { gaptol = gap * eps; } isupmn = in; isupmx = 1; /* Update WGAP so that it holds the minimum gap */ /* to the left or the right. This is crucial in the */ /* case where bisection is used to ensure that the */ /* eigenvalue is refined up to the required precision. */ /* The correct value is restored afterwards. */ savgap = wgap[windex]; wgap[windex] = gap; /* We want to use the Rayleigh Quotient Correction */ /* as often as possible since it converges quadratically */ /* when we are close enough to the desired eigenvalue. */ /* However, the Rayleigh Quotient can have the wrong sign */ /* and lead us away from the desired eigenvalue. In this */ /* case, the best we can do is to use bisection. */ usedbs = FALSE_; usedrq = FALSE_; /* Bisection is initially turned off unless it is forced */ needbs = ! tryrqc; L120: /* Check if bisection should be used to refine eigenvalue */ if (needbs) { /* Take the bisection as new iterate */ usedbs = TRUE_; itmp1 = iwork[iindr + windex]; offset = indexw[wbegin] - 1; d__1 = eps * 2.; odrrb_(&in, &d__[ibegin], &work[indlld + ibegin - 1], &indeig, &indeig, &c_b5, &d__1, & offset, &work[wbegin], &wgap[wbegin], & werr[wbegin], &work[indwrk], &iwork[ iindwk], pivmin, &spdiam, &itmp1, &iinfo); if (iinfo != 0) { *info = -3; return 0; } lambda = work[windex]; /* Reset twist index from inaccurate LAMBDA to */ /* force computation of true MINGMA */ iwork[iindr + windex] = 0; } /* Given LAMBDA, compute the eigenvector. */ L__1 = ! usedbs; odr1v_(&in, &c__1, &in, &lambda, &d__[ibegin], &l[ ibegin], &work[indld + ibegin - 1], &work[ indlld + ibegin - 1], pivmin, &gaptol, &z__[ ibegin + windex * z_dim1], &L__1, &negcnt, & ztz, &mingma, &iwork[iindr + windex], &isuppz[ (windex << 1) - 1], &nrminv, &resid, &rqcorr, &work[indwrk]); if (iter == 0) { bstres = resid; bstw = lambda; } else if (resid < bstres) { bstres = resid; bstw = lambda; } /* Computing MIN */ i__4 = isupmn, i__5 = isuppz[(windex << 1) - 1]; isupmn = imin(i__4,i__5); /* Computing MAX */ i__4 = isupmx, i__5 = isuppz[windex * 2]; isupmx = imax(i__4,i__5); ++iter; /* sin alpha <= |resid|/gap */ /* Note that both the residual and the gap are */ /* proportional to the matrix, so ||T|| doesn't play */ /* a role in the quotient */ /* Convergence test for Rayleigh-Quotient iteration */ /* (omitted when Bisection has been used) */ if (resid > tol * gap && fabs(rqcorr) > rqtol * fabs( lambda) && ! usedbs) { /* We need to check that the RQCORR update doesn't */ /* move the eigenvalue away from the desired one and */ /* towards a neighbor. -> protection with bisection */ if (indeig <= negcnt) { /* The wanted eigenvalue lies to the left */ sgndef = -1.; } else { /* The wanted eigenvalue lies to the right */ sgndef = 1.; } /* We only use the RQCORR if it improves the */ /* the iterate reasonably. */ if (rqcorr * sgndef >= 0. && lambda + rqcorr <= right && lambda + rqcorr >= left) { usedrq = TRUE_; /* Store new midpoint of bisection interval in WORK */ if (sgndef == 1.) { /* The current LAMBDA is on the left of the true */ /* eigenvalue */ left = lambda; /* We prefer to assume that the error estimate */ /* is correct. We could make the interval not */ /* as a bracket but to be modified if the RQCORR */ /* chooses to. In this case, the RIGHT side should */ /* be modified as follows: */ /* RIGHT = MAX(RIGHT, LAMBDA + RQCORR) */ } else { /* The current LAMBDA is on the right of the true */ /* eigenvalue */ right = lambda; /* See comment about assuming the error estimate is */ /* correct above. */ /* LEFT = MIN(LEFT, LAMBDA + RQCORR) */ } work[windex] = (right + left) * .5; /* Take RQCORR since it has the correct sign and */ /* improves the iterate reasonably */ lambda += rqcorr; /* Update width of error interval */ werr[windex] = (right - left) * .5; } else { needbs = TRUE_; } if (right - left < rqtol * fabs(lambda)) { /* The eigenvalue is computed to bisection accuracy */ /* compute eigenvector and stop */ usedbs = TRUE_; goto L120; } else if (iter < 10) { goto L120; } else if (iter == 10) { needbs = TRUE_; goto L120; } else { *info = 5; return 0; } } else { stp2ii = FALSE_; if (usedrq && usedbs && bstres <= resid) { lambda = bstw; stp2ii = TRUE_; } if (stp2ii) { /* improve error angle by second step */ L__1 = ! usedbs; odr1v_(&in, &c__1, &in, &lambda, &d__[ibegin] , &l[ibegin], &work[indld + ibegin - 1], &work[indlld + ibegin - 1], pivmin, &gaptol, &z__[ibegin + windex * z_dim1], &L__1, &negcnt, &ztz, & mingma, &iwork[iindr + windex], & isuppz[(windex << 1) - 1], &nrminv, & resid, &rqcorr, &work[indwrk]); } work[windex] = lambda; } /* Compute FP-vector support w.r.t. whole matrix */ isuppz[(windex << 1) - 1] += oldien; isuppz[windex * 2] += oldien; zfrom = isuppz[(windex << 1) - 1]; zto = isuppz[windex * 2]; isupmn += oldien; isupmx += oldien; /* Ensure vector is ok if support in the RQI has changed */ if (isupmn < zfrom) { i__4 = zfrom - 1; for (ii = isupmn; ii <= i__4; ++ii) { z__[ii + windex * z_dim1] = 0.; /* L122: */ } } if (isupmx > zto) { i__4 = isupmx; for (ii = zto + 1; ii <= i__4; ++ii) { z__[ii + windex * z_dim1] = 0.; /* L123: */ } } i__4 = zto - zfrom + 1; odscl_(&i__4, &nrminv, &z__[zfrom + windex * z_dim1], &c__1); L125: /* Update W */ w[windex] = lambda + sigma; /* Recompute the gaps on the left and right */ /* But only allow them to become larger and not */ /* smaller (which can only happen through "bad" */ /* cancellation and doesn't reflect the theory */ /* where the initial gaps are underestimated due */ /* to WERR being too crude.) */ if (! eskip) { if (k > 1) { /* Computing MAX */ d__1 = wgap[windmn], d__2 = w[windex] - werr[ windex] - w[windmn] - werr[windmn]; wgap[windmn] = fmax(d__1,d__2); } if (windex < wend) { /* Computing MAX */ d__1 = savgap, d__2 = w[windpl] - werr[windpl] - w[windex] - werr[windex]; wgap[windex] = fmax(d__1,d__2); } } ++idone; } /* here ends the code for the current child */ L139: /* Proceed to any remaining child nodes */ newfst = j + 1; L140: ; } /* L150: */ } ++ndepth; goto L40; } ibegin = iend + 1; wbegin = wend + 1; L170: ; } return 0; /* End of ODRRV */ } /* odrrv_ */
the_stack_data/25137391.c
/*** * This code is a part of EvoApproxLib library (ehw.fit.vutbr.cz/approxlib) distributed under The MIT License. * When used, please cite the following article(s): V. Mrazek, L. Sekanina, Z. Vasicek "Libraries of Approximate Circuits: Automated Design and Application in CNN Accelerators" IEEE Journal on Emerging and Selected Topics in Circuits and Systems, Vol 10, No 4, 2020 * This file contains a circuit from a sub-set of pareto optimal circuits with respect to the pwr and ep parameters ***/ // MAE% = 0.078 % // MAE = 0.2 // WCE% = 0.78 % // WCE = 2.0 // WCRE% = 100.00 % // EP% = 12.50 % // MRE% = 1.00 % // MSE = 0.5 // PDK45_PWR = 0.034 mW // PDK45_AREA = 78.4 um2 // PDK45_DELAY = 0.60 ns #include <stdint.h> #include <stdlib.h> uint64_t add8se_7C9(const uint64_t B,const uint64_t A) { uint64_t dout_16, dout_17, dout_18, dout_19, dout_20, dout_21, dout_22, dout_23, dout_24, dout_25, dout_26, dout_27, dout_28, dout_29, dout_30, dout_31, dout_32, dout_33, dout_34, dout_35, dout_36, dout_37, dout_38, dout_39, dout_40, dout_41, dout_42, dout_43, dout_44, dout_45, dout_46, dout_47, dout_48, dout_49, dout_50, dout_51, dout_52, dout_53, dout_54, dout_55, dout_56, dout_57, dout_58, dout_59, dout_60, dout_61, dout_62, dout_63, dout_64, dout_65, dout_66; uint64_t O; dout_16=((A >> 0)&1)&((B >> 0)&1); dout_17=((A >> 0)&1)^((B >> 0)&1); dout_18=((A >> 1)&1)&((B >> 1)&1); dout_19=((A >> 1)&1)^((B >> 1)&1); dout_20=((A >> 2)&1)&((B >> 2)&1); dout_21=((A >> 2)&1)^((B >> 2)&1); dout_22=((A >> 3)&1)&((B >> 3)&1); dout_23=((A >> 3)&1)^((B >> 3)&1); dout_24=((A >> 4)&1)&((B >> 4)&1); dout_25=((A >> 4)&1)^((B >> 4)&1); dout_26=((A >> 5)&1)&((B >> 5)&1); dout_27=((A >> 5)&1)^((B >> 5)&1); dout_28=((A >> 6)&1)&((B >> 6)&1); dout_29=((A >> 6)&1)^((B >> 6)&1); dout_30=((A >> 7)&1)&((B >> 7)&1); dout_31=((A >> 7)&1)^((B >> 7)&1); dout_32=((A >> 7)&1)^((B >> 7)&1); dout_33=dout_21&dout_18; dout_34=dout_21&dout_19; dout_35=dout_20|dout_33; dout_36=dout_25&dout_22; dout_37=dout_25&dout_23; dout_38=dout_24|dout_36; dout_39=dout_29&dout_26; dout_40=dout_29&dout_27; dout_41=dout_28|dout_39; dout_42=dout_34&dout_16; dout_43=dout_35|dout_42; dout_44=dout_40&dout_38; dout_45=dout_40&dout_37; dout_46=dout_41|dout_44; dout_47=dout_45&dout_43; dout_48=dout_46|dout_47; dout_49=dout_37&dout_43; dout_50=dout_38|dout_49; dout_51=dout_19&dout_16; dout_52=dout_18|dout_51; dout_53=dout_23&dout_43; dout_54=dout_22|dout_53; dout_55=dout_27&dout_50; dout_56=dout_26|dout_55; dout_57=dout_31&dout_48; dout_58=dout_30|dout_57; dout_59=dout_19^dout_51; dout_60=dout_21^dout_52; dout_61=dout_23^dout_43; dout_62=dout_25^dout_54; dout_63=dout_27^dout_50; dout_64=dout_29^dout_56; dout_65=dout_31^dout_48; dout_66=dout_32^dout_58; O = 0; O |= (dout_17&1) << 0; O |= (dout_59&1) << 1; O |= (dout_60&1) << 2; O |= (dout_61&1) << 3; O |= (dout_62&1) << 4; O |= (dout_63&1) << 5; O |= (dout_64&1) << 6; O |= (dout_65&1) << 7; O |= (dout_66&1) << 8; return O; }
the_stack_data/153269103.c
#include <stdio.h> main() { extern char *gets(); extern double frexp(), atof(); double real, fraction; int ep; char string[64]; for (;;) { printf("Enter number: "); if (gets(string) == NULL) break; real = atof(string); fraction = frexp(real, &ep); printf("%lf is the fraction of %lf\n", fraction, real); printf("%d is the binary exponent of %lf\n", ep, real); } putchar('\n'); }
the_stack_data/248580474.c
void test (char *s1, int x); void test3 (int, char *s1); void test2 (/*@only@*/ char *s1, int x); char *copystring (char *s); int f (/*@only@*/ char *name) /*@modifies *name;@*/ { test (name, f(name)); /* 1. Variable name used after being released */ test3 (f(name), name); /* 2. Variable name used after being released */ test2 (copystring(name), f(name)); /* 3. Argument 2 modifies *name, used by ... */ return 3; }
the_stack_data/109274.c
/** *2_Escreva um programa em C que receba três números inteiros como *entrada e imprima, como saída, os números em ordem crescente. */ #include <stdio.h> int main() { int n1, n2, n3; printf("Digite tres numeros: \n"); scanf("%d %d %d", &n1, &n2, &n3); if (n1 <= n2) { if (n2 <= n3) { printf("A ordem crescente: %d %d %d\n", n1, n2, n3); } else { if (n1 <= n3) { printf("A ordem crescente: %d %d %d\n", n1, n3, n2); } else { printf("A ordem crescente: %d %d %d\n", n3, n1, n2); } } } else { if (n1 <= n3) { printf("A ordem crescente: %d %d %d\n", n2, n1, n3); } else { if (n2 <= n3) { printf("A ordem crescente: %d %d %d\n", n2, n3, n1); } else { printf("A ordem crescente: %d %d %d\n", n3, n2, n1); } } } return 0; }
the_stack_data/61074887.c
// general protection fault in __smc_diag_dump // https://syzkaller.appspot.com/bug?id=c3fd5631a937ba55b81518905497c9b32320da3b // status:open // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <arpa/inet.h> #include <dirent.h> #include <endian.h> #include <errno.h> #include <fcntl.h> #include <net/if.h> #include <net/if_arp.h> #include <netinet/in.h> #include <pthread.h> #include <sched.h> #include <setjmp.h> #include <signal.h> #include <stdarg.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/time.h> #include <sys/types.h> #include <sys/uio.h> #include <sys/wait.h> #include <time.h> #include <unistd.h> #include <linux/futex.h> #include <linux/if_addr.h> #include <linux/if_ether.h> #include <linux/if_link.h> #include <linux/if_tun.h> #include <linux/in6.h> #include <linux/ip.h> #include <linux/neighbour.h> #include <linux/net.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> #include <linux/tcp.h> #include <linux/veth.h> unsigned long long procid; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_RELAXED)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } static struct { char* pos; int nesting; struct nlattr* nested[8]; char buf[1024]; } nlmsg; static void netlink_init(int typ, int flags, const void* data, int size) { memset(&nlmsg, 0, sizeof(nlmsg)); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf; hdr->nlmsg_type = typ; hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags; memcpy(hdr + 1, data, size); nlmsg.pos = (char*)(hdr + 1) + NLMSG_ALIGN(size); } static void netlink_attr(int typ, const void* data, int size) { struct nlattr* attr = (struct nlattr*)nlmsg.pos; attr->nla_len = sizeof(*attr) + size; attr->nla_type = typ; memcpy(attr + 1, data, size); nlmsg.pos += NLMSG_ALIGN(attr->nla_len); } static void netlink_nest(int typ) { struct nlattr* attr = (struct nlattr*)nlmsg.pos; attr->nla_type = typ; nlmsg.pos += sizeof(*attr); nlmsg.nested[nlmsg.nesting++] = attr; } static void netlink_done(void) { struct nlattr* attr = nlmsg.nested[--nlmsg.nesting]; attr->nla_len = nlmsg.pos - (char*)attr; } static int netlink_send(int sock) { if (nlmsg.pos > nlmsg.buf + sizeof(nlmsg.buf) || nlmsg.nesting) exit(1); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg.buf; hdr->nlmsg_len = nlmsg.pos - nlmsg.buf; struct sockaddr_nl addr; memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; unsigned n = sendto(sock, nlmsg.buf, hdr->nlmsg_len, 0, (struct sockaddr*)&addr, sizeof(addr)); if (n != hdr->nlmsg_len) exit(1); n = recv(sock, nlmsg.buf, sizeof(nlmsg.buf), 0); if (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr)) exit(1); if (hdr->nlmsg_type != NLMSG_ERROR) exit(1); return -((struct nlmsgerr*)(hdr + 1))->error; } static void netlink_add_device_impl(const char* type, const char* name) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); netlink_init(RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr)); if (name) netlink_attr(IFLA_IFNAME, name, strlen(name)); netlink_nest(IFLA_LINKINFO); netlink_attr(IFLA_INFO_KIND, type, strlen(type)); } static void netlink_add_device(int sock, const char* type, const char* name) { netlink_add_device_impl(type, name); netlink_done(); int err = netlink_send(sock); (void)err; } static void netlink_add_veth(int sock, const char* name, const char* peer) { netlink_add_device_impl("veth", name); netlink_nest(IFLA_INFO_DATA); netlink_nest(VETH_INFO_PEER); nlmsg.pos += sizeof(struct ifinfomsg); netlink_attr(IFLA_IFNAME, peer, strlen(peer)); netlink_done(); netlink_done(); netlink_done(); int err = netlink_send(sock); (void)err; } static void netlink_add_hsr(int sock, const char* name, const char* slave1, const char* slave2) { netlink_add_device_impl("hsr", name); netlink_nest(IFLA_INFO_DATA); int ifindex1 = if_nametoindex(slave1); netlink_attr(IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1)); int ifindex2 = if_nametoindex(slave2); netlink_attr(IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2)); netlink_done(); netlink_done(); int err = netlink_send(sock); (void)err; } static void netlink_device_change(int sock, const char* name, bool up, const char* master, const void* mac, int macsize) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); if (up) hdr.ifi_flags = hdr.ifi_change = IFF_UP; netlink_init(RTM_NEWLINK, 0, &hdr, sizeof(hdr)); netlink_attr(IFLA_IFNAME, name, strlen(name)); if (master) { int ifindex = if_nametoindex(master); netlink_attr(IFLA_MASTER, &ifindex, sizeof(ifindex)); } if (macsize) netlink_attr(IFLA_ADDRESS, mac, macsize); int err = netlink_send(sock); (void)err; } static int netlink_add_addr(int sock, const char* dev, const void* addr, int addrsize) { struct ifaddrmsg hdr; memset(&hdr, 0, sizeof(hdr)); hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6; hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120; hdr.ifa_scope = RT_SCOPE_UNIVERSE; hdr.ifa_index = if_nametoindex(dev); netlink_init(RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr, sizeof(hdr)); netlink_attr(IFA_LOCAL, addr, addrsize); netlink_attr(IFA_ADDRESS, addr, addrsize); return netlink_send(sock); } static void netlink_add_addr4(int sock, const char* dev, const char* addr) { struct in_addr in_addr; inet_pton(AF_INET, addr, &in_addr); int err = netlink_add_addr(sock, dev, &in_addr, sizeof(in_addr)); (void)err; } static void netlink_add_addr6(int sock, const char* dev, const char* addr) { struct in6_addr in6_addr; inet_pton(AF_INET6, addr, &in6_addr); int err = netlink_add_addr(sock, dev, &in6_addr, sizeof(in6_addr)); (void)err; } static void netlink_add_neigh(int sock, const char* name, const void* addr, int addrsize, const void* mac, int macsize) { struct ndmsg hdr; memset(&hdr, 0, sizeof(hdr)); hdr.ndm_family = addrsize == 4 ? AF_INET : AF_INET6; hdr.ndm_ifindex = if_nametoindex(name); hdr.ndm_state = NUD_PERMANENT; netlink_init(RTM_NEWNEIGH, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr)); netlink_attr(NDA_DST, addr, addrsize); netlink_attr(NDA_LLADDR, mac, macsize); int err = netlink_send(sock); (void)err; } static int tunfd = -1; static int tun_frags_enabled; #define SYZ_TUN_MAX_PACKET_SIZE 1000 #define TUN_IFACE "syz_tun" #define LOCAL_MAC 0xaaaaaaaaaaaa #define REMOTE_MAC 0xaaaaaaaaaabb #define LOCAL_IPV4 "172.20.20.170" #define REMOTE_IPV4 "172.20.20.187" #define LOCAL_IPV6 "fe80::aa" #define REMOTE_IPV6 "fe80::bb" #define IFF_NAPI 0x0010 #define IFF_NAPI_FRAGS 0x0020 static void initialize_tun(void) { tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK); if (tunfd == -1) { printf("tun: can't open /dev/net/tun: please enable CONFIG_TUN=y\n"); printf("otherwise fuzzing or reproducing might not work as intended\n"); return; } const int kTunFd = 240; if (dup2(tunfd, kTunFd) < 0) exit(1); close(tunfd); tunfd = kTunFd; struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, TUN_IFACE, IFNAMSIZ); ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_NAPI | IFF_NAPI_FRAGS; if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) { ifr.ifr_flags = IFF_TAP | IFF_NO_PI; if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) exit(1); } if (ioctl(tunfd, TUNGETIFF, (void*)&ifr) < 0) exit(1); tun_frags_enabled = (ifr.ifr_flags & IFF_NAPI_FRAGS) != 0; char sysctl[64]; sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/accept_dad", TUN_IFACE); write_file(sysctl, "0"); sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/router_solicitations", TUN_IFACE); write_file(sysctl, "0"); int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); netlink_add_addr4(sock, TUN_IFACE, LOCAL_IPV4); netlink_add_addr6(sock, TUN_IFACE, LOCAL_IPV6); uint64_t macaddr = REMOTE_MAC; struct in_addr in_addr; inet_pton(AF_INET, REMOTE_IPV4, &in_addr); netlink_add_neigh(sock, TUN_IFACE, &in_addr, sizeof(in_addr), &macaddr, ETH_ALEN); struct in6_addr in6_addr; inet_pton(AF_INET6, REMOTE_IPV6, &in6_addr); netlink_add_neigh(sock, TUN_IFACE, &in6_addr, sizeof(in6_addr), &macaddr, ETH_ALEN); macaddr = LOCAL_MAC; netlink_device_change(sock, TUN_IFACE, true, 0, &macaddr, ETH_ALEN); close(sock); } #define DEV_IPV4 "172.20.20.%d" #define DEV_IPV6 "fe80::%02x" #define DEV_MAC 0x00aaaaaaaaaa static void initialize_netdevices(void) { char netdevsim[16]; sprintf(netdevsim, "netdevsim%d", (int)procid); struct { const char* type; const char* dev; } devtypes[] = { {"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"}, {"vcan", "vcan0"}, {"bond", "bond0"}, {"team", "team0"}, {"dummy", "dummy0"}, {"nlmon", "nlmon0"}, {"caif", "caif0"}, {"batadv", "batadv0"}, {"vxcan", "vxcan1"}, {"netdevsim", netdevsim}, {"veth", 0}, }; const char* devmasters[] = {"bridge", "bond", "team"}; struct { const char* name; int macsize; bool noipv6; } devices[] = { {"lo", ETH_ALEN}, {"sit0", 0}, {"bridge0", ETH_ALEN}, {"vcan0", 0, true}, {"tunl0", 0}, {"gre0", 0}, {"gretap0", ETH_ALEN}, {"ip_vti0", 0}, {"ip6_vti0", 0}, {"ip6tnl0", 0}, {"ip6gre0", 0}, {"ip6gretap0", ETH_ALEN}, {"erspan0", ETH_ALEN}, {"bond0", ETH_ALEN}, {"veth0", ETH_ALEN}, {"veth1", ETH_ALEN}, {"team0", ETH_ALEN}, {"veth0_to_bridge", ETH_ALEN}, {"veth1_to_bridge", ETH_ALEN}, {"veth0_to_bond", ETH_ALEN}, {"veth1_to_bond", ETH_ALEN}, {"veth0_to_team", ETH_ALEN}, {"veth1_to_team", ETH_ALEN}, {"veth0_to_hsr", ETH_ALEN}, {"veth1_to_hsr", ETH_ALEN}, {"hsr0", 0}, {"dummy0", ETH_ALEN}, {"nlmon0", 0}, {"vxcan1", 0, true}, {"caif0", ETH_ALEN}, {"batadv0", ETH_ALEN}, {netdevsim, ETH_ALEN}, }; int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) netlink_add_device(sock, devtypes[i].type, devtypes[i].dev); for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) { char master[32], slave0[32], veth0[32], slave1[32], veth1[32]; sprintf(slave0, "%s_slave_0", devmasters[i]); sprintf(veth0, "veth0_to_%s", devmasters[i]); netlink_add_veth(sock, slave0, veth0); sprintf(slave1, "%s_slave_1", devmasters[i]); sprintf(veth1, "veth1_to_%s", devmasters[i]); netlink_add_veth(sock, slave1, veth1); sprintf(master, "%s0", devmasters[i]); netlink_device_change(sock, slave0, false, master, 0, 0); netlink_device_change(sock, slave1, false, master, 0, 0); } netlink_device_change(sock, "bridge_slave_0", true, 0, 0, 0); netlink_device_change(sock, "bridge_slave_1", true, 0, 0, 0); netlink_add_veth(sock, "hsr_slave_0", "veth0_to_hsr"); netlink_add_veth(sock, "hsr_slave_1", "veth1_to_hsr"); netlink_add_hsr(sock, "hsr0", "hsr_slave_0", "hsr_slave_1"); netlink_device_change(sock, "hsr_slave_0", true, 0, 0, 0); netlink_device_change(sock, "hsr_slave_1", true, 0, 0, 0); for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) { char addr[32]; sprintf(addr, DEV_IPV4, i + 10); netlink_add_addr4(sock, devices[i].name, addr); if (!devices[i].noipv6) { sprintf(addr, DEV_IPV6, i + 10); netlink_add_addr6(sock, devices[i].name, addr); } uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40); netlink_device_change(sock, devices[i].name, true, 0, &macaddr, devices[i].macsize); } close(sock); } static void initialize_netdevices_init(void) { int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); struct { const char* type; int macsize; bool noipv6; bool noup; } devtypes[] = { {"nr", 7, true}, {"rose", 5, true, true}, }; unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) { char dev[32], addr[32]; sprintf(dev, "%s%d", devtypes[i].type, (int)procid); sprintf(addr, "172.30.%d.%d", i, (int)procid + 1); netlink_add_addr4(sock, dev, addr); if (!devtypes[i].noipv6) { sprintf(addr, "fe88::%02x:%02x", i, (int)procid + 1); netlink_add_addr6(sock, dev, addr); } int macsize = devtypes[i].macsize; uint64_t macaddr = 0xbbbbbb + ((unsigned long long)i << (8 * (macsize - 2))) + (procid << (8 * (macsize - 1))); netlink_device_change(sock, dev, !devtypes[i].noup, 0, &macaddr, macsize); } close(sock); } static int read_tun(char* data, int size) { if (tunfd < 0) return -1; int rv = read(tunfd, data, size); if (rv < 0) { if (errno == EAGAIN) return -1; if (errno == EBADFD) return -1; exit(1); } return rv; } static void flush_tun() { char data[SYZ_TUN_MAX_PACKET_SIZE]; while (read_tun(&data[0], sizeof(data)) != -1) { } } #define XT_TABLE_SIZE 1536 #define XT_MAX_ENTRIES 10 struct xt_counters { uint64_t pcnt, bcnt; }; struct ipt_getinfo { char name[32]; unsigned int valid_hooks; unsigned int hook_entry[5]; unsigned int underflow[5]; unsigned int num_entries; unsigned int size; }; struct ipt_get_entries { char name[32]; unsigned int size; void* entrytable[XT_TABLE_SIZE / sizeof(void*)]; }; struct ipt_replace { char name[32]; unsigned int valid_hooks; unsigned int num_entries; unsigned int size; unsigned int hook_entry[5]; unsigned int underflow[5]; unsigned int num_counters; struct xt_counters* counters; char entrytable[XT_TABLE_SIZE]; }; struct ipt_table_desc { const char* name; struct ipt_getinfo info; struct ipt_replace replace; }; static struct ipt_table_desc ipv4_tables[] = { {.name = "filter"}, {.name = "nat"}, {.name = "mangle"}, {.name = "raw"}, {.name = "security"}, }; static struct ipt_table_desc ipv6_tables[] = { {.name = "filter"}, {.name = "nat"}, {.name = "mangle"}, {.name = "raw"}, {.name = "security"}, }; #define IPT_BASE_CTL 64 #define IPT_SO_SET_REPLACE (IPT_BASE_CTL) #define IPT_SO_GET_INFO (IPT_BASE_CTL) #define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1) struct arpt_getinfo { char name[32]; unsigned int valid_hooks; unsigned int hook_entry[3]; unsigned int underflow[3]; unsigned int num_entries; unsigned int size; }; struct arpt_get_entries { char name[32]; unsigned int size; void* entrytable[XT_TABLE_SIZE / sizeof(void*)]; }; struct arpt_replace { char name[32]; unsigned int valid_hooks; unsigned int num_entries; unsigned int size; unsigned int hook_entry[3]; unsigned int underflow[3]; unsigned int num_counters; struct xt_counters* counters; char entrytable[XT_TABLE_SIZE]; }; struct arpt_table_desc { const char* name; struct arpt_getinfo info; struct arpt_replace replace; }; static struct arpt_table_desc arpt_tables[] = { {.name = "filter"}, }; #define ARPT_BASE_CTL 96 #define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL) #define ARPT_SO_GET_INFO (ARPT_BASE_CTL) #define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1) static void checkpoint_iptables(struct ipt_table_desc* tables, int num_tables, int family, int level) { struct ipt_get_entries entries; socklen_t optlen; int fd, i; fd = socket(family, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < num_tables; i++) { struct ipt_table_desc* table = &tables[i]; strcpy(table->info.name, table->name); strcpy(table->replace.name, table->name); optlen = sizeof(table->info); if (getsockopt(fd, level, IPT_SO_GET_INFO, &table->info, &optlen)) { switch (errno) { case EPERM: case ENOENT: case ENOPROTOOPT: continue; } exit(1); } if (table->info.size > sizeof(table->replace.entrytable)) exit(1); if (table->info.num_entries > XT_MAX_ENTRIES) exit(1); memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size; if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); table->replace.valid_hooks = table->info.valid_hooks; table->replace.num_entries = table->info.num_entries; table->replace.size = table->info.size; memcpy(table->replace.hook_entry, table->info.hook_entry, sizeof(table->replace.hook_entry)); memcpy(table->replace.underflow, table->info.underflow, sizeof(table->replace.underflow)); memcpy(table->replace.entrytable, entries.entrytable, table->info.size); } close(fd); } static void reset_iptables(struct ipt_table_desc* tables, int num_tables, int family, int level) { struct xt_counters counters[XT_MAX_ENTRIES]; struct ipt_get_entries entries; struct ipt_getinfo info; socklen_t optlen; int fd, i; fd = socket(family, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < num_tables; i++) { struct ipt_table_desc* table = &tables[i]; if (table->info.valid_hooks == 0) continue; memset(&info, 0, sizeof(info)); strcpy(info.name, table->name); optlen = sizeof(info); if (getsockopt(fd, level, IPT_SO_GET_INFO, &info, &optlen)) exit(1); if (memcmp(&table->info, &info, sizeof(table->info)) == 0) { memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size; if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); if (memcmp(table->replace.entrytable, entries.entrytable, table->info.size) == 0) continue; } table->replace.num_counters = info.num_entries; table->replace.counters = counters; optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) + table->replace.size; if (setsockopt(fd, level, IPT_SO_SET_REPLACE, &table->replace, optlen)) exit(1); } close(fd); } static void checkpoint_arptables(void) { struct arpt_get_entries entries; socklen_t optlen; unsigned i; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) { struct arpt_table_desc* table = &arpt_tables[i]; strcpy(table->info.name, table->name); strcpy(table->replace.name, table->name); optlen = sizeof(table->info); if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &table->info, &optlen)) { switch (errno) { case EPERM: case ENOENT: case ENOPROTOOPT: continue; } exit(1); } if (table->info.size > sizeof(table->replace.entrytable)) exit(1); if (table->info.num_entries > XT_MAX_ENTRIES) exit(1); memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size; if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); table->replace.valid_hooks = table->info.valid_hooks; table->replace.num_entries = table->info.num_entries; table->replace.size = table->info.size; memcpy(table->replace.hook_entry, table->info.hook_entry, sizeof(table->replace.hook_entry)); memcpy(table->replace.underflow, table->info.underflow, sizeof(table->replace.underflow)); memcpy(table->replace.entrytable, entries.entrytable, table->info.size); } close(fd); } static void reset_arptables() { struct xt_counters counters[XT_MAX_ENTRIES]; struct arpt_get_entries entries; struct arpt_getinfo info; socklen_t optlen; unsigned i; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) { struct arpt_table_desc* table = &arpt_tables[i]; if (table->info.valid_hooks == 0) continue; memset(&info, 0, sizeof(info)); strcpy(info.name, table->name); optlen = sizeof(info); if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &info, &optlen)) exit(1); if (memcmp(&table->info, &info, sizeof(table->info)) == 0) { memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size; if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); if (memcmp(table->replace.entrytable, entries.entrytable, table->info.size) == 0) continue; } else { } table->replace.num_counters = info.num_entries; table->replace.counters = counters; optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) + table->replace.size; if (setsockopt(fd, SOL_IP, ARPT_SO_SET_REPLACE, &table->replace, optlen)) exit(1); } close(fd); } #define NF_BR_NUMHOOKS 6 #define EBT_TABLE_MAXNAMELEN 32 #define EBT_CHAIN_MAXNAMELEN 32 #define EBT_BASE_CTL 128 #define EBT_SO_SET_ENTRIES (EBT_BASE_CTL) #define EBT_SO_GET_INFO (EBT_BASE_CTL) #define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO + 1) #define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES + 1) #define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO + 1) struct ebt_replace { char name[EBT_TABLE_MAXNAMELEN]; unsigned int valid_hooks; unsigned int nentries; unsigned int entries_size; struct ebt_entries* hook_entry[NF_BR_NUMHOOKS]; unsigned int num_counters; struct ebt_counter* counters; char* entries; }; struct ebt_entries { unsigned int distinguisher; char name[EBT_CHAIN_MAXNAMELEN]; unsigned int counter_offset; int policy; unsigned int nentries; char data[0] __attribute__((aligned(__alignof__(struct ebt_replace)))); }; struct ebt_table_desc { const char* name; struct ebt_replace replace; char entrytable[XT_TABLE_SIZE]; }; static struct ebt_table_desc ebt_tables[] = { {.name = "filter"}, {.name = "nat"}, {.name = "broute"}, }; static void checkpoint_ebtables(void) { socklen_t optlen; unsigned i; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) { struct ebt_table_desc* table = &ebt_tables[i]; strcpy(table->replace.name, table->name); optlen = sizeof(table->replace); if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_INFO, &table->replace, &optlen)) { switch (errno) { case EPERM: case ENOENT: case ENOPROTOOPT: continue; } exit(1); } if (table->replace.entries_size > sizeof(table->entrytable)) exit(1); table->replace.num_counters = 0; table->replace.entries = table->entrytable; optlen = sizeof(table->replace) + table->replace.entries_size; if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_ENTRIES, &table->replace, &optlen)) exit(1); } close(fd); } static void reset_ebtables() { struct ebt_replace replace; char entrytable[XT_TABLE_SIZE]; socklen_t optlen; unsigned i, j, h; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) { struct ebt_table_desc* table = &ebt_tables[i]; if (table->replace.valid_hooks == 0) continue; memset(&replace, 0, sizeof(replace)); strcpy(replace.name, table->name); optlen = sizeof(replace); if (getsockopt(fd, SOL_IP, EBT_SO_GET_INFO, &replace, &optlen)) exit(1); replace.num_counters = 0; table->replace.entries = 0; for (h = 0; h < NF_BR_NUMHOOKS; h++) table->replace.hook_entry[h] = 0; if (memcmp(&table->replace, &replace, sizeof(table->replace)) == 0) { memset(&entrytable, 0, sizeof(entrytable)); replace.entries = entrytable; optlen = sizeof(replace) + replace.entries_size; if (getsockopt(fd, SOL_IP, EBT_SO_GET_ENTRIES, &replace, &optlen)) exit(1); if (memcmp(table->entrytable, entrytable, replace.entries_size) == 0) continue; } for (j = 0, h = 0; h < NF_BR_NUMHOOKS; h++) { if (table->replace.valid_hooks & (1 << h)) { table->replace.hook_entry[h] = (struct ebt_entries*)table->entrytable + j; j++; } } table->replace.entries = table->entrytable; optlen = sizeof(table->replace) + table->replace.entries_size; if (setsockopt(fd, SOL_IP, EBT_SO_SET_ENTRIES, &table->replace, optlen)) exit(1); } close(fd); } static void checkpoint_net_namespace(void) { checkpoint_ebtables(); checkpoint_arptables(); checkpoint_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]), AF_INET, SOL_IP); checkpoint_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]), AF_INET6, SOL_IPV6); } static void reset_net_namespace(void) { reset_ebtables(); reset_arptables(); reset_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]), AF_INET, SOL_IP); reset_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]), AF_INET6, SOL_IPV6); } static void setup_cgroups() { if (mkdir("/syzcgroup", 0777)) { } if (mkdir("/syzcgroup/unified", 0777)) { } if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) { } if (chmod("/syzcgroup/unified", 0777)) { } write_file("/syzcgroup/unified/cgroup.subtree_control", "+cpu +memory +io +pids +rdma"); if (mkdir("/syzcgroup/cpu", 0777)) { } if (mount("none", "/syzcgroup/cpu", "cgroup", 0, "cpuset,cpuacct,perf_event,hugetlb")) { } write_file("/syzcgroup/cpu/cgroup.clone_children", "1"); if (chmod("/syzcgroup/cpu", 0777)) { } if (mkdir("/syzcgroup/net", 0777)) { } if (mount("none", "/syzcgroup/net", "cgroup", 0, "net_cls,net_prio,devices,freezer")) { } if (chmod("/syzcgroup/net", 0777)) { } } static void setup_cgroups_loop() { int pid = getpid(); char file[128]; char cgroupdir[64]; snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/pids.max", cgroupdir); write_file(file, "32"); snprintf(file, sizeof(file), "%s/memory.low", cgroupdir); write_file(file, "%d", 298 << 20); snprintf(file, sizeof(file), "%s/memory.high", cgroupdir); write_file(file, "%d", 299 << 20); snprintf(file, sizeof(file), "%s/memory.max", cgroupdir); write_file(file, "%d", 300 << 20); snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); } static void setup_cgroups_test() { char cgroupdir[64]; snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid); if (symlink(cgroupdir, "./cgroup")) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid); if (symlink(cgroupdir, "./cgroup.cpu")) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid); if (symlink(cgroupdir, "./cgroup.net")) { } } static void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } setup_cgroups(); } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (200 << 20); setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); setup_common(); sandbox_common(); initialize_netdevices_init(); if (unshare(CLONE_NEWNET)) { } initialize_tun(); initialize_netdevices(); loop(); exit(1); } #define FS_IOC_SETFLAGS _IOW('f', 2, long) static void remove_dir(const char* dir) { DIR* dp; struct dirent* ep; int iter = 0; retry: while (umount2(dir, MNT_DETACH) == 0) { } dp = opendir(dir); if (dp == NULL) { if (errno == EMFILE) { exit(1); } exit(1); } while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); while (umount2(filename, MNT_DETACH) == 0) { } struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } int i; for (i = 0;; i++) { if (unlink(filename) == 0) break; if (errno == EPERM) { int fd = open(filename, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) close(fd); continue; } } if (errno == EROFS) { break; } if (errno != EBUSY || i > 100) exit(1); if (umount2(filename, MNT_DETACH)) exit(1); } } closedir(dp); int i; for (i = 0;; i++) { if (rmdir(dir) == 0) break; if (i < 100) { if (errno == EPERM) { int fd = open(dir, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) close(fd); continue; } } if (errno == EROFS) { break; } if (errno == EBUSY) { if (umount2(dir, MNT_DETACH)) exit(1); continue; } if (errno == ENOTEMPTY) { if (iter < 100) { iter++; goto retry; } } } exit(1); } } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); int i; for (i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } static void setup_loop() { setup_cgroups_loop(); checkpoint_net_namespace(); } static void reset_loop() { reset_net_namespace(); } static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setup_cgroups_test(); write_file("/proc/self/oom_score_adj", "1000"); flush_tun(); } static void close_fds() { int fd; for (fd = 3; fd < 30; fd++) close(fd); } static void setup_binfmt_misc() { if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0)) { } write_file("/proc/sys/fs/binfmt_misc/register", ":syz0:M:0:\x01::./file0:"); write_file("/proc/sys/fs/binfmt_misc/register", ":syz1:M:1:\x02::./file0:POC"); } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; int collide = 0; again: for (call = 0; call < 10; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); close_fds(); if (!collide) { collide = 1; goto again; } } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { setup_loop(); int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); reset_loop(); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); setup_test(); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res; switch (call) { case 0: res = syscall(__NR_socket, 2, 2, 0x88); if (res != -1) r[0] = res; break; case 1: syscall(__NR_socket, 0x2b, 1, 0); break; case 2: syscall(__NR_ioctl, r[0], 0x3000008912, 0); break; case 3: res = syscall(__NR_pipe, 0x20000000); if (res != -1) { NONFAILING(r[1] = *(uint32_t*)0x20000000); NONFAILING(r[2] = *(uint32_t*)0x20000004); } break; case 4: res = syscall(__NR_socket, 2, 2, 0); if (res != -1) r[3] = res; break; case 5: NONFAILING(*(uint64_t*)0x20000100 = 0x20000800); NONFAILING(memcpy( (void*)0x20000800, "\x58\x00\x00\x00\x14\x00\xad\xfd\x8a\x98\x7e\x40\xda\x2e\x6a\x26\x2b", 17)); NONFAILING(*(uint64_t*)0x20000108 = 0x11); syscall(__NR_writev, r[2], 0x20000100, 1); break; case 6: syscall(__NR_close, r[3]); break; case 7: syscall(__NR_socket, 0x10, 3, 4); break; case 8: syscall(__NR_write, r[2], 0x20000140, 0x4240a2a0); break; case 9: syscall(__NR_splice, r[1], 0, r[3], 0, 0x80000001, 0); break; } } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); setup_binfmt_misc(); install_segv_handler(); use_temporary_dir(); do_sandbox_none(); return 0; }
the_stack_data/31387279.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "pwd.h" int echo(char *str) { if(str[0]=='$'){ char * str2 = (char*)malloc(128*sizeof(char)); for(int i=0;i<strlen(str);++i){ str2[i] = str[i+1]; } if(getenv(str2)){ printf("%s\n", getenv(str2)); } else { perror("Environment variable not found"); } free(str2); return 0; } else if (strcmp(str, "~+") == 0) { if (pwd("") != 0) { perror("k7sh pwd:"); } return 0; } else if(0==strcmp(str, "~")){ printf("%s\n", getenv("HOME")); return 0; } else printf("%s\n", str); return 0; }
the_stack_data/26083.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2015-2021 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <assert.h> #include <pthread.h> #include <unistd.h> /* Number of threads. Each thread continuously steps over a breakpoint. */ #define NTHREADS 10 pthread_t threads[NTHREADS]; pthread_barrier_t barrier; /* Used to create a conditional breakpoint that always fails. */ volatile int zero; static void * thread_func (void *arg) { pthread_barrier_wait (&barrier); while (1) { usleep (1); /* set break here */ } return NULL; } int main (void) { int ret; int i; /* Don't run forever. */ alarm (180); pthread_barrier_init (&barrier, NULL, NTHREADS + 1); /* Start the threads that constantly hits a conditional breakpoint that needs to be stepped over. */ for (i = 0; i < NTHREADS; i++) { ret = pthread_create (&threads[i], NULL, thread_func, NULL); assert (ret == 0); } /* Wait until all threads are up and running. */ pthread_barrier_wait (&barrier); /* Let them start hitting the breakpoint. */ usleep (100); /* Exit abruptly. */ return 0; }
the_stack_data/86074203.c
#include <stdio.h> int main(void) { int num1, denom1, num2, denom2, result_num, result_denom; printf("Enter first fraction: "); scanf("%d/%d", &num1, &denom1); printf("Enter second fraction: "); scanf("%d/%d", &num2, &denom2); result_num = num1 * denom2 + num2 * denom1; result_denom = denom1 * denom2; printf("The sum is %d/%d\n", result_num, result_denom); return 0; }
the_stack_data/144223.c
#include <stdio.h> typedef struct fraction { int numerator ; int denominator ; }fraction; void reduce(struct fraction f, struct fraction * reduced_f){ int gcd = f.numerator; while(f.numerator%gcd||f.denominator%gcd)gcd--; reduced_f->numerator = f.numerator/gcd; reduced_f->denominator =f.denominator/gcd; } int main(){ printf("Enter a fraction:"); struct fraction i,o; scanf("%d/%d",&i.numerator,&i.denominator); reduce(i,&o); printf("In lowest terms: %d/%d\n",o.numerator,o.denominator); }
the_stack_data/117328746.c
// https://issues.dlang.org/show_bug.cgi?id=22892 char buf[1]; void fn() { char c = *buf; }
the_stack_data/165768271.c
#include<stdio.h> int N(int a[],int l,int r,int n); int M(int a[],int l,int r,int n); int H(int a[],int l,int r); int min(int l,int r); int max(int l,int r); int main() { int n,K; scanf("%d%d",&n,&K); int a[n]; int i; for(i=0;i<n;i++) scanf("%d",&a[i]); int l,r,b[n]; for(i=0;i<K;i++) { scanf("%d%d",&l,&r); b[i]=H(a,min(N(a,l,r,n),M(a,l,r,n)),max(N(a,l,r,n),M(a,l,r,n))); } for(i=0;i<K;i++) printf("%d\n",b[i]); return 0; } int N(int a[],int l,int r,int n) { int i,x=0; for(i=l;i<=r;i++) x=(x+a[i])%n; return x; } int M(int a[],int l,int r,int n) { int i,x=1; for(i=l;i<=r;i++) x=(x*a[i])%n; return x; } int H(int a[],int l,int r) { int i,x; x=a[l]; if(l!=r) for(i=l+1;i<=r;i++) x=x^a[i]; return x; } int min(int l,int r) { int m; if(l<r) m=l; else m=r; return m; } int max(int l,int r) { int m; if(l>r) m=l; else m=r; return m; }
the_stack_data/26701235.c
// 地图上显示蛇的身子 // #include <curses.h> struct Snack { int x; int y; struct Snack *next; }; // 全局变量用g_开头 struct Snack g_snack = {3, 3, NULL}; void process_key() { int key; while (1) { key = getch(); switch (key) { case KEY_UP: printw("KEY_UP\n"); break; case KEY_DOWN: printw("KEY_DOWN\n"); break; case KEY_LEFT: printw("KEY_LEFT\n"); break; case KEY_RIGHT: printw("KEY_RIGHT\n"); break; default: // 打印其他按键 printw(" 0%o, %c\n", key, key); break; } } } void init_ncurse() { // 不显示输入的按键 noecho(); // Special keys. In order to capture special keystrokes like Backspace, // Delete and the four arrow keys by getch(), you need to call keypad(stdscr, TRUE); } void init_map() { int x; int y; for (x = 0; x < 20; x++) { for (y = 0; y < 20; y++) { if (x == 0 || x == 19) { printw("--"); } else if (y == 0 || y == 19) { if (y == 0) { printw("| "); } else { printw(" |"); } } else { // 打印蛇的身子或者空格 //if (x == 3 && y == 3) if (x == g_snack.x && y == g_snack.y) { printw("[]"); } else { printw(" "); } } } printw("\n"); } } int main() { initscr(); init_map(); getch(); endwin(); }
the_stack_data/183023.c
/* f2c.h -- Standard Fortran to C header file */ /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ #ifndef F2C_INCLUDE #define F2C_INCLUDE #include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimag(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static integer c_n1 = -1; /* > \brief <b> DSYSV computes the solution to system of linear equations A * X = B for SY matrices</b> */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download DSYSV + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsysv.f "> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsysv.f "> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsysv.f "> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE DSYSV( UPLO, N, NRHS, A, LDA, IPIV, B, LDB, WORK, */ /* LWORK, INFO ) */ /* CHARACTER UPLO */ /* INTEGER INFO, LDA, LDB, LWORK, N, NRHS */ /* INTEGER IPIV( * ) */ /* DOUBLE PRECISION A( LDA, * ), B( LDB, * ), WORK( * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > DSYSV computes the solution to a real system of linear equations */ /* > A * X = B, */ /* > where A is an N-by-N symmetric matrix and X and B are N-by-NRHS */ /* > matrices. */ /* > */ /* > The diagonal pivoting method is used to factor A as */ /* > A = U * D * U**T, if UPLO = 'U', or */ /* > A = L * D * L**T, if UPLO = 'L', */ /* > where U (or L) is a product of permutation and unit upper (lower) */ /* > triangular matrices, and D is symmetric and block diagonal with */ /* > 1-by-1 and 2-by-2 diagonal blocks. The factored form of A is then */ /* > used to solve the system of equations A * X = B. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] UPLO */ /* > \verbatim */ /* > UPLO is CHARACTER*1 */ /* > = 'U': Upper triangle of A is stored; */ /* > = 'L': Lower triangle of A is stored. */ /* > \endverbatim */ /* > */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The number of linear equations, i.e., the order of the */ /* > matrix A. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] NRHS */ /* > \verbatim */ /* > NRHS is INTEGER */ /* > The number of right hand sides, i.e., the number of columns */ /* > of the matrix B. NRHS >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in,out] A */ /* > \verbatim */ /* > A is DOUBLE PRECISION array, dimension (LDA,N) */ /* > On entry, the symmetric matrix A. If UPLO = 'U', the leading */ /* > N-by-N upper triangular part of A contains the upper */ /* > triangular part of the matrix A, and the strictly lower */ /* > triangular part of A is not referenced. If UPLO = 'L', the */ /* > leading N-by-N lower triangular part of A contains the lower */ /* > triangular part of the matrix A, and the strictly upper */ /* > triangular part of A is not referenced. */ /* > */ /* > On exit, if INFO = 0, the block diagonal matrix D and the */ /* > multipliers used to obtain the factor U or L from the */ /* > factorization A = U*D*U**T or A = L*D*L**T as computed by */ /* > DSYTRF. */ /* > \endverbatim */ /* > */ /* > \param[in] LDA */ /* > \verbatim */ /* > LDA is INTEGER */ /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[out] IPIV */ /* > \verbatim */ /* > IPIV is INTEGER array, dimension (N) */ /* > Details of the interchanges and the block structure of D, as */ /* > determined by DSYTRF. If IPIV(k) > 0, then rows and columns */ /* > k and IPIV(k) were interchanged, and D(k,k) is a 1-by-1 */ /* > diagonal block. If UPLO = 'U' and IPIV(k) = IPIV(k-1) < 0, */ /* > then rows and columns k-1 and -IPIV(k) were interchanged and */ /* > D(k-1:k,k-1:k) is a 2-by-2 diagonal block. If UPLO = 'L' and */ /* > IPIV(k) = IPIV(k+1) < 0, then rows and columns k+1 and */ /* > -IPIV(k) were interchanged and D(k:k+1,k:k+1) is a 2-by-2 */ /* > diagonal block. */ /* > \endverbatim */ /* > */ /* > \param[in,out] B */ /* > \verbatim */ /* > B is DOUBLE PRECISION array, dimension (LDB,NRHS) */ /* > On entry, the N-by-NRHS right hand side matrix B. */ /* > On exit, if INFO = 0, the N-by-NRHS solution matrix X. */ /* > \endverbatim */ /* > */ /* > \param[in] LDB */ /* > \verbatim */ /* > LDB is INTEGER */ /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[out] WORK */ /* > \verbatim */ /* > WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)) */ /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ /* > \endverbatim */ /* > */ /* > \param[in] LWORK */ /* > \verbatim */ /* > LWORK is INTEGER */ /* > The length of WORK. LWORK >= 1, and for best performance */ /* > LWORK >= f2cmax(1,N*NB), where NB is the optimal blocksize for */ /* > DSYTRF. */ /* > for LWORK < N, TRS will be done with Level BLAS 2 */ /* > for LWORK >= N, TRS will be done with Level BLAS 3 */ /* > */ /* > If LWORK = -1, then a workspace query is assumed; the routine */ /* > only calculates the optimal size of the WORK array, returns */ /* > this value as the first entry of the WORK array, and no error */ /* > message related to LWORK is issued by XERBLA. */ /* > \endverbatim */ /* > */ /* > \param[out] INFO */ /* > \verbatim */ /* > INFO is INTEGER */ /* > = 0: successful exit */ /* > < 0: if INFO = -i, the i-th argument had an illegal value */ /* > > 0: if INFO = i, D(i,i) is exactly zero. The factorization */ /* > has been completed, but the block diagonal matrix D is */ /* > exactly singular, so the solution could not be computed. */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date December 2016 */ /* > \ingroup doubleSYsolve */ /* ===================================================================== */ /* Subroutine */ int dsysv_(char *uplo, integer *n, integer *nrhs, doublereal *a, integer *lda, integer *ipiv, doublereal *b, integer *ldb, doublereal *work, integer *lwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, i__1; /* Local variables */ extern logical lsame_(char *, char *); extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen), dsytrf_( char *, integer *, doublereal *, integer *, integer *, doublereal *, integer *, integer *); integer lwkopt; logical lquery; extern /* Subroutine */ int dsytrs_(char *, integer *, integer *, doublereal *, integer *, integer *, doublereal *, integer *, integer *), dsytrs2_(char *, integer *, integer *, doublereal *, integer *, integer *, doublereal *, integer *, doublereal *, integer *); /* -- LAPACK driver routine (version 3.7.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* December 2016 */ /* ===================================================================== */ /* Test the input parameters. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; --ipiv; b_dim1 = *ldb; b_offset = 1 + b_dim1 * 1; b -= b_offset; --work; /* Function Body */ *info = 0; lquery = *lwork == -1; if (! lsame_(uplo, "U") && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*nrhs < 0) { *info = -3; } else if (*lda < f2cmax(1,*n)) { *info = -5; } else if (*ldb < f2cmax(1,*n)) { *info = -8; } else if (*lwork < 1 && ! lquery) { *info = -10; } if (*info == 0) { if (*n == 0) { lwkopt = 1; } else { dsytrf_(uplo, n, &a[a_offset], lda, &ipiv[1], &work[1], &c_n1, info); lwkopt = (integer) work[1]; } work[1] = (doublereal) lwkopt; } if (*info != 0) { i__1 = -(*info); xerbla_("DSYSV ", &i__1, (ftnlen)6); return 0; } else if (lquery) { return 0; } /* Compute the factorization A = U*D*U**T or A = L*D*L**T. */ dsytrf_(uplo, n, &a[a_offset], lda, &ipiv[1], &work[1], lwork, info); if (*info == 0) { /* Solve the system A*X = B, overwriting B with X. */ if (*lwork < *n) { /* Solve with TRS ( Use Level BLAS 2) */ dsytrs_(uplo, n, nrhs, &a[a_offset], lda, &ipiv[1], &b[b_offset], ldb, info); } else { /* Solve with TRS2 ( Use Level BLAS 3) */ dsytrs2_(uplo, n, nrhs, &a[a_offset], lda, &ipiv[1], &b[b_offset], ldb, &work[1], info); } } work[1] = (doublereal) lwkopt; return 0; /* End of DSYSV */ } /* dsysv_ */
the_stack_data/68888252.c
// PARAM: --disable ana.mutex.disjoint_types --set ana.activated[+] "'var_eq'" --set ana.activated[+] "'symb_locks'" #include<pthread.h> #include<stdio.h> struct s { int datum; pthread_mutex_t mutex; } a[10]; void *t_fun(void *arg) { int i; struct s *p = &a[i]; pthread_mutex_lock(&p->mutex); p->datum++; // NOWARN pthread_mutex_unlock(&p->mutex); return NULL; } int main () { int i; pthread_t t1; pthread_create(&t1, NULL, t_fun, NULL); pthread_mutex_lock(&a[i].mutex); a[i].datum++; // NOWARN pthread_mutex_unlock(&a[i].mutex); return 0; }
the_stack_data/1103470.c
#include <stdio.h> main() { printf("Hello World!\n"); }
the_stack_data/95756.c
// myls.c ... my very own "ls" implementation #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> #include <err.h> #include <errno.h> #include <fcntl.h> #include <grp.h> #include <pwd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #ifdef __linux__ # include <bsd/string.h> #endif #include <sysexits.h> #include <unistd.h> #define MAXDIRNAME 256 #define MAXFNAME 256 #define MAXNAME 24 char *rwxmode (mode_t, char *); char *username (uid_t, char *); char *groupname (gid_t, char *); int main (int argc, char *argv[]) { // string buffers for various names char uname[MAXNAME+1]; // UNCOMMENT this line char gname[MAXNAME+1]; // UNCOMMENT this line char mode[MAXNAME+1]; // UNCOMMENT this line // collect the directory name, with "." as default char dirname[MAXDIRNAME] = "."; if (argc >= 2) strlcpy (dirname, argv[1], MAXDIRNAME); // check that the name really is a directory struct stat info; if (stat (dirname, &info) < 0) err (EX_OSERR, "%s", dirname); if (! S_ISDIR (info.st_mode)) { errno = ENOTDIR; err (EX_DATAERR, "%s", dirname); } // open the directory to start reading DIR *df; // UNCOMMENT this line df = opendir(dirname); // read directory entries struct dirent *entry; // UNCOMMENT this line while((entry = readdir(df)) != NULL) { if(entry->d_name[0] == '.' ) continue; // if the object's name start with '.' struct stat status; lstat(entry->d_name, &status); printf ( "%s %-8.8s %-8.8s %8lld %s\n", rwxmode (status.st_mode, mode), username (status.st_uid, uname), groupname(status.st_gid, gname), (long long) status.st_size, entry->d_name); } // finish up closedir(df); // UNCOMMENT this line return EXIT_SUCCESS; } // convert octal mode to -rwxrwxrwx string char *rwxmode (mode_t mode, char *str) { switch(mode & S_IFMT) { case S_IFDIR: str[0] = 'd'; break; case S_IFREG: str[0] = '-'; break; case S_IFLNK: str[0] = 'l'; break; default: str[0] = '?'; break; } if(mode & S_IRUSR) { str[1] = 'r'; } else { str[1] = '-'; } if(mode & S_IWUSR) { str[2] = 'w'; } else { str[2] = '-'; } if(mode & S_IXUSR) { str[3] = 'x'; } else { str[3] = '-'; } if(mode & S_IRGRP) { str[4] = 'r'; } else { str[4] = '-'; } if(mode & S_IWGRP) { str[5] = 'w'; } else { str[5] = '-'; } if(mode & S_IXGRP) { str[6] = 'x'; } else { str[6] = '-'; } if(mode & S_IROTH) { str[7] = 'r'; } else { str[7] = '-'; } if(mode & S_IWOTH) { str[8] = 'w'; } else { str[8] = '-'; } if(mode & S_IXOTH) { str[9] = 'x'; } else { str[9] = '-'; } return str; } // convert user id to user name char *username (uid_t uid, char *name) { struct passwd *uinfo = getpwuid (uid); if (uinfo != NULL) snprintf (name, MAXNAME, "%s", uinfo->pw_name); else snprintf (name, MAXNAME, "%d?", (int) uid); return name; } // convert group id to group name char *groupname (gid_t gid, char *name) { struct group *ginfo = getgrgid (gid); if (ginfo != NULL) snprintf (name, MAXNAME, "%s", ginfo->gr_name); else snprintf (name, MAXNAME, "%d?", (int) gid); return name; }
the_stack_data/220455177.c
#include <stdio.h> #include <stdlib.h> #include <string.h> static char* multiply(char* num1, char* num2) { if (*num1 == '\0') { return num1; } if (*num2 == '\0') { return num2; } int i, j; int len1 = strlen(num1); int len2 = strlen(num2); char *result = malloc(len1 + len2 + 1); memset(result, '0', len1 + len2 + 1); result[len1 + len2] = '\0'; for (i = len2 - 1; i >= 0; i--) { int carry = 0; for (j = len1 - 1; j >= 0; j--) { carry += (num2[i] - '0') * (num1[j] - '0') + (result[i + j + 1] - '0'); result[i + j + 1] = carry % 10 + '0'; carry /= 10; } result[i + j + 1] = carry + '0'; } while (result[0] == '0' && result[1] != '\0') { result++; } return result; } int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr, "Usage: ./test m1 m2\n"); exit(-1); } printf("%s\n", multiply(argv[1], argv[2])); return 0; }
the_stack_data/161080314.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <CL/cl.h> unsigned char *read_buffer(char *file_name, size_t *size_ptr) { FILE *f; unsigned char *buf; size_t size; /* Open file */ f = fopen(file_name, "rb"); if (!f) return NULL; /* Obtain file size */ fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); /* Allocate and read buffer */ buf = malloc(size + 1); fread(buf, 1, size, f); buf[size] = '\0'; /* Return size of buffer */ if (size_ptr) *size_ptr = size; /* Return buffer */ return buf; } void write_buffer(char *file_name, const char *buffer, size_t buffer_size) { FILE *f; /* Open file */ f = fopen(file_name, "w+"); /* Write buffer */ if(buffer) fwrite(buffer, 1, buffer_size, f); /* Close file */ fclose(f); } int main(int argc, char const *argv[]) { /* Get platform */ cl_platform_id platform; cl_uint num_platforms; cl_int ret = clGetPlatformIDs(1, &platform, &num_platforms); if (ret != CL_SUCCESS) { printf("error: call to 'clGetPlatformIDs' failed\n"); exit(1); } printf("Number of platforms: %d\n", num_platforms); printf("platform=%p\n", platform); /* Get platform name */ char platform_name[100]; ret = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clGetPlatformInfo' failed\n"); exit(1); } printf("platform.name='%s'\n\n", platform_name); /* Get device */ cl_device_id device; cl_uint num_devices; ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, &num_devices); if (ret != CL_SUCCESS) { printf("error: call to 'clGetDeviceIDs' failed\n"); exit(1); } printf("Number of devices: %d\n", num_devices); printf("device=%p\n", device); /* Get device name */ char device_name[100]; ret = clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_name), device_name, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clGetDeviceInfo' failed\n"); exit(1); } printf("device.name='%s'\n", device_name); printf("\n"); /* Create a Context Object */ cl_context context; context = clCreateContext(NULL, 1, &device, NULL, NULL, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateContext' failed\n"); exit(1); } printf("context=%p\n", context); /* Create a Command Queue Object*/ cl_command_queue command_queue; command_queue = clCreateCommandQueue(context, device, 0, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateCommandQueue' failed\n"); exit(1); } printf("command_queue=%p\n", command_queue); printf("\n"); /* Program source */ unsigned char *source_code; size_t source_length; /* Read program from 'relational_less_than_ushort2ushort2.cl' */ source_code = read_buffer("relational_less_than_ushort2ushort2.cl", &source_length); /* Create a program */ cl_program program; program = clCreateProgramWithSource(context, 1, (const char **)&source_code, &source_length, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateProgramWithSource' failed\n"); exit(1); } printf("program=%p\n", program); /* Build program */ ret = clBuildProgram(program, 1, &device, NULL, NULL, NULL); if (ret != CL_SUCCESS ) { size_t size; char *log; /* Get log size */ clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,0, NULL, &size); /* Allocate log and print */ log = malloc(size); clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,size, log, NULL); printf("error: call to 'clBuildProgram' failed:\n%s\n", log); /* Free log and exit */ free(log); exit(1); } printf("program built\n"); printf("\n"); /* Create a Kernel Object */ cl_kernel kernel; kernel = clCreateKernel(program, "relational_less_than_ushort2ushort2", &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateKernel' failed\n"); exit(1); } /* Create and allocate host buffers */ size_t num_elem = 10; /* Create and init host side src buffer 0 */ cl_ushort2 *src_0_host_buffer; src_0_host_buffer = malloc(num_elem * sizeof(cl_ushort2)); for (int i = 0; i < num_elem; i++) src_0_host_buffer[i] = (cl_ushort2){{2, 2}}; /* Create and init device side src buffer 0 */ cl_mem src_0_device_buffer; src_0_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_ushort2), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create source buffer\n"); exit(1); } ret = clEnqueueWriteBuffer(command_queue, src_0_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_ushort2), src_0_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueWriteBuffer' failed\n"); exit(1); } /* Create and init host side src buffer 1 */ cl_ushort2 *src_1_host_buffer; src_1_host_buffer = malloc(num_elem * sizeof(cl_ushort2)); for (int i = 0; i < num_elem; i++) src_1_host_buffer[i] = (cl_ushort2){{2, 2}}; /* Create and init device side src buffer 1 */ cl_mem src_1_device_buffer; src_1_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_ushort2), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create source buffer\n"); exit(1); } ret = clEnqueueWriteBuffer(command_queue, src_1_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_ushort2), src_1_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueWriteBuffer' failed\n"); exit(1); } /* Create host dst buffer */ cl_int2 *dst_host_buffer; dst_host_buffer = malloc(num_elem * sizeof(cl_int2)); memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_int2)); /* Create device dst buffer */ cl_mem dst_device_buffer; dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_int2), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create dst buffer\n"); exit(1); } /* Set kernel arguments */ ret = CL_SUCCESS; ret |= clSetKernelArg(kernel, 0, sizeof(cl_mem), &src_0_device_buffer); ret |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &src_1_device_buffer); ret |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &dst_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clSetKernelArg' failed\n"); exit(1); } /* Launch the kernel */ size_t global_work_size = num_elem; size_t local_work_size = num_elem; ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueNDRangeKernel' failed\n"); exit(1); } /* Wait for it to finish */ clFinish(command_queue); /* Read results from GPU */ ret = clEnqueueReadBuffer(command_queue, dst_device_buffer, CL_TRUE,0, num_elem * sizeof(cl_int2), dst_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueReadBuffer' failed\n"); exit(1); } /* Dump dst buffer to file */ char dump_file[100]; sprintf((char *)&dump_file, "%s.result", argv[0]); write_buffer(dump_file, (const char *)dst_host_buffer, num_elem * sizeof(cl_int2)); printf("Result dumped to %s\n", dump_file); /* Free host dst buffer */ free(dst_host_buffer); /* Free device dst buffer */ ret = clReleaseMemObject(dst_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Free host side src buffer 0 */ free(src_0_host_buffer); /* Free device side src buffer 0 */ ret = clReleaseMemObject(src_0_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Free host side src buffer 1 */ free(src_1_host_buffer); /* Free device side src buffer 1 */ ret = clReleaseMemObject(src_1_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Release kernel */ ret = clReleaseKernel(kernel); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseKernel' failed\n"); exit(1); } /* Release program */ ret = clReleaseProgram(program); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseProgram' failed\n"); exit(1); } /* Release command queue */ ret = clReleaseCommandQueue(command_queue); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseCommandQueue' failed\n"); exit(1); } /* Release context */ ret = clReleaseContext(context); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseContext' failed\n"); exit(1); } return 0; }
the_stack_data/74198.c
#include <stdio.h> #define PI 3.14f int main(void) { float radius, volume; radius = 10; volume = 4.0f / 3.0f * PI * radius * radius * radius; printf("Volume of a sphere of radius %.2fm in m^3: %.2f\n", radius, volume); return 0; }
the_stack_data/1045901.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <CL/cl.h> unsigned char *read_buffer(char *file_name, size_t *size_ptr) { FILE *f; unsigned char *buf; size_t size; /* Open file */ f = fopen(file_name, "rb"); if (!f) return NULL; /* Obtain file size */ fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); /* Allocate and read buffer */ buf = malloc(size + 1); fread(buf, 1, size, f); buf[size] = '\0'; /* Return size of buffer */ if (size_ptr) *size_ptr = size; /* Return buffer */ return buf; } void write_buffer(char *file_name, const char *buffer, size_t buffer_size) { FILE *f; /* Open file */ f = fopen(file_name, "w+"); /* Write buffer */ if(buffer) fwrite(buffer, 1, buffer_size, f); /* Close file */ fclose(f); } int main(int argc, char const *argv[]) { /* Get platform */ cl_platform_id platform; cl_uint num_platforms; cl_int ret = clGetPlatformIDs(1, &platform, &num_platforms); if (ret != CL_SUCCESS) { printf("error: call to 'clGetPlatformIDs' failed\n"); exit(1); } printf("Number of platforms: %d\n", num_platforms); printf("platform=%p\n", platform); /* Get platform name */ char platform_name[100]; ret = clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_name), platform_name, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clGetPlatformInfo' failed\n"); exit(1); } printf("platform.name='%s'\n\n", platform_name); /* Get device */ cl_device_id device; cl_uint num_devices; ret = clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, &num_devices); if (ret != CL_SUCCESS) { printf("error: call to 'clGetDeviceIDs' failed\n"); exit(1); } printf("Number of devices: %d\n", num_devices); printf("device=%p\n", device); /* Get device name */ char device_name[100]; ret = clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_name), device_name, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clGetDeviceInfo' failed\n"); exit(1); } printf("device.name='%s'\n", device_name); printf("\n"); /* Create a Context Object */ cl_context context; context = clCreateContext(NULL, 1, &device, NULL, NULL, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateContext' failed\n"); exit(1); } printf("context=%p\n", context); /* Create a Command Queue Object*/ cl_command_queue command_queue; command_queue = clCreateCommandQueue(context, device, 0, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateCommandQueue' failed\n"); exit(1); } printf("command_queue=%p\n", command_queue); printf("\n"); /* Program source */ unsigned char *source_code; size_t source_length; /* Read program from 'relational_greater_than_or_equal_to_float8float8.cl' */ source_code = read_buffer("relational_greater_than_or_equal_to_float8float8.cl", &source_length); /* Create a program */ cl_program program; program = clCreateProgramWithSource(context, 1, (const char **)&source_code, &source_length, &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateProgramWithSource' failed\n"); exit(1); } printf("program=%p\n", program); /* Build program */ ret = clBuildProgram(program, 1, &device, NULL, NULL, NULL); if (ret != CL_SUCCESS ) { size_t size; char *log; /* Get log size */ clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,0, NULL, &size); /* Allocate log and print */ log = malloc(size); clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG,size, log, NULL); printf("error: call to 'clBuildProgram' failed:\n%s\n", log); /* Free log and exit */ free(log); exit(1); } printf("program built\n"); printf("\n"); /* Create a Kernel Object */ cl_kernel kernel; kernel = clCreateKernel(program, "relational_greater_than_or_equal_to_float8float8", &ret); if (ret != CL_SUCCESS) { printf("error: call to 'clCreateKernel' failed\n"); exit(1); } /* Create and allocate host buffers */ size_t num_elem = 10; /* Create and init host side src buffer 0 */ cl_float8 *src_0_host_buffer; src_0_host_buffer = malloc(num_elem * sizeof(cl_float8)); for (int i = 0; i < num_elem; i++) src_0_host_buffer[i] = (cl_float8){{2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0}}; /* Create and init device side src buffer 0 */ cl_mem src_0_device_buffer; src_0_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_float8), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create source buffer\n"); exit(1); } ret = clEnqueueWriteBuffer(command_queue, src_0_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_float8), src_0_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueWriteBuffer' failed\n"); exit(1); } /* Create and init host side src buffer 1 */ cl_float8 *src_1_host_buffer; src_1_host_buffer = malloc(num_elem * sizeof(cl_float8)); for (int i = 0; i < num_elem; i++) src_1_host_buffer[i] = (cl_float8){{2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0}}; /* Create and init device side src buffer 1 */ cl_mem src_1_device_buffer; src_1_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_float8), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create source buffer\n"); exit(1); } ret = clEnqueueWriteBuffer(command_queue, src_1_device_buffer, CL_TRUE, 0, num_elem * sizeof(cl_float8), src_1_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueWriteBuffer' failed\n"); exit(1); } /* Create host dst buffer */ cl_int8 *dst_host_buffer; dst_host_buffer = malloc(num_elem * sizeof(cl_int8)); memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_int8)); /* Create device dst buffer */ cl_mem dst_device_buffer; dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_int8), NULL, &ret); if (ret != CL_SUCCESS) { printf("error: could not create dst buffer\n"); exit(1); } /* Set kernel arguments */ ret = CL_SUCCESS; ret |= clSetKernelArg(kernel, 0, sizeof(cl_mem), &src_0_device_buffer); ret |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &src_1_device_buffer); ret |= clSetKernelArg(kernel, 2, sizeof(cl_mem), &dst_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clSetKernelArg' failed\n"); exit(1); } /* Launch the kernel */ size_t global_work_size = num_elem; size_t local_work_size = num_elem; ret = clEnqueueNDRangeKernel(command_queue, kernel, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueNDRangeKernel' failed\n"); exit(1); } /* Wait for it to finish */ clFinish(command_queue); /* Read results from GPU */ ret = clEnqueueReadBuffer(command_queue, dst_device_buffer, CL_TRUE,0, num_elem * sizeof(cl_int8), dst_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueReadBuffer' failed\n"); exit(1); } /* Dump dst buffer to file */ char dump_file[100]; sprintf((char *)&dump_file, "%s.result", argv[0]); write_buffer(dump_file, (const char *)dst_host_buffer, num_elem * sizeof(cl_int8)); printf("Result dumped to %s\n", dump_file); /* Free host dst buffer */ free(dst_host_buffer); /* Free device dst buffer */ ret = clReleaseMemObject(dst_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Free host side src buffer 0 */ free(src_0_host_buffer); /* Free device side src buffer 0 */ ret = clReleaseMemObject(src_0_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Free host side src buffer 1 */ free(src_1_host_buffer); /* Free device side src buffer 1 */ ret = clReleaseMemObject(src_1_device_buffer); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseMemObject' failed\n"); exit(1); } /* Release kernel */ ret = clReleaseKernel(kernel); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseKernel' failed\n"); exit(1); } /* Release program */ ret = clReleaseProgram(program); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseProgram' failed\n"); exit(1); } /* Release command queue */ ret = clReleaseCommandQueue(command_queue); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseCommandQueue' failed\n"); exit(1); } /* Release context */ ret = clReleaseContext(context); if (ret != CL_SUCCESS) { printf("error: call to 'clReleaseContext' failed\n"); exit(1); } return 0; }
the_stack_data/218894004.c
/* Autor: jorgeaah Compilador: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Compilado: gcc NewtonRaphson.c -lm Fecha: lun 03 may 2021 10:31:55 CST Librerias: stdio, stdlib, math Resumen: Programa que utiliza el metodo de la biseccion para encontrar la raíz de una ecuación dado un rango determinado. Entrada: Salida: */ //Librerias #include <stdio.h> #include <stdlib.h> #include <math.h> float ecuacion(float x); float biseccion(float x_inf, float x_sup, float error); int main() { float raiz = biseccion (0.0F, 100.0F, 0.001F); printf("La raiz de la ecuacion ingresada es %f con error de menos de una milésima. \n", raiz); //Escribiendo el script para gnuplot FILE *fp = fopen("NewtonRaphson", "w+"); fprintf(fp, "set terminal wxt \n"); fprintf(fp, "set title \"Raíz por el método de bisección\" \n"); fprintf(fp, "set xlabel \"x\" \n"); fprintf(fp, "set xrange [0: 10] \n"); fprintf(fp, "set ylabel \"y\" \n"); fprintf(fp, "set yrange [-1: 2] \n"); fprintf(fp, "ecuacion(x) = sqrt(x*0.5)-1 \n"); fprintf(fp, "set object circle at first %f,0 radius char 0.1 fillstyle empty border lc rgb \"#aa1100\" lw 2 \n", raiz); fprintf(fp, "plot ecuacion(x) with lines title \"sqrt(x/2)-1\" \n"); fclose(fp); //Llamando a gnuplot system("gnuplot --persist NewtonRaphson"); return 0; } float ecuacion(float x) { return (float) sqrt((double) x*0.5F)-1.0F; } float biseccion(float x_inf, float x_sup, float error) { float y_inf = ecuacion(x_inf); float y_sup = ecuacion(x_sup); while(1) { float x_med = 0.5F*(x_inf + x_sup); float y_med = ecuacion(x_med); if ((y_inf*y_med) > 0) { x_inf = x_med; y_inf = ecuacion(x_inf); } else { x_sup = x_med; y_sup = ecuacion(x_sup); } if ((x_sup-x_inf) < error) { return 0.5F*(x_sup+x_inf); } } }
the_stack_data/179831355.c
// from john regehr struct s { int *p1, *p2; }; int main(void) { struct s a; struct s *b = malloc(sizeof(struct s)); a.p1 = &b->p2; a.p2 = &b->p1; b->p1 = &a.p2; b->p2 = &a.p1; return 0; }
the_stack_data/75210.c
#include <ctype.h> #include <strings.h> #include <stdlib.h> #include <stdio.h> int main(int argc, char **argv) { int i; int j; int ret; if (argc == 3) { i = atoi(argv[1]); j = -9; while (j < 255) { ret = isspace(j); if (j % 10 == 0) printf("%d ", ret); else printf("%d", ret); j++; } } return (0); }
the_stack_data/52556.c
/* ヘッダファイルのインクルード */ #include <stdio.h> /* 標準入出力 */ #include <string.h> /* 文字列処理 */ /* main関数の定義 */ int main(void){ /* 配列の宣言 */ char str1[] = "ABCDE"; /* コピー元char型配列str1は"ABCDE"に初期化. */ char str2[256]; /* コピー先char型配列str2. */ /* str2は空文字列("")にする. */ str2[0] = '\0'; /* str2の先頭にNULL文字を入れることで空文字列("")にする. */ /* str1, str2の出力.(strcpy前) */ printf("str1: %s\n", str1); /* str1を出力.("ABCDE") */ printf("str2: %s\n", str2); /* str2を出力.("") */ /* 1行空ける. */ printf("\n"); /* printfで"\n"を出力することで1行空ける. */ /* str1の文字列をstr2にコピー. */ strcpy(str2, str1); /* strcpyでstr1の文字列をstr2にコピー. */ /* str1, str2の出力.(strcpy後) */ printf("str1: %s\n", str1); /* str1を出力.("ABCDE") */ printf("str2: %s\n", str2); /* str2を出力.(コピーされたので"ABCDE") */ /* プログラムの終了 */ return 0; }
the_stack_data/6388901.c
/* PR target/56228 */ /* { dg-do assemble } */ /* { dg-options "-O2" } */ /* { dg-skip-if "accessing program memory with data memory address" { "avr-*-*" } { "*" } { "" } } */ short a[14] = { 1, 2 }; short b[15] = { 3, 4 }; int foo () { void (*fna) (void) = (void (*) (void)) a; void (*fnb) (void) = (void (*) (void)) b; fna (); fnb (); return a[1] == b[1]; }
the_stack_data/57950347.c
// arrays_pointers.c // Chapter 14 // <book title> // // Demonstrate how to // 1) an array name is interchangeable with a pointer to the same address // 2) get info about the pointers and their values // 3) traverse the array using 3 methods: // a) using array notation incrementing index; // b) using pointer plus offset (pointer doesn't change); and // c) using incremented pointer (pointer changes). // // compile with: cc arrays_pointers.c -o arrays_pointers -Wall -Werror -std=c11 // #include <stdio.h> int main(int argc, char *argv[]) { const int arraySize = 5; int array[5] = { 1 , 2 , 3 , 4 , 5 }; int* pArray1 = array; int* pArray2 = &(array[0]); printf("Pointer values (addresses) from initial assignments:\n\n"); printf( " address of array = %#lx, value at array = %d\n" , (unsigned long)array , *array ); printf( " address of &array[0] = %#lx, value at array[0] = %d\n" , (unsigned long)&array[0] , array[0] ); printf( " address of pArray1 = %#lx, value at pArray1 = %#lx\n" , (unsigned long)&pArray1 , (unsigned long) pArray1 ); printf( " address of pArray2 = %#lx, value at pArray2 = %#lx\n\n" , (unsigned long)&pArray2 , (unsigned long) pArray2 ); printf("\n(1) Array values using array notation (index is incremented):\n\n"); for( int i = 0; i < arraySize ; i++ ) printf( " &(array[%1d]) = %#lx, array[%1d] = %1d, i++\n", i , (unsigned long)&(array[i]), i , array[i] ); printf("\n(2) Array values using a pointer addition (offset is incremented):\n\n"); for( int i = 0 ; i < arraySize; i++ ) printf( " pArray2+%1d = %#lx, *(pArray2+%1d) = %1d, i++\n", i , (unsigned long)(pArray2+i) , i , *(pArray2+i) ); printf("\n(3) Array values using pointer referencing (pointer is incremented):\n\n"); for( int i = 0 ; i < arraySize ; i++ , pArray1++ ) printf( " pArray1 = %#lx, *pArray1 = %1d, pArray1++\n", (unsigned long)pArray1 , *pArray1 ); } /* eof */
the_stack_data/2268.c
/* * POK header * * The following file is a part of the POK project. Any modification should * made according to the POK licence. You CANNOT use this file or a part of * this file is this part of a file for your own project * * For more information on the POK licence, please see our LICENCE FILE * * Please follow the coding guidelines described in doc/CODING_GUIDELINES * * Copyright (c) 2007-2009 POK team * * Created by julien on Thu Jan 15 23:34:13 2009 */ #if defined (POK_NEEDS_DEBUG) || defined (POK_NEEDS_PORTS_QUEUEING) || defined (POK_NEEDS_PORTS_SAMPLING) || defined(POK_NEEDS_PORTS_VIRTUAL) #include <libc.h> __attribute__ ((weak)) int strcmp (const char *s1, const char *s2) { unsigned int i; for (i = 0; ; i++) { if (s1[i] == '\0' && s2[i] == '\0') { return 0; } if (s1[i] < s2[i]) { return -1; } if (s1[i] > s2[i]) { return 1; } } } __attribute__ ((weak)) int strncmp (const char *s1, const char *s2, size_t size) { unsigned int i; for (i = 0; i < size; i++) { if (s1[i] == '\0' && s2[i] == '\0') { return 0; } if (s1[i] < s2[i]) { return -1; } if (s1[i] > s2[i]) { return 1; } } return 0; } #endif
the_stack_data/70450640.c
#include <stdlib.h> #include <stdio.h> #include <math.h> #define UNLIMIT #define MAXARRAY 10000 /* this number, if too large, will cause a seg. fault!! */ struct my3DVertexStruct { int x, y, z; double distance; }; int compare(const void *elem1, const void *elem2) { /* D = [(x1 - x2)^2 + (y1 - y2)^2 + (z1 - z2)^2]^(1/2) */ /* sort based on distances from the origin... */ double distance1, distance2; distance1 = (*((struct my3DVertexStruct *)elem1)).distance; distance2 = (*((struct my3DVertexStruct *)elem2)).distance; return (distance1 > distance2) ? 1 : ((distance1 == distance2) ? 0 : -1); } int main(int argc, char *argv[]) { struct my3DVertexStruct array[MAXARRAY]; FILE *fp; int i,count=0; int x, y, z; if (argc<2) { fprintf(stderr,"Usage: qsort_large <file>\n"); exit(-1); } else { fp = fopen(argv[1],"r"); while((fscanf(fp, "%d", &x) == 1) && (fscanf(fp, "%d", &y) == 1) && (fscanf(fp, "%d", &z) == 1) && (count < MAXARRAY)) { array[count].x = x; array[count].y = y; array[count].z = z; array[count].distance = sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2)); count++; } } printf("\nSorting %d vectors based on distance from the origin.\n\n",count); qsort(array,count,sizeof(struct my3DVertexStruct),compare); for(i=0;i<count;i++) printf("%d %d %d\n", array[i].x, array[i].y, array[i].z); return 0; }
the_stack_data/54825637.c
static inline int fun(int a) { if (a) return 1; } static int foo(int a) { return fun(a); } /* * check-name: missing-return1 * check-command: sparse -vir -flinearize=last $file */
the_stack_data/880402.c
#include<stdio.h> /*type def struct myclass { int data; struct myclass* link; }mc; mc *Head=NULL; void create(int num){ mc *Temp=NULL; Temp=(void *)malloc(sizeof((mc)); }*/ void main() { }
the_stack_data/755228.c
extern void PUT32 (unsigned int address, unsigned int value); extern unsigned int GET32 (unsigned int address); #define GPIO1_BASE 0x4804C000 #define GPIO_SYSCONFIG 0x10 #define GPIO_SYSSTATUS 0x114 #define GPIO_OE 0x134 #define GPIO_CLRDATAOUT 0x190 #define GPIO_SETDATAOUT 0x194 #define CM_PER_BASE 0x44e00000 #define CM_PER_GPIO1 0xAC #define TIME 50000000 void _main (void) { volatile unsigned int ra; PUT32(CM_PER_BASE + CM_PER_GPIO1, 1 << 18 | 2); ra = GET32(GPIO1_BASE + GPIO_OE); ra &= ~(15 << 21); PUT32(GPIO1_BASE + GPIO_OE, ra); for (;;) { PUT32(GPIO1_BASE + GPIO_SETDATAOUT, (15 << 21)); for (ra = 0; ra < TIME; ra ++); PUT32(GPIO1_BASE + GPIO_CLRDATAOUT, 15 << 21); for (ra = 0; ra < TIME; ra ++); } return; } /* The MIT License (MIT) Copyright (c) 2015 Alexis Marquet Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
the_stack_data/193892563.c
#include <stdio.h> #include <stdlib.h> #include <string.h> // Just a guess #define MAX_LENGTH 1000000 #define ITERATIONS 40 #define MAX_LENGTH2 10000000 #define ITERATIONS2 50 int part1(FILE *in); int part2(FILE *in); int iterate(int *data); int iterate2(int *data); int main() { FILE *in = fopen("in10", "r"); printf("Part1: %d\n", part1(in)); rewind(in); printf("Part2: %d\n", part2(in)); fclose(in); return 0; } int part1(FILE *in) { char line[MAX_LENGTH] = {0}; int res[MAX_LENGTH] = {0}; int resCount = 0; fgets(line, MAX_LENGTH, in); *strchr(line, '\n') = '\0'; for (int i = 0; i < strlen(line); i++) res[i] = line[i] - '0'; for (int i = 0; i < ITERATIONS; i++) resCount = iterate(res); return resCount; } int part2(FILE *in) { char *line = malloc(MAX_LENGTH * sizeof(*line)); int *res = calloc(MAX_LENGTH2, sizeof(*res)); int resCount = 0; fgets(line, MAX_LENGTH, in); *strchr(line, '\n') = '\0'; for (int i = 0; i < strlen(line); i++) res[i] = line[i] - '0'; free(line); for (int i = 0; i < ITERATIONS2; i++) resCount = iterate2(res); free(res); return resCount; } int iterate(int *data) { int *buff = calloc(MAX_LENGTH, sizeof(*buff)); int current = 0; int currentCount = 0; int buffI = 0; for (int i = 0; data[i] != 0; i++) { if (current != data[i]) { if (currentCount != 0) { buff[buffI++] = currentCount; buff[buffI++] = current; } current = data[i]; currentCount = 1; } else currentCount++; } if (currentCount != 0) { buff[buffI++] = currentCount; buff[buffI++] = current; //printf("-> %dx%d (%d)\n", currentCount, current, buffI); } memcpy(data, buff, MAX_LENGTH * sizeof(*buff)); free(buff); return buffI; } int iterate2(int *data) { int *buff = calloc(MAX_LENGTH2, sizeof(*buff)); int current = 0; int currentCount = 0; int buffI = 0; for (int i = 0; data[i] != 0; i++) { if (current != data[i]) { if (currentCount != 0) { buff[buffI++] = currentCount; buff[buffI++] = current; } current = data[i]; currentCount = 1; } else currentCount++; } if (currentCount != 0) { buff[buffI++] = currentCount; buff[buffI++] = current; //printf("-> %dx%d (%d)\n", currentCount, current, buffI); } memcpy(data, buff, MAX_LENGTH2 * sizeof(*buff)); free(buff); return buffI; }
the_stack_data/153556.c
// Euclidean Algorithm #include <stdio.h> // C function for extended Euclidean Algorithm int gcdExtended(int a, int b, int *x, int *y) { // Base Case if (a == 0) { *x = 0; *y = 1; return b; } int x1, y1; // To store results of recursive call int gcd = gcdExtended(b%a, a, &x1, &y1); // Update x and y using results of recursive // call *x = y1 - (b/a) * x1; *y = x1; return gcd; } // Driver Program int main() { int x, y; int a = 35, b = 15; int g = gcdExtended(a, b, &x, &y); printf("gcd(%d, %d) = %d", a, b, g); return 0; }
the_stack_data/1075932.c
#include <stdio.h> void main (void) { // Setup the variables float a; float b = 3.641; int c; // Initialize a a = 2.897; // Add a and b c = a + b; // Output the results to the user printf ("The sum of adding %f and %f is %d\n", a, b, c); }
the_stack_data/45223.c
int main(const int argc, const char ** argv) { return 0; }
the_stack_data/62565.c
/* { dg-do compile { target { powerpc*-*-* } } } */ /* { dg-require-effective-target lp64 } */ /* { dg-options "-O -mno-popcntb" } */ /* { dg-final { scan-assembler-not "stwbrx" } } */ void write_reverse (unsigned long *addr, unsigned long val) { unsigned long reverse = __builtin_bswap64 (val); __atomic_store_n (addr, reverse, __ATOMIC_RELAXED); }
the_stack_data/122016021.c
#include <stdio.h> #include <unistd.h> #include <sys/types.h> int main ( ) { int id, ret; ret = fork(); ret = fork(); id = getpid(); printf("\n My identifier is ID = [%d]\n", id); while(1) ; return 0; }
the_stack_data/115765403.c
/* dmc - dynamic mail client * See LICENSE file for copyright and license details. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> static const char cb64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq"; static void b64_encode(unsigned char in[3], unsigned char out[4], int len) { out[0] = cb64[ in[0] >> 2 ]; out[1] = cb64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ]; out[2] = (len > 1 ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] : '='); out[3] = (len > 2 ? cb64[ in[2] & 0x3f ] : '='); } static int b64_decode(unsigned char in[4], unsigned char out[3]) { unsigned char len = 3, i, v[4]; for(i=0;i<4;i++) { if (in[i]<43||in[i]>122) return -1; v[i] = cd64[in[i]-43]; if (v[i]!='$') v[i]-=62; else { len = i-1; break; } } out[0] = v[0] << 2 | v[1] >> 4; out[1] = v[1] << 4 | v[2] >> 2; out[2] = ((v[2] << 6) & 0xc0) | v[3]; return len; } static void mime_pack(char **files, int nfiles) { FILE *fd = NULL; char b[1024], cmd[1024], *ptr = NULL, *ptr2 = NULL; unsigned char bd[1024]; int header = 1, len, in, out, i; memset (b, '\0', 1024); while(fgets (b, 1023, stdin)) { if (header && b[0] == '\n') { printf ("Content-Type: multipart/mixed; boundary=\"dmc-multipart\"\n\n" "--dmc-multipart\n" "Content-Type: text/plain\n"); header = 0; } fputs (b, stdout); } for(i = 0; i < nfiles; i++) { snprintf (cmd, 1023, "file -iL \"%s\"", files[i]); if (!(fd=popen (cmd, "r"))) continue; fgets (b, 1023, fd); pclose (fd); if (!(ptr = strchr(b, ' '))) continue; if (!(fd=fopen(files[i], "r"))) continue; if ((ptr2 = strrchr(files[i], '/'))) ptr2++; else ptr2 = files[i]; puts ("--dmc-multipart"); printf ("Content-Type: %s", ptr+1); printf ("Content-Disposition: attachment; filename=\"%s\"\n", ptr2); if (strstr (ptr, "text")) { printf("Content-Transfer-Encoding: quoted-printable\n\n"); while (fgets(b, 1023, fd)) printf("%s", b); } else { puts ("Content-Transfer-Encoding: base64\n"); while ((len=fread(b, 1, 57, fd))) { memset(bd,'\0',1024); for(in=out=0;in<len;in+=3,out+=4) b64_encode((unsigned char*)b+in,bd+out,len-in>3?3:len-in); puts ((char *)bd); } } fclose (fd); } puts ("--dmc-multipart--"); } static void mime_unpack (int xtr) { FILE *fd = NULL; char b[1024], boundary[1024], encoding[1024], filename[1024], *ptr, *ptr2; unsigned char bd[1024]; int entity = 0, dump = 0, empty = 0, len, in, out, i, n = 0; boundary[0] = encoding[0] = filename[0] = '\0'; memset (b, '\0', 1024); while (fgets(b, 1023, stdin)) { if (!memcmp(b, "--", 2)) { if (boundary[0] && strstr(b, boundary) && !memcmp(b+strlen(b)-3, "--", 2)) { entity = dump = empty = 0; } else { strncpy(boundary, b+2, 1023); if ((len = strlen(boundary)) > 0) boundary[len-1] = '\0'; if (fgets(b, 1023, stdin) && strstr(b, "Content-Type:")) { entity = 1; dump = empty = 0; } } } if (entity) { if ((ptr = strstr(b, "Content-Transfer-Encoding:"))) { strncpy(encoding, ptr+26, 1023); } else if ((ptr = strstr(b, "filename=")) && ((ptr2 = strchr(ptr, '"')) || (ptr2 = strchr(ptr, '=')))) { strncpy(filename, ptr2+1, 1023); if ((ptr = strchr(filename, '"')) || (ptr = strchr(filename, ' ')) || (ptr = strchr(filename, '\n'))) ptr[0] = '\0'; puts (filename); } else if (strstr(b, "boundary=")) { empty = 1; } else if (b[0] == '\n') { if (!empty && !filename[0]) snprintf(filename, 1023, "mimepart-%i", n++); if (xtr && !dump && filename[0] && (fd = fopen(filename, "w"))) { dump = 1; continue; } else if (dump && strstr(encoding, "base64")) dump = 0; } } else boundary[0] = '\0'; if (dump) { if (strstr(encoding, "base64")) { memset(bd,'\0',1024); if ((len = strlen(b)) > 0) b[len-1] = '\0'; for(in=out=0;in<len-1;in+=4) out+=b64_decode((unsigned char*)b+in,bd+out); for(i=0;i<out;i++) fputc(bd[i], fd); } else fputs(b, fd); } else if (fd) { fclose(fd); fd = NULL; encoding[0] = filename[0] = '\0'; } } } int main(int argc, char **argv) { if (argc < 2 || !strcmp(argv[1], "-h")) { fprintf (stderr, "Usage: %s [-hlu | attachment1 attachment2...] < mail\n", argv[0]); return 1; } else if (!strcmp(argv[1], "-l")) mime_unpack (0); else if (!strcmp(argv[1], "-u")) mime_unpack (1); else mime_pack(argv+1, argc-1); return 0; }
the_stack_data/64199825.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #define SHORT_INPUT "d10_short_input" #define INPUT "d10_input" void reset_stack(); char obracks[4] = {'(', '[', '{', '<'}; char cbracks[4] = {')', ']', '}', '>'}; int points [4] = {3, 57, 1197, 25137}; char *stack; char *sp; void push(char c); char pop(); int main(int ac) { int input = ac > 1; FILE *fp = fopen(input ? INPUT : SHORT_INPUT, "r"); if (fp == NULL) { printf("cant read file\n"); return 1; } reset_stack(); // go through all lines int score = 0, corrupted; char line[200]; while (fgets(line, 200, fp) != NULL) { corrupted = 0; // go through all chars in line int i = 0; while (!corrupted) { char c = line[i]; if (c == '\n') break; for (int i = 0; i < 4 && !corrupted; i++) { if (c == obracks[i]) push(c); if (c == cbracks[i]) { char o = pop(); if (o != obracks[i]) { corrupted = 1; score += points[i]; } } } i++; } reset_stack(); } printf(" score = %i\n", score); return 0; } void push(char c) { sp++; *sp = c; } char pop() { char c = *sp; sp--; return c; } void reset_stack() { if (stack != NULL) free(stack); stack = malloc(200 * sizeof(char)); stack[0] = 'E'; sp = stack + 1; }
the_stack_data/51700964.c
int main() { int i; int p; p = 10; i = 5; if (i==5){ int i; int p; { int i; } //return p; } return i + p; }
the_stack_data/82023.c
#include <stdio.h> double sum(double a, double b); int main(void) { printf("%.2lf\n", sum(3, 5)); return 0; } double sum(double a, double b) { return a+b; }
the_stack_data/100141083.c
/* * Software License Agreement (BSD License) * * Copyright (c) 2010, Roel Verdult * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the copyright holders 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 ''AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #include <stdio.h> #include <stdint.h> #define BLOCK_COUNT 7 #define BLOCK_LENGTH 4 #define BLOCK_TOTAL (BLOCK_COUNT*BLOCK_LENGTH) typedef unsigned char byte_t; int main(int argc, char *argv[]) { FILE* pf; byte_t buf[BLOCK_TOTAL]; uint32_t crc = 0; uint32_t block; // Check for required arguments if (argc < 2) { printf("syntax: checksum <firmware.bin>\n"); return 1; } // Try to open the supplied firmware if ((pf = fopen(argv[1],"rb+")) == NULL) { printf("error: could not open file [%s] with write access\n",argv[1]); return 1; } // Read out the data blocks used for crc calculation if (fread(buf,1,BLOCK_TOTAL,pf) != BLOCK_TOTAL) { printf("error: could not read required bytes\n"); fclose(pf); return 1; } // Compute the crc value for (block=0; block<BLOCK_COUNT; block++) { crc += *((uint32_t*)(buf+(block*BLOCK_LENGTH))); } crc = (~crc) + 1; // Reposition the file stream indicator to switch between read and write if (fseek(pf,0,SEEK_CUR) != 0) { printf("error: could not switch from read to write mode\n"); fclose(pf); return 1; } // Write the crc back to the file if (fwrite((byte_t*)&crc,1,BLOCK_LENGTH,pf) != BLOCK_LENGTH) { printf("error: could not write crc back to file\n"); fclose(pf); return 1; } printf("succesfully updated crc to: %08x\n",crc); fclose(pf); return 0; }
the_stack_data/60836.c
// Assignment: Homework #2 (Lexical Analyzer) // Students: Nicole Freites & Shivani Kumar #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #define MAX_CODE_LENGTH 500 // Holds all the values for the tokens. typedef enum { nulsym = 1, identsym, numbersym, plussym, minussym, multsym, slashsym, oddsym, eqlsym, neqsym, lessym, leqsym, gtrsym, geqsym, lparentsym, rparentsym, commasym, semicolonsym, periodsym, becomessym, lbracesym, rbracesym, ifsym, thensym, whilesym, dosym, callsym, constsym, varsym, procsym, writesym, readsym, elsesym } token_type; // Struct to keep track of tokens when printing lexeme list. typedef struct lexeme_list { int token; char identifier[11]; int digit; }lexeme_list; int main() { // An array that holds tokens for the lexeme list. lexeme_list *lexemeArray = calloc(MAX_CODE_LENGTH, sizeof(lexeme_list)); // String array that holds the reserved words. If a string matches any of the words when being compared, it is a reserved word. const char reserved_words[13][11] = {"const", "var", "procedure", "call", "if", "then", "else", "while", "do", "read", "write", "odd", "NULL"}; // Char array to hold all of the characters in the input file. char *charInputArr = calloc(MAX_CODE_LENGTH, sizeof(char)); // Initializes buffer array to temporarily hold characters when reading through the file. Also, sets buffer to empty. char buffer[11]; buffer[0] = '\0'; printf("Source Program:\n"); int charArr_index = 0; // Reads through input file until it reaches the end of the file. while(!feof(stdin)) { // Takes in character from input file and places it in char array. Prints it after. charInputArr[charArr_index] = getchar(); if(charInputArr[charArr_index] == EOF) break; printf("%c", charInputArr[charArr_index]); charArr_index++; } //Resets and initializes ints to keep track of indexes for the arrays. charArr_index = 0; int buff_index = 0; int ll_index = 0; printf("\n\nLexeme Table:\n"); printf("lexeme\t\t\ttoken type\n"); // Checks each character in character array until it reaches end-of-file to assign them tokens. while(charInputArr[charArr_index] != EOF) { // Resets index and array, as a precaution. buff_index = 0; buffer[0] = '\0'; // Determines if current character is a space. if(isspace(charInputArr[charArr_index]) != 0) { charArr_index++; continue; } // Checks if current char is an letter. else if((isalpha(charInputArr[charArr_index]) != 0) && (isspace(charInputArr[charArr_index]) == 0)) { buff_index = 0; // Runs loop until it detects that the current char is not a letter or a digit. while((isalpha(charInputArr[charArr_index]) != 0 || isdigit(charInputArr[charArr_index]) != 0) && isspace(charInputArr[charArr_index]) == 0) { // Makes sure identifier is not over 11 letters. if(buff_index < 11) { buffer[buff_index] = charInputArr[charArr_index]; charArr_index++; buff_index++; } // If it's over 11 letters, there is an error that the identifier name is too long. // Prints error message and stops the program. else { printf("Name too long.\n"); return 0; } } // Adds null terminator to end of characters to signal the length of the identifier in the buffer array. buffer[buff_index] = '\0'; // Checks if the identifier in buffer is a reserved word. for(int check = 0; check <= 12; check++) { // If it matches one of the reserved words, it will print the reserved word and its token. if((strcmp(buffer, reserved_words[check]) == 0) && buffer[0] != '\0') { switch(check) { // const case 0: lexemeArray[ll_index].token = constsym; ll_index++; printf("const\t\t\t%d\n", constsym); buffer[0] = '\0'; break; // var case 1: lexemeArray[ll_index].token = varsym; ll_index++; printf("var\t\t\t\t%d\n", varsym); buffer[0] = '\0'; break; // procedure case 2: lexemeArray[ll_index].token = procsym; ll_index++; printf("procedure\t\t%d\n", procsym); buffer[0] = '\0'; break; // call case 3: lexemeArray[ll_index].token = callsym; ll_index++; printf("call\t\t\t%d\n", callsym); buffer[0] = '\0'; break; // if case 4: lexemeArray[ll_index].token = ifsym; ll_index++; printf("if\t\t\t\t%d\n", ifsym); buffer[0] = '\0'; break; // then case 5: lexemeArray[ll_index].token = thensym; ll_index++; printf("then\t\t\t%d\n", thensym); buffer[0] = '\0'; break; // else case 6: lexemeArray[ll_index].token = elsesym; ll_index++; printf("else\t\t\t%d\n", elsesym); buffer[0] = '\0'; break; // while case 7: lexemeArray[ll_index].token = whilesym; ll_index++; printf("while\t\t\t%d\n", whilesym); buffer[0] = '\0'; break; // do case 8: lexemeArray[ll_index].token = dosym; ll_index++; printf("do\t\t\t\t%d\n", dosym); buffer[0] = '\0'; break; // read case 9: lexemeArray[ll_index].token = readsym; ll_index++; printf("read\t\t\t\t%d\n", readsym); buffer[0] = '\0'; break; // write case 10: lexemeArray[ll_index].token = writesym; ll_index++; printf("write\t\t\t\t%d\n", writesym); buffer[0] = '\0'; break; // odd case 11: lexemeArray[ll_index].token = oddsym; ll_index++; printf("odd\t\t\t\t%d\n", oddsym); buffer[0] = '\0'; break; // null case 12: lexemeArray[ll_index].token = nulsym; ll_index++; printf("NULL\t\t\t\t%d\n", nulsym); buffer[0] = '\0'; break; } } // If the identifier in buffer is not a reserved word, it is an identifier. else if(check == 12 && (strcmp(buffer, reserved_words[check]) != 0) && buffer[0] != '\0') { lexemeArray[ll_index].token = identsym; int index = 0; // Places identifier in lexeme list to print later. while(buffer[index] != '\0') { lexemeArray[ll_index].identifier[index] = buffer[index]; index++; } ll_index++; printf("%s\t\t\t\t%d\n", buffer, identsym); buffer[0] = '\0'; } } continue; } // Determines if the character is a digit. else if(isdigit(charInputArr[charArr_index]) != 0 && isspace(charInputArr[charArr_index]) == 0) { // Characters get checked until a non-digit or space is reached. while(isdigit(charInputArr[charArr_index]) != 0 && isspace(charInputArr[charArr_index]) == 0) { // If an identifier starts with a digit, an error will occur. if(isalpha(charInputArr[charArr_index]) != 0) { printf("Variable does not start with letter.\n"); return 0; } // Makes sure the digit is at most 5 digits in length. else if(buff_index < 5) { buffer[buff_index] = charInputArr[charArr_index]; charArr_index++; buff_index++; } // If the number passes 5 digits, an error will occur. else { printf("Number too long.\n"); return 0; } } buffer[buff_index] = '\0'; // Makes sure string is not empty before setting token. if(buffer[0] != '\0') { // Sets token to numbersym. lexemeArray[ll_index].token = numbersym; // Goes through each digit in buffer and places the digit in the lexeme list placeholder. int index = 0; lexemeArray[ll_index].digit = atoi(buffer); ll_index++; printf("%s\t\t\t\t%d\n", buffer, numbersym); buffer[0] = '\0'; } } // Determines if character is a symbol: if it's not a letter, digit, or space, it's a symbol. else if((isalpha(charInputArr[charArr_index]) == 0) && (isdigit(charInputArr[charArr_index]) == 0) && (isspace(charInputArr[charArr_index]) == 0)) { // Goes through all the possibilities of symbols that may be encountered in an input. switch(charInputArr[charArr_index]) { // plus case '+': printf("+\t\t\t\t%d\n", plussym); lexemeArray[ll_index].token = plussym; ll_index++; charArr_index++; break; // minus case '-': printf("-\t\t\t\t%d\n", minussym); lexemeArray[ll_index].token = minussym; ll_index++; charArr_index++; break; // multiplication case '*': printf("*\t\t\t\t%d\n", multsym); lexemeArray[ll_index].token = multsym; ll_index++; charArr_index++; break; // slash case '/': charArr_index++; // Checks if the next symbol is a *. // If so, it is a comment and will loop through the char array until it finds the end of the comment */. if(charInputArr[charArr_index] == '*') { while(charInputArr[charArr_index] != EOF) { charArr_index++; if(charInputArr[charArr_index] == '*') { charArr_index++; if(charInputArr[charArr_index] == '/') { charArr_index++; break; } else continue; } } } // If it is not a comment, it is just a slash symbol. else { printf("/\t\t\t\t%d\n", slashsym); lexemeArray[ll_index].token = slashsym; ll_index++; } break; // left parenthesis case '(': printf("(\t\t\t\t%d\n", lparentsym); lexemeArray[ll_index].token = lparentsym; ll_index++; charArr_index++; break; // right parenthesis case ')': printf(")\t\t\t\t%d\n", rparentsym); lexemeArray[ll_index].token = rparentsym; ll_index++; charArr_index++; break; // equal case '=': printf("=\t\t\t\t%d\n", eqlsym); lexemeArray[ll_index].token = eqlsym; ll_index++; charArr_index++; break; // comma case ',': printf(",\t\t\t\t%d\n", commasym); lexemeArray[ll_index].token = commasym; ll_index++; charArr_index++; break; // period case '.': printf(".\t\t\t\t%d\n", periodsym); lexemeArray[ll_index].token = periodsym; ll_index++; charArr_index++; break; // less than case '<': charArr_index++; // Checks to see if the next character makes it a leqsym if(charInputArr[charArr_index] == '=') { printf("<=\t\t\t\t%d\n", leqsym); lexemeArray[ll_index].token = leqsym; ll_index++; charArr_index++; } // Checks to see if the next character makes it a neqsym else if(charInputArr[charArr_index] == '>') { printf("<>\t\t\t\t%d\n", neqsym); lexemeArray[ll_index].token = neqsym; ll_index++; charArr_index++; } // If not, it is just the less than symbol. else { printf("<\t\t\t\t%d\n", lessym); lexemeArray[ll_index].token = lessym; ll_index++; } break; // greater than case '>': charArr_index++; // Checks to see if the next character will make it a geqsym. if(charInputArr[charArr_index] == '=') { printf(">=\t\t\t\t%d\n", geqsym); lexemeArray[ll_index].token = geqsym; ll_index++; charArr_index++; } // If not, it is just a greater than symbol. else { printf(">\t\t\t\t%d\n", gtrsym); lexemeArray[ll_index].token = gtrsym; ll_index++; } break; // semicolon case ';': printf(";\t\t\t\t%d\n", semicolonsym); lexemeArray[ll_index].token = semicolonsym; ll_index++; charArr_index++; break; // colon case ':': charArr_index++; // Checks the next character to see if it makes it a becomessym. if(charInputArr[charArr_index] == '=') { printf(":=\t\t\t\t%d\n", becomessym); lexemeArray[ll_index].token = becomessym; ll_index++; charArr_index++; } // If not, the symbol is invalid and throws an error. else { printf("Invalid symbols.\n"); return 0; } break; // left brace case '{': printf("{\t\t\t\t%d\n", lbracesym); lexemeArray[ll_index].token = lbracesym; ll_index++; charArr_index++; break; // right brace case '}': printf("}\t\t\t\t%d\n", rbracesym); lexemeArray[ll_index].token = rbracesym; ll_index++; charArr_index++; break; // not case '!': charArr_index++; // Checks to see if the next character makes it a neqsym. if(charInputArr[charArr_index] == '=') { printf("!=\t\t\t\t%d\n", neqsym); lexemeArray[ll_index].token = neqsym; ll_index++; charArr_index++; } // If not, the symbol is invalid and throws an error. else { printf("Invalid symbols.\n"); return 0; } break; // If it is not any of the special symbols provided, it is an invalid symbol. default: printf("Invalid symbols.\n"); break; } } continue; } printf("Lexeme List:\n"); int count = 0; lexemeArray[ll_index].token = '\0'; // Until count does not reach the terminator, it will print all of the corresponding tokens in the lexeme list array. while(lexemeArray[count].token != '\0') { // If the token is an identifier, it will print the corresponding identifier in the list. if(lexemeArray[count].token == identsym) printf("%d %s ", lexemeArray[count].token, lexemeArray[count].identifier); // If the token is a digit, it will print the corresponding digit in the list. else if(lexemeArray[count].token == numbersym) printf("%d %d ", lexemeArray[count].token, lexemeArray[count].digit); // If the token is not a identifier or digit, it just prints the token alone. else printf("%d ", lexemeArray[count].token); count++; } printf("\n"); // Frees the arrays. free(charInputArr); free(lexemeArray); charInputArr = NULL; lexemeArray = NULL; return 0; }
the_stack_data/90761615.c
#define TIMEOUT1 4 //400 #define TIMEOUT2 6 //600 #define TIMEOUT3 10 //5400 /* Named Constants */ #define FALSE 0 #define TRUE 1 /* Type declarations */ typedef char INT8; typedef unsigned char UINT8; typedef short INT16; typedef unsigned short UINT16; typedef int INT32; typedef unsigned int UINT32; typedef double REAL; typedef float SINGLE; typedef unsigned char BOOL; /* Function-like macros */ /* Conversion to the BOOL type */ #define TO_BOOL(X) ((X) ? 1 : 0) /* Type declarations */ typedef struct { INT32 Counter; BOOL InitSystem_OPEN; BOOL VehicleOpen_OPEN; BOOL AlarmWillBeArmedAfter20sec_CounterStart_OPEN; BOOL AlarmWillBeArmedAfter20sec_CounterPlus_OPEN; BOOL AlarmWillBeArmedAfter20sec_CounterEnd_OPEN; BOOL AlarmWillBeArmedAfter20sec_OPEN; BOOL AlarmOnlyOptical_CounterPlus_OPEN; BOOL AlarmOnlyOptical_CounterStart_OPEN; BOOL AlarmOnlyOptical_CounterEnd_OPEN; BOOL AlarmOnlyOptical_OPEN; BOOL AlarmAcousticAndOptical_CounterStart_OPEN; BOOL AlarmAcousticAndOptical_CounterPlus_OPEN; BOOL AlarmAcousticAndOptical_CounterEnd_OPEN; BOOL AlarmAcousticAndOptical_OPEN; BOOL AlarmArmed_OPEN; BOOL Alarm_system_OPEN; } t_Alarm_system_state; typedef struct { BOOL OpticalAlarm; BOOL AlarmSensor; BOOL VehLocked; BOOL AcousticAlarm; BOOL AlarmArmed; } t_Alarm_system_io; /* Named Constants */ #define ALARM_SYSTEM_TICK 0 void Alarm_system_init(t_Alarm_system_io *_io_, t_Alarm_system_state *_state_) { _io_->OpticalAlarm = FALSE; _io_->AlarmSensor = FALSE; _io_->VehLocked = FALSE; _io_->AcousticAlarm = FALSE; _io_->AlarmArmed = FALSE; _state_->Counter = 0; _state_->InitSystem_OPEN = 0; _state_->VehicleOpen_OPEN = 0; _state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN = 0; _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = 0; _state_->AlarmWillBeArmedAfter20sec_CounterEnd_OPEN = 0; _state_->AlarmWillBeArmedAfter20sec_OPEN = 0; _state_->AlarmOnlyOptical_CounterPlus_OPEN = 0; _state_->AlarmOnlyOptical_CounterStart_OPEN = 0; _state_->AlarmOnlyOptical_CounterEnd_OPEN = 0; _state_->AlarmOnlyOptical_OPEN = 0; _state_->AlarmAcousticAndOptical_CounterStart_OPEN = 0; _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = 0; _state_->AlarmAcousticAndOptical_CounterEnd_OPEN = 0; _state_->AlarmAcousticAndOptical_OPEN = 0; _state_->AlarmArmed_OPEN = 0; _state_->Alarm_system_OPEN = 0; } void Alarm_system_compute( t_Alarm_system_io *_io_, t_Alarm_system_state *_state_) { UINT16 activeEvent = ALARM_SYSTEM_TICK; if(!_state_->Alarm_system_OPEN) { /* Open the chart */ _state_->Alarm_system_OPEN = TRUE; /* Enter the chart's composition */ /* Enter state InitSystem */ _state_->InitSystem_OPEN = TRUE; } else { /* Execute an open chart */ if(_state_->InitSystem_OPEN) { /* Execute state InitSystem */ if(_io_->VehLocked == 1) { _state_->InitSystem_OPEN = FALSE; _state_->AlarmWillBeArmedAfter20sec_OPEN = TRUE; /* Open the inner composition of state AlarmWillBeArmedAfter20sec */ /* Enter state AlarmWillBeArmedAfter20sec.CounterStart */ _state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN = TRUE; /* Perform entry actions of state AlarmWillBeArmedAfter20sec.CounterStart */ _state_->Counter = 1; } else { if(_io_->VehLocked == 0) { _state_->InitSystem_OPEN = FALSE; _state_->VehicleOpen_OPEN = TRUE; //possible BUG } else { /* Perform during and on-event actions of state InitSystem */ _io_->AlarmArmed = TO_BOOL(1); _io_->AcousticAlarm = TO_BOOL(0); _io_->OpticalAlarm = TO_BOOL(0); } } } else { if(_state_->VehicleOpen_OPEN) { /* Execute state VehicleOpen */ if(_io_->VehLocked == 1) { _state_->VehicleOpen_OPEN = FALSE; _state_->AlarmWillBeArmedAfter20sec_OPEN = TRUE; /* Open the inner composition of state AlarmWillBeArmedAfter20sec */ /* Enter state AlarmWillBeArmedAfter20sec.CounterStart */ _state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN = TRUE; /* Perform entry actions of state AlarmWillBeArmedAfter20sec.CounterStart */ _state_->Counter = 1; } else { /* Perform during and on-event actions of state VehicleOpen */ _io_->AlarmArmed = TO_BOOL(0); _io_->AcousticAlarm = TO_BOOL(0); _io_->OpticalAlarm = TO_BOOL(0); } } else { if(_state_->AlarmWillBeArmedAfter20sec_OPEN) { /* Execute state AlarmWillBeArmedAfter20sec */ if(_state_->Counter == 0 && _io_->VehLocked == 1) { /* Close the inner composition of state AlarmWillBeArmedAfter20sec */ if(_state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN) { _state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN = FALSE; } else { if(_state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN) { _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = FALSE; } else { if(_state_->AlarmWillBeArmedAfter20sec_CounterEnd_OPEN) { _state_->AlarmWillBeArmedAfter20sec_CounterEnd_OPEN = FALSE; } } } _state_->AlarmWillBeArmedAfter20sec_OPEN = FALSE; _state_->AlarmArmed_OPEN = TRUE; } else { if(_io_->VehLocked == 0) { /* Close the inner composition of state AlarmWillBeArmedAfter20sec */ if(_state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN) { _state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN = FALSE; } else { if(_state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN) { _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = FALSE; } else { if(_state_->AlarmWillBeArmedAfter20sec_CounterEnd_OPEN) { _state_->AlarmWillBeArmedAfter20sec_CounterEnd_OPEN = FALSE; } } } _state_->AlarmWillBeArmedAfter20sec_OPEN = FALSE; _state_->VehicleOpen_OPEN = TRUE; //possible BUG } else { /* Perform during and on-event actions of state AlarmWillBeArmedAfter20sec */ _io_->AlarmArmed = TO_BOOL(0); _io_->AcousticAlarm = TO_BOOL(0); _io_->OpticalAlarm = TO_BOOL(0); if(_state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN) { /* Execute state AlarmWillBeArmedAfter20sec.CounterStart */ _state_->AlarmWillBeArmedAfter20sec_CounterStart_OPEN = FALSE; _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = TRUE; /* Perform entry actions of state AlarmWillBeArmedAfter20sec.CounterPlus */ _state_->Counter = _state_->Counter + 1; } else { if(_state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN) { /* Execute state AlarmWillBeArmedAfter20sec.CounterPlus */ if(_state_->Counter < TIMEOUT1 || _io_->VehLocked == 0) { _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = FALSE; _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = TRUE; /* Perform entry actions of state AlarmWillBeArmedAfter20sec.CounterPlus */ _state_->Counter = _state_->Counter + 1; } else { _state_->AlarmWillBeArmedAfter20sec_CounterPlus_OPEN = FALSE; _state_->AlarmWillBeArmedAfter20sec_CounterEnd_OPEN = TRUE; /* Perform entry actions of state AlarmWillBeArmedAfter20sec.CounterEnd */ _state_->Counter = 0; } } } } } } else { if(_state_->AlarmOnlyOptical_OPEN) { /* Execute state AlarmOnlyOptical */ if(_state_->Counter == 0) { /* Close the inner composition of state AlarmOnlyOptical */ if(_state_->AlarmOnlyOptical_CounterPlus_OPEN) { _state_->AlarmOnlyOptical_CounterPlus_OPEN = FALSE; } else { if(_state_->AlarmOnlyOptical_CounterStart_OPEN) { _state_->AlarmOnlyOptical_CounterStart_OPEN = FALSE; } else { if(_state_->AlarmOnlyOptical_CounterEnd_OPEN) { _state_->AlarmOnlyOptical_CounterEnd_OPEN = FALSE; } } } _state_->AlarmOnlyOptical_OPEN = FALSE; _state_->AlarmArmed_OPEN = TRUE; } else { if(_io_->VehLocked == 0) { /* Close the inner composition of state AlarmOnlyOptical */ if(_state_->AlarmOnlyOptical_CounterPlus_OPEN) { _state_->AlarmOnlyOptical_CounterPlus_OPEN = FALSE; } else { if(_state_->AlarmOnlyOptical_CounterStart_OPEN) { _state_->AlarmOnlyOptical_CounterStart_OPEN = FALSE; } else { if(_state_->AlarmOnlyOptical_CounterEnd_OPEN) { _state_->AlarmOnlyOptical_CounterEnd_OPEN = FALSE; } } } _state_->AlarmOnlyOptical_OPEN = FALSE; _state_->VehicleOpen_OPEN = TRUE; //possible BUG } else { /* Perform during and on-event actions of state AlarmOnlyOptical */ _io_->AlarmArmed = TO_BOOL(0); _io_->AcousticAlarm = TO_BOOL(0); _io_->OpticalAlarm = TO_BOOL(1); if(_state_->AlarmOnlyOptical_CounterPlus_OPEN) { /* Execute state AlarmOnlyOptical.CounterPlus */ if(_state_->Counter < TIMEOUT3 && _io_->VehLocked == 1) { _state_->AlarmOnlyOptical_CounterPlus_OPEN = FALSE; _state_->AlarmOnlyOptical_CounterPlus_OPEN = TRUE; /* Perform entry actions of state AlarmOnlyOptical.CounterPlus */ _state_->Counter = _state_->Counter + 1; } else { _state_->AlarmOnlyOptical_CounterPlus_OPEN = FALSE; _state_->AlarmOnlyOptical_CounterEnd_OPEN = TRUE; /* Perform entry actions of state AlarmOnlyOptical.CounterEnd */ _state_->Counter = 0; } } else { if(_state_->AlarmOnlyOptical_CounterStart_OPEN) { /* Execute state AlarmOnlyOptical.CounterStart */ _state_->AlarmOnlyOptical_CounterStart_OPEN = FALSE; _state_->AlarmOnlyOptical_CounterPlus_OPEN = TRUE; /* Perform entry actions of state AlarmOnlyOptical.CounterPlus */ _state_->Counter = _state_->Counter + 1; } } } } } else { if(_state_->AlarmAcousticAndOptical_OPEN) { /* Execute state AlarmAcousticAndOptical */ if(_state_->Counter == 0) { /* Close the inner composition of state AlarmAcousticAndOptical */ if(_state_->AlarmAcousticAndOptical_CounterStart_OPEN) { _state_->AlarmAcousticAndOptical_CounterStart_OPEN = FALSE; } else { if(_state_->AlarmAcousticAndOptical_CounterPlus_OPEN) { _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = FALSE; } else { if(_state_->AlarmAcousticAndOptical_CounterEnd_OPEN) { _state_->AlarmAcousticAndOptical_CounterEnd_OPEN = FALSE; } } } _state_->AlarmAcousticAndOptical_OPEN = FALSE; _state_->AlarmOnlyOptical_OPEN = TRUE; /* Open the inner composition of state AlarmOnlyOptical */ /* Enter state AlarmOnlyOptical.CounterStart */ _state_->AlarmOnlyOptical_CounterStart_OPEN = TRUE; /* Perform entry actions of state AlarmOnlyOptical.CounterStart */ _state_->Counter = 1; } else { if(_io_->VehLocked == 0) { /* Close the inner composition of state AlarmAcousticAndOptical */ if(_state_->AlarmAcousticAndOptical_CounterStart_OPEN) { _state_->AlarmAcousticAndOptical_CounterStart_OPEN = FALSE; } else { if(_state_->AlarmAcousticAndOptical_CounterPlus_OPEN) { _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = FALSE; } else { if(_state_->AlarmAcousticAndOptical_CounterEnd_OPEN) { _state_->AlarmAcousticAndOptical_CounterEnd_OPEN = FALSE; } } } _state_->AlarmAcousticAndOptical_OPEN = FALSE; _state_->VehicleOpen_OPEN = TRUE; //BUG does not work } else { /* Perform during and on-event actions of state AlarmAcousticAndOptical */ _io_->AlarmArmed = TO_BOOL(0); _io_->AcousticAlarm = TO_BOOL(1); _io_->OpticalAlarm = TO_BOOL(1); if(_state_->AlarmAcousticAndOptical_CounterStart_OPEN) { /* Execute state AlarmAcousticAndOptical.CounterStart */ _state_->AlarmAcousticAndOptical_CounterStart_OPEN = FALSE; _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = TRUE; /* Perform entry actions of state AlarmAcousticAndOptical.CounterPlus */ _state_->Counter = _state_->Counter + 1; } else { if(_state_->AlarmAcousticAndOptical_CounterPlus_OPEN) { /* Execute state AlarmAcousticAndOptical.CounterPlus */ if(_state_->Counter < TIMEOUT2 && _io_->VehLocked == 1) { _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = FALSE; _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = TRUE; /* Perform entry actions of state AlarmAcousticAndOptical.CounterPlus */ _state_->Counter = _state_->Counter + 1; } else { _state_->AlarmAcousticAndOptical_CounterPlus_OPEN = FALSE; _state_->AlarmAcousticAndOptical_CounterEnd_OPEN = TRUE; /* Perform entry actions of state AlarmAcousticAndOptical.CounterEnd */ _state_->Counter = 0; } } } } } } else { if(_state_->AlarmArmed_OPEN) { /* Execute state AlarmArmed */ if(_io_->AlarmSensor == 1) { _state_->AlarmArmed_OPEN = FALSE; _state_->AlarmAcousticAndOptical_OPEN = TRUE; //BUG does not work /* Open the inner composition of state AlarmAcousticAndOptical */ /* Enter state AlarmAcousticAndOptical.CounterStart */ _state_->AlarmAcousticAndOptical_CounterStart_OPEN = TRUE; /* Perform entry actions of state AlarmAcousticAndOptical.CounterStart */ _state_->Counter = 1; } else { if(_io_->VehLocked == 0) { _state_->AlarmArmed_OPEN = FALSE; _state_->VehicleOpen_OPEN = TRUE; //BUG does not work } else { /* Perform during and on-event actions of state AlarmArmed */ _io_->AlarmArmed = TO_BOOL(1); _io_->AcousticAlarm = TO_BOOL(0); _io_->OpticalAlarm = TO_BOOL(0); } } } } } } } } } } extern int nondet_int(); t_Alarm_system_io havocIO() { t_Alarm_system_io _io_; _io_.VehLocked = nondet_int(); _io_.AlarmSensor = nondet_int(); __CPROVER_assume( 0 <= _io_.VehLocked && _io_.VehLocked <= 1 && 0 <= _io_.AlarmSensor && _io_.AlarmSensor <= 1); return _io_; } int main() { int k = 0; t_Alarm_system_state _state_; t_Alarm_system_state _state_old; t_Alarm_system_io _io_; Alarm_system_init(&_io_, &_state_); while(1) { _state_old = _state_; _io_ = havocIO(); Alarm_system_compute(&_io_, &_state_); if(_state_old.AlarmArmed_OPEN && _io_.AlarmSensor) { assert(_state_.AlarmAcousticAndOptical_OPEN); } if( !_state_.InitSystem_OPEN && _state_old.Counter != 0 && !_io_.AlarmSensor && !_io_.VehLocked) assert(_state_.VehicleOpen_OPEN); } return 0; }
the_stack_data/560627.c
/* * POK header * * The following file is a part of the POK project. Any modification should * made according to the POK licence. You CANNOT use this file or a part of * this file is this part of a file for your own project * * For more information on the POK licence, please see our LICENCE FILE * * Please follow the coding guidelines described in doc/CODING_GUIDELINES * * Copyright (c) 2007-2009 POK team * * Created by julien on Fri Jan 30 14:41:34 2009 */ /* e_asinf.c -- float version of e_asin.c. * Conversion to float by Ian Lance Taylor, Cygnus Support, [email protected]. */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. * * Developed at SunPro, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ #ifdef POK_NEEDS_LIBMATH #include <libm.h> #include "math_private.h" static const float one = 1.0000000000e+00, /* 0x3F800000 */ huge = 1.000e+30, pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */ pio2_lo = 7.5497894159e-08, /* 0x33a22168 */ pio4_hi = 7.8539818525e-01, /* 0x3f490fdb */ /* coefficient for R(x^2) */ pS0 = 1.6666667163e-01, /* 0x3e2aaaab */ pS1 = -3.2556581497e-01, /* 0xbea6b090 */ pS2 = 2.0121252537e-01, /* 0x3e4e0aa8 */ pS3 = -4.0055535734e-02, /* 0xbd241146 */ pS4 = 7.9153501429e-04, /* 0x3a4f7f04 */ pS5 = 3.4793309169e-05, /* 0x3811ef08 */ qS1 = -2.4033949375e+00, /* 0xc019d139 */ qS2 = 2.0209457874e+00, /* 0x4001572d */ qS3 = -6.8828397989e-01, /* 0xbf303361 */ qS4 = 7.7038154006e-02; /* 0x3d9dc62e */ float __ieee754_asinf(float x) { float t, w, p, q, c, r, s; int32_t hx, ix; t = 0; GET_FLOAT_WORD(hx, x); ix = hx & 0x7fffffff; if (ix == 0x3f800000) { /* asin(1)=+-pi/2 with inexact */ return x * pio2_hi + x * pio2_lo; } else if (ix > 0x3f800000) { /* |x|>= 1 */ return (x - x) / (x - x); /* asin(|x|>1) is NaN */ } else if (ix < 0x3f000000) { /* |x|<0.5 */ if (ix < 0x32000000) { /* if |x| < 2**-27 */ if (huge + x > one) return x; /* return x with inexact if x!=0*/ } else t = x * x; p = t * (pS0 + t * (pS1 + t * (pS2 + t * (pS3 + t * (pS4 + t * pS5))))); q = one + t * (qS1 + t * (qS2 + t * (qS3 + t * qS4))); w = p / q; return x + x * w; } /* 1> |x|>= 0.5 */ w = one - fabsf(x); t = w * (float)0.5; p = t * (pS0 + t * (pS1 + t * (pS2 + t * (pS3 + t * (pS4 + t * pS5))))); q = one + t * (qS1 + t * (qS2 + t * (qS3 + t * qS4))); s = __ieee754_sqrtf(t); if (ix >= 0x3F79999A) { /* if |x| > 0.975 */ w = p / q; t = pio2_hi - ((float)2.0 * (s + s * w) - pio2_lo); } else { int32_t iw; w = s; GET_FLOAT_WORD(iw, w); SET_FLOAT_WORD(w, iw & 0xfffff000); c = (t - w * w) / (s + w); r = p / q; p = (float)2.0 * s * r - (pio2_lo - (float)2.0 * c); q = pio4_hi - (float)2.0 * w; t = pio4_hi - (p - q); } if (hx > 0) return t; else return -t; } #endif
the_stack_data/547161.c
/* PR middle-end/11151 */ /* Originator: Andrew Church <[email protected]> */ /* { dg-do run } */ /* This used to fail on SPARC because the (undefined) return value of 'bar' was overwriting that of 'foo'. */ extern void abort(void); int foo(int n) { return n+1; } int bar(int n) { __builtin_return(__builtin_apply((void (*)(void))foo, __builtin_apply_args(), 64)); } int main(void) { if (bar(1) != 2) abort(); return 0; }
the_stack_data/92324369.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_split_whitespaces.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: esupatae <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/05 02:58:48 by esupatae #+# #+# */ /* Updated: 2019/04/05 16:49:40 by esupatae ### ########.fr */ /* */ /* ************************************************************************** */ #include <stdlib.h> int is_whitespace(char c); int count_words(char *str); void create_addrs(char *str, int **addr); int calc_size(int **addr, int nbw); char **write_words(int **addr, int nbw, char *str); int is_whitespace(char c) { char *chars; chars = " \t\n\v\f\r"; while (*chars) if (c == *chars++) return (1); return (0); } int count_words(char *str) { int words; words = 0; while (*str) { if (!is_whitespace(*str)) { words++; while (!is_whitespace(*str) && *str) str++; } str++; } return (words); } void create_addrs(char *str, int **addr) { int i; int j; int w; i = 0; j = 0; w = 0; while (str[i]) { if (!is_whitespace(str[i])) { j = i; while (!is_whitespace(str[j]) && str[j]) j++; addr[w] = (int*)(malloc(sizeof(int) * 2)); addr[w][0] = i; addr[w][1] = j; w++; i = j; } i++; } } int calc_size(int **addr, int nbw) { int i; int size; i = 0; size = 0; while (i < nbw) { size = size + (*addr[1] - *addr[0] + 1); i++; } return (size); } char *extract_word(char *str, int start, int end) { int i; char *temp; i = start; temp = (char*)(malloc(sizeof(char) * (end - start + 2))); while (i <= end) { temp[i - start] = str[i]; i++; } temp[i] = '\0'; return (temp); } char **write_words(int **addr, int nbw, char *str) { char **wordarr; int size; int word_size; int i; size = calc_size(addr, nbw); wordarr = (char**)(malloc(sizeof(char*) * (size + 1))); i = 0; while (i < nbw) { word_size = addr[i][1] - addr[i][0] + 2; wordarr[i] = (char*)(malloc(sizeof(char) * word_size)); wordarr[i] = extract_word(str, addr[i][0], addr[i][1]); i++; } wordarr[i] = 0; return (wordarr); } char **ft_split_whitespaces(char *str) { int **addr; int words; int size; char **arr; words = count_words(str); addr = (int**)(malloc(sizeof(int*) * (words * 2 + 1))); create_addrs(str, addr); arr = write_words(addr, words, str); return (arr); }
the_stack_data/127083.c
#include <stdio.h> #include <stdlib.h> int main() { int a[]={7,6,8,4,3},i,n=5,j,t,k; int* p=a; printf("enter the elements :"); /* for(i=0;i<=n-1;i++) scanf("%d",p++); */ p=a; for(i=0;i<=n-1;i++) printf("%d,",*(p+i)); for(j=0;j<=n-1;j++) { for(i=0;i<=n-2;i++) { if(*(p+i)>*(p+i+1)) { t=*(p+i); *(p+i)=*(p+i+1); *(p+i+1)=t; } } } printf("\n"); for(k=0;k<=n-1;k++) printf("%d,",*(p+k)); }
the_stack_data/148579454.c
/** * @brief - program to find the prime numbers from 0 to 400 * * Author: Dev Naga <[email protected]> * * Apache LICENCE */ #include <stdio.h> #include <stdlib.h> struct linked_list { void *data; struct linked_list *next; }; static struct linked_list *head = NULL; static struct linked_list *tail = NULL; int linked_list_add(void *data) { struct linked_list *item; item = calloc(1, sizeof(struct linked_list)); if (!item) { fprintf(stderr, "failed to allocate @ %s %u\n", __func__, __LINE__); return -1; } item->data = data; if (!head) { head = item; tail = item; } else { tail->next = item; tail = item; } return 0; } int linked_list_add_head(void *data) { struct linked_list *item; item = calloc(1, sizeof(struct linked_list)); if (!item) { return -1; } item->data = data; if (!head) { head = item; tail = item; } else { item->next = head; head = item; } return 0; } int linked_list_remove(void *data, void (*remove_callback)(void *data)) { struct linked_list *cur; struct linked_list *prev; cur = head; if (cur->data == data) { head = cur->next; remove_callback(cur->data); free(cur); return 0; } while (cur) { if (cur->data == data) { prev->next = cur->next; remove_callback(cur->data); free(cur); return 0; } prev = cur; cur = cur->next; } return -1; } /** * return 1 if an item found or 0 if not */ int linked_list_find_item(void *data) { struct linked_list *cur; for (cur = head; cur; cur = cur->next) { if (cur->data == data) { return 1; } } return 0; } int linked_list_remove_all(void (*remove_callback)(void *data)) { struct linked_list *cur; struct linked_list *prev; cur = head; while (cur) { prev = cur; remove_callback(cur->data); cur = cur->next; free(prev); } } void linked_list_print(void (*print_callback)(void *data)) { struct linked_list *item; for (item = head; item; item = item->next) { print_callback(item->data); } } int linked_list_count() { struct linked_list *cur; int count = 0; for (cur = head; cur; cur = cur->next) { count ++; } return count; }
the_stack_data/234517354.c
/* MIT License Copyright (c) 2017-2019, Shahzeb Siddiqui Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include <stdio.h> #include <stdlib.h> #include <math.h> int main( int argc, char* argv[] ) { // Size of vectors int n = 10000; // Input vectors double *restrict a; double *restrict b; // Output vector double *restrict c; // Size, in bytes, of each vector size_t bytes = n*sizeof(double); // Allocate memory for each vector a = (double*)malloc(bytes); b = (double*)malloc(bytes); c = (double*)malloc(bytes); // Initialize content of input vectors, vector a[i] = sin(i)^2 vector b[i] = cos(i)^2 int i; for(i=0; i<n; i++) { a[i] = sin(i)*sin(i); b[i] = cos(i)*cos(i); } // sum component wise and save result into vector c #pragma acc kernels copyin(a[0:n],b[0:n]), copyout(c[0:n]) for(i=0; i<n; i++) { c[i] = a[i] + b[i]; } // Sum up vector c and print result divided by n, this should equal 1 within error double sum = 0.0; for(i=0; i<n; i++) { sum += c[i]; } sum = sum/n; printf("final result: %f\n", sum); // Release memory free(a); free(b); free(c); return 0; }
the_stack_data/145452226.c
/* Autor: Dayrin Cardona Compilador: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 Compilado: gcc Problema41603.c -o Problema41603 Fecha: Sun Mar 21 03:35:15 UTC 2021 Librerías: stdio (u otras) Resumen: Programa para mostrar los números primos dentro de un rango proporcionado por el usuario Entradas: N1, N2 Salidas: i */ //Librerías #include <stdio.h> //Se declaran las variables globales del programa int i, j, primo, N1, N2; void Es_primo(); int main(){ //Se pide al usuario que ingrese un primer número para crear un rango printf("Ingrese un primer número \n"); scanf("%d",&N1); //Se pide al usuario que ingrese un segundo número para crear un rango printf("Ingrese un segundo número \n"); scanf("%d",&N2); //Se iguala la variable i al primer número i=N1; //Con la sentencia while, mientras i sea menor o igual al segundo número, //el programa encuentra todos los números primos que están dentro de este rango. printf("Los números primos entre este rango son "); while(i<=N2){ //Dentro del bucle, el programa ejecuta la función Es_primo Es_primo(); //Si el número es primo, el programa escribe el número primo if(primo==1){ printf("%d, ",i); } //De lo contrario, el contador se aumenta en una unidad, y el bucle se repite de nuevo else(primo=0);{ i++; } } //El programa finaliza return 0; } void Es_primo(){ //Se inicializa el valor de la variable j y el valor de la variable primo j=2, primo=1; //Se utiliza la sentencia while para verificar que el número sea primo, dividiéndolo por cada número desde 2 hasta el valor actual de la variable i //controlada por el bucle while del programa principal. El bucle termina cuando se haya terminado de dividir el número ingresado por todos los números antes de él y se haya establecido si es //primo o no, o si dentro del bucle se encontró que el número no era primo. while((j<i) && (primo==1)) { //Si el residuo de la división entre el número indicado por el rango del usuario y la variable j es cero, //entonces la variable primo es cero y el número no es primo. if(i%j==0){ primo=0; } //De lo contrario, si este residuo no es cero, se aumenta el contador en una unidad, y el bucle para verificar si el número es primo o no se repite. else { j++; } } }
the_stack_data/139247.c
int main() { int c; // to suppress empty warnings }
the_stack_data/18887973.c
#include <stdio.h> int main(int argc, char* argv[]) { char nome[51]; printf("Teste de parâmetros.\n"); printf("Nosso programa recebeu %i argumentos.\n", argc); printf("Nosso programa tem nome %s.\n", argv[0]); int i; for(i = 0; i < argc ; i++) { printf("Parâmetro %i tem valor %s.\n", i, argv[i]); } return 0; }
the_stack_data/82949088.c
#include <stdio.h> int main(int argc, char *argv[]) { unsigned long n; scanf("%ld",&n); printf("%ld",(n*n*n+5*n)/6); }
the_stack_data/399553.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); extern void __VERIFIER_assume(int); void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } } extern int __VERIFIER_nondet_int(void); int N; int main() { N = __VERIFIER_nondet_int(); if(N <= 0) return 1; int i; int a[N]; int b[N]; b[0] = 1; a[0] = N+1; for(i=1; i<N; i++) { b[i] = b[i-1] + 2; } for(i=1; i<N; i++) { a[i] = a[i-1] + b[i-1] + 2; } for(i=0; i<N; i++) { __VERIFIER_assert(a[i] == N + (i+1)*(i+1)); } return 1; }
the_stack_data/17338.c
/* wordguess.c Author: Keith Mburu 2/4/2022 Implements word guessing game */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> #define MAXLENGTH 63 // highest total length of word chars (32) and spaces (31) /* Runs the game until the player wins */ void play(char* word, char* progress, char* complete) { char guess; // player's guess for one character int found; // check for guess correctness for (int i = 1; i != 0; i++) { // runs until player wins found = 0; printf("Turn: %d\n\n", i); printf("%s", progress); printf("\nGuess a character: "); fgets(&guess, 2, stdin); // read in ome character from player while (fgetc(stdin) != '\n'); // do away with any remaining characters for (int j = 0; j < strlen(word); j++) { if (word[j] == guess) { // check if guess is correct and update progress progress[2*j] = word[j]; found = 1; } } if (!found) { printf("Sorry, %c not found!\n", guess); } else if (strcmp(complete, progress) == 0) { // compare progress to end goal printf("\n%s\nYou won in %d turns!\n", progress, i); break; // end loop } } } int main() { printf("Welcome to Word Guess!\n\n"); // getting word to be guessed from a file of words FILE* wordFile; wordFile = fopen("words.txt", "r"); char lineCountStr[MAXLENGTH]; int lineCount; fgets(lineCountStr, MAXLENGTH+1, wordFile); lineCount = atoi(lineCountStr); srand(time(0)); int line = rand() % lineCount; char word[MAXLENGTH]; for (int i = 0; i < line; i++) { fgets(word, MAXLENGTH+1, wordFile); } fclose(wordFile); // setting up current progress and end goal char progress[MAXLENGTH] = "_"; char complete[MAXLENGTH] = ""; complete[0] = word[0]; for (int i = 0; i < strlen(word) - 2; i++) { strcat(progress, " _"); strcat(complete, " "); complete[2*(i+1)] = word[i+1]; } complete[(strlen(word)-1)*2] = '\0'; play(word, progress, complete); return 0; }
the_stack_data/151805.c
#pragma acc data present (rho_i, u, qs, rhs, square) create (lhsX, fjacX, njacX) #pragma acc parallel loop gang num_gangs (isize+1) num_workers (8) vector_length (32) #pragma acc kernels loop gang #pragma acc loop worker independent #pragma acc loop vector independent #pragma acc parallel loop gang num_gangs (gp12) num_workers (8) vector_length (32) #pragma acc kernels loop gang #pragma acc loop worker vector independent #pragma acc parallel loop gang num_gangs (gp12) num_workers (8) vector_length (32) #pragma acc kernels loop gang #pragma acc loop worker vector independent #pragma acc parallel loop gang num_gangs (isize-1) num_workers (8) vector_length (32) #pragma acc kernels loop gang #pragma acc loop worker independent #pragma acc loop vector independent #pragma acc parallel loop gang num_gangs (gp12) num_workers (4) vector_length (32) #pragma acc kernels loop gang #pragma acc loop worker vector independent #pragma acc parallel loop gang num_gangs (gp12) num_workers (4) vector_length (32) #pragma acc kernels loop gang #pragma acc loop worker vector independent #pragma acc parallel loop gang num_gangs (gp12) num_workers (4) vector_length (32) #pragma acc kernels loop gang #pragma acc loop worker vector independent #pragma acc parallel loop gang num_gangs (gp12) num_workers (4) vector_length (32) #pragma acc kernels loop gang #pragma acc loop worker vector independent #pragma acc parallel loop gang num_gangs (gp12) num_workers (4) vector_length (32) #pragma acc kernels loop gang #pragma acc loop worker vector independent #pragma acc parallel loop gang num_gangs (gp12) num_workers (4) vector_length (32) #pragma acc kernels loop gang #pragma acc loop worker vector independent
the_stack_data/247019549.c
/* static.c */ #include <stdio.h> int natural_generator() { int a = 1; static int b = -1; b += 1; return a + b; } int main() { printf("%d\n", natural_generator()); printf("%d\n", natural_generator()); printf("%d\n", natural_generator()); return 0; }
the_stack_data/1148180.c
#include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; #ifdef _MSC_VER static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;} static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;} static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;} static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;} #else static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #endif #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #ifdef _MSC_VER #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);} #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);} #else #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #endif #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimagf(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #ifdef _MSC_VER static _Fcomplex cpow_ui(complex x, integer n) { complex pow={1.0,0.0}; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i; for(u = n; ; ) { if(u & 01) pow.r *= x.r, pow.i *= x.i; if(u >>= 1) x.r *= x.r, x.i *= x.i; else break; } } _Fcomplex p={pow.r, pow.i}; return p; } #else static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #endif #ifdef _MSC_VER static _Dcomplex zpow_ui(_Dcomplex x, integer n) { _Dcomplex pow={1.0,0.0}; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1]; for(u = n; ; ) { if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1]; if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1]; else break; } } _Dcomplex p = {pow._Val[0], pow._Val[1]}; return p; } #else static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #endif static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Fcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0]; zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0]; zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1]; } } pCf(z) = zdotc; } #else _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } #endif static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Dcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0]; zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0]; zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1]; } } pCd(z) = zdotc; } #else _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Fcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0]; zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0]; zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1]; } } pCf(z) = zdotc; } #else _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } #endif static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Dcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0]; zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0]; zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1]; } } pCd(z) = zdotc; } #else _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static integer c__1 = 1; static integer c_n1 = -1; static real c_b13 = -1.f; static real c_b14 = 1.f; /* > \brief \b SPOTRF */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download SPOTRF + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/spotrf. f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/spotrf. f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/spotrf. f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE SPOTRF( UPLO, N, A, LDA, INFO ) */ /* CHARACTER UPLO */ /* INTEGER INFO, LDA, N */ /* REAL A( LDA, * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > SPOTRF computes the Cholesky factorization of a real symmetric */ /* > positive definite matrix A. */ /* > */ /* > The factorization has the form */ /* > A = U**T * U, if UPLO = 'U', or */ /* > A = L * L**T, if UPLO = 'L', */ /* > where U is an upper triangular matrix and L is lower triangular. */ /* > */ /* > This is the block version of the algorithm, calling Level 3 BLAS. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] UPLO */ /* > \verbatim */ /* > UPLO is CHARACTER*1 */ /* > = 'U': Upper triangle of A is stored; */ /* > = 'L': Lower triangle of A is stored. */ /* > \endverbatim */ /* > */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The order of the matrix A. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in,out] A */ /* > \verbatim */ /* > A is REAL array, dimension (LDA,N) */ /* > On entry, the symmetric matrix A. If UPLO = 'U', the leading */ /* > N-by-N upper triangular part of A contains the upper */ /* > triangular part of the matrix A, and the strictly lower */ /* > triangular part of A is not referenced. If UPLO = 'L', the */ /* > leading N-by-N lower triangular part of A contains the lower */ /* > triangular part of the matrix A, and the strictly upper */ /* > triangular part of A is not referenced. */ /* > */ /* > On exit, if INFO = 0, the factor U or L from the Cholesky */ /* > factorization A = U**T*U or A = L*L**T. */ /* > \endverbatim */ /* > */ /* > \param[in] LDA */ /* > \verbatim */ /* > LDA is INTEGER */ /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[out] INFO */ /* > \verbatim */ /* > INFO is INTEGER */ /* > = 0: successful exit */ /* > < 0: if INFO = -i, the i-th argument had an illegal value */ /* > > 0: if INFO = i, the leading minor of order i is not */ /* > positive definite, and the factorization could not be */ /* > completed. */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date December 2016 */ /* > \ingroup realPOcomputational */ /* ===================================================================== */ /* Subroutine */ int spotrf_(char *uplo, integer *n, real *a, integer *lda, integer *info) { /* System generated locals */ integer a_dim1, a_offset, i__1, i__2, i__3, i__4; /* Local variables */ integer j; extern logical lsame_(char *, char *); extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *, integer *, real *, real *, integer *, real *, integer *, real *, real *, integer *); logical upper; extern /* Subroutine */ int strsm_(char *, char *, char *, char *, integer *, integer *, real *, real *, integer *, real *, integer * ), ssyrk_(char *, char *, integer *, integer *, real *, real *, integer *, real *, real *, integer * ); integer jb, nb; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *, ftnlen, ftnlen); extern /* Subroutine */ int spotrf2_(char *, integer *, real *, integer *, integer *); /* -- LAPACK computational routine (version 3.7.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* December 2016 */ /* ===================================================================== */ /* Test the input parameters. */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*lda < f2cmax(1,*n)) { *info = -4; } if (*info != 0) { i__1 = -(*info); xerbla_("SPOTRF", &i__1, (ftnlen)6); return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } /* Determine the block size for this environment. */ nb = ilaenv_(&c__1, "SPOTRF", uplo, n, &c_n1, &c_n1, &c_n1, (ftnlen)6, ( ftnlen)1); if (nb <= 1 || nb >= *n) { /* Use unblocked code. */ spotrf2_(uplo, n, &a[a_offset], lda, info); } else { /* Use blocked code. */ if (upper) { /* Compute the Cholesky factorization A = U**T*U. */ i__1 = *n; i__2 = nb; for (j = 1; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) { /* Update and factorize the current diagonal block and test */ /* for non-positive-definiteness. */ /* Computing MIN */ i__3 = nb, i__4 = *n - j + 1; jb = f2cmin(i__3,i__4); i__3 = j - 1; ssyrk_("Upper", "Transpose", &jb, &i__3, &c_b13, &a[j * a_dim1 + 1], lda, &c_b14, &a[j + j * a_dim1], lda); spotrf2_("Upper", &jb, &a[j + j * a_dim1], lda, info); if (*info != 0) { goto L30; } if (j + jb <= *n) { /* Compute the current block row. */ i__3 = *n - j - jb + 1; i__4 = j - 1; sgemm_("Transpose", "No transpose", &jb, &i__3, &i__4, & c_b13, &a[j * a_dim1 + 1], lda, &a[(j + jb) * a_dim1 + 1], lda, &c_b14, &a[j + (j + jb) * a_dim1], lda); i__3 = *n - j - jb + 1; strsm_("Left", "Upper", "Transpose", "Non-unit", &jb, & i__3, &c_b14, &a[j + j * a_dim1], lda, &a[j + (j + jb) * a_dim1], lda); } /* L10: */ } } else { /* Compute the Cholesky factorization A = L*L**T. */ i__2 = *n; i__1 = nb; for (j = 1; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) { /* Update and factorize the current diagonal block and test */ /* for non-positive-definiteness. */ /* Computing MIN */ i__3 = nb, i__4 = *n - j + 1; jb = f2cmin(i__3,i__4); i__3 = j - 1; ssyrk_("Lower", "No transpose", &jb, &i__3, &c_b13, &a[j + a_dim1], lda, &c_b14, &a[j + j * a_dim1], lda); spotrf2_("Lower", &jb, &a[j + j * a_dim1], lda, info); if (*info != 0) { goto L30; } if (j + jb <= *n) { /* Compute the current block column. */ i__3 = *n - j - jb + 1; i__4 = j - 1; sgemm_("No transpose", "Transpose", &i__3, &jb, &i__4, & c_b13, &a[j + jb + a_dim1], lda, &a[j + a_dim1], lda, &c_b14, &a[j + jb + j * a_dim1], lda); i__3 = *n - j - jb + 1; strsm_("Right", "Lower", "Transpose", "Non-unit", &i__3, & jb, &c_b14, &a[j + j * a_dim1], lda, &a[j + jb + j * a_dim1], lda); } /* L20: */ } } } goto L40; L30: *info = *info + j - 1; L40: return 0; /* End of SPOTRF */ } /* spotrf_ */
the_stack_data/396545.c
// RUN: %clang_cc1 -ffreestanding -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s #include <x86intrin.h> unsigned char test_addcarry_u32(unsigned char __cf, unsigned int __x, unsigned int __y, unsigned int *__p) { // CHECK-LABEL: test_addcarry_u32 // CHECK: call i8 @llvm.x86.addcarry.u32 return _addcarry_u32(__cf, __x, __y, __p); } unsigned char test_addcarry_u64(unsigned char __cf, unsigned long long __x, unsigned long long __y, unsigned long long *__p) { // CHECK-LABEL: test_addcarry_u64 // CHECK: call i8 @llvm.x86.addcarry.u64 return _addcarry_u64(__cf, __x, __y, __p); } unsigned char test_subborrow_u32(unsigned char __cf, unsigned int __x, unsigned int __y, unsigned int *__p) { // CHECK-LABEL: test_subborrow_u32 // CHECK: call i8 @llvm.x86.subborrow.u32 return _subborrow_u32(__cf, __x, __y, __p); } unsigned char test_subborrow_u64(unsigned char __cf, unsigned long long __x, unsigned long long __y, unsigned long long *__p) { // CHECK-LABEL: test_subborrow_u64 // CHECK: call i8 @llvm.x86.subborrow.u64 return _subborrow_u64(__cf, __x, __y, __p); }
the_stack_data/28263794.c
#define _GNU_SOURCE #include <dlfcn.h> #include <stdio.h> #include <ftw.h> #include <glob.h> #include <utime.h> char * basename (const char *filename); int glob (const char *pattern, int flags, int (*errfunc) (const char *filename, int error_code), glob_t *vector_ptr); int glob64 (const char *pattern, int flags, int (*errfunc) (const char *filename, int error_code), glob64_t *vector_ptr); FILE * fopen (const char *filename, const char *opentype); FILE * fopen64 (const char *filename, const char *opentype); FILE * freopen (const char *filename, const char *opentype, FILE *stream); FILE * freopen64 (const char *filename, const char *opentype, FILE *stream); int open (const char *filename, int flags, ...); int open64 (const char *filename, int flags, ...); int chdir (const char *filename); int ftw (const char *filename, __ftw_func_t func, int descriptors); int ftw64 (const char *filename, __ftw64_func_t func, int descriptors); int nftw (const char *filename, __nftw_func_t func, int descriptors, int flag); int nftw64 (const char *filename, __nftw64_func_t func, int descriptors, int flag); ssize_t readlink (const char *filename, char *buffer, size_t size); int unlink (const char *filename); int rmdir (const char *filename); int remove (const char *filename); int mkdir (const char *filename, mode_t mode); int stat (const char *filename, struct stat *buf); int stat64 (const char *filename, struct stat64 *buf); int lstat (const char *filename, struct stat *buf); int lstat64 (const char *filename, struct stat64 *buf); int chown (const char *filename, uid_t owner, gid_t group); int chmod (const char *filename, mode_t mode); int access (const char *filename, int how); int utime (const char *filename, const struct utimbuf *times); int utimes (const char *filename, const struct timeval tvp[2]); int lutimes (const char *filename, const struct timeval tvp[2]); int truncate (const char *filename, off_t length); int mknod (const char *filename, mode_t mode, dev_t dev); int mkfifo (const char *filename, mode_t mode); int execv (const char *filename, char *const argv[]); int execl (const char *filename, const char *arg0, ...); int execve (const char *filename, char *const argv[], char *const env[]); int execle (const char *filename, const char *arg0, ...); int execvp (const char *filename, char *const argv[]); int execlp (const char *filename, const char *arg0, ...); long int pathconf (const char *filename, int parameter);
the_stack_data/20449816.c
#if defined(_MSC_VER) && !defined(_WIN64) #include <windows.h> #if (_WIN32_WINNT < 0x0502) void MemoryBarrier() { LONG Barrier; __asm { xchg Barrier, eax } } #endif #endif
the_stack_data/14200440.c
#include <curses.h> #include <stdio.h> #include <stdlib.h> // watch this and implement menu for states // https://www.youtube.com/watch?v=3YiPdibiQHA #define BKSP '\b' enum states { HOME, ECHO, SLEEP }; enum states programState = HOME; int startSession(); int endSession(); int main(void) { startSession(); int c; while (c != 'q') { switch (programState) { case HOME: { // printw("start home case\n"); c = getch(); if (c == 'E') { programState = ECHO; } else if (c == 'S') { programState = SLEEP; } else { // putchar('BKSP'); } break; } case ECHO: { int echo_char = getch(); if (echo_char == 'H') { programState = HOME; } else { addch(echo_char); } break; } case SLEEP: { int echo_char = getch(); if (echo_char == 'H') { programState = HOME; } else { // do nothing, dont care about any other echo_char } break; } default: // do nothing. why are we here anyway break; } } endSession(); } int startSession() { initscr(); noecho(); return 0; } int endSession() { echo(); endwin(); return 0; }
the_stack_data/136251.c
/** ****************************************************************************** * @file stm32f3xx_ll_hrtim.c * @author MCD Application Team * @version V1.4.0 * @date 16-December-2016 * @brief HRTIM LL module driver. ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2> * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ #if defined(USE_FULL_LL_DRIVER) /* Includes ------------------------------------------------------------------*/ #include "stm32f3xx_ll_hrtim.h" #include "stm32f3xx_ll_bus.h" #ifdef USE_FULL_ASSERT #include "stm32_assert.h" #else #define assert_param(expr) ((void)0U) #endif /** @addtogroup STM32F3xx_LL_Driver * @{ */ #if defined (HRTIM1) /** @addtogroup HRTIM_LL * @{ */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /** @addtogroup HRTIM_LL_Exported_Functions * @{ */ /** * @brief Set HRTIM instance registers to their reset values. * @param HRTIMx High Resolution Timer instance * @retval ErrorStatus enumeration value: * - SUCCESS: HRTIMx registers are de-initialized * - ERROR: invalid HRTIMx instance */ ErrorStatus LL_HRTIM_DeInit(HRTIM_TypeDef* HRTIMx) { ErrorStatus result = SUCCESS; /* Check the parameters */ assert_param(IS_HRTIM_ALL_INSTANCE(HRTIMx)); LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_HRTIM1); LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_HRTIM1); return result; } /** * @} */ /** * @} */ #endif /* HRTIM1 */ /** * @} */ #endif /* USE_FULL_LL_DRIVER */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
the_stack_data/111517.c
static int dfs(int **matrix, int **dp, int row_sz, int col_sz, int x, int y) { if (dp[x][y]) return dp[x][y]; int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; int max = 1; for (int i = 0; i < 4; i++) { int cur_x = x + dir[i][0], cur_y = y + dir[i][1]; if (cur_x >= 0 && cur_x < row_sz && cur_y >= 0 && cur_y < col_sz && matrix[x][y] < matrix[cur_x][cur_y]) { int len = 1 + dfs(matrix, dp, row_sz, col_sz, cur_x, cur_y); max = (max > len ? max : len); } } dp[x][y] = max; return max; } int longestIncreasingPath(int **matrix, int matrix_sz, int *matrix_col_sz) { if (!matrix_sz) return 0; int **dp = malloc(sizeof(int *) * matrix_sz); int m_col_sz = matrix_col_sz[0]; for (int i = 0; i < matrix_sz; i++) dp[i] = calloc(m_col_sz, sizeof(int)); int ret = 1; for (int i = 0; i < matrix_sz; i++) { for (int j = 0; j < m_col_sz; j++) { int tmp = dfs(matrix, dp, matrix_sz, m_col_sz, i, j); ret = (ret > tmp ? ret : tmp); } } for (int i = 0; i < matrix_sz; i++) free(dp[i]); free(dp); return ret; }
the_stack_data/103265573.c
/* $Id$ */ /* tolower( int ) This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. */ #include <ctype.h> #ifndef REGTEST int tolower( int c ) { if (isupper(c)) return (c-'A'+'a'); else return c; } #endif #ifdef TEST #include <_PDCLIB_test.h> int main( void ) { TESTCASE( tolower( 'A' ) == 'a' ); TESTCASE( tolower( 'Z' ) == 'z' ); TESTCASE( tolower( 'a' ) == 'a' ); TESTCASE( tolower( 'z' ) == 'z' ); TESTCASE( tolower( '@' ) == '@' ); TESTCASE( tolower( '[' ) == '[' ); return TEST_RESULTS; } #endif
the_stack_data/212644145.c
#include <stdio.h> #include <stdlib.h> #define POVEZANI 1 #define NEPOVEZANI 0 #define NEDEFINISANO (-1) struct Element { int indeksCvora; struct Element *sled; }; void inicijalizacija( int **graf, int *d, int *preth, int n ) { int i, j; for(i = 0; i < n; i++) { /* inicijalizacija grafa */ graf[i] = (int*) malloc( n * sizeof( int ) ); if( !graf[i] ) { printf("Neuspesno alociranje memorije\n"); exit(EXIT_FAILURE); } for(j = 0; j < n; j++) { graf[i][j] = NEPOVEZANI; } /* inicijalizacija pomocnih nizova */ d[i] = NEDEFINISANO; preth[i] = NEDEFINISANO; } } void dodajURed( struct Element **glava, struct Element **rep, int indeksCvora ) { struct Element *novi = (struct Element *) malloc( sizeof( struct Element ) ); if( !novi ) { printf("Neuspesno alociranje memorije\n"); exit(EXIT_FAILURE); } novi->indeksCvora = indeksCvora; novi->sled = NULL; if( *glava == NULL ) /* proverava da li je red prazan */ { *glava = novi; *rep = novi; } else /* dodaje element na kraj reda */ { (*rep)->sled = novi; /* na poslednji el. povezuje novi */ *rep = novi; /* posto je novi povezan na kraj, sada on postaje poslednji */ } } int skiniSaRed( struct Element **glava, struct Element **rep ) { int indeksCvora; struct Element *temp; if( *glava == NULL ) /* proveri da li je red prazan */ return NEDEFINISANO; else { indeksCvora = (*glava)->indeksCvora; /* cuva indeks cvora koji ce se izbaciti iz reda */ if( *glava == *rep ) /* proveri da li je u redu ostao sam jedan element */ *rep = NULL; /* sprecava pojavu dangling pointera */ temp = *glava; /* sacuvaj adresu el. koji ce biti obrisan */ *glava = (*glava)->sled; /* postavi glavu na sledeci element; ako ima samo 1. bice NULL */ free(temp); /* oslobodi memoriju koji je zauzimao prvi element */ return indeksCvora; /* vrati indeks cvora koji se nalazio na prvom mestu u redu */ } } void stampajMatricuPovezanosti( int **graf, int n ) { int i, j; printf(" "); for(i = 0; i < n; i++) printf("%3d ", i ); printf("\n"); for(i = 0; i < n; i++) { printf("%3d ", i ); for(j = 0; j < n; j++) { if( graf[i][j] == NEPOVEZANI ) printf("INF "); else printf("%3d ", graf[i][j]); } printf("\n"); } printf("\n"); } void bfs( int **graf, int *d, int *preth, struct Element **glava, struct Element **rep, int n ) { int u, v; /* prolazi kroz graf sve dok svi cvorovi kojima je predak cvor s * ne obidju sve svoje susede */ while( ( u = skiniSaRed( glava, rep ) ) != NEDEFINISANO ) { for( v = 0; v < n; v++ ) { if( graf[u][v] == POVEZANI && d[v] == NEDEFINISANO ) { d[v] = d[u] + 1; preth[v] = u; dodajURed( glava, rep, v ); } } } } void stampajPutanju( int *preth, int pocetniCvor, int indeksCvora ) { if( indeksCvora == pocetniCvor ) printf("%d ", indeksCvora ); else if( preth[indeksCvora] == NEDEFINISANO ) printf("Nije moguce doci od cvora %d do cvora %d\n", pocetniCvor, indeksCvora ); else { stampajPutanju( preth, pocetniCvor, preth[indeksCvora] ); printf("%d ", indeksCvora ); } } int main() { int i, n, l; int u, v, s; /* deklaracija pointera na pocetak i kraj reda */ struct Element *glava, *rep; /* inicijalizacija pointera na el. reda*/ glava = rep = NULL; printf("Unesite broj cvorova i veza:\n"); scanf("%d%d", &n, &l ); int **graf = (int**) malloc( n * sizeof( int* ) ); int *d = (int*) malloc( n * sizeof( int ) ); int *preth = (int*) malloc( n * sizeof( int ) ); /* provera da li je sve ispravno alocirano */ if( !graf || !d || !preth ) { printf("Neuspesno alociranje memorije\n"); exit(EXIT_FAILURE); } /* inicijalizacija grafa i potrebnih nizova */ inicijalizacija( graf, d, preth, n ); /* unos podataka o vezama */ printf("Unesite veze:\n"); for(i = 0; i < l; i++) { scanf("%d%d", &u, &v ); graf[u][v] = POVEZANI; } printf("Unesite indeks pocetnog cvora (zero-based):\n"); scanf("%d", &s ); /* prvom cvoru je potrebno 0 koraka da dodje do samog sebe */ d[s] = 0; /* posto znamo "daljinu" cvora s od pocetka (njega samog) * dodajemo ga u red za cvorove cije susete treba ispitati */ dodajURed( &glava, &rep, s ); /* odredjivanje potrebnih koraka od cvora s do svakog drugo cvora */ bfs( graf, d, preth, &glava, &rep, n ); /* ispisivanje putanje od cvora s to svakog cvora u grafu, ukoliko postoji */ for(i = 0; i < n; i++) { printf("Putanja od %d do %d:\n", s, i ); stampajPutanju( preth, s, i ); printf("\n"); } /* ispis matrice povezanosti */ stampajMatricuPovezanosti( graf, n ); }
the_stack_data/150144142.c
#include <stdio.h> #include <ctype.h> long alphaToInt(char *); int main(int argc, char *argv[]) { char str[10]; while (gets(str) && *str) printf("%ld\n", alphaToInt(str)); return 0; } long alphaToInt(char * str) { long result = 0 , sign = (*str == '-') ? -1 : 1; char * pt = (sign == -1) ? str+1: str; while (isnumber(*pt)) { result = result*10 + (*pt++ - '0'); } return sign*result; }
the_stack_data/18888965.c
#include <wctype.h> int iswxdigit(wint_t wc) { return (unsigned)(wc - '0') < 10 || (unsigned)((wc | 32) - 'a') < 6; }
the_stack_data/717269.c
/* * BSD 3-Clause License * * Copyright (c) 2021, Timothy Brown * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. Neither the name of the 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <stdlib.h> #include <stdio.h> #include <stdint.h> #include <sys/resource.h> #include <string.h> #include <errno.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #ifdef HAVE_MPI #include <mpi.h> #endif int plimit(char *limit) { int rank = 0; int world = 0; int resource = 0; struct rlimit lim = {0}; #ifdef HAVE_MPI MPI_Comm_size(MPI_COMM_WORLD, &world); MPI_Comm_rank(MPI_COMM_WORLD, &rank); #endif if (strcmp(limit, "core") == 0) { resource = RLIMIT_CORE; } else if (strcmp(limit, "cpu") == 0) { resource = RLIMIT_CPU; } else if (strcmp(limit, "data") == 0) { resource = RLIMIT_DATA; } else if (strcmp(limit, "fsize") == 0) { resource = RLIMIT_FSIZE; } else if (strcmp(limit, "memlock") == 0) { resource = RLIMIT_MEMLOCK; } else if (strcmp(limit, "nofile") == 0) { resource = RLIMIT_NOFILE; } else if (strcmp(limit, "nproc") == 0) { resource = RLIMIT_NPROC; } else if (strcmp(limit, "rss") == 0) { resource = RLIMIT_RSS; } else if (strcmp(limit, "stack") == 0) { resource = RLIMIT_STACK; } if (getrlimit(resource, &lim) == 0) { printf("[%03d/%03d] %s limits -> soft: %ju\thard: %ju\n", rank, world, limit, (uintmax_t)lim.rlim_cur, (uintmax_t)lim.rlim_max); } else { fprintf(stderr, "unable to get %s from getrlimit(): %s\n", limit, strerror(errno)); } return EXIT_SUCCESS; }
the_stack_data/125139774.c
// Check passing PowerPC ABI options to the backend. // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ELFv1 %s // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1 %s // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mabi=elfv1-qpx | FileCheck -check-prefix=CHECK-ELFv1-QPX %s // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mcpu=a2q | FileCheck -check-prefix=CHECK-ELFv1-QPX %s // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mcpu=a2 -mqpx | FileCheck -check-prefix=CHECK-ELFv1-QPX %s // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mcpu=a2q -mno-qpx | FileCheck -check-prefix=CHECK-ELFv1 %s // RUN: %clang -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2-BE %s // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ELFv2 %s // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1-LE %s // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2 %s // RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2 %s // CHECK-ELFv1: "-mrelocation-model" "pic" "-pic-level" "2" // CHECK-ELFv1: "-target-abi" "elfv1" // CHECK-ELFv1-LE: "-mrelocation-model" "static" // CHECK-ELFv1-LE: "-target-abi" "elfv1" // CHECK-ELFv1-QPX: "-mrelocation-model" "pic" "-pic-level" "2" // CHECK-ELFv1-QPX: "-target-abi" "elfv1-qpx" // CHECK-ELFv2: "-mrelocation-model" "static" // CHECK-ELFv2: "-target-abi" "elfv2" // CHECK-ELFv2-BE: "-mrelocation-model" "pic" "-pic-level" "2" // CHECK-ELFv2-BE: "-target-abi" "elfv2" // RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ELFv1-PIC %s // RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1-PIC %s // RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mabi=elfv1-qpx | FileCheck -check-prefix=CHECK-ELFv1-QPX-PIC %s // RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mcpu=a2q | FileCheck -check-prefix=CHECK-ELFv1-QPX-PIC %s // RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mcpu=a2 -mqpx | FileCheck -check-prefix=CHECK-ELFv1-QPX-PIC %s // RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mcpu=a2q -mno-qpx | FileCheck -check-prefix=CHECK-ELFv1-PIC %s // RUN: %clang -fPIC -target powerpc64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2-PIC %s // RUN: %clang -fPIC -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ELFv2-PIC %s // RUN: %clang -fPIC -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mabi=elfv1 | FileCheck -check-prefix=CHECK-ELFv1-PIC %s // RUN: %clang -fPIC -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mabi=elfv2 | FileCheck -check-prefix=CHECK-ELFv2-PIC %s // RUN: %clang -fPIC -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2-PIC %s // CHECK-ELFv1-PIC: "-mrelocation-model" "pic" "-pic-level" "2" // CHECK-ELFv1-PIC: "-target-abi" "elfv1" // CHECK-ELFv1-QPX-PIC: "-mrelocation-model" "pic" "-pic-level" "2" // CHECK-ELFv1-QPX-PIC: "-target-abi" "elfv1-qpx" // CHECK-ELFv2-PIC: "-mrelocation-model" "pic" "-pic-level" "2" // CHECK-ELFv2-PIC: "-target-abi" "elfv2" // Check -mabi=ieeelongdouble is passed through but it does not change -target-abi. // RUN: %clang -target powerpc64le-linux-gnu %s -mabi=ieeelongdouble -mabi=elfv1 -### 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ELFv1-IEEE %s // RUN: %clang -target powerpc64le-linux-gnu %s -mabi=elfv1 -mabi=ieeelongdouble -### 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ELFv1-IEEE %s // RUN: %clang -target powerpc64le-linux-gnu %s -mabi=elfv2 -mabi=elfv1 -mabi=ibmlongdouble -mabi=ieeelongdouble -### 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ELFv1-IEEE %s // CHECK-ELFv1-IEEE: "-mabi=ieeelongdouble" // CHECK-ELFv1-IEEE: "-target-abi" "elfv1" // Check -mabi=ibmlongdouble is the default. // RUN: %clang -target powerpc64le-linux-gnu %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ELFv2-IBM128 %s // RUN: %clang -target powerpc64le-linux-gnu %s -mabi=ibmlongdouble -### 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ELFv2-IBM128 %s // CHECK-ELFv2-IBM128-NOT: "-mabi=ieeelongdouble" // CHECK-ELFv2-IBM128: "-target-abi" "elfv2"
the_stack_data/20524.c
#include <stdio.h> #if defined(__is_libk) #include <kernel/tty.h> #endif int putchar(int ic) { #if defined(__is_libk) tty_putChar((char) ic); #else // TODO: Implement stdio and the write system call. #endif return ic; }
the_stack_data/128095.c
// ConsoleApplication1.cpp : Diese Datei enthält die Funktion "main". Hier beginnt und endet die Ausführung des Programms. // #include <stdio.h> int main() { /*char eingabe ; //std::cout << "Hello World!\n"; //printf("Hello world"); gets_s(eingabe, 1); printf(eingabe); */ int breite; int laenge; int dicke; printf("Blechrechner"); /*scanf_s gets_s(breite); printf("The line entered was: %d\n", breite);*/ } // Programm ausführen: STRG+F5 oder "Debuggen" > Menü "Ohne Debuggen starten" // Programm debuggen: F5 oder "Debuggen" > Menü "Debuggen starten" // Tipps für den Einstieg: // 1. Verwenden Sie das Projektmappen-Explorer-Fenster zum Hinzufügen/Verwalten von Dateien. // 2. Verwenden Sie das Team Explorer-Fenster zum Herstellen einer Verbindung mit der Quellcodeverwaltung. // 3. Verwenden Sie das Ausgabefenster, um die Buildausgabe und andere Nachrichten anzuzeigen. // 4. Verwenden Sie das Fenster "Fehlerliste", um Fehler anzuzeigen. // 5. Wechseln Sie zu "Projekt" > "Neues Element hinzufügen", um neue Codedateien zu erstellen, bzw. zu "Projekt" > "Vorhandenes Element hinzufügen", um dem Projekt vorhandene Codedateien hinzuzufügen. // 6. Um dieses Projekt später erneut zu öffnen, wechseln Sie zu "Datei" > "Öffnen" > "Projekt", und wählen Sie die SLN-Datei aus.
the_stack_data/486302.c
// kernel BUG at fs/f2fs/inode.c:LINE! // https://syzkaller.appspot.com/bug?id=eed3a60015923d6c5c1a // status:0 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <endian.h> #include <errno.h> #include <fcntl.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/mount.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/types.h> #include <unistd.h> #include <linux/loop.h> static unsigned long long procid; struct fs_image_segment { void* data; uintptr_t size; uintptr_t offset; }; #define IMAGE_MAX_SEGMENTS 4096 #define IMAGE_MAX_SIZE (129 << 20) #define sys_memfd_create 319 static unsigned long fs_image_segment_check(unsigned long size, unsigned long nsegs, struct fs_image_segment* segs) { if (nsegs > IMAGE_MAX_SEGMENTS) nsegs = IMAGE_MAX_SEGMENTS; for (size_t i = 0; i < nsegs; i++) { if (segs[i].size > IMAGE_MAX_SIZE) segs[i].size = IMAGE_MAX_SIZE; segs[i].offset %= IMAGE_MAX_SIZE; if (segs[i].offset > IMAGE_MAX_SIZE - segs[i].size) segs[i].offset = IMAGE_MAX_SIZE - segs[i].size; if (size < segs[i].offset + segs[i].offset) size = segs[i].offset + segs[i].offset; } if (size > IMAGE_MAX_SIZE) size = IMAGE_MAX_SIZE; return size; } static int setup_loop_device(long unsigned size, long unsigned nsegs, struct fs_image_segment* segs, const char* loopname, int* memfd_p, int* loopfd_p) { int err = 0, loopfd = -1; size = fs_image_segment_check(size, nsegs, segs); int memfd = syscall(sys_memfd_create, "syzkaller", 0); if (memfd == -1) { err = errno; goto error; } if (ftruncate(memfd, size)) { err = errno; goto error_close_memfd; } for (size_t i = 0; i < nsegs; i++) { if (pwrite(memfd, segs[i].data, segs[i].size, segs[i].offset) < 0) { } } loopfd = open(loopname, O_RDWR); if (loopfd == -1) { err = errno; goto error_close_memfd; } if (ioctl(loopfd, LOOP_SET_FD, memfd)) { if (errno != EBUSY) { err = errno; goto error_close_loop; } ioctl(loopfd, LOOP_CLR_FD, 0); usleep(1000); if (ioctl(loopfd, LOOP_SET_FD, memfd)) { err = errno; goto error_close_loop; } } *memfd_p = memfd; *loopfd_p = loopfd; return 0; error_close_loop: close(loopfd); error_close_memfd: close(memfd); error: errno = err; return -1; } static long syz_mount_image(volatile long fsarg, volatile long dir, volatile unsigned long size, volatile unsigned long nsegs, volatile long segments, volatile long flags, volatile long optsarg) { struct fs_image_segment* segs = (struct fs_image_segment*)segments; int res = -1, err = 0, loopfd = -1, memfd = -1, need_loop_device = !!segs; char* mount_opts = (char*)optsarg; char* target = (char*)dir; char* fs = (char*)fsarg; char* source = NULL; char loopname[64]; if (need_loop_device) { memset(loopname, 0, sizeof(loopname)); snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid); if (setup_loop_device(size, nsegs, segs, loopname, &memfd, &loopfd) == -1) return -1; source = loopname; } mkdir(target, 0777); char opts[256]; memset(opts, 0, sizeof(opts)); if (strlen(mount_opts) > (sizeof(opts) - 32)) { } strncpy(opts, mount_opts, sizeof(opts) - 32); if (strcmp(fs, "iso9660") == 0) { flags |= MS_RDONLY; } else if (strncmp(fs, "ext", 3) == 0) { if (strstr(opts, "errors=panic") || strstr(opts, "errors=remount-ro") == 0) strcat(opts, ",errors=continue"); } else if (strcmp(fs, "xfs") == 0) { strcat(opts, ",nouuid"); } res = mount(source, target, fs, flags, opts); if (res == -1) { err = errno; goto error_clear_loop; } res = open(target, O_RDONLY | O_DIRECTORY); if (res == -1) { err = errno; } error_clear_loop: if (need_loop_device) { ioctl(loopfd, LOOP_CLR_FD, 0); close(loopfd); close(memfd); } errno = err; return res; } int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); memcpy((void*)0x20000000, "f2fs\000", 5); memcpy((void*)0x20000100, "./file0\000", 8); *(uint64_t*)0x20000200 = 0x20010000; memcpy((void*)0x20010000, "\x10\x20\xf5\xf2\x01\x00\x0b\x00\x09\x00\x00\x00\x03\x00\x00\x00\x0c" "\x00\x00\x00\x09\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00" "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x18\x00\x00\x00\x1f\x00\x00" "\x00\x02\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00" "\x18\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00\x06\x00\x00\x00" "\x0a\x00\x00\x00\x0e\x00\x00\x00\x10\x00\x00\x03\x00\x00\x00\x01\x00" "\x00\x00\x02", 105); *(uint64_t*)0x20000208 = 0x69; *(uint64_t*)0x20000210 = 0x400; *(uint64_t*)0x20000218 = 0x20010a00; memcpy((void*)0x20010a00, "\x43\x79\xd5\x27\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x02" "\x00\x00\x00\x00\x00\x00\x00\x0d\x00\x00\x00\x10\x00\x00\x00\x12\x00" "\x00\x00\x17\x00\x00\x00\x16\x00\x00\x00\x15\x00\x00\x00\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14" "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x85\x01\x00\x00" "\x06\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x04" "\x00\x00\x00\x40\x00\x00\x00\x40\x00\x00\x00\xfc\x0f", 166); *(uint64_t*)0x20000220 = 0xa6; *(uint64_t*)0x20000228 = 0x200000; *(uint64_t*)0x20000230 = 0x20010b00; memcpy((void*)0x20010b00, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x29\x64\x03\x9d\x01\x00\x03\x00" "\x00\x00\x00\x03\x00\x00\x00\x00\x3e", 45); *(uint64_t*)0x20000238 = 0x2d; *(uint64_t*)0x20000240 = 0x200fe0; *(uint64_t*)0x20000248 = 0x20010c00; memcpy((void*)0x20010c00, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x06\x00\x17\x00\x00\x00\x01\x0c\x80", 36); *(uint64_t*)0x20000250 = 0x24; *(uint64_t*)0x20000258 = 0x2011e0; *(uint64_t*)0x20000260 = 0x20011600; memcpy((void*)0x20011600, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x43\x79" "\xd5\x27\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x02\x00\x00" "\x00\x00\x00\x00\x00\x0d\x00\x00\x00\x10\x00\x00\x00\x12\x00\x00\x00" "\x17\x00\x00\x00\x16\x00\x00\x00\x15\x00\x00\x00\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00" "\x00\x01\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x01\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x85\x01\x00\x00\x06\x00" "\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x04\x00\x00" "\x00\x40\x00\x00\x00\x40\x00\x00\x00\xfc\x0f", 198); *(uint64_t*)0x20000268 = 0xc6; *(uint64_t*)0x20000270 = 0x204fe0; *(uint64_t*)0x20000278 = 0x20011700; memcpy((void*)0x20011700, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x29\x64\x03\x9d", 32); *(uint64_t*)0x20000280 = 0x20; *(uint64_t*)0x20000288 = 0x205fe0; *(uint64_t*)0x20000290 = 0x200002c0; memcpy((void*)0x200002c0, "\xed\x41\x00\x00\x5c\xf9\x01\x53\x5f\x01\x00\x02\x00\x00\x00\x00\x10" "\xb1\x7a\x86\x52\x8a\xb2\x41\x20\x67\x03\xcf\x4e\xd5\xaa\x0f\x8d\x59" "\x31\xc4\x0e\xb4\xe2\xed\x38\xc6\x3a\x68\x21\x9e\xd0\x74\x83\xf4\x41" "\x2f\x98\xa6\x3d\xfa\x1d\x19\x9e\x23\x3e\x16\x18\x69\xc2\xac\xa5\xea" "\x33\x81\x8b\xdc\x2a\x58\x77\xd3\xb1\xc2\x00\x00\x00\x00\x00\x00\xcc" "\x0c\xa3\x43\x7a\x22\xbc\x69\xa9\xe7\x8b\xfc\xa5\x0c\x36\xff\xff\x07" "\x5c\x77\x63\x51\x14\x62\xfc\xb8\xcb\x91\x9a\x94\x11\x16\x1a\x91\xca" "\x25\xbe\x15\x4e\xd4\x93\xa1\x23\x6c\x05\x0c\x06\xda\xf5\x4c\xb3\xf9" "\xcf\xc9\x00\x79\x7f\x5b\x8c\x1b\x52\x3f\xa3\x4d\xbb\x69\x06\x5b\xa2" "\x43\x3a\x20\x3b\xa8\x0a\x6e\xc7\x16\x01\xd5\x21\x2a\xa4\x0e\xa9\x4d" "\x9e\x1c\xb5\xca\x49\x8e\x9c\xc0\x7a\xa8\x43\x81\xbd\x30\xce\x58\xad" "\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 202); *(uint64_t*)0x20000298 = 0xca; *(uint64_t*)0x200002a0 = 0x3e00000; *(uint64_t*)0x200002a8 = 0x20012300; memcpy((void*)0x20012300, "\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x03", 13); *(uint64_t*)0x200002b0 = 0xd; *(uint64_t*)0x200002b8 = 0x3e00fe0; syz_mount_image(0x20000000, 0x20000100, 0, 8, 0x20000200, 0, 0x200015c0); return 0; }
the_stack_data/389409.c
// PARAM: --set ana.activated[+] "'region'" #include<pthread.h> #include<stdlib.h> #include<stdio.h> struct s { int datum; struct s *next; } *A; void init (struct s *p, int x) { p -> datum = x; p -> next = NULL; } pthread_mutex_t A_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t B_mutex = PTHREAD_MUTEX_INITIALIZER; void *t_fun(void *arg) { struct s *p = malloc(sizeof(struct s)); struct s *t; init(p,7); pthread_mutex_lock(&A_mutex); t = A->next; // NORACE A->next = p; // NORACE p->next = t; // NORACE pthread_mutex_unlock(&A_mutex); return NULL; } int main () { pthread_t t1; struct s *p = malloc(sizeof(struct s)); init(p,9); A = malloc(sizeof(struct s)); init(A,3); A->next = p; pthread_create(&t1, NULL, t_fun, NULL); pthread_mutex_lock(&A_mutex); p = A->next; // NORACE printf("%d\n", p->datum); // NORACE pthread_mutex_unlock(&A_mutex); return 0; }
the_stack_data/760967.c
/* +----------------------------------------------------------------------+ | Yar - Light, concurrent RPC framework | +----------------------------------------------------------------------+ | Copyright (c) 2012-2013 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | | available through the world-wide-web at the following url: | | http://www.php.net/license/3_01.txt | | If you did not receive a copy of the PHP license and are unable to | | obtain it through the world-wide-web, please send a note to | | [email protected] so we can mail you a copy immediately. | +----------------------------------------------------------------------+ | Author: Xinchen Hui <[email protected]> | | Zhenyu Zhang <[email protected]> | +----------------------------------------------------------------------+ */ /* $Id$ */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifdef YAC_ENABLE_MSGPACK #include "php.h" #include "ext/msgpack/php_msgpack.h" #include "zend_smart_str.h" /* for smart_str */ #include "yac_serializer.h" int yac_serializer_msgpack_pack(zval *pzval, smart_str *buf, char **msg) /* {{{ */ { php_msgpack_serialize(buf, pzval); return 1; } /* }}} */ zval * yac_serializer_msgpack_unpack(char *content, size_t len, char **msg, zval *rv) /* {{{ */ { ZVAL_NULL(rv); php_msgpack_unserialize(rv, content, len); return rv; } /* }}} */ #endif /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noet sw=4 ts=4 fdm=marker * vim<600: noet sw=4 ts=4 */
the_stack_data/234518342.c
/* * Discovering Bit operators. */ #include <stddef.h> #include <stdbool.h> #include <stdio.h> #include <stdint.h> #define PRINT_TOPIC(...) \ { \ printf("\n\n" #__VA_ARGS__ "\n"); \ size_t num_separators = sizeof #__VA_ARGS__; \ while (--num_separators) \ putchar('='); \ printf("\n"); \ } /* * Print binary representation of the object. * * obj_mem - address of the object in memory * obj_size - size of the object in bytes. * litte_endian - read memory from last address to first. */ void printBinary(void *obj_mem, size_t obj_size, bool little_endian) { char *byte_mem; int num_bits; if (little_endian) byte_mem = (char *) obj_mem + obj_size - 1; else byte_mem = obj_mem; while (obj_size--) { num_bits = 8; while (num_bits--) putchar('0' + (*byte_mem >> num_bits & 1)); putchar(' '); if (little_endian) byte_mem--; else byte_mem++; } putchar('\n'); } int main(void) { { PRINT_TOPIC(Bitwise operations); uint8_t ui1; int8_t si1; // Set all bits to 1 ui1 = ~0; si1 = ~0; printBinary(&ui1, sizeof ui1, true); printBinary(&si1, sizeof si1, true); // Right shift half of the object. ui1 >>= sizeof ui1 * 4; si1 >>= sizeof si1 * 4;; printBinary(&ui1, sizeof ui1, true); printBinary(&si1, sizeof si1, true); // Precedency for binary operators #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wparentheses" ui1 = 0xAA | // 3) 10101010 | 10011100 = 10111110 0xCC ^ // 2) 11001100 ^ 01010000 = 10011100 0xF0 & // 1)11110000 & 01010101 = 01010000 0x550 >> 4; #pragma GCC diagnostic pop printBinary(&ui1, sizeof ui1, true); } { PRINT_TOPIC(Accessing individual bits); uint8_t ui1 = 0; // Set bit 4 to 1; ui1 |= 1 << 4; printBinary(&ui1, sizeof ui1, true); // Unset bit 4 ui1 &= ~(1 << 4); printBinary(&ui1, sizeof ui1, true); // Toggle bits 0, 3 and 5 ui1 ^= 1 + 8 + 32; printBinary(&ui1, sizeof ui1, true); // Test for bits 0 or 2 if (ui1 & (1 | 4)) printf("bit 0 or 2 is set\n"); // Test for bits 0 and 3 if ((ui1 & (1 | 8)) == (1 | 8)) printf("bits 0 and 3 are set\n"); } { PRINT_TOPIC(Accessing multiple bits); uint8_t ui1 = ~0, j; // Clear 3 bits starting from bit 4 ui1 &= ~(0x7 << 4); printBinary(&ui1, sizeof ui1, true); // Set 3 bits starting from bit 4 ui1 |= 0x7 << 4; printBinary(&ui1, sizeof ui1, true); // toggle 3 bits starting from bit 5 ui1 ^= 0x7 << 5; printBinary(&ui1, sizeof ui1, true); // Modify bits 4-7 to store the value j j = 0xA; ui1 = (ui1 & ~0xF0) | (j << 4); printBinary(&ui1, sizeof ui1, true); // Retreive the value of bits 4-7 of ui1 j = ui1 >> 4 & 0xF; printBinary(&j, sizeof j, true); } { PRINT_TOPIC(Bit Fields and Structures); struct storage { unsigned int a : 5; // 5 bits (from 0 to 31) unsigned int b : 4; unsigned int : 8; // Padding 8 bits signed int c : 7; // 7 bits (from -64 to 63) int : 0; // Break paddind (skip until the end of allocation unit) unsigned int d : 32; // May not work if unsigned int takes less than 32 bits }; struct storage s; // &s.a = illegal operation s.a = 0x11; // 10001 s.b = 0x9; // 1001 s.c = -63; // 1000001 s.d = ~0; // All ones printBinary(&s, sizeof s, true); // Next operations assume Little-Endian storage. unsigned int *field = (void *) &s; // Overwrite s.a to 01110 *field = (*field & ~(0x1f)) | (0xE); // Overwrite s.b to 0110 *field = (*field & ~(0xF << 5)) | (0x6 << 5); // Toggle s.c *field ^= 0x7F << 17; // Switch to the next bit field and toggle it *++field ^= ~0; printBinary(&s, sizeof s, true); } { PRINT_TOPIC(Multiple views of data with unions); typedef unsigned char Byte; typedef uint16_t Word; struct date { Word day : 5, month : 4, year : 7; }; union fast_date{ Word _dt; struct date dt; }; struct date dt = {.day = 0x1, .month = 0x3, .year = 0x7F}; union fast_date fdt = {0xFFFF}; fdt = *(union fast_date *) &dt; printBinary(&dt, sizeof dt, true); printBinary(&fdt, sizeof fdt, true); union { struct { Word ax, bx, cx, dx; } words; struct { Byte al, ah, bl, bh, cl, ch, dl, dh; } bytes; } registers; registers.bytes.al = 0xF7; registers.bytes.ah = 0x7F; printBinary(&registers.words.ax, sizeof registers.words.ax, true); } { PRINT_TOPIC(Volatile Type Qualifier); typedef unsigned char Byte; // p is a pointer to a volatile byte. // Basically informs the compiler // that contents of memory can be easily changed // outside this translation unit volatile Byte *p = (Byte *) 0x100; p += 1; } return 0; }
the_stack_data/151705563.c
/* f2c.h -- Standard Fortran to C header file */ /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ #ifndef F2C_INCLUDE #define F2C_INCLUDE #include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimag(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static integer c__1 = 1; static integer c_n1 = -1; static real c_b32 = -1.f; static real c_b34 = 1.f; /* > \brief \b SGGGLM */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download SGGGLM + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sggglm. f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sggglm. f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sggglm. f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE SGGGLM( N, M, P, A, LDA, B, LDB, D, X, Y, WORK, LWORK, */ /* INFO ) */ /* INTEGER INFO, LDA, LDB, LWORK, M, N, P */ /* REAL A( LDA, * ), B( LDB, * ), D( * ), WORK( * ), */ /* $ X( * ), Y( * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > SGGGLM solves a general Gauss-Markov linear model (GLM) problem: */ /* > */ /* > minimize || y ||_2 subject to d = A*x + B*y */ /* > x */ /* > */ /* > where A is an N-by-M matrix, B is an N-by-P matrix, and d is a */ /* > given N-vector. It is assumed that M <= N <= M+P, and */ /* > */ /* > rank(A) = M and rank( A B ) = N. */ /* > */ /* > Under these assumptions, the constrained equation is always */ /* > consistent, and there is a unique solution x and a minimal 2-norm */ /* > solution y, which is obtained using a generalized QR factorization */ /* > of the matrices (A, B) given by */ /* > */ /* > A = Q*(R), B = Q*T*Z. */ /* > (0) */ /* > */ /* > In particular, if matrix B is square nonsingular, then the problem */ /* > GLM is equivalent to the following weighted linear least squares */ /* > problem */ /* > */ /* > minimize || inv(B)*(d-A*x) ||_2 */ /* > x */ /* > */ /* > where inv(B) denotes the inverse of B. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The number of rows of the matrices A and B. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] M */ /* > \verbatim */ /* > M is INTEGER */ /* > The number of columns of the matrix A. 0 <= M <= N. */ /* > \endverbatim */ /* > */ /* > \param[in] P */ /* > \verbatim */ /* > P is INTEGER */ /* > The number of columns of the matrix B. P >= N-M. */ /* > \endverbatim */ /* > */ /* > \param[in,out] A */ /* > \verbatim */ /* > A is REAL array, dimension (LDA,M) */ /* > On entry, the N-by-M matrix A. */ /* > On exit, the upper triangular part of the array A contains */ /* > the M-by-M upper triangular matrix R. */ /* > \endverbatim */ /* > */ /* > \param[in] LDA */ /* > \verbatim */ /* > LDA is INTEGER */ /* > The leading dimension of the array A. LDA >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[in,out] B */ /* > \verbatim */ /* > B is REAL array, dimension (LDB,P) */ /* > On entry, the N-by-P matrix B. */ /* > On exit, if N <= P, the upper triangle of the subarray */ /* > B(1:N,P-N+1:P) contains the N-by-N upper triangular matrix T; */ /* > if N > P, the elements on and above the (N-P)th subdiagonal */ /* > contain the N-by-P upper trapezoidal matrix T. */ /* > \endverbatim */ /* > */ /* > \param[in] LDB */ /* > \verbatim */ /* > LDB is INTEGER */ /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[in,out] D */ /* > \verbatim */ /* > D is REAL array, dimension (N) */ /* > On entry, D is the left hand side of the GLM equation. */ /* > On exit, D is destroyed. */ /* > \endverbatim */ /* > */ /* > \param[out] X */ /* > \verbatim */ /* > X is REAL array, dimension (M) */ /* > \endverbatim */ /* > */ /* > \param[out] Y */ /* > \verbatim */ /* > Y is REAL array, dimension (P) */ /* > */ /* > On exit, X and Y are the solutions of the GLM problem. */ /* > \endverbatim */ /* > */ /* > \param[out] WORK */ /* > \verbatim */ /* > WORK is REAL array, dimension (MAX(1,LWORK)) */ /* > On exit, if INFO = 0, WORK(1) returns the optimal LWORK. */ /* > \endverbatim */ /* > */ /* > \param[in] LWORK */ /* > \verbatim */ /* > LWORK is INTEGER */ /* > The dimension of the array WORK. LWORK >= f2cmax(1,N+M+P). */ /* > For optimum performance, LWORK >= M+f2cmin(N,P)+f2cmax(N,P)*NB, */ /* > where NB is an upper bound for the optimal blocksizes for */ /* > SGEQRF, SGERQF, SORMQR and SORMRQ. */ /* > */ /* > If LWORK = -1, then a workspace query is assumed; the routine */ /* > only calculates the optimal size of the WORK array, returns */ /* > this value as the first entry of the WORK array, and no error */ /* > message related to LWORK is issued by XERBLA. */ /* > \endverbatim */ /* > */ /* > \param[out] INFO */ /* > \verbatim */ /* > INFO is INTEGER */ /* > = 0: successful exit. */ /* > < 0: if INFO = -i, the i-th argument had an illegal value. */ /* > = 1: the upper triangular factor R associated with A in the */ /* > generalized QR factorization of the pair (A, B) is */ /* > singular, so that rank(A) < M; the least squares */ /* > solution could not be computed. */ /* > = 2: the bottom (N-M) by (N-M) part of the upper trapezoidal */ /* > factor T associated with B in the generalized QR */ /* > factorization of the pair (A, B) is singular, so that */ /* > rank( A B ) < N; the least squares solution could not */ /* > be computed. */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date December 2016 */ /* > \ingroup realOTHEReigen */ /* ===================================================================== */ /* Subroutine */ int sggglm_(integer *n, integer *m, integer *p, real *a, integer *lda, real *b, integer *ldb, real *d__, real *x, real *y, real *work, integer *lwork, integer *info) { /* System generated locals */ integer a_dim1, a_offset, b_dim1, b_offset, i__1, i__2, i__3, i__4; /* Local variables */ integer lopt, i__; extern /* Subroutine */ int sgemv_(char *, integer *, integer *, real *, real *, integer *, real *, integer *, real *, real *, integer *), scopy_(integer *, real *, integer *, real *, integer *); integer nb, np; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); extern integer ilaenv_(integer *, char *, char *, integer *, integer *, integer *, integer *, ftnlen, ftnlen); extern /* Subroutine */ int sggqrf_(integer *, integer *, integer *, real *, integer *, real *, real *, integer *, real *, real *, integer * , integer *); integer lwkmin, nb1, nb2, nb3, nb4, lwkopt; logical lquery; extern /* Subroutine */ int sormqr_(char *, char *, integer *, integer *, integer *, real *, integer *, real *, real *, integer *, real *, integer *, integer *), sormrq_(char *, char *, integer *, integer *, integer *, real *, integer *, real *, real * , integer *, real *, integer *, integer *), strtrs_(char *, char *, char *, integer *, integer *, real *, integer *, real *, integer *, integer *); /* -- LAPACK driver routine (version 3.7.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* December 2016 */ /* =================================================================== */ /* Test the input parameters */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; b_dim1 = *ldb; b_offset = 1 + b_dim1 * 1; b -= b_offset; --d__; --x; --y; --work; /* Function Body */ *info = 0; np = f2cmin(*n,*p); lquery = *lwork == -1; if (*n < 0) { *info = -1; } else if (*m < 0 || *m > *n) { *info = -2; } else if (*p < 0 || *p < *n - *m) { *info = -3; } else if (*lda < f2cmax(1,*n)) { *info = -5; } else if (*ldb < f2cmax(1,*n)) { *info = -7; } /* Calculate workspace */ if (*info == 0) { if (*n == 0) { lwkmin = 1; lwkopt = 1; } else { nb1 = ilaenv_(&c__1, "SGEQRF", " ", n, m, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1); nb2 = ilaenv_(&c__1, "SGERQF", " ", n, m, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1); nb3 = ilaenv_(&c__1, "SORMQR", " ", n, m, p, &c_n1, (ftnlen)6, ( ftnlen)1); nb4 = ilaenv_(&c__1, "SORMRQ", " ", n, m, p, &c_n1, (ftnlen)6, ( ftnlen)1); /* Computing MAX */ i__1 = f2cmax(nb1,nb2), i__1 = f2cmax(i__1,nb3); nb = f2cmax(i__1,nb4); lwkmin = *m + *n + *p; lwkopt = *m + np + f2cmax(*n,*p) * nb; } work[1] = (real) lwkopt; if (*lwork < lwkmin && ! lquery) { *info = -12; } } if (*info != 0) { i__1 = -(*info); xerbla_("SGGGLM", &i__1, (ftnlen)6); return 0; } else if (lquery) { return 0; } /* Quick return if possible */ if (*n == 0) { i__1 = *m; for (i__ = 1; i__ <= i__1; ++i__) { x[i__] = 0.f; } i__1 = *p; for (i__ = 1; i__ <= i__1; ++i__) { y[i__] = 0.f; } return 0; } /* Compute the GQR factorization of matrices A and B: */ /* Q**T*A = ( R11 ) M, Q**T*B*Z**T = ( T11 T12 ) M */ /* ( 0 ) N-M ( 0 T22 ) N-M */ /* M M+P-N N-M */ /* where R11 and T22 are upper triangular, and Q and Z are */ /* orthogonal. */ i__1 = *lwork - *m - np; sggqrf_(n, m, p, &a[a_offset], lda, &work[1], &b[b_offset], ldb, &work[*m + 1], &work[*m + np + 1], &i__1, info); lopt = work[*m + np + 1]; /* Update left-hand-side vector d = Q**T*d = ( d1 ) M */ /* ( d2 ) N-M */ i__1 = f2cmax(1,*n); i__2 = *lwork - *m - np; sormqr_("Left", "Transpose", n, &c__1, m, &a[a_offset], lda, &work[1], & d__[1], &i__1, &work[*m + np + 1], &i__2, info); /* Computing MAX */ i__1 = lopt, i__2 = (integer) work[*m + np + 1]; lopt = f2cmax(i__1,i__2); /* Solve T22*y2 = d2 for y2 */ if (*n > *m) { i__1 = *n - *m; i__2 = *n - *m; strtrs_("Upper", "No transpose", "Non unit", &i__1, &c__1, &b[*m + 1 + (*m + *p - *n + 1) * b_dim1], ldb, &d__[*m + 1], &i__2, info); if (*info > 0) { *info = 1; return 0; } i__1 = *n - *m; scopy_(&i__1, &d__[*m + 1], &c__1, &y[*m + *p - *n + 1], &c__1); } /* Set y1 = 0 */ i__1 = *m + *p - *n; for (i__ = 1; i__ <= i__1; ++i__) { y[i__] = 0.f; /* L10: */ } /* Update d1 = d1 - T12*y2 */ i__1 = *n - *m; sgemv_("No transpose", m, &i__1, &c_b32, &b[(*m + *p - *n + 1) * b_dim1 + 1], ldb, &y[*m + *p - *n + 1], &c__1, &c_b34, &d__[1], &c__1); /* Solve triangular system: R11*x = d1 */ if (*m > 0) { strtrs_("Upper", "No Transpose", "Non unit", m, &c__1, &a[a_offset], lda, &d__[1], m, info); if (*info > 0) { *info = 2; return 0; } /* Copy D to X */ scopy_(m, &d__[1], &c__1, &x[1], &c__1); } /* Backward transformation y = Z**T *y */ /* Computing MAX */ i__1 = 1, i__2 = *n - *p + 1; i__3 = f2cmax(1,*p); i__4 = *lwork - *m - np; sormrq_("Left", "Transpose", p, &c__1, &np, &b[f2cmax(i__1,i__2) + b_dim1], ldb, &work[*m + 1], &y[1], &i__3, &work[*m + np + 1], &i__4, info); /* Computing MAX */ i__1 = lopt, i__2 = (integer) work[*m + np + 1]; work[1] = (real) (*m + np + f2cmax(i__1,i__2)); return 0; /* End of SGGGLM */ } /* sggglm_ */
the_stack_data/7950251.c
/* * Copyright (c) Huawei Technologies Co., Ltd. 2012-2021. All rights reserved. */ struct lookup { const char *l_word; const int l_value; }; static const struct lookup *byword(const char *word, const struct lookup *table) { return 0; }
the_stack_data/1156344.c
#include <stdio.h> int main() { int cont, x = 0; for(cont = 1; cont <= 100; cont++){ x = cont % 2; if(x == 0) printf("%d\n", cont); } return 0; }
the_stack_data/93888828.c
#include <stdlib.h> #include <stdio.h> #include <assert.h> #include <time.h> //bhmr2007.c int main(int argc, char** argv) { srand(time(0)); int unknown_1 = atoi(argv[1]); int unknown_2 = atoi(argv[2]); int i, n, a, b; i = 0; a = 0; b = 0; n = rand()%2 < unknown_1; assert(n >= 0); assert(n <= 1000000); int while_counter_1 = 0; while (while_counter_1 < 50) { printf("%d , %d , %d , %d , %d , %d , %d \n", 1, while_counter_1++, 1, i, n, a, b); if (!(i < n)) break; if (rand()%2 < unknown_2) { a = a + 1; b = b + 2; } else { a = a + 2; b = b + 1; } i = i + 1; } assert(a + b == 3 * n); return 0; }