file
stringlengths
18
26
data
stringlengths
2
1.05M
the_stack_data/149394.c
#include <stdio.h> #include <pthread.h> #include <assert.h> #include <unistd.h> #include <sys/time.h> pthread_cond_t cond1 = PTHREAD_COND_INITIALIZER; pthread_mutex_t mut1 = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond2 = PTHREAD_COND_INITIALIZER; pthread_mutex_t mut2 = PTHREAD_MUTEX_INITIALIZER; int done = 0; int todo = 0; double wtime(void); void* thread1_fn(void* foo); void wakeywakey(void); double wtime(void) { struct timeval t; gettimeofday(&t, NULL); return((double)t.tv_sec + (double)t.tv_usec / 1000000); } void* thread1_fn(void* foo) { int ret = -1; while(1) { pthread_mutex_lock(&mut1); while(todo == 0) { ret = pthread_cond_wait(&cond1, &mut1); assert(ret == 0); } todo = 0; pthread_mutex_unlock(&mut1); pthread_mutex_lock(&mut2); done = 1; pthread_mutex_unlock(&mut2); pthread_cond_signal(&cond2); } } void wakeywakey(void) { int ret = -1; pthread_mutex_lock(&mut1); todo = 1; pthread_mutex_unlock(&mut1); pthread_cond_signal(&cond1); pthread_mutex_lock(&mut2); while(done == 0) { ret = pthread_cond_wait(&cond2, &mut2); assert(ret == 0); } done = 0; pthread_mutex_unlock(&mut2); } #define ITERATIONS 100000 int main(int argc, char **argv) { pthread_t thread1; int ret = -1; int i = 0; double time1, time2; ret = pthread_create(&thread1, NULL, thread1_fn, NULL); assert(ret == 0); time1 = wtime(); for(i=0; i<ITERATIONS; i++) { wakeywakey(); } time2 = wtime(); printf("time for %d iterations: %f seconds.\n", ITERATIONS, (time2-time1)); printf("per iteration: %f\n", (time2-time1)/(double)ITERATIONS); return(0); }
the_stack_data/82950891.c
/* Taxonomy Classification: 0000100000200000000100 */ /* * WRITE/READ 0 write * WHICH BOUND 0 upper * DATA TYPE 0 char * MEMORY LOCATION 0 stack * SCOPE 1 inter-procedural * CONTAINER 0 no * POINTER 0 no * INDEX COMPLEXITY 0 constant * ADDRESS COMPLEXITY 0 constant * LENGTH COMPLEXITY 0 N/A * ADDRESS ALIAS 2 yes, two levels * INDEX ALIAS 0 none * LOCAL CONTROL FLOW 0 none * SECONDARY CONTROL FLOW 0 none * LOOP STRUCTURE 0 no * LOOP COMPLEXITY 0 N/A * ASYNCHRONY 0 no * TAINT 0 no * RUNTIME ENV. DEPENDENCE 0 no * MAGNITUDE 1 1 byte * CONTINUOUS/DISCRETE 0 discrete * SIGNEDNESS 0 no */ /* Copyright 2005 Massachusetts Institute of Technology All rights reserved. Redistribution and use of software in source and binary forms, with or without modification, are permitted provided that the following conditions are met. - Redistributions of source code must retain the above copyright notice, this set of conditions and the disclaimer below. - Redistributions in binary form must reproduce the copyright notice, this set of conditions, and the disclaimer below in the documentation and/or other materials provided with the distribution. - Neither the name of the Massachusetts Institute of Technology nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS". ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ void function2(char * buf) { /* BAD */ buf[10] = 'A'; } void function1(char * buf) { function2(buf); } int main(int argc, char *argv[]) { char buf[10]; function1(buf); return 0; }
the_stack_data/168893063.c
#include <stdio.h> #include <stdlib.h> int main(){ return 0; }
the_stack_data/11076211.c
#include "dialog.h" #if USE_DIALOG #include "wait.h" #include <assert.h> #include <stddef.h> typedef struct { DWORD helpID; DWORD exStyle; DWORD style; short x; short y; short cx; short cy; DWORD id; } DLGITEMTEMPLATEEX0; #define DLG_TYPEFACE L"MS Shell Dlg" struct dlg_template_suffix { WORD pointsize; WORD weight; BYTE italic; BYTE charset; WCHAR typeface[arraysize(DLG_TYPEFACE)]; }; static size_t _size_sz(const WCHAR *s) { return lstrlenW(s) + 1; } static size_t _size_sz_or_ord(const WORD *s) { return *s == 0xffff ? 2 : _size_sz(s); } static void _copy_words(WORD **dst, const WORD **src, size_t size) { memcpy(*dst, *src, size * sizeof(WORD)); *src += size; *dst += size; } static ptrdiff_t _round_dword(ptrdiff_t p) { return (p + sizeof(DWORD) - 1) & ~(sizeof(DWORD) - 1); } dialog dialog_create(LPTSTR template_name) { HRSRC src_res_info; HGLOBAL src_global; DLGTEMPLATE FAR *src_rsrc; DWORD_PTR dst_size; DLGTEMPLATEEX0 *dst_rsrc; src_res_info = FindResource(global_instance, template_name, RT_DIALOG); /* Might as well. */ if(!src_res_info) return (dialog)0; src_global = LoadResource(global_instance, src_res_info); src_rsrc = LockResource(src_global); assert((src_rsrc->style & 0xffff0000) != 0xffff0000); assert(!((ptrdiff_t)src_rsrc & (sizeof(DWORD) - 1))); if(!dialog_using_ex()) { dst_size = SizeofResource(global_instance, src_res_info); } else { const WORD *src = (const void *)(src_rsrc + 1); size_t menu_size, class_size, title_size; WORD cdit = src_rsrc->cdit; menu_size = _size_sz_or_ord(src); src += menu_size; class_size = _size_sz_or_ord(src); src += class_size; title_size = _size_sz(src); src += title_size; if(src_rsrc->style & DS_SETFONT) { src += 1; src += _size_sz(src); } dst_size = sizeof(DLGTEMPLATEEX0) + (menu_size + class_size + title_size) * sizeof(WORD) + sizeof(struct dlg_template_suffix); while(cdit) { size_t create_size; src = (const void *)((const DLGITEMTEMPLATE *)_round_dword((ptrdiff_t)src) + 1); dst_size = _round_dword(dst_size); class_size = _size_sz_or_ord(src); src += class_size; title_size = _size_sz(src); src += title_size; if(!*src) create_size = 0; else create_size = *src - sizeof(WORD); ++src; src = (void *)_round_dword((ptrdiff_t)src + create_size); dst_size += sizeof(DLGITEMTEMPLATEEX0) + (class_size + title_size) * sizeof(WORD) + sizeof(WORD) + create_size; --cdit; } _round_dword(dst_size); } dst_rsrc = HeapAlloc(global_heap, 0, dst_size); if(dst_rsrc) { if(!dialog_using_ex()) { memcpy(dst_rsrc, src_rsrc, dst_size); } else { static const struct dlg_template_suffix suffix0 = { 8, 0, FALSE, DEFAULT_CHARSET, DLG_TYPEFACE }; const WORD *src; struct dlg_template_suffix *dst_suffix; WORD *dst; WORD cdit = src_rsrc->cdit; dst_rsrc->dlgVer = 1; dst_rsrc->signature = 0xffff; dst_rsrc->helpID = 0; dst_rsrc->exStyle = src_rsrc->dwExtendedStyle; dst_rsrc->style = src_rsrc->style | DS_SHELLFONT; dst_rsrc->cDlgItems = cdit; dst_rsrc->x = src_rsrc->x; dst_rsrc->y = src_rsrc->y; dst_rsrc->cx = src_rsrc->cx; dst_rsrc->cy = src_rsrc->cy; src = (const void *)(src_rsrc + 1); dst = (void *)(dst_rsrc + 1); _copy_words(&dst, &src, _size_sz_or_ord(src)); /* menu */ _copy_words(&dst, &src, _size_sz_or_ord(src)); /* windowClass */ _copy_words(&dst, &src, _size_sz(src)); /* title */ dst_suffix = (struct dlg_template_suffix *)dst; *dst_suffix = suffix0; if(src_rsrc->style & DS_SETFONT) { dst_suffix->pointsize = *src; ++src; src += _size_sz(src); } dst = (WORD *)(dst_suffix + 1); while(cdit) { WORD size; DLGITEMTEMPLATEEX0 *dst_item; const DLGITEMTEMPLATE *src_item; /* DLGITEMTEMPLATEs start on a DWORD boundary; they don't necessarily end on one. */ src = (const void *)_round_dword((ptrdiff_t)src); dst = (void *)_round_dword((ptrdiff_t)dst); src_item = (const DLGITEMTEMPLATE *)src; dst_item = (DLGITEMTEMPLATEEX0 *)dst; dst_item->helpID = 0; dst_item->exStyle = src_item->dwExtendedStyle; dst_item->style = src_item->style; dst_item->x = src_item->x; dst_item->y = src_item->y; dst_item->cx = src_item->cx; dst_item->cy = src_item->cy; dst_item->id = (INT)(SHORT)src_item->id; src = (const WORD *)(src_item + 1); dst = (WORD *)(dst_item + 1); _copy_words(&dst, &src, _size_sz_or_ord(src)); /* windowClass */ _copy_words(&dst, &src, _size_sz_or_ord(src)); /* title */ if(!*src) size = 0; else size = *src - sizeof(WORD); ++src; *dst = size; ++dst; memcpy(dst, src, size); src = (const void *)((const BYTE *)src + size); dst = (void *)((BYTE *)dst + size); --cdit; } assert((DWORD_PTR)((BYTE *)src - (BYTE *)src_rsrc) <= SizeofResource(global_instance, src_res_info)); assert((DWORD_PTR)((BYTE *)dst - (BYTE *)dst_rsrc) <= dst_size); } } (void)UnlockResource(src_global); FreeResource(src_global); return dst_rsrc; } #endif
the_stack_data/151705991.c
#include <stdio.h> #define NUM 5 int and (int a, int b); int or (int a, int b); int not(int a); int nand(int a, int b); int nor(int a, int b); int exor(int a, int b); void HA(int a, int b, int *s, int *c); void FA(int a, int b, int pre_c, int *s, int *c); void Add(); int main(void) { int count = 0; static int i = 1;//カウント用の変数 static int c = 1;//カウント番号の桁数 static int num = 0;//カウント番号 while(count<256*1024){ if(i >= 1073741824){//29カウント毎にiの値をリセット i = 1; c = c << 1;//iをリセットした回数を記録 } if(1){//i<1024000){ //ここに繰り返す処理を記述する printf("%d:%d-%d\n",count,c,i); i = i << 1; }else{ break; } } return 0; } /* int a[NUM], b[NUM]; int c[NUM], s[NUM]; a[0] = 1; a[1] = 1; a[2] = 0; a[3] = 0; a[4] = 0; printf("A = "); for (int i = NUM - 1; i >= 0; i--) { printf("%d", a[i]); } printf("\n"); b[0] = 1; b[1] = 0; b[2] = 0; b[3] = 0; b[4] = 0; printf("B = "); for (int i = NUM - 1; i >= 0; i--) { printf("%d", b[i]); } printf("\n"); HA(a[0], b[0], &s[0], &c[0]); printf("HA : s0 = %d , c0 = %d\n", s[0], c[0]); for (int i = 1; i < NUM; i++) { FA(a[i], b[i], c[i - 1], &s[i], &c[i]); printf("FA : s%d = %d , c%d = %d\n", i, s[i], i, c[i]); } printf("\nA+B = "); for (int i = NUM - 1; i >= 0; i--) { printf("%d", s[i]); } printf("\n"); return 0; } int and (int a, int b) { int s = a & b; return s; } int or (int a, int b) { int s = a | b; return s; } int not(int a) { int s; if (a == 1) { s = 0; } else { s = 1; } return s; } int nand(int a, int b) { int s = not(a & b); return s; } int nor(int a, int b) { int s = not(a | b); return s; } int exor(int a, int b) { int s = a ^ b; return s; } void HA(int a, int b, int *s, int *c) { int or1, and1, not1, and2; or1 = or (a, b); and1 = and (a, b); not1 = not(and1); and2 = and (or1, not1); *s = and2; *c = and1; } void FA(int a, int b, int pre_c, int *s, int *c) { int HAs1, HAc1, HAs2, HAc2, or1; HA(a, b, &HAs1, &HAc1); HA(HAs1, pre_c, &HAs2, &HAc2); or1 = or (HAc1, HAc2); *s = HAs2; *c = or1; } void Add(int a[], int b[], int s[], int c) { HA(a[0], b[0], &s[0], &c[0]); printf("HA : s0 = %d , c0 = %d\n", s[0], c[0]); for (int i = 1; i < NUM; i++) { FA(a[i], b[i], c[i - 1], &s[i], &c[i]); printf("FA : s%d = %d , c%d = %d\n", i, s[i], i, c[i]); } printf("\nA+B = "); for (int i = NUM - 1; i >= 0; i--) { printf("%d", s[i]); } printf("\n"); } */
the_stack_data/48394.c
#include <stdio.h> #include <stdlib.h> void main() { char a[69]; printf("%p\n", system+765772); fgets(a, 96, stdin); }
the_stack_data/140625.c
#include <stdio.h> int main() { int c; float f; printf("Temparature in Celsius:\n"); scanf("%d",&c); f = (1.8 * c) + 32; printf("Temparature in Fahrenheit is %0.1fF",f); return 0; }
the_stack_data/237644158.c
// // This file is part of the Bones source-to-source compiler examples. This C-code // demonstrates the use of Bones for an example application: 'nw', taken from // the Rodinia benchmark suite. For more information on the application or on Bones // please use the contact information below. // // == More information on Hotspot // Original code......https://www.cs.virginia.edu/~skadron/wiki/rodinia/ // // == More information on Bones // Contact............Cedric Nugteren <[email protected]> // Web address........http://parse.ele.tue.nl/bones/ // // == File information // Filename...........applications/nw.c // Authors............Cedric Nugteren // Last modified on...01-Jun-2014 // //######################################################################## //### Includes //######################################################################## #include <stdio.h> #include <stdlib.h> #include <math.h> //######################################################################## //### Defines //######################################################################## // Config #define MAX_ROWS (2048+1) #define MAX_COLS (2048+1) #define PENALTY 10 // Reference int blosum62[24][24] = { { 4, -1, -2, -2, 0, -1, -1, 0, -2, -1, -1, -1, -1, -2, -1, 1, 0, -3, -2, 0, -2, -1, 0, -4}, {-1, 5, 0, -2, -3, 1, 0, -2, 0, -3, -2, 2, -1, -3, -2, -1, -1, -3, -2, -3, -1, 0, -1, -4}, {-2, 0, 6, 1, -3, 0, 0, 0, 1, -3, -3, 0, -2, -3, -2, 1, 0, -4, -2, -3, 3, 0, -1, -4}, {-2, -2, 1, 6, -3, 0, 2, -1, -1, -3, -4, -1, -3, -3, -1, 0, -1, -4, -3, -3, 4, 1, -1, -4}, { 0, -3, -3, -3, 9, -3, -4, -3, -3, -1, -1, -3, -1, -2, -3, -1, -1, -2, -2, -1, -3, -3, -2, -4}, {-1, 1, 0, 0, -3, 5, 2, -2, 0, -3, -2, 1, 0, -3, -1, 0, -1, -2, -1, -2, 0, 3, -1, -4}, {-1, 0, 0, 2, -4, 2, 5, -2, 0, -3, -3, 1, -2, -3, -1, 0, -1, -3, -2, -2, 1, 4, -1, -4}, { 0, -2, 0, -1, -3, -2, -2, 6, -2, -4, -4, -2, -3, -3, -2, 0, -2, -2, -3, -3, -1, -2, -1, -4}, {-2, 0, 1, -1, -3, 0, 0, -2, 8, -3, -3, -1, -2, -1, -2, -1, -2, -2, 2, -3, 0, 0, -1, -4}, {-1, -3, -3, -3, -1, -3, -3, -4, -3, 4, 2, -3, 1, 0, -3, -2, -1, -3, -1, 3, -3, -3, -1, -4}, {-1, -2, -3, -4, -1, -2, -3, -4, -3, 2, 4, -2, 2, 0, -3, -2, -1, -2, -1, 1, -4, -3, -1, -4}, {-1, 2, 0, -1, -3, 1, 1, -2, -1, -3, -2, 5, -1, -3, -1, 0, -1, -3, -2, -2, 0, 1, -1, -4}, {-1, -1, -2, -3, -1, 0, -2, -3, -2, 1, 2, -1, 5, 0, -2, -1, -1, -1, -1, 1, -3, -1, -1, -4}, {-2, -3, -3, -3, -2, -3, -3, -3, -1, 0, 0, -3, 0, 6, -4, -2, -2, 1, 3, -1, -3, -3, -1, -4}, {-1, -2, -2, -1, -3, -1, -1, -2, -2, -3, -3, -1, -2, -4, 7, -1, -1, -4, -3, -2, -2, -1, -2, -4}, { 1, -1, 1, 0, -1, 0, 0, 0, -1, -2, -2, 0, -1, -2, -1, 4, 1, -3, -2, -2, 0, 0, 0, -4}, { 0, -1, 0, -1, -1, -1, -1, -2, -2, -1, -1, -1, -1, -2, -1, 1, 5, -2, -2, 0, -1, -1, 0, -4}, {-3, -3, -4, -4, -2, -2, -3, -2, -2, -3, -2, -3, -1, 1, -4, -3, -2, 11, 2, -3, -4, -3, -2, -4}, {-2, -2, -2, -3, -2, -1, -2, -3, 2, -1, -1, -2, -1, 3, -3, -2, -2, 2, 7, -1, -3, -2, -1, -4}, { 0, -3, -3, -3, -1, -2, -2, -3, -3, 3, 1, -2, 1, -1, -2, -2, 0, -3, -1, 4, -3, -2, -1, -4}, {-2, -1, 3, 4, -3, 0, 1, -1, 0, -3, -4, 0, -3, -3, -2, 0, -1, -4, -3, -3, 4, 1, -1, -4}, {-1, 0, 0, 1, -3, 3, 4, -2, 0, -3, -3, 1, -1, -3, -1, 0, -1, -3, -2, -2, 1, 4, -1, -4}, { 0, -1, -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, 0, 0, -2, -1, -1, -1, -1, -1, -4}, {-4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, -4, 1} }; //######################################################################## //### Start of the main function //######################################################################## int main(void) { printf("[nw] Start Needleman-Wunsch\n"); // Arrays int similarity[MAX_ROWS][MAX_COLS]; int items[MAX_ROWS][MAX_COLS]; // Initialize random input data srand (7); for (int i=0; i<MAX_ROWS; i++) { for (int j=0; j<MAX_COLS; j++) { items[i][j] = 0; } } for (int i=1; i<MAX_ROWS; i++) { items[i][0] = rand()%10 + 1; } for (int j=1; j<MAX_COLS; j++) { items[0][j] = rand()%10 + 1; } // Initialize reference for (int i=0; i<MAX_ROWS; i++) { for (int j=0; j<MAX_COLS; j++) { similarity[i][j] = blosum62[items[i][0]][items[0][j]]; } } // Update input with penalty for (int i=1; i<MAX_ROWS; i++) { items[i][0] = -i*PENALTY; } for (int j=1; j<MAX_COLS; j++) { items[0][j] = -j*PENALTY; } // Start of computation #pragma scop // Compute top-left matrix for (int i=0; i<MAX_ROWS-2; i++) { for (int idx=0; idx <= i; idx++) { int a = items[idx+0][i+0-idx] + similarity[idx+1][i+1-idx]; int b = items[idx+1][i+0-idx] - PENALTY; int c = items[idx+0][i+1-idx] - PENALTY; int max_val = a; if (b > max_val) { max_val = b; } if (c > max_val) { max_val = c; } items[idx+1][i+1-idx] = max_val; } } // Compute bottom-right matrix for (int i=MAX_ROWS-4; i>=0; i--) { for (int idx=0; idx <= i; idx++) { int a = items[MAX_ROWS-idx-3][idx+MAX_COLS-i-3] + similarity[MAX_ROWS-idx-2][idx+MAX_COLS-i-2]; int b = items[MAX_ROWS-idx-2][idx+MAX_COLS-i-3] - PENALTY; int c = items[MAX_ROWS-idx-3][idx+MAX_COLS-i-2] - PENALTY; int max_val = a; if (b > max_val) { max_val = b; } if (c > max_val) { max_val = c; } items[MAX_ROWS-idx-2][idx+MAX_COLS-i-2] = max_val; } } // End of computation #pragma endscop // Clean-up and exit printf("\n[nw] Completed\n\n"); fflush(stdout); fflush(stdout); return 0; } //########################################################################
the_stack_data/71616.c
#include <stdio.h> int main(int argc, char *argv[]) { int *ptr = NULL; printf("Address: %p", ptr); printf("Value: %d", *ptr); return 0; }
the_stack_data/56150.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 'mul_hi_long4long4.cl' */ source_code = read_buffer("mul_hi_long4long4.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, "mul_hi_long4long4", &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_long4 *src_0_host_buffer; src_0_host_buffer = malloc(num_elem * sizeof(cl_long4)); for (int i = 0; i < num_elem; i++) src_0_host_buffer[i] = (cl_long4){{2, 2, 2, 2}}; /* Create and init device side src buffer 0 */ cl_mem src_0_device_buffer; src_0_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_long4), 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_long4), 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_long4 *src_1_host_buffer; src_1_host_buffer = malloc(num_elem * sizeof(cl_long4)); for (int i = 0; i < num_elem; i++) src_1_host_buffer[i] = (cl_long4){{2, 2, 2, 2}}; /* Create and init device side src buffer 1 */ cl_mem src_1_device_buffer; src_1_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_long4), 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_long4), 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_long4 *dst_host_buffer; dst_host_buffer = malloc(num_elem * sizeof(cl_long4)); memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_long4)); /* Create device dst buffer */ cl_mem dst_device_buffer; dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_long4), 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_long4), 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_long4)); 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/198569.c
#include <stdint.h> #include <stdatomic.h> void atomic_write16(const uint16_t *ptr, uint16_t val) { atomic_store((_Atomic uint16_t*)ptr, val); }
the_stack_data/100139769.c
/*@ begin PerfTuning ( def build { arg build_command = 'gcc -O3 -fopenmp -DDYNAMIC'; arg libs = '-lm -lrt'; } def performance_counter { arg repetitions = 10; } def performance_params { # Cache tiling param T2_I[] = [1,16,32,64,128,256,512]; param T2_J[] = [1,16,32,64,128,256,512]; param T2_Ia[] = [1,64,128,256,512,1024,2048]; param T2_Ja[] = [1,64,128,256,512,1024,2048]; param T4_I[] = [1,16,32,64,128,256,512]; param T4_J[] = [1,16,32,64,128,256,512]; param T4_Ia[] = [1,64,128,256,512,1024,2048]; param T4_Ja[] = [1,64,128,256,512,1024,2048]; # Unroll-jam param U1_I[] = [1]+range(2,17,2); param U2_I[] = [1]; param U2_J[] = [1]+range(2,17,2); param U3_I[] = [1]+range(2,17,2); param U4_I[] = [1]+range(2,17,2); param U4_J[] = [1]+range(2,17,2); # Scalar replacement # Vectorization # Parallelization # Constraints constraint tileI2 = ((T2_Ia == 1) or (T2_Ia % T2_I == 0)); constraint tileJ2 = ((T2_Ja == 1) or (T2_Ja % T2_J == 0)); constraint tileI4 = ((T4_Ia == 1) or (T4_Ia % T4_I == 0)); constraint tileJ4 = ((T4_Ja == 1) or (T4_Ja % T4_J == 0)); constraint unroll_limit_2 = (U2_I == 1) or (U2_J == 1); constraint unroll_limit_4 = (U4_I == 1) or (U4_J == 1); } def search { arg algorithm = 'Randomlocal'; arg total_runs = 1000; } def input_params { param N[] = [10000]; } def input_vars { arg decl_file = 'decl.h'; arg init_file = 'init.c'; } ) @*/ #define max(x,y) ((x) > (y)? (x) : (y)) #define min(x,y) ((x) < (y)? (x) : (y)) int i,j, k,t; int it, jt, kt; int ii, jj, kk; int iii, jjj, kkk; /*@ begin Loop( transform Composite( unrolljam = (['i'],[U1_I]) ) for (i=0;i<=n-1;i++) { x[i]=0; w[i]=0; } transform Composite( tile = [('j',T2_J,'jj'),('i',T2_I,'ii'), (('jj','j'),T2_Ja,'jjj'),(('ii','i'),T2_Ia,'iii')], unrolljam = (['j','i'],[U2_J,U2_I]) ) for (j=0;j<=n-1;j++) { for (i=0;i<=n-1;i++) { B[j*n+i]=u2[j]*v2[i]+u1[j]*v1[i]+A[j*n+i]; x[i]=y[j]*B[j*n+i]+x[i]; } } transform Composite( unrolljam = (['i'],[U3_I]) ) for (i=0;i<=n-1;i++) { x[i]=b*x[i]+z[i]; } transform Composite( tile = [('i',T4_I,'ii'),('j',T4_J,'jj'), (('ii','i'),T4_Ia,'iii'),(('jj','j'),T4_Ja,'jjj')], unrolljam = (['i','j'],[U4_J,U4_I]) ) for (i = 0; i <= n-1; i++) { for (j = 0; j <= n-1; j++) { w[i] = w[i] + B[i*n+j]*x[j]; } w[i] = a*w[i]; } ) @*/ /*@ end @*/ /*@ end @*/
the_stack_data/91350.c
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <omp.h> #define MXITER 1000 #define NPOINTS 2048 typedef struct { double r; double i; }d_complex; // return 1 if c is outside the mandelbrot set // reutrn 0 if c is inside the mandelbrot set int testpoint(d_complex c){ d_complex z; int iter; double temp; z = c; for(iter=0; iter<MXITER; iter++){ temp = (z.r*z.r) - (z.i*z.i) + c.r; z.i = z.r*z.i*2. + c.i; z.r = temp; if((z.r*z.r+z.i*z.i)>4.0){ return 1; } } return 0; } int mandeloutside(){ int i,j; double eps = 1e-5; d_complex c; int numoutside = 0; #pragma omp parallel for reduction(+:numoutside) private(j,c) for(i=0;i<NPOINTS;i++){ for(j=0;j<NPOINTS;j++){ c.r = -2. + 2.5*(double)(i)/(double)(NPOINTS)+eps; c.i = 1.125*(double)(j)/(double)(NPOINTS)+eps; numoutside += testpoint(c); } } return numoutside; } int main(int argc, char **argv){ double start = omp_get_wtime(); double numoutside = mandeloutside(); double end = omp_get_wtime(); printf("elapsed = %g\n", end-start); double area = 2.*2.5*1.125*(NPOINTS*NPOINTS-numoutside)/(NPOINTS*NPOINTS); printf("area = %17.15lf\n", area); return 0; }
the_stack_data/437576.c
/* Name - BufferOverflowDemo.C Date - 1/1/2010 Programmer - R. R. Brooks Purpose - Show very simple buffer overflow and how to get it working using emacs/gdb. Input - Input a string. Output - Some statements allowing students to see what is going wrong. */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> void InputStringNoCheck(void) { char buffer[]={'@','@','@','@','@','\x00'}; int input; int i=0; printf("Buffer= %s\n",buffer); input=getchar(); while(input != (int)'\n'){ printf("input=%c, binary=%x, i=%d\n",input,input,i); buffer[i++]=input; printf("Buffer= %s\n",buffer); input=getchar(); } buffer[i]=0; printf("Buffer= %s\n",buffer); } void recursion(int i) { if(i>0){ printf("recurse=%d\n",i); recursion(i-1); printf("recurse=%d\n",i); }else{ InputStringNoCheck(); } } int main(int argc, char **argv) { int recurse=6; printf("Before recursion\n"); recursion(recurse); printf("After recursion\n"); return(1); }
the_stack_data/103265981.c
#include <stdio.h> int fun(void); int fun(void) { return 2 * 5; } int main(void) { printf("\tThe function returns: %d\n", fun()); return 0; }
the_stack_data/206393116.c
//C program to find sum of first 100 natural numbers. #include <stdio.h> int main() { int i, sum = 0; for (i = 1; i <= 100; i++) { sum = sum + i; } printf("Sum of first 100 natural numbers=%d", sum); }
the_stack_data/18888597.c
/* * Copyright © 2009 CNRS * Copyright © 2009-2017 Inria. All rights reserved. * Copyright © 2009-2010 Université Bordeaux * Copyright © 2011 Cisco Systems, Inc. All rights reserved. * See COPYING in top-level directory. */ #include "hwloc.h" #include <stdlib.h> #include <stdio.h> #include <string.h> #include <assert.h> int main(void) { hwloc_topology_t topology, topology2, reload; hwloc_obj_t obj; hwloc_bitmap_t set; char *buf1, *buf2; int buflen1, buflen2, err; hwloc_topology_diff_t diff; /* build and annotate a topology */ err = hwloc_topology_init(&topology); assert(!err); err = hwloc_topology_set_synthetic(topology, "NUMA:2 pack:2 core:2 pu:2"); assert(!err); err = hwloc_topology_set_type_filter(topology, HWLOC_OBJ_MISC, HWLOC_TYPE_FILTER_KEEP_ALL); assert(!err); err = hwloc_topology_load(topology); assert(!err); hwloc_topology_check(topology); /* Misc below root */ obj = hwloc_get_root_obj(topology); obj = hwloc_topology_insert_misc_object(topology, obj, "below root"); assert(obj); /* Misc below previous Misc */ obj = hwloc_topology_insert_misc_object(topology, obj, "below Misc below root"); assert(obj); /* Misc below last NUMA node */ obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_NUMANODE, 1); assert(obj); obj = hwloc_topology_insert_misc_object(topology, obj, "below last NUMA"); assert(obj); /* Misc below last Package */ obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PACKAGE, 3); assert(obj); obj = hwloc_topology_insert_misc_object(topology, obj, "below last Package"); assert(obj); /* Misc below last Core */ obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_CORE, 7); assert(obj); obj = hwloc_topology_insert_misc_object(topology, obj, "below last Core"); assert(obj); /* Misc below first PU */ obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PU, 0); assert(obj); obj = hwloc_topology_insert_misc_object(topology, obj, "below first PU"); assert(obj); hwloc_topology_check(topology); /* restrict it to only 3 Packages node without dropping Misc objects */ set = hwloc_bitmap_dup(hwloc_topology_get_topology_cpuset(topology)); obj = hwloc_get_obj_by_type(topology, HWLOC_OBJ_PACKAGE, 3); assert(obj); hwloc_bitmap_andnot(set, set, obj->cpuset); err = hwloc_topology_restrict(topology, set, HWLOC_RESTRICT_FLAG_ADAPT_MISC); assert(!err); hwloc_topology_check(topology); /* check that export/reimport/export gives same export buffer */ err = hwloc_topology_export_xmlbuffer(topology, &buf1, &buflen1, 0); assert(!err); err = hwloc_topology_init(&reload); assert(!err); err = hwloc_topology_set_xmlbuffer(reload, buf1, buflen1); assert(!err); err = hwloc_topology_set_type_filter(reload, HWLOC_OBJ_MISC, HWLOC_TYPE_FILTER_KEEP_ALL); assert(!err); err = hwloc_topology_load(reload); assert(!err); hwloc_topology_check(reload); err = hwloc_topology_export_xmlbuffer(reload, &buf2, &buflen2, 0); assert(!err); assert(buflen1 == buflen2); err = strcmp(buf1, buf2); assert(!err); hwloc_free_xmlbuffer(reload, buf2); hwloc_topology_destroy(reload); /* build another restricted topology manually without Packages */ err = hwloc_topology_init(&topology2); assert(!err); err = hwloc_topology_set_synthetic(topology2, "NUMA:2 pack:2 core:2 pu:2"); /* must keep the same topology string to avoid SyntheticDescription info difference */ assert(!err); err = hwloc_topology_set_type_filter(topology2, HWLOC_OBJ_PACKAGE, HWLOC_TYPE_FILTER_KEEP_NONE); assert(!err); err = hwloc_topology_set_type_filter(topology2, HWLOC_OBJ_MISC, HWLOC_TYPE_FILTER_KEEP_ALL); assert(!err); err = hwloc_topology_load(topology2); assert(!err); hwloc_topology_check(topology2); err = hwloc_topology_restrict(topology2, set, HWLOC_RESTRICT_FLAG_ADAPT_MISC); assert(!err); /* reimport without Packages and Misc, and check they are equal */ err = hwloc_topology_init(&reload); assert(!err); err = hwloc_topology_set_xmlbuffer(reload, buf1, buflen1); assert(!err); err = hwloc_topology_set_type_filter(reload, HWLOC_OBJ_PACKAGE, HWLOC_TYPE_FILTER_KEEP_NONE); assert(!err); err = hwloc_topology_load(reload); assert(!err); err = hwloc_topology_diff_build(reload, topology2, 0, &diff); assert(!err); assert(!diff); hwloc_topology_destroy(reload); /* re-add some Misc now */ /* Misc below root */ obj = hwloc_get_root_obj(topology2); obj = hwloc_topology_insert_misc_object(topology2, obj, "below root"); assert(obj); /* Misc below previous Misc */ obj = hwloc_topology_insert_misc_object(topology2, obj, "below Misc below root"); assert(obj); /* Misc below last NUMA node */ obj = hwloc_get_obj_by_type(topology2, HWLOC_OBJ_NUMANODE, 1); assert(obj); hwloc_topology_insert_misc_object(topology2, obj, "below last NUMA"); /* Misc below parent Group of this NUMA node (where Package and Core Misc will end up) */ assert(obj->parent->type == HWLOC_OBJ_GROUP); hwloc_topology_insert_misc_object(topology2, obj->parent, "below last Package"); hwloc_topology_insert_misc_object(topology2, obj->parent, "below last Core"); assert(obj); /* Misc below first PU */ obj = hwloc_get_obj_by_type(topology2, HWLOC_OBJ_PU, 0); assert(obj); obj = hwloc_topology_insert_misc_object(topology2, obj, "below first PU"); assert(obj); /* reimport without Packages and check they are equal*/ err = hwloc_topology_init(&reload); assert(!err); err = hwloc_topology_set_xmlbuffer(reload, buf1, buflen1); assert(!err); err = hwloc_topology_set_type_filter(reload, HWLOC_OBJ_PACKAGE, HWLOC_TYPE_FILTER_KEEP_NONE); assert(!err); err = hwloc_topology_set_type_filter(reload, HWLOC_OBJ_MISC, HWLOC_TYPE_FILTER_KEEP_ALL); assert(!err); err = hwloc_topology_load(reload); assert(!err); err = hwloc_topology_diff_build(reload, topology2, 0, &diff); assert(!err); assert(!diff); hwloc_topology_destroy(reload); hwloc_free_xmlbuffer(topology, buf1); hwloc_topology_destroy(topology); hwloc_topology_destroy(topology2); hwloc_bitmap_free(set); return 0; }
the_stack_data/28261635.c
/** * Copyright 2020 Huawei Technologies Co., Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifdef ENABLE_SSE #include <x86intrin.h> #include "nnacl/pack.h" #include "nnacl/int8/conv_int8.h" void PackNHWCToNCHWFp32(const void *src, void *dst, int batches, int plane, int channel) { int hw8 = plane / C8NUM * C8NUM; int c8 = channel / C8NUM * C8NUM; int batch = plane * channel; for (int n = 0; n < batches; n++) { const float *src_batch = (const float *)src + n * batch; float *dst_batch = (float *)dst + n * batch; int hw = 0; for (; hw < hw8; hw += C8NUM) { int c = 0; for (; c < c8; c += C8NUM) { const float *src_ptr = src_batch + hw * channel + c; float *dst_ptr = dst_batch + c * plane + hw; // 11-14 __m128 v0_ma = _mm_loadu_ps(src_ptr); __m128 v1_ma = _mm_loadu_ps(src_ptr + channel); __m128 v2_ma = _mm_loadu_ps(src_ptr + 2 * channel); __m128 v3_ma = _mm_loadu_ps(src_ptr + 3 * channel); __m128 v4_ma = _mm_unpacklo_ps(v0_ma, v1_ma); __m128 v5_ma = _mm_unpackhi_ps(v0_ma, v1_ma); __m128 v6_ma = _mm_unpacklo_ps(v2_ma, v3_ma); __m128 v7_ma = _mm_unpackhi_ps(v2_ma, v3_ma); __m128 v8_ma = _mm_movelh_ps(v4_ma, v6_ma); __m128 v9_ma = _mm_movehl_ps(v6_ma, v4_ma); __m128 v10_ma = _mm_movelh_ps(v5_ma, v7_ma); __m128 v11_ma = _mm_movehl_ps(v7_ma, v5_ma); _mm_storeu_ps(dst_ptr, v8_ma); _mm_storeu_ps(dst_ptr + plane, v9_ma); _mm_storeu_ps(dst_ptr + 2 * plane, v10_ma); _mm_storeu_ps(dst_ptr + 3 * plane, v11_ma); // 15-18 v0_ma = _mm_loadu_ps(src_ptr + C4NUM); v1_ma = _mm_loadu_ps(src_ptr + channel + C4NUM); v2_ma = _mm_loadu_ps(src_ptr + 2 * channel + C4NUM); v3_ma = _mm_loadu_ps(src_ptr + 3 * channel + C4NUM); v4_ma = _mm_unpacklo_ps(v0_ma, v1_ma); v5_ma = _mm_unpackhi_ps(v0_ma, v1_ma); v6_ma = _mm_unpacklo_ps(v2_ma, v3_ma); v7_ma = _mm_unpackhi_ps(v2_ma, v3_ma); v8_ma = _mm_movelh_ps(v4_ma, v6_ma); v9_ma = _mm_movehl_ps(v6_ma, v4_ma); v10_ma = _mm_movelh_ps(v5_ma, v7_ma); v11_ma = _mm_movehl_ps(v7_ma, v5_ma); _mm_storeu_ps(dst_ptr + C4NUM * plane, v8_ma); _mm_storeu_ps(dst_ptr + (C4NUM + 1) * plane, v9_ma); _mm_storeu_ps(dst_ptr + (C4NUM + 2) * plane, v10_ma); _mm_storeu_ps(dst_ptr + (C4NUM + 3) * plane, v11_ma); // 21-24 v0_ma = _mm_loadu_ps(src_ptr + C4NUM * channel); v1_ma = _mm_loadu_ps(src_ptr + (C4NUM + 1) * channel); v2_ma = _mm_loadu_ps(src_ptr + (C4NUM + 2) * channel); v3_ma = _mm_loadu_ps(src_ptr + (C4NUM + 3) * channel); v4_ma = _mm_unpacklo_ps(v0_ma, v1_ma); v5_ma = _mm_unpackhi_ps(v0_ma, v1_ma); v6_ma = _mm_unpacklo_ps(v2_ma, v3_ma); v7_ma = _mm_unpackhi_ps(v2_ma, v3_ma); v8_ma = _mm_movelh_ps(v4_ma, v6_ma); v9_ma = _mm_movehl_ps(v6_ma, v4_ma); v10_ma = _mm_movelh_ps(v5_ma, v7_ma); v11_ma = _mm_movehl_ps(v7_ma, v5_ma); _mm_storeu_ps(dst_ptr + C4NUM, v8_ma); _mm_storeu_ps(dst_ptr + plane + C4NUM, v9_ma); _mm_storeu_ps(dst_ptr + 2 * plane + C4NUM, v10_ma); _mm_storeu_ps(dst_ptr + 3 * plane + C4NUM, v11_ma); // 25-28 v0_ma = _mm_loadu_ps(src_ptr + C4NUM * channel + C4NUM); v1_ma = _mm_loadu_ps(src_ptr + (C4NUM + 1) * channel + C4NUM); v2_ma = _mm_loadu_ps(src_ptr + (C4NUM + 2) * channel + C4NUM); v3_ma = _mm_loadu_ps(src_ptr + (C4NUM + 3) * channel + C4NUM); v4_ma = _mm_unpacklo_ps(v0_ma, v1_ma); v5_ma = _mm_unpackhi_ps(v0_ma, v1_ma); v6_ma = _mm_unpacklo_ps(v2_ma, v3_ma); v7_ma = _mm_unpackhi_ps(v2_ma, v3_ma); v8_ma = _mm_movelh_ps(v4_ma, v6_ma); v9_ma = _mm_movehl_ps(v6_ma, v4_ma); v10_ma = _mm_movelh_ps(v5_ma, v7_ma); v11_ma = _mm_movehl_ps(v7_ma, v5_ma); _mm_storeu_ps(dst_ptr + C4NUM * plane + C4NUM, v8_ma); _mm_storeu_ps(dst_ptr + (C4NUM + 1) * plane + C4NUM, v9_ma); _mm_storeu_ps(dst_ptr + (C4NUM + 2) * plane + C4NUM, v10_ma); _mm_storeu_ps(dst_ptr + (C4NUM + 3) * plane + C4NUM, v11_ma); } for (; c < channel; c++) { const float *src_ptr = src_batch + hw * channel + c; float *dst_ptr = dst_batch + c * plane + hw; for (size_t i = 0; i < C8NUM; i++) { dst_ptr[i] = src_ptr[i * channel]; } } } for (; hw < plane; hw++) { const float *src_ptr = src_batch + hw * channel; float *dst_ptr = dst_batch + hw; for (size_t i = 0; i < channel; i++) { dst_ptr[i * plane] = src_ptr[i]; } } } return; } #endif
the_stack_data/200142327.c
#include <stdio.h> #include <string.h> #define MAXARRSIZE 400 char *find(char *,char ); int main() { int result; char input_array[MAXARRSIZE], searched; fgets(input_array, MAXARRSIZE + 1, stdin); scanf("%c",&searched); if(find(input_array, searched) != NULL) { result = find(input_array, searched) - input_array; printf("%d",result); } else printf("-1"); return 0; } char *find(char *haystack,char needle) { int i; char *ptr = NULL; for(i = 0;i < strlen(haystack); i++) { if(needle == haystack[i]) { ptr = &haystack[i]; break; } } return ptr; }
the_stack_data/36076075.c
// SPDX-License-Identifier: zlib-acknowledgement //#include <printf.h> // //void //asterix_name(char buf[], char *name) //{ // sprintf(buf, "***** %s *****", name); //} int add_int(int x, int y) { return x + y; } int sub_int(int x, int y) { return x - y; }
the_stack_data/45449017.c
#include <stdio.h> int main() { struct car { char maker[15]; char model[15]; char registration[20]; int antiquity; long int mileage; float purchase_price; } mycar; printf("Insert maker: "); scanf("%s", mycar.maker); printf("Insert model: "); scanf("%s", mycar.model); printf("Insert registration: "); scanf("%s", mycar.registration); printf("Insert antiquity: "); scanf("%d", &mycar.antiquity); printf("Insert mileage: "); scanf("%ld", &mycar.mileage); printf("Insert purchase price: "); scanf("%f", &mycar.purchase_price); printf("\n\n\n"); printf("A %s %s de %d, with registration number #%s\n", mycar.maker, mycar.model, mycar.antiquity, mycar.registration); printf("actually with %ld mileage and it was bought by $%5.2f", mycar.mileage, mycar.purchase_price); return 0; }
the_stack_data/135078.c
#include <stdio.h> int main(int argc, char* argv[]) { printf("CHILD PROCESS %s EXEC PROGRAM %s\n", argv[1], argv[0]); printf("Hello, world!\n"); printf("I am a task that is executed using exec\n"); printf("CHILD PROCESS %s COMPLETE EXEC PROGRAM %s\n", argv[1], argv[0]); printf("\n"); return 0; }
the_stack_data/218892951.c
#include<stdio.h> int main() { float x='a'; printf("%f",x); return 0; }
the_stack_data/50138927.c
/* BE SMART AND JUST DO THIS WITH LINKED LISTS..... I WAS BORED AND WANTED OT TRY SOMETHING OUT. YOU HAVE BEEN WARNED */ #include <stdio.h> #include<string.h> struct State { char name[10]; char Transitions[10][50]; int Epsilons[10]; int EpsTop; }S[10]; void main() { int EpsilonClosure[10]; char Trans[50]=""; int Stack[10]; int Visited[10]; int N,m,i,j,k,l,d=0,done,E=0,top=0,Vcount=0,VFlag,OldE; printf("Enter The Number of States:"); scanf("%d",&N); printf("Enter Names of States:\n"); //Get the name for(i=0;i<N;i++) { scanf("%s",&S[i].name); } //Enter Transitions for(i=0;i<N;i++) { printf("Enter Transitions for state %s\n",S[i].name); for (j=0;j<N;j++) { //Entering Name : Transitions printf("to %s : ",S[j].name); scanf("%s",S[i].Transitions[j]); } } // Strip the string Also /* This Area below is for the sole purpose of understanding the input. It searches the Transitions and finds the "e" transition. All the searching is done directly below. Once found it adds that index to the Epsilons array of the object and it also sets the EspsTop to top of stack. */ for(i=0;i<N;i++) { //Selecting the State top=0; for(j=0;j<N;j++) { // Selecting from list of Strings strcpy(Trans,S[i].Transitions[j]); // printf("checking %s:\n",Trans); for (k=0;Trans[k]!='\0';k++) { // Going Element by Element // Yes , I am Aware of this mistake below if(Trans[k]==','|| Trans[k]==' ') continue; if(Trans[k]=='e' && (Trans[k+1]=='\0' || Trans[k+1]==',')) { //Check if Visited VFlag = 0; if(Vcount ==0) { Stack[top++]=j; Visited[Vcount]=j; Vcount++; // printf("\nfreebie\n"); } else { for(l=0;l<Vcount;l++) { if (j == Visited[l]) VFlag=1; } if (VFlag == 0) { //printf("Added %d to Stack\n",j); Visited[Vcount] = j; Vcount++; Stack[top++] = j; } // else // { // printf("Already found in Stack\n"); // } } } } } printf("%s has Epsilons to:\n",S[i].name); for(l=0;l<top;l++) { printf("\t%s\n",S[Stack[l]].name); S[i].Epsilons[l]=Stack[l]; } S[i].EpsTop=top; top=0; Vcount=0; } /* Prints the entire table */ // Testing for(i=0;i<N;i++) { printf("\t%s",S[i].name); } printf("\n"); for(i=0;i<N;i++) { printf("\n%s\t",S[i].name); for(j=0;j<N;j++) { printf("%s\t",S[i].Transitions[j]); } printf("Epsilon Count :: %d\n",S[i].EpsTop); } //Getting CLosure for(i=0;i<N;i++) { /* Fill the Closure with -1 And pick the starting State have a counter to indicate index in the EpsilonClosure Array Compare elements of States epsilons with the EpsilonClosure array: if not in Closure Array: Add it ot Closure Array else ignore/continue change the State to next from counter; print the Closure */ for(m=0;m<10;m++) EpsilonClosure[m]=-1; EpsilonClosure[0]=i; E=1; done =0; d=i; Vcount=0; // printf("Startig with %s\n",S[i].name); while (!done) { OldE =E; if(Vcount>=E) { done = 1; } // printf("\tWhile:Looking into %s\n",S[d].name); for(j=0;j<S[d].EpsTop;j++) { VFlag=0; for (k=0;k<E;k++) { // printf("\t\t\tchecking S[%d].Epsilons[%d] (%d) == EpsilonClosure[%d] (%d) \n",d,j,S[d].Epsilons[j],k,EpsilonClosure[k]); if(S[d].Epsilons[j] == EpsilonClosure[k]) { // printf("\t\t\tAlready Present\n"); VFlag = 1; } } if(VFlag == 0) { // printf("\t\t Added %d to Closure\n",S[d].Epsilons[j]); EpsilonClosure[E++]=S[d].Epsilons[j]; } } if(Vcount>=E) { done = 1; } d=EpsilonClosure[++Vcount]; //printf("\t\tUpdated d to %d\n",d); if(d==-1) { d=-1; done =1; } } printf("\n\tClosure of %s ::\n",S[i].name); for(j=0;j<E;j++) printf("\t\t\t%s\n",S[EpsilonClosure[j]].name); } }
the_stack_data/182953131.c
/*===- InstrProfilingPlatformOther.c - Profile data default platform ------===*\ |* |* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |* See https://llvm.org/LICENSE.txt for license information. |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |* \*===----------------------------------------------------------------------===*/ #if !defined(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) && \ !(defined(__sun__) && defined(__svr4__)) && !defined(__NetBSD__) && \ !defined(_WIN32) #include <stdlib.h> #include <stdio.h> #include "InstrProfiling.h" static const __llvm_profile_data *DataFirst = NULL; static const __llvm_profile_data *DataLast = NULL; static const char *NamesFirst = NULL; static const char *NamesLast = NULL; static uint64_t *CountersFirst = NULL; static uint64_t *CountersLast = NULL; static const void *getMinAddr(const void *A1, const void *A2) { return A1 < A2 ? A1 : A2; } static const void *getMaxAddr(const void *A1, const void *A2) { return A1 > A2 ? A1 : A2; } /*! * \brief Register an instrumented function. * * Calls to this are emitted by clang with -fprofile-instr-generate. Such * calls are only required (and only emitted) on targets where we haven't * implemented linker magic to find the bounds of the sections. */ COMPILER_RT_VISIBILITY void __llvm_profile_register_function(void *Data_) { /* TODO: Only emit this function if we can't use linker magic. */ const __llvm_profile_data *Data = (__llvm_profile_data *)Data_; if (!DataFirst) { DataFirst = Data; DataLast = Data + 1; CountersFirst = Data->CounterPtr; CountersLast = (uint64_t *)Data->CounterPtr + Data->NumCounters; return; } DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data); CountersFirst = (uint64_t *)getMinAddr(CountersFirst, Data->CounterPtr); DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1); CountersLast = (uint64_t *)getMaxAddr( CountersLast, (uint64_t *)Data->CounterPtr + Data->NumCounters); } COMPILER_RT_VISIBILITY void __llvm_profile_register_names_function(void *NamesStart, uint64_t NamesSize) { if (!NamesFirst) { NamesFirst = (const char *)NamesStart; NamesLast = (const char *)NamesStart + NamesSize; return; } NamesFirst = (const char *)getMinAddr(NamesFirst, NamesStart); NamesLast = (const char *)getMaxAddr(NamesLast, (const char *)NamesStart + NamesSize); } COMPILER_RT_VISIBILITY const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; } COMPILER_RT_VISIBILITY const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; } COMPILER_RT_VISIBILITY const char *__llvm_profile_begin_names(void) { return NamesFirst; } COMPILER_RT_VISIBILITY const char *__llvm_profile_end_names(void) { return NamesLast; } COMPILER_RT_VISIBILITY uint64_t *__llvm_profile_begin_counters(void) { return CountersFirst; } COMPILER_RT_VISIBILITY uint64_t *__llvm_profile_end_counters(void) { return CountersLast; } COMPILER_RT_VISIBILITY ValueProfNode *__llvm_profile_begin_vnodes(void) { return 0; } COMPILER_RT_VISIBILITY ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; } COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0; COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0; #endif
the_stack_data/181393389.c
#include<stdio.h> void squeeze2(char s1[], char s2[]); main() { int c, i; char s1[1000], s2[500]; for (i = 0; (c = getchar()) != EOF && c!='\n'; ++i) s1[i] = c; for (i = 0; (c = getchar()) != EOF && c!='\n'; ++i) s2[i] = c; squeeze2(s1, s2); printf ("%s", s1); } void squeeze2(char s1[], char s2[]) { int i, j, o; for (o = 0; s2[o] != '\0'; o++) { for (i = j = 0; s1[i] != '\0'; i++) if (s1[i] != s2[o]) s1[j++] = s1[i]; s1[j] = '\0'; } }
the_stack_data/37637454.c
/* The MIT License Copyright (c) 2011 by Attractive Chaos <[email protected]> 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. */ // This file originally found here: // https://raw.githubusercontent.com/attractivechaos/plb/master/sudoku/sudoku_v1.c // This file implements an improved algorithm of Guenter Stertenbrink's suexco.c // (http://magictour.free.fr/suexco.txt). #include <stdlib.h> #include <stdint.h> #include <string.h> #include <stdio.h> /* For Sudoku, there are 9x9x9=729 possible choices (9 numbers to choose for each cell in a 9x9 grid), and 4x9x9=324 constraints with each constraint representing a set of choices that are mutually conflictive with each other. The 324 constraints are classified into 4 categories: 1. row-column where each cell contains only one number 2. box-number where each number appears only once in one 3x3 box 3. row-number where each number appears only once in one row 4. col-number where each number appears only once in one column Each category consists of 81 constraints. We number these constraints from 0 to 323. In this program, for example, constraint 0 requires that the (0,0) cell contains only one number; constraint 81 requires that number 1 appears only once in the upper-left 3x3 box; constraint 162 requires that number 1 appears only once in row 1; constraint 243 requires that number 1 appears only once in column 1. Noting that a constraint is a subset of choices, we may represent a constraint with a binary vector of 729 elements. Thus we have a 729x324 binary matrix M with M(r,c)=1 indicating the constraint c involves choice r. Solving a Sudoku is reduced to finding a subset of choices such that no choices are present in the same constraint. This is equivalent to finding the minimal subset of choices intersecting all constraints, a minimum hitting set problem or a equivalence of the exact cover problem. The 729x324 binary matrix is a sparse matrix, with each row containing 4 non-zero elements and each column 9 non-zero elements. In practical implementation, we store the coordinate of non-zero elements instead of the binary matrix itself. We use a binary row vector to indicate the constraints that have not been used and use a column vector to keep the number of times a choice has been forbidden. When we set a choice, we will use up 4 constraints and forbid other choices in the 4 constraints. When we make wrong choices, we will find an unused constraint with all choices forbidden, in which case, we have to backtrack to make new choices. Once we understand what the 729x324 matrix represents, the backtracking algorithm itself is easy. A major difference between the algorithm implemented here and Guenter Stertenbrink's suexco.c lies in how to count the number of the available choices for each constraint. Suexco.c computes the count with a loop, while the algorithm here keeps the count in an array. The latter is a little more complex to implement as we have to keep the counts synchronized all the time, but it is 50-100% faster, depending on the input. */ // the sparse representation of the binary matrix typedef struct { uint16_t r[324][9]; // M(r[c][i], c) is a non-zero element uint16_t c[729][4]; // M(r, c[r][j]) is a non-zero element } sdaux_t; // generate the sparse representation of the binary matrix sdaux_t *sd_genmat() { sdaux_t *a; int i, j, k, r, c, c2, r2; int8_t nr[324]; a = calloc(1, sizeof(sdaux_t)); for (i = r = 0; i < 9; ++i) // generate c[729][4] for (j = 0; j < 9; ++j) for (k = 0; k < 9; ++k) // this "9" means each cell has 9 possible numbers a->c[r][0] = 9 * i + j, // row-column constraint a->c[r][1] = (i/3*3 + j/3) * 9 + k + 81, // box-number constraint a->c[r][2] = 9 * i + k + 162, // row-number constraint a->c[r][3] = 9 * j + k + 243, // col-number constraint ++r; for (c = 0; c < 324; ++c) nr[c] = 0; for (r = 0; r < 729; ++r) // generate r[][] from c[][] for (c2 = 0; c2 < 4; ++c2) k = a->c[r][c2], a->r[k][nr[k]++] = r; return a; } // update the state vectors when we pick up choice r; v=1 for setting choice; v=-1 for reverting static inline int sd_update(const sdaux_t *aux, int8_t sr[729], uint8_t sc[324], int r, int v) { int c2, min = 10, min_c = 0; for (c2 = 0; c2 < 4; ++c2) sc[aux->c[r][c2]] += v<<7; for (c2 = 0; c2 < 4; ++c2) { // update # available choices int r2, rr, cc2, c = aux->c[r][c2]; if (v > 0) { // move forward for (r2 = 0; r2 < 9; ++r2) { if (sr[rr = aux->r[c][r2]]++ != 0) continue; // update the row status for (cc2 = 0; cc2 < 4; ++cc2) { int cc = aux->c[rr][cc2]; if (--sc[cc] < min) // update # allowed choices min = sc[cc], min_c = cc; // register the minimum number } } } else { // revert const uint16_t *p; for (r2 = 0; r2 < 9; ++r2) { if (--sr[rr = aux->r[c][r2]] != 0) continue; // update the row status p = aux->c[rr]; ++sc[p[0]]; ++sc[p[1]]; ++sc[p[2]]; ++sc[p[3]]; // update the count array } } } return min<<16 | min_c; // return the col that has been modified and with the minimal available choices } // solve a Sudoku; _s is the standard dot/number representation int sd_solve(const sdaux_t *aux, const char *_s, char *solution, size_t limit, size_t *num_guesses) { int i, j, r, c, r2, dir, cand, n = 0, min, hints = 0; // dir=1: forward; dir=-1: backtrack int8_t sr[729], cr[81]; // sr[r]: # times the row is forbidden by others; cr[i]: row chosen at step i uint8_t sc[324]; // bit 1-7: # allowed choices; bit 8: the constraint has been used or not int16_t cc[81]; // cc[i]: col chosen at step i for (r = 0; r < 729; ++r) sr[r] = 0; // no row is forbidden for (c = 0; c < 324; ++c) sc[c] = 0<<7|9; // 9 allowed choices; no constraint has been used for (i = 0; i < 81; ++i) { int a = _s[i] >= '1' && _s[i] <= '9'? _s[i] - '1' : -1; // number from -1 to 8 if (a >= 0) sd_update(aux, sr, sc, i * 9 + a, 1); // set the choice if (a >= 0) ++hints; // count the number of hints cr[i] = cc[i] = -1, solution[i] = _s[i]; } for (i = 0, dir = 1, cand = 10<<16|0;;) { while (i >= 0 && i < 81 - hints) { // maximum 81-hints steps if (dir == 1) { min = cand>>16, cc[i] = cand&0xffff; if (min > 1) { for (c = 0; c < 324; ++c) { if (sc[c] < min) { min = sc[c], cc[i] = c; // choose the top constraint if (min <= 1) break; // this is for acceleration; slower without this line } } } if (min == 0 || min == 10) cr[i--] = dir = -1; // backtrack } if (i < 0) { return 0; // an inconsistency; no solution } c = cc[i]; if (dir == -1 && cr[i] >= 0) sd_update(aux, sr, sc, aux->r[c][cr[i]], -1); // revert the choice for (r2 = cr[i] + 1; r2 < 9; ++r2) // search for the choice to make if (sr[aux->r[c][r2]] == 0) break; // found if the state equals 0 if (r2 < 9) { if (min > 1) (*num_guesses)++; cand = sd_update(aux, sr, sc, aux->r[c][r2], 1); // set the choice cr[i++] = r2; dir = 1; // moving forward } else cr[i--] = dir = -1; // backtrack } if (i < 0) break; for (j = 0; j < i; ++j) r = aux->r[cc[j]][cr[j]], solution[r/9] = r%9 + '1'; // print ++n; --i; dir = -1; // backtrack if (n == limit) break; } return n; // return the number of solutions } sdaux_t *aux = NULL; size_t OtherSolverKudoku(const char *input, size_t limit /* unused */, uint32_t configuration /* unused */, char *solution, size_t *num_guesses) { if (aux == NULL) aux = sd_genmat(); *num_guesses = 0; return sd_solve(aux, input, solution, limit, num_guesses); }
the_stack_data/22485.c
#include <stdio.h> // 定义常量 #define ONE 1; // 编译期常量 const int C_ONE = 1; // const描述不变化的值,并没有指出常量应该如何分配 #define dprint(a) printf(#a " = %g\n", a) int main() { double d = 1; dprint(d); printf("""""" " a" "bcde\n"); // 用goto跳出嵌套循环 int break_from_inner_loop = 0; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { printf("i = %d, j = %d\n", i, j); if (i == 1 && j == 1) { break_from_inner_loop = 1; goto found; } } } found: printf("end\n"); return 0; }
the_stack_data/181392001.c
#include <stdio.h> #include <stdlib.h> int fibonnaci(int n, int *c) { *c = *c + 1; if (n == 0 || n == 1) return n; return fibonnaci(n - 1, c) + fibonnaci(n - 2, c); } int main(int argc, char** argv) { int n, i; scanf("%d", &n); for(i = 0; i < n; i++) { int t, c = -1; scanf("%d", &t); int fibt = fibonnaci(t, &c); printf("fib(%d) = %d calls = %d\n", t, c, fibt); } return EXIT_SUCCESS; }
the_stack_data/92328156.c
#include <stdio.h> #include <unistd.h> #include <sys/wait.h> #include "check.h" int main(void) { int chan[2]; int status; pipe(chan); if (fork() > 0) { dup2(chan[0], STDIN_FILENO); if (yorn("Do you really wanna do this (y/N)? ")) { printf("Affirmative!\n"); _exit(0); } printf("OK, aborting!\n"); _exit(1); } sleep(1); if (write(chan[1], "Y", 1) != 1) return 1; wait(&status); return WEXITSTATUS(status); }
the_stack_data/1052286.c
// ---------------------------------------- // PROJECT EULER PROBLEM 5 // https://projecteuler.net/problem=5 // ---------------------------------------- #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <inttypes.h> #include <math.h> #include <time.h> #include <string.h> #define MAX_DIV 20 // Compute the Greatest Common Divisor of two numbers unsigned int gcd(unsigned int a, unsigned int b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } // Compute the Least Common Multiple of two numbers unsigned int lcm(unsigned int a, unsigned int b) { if (a > b) { return (a / gcd(a, b)) * b; } else { return (b / gcd(a, b)) * a; } } int main(int argc, char *argv[]) { int min = 1; // Loop through 1...19 for (int i = 1; i < MAX_DIV; i++) { // Find the LCM of i and the next number, and the previous LCM int l = lcm(lcm(i, i + 1), min); if (l > min) { min = l; } } // We found the LCM of all of them printf("Minimum common factor = %d\n", min); }
the_stack_data/92327140.c
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ char ch; char s[50]; char sen[100]; scanf("%c",&ch); scanf("%s",&s); scanf("\n"); scanf("%[^\n]%*c",&sen); printf("%c",ch); printf("\n%s",s); printf("\n%s",sen); return 0; }
the_stack_data/232954544.c
#include <stdio.h> double d = 3.9 + 0.234; int main(void) { printf("d = %f\n", d); return 0; }
the_stack_data/62997.c
#include <stdio.h> int isNIF(char s[9]) { int ret = 0; char letter [] ={'T','R','W','A','G','M','Y','F','P','D','X','B','N','J','Z','S','Q','V','H','L','C','K','E'}; int n=0; int aux; for(int i=0; i<8; i++) { aux = s[i]-'0'; n = n*10+aux; } printf("(%d )%c == %c \n",n%28, s[8],letter[n%23]); if(s[8] == letter[n%23]) ret = 1; return ret; } void posibleNIF(char s [9]) { printf("ha sobrevivido aquí "); if( isNIF(s) == 1) printf(" DNI %s ", s); } int main() { char * dni = "12345678Z"; posibleNIF(dni); }
the_stack_data/50137931.c
// Note: %s must be preceded by --, otherwise it may be interpreted as a // command-line option, e.g. on Mac where %s is commonly under /Users. // Alias options: // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=c %s // c: -c // RUN: %clang_cl /C -### -- %s 2>&1 | FileCheck -check-prefix=C %s // C: error: invalid argument '-C' only allowed with '/E, /P or /EP' // RUN: %clang_cl /C /P -### -- %s 2>&1 | FileCheck -check-prefix=C_P %s // C_P: "-E" // C_P: "-C" // RUN: %clang_cl /d1reportAllClassLayout -### -- %s 2>&1 | FileCheck -check-prefix=d1reportAllClassLayout %s // d1reportAllClassLayout: -fdump-record-layouts // RUN: %clang_cl /Dfoo=bar /D bar=baz /DMYDEF#value /DMYDEF2=foo#bar /DMYDEF3#a=b /DMYDEF4# \ // RUN: -### -- %s 2>&1 | FileCheck -check-prefix=D %s // D: "-D" "foo=bar" // D: "-D" "bar=baz" // D: "-D" "MYDEF=value" // D: "-D" "MYDEF2=foo#bar" // D: "-D" "MYDEF3=a=b" // D: "-D" "MYDEF4=" // RUN: %clang_cl /E -### -- %s 2>&1 | FileCheck -check-prefix=E %s // E: "-E" // E: "-o" "-" // RUN: %clang_cl /EP -### -- %s 2>&1 | FileCheck -check-prefix=EP %s // EP: "-E" // EP: "-P" // EP: "-o" "-" // RUN: %clang_cl /fp:fast /fp:except -### -- %s 2>&1 | FileCheck -check-prefix=fpexcept %s // fpexcept-NOT: -menable-unsafe-fp-math // RUN: %clang_cl /fp:fast /fp:except /fp:except- -### -- %s 2>&1 | FileCheck -check-prefix=fpexcept_ %s // fpexcept_: -menable-unsafe-fp-math // RUN: %clang_cl /fp:precise /fp:fast -### -- %s 2>&1 | FileCheck -check-prefix=fpfast %s // fpfast: -menable-unsafe-fp-math // fpfast: -ffast-math // RUN: %clang_cl /fp:fast /fp:precise -### -- %s 2>&1 | FileCheck -check-prefix=fpprecise %s // fpprecise-NOT: -menable-unsafe-fp-math // fpprecise-NOT: -ffast-math // RUN: %clang_cl /fp:fast /fp:strict -### -- %s 2>&1 | FileCheck -check-prefix=fpstrict %s // fpstrict-NOT: -menable-unsafe-fp-math // fpstrict-NOT: -ffast-math // RUN: %clang_cl /Z7 -gcolumn-info -### -- %s 2>&1 | FileCheck -check-prefix=gcolumn %s // gcolumn: -dwarf-column-info // RUN: %clang_cl /Z7 -gno-column-info -### -- %s 2>&1 | FileCheck -check-prefix=gnocolumn %s // gnocolumn-NOT: -dwarf-column-info // RUN: %clang_cl /Z7 -### -- %s 2>&1 | FileCheck -check-prefix=gdefcolumn %s // gdefcolumn-NOT: -dwarf-column-info // RUN: %clang_cl -### /FA -fprofile-instr-generate -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-INSTR-GENERATE %s // RUN: %clang_cl -### /FA -fprofile-instr-generate=/tmp/somefile.profraw -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-INSTR-GENERATE-FILE %s // CHECK-PROFILE-INSTR-GENERATE: "-fprofile-instrument=clang" "--dependent-lib={{[^"]*}}clang_rt.profile-{{[^"]*}}.lib" // CHECK-PROFILE-INSTR-GENERATE-FILE: "-fprofile-instrument-path=/tmp/somefile.profraw" // RUN: %clang_cl -### /FA -fprofile-generate -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE %s // CHECK-PROFILE-GENERATE: "-fprofile-instrument=llvm" "--dependent-lib={{[^"]*}}clang_rt.profile-{{[^"]*}}.lib" // RUN: %clang_cl -### /FA -fprofile-instr-generate -fprofile-instr-use -- %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MIX-GEN-USE %s // RUN: %clang_cl -### /FA -fprofile-instr-generate -fprofile-instr-use=file -- %s 2>&1 | FileCheck -check-prefix=CHECK-NO-MIX-GEN-USE %s // CHECK-NO-MIX-GEN-USE: '{{[a-z=-]*}}' not allowed with '{{[a-z=-]*}}' // RUN: %clang_cl -### /FA -fprofile-instr-use -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE %s // RUN: %clang_cl -### /FA -fprofile-instr-use=/tmp/somefile.prof -- %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-USE-FILE %s // CHECK-PROFILE-USE: "-fprofile-instrument-use-path=default.profdata" // CHECK-PROFILE-USE-FILE: "-fprofile-instrument-use-path=/tmp/somefile.prof" // RUN: %clang_cl /GA -### -- %s 2>&1 | FileCheck -check-prefix=GA %s // GA: -ftls-model=local-exec // RTTI is on by default; just check that we don't error. // RUN: %clang_cl /Zs /GR -- %s 2>&1 // RUN: %clang_cl /GR- -### -- %s 2>&1 | FileCheck -check-prefix=GR_ %s // GR_: -fno-rtti // Security Buffer Check is on by default. // RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=GS-default %s // GS-default: "-stack-protector" "2" // RUN: %clang_cl /GS -### -- %s 2>&1 | FileCheck -check-prefix=GS %s // GS: "-stack-protector" "2" // RUN: %clang_cl /GS- -### -- %s 2>&1 | FileCheck -check-prefix=GS_ %s // GS_-NOT: -stack-protector // RUN: %clang_cl /Gy -### -- %s 2>&1 | FileCheck -check-prefix=Gy %s // Gy: -ffunction-sections // RUN: %clang_cl /Gy /Gy- -### -- %s 2>&1 | FileCheck -check-prefix=Gy_ %s // Gy_-NOT: -ffunction-sections // RUN: %clang_cl /Gs -### -- %s 2>&1 | FileCheck -check-prefix=Gs %s // Gs: "-mstack-probe-size=4096" // RUN: %clang_cl /Gs0 -### -- %s 2>&1 | FileCheck -check-prefix=Gs0 %s // Gs0: "-mstack-probe-size=0" // RUN: %clang_cl /Gs4096 -### -- %s 2>&1 | FileCheck -check-prefix=Gs4096 %s // Gs4096: "-mstack-probe-size=4096" // RUN: %clang_cl /Gw -### -- %s 2>&1 | FileCheck -check-prefix=Gw %s // Gw: -fdata-sections // RUN: %clang_cl /Gw /Gw- -### -- %s 2>&1 | FileCheck -check-prefix=Gw_ %s // Gw_-NOT: -fdata-sections // RUN: %clang_cl /Imyincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_I %s // RUN: %clang_cl /I myincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_I %s // SLASH_I: "-I" "myincludedir" // RUN: %clang_cl /imsvcmyincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_imsvc %s // RUN: %clang_cl /imsvc myincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_imsvc %s // Clang's resource header directory should be first: // SLASH_imsvc: "-internal-isystem" "{{[^"]*}}lib{{(64)?/|\\\\}}clang{{[^"]*}}include" // SLASH_imsvc: "-internal-isystem" "myincludedir" // RUN: %clang_cl /J -### -- %s 2>&1 | FileCheck -check-prefix=J %s // J: -fno-signed-char // RUN: %clang_cl /Ofoo -### -- %s 2>&1 | FileCheck -check-prefix=O %s // O: /Ofoo // RUN: %clang_cl /Ob0 -### -- %s 2>&1 | FileCheck -check-prefix=Ob0 %s // Ob0: -fno-inline // RUN: %clang_cl /Ob2 -### -- %s 2>&1 | FileCheck -check-prefix=Ob2 %s // RUN: %clang_cl /Odb2 -### -- %s 2>&1 | FileCheck -check-prefix=Ob2 %s // RUN: %clang_cl /O2 /Ob2 -### -- %s 2>&1 | FileCheck -check-prefix=Ob2 %s // Ob2-NOT: warning: argument unused during compilation: '/O2' // Ob2: -finline-functions // RUN: %clang_cl /Ob1 -### -- %s 2>&1 | FileCheck -check-prefix=Ob1 %s // RUN: %clang_cl /Odb1 -### -- %s 2>&1 | FileCheck -check-prefix=Ob1 %s // Ob1: -finline-hint-functions // RUN: %clang_cl /Od -### -- %s 2>&1 | FileCheck -check-prefix=Od %s // Od: -O0 // RUN: %clang_cl /Oi- /Oi -### -- %s 2>&1 | FileCheck -check-prefix=Oi %s // Oi-NOT: -fno-builtin // RUN: %clang_cl /Oi- -### -- %s 2>&1 | FileCheck -check-prefix=Oi_ %s // Oi_: -fno-builtin // RUN: %clang_cl /Os --target=i686-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Os %s // RUN: %clang_cl /Os --target=x86_64-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Os %s // Os-NOT: -mdisable-fp-elim // Os: -momit-leaf-frame-pointer // Os: -Os // RUN: %clang_cl /Ot --target=i686-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ot %s // RUN: %clang_cl /Ot --target=x86_64-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ot %s // Ot-NOT: -mdisable-fp-elim // Ot: -momit-leaf-frame-pointer // Ot: -O2 // RUN: %clang_cl /Ox --target=i686-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ox %s // RUN: %clang_cl /Ox --target=x86_64-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ox %s // Ox-NOT: -mdisable-fp-elim // Ox: -momit-leaf-frame-pointer // Ox: -O2 // RUN: %clang_cl --target=i686-pc-win32 /O2sy- -### -- %s 2>&1 | FileCheck -check-prefix=PR24003 %s // PR24003: -mdisable-fp-elim // PR24003: -momit-leaf-frame-pointer // PR24003: -Os // RUN: %clang_cl --target=i686-pc-win32 -Werror /Oy- /O2 -### -- %s 2>&1 | FileCheck -check-prefix=Oy_2 %s // Oy_2: -momit-leaf-frame-pointer // Oy_2: -O2 // RUN: %clang_cl --target=aarch64-pc-windows-msvc -Werror /Oy- /O2 -### -- %s 2>&1 | FileCheck -check-prefix=Oy_aarch64 %s // Oy_aarch64: -mdisable-fp-elim // Oy_aarch64: -O2 // RUN: %clang_cl --target=i686-pc-win32 -Werror /O2 /O2 -### -- %s 2>&1 | FileCheck -check-prefix=O2O2 %s // O2O2: "-O2" // RUN: %clang_cl /Zs -Werror /Oy -- %s 2>&1 // RUN: %clang_cl --target=i686-pc-win32 -Werror /Oy- -### -- %s 2>&1 | FileCheck -check-prefix=Oy_ %s // Oy_: -mdisable-fp-elim // RUN: %clang_cl /Qvec -### -- %s 2>&1 | FileCheck -check-prefix=Qvec %s // Qvec: -vectorize-loops // RUN: %clang_cl /Qvec /Qvec- -### -- %s 2>&1 | FileCheck -check-prefix=Qvec_ %s // Qvec_-NOT: -vectorize-loops // RUN: %clang_cl /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes %s // showIncludes: --show-includes // RUN: %clang_cl /E /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_E %s // RUN: %clang_cl /EP /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_E %s // RUN: %clang_cl /E /EP /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_E %s // RUN: %clang_cl /EP /P /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_E %s // showIncludes_E-NOT: warning: argument unused during compilation: '--show-includes' // /source-charset: should warn on everything except UTF-8. // RUN: %clang_cl /source-charset:utf-16 -### -- %s 2>&1 | FileCheck -check-prefix=source-charset-utf-16 %s // source-charset-utf-16: invalid value 'utf-16' // /execution-charset: should warn on everything except UTF-8. // RUN: %clang_cl /execution-charset:utf-16 -### -- %s 2>&1 | FileCheck -check-prefix=execution-charset-utf-16 %s // execution-charset-utf-16: invalid value 'utf-16' // // RUN: %clang_cl /Umymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s // RUN: %clang_cl /U mymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s // U: "-U" "mymacro" // RUN: %clang_cl /validate-charset -### -- %s 2>&1 | FileCheck -check-prefix=validate-charset %s // validate-charset: -Winvalid-source-encoding // RUN: %clang_cl /validate-charset- -### -- %s 2>&1 | FileCheck -check-prefix=validate-charset_ %s // validate-charset_: -Wno-invalid-source-encoding // RUN: %clang_cl /vd2 -### -- %s 2>&1 | FileCheck -check-prefix=VD2 %s // VD2: -vtordisp-mode=2 // RUN: %clang_cl /vmg -### -- %s 2>&1 | FileCheck -check-prefix=VMG %s // VMG: "-fms-memptr-rep=virtual" // RUN: %clang_cl /vmg /vms -### -- %s 2>&1 | FileCheck -check-prefix=VMS %s // VMS: "-fms-memptr-rep=single" // RUN: %clang_cl /vmg /vmm -### -- %s 2>&1 | FileCheck -check-prefix=VMM %s // VMM: "-fms-memptr-rep=multiple" // RUN: %clang_cl /vmg /vmv -### -- %s 2>&1 | FileCheck -check-prefix=VMV %s // VMV: "-fms-memptr-rep=virtual" // RUN: %clang_cl /vmg /vmb -### -- %s 2>&1 | FileCheck -check-prefix=VMB %s // VMB: '/vmg' not allowed with '/vmb' // RUN: %clang_cl /vmg /vmm /vms -### -- %s 2>&1 | FileCheck -check-prefix=VMX %s // VMX: '/vms' not allowed with '/vmm' // RUN: %clang_cl /volatile:iso -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-ISO %s // VOLATILE-ISO-NOT: "-fms-volatile" // RUN: %clang_cl /volatile:ms -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-MS %s // VOLATILE-MS: "-fms-volatile" // RUN: %clang_cl /W0 -### -- %s 2>&1 | FileCheck -check-prefix=W0 %s // W0: -w // RUN: %clang_cl /W1 -### -- %s 2>&1 | FileCheck -check-prefix=W1 %s // RUN: %clang_cl /W2 -### -- %s 2>&1 | FileCheck -check-prefix=W1 %s // RUN: %clang_cl /W3 -### -- %s 2>&1 | FileCheck -check-prefix=W1 %s // RUN: %clang_cl /W4 -### -- %s 2>&1 | FileCheck -check-prefix=W4 %s // RUN: %clang_cl /Wall -### -- %s 2>&1 | FileCheck -check-prefix=Weverything %s // W1: -Wall // W4: -WCL4 // Weverything: -Weverything // RUN: %clang_cl /WX -### -- %s 2>&1 | FileCheck -check-prefix=WX %s // WX: -Werror // RUN: %clang_cl /WX- -### -- %s 2>&1 | FileCheck -check-prefix=WX_ %s // WX_: -Wno-error // RUN: %clang_cl /w -### -- %s 2>&1 | FileCheck -check-prefix=w %s // w: -w // RUN: %clang_cl /Zp -### -- %s 2>&1 | FileCheck -check-prefix=ZP %s // ZP: -fpack-struct=1 // RUN: %clang_cl /Zp2 -### -- %s 2>&1 | FileCheck -check-prefix=ZP2 %s // ZP2: -fpack-struct=2 // RUN: %clang_cl /Zs -### -- %s 2>&1 | FileCheck -check-prefix=Zs %s // Zs: -fsyntax-only // RUN: %clang_cl /FIasdf.h -### -- %s 2>&1 | FileCheck -check-prefix=FI %s // FI: "-include" "asdf.h" // RUN: %clang_cl /FI asdf.h -### -- %s 2>&1 | FileCheck -check-prefix=FI_ %s // FI_: "-include" "asdf.h" // RUN: %clang_cl /TP /c -### -- %s 2>&1 | FileCheck -check-prefix=NO-GX %s // NO-GX-NOT: "-fcxx-exceptions" "-fexceptions" // RUN: %clang_cl /TP /c /GX -### -- %s 2>&1 | FileCheck -check-prefix=GX %s // GX: "-fcxx-exceptions" "-fexceptions" // RUN: %clang_cl /TP /c /GX /GX- -### -- %s 2>&1 | FileCheck -check-prefix=GX_ %s // GX_-NOT: "-fcxx-exceptions" "-fexceptions" // RUN: %clang_cl /d1PP -### -- %s 2>&1 | FileCheck -check-prefix=d1PP %s // d1PP: -dD // We forward any unrecognized -W diagnostic options to cc1. // RUN: %clang_cl -Wunused-pragmas -### -- %s 2>&1 | FileCheck -check-prefix=WJoined %s // WJoined: "-cc1" // WJoined: "-Wunused-pragmas" // We recognize -f[no-]strict-aliasing. // RUN: %clang_cl -c -### -- %s 2>&1 | FileCheck -check-prefix=DEFAULTSTRICT %s // DEFAULTSTRICT: "-relaxed-aliasing" // RUN: %clang_cl -c -fstrict-aliasing -### -- %s 2>&1 | FileCheck -check-prefix=STRICT %s // STRICT-NOT: "-relaxed-aliasing" // RUN: %clang_cl -c -fno-strict-aliasing -### -- %s 2>&1 | FileCheck -check-prefix=NOSTRICT %s // NOSTRICT: "-relaxed-aliasing" // We recognize -f[no-]delayed-template-parsing. // /Zc:twoPhase[-] has the opposite meaning. // RUN: %clang_cl -c -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDDEFAULT %s // DELAYEDDEFAULT: "-fdelayed-template-parsing" // RUN: %clang_cl -c -fdelayed-template-parsing -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDON %s // RUN: %clang_cl -c /Zc:twoPhase- -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDON %s // DELAYEDON: "-fdelayed-template-parsing" // RUN: %clang_cl -c -fno-delayed-template-parsing -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s // RUN: %clang_cl -c /Zc:twoPhase -### -- %s 2>&1 | FileCheck -check-prefix=DELAYEDOFF %s // DELAYEDOFF-NOT: "-fdelayed-template-parsing" // RUN: %clang_cl -c -### /std:c++latest -- %s 2>&1 | FileCheck -check-prefix CHECK-LATEST-CHAR8_T %s // CHECK-LATEST-CHAR8_T-NOT: "-fchar8_t" // RUN: %clang_cl -c -### /Zc:char8_t -- %s 2>&1 | FileCheck -check-prefix CHECK-CHAR8_T %s // CHECK-CHAR8_T: "-fchar8_t" // RUN: %clang_cl -c -### /Zc:char8_t- -- %s 2>&1 | FileCheck -check-prefix CHECK-CHAR8_T_ %s // CHECK-CHAR8_T_: "-fno-char8_t" // For some warning ids, we can map from MSVC warning to Clang warning. // RUN: %clang_cl -wd4005 -wd4100 -wd4910 -wd4996 -### -- %s 2>&1 | FileCheck -check-prefix=Wno %s // Wno: "-cc1" // Wno: "-Wno-macro-redefined" // Wno: "-Wno-unused-parameter" // Wno: "-Wno-dllexport-explicit-instantiation-decl" // Wno: "-Wno-deprecated-declarations" // Ignored options. Check that we don't get "unused during compilation" errors. // RUN: %clang_cl /c \ // RUN: /analyze- \ // RUN: /bigobj \ // RUN: /cgthreads4 \ // RUN: /cgthreads8 \ // RUN: /d2FastFail \ // RUN: /d2Zi+ \ // RUN: /errorReport:foo \ // RUN: /execution-charset:utf-8 \ // RUN: /FC \ // RUN: /Fdfoo \ // RUN: /FS \ // RUN: /Gd \ // RUN: /GF \ // RUN: /GS- \ // RUN: /kernel- \ // RUN: /nologo \ // RUN: /Og \ // RUN: /openmp- \ // RUN: /permissive- \ // RUN: /RTC1 \ // RUN: /sdl \ // RUN: /sdl- \ // RUN: /source-charset:utf-8 \ // RUN: /utf-8 \ // RUN: /vmg \ // RUN: /volatile:iso \ // RUN: /w12345 \ // RUN: /wd1234 \ // RUN: /Zc:__cplusplus \ // RUN: /Zc:auto \ // RUN: /Zc:forScope \ // RUN: /Zc:inline \ // RUN: /Zc:rvalueCast \ // RUN: /Zc:ternary \ // RUN: /Zc:wchar_t \ // RUN: /Zm \ // RUN: /Zo \ // RUN: /Zo- \ // RUN: -### -- %s 2>&1 | FileCheck -check-prefix=IGNORED %s // IGNORED-NOT: argument unused during compilation // IGNORED-NOT: no such file or directory // Don't confuse /openmp- with the /o flag: // IGNORED-NOT: "-o" "penmp-.obj" // Ignored options and compile-only options are ignored for link jobs. // RUN: touch %t.obj // RUN: %clang_cl /nologo -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s // RUN: %clang_cl /Dfoo -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s // RUN: %clang_cl /MD -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s // LINKUNUSED-NOT: argument unused during compilation // Support ignoring warnings about unused arguments. // RUN: %clang_cl /Abracadabra -Qunused-arguments -### -- %s 2>&1 | FileCheck -check-prefix=UNUSED %s // UNUSED-NOT: argument unused during compilation // Unsupported but parsed options. Check that we don't error on them. // (/Zs is for syntax-only) // RUN: %clang_cl /Zs \ // RUN: /await \ // RUN: /constexpr:depth1000 /constexpr:backtrace1000 /constexpr:steps1000 \ // RUN: /AIfoo \ // RUN: /AI foo_does_not_exist \ // RUN: /Bt \ // RUN: /Bt+ \ // RUN: /clr:pure \ // RUN: /d2FH4 \ // RUN: /docname \ // RUN: /EHsc \ // RUN: /F 42 \ // RUN: /FA \ // RUN: /FAc \ // RUN: /Fafilename \ // RUN: /FAs \ // RUN: /FAu \ // RUN: /favor:blend \ // RUN: /Fifoo \ // RUN: /Fmfoo \ // RUN: /FpDebug\main.pch \ // RUN: /Frfoo \ // RUN: /FRfoo \ // RUN: /FU foo \ // RUN: /Fx \ // RUN: /G1 \ // RUN: /G2 \ // RUN: /GA \ // RUN: /Gd \ // RUN: /Ge \ // RUN: /Gh \ // RUN: /GH \ // RUN: /GL \ // RUN: /GL- \ // RUN: /Gm \ // RUN: /Gm- \ // RUN: /Gr \ // RUN: /GS \ // RUN: /GT \ // RUN: /GX \ // RUN: /Gv \ // RUN: /Gz \ // RUN: /GZ \ // RUN: /H \ // RUN: /homeparams \ // RUN: /hotpatch \ // RUN: /JMC \ // RUN: /kernel \ // RUN: /LN \ // RUN: /MP \ // RUN: /o foo.obj \ // RUN: /ofoo.obj \ // RUN: /openmp \ // RUN: /openmp:experimental \ // RUN: /Qfast_transcendentals \ // RUN: /QIfist \ // RUN: /Qimprecise_fwaits \ // RUN: /Qpar \ // RUN: /Qpar-report:1 \ // RUN: /Qsafe_fp_loads \ // RUN: /Qspectre \ // RUN: /Qvec-report:2 \ // RUN: /u \ // RUN: /V \ // RUN: /volatile:ms \ // RUN: /wfoo \ // RUN: /WL \ // RUN: /Wp64 \ // RUN: /X \ // RUN: /Y- \ // RUN: /Yc \ // RUN: /Ycstdafx.h \ // RUN: /Yd \ // RUN: /Yl- \ // RUN: /Ylfoo \ // RUN: /Yustdafx.h \ // RUN: /Z7 \ // RUN: /Za \ // RUN: /Ze \ // RUN: /Zg \ // RUN: /Zi \ // RUN: /ZI \ // RUN: /Zl \ // RUN: /ZW:nostdlib \ // RUN: -- %s 2>&1 // We support -Xclang for forwarding options to cc1. // RUN: %clang_cl -Xclang hellocc1 -### -- %s 2>&1 | FileCheck -check-prefix=Xclang %s // Xclang: "-cc1" // Xclang: "hellocc1" // Files under /Users are often confused with the /U flag. (This could happen // for other flags too, but this is the one people run into.) // RUN: %clang_cl /c /Users/me/myfile.c -### 2>&1 | FileCheck -check-prefix=SlashU %s // SlashU: warning: '/Users/me/myfile.c' treated as the '/U' option // SlashU: note: Use '--' to treat subsequent arguments as filenames // RTTI is on by default. /GR- controls -fno-rtti-data. // RUN: %clang_cl /c /GR- -### -- %s 2>&1 | FileCheck -check-prefix=NoRTTI %s // NoRTTI: "-fno-rtti-data" // NoRTTI-NOT: "-fno-rtti" // RUN: %clang_cl /c /GR -### -- %s 2>&1 | FileCheck -check-prefix=RTTI %s // RTTI-NOT: "-fno-rtti-data" // RTTI-NOT: "-fno-rtti" // thread safe statics are off for versions < 19. // RUN: %clang_cl /c -### -fms-compatibility-version=18 -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s // RUN: %clang_cl /Zc:threadSafeInit /Zc:threadSafeInit- /c -### -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s // NoThreadSafeStatics: "-fno-threadsafe-statics" // RUN: %clang_cl /Zc:threadSafeInit /c -### -- %s 2>&1 | FileCheck -check-prefix=ThreadSafeStatics %s // ThreadSafeStatics-NOT: "-fno-threadsafe-statics" // RUN: %clang_cl /Zc:dllexportInlines- /c -### -- %s 2>&1 | FileCheck -check-prefix=NoDllExportInlines %s // NoDllExportInlines: "-fno-dllexport-inlines" // RUN: %clang_cl /Zc:dllexportInlines /c -### -- %s 2>&1 | FileCheck -check-prefix=DllExportInlines %s // DllExportInlines-NOT: "-fno-dllexport-inlines" // RUN: %clang_cl /fallback /Zc:dllexportInlines- /c -### -- %s 2>&1 | FileCheck -check-prefix=DllExportInlinesFallback %s // DllExportInlinesFallback: error: option '/Zc:dllexportInlines-' is ABI-changing and not compatible with '/fallback' // RUN: %clang_cl /Zi /c -### -- %s 2>&1 | FileCheck -check-prefix=Zi %s // Zi: "-gcodeview" // Zi: "-debug-info-kind=limited" // RUN: %clang_cl /Z7 /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7 %s // Z7: "-gcodeview" // Z7: "-debug-info-kind=limited" // RUN: %clang_cl /Zd /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7GMLT %s // Z7GMLT: "-gcodeview" // Z7GMLT: "-debug-info-kind=line-tables-only" // RUN: %clang_cl -gline-tables-only /c -### -- %s 2>&1 | FileCheck -check-prefix=ZGMLT %s // ZGMLT: "-gcodeview" // ZGMLT: "-debug-info-kind=line-tables-only" // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=BreproDefault %s // BreproDefault: "-mincremental-linker-compatible" // RUN: %clang_cl /Brepro- /Brepro /c '-###' -- %s 2>&1 | FileCheck -check-prefix=Brepro %s // Brepro-NOT: "-mincremental-linker-compatible" // RUN: %clang_cl /Brepro /Brepro- /c '-###' -- %s 2>&1 | FileCheck -check-prefix=Brepro_ %s // Brepro_: "-mincremental-linker-compatible" // This test was super sneaky: "/Z7" means "line-tables", but "-gdwarf" occurs // later on the command line, so it should win. Interestingly the cc1 arguments // came out right, but had wrong semantics, because an invariant assumed by // CompilerInvocation was violated: it expects that at most one of {gdwarfN, // line-tables-only} appear. If you assume that, then you can safely use // Args.hasArg to test whether a boolean flag is present without caring // where it appeared. And for this test, it appeared to the left of -gdwarf // which made it "win". This test could not detect that bug. // RUN: %clang_cl /Z7 -gdwarf /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7_gdwarf %s // Z7_gdwarf: "-gcodeview" // Z7_gdwarf: "-debug-info-kind=limited" // Z7_gdwarf: "-dwarf-version=4" // RUN: %clang_cl -fmsc-version=1800 -TP -### -- %s 2>&1 | FileCheck -check-prefix=CXX11 %s // CXX11: -std=c++11 // RUN: %clang_cl -fmsc-version=1900 -TP -### -- %s 2>&1 | FileCheck -check-prefix=CXX14 %s // CXX14: -std=c++14 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++14 -### -- %s 2>&1 | FileCheck -check-prefix=STDCXX14 %s // STDCXX14: -std=c++14 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++17 -### -- %s 2>&1 | FileCheck -check-prefix=STDCXX17 %s // STDCXX17: -std=c++17 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++latest -### -- %s 2>&1 | FileCheck -check-prefix=STDCXXLATEST %s // STDCXXLATEST: -std=c++2a // RUN: env CL="/Gy" %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=ENV-CL %s // ENV-CL: "-ffunction-sections" // RUN: env CL="/Gy" _CL_="/Gy- -- %s" %clang_cl -### 2>&1 | FileCheck -check-prefix=ENV-_CL_ %s // ENV-_CL_-NOT: "-ffunction-sections" // RUN: env CL="%s" _CL_="%s" not %clang --rsp-quoting=windows -c // RUN: %clang_cl -### /c -flto -- %s 2>&1 | FileCheck -check-prefix=LTO %s // LTO: -flto // RUN: %clang_cl -### /c -flto=thin -- %s 2>&1 | FileCheck -check-prefix=LTO-THIN %s // LTO-THIN: -flto=thin // RUN: %clang_cl -### -Fe%t.exe -entry:main -flto -- %s 2>&1 | FileCheck -check-prefix=LTO-WITHOUT-LLD %s // LTO-WITHOUT-LLD: LTO requires -fuse-ld=lld // RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=NOCFGUARD %s // RUN: %clang_cl /guard:cf- -### -- %s 2>&1 | FileCheck -check-prefix=NOCFGUARD %s // NOCFGUARD-NOT: -cfguard // RUN: %clang_cl /guard:cf -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARD %s // RUN: %clang_cl /guard:cf,nochecks -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARD %s // RUN: %clang_cl /guard:nochecks -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARD %s // CFGUARD: -cfguard // RUN: %clang_cl /guard:foo -### -- %s 2>&1 | FileCheck -check-prefix=CFGUARDINVALID %s // CFGUARDINVALID: invalid value 'foo' in '/guard:' // Accept "core" clang options. // (/Zs is for syntax-only, -Werror makes it fail hard on unknown options) // RUN: %clang_cl \ // RUN: --driver-mode=cl \ // RUN: -fblocks \ // RUN: -fcrash-diagnostics-dir=/foo \ // RUN: -fno-crash-diagnostics \ // RUN: -fno-blocks \ // RUN: -fbuiltin \ // RUN: -fno-builtin \ // RUN: -fno-builtin-strcpy \ // RUN: -fcolor-diagnostics \ // RUN: -fno-color-diagnostics \ // RUN: -fcoverage-mapping \ // RUN: -fno-coverage-mapping \ // RUN: -fdiagnostics-color \ // RUN: -fno-diagnostics-color \ // RUN: -fdiagnostics-parseable-fixits \ // RUN: -fdiagnostics-absolute-paths \ // RUN: -ferror-limit=10 \ // RUN: -fmsc-version=1800 \ // RUN: -fno-strict-aliasing \ // RUN: -fstrict-aliasing \ // RUN: -fsyntax-only \ // RUN: -fms-compatibility \ // RUN: -fno-ms-compatibility \ // RUN: -fms-extensions \ // RUN: -fno-ms-extensions \ // RUN: -Xclang -disable-llvm-passes \ // RUN: -resource-dir asdf \ // RUN: -resource-dir=asdf \ // RUN: -Wunused-variable \ // RUN: -fmacro-backtrace-limit=0 \ // RUN: -fstandalone-debug \ // RUN: -flimit-debug-info \ // RUN: -flto \ // RUN: -fmerge-all-constants \ // RUN: -no-canonical-prefixes \ // RUN: -march=skylake \ // RUN: -fbracket-depth=123 \ // RUN: -fprofile-generate \ // RUN: -fprofile-generate=dir \ // RUN: -fno-profile-generate \ // RUN: -fno-profile-instr-generate \ // RUN: -fno-profile-instr-use \ // RUN: -fcs-profile-generate \ // RUN: -fcs-profile-generate=dir \ // RUN: -ftime-trace \ // RUN: --version \ // RUN: -Werror /Zs -- %s 2>&1 // Accept clang options under the /clang: flag. // The first test case ensures that the SLP vectorizer is on by default and that // it's being turned off by the /clang:-fno-slp-vectorize flag. // RUN: %clang_cl -O2 -### -- %s 2>&1 | FileCheck -check-prefix=NOCLANG %s // NOCLANG: "--dependent-lib=libcmt" // NOCLANG-SAME: "-vectorize-slp" // NOCLANG-NOT: "--dependent-lib=msvcrt" // RUN: %clang_cl -O2 -MD /clang:-fno-slp-vectorize /clang:-MD /clang:-MF /clang:my_dependency_file.dep -### -- %s 2>&1 | FileCheck -check-prefix=CLANG %s // CLANG: "--dependent-lib=msvcrt" // CLANG-SAME: "-dependency-file" "my_dependency_file.dep" // CLANG-NOT: "--dependent-lib=libcmt" // CLANG-NOT: "-vectorize-slp" void f() { }
the_stack_data/73574002.c
#ifdef CS333_P3 #include "types.h" #include "user.h" int main(void) { int pid; printf(1,"Forking\n"); pid = fork(); if(pid<0){ printf(2,"An error has occurred while forking!\n"); exit(); } if(pid == 0){ printf(1,"Child process is sleeping for 10 seconds\n"); sleep(10*TPS); printf(1,"Child process is exiting normally. \n"); exit(); } sleep(5*TPS); printf(1,"Wait for the child to exit normally. Sleeping for 20 seconds.\n"); sleep(20*TPS); printf(1,"Before Wait(). Sleeping for 5 seconds.\n"); sleep(5*TPS); wait(); printf(1,"After Wait(). Sleeping for 5 seconds. \n"); sleep(5*TPS); exit(); } #endif
the_stack_data/102664.c
/* * http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html * Copyright Takuya OOURA, 1996-2001 * * You may use, copy, modify and distribute this code for any purpose (include * commercial use) and without fee. Please refer to this package when you modify * this code. * * Changes: * Trivial type modifications by the WebRTC authors. */ /* Fast Fourier/Cosine/Sine Transform dimension :one data length :power of 2 decimation :frequency radix :4, 2 data :inplace table :use functions cdft: Complex Discrete Fourier Transform rdft: Real Discrete Fourier Transform ddct: Discrete Cosine Transform ddst: Discrete Sine Transform dfct: Cosine Transform of RDFT (Real Symmetric DFT) dfst: Sine Transform of RDFT (Real Anti-symmetric DFT) function prototypes void cdft(int, int, float *, int *, float *); void rdft(int, int, float *, int *, float *); void ddct(int, int, float *, int *, float *); void ddst(int, int, float *, int *, float *); void dfct(int, float *, float *, int *, float *); void dfst(int, float *, float *, int *, float *); -------- Complex DFT (Discrete Fourier Transform) -------- [definition] <case1> X[k] = sum_j=0^n-1 x[j]*exp(2*pi*i*j*k/n), 0<=k<n <case2> X[k] = sum_j=0^n-1 x[j]*exp(-2*pi*i*j*k/n), 0<=k<n (notes: sum_j=0^n-1 is a summation from j=0 to n-1) [usage] <case1> ip[0] = 0; // first time only cdft(2*n, 1, a, ip, w); <case2> ip[0] = 0; // first time only cdft(2*n, -1, a, ip, w); [parameters] 2*n :data length (int) n >= 1, n = power of 2 a[0...2*n-1] :input/output data (float *) input data a[2*j] = Re(x[j]), a[2*j+1] = Im(x[j]), 0<=j<n output data a[2*k] = Re(X[k]), a[2*k+1] = Im(X[k]), 0<=k<n ip[0...*] :work area for bit reversal (int *) length of ip >= 2+sqrt(n) strictly, length of ip >= 2+(1<<(int)(log(n+0.5)/log(2))/2). ip[0],ip[1] are pointers of the cos/sin table. w[0...n/2-1] :cos/sin table (float *) w[],ip[] are initialized if ip[0] == 0. [remark] Inverse of cdft(2*n, -1, a, ip, w); is cdft(2*n, 1, a, ip, w); for (j = 0; j <= 2 * n - 1; j++) { a[j] *= 1.0 / n; } . -------- Real DFT / Inverse of Real DFT -------- [definition] <case1> RDFT R[k] = sum_j=0^n-1 a[j]*cos(2*pi*j*k/n), 0<=k<=n/2 I[k] = sum_j=0^n-1 a[j]*sin(2*pi*j*k/n), 0<k<n/2 <case2> IRDFT (excluding scale) a[k] = (R[0] + R[n/2]*cos(pi*k))/2 + sum_j=1^n/2-1 R[j]*cos(2*pi*j*k/n) + sum_j=1^n/2-1 I[j]*sin(2*pi*j*k/n), 0<=k<n [usage] <case1> ip[0] = 0; // first time only rdft(n, 1, a, ip, w); <case2> ip[0] = 0; // first time only rdft(n, -1, a, ip, w); [parameters] n :data length (int) n >= 2, n = power of 2 a[0...n-1] :input/output data (float *) <case1> output data a[2*k] = R[k], 0<=k<n/2 a[2*k+1] = I[k], 0<k<n/2 a[1] = R[n/2] <case2> input data a[2*j] = R[j], 0<=j<n/2 a[2*j+1] = I[j], 0<j<n/2 a[1] = R[n/2] ip[0...*] :work area for bit reversal (int *) length of ip >= 2+sqrt(n/2) strictly, length of ip >= 2+(1<<(int)(log(n/2+0.5)/log(2))/2). ip[0],ip[1] are pointers of the cos/sin table. w[0...n/2-1] :cos/sin table (float *) w[],ip[] are initialized if ip[0] == 0. [remark] Inverse of rdft(n, 1, a, ip, w); is rdft(n, -1, a, ip, w); for (j = 0; j <= n - 1; j++) { a[j] *= 2.0 / n; } . -------- DCT (Discrete Cosine Transform) / Inverse of DCT -------- [definition] <case1> IDCT (excluding scale) C[k] = sum_j=0^n-1 a[j]*cos(pi*j*(k+1/2)/n), 0<=k<n <case2> DCT C[k] = sum_j=0^n-1 a[j]*cos(pi*(j+1/2)*k/n), 0<=k<n [usage] <case1> ip[0] = 0; // first time only ddct(n, 1, a, ip, w); <case2> ip[0] = 0; // first time only ddct(n, -1, a, ip, w); [parameters] n :data length (int) n >= 2, n = power of 2 a[0...n-1] :input/output data (float *) output data a[k] = C[k], 0<=k<n ip[0...*] :work area for bit reversal (int *) length of ip >= 2+sqrt(n/2) strictly, length of ip >= 2+(1<<(int)(log(n/2+0.5)/log(2))/2). ip[0],ip[1] are pointers of the cos/sin table. w[0...n*5/4-1] :cos/sin table (float *) w[],ip[] are initialized if ip[0] == 0. [remark] Inverse of ddct(n, -1, a, ip, w); is a[0] *= 0.5; ddct(n, 1, a, ip, w); for (j = 0; j <= n - 1; j++) { a[j] *= 2.0 / n; } . -------- DST (Discrete Sine Transform) / Inverse of DST -------- [definition] <case1> IDST (excluding scale) S[k] = sum_j=1^n A[j]*sin(pi*j*(k+1/2)/n), 0<=k<n <case2> DST S[k] = sum_j=0^n-1 a[j]*sin(pi*(j+1/2)*k/n), 0<k<=n [usage] <case1> ip[0] = 0; // first time only ddst(n, 1, a, ip, w); <case2> ip[0] = 0; // first time only ddst(n, -1, a, ip, w); [parameters] n :data length (int) n >= 2, n = power of 2 a[0...n-1] :input/output data (float *) <case1> input data a[j] = A[j], 0<j<n a[0] = A[n] output data a[k] = S[k], 0<=k<n <case2> output data a[k] = S[k], 0<k<n a[0] = S[n] ip[0...*] :work area for bit reversal (int *) length of ip >= 2+sqrt(n/2) strictly, length of ip >= 2+(1<<(int)(log(n/2+0.5)/log(2))/2). ip[0],ip[1] are pointers of the cos/sin table. w[0...n*5/4-1] :cos/sin table (float *) w[],ip[] are initialized if ip[0] == 0. [remark] Inverse of ddst(n, -1, a, ip, w); is a[0] *= 0.5; ddst(n, 1, a, ip, w); for (j = 0; j <= n - 1; j++) { a[j] *= 2.0 / n; } . -------- Cosine Transform of RDFT (Real Symmetric DFT) -------- [definition] C[k] = sum_j=0^n a[j]*cos(pi*j*k/n), 0<=k<=n [usage] ip[0] = 0; // first time only dfct(n, a, t, ip, w); [parameters] n :data length - 1 (int) n >= 2, n = power of 2 a[0...n] :input/output data (float *) output data a[k] = C[k], 0<=k<=n t[0...n/2] :work area (float *) ip[0...*] :work area for bit reversal (int *) length of ip >= 2+sqrt(n/4) strictly, length of ip >= 2+(1<<(int)(log(n/4+0.5)/log(2))/2). ip[0],ip[1] are pointers of the cos/sin table. w[0...n*5/8-1] :cos/sin table (float *) w[],ip[] are initialized if ip[0] == 0. [remark] Inverse of a[0] *= 0.5; a[n] *= 0.5; dfct(n, a, t, ip, w); is a[0] *= 0.5; a[n] *= 0.5; dfct(n, a, t, ip, w); for (j = 0; j <= n; j++) { a[j] *= 2.0 / n; } . -------- Sine Transform of RDFT (Real Anti-symmetric DFT) -------- [definition] S[k] = sum_j=1^n-1 a[j]*sin(pi*j*k/n), 0<k<n [usage] ip[0] = 0; // first time only dfst(n, a, t, ip, w); [parameters] n :data length + 1 (int) n >= 2, n = power of 2 a[0...n-1] :input/output data (float *) output data a[k] = S[k], 0<k<n (a[0] is used for work area) t[0...n/2-1] :work area (float *) ip[0...*] :work area for bit reversal (int *) length of ip >= 2+sqrt(n/4) strictly, length of ip >= 2+(1<<(int)(log(n/4+0.5)/log(2))/2). ip[0],ip[1] are pointers of the cos/sin table. w[0...n*5/8-1] :cos/sin table (float *) w[],ip[] are initialized if ip[0] == 0. [remark] Inverse of dfst(n, a, t, ip, w); is dfst(n, a, t, ip, w); for (j = 1; j <= n - 1; j++) { a[j] *= 2.0 / n; } . Appendix : The cos/sin table is recalculated when the larger table required. w[] and ip[] are compatible with all routines. */ static void makewt(int nw, int *ip, float *w); static void makect(int nc, int *ip, float *c); static void bitrv2(int n, int *ip, float *a); #if 0 // Not used. static void bitrv2conj(int n, int *ip, float *a); #endif static void cftfsub(int n, float *a, float *w); static void cftbsub(int n, float *a, float *w); static void cft1st(int n, float *a, float *w); static void cftmdl(int n, int l, float *a, float *w); static void rftfsub(int n, float *a, int nc, float *c); static void rftbsub(int n, float *a, int nc, float *c); #if 0 // Not used. static void dctsub(int n, float *a, int nc, float *c) static void dstsub(int n, float *a, int nc, float *c) #endif #if 0 // Not used. void WebRtc_cdft(int n, int isgn, float *a, int *ip, float *w) { if (n > (ip[0] << 2)) { makewt(n >> 2, ip, w); } if (n > 4) { if (isgn >= 0) { bitrv2(n, ip + 2, a); cftfsub(n, a, w); } else { bitrv2conj(n, ip + 2, a); cftbsub(n, a, w); } } else if (n == 4) { cftfsub(n, a, w); } } #endif void WebRtc_rdft(int n, int isgn, float *a, int *ip, float *w) { int nw, nc; float xi; nw = ip[0]; if (n > (nw << 2)) { nw = n >> 2; makewt(nw, ip, w); } nc = ip[1]; if (n > (nc << 2)) { nc = n >> 2; makect(nc, ip, w + nw); } if (isgn >= 0) { if (n > 4) { bitrv2(n, ip + 2, a); cftfsub(n, a, w); rftfsub(n, a, nc, w + nw); } else if (n == 4) { cftfsub(n, a, w); } xi = a[0] - a[1]; a[0] += a[1]; a[1] = xi; } else { a[1] = 0.5f * (a[0] - a[1]); a[0] -= a[1]; if (n > 4) { rftbsub(n, a, nc, w + nw); bitrv2(n, ip + 2, a); cftbsub(n, a, w); } else if (n == 4) { cftfsub(n, a, w); } } } #if 0 // Not used. static void ddct(int n, int isgn, float *a, int *ip, float *w) { int j, nw, nc; float xr; nw = ip[0]; if (n > (nw << 2)) { nw = n >> 2; makewt(nw, ip, w); } nc = ip[1]; if (n > nc) { nc = n; makect(nc, ip, w + nw); } if (isgn < 0) { xr = a[n - 1]; for (j = n - 2; j >= 2; j -= 2) { a[j + 1] = a[j] - a[j - 1]; a[j] += a[j - 1]; } a[1] = a[0] - xr; a[0] += xr; if (n > 4) { rftbsub(n, a, nc, w + nw); bitrv2(n, ip + 2, a); cftbsub(n, a, w); } else if (n == 4) { cftfsub(n, a, w); } } dctsub(n, a, nc, w + nw); if (isgn >= 0) { if (n > 4) { bitrv2(n, ip + 2, a); cftfsub(n, a, w); rftfsub(n, a, nc, w + nw); } else if (n == 4) { cftfsub(n, a, w); } xr = a[0] - a[1]; a[0] += a[1]; for (j = 2; j < n; j += 2) { a[j - 1] = a[j] - a[j + 1]; a[j] += a[j + 1]; } a[n - 1] = xr; } } static void ddst(int n, int isgn, float *a, int *ip, float *w) { int j, nw, nc; float xr; nw = ip[0]; if (n > (nw << 2)) { nw = n >> 2; makewt(nw, ip, w); } nc = ip[1]; if (n > nc) { nc = n; makect(nc, ip, w + nw); } if (isgn < 0) { xr = a[n - 1]; for (j = n - 2; j >= 2; j -= 2) { a[j + 1] = -a[j] - a[j - 1]; a[j] -= a[j - 1]; } a[1] = a[0] + xr; a[0] -= xr; if (n > 4) { rftbsub(n, a, nc, w + nw); bitrv2(n, ip + 2, a); cftbsub(n, a, w); } else if (n == 4) { cftfsub(n, a, w); } } dstsub(n, a, nc, w + nw); if (isgn >= 0) { if (n > 4) { bitrv2(n, ip + 2, a); cftfsub(n, a, w); rftfsub(n, a, nc, w + nw); } else if (n == 4) { cftfsub(n, a, w); } xr = a[0] - a[1]; a[0] += a[1]; for (j = 2; j < n; j += 2) { a[j - 1] = -a[j] - a[j + 1]; a[j] -= a[j + 1]; } a[n - 1] = -xr; } } static void dfct(int n, float *a, float *t, int *ip, float *w) { int j, k, l, m, mh, nw, nc; float xr, xi, yr, yi; nw = ip[0]; if (n > (nw << 3)) { nw = n >> 3; makewt(nw, ip, w); } nc = ip[1]; if (n > (nc << 1)) { nc = n >> 1; makect(nc, ip, w + nw); } m = n >> 1; yi = a[m]; xi = a[0] + a[n]; a[0] -= a[n]; t[0] = xi - yi; t[m] = xi + yi; if (n > 2) { mh = m >> 1; for (j = 1; j < mh; j++) { k = m - j; xr = a[j] - a[n - j]; xi = a[j] + a[n - j]; yr = a[k] - a[n - k]; yi = a[k] + a[n - k]; a[j] = xr; a[k] = yr; t[j] = xi - yi; t[k] = xi + yi; } t[mh] = a[mh] + a[n - mh]; a[mh] -= a[n - mh]; dctsub(m, a, nc, w + nw); if (m > 4) { bitrv2(m, ip + 2, a); cftfsub(m, a, w); rftfsub(m, a, nc, w + nw); } else if (m == 4) { cftfsub(m, a, w); } a[n - 1] = a[0] - a[1]; a[1] = a[0] + a[1]; for (j = m - 2; j >= 2; j -= 2) { a[2 * j + 1] = a[j] + a[j + 1]; a[2 * j - 1] = a[j] - a[j + 1]; } l = 2; m = mh; while (m >= 2) { dctsub(m, t, nc, w + nw); if (m > 4) { bitrv2(m, ip + 2, t); cftfsub(m, t, w); rftfsub(m, t, nc, w + nw); } else if (m == 4) { cftfsub(m, t, w); } a[n - l] = t[0] - t[1]; a[l] = t[0] + t[1]; k = 0; for (j = 2; j < m; j += 2) { k += l << 2; a[k - l] = t[j] - t[j + 1]; a[k + l] = t[j] + t[j + 1]; } l <<= 1; mh = m >> 1; for (j = 0; j < mh; j++) { k = m - j; t[j] = t[m + k] - t[m + j]; t[k] = t[m + k] + t[m + j]; } t[mh] = t[m + mh]; m = mh; } a[l] = t[0]; a[n] = t[2] - t[1]; a[0] = t[2] + t[1]; } else { a[1] = a[0]; a[2] = t[0]; a[0] = t[1]; } } static void dfst(int n, float *a, float *t, int *ip, float *w) { int j, k, l, m, mh, nw, nc; float xr, xi, yr, yi; nw = ip[0]; if (n > (nw << 3)) { nw = n >> 3; makewt(nw, ip, w); } nc = ip[1]; if (n > (nc << 1)) { nc = n >> 1; makect(nc, ip, w + nw); } if (n > 2) { m = n >> 1; mh = m >> 1; for (j = 1; j < mh; j++) { k = m - j; xr = a[j] + a[n - j]; xi = a[j] - a[n - j]; yr = a[k] + a[n - k]; yi = a[k] - a[n - k]; a[j] = xr; a[k] = yr; t[j] = xi + yi; t[k] = xi - yi; } t[0] = a[mh] - a[n - mh]; a[mh] += a[n - mh]; a[0] = a[m]; dstsub(m, a, nc, w + nw); if (m > 4) { bitrv2(m, ip + 2, a); cftfsub(m, a, w); rftfsub(m, a, nc, w + nw); } else if (m == 4) { cftfsub(m, a, w); } a[n - 1] = a[1] - a[0]; a[1] = a[0] + a[1]; for (j = m - 2; j >= 2; j -= 2) { a[2 * j + 1] = a[j] - a[j + 1]; a[2 * j - 1] = -a[j] - a[j + 1]; } l = 2; m = mh; while (m >= 2) { dstsub(m, t, nc, w + nw); if (m > 4) { bitrv2(m, ip + 2, t); cftfsub(m, t, w); rftfsub(m, t, nc, w + nw); } else if (m == 4) { cftfsub(m, t, w); } a[n - l] = t[1] - t[0]; a[l] = t[0] + t[1]; k = 0; for (j = 2; j < m; j += 2) { k += l << 2; a[k - l] = -t[j] - t[j + 1]; a[k + l] = t[j] - t[j + 1]; } l <<= 1; mh = m >> 1; for (j = 1; j < mh; j++) { k = m - j; t[j] = t[m + k] + t[m + j]; t[k] = t[m + k] - t[m + j]; } t[0] = t[m + mh]; m = mh; } a[l] = t[0]; } a[0] = 0; } #endif // Not used. /* -------- initializing routines -------- */ #include <math.h> static void makewt(int nw, int *ip, float *w) { int j, nwh; float delta, x, y; ip[0] = nw; ip[1] = 1; if (nw > 2) { nwh = nw >> 1; delta = atanf(1.0f) / nwh; w[0] = 1; w[1] = 0; w[nwh] = (float)cos(delta * nwh); w[nwh + 1] = w[nwh]; if (nwh > 2) { for (j = 2; j < nwh; j += 2) { x = (float)cos(delta * j); y = (float)sin(delta * j); w[j] = x; w[j + 1] = y; w[nw - j] = y; w[nw - j + 1] = x; } bitrv2(nw, ip + 2, w); } } } static void makect(int nc, int *ip, float *c) { int j, nch; float delta; ip[1] = nc; if (nc > 1) { nch = nc >> 1; delta = atanf(1.0f) / nch; c[0] = (float)cos(delta * nch); c[nch] = 0.5f * c[0]; for (j = 1; j < nch; j++) { c[j] = 0.5f * (float)cos(delta * j); c[nc - j] = 0.5f * (float)sin(delta * j); } } } /* -------- child routines -------- */ static void bitrv2(int n, int *ip, float *a) { int j, j1, k, k1, l, m, m2; float xr, xi, yr, yi; ip[0] = 0; l = n; m = 1; while ((m << 3) < l) { l >>= 1; for (j = 0; j < m; j++) { ip[m + j] = ip[j] + l; } m <<= 1; } m2 = 2 * m; if ((m << 3) == l) { for (k = 0; k < m; k++) { for (j = 0; j < k; j++) { j1 = 2 * j + ip[k]; k1 = 2 * k + ip[j]; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += 2 * m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 -= m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += 2 * m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } j1 = 2 * k + m2 + ip[k]; k1 = j1 + m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } } else { for (k = 1; k < m; k++) { for (j = 0; j < k; j++) { j1 = 2 * j + ip[k]; k1 = 2 * k + ip[j]; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += m2; xr = a[j1]; xi = a[j1 + 1]; yr = a[k1]; yi = a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } } } } #if 0 // Not used. static void bitrv2conj(int n, int *ip, float *a) { int j, j1, k, k1, l, m, m2; float xr, xi, yr, yi; ip[0] = 0; l = n; m = 1; while ((m << 3) < l) { l >>= 1; for (j = 0; j < m; j++) { ip[m + j] = ip[j] + l; } m <<= 1; } m2 = 2 * m; if ((m << 3) == l) { for (k = 0; k < m; k++) { for (j = 0; j < k; j++) { j1 = 2 * j + ip[k]; k1 = 2 * k + ip[j]; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += 2 * m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 -= m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += 2 * m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } k1 = 2 * k + ip[k]; a[k1 + 1] = -a[k1 + 1]; j1 = k1 + m2; k1 = j1 + m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; k1 += m2; a[k1 + 1] = -a[k1 + 1]; } } else { a[1] = -a[1]; a[m2 + 1] = -a[m2 + 1]; for (k = 1; k < m; k++) { for (j = 0; j < k; j++) { j1 = 2 * j + ip[k]; k1 = 2 * k + ip[j]; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; j1 += m2; k1 += m2; xr = a[j1]; xi = -a[j1 + 1]; yr = a[k1]; yi = -a[k1 + 1]; a[j1] = yr; a[j1 + 1] = yi; a[k1] = xr; a[k1 + 1] = xi; } k1 = 2 * k + ip[k]; a[k1 + 1] = -a[k1 + 1]; a[k1 + m2 + 1] = -a[k1 + m2 + 1]; } } } #endif static void cftfsub(int n, float *a, float *w) { int j, j1, j2, j3, l; float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; l = 2; if (n > 8) { cft1st(n, a, w); l = 8; while ((l << 2) < n) { cftmdl(n, l, a, w); l <<= 2; } } if ((l << 2) == n) { for (j = 0; j < l; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; a[j2] = x0r - x2r; a[j2 + 1] = x0i - x2i; a[j1] = x1r - x3i; a[j1 + 1] = x1i + x3r; a[j3] = x1r + x3i; a[j3 + 1] = x1i - x3r; } } else { for (j = 0; j < l; j += 2) { j1 = j + l; x0r = a[j] - a[j1]; x0i = a[j + 1] - a[j1 + 1]; a[j] += a[j1]; a[j + 1] += a[j1 + 1]; a[j1] = x0r; a[j1 + 1] = x0i; } } } static void cftbsub(int n, float *a, float *w) { int j, j1, j2, j3, l; float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; l = 2; if (n > 8) { cft1st(n, a, w); l = 8; while ((l << 2) < n) { cftmdl(n, l, a, w); l <<= 2; } } if ((l << 2) == n) { for (j = 0; j < l; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = -a[j + 1] - a[j1 + 1]; x1r = a[j] - a[j1]; x1i = -a[j + 1] + a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i - x2i; a[j2] = x0r - x2r; a[j2 + 1] = x0i + x2i; a[j1] = x1r - x3i; a[j1 + 1] = x1i - x3r; a[j3] = x1r + x3i; a[j3 + 1] = x1i + x3r; } } else { for (j = 0; j < l; j += 2) { j1 = j + l; x0r = a[j] - a[j1]; x0i = -a[j + 1] + a[j1 + 1]; a[j] += a[j1]; a[j + 1] = -a[j + 1] - a[j1 + 1]; a[j1] = x0r; a[j1 + 1] = x0i; } } } static void cft1st(int n, float *a, float *w) { int j, k1, k2; float wk1r, wk1i, wk2r, wk2i, wk3r, wk3i; float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; x0r = a[0] + a[2]; x0i = a[1] + a[3]; x1r = a[0] - a[2]; x1i = a[1] - a[3]; x2r = a[4] + a[6]; x2i = a[5] + a[7]; x3r = a[4] - a[6]; x3i = a[5] - a[7]; a[0] = x0r + x2r; a[1] = x0i + x2i; a[4] = x0r - x2r; a[5] = x0i - x2i; a[2] = x1r - x3i; a[3] = x1i + x3r; a[6] = x1r + x3i; a[7] = x1i - x3r; wk1r = w[2]; x0r = a[8] + a[10]; x0i = a[9] + a[11]; x1r = a[8] - a[10]; x1i = a[9] - a[11]; x2r = a[12] + a[14]; x2i = a[13] + a[15]; x3r = a[12] - a[14]; x3i = a[13] - a[15]; a[8] = x0r + x2r; a[9] = x0i + x2i; a[12] = x2i - x0i; a[13] = x0r - x2r; x0r = x1r - x3i; x0i = x1i + x3r; a[10] = wk1r * (x0r - x0i); a[11] = wk1r * (x0r + x0i); x0r = x3i + x1r; x0i = x3r - x1i; a[14] = wk1r * (x0i - x0r); a[15] = wk1r * (x0i + x0r); k1 = 0; for (j = 16; j < n; j += 16) { k1 += 2; k2 = 2 * k1; wk2r = w[k1]; wk2i = w[k1 + 1]; wk1r = w[k2]; wk1i = w[k2 + 1]; wk3r = wk1r - 2 * wk2i * wk1i; wk3i = 2 * wk2i * wk1r - wk1i; x0r = a[j] + a[j + 2]; x0i = a[j + 1] + a[j + 3]; x1r = a[j] - a[j + 2]; x1i = a[j + 1] - a[j + 3]; x2r = a[j + 4] + a[j + 6]; x2i = a[j + 5] + a[j + 7]; x3r = a[j + 4] - a[j + 6]; x3i = a[j + 5] - a[j + 7]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; x0r -= x2r; x0i -= x2i; a[j + 4] = wk2r * x0r - wk2i * x0i; a[j + 5] = wk2r * x0i + wk2i * x0r; x0r = x1r - x3i; x0i = x1i + x3r; a[j + 2] = wk1r * x0r - wk1i * x0i; a[j + 3] = wk1r * x0i + wk1i * x0r; x0r = x1r + x3i; x0i = x1i - x3r; a[j + 6] = wk3r * x0r - wk3i * x0i; a[j + 7] = wk3r * x0i + wk3i * x0r; wk1r = w[k2 + 2]; wk1i = w[k2 + 3]; wk3r = wk1r - 2 * wk2r * wk1i; wk3i = 2 * wk2r * wk1r - wk1i; x0r = a[j + 8] + a[j + 10]; x0i = a[j + 9] + a[j + 11]; x1r = a[j + 8] - a[j + 10]; x1i = a[j + 9] - a[j + 11]; x2r = a[j + 12] + a[j + 14]; x2i = a[j + 13] + a[j + 15]; x3r = a[j + 12] - a[j + 14]; x3i = a[j + 13] - a[j + 15]; a[j + 8] = x0r + x2r; a[j + 9] = x0i + x2i; x0r -= x2r; x0i -= x2i; a[j + 12] = -wk2i * x0r - wk2r * x0i; a[j + 13] = -wk2i * x0i + wk2r * x0r; x0r = x1r - x3i; x0i = x1i + x3r; a[j + 10] = wk1r * x0r - wk1i * x0i; a[j + 11] = wk1r * x0i + wk1i * x0r; x0r = x1r + x3i; x0i = x1i - x3r; a[j + 14] = wk3r * x0r - wk3i * x0i; a[j + 15] = wk3r * x0i + wk3i * x0r; } } static void cftmdl(int n, int l, float *a, float *w) { int j, j1, j2, j3, k, k1, k2, m, m2; float wk1r, wk1i, wk2r, wk2i, wk3r, wk3i; float x0r, x0i, x1r, x1i, x2r, x2i, x3r, x3i; m = l << 2; for (j = 0; j < l; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; a[j2] = x0r - x2r; a[j2 + 1] = x0i - x2i; a[j1] = x1r - x3i; a[j1 + 1] = x1i + x3r; a[j3] = x1r + x3i; a[j3 + 1] = x1i - x3r; } wk1r = w[2]; for (j = m; j < l + m; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; a[j2] = x2i - x0i; a[j2 + 1] = x0r - x2r; x0r = x1r - x3i; x0i = x1i + x3r; a[j1] = wk1r * (x0r - x0i); a[j1 + 1] = wk1r * (x0r + x0i); x0r = x3i + x1r; x0i = x3r - x1i; a[j3] = wk1r * (x0i - x0r); a[j3 + 1] = wk1r * (x0i + x0r); } k1 = 0; m2 = 2 * m; for (k = m2; k < n; k += m2) { k1 += 2; k2 = 2 * k1; wk2r = w[k1]; wk2i = w[k1 + 1]; wk1r = w[k2]; wk1i = w[k2 + 1]; wk3r = wk1r - 2 * wk2i * wk1i; wk3i = 2 * wk2i * wk1r - wk1i; for (j = k; j < l + k; j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; x0r -= x2r; x0i -= x2i; a[j2] = wk2r * x0r - wk2i * x0i; a[j2 + 1] = wk2r * x0i + wk2i * x0r; x0r = x1r - x3i; x0i = x1i + x3r; a[j1] = wk1r * x0r - wk1i * x0i; a[j1 + 1] = wk1r * x0i + wk1i * x0r; x0r = x1r + x3i; x0i = x1i - x3r; a[j3] = wk3r * x0r - wk3i * x0i; a[j3 + 1] = wk3r * x0i + wk3i * x0r; } wk1r = w[k2 + 2]; wk1i = w[k2 + 3]; wk3r = wk1r - 2 * wk2r * wk1i; wk3i = 2 * wk2r * wk1r - wk1i; for (j = k + m; j < l + (k + m); j += 2) { j1 = j + l; j2 = j1 + l; j3 = j2 + l; x0r = a[j] + a[j1]; x0i = a[j + 1] + a[j1 + 1]; x1r = a[j] - a[j1]; x1i = a[j + 1] - a[j1 + 1]; x2r = a[j2] + a[j3]; x2i = a[j2 + 1] + a[j3 + 1]; x3r = a[j2] - a[j3]; x3i = a[j2 + 1] - a[j3 + 1]; a[j] = x0r + x2r; a[j + 1] = x0i + x2i; x0r -= x2r; x0i -= x2i; a[j2] = -wk2i * x0r - wk2r * x0i; a[j2 + 1] = -wk2i * x0i + wk2r * x0r; x0r = x1r - x3i; x0i = x1i + x3r; a[j1] = wk1r * x0r - wk1i * x0i; a[j1 + 1] = wk1r * x0i + wk1i * x0r; x0r = x1r + x3i; x0i = x1i - x3r; a[j3] = wk3r * x0r - wk3i * x0i; a[j3 + 1] = wk3r * x0i + wk3i * x0r; } } } static void rftfsub(int n, float *a, int nc, float *c) { int j, k, kk, ks, m; float wkr, wki, xr, xi, yr, yi; m = n >> 1; ks = 2 * nc / m; kk = 0; for (j = 2; j < m; j += 2) { k = n - j; kk += ks; wkr = 0.5f - c[nc - kk]; wki = c[kk]; xr = a[j] - a[k]; xi = a[j + 1] + a[k + 1]; yr = wkr * xr - wki * xi; yi = wkr * xi + wki * xr; a[j] -= yr; a[j + 1] -= yi; a[k] += yr; a[k + 1] -= yi; } } static void rftbsub(int n, float *a, int nc, float *c) { int j, k, kk, ks, m; float wkr, wki, xr, xi, yr, yi; a[1] = -a[1]; m = n >> 1; ks = 2 * nc / m; kk = 0; for (j = 2; j < m; j += 2) { k = n - j; kk += ks; wkr = 0.5f - c[nc - kk]; wki = c[kk]; xr = a[j] - a[k]; xi = a[j + 1] + a[k + 1]; yr = wkr * xr + wki * xi; yi = wkr * xi - wki * xr; a[j] -= yr; a[j + 1] = yi - a[j + 1]; a[k] += yr; a[k + 1] = yi - a[k + 1]; } a[m + 1] = -a[m + 1]; } #if 0 // Not used. static void dctsub(int n, float *a, int nc, float *c) { int j, k, kk, ks, m; float wkr, wki, xr; m = n >> 1; ks = nc / n; kk = 0; for (j = 1; j < m; j++) { k = n - j; kk += ks; wkr = c[kk] - c[nc - kk]; wki = c[kk] + c[nc - kk]; xr = wki * a[j] - wkr * a[k]; a[j] = wkr * a[j] + wki * a[k]; a[k] = xr; } a[m] *= c[0]; } static void dstsub(int n, float *a, int nc, float *c) { int j, k, kk, ks, m; float wkr, wki, xr; m = n >> 1; ks = nc / n; kk = 0; for (j = 1; j < m; j++) { k = n - j; kk += ks; wkr = c[kk] - c[nc - kk]; wki = c[kk] + c[nc - kk]; xr = wki * a[k] - wkr * a[j]; a[k] = wkr * a[k] + wki * a[j]; a[j] = xr; } a[m] *= c[0]; } #endif // Not used.
the_stack_data/162643122.c
#include <stdio.h> int main(void) { printf("Hello, World\n"); return 0; }
the_stack_data/37638442.c
#include <stdio.h> int sum(int a[], int n); int main() { int a[] = {1, 2, 3, 4, 5}; printf("sum = %d\n", sum(a, 5)); for (int i = 0; i <= 5; i++) printf("%d\n", a[i]); return 0; } int sum(int a[], int n) { int sum = 0; for (int i = 0; i <= n; i++) sum += a[i]; return sum; }
the_stack_data/125122.c
/// 3.6. Scrieţi un program care să conţină apelul gets(s), unde s a fost definit ca un tablou șir de caractere. Verificaţi ce conţine fiecare element al tabloului. De ce caracterul '\n' a fost înlocuit cu '\0'? #include <stdio.h> #include <stdlib.h> int main() { char s[21]; printf("Dati un text (maxim 20 de caractere): "); fgets(s, 21, stdin); for(int i=0; i<21; i++) printf("%c, %d\n", s[i], s[i]); return 0; }
the_stack_data/51700596.c
#include <stdio.h> #define N 10 int main() { int i, j, a[N], temp; printf("Please enter 10 numbers: "); for (i = 0; i < N; i++) scanf("%d", &a[i]); for (i = 0; i < N; i++) { int min = i; for (j = i + 1; j < N; j++) if (a[min] > a[j]) min = j; if (min != i) { temp = a[min]; a[min] = a[i]; a[i] = temp; } } printf("The sort result is: "); for (i = 0; i < N; i++) printf("%d ", a[i]); printf("\n"); return 0; }
the_stack_data/75136656.c
/* Check inlining of unstructured code due to multiple return statements. Same as inlining12.c, but without multiple returns. The break statements in the switch structure */ #include <stdio.h> #define FREIA_OK 0 #define FREIA_SIZE_ERROR 1 #define FREIA_INVALID_PARAM 2 typedef int freia_error; typedef int freia_data2d; typedef int int32_t; typedef unsigned int uint32_t; extern int freia_common_check_image_bpp_compat(freia_data2d *, freia_data2d *, void *); extern int freia_common_print_backtrace(); extern int freia_aipo_copy(freia_data2d *, freia_data2d *); extern int freia_aipo_dilate_8c(freia_data2d *, freia_data2d *, int *); extern int freia_aipo_dilate_6c(freia_data2d *, freia_data2d *, int *); freia_error freia_cipo_dilate(freia_data2d *imout, freia_data2d *imin, int32_t connexity, uint32_t size) { int kernel_8c[9] = {1,1,1, 1,1,1, 1,1,1}; int kernel_6c[9] = {0, 1,1, 1,1,1, 0, 1,1}; int kernel_4c[9] = {0,1,0, 1,1,1, 0,1,0}; int i; freia_error ret; if(freia_common_check_image_bpp_compat(imout,imin,((void *)0)) != 1) { fprintf(stderr,"ERROR: file %s, line %d, function %s: " "bpp of images are not compatibles\n", "./freia.src/cipo/src/freiaComplexOpMorpho.c",90,__FUNCTION__); freia_common_print_backtrace(); ret = FREIA_SIZE_ERROR; } else if(freia_common_check_image_bpp_compat(imout,imin, ((void *)0)) != 1) { fprintf(stderr,"ERROR: file %s, line %d, function %s: " "bpp of images are not compatibles\n", "./freia.src/cipo/src/freiaComplexOpMorpho.c",95,__FUNCTION__); freia_common_print_backtrace(); ret = FREIA_SIZE_ERROR; } else if(size==0) { freia_aipo_copy(imout,imin); ret = FREIA_OK; } else switch(connexity) { case 4: freia_aipo_dilate_8c(imout,imin,kernel_4c); for(i=1 ; i<size ; i++) freia_aipo_dilate_8c(imout,imout,kernel_4c); ret = FREIA_OK; break; case 6: freia_aipo_dilate_6c(imout,imin,kernel_6c); for(i=1 ; i<size ; i++) freia_aipo_dilate_6c(imout,imout,kernel_6c); ret = FREIA_OK; break; case 8: freia_aipo_dilate_8c(imout,imin,kernel_8c); for(i=1 ; i<size ; i++) freia_aipo_dilate_8c(imout,imout,kernel_8c); ret = FREIA_OK; break; default: ret = FREIA_INVALID_PARAM; break; } return ret; } freia_error freia_cipo_outer_gradient(freia_data2d *imout, freia_data2d *imin, int32_t connexity, uint32_t size) { freia_error ret; ret = freia_cipo_dilate(imout, imin, connexity, size); ret |= freia_aipo_sub(imout,imout,imin); return ret; }
the_stack_data/14111.c
/***************************************************************************** Copyright (c) 2012 - Analog Devices Inc. All Rights Reserved. This software is proprietary & confidential to Analog Devices, Inc. and its licensors. ****************************************************************************** File Name : sv_mod.c Generation Date: 2012-05-16 Generated By: Jens Sorensen Description: This file implements a space vector modulator by calculating the zero sequence and adding it to the reference. *****************************************************************************/ /*============= C O D E =============*/ /***************************************************************************** Function: SvModulator Space Vector Modulator. Takes 3 reference voltages as input and calculates duty-cycles. Funtions called from S-function and is prototyped in S-function builder Parameters: u0,u1,u2; Pointers to voltage references u3; Pointer to modulator selector y0,y1,y2; pointers to duty-cycles (where result is stored) Returns: None *****************************************************************************/ void SvModulator(const float *u0, const float *u1, const float *u2, const unsigned char *u3, float *y0, float *y1, float *y2) { float u0_abs, u1_abs, u2_abs; // Absolute value of references float v_0; // Zero-sequence voltage if(*u3==1){ if(*u0 < 0) // Find absolute vaule of all references u0_abs = -*u0; else u0_abs = *u0; if(*u1 < 0) u1_abs = -*u1; else u1_abs = *u1; if(*u2 < 0) u2_abs = -*u2; else u2_abs = *u2; if( u0_abs<u1_abs && u0_abs<u2_abs ) // |va| is smallest v_0 = *u0*0.5; else if( u1_abs<u0_abs && u1_abs<u2_abs ) // |vb| is smallest v_0 = *u1*0.5; else // |vc| is smallest v_0 = *u2*0.5; } else{ v_0 = 0; } *y0=*u0+v_0; *y1=*u1+v_0; *y2=*u2+v_0; } /* End Of File */
the_stack_data/33657.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2011 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/>. */ void stabs_function (void) /* marker-here */ { }
the_stack_data/29824847.c
#include<stdio.h> /* The program ask the user to enter two numbers and then prints the sum, product, difference, quotient and modulus of the two numbers. */ int mainB() { int number1, number2; printf("Please enter two numbers to be operated:\n"); scanf("%d%d",&number1, &number2); printf("The sum of the %d and %d is: %d\n", number1, number2, number1+number2); printf("The product between the %d and %d is: %d\n", number1, number2, number1*number2); printf("The difference between the %d and %d is: %d\n", number1, number2, number1-number2); if(number2 != 0) printf("The quotient between the %d and %d is: %d\n", number1, number2, number1/number2); printf("The modulus between the %d and %d is: %d\n", number1, number2, number1%number2); return 0; }
the_stack_data/193892991.c
#include<stdio.h> int main() { int n; scanf("%d",&n); int Arr[n]; int i,j; for(i=0;i<n;i++) scanf("%d",&Arr[i]); for(i=1;i<n;i++) { j= i-1; int cmp= Arr[i]; while(j>=0&&Arr[j]>cmp) { Arr[j+1]=Arr[j]; j--; } Arr[j+1]=cmp; } for(i=0;i<n;i++) printf("%d ",Arr[i]); printf("\n"); }
the_stack_data/452271.c
void __div0 (void) { while (1) ; }
the_stack_data/15299.c
/* In this code, "math.h" library is used. So, when you compile the code, please add "-lm". Try this commands: $ gcc -c 1801042637.c $ gcc 1801042637.o -o 1801042637 -lm $ ./1801042637 Thank you. */ #include <stdio.h> /*standart input output library*/ #include <string.h> /*strlen(), strcpy(), strcmp() functions*/ #include <stdlib.h> /*abs() functions*/ #include <math.h> /*pow(), sqrt(), acos() functions and M_PI */ #define STRING_SIZE 10 #define ARRAY_SIZE 100 #define LINES_SIZE 100 #define COMPONENT_SIZE 20 #define ROW 500 #define COLUMN 200 #define NUMBER_COUNT 10 /*Functions and structures are defined to be called in the main and other functions*/ typedef struct { double x, y; char name_point[STRING_SIZE]; } point; typedef struct { point points_line[LINES_SIZE]; char name_line[STRING_SIZE]; } line; typedef struct { point points_poly[COMPONENT_SIZE]; line lines_poly[COMPONENT_SIZE]; char name_polygon[STRING_SIZE]; } polygon; void read_input(char* file_path, char input[ROW][COLUMN]);/*to read all the information from the file*/ void read_data(char input[ROW][COLUMN], int count_array[NUMBER_COUNT], int flag, point *points, line *lines, polygon *polygons);/*to read all the data from the file*/ void read_actions(char input[ROW][COLUMN], int count_array[NUMBER_COUNT], int flag, point *points, line *lines, polygon *polygons);/*to read all the action from the file*/ char type_object(char input[ROW][COLUMN], int flag);/*to determine type of objects*/ double distance_points(char temp2[STRING_SIZE], char temp3[STRING_SIZE], int count_array[NUMBER_COUNT], point *points);/*to find distance between two points*/ double distance_lines(char temp2[STRING_SIZE], char temp3[STRING_SIZE], int count_array[NUMBER_COUNT], point *points, line *lines);/*to finds distance between a line and a point*/ double angle(char temp2[STRING_SIZE], char temp3[STRING_SIZE], int count_array[NUMBER_COUNT], point *points, line *lines);/*to find angle between two lines*/ double area(char temp2[STRING_SIZE], int count_array[NUMBER_COUNT], point *points, polygon *polygons);/*to find are of polygon*/ double length_line(char temp2[STRING_SIZE], int count_array[NUMBER_COUNT], line *lines);/*to find length of line*/ double length_polygon (char temp2[STRING_SIZE], int count_array[NUMBER_COUNT], point *points, polygon *polygons);/*to find length of polygon*/ void main(){ char input[ROW][COLUMN] = {'\0'};/*all the inputs is in this array*/ point points[ARRAY_SIZE]; line lines[ARRAY_SIZE]; polygon polygons[ARRAY_SIZE]; int count_array[NUMBER_COUNT];/*to keep some counters*/ read_input("commands.txt", input); for(int i=0; input[i][0] != '\0'; i++){ if( strcmp(input[i], "data") == 0 ){ /*there is "data"*/ read_data(input, count_array, i+1, points, lines, polygons); } if( strcmp(input[i],"actions") == 0 ){ /*there is "actions"*/ read_actions(input, count_array, i+1, points, lines, polygons); } } } void read_input(char* file_path, char input[ROW][COLUMN]){ int inp,/*To check EOF*/ row = 0, column = 0; char c; /*to keep characters of the comment line temporarily*/ FILE *fp = fopen(file_path,"r"); if( fp == NULL){ /*the file does not exist*/ printf("Error.\n"); } else{ inp = fscanf(fp, "%c", &input[row][column]); do{ if( input[row][column] == '/' ){ column++; fscanf(fp, "%c", &input[row][column]); if( input[row][column] == '/' ){ /*there is a comment line*/ input[row][column] = '\0'; input[row][column-1] = '\0'; column-=2; fscanf(fp, "%c", &c); while(c != '\n' ){ fscanf(fp, "%c", &c); } /*end of the comment line*/ input[row][column] = c; } } if( input[row][column] == '\n' ){/*there is a new line*/ input[row][column] = '\0'; row++; column = 0; inp = fscanf(fp, "%c", &input[row][column]); } column++; inp = fscanf(fp, "%c", &input[row][column]); }while( inp != EOF ); fclose(fp); for(int i=0; i<=row; i++){ /*remove \r and SPACE from the array */ sscanf(input[i],"%[^\r]",input[i]); int j=(int)strlen(input[i])-1; while( (int)input[i][j] == 32 ){ input[i][j] = '\0'; j--; } } } } void read_data(char input[ROW][COLUMN], int count_array[NUMBER_COUNT], int flag, point *points, line *lines, polygon *polygons){ int count=0, count_point=0, count_line=0, count_poly=0, count_poly_line=0, count_poly_point=0; char temp[20]={'\0'}; sscanf(input[flag], "%d", &count); for(int i=0; i<count; i++){ switch( type_object(input, flag+i+1) ){ case 'P':/*there is a point*/ sscanf(input[flag+i+1], "%lf %lf %s", &points[count_point].x, &points[count_point].y, points[count_point].name_point ); count_point++; break; case 'L':/*there is a line*/ sscanf(input[flag+i+1], "%s %s %s", lines[count_line].points_line[0].name_point, lines[count_line].points_line[1].name_point, lines[count_line].name_line ); count_line++; break; case 'l': /*there is a polygon(lines)*/ sscanf(input[flag+i+1], "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s", polygons[count_poly].lines_poly[0].name_line, polygons[count_poly].lines_poly[1].name_line, polygons[count_poly].lines_poly[2].name_line, polygons[count_poly].lines_poly[3].name_line, polygons[count_poly].lines_poly[4].name_line, polygons[count_poly].lines_poly[5].name_line, polygons[count_poly].lines_poly[6].name_line, polygons[count_poly].lines_poly[7].name_line, polygons[count_poly].lines_poly[8].name_line, polygons[count_poly].lines_poly[9].name_line, polygons[count_poly].lines_poly[10].name_line, polygons[count_poly].lines_poly[11].name_line, polygons[count_poly].lines_poly[12].name_line, polygons[count_poly].lines_poly[13].name_line, polygons[count_poly].lines_poly[14].name_line, polygons[count_poly].lines_poly[15].name_line, polygons[count_poly].lines_poly[16].name_line, polygons[count_poly].lines_poly[17].name_line, polygons[count_poly].lines_poly[18].name_line, polygons[count_poly].lines_poly[19].name_line, polygons[count_poly].name_polygon); if( ((strlen(input[flag+i+1])+1)/4) < 21 ){ strcpy(temp, polygons[count_poly].lines_poly[((strlen(input[flag+i+1])+1)/4)-1].name_line); strcpy(polygons[count_poly].lines_poly[((strlen(input[flag+i+1])+1)/4)-1].name_line, "\0"); strcpy(polygons[count_poly].name_polygon, temp ); } count_poly++; count_poly_line++; break; case 'p': /*there is a polygon(points)*/ sscanf(input[flag+i+1], "%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s", polygons[count_poly].points_poly[0].name_point, polygons[count_poly].points_poly[1].name_point, polygons[count_poly].points_poly[2].name_point, polygons[count_poly].points_poly[3].name_point, polygons[count_poly].points_poly[4].name_point, polygons[count_poly].points_poly[5].name_point, polygons[count_poly].points_poly[6].name_point, polygons[count_poly].points_poly[7].name_point, polygons[count_poly].points_poly[8].name_point, polygons[count_poly].points_poly[9].name_point, polygons[count_poly].points_poly[10].name_point, polygons[count_poly].points_poly[11].name_point, polygons[count_poly].points_poly[12].name_point, polygons[count_poly].points_poly[13].name_point, polygons[count_poly].points_poly[14].name_point, polygons[count_poly].points_poly[15].name_point, polygons[count_poly].points_poly[16].name_point, polygons[count_poly].points_poly[17].name_point, polygons[count_poly].points_poly[18].name_point, polygons[count_poly].points_poly[19].name_point, polygons[count_poly].name_polygon); if( ((strlen(input[flag+i+1]))/3) < 21 ){ strcpy(temp, polygons[count_poly].points_poly[((strlen(input[flag+i+1]))/3)-1].name_point); strcpy(polygons[count_poly].points_poly[((strlen(input[flag+i+1]))/3)-1].name_point, "\0"); strcpy(polygons[count_poly].name_polygon, temp ); } count_poly++; count_poly_point++; break; case 'E': /*something is wrong. for example, there is empty line*/ break; } } for(int count=0; count<count_line; count++){/*to fill elements of lines[]*/ for(int i=0; i<2; i++){ for(int j=0; j<count_point; j++){ if( strcmp(lines[count].points_line[i].name_point, points[j].name_point) == 0 ){ lines[count].points_line[i].x = points[j].x; lines[count].points_line[i].y = points[j].y; } } } } for(int count=0; count<count_poly; count++){/*to fill elements of polygons[].lines_poly[]*/ for(int i=0; i<20; i++){ for(int j=0; j<count_line; j++){ for(int k=0; k<1; k++){ if( strcmp(lines[j].name_line, polygons[count].lines_poly[i].name_line) == 0 ){ strcpy(polygons[count].lines_poly[i].points_line[0].name_point, lines[j].points_line[0].name_point); strcpy(polygons[count].lines_poly[i].points_line[1].name_point, lines[j].points_line[1].name_point); polygons[count].lines_poly[i].points_line[j].x = lines[j].points_line[k].x; polygons[count].lines_poly[i].points_line[j].y = lines[j].points_line[k].y; } } } } } for(int count=0; count<count_poly; count++){/*to fill elements of polygons[].lines_poly[]*/ for(int i=0; i<20; i++){ for(int j=0; j<count_point; j++){ for(int k=0; k<1; k++){ if( strcmp(points[j].name_point, polygons[count].points_poly[i].name_point) == 0 ){ polygons[count].points_poly[i].x = points[j].x; polygons[count].points_poly[i].y = points[j].y; } } } } } /*counters are kept to use in other functions*/ count_array[0] = count_point; count_array[1] = count_line; count_array[2] = count_poly; count_array[3] = count_poly_line; count_array[4] = count_poly_point; } void read_actions(char input[ROW][COLUMN], int count_array[NUMBER_COUNT], int flag, point *points, line *lines, polygon *polygons){ char file_path[20] = {'\0'}; char temp[STRING_SIZE] = {'\0'}; int count=0, inp; char temp2[STRING_SIZE], temp3[STRING_SIZE]; sscanf(input[flag], "%s", file_path);/*a file name indicating where the results of the actions will be output*/ sscanf(input[flag+1], "%d", &count); FILE *fp = fopen(file_path,"w"); if( fp == NULL ){ /*the file could not be opened*/ printf("Error.\n"); } else{ for(int i=0; i<count; i++){ sscanf(input[flag+2+i], "%s", temp); if( strcmp( temp, "Distance" ) == 0 ){ sscanf(input[flag+2+i], "%s %s %s", temp, temp2, temp3); switch( type_object(input, flag+2+i) ){ case 'P': fprintf(fp, "%s(%s,%s) = %.1lf\n", temp, temp2, temp3, distance_points(temp2,temp3,count_array,points)); break; case 'L': fprintf(fp, "%s(%s,%s) = %.1lf\n", temp, temp2, temp3, distance_lines(temp2,temp3,count_array,points,lines)); break; default: break; } } if( strcmp( temp, "Angle" ) == 0 ){ sscanf(input[flag+2+i], "%s %s %s", temp, temp2, temp3); fprintf(fp, "%s(%s,%s) = %.1lf\n", temp, temp2, temp3, angle(temp2, temp3, count_array, points, lines)); } if( strcmp( temp, "Length" ) == 0 ){ sscanf(input[flag+2+i], "%s %s", temp, temp2); switch( type_object(input, flag+2+i) ){ case 'L': fprintf(fp, "%s(%s) = %.1lf\n", temp, temp2, length_line(temp2, count_array, lines)); break; default: fprintf(fp, "%s(%s) = %.1lf\n", temp, temp2, length_polygon(temp2, count_array, points, polygons)); break; } } if( strcmp( temp, "Area" ) == 0 ){ sscanf(input[flag+2+i], "%s %s", temp, temp2); fprintf(fp, "%s(%s) = %.1lf\n", temp, temp2, area(temp2, count_array, points, polygons)); } } } fclose(fp); } char type_object(char input[ROW][COLUMN], int flag){ char c; int counter_p=0, counter_l=0, counter_pg=0; for(int i=0; input[flag][i] != '\0'; i++){ if( input[flag][i] == 'P'){ counter_p++; } if( input[flag][i] == 'L'){ counter_l++; } if( input[flag][i] == 'P' && input[flag][i+1] == 'G'){ counter_pg++; } } if( counter_pg != 0 ){ /*there is a polygon line*/ if(counter_l > 0){ /*there is a polygon(with lines) line*/ return 'l'; } else if(counter_p > 0){/*there is a polygon(with points) line*/ return 'p'; } else{ return 'E'; } } else if( counter_l != 0 ){/*there is a line line*/ return 'L'; } else if( counter_p != 0){/*there is a point line*/ return 'P'; } else{ return 'E'; } } double distance_points(char temp2[STRING_SIZE], char temp3[STRING_SIZE], int count_array[NUMBER_COUNT], point *points){ int count_point_1=0, count_point_2=0; double x[count_array[0]],y[count_array[0]]; for(int i=0; i<count_array[0]; i++){ if( strcmp(temp2,points[i].name_point) == 0 ){ x[i] = points[i].x; y[i] = points[i].y; count_point_1 = i; } if( strcmp(temp3,points[i].name_point) == 0 ){ x[i] = points[i].x; y[i] = points[i].y; count_point_2 = i; } } return sqrt( pow((x[count_point_2] - x[count_point_1]),2) + pow((y[count_point_2] - y[count_point_1]),2) ); } double distance_lines(char temp2[STRING_SIZE], char temp3[STRING_SIZE], int count_array[NUMBER_COUNT], point *points, line *lines){ double x0[count_array[0]], y0[count_array[0]], x1[count_array[1]], x2[count_array[1]], y1[count_array[1]], y2[count_array[1]], length1, length2; double answer=0.0; int count2=0, count1=0, count0=0; for(int i=0; i<count_array[0]; i++){ if( strcmp(temp2,points[i].name_point) == 0 ){ x0[i] = points[i].x; y0[i] = points[i].y; count0 = i; } } for(int i=0; i<count_array[1]; i++){ if( strcmp(temp3, lines[i].name_line ) == 0 ){ x1[i] = lines[i].points_line[0].x; y1[i] = lines[i].points_line[0].y; x2[i] = lines[i].points_line[1].x; y2[i] = lines[i].points_line[1].y; count1=i; } } answer = (double)abs( ( (y2[count1]-y1[count1])*x0[count0] ) - ( (x2[count1]-x1[count1])*y0[count0] ) + ( x2[count1]*y1[count1] ) - ( y2[count1]*x1[count1] ) ); return answer/ sqrt( pow( y2[count1]-y1[count1], 2) + pow( x2[count1]-x1[count1], 2) ); } double angle(char temp2[STRING_SIZE], char temp3[STRING_SIZE], int count_array[NUMBER_COUNT], point *points, line *lines){ double x[count_array[1]], y[count_array[1]], x1[count_array[1]], x2[count_array[1]], y1[count_array[1]], y2[count_array[1]], length1, length2; double answer; int count2=0, count3=0, count=0; for(int i=0; i<count_array[1]; i++){ if( strcmp(temp2, lines[i].name_line ) == 0 ){ count2=i; count++; } if( strcmp(temp3, lines[i].name_line ) == 0 ){ count3=i; count++; } if(count == 2){ x1[count2] = lines[count2].points_line[0].x; y1[count2] = lines[count2].points_line[0].y; x2[count2] = lines[count2].points_line[1].x; y2[count2] = lines[count2].points_line[1].y; x[count2] = x2[count2] - x1[count2]; y[count2] = y2[count2] - y1[count2]; x1[count3] = lines[count3].points_line[0].x; y1[count3] = lines[count3].points_line[0].y; x2[count3] = lines[count3].points_line[1].x; y2[count3] = lines[count3].points_line[1].y; x[count3] = x2[count3] - x1[count3]; y[count3] = y2[count3] - y1[count3]; length1 = length_line(temp2,count_array,lines); length2 = length_line(temp3,count_array,lines); answer = ((x[count3] * x[count2]) + (y[count3] * y[count2])) / (length1 * length2); answer = acos(answer) * 180 / M_PI; if(answer == 180){ answer = 0; } return answer; } } } double length_line(char temp2[STRING_SIZE], int count_array[NUMBER_COUNT], line *lines){ int count=0, count_polypoint=0, count_polyline=0; double x1[count_array[0]],y1[count_array[0]]; double x2[count_array[0]],y2[count_array[0]]; double length_object = 0.0; for(int i=0; i<count_array[1]; i++){ if( strcmp(temp2, lines[i].name_line ) == 0 ){ x1[i] = lines[i].points_line[0].x; y1[i] = lines[i].points_line[0].y; x2[i] = lines[i].points_line[1].x; y2[i] = lines[i].points_line[1].y; count=i; } } return sqrt( pow((x2[count] - x1[count]),2) + pow((y2[count] - y1[count]),2) ); } double length_polygon (char temp2[STRING_SIZE], int count_array[NUMBER_COUNT], point *points, polygon *polygons){ int count=0, count_polypoint=0, count_polyline=0; double x1[count_array[0]],y1[count_array[0]]; double x2[count_array[0]],y2[count_array[0]]; double length_object = 0.0; for(int i=0; i<count_array[2]; i++){ if( strcmp(temp2, polygons[i].name_polygon) == 0 ){ if( polygons[i].points_poly[0].name_point[0] == 'P' ){ for(int j=0; j<20; j++){ if( polygons[i].points_poly[j].name_point[0] == 'P' ){ count_polypoint++; } } for(int j=0; j<count_polypoint-1; j++){ length_object += distance_points(polygons[i].points_poly[j].name_point,polygons[i].points_poly[j+1].name_point, count_array, points); } length_object += distance_points(polygons[i].points_poly[count_polypoint-1].name_point,polygons[i].points_poly[0].name_point, count_array, points); return length_object; } else if( polygons[i].lines_poly[0].name_line[0] == 'L' ){ for(int j=0; j<20; j++){ if( polygons[i].lines_poly[j].name_line[0] == 'L' ){ count_polyline++; } } for(int j=0; j<count_polyline; j++){ length_object += distance_points(polygons[i].lines_poly[j].points_line[0].name_point, polygons[i].lines_poly[j].points_line[1].name_point, count_array, points); } return length_object; } } } } double area(char temp2[STRING_SIZE], int count_array[NUMBER_COUNT], point *points, polygon *polygons){ int count=0, count_polypoint=0, count_polyline=0; double x1[count_array[0]],y1[count_array[0]]; double x2[count_array[0]],y2[count_array[0]]; int arr_points[25] = {-1}; double area_object = 0.0; for(int i=0; i<count_array[2]; i++){ if( strcmp(temp2, polygons[i].name_polygon ) == 0 ){ if( polygons[i].points_poly[0].name_point[0] == 'P' ){ for(int j=0; j<20; j++){ if( polygons[i].points_poly[j].name_point[0] == 'P' ){ count_polypoint++; } } for(int j=0; j<count_polypoint-1; j++){ area_object += (polygons[i].points_poly[j].x * polygons[i].points_poly[j+1].y)-(polygons[i].points_poly[j].y * polygons[i].points_poly[j+1].x); } area_object += (polygons[i].points_poly[count_polypoint-1].x * polygons[i].points_poly[0].y)-(polygons[i].points_poly[count_polypoint-1].y * polygons[i].points_poly[0].x); return (double)abs(area_object)/2.0; } else if( polygons[i].lines_poly[0].name_line[0] == 'L' ){ for(int j=0; j<20; j++){ if( polygons[i].lines_poly[j].name_line[0] == 'L' ){ count_polyline++; } } for(int j=0; j<20; j++){ for(int m=0; m<2; m++){ for(int k=0; k<count_array[0]; k++){ if( strcmp(polygons[i].lines_poly[j].points_line[m].name_point, points[k].name_point) == 0 ){ if(arr_points[k-1] != k){ arr_points[k] = k; } } } } } for(int j=0; j<count_polyline-1; j++){ area_object += (points[j].x * points[j+1].y)-( points[j].y * points[j+1].x); } area_object += (points[count_polyline-1].x * points[0].y)-( points[count_polyline-1].y * points[0].x); return (double)abs(area_object)/2.0; } } } }
the_stack_data/18887581.c
/* 작성자: vocovoco 컴파일 명령어: gcc mproc_server.c -o mproc_server 실행 방법: ./mproc_server <Port#> */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <signal.h> #include <sys/ipc.h> #include <sys/shm.h> #include <sys/wait.h> #include <arpa/inet.h> #include <sys/socket.h> #define BUF_SIZE 1024 struct shared_use{ int clnt_num; int read_clnt_num; pid_t write_clnt; char message[BUF_SIZE]; }; void* shared_memory = (void*)0; struct shared_use *shared_space; int shmid, running; void error_handling(char *message); void read_childproc(int sig); int main(int argc, char *argv[]) { int serv_sock, clnt_sock; struct sockaddr_in serv_adr, clnt_adr; pid_t pid; struct sigaction act; socklen_t adr_sz; int str_len, state; char buf[BUF_SIZE]; shmid = shmget((key_t)5555, sizeof(struct shared_use), 0666|IPC_CREAT); if(shmid == -1) { puts("shmget() error"); exit(1); } shared_memory = shmat(shmid, (void*)0, 0); if(shared_memory == (void*)-1) error_handling("shmat() error"); shared_space = (struct shared_use*)shared_memory; shared_space->clnt_num = 0; shared_space->read_clnt_num = shared_space->clnt_num - 1; strcpy(shared_space->message, "null"); if(argc != 2){ printf("Usage : %s <port>\n", argv[0]); exit(1); } act.sa_handler = read_childproc; sigemptyset(&act.sa_mask); act.sa_flags=0; sigaddset(&act.sa_mask,SIGINT); sigaddset(&act.sa_mask,SIGCHLD); state=sigaction(SIGINT, &act, 0); state=sigaction(SIGCHLD, &act, 0); serv_sock = socket(PF_INET, SOCK_STREAM, 0); memset(&serv_adr, 0, sizeof(serv_adr)); serv_adr.sin_family = AF_INET; serv_adr.sin_addr.s_addr = htonl(INADDR_ANY); serv_adr.sin_port = htons(atoi(argv[1])); if(bind(serv_sock, (struct sockaddr*) &serv_adr, sizeof(serv_adr)) == -1) error_handling("bind() error"); if(listen(serv_sock, 5) == -1) error_handling("listen() error"); while(1) { adr_sz = sizeof(clnt_adr); clnt_sock = accept(serv_sock, (struct sockaddr*)&clnt_adr, &adr_sz); if(clnt_sock == -1) continue; shmctl(shmid, SHM_LOCK, 0); shared_space->clnt_num++; shared_space->read_clnt_num++; shmctl(shmid, SHM_UNLOCK, 0); //printf("%d\n", shared_space->clnt_num); pid = fork(); if(pid == -1) { close(clnt_sock); continue; } if(pid == 0) { printf("new client %s:%d connected...\n", inet_ntoa(clnt_adr.sin_addr), getpid()); close(serv_sock); pid = fork(); if(pid == 0) { while((str_len=read(clnt_sock, buf, BUF_SIZE)) != 0) { while(1){ shmctl(shmid, SHM_LOCK, 0); if(shared_space->read_clnt_num >= (shared_space->clnt_num - 1)){ shared_space->read_clnt_num--; //puts("--------------------"); break; } shmctl(shmid, SHM_UNLOCK, 0); } shared_space->write_clnt = getppid(); strcpy(shared_space->message, buf); shmctl(shmid, SHM_UNLOCK, 0); } close(clnt_sock);//shutdown(clnt_sock, SHUT_RDWR); return 0; } running = 1; while(running) { if(strcmp(shared_space->message,"null")&&(getpid() != shared_space->write_clnt)) { shmctl(shmid, SHM_LOCK, 0); //printf("%d, %d\n", getpid(), shared_space->write_clnt); //printf("%d\n", shared_space->read_clnt_num); if((shared_space->read_clnt_num--) == 0){ //printf("%d, %d\n", shared_space->clnt_num, shared_space->read_clnt_num); sprintf(buf, "%d", (int)shared_space->write_clnt); strcat(buf, ": "); strcat(buf, shared_space->message); write(clnt_sock, buf, strlen(buf)); strcpy(shared_space->message, "null"); //printf("1: %d\n", getpid()); shared_space->read_clnt_num = shared_space->clnt_num - 1; shmctl(shmid, SHM_UNLOCK, 0); } else { sprintf(buf, "%d", (int)shared_space->write_clnt); strcat(buf, ": "); strcat(buf, shared_space->message); write(clnt_sock, buf, strlen(buf)); //printf("2: %d, %d\n", getpid(), shared_space->read_clnt_num); shmctl(shmid, SHM_UNLOCK, 0); while(strcmp(shared_space->message, "null")); } } else if(shared_space->clnt_num == 1) strcpy(shared_space->message, "null"); } printf("client %s:%d disconnected...\n", inet_ntoa(clnt_adr.sin_addr), getpid()); shmctl(shmid, SHM_LOCK, 0); shared_space->clnt_num--; shmctl(shmid, SHM_UNLOCK, 0); //printf("%d\n", shared_space->clnt_num); close(clnt_sock); return 0; } else close(clnt_sock); } close(serv_sock); return 0; } void read_childproc(int sig) { pid_t pid; int status; switch(sig) { case SIGCHLD: pid = waitpid(-1, &status, WNOHANG); if(pid > 0) running = 0; break; case SIGINT: shmdt(shared_memory); shmctl(shmid, IPC_RMID, 0); exit(1); break; } } void error_handling(char *message) { fputs(message, stderr); fputc('/n', stderr); raise(SIGINT); }
the_stack_data/1041.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 10000 typedef struct Deque { int *deque; int front, rear, size; }Deque; void init_deque(Deque* d) { d->deque = (int*)malloc(sizeof(int)*MAX); d->front=0; d->rear=0; d->size=0; } int size(Deque* d) { return d->size; } int full(Deque* d) { return ((d->rear+1)%MAX==d->front); } int empty(Deque* d) { return (d->front == d->rear); } int front(Deque* d) { if(empty(d)) return -1; return d->deque[(d->front+1)%MAX]; } int back(Deque* d) { if(empty(d)) return -1; return d->deque[d->rear]; } void push_front(Deque* d, int data) { if(full(d)) printf("덱이 포화상태입니다. 데이터 삽입을 취소합니다.\n"); else { d->deque[d->front] = data; d->front = (d->front-1+MAX) % MAX; d->size++; } } void push_back(Deque* d, int data) { if(full(d)) printf("덱이 포화상태입니다. 데이터 삽입을 취소합니다.\n"); else { d->rear = (d->rear+1) % MAX; d->deque[d->rear] = data; d->size++; } } int pop_front(Deque* d) { if(empty(d)) return -1; d->front=(d->front+1)%MAX; d->size--; return d->deque[d->front]; } int pop_back(Deque* d) { if(empty(d)) return -1; int tmp=d->deque[d->rear]; d->rear=(d->rear-1+MAX)%MAX; d->size--; return tmp; } int main(void) { Deque* deque=(Deque*)malloc(sizeof(Deque)); init_deque(deque); char Get_Com[11]; int N,num; scanf("%d",&N); for(int i=0;i<N;i++) { scanf("%s",Get_Com); if(strcmp(Get_Com,"push_front")==0) { scanf("%d",&num); push_front(deque,num); } else if(strcmp(Get_Com,"push_back")==0) { scanf("%d",&num); push_back(deque,num); } else if(strcmp(Get_Com,"front")==0) printf("%d\n",front(deque)); else if(strcmp(Get_Com,"back")==0) printf("%d\n",back(deque)); else if(strcmp(Get_Com,"empty")==0) printf("%d\n",empty(deque)); else if(strcmp(Get_Com,"size")==0) printf("%d\n",size(deque)); else if(strcmp(Get_Com,"pop_front")==0) printf("%d\n",pop_front(deque)); else if(strcmp(Get_Com,"pop_back")==0) printf("%d\n",pop_back(deque)); } return 0; }
the_stack_data/215768439.c
#define _GNU_SOURCE #include <unistd.h> #include <errno.h> #include <fcntl.h> #include "syscall.h" int __dup3(int old, int new, int flags) { int r; #ifdef SYS_dup2 if (old==new) return __syscall_ret(-EINVAL); if (flags & O_CLOEXEC) { while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY); if (r!=-ENOSYS) return __syscall_ret(r); } while ((r=__syscall(SYS_dup2, old, new))==-EBUSY); #ifndef __EMSCRIPTEN__ // CLOEXEC makes no sense for a single process if (flags & O_CLOEXEC) __syscall(SYS_fcntl, new, F_SETFD, FD_CLOEXEC); #endif #else while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY); #endif return __syscall_ret(r); } weak_alias(__dup3, dup3);
the_stack_data/125140316.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 'min_float16float16.cl' */ source_code = read_buffer("min_float16float16.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, "min_float16float16", &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_float16 *src_0_host_buffer; src_0_host_buffer = malloc(num_elem * sizeof(cl_float16)); for (int i = 0; i < num_elem; i++) src_0_host_buffer[i] = (cl_float16){{2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 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_float16), 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_float16), 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_float16 *src_1_host_buffer; src_1_host_buffer = malloc(num_elem * sizeof(cl_float16)); for (int i = 0; i < num_elem; i++) src_1_host_buffer[i] = (cl_float16){{2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 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_float16), 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_float16), 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_float16 *dst_host_buffer; dst_host_buffer = malloc(num_elem * sizeof(cl_float16)); memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_float16)); /* Create device dst buffer */ cl_mem dst_device_buffer; dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_float16), 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_float16), 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_float16)); 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/59146.c
// RUN: %shorntest %t-harness.ll %t-debug %s | OutputCheck %s // RUN: %shorntest %t-harness0.ll %t-debug0 %s -O0 | OutputCheck %s // RUN: %shorntest %t-harness1.ll %t-debug1 %s -O1 | OutputCheck %s // RUN: %shorntest %t-harness2.ll %t-debug2 %s -O2 | OutputCheck %s // RUN: %shorntest %t-harness3.ll %t-debug3 %s -O3 | OutputCheck %s // CHECK: ^unsat$ /** Convert this program into SSA **/ int nd(void); char *ndc(void); extern void __VERIFIER_error(void); int main(void) { int i; char *buf; char last; i = nd(); buf = ndc(); if (buf[i] == '\0') { int start = 0; while (start < i) { buf[start] = 'f'; start++; last = buf[start - 1]; } if (start > 1 && last != 'f') __VERIFIER_error(); } return 0; }
the_stack_data/18886609.c
/* payroll - calculate pay given time and a half for overtime * Written by: C. Severance - Tue Dec 7 22:18:41 EST 1993 */ main() { float rate,hours,pay; /* Prompt the user for hours and the rate */ printf("enter the hours worked - \n"); scanf("%f",&hours); printf("enter the pay per hour -\n"); scanf("%f",&rate); /* Calculate the pay compensating for overtime */ if ( hours > 40.0 ) { pay = rate * 40.0 + ( rate * 1.5 * (hours - 40.0)); } else { pay = rate * hours; } /* Print out the pay */ printf("pay is - %f\n",pay); }
the_stack_data/29826514.c
/* * Kerberos 5 "PA ENC TIMESTAMP" by magnum & Dhiru * * Pcap file -> input file: * 1. tshark -r capture.pcapng -T pdml > ~/capture.pdml * 2. krbng2john.py ~/capture.pdml > krb5.in * 3. Run john on krb5.in * * http://www.ietf.org/rfc/rfc4757.txt * http://www.securiteam.com/windowsntfocus/5BP0H0A6KM.html * * Input format is 'user:$krb5pa$etype$user$realm$salt$timestamp+checksum' * * NOTE: Checksum implies last 12 bytes of PA_ENC_TIMESTAMP value in AS-REQ * packet. * * Default Salt: realm + user * * AES-256 encryption & decryption of AS-REQ timestamp in Kerberos v5 * See the following RFC for more details about the crypto & algorithms used: * * RFC3961 - Encryption and Checksum Specifications for Kerberos 5 * RFC3962 - Advanced Encryption Standard (AES) Encryption for Kerberos 5 * * march 09 / kevin devine <wyse101 0x40 gmail.com> * * This software is Copyright (c) 2012 magnum, and it is hereby released to the * general public under the following terms: Redistribution and use in source * and binary forms, with or without modification, are permitted. * * This software is Copyright (c) 2012 Dhiru Kholia (dhiru at openwall.com) and * released under same terms as above */ #ifdef HAVE_OPENCL #if FMT_EXTERNS_H extern struct fmt_main fmt_opencl_krb5pa_sha1; #elif FMT_REGISTERS_H john_register_one(&fmt_opencl_krb5pa_sha1); #else #include <errno.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include "arch.h" #include "misc.h" #include "formats.h" #include "options.h" #include "common.h" #include "unicode.h" #include "config.h" #include "aes/aes.h" #include "common-opencl.h" #define OUTLEN 32 #include "opencl_pbkdf2_hmac_sha1.h" #include "gladman_hmac.h" #include "loader.h" #define FORMAT_LABEL "krb5pa-sha1-opencl" #define FORMAT_NAME "Kerberos 5 AS-REQ Pre-Auth etype 17/18" /* aes-cts-hmac-sha1-96 */ #define ALGORITHM_NAME "PBKDF2-SHA1 OpenCL" #define BENCHMARK_COMMENT "" #define BENCHMARK_LENGTH -1001 #define BINARY_SIZE 12 #define BINARY_ALIGN 4 #define SALT_SIZE sizeof(struct custom_salt) #define SALT_ALIGN 1 #define MAX_SALTLEN 52 #define MAX_REALMLEN MAX_SALTLEN #define MAX_USERLEN MAX_SALTLEN #define TIMESTAMP_SIZE 44 #define CHECKSUM_SIZE BINARY_SIZE #define TOTAL_LENGTH (14 + 2 * (CHECKSUM_SIZE + TIMESTAMP_SIZE) + MAX_REALMLEN + MAX_USERLEN + MAX_SALTLEN) #define MIN_KEYS_PER_CRYPT 1 #define MAX_KEYS_PER_CRYPT 1 #define MIN(a, b) (((a) > (b)) ? (b) : (a)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) /* This handles all sizes */ #define GETPOS(i, index) (((index) % v_width) * 4 + ((i) & ~3U) * v_width + (((i) & 3) ^ 3) + ((index) / v_width) * 64 * v_width) /* This is faster but can't handle size 3 */ //#define GETPOS(i, index) (((index) & (v_width - 1)) * 4 + ((i) & ~3U) * v_width + (((i) & 3) ^ 3) + ((index) / v_width) * 64 * v_width) #define HEXCHARS "0123456789abcdefABCDEF" static struct fmt_tests tests[] = { {"$krb5pa$18$user1$EXAMPLE.COM$$2a0e68168d1eac344da458599c3a2b33ff326a061449fcbc242b212504e484d45903c6a16e2d593912f56c93883bf697b325193d62a8be9c", "openwall"}, {"$krb5pa$18$user1$EXAMPLE.COM$$a3918bd0381107feedec8db0022bdf3ac56e534ed54d13c62a7013a47713cfc31ef4e7e572f912fa4164f76b335e588bf29c2d17b11c5caa", "openwall"}, {"$krb5pa$18$l33t$EXAMPLE.COM$$98f732b309a1d7ef2355a974842a32894d911e97150f5d57f248e1c2632fbd3735c5f156532ccae0341e6a2d779ca83a06021fe57dafa464", "openwall"}, {"$krb5pa$18$aduser$AD.EXAMPLE.COM$$64dfeee04be2b2e0423814e0df4d0f960885aca4efffe6cb5694c4d34690406071c4968abd2c153ee42d258c5e09a41269bbcd7799f478d3", "password@123"}, {"$krb5pa$18$aduser$AD.EXAMPLE.COM$$f94f755a8b4493d925094a4eb1cec630ac40411a14c9733a853516fe426637d9daefdedc0567e2bb5a83d4f89a0ad1a4b178662b6106c0ff", "password@12345678"}, {"$krb5pa$18$aduser$AD.EXAMPLE.COM$AD.EXAMPLE.COMaduser$f94f755a8b4493d925094a4eb1cec630ac40411a14c9733a853516fe426637d9daefdedc0567e2bb5a83d4f89a0ad1a4b178662b6106c0ff", "password@12345678"}, /* etype 17 hash obtained using MiTM etype downgrade attack */ {"$krb5pa$17$user1$EXAMPLE.COM$$c5461873dc13665771b98ba80be53939e906d90ae1ba79cf2e21f0395e50ee56379fbef4d0298cfccfd6cf8f907329120048fd05e8ae5df4", "openwall"}, {NULL}, }; static cl_mem mem_in, mem_out, mem_salt, mem_state, pinned_in, pinned_out; static cl_kernel pbkdf2_init, pbkdf2_loop, pbkdf2_final; static unsigned int v_width = 1; /* Vector width of kernel */ static struct custom_salt { int type; int etype; unsigned char realm[64]; unsigned char user[64]; unsigned char salt[64]; /* realm + user */ unsigned char ct[TIMESTAMP_SIZE]; } *cur_salt; static unsigned char constant[16]; static unsigned char ke_input[16]; static unsigned char ki_input[16]; static size_t key_buf_size; static unsigned int *inbuffer; static pbkdf2_salt currentsalt; static pbkdf2_out *output; static ARCH_WORD_32 (*crypt_out)[BINARY_SIZE / sizeof(ARCH_WORD_32)]; static int new_keys; #define ITERATIONS (4096 - 1) #define HASH_LOOPS 105 // Must be made from factors 3, 3, 5, 7, 13 #define STEP 0 #define SEED 128 #define OCL_CONFIG "krb5pa-sha1" static const char * warn[] = { "P xfer: " , ", init: " , ", loop: " , ", final: ", ", res xfer: " }; static int split_events[] = { 2, -1, -1 }; //This file contains auto-tuning routine(s). Has to be included after formats definitions. #include "opencl-autotune.h" #include "memdbg.h" /* ------- Helper functions ------- */ static size_t get_task_max_work_group_size() { size_t s; s = autotune_get_task_max_work_group_size(FALSE, 0, pbkdf2_init); s = MIN(s, autotune_get_task_max_work_group_size(FALSE, 0, pbkdf2_loop)); s = MIN(s, autotune_get_task_max_work_group_size(FALSE, 0, pbkdf2_final)); return s; } static size_t get_task_max_size() { return 0; } static size_t get_default_workgroup() { if (cpu(device_info[gpu_id])) return get_platform_vendor_id(platform_id) == DEV_INTEL ? 8 : 1; else return 64; } #if 0 struct fmt_main *me; #endif static void create_clobj(size_t gws, struct fmt_main *self) { gws *= v_width; key_buf_size = 64 * gws; /// Allocate memory pinned_in = clCreateBuffer(context[gpu_id], CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR, key_buf_size, NULL, &ret_code); HANDLE_CLERROR(ret_code, "Error allocating pinned in"); mem_in = clCreateBuffer(context[gpu_id], CL_MEM_READ_ONLY, key_buf_size, NULL, &ret_code); HANDLE_CLERROR(ret_code, "Error allocating mem in"); inbuffer = clEnqueueMapBuffer(queue[gpu_id], pinned_in, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, key_buf_size, 0, NULL, NULL, &ret_code); HANDLE_CLERROR(ret_code, "Error mapping page-locked memory"); mem_state = clCreateBuffer(context[gpu_id], CL_MEM_READ_WRITE, sizeof(pbkdf2_state) * gws, NULL, &ret_code); HANDLE_CLERROR(ret_code, "Error allocating mem_state"); mem_salt = clCreateBuffer(context[gpu_id], CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, sizeof(pbkdf2_salt), &currentsalt, &ret_code); HANDLE_CLERROR(ret_code, "Error allocating mem setting"); pinned_out = clCreateBuffer(context[gpu_id], CL_MEM_WRITE_ONLY | CL_MEM_ALLOC_HOST_PTR, sizeof(pbkdf2_out) * gws, NULL, &ret_code); HANDLE_CLERROR(ret_code, "Error allocating pinned out"); mem_out = clCreateBuffer(context[gpu_id], CL_MEM_WRITE_ONLY, sizeof(pbkdf2_out) * gws, NULL, &ret_code); HANDLE_CLERROR(ret_code, "Error allocating mem out"); output = clEnqueueMapBuffer(queue[gpu_id], pinned_out, CL_TRUE, CL_MAP_READ, 0, sizeof(pbkdf2_out) * gws, 0, NULL, NULL, &ret_code); HANDLE_CLERROR(ret_code, "Error mapping page-locked memory"); HANDLE_CLERROR(clSetKernelArg(pbkdf2_init, 0, sizeof(mem_in), &mem_in), "Error while setting mem_in kernel argument"); HANDLE_CLERROR(clSetKernelArg(pbkdf2_init, 1, sizeof(mem_salt), &mem_salt), "Error while setting mem_salt kernel argument"); HANDLE_CLERROR(clSetKernelArg(pbkdf2_init, 2, sizeof(mem_state), &mem_state), "Error while setting mem_state kernel argument"); HANDLE_CLERROR(clSetKernelArg(pbkdf2_loop, 0, sizeof(mem_state), &mem_state), "Error while setting mem_state kernel argument"); HANDLE_CLERROR(clSetKernelArg(pbkdf2_final, 0, sizeof(mem_salt), &mem_salt), "Error while setting mem_salt kernel argument"); HANDLE_CLERROR(clSetKernelArg(pbkdf2_final, 1, sizeof(mem_out), &mem_out), "Error while setting mem_out kernel argument"); HANDLE_CLERROR(clSetKernelArg(pbkdf2_final, 2, sizeof(mem_state), &mem_state), "Error while setting mem_state kernel argument"); crypt_out = mem_alloc(sizeof(*crypt_out) * gws); } static void release_clobj(void) { HANDLE_CLERROR(clEnqueueUnmapMemObject(queue[gpu_id], pinned_in, inbuffer, 0, NULL, NULL), "Error Unmapping mem in"); HANDLE_CLERROR(clEnqueueUnmapMemObject(queue[gpu_id], pinned_out, output, 0, NULL, NULL), "Error Unmapping mem in"); HANDLE_CLERROR(clFinish(queue[gpu_id]), "Error releasing memory mappings"); HANDLE_CLERROR(clReleaseMemObject(pinned_in), "Release pinned_in"); HANDLE_CLERROR(clReleaseMemObject(pinned_out), "Release pinned_out"); HANDLE_CLERROR(clReleaseMemObject(mem_in), "Release pinned_in"); HANDLE_CLERROR(clReleaseMemObject(mem_out), "Release mem_out"); HANDLE_CLERROR(clReleaseMemObject(mem_salt), "Release mem_salt"); HANDLE_CLERROR(clReleaseMemObject(mem_state), "Release mem state"); MEM_FREE(crypt_out); } static void done(void) { release_clobj(); HANDLE_CLERROR(clReleaseKernel(pbkdf2_init), "Release Kernel"); HANDLE_CLERROR(clReleaseKernel(pbkdf2_loop), "Release Kernel"); HANDLE_CLERROR(clReleaseKernel(pbkdf2_final), "Release Kernel"); HANDLE_CLERROR(clReleaseProgram(program[gpu_id]), "Release Program"); } /* n-fold(k-bits): * l = lcm(n,k) * r = l/k * s = k-bits | k-bits rot 13 | k-bits rot 13*2 | ... | k-bits rot 13*(r-1) * compute the 1's complement sum: * n-fold = s[0..n-1]+s[n..2n-1]+s[2n..3n-1]+..+s[(k-1)*n..k*n-1] */ /* representation: msb first, assume n and k are multiples of 8, and * that k>=16. this is the case of all the cryptosystems which are * likely to be used. this function can be replaced if that * assumption ever fails. */ /* input length is in bits */ static void nfold(unsigned int inbits, const unsigned char *in, unsigned int outbits,unsigned char *out) { int a,b,c,lcm; int byte, i, msbit; /* the code below is more readable if I make these bytes * instead of bits */ inbits >>= 3; outbits >>= 3; /* first compute lcm(n,k) */ a = outbits; b = inbits; while (b != 0) { c = b; b = a % b; a = c; } lcm = outbits*inbits/a; /* now do the real work */ memset(out, 0, outbits); byte = 0; /* this will end up cycling through k lcm(k,n)/k times, which * is correct */ for (i = lcm - 1; i >= 0; i--) { /* compute the msbit in k which gets added into this byte */ msbit = (/* first, start with the msbit in the first, unrotated byte */ ((inbits << 3) - 1) /* then, for each byte, shift to the right for each * repetition */ +(((inbits << 3) + 13) * (i / inbits)) /* last, pick out the correct byte within that * shifted repetition */ +((inbits - (i % inbits)) << 3) ) % (inbits << 3); /* pull out the byte value itself */ byte += (((in[((inbits - 1) - (msbit >> 3)) % inbits] << 8)| (in[((inbits) - (msbit>>3)) % inbits])) >>((msbit & 7) + 1)) & 0xff; /* do the addition */ byte += out[i % outbits]; out[i % outbits] = byte & 0xff; /* keep around the carry bit, if any */ byte >>= 8; } /* if there's a carry bit left over, add it back in */ if (byte) { for (i = outbits - 1; i >= 0; i--) { /* do the addition */ byte += out[i]; out[i] = byte & 0xff; /* keep around the carry bit, if any */ byte >>= 8;\ } } } static int crypt_all(int *pcount, struct db_salt *salt); static int crypt_all_benchmark(int *pcount, struct db_salt *salt); static void init(struct fmt_main *self) { unsigned char usage[5]; char build_opts[128]; static char valgo[sizeof(ALGORITHM_NAME) + 8] = ""; #if 0 me = self; #endif if ((v_width = opencl_get_vector_width(gpu_id, sizeof(cl_int))) > 1) { /* Run vectorized kernel */ snprintf(valgo, sizeof(valgo), ALGORITHM_NAME " %ux", v_width); self->params.algorithm_name = valgo; } snprintf(build_opts, sizeof(build_opts), "-DHASH_LOOPS=%u -DITERATIONS=%u -DOUTLEN=%u " "-DPLAINTEXT_LENGTH=%u -DV_WIDTH=%u", HASH_LOOPS, ITERATIONS, OUTLEN, PLAINTEXT_LENGTH, v_width); opencl_init("$JOHN/kernels/pbkdf2_hmac_sha1_kernel.cl", gpu_id, build_opts); pbkdf2_init = clCreateKernel(program[gpu_id], "pbkdf2_init", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel"); crypt_kernel = pbkdf2_loop = clCreateKernel(program[gpu_id], "pbkdf2_loop", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel"); pbkdf2_final = clCreateKernel(program[gpu_id], "pbkdf2_final", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel"); //Initialize openCL tuning (library) for this format. opencl_init_auto_setup(SEED, 2 * HASH_LOOPS, split_events, warn, 2, self, create_clobj, release_clobj, sizeof(pbkdf2_state), 0); //Auto tune execution from shared/included code. self->methods.crypt_all = crypt_all_benchmark; autotune_run(self, 4 * ITERATIONS + 4, 0, (cpu(device_info[gpu_id]) ? 1000000000 : 5000000000ULL)); self->methods.crypt_all = crypt_all; self->params.min_keys_per_crypt = local_work_size * v_width; self->params.max_keys_per_crypt = global_work_size * v_width; // generate 128 bits from 40 bits of "kerberos" string nfold(8 * 8, (unsigned char*)"kerberos", 128, constant); memset(usage,0,sizeof(usage)); usage[3] = 0x01; // key number in big-endian format usage[4] = 0xAA; // used to derive Ke nfold(sizeof(usage)*8,usage,sizeof(ke_input)*8,ke_input); memset(usage,0,sizeof(usage)); usage[3] = 0x01; // key number in big-endian format usage[4] = 0x55; // used to derive Ki nfold(sizeof(usage)*8,usage,sizeof(ki_input)*8,ki_input); } static int valid(char *ciphertext, struct fmt_main *self) { char *p, *data = ciphertext; int type, saltlen = 0; // tag is mandatory if (strncmp(ciphertext, "$krb5pa$", 8) != 0) return 0; data += 8; // etype field, 17 or 18 p = strchr(data, '$'); if (!p || p - data != 2) return 0; type = atoi(data); if (type < 17 || type > 18) return 0; data = p + 1; // user field p = strchr(data, '$'); if (!p || p - data > MAX_USERLEN) return 0; saltlen += p - data; data = p + 1; // realm field p = strchr(data, '$'); if (!p || p - data > MAX_REALMLEN) return 0; saltlen += p - data; data = p + 1; // salt field p = strchr(data, '$'); if (!p) return 0; // if salt is empty, realm.user is used instead if (p - data) saltlen = p - data; data = p + 1; // We support a max. total salt length of 52. // We could opt to emit a warning if rejected here. if(saltlen > MAX_SALTLEN) { static int warned = 0; if (!ldr_in_pot) if (!warned++) fprintf(stderr, "%s: One or more hashes rejected due to salt length limitation\n", FORMAT_LABEL); return 0; } // 56 bytes (112 hex chars) encrypted timestamp + checksum if (strlen(data) != 2 * (TIMESTAMP_SIZE + CHECKSUM_SIZE) || strspn(data, HEXCHARS) != strlen(data)) return 0; return 1; } static void *get_salt(char *ciphertext) { char *ctcopy = strdup(ciphertext); char *keeptr = ctcopy; char *p; int i; static struct custom_salt cs; ctcopy += 8; p = strtok(ctcopy, "$"); cs.etype = atoi(p); p = strtok(NULL, "$"); if (p[-1] == '$') cs.user[0] = 0; else { strcpy((char*)cs.user, p); p = strtok(NULL, "$"); } if (p[-1] == '$') cs.realm[0] = 0; else { strcpy((char*)cs.realm, p); p = strtok(NULL, "$"); } if (p[-1] == '$') { strcpy((char*)cs.salt, (char*)cs.realm); strcat((char*)cs.salt, (char*)cs.user); } else { strcpy((char*)cs.salt, p); p = strtok(NULL, "$"); } for (i = 0; i < TIMESTAMP_SIZE; i++) cs.ct[i] = atoi16[ARCH_INDEX(p[i * 2])] * 16 + atoi16[ARCH_INDEX(p[i * 2 + 1])]; MEM_FREE(keeptr); return (void *)&cs; } static void clear_keys(void) { memset(inbuffer, 0, key_buf_size); } static void set_key(char *key, int index) { int i; int length = strlen(key); for (i = 0; i < length; i++) ((char*)inbuffer)[GETPOS(i, index)] = key[i]; new_keys = 1; } static char* get_key(int index) { static char ret[PLAINTEXT_LENGTH + 1]; int i = 0; while (i < PLAINTEXT_LENGTH && (ret[i] = ((char*)inbuffer)[GETPOS(i, index)])) i++; ret[i] = 0; return ret; } static char *split(char *ciphertext, int index, struct fmt_main *pFmt) { static char out[TOTAL_LENGTH + 1]; char in[TOTAL_LENGTH + 1]; char salt[MAX_SALTLEN + 1]; char *data; char *e, *u, *r, *s, *tc; strnzcpy(in, ciphertext, sizeof(in)); tc = strrchr(in, '$'); *tc++ = 0; s = strrchr(in, '$'); *s++ = 0; r = strrchr(in, '$'); *r++ = 0; u = strrchr(in, '$'); *u++ = 0; e = in + 8; /* Default salt is user.realm */ if (!*s) { snprintf(salt, sizeof(salt), "%s%s", r, u); s = salt; } snprintf(out, sizeof(out), "$krb5pa$%s$%s$%s$%s$%s", e, u, r, s, tc); data = out + strlen(out) - 2 * (CHECKSUM_SIZE + TIMESTAMP_SIZE) - 1; strlwr(data); return out; } static void *get_binary(char *ciphertext) { static union { unsigned char c[BINARY_SIZE]; ARCH_WORD dummy; } buf; unsigned char *out = buf.c; char *p; int i; p = strrchr(ciphertext, '$') + 1 + TIMESTAMP_SIZE * 2; /* skip to checksum field */ for (i = 0; i < BINARY_SIZE; i++) { out[i] = (atoi16[ARCH_INDEX(*p)] << 4) | atoi16[ARCH_INDEX(p[1])]; p += 2; } return out; } static int get_hash_0(int index) { return crypt_out[index][0] & 0xf; } static int get_hash_1(int index) { return crypt_out[index][0] & 0xff; } static int get_hash_2(int index) { return crypt_out[index][0] & 0xfff; } static int get_hash_3(int index) { return crypt_out[index][0] & 0xffff; } static int get_hash_4(int index) { return crypt_out[index][0] & 0xfffff; } static int get_hash_5(int index) { return crypt_out[index][0] & 0xffffff; } static int get_hash_6(int index) { return crypt_out[index][0] & 0x7ffffff; } static void set_salt(void *salt) { cur_salt = (struct custom_salt *)salt; currentsalt.length = strlen((char*)cur_salt->salt); currentsalt.iterations = ITERATIONS; memcpy(currentsalt.salt, cur_salt->salt, currentsalt.length); HANDLE_CLERROR(clEnqueueWriteBuffer(queue[gpu_id], mem_salt, CL_FALSE, 0, sizeof(pbkdf2_salt), &currentsalt, 0, NULL, NULL), "Copy setting to gpu"); } static void AES_cts_encrypt(const unsigned char *in, unsigned char *out, size_t len, const AES_KEY *key, unsigned char *ivec, const int encryptp) { unsigned char tmp[AES_BLOCK_SIZE]; unsigned int i; if (encryptp) { while(len > AES_BLOCK_SIZE) { for (i = 0; i < AES_BLOCK_SIZE; i++) tmp[i] = in[i] ^ ivec[i]; AES_encrypt(tmp, out, key); memcpy(ivec, out, AES_BLOCK_SIZE); len -= AES_BLOCK_SIZE; in += AES_BLOCK_SIZE; out += AES_BLOCK_SIZE; } for (i = 0; i < len; i++) tmp[i] = in[i] ^ ivec[i]; for (; i < AES_BLOCK_SIZE; i++) tmp[i] = 0 ^ ivec[i]; AES_encrypt(tmp, out - AES_BLOCK_SIZE, key); memcpy(out, ivec, len); memcpy(ivec, out - AES_BLOCK_SIZE, AES_BLOCK_SIZE); } else { unsigned char tmp2[AES_BLOCK_SIZE]; unsigned char tmp3[AES_BLOCK_SIZE]; while(len > AES_BLOCK_SIZE * 2) { memcpy(tmp, in, AES_BLOCK_SIZE); AES_decrypt(in, out, key); for (i = 0; i < AES_BLOCK_SIZE; i++) out[i] ^= ivec[i]; memcpy(ivec, tmp, AES_BLOCK_SIZE); len -= AES_BLOCK_SIZE; in += AES_BLOCK_SIZE; out += AES_BLOCK_SIZE; } len -= AES_BLOCK_SIZE; memcpy(tmp, in, AES_BLOCK_SIZE); /* save last iv */ AES_decrypt(in, tmp2, key); memcpy(tmp3, in + AES_BLOCK_SIZE, len); memcpy(tmp3 + len, tmp2 + len, AES_BLOCK_SIZE - len); /* xor 0 */ for (i = 0; i < len; i++) out[i + AES_BLOCK_SIZE] = tmp2[i] ^ tmp3[i]; AES_decrypt(tmp3, out, key); for (i = 0; i < AES_BLOCK_SIZE; i++) out[i] ^= ivec[i]; memcpy(ivec, tmp, AES_BLOCK_SIZE); } } // keysize = 32 for 256 bits, 16 for 128 bits static void dk(unsigned char key_out[], unsigned char key_in[], size_t key_size, unsigned char ptext[], size_t ptext_size) { unsigned char iv[32]; unsigned char plaintext[32]; AES_KEY ekey; memset(iv,0,sizeof(iv)); memset(plaintext,0,sizeof(plaintext)); memcpy(plaintext,ptext,16); AES_set_encrypt_key(key_in,key_size*8,&ekey); AES_cbc_encrypt(plaintext,key_out,key_size,&ekey,iv,AES_ENCRYPT); } static void krb_decrypt(const unsigned char ciphertext[], size_t ctext_size, unsigned char plaintext[], const unsigned char key[], size_t key_size) { unsigned char iv[32]; AES_KEY ekey; memset(iv,0,sizeof(iv)); AES_set_decrypt_key(key,key_size*8,&ekey); AES_cts_encrypt(ciphertext,plaintext,ctext_size,&ekey,iv,AES_DECRYPT); } static int crypt_all(int *pcount, struct db_salt *salt) { int count = *pcount; int i; int key_size; size_t scalar_gws; global_work_size = ((count + (v_width * local_work_size - 1)) / (v_width * local_work_size)) * local_work_size; scalar_gws = global_work_size * v_width; if (cur_salt->etype == 17) key_size = 16; else key_size = 32; /// Copy data to gpu if (new_keys) { HANDLE_CLERROR(clEnqueueWriteBuffer(queue[gpu_id], mem_in, CL_FALSE, 0, key_buf_size, inbuffer, 0, NULL, NULL), "Copy data to gpu"); new_keys = 0; } /// Run kernel HANDLE_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], pbkdf2_init, 1, NULL, &global_work_size, &local_work_size, 0, NULL, firstEvent), "Run initial kernel"); for (i = 0; i < ITERATIONS / HASH_LOOPS; i++) { HANDLE_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], pbkdf2_loop, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL), "Run loop kernel"); HANDLE_CLERROR(clFinish(queue[gpu_id]), "Error running loop kernel"); opencl_process_event(); } HANDLE_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], pbkdf2_final, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL), "Run intermediate kernel"); for (i = 0; i < ITERATIONS / HASH_LOOPS; i++) { HANDLE_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], pbkdf2_loop, 1, NULL, &global_work_size, &local_work_size, 0, NULL, NULL), "Run loop kernel (2nd pass)"); HANDLE_CLERROR(clFinish(queue[gpu_id]), "Error running loop kernel"); opencl_process_event(); } HANDLE_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], pbkdf2_final, 1, NULL, &global_work_size, &local_work_size, 0, NULL, lastEvent), "Run final kernel (SHA1)"); HANDLE_CLERROR(clFinish(queue[gpu_id]), "Failed running final kernel"); /// Read the result back HANDLE_CLERROR(clEnqueueReadBuffer(queue[gpu_id], mem_out, CL_TRUE, 0, sizeof(pbkdf2_out) * scalar_gws, output, 0, NULL, NULL), "Copy result back"); #ifdef _OPENMP #pragma omp parallel for #endif for (i = 0; i < count; i++) { unsigned char base_key[32]; unsigned char Ke[32]; unsigned char plaintext[TIMESTAMP_SIZE]; //pbkdf2((const unsigned char*)saved_key[i], len, (unsigned char *)cur_salt->salt,strlen((char*)cur_salt->salt), 4096, (unsigned int*)tkey); // generate 128 bits from 40 bits of "kerberos" string // This is precomputed in init() //nfold(8 * 8, (unsigned char*)"kerberos", 128, constant); dk(base_key, (unsigned char*)output[i].dk, key_size, constant, 32); /* The "well-known constant" used for the DK function is the key usage number, * expressed as four octets in big-endian order, followed by one octet indicated below. * Kc = DK(base-key, usage | 0x99); * Ke = DK(base-key, usage | 0xAA); * Ki = DK(base-key, usage | 0x55); */ // derive Ke for decryption/encryption // This is precomputed in init() //memset(usage,0,sizeof(usage)); //usage[3] = 0x01; // key number in big-endian format //usage[4] = 0xAA; // used to derive Ke //nfold(sizeof(usage)*8,usage,sizeof(ke_input)*8,ke_input); dk(Ke, base_key, key_size, ke_input, 32); // decrypt the AS-REQ timestamp encrypted with 256-bit AES // here is enough to check the string, further computation below is required // to fully verify the checksum krb_decrypt(cur_salt->ct, TIMESTAMP_SIZE, plaintext, Ke, key_size); // Check a couple bytes from known plain (YYYYMMDDHHMMSSZ) and // bail out if we are out of luck. if (plaintext[22] == '2' && plaintext[23] == '0' && plaintext[36] == 'Z') { unsigned char Ki[32]; unsigned char checksum[20]; // derive Ki used in HMAC-SHA-1 checksum // This is precomputed in init() //memset(usage,0,sizeof(usage)); //usage[3] = 0x01; // key number in big-endian format //usage[4] = 0x55; // used to derive Ki //nfold(sizeof(usage)*8,usage,sizeof(ki_input)*8,ki_input); dk(Ki, base_key, key_size, ki_input, 32); // derive checksum of plaintext (only 96 bits used out of 160) hmac_sha1(Ki, key_size, plaintext, TIMESTAMP_SIZE, checksum, 20); memcpy(crypt_out[i], checksum, BINARY_SIZE); } else { memset(crypt_out[i], 0, BINARY_SIZE); } } return count; } static int crypt_all_benchmark(int *pcount, struct db_salt *salt) { size_t scalar_gws; size_t *lws = local_work_size ? &local_work_size : NULL; global_work_size = local_work_size ? ((*pcount + (v_width * local_work_size - 1)) / (v_width * local_work_size)) * local_work_size : *pcount / v_width; scalar_gws = global_work_size * v_width; #if 0 fprintf(stderr, "%s(%d) lws %zu gws %zu sgws %zu kpc %d/%d\n", __FUNCTION__, *pcount, local_work_size, global_work_size, scalar_gws, me->params.min_keys_per_crypt, me->params.max_keys_per_crypt); #endif /// Copy data to gpu BENCH_CLERROR(clEnqueueWriteBuffer(queue[gpu_id], mem_in, CL_FALSE, 0, key_buf_size, inbuffer, 0, NULL, multi_profilingEvent[0]), "Copy data to gpu"); /// Run kernels BENCH_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], pbkdf2_init, 1, NULL, &global_work_size, lws, 0, NULL, multi_profilingEvent[1]), "Run initial kernel"); BENCH_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], pbkdf2_loop, 1, NULL, &global_work_size, lws, 0, NULL, NULL), "Run loop kernel"); BENCH_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], pbkdf2_loop, 1, NULL, &global_work_size, lws, 0, NULL, multi_profilingEvent[2]), "Run loop kernel"); BENCH_CLERROR(clEnqueueNDRangeKernel(queue[gpu_id], pbkdf2_final, 1, NULL, &global_work_size, lws, 0, NULL, multi_profilingEvent[3]), "Run intermediate kernel"); /// Read the result back BENCH_CLERROR(clEnqueueReadBuffer(queue[gpu_id], mem_out, CL_TRUE, 0, sizeof(pbkdf2_out) * scalar_gws, output, 0, NULL, multi_profilingEvent[4]), "Copy result back"); return *pcount; } static int cmp_all(void *binary, int count) { int index = 0; for (; index < count; index++) if (!memcmp(binary, crypt_out[index], BINARY_SIZE)) return 1; return 0; } static int cmp_one(void *binary, int index) { return !memcmp(binary, crypt_out[index], BINARY_SIZE); } static int cmp_exact(char *source, int index) { return 1; } struct fmt_main fmt_opencl_krb5pa_sha1 = { { FORMAT_LABEL, FORMAT_NAME, ALGORITHM_NAME, BENCHMARK_COMMENT, BENCHMARK_LENGTH, PLAINTEXT_LENGTH, BINARY_SIZE, BINARY_ALIGN, SALT_SIZE, SALT_ALIGN, MIN_KEYS_PER_CRYPT, MAX_KEYS_PER_CRYPT, FMT_CASE | FMT_8_BIT | FMT_SPLIT_UNIFIES_CASE | FMT_OMP, #if FMT_MAIN_VERSION > 11 { NULL }, #endif tests }, { init, done, fmt_default_reset, fmt_default_prepare, valid, split, get_binary, get_salt, #if FMT_MAIN_VERSION > 11 { NULL }, #endif fmt_default_source, { fmt_default_binary_hash_0, fmt_default_binary_hash_1, fmt_default_binary_hash_2, fmt_default_binary_hash_3, fmt_default_binary_hash_4, fmt_default_binary_hash_5, fmt_default_binary_hash_6 }, fmt_default_salt_hash, set_salt, set_key, get_key, clear_keys, crypt_all, { get_hash_0, get_hash_1, get_hash_2, get_hash_3, get_hash_4, get_hash_5, get_hash_6 }, cmp_all, cmp_one, cmp_exact } }; #endif /* plugin stanza */ #endif /* HAVE_OPENCL */
the_stack_data/126702767.c
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { char cpf1[14]; char cpf2[11]; int i = 0, n = 0; printf("Digite seu cpf na forma NNN.NNN.NNN-NN: \n"); scanf("%s", cpf1); for (i = 0; i < 14; i++) { if (cpf1[i] == '.' || cpf1[i] == '-') { continue; } else { cpf2[n] = cpf1[i]; n++; } } printf("\n\n CPF formatado = %s", cpf2); return 0; }
the_stack_data/47382.c
int api_openwin(char *buf, int xsiz, int ysiz, int col_inv, char *title); void api_initmalloc(void); char *api_malloc(int size); void api_refreshwin(int win, int x0, int y0, int x1, int y1); void api_linewin(int win, int x0, int y0, int x1, int y1, int col); int api_getkey(int mode); void api_end(void); unsigned char rgb2pal(int r, int g, int b, int x, int y); void HariMain(void) { char *buf; int win, x, y; api_initmalloc(); buf = api_malloc(144 * 164); win = api_openwin(buf, 144, 164, -1, "color2"); for (y = 0; y < 128; y++) { for (x = 0; x < 128; x++) { buf[(x + 8) + (y + 28) * 144] = rgb2pal(x * 2, y * 2, 0, x, y); } } api_refreshwin(win, 8, 28, 136, 156); api_getkey(1); /* てきとうなキー入力を待つ */ api_end(); } unsigned char rgb2pal(int r, int g, int b, int x, int y) { static int table[4] = {3, 1, 0, 2}; int i; x &= 1; /* 偶数か奇数か */ y &= 1; i = table[x + y * 2]; /* 中間色を作るための定数 */ r = (r * 21) / 256; /* これで 0〜20 になる */ g = (g * 21) / 256; b = (b * 21) / 256; r = (r + i) / 4; /* これで 0〜5 になる */ g = (g + i) / 4; b = (b + i) / 4; return 16 + r + g * 6 + b * 36; }
the_stack_data/328327.c
#include<stdio.h> #define str(x) #x #define Xstr(X) str(X) #define oper multiply main() { char *opername=Xstr(Addition); printf("%s",opername); }
the_stack_data/232956817.c
#include <stdio.h> void scilab_rt_errbar_d2i2i2d2_(int in00, int in01, double matrixin0[in00][in01], int in10, int in11, int matrixin1[in10][in11], int in20, int in21, int matrixin2[in20][in21], int in30, int in31, double matrixin3[in30][in31]) { int i; int j; double val0 = 0; int val1 = 0; int val2 = 0; double val3 = 0; for (i = 0; i < in00; ++i) { for (j = 0; j < in01; ++j) { val0 += matrixin0[i][j]; } } printf("%f", val0); for (i = 0; i < in10; ++i) { for (j = 0; j < in11; ++j) { val1 += matrixin1[i][j]; } } printf("%d", val1); for (i = 0; i < in20; ++i) { for (j = 0; j < in21; ++j) { val2 += matrixin2[i][j]; } } printf("%d", val2); for (i = 0; i < in30; ++i) { for (j = 0; j < in31; ++j) { val3 += matrixin3[i][j]; } } printf("%f", val3); }
the_stack_data/995712.c
// KMSAN: uninit-value in rds_connect // https://syzkaller.appspot.com/bug?id=f4e61c010416c1e6f0fa3ffe247561b60a50ad71 // status:fixed // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <endian.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/syscall.h> #include <sys/types.h> #include <unistd.h> uint64_t r[1] = {0xffffffffffffffff}; int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); long res = 0; res = syscall(__NR_socket, 0x15, 5, 0); if (res != -1) r[0] = res; *(uint16_t*)0x20000080 = 2; *(uint16_t*)0x20000082 = htobe16(0); *(uint32_t*)0x20000084 = htobe32(0xe0000002); *(uint8_t*)0x20000088 = 0; *(uint8_t*)0x20000089 = 0; *(uint8_t*)0x2000008a = 0; *(uint8_t*)0x2000008b = 0; *(uint8_t*)0x2000008c = 0; *(uint8_t*)0x2000008d = 0; *(uint8_t*)0x2000008e = 0; *(uint8_t*)0x2000008f = 0; syscall(__NR_connect, r[0], 0x20000080, 0); *(uint32_t*)0x20000200 = 4; syscall(__NR_getsockopt, -1, 1, 0x2f, 0x200001c0, 0x20000200); memcpy((void*)0x20000080, "\x0a\x5c\xc8\x07\x00\x31\x5f\x85\x71\x50\x70", 11); syscall(__NR_ioctl, -1, 0x8912, 0x20000080); *(uint16_t*)0x200013c0 = 0x11; *(uint16_t*)0x200013c2 = htobe16(0); *(uint32_t*)0x200013c4 = 0; *(uint16_t*)0x200013c8 = 1; *(uint8_t*)0x200013ca = 1; *(uint8_t*)0x200013cb = 6; *(uint8_t*)0x200013cc = 0xaa; *(uint8_t*)0x200013cd = 0xaa; *(uint8_t*)0x200013ce = 0xaa; *(uint8_t*)0x200013cf = 0xaa; *(uint8_t*)0x200013d0 = 0xaa; *(uint8_t*)0x200013d1 = 0xaa; *(uint8_t*)0x200013d2 = 0; *(uint8_t*)0x200013d3 = 0; *(uint64_t*)0x20001440 = 0x20000380; *(uint64_t*)0x20001448 = 0x1000; *(uint64_t*)0x20001450 = 0x20001380; *(uint64_t*)0x20001458 = 0x20; syscall(__NR_setsockopt, -1, 0x114, 7, 0x200013c0, 0xa0); return 0; }
the_stack_data/154830798.c
//@ ltl invariant negative: ( ( ([] (<> (! AP((10.0 <= tot_transm_time))))) || (! ([] (<> ( (! AP((mgr_l != 0))) && (X AP((mgr_l != 0)))))))) || (! ([] (<> AP((1.0 <= _diverge_delta)))))); extern float __VERIFIER_nondet_float(void); extern int __VERIFIER_nondet_int(void); char __VERIFIER_nondet_bool(void) { return __VERIFIER_nondet_int() != 0; } float _diverge_delta, _x__diverge_delta; char st2_evt1, _x_st2_evt1; char st2_evt0, _x_st2_evt0; float st2_req_time, _x_st2_req_time; char st2_l, _x_st2_l; char st1_evt1, _x_st1_evt1; char st1_evt0, _x_st1_evt0; float delta, _x_delta; char st1_l, _x_st1_l; float tot_transm_time, _x_tot_transm_time; float st0_req_time, _x_st0_req_time; char mgr_l, _x_mgr_l; float mgr_c, _x_mgr_c; float mgr_timeout, _x_mgr_timeout; char mgr_evt0, _x_mgr_evt0; char mgr_evt1, _x_mgr_evt1; char st0_l, _x_st0_l; char st0_evt0, _x_st0_evt0; char st0_evt1, _x_st0_evt1; float st1_req_time, _x_st1_req_time; int main() { _diverge_delta = __VERIFIER_nondet_float(); st2_evt1 = __VERIFIER_nondet_bool(); st2_evt0 = __VERIFIER_nondet_bool(); st2_req_time = __VERIFIER_nondet_float(); st2_l = __VERIFIER_nondet_bool(); st1_evt1 = __VERIFIER_nondet_bool(); st1_evt0 = __VERIFIER_nondet_bool(); delta = __VERIFIER_nondet_float(); st1_l = __VERIFIER_nondet_bool(); tot_transm_time = __VERIFIER_nondet_float(); st0_req_time = __VERIFIER_nondet_float(); mgr_l = __VERIFIER_nondet_bool(); mgr_c = __VERIFIER_nondet_float(); mgr_timeout = __VERIFIER_nondet_float(); mgr_evt0 = __VERIFIER_nondet_bool(); mgr_evt1 = __VERIFIER_nondet_bool(); st0_l = __VERIFIER_nondet_bool(); st0_evt0 = __VERIFIER_nondet_bool(); st0_evt1 = __VERIFIER_nondet_bool(); st1_req_time = __VERIFIER_nondet_float(); int __ok = (((((st2_l != 0) && (((st2_evt1 != 0) && ( !(st2_evt0 != 0))) || ((( !(st2_evt0 != 0)) && ( !(st2_evt1 != 0))) || ((st2_evt0 != 0) && ( !(st2_evt1 != 0)))))) && ( !(st2_req_time <= 0.0))) && ((((st1_l != 0) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((( !(st1_evt0 != 0)) && ( !(st1_evt1 != 0))) || ((st1_evt0 != 0) && ( !(st1_evt1 != 0)))))) && ( !(st1_req_time <= 0.0))) && ((((st0_l != 0) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((( !(st0_evt0 != 0)) && ( !(st0_evt1 != 0))) || ((st0_evt0 != 0) && ( !(st0_evt1 != 0)))))) && ( !(st0_req_time <= 0.0))) && (((((mgr_l != 0) && (((mgr_evt1 != 0) && ( !(mgr_evt0 != 0))) || ((( !(mgr_evt0 != 0)) && ( !(mgr_evt1 != 0))) || ((mgr_evt0 != 0) && ( !(mgr_evt1 != 0)))))) && ((mgr_c == 0.0) && (mgr_timeout == 0.0))) && ((mgr_l != 0) || (mgr_c <= mgr_timeout))) && ((tot_transm_time == 0.0) && (0.0 <= delta)))))) && (delta == _diverge_delta)); while (__ok) { _x__diverge_delta = __VERIFIER_nondet_float(); _x_st2_evt1 = __VERIFIER_nondet_bool(); _x_st2_evt0 = __VERIFIER_nondet_bool(); _x_st2_req_time = __VERIFIER_nondet_float(); _x_st2_l = __VERIFIER_nondet_bool(); _x_st1_evt1 = __VERIFIER_nondet_bool(); _x_st1_evt0 = __VERIFIER_nondet_bool(); _x_delta = __VERIFIER_nondet_float(); _x_st1_l = __VERIFIER_nondet_bool(); _x_tot_transm_time = __VERIFIER_nondet_float(); _x_st0_req_time = __VERIFIER_nondet_float(); _x_mgr_l = __VERIFIER_nondet_bool(); _x_mgr_c = __VERIFIER_nondet_float(); _x_mgr_timeout = __VERIFIER_nondet_float(); _x_mgr_evt0 = __VERIFIER_nondet_bool(); _x_mgr_evt1 = __VERIFIER_nondet_bool(); _x_st0_l = __VERIFIER_nondet_bool(); _x_st0_evt0 = __VERIFIER_nondet_bool(); _x_st0_evt1 = __VERIFIER_nondet_bool(); _x_st1_req_time = __VERIFIER_nondet_float(); __ok = (((((((((_x_st2_evt1 != 0) && ( !(_x_st2_evt0 != 0))) || ((( !(_x_st2_evt0 != 0)) && ( !(_x_st2_evt1 != 0))) || ((_x_st2_evt0 != 0) && ( !(_x_st2_evt1 != 0))))) && ( !(_x_st2_req_time <= 0.0))) && ((((st2_l != 0) == (_x_st2_l != 0)) && (st2_req_time == _x_st2_req_time)) || ( !(( !(delta <= 0.0)) || ((st2_evt1 != 0) && ( !(st2_evt0 != 0))))))) && ((((( !(st2_evt0 != 0)) && ( !(st2_evt1 != 0))) && ( !(_x_st2_l != 0))) && ((st2_req_time == _x_st2_req_time) && (_x_mgr_timeout == st2_req_time))) || ( !((st2_l != 0) && ((delta == 0.0) && ((( !(st2_evt0 != 0)) && ( !(st2_evt1 != 0))) || ((st2_evt0 != 0) && ( !(st2_evt1 != 0))))))))) && ((((st2_evt0 != 0) && ( !(st2_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st2_l != 0))) || ( !(( !(st2_l != 0)) && ((delta == 0.0) && ((( !(st2_evt0 != 0)) && ( !(st2_evt1 != 0))) || ((st2_evt0 != 0) && ( !(st2_evt1 != 0))))))))) && ((((((((_x_st1_evt1 != 0) && ( !(_x_st1_evt0 != 0))) || ((( !(_x_st1_evt0 != 0)) && ( !(_x_st1_evt1 != 0))) || ((_x_st1_evt0 != 0) && ( !(_x_st1_evt1 != 0))))) && ( !(_x_st1_req_time <= 0.0))) && ((((st1_l != 0) == (_x_st1_l != 0)) && (st1_req_time == _x_st1_req_time)) || ( !(( !(delta <= 0.0)) || ((st1_evt1 != 0) && ( !(st1_evt0 != 0))))))) && ((((( !(st1_evt0 != 0)) && ( !(st1_evt1 != 0))) && ( !(_x_st1_l != 0))) && ((st1_req_time == _x_st1_req_time) && (_x_mgr_timeout == st1_req_time))) || ( !((st1_l != 0) && ((delta == 0.0) && ((( !(st1_evt0 != 0)) && ( !(st1_evt1 != 0))) || ((st1_evt0 != 0) && ( !(st1_evt1 != 0))))))))) && ((((st1_evt0 != 0) && ( !(st1_evt1 != 0))) && (( !(mgr_c <= 0.0)) && (_x_st1_l != 0))) || ( !(( !(st1_l != 0)) && ((delta == 0.0) && ((( !(st1_evt0 != 0)) && ( !(st1_evt1 != 0))) || ((st1_evt0 != 0) && ( !(st1_evt1 != 0))))))))) && ((((((((_x_st0_evt1 != 0) && ( !(_x_st0_evt0 != 0))) || ((( !(_x_st0_evt0 != 0)) && ( !(_x_st0_evt1 != 0))) || ((_x_st0_evt0 != 0) && ( !(_x_st0_evt1 != 0))))) && ( !(_x_st0_req_time <= 0.0))) && ((((st0_l != 0) == (_x_st0_l != 0)) && (st0_req_time == _x_st0_req_time)) || ( !(( !(delta <= 0.0)) || ((st0_evt1 != 0) && ( !(st0_evt0 != 0))))))) && ((((( !(st0_evt0 != 0)) && ( !(st0_evt1 != 0))) && ( !(_x_st0_l != 0))) && ((st0_req_time == _x_st0_req_time) && (_x_mgr_timeout == st0_req_time))) || ( !((st0_l != 0) && ((delta == 0.0) && ((( !(st0_evt0 != 0)) && ( !(st0_evt1 != 0))) || ((st0_evt0 != 0) && ( !(st0_evt1 != 0))))))))) && ((((st0_evt0 != 0) && ( !(st0_evt1 != 0))) && ((_x_st0_l != 0) && ( !(mgr_c <= 0.0)))) || ( !(( !(st0_l != 0)) && ((delta == 0.0) && ((( !(st0_evt0 != 0)) && ( !(st0_evt1 != 0))) || ((st0_evt0 != 0) && ( !(st0_evt1 != 0))))))))) && ((((((((_x_mgr_evt1 != 0) && ( !(_x_mgr_evt0 != 0))) || ((( !(_x_mgr_evt0 != 0)) && ( !(_x_mgr_evt1 != 0))) || ((_x_mgr_evt0 != 0) && ( !(_x_mgr_evt1 != 0))))) && ((_x_mgr_l != 0) || (_x_mgr_c <= _x_mgr_timeout))) && (((((mgr_l != 0) == (_x_mgr_l != 0)) && ((delta + (mgr_c + (-1.0 * _x_mgr_c))) == 0.0)) && (mgr_timeout == _x_mgr_timeout)) || ( !(((mgr_evt1 != 0) && ( !(mgr_evt0 != 0))) || ( !(delta <= 0.0)))))) && (((( !(mgr_evt0 != 0)) && ( !(mgr_evt1 != 0))) && (( !(_x_mgr_l != 0)) && (_x_mgr_c == 0.0))) || ( !((mgr_l != 0) && (((( !(mgr_evt0 != 0)) && ( !(mgr_evt1 != 0))) || ((mgr_evt0 != 0) && ( !(mgr_evt1 != 0)))) && (delta == 0.0)))))) && ((((_x_mgr_l != 0) && ((mgr_evt0 != 0) && ( !(mgr_evt1 != 0)))) && ((_x_mgr_c == 0.0) && (_x_mgr_timeout == 0.0))) || ( !(( !(mgr_l != 0)) && (((( !(mgr_evt0 != 0)) && ( !(mgr_evt1 != 0))) || ((mgr_evt0 != 0) && ( !(mgr_evt1 != 0)))) && (delta == 0.0)))))) && ((((((((0.0 <= _x_delta) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st1_evt1 != 0) && ( !(st1_evt0 != 0))))) && (((st0_evt1 != 0) && ( !(st0_evt0 != 0))) || ((st2_evt1 != 0) && ( !(st2_evt0 != 0))))) && (((st1_evt1 != 0) && ( !(st1_evt0 != 0))) || ((st2_evt1 != 0) && ( !(st2_evt0 != 0))))) && ((( !(mgr_evt0 != 0)) && ( !(mgr_evt1 != 0))) == ((( !(st2_evt0 != 0)) && ( !(st2_evt1 != 0))) || ((( !(st0_evt0 != 0)) && ( !(st0_evt1 != 0))) || (( !(st1_evt0 != 0)) && ( !(st1_evt1 != 0))))))) && (((mgr_evt0 != 0) && ( !(mgr_evt1 != 0))) == (((st2_evt0 != 0) && ( !(st2_evt1 != 0))) || (((st0_evt0 != 0) && ( !(st0_evt1 != 0))) || ((st1_evt0 != 0) && ( !(st1_evt1 != 0))))))) && (((tot_transm_time + ((-1.0 * _x_tot_transm_time) + mgr_c)) == 0.0) || ( !((_x_mgr_l != 0) && ( !(mgr_l != 0)))))) && (((_x_mgr_l != 0) && ( !(mgr_l != 0))) || (tot_transm_time == _x_tot_transm_time))))))) && (((delta == _x__diverge_delta) || ( !(1.0 <= _diverge_delta))) && ((1.0 <= _diverge_delta) || ((delta + (_diverge_delta + (-1.0 * _x__diverge_delta))) == 0.0)))); _diverge_delta = _x__diverge_delta; st2_evt1 = _x_st2_evt1; st2_evt0 = _x_st2_evt0; st2_req_time = _x_st2_req_time; st2_l = _x_st2_l; st1_evt1 = _x_st1_evt1; st1_evt0 = _x_st1_evt0; delta = _x_delta; st1_l = _x_st1_l; tot_transm_time = _x_tot_transm_time; st0_req_time = _x_st0_req_time; mgr_l = _x_mgr_l; mgr_c = _x_mgr_c; mgr_timeout = _x_mgr_timeout; mgr_evt0 = _x_mgr_evt0; mgr_evt1 = _x_mgr_evt1; st0_l = _x_st0_l; st0_evt0 = _x_st0_evt0; st0_evt1 = _x_st0_evt1; st1_req_time = _x_st1_req_time; } }
the_stack_data/122015208.c
#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> void executeredirect(char *s, int in, int out); int makeargv(const char *s, const char *delimiters, char ***argvp); static void perror_exit(char *s) { perror(s); exit(1); } void executecmd(char *cmds) { int child; int count; int fds[2]; int i; char **pipelist; count = makeargv(cmds, "|", &pipelist); if (count <= 0) { fprintf(stderr, "Failed to find any commands\n"); exit(1); } for (i = 0; i < count - 1; i++) { /* handle all but last one */ if (pipe(fds) == -1) perror_exit("Failed to create pipes"); else if ((child = fork()) == -1) perror_exit("Failed to create process to run command"); else if (child) { /* parent code */ if (dup2(fds[1], STDOUT_FILENO) == -1) perror_exit("Failed to connect pipeline"); if (close(fds[0]) || close(fds[1])) perror_exit("Failed to close needed files"); executeredirect(pipelist[i], i==0, 0); exit(1); } if (dup2(fds[0], STDIN_FILENO) == -1) /* child code */ perror_exit("Failed to connect last component"); if (close(fds[0]) || close(fds[1])) perror_exit("Failed to do final close"); } executeredirect(pipelist[i], i==0, 1); /* handle the last one */ exit(1); }
the_stack_data/80182.c
/****************************************************************************** * $Id$ * * Project: OGR * Purpose: Generate a mapping table from a 1-byte encoding to unicode, * for ogr_expat.cpp * Author: Even Rouault, even dot rouault at mines dash paris dot org * ****************************************************************************** * Copyright (c) 2012, Even Rouault <even dot rouault at mines-paris dot org> * * 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 <errno.h> #include <iconv.h> #include <stdio.h> #include <stdlib.h> #include <string.h> static unsigned utf8decode(const char* p, const char* end, int* len) { unsigned char c = *(unsigned char*)p; if (c < 0x80) { *len = 1; return c; #if ERRORS_TO_CP1252 } else if (c < 0xa0) { *len = 1; return cp1252[c-0x80]; #endif } else if (c < 0xc2) { goto FAIL; } if (p+1 >= end || (p[1]&0xc0) != 0x80) goto FAIL; if (c < 0xe0) { *len = 2; return ((p[0] & 0x1f) << 6) + ((p[1] & 0x3f)); } else if (c == 0xe0) { if (((unsigned char*)p)[1] < 0xa0) goto FAIL; goto UTF8_3; #if STRICT_RFC3629 } else if (c == 0xed) { // RFC 3629 says surrogate chars are illegal. if (((unsigned char*)p)[1] >= 0xa0) goto FAIL; goto UTF8_3; } else if (c == 0xef) { // 0xfffe and 0xffff are also illegal characters if (((unsigned char*)p)[1]==0xbf && ((unsigned char*)p)[2]>=0xbe) goto FAIL; goto UTF8_3; #endif } else if (c < 0xf0) { UTF8_3: if (p+2 >= end || (p[2]&0xc0) != 0x80) goto FAIL; *len = 3; return ((p[0] & 0x0f) << 12) + ((p[1] & 0x3f) << 6) + ((p[2] & 0x3f)); } else if (c == 0xf0) { if (((unsigned char*)p)[1] < 0x90) goto FAIL; goto UTF8_4; } else if (c < 0xf4) { UTF8_4: if (p+3 >= end || (p[2]&0xc0) != 0x80 || (p[3]&0xc0) != 0x80) goto FAIL; *len = 4; #if STRICT_RFC3629 // RFC 3629 says all codes ending in fffe or ffff are illegal: if ((p[1]&0xf)==0xf && ((unsigned char*)p)[2] == 0xbf && ((unsigned char*)p)[3] >= 0xbe) goto FAIL; #endif return ((p[0] & 0x07) << 18) + ((p[1] & 0x3f) << 12) + ((p[2] & 0x3f) << 6) + ((p[3] & 0x3f)); } else if (c == 0xf4) { if (((unsigned char*)p)[1] > 0x8f) goto FAIL; // after 0x10ffff goto UTF8_4; } else { FAIL: *len = 1; #if ERRORS_TO_ISO8859_1 return c; #else return 0xfffd; // Unicode REPLACEMENT CHARACTER #endif } } int main(int argc, char* argv[]) { iconv_t sConv; const char* pszSrcEncoding; const char* pszDstEncoding = "UTF-8"; int i; int nLastIdentical = -1; if( argc != 2 ) { fprintf(stderr, "Usage: generate_encoding_table encoding_name\n"); return 1; } pszSrcEncoding = argv[1]; sConv = iconv_open( pszDstEncoding, pszSrcEncoding ); if ( sConv == (iconv_t)-1 ) { fprintf(stderr, "Recode from %s to %s failed with the error: \"%s\".", pszSrcEncoding, pszDstEncoding, strerror(errno) ); return 1; } for(i = 0; i < 256; i++) { char szSrcBuf[2] = {(char)i, 0}; char szDstBuf[5] = {0,0,0,0,0}; char *pszSrcBuf = szSrcBuf; char *pszDstBuf = szDstBuf; size_t nSrcLen = strlen( szSrcBuf ); size_t nDstLen = sizeof(szDstBuf); size_t nConverted = iconv( sConv, &pszSrcBuf, &nSrcLen, &pszDstBuf, &nDstLen ); int nUnicode = -1; if( nConverted == -1 ) { if ( errno == EILSEQ ) { /* fprintf(stderr, "EILSEQ for %d\n", i); */ } else if ( errno == E2BIG ) { fprintf(stderr, "E2BIG for %d\n", i); return 1; } else { fprintf(stderr, "other error for %d\n", i); return 1; } } else { int len; nUnicode = utf8decode(szDstBuf, szDstBuf + strlen(szDstBuf), &len); if( nUnicode == 0xfffd ) nUnicode = -1; } if( nLastIdentical >= 0 && i != nUnicode ) { if( nLastIdentical + 1 == i ) printf("info->map[0x%02X] = 0x%02X;\n", nLastIdentical, nLastIdentical); else { printf("for(i = 0x%02X; i < 0x%02X; i++)\n", nLastIdentical, i); printf(" info->map[i] = i;\n"); } nLastIdentical = -1; } if( nUnicode < 0 ) printf("info->map[0x%02X] = -1;\n", i); else if (nUnicode <= 0xFF ) { if( i == nUnicode ) { if( nLastIdentical < 0 ) nLastIdentical = i; } else printf("info->map[0x%02X] = 0x%02X;\n", i, nUnicode); } else if (nUnicode <= 0xFFFF ) printf("info->map[0x%02X] = 0x%04X;\n", i, nUnicode); else if (nUnicode <= 0xFFFFFF ) printf("info->map[0x%02X] = 0x%06X;\n", i, nUnicode); else printf("info->map[0x%02X] = 0x%08X;\n", i, nUnicode); } if( nLastIdentical >= 0 ) { if( nLastIdentical + 1 == i ) printf("info->map[0x%02X] = 0x%02X;\n", nLastIdentical, nLastIdentical); else { printf("for(i = 0x%02X; i < 0x%02X; i++)\n", nLastIdentical, i); printf(" info->map[i] = i;\n"); } nLastIdentical = -1; } iconv_close( sConv ); return 0; }
the_stack_data/93886744.c
/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */ /* EMACS_MODES: !fill, lnumb, !overwrite, !nodelete, !picture */ /** ** mergelist() - ADD CONTENT OF ONE LIST TO ANOTHER **/ int #if defined(__STDC__) mergelist ( char *** dstlist, char ** srclist ) #else mergelist (dstlist, srclist) register char ***dstlist, **srclist; #endif { if (!srclist || !*srclist) return (0); while (*srclist) if (addlist(dstlist, *srclist++) == -1) return (-1); return (0); }
the_stack_data/154831410.c
#include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/syscall.h> struct message { int i; int j; }; void *hello(struct message *str) { printf("child,the tid=%lu,pid=%ld\n",pthread_self(),syscall(SYS_gettid)); printf("the arg.i is %d,arg.j is %d\n",str->i,str->j); while(1); } int main(int argc,char *agrv[]) { struct message test; pthread_t thread_id; test.i=10; test.j=20; pthread_create(&thread_id,NULL,(void *)*hello,&test); printf("parent,the tid=%lu,pid=%ld\n",pthread_self(),syscall(SYS_gettid)); pthread_join(thread_id,NULL); }
the_stack_data/73574149.c
// Practica tema 5 , Ivanov Manov Istaliyan #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/unistd.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netinet/ip.h> #include <errno.h> #define MAX_CADENA 81 int main (int argc , char *argv[]){ int puerto; //En este caso solo se puede definir el numero de puerto en el que va a estar escuchando el servidor if (argc == 3){ //Comprobamos que si se introducen 2 argumentos el primero sea -p if(strcmp(argv[1] , "-p") != 0){ printf("El primer argumento no es valido \n"); exit(EXIT_FAILURE); } sscanf(argv[2] , "%d" , &puerto); puerto = htons(puerto); }else if (argc == 1){ //Si no hay argumentos es que por defecto se escucha en el puerto 5 puerto= htons(5); }else { //Si los argumentos no cumplen las condiciones necesarias se muestra un mensaje de error printf("Numero de argumentos invalido \n"); exit(EXIT_FAILURE); } //Creamos el socket en el que va a estar nuestro servicio escuchando int socketServidor = socket(AF_INET , SOCK_DGRAM , 0); if (socketServidor < 0 ){ perror("socket()"); exit(EXIT_FAILURE); } //Creamos la estructura necesaria para asignarle una direccion IP al socket creado //Estaráescuchando en el puerto indicado, por defecto el 5 struct sockaddr_in myaddr; myaddr.sin_family = AF_INET; myaddr.sin_port = puerto; myaddr.sin_addr.s_addr = INADDR_ANY; //Se enlaza el socket con la direccion que hemos indicado en la estructura myaddr int enlace = bind(socketServidor , (struct sockaddr *) &myaddr , sizeof(myaddr)); if (enlace < 0){ perror("bind()"); exit(EXIT_FAILURE); } //Creamos un buffer donde vamos a almacenar la cadena que nos llegue char cadenaEntrante[MAX_CADENA]; struct sockaddr_in direccion_cliente; socklen_t tamano = sizeof(cadenaEntrante); //Iniciamos un bucle infinito que va a recibir cadenas de caracteres, pasarlas //a mayusculas y enviarlas de nuevo a la IP de la que provienen while(1){ //Dejamos el buffer vacio para que no haya caracteres que no se corresponden con lo enviado memset(cadenaEntrante , 0 ,sizeof(cadenaEntrante)); //Recibimos una cadena de un cliente y la almacenamos en nuestro buffer int recibe = recvfrom(socketServidor , &cadenaEntrante , sizeof(cadenaEntrante) , 0 , (struct sockaddr *) &direccion_cliente , &tamano ); if(recibe < 0){ perror("recvfrom()"); exit(EXIT_FAILURE); } //Recorremos la cadena y pasamos a mayuscula los caracteres que se correspondan a las letras minusculas. //Para ello restamos 32 ya que es la diferencia que se indica en la tabla ASCII. int i; for(i = 0; i < sizeof(cadenaEntrante) ; i++ ){ if(cadenaEntrante[i] >= 'a' && cadenaEntrante[i] <= 'z' ){ cadenaEntrante[i] -= 32; } } //Enviamos la cadena que acabamos de modificar al cliente del que hemos recibido la solicitud. int envia = sendto(socketServidor , &cadenaEntrante , sizeof(cadenaEntrante) , 0 , (struct sockaddr *) &direccion_cliente , sizeof(direccion_cliente)); if(envia < 0){ perror("sendto()"); exit(EXIT_FAILURE); } } //close(socketServidor); return 0; }
the_stack_data/104826893.c
/*numPass=5, numTotal=5 Verdict:ACCEPTED, Visibility:1, Input:"2", ExpOutput:"2 -3 2 ", Output:"2 -3 2 " Verdict:ACCEPTED, Visibility:1, Input:"20", ExpOutput:"20 15 10 5 0 5 10 15 20 ", Output:"20 15 10 5 0 5 10 15 20 " Verdict:ACCEPTED, Visibility:1, Input:"4", ExpOutput:"4 -1 4 ", Output:"4 -1 4 " Verdict:ACCEPTED, Visibility:0, Input:"16", ExpOutput:"16 11 6 1 -4 1 6 11 16 ", Output:"16 11 6 1 -4 1 6 11 16 " Verdict:ACCEPTED, Visibility:0, Input:"8", ExpOutput:"8 3 -2 3 8 ", Output:"8 3 -2 3 8 " */ #include <stdio.h> int n; void res(int i){ if(i<=0){printf("%d ",i); return; } printf("%d ",i); res(i-5); printf("%d ",i); } int main(){ scanf("%d",&n); res(n); return 0; }
the_stack_data/187641935.c
#include <stdio.h> #include <string.h> #include<stdlib.h> #include<ctype.h> #define MAXL 100 int Digraph[MAXL][MAXL]; int zeroSign = 0;//zeroSign==1表示从0开始 void displayVex(int array[MAXL][MAXL],int number); void Initialize(int arr[MAXL][MAXL]); void getEdge(int array[MAXL][MAXL],int number); void displayGraph(int array[MAXL][MAXL],int number); void Initialize(int arr[MAXL][MAXL]){ memset(arr,0,MAXL*MAXL*sizeof(int)); } int getnum(void){ char m; int num = 0; while((m=getchar())!=EOF && m!='\n' && isdigit(m)){ num = num*10 + m - '0'; } return num; } void getEdge(int array[MAXL][MAXL],int number){ int row,column; for(int i=0;i<number;i++){ row = getnum(); column = getnum(); if(row==0 || column==0) zeroSign = 1; array[row][column] = 1; } } void displayGraph(int array[MAXL][MAXL],int number){ for(int i=0;i<number;i++){ for(int j=0;j<number;j++){ printf("%d",array[i][j]); if(j!=0 && j!=number-1) printf(","); } if(i!=number-1) printf("\n"); } } void displayVex(int array[MAXL][MAXL],int number){ for(int i=1-zeroSign;i<=number-zeroSign;i++){ printf("%d",i); int count = 0; for(int j=number-zeroSign;j>0-zeroSign;j--) if(array[i][j]==1){ if(!count){ printf(" %d",j); count++; } else printf(",%d",j); } if(i!=number-zeroSign) printf("\n"); } } int main(){ int vexNum,edgeNum; vexNum = getnum(); edgeNum = getnum(); getEdge(Digraph,edgeNum); displayVex(Digraph,vexNum); return 0; }
the_stack_data/92326383.c
/* Copyright (c) 2015-2016, ARM Limited 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 company 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 (__OPTIMIZE_SIZE__) || defined (PREFER_SIZE_OVER_SPEED)) # include "../../string/rawmemchr.c" #else /* See rawmemchr.S. */ #endif
the_stack_data/125069.c
// Написать функцию: // void arrayZeroFill(int array[], int size) // Заполнить массив нулями. void arrayZeroFill(int array[], int size) { for ( int i = 0; i < size; i++ ) { array[i] = 0; } }
the_stack_data/37638509.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #define BUFSIZE 256 struct grid { int *data; size_t l; }; struct player { int px; int py; int vx; int vy; int distance_initiale_x; int distance_initiale_y; int vx_max; int vy_max; }; struct checkpoint { int x; int y; int h; int w; int x_best; int y_best; }; void checkpoint_create (struct checkpoint *self){ self->x=0; self->y=0; self->h=1; self->w=1; self->x_best=0; self->y_best=0; } void player_create (struct player *self){ self->px=0; self->py=0; self->vx=0; self->vy=0; } void deplacement_one(struct player *self,const struct checkpoint *obj, const struct grid *grille){ if(self->px<obj->x){ switch(self->vx){ case 1 :{ self->px++; }break; case 0 :{ self->px++; self->vx++; }break; case -1 :{ self->vx--; }break; default:{}break; } } else { if(self->px>obj->x){ switch(self->vx){ case 1 :{ self->vx--; }break; case 0 :{ self->px--; self->vx--; }break; case -1 :{ self->px--; }break; default:{}break; } } else { self->vx=0; if(self->py<obj->y){ switch(self->vy){ case 1:{ self->py++; }break; case 0:{ self->py++; self->vy++; }break; case -1:{ self->vy++; }break; default:{}break; } } else { if(self->py>obj->y){ switch(self->vy){ case 1 :{ self->vy--; }break; case 0 :{ self->py--; self->vy--; }break; case -1:{ self->py--; }break; default:{}break; } } } } } } int main(){ struct grid grille; struct player one; struct checkpoint objective; checkpoint_create(&objective); player_create(&one); setbuf(stdout, NULL); char buf [BUFSIZE]; //recuperation de la taille de la grille fgets(buf,BUFSIZE,stdin); grille.l = atoi(buf); grille.data = calloc(grille.l*grille.l,sizeof(int)); //recuperation des valeurs de la grille for(size_t i=0;i<grille.l*grille.l;i++){ fgets(buf,BUFSIZE,stdin); grille.data[i]=atoi(buf); } fgets(buf,BUFSIZE,stdin); one.px=atoi(buf); fgets(buf,BUFSIZE,stdin); one.py=atoi(buf); fgets(buf,BUFSIZE,stdin); objective.x=atoi(buf); fgets(buf,BUFSIZE,stdin); objective.y=atoi(buf); fgets(buf,BUFSIZE,stdin); objective.w=atoi(buf); fgets(buf,BUFSIZE,stdin); objective.h=atoi(buf); fprintf(stderr,"x %i\ny %i\nw %i\nh %i\n",objective.x,objective.y,objective.w,objective.h); //calcul_meilleure_case(&batman,&objective,&grille); //calcul_distance_initiale(&batman,&objective); //calcul_vitesse_max(&batman,&objective); for(;;){ deplacement_one(&one,&objective,&grille); //fprintf(stderr,"px %i\npy %i\n",retad.distance_initiale_x,batman.distance_initiale_y); printf("%i\n%i\n",one.px,one.py); //printf("%i\n%i\n",bouledeneige.vx,bouledeneige.vy); fgets(buf,BUFSIZE,stdin); if(strcmp(buf,"ERROR\n")==0){ break; } if(strcmp(buf,"CHECKPOINT\n")==0){ fgets(buf,BUFSIZE,stdin); objective.x=atoi(buf); fgets(buf,BUFSIZE,stdin); objective.y=atoi(buf); fgets(buf,BUFSIZE,stdin); objective.w=atoi(buf); fgets(buf,BUFSIZE,stdin); objective.h=atoi(buf); fprintf(stderr,"x %i\ny %i\nw %i\nh %i\n",objective.x,objective.y,objective.w,objective.h); // calcul_meilleure_case(&batman,&objective,&grille); // calcul_distance_initiale(&batman,&objective); // calcul_vitesse_max(&batman,&objective); } if(strcmp(buf,"FINISH\n")==0){ break; } } return 0; }
the_stack_data/90762577.c
#include<stdio.h> #include<string.h> #define N 30 int main() { char st1[40],st2[40]="costa"; int i,cont=0; for(i=0;i<30;i++) { printf("digite o nome completo\n"); gets(st1); if(strstr(st1,st2)!=0) //strstr(st1,st2) avalia se há ocorrencia de st2 dentro do st1. cont++; } printf("num de nome com %s = %d\n",st2,cont); return(0); }
the_stack_data/232955787.c
/* * 15.6.c -- Design a bit-field structure that holds the following information: * * Font ID: A number in the range 0–255 * Font Size: A number in the range 0–127 * Alignment: A number in the range 0–2 represented the choices Left, * Center, and Right * Bold: Off (0) or on (1) * Italic: Off (0) or on (1) * Underline: Off (0) or on (1) * * Use this structure in a program that displays the font parameters and uses a * looped menu to let the user change parameters. For example, a sample run * might look like this: * * ID SIZE ALIGNMENT B I U * 1 12 left off off off * f)change font s)change size a)change alignment * b)toggle bold i)toggle italic u)toggle underline * q)quit * s * Enter font size (0-127): * 36 * ID SIZE ALIGNMENT B I U * 1 36 left off off off * f)change font s)change size a)change alignment * b)toggle bold i)toggle italic u)toggle * underline * q)quit * a * Select alignment: * l)left c)center r)right * r * ID SIZE ALIGNMENT B I U * 1 36 right off off off */ #include <stdio.h> #include <stdbool.h> #include <string.h> /* alignment constants */ #define LEFT 0 #define CENTER 1 #define RIGHT 2 struct font_properties { unsigned int font_id : 8; unsigned int font_size : 7; unsigned int : 1; unsigned int alignment : 2; bool bold : 1; bool italic : 1; bool underline : 1; unsigned int : 11; }; void show_font_settings(const struct font_properties *); void show_menu(void); char get_letter(const char *); void clean_line(void); void apply_choice(struct font_properties *, char); int get_number(void); void change_font(struct font_properties *); void change_font_size(struct font_properties *); void change_alignment(struct font_properties *); void toggle_bold(struct font_properties *); void toggle_italic(struct font_properties *); void toggle_underline(struct font_properties *); int main(void) { struct font_properties font = { 1, 12, 0, 0, 0, 0 }; const char *options = "fsabiuq"; char choice; show_font_settings(&font); show_menu(); choice = get_letter(options); while (choice != 'q') { apply_choice(&font, choice); show_font_settings(&font); show_menu(); choice = get_letter(options); } return 0; } void show_font_settings(const struct font_properties *f) { printf("\tID SIZE ALIGNMENT B I U\n"); printf("\t%-2u %-3u ", f->font_id, f->font_size); switch (f->alignment) { case LEFT: printf("left "); break; case CENTER: printf("center "); break; case RIGHT: printf("right "); break; default: printf("unknown "); } printf("%-3s ", f->bold ? "on" : "off"); printf("%-3s ", f->italic ? "on" : "off"); printf("%-3s\n", f->underline ? "on" : "off"); } void show_menu(void) { printf("\tf) change font s) change size a) change alignment\n" "\tb) toggle bold i) toggle italic u) toggle underline\n" "\tq) quit\n"); } char get_letter(const char *o) { char choice; while (1) { printf("Enter a letter of your choice: _\b"); choice = getchar(); clean_line(); if (strchr(o, choice)) break; else printf("Invalid input.\n"); } return choice; } void clean_line(void) { while (getchar() != '\n') continue; } void apply_choice(struct font_properties *f, char c) { switch (c) { case 'f': change_font(f); break; case 's': change_font_size(f); break; case 'a': change_alignment(f); break; case 'b': toggle_bold(f); break; case 'i': toggle_italic(f); break; case 'u': toggle_underline(f); break; default: puts("Switch error!"); } } int get_number(void) { int number; while (1) { if (scanf("%d", &number) == 1) { clean_line(); break; } printf("Invalid input! It must be a number: _\b"); clean_line(); } return number; } void change_font(struct font_properties *f) { int new_font_id; printf("Enter id: _\b"); new_font_id = get_number(); while (new_font_id < 0 || new_font_id > 255) { printf("Invalid input. Enter a number from 0-255: _\b"); new_font_id = get_number(); } f->font_id = new_font_id; } void change_font_size(struct font_properties *f) { int new_font_size; printf("Enter a font size: _\b"); new_font_size = get_number(); while (new_font_size < 0 || new_font_size > 127) { printf("Invalid input. Enter a number from 0-127: _\b"); new_font_size = get_number(); } f->font_size = new_font_size; } void change_alignment(struct font_properties *f) { char choice; printf("Select alignment:\n"); printf("l) left c) center r) right\n"); choice = get_letter("lcr"); switch (choice) { case 'l': f->alignment = LEFT; break; case 'c': f->alignment = CENTER; break; case 'r': f->alignment = RIGHT; break; default: printf("Switch error!\n"); } } void toggle_bold(struct font_properties *f) { if (f->bold) f->bold = 0; else f->bold = 1; } void toggle_italic(struct font_properties *f) { if (f->italic) f->italic = 0; else f->italic = 1; } void toggle_underline(struct font_properties *f) { if (f->underline) f->underline = 0; else f->underline = 1; }
the_stack_data/162643069.c
#include<stdio.h> void main() { char ch; printf("Enter a charater:"); ch=getc(stdin); printf("You have entered the character %c\n",ch); }
the_stack_data/425834.c
#include "syscall.h" int main() { int i; char *message = "Message from hw3testprog1_2\n\r"; int messageLength = getStringSize(message); PredictCPU(50); for (i = 0; i < 2; i++) { Write(message, messageLength, 1); } return 0; } int getStringSize(char *s) { int count = 0; while (*s != 0) { s++; count++; } /*count++;*/ return count; }
the_stack_data/192330005.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 short input[1] , unsigned short output[1] ) ; extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ; extern int gettimeofday(struct timeval *tv , void *tz , ...) ; extern int printf(char const *format , ...) ; int main(int argc , char *argv[] ) ; void megaInit(void) ; extern unsigned long strlen(char const *s ) ; extern long strtol(char const *str , char const *endptr , int base ) ; extern unsigned long strnlen(char const *s , unsigned long maxlen ) ; extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ; struct timeval { long tv_sec ; long tv_usec ; }; extern void *malloc(unsigned long size ) ; extern int scanf(char const *format , ...) ; void megaInit(void) { { } } int main(int argc , char *argv[] ) { unsigned short input[1] ; unsigned short output[1] ; int randomFuns_i5 ; unsigned short randomFuns_value6 ; int randomFuns_main_i7 ; { megaInit(); if (argc != 2) { printf("Call this program with %i arguments\n", 1); exit(-1); } else { } randomFuns_i5 = 0; while (randomFuns_i5 < 1) { randomFuns_value6 = (unsigned short )strtoul(argv[randomFuns_i5 + 1], 0, 10); input[randomFuns_i5] = randomFuns_value6; randomFuns_i5 ++; } RandomFunc(input, output); if (output[0] == (unsigned short)31026) { printf("You win!\n"); } else { } randomFuns_main_i7 = 0; while (randomFuns_main_i7 < 1) { printf("%u\n", output[randomFuns_main_i7]); randomFuns_main_i7 ++; } } } void RandomFunc(unsigned short input[1] , unsigned short output[1] ) { unsigned short state[1] ; unsigned short local1 ; char copy11 ; char copy14 ; { state[0UL] = (input[0UL] | 51238316UL) >> (unsigned short)3; local1 = 0UL; while (local1 < 1UL) { if (state[0UL] > local1) { copy11 = *((char *)(& state[local1]) + 1); *((char *)(& state[local1]) + 1) = *((char *)(& state[local1]) + 0); *((char *)(& state[local1]) + 0) = copy11; } else { copy14 = *((char *)(& state[local1]) + 1); *((char *)(& state[local1]) + 1) = *((char *)(& state[local1]) + 0); *((char *)(& state[local1]) + 0) = copy14; copy14 = *((char *)(& state[local1]) + 0); *((char *)(& state[local1]) + 0) = *((char *)(& state[local1]) + 1); *((char *)(& state[local1]) + 1) = copy14; } local1 += 2UL; } output[0UL] = state[0UL] | 306719454UL; } }
the_stack_data/89200199.c
#include <assert.h> extern int __VERIFIER_nondet_int(); int ssl3_connect(void) { int s__state ; int blastFlag ; s__state = 12292; blastFlag = 0; while (1) { if (s__state == 12292) { goto switch_1_12292; } else { if (s__state == 4368) { goto switch_1_4368; } else { if (s__state == 4384) { goto switch_1_4384; } else { if (s__state == 4400) { goto switch_1_4400; } else { return 0; if (0) { switch_1_12292: /* CIL Label */ s__state = 4368; continue; switch_1_4368: /* CIL Label */ ; blastFlag++; s__state = 4384; continue; switch_1_4384: /* CIL Label */ ; blastFlag++; s__state = 4400; continue; switch_1_4400: /* CIL Label */ ; if (blastFlag == 2) { break; } continue; } } } } } } assert(0); return -1; } int main(void) { ssl3_connect(); return 0; } /* We get hoisted assertion: (C) $guard#ls50%2 && ($cond#22%2 || $cond#36%2 || $cond#49%2) ==> ($guard#51 ==> FALSE) But $cond#36%2 is a return and no break condition! */
the_stack_data/32494.c
/* * Copyright (c) 2013 Jan-Piet Mens <jpmens()gmail.com> wendal <wendal1985()gmai.com> * 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 mosquitto 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 OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifdef BE_HTTP #include "backends.h" #include "be-http.h" #include <stdio.h> #include <stdlib.h> #include <string.h> #include "hash.h" #include "log.h" #include <curl/curl.h> static int http_post(void *handle, char *uri, const char *clientid, const char *username,const char *password, const char *topic, int acc) { struct http_backend *conf = (struct http_backend *)handle; CURL *curl; struct curl_slist *headerlist=NULL; int re; int respCode = 0; int ok = FALSE; char *url; char *data; if (username == NULL) { return (FALSE); } clientid = (clientid && *clientid) ? clientid : ""; password = (password && *password) ? password : ""; topic = (topic && *topic) ? topic : ""; if ((curl = curl_easy_init()) == NULL) { _fatal("create curl_easy_handle fails"); return (FALSE); } if (conf->hostheader != NULL) curl_slist_append(headerlist, conf->hostheader); curl_slist_append(headerlist, "Expect:"); //_log(LOG_NOTICE, "u=%s p=%s t=%s acc=%d", username, password, topic, acc); url = (char *)malloc(strlen(conf->ip) + strlen(uri) + 20); if (url == NULL) { _fatal("ENOMEM"); return (FALSE); } sprintf(url, "http://%s:%d%s", conf->ip, conf->port, uri); /* Hoping the 1024 is sufficient for curl_easy_escapes ... */ data = (char *)malloc(strlen(username) + strlen(password) + strlen(topic) + strlen(clientid) + 1024); if (data == NULL) { _fatal("ENOMEM"); return (FALSE); } sprintf(data, "username=%s&password=%s&topic=%s&acc=%d&clientid=%s", curl_easy_escape(curl, username, 0), curl_easy_escape(curl, password, 0), curl_easy_escape(curl, topic, 0), acc, curl_easy_escape(curl, clientid, 0)); _log(LOG_DEBUG, "url=%s", url); // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_POST, 1L); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10); re = curl_easy_perform(curl); if (re == CURLE_OK) { re = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &respCode); if (re == CURLE_OK && respCode == 200) { ok = TRUE; } else { //_log(LOG_NOTICE, "http auth fail re=%d respCode=%d", re, respCode); } } else { _log(LOG_DEBUG, "http req fail url=%s re=%s", url, curl_easy_strerror(re)); } curl_easy_cleanup(curl); curl_slist_free_all (headerlist); free(url); free(data); return (ok); } void *be_http_init() { struct http_backend *conf; char *ip; char *getuser_uri; char *superuser_uri; char *aclcheck_uri; if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { _fatal("init curl fail"); return (NULL); } if ((ip = p_stab("http_ip")) == NULL) { _fatal("Mandatory parameter `http_ip' missing"); return (NULL); } if ((getuser_uri = p_stab("http_getuser_uri")) == NULL) { _fatal("Mandatory parameter `http_getuser_uri' missing"); return (NULL); } if ((superuser_uri = p_stab("http_superuser_uri")) == NULL) { _fatal("Mandatory parameter `http_superuser_uri' missing"); return (NULL); } if ((aclcheck_uri = p_stab("http_aclcheck_uri")) == NULL) { _fatal("Mandatory parameter `http_aclcheck_uri' missing"); return (NULL); } conf = (struct http_backend *)malloc(sizeof(struct http_backend)); conf->ip = ip; conf->port = p_stab("http_port") == NULL ? 80 : atoi(p_stab("http_port")); if (p_stab("http_hostname") != NULL) { conf->hostheader = (char *)malloc(128); sprintf(conf->hostheader, "Host: %s", p_stab("http_hostname")); } else { conf->hostheader = NULL; } conf->getuser_uri = getuser_uri; conf->superuser_uri = superuser_uri; conf->aclcheck_uri = aclcheck_uri; _log(LOG_DEBUG, "getuser_uri=%s", getuser_uri); _log(LOG_DEBUG, "superuser_uri=%s", superuser_uri); _log(LOG_DEBUG, "aclcheck_uri=%s", aclcheck_uri); return (conf); }; void be_http_destroy(void *handle) { struct http_backend *conf = (struct http_backend *)handle; if (conf) { curl_global_cleanup(); free(conf); } }; char *be_http_getuser(void *handle, const char *username, const char *password, int *authenticated) { struct http_backend *conf = (struct http_backend *)handle; int re; if (username == NULL) { return NULL; } re = http_post(handle, conf->getuser_uri, NULL, username, password, NULL, -1); if (re == 1) { *authenticated = 1; } return NULL; }; int be_http_superuser(void *handle, const char *username) { struct http_backend *conf = (struct http_backend *)handle; return http_post(handle, conf->superuser_uri, NULL, username, NULL, NULL, -1); }; int be_http_aclcheck(void *handle, const char *clientid, const char *username, const char *topic, int acc) { struct http_backend *conf = (struct http_backend *)handle; return http_post(conf, conf->aclcheck_uri, clientid, username, NULL, topic, acc); }; #endif /* BE_HTTP */
the_stack_data/75137495.c
#include <stdio.h> #include <math.h> #define RAD_TO_DEG (180/(4 * atan(1))) typedef struct polar_v { double magnitude; double angle; } Polar_V; typedef struct rect_v { double x; double y; } Rect_V; Polar_V rect_to_polar(const Rect_V); int main(void) { Rect_V input; Polar_V result; puts("Enter x and y coordinates; enter q to quit:"); while (scanf("%lf %lf", &input.x, &input.y) == 2) { result = rect_to_polar(input); printf("magnitude = %0.2f, angle = %0.2f\n", result.magnitude, result.angle); } return 0; } Polar_V rect_to_polar(const Rect_V rv) { Polar_V pv; pv.magnitude = sqrt(rv.x * rv.x + rv.y * rv.y); if (pv.magnitude == 0) pv.angle = 0.0; else pv.angle = RAD_TO_DEG * atan2(rv.y, rv.x); return pv; }
the_stack_data/34512367.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } } #define size 250 int main( ) { int a[size]; int b[size]; int i = 1; int j = 0; while( i < size ) { a[j] = b[i]; i = i+3; j = j+1; } i = 1; j = 0; while( i < size ) { __VERIFIER_assert( a[j] == b[3*j+1] ); i = i+3; j = j+1; } return 0; }
the_stack_data/89201211.c
#include<stdio.h> int skip(int arr[],int elem,int size,int index){ while(index < size && elem == arr[index]){ index++; } return index; } int main(){ int a[] = {1,2,3,4,5}; int b[] = {1,3,5,7,9,11,12,13,13,15}; int c[100]={0}; int i=0; int k=0; int j=0; int count=0; int a_length = 5; int b_length = 10; //lets keep static length for now while((i<a_length) && (j<b_length)){ if(a[i] < b[j]){ c[k] = a[i]; i = skip(a,a[i],a_length,i); } else if(a[i] == b[j]){ c[k] = a[i]; i = skip(a,a[i],a_length,i); j = skip(b,b[j],b_length,j); } else{ c[k] = b[j]; j = skip(b,b[j],b_length,j); } k++; count++; } //if remaining element loop and add to the array while(j < b_length){ c[k] = b[j]; j = skip(b,b[j],b_length,j); k++; count++; } while(i < a_length){ c[k] = a[i]; i = skip(a,a[i],a_length,i); k++; count++; } printf("\n"); for(i=0;i<count;i++){ printf("%d ",c[i]); } }
the_stack_data/1264919.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 mre parameters ***/ // MAE% = 7.66 % // MAE = 9.8 // WCE% = 23.44 % // WCE = 30 // WCRE% = 850.00 % // EP% = 96.91 % // MRE% = 33.04 % // MSE = 142 // PDK45_PWR = 0.017 mW // PDK45_AREA = 40.8 um2 // PDK45_DELAY = 0.38 ns #include <stdint.h> #include <stdlib.h> uint64_t add8s_6PA(const uint64_t B,const uint64_t A) { uint64_t 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; uint64_t O; dout_33=((A >> 4)&1)^((B >> 4)&1); dout_34=((A >> 4)&1)&((B >> 4)&1); dout_35=dout_33&((B >> 7)&1); dout_36=dout_33^dout_35; dout_37=dout_34|dout_35; dout_38=((A >> 5)&1)^((B >> 5)&1); dout_39=((A >> 5)&1)&((B >> 5)&1); dout_40=dout_38&dout_37; dout_41=dout_38^dout_37; dout_42=dout_39|dout_40; dout_43=((A >> 6)&1)^((B >> 6)&1); dout_44=((A >> 6)&1)&((B >> 6)&1); dout_45=dout_43&dout_42; dout_46=dout_43^dout_42; dout_47=dout_44|dout_45; dout_48=((A >> 7)&1)^((B >> 7)&1); dout_49=dout_48^dout_47; O = 0; O |= (dout_46&1) << 0; O |= (dout_36&1) << 1; O |= (dout_49&1) << 2; O |= (dout_49&1) << 3; O |= (dout_36&1) << 4; O |= (dout_41&1) << 5; O |= (dout_46&1) << 6; O |= (dout_49&1) << 7; return O; }
the_stack_data/54824806.c
#include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/syscall.h> struct message { int i; int j; }; void* hello(struct message* msg) { printf("This is child thread, tid = %lu, pid = %ld\n", pthread_self(), syscall(SYS_gettid)); printf("The arg.i is %d, arg.j is %d\n", msg->i, msg->j); while(1); } int main(int argc, char* argv[]) { struct message test_msg; pthread_t thread_id; test_msg.i = 10; test_msg.j = 20; // To create a thread. pthread_create(&thread_id, NULL, (void *)*hello, &test_msg); printf("parent, the tid = %lu, pid = %ld\n", pthread_self(), syscall(SYS_gettid)); pthread_join(thread_id, NULL); return 0; }
the_stack_data/809537.c
//OBJ struct a { struct a * x; }; void foo (struct a * b) { int i; for (i = 0; i < 1000; i++) { b->x = b; b++; } } void bar (struct a * b) { int i; for (i = 0; i < 1000; i++) { b->x = b; b--; } }
the_stack_data/1240084.c
/* * ldt_gdt.c - Test cases for LDT and GDT access * Copyright (c) 2011-2015 Andrew Lutomirski */ #define _GNU_SOURCE #include <stdio.h> #include <sys/time.h> #include <time.h> #include <stdlib.h> #include <unistd.h> #include <sys/syscall.h> #include <dlfcn.h> #include <string.h> #include <errno.h> #include <sched.h> #include <stdbool.h> #ifndef SYS_getcpu # ifdef __x86_64__ # define SYS_getcpu 309 # else # define SYS_getcpu 318 # endif #endif int nerrs = 0; #ifdef __x86_64__ # define VSYS(x) (x) #else # define VSYS(x) 0 #endif typedef long (*getcpu_t)(unsigned *, unsigned *, void *); const getcpu_t vgetcpu = (getcpu_t)VSYS(0xffffffffff600800); getcpu_t vdso_getcpu; void fill_function_pointers() { void *vdso = dlopen("linux-vdso.so.1", RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD); if (!vdso) vdso = dlopen("linux-gate.so.1", RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD); if (!vdso) { printf("[WARN]\tfailed to find vDSO\n"); return; } vdso_getcpu = (getcpu_t)dlsym(vdso, "__vdso_getcpu"); if (!vdso_getcpu) printf("Warning: failed to find getcpu in vDSO\n"); } static long sys_getcpu(unsigned * cpu, unsigned * node, void* cache) { return syscall(__NR_getcpu, cpu, node, cache); } static void test_getcpu(void) { printf("[RUN]\tTesting getcpu...\n"); for (int cpu = 0; ; cpu++) { cpu_set_t cpuset; CPU_ZERO(&cpuset); CPU_SET(cpu, &cpuset); if (sched_setaffinity(0, sizeof(cpuset), &cpuset) != 0) return; unsigned cpu_sys, cpu_vdso, cpu_vsys, node_sys, node_vdso, node_vsys; long ret_sys, ret_vdso = 1, ret_vsys = 1; unsigned node; ret_sys = sys_getcpu(&cpu_sys, &node_sys, 0); if (vdso_getcpu) ret_vdso = vdso_getcpu(&cpu_vdso, &node_vdso, 0); if (vgetcpu) ret_vsys = vgetcpu(&cpu_vsys, &node_vsys, 0); if (!ret_sys) node = node_sys; else if (!ret_vdso) node = node_vdso; else if (!ret_vsys) node = node_vsys; bool ok = true; if (!ret_sys && (cpu_sys != cpu || node_sys != node)) ok = false; if (!ret_vdso && (cpu_vdso != cpu || node_vdso != node)) ok = false; if (!ret_vsys && (cpu_vsys != cpu || node_vsys != node)) ok = false; printf("[%s]\tCPU %u:", ok ? "OK" : "FAIL", cpu); if (!ret_sys) printf(" syscall: cpu %u, node %u", cpu_sys, node_sys); if (!ret_vdso) printf(" vdso: cpu %u, node %u", cpu_vdso, node_vdso); if (!ret_vsys) printf(" vsyscall: cpu %u, node %u", cpu_vsys, node_vsys); printf("\n"); if (!ok) nerrs++; } } int main(int argc, char **argv) { fill_function_pointers(); test_getcpu(); return nerrs ? 1 : 0; }
the_stack_data/1027590.c
/* Task 1: Write a program to read/write registers using inline assembly */ #include<stdio.h> #include<stdlib.h> int main(int argc, char ** argv){ printf("*** Welcome to Swapnil-lab ***\n"); int a =22, b; printf("Before asm a:%d b:%d \n", a,b); __asm__ __volatile__ ("movl %1, %%eax ;\n\t " "movl %%eax, %0 ;" :"=r"(b) :"r"(a) :"%eax" ); printf("After asm a:%d b:%d \n", a,b); return 0; }
the_stack_data/18886742.c
extern int get_counter(); extern int add_to_counter(int value_to_add); int increment_counter_loop(int number_of_times) { int current_counter = get_counter(); for(int i = 0; i < number_of_times; i++) { current_counter = add_to_counter(1); } return current_counter; }
the_stack_data/215768572.c
char* dummy = "foobar"; const char* constdummy = "constfoobar"; int main (int argc, char** argv) { return 17; }
the_stack_data/883760.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 'multiply_uchar8uchar8.cl' */ source_code = read_buffer("multiply_uchar8uchar8.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, "multiply_uchar8uchar8", &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_uchar8 *src_0_host_buffer; src_0_host_buffer = malloc(num_elem * sizeof(cl_uchar8)); for (int i = 0; i < num_elem; i++) src_0_host_buffer[i] = (cl_uchar8){{2, 2, 2, 2, 2, 2, 2, 2}}; /* Create and init device side src buffer 0 */ cl_mem src_0_device_buffer; src_0_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_uchar8), 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_uchar8), 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_uchar8 *src_1_host_buffer; src_1_host_buffer = malloc(num_elem * sizeof(cl_uchar8)); for (int i = 0; i < num_elem; i++) src_1_host_buffer[i] = (cl_uchar8){{2, 2, 2, 2, 2, 2, 2, 2}}; /* Create and init device side src buffer 1 */ cl_mem src_1_device_buffer; src_1_device_buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, num_elem * sizeof(cl_uchar8), 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_uchar8), 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_uchar8 *dst_host_buffer; dst_host_buffer = malloc(num_elem * sizeof(cl_uchar8)); memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_uchar8)); /* Create device dst buffer */ cl_mem dst_device_buffer; dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_uchar8), 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_uchar8), 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_uchar8)); 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/54826555.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: ekutlay <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/10/29 18:44:00 by ekutlay #+# #+# */ /* Updated: 2021/10/30 21:22:25 by ekutlay ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strlen(char *str) { int counter; counter = 0; while (str[counter] != '/0') { counter++; } return (counter); }
the_stack_data/76701531.c
/* +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ | Copyright (c) 1997-2010 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: Pierre A. Joye <[email protected]> | +----------------------------------------------------------------------+ */ /* $Id: link_win32.c 293036 2010-01-03 09:23:27Z sebastian $ */ #ifdef PHP_WIN32 #include "php.h" #include "php_filestat.h" #include "php_globals.h" #include <WinBase.h> #include <stdlib.h> #include <string.h> #if HAVE_PWD_H #include "win32/pwd.h" #endif #if HAVE_GRP_H #include "win32/grp.h" #endif #include <errno.h> #include <ctype.h> #include "safe_mode.h" #include "php_link.h" #include "php_string.h" /* TODO: - Create php_readlink, php_link and php_symlink in win32/link.c - Expose them (PHPAPI) so extensions developers can use them - define link/readlink/symlink to their php_ equivalent and use them in ext/standart/link.c - this file is then useless and we have a portable link API */ #ifndef VOLUME_NAME_NT #define VOLUME_NAME_NT 0x2 #endif #ifndef VOLUME_NAME_DOS #define VOLUME_NAME_DOS 0x0 #endif /* {{{ proto string readlink(string filename) Return the target of a symbolic link */ PHP_FUNCTION(readlink) { HINSTANCE kernel32; char *link; int link_len; TCHAR Path[MAXPATHLEN]; char path_resolved[MAXPATHLEN]; HANDLE hFile; DWORD dwRet; typedef BOOL (WINAPI *gfpnh_func)(HANDLE, LPTSTR, DWORD, DWORD); gfpnh_func pGetFinalPathNameByHandle; kernel32 = LoadLibrary("kernel32.dll"); if (kernel32) { pGetFinalPathNameByHandle = (gfpnh_func)GetProcAddress(kernel32, "GetFinalPathNameByHandleA"); if (pGetFinalPathNameByHandle == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't call GetFinalPathNameByHandleA"); RETURN_FALSE; } } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't call get a handle on kernel32.dll"); RETURN_FALSE; } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &link, &link_len) == FAILURE) { return; } if (OPENBASEDIR_CHECKPATH(link)) { RETURN_FALSE; } if (!expand_filepath(link, path_resolved TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory"); RETURN_FALSE; } hFile = CreateFile(path_resolved, // file to open GENERIC_READ, // open for reading FILE_SHARE_READ, // share for reading NULL, // default security OPEN_EXISTING, // existing file only FILE_FLAG_BACKUP_SEMANTICS, // normal file NULL); // no attr. template if( hFile == INVALID_HANDLE_VALUE) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not open file (error %d)", GetLastError()); RETURN_FALSE; } dwRet = pGetFinalPathNameByHandle(hFile, Path, MAXPATHLEN, VOLUME_NAME_DOS); if(dwRet >= MAXPATHLEN) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't resolve the full path, the path exceeds the MAX_PATH_LEN (%d) limit", MAXPATHLEN); RETURN_FALSE; } CloseHandle(hFile); /* Append NULL to the end of the string */ Path[dwRet] = '\0'; if(dwRet > 4) { /* Skip first 4 characters if they are "\??\" */ if(Path[0] == '\\' && Path[1] == '\\' && Path[2] == '?' && Path[3] == '\\') { RETURN_STRING(Path + 4, 1); } } else { RETURN_STRING(Path, 1); } } /* }}} */ /* {{{ proto int linkinfo(string filename) Returns the st_dev field of the UNIX C stat structure describing the link */ PHP_FUNCTION(linkinfo) { char *link; int link_len; struct stat sb; int ret; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &link, &link_len) == FAILURE) { return; } ret = VCWD_STAT(link, &sb); if (ret == -1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); RETURN_LONG(-1L); } RETURN_LONG((long) sb.st_dev); } /* }}} */ /* {{{ proto int symlink(string target, string link) Create a symbolic link */ PHP_FUNCTION(symlink) { char *topath, *frompath; int topath_len, frompath_len; BOOLEAN ret; char source_p[MAXPATHLEN]; char dest_p[MAXPATHLEN]; char dirname[MAXPATHLEN]; size_t len; DWORD attr; HINSTANCE kernel32; typedef BOOLEAN (WINAPI *csla_func)(LPCSTR, LPCSTR, DWORD); csla_func pCreateSymbolicLinkA; kernel32 = LoadLibrary("kernel32.dll"); if (kernel32) { pCreateSymbolicLinkA = (csla_func)GetProcAddress(kernel32, "CreateSymbolicLinkA"); if (pCreateSymbolicLinkA == NULL) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't call CreateSymbolicLinkA"); RETURN_FALSE; } } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't call get a handle on kernel32.dll"); RETURN_FALSE; } if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &topath, &topath_len, &frompath, &frompath_len) == FAILURE) { return; } if (!expand_filepath(frompath, source_p TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory"); RETURN_FALSE; } memcpy(dirname, source_p, sizeof(source_p)); len = php_dirname(dirname, strlen(dirname)); if (!expand_filepath_ex(topath, dest_p, dirname, len TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory"); RETURN_FALSE; } if (php_stream_locate_url_wrapper(source_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) || php_stream_locate_url_wrapper(dest_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to symlink to a URL"); RETURN_FALSE; } if (OPENBASEDIR_CHECKPATH(dest_p)) { RETURN_FALSE; } if (OPENBASEDIR_CHECKPATH(source_p)) { RETURN_FALSE; } if ((attr = GetFileAttributes(topath)) == INVALID_FILE_ATTRIBUTES) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not fetch file information(error %d)", GetLastError()); RETURN_FALSE; } /* For the source, an expanded path must be used (in ZTS an other thread could have changed the CWD). * For the target the exact string given by the user must be used, relative or not, existing or not. * The target is relative to the link itself, not to the CWD. */ ret = pCreateSymbolicLinkA(source_p, topath, (attr & FILE_ATTRIBUTE_DIRECTORY ? 1 : 0)); if (!ret) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot create symlink, error code(%d)", GetLastError()); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ /* {{{ proto int link(string target, string link) Create a hard link */ PHP_FUNCTION(link) { char *topath, *frompath; int topath_len, frompath_len; int ret; char source_p[MAXPATHLEN]; char dest_p[MAXPATHLEN]; /*First argument to link function is the target and hence should go to frompath Second argument to link function is the link itself and hence should go to topath */ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &frompath, &frompath_len, &topath, &topath_len) == FAILURE) { return; } if (!expand_filepath(frompath, source_p TSRMLS_CC) || !expand_filepath(topath, dest_p TSRMLS_CC)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "No such file or directory"); RETURN_FALSE; } if (php_stream_locate_url_wrapper(source_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) || php_stream_locate_url_wrapper(dest_p, NULL, STREAM_LOCATE_WRAPPERS_ONLY TSRMLS_CC) ) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to link to a URL"); RETURN_FALSE; } if (OPENBASEDIR_CHECKPATH(source_p)) { RETURN_FALSE; } if (OPENBASEDIR_CHECKPATH(dest_p)) { RETURN_FALSE; } #ifndef ZTS ret = CreateHardLinkA(topath, frompath, NULL); #else ret = CreateHardLinkA(dest_p, source_p, NULL); #endif if (ret == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); RETURN_FALSE; } RETURN_TRUE; } /* }}} */ #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/58385.c
/* * Copyright (c) 2006-2007 Dave Dribin * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, copy, * modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #if __i386__ #include "src/emu/cpu/drcfe.c" #endif
the_stack_data/150634.c
#include <stdio.h> int main(){ int n, i, j, t; printf("Enter the rows: "); scanf("%d", &n); for (i = 0; i < n; i += 1){ for (j = 1; j <= (n - i); j += 1){ printf(" "); } for (t = 0; t <= i; t++){ printf("%d ",i+1); } printf("\n"); } return 0; }
the_stack_data/337320.c
void fence() { asm("sync"); } void lwfence() { asm("lwsync"); } void isync() { asm("isync"); } int __unbuffered_cnt = 0; int __unbuffered_p0_EAX = 0; int x = 0; int y = 0; int z = 0; void *P0(void *arg) { z = 2; fence(); __unbuffered_p0_EAX = x; // Instrumentation for CPROVER fence(); __unbuffered_cnt++; } void *P1(void *arg) { x = 1; y = 1; // Instrumentation for CPROVER fence(); __unbuffered_cnt++; } void *P2(void *arg) { y = 2; z = 1; // Instrumentation for CPROVER fence(); __unbuffered_cnt++; } int main() { __CPROVER_ASYNC_0: P0(0); __CPROVER_ASYNC_1: P1(0); __CPROVER_ASYNC_2: P2(0); __CPROVER_assume(__unbuffered_cnt == 3); fence(); // EXPECT:exists __CPROVER_assert( !(y == 2 && z == 2 && __unbuffered_p0_EAX == 0), "Program was expected to be safe for X86, model checker should have said " "NO.\nThis likely is a bug in the tool chain."); return 0; }
the_stack_data/1236802.c
/***************************************************************** Original script by Maksim Bashov 2012-10-23 for RMV videos. Modified during 2019-02 by Damien Moore. Split Program string to extract Version and added Time, Style, Questionmarks and Status. On 2019-02-24 fixed method for printing mouse event times. At this stage program was identical to RMV parser which did not work with earlier UMF files. On 2019-03-04 customised to work exclusively with UMF videos which have a different header. Modified 2020-01-25 by Damien Moore since some early versions do not have 3bv, 3bvs or Timestamp values. Tidied code and wrote detailed comments. On 2020-02-03 fixed a major bug that caused Solved 3BV (in RAWVF2RAWVF) to be incorrect in certain videos. This bug occurred when using event[cur++] in the function used to create the missing first left click (since Viennasweeper does not record mouse event prior to the time starting and it is the release of the button that starts the timer). This is being released as Viennasweeper (UMF) RAW version 6. *****************************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAXREP 100000 #define MAXNAME 1000 struct event { int time; int x,y; unsigned char event; }; typedef struct event event; FILE* UMF; //Initialise global variables int mode,level,w,h,m; //Mode, Level, Width, Height, Mines int size; //Number of game events int* board; //Stores board and mine locations int qm,nf; //Questionmarks, Style char name[MAXNAME]; //Player name char program[MAXNAME]; //Program char version[MAXNAME]; //Version char verstring[MAXNAME]; //Substring of Version event video[MAXREP]; //Game events const int square_size=16; //Cell size used in mouse movement calculations int score; //Time int score_check; //Boolean used to check if time found from game events //============================================================================================== //Function asks user to exit after program has run successfully //============================================================================================== void pause() { //fprintf(stderr,"Press enter to exit\n"); //while(getchar()!='\n'); } //============================================================================================== //Function to print error messages //============================================================================================== void error(const char* msg) { fprintf(stderr,"%s\n",msg); pause(); exit(1); } //============================================================================================== //Function is run if there is a parsing error //============================================================================================== _fgetc(FILE* f) { if(!feof(f)) return fgetc(f); else { error("Error 4: Unexpected end of file"); } } //============================================================================================== //Functions to parse either 2, 3 or 4 bytes at a time //============================================================================================== int getint2(FILE* f) { //Creates a string array called c holding 2 bytes unsigned char c[2]; //This retrieves two bytes c[0]=_fgetc(f);c[1]=_fgetc(f); //Return ends the function and returns output to variable getint2 //This code reads 2 bytes and puts them in a 4 byte int //You cannot "add" bytes in the normal sense, instead you perform shift operations //Multiplying by 256 is the same as shifting left by 1 byte (8 bits) //The result is c[0] is moved to int byte 3 while c[1] stayes in int byte 4 return (int)c[1]+c[0]*256; } int getint3(FILE* f) { //Creates a string array called c holding 3 bytes unsigned char c[3]; c[0]=_fgetc(f);c[1]=_fgetc(f);c[2]=_fgetc(f); return (int)c[2]+c[1]*256+c[0]*65536; } int getint(FILE* f) { //Creates a string array called c holding 4 bytes unsigned char c[4]; int i; for(i=0;i<4;++i) c[i]=_fgetc(f); return (int)c[2]+c[3]*256+c[0]*65536+c[1]*16777216; } //============================================================================================== //Function is used to print game events //============================================================================================== void print_event(event* e) { const char* event_names[]={"","mv","lc","lr","rc","rr","mc","mr","","pressed","pressedqm","closed", "questionmark","flag","blast","boom","won","nonstandard","number0","number1","number2","number3", "number4","number5","number6","number7","number8","blast"}; unsigned char c=e->event; //Mouse event if(c<=7) { printf("%d.%03d %s %d %d (%d %d)\n", e->time/1000,e->time%1000, event_names[c], e->x/square_size+1,e->y/square_size+1, e->x,e->y); } //Board event else if(c<=14 || (c>=18 && c<=27)) { printf("%s %d %d\n", event_names[c], e->x,e->y); } //End event (ie, 'blast') else if(c<=17) { printf("%s\n", event_names[c]); } } //============================================================================================== //Function is used to fetch Time and Status //============================================================================================== void print_event2(event* e) { const char* event_names[]={"","mv","lc","lr","rc","rr","mc","mr","","pressed","pressedqm","closed", "questionmark","flag","blast","Lost","Won","nonstandard","number0","number1","number2","number3", "number4","number5","number6","number7","number8","blast"}; unsigned char c=e->event; //Mouse event if(c<=7) { //Put time of click into score variable score=e->time; } else {score=0;} //Win or lose status if(c==16||c==15) { printf("%s\n",event_names[c]); } } //============================================================================================== //Function is used to read video data //============================================================================================== int readumf() { //Initialise local variables int i,j,cur=0; unsigned char c,d; const char* header_1="*umf"; int fs; int version_info_size; //Value gives string length starting at space before Viennasweeper in header int player_info_size; //Value gives string length starting at Name in header int board_size; int preflags_size; int properties_size; int vid_size; int cs_size; int num_player_info; int name_length; int num_preflags; int is_first_event=1; //Check first 4 bytes of header is *umf for(i=0;i<4;++i) if((c=_fgetc(UMF))!=header_1[i]) error("No UMF header"); //The getint2 function reads 2 bytes at a time //In legitimate videos byte 4=0 and byte 5=1, getint2 sum is thus 1 if(getint2(UMF)!=1) error("Invalid video type"); //The getint functions reads 4 bytes at a time fs=getint(UMF); //Gets byte 6-9 version_info_size=getint2(UMF); //Gets byte 10-11 player_info_size=getint2(UMF); //Gets byte 12-13 board_size=getint2(UMF); //Gets byte 14-15 preflags_size=getint2(UMF); //Gets byte 16-17 properties_size=getint2(UMF); //Gets byte 18-19 vid_size=getint(UMF); //Gets byte 20-23 _fgetc(UMF); //Gets byte 24 which is a newline //Throw away byte _fgetc(UMF); //Fetch Version for(i=0;i<version_info_size-1;++i) version[i]=_fgetc(UMF); //Throw away byte _fgetc(UMF); //Check next two bytes to see if player entered Name num_player_info=getint2(UMF); //Fetch Player name if it exists if(num_player_info>0) { name_length=_fgetc(UMF); for(i=0;i<name_length;++i) name[i]=_fgetc(UMF); name[i]=0; } //Throw away next 4 bytes getint(UMF); //Get board size and Mine details w=_fgetc(UMF); //Next byte is w so 8, 9 or 1E h=_fgetc(UMF); //Next byte is h so 8, 9 or 10 m=getint2(UMF); //Next two bytes are number of mines //Fetch board layout and put in memory board=(int*)malloc(sizeof(int)*w*h); for(i=0;i<w*h;++i) board[i]=0; //Every 2 bytes is x,y with 0,0 being the top left corner for(i=0;i<m;++i) { c=_fgetc(UMF);d=_fgetc(UMF); if(c>w || d>h) error("Invalid mine position"); board[d*w+c]=1; } //Check number of flags placed before game started if(preflags_size) { num_preflags=getint2(UMF); for(i=0;i<num_preflags;++i) { c=_fgetc(UMF);d=_fgetc(UMF); video[cur].event=4; video[cur].x=square_size/2+c*square_size; video[cur].y=square_size/2+d*square_size; video[cur++].time=0; video[cur].event=5; video[cur].x=square_size/2+c*square_size; video[cur].y=square_size/2+d*square_size; video[cur++].time=0; } } //Fetch game properties qm=_fgetc(UMF); //Value 1 if Questionmarks used otherwise 0 nf=_fgetc(UMF); //Value 1 if no Flags were used otherwise 0 mode=_fgetc(UMF); //Value 0 for Classic, 1 UPK, 2 Cheat, 3 Density level=_fgetc(UMF); //Value 0 for Beg, 1 Int, 2 Exp, 3 Custom //Throw away some more bytes for(i=4;i<properties_size;++i) _fgetc(UMF); //Each iteration reads one mouse event while(1) { video[cur].event=c=_fgetc(UMF);++i; //Get next 4 bytes containing time of event if(!c) { getint(UMF);i+=4; } //Get mouse event (3 bytes time, 1 wasted, 2 width, 2 height) else if(c<=7) { i+=8; video[cur].time=getint3(UMF); _fgetc(UMF); video[cur].x=getint2(UMF)-12; video[cur++].y=getint2(UMF)-56; //Viennasweeper does not record clicks before timer starts //LR starts timer so the first LC is missed in the video file //This code generates the missing LC in that case //In other cases it generates a ghost event thus event[0] is empty if(is_first_event) { is_first_event=0; video[cur].event=video[cur-1].event; video[cur-1].event=2; video[cur].time=video[cur-1].time; video[cur].x=video[cur-1].x; video[cur].y=video[cur-1].y; cur++; } } else if(c==8) error("Invalid event"); //Get board event (ie, 'pressed' or 'number 3') else if(c<=14 || (c>=18 && c<=27)) { i+=2; video[cur].x=_fgetc(UMF)+1; video[cur].y=_fgetc(UMF)+1; cur++; } //Get game status (ie, 'won') else if(c<=17) { break; } else { error("Invalid event"); } } //Number of game events size=cur+1; return 1; } //============================================================================================== //Function is used to print video data //============================================================================================== void writetxt() { //Initialise local variables int i,j; const char* level_names[]={"Beginner","Intermediate","Expert","Custom"}; const char* mode_names[]={"Classic","UPK","Cheat","Density"}; //Code version and Program printf("RawVF_Version: Rev6\n"); printf("Program: Vienna Minesweeper\n"); //Print Version printf("Version: "); //There are several different Viennsweeper UMF formats //For example, 'Vienna International MineSweeper Meeting 2006-Client.2006.Christoph Nikolaus Marx.Version Debug' //For example, 'Budapest 2007 World Championship-Client.Christoph Nikolaus Marx' //This fetches the Version string but stops at '-' if it exists for(i=0;i<1000;++i) { if(version[i]!='-') verstring[i]=version[i]; else break; } printf("%s\n",verstring); //Print Player printf("Player: %s\n",name); //Print grid details printf("Level: %s\n",level_names[level]); printf("Width: %d\n",w); printf("Height: %d\n",h); printf("Mines: %d\n",m); //Print Marks if(qm) printf("Marks: On\n"); else printf("Marks: Off\n"); //Print Time printf("Time: "); //Time is taken from the last mouse event //Usually this is the 3rd last printed event if(i=size-3) { print_event2(video+i); if(score!=0) { printf("%d.%03d\n",score/1000,score%1000); score_check=1; } } //Sometimes it is the 4th last printed event if(score_check!=1) { if(i=size-4) { print_event2(video+i); if(score!=0) { printf("%d.%03d\n",score/1000,score%1000); score_check=1; } } } //Print Mode printf("Mode: %s\n",mode_names[mode]); //Print Style if(nf) printf("Style: NF\n"); else printf("Style: FL\n"); //Print Status if(i=size-1) { printf("Status: "); print_event2(video+i); } //Print Board printf("Board:\n"); for(i=0;i<h;++i) { for(j=0;j<w;++j) if(board[i*w+j]) printf("*"); else printf("0"); printf("\n"); } //Print Mouse events printf("Events:\n"); printf("0.000 start\n"); for(i=0;i<size;++i) { print_event(video+i); } } //============================================================================================== //Run program and display any error messages //============================================================================================== int main(int argc,char** argv) { //Program can be run in command line as "program video.umf>output.txt" //The output file is optional if you prefer printing to screen if(argc<2) { printf("Error 1: Name of input file missing\n"); printf("Usage: %s <input umf> [nopause]\n",argv[0]); pause(); return 0; } //Open video file UMF=fopen(argv[1],"rb"); //Error if video is not an UMF file if(!UMF) { printf("Error 2: Could not open UMF\n"); return 1; } //Error if video parsing fails if(!readumf()) { printf("Error 3: Invalid UMF\n"); return 1; } //Print results, close file and free memory writetxt(); fclose(UMF);free(board); //Program ends with message to exit if(argc==2) pause(); return 0; }
the_stack_data/220191.c
#include <unistd.h> int main(int argc, char *argv[]) { sync(); return 0; }
the_stack_data/61607.c
/* * Copyright 2015 Google Inc. * All rights reserved. * diagutil -- Linux-based Hardware Diagnostic Utilities */ #include <stdlib.h> #include <stdio.h> #include <string.h> #define DIAGS_VERSION "1.2" /* External Functions */ int ioread(int argc, char **argv); int iowrite(int argc, char **argv); int iowrite_only(int argc, char *argv[]); int i2cprobe(int argc, char **argv); int i2cread(int argc, char **argv); int i2cwrite(int argc, char **argv); int board_temp(int argc, char *argv[]); int led_set(int argc, char *argv[]); int led_set_pwm(int argc, char *argv[]); int switch_state(int argc, char *argv[]); int poe_disable(int argc, char *argv[]); int phy_read(int argc, char *argv[]); int phy_write(int argc, char *argv[]); int loopback_test(int argc, char *argv[]); /* Define the command structure */ typedef struct { const char *name; int (*funcp)(int, char **); } tCOMMAND; void printVersion() { printf("%s\n", DIAGS_VERSION); } int version(int argc, char *argv[]) { // This is to avoid unused params warning if ((argc != 1) || (argv[0] == NULL)) { printf("Invalid command parameter\n"); } printVersion(); return 0; } /* Table of supported commands */ tCOMMAND command_list[] = { {"ioread", ioread}, {"iowrite", iowrite}, {"iowrite_only", iowrite_only}, {"", NULL}, {"i2cread", i2cread}, {"i2cwrite", i2cwrite}, {"i2cprobe", i2cprobe}, {"board_temp", board_temp}, {"led_set", led_set}, {"led_set_pwm", led_set_pwm}, {"", NULL}, {"switch_state", switch_state}, {"poe_disable", poe_disable}, {"", NULL}, {"phy_read", phy_read}, {"phy_write", phy_write}, {"loopback_test", loopback_test}, {"", NULL}, {"version", version}, {"", NULL}, {NULL, NULL}, }; static void usage(void) { int i; printf("Supported commands:\n"); for (i = 0; command_list[i].name != NULL; ++i) { printf("\t%s\n", command_list[i].name); } return; } int main(int argc, char *argv[]) { int i; if (argc > 1) { /* Search the command list for a match */ for (i = 0; command_list[i].name != NULL; ++i) { if (strcmp(argv[1], command_list[i].name) == 0) { return command_list[i].funcp(argc - 1, &argv[1]); } } } /* no command or bad command */ usage(); return 0; }
the_stack_data/187643466.c
static int foo(void) __attribute__((unknown_attribute)); /* * check-name: warn-unknown-attribute-yes * check-command: sparse -Wunknown-attribute $file * * check-error-start Wunknown-attribute-yes.c:1:37: warning: attribute 'unknown_attribute': unknown attribute * check-error-end */
the_stack_data/46141.c
#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define bool int #define false 0 #define true !false #define CLOSE_PATCHER \ if (!silent) { \ puts("Press Enter to close the patcher."); \ getchar(); \ } \ exit(1); #define puts if (!silent) puts #define printf if (!silent) printf #define wait() if (!silent) while (getchar() != '\n'); typedef struct Patch_t { int pos; int orig; int new; } Patch; // when i first wrote this it had like 3 patches and i didn't think i'd keep adding more // maybe one of these days i'll rewrite this to be more modular Patch upx_80[]; Patch joypatch_80[]; Patch joypatch_81_65[]; Patch joypatch_81_140[]; Patch joypatch_81_141[]; Patch dplaypatch_80[]; Patch dplaypatch_81_65[]; Patch dplaypatch_81_140[]; Patch dplaypatch_81_141[]; Patch schedpatch_80[]; Patch schedpatch_80upx[]; Patch schedpatch_81_65[]; Patch schedpatch_81_140[]; Patch schedpatch_81_141[]; bool silent = false; static int can_patch(FILE *f, Patch patches[]) { // returns 2 if already patched, 1 if unpatched, 0 if it's not the right file bool unpatched = true; bool patched = true; int c; for (Patch *p = patches; p->pos != -1; p++) { fseek(f, p->pos, SEEK_SET); c = fgetc(f); if (c != p->orig) { unpatched = false; } if (c != p->new) { patched = false; } } if (patched) return 2; if (unpatched) return 1; return 0; } static void strcatfn(char *s, const char *fn) { #ifdef _WIN32 // windows files can't have quotes so no sanitation necessary strcat(s, "\""); strcat(s, fn); strcat(s, "\""); #else // unix files can have quotes so gotta sanitize for (int i = 0; i < strlen(fn); i++) { if (fn[i] != '"') { *s++ = fn[i]; } else { *s++ = '\\'; *s++ = '"'; } } *s++ = '"'; *s++ = 0; #endif } static bool prompt(const char *text) { if (silent) return true; int c = 0; while (c != 'y' && c != 'n' && c != 'Y' && c != 'N') { printf(text); c = getchar(); while (getchar() != '\n'); } return (c == 'y' || c == 'Y'); } // return true if a backup can be made static bool rename_for_backup(const char *fn, const char *bak_fn) { puts("Making backup..."); bool can_backup = true; // rename the original if (rename(fn, bak_fn)) { if (errno == EEXIST) { errno = 0; printf("There is already a file in location %s\n", bak_fn); if (prompt("Overwrite it? [y/n] ")) { if (remove(bak_fn)) { printf("Could not remove existing file (errno %i).\n", errno); if (prompt("Continue without making a backup? [y/n] ")) { can_backup = false; } else { CLOSE_PATCHER; } } else { if (rename(fn, bak_fn)) { printf("The existing file was deleted, but the backup could still not be made (errno %i).\n", errno); puts("I hope there wasn't anything important in there..."); if (prompt("Continue without making a backup? [y/n] ")) { can_backup = false; } else { CLOSE_PATCHER; } } } } else { can_backup = false; } } else { printf("Failed to add .bak to the filename (errno %i).\n", errno); if (prompt("Continue without making a backup? [y/n] ")) { can_backup = false; } else { CLOSE_PATCHER; } } } return can_backup; } // de-upx if necessary, return true if unpacked static bool upx(FILE **fp, const char *fn, const char *argv0) { FILE *f = *fp; // identify UPX headers fseek(f, 0x170, SEEK_SET); const char head1[] = {0x55, 0x50, 0x58, 0x30, 0, 0, 0, 0}; for (int i = 0; i < 8; i++) { if (fgetc(f) != head1[i]) return false; } fseek(f, 0x198, SEEK_SET); const char head2[] = {0x55, 0x50, 0x58, 0x31, 0, 0, 0, 0}; for (int i = 0; i < 8; i++) { if (fgetc(f) != head2[i]) return false; } // make backup filename char *bak_fn = malloc(strlen(fn) + 5); strcpy(bak_fn, fn); strcat(bak_fn, ".bak"); // ask for confirmation printf("Will make a backup to %s\n", bak_fn); puts("Looks like your game was packed with UPX. We need to unpack it first."); puts("Please download the latest release of UPX from https://github.com/upx/upx/releases/tag/v3.96"); puts("and put upx.exe in the same directory as gm8x_fix.exe, then press Enter to unpack."); wait(); // rename original fclose(f); bool can_backup = rename_for_backup(fn, bak_fn); // get upx path char *cmd_buf = malloc(strlen(bak_fn) * 4 + strlen(argv0)); int path_len = strlen(argv0); while (path_len > 0 && argv0[path_len-1] != '/' #ifdef _WIN32 && argv0[path_len-1] != '\\' #endif ) { path_len--; } cmd_buf[path_len] = 0; if (path_len > 0) { strncpy(cmd_buf, argv0, path_len); } if (can_backup) { strcat(cmd_buf, "upx -d -o "); strcatfn(cmd_buf, fn); strcat(cmd_buf, " "); strcatfn(cmd_buf, bak_fn); } else { strcat(cmd_buf, "upx -d "); strcatfn(cmd_buf, fn); } int res = system(cmd_buf); if (res != 0) { printf("UPX unpack failed (error code %i).", res); if (can_backup && rename(bak_fn, fn) != 0) { printf("Could not restore the original file (errno %i).\n", errno); puts("Your game will have had .bak added to its filename, and no "); puts("patches have been applied."); } else { puts("The backup has been restored and the game is unchanged."); } free(bak_fn); free(cmd_buf); CLOSE_PATCHER; } free(bak_fn); free(cmd_buf); // reopen *fp = f = fopen(fn, "rb"); return true; } static void patch_exe(FILE *f, Patch patches[]) { for (Patch *p = patches; p->pos != -1; p++) { fseek(f, p->pos, SEEK_SET); fputc(p->new, f); } } int main(int argc, const char *argv[]) { // check arguments const char *fn = NULL; bool valid_args = true; if (argc == 2) { fn = argv[1]; } else if (argc == 3) { if (strcmp(argv[1], "-s") == 0) { silent = true; fn = argv[2]; } else { valid_args = false; } } else { valid_args = false; } // funny title puts("Welcome to gm8x_fix v0.4.4!"); puts("Source code is at https://github.com/skyfloogle/gm8x_fix under MIT license."); puts("---------------------------------------------------------------------------"); // compain about arguments if necessary if (!valid_args) { puts("Error: Invalid arguments."); puts("Please drag your Game Maker game onto the patcher's executable file."); puts("Or if you're a commandline nerd, run with this:"); puts(" gm8x_fix [-s] FILE"); puts("Add -s to remove commandline output."); CLOSE_PATCHER; } printf("Inspecting file: %s\n\n", argv[1]); FILE *f = fopen(fn, "rb"); if (f == NULL) { printf("Could not open file (errno %i).\n", errno); CLOSE_PATCHER; } if (fgetc(f) != 'M' || fgetc(f) != 'Z') { fclose(f); puts("This is not an executable file."); CLOSE_PATCHER; } // de-upx if necessary bool unpacked_upx = upx(&f, fn, argv[0]); // identify patches fseek(f, 0x116, SEEK_SET); int mempatch = !(!(fgetc(f) & 0x0020))+1; // IMAGE_FILE_LARGE_ADDRESS_AWARE flag int upx80 = can_patch(f, upx_80); int joy80 = can_patch(f, joypatch_80); int joy81_65 = can_patch(f, joypatch_81_65); int joy81_140 = can_patch(f, joypatch_81_140); int joy81_141 = can_patch(f, joypatch_81_141); int dplay80 = can_patch(f, dplaypatch_80); int dplay81_65 = can_patch(f, dplaypatch_81_65); int dplay81_140 = can_patch(f, dplaypatch_81_140); int dplay81_141 = can_patch(f, dplaypatch_81_141); int sched80 = can_patch(f, schedpatch_80); int sched80upx = can_patch(f, schedpatch_80upx); int sched81_65 = can_patch(f, schedpatch_81_65); int sched81_140 = can_patch(f, schedpatch_81_140); int sched81_141 = can_patch(f, schedpatch_81_141); bool any_patch_applied = upx80 == 2 || joy80 == 2 || joy81_65 == 2 || joy81_140 == 2 || joy81_141 == 2 || sched80 == 2 || sched80upx == 2 || sched81_65 == 2 || sched81_140 == 2 || sched81_141 == 2; bool can_apply_any = upx80 == 1 || joy80 == 1 || joy81_65 == 1 || joy81_140 == 1 || joy81_141 == 1 || sched80 == 1 || sched80upx == 1 || sched81_65 == 1 || sched81_140 == 1 || sched81_141 == 1; // list patches if (!can_apply_any && !any_patch_applied) { puts("This game cannot be patched. It may not be a GameMaker 8.0 or 8.1 game."); fclose(f); CLOSE_PATCHER; } if (unpacked_upx && can_apply_any && upx80 == 0) { puts("Unpacked with UPX, but header offset wasn't recognised. I haven't seen this before, please file an issue on the GitHub."); puts("You can continue applying patches if you want by pressing enter."); wait(); } if (any_patch_applied) { puts("Patches already applied:"); if (upx80 == 2) puts("* UPX unpacked header adjustment"); if (mempatch == 2) puts("* Memory patch"); if (joy80 == 2) puts("* GM8.0 joystick patch"); if (joy81_65 == 2) puts("* GM8.1.65 joystick patch"); if (joy81_140 == 2) puts("* GM8.1.140 joystick patch"); if (joy81_141 == 2) puts("* GM8.1.141 joystick patch"); if (dplay80 == 2) puts("* GM8.0 DirectPlay patch"); if (dplay81_65 == 2) puts("* GM8.1.65 DirectPlay patch"); if (dplay81_140 == 2) puts("* GM8.1.140 DirectPlay patch"); if (dplay81_141 == 2) puts("* GM8.1.141 DirectPlay patch"); if (sched80 == 2) puts("* GM8.0 scheduler patch"); if (sched80upx == 2) puts("* GM8.0 (UPX unpacked) scheduler patch"); if (sched81_65 == 2) puts("* GM8.1.65 scheduler patch"); if (sched81_140 == 2) puts("* GM8.1.140 scheduler patch"); if (sched81_141 == 2) puts("* GM8.1.141 scheduler patch"); } if (can_apply_any) { puts("Patches that can be applied:"); if (upx80 == 1) puts("* UPX unpacked header adjustment (required, I won't ask for confirmation)"); if (mempatch == 1) puts("* Memory patch"); if (joy80 == 1) puts("* GM8.0 joystick patch"); if (joy81_65 == 1) puts("* GM8.1.65 joystick patch"); if (joy81_140 == 1) puts("* GM8.1.140 joystick patch"); if (joy81_141 == 1) puts("* GM8.1.141 joystick patch"); if (dplay80 == 1) puts("* GM8.0 DirectPlay patch"); if (dplay81_65 == 1) puts("* GM8.1.65 DirectPlay patch"); if (dplay81_140 == 1) puts("* GM8.1.140 DirectPlay patch"); if (dplay81_141 == 1) puts("* GM8.1.141 DirectPlay patch"); if (sched80 == 1) puts("* GM8.0 scheduler patch (requires joystick patch)"); if (sched80upx == 1) puts("* GM8.0 (UPX unpacked) scheduler patch (requires joystick patch)"); if (sched81_65 == 1) puts("* GM8.1.65 scheduler patch (requires joystick patch)"); if (sched81_140 == 1) puts("* GM8.1.140 scheduler patch (requires joystick patch)"); if (sched81_141 == 1) puts("* GM8.1.141 scheduler patch (requires joystick patch)"); } else { puts("No new patches can be applied."); fclose(f); CLOSE_PATCHER; } // if we unpacked upx it's already backed up if (!unpacked_upx) { // make backup filename char *bak_fn = malloc(strlen(fn) + 5); strcpy(bak_fn, fn); strcat(bak_fn, ".bak"); // ask for confirmation printf("Will make a backup to %s\n", bak_fn); printf("Press Enter to make a backup and choose patches to apply. "); wait(); fclose(f); // i waited until here to close it so you can't mess with the file before confirming bool can_backup = rename_for_backup(fn, bak_fn); if (can_backup) { // copy it to the original location char *copy_cmd = malloc(strlen(bak_fn) * 4); #ifdef _WIN32 strcpy(copy_cmd, "copy "); #else strcpy(copy_cmd, "cp "); #endif strcatfn(copy_cmd, bak_fn); strcat(copy_cmd, " "); strcatfn(copy_cmd, fn); int res = system(copy_cmd); if (res != 0) { printf("File copy failed (error code %i).\n", res); if (rename(bak_fn, fn) != 0) { printf("Could not restore the original file (errno %i).\n", errno); puts("Your game will have had .bak added to its filename, and no "); puts("patches have been applied."); } else { puts("The backup has been restored and the game is unchanged."); } free(bak_fn); free(copy_cmd); CLOSE_PATCHER; } free(bak_fn); free(copy_cmd); } else { puts("Not backing up."); } } // apply the patches f = fopen(fn, "rb+"); if (upx80 == 1) patch_exe(f, upx_80); if (mempatch == 1 && prompt("Apply memory patch? [y/n] ")) { fseek(f, 0x116, SEEK_SET); int c = fgetc(f); fseek(f, 0x116, SEEK_SET); fputc(c | 0x0020, f); } bool joy_patched = (joy80 == 2 || joy81_65 == 2 || joy81_140 == 2 || joy81_141 == 2); if (joy80 == 1 && prompt("Apply GM8.0 joystick patch? [y/n] ")) { patch_exe(f, joypatch_80); joy_patched = true; } if (joy81_65 == 1 && prompt("Apply GM8.1.65 joystick patch? [y/n] ")) { patch_exe(f, joypatch_81_65); joy_patched = true; } if (joy81_140 == 1 && prompt("Apply GM8.1.140 joystick patch? [y/n] ")) { patch_exe(f, joypatch_81_140); joy_patched = true; } if (joy81_141 == 1 && prompt("Apply GM8.1.141 joystick patch? [y/n] ")) { patch_exe(f, joypatch_81_141); joy_patched = true; } if (dplay80 == 1 && prompt("Apply GM8.0 DirectPlay patch? [y/n] ")) patch_exe(f, dplaypatch_80); if (dplay81_65 == 1 && prompt("Apply GM8.1.65 DirectPlay patch? [y/n] ")) patch_exe(f, dplaypatch_81_65); if (dplay81_140 == 1 && prompt("Apply GM8.1.140 DirectPlay patch? [y/n] ")) patch_exe(f, dplaypatch_81_140); if (dplay81_141 == 1 && prompt("Apply GM8.1.141 DirectPlay patch? [y/n] ")) patch_exe(f, dplaypatch_81_141); if ((sched80 == 1 || sched80upx == 1 || sched81_65 == 1 || sched81_140 == 1 || sched81_141 == 1) && !joy_patched) { puts("It looks like the joystick patch wasn't applied. It's best to apply that if you're going to use the scheduler patch."); } if (sched80 == 1 && prompt("Apply GM8.0 scheduler patch? [y/n] ")) patch_exe(f, schedpatch_80); if (sched80upx == 1 && prompt("Apply GM8.0 (UPX unpacked) scheduler patch? [y/n] ")) patch_exe(f, schedpatch_80upx); if (sched81_65 == 1 && prompt("Apply GM8.1.65 scheduler patch? [y/n] ")) patch_exe(f, schedpatch_81_65); if (sched81_140 == 1 && prompt("Apply GM8.1.140 scheduler patch? [y/n] ")) patch_exe(f, schedpatch_81_140); if (sched81_141 == 1 && prompt("Apply GM8.1.141 scheduler patch? [y/n] ")) patch_exe(f, schedpatch_81_141); fclose(f); puts("All done!"); puts("Press Enter to close the patcher."); wait(); return 0; } Patch upx_80[] = { {0x144ac1, 0xa4, 0xf0}, {0x144ac2, 0x0a, 0x1c}, {-1,0,0} }; Patch joypatch_80[] = { { 0x1399df, 0x53, 0xb8 }, { 0x1399e0, 0x6a, 0xa5 }, { 0x1399e2, 0xe8, 0x0 }, { 0x1399e3, 0x61, 0x0 }, { 0x1399e4, 0x7b, 0x90 }, { 0x1399e5, 0xf4, 0x90 }, { 0x1399e6, 0xff, 0x90 }, { 0x139ae0, 0x53, 0xb8 }, { 0x139ae1, 0x6a, 0xa5 }, { 0x139ae2, 0x1, 0x0 }, { 0x139ae3, 0xe8, 0x0 }, { 0x139ae4, 0x60, 0x0 }, { 0x139ae5, 0x7a, 0x90 }, { 0x139ae6, 0xf4, 0x90 }, { 0x139ae7, 0xff, 0x90 }, { 0x16466d, 0x50, 0xb8 }, { 0x16466e, 0x53, 0xa5 }, { 0x16466f, 0xe8, 0x0 }, { 0x164670, 0xcc, 0x0 }, { 0x164671, 0xce, 0x0 }, { 0x164672, 0xf1, 0x90 }, { 0x164673, 0xff, 0x90 }, { 0x1646cd, 0x50, 0xb8 }, { 0x1646ce, 0x56, 0xa5 }, { 0x1646cf, 0xe8, 0x0 }, { 0x1646d0, 0x6c, 0x0 }, { 0x1646d1, 0xce, 0x0 }, { 0x1646d2, 0xf1, 0x90 }, { 0x1646d3, 0xff, 0x90 }, { 0x164767, 0x68, 0xb8 }, { 0x164768, 0x94, 0xa5 }, { 0x164769, 0x1, 0x0 }, { 0x16476c, 0x8d, 0x90 }, { 0x16476d, 0x85, 0x90 }, { 0x16476e, 0x6c, 0x90 }, { 0x16476f, 0xfe, 0x90 }, { 0x164770, 0xff, 0x90 }, { 0x164771, 0xff, 0x90 }, { 0x164772, 0x50, 0x90 }, { 0x164773, 0x56, 0x90 }, { 0x164774, 0xe8, 0x90 }, { 0x164775, 0xbf, 0x90 }, { 0x164776, 0xcd, 0x90 }, { 0x164777, 0xf1, 0x90 }, { 0x164778, 0xff, 0x90 }, { 0x1647d1, 0x68, 0xb8 }, { 0x1647d2, 0x94, 0xa5 }, { 0x1647d3, 0x1, 0x0 }, { 0x1647d6, 0x8d, 0x90 }, { 0x1647d7, 0x85, 0x90 }, { 0x1647d8, 0x6c, 0x90 }, { 0x1647d9, 0xfe, 0x90 }, { 0x1647da, 0xff, 0x90 }, { 0x1647db, 0xff, 0x90 }, { 0x1647dc, 0x50, 0x90 }, { 0x1647dd, 0x56, 0x90 }, { 0x1647de, 0xe8, 0x90 }, { 0x1647df, 0x55, 0x90 }, { 0x1647e0, 0xcd, 0x90 }, { 0x1647e1, 0xf1, 0x90 }, { 0x1647e2, 0xff, 0x90 }, { 0x164849, 0x68, 0xb8 }, { 0x16484a, 0x94, 0xa5 }, { 0x16484b, 0x1, 0x0 }, { 0x16484e, 0x8d, 0x90 }, { 0x16484f, 0x85, 0x90 }, { 0x164850, 0x6c, 0x90 }, { 0x164851, 0xfe, 0x90 }, { 0x164852, 0xff, 0x90 }, { 0x164853, 0xff, 0x90 }, { 0x164854, 0x50, 0x90 }, { 0x164855, 0x56, 0x90 }, { 0x164856, 0xe8, 0x90 }, { 0x164857, 0xdd, 0x90 }, { 0x164858, 0xcc, 0x90 }, { 0x164859, 0xf1, 0x90 }, { 0x16485a, 0xff, 0x90 }, { 0x1648c1, 0x68, 0xb8 }, { 0x1648c2, 0x94, 0xa5 }, { 0x1648c3, 0x1, 0x0 }, { 0x1648c6, 0x8d, 0x90 }, { 0x1648c7, 0x85, 0x90 }, { 0x1648c8, 0x6c, 0x90 }, { 0x1648c9, 0xfe, 0x90 }, { 0x1648ca, 0xff, 0x90 }, { 0x1648cb, 0xff, 0x90 }, { 0x1648cc, 0x50, 0x90 }, { 0x1648cd, 0x56, 0x90 }, { 0x1648ce, 0xe8, 0x90 }, { 0x1648cf, 0x65, 0x90 }, { 0x1648d0, 0xcc, 0x90 }, { 0x1648d1, 0xf1, 0x90 }, { 0x1648d2, 0xff, 0x90 }, { 0x164948, 0x50, 0xb8 }, { 0x164949, 0x56, 0xa5 }, { 0x16494a, 0xe8, 0x0 }, { 0x16494b, 0xf9, 0x0 }, { 0x16494c, 0xcb, 0x0 }, { 0x16494d, 0xf1, 0x90 }, { 0x16494e, 0xff, 0x90 }, { 0x164daf, 0x50, 0xb8 }, { 0x164db0, 0x56, 0xa5 }, { 0x164db1, 0xe8, 0x0 }, { 0x164db2, 0x92, 0x0 }, { 0x164db3, 0xc7, 0x0 }, { 0x164db4, 0xf1, 0x90 }, { 0x164db5, 0xff, 0x90 }, { 0x164e2f, 0x50, 0xb8 }, { 0x164e30, 0x56, 0xa5 }, { 0x164e31, 0xe8, 0x0 }, { 0x164e32, 0x12, 0x0 }, { 0x164e33, 0xc7, 0x0 }, { 0x164e34, 0xf1, 0x90 }, { 0x164e35, 0xff, 0x90 }, { 0x164eaf, 0x50, 0xb8 }, { 0x164eb0, 0x56, 0xa5 }, { 0x164eb1, 0xe8, 0x0 }, { 0x164eb2, 0x92, 0x0 }, { 0x164eb3, 0xc6, 0x0 }, { 0x164eb4, 0xf1, 0x90 }, { 0x164eb5, 0xff, 0x90 }, { 0x164f2f, 0x50, 0xb8 }, { 0x164f30, 0x56, 0xa5 }, { 0x164f31, 0xe8, 0x0 }, { 0x164f32, 0x12, 0x0 }, { 0x164f33, 0xc6, 0x0 }, { 0x164f34, 0xf1, 0x90 }, { 0x164f35, 0xff, 0x90 }, { 0x164faf, 0x50, 0xb8 }, { 0x164fb0, 0x56, 0xa5 }, { 0x164fb1, 0xe8, 0x0 }, { 0x164fb2, 0x92, 0x0 }, { 0x164fb3, 0xc5, 0x0 }, { 0x164fb4, 0xf1, 0x90 }, { 0x164fb5, 0xff, 0x90 }, { 0x16502f, 0x50, 0xb8 }, { 0x165030, 0x56, 0xa5 }, { 0x165031, 0xe8, 0x0 }, { 0x165032, 0x12, 0x0 }, { 0x165033, 0xc5, 0x0 }, { 0x165034, 0xf1, 0x90 }, { 0x165035, 0xff, 0x90 }, { 0x1650b3, 0x50, 0xb8 }, { 0x1650b4, 0x56, 0xa5 }, { 0x1650b5, 0xe8, 0x0 }, { 0x1650b6, 0x8e, 0x0 }, { 0x1650b7, 0xc4, 0x0 }, { 0x1650b8, 0xf1, 0x90 }, { 0x1650b9, 0xff, 0x90 }, {-1,0,0} }; Patch joypatch_81_65[] = { { 0x1cefb3, 0x53, 0xb8 }, { 0x1cefb4, 0x6a, 0xa5 }, { 0x1cefb6, 0xe8, 0x00 }, { 0x1cefb7, 0x4d, 0x00 }, { 0x1cefb8, 0xa2, 0x90 }, { 0x1cefb9, 0xf3, 0x90 }, { 0x1cefba, 0xff, 0x90 }, { 0x1cf0b4, 0x53, 0xb8 }, { 0x1cf0b5, 0x6a, 0xa5 }, { 0x1cf0b6, 0x01, 0x00 }, { 0x1cf0b7, 0xe8, 0x00 }, { 0x1cf0b8, 0x4c, 0x00 }, { 0x1cf0b9, 0xa1, 0x90 }, { 0x1cf0ba, 0xf3, 0x90 }, { 0x1cf0bb, 0xff, 0x90 }, { 0x20a5ea, 0x8d, 0xb8 }, { 0x20a5eb, 0x45, 0xa5 }, { 0x20a5ec, 0xf0, 0x00 }, { 0x20a5ed, 0x50, 0x00 }, { 0x20a5ee, 0x53, 0x00 }, { 0x20a5ef, 0xe8, 0x90 }, { 0x20a5f0, 0x0c, 0x90 }, { 0x20a5f1, 0xec, 0x90 }, { 0x20a5f2, 0xef, 0x90 }, { 0x20a5f3, 0xff, 0x90 }, { 0x20a64a, 0x8d, 0xb8 }, { 0x20a64b, 0x45, 0xa5 }, { 0x20a64c, 0xf0, 0x00 }, { 0x20a64d, 0x50, 0x00 }, { 0x20a64e, 0x56, 0x00 }, { 0x20a64f, 0xe8, 0x90 }, { 0x20a650, 0xac, 0x90 }, { 0x20a651, 0xeb, 0x90 }, { 0x20a652, 0xef, 0x90 }, { 0x20a653, 0xff, 0x90 }, { 0x20a6e9, 0x68, 0xb8 }, { 0x20a6ea, 0xd8, 0xa5 }, { 0x20a6eb, 0x02, 0x00 }, { 0x20a6ee, 0x8d, 0x90 }, { 0x20a6ef, 0x85, 0x90 }, { 0x20a6f0, 0x28, 0x90 }, { 0x20a6f1, 0xfd, 0x90 }, { 0x20a6f2, 0xff, 0x90 }, { 0x20a6f3, 0xff, 0x90 }, { 0x20a6f4, 0x50, 0x90 }, { 0x20a6f5, 0x56, 0x90 }, { 0x20a6f6, 0xe8, 0x90 }, { 0x20a6f7, 0xfd, 0x90 }, { 0x20a6f8, 0xea, 0x90 }, { 0x20a6f9, 0xef, 0x90 }, { 0x20a6fa, 0xff, 0x90 }, { 0x20a755, 0x68, 0xb8 }, { 0x20a756, 0xd8, 0xa5 }, { 0x20a757, 0x02, 0x00 }, { 0x20a75a, 0x8d, 0x90 }, { 0x20a75b, 0x85, 0x90 }, { 0x20a75c, 0x28, 0x90 }, { 0x20a75d, 0xfd, 0x90 }, { 0x20a75e, 0xff, 0x90 }, { 0x20a75f, 0xff, 0x90 }, { 0x20a760, 0x50, 0x90 }, { 0x20a761, 0x56, 0x90 }, { 0x20a762, 0xe8, 0x90 }, { 0x20a763, 0x91, 0x90 }, { 0x20a764, 0xea, 0x90 }, { 0x20a765, 0xef, 0x90 }, { 0x20a766, 0xff, 0x90 }, { 0x20a7cd, 0x68, 0xb8 }, { 0x20a7ce, 0xd8, 0xa5 }, { 0x20a7cf, 0x02, 0x00 }, { 0x20a7d2, 0x8d, 0x90 }, { 0x20a7d3, 0x85, 0x90 }, { 0x20a7d4, 0x28, 0x90 }, { 0x20a7d5, 0xfd, 0x90 }, { 0x20a7d6, 0xff, 0x90 }, { 0x20a7d7, 0xff, 0x90 }, { 0x20a7d8, 0x50, 0x90 }, { 0x20a7d9, 0x56, 0x90 }, { 0x20a7da, 0xe8, 0x90 }, { 0x20a7db, 0x19, 0x90 }, { 0x20a7dc, 0xea, 0x90 }, { 0x20a7dd, 0xef, 0x90 }, { 0x20a7de, 0xff, 0x90 }, { 0x20a845, 0x68, 0xb8 }, { 0x20a846, 0xd8, 0xa5 }, { 0x20a847, 0x02, 0x00 }, { 0x20a84a, 0x8d, 0x90 }, { 0x20a84b, 0x85, 0x90 }, { 0x20a84c, 0x28, 0x90 }, { 0x20a84d, 0xfd, 0x90 }, { 0x20a84e, 0xff, 0x90 }, { 0x20a84f, 0xff, 0x90 }, { 0x20a850, 0x50, 0x90 }, { 0x20a851, 0x56, 0x90 }, { 0x20a852, 0xe8, 0x90 }, { 0x20a853, 0xa1, 0x90 }, { 0x20a854, 0xe9, 0x90 }, { 0x20a855, 0xef, 0x90 }, { 0x20a856, 0xff, 0x90 }, { 0x20a8c9, 0x8d, 0xb8 }, { 0x20a8ca, 0x45, 0xa5 }, { 0x20a8cb, 0xcc, 0x00 }, { 0x20a8cc, 0x50, 0x00 }, { 0x20a8cd, 0x56, 0x00 }, { 0x20a8ce, 0xe8, 0x90 }, { 0x20a8cf, 0x35, 0x90 }, { 0x20a8d0, 0xe9, 0x90 }, { 0x20a8d1, 0xef, 0x90 }, { 0x20a8d2, 0xff, 0x90 }, { 0x20ad30, 0x8d, 0xb8 }, { 0x20ad31, 0x45, 0xa5 }, { 0x20ad32, 0xcc, 0x00 }, { 0x20ad33, 0x50, 0x00 }, { 0x20ad34, 0x56, 0x00 }, { 0x20ad35, 0xe8, 0x90 }, { 0x20ad36, 0xce, 0x90 }, { 0x20ad37, 0xe4, 0x90 }, { 0x20ad38, 0xef, 0x90 }, { 0x20ad39, 0xff, 0x90 }, { 0x20adb0, 0x8d, 0xb8 }, { 0x20adb1, 0x45, 0xa5 }, { 0x20adb2, 0xcc, 0x00 }, { 0x20adb3, 0x50, 0x00 }, { 0x20adb4, 0x56, 0x00 }, { 0x20adb5, 0xe8, 0x90 }, { 0x20adb6, 0x4e, 0x90 }, { 0x20adb7, 0xe4, 0x90 }, { 0x20adb8, 0xef, 0x90 }, { 0x20adb9, 0xff, 0x90 }, { 0x20ae30, 0x8d, 0xb8 }, { 0x20ae31, 0x45, 0xa5 }, { 0x20ae32, 0xcc, 0x00 }, { 0x20ae33, 0x50, 0x00 }, { 0x20ae34, 0x56, 0x00 }, { 0x20ae35, 0xe8, 0x90 }, { 0x20ae36, 0xce, 0x90 }, { 0x20ae37, 0xe3, 0x90 }, { 0x20ae38, 0xef, 0x90 }, { 0x20ae39, 0xff, 0x90 }, { 0x20aeb0, 0x8d, 0xb8 }, { 0x20aeb1, 0x45, 0xa5 }, { 0x20aeb2, 0xcc, 0x00 }, { 0x20aeb3, 0x50, 0x00 }, { 0x20aeb4, 0x56, 0x00 }, { 0x20aeb5, 0xe8, 0x90 }, { 0x20aeb6, 0x4e, 0x90 }, { 0x20aeb7, 0xe3, 0x90 }, { 0x20aeb8, 0xef, 0x90 }, { 0x20aeb9, 0xff, 0x90 }, { 0x20af30, 0x8d, 0xb8 }, { 0x20af31, 0x45, 0xa5 }, { 0x20af32, 0xcc, 0x00 }, { 0x20af33, 0x50, 0x00 }, { 0x20af34, 0x56, 0x00 }, { 0x20af35, 0xe8, 0x90 }, { 0x20af36, 0xce, 0x90 }, { 0x20af37, 0xe2, 0x90 }, { 0x20af38, 0xef, 0x90 }, { 0x20af39, 0xff, 0x90 }, { 0x20afb0, 0x8d, 0xb8 }, { 0x20afb1, 0x45, 0xa5 }, { 0x20afb2, 0xcc, 0x00 }, { 0x20afb3, 0x50, 0x00 }, { 0x20afb4, 0x56, 0x00 }, { 0x20afb5, 0xe8, 0x90 }, { 0x20afb6, 0x4e, 0x90 }, { 0x20afb7, 0xe2, 0x90 }, { 0x20afb8, 0xef, 0x90 }, { 0x20afb9, 0xff, 0x90 }, { 0x20b034, 0x8d, 0xb8 }, { 0x20b035, 0x45, 0xa5 }, { 0x20b036, 0xcc, 0x00 }, { 0x20b037, 0x50, 0x00 }, { 0x20b038, 0x56, 0x00 }, { 0x20b039, 0xe8, 0x90 }, { 0x20b03a, 0xca, 0x90 }, { 0x20b03b, 0xe1, 0x90 }, { 0x20b03c, 0xef, 0x90 }, { 0x20b03d, 0xff, 0x90 }, {-1,0,0} }; Patch joypatch_81_140[] = { { 0x1f6cdb, 0x53, 0xb8 }, { 0x1f6cdc, 0x6a, 0xa5 }, { 0x1f6cde, 0xe8, 0x0 }, { 0x1f6cdf, 0x39, 0x0 }, { 0x1f6ce0, 0x59, 0x90 }, { 0x1f6ce1, 0xf1, 0x90 }, { 0x1f6ce2, 0xff, 0x90 }, { 0x1f6ddc, 0x53, 0xb8 }, { 0x1f6ddd, 0x6a, 0xa5 }, { 0x1f6dde, 0x1, 0x0 }, { 0x1f6ddf, 0xe8, 0x0 }, { 0x1f6de0, 0x38, 0x0 }, { 0x1f6de1, 0x58, 0x90 }, { 0x1f6de2, 0xf1, 0x90 }, { 0x1f6de3, 0xff, 0x90 }, { 0x2444e1, 0x50, 0xb8 }, { 0x2444e2, 0x53, 0xa5 }, { 0x2444e3, 0xe8, 0x0 }, { 0x2444e4, 0x2c, 0x0 }, { 0x2444e5, 0x81, 0x0 }, { 0x2444e6, 0xec, 0x90 }, { 0x2444e7, 0xff, 0x90 }, { 0x244541, 0x50, 0xb8 }, { 0x244542, 0x56, 0xa5 }, { 0x244543, 0xe8, 0x0 }, { 0x244544, 0xcc, 0x0 }, { 0x244545, 0x80, 0x0 }, { 0x244546, 0xec, 0x90 }, { 0x244547, 0xff, 0x90 }, { 0x2445e6, 0x50, 0xb8 }, { 0x2445e7, 0x56, 0xa5 }, { 0x2445e8, 0xe8, 0x0 }, { 0x2445e9, 0x1f, 0x0 }, { 0x2445ea, 0x80, 0x0 }, { 0x2445eb, 0xec, 0x90 }, { 0x2445ec, 0xff, 0x90 }, { 0x244658, 0x50, 0xb8 }, { 0x244659, 0x56, 0xa5 }, { 0x24465a, 0xe8, 0x0 }, { 0x24465b, 0xad, 0x0 }, { 0x24465c, 0x7f, 0x0 }, { 0x24465d, 0xec, 0x90 }, { 0x24465e, 0xff, 0x90 }, { 0x2446d0, 0x50, 0xb8 }, { 0x2446d1, 0x56, 0xa5 }, { 0x2446d2, 0xe8, 0x0 }, { 0x2446d3, 0x35, 0x0 }, { 0x2446d4, 0x7f, 0x0 }, { 0x2446d5, 0xec, 0x90 }, { 0x2446d6, 0xff, 0x90 }, { 0x244748, 0x50, 0xb8 }, { 0x244749, 0x56, 0xa5 }, { 0x24474a, 0xe8, 0x0 }, { 0x24474b, 0xbd, 0x0 }, { 0x24474c, 0x7e, 0x0 }, { 0x24474d, 0xec, 0x90 }, { 0x24474e, 0xff, 0x90 }, { 0x2447c4, 0x50, 0xb8 }, { 0x2447c5, 0x56, 0xa5 }, { 0x2447c6, 0xe8, 0x0 }, { 0x2447c7, 0x51, 0x0 }, { 0x2447c8, 0x7e, 0x0 }, { 0x2447c9, 0xec, 0x90 }, { 0x2447ca, 0xff, 0x90 }, { 0x244c2b, 0x50, 0xb8 }, { 0x244c2c, 0x56, 0xa5 }, { 0x244c2d, 0xe8, 0x0 }, { 0x244c2e, 0xea, 0x0 }, { 0x244c2f, 0x79, 0x0 }, { 0x244c30, 0xec, 0x90 }, { 0x244c31, 0xff, 0x90 }, { 0x244cab, 0x50, 0xb8 }, { 0x244cac, 0x56, 0xa5 }, { 0x244cad, 0xe8, 0x0 }, { 0x244cae, 0x6a, 0x0 }, { 0x244caf, 0x79, 0x0 }, { 0x244cb0, 0xec, 0x90 }, { 0x244cb1, 0xff, 0x90 }, { 0x244d2b, 0x50, 0xb8 }, { 0x244d2c, 0x56, 0xa5 }, { 0x244d2d, 0xe8, 0x0 }, { 0x244d2e, 0xea, 0x0 }, { 0x244d2f, 0x78, 0x0 }, { 0x244d30, 0xec, 0x90 }, { 0x244d31, 0xff, 0x90 }, { 0x244dab, 0x50, 0xb8 }, { 0x244dac, 0x56, 0xa5 }, { 0x244dad, 0xe8, 0x0 }, { 0x244dae, 0x6a, 0x0 }, { 0x244daf, 0x78, 0x0 }, { 0x244db0, 0xec, 0x90 }, { 0x244db1, 0xff, 0x90 }, { 0x244e2b, 0x50, 0xb8 }, { 0x244e2c, 0x56, 0xa5 }, { 0x244e2d, 0xe8, 0x0 }, { 0x244e2e, 0xea, 0x0 }, { 0x244e2f, 0x77, 0x0 }, { 0x244e30, 0xec, 0x90 }, { 0x244e31, 0xff, 0x90 }, { 0x244eab, 0x50, 0xb8 }, { 0x244eac, 0x56, 0xa5 }, { 0x244ead, 0xe8, 0x0 }, { 0x244eae, 0x6a, 0x0 }, { 0x244eaf, 0x77, 0x0 }, { 0x244eb0, 0xec, 0x90 }, { 0x244eb1, 0xff, 0x90 }, { 0x244f2f, 0x50, 0xb8 }, { 0x244f30, 0x56, 0xa5 }, { 0x244f31, 0xe8, 0x0 }, { 0x244f32, 0xe6, 0x0 }, { 0x244f33, 0x76, 0x0 }, { 0x244f34, 0xec, 0x90 }, { 0x244f35, 0xff, 0x90 }, {-1,0,0} }; Patch joypatch_81_141[] = { { 0x1f6ce7, 0x53, 0xb8 }, { 0x1f6ce8, 0x6a, 0xa5 }, { 0x1f6cea, 0xe8, 0x0 }, { 0x1f6ceb, 0x2d, 0x0 }, { 0x1f6cec, 0x59, 0x90 }, { 0x1f6ced, 0xf1, 0x90 }, { 0x1f6cee, 0xff, 0x90 }, { 0x1f6de8, 0x53, 0xb8 }, { 0x1f6de9, 0x6a, 0xa5 }, { 0x1f6dea, 0x1, 0x0 }, { 0x1f6deb, 0xe8, 0x0 }, { 0x1f6dec, 0x2c, 0x0 }, { 0x1f6ded, 0x58, 0x90 }, { 0x1f6dee, 0xf1, 0x90 }, { 0x1f6def, 0xff, 0x90 }, { 0x244711, 0x50, 0xb8 }, { 0x244712, 0x53, 0xa5 }, { 0x244713, 0xe8, 0x0 }, { 0x244714, 0xfc, 0x0 }, { 0x244715, 0x7e, 0x0 }, { 0x244716, 0xec, 0x90 }, { 0x244717, 0xff, 0x90 }, { 0x244771, 0x50, 0xb8 }, { 0x244772, 0x56, 0xa5 }, { 0x244773, 0xe8, 0x0 }, { 0x244774, 0x9c, 0x0 }, { 0x244775, 0x7e, 0x0 }, { 0x244776, 0xec, 0x90 }, { 0x244777, 0xff, 0x90 }, { 0x24480b, 0x68, 0xb8 }, { 0x24480c, 0xd8, 0xa5 }, { 0x24480d, 0x2, 0x0 }, { 0x244810, 0x8d, 0x90 }, { 0x244811, 0x85, 0x90 }, { 0x244812, 0x28, 0x90 }, { 0x244813, 0xfd, 0x90 }, { 0x244814, 0xff, 0x90 }, { 0x244815, 0xff, 0x90 }, { 0x244816, 0x50, 0x90 }, { 0x244817, 0x56, 0x90 }, { 0x244818, 0xe8, 0x90 }, { 0x244819, 0xef, 0x90 }, { 0x24481a, 0x7d, 0x90 }, { 0x24481b, 0xec, 0x90 }, { 0x24481c, 0xff, 0x90 }, { 0x24487d, 0x68, 0xb8 }, { 0x24487e, 0xd8, 0xa5 }, { 0x24487f, 0x2, 0x0 }, { 0x244882, 0x8d, 0x90 }, { 0x244883, 0x85, 0x90 }, { 0x244884, 0x28, 0x90 }, { 0x244885, 0xfd, 0x90 }, { 0x244886, 0xff, 0x90 }, { 0x244887, 0xff, 0x90 }, { 0x244888, 0x50, 0x90 }, { 0x244889, 0x56, 0x90 }, { 0x24488a, 0xe8, 0x90 }, { 0x24488b, 0x7d, 0x90 }, { 0x24488c, 0x7d, 0x90 }, { 0x24488d, 0xec, 0x90 }, { 0x24488e, 0xff, 0x90 }, { 0x2448f5, 0x68, 0xb8 }, { 0x2448f6, 0xd8, 0xa5 }, { 0x2448f7, 0x2, 0x0 }, { 0x2448fa, 0x8d, 0x90 }, { 0x2448fb, 0x85, 0x90 }, { 0x2448fc, 0x28, 0x90 }, { 0x2448fd, 0xfd, 0x90 }, { 0x2448fe, 0xff, 0x90 }, { 0x2448ff, 0xff, 0x90 }, { 0x244900, 0x50, 0x90 }, { 0x244901, 0x56, 0x90 }, { 0x244902, 0xe8, 0x90 }, { 0x244903, 0x5, 0x90 }, { 0x244904, 0x7d, 0x90 }, { 0x244905, 0xec, 0x90 }, { 0x244906, 0xff, 0x90 }, { 0x24496d, 0x68, 0xb8 }, { 0x24496e, 0xd8, 0xa5 }, { 0x24496f, 0x2, 0x0 }, { 0x244972, 0x8d, 0x90 }, { 0x244973, 0x85, 0x90 }, { 0x244974, 0x28, 0x90 }, { 0x244975, 0xfd, 0x90 }, { 0x244976, 0xff, 0x90 }, { 0x244977, 0xff, 0x90 }, { 0x244978, 0x50, 0x90 }, { 0x244979, 0x56, 0x90 }, { 0x24497a, 0xe8, 0x90 }, { 0x24497b, 0x8d, 0x90 }, { 0x24497c, 0x7c, 0x90 }, { 0x24497d, 0xec, 0x90 }, { 0x24497e, 0xff, 0x90 }, { 0x2449f4, 0x50, 0xb8 }, { 0x2449f5, 0x56, 0xa5 }, { 0x2449f6, 0xe8, 0x0 }, { 0x2449f7, 0x21, 0x0 }, { 0x2449f8, 0x7c, 0x0 }, { 0x2449f9, 0xec, 0x90 }, { 0x2449fa, 0xff, 0x90 }, { 0x244e5b, 0x50, 0xb8 }, { 0x244e5c, 0x56, 0xa5 }, { 0x244e5d, 0xe8, 0x0 }, { 0x244e5e, 0xba, 0x0 }, { 0x244e5f, 0x77, 0x0 }, { 0x244e60, 0xec, 0x90 }, { 0x244e61, 0xff, 0x90 }, { 0x244edb, 0x50, 0xb8 }, { 0x244edc, 0x56, 0xa5 }, { 0x244edd, 0xe8, 0x0 }, { 0x244ede, 0x3a, 0x0 }, { 0x244edf, 0x77, 0x0 }, { 0x244ee0, 0xec, 0x90 }, { 0x244ee1, 0xff, 0x90 }, { 0x244f5b, 0x50, 0xb8 }, { 0x244f5c, 0x56, 0xa5 }, { 0x244f5d, 0xe8, 0x0 }, { 0x244f5e, 0xba, 0x0 }, { 0x244f5f, 0x76, 0x0 }, { 0x244f60, 0xec, 0x90 }, { 0x244f61, 0xff, 0x90 }, { 0x244fdb, 0x50, 0xb8 }, { 0x244fdc, 0x56, 0xa5 }, { 0x244fdd, 0xe8, 0x0 }, { 0x244fde, 0x3a, 0x0 }, { 0x244fdf, 0x76, 0x0 }, { 0x244fe0, 0xec, 0x90 }, { 0x244fe1, 0xff, 0x90 }, { 0x24505b, 0x50, 0xb8 }, { 0x24505c, 0x56, 0xa5 }, { 0x24505d, 0xe8, 0x0 }, { 0x24505e, 0xba, 0x0 }, { 0x24505f, 0x75, 0x0 }, { 0x245060, 0xec, 0x90 }, { 0x245061, 0xff, 0x90 }, { 0x2450db, 0x50, 0xb8 }, { 0x2450dc, 0x56, 0xa5 }, { 0x2450dd, 0xe8, 0x0 }, { 0x2450de, 0x3a, 0x0 }, { 0x2450df, 0x75, 0x0 }, { 0x2450e0, 0xec, 0x90 }, { 0x2450e1, 0xff, 0x90 }, { 0x24515f, 0x50, 0xb8 }, { 0x245160, 0x56, 0xa5 }, { 0x245161, 0xe8, 0x0 }, { 0x245162, 0xb6, 0x0 }, { 0x245163, 0x74, 0x0 }, { 0x245164, 0xec, 0x90 }, { 0x245165, 0xff, 0x90 }, {-1,0,0} }; Patch dplaypatch_80[] = { { 0x187380, 'D', 0 }, { 0x187381, 'P', 'P' }, { 0x187382, 'l', 'l' }, { 0x187383, 'a', 'a' }, { 0x187384, 'y', 'y' }, { 0x187385, 'X', 'X' }, {-1,0,0} }; Patch dplaypatch_81_65[] = { { 0x23d184, 'D', 0 }, { 0x23d186, 'P', 'P' }, { 0x23d188, 'l', 'l' }, { 0x23d18a, 'a', 'a' }, { 0x23d18c, 'y', 'y' }, { 0x23d18e, 'X', 'X' }, {-1,0,0} }; Patch dplaypatch_81_140[] = { { 0x279a10, 'D', 0 }, { 0x279a12, 'P', 'P' }, { 0x279a14, 'l', 'l' }, { 0x279a16, 'a', 'a' }, { 0x279a18, 'y', 'y' }, { 0x279a1a, 'X', 'X' }, {-1,0,0} }; Patch dplaypatch_81_141[] = { { 0x279c10, 'D', 0 }, { 0x279c12, 'P', 'P' }, { 0x279c14, 'l', 'l' }, { 0x279c16, 'a', 'a' }, { 0x279c18, 'y', 'y' }, { 0x279c1a, 'X', 'X' }, {-1,0,0} }; Patch schedpatch_80[] = { {0x14461a, 0xb8, 0x6a}, {0x14461b, 0x2d, 0x01}, {0x14461c, 0x00, 0xe8}, {0x14461d, 0x00, 0x17}, {0x14461e, 0x00, 0xcf}, {0x14461f, 0xe8, 0xf3}, {0x144620, 0x18, 0xff}, {0x144621, 0xef, 0x90}, {0x144622, 0xff, 0x90}, {0x144623, 0xff, 0x90}, {0x191e82, 0x6a, 0x74}, {0x191e83, 0x6f, 0x69}, {0x191e84, 0x79, 0x6d}, {0x191e85, 0x47, 0x65}, {0x191e86, 0x65, 0x42}, {0x191e87, 0x74, 0x65}, {0x191e88, 0x44, 0x67}, {0x191e89, 0x65, 0x69}, {0x191e8a, 0x76, 0x6e}, {0x191e8b, 0x43, 0x50}, {0x191e8c, 0x61, 0x65}, {0x191e8d, 0x70, 0x72}, {0x191e8e, 0x73, 0x69}, {0x191e8f, 0x41, 0x6f}, {0x191e90, 0x00, 0x64}, {-1,0,0} }; Patch schedpatch_80upx[] = { {0x14461a, 0xb8, 0x6a}, {0x14461b, 0x2d, 0x01}, {0x14461c, 0x00, 0xe8}, {0x14461d, 0x00, 0x17}, {0x14461e, 0x00, 0xcf}, {0x14461f, 0xe8, 0xf3}, {0x144620, 0x18, 0xff}, {0x144621, 0xef, 0x90}, {0x144622, 0xff, 0x90}, {0x144623, 0xff, 0x90}, {0x191c4e, 0x6a, 0x74}, {0x191c4f, 0x6f, 0x69}, {0x191c50, 0x79, 0x6d}, {0x191c51, 0x47, 0x65}, {0x191c52, 0x65, 0x42}, {0x191c53, 0x74, 0x65}, {0x191c54, 0x44, 0x67}, {0x191c55, 0x65, 0x69}, {0x191c56, 0x76, 0x6e}, {0x191c57, 0x43, 0x50}, {0x191c58, 0x61, 0x65}, {0x191c59, 0x70, 0x72}, {0x191c5a, 0x73, 0x69}, {0x191c5b, 0x41, 0x6f}, {0x191c5c, 0x00, 0x64}, {-1,0,0} }; Patch schedpatch_81_65[] = { { 0x1e3fd6, 0xb8, 0x6a }, { 0x1e3fd7, 0x2d, 0x01 }, { 0x1e3fd8, 0x00, 0xe8 }, { 0x1e3fd9, 0x00, 0x1b }, { 0x1e3fda, 0x00, 0x52 }, { 0x1e3fdb, 0xe8, 0xf2 }, { 0x1e3fdc, 0x98, 0xff }, { 0x1e3fdd, 0xe7, 0x90 }, { 0x1e3fde, 0xff, 0x90 }, { 0x1e3fdf, 0xff, 0x90 }, { 0x24cb5e, 0x6a, 0x74 }, { 0x24cb5f, 0x6f, 0x69 }, { 0x24cb60, 0x79, 0x6d }, { 0x24cb61, 0x47, 0x65 }, { 0x24cb62, 0x65, 0x42 }, { 0x24cb63, 0x74, 0x65 }, { 0x24cb64, 0x44, 0x67 }, { 0x24cb65, 0x65, 0x69 }, { 0x24cb66, 0x76, 0x6e }, { 0x24cb67, 0x43, 0x50 }, { 0x24cb68, 0x61, 0x65 }, { 0x24cb69, 0x70, 0x72 }, { 0x24cb6a, 0x73, 0x69 }, { 0x24cb6b, 0x57, 0x6f }, { 0x24cb6c, 0x00, 0x64 }, {-1,0,0} }; Patch schedpatch_81_140[] = { { 0x279d23, 0xb8, 0x6a }, { 0x279d24, 0x20, 0x1 }, { 0x279d25, 0xb1, 0xe8 }, { 0x279d26, 0x67, 0xe2 }, { 0x279d27, 0x0, 0x22 }, { 0x279d28, 0xe8, 0xe9 }, { 0x279d29, 0xd7, 0xff }, { 0x279d2a, 0x67, 0x90 }, { 0x279d2b, 0xee, 0x90 }, { 0x279d2c, 0xff, 0x90 }, { 0x28bc88, 0x6a, 0x74 }, { 0x28bc89, 0x6f, 0x69 }, { 0x28bc8a, 0x79, 0x6d }, { 0x28bc8b, 0x47, 0x65 }, { 0x28bc8c, 0x65, 0x42 }, { 0x28bc8d, 0x74, 0x65 }, { 0x28bc8e, 0x44, 0x67 }, { 0x28bc8f, 0x65, 0x69 }, { 0x28bc90, 0x76, 0x6e }, { 0x28bc91, 0x43, 0x50 }, { 0x28bc92, 0x61, 0x65 }, { 0x28bc93, 0x70, 0x72 }, { 0x28bc94, 0x73, 0x69 }, { 0x28bc95, 0x57, 0x6f }, { 0x28bc96, 0x0, 0x64 }, {-1,0,0} }; Patch schedpatch_81_141[] = { {0x279f23, 0xb8, 0x6a}, {0x279f24, 0x20, 0x01}, {0x279f25, 0xb1, 0xe8}, {0x279f26, 0x67, 0xe2}, {0x279f27, 0x00, 0x22}, {0x279f28, 0xe8, 0xe9}, {0x279f29, 0xd7, 0xff}, {0x279f2a, 0x67, 0x90}, {0x279f2b, 0xee, 0x90}, {0x279f2c, 0xff, 0x90}, {0x28be88, 0x6a, 0x74}, {0x28be89, 0x6f, 0x69}, {0x28be8a, 0x79, 0x6d}, {0x28be8b, 0x47, 0x65}, {0x28be8c, 0x65, 0x42}, {0x28be8d, 0x74, 0x65}, {0x28be8e, 0x44, 0x67}, {0x28be8f, 0x65, 0x69}, {0x28be90, 0x76, 0x6e}, {0x28be91, 0x43, 0x50}, {0x28be92, 0x61, 0x65}, {0x28be93, 0x70, 0x72}, {0x28be94, 0x73, 0x69}, {0x28be95, 0x57, 0x6f}, {0x28be96, 0x00, 0x64}, {-1,0,0} };
the_stack_data/122015343.c
#include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include <netinet/in.h> #include <arpa/inet.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #include <fcntl.h> #include <sys/shm.h> #include <sys/time.h> int sockinit(short port) { int sock = socket(AF_INET,SOCK_STREAM, 0); struct sockaddr_in servaddr; memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(port); servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); if (connect(sock, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) { perror("connect"); exit(1); } return sock; } void sockclose(int s){ close(s); } void socksend(int s,void *dataa,int siz){ send(s,dataa,siz,0); } long int timem(){ struct timeval t; gettimeofday(&t, NULL); return t.tv_sec*1000+t.tv_usec/1000; } int udpinit(short port){ int sock = socket(AF_INET,SOCK_DGRAM, 0); struct sockaddr_in servaddr; memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(port); servaddr.sin_addr.s_addr = INADDR_ANY; if (bind(sock, (struct sockaddr *)&servaddr, sizeof(servaddr))<0){ perror("connect"); exit(1); } return sock; } int udprecv(int s,void *dataa,int siz){ struct sockaddr from; return recvfrom(s, dataa, siz, 0,&from,0); } double llhr[3]={39.68,139,76}; void threadrecv(){ printf("listing\n"); short p=5678; int s=udpinit(p); while(1){ udprecv(s,llhr,3*sizeof(double)); //printf("%lf%lf%lf\n",llhr[0],llhr[1],llhr[2]); } }