file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/110051.c
#include <string.h> /****************************************************************** A basic library for C operations involving the Heathen Webserver Copyright 2018 Connor Berry 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. **************************************************************************/ struct post_dict{ char* index; char* value; }; /* * sift_args takes the normal array of args and sifts them into a dictionary * based on form of 'index':'value' * post_dict buffer = receiving buffer * argc = the argument count brought into the program originally * args[] = the arguments originally passed to the program * On error, returns nonzero value. The optional arguments (separate from the * program identifier) must be evenly divisible by two. */ int sift_args( struct post_dict buffer[], int argc, char* args[] ){ int post_argc = argc-1; if ( post_argc % 2 == 0 ){ for ( int i = 1, j = 0; i < argc; i+=2, j++ ){ struct post_dict item = { args[i], args[i+1] }; buffer[j] = item; } return 0; } return 1; } /* * Returns index in post_dict haystack of 'needle' identifier * returns -1 if no needle in haystack */ int indexof( struct post_dict haystack[], int haystackc, char* needle ){ for ( int i = 0; i < haystackc; i++ ){ if ( !strcmp( haystack[i].index, needle ) ){ return i; } } return -1; }
the_stack_data/137717.c
// Biblioteca #include <stdio.h> //Funcao principal int main(int argc, char const *argv[]) { // Escreve na tela puts("Hola mundo"); return 0; }
the_stack_data/498708.c
#define _GNU_SOURCE #include <errno.h> #include <sched.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/mman.h> #include <sys/wait.h> #include <unistd.h> #define STACK_SIZE (1024 * 1024) /* Stack size for cloned child */ struct clone_args { char **argv; }; // child_exec is the func that will be executed as the result of clone static int child_exec(void *stuff) { struct clone_args *args = (struct clone_args *)stuff; if (execvp(args->argv[0], args->argv) != 0) { fprintf(stderr, "failed to execvp argments %s\n", strerror(errno)); exit(-1); } // we should never reach here! exit(EXIT_FAILURE); } int main(int argc, char **argv) { struct clone_args args; args.argv = &argv[1]; int clone_flags = CLONE_NEWUSER | SIGCHLD; // allocate stack for child char *stack; /* Start of stack buffer */ char *child_stack; /* End of stack buffer */ stack = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON | MAP_STACK, -1, 0); if (stack == MAP_FAILED) { fprintf(stderr, "mmap failed: %s\n", strerror(errno)); exit(EXIT_FAILURE); } child_stack = stack + STACK_SIZE; /* Assume stack grows downward */ // the result of this call is that our child_exec will be run in another // process returning its pid pid_t pid = clone(child_exec, child_stack, clone_flags, &args); if (pid < 0) { fprintf(stderr, "clone failed: %s\n", strerror(errno)); exit(EXIT_FAILURE); } // lets wait on our child process here before we, the parent, exits if (waitpid(pid, NULL, 0) == -1) { fprintf(stderr, "failed to wait pid %d\n", pid); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); }
the_stack_data/19668.c
#include <stdio.h> #ifdef __cplusplus extern "C" { #endif int helloNativeLibrary(int number, const char *cstr) { printf("from C: helloNativeLibrary(%d, \"%s\")\n", number, cstr); return 456; } #ifdef __cplusplus } #endif
the_stack_data/247017019.c
/* $Xorg: ScrOfWin.c,v 1.4 2001/02/09 02:03:53 xorgcvs Exp $ */ /* Copyright 1989, 1998 The Open Group Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation. 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 OPEN GROUP 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. Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from The Open Group. */ /* $XFree86: xc/lib/Xmu/ScrOfWin.c,v 1.6 2001/01/17 19:42:56 dawes Exp $ */ /* * Author: Jim Fulton, MIT X Consortium */ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <stdio.h> #include <X11/Xlib.h> #include <X11/Xmu/WinUtil.h> Screen * XmuScreenOfWindow(Display *dpy, Window w) { register int i; Window root; int x, y; /* dummy variables */ unsigned int width, height, bw, depth; /* dummy variables */ if (!XGetGeometry (dpy, w, &root, &x, &y, &width, &height, &bw, &depth)) { return NULL; } for (i = 0; i < ScreenCount (dpy); i++) { /* find root from list */ if (root == RootWindow (dpy, i)) { return ScreenOfDisplay (dpy, i); } } return NULL; }
the_stack_data/14201106.c
/* */ /* Multiple Master font support (body). */ /* */ /* Copyright 1996-2001, 2003, 2004, 2009 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */
the_stack_data/36075492.c
/* Função: Ler dois valores e informar o dividendo, divisor, quoficiente e o resto dele Autor: Gabriel Maciel dos Santos Data: 11/03/18 */ #include <stdio.h> int main(){ int num1, num2, dividendo, divisor, quoficiente, resto; printf("Digite dois numeros:\n"); scanf("%d %d", &num1, &num2); dividendo = num1; divisor = num2; quoficiente = num1 / num2; resto = num1 % num2; printf("O dividendo: %d\nO divisor: %d\nO quoficiente: %d\nO resto: %d\n", dividendo, divisor, quoficiente, resto); return 0; }
the_stack_data/467302.c
// https://syzkaller.appspot.com/bug?id=bd699d3418ad3b9acb4fbbfb646adb9900395023 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <dirent.h> #include <endian.h> #include <errno.h> #include <fcntl.h> #include <sched.h> #include <signal.h> #include <stdarg.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/time.h> #include <sys/types.h> #include <sys/wait.h> #include <time.h> #include <unistd.h> #include <linux/capability.h> static unsigned long long procid; static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } #define MAX_FDS 30 static void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setsid(); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (200 << 20); setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } static int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static void drop_caps(void) { struct __user_cap_header_struct cap_hdr = {}; struct __user_cap_data_struct cap_data[2] = {}; cap_hdr.version = _LINUX_CAPABILITY_VERSION_3; cap_hdr.pid = getpid(); if (syscall(SYS_capget, &cap_hdr, &cap_data)) exit(1); const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE); cap_data[0].effective &= ~drop; cap_data[0].permitted &= ~drop; cap_data[0].inheritable &= ~drop; if (syscall(SYS_capset, &cap_hdr, &cap_data)) exit(1); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); setup_common(); sandbox_common(); drop_caps(); if (unshare(CLONE_NEWNET)) { } loop(); exit(1); } #define FS_IOC_SETFLAGS _IOW('f', 2, long) static void remove_dir(const char* dir) { int iter = 0; DIR* dp = 0; retry: while (umount2(dir, MNT_DETACH) == 0) { } dp = opendir(dir); if (dp == NULL) { if (errno == EMFILE) { exit(1); } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); while (umount2(filename, MNT_DETACH) == 0) { } struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } int i; for (i = 0;; i++) { if (unlink(filename) == 0) break; if (errno == EPERM) { int fd = open(filename, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno != EBUSY || i > 100) exit(1); if (umount2(filename, MNT_DETACH)) exit(1); } } closedir(dp); for (int i = 0;; i++) { if (rmdir(dir) == 0) break; if (i < 100) { if (errno == EPERM) { int fd = open(dir, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno == EBUSY) { if (umount2(dir, MNT_DETACH)) exit(1); continue; } if (errno == ENOTEMPTY) { if (iter < 100) { iter++; goto retry; } } } exit(1); } } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); for (int i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); write_file("/proc/self/oom_score_adj", "1000"); } static void close_fds() { for (int fd = 3; fd < MAX_FDS; fd++) close(fd); } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); setup_test(); execute_one(); close_fds(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) { continue; } kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0x0}; void execute_one(void) { intptr_t res = 0; res = syscall(__NR_socket, 0x1000000010ul, 0x80002ul, 0); if (res != -1) r[0] = res; res = syscall(__NR_socket, 0x10ul, 0x803ul, 0); if (res != -1) r[1] = res; *(uint64_t*)0x20000280 = 0; *(uint32_t*)0x20000288 = 0; *(uint64_t*)0x20000290 = 0x20000180; *(uint64_t*)0x20000180 = 0; *(uint64_t*)0x20000188 = 0; *(uint64_t*)0x20000298 = 1; *(uint64_t*)0x200002a0 = 0; *(uint64_t*)0x200002a8 = 0; *(uint32_t*)0x200002b0 = 0; syscall(__NR_sendmsg, r[1], 0x20000280ul, 0ul); *(uint32_t*)0x20000200 = 0x14; res = syscall(__NR_getsockname, r[1], 0x20000100ul, 0x20000200ul); if (res != -1) r[2] = *(uint32_t*)0x20000104; *(uint64_t*)0x20000240 = 0; *(uint32_t*)0x20000248 = 0; *(uint64_t*)0x20000250 = 0x20000140; *(uint64_t*)0x20000140 = 0x200003c0; memcpy((void*)0x200003c0, "\x38\x00\x00\x00\x24\x00\xff\xff\xff\x7f\x00\x00\x00\x00\x3c\x00\x05" "\x00\x00\x00", 20); *(uint32_t*)0x200003d4 = r[2]; memcpy((void*)0x200003d8, "\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x09\x00\x01\x00\x68" "\x66\x73\x63\x00\x00\x00\x00\x08\x00\x02", 27); *(uint64_t*)0x20000148 = 0x38; *(uint64_t*)0x20000258 = 1; *(uint64_t*)0x20000260 = 0; *(uint64_t*)0x20000268 = 0; *(uint32_t*)0x20000270 = 0; syscall(__NR_sendmsg, -1, 0x20000240ul, 0ul); *(uint64_t*)0x200002c0 = 0; *(uint32_t*)0x200002c8 = 0; *(uint64_t*)0x200002d0 = 0x20000180; *(uint64_t*)0x20000180 = 0x20000600; *(uint32_t*)0x20000600 = 0x7c; *(uint16_t*)0x20000604 = 0x2c; *(uint16_t*)0x20000606 = 0xd27; *(uint32_t*)0x20000608 = 0; *(uint32_t*)0x2000060c = 0; *(uint8_t*)0x20000610 = 0; *(uint8_t*)0x20000611 = 0; *(uint16_t*)0x20000612 = 0; *(uint32_t*)0x20000614 = r[2]; *(uint16_t*)0x20000618 = 0; *(uint16_t*)0x2000061a = 0; *(uint16_t*)0x2000061c = 0; *(uint16_t*)0x2000061e = 0; *(uint16_t*)0x20000620 = 0xe; *(uint16_t*)0x20000622 = 0xffe0; *(uint16_t*)0x20000624 = 0xc; *(uint16_t*)0x20000626 = 1; memcpy((void*)0x20000628, "tcindex\000", 8); *(uint16_t*)0x20000630 = 0x4c; *(uint16_t*)0x20000632 = 2; *(uint16_t*)0x20000634 = 6; *(uint16_t*)0x20000636 = 2; *(uint16_t*)0x20000638 = 0; *(uint16_t*)0x2000063c = 0x40; *(uint16_t*)0x2000063e = 6; *(uint16_t*)0x20000640 = 0x3c; *(uint16_t*)0x20000642 = 1; *(uint32_t*)0x20000644 = 0; *(uint32_t*)0x20000648 = 0; *(uint32_t*)0x2000064c = 0; *(uint32_t*)0x20000650 = 0; *(uint32_t*)0x20000654 = 0; *(uint8_t*)0x20000658 = 0; *(uint8_t*)0x20000659 = 0; *(uint16_t*)0x2000065a = 0; *(uint16_t*)0x2000065c = 0; *(uint16_t*)0x2000065e = 0; *(uint32_t*)0x20000660 = 0; *(uint8_t*)0x20000664 = 0; *(uint8_t*)0x20000665 = 0; *(uint16_t*)0x20000666 = 0; *(uint16_t*)0x20000668 = 0; *(uint16_t*)0x2000066a = 0; *(uint32_t*)0x2000066c = 0; *(uint32_t*)0x20000670 = 0; *(uint32_t*)0x20000674 = 0; *(uint32_t*)0x20000678 = 0; *(uint64_t*)0x20000188 = 0x7c; *(uint64_t*)0x200002d8 = 1; *(uint64_t*)0x200002e0 = 0; *(uint64_t*)0x200002e8 = 0; *(uint32_t*)0x200002f0 = 0; syscall(__NR_sendmsg, -1, 0x200002c0ul, 0ul); syscall(__NR_sendmmsg, r[0], 0x20000200ul, 0x10efe10675dec16ul, 0ul); memcpy((void*)0x20000000, "./file0\000", 8); syscall(__NR_mkdir, 0x20000000ul, 0ul); memcpy((void*)0x20000040, "./file0\000", 8); syscall(__NR_mount, 0x20000000ul, 0x20000040ul, 0ul, 0x1009ul, 0ul); memcpy((void*)0x20000080, "./file0\000", 8); memcpy((void*)0x20000140, "./file0\000", 8); syscall(__NR_pivot_root, 0x20000080ul, 0x20000140ul); } int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; }
the_stack_data/1157602.c
#include <stdio.h> int main() { double euros = 0.92, dollars; printf("Enter the dollar amount: "); scanf("%lf", &dollars); euros = dollars * euros; printf("%lf dollars are %lf euros.\n", dollars, euros); return 0; }
the_stack_data/7951717.c
extern const unsigned char MXPagerViewVersionString[]; extern const double MXPagerViewVersionNumber; const unsigned char MXPagerViewVersionString[] __attribute__ ((used)) = "@(#)PROGRAM:MXPagerView PROJECT:Pods-1" "\n"; const double MXPagerViewVersionNumber __attribute__ ((used)) = (double)1.;
the_stack_data/709663.c
#include <sys/stat.h> #include <fcntl.h> #include "syscall.h" int chmod(const char *path, mode_t mode) { #ifdef SYS_chmod return syscall(SYS_chmod, path, mode); #else return syscall(SYS_fchmodat, AT_FDCWD, path, mode); #endif }
the_stack_data/22012960.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <pthread.h> pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t condition_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t condition_cond = PTHREAD_COND_INITIALIZER; void *print_num_1(void); void *print_num_2(void); int count = 1; int main(int argc, char **argv) { pthread_t thread_1, thread_2; int iret_1, iret_2; iret_1 = pthread_create(&thread_1, NULL, print_num_1, NULL); iret_2 = pthread_create(&thread_2, NULL, print_num_2, NULL); pthread_join(thread_1, NULL); pthread_join(thread_2, NULL); return EXIT_SUCCESS; } void *print_num_1(void) { for(;;) { pthread_mutex_lock(&condition_mutex); pthread_cond_wait(&condition_cond, &condition_mutex); pthread_mutex_unlock(&condition_mutex); pthread_mutex_lock(&count_mutex); printf("%d\n",count); count++; pthread_mutex_unlock(&count_mutex); if(count >= 1000) return(NULL); } } void *print_num_2(void) { for(;;) { pthread_mutex_lock(&condition_mutex); pthread_cond_signal(&condition_cond); pthread_mutex_unlock(&condition_mutex); pthread_mutex_lock(&count_mutex); printf("%d\n",count); count++; pthread_mutex_unlock(&count_mutex); if(count >= 1000) return(NULL); } }
the_stack_data/190767207.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, Z. Vasicek, L. Sekanina, H. Jiang and J. Han, "Scalable Construction of Approximate Multipliers With Formally Guaranteed Worst Case Error" in IEEE Transactions on Very Large Scale Integration (VLSI) Systems, vol. 26, no. 11, pp. 2572-2576, Nov. 2018. doi: 10.1109/TVLSI.2018.2856362 * This file contains a circuit from a sub-set of pareto optimal circuits with respect to the pwr and mae parameters ***/ // MAE% = 0.00 % // MAE = 0 // WCE% = 0.00 % // WCE = 0 // WCRE% = 0.00 % // EP% = 0.00 % // MRE% = 0.00 % // MSE = 0 // PDK45_PWR = 2.202 mW // PDK45_AREA = 3203.0 um2 // PDK45_DELAY = 3.11 ns #include <stdint.h> #include <stdlib.h> uint16_t trun8_tam00b(uint8_t A, uint8_t B) { uint16_t P, P_; uint8_t tmp, C_1_0,C_1_1,C_1_2,C_1_3,C_1_4,C_1_5,C_1_6,C_2_0,C_2_1,C_2_2,C_2_3,C_2_4,C_2_5,C_2_6,C_3_0,C_3_1,C_3_2,C_3_3,C_3_4,C_3_5,C_3_6,C_4_0,C_4_1,C_4_2,C_4_3,C_4_4,C_4_5,C_4_6,C_5_0,C_5_1,C_5_2,C_5_3,C_5_4,C_5_5,C_5_6,C_6_0,C_6_1,C_6_2,C_6_3,C_6_4,C_6_5,C_6_6,C_7_0,C_7_1,C_7_2,C_7_3,C_7_4,C_7_5,C_7_6,S_0_0,S_0_1,S_0_2,S_0_3,S_0_4,S_0_5,S_0_6,S_0_7,S_1_0,S_1_1,S_1_2,S_1_3,S_1_4,S_1_5,S_1_6,S_1_7,S_2_0,S_2_1,S_2_2,S_2_3,S_2_4,S_2_5,S_2_6,S_2_7,S_3_0,S_3_1,S_3_2,S_3_3,S_3_4,S_3_5,S_3_6,S_3_7,S_4_0,S_4_1,S_4_2,S_4_3,S_4_4,S_4_5,S_4_6,S_4_7,S_5_0,S_5_1,S_5_2,S_5_3,S_5_4,S_5_5,S_5_6,S_5_7,S_6_0,S_6_1,S_6_2,S_6_3,S_6_4,S_6_5,S_6_6,S_6_7,S_7_0,S_7_1,S_7_2,S_7_3,S_7_4,S_7_5,S_7_6,S_7_7,S_8_0,S_8_1,S_8_2,S_8_3,S_8_4,S_8_5,S_8_6,S_8_7; S_0_0 = (((A>>0)&1) & ((B>>0)&1)); S_0_1 = (((A>>0)&1) & ((B>>1)&1)); S_0_2 = (((A>>0)&1) & ((B>>2)&1)); S_0_3 = (((A>>0)&1) & ((B>>3)&1)); S_0_4 = (((A>>0)&1) & ((B>>4)&1)); S_0_5 = (((A>>0)&1) & ((B>>5)&1)); S_0_6 = (((A>>0)&1) & ((B>>6)&1)); S_0_7 = (((A>>0)&1) & ((B>>7)&1)); S_1_0 = S_0_1^(((A>>1)&1) & ((B>>0)&1)); C_1_0 = S_0_1&(((A>>1)&1) & ((B>>0)&1)); S_1_1 = S_0_2^(((A>>1)&1) & ((B>>1)&1)); C_1_1 = S_0_2&(((A>>1)&1) & ((B>>1)&1)); S_1_2 = S_0_3^(((A>>1)&1) & ((B>>2)&1)); C_1_2 = S_0_3&(((A>>1)&1) & ((B>>2)&1)); S_1_3 = S_0_4^(((A>>1)&1) & ((B>>3)&1)); C_1_3 = S_0_4&(((A>>1)&1) & ((B>>3)&1)); S_1_4 = S_0_5^(((A>>1)&1) & ((B>>4)&1)); C_1_4 = S_0_5&(((A>>1)&1) & ((B>>4)&1)); S_1_5 = S_0_6^(((A>>1)&1) & ((B>>5)&1)); C_1_5 = S_0_6&(((A>>1)&1) & ((B>>5)&1)); S_1_6 = S_0_7^(((A>>1)&1) & ((B>>6)&1)); C_1_6 = S_0_7&(((A>>1)&1) & ((B>>6)&1)); S_1_7 = (((A>>1)&1) & ((B>>7)&1)); tmp = S_1_1^C_1_0; S_2_0 = tmp^(((A>>2)&1) & ((B>>0)&1)); C_2_0 = (tmp&(((A>>2)&1) & ((B>>0)&1)))|(S_1_1&C_1_0); tmp = S_1_2^C_1_1; S_2_1 = tmp^(((A>>2)&1) & ((B>>1)&1)); C_2_1 = (tmp&(((A>>2)&1) & ((B>>1)&1)))|(S_1_2&C_1_1); tmp = S_1_3^C_1_2; S_2_2 = tmp^(((A>>2)&1) & ((B>>2)&1)); C_2_2 = (tmp&(((A>>2)&1) & ((B>>2)&1)))|(S_1_3&C_1_2); tmp = S_1_4^C_1_3; S_2_3 = tmp^(((A>>2)&1) & ((B>>3)&1)); C_2_3 = (tmp&(((A>>2)&1) & ((B>>3)&1)))|(S_1_4&C_1_3); tmp = S_1_5^C_1_4; S_2_4 = tmp^(((A>>2)&1) & ((B>>4)&1)); C_2_4 = (tmp&(((A>>2)&1) & ((B>>4)&1)))|(S_1_5&C_1_4); tmp = S_1_6^C_1_5; S_2_5 = tmp^(((A>>2)&1) & ((B>>5)&1)); C_2_5 = (tmp&(((A>>2)&1) & ((B>>5)&1)))|(S_1_6&C_1_5); tmp = S_1_7^C_1_6; S_2_6 = tmp^(((A>>2)&1) & ((B>>6)&1)); C_2_6 = (tmp&(((A>>2)&1) & ((B>>6)&1)))|(S_1_7&C_1_6); S_2_7 = (((A>>2)&1) & ((B>>7)&1)); tmp = S_2_1^C_2_0; S_3_0 = tmp^(((A>>3)&1) & ((B>>0)&1)); C_3_0 = (tmp&(((A>>3)&1) & ((B>>0)&1)))|(S_2_1&C_2_0); tmp = S_2_2^C_2_1; S_3_1 = tmp^(((A>>3)&1) & ((B>>1)&1)); C_3_1 = (tmp&(((A>>3)&1) & ((B>>1)&1)))|(S_2_2&C_2_1); tmp = S_2_3^C_2_2; S_3_2 = tmp^(((A>>3)&1) & ((B>>2)&1)); C_3_2 = (tmp&(((A>>3)&1) & ((B>>2)&1)))|(S_2_3&C_2_2); tmp = S_2_4^C_2_3; S_3_3 = tmp^(((A>>3)&1) & ((B>>3)&1)); C_3_3 = (tmp&(((A>>3)&1) & ((B>>3)&1)))|(S_2_4&C_2_3); tmp = S_2_5^C_2_4; S_3_4 = tmp^(((A>>3)&1) & ((B>>4)&1)); C_3_4 = (tmp&(((A>>3)&1) & ((B>>4)&1)))|(S_2_5&C_2_4); tmp = S_2_6^C_2_5; S_3_5 = tmp^(((A>>3)&1) & ((B>>5)&1)); C_3_5 = (tmp&(((A>>3)&1) & ((B>>5)&1)))|(S_2_6&C_2_5); tmp = S_2_7^C_2_6; S_3_6 = tmp^(((A>>3)&1) & ((B>>6)&1)); C_3_6 = (tmp&(((A>>3)&1) & ((B>>6)&1)))|(S_2_7&C_2_6); S_3_7 = (((A>>3)&1) & ((B>>7)&1)); tmp = S_3_1^C_3_0; S_4_0 = tmp^(((A>>4)&1) & ((B>>0)&1)); C_4_0 = (tmp&(((A>>4)&1) & ((B>>0)&1)))|(S_3_1&C_3_0); tmp = S_3_2^C_3_1; S_4_1 = tmp^(((A>>4)&1) & ((B>>1)&1)); C_4_1 = (tmp&(((A>>4)&1) & ((B>>1)&1)))|(S_3_2&C_3_1); tmp = S_3_3^C_3_2; S_4_2 = tmp^(((A>>4)&1) & ((B>>2)&1)); C_4_2 = (tmp&(((A>>4)&1) & ((B>>2)&1)))|(S_3_3&C_3_2); tmp = S_3_4^C_3_3; S_4_3 = tmp^(((A>>4)&1) & ((B>>3)&1)); C_4_3 = (tmp&(((A>>4)&1) & ((B>>3)&1)))|(S_3_4&C_3_3); tmp = S_3_5^C_3_4; S_4_4 = tmp^(((A>>4)&1) & ((B>>4)&1)); C_4_4 = (tmp&(((A>>4)&1) & ((B>>4)&1)))|(S_3_5&C_3_4); tmp = S_3_6^C_3_5; S_4_5 = tmp^(((A>>4)&1) & ((B>>5)&1)); C_4_5 = (tmp&(((A>>4)&1) & ((B>>5)&1)))|(S_3_6&C_3_5); tmp = S_3_7^C_3_6; S_4_6 = tmp^(((A>>4)&1) & ((B>>6)&1)); C_4_6 = (tmp&(((A>>4)&1) & ((B>>6)&1)))|(S_3_7&C_3_6); S_4_7 = (((A>>4)&1) & ((B>>7)&1)); tmp = S_4_1^C_4_0; S_5_0 = tmp^(((A>>5)&1) & ((B>>0)&1)); C_5_0 = (tmp&(((A>>5)&1) & ((B>>0)&1)))|(S_4_1&C_4_0); tmp = S_4_2^C_4_1; S_5_1 = tmp^(((A>>5)&1) & ((B>>1)&1)); C_5_1 = (tmp&(((A>>5)&1) & ((B>>1)&1)))|(S_4_2&C_4_1); tmp = S_4_3^C_4_2; S_5_2 = tmp^(((A>>5)&1) & ((B>>2)&1)); C_5_2 = (tmp&(((A>>5)&1) & ((B>>2)&1)))|(S_4_3&C_4_2); tmp = S_4_4^C_4_3; S_5_3 = tmp^(((A>>5)&1) & ((B>>3)&1)); C_5_3 = (tmp&(((A>>5)&1) & ((B>>3)&1)))|(S_4_4&C_4_3); tmp = S_4_5^C_4_4; S_5_4 = tmp^(((A>>5)&1) & ((B>>4)&1)); C_5_4 = (tmp&(((A>>5)&1) & ((B>>4)&1)))|(S_4_5&C_4_4); tmp = S_4_6^C_4_5; S_5_5 = tmp^(((A>>5)&1) & ((B>>5)&1)); C_5_5 = (tmp&(((A>>5)&1) & ((B>>5)&1)))|(S_4_6&C_4_5); tmp = S_4_7^C_4_6; S_5_6 = tmp^(((A>>5)&1) & ((B>>6)&1)); C_5_6 = (tmp&(((A>>5)&1) & ((B>>6)&1)))|(S_4_7&C_4_6); S_5_7 = (((A>>5)&1) & ((B>>7)&1)); tmp = S_5_1^C_5_0; S_6_0 = tmp^(((A>>6)&1) & ((B>>0)&1)); C_6_0 = (tmp&(((A>>6)&1) & ((B>>0)&1)))|(S_5_1&C_5_0); tmp = S_5_2^C_5_1; S_6_1 = tmp^(((A>>6)&1) & ((B>>1)&1)); C_6_1 = (tmp&(((A>>6)&1) & ((B>>1)&1)))|(S_5_2&C_5_1); tmp = S_5_3^C_5_2; S_6_2 = tmp^(((A>>6)&1) & ((B>>2)&1)); C_6_2 = (tmp&(((A>>6)&1) & ((B>>2)&1)))|(S_5_3&C_5_2); tmp = S_5_4^C_5_3; S_6_3 = tmp^(((A>>6)&1) & ((B>>3)&1)); C_6_3 = (tmp&(((A>>6)&1) & ((B>>3)&1)))|(S_5_4&C_5_3); tmp = S_5_5^C_5_4; S_6_4 = tmp^(((A>>6)&1) & ((B>>4)&1)); C_6_4 = (tmp&(((A>>6)&1) & ((B>>4)&1)))|(S_5_5&C_5_4); tmp = S_5_6^C_5_5; S_6_5 = tmp^(((A>>6)&1) & ((B>>5)&1)); C_6_5 = (tmp&(((A>>6)&1) & ((B>>5)&1)))|(S_5_6&C_5_5); tmp = S_5_7^C_5_6; S_6_6 = tmp^(((A>>6)&1) & ((B>>6)&1)); C_6_6 = (tmp&(((A>>6)&1) & ((B>>6)&1)))|(S_5_7&C_5_6); S_6_7 = (((A>>6)&1) & ((B>>7)&1)); tmp = S_6_1^C_6_0; S_7_0 = tmp^(((A>>7)&1) & ((B>>0)&1)); C_7_0 = (tmp&(((A>>7)&1) & ((B>>0)&1)))|(S_6_1&C_6_0); tmp = S_6_2^C_6_1; S_7_1 = tmp^(((A>>7)&1) & ((B>>1)&1)); C_7_1 = (tmp&(((A>>7)&1) & ((B>>1)&1)))|(S_6_2&C_6_1); tmp = S_6_3^C_6_2; S_7_2 = tmp^(((A>>7)&1) & ((B>>2)&1)); C_7_2 = (tmp&(((A>>7)&1) & ((B>>2)&1)))|(S_6_3&C_6_2); tmp = S_6_4^C_6_3; S_7_3 = tmp^(((A>>7)&1) & ((B>>3)&1)); C_7_3 = (tmp&(((A>>7)&1) & ((B>>3)&1)))|(S_6_4&C_6_3); tmp = S_6_5^C_6_4; S_7_4 = tmp^(((A>>7)&1) & ((B>>4)&1)); C_7_4 = (tmp&(((A>>7)&1) & ((B>>4)&1)))|(S_6_5&C_6_4); tmp = S_6_6^C_6_5; S_7_5 = tmp^(((A>>7)&1) & ((B>>5)&1)); C_7_5 = (tmp&(((A>>7)&1) & ((B>>5)&1)))|(S_6_6&C_6_5); tmp = S_6_7^C_6_6; S_7_6 = tmp^(((A>>7)&1) & ((B>>6)&1)); C_7_6 = (tmp&(((A>>7)&1) & ((B>>6)&1)))|(S_6_7&C_6_6); S_7_7 = (((A>>7)&1) & ((B>>7)&1)); P_ = (((C_7_0 & 1)<<0)|((C_7_1 & 1)<<1)|((C_7_2 & 1)<<2)|((C_7_3 & 1)<<3)|((C_7_4 & 1)<<4)|((C_7_5 & 1)<<5)|((C_7_6 & 1)<<6)) + (((S_7_1 & 1)<<0)|((S_7_2 & 1)<<1)|((S_7_3 & 1)<<2)|((S_7_4 & 1)<<3)|((S_7_5 & 1)<<4)|((S_7_6 & 1)<<5)|((S_7_7 & 1)<<6)); S_8_0 = (P_ >> 0) & 1; S_8_1 = (P_ >> 1) & 1; S_8_2 = (P_ >> 2) & 1; S_8_3 = (P_ >> 3) & 1; S_8_4 = (P_ >> 4) & 1; S_8_5 = (P_ >> 5) & 1; S_8_6 = (P_ >> 6) & 1; S_8_7 = (P_ >> 7) & 1; P = 0; P |= (S_0_0 & 1) << 0; P |= (S_1_0 & 1) << 1; P |= (S_2_0 & 1) << 2; P |= (S_3_0 & 1) << 3; P |= (S_4_0 & 1) << 4; P |= (S_5_0 & 1) << 5; P |= (S_6_0 & 1) << 6; P |= (S_7_0 & 1) << 7; P |= (S_8_0 & 1) << 8; P |= (S_8_1 & 1) << 9; P |= (S_8_2 & 1) << 10; P |= (S_8_3 & 1) << 11; P |= (S_8_4 & 1) << 12; P |= (S_8_5 & 1) << 13; P |= (S_8_6 & 1) << 14; P |= (S_8_7 & 1) << 15; return P; } uint16_t mul8_364(uint8_t a, uint8_t b) { uint16_t c = 0; uint8_t n0 = (a >> 0) & 0x1; uint8_t n2 = (a >> 1) & 0x1; uint8_t n4 = (a >> 2) & 0x1; uint8_t n6 = (a >> 3) & 0x1; uint8_t n8 = (a >> 4) & 0x1; uint8_t n10 = (a >> 5) & 0x1; uint8_t n12 = (a >> 6) & 0x1; uint8_t n14 = (a >> 7) & 0x1; uint8_t n16 = (b >> 0) & 0x1; uint8_t n18 = (b >> 1) & 0x1; uint8_t n20 = (b >> 2) & 0x1; uint8_t n22 = (b >> 3) & 0x1; uint8_t n24 = (b >> 4) & 0x1; uint8_t n26 = (b >> 5) & 0x1; uint8_t n28 = (b >> 6) & 0x1; uint8_t n30 = (b >> 7) & 0x1; uint8_t n32; uint8_t n48; uint8_t n64; uint8_t n82; uint8_t n98; uint8_t n114; uint8_t n132; uint8_t n149; uint8_t n164; uint8_t n167; uint8_t n182; uint8_t n198; uint8_t n214; uint8_t n232; uint8_t n248; uint8_t n264; uint8_t n282; uint8_t n298; uint8_t n299; uint8_t n314; uint8_t n315; uint8_t n332; uint8_t n333; uint8_t n348; uint8_t n349; uint8_t n364; uint8_t n365; uint8_t n382; uint8_t n383; uint8_t n398; uint8_t n399; uint8_t n414; uint8_t n432; uint8_t n448; uint8_t n464; uint8_t n482; uint8_t n498; uint8_t n514; uint8_t n532; uint8_t n548; uint8_t n549; uint8_t n564; uint8_t n565; uint8_t n582; uint8_t n583; uint8_t n598; uint8_t n599; uint8_t n614; uint8_t n615; uint8_t n632; uint8_t n633; uint8_t n648; uint8_t n649; uint8_t n664; uint8_t n682; uint8_t n698; uint8_t n714; uint8_t n732; uint8_t n748; uint8_t n764; uint8_t n782; uint8_t n798; uint8_t n799; uint8_t n814; uint8_t n815; uint8_t n832; uint8_t n833; uint8_t n848; uint8_t n849; uint8_t n864; uint8_t n865; uint8_t n882; uint8_t n883; uint8_t n898; uint8_t n899; uint8_t n914; uint8_t n932; uint8_t n948; uint8_t n964; uint8_t n982; uint8_t n998; uint8_t n1014; uint8_t n1032; uint8_t n1048; uint8_t n1049; uint8_t n1064; uint8_t n1065; uint8_t n1082; uint8_t n1083; uint8_t n1098; uint8_t n1099; uint8_t n1114; uint8_t n1115; uint8_t n1132; uint8_t n1133; uint8_t n1148; uint8_t n1149; uint8_t n1164; uint8_t n1182; uint8_t n1198; uint8_t n1214; uint8_t n1232; uint8_t n1248; uint8_t n1264; uint8_t n1282; uint8_t n1298; uint8_t n1299; uint8_t n1314; uint8_t n1315; uint8_t n1332; uint8_t n1333; uint8_t n1348; uint8_t n1349; uint8_t n1364; uint8_t n1365; uint8_t n1382; uint8_t n1383; uint8_t n1398; uint8_t n1399; uint8_t n1414; uint8_t n1432; uint8_t n1448; uint8_t n1464; uint8_t n1482; uint8_t n1498; uint8_t n1514; uint8_t n1532; uint8_t n1548; uint8_t n1549; uint8_t n1564; uint8_t n1565; uint8_t n1582; uint8_t n1583; uint8_t n1598; uint8_t n1599; uint8_t n1614; uint8_t n1615; uint8_t n1632; uint8_t n1633; uint8_t n1648; uint8_t n1649; uint8_t n1664; uint8_t n1682; uint8_t n1698; uint8_t n1714; uint8_t n1732; uint8_t n1748; uint8_t n1764; uint8_t n1782; uint8_t n1798; uint8_t n1799; uint8_t n1814; uint8_t n1815; uint8_t n1832; uint8_t n1833; uint8_t n1848; uint8_t n1849; uint8_t n1864; uint8_t n1865; uint8_t n1882; uint8_t n1883; uint8_t n1898; uint8_t n1899; uint8_t n1914; uint8_t n1915; uint8_t n1932; uint8_t n1933; uint8_t n1948; uint8_t n1949; uint8_t n1964; uint8_t n1965; uint8_t n1982; uint8_t n1983; uint8_t n1998; uint8_t n1999; uint8_t n2014; uint8_t n2015; n32 = n0 & n16; n48 = n2 & n16; n64 = n4 & n16; n82 = n6 & n16; n98 = n8 & n16; n114 = n10 & n16; n132 = n12 & n16; n149 = n14 & n16; n164 = n0 & n18; n167 = n149; n182 = n2 & n18; n198 = n4 & n18; n214 = n6 & n18; n232 = n8 & n18; n248 = n10 & n18; n264 = n12 & n18; n282 = n14 & n18; n298 = n48 ^ n164; n299 = n48 & n164; n314 = n64 ^ n182; n315 = n64 & n182; n332 = n82 ^ n198; n333 = n82 & n198; n348 = n98 ^ n214; n349 = n98 & n214; n364 = n114 ^ n232; n365 = n114 & n232; n382 = n132 ^ n248; n383 = n132 & n248; n398 = n167 ^ n264; n399 = n167 & n264; n414 = n0 & n20; n432 = n2 & n20; n448 = n4 & n20; n464 = n6 & n20; n482 = n8 & n20; n498 = n10 & n20; n514 = n12 & n20; n532 = n14 & n20; n548 = (n314 ^ n414) ^ n299; n549 = (n314 & n414) | (n414 & n299) | (n314 & n299); n564 = (n332 ^ n432) ^ n315; n565 = (n332 & n432) | (n432 & n315) | (n332 & n315); n582 = (n348 ^ n448) ^ n333; n583 = (n348 & n448) | (n448 & n333) | (n348 & n333); n598 = (n364 ^ n464) ^ n349; n599 = (n364 & n464) | (n464 & n349) | (n364 & n349); n614 = (n382 ^ n482) ^ n365; n615 = (n382 & n482) | (n482 & n365) | (n382 & n365); n632 = (n398 ^ n498) ^ n383; n633 = (n398 & n498) | (n498 & n383) | (n398 & n383); n648 = (n282 ^ n514) ^ n399; n649 = (n282 & n514) | (n514 & n399) | (n282 & n399); n664 = n0 & n22; n682 = n2 & n22; n698 = n4 & n22; n714 = n6 & n22; n732 = n8 & n22; n748 = n10 & n22; n764 = n12 & n22; n782 = n14 & n22; n798 = (n564 ^ n664) ^ n549; n799 = (n564 & n664) | (n664 & n549) | (n564 & n549); n814 = (n582 ^ n682) ^ n565; n815 = (n582 & n682) | (n682 & n565) | (n582 & n565); n832 = (n598 ^ n698) ^ n583; n833 = (n598 & n698) | (n698 & n583) | (n598 & n583); n848 = (n614 ^ n714) ^ n599; n849 = (n614 & n714) | (n714 & n599) | (n614 & n599); n864 = (n632 ^ n732) ^ n615; n865 = (n632 & n732) | (n732 & n615) | (n632 & n615); n882 = (n648 ^ n748) ^ n633; n883 = (n648 & n748) | (n748 & n633) | (n648 & n633); n898 = (n532 ^ n764) ^ n649; n899 = (n532 & n764) | (n764 & n649) | (n532 & n649); n914 = n0 & n24; n932 = n2 & n24; n948 = n4 & n24; n964 = n6 & n24; n982 = n8 & n24; n998 = n10 & n24; n1014 = n12 & n24; n1032 = n14 & n24; n1048 = (n814 ^ n914) ^ n799; n1049 = (n814 & n914) | (n914 & n799) | (n814 & n799); n1064 = (n832 ^ n932) ^ n815; n1065 = (n832 & n932) | (n932 & n815) | (n832 & n815); n1082 = (n848 ^ n948) ^ n833; n1083 = (n848 & n948) | (n948 & n833) | (n848 & n833); n1098 = (n864 ^ n964) ^ n849; n1099 = (n864 & n964) | (n964 & n849) | (n864 & n849); n1114 = (n882 ^ n982) ^ n865; n1115 = (n882 & n982) | (n982 & n865) | (n882 & n865); n1132 = (n898 ^ n998) ^ n883; n1133 = (n898 & n998) | (n998 & n883) | (n898 & n883); n1148 = (n782 ^ n1014) ^ n899; n1149 = (n782 & n1014) | (n1014 & n899) | (n782 & n899); n1164 = n0 & n26; n1182 = n2 & n26; n1198 = n4 & n26; n1214 = n6 & n26; n1232 = n8 & n26; n1248 = n10 & n26; n1264 = n12 & n26; n1282 = n14 & n26; n1298 = (n1064 ^ n1164) ^ n1049; n1299 = (n1064 & n1164) | (n1164 & n1049) | (n1064 & n1049); n1314 = (n1082 ^ n1182) ^ n1065; n1315 = (n1082 & n1182) | (n1182 & n1065) | (n1082 & n1065); n1332 = (n1098 ^ n1198) ^ n1083; n1333 = (n1098 & n1198) | (n1198 & n1083) | (n1098 & n1083); n1348 = (n1114 ^ n1214) ^ n1099; n1349 = (n1114 & n1214) | (n1214 & n1099) | (n1114 & n1099); n1364 = (n1132 ^ n1232) ^ n1115; n1365 = (n1132 & n1232) | (n1232 & n1115) | (n1132 & n1115); n1382 = (n1148 ^ n1248) ^ n1133; n1383 = (n1148 & n1248) | (n1248 & n1133) | (n1148 & n1133); n1398 = (n1032 ^ n1264) ^ n1149; n1399 = (n1032 & n1264) | (n1264 & n1149) | (n1032 & n1149); n1414 = n0 & n28; n1432 = n2 & n28; n1448 = n4 & n28; n1464 = n6 & n28; n1482 = n8 & n28; n1498 = n10 & n28; n1514 = n12 & n28; n1532 = n14 & n28; n1548 = (n1314 ^ n1414) ^ n1299; n1549 = (n1314 & n1414) | (n1414 & n1299) | (n1314 & n1299); n1564 = (n1332 ^ n1432) ^ n1315; n1565 = (n1332 & n1432) | (n1432 & n1315) | (n1332 & n1315); n1582 = (n1348 ^ n1448) ^ n1333; n1583 = (n1348 & n1448) | (n1448 & n1333) | (n1348 & n1333); n1598 = (n1364 ^ n1464) ^ n1349; n1599 = (n1364 & n1464) | (n1464 & n1349) | (n1364 & n1349); n1614 = (n1382 ^ n1482) ^ n1365; n1615 = (n1382 & n1482) | (n1482 & n1365) | (n1382 & n1365); n1632 = (n1398 ^ n1498) ^ n1383; n1633 = (n1398 & n1498) | (n1498 & n1383) | (n1398 & n1383); n1648 = (n1282 ^ n1514) ^ n1399; n1649 = (n1282 & n1514) | (n1514 & n1399) | (n1282 & n1399); n1664 = n0 & n30; n1682 = n2 & n30; n1698 = n4 & n30; n1714 = n6 & n30; n1732 = n8 & n30; n1748 = n10 & n30; n1764 = n12 & n30; n1782 = n14 & n30; n1798 = (n1564 ^ n1664) ^ n1549; n1799 = (n1564 & n1664) | (n1664 & n1549) | (n1564 & n1549); n1814 = (n1582 ^ n1682) ^ n1565; n1815 = (n1582 & n1682) | (n1682 & n1565) | (n1582 & n1565); n1832 = (n1598 ^ n1698) ^ n1583; n1833 = (n1598 & n1698) | (n1698 & n1583) | (n1598 & n1583); n1848 = (n1614 ^ n1714) ^ n1599; n1849 = (n1614 & n1714) | (n1714 & n1599) | (n1614 & n1599); n1864 = (n1632 ^ n1732) ^ n1615; n1865 = (n1632 & n1732) | (n1732 & n1615) | (n1632 & n1615); n1882 = (n1648 ^ n1748) ^ n1633; n1883 = (n1648 & n1748) | (n1748 & n1633) | (n1648 & n1633); n1898 = (n1532 ^ n1764) ^ n1649; n1899 = (n1532 & n1764) | (n1764 & n1649) | (n1532 & n1649); n1914 = n1814 ^ n1799; n1915 = n1814 & n1799; n1932 = (n1832 ^ n1815) ^ n1915; n1933 = (n1832 & n1815) | (n1815 & n1915) | (n1832 & n1915); n1948 = (n1848 ^ n1833) ^ n1933; n1949 = (n1848 & n1833) | (n1833 & n1933) | (n1848 & n1933); n1964 = (n1864 ^ n1849) ^ n1949; n1965 = (n1864 & n1849) | (n1849 & n1949) | (n1864 & n1949); n1982 = (n1882 ^ n1865) ^ n1965; n1983 = (n1882 & n1865) | (n1865 & n1965) | (n1882 & n1965); n1998 = (n1898 ^ n1883) ^ n1983; n1999 = (n1898 & n1883) | (n1883 & n1983) | (n1898 & n1983); n2014 = (n1782 ^ n1899) ^ n1999; n2015 = (n1782 & n1899) | (n1899 & n1999) | (n1782 & n1999); c |= (n32 & 0x1) << 0; c |= (n298 & 0x1) << 1; c |= (n548 & 0x1) << 2; c |= (n798 & 0x1) << 3; c |= (n1048 & 0x1) << 4; c |= (n1298 & 0x1) << 5; c |= (n1548 & 0x1) << 6; c |= (n1798 & 0x1) << 7; c |= (n1914 & 0x1) << 8; c |= (n1932 & 0x1) << 9; c |= (n1948 & 0x1) << 10; c |= (n1964 & 0x1) << 11; c |= (n1982 & 0x1) << 12; c |= (n1998 & 0x1) << 13; c |= (n2014 & 0x1) << 14; c |= (n2015 & 0x1) << 15; return c; } uint32_t mul16u_BMC (uint16_t a, uint16_t b) { static uint16_t * cacheLL = NULL; static uint16_t * cacheLH = NULL; static uint16_t * cacheHL = NULL; static uint16_t * cacheHH = NULL; int fillData = cacheLL == NULL || cacheLH == NULL || cacheHL == NULL || cacheHH == NULL; if(!cacheLL) cacheLL = (uint16_t *)malloc(256 * 256 * sizeof(uint16_t)); if(!cacheLH) cacheLH = (uint16_t *)malloc(256 * 256 * sizeof(uint16_t)); if(!cacheHL) cacheHL = (uint16_t *)malloc(256 * 256 * sizeof(uint16_t)); if(!cacheHH) cacheHH = (uint16_t *)malloc(256 * 256 * sizeof(uint16_t)); if(fillData) { for(int i = 0; i < 256; i++) { for(int j = 0; j < 256; j++) { cacheLL[i * 256 + j] = mul8_364(i, j); cacheLH[i * 256 + j] = mul8_364(i, j); cacheHL[i * 256 + j] = trun8_tam00b(i, j); cacheHH[i * 256 + j] = mul8_364(i, j); } } } uint32_t opt = 0; opt += (uint32_t)cacheLL[(a & 0xFF ) * 256 + (b & 0xFF )]; opt += (uint32_t)cacheLH[(a & 0xFF ) * 256 + ((b >> 8) & 0xFF )] << 8; opt += (uint32_t)cacheHL[((a >> 8) & 0xFF) * 256 + (b & 0xFF )] << 8; opt += (uint32_t)cacheHH[((a >> 8) & 0xFF) * 256 + ((b >> 8) & 0xFF )] << 16; return opt; }
the_stack_data/1190402.c
#include<stdio.h> void towhan(int n,char x,char y,char z) { if(n>=1) { towhan(n-1,x,z,y); printf("\nMOVE TOP DISK FROM TOWER '%c' TO TOP OF TOWER '%c' \n",x,y); towhan(n-1,z,y,x); } } int main() { int n; printf("ENTER THE NUMBER OF DISKS"); scanf("%d",&n); towhan(n,'A','B','C'); int getch(); return 0; }
the_stack_data/148577104.c
int mx_sum_digits(int num) { int c = 0; if (num < 0) num *= -1; while (num % 10 != 0) { c = c + num % 10; num = num / 10; } return c; }
the_stack_data/21062.c
// SKIP PARAM: --sets solver td3 --enable ana.int.interval --enable exp.partition-arrays.enabled --set ana.activated "['base','threadid','threadflag','expRelation','mallocWrapper','octApron']" // Example from https://www-apr.lip6.fr/~mine/publi/article-mine-HOSC06.pdf void main(void) { int X = 0; int N = rand(); if(N < 0) { N = 0; } while(X < N) { X++; } assert(X-N == 0); assert(X == N); if(X == N) { N = 8; } else { // is dead code but if that is detected or not depends on what we do in branch // currenlty we can't detect this N = 42; } }
the_stack_data/167329937.c
#include <stdio.h> int fibonacci_m(int N, int known_result[]) { if( N>=1 && N<=46 ) //Result for N=47 is too big for int { if( known_result[N]==0 ) { if( N==1 ) known_result[N]=1; else known_result[N] = fibonacci_m(N-1, known_result) + known_result[N-2]; } return known_result[N]; } else { printf("Invalid entry. Please enter 1 to 46.\n"); return 0; } } int main() { int N; int known[50] = {0}; printf("Please enter a number N (1 to 46): "); scanf("%d", &N); printf("Fibonacci(%d) is %d\n", N, fibonacci_m(N, known)); return 0; } /* OUTPUT ------ Please enter a number N (1 to 46): Fibonacci(?) is ? N RESULT ------------ 1 1 2 1 3 2 4 3 5 5 6 8 7 13 8 21 9 34 10 55 and so on */
the_stack_data/1251921.c
#include <unistd.h> extern char **__environ; int execv(const char *path, char *const argv[]) { return execve(path, argv, __environ); }
the_stack_data/242329455.c
/* en este programa se muestra un ejemplo sencillo de la utilizacion de semaforos en forma de mutex donde un hilo sumara 1000 veces 1 a un contador mientras que otro hilo restara 1000 veces 1 al contador al final del programa deberia de mostrar el contador en 0 */ #include <stdio.h> #include <semaphore.h> #include <pthread.h> #define LOOP 1000 static void * thread_1_function(void* arg); static void * thread_2_function(void* arg); static int contador = 0; sem_t sem1; int main (void) { pthread_t thread_1, thread_2; sem_init(&sem1, 0, 1); pthread_create(&thread_1, NULL, *thread_1_function, NULL); pthread_create(&thread_2, NULL, *thread_2_function, NULL); pthread_join(thread_1, NULL); pthread_join(thread_2, NULL); printf("valor contador %d \n", contador); return 0; } static void * thread_1_function(void* arg) { for(int i = 0; i< LOOP; i++) { sem_wait(&sem1); contador += 1; sem_post(&sem1); } } static void * thread_2_function(void* arg) { for(int i = 0; i< LOOP; i++) { sem_wait(&sem1); contador -= 1; sem_post(&sem1); } }
the_stack_data/101283.c
#include <stdio.h> #define TRUE 1 #define FALSE 0 int main() { int n; char buffer[100]; int rip[10]; int scritto = FALSE; // Init array for(int x = 0; x < 10; x++) rip[x] = 0; scanf("%d", &n); sprintf(buffer,"%d", n); for(int x = 0;; x++) { if(buffer[x] == 0) break; rip[buffer[x]-48]++; } for(int x = 0; x < 10; x++) { if(rip[x] > 1) { if(!scritto) printf("Cifre ripetute: "); if(scritto) printf(", "); printf("%d", x); scritto = TRUE; } } if(!scritto) printf("Non ci sono cifre ripetute"); printf("\n"); }
the_stack_data/81836.c
/* * Copyright 1993 Bill Triggs <[email protected]> * Copyright 1995-2017 Bruno Haible <[email protected]> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 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/>. */ /* This file defines test functions of selected signatures, that exercise dark corners of the various ABIs. */ #include <stdio.h> FILE* out; #define uchar unsigned char #define ushort unsigned short #define uint unsigned int #define ulong unsigned long typedef struct { char x; } Char; typedef struct { short x; } Short; typedef struct { int x; } Int; typedef struct { long x; } Long; typedef struct { float x; } Float; typedef struct { double x; } Double; typedef struct { char c; float f; } A; typedef struct { double d; int i[3]; } B; typedef struct { long l1; long l2; } J; typedef struct { long l1; long l2; long l3; long l4; } K; typedef struct { long l1; long l2; long l3; long l4; long l5; long l6; } L; typedef struct { char x1; } Size1; typedef struct { char x1; char x2; } Size2; typedef struct { char x1; char x2; char x3; } Size3; typedef struct { char x1; char x2; char x3; char x4; } Size4; typedef struct { char x1; char x2; char x3; char x4; char x5; char x6; char x7; } Size7; typedef struct { char x1; char x2; char x3; char x4; char x5; char x6; char x7; char x8; } Size8; typedef struct { char x1; char x2; char x3; char x4; char x5; char x6; char x7; char x8; char x9; char x10; char x11; char x12; } Size12; typedef struct { char x1; char x2; char x3; char x4; char x5; char x6; char x7; char x8; char x9; char x10; char x11; char x12; char x13; char x14; char x15; } Size15; typedef struct { char x1; char x2; char x3; char x4; char x5; char x6; char x7; char x8; char x9; char x10; char x11; char x12; char x13; char x14; char x15; char x16; } Size16; typedef struct { char c[3]; } T; typedef struct { char c[33],c1; } X; /* Don't use a number over 127, as some systems use signed chars and the test case 25 doesn't account for this, resulting in undefined behavior. See https://github.com/libffi/libffi/issues/598. */ char c1='a', c2=127, c3=(char)1; short s1=32767, s2=(short)32768, s3=3, s4=4, s5=5, s6=6, s7=7, s8=8, s9=9; int i1=1, i2=2, i3=3, i4=4, i5=5, i6=6, i7=7, i8=8, i9=9, i10=11, i11=12, i12=13, i13=14, i14=15, i15=16, i16=17; long l1=1, l2=2, l3=3, l4=4, l5=5, l6=6, l7=7, l8=8, l9=9; long long ll1 = 3875056143130689530LL; float f1=0.1f, f2=0.2f, f3=0.3f, f4=0.4f, f5=0.5f, f6=0.6f, f7=0.7f, f8=0.8f, f9=0.9f, f10=1.1f, f11=1.2f, f12=1.3f, f13=1.4f, f14=1.5f, f15=1.6f, f16=1.7f, f17=1.8f, f18=1.9f, f19=2.1f, f20=2.2f, f21=2.3f, f22=2.4f, f23=2.5f, f24=2.6f; double d1=0.1, d2=0.2, d3=0.3, d4=0.4, d5=0.5, d6=0.6, d7=0.7, d8=0.8, d9=0.9, d10=1.1, d11=1.2, d12=1.3, d13=1.4, d14=1.5, d15=1.6, d16=1.7, d17=1.8; uchar uc1='a', uc2=127, uc3=128, uc4=255, uc5=(uchar)-1; ushort us1=1, us2=2, us3=3, us4=4, us5=5, us6=6, us7=7, us8=8, us9=9; uint ui1=1, ui2=2, ui3=3, ui4=4, ui5=5, ui6=6, ui7=7, ui8=8, ui9=9; ulong ul1=1, ul2=2, ul3=3, ul4=4, ul5=5, ul6=6, ul7=7, ul8=8, ul9=9; char *str1="hello",str2[]="goodbye",*str3="still here?"; Char C1={'A'}, C2={'B'}, C3={'C'}, C4={'\377'}, C5={(char)(-1)}; Short S1={1}, S2={2}, S3={3}, S4={4}, S5={5}, S6={6}, S7={7}, S8={8}, S9={9}; Int I1={1}, I2={2}, I3={3}, I4={4}, I5={5}, I6={6}, I7={7}, I8={8}, I9={9}; Float F1={0.1f}, F2={0.2f}, F3={0.3f}, F4={0.4f}, F5={0.5f}, F6={0.6f}, F7={0.7f}, F8={0.8f}, F9={0.9f}; Double D1={0.1}, D2={0.2}, D3={0.3}, D4={0.4}, D5={0.5}, D6={0.6}, D7={0.7}, D8={0.8}, D9={0.9}; A A1={'a',0.1f},A2={'b',0.2f},A3={'\377',0.3f}; B B1={0.1,{1,2,3}},B2={0.2,{5,4,3}}; J J1={47,11},J2={73,55}; K K1={19,69,12,28}; L L1={561,1105,1729,2465,2821,6601}; /* A002997 */ Size1 Size1_1={'a'}; Size2 Size2_1={'a','b'}; Size3 Size3_1={'a','b','c'}; Size4 Size4_1={'a','b','c','d'}; Size7 Size7_1={'a','b','c','d','e','f','g'}; Size8 Size8_1={'a','b','c','d','e','f','g','h'}; Size12 Size12_1={'a','b','c','d','e','f','g','h','i','j','k','l'}; Size15 Size15_1={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o'}; Size16 Size16_1={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'}; T T1={{'t','h','e'}},T2={{'f','o','x'}}; X X1={"abcdefghijklmnopqrstuvwxyzABCDEF",'G'}, X2={"123",'9'}, X3={"return-return-return",'R'}; #if defined(__GNUC__) #define __STDCALL__ __attribute__((stdcall)) #define __THISCALL__ __attribute__((thiscall)) #define __FASTCALL__ __attribute__((fastcall)) #define __MSABI__ __attribute__((ms_abi)) #else #define __STDCALL__ __stdcall #define __THISCALL__ __thiscall #define __FASTCALL__ __fastcall #endif #ifndef ABI_ATTR #define ABI_ATTR #endif /* void tests */ void ABI_ATTR v_v (void) { fprintf(out,"void f(void):\n"); fflush(out); } /* int tests */ int ABI_ATTR i_v (void) { int r=99; fprintf(out,"int f(void):"); fflush(out); return r; } int ABI_ATTR i_i (int a) { int r=a+1; fprintf(out,"int f(int):(%d)",a); fflush(out); return r; } int ABI_ATTR i_i2 (int a, int b) { int r=a+b; fprintf(out,"int f(2*int):(%d,%d)",a,b); fflush(out); return r; } int ABI_ATTR i_i4 (int a, int b, int c, int d) { int r=a+b+c+d; fprintf(out,"int f(4*int):(%d,%d,%d,%d)",a,b,c,d); fflush(out); return r; } int ABI_ATTR i_i8 (int a, int b, int c, int d, int e, int f, int g, int h) { int r=a+b+c+d+e+f+g+h; fprintf(out,"int f(8*int):(%d,%d,%d,%d,%d,%d,%d,%d)",a,b,c,d,e,f,g,h); fflush(out); return r; } int ABI_ATTR i_i16 (int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n, int o, int p) { int r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p; fprintf(out,"int f(16*int):(%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)", a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p); fflush(out); return r; } /* float tests */ float ABI_ATTR f_f (float a) { float r=a+1.0f; fprintf(out,"float f(float):(%g)",a); fflush(out); return r; } float ABI_ATTR f_f2 (float a, float b) { float r=a+b; fprintf(out,"float f(2*float):(%g,%g)",a,b); fflush(out); return r; } float ABI_ATTR f_f4 (float a, float b, float c, float d) { float r=a+b+c+d; fprintf(out,"float f(4*float):(%g,%g,%g,%g)",a,b,c,d); fflush(out); return r; } float ABI_ATTR f_f8 (float a, float b, float c, float d, float e, float f, float g, float h) { float r=a+b+c+d+e+f+g+h; fprintf(out,"float f(8*float):(%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h); fflush(out); return r; } float ABI_ATTR f_f16 (float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l, float m, float n, float o, float p) { float r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p; fprintf(out,"float f(16*float):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p); fflush(out); return r; } float ABI_ATTR f_f24 (float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l, float m, float n, float o, float p, float q, float s, float t, float u, float v, float w, float x, float y) { float r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+s+t+u+v+w+x+y; fprintf(out,"float f(24*float):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,s,t,u,v,w,x,y); fflush(out); return r; } /* double tests */ double ABI_ATTR d_d (double a) { double r=a+1.0; fprintf(out,"double f(double):(%g)",a); fflush(out); return r; } double ABI_ATTR d_d2 (double a, double b) { double r=a+b; fprintf(out,"double f(2*double):(%g,%g)",a,b); fflush(out); return r; } double ABI_ATTR d_d4 (double a, double b, double c, double d) { double r=a+b+c+d; fprintf(out,"double f(4*double):(%g,%g,%g,%g)",a,b,c,d); fflush(out); return r; } double ABI_ATTR d_d8 (double a, double b, double c, double d, double e, double f, double g, double h) { double r=a+b+c+d+e+f+g+h; fprintf(out,"double f(8*double):(%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h); fflush(out); return r; } double ABI_ATTR d_d16 (double a, double b, double c, double d, double e, double f, double g, double h, double i, double j, double k, double l, double m, double n, double o, double p) { double r=a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p; fprintf(out,"double f(16*double):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p); fflush(out); return r; } /* pointer tests */ void* ABI_ATTR vp_vpdpcpsp (void* a, double* b, char* c, Int* d) { void* ret = (char*)b + 1; fprintf(out,"void* f(void*,double*,char*,Int*):(0x%p,0x%p,0x%p,0x%p)",a,b,c,d); fflush(out); return ret; } /* mixed number tests */ uchar ABI_ATTR uc_ucsil (uchar a, ushort b, uint c, ulong d) { uchar r = (uchar)-1; fprintf(out,"uchar f(uchar,ushort,uint,ulong):(%u,%u,%u,%lu)",a,b,c,d); fflush(out); return r; } double ABI_ATTR d_iidd (int a, int b, double c, double d) { double r = a+b+c+d; fprintf(out,"double f(int,int,double,double):(%d,%d,%g,%g)",a,b,c,d); fflush(out); return r; } double ABI_ATTR d_iiidi (int a, int b, int c, double d, int e) { double r = a+b+c+d+e; fprintf(out,"double f(int,int,int,double,int):(%d,%d,%d,%g,%d)",a,b,c,d,e); fflush(out); return r; } double ABI_ATTR d_idid (int a, double b, int c, double d) { double r = a+b+c+d; fprintf(out,"double f(int,double,int,double):(%d,%g,%d,%g)",a,b,c,d); fflush(out); return r; } double ABI_ATTR d_fdi (float a, double b, int c) { double r = a+b+c; fprintf(out,"double f(float,double,int):(%g,%g,%d)",a,b,c); fflush(out); return r; } ushort ABI_ATTR us_cdcd (char a, double b, char c, double d) { ushort r = (ushort)(a + b + c + d); fprintf(out,"ushort f(char,double,char,double):('%c',%g,'%c',%g)",a,b,c,d); fflush(out); return r; } long long ABI_ATTR ll_iiilli (int a, int b, int c, long long d, int e) { long long r = (long long)(int)a+(long long)(int)b+(long long)(int)c+d+(long long)(int)e; fprintf(out,"long long f(int,int,int,long long,int):(%d,%d,%d,0x%lx%08lx,%d)",a,b,c,(long)(d>>32),(long)(d&0xffffffff),e); fflush(out); return r; } long long ABI_ATTR ll_flli (float a, long long b, int c) { long long r = (long long)(int)a + b + (long long)c; fprintf(out,"long long f(float,long long,int):(%g,0x%lx%08lx,0x%lx)",a,(long)(b>>32),(long)(b&0xffffffff),(long)c); fflush(out); return r; } float ABI_ATTR f_fi (float a, int z) { float r = a+z; fprintf(out,"float f(float,int):(%g,%d)",a,z); fflush(out); return r; } float ABI_ATTR f_f2i (float a, float b, int z) { float r = a+b+z; fprintf(out,"float f(2*float,int):(%g,%g,%d)",a,b,z); fflush(out); return r; } float ABI_ATTR f_f3i (float a, float b, float c, int z) { float r = a+b+c+z; fprintf(out,"float f(3*float,int):(%g,%g,%g,%d)",a,b,c,z); fflush(out); return r; } float ABI_ATTR f_f4i (float a, float b, float c, float d, int z) { float r = a+b+c+d+z; fprintf(out,"float f(4*float,int):(%g,%g,%g,%g,%d)",a,b,c,d,z); fflush(out); return r; } float ABI_ATTR f_f7i (float a, float b, float c, float d, float e, float f, float g, int z) { float r = a+b+c+d+e+f+g+z; fprintf(out,"float f(7*float,int):(%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,z); fflush(out); return r; } float ABI_ATTR f_f8i (float a, float b, float c, float d, float e, float f, float g, float h, int z) { float r = a+b+c+d+e+f+g+h+z; fprintf(out,"float f(8*float,int):(%g,%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,h,z); fflush(out); return r; } float ABI_ATTR f_f12i (float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l, int z) { float r = a+b+c+d+e+f+g+h+i+j+k+l+z; fprintf(out,"float f(12*float,int):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,h,i,j,k,l,z); fflush(out); return r; } float ABI_ATTR f_f13i (float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l, float m, int z) { float r = a+b+c+d+e+f+g+h+i+j+k+l+m+z; fprintf(out,"float f(13*float,int):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,h,i,j,k,l,m,z); fflush(out); return r; } double ABI_ATTR d_di (double a, int z) { double r = a+z; fprintf(out,"double f(double,int):(%g,%d)",a,z); fflush(out); return r; } double ABI_ATTR d_d2i (double a, double b, int z) { double r = a+b+z; fprintf(out,"double f(2*double,int):(%g,%g,%d)",a,b,z); fflush(out); return r; } double ABI_ATTR d_d3i (double a, double b, double c, int z) { double r = a+b+c+z; fprintf(out,"double f(3*double,int):(%g,%g,%g,%d)",a,b,c,z); fflush(out); return r; } double ABI_ATTR d_d4i (double a, double b, double c, double d, int z) { double r = a+b+c+d+z; fprintf(out,"double f(4*double,int):(%g,%g,%g,%g,%d)",a,b,c,d,z); fflush(out); return r; } double ABI_ATTR d_d7i (double a, double b, double c, double d, double e, double f, double g, int z) { double r = a+b+c+d+e+f+g+z; fprintf(out,"double f(7*double,int):(%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,z); fflush(out); return r; } double ABI_ATTR d_d8i (double a, double b, double c, double d, double e, double f, double g, double h, int z) { double r = a+b+c+d+e+f+g+h+z; fprintf(out,"double f(8*double,int):(%g,%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,h,z); fflush(out); return r; } double ABI_ATTR d_d12i (double a, double b, double c, double d, double e, double f, double g, double h, double i, double j, double k, double l, int z) { double r = a+b+c+d+e+f+g+h+i+j+k+l+z; fprintf(out,"double f(12*double,int):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,h,i,j,k,l,z); fflush(out); return r; } double ABI_ATTR d_d13i (double a, double b, double c, double d, double e, double f, double g, double h, double i, double j, double k, double l, double m, int z) { double r = a+b+c+d+e+f+g+h+i+j+k+l+m+z; fprintf(out,"double f(13*double,int):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%d)",a,b,c,d,e,f,g,h,i,j,k,l,m,z); fflush(out); return r; } /* small structure return tests */ Size1 ABI_ATTR S1_v (void) { fprintf(out,"Size1 f(void):"); fflush(out); return Size1_1; } Size2 ABI_ATTR S2_v (void) { fprintf(out,"Size2 f(void):"); fflush(out); return Size2_1; } Size3 ABI_ATTR S3_v (void) { fprintf(out,"Size3 f(void):"); fflush(out); return Size3_1; } Size4 ABI_ATTR S4_v (void) { fprintf(out,"Size4 f(void):"); fflush(out); return Size4_1; } Size7 ABI_ATTR S7_v (void) { fprintf(out,"Size7 f(void):"); fflush(out); return Size7_1; } Size8 ABI_ATTR S8_v (void) { fprintf(out,"Size8 f(void):"); fflush(out); return Size8_1; } Size12 ABI_ATTR S12_v (void) { fprintf(out,"Size12 f(void):"); fflush(out); return Size12_1; } Size15 ABI_ATTR S15_v (void) { fprintf(out,"Size15 f(void):"); fflush(out); return Size15_1; } Size16 ABI_ATTR S16_v (void) { fprintf(out,"Size16 f(void):"); fflush(out); return Size16_1; } /* structure tests */ Int ABI_ATTR I_III (Int a, Int b, Int c) { Int r; r.x = a.x + b.x + c.x; fprintf(out,"Int f(Int,Int,Int):({%d},{%d},{%d})",a.x,b.x,c.x); fflush(out); return r; } Char ABI_ATTR C_CdC (Char a, double b, Char c) { Char r; r.x = (a.x + c.x)/2; fprintf(out,"Char f(Char,double,Char):({'%c'},%g,{'%c'})",a.x,b,c.x); fflush(out); return r; } Float ABI_ATTR F_Ffd (Float a, float b, double c) { Float r; r.x = (float) (a.x + b + c); fprintf(out,"Float f(Float,float,double):({%g},%g,%g)",a.x,b,c); fflush(out); return r; } Double ABI_ATTR D_fDd (float a, Double b, double c) { Double r; r.x = a + b.x + c; fprintf(out,"Double f(float,Double,double):(%g,{%g},%g)",a,b.x,c); fflush(out); return r; } Double ABI_ATTR D_Dfd (Double a, float b, double c) { Double r; r.x = a.x + b + c; fprintf(out,"Double f(Double,float,double):({%g},%g,%g)",a.x,b,c); fflush(out); return r; } J ABI_ATTR J_JiJ (J a, int b, J c) { J r; r.l1 = a.l1+c.l1; r.l2 = a.l2+b+c.l2; fprintf(out,"J f(J,int,J):({%ld,%ld},%d,{%ld,%ld})",a.l1,a.l2,b,c.l1,c.l2); fflush(out); return r; } T ABI_ATTR T_TcT (T a, char b, T c) { T r; r.c[0]='b'; r.c[1]=c.c[1]; r.c[2]=c.c[2]; fprintf(out,"T f(T,char,T):({\"%c%c%c\"},'%c',{\"%c%c%c\"})",a.c[0],a.c[1],a.c[2],b,c.c[0],c.c[1],c.c[2]); fflush(out); return r; } X ABI_ATTR X_BcdB (B a, char b, double c, B d) { static X xr={"return val",'R'}; X r; r = xr; r.c1 = b; fprintf(out,"X f(B,char,double,B):({%g,{%d,%d,%d}},'%c',%g,{%g,{%d,%d,%d}})", a.d,a.i[0],a.i[1],a.i[2],b,c,d.d,d.i[0],d.i[1],d.i[2]); fflush(out); return r; } /* Test for cases where some argument (especially structure, 'long long', or 'double') may be passed partially in general-purpose argument registers and partially on the stack. Different ABIs pass between 4 and 8 arguments (or none) in general-purpose argument registers. */ long ABI_ATTR l_l0K (K b, long c) { long r = b.l1 + b.l2 + b.l3 + b.l4 + c; fprintf(out,"long f(K,long):(%ld,%ld,%ld,%ld,%ld)",b.l1,b.l2,b.l3,b.l4,c); fflush(out); return r; } long ABI_ATTR l_l1K (long a1, K b, long c) { long r = a1 + b.l1 + b.l2 + b.l3 + b.l4 + c; fprintf(out,"long f(long,K,long):(%ld,%ld,%ld,%ld,%ld,%ld)",a1,b.l1,b.l2,b.l3,b.l4,c); fflush(out); return r; } long ABI_ATTR l_l2K (long a1, long a2, K b, long c) { long r = a1 + a2 + b.l1 + b.l2 + b.l3 + b.l4 + c; fprintf(out,"long f(2*long,K,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a1,a2,b.l1,b.l2,b.l3,b.l4,c); fflush(out); return r; } long ABI_ATTR l_l3K (long a1, long a2, long a3, K b, long c) { long r = a1 + a2 + a3 + b.l1 + b.l2 + b.l3 + b.l4 + c; fprintf(out,"long f(3*long,K,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a1,a2,a3,b.l1,b.l2,b.l3,b.l4,c); fflush(out); return r; } long ABI_ATTR l_l4K (long a1, long a2, long a3, long a4, K b, long c) { long r = a1 + a2 + a3 + a4 + b.l1 + b.l2 + b.l3 + b.l4 + c; fprintf(out,"long f(4*long,K,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a1,a2,a3,a4,b.l1,b.l2,b.l3,b.l4,c); fflush(out); return r; } long ABI_ATTR l_l5K (long a1, long a2, long a3, long a4, long a5, K b, long c) { long r = a1 + a2 + a3 + a4 + a5 + b.l1 + b.l2 + b.l3 + b.l4 + c; fprintf(out,"long f(5*long,K,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a1,a2,a3,a4,a5,b.l1,b.l2,b.l3,b.l4,c); fflush(out); return r; } long ABI_ATTR l_l6K (long a1, long a2, long a3, long a4, long a5, long a6, K b, long c) { long r = a1 + a2 + a3 + a4 + a5 + a6 + b.l1 + b.l2 + b.l3 + b.l4 + c; fprintf(out,"long f(6*long,K,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a1,a2,a3,a4,a5,a6,b.l1,b.l2,b.l3,b.l4,c); fflush(out); return r; } /* These tests is crafted on the knowledge that for all known ABIs: * 17 > number of floating-point argument registers, * 3 < number of general-purpose argument registers < 3 + 6. */ float ABI_ATTR f_f17l3L (float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l, float m, float n, float o, float p, float q, long s, long t, long u, L z) { float r = a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+s+t+u+z.l1+z.l2+z.l3+z.l4+z.l5+z.l6; fprintf(out,"float f(17*float,3*int,L):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,s,t,u,z.l1,z.l2,z.l3,z.l4,z.l5,z.l6); fflush(out); return r; } double ABI_ATTR d_d17l3L (double a, double b, double c, double d, double e, double f, double g, double h, double i, double j, double k, double l, double m, double n, double o, double p, double q, long s, long t, long u, L z) { double r = a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p+q+s+t+u+z.l1+z.l2+z.l3+z.l4+z.l5+z.l6; fprintf(out,"double f(17*double,3*int,L):(%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld)",a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,s,t,u,z.l1,z.l2,z.l3,z.l4,z.l5,z.l6); fflush(out); return r; } long long ABI_ATTR ll_l2ll (long a1, long a2, long long b, long c) { long long r = (long long) (a1 + a2) + b + c; fprintf(out,"long long f(2*long,long long,long):(%ld,%ld,0x%lx%08lx,%ld)",a1,a2,(long)(b>>32),(long)(b&0xffffffff),c); fflush(out); return r; } long long ABI_ATTR ll_l3ll (long a1, long a2, long a3, long long b, long c) { long long r = (long long) (a1 + a2 + a3) + b + c; fprintf(out,"long long f(3*long,long long,long):(%ld,%ld,%ld,0x%lx%08lx,%ld)",a1,a2,a3,(long)(b>>32),(long)(b&0xffffffff),c); fflush(out); return r; } long long ABI_ATTR ll_l4ll (long a1, long a2, long a3, long a4, long long b, long c) { long long r = (long long) (a1 + a2 + a3 + a4) + b + c; fprintf(out,"long long f(4*long,long long,long):(%ld,%ld,%ld,%ld,0x%lx%08lx,%ld)",a1,a2,a3,a4,(long)(b>>32),(long)(b&0xffffffff),c); fflush(out); return r; } long long ABI_ATTR ll_l5ll (long a1, long a2, long a3, long a4, long a5, long long b, long c) { long long r = (long long) (a1 + a2 + a3 + a4 + a5) + b + c; fprintf(out,"long long f(5*long,long long,long):(%ld,%ld,%ld,%ld,%ld,0x%lx%08lx,%ld)",a1,a2,a3,a4,a5,(long)(b>>32),(long)(b&0xffffffff),c); fflush(out); return r; } long long ABI_ATTR ll_l6ll (long a1, long a2, long a3, long a4, long a5, long a6, long long b, long c) { long long r = (long long) (a1 + a2 + a3 + a4 + a5 + a6) + b + c; fprintf(out,"long long f(6*long,long long,long):(%ld,%ld,%ld,%ld,%ld,%ld,0x%lx%08lx,%ld)",a1,a2,a3,a4,a5,a6,(long)(b>>32),(long)(b&0xffffffff),c); fflush(out); return r; } long long ABI_ATTR ll_l7ll (long a1, long a2, long a3, long a4, long a5, long a6, long a7, long long b, long c) { long long r = (long long) (a1 + a2 + a3 + a4 + a5 + a6 + a7) + b + c; fprintf(out,"long long f(7*long,long long,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld,0x%lx%08lx,%ld)",a1,a2,a3,a4,a5,a6,a7,(long)(b>>32),(long)(b&0xffffffff),c); fflush(out); return r; } double ABI_ATTR d_l2d (long a1, long a2, double b, long c) { double r = (double) (a1 + a2) + b + c; fprintf(out,"double f(2*long,double,long):(%ld,%ld,%g,%ld)",a1,a2,b,c); fflush(out); return r; } double ABI_ATTR d_l3d (long a1, long a2, long a3, double b, long c) { double r = (double) (a1 + a2 + a3) + b + c; fprintf(out,"double f(3*long,double,long):(%ld,%ld,%ld,%g,%ld)",a1,a2,a3,b,c); fflush(out); return r; } double ABI_ATTR d_l4d (long a1, long a2, long a3, long a4, double b, long c) { double r = (double) (a1 + a2 + a3 + a4) + b + c; fprintf(out,"double f(4*long,double,long):(%ld,%ld,%ld,%ld,%g,%ld)",a1,a2,a3,a4,b,c); fflush(out); return r; } double ABI_ATTR d_l5d (long a1, long a2, long a3, long a4, long a5, double b, long c) { double r = (double) (a1 + a2 + a3 + a4 + a5) + b + c; fprintf(out,"double f(5*long,double,long):(%ld,%ld,%ld,%ld,%ld,%g,%ld)",a1,a2,a3,a4,a5,b,c); fflush(out); return r; } double ABI_ATTR d_l6d (long a1, long a2, long a3, long a4, long a5, long a6, double b, long c) { double r = (double) (a1 + a2 + a3 + a4 + a5 + a6) + b + c; fprintf(out,"double f(6*long,double,long):(%ld,%ld,%ld,%ld,%ld,%ld,%g,%ld)",a1,a2,a3,a4,a5,a6,b,c); fflush(out); return r; } double ABI_ATTR d_l7d (long a1, long a2, long a3, long a4, long a5, long a6, long a7, double b, long c) { double r = (double) (a1 + a2 + a3 + a4 + a5 + a6 + a7) + b + c; fprintf(out,"double f(7*long,double,long):(%ld,%ld,%ld,%ld,%ld,%ld,%ld,%g,%ld)",a1,a2,a3,a4,a5,a6,a7,b,c); fflush(out); return r; }
the_stack_data/148578112.c
// no output from test machine // https://syzkaller.appspot.com/bug?id=ef95147925146612c0c5b3abc6a2a10cdc1797f1 // status:open // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <endian.h> #include <fcntl.h> #include <setjmp.h> #include <signal.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/types.h> #include <unistd.h> static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } #define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \ *(type*)(addr) = \ htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \ (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) static long syz_open_dev(volatile long a0, volatile long a1, volatile long a2) { if (a0 == 0xc || a0 == 0xb) { char buf[128]; sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1, (uint8_t)a2); return open(buf, O_RDWR, 0); } else { char buf[1024]; char* hash; NONFAILING(strncpy(buf, (char*)a0, sizeof(buf) - 1)); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); a1 /= 10; } return open(buf, a2, 0); } } #ifndef __NR_sched_setattr #define __NR_sched_setattr 314 #endif uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); install_segv_handler(); long res = 0; NONFAILING(*(uint32_t*)0x200002c0 = 0); NONFAILING(*(uint32_t*)0x200002c4 = 2); NONFAILING(*(uint64_t*)0x200002c8 = 0); NONFAILING(*(uint32_t*)0x200002d0 = 0); NONFAILING(*(uint32_t*)0x200002d4 = 3); NONFAILING(*(uint64_t*)0x200002d8 = 0); NONFAILING(*(uint64_t*)0x200002e0 = 0); NONFAILING(*(uint64_t*)0x200002e8 = 0); syscall(__NR_sched_setattr, 0, 0x200002c0, 0); syz_open_dev(0, 0, 0); NONFAILING(memcpy((void*)0x200000c0, "./bus\000", 6)); res = syscall(__NR_creat, 0x200000c0, 0); if (res != -1) r[0] = res; NONFAILING(*(uint64_t*)0x20000380 = -1); syscall(__NR_write, r[0], 0x20000380, 1); NONFAILING(*(uint32_t*)0x20000040 = 1); NONFAILING(*(uint32_t*)0x20000044 = 0x70); NONFAILING(*(uint8_t*)0x20000048 = 0); NONFAILING(*(uint8_t*)0x20000049 = 0); NONFAILING(*(uint8_t*)0x2000004a = 0); NONFAILING(*(uint8_t*)0x2000004b = 0); NONFAILING(*(uint32_t*)0x2000004c = 0); NONFAILING(*(uint64_t*)0x20000050 = 0x50d); NONFAILING(*(uint64_t*)0x20000058 = 0); NONFAILING(*(uint64_t*)0x20000060 = 0); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 0, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 1, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 2, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 3, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 4, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 5, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 6, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 7, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 8, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 9, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 10, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 11, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 12, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 13, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 14, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 15, 2)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 17, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 18, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 19, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 20, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 21, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 22, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 23, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 24, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 25, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 26, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 27, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 28, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, , 0x20000068, 0, 29, 35)); NONFAILING(*(uint32_t*)0x20000070 = 0); NONFAILING(*(uint32_t*)0x20000074 = 0); NONFAILING(*(uint64_t*)0x20000078 = 0); NONFAILING(*(uint64_t*)0x20000080 = 0); NONFAILING(*(uint64_t*)0x20000088 = 0); NONFAILING(*(uint64_t*)0x20000090 = 0); NONFAILING(*(uint32_t*)0x20000098 = 0); NONFAILING(*(uint32_t*)0x2000009c = 0); NONFAILING(*(uint64_t*)0x200000a0 = 0); NONFAILING(*(uint32_t*)0x200000a8 = 0); NONFAILING(*(uint16_t*)0x200000ac = 0); NONFAILING(*(uint16_t*)0x200000ae = 0); syscall(__NR_perf_event_open, 0x20000040, 0, -1, -1, 0); NONFAILING(memcpy((void*)0x20000180, "./bus\000", 6)); res = syscall(__NR_open, 0x20000180, 0, 0); if (res != -1) r[1] = res; syscall(__NR_sendto, r[0], 0, 0, 0x4000800, 0, 0); syscall(__NR_sendfile, r[0], r[1], 0, 0x8000fffffffe); syscall(__NR_preadv, -1, 0, 0, 0); return 0; }
the_stack_data/190768211.c
extern const unsigned char SmoothSwipexitVersionString[]; extern const double SmoothSwipexitVersionNumber; const unsigned char SmoothSwipexitVersionString[] __attribute__ ((used)) = "@(#)PROGRAM:SmoothSwipexit PROJECT:SmoothSwipexit-1" "\n"; const double SmoothSwipexitVersionNumber __attribute__ ((used)) = (double)1.;
the_stack_data/122015834.c
/* This file is part of MAMBO, a low-overhead dynamic binary modification tool: https://github.com/beehive-lab/mambo Copyright 2013-2016 Cosmin Gorgovan <cosmin at linux-geek dot org> 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 PLUGINS_NEW #include <stdio.h> #include <assert.h> #include <stdarg.h> #include "../plugins.h" #ifdef __arm__ #include "../pie/pie-thumb-encoder.h" #elif __aarch64__ #include "../pie/pie-a64-encoder.h" #include "../api/emit_a64.h" #endif #define not_implemented() \ fprintf(stderr, "%s: Implement me\n", __PRETTY_FUNCTION__); \ while(1); #ifdef __arm__ void emit_thumb_push_cpsr(mambo_context *ctx, enum reg tmp_reg) { uint16_t *write_p = ctx->code.write_p; // MRS tmp_reg, CPSR thumb_mrs32(&write_p, tmp_reg); write_p += 2; // PUSH {tmp_reg} thumb_push_regs(&write_p, 1 << tmp_reg); ctx->code.write_p = write_p; } void emit_arm_push_cpsr(mambo_context *ctx, enum reg tmp_reg) { emit_arm_mrs(ctx, tmp_reg); emit_arm_push(ctx, 1 << tmp_reg); } void emit_thumb_pop_cpsr(mambo_context *ctx, enum reg tmp_reg) { uint16_t *write_p = ctx->code.write_p; // POP {tmp_reg} thumb_pop_regs(&write_p, 1 << tmp_reg); // MSR tmp_reg, CPSR_fs thumb_msr32(&write_p, tmp_reg, 3); write_p += 2; ctx->code.write_p = write_p; } void emit_arm_pop_cpsr(mambo_context *ctx, enum reg tmp_reg) { emit_arm_pop(ctx, 1 << tmp_reg); emit_arm_msr(ctx, tmp_reg, 3); } void emit_thumb_copy_to_reg_32bit(mambo_context *ctx, enum reg reg, uint32_t value) { if (value <= 0xFFFF) { copy_to_reg_16bit((uint16_t **)&ctx->code.write_p, reg, value); } else { copy_to_reg_32bit((uint16_t **)&ctx->code.write_p, reg, value); } } void emit_arm_copy_to_reg_32bit(mambo_context *ctx, enum reg reg, uint32_t value) { if (value <= 0xFFFF) { arm_copy_to_reg_16bit((uint32_t **)&ctx->code.write_p, reg, value); } else { arm_copy_to_reg_32bit((uint32_t **)&ctx->code.write_p, reg, value); } } void emit_thumb_b16_cond(void *write_p, void *target, mambo_cond cond) { thumb_b16_cond_helper((uint16_t *)write_p, (uint32_t)target, cond); } void emit_thumb_push(mambo_context *ctx, uint32_t regs) { ctx->code.plugin_pushed_reg_count += count_bits(regs); uint16_t *write_p = ctx->code.write_p; thumb_push_regs(&write_p, regs); ctx->code.write_p = write_p; } void emit_arm_push(mambo_context *ctx, uint32_t regs) { ctx->code.plugin_pushed_reg_count += count_bits(regs); uint32_t *write_p = ctx->code.write_p; arm_push_regs(regs); ctx->code.write_p = write_p; } void emit_thumb_pop(mambo_context *ctx, uint32_t regs) { ctx->code.plugin_pushed_reg_count -= count_bits(regs); assert(ctx->code.plugin_pushed_reg_count >= 0); uint16_t *write_p = ctx->code.write_p; thumb_pop_regs(&write_p, regs); ctx->code.write_p = write_p; } void emit_arm_pop(mambo_context *ctx, uint32_t regs) { ctx->code.plugin_pushed_reg_count -= count_bits(regs); assert(ctx->code.plugin_pushed_reg_count >= 0); uint32_t *write_p = ctx->code.write_p; arm_pop_regs(regs); ctx->code.write_p = write_p; } void emit_arm_fcall(mambo_context *ctx, void *function_ptr) { emit_arm_copy_to_reg_32bit(ctx, lr, (uint32_t)function_ptr); emit_arm_blx(ctx, lr); } void emit_thumb_fcall(mambo_context *ctx, void *function_ptr) { emit_thumb_copy_to_reg_32bit(ctx, lr, (uint32_t)function_ptr); emit_thumb_blx16(ctx, lr); } static inline int emit_arm_add_sub_shift(mambo_context *ctx, int rd, int rn, int rm, unsigned int shift_type, unsigned int shift) { if (shift < 0 || shift > 31 || shift_type > ROR) { return -1; } if (rm < 0) { rm = -rm; emit_arm_sub(ctx, REG_PROC, 0, rd, rn, rm | (shift_type << 5) | (shift << 7)); } else { emit_arm_add(ctx, REG_PROC, 0, rd, rn, rm | (shift_type << 5) | (shift << 7)); } return 0; } static inline int emit_arm_add_sub(mambo_context *ctx, int rd, int rn, int rm) { return emit_arm_add_sub_shift(ctx, rd, rn, rm, LSL, 0); } static inline int emit_thumb_add_sub_shift(mambo_context *ctx, int rd, int rn, int rm, unsigned int shift_type, unsigned int shift) { if (shift < 0 || shift > 31 || shift_type > ROR) { return -1; } if (rm < 0) { rm = -rm; emit_thumb_sub32(ctx, 0, rn, shift >> 2, rd, shift, shift_type, rm); } else { emit_thumb_add32(ctx, 0, rn, shift >> 2, rd, shift, shift_type, rm); } return 0; } static inline int emit_thumb_add_sub(mambo_context *ctx, int rd, int rn, int rm) { return emit_thumb_add_sub_shift(ctx, rd, rn, rm, LSL, 0); } #endif // __arm__ #ifdef __aarch64__ void emit_a64_push(mambo_context *ctx, uint32_t regs) { int reg_no = count_bits(regs); ctx->code.plugin_pushed_reg_count += reg_no; uint32_t *write_p = ctx->code.write_p; uint32_t to_push[2]; if (reg_no & 1) { reg_no = get_highest_n_regs(regs, to_push, 1); assert(reg_no == 1); a64_push_reg(to_push[0]); regs &= ~(1 << to_push[0]); } while (regs != 0) { reg_no = get_highest_n_regs(regs, to_push, 2); assert(reg_no == 2); a64_push_pair_reg(to_push[1], to_push[0]); regs &= ~((1 << to_push[0]) | (1 << to_push[1])); } ctx->code.write_p = write_p; } void emit_a64_pop(mambo_context *ctx, uint32_t regs) { ctx->code.plugin_pushed_reg_count -= count_bits(regs); assert(ctx->code.plugin_pushed_reg_count >= 0); uint32_t *write_p = ctx->code.write_p; uint32_t to_pop[2]; int reg_no; while (regs != 0) { reg_no = get_lowest_n_regs(regs, to_pop, 2); assert(reg_no == 1 || reg_no == 2); if (reg_no == 2) { a64_pop_pair_reg(to_pop[0], to_pop[1]); regs &= ~((1 << to_pop[0]) | (1 << to_pop[1])); } else if (reg_no == 1) { a64_pop_reg(to_pop[0]); regs &= ~(1 << to_pop[0]); } } ctx->code.write_p = write_p; } static inline int emit_a64_add_sub_shift(mambo_context *ctx, int rd, int rn, int rm, unsigned int shift_type, unsigned int shift) { if (shift < 0 || shift > 63 || shift_type > ASR) return -1; int op = (rm < 0); rm = abs(rm); emit_a64_ADD_SUB_shift_reg(ctx, 1, op, 0, shift_type, rm, shift, rn, rd); return 0; } static inline int emit_a64_add_sub(mambo_context *ctx, int rd, int rn, int rm) { return emit_a64_add_sub_shift(ctx, rd, rn, rm, LSL, 0); } int emit_a64_add_sub_ext(mambo_context *ctx, int rd, int rn, int rm, int ext_option, int shift) { int op = (rm < 0); rm = abs(rm); if (shift > 4 || shift < 0) return -1; emit_a64_ADD_SUB_ext_reg(ctx, 1, op, 0, rm, ext_option, shift, rn, rd); return 0; } #endif void emit_push(mambo_context *ctx, uint32_t regs) { #ifdef __arm__ inst_set isa = mambo_get_inst_type(ctx); if (isa == ARM_INST) { emit_arm_push(ctx, regs); } else { emit_thumb_push(ctx, regs); } #elif __aarch64__ emit_a64_push(ctx, regs); #endif } void emit_pop(mambo_context *ctx, uint32_t regs) { assert(ctx->code.plugin_pushed_reg_count >= 0); #ifdef __arm__ inst_set isa = mambo_get_inst_type(ctx); if (isa == ARM_INST) { emit_arm_pop(ctx, regs); } else { emit_thumb_pop(ctx, regs); } #elif __aarch64__ emit_a64_pop(ctx, regs); #endif } void emit_set_reg(mambo_context *ctx, enum reg reg, uintptr_t value) { #ifdef __arm__ inst_set isa = mambo_get_inst_type(ctx); if (isa == ARM_INST) { emit_arm_copy_to_reg_32bit(ctx, reg, value); } else { emit_thumb_copy_to_reg_32bit(ctx, reg, value); } #elif __aarch64__ a64_copy_to_reg_64bits((uint32_t **)&ctx->code.write_p, reg, value); #endif } int __emit_branch_cond(inst_set inst_type, void *write, uintptr_t target, mambo_cond cond, bool link) { intptr_t diff = (target & (~THUMB)) - (uintptr_t)write; if (cond != AL && link) return -1; #ifdef __arm__ switch (inst_type) { case THUMB_INST: diff -= 4; if (cond == AL) { bool to_arm = link && !(target & THUMB); target &= ~THUMB; if (diff < -16777216 || diff > 16777214) return -1; thumb_b_bl_helper(write, target, link, to_arm); } else { if (diff < -1048576 || diff > 1048574) return -1; void *write_c = write; thumb_b32_cond_helper((uint16_t **)&write, target, cond); assert((write_c + 4) == write); } break; case ARM_INST: if (target & THUMB) return -1; diff -= 8; if (diff < -33554432 || diff > 33554428) return -1; arm_branch_helper(write, target, link, cond); break; default: return -1; } #endif #ifdef __aarch64__ if (cond == AL) { if (diff < -134217728 || diff > 134217724) return -1; a64_branch_helper(write, target, link); //a64_b_helper(write, target); } else { if (diff < -1048576 || diff > 1048572) return -1; a64_b_cond_helper(write, target, cond); } #endif return 0; } void emit_fcall(mambo_context *ctx, void *function_ptr) { // First try an immediate call, and if that is out of range then generate an indirect call int ret = __emit_branch_cond(ctx->code.inst_type, ctx->code.write_p, (uintptr_t)function_ptr, AL, true); if (ret == 0) return; emit_set_reg(ctx, lr, (uintptr_t)function_ptr); #ifdef __arm__ inst_set type = mambo_get_inst_type(ctx); if (type == ARM_INST) { emit_arm_blx(ctx, lr); } else { emit_thumb_blx16(ctx, lr); } #elif __aarch64__ emit_a64_BLR(ctx, lr); #endif } int emit_safe_fcall(mambo_context *ctx, void *function_ptr, int argno) { uintptr_t to_push = (1 << lr); #ifdef __arm__ to_push |= (1 << r0) | (1 << r1) | (1 << r2) | (1 << r3) | (1 << r4); #elif __aarch64__ to_push |= 0x1FF; #endif if (argno > MAX_FCALL_ARGS) return -1; to_push &= ~(((1 << MAX_FCALL_ARGS)-1) >> (MAX_FCALL_ARGS - argno)); emit_push(ctx, to_push); emit_set_reg_ptr(ctx, MAX_FCALL_ARGS, function_ptr); emit_fcall(ctx, safe_fcall_trampoline); emit_pop(ctx, to_push); return 0; } int emit_safe_fcall_static_args(mambo_context *ctx, void *fptr, int argno, ...) { va_list args; uint32_t reglist = 0; if (argno > MAX_FCALL_ARGS || argno < 0) return -1; if (argno > 0) { reglist = 0xFF >> (8-argno); emit_push(ctx, reglist); va_start(args, argno); for (int a = 0; a < argno; a++) { emit_set_reg(ctx, a, va_arg(args, uintptr_t)); } va_end(args); } emit_safe_fcall(ctx, fptr, argno); if (argno > 0) { emit_pop(ctx, reglist); } return 0; } void emit_mov(mambo_context *ctx, enum reg rd, enum reg rn) { #ifdef __arm__ assert(rd >= 0 && rd < pc && rn >= 0 && rn < pc); if (mambo_get_inst_type(ctx) == THUMB_INST) { emit_thumb_movh16(ctx, rd >> 3, rn, rd); } else { emit_arm_mov(ctx, REG_PROC, 0, rd, rn); } #elif __aarch64__ if (rn == sp) { emit_a64_ADD_SUB_immed(ctx, 1, 0, 0, 0, 0, rn, rd); } else { emit_a64_logical_reg(ctx, 1, 1, 0, 0, rn, 0, 0x1F, rd); } #endif } #ifdef __arm__ #define SHIFTED_ADD_SUB_I_BITS 8 #define _emit_add_shift_imm(rd, rn, offset, shift) \ assert((shift & 1) == 0); \ emit_arm_add(ctx, IMM_PROC, 0, rd, rn, ((16 - (shift / 2)) << 8) | offset); #define _emit_sub_shift_imm(rd, rn, offset, shift) \ assert((shift & 1) == 0); \ emit_arm_sub(ctx, IMM_PROC, 0, rd, rn, ((16 - (shift / 2)) << 8) | offset); #elif __aarch64__ #define SHIFTED_ADD_SUB_I_BITS 12 #define _emit_add_shift_imm(rd, rn, offset, shift) \ assert((shift) == 0 || (shift) == 12); \ emit_a64_ADD_SUB_immed(ctx, 1, 0, 0, (shift == 12), (offset), (rn), (rd)); #define _emit_sub_shift_imm(rd, rn, offset, shift) \ assert((shift) == 0 || (shift) == 12); \ emit_a64_ADD_SUB_immed(ctx, 1, 1, 0, (shift == 12), (offset), (rn), (rd)); #endif #define SHIFTED_ADD_SUB_I_MASK ((1 << SHIFTED_ADD_SUB_I_BITS) - 1) #define SHIFTED_ADD_SUB_MAX (SHIFTED_ADD_SUB_I_MASK | (SHIFTED_ADD_SUB_I_MASK << SHIFTED_ADD_SUB_I_BITS)) int emit_add_sub_i(mambo_context *ctx, int rd, int rn, int offset) { if (offset == 0) { if (rd != rn) { emit_mov(ctx, rd, rn); return 0; } } else { #ifdef __arm__ inst_set isa = mambo_get_inst_type(ctx); if (isa == THUMB_INST) { if (offset > 0xFFF || offset < -0xFFF) return -1; if (offset < 0) { offset = -offset; emit_thumb_subwi32(ctx, offset >> 11, rn, offset >> 8, rd, offset); } else { emit_thumb_addwi32(ctx, offset >> 11, rn, offset >> 8, rd, offset); } return 0; } #endif if (offset < -SHIFTED_ADD_SUB_MAX || offset > SHIFTED_ADD_SUB_MAX) return -1; if (offset < 0) { offset = -offset; if (offset & SHIFTED_ADD_SUB_I_MASK) { _emit_sub_shift_imm(rd, rn, offset & SHIFTED_ADD_SUB_I_MASK, 0); rn = rd; } if (offset & (SHIFTED_ADD_SUB_I_MASK << SHIFTED_ADD_SUB_I_BITS)) { _emit_sub_shift_imm(rd, rn, offset >> SHIFTED_ADD_SUB_I_BITS, SHIFTED_ADD_SUB_I_BITS); } } else { if (offset & SHIFTED_ADD_SUB_I_MASK) { _emit_add_shift_imm(rd, rn, offset & SHIFTED_ADD_SUB_I_MASK, 0); rn = rd; } if (offset & (SHIFTED_ADD_SUB_I_MASK << SHIFTED_ADD_SUB_I_BITS)) { _emit_add_shift_imm(rd, rn, offset >> SHIFTED_ADD_SUB_I_BITS, SHIFTED_ADD_SUB_I_BITS); } } } // offset != 0 return 0; } inline int emit_add_sub_shift(mambo_context *ctx, int rd, int rn, int rm, unsigned int shift_type, unsigned int shift) { #ifdef __arm__ if (mambo_get_inst_type(ctx) == THUMB_INST) { return emit_thumb_add_sub_shift(ctx, rd, rn, rm, shift_type, shift); } else { return emit_arm_add_sub_shift(ctx, rd, rn, rm, shift_type, shift); } #elif __aarch64__ return emit_a64_add_sub_shift(ctx, rd, rn, rm, shift_type, shift); #endif } inline int emit_add_sub(mambo_context *ctx, int rd, int rn, int rm) { return emit_add_sub_shift(ctx, rd, rn, rm, LSL, 0); } int emit_branch_cond(mambo_context *ctx, void *target, mambo_cond cond) { void *write_p = mambo_get_cc_addr(ctx); int ret = __emit_branch_cond(mambo_get_inst_type(ctx), write_p, (uintptr_t)target, cond, false); if (ret == 0) { mambo_set_cc_addr(ctx, write_p + 4); } return ret; } int emit_branch(mambo_context *ctx, void *target) { return emit_branch_cond(ctx, target, AL); } int __emit_branch_cbz_cbnz(mambo_context *ctx, void *write_p, void *target, enum reg reg, bool is_cbz) { int ret = -1; #ifdef __aarch64__ ret = a64_cbz_cbnz_helper((uint32_t *)write_p, !is_cbz, (uint64_t)target, 1, reg); #elif __arm__ if (mambo_get_inst_type(ctx) == THUMB_INST) { ret = thumb_cbz_cbnz_helper((uint16_t *)write_p, (uint32_t)target, reg, is_cbz); } #endif return ret; } int emit_branch_cbz_cbnz(mambo_context *ctx, void *target, enum reg reg, bool is_cbz) { void *write_p = mambo_get_cc_addr(ctx); int ret = __emit_branch_cbz_cbnz(ctx, write_p, target, reg, is_cbz); if (ret == 0) { #ifdef __aarch64__ mambo_set_cc_addr(ctx, write_p + 4); #elif __arm__ mambo_set_cc_addr(ctx, write_p + 2); #endif } return ret; } int emit_branch_cbz(mambo_context *ctx, void *target, enum reg reg) { return emit_branch_cbz_cbnz(ctx, target, reg, true); } int emit_branch_cbnz(mambo_context *ctx, void *target, enum reg reg) { return emit_branch_cbz_cbnz(ctx, target, reg, false); } int __mambo_reserve(mambo_context *ctx, mambo_branch *br, size_t incr) { if (ctx->code.write_p) { br->loc = ctx->code.write_p; ctx->code.write_p += incr; return 0; } return -1; } int mambo_reserve_branch(mambo_context *ctx, mambo_branch *br) { return __mambo_reserve(ctx, br, 4); } int mambo_reserve_branch_cbz(mambo_context *ctx, mambo_branch *br) { #ifdef __arm__ if (mambo_get_inst_type(ctx) == THUMB_INST) { return __mambo_reserve(ctx, br, 2); } return -1; #endif return __mambo_reserve(ctx, br, 4); } int __emit_local_branch(mambo_context *ctx, mambo_branch *br, mambo_cond cond, bool link) { uintptr_t target = (uintptr_t)mambo_get_cc_addr(ctx); #ifdef __arm__ if (ctx->code.inst_type == THUMB_INST) { target |= THUMB; } #endif return __emit_branch_cond(mambo_get_inst_type(ctx), br->loc, target, cond, link); } int emit_local_branch_cond(mambo_context *ctx, mambo_branch *br, mambo_cond cond) { return __emit_local_branch(ctx, br, cond, false); } int emit_local_branch(mambo_context *ctx, mambo_branch *br) { return __emit_local_branch(ctx, br, AL, false); } int emit_local_fcall(mambo_context *ctx, mambo_branch *br) { return __emit_local_branch(ctx, br, AL, true); } int emit_local_branch_cbz_cbnz(mambo_context *ctx, mambo_branch *br, enum reg reg, bool is_cbz) { return __emit_branch_cbz_cbnz(ctx, br->loc, mambo_get_cc_addr(ctx), reg, is_cbz); } int emit_local_branch_cbz(mambo_context *ctx, mambo_branch *br, enum reg reg) { return emit_local_branch_cbz_cbnz(ctx, br, reg, true); } int emit_local_branch_cbnz(mambo_context *ctx, mambo_branch *br, enum reg reg) { return emit_local_branch_cbz_cbnz(ctx, br, reg, false); } void emit_counter64_incr(mambo_context *ctx, void *counter, unsigned incr) { #ifdef __arm__ /* On AArch32 we use NEON rather than ADD and ADC to avoid having to save and restore the PSR register, which is slow. VPUSH {D0, D1} PUSH {R0} MOV{W,T} R0, counter VLDR D1, [R0] VMOV.I32 D0, #incr VSHR.U64 D0, D0, #32 VADD.I64 D0, D1, D0 VSTR D0, [R0] POP {R0} VPOP {D0, D1} */ assert(incr <= 255); switch(mambo_get_inst_type(ctx)) { case THUMB_INST: { emit_thumb_vfp_vpush(ctx, 1, 0, 0, 4); emit_thumb_push(ctx, 1 << r0); emit_thumb_copy_to_reg_32bit(ctx, r0, (uintptr_t)counter); emit_thumb_vfp_vldr_dp(ctx, 1, r0, 0, 1, 0); emit_thumb_neon_vmovi(ctx, 0, 0, 0, 0, 0, incr >> 7, incr >> 4, incr); emit_thumb_neon_vshr(ctx, 1, 0, 0, 0, 0, 0, 1, 32); emit_thumb_neon_vadd_i(ctx, 3, 0, 0, 0, 0, 1, 0, 0); emit_thumb_vfp_vstr_dp(ctx, 1, 0, r0, 0, 0); emit_thumb_pop(ctx, 1 << r0); emit_thumb_vfp_vpop(ctx, 1, 0, 0, 4); break; } case ARM_INST: emit_arm_vfp_vpush_dp(ctx, 0, 0, 4); emit_arm_push(ctx, (1 << r0)); emit_arm_copy_to_reg_32bit(ctx, r0, (uintptr_t)counter); emit_arm_vfp_vldr_dp(ctx, 1, 0, r0, 1, 0); emit_arm_neon_vmovi(ctx, 0, 0, 0, 0, 0, incr >> 7, incr >> 4, incr); emit_arm_neon_vshr(ctx, 1, 0, 0, 0, 0, 0, 1, 32); emit_arm_neon_vadd_i(ctx, 3, 0, 0, 0, 0, 1, 0, 0); emit_arm_vfp_vstr_dp(ctx, 1, 0, r0, 0, 0); emit_arm_pop(ctx, (1 << r0)); emit_arm_vfp_vpop_dp(ctx, 0, 0, 4); break; } #endif #ifdef __aarch64__ assert(incr <= 0xFFF); emit_a64_push(ctx, (1 << x0) | (1 << x1)); a64_copy_to_reg_64bits((uint32_t **)&ctx->code.write_p, x0, (uintptr_t)counter); emit_a64_LDR_STR_unsigned_immed(ctx, 3, 0, 1, 0, x0, x1); emit_a64_ADD_SUB_immed(ctx, 1, 0, 0, 0, incr, x1, x1); emit_a64_LDR_STR_unsigned_immed(ctx, 3, 0, 0, 0, x0, x1); emit_a64_pop(ctx, (1 << x0) | (1 << x1)); #endif } int emit_indirect_branch_by_spc(mambo_context *ctx, enum reg reg) { #ifdef __aarch64__ // Uses fragment id 0 to prevent the dispatcher from attempting linking on an IHL miss a64_inline_hash_lookup(current_thread, 0, (uint32_t **)&ctx->code.write_p, ctx->code.read_address, reg, false, false); #else switch(ctx->code.inst_type) { case ARM_INST: emit_push(ctx, (1 << r4) | (1 << 5) | (1 << 6)); arm_inline_hash_lookup(current_thread, (uint32_t **)&ctx->code.write_p, 0, reg); break; case THUMB_INST: { uint16_t *write_p = (uint16_t *)ctx->code.write_p; if (reg != r5 && reg != r6) { thumb_push16(&write_p, (1 << r5) | (1 << r6)); } else { thumb_push16(&write_p, (1 << r4) | (1 << r5) | (1 << r6)); write_p++; thumb_movh16(&write_p, 0, reg, r5); reg = -1; } write_p++; thumb_inline_hash_lookup(current_thread, &write_p, 0, reg); ctx->code.write_p = write_p; break; } default: assert(0); } #endif } #endif
the_stack_data/145453760.c
#include <stdio.h> #include <stdlib.h> int somaBit(int vetorA[], long int C){ int vetorB[20], i,j; long int aux = C; for(j=0;j<20;j++)vetorB[j] = 0; i = 0; while(aux!= 0){ vetorB[i] = aux % 2; aux = aux / 2; i++; } j=0; while(j<20){ if(vetorB[j] == vetorA[j])vetorA[j] = 0; else vetorA[j] = 1; j++; } for(j=0;j<20;j++) if(vetorA[j] == 1)return 0; return 1; } int main(){ int vetorA[20],vetorB[20],T,N,i,j,tam; long int C, soma, menor; int zero; scanf("%d",&T); for(i=0;i<T;i++){ scanf("%d",&N); soma = 0; for(j=0;j<20;j++)vetorA[j] = 0; menor = 1000001; for(j=0;j<N;j++){ scanf("%ld",&C); soma = soma + C; if(C < menor) menor = C; zero = somaBit(vetorA,C); } if((zero == 1))printf("Case #%d: %ld",i+1,soma - menor); else printf("Case #%d: NO",i+1); if(i < T-1)printf("\n"); } }
the_stack_data/190769199.c
#include <unistd.h> #include <stdio.h> int main(){ pid_t pid_base_process = getpid(); printf("[%d] MAIN START\n", getpid()); char *args[]={"./called_by_exec",NULL}; execvp("./called_by_exec", args); printf("[%d] MAIN END\n", getpid()); // Will not be executed return 0; }
the_stack_data/1116898.c
/* QEMU versatile machine memory map sets VIRT_UART as 0x101f1000 */ #define UART0_BASE 0x101f1000 volatile unsigned int * const UART0DR = (unsigned int *)UART0_BASE; /* Until we reach to the end of the string, put each char on UART0 */ void print_uart0(const char *str) { while(*str != '\0') { *UART0DR = (unsigned int)(*str); str++; } } /* Entry function from startup.s */ void main() { print_uart0("Hello OpenEmbedded on ARMv5!\n"); }
the_stack_data/1076127.c
/* This testcase is from PR43012. You will need CLooG-PPL 0.15.8 or later to have this testcase fixed. */ /* { dg-do run } */ /* { dg-options "-O2 -floop-strip-mine" } */ extern void abort (void); #ifdef DBG extern int printf (const char *, ...); #endif #define LAST_TOKEN 534 #define FLOAT_FUNCT_TOKEN 64 #define VECTOR_FUNCT_TOKEN 77 #define COLOUR_KEY_TOKEN 89 int Table[LAST_TOKEN]; void pre_init_tokenizer () { int i; for (i = 0; i < LAST_TOKEN; i++) { Table[i] = i; if (i < FLOAT_FUNCT_TOKEN) Table[i] = FLOAT_FUNCT_TOKEN; else { if (i < VECTOR_FUNCT_TOKEN) Table[i] = VECTOR_FUNCT_TOKEN; else { if (i < COLOUR_KEY_TOKEN) Table[i] = COLOUR_KEY_TOKEN; } } } } void check () { int i; for (i = 0; i < FLOAT_FUNCT_TOKEN; i++) if (Table[i] != FLOAT_FUNCT_TOKEN) abort (); for (i = FLOAT_FUNCT_TOKEN; i < VECTOR_FUNCT_TOKEN; i++) if (Table[i] != VECTOR_FUNCT_TOKEN) abort (); for (i = VECTOR_FUNCT_TOKEN; i < COLOUR_KEY_TOKEN; i++) if (Table[i] != COLOUR_KEY_TOKEN) abort (); for (i = COLOUR_KEY_TOKEN; i < LAST_TOKEN; i++) if (Table[i] != i) abort (); } int main () { int i; pre_init_tokenizer (); #ifdef DBG for (i = 0; i < LAST_TOKEN; i++) printf ("%3d: %d\n", i, Table[i]); #endif check (); return 0; }
the_stack_data/95450481.c
int CommunityExpressNS_CommunityExpress_Initialize() { return 0; } int SteamUnityAPI_Init() { return 1; } int SteamUnityAPI_RestartAppIfNecessary() { return 0; } int SteamUnityAPI_Shutdown() { return 0; } int SteamUnityAPI_SteamFriends() { return 0; } int SteamUnityAPI_SteamRemoteStorage() { return 0; } int SteamUnityAPI_SteamRemoteStorage_EnumeratePublishedWorkshopFiles() { return 0; } int SteamUnityAPI_SteamMatchmaking() { return 0; } int SteamUnityAPI_SteamMatchmakingServers() { return 0; } int SteamUnityAPI_SteamNetworking() { return 0; } int SteamUnityAPI_SteamNetworking_AllowP2PPacketRelay() { return 0; } int SteamUnityAPI_SteamNetworking_IsP2PPacketAvailable() { return 0; } int SteamUnityAPI_RunCallbacks() { return 0; } int SteamUnityAPI_SteamGameServer_RunCallbacks() { return 0; } int SteamUnityAPI_SteamUtils_GetAppID() { return 0; } int SteamUnityAPI_SteamUtils_GetLobbyEnteredResult(void *a, int b, int c) { b = 0; c = 0; return 0; } int SteamUnityAPI_IsSteamRunning() { return 1; } int SteamUnityAPI_SteamUtils_IsAPICallCompleted(int a, int b) { b = 0; return 0; } int SteamUnityAPI_SetWarningMessageHook() { return 0; } int SteamUnityAPI_SteamUser() { return 0; } int SteamUnityAPI_SteamUser_GetSteamID(void *a) { return 0; } int SteamUnityAPI_SteamFriends_ActivateGameOverlayToWebPage() { return 0; } int SteamUnityAPI_GetPersonaNameByID(int a) { return 0; } int SteamUnityAPI_SteamUserStats() { return 0; } int SteamUnityAPI_SteamUserStats_RequestCurrentStats() { return 0; } int SteamUnityAPI_SteamUtils_GetServerRealTime() { return 0; } int SteamUnityAPI_SteamUserStats_FindOrCreateLeaderboard() { return 0; }
the_stack_data/31138.c
#include<stdlib.h> #include<stdio.h> #include<string.h> #include<math.h> unsigned char *binGap(int t, int m){ int q; int i, log; static unsigned char bin[8]; if (m < 0 || m > pow(2, (t))-1){ printf("Number not in range [0..(q^t-1)]"); } for (i = 0; i < (t); i++){ bin[i] = 0; } while ( m > 1){ log = log2(m); bin[t-log-1] = 1; m = m - pow(2, log); } if( m == 1){ bin[t-1] = 1; } return bin; } int main(){ unsigned char buffs[9]; FILE *myFile; myFile = fopen("RandomCodeword96.txt", "r"); if (myFile == NULL){ printf("Error Reading File\n"); exit (0); } for (int a = 0; a < 9; a++) { fscanf(myFile, "%d,", &buffs[a]); } for (int a = 0; a < 9; a++) { printf("%u", buffs[a]); } fclose(myFile); return 0; }
the_stack_data/139489.c
/** ****************************************************************************** * @file stm32mp1xx_ll_pwr.c * @author MCD Application Team * @brief PWR LL module driver. ****************************************************************************** * @attention * * Copyright (c) 2019 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ #if defined(USE_FULL_LL_DRIVER) /* Includes ------------------------------------------------------------------*/ #include "stm32mp1xx_ll_pwr.h" /** @addtogroup STM32MP1xx_LL_Driver * @{ */ #if defined(PWR) /** @defgroup PWR_LL PWR * @{ */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /** @addtogroup PWR_LL_Exported_Functions * @{ */ /** @addtogroup PWR_LL_EF_Init * @{ */ /** * @brief De-initialize the PWR registers to their default reset values. * @retval An ErrorStatus enumeration value: * - SUCCESS: PWR registers are de-initialized * - ERROR: not applicable */ ErrorStatus LL_PWR_DeInit(void) { WRITE_REG(PWR->WKUPCR, (PWR_WKUPCR_WKUPC1 | PWR_WKUPCR_WKUPC2 | PWR_WKUPCR_WKUPC3 | \ PWR_WKUPCR_WKUPC4 | PWR_WKUPCR_WKUPC5 | PWR_WKUPCR_WKUPC6)); return SUCCESS; } /** * @} */ /** * @} */ /** * @} */ #endif /* defined(PWR) */ /** * @} */ #endif /* USE_FULL_LL_DRIVER */
the_stack_data/398015.c
/** ****************************************************************************** * @file stm32wbxx_ll_rng.c * @author MCD Application Team * @brief RNG LL module driver. ****************************************************************************** * @attention * * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics. * All rights reserved.</center></h2> * * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ #if defined(USE_FULL_LL_DRIVER) /* Includes ------------------------------------------------------------------*/ #include "stm32wbxx_ll_rng.h" #include "stm32wbxx_ll_bus.h" #ifdef USE_FULL_ASSERT #include "stm32_assert.h" #else #define assert_param(expr) ((void)0U) #endif /** @addtogroup STM32WBxx_LL_Driver * @{ */ #if defined (RNG) /** @addtogroup RNG_LL * @{ */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ /** @addtogroup RNG_LL_Private_Macros * @{ */ #define IS_LL_RNG_CED(__MODE__) (((__MODE__) == LL_RNG_CED_ENABLE) || \ ((__MODE__) == LL_RNG_CED_DISABLE)) /** * @} */ /* Private function prototypes -----------------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /** @addtogroup RNG_LL_Exported_Functions * @{ */ /** @addtogroup RNG_LL_EF_Init * @{ */ /** * @brief De-initialize RNG registers (Registers restored to their default values). * @param RNGx RNG Instance * @retval An ErrorStatus enumeration value: * - SUCCESS: RNG registers are de-initialized * - ERROR: not applicable */ ErrorStatus LL_RNG_DeInit(RNG_TypeDef *RNGx) { /* Check the parameters */ assert_param(IS_RNG_ALL_INSTANCE(RNGx)); /* Enable RNG reset state */ LL_AHB3_GRP1_ForceReset(LL_AHB3_GRP1_PERIPH_RNG); /* Release RNG from reset state */ LL_AHB3_GRP1_ReleaseReset(LL_AHB3_GRP1_PERIPH_RNG); return (SUCCESS); } /** * @brief Initialize RNG registers according to the specified parameters in RNG_InitStruct. * @param RNGx RNG Instance * @param RNG_InitStruct pointer to a LL_RNG_InitTypeDef structure * that contains the configuration information for the specified RNG peripheral. * @retval An ErrorStatus enumeration value: * - SUCCESS: RNG registers are initialized according to RNG_InitStruct content * - ERROR: not applicable */ ErrorStatus LL_RNG_Init(RNG_TypeDef *RNGx, LL_RNG_InitTypeDef *RNG_InitStruct) { /* Check the parameters */ assert_param(IS_RNG_ALL_INSTANCE(RNGx)); assert_param(IS_LL_RNG_CED(RNG_InitStruct->ClockErrorDetection)); /* Clock Error Detection configuration */ MODIFY_REG(RNGx->CR, RNG_CR_CED, RNG_InitStruct->ClockErrorDetection); return (SUCCESS); } /** * @brief Set each @ref LL_RNG_InitTypeDef field to default value. * @param RNG_InitStruct pointer to a @ref LL_RNG_InitTypeDef structure * whose fields will be set to default values. * @retval None */ void LL_RNG_StructInit(LL_RNG_InitTypeDef *RNG_InitStruct) { /* Set RNG_InitStruct fields to default values */ RNG_InitStruct->ClockErrorDetection = LL_RNG_CED_ENABLE; } /** * @} */ /** * @} */ /** * @} */ #endif /* RNG */ /** * @} */ #endif /* USE_FULL_LL_DRIVER */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
the_stack_data/82949646.c
/* ACM 507 Jill Rides Again * mythnc * 2012/01/18 11:15:29 * run time: 0.136 */ #include <stdio.h> #define MAXS 20001 void input(void); void kadane(void); void output(int); int list[MAXS]; int n, maxstart, maxend; int main(void) { int set, i; scanf("%d", &set); for (i = 1; i <= set; i++) { input(); kadane(); output(i); } return 0; } /* input: receive input data */ void input(void) { int i; scanf("%d", &n); for (i = 1; i < n; i++) scanf("%d", &list[i]); } /* kadane: use kadane algorithm to find the maximum sum */ void kadane(void) { int max, start, end; int sum; max = 0; maxstart = maxend = sum = 0; start = 1; for (end = 1; end < n; end++) { sum += list[end]; if (sum > max) { max = sum; maxstart = start; maxend = end; } else if (sum == max && end - start > maxend - maxstart) { maxstart = start; maxend = end; } if (sum < 0) { sum = 0; start = end + 1; } } } /* output: out put result */ void output(int set) { if (maxstart == 0) printf("Route %d has no nice parts\n", set); else printf("The nicest part of route %d is between stops %d and %d\n", set, maxstart, maxend + 1); }
the_stack_data/138701.c
/*Exercise 2 - Selection Write a program to calculate the amount to be paid for a rented vehicle. • Input the distance the van has travelled • The first 30 km is at a rate of 50/= per km. • The remaining distance is calculated at the rate of 40/= per km. e.g. Distance -> 20 Amount = 20 x 50 = 1000 Distance -> 50 Amount = 30 x 50 + (50-30) x 40 = 2300*/ #include <stdio.h> int main() { //variable declaration float distance, rent; printf("Enter the distance the van has travelled(in km) : ");//input distance scanf("%f", &distance);//read distance if(distance <= 30){ rent = distance * 50;//making sure the distance is lessthan or equal to 30km and caculating the relevent rent } else{ rent = 30 * 50 + (distance - 30) * 40;////making sure the distance is greaterthan to 30km and caculating the rent likewise } printf("Amount = %.2f", rent);//display rent return 0; }//end of function main
the_stack_data/95451709.c
/* Taxonomy Classification: 0000000000000031000200 */ /* * WRITE/READ 0 write * WHICH BOUND 0 upper * DATA TYPE 0 char * MEMORY LOCATION 0 stack * SCOPE 0 same * CONTAINER 0 no * POINTER 0 no * INDEX COMPLEXITY 0 constant * ADDRESS COMPLEXITY 0 constant * LENGTH COMPLEXITY 0 N/A * ADDRESS ALIAS 0 none * INDEX ALIAS 0 none * LOCAL CONTROL FLOW 0 none * SECONDARY CONTROL FLOW 0 none * LOOP STRUCTURE 3 while * LOOP COMPLEXITY 1 zero * ASYNCHRONY 0 no * TAINT 0 no * RUNTIME ENV. DEPENDENCE 0 no * MAGNITUDE 2 8 bytes * 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. */ int main(int argc, char *argv[]) { int loop_counter; char buf[10]; loop_counter = 0; while(loop_counter <= 17) { /* BAD */ buf[17] = 'A'; loop_counter++; } return 0; }
the_stack_data/247019387.c
/* * Copyright (C) 2009-2017 National Technology & Engineering Solutions * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with * NTESS, the U.S. Government retains certain rights in this software. * * 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 NTESS 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. * */ /* $Id: wmet.c,v 1.23 2007/02/20 18:06:03 gdsjaar Exp $ */ #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #if defined(CRAY) #include <sys/types.h> #endif #include <stdlib.h> #include <sys/file.h> #include <unistd.h> /* * SUN DEC/ULTRIX ALLIANT : C routines must have underscores * SGI CONVEX : C routines must have underscores * * VAX HP IBM/aix : C routines do not have underscores * * CRAY/UNICOS : C routines must be capitalized, * and no underscores */ #if defined(CRAY) #define vdgnam WMETGN #define cdrofs WMETOF #define cdroff WMETFF #define cdrcfs WMETCF #define wmetbf WMETBF #endif #if !defined(CRAY) && !defined(ADDC_) #define vdgnam wmetgn #define cdrofs wmetof #define cdroff wmetff #define cdrcfs wmetcf #endif #if defined(ADDC_) #define vdgnam wmetgn_ #define cdrofs wmetof_ #define cdroff wmetff_ #define cdrcfs wmetcf_ #define wmetbf wmetbf_ #endif /* #define BUFFER_SIZE 132 */ #define BUFFER_SIZE 8192 extern char *getenv(); static char filename[100]; /* name of file */ static int file_d = -1; /* file descriptor - -1 if file not open */ static char buffer[BUFFER_SIZE]; /* for buffering data for output to file */ static int buff_ptr = 0; /* keep track of buffer space */ #if !defined(__convex__) && !defined(ultrix) && !defined(__osf__) && !defined(linux) && \ !defined(__PARAGON__) && !defined(__hpux) && !defined(interix) && !defined(__CYGWIN__) void vdgnam(name) char *name; { } #endif /* Open file for sequential access. FORTRAN unit number is ignored. */ void cdrofs(ifilcd) int *ifilcd; /* FORTRAN unit number ignored, provide for compatibility */ { char *fname; /* Determine name of file (if specified) in environment variable DUAL_FILENAME */ if ((fname = getenv("DUAL_FILENAME")) == (char *)NULL) strcpy(filename, "dual_device.met"); else strcpy(filename, fname); /* open the file - if it doesn't exist, create it with mode 664 */ /* -- open returns a file descriptor which is stored in the statelist */ /* -- O_TRUNC ??? read/writing??? */ if ((file_d = open(filename, (O_CREAT | O_TRUNC | O_RDWR), 0664)) == -1) { printf("cdrofs: error opening output file\n"); exit(1); } } void cdroff(ifilcd, idum1, idum2, idum3) int *ifilcd, *idum1, *idum2, *idum3; { cdrofs(ifilcd); } /* Close file sequential. FORTRAN unit number is ignored. */ void cdrcfs(ifilcd, eof) int *ifilcd, *eof; { char buf[4]; int istat; /* if eof = 1 then write eof on file */ if (*eof == 1) { *buf = EOF; if ((istat = write(file_d, buf, 4)) == -1) { printf("cdrcfs: error writing EOF\n"); exit(1); } } /* close the file */ close(file_d); file_d = -1; } /* Metafile buffering routine. (device dependent ) Metafile driver passes OUTARY as an integer array, always with 16 bits/word, right justified. This buffering routine assumes 16 bits/word and assumes 8 bit bytes. */ void wmetbf(numwds, outary) int *numwds; /* number of words in OUTARY, 0 = buffer flush */ unsigned outary[]; /* data to be buffered */ { static unsigned mask1 = ~(~0 << 8) << 8; /* mask off higher 8 bits */ static unsigned mask2 = ~(~0 << 8); /* mask off lower 8 bits */ int i; /* loop variable */ int istat; /* check for buffer flush and if there is something to flush */ if (*numwds <= 0 && buff_ptr > 0) { /* write out the data as a byte stream. */ if ((istat = write(file_d, buffer, buff_ptr)) == -1) { printf("wmetbf: write error\n"); } /* end write buffer */ /* reset buff pointer */ buff_ptr = 0; } /* end if buffer flush */ else /* pack outary into buffer */ { if (buff_ptr + *numwds >= BUFFER_SIZE) { /* write out the data as a byte stream. */ if ((istat = write(file_d, buffer, buff_ptr)) == -1) { printf("wmetbf: write error\n"); } /* end write buffer */ /* reset buff pointer */ buff_ptr = 0; } for (i = 0; i < *numwds; i++) { buffer[buff_ptr++] = (outary[i] & mask1) >> 8; buffer[buff_ptr++] = (outary[i] & mask2); } /* end for i=... */ } /* end else */ } /* end wmetbf */
the_stack_data/57950589.c
/* * strndup.c */ #include <string.h> #include <stdlib.h> char *strndup(const char *s, size_t n) { int l = n > strlen(s) ? strlen(s) + 1 : n + 1; char *d = malloc(l); if (d) memcpy(d, s, l); d[n] = '\0'; return d; }
the_stack_data/193893025.c
/* * clang -Wall -Wextra -pedantic -std=c11 serialize.c -o serialize -g */ #include <stdio.h> #include <stdlib.h> typedef struct { int a; double b; } bar; int main(int argc, __attribute__((unused)) char *argv[argc + 1]) { FILE *f; bar b; if ((f = fopen("serialize.data", "rb")) == NULL) { b.a = 5; b.b = 3.4; f = fopen("serialize.data", "wb"); fwrite(&b, 1, sizeof(b), f); fclose(f); } else { fread(&b, 1, sizeof(b), f); fclose(f); printf("%d\n%f\n", b.a, b.b); } return 0; }
the_stack_data/54824371.c
/** * POSXI sem * * */ #include <unistd.h> #include <stdio.h> #include <fcntl.h> #include <sys/stat.h> #include <semaphore.h> #include <stdlib.h> #define SEM_KEY "mysem" int main(void) { sem_t *sem; sem = sem_open(SEM_KEY, O_CREAT, 0666, 0); printf("post sem\n"); sem_post(sem); printf("post sem ok\n"); }
the_stack_data/34512810.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_tolower.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mrouabeh <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/03 09:55:54 by mrouabeh #+# #+# */ /* Updated: 2019/12/02 14:03:58 by mrouabeh ### ########.fr */ /* */ /* ************************************************************************** */ int ft_tolower(int c) { if ('A' <= c && c <= 'Z') c += 32; return (c); }
the_stack_data/12639119.c
/** * C binding */ #include <stdio.h> #include <stdlib.h> #include <string.h> //==========================================================================================// #define list_entry(p, type, mem) \ (type *) ((unsigned long)p - (unsigned long)(&((type *)0)->mem)) struct list_head{ struct list_head *prev; struct list_head *next; }; /* insert @p between @a and @b */ void _add_list(struct list_head *p, struct list_head *a, struct list_head *b) { a->next = p; b->prev = p; p->prev = a; p->next = b; } void add_like_queue(struct list_head *p, struct list_head *cur) { _add_list(p, cur->prev, cur); } void add_like_stack(struct list_head *p, struct list_head *cur) { _add_list(p, cur, cur->next); } /** * Return an array of size *returnSize. * Note: The returned array must be malloced, assume caller calls free(). */ int* selfDividingNumbers(int left, int right, int* returnSize) { int i; int num; int dirty = 0; int count = 0; typedef struct { int dg_val; struct list_head list; }my_digit_t; struct list_head header; // store final dynamic array! struct list_head tmphdr; struct list_head *pos; header.prev = header.next = &header; my_digit_t *ptr = NULL; my_digit_t *ptr2 = NULL; for(i = left; i <= right; i++) { num = i; tmphdr.prev = tmphdr.next = &tmphdr; while(num > 0) { ptr = (my_digit_t *)malloc(sizeof(my_digit_t)); ptr->dg_val = num % 10; add_like_stack(&ptr->list, &tmphdr); num /= 10; } dirty = 0; for(pos = tmphdr.next; pos != &tmphdr; pos = pos->next) { ptr = list_entry(pos, my_digit_t, list); if (ptr->dg_val == 0 || i % ptr->dg_val != 0) { dirty = 1; break; } } if(dirty == 0) { ptr = (my_digit_t *)malloc(sizeof(my_digit_t)); ptr->dg_val = i; add_like_queue(&ptr->list, &header); count++; } } *returnSize = count; i = 0; int *final = (int *)malloc(count*sizeof(int)); for(pos = header.next; pos != &header; pos = pos->next) { ptr = list_entry(pos, my_digit_t, list); final[i++] = ptr->dg_val; } return final; } //==========================================================================================// struct ListNode { int val; struct ListNode *next; }; /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ void deleteNode(struct ListNode* node) { // special, actually free the next-node, not the @node // specify in the parameter! node->val = node->next->val; node->next = node->next->next; free(node->next); } //==========================================================================================// /** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *columnSizes array. * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free(). */ int** flipAndInvertImage(int** A, int ARowSize, int *AColSizes, int** columnSizes, int* returnSize) { } //==========================================================================================// /** * Return an array of size *returnSize. * Note: The returned array must be malloced, assume caller calls free(). */ char** findWords(char** words, int wordsSize, int* returnSize) { int i, j; char *mapping[] = { "qwertyuiop", "asdfghjkl", "zxcvbnm" }; int k, map_idx; int meet; char *pos; struct my_keyboard{ int words_line_no; struct list_head list; }; struct list_head hdr; hdr.prev = hdr.next = &hdr; int line1, line2, line3; int map_line = -1; int map_ok = 1; int count_mapped = 0; for(i = 0; i < wordsSize; i++) { printf("%s\n", words[i]); pos = words[i]; j = 0; map_ok = 1; while(pos[j++] != '\0') { printf("%c ", pos[j - 1]); line1 = line2 = line3 = 0; for(k = 0; k < 3; k++) { map_idx = 0; meet = 0; while(mapping[k][map_idx] != '\0') { if(pos[j - 1] == mapping[k][map_idx]) { meet = 1; break; } map_idx++; } if(meet == 1) { if(map_line == -1){ map_line = k; } else { if (map_line != k) { map_ok = 0; break; } } } } if(map_ok == 0) { break; } } if(map_ok == 1) { // add it! struct my_keyboard *key = (struct my_keyboard *)malloc(sizeof(struct my_keyboard)); key->words_line_no = i; add_like_queue(&key->list, &hdr); count_mapped++; } printf("\n"); } char **ret = (char **)malloc(count_mapped * sizeof(char *)); struct my_keyboard *p; i = 0; struct list_head *ppos; for(ppos = hdr.next; ppos != &hdr; ppos = ppos->next) { p = list_entry(ppos, struct my_keyboard, list); ret[i] = words[p->words_line_no]; i++; } *returnSize = count_mapped; return ret; } //==========================================================================================// typedef struct { int digit; struct list_head list; }digit_t; int print_digit(int num, int *len, struct list_head *hdr) { int count = 0; digit_t *d; while(num > 0) { printf("%d ", num % 10); d = (digit_t *)malloc(sizeof(digit_t)); d->digit = (num % 10); add_like_queue(&d->list, hdr); num = num / 10; count++; } printf("\n"); *len = count; return count; } int do_digit(int num) { struct list_head hdr; hdr.prev = hdr.next = &hdr; struct list_head *pos; int return_len = 0; int i = 0; while(print_digit(num, &return_len, &hdr) > 1) { i = 0; for(pos = hdr.next; pos != &hdr; pos = pos->next) { digit_t *dg = list_entry(pos, digit_t, list); i += dg->digit; } num = i; // do it again! hdr.prev = hdr.next = &hdr; } return num; } int addDigits(int num) { return do_digit(num); } //==========================================================================================// /** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */ // note - the struct already at above code! struct ListNode* middleNode(struct ListNode* head) { int count = 0; int middle; struct ListNode *pos; for(pos = head; pos != NULL; pos = pos->next) { count++; } printf("list node totally %d\n", count); middle = count/2; printf("middle=%d\n", middle); count = 0; for(pos = head; pos != NULL; pos = pos->next) { if(count++ == middle) { break; } } return pos; } void test_middleNode() { struct ListNode hdr; struct ListNode nodes[6]; nodes[0].val = 1; hdr.next = &nodes[0]; nodes[1].val = 2; nodes[0].next = &nodes[1]; nodes[2].val = 3; nodes[1].next = &nodes[2]; nodes[3].val = 4; nodes[2].next = &nodes[3]; nodes[4].val = 5; nodes[3].next = &nodes[4]; nodes[5].val = 6; nodes[4].next = &nodes[5]; nodes[5].next = NULL; struct ListNode *middle = middleNode(hdr.next); struct ListNode *pos; for(pos = middle; pos != NULL; pos = pos->next) { printf("The middle data:%d\n", pos->val); } } //==========================================================================================// int numUniqueEmails(char** emails, int emailsSize) { return 0; } //==========================================================================================// int hammingDistance(int x, int y) { int b = x ^ y; printf("the value:%d %#x\n", b, b); int count = 0; while ( b ) { if( b& 1 ){ ++count; } b>>= 1; } printf("now, the 1 has %d\n", count); return b; } typedef int bool; //==========================================================================================// bool judgeCircle(char* moves) { int a = 0; int b = 0; int c = 0; int d = 0; int i = 0; while(moves[i] != '\0') { switch(moves[i]) { case 'U': a++; break; case 'D': b++; break; case 'L': c++; break; case 'R': d++; break; } i++; } printf("the abcd is %d %d %d %d\n\n", a,b,c,d); return ((a == b) && (c == d)); } //==========================================================================================// bool checkRecord(char* s) { int i = 0; int prev = 0; int a=0,l=0; bool good = 1; while(s[i] != '\0'){ printf("prev = %d, si=%d, a=%d, l=%d\n", prev, s[i], a, l); if (a > 1 || l > 1) { good = 0; break; } if(s[i] == 'A'){ a++; } else if (s[i] == 'L') { printf("now, prev = %d\n", prev); if(prev == 0 || prev == 'L'){ l++; } else { l++; } } else { ; } prev = s[i]; i++; } return good; } //==========================================================================================// int peakIndexInMountainArray(int* A, int ASize) { int i; int fast_i; for(i = 0; i <ASize; i++) { fast_i = i; fast_i ++; if (A[i] > A[fast_i]) { break; } } return i; } //==========================================================================================// int main(int argc, char **argv) { int b; char *a[] = {"abc", "hello"}; // findWords(a, 2, &b); int i = checkRecord("PPAPLLL"); printf("%d\n", i); return 0; }
the_stack_data/152010.c
/* $OpenBSD: rmd_one.c,v 1.9 2015/09/10 15:56:25 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young ([email protected]) * All rights reserved. * * This package is an SSL implementation written * by Eric Young ([email protected]). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson ([email protected]). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. * * 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 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. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by * Eric Young ([email protected])" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson ([email protected])" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 AUTHOR 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. * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] */ #include <stdio.h> #include <string.h> #include <openssl/ripemd.h> #include <openssl/crypto.h> unsigned char *RIPEMD160(const unsigned char *d, size_t n, unsigned char *md) { RIPEMD160_CTX c; static unsigned char m[RIPEMD160_DIGEST_LENGTH]; if (md == NULL) md=m; if (!RIPEMD160_Init(&c)) return NULL; RIPEMD160_Update(&c,d,n); RIPEMD160_Final(md,&c); explicit_bzero(&c,sizeof(c)); return(md); }
the_stack_data/57951601.c
#include<stdio.h> #include<sys/types.h> #include<unistd.h> #include<sys/wait.h> #include<stdlib.h> #include<string.h> #include<ctype.h> #include<math.h> #define BS 20 //--------------Word Count Question--------------- int main() { printf("-----------Word Count from a text file--------------\n"); char wm[BS]; char rm[BS]; int fd[2]; pipe(fd); FILE *fp; pid_t pid = fork(); if(pid<0) printf("failed to fork\n"); else if(pid==0) { char ch[1]; close(fd[0]); fp= fopen("textwc.txt", "r"); while(!feof(fp)) { ch[0] = fgetc(fp); write(fd[1], ch, 1); } fclose(fp); close(fd[1]); } else if(pid>0) { int nc=0, nw=0, nl=0, ns=0; char rec[1]; close(fd[1]); while(read(fd[0], rec, 1)>0) { nc++; //printf("%c-->%d\n", rec[0], nc ); //if(rec[0]=='.') //ns++; if(rec[0]=='\n') nl++; if(rec[0]==' ' || rec[0] == '\n') nw++; } //printf("%c %d\n", rec[0], rec[0] ); //nw++; nc--; close(fd[0]); printf("wc -c: %d\twc -l: %d\twc -w :%d\t\n", nc, nl, nw); return 0; } }
the_stack_data/153398.c
#include<stdio.h> #include<string.h> int tictactoe(); int tictacbot(); int help(); /* * Copyright 2021 © GG * * 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. */ /* * author GG [email protected] * version 1.0.0 */ int main(int argc, char *argv[]) { int status = 0; if (argc == 1) { status = tictactoe(); } else if (argc == 2) { if ((strcmp(argv[1], "-c") == 0) || (strcmp(argv[1], "--computer") == 0)) status = tictacbot(); else if ((strcmp(argv[1], "-p") == 0) || (strcmp(argv[1], "--player") == 0)) status = tictactoe(); else status = help(); } else { status = help(); } return(status); }
the_stack_data/12638291.c
/* Unwinder test program. Copyright (C) 2003-2019 Free Software Foundation, Inc. This file is part of GDB. 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/>. */ #ifdef SYMBOL_PREFIX #define SYMBOL(str) SYMBOL_PREFIX #str #else #define SYMBOL(str) #str #endif void gdb1253 (void); void gdb1718 (void); void gdb1338 (void); void jump_at_beginning (void); void standard (void); void stack_align_ecx (void); void stack_align_edx (void); void stack_align_eax (void); int main (void) { standard (); stack_align_ecx (); stack_align_edx (); stack_align_eax (); gdb1253 (); gdb1718 (); gdb1338 (); jump_at_beginning (); return 0; } /* A normal prologue. */ asm(".text\n" " .align 8\n" SYMBOL (standard) ":\n" " pushl %ebp\n" " movl %esp, %ebp\n" " pushl %edi\n" " int $0x03\n" " leave\n" " ret\n"); /* Relevant part of the prologue from symtab/1253. */ asm(".text\n" " .align 8\n" SYMBOL (gdb1253) ":\n" " pushl %ebp\n" " xorl %ecx, %ecx\n" " movl %esp, %ebp\n" " pushl %edi\n" " int $0x03\n" " leave\n" " ret\n"); /* Relevant part of the prologue from backtrace/1718. */ asm(".text\n" " .align 8\n" SYMBOL (gdb1718) ":\n" " pushl %ebp\n" " movl $0x11111111, %eax\n" " movl %esp, %ebp\n" " pushl %esi\n" " movl $0x22222222, %esi\n" " pushl %ebx\n" " int $0x03\n" " leave\n" " ret\n"); /* Relevant part of the prologue from backtrace/1338. */ asm(".text\n" " .align 8\n" SYMBOL (gdb1338) ":\n" " pushl %edi\n" " pushl %esi\n" " pushl %ebx\n" " int $0x03\n" " popl %ebx\n" " popl %esi\n" " popl %edi\n" " ret\n"); /* The purpose of this function is to verify that, during prologue skip, GDB does not follow a jump at the beginnning of the "real" code. */ asm(".text\n" " .align 8\n" SYMBOL (jump_at_beginning) ":\n" " pushl %ebp\n" " movl %esp,%ebp\n" " jmp .gdbjump\n" " nop\n" ".gdbjump:\n" " movl %ebp,%esp\n" " popl %ebp\n" " ret\n"); asm(".text\n" " .align 8\n" SYMBOL (stack_align_ecx) ":\n" " leal 4(%esp), %ecx\n" " andl $-16, %esp\n" " pushl -4(%ecx)\n" " pushl %ebp\n" " movl %esp, %ebp\n" " pushl %edi\n" " pushl %ecx\n" " int $0x03\n" " popl %ecx\n" " popl %edi\n" " popl %ebp\n" " leal -4(%ecx), %esp\n" " ret\n"); asm(".text\n" " .align 8\n" SYMBOL (stack_align_edx) ":\n" " leal 4(%esp), %edx\n" " andl $-16, %esp\n" " pushl -4(%edx)\n" " pushl %ebp\n" " movl %esp, %ebp\n" " pushl %edi\n" " pushl %ecx\n" " int $0x03\n" " popl %ecx\n" " popl %edi\n" " popl %ebp\n" " leal -4(%edx), %esp\n" " ret\n"); asm(".text\n" " .align 8\n" SYMBOL (stack_align_eax) ":\n" " leal 4(%esp), %eax\n" " andl $-16, %esp\n" " pushl -4(%eax)\n" " pushl %ebp\n" " movl %esp, %ebp\n" " pushl %edi\n" " pushl %ecx\n" " int $0x03\n" " popl %ecx\n" " popl %edi\n" " popl %ebp\n" " leal -4(%eax), %esp\n" " ret\n");
the_stack_data/70451306.c
#include <stdlib.h> #include <stdio.h> #include <stdbool.h> #include <string.h> #include <ctype.h> #include <limits.h> #include <assert.h> /*Get most significant byte from x */ unsigned get_msb(unsigned x) { unsigned shift = (sizeof(unsigned) - 1) << 3; return (x >> shift) & 0xff; } unsigned get_lsb(unsigned x) { return x & 0xff; } /*2.61 */ bool two_sixone(int x) { /*Condition A */ bool condA = !~x; bool condB = !x; bool condC = !(get_lsb(x) ^ 0xff); bool condD = !get_msb(x); return condA || condB || condC || condD; } /* 2.62 */ bool int_shifts_are_arithmetic() { /* 0x1111111111...11 */ int i = -1; return !((i >> 1) ^ i); } void test_two_sixone() { assert(two_sixone(0x0)); assert(two_sixone(-1)); assert(two_sixone(0xff)); /* INT_MIN = 0x10000000...00 */ assert(!two_sixone(INT_MIN)); assert(!two_sixone(INT_MIN + 0xf)); } void test_int_shifts_are_arithmetic() { assert(int_shifts_are_arithmetic()); } int main() { test_two_sixone(); test_int_shifts_are_arithmetic(); }
the_stack_data/195210.c
/** * Name: Charles Cash * Date: September 14, 2016 * Class: COP 2220 * Assignment: Table of squares and cubes */ #include <math.h> #include <stdio.h> /** * Loops through desired numbers * in loops applies pow( num, 2) to get cubes and pow(num, 3) to get cubes */ int main(void){ int num, tempSquare, tempCube; printf("number\tsquare\tcube\n"); for(num = 0; num < 11; num++){ tempSquare = pow(num, 2); tempCube = pow(num, 3); printf("%d\t%d\t%d\n", num, tempSquare, tempCube); } return 0; }
the_stack_data/83565.c
/* $Id: qfits_memory.c,v 1.4 2006/08/24 15:01:56 yjung Exp $ * * This file is part of the ESO QFITS Library * Copyright (C) 2001-2004 European Southern Observatory * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * $Author: yjung $ * $Date: 2006/08/24 15:01:56 $ * $Revision: 1.4 $ * $Name: qfits-6_2_0 $ */ /*----------------------------------------------------------------------------- Includes -----------------------------------------------------------------------------*/ #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> /* #include <string.h> #include <unistd.h> #include <sys/types.h> #include <fcntl.h> #include <sys/mman.h> #include <sys/resource.h> */ /*----------------------------------------------------------------------------*/ /** @brief Map a file's contents to memory as a char pointer. @param name Name of the file to map @param offs Offset to the first mapped byte in file. @param size Returned size of the mapped file in bytes. @param srcname Name of the source file making the call. @param srclin Line # where the call was made. @return A pointer to char, to be freed using qfits_memory_free(). This function takes in input the name of a file. It tries to map the file into memory and if it succeeds, returns the file's contents as a char pointer. It also modifies the input size variable to be the size of the mapped file in bytes. This function is normally never directly called but through the falloc() macro. The offset indicates the starting point for the mapping, i.e. if you are not interested in mapping the whole file but only from a given place. The returned pointer ptr must be deallocated with qfits_memory_fdealloc(ptr) */ /*----------------------------------------------------------------------------*/ char * qfits_memory_falloc( char * name, size_t offs, size_t * size, const char * srcname, int srclin) { char *t; struct stat sta; FILE *thefile; if (stat(name, &sta)==-1) { return NULL; } if ((t = (char *) malloc((sta.st_size-offs+1)*sizeof(char)))) { if ((thefile = fopen(name, "r"))) { fseek(thefile, offs, SEEK_SET); fread(t, sizeof(char), sta.st_size-offs+1, thefile); fclose(thefile); if (size!=NULL) { (*size) = sta.st_size ; } } } return t; } /*----------------------------------------------------------------------------*/ /** @brief Free memory that has been allocated with falloc @param ptr Pointer to free. @param offs Offset to the first mapped byte in file. @param size size to unmap @param filename Name of the file where the dealloc took place. @param lineno Line number in the file. @return void */ /*----------------------------------------------------------------------------*/ void qfits_memory_fdealloc( void * ptr, size_t offs, size_t size, const char * filename, int lineno) { free(ptr); }
the_stack_data/107953694.c
#include <stdio.h> #include <stdlib.h> int K; int nextInt() { int n = 0; int negative = 0; int c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') { negative = 1; c = getchar(); } while (c >= '0' && c <= '9') { n = 10 * n + c - '0'; c = getchar(); } return negative ? -n : n; } void swap(int *a, int *b) { int t = *b; *b = *a; *a = t; } int partition(int *arr, int begin, int end) { int pivot_position = (end + begin) / 2; swap(&arr[begin], &arr[pivot_position]); pivot_position = begin; int i; for (i = begin + 1; i < end; i++) { if (arr[i] < arr[pivot_position]) { swap(&arr[i], &arr[pivot_position]); pivot_position++; swap(&arr[i], &arr[pivot_position]); } } return pivot_position; } void quickselect(int *arr, int begin, int end) { if (end - begin <= 1) return; if (begin > K) return; if (end <= K) return; int pivot_position = partition(arr, begin, end); quickselect(arr, begin, pivot_position); quickselect(arr, pivot_position + 1, end); } int main() { int num; int *data; num = nextInt(); K = nextInt(); data = malloc(sizeof(int) * num); int i; for (i = 0; i < num; i++) { data[i] = nextInt(); } quickselect(data, 0, num); printf("%d\n", data[K]); return 0; }
the_stack_data/162642896.c
#include <stdio.h> #include <stdbool.h> //Booleanos bool bEsAdolecente(int edad); int main(void){ bool bAdolecente = bEsAdolecente(23); if(bAdolecente){ printf("Nini\n"); }else{ printf("Consigue trabajo\n"); }//fin if-else return 0; }//fin int main bool bEsAdolecente(int edad){ if(edad <= 18){ return true; }else{ return false; }//fin if-else }//fin bool
the_stack_data/124896.c
// RUN: cp %s %t // RUN: %clang_cc1 -pedantic -Wall -fixit %t // RUN: %clang_cc1 -fsyntax-only -pedantic -Wall -Werror %t // RUN: %clang_cc1 -E -o - %t | FileCheck %s /* This is a test of the various code modification hints that are provided as part of warning or extension diagnostics. All of the warnings will be fixed by -fixit, and the resulting file should compile cleanly with -Werror -pedantic. */ int printf(char const *, ...); typedef __SIZE_TYPE__ size_t; typedef __INTMAX_TYPE__ intmax_t; typedef __UINTMAX_TYPE__ uintmax_t; typedef __PTRDIFF_TYPE__ ptrdiff_t; void test() { // Basic types printf("%s", (int) 123); printf("abc%0f", "testing testing 123"); printf("%u", (long) -12); printf("%p", 123); printf("%c\n", "x"); printf("%c\n", 1.23); // Larger types printf("%+.2d", (unsigned long long) 123456); printf("%1d", (long double) 1.23); // Flag handling printf("%0+s", (unsigned) 31337); // 0 flag should stay printf("%#p", (void *) 0); printf("% +f", 1.23); // + flag should stay printf("%0-f", 1.23); // - flag should stay // Positional arguments #pragma clang diagnostic push // Don't warn about using positional arguments. #pragma clang diagnostic ignored "-Wformat-non-iso" printf("%1$f:%2$.*3$f:%4$.*3$f\n", 1, 2, 3, 4); #pragma clang diagnostic pop // Precision printf("%10.5d", 1l); // (bug 7394) printf("%.2c", 'a'); // Ignored flags printf("%0-f", 1.23); // Bad length modifiers printf("%hhs", "foo"); #pragma clang diagnostic push // Don't warn about using positional arguments. #pragma clang diagnostic ignored "-Wformat-non-iso" printf("%1$zp", (void *)0); #pragma clang diagnostic pop // Preserve the original formatting for unsigned integers. unsigned long val = 42; printf("%X", val); // size_t, etc. printf("%f", (size_t) 42); printf("%f", (intmax_t) 42); printf("%f", (uintmax_t) 42); printf("%f", (ptrdiff_t) 42); // Look beyond the first typedef. typedef size_t my_size_type; typedef intmax_t my_intmax_type; typedef uintmax_t my_uintmax_type; typedef ptrdiff_t my_ptrdiff_type; typedef int my_int_type; printf("%f", (my_size_type) 42); printf("%f", (my_intmax_type) 42); printf("%f", (my_uintmax_type) 42); printf("%f", (my_ptrdiff_type) 42); printf("%f", (my_int_type) 42); // string printf("%ld", "foo"); // Preserve the original choice of conversion specifier. printf("%o", (long) 42); printf("%u", (long) 42); printf("%x", (long) 42); printf("%X", (long) 42); printf("%i", (unsigned long) 42); printf("%d", (unsigned long) 42); printf("%F", (long double) 42); printf("%e", (long double) 42); printf("%E", (long double) 42); printf("%g", (long double) 42); printf("%G", (long double) 42); printf("%a", (long double) 42); printf("%A", (long double) 42); } int scanf(char const *, ...); void test2() { char str[100]; short shortVar; unsigned short uShortVar; int intVar; unsigned uIntVar; float floatVar; double doubleVar; long double longDoubleVar; long longVar; unsigned long uLongVar; long long longLongVar; unsigned long long uLongLongVar; size_t sizeVar; intmax_t intmaxVar; uintmax_t uIntmaxVar; ptrdiff_t ptrdiffVar; scanf("%lf", str); scanf("%f", &shortVar); scanf("%f", &uShortVar); scanf("%p", &intVar); scanf("%Lf", &uIntVar); scanf("%ld", &floatVar); scanf("%f", &doubleVar); scanf("%d", &longDoubleVar); scanf("%f", &longVar); scanf("%f", &uLongVar); scanf("%f", &longLongVar); scanf("%f", &uLongLongVar); // Some named ints. scanf("%f", &sizeVar); scanf("%f", &intmaxVar); scanf("%f", &uIntmaxVar); scanf("%f", &ptrdiffVar); // Look beyond the first typedef for named integer types. typedef size_t my_size_type; typedef intmax_t my_intmax_type; typedef uintmax_t my_uintmax_type; typedef ptrdiff_t my_ptrdiff_type; typedef int my_int_type; scanf("%f", (my_size_type*)&sizeVar); scanf("%f", (my_intmax_type*)&intmaxVar); scanf("%f", (my_uintmax_type*)&uIntmaxVar); scanf("%f", (my_ptrdiff_type*)&ptrdiffVar); scanf("%f", (my_int_type*)&intVar); // Preserve the original formatting. scanf("%o", &longVar); scanf("%u", &longVar); scanf("%x", &longVar); scanf("%X", &longVar); scanf("%i", &uLongVar); scanf("%d", &uLongVar); scanf("%F", &longDoubleVar); scanf("%e", &longDoubleVar); scanf("%E", &longDoubleVar); scanf("%g", &longDoubleVar); scanf("%G", &longDoubleVar); scanf("%a", &longDoubleVar); scanf("%A", &longDoubleVar); } // Validate the fixes. // CHECK: printf("%d", (int) 123); // CHECK: printf("abc%s", "testing testing 123"); // CHECK: printf("%lu", (long) -12); // CHECK: printf("%d", 123); // CHECK: printf("%s\n", "x"); // CHECK: printf("%f\n", 1.23); // CHECK: printf("%+.2lld", (unsigned long long) 123456); // CHECK: printf("%1Lf", (long double) 1.23); // CHECK: printf("%0u", (unsigned) 31337); // CHECK: printf("%p", (void *) 0); // CHECK: printf("%+f", 1.23); // CHECK: printf("%-f", 1.23); // CHECK: printf("%1$d:%2$.*3$d:%4$.*3$d\n", 1, 2, 3, 4); // CHECK: printf("%10.5ld", 1l); // CHECK: printf("%c", 'a'); // CHECK: printf("%-f", 1.23); // CHECK: printf("%s", "foo"); // CHECK: printf("%1$p", (void *)0); // CHECK: printf("%lX", val); // CHECK: printf("%zu", (size_t) 42); // CHECK: printf("%jd", (intmax_t) 42); // CHECK: printf("%ju", (uintmax_t) 42); // CHECK: printf("%td", (ptrdiff_t) 42); // CHECK: printf("%zu", (my_size_type) 42); // CHECK: printf("%jd", (my_intmax_type) 42); // CHECK: printf("%ju", (my_uintmax_type) 42); // CHECK: printf("%td", (my_ptrdiff_type) 42); // CHECK: printf("%d", (my_int_type) 42); // CHECK: printf("%s", "foo"); // CHECK: printf("%lo", (long) 42); // CHECK: printf("%lu", (long) 42); // CHECK: printf("%lx", (long) 42); // CHECK: printf("%lX", (long) 42); // CHECK: printf("%li", (unsigned long) 42); // CHECK: printf("%ld", (unsigned long) 42); // CHECK: printf("%LF", (long double) 42); // CHECK: printf("%Le", (long double) 42); // CHECK: printf("%LE", (long double) 42); // CHECK: printf("%Lg", (long double) 42); // CHECK: printf("%LG", (long double) 42); // CHECK: printf("%La", (long double) 42); // CHECK: printf("%LA", (long double) 42); // CHECK: scanf("%s", str); // CHECK: scanf("%hd", &shortVar); // CHECK: scanf("%hu", &uShortVar); // CHECK: scanf("%d", &intVar); // CHECK: scanf("%u", &uIntVar); // CHECK: scanf("%f", &floatVar); // CHECK: scanf("%lf", &doubleVar); // CHECK: scanf("%Lf", &longDoubleVar); // CHECK: scanf("%ld", &longVar); // CHECK: scanf("%lu", &uLongVar); // CHECK: scanf("%lld", &longLongVar); // CHECK: scanf("%llu", &uLongLongVar); // CHECK: scanf("%zu", &sizeVar); // CHECK: scanf("%jd", &intmaxVar); // CHECK: scanf("%ju", &uIntmaxVar); // CHECK: scanf("%td", &ptrdiffVar); // CHECK: scanf("%zu", (my_size_type*)&sizeVar); // CHECK: scanf("%jd", (my_intmax_type*)&intmaxVar); // CHECK: scanf("%ju", (my_uintmax_type*)&uIntmaxVar); // CHECK: scanf("%td", (my_ptrdiff_type*)&ptrdiffVar); // CHECK: scanf("%d", (my_int_type*)&intVar); // CHECK: scanf("%lo", &longVar); // CHECK: scanf("%lu", &longVar); // CHECK: scanf("%lx", &longVar); // CHECK: scanf("%lX", &longVar); // CHECK: scanf("%li", &uLongVar); // CHECK: scanf("%ld", &uLongVar); // CHECK: scanf("%LF", &longDoubleVar); // CHECK: scanf("%Le", &longDoubleVar); // CHECK: scanf("%LE", &longDoubleVar); // CHECK: scanf("%Lg", &longDoubleVar); // CHECK: scanf("%LG", &longDoubleVar); // CHECK: scanf("%La", &longDoubleVar); // CHECK: scanf("%LA", &longDoubleVar);
the_stack_data/63023.c
/* { dg-do compile { target powerpc*-*-darwin* } } */ /* { dg-require-effective-target ilp32 } */ /* { dg-skip-if "do not override -mcpu" { powerpc*-*-* } { "-mcpu=*" } { "-mcpu=G3" } } */ /* { dg-options "-mcpu=G3 -funwind-tables" } */ /* { dg-final { scan-assembler "bl save_world" } } */ /* { dg-final { scan-assembler ".byte\t0x6b" } } */ /* Verify that on Darwin, even with -mcpu=G3, __builtin_eh_return saves Altivec registers using save_world, and reports their location in its EH information. */ long offset; void *handler; extern void setup_offset(void); void foo(void) { __builtin_unwind_init (); setup_offset(); __builtin_eh_return (offset, handler); }
the_stack_data/44765.c
#include<stdio.h> #include<stdlib.h> typedef struct tree { int item; struct tree *right,*left; }tree; tree* find(int value,tree* t) { if(t==NULL) printf("not found"); else if(t->item>value) return find(value,t->left); else if (t->item<value) return find(value,t->right); return t; } tree* findmin(tree *t) { if(t==NULL) printf("empty tree"); if(t->left!=NULL) return findmin(t->left); else return t; } tree* findmax(tree *t) { if(t==NULL) printf("not found"); if(t->right==NULL) return t; else return findmax(t->right); } tree* insert(int value, tree* t) { if(t==NULL) { t=(tree*) calloc(1,sizeof(tree)); t->item=value; t->right=t->left=NULL; } else if(t->item>value) t->left=insert(value,t->left); else if(t->item<value) t->right=insert(value,t->right); return t; } tree* delete(int value,tree *t) { tree *temp,*z; if(t==NULL) printf("tree is empty"); else if(t->item>value) t->left=delete(value,t->left); else if(t->item<value) t->right=delete(value,t->right); else if(t->right!=NULL && t->left!=NULL) //two children case { temp=findmin(t->right); t->item=temp->item; t->right=delete(temp->item,t->right); free(temp); } else if(t->right==NULL && t->left==NULL) //zero child case. { z=t; free(z); } else //one child case { if(t->left==NULL) { z=t; t=t->right; free(z); } else { z=t; t=t->left; free(z); } } return t; } int main() { tree *t,*rn; int val,i=1; t=NULL; while(i<=10) { printf("enter value to insert"); scanf("%d",&val); t=insert(val,t); i++; } t=delete(19,t); printf("\ndeleted from tree with root node: %d\n",t->item); rn=find(22,t); printf("node found %d\n",rn->item); rn=findmin(t); printf("min node %d\n",rn->item); rn=findmax(t); printf("max node found %d\n",rn->item); return 0; }
the_stack_data/249267.c
#include <stdint.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #define DEBUG_ENABLED 1 #define KiB 1024 #define MiB 1024 * KiB #define GiB 1024 * MiB const size_t MEM_CHUNK_SIZE = 1 * MiB; const size_t MEM_MAX_SIZE = 1 * GiB; const size_t FILE_MAX_SIZE = 1 * GiB; typedef uint8_t mem_t; mem_t *mem = NULL; char *program = NULL; size_t *loops_stack = NULL; size_t mem_size = 0; size_t program_size = 0; size_t mem_ptr = 0; size_t mem_max = 0; size_t max_nested_loops = 0; size_t loops_stack_ptr = 0; void allocate_memory() { size_t new_size = mem_size + MEM_CHUNK_SIZE; if (new_size > MEM_MAX_SIZE) { fprintf(stderr, "OOM Error: can't allocate more than %zu bytes of memory\n", MEM_MAX_SIZE); exit(EXIT_FAILURE); } void *new_mem = realloc(mem, new_size); if (new_mem == NULL) { fprintf(stderr, "OOM Error: can't allocate %zu bytes of memory\n", new_size); exit(EXIT_FAILURE); } mem = (mem_t *) new_mem; memset(mem + mem_size, 0, new_size - mem_size); mem_size = new_size; } void read_program(char *file_name) { FILE *fd = fopen(file_name, "r"); if (fd == NULL) { fprintf(stderr, "IO Error: unable to open %s\n", file_name); exit(EXIT_FAILURE); } fseek(fd, 0L, SEEK_END); size_t file_size = ftell(fd); fseek(fd, 0L, SEEK_SET); if (file_size > FILE_MAX_SIZE) { fprintf(stderr, "IO Error: file is too big (max: %zu bytes)\n", FILE_MAX_SIZE); exit(EXIT_FAILURE); } program = (char *) calloc(file_size + 1, sizeof(char)); if (program == NULL) { fprintf(stderr, "OOM Error: can't allocate %lu bytes of memory\n", file_size * sizeof(char)); exit(EXIT_FAILURE); } fread(program, sizeof(char), file_size, fd); fclose(fd); program_size = file_size; } void clean_check_program() { size_t k = 0; size_t brackets = 0; for (size_t i = 0; i < program_size; ++i) { char c = program[i]; if (c == '>' || c == '<' || c == '+' || c == '-' || c == ',' || c == '.' || c == '[' || c == ']' || c == '@') { if (k != i) { program[k] = c; } ++k; if (brackets > max_nested_loops) { max_nested_loops = brackets; } if (c == '[') { ++brackets; } else if (c == ']') { --brackets; } } } if (brackets != 0) { fprintf(stderr, "Parsing Error: brackets didn't match\n"); exit(EXIT_FAILURE); } loops_stack = (size_t *) calloc(max_nested_loops, sizeof(size_t)); if (loops_stack == NULL) { fprintf(stderr, "OOM Error: can't allocate %zu bytes of memory\n", max_nested_loops * sizeof(size_t)); exit(EXIT_FAILURE); } program_size = k; } void evaluate_program() { allocate_memory(); size_t i = 0; while (i < program_size) { switch (program[i]) { case '>': ++mem_ptr; if (mem_ptr >= mem_size) { allocate_memory(); } ++i; break; case '<': if (mem_ptr == 0) { fprintf(stderr, "MEM Error: negative pointer\n"); exit(EXIT_FAILURE); } --mem_ptr; ++i; break; case '+': ++mem[mem_ptr]; ++i; break; case '-': --mem[mem_ptr]; ++i; break; case '[': if (mem[mem_ptr] == 0) { size_t brackets = 1; while (brackets != 0) { ++i; if (program[i] == '[') { ++brackets; } else if (program[i] == ']') { --brackets; } } ++i; } else { loops_stack[loops_stack_ptr++] = i; ++i; } break; case ']': i = loops_stack[--loops_stack_ptr]; break; case '.': putc(mem[mem_ptr], stdout); ++i; break; case ',': mem[mem_ptr] = getc(stdin); ++i; break; #ifdef DEBUG_ENABLED case '@': printf("@ debug: "); for (size_t j = 0; j <= mem_max; ++j) { if (j == mem_ptr) { printf("*"); } printf("(%lu: %d)", j, mem[j]); } printf("\n"); ++i; break; #endif default: break; } if (mem_ptr > mem_max) { mem_max = mem_ptr; } } } int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "USAGE: %s file\n", argv[0]); exit(EXIT_FAILURE); } read_program(argv[1]); clean_check_program(); evaluate_program(); putc('\n', stdout); return 0; }
the_stack_data/100040.c
#include <stdio.h> #include <stdlib.h> typedef struct _Stack{ int sizenow; int blocksize; int nowtop; int* pointer; }Stack, *PStack; PStack CreateStack(int blocksize){ PStack stack = NULL; stack = (PStack)malloc(sizeof(Stack)); if(stack){ stack->nowtop = 0; stack->sizenow = stack->blocksize = blocksize; stack->pointer = (int*)malloc(sizeof(int)*blocksize); } return stack; } void CleanupStack(PStack* pstack) { if(pstack && *pstack) { if((*pstack)->pointer) { free((*pstack)->pointer); free(*pstack); *pstack = NULL; } } } void PushIntoStack(PStack stack, int ival){ int* pointer = NULL; int i; if(stack){ if(stack->nowtop >= stack->sizenow){ stack->sizenow += stack->blocksize; pointer = (int*)malloc(sizeof(int)*stack->sizenow); for(i=0;i<stack->nowtop;i++){ pointer[i] = stack->pointer[i]; } free(stack->pointer); stack->pointer = pointer; pointer = NULL; } stack->pointer[stack->nowtop] = ival; stack->nowtop ++; } } int PopFromStack(PStack stack){ int ret = -1; if(stack){ if(stack->nowtop > 0){ ret = stack->pointer[--stack->nowtop]; } } return ret; } void PrintFromTailOfStack(PStack stack){ int i; if(stack){ printf("["); for(i=stack->nowtop-1;i>=0;i--){ printf("%d ", stack->pointer[i]); } printf("]"); } } PStack gstack = NULL; int gistackblocksize = 10; int inputdecint(){ int c; int num = 0; int inputed = 0; while(1){ c = getch(); if((c >= '0') && (c <= '9')){ putchar(c); num = num * 10 + c - '0'; inputed = 1; }else if (((c == '\r') || (c == '\n')) && inputed){ break; }else if((c=='\b') && (inputed)){ putchar('\b'); } } fflush(stdin); return num; } int init() { gstack = CreateStack(gistackblocksize); return gstack != NULL; } void choice_push(){ int ival; if(gstack != NULL){ ival = inputdecint(); printf("\r \r"); printf("%d => ", ival); PrintFromTailOfStack(gstack); PushIntoStack(gstack, ival); printf(" ==>> "); PrintFromTailOfStack(gstack); printf("\n"); } } void choice_pop(){ int ival; if(gstack != NULL){ ival = PopFromStack(gstack); printf("%d <= ", ival); PrintFromTailOfStack(gstack); printf("\n"); } } void cleanup(){ if(gstack != NULL){ CleanupStack(&gstack); } } int main(int argc, char *argv[]) { int c; int exit = 0; if(init()){ while(!exit){ printf("0: exit, 1. push, 2. pop, your choice: "); c = getch() - '0'; switch(c){ case 0:printf("exit\n");exit=1;break; case 1:printf("push\n");choice_push();break; case 2:printf("pop\n");choice_pop();break; } } cleanup(); } return 0; }
the_stack_data/127706.c
/* fips_rsagtest.c */ /* Written by Dr Stephen N Henson ([email protected]) for the OpenSSL * project 2005. */ /* ==================================================================== * Copyright (c) 2005,2007 The OpenSSL Project. 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. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" * * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * [email protected]. * * 5. Products derived from this software may not be called "OpenSSL" * nor may "OpenSSL" appear in their names without prior written * permission of the OpenSSL Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" * * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY * EXPRESSED 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 OpenSSL PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This product includes cryptographic software written by Eric Young * ([email protected]). This product includes software written by Tim * Hudson ([email protected]). * */ #include <stdio.h> #include <ctype.h> #include <string.h> #include <openssl/bio.h> #include <openssl/evp.h> #include <openssl/hmac.h> #include <openssl/err.h> #include <openssl/bn.h> #include <openssl/x509v3.h> #ifndef OPENSSL_FIPS int main(int argc, char *argv[]) { printf("No FIPS RSA support\n"); return(0); } #else #include <openssl/rsa.h> #include "fips_utl.h" int rsa_test(FILE *out, FILE *in); static int rsa_printkey1(FILE *out, RSA *rsa, BIGNUM *Xp1, BIGNUM *Xp2, BIGNUM *Xp, BIGNUM *e); static int rsa_printkey2(FILE *out, RSA *rsa, BIGNUM *Xq1, BIGNUM *Xq2, BIGNUM *Xq); int main(int argc, char **argv) { FILE *in = NULL, *out = NULL; int ret = 1; if(!FIPS_mode_set(1)) { do_print_errors(); goto end; } if (argc == 1) in = stdin; else in = fopen(argv[1], "r"); if (argc < 2) out = stdout; else out = fopen(argv[2], "w"); if (!in) { fprintf(stderr, "FATAL input initialization error\n"); goto end; } if (!out) { fprintf(stderr, "FATAL output initialization error\n"); goto end; } if (!rsa_test(out, in)) { fprintf(stderr, "FATAL RSAGTEST file processing error\n"); goto end; } else ret = 0; end: if (ret) do_print_errors(); if (in && (in != stdin)) fclose(in); if (out && (out != stdout)) fclose(out); return ret; } #define RSA_TEST_MAXLINELEN 10240 int rsa_test(FILE *out, FILE *in) { char *linebuf, *olinebuf, *p, *q; char *keyword, *value; RSA *rsa = NULL; BIGNUM *Xp1 = NULL, *Xp2 = NULL, *Xp = NULL; BIGNUM *Xq1 = NULL, *Xq2 = NULL, *Xq = NULL; BIGNUM *e = NULL; int ret = 0; int lnum = 0; olinebuf = OPENSSL_malloc(RSA_TEST_MAXLINELEN); linebuf = OPENSSL_malloc(RSA_TEST_MAXLINELEN); if (!linebuf || !olinebuf) goto error; while (fgets(olinebuf, RSA_TEST_MAXLINELEN, in)) { lnum++; strcpy(linebuf, olinebuf); keyword = linebuf; /* Skip leading space */ while (isspace((unsigned char)*keyword)) keyword++; /* Look for = sign */ p = strchr(linebuf, '='); /* If no = or starts with [ (for [foo = bar] line) just copy */ if (!p || *keyword=='[') { if (fputs(olinebuf, out) < 0) goto error; continue; } q = p - 1; /* Remove trailing space */ while (isspace((unsigned char)*q)) *q-- = 0; *p = 0; value = p + 1; /* Remove leading space from value */ while (isspace((unsigned char)*value)) value++; /* Remove trailing space from value */ p = value + strlen(value) - 1; while (*p == '\n' || isspace((unsigned char)*p)) *p-- = 0; if (!strcmp(keyword, "xp1")) { if (Xp1 || !do_hex2bn(&Xp1,value)) goto parse_error; } else if (!strcmp(keyword, "xp2")) { if (Xp2 || !do_hex2bn(&Xp2,value)) goto parse_error; } else if (!strcmp(keyword, "Xp")) { if (Xp || !do_hex2bn(&Xp,value)) goto parse_error; } else if (!strcmp(keyword, "xq1")) { if (Xq1 || !do_hex2bn(&Xq1,value)) goto parse_error; } else if (!strcmp(keyword, "xq2")) { if (Xq2 || !do_hex2bn(&Xq2,value)) goto parse_error; } else if (!strcmp(keyword, "Xq")) { if (Xq || !do_hex2bn(&Xq,value)) goto parse_error; } else if (!strcmp(keyword, "e")) { if (e || !do_hex2bn(&e,value)) goto parse_error; } else if (!strcmp(keyword, "p1")) continue; else if (!strcmp(keyword, "p2")) continue; else if (!strcmp(keyword, "p")) continue; else if (!strcmp(keyword, "q1")) continue; else if (!strcmp(keyword, "q2")) continue; else if (!strcmp(keyword, "q")) continue; else if (!strcmp(keyword, "n")) continue; else if (!strcmp(keyword, "d")) continue; else goto parse_error; fputs(olinebuf, out); if (e && Xp1 && Xp2 && Xp) { rsa = FIPS_rsa_new(); if (!rsa) goto error; if (!rsa_printkey1(out, rsa, Xp1, Xp2, Xp, e)) goto error; BN_free(Xp1); Xp1 = NULL; BN_free(Xp2); Xp2 = NULL; BN_free(Xp); Xp = NULL; BN_free(e); e = NULL; } if (rsa && Xq1 && Xq2 && Xq) { if (!rsa_printkey2(out, rsa, Xq1, Xq2, Xq)) goto error; BN_free(Xq1); Xq1 = NULL; BN_free(Xq2); Xq2 = NULL; BN_free(Xq); Xq = NULL; FIPS_rsa_free(rsa); rsa = NULL; } } ret = 1; error: if (olinebuf) OPENSSL_free(olinebuf); if (linebuf) OPENSSL_free(linebuf); if (Xp1) BN_free(Xp1); if (Xp2) BN_free(Xp2); if (Xp) BN_free(Xp); if (Xq1) BN_free(Xq1); if (Xq1) BN_free(Xq1); if (Xq2) BN_free(Xq2); if (Xq) BN_free(Xq); if (e) BN_free(e); if (rsa) FIPS_rsa_free(rsa); return ret; parse_error: fprintf(stderr, "FATAL parse error processing line %d\n", lnum); goto error; } static int rsa_printkey1(FILE *out, RSA *rsa, BIGNUM *Xp1, BIGNUM *Xp2, BIGNUM *Xp, BIGNUM *e) { int ret = 0; BIGNUM *p1 = NULL, *p2 = NULL; p1 = BN_new(); p2 = BN_new(); if (!p1 || !p2) goto error; if (!RSA_X931_derive_ex(rsa, p1, p2, NULL, NULL, Xp1, Xp2, Xp, NULL, NULL, NULL, e, NULL)) goto error; do_bn_print_name(out, "p1", p1); do_bn_print_name(out, "p2", p2); do_bn_print_name(out, "p", rsa->p); ret = 1; error: if (p1) BN_free(p1); if (p2) BN_free(p2); return ret; } static int rsa_printkey2(FILE *out, RSA *rsa, BIGNUM *Xq1, BIGNUM *Xq2, BIGNUM *Xq) { int ret = 0; BIGNUM *q1 = NULL, *q2 = NULL; q1 = BN_new(); q2 = BN_new(); if (!q1 || !q2) goto error; if (!RSA_X931_derive_ex(rsa, NULL, NULL, q1, q2, NULL, NULL, NULL, Xq1, Xq2, Xq, NULL, NULL)) goto error; do_bn_print_name(out, "q1", q1); do_bn_print_name(out, "q2", q2); do_bn_print_name(out, "q", rsa->q); do_bn_print_name(out, "n", rsa->n); do_bn_print_name(out, "d", rsa->d); ret = 1; error: if (q1) BN_free(q1); if (q2) BN_free(q2); return ret; } #endif
the_stack_data/73576626.c
/* * Copyright 2018 The Chromium OS Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifdef DRV_MSM #include <errno.h> #include <msm_drm.h> #include <stdio.h> #include <string.h> #include <sys/mman.h> #include <xf86drm.h> #include "drv_priv.h" #include "helpers.h" #include "util.h" #define DEFAULT_ALIGNMENT 64 static const uint32_t render_target_formats[] = { DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888, DRM_FORMAT_RGB565, DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888 }; static const uint32_t texture_source_formats[] = { DRM_FORMAT_NV12, DRM_FORMAT_R8, DRM_FORMAT_YVU420, DRM_FORMAT_YVU420_ANDROID }; static int msm_init(struct driver *drv) { drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats), &LINEAR_METADATA, BO_USE_RENDER_MASK); drv_add_combinations(drv, texture_source_formats, ARRAY_SIZE(texture_source_formats), &LINEAR_METADATA, BO_USE_TEXTURE_MASK | BO_USE_HW_VIDEO_DECODER); /* Android CTS tests require this. */ drv_add_combination(drv, DRM_FORMAT_BGR888, &LINEAR_METADATA, BO_USE_SW_MASK); return drv_modify_linear_combinations(drv); } /* msm_bo_create will create linear buffers for now */ static int msm_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, uint64_t flags) { struct drm_msm_gem_new req; uint32_t stride, alignw, alignh; int ret; size_t i; /* will get alignment from libadreno eventually */ alignw = ALIGN(width, DEFAULT_ALIGNMENT); alignh = ALIGN(height, DEFAULT_ALIGNMENT); /* HAL_PIXEL_FORMAT_YV12 requires that the buffer's height not be aligned. */ if (bo->format == DRM_FORMAT_YVU420_ANDROID) alignh = bo->height; /* * The extra 12KB at the end are a requirement of the Venus codec driver. * Since |height| will be multiplied by 3/2 in drv_dumb_bo_create, * we multiply this padding by 2/3 here. */ if (bo->format == DRM_FORMAT_NV12) alignh += 2 * DIV_ROUND_UP(0x3000, 3 * alignw); stride = drv_stride_from_format(format, alignw, 0); /* Calculate size and assign stride, size, offset to each plane based on format */ drv_bo_from_format(bo, stride, alignh, format); memset(&req, 0, sizeof(req)); req.flags = MSM_BO_WC | MSM_BO_SCANOUT; req.size = bo->total_size; ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MSM_GEM_NEW, &req); if (ret) { drv_log("DRM_IOCTL_MSM_GEM_NEW failed with %s\n", strerror(errno)); return ret; } /* * Though we use only one plane, we need to set handle for * all planes to pass kernel checks */ for (i = 0; i < bo->num_planes; i++) { bo->handles[i].u32 = req.handle; } return 0; } static void *msm_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t map_flags) { int ret; struct drm_msm_gem_info req; memset(&req, 0, sizeof(req)); req.handle = bo->handles[0].u32; ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MSM_GEM_INFO, &req); if (ret) { drv_log("DRM_IOCLT_MSM_GEM_INFO failed with %s\n", strerror(errno)); return MAP_FAILED; } vma->length = bo->total_size; return mmap(0, bo->total_size, drv_get_prot(map_flags), MAP_SHARED, bo->drv->fd, req.offset); } const struct backend backend_msm = { .name = "msm", .init = msm_init, .bo_create = msm_bo_create, .bo_destroy = drv_gem_bo_destroy, .bo_import = drv_prime_bo_import, .bo_map = msm_bo_map, .bo_unmap = drv_bo_munmap, }; #endif /* DRV_MSM */
the_stack_data/100141706.c
/* * hello.c */ #include <stdio.h> void hello() { printf("Hello World!\n"); }
the_stack_data/92325764.c
#include <stdio.h> int foo (int a, int b) { int c; asm volatile ( "mul %1, %1, %1;" "mul %2, %2, %2;" "add %0, %1, %2;" :"=r"(c) :"r"(a), "r"(b) ); return c; } int main () { printf("%d\n", foo(1, 2)); return 0; }
the_stack_data/148578059.c
#include <stdio.h> #include <assert.h> #define KNRM "\x1B[0m" #define KRED "\x1B[31m" #define KGRN "\x1B[32m" #define KYEL "\x1B[33m" #define KBLU "\x1B[34m" #define KMAG "\x1B[35m" #define KCYN "\x1B[36m" #define KWHT "\x1B[37m"
the_stack_data/232956360.c
#include <stdio.h> #include <time.h> // Table of lengths for ulength. Non-static so ulength can be inlined. const char ulengthTable[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 4, 0 }; // Find length of UTF8 character from first byte, or return 0 for invalid. // Based on https://nullprogram.com/blog/2017/10/06/. extern inline int ulength(char *s) { unsigned char ch = s[0]; return ulengthTable[ch>>3]; } // Get the length of a UTF8 character, or zero for invalid. int ulength2(char *s) { int n = 0x1F00 | ((unsigned char *)s)[0]; n = n >> 3; n = n & (n >> 1); n = n & (n >> 2); n = n & (n >> 4); int m = 1 - ((n>>4)&1) + ((n>>2)&2) + ((n>>2)&1) + ((n>>1)&1) - ((n<<2)&4); return m; } // Linear combo? //a*0 + b*16 + c*24 + d*28 + e*30 + f*31 + g //0->1 => g = 1 //a*0 + b*16 + c*24 + d*28 + e*30 + f*31 + 1 //24->2 => c*24+1 = 2 =? c*24 = 1 => c = 1/24 int main(int argc, char const *argv[]) { int total1 = 0, total2 = 0; char c; clock_t t0, t1, t2; t0 = clock(); for (int i = 0; i < 10000000; i++) { c = i; total1 += ulength(&c); } t1 = clock(); for (int i = 0; i < 10000000; i++) { c = i; total2 += ulength2(&c); } t2 = clock(); printf("%d %d\n", total1, total2); printf("%ld %ld\n", t1-t0, t2-t1); return 0; }
the_stack_data/791976.c
#include <stdio.h> int x=5;//Added X. This lead to some specific lines in the .s file generated int a = 3;//Adding these adds a lot of lines to hello.c int b = 4; int main() { int c = a+b; printf("c is %d\n",c ); if (c%2 == 0) { printf("c is even\n"); } else { printf("c is odd\n"); } printf("%i!\n",x);//Printing the value of X return 0;// When I am running the -o2 flag, i see a lot of comments //generated in the command line but no difference in the output. } //This includes the changes made in class.
the_stack_data/95451642.c
/* Copyright 1992, 1993, 1994, 1995, 1996, 1999, 2004, 2007, 2008 Free Software Foundation, Inc. This file is part of GDB. 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/>. */ /* Simple little program that just generates a core dump from inside some nested function calls. Keep this as self contained as possible, I.E. use no environment resources other than possibly abort(). */ #ifndef __STDC__ #define const /**/ #endif #ifndef HAVE_ABORT #define HAVE_ABORT 1 #endif #if HAVE_ABORT #include <stdlib.h> #define ABORT abort() #else #define ABORT {char *invalid = 0; *invalid = 0xFF;} #endif /* Don't make these automatic vars or we will have to walk back up the stack to access them. */ char *buf1; char *buf2; int coremaker_data = 1; /* In Data section */ int coremaker_bss; /* In BSS section */ const int coremaker_ro = 201; /* In Read-Only Data section */ void func2 (int x) { int coremaker_local[5]; int i; static int y; /* Make sure that coremaker_local doesn't get optimized away. */ for (i = 0; i < 5; i++) coremaker_local[i] = i; coremaker_bss = 0; for (i = 0; i < 5; i++) coremaker_bss += coremaker_local[i]; coremaker_data = coremaker_ro + 1; y = 10 * x; ABORT; } void func1 (int x) { func2 (x * 2); } int main () { func1 (10); return 0; }
the_stack_data/34511780.c
#include<stdio.h> int N(int l,int r,int n,int *arr) { int sum=0; int i; for(i=l;i<=r;i++) sum+=arr[i]%n; sum=sum%n; return sum; } int M(int l,int r,int n,int *arr) { int num=1; int i; for(i=l;i<=r;i++) num=(num*arr[i])%n; num=num%n; return num; } int H(int l,int r,int *arr) { int res=arr[l], i; for(i=l+1;i<=r;i++) res=res^arr[i]; return res; } int main() { int n,K; int arr[100]; int i; scanf("%d%d",&n,&K); for(i=0;i<n;i++) scanf("%d",&arr[i]); for( i=0;i<K;i++) { int l,r; scanf("%d%d",&l,&r); int b=M(l,r,n,arr); int c=N(l,r,n,arr); int temp; if (b>c){ temp =b; b=c; c= temp; } printf("%d\n",H(b,c,arr)); } return 0; }
the_stack_data/125140861.c
#include <stddef.h> #include <stdlib.h> void* malloc(size_t size) { return (size == 12345) ? 0 : calloc(1, size); }
the_stack_data/32950031.c
/** * Return an array of arrays of size *returnSize. * The sizes of the arrays are returned as *returnColumnSizes array. * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free(). */ int** flipAndInvertImage(int** A, int ASize, int* AColSize, int* returnSize, int** returnColumnSizes) { *returnColumnSizes = malloc(sizeof(int)*ASize); *returnSize = ASize; for (int i = 0; i < ASize; i++) { (*returnColumnSizes)[i] = AColSize[i]; int head = 0; int tail = AColSize[i]-1; while (head < tail) { int tmp = A[i][head]; A[i][head] = A[i][tail]^1; A[i][tail] = tmp^1; head++; tail--; } if (head == tail) { A[i][head] ^= 1; } } return A; }
the_stack_data/379790.c
#include <math.h> #include <stdbool.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <sys/time.h> #define MILLION 1000000L int main (int argc, char *argv[]){ int adder = 0; long long catcher; int i = 0; long long increase = -1; int lengthcheck; int lengthcheck2; int loop = 1; int numfind = 0; long long *primegreater; long long primeparameter; long timedif; double timedifout; struct timeval tpend; struct timeval tpstart; if ( argc < 3 ){ fprintf(stderr, " Please enter 1 integer parameter\n"); exit(-1); } else if ( argc > 3 ){ fprintf(stderr, " Please enter 1 integer parameter\n"); exit(-1); } if ( strlen(argv[1]) > 25 ) { fprintf(stderr, " Please do not try to buffer overflow\n"); exit(-1); } if ( strlen(argv[2]) > 25 ) { fprintf(stderr, " Please do not try to buffer overflow\n"); exit(-1); } lengthcheck = strlen(argv[1]); lengthcheck2 = strlen(argv[2]); for ( i = 0; i < lengthcheck; i++){ if ( isalpha(argv[1][i]) ){ fprintf(stderr, " Please only enter digits \n"); exit(-1); } else if ( isdigit(argv[1][i]) ) { } else { fprintf(stderr," Please only enter digits \n"); exit(-1); } } for ( i = 0; i < lengthcheck2; i++){ if ( isalpha(argv[2][i]) ){ fprintf(stderr, " Please only enter digits \n"); exit(-1); } else if ( isdigit(argv[2][i]) ) { } else { fprintf(stderr," Please only enter digits \n"); exit(-1); } } fprintf(stderr, "This is part 3\n"); fprintf(stderr, "Ivan Capistran\n"); fprintf(stderr, "Parameter: %s %s\n" ,argv[1], argv[2]); primeparameter = atoll(argv[1]); numfind = atoi(argv[2]); primegreater = (long long *)malloc(sizeof(long long) * numfind); if (gettimeofday(&tpstart, NULL)) { fprintf(stderr, "Failed to get start time\n"); return 1; } while(numfind > 0){ ++increase; catcher = ( primeparameter + increase ); if ( isPrimeLongLong( catcher )){ primegreater[adder] = (catcher); ++adder; --numfind; } } if (gettimeofday(&tpend, NULL)) { fprintf(stderr, "Failed to get end time\n"); return 1; } /* standard output */ printf("%lld\n", primeparameter); for (i = 0; i < (adder); i++){ printf("%lld\n",primegreater[i]); } /* standard err */ fprintf(stderr,"%lld\n", primeparameter); for (i = 0; i < (adder); i++){ fprintf(stderr,"%lld\n",primegreater[i]); } timedif = MILLION*(tpend.tv_sec - tpstart.tv_sec) + tpend.tv_usec - tpstart.tv_usec; timedifout = timedif/1000000.0; fprintf(stderr,"%.5lf\n", timedifout); free(primegreater); return 0; }
the_stack_data/247018144.c
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/socket.h> #include <sys/un.h> #include <stddef.h> int main() { char file[16] = "foo.socket"; int lfd = socket(AF_UNIX, SOCK_STREAM, 0); if (lfd < 0) { perror("create socket failed ::"); return EXIT_SUCCESS; } struct sockaddr_un un; un.sun_family = AF_UNIX; sprintf(un.sun_path, "%s%05d", "/tmp/", getpid()); int len = offsetof(struct sockaddr_un, sun_path) + strlen(un.sun_path); unlink(un.sun_path); int flag = bind(lfd, (struct sockaddr *)&un, len); if (flag < 0) { perror("bind failed ::"); return EXIT_FAILURE; } memset(&un, 0, sizeof un); un.sun_family = AF_UNIX; strcpy(un.sun_path, file); len = offsetof(struct sockaddr_un, sun_path) + strlen(file); flag = connect(lfd, (struct sockaddr *)&un, len); if (flag < 0) { perror("conn failed ::"); return EXIT_FAILURE; } char buf[1500]; for (;;) { memset(buf, 0, sizeof buf); int n = read(STDIN_FILENO, buf, sizeof buf); if (n <= 0) { break; } send(lfd, buf, n, 0); memset(buf, 0, sizeof buf); n = recv(lfd, buf, sizeof buf, 0); if (n == 0) { break; } write(STDOUT_FILENO, buf, n); } close(lfd); return EXIT_SUCCESS; }
the_stack_data/16735.c
#include<stdio.h> #include<stdlib.h> int main(void) { float dist, consumo, gasto, precolt, lts; printf("informe a distancia percorida: "); scanf("%f",&dist); printf("informe a consumo: "); scanf("%f",&consumo); printf("informe a preco do litro de combutivel: "); scanf("%f",&precolt); gasto=(dist/consumo)*precolt; lts=dist/consumo; printf("maria gatara %.2f litros com um custo total de %.2f reais",lts, gasto); }
the_stack_data/31073.c
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 OR MIT
the_stack_data/3665.c
#include <math.h> double modf(double x, double * e){ int neg = 0; long i; if(x < 0){ neg = 1; x = -x; } i = (long) x; x -= i; if(neg){ x = -x; i = -i; } *e = i; return x; }
the_stack_data/313081.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> int main () { int child, status; printf("Parent $PATH = %s\n", getenv("PATH")); printf("Parent $HOME = %s\n", getenv("HOME")); printf("Parent $USER = %s\n", getenv("USER")); printf("Parent $IFS = %s\n", getenv("IFS")); printf("Parent $ROOT = %s\n", getenv("ROOT")); printf("Parent $TEST = %s\n", getenv("TEST")); putenv("TEST=value"); printf("Parent putenv(TEST=value); now $TEST = %s\n", getenv("TEST")); fflush(stdout); switch(child = fork()){ case 0: printf("Child $PATH = %s\n", getenv("PATH")); printf("Child $HOME = %s\n", getenv("HOME")); printf("Child $USER = %s\n", getenv("USER")); printf("Child $IFS = %s\n", getenv("IFS")); printf("Child $ROOT = %s\n", getenv("ROOT")); printf("Child $TEST = %s\n", getenv("TEST")); exit(0); case -1: printf("FAIL: fork\n"); return 1; default: wait(&status); break; } unsetenv("TEST"); printf("Parent unsetenv(TEST); now $TEST = %s\n", getenv("TEST")); if(status) printf("FAIL: child returned %d\n", status); exit(status); }
the_stack_data/29824330.c
/* @@@@ PROGRAM NAME: knkcch09proj04.c @@@@ FLAGS: -std=c99 @@@@ PROGRAM STATEMENT: Modify Programming Project 16 from Chapter 8 so that it includes the following functions: void read_word(int counts[26]); bool equal_array(int counts1[26], int counts2[26]) ; main will call read_word twice, once for each of the two words entered by the user. As it reads a word. read_word will use the letters in the word to update the counts array, as described in the original project. (main will declare two arrays, one for each word. These arrays are used to track how many times each letter occurs in the words.) main will then call equal_array, passing it the two arrays. equal_array will return true if the elements in the two arrays are identical (indicating that the words are anagrams) and false otherwise. */ #include<stdio.h> #include<ctype.h> //tolower(), isalpha() #include<stdbool.h> //bool, true, false. //----------------------------------------------------------------------------- void read_word(int counts[26]); bool equal_array(int counts1[26], int counts2[26]); //------------------------START OF MAIN()-------------------------------------- int main(void) { printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); int counts[26]={0},counts1[26]={0}; bool flag=0; //getting first word printf("Enter first word: "); read_word(counts); //getting second word printf("Enter second word: "); read_word(counts1); //Check if they are anagrams flag=equal_array(counts,counts1); //Tell if they are anagrams. if(flag) printf("The words are not anagrams."); else printf("The words are anagrams."); printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); return 0; } //-------------------------END OF MAIN()--------------------------------------- void read_word(int counts[26]) { char ch; while((ch=tolower(getchar()))!='\n' && ch!=' ') if(isalpha(ch)) counts[ch-'a']++; } //--------------------------------------------------------------------------- bool equal_array(int counts1[26], int counts2[26]) { bool flag=false; for(short i=0;i<26;i++) if(counts1[i]!=counts2[i]) { flag=true; break; } return flag; } //--------------------------------------------------------------------------- /* OUTPUT: @@@@ Trial1: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Enter first word: net Enter second word: ten The words are anagrams. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@@@ Trial2: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Enter first word: graph Enter second word: rough The words are not anagrams. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@@@ Trial3: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Enter first word: sentence Enter second word: tennice The words are not anagrams. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@@@ Trial4: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Enter first word: note Enter second word: tone The words are anagrams. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ //---------------------------------------------------------------------------
the_stack_data/927838.c
#include <setjmp.h> #include <stdint.h> #include <stdlib.h> #ifdef CFG_TARGET_OS_windows #define platform_setjmp(buf) setjmp(buf) #define platform_longjmp(buf, arg) longjmp(buf, arg) typedef jmp_buf platform_jmp_buf; #elif defined(__clang__) && (defined(__aarch64__) || defined(__s390x__)) // Clang on aarch64 and s390x doesn't support `__builtin_setjmp`, so use //`sigsetjmp` from libc. // // Note that `sigsetjmp` and `siglongjmp` are used here where possible to // explicitly pass a 0 argument to `sigsetjmp` that we don't need to preserve // the process signal mask. This should make this call a bit faster b/c it // doesn't need to touch the kernel signal handling routines. #define platform_setjmp(buf) sigsetjmp(buf, 0) #define platform_longjmp(buf, arg) siglongjmp(buf, arg) typedef sigjmp_buf platform_jmp_buf; #else // GCC and Clang both provide `__builtin_setjmp`/`__builtin_longjmp`, which // differ from plain `setjmp` and `longjmp` in that they're implemented by // the compiler inline rather than in libc, and the compiler can avoid saving // and restoring most of the registers. See the [GCC docs] and [clang docs] // for more information. // // Per the caveat in the GCC docs, this assumes that the host compiler (which // may be compiling for a generic architecture family) knows about all the // register state that Cranelift (which may be specializing for the hardware at // runtime) is assuming is callee-saved. // // [GCC docs]: https://gcc.gnu.org/onlinedocs/gcc/Nonlocal-Gotos.html // [clang docs]: https://llvm.org/docs/ExceptionHandling.html#llvm-eh-sjlj-setjmp #define platform_setjmp(buf) __builtin_setjmp(buf) #define platform_longjmp(buf, arg) __builtin_longjmp(buf, arg) typedef void *platform_jmp_buf[5]; // this is the documented size; see the docs links for details. #endif int wasmtime_setjmp( void **buf_storage, void (*body)(void*, void*), void *payload, void *callee) { platform_jmp_buf buf; if (platform_setjmp(buf) != 0) { return 0; } *buf_storage = &buf; body(payload, callee); return 1; } void wasmtime_longjmp(void *JmpBuf) { platform_jmp_buf *buf = (platform_jmp_buf*) JmpBuf; platform_longjmp(*buf, 1); } #ifdef CFG_TARGET_OS_windows // export required for external access. __declspec(dllexport) #else // Note the `weak` linkage here, though, which is intended to let other code // override this symbol if it's defined elsewhere, since this definition doesn't // matter. // Just in case cross-language LTO is enabled we set the `noinline` attribute // and also try to have some sort of side effect in this function with a dummy // `asm` statement. __attribute__((weak, noinline)) #endif void __jit_debug_register_code() { #ifndef CFG_TARGET_OS_windows asm(""); #endif } struct JITDescriptor { uint32_t version_; uint32_t action_flag_; void* relevant_entry_; void* first_entry_; }; #ifdef CFG_TARGET_OS_windows // export required for external access. __declspec(dllexport) #else // Note the `weak` linkage here which is the same purpose as above. We want to // let other runtimes be able to override this since our own definition isn't // important. __attribute__((weak)) #endif struct JITDescriptor __jit_debug_descriptor = {1, 0, NULL, NULL}; struct JITDescriptor* wasmtime_jit_debug_descriptor() { return &__jit_debug_descriptor; }
the_stack_data/12639052.c
/* crypto/md4/md4.c */ /* Copyright (C) 1995-1998 Eric Young ([email protected]) * All rights reserved. * * This package is an SSL implementation written * by Eric Young ([email protected]). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson ([email protected]). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. * * 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 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. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by * Eric Young ([email protected])" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson ([email protected])" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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 AUTHOR 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. * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] */ #include <stdio.h> #include <stdlib.h> #include <openssl/md4.h> #define BUFSIZE 1024*16 void do_fp(FILE *f); void pt(unsigned char *md); #ifndef _OSD_POSIX int read(int, void *, unsigned int); #endif int main(int argc, char **argv) { int i,err=0; FILE *IN; if (argc == 1) { do_fp(stdin); } else { for (i=1; i<argc; i++) { IN=fopen(argv[i],"r"); if (IN == NULL) { perror(argv[i]); err++; continue; } printf("MD4(%s)= ",argv[i]); do_fp(IN); fclose(IN); } } exit(err); } void do_fp(FILE *f) { MD4_CTX c; unsigned char md[MD4_DIGEST_LENGTH]; int fd; int i; static unsigned char buf[BUFSIZE]; fd=fileno(f); MD4_Init(&c); for (;;) { i=read(fd,buf,BUFSIZE); if (i <= 0) break; MD4_Update(&c,buf,(unsigned long)i); } MD4_Final(&(md[0]),&c); pt(md); } void pt(unsigned char *md) { int i; for (i=0; i<MD4_DIGEST_LENGTH; i++) printf("%02x",md[i]); printf("\n"); }
the_stack_data/1264325.c
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/types.h> #include <sys/wait.h> int main() { int n = 5; int i = 0; pid_t pid = 0; for (i = 0;i < 5;++i) { pid = fork(); if (pid == 0) { printf("i am child,pid = %d,ppid = %d\n",getpid(), getppid()); break; } } if (i == 5) { while (1){ pid_t wpid = waitpid(-1, NULL,WNOHANG); if (wpid == -1) break; else if (wpid > 0){ printf("waitpid wpid= %d\n",wpid); } } while(1){ sleep(1); } } if (i < 5) { printf("i am child\n"); } return 0; }
the_stack_data/1024177.c
float q_sqrt(float number){ long i; float x2, y; const float threehalfs = 1.5F; x2 = number * 0.5F; y = number; i = *(long *) &y; i = 0x5f3759df - (i >> 1); y = * (float *) &i; y = y * (threehalfs - (x2 * y * y)); return y; }
the_stack_data/514477.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/x509.h> #include <openssl/hmac.h> void hmac_sha256( const unsigned char *text, /* pointer to data stream */ int text_len, /* length of data stream */ const unsigned char *key, /* pointer to authentication key */ int key_len, /* length of authentication key */ void *digest) /* caller digest to be filled in */ { #ifdef EVP_MAX_MD_SIZE unsigned int result_len; unsigned char result[EVP_MAX_MD_SIZE]; HMAC(EVP_sha256(), key, strlen(key), text, strlen(text), result, &result_len); memcpy(digest, result, result_len); #else unsigned char k_ipad[65]; /* inner padding - * key XORd with ipad */ unsigned char k_opad[65]; /* outer padding - * key XORd with opad */ unsigned char tk[SHA256_DIGEST_LENGTH]; unsigned char tk2[SHA256_DIGEST_LENGTH]; unsigned char bufferIn[1024]; unsigned char bufferOut[1024]; int i; /* if key is longer than 64 bytes reset it to key=sha256(key) */ if ( key_len > 64 ) { SHA256( key, key_len, tk ); key = tk; key_len = SHA256_DIGEST_LENGTH; } /* * the HMAC_SHA256 transform looks like: * * SHA256(K XOR opad, SHA256(K XOR ipad, text)) * * where K is an n byte key * ipad is the byte 0x36 repeated 64 times * opad is the byte 0x5c repeated 64 times * and text is the data being protected */ /* start out by storing key in pads */ memset( k_ipad, 0, sizeof k_ipad ); memset( k_opad, 0, sizeof k_opad ); memcpy( k_ipad, key, key_len ); memcpy( k_opad, key, key_len ); /* XOR key with ipad and opad values */ for ( i = 0; i < 64; i++ ) { k_ipad[i] ^= 0x36; k_opad[i] ^= 0x5c; } /* * perform inner SHA256 */ memset( bufferIn, 0x00, 1024 ); memcpy( bufferIn, k_ipad, 64 ); memcpy( bufferIn + 64, text, text_len ); SHA256( bufferIn, 64 + text_len, tk2 ); /* * perform outer SHA256 */ memset( bufferOut, 0x00, 1024 ); memcpy( bufferOut, k_opad, 64 ); memcpy( bufferOut + 64, tk2, SHA256_DIGEST_LENGTH ); SHA256( bufferOut, 64 + SHA256_DIGEST_LENGTH, digest ); #endif } #ifdef TEST #ifdef _MSC_VER #define Thread __declspec( thread ) #else #define Thread #endif void printdump( const char *buffer, size_t sz ) { int i, c; unsigned char buf[80]; for ( i = 0; (unsigned)i < sz; i++ ) { if ( (i != 0) && (i % 16 == 0) ) { buf[16] = NUL; fprintf( stderr, " %s\n", buf ); } if ( i % 16 == 0 ) fprintf( stderr, "%08x:", &buffer[i] ); c = buffer[i] & 0xFF; if ( (c >= ' ') && (c <= 0x7E) ) buf[i % 16] = (unsigned char)c; else buf[i % 16] = '.'; fprintf( stderr, " %02x", c & 0xFF ); } if ( i % 16 == 0 ) buf[16] = NUL; else { buf[i % 16] = NUL; for ( i = i % 16; i < 16; i++ ) fputs( " ", stderr ); } fprintf( stderr, " %s\n", buf ); } static char b[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /* 0000000000111111111122222222223333333333444444444455555555556666 */ /* 0123456789012345678901234567890123456789012345678901234567890123 */ char * base64( const unsigned char *src, size_t sz ) { unsigned char *pp, *p, *q; Thread static unsigned char *qq = NULL; size_t i, safe = sz; if ( qq ) { free( qq ); qq = NULL; } if ( !src || (sz == 0) ) return ( NULL ); if ( (sz % 3) == 1 ) { p = (unsigned char *)malloc( sz + 2 ); if ( !p ) return ( NULL ); memcpy( p, src, sz ); p[sz] = p[sz + 1] = '='; sz += 2; } else if ( (sz % 3) == 2 ) { p = (unsigned char *)malloc( sz + 1 ); if ( !p ) return ( NULL ); memcpy( p, src, sz ); p[sz] = '='; sz++; } else p = (unsigned char *)src; q = (unsigned char *)malloc( (sz / 3) * 4 + 2 ); if ( !q ) { if ( p != src ) free( p ); return ( NULL ); } pp = p; qq = q; for ( i = 0; i < sz; i += 3 ) { q[0] = b[(p[0] & 0xFC) >> 2]; q[1] = b[((p[0] & 0x03) << 4) | ((p[1] & 0xF0) >> 4)]; q[2] = b[((p[1] & 0x0F) << 2) | ((p[2] & 0xC0) >> 6)]; q[3] = b[p[2] & 0x3F]; p += 3; q += 4; } *q = NUL; if ( (safe % 3) == 1 ) { *(q - 1) = '='; *(q - 2) = '='; } if ( (safe % 3) == 2 ) *(q - 1) = '='; if ( pp != src ) free( pp ); return ( (char *)qq ); } /* int main( int argc, char *argv[] ) { // via http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?rest-signature.html // see also: // http://chalow.net/2009-05-09-1.html // http://d.hatena.ne.jp/zorio/20090509/1241886502 char *p; const char *key = "1234567890"; char req[2048]; char message[10240]; char digest[BUFSIZ]; sprintf( req, "AWSAccessKeyId=%s&" "ItemId=%s&" "Operation=%s&" "ResponseGroup=%s&" "Service=%s&" "Timestamp=%s&" "Version=%s", "00000000000000000000", "0679722769", "ItemLookup", "ItemAttributes%2COffers%2CImages%2CReviews", "AWSECommerceService", "2009-01-01T12%3A00%3A00Z", "2009-01-06" ); sprintf( message, "%s\n" "%s\n" "%s\n" "%s", "GET", "webservices.amazon.com", "/onca/xml", req ); memset( digest, 0x00, BUFSIZ ); hmac_sha256( message, strlen(message), key, strlen(key), digest ); printdump( digest, BUFSIZ ); { int c; fputs( ": ", stderr ); c = getchar(); } // 35 a7 1e f9 4d c0 cf 83 a1 37 bb 48 4a a8 2c d6 // f7 4b 04 70 44 8a 35 9c 05 e0 aa 2f 9c 4d f7 18 p = base64( digest, SHA256_DIGEST_LENGTH ); if ( p ) printf( "RESULT: %s\n", p ); { int c; fputs( ": ", stderr ); c = getchar(); } // RESULT: Nace+U3Az4OhN7tISqgs1vdLBHBEijWcBeCqL5xN9xg= /* // via http://stackoverflow.com/questions/699041/hmacsha256-in-php-and-c-differ string password = "Password"; string filename = "Filename"; var hmacsha256 = new HMACSHA256(Encoding.UTF8.GetBytes(password)); hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(filename)); foreach(byte test in hmacsha256.Hash){ Console.Write(test.ToString("X2")); } // 5FE2AE06FF9828B33FE304545289A3F590BFD948CA9AB731C980379992EF41F1 */ /* key = "Password"; sprintf( message, "Filename" ); memset( digest, 0x00, BUFSIZ ); hmac_sha256( message, strlen(message), key, strlen(key), digest ); printdump( digest, BUFSIZ ); { int c; fputs( ": ", stderr ); c = getchar(); } // 5f e2 ae 06 ff 98 28 b3 3f e3 04 54 52 89 a3 f5 // 90 bf d9 48 ca 9a b7 31 c9 80 37 99 92 ef 41 f1 p = base64( digest, SHA256_DIGEST_LENGTH ); if ( p ) printf( "RESULT: %s\n", p ); { int c; fputs( ": ", stderr ); c = getchar(); } // X+KuBv+YKLM/4wRUUomj9ZC/2UjKmrcxyYA3mZLvQfE= return ( 0 ); }*/ #endif
the_stack_data/63168.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 'pre_decrement_long.cl' */ source_code = read_buffer("pre_decrement_long.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, "pre_decrement_long", &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_long *src_0_host_buffer; src_0_host_buffer = malloc(num_elem * sizeof(cl_long)); for (int i = 0; i < num_elem; i++) src_0_host_buffer[i] = (cl_long)(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_long), 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_long), src_0_host_buffer, 0, NULL, NULL); if (ret != CL_SUCCESS) { printf("error: call to 'clEnqueueWriteBuffer' failed\n"); exit(1); } /* Create host dst buffer */ cl_long *dst_host_buffer; dst_host_buffer = malloc(num_elem * sizeof(cl_long)); memset((void *)dst_host_buffer, 1, num_elem * sizeof(cl_long)); /* Create device dst buffer */ cl_mem dst_device_buffer; dst_device_buffer = clCreateBuffer(context, CL_MEM_WRITE_ONLY, num_elem *sizeof(cl_long), 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), &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_long), 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_long)); 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); } /* 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/107952457.c
/*++ * testharness.c * * Simple test harness for running BLISS tests. * * Copyright © 2013, Matthew Madison. * All rights reserved. * Distributed under license. See LICENSE.TXT for details. *-- */ #include <stdio.h> #include <stdlib.h> #include <stdarg.h> int TEST_INIT(void); void RUNTEST(int); void TEST_PRINTF (const char *fmt, ...) { va_list ap; va_start(ap, fmt); vprintf(fmt, ap); } int main (int argc, char *argv[]) { int i, numtests; numtests = TEST_INIT(); if (argc < 2) { for (i = 1; i <= numtests; i++) RUNTEST(i); return 0; } for (i = 1; i < argc; i++) { int tno = atoi(argv[i]); if (tno >= 1 && tno <= numtests) { RUNTEST(tno); } } return 0; }
the_stack_data/50137246.c
// RUN: rm -rf %t* // RUN: 3c -base-dir=%S -addcr -alltypes -output-dir=%t.checkedALL %s %S/arrinstructcallermulti2.c -- // RUN: 3c -base-dir=%S -addcr -output-dir=%t.checkedNOALL %s %S/arrinstructcallermulti2.c -- // RUN: %clang -working-directory=%t.checkedNOALL -c arrinstructcallermulti1.c arrinstructcallermulti2.c // RUN: FileCheck -match-full-lines -check-prefixes="CHECK_NOALL","CHECK" --input-file %t.checkedNOALL/arrinstructcallermulti1.c %s // RUN: FileCheck -match-full-lines -check-prefixes="CHECK_ALL","CHECK" --input-file %t.checkedALL/arrinstructcallermulti1.c %s // RUN: 3c -base-dir=%S -alltypes -output-dir=%t.checked %S/arrinstructcallermulti2.c %s -- // RUN: 3c -base-dir=%t.checked -alltypes -output-dir=%t.convert_again %t.checked/arrinstructcallermulti1.c %t.checked/arrinstructcallermulti2.c -- // RUN: test ! -f %t.convert_again/arrinstructcallermulti1.c // RUN: test ! -f %t.convert_again/arrinstructcallermulti2.c /******************************************************************************/ /*This file tests three functions: two callers bar and foo, and a callee sus*/ /*In particular, this file tests: how the tool behaves when there is an array field within a struct*/ /*For robustness, this test is identical to arrinstructprotocaller.c and arrinstructcaller.c except in that the callee and callers are split amongst two files to see how the tool performs conversions*/ /*In this test, foo and sus will treat their return values safely, but bar will not, through invalid pointer arithmetic, an unsafe cast, etc.*/ /******************************************************************************/ #include <stddef.h> #include <stdlib.h> #include <stdio.h> #include <string.h> struct general { int data; struct general *next; //CHECK: _Ptr<struct general> next; }; struct warr { int data1[5]; //CHECK_NOALL: int data1[5]; //CHECK_ALL: int data1 _Checked[5]; char *name; //CHECK: _Ptr<char> name; }; struct fptrarr { int *values; //CHECK: _Ptr<int> values; char *name; //CHECK: _Ptr<char> name; int (*mapper)(int); //CHECK: _Ptr<int (int)> mapper; }; struct fptr { int *value; //CHECK: _Ptr<int> value; int (*func)(int); //CHECK: _Ptr<int (int)> func; }; struct arrfptr { int args[5]; //CHECK_NOALL: int args[5]; //CHECK_ALL: int args _Checked[5]; int (*funcs[5])(int); //CHECK_NOALL: int (*funcs[5])(int); //CHECK_ALL: _Ptr<int (int)> funcs _Checked[5]; }; static int add1(int x) { //CHECK: static int add1(int x) _Checked { return x + 1; } static int sub1(int x) { //CHECK: static int sub1(int x) _Checked { return x - 1; } static int fact(int n) { //CHECK: static int fact(int n) _Checked { if (n == 0) { return 1; } return n * fact(n - 1); } static int fib(int n) { //CHECK: static int fib(int n) _Checked { if (n == 0) { return 0; } if (n == 1) { return 1; } return fib(n - 1) + fib(n - 2); } static int zerohuh(int n) { //CHECK: static int zerohuh(int n) _Checked { return !n; } static int *mul2(int *x) { //CHECK: static _Ptr<int> mul2(_Ptr<int> x) _Checked { *x *= 2; return x; } struct warr *sus(struct warr *, struct warr *); //CHECK_NOALL: _Ptr<struct warr> sus(struct warr *x : itype(_Ptr<struct warr>), _Ptr<struct warr> y); //CHECK_ALL: _Array_ptr<struct warr> sus(struct warr *x : itype(_Ptr<struct warr>), _Array_ptr<struct warr> y); struct warr *foo() { //CHECK: _Ptr<struct warr> foo(void) { struct warr *x = malloc(sizeof(struct warr)); //CHECK: _Ptr<struct warr> x = malloc<struct warr>(sizeof(struct warr)); struct warr *y = malloc(sizeof(struct warr)); //CHECK_NOALL: _Ptr<struct warr> y = malloc<struct warr>(sizeof(struct warr)); //CHECK_ALL: struct warr *y = malloc<struct warr>(sizeof(struct warr)); struct warr *z = sus(x, y); //CHECK_NOALL: _Ptr<struct warr> z = sus(x, y); //CHECK_ALL: _Ptr<struct warr> z = sus(x, _Assume_bounds_cast<_Array_ptr<struct warr>>(y, byte_count(0))); return z; } struct warr *bar() { //CHECK_NOALL: struct warr *bar(void) : itype(_Ptr<struct warr>) { //CHECK_ALL: _Ptr<struct warr> bar(void) { struct warr *x = malloc(sizeof(struct warr)); //CHECK: _Ptr<struct warr> x = malloc<struct warr>(sizeof(struct warr)); struct warr *y = malloc(sizeof(struct warr)); //CHECK_NOALL: _Ptr<struct warr> y = malloc<struct warr>(sizeof(struct warr)); //CHECK_ALL: struct warr *y = malloc<struct warr>(sizeof(struct warr)); struct warr *z = sus(x, y); //CHECK_NOALL: struct warr *z = ((struct warr *)sus(x, y)); //CHECK_ALL: _Array_ptr<struct warr> z = sus(x, _Assume_bounds_cast<_Array_ptr<struct warr>>(y, byte_count(0))); z += 2; return z; }
the_stack_data/115765386.c
/* Unwinder test program. Copyright 2003-2019 Free Software Foundation, Inc. This file is part of GDB. 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/>. */ #ifdef SYMBOL_PREFIX #define SYMBOL(str) SYMBOL_PREFIX #str #else #define SYMBOL(str) #str #endif void trap (void) { asm ("int $0x03"); } /* Make sure that main directly follows a function without an epilogue. */ asm(".text\n" " .align 8\n" " .globl gdb1435\n" "gdb1435:\n" " pushl %ebp\n" " mov %esp, %ebp\n" " call " SYMBOL (trap) "\n" " .globl " SYMBOL (main) "\n" SYMBOL (main) ":\n" " pushl %ebp\n" " mov %esp, %ebp\n" " call gdb1435\n");
the_stack_data/104827127.c
#include<stdio.h> #include<stdlib.h> #include<math.h> int main(){ int lato;//lato del quadrato int I;//contatore int k;//contatore printf("\n Programma che tramite l'uso del carattere * disegna un quadrato"); do{ //tramite questo do-while faccio inserire all'utente la lunghezza del lato compresa tra 1 e 20 printf("\n inserire il lato del quadrato(1-20): "); scanf("%d",&lato); }while((lato<0)||(lato>20)); I=0; while(I<lato){ printf("*"); k=1; while(k<lato-1){ if((I=0)||(I=(lato-1))){ printf("*"); }else{ printf(" "); } k++; } printf("*"); printf("\n"); I++; } }
the_stack_data/104828131.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> #include <stdint.h> #include <sys/time.h> #include <sys/stat.h> /* Nome funzione Assembly dichiarata con extern */ extern int postfix(char* input,char* output); /* ************************************* */ char* retrieve_input(char* filename); // funzione di supporto che prende in input il nome del file // e restituisce la stringa da passare come parametro alla funzione assembly void write_output(char* filename,char* output); // Scrive il risultato su un file di output int main(int argc, char *argv[]) { char* input; char output[12]; //********************************** // Recupera input dal file //********************************** input = retrieve_input(argv[1]); //********************************** // Chiamata assembly //********************************** postfix(input,output); //printf("%s\n",output); // printf di controllo //********************************** // Scrivi output della funzione sul file //********************************** write_output(argv[2],output); return 0; } void write_output(char* filename, char* output){ FILE *outputFile = fopen (filename, "w"); // apre il file da scrivere. Se non esiste lo crea. Se esiste lo resetta fprintf (outputFile, "%s", output); // scrive sul file fclose (outputFile); // chiude il file } char* retrieve_input(char* filename){ FILE *inputFile = fopen(filename, "r"); char* input_string; // stringa di input struct stat st; // struttura speciale per recuperare info sui file size_t size; // st_size, parte della struttura st, contiene la dimensione del file in byte. if (inputFile == 0) { fprintf(stderr, "failed to open the input file. Syntax ./test <input_file> <output_file>\n"); exit(1); } stat(filename, &st); // funzione per recuperare info del file e salvarle in struttura st size = st.st_size+1; // st_size, parte della struttura st, contiene la dimensione del file char* parameter = malloc(sizeof(char)*(size)); // alloco la stringa in base alla dimesione. +1 per tappo fine stringa fgets(parameter, (sizeof(char)*(size)), inputFile); // copio dal file alla stringa, parametro della funzione assembly parameter[strlen(parameter)]='\0'; // tappo! fclose(inputFile); return parameter; }
the_stack_data/142001.c
#include <stdio.h> #include <stdlib.h> void tempo_espera(int process[], int duracao[], int tempo_f[], int qntP, int espera[], int waitT[], int quantum) { int auxD[qntP]; int auxT[qntP]; for (int c=0; c<qntP; c++) { auxD[c] = duracao[c]; auxT[c] = process[c]; espera[c] = 0; waitT[c] = 0; } int tempo = 0; while (1) { int check = 0; for (int c=0; c<qntP; c++) { if (auxD[c] > 0) { check = 1; if (auxD[c] > quantum) { if (espera[c] == 0) {espera[c] = tempo;} tempo += quantum; auxD[c] -= quantum; for (int i=0; i<qntP;i++){ if (i!=c){waitT[c] += quantum;} } } else { tempo = tempo + auxD[c]; tempo_f[c] = tempo; auxD[c] = 0; for (int i=0;i<qntP;i++){ if (i!=c){waitT[c] += auxD[c];} } } } } if (check == 0) { break; } } }
the_stack_data/998120.c
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <inttypes.h> /*#include <windows.h> void color(int t,int f) { HANDLE H=GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(H,f*16+t); } */ int main(void) { //color(10,0); printf("Ce programme calcule la somme des entiers de 1 a la limite que vous aurez specifiee.\n"); uint32_t i=1; uint64_t sum=0; uint32_t lim; printf("Limite="); scanf("%" SCNu32,&lim); while(i<=lim){ //printf("%" SCNu64 "+%" SCNu32 "=%" SCNu64 "\n",sum,i,sum+i); sum+=i; i++; } printf("Somme des entiers de 1 a %" SCNu32 "=%" SCNu64,lim,sum); return EXIT_SUCCESS; }
the_stack_data/603986.c
/*b03902052 顏廷宇*/ #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <string.h> int main(int argc, char *argv[]) { if(argc < 3) fprintf(stderr, "player doesn't have enough file\n"); char string[100]; sprintf(string, "host%s_%s.FIFO", argv[1], argv[2]); int a_fd = open(string, O_RDONLY); //make a fifo!!! char s[100]; sprintf(s, "host%s.FIFO", argv[1]); int p_fd = open(s, O_WRONLY); FILE *fp = fdopen(p_fd, "w"); for(int time = 0; time < 10; time++) { char money[100] = {0}; read(a_fd, money, 100); int m; if(strcmp(argv[2], "A") == 0){ int m; sscanf(money, "%d %*s %*s %*s\n", &m); char pass[100]; if(time == 0 || time == 3 || time == 6) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m-3); else if(time == 1 || time == 4 || time == 7) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m-2); else if(time == 2 || time == 5 || time == 8) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m-1); else if(time == 9) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m); fputs(pass, fp); fflush(fp); } else if(strcmp(argv[2], "B") == 0){ int m; sscanf(money, "%*s %d %*s %*s\n", &m); int tmp = 0; char pass[100]; if(time == 0 || time == 3 || time == 6) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m-3); else if(time == 1 || time == 4 || time == 7) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m-2); else if(time == 2 || time == 5 || time == 8) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m-1); else if(time == 9) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m); fputs(pass, fp); fflush(fp); } else if(strcmp(argv[2], "C") == 0){ int m; sscanf(money, "%*s %*s %d %*s\n", &m); int tmp = 0; char pass[100]; if(time == 0 || time == 3 || time == 6) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m-3); else if(time == 1 || time == 4 || time == 7) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m-2); else if(time == 2 || time == 5 || time == 8) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m-1); else if(time == 9) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m); fputs(pass, fp); fflush(fp); } else if(strcmp(argv[2], "D") == 0){ int m; sscanf(money, "%*s %*s %*s %d", &m); int tmp = 0; char pass[100]; if(time == 0 || time == 3 || time == 6) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m-3); else if(time == 1 || time == 4 || time == 7) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m-2); else if(time == 2 || time == 5 || time == 8) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m-1); else if(time == 9) sprintf(pass, "%s %s %d\n", argv[2], argv[3], m); fputs(pass, fp); fflush(fp); } else fprintf(stderr, "fuck\n"); } exit(0); return 0; }
the_stack_data/225143737.c
#include <assert.h> #include <stddef.h> int main() { int foo; int *bar = &foo; if (bar) { } else { assert(0); } int *baz = NULL; if (baz) { assert(0); } return 0; }
the_stack_data/11074435.c
#include <stdio.h> #include <signal.h> #include <string.h> #include <stdlib.h> #include <unistd.h> void terminal_handler(int signum); void quit_handler(int signum); #define INPUTLEN 100 int main(void) { signal(SIGINT, terminal_handler); signal(SIGQUIT, quit_handler); char buf[INPUTLEN]; int nchar; do { nchar = read(0, buf, INPUTLEN); if (nchar == -1) { perror("read"); exit(1); } buf[nchar] = '\0'; printf("input: %d, %s\n", nchar, buf); } while (strncmp(buf, "quit", 4) != 0); exit(0); } void terminal_handler(int signum) { printf("in terminal\n"); sleep(2); printf("out terminal\n"); } void quit_handler(int signum) { printf("in quit\n"); sleep(6); printf("out quit\n"); }
the_stack_data/978466.c
#include <stdio.h> #include <stdlib.h> #define _GNU_SOURCE #include <getopt.h> static void do_head(FILE *f, long nlines); #define DEFAULT_N_LINES 10 static struct option longopts[] = { {"lines", required_argument, NULL, 'n'}, {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0} }; int main(int argc, char *argv[]) { int opt; long nlines = DEFAULT_N_LINES; // process options while ((opt = getopt_long(argc, argv, "n:", longopts, NULL)) != -1) { switch (opt) { case 'n': nlines = atoi(optarg); break; case 'h': fprintf(stdout, "Usage: %s [-n LINES] [file ...]\n", argv[0]); exit(0); case '?': fprintf(stderr, "Usage: %s [-n LINES] [file ...]\n", argv[0]); exit(1); } } if (optind == argc) { do_head(stdin, nlines); exit(0); } int i; for (i = optind; i < argc; i++) { FILE *f; f = fopen(argv[i], "r"); if (!f) { perror(argv[i]); exit(1); } do_head(f, nlines); fclose(f); } exit(0); } static void do_head(FILE *f, long nlines) { int c; if (nlines <= 0) { return; } while ((c = getc(f)) != EOF) { if (putchar(c) < 0) { exit(1); } if (c == '\n') { nlines--; if (nlines == 0) { return; } } } }
the_stack_data/143389.c
/*| headers |*/ /*| object_like_macros |*/ /*| types |*/ /*| structures |*/ /*| extern_declarations |*/ /*| function_declarations |*/ /*| state |*/ /*| function_like_macros |*/ #define preempt_disable() #define preempt_enable() #define preempt_clear() #define precondition_preemption_disabled() #define postcondition_preemption_disabled() /*| functions |*/ /*| public_functions |*/ /*| public_privileged_functions |*/
the_stack_data/50138250.c
#include <stdio.h> int main(void) { printf("Hallo Welt\n"); system("Pause"); return 0; }
the_stack_data/93574.c
asm ( ".section .text /*[SLICE_EXTRA] comes with 00000000*/\n" ".globl _section1 /*[SLICE_EXTRA] comes with 00000000*/\n" "_section1: /*[SLICE_EXTRA] comes with 00000000*/\n" "mov, ecx, 32 /*[SLICE_EXTRA] comes with b7e8c19a*/\n" "mov, edi, ecx /*[SLICE_EXTRA] comes with b7e8c19a*/\n" "mov, #sze1[0xbfffef74], 24 /*[SLICE] #00000000 [SLICE_INFO] comes with b7e8c19a*/\n" "mov, #sze1[0xbfffef74], dx /*[SLICE] #00000000 [SLICE_INFO] comes with b7e8c19a*/\n" );
the_stack_data/412414.c
#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define STEPS 10 #define MAXLEN 64 #define N 128 #define AT(i, j) ((i) * (N) + (j)) static void step(char rules[N * N], long elements[N], long pairs[N * N], long work[N * N]) { size_t lhs1, lhs2, rhs; for (lhs1 = 0; lhs1 < N; ++lhs1) { for (lhs2 = 0; lhs2 < N; ++lhs2) { if (!rules[AT(lhs1, lhs2)]) continue; rhs = rules[AT(lhs1, lhs2)]; elements[rhs] += pairs[AT(lhs1, lhs2)]; work[AT(lhs1, rhs)] += pairs[AT(lhs1, lhs2)]; work[AT(rhs, lhs2)] += pairs[AT(lhs1, lhs2)]; } } } int main(void) { char buf[MAXLEN] = {'\0'}, seq[MAXLEN] = {'\0'}, *tok1, *tok2; char rules[N * N] = {'\0'}; int part = 0; long elements[N] = {0}, pairs[N * N] = {0}, work[N * N]; long min = LONG_MAX; long max = LONG_MIN; size_t i, seqlen = 0; while (!feof(stdin)) { if (fgets(buf, sizeof(buf), stdin)) { if (buf[0] == '\n') { part = 1; continue; } if (!part) { seqlen = strlen(buf); if (buf[seqlen - 1] == '\n') buf[--seqlen] = '\0'; memcpy(seq, buf, seqlen); } else { if (!(tok1 = strtok(buf, " -> "))) { fprintf(stderr, "cannot parse the first token\n"); exit(EXIT_FAILURE); } if (strlen(tok1) != 2) { fprintf(stderr, "the first token must consist of 2 letters\n"); exit(EXIT_FAILURE); } if (!(tok2 = strtok(NULL, " -> "))) { fprintf(stderr, "cannot parse the second token\n"); exit(EXIT_FAILURE); } if (strlen(tok2) == 2 && tok2[1] == '\n') tok2[1] = '\0'; if (strlen(tok2) != 1) { fprintf(stderr, "the second token must consist of 1 letter\n"); exit(EXIT_FAILURE); } rules[AT(tok1[0], tok1[1])] = tok2[0]; } } } for (i = 0; i < seqlen; ++i) { elements[(size_t) seq[i]]++; if (i < seqlen - 1) pairs[AT((size_t) seq[i], (size_t) seq[i + 1])]++; } for (i = 0, part = 0; i < STEPS; ++i, part = !part) { if (!part) { memset(work, 0x00, sizeof(work)); step(rules, elements, pairs, work); } else { memset(pairs, 0x00, sizeof(pairs)); step(rules, elements, work, pairs); } } for (i = 0; i < N; ++i) { if (elements[i] > 0 && elements[i] > max) max = elements[i]; if (elements[i] > 0 && elements[i] < min) min = elements[i]; } printf("%ld\n", max - min); return EXIT_SUCCESS; }
the_stack_data/134887.c
#include <stdio.h> int main(void){ return 0; }
the_stack_data/1084923.c
int main() { int a = 68; a = 5 >> a >> 56; return a; }
the_stack_data/176705082.c
#include <stdio.h> #include <stdlib.h> #define SUB_N 128 #define ROI_ROW_START 88 #define ROI_COL_START 146 int mean(int n, int x[]) { int temp; int i; temp = 0; for (i = 0; i < n; ++i) { temp += x[i]; } return (temp/n); } int main() { int i, j, t; FILE *ifp, *ofp; int frameId = 0; char file_name[100]; unsigned char buffer[420]; static unsigned char img[315][420]; static unsigned char imgS[30][144][144]; int val; int element[30]; static int template[144][144]; char temp_str[9]; for (t = 0; t < 990; t += 33) { sprintf(file_name, "../image/image_f%03d.bin", t); if (!(ifp = fopen(file_name, "rb"))) { printf("File image_f%03d.bin cannot be opened for read.\n", 0); return -1; } for (j = 0; j < 315; ++j) { fread(buffer, 1, 420, ifp); for (i = 0; i < 420; ++i) { img[j][i] = buffer[i]; } } for (j = 0; j < 144; ++j) { for (i = 0; i < 144; ++i) { imgS[t/33][j][i] = img[j+ROI_ROW_START-8-1][i+ROI_COL_START-8-1]; } } fclose(ifp); } // Compute template for (j = 0; j < 144; ++j) { for (i = 0; i < 144; ++i) { for (t = 0; t < 30; ++t) { element[t] = imgS[t][j][i]; } template[j][i] = mean(30, element); } } // Check correctness of the template. /* for (j = 0; j < 5; ++j) { for (i = 0; i < 5; ++i) { printf("%d,", template[j][i]); } printf("\n"); } return 0; */ // Open img_mem.coe file for write. if (!(ofp = fopen("tml_mem.coe", "w"))) { printf("File tml_mem.coe cannot be opened for write.\n"); return -1; } fprintf(ofp, "memory_initialization_radix=16;\n"); fprintf(ofp, "memory_initialization_vector=\n"); for (j = 0; j < 144; ++j) { for (i = 0; i < 144; i += 4) { sprintf(temp_str, "%02x%02x%02x%02x", template[j][i+3], template[j][i+2], template[j][i+1], template[j][i+0]); fprintf(ofp, "%s\n", temp_str); } } fclose(ofp); // Open template.txt for template store if (!(ofp = fopen("template.txt","w"))) { printf("File template.txt cannot be opened for write.\n"); return -1; } for (j = 0; j < 144; ++j) { for (i = 0; i < 144; ++i) { fprintf(ofp, "%d\n", template[j][i]); } } fclose(ofp); printf("Processing complete.\n"); return 0; }
the_stack_data/73032.c
#include <unistd.h> int main (void) { for (;;) fork (); return (0); }
the_stack_data/218892226.c
// RUN: %clang_cc1 -triple i386-pc-elfiamcu -emit-llvm %s -o - | FileCheck %s // Structure that is more than 8 byte. struct Big { double a[10]; }; // Empty union with zero size must be returned as void. union U1 { } u1; // Too large union (80 bytes) must be returned via memory. union U2 { struct Big b; } u2; // Must be returned in register. union U3 { int x; } u3; // Empty struct with zero size, must be returned as void. struct S1 { } s1; // Must be returend in register. struct S2 { int x; } s2; // CHECK: [[UNION1_TYPE:%.+]] = type {} // CHECK: [[UNION2_TYPE:%.+]] = type { [[STRUCT_TYPE:%.+]] } // CHECK: [[STRUCT_TYPE]] = type { [10 x double] } // CHECK: [[UNION3_TYPE:%.+]] = type { i32 } // CHECK: [[STRUCT1_TYPE:%.+]] = type {} // CHECK: [[STRUCT2_TYPE:%.+]] = type { i32 } union U1 foo1() { return u1; } union U2 foo2() { return u2; } union U3 foo3() { return u3; } struct S1 bar1() { return s1; } struct S2 bar2() { return s2; } struct S1 bar3(union U1 u) { return s1; } // CHECK: define void @foo1() // CHECK: define void @foo2([[UNION2_TYPE]]* noalias sret %{{.+}}) // CHECK: define i32 @foo3() // CHECK: define void @bar1() // CHECK: define i32 @bar2() // CHECK: define void @bar3() void run() { union U1 x1 = foo1(); union U2 x2 = foo2(); union U3 x3 = foo3(); struct S1 y1 = bar1(); struct S2 y2 = bar2(); struct S1 y3 = bar3(x1); // CHECK: [[X1:%.+]] = alloca [[UNION1_TYPE]] // CHECK: [[X2:%.+]] = alloca [[UNION2_TYPE]] // CHECK: [[X3:%.+]] = alloca [[UNION3_TYPE]] // CHECK: [[Y1:%.+]] = alloca [[STRUCT1_TYPE]] // CHECK: [[Y2:%.+]] = alloca [[STRUCT2_TYPE]] // CHECK: call void @foo1() // CHECK: call void @foo2([[UNION2_TYPE]]* sret [[X2]]) // CHECK: {{.+}} = call i32 @foo3() // CHECK: call void @bar1() // CHECK: {{.+}} = call i32 @bar2() // CHECK: call void @bar3() }
the_stack_data/54774.c
/* Example code for Exercises in C. Copyright 2014 Allen Downey License: Creative Commons Attribution-ShareAlike 3.0 */ #include <stdio.h> #include <stdlib.h> #include <assert.h> void free_anything(int *p) { free(p); } int read_element(int *array, int index) { int x = array[index]; return x; } int main() { int never_allocated; int *free_twice = malloc(sizeof (int)); int *use_after_free = malloc(sizeof (int)); int *never_free = malloc(sizeof (int)); int array1[100]; int *array2 = malloc(100 * sizeof (int)); // valgrind does not bounds-check static arrays read_element(array1, 0); read_element(array1, 99); // but it does bounds-check dynamic arrays read_element(array2, 0); read_element(array2, 99); free(array2); // and it catches use after free free(use_after_free); //*use_after_free = 17; // Don't change values after it is freed! // never_free is definitely lost *never_free = 17; free(never_free); // Release this variable from its eternal prison // the following line would generate a warning // free(&never_allocated); // but this one doesn't //free_anything(&never_allocated); //free(free_twice); free(free_twice); return 0; }