file
stringlengths
18
26
data
stringlengths
2
1.05M
the_stack_data/107090.c
//Option 12 #include <stdio.h> #include <stdlib.h> const int size = 4; int main() { //Task1 int a[] = {0, 3, 5, 7}; int *ptr[size], i; if (ptr == NULL) { printf("____TASK 1____"); printf("Can't run the program !"); exit(0); } printf("\n____TASK 1____"); for (i = 0; i < size; i++) { ptr[i] = &a[i]; } //print the array on the the screen printf("\nThe array is: "); for (i = 0; i < size; i++) { printf(" %d ", *ptr[i]); } //Task 2 int *ptr_arr, num_element; printf("\n\n\n____TASK 2____"); //memory allocation ptr_arr = (int *)calloc(8, sizeof(int)); printf("\nEnter the number of the element of the array: "); scanf("%d", &num_element); for (size_t j = 0; j < num_element; j++) { printf("ptr_arr[%d] = ", j); scanf("%d", (ptr_arr + j)); } printf("The array is: "); for (size_t j = 0; j < num_element; j++) { printf(" %d ", *(ptr_arr + j)); } //release memoryz free(ptr_arr); return 0; }
the_stack_data/28267.c
#include <stdio.h> #include <stdlib.h> // This solution is a C solution working only on positive numbers. int main() { int k; scanf("%d", &k); printf("%d\n", abs(k)*2); return 0; }
the_stack_data/32949225.c
/* * Author: Bjorn Gustavsson * Purpose: A port program to be used for testing the open_port bif. */ #ifdef VXWORKS #include <vxWorks.h> #include <taskVarLib.h> #include <taskLib.h> #include <sysLib.h> #include <string.h> #include <ioLib.h> #endif #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #ifndef __WIN32__ #include <unistd.h> #ifdef VXWORKS #include "reclaim.h" #include <sys/times.h> #else #include <sys/time.h> #endif #define O_BINARY 0 #define _setmode(fd, mode) #endif #ifdef __WIN32__ #include "windows.h" #include "winbase.h" #endif #ifdef VXWORKS #define REDIR_STDOUT(fd) ioTaskStdSet(0, 1, fd); #else #define REDIR_STDOUT(fd) if (dup2(fd, 1) == -1) { \ fprintf(stderr, "%s: failed to duplicate handle %d to 1: %d\n", \ port_data->progname, fd, errno); \ exit(1); \ } #endif #ifdef VXWORKS #define MAIN(argc, argv) port_test(argc, argv) #else #define MAIN(argc, argv) main(argc, argv) #endif extern int errno; typedef struct { char* progname; /* Name of this program (from argv[0]). */ int header_size; /* Number of bytes in each packet header: * 1, 2, or 4, or 0 for a continous byte stream. */ int fd_from_erl; /* File descriptor from Erlang. */ int fd_to_erl; /* File descriptor to Erlang. */ unsigned char* io_buf; /* Buffer for file i/o. */ int io_buf_size; /* Current size of i/o buffer. */ int delay_mode; /* If set, this program will wait 5 seconds * after reading the header for a packet * before reading the rest. */ int break_mode; /* If set, this program will close standard * input, which should case broken pipe * error in the writer. */ int quit_mode; /* If set, this program will exit * just after reading the packet header. */ int slow_writes; /* Writes back the reply in chunks with * sleeps in between. The value is the * chunk size. If 0, normal writes are done. */ char* output_file; /* File into which the result will be written. */ int no_packet_loop; /* No packet loop. */ int limited_bytecount; /* Only answer a limited number of bytes, then exit (stream mode) */ } PORT_TEST_DATA; PORT_TEST_DATA* port_data; static int packet_loop(); static void reply(); static void write_reply(); static void ensure_buf_big_enough(); static int readn(); static void delay(unsigned ms); static void dump(unsigned char* buf, int sz, int max); static void replace_stdout(char* filename); static void generate_reply(char* spec); #ifndef VXWORKS #ifndef HAVE_STRERROR extern int sys_nerr; #ifndef sys_errlist /* sys_errlist is sometimes defined to call a function on win32 */ extern char *sys_errlist[]; #endif char* strerror(err) int err; { static char msgstr[1024]; if (err == 0) { msgstr[0] = '\0'; } else if (0 < err && err < sys_nerr) { strcpy(msgstr, sys_errlist[err]); } else { sprintf(msgstr, "Unknown error %d", err); } return msgstr; } #endif #endif MAIN(argc, argv) int argc; char *argv[]; { int ret; #ifdef VXWORKS if(taskVarAdd(0, (int *)&port_data) != OK) { fprintf(stderr, "Can't do taskVarAdd in port_test\n"); exit(1); } #endif if((port_data = (PORT_TEST_DATA *) malloc(sizeof(PORT_TEST_DATA))) == NULL) { fprintf(stderr, "Couldn't malloc for port_data"); exit(1); } port_data->header_size = 0; port_data->io_buf_size = 0; port_data->delay_mode = 0; port_data->break_mode = 0; port_data->quit_mode = 0; port_data->slow_writes = 0; port_data->output_file = NULL; port_data->no_packet_loop = 0; port_data->progname = argv[0]; port_data->fd_from_erl = 0; port_data->fd_to_erl = 1; port_data->limited_bytecount = 0; _setmode(0, _O_BINARY); _setmode(1, _O_BINARY); while (argc > 1 && argv[1][0] == '-') { switch (argv[1][1]) { case 'b': /* Break mode. */ port_data->break_mode = 1; break; case 'c': /* Close standard output. */ close(port_data->fd_to_erl); break; case 'd': /* Delay mode. */ port_data->delay_mode = 1; break; case 'e': port_data->fd_to_erl = 2; break; case 'h': /* Header size for packets. */ switch (argv[1][2]) { case '0': port_data->header_size = 0; break; case '1': port_data->header_size = 1; break; case '2': port_data->header_size = 2; break; case '4': port_data->header_size = 4; break; case '\0': fprintf(stderr, "%s: missing header size for -h\n", port_data->progname); return 1; default: fprintf(stderr, "%s: illegal packet header size: %c\n", port_data->progname, argv[1][2]); return 1; } break; case 'l': port_data->limited_bytecount = atoi(argv[1]+2); break; case 'n': /* No packet loop. */ port_data->no_packet_loop = 1; break; case 'o': /* Output to file. */ port_data->output_file = argv[1]+2; break; case 'q': /* Quit mode. */ port_data->quit_mode = 1; break; case 'r': /* Generate reply. */ generate_reply(argv[1]+2); break; case 's': /* Slow writes. */ port_data->slow_writes = atoi(argv[1]+2); break; default: fprintf(stderr, "Unrecognized switch: %s\n", argv[1]); free(port_data); exit(1); } argc--, argv++; } if (argc > 1) { /* XXX Add error printout here */ } if (port_data->no_packet_loop){ free(port_data); exit(0); } /* * If an output file was given, let it replace standard output. */ if (port_data->output_file) replace_stdout(port_data->output_file); ret = packet_loop(); if(port_data->io_buf_size > 0) free(port_data->io_buf); free(port_data); return ret; } static int packet_loop(void) { int total_read = 0; port_data->io_buf = (unsigned char*) malloc(1); /* Allocate once, so realloc works (SunOS) */ for (;;) { int packet_length; /* Length of current packet. */ int i; int bytes_read; /* Number of bytes read. */ /* * Read the packet header, if any. */ if (port_data->header_size == 0) { if(port_data->limited_bytecount && port_data->limited_bytecount - total_read < 4096) packet_length = port_data->limited_bytecount - total_read; else packet_length = 4096; } else { ensure_buf_big_enough(port_data->header_size); if (readn(port_data->fd_from_erl, port_data->io_buf, port_data->header_size) != port_data->header_size) { return(1); } /* * Get the length of this packet. */ packet_length = 0; for (i = 0; i < port_data->header_size; i++) packet_length = (packet_length << 8) | port_data->io_buf[i]; } /* * Delay if delay mode. */ if (port_data->delay_mode) { delay(5000L); } if (port_data->quit_mode) { return(1); } else if (port_data->break_mode) { close(0); delay(32000L); return(1); } /* * Read the packet itself. */ ensure_buf_big_enough(packet_length+4+1); /* At least five bytes. */ port_data->io_buf[4] = '\0'; if (port_data->header_size == 0) { bytes_read = read(port_data->fd_from_erl, port_data->io_buf+4, packet_length); if (bytes_read == 0) return(1); if (bytes_read < 0) { fprintf(stderr, "Error reading %d bytes: %s\n", packet_length, strerror(errno)); return(1); } total_read += bytes_read; } else { bytes_read = readn(port_data->fd_from_erl, port_data->io_buf+4, packet_length); if (bytes_read != packet_length) { fprintf(stderr, "%s: couldn't read packet of length %d\r\n", port_data->progname, packet_length); return(1); } } /* * Act on the command. */ if (port_data->header_size == 0) { reply(port_data->io_buf+4, bytes_read); if(port_data->limited_bytecount && port_data->limited_bytecount <= total_read){ delay(5000L); return(0); } } else { switch (port_data->io_buf[4]) { case 'p': /* ping */ port_data->io_buf[4] = 'P'; reply(port_data->io_buf+4, bytes_read); break; case 'e': /* echo */ reply(port_data->io_buf+4, bytes_read); break; case 'x': /* exit */ return(5); break; default: fprintf(stderr, "%s: bad packet of length %d received: ", port_data->progname, bytes_read); dump(port_data->io_buf+4, bytes_read, 10); fprintf(stderr, "\r\n"); return(1); } } } } /* * Sends a packet back to Erlang. */ static void reply(buf, size) char* buf; /* Buffer with reply. The four bytes before * this pointer must be allocated so that * this function can put the header there. */ int size; /* Size of buffer to send. */ { int n; /* Temporary to hold size. */ int i; /* Loop counter. */ /* * Fill the header starting with the least significant byte * (this will work even if there is no header). */ n = size; for (i = 0; i < port_data->header_size; i++) { *--buf = (char) n; /* Store least significant byte. */ n = n >> 8; } size += port_data->header_size; write_reply(buf, size); } static void write_reply(buf, size) char* buf; /* Buffer with reply. Must contain header. */ int size; /* Size of buffer to send. */ { int n; /* Temporary to hold size. */ if (port_data->slow_writes <= 0) { /* Normal, "fast", write. */ write(port_data->fd_to_erl, buf, size); } else { /* * Write chunks with delays in between. */ while (size > 0) { n = size > port_data->slow_writes ? port_data->slow_writes : size; write(port_data->fd_to_erl, buf, n); size -= n; buf += n; if (size) delay(500L); } } } /* * Ensures that our I/O buffer is big enough for the packet to come. */ static void ensure_buf_big_enough(size) int size; /* Needed size of buffer. */ { if (port_data->io_buf_size >= size) return; port_data->io_buf = (unsigned char*) realloc(port_data->io_buf, size); if (port_data->io_buf == NULL) { fprintf(stderr, "%s: insufficient memory for i/o buffer of size %d\n", port_data->progname, size); exit(1); } port_data->io_buf_size = size; } /* * Reads len number of bytes. */ static int readn(fd, buf, len) int fd; /* File descriptor to read from. */ unsigned char *buf; /* Store in this buffer. */ int len; /* Number of bytes to read. */ { int n; /* Byte count in last read call. */ int sofar; /* Bytes read so far. */ sofar = 0; do { if ((n = read(fd, buf+sofar, len-sofar)) <= 0) /* error or EOF in read */ return(n); sofar += n; } while (sofar < len); return sofar; } static void replace_stdout(filename) char* filename; /* Name of file to replace standard output. */ { int fd; fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0666); if (fd == -1) { fprintf(stderr, "%s: failed to open %s for writing: %d\n", port_data->progname, filename, errno); exit(1); } REDIR_STDOUT(fd); } static void dump(buf, sz, max) unsigned char* buf; int sz; int max; { int i, imax; char comma[5]; comma[0] = ','; comma[1] = '\0'; if (!sz) return; if (sz > max) imax = max; else imax = sz; for (i=0; i<imax; i++) { if (i == imax-1) { if (sz > max) strcpy(comma, ",..."); else comma[0] = 0; } if (isdigit(buf[i])) { fprintf(stderr, "%u%s", (int)(buf[i]), comma); } else { if (isalpha(buf[i])) { fprintf(stderr, "%c%s", buf[i], comma); } else { fprintf(stderr, "%u%s", (int)(buf[i]), comma); } } } } /* * Delays (sleeps) the given number of milli-seconds. */ static void delay(unsigned ms) { #ifdef VXWORKS taskDelay((sysClkRateGet() * ms) / 1000); #else #ifdef __WIN32__ Sleep(ms); #else struct timeval t; t.tv_sec = ms/1000; t.tv_usec = (ms % 1000) * 1000; select(0, NULL, NULL, NULL, &t); #endif #endif } /* * Generates a reply buffer given the specification. * * <packet-bytes>,<start-character>,<increment>,<size> * * Where: * <packet-bytes> is */ static void generate_reply(spec) char* spec; /* Specification for reply. */ { typedef struct item { int start; /* Start character. */ int incrementer; /* How much to increment. */ size_t size; /* Size of reply buffer. */ } Item; Item items[256]; int last; int cur; size_t total_size; char* buf; /* Reply buffer. */ char* s; /* Current pointer into buffer. */ int c; total_size = 0; last = 0; while (*spec) { char* colon; items[last].incrementer = 1; items[last].start = *spec++; items[last].size = atoi(spec); total_size += port_data->header_size+items[last].size; last++; if ((colon = strchr(spec, ':')) == NULL) { spec += strlen(spec); } else { *colon = '\0'; spec = colon+1; } } buf = (char *) malloc(total_size); if (buf == NULL) { fprintf(stderr, "%s: insufficent memory for reply buffer of size %d\n", port_data->progname, total_size); exit(1); } s = buf; for (cur = 0; cur < last; cur++) { int i; size_t n; n = items[cur].size; s += port_data->header_size; for (i = 0; i < port_data->header_size; i++) { *--s = (char) n; /* Store least significant byte. */ n = n >> 8; } s += port_data->header_size; c = items[cur].start; for (i = 0; i < items[cur].size; i++) { *s++ = c; c++; if (c > 126) { c = 33; } } } write_reply(buf, s-buf); }
the_stack_data/82950519.c
/* * Lyceum-2.46 * * Copyright (c) 2004 phish <[email protected]> * 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 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. * */ #include <stdio.h> #include <stdlib.h> #include <string.h> char retbuf[BUFSIZ]; char * s_icmp_pkt (char *msg) { extern unsigned long realip; snprintf (retbuf, BUFSIZ, "1:%ld:%s", realip, msg); retbuf[strlen (retbuf)] = '\0'; return (char *) retbuf; } char * c_icmp_pkt (char *msg, unsigned long zombie_ip) { extern unsigned long realip; if (zombie_ip) snprintf (retbuf, BUFSIZ, "0:%ld:%ld:%s", realip, zombie_ip, msg); else snprintf (retbuf, BUFSIZ, "0:%ld:0:%s", realip, msg); retbuf[strlen (retbuf)] = '\0'; return (char *) retbuf; } #ifdef _CLIENT_ char * get_icmp_proto_by_name (int type) { switch (type) { case 0: return "Echo Reply"; case 3: return "Destination Unreachable"; case 4: return "Source Quench"; case 5: return "Redirect (change route)"; case 8: return "Echo Request"; case 11: return "Time Exceeded"; case 12: return "Parameter Problem"; case 13: return "Timestamp Request"; case 14: return "Timestamp Reply"; case 15: return "Information Request"; case 16: return "Information Reply"; case 17: return "Address Mask Request"; case 18: return "Address Mask Reply"; } return NULL; } void print_icmp_types (void) { int icmp_numbers[] = { 0, 3, 4, 5, 8, 11, 12, 13, 14, 15, 16, 17, 18, -1 }; int count = 0; while ((icmp_numbers[count]) != -1) { printf ("%d - %s\n", icmp_numbers[count], get_icmp_proto_by_name (icmp_numbers[count])); count++; } exit (0); } #endif
the_stack_data/90766140.c
// // CTest.c // TestARM // // Created by Silence on 2019/8/17. // Copyright © 2019年 Silence. All rights reserved. // #include <stdio.h> void simple() { int a = 2 ; int b = 3 ; } void another() { int a = 4; int b = 5; simple(); }
the_stack_data/31388315.c
/* * FreeRTOS Kernel V10.2.1 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * 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. * * http://www.FreeRTOS.org * http://aws.amazon.com/freertos * * 1 tab == 4 spaces! */ #include <stdint.h> extern uint32_t Image$$ER_IROM_FREERTOS_SYSTEM_CALLS$$Base; extern uint32_t Image$$ER_IROM_FREERTOS_SYSTEM_CALLS$$Limit; /* Memory map needed for MPU setup. Must must match the one defined in * the scatter-loading file (MPUDemo.sct). */ const uint32_t * __FLASH_segment_start__ = ( uint32_t * ) 0x08000000; const uint32_t * __FLASH_segment_end__ = ( uint32_t * ) 0x08100000; const uint32_t * __SRAM_segment_start__ = ( uint32_t * ) 0x20000000; const uint32_t * __SRAM_segment_end__ = ( uint32_t * ) 0x20018000; const uint32_t * __privileged_functions_start__ = ( uint32_t * ) 0x08000000; const uint32_t * __privileged_functions_end__ = ( uint32_t * ) 0x08008000; const uint32_t * __privileged_data_start__ = ( uint32_t * ) 0x20000000; const uint32_t * __privileged_data_end__ = ( uint32_t * ) 0x20000400; const uint32_t * __syscalls_flash_start__ = ( uint32_t * ) &( Image$$ER_IROM_FREERTOS_SYSTEM_CALLS$$Base ); const uint32_t * __syscalls_flash_end__ = ( uint32_t * ) &( Image$$ER_IROM_FREERTOS_SYSTEM_CALLS$$Limit ); /*-----------------------------------------------------------*/ /** * @brief Mem fault handler. */ void MemManage_Handler( void ) __attribute__ (( naked )); /*-----------------------------------------------------------*/ void MemManage_Handler( void ) { __asm volatile ( " tst lr, #4 \n" " ite eq \n" " mrseq r0, msp \n" " mrsne r0, psp \n" " ldr r1, handler_address_const \n" " bx r1 \n" " \n" " handler_address_const: .word vHandleMemoryFault \n" ); } /*-----------------------------------------------------------*/
the_stack_data/106318.c
/** * \file exo6.c * \author Pallamidessi joseph * \version 1.0 * \date 16 octobre 2012 * \brief * * \details * */ #include <sys/types.h> #include <sys/wait.h> #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <ctype.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> int main(int args,char* argv[]){ int i,j; for(i=0;i<2;i++){ if(fork()==0){ if(i==0){ printf("premier fils\n"); execlp("ls","ls","-l",NULL); } else{ printf("deuxieme fils\n"); execlp("ps","ps","-l",NULL); } } else{ for(j=0;j<2;j++) wait(NULL); } } return 0; }
the_stack_data/48576243.c
#include <unistd.h> #include <errno.h> #include <stdio.h> #include <string.h> /* Usage: rm [FILE...] */ int main(int argc, char *argv[]) { int i; if (argc == 1) { fprintf(stderr, "%s: missing operand\n", argv[0]); return 1; } for (i = 1; i < argc; i++) { if (unlink(argv[i]) < 0) { fprintf(stderr, "%s: %s: %s\n", argv[0], argv[i], strerror(errno)); return 1; } } return 0; }
the_stack_data/184518062.c
/* This source code was extracted from the Q8 package created and placed in the PUBLIC DOMAIN by Doug Gwyn <[email protected]> last edit: 1999/11/05 [email protected] Implements subclause 7.8.2 of ISO/IEC 9899:1999 (E). This particular implementation requires the matching <inttypes.h>. It also assumes that character codes for A..Z and a..z are in contiguous ascending order; this is true for ASCII but not EBCDIC. */ #include <wchar.h> #ifndef __COREDLL__ #include <errno.h> #endif #include <ctype.h> #include <inttypes.h> /* convert digit wide character to number, in any base */ #define ToWNumber(c) (iswdigit(c) ? (c) - L'0' : \ iswupper(c) ? (c) - L'A' + 10 : \ iswlower(c) ? (c) - L'a' + 10 : \ -1 /* "invalid" flag */ \ ) /* validate converted digit character for specific base */ #define valid(n, b) ((n) >= 0 && (n) < (b)) intmax_t wcstoimax(nptr, endptr, base) register const wchar_t * __restrict__ nptr; wchar_t ** __restrict__ endptr; register int base; { register uintmax_t accum; /* accumulates converted value */ register int n; /* numeral from digit character */ int minus; /* set iff minus sign seen */ int toobig; /* set iff value overflows */ if ( endptr != NULL ) *endptr = (wchar_t *)nptr; /* in case no conv performed */ if ( base < 0 || base == 1 || base > 36 ) { #ifndef __COREDLL__ errno = EDOM; #endif return 0; /* unspecified behavior */ } /* skip initial, possibly empty sequence of white-space w.characters */ while ( iswspace(*nptr) ) ++nptr; /* process subject sequence: */ /* optional sign */ if ( (minus = *nptr == L'-') || *nptr == L'+' ) ++nptr; if ( base == 0 ) { if ( *nptr == L'0' ) { if ( nptr[1] == L'X' || nptr[1] == L'x' ) base = 16; else base = 8; } else base = 10; } /* optional "0x" or "0X" for base 16 */ if ( base == 16 && *nptr == L'0' && (nptr[1] == L'X' || nptr[1] == L'x') ) nptr += 2; /* skip past this prefix */ /* check whether there is at least one valid digit */ n = ToWNumber(*nptr); ++nptr; if ( !valid(n, base) ) return 0; /* subject seq. not of expected form */ accum = n; for ( toobig = 0; n = ToWNumber(*nptr), valid(n, base); ++nptr ) if ( accum > (uintmax_t)(INTMAX_MAX / base + 2) ) /* major wrap-around */ toobig = 1; /* but keep scanning */ else accum = base * accum + n; if ( endptr != NULL ) *endptr = (wchar_t *)nptr; /* -> first not-valid-digit */ if ( minus ) { if ( accum > (uintmax_t)INTMAX_MAX + 1 ) toobig = 1; } else if ( accum > (uintmax_t)INTMAX_MAX ) toobig = 1; if ( toobig ) { #ifndef __COREDLL__ errno = ERANGE; #endif return minus ? INTMAX_MIN : INTMAX_MAX; } else return (intmax_t)(minus ? -accum : accum); } long long __attribute__ ((alias ("wcstoimax"))) wcstoll (const wchar_t* __restrict__ nptr, wchar_t ** __restrict__ endptr, int base);
the_stack_data/25139175.c
/***********************************************/ /* Konami games */ /***********************************************/ /* pooyan */ extern struct GameDriver driver_pootan; extern struct GameDriver driver_pooyan; extern struct GameDriver driver_pooyans; /* timeplt */ extern struct GameDriver driver_spaceplt; extern struct GameDriver driver_timeplt; extern struct GameDriver driver_timepltc; extern struct GameDriver driver_psurge; /* rocnrope */ extern struct GameDriver driver_rocnrope; extern struct GameDriver driver_rocnropk; /* gyruss */ extern struct GameDriver driver_gyruss; extern struct GameDriver driver_gyrussce; extern struct GameDriver driver_venus; /* trackfld */ extern struct GameDriver driver_hyprolyb; extern struct GameDriver driver_hyprolym; extern struct GameDriver driver_trackflc; extern struct GameDriver driver_trackfld; /* tp84 */ extern struct GameDriver driver_tp84; extern struct GameDriver driver_tp84a; /* hyperspt */ extern struct GameDriver driver_hpolym84; extern struct GameDriver driver_hyperspt; extern struct GameDriver driver_roadf; extern struct GameDriver driver_roadf2; /* sbasketb */ extern struct GameDriver driver_sbasketb; /* mikie */ extern struct GameDriver driver_mikie; extern struct GameDriver driver_mikiehs; extern struct GameDriver driver_mikiej; /* yiear */ extern struct GameDriver driver_yiear; extern struct GameDriver driver_yiear2; /* shaolins */ extern struct GameDriver driver_kicker; extern struct GameDriver driver_shaolins; /* pingpong */ extern struct GameDriver driver_pingpong; /* gberet */ extern struct GameDriver driver_gberet; extern struct GameDriver driver_gberetb; extern struct GameDriver driver_rushatck; extern struct GameDriver driver_mrgoemon; /* jailbrek */ extern struct GameDriver driver_jailbrek; /* ironhors */ extern struct GameDriver driver_dairesya; extern struct GameDriver driver_ironhors; extern struct GameDriver driver_farwest; /* jackal */ extern struct GameDriver driver_jackal; extern struct GameDriver driver_jackalj; extern struct GameDriver driver_topgunr; extern struct GameDriver driver_topgunbl; /* contra */ extern struct GameDriver driver_contra; extern struct GameDriver driver_contrab; extern struct GameDriver driver_contraj; extern struct GameDriver driver_contrajb; extern struct GameDriver driver_gryzor; /* mainevt */ extern struct GameDriver driver_devstor2; extern struct GameDriver driver_devstor3; extern struct GameDriver driver_devstors; extern struct GameDriver driver_garuka; extern struct GameDriver driver_mainevt; extern struct GameDriver driver_mainevt2; extern struct GameDriver driver_ringohja; /* tutankhm */ extern struct GameDriver driver_tutankhm; extern struct GameDriver driver_tutankst; /* junofrst */ extern struct GameDriver driver_junofrst; extern struct GameDriver driver_junofstg; /* finalizr */ extern struct GameDriver driver_finalizr; extern struct GameDriver driver_finalizb; /* battlnts */ extern struct GameDriver driver_battlnts; extern struct GameDriver driver_battlntj; extern struct GameDriver driver_thehustl; extern struct GameDriver driver_thehustj; extern struct GameDriver driver_rackemup; /* combatsc */ extern struct GameDriver driver_combasc; extern struct GameDriver driver_combasct; extern struct GameDriver driver_combascj; extern struct GameDriver driver_bootcamp; extern struct GameDriver driver_combasc; /* others */ extern struct GameDriver driver_parodius; extern struct GameDriver driver_xmen2pj; extern struct GameDriver driver_xmen; extern struct GameDriver driver_xmen6p; extern struct GameDriver driver_vendetta; extern struct GameDriver driver_vendett2; extern struct GameDriver driver_twinbee; extern struct GameDriver driver_trigon; extern struct GameDriver driver_thnderxj; extern struct GameDriver driver_thndrx2; extern struct GameDriver driver_thunderx; extern struct GameDriver driver_simps2pj; extern struct GameDriver driver_simpsn2p; extern struct GameDriver driver_simpsons; extern struct GameDriver driver_fround; extern struct GameDriver driver_tmht2p; extern struct GameDriver driver_tmht; extern struct GameDriver driver_tmnt2pj; extern struct GameDriver driver_tmnt2po; extern struct GameDriver driver_tmntj; extern struct GameDriver driver_tmnt; extern struct GameDriver driver_tmnt22p; extern struct GameDriver driver_tmnt2a; extern struct GameDriver driver_tmnt2; extern struct GameDriver driver_surpratk; extern struct GameDriver driver_scontraj; extern struct GameDriver driver_scontra; extern struct GameDriver driver_ssrdrabd; extern struct GameDriver driver_ssrdrjbd; extern struct GameDriver driver_ssrdrubc; extern struct GameDriver driver_ssrdruac; extern struct GameDriver driver_ssrdruda; extern struct GameDriver driver_ssrdrebc; extern struct GameDriver driver_ssrdrebd; extern struct GameDriver driver_ssriders; extern struct GameDriver driver_salamand; extern struct GameDriver driver_rockrage; extern struct GameDriver driver_punksht2; extern struct GameDriver driver_punkshot; extern struct GameDriver driver_quarth; extern struct GameDriver driver_nemesuk; extern struct GameDriver driver_nemesis; extern struct GameDriver driver_megazone; extern struct GameDriver driver_majuu; extern struct GameDriver driver_miaj; extern struct GameDriver driver_mia2; extern struct GameDriver driver_mia; extern struct GameDriver driver_lgtnfght; extern struct GameDriver driver_lifefrcj; extern struct GameDriver driver_lifefrce; extern struct GameDriver driver_labyrunr; extern struct GameDriver driver_konami88; extern struct GameDriver driver_konamigt; extern struct GameDriver driver_rf2; extern struct GameDriver driver_junglers; extern struct GameDriver driver_jungler; extern struct GameDriver driver_hotchase; extern struct GameDriver driver_gradius2; extern struct GameDriver driver_grdius2a; extern struct GameDriver driver_grdius2b; extern struct GameDriver driver_grdius3a; extern struct GameDriver driver_gradius3; extern struct GameDriver driver_gradius; extern struct GameDriver driver_fastlane; extern struct GameDriver driver_ddribble; extern struct GameDriver driver_devilw; extern struct GameDriver driver_darkadv; extern struct GameDriver driver_circuscc; extern struct GameDriver driver_circusce; extern struct GameDriver driver_circusc2; extern struct GameDriver driver_circusc; extern struct GameDriver driver_bottom9n; extern struct GameDriver driver_bottom9; extern struct GameDriver driver_aliensj; extern struct GameDriver driver_aliensu; extern struct GameDriver driver_aliens; extern struct GameDriver driver_aliens2; extern struct GameDriver driver_ajaxj; extern struct GameDriver driver_ajax; //extern struct GameDriver driver_600; extern struct GameDriver driver_88games; extern struct GameDriver driver_wecleman; extern struct GameDriver driver_pandoras; extern struct GameDriver driver_hcastle; extern struct GameDriver driver_hcastlea; extern struct GameDriver driver_hcastlej; extern struct GameDriver driver_labyrunr; extern struct GameDriver driver_locomotn; extern struct GameDriver driver_gutangtn; extern struct GameDriver driver_cottong; extern struct GameDriver driver_commsega; extern struct GameDriver driver_blswhstl; extern struct GameDriver driver_bladstle; extern struct GameDriver driver_bladestl; extern struct GameDriver driver_crazycop; extern struct GameDriver driver_crimfgtj; extern struct GameDriver driver_crimfght; extern struct GameDriver driver_crimfgt2; extern struct GameDriver driver_vendettj; extern struct GameDriver driver_cuebrick; extern struct GameDriver driver_detatwin; extern struct GameDriver driver_flkatck; extern struct GameDriver driver_hpuncher; extern struct GameDriver driver_gbusters; extern struct GameDriver driver_gwarrior; extern struct GameDriver driver_rockragj; extern struct GameDriver driver_mx5000; extern struct GameDriver driver_rollergj; extern struct GameDriver driver_rollerg; extern struct GameDriver driver_spy; extern struct GameDriver driver_vulcan; const struct GameDriver *drivers[] = { &driver_pootan, &driver_pooyan, &driver_pooyans, &driver_spaceplt, &driver_timeplt, &driver_timepltc, &driver_psurge, &driver_rocnrope, &driver_rocnropk, &driver_gyruss, &driver_gyrussce, &driver_venus, &driver_hyprolyb, &driver_hyprolym, &driver_trackflc, &driver_trackfld, &driver_tp84, &driver_tp84a, &driver_hpolym84, &driver_hyperspt, &driver_roadf, &driver_roadf2, &driver_sbasketb, &driver_mikie, &driver_mikiehs, &driver_mikiej, &driver_yiear, &driver_yiear2, &driver_kicker, &driver_shaolins, &driver_pingpong, &driver_gberet, &driver_gberetb, &driver_rushatck, &driver_mrgoemon, &driver_jailbrek, &driver_dairesya, &driver_ironhors, &driver_farwest, &driver_jackal, &driver_jackalj, &driver_topgunr, &driver_topgunbl, &driver_contra, &driver_contrab, &driver_contraj, &driver_contrajb, &driver_gryzor, &driver_devstor2, &driver_devstor3, &driver_devstors, &driver_garuka, &driver_mainevt, &driver_mainevt2, &driver_ringohja, &driver_tutankhm, &driver_tutankst, &driver_junofrst, &driver_junofstg, &driver_finalizr, &driver_finalizb, &driver_battlnts, &driver_battlntj, &driver_thehustl, &driver_thehustj, &driver_rackemup, &driver_combasc, &driver_combasct, &driver_combascj, &driver_bootcamp, &driver_combasc, &driver_parodius, &driver_xmen2pj, &driver_xmen, &driver_xmen6p, &driver_vendetta, &driver_vendett2, &driver_twinbee, &driver_trigon, &driver_thnderxj, &driver_thndrx2, &driver_thunderx, &driver_simps2pj, &driver_simpsn2p, &driver_simpsons, &driver_fround, &driver_tmht2p, &driver_tmht, &driver_tmnt2pj, &driver_tmnt2po, &driver_tmntj, &driver_tmnt, &driver_tmnt22p, &driver_tmnt2a, &driver_tmnt2, &driver_surpratk, &driver_scontraj, &driver_scontra, &driver_ssrdrabd, &driver_ssrdrjbd, &driver_ssrdrubc, &driver_ssrdruac, &driver_ssrdruda, &driver_ssrdrebc, &driver_ssrdrebd, &driver_ssriders, &driver_salamand, &driver_rockrage, &driver_punksht2, &driver_punkshot, &driver_quarth, &driver_nemesuk, &driver_nemesis, &driver_megazone, &driver_majuu, &driver_miaj, &driver_mia2, &driver_mia, &driver_lgtnfght, &driver_lifefrcj, &driver_lifefrce, &driver_labyrunr, &driver_konami88, &driver_konamigt, &driver_rf2, &driver_junglers, &driver_jungler, &driver_hotchase, &driver_gradius2, &driver_grdius2a, &driver_grdius2b, &driver_grdius3a, &driver_gradius3, &driver_gradius, &driver_fastlane, &driver_ddribble, &driver_devilw, &driver_darkadv, &driver_circuscc, &driver_circusce, &driver_circusc2, &driver_circusc, &driver_bottom9n, &driver_bottom9, &driver_aliensj, &driver_aliensu, &driver_aliens, &driver_aliens2, &driver_ajaxj, &driver_ajax, // &driver_600, &driver_88games, &driver_wecleman, &driver_pandoras, &driver_hcastle, &driver_hcastlea, &driver_hcastlej, &driver_labyrunr, &driver_locomotn, &driver_gutangtn, &driver_cottong, &driver_commsega, &driver_blswhstl, &driver_bladstle, &driver_bladestl, &driver_crazycop, &driver_crimfgtj, &driver_crimfght, &driver_crimfgt2, &driver_vendettj, &driver_cuebrick, &driver_detatwin, &driver_flkatck, &driver_hpuncher, &driver_gbusters, &driver_gwarrior, &driver_rockragj, &driver_mx5000, &driver_rollergj, &driver_rollerg, &driver_spy, &driver_vulcan, 0 /* end of array */ };
the_stack_data/40825.c
//EXERCICIO 1 #include <stdio.h> #include <string.h> int main() { char nome[10]; printf("Digite seu nome:"); gets(nome); for (int cont = 0; cont < 4; cont++) { printf("%c\n", nome[cont]); } return 0; }
the_stack_data/14199268.c
#include <stdbool.h> #include <stdarg.h> #include <stdio.h> #include <string.h> static void print(const char* data, size_t data_length) { for (size_t i = 0; i < data_length; i++) { putchar((int)((const unsigned char*)data)[i]); } } int printf(const char* restrict format, ...) { va_list parameters; va_start(parameters, format); unsigned char *where, buf[16]; int written = 0; size_t amount; bool rejected_bad_specifier = false; while (*format != '\0') { if (*format != '%') { print_c: amount = 1; while (format[amount] && format[amount] != '%') { amount++; } print(format, amount); format += amount; written += amount; continue; } const char* format_begun_at = format; if (*(++format) == '%') { goto print_c; } if (rejected_bad_specifier) { incomprehensible_conversion: rejected_bad_specifier = true; format = format_begun_at; goto print_c; } if (*format == 'c') { format++; char c = (char)va_arg(parameters, int /* char promotes to int */); print(&c, sizeof(c)); } else if (*format == 's') { format++; const char* s = va_arg(parameters, const char*); print(s, strlen(s)); } else if (*format == 'd') { format++; int i = va_arg(parameters, int); where = buf + 16 - 1; *where = '\0'; int radix = 10; do { unsigned long temp; temp = (unsigned long)i % radix; where--; if (temp < 10) { *where = temp + '0'; } else { *where = temp - 10 + 'a'; } i = (unsigned long)i / radix; } while (i != 0); print(where, strlen(where)); } else if (*format == 'x') { format++; int n = va_arg(parameters, unsigned int); char noZeroes = 1; print("0x", 2); int temp; int i; for (i = 28; i > 0; i -= 4) { temp = (n >> i) & 0xF; if (temp == 0 && noZeroes != 0) { continue; } if (temp >= 0xA) { noZeroes = 0; putchar(temp - 0xA + 'a'); } else { noZeroes = 0; putchar(temp + '0'); } } temp = n & 0xF; if (temp >= 0xA) { noZeroes = 0; putchar(temp - 0xA + 'a'); } else { noZeroes = 0; putchar(temp + '0'); } } else { goto incomprehensible_conversion; } } va_end(parameters); return written; }
the_stack_data/700466.c
#include <stdio.h> main() { printf("Hello, world\a"); }
the_stack_data/97012066.c
#include <stdio.h> int main () //Declarando e Implementando la función { printf("Hola Mundo\n"); /* imprime la cadena */ return 0; /* sale de la función */ }
the_stack_data/630191.c
#include <stdio.h> int main () { int senha, i; for (i=0; ; i++) { scanf("%d", &senha); if (senha == 2002) { printf("Acesso Permitido\n"); break; } else { printf("Senha Invalida\n"); continue; } } return 0; }
the_stack_data/159516380.c
/* Generated by CIL v. 1.7.0 */ /* print_CIL_Input is false */ struct _IO_FILE; struct timeval; extern float strtof(char const *str , char const *endptr ) ; extern void signal(int sig , void *func ) ; typedef struct _IO_FILE FILE; extern int atoi(char const *s ) ; extern double strtod(char const *str , char const *endptr ) ; extern int fclose(void *stream ) ; extern void *fopen(char const *filename , char const *mode ) ; extern void abort() ; extern void exit(int status ) ; extern int raise(int sig ) ; extern int fprintf(struct _IO_FILE *stream , char const *format , ...) ; extern int strcmp(char const *a , char const *b ) ; extern int rand() ; extern unsigned long strtoul(char const *str , char const *endptr , int base ) ; void RandomFunc(unsigned int input[1] , unsigned int output[1] ) ; extern int strncmp(char const *s1 , char const *s2 , unsigned long maxlen ) ; extern int gettimeofday(struct timeval *tv , void *tz , ...) ; extern int printf(char const *format , ...) ; int main(int argc , char *argv[] ) ; void megaInit(void) ; extern unsigned long strlen(char const *s ) ; extern long strtol(char const *str , char const *endptr , int base ) ; extern unsigned long strnlen(char const *s , unsigned long maxlen ) ; extern void *memcpy(void *s1 , void const *s2 , unsigned long size ) ; struct timeval { long tv_sec ; long tv_usec ; }; extern void *malloc(unsigned long size ) ; extern int scanf(char const *format , ...) ; int main(int argc , char *argv[] ) { unsigned int input[1] ; unsigned int output[1] ; int randomFuns_i5 ; unsigned int randomFuns_value6 ; int randomFuns_main_i7 ; { megaInit(); if (argc != 2) { printf("Call this program with %i arguments\n", 1); exit(-1); } else { } randomFuns_i5 = 0; while (randomFuns_i5 < 1) { randomFuns_value6 = (unsigned int )strtoul(argv[randomFuns_i5 + 1], 0, 10); input[randomFuns_i5] = randomFuns_value6; randomFuns_i5 ++; } RandomFunc(input, output); if (output[0] == 4242424242U) { printf("You win!\n"); } else { } randomFuns_main_i7 = 0; while (randomFuns_main_i7 < 1) { printf("%u\n", output[randomFuns_main_i7]); randomFuns_main_i7 ++; } } } void RandomFunc(unsigned int input[1] , unsigned int output[1] ) { unsigned int state[1] ; unsigned int local2 ; unsigned int local1 ; unsigned short copy11 ; { state[0UL] = (input[0UL] + 51238316UL) + 274866410U; local1 = 0UL; while (local1 < input[1UL]) { local2 = 0UL; while (local2 < input[1UL]) { if (state[0UL] != local2 + local1) { state[0UL] = state[local1] + state[0UL]; state[local1] = state[0UL] - state[local1]; } else { copy11 = *((unsigned short *)(& state[local1]) + 1); *((unsigned short *)(& state[local1]) + 1) = *((unsigned short *)(& state[local1]) + 0); *((unsigned short *)(& state[local1]) + 0) = copy11; state[local2] += state[0UL]; } local2 ++; } local1 += 2UL; } output[0UL] = (state[0UL] - 244510388UL) + 3526034937U; } } void megaInit(void) { { } }
the_stack_data/418981.c
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ____ ___ __ _ // / __// o |,'_/ .' \ // / _/ / _,'/ /_n / o / _ __ _ ___ _ _ __ // /_/ /_/ |__,'/_n_/ / \,' /.' \ ,' _/,' \ / |/ / // / \,' // o /_\ `./ o // || / // /_/ /_//_n_//___,'|_,'/_/|_/ // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Author : Wesley Taylor-Rendal (WTR) // Design history : Review git logs. // Description : Introducing Character Arrays // Concepts : Unspecified array dimensions on declaration will set the // : default size to the contents assigned during // : initialisation // : Indexed initialisation x[] = {[6]='?'} has same dimensions //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include <stdio.h> int main(void) { char word[] = {'H', 'e', 'l', 'l', 'o', '?'}; int i; for (i=0; i<6; ++i) printf("%c", word[i]); printf("\n"); return 0; }
the_stack_data/119254.c
// gcc portScanner.c -o portScanner // ./portScanner #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/time.h> #include <sys/ioctl.h> #include <netinet/in.h> #include <string.h> #include <stdlib.h> #define MAX_SIZE 100 int main() { int sockfd; struct sockaddr_in serverAddress; char *arr[MAX_SIZE]; int i, j, size, startingPort, endingPort; //Get start port number printf("\nEnter start port number : "); scanf("%d" , &startingPort); //Get end port number printf("Enter end port number : "); scanf("%d" , &endingPort); //Get size of IP array printf("Enter size of the IP array : "); scanf("%d", &size); //Get IPs in array printf("Enter IPs with one space between : "); for(i=0; i<size; i++) { arr[i] = (char*)malloc(16); scanf("%15s", arr[i]); } printf("starting port scans\n"); for(j=0; j<size; j++) { FILE *outFile = fopen(arr[j], "w"); for(i = startingPort ; i <= endingPort ; i++) { // attempt to create socket if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("\n socket creation error \n"); return -1; } serverAddress.sin_family = AF_INET; inet_pton(AF_INET, arr[j], &serverAddress.sin_addr); serverAddress.sin_port = htons(i); //attempt connection if (connect(sockfd, (const struct sockaddr *)&serverAddress, sizeof(serverAddress)) >= 0) { printf("port %d open\n",i); fprintf(outFile,"port %d open\n",i); } close(sockfd); } fclose(outFile); printf("\nPort scan for %s completed\n\n",arr[j]); } return 0; }
the_stack_data/242331482.c
/* This is a heavily customized and minimized copy of Lua 5.1.5. */ /* It's only used to build LuaJIT. It does NOT have all standard functions! */ /****************************************************************************** * Copyright (C) 1994-2012 Lua.org, PUC-Rio. All rights reserved. * * 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. ******************************************************************************/ #ifdef _MSC_VER typedef unsigned __int64 U64; #else typedef unsigned long long U64; #endif int _CRT_glob = 0; #include <stddef.h> #include <stdarg.h> #include <limits.h> #include <math.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <setjmp.h> #include <errno.h> #include <time.h> typedef enum{ TM_INDEX, TM_NEWINDEX, TM_GC, TM_MODE, TM_EQ, TM_ADD, TM_SUB, TM_MUL, TM_DIV, TM_MOD, TM_POW, TM_UNM, TM_LEN, TM_LT, TM_LE, TM_CONCAT, TM_CALL, TM_N }TMS; enum OpMode{iABC,iABx,iAsBx}; typedef enum{ OP_MOVE, OP_LOADK, OP_LOADBOOL, OP_LOADNIL, OP_GETUPVAL, OP_GETGLOBAL, OP_GETTABLE, OP_SETGLOBAL, OP_SETUPVAL, OP_SETTABLE, OP_NEWTABLE, OP_SELF, OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_POW, OP_UNM, OP_NOT, OP_LEN, OP_CONCAT, OP_JMP, OP_EQ, OP_LT, OP_LE, OP_TEST, OP_TESTSET, OP_CALL, OP_TAILCALL, OP_RETURN, OP_FORLOOP, OP_FORPREP, OP_TFORLOOP, OP_SETLIST, OP_CLOSE, OP_CLOSURE, OP_VARARG }OpCode; enum OpArgMask{ OpArgN, OpArgU, OpArgR, OpArgK }; typedef enum{ VVOID, VNIL, VTRUE, VFALSE, VK, VKNUM, VLOCAL, VUPVAL, VGLOBAL, VINDEXED, VJMP, VRELOCABLE, VNONRELOC, VCALL, VVARARG }expkind; enum RESERVED{ TK_AND=257,TK_BREAK, TK_DO,TK_ELSE,TK_ELSEIF,TK_END,TK_FALSE,TK_FOR,TK_FUNCTION, TK_IF,TK_IN,TK_LOCAL,TK_NIL,TK_NOT,TK_OR,TK_REPEAT, TK_RETURN,TK_THEN,TK_TRUE,TK_UNTIL,TK_WHILE, TK_CONCAT,TK_DOTS,TK_EQ,TK_GE,TK_LE,TK_NE,TK_NUMBER, TK_NAME,TK_STRING,TK_EOS }; typedef enum BinOpr{ OPR_ADD,OPR_SUB,OPR_MUL,OPR_DIV,OPR_MOD,OPR_POW, OPR_CONCAT, OPR_NE,OPR_EQ, OPR_LT,OPR_LE,OPR_GT,OPR_GE, OPR_AND,OPR_OR, OPR_NOBINOPR }BinOpr; typedef enum UnOpr{OPR_MINUS,OPR_NOT,OPR_LEN,OPR_NOUNOPR}UnOpr; #define LUA_QL(x)"'"x"'" #define luai_apicheck(L,o){(void)L;} #define lua_number2str(s,n)sprintf((s),"%.14g",(n)) #define lua_str2number(s,p)strtod((s),(p)) #define luai_numadd(a,b)((a)+(b)) #define luai_numsub(a,b)((a)-(b)) #define luai_nummul(a,b)((a)*(b)) #define luai_numdiv(a,b)((a)/(b)) #define luai_nummod(a,b)((a)-floor((a)/(b))*(b)) #define luai_numpow(a,b)(pow(a,b)) #define luai_numunm(a)(-(a)) #define luai_numeq(a,b)((a)==(b)) #define luai_numlt(a,b)((a)<(b)) #define luai_numle(a,b)((a)<=(b)) #define luai_numisnan(a)(!luai_numeq((a),(a))) #define lua_number2int(i,d)((i)=(int)(d)) #define lua_number2integer(i,d)((i)=(lua_Integer)(d)) #define LUAI_THROW(L,c)longjmp((c)->b,1) #define LUAI_TRY(L,c,a)if(setjmp((c)->b)==0){a} #define lua_pclose(L,file)((void)((void)L,file),0) #define lua_upvalueindex(i)((-10002)-(i)) typedef struct lua_State lua_State; typedef int(*lua_CFunction)(lua_State*L); typedef const char*(*lua_Reader)(lua_State*L,void*ud,size_t*sz); typedef void*(*lua_Alloc)(void*ud,void*ptr,size_t osize,size_t nsize); typedef double lua_Number; typedef ptrdiff_t lua_Integer; static void lua_settop(lua_State*L,int idx); static int lua_type(lua_State*L,int idx); static const char* lua_tolstring(lua_State*L,int idx,size_t*len); static size_t lua_objlen(lua_State*L,int idx); static void lua_pushlstring(lua_State*L,const char*s,size_t l); static void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n); static void lua_createtable(lua_State*L,int narr,int nrec); static void lua_setfield(lua_State*L,int idx,const char*k); #define lua_pop(L,n)lua_settop(L,-(n)-1) #define lua_newtable(L)lua_createtable(L,0,0) #define lua_pushcfunction(L,f)lua_pushcclosure(L,(f),0) #define lua_strlen(L,i)lua_objlen(L,(i)) #define lua_isfunction(L,n)(lua_type(L,(n))==6) #define lua_istable(L,n)(lua_type(L,(n))==5) #define lua_isnil(L,n)(lua_type(L,(n))==0) #define lua_isboolean(L,n)(lua_type(L,(n))==1) #define lua_isnone(L,n)(lua_type(L,(n))==(-1)) #define lua_isnoneornil(L,n)(lua_type(L,(n))<=0) #define lua_pushliteral(L,s)lua_pushlstring(L,""s,(sizeof(s)/sizeof(char))-1) #define lua_setglobal(L,s)lua_setfield(L,(-10002),(s)) #define lua_tostring(L,i)lua_tolstring(L,(i),NULL) typedef struct lua_Debug lua_Debug; typedef void(*lua_Hook)(lua_State*L,lua_Debug*ar); struct lua_Debug{ int event; const char*name; const char*namewhat; const char*what; const char*source; int currentline; int nups; int linedefined; int lastlinedefined; char short_src[60]; int i_ci; }; typedef unsigned int lu_int32; typedef size_t lu_mem; typedef ptrdiff_t l_mem; typedef unsigned char lu_byte; #define IntPoint(p)((unsigned int)(lu_mem)(p)) typedef union{double u;void*s;long l;}L_Umaxalign; typedef double l_uacNumber; #define check_exp(c,e)(e) #define UNUSED(x)((void)(x)) #define cast(t,exp)((t)(exp)) #define cast_byte(i)cast(lu_byte,(i)) #define cast_num(i)cast(lua_Number,(i)) #define cast_int(i)cast(int,(i)) typedef lu_int32 Instruction; #define condhardstacktests(x)((void)0) typedef union GCObject GCObject; typedef struct GCheader{ GCObject*next;lu_byte tt;lu_byte marked; }GCheader; typedef union{ GCObject*gc; void*p; lua_Number n; int b; }Value; typedef struct lua_TValue{ Value value;int tt; }TValue; #define ttisnil(o)(ttype(o)==0) #define ttisnumber(o)(ttype(o)==3) #define ttisstring(o)(ttype(o)==4) #define ttistable(o)(ttype(o)==5) #define ttisfunction(o)(ttype(o)==6) #define ttisboolean(o)(ttype(o)==1) #define ttisuserdata(o)(ttype(o)==7) #define ttisthread(o)(ttype(o)==8) #define ttislightuserdata(o)(ttype(o)==2) #define ttype(o)((o)->tt) #define gcvalue(o)check_exp(iscollectable(o),(o)->value.gc) #define pvalue(o)check_exp(ttislightuserdata(o),(o)->value.p) #define nvalue(o)check_exp(ttisnumber(o),(o)->value.n) #define rawtsvalue(o)check_exp(ttisstring(o),&(o)->value.gc->ts) #define tsvalue(o)(&rawtsvalue(o)->tsv) #define rawuvalue(o)check_exp(ttisuserdata(o),&(o)->value.gc->u) #define uvalue(o)(&rawuvalue(o)->uv) #define clvalue(o)check_exp(ttisfunction(o),&(o)->value.gc->cl) #define hvalue(o)check_exp(ttistable(o),&(o)->value.gc->h) #define bvalue(o)check_exp(ttisboolean(o),(o)->value.b) #define thvalue(o)check_exp(ttisthread(o),&(o)->value.gc->th) #define l_isfalse(o)(ttisnil(o)||(ttisboolean(o)&&bvalue(o)==0)) #define checkconsistency(obj) #define checkliveness(g,obj) #define setnilvalue(obj)((obj)->tt=0) #define setnvalue(obj,x){TValue*i_o=(obj);i_o->value.n=(x);i_o->tt=3;} #define setbvalue(obj,x){TValue*i_o=(obj);i_o->value.b=(x);i_o->tt=1;} #define setsvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=4;checkliveness(G(L),i_o);} #define setuvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=7;checkliveness(G(L),i_o);} #define setthvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=8;checkliveness(G(L),i_o);} #define setclvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=6;checkliveness(G(L),i_o);} #define sethvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=5;checkliveness(G(L),i_o);} #define setptvalue(L,obj,x){TValue*i_o=(obj);i_o->value.gc=cast(GCObject*,(x));i_o->tt=(8+1);checkliveness(G(L),i_o);} #define setobj(L,obj1,obj2){const TValue*o2=(obj2);TValue*o1=(obj1);o1->value=o2->value;o1->tt=o2->tt;checkliveness(G(L),o1);} #define setttype(obj,tt)(ttype(obj)=(tt)) #define iscollectable(o)(ttype(o)>=4) typedef TValue*StkId; typedef union TString{ L_Umaxalign dummy; struct{ GCObject*next;lu_byte tt;lu_byte marked; lu_byte reserved; unsigned int hash; size_t len; }tsv; }TString; #define getstr(ts)cast(const char*,(ts)+1) #define svalue(o)getstr(rawtsvalue(o)) typedef union Udata{ L_Umaxalign dummy; struct{ GCObject*next;lu_byte tt;lu_byte marked; struct Table*metatable; struct Table*env; size_t len; }uv; }Udata; typedef struct Proto{ GCObject*next;lu_byte tt;lu_byte marked; TValue*k; Instruction*code; struct Proto**p; int*lineinfo; struct LocVar*locvars; TString**upvalues; TString*source; int sizeupvalues; int sizek; int sizecode; int sizelineinfo; int sizep; int sizelocvars; int linedefined; int lastlinedefined; GCObject*gclist; lu_byte nups; lu_byte numparams; lu_byte is_vararg; lu_byte maxstacksize; }Proto; typedef struct LocVar{ TString*varname; int startpc; int endpc; }LocVar; typedef struct UpVal{ GCObject*next;lu_byte tt;lu_byte marked; TValue*v; union{ TValue value; struct{ struct UpVal*prev; struct UpVal*next; }l; }u; }UpVal; typedef struct CClosure{ GCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env; lua_CFunction f; TValue upvalue[1]; }CClosure; typedef struct LClosure{ GCObject*next;lu_byte tt;lu_byte marked;lu_byte isC;lu_byte nupvalues;GCObject*gclist;struct Table*env; struct Proto*p; UpVal*upvals[1]; }LClosure; typedef union Closure{ CClosure c; LClosure l; }Closure; #define iscfunction(o)(ttype(o)==6&&clvalue(o)->c.isC) typedef union TKey{ struct{ Value value;int tt; struct Node*next; }nk; TValue tvk; }TKey; typedef struct Node{ TValue i_val; TKey i_key; }Node; typedef struct Table{ GCObject*next;lu_byte tt;lu_byte marked; lu_byte flags; lu_byte lsizenode; struct Table*metatable; TValue*array; Node*node; Node*lastfree; GCObject*gclist; int sizearray; }Table; #define lmod(s,size)(check_exp((size&(size-1))==0,(cast(int,(s)&((size)-1))))) #define twoto(x)((size_t)1<<(x)) #define sizenode(t)(twoto((t)->lsizenode)) static const TValue luaO_nilobject_; #define ceillog2(x)(luaO_log2((x)-1)+1) static int luaO_log2(unsigned int x); #define gfasttm(g,et,e)((et)==NULL?NULL:((et)->flags&(1u<<(e)))?NULL:luaT_gettm(et,e,(g)->tmname[e])) #define fasttm(l,et,e)gfasttm(G(l),et,e) static const TValue*luaT_gettm(Table*events,TMS event,TString*ename); #define luaM_reallocv(L,b,on,n,e)((cast(size_t,(n)+1)<=((size_t)(~(size_t)0)-2)/(e))?luaM_realloc_(L,(b),(on)*(e),(n)*(e)):luaM_toobig(L)) #define luaM_freemem(L,b,s)luaM_realloc_(L,(b),(s),0) #define luaM_free(L,b)luaM_realloc_(L,(b),sizeof(*(b)),0) #define luaM_freearray(L,b,n,t)luaM_reallocv(L,(b),n,0,sizeof(t)) #define luaM_malloc(L,t)luaM_realloc_(L,NULL,0,(t)) #define luaM_new(L,t)cast(t*,luaM_malloc(L,sizeof(t))) #define luaM_newvector(L,n,t)cast(t*,luaM_reallocv(L,NULL,0,n,sizeof(t))) #define luaM_growvector(L,v,nelems,size,t,limit,e)if((nelems)+1>(size))((v)=cast(t*,luaM_growaux_(L,v,&(size),sizeof(t),limit,e))) #define luaM_reallocvector(L,v,oldn,n,t)((v)=cast(t*,luaM_reallocv(L,v,oldn,n,sizeof(t)))) static void*luaM_realloc_(lua_State*L,void*block,size_t oldsize, size_t size); static void*luaM_toobig(lua_State*L); static void*luaM_growaux_(lua_State*L,void*block,int*size, size_t size_elem,int limit, const char*errormsg); typedef struct Zio ZIO; #define char2int(c)cast(int,cast(unsigned char,(c))) #define zgetc(z)(((z)->n--)>0?char2int(*(z)->p++):luaZ_fill(z)) typedef struct Mbuffer{ char*buffer; size_t n; size_t buffsize; }Mbuffer; #define luaZ_initbuffer(L,buff)((buff)->buffer=NULL,(buff)->buffsize=0) #define luaZ_buffer(buff)((buff)->buffer) #define luaZ_sizebuffer(buff)((buff)->buffsize) #define luaZ_bufflen(buff)((buff)->n) #define luaZ_resetbuffer(buff)((buff)->n=0) #define luaZ_resizebuffer(L,buff,size)(luaM_reallocvector(L,(buff)->buffer,(buff)->buffsize,size,char),(buff)->buffsize=size) #define luaZ_freebuffer(L,buff)luaZ_resizebuffer(L,buff,0) struct Zio{ size_t n; const char*p; lua_Reader reader; void*data; lua_State*L; }; static int luaZ_fill(ZIO*z); struct lua_longjmp; #define gt(L)(&L->l_gt) #define registry(L)(&G(L)->l_registry) typedef struct stringtable{ GCObject**hash; lu_int32 nuse; int size; }stringtable; typedef struct CallInfo{ StkId base; StkId func; StkId top; const Instruction*savedpc; int nresults; int tailcalls; }CallInfo; #define curr_func(L)(clvalue(L->ci->func)) #define ci_func(ci)(clvalue((ci)->func)) #define f_isLua(ci)(!ci_func(ci)->c.isC) #define isLua(ci)(ttisfunction((ci)->func)&&f_isLua(ci)) typedef struct global_State{ stringtable strt; lua_Alloc frealloc; void*ud; lu_byte currentwhite; lu_byte gcstate; int sweepstrgc; GCObject*rootgc; GCObject**sweepgc; GCObject*gray; GCObject*grayagain; GCObject*weak; GCObject*tmudata; Mbuffer buff; lu_mem GCthreshold; lu_mem totalbytes; lu_mem estimate; lu_mem gcdept; int gcpause; int gcstepmul; lua_CFunction panic; TValue l_registry; struct lua_State*mainthread; UpVal uvhead; struct Table*mt[(8+1)]; TString*tmname[TM_N]; }global_State; struct lua_State{ GCObject*next;lu_byte tt;lu_byte marked; lu_byte status; StkId top; StkId base; global_State*l_G; CallInfo*ci; const Instruction*savedpc; StkId stack_last; StkId stack; CallInfo*end_ci; CallInfo*base_ci; int stacksize; int size_ci; unsigned short nCcalls; unsigned short baseCcalls; lu_byte hookmask; lu_byte allowhook; int basehookcount; int hookcount; lua_Hook hook; TValue l_gt; TValue env; GCObject*openupval; GCObject*gclist; struct lua_longjmp*errorJmp; ptrdiff_t errfunc; }; #define G(L)(L->l_G) union GCObject{ GCheader gch; union TString ts; union Udata u; union Closure cl; struct Table h; struct Proto p; struct UpVal uv; struct lua_State th; }; #define rawgco2ts(o)check_exp((o)->gch.tt==4,&((o)->ts)) #define gco2ts(o)(&rawgco2ts(o)->tsv) #define rawgco2u(o)check_exp((o)->gch.tt==7,&((o)->u)) #define gco2u(o)(&rawgco2u(o)->uv) #define gco2cl(o)check_exp((o)->gch.tt==6,&((o)->cl)) #define gco2h(o)check_exp((o)->gch.tt==5,&((o)->h)) #define gco2p(o)check_exp((o)->gch.tt==(8+1),&((o)->p)) #define gco2uv(o)check_exp((o)->gch.tt==(8+2),&((o)->uv)) #define ngcotouv(o)check_exp((o)==NULL||(o)->gch.tt==(8+2),&((o)->uv)) #define gco2th(o)check_exp((o)->gch.tt==8,&((o)->th)) #define obj2gco(v)(cast(GCObject*,(v))) static void luaE_freethread(lua_State*L,lua_State*L1); #define pcRel(pc,p)(cast(int,(pc)-(p)->code)-1) #define getline_(f,pc)(((f)->lineinfo)?(f)->lineinfo[pc]:0) #define resethookcount(L)(L->hookcount=L->basehookcount) static void luaG_typeerror(lua_State*L,const TValue*o, const char*opname); static void luaG_runerror(lua_State*L,const char*fmt,...); #define luaD_checkstack(L,n)if((char*)L->stack_last-(char*)L->top<=(n)*(int)sizeof(TValue))luaD_growstack(L,n);else condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1)); #define incr_top(L){luaD_checkstack(L,1);L->top++;} #define savestack(L,p)((char*)(p)-(char*)L->stack) #define restorestack(L,n)((TValue*)((char*)L->stack+(n))) #define saveci(L,p)((char*)(p)-(char*)L->base_ci) #define restoreci(L,n)((CallInfo*)((char*)L->base_ci+(n))) typedef void(*Pfunc)(lua_State*L,void*ud); static int luaD_poscall(lua_State*L,StkId firstResult); static void luaD_reallocCI(lua_State*L,int newsize); static void luaD_reallocstack(lua_State*L,int newsize); static void luaD_growstack(lua_State*L,int n); static void luaD_throw(lua_State*L,int errcode); static void*luaM_growaux_(lua_State*L,void*block,int*size,size_t size_elems, int limit,const char*errormsg){ void*newblock; int newsize; if(*size>=limit/2){ if(*size>=limit) luaG_runerror(L,errormsg); newsize=limit; } else{ newsize=(*size)*2; if(newsize<4) newsize=4; } newblock=luaM_reallocv(L,block,*size,newsize,size_elems); *size=newsize; return newblock; } static void*luaM_toobig(lua_State*L){ luaG_runerror(L,"memory allocation error: block too big"); return NULL; } static void*luaM_realloc_(lua_State*L,void*block,size_t osize,size_t nsize){ global_State*g=G(L); block=(*g->frealloc)(g->ud,block,osize,nsize); if(block==NULL&&nsize>0) luaD_throw(L,4); g->totalbytes=(g->totalbytes-osize)+nsize; return block; } #define resetbits(x,m)((x)&=cast(lu_byte,~(m))) #define setbits(x,m)((x)|=(m)) #define testbits(x,m)((x)&(m)) #define bitmask(b)(1<<(b)) #define bit2mask(b1,b2)(bitmask(b1)|bitmask(b2)) #define l_setbit(x,b)setbits(x,bitmask(b)) #define resetbit(x,b)resetbits(x,bitmask(b)) #define testbit(x,b)testbits(x,bitmask(b)) #define set2bits(x,b1,b2)setbits(x,(bit2mask(b1,b2))) #define reset2bits(x,b1,b2)resetbits(x,(bit2mask(b1,b2))) #define test2bits(x,b1,b2)testbits(x,(bit2mask(b1,b2))) #define iswhite(x)test2bits((x)->gch.marked,0,1) #define isblack(x)testbit((x)->gch.marked,2) #define isgray(x)(!isblack(x)&&!iswhite(x)) #define otherwhite(g)(g->currentwhite^bit2mask(0,1)) #define isdead(g,v)((v)->gch.marked&otherwhite(g)&bit2mask(0,1)) #define changewhite(x)((x)->gch.marked^=bit2mask(0,1)) #define gray2black(x)l_setbit((x)->gch.marked,2) #define valiswhite(x)(iscollectable(x)&&iswhite(gcvalue(x))) #define luaC_white(g)cast(lu_byte,(g)->currentwhite&bit2mask(0,1)) #define luaC_checkGC(L){condhardstacktests(luaD_reallocstack(L,L->stacksize-5-1));if(G(L)->totalbytes>=G(L)->GCthreshold)luaC_step(L);} #define luaC_barrier(L,p,v){if(valiswhite(v)&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),gcvalue(v));} #define luaC_barriert(L,t,v){if(valiswhite(v)&&isblack(obj2gco(t)))luaC_barrierback(L,t);} #define luaC_objbarrier(L,p,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(p)))luaC_barrierf(L,obj2gco(p),obj2gco(o));} #define luaC_objbarriert(L,t,o){if(iswhite(obj2gco(o))&&isblack(obj2gco(t)))luaC_barrierback(L,t);} static void luaC_step(lua_State*L); static void luaC_link(lua_State*L,GCObject*o,lu_byte tt); static void luaC_linkupval(lua_State*L,UpVal*uv); static void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v); static void luaC_barrierback(lua_State*L,Table*t); #define sizestring(s)(sizeof(union TString)+((s)->len+1)*sizeof(char)) #define sizeudata(u)(sizeof(union Udata)+(u)->len) #define luaS_new(L,s)(luaS_newlstr(L,s,strlen(s))) #define luaS_newliteral(L,s)(luaS_newlstr(L,""s,(sizeof(s)/sizeof(char))-1)) #define luaS_fix(s)l_setbit((s)->tsv.marked,5) static TString*luaS_newlstr(lua_State*L,const char*str,size_t l); #define tostring(L,o)((ttype(o)==4)||(luaV_tostring(L,o))) #define tonumber(o,n)(ttype(o)==3||(((o)=luaV_tonumber(o,n))!=NULL)) #define equalobj(L,o1,o2)(ttype(o1)==ttype(o2)&&luaV_equalval(L,o1,o2)) static int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2); static const TValue*luaV_tonumber(const TValue*obj,TValue*n); static int luaV_tostring(lua_State*L,StkId obj); static void luaV_execute(lua_State*L,int nexeccalls); static void luaV_concat(lua_State*L,int total,int last); static const TValue luaO_nilobject_={{NULL},0}; static int luaO_int2fb(unsigned int x){ int e=0; while(x>=16){ x=(x+1)>>1; e++; } if(x<8)return x; else return((e+1)<<3)|(cast_int(x)-8); } static int luaO_fb2int(int x){ int e=(x>>3)&31; if(e==0)return x; else return((x&7)+8)<<(e-1); } static int luaO_log2(unsigned int x){ static const lu_byte log_2[256]={ 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8 }; int l=-1; while(x>=256){l+=8;x>>=8;} return l+log_2[x]; } static int luaO_rawequalObj(const TValue*t1,const TValue*t2){ if(ttype(t1)!=ttype(t2))return 0; else switch(ttype(t1)){ case 0: return 1; case 3: return luai_numeq(nvalue(t1),nvalue(t2)); case 1: return bvalue(t1)==bvalue(t2); case 2: return pvalue(t1)==pvalue(t2); default: return gcvalue(t1)==gcvalue(t2); } } static int luaO_str2d(const char*s,lua_Number*result){ char*endptr; *result=lua_str2number(s,&endptr); if(endptr==s)return 0; if(*endptr=='x'||*endptr=='X') *result=cast_num(strtoul(s,&endptr,16)); if(*endptr=='\0')return 1; while(isspace(cast(unsigned char,*endptr)))endptr++; if(*endptr!='\0')return 0; return 1; } static void pushstr(lua_State*L,const char*str){ setsvalue(L,L->top,luaS_new(L,str)); incr_top(L); } static const char*luaO_pushvfstring(lua_State*L,const char*fmt,va_list argp){ int n=1; pushstr(L,""); for(;;){ const char*e=strchr(fmt,'%'); if(e==NULL)break; setsvalue(L,L->top,luaS_newlstr(L,fmt,e-fmt)); incr_top(L); switch(*(e+1)){ case's':{ const char*s=va_arg(argp,char*); if(s==NULL)s="(null)"; pushstr(L,s); break; } case'c':{ char buff[2]; buff[0]=cast(char,va_arg(argp,int)); buff[1]='\0'; pushstr(L,buff); break; } case'd':{ setnvalue(L->top,cast_num(va_arg(argp,int))); incr_top(L); break; } case'f':{ setnvalue(L->top,cast_num(va_arg(argp,l_uacNumber))); incr_top(L); break; } case'p':{ char buff[4*sizeof(void*)+8]; sprintf(buff,"%p",va_arg(argp,void*)); pushstr(L,buff); break; } case'%':{ pushstr(L,"%"); break; } default:{ char buff[3]; buff[0]='%'; buff[1]=*(e+1); buff[2]='\0'; pushstr(L,buff); break; } } n+=2; fmt=e+2; } pushstr(L,fmt); luaV_concat(L,n+1,cast_int(L->top-L->base)-1); L->top-=n; return svalue(L->top-1); } static const char*luaO_pushfstring(lua_State*L,const char*fmt,...){ const char*msg; va_list argp; va_start(argp,fmt); msg=luaO_pushvfstring(L,fmt,argp); va_end(argp); return msg; } static void luaO_chunkid(char*out,const char*source,size_t bufflen){ if(*source=='='){ strncpy(out,source+1,bufflen); out[bufflen-1]='\0'; } else{ if(*source=='@'){ size_t l; source++; bufflen-=sizeof(" '...' "); l=strlen(source); strcpy(out,""); if(l>bufflen){ source+=(l-bufflen); strcat(out,"..."); } strcat(out,source); } else{ size_t len=strcspn(source,"\n\r"); bufflen-=sizeof(" [string \"...\"] "); if(len>bufflen)len=bufflen; strcpy(out,"[string \""); if(source[len]!='\0'){ strncat(out,source,len); strcat(out,"..."); } else strcat(out,source); strcat(out,"\"]"); } } } #define gnode(t,i)(&(t)->node[i]) #define gkey(n)(&(n)->i_key.nk) #define gval(n)(&(n)->i_val) #define gnext(n)((n)->i_key.nk.next) #define key2tval(n)(&(n)->i_key.tvk) static TValue*luaH_setnum(lua_State*L,Table*t,int key); static const TValue*luaH_getstr(Table*t,TString*key); static TValue*luaH_set(lua_State*L,Table*t,const TValue*key); static const char*const luaT_typenames[]={ "nil","boolean","userdata","number", "string","table","function","userdata","thread", "proto","upval" }; static void luaT_init(lua_State*L){ static const char*const luaT_eventname[]={ "__index","__newindex", "__gc","__mode","__eq", "__add","__sub","__mul","__div","__mod", "__pow","__unm","__len","__lt","__le", "__concat","__call" }; int i; for(i=0;i<TM_N;i++){ G(L)->tmname[i]=luaS_new(L,luaT_eventname[i]); luaS_fix(G(L)->tmname[i]); } } static const TValue*luaT_gettm(Table*events,TMS event,TString*ename){ const TValue*tm=luaH_getstr(events,ename); if(ttisnil(tm)){ events->flags|=cast_byte(1u<<event); return NULL; } else return tm; } static const TValue*luaT_gettmbyobj(lua_State*L,const TValue*o,TMS event){ Table*mt; switch(ttype(o)){ case 5: mt=hvalue(o)->metatable; break; case 7: mt=uvalue(o)->metatable; break; default: mt=G(L)->mt[ttype(o)]; } return(mt?luaH_getstr(mt,G(L)->tmname[event]):(&luaO_nilobject_)); } #define sizeCclosure(n)(cast(int,sizeof(CClosure))+cast(int,sizeof(TValue)*((n)-1))) #define sizeLclosure(n)(cast(int,sizeof(LClosure))+cast(int,sizeof(TValue*)*((n)-1))) static Closure*luaF_newCclosure(lua_State*L,int nelems,Table*e){ Closure*c=cast(Closure*,luaM_malloc(L,sizeCclosure(nelems))); luaC_link(L,obj2gco(c),6); c->c.isC=1; c->c.env=e; c->c.nupvalues=cast_byte(nelems); return c; } static Closure*luaF_newLclosure(lua_State*L,int nelems,Table*e){ Closure*c=cast(Closure*,luaM_malloc(L,sizeLclosure(nelems))); luaC_link(L,obj2gco(c),6); c->l.isC=0; c->l.env=e; c->l.nupvalues=cast_byte(nelems); while(nelems--)c->l.upvals[nelems]=NULL; return c; } static UpVal*luaF_newupval(lua_State*L){ UpVal*uv=luaM_new(L,UpVal); luaC_link(L,obj2gco(uv),(8+2)); uv->v=&uv->u.value; setnilvalue(uv->v); return uv; } static UpVal*luaF_findupval(lua_State*L,StkId level){ global_State*g=G(L); GCObject**pp=&L->openupval; UpVal*p; UpVal*uv; while(*pp!=NULL&&(p=ngcotouv(*pp))->v>=level){ if(p->v==level){ if(isdead(g,obj2gco(p))) changewhite(obj2gco(p)); return p; } pp=&p->next; } uv=luaM_new(L,UpVal); uv->tt=(8+2); uv->marked=luaC_white(g); uv->v=level; uv->next=*pp; *pp=obj2gco(uv); uv->u.l.prev=&g->uvhead; uv->u.l.next=g->uvhead.u.l.next; uv->u.l.next->u.l.prev=uv; g->uvhead.u.l.next=uv; return uv; } static void unlinkupval(UpVal*uv){ uv->u.l.next->u.l.prev=uv->u.l.prev; uv->u.l.prev->u.l.next=uv->u.l.next; } static void luaF_freeupval(lua_State*L,UpVal*uv){ if(uv->v!=&uv->u.value) unlinkupval(uv); luaM_free(L,uv); } static void luaF_close(lua_State*L,StkId level){ UpVal*uv; global_State*g=G(L); while(L->openupval!=NULL&&(uv=ngcotouv(L->openupval))->v>=level){ GCObject*o=obj2gco(uv); L->openupval=uv->next; if(isdead(g,o)) luaF_freeupval(L,uv); else{ unlinkupval(uv); setobj(L,&uv->u.value,uv->v); uv->v=&uv->u.value; luaC_linkupval(L,uv); } } } static Proto*luaF_newproto(lua_State*L){ Proto*f=luaM_new(L,Proto); luaC_link(L,obj2gco(f),(8+1)); f->k=NULL; f->sizek=0; f->p=NULL; f->sizep=0; f->code=NULL; f->sizecode=0; f->sizelineinfo=0; f->sizeupvalues=0; f->nups=0; f->upvalues=NULL; f->numparams=0; f->is_vararg=0; f->maxstacksize=0; f->lineinfo=NULL; f->sizelocvars=0; f->locvars=NULL; f->linedefined=0; f->lastlinedefined=0; f->source=NULL; return f; } static void luaF_freeproto(lua_State*L,Proto*f){ luaM_freearray(L,f->code,f->sizecode,Instruction); luaM_freearray(L,f->p,f->sizep,Proto*); luaM_freearray(L,f->k,f->sizek,TValue); luaM_freearray(L,f->lineinfo,f->sizelineinfo,int); luaM_freearray(L,f->locvars,f->sizelocvars,struct LocVar); luaM_freearray(L,f->upvalues,f->sizeupvalues,TString*); luaM_free(L,f); } static void luaF_freeclosure(lua_State*L,Closure*c){ int size=(c->c.isC)?sizeCclosure(c->c.nupvalues): sizeLclosure(c->l.nupvalues); luaM_freemem(L,c,size); } #define MASK1(n,p)((~((~(Instruction)0)<<n))<<p) #define MASK0(n,p)(~MASK1(n,p)) #define GET_OPCODE(i)(cast(OpCode,((i)>>0)&MASK1(6,0))) #define SET_OPCODE(i,o)((i)=(((i)&MASK0(6,0))|((cast(Instruction,o)<<0)&MASK1(6,0)))) #define GETARG_A(i)(cast(int,((i)>>(0+6))&MASK1(8,0))) #define SETARG_A(i,u)((i)=(((i)&MASK0(8,(0+6)))|((cast(Instruction,u)<<(0+6))&MASK1(8,(0+6))))) #define GETARG_B(i)(cast(int,((i)>>(((0+6)+8)+9))&MASK1(9,0))) #define SETARG_B(i,b)((i)=(((i)&MASK0(9,(((0+6)+8)+9)))|((cast(Instruction,b)<<(((0+6)+8)+9))&MASK1(9,(((0+6)+8)+9))))) #define GETARG_C(i)(cast(int,((i)>>((0+6)+8))&MASK1(9,0))) #define SETARG_C(i,b)((i)=(((i)&MASK0(9,((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1(9,((0+6)+8))))) #define GETARG_Bx(i)(cast(int,((i)>>((0+6)+8))&MASK1((9+9),0))) #define SETARG_Bx(i,b)((i)=(((i)&MASK0((9+9),((0+6)+8)))|((cast(Instruction,b)<<((0+6)+8))&MASK1((9+9),((0+6)+8))))) #define GETARG_sBx(i)(GETARG_Bx(i)-(((1<<(9+9))-1)>>1)) #define SETARG_sBx(i,b)SETARG_Bx((i),cast(unsigned int,(b)+(((1<<(9+9))-1)>>1))) #define CREATE_ABC(o,a,b,c)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,b)<<(((0+6)+8)+9))|(cast(Instruction,c)<<((0+6)+8))) #define CREATE_ABx(o,a,bc)((cast(Instruction,o)<<0)|(cast(Instruction,a)<<(0+6))|(cast(Instruction,bc)<<((0+6)+8))) #define ISK(x)((x)&(1<<(9-1))) #define INDEXK(r)((int)(r)&~(1<<(9-1))) #define RKASK(x)((x)|(1<<(9-1))) static const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)]; #define getBMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>4)&3)) #define getCMode(m)(cast(enum OpArgMask,(luaP_opmodes[m]>>2)&3)) #define testTMode(m)(luaP_opmodes[m]&(1<<7)) typedef struct expdesc{ expkind k; union{ struct{int info,aux;}s; lua_Number nval; }u; int t; int f; }expdesc; typedef struct upvaldesc{ lu_byte k; lu_byte info; }upvaldesc; struct BlockCnt; typedef struct FuncState{ Proto*f; Table*h; struct FuncState*prev; struct LexState*ls; struct lua_State*L; struct BlockCnt*bl; int pc; int lasttarget; int jpc; int freereg; int nk; int np; short nlocvars; lu_byte nactvar; upvaldesc upvalues[60]; unsigned short actvar[200]; }FuncState; static Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff, const char*name); struct lua_longjmp{ struct lua_longjmp*previous; jmp_buf b; volatile int status; }; static void luaD_seterrorobj(lua_State*L,int errcode,StkId oldtop){ switch(errcode){ case 4:{ setsvalue(L,oldtop,luaS_newliteral(L,"not enough memory")); break; } case 5:{ setsvalue(L,oldtop,luaS_newliteral(L,"error in error handling")); break; } case 3: case 2:{ setobj(L,oldtop,L->top-1); break; } } L->top=oldtop+1; } static void restore_stack_limit(lua_State*L){ if(L->size_ci>20000){ int inuse=cast_int(L->ci-L->base_ci); if(inuse+1<20000) luaD_reallocCI(L,20000); } } static void resetstack(lua_State*L,int status){ L->ci=L->base_ci; L->base=L->ci->base; luaF_close(L,L->base); luaD_seterrorobj(L,status,L->base); L->nCcalls=L->baseCcalls; L->allowhook=1; restore_stack_limit(L); L->errfunc=0; L->errorJmp=NULL; } static void luaD_throw(lua_State*L,int errcode){ if(L->errorJmp){ L->errorJmp->status=errcode; LUAI_THROW(L,L->errorJmp); } else{ L->status=cast_byte(errcode); if(G(L)->panic){ resetstack(L,errcode); G(L)->panic(L); } exit(EXIT_FAILURE); } } static int luaD_rawrunprotected(lua_State*L,Pfunc f,void*ud){ struct lua_longjmp lj; lj.status=0; lj.previous=L->errorJmp; L->errorJmp=&lj; LUAI_TRY(L,&lj, (*f)(L,ud); ); L->errorJmp=lj.previous; return lj.status; } static void correctstack(lua_State*L,TValue*oldstack){ CallInfo*ci; GCObject*up; L->top=(L->top-oldstack)+L->stack; for(up=L->openupval;up!=NULL;up=up->gch.next) gco2uv(up)->v=(gco2uv(up)->v-oldstack)+L->stack; for(ci=L->base_ci;ci<=L->ci;ci++){ ci->top=(ci->top-oldstack)+L->stack; ci->base=(ci->base-oldstack)+L->stack; ci->func=(ci->func-oldstack)+L->stack; } L->base=(L->base-oldstack)+L->stack; } static void luaD_reallocstack(lua_State*L,int newsize){ TValue*oldstack=L->stack; int realsize=newsize+1+5; luaM_reallocvector(L,L->stack,L->stacksize,realsize,TValue); L->stacksize=realsize; L->stack_last=L->stack+newsize; correctstack(L,oldstack); } static void luaD_reallocCI(lua_State*L,int newsize){ CallInfo*oldci=L->base_ci; luaM_reallocvector(L,L->base_ci,L->size_ci,newsize,CallInfo); L->size_ci=newsize; L->ci=(L->ci-oldci)+L->base_ci; L->end_ci=L->base_ci+L->size_ci-1; } static void luaD_growstack(lua_State*L,int n){ if(n<=L->stacksize) luaD_reallocstack(L,2*L->stacksize); else luaD_reallocstack(L,L->stacksize+n); } static CallInfo*growCI(lua_State*L){ if(L->size_ci>20000) luaD_throw(L,5); else{ luaD_reallocCI(L,2*L->size_ci); if(L->size_ci>20000) luaG_runerror(L,"stack overflow"); } return++L->ci; } static StkId adjust_varargs(lua_State*L,Proto*p,int actual){ int i; int nfixargs=p->numparams; Table*htab=NULL; StkId base,fixed; for(;actual<nfixargs;++actual) setnilvalue(L->top++); fixed=L->top-actual; base=L->top; for(i=0;i<nfixargs;i++){ setobj(L,L->top++,fixed+i); setnilvalue(fixed+i); } if(htab){ sethvalue(L,L->top++,htab); } return base; } static StkId tryfuncTM(lua_State*L,StkId func){ const TValue*tm=luaT_gettmbyobj(L,func,TM_CALL); StkId p; ptrdiff_t funcr=savestack(L,func); if(!ttisfunction(tm)) luaG_typeerror(L,func,"call"); for(p=L->top;p>func;p--)setobj(L,p,p-1); incr_top(L); func=restorestack(L,funcr); setobj(L,func,tm); return func; } #define inc_ci(L)((L->ci==L->end_ci)?growCI(L):(condhardstacktests(luaD_reallocCI(L,L->size_ci)),++L->ci)) static int luaD_precall(lua_State*L,StkId func,int nresults){ LClosure*cl; ptrdiff_t funcr; if(!ttisfunction(func)) func=tryfuncTM(L,func); funcr=savestack(L,func); cl=&clvalue(func)->l; L->ci->savedpc=L->savedpc; if(!cl->isC){ CallInfo*ci; StkId st,base; Proto*p=cl->p; luaD_checkstack(L,p->maxstacksize); func=restorestack(L,funcr); if(!p->is_vararg){ base=func+1; if(L->top>base+p->numparams) L->top=base+p->numparams; } else{ int nargs=cast_int(L->top-func)-1; base=adjust_varargs(L,p,nargs); func=restorestack(L,funcr); } ci=inc_ci(L); ci->func=func; L->base=ci->base=base; ci->top=L->base+p->maxstacksize; L->savedpc=p->code; ci->tailcalls=0; ci->nresults=nresults; for(st=L->top;st<ci->top;st++) setnilvalue(st); L->top=ci->top; return 0; } else{ CallInfo*ci; int n; luaD_checkstack(L,20); ci=inc_ci(L); ci->func=restorestack(L,funcr); L->base=ci->base=ci->func+1; ci->top=L->top+20; ci->nresults=nresults; n=(*curr_func(L)->c.f)(L); if(n<0) return 2; else{ luaD_poscall(L,L->top-n); return 1; } } } static int luaD_poscall(lua_State*L,StkId firstResult){ StkId res; int wanted,i; CallInfo*ci; ci=L->ci--; res=ci->func; wanted=ci->nresults; L->base=(ci-1)->base; L->savedpc=(ci-1)->savedpc; for(i=wanted;i!=0&&firstResult<L->top;i--) setobj(L,res++,firstResult++); while(i-->0) setnilvalue(res++); L->top=res; return(wanted-(-1)); } static void luaD_call(lua_State*L,StkId func,int nResults){ if(++L->nCcalls>=200){ if(L->nCcalls==200) luaG_runerror(L,"C stack overflow"); else if(L->nCcalls>=(200+(200>>3))) luaD_throw(L,5); } if(luaD_precall(L,func,nResults)==0) luaV_execute(L,1); L->nCcalls--; luaC_checkGC(L); } static int luaD_pcall(lua_State*L,Pfunc func,void*u, ptrdiff_t old_top,ptrdiff_t ef){ int status; unsigned short oldnCcalls=L->nCcalls; ptrdiff_t old_ci=saveci(L,L->ci); lu_byte old_allowhooks=L->allowhook; ptrdiff_t old_errfunc=L->errfunc; L->errfunc=ef; status=luaD_rawrunprotected(L,func,u); if(status!=0){ StkId oldtop=restorestack(L,old_top); luaF_close(L,oldtop); luaD_seterrorobj(L,status,oldtop); L->nCcalls=oldnCcalls; L->ci=restoreci(L,old_ci); L->base=L->ci->base; L->savedpc=L->ci->savedpc; L->allowhook=old_allowhooks; restore_stack_limit(L); } L->errfunc=old_errfunc; return status; } struct SParser{ ZIO*z; Mbuffer buff; const char*name; }; static void f_parser(lua_State*L,void*ud){ int i; Proto*tf; Closure*cl; struct SParser*p=cast(struct SParser*,ud); luaC_checkGC(L); tf=luaY_parser(L,p->z, &p->buff,p->name); cl=luaF_newLclosure(L,tf->nups,hvalue(gt(L))); cl->l.p=tf; for(i=0;i<tf->nups;i++) cl->l.upvals[i]=luaF_newupval(L); setclvalue(L,L->top,cl); incr_top(L); } static int luaD_protectedparser(lua_State*L,ZIO*z,const char*name){ struct SParser p; int status; p.z=z;p.name=name; luaZ_initbuffer(L,&p.buff); status=luaD_pcall(L,f_parser,&p,savestack(L,L->top),L->errfunc); luaZ_freebuffer(L,&p.buff); return status; } static void luaS_resize(lua_State*L,int newsize){ GCObject**newhash; stringtable*tb; int i; if(G(L)->gcstate==2) return; newhash=luaM_newvector(L,newsize,GCObject*); tb=&G(L)->strt; for(i=0;i<newsize;i++)newhash[i]=NULL; for(i=0;i<tb->size;i++){ GCObject*p=tb->hash[i]; while(p){ GCObject*next=p->gch.next; unsigned int h=gco2ts(p)->hash; int h1=lmod(h,newsize); p->gch.next=newhash[h1]; newhash[h1]=p; p=next; } } luaM_freearray(L,tb->hash,tb->size,TString*); tb->size=newsize; tb->hash=newhash; } static TString*newlstr(lua_State*L,const char*str,size_t l, unsigned int h){ TString*ts; stringtable*tb; if(l+1>(((size_t)(~(size_t)0)-2)-sizeof(TString))/sizeof(char)) luaM_toobig(L); ts=cast(TString*,luaM_malloc(L,(l+1)*sizeof(char)+sizeof(TString))); ts->tsv.len=l; ts->tsv.hash=h; ts->tsv.marked=luaC_white(G(L)); ts->tsv.tt=4; ts->tsv.reserved=0; memcpy(ts+1,str,l*sizeof(char)); ((char*)(ts+1))[l]='\0'; tb=&G(L)->strt; h=lmod(h,tb->size); ts->tsv.next=tb->hash[h]; tb->hash[h]=obj2gco(ts); tb->nuse++; if(tb->nuse>cast(lu_int32,tb->size)&&tb->size<=(INT_MAX-2)/2) luaS_resize(L,tb->size*2); return ts; } static TString*luaS_newlstr(lua_State*L,const char*str,size_t l){ GCObject*o; unsigned int h=cast(unsigned int,l); size_t step=(l>>5)+1; size_t l1; for(l1=l;l1>=step;l1-=step) h=h^((h<<5)+(h>>2)+cast(unsigned char,str[l1-1])); for(o=G(L)->strt.hash[lmod(h,G(L)->strt.size)]; o!=NULL; o=o->gch.next){ TString*ts=rawgco2ts(o); if(ts->tsv.len==l&&(memcmp(str,getstr(ts),l)==0)){ if(isdead(G(L),o))changewhite(o); return ts; } } return newlstr(L,str,l,h); } static Udata*luaS_newudata(lua_State*L,size_t s,Table*e){ Udata*u; if(s>((size_t)(~(size_t)0)-2)-sizeof(Udata)) luaM_toobig(L); u=cast(Udata*,luaM_malloc(L,s+sizeof(Udata))); u->uv.marked=luaC_white(G(L)); u->uv.tt=7; u->uv.len=s; u->uv.metatable=NULL; u->uv.env=e; u->uv.next=G(L)->mainthread->next; G(L)->mainthread->next=obj2gco(u); return u; } #define hashpow2(t,n)(gnode(t,lmod((n),sizenode(t)))) #define hashstr(t,str)hashpow2(t,(str)->tsv.hash) #define hashboolean(t,p)hashpow2(t,p) #define hashmod(t,n)(gnode(t,((n)%((sizenode(t)-1)|1)))) #define hashpointer(t,p)hashmod(t,IntPoint(p)) static const Node dummynode_={ {{NULL},0}, {{{NULL},0,NULL}} }; static Node*hashnum(const Table*t,lua_Number n){ unsigned int a[cast_int(sizeof(lua_Number)/sizeof(int))]; int i; if(luai_numeq(n,0)) return gnode(t,0); memcpy(a,&n,sizeof(a)); for(i=1;i<cast_int(sizeof(lua_Number)/sizeof(int));i++)a[0]+=a[i]; return hashmod(t,a[0]); } static Node*mainposition(const Table*t,const TValue*key){ switch(ttype(key)){ case 3: return hashnum(t,nvalue(key)); case 4: return hashstr(t,rawtsvalue(key)); case 1: return hashboolean(t,bvalue(key)); case 2: return hashpointer(t,pvalue(key)); default: return hashpointer(t,gcvalue(key)); } } static int arrayindex(const TValue*key){ if(ttisnumber(key)){ lua_Number n=nvalue(key); int k; lua_number2int(k,n); if(luai_numeq(cast_num(k),n)) return k; } return-1; } static int findindex(lua_State*L,Table*t,StkId key){ int i; if(ttisnil(key))return-1; i=arrayindex(key); if(0<i&&i<=t->sizearray) return i-1; else{ Node*n=mainposition(t,key); do{ if(luaO_rawequalObj(key2tval(n),key)|| (ttype(gkey(n))==(8+3)&&iscollectable(key)&& gcvalue(gkey(n))==gcvalue(key))){ i=cast_int(n-gnode(t,0)); return i+t->sizearray; } else n=gnext(n); }while(n); luaG_runerror(L,"invalid key to "LUA_QL("next")); return 0; } } static int luaH_next(lua_State*L,Table*t,StkId key){ int i=findindex(L,t,key); for(i++;i<t->sizearray;i++){ if(!ttisnil(&t->array[i])){ setnvalue(key,cast_num(i+1)); setobj(L,key+1,&t->array[i]); return 1; } } for(i-=t->sizearray;i<(int)sizenode(t);i++){ if(!ttisnil(gval(gnode(t,i)))){ setobj(L,key,key2tval(gnode(t,i))); setobj(L,key+1,gval(gnode(t,i))); return 1; } } return 0; } static int computesizes(int nums[],int*narray){ int i; int twotoi; int a=0; int na=0; int n=0; for(i=0,twotoi=1;twotoi/2<*narray;i++,twotoi*=2){ if(nums[i]>0){ a+=nums[i]; if(a>twotoi/2){ n=twotoi; na=a; } } if(a==*narray)break; } *narray=n; return na; } static int countint(const TValue*key,int*nums){ int k=arrayindex(key); if(0<k&&k<=(1<<(32-2))){ nums[ceillog2(k)]++; return 1; } else return 0; } static int numusearray(const Table*t,int*nums){ int lg; int ttlg; int ause=0; int i=1; for(lg=0,ttlg=1;lg<=(32-2);lg++,ttlg*=2){ int lc=0; int lim=ttlg; if(lim>t->sizearray){ lim=t->sizearray; if(i>lim) break; } for(;i<=lim;i++){ if(!ttisnil(&t->array[i-1])) lc++; } nums[lg]+=lc; ause+=lc; } return ause; } static int numusehash(const Table*t,int*nums,int*pnasize){ int totaluse=0; int ause=0; int i=sizenode(t); while(i--){ Node*n=&t->node[i]; if(!ttisnil(gval(n))){ ause+=countint(key2tval(n),nums); totaluse++; } } *pnasize+=ause; return totaluse; } static void setarrayvector(lua_State*L,Table*t,int size){ int i; luaM_reallocvector(L,t->array,t->sizearray,size,TValue); for(i=t->sizearray;i<size;i++) setnilvalue(&t->array[i]); t->sizearray=size; } static void setnodevector(lua_State*L,Table*t,int size){ int lsize; if(size==0){ t->node=cast(Node*,(&dummynode_)); lsize=0; } else{ int i; lsize=ceillog2(size); if(lsize>(32-2)) luaG_runerror(L,"table overflow"); size=twoto(lsize); t->node=luaM_newvector(L,size,Node); for(i=0;i<size;i++){ Node*n=gnode(t,i); gnext(n)=NULL; setnilvalue(gkey(n)); setnilvalue(gval(n)); } } t->lsizenode=cast_byte(lsize); t->lastfree=gnode(t,size); } static void resize(lua_State*L,Table*t,int nasize,int nhsize){ int i; int oldasize=t->sizearray; int oldhsize=t->lsizenode; Node*nold=t->node; if(nasize>oldasize) setarrayvector(L,t,nasize); setnodevector(L,t,nhsize); if(nasize<oldasize){ t->sizearray=nasize; for(i=nasize;i<oldasize;i++){ if(!ttisnil(&t->array[i])) setobj(L,luaH_setnum(L,t,i+1),&t->array[i]); } luaM_reallocvector(L,t->array,oldasize,nasize,TValue); } for(i=twoto(oldhsize)-1;i>=0;i--){ Node*old=nold+i; if(!ttisnil(gval(old))) setobj(L,luaH_set(L,t,key2tval(old)),gval(old)); } if(nold!=(&dummynode_)) luaM_freearray(L,nold,twoto(oldhsize),Node); } static void luaH_resizearray(lua_State*L,Table*t,int nasize){ int nsize=(t->node==(&dummynode_))?0:sizenode(t); resize(L,t,nasize,nsize); } static void rehash(lua_State*L,Table*t,const TValue*ek){ int nasize,na; int nums[(32-2)+1]; int i; int totaluse; for(i=0;i<=(32-2);i++)nums[i]=0; nasize=numusearray(t,nums); totaluse=nasize; totaluse+=numusehash(t,nums,&nasize); nasize+=countint(ek,nums); totaluse++; na=computesizes(nums,&nasize); resize(L,t,nasize,totaluse-na); } static Table*luaH_new(lua_State*L,int narray,int nhash){ Table*t=luaM_new(L,Table); luaC_link(L,obj2gco(t),5); t->metatable=NULL; t->flags=cast_byte(~0); t->array=NULL; t->sizearray=0; t->lsizenode=0; t->node=cast(Node*,(&dummynode_)); setarrayvector(L,t,narray); setnodevector(L,t,nhash); return t; } static void luaH_free(lua_State*L,Table*t){ if(t->node!=(&dummynode_)) luaM_freearray(L,t->node,sizenode(t),Node); luaM_freearray(L,t->array,t->sizearray,TValue); luaM_free(L,t); } static Node*getfreepos(Table*t){ while(t->lastfree-->t->node){ if(ttisnil(gkey(t->lastfree))) return t->lastfree; } return NULL; } static TValue*newkey(lua_State*L,Table*t,const TValue*key){ Node*mp=mainposition(t,key); if(!ttisnil(gval(mp))||mp==(&dummynode_)){ Node*othern; Node*n=getfreepos(t); if(n==NULL){ rehash(L,t,key); return luaH_set(L,t,key); } othern=mainposition(t,key2tval(mp)); if(othern!=mp){ while(gnext(othern)!=mp)othern=gnext(othern); gnext(othern)=n; *n=*mp; gnext(mp)=NULL; setnilvalue(gval(mp)); } else{ gnext(n)=gnext(mp); gnext(mp)=n; mp=n; } } gkey(mp)->value=key->value;gkey(mp)->tt=key->tt; luaC_barriert(L,t,key); return gval(mp); } static const TValue*luaH_getnum(Table*t,int key){ if(cast(unsigned int,key)-1<cast(unsigned int,t->sizearray)) return&t->array[key-1]; else{ lua_Number nk=cast_num(key); Node*n=hashnum(t,nk); do{ if(ttisnumber(gkey(n))&&luai_numeq(nvalue(gkey(n)),nk)) return gval(n); else n=gnext(n); }while(n); return(&luaO_nilobject_); } } static const TValue*luaH_getstr(Table*t,TString*key){ Node*n=hashstr(t,key); do{ if(ttisstring(gkey(n))&&rawtsvalue(gkey(n))==key) return gval(n); else n=gnext(n); }while(n); return(&luaO_nilobject_); } static const TValue*luaH_get(Table*t,const TValue*key){ switch(ttype(key)){ case 0:return(&luaO_nilobject_); case 4:return luaH_getstr(t,rawtsvalue(key)); case 3:{ int k; lua_Number n=nvalue(key); lua_number2int(k,n); if(luai_numeq(cast_num(k),nvalue(key))) return luaH_getnum(t,k); } default:{ Node*n=mainposition(t,key); do{ if(luaO_rawequalObj(key2tval(n),key)) return gval(n); else n=gnext(n); }while(n); return(&luaO_nilobject_); } } } static TValue*luaH_set(lua_State*L,Table*t,const TValue*key){ const TValue*p=luaH_get(t,key); t->flags=0; if(p!=(&luaO_nilobject_)) return cast(TValue*,p); else{ if(ttisnil(key))luaG_runerror(L,"table index is nil"); else if(ttisnumber(key)&&luai_numisnan(nvalue(key))) luaG_runerror(L,"table index is NaN"); return newkey(L,t,key); } } static TValue*luaH_setnum(lua_State*L,Table*t,int key){ const TValue*p=luaH_getnum(t,key); if(p!=(&luaO_nilobject_)) return cast(TValue*,p); else{ TValue k; setnvalue(&k,cast_num(key)); return newkey(L,t,&k); } } static TValue*luaH_setstr(lua_State*L,Table*t,TString*key){ const TValue*p=luaH_getstr(t,key); if(p!=(&luaO_nilobject_)) return cast(TValue*,p); else{ TValue k; setsvalue(L,&k,key); return newkey(L,t,&k); } } static int unbound_search(Table*t,unsigned int j){ unsigned int i=j; j++; while(!ttisnil(luaH_getnum(t,j))){ i=j; j*=2; if(j>cast(unsigned int,(INT_MAX-2))){ i=1; while(!ttisnil(luaH_getnum(t,i)))i++; return i-1; } } while(j-i>1){ unsigned int m=(i+j)/2; if(ttisnil(luaH_getnum(t,m)))j=m; else i=m; } return i; } static int luaH_getn(Table*t){ unsigned int j=t->sizearray; if(j>0&&ttisnil(&t->array[j-1])){ unsigned int i=0; while(j-i>1){ unsigned int m=(i+j)/2; if(ttisnil(&t->array[m-1]))j=m; else i=m; } return i; } else if(t->node==(&dummynode_)) return j; else return unbound_search(t,j); } #define makewhite(g,x)((x)->gch.marked=cast_byte(((x)->gch.marked&cast_byte(~(bitmask(2)|bit2mask(0,1))))|luaC_white(g))) #define white2gray(x)reset2bits((x)->gch.marked,0,1) #define black2gray(x)resetbit((x)->gch.marked,2) #define stringmark(s)reset2bits((s)->tsv.marked,0,1) #define isfinalized(u)testbit((u)->marked,3) #define markfinalized(u)l_setbit((u)->marked,3) #define markvalue(g,o){checkconsistency(o);if(iscollectable(o)&&iswhite(gcvalue(o)))reallymarkobject(g,gcvalue(o));} #define markobject(g,t){if(iswhite(obj2gco(t)))reallymarkobject(g,obj2gco(t));} #define setthreshold(g)(g->GCthreshold=(g->estimate/100)*g->gcpause) static void removeentry(Node*n){ if(iscollectable(gkey(n))) setttype(gkey(n),(8+3)); } static void reallymarkobject(global_State*g,GCObject*o){ white2gray(o); switch(o->gch.tt){ case 4:{ return; } case 7:{ Table*mt=gco2u(o)->metatable; gray2black(o); if(mt)markobject(g,mt); markobject(g,gco2u(o)->env); return; } case(8+2):{ UpVal*uv=gco2uv(o); markvalue(g,uv->v); if(uv->v==&uv->u.value) gray2black(o); return; } case 6:{ gco2cl(o)->c.gclist=g->gray; g->gray=o; break; } case 5:{ gco2h(o)->gclist=g->gray; g->gray=o; break; } case 8:{ gco2th(o)->gclist=g->gray; g->gray=o; break; } case(8+1):{ gco2p(o)->gclist=g->gray; g->gray=o; break; } default:; } } static void marktmu(global_State*g){ GCObject*u=g->tmudata; if(u){ do{ u=u->gch.next; makewhite(g,u); reallymarkobject(g,u); }while(u!=g->tmudata); } } static size_t luaC_separateudata(lua_State*L,int all){ global_State*g=G(L); size_t deadmem=0; GCObject**p=&g->mainthread->next; GCObject*curr; while((curr=*p)!=NULL){ if(!(iswhite(curr)||all)||isfinalized(gco2u(curr))) p=&curr->gch.next; else if(fasttm(L,gco2u(curr)->metatable,TM_GC)==NULL){ markfinalized(gco2u(curr)); p=&curr->gch.next; } else{ deadmem+=sizeudata(gco2u(curr)); markfinalized(gco2u(curr)); *p=curr->gch.next; if(g->tmudata==NULL) g->tmudata=curr->gch.next=curr; else{ curr->gch.next=g->tmudata->gch.next; g->tmudata->gch.next=curr; g->tmudata=curr; } } } return deadmem; } static int traversetable(global_State*g,Table*h){ int i; int weakkey=0; int weakvalue=0; const TValue*mode; if(h->metatable) markobject(g,h->metatable); mode=gfasttm(g,h->metatable,TM_MODE); if(mode&&ttisstring(mode)){ weakkey=(strchr(svalue(mode),'k')!=NULL); weakvalue=(strchr(svalue(mode),'v')!=NULL); if(weakkey||weakvalue){ h->marked&=~(bitmask(3)|bitmask(4)); h->marked|=cast_byte((weakkey<<3)| (weakvalue<<4)); h->gclist=g->weak; g->weak=obj2gco(h); } } if(weakkey&&weakvalue)return 1; if(!weakvalue){ i=h->sizearray; while(i--) markvalue(g,&h->array[i]); } i=sizenode(h); while(i--){ Node*n=gnode(h,i); if(ttisnil(gval(n))) removeentry(n); else{ if(!weakkey)markvalue(g,gkey(n)); if(!weakvalue)markvalue(g,gval(n)); } } return weakkey||weakvalue; } static void traverseproto(global_State*g,Proto*f){ int i; if(f->source)stringmark(f->source); for(i=0;i<f->sizek;i++) markvalue(g,&f->k[i]); for(i=0;i<f->sizeupvalues;i++){ if(f->upvalues[i]) stringmark(f->upvalues[i]); } for(i=0;i<f->sizep;i++){ if(f->p[i]) markobject(g,f->p[i]); } for(i=0;i<f->sizelocvars;i++){ if(f->locvars[i].varname) stringmark(f->locvars[i].varname); } } static void traverseclosure(global_State*g,Closure*cl){ markobject(g,cl->c.env); if(cl->c.isC){ int i; for(i=0;i<cl->c.nupvalues;i++) markvalue(g,&cl->c.upvalue[i]); } else{ int i; markobject(g,cl->l.p); for(i=0;i<cl->l.nupvalues;i++) markobject(g,cl->l.upvals[i]); } } static void checkstacksizes(lua_State*L,StkId max){ int ci_used=cast_int(L->ci-L->base_ci); int s_used=cast_int(max-L->stack); if(L->size_ci>20000) return; if(4*ci_used<L->size_ci&&2*8<L->size_ci) luaD_reallocCI(L,L->size_ci/2); condhardstacktests(luaD_reallocCI(L,ci_used+1)); if(4*s_used<L->stacksize&& 2*((2*20)+5)<L->stacksize) luaD_reallocstack(L,L->stacksize/2); condhardstacktests(luaD_reallocstack(L,s_used)); } static void traversestack(global_State*g,lua_State*l){ StkId o,lim; CallInfo*ci; markvalue(g,gt(l)); lim=l->top; for(ci=l->base_ci;ci<=l->ci;ci++){ if(lim<ci->top)lim=ci->top; } for(o=l->stack;o<l->top;o++) markvalue(g,o); for(;o<=lim;o++) setnilvalue(o); checkstacksizes(l,lim); } static l_mem propagatemark(global_State*g){ GCObject*o=g->gray; gray2black(o); switch(o->gch.tt){ case 5:{ Table*h=gco2h(o); g->gray=h->gclist; if(traversetable(g,h)) black2gray(o); return sizeof(Table)+sizeof(TValue)*h->sizearray+ sizeof(Node)*sizenode(h); } case 6:{ Closure*cl=gco2cl(o); g->gray=cl->c.gclist; traverseclosure(g,cl); return(cl->c.isC)?sizeCclosure(cl->c.nupvalues): sizeLclosure(cl->l.nupvalues); } case 8:{ lua_State*th=gco2th(o); g->gray=th->gclist; th->gclist=g->grayagain; g->grayagain=o; black2gray(o); traversestack(g,th); return sizeof(lua_State)+sizeof(TValue)*th->stacksize+ sizeof(CallInfo)*th->size_ci; } case(8+1):{ Proto*p=gco2p(o); g->gray=p->gclist; traverseproto(g,p); return sizeof(Proto)+sizeof(Instruction)*p->sizecode+ sizeof(Proto*)*p->sizep+ sizeof(TValue)*p->sizek+ sizeof(int)*p->sizelineinfo+ sizeof(LocVar)*p->sizelocvars+ sizeof(TString*)*p->sizeupvalues; } default:return 0; } } static size_t propagateall(global_State*g){ size_t m=0; while(g->gray)m+=propagatemark(g); return m; } static int iscleared(const TValue*o,int iskey){ if(!iscollectable(o))return 0; if(ttisstring(o)){ stringmark(rawtsvalue(o)); return 0; } return iswhite(gcvalue(o))|| (ttisuserdata(o)&&(!iskey&&isfinalized(uvalue(o)))); } static void cleartable(GCObject*l){ while(l){ Table*h=gco2h(l); int i=h->sizearray; if(testbit(h->marked,4)){ while(i--){ TValue*o=&h->array[i]; if(iscleared(o,0)) setnilvalue(o); } } i=sizenode(h); while(i--){ Node*n=gnode(h,i); if(!ttisnil(gval(n))&& (iscleared(key2tval(n),1)||iscleared(gval(n),0))){ setnilvalue(gval(n)); removeentry(n); } } l=h->gclist; } } static void freeobj(lua_State*L,GCObject*o){ switch(o->gch.tt){ case(8+1):luaF_freeproto(L,gco2p(o));break; case 6:luaF_freeclosure(L,gco2cl(o));break; case(8+2):luaF_freeupval(L,gco2uv(o));break; case 5:luaH_free(L,gco2h(o));break; case 8:{ luaE_freethread(L,gco2th(o)); break; } case 4:{ G(L)->strt.nuse--; luaM_freemem(L,o,sizestring(gco2ts(o))); break; } case 7:{ luaM_freemem(L,o,sizeudata(gco2u(o))); break; } default:; } } #define sweepwholelist(L,p)sweeplist(L,p,((lu_mem)(~(lu_mem)0)-2)) static GCObject**sweeplist(lua_State*L,GCObject**p,lu_mem count){ GCObject*curr; global_State*g=G(L); int deadmask=otherwhite(g); while((curr=*p)!=NULL&&count-->0){ if(curr->gch.tt==8) sweepwholelist(L,&gco2th(curr)->openupval); if((curr->gch.marked^bit2mask(0,1))&deadmask){ makewhite(g,curr); p=&curr->gch.next; } else{ *p=curr->gch.next; if(curr==g->rootgc) g->rootgc=curr->gch.next; freeobj(L,curr); } } return p; } static void checkSizes(lua_State*L){ global_State*g=G(L); if(g->strt.nuse<cast(lu_int32,g->strt.size/4)&& g->strt.size>32*2) luaS_resize(L,g->strt.size/2); if(luaZ_sizebuffer(&g->buff)>32*2){ size_t newsize=luaZ_sizebuffer(&g->buff)/2; luaZ_resizebuffer(L,&g->buff,newsize); } } static void GCTM(lua_State*L){ global_State*g=G(L); GCObject*o=g->tmudata->gch.next; Udata*udata=rawgco2u(o); const TValue*tm; if(o==g->tmudata) g->tmudata=NULL; else g->tmudata->gch.next=udata->uv.next; udata->uv.next=g->mainthread->next; g->mainthread->next=o; makewhite(g,o); tm=fasttm(L,udata->uv.metatable,TM_GC); if(tm!=NULL){ lu_byte oldah=L->allowhook; lu_mem oldt=g->GCthreshold; L->allowhook=0; g->GCthreshold=2*g->totalbytes; setobj(L,L->top,tm); setuvalue(L,L->top+1,udata); L->top+=2; luaD_call(L,L->top-2,0); L->allowhook=oldah; g->GCthreshold=oldt; } } static void luaC_callGCTM(lua_State*L){ while(G(L)->tmudata) GCTM(L); } static void luaC_freeall(lua_State*L){ global_State*g=G(L); int i; g->currentwhite=bit2mask(0,1)|bitmask(6); sweepwholelist(L,&g->rootgc); for(i=0;i<g->strt.size;i++) sweepwholelist(L,&g->strt.hash[i]); } static void markmt(global_State*g){ int i; for(i=0;i<(8+1);i++) if(g->mt[i])markobject(g,g->mt[i]); } static void markroot(lua_State*L){ global_State*g=G(L); g->gray=NULL; g->grayagain=NULL; g->weak=NULL; markobject(g,g->mainthread); markvalue(g,gt(g->mainthread)); markvalue(g,registry(L)); markmt(g); g->gcstate=1; } static void remarkupvals(global_State*g){ UpVal*uv; for(uv=g->uvhead.u.l.next;uv!=&g->uvhead;uv=uv->u.l.next){ if(isgray(obj2gco(uv))) markvalue(g,uv->v); } } static void atomic(lua_State*L){ global_State*g=G(L); size_t udsize; remarkupvals(g); propagateall(g); g->gray=g->weak; g->weak=NULL; markobject(g,L); markmt(g); propagateall(g); g->gray=g->grayagain; g->grayagain=NULL; propagateall(g); udsize=luaC_separateudata(L,0); marktmu(g); udsize+=propagateall(g); cleartable(g->weak); g->currentwhite=cast_byte(otherwhite(g)); g->sweepstrgc=0; g->sweepgc=&g->rootgc; g->gcstate=2; g->estimate=g->totalbytes-udsize; } static l_mem singlestep(lua_State*L){ global_State*g=G(L); switch(g->gcstate){ case 0:{ markroot(L); return 0; } case 1:{ if(g->gray) return propagatemark(g); else{ atomic(L); return 0; } } case 2:{ lu_mem old=g->totalbytes; sweepwholelist(L,&g->strt.hash[g->sweepstrgc++]); if(g->sweepstrgc>=g->strt.size) g->gcstate=3; g->estimate-=old-g->totalbytes; return 10; } case 3:{ lu_mem old=g->totalbytes; g->sweepgc=sweeplist(L,g->sweepgc,40); if(*g->sweepgc==NULL){ checkSizes(L); g->gcstate=4; } g->estimate-=old-g->totalbytes; return 40*10; } case 4:{ if(g->tmudata){ GCTM(L); if(g->estimate>100) g->estimate-=100; return 100; } else{ g->gcstate=0; g->gcdept=0; return 0; } } default:return 0; } } static void luaC_step(lua_State*L){ global_State*g=G(L); l_mem lim=(1024u/100)*g->gcstepmul; if(lim==0) lim=(((lu_mem)(~(lu_mem)0)-2)-1)/2; g->gcdept+=g->totalbytes-g->GCthreshold; do{ lim-=singlestep(L); if(g->gcstate==0) break; }while(lim>0); if(g->gcstate!=0){ if(g->gcdept<1024u) g->GCthreshold=g->totalbytes+1024u; else{ g->gcdept-=1024u; g->GCthreshold=g->totalbytes; } } else{ setthreshold(g); } } static void luaC_barrierf(lua_State*L,GCObject*o,GCObject*v){ global_State*g=G(L); if(g->gcstate==1) reallymarkobject(g,v); else makewhite(g,o); } static void luaC_barrierback(lua_State*L,Table*t){ global_State*g=G(L); GCObject*o=obj2gco(t); black2gray(o); t->gclist=g->grayagain; g->grayagain=o; } static void luaC_link(lua_State*L,GCObject*o,lu_byte tt){ global_State*g=G(L); o->gch.next=g->rootgc; g->rootgc=o; o->gch.marked=luaC_white(g); o->gch.tt=tt; } static void luaC_linkupval(lua_State*L,UpVal*uv){ global_State*g=G(L); GCObject*o=obj2gco(uv); o->gch.next=g->rootgc; g->rootgc=o; if(isgray(o)){ if(g->gcstate==1){ gray2black(o); luaC_barrier(L,uv,uv->v); } else{ makewhite(g,o); } } } typedef union{ lua_Number r; TString*ts; }SemInfo; typedef struct Token{ int token; SemInfo seminfo; }Token; typedef struct LexState{ int current; int linenumber; int lastline; Token t; Token lookahead; struct FuncState*fs; struct lua_State*L; ZIO*z; Mbuffer*buff; TString*source; char decpoint; }LexState; static void luaX_init(lua_State*L); static void luaX_lexerror(LexState*ls,const char*msg,int token); #define state_size(x)(sizeof(x)+0) #define fromstate(l)(cast(lu_byte*,(l))-0) #define tostate(l)(cast(lua_State*,cast(lu_byte*,l)+0)) typedef struct LG{ lua_State l; global_State g; }LG; static void stack_init(lua_State*L1,lua_State*L){ L1->base_ci=luaM_newvector(L,8,CallInfo); L1->ci=L1->base_ci; L1->size_ci=8; L1->end_ci=L1->base_ci+L1->size_ci-1; L1->stack=luaM_newvector(L,(2*20)+5,TValue); L1->stacksize=(2*20)+5; L1->top=L1->stack; L1->stack_last=L1->stack+(L1->stacksize-5)-1; L1->ci->func=L1->top; setnilvalue(L1->top++); L1->base=L1->ci->base=L1->top; L1->ci->top=L1->top+20; } static void freestack(lua_State*L,lua_State*L1){ luaM_freearray(L,L1->base_ci,L1->size_ci,CallInfo); luaM_freearray(L,L1->stack,L1->stacksize,TValue); } static void f_luaopen(lua_State*L,void*ud){ global_State*g=G(L); UNUSED(ud); stack_init(L,L); sethvalue(L,gt(L),luaH_new(L,0,2)); sethvalue(L,registry(L),luaH_new(L,0,2)); luaS_resize(L,32); luaT_init(L); luaX_init(L); luaS_fix(luaS_newliteral(L,"not enough memory")); g->GCthreshold=4*g->totalbytes; } static void preinit_state(lua_State*L,global_State*g){ G(L)=g; L->stack=NULL; L->stacksize=0; L->errorJmp=NULL; L->hook=NULL; L->hookmask=0; L->basehookcount=0; L->allowhook=1; resethookcount(L); L->openupval=NULL; L->size_ci=0; L->nCcalls=L->baseCcalls=0; L->status=0; L->base_ci=L->ci=NULL; L->savedpc=NULL; L->errfunc=0; setnilvalue(gt(L)); } static void close_state(lua_State*L){ global_State*g=G(L); luaF_close(L,L->stack); luaC_freeall(L); luaM_freearray(L,G(L)->strt.hash,G(L)->strt.size,TString*); luaZ_freebuffer(L,&g->buff); freestack(L,L); (*g->frealloc)(g->ud,fromstate(L),state_size(LG),0); } static void luaE_freethread(lua_State*L,lua_State*L1){ luaF_close(L1,L1->stack); freestack(L,L1); luaM_freemem(L,fromstate(L1),state_size(lua_State)); } static lua_State*lua_newstate(lua_Alloc f,void*ud){ int i; lua_State*L; global_State*g; void*l=(*f)(ud,NULL,0,state_size(LG)); if(l==NULL)return NULL; L=tostate(l); g=&((LG*)L)->g; L->next=NULL; L->tt=8; g->currentwhite=bit2mask(0,5); L->marked=luaC_white(g); set2bits(L->marked,5,6); preinit_state(L,g); g->frealloc=f; g->ud=ud; g->mainthread=L; g->uvhead.u.l.prev=&g->uvhead; g->uvhead.u.l.next=&g->uvhead; g->GCthreshold=0; g->strt.size=0; g->strt.nuse=0; g->strt.hash=NULL; setnilvalue(registry(L)); luaZ_initbuffer(L,&g->buff); g->panic=NULL; g->gcstate=0; g->rootgc=obj2gco(L); g->sweepstrgc=0; g->sweepgc=&g->rootgc; g->gray=NULL; g->grayagain=NULL; g->weak=NULL; g->tmudata=NULL; g->totalbytes=sizeof(LG); g->gcpause=200; g->gcstepmul=200; g->gcdept=0; for(i=0;i<(8+1);i++)g->mt[i]=NULL; if(luaD_rawrunprotected(L,f_luaopen,NULL)!=0){ close_state(L); L=NULL; } else {} return L; } static void callallgcTM(lua_State*L,void*ud){ UNUSED(ud); luaC_callGCTM(L); } static void lua_close(lua_State*L){ L=G(L)->mainthread; luaF_close(L,L->stack); luaC_separateudata(L,1); L->errfunc=0; do{ L->ci=L->base_ci; L->base=L->top=L->ci->base; L->nCcalls=L->baseCcalls=0; }while(luaD_rawrunprotected(L,callallgcTM,NULL)!=0); close_state(L); } #define getcode(fs,e)((fs)->f->code[(e)->u.s.info]) #define luaK_codeAsBx(fs,o,A,sBx)luaK_codeABx(fs,o,A,(sBx)+(((1<<(9+9))-1)>>1)) #define luaK_setmultret(fs,e)luaK_setreturns(fs,e,(-1)) static int luaK_codeABx(FuncState*fs,OpCode o,int A,unsigned int Bx); static int luaK_codeABC(FuncState*fs,OpCode o,int A,int B,int C); static void luaK_setreturns(FuncState*fs,expdesc*e,int nresults); static void luaK_patchtohere(FuncState*fs,int list); static void luaK_concat(FuncState*fs,int*l1,int l2); static int currentpc(lua_State*L,CallInfo*ci){ if(!isLua(ci))return-1; if(ci==L->ci) ci->savedpc=L->savedpc; return pcRel(ci->savedpc,ci_func(ci)->l.p); } static int currentline(lua_State*L,CallInfo*ci){ int pc=currentpc(L,ci); if(pc<0) return-1; else return getline_(ci_func(ci)->l.p,pc); } static int lua_getstack(lua_State*L,int level,lua_Debug*ar){ int status; CallInfo*ci; for(ci=L->ci;level>0&&ci>L->base_ci;ci--){ level--; if(f_isLua(ci)) level-=ci->tailcalls; } if(level==0&&ci>L->base_ci){ status=1; ar->i_ci=cast_int(ci-L->base_ci); } else if(level<0){ status=1; ar->i_ci=0; } else status=0; return status; } static Proto*getluaproto(CallInfo*ci){ return(isLua(ci)?ci_func(ci)->l.p:NULL); } static void funcinfo(lua_Debug*ar,Closure*cl){ if(cl->c.isC){ ar->source="=[C]"; ar->linedefined=-1; ar->lastlinedefined=-1; ar->what="C"; } else{ ar->source=getstr(cl->l.p->source); ar->linedefined=cl->l.p->linedefined; ar->lastlinedefined=cl->l.p->lastlinedefined; ar->what=(ar->linedefined==0)?"main":"Lua"; } luaO_chunkid(ar->short_src,ar->source,60); } static void info_tailcall(lua_Debug*ar){ ar->name=ar->namewhat=""; ar->what="tail"; ar->lastlinedefined=ar->linedefined=ar->currentline=-1; ar->source="=(tail call)"; luaO_chunkid(ar->short_src,ar->source,60); ar->nups=0; } static void collectvalidlines(lua_State*L,Closure*f){ if(f==NULL||f->c.isC){ setnilvalue(L->top); } else{ Table*t=luaH_new(L,0,0); int*lineinfo=f->l.p->lineinfo; int i; for(i=0;i<f->l.p->sizelineinfo;i++) setbvalue(luaH_setnum(L,t,lineinfo[i]),1); sethvalue(L,L->top,t); } incr_top(L); } static int auxgetinfo(lua_State*L,const char*what,lua_Debug*ar, Closure*f,CallInfo*ci){ int status=1; if(f==NULL){ info_tailcall(ar); return status; } for(;*what;what++){ switch(*what){ case'S':{ funcinfo(ar,f); break; } case'l':{ ar->currentline=(ci)?currentline(L,ci):-1; break; } case'u':{ ar->nups=f->c.nupvalues; break; } case'n':{ ar->namewhat=(ci)?NULL:NULL; if(ar->namewhat==NULL){ ar->namewhat=""; ar->name=NULL; } break; } case'L': case'f': break; default:status=0; } } return status; } static int lua_getinfo(lua_State*L,const char*what,lua_Debug*ar){ int status; Closure*f=NULL; CallInfo*ci=NULL; if(*what=='>'){ StkId func=L->top-1; luai_apicheck(L,ttisfunction(func)); what++; f=clvalue(func); L->top--; } else if(ar->i_ci!=0){ ci=L->base_ci+ar->i_ci; f=clvalue(ci->func); } status=auxgetinfo(L,what,ar,f,ci); if(strchr(what,'f')){ if(f==NULL)setnilvalue(L->top); else setclvalue(L,L->top,f); incr_top(L); } if(strchr(what,'L')) collectvalidlines(L,f); return status; } static int isinstack(CallInfo*ci,const TValue*o){ StkId p; for(p=ci->base;p<ci->top;p++) if(o==p)return 1; return 0; } static void luaG_typeerror(lua_State*L,const TValue*o,const char*op){ const char*name=NULL; const char*t=luaT_typenames[ttype(o)]; const char*kind=(isinstack(L->ci,o))? NULL: NULL; if(kind) luaG_runerror(L,"attempt to %s %s "LUA_QL("%s")" (a %s value)", op,kind,name,t); else luaG_runerror(L,"attempt to %s a %s value",op,t); } static void luaG_concaterror(lua_State*L,StkId p1,StkId p2){ if(ttisstring(p1)||ttisnumber(p1))p1=p2; luaG_typeerror(L,p1,"concatenate"); } static void luaG_aritherror(lua_State*L,const TValue*p1,const TValue*p2){ TValue temp; if(luaV_tonumber(p1,&temp)==NULL) p2=p1; luaG_typeerror(L,p2,"perform arithmetic on"); } static int luaG_ordererror(lua_State*L,const TValue*p1,const TValue*p2){ const char*t1=luaT_typenames[ttype(p1)]; const char*t2=luaT_typenames[ttype(p2)]; if(t1[2]==t2[2]) luaG_runerror(L,"attempt to compare two %s values",t1); else luaG_runerror(L,"attempt to compare %s with %s",t1,t2); return 0; } static void addinfo(lua_State*L,const char*msg){ CallInfo*ci=L->ci; if(isLua(ci)){ char buff[60]; int line=currentline(L,ci); luaO_chunkid(buff,getstr(getluaproto(ci)->source),60); luaO_pushfstring(L,"%s:%d: %s",buff,line,msg); } } static void luaG_errormsg(lua_State*L){ if(L->errfunc!=0){ StkId errfunc=restorestack(L,L->errfunc); if(!ttisfunction(errfunc))luaD_throw(L,5); setobj(L,L->top,L->top-1); setobj(L,L->top-1,errfunc); incr_top(L); luaD_call(L,L->top-2,1); } luaD_throw(L,2); } static void luaG_runerror(lua_State*L,const char*fmt,...){ va_list argp; va_start(argp,fmt); addinfo(L,luaO_pushvfstring(L,fmt,argp)); va_end(argp); luaG_errormsg(L); } static int luaZ_fill(ZIO*z){ size_t size; lua_State*L=z->L; const char*buff; buff=z->reader(L,z->data,&size); if(buff==NULL||size==0)return(-1); z->n=size-1; z->p=buff; return char2int(*(z->p++)); } static void luaZ_init(lua_State*L,ZIO*z,lua_Reader reader,void*data){ z->L=L; z->reader=reader; z->data=data; z->n=0; z->p=NULL; } static char*luaZ_openspace(lua_State*L,Mbuffer*buff,size_t n){ if(n>buff->buffsize){ if(n<32)n=32; luaZ_resizebuffer(L,buff,n); } return buff->buffer; } #define opmode(t,a,b,c,m)(((t)<<7)|((a)<<6)|((b)<<4)|((c)<<2)|(m)) static const lu_byte luaP_opmodes[(cast(int,OP_VARARG)+1)]={ opmode(0,1,OpArgR,OpArgN,iABC) ,opmode(0,1,OpArgK,OpArgN,iABx) ,opmode(0,1,OpArgU,OpArgU,iABC) ,opmode(0,1,OpArgR,OpArgN,iABC) ,opmode(0,1,OpArgU,OpArgN,iABC) ,opmode(0,1,OpArgK,OpArgN,iABx) ,opmode(0,1,OpArgR,OpArgK,iABC) ,opmode(0,0,OpArgK,OpArgN,iABx) ,opmode(0,0,OpArgU,OpArgN,iABC) ,opmode(0,0,OpArgK,OpArgK,iABC) ,opmode(0,1,OpArgU,OpArgU,iABC) ,opmode(0,1,OpArgR,OpArgK,iABC) ,opmode(0,1,OpArgK,OpArgK,iABC) ,opmode(0,1,OpArgK,OpArgK,iABC) ,opmode(0,1,OpArgK,OpArgK,iABC) ,opmode(0,1,OpArgK,OpArgK,iABC) ,opmode(0,1,OpArgK,OpArgK,iABC) ,opmode(0,1,OpArgK,OpArgK,iABC) ,opmode(0,1,OpArgR,OpArgN,iABC) ,opmode(0,1,OpArgR,OpArgN,iABC) ,opmode(0,1,OpArgR,OpArgN,iABC) ,opmode(0,1,OpArgR,OpArgR,iABC) ,opmode(0,0,OpArgR,OpArgN,iAsBx) ,opmode(1,0,OpArgK,OpArgK,iABC) ,opmode(1,0,OpArgK,OpArgK,iABC) ,opmode(1,0,OpArgK,OpArgK,iABC) ,opmode(1,1,OpArgR,OpArgU,iABC) ,opmode(1,1,OpArgR,OpArgU,iABC) ,opmode(0,1,OpArgU,OpArgU,iABC) ,opmode(0,1,OpArgU,OpArgU,iABC) ,opmode(0,0,OpArgU,OpArgN,iABC) ,opmode(0,1,OpArgR,OpArgN,iAsBx) ,opmode(0,1,OpArgR,OpArgN,iAsBx) ,opmode(1,0,OpArgN,OpArgU,iABC) ,opmode(0,0,OpArgU,OpArgU,iABC) ,opmode(0,0,OpArgN,OpArgN,iABC) ,opmode(0,1,OpArgU,OpArgN,iABx) ,opmode(0,1,OpArgU,OpArgN,iABC) }; #define next(ls)(ls->current=zgetc(ls->z)) #define currIsNewline(ls)(ls->current=='\n'||ls->current=='\r') static const char*const luaX_tokens[]={ "and","break","do","else","elseif", "end","false","for","function","if", "in","local","nil","not","or","repeat", "return","then","true","until","while", "..","...","==",">=","<=","~=", "<number>","<name>","<string>","<eof>", NULL }; #define save_and_next(ls)(save(ls,ls->current),next(ls)) static void save(LexState*ls,int c){ Mbuffer*b=ls->buff; if(b->n+1>b->buffsize){ size_t newsize; if(b->buffsize>=((size_t)(~(size_t)0)-2)/2) luaX_lexerror(ls,"lexical element too long",0); newsize=b->buffsize*2; luaZ_resizebuffer(ls->L,b,newsize); } b->buffer[b->n++]=cast(char,c); } static void luaX_init(lua_State*L){ int i; for(i=0;i<(cast(int,TK_WHILE-257+1));i++){ TString*ts=luaS_new(L,luaX_tokens[i]); luaS_fix(ts); ts->tsv.reserved=cast_byte(i+1); } } static const char*luaX_token2str(LexState*ls,int token){ if(token<257){ return(iscntrl(token))?luaO_pushfstring(ls->L,"char(%d)",token): luaO_pushfstring(ls->L,"%c",token); } else return luaX_tokens[token-257]; } static const char*txtToken(LexState*ls,int token){ switch(token){ case TK_NAME: case TK_STRING: case TK_NUMBER: save(ls,'\0'); return luaZ_buffer(ls->buff); default: return luaX_token2str(ls,token); } } static void luaX_lexerror(LexState*ls,const char*msg,int token){ char buff[80]; luaO_chunkid(buff,getstr(ls->source),80); msg=luaO_pushfstring(ls->L,"%s:%d: %s",buff,ls->linenumber,msg); if(token) luaO_pushfstring(ls->L,"%s near "LUA_QL("%s"),msg,txtToken(ls,token)); luaD_throw(ls->L,3); } static void luaX_syntaxerror(LexState*ls,const char*msg){ luaX_lexerror(ls,msg,ls->t.token); } static TString*luaX_newstring(LexState*ls,const char*str,size_t l){ lua_State*L=ls->L; TString*ts=luaS_newlstr(L,str,l); TValue*o=luaH_setstr(L,ls->fs->h,ts); if(ttisnil(o)){ setbvalue(o,1); luaC_checkGC(L); } return ts; } static void inclinenumber(LexState*ls){ int old=ls->current; next(ls); if(currIsNewline(ls)&&ls->current!=old) next(ls); if(++ls->linenumber>=(INT_MAX-2)) luaX_syntaxerror(ls,"chunk has too many lines"); } static void luaX_setinput(lua_State*L,LexState*ls,ZIO*z,TString*source){ ls->decpoint='.'; ls->L=L; ls->lookahead.token=TK_EOS; ls->z=z; ls->fs=NULL; ls->linenumber=1; ls->lastline=1; ls->source=source; luaZ_resizebuffer(ls->L,ls->buff,32); next(ls); } static int check_next(LexState*ls,const char*set){ if(!strchr(set,ls->current)) return 0; save_and_next(ls); return 1; } static void buffreplace(LexState*ls,char from,char to){ size_t n=luaZ_bufflen(ls->buff); char*p=luaZ_buffer(ls->buff); while(n--) if(p[n]==from)p[n]=to; } static void read_numeral(LexState*ls,SemInfo*seminfo){ do{ save_and_next(ls); }while(isdigit(ls->current)||ls->current=='.'); if(check_next(ls,"Ee")) check_next(ls,"+-"); while(isalnum(ls->current)||ls->current=='_') save_and_next(ls); save(ls,'\0'); buffreplace(ls,'.',ls->decpoint); if(!luaO_str2d(luaZ_buffer(ls->buff),&seminfo->r)) luaX_lexerror(ls,"malformed number",TK_NUMBER); } static int skip_sep(LexState*ls){ int count=0; int s=ls->current; save_and_next(ls); while(ls->current=='='){ save_and_next(ls); count++; } return(ls->current==s)?count:(-count)-1; } static void read_long_string(LexState*ls,SemInfo*seminfo,int sep){ int cont=0; (void)(cont); save_and_next(ls); if(currIsNewline(ls)) inclinenumber(ls); for(;;){ switch(ls->current){ case(-1): luaX_lexerror(ls,(seminfo)?"unfinished long string": "unfinished long comment",TK_EOS); break; case']':{ if(skip_sep(ls)==sep){ save_and_next(ls); goto endloop; } break; } case'\n': case'\r':{ save(ls,'\n'); inclinenumber(ls); if(!seminfo)luaZ_resetbuffer(ls->buff); break; } default:{ if(seminfo)save_and_next(ls); else next(ls); } } }endloop: if(seminfo) seminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+(2+sep), luaZ_bufflen(ls->buff)-2*(2+sep)); } static void read_string(LexState*ls,int del,SemInfo*seminfo){ save_and_next(ls); while(ls->current!=del){ switch(ls->current){ case(-1): luaX_lexerror(ls,"unfinished string",TK_EOS); continue; case'\n': case'\r': luaX_lexerror(ls,"unfinished string",TK_STRING); continue; case'\\':{ int c; next(ls); switch(ls->current){ case'a':c='\a';break; case'b':c='\b';break; case'f':c='\f';break; case'n':c='\n';break; case'r':c='\r';break; case't':c='\t';break; case'v':c='\v';break; case'\n': case'\r':save(ls,'\n');inclinenumber(ls);continue; case(-1):continue; default:{ if(!isdigit(ls->current)) save_and_next(ls); else{ int i=0; c=0; do{ c=10*c+(ls->current-'0'); next(ls); }while(++i<3&&isdigit(ls->current)); if(c>UCHAR_MAX) luaX_lexerror(ls,"escape sequence too large",TK_STRING); save(ls,c); } continue; } } save(ls,c); next(ls); continue; } default: save_and_next(ls); } } save_and_next(ls); seminfo->ts=luaX_newstring(ls,luaZ_buffer(ls->buff)+1, luaZ_bufflen(ls->buff)-2); } static int llex(LexState*ls,SemInfo*seminfo){ luaZ_resetbuffer(ls->buff); for(;;){ switch(ls->current){ case'\n': case'\r':{ inclinenumber(ls); continue; } case'-':{ next(ls); if(ls->current!='-')return'-'; next(ls); if(ls->current=='['){ int sep=skip_sep(ls); luaZ_resetbuffer(ls->buff); if(sep>=0){ read_long_string(ls,NULL,sep); luaZ_resetbuffer(ls->buff); continue; } } while(!currIsNewline(ls)&&ls->current!=(-1)) next(ls); continue; } case'[':{ int sep=skip_sep(ls); if(sep>=0){ read_long_string(ls,seminfo,sep); return TK_STRING; } else if(sep==-1)return'['; else luaX_lexerror(ls,"invalid long string delimiter",TK_STRING); } case'=':{ next(ls); if(ls->current!='=')return'='; else{next(ls);return TK_EQ;} } case'<':{ next(ls); if(ls->current!='=')return'<'; else{next(ls);return TK_LE;} } case'>':{ next(ls); if(ls->current!='=')return'>'; else{next(ls);return TK_GE;} } case'~':{ next(ls); if(ls->current!='=')return'~'; else{next(ls);return TK_NE;} } case'"': case'\'':{ read_string(ls,ls->current,seminfo); return TK_STRING; } case'.':{ save_and_next(ls); if(check_next(ls,".")){ if(check_next(ls,".")) return TK_DOTS; else return TK_CONCAT; } else if(!isdigit(ls->current))return'.'; else{ read_numeral(ls,seminfo); return TK_NUMBER; } } case(-1):{ return TK_EOS; } default:{ if(isspace(ls->current)){ next(ls); continue; } else if(isdigit(ls->current)){ read_numeral(ls,seminfo); return TK_NUMBER; } else if(isalpha(ls->current)||ls->current=='_'){ TString*ts; do{ save_and_next(ls); }while(isalnum(ls->current)||ls->current=='_'); ts=luaX_newstring(ls,luaZ_buffer(ls->buff), luaZ_bufflen(ls->buff)); if(ts->tsv.reserved>0) return ts->tsv.reserved-1+257; else{ seminfo->ts=ts; return TK_NAME; } } else{ int c=ls->current; next(ls); return c; } } } } } static void luaX_next(LexState*ls){ ls->lastline=ls->linenumber; if(ls->lookahead.token!=TK_EOS){ ls->t=ls->lookahead; ls->lookahead.token=TK_EOS; } else ls->t.token=llex(ls,&ls->t.seminfo); } static void luaX_lookahead(LexState*ls){ ls->lookahead.token=llex(ls,&ls->lookahead.seminfo); } #define hasjumps(e)((e)->t!=(e)->f) static int isnumeral(expdesc*e){ return(e->k==VKNUM&&e->t==(-1)&&e->f==(-1)); } static void luaK_nil(FuncState*fs,int from,int n){ Instruction*previous; if(fs->pc>fs->lasttarget){ if(fs->pc==0){ if(from>=fs->nactvar) return; } else{ previous=&fs->f->code[fs->pc-1]; if(GET_OPCODE(*previous)==OP_LOADNIL){ int pfrom=GETARG_A(*previous); int pto=GETARG_B(*previous); if(pfrom<=from&&from<=pto+1){ if(from+n-1>pto) SETARG_B(*previous,from+n-1); return; } } } } luaK_codeABC(fs,OP_LOADNIL,from,from+n-1,0); } static int luaK_jump(FuncState*fs){ int jpc=fs->jpc; int j; fs->jpc=(-1); j=luaK_codeAsBx(fs,OP_JMP,0,(-1)); luaK_concat(fs,&j,jpc); return j; } static void luaK_ret(FuncState*fs,int first,int nret){ luaK_codeABC(fs,OP_RETURN,first,nret+1,0); } static int condjump(FuncState*fs,OpCode op,int A,int B,int C){ luaK_codeABC(fs,op,A,B,C); return luaK_jump(fs); } static void fixjump(FuncState*fs,int pc,int dest){ Instruction*jmp=&fs->f->code[pc]; int offset=dest-(pc+1); if(abs(offset)>(((1<<(9+9))-1)>>1)) luaX_syntaxerror(fs->ls,"control structure too long"); SETARG_sBx(*jmp,offset); } static int luaK_getlabel(FuncState*fs){ fs->lasttarget=fs->pc; return fs->pc; } static int getjump(FuncState*fs,int pc){ int offset=GETARG_sBx(fs->f->code[pc]); if(offset==(-1)) return(-1); else return(pc+1)+offset; } static Instruction*getjumpcontrol(FuncState*fs,int pc){ Instruction*pi=&fs->f->code[pc]; if(pc>=1&&testTMode(GET_OPCODE(*(pi-1)))) return pi-1; else return pi; } static int need_value(FuncState*fs,int list){ for(;list!=(-1);list=getjump(fs,list)){ Instruction i=*getjumpcontrol(fs,list); if(GET_OPCODE(i)!=OP_TESTSET)return 1; } return 0; } static int patchtestreg(FuncState*fs,int node,int reg){ Instruction*i=getjumpcontrol(fs,node); if(GET_OPCODE(*i)!=OP_TESTSET) return 0; if(reg!=((1<<8)-1)&&reg!=GETARG_B(*i)) SETARG_A(*i,reg); else *i=CREATE_ABC(OP_TEST,GETARG_B(*i),0,GETARG_C(*i)); return 1; } static void removevalues(FuncState*fs,int list){ for(;list!=(-1);list=getjump(fs,list)) patchtestreg(fs,list,((1<<8)-1)); } static void patchlistaux(FuncState*fs,int list,int vtarget,int reg, int dtarget){ while(list!=(-1)){ int next=getjump(fs,list); if(patchtestreg(fs,list,reg)) fixjump(fs,list,vtarget); else fixjump(fs,list,dtarget); list=next; } } static void dischargejpc(FuncState*fs){ patchlistaux(fs,fs->jpc,fs->pc,((1<<8)-1),fs->pc); fs->jpc=(-1); } static void luaK_patchlist(FuncState*fs,int list,int target){ if(target==fs->pc) luaK_patchtohere(fs,list); else{ patchlistaux(fs,list,target,((1<<8)-1),target); } } static void luaK_patchtohere(FuncState*fs,int list){ luaK_getlabel(fs); luaK_concat(fs,&fs->jpc,list); } static void luaK_concat(FuncState*fs,int*l1,int l2){ if(l2==(-1))return; else if(*l1==(-1)) *l1=l2; else{ int list=*l1; int next; while((next=getjump(fs,list))!=(-1)) list=next; fixjump(fs,list,l2); } } static void luaK_checkstack(FuncState*fs,int n){ int newstack=fs->freereg+n; if(newstack>fs->f->maxstacksize){ if(newstack>=250) luaX_syntaxerror(fs->ls,"function or expression too complex"); fs->f->maxstacksize=cast_byte(newstack); } } static void luaK_reserveregs(FuncState*fs,int n){ luaK_checkstack(fs,n); fs->freereg+=n; } static void freereg(FuncState*fs,int reg){ if(!ISK(reg)&&reg>=fs->nactvar){ fs->freereg--; } } static void freeexp(FuncState*fs,expdesc*e){ if(e->k==VNONRELOC) freereg(fs,e->u.s.info); } static int addk(FuncState*fs,TValue*k,TValue*v){ lua_State*L=fs->L; TValue*idx=luaH_set(L,fs->h,k); Proto*f=fs->f; int oldsize=f->sizek; if(ttisnumber(idx)){ return cast_int(nvalue(idx)); } else{ setnvalue(idx,cast_num(fs->nk)); luaM_growvector(L,f->k,fs->nk,f->sizek,TValue, ((1<<(9+9))-1),"constant table overflow"); while(oldsize<f->sizek)setnilvalue(&f->k[oldsize++]); setobj(L,&f->k[fs->nk],v); luaC_barrier(L,f,v); return fs->nk++; } } static int luaK_stringK(FuncState*fs,TString*s){ TValue o; setsvalue(fs->L,&o,s); return addk(fs,&o,&o); } static int luaK_numberK(FuncState*fs,lua_Number r){ TValue o; setnvalue(&o,r); return addk(fs,&o,&o); } static int boolK(FuncState*fs,int b){ TValue o; setbvalue(&o,b); return addk(fs,&o,&o); } static int nilK(FuncState*fs){ TValue k,v; setnilvalue(&v); sethvalue(fs->L,&k,fs->h); return addk(fs,&k,&v); } static void luaK_setreturns(FuncState*fs,expdesc*e,int nresults){ if(e->k==VCALL){ SETARG_C(getcode(fs,e),nresults+1); } else if(e->k==VVARARG){ SETARG_B(getcode(fs,e),nresults+1); SETARG_A(getcode(fs,e),fs->freereg); luaK_reserveregs(fs,1); } } static void luaK_setoneret(FuncState*fs,expdesc*e){ if(e->k==VCALL){ e->k=VNONRELOC; e->u.s.info=GETARG_A(getcode(fs,e)); } else if(e->k==VVARARG){ SETARG_B(getcode(fs,e),2); e->k=VRELOCABLE; } } static void luaK_dischargevars(FuncState*fs,expdesc*e){ switch(e->k){ case VLOCAL:{ e->k=VNONRELOC; break; } case VUPVAL:{ e->u.s.info=luaK_codeABC(fs,OP_GETUPVAL,0,e->u.s.info,0); e->k=VRELOCABLE; break; } case VGLOBAL:{ e->u.s.info=luaK_codeABx(fs,OP_GETGLOBAL,0,e->u.s.info); e->k=VRELOCABLE; break; } case VINDEXED:{ freereg(fs,e->u.s.aux); freereg(fs,e->u.s.info); e->u.s.info=luaK_codeABC(fs,OP_GETTABLE,0,e->u.s.info,e->u.s.aux); e->k=VRELOCABLE; break; } case VVARARG: case VCALL:{ luaK_setoneret(fs,e); break; } default:break; } } static int code_label(FuncState*fs,int A,int b,int jump){ luaK_getlabel(fs); return luaK_codeABC(fs,OP_LOADBOOL,A,b,jump); } static void discharge2reg(FuncState*fs,expdesc*e,int reg){ luaK_dischargevars(fs,e); switch(e->k){ case VNIL:{ luaK_nil(fs,reg,1); break; } case VFALSE:case VTRUE:{ luaK_codeABC(fs,OP_LOADBOOL,reg,e->k==VTRUE,0); break; } case VK:{ luaK_codeABx(fs,OP_LOADK,reg,e->u.s.info); break; } case VKNUM:{ luaK_codeABx(fs,OP_LOADK,reg,luaK_numberK(fs,e->u.nval)); break; } case VRELOCABLE:{ Instruction*pc=&getcode(fs,e); SETARG_A(*pc,reg); break; } case VNONRELOC:{ if(reg!=e->u.s.info) luaK_codeABC(fs,OP_MOVE,reg,e->u.s.info,0); break; } default:{ return; } } e->u.s.info=reg; e->k=VNONRELOC; } static void discharge2anyreg(FuncState*fs,expdesc*e){ if(e->k!=VNONRELOC){ luaK_reserveregs(fs,1); discharge2reg(fs,e,fs->freereg-1); } } static void exp2reg(FuncState*fs,expdesc*e,int reg){ discharge2reg(fs,e,reg); if(e->k==VJMP) luaK_concat(fs,&e->t,e->u.s.info); if(hasjumps(e)){ int final; int p_f=(-1); int p_t=(-1); if(need_value(fs,e->t)||need_value(fs,e->f)){ int fj=(e->k==VJMP)?(-1):luaK_jump(fs); p_f=code_label(fs,reg,0,1); p_t=code_label(fs,reg,1,0); luaK_patchtohere(fs,fj); } final=luaK_getlabel(fs); patchlistaux(fs,e->f,final,reg,p_f); patchlistaux(fs,e->t,final,reg,p_t); } e->f=e->t=(-1); e->u.s.info=reg; e->k=VNONRELOC; } static void luaK_exp2nextreg(FuncState*fs,expdesc*e){ luaK_dischargevars(fs,e); freeexp(fs,e); luaK_reserveregs(fs,1); exp2reg(fs,e,fs->freereg-1); } static int luaK_exp2anyreg(FuncState*fs,expdesc*e){ luaK_dischargevars(fs,e); if(e->k==VNONRELOC){ if(!hasjumps(e))return e->u.s.info; if(e->u.s.info>=fs->nactvar){ exp2reg(fs,e,e->u.s.info); return e->u.s.info; } } luaK_exp2nextreg(fs,e); return e->u.s.info; } static void luaK_exp2val(FuncState*fs,expdesc*e){ if(hasjumps(e)) luaK_exp2anyreg(fs,e); else luaK_dischargevars(fs,e); } static int luaK_exp2RK(FuncState*fs,expdesc*e){ luaK_exp2val(fs,e); switch(e->k){ case VKNUM: case VTRUE: case VFALSE: case VNIL:{ if(fs->nk<=((1<<(9-1))-1)){ e->u.s.info=(e->k==VNIL)?nilK(fs): (e->k==VKNUM)?luaK_numberK(fs,e->u.nval): boolK(fs,(e->k==VTRUE)); e->k=VK; return RKASK(e->u.s.info); } else break; } case VK:{ if(e->u.s.info<=((1<<(9-1))-1)) return RKASK(e->u.s.info); else break; } default:break; } return luaK_exp2anyreg(fs,e); } static void luaK_storevar(FuncState*fs,expdesc*var,expdesc*ex){ switch(var->k){ case VLOCAL:{ freeexp(fs,ex); exp2reg(fs,ex,var->u.s.info); return; } case VUPVAL:{ int e=luaK_exp2anyreg(fs,ex); luaK_codeABC(fs,OP_SETUPVAL,e,var->u.s.info,0); break; } case VGLOBAL:{ int e=luaK_exp2anyreg(fs,ex); luaK_codeABx(fs,OP_SETGLOBAL,e,var->u.s.info); break; } case VINDEXED:{ int e=luaK_exp2RK(fs,ex); luaK_codeABC(fs,OP_SETTABLE,var->u.s.info,var->u.s.aux,e); break; } default:{ break; } } freeexp(fs,ex); } static void luaK_self(FuncState*fs,expdesc*e,expdesc*key){ int func; luaK_exp2anyreg(fs,e); freeexp(fs,e); func=fs->freereg; luaK_reserveregs(fs,2); luaK_codeABC(fs,OP_SELF,func,e->u.s.info,luaK_exp2RK(fs,key)); freeexp(fs,key); e->u.s.info=func; e->k=VNONRELOC; } static void invertjump(FuncState*fs,expdesc*e){ Instruction*pc=getjumpcontrol(fs,e->u.s.info); SETARG_A(*pc,!(GETARG_A(*pc))); } static int jumponcond(FuncState*fs,expdesc*e,int cond){ if(e->k==VRELOCABLE){ Instruction ie=getcode(fs,e); if(GET_OPCODE(ie)==OP_NOT){ fs->pc--; return condjump(fs,OP_TEST,GETARG_B(ie),0,!cond); } } discharge2anyreg(fs,e); freeexp(fs,e); return condjump(fs,OP_TESTSET,((1<<8)-1),e->u.s.info,cond); } static void luaK_goiftrue(FuncState*fs,expdesc*e){ int pc; luaK_dischargevars(fs,e); switch(e->k){ case VK:case VKNUM:case VTRUE:{ pc=(-1); break; } case VJMP:{ invertjump(fs,e); pc=e->u.s.info; break; } default:{ pc=jumponcond(fs,e,0); break; } } luaK_concat(fs,&e->f,pc); luaK_patchtohere(fs,e->t); e->t=(-1); } static void luaK_goiffalse(FuncState*fs,expdesc*e){ int pc; luaK_dischargevars(fs,e); switch(e->k){ case VNIL:case VFALSE:{ pc=(-1); break; } case VJMP:{ pc=e->u.s.info; break; } default:{ pc=jumponcond(fs,e,1); break; } } luaK_concat(fs,&e->t,pc); luaK_patchtohere(fs,e->f); e->f=(-1); } static void codenot(FuncState*fs,expdesc*e){ luaK_dischargevars(fs,e); switch(e->k){ case VNIL:case VFALSE:{ e->k=VTRUE; break; } case VK:case VKNUM:case VTRUE:{ e->k=VFALSE; break; } case VJMP:{ invertjump(fs,e); break; } case VRELOCABLE: case VNONRELOC:{ discharge2anyreg(fs,e); freeexp(fs,e); e->u.s.info=luaK_codeABC(fs,OP_NOT,0,e->u.s.info,0); e->k=VRELOCABLE; break; } default:{ break; } } {int temp=e->f;e->f=e->t;e->t=temp;} removevalues(fs,e->f); removevalues(fs,e->t); } static void luaK_indexed(FuncState*fs,expdesc*t,expdesc*k){ t->u.s.aux=luaK_exp2RK(fs,k); t->k=VINDEXED; } static int constfolding(OpCode op,expdesc*e1,expdesc*e2){ lua_Number v1,v2,r; if(!isnumeral(e1)||!isnumeral(e2))return 0; v1=e1->u.nval; v2=e2->u.nval; switch(op){ case OP_ADD:r=luai_numadd(v1,v2);break; case OP_SUB:r=luai_numsub(v1,v2);break; case OP_MUL:r=luai_nummul(v1,v2);break; case OP_DIV: if(v2==0)return 0; r=luai_numdiv(v1,v2);break; case OP_MOD: if(v2==0)return 0; r=luai_nummod(v1,v2);break; case OP_POW:r=luai_numpow(v1,v2);break; case OP_UNM:r=luai_numunm(v1);break; case OP_LEN:return 0; default:r=0;break; } if(luai_numisnan(r))return 0; e1->u.nval=r; return 1; } static void codearith(FuncState*fs,OpCode op,expdesc*e1,expdesc*e2){ if(constfolding(op,e1,e2)) return; else{ int o2=(op!=OP_UNM&&op!=OP_LEN)?luaK_exp2RK(fs,e2):0; int o1=luaK_exp2RK(fs,e1); if(o1>o2){ freeexp(fs,e1); freeexp(fs,e2); } else{ freeexp(fs,e2); freeexp(fs,e1); } e1->u.s.info=luaK_codeABC(fs,op,0,o1,o2); e1->k=VRELOCABLE; } } static void codecomp(FuncState*fs,OpCode op,int cond,expdesc*e1, expdesc*e2){ int o1=luaK_exp2RK(fs,e1); int o2=luaK_exp2RK(fs,e2); freeexp(fs,e2); freeexp(fs,e1); if(cond==0&&op!=OP_EQ){ int temp; temp=o1;o1=o2;o2=temp; cond=1; } e1->u.s.info=condjump(fs,op,cond,o1,o2); e1->k=VJMP; } static void luaK_prefix(FuncState*fs,UnOpr op,expdesc*e){ expdesc e2; e2.t=e2.f=(-1);e2.k=VKNUM;e2.u.nval=0; switch(op){ case OPR_MINUS:{ if(!isnumeral(e)) luaK_exp2anyreg(fs,e); codearith(fs,OP_UNM,e,&e2); break; } case OPR_NOT:codenot(fs,e);break; case OPR_LEN:{ luaK_exp2anyreg(fs,e); codearith(fs,OP_LEN,e,&e2); break; } default:; } } static void luaK_infix(FuncState*fs,BinOpr op,expdesc*v){ switch(op){ case OPR_AND:{ luaK_goiftrue(fs,v); break; } case OPR_OR:{ luaK_goiffalse(fs,v); break; } case OPR_CONCAT:{ luaK_exp2nextreg(fs,v); break; } case OPR_ADD:case OPR_SUB:case OPR_MUL:case OPR_DIV: case OPR_MOD:case OPR_POW:{ if(!isnumeral(v))luaK_exp2RK(fs,v); break; } default:{ luaK_exp2RK(fs,v); break; } } } static void luaK_posfix(FuncState*fs,BinOpr op,expdesc*e1,expdesc*e2){ switch(op){ case OPR_AND:{ luaK_dischargevars(fs,e2); luaK_concat(fs,&e2->f,e1->f); *e1=*e2; break; } case OPR_OR:{ luaK_dischargevars(fs,e2); luaK_concat(fs,&e2->t,e1->t); *e1=*e2; break; } case OPR_CONCAT:{ luaK_exp2val(fs,e2); if(e2->k==VRELOCABLE&&GET_OPCODE(getcode(fs,e2))==OP_CONCAT){ freeexp(fs,e1); SETARG_B(getcode(fs,e2),e1->u.s.info); e1->k=VRELOCABLE;e1->u.s.info=e2->u.s.info; } else{ luaK_exp2nextreg(fs,e2); codearith(fs,OP_CONCAT,e1,e2); } break; } case OPR_ADD:codearith(fs,OP_ADD,e1,e2);break; case OPR_SUB:codearith(fs,OP_SUB,e1,e2);break; case OPR_MUL:codearith(fs,OP_MUL,e1,e2);break; case OPR_DIV:codearith(fs,OP_DIV,e1,e2);break; case OPR_MOD:codearith(fs,OP_MOD,e1,e2);break; case OPR_POW:codearith(fs,OP_POW,e1,e2);break; case OPR_EQ:codecomp(fs,OP_EQ,1,e1,e2);break; case OPR_NE:codecomp(fs,OP_EQ,0,e1,e2);break; case OPR_LT:codecomp(fs,OP_LT,1,e1,e2);break; case OPR_LE:codecomp(fs,OP_LE,1,e1,e2);break; case OPR_GT:codecomp(fs,OP_LT,0,e1,e2);break; case OPR_GE:codecomp(fs,OP_LE,0,e1,e2);break; default:; } } static void luaK_fixline(FuncState*fs,int line){ fs->f->lineinfo[fs->pc-1]=line; } static int luaK_code(FuncState*fs,Instruction i,int line){ Proto*f=fs->f; dischargejpc(fs); luaM_growvector(fs->L,f->code,fs->pc,f->sizecode,Instruction, (INT_MAX-2),"code size overflow"); f->code[fs->pc]=i; luaM_growvector(fs->L,f->lineinfo,fs->pc,f->sizelineinfo,int, (INT_MAX-2),"code size overflow"); f->lineinfo[fs->pc]=line; return fs->pc++; } static int luaK_codeABC(FuncState*fs,OpCode o,int a,int b,int c){ return luaK_code(fs,CREATE_ABC(o,a,b,c),fs->ls->lastline); } static int luaK_codeABx(FuncState*fs,OpCode o,int a,unsigned int bc){ return luaK_code(fs,CREATE_ABx(o,a,bc),fs->ls->lastline); } static void luaK_setlist(FuncState*fs,int base,int nelems,int tostore){ int c=(nelems-1)/50+1; int b=(tostore==(-1))?0:tostore; if(c<=((1<<9)-1)) luaK_codeABC(fs,OP_SETLIST,base,b,c); else{ luaK_codeABC(fs,OP_SETLIST,base,b,0); luaK_code(fs,cast(Instruction,c),fs->ls->lastline); } fs->freereg=base+1; } #define hasmultret(k)((k)==VCALL||(k)==VVARARG) #define getlocvar(fs,i)((fs)->f->locvars[(fs)->actvar[i]]) #define luaY_checklimit(fs,v,l,m)if((v)>(l))errorlimit(fs,l,m) typedef struct BlockCnt{ struct BlockCnt*previous; int breaklist; lu_byte nactvar; lu_byte upval; lu_byte isbreakable; }BlockCnt; static void chunk(LexState*ls); static void expr(LexState*ls,expdesc*v); static void anchor_token(LexState*ls){ if(ls->t.token==TK_NAME||ls->t.token==TK_STRING){ TString*ts=ls->t.seminfo.ts; luaX_newstring(ls,getstr(ts),ts->tsv.len); } } static void error_expected(LexState*ls,int token){ luaX_syntaxerror(ls, luaO_pushfstring(ls->L,LUA_QL("%s")" expected",luaX_token2str(ls,token))); } static void errorlimit(FuncState*fs,int limit,const char*what){ const char*msg=(fs->f->linedefined==0)? luaO_pushfstring(fs->L,"main function has more than %d %s",limit,what): luaO_pushfstring(fs->L,"function at line %d has more than %d %s", fs->f->linedefined,limit,what); luaX_lexerror(fs->ls,msg,0); } static int testnext(LexState*ls,int c){ if(ls->t.token==c){ luaX_next(ls); return 1; } else return 0; } static void check(LexState*ls,int c){ if(ls->t.token!=c) error_expected(ls,c); } static void checknext(LexState*ls,int c){ check(ls,c); luaX_next(ls); } #define check_condition(ls,c,msg){if(!(c))luaX_syntaxerror(ls,msg);} static void check_match(LexState*ls,int what,int who,int where){ if(!testnext(ls,what)){ if(where==ls->linenumber) error_expected(ls,what); else{ luaX_syntaxerror(ls,luaO_pushfstring(ls->L, LUA_QL("%s")" expected (to close "LUA_QL("%s")" at line %d)", luaX_token2str(ls,what),luaX_token2str(ls,who),where)); } } } static TString*str_checkname(LexState*ls){ TString*ts; check(ls,TK_NAME); ts=ls->t.seminfo.ts; luaX_next(ls); return ts; } static void init_exp(expdesc*e,expkind k,int i){ e->f=e->t=(-1); e->k=k; e->u.s.info=i; } static void codestring(LexState*ls,expdesc*e,TString*s){ init_exp(e,VK,luaK_stringK(ls->fs,s)); } static void checkname(LexState*ls,expdesc*e){ codestring(ls,e,str_checkname(ls)); } static int registerlocalvar(LexState*ls,TString*varname){ FuncState*fs=ls->fs; Proto*f=fs->f; int oldsize=f->sizelocvars; luaM_growvector(ls->L,f->locvars,fs->nlocvars,f->sizelocvars, LocVar,SHRT_MAX,"too many local variables"); while(oldsize<f->sizelocvars)f->locvars[oldsize++].varname=NULL; f->locvars[fs->nlocvars].varname=varname; luaC_objbarrier(ls->L,f,varname); return fs->nlocvars++; } #define new_localvarliteral(ls,v,n)new_localvar(ls,luaX_newstring(ls,""v,(sizeof(v)/sizeof(char))-1),n) static void new_localvar(LexState*ls,TString*name,int n){ FuncState*fs=ls->fs; luaY_checklimit(fs,fs->nactvar+n+1,200,"local variables"); fs->actvar[fs->nactvar+n]=cast(unsigned short,registerlocalvar(ls,name)); } static void adjustlocalvars(LexState*ls,int nvars){ FuncState*fs=ls->fs; fs->nactvar=cast_byte(fs->nactvar+nvars); for(;nvars;nvars--){ getlocvar(fs,fs->nactvar-nvars).startpc=fs->pc; } } static void removevars(LexState*ls,int tolevel){ FuncState*fs=ls->fs; while(fs->nactvar>tolevel) getlocvar(fs,--fs->nactvar).endpc=fs->pc; } static int indexupvalue(FuncState*fs,TString*name,expdesc*v){ int i; Proto*f=fs->f; int oldsize=f->sizeupvalues; for(i=0;i<f->nups;i++){ if(fs->upvalues[i].k==v->k&&fs->upvalues[i].info==v->u.s.info){ return i; } } luaY_checklimit(fs,f->nups+1,60,"upvalues"); luaM_growvector(fs->L,f->upvalues,f->nups,f->sizeupvalues, TString*,(INT_MAX-2),""); while(oldsize<f->sizeupvalues)f->upvalues[oldsize++]=NULL; f->upvalues[f->nups]=name; luaC_objbarrier(fs->L,f,name); fs->upvalues[f->nups].k=cast_byte(v->k); fs->upvalues[f->nups].info=cast_byte(v->u.s.info); return f->nups++; } static int searchvar(FuncState*fs,TString*n){ int i; for(i=fs->nactvar-1;i>=0;i--){ if(n==getlocvar(fs,i).varname) return i; } return-1; } static void markupval(FuncState*fs,int level){ BlockCnt*bl=fs->bl; while(bl&&bl->nactvar>level)bl=bl->previous; if(bl)bl->upval=1; } static int singlevaraux(FuncState*fs,TString*n,expdesc*var,int base){ if(fs==NULL){ init_exp(var,VGLOBAL,((1<<8)-1)); return VGLOBAL; } else{ int v=searchvar(fs,n); if(v>=0){ init_exp(var,VLOCAL,v); if(!base) markupval(fs,v); return VLOCAL; } else{ if(singlevaraux(fs->prev,n,var,0)==VGLOBAL) return VGLOBAL; var->u.s.info=indexupvalue(fs,n,var); var->k=VUPVAL; return VUPVAL; } } } static void singlevar(LexState*ls,expdesc*var){ TString*varname=str_checkname(ls); FuncState*fs=ls->fs; if(singlevaraux(fs,varname,var,1)==VGLOBAL) var->u.s.info=luaK_stringK(fs,varname); } static void adjust_assign(LexState*ls,int nvars,int nexps,expdesc*e){ FuncState*fs=ls->fs; int extra=nvars-nexps; if(hasmultret(e->k)){ extra++; if(extra<0)extra=0; luaK_setreturns(fs,e,extra); if(extra>1)luaK_reserveregs(fs,extra-1); } else{ if(e->k!=VVOID)luaK_exp2nextreg(fs,e); if(extra>0){ int reg=fs->freereg; luaK_reserveregs(fs,extra); luaK_nil(fs,reg,extra); } } } static void enterlevel(LexState*ls){ if(++ls->L->nCcalls>200) luaX_lexerror(ls,"chunk has too many syntax levels",0); } #define leavelevel(ls)((ls)->L->nCcalls--) static void enterblock(FuncState*fs,BlockCnt*bl,lu_byte isbreakable){ bl->breaklist=(-1); bl->isbreakable=isbreakable; bl->nactvar=fs->nactvar; bl->upval=0; bl->previous=fs->bl; fs->bl=bl; } static void leaveblock(FuncState*fs){ BlockCnt*bl=fs->bl; fs->bl=bl->previous; removevars(fs->ls,bl->nactvar); if(bl->upval) luaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0); fs->freereg=fs->nactvar; luaK_patchtohere(fs,bl->breaklist); } static void pushclosure(LexState*ls,FuncState*func,expdesc*v){ FuncState*fs=ls->fs; Proto*f=fs->f; int oldsize=f->sizep; int i; luaM_growvector(ls->L,f->p,fs->np,f->sizep,Proto*, ((1<<(9+9))-1),"constant table overflow"); while(oldsize<f->sizep)f->p[oldsize++]=NULL; f->p[fs->np++]=func->f; luaC_objbarrier(ls->L,f,func->f); init_exp(v,VRELOCABLE,luaK_codeABx(fs,OP_CLOSURE,0,fs->np-1)); for(i=0;i<func->f->nups;i++){ OpCode o=(func->upvalues[i].k==VLOCAL)?OP_MOVE:OP_GETUPVAL; luaK_codeABC(fs,o,0,func->upvalues[i].info,0); } } static void open_func(LexState*ls,FuncState*fs){ lua_State*L=ls->L; Proto*f=luaF_newproto(L); fs->f=f; fs->prev=ls->fs; fs->ls=ls; fs->L=L; ls->fs=fs; fs->pc=0; fs->lasttarget=-1; fs->jpc=(-1); fs->freereg=0; fs->nk=0; fs->np=0; fs->nlocvars=0; fs->nactvar=0; fs->bl=NULL; f->source=ls->source; f->maxstacksize=2; fs->h=luaH_new(L,0,0); sethvalue(L,L->top,fs->h); incr_top(L); setptvalue(L,L->top,f); incr_top(L); } static void close_func(LexState*ls){ lua_State*L=ls->L; FuncState*fs=ls->fs; Proto*f=fs->f; removevars(ls,0); luaK_ret(fs,0,0); luaM_reallocvector(L,f->code,f->sizecode,fs->pc,Instruction); f->sizecode=fs->pc; luaM_reallocvector(L,f->lineinfo,f->sizelineinfo,fs->pc,int); f->sizelineinfo=fs->pc; luaM_reallocvector(L,f->k,f->sizek,fs->nk,TValue); f->sizek=fs->nk; luaM_reallocvector(L,f->p,f->sizep,fs->np,Proto*); f->sizep=fs->np; luaM_reallocvector(L,f->locvars,f->sizelocvars,fs->nlocvars,LocVar); f->sizelocvars=fs->nlocvars; luaM_reallocvector(L,f->upvalues,f->sizeupvalues,f->nups,TString*); f->sizeupvalues=f->nups; ls->fs=fs->prev; if(fs)anchor_token(ls); L->top-=2; } static Proto*luaY_parser(lua_State*L,ZIO*z,Mbuffer*buff,const char*name){ struct LexState lexstate; struct FuncState funcstate; lexstate.buff=buff; luaX_setinput(L,&lexstate,z,luaS_new(L,name)); open_func(&lexstate,&funcstate); funcstate.f->is_vararg=2; luaX_next(&lexstate); chunk(&lexstate); check(&lexstate,TK_EOS); close_func(&lexstate); return funcstate.f; } static void field(LexState*ls,expdesc*v){ FuncState*fs=ls->fs; expdesc key; luaK_exp2anyreg(fs,v); luaX_next(ls); checkname(ls,&key); luaK_indexed(fs,v,&key); } static void yindex(LexState*ls,expdesc*v){ luaX_next(ls); expr(ls,v); luaK_exp2val(ls->fs,v); checknext(ls,']'); } struct ConsControl{ expdesc v; expdesc*t; int nh; int na; int tostore; }; static void recfield(LexState*ls,struct ConsControl*cc){ FuncState*fs=ls->fs; int reg=ls->fs->freereg; expdesc key,val; int rkkey; if(ls->t.token==TK_NAME){ luaY_checklimit(fs,cc->nh,(INT_MAX-2),"items in a constructor"); checkname(ls,&key); } else yindex(ls,&key); cc->nh++; checknext(ls,'='); rkkey=luaK_exp2RK(fs,&key); expr(ls,&val); luaK_codeABC(fs,OP_SETTABLE,cc->t->u.s.info,rkkey,luaK_exp2RK(fs,&val)); fs->freereg=reg; } static void closelistfield(FuncState*fs,struct ConsControl*cc){ if(cc->v.k==VVOID)return; luaK_exp2nextreg(fs,&cc->v); cc->v.k=VVOID; if(cc->tostore==50){ luaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore); cc->tostore=0; } } static void lastlistfield(FuncState*fs,struct ConsControl*cc){ if(cc->tostore==0)return; if(hasmultret(cc->v.k)){ luaK_setmultret(fs,&cc->v); luaK_setlist(fs,cc->t->u.s.info,cc->na,(-1)); cc->na--; } else{ if(cc->v.k!=VVOID) luaK_exp2nextreg(fs,&cc->v); luaK_setlist(fs,cc->t->u.s.info,cc->na,cc->tostore); } } static void listfield(LexState*ls,struct ConsControl*cc){ expr(ls,&cc->v); luaY_checklimit(ls->fs,cc->na,(INT_MAX-2),"items in a constructor"); cc->na++; cc->tostore++; } static void constructor(LexState*ls,expdesc*t){ FuncState*fs=ls->fs; int line=ls->linenumber; int pc=luaK_codeABC(fs,OP_NEWTABLE,0,0,0); struct ConsControl cc; cc.na=cc.nh=cc.tostore=0; cc.t=t; init_exp(t,VRELOCABLE,pc); init_exp(&cc.v,VVOID,0); luaK_exp2nextreg(ls->fs,t); checknext(ls,'{'); do{ if(ls->t.token=='}')break; closelistfield(fs,&cc); switch(ls->t.token){ case TK_NAME:{ luaX_lookahead(ls); if(ls->lookahead.token!='=') listfield(ls,&cc); else recfield(ls,&cc); break; } case'[':{ recfield(ls,&cc); break; } default:{ listfield(ls,&cc); break; } } }while(testnext(ls,',')||testnext(ls,';')); check_match(ls,'}','{',line); lastlistfield(fs,&cc); SETARG_B(fs->f->code[pc],luaO_int2fb(cc.na)); SETARG_C(fs->f->code[pc],luaO_int2fb(cc.nh)); } static void parlist(LexState*ls){ FuncState*fs=ls->fs; Proto*f=fs->f; int nparams=0; f->is_vararg=0; if(ls->t.token!=')'){ do{ switch(ls->t.token){ case TK_NAME:{ new_localvar(ls,str_checkname(ls),nparams++); break; } case TK_DOTS:{ luaX_next(ls); f->is_vararg|=2; break; } default:luaX_syntaxerror(ls,"<name> or "LUA_QL("...")" expected"); } }while(!f->is_vararg&&testnext(ls,',')); } adjustlocalvars(ls,nparams); f->numparams=cast_byte(fs->nactvar-(f->is_vararg&1)); luaK_reserveregs(fs,fs->nactvar); } static void body(LexState*ls,expdesc*e,int needself,int line){ FuncState new_fs; open_func(ls,&new_fs); new_fs.f->linedefined=line; checknext(ls,'('); if(needself){ new_localvarliteral(ls,"self",0); adjustlocalvars(ls,1); } parlist(ls); checknext(ls,')'); chunk(ls); new_fs.f->lastlinedefined=ls->linenumber; check_match(ls,TK_END,TK_FUNCTION,line); close_func(ls); pushclosure(ls,&new_fs,e); } static int explist1(LexState*ls,expdesc*v){ int n=1; expr(ls,v); while(testnext(ls,',')){ luaK_exp2nextreg(ls->fs,v); expr(ls,v); n++; } return n; } static void funcargs(LexState*ls,expdesc*f){ FuncState*fs=ls->fs; expdesc args; int base,nparams; int line=ls->linenumber; switch(ls->t.token){ case'(':{ if(line!=ls->lastline) luaX_syntaxerror(ls,"ambiguous syntax (function call x new statement)"); luaX_next(ls); if(ls->t.token==')') args.k=VVOID; else{ explist1(ls,&args); luaK_setmultret(fs,&args); } check_match(ls,')','(',line); break; } case'{':{ constructor(ls,&args); break; } case TK_STRING:{ codestring(ls,&args,ls->t.seminfo.ts); luaX_next(ls); break; } default:{ luaX_syntaxerror(ls,"function arguments expected"); return; } } base=f->u.s.info; if(hasmultret(args.k)) nparams=(-1); else{ if(args.k!=VVOID) luaK_exp2nextreg(fs,&args); nparams=fs->freereg-(base+1); } init_exp(f,VCALL,luaK_codeABC(fs,OP_CALL,base,nparams+1,2)); luaK_fixline(fs,line); fs->freereg=base+1; } static void prefixexp(LexState*ls,expdesc*v){ switch(ls->t.token){ case'(':{ int line=ls->linenumber; luaX_next(ls); expr(ls,v); check_match(ls,')','(',line); luaK_dischargevars(ls->fs,v); return; } case TK_NAME:{ singlevar(ls,v); return; } default:{ luaX_syntaxerror(ls,"unexpected symbol"); return; } } } static void primaryexp(LexState*ls,expdesc*v){ FuncState*fs=ls->fs; prefixexp(ls,v); for(;;){ switch(ls->t.token){ case'.':{ field(ls,v); break; } case'[':{ expdesc key; luaK_exp2anyreg(fs,v); yindex(ls,&key); luaK_indexed(fs,v,&key); break; } case':':{ expdesc key; luaX_next(ls); checkname(ls,&key); luaK_self(fs,v,&key); funcargs(ls,v); break; } case'(':case TK_STRING:case'{':{ luaK_exp2nextreg(fs,v); funcargs(ls,v); break; } default:return; } } } static void simpleexp(LexState*ls,expdesc*v){ switch(ls->t.token){ case TK_NUMBER:{ init_exp(v,VKNUM,0); v->u.nval=ls->t.seminfo.r; break; } case TK_STRING:{ codestring(ls,v,ls->t.seminfo.ts); break; } case TK_NIL:{ init_exp(v,VNIL,0); break; } case TK_TRUE:{ init_exp(v,VTRUE,0); break; } case TK_FALSE:{ init_exp(v,VFALSE,0); break; } case TK_DOTS:{ FuncState*fs=ls->fs; check_condition(ls,fs->f->is_vararg, "cannot use "LUA_QL("...")" outside a vararg function"); fs->f->is_vararg&=~4; init_exp(v,VVARARG,luaK_codeABC(fs,OP_VARARG,0,1,0)); break; } case'{':{ constructor(ls,v); return; } case TK_FUNCTION:{ luaX_next(ls); body(ls,v,0,ls->linenumber); return; } default:{ primaryexp(ls,v); return; } } luaX_next(ls); } static UnOpr getunopr(int op){ switch(op){ case TK_NOT:return OPR_NOT; case'-':return OPR_MINUS; case'#':return OPR_LEN; default:return OPR_NOUNOPR; } } static BinOpr getbinopr(int op){ switch(op){ case'+':return OPR_ADD; case'-':return OPR_SUB; case'*':return OPR_MUL; case'/':return OPR_DIV; case'%':return OPR_MOD; case'^':return OPR_POW; case TK_CONCAT:return OPR_CONCAT; case TK_NE:return OPR_NE; case TK_EQ:return OPR_EQ; case'<':return OPR_LT; case TK_LE:return OPR_LE; case'>':return OPR_GT; case TK_GE:return OPR_GE; case TK_AND:return OPR_AND; case TK_OR:return OPR_OR; default:return OPR_NOBINOPR; } } static const struct{ lu_byte left; lu_byte right; }priority[]={ {6,6},{6,6},{7,7},{7,7},{7,7}, {10,9},{5,4}, {3,3},{3,3}, {3,3},{3,3},{3,3},{3,3}, {2,2},{1,1} }; static BinOpr subexpr(LexState*ls,expdesc*v,unsigned int limit){ BinOpr op; UnOpr uop; enterlevel(ls); uop=getunopr(ls->t.token); if(uop!=OPR_NOUNOPR){ luaX_next(ls); subexpr(ls,v,8); luaK_prefix(ls->fs,uop,v); } else simpleexp(ls,v); op=getbinopr(ls->t.token); while(op!=OPR_NOBINOPR&&priority[op].left>limit){ expdesc v2; BinOpr nextop; luaX_next(ls); luaK_infix(ls->fs,op,v); nextop=subexpr(ls,&v2,priority[op].right); luaK_posfix(ls->fs,op,v,&v2); op=nextop; } leavelevel(ls); return op; } static void expr(LexState*ls,expdesc*v){ subexpr(ls,v,0); } static int block_follow(int token){ switch(token){ case TK_ELSE:case TK_ELSEIF:case TK_END: case TK_UNTIL:case TK_EOS: return 1; default:return 0; } } static void block(LexState*ls){ FuncState*fs=ls->fs; BlockCnt bl; enterblock(fs,&bl,0); chunk(ls); leaveblock(fs); } struct LHS_assign{ struct LHS_assign*prev; expdesc v; }; static void check_conflict(LexState*ls,struct LHS_assign*lh,expdesc*v){ FuncState*fs=ls->fs; int extra=fs->freereg; int conflict=0; for(;lh;lh=lh->prev){ if(lh->v.k==VINDEXED){ if(lh->v.u.s.info==v->u.s.info){ conflict=1; lh->v.u.s.info=extra; } if(lh->v.u.s.aux==v->u.s.info){ conflict=1; lh->v.u.s.aux=extra; } } } if(conflict){ luaK_codeABC(fs,OP_MOVE,fs->freereg,v->u.s.info,0); luaK_reserveregs(fs,1); } } static void assignment(LexState*ls,struct LHS_assign*lh,int nvars){ expdesc e; check_condition(ls,VLOCAL<=lh->v.k&&lh->v.k<=VINDEXED, "syntax error"); if(testnext(ls,',')){ struct LHS_assign nv; nv.prev=lh; primaryexp(ls,&nv.v); if(nv.v.k==VLOCAL) check_conflict(ls,lh,&nv.v); luaY_checklimit(ls->fs,nvars,200-ls->L->nCcalls, "variables in assignment"); assignment(ls,&nv,nvars+1); } else{ int nexps; checknext(ls,'='); nexps=explist1(ls,&e); if(nexps!=nvars){ adjust_assign(ls,nvars,nexps,&e); if(nexps>nvars) ls->fs->freereg-=nexps-nvars; } else{ luaK_setoneret(ls->fs,&e); luaK_storevar(ls->fs,&lh->v,&e); return; } } init_exp(&e,VNONRELOC,ls->fs->freereg-1); luaK_storevar(ls->fs,&lh->v,&e); } static int cond(LexState*ls){ expdesc v; expr(ls,&v); if(v.k==VNIL)v.k=VFALSE; luaK_goiftrue(ls->fs,&v); return v.f; } static void breakstat(LexState*ls){ FuncState*fs=ls->fs; BlockCnt*bl=fs->bl; int upval=0; while(bl&&!bl->isbreakable){ upval|=bl->upval; bl=bl->previous; } if(!bl) luaX_syntaxerror(ls,"no loop to break"); if(upval) luaK_codeABC(fs,OP_CLOSE,bl->nactvar,0,0); luaK_concat(fs,&bl->breaklist,luaK_jump(fs)); } static void whilestat(LexState*ls,int line){ FuncState*fs=ls->fs; int whileinit; int condexit; BlockCnt bl; luaX_next(ls); whileinit=luaK_getlabel(fs); condexit=cond(ls); enterblock(fs,&bl,1); checknext(ls,TK_DO); block(ls); luaK_patchlist(fs,luaK_jump(fs),whileinit); check_match(ls,TK_END,TK_WHILE,line); leaveblock(fs); luaK_patchtohere(fs,condexit); } static void repeatstat(LexState*ls,int line){ int condexit; FuncState*fs=ls->fs; int repeat_init=luaK_getlabel(fs); BlockCnt bl1,bl2; enterblock(fs,&bl1,1); enterblock(fs,&bl2,0); luaX_next(ls); chunk(ls); check_match(ls,TK_UNTIL,TK_REPEAT,line); condexit=cond(ls); if(!bl2.upval){ leaveblock(fs); luaK_patchlist(ls->fs,condexit,repeat_init); } else{ breakstat(ls); luaK_patchtohere(ls->fs,condexit); leaveblock(fs); luaK_patchlist(ls->fs,luaK_jump(fs),repeat_init); } leaveblock(fs); } static int exp1(LexState*ls){ expdesc e; int k; expr(ls,&e); k=e.k; luaK_exp2nextreg(ls->fs,&e); return k; } static void forbody(LexState*ls,int base,int line,int nvars,int isnum){ BlockCnt bl; FuncState*fs=ls->fs; int prep,endfor; adjustlocalvars(ls,3); checknext(ls,TK_DO); prep=isnum?luaK_codeAsBx(fs,OP_FORPREP,base,(-1)):luaK_jump(fs); enterblock(fs,&bl,0); adjustlocalvars(ls,nvars); luaK_reserveregs(fs,nvars); block(ls); leaveblock(fs); luaK_patchtohere(fs,prep); endfor=(isnum)?luaK_codeAsBx(fs,OP_FORLOOP,base,(-1)): luaK_codeABC(fs,OP_TFORLOOP,base,0,nvars); luaK_fixline(fs,line); luaK_patchlist(fs,(isnum?endfor:luaK_jump(fs)),prep+1); } static void fornum(LexState*ls,TString*varname,int line){ FuncState*fs=ls->fs; int base=fs->freereg; new_localvarliteral(ls,"(for index)",0); new_localvarliteral(ls,"(for limit)",1); new_localvarliteral(ls,"(for step)",2); new_localvar(ls,varname,3); checknext(ls,'='); exp1(ls); checknext(ls,','); exp1(ls); if(testnext(ls,',')) exp1(ls); else{ luaK_codeABx(fs,OP_LOADK,fs->freereg,luaK_numberK(fs,1)); luaK_reserveregs(fs,1); } forbody(ls,base,line,1,1); } static void forlist(LexState*ls,TString*indexname){ FuncState*fs=ls->fs; expdesc e; int nvars=0; int line; int base=fs->freereg; new_localvarliteral(ls,"(for generator)",nvars++); new_localvarliteral(ls,"(for state)",nvars++); new_localvarliteral(ls,"(for control)",nvars++); new_localvar(ls,indexname,nvars++); while(testnext(ls,',')) new_localvar(ls,str_checkname(ls),nvars++); checknext(ls,TK_IN); line=ls->linenumber; adjust_assign(ls,3,explist1(ls,&e),&e); luaK_checkstack(fs,3); forbody(ls,base,line,nvars-3,0); } static void forstat(LexState*ls,int line){ FuncState*fs=ls->fs; TString*varname; BlockCnt bl; enterblock(fs,&bl,1); luaX_next(ls); varname=str_checkname(ls); switch(ls->t.token){ case'=':fornum(ls,varname,line);break; case',':case TK_IN:forlist(ls,varname);break; default:luaX_syntaxerror(ls,LUA_QL("=")" or "LUA_QL("in")" expected"); } check_match(ls,TK_END,TK_FOR,line); leaveblock(fs); } static int test_then_block(LexState*ls){ int condexit; luaX_next(ls); condexit=cond(ls); checknext(ls,TK_THEN); block(ls); return condexit; } static void ifstat(LexState*ls,int line){ FuncState*fs=ls->fs; int flist; int escapelist=(-1); flist=test_then_block(ls); while(ls->t.token==TK_ELSEIF){ luaK_concat(fs,&escapelist,luaK_jump(fs)); luaK_patchtohere(fs,flist); flist=test_then_block(ls); } if(ls->t.token==TK_ELSE){ luaK_concat(fs,&escapelist,luaK_jump(fs)); luaK_patchtohere(fs,flist); luaX_next(ls); block(ls); } else luaK_concat(fs,&escapelist,flist); luaK_patchtohere(fs,escapelist); check_match(ls,TK_END,TK_IF,line); } static void localfunc(LexState*ls){ expdesc v,b; FuncState*fs=ls->fs; new_localvar(ls,str_checkname(ls),0); init_exp(&v,VLOCAL,fs->freereg); luaK_reserveregs(fs,1); adjustlocalvars(ls,1); body(ls,&b,0,ls->linenumber); luaK_storevar(fs,&v,&b); getlocvar(fs,fs->nactvar-1).startpc=fs->pc; } static void localstat(LexState*ls){ int nvars=0; int nexps; expdesc e; do{ new_localvar(ls,str_checkname(ls),nvars++); }while(testnext(ls,',')); if(testnext(ls,'=')) nexps=explist1(ls,&e); else{ e.k=VVOID; nexps=0; } adjust_assign(ls,nvars,nexps,&e); adjustlocalvars(ls,nvars); } static int funcname(LexState*ls,expdesc*v){ int needself=0; singlevar(ls,v); while(ls->t.token=='.') field(ls,v); if(ls->t.token==':'){ needself=1; field(ls,v); } return needself; } static void funcstat(LexState*ls,int line){ int needself; expdesc v,b; luaX_next(ls); needself=funcname(ls,&v); body(ls,&b,needself,line); luaK_storevar(ls->fs,&v,&b); luaK_fixline(ls->fs,line); } static void exprstat(LexState*ls){ FuncState*fs=ls->fs; struct LHS_assign v; primaryexp(ls,&v.v); if(v.v.k==VCALL) SETARG_C(getcode(fs,&v.v),1); else{ v.prev=NULL; assignment(ls,&v,1); } } static void retstat(LexState*ls){ FuncState*fs=ls->fs; expdesc e; int first,nret; luaX_next(ls); if(block_follow(ls->t.token)||ls->t.token==';') first=nret=0; else{ nret=explist1(ls,&e); if(hasmultret(e.k)){ luaK_setmultret(fs,&e); if(e.k==VCALL&&nret==1){ SET_OPCODE(getcode(fs,&e),OP_TAILCALL); } first=fs->nactvar; nret=(-1); } else{ if(nret==1) first=luaK_exp2anyreg(fs,&e); else{ luaK_exp2nextreg(fs,&e); first=fs->nactvar; } } } luaK_ret(fs,first,nret); } static int statement(LexState*ls){ int line=ls->linenumber; switch(ls->t.token){ case TK_IF:{ ifstat(ls,line); return 0; } case TK_WHILE:{ whilestat(ls,line); return 0; } case TK_DO:{ luaX_next(ls); block(ls); check_match(ls,TK_END,TK_DO,line); return 0; } case TK_FOR:{ forstat(ls,line); return 0; } case TK_REPEAT:{ repeatstat(ls,line); return 0; } case TK_FUNCTION:{ funcstat(ls,line); return 0; } case TK_LOCAL:{ luaX_next(ls); if(testnext(ls,TK_FUNCTION)) localfunc(ls); else localstat(ls); return 0; } case TK_RETURN:{ retstat(ls); return 1; } case TK_BREAK:{ luaX_next(ls); breakstat(ls); return 1; } default:{ exprstat(ls); return 0; } } } static void chunk(LexState*ls){ int islast=0; enterlevel(ls); while(!islast&&!block_follow(ls->t.token)){ islast=statement(ls); testnext(ls,';'); ls->fs->freereg=ls->fs->nactvar; } leavelevel(ls); } static const TValue*luaV_tonumber(const TValue*obj,TValue*n){ lua_Number num; if(ttisnumber(obj))return obj; if(ttisstring(obj)&&luaO_str2d(svalue(obj),&num)){ setnvalue(n,num); return n; } else return NULL; } static int luaV_tostring(lua_State*L,StkId obj){ if(!ttisnumber(obj)) return 0; else{ char s[32]; lua_Number n=nvalue(obj); lua_number2str(s,n); setsvalue(L,obj,luaS_new(L,s)); return 1; } } static void callTMres(lua_State*L,StkId res,const TValue*f, const TValue*p1,const TValue*p2){ ptrdiff_t result=savestack(L,res); setobj(L,L->top,f); setobj(L,L->top+1,p1); setobj(L,L->top+2,p2); luaD_checkstack(L,3); L->top+=3; luaD_call(L,L->top-3,1); res=restorestack(L,result); L->top--; setobj(L,res,L->top); } static void callTM(lua_State*L,const TValue*f,const TValue*p1, const TValue*p2,const TValue*p3){ setobj(L,L->top,f); setobj(L,L->top+1,p1); setobj(L,L->top+2,p2); setobj(L,L->top+3,p3); luaD_checkstack(L,4); L->top+=4; luaD_call(L,L->top-4,0); } static void luaV_gettable(lua_State*L,const TValue*t,TValue*key,StkId val){ int loop; for(loop=0;loop<100;loop++){ const TValue*tm; if(ttistable(t)){ Table*h=hvalue(t); const TValue*res=luaH_get(h,key); if(!ttisnil(res)|| (tm=fasttm(L,h->metatable,TM_INDEX))==NULL){ setobj(L,val,res); return; } } else if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_INDEX))) luaG_typeerror(L,t,"index"); if(ttisfunction(tm)){ callTMres(L,val,tm,t,key); return; } t=tm; } luaG_runerror(L,"loop in gettable"); } static void luaV_settable(lua_State*L,const TValue*t,TValue*key,StkId val){ int loop; TValue temp; for(loop=0;loop<100;loop++){ const TValue*tm; if(ttistable(t)){ Table*h=hvalue(t); TValue*oldval=luaH_set(L,h,key); if(!ttisnil(oldval)|| (tm=fasttm(L,h->metatable,TM_NEWINDEX))==NULL){ setobj(L,oldval,val); h->flags=0; luaC_barriert(L,h,val); return; } } else if(ttisnil(tm=luaT_gettmbyobj(L,t,TM_NEWINDEX))) luaG_typeerror(L,t,"index"); if(ttisfunction(tm)){ callTM(L,tm,t,key,val); return; } setobj(L,&temp,tm); t=&temp; } luaG_runerror(L,"loop in settable"); } static int call_binTM(lua_State*L,const TValue*p1,const TValue*p2, StkId res,TMS event){ const TValue*tm=luaT_gettmbyobj(L,p1,event); if(ttisnil(tm)) tm=luaT_gettmbyobj(L,p2,event); if(ttisnil(tm))return 0; callTMres(L,res,tm,p1,p2); return 1; } static const TValue*get_compTM(lua_State*L,Table*mt1,Table*mt2, TMS event){ const TValue*tm1=fasttm(L,mt1,event); const TValue*tm2; if(tm1==NULL)return NULL; if(mt1==mt2)return tm1; tm2=fasttm(L,mt2,event); if(tm2==NULL)return NULL; if(luaO_rawequalObj(tm1,tm2)) return tm1; return NULL; } static int call_orderTM(lua_State*L,const TValue*p1,const TValue*p2, TMS event){ const TValue*tm1=luaT_gettmbyobj(L,p1,event); const TValue*tm2; if(ttisnil(tm1))return-1; tm2=luaT_gettmbyobj(L,p2,event); if(!luaO_rawequalObj(tm1,tm2)) return-1; callTMres(L,L->top,tm1,p1,p2); return!l_isfalse(L->top); } static int l_strcmp(const TString*ls,const TString*rs){ const char*l=getstr(ls); size_t ll=ls->tsv.len; const char*r=getstr(rs); size_t lr=rs->tsv.len; for(;;){ int temp=strcoll(l,r); if(temp!=0)return temp; else{ size_t len=strlen(l); if(len==lr) return(len==ll)?0:1; else if(len==ll) return-1; len++; l+=len;ll-=len;r+=len;lr-=len; } } } static int luaV_lessthan(lua_State*L,const TValue*l,const TValue*r){ int res; if(ttype(l)!=ttype(r)) return luaG_ordererror(L,l,r); else if(ttisnumber(l)) return luai_numlt(nvalue(l),nvalue(r)); else if(ttisstring(l)) return l_strcmp(rawtsvalue(l),rawtsvalue(r))<0; else if((res=call_orderTM(L,l,r,TM_LT))!=-1) return res; return luaG_ordererror(L,l,r); } static int lessequal(lua_State*L,const TValue*l,const TValue*r){ int res; if(ttype(l)!=ttype(r)) return luaG_ordererror(L,l,r); else if(ttisnumber(l)) return luai_numle(nvalue(l),nvalue(r)); else if(ttisstring(l)) return l_strcmp(rawtsvalue(l),rawtsvalue(r))<=0; else if((res=call_orderTM(L,l,r,TM_LE))!=-1) return res; else if((res=call_orderTM(L,r,l,TM_LT))!=-1) return!res; return luaG_ordererror(L,l,r); } static int luaV_equalval(lua_State*L,const TValue*t1,const TValue*t2){ const TValue*tm; switch(ttype(t1)){ case 0:return 1; case 3:return luai_numeq(nvalue(t1),nvalue(t2)); case 1:return bvalue(t1)==bvalue(t2); case 2:return pvalue(t1)==pvalue(t2); case 7:{ if(uvalue(t1)==uvalue(t2))return 1; tm=get_compTM(L,uvalue(t1)->metatable,uvalue(t2)->metatable, TM_EQ); break; } case 5:{ if(hvalue(t1)==hvalue(t2))return 1; tm=get_compTM(L,hvalue(t1)->metatable,hvalue(t2)->metatable,TM_EQ); break; } default:return gcvalue(t1)==gcvalue(t2); } if(tm==NULL)return 0; callTMres(L,L->top,tm,t1,t2); return!l_isfalse(L->top); } static void luaV_concat(lua_State*L,int total,int last){ do{ StkId top=L->base+last+1; int n=2; if(!(ttisstring(top-2)||ttisnumber(top-2))||!tostring(L,top-1)){ if(!call_binTM(L,top-2,top-1,top-2,TM_CONCAT)) luaG_concaterror(L,top-2,top-1); }else if(tsvalue(top-1)->len==0) (void)tostring(L,top-2); else{ size_t tl=tsvalue(top-1)->len; char*buffer; int i; for(n=1;n<total&&tostring(L,top-n-1);n++){ size_t l=tsvalue(top-n-1)->len; if(l>=((size_t)(~(size_t)0)-2)-tl)luaG_runerror(L,"string length overflow"); tl+=l; } buffer=luaZ_openspace(L,&G(L)->buff,tl); tl=0; for(i=n;i>0;i--){ size_t l=tsvalue(top-i)->len; memcpy(buffer+tl,svalue(top-i),l); tl+=l; } setsvalue(L,top-n,luaS_newlstr(L,buffer,tl)); } total-=n-1; last-=n-1; }while(total>1); } static void Arith(lua_State*L,StkId ra,const TValue*rb, const TValue*rc,TMS op){ TValue tempb,tempc; const TValue*b,*c; if((b=luaV_tonumber(rb,&tempb))!=NULL&& (c=luaV_tonumber(rc,&tempc))!=NULL){ lua_Number nb=nvalue(b),nc=nvalue(c); switch(op){ case TM_ADD:setnvalue(ra,luai_numadd(nb,nc));break; case TM_SUB:setnvalue(ra,luai_numsub(nb,nc));break; case TM_MUL:setnvalue(ra,luai_nummul(nb,nc));break; case TM_DIV:setnvalue(ra,luai_numdiv(nb,nc));break; case TM_MOD:setnvalue(ra,luai_nummod(nb,nc));break; case TM_POW:setnvalue(ra,luai_numpow(nb,nc));break; case TM_UNM:setnvalue(ra,luai_numunm(nb));break; default:break; } } else if(!call_binTM(L,rb,rc,ra,op)) luaG_aritherror(L,rb,rc); } #define runtime_check(L,c){if(!(c))break;} #define RA(i)(base+GETARG_A(i)) #define RB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgR,base+GETARG_B(i)) #define RKB(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_B(i))?k+INDEXK(GETARG_B(i)):base+GETARG_B(i)) #define RKC(i)check_exp(getCMode(GET_OPCODE(i))==OpArgK,ISK(GETARG_C(i))?k+INDEXK(GETARG_C(i)):base+GETARG_C(i)) #define KBx(i)check_exp(getBMode(GET_OPCODE(i))==OpArgK,k+GETARG_Bx(i)) #define dojump(L,pc,i){(pc)+=(i);} #define Protect(x){L->savedpc=pc;{x;};base=L->base;} #define arith_op(op,tm){TValue*rb=RKB(i);TValue*rc=RKC(i);if(ttisnumber(rb)&&ttisnumber(rc)){lua_Number nb=nvalue(rb),nc=nvalue(rc);setnvalue(ra,op(nb,nc));}else Protect(Arith(L,ra,rb,rc,tm));} static void luaV_execute(lua_State*L,int nexeccalls){ LClosure*cl; StkId base; TValue*k; const Instruction*pc; reentry: pc=L->savedpc; cl=&clvalue(L->ci->func)->l; base=L->base; k=cl->p->k; for(;;){ const Instruction i=*pc++; StkId ra; ra=RA(i); switch(GET_OPCODE(i)){ case OP_MOVE:{ setobj(L,ra,RB(i)); continue; } case OP_LOADK:{ setobj(L,ra,KBx(i)); continue; } case OP_LOADBOOL:{ setbvalue(ra,GETARG_B(i)); if(GETARG_C(i))pc++; continue; } case OP_LOADNIL:{ TValue*rb=RB(i); do{ setnilvalue(rb--); }while(rb>=ra); continue; } case OP_GETUPVAL:{ int b=GETARG_B(i); setobj(L,ra,cl->upvals[b]->v); continue; } case OP_GETGLOBAL:{ TValue g; TValue*rb=KBx(i); sethvalue(L,&g,cl->env); Protect(luaV_gettable(L,&g,rb,ra)); continue; } case OP_GETTABLE:{ Protect(luaV_gettable(L,RB(i),RKC(i),ra)); continue; } case OP_SETGLOBAL:{ TValue g; sethvalue(L,&g,cl->env); Protect(luaV_settable(L,&g,KBx(i),ra)); continue; } case OP_SETUPVAL:{ UpVal*uv=cl->upvals[GETARG_B(i)]; setobj(L,uv->v,ra); luaC_barrier(L,uv,ra); continue; } case OP_SETTABLE:{ Protect(luaV_settable(L,ra,RKB(i),RKC(i))); continue; } case OP_NEWTABLE:{ int b=GETARG_B(i); int c=GETARG_C(i); sethvalue(L,ra,luaH_new(L,luaO_fb2int(b),luaO_fb2int(c))); Protect(luaC_checkGC(L)); continue; } case OP_SELF:{ StkId rb=RB(i); setobj(L,ra+1,rb); Protect(luaV_gettable(L,rb,RKC(i),ra)); continue; } case OP_ADD:{ arith_op(luai_numadd,TM_ADD); continue; } case OP_SUB:{ arith_op(luai_numsub,TM_SUB); continue; } case OP_MUL:{ arith_op(luai_nummul,TM_MUL); continue; } case OP_DIV:{ arith_op(luai_numdiv,TM_DIV); continue; } case OP_MOD:{ arith_op(luai_nummod,TM_MOD); continue; } case OP_POW:{ arith_op(luai_numpow,TM_POW); continue; } case OP_UNM:{ TValue*rb=RB(i); if(ttisnumber(rb)){ lua_Number nb=nvalue(rb); setnvalue(ra,luai_numunm(nb)); } else{ Protect(Arith(L,ra,rb,rb,TM_UNM)); } continue; } case OP_NOT:{ int res=l_isfalse(RB(i)); setbvalue(ra,res); continue; } case OP_LEN:{ const TValue*rb=RB(i); switch(ttype(rb)){ case 5:{ setnvalue(ra,cast_num(luaH_getn(hvalue(rb)))); break; } case 4:{ setnvalue(ra,cast_num(tsvalue(rb)->len)); break; } default:{ Protect( if(!call_binTM(L,rb,(&luaO_nilobject_),ra,TM_LEN)) luaG_typeerror(L,rb,"get length of"); ) } } continue; } case OP_CONCAT:{ int b=GETARG_B(i); int c=GETARG_C(i); Protect(luaV_concat(L,c-b+1,c);luaC_checkGC(L)); setobj(L,RA(i),base+b); continue; } case OP_JMP:{ dojump(L,pc,GETARG_sBx(i)); continue; } case OP_EQ:{ TValue*rb=RKB(i); TValue*rc=RKC(i); Protect( if(equalobj(L,rb,rc)==GETARG_A(i)) dojump(L,pc,GETARG_sBx(*pc)); ) pc++; continue; } case OP_LT:{ Protect( if(luaV_lessthan(L,RKB(i),RKC(i))==GETARG_A(i)) dojump(L,pc,GETARG_sBx(*pc)); ) pc++; continue; } case OP_LE:{ Protect( if(lessequal(L,RKB(i),RKC(i))==GETARG_A(i)) dojump(L,pc,GETARG_sBx(*pc)); ) pc++; continue; } case OP_TEST:{ if(l_isfalse(ra)!=GETARG_C(i)) dojump(L,pc,GETARG_sBx(*pc)); pc++; continue; } case OP_TESTSET:{ TValue*rb=RB(i); if(l_isfalse(rb)!=GETARG_C(i)){ setobj(L,ra,rb); dojump(L,pc,GETARG_sBx(*pc)); } pc++; continue; } case OP_CALL:{ int b=GETARG_B(i); int nresults=GETARG_C(i)-1; if(b!=0)L->top=ra+b; L->savedpc=pc; switch(luaD_precall(L,ra,nresults)){ case 0:{ nexeccalls++; goto reentry; } case 1:{ if(nresults>=0)L->top=L->ci->top; base=L->base; continue; } default:{ return; } } } case OP_TAILCALL:{ int b=GETARG_B(i); if(b!=0)L->top=ra+b; L->savedpc=pc; switch(luaD_precall(L,ra,(-1))){ case 0:{ CallInfo*ci=L->ci-1; int aux; StkId func=ci->func; StkId pfunc=(ci+1)->func; if(L->openupval)luaF_close(L,ci->base); L->base=ci->base=ci->func+((ci+1)->base-pfunc); for(aux=0;pfunc+aux<L->top;aux++) setobj(L,func+aux,pfunc+aux); ci->top=L->top=func+aux; ci->savedpc=L->savedpc; ci->tailcalls++; L->ci--; goto reentry; } case 1:{ base=L->base; continue; } default:{ return; } } } case OP_RETURN:{ int b=GETARG_B(i); if(b!=0)L->top=ra+b-1; if(L->openupval)luaF_close(L,base); L->savedpc=pc; b=luaD_poscall(L,ra); if(--nexeccalls==0) return; else{ if(b)L->top=L->ci->top; goto reentry; } } case OP_FORLOOP:{ lua_Number step=nvalue(ra+2); lua_Number idx=luai_numadd(nvalue(ra),step); lua_Number limit=nvalue(ra+1); if(luai_numlt(0,step)?luai_numle(idx,limit) :luai_numle(limit,idx)){ dojump(L,pc,GETARG_sBx(i)); setnvalue(ra,idx); setnvalue(ra+3,idx); } continue; } case OP_FORPREP:{ const TValue*init=ra; const TValue*plimit=ra+1; const TValue*pstep=ra+2; L->savedpc=pc; if(!tonumber(init,ra)) luaG_runerror(L,LUA_QL("for")" initial value must be a number"); else if(!tonumber(plimit,ra+1)) luaG_runerror(L,LUA_QL("for")" limit must be a number"); else if(!tonumber(pstep,ra+2)) luaG_runerror(L,LUA_QL("for")" step must be a number"); setnvalue(ra,luai_numsub(nvalue(ra),nvalue(pstep))); dojump(L,pc,GETARG_sBx(i)); continue; } case OP_TFORLOOP:{ StkId cb=ra+3; setobj(L,cb+2,ra+2); setobj(L,cb+1,ra+1); setobj(L,cb,ra); L->top=cb+3; Protect(luaD_call(L,cb,GETARG_C(i))); L->top=L->ci->top; cb=RA(i)+3; if(!ttisnil(cb)){ setobj(L,cb-1,cb); dojump(L,pc,GETARG_sBx(*pc)); } pc++; continue; } case OP_SETLIST:{ int n=GETARG_B(i); int c=GETARG_C(i); int last; Table*h; if(n==0){ n=cast_int(L->top-ra)-1; L->top=L->ci->top; } if(c==0)c=cast_int(*pc++); runtime_check(L,ttistable(ra)); h=hvalue(ra); last=((c-1)*50)+n; if(last>h->sizearray) luaH_resizearray(L,h,last); for(;n>0;n--){ TValue*val=ra+n; setobj(L,luaH_setnum(L,h,last--),val); luaC_barriert(L,h,val); } continue; } case OP_CLOSE:{ luaF_close(L,ra); continue; } case OP_CLOSURE:{ Proto*p; Closure*ncl; int nup,j; p=cl->p->p[GETARG_Bx(i)]; nup=p->nups; ncl=luaF_newLclosure(L,nup,cl->env); ncl->l.p=p; for(j=0;j<nup;j++,pc++){ if(GET_OPCODE(*pc)==OP_GETUPVAL) ncl->l.upvals[j]=cl->upvals[GETARG_B(*pc)]; else{ ncl->l.upvals[j]=luaF_findupval(L,base+GETARG_B(*pc)); } } setclvalue(L,ra,ncl); Protect(luaC_checkGC(L)); continue; } case OP_VARARG:{ int b=GETARG_B(i)-1; int j; CallInfo*ci=L->ci; int n=cast_int(ci->base-ci->func)-cl->p->numparams-1; if(b==(-1)){ Protect(luaD_checkstack(L,n)); ra=RA(i); b=n; L->top=ra+n; } for(j=0;j<b;j++){ if(j<n){ setobj(L,ra+j,ci->base-n+j); } else{ setnilvalue(ra+j); } } continue; } } } } #define api_checknelems(L,n)luai_apicheck(L,(n)<=(L->top-L->base)) #define api_checkvalidindex(L,i)luai_apicheck(L,(i)!=(&luaO_nilobject_)) #define api_incr_top(L){luai_apicheck(L,L->top<L->ci->top);L->top++;} static TValue*index2adr(lua_State*L,int idx){ if(idx>0){ TValue*o=L->base+(idx-1); luai_apicheck(L,idx<=L->ci->top-L->base); if(o>=L->top)return cast(TValue*,(&luaO_nilobject_)); else return o; } else if(idx>(-10000)){ luai_apicheck(L,idx!=0&&-idx<=L->top-L->base); return L->top+idx; } else switch(idx){ case(-10000):return registry(L); case(-10001):{ Closure*func=curr_func(L); sethvalue(L,&L->env,func->c.env); return&L->env; } case(-10002):return gt(L); default:{ Closure*func=curr_func(L); idx=(-10002)-idx; return(idx<=func->c.nupvalues) ?&func->c.upvalue[idx-1] :cast(TValue*,(&luaO_nilobject_)); } } } static Table*getcurrenv(lua_State*L){ if(L->ci==L->base_ci) return hvalue(gt(L)); else{ Closure*func=curr_func(L); return func->c.env; } } static int lua_checkstack(lua_State*L,int size){ int res=1; if(size>8000||(L->top-L->base+size)>8000) res=0; else if(size>0){ luaD_checkstack(L,size); if(L->ci->top<L->top+size) L->ci->top=L->top+size; } return res; } static lua_CFunction lua_atpanic(lua_State*L,lua_CFunction panicf){ lua_CFunction old; old=G(L)->panic; G(L)->panic=panicf; return old; } static int lua_gettop(lua_State*L){ return cast_int(L->top-L->base); } static void lua_settop(lua_State*L,int idx){ if(idx>=0){ luai_apicheck(L,idx<=L->stack_last-L->base); while(L->top<L->base+idx) setnilvalue(L->top++); L->top=L->base+idx; } else{ luai_apicheck(L,-(idx+1)<=(L->top-L->base)); L->top+=idx+1; } } static void lua_remove(lua_State*L,int idx){ StkId p; p=index2adr(L,idx); api_checkvalidindex(L,p); while(++p<L->top)setobj(L,p-1,p); L->top--; } static void lua_insert(lua_State*L,int idx){ StkId p; StkId q; p=index2adr(L,idx); api_checkvalidindex(L,p); for(q=L->top;q>p;q--)setobj(L,q,q-1); setobj(L,p,L->top); } static void lua_replace(lua_State*L,int idx){ StkId o; if(idx==(-10001)&&L->ci==L->base_ci) luaG_runerror(L,"no calling environment"); api_checknelems(L,1); o=index2adr(L,idx); api_checkvalidindex(L,o); if(idx==(-10001)){ Closure*func=curr_func(L); luai_apicheck(L,ttistable(L->top-1)); func->c.env=hvalue(L->top-1); luaC_barrier(L,func,L->top-1); } else{ setobj(L,o,L->top-1); if(idx<(-10002)) luaC_barrier(L,curr_func(L),L->top-1); } L->top--; } static void lua_pushvalue(lua_State*L,int idx){ setobj(L,L->top,index2adr(L,idx)); api_incr_top(L); } static int lua_type(lua_State*L,int idx){ StkId o=index2adr(L,idx); return(o==(&luaO_nilobject_))?(-1):ttype(o); } static const char*lua_typename(lua_State*L,int t){ UNUSED(L); return(t==(-1))?"no value":luaT_typenames[t]; } static int lua_iscfunction(lua_State*L,int idx){ StkId o=index2adr(L,idx); return iscfunction(o); } static int lua_isnumber(lua_State*L,int idx){ TValue n; const TValue*o=index2adr(L,idx); return tonumber(o,&n); } static int lua_isstring(lua_State*L,int idx){ int t=lua_type(L,idx); return(t==4||t==3); } static int lua_rawequal(lua_State*L,int index1,int index2){ StkId o1=index2adr(L,index1); StkId o2=index2adr(L,index2); return(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0 :luaO_rawequalObj(o1,o2); } static int lua_lessthan(lua_State*L,int index1,int index2){ StkId o1,o2; int i; o1=index2adr(L,index1); o2=index2adr(L,index2); i=(o1==(&luaO_nilobject_)||o2==(&luaO_nilobject_))?0 :luaV_lessthan(L,o1,o2); return i; } static lua_Number lua_tonumber(lua_State*L,int idx){ TValue n; const TValue*o=index2adr(L,idx); if(tonumber(o,&n)) return nvalue(o); else return 0; } static lua_Integer lua_tointeger(lua_State*L,int idx){ TValue n; const TValue*o=index2adr(L,idx); if(tonumber(o,&n)){ lua_Integer res; lua_Number num=nvalue(o); lua_number2integer(res,num); return res; } else return 0; } static int lua_toboolean(lua_State*L,int idx){ const TValue*o=index2adr(L,idx); return!l_isfalse(o); } static const char*lua_tolstring(lua_State*L,int idx,size_t*len){ StkId o=index2adr(L,idx); if(!ttisstring(o)){ if(!luaV_tostring(L,o)){ if(len!=NULL)*len=0; return NULL; } luaC_checkGC(L); o=index2adr(L,idx); } if(len!=NULL)*len=tsvalue(o)->len; return svalue(o); } static size_t lua_objlen(lua_State*L,int idx){ StkId o=index2adr(L,idx); switch(ttype(o)){ case 4:return tsvalue(o)->len; case 7:return uvalue(o)->len; case 5:return luaH_getn(hvalue(o)); case 3:{ size_t l; l=(luaV_tostring(L,o)?tsvalue(o)->len:0); return l; } default:return 0; } } static lua_CFunction lua_tocfunction(lua_State*L,int idx){ StkId o=index2adr(L,idx); return(!iscfunction(o))?NULL:clvalue(o)->c.f; } static void*lua_touserdata(lua_State*L,int idx){ StkId o=index2adr(L,idx); switch(ttype(o)){ case 7:return(rawuvalue(o)+1); case 2:return pvalue(o); default:return NULL; } } static void lua_pushnil(lua_State*L){ setnilvalue(L->top); api_incr_top(L); } static void lua_pushnumber(lua_State*L,lua_Number n){ setnvalue(L->top,n); api_incr_top(L); } static void lua_pushinteger(lua_State*L,lua_Integer n){ setnvalue(L->top,cast_num(n)); api_incr_top(L); } static void lua_pushlstring(lua_State*L,const char*s,size_t len){ luaC_checkGC(L); setsvalue(L,L->top,luaS_newlstr(L,s,len)); api_incr_top(L); } static void lua_pushstring(lua_State*L,const char*s){ if(s==NULL) lua_pushnil(L); else lua_pushlstring(L,s,strlen(s)); } static const char*lua_pushvfstring(lua_State*L,const char*fmt, va_list argp){ const char*ret; luaC_checkGC(L); ret=luaO_pushvfstring(L,fmt,argp); return ret; } static const char*lua_pushfstring(lua_State*L,const char*fmt,...){ const char*ret; va_list argp; luaC_checkGC(L); va_start(argp,fmt); ret=luaO_pushvfstring(L,fmt,argp); va_end(argp); return ret; } static void lua_pushcclosure(lua_State*L,lua_CFunction fn,int n){ Closure*cl; luaC_checkGC(L); api_checknelems(L,n); cl=luaF_newCclosure(L,n,getcurrenv(L)); cl->c.f=fn; L->top-=n; while(n--) setobj(L,&cl->c.upvalue[n],L->top+n); setclvalue(L,L->top,cl); api_incr_top(L); } static void lua_pushboolean(lua_State*L,int b){ setbvalue(L->top,(b!=0)); api_incr_top(L); } static int lua_pushthread(lua_State*L){ setthvalue(L,L->top,L); api_incr_top(L); return(G(L)->mainthread==L); } static void lua_gettable(lua_State*L,int idx){ StkId t; t=index2adr(L,idx); api_checkvalidindex(L,t); luaV_gettable(L,t,L->top-1,L->top-1); } static void lua_getfield(lua_State*L,int idx,const char*k){ StkId t; TValue key; t=index2adr(L,idx); api_checkvalidindex(L,t); setsvalue(L,&key,luaS_new(L,k)); luaV_gettable(L,t,&key,L->top); api_incr_top(L); } static void lua_rawget(lua_State*L,int idx){ StkId t; t=index2adr(L,idx); luai_apicheck(L,ttistable(t)); setobj(L,L->top-1,luaH_get(hvalue(t),L->top-1)); } static void lua_rawgeti(lua_State*L,int idx,int n){ StkId o; o=index2adr(L,idx); luai_apicheck(L,ttistable(o)); setobj(L,L->top,luaH_getnum(hvalue(o),n)); api_incr_top(L); } static void lua_createtable(lua_State*L,int narray,int nrec){ luaC_checkGC(L); sethvalue(L,L->top,luaH_new(L,narray,nrec)); api_incr_top(L); } static int lua_getmetatable(lua_State*L,int objindex){ const TValue*obj; Table*mt=NULL; int res; obj=index2adr(L,objindex); switch(ttype(obj)){ case 5: mt=hvalue(obj)->metatable; break; case 7: mt=uvalue(obj)->metatable; break; default: mt=G(L)->mt[ttype(obj)]; break; } if(mt==NULL) res=0; else{ sethvalue(L,L->top,mt); api_incr_top(L); res=1; } return res; } static void lua_getfenv(lua_State*L,int idx){ StkId o; o=index2adr(L,idx); api_checkvalidindex(L,o); switch(ttype(o)){ case 6: sethvalue(L,L->top,clvalue(o)->c.env); break; case 7: sethvalue(L,L->top,uvalue(o)->env); break; case 8: setobj(L,L->top,gt(thvalue(o))); break; default: setnilvalue(L->top); break; } api_incr_top(L); } static void lua_settable(lua_State*L,int idx){ StkId t; api_checknelems(L,2); t=index2adr(L,idx); api_checkvalidindex(L,t); luaV_settable(L,t,L->top-2,L->top-1); L->top-=2; } static void lua_setfield(lua_State*L,int idx,const char*k){ StkId t; TValue key; api_checknelems(L,1); t=index2adr(L,idx); api_checkvalidindex(L,t); setsvalue(L,&key,luaS_new(L,k)); luaV_settable(L,t,&key,L->top-1); L->top--; } static void lua_rawset(lua_State*L,int idx){ StkId t; api_checknelems(L,2); t=index2adr(L,idx); luai_apicheck(L,ttistable(t)); setobj(L,luaH_set(L,hvalue(t),L->top-2),L->top-1); luaC_barriert(L,hvalue(t),L->top-1); L->top-=2; } static void lua_rawseti(lua_State*L,int idx,int n){ StkId o; api_checknelems(L,1); o=index2adr(L,idx); luai_apicheck(L,ttistable(o)); setobj(L,luaH_setnum(L,hvalue(o),n),L->top-1); luaC_barriert(L,hvalue(o),L->top-1); L->top--; } static int lua_setmetatable(lua_State*L,int objindex){ TValue*obj; Table*mt; api_checknelems(L,1); obj=index2adr(L,objindex); api_checkvalidindex(L,obj); if(ttisnil(L->top-1)) mt=NULL; else{ luai_apicheck(L,ttistable(L->top-1)); mt=hvalue(L->top-1); } switch(ttype(obj)){ case 5:{ hvalue(obj)->metatable=mt; if(mt) luaC_objbarriert(L,hvalue(obj),mt); break; } case 7:{ uvalue(obj)->metatable=mt; if(mt) luaC_objbarrier(L,rawuvalue(obj),mt); break; } default:{ G(L)->mt[ttype(obj)]=mt; break; } } L->top--; return 1; } static int lua_setfenv(lua_State*L,int idx){ StkId o; int res=1; api_checknelems(L,1); o=index2adr(L,idx); api_checkvalidindex(L,o); luai_apicheck(L,ttistable(L->top-1)); switch(ttype(o)){ case 6: clvalue(o)->c.env=hvalue(L->top-1); break; case 7: uvalue(o)->env=hvalue(L->top-1); break; case 8: sethvalue(L,gt(thvalue(o)),hvalue(L->top-1)); break; default: res=0; break; } if(res)luaC_objbarrier(L,gcvalue(o),hvalue(L->top-1)); L->top--; return res; } #define adjustresults(L,nres){if(nres==(-1)&&L->top>=L->ci->top)L->ci->top=L->top;} #define checkresults(L,na,nr)luai_apicheck(L,(nr)==(-1)||(L->ci->top-L->top>=(nr)-(na))) static void lua_call(lua_State*L,int nargs,int nresults){ StkId func; api_checknelems(L,nargs+1); checkresults(L,nargs,nresults); func=L->top-(nargs+1); luaD_call(L,func,nresults); adjustresults(L,nresults); } struct CallS{ StkId func; int nresults; }; static void f_call(lua_State*L,void*ud){ struct CallS*c=cast(struct CallS*,ud); luaD_call(L,c->func,c->nresults); } static int lua_pcall(lua_State*L,int nargs,int nresults,int errfunc){ struct CallS c; int status; ptrdiff_t func; api_checknelems(L,nargs+1); checkresults(L,nargs,nresults); if(errfunc==0) func=0; else{ StkId o=index2adr(L,errfunc); api_checkvalidindex(L,o); func=savestack(L,o); } c.func=L->top-(nargs+1); c.nresults=nresults; status=luaD_pcall(L,f_call,&c,savestack(L,c.func),func); adjustresults(L,nresults); return status; } static int lua_load(lua_State*L,lua_Reader reader,void*data, const char*chunkname){ ZIO z; int status; if(!chunkname)chunkname="?"; luaZ_init(L,&z,reader,data); status=luaD_protectedparser(L,&z,chunkname); return status; } static int lua_error(lua_State*L){ api_checknelems(L,1); luaG_errormsg(L); return 0; } static int lua_next(lua_State*L,int idx){ StkId t; int more; t=index2adr(L,idx); luai_apicheck(L,ttistable(t)); more=luaH_next(L,hvalue(t),L->top-1); if(more){ api_incr_top(L); } else L->top-=1; return more; } static void lua_concat(lua_State*L,int n){ api_checknelems(L,n); if(n>=2){ luaC_checkGC(L); luaV_concat(L,n,cast_int(L->top-L->base)-1); L->top-=(n-1); } else if(n==0){ setsvalue(L,L->top,luaS_newlstr(L,"",0)); api_incr_top(L); } } static void*lua_newuserdata(lua_State*L,size_t size){ Udata*u; luaC_checkGC(L); u=luaS_newudata(L,size,getcurrenv(L)); setuvalue(L,L->top,u); api_incr_top(L); return u+1; } #define luaL_getn(L,i)((int)lua_objlen(L,i)) #define luaL_setn(L,i,j)((void)0) typedef struct luaL_Reg{ const char*name; lua_CFunction func; }luaL_Reg; static void luaI_openlib(lua_State*L,const char*libname, const luaL_Reg*l,int nup); static int luaL_argerror(lua_State*L,int numarg,const char*extramsg); static const char* luaL_checklstring(lua_State*L,int numArg, size_t*l); static const char* luaL_optlstring(lua_State*L,int numArg, const char*def,size_t*l); static lua_Integer luaL_checkinteger(lua_State*L,int numArg); static lua_Integer luaL_optinteger(lua_State*L,int nArg, lua_Integer def); static int luaL_error(lua_State*L,const char*fmt,...); static const char* luaL_findtable(lua_State*L,int idx, const char*fname,int szhint); #define luaL_argcheck(L,cond,numarg,extramsg)((void)((cond)||luaL_argerror(L,(numarg),(extramsg)))) #define luaL_checkstring(L,n)(luaL_checklstring(L,(n),NULL)) #define luaL_optstring(L,n,d)(luaL_optlstring(L,(n),(d),NULL)) #define luaL_checkint(L,n)((int)luaL_checkinteger(L,(n))) #define luaL_optint(L,n,d)((int)luaL_optinteger(L,(n),(d))) #define luaL_typename(L,i)lua_typename(L,lua_type(L,(i))) #define luaL_getmetatable(L,n)(lua_getfield(L,(-10000),(n))) #define luaL_opt(L,f,n,d)(lua_isnoneornil(L,(n))?(d):f(L,(n))) typedef struct luaL_Buffer{ char*p; int lvl; lua_State*L; char buffer[BUFSIZ]; }luaL_Buffer; #define luaL_addchar(B,c)((void)((B)->p<((B)->buffer+BUFSIZ)||luaL_prepbuffer(B)),(*(B)->p++=(char)(c))) #define luaL_addsize(B,n)((B)->p+=(n)) static char* luaL_prepbuffer(luaL_Buffer*B); static int luaL_argerror(lua_State*L,int narg,const char*extramsg){ lua_Debug ar; if(!lua_getstack(L,0,&ar)) return luaL_error(L,"bad argument #%d (%s)",narg,extramsg); lua_getinfo(L,"n",&ar); if(strcmp(ar.namewhat,"method")==0){ narg--; if(narg==0) return luaL_error(L,"calling "LUA_QL("%s")" on bad self (%s)", ar.name,extramsg); } if(ar.name==NULL) ar.name="?"; return luaL_error(L,"bad argument #%d to "LUA_QL("%s")" (%s)", narg,ar.name,extramsg); } static int luaL_typerror(lua_State*L,int narg,const char*tname){ const char*msg=lua_pushfstring(L,"%s expected, got %s", tname,luaL_typename(L,narg)); return luaL_argerror(L,narg,msg); } static void tag_error(lua_State*L,int narg,int tag){ luaL_typerror(L,narg,lua_typename(L,tag)); } static void luaL_where(lua_State*L,int level){ lua_Debug ar; if(lua_getstack(L,level,&ar)){ lua_getinfo(L,"Sl",&ar); if(ar.currentline>0){ lua_pushfstring(L,"%s:%d: ",ar.short_src,ar.currentline); return; } } lua_pushliteral(L,""); } static int luaL_error(lua_State*L,const char*fmt,...){ va_list argp; va_start(argp,fmt); luaL_where(L,1); lua_pushvfstring(L,fmt,argp); va_end(argp); lua_concat(L,2); return lua_error(L); } static int luaL_newmetatable(lua_State*L,const char*tname){ lua_getfield(L,(-10000),tname); if(!lua_isnil(L,-1)) return 0; lua_pop(L,1); lua_newtable(L); lua_pushvalue(L,-1); lua_setfield(L,(-10000),tname); return 1; } static void*luaL_checkudata(lua_State*L,int ud,const char*tname){ void*p=lua_touserdata(L,ud); if(p!=NULL){ if(lua_getmetatable(L,ud)){ lua_getfield(L,(-10000),tname); if(lua_rawequal(L,-1,-2)){ lua_pop(L,2); return p; } } } luaL_typerror(L,ud,tname); return NULL; } static void luaL_checkstack(lua_State*L,int space,const char*mes){ if(!lua_checkstack(L,space)) luaL_error(L,"stack overflow (%s)",mes); } static void luaL_checktype(lua_State*L,int narg,int t){ if(lua_type(L,narg)!=t) tag_error(L,narg,t); } static void luaL_checkany(lua_State*L,int narg){ if(lua_type(L,narg)==(-1)) luaL_argerror(L,narg,"value expected"); } static const char*luaL_checklstring(lua_State*L,int narg,size_t*len){ const char*s=lua_tolstring(L,narg,len); if(!s)tag_error(L,narg,4); return s; } static const char*luaL_optlstring(lua_State*L,int narg, const char*def,size_t*len){ if(lua_isnoneornil(L,narg)){ if(len) *len=(def?strlen(def):0); return def; } else return luaL_checklstring(L,narg,len); } static lua_Number luaL_checknumber(lua_State*L,int narg){ lua_Number d=lua_tonumber(L,narg); if(d==0&&!lua_isnumber(L,narg)) tag_error(L,narg,3); return d; } static lua_Integer luaL_checkinteger(lua_State*L,int narg){ lua_Integer d=lua_tointeger(L,narg); if(d==0&&!lua_isnumber(L,narg)) tag_error(L,narg,3); return d; } static lua_Integer luaL_optinteger(lua_State*L,int narg, lua_Integer def){ return luaL_opt(L,luaL_checkinteger,narg,def); } static int luaL_getmetafield(lua_State*L,int obj,const char*event){ if(!lua_getmetatable(L,obj)) return 0; lua_pushstring(L,event); lua_rawget(L,-2); if(lua_isnil(L,-1)){ lua_pop(L,2); return 0; } else{ lua_remove(L,-2); return 1; } } static void luaL_register(lua_State*L,const char*libname, const luaL_Reg*l){ luaI_openlib(L,libname,l,0); } static int libsize(const luaL_Reg*l){ int size=0; for(;l->name;l++)size++; return size; } static void luaI_openlib(lua_State*L,const char*libname, const luaL_Reg*l,int nup){ if(libname){ int size=libsize(l); luaL_findtable(L,(-10000),"_LOADED",1); lua_getfield(L,-1,libname); if(!lua_istable(L,-1)){ lua_pop(L,1); if(luaL_findtable(L,(-10002),libname,size)!=NULL) luaL_error(L,"name conflict for module "LUA_QL("%s"),libname); lua_pushvalue(L,-1); lua_setfield(L,-3,libname); } lua_remove(L,-2); lua_insert(L,-(nup+1)); } for(;l->name;l++){ int i; for(i=0;i<nup;i++) lua_pushvalue(L,-nup); lua_pushcclosure(L,l->func,nup); lua_setfield(L,-(nup+2),l->name); } lua_pop(L,nup); } static const char*luaL_findtable(lua_State*L,int idx, const char*fname,int szhint){ const char*e; lua_pushvalue(L,idx); do{ e=strchr(fname,'.'); if(e==NULL)e=fname+strlen(fname); lua_pushlstring(L,fname,e-fname); lua_rawget(L,-2); if(lua_isnil(L,-1)){ lua_pop(L,1); lua_createtable(L,0,(*e=='.'?1:szhint)); lua_pushlstring(L,fname,e-fname); lua_pushvalue(L,-2); lua_settable(L,-4); } else if(!lua_istable(L,-1)){ lua_pop(L,2); return fname; } lua_remove(L,-2); fname=e+1; }while(*e=='.'); return NULL; } #define bufflen(B)((B)->p-(B)->buffer) #define bufffree(B)((size_t)(BUFSIZ-bufflen(B))) static int emptybuffer(luaL_Buffer*B){ size_t l=bufflen(B); if(l==0)return 0; else{ lua_pushlstring(B->L,B->buffer,l); B->p=B->buffer; B->lvl++; return 1; } } static void adjuststack(luaL_Buffer*B){ if(B->lvl>1){ lua_State*L=B->L; int toget=1; size_t toplen=lua_strlen(L,-1); do{ size_t l=lua_strlen(L,-(toget+1)); if(B->lvl-toget+1>=(20/2)||toplen>l){ toplen+=l; toget++; } else break; }while(toget<B->lvl); lua_concat(L,toget); B->lvl=B->lvl-toget+1; } } static char*luaL_prepbuffer(luaL_Buffer*B){ if(emptybuffer(B)) adjuststack(B); return B->buffer; } static void luaL_addlstring(luaL_Buffer*B,const char*s,size_t l){ while(l--) luaL_addchar(B,*s++); } static void luaL_pushresult(luaL_Buffer*B){ emptybuffer(B); lua_concat(B->L,B->lvl); B->lvl=1; } static void luaL_addvalue(luaL_Buffer*B){ lua_State*L=B->L; size_t vl; const char*s=lua_tolstring(L,-1,&vl); if(vl<=bufffree(B)){ memcpy(B->p,s,vl); B->p+=vl; lua_pop(L,1); } else{ if(emptybuffer(B)) lua_insert(L,-2); B->lvl++; adjuststack(B); } } static void luaL_buffinit(lua_State*L,luaL_Buffer*B){ B->L=L; B->p=B->buffer; B->lvl=0; } typedef struct LoadF{ int extraline; FILE*f; char buff[BUFSIZ]; }LoadF; static const char*getF(lua_State*L,void*ud,size_t*size){ LoadF*lf=(LoadF*)ud; (void)L; if(lf->extraline){ lf->extraline=0; *size=1; return"\n"; } if(feof(lf->f))return NULL; *size=fread(lf->buff,1,sizeof(lf->buff),lf->f); return(*size>0)?lf->buff:NULL; } static int errfile(lua_State*L,const char*what,int fnameindex){ const char*serr=strerror(errno); const char*filename=lua_tostring(L,fnameindex)+1; lua_pushfstring(L,"cannot %s %s: %s",what,filename,serr); lua_remove(L,fnameindex); return(5+1); } static int luaL_loadfile(lua_State*L,const char*filename){ LoadF lf; int status,readstatus; int c; int fnameindex=lua_gettop(L)+1; lf.extraline=0; if(filename==NULL){ lua_pushliteral(L,"=stdin"); lf.f=stdin; } else{ lua_pushfstring(L,"@%s",filename); lf.f=fopen(filename,"r"); if(lf.f==NULL)return errfile(L,"open",fnameindex); } c=getc(lf.f); if(c=='#'){ lf.extraline=1; while((c=getc(lf.f))!=EOF&&c!='\n'); if(c=='\n')c=getc(lf.f); } if(c=="\033Lua"[0]&&filename){ lf.f=freopen(filename,"rb",lf.f); if(lf.f==NULL)return errfile(L,"reopen",fnameindex); while((c=getc(lf.f))!=EOF&&c!="\033Lua"[0]); lf.extraline=0; } ungetc(c,lf.f); status=lua_load(L,getF,&lf,lua_tostring(L,-1)); readstatus=ferror(lf.f); if(filename)fclose(lf.f); if(readstatus){ lua_settop(L,fnameindex); return errfile(L,"read",fnameindex); } lua_remove(L,fnameindex); return status; } typedef struct LoadS{ const char*s; size_t size; }LoadS; static const char*getS(lua_State*L,void*ud,size_t*size){ LoadS*ls=(LoadS*)ud; (void)L; if(ls->size==0)return NULL; *size=ls->size; ls->size=0; return ls->s; } static int luaL_loadbuffer(lua_State*L,const char*buff,size_t size, const char*name){ LoadS ls; ls.s=buff; ls.size=size; return lua_load(L,getS,&ls,name); } static void*l_alloc(void*ud,void*ptr,size_t osize,size_t nsize){ (void)ud; (void)osize; if(nsize==0){ free(ptr); return NULL; } else return realloc(ptr,nsize); } static int panic(lua_State*L){ (void)L; fprintf(stderr,"PANIC: unprotected error in call to Lua API (%s)\n", lua_tostring(L,-1)); return 0; } static lua_State*luaL_newstate(void){ lua_State*L=lua_newstate(l_alloc,NULL); if(L)lua_atpanic(L,&panic); return L; } static int luaB_tonumber(lua_State*L){ int base=luaL_optint(L,2,10); if(base==10){ luaL_checkany(L,1); if(lua_isnumber(L,1)){ lua_pushnumber(L,lua_tonumber(L,1)); return 1; } } else{ const char*s1=luaL_checkstring(L,1); char*s2; unsigned long n; luaL_argcheck(L,2<=base&&base<=36,2,"base out of range"); n=strtoul(s1,&s2,base); if(s1!=s2){ while(isspace((unsigned char)(*s2)))s2++; if(*s2=='\0'){ lua_pushnumber(L,(lua_Number)n); return 1; } } } lua_pushnil(L); return 1; } static int luaB_error(lua_State*L){ int level=luaL_optint(L,2,1); lua_settop(L,1); if(lua_isstring(L,1)&&level>0){ luaL_where(L,level); lua_pushvalue(L,1); lua_concat(L,2); } return lua_error(L); } static int luaB_setmetatable(lua_State*L){ int t=lua_type(L,2); luaL_checktype(L,1,5); luaL_argcheck(L,t==0||t==5,2, "nil or table expected"); if(luaL_getmetafield(L,1,"__metatable")) luaL_error(L,"cannot change a protected metatable"); lua_settop(L,2); lua_setmetatable(L,1); return 1; } static void getfunc(lua_State*L,int opt){ if(lua_isfunction(L,1))lua_pushvalue(L,1); else{ lua_Debug ar; int level=opt?luaL_optint(L,1,1):luaL_checkint(L,1); luaL_argcheck(L,level>=0,1,"level must be non-negative"); if(lua_getstack(L,level,&ar)==0) luaL_argerror(L,1,"invalid level"); lua_getinfo(L,"f",&ar); if(lua_isnil(L,-1)) luaL_error(L,"no function environment for tail call at level %d", level); } } static int luaB_setfenv(lua_State*L){ luaL_checktype(L,2,5); getfunc(L,0); lua_pushvalue(L,2); if(lua_isnumber(L,1)&&lua_tonumber(L,1)==0){ lua_pushthread(L); lua_insert(L,-2); lua_setfenv(L,-2); return 0; } else if(lua_iscfunction(L,-2)||lua_setfenv(L,-2)==0) luaL_error(L, LUA_QL("setfenv")" cannot change environment of given object"); return 1; } static int luaB_rawget(lua_State*L){ luaL_checktype(L,1,5); luaL_checkany(L,2); lua_settop(L,2); lua_rawget(L,1); return 1; } static int luaB_type(lua_State*L){ luaL_checkany(L,1); lua_pushstring(L,luaL_typename(L,1)); return 1; } static int luaB_next(lua_State*L){ luaL_checktype(L,1,5); lua_settop(L,2); if(lua_next(L,1)) return 2; else{ lua_pushnil(L); return 1; } } static int luaB_pairs(lua_State*L){ luaL_checktype(L,1,5); lua_pushvalue(L,lua_upvalueindex(1)); lua_pushvalue(L,1); lua_pushnil(L); return 3; } static int ipairsaux(lua_State*L){ int i=luaL_checkint(L,2); luaL_checktype(L,1,5); i++; lua_pushinteger(L,i); lua_rawgeti(L,1,i); return(lua_isnil(L,-1))?0:2; } static int luaB_ipairs(lua_State*L){ luaL_checktype(L,1,5); lua_pushvalue(L,lua_upvalueindex(1)); lua_pushvalue(L,1); lua_pushinteger(L,0); return 3; } static int load_aux(lua_State*L,int status){ if(status==0) return 1; else{ lua_pushnil(L); lua_insert(L,-2); return 2; } } static int luaB_loadstring(lua_State*L){ size_t l; const char*s=luaL_checklstring(L,1,&l); const char*chunkname=luaL_optstring(L,2,s); return load_aux(L,luaL_loadbuffer(L,s,l,chunkname)); } static int luaB_loadfile(lua_State*L){ const char*fname=luaL_optstring(L,1,NULL); return load_aux(L,luaL_loadfile(L,fname)); } static int luaB_assert(lua_State*L){ luaL_checkany(L,1); if(!lua_toboolean(L,1)) return luaL_error(L,"%s",luaL_optstring(L,2,"assertion failed!")); return lua_gettop(L); } static int luaB_unpack(lua_State*L){ int i,e,n; luaL_checktype(L,1,5); i=luaL_optint(L,2,1); e=luaL_opt(L,luaL_checkint,3,luaL_getn(L,1)); if(i>e)return 0; n=e-i+1; if(n<=0||!lua_checkstack(L,n)) return luaL_error(L,"too many results to unpack"); lua_rawgeti(L,1,i); while(i++<e) lua_rawgeti(L,1,i); return n; } static int luaB_pcall(lua_State*L){ int status; luaL_checkany(L,1); status=lua_pcall(L,lua_gettop(L)-1,(-1),0); lua_pushboolean(L,(status==0)); lua_insert(L,1); return lua_gettop(L); } static int luaB_newproxy(lua_State*L){ lua_settop(L,1); lua_newuserdata(L,0); if(lua_toboolean(L,1)==0) return 1; else if(lua_isboolean(L,1)){ lua_newtable(L); lua_pushvalue(L,-1); lua_pushboolean(L,1); lua_rawset(L,lua_upvalueindex(1)); } else{ int validproxy=0; if(lua_getmetatable(L,1)){ lua_rawget(L,lua_upvalueindex(1)); validproxy=lua_toboolean(L,-1); lua_pop(L,1); } luaL_argcheck(L,validproxy,1,"boolean or proxy expected"); lua_getmetatable(L,1); } lua_setmetatable(L,2); return 1; } static const luaL_Reg base_funcs[]={ {"assert",luaB_assert}, {"error",luaB_error}, {"loadfile",luaB_loadfile}, {"loadstring",luaB_loadstring}, {"next",luaB_next}, {"pcall",luaB_pcall}, {"rawget",luaB_rawget}, {"setfenv",luaB_setfenv}, {"setmetatable",luaB_setmetatable}, {"tonumber",luaB_tonumber}, {"type",luaB_type}, {"unpack",luaB_unpack}, {NULL,NULL} }; static void auxopen(lua_State*L,const char*name, lua_CFunction f,lua_CFunction u){ lua_pushcfunction(L,u); lua_pushcclosure(L,f,1); lua_setfield(L,-2,name); } static void base_open(lua_State*L){ lua_pushvalue(L,(-10002)); lua_setglobal(L,"_G"); luaL_register(L,"_G",base_funcs); lua_pushliteral(L,"Lua 5.1"); lua_setglobal(L,"_VERSION"); auxopen(L,"ipairs",luaB_ipairs,ipairsaux); auxopen(L,"pairs",luaB_pairs,luaB_next); lua_createtable(L,0,1); lua_pushvalue(L,-1); lua_setmetatable(L,-2); lua_pushliteral(L,"kv"); lua_setfield(L,-2,"__mode"); lua_pushcclosure(L,luaB_newproxy,1); lua_setglobal(L,"newproxy"); } static int luaopen_base(lua_State*L){ base_open(L); return 1; } #define aux_getn(L,n)(luaL_checktype(L,n,5),luaL_getn(L,n)) static int tinsert(lua_State*L){ int e=aux_getn(L,1)+1; int pos; switch(lua_gettop(L)){ case 2:{ pos=e; break; } case 3:{ int i; pos=luaL_checkint(L,2); if(pos>e)e=pos; for(i=e;i>pos;i--){ lua_rawgeti(L,1,i-1); lua_rawseti(L,1,i); } break; } default:{ return luaL_error(L,"wrong number of arguments to "LUA_QL("insert")); } } luaL_setn(L,1,e); lua_rawseti(L,1,pos); return 0; } static int tremove(lua_State*L){ int e=aux_getn(L,1); int pos=luaL_optint(L,2,e); if(!(1<=pos&&pos<=e)) return 0; luaL_setn(L,1,e-1); lua_rawgeti(L,1,pos); for(;pos<e;pos++){ lua_rawgeti(L,1,pos+1); lua_rawseti(L,1,pos); } lua_pushnil(L); lua_rawseti(L,1,e); return 1; } static void addfield(lua_State*L,luaL_Buffer*b,int i){ lua_rawgeti(L,1,i); if(!lua_isstring(L,-1)) luaL_error(L,"invalid value (%s) at index %d in table for " LUA_QL("concat"),luaL_typename(L,-1),i); luaL_addvalue(b); } static int tconcat(lua_State*L){ luaL_Buffer b; size_t lsep; int i,last; const char*sep=luaL_optlstring(L,2,"",&lsep); luaL_checktype(L,1,5); i=luaL_optint(L,3,1); last=luaL_opt(L,luaL_checkint,4,luaL_getn(L,1)); luaL_buffinit(L,&b); for(;i<last;i++){ addfield(L,&b,i); luaL_addlstring(&b,sep,lsep); } if(i==last) addfield(L,&b,i); luaL_pushresult(&b); return 1; } static void set2(lua_State*L,int i,int j){ lua_rawseti(L,1,i); lua_rawseti(L,1,j); } static int sort_comp(lua_State*L,int a,int b){ if(!lua_isnil(L,2)){ int res; lua_pushvalue(L,2); lua_pushvalue(L,a-1); lua_pushvalue(L,b-2); lua_call(L,2,1); res=lua_toboolean(L,-1); lua_pop(L,1); return res; } else return lua_lessthan(L,a,b); } static void auxsort(lua_State*L,int l,int u){ while(l<u){ int i,j; lua_rawgeti(L,1,l); lua_rawgeti(L,1,u); if(sort_comp(L,-1,-2)) set2(L,l,u); else lua_pop(L,2); if(u-l==1)break; i=(l+u)/2; lua_rawgeti(L,1,i); lua_rawgeti(L,1,l); if(sort_comp(L,-2,-1)) set2(L,i,l); else{ lua_pop(L,1); lua_rawgeti(L,1,u); if(sort_comp(L,-1,-2)) set2(L,i,u); else lua_pop(L,2); } if(u-l==2)break; lua_rawgeti(L,1,i); lua_pushvalue(L,-1); lua_rawgeti(L,1,u-1); set2(L,i,u-1); i=l;j=u-1; for(;;){ while(lua_rawgeti(L,1,++i),sort_comp(L,-1,-2)){ if(i>u)luaL_error(L,"invalid order function for sorting"); lua_pop(L,1); } while(lua_rawgeti(L,1,--j),sort_comp(L,-3,-1)){ if(j<l)luaL_error(L,"invalid order function for sorting"); lua_pop(L,1); } if(j<i){ lua_pop(L,3); break; } set2(L,i,j); } lua_rawgeti(L,1,u-1); lua_rawgeti(L,1,i); set2(L,u-1,i); if(i-l<u-i){ j=l;i=i-1;l=i+2; } else{ j=i+1;i=u;u=j-2; } auxsort(L,j,i); } } static int sort(lua_State*L){ int n=aux_getn(L,1); luaL_checkstack(L,40,""); if(!lua_isnoneornil(L,2)) luaL_checktype(L,2,6); lua_settop(L,2); auxsort(L,1,n); return 0; } static const luaL_Reg tab_funcs[]={ {"concat",tconcat}, {"insert",tinsert}, {"remove",tremove}, {"sort",sort}, {NULL,NULL} }; static int luaopen_table(lua_State*L){ luaL_register(L,"table",tab_funcs); return 1; } static const char*const fnames[]={"input","output"}; static int pushresult(lua_State*L,int i,const char*filename){ int en=errno; if(i){ lua_pushboolean(L,1); return 1; } else{ lua_pushnil(L); if(filename) lua_pushfstring(L,"%s: %s",filename,strerror(en)); else lua_pushfstring(L,"%s",strerror(en)); lua_pushinteger(L,en); return 3; } } static void fileerror(lua_State*L,int arg,const char*filename){ lua_pushfstring(L,"%s: %s",filename,strerror(errno)); luaL_argerror(L,arg,lua_tostring(L,-1)); } #define tofilep(L)((FILE**)luaL_checkudata(L,1,"FILE*")) static int io_type(lua_State*L){ void*ud; luaL_checkany(L,1); ud=lua_touserdata(L,1); lua_getfield(L,(-10000),"FILE*"); if(ud==NULL||!lua_getmetatable(L,1)||!lua_rawequal(L,-2,-1)) lua_pushnil(L); else if(*((FILE**)ud)==NULL) lua_pushliteral(L,"closed file"); else lua_pushliteral(L,"file"); return 1; } static FILE*tofile(lua_State*L){ FILE**f=tofilep(L); if(*f==NULL) luaL_error(L,"attempt to use a closed file"); return*f; } static FILE**newfile(lua_State*L){ FILE**pf=(FILE**)lua_newuserdata(L,sizeof(FILE*)); *pf=NULL; luaL_getmetatable(L,"FILE*"); lua_setmetatable(L,-2); return pf; } static int io_noclose(lua_State*L){ lua_pushnil(L); lua_pushliteral(L,"cannot close standard file"); return 2; } static int io_pclose(lua_State*L){ FILE**p=tofilep(L); int ok=lua_pclose(L,*p); *p=NULL; return pushresult(L,ok,NULL); } static int io_fclose(lua_State*L){ FILE**p=tofilep(L); int ok=(fclose(*p)==0); *p=NULL; return pushresult(L,ok,NULL); } static int aux_close(lua_State*L){ lua_getfenv(L,1); lua_getfield(L,-1,"__close"); return(lua_tocfunction(L,-1))(L); } static int io_close(lua_State*L){ if(lua_isnone(L,1)) lua_rawgeti(L,(-10001),2); tofile(L); return aux_close(L); } static int io_gc(lua_State*L){ FILE*f=*tofilep(L); if(f!=NULL) aux_close(L); return 0; } static int io_open(lua_State*L){ const char*filename=luaL_checkstring(L,1); const char*mode=luaL_optstring(L,2,"r"); FILE**pf=newfile(L); *pf=fopen(filename,mode); return(*pf==NULL)?pushresult(L,0,filename):1; } static FILE*getiofile(lua_State*L,int findex){ FILE*f; lua_rawgeti(L,(-10001),findex); f=*(FILE**)lua_touserdata(L,-1); if(f==NULL) luaL_error(L,"standard %s file is closed",fnames[findex-1]); return f; } static int g_iofile(lua_State*L,int f,const char*mode){ if(!lua_isnoneornil(L,1)){ const char*filename=lua_tostring(L,1); if(filename){ FILE**pf=newfile(L); *pf=fopen(filename,mode); if(*pf==NULL) fileerror(L,1,filename); } else{ tofile(L); lua_pushvalue(L,1); } lua_rawseti(L,(-10001),f); } lua_rawgeti(L,(-10001),f); return 1; } static int io_input(lua_State*L){ return g_iofile(L,1,"r"); } static int io_output(lua_State*L){ return g_iofile(L,2,"w"); } static int io_readline(lua_State*L); static void aux_lines(lua_State*L,int idx,int toclose){ lua_pushvalue(L,idx); lua_pushboolean(L,toclose); lua_pushcclosure(L,io_readline,2); } static int f_lines(lua_State*L){ tofile(L); aux_lines(L,1,0); return 1; } static int io_lines(lua_State*L){ if(lua_isnoneornil(L,1)){ lua_rawgeti(L,(-10001),1); return f_lines(L); } else{ const char*filename=luaL_checkstring(L,1); FILE**pf=newfile(L); *pf=fopen(filename,"r"); if(*pf==NULL) fileerror(L,1,filename); aux_lines(L,lua_gettop(L),1); return 1; } } static int read_number(lua_State*L,FILE*f){ lua_Number d; if(fscanf(f,"%lf",&d)==1){ lua_pushnumber(L,d); return 1; } else{ lua_pushnil(L); return 0; } } static int test_eof(lua_State*L,FILE*f){ int c=getc(f); ungetc(c,f); lua_pushlstring(L,NULL,0); return(c!=EOF); } static int read_line(lua_State*L,FILE*f){ luaL_Buffer b; luaL_buffinit(L,&b); for(;;){ size_t l; char*p=luaL_prepbuffer(&b); if(fgets(p,BUFSIZ,f)==NULL){ luaL_pushresult(&b); return(lua_objlen(L,-1)>0); } l=strlen(p); if(l==0||p[l-1]!='\n') luaL_addsize(&b,l); else{ luaL_addsize(&b,l-1); luaL_pushresult(&b); return 1; } } } static int read_chars(lua_State*L,FILE*f,size_t n){ size_t rlen; size_t nr; luaL_Buffer b; luaL_buffinit(L,&b); rlen=BUFSIZ; do{ char*p=luaL_prepbuffer(&b); if(rlen>n)rlen=n; nr=fread(p,sizeof(char),rlen,f); luaL_addsize(&b,nr); n-=nr; }while(n>0&&nr==rlen); luaL_pushresult(&b); return(n==0||lua_objlen(L,-1)>0); } static int g_read(lua_State*L,FILE*f,int first){ int nargs=lua_gettop(L)-1; int success; int n; clearerr(f); if(nargs==0){ success=read_line(L,f); n=first+1; } else{ luaL_checkstack(L,nargs+20,"too many arguments"); success=1; for(n=first;nargs--&&success;n++){ if(lua_type(L,n)==3){ size_t l=(size_t)lua_tointeger(L,n); success=(l==0)?test_eof(L,f):read_chars(L,f,l); } else{ const char*p=lua_tostring(L,n); luaL_argcheck(L,p&&p[0]=='*',n,"invalid option"); switch(p[1]){ case'n': success=read_number(L,f); break; case'l': success=read_line(L,f); break; case'a': read_chars(L,f,~((size_t)0)); success=1; break; default: return luaL_argerror(L,n,"invalid format"); } } } } if(ferror(f)) return pushresult(L,0,NULL); if(!success){ lua_pop(L,1); lua_pushnil(L); } return n-first; } static int io_read(lua_State*L){ return g_read(L,getiofile(L,1),1); } static int f_read(lua_State*L){ return g_read(L,tofile(L),2); } static int io_readline(lua_State*L){ FILE*f=*(FILE**)lua_touserdata(L,lua_upvalueindex(1)); int sucess; if(f==NULL) luaL_error(L,"file is already closed"); sucess=read_line(L,f); if(ferror(f)) return luaL_error(L,"%s",strerror(errno)); if(sucess)return 1; else{ if(lua_toboolean(L,lua_upvalueindex(2))){ lua_settop(L,0); lua_pushvalue(L,lua_upvalueindex(1)); aux_close(L); } return 0; } } static int g_write(lua_State*L,FILE*f,int arg){ int nargs=lua_gettop(L)-1; int status=1; for(;nargs--;arg++){ if(lua_type(L,arg)==3){ status=status&& fprintf(f,"%.14g",lua_tonumber(L,arg))>0; } else{ size_t l; const char*s=luaL_checklstring(L,arg,&l); status=status&&(fwrite(s,sizeof(char),l,f)==l); } } return pushresult(L,status,NULL); } static int io_write(lua_State*L){ return g_write(L,getiofile(L,2),1); } static int f_write(lua_State*L){ return g_write(L,tofile(L),2); } static int io_flush(lua_State*L){ return pushresult(L,fflush(getiofile(L,2))==0,NULL); } static int f_flush(lua_State*L){ return pushresult(L,fflush(tofile(L))==0,NULL); } static const luaL_Reg iolib[]={ {"close",io_close}, {"flush",io_flush}, {"input",io_input}, {"lines",io_lines}, {"open",io_open}, {"output",io_output}, {"read",io_read}, {"type",io_type}, {"write",io_write}, {NULL,NULL} }; static const luaL_Reg flib[]={ {"close",io_close}, {"flush",f_flush}, {"lines",f_lines}, {"read",f_read}, {"write",f_write}, {"__gc",io_gc}, {NULL,NULL} }; static void createmeta(lua_State*L){ luaL_newmetatable(L,"FILE*"); lua_pushvalue(L,-1); lua_setfield(L,-2,"__index"); luaL_register(L,NULL,flib); } static void createstdfile(lua_State*L,FILE*f,int k,const char*fname){ *newfile(L)=f; if(k>0){ lua_pushvalue(L,-1); lua_rawseti(L,(-10001),k); } lua_pushvalue(L,-2); lua_setfenv(L,-2); lua_setfield(L,-3,fname); } static void newfenv(lua_State*L,lua_CFunction cls){ lua_createtable(L,0,1); lua_pushcfunction(L,cls); lua_setfield(L,-2,"__close"); } static int luaopen_io(lua_State*L){ createmeta(L); newfenv(L,io_fclose); lua_replace(L,(-10001)); luaL_register(L,"io",iolib); newfenv(L,io_noclose); createstdfile(L,stdin,1,"stdin"); createstdfile(L,stdout,2,"stdout"); createstdfile(L,stderr,0,"stderr"); lua_pop(L,1); lua_getfield(L,-1,"popen"); newfenv(L,io_pclose); lua_setfenv(L,-2); lua_pop(L,1); return 1; } static int os_pushresult(lua_State*L,int i,const char*filename){ int en=errno; if(i){ lua_pushboolean(L,1); return 1; } else{ lua_pushnil(L); lua_pushfstring(L,"%s: %s",filename,strerror(en)); lua_pushinteger(L,en); return 3; } } static int os_remove(lua_State*L){ const char*filename=luaL_checkstring(L,1); return os_pushresult(L,remove(filename)==0,filename); } static int os_exit(lua_State*L){ exit(luaL_optint(L,1,EXIT_SUCCESS)); } static const luaL_Reg syslib[]={ {"exit",os_exit}, {"remove",os_remove}, {NULL,NULL} }; static int luaopen_os(lua_State*L){ luaL_register(L,"os",syslib); return 1; } #define uchar(c)((unsigned char)(c)) static ptrdiff_t posrelat(ptrdiff_t pos,size_t len){ if(pos<0)pos+=(ptrdiff_t)len+1; return(pos>=0)?pos:0; } static int str_sub(lua_State*L){ size_t l; const char*s=luaL_checklstring(L,1,&l); ptrdiff_t start=posrelat(luaL_checkinteger(L,2),l); ptrdiff_t end=posrelat(luaL_optinteger(L,3,-1),l); if(start<1)start=1; if(end>(ptrdiff_t)l)end=(ptrdiff_t)l; if(start<=end) lua_pushlstring(L,s+start-1,end-start+1); else lua_pushliteral(L,""); return 1; } static int str_lower(lua_State*L){ size_t l; size_t i; luaL_Buffer b; const char*s=luaL_checklstring(L,1,&l); luaL_buffinit(L,&b); for(i=0;i<l;i++) luaL_addchar(&b,tolower(uchar(s[i]))); luaL_pushresult(&b); return 1; } static int str_upper(lua_State*L){ size_t l; size_t i; luaL_Buffer b; const char*s=luaL_checklstring(L,1,&l); luaL_buffinit(L,&b); for(i=0;i<l;i++) luaL_addchar(&b,toupper(uchar(s[i]))); luaL_pushresult(&b); return 1; } static int str_rep(lua_State*L){ size_t l; luaL_Buffer b; const char*s=luaL_checklstring(L,1,&l); int n=luaL_checkint(L,2); luaL_buffinit(L,&b); while(n-->0) luaL_addlstring(&b,s,l); luaL_pushresult(&b); return 1; } static int str_byte(lua_State*L){ size_t l; const char*s=luaL_checklstring(L,1,&l); ptrdiff_t posi=posrelat(luaL_optinteger(L,2,1),l); ptrdiff_t pose=posrelat(luaL_optinteger(L,3,posi),l); int n,i; if(posi<=0)posi=1; if((size_t)pose>l)pose=l; if(posi>pose)return 0; n=(int)(pose-posi+1); if(posi+n<=pose) luaL_error(L,"string slice too long"); luaL_checkstack(L,n,"string slice too long"); for(i=0;i<n;i++) lua_pushinteger(L,uchar(s[posi+i-1])); return n; } static int str_char(lua_State*L){ int n=lua_gettop(L); int i; luaL_Buffer b; luaL_buffinit(L,&b); for(i=1;i<=n;i++){ int c=luaL_checkint(L,i); luaL_argcheck(L,uchar(c)==c,i,"invalid value"); luaL_addchar(&b,uchar(c)); } luaL_pushresult(&b); return 1; } typedef struct MatchState{ const char*src_init; const char*src_end; lua_State*L; int level; struct{ const char*init; ptrdiff_t len; }capture[32]; }MatchState; static int check_capture(MatchState*ms,int l){ l-='1'; if(l<0||l>=ms->level||ms->capture[l].len==(-1)) return luaL_error(ms->L,"invalid capture index"); return l; } static int capture_to_close(MatchState*ms){ int level=ms->level; for(level--;level>=0;level--) if(ms->capture[level].len==(-1))return level; return luaL_error(ms->L,"invalid pattern capture"); } static const char*classend(MatchState*ms,const char*p){ switch(*p++){ case'%':{ if(*p=='\0') luaL_error(ms->L,"malformed pattern (ends with "LUA_QL("%%")")"); return p+1; } case'[':{ if(*p=='^')p++; do{ if(*p=='\0') luaL_error(ms->L,"malformed pattern (missing "LUA_QL("]")")"); if(*(p++)=='%'&&*p!='\0') p++; }while(*p!=']'); return p+1; } default:{ return p; } } } static int match_class(int c,int cl){ int res; switch(tolower(cl)){ case'a':res=isalpha(c);break; case'c':res=iscntrl(c);break; case'd':res=isdigit(c);break; case'l':res=islower(c);break; case'p':res=ispunct(c);break; case's':res=isspace(c);break; case'u':res=isupper(c);break; case'w':res=isalnum(c);break; case'x':res=isxdigit(c);break; case'z':res=(c==0);break; default:return(cl==c); } return(islower(cl)?res:!res); } static int matchbracketclass(int c,const char*p,const char*ec){ int sig=1; if(*(p+1)=='^'){ sig=0; p++; } while(++p<ec){ if(*p=='%'){ p++; if(match_class(c,uchar(*p))) return sig; } else if((*(p+1)=='-')&&(p+2<ec)){ p+=2; if(uchar(*(p-2))<=c&&c<=uchar(*p)) return sig; } else if(uchar(*p)==c)return sig; } return!sig; } static int singlematch(int c,const char*p,const char*ep){ switch(*p){ case'.':return 1; case'%':return match_class(c,uchar(*(p+1))); case'[':return matchbracketclass(c,p,ep-1); default:return(uchar(*p)==c); } } static const char*match(MatchState*ms,const char*s,const char*p); static const char*matchbalance(MatchState*ms,const char*s, const char*p){ if(*p==0||*(p+1)==0) luaL_error(ms->L,"unbalanced pattern"); if(*s!=*p)return NULL; else{ int b=*p; int e=*(p+1); int cont=1; while(++s<ms->src_end){ if(*s==e){ if(--cont==0)return s+1; } else if(*s==b)cont++; } } return NULL; } static const char*max_expand(MatchState*ms,const char*s, const char*p,const char*ep){ ptrdiff_t i=0; while((s+i)<ms->src_end&&singlematch(uchar(*(s+i)),p,ep)) i++; while(i>=0){ const char*res=match(ms,(s+i),ep+1); if(res)return res; i--; } return NULL; } static const char*min_expand(MatchState*ms,const char*s, const char*p,const char*ep){ for(;;){ const char*res=match(ms,s,ep+1); if(res!=NULL) return res; else if(s<ms->src_end&&singlematch(uchar(*s),p,ep)) s++; else return NULL; } } static const char*start_capture(MatchState*ms,const char*s, const char*p,int what){ const char*res; int level=ms->level; if(level>=32)luaL_error(ms->L,"too many captures"); ms->capture[level].init=s; ms->capture[level].len=what; ms->level=level+1; if((res=match(ms,s,p))==NULL) ms->level--; return res; } static const char*end_capture(MatchState*ms,const char*s, const char*p){ int l=capture_to_close(ms); const char*res; ms->capture[l].len=s-ms->capture[l].init; if((res=match(ms,s,p))==NULL) ms->capture[l].len=(-1); return res; } static const char*match_capture(MatchState*ms,const char*s,int l){ size_t len; l=check_capture(ms,l); len=ms->capture[l].len; if((size_t)(ms->src_end-s)>=len&& memcmp(ms->capture[l].init,s,len)==0) return s+len; else return NULL; } static const char*match(MatchState*ms,const char*s,const char*p){ init: switch(*p){ case'(':{ if(*(p+1)==')') return start_capture(ms,s,p+2,(-2)); else return start_capture(ms,s,p+1,(-1)); } case')':{ return end_capture(ms,s,p+1); } case'%':{ switch(*(p+1)){ case'b':{ s=matchbalance(ms,s,p+2); if(s==NULL)return NULL; p+=4;goto init; } case'f':{ const char*ep;char previous; p+=2; if(*p!='[') luaL_error(ms->L,"missing "LUA_QL("[")" after " LUA_QL("%%f")" in pattern"); ep=classend(ms,p); previous=(s==ms->src_init)?'\0':*(s-1); if(matchbracketclass(uchar(previous),p,ep-1)|| !matchbracketclass(uchar(*s),p,ep-1))return NULL; p=ep;goto init; } default:{ if(isdigit(uchar(*(p+1)))){ s=match_capture(ms,s,uchar(*(p+1))); if(s==NULL)return NULL; p+=2;goto init; } goto dflt; } } } case'\0':{ return s; } case'$':{ if(*(p+1)=='\0') return(s==ms->src_end)?s:NULL; else goto dflt; } default:dflt:{ const char*ep=classend(ms,p); int m=s<ms->src_end&&singlematch(uchar(*s),p,ep); switch(*ep){ case'?':{ const char*res; if(m&&((res=match(ms,s+1,ep+1))!=NULL)) return res; p=ep+1;goto init; } case'*':{ return max_expand(ms,s,p,ep); } case'+':{ return(m?max_expand(ms,s+1,p,ep):NULL); } case'-':{ return min_expand(ms,s,p,ep); } default:{ if(!m)return NULL; s++;p=ep;goto init; } } } } } static const char*lmemfind(const char*s1,size_t l1, const char*s2,size_t l2){ if(l2==0)return s1; else if(l2>l1)return NULL; else{ const char*init; l2--; l1=l1-l2; while(l1>0&&(init=(const char*)memchr(s1,*s2,l1))!=NULL){ init++; if(memcmp(init,s2+1,l2)==0) return init-1; else{ l1-=init-s1; s1=init; } } return NULL; } } static void push_onecapture(MatchState*ms,int i,const char*s, const char*e){ if(i>=ms->level){ if(i==0) lua_pushlstring(ms->L,s,e-s); else luaL_error(ms->L,"invalid capture index"); } else{ ptrdiff_t l=ms->capture[i].len; if(l==(-1))luaL_error(ms->L,"unfinished capture"); if(l==(-2)) lua_pushinteger(ms->L,ms->capture[i].init-ms->src_init+1); else lua_pushlstring(ms->L,ms->capture[i].init,l); } } static int push_captures(MatchState*ms,const char*s,const char*e){ int i; int nlevels=(ms->level==0&&s)?1:ms->level; luaL_checkstack(ms->L,nlevels,"too many captures"); for(i=0;i<nlevels;i++) push_onecapture(ms,i,s,e); return nlevels; } static int str_find_aux(lua_State*L,int find){ size_t l1,l2; const char*s=luaL_checklstring(L,1,&l1); const char*p=luaL_checklstring(L,2,&l2); ptrdiff_t init=posrelat(luaL_optinteger(L,3,1),l1)-1; if(init<0)init=0; else if((size_t)(init)>l1)init=(ptrdiff_t)l1; if(find&&(lua_toboolean(L,4)|| strpbrk(p,"^$*+?.([%-")==NULL)){ const char*s2=lmemfind(s+init,l1-init,p,l2); if(s2){ lua_pushinteger(L,s2-s+1); lua_pushinteger(L,s2-s+l2); return 2; } } else{ MatchState ms; int anchor=(*p=='^')?(p++,1):0; const char*s1=s+init; ms.L=L; ms.src_init=s; ms.src_end=s+l1; do{ const char*res; ms.level=0; if((res=match(&ms,s1,p))!=NULL){ if(find){ lua_pushinteger(L,s1-s+1); lua_pushinteger(L,res-s); return push_captures(&ms,NULL,0)+2; } else return push_captures(&ms,s1,res); } }while(s1++<ms.src_end&&!anchor); } lua_pushnil(L); return 1; } static int str_find(lua_State*L){ return str_find_aux(L,1); } static int str_match(lua_State*L){ return str_find_aux(L,0); } static int gmatch_aux(lua_State*L){ MatchState ms; size_t ls; const char*s=lua_tolstring(L,lua_upvalueindex(1),&ls); const char*p=lua_tostring(L,lua_upvalueindex(2)); const char*src; ms.L=L; ms.src_init=s; ms.src_end=s+ls; for(src=s+(size_t)lua_tointeger(L,lua_upvalueindex(3)); src<=ms.src_end; src++){ const char*e; ms.level=0; if((e=match(&ms,src,p))!=NULL){ lua_Integer newstart=e-s; if(e==src)newstart++; lua_pushinteger(L,newstart); lua_replace(L,lua_upvalueindex(3)); return push_captures(&ms,src,e); } } return 0; } static int gmatch(lua_State*L){ luaL_checkstring(L,1); luaL_checkstring(L,2); lua_settop(L,2); lua_pushinteger(L,0); lua_pushcclosure(L,gmatch_aux,3); return 1; } static void add_s(MatchState*ms,luaL_Buffer*b,const char*s, const char*e){ size_t l,i; const char*news=lua_tolstring(ms->L,3,&l); for(i=0;i<l;i++){ if(news[i]!='%') luaL_addchar(b,news[i]); else{ i++; if(!isdigit(uchar(news[i]))) luaL_addchar(b,news[i]); else if(news[i]=='0') luaL_addlstring(b,s,e-s); else{ push_onecapture(ms,news[i]-'1',s,e); luaL_addvalue(b); } } } } static void add_value(MatchState*ms,luaL_Buffer*b,const char*s, const char*e){ lua_State*L=ms->L; switch(lua_type(L,3)){ case 3: case 4:{ add_s(ms,b,s,e); return; } case 6:{ int n; lua_pushvalue(L,3); n=push_captures(ms,s,e); lua_call(L,n,1); break; } case 5:{ push_onecapture(ms,0,s,e); lua_gettable(L,3); break; } } if(!lua_toboolean(L,-1)){ lua_pop(L,1); lua_pushlstring(L,s,e-s); } else if(!lua_isstring(L,-1)) luaL_error(L,"invalid replacement value (a %s)",luaL_typename(L,-1)); luaL_addvalue(b); } static int str_gsub(lua_State*L){ size_t srcl; const char*src=luaL_checklstring(L,1,&srcl); const char*p=luaL_checkstring(L,2); int tr=lua_type(L,3); int max_s=luaL_optint(L,4,srcl+1); int anchor=(*p=='^')?(p++,1):0; int n=0; MatchState ms; luaL_Buffer b; luaL_argcheck(L,tr==3||tr==4|| tr==6||tr==5,3, "string/function/table expected"); luaL_buffinit(L,&b); ms.L=L; ms.src_init=src; ms.src_end=src+srcl; while(n<max_s){ const char*e; ms.level=0; e=match(&ms,src,p); if(e){ n++; add_value(&ms,&b,src,e); } if(e&&e>src) src=e; else if(src<ms.src_end) luaL_addchar(&b,*src++); else break; if(anchor)break; } luaL_addlstring(&b,src,ms.src_end-src); luaL_pushresult(&b); lua_pushinteger(L,n); return 2; } static void addquoted(lua_State*L,luaL_Buffer*b,int arg){ size_t l; const char*s=luaL_checklstring(L,arg,&l); luaL_addchar(b,'"'); while(l--){ switch(*s){ case'"':case'\\':case'\n':{ luaL_addchar(b,'\\'); luaL_addchar(b,*s); break; } case'\r':{ luaL_addlstring(b,"\\r",2); break; } case'\0':{ luaL_addlstring(b,"\\000",4); break; } default:{ luaL_addchar(b,*s); break; } } s++; } luaL_addchar(b,'"'); } static const char*scanformat(lua_State*L,const char*strfrmt,char*form){ const char*p=strfrmt; while(*p!='\0'&&strchr("-+ #0",*p)!=NULL)p++; if((size_t)(p-strfrmt)>=sizeof("-+ #0")) luaL_error(L,"invalid format (repeated flags)"); if(isdigit(uchar(*p)))p++; if(isdigit(uchar(*p)))p++; if(*p=='.'){ p++; if(isdigit(uchar(*p)))p++; if(isdigit(uchar(*p)))p++; } if(isdigit(uchar(*p))) luaL_error(L,"invalid format (width or precision too long)"); *(form++)='%'; strncpy(form,strfrmt,p-strfrmt+1); form+=p-strfrmt+1; *form='\0'; return p; } static void addintlen(char*form){ size_t l=strlen(form); char spec=form[l-1]; strcpy(form+l-1,"l"); form[l+sizeof("l")-2]=spec; form[l+sizeof("l")-1]='\0'; } static int str_format(lua_State*L){ int top=lua_gettop(L); int arg=1; size_t sfl; const char*strfrmt=luaL_checklstring(L,arg,&sfl); const char*strfrmt_end=strfrmt+sfl; luaL_Buffer b; luaL_buffinit(L,&b); while(strfrmt<strfrmt_end){ if(*strfrmt!='%') luaL_addchar(&b,*strfrmt++); else if(*++strfrmt=='%') luaL_addchar(&b,*strfrmt++); else{ char form[(sizeof("-+ #0")+sizeof("l")+10)]; char buff[512]; if(++arg>top) luaL_argerror(L,arg,"no value"); strfrmt=scanformat(L,strfrmt,form); switch(*strfrmt++){ case'c':{ sprintf(buff,form,(int)luaL_checknumber(L,arg)); break; } case'd':case'i':{ addintlen(form); sprintf(buff,form,(long)luaL_checknumber(L,arg)); break; } case'o':case'u':case'x':case'X':{ addintlen(form); sprintf(buff,form,(unsigned long)luaL_checknumber(L,arg)); break; } case'e':case'E':case'f': case'g':case'G':{ sprintf(buff,form,(double)luaL_checknumber(L,arg)); break; } case'q':{ addquoted(L,&b,arg); continue; } case's':{ size_t l; const char*s=luaL_checklstring(L,arg,&l); if(!strchr(form,'.')&&l>=100){ lua_pushvalue(L,arg); luaL_addvalue(&b); continue; } else{ sprintf(buff,form,s); break; } } default:{ return luaL_error(L,"invalid option "LUA_QL("%%%c")" to " LUA_QL("format"),*(strfrmt-1)); } } luaL_addlstring(&b,buff,strlen(buff)); } } luaL_pushresult(&b); return 1; } static const luaL_Reg strlib[]={ {"byte",str_byte}, {"char",str_char}, {"find",str_find}, {"format",str_format}, {"gmatch",gmatch}, {"gsub",str_gsub}, {"lower",str_lower}, {"match",str_match}, {"rep",str_rep}, {"sub",str_sub}, {"upper",str_upper}, {NULL,NULL} }; static void createmetatable(lua_State*L){ lua_createtable(L,0,1); lua_pushliteral(L,""); lua_pushvalue(L,-2); lua_setmetatable(L,-2); lua_pop(L,1); lua_pushvalue(L,-2); lua_setfield(L,-2,"__index"); lua_pop(L,1); } static int luaopen_string(lua_State*L){ luaL_register(L,"string",strlib); createmetatable(L); return 1; } static const luaL_Reg lualibs[]={ {"",luaopen_base}, {"table",luaopen_table}, {"io",luaopen_io}, {"os",luaopen_os}, {"string",luaopen_string}, {NULL,NULL} }; static void luaL_openlibs(lua_State*L){ const luaL_Reg*lib=lualibs; for(;lib->func;lib++){ lua_pushcfunction(L,lib->func); lua_pushstring(L,lib->name); lua_call(L,1,0); } } typedef unsigned int UB; static UB barg(lua_State*L,int idx){ union{lua_Number n;U64 b;}bn; bn.n=lua_tonumber(L,idx)+6755399441055744.0; if(bn.n==0.0&&!lua_isnumber(L,idx))luaL_typerror(L,idx,"number"); return(UB)bn.b; } #define BRET(b)lua_pushnumber(L,(lua_Number)(int)(b));return 1; static int tobit(lua_State*L){ BRET(barg(L,1))} static int bnot(lua_State*L){ BRET(~barg(L,1))} static int band(lua_State*L){ int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b&=barg(L,i);BRET(b)} static int bor(lua_State*L){ int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b|=barg(L,i);BRET(b)} static int bxor(lua_State*L){ int i;UB b=barg(L,1);for(i=lua_gettop(L);i>1;i--)b^=barg(L,i);BRET(b)} static int lshift(lua_State*L){ UB b=barg(L,1),n=barg(L,2)&31;BRET(b<<n)} static int rshift(lua_State*L){ UB b=barg(L,1),n=barg(L,2)&31;BRET(b>>n)} static int arshift(lua_State*L){ UB b=barg(L,1),n=barg(L,2)&31;BRET((int)b>>n)} static int rol(lua_State*L){ UB b=barg(L,1),n=barg(L,2)&31;BRET((b<<n)|(b>>(32-n)))} static int ror(lua_State*L){ UB b=barg(L,1),n=barg(L,2)&31;BRET((b>>n)|(b<<(32-n)))} static int bswap(lua_State*L){ UB b=barg(L,1);b=(b>>24)|((b>>8)&0xff00)|((b&0xff00)<<8)|(b<<24);BRET(b)} static int tohex(lua_State*L){ UB b=barg(L,1); int n=lua_isnone(L,2)?8:(int)barg(L,2); const char*hexdigits="0123456789abcdef"; char buf[8]; int i; if(n<0){n=-n;hexdigits="0123456789ABCDEF";} if(n>8)n=8; for(i=(int)n;--i>=0;){buf[i]=hexdigits[b&15];b>>=4;} lua_pushlstring(L,buf,(size_t)n); return 1; } static const struct luaL_Reg bitlib[]={ {"tobit",tobit}, {"bnot",bnot}, {"band",band}, {"bor",bor}, {"bxor",bxor}, {"lshift",lshift}, {"rshift",rshift}, {"arshift",arshift}, {"rol",rol}, {"ror",ror}, {"bswap",bswap}, {"tohex",tohex}, {NULL,NULL} }; int main(int argc,char**argv){ lua_State*L=luaL_newstate(); int i; luaL_openlibs(L); luaL_register(L,"bit",bitlib); if(argc<2)return sizeof(void*); lua_createtable(L,0,1); lua_pushstring(L,argv[1]); lua_rawseti(L,-2,0); lua_setglobal(L,"arg"); if(luaL_loadfile(L,argv[1])) goto err; for(i=2;i<argc;i++) lua_pushstring(L,argv[i]); if(lua_pcall(L,argc-2,0,0)){ err: fprintf(stderr,"Error: %s\n",lua_tostring(L,-1)); return 1; } lua_close(L); return 0; }
the_stack_data/359006.c
#include <stdio.h> #include <stdlib.h> typedef char String[1000];/*make the size big to avoid errors*/ typedef struct { int id; char *name; } myClass; /* int main(void) { String message = "not enitialized message\n"; myClass *myObject = (myClass *)malloc(sizeof(myClass));/*instentiate an object int idSize,nameSize; myObject->id= 123; myObject->name = "Adam"; idSize = sizeof myObject->id; nameSize = sizeof myObject->name; sprintf(message,"\nObject Name: myObject\n" "Object Members:-\n" "id: size = %d, value = %d\n" "name: size = %d, value = %s\n\n", idSize, myObject->id, nameSize, myObject->name); puts(message); return 0; } */ /*Sample Output:- Object Name: myObject Object Members:- id: size = 4, value = 123 name: size = 4, value = Adam */
the_stack_data/211079979.c
#include <omp.h> #include <stdio.h> #include <stdlib.h> double start_time; double end_time; float *dirty; float ressss; int flushsz=100000000; int num_of_core=128; void get_time(int flag){ float tttmp[num_of_core]; if (flag == 1){ dirty = (float *)malloc(flushsz * sizeof(float)); #pragma omp parallel for for (int dirt = 0; dirt < flushsz; dirt++){ dirty[dirt] += dirt%100; tttmp[dirt%num_of_core] += dirty[dirt]; } for(int ii =0; ii<num_of_core;ii++){ressss+= tttmp[ii];} //printf("flush\n"); start_time = omp_get_wtime(); } else{ end_time = omp_get_wtime() - start_time; printf("time is : %lf\n", end_time); free(dirty); } }
the_stack_data/184395.c
#include<stdio.h> int cf(float x){ x=(x*1.8)+32; return(x); } int fc(float x){ x=(x-32)/1.8; return(x); } void main(){ char c; float x,C,F; printf("Você gostaria de saber os graus Celsius ou Fahrenheit C ou F: "); scanf("%c", &c); switch(tolower(c)){ case 'c': printf("Digite a temperatura em Fahrenheit: "); scanf("%f", &x); C=fc(x); printf("A temperatura em Celsius é %.2f.", C); break; case 'f': printf("Digite a temperatura em Celsius: "); scanf("%f", &x); F=cf(x); printf("A temperatura em Fahrenheit é %.2f.", F); break; } }
the_stack_data/15763346.c
#include <sys/types.h> /* pid_t() */ #include <sys/wait.h> /* wait() */ #include <stdio.h> /* printf() */ #include <stdlib.h> /* exit() */ #include <unistd.h> /* _exit(), fork() */ #include <signal.h> /* signal() */ /* tuberia <prog1> <prog2> runs prog2 emulating its stdin with the prog1 stdout */ void runSource(int pfd[], char *prog1); void runDestination(int pfd[], char *prog2); int main(int argc, char *argv[]) { if (argc != 3 ){ /*Basic error handling*/ fprintf(stderr, "Error in number of arguments\n"); _exit(EXIT_FAILURE); } pid_t pid; //save the pid of the children int pipefd[2]; pipe(pipefd); /* Whatever is written in fd[1] will be read from fd[0] */ runSource(pipefd, argv[1]); //run the first program runDestination(pipefd, argv[2]); //run the second program close(pipefd[0]); close(pipefd[1]); /*close both file descriptors on the pipe */ while ((pid = wait(NULL)) != -1) {/* wait until any child proccess ends */ printf("Process %d ends\n", pid); } return EXIT_SUCCESS; } void runSource(int pipefd[], char *prog1) { /* run the first program */ switch (fork()) { case 0: /* child */ close(STDOUT_FILENO); dup(pipefd[1]); /* this end of the pipe becomes stdout */ close(pipefd[0]); /* this process does not need the other end */ execlp(prog1, prog1, (char *)NULL); /* run the program */ break; default: break; /* parent does nothing */ case -1: fprintf(stderr,"Error in fork()\n"); exit(EXIT_FAILURE); break; } } void runDestination(int pipefd[], char *prog2) { /* run the second program */ switch (fork()) { case 0: /* child */ close(STDIN_FILENO); dup(pipefd[0]); /* this end of the pipe becomes stdin */ close(pipefd[1]); /* this process does not need the other end */ execlp(prog2, prog2, (char *)NULL); /* run the program */ break; default: break; /* parent does nothing */ case -1: fprintf(stderr,"Error in fork()\n"); exit(EXIT_FAILURE); break; } }
the_stack_data/11074629.c
#include <endian.h> int main(int argc, char *argv[]) { return 0 * __swap32md(argc); }
the_stack_data/161079720.c
#include<string.h> #include<math.h> #include<stdlib.h> #include<stdio.h> int main() { int I, J; I = 1; J = 60; while(J >= 0) { printf("I=%d J=%d\n", I, J); I = I + 3; J = J - 5; } return 0; }
the_stack_data/143195.c
// https://www.geeksforgeeks.org/print-all-possible-combinations-of-r-elements-in-a-given-array-of-size-n/ // Program to print all combination of size r in an array of size n #include <stdio.h> #include <stdlib.h> void comb_backtrack(const int* arr, int* vcurr, int start, int end, int index, int r, size_t* cont); void print_combination(int n, int k, size_t* cont) { int* vcurr = malloc(k * sizeof(int)); int* digits = malloc(n * sizeof(int)); for (size_t arr_cont = 0; arr_cont < n; arr_cont += 1) digits[arr_cont] = arr_cont + 1; comb_backtrack(digits, vcurr, 0, n - 1, 0, k, cont); free(vcurr); free(digits); } void comb_backtrack(const int* arr, int* vcurr, int start, int end, int i, int k, size_t* cont) { if (i == k) { (*cont)++; printf("%zu)\t", *cont); for (int j = 0; j < k; j++) printf("%d ", vcurr[j]); printf("\n"); return; } for (int j = start; j <= end && end - j + 1 >= k - i; j += 1) { vcurr[i] = arr[j]; comb_backtrack(arr, vcurr, j + 1, end, i + 1, k, cont); } } int main() { int k = 3; int n = 6; size_t cont = 0; print_combination(n, k, &cont); return EXIT_SUCCESS; }
the_stack_data/214176.c
/* $OpenBSD: wcscspn.c,v 1.4 2015/09/12 16:23:14 guenther Exp $ */ /* $NetBSD: wcscspn.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */ /*- * Copyright (c)1999 Citrus 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 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. * * citrus Id: wcscspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp */ #include <wchar.h> size_t wcscspn(const wchar_t *s, const wchar_t *set) { const wchar_t *p; const wchar_t *q; p = s; while (*p) { q = set; while (*q) { if (*p == *q) goto done; q++; } p++; } done: return (p - s); } DEF_STRONG(wcscspn);
the_stack_data/593979.c
/* There was a parsing error here */ static const int pi = 3, s0 = 7;
the_stack_data/93768.c
/*- * %sccs.include.proprietary.c% */ #ifndef lint static char sccsid[] = "@(#)mkey1.c 4.2 (Berkeley) 04/18/91"; #endif /* not lint */ #include <stdio.h> extern char *comname; /* "/usr/lib/eign" */ int wholefile = 0; int keycount = 100; int labels = 1; int minlen = 3; extern int comcount; char *iglist = "XYZ#"; main (argc,argv) char *argv[]; { /* this program expects as its arguments a list of * files and generates a set of lines of the form * filename:byte-add,length (tab) key1 key2 key3 * where the byte addresses give the position within * the file and the keys are the strings off the lines * which are alphabetic, first six characters only. */ int i; char *name, qn[200]; char *inlist = 0; FILE *f, *ff; while (argc>1 && argv[1][0] == '-') { switch(argv[1][1]) { case 'c': comname = argv[2]; argv++; argc--; break; case 'w': wholefile = 1; break; case 'f': inlist = argv[2]; argv++; argc--; break; case 'i': iglist = argv[2]; argv++; argc--; break; case 'l': minlen = atoi(argv[1]+2); if (minlen<=0) minlen=3; break; case 'n': /* number of common words to use */ comcount = atoi(argv[1]+2); break; case 'k': /* number of keys per file max */ keycount = atoi(argv[1]+2); break; case 's': /* suppress labels, search only */ labels = 0; break; } argc--; argv++; } if (inlist) { ff = fopen(inlist, "r"); while (fgets(qn, 200, ff)) { trimnl(qn); f = fopen (qn, "r"); if (f!=NULL) dofile(f, qn); else fprintf(stderr, "Can't read %s\n",qn); } } else if (argc<=1) dofile(stdin, ""); else for(i=1; i<argc; i++) { f = fopen(name=argv[i], "r"); if (f==NULL) err("No file %s",name); else dofile(f, name); } exit(0); }
the_stack_data/135913.c
#include <ncurses.h> int main(void) { WINDOW *winny; int a; initscr(); start_color(); init_pair(1,COLOR_WHITE,COLOR_BLUE); init_pair(2,COLOR_RED,COLOR_YELLOW); bkgd(COLOR_PAIR(1)); winny = newwin(5,20,10,30); wbkgd(winny,COLOR_PAIR(2)); for(a=0;a<(COLS*LINES);a++) addch('*'); syncok(winny,TRUE); waddstr(winny,"This string is written to the window 'winny'"); wnoutrefresh(stdscr); wnoutrefresh(winny); doupdate(); getch(); delwin(winny); touchwin(stdscr); refresh(); getch(); endwin(); return 0; }
the_stack_data/674094.c
//----------------------------------------------------------------------------- // caps.c // extracts the upper case letters in the input file and places them // in the output file // // // A new feature in this program is the placement of a function // definition after function main, rather than before. When this is // done, a function prototype must precede function main. A function // prototype consists of the function heading followed by a semicolon. //----------------------------------------------------------------------------- #include<stdio.h> #include<stdlib.h> #include<ctype.h> #include<assert.h> #define MAX_STRING_LENGTH 100 // prototype of function extractCaps void extractCaps(char* s, char* caps); // function main which reads command line arguments int main(int argc, char* argv[]){ FILE* in; // handle for input file FILE* out; // handle for output file char* word; // dynamically allocated string holding input word char* capsWord; // dynamically allocated string holding caps in word // check command line for correct number of arguments if( argc != 3 ){ printf("Usage: %s input-file output-file\n", argv[0]); exit(EXIT_FAILURE); } // open input file for reading in = fopen(argv[1], "r"); if( in==NULL ){ printf("Unable to read from file %s\n", argv[1]); exit(EXIT_FAILURE); } // open output file for writing out = fopen(argv[2], "w"); if( out==NULL ){ printf("Unable to write to file %s\n", argv[2]); exit(EXIT_FAILURE); } // allocate strings word and capsWord from heap memory word = calloc(MAX_STRING_LENGTH+1, sizeof(char) ); capsWord = calloc(MAX_STRING_LENGTH+1, sizeof(char) ); assert( word!=NULL && capsWord!=NULL ); // read each word in input file, extract caps while( fscanf(in, " %s", word) != EOF ){ extractCaps(word, capsWord); fprintf(out, "%s\n", capsWord); } // free heap memory associated with string variables word and capsWord free(word); free(capsWord); // close input and output files fclose(in); fclose(out); return EXIT_SUCCESS; } // definition of function extractCaps void extractCaps(char* s, char* caps){ int i=0, j=0; while(s[i]!='\0' && i<MAX_STRING_LENGTH){ if( isupper(s[i]) ){ caps[j] = s[i]; j++; } i++; } caps[j] = '\0'; }
the_stack_data/54568.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_isdigit.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: fnaciri- <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/10/09 15:00:06 by fnaciri- #+# #+# */ /* Updated: 2019/10/20 19:32:07 by fnaciri- ### ########.fr */ /* */ /* ************************************************************************** */ int ft_isdigit(int c) { if (c >= 48 && c <= 57) return (1); return (0); }
the_stack_data/1149791.c
/* utils.c - some useful functions that can be used elsewhere. * * "THE BEER-WARE LICENSE" (Revision 42): * <[email protected]> wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return Clement LECIGNE. */ #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <dirent.h> #define _GNU_SOURCE #include <unistd.h> #include <fcntl.h> #include <sys/syscall.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> #include <netinet/in.h> #ifdef __OpenBSD__ /* -lutil */ #include <util.h> #endif /* do a random kernel operation, used to detect memory disclosure. */ void kernop(void) { const int randsopts[] = { SOL_SOCKET, IPPROTO_IPV6, IPPROTO_IP, IPPROTO_TCP }; int ret; unsigned int len; char buf[1024]; int s; s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (s < 0) return; do { len = (rand() % 2) ? sizeof(int) : sizeof(buf); ret = getsockopt(s, randsopts[rand() % sizeof(randsopts)/sizeof(randsopts[0])], rand() % 130, &buf, &len); } while (ret < 0); close(s); } /* return random filename on the FS or not. */ char *getfile(void) { switch (rand() % 5) { case 0: return "/etc/passwd"; case 1: return "/dev/random"; case 2: return "/tmp/fusse"; case 3: return "/tmp/"; #ifdef __linux__ case 4: return "/proc/self/maps"; #endif default: return "/"; } return "foo"; } /* return a random file descriptor */ int getfd(void) { int fd, flags; do { switch (rand() % 7) { case 0: fd = open("/etc/passwd", O_RDONLY); break; case 1: fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); break; case 2: fd = open("/dev/random", O_RDONLY); break; case 3: fd = open("/tmp/fusse", O_CREAT|O_RDWR, 0666); break; default: fd = open(getfile(), rand()); break; } } while (fd < 0); flags = fcntl(fd, F_GETFL, 0); /* force non blocking more on fd */ fcntl(fd, F_SETFL, flags | O_NONBLOCK); return fd; } /* return an int from hell! :) */ int evilint(void) { int state; unsigned common_sizeofs[] = { 16, 32, 64, 128, 256 }; #define _SIZEOFRAND ((rand() % 4) ? 1 : common_sizeofs[rand()%(sizeof(common_sizeofs)/sizeof(common_sizeofs[0]))]); state = rand() % 20; switch ( state ) { case 0: return rand(); break; case 1: return( 0xffffff00 | (rand() % 256)); case 2: return 0x8000 / _SIZEOFRAND; case 3: return 0xffff / _SIZEOFRAND; case 4: return 0x80000000 / _SIZEOFRAND; case 5: return -1; case 6: return 0xff; case 7: return 0x7fffffff / _SIZEOFRAND; case 8: return 0; case 9: return 4; case 10: return 8; case 11: return 12; case 12: return 0xffffffff / _SIZEOFRAND case 13: case 14: return rand() & 256; default: return rand(); } } uintptr_t evilptr(void) { return (uintptr_t) evilint(); } void dump(unsigned char * data, unsigned int len) { unsigned int dp, p; const char trans[] = "................................ !\"#$%&'()*+,-./0123456789" ":;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklm" "nopqrstuvwxyz{|}~...................................." "....................................................." "........................................"; printf("\n"); for ( dp = 1; dp <= len; dp++ ) { printf("%02x ", data[dp-1]); if ( (dp % 8) == 0 ) { printf("| "); p = dp; for ( dp -= 8; dp < p; dp++ ) { printf("%c", trans[data[dp]]); } printf("\n"); } } return; } /* create a random stream of mm_size bytes inside mm. */ void fuzzer(char *mm, size_t mm_size) { size_t i; for ( i = 0 ; i < mm_size ; i++ ) { /* lame format string checker, evil values or random. */ if ( rand() % 40 == 0 && i < mm_size - 2 ) { mm[i++] = '%'; switch (rand() % 2) { case 0: mm[i] = 'n'; break; case 1: mm[i] = 'x'; break; default: mm[i] = 'u'; break; } } else if ( rand() % 40 == 0 ) mm[i] = 255; else if ( rand() % 40 == 0 ) mm[i] = 0; else { mm[i] = rand() & 255; if ( rand() % 10 == 0 ) mm[i] |= 0x80; } } return; } /* return a valid random fd */ int randfd(void) { DIR *dip; struct dirent *dit; static int nbf = 1500; unsigned int n = rand() % nbf, i = 0; int fd = -1; chdir("/dev"); dip = opendir("/dev"); if ( dip == NULL ) return -1; while ( (dit = readdir(dip)) != NULL ) { if ( i == n ) { //printf("open(%s)...", dit->d_name); switch (rand() % 3) { #if defined(__OpenBSD__) case 1: fd = opendev(dit->d_name, O_RDONLY, (rand() % 2) ? OPENDEV_BLCK : OPENDEV_PART, NULL); break; case 2: fd = opendev(dit->d_name, O_RDWR, (rand() % 2) ? OPENDEV_BLCK : OPENDEV_PART, NULL); break; #else case 1: case 2: #endif case 0: fd = open(dit->d_name, O_RDONLY); break; } //printf("%s\n", (fd > 0) ? "done" : "failed"); closedir(dip); return fd; } i++; } nbf = i; closedir(dip); return -1; }
the_stack_data/14201251.c
#include<stdio.h> void main() { int x,y,z=1,i; printf("enter the number and power\n"); scanf("%d %d",&x,&y); for(i=1;i<=y;i++) z=z*x; printf("result is %d \n",z); }
the_stack_data/28262185.c
/* Machine description pattern tests. */ /* { dg-do compile } */ /* { dg-options "-lpthread -latomic" } */ /* { dg-do run { target { s390_useable_hw } } } */ /**/ char ae_8_0 (char *lock) { return __atomic_exchange_n (lock, 0, 2); } char ae_8_1 (char *lock) { return __atomic_exchange_n (lock, 1, 2); } char g8; char ae_8_g_0 (void) { return __atomic_exchange_n (&g8, 0, 2); } char ae_8_g_1 (void) { return __atomic_exchange_n (&g8, 1, 2); } /**/ short ae_16_0 (short *lock) { return __atomic_exchange_n (lock, 0, 2); } short ae_16_1 (short *lock) { return __atomic_exchange_n (lock, 1, 2); } short g16; short ae_16_g_0 (void) { return __atomic_exchange_n (&g16, 0, 2); } short ae_16_g_1 (void) { return __atomic_exchange_n (&g16, 1, 2); } /**/ int ae_32_0 (int *lock) { return __atomic_exchange_n (lock, 0, 2); } int ae_32_1 (int *lock) { return __atomic_exchange_n (lock, 1, 2); } int g32; int ae_32_g_0 (void) { return __atomic_exchange_n (&g32, 0, 2); } int ae_32_g_1 (void) { return __atomic_exchange_n (&g32, 1, 2); } /**/ long long ae_64_0 (long long *lock) { return __atomic_exchange_n (lock, 0, 2); } long long ae_64_1 (long long *lock) { return __atomic_exchange_n (lock, 1, 2); } long long g64; long long ae_64_g_0 (void) { return __atomic_exchange_n (&g64, 0, 2); } long long ae_64_g_1 (void) { return __atomic_exchange_n (&g64, 1, 2); } /**/ #ifdef __s390x__ __int128 ae_128_0 (__int128 *lock) { return __atomic_exchange_n (lock, 0, 2); } __int128 ae_128_1 (__int128 *lock) { return __atomic_exchange_n (lock, 1, 2); } __int128 g128; __int128 ae_128_g_0 (void) { return __atomic_exchange_n (&g128, 0, 2); } __int128 ae_128_g_1 (void) { return __atomic_exchange_n (&g128, 1, 2); } #endif int main(void) { int i; for (i = 0; i <= 2; i++) { int oval = i; { char lock; char rval; lock = oval; rval = ae_8_0 (&lock); if (lock != 0) __builtin_abort (); if (rval != oval) __builtin_abort (); lock = oval; rval = ae_8_1 (&lock); if (lock != 1) __builtin_abort (); if (rval != oval) __builtin_abort (); g8 = oval; rval = ae_8_g_0 (); if (g8 != 0) __builtin_abort (); if (rval != oval) __builtin_abort (); g8 = oval; rval = ae_8_g_1 (); if (g8 != 1) __builtin_abort (); if (rval != oval) __builtin_abort (); } { short lock; short rval; lock = oval; rval = ae_16_0 (&lock); if (lock != 0) __builtin_abort (); if (rval != oval) __builtin_abort (); lock = oval; rval = ae_16_1 (&lock); if (lock != 1) __builtin_abort (); if (rval != oval) __builtin_abort (); g16 = oval; rval = ae_16_g_0 (); if (g16 != 0) __builtin_abort (); if (rval != oval) __builtin_abort (); g16 = oval; rval = ae_16_g_1 (); if (g16 != 1) __builtin_abort (); if (rval != oval) __builtin_abort (); } { int lock; int rval; lock = oval; rval = ae_32_0 (&lock); if (lock != 0) __builtin_abort (); if (rval != oval) __builtin_abort (); lock = oval; rval = ae_32_1 (&lock); if (lock != 1) __builtin_abort (); if (rval != oval) __builtin_abort (); g32 = oval; rval = ae_32_g_0 (); if (g32 != 0) __builtin_abort (); if (rval != oval) __builtin_abort (); g32 = oval; rval = ae_32_g_1 (); if (g32 != 1) __builtin_abort (); if (rval != oval) __builtin_abort (); } { long long lock; long long rval; lock = oval; rval = ae_64_0 (&lock); if (lock != 0) __builtin_abort (); if (rval != oval) __builtin_abort (); lock = oval; rval = ae_64_1 (&lock); if (lock != 1) __builtin_abort (); if (rval != oval) __builtin_abort (); g64 = oval; rval = ae_64_g_0 (); if (g64 != 0) __builtin_abort (); if (rval != oval) __builtin_abort (); g64 = oval; rval = ae_64_g_1 (); if (g64 != 1) __builtin_abort (); if (rval != oval) __builtin_abort (); } #ifdef __s390x__ { __int128 lock; __int128 rval; lock = oval; rval = ae_128_0 (&lock); if (lock != 0) __builtin_abort (); if (rval != oval) __builtin_abort (); lock = oval; rval = ae_128_1 (&lock); if (lock != 1) __builtin_abort (); if (rval != oval) __builtin_abort (); g128 = oval; rval = ae_128_g_0 (); if (g128 != 0) __builtin_abort (); if (rval != oval) __builtin_abort (); g128 = oval; rval = ae_128_g_1 (); if (g128 != 1) __builtin_abort (); if (rval != oval) __builtin_abort (); } #endif } return 0; }
the_stack_data/103264362.c
/* UNIX V7 source code: see /COPYRIGHT or www.tuhs.org for details. */ /* */ #include <setjmp.h> #define INTR 2 #define QUIT 3 #define LINSIZ 1000 #define ARGSIZ 50 #define TRESIZ 100 #define QUOTE 0200 #define FAND 1 #define FCAT 2 #define FPIN 4 #define FPOU 8 #define FPAR 16 #define FINT 32 #define FPRS 64 #define TCOM 1 #define TPAR 2 #define TFIL 3 #define TLST 4 #define DTYP 0 #define DLEF 1 #define DRIT 2 #define DFLG 3 #define DSPR 4 #define DCOM 5 #define ENOMEM 12 #define ENOEXEC 8 int errval; char *dolp; char pidp[6]; char **dolv; jmp_buf jmpbuf; int dolc; char *promp; char *linep; char *elinep; char **argp; char **eargp; int *treep; int *treeend; char peekc; char gflg; char error; char uid; char setintr; char *arginp; int onelflg; int stoperr; #define NSIG 16 char *mesg[NSIG] = { 0, "Hangup", 0, "Quit", "Illegal instruction", "Trace/BPT trap", "IOT trap", "EMT trap", "Floating exception", "Killed", "Bus error", "Memory fault", "Bad system call", 0, "Alarm clock", "Terminated", }; char line[LINSIZ]; char *args[ARGSIZ]; int trebuf[TRESIZ]; main(c, av) int c; char **av; { register f; register char *acname, **v; for(f=3; f<15; f++) close(f); dolc = getpid(); for(f=4; f>=0; f--) { dolc = dolc/10; pidp[f] = dolc%10 + '0'; } v = av; acname = "<none>"; promp = "% "; if((uid = getuid()) == 0) promp = "# "; if(c>1 && v[1][0]=='-' && v[1][1]=='e') { ++stoperr; v[1] = v[0]; ++v; --c; } if(c > 1) { promp = 0; if (*v[1]=='-') { **v = '-'; if (v[1][1]=='c' && c>2) arginp = v[2]; else if (v[1][1]=='t') onelflg = 2; } else { close(0); f = open(v[1], 0); if(f < 0) { prs(v[1]); err(": cannot open",255); } } } if(**v == '-') { signal(QUIT, 1); f = signal(INTR, 1); if ((arginp==0&&onelflg==0) || (f&01)==0) setintr++; } dolv = v+1; dolc = c-1; loop: if(promp != 0) prs(promp); peekc = getc(); main1(); goto loop; } main1() { register char *cp; register *t; argp = args; eargp = args+ARGSIZ-5; linep = line; elinep = line+LINSIZ-5; error = 0; gflg = 0; do { cp = linep; word(); } while(*cp != '\n'); treep = trebuf; treeend = &trebuf[TRESIZ]; if(gflg == 0) { if(error == 0) { setjmp(jmpbuf); if (error) return; t = syntax(args, argp); } if(error != 0) err("syntax error",255); else execute(t); } } word() { register char c, c1; *argp++ = linep; loop: switch(c = getc()) { case ' ': case '\t': goto loop; case '\'': case '"': c1 = c; while((c=readc()) != c1) { if(c == '\n') { error++; peekc = c; return; } *linep++ = c|QUOTE; } goto pack; case '&': case ';': case '<': case '>': case '(': case ')': case '|': case '^': case '\n': *linep++ = c; *linep++ = '\0'; return; } peekc = c; pack: for(;;) { c = getc(); if(any(c, " '\"\t;&<>()|^\n")) { peekc = c; if(any(c, "\"'")) goto loop; *linep++ = '\0'; return; } *linep++ = c; } } tree(n) int n; { register *t; t = treep; treep += n; if (treep>treeend) { prs("Command line overflow\n"); error++; longjmp(jmpbuf, 1); } return(t); } getc() { register char c; if(peekc) { c = peekc; peekc = 0; return(c); } if(argp > eargp) { argp -= 10; while((c=getc()) != '\n'); argp += 10; err("Too many args",255); gflg++; return(c); } if(linep > elinep) { linep -= 10; while((c=getc()) != '\n'); linep += 10; err("Too many characters",255); gflg++; return(c); } getd: if(dolp) { c = *dolp++; if(c != '\0') return(c); dolp = 0; } c = readc(); if(c == '\\') { c = readc(); if(c == '\n') return(' '); return(c|QUOTE); } if(c == '$') { c = readc(); if(c>='0' && c<='9') { if(c-'0' < dolc) dolp = dolv[c-'0']; goto getd; } if(c == '$') { dolp = pidp; goto getd; } } return(c&0177); } readc() { int rdstat; char cc; register c; if (arginp) { if (arginp == (char *)1) exit(errval); if ((c = *arginp++) == 0) { arginp = 1; c = '\n'; } return(c); } if (onelflg==1) exit(255); if((rdstat = read(0, &cc, 1)) != 1) if(rdstat==0) exit(errval); /* end of file*/ else exit(255); /* error */ if (cc=='\n' && onelflg) onelflg--; return(cc); } /* * syntax * empty * syn1 */ syntax(p1, p2) char **p1, **p2; { while(p1 != p2) { if(any(**p1, ";&\n")) p1++; else return(syn1(p1, p2)); } return(0); } /* * syn1 * syn2 * syn2 & syntax * syn2 ; syntax */ syn1(p1, p2) char **p1, **p2; { register char **p; register *t, *t1; int l; l = 0; for(p=p1; p!=p2; p++) switch(**p) { case '(': l++; continue; case ')': l--; if(l < 0) error++; continue; case '&': case ';': case '\n': if(l == 0) { l = **p; t = tree(4); t[DTYP] = TLST; t[DLEF] = syn2(p1, p); t[DFLG] = 0; if(l == '&') { t1 = t[DLEF]; t1[DFLG] |= FAND|FPRS|FINT; } t[DRIT] = syntax(p+1, p2); return(t); } } if(l == 0) return(syn2(p1, p2)); error++; return(0); } /* * syn2 * syn3 * syn3 | syn2 */ syn2(p1, p2) char **p1, **p2; { register char **p; register int l, *t; l = 0; for(p=p1; p!=p2; p++) switch(**p) { case '(': l++; continue; case ')': l--; continue; case '|': case '^': if(l == 0) { t = tree(4); t[DTYP] = TFIL; t[DLEF] = syn3(p1, p); t[DRIT] = syn2(p+1, p2); t[DFLG] = 0; return(t); } } return(syn3(p1, p2)); } /* * syn3 * ( syn1 ) [ < in ] [ > out ] * word word* [ < in ] [ > out ] */ syn3(p1, p2) char **p1, **p2; { register char **p; char **lp, **rp; register *t; int n, l, i, o, c, flg; flg = 0; if(**p2 == ')') flg |= FPAR; lp = 0; rp = 0; i = 0; o = 0; n = 0; l = 0; for(p=p1; p!=p2; p++) switch(c = **p) { case '(': if(l == 0) { if(lp != 0) error++; lp = p+1; } l++; continue; case ')': l--; if(l == 0) rp = p; continue; case '>': p++; if(p!=p2 && **p=='>') flg |= FCAT; else p--; case '<': if(l == 0) { p++; if(p == p2) { error++; p--; } if(any(**p, "<>(")) error++; if(c == '<') { if(i != 0) error++; i = *p; continue; } if(o != 0) error++; o = *p; } continue; default: if(l == 0) p1[n++] = *p; } if(lp != 0) { if(n != 0) error++; t = tree(5); t[DTYP] = TPAR; t[DSPR] = syn1(lp, rp); goto out; } if(n == 0) error++; p1[n++] = 0; t = tree(n+5); t[DTYP] = TCOM; for(l=0; l<n; l++) t[l+DCOM] = p1[l]; out: t[DFLG] = flg; t[DLEF] = i; t[DRIT] = o; return(t); } scan(at, f) int *at; int (*f)(); { register char *p, c; register *t; t = at+DCOM; while(p = *t++) while(c = *p) *p++ = (*f)(c); } tglob(c) int c; { if(any(c, "[?*")) gflg = 1; return(c); } trim(c) int c; { return(c&0177); } execute(t, pf1, pf2) int *t, *pf1, *pf2; { int i, f, pv[2]; register *t1; register char *cp1, *cp2; extern errno; if(t != 0) switch(t[DTYP]) { case TCOM: cp1 = t[DCOM]; if(equal(cp1, "chdir")) { if(t[DCOM+1] != 0) { if(chdir(t[DCOM+1]) < 0) err("chdir: bad directory",255); } else err("chdir: arg count",255); return; } if(equal(cp1, "shift")) { if(dolc < 1) { prs("shift: no args\n"); return; } dolv[1] = dolv[0]; dolv++; dolc--; return; } if(equal(cp1, "login")) { if(promp != 0) { execv("/bin/login", t+DCOM); } prs("login: cannot execute\n"); return; } if(equal(cp1, "newgrp")) { if(promp != 0) { execv("/bin/newgrp", t+DCOM); } prs("newgrp: cannot execute\n"); return; } if(equal(cp1, "wait")) { pwait(-1, 0); return; } if(equal(cp1, ":")) return; case TPAR: f = t[DFLG]; i = 0; if((f&FPAR) == 0) i = fork(); if(i == -1) { err("try again",255); return; } if(i != 0) { if((f&FPIN) != 0) { close(pf1[0]); close(pf1[1]); } if((f&FPRS) != 0) { prn(i); prs("\n"); } if((f&FAND) != 0) return; if((f&FPOU) == 0) pwait(i, t); return; } if(t[DLEF] != 0) { close(0); i = open(t[DLEF], 0); if(i < 0) { prs(t[DLEF]); err(": cannot open",255); exit(255); } } if(t[DRIT] != 0) { if((f&FCAT) != 0) { i = open(t[DRIT], 1); if(i >= 0) { lseek(i, 0L, 2); goto f1; } } i = creat(t[DRIT], 0666); if(i < 0) { prs(t[DRIT]); err(": cannot create",255); exit(255); } f1: close(1); dup(i); close(i); } if((f&FPIN) != 0) { close(0); dup(pf1[0]); close(pf1[0]); close(pf1[1]); } if((f&FPOU) != 0) { close(1); dup(pf2[1]); close(pf2[0]); close(pf2[1]); } if((f&FINT)!=0 && t[DLEF]==0 && (f&FPIN)==0) { close(0); open("/dev/null", 0); } if((f&FINT) == 0 && setintr) { signal(INTR, 0); signal(QUIT, 0); } if(t[DTYP] == TPAR) { if(t1 = t[DSPR]) t1[DFLG] |= f&FINT; execute(t1); exit(255); } gflg = 0; scan(t, tglob); if(gflg) { t[DSPR] = "/etc/glob"; execv(t[DSPR], t+DSPR); prs("glob: cannot execute\n"); exit(255); } scan(t, trim); *linep = 0; texec(t[DCOM], t); cp1 = linep; cp2 = "/usr/bin/"; while(*cp1 = *cp2++) cp1++; cp2 = t[DCOM]; while(*cp1++ = *cp2++); texec(linep+4, t); texec(linep, t); prs(t[DCOM]); err(": not found",255); exit(255); case TFIL: f = t[DFLG]; pipe(pv); t1 = t[DLEF]; t1[DFLG] |= FPOU | (f&(FPIN|FINT|FPRS)); execute(t1, pf1, pv); t1 = t[DRIT]; t1[DFLG] |= FPIN | (f&(FPOU|FINT|FAND|FPRS)); execute(t1, pv, pf2); return; case TLST: f = t[DFLG]&FINT; if(t1 = t[DLEF]) t1[DFLG] |= f; execute(t1); if(t1 = t[DRIT]) t1[DFLG] |= f; execute(t1); return; } } texec(f, at) int *at; { extern errno; register int *t; t = at; execv(f, t+DCOM); if (errno==ENOEXEC) { if (*linep) t[DCOM] = linep; t[DSPR] = "/usr/bin/osh"; execv(t[DSPR], t+DSPR); prs("No shell!\n"); exit(255); } if (errno==ENOMEM) { prs(t[DCOM]); err(": too large",255); exit(255); } } err(s, exitno) char *s; int exitno; { prs(s); prs("\n"); if(promp == 0) { lseek(0, 0L, 2); exit(exitno); } } prs(as) char *as; { register char *s; s = as; while(*s) putc(*s++); } putc(c) { char cc; cc = c; write(2, &cc, 1); } prn(n) int n; { register a; if (a = n/10) prn(a); putc(n%10 + '0'); } any(c, as) int c; char *as; { register char *s; s = as; while(*s) if(*s++ == c) return(1); return(0); } equal(as1, as2) char *as1, *as2; { register char *s1, *s2; s1 = as1; s2 = as2; while(*s1++ == *s2) if(*s2++ == '\0') return(1); return(0); } pwait(i, t) int i, *t; { register p, e; int s; if(i != 0) for(;;) { p = wait(&s); if(p == -1) break; e = s&0177; if (e>=NSIG || mesg[e]) { if(p != i) { prn(p); prs(": "); } if (e < NSIG) prs(mesg[e]); else { prs("Signal "); prn(e); } if(s&0200) prs(" -- Core dumped"); } if (e || s&&stoperr) err("", (s>>8)|e ); errval |= (s>>8); } }
the_stack_data/137440.c
/* sms4.c ** SMS4 Encryption algorithm for wireless networks ** ** $Id: sms4.c 2009-12-31 14:41:57 tao.tang <$">[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 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. **/ #include <string.h> #include <stdio.h> /*#include "sms4.h"*/ #ifndef unlong typedef unsigned long unlong; #endif /* unlong */ #ifndef unchar typedef unsigned char unchar; #endif /* unchar */ /* define SMS4CROL for rotating left */ #define SMS4CROL(uval, bits) ((uval << bits) | (uval >> (0x20 - bits))) /* define MASK code for selecting expected bits from a 32 bits value */ #define SMS4MASK3 0xFF000000 #define SMS4MASK2 0x00FF0000 #define SMS4MASK1 0x0000FF00 #define SMS4MASK0 0x000000FF /* Sbox table: 8bits input convert to 8 bits output*/ static unchar SboxTable[16][16] = { {0xd6,0x90,0xe9,0xfe,0xcc,0xe1,0x3d,0xb7,0x16,0xb6,0x14,0xc2,0x28,0xfb,0x2c,0x05}, {0x2b,0x67,0x9a,0x76,0x2a,0xbe,0x04,0xc3,0xaa,0x44,0x13,0x26,0x49,0x86,0x06,0x99}, {0x9c,0x42,0x50,0xf4,0x91,0xef,0x98,0x7a,0x33,0x54,0x0b,0x43,0xed,0xcf,0xac,0x62}, {0xe4,0xb3,0x1c,0xa9,0xc9,0x08,0xe8,0x95,0x80,0xdf,0x94,0xfa,0x75,0x8f,0x3f,0xa6}, {0x47,0x07,0xa7,0xfc,0xf3,0x73,0x17,0xba,0x83,0x59,0x3c,0x19,0xe6,0x85,0x4f,0xa8}, {0x68,0x6b,0x81,0xb2,0x71,0x64,0xda,0x8b,0xf8,0xeb,0x0f,0x4b,0x70,0x56,0x9d,0x35}, {0x1e,0x24,0x0e,0x5e,0x63,0x58,0xd1,0xa2,0x25,0x22,0x7c,0x3b,0x01,0x21,0x78,0x87}, {0xd4,0x00,0x46,0x57,0x9f,0xd3,0x27,0x52,0x4c,0x36,0x02,0xe7,0xa0,0xc4,0xc8,0x9e}, {0xea,0xbf,0x8a,0xd2,0x40,0xc7,0x38,0xb5,0xa3,0xf7,0xf2,0xce,0xf9,0x61,0x15,0xa1}, {0xe0,0xae,0x5d,0xa4,0x9b,0x34,0x1a,0x55,0xad,0x93,0x32,0x30,0xf5,0x8c,0xb1,0xe3}, {0x1d,0xf6,0xe2,0x2e,0x82,0x66,0xca,0x60,0xc0,0x29,0x23,0xab,0x0d,0x53,0x4e,0x6f}, {0xd5,0xdb,0x37,0x45,0xde,0xfd,0x8e,0x2f,0x03,0xff,0x6a,0x72,0x6d,0x6c,0x5b,0x51}, {0x8d,0x1b,0xaf,0x92,0xbb,0xdd,0xbc,0x7f,0x11,0xd9,0x5c,0x41,0x1f,0x10,0x5a,0xd8}, {0x0a,0xc1,0x31,0x88,0xa5,0xcd,0x7b,0xbd,0x2d,0x74,0xd0,0x12,0xb8,0xe5,0xb4,0xb0}, {0x89,0x69,0x97,0x4a,0x0c,0x96,0x77,0x7e,0x65,0xb9,0xf1,0x09,0xc5,0x6e,0xc6,0x84}, {0x18,0xf0,0x7d,0xec,0x3a,0xdc,0x4d,0x20,0x79,0xee,0x5f,0x3e,0xd7,0xcb,0x39,0x48} }; /* Encryption key: 128bits */ static unlong MK[4] = {0x01234567,0x89abcdef,0xfedcba98,0x76543210}; /* System parameter */ static unlong FK[4] = {0xa3b1bac6,0x56aa3350,0x677d9197,0xb27022dc}; /* fixed parameter */ static unlong CK[32] = { 0x00070e15,0x1c232a31,0x383f464d,0x545b6269, 0x70777e85,0x8c939aa1,0xa8afb6bd,0xc4cbd2d9, 0xe0e7eef5,0xfc030a11,0x181f262d,0x343b4249, 0x50575e65,0x6c737a81,0x888f969d,0xa4abb2b9, 0xc0c7ced5,0xdce3eaf1,0xf8ff060d,0x141b2229, 0x30373e45,0x4c535a61,0x686f767d,0x848b9299, 0xa0a7aeb5,0xbcc3cad1,0xd8dfe6ed,0xf4fb0209, 0x10171e25,0x2c333a41,0x484f565d,0x646b7279 }; /* buffer for round encryption key */ static unlong ENRK[32]; static unlong DERK[32]; /* original contents for debugging */ unlong pData[4] = { 0x01234567, 0x89abcdef, 0xfedcba98, 0x76543210 }; /* original contents for debugging */ unlong pData2[9] = { 0x01234567, 0x89abcdef, 0xfedcba98, 0x76543210, 0x12121212, 0x34343434, 0x56565656, 0x78787878, 0x12341234 }; /*============================================================================= ** private function: ** look up in SboxTable and get the related value. ** args: [in] inch: 0x00~0xFF (8 bits unsigned value). **============================================================================*/ static unchar SMS4Sbox(unchar inch) { unchar *pTable = (unchar *)SboxTable; unchar retVal = (unchar)(pTable[inch]); return retVal; } /*============================================================================= ** private function: ** "T algorithm" == "L algorithm" + "t algorithm". ** args: [in] a: a is a 32 bits unsigned value; ** return: c: c is calculated with line algorithm "L" and nonline algorithm "t" **============================================================================*/ static unlong SMS4Lt(unlong a) { unlong b = 0; unlong c = 0; unchar a0 = (unchar)(a & SMS4MASK0); unchar a1 = (unchar)((a & SMS4MASK1) >> 8); unchar a2 = (unchar)((a & SMS4MASK2) >> 16); unchar a3 = (unchar)((a & SMS4MASK3) >> 24); unchar b0 = SMS4Sbox(a0); unchar b1 = SMS4Sbox(a1); unchar b2 = SMS4Sbox(a2); unchar b3 = SMS4Sbox(a3); b =b0 | (b1 << 8) | (b2 << 16) | (b3 << 24); c =b^(SMS4CROL(b, 2))^(SMS4CROL(b, 10))^(SMS4CROL(b, 18))^(SMS4CROL(b, 24)); return c; } /*============================================================================= ** private function: ** Calculating round encryption key. ** args: [in] a: a is a 32 bits unsigned value; ** return: ENRK[i]: i{0,1,2,3,...31}. **============================================================================*/ static unlong SMS4CalciRK(unlong a) { unlong b = 0; unlong rk = 0; unchar a0 = (unchar)(a & SMS4MASK0); unchar a1 = (unchar)((a & SMS4MASK1) >> 8); unchar a2 = (unchar)((a & SMS4MASK2) >> 16); unchar a3 = (unchar)((a & SMS4MASK3) >> 24); unchar b0 = SMS4Sbox(a0); unchar b1 = SMS4Sbox(a1); unchar b2 = SMS4Sbox(a2); unchar b3 = SMS4Sbox(a3); b = b0 | (b1 << 8) | (b2 << 16) | (b3 << 24); rk = b^(SMS4CROL(b, 13))^(SMS4CROL(b, 23)); return rk; } /*============================================================================= ** private function: ** Calculating round encryption key. ** args: [in] ulflag: if 0: not calculate DERK , else calculate; ** return: NONE. **============================================================================*/ static void SMS4CalcRK(unlong ulflag) { unlong k[36]; unlong i = 0; k[0] = MK[0]^FK[0]; k[1] = MK[1]^FK[1]; k[2] = MK[2]^FK[2]; k[3] = MK[3]^FK[3]; for(; i<32; i++) { k[i+4] = k[i] ^ (SMS4CalciRK(k[i+1]^k[i+2]^k[i+3]^CK[i])); ENRK[i] = k[i+4]; } if (ulflag != 0x00) { for (i=0; i<32; i++) { DERK[i] = ENRK[31-i]; } } } /*============================================================================= ** private function: ** "T algorithm" == "L algorithm" + "t algorithm". ** args: [in] a: a is a 32 bits unsigned value. **============================================================================*/ static unlong SMS4T(unlong a) { return (SMS4Lt(a)); } /*============================================================================= ** private function: ** Calculating and getting encryption/decryption contents. ** args: [in] x0: original contents; ** args: [in] x1: original contents; ** args: [in] x2: original contents; ** args: [in] x3: original contents; ** args: [in] rk: encryption/decryption key; ** return the contents of encryption/decryption contents. **============================================================================*/ static unlong SMS4F(unlong x0, unlong x1, unlong x2, unlong x3, unlong rk) { return (x0^SMS4Lt(x1^x2^x3^rk)); } /*============================================================================= ** public function: ** "T algorithm" == "L algorithm" + "t algorithm". ** args: [in] ulkey: password defined by user(NULL: default encryption key); ** args: [in] flag: if 0: not calculate DERK , else calculate; ** return ulkey: NULL for default encryption key. **============================================================================*/ unlong *SMS4SetKey(unlong *ulkey, unlong flag) { if (ulkey != NULL) { memcpy(MK, ulkey, sizeof(MK)); } SMS4CalcRK(flag); return ulkey; } /*============================================================================= ** public function: ** sms4 encryption algorithm. ** args: [in/out] psrc: a pointer point to original contents; ** args: [in] lgsrc: the length of original contents; ** args: [in] derk: a pointer point to encryption/decryption key; ** return: pRet: a pointer point to encrypted contents. **============================================================================*/ unlong *SMS4Encrypt(unlong *psrc, unlong lgsrc, unlong rk[]) { unlong *pRet = NULL; unlong i = 0; unlong ulbuf[36]; unlong ulCnter = 0; unlong ulTotal = (lgsrc >> 4); if(psrc != NULL) { pRet = psrc; /* !!!It's a temporary scheme: start!!! */ /*======================================== ** 16 bytes(128 bits) is deemed as an unit. **======================================*/ while (ulCnter<ulTotal) { /* reset number counter */ i = 0; /* filled up with 0*/ memset(ulbuf, 0, sizeof(ulbuf)); memcpy(ulbuf, psrc, 16); #ifdef SMS4DBG0 printf("0x%08x, 0x%08x, 0x%08x, 0x%08x, \n", ulbuf[0], ulbuf[1], ulbuf[2], ulbuf[3]); #endif /* SMS4DBG0 */ while(i<32) { ulbuf[i+4] = SMS4F(ulbuf[i], ulbuf[i+1], ulbuf[i+2], ulbuf[i+3], rk[i]); #ifdef SMS4DBG0 printf("0x%08x, \n", ulbuf[i+4]); #endif /* SMS4DBG0 */ i++; } /* save encrypted contents to original area */ psrc[0] = ulbuf[35]; psrc[1] = ulbuf[34]; psrc[2] = ulbuf[33]; psrc[3] = ulbuf[32]; ulCnter++; psrc += 4; } /* !!!It's a temporary scheme: end!!! */ } return pRet; } /*============================================================================= ** public function: ** sms4 decryption algorithm. ** args: [in/out] psrc: a pointer point to encrypted contents; ** args: [in] lgsrc: the length of encrypted contents; ** args: [in] derk: a pointer point to decryption key; ** return: pRet: a pointer point to decrypted contents. **============================================================================*/ unlong *SMS4Decrypt(unlong *psrc, unlong lgsrc, unlong derk[]) { unlong *pRet = NULL; unlong i = 0; if(psrc != NULL) { pRet = psrc; /* the same arithmetic, different encryption key sequence. */ SMS4Encrypt(psrc, lgsrc, derk); } return pRet; } void SMS4Encrypt1M() { unlong i = 0; while (i<1000000) { SMS4Encrypt(pData, sizeof(pData), ENRK); i++; // if (0 == i%10000) // { // printf("encrypted times: %d\n", i); // } } printf("0x%08x, 0x%08x, 0x%08x, 0x%08x. \n", pData[0], pData[1], pData[2], pData[3]); } /* entry-point for debugging */ int mainSms4() { SMS4SetKey(NULL, 1); /* cycle1: common test */ printf("0x%08x, 0x%08x, 0x%08x, 0x%08x. \n", pData[0], pData[1], pData[2], pData[3]); SMS4Encrypt(pData, sizeof(pData), ENRK); printf("0x%08x, 0x%08x, 0x%08x, 0x%08x. \n", pData[0], pData[1], pData[2], pData[3]); SMS4Decrypt(pData, sizeof(pData), DERK); printf("0x%08x, 0x%08x, 0x%08x, 0x%08x. \n", pData[0], pData[1], pData[2], pData[3]); /* cycle2: encrypted 1000000 times */ SMS4Encrypt1M(); /* cycle3: longer contents */ SMS4Encrypt(pData2, sizeof(pData2), ENRK); SMS4Decrypt(pData2, sizeof(pData2), DERK); return 0; }
the_stack_data/110306.c
/* { dg-skip-if "ptxas times out" { nvptx-*-* } { "-Os" } { "" } } */ __extension__ typedef unsigned long long int uint64_t; static int sub (int a, int b) { return a - b; } static uint64_t add (uint64_t a, uint64_t b) { return a + b; } int *ptr; int foo (uint64_t arg1, int *arg2) { int j; for (; j < 1; j++) { *arg2 |= sub ( sub (sub (j || 1 ^ 0x1, 1), arg1 < 0x1 <= sub (1, *ptr & j)), (sub ( j != 1 || sub (j && j, 1) >= 0, add (!j > arg1, 0x35DLL)))); } }
the_stack_data/716478.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strlen.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: ade-agui <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/04/09 05:33:59 by ade-agui #+# #+# */ /* Updated: 2021/04/13 18:04:01 by ade-agui ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strlen(char *str) { char i; int j; i = '0'; j = 0; if (*str == '\0') return (0); while (i != '\0') { i = str[j + 1]; j++; } return (j); }
the_stack_data/259121.c
/*- * Copyright (c) 2009-2010 Brad Penoff * Copyright (c) 2009-2010 Humaira Kamal * Copyright (c) 2011-2012 Irene Ruengeler * Copyright (c) 2011-2012 Michael Tuexen * 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 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. * */ #if defined(INET) || defined(INET6) #include <sys/types.h> #if !defined(_WIN32) #include <sys/socket.h> #include <netinet/in.h> #include <unistd.h> #include <pthread.h> #if !defined(__DragonFly__) && !defined(__FreeBSD__) && !defined(__NetBSD__) #include <sys/uio.h> #else #include <user_ip6_var.h> #endif #endif #include <netinet/sctp_os.h> #include <netinet/sctp_var.h> #include <netinet/sctp_pcb.h> #include <netinet/sctp_input.h> #if 0 #if defined(__linux__) #include <linux/netlink.h> #ifdef HAVE_LINUX_IF_ADDR_H #include <linux/if_addr.h> #endif #ifdef HAVE_LINUX_RTNETLINK_H #include <linux/rtnetlink.h> #endif #endif #endif #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) #include <net/route.h> #endif /* local macros and datatypes used to get IP addresses system independently */ #if !defined(IP_PKTINFO ) && !defined(IP_RECVDSTADDR) # error "Can't determine socket option to use to get UDP IP" #endif void recv_thread_destroy(void); #define MAXLEN_MBUF_CHAIN 128 #define ROUNDUP(a, size) (((a) & ((size)-1)) ? (1 + ((a) | ((size)-1))) : (a)) #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) #define NEXT_SA(ap) ap = (struct sockaddr *) \ ((caddr_t) ap + (ap->sa_len ? ROUNDUP(ap->sa_len, sizeof (uint32_t)) : sizeof(uint32_t))) #endif #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) static void sctp_get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info) { int i; for (i = 0; i < RTAX_MAX; i++) { if (addrs & (1 << i)) { rti_info[i] = sa; NEXT_SA(sa); } else { rti_info[i] = NULL; } } } static void sctp_handle_ifamsg(unsigned char type, unsigned short index, struct sockaddr *sa) { int rc; struct ifaddrs *ifa, *ifas; /* handle only the types we want */ if ((type != RTM_NEWADDR) && (type != RTM_DELADDR)) { return; } rc = getifaddrs(&ifas); if (rc != 0) { return; } for (ifa = ifas; ifa; ifa = ifa->ifa_next) { if (index == if_nametoindex(ifa->ifa_name)) { break; } } if (ifa == NULL) { freeifaddrs(ifas); return; } /* relay the appropriate address change to the base code */ if (type == RTM_NEWADDR) { (void)sctp_add_addr_to_vrf(SCTP_DEFAULT_VRFID, NULL, if_nametoindex(ifa->ifa_name), 0, ifa->ifa_name, NULL, sa, 0, 1); } else { sctp_del_addr_from_vrf(SCTP_DEFAULT_VRFID, ifa->ifa_addr, if_nametoindex(ifa->ifa_name), ifa->ifa_name); } freeifaddrs(ifas); } static void * recv_function_route(void *arg) { ssize_t ret; struct ifa_msghdr *ifa; char rt_buffer[1024]; struct sockaddr *sa, *rti_info[RTAX_MAX]; sctp_userspace_set_threadname("SCTP addr mon"); while (1) { memset(rt_buffer, 0, sizeof(rt_buffer)); ret = recv(SCTP_BASE_VAR(userspace_route), rt_buffer, sizeof(rt_buffer), 0); if (ret > 0) { ifa = (struct ifa_msghdr *) rt_buffer; if (ifa->ifam_type != RTM_DELADDR && ifa->ifam_type != RTM_NEWADDR) { continue; } sa = (struct sockaddr *) (ifa + 1); sctp_get_rtaddrs(ifa->ifam_addrs, sa, rti_info); switch (ifa->ifam_type) { case RTM_DELADDR: case RTM_NEWADDR: sctp_handle_ifamsg(ifa->ifam_type, ifa->ifam_index, rti_info[RTAX_IFA]); break; default: /* ignore this routing event */ break; } } if (ret < 0) { if (errno == EAGAIN || errno == EINTR) { continue; } else { break; } } } return (NULL); } #endif #if 0 /* This does not yet work on Linux */ static void * recv_function_route(void *arg) { int len; char buf[4096]; struct iovec iov = { buf, sizeof(buf) }; struct msghdr msg; struct nlmsghdr *nh; struct ifaddrmsg *rtmsg; struct rtattr *rtatp; struct in_addr *inp; struct sockaddr_nl sanl; #ifdef INET struct sockaddr_in *sa; #endif #ifdef INET6 struct sockaddr_in6 *sa6; #endif for (;;) { memset(&sanl, 0, sizeof(sanl)); sanl.nl_family = AF_NETLINK; sanl.nl_groups = RTMGRP_IPV6_IFADDR | RTMGRP_IPV4_IFADDR; memset(&msg, 0, sizeof(struct msghdr)); msg.msg_name = (void *)&sanl; msg.msg_namelen = sizeof(sanl); msg.msg_iov = &iov; msg.msg_iovlen = 1; msg.msg_control = NULL; msg.msg_controllen = 0; len = recvmsg(SCTP_BASE_VAR(userspace_route), &msg, 0); if (len < 0) { if (errno == EAGAIN || errno == EINTR) { continue; } else { break; } } for (nh = (struct nlmsghdr *) buf; NLMSG_OK (nh, len); nh = NLMSG_NEXT (nh, len)) { if (nh->nlmsg_type == NLMSG_DONE) break; if (nh->nlmsg_type == RTM_NEWADDR || nh->nlmsg_type == RTM_DELADDR) { rtmsg = (struct ifaddrmsg *)NLMSG_DATA(nh); rtatp = (struct rtattr *)IFA_RTA(rtmsg); if (rtatp->rta_type == IFA_ADDRESS) { inp = (struct in_addr *)RTA_DATA(rtatp); switch (rtmsg->ifa_family) { #ifdef INET case AF_INET: sa = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in)); sa->sin_family = rtmsg->ifa_family; sa->sin_port = 0; memcpy(&sa->sin_addr, inp, sizeof(struct in_addr)); sctp_handle_ifamsg(nh->nlmsg_type, rtmsg->ifa_index, (struct sockaddr *)sa); break; #endif #ifdef INET6 case AF_INET6: sa6 = (struct sockaddr_in6 *)malloc(sizeof(struct sockaddr_in6)); sa6->sin6_family = rtmsg->ifa_family; sa6->sin6_port = 0; memcpy(&sa6->sin6_addr, inp, sizeof(struct in6_addr)); sctp_handle_ifamsg(nh->nlmsg_type, rtmsg->ifa_index, (struct sockaddr *)sa6); break; #endif default: SCTPDBG(SCTP_DEBUG_USR, "Address family %d not supported.\n", rtmsg->ifa_family); break; } } } } } return (NULL); } #endif #ifdef INET static void * recv_function_raw(void *arg) { struct mbuf **recvmbuf; struct ip *iphdr; struct sctphdr *sh; uint16_t port; int offset, ecn = 0; int compute_crc = 1; struct sctp_chunkhdr *ch; struct sockaddr_in src, dst; #if !defined(_WIN32) unsigned int ncounter; struct msghdr msg; struct iovec recv_iovec[MAXLEN_MBUF_CHAIN]; #else WSABUF recv_iovec[MAXLEN_MBUF_CHAIN]; int nResult, m_ErrorCode; DWORD flags; DWORD ncounter; struct sockaddr_in from; int fromlen; #endif /*Initially the entire set of mbufs is to be allocated. to_fill indicates this amount. */ int to_fill = MAXLEN_MBUF_CHAIN; /* iovlen is the size of each mbuf in the chain */ int i, n; unsigned int iovlen = MCLBYTES; int want_ext = (iovlen > MLEN)? 1 : 0; int want_header = 0; sctp_userspace_set_threadname("SCTP/IP4 rcv"); memset(&src, 0, sizeof(struct sockaddr_in)); memset(&dst, 0, sizeof(struct sockaddr_in)); recvmbuf = malloc(sizeof(struct mbuf *) * MAXLEN_MBUF_CHAIN); while (1) { for (i = 0; i < to_fill; i++) { /* Not getting the packet header. Tests with chain of one run as usual without having the packet header. Have tried both sending and receiving */ recvmbuf[i] = sctp_get_mbuf_for_msg(iovlen, want_header, M_NOWAIT, want_ext, MT_DATA); #if !defined(_WIN32) recv_iovec[i].iov_base = (caddr_t)recvmbuf[i]->m_data; recv_iovec[i].iov_len = iovlen; #else recv_iovec[i].buf = (caddr_t)recvmbuf[i]->m_data; recv_iovec[i].len = iovlen; #endif } to_fill = 0; #if defined(_WIN32) flags = 0; ncounter = 0; fromlen = sizeof(struct sockaddr_in); memset(&from, 0, sizeof(struct sockaddr_in)); nResult = WSARecvFrom(SCTP_BASE_VAR(userspace_rawsctp), recv_iovec, MAXLEN_MBUF_CHAIN, &ncounter, &flags, (struct sockaddr *)&from, &fromlen, NULL, NULL); if (nResult != 0) { m_ErrorCode = WSAGetLastError(); if ((m_ErrorCode == WSAENOTSOCK) || (m_ErrorCode == WSAEINTR)) { break; } continue; } n = ncounter; #else memset(&msg, 0, sizeof(struct msghdr)); msg.msg_name = NULL; msg.msg_namelen = 0; msg.msg_iov = recv_iovec; msg.msg_iovlen = MAXLEN_MBUF_CHAIN; msg.msg_control = NULL; msg.msg_controllen = 0; ncounter = n = recvmsg(SCTP_BASE_VAR(userspace_rawsctp), &msg, 0); if (n < 0) { if (errno == EAGAIN || errno == EINTR) { continue; } else { break; } } #endif SCTP_HEADER_LEN(recvmbuf[0]) = n; /* length of total packet */ SCTP_STAT_INCR(sctps_recvpackets); SCTP_STAT_INCR_COUNTER64(sctps_inpackets); if ((unsigned int)n <= iovlen) { SCTP_BUF_LEN(recvmbuf[0]) = n; (to_fill)++; } else { i = 0; SCTP_BUF_LEN(recvmbuf[0]) = iovlen; ncounter -= min(ncounter, iovlen); (to_fill)++; do { recvmbuf[i]->m_next = recvmbuf[i+1]; SCTP_BUF_LEN(recvmbuf[i]->m_next) = min(ncounter, iovlen); i++; ncounter -= min(ncounter, iovlen); (to_fill)++; } while (ncounter > 0); } iphdr = mtod(recvmbuf[0], struct ip *); sh = (struct sctphdr *)((caddr_t)iphdr + sizeof(struct ip)); ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr)); offset = sizeof(struct ip) + sizeof(struct sctphdr); if (iphdr->ip_tos != 0) { ecn = iphdr->ip_tos & 0x02; } dst.sin_family = AF_INET; #ifdef HAVE_SIN_LEN dst.sin_len = sizeof(struct sockaddr_in); #endif dst.sin_addr = iphdr->ip_dst; dst.sin_port = sh->dest_port; src.sin_family = AF_INET; #ifdef HAVE_SIN_LEN src.sin_len = sizeof(struct sockaddr_in); #endif src.sin_addr = iphdr->ip_src; src.sin_port = sh->src_port; /* SCTP does not allow broadcasts or multicasts */ if (IN_MULTICAST(ntohl(dst.sin_addr.s_addr))) { m_freem(recvmbuf[0]); continue; } if (SCTP_IS_IT_BROADCAST(dst.sin_addr, recvmbuf[0])) { m_freem(recvmbuf[0]); continue; } port = 0; if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) && ((IN4_ISLOOPBACK_ADDRESS(&src.sin_addr) && IN4_ISLOOPBACK_ADDRESS(&dst.sin_addr)) || (src.sin_addr.s_addr == dst.sin_addr.s_addr))) { compute_crc = 0; SCTP_STAT_INCR(sctps_recvhwcrc); } else { SCTP_STAT_INCR(sctps_recvswcrc); } SCTPDBG(SCTP_DEBUG_USR, "%s: Received %d bytes.", __func__, n); SCTPDBG(SCTP_DEBUG_USR, " - calling sctp_common_input_processing with off=%d\n", offset); sctp_common_input_processing(&recvmbuf[0], sizeof(struct ip), offset, n, (struct sockaddr *)&src, (struct sockaddr *)&dst, sh, ch, compute_crc, ecn, SCTP_DEFAULT_VRFID, port); if (recvmbuf[0]) { m_freem(recvmbuf[0]); } } for (i = 0; i < MAXLEN_MBUF_CHAIN; i++) { m_free(recvmbuf[i]); } /* free the array itself */ free(recvmbuf); SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/IP4 rcv\n", __func__); return (NULL); } #endif #if defined(INET6) static void * recv_function_raw6(void *arg) { struct mbuf **recvmbuf6; #if !defined(_WIN32) unsigned int ncounter = 0; struct iovec recv_iovec[MAXLEN_MBUF_CHAIN]; struct msghdr msg; struct cmsghdr *cmsgptr; char cmsgbuf[CMSG_SPACE(sizeof (struct in6_pktinfo))]; #else WSABUF recv_iovec[MAXLEN_MBUF_CHAIN]; int nResult, m_ErrorCode; DWORD ncounter = 0; struct sockaddr_in6 from; GUID WSARecvMsg_GUID = WSAID_WSARECVMSG; LPFN_WSARECVMSG WSARecvMsg; WSACMSGHDR *cmsgptr; WSAMSG msg; char ControlBuffer[1024]; #endif struct sockaddr_in6 src, dst; struct sctphdr *sh; int offset; struct sctp_chunkhdr *ch; /*Initially the entire set of mbufs is to be allocated. to_fill indicates this amount. */ int to_fill = MAXLEN_MBUF_CHAIN; /* iovlen is the size of each mbuf in the chain */ int i, n; int compute_crc = 1; unsigned int iovlen = MCLBYTES; int want_ext = (iovlen > MLEN)? 1 : 0; int want_header = 0; sctp_userspace_set_threadname("SCTP/IP6 rcv"); recvmbuf6 = malloc(sizeof(struct mbuf *) * MAXLEN_MBUF_CHAIN); for (;;) { for (i = 0; i < to_fill; i++) { /* Not getting the packet header. Tests with chain of one run as usual without having the packet header. Have tried both sending and receiving */ recvmbuf6[i] = sctp_get_mbuf_for_msg(iovlen, want_header, M_NOWAIT, want_ext, MT_DATA); #if !defined(_WIN32) recv_iovec[i].iov_base = (caddr_t)recvmbuf6[i]->m_data; recv_iovec[i].iov_len = iovlen; #else recv_iovec[i].buf = (caddr_t)recvmbuf6[i]->m_data; recv_iovec[i].len = iovlen; #endif } to_fill = 0; #if defined(_WIN32) ncounter = 0; memset(&from, 0, sizeof(struct sockaddr_in6)); nResult = WSAIoctl(SCTP_BASE_VAR(userspace_rawsctp6), SIO_GET_EXTENSION_FUNCTION_POINTER, &WSARecvMsg_GUID, sizeof WSARecvMsg_GUID, &WSARecvMsg, sizeof WSARecvMsg, &ncounter, NULL, NULL); if (nResult == 0) { msg.name = (void *)&src; msg.namelen = sizeof(struct sockaddr_in6); msg.lpBuffers = recv_iovec; msg.dwBufferCount = MAXLEN_MBUF_CHAIN; msg.Control.len = sizeof ControlBuffer; msg.Control.buf = ControlBuffer; msg.dwFlags = 0; nResult = WSARecvMsg(SCTP_BASE_VAR(userspace_rawsctp6), &msg, &ncounter, NULL, NULL); } if (nResult != 0) { m_ErrorCode = WSAGetLastError(); if ((m_ErrorCode == WSAENOTSOCK) || (m_ErrorCode == WSAEINTR)) { break; } continue; } n = ncounter; #else memset(&msg, 0, sizeof(struct msghdr)); memset(&src, 0, sizeof(struct sockaddr_in6)); memset(&dst, 0, sizeof(struct sockaddr_in6)); memset(cmsgbuf, 0, CMSG_SPACE(sizeof (struct in6_pktinfo))); msg.msg_name = (void *)&src; msg.msg_namelen = sizeof(struct sockaddr_in6); msg.msg_iov = recv_iovec; msg.msg_iovlen = MAXLEN_MBUF_CHAIN; msg.msg_control = (void *)cmsgbuf; msg.msg_controllen = (socklen_t)CMSG_SPACE(sizeof (struct in6_pktinfo)); msg.msg_flags = 0; ncounter = n = recvmsg(SCTP_BASE_VAR(userspace_rawsctp6), &msg, 0); if (n < 0) { if (errno == EAGAIN || errno == EINTR) { continue; } else { break; } } #endif SCTP_HEADER_LEN(recvmbuf6[0]) = n; /* length of total packet */ SCTP_STAT_INCR(sctps_recvpackets); SCTP_STAT_INCR_COUNTER64(sctps_inpackets); if ((unsigned int)n <= iovlen) { SCTP_BUF_LEN(recvmbuf6[0]) = n; (to_fill)++; } else { i = 0; SCTP_BUF_LEN(recvmbuf6[0]) = iovlen; ncounter -= min(ncounter, iovlen); (to_fill)++; do { recvmbuf6[i]->m_next = recvmbuf6[i+1]; SCTP_BUF_LEN(recvmbuf6[i]->m_next) = min(ncounter, iovlen); i++; ncounter -= min(ncounter, iovlen); (to_fill)++; } while (ncounter > 0); } for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL; cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) { if ((cmsgptr->cmsg_level == IPPROTO_IPV6) && (cmsgptr->cmsg_type == IPV6_PKTINFO)) { struct in6_pktinfo * info; info = (struct in6_pktinfo *)CMSG_DATA(cmsgptr); memcpy((void *)&dst.sin6_addr, (const void *) &(info->ipi6_addr), sizeof(struct in6_addr)); break; } } /* SCTP does not allow broadcasts or multicasts */ if (IN6_IS_ADDR_MULTICAST(&dst.sin6_addr)) { m_freem(recvmbuf6[0]); continue; } sh = mtod(recvmbuf6[0], struct sctphdr *); ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr)); offset = sizeof(struct sctphdr); dst.sin6_family = AF_INET6; #ifdef HAVE_SIN6_LEN dst.sin6_len = sizeof(struct sockaddr_in6); #endif dst.sin6_port = sh->dest_port; src.sin6_family = AF_INET6; #ifdef HAVE_SIN6_LEN src.sin6_len = sizeof(struct sockaddr_in6); #endif src.sin6_port = sh->src_port; if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) && (memcmp(&src.sin6_addr, &dst.sin6_addr, sizeof(struct in6_addr)) == 0)) { compute_crc = 0; SCTP_STAT_INCR(sctps_recvhwcrc); } else { SCTP_STAT_INCR(sctps_recvswcrc); } SCTPDBG(SCTP_DEBUG_USR, "%s: Received %d bytes.", __func__, n); SCTPDBG(SCTP_DEBUG_USR, " - calling sctp_common_input_processing with off=%d\n", offset); sctp_common_input_processing(&recvmbuf6[0], 0, offset, n, (struct sockaddr *)&src, (struct sockaddr *)&dst, sh, ch, compute_crc, 0, SCTP_DEFAULT_VRFID, 0); if (recvmbuf6[0]) { m_freem(recvmbuf6[0]); } } for (i = 0; i < MAXLEN_MBUF_CHAIN; i++) { m_free(recvmbuf6[i]); } /* free the array itself */ free(recvmbuf6); SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/IP6 rcv\n", __func__); return (NULL); } #endif #ifdef INET static void * recv_function_udp(void *arg) { struct mbuf **udprecvmbuf; /*Initially the entire set of mbufs is to be allocated. to_fill indicates this amount. */ int to_fill = MAXLEN_MBUF_CHAIN; /* iovlen is the size of each mbuf in the chain */ int i, n, offset; unsigned int iovlen = MCLBYTES; int want_ext = (iovlen > MLEN)? 1 : 0; int want_header = 0; struct sctphdr *sh; uint16_t port; struct sctp_chunkhdr *ch; struct sockaddr_in src, dst; #if defined(IP_PKTINFO) char cmsgbuf[CMSG_SPACE(sizeof(struct in_pktinfo))]; #else char cmsgbuf[CMSG_SPACE(sizeof(struct in_addr))]; #endif int compute_crc = 1; #if !defined(_WIN32) unsigned int ncounter; struct iovec iov[MAXLEN_MBUF_CHAIN]; struct msghdr msg; struct cmsghdr *cmsgptr; #else GUID WSARecvMsg_GUID = WSAID_WSARECVMSG; LPFN_WSARECVMSG WSARecvMsg; char ControlBuffer[1024]; WSABUF iov[MAXLEN_MBUF_CHAIN]; WSAMSG msg; int nResult, m_ErrorCode; WSACMSGHDR *cmsgptr; DWORD ncounter; #endif sctp_userspace_set_threadname("SCTP/UDP/IP4 rcv"); udprecvmbuf = malloc(sizeof(struct mbuf *) * MAXLEN_MBUF_CHAIN); while (1) { for (i = 0; i < to_fill; i++) { /* Not getting the packet header. Tests with chain of one run as usual without having the packet header. Have tried both sending and receiving */ udprecvmbuf[i] = sctp_get_mbuf_for_msg(iovlen, want_header, M_NOWAIT, want_ext, MT_DATA); #if !defined(_WIN32) iov[i].iov_base = (caddr_t)udprecvmbuf[i]->m_data; iov[i].iov_len = iovlen; #else iov[i].buf = (caddr_t)udprecvmbuf[i]->m_data; iov[i].len = iovlen; #endif } to_fill = 0; #if !defined(_WIN32) memset(&msg, 0, sizeof(struct msghdr)); #else memset(&msg, 0, sizeof(WSAMSG)); #endif memset(&src, 0, sizeof(struct sockaddr_in)); memset(&dst, 0, sizeof(struct sockaddr_in)); memset(cmsgbuf, 0, sizeof(cmsgbuf)); #if !defined(_WIN32) msg.msg_name = (void *)&src; msg.msg_namelen = sizeof(struct sockaddr_in); msg.msg_iov = iov; msg.msg_iovlen = MAXLEN_MBUF_CHAIN; msg.msg_control = (void *)cmsgbuf; msg.msg_controllen = sizeof(cmsgbuf); msg.msg_flags = 0; ncounter = n = recvmsg(SCTP_BASE_VAR(userspace_udpsctp), &msg, 0); if (n < 0) { if (errno == EAGAIN || errno == EINTR) { continue; } else { break; } } #else nResult = WSAIoctl(SCTP_BASE_VAR(userspace_udpsctp), SIO_GET_EXTENSION_FUNCTION_POINTER, &WSARecvMsg_GUID, sizeof WSARecvMsg_GUID, &WSARecvMsg, sizeof WSARecvMsg, &ncounter, NULL, NULL); if (nResult == 0) { msg.name = (void *)&src; msg.namelen = sizeof(struct sockaddr_in); msg.lpBuffers = iov; msg.dwBufferCount = MAXLEN_MBUF_CHAIN; msg.Control.len = sizeof ControlBuffer; msg.Control.buf = ControlBuffer; msg.dwFlags = 0; nResult = WSARecvMsg(SCTP_BASE_VAR(userspace_udpsctp), &msg, &ncounter, NULL, NULL); } if (nResult != 0) { m_ErrorCode = WSAGetLastError(); if ((m_ErrorCode == WSAENOTSOCK) || (m_ErrorCode == WSAEINTR)) { break; } continue; } n = ncounter; #endif SCTP_HEADER_LEN(udprecvmbuf[0]) = n; /* length of total packet */ SCTP_STAT_INCR(sctps_recvpackets); SCTP_STAT_INCR_COUNTER64(sctps_inpackets); if ((unsigned int)n <= iovlen) { SCTP_BUF_LEN(udprecvmbuf[0]) = n; (to_fill)++; } else { i = 0; SCTP_BUF_LEN(udprecvmbuf[0]) = iovlen; ncounter -= min(ncounter, iovlen); (to_fill)++; do { udprecvmbuf[i]->m_next = udprecvmbuf[i+1]; SCTP_BUF_LEN(udprecvmbuf[i]->m_next) = min(ncounter, iovlen); i++; ncounter -= min(ncounter, iovlen); (to_fill)++; } while (ncounter > 0); } for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL; cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) { #if defined(IP_PKTINFO) if ((cmsgptr->cmsg_level == IPPROTO_IP) && (cmsgptr->cmsg_type == IP_PKTINFO)) { struct in_pktinfo *info; dst.sin_family = AF_INET; #ifdef HAVE_SIN_LEN dst.sin_len = sizeof(struct sockaddr_in); #endif info = (struct in_pktinfo *)CMSG_DATA(cmsgptr); memcpy((void *)&dst.sin_addr, (const void *)&(info->ipi_addr), sizeof(struct in_addr)); break; } #else if ((cmsgptr->cmsg_level == IPPROTO_IP) && (cmsgptr->cmsg_type == IP_RECVDSTADDR)) { struct in_addr *addr; dst.sin_family = AF_INET; #ifdef HAVE_SIN_LEN dst.sin_len = sizeof(struct sockaddr_in); #endif addr = (struct in_addr *)CMSG_DATA(cmsgptr); memcpy((void *)&dst.sin_addr, (const void *)addr, sizeof(struct in_addr)); break; } #endif } /* SCTP does not allow broadcasts or multicasts */ if (IN_MULTICAST(ntohl(dst.sin_addr.s_addr))) { m_freem(udprecvmbuf[0]); continue; } if (SCTP_IS_IT_BROADCAST(dst.sin_addr, udprecvmbuf[0])) { m_freem(udprecvmbuf[0]); continue; } /*offset = sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr);*/ sh = mtod(udprecvmbuf[0], struct sctphdr *); ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr)); offset = sizeof(struct sctphdr); port = src.sin_port; src.sin_port = sh->src_port; dst.sin_port = sh->dest_port; if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) && (src.sin_addr.s_addr == dst.sin_addr.s_addr)) { compute_crc = 0; SCTP_STAT_INCR(sctps_recvhwcrc); } else { SCTP_STAT_INCR(sctps_recvswcrc); } SCTPDBG(SCTP_DEBUG_USR, "%s: Received %d bytes.", __func__, n); SCTPDBG(SCTP_DEBUG_USR, " - calling sctp_common_input_processing with off=%d\n", offset); sctp_common_input_processing(&udprecvmbuf[0], 0, offset, n, (struct sockaddr *)&src, (struct sockaddr *)&dst, sh, ch, compute_crc, 0, SCTP_DEFAULT_VRFID, port); if (udprecvmbuf[0]) { m_freem(udprecvmbuf[0]); } } for (i = 0; i < MAXLEN_MBUF_CHAIN; i++) { m_free(udprecvmbuf[i]); } /* free the array itself */ free(udprecvmbuf); SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/UDP/IP4 rcv\n", __func__); return (NULL); } #endif #if defined(INET6) static void * recv_function_udp6(void *arg) { struct mbuf **udprecvmbuf6; /*Initially the entire set of mbufs is to be allocated. to_fill indicates this amount. */ int to_fill = MAXLEN_MBUF_CHAIN; /* iovlen is the size of each mbuf in the chain */ int i, n, offset; unsigned int iovlen = MCLBYTES; int want_ext = (iovlen > MLEN)? 1 : 0; int want_header = 0; struct sockaddr_in6 src, dst; struct sctphdr *sh; uint16_t port; struct sctp_chunkhdr *ch; char cmsgbuf[CMSG_SPACE(sizeof (struct in6_pktinfo))]; int compute_crc = 1; #if !defined(_WIN32) struct iovec iov[MAXLEN_MBUF_CHAIN]; struct msghdr msg; struct cmsghdr *cmsgptr; unsigned int ncounter; #else GUID WSARecvMsg_GUID = WSAID_WSARECVMSG; LPFN_WSARECVMSG WSARecvMsg; char ControlBuffer[1024]; WSABUF iov[MAXLEN_MBUF_CHAIN]; WSAMSG msg; int nResult, m_ErrorCode; WSACMSGHDR *cmsgptr; DWORD ncounter; #endif sctp_userspace_set_threadname("SCTP/UDP/IP6 rcv"); udprecvmbuf6 = malloc(sizeof(struct mbuf *) * MAXLEN_MBUF_CHAIN); while (1) { for (i = 0; i < to_fill; i++) { /* Not getting the packet header. Tests with chain of one run as usual without having the packet header. Have tried both sending and receiving */ udprecvmbuf6[i] = sctp_get_mbuf_for_msg(iovlen, want_header, M_NOWAIT, want_ext, MT_DATA); #if !defined(_WIN32) iov[i].iov_base = (caddr_t)udprecvmbuf6[i]->m_data; iov[i].iov_len = iovlen; #else iov[i].buf = (caddr_t)udprecvmbuf6[i]->m_data; iov[i].len = iovlen; #endif } to_fill = 0; #if !defined(_WIN32) memset(&msg, 0, sizeof(struct msghdr)); #else memset(&msg, 0, sizeof(WSAMSG)); #endif memset(&src, 0, sizeof(struct sockaddr_in6)); memset(&dst, 0, sizeof(struct sockaddr_in6)); memset(cmsgbuf, 0, CMSG_SPACE(sizeof (struct in6_pktinfo))); #if !defined(_WIN32) msg.msg_name = (void *)&src; msg.msg_namelen = sizeof(struct sockaddr_in6); msg.msg_iov = iov; msg.msg_iovlen = MAXLEN_MBUF_CHAIN; msg.msg_control = (void *)cmsgbuf; msg.msg_controllen = (socklen_t)CMSG_SPACE(sizeof (struct in6_pktinfo)); msg.msg_flags = 0; ncounter = n = recvmsg(SCTP_BASE_VAR(userspace_udpsctp6), &msg, 0); if (n < 0) { if (errno == EAGAIN || errno == EINTR) { continue; } else { break; } } #else nResult = WSAIoctl(SCTP_BASE_VAR(userspace_udpsctp6), SIO_GET_EXTENSION_FUNCTION_POINTER, &WSARecvMsg_GUID, sizeof WSARecvMsg_GUID, &WSARecvMsg, sizeof WSARecvMsg, &ncounter, NULL, NULL); if (nResult == SOCKET_ERROR) { m_ErrorCode = WSAGetLastError(); WSARecvMsg = NULL; } if (nResult == 0) { msg.name = (void *)&src; msg.namelen = sizeof(struct sockaddr_in6); msg.lpBuffers = iov; msg.dwBufferCount = MAXLEN_MBUF_CHAIN; msg.Control.len = sizeof ControlBuffer; msg.Control.buf = ControlBuffer; msg.dwFlags = 0; nResult = WSARecvMsg(SCTP_BASE_VAR(userspace_udpsctp6), &msg, &ncounter, NULL, NULL); } if (nResult != 0) { m_ErrorCode = WSAGetLastError(); if ((m_ErrorCode == WSAENOTSOCK) || (m_ErrorCode == WSAEINTR)) { break; } continue; } n = ncounter; #endif SCTP_HEADER_LEN(udprecvmbuf6[0]) = n; /* length of total packet */ SCTP_STAT_INCR(sctps_recvpackets); SCTP_STAT_INCR_COUNTER64(sctps_inpackets); if ((unsigned int)n <= iovlen) { SCTP_BUF_LEN(udprecvmbuf6[0]) = n; (to_fill)++; } else { i = 0; SCTP_BUF_LEN(udprecvmbuf6[0]) = iovlen; ncounter -= min(ncounter, iovlen); (to_fill)++; do { udprecvmbuf6[i]->m_next = udprecvmbuf6[i+1]; SCTP_BUF_LEN(udprecvmbuf6[i]->m_next) = min(ncounter, iovlen); i++; ncounter -= min(ncounter, iovlen); (to_fill)++; } while (ncounter > 0); } for (cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL; cmsgptr = CMSG_NXTHDR(&msg, cmsgptr)) { if ((cmsgptr->cmsg_level == IPPROTO_IPV6) && (cmsgptr->cmsg_type == IPV6_PKTINFO)) { struct in6_pktinfo *info; dst.sin6_family = AF_INET6; #ifdef HAVE_SIN6_LEN dst.sin6_len = sizeof(struct sockaddr_in6); #endif info = (struct in6_pktinfo *)CMSG_DATA(cmsgptr); /*dst.sin6_port = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port));*/ memcpy((void *)&dst.sin6_addr, (const void *)&(info->ipi6_addr), sizeof(struct in6_addr)); } } /* SCTP does not allow broadcasts or multicasts */ if (IN6_IS_ADDR_MULTICAST(&dst.sin6_addr)) { m_freem(udprecvmbuf6[0]); continue; } sh = mtod(udprecvmbuf6[0], struct sctphdr *); ch = (struct sctp_chunkhdr *)((caddr_t)sh + sizeof(struct sctphdr)); offset = sizeof(struct sctphdr); port = src.sin6_port; src.sin6_port = sh->src_port; dst.sin6_port = sh->dest_port; if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) && (memcmp(&src.sin6_addr, &dst.sin6_addr, sizeof(struct in6_addr)) == 0)) { compute_crc = 0; SCTP_STAT_INCR(sctps_recvhwcrc); } else { SCTP_STAT_INCR(sctps_recvswcrc); } SCTPDBG(SCTP_DEBUG_USR, "%s: Received %d bytes.", __func__, n); SCTPDBG(SCTP_DEBUG_USR, " - calling sctp_common_input_processing with off=%d\n", (int)sizeof(struct sctphdr)); sctp_common_input_processing(&udprecvmbuf6[0], 0, offset, n, (struct sockaddr *)&src, (struct sockaddr *)&dst, sh, ch, compute_crc, 0, SCTP_DEFAULT_VRFID, port); if (udprecvmbuf6[0]) { m_freem(udprecvmbuf6[0]); } } for (i = 0; i < MAXLEN_MBUF_CHAIN; i++) { m_free(udprecvmbuf6[i]); } /* free the array itself */ free(udprecvmbuf6); SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/UDP/IP6 rcv\n", __func__); return (NULL); } #endif #if defined(_WIN32) static void setReceiveBufferSize(SOCKET sfd, int new_size) #else static void setReceiveBufferSize(int sfd, int new_size) #endif { int ch = new_size; if (setsockopt (sfd, SOL_SOCKET, SO_RCVBUF, (void*)&ch, sizeof(ch)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't set recv-buffers size (errno = %d).\n", WSAGetLastError()); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set recv-buffers size (errno = %d).\n", errno); #endif } return; } #if defined(_WIN32) static void setSendBufferSize(SOCKET sfd, int new_size) #else static void setSendBufferSize(int sfd, int new_size) #endif { int ch = new_size; if (setsockopt (sfd, SOL_SOCKET, SO_SNDBUF, (void*)&ch, sizeof(ch)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't set send-buffers size (errno = %d).\n", WSAGetLastError()); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set send-buffers size (errno = %d).\n", errno); #endif } return; } #define SOCKET_TIMEOUT 100 /* in ms */ void recv_thread_init(void) { #if defined(INET) struct sockaddr_in addr_ipv4; const int hdrincl = 1; #endif #if defined(INET6) struct sockaddr_in6 addr_ipv6; #endif #if defined(INET) || defined(INET6) const int on = 1; #endif #if !defined(_WIN32) struct timeval timeout; memset(&timeout, 0, sizeof(struct timeval)); timeout.tv_sec = (SOCKET_TIMEOUT / 1000); timeout.tv_usec = (SOCKET_TIMEOUT % 1000) * 1000; #else unsigned int timeout = SOCKET_TIMEOUT; /* Timeout in milliseconds */ #endif #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) if (SCTP_BASE_VAR(userspace_route) == -1) { if ((SCTP_BASE_VAR(userspace_route) = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) { SCTPDBG(SCTP_DEBUG_USR, "Can't create routing socket (errno = %d).\n", errno); } #if 0 struct sockaddr_nl sanl; if ((SCTP_BASE_VAR(userspace_route) = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) { SCTPDBG(SCTP_DEBUG_USR, "Can't create routing socket (errno = %d.\n", errno); } memset(&sanl, 0, sizeof(sanl)); sanl.nl_family = AF_NETLINK; sanl.nl_groups = 0; #ifdef INET sanl.nl_groups |= RTMGRP_IPV4_IFADDR; #endif #ifdef INET6 sanl.nl_groups |= RTMGRP_IPV6_IFADDR; #endif if (bind(SCTP_BASE_VAR(userspace_route), (struct sockaddr *) &sanl, sizeof(sanl)) < 0) { SCTPDBG(SCTP_DEBUG_USR, "Can't bind routing socket (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_route)); SCTP_BASE_VAR(userspace_route) = -1; } #endif if (SCTP_BASE_VAR(userspace_route) != -1) { if (setsockopt(SCTP_BASE_VAR(userspace_route), SOL_SOCKET, SO_RCVTIMEO,(const void*)&timeout, sizeof(struct timeval)) < 0) { SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on routing socket (errno = %d).\n", errno); #if defined(_WIN32) closesocket(SCTP_BASE_VAR(userspace_route)); #else close(SCTP_BASE_VAR(userspace_route)); #endif SCTP_BASE_VAR(userspace_route) = -1; } } } #endif #if defined(INET) if (SCTP_BASE_VAR(userspace_rawsctp) == -1) { if ((SCTP_BASE_VAR(userspace_rawsctp) = socket(AF_INET, SOCK_RAW, IPPROTO_SCTP)) == -1) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't create raw socket for IPv4 (errno = %d).\n", WSAGetLastError()); #else SCTPDBG(SCTP_DEBUG_USR, "Can't create raw socket for IPv4 (errno = %d).\n", errno); #endif } else { /* complete setting up the raw SCTP socket */ if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp), IPPROTO_IP, IP_HDRINCL,(const void*)&hdrincl, sizeof(int)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't set IP_HDRINCL (errno = %d).\n", WSAGetLastError()); closesocket(SCTP_BASE_VAR(userspace_rawsctp)); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set IP_HDRINCL (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_rawsctp)); #endif SCTP_BASE_VAR(userspace_rawsctp) = -1; } else if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp), SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/IPv4 (errno = %d).\n", WSAGetLastError()); closesocket(SCTP_BASE_VAR(userspace_rawsctp)); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/IPv4 (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_rawsctp)); #endif SCTP_BASE_VAR(userspace_rawsctp) = -1; } else { memset((void *)&addr_ipv4, 0, sizeof(struct sockaddr_in)); #ifdef HAVE_SIN_LEN addr_ipv4.sin_len = sizeof(struct sockaddr_in); #endif addr_ipv4.sin_family = AF_INET; addr_ipv4.sin_port = htons(0); addr_ipv4.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(SCTP_BASE_VAR(userspace_rawsctp), (const struct sockaddr *)&addr_ipv4, sizeof(struct sockaddr_in)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/IPv4 (errno = %d).\n", WSAGetLastError()); closesocket(SCTP_BASE_VAR(userspace_rawsctp)); #else SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/IPv4 (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_rawsctp)); #endif SCTP_BASE_VAR(userspace_rawsctp) = -1; } else { setReceiveBufferSize(SCTP_BASE_VAR(userspace_rawsctp), SB_RAW); /* 128K */ setSendBufferSize(SCTP_BASE_VAR(userspace_rawsctp), SB_RAW); /* 128K Is this setting net.inet.raw.maxdgram value? Should it be set to 64K? */ } } } } if (SCTP_BASE_VAR(userspace_udpsctp) == -1) { if ((SCTP_BASE_VAR(userspace_udpsctp) = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/UDP/IPv4 (errno = %d).\n", WSAGetLastError()); #else SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/UDP/IPv4 (errno = %d).\n", errno); #endif } else { #if defined(IP_PKTINFO) if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp), IPPROTO_IP, IP_PKTINFO, (const void *)&on, (int)sizeof(int)) < 0) { #else if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp), IPPROTO_IP, IP_RECVDSTADDR, (const void *)&on, (int)sizeof(int)) < 0) { #endif #if defined(_WIN32) #if defined(IP_PKTINFO) SCTPDBG(SCTP_DEBUG_USR, "Can't set IP_PKTINFO on socket for SCTP/UDP/IPv4 (errno = %d).\n", WSAGetLastError()); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set IP_RECVDSTADDR on socket for SCTP/UDP/IPv4 (errno = %d).\n", WSAGetLastError()); #endif closesocket(SCTP_BASE_VAR(userspace_udpsctp)); #else #if defined(IP_PKTINFO) SCTPDBG(SCTP_DEBUG_USR, "Can't set IP_PKTINFO on socket for SCTP/UDP/IPv4 (errno = %d).\n", errno); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set IP_RECVDSTADDR on socket for SCTP/UDP/IPv4 (errno = %d).\n", errno); #endif close(SCTP_BASE_VAR(userspace_udpsctp)); #endif SCTP_BASE_VAR(userspace_udpsctp) = -1; } else if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp), SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/UDP/IPv4 (errno = %d).\n", WSAGetLastError()); closesocket(SCTP_BASE_VAR(userspace_udpsctp)); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/UDP/IPv4 (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_udpsctp)); #endif SCTP_BASE_VAR(userspace_udpsctp) = -1; } else { memset((void *)&addr_ipv4, 0, sizeof(struct sockaddr_in)); #ifdef HAVE_SIN_LEN addr_ipv4.sin_len = sizeof(struct sockaddr_in); #endif addr_ipv4.sin_family = AF_INET; addr_ipv4.sin_port = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)); addr_ipv4.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(SCTP_BASE_VAR(userspace_udpsctp), (const struct sockaddr *)&addr_ipv4, sizeof(struct sockaddr_in)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/UDP/IPv4 (errno = %d).\n", WSAGetLastError()); closesocket(SCTP_BASE_VAR(userspace_udpsctp)); #else SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/UDP/IPv4 (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_udpsctp)); #endif SCTP_BASE_VAR(userspace_udpsctp) = -1; } else { setReceiveBufferSize(SCTP_BASE_VAR(userspace_udpsctp), SB_RAW); /* 128K */ setSendBufferSize(SCTP_BASE_VAR(userspace_udpsctp), SB_RAW); /* 128K Is this setting net.inet.raw.maxdgram value? Should it be set to 64K? */ } } } } #endif #if defined(INET6) if (SCTP_BASE_VAR(userspace_rawsctp6) == -1) { if ((SCTP_BASE_VAR(userspace_rawsctp6) = socket(AF_INET6, SOCK_RAW, IPPROTO_SCTP)) == -1) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError()); #else SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/IPv6 (errno = %d).\n", errno); #endif } else { /* complete setting up the raw SCTP socket */ #if defined(IPV6_RECVPKTINFO) if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp6), IPPROTO_IPV6, IPV6_RECVPKTINFO, (const void *)&on, sizeof(on)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_RECVPKTINFO on socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError()); closesocket(SCTP_BASE_VAR(userspace_rawsctp6)); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_RECVPKTINFO on socket for SCTP/IPv6 (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_rawsctp6)); #endif SCTP_BASE_VAR(userspace_rawsctp6) = -1; } else { #else if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp6), IPPROTO_IPV6, IPV6_PKTINFO,(const void*)&on, sizeof(on)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_PKTINFO on socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError()); closesocket(SCTP_BASE_VAR(userspace_rawsctp6)); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_PKTINFO on socket for SCTP/IPv6 (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_rawsctp6)); #endif SCTP_BASE_VAR(userspace_rawsctp6) = -1; } else { #endif if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp6), IPPROTO_IPV6, IPV6_V6ONLY, (const void*)&on, (socklen_t)sizeof(on)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_V6ONLY on socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError()); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_V6ONLY on socket for SCTP/IPv6 (errno = %d).\n", errno); #endif } if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp6), SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError()); closesocket(SCTP_BASE_VAR(userspace_rawsctp6)); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/IPv6 (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_rawsctp6)); #endif SCTP_BASE_VAR(userspace_rawsctp6) = -1; } else { memset((void *)&addr_ipv6, 0, sizeof(struct sockaddr_in6)); #ifdef HAVE_SIN6_LEN addr_ipv6.sin6_len = sizeof(struct sockaddr_in6); #endif addr_ipv6.sin6_family = AF_INET6; addr_ipv6.sin6_port = htons(0); addr_ipv6.sin6_addr = in6addr_any; if (bind(SCTP_BASE_VAR(userspace_rawsctp6), (const struct sockaddr *)&addr_ipv6, sizeof(struct sockaddr_in6)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError()); closesocket(SCTP_BASE_VAR(userspace_rawsctp6)); #else SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/IPv6 (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_rawsctp6)); #endif SCTP_BASE_VAR(userspace_rawsctp6) = -1; } else { setReceiveBufferSize(SCTP_BASE_VAR(userspace_rawsctp6), SB_RAW); /* 128K */ setSendBufferSize(SCTP_BASE_VAR(userspace_rawsctp6), SB_RAW); /* 128K Is this setting net.inet.raw.maxdgram value? Should it be set to 64K? */ } } } } } if (SCTP_BASE_VAR(userspace_udpsctp6) == -1) { if ((SCTP_BASE_VAR(userspace_udpsctp6) = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) == -1) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError()); #else SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/UDP/IPv6 (errno = %d).\n", errno); #endif } #if defined(IPV6_RECVPKTINFO) if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp6), IPPROTO_IPV6, IPV6_RECVPKTINFO, (const void *)&on, (int)sizeof(int)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_RECVPKTINFO on socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError()); closesocket(SCTP_BASE_VAR(userspace_udpsctp6)); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_RECVPKTINFO on socket for SCTP/UDP/IPv6 (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_udpsctp6)); #endif SCTP_BASE_VAR(userspace_udpsctp6) = -1; } else { #else if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp6), IPPROTO_IPV6, IPV6_PKTINFO, (const void *)&on, (int)sizeof(int)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_PKTINFO on socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError()); closesocket(SCTP_BASE_VAR(userspace_udpsctp6)); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_PKTINFO on socket for SCTP/UDP/IPv6 (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_udpsctp6)); #endif SCTP_BASE_VAR(userspace_udpsctp6) = -1; } else { #endif if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp6), IPPROTO_IPV6, IPV6_V6ONLY, (const void *)&on, (socklen_t)sizeof(on)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_V6ONLY on socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError()); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_V6ONLY on socket for SCTP/UDP/IPv6 (errno = %d).\n", errno); #endif } if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp6), SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError()); closesocket(SCTP_BASE_VAR(userspace_udpsctp6)); #else SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/UDP/IPv6 (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_udpsctp6)); #endif SCTP_BASE_VAR(userspace_udpsctp6) = -1; } else { memset((void *)&addr_ipv6, 0, sizeof(struct sockaddr_in6)); #ifdef HAVE_SIN6_LEN addr_ipv6.sin6_len = sizeof(struct sockaddr_in6); #endif addr_ipv6.sin6_family = AF_INET6; addr_ipv6.sin6_port = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)); addr_ipv6.sin6_addr = in6addr_any; if (bind(SCTP_BASE_VAR(userspace_udpsctp6), (const struct sockaddr *)&addr_ipv6, sizeof(struct sockaddr_in6)) < 0) { #if defined(_WIN32) SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError()); closesocket(SCTP_BASE_VAR(userspace_udpsctp6)); #else SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/UDP/IPv6 (errno = %d).\n", errno); close(SCTP_BASE_VAR(userspace_udpsctp6)); #endif SCTP_BASE_VAR(userspace_udpsctp6) = -1; } else { setReceiveBufferSize(SCTP_BASE_VAR(userspace_udpsctp6), SB_RAW); /* 128K */ setSendBufferSize(SCTP_BASE_VAR(userspace_udpsctp6), SB_RAW); /* 128K Is this setting net.inet.raw.maxdgram value? Should it be set to 64K? */ } } } } #endif #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) #if defined(INET) || defined(INET6) if (SCTP_BASE_VAR(userspace_route) != -1) { int rc; if ((rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(recvthreadroute), &recv_function_route))) { SCTPDBG(SCTP_DEBUG_USR, "Can't start routing thread (%d).\n", rc); close(SCTP_BASE_VAR(userspace_route)); SCTP_BASE_VAR(userspace_route) = -1; } } #endif #endif #if defined(INET) if (SCTP_BASE_VAR(userspace_rawsctp) != -1) { int rc; if ((rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(recvthreadraw), &recv_function_raw))) { SCTPDBG(SCTP_DEBUG_USR, "Can't start SCTP/IPv4 recv thread (%d).\n", rc); #if defined(_WIN32) closesocket(SCTP_BASE_VAR(userspace_rawsctp)); #else close(SCTP_BASE_VAR(userspace_rawsctp)); #endif SCTP_BASE_VAR(userspace_rawsctp) = -1; } } if (SCTP_BASE_VAR(userspace_udpsctp) != -1) { int rc; if ((rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(recvthreadudp), &recv_function_udp))) { SCTPDBG(SCTP_DEBUG_USR, "Can't start SCTP/UDP/IPv4 recv thread (%d).\n", rc); #if defined(_WIN32) closesocket(SCTP_BASE_VAR(userspace_udpsctp)); #else close(SCTP_BASE_VAR(userspace_udpsctp)); #endif SCTP_BASE_VAR(userspace_udpsctp) = -1; } } #endif #if defined(INET6) if (SCTP_BASE_VAR(userspace_rawsctp6) != -1) { int rc; if ((rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(recvthreadraw6), &recv_function_raw6))) { SCTPDBG(SCTP_DEBUG_USR, "Can't start SCTP/IPv6 recv thread (%d).\n", rc); #if defined(_WIN32) closesocket(SCTP_BASE_VAR(userspace_rawsctp6)); #else close(SCTP_BASE_VAR(userspace_rawsctp6)); #endif SCTP_BASE_VAR(userspace_rawsctp6) = -1; } } if (SCTP_BASE_VAR(userspace_udpsctp6) != -1) { int rc; if ((rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(recvthreadudp6), &recv_function_udp6))) { SCTPDBG(SCTP_DEBUG_USR, "Can't start SCTP/UDP/IPv6 recv thread (%d).\n", rc); #if defined(_WIN32) closesocket(SCTP_BASE_VAR(userspace_udpsctp6)); #else close(SCTP_BASE_VAR(userspace_udpsctp6)); #endif SCTP_BASE_VAR(userspace_udpsctp6) = -1; } } #endif } void recv_thread_destroy(void) { #if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) #if defined(INET) || defined(INET6) if (SCTP_BASE_VAR(userspace_route) != -1) { close(SCTP_BASE_VAR(userspace_route)); pthread_join(SCTP_BASE_VAR(recvthreadroute), NULL); } #endif #endif #if defined(INET) if (SCTP_BASE_VAR(userspace_rawsctp) != -1) { #if defined(_WIN32) closesocket(SCTP_BASE_VAR(userspace_rawsctp)); SCTP_BASE_VAR(userspace_rawsctp) = -1; WaitForSingleObject(SCTP_BASE_VAR(recvthreadraw), INFINITE); CloseHandle(SCTP_BASE_VAR(recvthreadraw)); #else close(SCTP_BASE_VAR(userspace_rawsctp)); SCTP_BASE_VAR(userspace_rawsctp) = -1; pthread_join(SCTP_BASE_VAR(recvthreadraw), NULL); #endif } if (SCTP_BASE_VAR(userspace_udpsctp) != -1) { #if defined(_WIN32) closesocket(SCTP_BASE_VAR(userspace_udpsctp)); SCTP_BASE_VAR(userspace_udpsctp) = -1; WaitForSingleObject(SCTP_BASE_VAR(recvthreadudp), INFINITE); CloseHandle(SCTP_BASE_VAR(recvthreadudp)); #else close(SCTP_BASE_VAR(userspace_udpsctp)); SCTP_BASE_VAR(userspace_udpsctp) = -1; pthread_join(SCTP_BASE_VAR(recvthreadudp), NULL); #endif } #endif #if defined(INET6) if (SCTP_BASE_VAR(userspace_rawsctp6) != -1) { #if defined(_WIN32) closesocket(SCTP_BASE_VAR(userspace_rawsctp6)); SCTP_BASE_VAR(userspace_rawsctp6) = -1; WaitForSingleObject(SCTP_BASE_VAR(recvthreadraw6), INFINITE); CloseHandle(SCTP_BASE_VAR(recvthreadraw6)); #else close(SCTP_BASE_VAR(userspace_rawsctp6)); SCTP_BASE_VAR(userspace_rawsctp6) = -1; pthread_join(SCTP_BASE_VAR(recvthreadraw6), NULL); #endif } if (SCTP_BASE_VAR(userspace_udpsctp6) != -1) { #if defined(_WIN32) SCTP_BASE_VAR(userspace_udpsctp6) = -1; closesocket(SCTP_BASE_VAR(userspace_udpsctp6)); WaitForSingleObject(SCTP_BASE_VAR(recvthreadudp6), INFINITE); CloseHandle(SCTP_BASE_VAR(recvthreadudp6)); #else close(SCTP_BASE_VAR(userspace_udpsctp6)); SCTP_BASE_VAR(userspace_udpsctp6) = -1; pthread_join(SCTP_BASE_VAR(recvthreadudp6), NULL); #endif } #endif } #else int foo; #endif
the_stack_data/148577253.c
/*---------------------------------------------------------------------------- * Copyright (c) <2016-2018>, <Huawei Technologies Co., Ltd> * All rights reserved. * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * 3. Neither the name of the copyright holder nor the names of its contributors may be used * to endorse or promote products derived from this software without specific prior written * permission. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------- * Notice of Export Control Law * =============================================== * Huawei LiteOS may be subject to applicable export control laws and regulations, which might * include those applicable to Huawei LiteOS of U.S. and the country in which you are located. * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such * applicable export control laws and regulations. *---------------------------------------------------------------------------*/ #if defined(WITH_AT_FRAMEWORK) && defined(USE_NB_NEUL95) #include "los_nb_api.h" #include "at_api_interface.h" //#include "atiny_socket.h" #include "bc95.h" int los_nb_init(const int8_t* host, const int8_t* port, sec_param_s* psk) { int ret; int timecnt = 0; if(host == NULL || port == NULL) return -1; at.init(); ret = nb_get_netstat(); if(ret == AT_FAILED) { nb_reboot(); while(1) { ret = nb_hw_detect(); if(ret == AT_OK) break; LOS_TaskDelay(1000); } //nb_get_auto_connect(); //nb_connect(NULL, NULL, NULL); while(timecnt < 120) { ret = nb_get_netstat(); //nb_check_csq(); if(ret != AT_FAILED) { ret = nb_query_ip(); break; } LOS_TaskDelay(1000); timecnt++; } } if(psk != NULL)//encryption v1.9 { nb_send_psk(psk->pskid, psk->psk); } // if(ret != AT_FAILED) // { // nb_query_ip(); // } ret = nb_set_cdpserver((char *)host, (char *)port); return ret; } int los_nb_report(const char* buf, int len) { if(buf == NULL || len <= 0) return -1; return nb_send_payload(buf, len); } int los_nb_notify(char* featurestr,int cmdlen, oob_callback callback) { if(featurestr == NULL ||cmdlen <= 0 || cmdlen >= OOB_CMD_LEN - 1) return -1; return at.oob_register(featurestr,cmdlen, callback); } int los_nb_deinit(void) { //at.deinit(); return nb_reboot(); } #endif
the_stack_data/21335.c
#include <stdio.h> int main() { int n, i; int sum, a; while (scanf("%d", &n) != EOF) { sum = 0; for (i = 0; i < n; i++) { scanf("%d", &a); sum += a; } printf("%d\n", sum); } }
the_stack_data/129684.c
/* EX3_5.C ======= Suggested solution to Exercise 3-5 */ #include <stdlib.h> #include <stdio.h> void itob(int n, char s[], int b); void reverse(char s[]); int main(void) { char buffer[10]; int i; for ( i = 2; i <= 20; ++i ) { itob(255, buffer, i); printf("Decimal 255 in base %-2d : %s\n", i, buffer); } return 0; } /* Stores a string representation of integer n in s[], using a numerical base of b. Will handle up to base-36 before we run out of digits to use. */ void itob(int n, char s[], int b) { static char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int i, sign; if ( b < 2 || b > 36 ) { fprintf(stderr, "EX3_5: Cannot support base %d\n", b); exit(EXIT_FAILURE); } if ((sign = n) < 0) n = -n; i = 0; do { s[i++] = digits[n % b]; } while ((n /= b) > 0); if (sign < 0) s[i++] = '-'; s[i] = '\0'; reverse(s); } /* Reverses string s[] in place */ void reverse(char s[]) { int c, i, j; for ( i = 0, j = strlen(s)-1; i < j; i++, j--) { c = s[i]; s[i] = s[j]; s[j] = c; } }
the_stack_data/190767150.c
/* TIC TAC TOE game - 2 players - use an array 10 elements ingle dimension (do not use 0) we will use 9 elements as the grid - each element of the array represent coordinates on the board - display 3x3 grid - some function I will need + checkForWin - see if the player won or the game is a draw + drawBoard - redraws the board for each player turn + markBoard - sets the char array with a selection and check for an invalid selection how to print the board / grid? how to input data into the grid? loops for checking and drawing new grid after each move checking if the value is correct how to check positions on x and o? */
the_stack_data/225141878.c
/* Autogenerated: src/ExtractionOCaml/word_by_word_montgomery --static secp256k1 64 '2^256 - 2^32 - 977' mul square add sub opp from_montgomery to_montgomery nonzero selectznz to_bytes from_bytes */ /* curve description: secp256k1 */ /* machine_wordsize = 64 (from "64") */ /* requested operations: mul, square, add, sub, opp, from_montgomery, to_montgomery, nonzero, selectznz, to_bytes, from_bytes */ /* m = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f (from "2^256 - 2^32 - 977") */ /* */ /* NOTE: In addition to the bounds specified above each function, all */ /* functions synthesized for this Montgomery arithmetic require the */ /* input to be strictly less than the prime modulus (m), and also */ /* require the input to be in the unique saturated representation. */ /* All functions also ensure that these two properties are true of */ /* return values. */ /* */ /* Computed values: */ /* eval z = z[0] + (z[1] << 64) + (z[2] << 128) + (z[3] << 192) */ /* bytes_eval z = z[0] + (z[1] << 8) + (z[2] << 16) + (z[3] << 24) + (z[4] << 32) + (z[5] << 40) + (z[6] << 48) + (z[7] << 56) + (z[8] << 64) + (z[9] << 72) + (z[10] << 80) + (z[11] << 88) + (z[12] << 96) + (z[13] << 104) + (z[14] << 112) + (z[15] << 120) + (z[16] << 128) + (z[17] << 136) + (z[18] << 144) + (z[19] << 152) + (z[20] << 160) + (z[21] << 168) + (z[22] << 176) + (z[23] << 184) + (z[24] << 192) + (z[25] << 200) + (z[26] << 208) + (z[27] << 216) + (z[28] << 224) + (z[29] << 232) + (z[30] << 240) + (z[31] << 248) */ #include <stdint.h> typedef unsigned char fiat_secp256k1_uint1; typedef signed char fiat_secp256k1_int1; typedef signed __int128 fiat_secp256k1_int128; typedef unsigned __int128 fiat_secp256k1_uint128; #if (-1 & 3) != 3 #error "This code only works on a two's complement system" #endif /* * The function fiat_secp256k1_addcarryx_u64 is an addition with carry. * Postconditions: * out1 = (arg1 + arg2 + arg3) mod 2^64 * out2 = ⌊(arg1 + arg2 + arg3) / 2^64⌋ * * Input Bounds: * arg1: [0x0 ~> 0x1] * arg2: [0x0 ~> 0xffffffffffffffff] * arg3: [0x0 ~> 0xffffffffffffffff] * Output Bounds: * out1: [0x0 ~> 0xffffffffffffffff] * out2: [0x0 ~> 0x1] */ static void fiat_secp256k1_addcarryx_u64(uint64_t* out1, fiat_secp256k1_uint1* out2, fiat_secp256k1_uint1 arg1, uint64_t arg2, uint64_t arg3) { fiat_secp256k1_uint128 x1 = ((arg1 + (fiat_secp256k1_uint128)arg2) + arg3); uint64_t x2 = (uint64_t)(x1 & UINT64_C(0xffffffffffffffff)); fiat_secp256k1_uint1 x3 = (fiat_secp256k1_uint1)(x1 >> 64); *out1 = x2; *out2 = x3; } /* * The function fiat_secp256k1_subborrowx_u64 is a subtraction with borrow. * Postconditions: * out1 = (-arg1 + arg2 + -arg3) mod 2^64 * out2 = -⌊(-arg1 + arg2 + -arg3) / 2^64⌋ * * Input Bounds: * arg1: [0x0 ~> 0x1] * arg2: [0x0 ~> 0xffffffffffffffff] * arg3: [0x0 ~> 0xffffffffffffffff] * Output Bounds: * out1: [0x0 ~> 0xffffffffffffffff] * out2: [0x0 ~> 0x1] */ static void fiat_secp256k1_subborrowx_u64(uint64_t* out1, fiat_secp256k1_uint1* out2, fiat_secp256k1_uint1 arg1, uint64_t arg2, uint64_t arg3) { fiat_secp256k1_int128 x1 = ((arg2 - (fiat_secp256k1_int128)arg1) - arg3); fiat_secp256k1_int1 x2 = (fiat_secp256k1_int1)(x1 >> 64); uint64_t x3 = (uint64_t)(x1 & UINT64_C(0xffffffffffffffff)); *out1 = x3; *out2 = (fiat_secp256k1_uint1)(0x0 - x2); } /* * The function fiat_secp256k1_mulx_u64 is a multiplication, returning the full double-width result. * Postconditions: * out1 = (arg1 * arg2) mod 2^64 * out2 = ⌊arg1 * arg2 / 2^64⌋ * * Input Bounds: * arg1: [0x0 ~> 0xffffffffffffffff] * arg2: [0x0 ~> 0xffffffffffffffff] * Output Bounds: * out1: [0x0 ~> 0xffffffffffffffff] * out2: [0x0 ~> 0xffffffffffffffff] */ static void fiat_secp256k1_mulx_u64(uint64_t* out1, uint64_t* out2, uint64_t arg1, uint64_t arg2) { fiat_secp256k1_uint128 x1 = ((fiat_secp256k1_uint128)arg1 * arg2); uint64_t x2 = (uint64_t)(x1 & UINT64_C(0xffffffffffffffff)); uint64_t x3 = (uint64_t)(x1 >> 64); *out1 = x2; *out2 = x3; } /* * The function fiat_secp256k1_cmovznz_u64 is a single-word conditional move. * Postconditions: * out1 = (if arg1 = 0 then arg2 else arg3) * * Input Bounds: * arg1: [0x0 ~> 0x1] * arg2: [0x0 ~> 0xffffffffffffffff] * arg3: [0x0 ~> 0xffffffffffffffff] * Output Bounds: * out1: [0x0 ~> 0xffffffffffffffff] */ static void fiat_secp256k1_cmovznz_u64(uint64_t* out1, fiat_secp256k1_uint1 arg1, uint64_t arg2, uint64_t arg3) { fiat_secp256k1_uint1 x1 = (!(!arg1)); uint64_t x2 = ((fiat_secp256k1_int1)(0x0 - x1) & UINT64_C(0xffffffffffffffff)); uint64_t x3 = ((x2 & arg3) | ((~x2) & arg2)); *out1 = x3; } /* * The function fiat_secp256k1_mul multiplies two field elements in the Montgomery domain. * Preconditions: * 0 ≤ eval arg1 < m * 0 ≤ eval arg2 < m * Postconditions: * eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) * eval (from_montgomery arg2)) mod m * 0 ≤ eval out1 < m * * Input Bounds: * arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * arg2: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * Output Bounds: * out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] */ static void fiat_secp256k1_mul(uint64_t out1[4], const uint64_t arg1[4], const uint64_t arg2[4]) { uint64_t x1 = (arg1[1]); uint64_t x2 = (arg1[2]); uint64_t x3 = (arg1[3]); uint64_t x4 = (arg1[0]); uint64_t x5; uint64_t x6; fiat_secp256k1_mulx_u64(&x5, &x6, x4, (arg2[3])); uint64_t x7; uint64_t x8; fiat_secp256k1_mulx_u64(&x7, &x8, x4, (arg2[2])); uint64_t x9; uint64_t x10; fiat_secp256k1_mulx_u64(&x9, &x10, x4, (arg2[1])); uint64_t x11; uint64_t x12; fiat_secp256k1_mulx_u64(&x11, &x12, x4, (arg2[0])); uint64_t x13; fiat_secp256k1_uint1 x14; fiat_secp256k1_addcarryx_u64(&x13, &x14, 0x0, x12, x9); uint64_t x15; fiat_secp256k1_uint1 x16; fiat_secp256k1_addcarryx_u64(&x15, &x16, x14, x10, x7); uint64_t x17; fiat_secp256k1_uint1 x18; fiat_secp256k1_addcarryx_u64(&x17, &x18, x16, x8, x5); uint64_t x19 = (x18 + x6); uint64_t x20; uint64_t x21; fiat_secp256k1_mulx_u64(&x20, &x21, x11, UINT64_C(0xd838091dd2253531)); uint64_t x22; uint64_t x23; fiat_secp256k1_mulx_u64(&x22, &x23, x20, UINT64_C(0xffffffffffffffff)); uint64_t x24; uint64_t x25; fiat_secp256k1_mulx_u64(&x24, &x25, x20, UINT64_C(0xffffffffffffffff)); uint64_t x26; uint64_t x27; fiat_secp256k1_mulx_u64(&x26, &x27, x20, UINT64_C(0xffffffffffffffff)); uint64_t x28; uint64_t x29; fiat_secp256k1_mulx_u64(&x28, &x29, x20, UINT64_C(0xfffffffefffffc2f)); uint64_t x30; fiat_secp256k1_uint1 x31; fiat_secp256k1_addcarryx_u64(&x30, &x31, 0x0, x29, x26); uint64_t x32; fiat_secp256k1_uint1 x33; fiat_secp256k1_addcarryx_u64(&x32, &x33, x31, x27, x24); uint64_t x34; fiat_secp256k1_uint1 x35; fiat_secp256k1_addcarryx_u64(&x34, &x35, x33, x25, x22); uint64_t x36 = (x35 + x23); uint64_t x37; fiat_secp256k1_uint1 x38; fiat_secp256k1_addcarryx_u64(&x37, &x38, 0x0, x11, x28); uint64_t x39; fiat_secp256k1_uint1 x40; fiat_secp256k1_addcarryx_u64(&x39, &x40, x38, x13, x30); uint64_t x41; fiat_secp256k1_uint1 x42; fiat_secp256k1_addcarryx_u64(&x41, &x42, x40, x15, x32); uint64_t x43; fiat_secp256k1_uint1 x44; fiat_secp256k1_addcarryx_u64(&x43, &x44, x42, x17, x34); uint64_t x45; fiat_secp256k1_uint1 x46; fiat_secp256k1_addcarryx_u64(&x45, &x46, x44, x19, x36); uint64_t x47; uint64_t x48; fiat_secp256k1_mulx_u64(&x47, &x48, x1, (arg2[3])); uint64_t x49; uint64_t x50; fiat_secp256k1_mulx_u64(&x49, &x50, x1, (arg2[2])); uint64_t x51; uint64_t x52; fiat_secp256k1_mulx_u64(&x51, &x52, x1, (arg2[1])); uint64_t x53; uint64_t x54; fiat_secp256k1_mulx_u64(&x53, &x54, x1, (arg2[0])); uint64_t x55; fiat_secp256k1_uint1 x56; fiat_secp256k1_addcarryx_u64(&x55, &x56, 0x0, x54, x51); uint64_t x57; fiat_secp256k1_uint1 x58; fiat_secp256k1_addcarryx_u64(&x57, &x58, x56, x52, x49); uint64_t x59; fiat_secp256k1_uint1 x60; fiat_secp256k1_addcarryx_u64(&x59, &x60, x58, x50, x47); uint64_t x61 = (x60 + x48); uint64_t x62; fiat_secp256k1_uint1 x63; fiat_secp256k1_addcarryx_u64(&x62, &x63, 0x0, x39, x53); uint64_t x64; fiat_secp256k1_uint1 x65; fiat_secp256k1_addcarryx_u64(&x64, &x65, x63, x41, x55); uint64_t x66; fiat_secp256k1_uint1 x67; fiat_secp256k1_addcarryx_u64(&x66, &x67, x65, x43, x57); uint64_t x68; fiat_secp256k1_uint1 x69; fiat_secp256k1_addcarryx_u64(&x68, &x69, x67, x45, x59); uint64_t x70; fiat_secp256k1_uint1 x71; fiat_secp256k1_addcarryx_u64(&x70, &x71, x69, x46, x61); uint64_t x72; uint64_t x73; fiat_secp256k1_mulx_u64(&x72, &x73, x62, UINT64_C(0xd838091dd2253531)); uint64_t x74; uint64_t x75; fiat_secp256k1_mulx_u64(&x74, &x75, x72, UINT64_C(0xffffffffffffffff)); uint64_t x76; uint64_t x77; fiat_secp256k1_mulx_u64(&x76, &x77, x72, UINT64_C(0xffffffffffffffff)); uint64_t x78; uint64_t x79; fiat_secp256k1_mulx_u64(&x78, &x79, x72, UINT64_C(0xffffffffffffffff)); uint64_t x80; uint64_t x81; fiat_secp256k1_mulx_u64(&x80, &x81, x72, UINT64_C(0xfffffffefffffc2f)); uint64_t x82; fiat_secp256k1_uint1 x83; fiat_secp256k1_addcarryx_u64(&x82, &x83, 0x0, x81, x78); uint64_t x84; fiat_secp256k1_uint1 x85; fiat_secp256k1_addcarryx_u64(&x84, &x85, x83, x79, x76); uint64_t x86; fiat_secp256k1_uint1 x87; fiat_secp256k1_addcarryx_u64(&x86, &x87, x85, x77, x74); uint64_t x88 = (x87 + x75); uint64_t x89; fiat_secp256k1_uint1 x90; fiat_secp256k1_addcarryx_u64(&x89, &x90, 0x0, x62, x80); uint64_t x91; fiat_secp256k1_uint1 x92; fiat_secp256k1_addcarryx_u64(&x91, &x92, x90, x64, x82); uint64_t x93; fiat_secp256k1_uint1 x94; fiat_secp256k1_addcarryx_u64(&x93, &x94, x92, x66, x84); uint64_t x95; fiat_secp256k1_uint1 x96; fiat_secp256k1_addcarryx_u64(&x95, &x96, x94, x68, x86); uint64_t x97; fiat_secp256k1_uint1 x98; fiat_secp256k1_addcarryx_u64(&x97, &x98, x96, x70, x88); uint64_t x99 = ((uint64_t)x98 + x71); uint64_t x100; uint64_t x101; fiat_secp256k1_mulx_u64(&x100, &x101, x2, (arg2[3])); uint64_t x102; uint64_t x103; fiat_secp256k1_mulx_u64(&x102, &x103, x2, (arg2[2])); uint64_t x104; uint64_t x105; fiat_secp256k1_mulx_u64(&x104, &x105, x2, (arg2[1])); uint64_t x106; uint64_t x107; fiat_secp256k1_mulx_u64(&x106, &x107, x2, (arg2[0])); uint64_t x108; fiat_secp256k1_uint1 x109; fiat_secp256k1_addcarryx_u64(&x108, &x109, 0x0, x107, x104); uint64_t x110; fiat_secp256k1_uint1 x111; fiat_secp256k1_addcarryx_u64(&x110, &x111, x109, x105, x102); uint64_t x112; fiat_secp256k1_uint1 x113; fiat_secp256k1_addcarryx_u64(&x112, &x113, x111, x103, x100); uint64_t x114 = (x113 + x101); uint64_t x115; fiat_secp256k1_uint1 x116; fiat_secp256k1_addcarryx_u64(&x115, &x116, 0x0, x91, x106); uint64_t x117; fiat_secp256k1_uint1 x118; fiat_secp256k1_addcarryx_u64(&x117, &x118, x116, x93, x108); uint64_t x119; fiat_secp256k1_uint1 x120; fiat_secp256k1_addcarryx_u64(&x119, &x120, x118, x95, x110); uint64_t x121; fiat_secp256k1_uint1 x122; fiat_secp256k1_addcarryx_u64(&x121, &x122, x120, x97, x112); uint64_t x123; fiat_secp256k1_uint1 x124; fiat_secp256k1_addcarryx_u64(&x123, &x124, x122, x99, x114); uint64_t x125; uint64_t x126; fiat_secp256k1_mulx_u64(&x125, &x126, x115, UINT64_C(0xd838091dd2253531)); uint64_t x127; uint64_t x128; fiat_secp256k1_mulx_u64(&x127, &x128, x125, UINT64_C(0xffffffffffffffff)); uint64_t x129; uint64_t x130; fiat_secp256k1_mulx_u64(&x129, &x130, x125, UINT64_C(0xffffffffffffffff)); uint64_t x131; uint64_t x132; fiat_secp256k1_mulx_u64(&x131, &x132, x125, UINT64_C(0xffffffffffffffff)); uint64_t x133; uint64_t x134; fiat_secp256k1_mulx_u64(&x133, &x134, x125, UINT64_C(0xfffffffefffffc2f)); uint64_t x135; fiat_secp256k1_uint1 x136; fiat_secp256k1_addcarryx_u64(&x135, &x136, 0x0, x134, x131); uint64_t x137; fiat_secp256k1_uint1 x138; fiat_secp256k1_addcarryx_u64(&x137, &x138, x136, x132, x129); uint64_t x139; fiat_secp256k1_uint1 x140; fiat_secp256k1_addcarryx_u64(&x139, &x140, x138, x130, x127); uint64_t x141 = (x140 + x128); uint64_t x142; fiat_secp256k1_uint1 x143; fiat_secp256k1_addcarryx_u64(&x142, &x143, 0x0, x115, x133); uint64_t x144; fiat_secp256k1_uint1 x145; fiat_secp256k1_addcarryx_u64(&x144, &x145, x143, x117, x135); uint64_t x146; fiat_secp256k1_uint1 x147; fiat_secp256k1_addcarryx_u64(&x146, &x147, x145, x119, x137); uint64_t x148; fiat_secp256k1_uint1 x149; fiat_secp256k1_addcarryx_u64(&x148, &x149, x147, x121, x139); uint64_t x150; fiat_secp256k1_uint1 x151; fiat_secp256k1_addcarryx_u64(&x150, &x151, x149, x123, x141); uint64_t x152 = ((uint64_t)x151 + x124); uint64_t x153; uint64_t x154; fiat_secp256k1_mulx_u64(&x153, &x154, x3, (arg2[3])); uint64_t x155; uint64_t x156; fiat_secp256k1_mulx_u64(&x155, &x156, x3, (arg2[2])); uint64_t x157; uint64_t x158; fiat_secp256k1_mulx_u64(&x157, &x158, x3, (arg2[1])); uint64_t x159; uint64_t x160; fiat_secp256k1_mulx_u64(&x159, &x160, x3, (arg2[0])); uint64_t x161; fiat_secp256k1_uint1 x162; fiat_secp256k1_addcarryx_u64(&x161, &x162, 0x0, x160, x157); uint64_t x163; fiat_secp256k1_uint1 x164; fiat_secp256k1_addcarryx_u64(&x163, &x164, x162, x158, x155); uint64_t x165; fiat_secp256k1_uint1 x166; fiat_secp256k1_addcarryx_u64(&x165, &x166, x164, x156, x153); uint64_t x167 = (x166 + x154); uint64_t x168; fiat_secp256k1_uint1 x169; fiat_secp256k1_addcarryx_u64(&x168, &x169, 0x0, x144, x159); uint64_t x170; fiat_secp256k1_uint1 x171; fiat_secp256k1_addcarryx_u64(&x170, &x171, x169, x146, x161); uint64_t x172; fiat_secp256k1_uint1 x173; fiat_secp256k1_addcarryx_u64(&x172, &x173, x171, x148, x163); uint64_t x174; fiat_secp256k1_uint1 x175; fiat_secp256k1_addcarryx_u64(&x174, &x175, x173, x150, x165); uint64_t x176; fiat_secp256k1_uint1 x177; fiat_secp256k1_addcarryx_u64(&x176, &x177, x175, x152, x167); uint64_t x178; uint64_t x179; fiat_secp256k1_mulx_u64(&x178, &x179, x168, UINT64_C(0xd838091dd2253531)); uint64_t x180; uint64_t x181; fiat_secp256k1_mulx_u64(&x180, &x181, x178, UINT64_C(0xffffffffffffffff)); uint64_t x182; uint64_t x183; fiat_secp256k1_mulx_u64(&x182, &x183, x178, UINT64_C(0xffffffffffffffff)); uint64_t x184; uint64_t x185; fiat_secp256k1_mulx_u64(&x184, &x185, x178, UINT64_C(0xffffffffffffffff)); uint64_t x186; uint64_t x187; fiat_secp256k1_mulx_u64(&x186, &x187, x178, UINT64_C(0xfffffffefffffc2f)); uint64_t x188; fiat_secp256k1_uint1 x189; fiat_secp256k1_addcarryx_u64(&x188, &x189, 0x0, x187, x184); uint64_t x190; fiat_secp256k1_uint1 x191; fiat_secp256k1_addcarryx_u64(&x190, &x191, x189, x185, x182); uint64_t x192; fiat_secp256k1_uint1 x193; fiat_secp256k1_addcarryx_u64(&x192, &x193, x191, x183, x180); uint64_t x194 = (x193 + x181); uint64_t x195; fiat_secp256k1_uint1 x196; fiat_secp256k1_addcarryx_u64(&x195, &x196, 0x0, x168, x186); uint64_t x197; fiat_secp256k1_uint1 x198; fiat_secp256k1_addcarryx_u64(&x197, &x198, x196, x170, x188); uint64_t x199; fiat_secp256k1_uint1 x200; fiat_secp256k1_addcarryx_u64(&x199, &x200, x198, x172, x190); uint64_t x201; fiat_secp256k1_uint1 x202; fiat_secp256k1_addcarryx_u64(&x201, &x202, x200, x174, x192); uint64_t x203; fiat_secp256k1_uint1 x204; fiat_secp256k1_addcarryx_u64(&x203, &x204, x202, x176, x194); uint64_t x205 = ((uint64_t)x204 + x177); uint64_t x206; fiat_secp256k1_uint1 x207; fiat_secp256k1_subborrowx_u64(&x206, &x207, 0x0, x197, UINT64_C(0xfffffffefffffc2f)); uint64_t x208; fiat_secp256k1_uint1 x209; fiat_secp256k1_subborrowx_u64(&x208, &x209, x207, x199, UINT64_C(0xffffffffffffffff)); uint64_t x210; fiat_secp256k1_uint1 x211; fiat_secp256k1_subborrowx_u64(&x210, &x211, x209, x201, UINT64_C(0xffffffffffffffff)); uint64_t x212; fiat_secp256k1_uint1 x213; fiat_secp256k1_subborrowx_u64(&x212, &x213, x211, x203, UINT64_C(0xffffffffffffffff)); uint64_t x214; fiat_secp256k1_uint1 x215; fiat_secp256k1_subborrowx_u64(&x214, &x215, x213, x205, 0x0); uint64_t x216; fiat_secp256k1_cmovznz_u64(&x216, x215, x206, x197); uint64_t x217; fiat_secp256k1_cmovznz_u64(&x217, x215, x208, x199); uint64_t x218; fiat_secp256k1_cmovznz_u64(&x218, x215, x210, x201); uint64_t x219; fiat_secp256k1_cmovznz_u64(&x219, x215, x212, x203); out1[0] = x216; out1[1] = x217; out1[2] = x218; out1[3] = x219; } /* * The function fiat_secp256k1_square squares a field element in the Montgomery domain. * Preconditions: * 0 ≤ eval arg1 < m * Postconditions: * eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) * eval (from_montgomery arg1)) mod m * 0 ≤ eval out1 < m * * Input Bounds: * arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * Output Bounds: * out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] */ static void fiat_secp256k1_square(uint64_t out1[4], const uint64_t arg1[4]) { uint64_t x1 = (arg1[1]); uint64_t x2 = (arg1[2]); uint64_t x3 = (arg1[3]); uint64_t x4 = (arg1[0]); uint64_t x5; uint64_t x6; fiat_secp256k1_mulx_u64(&x5, &x6, x4, (arg1[3])); uint64_t x7; uint64_t x8; fiat_secp256k1_mulx_u64(&x7, &x8, x4, (arg1[2])); uint64_t x9; uint64_t x10; fiat_secp256k1_mulx_u64(&x9, &x10, x4, (arg1[1])); uint64_t x11; uint64_t x12; fiat_secp256k1_mulx_u64(&x11, &x12, x4, (arg1[0])); uint64_t x13; fiat_secp256k1_uint1 x14; fiat_secp256k1_addcarryx_u64(&x13, &x14, 0x0, x12, x9); uint64_t x15; fiat_secp256k1_uint1 x16; fiat_secp256k1_addcarryx_u64(&x15, &x16, x14, x10, x7); uint64_t x17; fiat_secp256k1_uint1 x18; fiat_secp256k1_addcarryx_u64(&x17, &x18, x16, x8, x5); uint64_t x19 = (x18 + x6); uint64_t x20; uint64_t x21; fiat_secp256k1_mulx_u64(&x20, &x21, x11, UINT64_C(0xd838091dd2253531)); uint64_t x22; uint64_t x23; fiat_secp256k1_mulx_u64(&x22, &x23, x20, UINT64_C(0xffffffffffffffff)); uint64_t x24; uint64_t x25; fiat_secp256k1_mulx_u64(&x24, &x25, x20, UINT64_C(0xffffffffffffffff)); uint64_t x26; uint64_t x27; fiat_secp256k1_mulx_u64(&x26, &x27, x20, UINT64_C(0xffffffffffffffff)); uint64_t x28; uint64_t x29; fiat_secp256k1_mulx_u64(&x28, &x29, x20, UINT64_C(0xfffffffefffffc2f)); uint64_t x30; fiat_secp256k1_uint1 x31; fiat_secp256k1_addcarryx_u64(&x30, &x31, 0x0, x29, x26); uint64_t x32; fiat_secp256k1_uint1 x33; fiat_secp256k1_addcarryx_u64(&x32, &x33, x31, x27, x24); uint64_t x34; fiat_secp256k1_uint1 x35; fiat_secp256k1_addcarryx_u64(&x34, &x35, x33, x25, x22); uint64_t x36 = (x35 + x23); uint64_t x37; fiat_secp256k1_uint1 x38; fiat_secp256k1_addcarryx_u64(&x37, &x38, 0x0, x11, x28); uint64_t x39; fiat_secp256k1_uint1 x40; fiat_secp256k1_addcarryx_u64(&x39, &x40, x38, x13, x30); uint64_t x41; fiat_secp256k1_uint1 x42; fiat_secp256k1_addcarryx_u64(&x41, &x42, x40, x15, x32); uint64_t x43; fiat_secp256k1_uint1 x44; fiat_secp256k1_addcarryx_u64(&x43, &x44, x42, x17, x34); uint64_t x45; fiat_secp256k1_uint1 x46; fiat_secp256k1_addcarryx_u64(&x45, &x46, x44, x19, x36); uint64_t x47; uint64_t x48; fiat_secp256k1_mulx_u64(&x47, &x48, x1, (arg1[3])); uint64_t x49; uint64_t x50; fiat_secp256k1_mulx_u64(&x49, &x50, x1, (arg1[2])); uint64_t x51; uint64_t x52; fiat_secp256k1_mulx_u64(&x51, &x52, x1, (arg1[1])); uint64_t x53; uint64_t x54; fiat_secp256k1_mulx_u64(&x53, &x54, x1, (arg1[0])); uint64_t x55; fiat_secp256k1_uint1 x56; fiat_secp256k1_addcarryx_u64(&x55, &x56, 0x0, x54, x51); uint64_t x57; fiat_secp256k1_uint1 x58; fiat_secp256k1_addcarryx_u64(&x57, &x58, x56, x52, x49); uint64_t x59; fiat_secp256k1_uint1 x60; fiat_secp256k1_addcarryx_u64(&x59, &x60, x58, x50, x47); uint64_t x61 = (x60 + x48); uint64_t x62; fiat_secp256k1_uint1 x63; fiat_secp256k1_addcarryx_u64(&x62, &x63, 0x0, x39, x53); uint64_t x64; fiat_secp256k1_uint1 x65; fiat_secp256k1_addcarryx_u64(&x64, &x65, x63, x41, x55); uint64_t x66; fiat_secp256k1_uint1 x67; fiat_secp256k1_addcarryx_u64(&x66, &x67, x65, x43, x57); uint64_t x68; fiat_secp256k1_uint1 x69; fiat_secp256k1_addcarryx_u64(&x68, &x69, x67, x45, x59); uint64_t x70; fiat_secp256k1_uint1 x71; fiat_secp256k1_addcarryx_u64(&x70, &x71, x69, x46, x61); uint64_t x72; uint64_t x73; fiat_secp256k1_mulx_u64(&x72, &x73, x62, UINT64_C(0xd838091dd2253531)); uint64_t x74; uint64_t x75; fiat_secp256k1_mulx_u64(&x74, &x75, x72, UINT64_C(0xffffffffffffffff)); uint64_t x76; uint64_t x77; fiat_secp256k1_mulx_u64(&x76, &x77, x72, UINT64_C(0xffffffffffffffff)); uint64_t x78; uint64_t x79; fiat_secp256k1_mulx_u64(&x78, &x79, x72, UINT64_C(0xffffffffffffffff)); uint64_t x80; uint64_t x81; fiat_secp256k1_mulx_u64(&x80, &x81, x72, UINT64_C(0xfffffffefffffc2f)); uint64_t x82; fiat_secp256k1_uint1 x83; fiat_secp256k1_addcarryx_u64(&x82, &x83, 0x0, x81, x78); uint64_t x84; fiat_secp256k1_uint1 x85; fiat_secp256k1_addcarryx_u64(&x84, &x85, x83, x79, x76); uint64_t x86; fiat_secp256k1_uint1 x87; fiat_secp256k1_addcarryx_u64(&x86, &x87, x85, x77, x74); uint64_t x88 = (x87 + x75); uint64_t x89; fiat_secp256k1_uint1 x90; fiat_secp256k1_addcarryx_u64(&x89, &x90, 0x0, x62, x80); uint64_t x91; fiat_secp256k1_uint1 x92; fiat_secp256k1_addcarryx_u64(&x91, &x92, x90, x64, x82); uint64_t x93; fiat_secp256k1_uint1 x94; fiat_secp256k1_addcarryx_u64(&x93, &x94, x92, x66, x84); uint64_t x95; fiat_secp256k1_uint1 x96; fiat_secp256k1_addcarryx_u64(&x95, &x96, x94, x68, x86); uint64_t x97; fiat_secp256k1_uint1 x98; fiat_secp256k1_addcarryx_u64(&x97, &x98, x96, x70, x88); uint64_t x99 = ((uint64_t)x98 + x71); uint64_t x100; uint64_t x101; fiat_secp256k1_mulx_u64(&x100, &x101, x2, (arg1[3])); uint64_t x102; uint64_t x103; fiat_secp256k1_mulx_u64(&x102, &x103, x2, (arg1[2])); uint64_t x104; uint64_t x105; fiat_secp256k1_mulx_u64(&x104, &x105, x2, (arg1[1])); uint64_t x106; uint64_t x107; fiat_secp256k1_mulx_u64(&x106, &x107, x2, (arg1[0])); uint64_t x108; fiat_secp256k1_uint1 x109; fiat_secp256k1_addcarryx_u64(&x108, &x109, 0x0, x107, x104); uint64_t x110; fiat_secp256k1_uint1 x111; fiat_secp256k1_addcarryx_u64(&x110, &x111, x109, x105, x102); uint64_t x112; fiat_secp256k1_uint1 x113; fiat_secp256k1_addcarryx_u64(&x112, &x113, x111, x103, x100); uint64_t x114 = (x113 + x101); uint64_t x115; fiat_secp256k1_uint1 x116; fiat_secp256k1_addcarryx_u64(&x115, &x116, 0x0, x91, x106); uint64_t x117; fiat_secp256k1_uint1 x118; fiat_secp256k1_addcarryx_u64(&x117, &x118, x116, x93, x108); uint64_t x119; fiat_secp256k1_uint1 x120; fiat_secp256k1_addcarryx_u64(&x119, &x120, x118, x95, x110); uint64_t x121; fiat_secp256k1_uint1 x122; fiat_secp256k1_addcarryx_u64(&x121, &x122, x120, x97, x112); uint64_t x123; fiat_secp256k1_uint1 x124; fiat_secp256k1_addcarryx_u64(&x123, &x124, x122, x99, x114); uint64_t x125; uint64_t x126; fiat_secp256k1_mulx_u64(&x125, &x126, x115, UINT64_C(0xd838091dd2253531)); uint64_t x127; uint64_t x128; fiat_secp256k1_mulx_u64(&x127, &x128, x125, UINT64_C(0xffffffffffffffff)); uint64_t x129; uint64_t x130; fiat_secp256k1_mulx_u64(&x129, &x130, x125, UINT64_C(0xffffffffffffffff)); uint64_t x131; uint64_t x132; fiat_secp256k1_mulx_u64(&x131, &x132, x125, UINT64_C(0xffffffffffffffff)); uint64_t x133; uint64_t x134; fiat_secp256k1_mulx_u64(&x133, &x134, x125, UINT64_C(0xfffffffefffffc2f)); uint64_t x135; fiat_secp256k1_uint1 x136; fiat_secp256k1_addcarryx_u64(&x135, &x136, 0x0, x134, x131); uint64_t x137; fiat_secp256k1_uint1 x138; fiat_secp256k1_addcarryx_u64(&x137, &x138, x136, x132, x129); uint64_t x139; fiat_secp256k1_uint1 x140; fiat_secp256k1_addcarryx_u64(&x139, &x140, x138, x130, x127); uint64_t x141 = (x140 + x128); uint64_t x142; fiat_secp256k1_uint1 x143; fiat_secp256k1_addcarryx_u64(&x142, &x143, 0x0, x115, x133); uint64_t x144; fiat_secp256k1_uint1 x145; fiat_secp256k1_addcarryx_u64(&x144, &x145, x143, x117, x135); uint64_t x146; fiat_secp256k1_uint1 x147; fiat_secp256k1_addcarryx_u64(&x146, &x147, x145, x119, x137); uint64_t x148; fiat_secp256k1_uint1 x149; fiat_secp256k1_addcarryx_u64(&x148, &x149, x147, x121, x139); uint64_t x150; fiat_secp256k1_uint1 x151; fiat_secp256k1_addcarryx_u64(&x150, &x151, x149, x123, x141); uint64_t x152 = ((uint64_t)x151 + x124); uint64_t x153; uint64_t x154; fiat_secp256k1_mulx_u64(&x153, &x154, x3, (arg1[3])); uint64_t x155; uint64_t x156; fiat_secp256k1_mulx_u64(&x155, &x156, x3, (arg1[2])); uint64_t x157; uint64_t x158; fiat_secp256k1_mulx_u64(&x157, &x158, x3, (arg1[1])); uint64_t x159; uint64_t x160; fiat_secp256k1_mulx_u64(&x159, &x160, x3, (arg1[0])); uint64_t x161; fiat_secp256k1_uint1 x162; fiat_secp256k1_addcarryx_u64(&x161, &x162, 0x0, x160, x157); uint64_t x163; fiat_secp256k1_uint1 x164; fiat_secp256k1_addcarryx_u64(&x163, &x164, x162, x158, x155); uint64_t x165; fiat_secp256k1_uint1 x166; fiat_secp256k1_addcarryx_u64(&x165, &x166, x164, x156, x153); uint64_t x167 = (x166 + x154); uint64_t x168; fiat_secp256k1_uint1 x169; fiat_secp256k1_addcarryx_u64(&x168, &x169, 0x0, x144, x159); uint64_t x170; fiat_secp256k1_uint1 x171; fiat_secp256k1_addcarryx_u64(&x170, &x171, x169, x146, x161); uint64_t x172; fiat_secp256k1_uint1 x173; fiat_secp256k1_addcarryx_u64(&x172, &x173, x171, x148, x163); uint64_t x174; fiat_secp256k1_uint1 x175; fiat_secp256k1_addcarryx_u64(&x174, &x175, x173, x150, x165); uint64_t x176; fiat_secp256k1_uint1 x177; fiat_secp256k1_addcarryx_u64(&x176, &x177, x175, x152, x167); uint64_t x178; uint64_t x179; fiat_secp256k1_mulx_u64(&x178, &x179, x168, UINT64_C(0xd838091dd2253531)); uint64_t x180; uint64_t x181; fiat_secp256k1_mulx_u64(&x180, &x181, x178, UINT64_C(0xffffffffffffffff)); uint64_t x182; uint64_t x183; fiat_secp256k1_mulx_u64(&x182, &x183, x178, UINT64_C(0xffffffffffffffff)); uint64_t x184; uint64_t x185; fiat_secp256k1_mulx_u64(&x184, &x185, x178, UINT64_C(0xffffffffffffffff)); uint64_t x186; uint64_t x187; fiat_secp256k1_mulx_u64(&x186, &x187, x178, UINT64_C(0xfffffffefffffc2f)); uint64_t x188; fiat_secp256k1_uint1 x189; fiat_secp256k1_addcarryx_u64(&x188, &x189, 0x0, x187, x184); uint64_t x190; fiat_secp256k1_uint1 x191; fiat_secp256k1_addcarryx_u64(&x190, &x191, x189, x185, x182); uint64_t x192; fiat_secp256k1_uint1 x193; fiat_secp256k1_addcarryx_u64(&x192, &x193, x191, x183, x180); uint64_t x194 = (x193 + x181); uint64_t x195; fiat_secp256k1_uint1 x196; fiat_secp256k1_addcarryx_u64(&x195, &x196, 0x0, x168, x186); uint64_t x197; fiat_secp256k1_uint1 x198; fiat_secp256k1_addcarryx_u64(&x197, &x198, x196, x170, x188); uint64_t x199; fiat_secp256k1_uint1 x200; fiat_secp256k1_addcarryx_u64(&x199, &x200, x198, x172, x190); uint64_t x201; fiat_secp256k1_uint1 x202; fiat_secp256k1_addcarryx_u64(&x201, &x202, x200, x174, x192); uint64_t x203; fiat_secp256k1_uint1 x204; fiat_secp256k1_addcarryx_u64(&x203, &x204, x202, x176, x194); uint64_t x205 = ((uint64_t)x204 + x177); uint64_t x206; fiat_secp256k1_uint1 x207; fiat_secp256k1_subborrowx_u64(&x206, &x207, 0x0, x197, UINT64_C(0xfffffffefffffc2f)); uint64_t x208; fiat_secp256k1_uint1 x209; fiat_secp256k1_subborrowx_u64(&x208, &x209, x207, x199, UINT64_C(0xffffffffffffffff)); uint64_t x210; fiat_secp256k1_uint1 x211; fiat_secp256k1_subborrowx_u64(&x210, &x211, x209, x201, UINT64_C(0xffffffffffffffff)); uint64_t x212; fiat_secp256k1_uint1 x213; fiat_secp256k1_subborrowx_u64(&x212, &x213, x211, x203, UINT64_C(0xffffffffffffffff)); uint64_t x214; fiat_secp256k1_uint1 x215; fiat_secp256k1_subborrowx_u64(&x214, &x215, x213, x205, 0x0); uint64_t x216; fiat_secp256k1_cmovznz_u64(&x216, x215, x206, x197); uint64_t x217; fiat_secp256k1_cmovznz_u64(&x217, x215, x208, x199); uint64_t x218; fiat_secp256k1_cmovznz_u64(&x218, x215, x210, x201); uint64_t x219; fiat_secp256k1_cmovznz_u64(&x219, x215, x212, x203); out1[0] = x216; out1[1] = x217; out1[2] = x218; out1[3] = x219; } /* * The function fiat_secp256k1_add adds two field elements in the Montgomery domain. * Preconditions: * 0 ≤ eval arg1 < m * 0 ≤ eval arg2 < m * Postconditions: * eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) + eval (from_montgomery arg2)) mod m * 0 ≤ eval out1 < m * * Input Bounds: * arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * arg2: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * Output Bounds: * out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] */ static void fiat_secp256k1_add(uint64_t out1[4], const uint64_t arg1[4], const uint64_t arg2[4]) { uint64_t x1; fiat_secp256k1_uint1 x2; fiat_secp256k1_addcarryx_u64(&x1, &x2, 0x0, (arg1[0]), (arg2[0])); uint64_t x3; fiat_secp256k1_uint1 x4; fiat_secp256k1_addcarryx_u64(&x3, &x4, x2, (arg1[1]), (arg2[1])); uint64_t x5; fiat_secp256k1_uint1 x6; fiat_secp256k1_addcarryx_u64(&x5, &x6, x4, (arg1[2]), (arg2[2])); uint64_t x7; fiat_secp256k1_uint1 x8; fiat_secp256k1_addcarryx_u64(&x7, &x8, x6, (arg1[3]), (arg2[3])); uint64_t x9; fiat_secp256k1_uint1 x10; fiat_secp256k1_subborrowx_u64(&x9, &x10, 0x0, x1, UINT64_C(0xfffffffefffffc2f)); uint64_t x11; fiat_secp256k1_uint1 x12; fiat_secp256k1_subborrowx_u64(&x11, &x12, x10, x3, UINT64_C(0xffffffffffffffff)); uint64_t x13; fiat_secp256k1_uint1 x14; fiat_secp256k1_subborrowx_u64(&x13, &x14, x12, x5, UINT64_C(0xffffffffffffffff)); uint64_t x15; fiat_secp256k1_uint1 x16; fiat_secp256k1_subborrowx_u64(&x15, &x16, x14, x7, UINT64_C(0xffffffffffffffff)); uint64_t x17; fiat_secp256k1_uint1 x18; fiat_secp256k1_subborrowx_u64(&x17, &x18, x16, x8, 0x0); uint64_t x19; fiat_secp256k1_cmovznz_u64(&x19, x18, x9, x1); uint64_t x20; fiat_secp256k1_cmovznz_u64(&x20, x18, x11, x3); uint64_t x21; fiat_secp256k1_cmovznz_u64(&x21, x18, x13, x5); uint64_t x22; fiat_secp256k1_cmovznz_u64(&x22, x18, x15, x7); out1[0] = x19; out1[1] = x20; out1[2] = x21; out1[3] = x22; } /* * The function fiat_secp256k1_sub subtracts two field elements in the Montgomery domain. * Preconditions: * 0 ≤ eval arg1 < m * 0 ≤ eval arg2 < m * Postconditions: * eval (from_montgomery out1) mod m = (eval (from_montgomery arg1) - eval (from_montgomery arg2)) mod m * 0 ≤ eval out1 < m * * Input Bounds: * arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * arg2: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * Output Bounds: * out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] */ static void fiat_secp256k1_sub(uint64_t out1[4], const uint64_t arg1[4], const uint64_t arg2[4]) { uint64_t x1; fiat_secp256k1_uint1 x2; fiat_secp256k1_subborrowx_u64(&x1, &x2, 0x0, (arg1[0]), (arg2[0])); uint64_t x3; fiat_secp256k1_uint1 x4; fiat_secp256k1_subborrowx_u64(&x3, &x4, x2, (arg1[1]), (arg2[1])); uint64_t x5; fiat_secp256k1_uint1 x6; fiat_secp256k1_subborrowx_u64(&x5, &x6, x4, (arg1[2]), (arg2[2])); uint64_t x7; fiat_secp256k1_uint1 x8; fiat_secp256k1_subborrowx_u64(&x7, &x8, x6, (arg1[3]), (arg2[3])); uint64_t x9; fiat_secp256k1_cmovznz_u64(&x9, x8, 0x0, UINT64_C(0xffffffffffffffff)); uint64_t x10; fiat_secp256k1_uint1 x11; fiat_secp256k1_addcarryx_u64(&x10, &x11, 0x0, x1, (x9 & UINT64_C(0xfffffffefffffc2f))); uint64_t x12; fiat_secp256k1_uint1 x13; fiat_secp256k1_addcarryx_u64(&x12, &x13, x11, x3, (x9 & UINT64_C(0xffffffffffffffff))); uint64_t x14; fiat_secp256k1_uint1 x15; fiat_secp256k1_addcarryx_u64(&x14, &x15, x13, x5, (x9 & UINT64_C(0xffffffffffffffff))); uint64_t x16; fiat_secp256k1_uint1 x17; fiat_secp256k1_addcarryx_u64(&x16, &x17, x15, x7, (x9 & UINT64_C(0xffffffffffffffff))); out1[0] = x10; out1[1] = x12; out1[2] = x14; out1[3] = x16; } /* * The function fiat_secp256k1_opp negates a field element in the Montgomery domain. * Preconditions: * 0 ≤ eval arg1 < m * Postconditions: * eval (from_montgomery out1) mod m = -eval (from_montgomery arg1) mod m * 0 ≤ eval out1 < m * * Input Bounds: * arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * Output Bounds: * out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] */ static void fiat_secp256k1_opp(uint64_t out1[4], const uint64_t arg1[4]) { uint64_t x1; fiat_secp256k1_uint1 x2; fiat_secp256k1_subborrowx_u64(&x1, &x2, 0x0, 0x0, (arg1[0])); uint64_t x3; fiat_secp256k1_uint1 x4; fiat_secp256k1_subborrowx_u64(&x3, &x4, x2, 0x0, (arg1[1])); uint64_t x5; fiat_secp256k1_uint1 x6; fiat_secp256k1_subborrowx_u64(&x5, &x6, x4, 0x0, (arg1[2])); uint64_t x7; fiat_secp256k1_uint1 x8; fiat_secp256k1_subborrowx_u64(&x7, &x8, x6, 0x0, (arg1[3])); uint64_t x9; fiat_secp256k1_cmovznz_u64(&x9, x8, 0x0, UINT64_C(0xffffffffffffffff)); uint64_t x10; fiat_secp256k1_uint1 x11; fiat_secp256k1_addcarryx_u64(&x10, &x11, 0x0, x1, (x9 & UINT64_C(0xfffffffefffffc2f))); uint64_t x12; fiat_secp256k1_uint1 x13; fiat_secp256k1_addcarryx_u64(&x12, &x13, x11, x3, (x9 & UINT64_C(0xffffffffffffffff))); uint64_t x14; fiat_secp256k1_uint1 x15; fiat_secp256k1_addcarryx_u64(&x14, &x15, x13, x5, (x9 & UINT64_C(0xffffffffffffffff))); uint64_t x16; fiat_secp256k1_uint1 x17; fiat_secp256k1_addcarryx_u64(&x16, &x17, x15, x7, (x9 & UINT64_C(0xffffffffffffffff))); out1[0] = x10; out1[1] = x12; out1[2] = x14; out1[3] = x16; } /* * The function fiat_secp256k1_from_montgomery translates a field element out of the Montgomery domain. * Preconditions: * 0 ≤ eval arg1 < m * Postconditions: * eval out1 mod m = (eval arg1 * ((2^64)⁻¹ mod m)^4) mod m * 0 ≤ eval out1 < m * * Input Bounds: * arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * Output Bounds: * out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] */ static void fiat_secp256k1_from_montgomery(uint64_t out1[4], const uint64_t arg1[4]) { uint64_t x1 = (arg1[0]); uint64_t x2; uint64_t x3; fiat_secp256k1_mulx_u64(&x2, &x3, x1, UINT64_C(0xd838091dd2253531)); uint64_t x4; uint64_t x5; fiat_secp256k1_mulx_u64(&x4, &x5, x2, UINT64_C(0xffffffffffffffff)); uint64_t x6; uint64_t x7; fiat_secp256k1_mulx_u64(&x6, &x7, x2, UINT64_C(0xffffffffffffffff)); uint64_t x8; uint64_t x9; fiat_secp256k1_mulx_u64(&x8, &x9, x2, UINT64_C(0xffffffffffffffff)); uint64_t x10; uint64_t x11; fiat_secp256k1_mulx_u64(&x10, &x11, x2, UINT64_C(0xfffffffefffffc2f)); uint64_t x12; fiat_secp256k1_uint1 x13; fiat_secp256k1_addcarryx_u64(&x12, &x13, 0x0, x11, x8); uint64_t x14; fiat_secp256k1_uint1 x15; fiat_secp256k1_addcarryx_u64(&x14, &x15, x13, x9, x6); uint64_t x16; fiat_secp256k1_uint1 x17; fiat_secp256k1_addcarryx_u64(&x16, &x17, x15, x7, x4); uint64_t x18; fiat_secp256k1_uint1 x19; fiat_secp256k1_addcarryx_u64(&x18, &x19, 0x0, x1, x10); uint64_t x20; fiat_secp256k1_uint1 x21; fiat_secp256k1_addcarryx_u64(&x20, &x21, x19, 0x0, x12); uint64_t x22; fiat_secp256k1_uint1 x23; fiat_secp256k1_addcarryx_u64(&x22, &x23, x21, 0x0, x14); uint64_t x24; fiat_secp256k1_uint1 x25; fiat_secp256k1_addcarryx_u64(&x24, &x25, x23, 0x0, x16); uint64_t x26; fiat_secp256k1_uint1 x27; fiat_secp256k1_addcarryx_u64(&x26, &x27, x25, 0x0, (x17 + x5)); uint64_t x28; fiat_secp256k1_uint1 x29; fiat_secp256k1_addcarryx_u64(&x28, &x29, 0x0, x20, (arg1[1])); uint64_t x30; fiat_secp256k1_uint1 x31; fiat_secp256k1_addcarryx_u64(&x30, &x31, x29, x22, 0x0); uint64_t x32; fiat_secp256k1_uint1 x33; fiat_secp256k1_addcarryx_u64(&x32, &x33, x31, x24, 0x0); uint64_t x34; fiat_secp256k1_uint1 x35; fiat_secp256k1_addcarryx_u64(&x34, &x35, x33, x26, 0x0); uint64_t x36; uint64_t x37; fiat_secp256k1_mulx_u64(&x36, &x37, x28, UINT64_C(0xd838091dd2253531)); uint64_t x38; uint64_t x39; fiat_secp256k1_mulx_u64(&x38, &x39, x36, UINT64_C(0xffffffffffffffff)); uint64_t x40; uint64_t x41; fiat_secp256k1_mulx_u64(&x40, &x41, x36, UINT64_C(0xffffffffffffffff)); uint64_t x42; uint64_t x43; fiat_secp256k1_mulx_u64(&x42, &x43, x36, UINT64_C(0xffffffffffffffff)); uint64_t x44; uint64_t x45; fiat_secp256k1_mulx_u64(&x44, &x45, x36, UINT64_C(0xfffffffefffffc2f)); uint64_t x46; fiat_secp256k1_uint1 x47; fiat_secp256k1_addcarryx_u64(&x46, &x47, 0x0, x45, x42); uint64_t x48; fiat_secp256k1_uint1 x49; fiat_secp256k1_addcarryx_u64(&x48, &x49, x47, x43, x40); uint64_t x50; fiat_secp256k1_uint1 x51; fiat_secp256k1_addcarryx_u64(&x50, &x51, x49, x41, x38); uint64_t x52; fiat_secp256k1_uint1 x53; fiat_secp256k1_addcarryx_u64(&x52, &x53, 0x0, x28, x44); uint64_t x54; fiat_secp256k1_uint1 x55; fiat_secp256k1_addcarryx_u64(&x54, &x55, x53, x30, x46); uint64_t x56; fiat_secp256k1_uint1 x57; fiat_secp256k1_addcarryx_u64(&x56, &x57, x55, x32, x48); uint64_t x58; fiat_secp256k1_uint1 x59; fiat_secp256k1_addcarryx_u64(&x58, &x59, x57, x34, x50); uint64_t x60; fiat_secp256k1_uint1 x61; fiat_secp256k1_addcarryx_u64(&x60, &x61, x59, ((uint64_t)x35 + x27), (x51 + x39)); uint64_t x62; fiat_secp256k1_uint1 x63; fiat_secp256k1_addcarryx_u64(&x62, &x63, 0x0, x54, (arg1[2])); uint64_t x64; fiat_secp256k1_uint1 x65; fiat_secp256k1_addcarryx_u64(&x64, &x65, x63, x56, 0x0); uint64_t x66; fiat_secp256k1_uint1 x67; fiat_secp256k1_addcarryx_u64(&x66, &x67, x65, x58, 0x0); uint64_t x68; fiat_secp256k1_uint1 x69; fiat_secp256k1_addcarryx_u64(&x68, &x69, x67, x60, 0x0); uint64_t x70; uint64_t x71; fiat_secp256k1_mulx_u64(&x70, &x71, x62, UINT64_C(0xd838091dd2253531)); uint64_t x72; uint64_t x73; fiat_secp256k1_mulx_u64(&x72, &x73, x70, UINT64_C(0xffffffffffffffff)); uint64_t x74; uint64_t x75; fiat_secp256k1_mulx_u64(&x74, &x75, x70, UINT64_C(0xffffffffffffffff)); uint64_t x76; uint64_t x77; fiat_secp256k1_mulx_u64(&x76, &x77, x70, UINT64_C(0xffffffffffffffff)); uint64_t x78; uint64_t x79; fiat_secp256k1_mulx_u64(&x78, &x79, x70, UINT64_C(0xfffffffefffffc2f)); uint64_t x80; fiat_secp256k1_uint1 x81; fiat_secp256k1_addcarryx_u64(&x80, &x81, 0x0, x79, x76); uint64_t x82; fiat_secp256k1_uint1 x83; fiat_secp256k1_addcarryx_u64(&x82, &x83, x81, x77, x74); uint64_t x84; fiat_secp256k1_uint1 x85; fiat_secp256k1_addcarryx_u64(&x84, &x85, x83, x75, x72); uint64_t x86; fiat_secp256k1_uint1 x87; fiat_secp256k1_addcarryx_u64(&x86, &x87, 0x0, x62, x78); uint64_t x88; fiat_secp256k1_uint1 x89; fiat_secp256k1_addcarryx_u64(&x88, &x89, x87, x64, x80); uint64_t x90; fiat_secp256k1_uint1 x91; fiat_secp256k1_addcarryx_u64(&x90, &x91, x89, x66, x82); uint64_t x92; fiat_secp256k1_uint1 x93; fiat_secp256k1_addcarryx_u64(&x92, &x93, x91, x68, x84); uint64_t x94; fiat_secp256k1_uint1 x95; fiat_secp256k1_addcarryx_u64(&x94, &x95, x93, ((uint64_t)x69 + x61), (x85 + x73)); uint64_t x96; fiat_secp256k1_uint1 x97; fiat_secp256k1_addcarryx_u64(&x96, &x97, 0x0, x88, (arg1[3])); uint64_t x98; fiat_secp256k1_uint1 x99; fiat_secp256k1_addcarryx_u64(&x98, &x99, x97, x90, 0x0); uint64_t x100; fiat_secp256k1_uint1 x101; fiat_secp256k1_addcarryx_u64(&x100, &x101, x99, x92, 0x0); uint64_t x102; fiat_secp256k1_uint1 x103; fiat_secp256k1_addcarryx_u64(&x102, &x103, x101, x94, 0x0); uint64_t x104; uint64_t x105; fiat_secp256k1_mulx_u64(&x104, &x105, x96, UINT64_C(0xd838091dd2253531)); uint64_t x106; uint64_t x107; fiat_secp256k1_mulx_u64(&x106, &x107, x104, UINT64_C(0xffffffffffffffff)); uint64_t x108; uint64_t x109; fiat_secp256k1_mulx_u64(&x108, &x109, x104, UINT64_C(0xffffffffffffffff)); uint64_t x110; uint64_t x111; fiat_secp256k1_mulx_u64(&x110, &x111, x104, UINT64_C(0xffffffffffffffff)); uint64_t x112; uint64_t x113; fiat_secp256k1_mulx_u64(&x112, &x113, x104, UINT64_C(0xfffffffefffffc2f)); uint64_t x114; fiat_secp256k1_uint1 x115; fiat_secp256k1_addcarryx_u64(&x114, &x115, 0x0, x113, x110); uint64_t x116; fiat_secp256k1_uint1 x117; fiat_secp256k1_addcarryx_u64(&x116, &x117, x115, x111, x108); uint64_t x118; fiat_secp256k1_uint1 x119; fiat_secp256k1_addcarryx_u64(&x118, &x119, x117, x109, x106); uint64_t x120; fiat_secp256k1_uint1 x121; fiat_secp256k1_addcarryx_u64(&x120, &x121, 0x0, x96, x112); uint64_t x122; fiat_secp256k1_uint1 x123; fiat_secp256k1_addcarryx_u64(&x122, &x123, x121, x98, x114); uint64_t x124; fiat_secp256k1_uint1 x125; fiat_secp256k1_addcarryx_u64(&x124, &x125, x123, x100, x116); uint64_t x126; fiat_secp256k1_uint1 x127; fiat_secp256k1_addcarryx_u64(&x126, &x127, x125, x102, x118); uint64_t x128; fiat_secp256k1_uint1 x129; fiat_secp256k1_addcarryx_u64(&x128, &x129, x127, ((uint64_t)x103 + x95), (x119 + x107)); uint64_t x130; fiat_secp256k1_uint1 x131; fiat_secp256k1_subborrowx_u64(&x130, &x131, 0x0, x122, UINT64_C(0xfffffffefffffc2f)); uint64_t x132; fiat_secp256k1_uint1 x133; fiat_secp256k1_subborrowx_u64(&x132, &x133, x131, x124, UINT64_C(0xffffffffffffffff)); uint64_t x134; fiat_secp256k1_uint1 x135; fiat_secp256k1_subborrowx_u64(&x134, &x135, x133, x126, UINT64_C(0xffffffffffffffff)); uint64_t x136; fiat_secp256k1_uint1 x137; fiat_secp256k1_subborrowx_u64(&x136, &x137, x135, x128, UINT64_C(0xffffffffffffffff)); uint64_t x138; fiat_secp256k1_uint1 x139; fiat_secp256k1_subborrowx_u64(&x138, &x139, x137, x129, 0x0); uint64_t x140; fiat_secp256k1_cmovznz_u64(&x140, x139, x130, x122); uint64_t x141; fiat_secp256k1_cmovznz_u64(&x141, x139, x132, x124); uint64_t x142; fiat_secp256k1_cmovznz_u64(&x142, x139, x134, x126); uint64_t x143; fiat_secp256k1_cmovznz_u64(&x143, x139, x136, x128); out1[0] = x140; out1[1] = x141; out1[2] = x142; out1[3] = x143; } /* * The function fiat_secp256k1_to_montgomery translates a field element into the Montgomery domain. * Preconditions: * 0 ≤ eval arg1 < m * Postconditions: * eval (from_montgomery out1) mod m = eval arg1 mod m * 0 ≤ eval out1 < m * * Input Bounds: * arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * Output Bounds: * out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] */ static void fiat_secp256k1_to_montgomery(uint64_t out1[4], const uint64_t arg1[4]) { uint64_t x1 = (arg1[1]); uint64_t x2 = (arg1[2]); uint64_t x3 = (arg1[3]); uint64_t x4 = (arg1[0]); uint64_t x5; uint64_t x6; fiat_secp256k1_mulx_u64(&x5, &x6, x4, UINT64_C(0x7a2000e90a1)); uint64_t x7; fiat_secp256k1_uint1 x8; fiat_secp256k1_addcarryx_u64(&x7, &x8, 0x0, x6, x4); uint64_t x9; uint64_t x10; fiat_secp256k1_mulx_u64(&x9, &x10, x5, UINT64_C(0xd838091dd2253531)); uint64_t x11; uint64_t x12; fiat_secp256k1_mulx_u64(&x11, &x12, x9, UINT64_C(0xffffffffffffffff)); uint64_t x13; uint64_t x14; fiat_secp256k1_mulx_u64(&x13, &x14, x9, UINT64_C(0xffffffffffffffff)); uint64_t x15; uint64_t x16; fiat_secp256k1_mulx_u64(&x15, &x16, x9, UINT64_C(0xffffffffffffffff)); uint64_t x17; uint64_t x18; fiat_secp256k1_mulx_u64(&x17, &x18, x9, UINT64_C(0xfffffffefffffc2f)); uint64_t x19; fiat_secp256k1_uint1 x20; fiat_secp256k1_addcarryx_u64(&x19, &x20, 0x0, x18, x15); uint64_t x21; fiat_secp256k1_uint1 x22; fiat_secp256k1_addcarryx_u64(&x21, &x22, x20, x16, x13); uint64_t x23; fiat_secp256k1_uint1 x24; fiat_secp256k1_addcarryx_u64(&x23, &x24, x22, x14, x11); uint64_t x25; fiat_secp256k1_uint1 x26; fiat_secp256k1_addcarryx_u64(&x25, &x26, 0x0, x5, x17); uint64_t x27; fiat_secp256k1_uint1 x28; fiat_secp256k1_addcarryx_u64(&x27, &x28, x26, x7, x19); uint64_t x29; fiat_secp256k1_uint1 x30; fiat_secp256k1_addcarryx_u64(&x29, &x30, x28, x8, x21); uint64_t x31; fiat_secp256k1_uint1 x32; fiat_secp256k1_addcarryx_u64(&x31, &x32, x30, 0x0, x23); uint64_t x33; fiat_secp256k1_uint1 x34; fiat_secp256k1_addcarryx_u64(&x33, &x34, x32, 0x0, (x24 + x12)); uint64_t x35; uint64_t x36; fiat_secp256k1_mulx_u64(&x35, &x36, x1, UINT64_C(0x7a2000e90a1)); uint64_t x37; fiat_secp256k1_uint1 x38; fiat_secp256k1_addcarryx_u64(&x37, &x38, 0x0, x36, x1); uint64_t x39; fiat_secp256k1_uint1 x40; fiat_secp256k1_addcarryx_u64(&x39, &x40, 0x0, x27, x35); uint64_t x41; fiat_secp256k1_uint1 x42; fiat_secp256k1_addcarryx_u64(&x41, &x42, x40, x29, x37); uint64_t x43; fiat_secp256k1_uint1 x44; fiat_secp256k1_addcarryx_u64(&x43, &x44, x42, x31, x38); uint64_t x45; fiat_secp256k1_uint1 x46; fiat_secp256k1_addcarryx_u64(&x45, &x46, x44, x33, 0x0); uint64_t x47; uint64_t x48; fiat_secp256k1_mulx_u64(&x47, &x48, x39, UINT64_C(0xd838091dd2253531)); uint64_t x49; uint64_t x50; fiat_secp256k1_mulx_u64(&x49, &x50, x47, UINT64_C(0xffffffffffffffff)); uint64_t x51; uint64_t x52; fiat_secp256k1_mulx_u64(&x51, &x52, x47, UINT64_C(0xffffffffffffffff)); uint64_t x53; uint64_t x54; fiat_secp256k1_mulx_u64(&x53, &x54, x47, UINT64_C(0xffffffffffffffff)); uint64_t x55; uint64_t x56; fiat_secp256k1_mulx_u64(&x55, &x56, x47, UINT64_C(0xfffffffefffffc2f)); uint64_t x57; fiat_secp256k1_uint1 x58; fiat_secp256k1_addcarryx_u64(&x57, &x58, 0x0, x56, x53); uint64_t x59; fiat_secp256k1_uint1 x60; fiat_secp256k1_addcarryx_u64(&x59, &x60, x58, x54, x51); uint64_t x61; fiat_secp256k1_uint1 x62; fiat_secp256k1_addcarryx_u64(&x61, &x62, x60, x52, x49); uint64_t x63; fiat_secp256k1_uint1 x64; fiat_secp256k1_addcarryx_u64(&x63, &x64, 0x0, x39, x55); uint64_t x65; fiat_secp256k1_uint1 x66; fiat_secp256k1_addcarryx_u64(&x65, &x66, x64, x41, x57); uint64_t x67; fiat_secp256k1_uint1 x68; fiat_secp256k1_addcarryx_u64(&x67, &x68, x66, x43, x59); uint64_t x69; fiat_secp256k1_uint1 x70; fiat_secp256k1_addcarryx_u64(&x69, &x70, x68, x45, x61); uint64_t x71; fiat_secp256k1_uint1 x72; fiat_secp256k1_addcarryx_u64(&x71, &x72, x70, ((uint64_t)x46 + x34), (x62 + x50)); uint64_t x73; uint64_t x74; fiat_secp256k1_mulx_u64(&x73, &x74, x2, UINT64_C(0x7a2000e90a1)); uint64_t x75; fiat_secp256k1_uint1 x76; fiat_secp256k1_addcarryx_u64(&x75, &x76, 0x0, x74, x2); uint64_t x77; fiat_secp256k1_uint1 x78; fiat_secp256k1_addcarryx_u64(&x77, &x78, 0x0, x65, x73); uint64_t x79; fiat_secp256k1_uint1 x80; fiat_secp256k1_addcarryx_u64(&x79, &x80, x78, x67, x75); uint64_t x81; fiat_secp256k1_uint1 x82; fiat_secp256k1_addcarryx_u64(&x81, &x82, x80, x69, x76); uint64_t x83; fiat_secp256k1_uint1 x84; fiat_secp256k1_addcarryx_u64(&x83, &x84, x82, x71, 0x0); uint64_t x85; uint64_t x86; fiat_secp256k1_mulx_u64(&x85, &x86, x77, UINT64_C(0xd838091dd2253531)); uint64_t x87; uint64_t x88; fiat_secp256k1_mulx_u64(&x87, &x88, x85, UINT64_C(0xffffffffffffffff)); uint64_t x89; uint64_t x90; fiat_secp256k1_mulx_u64(&x89, &x90, x85, UINT64_C(0xffffffffffffffff)); uint64_t x91; uint64_t x92; fiat_secp256k1_mulx_u64(&x91, &x92, x85, UINT64_C(0xffffffffffffffff)); uint64_t x93; uint64_t x94; fiat_secp256k1_mulx_u64(&x93, &x94, x85, UINT64_C(0xfffffffefffffc2f)); uint64_t x95; fiat_secp256k1_uint1 x96; fiat_secp256k1_addcarryx_u64(&x95, &x96, 0x0, x94, x91); uint64_t x97; fiat_secp256k1_uint1 x98; fiat_secp256k1_addcarryx_u64(&x97, &x98, x96, x92, x89); uint64_t x99; fiat_secp256k1_uint1 x100; fiat_secp256k1_addcarryx_u64(&x99, &x100, x98, x90, x87); uint64_t x101; fiat_secp256k1_uint1 x102; fiat_secp256k1_addcarryx_u64(&x101, &x102, 0x0, x77, x93); uint64_t x103; fiat_secp256k1_uint1 x104; fiat_secp256k1_addcarryx_u64(&x103, &x104, x102, x79, x95); uint64_t x105; fiat_secp256k1_uint1 x106; fiat_secp256k1_addcarryx_u64(&x105, &x106, x104, x81, x97); uint64_t x107; fiat_secp256k1_uint1 x108; fiat_secp256k1_addcarryx_u64(&x107, &x108, x106, x83, x99); uint64_t x109; fiat_secp256k1_uint1 x110; fiat_secp256k1_addcarryx_u64(&x109, &x110, x108, ((uint64_t)x84 + x72), (x100 + x88)); uint64_t x111; uint64_t x112; fiat_secp256k1_mulx_u64(&x111, &x112, x3, UINT64_C(0x7a2000e90a1)); uint64_t x113; fiat_secp256k1_uint1 x114; fiat_secp256k1_addcarryx_u64(&x113, &x114, 0x0, x112, x3); uint64_t x115; fiat_secp256k1_uint1 x116; fiat_secp256k1_addcarryx_u64(&x115, &x116, 0x0, x103, x111); uint64_t x117; fiat_secp256k1_uint1 x118; fiat_secp256k1_addcarryx_u64(&x117, &x118, x116, x105, x113); uint64_t x119; fiat_secp256k1_uint1 x120; fiat_secp256k1_addcarryx_u64(&x119, &x120, x118, x107, x114); uint64_t x121; fiat_secp256k1_uint1 x122; fiat_secp256k1_addcarryx_u64(&x121, &x122, x120, x109, 0x0); uint64_t x123; uint64_t x124; fiat_secp256k1_mulx_u64(&x123, &x124, x115, UINT64_C(0xd838091dd2253531)); uint64_t x125; uint64_t x126; fiat_secp256k1_mulx_u64(&x125, &x126, x123, UINT64_C(0xffffffffffffffff)); uint64_t x127; uint64_t x128; fiat_secp256k1_mulx_u64(&x127, &x128, x123, UINT64_C(0xffffffffffffffff)); uint64_t x129; uint64_t x130; fiat_secp256k1_mulx_u64(&x129, &x130, x123, UINT64_C(0xffffffffffffffff)); uint64_t x131; uint64_t x132; fiat_secp256k1_mulx_u64(&x131, &x132, x123, UINT64_C(0xfffffffefffffc2f)); uint64_t x133; fiat_secp256k1_uint1 x134; fiat_secp256k1_addcarryx_u64(&x133, &x134, 0x0, x132, x129); uint64_t x135; fiat_secp256k1_uint1 x136; fiat_secp256k1_addcarryx_u64(&x135, &x136, x134, x130, x127); uint64_t x137; fiat_secp256k1_uint1 x138; fiat_secp256k1_addcarryx_u64(&x137, &x138, x136, x128, x125); uint64_t x139; fiat_secp256k1_uint1 x140; fiat_secp256k1_addcarryx_u64(&x139, &x140, 0x0, x115, x131); uint64_t x141; fiat_secp256k1_uint1 x142; fiat_secp256k1_addcarryx_u64(&x141, &x142, x140, x117, x133); uint64_t x143; fiat_secp256k1_uint1 x144; fiat_secp256k1_addcarryx_u64(&x143, &x144, x142, x119, x135); uint64_t x145; fiat_secp256k1_uint1 x146; fiat_secp256k1_addcarryx_u64(&x145, &x146, x144, x121, x137); uint64_t x147; fiat_secp256k1_uint1 x148; fiat_secp256k1_addcarryx_u64(&x147, &x148, x146, ((uint64_t)x122 + x110), (x138 + x126)); uint64_t x149; fiat_secp256k1_uint1 x150; fiat_secp256k1_subborrowx_u64(&x149, &x150, 0x0, x141, UINT64_C(0xfffffffefffffc2f)); uint64_t x151; fiat_secp256k1_uint1 x152; fiat_secp256k1_subborrowx_u64(&x151, &x152, x150, x143, UINT64_C(0xffffffffffffffff)); uint64_t x153; fiat_secp256k1_uint1 x154; fiat_secp256k1_subborrowx_u64(&x153, &x154, x152, x145, UINT64_C(0xffffffffffffffff)); uint64_t x155; fiat_secp256k1_uint1 x156; fiat_secp256k1_subborrowx_u64(&x155, &x156, x154, x147, UINT64_C(0xffffffffffffffff)); uint64_t x157; fiat_secp256k1_uint1 x158; fiat_secp256k1_subborrowx_u64(&x157, &x158, x156, x148, 0x0); uint64_t x159; fiat_secp256k1_cmovznz_u64(&x159, x158, x149, x141); uint64_t x160; fiat_secp256k1_cmovznz_u64(&x160, x158, x151, x143); uint64_t x161; fiat_secp256k1_cmovznz_u64(&x161, x158, x153, x145); uint64_t x162; fiat_secp256k1_cmovznz_u64(&x162, x158, x155, x147); out1[0] = x159; out1[1] = x160; out1[2] = x161; out1[3] = x162; } /* * The function fiat_secp256k1_nonzero outputs a single non-zero word if the input is non-zero and zero otherwise. * Preconditions: * 0 ≤ eval arg1 < m * Postconditions: * out1 = 0 ↔ eval (from_montgomery arg1) mod m = 0 * * Input Bounds: * arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * Output Bounds: * out1: [0x0 ~> 0xffffffffffffffff] */ static void fiat_secp256k1_nonzero(uint64_t* out1, const uint64_t arg1[4]) { uint64_t x1 = ((arg1[0]) | ((arg1[1]) | ((arg1[2]) | ((arg1[3]) | (uint64_t)0x0)))); *out1 = x1; } /* * The function fiat_secp256k1_selectznz is a multi-limb conditional select. * Postconditions: * eval out1 = (if arg1 = 0 then eval arg2 else eval arg3) * * Input Bounds: * arg1: [0x0 ~> 0x1] * arg2: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * arg3: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * Output Bounds: * out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] */ static void fiat_secp256k1_selectznz(uint64_t out1[4], fiat_secp256k1_uint1 arg1, const uint64_t arg2[4], const uint64_t arg3[4]) { uint64_t x1; fiat_secp256k1_cmovznz_u64(&x1, arg1, (arg2[0]), (arg3[0])); uint64_t x2; fiat_secp256k1_cmovznz_u64(&x2, arg1, (arg2[1]), (arg3[1])); uint64_t x3; fiat_secp256k1_cmovznz_u64(&x3, arg1, (arg2[2]), (arg3[2])); uint64_t x4; fiat_secp256k1_cmovznz_u64(&x4, arg1, (arg2[3]), (arg3[3])); out1[0] = x1; out1[1] = x2; out1[2] = x3; out1[3] = x4; } /* * The function fiat_secp256k1_to_bytes serializes a field element in the Montgomery domain to bytes in little-endian order. * Preconditions: * 0 ≤ eval arg1 < m * Postconditions: * out1 = map (λ x, ⌊((eval arg1 mod m) mod 2^(8 * (x + 1))) / 2^(8 * x)⌋) [0..31] * * Input Bounds: * arg1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] * Output Bounds: * out1: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff]] */ static void fiat_secp256k1_to_bytes(uint8_t out1[32], const uint64_t arg1[4]) { uint64_t x1 = (arg1[3]); uint64_t x2 = (arg1[2]); uint64_t x3 = (arg1[1]); uint64_t x4 = (arg1[0]); uint64_t x5 = (x4 >> 8); uint8_t x6 = (uint8_t)(x4 & UINT8_C(0xff)); uint64_t x7 = (x5 >> 8); uint8_t x8 = (uint8_t)(x5 & UINT8_C(0xff)); uint64_t x9 = (x7 >> 8); uint8_t x10 = (uint8_t)(x7 & UINT8_C(0xff)); uint64_t x11 = (x9 >> 8); uint8_t x12 = (uint8_t)(x9 & UINT8_C(0xff)); uint64_t x13 = (x11 >> 8); uint8_t x14 = (uint8_t)(x11 & UINT8_C(0xff)); uint64_t x15 = (x13 >> 8); uint8_t x16 = (uint8_t)(x13 & UINT8_C(0xff)); uint8_t x17 = (uint8_t)(x15 >> 8); uint8_t x18 = (uint8_t)(x15 & UINT8_C(0xff)); uint8_t x19 = (uint8_t)(x17 & UINT8_C(0xff)); uint64_t x20 = (x3 >> 8); uint8_t x21 = (uint8_t)(x3 & UINT8_C(0xff)); uint64_t x22 = (x20 >> 8); uint8_t x23 = (uint8_t)(x20 & UINT8_C(0xff)); uint64_t x24 = (x22 >> 8); uint8_t x25 = (uint8_t)(x22 & UINT8_C(0xff)); uint64_t x26 = (x24 >> 8); uint8_t x27 = (uint8_t)(x24 & UINT8_C(0xff)); uint64_t x28 = (x26 >> 8); uint8_t x29 = (uint8_t)(x26 & UINT8_C(0xff)); uint64_t x30 = (x28 >> 8); uint8_t x31 = (uint8_t)(x28 & UINT8_C(0xff)); uint8_t x32 = (uint8_t)(x30 >> 8); uint8_t x33 = (uint8_t)(x30 & UINT8_C(0xff)); uint8_t x34 = (uint8_t)(x32 & UINT8_C(0xff)); uint64_t x35 = (x2 >> 8); uint8_t x36 = (uint8_t)(x2 & UINT8_C(0xff)); uint64_t x37 = (x35 >> 8); uint8_t x38 = (uint8_t)(x35 & UINT8_C(0xff)); uint64_t x39 = (x37 >> 8); uint8_t x40 = (uint8_t)(x37 & UINT8_C(0xff)); uint64_t x41 = (x39 >> 8); uint8_t x42 = (uint8_t)(x39 & UINT8_C(0xff)); uint64_t x43 = (x41 >> 8); uint8_t x44 = (uint8_t)(x41 & UINT8_C(0xff)); uint64_t x45 = (x43 >> 8); uint8_t x46 = (uint8_t)(x43 & UINT8_C(0xff)); uint8_t x47 = (uint8_t)(x45 >> 8); uint8_t x48 = (uint8_t)(x45 & UINT8_C(0xff)); uint8_t x49 = (uint8_t)(x47 & UINT8_C(0xff)); uint64_t x50 = (x1 >> 8); uint8_t x51 = (uint8_t)(x1 & UINT8_C(0xff)); uint64_t x52 = (x50 >> 8); uint8_t x53 = (uint8_t)(x50 & UINT8_C(0xff)); uint64_t x54 = (x52 >> 8); uint8_t x55 = (uint8_t)(x52 & UINT8_C(0xff)); uint64_t x56 = (x54 >> 8); uint8_t x57 = (uint8_t)(x54 & UINT8_C(0xff)); uint64_t x58 = (x56 >> 8); uint8_t x59 = (uint8_t)(x56 & UINT8_C(0xff)); uint64_t x60 = (x58 >> 8); uint8_t x61 = (uint8_t)(x58 & UINT8_C(0xff)); uint8_t x62 = (uint8_t)(x60 >> 8); uint8_t x63 = (uint8_t)(x60 & UINT8_C(0xff)); out1[0] = x6; out1[1] = x8; out1[2] = x10; out1[3] = x12; out1[4] = x14; out1[5] = x16; out1[6] = x18; out1[7] = x19; out1[8] = x21; out1[9] = x23; out1[10] = x25; out1[11] = x27; out1[12] = x29; out1[13] = x31; out1[14] = x33; out1[15] = x34; out1[16] = x36; out1[17] = x38; out1[18] = x40; out1[19] = x42; out1[20] = x44; out1[21] = x46; out1[22] = x48; out1[23] = x49; out1[24] = x51; out1[25] = x53; out1[26] = x55; out1[27] = x57; out1[28] = x59; out1[29] = x61; out1[30] = x63; out1[31] = x62; } /* * The function fiat_secp256k1_from_bytes deserializes a field element in the Montgomery domain from bytes in little-endian order. * Preconditions: * 0 ≤ bytes_eval arg1 < m * Postconditions: * eval out1 mod m = bytes_eval arg1 mod m * 0 ≤ eval out1 < m * * Input Bounds: * arg1: [[0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff], [0x0 ~> 0xff]] * Output Bounds: * out1: [[0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff], [0x0 ~> 0xffffffffffffffff]] */ static void fiat_secp256k1_from_bytes(uint64_t out1[4], const uint8_t arg1[32]) { uint64_t x1 = ((uint64_t)(arg1[31]) << 56); uint64_t x2 = ((uint64_t)(arg1[30]) << 48); uint64_t x3 = ((uint64_t)(arg1[29]) << 40); uint64_t x4 = ((uint64_t)(arg1[28]) << 32); uint64_t x5 = ((uint64_t)(arg1[27]) << 24); uint64_t x6 = ((uint64_t)(arg1[26]) << 16); uint64_t x7 = ((uint64_t)(arg1[25]) << 8); uint8_t x8 = (arg1[24]); uint64_t x9 = ((uint64_t)(arg1[23]) << 56); uint64_t x10 = ((uint64_t)(arg1[22]) << 48); uint64_t x11 = ((uint64_t)(arg1[21]) << 40); uint64_t x12 = ((uint64_t)(arg1[20]) << 32); uint64_t x13 = ((uint64_t)(arg1[19]) << 24); uint64_t x14 = ((uint64_t)(arg1[18]) << 16); uint64_t x15 = ((uint64_t)(arg1[17]) << 8); uint8_t x16 = (arg1[16]); uint64_t x17 = ((uint64_t)(arg1[15]) << 56); uint64_t x18 = ((uint64_t)(arg1[14]) << 48); uint64_t x19 = ((uint64_t)(arg1[13]) << 40); uint64_t x20 = ((uint64_t)(arg1[12]) << 32); uint64_t x21 = ((uint64_t)(arg1[11]) << 24); uint64_t x22 = ((uint64_t)(arg1[10]) << 16); uint64_t x23 = ((uint64_t)(arg1[9]) << 8); uint8_t x24 = (arg1[8]); uint64_t x25 = ((uint64_t)(arg1[7]) << 56); uint64_t x26 = ((uint64_t)(arg1[6]) << 48); uint64_t x27 = ((uint64_t)(arg1[5]) << 40); uint64_t x28 = ((uint64_t)(arg1[4]) << 32); uint64_t x29 = ((uint64_t)(arg1[3]) << 24); uint64_t x30 = ((uint64_t)(arg1[2]) << 16); uint64_t x31 = ((uint64_t)(arg1[1]) << 8); uint8_t x32 = (arg1[0]); uint64_t x33 = (x32 + (x31 + (x30 + (x29 + (x28 + (x27 + (x26 + x25))))))); uint64_t x34 = (x33 & UINT64_C(0xffffffffffffffff)); uint64_t x35 = (x8 + (x7 + (x6 + (x5 + (x4 + (x3 + (x2 + x1))))))); uint64_t x36 = (x16 + (x15 + (x14 + (x13 + (x12 + (x11 + (x10 + x9))))))); uint64_t x37 = (x24 + (x23 + (x22 + (x21 + (x20 + (x19 + (x18 + x17))))))); uint64_t x38 = (x37 & UINT64_C(0xffffffffffffffff)); uint64_t x39 = (x36 & UINT64_C(0xffffffffffffffff)); out1[0] = x34; out1[1] = x38; out1[2] = x39; out1[3] = x35; }
the_stack_data/234519553.c
/* * M1522.000800 System Programming * Shell Lab * * tsh - A tiny shell program with job control * * Name: <omitted> * Student id: <omitted> * */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <ctype.h> #include <signal.h> #include <sys/types.h> #include <sys/wait.h> #include <errno.h> /* Misc manifest constants */ #define MAXLINE 1024 /* max line size */ #define MAXARGS 128 /* max args on a command line */ #define MAXJOBS 16 /* max jobs at any point in time */ #define MAXJID 1<<16 /* max job ID */ /* Job states */ #define UNDEF 0 /* undefined */ #define FG 1 /* running in foreground */ #define BG 2 /* running in background */ #define ST 3 /* stopped */ /* * Jobs states: FG (foreground), BG (background), ST (stopped) * Job state transitions and enabling actions: * FG -> ST : ctrl-z * ST -> FG : fg command * ST -> BG : bg command * BG -> FG : fg command * At most 1 job can be in the FG state. */ /* Global variables */ extern char **environ; /* defined in libc */ char prompt[] = "tsh> "; /* command line prompt (DO NOT CHANGE) */ int verbose = 0; /* if true, print additional output */ int nextjid = 1; /* next job ID to allocate */ char sbuf[MAXLINE]; /* for composing sprintf messages */ struct job_t { /* The job struct */ pid_t pid; /* job PID */ int jid; /* job ID [1, 2, ...] */ int state; /* UNDEF, BG, FG, or ST */ char cmdline[MAXLINE]; /* command line */ }; struct job_t jobs[MAXJOBS]; /* The job list */ /* End global variables */ /* Function prototypes */ /*---------------------------------------------------------------------------- * Functions that you will implement */ void eval(char *cmdline); int builtin_cmd(char **argv); void do_bgfg(char **argv); void waitfg(pid_t pid); void sigchld_handler(int sig); void sigint_handler(int sig); void sigtstp_handler(int sig); int isdigits(char* str); /*----------------------------------------------------------------------------*/ /* These functions are already implemented for your convenience */ int parseline(const char *cmdline, char **argv); void sigquit_handler(int sig); void clearjob(struct job_t *job); void initjobs(struct job_t *jobs); int maxjid(struct job_t *jobs); int addjob(struct job_t *jobs, pid_t pid, int state, char *cmdline); int deletejob(struct job_t *jobs, pid_t pid); pid_t fgpid(struct job_t *jobs); struct job_t *getjobpid(struct job_t *jobs, pid_t pid); struct job_t *getjobjid(struct job_t *jobs, int jid); int pid2jid(pid_t pid); void listjobs(struct job_t *jobs); void usage(void); void unix_error(char *msg); void app_error(char *msg); typedef void handler_t(int); handler_t *Signal(int signum, handler_t *handler); /* * main - The shell's main routine */ int main(int argc, char **argv) { char c; char cmdline[MAXLINE]; int emit_prompt = 1; /* emit prompt (default) */ /* Redirect stderr to stdout (so that driver will get all output * on the pipe connected to stdout) */ dup2(1, 2); /* Parse the command line */ while ((c = getopt(argc, argv, "hvp")) != EOF) { switch (c) { case 'h': /* print help message */ usage(); break; case 'v': /* emit additional diagnostic info */ verbose = 1; break; case 'p': /* don't print a prompt */ emit_prompt = 0; /* handy for automatic testing */ break; default: usage(); } } /* Install the signal handlers */ /* These are the ones you will need to implement */ Signal(SIGINT, sigint_handler); /* ctrl-c */ Signal(SIGTSTP, sigtstp_handler); /* ctrl-z */ Signal(SIGCHLD, sigchld_handler); /* Terminated or stopped child */ /* This one provides a clean way to kill the shell */ Signal(SIGQUIT, sigquit_handler); /* Initialize the job list */ initjobs(jobs); /* Execute the shell's read/eval loop */ while (1) { /* Read command line */ if (emit_prompt) { printf("%s", prompt); fflush(stdout); } if ((fgets(cmdline, MAXLINE, stdin) == NULL) && ferror(stdin)) app_error("fgets error"); if (feof(stdin)) { /* End of file (ctrl-d) */ fflush(stdout); exit(0); } /* Evaluate the command line */ eval(cmdline); fflush(stdout); fflush(stdout); } exit(0); /* control never reaches here */ } /* * eval - Evaluate the command line that the user has just typed in * * If the user has requested a built-in command (quit, jobs, bg or fg) * then execute it immediately. Otherwise, fork a child process and * run the job in the context of the child. If the job is running in * the foreground, wait for it to terminate and then return. Note: * each child process must have a unique process group ID so that our * background children don't receive SIGINT (SIGTSTP) from the kernel * when we type ctrl-c (ctrl-z) at the keyboard. */ void eval(char *cmdline) { char *argv[MAXARGS]; /* stores the returned arguments of parseline */ int isBG; /* if the job is background or not */ pid_t pid; /* process id to identify the parent and child */ sigset_t mask; /* blocks signals */ // parse the input and execute immediately if possible isBG = parseline(cmdline, argv); if (argv[0] == NULL) return; if (builtin_cmd(argv)) return; // block sigchild if(sigemptyset(&mask) != 0){ unix_error("sigemptyset error"); } if(sigaddset(&mask, SIGCHLD) != 0){ unix_error("sigaddset error"); } if(sigprocmask(SIG_BLOCK, &mask, NULL) != 0){ unix_error("sigprocmask error"); } if((pid = fork()) < 0){ unix_error("forking error"); return; } //parent: register job to joblist, shell shoud get the signal so unblock them. if (pid) { addjob(jobs, pid, (isBG) ? BG : FG, cmdline); if (sigprocmask(SIG_UNBLOCK, &mask, NULL) != 0){ unix_error("sigprocmask error"); } if (isBG) { printf("[%d] (%d) %s", pid2jid(pid), pid, cmdline); } else { waitfg(pid); } } //child: new process group(pgid), unblock mask, and then exec else { if(setpgid(0, 0) < 0) { unix_error("setpgid error"); } if (sigprocmask(SIG_UNBLOCK, &mask, NULL) != 0){ unix_error("sigprocmask error"); } if (execvp(argv[0], argv) < 0) { printf("%s: Command not found\n", argv[0]); exit(0); } } return; } /* * parseline - Parse the command line and build the argv array. * * Characters enclosed in single quotes are treated as a single * argument. Return true if the user has requested a BG job, false if * the user has requested a FG job. */ int parseline(const char *cmdline, char **argv) { static char array[MAXLINE]; /* holds local copy of command line */ char *buf = array; /* ptr that traverses command line */ char *delim; /* points to first space delimiter */ int argc; /* number of args */ int bg; /* background job? */ strcpy(buf, cmdline); buf[strlen(buf)-1] = ' '; /* replace trailing '\n' with space */ while (*buf && (*buf == ' ')) /* ignore leading spaces */ buf++; /* Build the argv list */ argc = 0; if (*buf == '\'') { buf++; delim = strchr(buf, '\''); } else { delim = strchr(buf, ' '); } while (delim) { argv[argc++] = buf; *delim = '\0'; buf = delim + 1; while (*buf && (*buf == ' ')) /* ignore spaces */ buf++; if (*buf == '\'') { buf++; delim = strchr(buf, '\''); } else { delim = strchr(buf, ' '); } } argv[argc] = NULL; if (argc == 0) /* ignore blank line */ return 1; /* should the job run in the background? */ if ((bg = (*argv[argc-1] == '&')) != 0) { argv[--argc] = NULL; } return bg; } /* * builtin_cmd - If the user has typed a built-in command then execute * it immediately. */ int builtin_cmd(char **argv) { if (strncmp(argv[0], "quit", 4) == 0) { exit(0); } if (strncmp(argv[0], "bg", 2) == 0 || strncmp(argv[0], "fg", 2) == 0) { do_bgfg(argv); return 1; } if (strncmp(argv[0], "jobs", 4) == 0) { listjobs(jobs); return 1; } // ignore singleton & if (strncmp(argv[0], "&", 1) == 0) { return 1; } return 0; /* not a builtin command */ } /* * do_bgfg - Execute the builtin bg and fg commands */ void do_bgfg(char **argv) { struct job_t *job; int jid, pid; // if neither pid nor jid is given if (argv[1] == NULL) { printf("%s command requires PID or %%jobid argument\n", argv[0]); return; } // if id is given as jid type if (argv[1][0] == '%') { jid = atoi(&argv[1][1]); job = getjobjid(jobs, jid); if (job == NULL) { printf("%%%d: No such job\n", jid); return; } } // if id is given as pid type else if (isdigits(argv[1])) { pid = atoi(argv[1]); job = getjobpid(jobs, pid); if (job == NULL) { printf("(%d): No such process\n",pid); return; } } // if given arg is neither jid nor pid type else { printf("%s: argument must be a PID or %%jobid\n", argv[0]); return; } if (job->state == ST) { if (kill(-(job->pid), SIGCONT) < 0) { if (errno != ESRCH) { unix_error("kill error"); } } } if(strncmp("bg", argv[0], 2) == 0) { printf("[%d] (%d) %s", job->jid, job->pid, job->cmdline); job->state = BG; } else if(strncmp("fg", argv[0], 2) == 0 ) { job->state = FG; waitfg(job->pid); } //this cannot happen else { printf("error: %s\n", argv[0]); } return; } /* * waitfg - Block until process pid is no longer the foreground process */ void waitfg(pid_t pid) { sigset_t mask; if (sigemptyset(&mask) < 0) { unix_error("sigemptyset error"); } // avoid wasting cpu cycles by busy waiting // loops are runned only when any signal arrives while (pid == fgpid(jobs)) { sigsuspend(&mask); } return; } int isdigits(char* str) { int ret = 1; int i; for (i=0; i<strlen(str); i++) { // nonzero value to 1 ret *= !(!(isdigit(str[i]))); } return ret; } /***************** * Signal handlers *****************/ /* * sigchld_handler - The kernel sends a SIGCHLD to the shell whenever * a child job terminates (becomes a zombie), or stops because it * received a SIGSTOP or SIGTSTP signal. The handler reaps all * available zombie children, but doesn't wait for any other * currently running children to terminate. */ void sigchld_handler(int sig) { pid_t pid; int status; while ((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0) { if (WIFSTOPPED(status)) { // negative value to identify whether to print or not sigtstp_handler(-SIGTSTP); } else if (WIFSIGNALED(status)){ // negative value to identify whether to print or not sigint_handler(-SIGINT); } else { deletejob(jobs, pid); } } return; } /* * sigint_handler - The kernel sends a SIGINT to the shell whenver the * user types ctrl-c at the keyboard. Catch it and send it along * to the foreground job. */ void sigint_handler(int sig) { pid_t pid = fgpid(jobs); if (pid != 0) { if (kill(-pid, SIGINT) < 0 ) { if (errno != ESRCH) { unix_error("kill error"); } } if (sig < 0) { printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(pid), pid, -sig); deletejob(jobs, pid); } } return; } /* * sigtstp_handler - The kernel sends a SIGTSTP to the shell whenever * the user types ctrl-z at the keyboard. Catch it and suspend the * foreground job by sending it a SIGTSTP. */ void sigtstp_handler(int sig) { pid_t pid = fgpid(jobs); if (pid != 0) { if (kill(-pid, SIGTSTP) < 0 ) { if (errno != ESRCH) { unix_error("kill error"); } } if (sig < 0 ) { printf("Job [%d] (%d) Stopped by signal %d\n", pid2jid(pid), pid, -sig); getjobpid(jobs, pid)->state = ST; } } return; } /********************* * End signal handlers *********************/ /*********************************************** * Helper routines that manipulate the job list **********************************************/ /* clearjob - Clear the entries in a job struct */ void clearjob(struct job_t *job) { job->pid = 0; job->jid = 0; job->state = UNDEF; job->cmdline[0] = '\0'; } /* initjobs - Initialize the job list */ void initjobs(struct job_t *jobs) { int i; for (i = 0; i < MAXJOBS; i++) clearjob(&jobs[i]); } /* maxjid - Returns largest allocated job ID */ int maxjid(struct job_t *jobs) { int i, max=0; for (i = 0; i < MAXJOBS; i++) if (jobs[i].jid > max) max = jobs[i].jid; return max; } /* addjob - Add a job to the job list */ int addjob(struct job_t *jobs, pid_t pid, int state, char *cmdline) { int i; if (pid < 1) return 0; for (i = 0; i < MAXJOBS; i++) { if (jobs[i].pid == 0) { jobs[i].pid = pid; jobs[i].state = state; jobs[i].jid = nextjid++; if (nextjid > MAXJOBS) nextjid = 1; strcpy(jobs[i].cmdline, cmdline); if(verbose){ printf("Added job [%d] %d %s\n", jobs[i].jid, jobs[i].pid, jobs[i].cmdline); } return 1; } } printf("Tried to create too many jobs\n"); return 0; } /* deletejob - Delete a job whose PID=pid from the job list */ int deletejob(struct job_t *jobs, pid_t pid) { int i; if (pid < 1) return 0; for (i = 0; i < MAXJOBS; i++) { if (jobs[i].pid == pid) { clearjob(&jobs[i]); nextjid = maxjid(jobs)+1; return 1; } } return 0; } /* fgpid - Return PID of current foreground job, 0 if no such job */ pid_t fgpid(struct job_t *jobs) { int i; for (i = 0; i < MAXJOBS; i++) if (jobs[i].state == FG) return jobs[i].pid; return 0; } /* getjobpid - Find a job (by PID) on the job list */ struct job_t *getjobpid(struct job_t *jobs, pid_t pid) { int i; if (pid < 1) return NULL; for (i = 0; i < MAXJOBS; i++) if (jobs[i].pid == pid) return &jobs[i]; return NULL; } /* getjobjid - Find a job (by JID) on the job list */ struct job_t *getjobjid(struct job_t *jobs, int jid) { int i; if (jid < 1) return NULL; for (i = 0; i < MAXJOBS; i++) if (jobs[i].jid == jid) return &jobs[i]; return NULL; } /* pid2jid - Map process ID to job ID */ int pid2jid(pid_t pid) { int i; if (pid < 1) return 0; for (i = 0; i < MAXJOBS; i++) if (jobs[i].pid == pid) { return jobs[i].jid; } return 0; } /* listjobs - Print the job list */ void listjobs(struct job_t *jobs) { int i; for (i = 0; i < MAXJOBS; i++) { if (jobs[i].pid != 0) { printf("[%d] (%d) ", jobs[i].jid, jobs[i].pid); switch (jobs[i].state) { case BG: printf("Running "); break; case FG: printf("Foreground "); break; case ST: printf("Stopped "); break; default: printf("listjobs: Internal error: job[%d].state=%d ", i, jobs[i].state); } printf("%s", jobs[i].cmdline); } } } /****************************** * end job list helper routines ******************************/ /*********************** * Other helper routines ***********************/ /* * usage - print a help message */ void usage(void) { printf("Usage: shell [-hvp]\n"); printf(" -h print this message\n"); printf(" -v print additional diagnostic information\n"); printf(" -p do not emit a command prompt\n"); exit(1); } /* * unix_error - unix-style error routine */ void unix_error(char *msg) { fprintf(stdout, "%s: %s\n", msg, strerror(errno)); exit(1); } /* * app_error - application-style error routine */ void app_error(char *msg) { fprintf(stdout, "%s\n", msg); exit(1); } /* * Signal - wrapper for the sigaction function */ handler_t *Signal(int signum, handler_t *handler) { struct sigaction action, old_action; action.sa_handler = handler; sigemptyset(&action.sa_mask); /* block sigs of type being handled */ action.sa_flags = SA_RESTART; /* restart syscalls if possible */ if (sigaction(signum, &action, &old_action) < 0) unix_error("Signal error"); return (old_action.sa_handler); } /* * sigquit_handler - The driver program can gracefully terminate the * child shell by sending it a SIGQUIT signal. */ void sigquit_handler(int sig) { printf("Terminating after receipt of SIGQUIT signal\n"); exit(1); }
the_stack_data/7951440.c
#include <stdio.h> #include <stdlib.h> int main() { float n1, n2, n3, n4, n5, media; float a = 2.5, b = 2, c = 1; printf("Nota da primeira avaliação teórica: "); scanf("%f", &n1); printf("Nota da segunda avaliação teórica: "); scanf("%f", &n2); printf("Nota da primeira avaliação prática: "); scanf("%f", &n3); printf("Nota da segunda avaliação prática: "); scanf("%f", &n4); printf("Nota quantitativa: "); scanf("%f", &n5); media = ((n1/a + n2/a + n3/b + n4/b + n5/c) / 5) * 10; if(media >= 7) { printf("Aprovado com media %.2f", media); } else if(media >= 3 || media < 7) { printf("Exame com media %.2f", media); } else { printf("Reprovado com media %.2f", media); } return 0; }
the_stack_data/440713.c
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <dirent.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <unistd.h> #include <inttypes.h> #define INODES_CAPACITY 20 #define DIRSIZE 4 /* Create dynamic array of inodes. Each index holds an UNIQUE inode number. Dynamic array needs a size and capacity to expand when size closes in on capacity. */ typedef struct { size_t* array; int size; int capacity; } inodes; int traverseDir(char* dirname, inodes* arrInodes); int fileStats(char* dir, inodes* arrInodes); void resize(inodes* arrInodes); void buildPath(char* dest, char* path, char* entry); int main (int argc, char* argv[]){ inodes arrInodes; arrInodes.capacity = INODES_CAPACITY; arrInodes.size = 0; arrInodes.array = malloc(sizeof(size_t) * arrInodes.capacity); char path[PATH_MAX + 1]; if (argc == 1) { int blockSize = traverseDir(".", &arrInodes); printf("%d %s\n", blockSize, "."); } else if (argc == 2) { if (!realpath(argv[1], path)){ perror("Path could not be resolved"); } int blockSize = traverseDir(path, &arrInodes); printf("%d %s\n", blockSize, path); } return 0; } /* Create the directory name. dirent -> d_name does not give full path name. Need to store recursively. */ void buildPath(char* dest, char* path, char* entry){ strncat(dest, path, strlen(path)); strncat(dest, "/" , 1); strncat(dest, entry, strlen(entry)); } /* Traverse directory tree by directory name. Includes ALL files. */ int traverseDir(char* dirname, inodes* arrInodes){ DIR *dirp = opendir(dirname); struct dirent *direntp; int dirLen = 0; int totalBlockSize = 0; int size = 0; char *temp = NULL; while((direntp = readdir(dirp)) != NULL){ if (direntp -> d_name[0] != '.' || (direntp -> d_name[1] >= 'a' && direntp -> d_name[1] <= 'z')) { dirLen = strlen(dirname) + strlen(direntp -> d_name) + 1; temp = (char*) calloc(dirLen, sizeof(char*)); buildPath(temp, dirname, direntp -> d_name); if(direntp -> d_type == DT_DIR){ size = traverseDir(temp, arrInodes); totalBlockSize += size; printf("%d \t %s\n", size, temp); } else{ totalBlockSize += fileSize(temp, arrInodes); } } else if (direntp -> d_name[1] == '\0'){ totalBlockSize += DIRSIZE; } } free(temp); return totalBlockSize; } /* Take in unique hardlinks. Return 0 otherwise. */ int fileSize(char* file, inodes* arrInodes) { struct stat buf; if (!lstat(file, &buf)) { perror("lstat command failed"); } if (buf.st_nlink > 1) { for(int i = 0; i < arrInodes -> size; i++) { if((size_t) buf.st_ino == arrInodes -> array[i]) { return 0; } } arrInodes -> array[arrInodes -> size] = buf.st_ino; arrInodes -> size++; } if(arrInodes -> size == arrInodes -> capacity){ resize(arrInodes); } return buf.st_blocks; } /* Double the capacity. Resize the dynamic array of inodes. */ void resize(inodes* arrInodes) { size_t* newArrayInodes; arrInodes -> capacity = arrInodes -> capacity * 2; newArrayInodes = malloc(sizeof(size_t) * arrInodes -> capacity); free(arrInodes -> array); arrInodes -> array = newArrayInodes; }
the_stack_data/49977.c
/* Generated by CIL v. 1.5.1 */ /* print_CIL_Input is true */ typedef unsigned long size_t; typedef long __off_t; typedef long __off64_t; struct _IO_FILE; typedef struct _IO_FILE FILE; typedef void _IO_lock_t; struct _IO_marker { struct _IO_marker *_next ; struct _IO_FILE *_sbuf ; int _pos ; }; struct _IO_FILE { int _flags ; char *_IO_read_ptr ; char *_IO_read_end ; char *_IO_read_base ; char *_IO_write_base ; char *_IO_write_ptr ; char *_IO_write_end ; char *_IO_buf_base ; char *_IO_buf_end ; char *_IO_save_base ; char *_IO_backup_base ; char *_IO_save_end ; struct _IO_marker *_markers ; struct _IO_FILE *_chain ; int _fileno ; int _flags2 ; __off_t _old_offset ; unsigned short _cur_column ; signed char _vtable_offset ; char _shortbuf[1] ; _IO_lock_t *_lock ; __off64_t _offset ; void *__pad1 ; void *__pad2 ; void *__pad3 ; void *__pad4 ; size_t __pad5 ; int _mode ; char _unused2[(15UL * sizeof(int ) - 4UL * sizeof(void *)) - sizeof(size_t )] ; }; typedef long ptrdiff_t; typedef unsigned int uint32_t; struct UT_hash_handle; struct UT_hash_bucket { struct UT_hash_handle *hh_head ; unsigned int count ; unsigned int expand_mult ; }; typedef struct UT_hash_bucket UT_hash_bucket; struct UT_hash_table { UT_hash_bucket *buckets ; unsigned int num_buckets ; unsigned int log2_num_buckets ; unsigned int num_items ; struct UT_hash_handle *tail ; ptrdiff_t hho ; unsigned int ideal_chain_maxlen ; unsigned int nonideal_items ; unsigned int ineff_expands ; unsigned int noexpand ; uint32_t signature ; }; typedef struct UT_hash_table UT_hash_table; struct UT_hash_handle { struct UT_hash_table *tbl ; void *prev ; void *next ; struct UT_hash_handle *hh_prev ; struct UT_hash_handle *hh_next ; void *key ; unsigned int keylen ; unsigned int hashv ; }; typedef struct UT_hash_handle UT_hash_handle; struct my_struct { int sid ; char *true_expr ; char *false_expr ; int trueblk ; int falseblk ; UT_hash_handle hh ; }; struct CDGNode { int id ; int score ; int outcome ; char *expr ; struct CDGNode *trueNodeSet ; struct CDGNode *falseNodeSet ; struct CDGNode *parent ; struct CDGNode *next ; }; typedef struct CDGNode CDGNode; struct treeNode { int sid ; int level ; int outcome ; char *texp ; char *fexp ; struct treeNode *fchild ; struct treeNode *parent ; struct treeNode *next ; }; struct qnode { struct treeNode *levelptr[50] ; char *symbolicNames ; struct qnode *next ; }; struct Queue { struct qnode *front ; struct qnode *rear ; int totalElements ; }; enum TOKENTYPE { NOTHING = -1, DELIMETER = 0, OPERATOR = 1, NUMBER = 2, POINTER = 3, ARRAY1 = 4, VARIABLE = 5, FUNCTION = 6, UNKNOWN = 7 } ; struct field_values { char *sname ; void *cval ; int address ; int type ; }; struct sym_table { char *vname ; struct field_values *fval ; UT_hash_handle hh ; }; struct variable_table { char *varName ; int parameter ; UT_hash_handle hh ; }; struct arrayKey { char arrayName[50] ; int index ; }; struct arraySym_table { struct arrayKey key ; char sname[150] ; void *cval ; int address ; int type ; UT_hash_handle hh ; }; struct ObjectHT { char *field ; char *symName ; void *val ; UT_hash_handle hh ; }; typedef struct ObjectHT ObjectHT; struct MainHT { int key ; ObjectHT *val ; UT_hash_handle hh ; }; typedef struct MainHT MainHT; struct intVartable { char *sname ; int *value ; UT_hash_handle hh ; }; struct floatVartable { char *sname ; float *value ; UT_hash_handle hh ; }; enum ObjectType { CHAR = 0, INT = 1, FLOAT = 2, ARRAY = 3, STRUCT = 4 } ; typedef enum ObjectType ObjectType; struct node { void *element ; struct node *next ; }; typedef struct node node; struct __anonstruct_Stack_21 { int elementSize ; int elementsCnt ; node *head ; }; typedef struct __anonstruct_Stack_21 Stack; struct CDGPath { struct CDGNode *node ; struct CDGPath *next ; }; typedef struct CDGPath CDGPath; struct CDGContext { struct CDGPath *topPaths ; }; typedef struct CDGContext CDGContext; #pragma merger("0","./utils.i","-g,-g") extern struct _IO_FILE *stderr ; extern int fclose(FILE *__stream ) ; extern FILE *fopen(char const * __restrict __filename , char const * __restrict __modes ) ; extern int fprintf(FILE * __restrict __stream , char const * __restrict __format , ...) ; extern int fputs(char const * __restrict __s , FILE * __restrict __stream ) ; extern __attribute__((__nothrow__, __noreturn__)) void ( __attribute__((__leaf__)) exit)(int __status ) ; void printTestCase(char const *filename , char const *testcase ) { FILE *fp ; { fp = fopen((char const * __restrict )filename, (char const * __restrict )"a"); if ((unsigned long )fp == (unsigned long )((void *)0)) { fprintf((FILE * __restrict )stderr, (char const * __restrict )"Cannot open file: %s!", filename); exit(1); } fputs((char const * __restrict )testcase, (FILE * __restrict )fp); fclose(fp); return; } } #pragma merger("0","./sidTable.i","-g,-g") extern __attribute__((__nothrow__)) void *( __attribute__((__leaf__)) malloc)(size_t __size ) __attribute__((__malloc__)) ; extern __attribute__((__nothrow__)) void ( __attribute__((__leaf__)) free)(void *__ptr ) ; extern __attribute__((__nothrow__)) void *( __attribute__((__nonnull__(1), __leaf__)) memset)(void *__s , int __c , size_t __n ) ; extern __attribute__((__nothrow__)) int ( __attribute__((__nonnull__(1,2), __leaf__)) memcmp)(void const *__s1 , void const *__s2 , size_t __n ) __attribute__((__pure__)) ; extern __attribute__((__nothrow__)) char *( __attribute__((__nonnull__(1,2), __leaf__)) strcpy)(char * __restrict __dest , char const * __restrict __src ) ; extern __attribute__((__nothrow__)) size_t ( __attribute__((__nonnull__(1), __leaf__)) strlen)(char const *__s ) __attribute__((__pure__)) ; int *unrolledCopies ; void initSID(void) ; void isCopyOf(int copysid , int orgsid ) ; void add_condition(int sid , char *exp1 , char *exp2 , int tb , int fb ) ; struct my_struct *find_condition(int sid ) ; char *getTrueExpr(int sid ) ; char *getFalseExpr(int sid ) ; int countTotalConditions(void) ; int countCoveredConditions(void) ; int getBranchInfo(int id , int branch ) ; void setBranchInfo(int sid , int tblk , int fblk ) ; void delete_condition(struct my_struct *s ) ; void delete_allConditions(void) ; void print_conditions(void) ; CDGNode *pathNode[100] = { (CDGNode *)((void *)0)}; char *getPrepositionalFormula(char *expr ) ; int CDG_Module = 0; struct my_struct *conditions = (struct my_struct *)((void *)0); void isCopyOf(int copysid , int orgsid ) { { *(unrolledCopies + copysid) = orgsid; return; } } void initUnrolledCopies(void) { int maxCopies ; void *tmp ; int i ; { maxCopies = 500; tmp = malloc(sizeof(int ) * (unsigned long )maxCopies); unrolledCopies = (int *)tmp; i = 0; while (i < maxCopies) { *(unrolledCopies + i) = -1; i ++; } return; } } void initSID(void) { { initUnrolledCopies(); return; } } void add_condition(int sid , char *exp1 , char *exp2 , int tb , int fb ) { struct my_struct *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp ; void *tmp___0 ; unsigned int _ha_bkt ; void *tmp___1 ; void *tmp___2 ; unsigned int _hj_i___0 ; unsigned int _hj_j___0 ; unsigned int _hj_k___0 ; unsigned char *_hj_key___0 ; unsigned int _he_bkt ; unsigned int _he_bkt_i ; struct UT_hash_handle *_he_thh ; struct UT_hash_handle *_he_hh_nxt ; UT_hash_bucket *_he_new_buckets ; UT_hash_bucket *_he_newbkt ; void *tmp___3 ; int tmp___4 ; size_t tmp___5 ; void *tmp___6 ; size_t tmp___7 ; void *tmp___8 ; { while (1) { s = (struct my_struct *)((void *)0); if (conditions) { while (1) { _hj_key = (unsigned char *)(& sid); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct my_struct *)((void *)((char *)((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } while (s) { if ((unsigned long )s->hh.keylen == sizeof(int )) { tmp = memcmp((void const *)s->hh.key, (void const *)(& sid), sizeof(int )); if (tmp == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct my_struct *)((void *)((char *)s->hh.hh_next - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } } break; } } break; } if ((unsigned long )s == (unsigned long )((void *)0)) { tmp___0 = malloc(sizeof(struct my_struct )); s = (struct my_struct *)tmp___0; s->sid = sid; while (1) { s->hh.next = (void *)0; s->hh.key = (void *)((char *)(& s->sid)); s->hh.keylen = (unsigned int )sizeof(int ); if (! conditions) { conditions = s; conditions->hh.prev = (void *)0; while (1) { tmp___1 = malloc(sizeof(UT_hash_table )); conditions->hh.tbl = (UT_hash_table *)tmp___1; if (! conditions->hh.tbl) { exit(-1); } memset((void *)conditions->hh.tbl, 0, sizeof(UT_hash_table )); (conditions->hh.tbl)->tail = & conditions->hh; (conditions->hh.tbl)->num_buckets = 32U; (conditions->hh.tbl)->log2_num_buckets = 5U; (conditions->hh.tbl)->hho = (char *)(& conditions->hh) - (char *)conditions; tmp___2 = malloc(32UL * sizeof(struct UT_hash_bucket )); (conditions->hh.tbl)->buckets = (UT_hash_bucket *)tmp___2; if (! (conditions->hh.tbl)->buckets) { exit(-1); } memset((void *)(conditions->hh.tbl)->buckets, 0, 32UL * sizeof(struct UT_hash_bucket )); (conditions->hh.tbl)->signature = 2685476833U; break; } } else { ((conditions->hh.tbl)->tail)->next = (void *)s; s->hh.prev = (void *)((char *)(conditions->hh.tbl)->tail - (conditions->hh.tbl)->hho); (conditions->hh.tbl)->tail = & s->hh; } ((conditions->hh.tbl)->num_items) ++; s->hh.tbl = conditions->hh.tbl; while (1) { _hj_key___0 = (unsigned char *)(& s->sid); s->hh.hashv = 4276993775U; _hj_j___0 = 2654435769U; _hj_i___0 = _hj_j___0; _hj_k___0 = (unsigned int )sizeof(int ); while (_hj_k___0 >= 12U) { _hj_i___0 += (((unsigned int )*(_hj_key___0 + 0) + ((unsigned int )*(_hj_key___0 + 1) << 8)) + ((unsigned int )*(_hj_key___0 + 2) << 16)) + ((unsigned int )*(_hj_key___0 + 3) << 24); _hj_j___0 += (((unsigned int )*(_hj_key___0 + 4) + ((unsigned int )*(_hj_key___0 + 5) << 8)) + ((unsigned int )*(_hj_key___0 + 6) << 16)) + ((unsigned int )*(_hj_key___0 + 7) << 24); s->hh.hashv += (((unsigned int )*(_hj_key___0 + 8) + ((unsigned int )*(_hj_key___0 + 9) << 8)) + ((unsigned int )*(_hj_key___0 + 10) << 16)) + ((unsigned int )*(_hj_key___0 + 11) << 24); while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 13; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 12; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 3; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 15; break; } _hj_key___0 += 12; _hj_k___0 -= 12U; } s->hh.hashv = (unsigned int )((unsigned long )s->hh.hashv + sizeof(int )); switch (_hj_k___0) { case 11U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 10) << 24; case 10U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 9) << 16; case 9U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 8) << 8; case 8U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 7) << 24; case 7U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 6) << 16; case 6U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 5) << 8; case 5U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 4); case 4U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 3) << 24; case 3U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 2) << 16; case 2U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 1) << 8; case 1U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 0); } while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 13; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 12; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 3; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 15; break; } _ha_bkt = s->hh.hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } while (1) { (((conditions->hh.tbl)->buckets + _ha_bkt)->count) ++; s->hh.hh_next = ((conditions->hh.tbl)->buckets + _ha_bkt)->hh_head; s->hh.hh_prev = (struct UT_hash_handle *)((void *)0); if (((conditions->hh.tbl)->buckets + _ha_bkt)->hh_head) { (((conditions->hh.tbl)->buckets + _ha_bkt)->hh_head)->hh_prev = & s->hh; } ((conditions->hh.tbl)->buckets + _ha_bkt)->hh_head = & s->hh; if (((conditions->hh.tbl)->buckets + _ha_bkt)->count >= (((conditions->hh.tbl)->buckets + _ha_bkt)->expand_mult + 1U) * 10U) { if ((s->hh.tbl)->noexpand != 1U) { while (1) { tmp___3 = malloc((unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); _he_new_buckets = (UT_hash_bucket *)tmp___3; if (! _he_new_buckets) { exit(-1); } memset((void *)_he_new_buckets, 0, (unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); if ((s->hh.tbl)->num_items & ((s->hh.tbl)->num_buckets * 2U - 1U)) { tmp___4 = 1; } else { tmp___4 = 0; } (s->hh.tbl)->ideal_chain_maxlen = ((s->hh.tbl)->num_items >> ((s->hh.tbl)->log2_num_buckets + 1U)) + (unsigned int )tmp___4; (s->hh.tbl)->nonideal_items = 0U; _he_bkt_i = 0U; while (_he_bkt_i < (s->hh.tbl)->num_buckets) { _he_thh = ((s->hh.tbl)->buckets + _he_bkt_i)->hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; while (1) { _he_bkt = _he_thh->hashv & ((s->hh.tbl)->num_buckets * 2U - 1U); break; } _he_newbkt = _he_new_buckets + _he_bkt; (_he_newbkt->count) ++; if (_he_newbkt->count > (s->hh.tbl)->ideal_chain_maxlen) { ((s->hh.tbl)->nonideal_items) ++; _he_newbkt->expand_mult = _he_newbkt->count / (s->hh.tbl)->ideal_chain_maxlen; } _he_thh->hh_prev = (struct UT_hash_handle *)((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) { (_he_newbkt->hh_head)->hh_prev = _he_thh; } _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } _he_bkt_i ++; } free((void *)(s->hh.tbl)->buckets); (s->hh.tbl)->num_buckets *= 2U; ((s->hh.tbl)->log2_num_buckets) ++; (s->hh.tbl)->buckets = _he_new_buckets; if ((s->hh.tbl)->nonideal_items > (s->hh.tbl)->num_items >> 1) { ((s->hh.tbl)->ineff_expands) ++; } else { (s->hh.tbl)->ineff_expands = 0U; } if ((s->hh.tbl)->ineff_expands > 1U) { (s->hh.tbl)->noexpand = 1U; } break; } } } break; } break; } tmp___5 = strlen((char const *)exp1); tmp___6 = malloc(sizeof(char ) * (tmp___5 + 1UL)); s->true_expr = (char *)tmp___6; tmp___7 = strlen((char const *)exp2); tmp___8 = malloc(sizeof(char ) * (tmp___7 + 1UL)); s->false_expr = (char *)tmp___8; } strcpy((char * __restrict )s->true_expr, (char const * __restrict )exp1); strcpy((char * __restrict )s->false_expr, (char const * __restrict )exp2); s->trueblk = tb; s->falseblk = fb; return; } } struct my_struct *find_condition(int sid ) { struct my_struct *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp ; { while (1) { s = (struct my_struct *)((void *)0); if (conditions) { while (1) { _hj_key = (unsigned char *)(& sid); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct my_struct *)((void *)((char *)((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } while (s) { if ((unsigned long )s->hh.keylen == sizeof(int )) { tmp = memcmp((void const *)s->hh.key, (void const *)(& sid), sizeof(int )); if (tmp == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct my_struct *)((void *)((char *)s->hh.hh_next - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } } break; } } break; } return (s); } } int getTrueBlockSeen(int sid ) { struct my_struct *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp ; { while (1) { s = (struct my_struct *)((void *)0); if (conditions) { while (1) { _hj_key = (unsigned char *)(& sid); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct my_struct *)((void *)((char *)((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } while (s) { if ((unsigned long )s->hh.keylen == sizeof(int )) { tmp = memcmp((void const *)s->hh.key, (void const *)(& sid), sizeof(int )); if (tmp == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct my_struct *)((void *)((char *)s->hh.hh_next - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } } break; } } break; } return (s->trueblk); } } int getFalseBlockSeen(int sid ) { struct my_struct *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp ; { while (1) { s = (struct my_struct *)((void *)0); if (conditions) { while (1) { _hj_key = (unsigned char *)(& sid); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct my_struct *)((void *)((char *)((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } while (s) { if ((unsigned long )s->hh.keylen == sizeof(int )) { tmp = memcmp((void const *)s->hh.key, (void const *)(& sid), sizeof(int )); if (tmp == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct my_struct *)((void *)((char *)s->hh.hh_next - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } } break; } } break; } return (s->falseblk); } } char *getTrueExpr(int sid ) { struct my_struct *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp ; { while (1) { s = (struct my_struct *)((void *)0); if (conditions) { while (1) { _hj_key = (unsigned char *)(& sid); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct my_struct *)((void *)((char *)((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } while (s) { if ((unsigned long )s->hh.keylen == sizeof(int )) { tmp = memcmp((void const *)s->hh.key, (void const *)(& sid), sizeof(int )); if (tmp == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct my_struct *)((void *)((char *)s->hh.hh_next - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } } break; } } break; } return (s->true_expr); } } char *getFalseExpr(int sid ) { struct my_struct *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp ; { while (1) { s = (struct my_struct *)((void *)0); if (conditions) { while (1) { _hj_key = (unsigned char *)(& sid); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct my_struct *)((void *)((char *)((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } while (s) { if ((unsigned long )s->hh.keylen == sizeof(int )) { tmp = memcmp((void const *)s->hh.key, (void const *)(& sid), sizeof(int )); if (tmp == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct my_struct *)((void *)((char *)s->hh.hh_next - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } } break; } } break; } return (s->false_expr); } } void setTrueExpr(int sid , char *expr ) { char *str ; char *t ; CDGNode *temp ; char *tmp ; size_t tmp___0 ; void *tmp___1 ; struct my_struct *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp___2 ; char *tmp___3 ; size_t tmp___4 ; void *tmp___5 ; { if (CDG_Module == 1) { temp = pathNode[sid]; if ((unsigned long )temp != (unsigned long )((void *)0)) { if (temp->outcome) { t = temp->expr; free((void *)t); tmp = getPrepositionalFormula(expr); str = tmp; tmp___0 = strlen((char const *)str); tmp___1 = malloc(sizeof(char ) * (tmp___0 + 1UL)); temp->expr = (char *)tmp___1; strcpy((char * __restrict )temp->expr, (char const * __restrict )str); } } return; } while (1) { s = (struct my_struct *)((void *)0); if (conditions) { while (1) { _hj_key = (unsigned char *)(& sid); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct my_struct *)((void *)((char *)((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } while (s) { if ((unsigned long )s->hh.keylen == sizeof(int )) { tmp___2 = memcmp((void const *)s->hh.key, (void const *)(& sid), sizeof(int )); if (tmp___2 == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct my_struct *)((void *)((char *)s->hh.hh_next - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } } break; } } break; } t = s->true_expr; free((void *)t); tmp___3 = getPrepositionalFormula(expr); str = tmp___3; tmp___4 = strlen((char const *)str); tmp___5 = malloc(sizeof(char ) * (tmp___4 + 1UL)); s->true_expr = (char *)tmp___5; strcpy((char * __restrict )s->true_expr, (char const * __restrict )str); return; } } void setFalseExpr(int sid , char *expr ) { char *str ; char *t ; CDGNode *temp ; char *tmp ; size_t tmp___0 ; void *tmp___1 ; struct my_struct *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp___2 ; char *tmp___3 ; size_t tmp___4 ; void *tmp___5 ; { if (CDG_Module == 1) { temp = pathNode[sid]; if ((unsigned long )temp != (unsigned long )((void *)0)) { if (! temp->outcome) { t = temp->expr; free((void *)t); tmp = getPrepositionalFormula(expr); str = tmp; tmp___0 = strlen((char const *)str); tmp___1 = malloc(sizeof(char ) * (tmp___0 + 1UL)); temp->expr = (char *)tmp___1; strcpy((char * __restrict )temp->expr, (char const * __restrict )str); } } return; } while (1) { s = (struct my_struct *)((void *)0); if (conditions) { while (1) { _hj_key = (unsigned char *)(& sid); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct my_struct *)((void *)((char *)((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } while (s) { if ((unsigned long )s->hh.keylen == sizeof(int )) { tmp___2 = memcmp((void const *)s->hh.key, (void const *)(& sid), sizeof(int )); if (tmp___2 == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct my_struct *)((void *)((char *)s->hh.hh_next - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } } break; } } break; } t = s->false_expr; free((void *)t); tmp___3 = getPrepositionalFormula(expr); str = tmp___3; tmp___4 = strlen((char const *)str); tmp___5 = malloc(sizeof(char ) * (tmp___4 + 1UL)); s->false_expr = (char *)tmp___5; strcpy((char * __restrict )s->false_expr, (char const * __restrict )str); return; } } int countTotalConditions(void) { int count ; unsigned int tmp ; { if (conditions) { tmp = (conditions->hh.tbl)->num_items; } else { tmp = 0U; } count = (int )tmp; return (count); } } int countCoveredConditions(void) { int count ; struct my_struct *s ; { count = 0; s = conditions; while ((unsigned long )s != (unsigned long )((void *)0)) { if (s->trueblk == 1) { if (s->falseblk == 1) { count += 2; } else { goto _L___1; } } else _L___1: /* CIL Label */ if (s->trueblk == 1) { if (s->falseblk == 0) { count ++; } else if (s->falseblk == -1) { count ++; } else { goto _L___0; } } else _L___0: /* CIL Label */ if (s->trueblk == 0) { goto _L; } else if (s->trueblk == -1) { _L: /* CIL Label */ if (s->falseblk == 1) { count ++; } } s = (struct my_struct *)s->hh.next; } return (count); } } int countOrgTotalConditions(void) { int count ; struct my_struct *s ; { count = 0; s = conditions; while ((unsigned long )s != (unsigned long )((void *)0)) { if (*(unrolledCopies + s->sid) == s->sid) { count ++; } else if (*(unrolledCopies + s->sid) == -1) { count ++; } s = (struct my_struct *)s->hh.next; } return (count); } } int countOrgCoveredConditions(void) { int count ; int state ; int sid ; int tFlag ; int fFlag ; struct my_struct *s ; struct my_struct *temp ; { count = 0; tFlag = 0; fFlag = 0; s = conditions; while ((unsigned long )s != (unsigned long )((void *)0)) { state = 0; sid = *(unrolledCopies + s->sid); if (-1 != sid) { if (s->sid != sid) { goto __Cont; } } fFlag = 0; tFlag = fFlag; if (1 == s->trueblk) { tFlag = 1; } if (1 == s->falseblk) { fFlag = 1; } temp = conditions; while ((unsigned long )temp != (unsigned long )((void *)0)) { if (*(unrolledCopies + temp->sid) == s->sid) { if (temp->trueblk == 1) { tFlag = 1; } if (temp->falseblk == 1) { fFlag = 1; } } temp = (struct my_struct *)temp->hh.next; } if (tFlag) { count ++; } if (fFlag) { count ++; } __Cont: /* CIL Label */ s = (struct my_struct *)s->hh.next; } return (count); } } int getBranchInfo(int id , int branch ) { struct my_struct *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp ; { while (1) { s = (struct my_struct *)((void *)0); if (conditions) { while (1) { _hj_key = (unsigned char *)(& id); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct my_struct *)((void *)((char *)((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } while (s) { if ((unsigned long )s->hh.keylen == sizeof(int )) { tmp = memcmp((void const *)s->hh.key, (void const *)(& id), sizeof(int )); if (tmp == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct my_struct *)((void *)((char *)s->hh.hh_next - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } } break; } } break; } if (branch) { if (s) { if (s->trueblk == 0) { return (0); } return (1); } } if (! branch) { if (s) { if (s->falseblk == 0) { return (0); } return (1); } } return (1); } } void setBranchInfo(int sid , int tblk , int fblk ) { struct my_struct *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp ; { if (CDG_Module == 1) { return; } while (1) { s = (struct my_struct *)((void *)0); if (conditions) { while (1) { _hj_key = (unsigned char *)(& sid); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct my_struct *)((void *)((char *)((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } while (s) { if ((unsigned long )s->hh.keylen == sizeof(int )) { tmp = memcmp((void const *)s->hh.key, (void const *)(& sid), sizeof(int )); if (tmp == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct my_struct *)((void *)((char *)s->hh.hh_next - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } } break; } } break; } if (tblk) { if (s->trueblk != 1) { s->trueblk = tblk; } } if (fblk) { if (s->falseblk != 1) { s->falseblk = fblk; } } return; } } void updateSidForPath(int sid , int outcome ) { struct my_struct *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp ; { while (1) { s = (struct my_struct *)((void *)0); if (conditions) { while (1) { _hj_key = (unsigned char *)(& sid); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct my_struct *)((void *)((char *)((conditions->hh.tbl)->buckets + _hf_bkt)->hh_head - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } while (s) { if ((unsigned long )s->hh.keylen == sizeof(int )) { tmp = memcmp((void const *)s->hh.key, (void const *)(& sid), sizeof(int )); if (tmp == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct my_struct *)((void *)((char *)s->hh.hh_next - (conditions->hh.tbl)->hho)); break; } } else { s = (struct my_struct *)((void *)0); } } break; } } break; } if (outcome == 1) { if (s) { if (s->trueblk != 1) { s->trueblk = -1; } else { goto _L___0; } } else { goto _L___0; } } else _L___0: /* CIL Label */ if (outcome == 0) { if (s) { if (s->falseblk != 1) { s->falseblk = -1; } } } return; } } void delete_condition(struct my_struct *s ) { unsigned int _hd_bkt ; struct UT_hash_handle *_hd_hh_del ; { while (1) { if ((unsigned long )s->hh.prev == (unsigned long )((void *)0)) { if ((unsigned long )s->hh.next == (unsigned long )((void *)0)) { free((void *)(conditions->hh.tbl)->buckets); free((void *)conditions->hh.tbl); conditions = (struct my_struct *)((void *)0); } else { goto _L; } } else { _L: /* CIL Label */ _hd_hh_del = & s->hh; if ((unsigned long )s == (unsigned long )((void *)((char *)(conditions->hh.tbl)->tail - (conditions->hh.tbl)->hho))) { (conditions->hh.tbl)->tail = (UT_hash_handle *)((ptrdiff_t )s->hh.prev + (conditions->hh.tbl)->hho); } if (s->hh.prev) { ((UT_hash_handle *)((ptrdiff_t )s->hh.prev + (conditions->hh.tbl)->hho))->next = s->hh.next; } else { while (1) { conditions = (struct my_struct *)s->hh.next; break; } } if (_hd_hh_del->next) { ((UT_hash_handle *)((ptrdiff_t )_hd_hh_del->next + (conditions->hh.tbl)->hho))->prev = _hd_hh_del->prev; } while (1) { _hd_bkt = _hd_hh_del->hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } (((conditions->hh.tbl)->buckets + _hd_bkt)->count) --; if ((unsigned long )((conditions->hh.tbl)->buckets + _hd_bkt)->hh_head == (unsigned long )_hd_hh_del) { ((conditions->hh.tbl)->buckets + _hd_bkt)->hh_head = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_prev) { (_hd_hh_del->hh_prev)->hh_next = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_next) { (_hd_hh_del->hh_next)->hh_prev = _hd_hh_del->hh_prev; } ((conditions->hh.tbl)->num_items) --; } break; } free((void *)s); return; } } void delete_allConditions(void) { struct my_struct *current_con ; struct my_struct *tmp ; void *tmp___0 ; void *tmp___1 ; unsigned int _hd_bkt ; struct UT_hash_handle *_hd_hh_del ; { current_con = conditions; if (conditions) { tmp___0 = conditions->hh.next; } else { tmp___0 = (void *)0; } tmp = (struct my_struct *)tmp___0; while (current_con) { while (1) { if ((unsigned long )current_con->hh.prev == (unsigned long )((void *)0)) { if ((unsigned long )current_con->hh.next == (unsigned long )((void *)0)) { free((void *)(conditions->hh.tbl)->buckets); free((void *)conditions->hh.tbl); conditions = (struct my_struct *)((void *)0); } else { goto _L; } } else { _L: /* CIL Label */ _hd_hh_del = & current_con->hh; if ((unsigned long )current_con == (unsigned long )((void *)((char *)(conditions->hh.tbl)->tail - (conditions->hh.tbl)->hho))) { (conditions->hh.tbl)->tail = (UT_hash_handle *)((ptrdiff_t )current_con->hh.prev + (conditions->hh.tbl)->hho); } if (current_con->hh.prev) { ((UT_hash_handle *)((ptrdiff_t )current_con->hh.prev + (conditions->hh.tbl)->hho))->next = current_con->hh.next; } else { while (1) { conditions = (struct my_struct *)current_con->hh.next; break; } } if (_hd_hh_del->next) { ((UT_hash_handle *)((ptrdiff_t )_hd_hh_del->next + (conditions->hh.tbl)->hho))->prev = _hd_hh_del->prev; } while (1) { _hd_bkt = _hd_hh_del->hashv & ((conditions->hh.tbl)->num_buckets - 1U); break; } (((conditions->hh.tbl)->buckets + _hd_bkt)->count) --; if ((unsigned long )((conditions->hh.tbl)->buckets + _hd_bkt)->hh_head == (unsigned long )_hd_hh_del) { ((conditions->hh.tbl)->buckets + _hd_bkt)->hh_head = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_prev) { (_hd_hh_del->hh_prev)->hh_next = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_next) { (_hd_hh_del->hh_next)->hh_prev = _hd_hh_del->hh_prev; } ((conditions->hh.tbl)->num_items) --; } break; } free((void *)current_con); current_con = tmp; if (tmp) { tmp___1 = tmp->hh.next; } else { tmp___1 = (void *)0; } tmp = (struct my_struct *)tmp___1; } return; } } void print_conditions(void) { { return; } } #pragma merger("0","./directAndSolve.i","-g,-g") extern __attribute__((__nothrow__)) int ( __attribute__((__leaf__)) remove)(char const *__filename ) ; extern int printf(char const * __restrict __format , ...) ; extern char *fgets(char * __restrict __s , int __n , FILE * __restrict __stream ) ; extern __attribute__((__nothrow__)) int ( __attribute__((__leaf__)) feof)(FILE *__stream ) ; extern FILE *popen(char const *__command , char const *__modes ) ; extern int pclose(FILE *__stream ) ; extern __attribute__((__nothrow__)) int ( __attribute__((__nonnull__(1), __leaf__)) atoi)(char const *__nptr ) __attribute__((__pure__)) ; extern __attribute__((__nothrow__)) void *( __attribute__((__leaf__)) calloc)(size_t __nmemb , size_t __size ) __attribute__((__malloc__)) ; extern __attribute__((__nothrow__)) char *( __attribute__((__nonnull__(1,2), __leaf__)) strcat)(char * __restrict __dest , char const * __restrict __src ) ; extern __attribute__((__nothrow__)) int ( __attribute__((__nonnull__(1,2), __leaf__)) strcmp)(char const *__s1 , char const *__s2 ) __attribute__((__pure__)) ; extern __attribute__((__nothrow__)) char *( __attribute__((__nonnull__(2), __leaf__)) strtok)(char * __restrict __s , char const * __restrict __delim ) ; int getSid(struct treeNode *node ) ; struct treeNode *getFchild(struct treeNode *node ) ; struct treeNode *getNodeParent(struct treeNode *node ) ; struct treeNode *getNextnode(struct treeNode *node ) ; void clearTreeNodes(void) ; struct Queue queue ; void deQueue(void) ; void emptyQueue(void) ; enum TOKENTYPE token_type ; char *getNextTokenFromConstraintSolver(char const *str , int *pos , int length ) ; extern void getPrint() ; void constructStringToWriteinFile(char *str1 ) ; int check_level = 1; int check_position = 0; int execution_flag = 0; int countNoNewConditionAttempts = 0; float previousRunCoverage = (float )0; void printFile(char *s ) { FILE *fp ; FILE *tmp ; { tmp = fopen((char const * __restrict )"src/src/printTest.smt", (char const * __restrict )"a"); fp = tmp; if ((unsigned long )fp == (unsigned long )((void *)0)) { printf((char const * __restrict )"Error opening file!\n"); exit(1); } fprintf((FILE * __restrict )fp, (char const * __restrict )"%s", s); fclose(fp); return; } } void constructStringToWriteinFile(char *str1 ) { char *res ; char *str ; size_t tmp ; void *tmp___0 ; { tmp = strlen((char const *)str1); tmp___0 = calloc(tmp + 1UL, sizeof(char )); str = (char *)tmp___0; strcpy((char * __restrict )str, (char const * __restrict )str1); strcat((char * __restrict )str, (char const * __restrict )"\000"); printFile((char *)":extrafuns ("); res = strtok((char * __restrict )str, (char const * __restrict )"##"); while (res) { printFile((char *)"("); printFile(res); printFile((char *)" Int)"); res = strtok((char * __restrict )((void *)0), (char const * __restrict )"#"); } printFile((char *)")\n"); free((void *)str); return; } } char *getRearPathCondition(void) { char *str ; int i ; void *tmp ; struct treeNode *ptr ; { i = 1; tmp = malloc((size_t )1500); str = (char *)tmp; ptr = (queue.rear)->levelptr[i]; strcpy((char * __restrict )str, (char const * __restrict )""); while ((unsigned long )ptr != (unsigned long )((void *)0)) { if (ptr->outcome) { strcat((char * __restrict )str, (char const * __restrict )ptr->texp); } else { strcat((char * __restrict )str, (char const * __restrict )ptr->fexp); } strcat((char * __restrict )str, (char const * __restrict )"##"); ptr = getNextnode(ptr); if ((unsigned long )ptr == (unsigned long )((void *)0)) { i ++; ptr = (queue.rear)->levelptr[i]; } } strcat((char * __restrict )str, (char const * __restrict )"\000"); return (str); } } char *getFrontPathCondition(void) { char *str ; int i ; void *tmp ; struct treeNode *ptr ; { i = 1; tmp = malloc((size_t )1500); str = (char *)tmp; ptr = (queue.front)->levelptr[i]; strcpy((char * __restrict )str, (char const * __restrict )""); while ((unsigned long )ptr != (unsigned long )((void *)0)) { if (ptr->outcome) { strcat((char * __restrict )str, (char const * __restrict )ptr->texp); } else { strcat((char * __restrict )str, (char const * __restrict )ptr->fexp); } strcat((char * __restrict )str, (char const * __restrict )"##"); ptr = getNextnode(ptr); if ((unsigned long )ptr == (unsigned long )((void *)0)) { i ++; ptr = (queue.front)->levelptr[i]; } } strcat((char * __restrict )str, (char const * __restrict )"\000"); return (str); } } void writeConditionsToFile(char *str ) { char *token ; FILE *fp ; FILE *tmp ; { tmp = fopen((char const * __restrict )"src/src/printTest.smt", (char const * __restrict )"a"); fp = tmp; if ((unsigned long )fp == (unsigned long )((void *)0)) { printf((char const * __restrict )"Error opening file!\n"); exit(1); } token = strtok((char * __restrict )str, (char const * __restrict )"##"); while ((unsigned long )token != (unsigned long )((void *)0)) { strcat((char * __restrict )token, (char const * __restrict )"\000"); fprintf((FILE * __restrict )fp, (char const * __restrict )" :assumption %s\n", token); token = strtok((char * __restrict )((void *)0), (char const * __restrict )"##"); if ((unsigned long )token == (unsigned long )((void *)0)) { fprintf((FILE * __restrict )fp, (char const * __restrict )"%s", " ) "); } } fclose(fp); return; } } void updateValBySymbolicName(char *sname , void *value ) ; int getOutputFromConstraintSolver(void) { char *token ; char *save ; int i ; int len ; int value ; int negative ; FILE *pipe ; FILE *tmp ; char buffer[100] ; char result[10000] ; char *tmp___0 ; int tmp___1 ; size_t tmp___2 ; int tmp___3 ; { i = 0; negative = 0; tmp = popen("z3 -smt src/src/printTest.smt", "r"); pipe = tmp; if (! pipe) { return (0); } strcpy((char * __restrict )(result), (char const * __restrict )"\000"); while (1) { tmp___1 = feof(pipe); if (tmp___1) { break; } tmp___0 = fgets((char * __restrict )(buffer), 1000, (FILE * __restrict )pipe); if ((unsigned long )tmp___0 != (unsigned long )((void *)0)) { strcat((char * __restrict )(result), (char const * __restrict )(buffer)); } } pclose(pipe); tmp___2 = strlen((char const *)(result)); len = (int )tmp___2; token = getNextTokenFromConstraintSolver((char const *)(result), & i, len); if ((unsigned long )((void *)0) != (unsigned long )token) { tmp___3 = strcmp("unsat", (char const *)token); if (tmp___3 == 0) { return (0); } } while ((unsigned long )token != (unsigned long )((void *)0)) { negative = 0; switch ((int )token_type) { case 1: case 0: break; case 2: if ((int )*token == 45) { negative = 1; value = atoi((char const *)(token + 2)); } else { value = atoi((char const *)token); } if (negative) { value *= -1; } updateValBySymbolicName(save, & value); break; case 5: save = token; break; } token = getNextTokenFromConstraintSolver((char const *)(& result[i]), & i, len); } return (1); } } int checkForAllConstants(char const *str ) ; void writeProgramSVariables(void) ; void directPathConditions(void) { char *newPathCondition ; struct treeNode *curr ; struct treeNode *parent ; struct treeNode *temp ; int atleastOneConditionNotCovered ; int i ; float percent ; float orgPercent ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; FILE *coveragefile ; FILE *tmp___3 ; char *fpc ; char *tmp___4 ; int tmp___5 ; void *tmp___6 ; int tmp___7 ; int tmp___8 ; int tmp___9 ; int tmp___10 ; int tmp___11 ; int tmp___12 ; struct treeNode *tmp___13 ; int tmp___14 ; int tmp___15 ; int tmp___16 ; int tmp___17 ; int tmp___18 ; int tmp___19 ; int tmp___20 ; int tmp___21 ; struct treeNode *tmp___22 ; int tmp___23 ; { atleastOneConditionNotCovered = 0; i = 1; tmp = countCoveredConditions(); tmp___0 = countTotalConditions(); percent = (float )((tmp * 100) / (2 * tmp___0)); tmp___1 = countOrgCoveredConditions(); tmp___2 = countOrgTotalConditions(); orgPercent = (float )((tmp___1 * 100) / (2 * tmp___2)); printf((char const * __restrict )"COVERAGE = %f....\n", (double )orgPercent); tmp___3 = fopen((char const * __restrict )"src/src/coverage.txt", (char const * __restrict )"ab+"); coveragefile = tmp___3; fprintf((FILE * __restrict )coveragefile, (char const * __restrict )"%.1f\n", (double )orgPercent); if (queue.totalElements == 0) { emptyQueue(); return; } else if (countNoNewConditionAttempts >= 10) { emptyQueue(); return; } tmp___4 = getFrontPathCondition(); fpc = tmp___4; fpc = (char *)((void *)0); free((void *)fpc); tmp___5 = countTotalConditions(); if (tmp___5) { if (execution_flag == 1) { if (previousRunCoverage != percent) { countNoNewConditionAttempts = 0; } else { goto _L; } } else _L: /* CIL Label */ if (execution_flag == 1) { if (previousRunCoverage == percent) { countNoNewConditionAttempts ++; } } previousRunCoverage = percent; } tmp___6 = malloc((size_t )1500); newPathCondition = (char *)tmp___6; *newPathCondition = (char)0; if (check_position >= 1) { if ((unsigned long )(queue.front)->levelptr[check_level + 1] == (unsigned long )((void *)0)) { deQueue(); check_level = 1; check_position = 0; if ((unsigned long )newPathCondition != (unsigned long )((void *)0)) { newPathCondition = (char *)((void *)0); free((void *)newPathCondition); } execution_flag = 0; directPathConditions(); return; } } curr = (queue.front)->levelptr[check_level]; if (check_level == 1) { if (check_position == 0) { while ((unsigned long )curr != (unsigned long )((void *)0)) { if (curr->outcome) { tmp___7 = checkForAllConstants(curr->fexp); if (! tmp___7) { strcat((char * __restrict )newPathCondition, (char const * __restrict )curr->fexp); strcat((char * __restrict )newPathCondition, (char const * __restrict )"##"); } tmp___8 = getSid(curr); tmp___9 = getBranchInfo(tmp___8, 0); if (! tmp___9) { atleastOneConditionNotCovered = 1; } } else { tmp___10 = checkForAllConstants(curr->texp); if (! tmp___10) { strcat((char * __restrict )newPathCondition, (char const * __restrict )curr->texp); strcat((char * __restrict )newPathCondition, (char const * __restrict )"##"); } tmp___11 = getSid(curr); tmp___12 = getBranchInfo(tmp___11, 1); if (! tmp___12) { atleastOneConditionNotCovered = 1; } } curr = getNextnode(curr); } strcat((char * __restrict )newPathCondition, (char const * __restrict )"\000"); check_position ++; } else { goto _L___2; } } else { _L___2: /* CIL Label */ i = 1; while (1) { if (i < check_position) { if (! ((unsigned long )curr != (unsigned long )((void *)0))) { break; } } else { break; } curr = getNextnode(curr); i ++; } if (i < check_position) { goto _L___0; } else if (i == check_position) { if ((unsigned long )curr == (unsigned long )((void *)0)) { _L___0: /* CIL Label */ check_level ++; check_position = 1; if ((unsigned long )newPathCondition != (unsigned long )((void *)0)) { newPathCondition = (char *)((void *)0); free((void *)newPathCondition); } execution_flag = 0; directPathConditions(); return; } } tmp___13 = getFchild(curr); if ((unsigned long )tmp___13 == (unsigned long )((void *)0)) { check_position ++; if ((unsigned long )newPathCondition != (unsigned long )((void *)0)) { newPathCondition = (char *)((void *)0); free((void *)newPathCondition); } execution_flag = 0; directPathConditions(); return; } parent = curr; temp = (queue.front)->levelptr[parent->level + 1]; while ((temp->parent)->sid != parent->sid) { temp = temp->next; } curr = temp; while (1) { if ((unsigned long )curr != (unsigned long )((void *)0)) { if (! ((curr->parent)->sid == parent->sid)) { break; } } else { break; } if (curr->outcome) { tmp___14 = checkForAllConstants(curr->fexp); if (! tmp___14) { strcat((char * __restrict )newPathCondition, (char const * __restrict )curr->fexp); strcat((char * __restrict )newPathCondition, (char const * __restrict )"##"); } tmp___15 = getSid(curr); tmp___16 = getBranchInfo(tmp___15, 0); if (! tmp___16) { atleastOneConditionNotCovered = 1; } } else { tmp___17 = checkForAllConstants(curr->texp); if (! tmp___17) { strcat((char * __restrict )newPathCondition, (char const * __restrict )curr->texp); strcat((char * __restrict )newPathCondition, (char const * __restrict )"##"); } tmp___18 = getSid(curr); tmp___19 = getBranchInfo(tmp___18, 1); if (! tmp___19) { atleastOneConditionNotCovered = 1; } } curr = curr->next; } curr = parent; while ((unsigned long )curr != (unsigned long )((void *)0)) { if (curr->outcome) { tmp___21 = checkForAllConstants(curr->texp); if (tmp___21) { goto _L___1; } else { strcat((char * __restrict )newPathCondition, (char const * __restrict )curr->texp); strcat((char * __restrict )newPathCondition, (char const * __restrict )"##"); } } else { _L___1: /* CIL Label */ tmp___20 = checkForAllConstants(curr->fexp); if (! tmp___20) { strcat((char * __restrict )newPathCondition, (char const * __restrict )curr->fexp); strcat((char * __restrict )newPathCondition, (char const * __restrict )"##"); } } curr = getNodeParent(curr); } curr = (queue.front)->levelptr[check_level]; tmp___22 = getNextnode(curr); if ((unsigned long )tmp___22 == (unsigned long )((void *)0)) { check_level ++; check_position = 1; } else { check_position ++; } strcat((char * __restrict )newPathCondition, (char const * __restrict )"\000"); } if (atleastOneConditionNotCovered == 1) { if ((int )*(newPathCondition + 0) != 0) { getPrint(); writeProgramSVariables(); writeConditionsToFile(newPathCondition); tmp___23 = getOutputFromConstraintSolver(); if (! tmp___23) { remove("src/src/printTest.smt"); newPathCondition = (char *)((void *)0); free((void *)newPathCondition); execution_flag = 0; countNoNewConditionAttempts ++; directPathConditions(); return; } remove("src/src/printTest.smt"); execution_flag = 1; clearTreeNodes(); } else { goto _L___3; } } else { _L___3: /* CIL Label */ if ((unsigned long )newPathCondition != (unsigned long )((void *)0)) { newPathCondition = (char *)((void *)0); free((void *)newPathCondition); } countNoNewConditionAttempts ++; directPathConditions(); } if ((unsigned long )newPathCondition != (unsigned long )((void *)0)) { newPathCondition = (char *)((void *)0); free((void *)newPathCondition); } return; } } #pragma merger("0","./symbolicExec.i","-g,-g") extern __attribute__((__nothrow__)) void *( __attribute__((__warn_unused_result__, __leaf__)) realloc)(void *__ptr , size_t __size ) ; extern __attribute__((__nothrow__)) int sprintf(char * __restrict __s , char const * __restrict __format , ...) ; extern __attribute__((__nothrow__)) void *( __attribute__((__nonnull__(1,2), __leaf__)) memcpy)(void * __restrict __dest , void const * __restrict __src , size_t __n ) ; extern __attribute__((__nothrow__)) char *( __attribute__((__nonnull__(1,2), __leaf__)) strstr)(char const *__haystack , char const *__needle ) __attribute__((__pure__)) ; char *getNextToken(char const *str , int *pos , int length ) ; char *getAllSymbolicNamesinAPath(char *rhs ) ; struct field_values *addNewFields(char *sname , void *val , void *address , int type ) ; void add_entryToSTable(char *vname , char *sname , void *val , void *address , int type ) ; struct field_values *find_fieldValue(char *key ) ; char *find_symVal(char *key ) ; void *find_conVal(char *key ) ; int find_address(char *key ) ; void delete_entry(struct sym_table *s ) ; void delete_allSTableEntry(void) ; void print_entry(void) ; void handleAssignmentSymbolically(char *lhs , char *rhs , void *val , void *address , int type ) ; void delete_allVariableTableEntry(void) ; void addEntryToVariableTable(char *vname , int parameter ) ; int findParameter(char *key ) ; struct arraySym_table *arraySTable = (struct arraySym_table *)((void *)0); char *findArrayRecord(char *aname , int index___0 ) ; void addToIntTable(char *sname , int *val ) ; void addToFloatTable(char *sname , float *val ) ; int updateIntValBySname(char *sname , int value ) ; int updateFloatValBySname(char *sname , float value ) ; MainHT *mainHT = (MainHT *)((void *)0); static int toInt(void *addr ) { { return ((int )((size_t )addr % 2147483647UL)); } } struct sym_table *stable = (struct sym_table *)((void *)0); struct variable_table *varTable = (struct variable_table *)((void *)0); struct field_values *addNewFields(char *sname , void *val , void *address , int type ) { struct field_values *t ; int size ; void *tmp ; size_t tmp___0 ; void *tmp___1 ; char *tmp___2 ; int tmp___3 ; int tmp___4 ; char *tmp___5 ; int tmp___6 ; int tmp___7 ; { tmp = malloc(sizeof(struct field_values )); t = (struct field_values *)tmp; tmp___0 = strlen((char const *)sname); tmp___1 = calloc(tmp___0 + 1UL, sizeof(char )); t->sname = (char *)tmp___1; strcpy((char * __restrict )t->sname, (char const * __restrict )sname); if (type == 1) { size = (int )sizeof(int ); tmp___2 = strstr((char const *)sname, "structVar"); if ((unsigned long )tmp___2 == (unsigned long )((void *)0)) { tmp___3 = strcmp((char const *)sname, "Constant"); if (tmp___3 != 0) { tmp___4 = strcmp((char const *)sname, "Function"); if (tmp___4 != 0) { addToIntTable(sname, (int *)val); } } } } else { size = (int )sizeof(float ); tmp___5 = strstr((char const *)sname, "structVar"); if ((unsigned long )tmp___5 == (unsigned long )((void *)0)) { tmp___6 = strcmp((char const *)sname, "Constant"); if (tmp___6 != 0) { tmp___7 = strcmp((char const *)sname, "Function"); if (tmp___7 != 0) { addToFloatTable(t->sname, (float *)val); } } } } t->cval = malloc((size_t )size); memcpy((void * __restrict )t->cval, (void const * __restrict )val, (size_t )size); t->address = toInt(address); t->type = type; return (t); } } void add_entryToSTable(char *vname , char *sname , void *val , void *address , int type ) { struct sym_table *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; size_t tmp ; size_t tmp___0 ; size_t tmp___1 ; int tmp___2 ; size_t tmp___3 ; void *tmp___4 ; size_t tmp___5 ; void *tmp___6 ; unsigned int _ha_bkt ; size_t tmp___7 ; void *tmp___8 ; void *tmp___9 ; unsigned int _hj_i___0 ; unsigned int _hj_j___0 ; unsigned int _hj_k___0 ; unsigned char *_hj_key___0 ; size_t tmp___10 ; size_t tmp___11 ; unsigned int _he_bkt ; unsigned int _he_bkt_i ; struct UT_hash_handle *_he_thh ; struct UT_hash_handle *_he_hh_nxt ; UT_hash_bucket *_he_new_buckets ; UT_hash_bucket *_he_newbkt ; void *tmp___12 ; int tmp___13 ; { while (1) { s = (struct sym_table *)((void *)0); if (stable) { while (1) { _hj_key = (unsigned char *)vname; _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; tmp = strlen((char const *)vname); _hj_k = (unsigned int )tmp; while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } tmp___0 = strlen((char const *)vname); _hf_hashv = (unsigned int )((size_t )_hf_hashv + tmp___0); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((stable->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((stable->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct sym_table *)((void *)((char *)((stable->hh.tbl)->buckets + _hf_bkt)->hh_head - (stable->hh.tbl)->hho)); break; } } else { s = (struct sym_table *)((void *)0); } while (s) { tmp___3 = strlen((char const *)vname); if ((size_t )s->hh.keylen == tmp___3) { tmp___1 = strlen((char const *)vname); tmp___2 = memcmp((void const *)s->hh.key, (void const *)vname, tmp___1); if (tmp___2 == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct sym_table *)((void *)((char *)s->hh.hh_next - (stable->hh.tbl)->hho)); break; } } else { s = (struct sym_table *)((void *)0); } } break; } } break; } if ((unsigned long )s == (unsigned long )((void *)0)) { tmp___4 = malloc(sizeof(struct sym_table )); s = (struct sym_table *)tmp___4; tmp___5 = strlen((char const *)vname); tmp___6 = calloc(tmp___5 + 1UL, sizeof(char )); s->vname = (char *)tmp___6; strcpy((char * __restrict )s->vname, (char const * __restrict )vname); while (1) { s->hh.next = (void *)0; s->hh.key = (void *)(s->vname + 0); tmp___7 = strlen((char const *)s->vname); s->hh.keylen = (unsigned int )tmp___7; if (! stable) { stable = s; stable->hh.prev = (void *)0; while (1) { tmp___8 = malloc(sizeof(UT_hash_table )); stable->hh.tbl = (UT_hash_table *)tmp___8; if (! stable->hh.tbl) { exit(-1); } memset((void *)stable->hh.tbl, 0, sizeof(UT_hash_table )); (stable->hh.tbl)->tail = & stable->hh; (stable->hh.tbl)->num_buckets = 32U; (stable->hh.tbl)->log2_num_buckets = 5U; (stable->hh.tbl)->hho = (char *)(& stable->hh) - (char *)stable; tmp___9 = malloc(32UL * sizeof(struct UT_hash_bucket )); (stable->hh.tbl)->buckets = (UT_hash_bucket *)tmp___9; if (! (stable->hh.tbl)->buckets) { exit(-1); } memset((void *)(stable->hh.tbl)->buckets, 0, 32UL * sizeof(struct UT_hash_bucket )); (stable->hh.tbl)->signature = 2685476833U; break; } } else { ((stable->hh.tbl)->tail)->next = (void *)s; s->hh.prev = (void *)((char *)(stable->hh.tbl)->tail - (stable->hh.tbl)->hho); (stable->hh.tbl)->tail = & s->hh; } ((stable->hh.tbl)->num_items) ++; s->hh.tbl = stable->hh.tbl; while (1) { _hj_key___0 = (unsigned char *)(s->vname + 0); s->hh.hashv = 4276993775U; _hj_j___0 = 2654435769U; _hj_i___0 = _hj_j___0; tmp___10 = strlen((char const *)s->vname); _hj_k___0 = (unsigned int )tmp___10; while (_hj_k___0 >= 12U) { _hj_i___0 += (((unsigned int )*(_hj_key___0 + 0) + ((unsigned int )*(_hj_key___0 + 1) << 8)) + ((unsigned int )*(_hj_key___0 + 2) << 16)) + ((unsigned int )*(_hj_key___0 + 3) << 24); _hj_j___0 += (((unsigned int )*(_hj_key___0 + 4) + ((unsigned int )*(_hj_key___0 + 5) << 8)) + ((unsigned int )*(_hj_key___0 + 6) << 16)) + ((unsigned int )*(_hj_key___0 + 7) << 24); s->hh.hashv += (((unsigned int )*(_hj_key___0 + 8) + ((unsigned int )*(_hj_key___0 + 9) << 8)) + ((unsigned int )*(_hj_key___0 + 10) << 16)) + ((unsigned int )*(_hj_key___0 + 11) << 24); while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 13; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 12; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 3; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 15; break; } _hj_key___0 += 12; _hj_k___0 -= 12U; } tmp___11 = strlen((char const *)s->vname); s->hh.hashv = (unsigned int )((size_t )s->hh.hashv + tmp___11); switch (_hj_k___0) { case 11U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 10) << 24; case 10U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 9) << 16; case 9U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 8) << 8; case 8U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 7) << 24; case 7U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 6) << 16; case 6U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 5) << 8; case 5U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 4); case 4U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 3) << 24; case 3U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 2) << 16; case 2U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 1) << 8; case 1U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 0); } while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 13; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 12; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 3; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 15; break; } _ha_bkt = s->hh.hashv & ((stable->hh.tbl)->num_buckets - 1U); break; } while (1) { (((stable->hh.tbl)->buckets + _ha_bkt)->count) ++; s->hh.hh_next = ((stable->hh.tbl)->buckets + _ha_bkt)->hh_head; s->hh.hh_prev = (struct UT_hash_handle *)((void *)0); if (((stable->hh.tbl)->buckets + _ha_bkt)->hh_head) { (((stable->hh.tbl)->buckets + _ha_bkt)->hh_head)->hh_prev = & s->hh; } ((stable->hh.tbl)->buckets + _ha_bkt)->hh_head = & s->hh; if (((stable->hh.tbl)->buckets + _ha_bkt)->count >= (((stable->hh.tbl)->buckets + _ha_bkt)->expand_mult + 1U) * 10U) { if ((s->hh.tbl)->noexpand != 1U) { while (1) { tmp___12 = malloc((unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); _he_new_buckets = (UT_hash_bucket *)tmp___12; if (! _he_new_buckets) { exit(-1); } memset((void *)_he_new_buckets, 0, (unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); if ((s->hh.tbl)->num_items & ((s->hh.tbl)->num_buckets * 2U - 1U)) { tmp___13 = 1; } else { tmp___13 = 0; } (s->hh.tbl)->ideal_chain_maxlen = ((s->hh.tbl)->num_items >> ((s->hh.tbl)->log2_num_buckets + 1U)) + (unsigned int )tmp___13; (s->hh.tbl)->nonideal_items = 0U; _he_bkt_i = 0U; while (_he_bkt_i < (s->hh.tbl)->num_buckets) { _he_thh = ((s->hh.tbl)->buckets + _he_bkt_i)->hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; while (1) { _he_bkt = _he_thh->hashv & ((s->hh.tbl)->num_buckets * 2U - 1U); break; } _he_newbkt = _he_new_buckets + _he_bkt; (_he_newbkt->count) ++; if (_he_newbkt->count > (s->hh.tbl)->ideal_chain_maxlen) { ((s->hh.tbl)->nonideal_items) ++; _he_newbkt->expand_mult = _he_newbkt->count / (s->hh.tbl)->ideal_chain_maxlen; } _he_thh->hh_prev = (struct UT_hash_handle *)((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) { (_he_newbkt->hh_head)->hh_prev = _he_thh; } _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } _he_bkt_i ++; } free((void *)(s->hh.tbl)->buckets); (s->hh.tbl)->num_buckets *= 2U; ((s->hh.tbl)->log2_num_buckets) ++; (s->hh.tbl)->buckets = _he_new_buckets; if ((s->hh.tbl)->nonideal_items > (s->hh.tbl)->num_items >> 1) { ((s->hh.tbl)->ineff_expands) ++; } else { (s->hh.tbl)->ineff_expands = 0U; } if ((s->hh.tbl)->ineff_expands > 1U) { (s->hh.tbl)->noexpand = 1U; } break; } } } break; } break; } } s->fval = addNewFields(sname, val, address, type); return; } } void addEntryToVariableTable(char *vname , int parameter ) { struct variable_table *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; size_t tmp ; size_t tmp___0 ; size_t tmp___1 ; int tmp___2 ; size_t tmp___3 ; void *tmp___4 ; size_t tmp___5 ; void *tmp___6 ; unsigned int _ha_bkt ; size_t tmp___7 ; void *tmp___8 ; void *tmp___9 ; unsigned int _hj_i___0 ; unsigned int _hj_j___0 ; unsigned int _hj_k___0 ; unsigned char *_hj_key___0 ; size_t tmp___10 ; size_t tmp___11 ; unsigned int _he_bkt ; unsigned int _he_bkt_i ; struct UT_hash_handle *_he_thh ; struct UT_hash_handle *_he_hh_nxt ; UT_hash_bucket *_he_new_buckets ; UT_hash_bucket *_he_newbkt ; void *tmp___12 ; int tmp___13 ; { while (1) { s = (struct variable_table *)((void *)0); if (varTable) { while (1) { _hj_key = (unsigned char *)vname; _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; tmp = strlen((char const *)vname); _hj_k = (unsigned int )tmp; while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } tmp___0 = strlen((char const *)vname); _hf_hashv = (unsigned int )((size_t )_hf_hashv + tmp___0); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((varTable->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((varTable->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct variable_table *)((void *)((char *)((varTable->hh.tbl)->buckets + _hf_bkt)->hh_head - (varTable->hh.tbl)->hho)); break; } } else { s = (struct variable_table *)((void *)0); } while (s) { tmp___3 = strlen((char const *)vname); if ((size_t )s->hh.keylen == tmp___3) { tmp___1 = strlen((char const *)vname); tmp___2 = memcmp((void const *)s->hh.key, (void const *)vname, tmp___1); if (tmp___2 == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct variable_table *)((void *)((char *)s->hh.hh_next - (varTable->hh.tbl)->hho)); break; } } else { s = (struct variable_table *)((void *)0); } } break; } } break; } if ((unsigned long )s == (unsigned long )((void *)0)) { tmp___4 = malloc(sizeof(struct variable_table )); s = (struct variable_table *)tmp___4; tmp___5 = strlen((char const *)vname); tmp___6 = calloc(tmp___5 + 1UL, sizeof(char )); s->varName = (char *)tmp___6; strcpy((char * __restrict )s->varName, (char const * __restrict )vname); while (1) { s->hh.next = (void *)0; s->hh.key = (void *)(s->varName + 0); tmp___7 = strlen((char const *)s->varName); s->hh.keylen = (unsigned int )tmp___7; if (! varTable) { varTable = s; varTable->hh.prev = (void *)0; while (1) { tmp___8 = malloc(sizeof(UT_hash_table )); varTable->hh.tbl = (UT_hash_table *)tmp___8; if (! varTable->hh.tbl) { exit(-1); } memset((void *)varTable->hh.tbl, 0, sizeof(UT_hash_table )); (varTable->hh.tbl)->tail = & varTable->hh; (varTable->hh.tbl)->num_buckets = 32U; (varTable->hh.tbl)->log2_num_buckets = 5U; (varTable->hh.tbl)->hho = (char *)(& varTable->hh) - (char *)varTable; tmp___9 = malloc(32UL * sizeof(struct UT_hash_bucket )); (varTable->hh.tbl)->buckets = (UT_hash_bucket *)tmp___9; if (! (varTable->hh.tbl)->buckets) { exit(-1); } memset((void *)(varTable->hh.tbl)->buckets, 0, 32UL * sizeof(struct UT_hash_bucket )); (varTable->hh.tbl)->signature = 2685476833U; break; } } else { ((varTable->hh.tbl)->tail)->next = (void *)s; s->hh.prev = (void *)((char *)(varTable->hh.tbl)->tail - (varTable->hh.tbl)->hho); (varTable->hh.tbl)->tail = & s->hh; } ((varTable->hh.tbl)->num_items) ++; s->hh.tbl = varTable->hh.tbl; while (1) { _hj_key___0 = (unsigned char *)(s->varName + 0); s->hh.hashv = 4276993775U; _hj_j___0 = 2654435769U; _hj_i___0 = _hj_j___0; tmp___10 = strlen((char const *)s->varName); _hj_k___0 = (unsigned int )tmp___10; while (_hj_k___0 >= 12U) { _hj_i___0 += (((unsigned int )*(_hj_key___0 + 0) + ((unsigned int )*(_hj_key___0 + 1) << 8)) + ((unsigned int )*(_hj_key___0 + 2) << 16)) + ((unsigned int )*(_hj_key___0 + 3) << 24); _hj_j___0 += (((unsigned int )*(_hj_key___0 + 4) + ((unsigned int )*(_hj_key___0 + 5) << 8)) + ((unsigned int )*(_hj_key___0 + 6) << 16)) + ((unsigned int )*(_hj_key___0 + 7) << 24); s->hh.hashv += (((unsigned int )*(_hj_key___0 + 8) + ((unsigned int )*(_hj_key___0 + 9) << 8)) + ((unsigned int )*(_hj_key___0 + 10) << 16)) + ((unsigned int )*(_hj_key___0 + 11) << 24); while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 13; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 12; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 3; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 15; break; } _hj_key___0 += 12; _hj_k___0 -= 12U; } tmp___11 = strlen((char const *)s->varName); s->hh.hashv = (unsigned int )((size_t )s->hh.hashv + tmp___11); switch (_hj_k___0) { case 11U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 10) << 24; case 10U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 9) << 16; case 9U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 8) << 8; case 8U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 7) << 24; case 7U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 6) << 16; case 6U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 5) << 8; case 5U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 4); case 4U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 3) << 24; case 3U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 2) << 16; case 2U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 1) << 8; case 1U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 0); } while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 13; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 12; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 3; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 15; break; } _ha_bkt = s->hh.hashv & ((varTable->hh.tbl)->num_buckets - 1U); break; } while (1) { (((varTable->hh.tbl)->buckets + _ha_bkt)->count) ++; s->hh.hh_next = ((varTable->hh.tbl)->buckets + _ha_bkt)->hh_head; s->hh.hh_prev = (struct UT_hash_handle *)((void *)0); if (((varTable->hh.tbl)->buckets + _ha_bkt)->hh_head) { (((varTable->hh.tbl)->buckets + _ha_bkt)->hh_head)->hh_prev = & s->hh; } ((varTable->hh.tbl)->buckets + _ha_bkt)->hh_head = & s->hh; if (((varTable->hh.tbl)->buckets + _ha_bkt)->count >= (((varTable->hh.tbl)->buckets + _ha_bkt)->expand_mult + 1U) * 10U) { if ((s->hh.tbl)->noexpand != 1U) { while (1) { tmp___12 = malloc((unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); _he_new_buckets = (UT_hash_bucket *)tmp___12; if (! _he_new_buckets) { exit(-1); } memset((void *)_he_new_buckets, 0, (unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); if ((s->hh.tbl)->num_items & ((s->hh.tbl)->num_buckets * 2U - 1U)) { tmp___13 = 1; } else { tmp___13 = 0; } (s->hh.tbl)->ideal_chain_maxlen = ((s->hh.tbl)->num_items >> ((s->hh.tbl)->log2_num_buckets + 1U)) + (unsigned int )tmp___13; (s->hh.tbl)->nonideal_items = 0U; _he_bkt_i = 0U; while (_he_bkt_i < (s->hh.tbl)->num_buckets) { _he_thh = ((s->hh.tbl)->buckets + _he_bkt_i)->hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; while (1) { _he_bkt = _he_thh->hashv & ((s->hh.tbl)->num_buckets * 2U - 1U); break; } _he_newbkt = _he_new_buckets + _he_bkt; (_he_newbkt->count) ++; if (_he_newbkt->count > (s->hh.tbl)->ideal_chain_maxlen) { ((s->hh.tbl)->nonideal_items) ++; _he_newbkt->expand_mult = _he_newbkt->count / (s->hh.tbl)->ideal_chain_maxlen; } _he_thh->hh_prev = (struct UT_hash_handle *)((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) { (_he_newbkt->hh_head)->hh_prev = _he_thh; } _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } _he_bkt_i ++; } free((void *)(s->hh.tbl)->buckets); (s->hh.tbl)->num_buckets *= 2U; ((s->hh.tbl)->log2_num_buckets) ++; (s->hh.tbl)->buckets = _he_new_buckets; if ((s->hh.tbl)->nonideal_items > (s->hh.tbl)->num_items >> 1) { ((s->hh.tbl)->ineff_expands) ++; } else { (s->hh.tbl)->ineff_expands = 0U; } if ((s->hh.tbl)->ineff_expands > 1U) { (s->hh.tbl)->noexpand = 1U; } break; } } } break; } break; } s->parameter = parameter; } return; } } int findParameter(char *key ) { struct variable_table *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; size_t tmp ; size_t tmp___0 ; size_t tmp___1 ; int tmp___2 ; size_t tmp___3 ; { while (1) { s = (struct variable_table *)((void *)0); if (varTable) { while (1) { _hj_key = (unsigned char *)key; _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; tmp = strlen((char const *)key); _hj_k = (unsigned int )tmp; while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } tmp___0 = strlen((char const *)key); _hf_hashv = (unsigned int )((size_t )_hf_hashv + tmp___0); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((varTable->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((varTable->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct variable_table *)((void *)((char *)((varTable->hh.tbl)->buckets + _hf_bkt)->hh_head - (varTable->hh.tbl)->hho)); break; } } else { s = (struct variable_table *)((void *)0); } while (s) { tmp___3 = strlen((char const *)key); if ((size_t )s->hh.keylen == tmp___3) { tmp___1 = strlen((char const *)key); tmp___2 = memcmp((void const *)s->hh.key, (void const *)key, tmp___1); if (tmp___2 == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct variable_table *)((void *)((char *)s->hh.hh_next - (varTable->hh.tbl)->hho)); break; } } else { s = (struct variable_table *)((void *)0); } } break; } } break; } return (s->parameter); } } struct field_values *find_fieldValue(char *key ) { struct sym_table *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; size_t tmp ; size_t tmp___0 ; size_t tmp___1 ; int tmp___2 ; size_t tmp___3 ; { while (1) { s = (struct sym_table *)((void *)0); if (stable) { while (1) { _hj_key = (unsigned char *)key; _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; tmp = strlen((char const *)key); _hj_k = (unsigned int )tmp; while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } tmp___0 = strlen((char const *)key); _hf_hashv = (unsigned int )((size_t )_hf_hashv + tmp___0); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((stable->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((stable->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct sym_table *)((void *)((char *)((stable->hh.tbl)->buckets + _hf_bkt)->hh_head - (stable->hh.tbl)->hho)); break; } } else { s = (struct sym_table *)((void *)0); } while (s) { tmp___3 = strlen((char const *)key); if ((size_t )s->hh.keylen == tmp___3) { tmp___1 = strlen((char const *)key); tmp___2 = memcmp((void const *)s->hh.key, (void const *)key, tmp___1); if (tmp___2 == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct sym_table *)((void *)((char *)s->hh.hh_next - (stable->hh.tbl)->hho)); break; } } else { s = (struct sym_table *)((void *)0); } } break; } } break; } if ((unsigned long )s == (unsigned long )((void *)0)) { return ((struct field_values *)((void *)0)); } return (s->fval); } } char *find_symVal(char *key ) { struct field_values *fv ; { fv = find_fieldValue(key); if ((unsigned long )fv == (unsigned long )((void *)0)) { return ((char *)((void *)0)); } return (fv->sname); } } void *find_conVal(char *key ) { struct field_values *fv ; { fv = find_fieldValue(key); return (fv->cval); } } int find_address(char *key ) { struct field_values *fv ; { fv = find_fieldValue(key); return (fv->address); } } void delete_entry(struct sym_table *s ) { unsigned int _hd_bkt ; struct UT_hash_handle *_hd_hh_del ; { while (1) { if ((unsigned long )s->hh.prev == (unsigned long )((void *)0)) { if ((unsigned long )s->hh.next == (unsigned long )((void *)0)) { free((void *)(stable->hh.tbl)->buckets); free((void *)stable->hh.tbl); stable = (struct sym_table *)((void *)0); } else { goto _L; } } else { _L: /* CIL Label */ _hd_hh_del = & s->hh; if ((unsigned long )s == (unsigned long )((void *)((char *)(stable->hh.tbl)->tail - (stable->hh.tbl)->hho))) { (stable->hh.tbl)->tail = (UT_hash_handle *)((ptrdiff_t )s->hh.prev + (stable->hh.tbl)->hho); } if (s->hh.prev) { ((UT_hash_handle *)((ptrdiff_t )s->hh.prev + (stable->hh.tbl)->hho))->next = s->hh.next; } else { while (1) { stable = (struct sym_table *)s->hh.next; break; } } if (_hd_hh_del->next) { ((UT_hash_handle *)((ptrdiff_t )_hd_hh_del->next + (stable->hh.tbl)->hho))->prev = _hd_hh_del->prev; } while (1) { _hd_bkt = _hd_hh_del->hashv & ((stable->hh.tbl)->num_buckets - 1U); break; } (((stable->hh.tbl)->buckets + _hd_bkt)->count) --; if ((unsigned long )((stable->hh.tbl)->buckets + _hd_bkt)->hh_head == (unsigned long )_hd_hh_del) { ((stable->hh.tbl)->buckets + _hd_bkt)->hh_head = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_prev) { (_hd_hh_del->hh_prev)->hh_next = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_next) { (_hd_hh_del->hh_next)->hh_prev = _hd_hh_del->hh_prev; } ((stable->hh.tbl)->num_items) --; } break; } free((void *)s); return; } } void delete_allSTableEntry(void) { struct sym_table *current_entry ; struct sym_table *tmp ; void *tmp___0 ; void *tmp___1 ; unsigned int _hd_bkt ; struct UT_hash_handle *_hd_hh_del ; { current_entry = stable; if (stable) { tmp___0 = stable->hh.next; } else { tmp___0 = (void *)0; } tmp = (struct sym_table *)tmp___0; while (current_entry) { while (1) { if ((unsigned long )current_entry->hh.prev == (unsigned long )((void *)0)) { if ((unsigned long )current_entry->hh.next == (unsigned long )((void *)0)) { free((void *)(stable->hh.tbl)->buckets); free((void *)stable->hh.tbl); stable = (struct sym_table *)((void *)0); } else { goto _L; } } else { _L: /* CIL Label */ _hd_hh_del = & current_entry->hh; if ((unsigned long )current_entry == (unsigned long )((void *)((char *)(stable->hh.tbl)->tail - (stable->hh.tbl)->hho))) { (stable->hh.tbl)->tail = (UT_hash_handle *)((ptrdiff_t )current_entry->hh.prev + (stable->hh.tbl)->hho); } if (current_entry->hh.prev) { ((UT_hash_handle *)((ptrdiff_t )current_entry->hh.prev + (stable->hh.tbl)->hho))->next = current_entry->hh.next; } else { while (1) { stable = (struct sym_table *)current_entry->hh.next; break; } } if (_hd_hh_del->next) { ((UT_hash_handle *)((ptrdiff_t )_hd_hh_del->next + (stable->hh.tbl)->hho))->prev = _hd_hh_del->prev; } while (1) { _hd_bkt = _hd_hh_del->hashv & ((stable->hh.tbl)->num_buckets - 1U); break; } (((stable->hh.tbl)->buckets + _hd_bkt)->count) --; if ((unsigned long )((stable->hh.tbl)->buckets + _hd_bkt)->hh_head == (unsigned long )_hd_hh_del) { ((stable->hh.tbl)->buckets + _hd_bkt)->hh_head = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_prev) { (_hd_hh_del->hh_prev)->hh_next = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_next) { (_hd_hh_del->hh_next)->hh_prev = _hd_hh_del->hh_prev; } ((stable->hh.tbl)->num_items) --; } break; } free((void *)current_entry); current_entry = tmp; if (tmp) { tmp___1 = tmp->hh.next; } else { tmp___1 = (void *)0; } tmp = (struct sym_table *)tmp___1; } return; } } void delete_allVariableTableEntry(void) { struct variable_table *current_entry ; struct variable_table *tmp ; void *tmp___0 ; void *tmp___1 ; unsigned int _hd_bkt ; struct UT_hash_handle *_hd_hh_del ; { current_entry = varTable; if (varTable) { tmp___0 = varTable->hh.next; } else { tmp___0 = (void *)0; } tmp = (struct variable_table *)tmp___0; while (current_entry) { while (1) { if ((unsigned long )current_entry->hh.prev == (unsigned long )((void *)0)) { if ((unsigned long )current_entry->hh.next == (unsigned long )((void *)0)) { free((void *)(varTable->hh.tbl)->buckets); free((void *)varTable->hh.tbl); varTable = (struct variable_table *)((void *)0); } else { goto _L; } } else { _L: /* CIL Label */ _hd_hh_del = & current_entry->hh; if ((unsigned long )current_entry == (unsigned long )((void *)((char *)(varTable->hh.tbl)->tail - (varTable->hh.tbl)->hho))) { (varTable->hh.tbl)->tail = (UT_hash_handle *)((ptrdiff_t )current_entry->hh.prev + (varTable->hh.tbl)->hho); } if (current_entry->hh.prev) { ((UT_hash_handle *)((ptrdiff_t )current_entry->hh.prev + (varTable->hh.tbl)->hho))->next = current_entry->hh.next; } else { while (1) { varTable = (struct variable_table *)current_entry->hh.next; break; } } if (_hd_hh_del->next) { ((UT_hash_handle *)((ptrdiff_t )_hd_hh_del->next + (varTable->hh.tbl)->hho))->prev = _hd_hh_del->prev; } while (1) { _hd_bkt = _hd_hh_del->hashv & ((varTable->hh.tbl)->num_buckets - 1U); break; } (((varTable->hh.tbl)->buckets + _hd_bkt)->count) --; if ((unsigned long )((varTable->hh.tbl)->buckets + _hd_bkt)->hh_head == (unsigned long )_hd_hh_del) { ((varTable->hh.tbl)->buckets + _hd_bkt)->hh_head = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_prev) { (_hd_hh_del->hh_prev)->hh_next = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_next) { (_hd_hh_del->hh_next)->hh_prev = _hd_hh_del->hh_prev; } ((varTable->hh.tbl)->num_items) --; } break; } free((void *)current_entry); current_entry = tmp; if (tmp) { tmp___1 = tmp->hh.next; } else { tmp___1 = (void *)0; } tmp = (struct variable_table *)tmp___1; } return; } } void print_entry(void) { struct sym_table *s ; int tmp ; void *tmp___0 ; char *tmp___1 ; { s = stable; while ((unsigned long )s != (unsigned long )((void *)0)) { tmp = find_address(s->vname); tmp___0 = find_conVal(s->vname); tmp___1 = find_symVal(s->vname); printf((char const * __restrict )"variable name %s: symbolic name: %s concrete value:%d address:%d\n", s->vname, tmp___1, *((int *)tmp___0), tmp); s = (struct sym_table *)s->hh.next; } return; } } void updateValBySymbolicName(char *sname , void *value ) { struct sym_table *s ; struct arraySym_table *s1 ; int size ; char *tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; { size = (int )sizeof(int ); s = stable; while ((unsigned long )s != (unsigned long )((void *)0)) { tmp = find_symVal(s->vname); tmp___0 = strcmp((char const *)tmp, (char const *)sname); if (tmp___0 == 0) { memcpy((void * __restrict )(s->fval)->cval, (void const * __restrict )value, (size_t )size); if ((s->fval)->type == 1) { updateIntValBySname(sname, *((int *)value)); } else if (*((int *)value) < 0) { updateFloatValBySname(sname, (float )*((int *)value)); } else { updateFloatValBySname(sname, *((float *)value)); } return; } s = (struct sym_table *)s->hh.next; } s1 = arraySTable; while ((unsigned long )s1 != (unsigned long )((void *)0)) { tmp___1 = strcmp((char const *)(s1->sname), (char const *)sname); if (tmp___1 == 0) { memcpy((void * __restrict )s1->cval, (void const * __restrict )value, (size_t )size); if (s1->type == 1) { updateIntValBySname(sname, *((int *)value)); } else { updateFloatValBySname(sname, *((float *)value)); } return; } s1 = (struct arraySym_table *)s1->hh.next; } tmp___2 = updateIntValBySname(sname, *((int *)value)); if (! tmp___2) { if (*((int *)value) < 0) { updateFloatValBySname(sname, (float )*((int *)value)); } else { updateFloatValBySname(sname, *((float *)value)); } } return; } } void *findValBySymbolicName(char *sname ) { struct sym_table *s ; char *tmp ; int tmp___0 ; { s = stable; while ((unsigned long )s != (unsigned long )((void *)0)) { tmp = find_symVal(s->vname); tmp___0 = strcmp((char const *)tmp, (char const *)sname); if (tmp___0 == 0) { return ((s->fval)->cval); } s = (struct sym_table *)s->hh.next; } return ((void *)0); } } char *getAllSymbolicNamesinAPath(char *rhs ) { char *token ; char *result ; int i ; int len ; void *tmp ; size_t tmp___0 ; size_t tmp___1 ; size_t tmp___2 ; void *tmp___3 ; int tmp___4 ; { i = 0; tmp = calloc((size_t )2, sizeof(char )); result = (char *)tmp; tmp___0 = strlen((char const *)rhs); len = (int )tmp___0; token = getNextToken((char const *)rhs, & i, len); while ((unsigned long )token != (unsigned long )((void *)0)) { free((void *)token); token = getNextToken((char const *)(rhs + i), & i, len); switch ((int )token_type) { case 2: case 1: case 0: break; case 5: tmp___4 = strcmp((char const *)token, "not"); if (tmp___4 != 0) { tmp___1 = strlen((char const *)result); tmp___2 = strlen((char const *)token); tmp___3 = realloc((void *)result, (((tmp___1 + tmp___2) + 1UL) + 2UL) * sizeof(char )); result = (char *)tmp___3; strcat((char * __restrict )result, (char const * __restrict )token); strcat((char * __restrict )result, (char const * __restrict )"##"); } break; } } strcat((char * __restrict )result, (char const * __restrict )"\000"); return (result); } } char *getArrayName(char const *str ) ; void handleAssignmentSymbolically(char *lhs , char *rhs , void *val , void *address , int type ) { int i ; int len ; int parameter ; int j ; int value ; char *token ; char *result ; char *symName ; char *temp ; char buff[15] ; void *tmp ; size_t tmp___0 ; size_t tmp___1 ; size_t tmp___2 ; void *tmp___3 ; int tmp___4 ; int tmp___5 ; void *tmp___6 ; size_t tmp___7 ; size_t tmp___8 ; void *tmp___9 ; void *tmp___10 ; size_t tmp___11 ; size_t tmp___12 ; void *tmp___13 ; size_t tmp___14 ; size_t tmp___15 ; void *tmp___16 ; int tmp___17 ; int tmp___18 ; int tmp___19 ; void *tmp___20 ; size_t tmp___21 ; size_t tmp___22 ; void *tmp___23 ; void *tmp___24 ; size_t tmp___25 ; size_t tmp___26 ; void *tmp___27 ; size_t tmp___28 ; size_t tmp___29 ; void *tmp___30 ; int tmp___31 ; int tmp___32 ; void *tmp___33 ; size_t tmp___34 ; size_t tmp___35 ; void *tmp___36 ; void *tmp___37 ; size_t tmp___38 ; size_t tmp___39 ; void *tmp___40 ; size_t tmp___41 ; size_t tmp___42 ; void *tmp___43 ; int tmp___44 ; int tmp___45 ; { i = 0; tmp = calloc((size_t )2, sizeof(char )); result = (char *)tmp; tmp___0 = strlen((char const *)rhs); len = (int )tmp___0; token = getNextToken((char const *)rhs, & i, len); while ((unsigned long )token != (unsigned long )((void *)0)) { switch ((int )token_type) { case 2: case 1: case 0: tmp___1 = strlen((char const *)result); tmp___2 = strlen((char const *)token); tmp___3 = realloc((void *)result, ((tmp___1 + tmp___2) + 1UL) * sizeof(char )); result = (char *)tmp___3; strcat((char * __restrict )result, (char const * __restrict )token); break; case 3: parameter = findParameter(token); j = 0; while (j < 2 * parameter + 1) { symName = find_symVal(temp); if ((unsigned long )symName == (unsigned long )((void *)0)) { tmp___4 = findParameter(temp); tmp___5 = (int )getArrayName(temp); symName = findArrayRecord((char *)tmp___5, tmp___4); } temp = symName; j ++; } if ((unsigned long )symName != (unsigned long )((void *)0)) { tmp___18 = strcmp((char const *)symName, "Constant"); if (tmp___18 == 0) { tmp___6 = findValBySymbolicName(symName); value = *((int *)tmp___6); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", value); tmp___7 = strlen((char const *)result); tmp___8 = strlen((char const *)(buff)); tmp___9 = realloc((void *)result, ((tmp___7 + tmp___8) + 1UL) * sizeof(char )); result = (char *)tmp___9; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___17 = strcmp((char const *)symName, "Function"); if (tmp___17 == 0) { tmp___10 = findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___10)); tmp___11 = strlen((char const *)result); tmp___12 = strlen((char const *)(buff)); tmp___13 = realloc((void *)result, ((tmp___11 + tmp___12) + 1UL) * sizeof(char )); result = (char *)tmp___13; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___14 = strlen((char const *)result); tmp___15 = strlen((char const *)symName); tmp___16 = realloc((void *)result, ((tmp___14 + tmp___15) + 1UL) * sizeof(char )); result = (char *)tmp___16; strcat((char * __restrict )result, (char const * __restrict )symName); } } } break; case 4: parameter = findParameter(token); tmp___19 = (int )getArrayName(token); symName = findArrayRecord((char *)tmp___19, parameter); if ((unsigned long )symName != (unsigned long )((void *)0)) { tmp___32 = strcmp((char const *)symName, "Constant"); if (tmp___32 == 0) { tmp___20 = findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___20)); tmp___21 = strlen((char const *)result); tmp___22 = strlen((char const *)(buff)); tmp___23 = realloc((void *)result, ((tmp___21 + tmp___22) + 1UL) * sizeof(char )); result = (char *)tmp___23; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___31 = strcmp((char const *)symName, "Function"); if (tmp___31 == 0) { tmp___24 = findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___24)); tmp___25 = strlen((char const *)result); tmp___26 = strlen((char const *)(buff)); tmp___27 = realloc((void *)result, ((tmp___25 + tmp___26) + 1UL) * sizeof(char )); result = (char *)tmp___27; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___28 = strlen((char const *)result); tmp___29 = strlen((char const *)symName); tmp___30 = realloc((void *)result, ((tmp___28 + tmp___29) + 1UL) * sizeof(char )); result = (char *)tmp___30; strcat((char * __restrict )result, (char const * __restrict )symName); } } } break; case 5: symName = find_symVal(token); if ((unsigned long )symName != (unsigned long )((void *)0)) { tmp___45 = strcmp((char const *)symName, "Constant"); if (tmp___45 == 0) { tmp___33 = findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___33)); tmp___34 = strlen((char const *)result); tmp___35 = strlen((char const *)(buff)); tmp___36 = realloc((void *)result, ((tmp___34 + tmp___35) + 1UL) * sizeof(char )); result = (char *)tmp___36; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___44 = strcmp((char const *)symName, "Function"); if (tmp___44 == 0) { tmp___37 = findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___37)); tmp___38 = strlen((char const *)result); tmp___39 = strlen((char const *)(buff)); tmp___40 = realloc((void *)result, ((tmp___38 + tmp___39) + 1UL) * sizeof(char )); result = (char *)tmp___40; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___41 = strlen((char const *)result); tmp___42 = strlen((char const *)symName); tmp___43 = realloc((void *)result, ((tmp___41 + tmp___42) + 1UL) * sizeof(char )); result = (char *)tmp___43; strcat((char * __restrict )result, (char const * __restrict )symName); } } } break; } token = getNextToken((char const *)(rhs + i), & i, len); } strcat((char * __restrict )result, (char const * __restrict )"\000"); add_entryToSTable(lhs, result, val, address, type); delete_allVariableTableEntry(); return; } } char *getPointerName(char const *str ) ; char *getPrepositionalFormula(char *expr ) { int i ; int len ; int parameter ; int j ; char *token ; char *result ; char *symName ; char *temp ; char buff[15] ; void *tmp ; size_t tmp___0 ; size_t tmp___1 ; size_t tmp___2 ; void *tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; void *tmp___7 ; size_t tmp___8 ; size_t tmp___9 ; void *tmp___10 ; void *tmp___11 ; size_t tmp___12 ; size_t tmp___13 ; void *tmp___14 ; size_t tmp___15 ; size_t tmp___16 ; void *tmp___17 ; int tmp___18 ; int tmp___19 ; int tmp___20 ; void *tmp___21 ; size_t tmp___22 ; size_t tmp___23 ; void *tmp___24 ; void *tmp___25 ; size_t tmp___26 ; size_t tmp___27 ; void *tmp___28 ; size_t tmp___29 ; size_t tmp___30 ; void *tmp___31 ; int tmp___32 ; int tmp___33 ; size_t tmp___34 ; size_t tmp___35 ; void *tmp___36 ; void *tmp___37 ; size_t tmp___38 ; size_t tmp___39 ; void *tmp___40 ; void *tmp___41 ; size_t tmp___42 ; size_t tmp___43 ; void *tmp___44 ; size_t tmp___45 ; size_t tmp___46 ; void *tmp___47 ; int tmp___48 ; int tmp___49 ; int tmp___50 ; { i = 0; tmp = calloc((size_t )2, sizeof(char )); result = (char *)tmp; tmp___0 = strlen((char const *)expr); len = (int )tmp___0; token = getNextToken((char const *)expr, & i, len); while ((unsigned long )token != (unsigned long )((void *)0)) { switch ((int )token_type) { case 2: case 1: case 0: tmp___1 = strlen((char const *)result); tmp___2 = strlen((char const *)token); tmp___3 = realloc((void *)result, ((tmp___1 + tmp___2) + 1UL) * sizeof(char )); result = (char *)tmp___3; strcat((char * __restrict )result, (char const * __restrict )token); break; case 3: parameter = findParameter(token); j = 0; tmp___4 = (int )getPointerName(token); temp = (char *)tmp___4; while (j < 2 * parameter + 1) { symName = find_symVal(temp); if ((unsigned long )symName == (unsigned long )((void *)0)) { tmp___5 = findParameter(temp); tmp___6 = (int )getArrayName(temp); symName = findArrayRecord((char *)tmp___6, tmp___5); } temp = symName; j ++; } if ((unsigned long )symName != (unsigned long )((void *)0)) { tmp___19 = strcmp((char const *)symName, "Constant"); if (tmp___19 == 0) { tmp___7 = findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___7)); tmp___8 = strlen((char const *)result); tmp___9 = strlen((char const *)(buff)); tmp___10 = realloc((void *)result, ((tmp___8 + tmp___9) + 1UL) * sizeof(char )); result = (char *)tmp___10; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___18 = strcmp((char const *)symName, "Function"); if (tmp___18 == 0) { tmp___11 = findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___11)); tmp___12 = strlen((char const *)result); tmp___13 = strlen((char const *)(buff)); tmp___14 = realloc((void *)result, ((tmp___12 + tmp___13) + 1UL) * sizeof(char )); result = (char *)tmp___14; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___15 = strlen((char const *)result); tmp___16 = strlen((char const *)symName); tmp___17 = realloc((void *)result, ((tmp___15 + tmp___16) + 1UL) * sizeof(char )); result = (char *)tmp___17; strcat((char * __restrict )result, (char const * __restrict )symName); } } } break; case 4: parameter = findParameter(token); tmp___20 = (int )getArrayName(token); symName = findArrayRecord((char *)tmp___20, parameter); if ((unsigned long )symName != (unsigned long )((void *)0)) { tmp___33 = strcmp((char const *)symName, "Constant"); if (tmp___33 == 0) { tmp___21 = findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___21)); tmp___22 = strlen((char const *)result); tmp___23 = strlen((char const *)(buff)); tmp___24 = realloc((void *)result, ((tmp___22 + tmp___23) + 1UL) * sizeof(char )); result = (char *)tmp___24; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___32 = strcmp((char const *)symName, "Function"); if (tmp___32 == 0) { tmp___25 = findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___25)); tmp___26 = strlen((char const *)result); tmp___27 = strlen((char const *)(buff)); tmp___28 = realloc((void *)result, ((tmp___26 + tmp___27) + 1UL) * sizeof(char )); result = (char *)tmp___28; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___29 = strlen((char const *)result); tmp___30 = strlen((char const *)symName); tmp___31 = realloc((void *)result, ((tmp___29 + tmp___30) + 1UL) * sizeof(char )); result = (char *)tmp___31; strcat((char * __restrict )result, (char const * __restrict )symName); } } } break; case 5: tmp___50 = strcmp((char const *)token, "not"); if (tmp___50 == 0) { tmp___34 = strlen((char const *)result); tmp___35 = strlen((char const *)token); tmp___36 = realloc((void *)result, ((tmp___34 + tmp___35) + 1UL) * sizeof(char )); result = (char *)tmp___36; strcat((char * __restrict )result, (char const * __restrict )token); } else { symName = find_symVal(token); if ((unsigned long )symName != (unsigned long )((void *)0)) { tmp___49 = strcmp((char const *)symName, "Constant"); if (tmp___49 == 0) { tmp___37 = findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___37)); tmp___38 = strlen((char const *)result); tmp___39 = strlen((char const *)(buff)); tmp___40 = realloc((void *)result, ((tmp___38 + tmp___39) + 1UL) * sizeof(char )); result = (char *)tmp___40; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___48 = strcmp((char const *)symName, "Function"); if (tmp___48 == 0) { tmp___41 = findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___41)); tmp___42 = strlen((char const *)result); tmp___43 = strlen((char const *)(buff)); tmp___44 = realloc((void *)result, ((tmp___42 + tmp___43) + 1UL) * sizeof(char )); result = (char *)tmp___44; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___45 = strlen((char const *)result); tmp___46 = strlen((char const *)symName); tmp___47 = realloc((void *)result, ((tmp___45 + tmp___46) + 1UL) * sizeof(char )); result = (char *)tmp___47; strcat((char * __restrict )result, (char const * __restrict )symName); } } } } break; } free((void *)token); token = getNextToken((char const *)(expr + i), & i, len); } strcat((char * __restrict )result, (char const * __restrict )"\000"); return (result); } } #pragma merger("0","./queue.i","-g,-g") void enQueue(void) ; int isQueueEmpty(void) ; int isNotQueueEmpty(void) ; void enQueue(void) { int i ; struct qnode *newNode___0 ; void *tmp ; { i = 0; if (CDG_Module) { return; } tmp = malloc(sizeof(struct qnode )); newNode___0 = (struct qnode *)tmp; newNode___0->next = (struct qnode *)((void *)0); i = 0; while (i < 50) { newNode___0->levelptr[i] = (struct treeNode *)((void *)0); i ++; } newNode___0->symbolicNames = (char *)((void *)0); if ((unsigned long )queue.front == (unsigned long )((void *)0)) { queue.front = newNode___0; queue.rear = newNode___0; } else { (queue.rear)->next = newNode___0; queue.rear = newNode___0; } (queue.totalElements) ++; return; } } int isQueueEmpty(void) { { if ((unsigned long )queue.front == (unsigned long )((void *)0)) { if ((unsigned long )queue.rear == (unsigned long )((void *)0)) { return (1); } } return (0); } } int isNotQueueEmpty(void) { int tmp ; { tmp = isQueueEmpty(); if (tmp) { return (0); } return (1); } } void deQueue(void) { struct qnode *temp ; { if ((unsigned long )queue.front == (unsigned long )queue.rear) { temp = queue.front; queue.front = (struct qnode *)((void *)0); queue.rear = (struct qnode *)((void *)0); } else { temp = queue.front; queue.front = (queue.front)->next; } free((void *)temp); (queue.totalElements) --; return; } } void emptyQueue(void) { int tmp ; { while (1) { tmp = isQueueEmpty(); if (tmp) { break; } deQueue(); } return; } } #pragma merger("0","./levelTree.i","-g,-g") int getLevel(struct treeNode *node ) ; int getNodeOutcome(struct treeNode *node ) ; struct treeNode *setSid(struct treeNode *node , int sid ) ; struct treeNode *setLevel(struct treeNode *node , int level ) ; struct treeNode *setNodeOutcome(struct treeNode *node , int outcome ) ; struct treeNode *setFchild(struct treeNode *node , struct treeNode *child ) ; struct treeNode *setNodeParent(struct treeNode *node , struct treeNode *parent ) ; struct treeNode *setNextnode(struct treeNode *node , struct treeNode *nxt ) ; struct treeNode *getFirstNodeAtLevel(int level ) ; void setFirstNodeAtLevel(int level , struct treeNode *node ) ; int ifFirstChild(struct treeNode *node ) ; struct treeNode *newtreeNode(int sid , int level , char *texp , char *fexp , int outcome ) ; void addToTree(int sid , int level , char *texp , char *fexp , int pid , int outcome ) ; void printLevel(void) ; struct treeNode *tree_nodes[100] = { (struct treeNode *)((void *)0)}; int getSid(struct treeNode *node ) { { return (node->sid); } } int getLevel(struct treeNode *node ) { { return (node->level); } } int getNodeOutcome(struct treeNode *node ) { { return (node->outcome); } } struct treeNode *getFchild(struct treeNode *node ) { { return (node->fchild); } } struct treeNode *getNodeParent(struct treeNode *node ) { { return (node->parent); } } struct treeNode *getNextnode(struct treeNode *node ) { { return (node->next); } } struct treeNode *setSid(struct treeNode *node , int sid ) { { node->sid = sid; return (node); } } struct treeNode *setLevel(struct treeNode *node , int level ) { { node->level = level; return (node); } } struct treeNode *setNodeOutcome(struct treeNode *node , int outcome ) { { node->outcome = outcome; return (node); } } struct treeNode *setFchild(struct treeNode *node , struct treeNode *child ) { { node->fchild = child; return (node); } } struct treeNode *setNodeParent(struct treeNode *node , struct treeNode *parent ) { { node->parent = parent; return (node); } } struct treeNode *setNextnode(struct treeNode *node , struct treeNode *nxt ) { { node->next = nxt; return (node); } } struct treeNode *getFirstNodeAtLevel(int level ) { { return ((queue.rear)->levelptr[level]); } } void setFirstNodeAtLevel(int level , struct treeNode *node ) { { (queue.rear)->levelptr[level] = node; return; } } int ifFirstChild(struct treeNode *node ) { struct treeNode *tmp ; struct treeNode *tmp___0 ; { tmp = getNodeParent(node); tmp___0 = getFchild(tmp); if ((unsigned long )tmp___0 == (unsigned long )((void *)0)) { return (1); } return (0); } } struct treeNode *newtreeNode(int sid , int level , char *texp , char *fexp , int outcome ) { struct treeNode *new_treeNode ; void *tmp ; char *tep ; char *fep ; int tmp___0 ; int tmp___1 ; size_t tmp___2 ; void *tmp___3 ; size_t tmp___4 ; void *tmp___5 ; { tmp = malloc(sizeof(struct treeNode )); new_treeNode = (struct treeNode *)tmp; new_treeNode->sid = sid; new_treeNode->level = level; new_treeNode->outcome = outcome; tmp___0 = (int )getPrepositionalFormula(texp); tep = (char *)tmp___0; tmp___1 = (int )getPrepositionalFormula(fexp); fep = (char *)tmp___1; tmp___2 = strlen((char const *)tep); tmp___3 = malloc(sizeof(char ) * (tmp___2 + 1UL)); new_treeNode->texp = (char *)tmp___3; tmp___4 = strlen((char const *)fep); tmp___5 = malloc(sizeof(char ) * (tmp___4 + 1UL)); new_treeNode->fexp = (char *)tmp___5; strcpy((char * __restrict )new_treeNode->texp, (char const * __restrict )tep); strcpy((char * __restrict )new_treeNode->fexp, (char const * __restrict )fep); new_treeNode->fchild = (struct treeNode *)((void *)0); new_treeNode->parent = (struct treeNode *)((void *)0); new_treeNode->next = (struct treeNode *)((void *)0); return (new_treeNode); } } void addToTree(int sid , int level , char *texp , char *fexp , int pid , int outcome ) { int tmp ; struct treeNode *new_treeNode ; struct treeNode *tmp___0 ; struct treeNode *tmp___1 ; struct treeNode *tmp___2 ; struct treeNode *tmp___3 ; int tmp___4 ; struct treeNode *tmp___5 ; { tmp = isQueueEmpty(); if (tmp) { return; } tmp___0 = newtreeNode(sid, level, texp, fexp, outcome); new_treeNode = tmp___0; tmp___2 = getFirstNodeAtLevel(level); if ((unsigned long )tmp___2 == (unsigned long )((void *)0)) { setFirstNodeAtLevel(level, new_treeNode); } else { tmp___1 = getFirstNodeAtLevel(level); setNextnode(new_treeNode, tmp___1); setFirstNodeAtLevel(level, new_treeNode); } if (level > 1) { setNodeParent(new_treeNode, tree_nodes[pid]); } tmp___5 = getNodeParent(new_treeNode); if ((unsigned long )tmp___5 != (unsigned long )((void *)0)) { tmp___4 = ifFirstChild(new_treeNode); if (tmp___4) { tmp___3 = getNodeParent(new_treeNode); setFchild(tmp___3, new_treeNode); } } tree_nodes[sid] = new_treeNode; return; } } void printLevel(void) { int level ; struct treeNode *curr ; struct treeNode *tmp ; struct treeNode *tmp___0 ; struct treeNode *tmp___1 ; { level = 1; tmp = getFirstNodeAtLevel(level); curr = tmp; while ((unsigned long )curr != (unsigned long )((void *)0)) { printf((char const * __restrict )"condition = %d ", curr->sid); tmp___0 = getNodeParent(curr); if ((unsigned long )tmp___0 != (unsigned long )((void *)0)) { printf((char const * __restrict )"parent = %d ", (curr->parent)->sid); } tmp___1 = getFchild(curr); if ((unsigned long )tmp___1 != (unsigned long )((void *)0)) { printf((char const * __restrict )"child = %d \n", (curr->fchild)->sid); } curr = getNextnode(curr); if ((unsigned long )curr == (unsigned long )((void *)0)) { level ++; curr = getFirstNodeAtLevel(level); printf((char const * __restrict )"\n"); } } return; } } void clearTreeNodes(void) { int i ; { i = 0; while (i < 100) { tree_nodes[i] = (struct treeNode *)((void *)0); i ++; } return; } } #pragma merger("0","./stringTokenize.i","-g,-g") extern __attribute__((__nothrow__)) char *( __attribute__((__nonnull__(1), __leaf__)) strchr)(char const *__s , int __c ) __attribute__((__pure__)) ; int isWhiteSpace(char const c ) ; int isOperator(char const c ) ; int isNotOperator(char const c ) ; int isAlpha(char const c ) ; int isDigitDot(char const c ) ; int isDigit(char const c ) ; int isWhiteSpace(char const c ) { int tmp ; { if ((int const )c == 0) { return (0); } if ((int const )c == 32) { tmp = 1; } else if ((int const )c == 9) { tmp = 1; } else { tmp = 0; } return (tmp); } } int isOperator(char const c ) { char *tmp ; { if ((int const )c == 0) { return (0); } tmp = strchr("&|<>=+-/*%^!", (int )c); return ((unsigned long )tmp != (unsigned long )((char *)0)); } } int isNotOperator(char const c ) { char *tmp ; { if ((int const )c == 0) { return (0); } tmp = strchr("&|<>=+-/*%^!()", (int )c); return ((unsigned long )tmp != (unsigned long )((char *)0)); } } extern int ( /* missing proto */ toupper)() ; int isAlpha(char const c ) { int tmp ; char *tmp___0 ; { if ((int const )c == 0) { return (0); } tmp = toupper((int const )c); tmp___0 = strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZ_", tmp); return ((unsigned long )tmp___0 != (unsigned long )((char *)0)); } } int isDigitDot(char const c ) { char *tmp ; { if ((int const )c == 0) { return (0); } tmp = strchr("0123456789.", (int )c); return ((unsigned long )tmp != (unsigned long )((char *)0)); } } int isDigit(char const c ) { char *tmp ; { if ((int const )c == 0) { return (0); } tmp = strchr("0123456789", (int )c); return ((unsigned long )tmp != (unsigned long )((char *)0)); } } char *getNextToken(char const *str , int *pos , int length ) { int i ; char *res ; int countPars ; void *tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; int tmp___7 ; int tmp___8 ; int tmp___9 ; int tmp___10 ; { i = 0; countPars = 0; tmp = malloc((size_t )(length + 1)); res = (char *)tmp; while (1) { tmp___0 = isWhiteSpace(*str); if (! tmp___0) { break; } *(res + i) = (char )*str; str ++; (*pos) ++; i ++; *(res + i) = (char )'\000'; token_type = (enum TOKENTYPE )0; return (res); } if ((int const )*str == 35) { while ((int const )*str == 35) { *(res + i) = (char )*str; str ++; (*pos) ++; i ++; } *(res + i) = (char )'\000'; token_type = (enum TOKENTYPE )0; return (res); } while ((int const )*str == 10) { str ++; (*pos) ++; } if ((int const )*str == 0) { return ((char *)((void *)0)); } if ((int const )*str == 40) { goto _L; } else if ((int const )*str == 41) { _L: /* CIL Label */ *(res + i) = (char )*str; str ++; (*pos) ++; i ++; *(res + i) = (char )'\000'; token_type = (enum TOKENTYPE )0; return (res); } if ((int const )*str == 42) { if ((int const )*(str + 1) == 40) { while (1) { *(res + i) = (char )*str; if ((int const )*str == 41) { countPars --; } str ++; if ((int const )*str == 40) { countPars ++; } (*pos) ++; i ++; token_type = (enum TOKENTYPE )4; if (countPars == 0) { break; } } *(res + i) = (char )'\000'; return (res); } } if ((int const )*str == 42) { if ((int const )*(str + 1) != 32) { while ((int const )*str == 42) { *(res + i) = (char )*str; str ++; (*pos) ++; i ++; } while (1) { tmp___1 = isAlpha(*str); if (! tmp___1) { tmp___2 = isDigit(*str); if (! tmp___2) { break; } } *(res + i) = (char )*str; str ++; (*pos) ++; i ++; token_type = (enum TOKENTYPE )4; } *(res + i) = (char )'\000'; return (res); } } if ((int const )*str == 37) { *(res + i) = (char )'m'; i ++; *(res + i) = (char )'o'; i ++; *(res + i) = (char )'d'; i ++; *(res + i) = (char )'\000'; str ++; (*pos) ++; token_type = (enum TOKENTYPE )1; return (res); } tmp___4 = isOperator(*str); if (tmp___4) { while (1) { tmp___3 = isOperator(*str); if (! tmp___3) { break; } *(res + i) = (char )*str; str ++; (*pos) ++; i ++; token_type = (enum TOKENTYPE )1; } *(res + i) = (char )'\000'; return (res); } tmp___6 = isDigitDot(*str); if (tmp___6) { while (1) { tmp___5 = isDigitDot(*str); if (! tmp___5) { break; } *(res + i) = (char )*str; (*pos) ++; i ++; str ++; token_type = (enum TOKENTYPE )2; } *(res + i) = (char )'\000'; return (res); } tmp___10 = isAlpha(*str); if (tmp___10) { while (1) { tmp___7 = isAlpha(*str); if (! tmp___7) { tmp___8 = isDigit(*str); if (! tmp___8) { break; } } *(res + i) = (char )*str; str ++; (*pos) ++; i ++; token_type = (enum TOKENTYPE )5; } if ((int const )*str == 40) { token_type = (enum TOKENTYPE )6; while (1) { tmp___9 = isWhiteSpace(*str); if (tmp___9) { break; } str ++; (*pos) ++; } } else if ((int const )*str == 91) { token_type = (enum TOKENTYPE )4; while (1) { *(res + i) = (char )*str; i ++; (*pos) ++; if ((int const )*str == 93) { break; } str ++; } } else { token_type = (enum TOKENTYPE )5; } *(res + i) = (char )'\000'; return (res); } return ((char *)((void *)0)); } } char *getArrayName(char const *str ) { int i ; char *res ; size_t tmp ; void *tmp___0 ; int tmp___1 ; int tmp___2 ; { i = 0; tmp = strlen(str); tmp___0 = malloc(tmp); res = (char *)tmp___0; if ((int const )*str != 42) { while ((int const )*str != 91) { *(res + i) = (char )*str; str ++; i ++; } *(res + i) = (char )'\000'; } else if ((int const )*str == 42) { tmp___2 = isAlpha(*(str + 1)); if (tmp___2) { tmp___1 = (int )getPointerName(str); return ((char *)tmp___1); } else { goto _L; } } else { _L: /* CIL Label */ str ++; str ++; while ((int const )*str != 32) { *(res + i) = (char )*str; str ++; i ++; } *(res + i) = (char )'\000'; } return (res); } } char *getPointerName(char const *str ) { int i ; char *res ; size_t tmp ; void *tmp___0 ; { i = 0; tmp = strlen(str); tmp___0 = malloc(tmp); res = (char *)tmp___0; while ((int const )*str == 42) { str ++; } while ((int const )*str != 0) { *(res + i) = (char )*str; str ++; i ++; } *(res + i) = (char )'\000'; return (res); } } char *getNextTokenFromConstraintSolver(char const *str , int *pos , int length ) { int i ; char *res ; void *tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; int tmp___7 ; int tmp___8 ; { i = 0; tmp = malloc((size_t )(length + 1)); res = (char *)tmp; if ((int const )*str == 45) { tmp___0 = isDigitDot(*(str + 2)); if (tmp___0) { while ((int const )*str != 41) { *(res + i) = (char )*str; (*pos) ++; i ++; str ++; token_type = (enum TOKENTYPE )2; } *(res + i) = (char )'\000'; return (res); } } while (1) { tmp___1 = isWhiteSpace(*str); if (! tmp___1) { if (! ((int const )*str == 10)) { tmp___2 = isOperator(*str); if (! tmp___2) { break; } } } str ++; (*pos) ++; } if ((int const )*str == 0) { free((void *)res); return ((char *)((void *)0)); } if ((int const )*str == 40) { goto _L; } else if ((int const )*str == 41) { _L: /* CIL Label */ *(res + i) = (char )*str; str ++; (*pos) ++; i ++; *(res + i) = (char )'\000'; token_type = (enum TOKENTYPE )0; return (res); } tmp___4 = isDigitDot(*str); if (tmp___4) { while (1) { tmp___3 = isDigitDot(*str); if (! tmp___3) { break; } *(res + i) = (char )*str; (*pos) ++; i ++; str ++; token_type = (enum TOKENTYPE )2; } *(res + i) = (char )'\000'; return (res); } tmp___8 = isAlpha(*str); if (tmp___8) { while (1) { tmp___5 = isAlpha(*str); if (! tmp___5) { tmp___6 = isDigit(*str); if (! tmp___6) { break; } } *(res + i) = (char )*str; str ++; (*pos) ++; i ++; token_type = (enum TOKENTYPE )5; } *(res + i) = (char )'\000'; if ((int const )*str == 40) { token_type = (enum TOKENTYPE )6; while (1) { tmp___7 = isWhiteSpace(*str); if (tmp___7) { break; } str ++; (*pos) ++; } } else { token_type = (enum TOKENTYPE )5; } return (res); } free((void *)res); return ((char *)((void *)0)); } } int checkForAllConstants(char const *str ) { int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; { while ((int const )*str != 0) { tmp = isWhiteSpace(*str); if (tmp) { str ++; } else { tmp___0 = isOperator(*str); if (tmp___0) { str ++; } else { tmp___1 = isDigitDot(*str); if (tmp___1) { str ++; } else { tmp___2 = isDigit(*str); if (tmp___2) { str ++; } else if ((int const )*str == 40) { str ++; } else if ((int const )*str == 41) { str ++; } else if ((int const )*str == 110) { if ((int const )*(str + 1) == 111) { if ((int const )*(str + 2) == 116) { if ((int const )*(str + 3) == 32) { str ++; str ++; str ++; } else { goto _L___1; } } else { goto _L___1; } } else { goto _L___1; } } else _L___1: /* CIL Label */ if ((int const )*str == 109) { if ((int const )*(str + 1) == 111) { if ((int const )*(str + 2) == 100) { if ((int const )*(str + 3) == 32) { str ++; str ++; str ++; } else { return (0); } } else { return (0); } } else { return (0); } } else { return (0); } } } } } return (1); } } #pragma merger("0","./arrayAndPointersSymbolicExec.i","-g,-g") void add_entryToArraySTable(char *aname , int index___0 , char *sname , void *val , void *address , int type ) ; void print_ArrayEntry(void) ; void deleteArrayTable(void) ; static int toInt___0(void *addr ) { { return ((int )((size_t )addr % 2147483647UL)); } } void add_entryToArraySTable(char *aname , int index___0 , char *sname , void *val , void *address , int type ) { struct arraySym_table *s ; int size ; int tmp ; int tmp___0 ; int tmp___1 ; void *tmp___2 ; unsigned int _ha_bkt ; void *tmp___3 ; void *tmp___4 ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; unsigned int _he_bkt ; unsigned int _he_bkt_i ; struct UT_hash_handle *_he_thh ; struct UT_hash_handle *_he_hh_nxt ; UT_hash_bucket *_he_new_buckets ; UT_hash_bucket *_he_newbkt ; void *tmp___5 ; int tmp___6 ; { s = arraySTable; while ((unsigned long )s != (unsigned long )((void *)0)) { tmp = strcmp((char const *)(s->key.arrayName), (char const *)aname); if (tmp == 0) { if (s->key.index == index___0) { tmp___0 = strcmp((char const *)(s->sname), "Constant"); if (tmp___0 == 0) { strcpy((char * __restrict )(s->sname), (char const * __restrict )sname); break; } } } tmp___1 = strcmp((char const *)(s->key.arrayName), (char const *)aname); if (tmp___1 == 0) { if (s->key.index == index___0) { return; } } s = (struct arraySym_table *)s->hh.next; } if ((unsigned long )s == (unsigned long )((void *)0)) { tmp___2 = malloc(sizeof(struct arraySym_table )); s = (struct arraySym_table *)tmp___2; strcpy((char * __restrict )(s->key.arrayName), (char const * __restrict )aname); s->key.index = index___0; while (1) { s->hh.next = (void *)0; s->hh.key = (void *)((char *)(& s->key)); s->hh.keylen = (unsigned int )sizeof(struct arrayKey ); if (! arraySTable) { arraySTable = s; arraySTable->hh.prev = (void *)0; while (1) { tmp___3 = malloc(sizeof(UT_hash_table )); arraySTable->hh.tbl = (UT_hash_table *)tmp___3; if (! arraySTable->hh.tbl) { exit(-1); } memset((void *)arraySTable->hh.tbl, 0, sizeof(UT_hash_table )); (arraySTable->hh.tbl)->tail = & arraySTable->hh; (arraySTable->hh.tbl)->num_buckets = 32U; (arraySTable->hh.tbl)->log2_num_buckets = 5U; (arraySTable->hh.tbl)->hho = (char *)(& arraySTable->hh) - (char *)arraySTable; tmp___4 = malloc(32UL * sizeof(struct UT_hash_bucket )); (arraySTable->hh.tbl)->buckets = (UT_hash_bucket *)tmp___4; if (! (arraySTable->hh.tbl)->buckets) { exit(-1); } memset((void *)(arraySTable->hh.tbl)->buckets, 0, 32UL * sizeof(struct UT_hash_bucket )); (arraySTable->hh.tbl)->signature = 2685476833U; break; } } else { ((arraySTable->hh.tbl)->tail)->next = (void *)s; s->hh.prev = (void *)((char *)(arraySTable->hh.tbl)->tail - (arraySTable->hh.tbl)->hho); (arraySTable->hh.tbl)->tail = & s->hh; } ((arraySTable->hh.tbl)->num_items) ++; s->hh.tbl = arraySTable->hh.tbl; while (1) { _hj_key = (unsigned char *)(& s->key); s->hh.hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(struct arrayKey ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); s->hh.hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= s->hh.hashv; _hj_i ^= s->hh.hashv >> 13; _hj_j -= s->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; s->hh.hashv -= _hj_i; s->hh.hashv -= _hj_j; s->hh.hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= s->hh.hashv; _hj_i ^= s->hh.hashv >> 12; _hj_j -= s->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; s->hh.hashv -= _hj_i; s->hh.hashv -= _hj_j; s->hh.hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= s->hh.hashv; _hj_i ^= s->hh.hashv >> 3; _hj_j -= s->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; s->hh.hashv -= _hj_i; s->hh.hashv -= _hj_j; s->hh.hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } s->hh.hashv = (unsigned int )((unsigned long )s->hh.hashv + sizeof(struct arrayKey )); switch (_hj_k) { case 11U: s->hh.hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: s->hh.hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: s->hh.hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= s->hh.hashv; _hj_i ^= s->hh.hashv >> 13; _hj_j -= s->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; s->hh.hashv -= _hj_i; s->hh.hashv -= _hj_j; s->hh.hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= s->hh.hashv; _hj_i ^= s->hh.hashv >> 12; _hj_j -= s->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; s->hh.hashv -= _hj_i; s->hh.hashv -= _hj_j; s->hh.hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= s->hh.hashv; _hj_i ^= s->hh.hashv >> 3; _hj_j -= s->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; s->hh.hashv -= _hj_i; s->hh.hashv -= _hj_j; s->hh.hashv ^= _hj_j >> 15; break; } _ha_bkt = s->hh.hashv & ((arraySTable->hh.tbl)->num_buckets - 1U); break; } while (1) { (((arraySTable->hh.tbl)->buckets + _ha_bkt)->count) ++; s->hh.hh_next = ((arraySTable->hh.tbl)->buckets + _ha_bkt)->hh_head; s->hh.hh_prev = (struct UT_hash_handle *)((void *)0); if (((arraySTable->hh.tbl)->buckets + _ha_bkt)->hh_head) { (((arraySTable->hh.tbl)->buckets + _ha_bkt)->hh_head)->hh_prev = & s->hh; } ((arraySTable->hh.tbl)->buckets + _ha_bkt)->hh_head = & s->hh; if (((arraySTable->hh.tbl)->buckets + _ha_bkt)->count >= (((arraySTable->hh.tbl)->buckets + _ha_bkt)->expand_mult + 1U) * 10U) { if ((s->hh.tbl)->noexpand != 1U) { while (1) { tmp___5 = malloc((unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); _he_new_buckets = (UT_hash_bucket *)tmp___5; if (! _he_new_buckets) { exit(-1); } memset((void *)_he_new_buckets, 0, (unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); if ((s->hh.tbl)->num_items & ((s->hh.tbl)->num_buckets * 2U - 1U)) { tmp___6 = 1; } else { tmp___6 = 0; } (s->hh.tbl)->ideal_chain_maxlen = ((s->hh.tbl)->num_items >> ((s->hh.tbl)->log2_num_buckets + 1U)) + (unsigned int )tmp___6; (s->hh.tbl)->nonideal_items = 0U; _he_bkt_i = 0U; while (_he_bkt_i < (s->hh.tbl)->num_buckets) { _he_thh = ((s->hh.tbl)->buckets + _he_bkt_i)->hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; while (1) { _he_bkt = _he_thh->hashv & ((s->hh.tbl)->num_buckets * 2U - 1U); break; } _he_newbkt = _he_new_buckets + _he_bkt; (_he_newbkt->count) ++; if (_he_newbkt->count > (s->hh.tbl)->ideal_chain_maxlen) { ((s->hh.tbl)->nonideal_items) ++; _he_newbkt->expand_mult = _he_newbkt->count / (s->hh.tbl)->ideal_chain_maxlen; } _he_thh->hh_prev = (struct UT_hash_handle *)((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) { (_he_newbkt->hh_head)->hh_prev = _he_thh; } _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } _he_bkt_i ++; } free((void *)(s->hh.tbl)->buckets); (s->hh.tbl)->num_buckets *= 2U; ((s->hh.tbl)->log2_num_buckets) ++; (s->hh.tbl)->buckets = _he_new_buckets; if ((s->hh.tbl)->nonideal_items > (s->hh.tbl)->num_items >> 1) { ((s->hh.tbl)->ineff_expands) ++; } else { (s->hh.tbl)->ineff_expands = 0U; } if ((s->hh.tbl)->ineff_expands > 1U) { (s->hh.tbl)->noexpand = 1U; } break; } } } break; } break; } strcpy((char * __restrict )(s->sname), (char const * __restrict )sname); } if (type == 1) { size = (int )sizeof(int ); addToIntTable(sname, (int *)val); } else { size = (int )sizeof(float ); addToFloatTable(sname, (float *)val); } s->cval = malloc((size_t )size); memcpy((void * __restrict )s->cval, (void const * __restrict )val, (size_t )size); s->address = toInt___0(address); s->type = type; return; } } char *findArrayRecord(char *aname , int index___0 ) { struct arraySym_table k ; struct arraySym_table *s ; int tmp ; { memset((void *)(& k), 0, sizeof(struct arraySym_table )); strcpy((char * __restrict )(k.key.arrayName), (char const * __restrict )aname); k.key.index = index___0; s = arraySTable; while ((unsigned long )s != (unsigned long )((void *)0)) { tmp = strcmp((char const *)(s->key.arrayName), (char const *)aname); if (tmp == 0) { if (s->key.index == index___0) { return (s->sname); } } s = (struct arraySym_table *)s->hh.next; } return ((char *)((void *)0)); } } void print_ArrayEntry(void) { struct arraySym_table *s ; { s = arraySTable; while ((unsigned long )s != (unsigned long )((void *)0)) { printf((char const * __restrict )"variable name %s: index:%d symbolic name: %s value :%d address=%d\n", s->key.arrayName, s->key.index, s->sname, *((int *)s->cval), s->address); s = (struct arraySym_table *)s->hh.next; } return; } } void deleteArrayTable(void) { struct arraySym_table *p ; struct arraySym_table *tmp ; void *tmp___0 ; void *tmp___1 ; unsigned int _hd_bkt ; struct UT_hash_handle *_hd_hh_del ; { p = arraySTable; if (arraySTable) { tmp___0 = arraySTable->hh.next; } else { tmp___0 = (void *)0; } tmp = (struct arraySym_table *)tmp___0; while (p) { while (1) { if ((unsigned long )p->hh.prev == (unsigned long )((void *)0)) { if ((unsigned long )p->hh.next == (unsigned long )((void *)0)) { free((void *)(arraySTable->hh.tbl)->buckets); free((void *)arraySTable->hh.tbl); arraySTable = (struct arraySym_table *)((void *)0); } else { goto _L; } } else { _L: /* CIL Label */ _hd_hh_del = & p->hh; if ((unsigned long )p == (unsigned long )((void *)((char *)(arraySTable->hh.tbl)->tail - (arraySTable->hh.tbl)->hho))) { (arraySTable->hh.tbl)->tail = (UT_hash_handle *)((ptrdiff_t )p->hh.prev + (arraySTable->hh.tbl)->hho); } if (p->hh.prev) { ((UT_hash_handle *)((ptrdiff_t )p->hh.prev + (arraySTable->hh.tbl)->hho))->next = p->hh.next; } else { while (1) { arraySTable = (struct arraySym_table *)p->hh.next; break; } } if (_hd_hh_del->next) { ((UT_hash_handle *)((ptrdiff_t )_hd_hh_del->next + (arraySTable->hh.tbl)->hho))->prev = _hd_hh_del->prev; } while (1) { _hd_bkt = _hd_hh_del->hashv & ((arraySTable->hh.tbl)->num_buckets - 1U); break; } (((arraySTable->hh.tbl)->buckets + _hd_bkt)->count) --; if ((unsigned long )((arraySTable->hh.tbl)->buckets + _hd_bkt)->hh_head == (unsigned long )_hd_hh_del) { ((arraySTable->hh.tbl)->buckets + _hd_bkt)->hh_head = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_prev) { (_hd_hh_del->hh_prev)->hh_next = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_next) { (_hd_hh_del->hh_next)->hh_prev = _hd_hh_del->hh_prev; } ((arraySTable->hh.tbl)->num_items) --; } break; } free((void *)p); p = tmp; if (tmp) { tmp___1 = tmp->hh.next; } else { tmp___1 = (void *)0; } tmp = (struct arraySym_table *)tmp___1; } return; } } void handleArraySymbolically(char *lhs , int index___0 , char *rhs , void *val , void *address , int type ) { int i ; int len ; int parameter ; int j ; int value ; char *token ; char *result ; char *symName ; char *temp ; char buff[15] ; void *tmp ; size_t tmp___0 ; size_t tmp___1 ; size_t tmp___2 ; void *tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; size_t tmp___7 ; size_t tmp___8 ; void *tmp___9 ; int tmp___10 ; size_t tmp___11 ; size_t tmp___12 ; void *tmp___13 ; size_t tmp___14 ; size_t tmp___15 ; void *tmp___16 ; int tmp___17 ; int tmp___18 ; int tmp___19 ; int tmp___20 ; size_t tmp___21 ; size_t tmp___22 ; void *tmp___23 ; int tmp___24 ; size_t tmp___25 ; size_t tmp___26 ; void *tmp___27 ; size_t tmp___28 ; size_t tmp___29 ; void *tmp___30 ; int tmp___31 ; int tmp___32 ; int tmp___33 ; size_t tmp___34 ; size_t tmp___35 ; void *tmp___36 ; int tmp___37 ; size_t tmp___38 ; size_t tmp___39 ; void *tmp___40 ; size_t tmp___41 ; size_t tmp___42 ; void *tmp___43 ; int tmp___44 ; int tmp___45 ; { i = 0; tmp = calloc((size_t )2, sizeof(char )); result = (char *)tmp; tmp___0 = strlen((char const *)rhs); len = (int )tmp___0; token = getNextToken((char const *)rhs, & i, len); while ((unsigned long )token != (unsigned long )((void *)0)) { switch ((int )token_type) { case 2: case 1: case 0: tmp___1 = strlen((char const *)result); tmp___2 = strlen((char const *)token); tmp___3 = realloc((void *)result, ((tmp___1 + tmp___2) + 1UL) * sizeof(char )); result = (char *)tmp___3; strcat((char * __restrict )result, (char const * __restrict )token); break; case 3: parameter = findParameter(token); j = 0; while (j < 2 * parameter + 1) { symName = find_symVal(temp); if ((unsigned long )symName == (unsigned long )((void *)0)) { tmp___4 = findParameter(temp); tmp___5 = (int )getArrayName(temp); symName = findArrayRecord((char *)tmp___5, tmp___4); } temp = symName; j ++; } if ((unsigned long )symName != (unsigned long )((void *)0)) { tmp___18 = strcmp((char const *)symName, "Constant"); if (tmp___18 == 0) { tmp___6 = (int )findValBySymbolicName(symName); value = *((int *)tmp___6); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", value); tmp___7 = strlen((char const *)result); tmp___8 = strlen((char const *)(buff)); tmp___9 = realloc((void *)result, ((tmp___7 + tmp___8) + 1UL) * sizeof(char )); result = (char *)tmp___9; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___17 = strcmp((char const *)symName, "Function"); if (tmp___17 == 0) { tmp___10 = (int )findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___10)); tmp___11 = strlen((char const *)result); tmp___12 = strlen((char const *)(buff)); tmp___13 = realloc((void *)result, ((tmp___11 + tmp___12) + 1UL) * sizeof(char )); result = (char *)tmp___13; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___14 = strlen((char const *)result); tmp___15 = strlen((char const *)symName); tmp___16 = realloc((void *)result, ((tmp___14 + tmp___15) + 1UL) * sizeof(char )); result = (char *)tmp___16; strcat((char * __restrict )result, (char const * __restrict )symName); } } } break; case 4: parameter = findParameter(token); tmp___19 = (int )getArrayName(token); symName = findArrayRecord((char *)tmp___19, parameter); if ((unsigned long )symName != (unsigned long )((void *)0)) { tmp___32 = strcmp((char const *)symName, "Constant"); if (tmp___32 == 0) { tmp___20 = (int )findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___20)); tmp___21 = strlen((char const *)result); tmp___22 = strlen((char const *)(buff)); tmp___23 = realloc((void *)result, ((tmp___21 + tmp___22) + 1UL) * sizeof(char )); result = (char *)tmp___23; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___31 = strcmp((char const *)symName, "Function"); if (tmp___31 == 0) { tmp___24 = (int )findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___24)); tmp___25 = strlen((char const *)result); tmp___26 = strlen((char const *)(buff)); tmp___27 = realloc((void *)result, ((tmp___25 + tmp___26) + 1UL) * sizeof(char )); result = (char *)tmp___27; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___28 = strlen((char const *)result); tmp___29 = strlen((char const *)symName); tmp___30 = realloc((void *)result, ((tmp___28 + tmp___29) + 1UL) * sizeof(char )); result = (char *)tmp___30; strcat((char * __restrict )result, (char const * __restrict )symName); } } } break; case 5: symName = find_symVal(token); if ((unsigned long )symName != (unsigned long )((void *)0)) { tmp___45 = strcmp((char const *)symName, "Constant"); if (tmp___45 == 0) { tmp___33 = (int )findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___33)); tmp___34 = strlen((char const *)result); tmp___35 = strlen((char const *)(buff)); tmp___36 = realloc((void *)result, ((tmp___34 + tmp___35) + 1UL) * sizeof(char )); result = (char *)tmp___36; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___44 = strcmp((char const *)symName, "Function"); if (tmp___44 == 0) { tmp___37 = (int )findValBySymbolicName(symName); sprintf((char * __restrict )(buff), (char const * __restrict )"%d", *((int *)tmp___37)); tmp___38 = strlen((char const *)result); tmp___39 = strlen((char const *)(buff)); tmp___40 = realloc((void *)result, ((tmp___38 + tmp___39) + 1UL) * sizeof(char )); result = (char *)tmp___40; strcat((char * __restrict )result, (char const * __restrict )(buff)); } else { tmp___41 = strlen((char const *)result); tmp___42 = strlen((char const *)symName); tmp___43 = realloc((void *)result, ((tmp___41 + tmp___42) + 1UL) * sizeof(char )); result = (char *)tmp___43; strcat((char * __restrict )result, (char const * __restrict )symName); } } } break; } token = getNextToken((char const *)(rhs + i), & i, len); } strcat((char * __restrict )result, (char const * __restrict )"\000"); add_entryToArraySTable(lhs, index___0, result, val, address, type); delete_allVariableTableEntry(); return; } } #pragma merger("0","./updateIntegerValues.i","-g,-g") struct intVartable *itable = (struct intVartable *)((void *)0); struct floatVartable *ftable = (struct floatVartable *)((void *)0); void addToIntTable(char *sname , int *val ) { struct intVartable *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; size_t tmp ; size_t tmp___0 ; size_t tmp___1 ; int tmp___2 ; size_t tmp___3 ; void *tmp___4 ; size_t tmp___5 ; void *tmp___6 ; unsigned int _ha_bkt ; size_t tmp___7 ; void *tmp___8 ; void *tmp___9 ; unsigned int _hj_i___0 ; unsigned int _hj_j___0 ; unsigned int _hj_k___0 ; unsigned char *_hj_key___0 ; size_t tmp___10 ; size_t tmp___11 ; unsigned int _he_bkt ; unsigned int _he_bkt_i ; struct UT_hash_handle *_he_thh ; struct UT_hash_handle *_he_hh_nxt ; UT_hash_bucket *_he_new_buckets ; UT_hash_bucket *_he_newbkt ; void *tmp___12 ; int tmp___13 ; void *tmp___14 ; size_t tmp___15 ; void *tmp___16 ; unsigned int _ha_bkt___0 ; size_t tmp___17 ; void *tmp___18 ; void *tmp___19 ; unsigned int _hj_i___1 ; unsigned int _hj_j___1 ; unsigned int _hj_k___1 ; unsigned char *_hj_key___1 ; size_t tmp___20 ; size_t tmp___21 ; unsigned int _he_bkt___0 ; unsigned int _he_bkt_i___0 ; struct UT_hash_handle *_he_thh___0 ; struct UT_hash_handle *_he_hh_nxt___0 ; UT_hash_bucket *_he_new_buckets___0 ; UT_hash_bucket *_he_newbkt___0 ; void *tmp___22 ; int tmp___23 ; { while (1) { s = (struct intVartable *)((void *)0); if (itable) { while (1) { _hj_key = (unsigned char *)sname; _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; tmp = strlen((char const *)sname); _hj_k = (unsigned int )tmp; while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } tmp___0 = strlen((char const *)sname); _hf_hashv = (unsigned int )((size_t )_hf_hashv + tmp___0); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((itable->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((itable->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct intVartable *)((void *)((char *)((itable->hh.tbl)->buckets + _hf_bkt)->hh_head - (itable->hh.tbl)->hho)); break; } } else { s = (struct intVartable *)((void *)0); } while (s) { tmp___3 = strlen((char const *)sname); if ((size_t )s->hh.keylen == tmp___3) { tmp___1 = strlen((char const *)sname); tmp___2 = memcmp((void const *)s->hh.key, (void const *)sname, tmp___1); if (tmp___2 == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct intVartable *)((void *)((char *)s->hh.hh_next - (itable->hh.tbl)->hho)); break; } } else { s = (struct intVartable *)((void *)0); } } break; } } break; } if (CDG_Module == 1) { if ((unsigned long )s == (unsigned long )((void *)0)) { tmp___4 = malloc(sizeof(struct intVartable )); s = (struct intVartable *)tmp___4; tmp___5 = strlen((char const *)sname); tmp___6 = malloc(sizeof(char ) * (tmp___5 + 1UL)); s->sname = (char *)tmp___6; strcpy((char * __restrict )s->sname, (char const * __restrict )sname); while (1) { s->hh.next = (void *)0; s->hh.key = (void *)(s->sname + 0); tmp___7 = strlen((char const *)s->sname); s->hh.keylen = (unsigned int )tmp___7; if (! itable) { itable = s; itable->hh.prev = (void *)0; while (1) { tmp___8 = malloc(sizeof(UT_hash_table )); itable->hh.tbl = (UT_hash_table *)tmp___8; if (! itable->hh.tbl) { exit(-1); } memset((void *)itable->hh.tbl, 0, sizeof(UT_hash_table )); (itable->hh.tbl)->tail = & itable->hh; (itable->hh.tbl)->num_buckets = 32U; (itable->hh.tbl)->log2_num_buckets = 5U; (itable->hh.tbl)->hho = (char *)(& itable->hh) - (char *)itable; tmp___9 = malloc(32UL * sizeof(struct UT_hash_bucket )); (itable->hh.tbl)->buckets = (UT_hash_bucket *)tmp___9; if (! (itable->hh.tbl)->buckets) { exit(-1); } memset((void *)(itable->hh.tbl)->buckets, 0, 32UL * sizeof(struct UT_hash_bucket )); (itable->hh.tbl)->signature = 2685476833U; break; } } else { ((itable->hh.tbl)->tail)->next = (void *)s; s->hh.prev = (void *)((char *)(itable->hh.tbl)->tail - (itable->hh.tbl)->hho); (itable->hh.tbl)->tail = & s->hh; } ((itable->hh.tbl)->num_items) ++; s->hh.tbl = itable->hh.tbl; while (1) { _hj_key___0 = (unsigned char *)(s->sname + 0); s->hh.hashv = 4276993775U; _hj_j___0 = 2654435769U; _hj_i___0 = _hj_j___0; tmp___10 = strlen((char const *)s->sname); _hj_k___0 = (unsigned int )tmp___10; while (_hj_k___0 >= 12U) { _hj_i___0 += (((unsigned int )*(_hj_key___0 + 0) + ((unsigned int )*(_hj_key___0 + 1) << 8)) + ((unsigned int )*(_hj_key___0 + 2) << 16)) + ((unsigned int )*(_hj_key___0 + 3) << 24); _hj_j___0 += (((unsigned int )*(_hj_key___0 + 4) + ((unsigned int )*(_hj_key___0 + 5) << 8)) + ((unsigned int )*(_hj_key___0 + 6) << 16)) + ((unsigned int )*(_hj_key___0 + 7) << 24); s->hh.hashv += (((unsigned int )*(_hj_key___0 + 8) + ((unsigned int )*(_hj_key___0 + 9) << 8)) + ((unsigned int )*(_hj_key___0 + 10) << 16)) + ((unsigned int )*(_hj_key___0 + 11) << 24); while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 13; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 12; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 3; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 15; break; } _hj_key___0 += 12; _hj_k___0 -= 12U; } tmp___11 = strlen((char const *)s->sname); s->hh.hashv = (unsigned int )((size_t )s->hh.hashv + tmp___11); switch (_hj_k___0) { case 11U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 10) << 24; case 10U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 9) << 16; case 9U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 8) << 8; case 8U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 7) << 24; case 7U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 6) << 16; case 6U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 5) << 8; case 5U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 4); case 4U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 3) << 24; case 3U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 2) << 16; case 2U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 1) << 8; case 1U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 0); } while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 13; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 12; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 3; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 15; break; } _ha_bkt = s->hh.hashv & ((itable->hh.tbl)->num_buckets - 1U); break; } while (1) { (((itable->hh.tbl)->buckets + _ha_bkt)->count) ++; s->hh.hh_next = ((itable->hh.tbl)->buckets + _ha_bkt)->hh_head; s->hh.hh_prev = (struct UT_hash_handle *)((void *)0); if (((itable->hh.tbl)->buckets + _ha_bkt)->hh_head) { (((itable->hh.tbl)->buckets + _ha_bkt)->hh_head)->hh_prev = & s->hh; } ((itable->hh.tbl)->buckets + _ha_bkt)->hh_head = & s->hh; if (((itable->hh.tbl)->buckets + _ha_bkt)->count >= (((itable->hh.tbl)->buckets + _ha_bkt)->expand_mult + 1U) * 10U) { if ((s->hh.tbl)->noexpand != 1U) { while (1) { tmp___12 = malloc((unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); _he_new_buckets = (UT_hash_bucket *)tmp___12; if (! _he_new_buckets) { exit(-1); } memset((void *)_he_new_buckets, 0, (unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); if ((s->hh.tbl)->num_items & ((s->hh.tbl)->num_buckets * 2U - 1U)) { tmp___13 = 1; } else { tmp___13 = 0; } (s->hh.tbl)->ideal_chain_maxlen = ((s->hh.tbl)->num_items >> ((s->hh.tbl)->log2_num_buckets + 1U)) + (unsigned int )tmp___13; (s->hh.tbl)->nonideal_items = 0U; _he_bkt_i = 0U; while (_he_bkt_i < (s->hh.tbl)->num_buckets) { _he_thh = ((s->hh.tbl)->buckets + _he_bkt_i)->hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; while (1) { _he_bkt = _he_thh->hashv & ((s->hh.tbl)->num_buckets * 2U - 1U); break; } _he_newbkt = _he_new_buckets + _he_bkt; (_he_newbkt->count) ++; if (_he_newbkt->count > (s->hh.tbl)->ideal_chain_maxlen) { ((s->hh.tbl)->nonideal_items) ++; _he_newbkt->expand_mult = _he_newbkt->count / (s->hh.tbl)->ideal_chain_maxlen; } _he_thh->hh_prev = (struct UT_hash_handle *)((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) { (_he_newbkt->hh_head)->hh_prev = _he_thh; } _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } _he_bkt_i ++; } free((void *)(s->hh.tbl)->buckets); (s->hh.tbl)->num_buckets *= 2U; ((s->hh.tbl)->log2_num_buckets) ++; (s->hh.tbl)->buckets = _he_new_buckets; if ((s->hh.tbl)->nonideal_items > (s->hh.tbl)->num_items >> 1) { ((s->hh.tbl)->ineff_expands) ++; } else { (s->hh.tbl)->ineff_expands = 0U; } if ((s->hh.tbl)->ineff_expands > 1U) { (s->hh.tbl)->noexpand = 1U; } break; } } } break; } break; } s->value = val; } } else { if ((unsigned long )s == (unsigned long )((void *)0)) { tmp___14 = malloc(sizeof(struct intVartable )); s = (struct intVartable *)tmp___14; tmp___15 = strlen((char const *)sname); tmp___16 = malloc(sizeof(char ) * (tmp___15 + 1UL)); s->sname = (char *)tmp___16; strcpy((char * __restrict )s->sname, (char const * __restrict )sname); while (1) { s->hh.next = (void *)0; s->hh.key = (void *)(s->sname + 0); tmp___17 = strlen((char const *)s->sname); s->hh.keylen = (unsigned int )tmp___17; if (! itable) { itable = s; itable->hh.prev = (void *)0; while (1) { tmp___18 = malloc(sizeof(UT_hash_table )); itable->hh.tbl = (UT_hash_table *)tmp___18; if (! itable->hh.tbl) { exit(-1); } memset((void *)itable->hh.tbl, 0, sizeof(UT_hash_table )); (itable->hh.tbl)->tail = & itable->hh; (itable->hh.tbl)->num_buckets = 32U; (itable->hh.tbl)->log2_num_buckets = 5U; (itable->hh.tbl)->hho = (char *)(& itable->hh) - (char *)itable; tmp___19 = malloc(32UL * sizeof(struct UT_hash_bucket )); (itable->hh.tbl)->buckets = (UT_hash_bucket *)tmp___19; if (! (itable->hh.tbl)->buckets) { exit(-1); } memset((void *)(itable->hh.tbl)->buckets, 0, 32UL * sizeof(struct UT_hash_bucket )); (itable->hh.tbl)->signature = 2685476833U; break; } } else { ((itable->hh.tbl)->tail)->next = (void *)s; s->hh.prev = (void *)((char *)(itable->hh.tbl)->tail - (itable->hh.tbl)->hho); (itable->hh.tbl)->tail = & s->hh; } ((itable->hh.tbl)->num_items) ++; s->hh.tbl = itable->hh.tbl; while (1) { _hj_key___1 = (unsigned char *)(s->sname + 0); s->hh.hashv = 4276993775U; _hj_j___1 = 2654435769U; _hj_i___1 = _hj_j___1; tmp___20 = strlen((char const *)s->sname); _hj_k___1 = (unsigned int )tmp___20; while (_hj_k___1 >= 12U) { _hj_i___1 += (((unsigned int )*(_hj_key___1 + 0) + ((unsigned int )*(_hj_key___1 + 1) << 8)) + ((unsigned int )*(_hj_key___1 + 2) << 16)) + ((unsigned int )*(_hj_key___1 + 3) << 24); _hj_j___1 += (((unsigned int )*(_hj_key___1 + 4) + ((unsigned int )*(_hj_key___1 + 5) << 8)) + ((unsigned int )*(_hj_key___1 + 6) << 16)) + ((unsigned int )*(_hj_key___1 + 7) << 24); s->hh.hashv += (((unsigned int )*(_hj_key___1 + 8) + ((unsigned int )*(_hj_key___1 + 9) << 8)) + ((unsigned int )*(_hj_key___1 + 10) << 16)) + ((unsigned int )*(_hj_key___1 + 11) << 24); while (1) { _hj_i___1 -= _hj_j___1; _hj_i___1 -= s->hh.hashv; _hj_i___1 ^= s->hh.hashv >> 13; _hj_j___1 -= s->hh.hashv; _hj_j___1 -= _hj_i___1; _hj_j___1 ^= _hj_i___1 << 8; s->hh.hashv -= _hj_i___1; s->hh.hashv -= _hj_j___1; s->hh.hashv ^= _hj_j___1 >> 13; _hj_i___1 -= _hj_j___1; _hj_i___1 -= s->hh.hashv; _hj_i___1 ^= s->hh.hashv >> 12; _hj_j___1 -= s->hh.hashv; _hj_j___1 -= _hj_i___1; _hj_j___1 ^= _hj_i___1 << 16; s->hh.hashv -= _hj_i___1; s->hh.hashv -= _hj_j___1; s->hh.hashv ^= _hj_j___1 >> 5; _hj_i___1 -= _hj_j___1; _hj_i___1 -= s->hh.hashv; _hj_i___1 ^= s->hh.hashv >> 3; _hj_j___1 -= s->hh.hashv; _hj_j___1 -= _hj_i___1; _hj_j___1 ^= _hj_i___1 << 10; s->hh.hashv -= _hj_i___1; s->hh.hashv -= _hj_j___1; s->hh.hashv ^= _hj_j___1 >> 15; break; } _hj_key___1 += 12; _hj_k___1 -= 12U; } tmp___21 = strlen((char const *)s->sname); s->hh.hashv = (unsigned int )((size_t )s->hh.hashv + tmp___21); switch (_hj_k___1) { case 11U: s->hh.hashv += (unsigned int )*(_hj_key___1 + 10) << 24; case 10U: s->hh.hashv += (unsigned int )*(_hj_key___1 + 9) << 16; case 9U: s->hh.hashv += (unsigned int )*(_hj_key___1 + 8) << 8; case 8U: _hj_j___1 += (unsigned int )*(_hj_key___1 + 7) << 24; case 7U: _hj_j___1 += (unsigned int )*(_hj_key___1 + 6) << 16; case 6U: _hj_j___1 += (unsigned int )*(_hj_key___1 + 5) << 8; case 5U: _hj_j___1 += (unsigned int )*(_hj_key___1 + 4); case 4U: _hj_i___1 += (unsigned int )*(_hj_key___1 + 3) << 24; case 3U: _hj_i___1 += (unsigned int )*(_hj_key___1 + 2) << 16; case 2U: _hj_i___1 += (unsigned int )*(_hj_key___1 + 1) << 8; case 1U: _hj_i___1 += (unsigned int )*(_hj_key___1 + 0); } while (1) { _hj_i___1 -= _hj_j___1; _hj_i___1 -= s->hh.hashv; _hj_i___1 ^= s->hh.hashv >> 13; _hj_j___1 -= s->hh.hashv; _hj_j___1 -= _hj_i___1; _hj_j___1 ^= _hj_i___1 << 8; s->hh.hashv -= _hj_i___1; s->hh.hashv -= _hj_j___1; s->hh.hashv ^= _hj_j___1 >> 13; _hj_i___1 -= _hj_j___1; _hj_i___1 -= s->hh.hashv; _hj_i___1 ^= s->hh.hashv >> 12; _hj_j___1 -= s->hh.hashv; _hj_j___1 -= _hj_i___1; _hj_j___1 ^= _hj_i___1 << 16; s->hh.hashv -= _hj_i___1; s->hh.hashv -= _hj_j___1; s->hh.hashv ^= _hj_j___1 >> 5; _hj_i___1 -= _hj_j___1; _hj_i___1 -= s->hh.hashv; _hj_i___1 ^= s->hh.hashv >> 3; _hj_j___1 -= s->hh.hashv; _hj_j___1 -= _hj_i___1; _hj_j___1 ^= _hj_i___1 << 10; s->hh.hashv -= _hj_i___1; s->hh.hashv -= _hj_j___1; s->hh.hashv ^= _hj_j___1 >> 15; break; } _ha_bkt___0 = s->hh.hashv & ((itable->hh.tbl)->num_buckets - 1U); break; } while (1) { (((itable->hh.tbl)->buckets + _ha_bkt___0)->count) ++; s->hh.hh_next = ((itable->hh.tbl)->buckets + _ha_bkt___0)->hh_head; s->hh.hh_prev = (struct UT_hash_handle *)((void *)0); if (((itable->hh.tbl)->buckets + _ha_bkt___0)->hh_head) { (((itable->hh.tbl)->buckets + _ha_bkt___0)->hh_head)->hh_prev = & s->hh; } ((itable->hh.tbl)->buckets + _ha_bkt___0)->hh_head = & s->hh; if (((itable->hh.tbl)->buckets + _ha_bkt___0)->count >= (((itable->hh.tbl)->buckets + _ha_bkt___0)->expand_mult + 1U) * 10U) { if ((s->hh.tbl)->noexpand != 1U) { while (1) { tmp___22 = malloc((unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); _he_new_buckets___0 = (UT_hash_bucket *)tmp___22; if (! _he_new_buckets___0) { exit(-1); } memset((void *)_he_new_buckets___0, 0, (unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); if ((s->hh.tbl)->num_items & ((s->hh.tbl)->num_buckets * 2U - 1U)) { tmp___23 = 1; } else { tmp___23 = 0; } (s->hh.tbl)->ideal_chain_maxlen = ((s->hh.tbl)->num_items >> ((s->hh.tbl)->log2_num_buckets + 1U)) + (unsigned int )tmp___23; (s->hh.tbl)->nonideal_items = 0U; _he_bkt_i___0 = 0U; while (_he_bkt_i___0 < (s->hh.tbl)->num_buckets) { _he_thh___0 = ((s->hh.tbl)->buckets + _he_bkt_i___0)->hh_head; while (_he_thh___0) { _he_hh_nxt___0 = _he_thh___0->hh_next; while (1) { _he_bkt___0 = _he_thh___0->hashv & ((s->hh.tbl)->num_buckets * 2U - 1U); break; } _he_newbkt___0 = _he_new_buckets___0 + _he_bkt___0; (_he_newbkt___0->count) ++; if (_he_newbkt___0->count > (s->hh.tbl)->ideal_chain_maxlen) { ((s->hh.tbl)->nonideal_items) ++; _he_newbkt___0->expand_mult = _he_newbkt___0->count / (s->hh.tbl)->ideal_chain_maxlen; } _he_thh___0->hh_prev = (struct UT_hash_handle *)((void *)0); _he_thh___0->hh_next = _he_newbkt___0->hh_head; if (_he_newbkt___0->hh_head) { (_he_newbkt___0->hh_head)->hh_prev = _he_thh___0; } _he_newbkt___0->hh_head = _he_thh___0; _he_thh___0 = _he_hh_nxt___0; } _he_bkt_i___0 ++; } free((void *)(s->hh.tbl)->buckets); (s->hh.tbl)->num_buckets *= 2U; ((s->hh.tbl)->log2_num_buckets) ++; (s->hh.tbl)->buckets = _he_new_buckets___0; if ((s->hh.tbl)->nonideal_items > (s->hh.tbl)->num_items >> 1) { ((s->hh.tbl)->ineff_expands) ++; } else { (s->hh.tbl)->ineff_expands = 0U; } if ((s->hh.tbl)->ineff_expands > 1U) { (s->hh.tbl)->noexpand = 1U; } break; } } } break; } break; } } s->value = val; } return; } } void addToFloatTable(char *sname , float *val ) { struct floatVartable *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; size_t tmp ; size_t tmp___0 ; size_t tmp___1 ; int tmp___2 ; size_t tmp___3 ; void *tmp___4 ; size_t tmp___5 ; void *tmp___6 ; unsigned int _ha_bkt ; size_t tmp___7 ; void *tmp___8 ; void *tmp___9 ; unsigned int _hj_i___0 ; unsigned int _hj_j___0 ; unsigned int _hj_k___0 ; unsigned char *_hj_key___0 ; size_t tmp___10 ; size_t tmp___11 ; unsigned int _he_bkt ; unsigned int _he_bkt_i ; struct UT_hash_handle *_he_thh ; struct UT_hash_handle *_he_hh_nxt ; UT_hash_bucket *_he_new_buckets ; UT_hash_bucket *_he_newbkt ; void *tmp___12 ; int tmp___13 ; { while (1) { s = (struct floatVartable *)((void *)0); if (ftable) { while (1) { _hj_key = (unsigned char *)sname; _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; tmp = strlen((char const *)sname); _hj_k = (unsigned int )tmp; while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } tmp___0 = strlen((char const *)sname); _hf_hashv = (unsigned int )((size_t )_hf_hashv + tmp___0); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((ftable->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((ftable->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct floatVartable *)((void *)((char *)((ftable->hh.tbl)->buckets + _hf_bkt)->hh_head - (ftable->hh.tbl)->hho)); break; } } else { s = (struct floatVartable *)((void *)0); } while (s) { tmp___3 = strlen((char const *)sname); if ((size_t )s->hh.keylen == tmp___3) { tmp___1 = strlen((char const *)sname); tmp___2 = memcmp((void const *)s->hh.key, (void const *)sname, tmp___1); if (tmp___2 == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct floatVartable *)((void *)((char *)s->hh.hh_next - (ftable->hh.tbl)->hho)); break; } } else { s = (struct floatVartable *)((void *)0); } } break; } } break; } if ((unsigned long )s == (unsigned long )((void *)0)) { tmp___4 = malloc(sizeof(struct floatVartable )); s = (struct floatVartable *)tmp___4; tmp___5 = strlen((char const *)sname); tmp___6 = malloc(sizeof(char ) * (tmp___5 + 1UL)); s->sname = (char *)tmp___6; strcpy((char * __restrict )s->sname, (char const * __restrict )sname); while (1) { s->hh.next = (void *)0; s->hh.key = (void *)(s->sname + 0); tmp___7 = strlen((char const *)s->sname); s->hh.keylen = (unsigned int )tmp___7; if (! ftable) { ftable = s; ftable->hh.prev = (void *)0; while (1) { tmp___8 = malloc(sizeof(UT_hash_table )); ftable->hh.tbl = (UT_hash_table *)tmp___8; if (! ftable->hh.tbl) { exit(-1); } memset((void *)ftable->hh.tbl, 0, sizeof(UT_hash_table )); (ftable->hh.tbl)->tail = & ftable->hh; (ftable->hh.tbl)->num_buckets = 32U; (ftable->hh.tbl)->log2_num_buckets = 5U; (ftable->hh.tbl)->hho = (char *)(& ftable->hh) - (char *)ftable; tmp___9 = malloc(32UL * sizeof(struct UT_hash_bucket )); (ftable->hh.tbl)->buckets = (UT_hash_bucket *)tmp___9; if (! (ftable->hh.tbl)->buckets) { exit(-1); } memset((void *)(ftable->hh.tbl)->buckets, 0, 32UL * sizeof(struct UT_hash_bucket )); (ftable->hh.tbl)->signature = 2685476833U; break; } } else { ((ftable->hh.tbl)->tail)->next = (void *)s; s->hh.prev = (void *)((char *)(ftable->hh.tbl)->tail - (ftable->hh.tbl)->hho); (ftable->hh.tbl)->tail = & s->hh; } ((ftable->hh.tbl)->num_items) ++; s->hh.tbl = ftable->hh.tbl; while (1) { _hj_key___0 = (unsigned char *)(s->sname + 0); s->hh.hashv = 4276993775U; _hj_j___0 = 2654435769U; _hj_i___0 = _hj_j___0; tmp___10 = strlen((char const *)s->sname); _hj_k___0 = (unsigned int )tmp___10; while (_hj_k___0 >= 12U) { _hj_i___0 += (((unsigned int )*(_hj_key___0 + 0) + ((unsigned int )*(_hj_key___0 + 1) << 8)) + ((unsigned int )*(_hj_key___0 + 2) << 16)) + ((unsigned int )*(_hj_key___0 + 3) << 24); _hj_j___0 += (((unsigned int )*(_hj_key___0 + 4) + ((unsigned int )*(_hj_key___0 + 5) << 8)) + ((unsigned int )*(_hj_key___0 + 6) << 16)) + ((unsigned int )*(_hj_key___0 + 7) << 24); s->hh.hashv += (((unsigned int )*(_hj_key___0 + 8) + ((unsigned int )*(_hj_key___0 + 9) << 8)) + ((unsigned int )*(_hj_key___0 + 10) << 16)) + ((unsigned int )*(_hj_key___0 + 11) << 24); while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 13; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 12; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 3; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 15; break; } _hj_key___0 += 12; _hj_k___0 -= 12U; } tmp___11 = strlen((char const *)s->sname); s->hh.hashv = (unsigned int )((size_t )s->hh.hashv + tmp___11); switch (_hj_k___0) { case 11U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 10) << 24; case 10U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 9) << 16; case 9U: s->hh.hashv += (unsigned int )*(_hj_key___0 + 8) << 8; case 8U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 7) << 24; case 7U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 6) << 16; case 6U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 5) << 8; case 5U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 4); case 4U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 3) << 24; case 3U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 2) << 16; case 2U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 1) << 8; case 1U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 0); } while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 13; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 12; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= s->hh.hashv; _hj_i___0 ^= s->hh.hashv >> 3; _hj_j___0 -= s->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; s->hh.hashv -= _hj_i___0; s->hh.hashv -= _hj_j___0; s->hh.hashv ^= _hj_j___0 >> 15; break; } _ha_bkt = s->hh.hashv & ((ftable->hh.tbl)->num_buckets - 1U); break; } while (1) { (((ftable->hh.tbl)->buckets + _ha_bkt)->count) ++; s->hh.hh_next = ((ftable->hh.tbl)->buckets + _ha_bkt)->hh_head; s->hh.hh_prev = (struct UT_hash_handle *)((void *)0); if (((ftable->hh.tbl)->buckets + _ha_bkt)->hh_head) { (((ftable->hh.tbl)->buckets + _ha_bkt)->hh_head)->hh_prev = & s->hh; } ((ftable->hh.tbl)->buckets + _ha_bkt)->hh_head = & s->hh; if (((ftable->hh.tbl)->buckets + _ha_bkt)->count >= (((ftable->hh.tbl)->buckets + _ha_bkt)->expand_mult + 1U) * 10U) { if ((s->hh.tbl)->noexpand != 1U) { while (1) { tmp___12 = malloc((unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); _he_new_buckets = (UT_hash_bucket *)tmp___12; if (! _he_new_buckets) { exit(-1); } memset((void *)_he_new_buckets, 0, (unsigned long )(2U * (s->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); if ((s->hh.tbl)->num_items & ((s->hh.tbl)->num_buckets * 2U - 1U)) { tmp___13 = 1; } else { tmp___13 = 0; } (s->hh.tbl)->ideal_chain_maxlen = ((s->hh.tbl)->num_items >> ((s->hh.tbl)->log2_num_buckets + 1U)) + (unsigned int )tmp___13; (s->hh.tbl)->nonideal_items = 0U; _he_bkt_i = 0U; while (_he_bkt_i < (s->hh.tbl)->num_buckets) { _he_thh = ((s->hh.tbl)->buckets + _he_bkt_i)->hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; while (1) { _he_bkt = _he_thh->hashv & ((s->hh.tbl)->num_buckets * 2U - 1U); break; } _he_newbkt = _he_new_buckets + _he_bkt; (_he_newbkt->count) ++; if (_he_newbkt->count > (s->hh.tbl)->ideal_chain_maxlen) { ((s->hh.tbl)->nonideal_items) ++; _he_newbkt->expand_mult = _he_newbkt->count / (s->hh.tbl)->ideal_chain_maxlen; } _he_thh->hh_prev = (struct UT_hash_handle *)((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) { (_he_newbkt->hh_head)->hh_prev = _he_thh; } _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } _he_bkt_i ++; } free((void *)(s->hh.tbl)->buckets); (s->hh.tbl)->num_buckets *= 2U; ((s->hh.tbl)->log2_num_buckets) ++; (s->hh.tbl)->buckets = _he_new_buckets; if ((s->hh.tbl)->nonideal_items > (s->hh.tbl)->num_items >> 1) { ((s->hh.tbl)->ineff_expands) ++; } else { (s->hh.tbl)->ineff_expands = 0U; } if ((s->hh.tbl)->ineff_expands > 1U) { (s->hh.tbl)->noexpand = 1U; } break; } } } break; } break; } } s->value = val; return; } } int updateIntValBySname(char *sname , int value ) { struct intVartable *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; size_t tmp ; size_t tmp___0 ; size_t tmp___1 ; int tmp___2 ; size_t tmp___3 ; { while (1) { s = (struct intVartable *)((void *)0); if (itable) { while (1) { _hj_key = (unsigned char *)sname; _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; tmp = strlen((char const *)sname); _hj_k = (unsigned int )tmp; while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } tmp___0 = strlen((char const *)sname); _hf_hashv = (unsigned int )((size_t )_hf_hashv + tmp___0); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((itable->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((itable->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct intVartable *)((void *)((char *)((itable->hh.tbl)->buckets + _hf_bkt)->hh_head - (itable->hh.tbl)->hho)); break; } } else { s = (struct intVartable *)((void *)0); } while (s) { tmp___3 = strlen((char const *)sname); if ((size_t )s->hh.keylen == tmp___3) { tmp___1 = strlen((char const *)sname); tmp___2 = memcmp((void const *)s->hh.key, (void const *)sname, tmp___1); if (tmp___2 == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct intVartable *)((void *)((char *)s->hh.hh_next - (itable->hh.tbl)->hho)); break; } } else { s = (struct intVartable *)((void *)0); } } break; } } break; } if ((unsigned long )s == (unsigned long )((void *)0)) { printf((char const * __restrict )"Its null\n"); return (0); } *(s->value) = value; return (1); } } int updateFloatValBySname(char *sname , float value ) { struct floatVartable *s ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; size_t tmp ; size_t tmp___0 ; size_t tmp___1 ; int tmp___2 ; size_t tmp___3 ; { while (1) { s = (struct floatVartable *)((void *)0); if (ftable) { while (1) { _hj_key = (unsigned char *)sname; _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; tmp = strlen((char const *)sname); _hj_k = (unsigned int )tmp; while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } tmp___0 = strlen((char const *)sname); _hf_hashv = (unsigned int )((size_t )_hf_hashv + tmp___0); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((ftable->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((ftable->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { s = (struct floatVartable *)((void *)((char *)((ftable->hh.tbl)->buckets + _hf_bkt)->hh_head - (ftable->hh.tbl)->hho)); break; } } else { s = (struct floatVartable *)((void *)0); } while (s) { tmp___3 = strlen((char const *)sname); if ((size_t )s->hh.keylen == tmp___3) { tmp___1 = strlen((char const *)sname); tmp___2 = memcmp((void const *)s->hh.key, (void const *)sname, tmp___1); if (tmp___2 == 0) { break; } } if (s->hh.hh_next) { while (1) { s = (struct floatVartable *)((void *)((char *)s->hh.hh_next - (ftable->hh.tbl)->hho)); break; } } else { s = (struct floatVartable *)((void *)0); } } break; } } break; } if ((unsigned long )s == (unsigned long )((void *)0)) { return (0); } *(s->value) = value; return (1); } } void deleteTableEntry(void) { struct intVartable *curr ; struct intVartable *tmp ; struct floatVartable *curr1 ; struct floatVartable *tmp1 ; void *tmp___0 ; void *tmp___1 ; unsigned int _hd_bkt ; struct UT_hash_handle *_hd_hh_del ; void *tmp___2 ; void *tmp___3 ; unsigned int _hd_bkt___0 ; struct UT_hash_handle *_hd_hh_del___0 ; { curr = itable; if (itable) { tmp___0 = itable->hh.next; } else { tmp___0 = (void *)0; } tmp = (struct intVartable *)tmp___0; while (curr) { while (1) { if ((unsigned long )curr->hh.prev == (unsigned long )((void *)0)) { if ((unsigned long )curr->hh.next == (unsigned long )((void *)0)) { free((void *)(itable->hh.tbl)->buckets); free((void *)itable->hh.tbl); itable = (struct intVartable *)((void *)0); } else { goto _L; } } else { _L: /* CIL Label */ _hd_hh_del = & curr->hh; if ((unsigned long )curr == (unsigned long )((void *)((char *)(itable->hh.tbl)->tail - (itable->hh.tbl)->hho))) { (itable->hh.tbl)->tail = (UT_hash_handle *)((ptrdiff_t )curr->hh.prev + (itable->hh.tbl)->hho); } if (curr->hh.prev) { ((UT_hash_handle *)((ptrdiff_t )curr->hh.prev + (itable->hh.tbl)->hho))->next = curr->hh.next; } else { while (1) { itable = (struct intVartable *)curr->hh.next; break; } } if (_hd_hh_del->next) { ((UT_hash_handle *)((ptrdiff_t )_hd_hh_del->next + (itable->hh.tbl)->hho))->prev = _hd_hh_del->prev; } while (1) { _hd_bkt = _hd_hh_del->hashv & ((itable->hh.tbl)->num_buckets - 1U); break; } (((itable->hh.tbl)->buckets + _hd_bkt)->count) --; if ((unsigned long )((itable->hh.tbl)->buckets + _hd_bkt)->hh_head == (unsigned long )_hd_hh_del) { ((itable->hh.tbl)->buckets + _hd_bkt)->hh_head = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_prev) { (_hd_hh_del->hh_prev)->hh_next = _hd_hh_del->hh_next; } if (_hd_hh_del->hh_next) { (_hd_hh_del->hh_next)->hh_prev = _hd_hh_del->hh_prev; } ((itable->hh.tbl)->num_items) --; } break; } free((void *)curr); curr = tmp; if (tmp) { tmp___1 = tmp->hh.next; } else { tmp___1 = (void *)0; } tmp = (struct intVartable *)tmp___1; } curr1 = ftable; if (ftable) { tmp___2 = ftable->hh.next; } else { tmp___2 = (void *)0; } tmp1 = (struct floatVartable *)tmp___2; while (curr1) { while (1) { if ((unsigned long )curr1->hh.prev == (unsigned long )((void *)0)) { if ((unsigned long )curr1->hh.next == (unsigned long )((void *)0)) { free((void *)(ftable->hh.tbl)->buckets); free((void *)ftable->hh.tbl); ftable = (struct floatVartable *)((void *)0); } else { goto _L___0; } } else { _L___0: /* CIL Label */ _hd_hh_del___0 = & curr1->hh; if ((unsigned long )curr1 == (unsigned long )((void *)((char *)(ftable->hh.tbl)->tail - (ftable->hh.tbl)->hho))) { (ftable->hh.tbl)->tail = (UT_hash_handle *)((ptrdiff_t )curr1->hh.prev + (ftable->hh.tbl)->hho); } if (curr1->hh.prev) { ((UT_hash_handle *)((ptrdiff_t )curr1->hh.prev + (ftable->hh.tbl)->hho))->next = curr1->hh.next; } else { while (1) { ftable = (struct floatVartable *)curr1->hh.next; break; } } if (_hd_hh_del___0->next) { ((UT_hash_handle *)((ptrdiff_t )_hd_hh_del___0->next + (ftable->hh.tbl)->hho))->prev = _hd_hh_del___0->prev; } while (1) { _hd_bkt___0 = _hd_hh_del___0->hashv & ((ftable->hh.tbl)->num_buckets - 1U); break; } (((ftable->hh.tbl)->buckets + _hd_bkt___0)->count) --; if ((unsigned long )((ftable->hh.tbl)->buckets + _hd_bkt___0)->hh_head == (unsigned long )_hd_hh_del___0) { ((ftable->hh.tbl)->buckets + _hd_bkt___0)->hh_head = _hd_hh_del___0->hh_next; } if (_hd_hh_del___0->hh_prev) { (_hd_hh_del___0->hh_prev)->hh_next = _hd_hh_del___0->hh_next; } if (_hd_hh_del___0->hh_next) { (_hd_hh_del___0->hh_next)->hh_prev = _hd_hh_del___0->hh_prev; } ((ftable->hh.tbl)->num_items) --; } break; } free((void *)curr1); curr1 = tmp1; if (tmp1) { tmp___3 = tmp1->hh.next; } else { tmp___3 = (void *)0; } tmp1 = (struct floatVartable *)tmp___3; } return; } } void writeProgramSVariables(void) { struct intVartable *s ; struct floatVartable *s1 ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; { printFile(":extrafuns ("); s = itable; while ((unsigned long )s != (unsigned long )((void *)0)) { tmp = strcmp((char const *)s->sname, "Function"); if (tmp == 0) { goto __Cont; } else { tmp___0 = strcmp((char const *)s->sname, "Constant"); if (tmp___0 == 0) { goto __Cont; } else if ((int )*(s->sname + 0) == 40) { goto __Cont; } } printFile("("); printFile(s->sname); printFile(" Int)"); __Cont: /* CIL Label */ s = (struct intVartable *)s->hh.next; } s1 = ftable; while ((unsigned long )s1 != (unsigned long )((void *)0)) { tmp___1 = strcmp((char const *)s1->sname, "Function"); if (tmp___1 == 0) { goto __Cont___0; } else { tmp___2 = strcmp((char const *)s1->sname, "Constant"); if (tmp___2 == 0) { goto __Cont___0; } else if ((int )*(s1->sname + 0) == 40) { goto __Cont___0; } else if ((int )*(s1->sname + 0) == 45) { goto __Cont___0; } } printFile("("); printFile(s1->sname); printFile(" Real)"); __Cont___0: /* CIL Label */ s1 = (struct floatVartable *)s1->hh.next; } printFile(")\n"); return; } } #pragma merger("0","./flatds.i","-g,-g") extern __attribute__((__nothrow__, __noreturn__)) void ( __attribute__((__leaf__)) __assert_fail)(char const *__assertion , char const *__file , unsigned int __line , char const *__function ) ; void *load(void *addr , char *field , int t ) ; void store(void *addr , char *lField , int t , void *value , char *sname ) ; char *getSymName(void *addr , char *field ) ; void setValue(char *symName , int t , void *value ) ; void *getValue(char *symName ) ; void UpdateSymName(char *symName , char *sname ) ; ObjectType getObjectType(int t ) ; static int toInt___1(void *addr ) { { return ((int )((size_t )addr % 2147483647UL)); } } static int getSizeByType(ObjectType type ) { int size ; { size = 0; switch ((unsigned int )type) { case 0U: size = (int )sizeof(char ); break; case 1U: size = (int )sizeof(int ); break; case 2U: size = (int )sizeof(float ); break; case 3U: break; default: if ((void *)0) { if (! "No size for this type") { __assert_fail("((void *)0) && \"No size for this type\"", "src/src/flatds.c", 22U, "getSizeByType"); } } else { __assert_fail("((void *)0) && \"No size for this type\"", "src/src/flatds.c", 22U, "getSizeByType"); } break; } return (size); } } static ObjectHT *newField(char *baseSymName , char *lField , ObjectType type , void *value , char *sname ) { ObjectHT *o ; void *tmp ; ObjectHT *objectHT ; ObjectHT *t ; char base[12] ; int size ; size_t tmp___0 ; void *tmp___1 ; size_t tmp___2 ; void *tmp___3 ; size_t tmp___4 ; size_t tmp___5 ; void *tmp___6 ; void *tmp___7 ; size_t tmp___8 ; void *tmp___9 ; size_t tmp___10 ; unsigned int _ha_bkt ; size_t tmp___11 ; void *tmp___12 ; void *tmp___13 ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; size_t tmp___14 ; size_t tmp___15 ; unsigned int _he_bkt ; unsigned int _he_bkt_i ; struct UT_hash_handle *_he_thh ; struct UT_hash_handle *_he_hh_nxt ; UT_hash_bucket *_he_new_buckets ; UT_hash_bucket *_he_newbkt ; void *tmp___16 ; int tmp___17 ; size_t tmp___18 ; void *tmp___19 ; { tmp = malloc(sizeof(ObjectHT )); o = (ObjectHT *)tmp; objectHT = (ObjectHT *)((void *)0); base[0] = (char )'b'; base[1] = (char )'a'; base[2] = (char )'s'; base[3] = (char )'e'; base[4] = (char )'S'; base[5] = (char )'y'; base[6] = (char )'m'; base[7] = (char )'N'; base[8] = (char )'a'; base[9] = (char )'m'; base[10] = (char )'e'; base[11] = (char )'\000'; switch ((unsigned int )type) { case 0U: size = (int )sizeof(char ); o->val = malloc((size_t )size); memcpy((void * __restrict )o->val, (void const * __restrict )value, (size_t )size); break; case 1U: tmp___0 = strlen((char const *)sname); tmp___1 = malloc(sizeof(char ) * (tmp___0 + 1UL)); o->symName = (char *)tmp___1; strcpy((char * __restrict )o->symName, (char const * __restrict )sname); size = (int )sizeof(int ); o->val = malloc((size_t )size); memcpy((void * __restrict )o->val, (void const * __restrict )value, (size_t )size); addToIntTable(o->symName, (int *)value); break; case 2U: tmp___2 = strlen((char const *)sname); tmp___3 = malloc(sizeof(char ) * (tmp___2 + 1UL)); o->symName = (char *)tmp___3; strcpy((char * __restrict )o->symName, (char const * __restrict )sname); size = (int )sizeof(float ); o->val = malloc((size_t )size); memcpy((void * __restrict )o->val, (void const * __restrict )value, (size_t )size); addToFloatTable(o->symName, (float *)value); break; case 4U: case 3U: tmp___4 = strlen((char const *)baseSymName); tmp___5 = strlen((char const *)lField); tmp___6 = malloc(sizeof(char ) * (((tmp___4 + tmp___5) + 1UL) + 1UL)); o->symName = (char *)tmp___6; strcpy((char * __restrict )o->symName, (char const * __restrict )baseSymName); strcat((char * __restrict )o->symName, (char const * __restrict )"_"); strcat((char * __restrict )o->symName, (char const * __restrict )lField); tmp___7 = malloc(sizeof(ObjectHT )); t = (ObjectHT *)tmp___7; tmp___8 = strlen((char const *)(base)); tmp___9 = malloc(sizeof(char ) * (tmp___8 + 1UL)); t->field = (char *)tmp___9; strcpy((char * __restrict )t->field, (char const * __restrict )(base)); tmp___10 = strlen((char const *)o->symName); t->val = malloc((tmp___10 + 1UL) * sizeof(char )); strcpy((char * __restrict )t->val, (char const * __restrict )o->symName); while (1) { t->hh.next = (void *)0; t->hh.key = (void *)(t->field + 0); tmp___11 = strlen((char const *)t->field); t->hh.keylen = (unsigned int )tmp___11; if (! objectHT) { objectHT = t; objectHT->hh.prev = (void *)0; while (1) { tmp___12 = malloc(sizeof(UT_hash_table )); objectHT->hh.tbl = (UT_hash_table *)tmp___12; if (! objectHT->hh.tbl) { exit(-1); } memset((void *)objectHT->hh.tbl, 0, sizeof(UT_hash_table )); (objectHT->hh.tbl)->tail = & objectHT->hh; (objectHT->hh.tbl)->num_buckets = 32U; (objectHT->hh.tbl)->log2_num_buckets = 5U; (objectHT->hh.tbl)->hho = (char *)(& objectHT->hh) - (char *)objectHT; tmp___13 = malloc(32UL * sizeof(struct UT_hash_bucket )); (objectHT->hh.tbl)->buckets = (UT_hash_bucket *)tmp___13; if (! (objectHT->hh.tbl)->buckets) { exit(-1); } memset((void *)(objectHT->hh.tbl)->buckets, 0, 32UL * sizeof(struct UT_hash_bucket )); (objectHT->hh.tbl)->signature = 2685476833U; break; } } else { ((objectHT->hh.tbl)->tail)->next = (void *)t; t->hh.prev = (void *)((char *)(objectHT->hh.tbl)->tail - (objectHT->hh.tbl)->hho); (objectHT->hh.tbl)->tail = & t->hh; } ((objectHT->hh.tbl)->num_items) ++; t->hh.tbl = objectHT->hh.tbl; while (1) { _hj_key = (unsigned char *)(t->field + 0); t->hh.hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; tmp___14 = strlen((char const *)t->field); _hj_k = (unsigned int )tmp___14; while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); t->hh.hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= t->hh.hashv; _hj_i ^= t->hh.hashv >> 13; _hj_j -= t->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; t->hh.hashv -= _hj_i; t->hh.hashv -= _hj_j; t->hh.hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= t->hh.hashv; _hj_i ^= t->hh.hashv >> 12; _hj_j -= t->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; t->hh.hashv -= _hj_i; t->hh.hashv -= _hj_j; t->hh.hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= t->hh.hashv; _hj_i ^= t->hh.hashv >> 3; _hj_j -= t->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; t->hh.hashv -= _hj_i; t->hh.hashv -= _hj_j; t->hh.hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } tmp___15 = strlen((char const *)t->field); t->hh.hashv = (unsigned int )((size_t )t->hh.hashv + tmp___15); switch (_hj_k) { case 11U: t->hh.hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: t->hh.hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: t->hh.hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= t->hh.hashv; _hj_i ^= t->hh.hashv >> 13; _hj_j -= t->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; t->hh.hashv -= _hj_i; t->hh.hashv -= _hj_j; t->hh.hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= t->hh.hashv; _hj_i ^= t->hh.hashv >> 12; _hj_j -= t->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; t->hh.hashv -= _hj_i; t->hh.hashv -= _hj_j; t->hh.hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= t->hh.hashv; _hj_i ^= t->hh.hashv >> 3; _hj_j -= t->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; t->hh.hashv -= _hj_i; t->hh.hashv -= _hj_j; t->hh.hashv ^= _hj_j >> 15; break; } _ha_bkt = t->hh.hashv & ((objectHT->hh.tbl)->num_buckets - 1U); break; } while (1) { (((objectHT->hh.tbl)->buckets + _ha_bkt)->count) ++; t->hh.hh_next = ((objectHT->hh.tbl)->buckets + _ha_bkt)->hh_head; t->hh.hh_prev = (struct UT_hash_handle *)((void *)0); if (((objectHT->hh.tbl)->buckets + _ha_bkt)->hh_head) { (((objectHT->hh.tbl)->buckets + _ha_bkt)->hh_head)->hh_prev = & t->hh; } ((objectHT->hh.tbl)->buckets + _ha_bkt)->hh_head = & t->hh; if (((objectHT->hh.tbl)->buckets + _ha_bkt)->count >= (((objectHT->hh.tbl)->buckets + _ha_bkt)->expand_mult + 1U) * 10U) { if ((t->hh.tbl)->noexpand != 1U) { while (1) { tmp___16 = malloc((unsigned long )(2U * (t->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); _he_new_buckets = (UT_hash_bucket *)tmp___16; if (! _he_new_buckets) { exit(-1); } memset((void *)_he_new_buckets, 0, (unsigned long )(2U * (t->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); if ((t->hh.tbl)->num_items & ((t->hh.tbl)->num_buckets * 2U - 1U)) { tmp___17 = 1; } else { tmp___17 = 0; } (t->hh.tbl)->ideal_chain_maxlen = ((t->hh.tbl)->num_items >> ((t->hh.tbl)->log2_num_buckets + 1U)) + (unsigned int )tmp___17; (t->hh.tbl)->nonideal_items = 0U; _he_bkt_i = 0U; while (_he_bkt_i < (t->hh.tbl)->num_buckets) { _he_thh = ((t->hh.tbl)->buckets + _he_bkt_i)->hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; while (1) { _he_bkt = _he_thh->hashv & ((t->hh.tbl)->num_buckets * 2U - 1U); break; } _he_newbkt = _he_new_buckets + _he_bkt; (_he_newbkt->count) ++; if (_he_newbkt->count > (t->hh.tbl)->ideal_chain_maxlen) { ((t->hh.tbl)->nonideal_items) ++; _he_newbkt->expand_mult = _he_newbkt->count / (t->hh.tbl)->ideal_chain_maxlen; } _he_thh->hh_prev = (struct UT_hash_handle *)((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) { (_he_newbkt->hh_head)->hh_prev = _he_thh; } _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } _he_bkt_i ++; } free((void *)(t->hh.tbl)->buckets); (t->hh.tbl)->num_buckets *= 2U; ((t->hh.tbl)->log2_num_buckets) ++; (t->hh.tbl)->buckets = _he_new_buckets; if ((t->hh.tbl)->nonideal_items > (t->hh.tbl)->num_items >> 1) { ((t->hh.tbl)->ineff_expands) ++; } else { (t->hh.tbl)->ineff_expands = 0U; } if ((t->hh.tbl)->ineff_expands > 1U) { (t->hh.tbl)->noexpand = 1U; } break; } } } break; } break; } o->val = (void *)objectHT; break; default: break; } tmp___18 = strlen((char const *)lField); tmp___19 = malloc(sizeof(char ) * (tmp___18 + 1UL)); o->field = (char *)tmp___19; strcpy((char * __restrict )o->field, (char const * __restrict )lField); return (o); } } static void addField(ObjectHT *objectHT , char *field , ObjectType type , void *value , char *sname ) { char base[12] ; ObjectHT *t ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; size_t tmp ; size_t tmp___0 ; size_t tmp___1 ; int tmp___2 ; size_t tmp___3 ; ObjectHT *o ; ObjectHT *tmp___4 ; unsigned int _ha_bkt ; size_t tmp___5 ; void *tmp___6 ; void *tmp___7 ; unsigned int _hj_i___0 ; unsigned int _hj_j___0 ; unsigned int _hj_k___0 ; unsigned char *_hj_key___0 ; size_t tmp___8 ; size_t tmp___9 ; unsigned int _he_bkt ; unsigned int _he_bkt_i ; struct UT_hash_handle *_he_thh ; struct UT_hash_handle *_he_hh_nxt ; UT_hash_bucket *_he_new_buckets ; UT_hash_bucket *_he_newbkt ; void *tmp___10 ; int tmp___11 ; { base[0] = (char )'b'; base[1] = (char )'a'; base[2] = (char )'s'; base[3] = (char )'e'; base[4] = (char )'S'; base[5] = (char )'y'; base[6] = (char )'m'; base[7] = (char )'N'; base[8] = (char )'a'; base[9] = (char )'m'; base[10] = (char )'e'; base[11] = (char )'\000'; while (1) { t = (ObjectHT *)((void *)0); if (objectHT) { while (1) { _hj_key = (unsigned char *)(base); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; tmp = strlen((char const *)(base)); _hj_k = (unsigned int )tmp; while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } tmp___0 = strlen((char const *)(base)); _hf_hashv = (unsigned int )((size_t )_hf_hashv + tmp___0); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((objectHT->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((objectHT->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { t = (ObjectHT *)((void *)((char *)((objectHT->hh.tbl)->buckets + _hf_bkt)->hh_head - (objectHT->hh.tbl)->hho)); break; } } else { t = (ObjectHT *)((void *)0); } while (t) { tmp___3 = strlen((char const *)(base)); if ((size_t )t->hh.keylen == tmp___3) { tmp___1 = strlen((char const *)(base)); tmp___2 = memcmp((void const *)t->hh.key, (void const *)(base), tmp___1); if (tmp___2 == 0) { break; } } if (t->hh.hh_next) { while (1) { t = (ObjectHT *)((void *)((char *)t->hh.hh_next - (objectHT->hh.tbl)->hho)); break; } } else { t = (ObjectHT *)((void *)0); } } break; } } break; } tmp___4 = newField((char *)t->val, field, type, value, sname); o = tmp___4; while (1) { o->hh.next = (void *)0; o->hh.key = (void *)(o->field + 0); tmp___5 = strlen((char const *)o->field); o->hh.keylen = (unsigned int )tmp___5; if (! objectHT) { objectHT = o; objectHT->hh.prev = (void *)0; while (1) { tmp___6 = malloc(sizeof(UT_hash_table )); objectHT->hh.tbl = (UT_hash_table *)tmp___6; if (! objectHT->hh.tbl) { exit(-1); } memset((void *)objectHT->hh.tbl, 0, sizeof(UT_hash_table )); (objectHT->hh.tbl)->tail = & objectHT->hh; (objectHT->hh.tbl)->num_buckets = 32U; (objectHT->hh.tbl)->log2_num_buckets = 5U; (objectHT->hh.tbl)->hho = (char *)(& objectHT->hh) - (char *)objectHT; tmp___7 = malloc(32UL * sizeof(struct UT_hash_bucket )); (objectHT->hh.tbl)->buckets = (UT_hash_bucket *)tmp___7; if (! (objectHT->hh.tbl)->buckets) { exit(-1); } memset((void *)(objectHT->hh.tbl)->buckets, 0, 32UL * sizeof(struct UT_hash_bucket )); (objectHT->hh.tbl)->signature = 2685476833U; break; } } else { ((objectHT->hh.tbl)->tail)->next = (void *)o; o->hh.prev = (void *)((char *)(objectHT->hh.tbl)->tail - (objectHT->hh.tbl)->hho); (objectHT->hh.tbl)->tail = & o->hh; } ((objectHT->hh.tbl)->num_items) ++; o->hh.tbl = objectHT->hh.tbl; while (1) { _hj_key___0 = (unsigned char *)(o->field + 0); o->hh.hashv = 4276993775U; _hj_j___0 = 2654435769U; _hj_i___0 = _hj_j___0; tmp___8 = strlen((char const *)o->field); _hj_k___0 = (unsigned int )tmp___8; while (_hj_k___0 >= 12U) { _hj_i___0 += (((unsigned int )*(_hj_key___0 + 0) + ((unsigned int )*(_hj_key___0 + 1) << 8)) + ((unsigned int )*(_hj_key___0 + 2) << 16)) + ((unsigned int )*(_hj_key___0 + 3) << 24); _hj_j___0 += (((unsigned int )*(_hj_key___0 + 4) + ((unsigned int )*(_hj_key___0 + 5) << 8)) + ((unsigned int )*(_hj_key___0 + 6) << 16)) + ((unsigned int )*(_hj_key___0 + 7) << 24); o->hh.hashv += (((unsigned int )*(_hj_key___0 + 8) + ((unsigned int )*(_hj_key___0 + 9) << 8)) + ((unsigned int )*(_hj_key___0 + 10) << 16)) + ((unsigned int )*(_hj_key___0 + 11) << 24); while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= o->hh.hashv; _hj_i___0 ^= o->hh.hashv >> 13; _hj_j___0 -= o->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; o->hh.hashv -= _hj_i___0; o->hh.hashv -= _hj_j___0; o->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= o->hh.hashv; _hj_i___0 ^= o->hh.hashv >> 12; _hj_j___0 -= o->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; o->hh.hashv -= _hj_i___0; o->hh.hashv -= _hj_j___0; o->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= o->hh.hashv; _hj_i___0 ^= o->hh.hashv >> 3; _hj_j___0 -= o->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; o->hh.hashv -= _hj_i___0; o->hh.hashv -= _hj_j___0; o->hh.hashv ^= _hj_j___0 >> 15; break; } _hj_key___0 += 12; _hj_k___0 -= 12U; } tmp___9 = strlen((char const *)o->field); o->hh.hashv = (unsigned int )((size_t )o->hh.hashv + tmp___9); switch (_hj_k___0) { case 11U: o->hh.hashv += (unsigned int )*(_hj_key___0 + 10) << 24; case 10U: o->hh.hashv += (unsigned int )*(_hj_key___0 + 9) << 16; case 9U: o->hh.hashv += (unsigned int )*(_hj_key___0 + 8) << 8; case 8U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 7) << 24; case 7U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 6) << 16; case 6U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 5) << 8; case 5U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 4); case 4U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 3) << 24; case 3U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 2) << 16; case 2U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 1) << 8; case 1U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 0); } while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= o->hh.hashv; _hj_i___0 ^= o->hh.hashv >> 13; _hj_j___0 -= o->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; o->hh.hashv -= _hj_i___0; o->hh.hashv -= _hj_j___0; o->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= o->hh.hashv; _hj_i___0 ^= o->hh.hashv >> 12; _hj_j___0 -= o->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; o->hh.hashv -= _hj_i___0; o->hh.hashv -= _hj_j___0; o->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= o->hh.hashv; _hj_i___0 ^= o->hh.hashv >> 3; _hj_j___0 -= o->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; o->hh.hashv -= _hj_i___0; o->hh.hashv -= _hj_j___0; o->hh.hashv ^= _hj_j___0 >> 15; break; } _ha_bkt = o->hh.hashv & ((objectHT->hh.tbl)->num_buckets - 1U); break; } while (1) { (((objectHT->hh.tbl)->buckets + _ha_bkt)->count) ++; o->hh.hh_next = ((objectHT->hh.tbl)->buckets + _ha_bkt)->hh_head; o->hh.hh_prev = (struct UT_hash_handle *)((void *)0); if (((objectHT->hh.tbl)->buckets + _ha_bkt)->hh_head) { (((objectHT->hh.tbl)->buckets + _ha_bkt)->hh_head)->hh_prev = & o->hh; } ((objectHT->hh.tbl)->buckets + _ha_bkt)->hh_head = & o->hh; if (((objectHT->hh.tbl)->buckets + _ha_bkt)->count >= (((objectHT->hh.tbl)->buckets + _ha_bkt)->expand_mult + 1U) * 10U) { if ((o->hh.tbl)->noexpand != 1U) { while (1) { tmp___10 = malloc((unsigned long )(2U * (o->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); _he_new_buckets = (UT_hash_bucket *)tmp___10; if (! _he_new_buckets) { exit(-1); } memset((void *)_he_new_buckets, 0, (unsigned long )(2U * (o->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); if ((o->hh.tbl)->num_items & ((o->hh.tbl)->num_buckets * 2U - 1U)) { tmp___11 = 1; } else { tmp___11 = 0; } (o->hh.tbl)->ideal_chain_maxlen = ((o->hh.tbl)->num_items >> ((o->hh.tbl)->log2_num_buckets + 1U)) + (unsigned int )tmp___11; (o->hh.tbl)->nonideal_items = 0U; _he_bkt_i = 0U; while (_he_bkt_i < (o->hh.tbl)->num_buckets) { _he_thh = ((o->hh.tbl)->buckets + _he_bkt_i)->hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; while (1) { _he_bkt = _he_thh->hashv & ((o->hh.tbl)->num_buckets * 2U - 1U); break; } _he_newbkt = _he_new_buckets + _he_bkt; (_he_newbkt->count) ++; if (_he_newbkt->count > (o->hh.tbl)->ideal_chain_maxlen) { ((o->hh.tbl)->nonideal_items) ++; _he_newbkt->expand_mult = _he_newbkt->count / (o->hh.tbl)->ideal_chain_maxlen; } _he_thh->hh_prev = (struct UT_hash_handle *)((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) { (_he_newbkt->hh_head)->hh_prev = _he_thh; } _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } _he_bkt_i ++; } free((void *)(o->hh.tbl)->buckets); (o->hh.tbl)->num_buckets *= 2U; ((o->hh.tbl)->log2_num_buckets) ++; (o->hh.tbl)->buckets = _he_new_buckets; if ((o->hh.tbl)->nonideal_items > (o->hh.tbl)->num_items >> 1) { ((o->hh.tbl)->ineff_expands) ++; } else { (o->hh.tbl)->ineff_expands = 0U; } if ((o->hh.tbl)->ineff_expands > 1U) { (o->hh.tbl)->noexpand = 1U; } break; } } } break; } break; } return; } } static ObjectHT *newObject(char *field , ObjectType type , void *value ) { ObjectHT *objectHT ; ObjectHT *t ; char baseName[12] ; char baseValue[12] ; unsigned int tmp ; char temp[12] ; void *tmp___0 ; size_t tmp___1 ; void *tmp___2 ; unsigned int _ha_bkt ; size_t tmp___3 ; void *tmp___4 ; void *tmp___5 ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; size_t tmp___6 ; size_t tmp___7 ; unsigned int _he_bkt ; unsigned int _he_bkt_i ; struct UT_hash_handle *_he_thh ; struct UT_hash_handle *_he_hh_nxt ; UT_hash_bucket *_he_new_buckets ; UT_hash_bucket *_he_newbkt ; void *tmp___8 ; int tmp___9 ; int tmp___10 ; size_t tmp___11 ; { objectHT = (ObjectHT *)((void *)0); baseName[0] = (char )'b'; baseName[1] = (char )'a'; baseName[2] = (char )'s'; baseName[3] = (char )'e'; baseName[4] = (char )'S'; baseName[5] = (char )'y'; baseName[6] = (char )'m'; baseName[7] = (char )'N'; baseName[8] = (char )'a'; baseName[9] = (char )'m'; baseName[10] = (char )'e'; baseName[11] = (char )'\000'; baseValue[0] = (char )'_'; baseValue[1] = (char )'\000'; tmp = 2U; while (! (tmp >= 12U)) { baseValue[tmp] = (char)0; tmp ++; } tmp___0 = malloc(sizeof(ObjectHT )); t = (ObjectHT *)tmp___0; tmp___1 = strlen((char const *)(baseName)); tmp___2 = malloc(sizeof(char ) * (tmp___1 + 1UL)); t->field = (char *)tmp___2; strcpy((char * __restrict )t->field, (char const * __restrict )(baseName)); while (1) { t->hh.next = (void *)0; t->hh.key = (void *)(t->field + 0); tmp___3 = strlen((char const *)t->field); t->hh.keylen = (unsigned int )tmp___3; if (! objectHT) { objectHT = t; objectHT->hh.prev = (void *)0; while (1) { tmp___4 = malloc(sizeof(UT_hash_table )); objectHT->hh.tbl = (UT_hash_table *)tmp___4; if (! objectHT->hh.tbl) { exit(-1); } memset((void *)objectHT->hh.tbl, 0, sizeof(UT_hash_table )); (objectHT->hh.tbl)->tail = & objectHT->hh; (objectHT->hh.tbl)->num_buckets = 32U; (objectHT->hh.tbl)->log2_num_buckets = 5U; (objectHT->hh.tbl)->hho = (char *)(& objectHT->hh) - (char *)objectHT; tmp___5 = malloc(32UL * sizeof(struct UT_hash_bucket )); (objectHT->hh.tbl)->buckets = (UT_hash_bucket *)tmp___5; if (! (objectHT->hh.tbl)->buckets) { exit(-1); } memset((void *)(objectHT->hh.tbl)->buckets, 0, 32UL * sizeof(struct UT_hash_bucket )); (objectHT->hh.tbl)->signature = 2685476833U; break; } } else { ((objectHT->hh.tbl)->tail)->next = (void *)t; t->hh.prev = (void *)((char *)(objectHT->hh.tbl)->tail - (objectHT->hh.tbl)->hho); (objectHT->hh.tbl)->tail = & t->hh; } ((objectHT->hh.tbl)->num_items) ++; t->hh.tbl = objectHT->hh.tbl; while (1) { _hj_key = (unsigned char *)(t->field + 0); t->hh.hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; tmp___6 = strlen((char const *)t->field); _hj_k = (unsigned int )tmp___6; while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); t->hh.hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= t->hh.hashv; _hj_i ^= t->hh.hashv >> 13; _hj_j -= t->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; t->hh.hashv -= _hj_i; t->hh.hashv -= _hj_j; t->hh.hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= t->hh.hashv; _hj_i ^= t->hh.hashv >> 12; _hj_j -= t->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; t->hh.hashv -= _hj_i; t->hh.hashv -= _hj_j; t->hh.hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= t->hh.hashv; _hj_i ^= t->hh.hashv >> 3; _hj_j -= t->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; t->hh.hashv -= _hj_i; t->hh.hashv -= _hj_j; t->hh.hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } tmp___7 = strlen((char const *)t->field); t->hh.hashv = (unsigned int )((size_t )t->hh.hashv + tmp___7); switch (_hj_k) { case 11U: t->hh.hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: t->hh.hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: t->hh.hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= t->hh.hashv; _hj_i ^= t->hh.hashv >> 13; _hj_j -= t->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; t->hh.hashv -= _hj_i; t->hh.hashv -= _hj_j; t->hh.hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= t->hh.hashv; _hj_i ^= t->hh.hashv >> 12; _hj_j -= t->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; t->hh.hashv -= _hj_i; t->hh.hashv -= _hj_j; t->hh.hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= t->hh.hashv; _hj_i ^= t->hh.hashv >> 3; _hj_j -= t->hh.hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; t->hh.hashv -= _hj_i; t->hh.hashv -= _hj_j; t->hh.hashv ^= _hj_j >> 15; break; } _ha_bkt = t->hh.hashv & ((objectHT->hh.tbl)->num_buckets - 1U); break; } while (1) { (((objectHT->hh.tbl)->buckets + _ha_bkt)->count) ++; t->hh.hh_next = ((objectHT->hh.tbl)->buckets + _ha_bkt)->hh_head; t->hh.hh_prev = (struct UT_hash_handle *)((void *)0); if (((objectHT->hh.tbl)->buckets + _ha_bkt)->hh_head) { (((objectHT->hh.tbl)->buckets + _ha_bkt)->hh_head)->hh_prev = & t->hh; } ((objectHT->hh.tbl)->buckets + _ha_bkt)->hh_head = & t->hh; if (((objectHT->hh.tbl)->buckets + _ha_bkt)->count >= (((objectHT->hh.tbl)->buckets + _ha_bkt)->expand_mult + 1U) * 10U) { if ((t->hh.tbl)->noexpand != 1U) { while (1) { tmp___8 = malloc((unsigned long )(2U * (t->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); _he_new_buckets = (UT_hash_bucket *)tmp___8; if (! _he_new_buckets) { exit(-1); } memset((void *)_he_new_buckets, 0, (unsigned long )(2U * (t->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); if ((t->hh.tbl)->num_items & ((t->hh.tbl)->num_buckets * 2U - 1U)) { tmp___9 = 1; } else { tmp___9 = 0; } (t->hh.tbl)->ideal_chain_maxlen = ((t->hh.tbl)->num_items >> ((t->hh.tbl)->log2_num_buckets + 1U)) + (unsigned int )tmp___9; (t->hh.tbl)->nonideal_items = 0U; _he_bkt_i = 0U; while (_he_bkt_i < (t->hh.tbl)->num_buckets) { _he_thh = ((t->hh.tbl)->buckets + _he_bkt_i)->hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; while (1) { _he_bkt = _he_thh->hashv & ((t->hh.tbl)->num_buckets * 2U - 1U); break; } _he_newbkt = _he_new_buckets + _he_bkt; (_he_newbkt->count) ++; if (_he_newbkt->count > (t->hh.tbl)->ideal_chain_maxlen) { ((t->hh.tbl)->nonideal_items) ++; _he_newbkt->expand_mult = _he_newbkt->count / (t->hh.tbl)->ideal_chain_maxlen; } _he_thh->hh_prev = (struct UT_hash_handle *)((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) { (_he_newbkt->hh_head)->hh_prev = _he_thh; } _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } _he_bkt_i ++; } free((void *)(t->hh.tbl)->buckets); (t->hh.tbl)->num_buckets *= 2U; ((t->hh.tbl)->log2_num_buckets) ++; (t->hh.tbl)->buckets = _he_new_buckets; if ((t->hh.tbl)->nonideal_items > (t->hh.tbl)->num_items >> 1) { ((t->hh.tbl)->ineff_expands) ++; } else { (t->hh.tbl)->ineff_expands = 0U; } if ((t->hh.tbl)->ineff_expands > 1U) { (t->hh.tbl)->noexpand = 1U; } break; } } } break; } break; } tmp___10 = toInt___1((void *)objectHT); sprintf((char * __restrict )(temp), (char const * __restrict )"%d", tmp___10); strcat((char * __restrict )(baseValue), (char const * __restrict )(temp)); tmp___11 = strlen((char const *)(baseValue)); t->val = malloc((tmp___11 + 1UL) * sizeof(char )); strcpy((char * __restrict )t->val, (char const * __restrict )(baseValue)); return (objectHT); } } void *load(void *addr , char *field , int t ) { MainHT *m ; ObjectHT *o ; ObjectType type ; int x ; int tmp ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp___0 ; unsigned int _hf_bkt___0 ; unsigned int _hf_hashv___0 ; unsigned int _hj_i___0 ; unsigned int _hj_j___0 ; unsigned int _hj_k___0 ; unsigned char *_hj_key___0 ; int tmp___1 ; unsigned int _hf_bkt___1 ; unsigned int _hf_hashv___1 ; unsigned int _hj_i___1 ; unsigned int _hj_j___1 ; unsigned int _hj_k___1 ; unsigned char *_hj_key___1 ; size_t tmp___2 ; size_t tmp___3 ; size_t tmp___4 ; int tmp___5 ; size_t tmp___6 ; { type = getObjectType(t); tmp = toInt___1(addr); x = tmp; while (1) { m = (MainHT *)((void *)0); if (mainHT) { while (1) { _hj_key = (unsigned char *)(& x); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((mainHT->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((mainHT->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { m = (MainHT *)((void *)((char *)((mainHT->hh.tbl)->buckets + _hf_bkt)->hh_head - (mainHT->hh.tbl)->hho)); break; } } else { m = (MainHT *)((void *)0); } while (m) { if ((unsigned long )m->hh.keylen == sizeof(int )) { tmp___0 = memcmp((void const *)m->hh.key, (void const *)(& x), sizeof(int )); if (tmp___0 == 0) { break; } } if (m->hh.hh_next) { while (1) { m = (MainHT *)((void *)((char *)m->hh.hh_next - (mainHT->hh.tbl)->hho)); break; } } else { m = (MainHT *)((void *)0); } } break; } } break; } if ((unsigned long )((void *)0) == (unsigned long )m) { store(addr, field, (int )type, (void *)field, (char *)""); while (1) { m = (MainHT *)((void *)0); if (mainHT) { while (1) { _hj_key___0 = (unsigned char *)(& x); _hf_hashv___0 = 4276993775U; _hj_j___0 = 2654435769U; _hj_i___0 = _hj_j___0; _hj_k___0 = (unsigned int )sizeof(int ); while (_hj_k___0 >= 12U) { _hj_i___0 += (((unsigned int )*(_hj_key___0 + 0) + ((unsigned int )*(_hj_key___0 + 1) << 8)) + ((unsigned int )*(_hj_key___0 + 2) << 16)) + ((unsigned int )*(_hj_key___0 + 3) << 24); _hj_j___0 += (((unsigned int )*(_hj_key___0 + 4) + ((unsigned int )*(_hj_key___0 + 5) << 8)) + ((unsigned int )*(_hj_key___0 + 6) << 16)) + ((unsigned int )*(_hj_key___0 + 7) << 24); _hf_hashv___0 += (((unsigned int )*(_hj_key___0 + 8) + ((unsigned int )*(_hj_key___0 + 9) << 8)) + ((unsigned int )*(_hj_key___0 + 10) << 16)) + ((unsigned int )*(_hj_key___0 + 11) << 24); while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= _hf_hashv___0; _hj_i___0 ^= _hf_hashv___0 >> 13; _hj_j___0 -= _hf_hashv___0; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; _hf_hashv___0 -= _hj_i___0; _hf_hashv___0 -= _hj_j___0; _hf_hashv___0 ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= _hf_hashv___0; _hj_i___0 ^= _hf_hashv___0 >> 12; _hj_j___0 -= _hf_hashv___0; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; _hf_hashv___0 -= _hj_i___0; _hf_hashv___0 -= _hj_j___0; _hf_hashv___0 ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= _hf_hashv___0; _hj_i___0 ^= _hf_hashv___0 >> 3; _hj_j___0 -= _hf_hashv___0; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; _hf_hashv___0 -= _hj_i___0; _hf_hashv___0 -= _hj_j___0; _hf_hashv___0 ^= _hj_j___0 >> 15; break; } _hj_key___0 += 12; _hj_k___0 -= 12U; } _hf_hashv___0 = (unsigned int )((unsigned long )_hf_hashv___0 + sizeof(int )); switch (_hj_k___0) { case 11U: _hf_hashv___0 += (unsigned int )*(_hj_key___0 + 10) << 24; case 10U: _hf_hashv___0 += (unsigned int )*(_hj_key___0 + 9) << 16; case 9U: _hf_hashv___0 += (unsigned int )*(_hj_key___0 + 8) << 8; case 8U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 7) << 24; case 7U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 6) << 16; case 6U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 5) << 8; case 5U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 4); case 4U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 3) << 24; case 3U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 2) << 16; case 2U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 1) << 8; case 1U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 0); } while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= _hf_hashv___0; _hj_i___0 ^= _hf_hashv___0 >> 13; _hj_j___0 -= _hf_hashv___0; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; _hf_hashv___0 -= _hj_i___0; _hf_hashv___0 -= _hj_j___0; _hf_hashv___0 ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= _hf_hashv___0; _hj_i___0 ^= _hf_hashv___0 >> 12; _hj_j___0 -= _hf_hashv___0; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; _hf_hashv___0 -= _hj_i___0; _hf_hashv___0 -= _hj_j___0; _hf_hashv___0 ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= _hf_hashv___0; _hj_i___0 ^= _hf_hashv___0 >> 3; _hj_j___0 -= _hf_hashv___0; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; _hf_hashv___0 -= _hj_i___0; _hf_hashv___0 -= _hj_j___0; _hf_hashv___0 ^= _hj_j___0 >> 15; break; } _hf_bkt___0 = _hf_hashv___0 & ((mainHT->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((mainHT->hh.tbl)->buckets + _hf_bkt___0)->hh_head) { while (1) { m = (MainHT *)((void *)((char *)((mainHT->hh.tbl)->buckets + _hf_bkt___0)->hh_head - (mainHT->hh.tbl)->hho)); break; } } else { m = (MainHT *)((void *)0); } while (m) { if ((unsigned long )m->hh.keylen == sizeof(int )) { tmp___1 = memcmp((void const *)m->hh.key, (void const *)(& x), sizeof(int )); if (tmp___1 == 0) { break; } } if (m->hh.hh_next) { while (1) { m = (MainHT *)((void *)((char *)m->hh.hh_next - (mainHT->hh.tbl)->hho)); break; } } else { m = (MainHT *)((void *)0); } } break; } } break; } } while (1) { o = (ObjectHT *)((void *)0); if (m->val) { while (1) { _hj_key___1 = (unsigned char *)field; _hf_hashv___1 = 4276993775U; _hj_j___1 = 2654435769U; _hj_i___1 = _hj_j___1; tmp___2 = strlen((char const *)field); _hj_k___1 = (unsigned int )tmp___2; while (_hj_k___1 >= 12U) { _hj_i___1 += (((unsigned int )*(_hj_key___1 + 0) + ((unsigned int )*(_hj_key___1 + 1) << 8)) + ((unsigned int )*(_hj_key___1 + 2) << 16)) + ((unsigned int )*(_hj_key___1 + 3) << 24); _hj_j___1 += (((unsigned int )*(_hj_key___1 + 4) + ((unsigned int )*(_hj_key___1 + 5) << 8)) + ((unsigned int )*(_hj_key___1 + 6) << 16)) + ((unsigned int )*(_hj_key___1 + 7) << 24); _hf_hashv___1 += (((unsigned int )*(_hj_key___1 + 8) + ((unsigned int )*(_hj_key___1 + 9) << 8)) + ((unsigned int )*(_hj_key___1 + 10) << 16)) + ((unsigned int )*(_hj_key___1 + 11) << 24); while (1) { _hj_i___1 -= _hj_j___1; _hj_i___1 -= _hf_hashv___1; _hj_i___1 ^= _hf_hashv___1 >> 13; _hj_j___1 -= _hf_hashv___1; _hj_j___1 -= _hj_i___1; _hj_j___1 ^= _hj_i___1 << 8; _hf_hashv___1 -= _hj_i___1; _hf_hashv___1 -= _hj_j___1; _hf_hashv___1 ^= _hj_j___1 >> 13; _hj_i___1 -= _hj_j___1; _hj_i___1 -= _hf_hashv___1; _hj_i___1 ^= _hf_hashv___1 >> 12; _hj_j___1 -= _hf_hashv___1; _hj_j___1 -= _hj_i___1; _hj_j___1 ^= _hj_i___1 << 16; _hf_hashv___1 -= _hj_i___1; _hf_hashv___1 -= _hj_j___1; _hf_hashv___1 ^= _hj_j___1 >> 5; _hj_i___1 -= _hj_j___1; _hj_i___1 -= _hf_hashv___1; _hj_i___1 ^= _hf_hashv___1 >> 3; _hj_j___1 -= _hf_hashv___1; _hj_j___1 -= _hj_i___1; _hj_j___1 ^= _hj_i___1 << 10; _hf_hashv___1 -= _hj_i___1; _hf_hashv___1 -= _hj_j___1; _hf_hashv___1 ^= _hj_j___1 >> 15; break; } _hj_key___1 += 12; _hj_k___1 -= 12U; } tmp___3 = strlen((char const *)field); _hf_hashv___1 = (unsigned int )((size_t )_hf_hashv___1 + tmp___3); switch (_hj_k___1) { case 11U: _hf_hashv___1 += (unsigned int )*(_hj_key___1 + 10) << 24; case 10U: _hf_hashv___1 += (unsigned int )*(_hj_key___1 + 9) << 16; case 9U: _hf_hashv___1 += (unsigned int )*(_hj_key___1 + 8) << 8; case 8U: _hj_j___1 += (unsigned int )*(_hj_key___1 + 7) << 24; case 7U: _hj_j___1 += (unsigned int )*(_hj_key___1 + 6) << 16; case 6U: _hj_j___1 += (unsigned int )*(_hj_key___1 + 5) << 8; case 5U: _hj_j___1 += (unsigned int )*(_hj_key___1 + 4); case 4U: _hj_i___1 += (unsigned int )*(_hj_key___1 + 3) << 24; case 3U: _hj_i___1 += (unsigned int )*(_hj_key___1 + 2) << 16; case 2U: _hj_i___1 += (unsigned int )*(_hj_key___1 + 1) << 8; case 1U: _hj_i___1 += (unsigned int )*(_hj_key___1 + 0); } while (1) { _hj_i___1 -= _hj_j___1; _hj_i___1 -= _hf_hashv___1; _hj_i___1 ^= _hf_hashv___1 >> 13; _hj_j___1 -= _hf_hashv___1; _hj_j___1 -= _hj_i___1; _hj_j___1 ^= _hj_i___1 << 8; _hf_hashv___1 -= _hj_i___1; _hf_hashv___1 -= _hj_j___1; _hf_hashv___1 ^= _hj_j___1 >> 13; _hj_i___1 -= _hj_j___1; _hj_i___1 -= _hf_hashv___1; _hj_i___1 ^= _hf_hashv___1 >> 12; _hj_j___1 -= _hf_hashv___1; _hj_j___1 -= _hj_i___1; _hj_j___1 ^= _hj_i___1 << 16; _hf_hashv___1 -= _hj_i___1; _hf_hashv___1 -= _hj_j___1; _hf_hashv___1 ^= _hj_j___1 >> 5; _hj_i___1 -= _hj_j___1; _hj_i___1 -= _hf_hashv___1; _hj_i___1 ^= _hf_hashv___1 >> 3; _hj_j___1 -= _hf_hashv___1; _hj_j___1 -= _hj_i___1; _hj_j___1 ^= _hj_i___1 << 10; _hf_hashv___1 -= _hj_i___1; _hf_hashv___1 -= _hj_j___1; _hf_hashv___1 ^= _hj_j___1 >> 15; break; } _hf_bkt___1 = _hf_hashv___1 & (((m->val)->hh.tbl)->num_buckets - 1U); break; } while (1) { if ((((m->val)->hh.tbl)->buckets + _hf_bkt___1)->hh_head) { while (1) { o = (ObjectHT *)((void *)((char *)(((m->val)->hh.tbl)->buckets + _hf_bkt___1)->hh_head - ((m->val)->hh.tbl)->hho)); break; } } else { o = (ObjectHT *)((void *)0); } while (o) { tmp___6 = strlen((char const *)field); if ((size_t )o->hh.keylen == tmp___6) { tmp___4 = strlen((char const *)field); tmp___5 = memcmp((void const *)o->hh.key, (void const *)field, tmp___4); if (tmp___5 == 0) { break; } } if (o->hh.hh_next) { while (1) { o = (ObjectHT *)((void *)((char *)o->hh.hh_next - ((m->val)->hh.tbl)->hho)); break; } } else { o = (ObjectHT *)((void *)0); } } break; } } break; } if (! ((unsigned long )((void *)0) != (unsigned long )o)) { __assert_fail("((void *)0) != o", "src/src/flatds.c", 123U, "load"); } return (o->val); } } void store(void *addr , char *lField , int t , void *value , char *sname ) { MainHT *m ; ObjectType type ; int lKey ; int tmp ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp___0 ; void *tmp___1 ; unsigned int _ha_bkt ; void *tmp___2 ; void *tmp___3 ; unsigned int _hj_i___0 ; unsigned int _hj_j___0 ; unsigned int _hj_k___0 ; unsigned char *_hj_key___0 ; unsigned int _he_bkt ; unsigned int _he_bkt_i ; struct UT_hash_handle *_he_thh ; struct UT_hash_handle *_he_hh_nxt ; UT_hash_bucket *_he_new_buckets ; UT_hash_bucket *_he_newbkt ; void *tmp___4 ; int tmp___5 ; { type = getObjectType(t); tmp = toInt___1(addr); lKey = tmp; while (1) { m = (MainHT *)((void *)0); if (mainHT) { while (1) { _hj_key = (unsigned char *)(& lKey); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((mainHT->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((mainHT->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { m = (MainHT *)((void *)((char *)((mainHT->hh.tbl)->buckets + _hf_bkt)->hh_head - (mainHT->hh.tbl)->hho)); break; } } else { m = (MainHT *)((void *)0); } while (m) { if ((unsigned long )m->hh.keylen == sizeof(int )) { tmp___0 = memcmp((void const *)m->hh.key, (void const *)(& lKey), sizeof(int )); if (tmp___0 == 0) { break; } } if (m->hh.hh_next) { while (1) { m = (MainHT *)((void *)((char *)m->hh.hh_next - (mainHT->hh.tbl)->hho)); break; } } else { m = (MainHT *)((void *)0); } } break; } } break; } if ((unsigned long )((void *)0) == (unsigned long )m) { tmp___1 = malloc(sizeof(MainHT )); m = (MainHT *)tmp___1; m->key = lKey; m->val = newObject(lField, type, value); while (1) { m->hh.next = (void *)0; m->hh.key = (void *)((char *)(& m->key)); m->hh.keylen = (unsigned int )sizeof(int ); if (! mainHT) { mainHT = m; mainHT->hh.prev = (void *)0; while (1) { tmp___2 = malloc(sizeof(UT_hash_table )); mainHT->hh.tbl = (UT_hash_table *)tmp___2; if (! mainHT->hh.tbl) { exit(-1); } memset((void *)mainHT->hh.tbl, 0, sizeof(UT_hash_table )); (mainHT->hh.tbl)->tail = & mainHT->hh; (mainHT->hh.tbl)->num_buckets = 32U; (mainHT->hh.tbl)->log2_num_buckets = 5U; (mainHT->hh.tbl)->hho = (char *)(& mainHT->hh) - (char *)mainHT; tmp___3 = malloc(32UL * sizeof(struct UT_hash_bucket )); (mainHT->hh.tbl)->buckets = (UT_hash_bucket *)tmp___3; if (! (mainHT->hh.tbl)->buckets) { exit(-1); } memset((void *)(mainHT->hh.tbl)->buckets, 0, 32UL * sizeof(struct UT_hash_bucket )); (mainHT->hh.tbl)->signature = 2685476833U; break; } } else { ((mainHT->hh.tbl)->tail)->next = (void *)m; m->hh.prev = (void *)((char *)(mainHT->hh.tbl)->tail - (mainHT->hh.tbl)->hho); (mainHT->hh.tbl)->tail = & m->hh; } ((mainHT->hh.tbl)->num_items) ++; m->hh.tbl = mainHT->hh.tbl; while (1) { _hj_key___0 = (unsigned char *)(& m->key); m->hh.hashv = 4276993775U; _hj_j___0 = 2654435769U; _hj_i___0 = _hj_j___0; _hj_k___0 = (unsigned int )sizeof(int ); while (_hj_k___0 >= 12U) { _hj_i___0 += (((unsigned int )*(_hj_key___0 + 0) + ((unsigned int )*(_hj_key___0 + 1) << 8)) + ((unsigned int )*(_hj_key___0 + 2) << 16)) + ((unsigned int )*(_hj_key___0 + 3) << 24); _hj_j___0 += (((unsigned int )*(_hj_key___0 + 4) + ((unsigned int )*(_hj_key___0 + 5) << 8)) + ((unsigned int )*(_hj_key___0 + 6) << 16)) + ((unsigned int )*(_hj_key___0 + 7) << 24); m->hh.hashv += (((unsigned int )*(_hj_key___0 + 8) + ((unsigned int )*(_hj_key___0 + 9) << 8)) + ((unsigned int )*(_hj_key___0 + 10) << 16)) + ((unsigned int )*(_hj_key___0 + 11) << 24); while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= m->hh.hashv; _hj_i___0 ^= m->hh.hashv >> 13; _hj_j___0 -= m->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; m->hh.hashv -= _hj_i___0; m->hh.hashv -= _hj_j___0; m->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= m->hh.hashv; _hj_i___0 ^= m->hh.hashv >> 12; _hj_j___0 -= m->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; m->hh.hashv -= _hj_i___0; m->hh.hashv -= _hj_j___0; m->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= m->hh.hashv; _hj_i___0 ^= m->hh.hashv >> 3; _hj_j___0 -= m->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; m->hh.hashv -= _hj_i___0; m->hh.hashv -= _hj_j___0; m->hh.hashv ^= _hj_j___0 >> 15; break; } _hj_key___0 += 12; _hj_k___0 -= 12U; } m->hh.hashv = (unsigned int )((unsigned long )m->hh.hashv + sizeof(int )); switch (_hj_k___0) { case 11U: m->hh.hashv += (unsigned int )*(_hj_key___0 + 10) << 24; case 10U: m->hh.hashv += (unsigned int )*(_hj_key___0 + 9) << 16; case 9U: m->hh.hashv += (unsigned int )*(_hj_key___0 + 8) << 8; case 8U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 7) << 24; case 7U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 6) << 16; case 6U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 5) << 8; case 5U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 4); case 4U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 3) << 24; case 3U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 2) << 16; case 2U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 1) << 8; case 1U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 0); } while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= m->hh.hashv; _hj_i___0 ^= m->hh.hashv >> 13; _hj_j___0 -= m->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; m->hh.hashv -= _hj_i___0; m->hh.hashv -= _hj_j___0; m->hh.hashv ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= m->hh.hashv; _hj_i___0 ^= m->hh.hashv >> 12; _hj_j___0 -= m->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; m->hh.hashv -= _hj_i___0; m->hh.hashv -= _hj_j___0; m->hh.hashv ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= m->hh.hashv; _hj_i___0 ^= m->hh.hashv >> 3; _hj_j___0 -= m->hh.hashv; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; m->hh.hashv -= _hj_i___0; m->hh.hashv -= _hj_j___0; m->hh.hashv ^= _hj_j___0 >> 15; break; } _ha_bkt = m->hh.hashv & ((mainHT->hh.tbl)->num_buckets - 1U); break; } while (1) { (((mainHT->hh.tbl)->buckets + _ha_bkt)->count) ++; m->hh.hh_next = ((mainHT->hh.tbl)->buckets + _ha_bkt)->hh_head; m->hh.hh_prev = (struct UT_hash_handle *)((void *)0); if (((mainHT->hh.tbl)->buckets + _ha_bkt)->hh_head) { (((mainHT->hh.tbl)->buckets + _ha_bkt)->hh_head)->hh_prev = & m->hh; } ((mainHT->hh.tbl)->buckets + _ha_bkt)->hh_head = & m->hh; if (((mainHT->hh.tbl)->buckets + _ha_bkt)->count >= (((mainHT->hh.tbl)->buckets + _ha_bkt)->expand_mult + 1U) * 10U) { if ((m->hh.tbl)->noexpand != 1U) { while (1) { tmp___4 = malloc((unsigned long )(2U * (m->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); _he_new_buckets = (UT_hash_bucket *)tmp___4; if (! _he_new_buckets) { exit(-1); } memset((void *)_he_new_buckets, 0, (unsigned long )(2U * (m->hh.tbl)->num_buckets) * sizeof(struct UT_hash_bucket )); if ((m->hh.tbl)->num_items & ((m->hh.tbl)->num_buckets * 2U - 1U)) { tmp___5 = 1; } else { tmp___5 = 0; } (m->hh.tbl)->ideal_chain_maxlen = ((m->hh.tbl)->num_items >> ((m->hh.tbl)->log2_num_buckets + 1U)) + (unsigned int )tmp___5; (m->hh.tbl)->nonideal_items = 0U; _he_bkt_i = 0U; while (_he_bkt_i < (m->hh.tbl)->num_buckets) { _he_thh = ((m->hh.tbl)->buckets + _he_bkt_i)->hh_head; while (_he_thh) { _he_hh_nxt = _he_thh->hh_next; while (1) { _he_bkt = _he_thh->hashv & ((m->hh.tbl)->num_buckets * 2U - 1U); break; } _he_newbkt = _he_new_buckets + _he_bkt; (_he_newbkt->count) ++; if (_he_newbkt->count > (m->hh.tbl)->ideal_chain_maxlen) { ((m->hh.tbl)->nonideal_items) ++; _he_newbkt->expand_mult = _he_newbkt->count / (m->hh.tbl)->ideal_chain_maxlen; } _he_thh->hh_prev = (struct UT_hash_handle *)((void *)0); _he_thh->hh_next = _he_newbkt->hh_head; if (_he_newbkt->hh_head) { (_he_newbkt->hh_head)->hh_prev = _he_thh; } _he_newbkt->hh_head = _he_thh; _he_thh = _he_hh_nxt; } _he_bkt_i ++; } free((void *)(m->hh.tbl)->buckets); (m->hh.tbl)->num_buckets *= 2U; ((m->hh.tbl)->log2_num_buckets) ++; (m->hh.tbl)->buckets = _he_new_buckets; if ((m->hh.tbl)->nonideal_items > (m->hh.tbl)->num_items >> 1) { ((m->hh.tbl)->ineff_expands) ++; } else { (m->hh.tbl)->ineff_expands = 0U; } if ((m->hh.tbl)->ineff_expands > 1U) { (m->hh.tbl)->noexpand = 1U; } break; } } } break; } break; } } addField(m->val, lField, type, value, sname); return; } } char *getSymName(void *addr , char *field ) { MainHT *m ; ObjectHT *o ; int x ; int tmp ; unsigned int _hf_bkt ; unsigned int _hf_hashv ; unsigned int _hj_i ; unsigned int _hj_j ; unsigned int _hj_k ; unsigned char *_hj_key ; int tmp___0 ; unsigned int _hf_bkt___0 ; unsigned int _hf_hashv___0 ; unsigned int _hj_i___0 ; unsigned int _hj_j___0 ; unsigned int _hj_k___0 ; unsigned char *_hj_key___0 ; size_t tmp___1 ; size_t tmp___2 ; size_t tmp___3 ; int tmp___4 ; size_t tmp___5 ; { tmp = toInt___1(addr); x = tmp; while (1) { m = (MainHT *)((void *)0); if (mainHT) { while (1) { _hj_key = (unsigned char *)(& x); _hf_hashv = 4276993775U; _hj_j = 2654435769U; _hj_i = _hj_j; _hj_k = (unsigned int )sizeof(int ); while (_hj_k >= 12U) { _hj_i += (((unsigned int )*(_hj_key + 0) + ((unsigned int )*(_hj_key + 1) << 8)) + ((unsigned int )*(_hj_key + 2) << 16)) + ((unsigned int )*(_hj_key + 3) << 24); _hj_j += (((unsigned int )*(_hj_key + 4) + ((unsigned int )*(_hj_key + 5) << 8)) + ((unsigned int )*(_hj_key + 6) << 16)) + ((unsigned int )*(_hj_key + 7) << 24); _hf_hashv += (((unsigned int )*(_hj_key + 8) + ((unsigned int )*(_hj_key + 9) << 8)) + ((unsigned int )*(_hj_key + 10) << 16)) + ((unsigned int )*(_hj_key + 11) << 24); while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hj_key += 12; _hj_k -= 12U; } _hf_hashv = (unsigned int )((unsigned long )_hf_hashv + sizeof(int )); switch (_hj_k) { case 11U: _hf_hashv += (unsigned int )*(_hj_key + 10) << 24; case 10U: _hf_hashv += (unsigned int )*(_hj_key + 9) << 16; case 9U: _hf_hashv += (unsigned int )*(_hj_key + 8) << 8; case 8U: _hj_j += (unsigned int )*(_hj_key + 7) << 24; case 7U: _hj_j += (unsigned int )*(_hj_key + 6) << 16; case 6U: _hj_j += (unsigned int )*(_hj_key + 5) << 8; case 5U: _hj_j += (unsigned int )*(_hj_key + 4); case 4U: _hj_i += (unsigned int )*(_hj_key + 3) << 24; case 3U: _hj_i += (unsigned int )*(_hj_key + 2) << 16; case 2U: _hj_i += (unsigned int )*(_hj_key + 1) << 8; case 1U: _hj_i += (unsigned int )*(_hj_key + 0); } while (1) { _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 13; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 8; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 13; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 12; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 16; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 5; _hj_i -= _hj_j; _hj_i -= _hf_hashv; _hj_i ^= _hf_hashv >> 3; _hj_j -= _hf_hashv; _hj_j -= _hj_i; _hj_j ^= _hj_i << 10; _hf_hashv -= _hj_i; _hf_hashv -= _hj_j; _hf_hashv ^= _hj_j >> 15; break; } _hf_bkt = _hf_hashv & ((mainHT->hh.tbl)->num_buckets - 1U); break; } while (1) { if (((mainHT->hh.tbl)->buckets + _hf_bkt)->hh_head) { while (1) { m = (MainHT *)((void *)((char *)((mainHT->hh.tbl)->buckets + _hf_bkt)->hh_head - (mainHT->hh.tbl)->hho)); break; } } else { m = (MainHT *)((void *)0); } while (m) { if ((unsigned long )m->hh.keylen == sizeof(int )) { tmp___0 = memcmp((void const *)m->hh.key, (void const *)(& x), sizeof(int )); if (tmp___0 == 0) { break; } } if (m->hh.hh_next) { while (1) { m = (MainHT *)((void *)((char *)m->hh.hh_next - (mainHT->hh.tbl)->hho)); break; } } else { m = (MainHT *)((void *)0); } } break; } } break; } while (1) { o = (ObjectHT *)((void *)0); if (m->val) { while (1) { _hj_key___0 = (unsigned char *)field; _hf_hashv___0 = 4276993775U; _hj_j___0 = 2654435769U; _hj_i___0 = _hj_j___0; tmp___1 = strlen((char const *)field); _hj_k___0 = (unsigned int )tmp___1; while (_hj_k___0 >= 12U) { _hj_i___0 += (((unsigned int )*(_hj_key___0 + 0) + ((unsigned int )*(_hj_key___0 + 1) << 8)) + ((unsigned int )*(_hj_key___0 + 2) << 16)) + ((unsigned int )*(_hj_key___0 + 3) << 24); _hj_j___0 += (((unsigned int )*(_hj_key___0 + 4) + ((unsigned int )*(_hj_key___0 + 5) << 8)) + ((unsigned int )*(_hj_key___0 + 6) << 16)) + ((unsigned int )*(_hj_key___0 + 7) << 24); _hf_hashv___0 += (((unsigned int )*(_hj_key___0 + 8) + ((unsigned int )*(_hj_key___0 + 9) << 8)) + ((unsigned int )*(_hj_key___0 + 10) << 16)) + ((unsigned int )*(_hj_key___0 + 11) << 24); while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= _hf_hashv___0; _hj_i___0 ^= _hf_hashv___0 >> 13; _hj_j___0 -= _hf_hashv___0; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; _hf_hashv___0 -= _hj_i___0; _hf_hashv___0 -= _hj_j___0; _hf_hashv___0 ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= _hf_hashv___0; _hj_i___0 ^= _hf_hashv___0 >> 12; _hj_j___0 -= _hf_hashv___0; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; _hf_hashv___0 -= _hj_i___0; _hf_hashv___0 -= _hj_j___0; _hf_hashv___0 ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= _hf_hashv___0; _hj_i___0 ^= _hf_hashv___0 >> 3; _hj_j___0 -= _hf_hashv___0; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; _hf_hashv___0 -= _hj_i___0; _hf_hashv___0 -= _hj_j___0; _hf_hashv___0 ^= _hj_j___0 >> 15; break; } _hj_key___0 += 12; _hj_k___0 -= 12U; } tmp___2 = strlen((char const *)field); _hf_hashv___0 = (unsigned int )((size_t )_hf_hashv___0 + tmp___2); switch (_hj_k___0) { case 11U: _hf_hashv___0 += (unsigned int )*(_hj_key___0 + 10) << 24; case 10U: _hf_hashv___0 += (unsigned int )*(_hj_key___0 + 9) << 16; case 9U: _hf_hashv___0 += (unsigned int )*(_hj_key___0 + 8) << 8; case 8U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 7) << 24; case 7U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 6) << 16; case 6U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 5) << 8; case 5U: _hj_j___0 += (unsigned int )*(_hj_key___0 + 4); case 4U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 3) << 24; case 3U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 2) << 16; case 2U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 1) << 8; case 1U: _hj_i___0 += (unsigned int )*(_hj_key___0 + 0); } while (1) { _hj_i___0 -= _hj_j___0; _hj_i___0 -= _hf_hashv___0; _hj_i___0 ^= _hf_hashv___0 >> 13; _hj_j___0 -= _hf_hashv___0; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 8; _hf_hashv___0 -= _hj_i___0; _hf_hashv___0 -= _hj_j___0; _hf_hashv___0 ^= _hj_j___0 >> 13; _hj_i___0 -= _hj_j___0; _hj_i___0 -= _hf_hashv___0; _hj_i___0 ^= _hf_hashv___0 >> 12; _hj_j___0 -= _hf_hashv___0; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 16; _hf_hashv___0 -= _hj_i___0; _hf_hashv___0 -= _hj_j___0; _hf_hashv___0 ^= _hj_j___0 >> 5; _hj_i___0 -= _hj_j___0; _hj_i___0 -= _hf_hashv___0; _hj_i___0 ^= _hf_hashv___0 >> 3; _hj_j___0 -= _hf_hashv___0; _hj_j___0 -= _hj_i___0; _hj_j___0 ^= _hj_i___0 << 10; _hf_hashv___0 -= _hj_i___0; _hf_hashv___0 -= _hj_j___0; _hf_hashv___0 ^= _hj_j___0 >> 15; break; } _hf_bkt___0 = _hf_hashv___0 & (((m->val)->hh.tbl)->num_buckets - 1U); break; } while (1) { if ((((m->val)->hh.tbl)->buckets + _hf_bkt___0)->hh_head) { while (1) { o = (ObjectHT *)((void *)((char *)(((m->val)->hh.tbl)->buckets + _hf_bkt___0)->hh_head - ((m->val)->hh.tbl)->hho)); break; } } else { o = (ObjectHT *)((void *)0); } while (o) { tmp___5 = strlen((char const *)field); if ((size_t )o->hh.keylen == tmp___5) { tmp___3 = strlen((char const *)field); tmp___4 = memcmp((void const *)o->hh.key, (void const *)field, tmp___3); if (tmp___4 == 0) { break; } } if (o->hh.hh_next) { while (1) { o = (ObjectHT *)((void *)((char *)o->hh.hh_next - ((m->val)->hh.tbl)->hho)); break; } } else { o = (ObjectHT *)((void *)0); } } break; } } break; } if (! ((unsigned long )((void *)0) != (unsigned long )o)) { __assert_fail("((void *)0) != o", "src/src/flatds.c", 151U, "getSymName"); } return (o->symName); } } ObjectHT *findBySymName(char *symName ) { MainHT *mn ; MainHT *tmpMn ; ObjectHT *object ; ObjectHT *tmpObj ; void *tmp ; void *tmp___0 ; void *tmp___1 ; void *tmp___2 ; int tmp___3 ; { mn = mainHT; if (mainHT) { tmp = mainHT->hh.next; } else { tmp = (void *)0; } tmpMn = (MainHT *)tmp; while (mn) { object = mn->val; if (mn->val) { tmp___1 = (mn->val)->hh.next; } else { tmp___1 = (void *)0; } tmpObj = (ObjectHT *)tmp___1; while (object) { if ((unsigned long )((void *)0) != (unsigned long )object->symName) { tmp___3 = strcmp((char const *)object->symName, (char const *)symName); if (0 == tmp___3) { return (object); } } object = tmpObj; if (tmpObj) { tmp___2 = tmpObj->hh.next; } else { tmp___2 = (void *)0; } tmpObj = (ObjectHT *)tmp___2; } mn = tmpMn; if (tmpMn) { tmp___0 = tmpMn->hh.next; } else { tmp___0 = (void *)0; } tmpMn = (MainHT *)tmp___0; } return ((ObjectHT *)0); } } void UpdateSymName(char *symName , char *sname ) { MainHT *mn ; MainHT *tmpMn ; ObjectHT *object ; ObjectHT *tmpObj ; char *formula ; void *tmp ; void *tmp___0 ; void *tmp___1 ; void *tmp___2 ; int tmp___3 ; size_t tmp___4 ; void *tmp___5 ; size_t tmp___6 ; void *tmp___7 ; int tmp___8 ; { mn = mainHT; if (mainHT) { tmp = mainHT->hh.next; } else { tmp = (void *)0; } tmpMn = (MainHT *)tmp; while (mn) { object = mn->val; if (mn->val) { tmp___1 = (mn->val)->hh.next; } else { tmp___1 = (void *)0; } tmpObj = (ObjectHT *)tmp___1; while (object) { tmp___8 = strcmp((char const *)object->symName, (char const *)symName); if (0 == tmp___8) { tmp___3 = (int )getPrepositionalFormula(sname); formula = (char *)tmp___3; if ((unsigned long )((void *)0) == (unsigned long )object->symName) { tmp___4 = strlen((char const *)formula); tmp___5 = malloc(sizeof(char ) * (tmp___4 + 1UL)); object->symName = (char *)tmp___5; } else { tmp___6 = strlen((char const *)formula); tmp___7 = realloc((void *)object->symName, sizeof(char ) * (tmp___6 + 1UL)); object->symName = (char *)tmp___7; } strcpy((char * __restrict )object->symName, (char const * __restrict )formula); } object = tmpObj; if (tmpObj) { tmp___2 = tmpObj->hh.next; } else { tmp___2 = (void *)0; } tmpObj = (ObjectHT *)tmp___2; } mn = tmpMn; if (tmpMn) { tmp___0 = tmpMn->hh.next; } else { tmp___0 = (void *)0; } tmpMn = (MainHT *)tmp___0; } return; } } ObjectType getObjectType(int t ) { ObjectType type ; { switch (t) { case 0: type = (ObjectType )0; break; case 1: type = (ObjectType )1; break; case 2: type = (ObjectType )2; break; case 3: type = (ObjectType )3; break; case 4: type = (ObjectType )4; break; } return (type); } } void setValue(char *symName , int t , void *value ) { ObjectType type ; ObjectHT *o ; ObjectHT *tmp ; int tmp___0 ; { type = getObjectType(t); tmp = findBySymName(symName); o = tmp; if ((unsigned long )o == (unsigned long )((void *)0)) { return; } tmp___0 = getSizeByType(type); memcpy((void * __restrict )o->val, (void const * __restrict )value, (size_t )tmp___0); return; } } void *getValue(char *symName ) { ObjectHT *o ; ObjectHT *tmp ; { tmp = findBySymName(symName); o = tmp; return (o->val); } } void delete_allStructTableEntry(void) { { while (1) { if (mainHT) { free((void *)(mainHT->hh.tbl)->buckets); free((void *)mainHT->hh.tbl); mainHT = (MainHT *)((void *)0); } break; } mainHT = (MainHT *)((void *)0); return; } } #pragma merger("0","./cdg.i","-g,-g") Stack *stackNew(int elementSize ) ; void stackPush(Stack *s , void const *element ) ; void stackPop(Stack *s , void *element ) ; int stackIsEmpty(Stack *s ) ; void stackFree(Stack *s ) ; CDGNode *newNode(int id , int score , int outcome , char const *expr , CDGNode *trueNodeSet , CDGNode *falseNodeSet , CDGNode *parent , CDGNode *next ) ; CDGNode *newBlankNode(void) ; CDGNode *addDummyNodes(CDGNode *node___0 ) ; void deleteNode(CDGNode *node___0 ) ; int getID(CDGNode *node___0 ) ; CDGNode *setID(CDGNode *node___0 , int id ) ; int getScore(CDGNode *node___0 ) ; CDGNode *setScore(CDGNode *node___0 , int score ) ; int getOutcome(CDGNode *node___0 ) ; CDGNode *setOutcome(CDGNode *node___0 , int outcome ) ; char *getExpr(CDGNode *node___0 ) ; CDGNode *setExpr(CDGNode *node___0 , char const *expr ) ; CDGNode *getTrueNodeSet(CDGNode *node___0 ) ; CDGNode *getFalseNodeSet(CDGNode *node___0 ) ; CDGNode *addTrueNode(CDGNode *node___0 , CDGNode *trueNode ) ; CDGNode *addFalseNode(CDGNode *node___0 , CDGNode *falseNode ) ; CDGNode *getParent(CDGNode *node___0 ) ; CDGNode *setParent(CDGNode *node___0 , CDGNode *parentNode ) ; CDGNode *getNextNode(CDGNode *node___0 ) ; CDGNode *setNextNode(CDGNode *node___0 , CDGNode *nextNode ) ; CDGNode *updateScore(CDGNode *node___0 , int initialize ) ; CDGNode *updateCDG(CDGNode *root___0 , int initialize ) ; void coverNodes(CDGNode *root___0 , CDGNode **nodes___0 , int size ) ; void deleteCDG(CDGNode *root___0 ) ; CDGNode *getPathNode(CDGPath *path ) ; CDGPath *getNextPath(CDGPath *path ) ; CDGPath *getTopPaths(CDGContext *ctx___0 , CDGNode *root___0 , int numberOfPaths ) ; CDGNode *getFeasibleSatNodes(CDGContext *ctx___0 , int pathRank___0 , CDGNode *list ) ; int getPathLength(CDGNode *node___0 ) ; void deletePaths(CDGPath *path ) ; int max(int a , int b ) { int tmp ; { if (a > b) { tmp = a; } else { tmp = b; } return (tmp); } } void pushNodeListToStack(Stack *s , CDGNode *node___0 ) { { if (! ((unsigned long )((void *)0) != (unsigned long )node___0)) { __assert_fail("((void *)0) != node", "src/src/cdg.c", 8U, "pushNodeListToStack"); } while (1) { stackPush(s, (void const *)(& node___0)); node___0 = getNextNode(node___0); if (! node___0) { break; } } return; } } void postOrder(CDGNode *root___0 , Stack *s ) { Stack *temp ; Stack *tmp ; CDGNode *node___0 ; CDGNode *tmp___0 ; CDGNode *tmp___1 ; CDGNode *tmp___2 ; CDGNode *tmp___3 ; int tmp___4 ; { if ((unsigned long )((void *)0) == (unsigned long )root___0) { return; } tmp = stackNew((int )sizeof(CDGNode *)); temp = tmp; pushNodeListToStack(temp, root___0); while (1) { tmp___4 = stackIsEmpty(temp); if (tmp___4) { break; } stackPop(temp, (void *)(& node___0)); tmp___1 = getTrueNodeSet(node___0); if (tmp___1) { tmp___0 = getTrueNodeSet(node___0); pushNodeListToStack(temp, tmp___0); } tmp___3 = getFalseNodeSet(node___0); if (tmp___3) { tmp___2 = getFalseNodeSet(node___0); pushNodeListToStack(temp, tmp___2); } stackPush(s, (void const *)(& node___0)); } stackFree(temp); return; } } CDGNode *getTrueNodeSet(CDGNode *node___0 ) { { return (node___0->trueNodeSet); } } CDGNode *setTrueNodeSet(CDGNode *node___0 , CDGNode *trueNodeSet ) { { node___0->trueNodeSet = trueNodeSet; return (node___0); } } CDGNode *getFalseNodeSet(CDGNode *node___0 ) { { return (node___0->falseNodeSet); } } CDGNode *setFalseNodeSet(CDGNode *node___0 , CDGNode *falseNodeSet ) { { node___0->falseNodeSet = falseNodeSet; return (node___0); } } CDGNode *setNextNode(CDGNode *node___0 , CDGNode *nextNode ) { CDGNode *tmp ; { node___0->next = nextNode; if (nextNode) { tmp = getParent(node___0); setParent(nextNode, tmp); } return (node___0); } } CDGNode *setTrueNodeSetScore(CDGNode *node___0 , int score ) { CDGNode *curr ; { curr = getTrueNodeSet(node___0); while ((unsigned long )curr != (unsigned long )((void *)0)) { setScore(curr, score); curr = curr->next; } return (node___0); } } CDGNode *setFalseNodeSetScore(CDGNode *node___0 , int score ) { CDGNode *curr ; { curr = getFalseNodeSet(node___0); while ((unsigned long )curr != (unsigned long )((void *)0)) { setScore(curr, score); curr = curr->next; } return (node___0); } } CDGNode *getLastNode(CDGNode *node___0 ) { CDGNode *curr ; CDGNode *tmp ; { if (! ((unsigned long )((void *)0) != (unsigned long )node___0)) { __assert_fail("((void *)0) != node", "src/src/cdg.c", 88U, "getLastNode"); } curr = node___0; while (1) { tmp = getNextNode(curr); if (! tmp) { break; } curr = getNextNode(curr); } return (curr); } } int isLeaf(CDGNode *node___0 ) { CDGNode *tmp ; CDGNode *tmp___0 ; { tmp = getTrueNodeSet(node___0); if (tmp) { return (0); } else { tmp___0 = getFalseNodeSet(node___0); if (tmp___0) { return (0); } } return (1); } } int getConditionalNodeSum(CDGNode *node___0 ) { int sum ; int tmp ; int tmp___0 ; { sum = 0; while ((unsigned long )node___0 != (unsigned long )((void *)0)) { tmp___0 = isLeaf(node___0); if (! tmp___0) { tmp = getScore(node___0); sum += tmp; } node___0 = getNextNode(node___0); } return (sum); } } int hasUncoveredChild(CDGNode *node___0 , int branch ) { CDGNode *temp ; int tmp ; int tmp___0 ; { if (branch) { temp = getTrueNodeSet(node___0); } else { temp = getFalseNodeSet(node___0); } while (temp) { tmp = isLeaf(temp); if (tmp) { tmp___0 = getScore(temp); if (0 < tmp___0) { return (1); } } temp = getNextNode(temp); } return (0); } } int hasUncoveredBranch(CDGNode *node___0 , int branch ) { CDGNode *tmp ; CDGNode *tmp___0 ; int tmp___1 ; int tmp___2 ; { if (branch) { tmp = getTrueNodeSet(node___0); if ((unsigned long )((void *)0) == (unsigned long )tmp) { return (0); } } if (0 == branch) { tmp___0 = getFalseNodeSet(node___0); if ((unsigned long )((void *)0) == (unsigned long )tmp___0) { return (0); } } tmp___1 = getID(node___0); tmp___2 = getBranchInfo(tmp___1, branch); if (0 == tmp___2) { return (1); } return (0); } } int hasConditionalChild(CDGNode *node___0 ) { CDGNode *temp ; int tmp ; int tmp___0 ; { temp = getTrueNodeSet(node___0); while (temp) { tmp = isLeaf(temp); if (! tmp) { return (1); } temp = getNextNode(temp); } temp = getFalseNodeSet(node___0); while (temp) { tmp___0 = isLeaf(temp); if (! tmp___0) { return (1); } temp = getNextNode(temp); } return (0); } } int isConditionalLeaf(CDGNode *node___0 ) { int tmp ; int tmp___0 ; CDGNode *tmp___1 ; int tmp___2 ; CDGNode *tmp___3 ; int tmp___4 ; { tmp = isLeaf(node___0); if (tmp) { return (0); } tmp___0 = hasConditionalChild(node___0); if (! tmp___0) { return (1); } tmp___1 = getTrueNodeSet(node___0); tmp___2 = getConditionalNodeSum(tmp___1); if (0 < tmp___2) { return (0); } tmp___3 = getFalseNodeSet(node___0); tmp___4 = getConditionalNodeSum(tmp___3); if (0 < tmp___4) { return (0); } return (1); } } CDGNode *resetExpr(CDGNode *node___0 ) { { if ((unsigned long )((void *)0) != (unsigned long )node___0->expr) { free((void *)node___0->expr); } return (node___0); } } CDGNode *resetTrueNodeSet(CDGNode *node___0 ) { { node___0->trueNodeSet = (struct CDGNode *)((void *)0); return (node___0); } } CDGNode *resetFalseNodeSet(CDGNode *node___0 ) { { node___0->falseNodeSet = (struct CDGNode *)((void *)0); return (node___0); } } CDGNode *resetParent(CDGNode *node___0 ) { { node___0->parent = (struct CDGNode *)((void *)0); return (node___0); } } CDGNode *resetNextNode(CDGNode *node___0 ) { { node___0->next = (struct CDGNode *)((void *)0); return (node___0); } } CDGNode *getMaxScoreConditionNode(CDGNode *node___0 ) { CDGNode *out ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; { out = (CDGNode *)((void *)0); while (1) { tmp___1 = isLeaf(node___0); if (! tmp___1) { tmp___2 = getScore(node___0); if (0 < tmp___2) { if ((unsigned long )((void *)0) == (unsigned long )out) { out = node___0; } else { tmp = getScore(out); tmp___0 = getScore(node___0); if (tmp < tmp___0) { out = node___0; } } } } node___0 = getNextNode(node___0); if (! ((unsigned long )((void *)0) != (unsigned long )node___0)) { break; } } return (out); } } CDGNode *getMaxScoreConditionChildNode(CDGNode *node___0 , int *outcome ) { CDGNode *maxTrue ; CDGNode *maxFalse ; CDGNode *tmp ; CDGNode *tmp___0 ; CDGNode *tmp___1 ; CDGNode *tmp___2 ; int tmp___3 ; int tmp___4 ; { maxTrue = (CDGNode *)((void *)0); maxFalse = (CDGNode *)((void *)0); tmp___0 = getTrueNodeSet(node___0); if (tmp___0) { tmp = getTrueNodeSet(node___0); maxTrue = getMaxScoreConditionNode(tmp); } tmp___2 = getFalseNodeSet(node___0); if (tmp___2) { tmp___1 = getFalseNodeSet(node___0); maxFalse = getMaxScoreConditionNode(tmp___1); } if ((unsigned long )((void *)0) == (unsigned long )maxFalse) { *outcome = 1; return (maxTrue); } if ((unsigned long )((void *)0) == (unsigned long )maxTrue) { *outcome = 0; return (maxFalse); } tmp___3 = getScore(maxTrue); tmp___4 = getScore(maxFalse); if (tmp___3 < tmp___4) { *outcome = 0; return (maxFalse); } *outcome = 1; return (maxTrue); } } CDGNode *newNode(int id , int score , int outcome , char const *expr , CDGNode *trueNodeSet , CDGNode *falseNodeSet , CDGNode *parent , CDGNode *next ) { CDGNode *node___0 ; void *tmp ; { tmp = malloc(sizeof(CDGNode )); node___0 = (CDGNode *)tmp; if (! ((unsigned long )((void *)0) != (unsigned long )node___0)) { __assert_fail("((void *)0) != node", "src/src/cdg.c", 233U, "newNode"); } setID(node___0, id); setScore(node___0, score); setOutcome(node___0, outcome); setExpr(node___0, expr); setTrueNodeSet(node___0, trueNodeSet); setFalseNodeSet(node___0, falseNodeSet); setParent(node___0, parent); setNextNode(node___0, next); return (node___0); } } CDGNode *newBlankNode(void) { CDGNode *tmp ; { tmp = newNode(-1, 1, 1, (char const *)((void *)0), (CDGNode *)((void *)0), (CDGNode *)((void *)0), (CDGNode *)((void *)0), (CDGNode *)((void *)0)); return (tmp); } } void deleteNode(CDGNode *node___0 ) { { if (! ((unsigned long )((void *)0) != (unsigned long )node___0)) { __assert_fail("((void *)0) != node", "src/src/cdg.c", 250U, "deleteNode"); } free((void *)node___0); return; } } void deleteNodeList(CDGNode *node___0 ) { CDGNode *next ; { if (! ((unsigned long )((void *)0) != (unsigned long )node___0)) { __assert_fail("((void *)0) != node", "src/src/cdg.c", 260U, "deleteNodeList"); } while (1) { next = getNextNode(node___0); deleteNode(node___0); node___0 = next; if (! node___0) { break; } } return; } } void deleteCDG(CDGNode *root___0 ) { CDGNode *node___0 ; Stack *nodeStack ; Stack *tmp ; int tmp___0 ; { if ((unsigned long )((void *)0) == (unsigned long )root___0) { return; } tmp = stackNew((int )sizeof(CDGNode *)); nodeStack = tmp; postOrder(root___0, nodeStack); while (1) { tmp___0 = stackIsEmpty(nodeStack); if (tmp___0) { break; } stackPop(nodeStack, (void *)(& node___0)); deleteNode(node___0); } stackFree(nodeStack); return; } } int getID(CDGNode *node___0 ) { { return (node___0->id); } } CDGNode *setID(CDGNode *node___0 , int id ) { { node___0->id = id; return (node___0); } } int getScore(CDGNode *node___0 ) { { return (node___0->score); } } CDGNode *setScore(CDGNode *node___0 , int score ) { { node___0->score = score; return (node___0); } } int getOutcome(CDGNode *node___0 ) { { return (node___0->outcome); } } CDGNode *setOutcome(CDGNode *node___0 , int outcome ) { { node___0->outcome = outcome; return (node___0); } } char *getExpr(CDGNode *node___0 ) { { if ((unsigned long )node___0->expr != (unsigned long )((void *)0)) { return (node___0->expr); } return ((char *)((void *)0)); } } CDGNode *setExpr(CDGNode *node___0 , char const *expr ) { size_t tmp ; void *tmp___0 ; { if ((unsigned long )((void *)0) == (unsigned long )expr) { node___0->expr = (char *)((void *)0); return (node___0); } tmp = strlen(expr); tmp___0 = malloc(sizeof(char ) * (tmp + 1UL)); node___0->expr = (char *)tmp___0; strcpy((char * __restrict )node___0->expr, (char const * __restrict )expr); return (node___0); } } CDGNode *addTrueNode(CDGNode *node___0 , CDGNode *trueNode ) { { if ((unsigned long )((void *)0) == (unsigned long )trueNode) { return (node___0); } trueNode->next = node___0->trueNodeSet; node___0->trueNodeSet = trueNode; setParent(trueNode, node___0); return (node___0); } } CDGNode *addFalseNode(CDGNode *node___0 , CDGNode *falseNode ) { { if ((unsigned long )((void *)0) == (unsigned long )falseNode) { return (node___0); } falseNode->next = node___0->falseNodeSet; node___0->falseNodeSet = falseNode; setParent(falseNode, node___0); return (node___0); } } CDGNode *getParent(CDGNode *node___0 ) { { return (node___0->parent); } } CDGNode *setParent(CDGNode *node___0 , CDGNode *parentNode ) { { node___0->parent = parentNode; return (node___0); } } CDGNode *getNextNode(CDGNode *node___0 ) { { return (node___0->next); } } CDGNode *updateScore(CDGNode *node___0 , int initialize ) { int tmp ; CDGNode *tmp___0 ; CDGNode *tmp___1 ; CDGNode *tmp___2 ; int tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; int tmp___7 ; int tmp___8 ; CDGNode *tmp___9 ; int tmp___10 ; CDGNode *tmp___11 ; int tmp___12 ; CDGNode *tmp___13 ; int tmp___14 ; int trueScore ; CDGNode *tmp___15 ; int tmp___16 ; int falseScore ; CDGNode *tmp___17 ; int tmp___18 ; int tmp___19 ; int tmp___20 ; int tmp___21 ; int tmp___22 ; { if (! ((unsigned long )((void *)0) != (unsigned long )node___0)) { __assert_fail("((void *)0) != node", "src/src/cdg.c", 360U, "updateScore"); } tmp = isLeaf(node___0); if (tmp) { return (node___0); } tmp___14 = isConditionalLeaf(node___0); if (tmp___14) { if (initialize) { tmp___7 = getBranchInfo(node___0->id, 1); if (tmp___7) { tmp___8 = getBranchInfo(node___0->id, 0); if (tmp___8) { goto _L___0; } else { setScore(node___0, 1); setTrueNodeSetScore(node___0, 0); setFalseNodeSetScore(node___0, 1); tmp___0 = setOutcome(node___0, 0); return (tmp___0); } } else { _L___0: /* CIL Label */ tmp___5 = getBranchInfo(node___0->id, 0); if (tmp___5) { tmp___6 = getBranchInfo(node___0->id, 1); if (tmp___6) { goto _L; } else { setScore(node___0, 1); setFalseNodeSetScore(node___0, 0); setTrueNodeSetScore(node___0, 1); tmp___1 = setOutcome(node___0, 1); return (tmp___1); } } else { _L: /* CIL Label */ tmp___3 = getBranchInfo(node___0->id, 0); if (tmp___3) { tmp___4 = getBranchInfo(node___0->id, 1); if (tmp___4) { setScore(node___0, 0); setTrueNodeSetScore(node___0, 0); setFalseNodeSetScore(node___0, 0); tmp___2 = setOutcome(node___0, 1); return (tmp___2); } } } } } else { tmp___10 = hasUncoveredChild(node___0, 1); if (tmp___10) { setScore(node___0, 1); tmp___9 = setOutcome(node___0, 1); return (tmp___9); } tmp___12 = hasUncoveredChild(node___0, 0); if (tmp___12) { setScore(node___0, 1); tmp___11 = setOutcome(node___0, 0); return (tmp___11); } } setScore(node___0, 0); tmp___13 = setOutcome(node___0, 1); return (tmp___13); } tmp___15 = getTrueNodeSet(node___0); tmp___16 = getConditionalNodeSum(tmp___15); trueScore = tmp___16; tmp___17 = getFalseNodeSet(node___0); tmp___18 = getConditionalNodeSum(tmp___17); falseScore = tmp___18; if (trueScore >= falseScore) { if (node___0->id == 0) { setScore(node___0, trueScore); setOutcome(node___0, 1); } else { tmp___19 = getBranchInfo(node___0->id, 1); if (tmp___19) { tmp___20 = getBranchInfo(node___0->id, 0); if (tmp___20) { setScore(node___0, trueScore); } else { setScore(node___0, trueScore + 1); } } else { setScore(node___0, trueScore + 1); } setOutcome(node___0, 1); } } else if (node___0->id == 0) { setScore(node___0, falseScore); setOutcome(node___0, 0); } else { tmp___21 = getBranchInfo(node___0->id, 1); if (tmp___21) { tmp___22 = getBranchInfo(node___0->id, 0); if (tmp___22) { setScore(node___0, falseScore); } else { setScore(node___0, falseScore + 1); } } else { setScore(node___0, falseScore + 1); } setOutcome(node___0, 0); } return (node___0); } } CDGNode *propagateScoreChange(CDGNode *node___0 ) { CDGNode *currNode ; { currNode = node___0; while (currNode) { updateScore(currNode, 0); currNode = getParent(currNode); } return (node___0); } } CDGNode *visitAnyOneNode(CDGNode *node___0 ) { int tmp ; int tmp___0 ; { if (! ((unsigned long )((void *)0) != (unsigned long )node___0)) { __assert_fail("((void *)0) != node", "src/src/cdg.c", 448U, "visitAnyOneNode"); } while (1) { tmp = isLeaf(node___0); if (tmp) { tmp___0 = getScore(node___0); if (1 == tmp___0) { setScore(node___0, 0); return (node___0); } } node___0 = getNextNode(node___0); if (! node___0) { break; } } return ((CDGNode *)((void *)0)); } } CDGNode *visitAnyOneChild(CDGNode *node___0 ) { CDGNode *child ; CDGNode *tmp ; CDGNode *tmp___0 ; CDGNode *tmp___1 ; CDGNode *tmp___2 ; { child = (CDGNode *)((void *)0); tmp___0 = getFalseNodeSet(node___0); if (tmp___0) { tmp = getFalseNodeSet(node___0); child = visitAnyOneNode(tmp); } if ((unsigned long )((void *)0) == (unsigned long )child) { tmp___2 = getTrueNodeSet(node___0); if (tmp___2) { tmp___1 = getTrueNodeSet(node___0); child = visitAnyOneNode(tmp___1); } } if (! ((unsigned long )((void *)0) != (unsigned long )child)) { __assert_fail("((void *)0) != child", "src/src/cdg.c", 468U, "visitAnyOneChild"); } return (child); } } CDGNode *unVisitNode(CDGNode *node___0 ) { CDGNode *tmp ; { tmp = setScore(node___0, 1); return (tmp); } } CDGNode *updateCDG(CDGNode *root___0 , int initialize ) { int size ; Stack *nodeStack ; Stack *tmp ; CDGNode *node___0 ; int tmp___0 ; { size = (int )sizeof(CDGNode *); if (! ((unsigned long )((void *)0) != (unsigned long )root___0)) { __assert_fail("((void *)0) != root", "src/src/cdg.c", 479U, "updateCDG"); } tmp = stackNew(size); nodeStack = tmp; postOrder(root___0, nodeStack); while (1) { tmp___0 = stackIsEmpty(nodeStack); if (tmp___0) { break; } stackPop(nodeStack, (void *)(& node___0)); updateScore(node___0, initialize); } stackFree(nodeStack); return (root___0); } } void visitChildren(CDGNode *node___0 , int outcome ) { CDGNode *children ; int tmp ; { if (outcome) { children = getTrueNodeSet(node___0); } else { children = getFalseNodeSet(node___0); } while (children) { tmp = isLeaf(children); if (tmp) { setScore(children, 0); } children = getNextNode(children); } return; } } void visitIfExists(CDGNode *node___0 , CDGNode **nodes___0 , int size ) { int i ; int tmp ; int tmp___0 ; int tmp___1 ; { i = 0; while (i < size) { tmp___0 = getID(node___0); tmp___1 = getID(*(nodes___0 + i)); if (tmp___0 == tmp___1) { tmp = getOutcome(*(nodes___0 + i)); visitChildren(node___0, tmp); return; } i ++; } return; } } void coverNodes(CDGNode *root___0 , CDGNode **nodes___0 , int size ) { Stack *nodeStack ; Stack *tmp ; CDGNode *node___0 ; int tmp___0 ; { if (! ((unsigned long )((void *)0) != (unsigned long )root___0)) { __assert_fail("((void *)0) != root", "src/src/cdg.c", 519U, "coverNodes"); } if (0 == size) { return; } tmp = stackNew((int )sizeof(CDGNode *)); nodeStack = tmp; postOrder(root___0, nodeStack); while (1) { tmp___0 = stackIsEmpty(nodeStack); if (tmp___0) { break; } stackPop(nodeStack, (void *)(& node___0)); visitIfExists(node___0, nodes___0, size); } updateCDG(root___0, 0); return; } } CDGPath *setPathNode(CDGPath *path , CDGNode *node___0 ) { { if (! ((unsigned long )((void *)0) != (unsigned long )path)) { __assert_fail("((void *)0) != path", "src/src/cdg.c", 534U, "setPathNode"); } path->node = node___0; return (path); } } CDGPath *setNextPath(CDGPath *path , CDGPath *nextPath ) { { if (! ((unsigned long )((void *)0) != (unsigned long )path)) { __assert_fail("((void *)0) != path", "src/src/cdg.c", 540U, "setNextPath"); } path->next = nextPath; return (path); } } CDGPath *newPath(void) { CDGPath *path ; void *tmp ; { tmp = malloc(sizeof(CDGPath )); path = (CDGPath *)tmp; if (! ((unsigned long )((void *)0) != (unsigned long )path)) { __assert_fail("((void *)0) != path", "src/src/cdg.c", 548U, "newPath"); } setPathNode(path, (CDGNode *)((void *)0)); setNextPath(path, (CDGPath *)((void *)0)); return (path); } } CDGNode *getPathNode(CDGPath *path ) { { if (! ((unsigned long )((void *)0) != (unsigned long )path)) { __assert_fail("((void *)0) != path", "src/src/cdg.c", 555U, "getPathNode"); } return (path->node); } } CDGPath *getNextPath(CDGPath *path ) { { if (! ((unsigned long )((void *)0) != (unsigned long )path)) { __assert_fail("((void *)0) != path", "src/src/cdg.c", 560U, "getNextPath"); } return (path->next); } } CDGNode *copyToPathNode(CDGNode *pathNode___0 , CDGNode *node___0 ) { int tmp ; char *tmp___0 ; int tmp___1 ; { if (! ((unsigned long )((void *)0) != (unsigned long )pathNode___0)) { __assert_fail("((void *)0) != pathNode", "src/src/cdg.c", 565U, "copyToPathNode"); } tmp = getID(node___0); setID(pathNode___0, tmp); tmp___0 = getExpr(node___0); setExpr(pathNode___0, (char const *)tmp___0); tmp___1 = getOutcome(node___0); setOutcome(pathNode___0, tmp___1); return (pathNode___0); } } CDGNode *pathToList(CDGNode *head ) { Stack *nodeStack ; Stack *tmp ; CDGNode *node___0 ; CDGNode *list ; CDGNode *tmp___0 ; CDGNode *tmp___1 ; int tmp___2 ; { if (! ((unsigned long )((void *)0) != (unsigned long )head)) { __assert_fail("((void *)0) != head", "src/src/cdg.c", 573U, "pathToList"); } tmp = stackNew((int )sizeof(CDGNode *)); nodeStack = tmp; list = (CDGNode *)((void *)0); postOrder(head, nodeStack); while (1) { tmp___2 = stackIsEmpty(nodeStack); if (tmp___2) { break; } stackPop(nodeStack, (void *)(& node___0)); tmp___0 = newBlankNode(); tmp___1 = copyToPathNode(tmp___0, node___0); list = setNextNode(tmp___1, list); } return (list); } } CDGNode *getTopPath(CDGNode *node___0 , Stack *changedNodes , Stack *changedBranches ) { CDGNode *pathNode___0 ; CDGNode *tmp ; CDGNode *temp ; int branch ; CDGNode *tmp___0 ; CDGNode *tmp___1 ; int tmp___2 ; int tmp___3 ; int tmp___4 ; CDGNode *tmp___5 ; CDGNode *tmp___6 ; int tmp___7 ; int tmp___8 ; int tmp___9 ; CDGNode *tmp___10 ; CDGNode *tmp___11 ; int tmp___12 ; int tmp___13 ; int tmp___14 ; { tmp = newBlankNode(); pathNode___0 = tmp; temp = pathNode___0; while (node___0) { tmp___14 = getScore(node___0); if (0 != tmp___14) { stackPush(changedNodes, (void const *)(& node___0)); branch = getOutcome(node___0); stackPush(changedBranches, (void const *)(& branch)); tmp___13 = isLeaf(node___0); if (tmp___13) { setScore(node___0, 0); } else { tmp___0 = newBlankNode(); tmp___1 = copyToPathNode(tmp___0, node___0); setNextNode(temp, tmp___1); temp = getNextNode(temp); tmp___12 = getOutcome(node___0); if (tmp___12) { tmp___2 = getID(node___0); tmp___3 = getBranchInfo(tmp___2, 0); tmp___4 = getID(node___0); setBranchInfo(tmp___4, 1, tmp___3); tmp___5 = getTrueNodeSet(node___0); tmp___6 = getTopPath(tmp___5, changedNodes, changedBranches); setTrueNodeSet(temp, tmp___6); } else { tmp___7 = getID(node___0); tmp___8 = getBranchInfo(tmp___7, 1); tmp___9 = getID(node___0); setBranchInfo(tmp___9, tmp___8, 1); tmp___10 = getFalseNodeSet(node___0); tmp___11 = getTopPath(tmp___10, changedNodes, changedBranches); setFalseNodeSet(temp, tmp___11); } } } node___0 = getNextNode(node___0); } if ((unsigned long )temp == (unsigned long )pathNode___0) { deleteNode(pathNode___0); pathNode___0 = (CDGNode *)((void *)0); } else { temp = pathNode___0; pathNode___0 = getNextNode(pathNode___0); deleteNode(temp); } return (pathNode___0); } } CDGPath *getTopPaths(CDGContext *ctx___0 , CDGNode *root___0 , int numberOfPaths ) { CDGPath *pathHead___0 ; CDGNode *path ; CDGPath *currPath ; CDGNode *node___0 ; int branch ; Stack *changedNodes ; Stack *tmp ; Stack *changedBranches ; Stack *tmp___0 ; CDGPath *tmp___1 ; CDGPath *tmp___2 ; CDGPath *tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; int tmp___7 ; int tmp___8 ; int tmp___9 ; int tmp___10 ; int tmp___11 ; int tmp___12 ; int tmp___13 ; CDGPath *outPathHead ; CDGNode *tmp___14 ; CDGPath *tmp___15 ; CDGNode *tmp___16 ; CDGPath *tmp___17 ; CDGPath *tmp___18 ; { pathHead___0 = (CDGPath *)((void *)0); tmp = stackNew((int )sizeof(CDGNode *)); changedNodes = tmp; tmp___0 = stackNew((int )sizeof(int )); changedBranches = tmp___0; while (1) { tmp___4 = numberOfPaths; numberOfPaths --; if (! tmp___4) { break; } path = getTopPath(root___0, changedNodes, changedBranches); if ((unsigned long )((void *)0) == (unsigned long )path) { break; } if ((unsigned long )((void *)0) == (unsigned long )pathHead___0) { tmp___1 = newPath(); pathHead___0 = setPathNode(tmp___1, path); currPath = pathHead___0; } else { tmp___2 = newPath(); tmp___3 = setPathNode(tmp___2, path); setNextPath(currPath, tmp___3); currPath = getNextPath(currPath); } updateCDG(root___0, 0); } while (1) { tmp___12 = stackIsEmpty(changedNodes); if (tmp___12) { break; } else { tmp___13 = stackIsEmpty(changedBranches); if (tmp___13) { break; } } stackPop(changedNodes, (void *)(& node___0)); stackPop(changedBranches, (void *)(& branch)); tmp___11 = isLeaf(node___0); if (tmp___11) { setScore(node___0, 1); } else if (branch) { tmp___5 = getID(node___0); tmp___6 = getBranchInfo(tmp___5, 0); tmp___7 = getID(node___0); setBranchInfo(tmp___7, 0, tmp___6); } else { tmp___8 = getID(node___0); tmp___9 = getBranchInfo(tmp___8, 1); tmp___10 = getID(node___0); setBranchInfo(tmp___10, tmp___9, 0); } } updateCDG(root___0, 0); stackFree(changedNodes); stackFree(changedBranches); ctx___0->topPaths = pathHead___0; if ((unsigned long )((void *)0) == (unsigned long )pathHead___0) { return ((CDGPath *)((void *)0)); } outPathHead = (CDGPath *)((void *)0); currPath = (CDGPath *)((void *)0); path = (CDGNode *)((void *)0); while ((unsigned long )((void *)0) != (unsigned long )pathHead___0) { path = getPathNode(pathHead___0); if ((unsigned long )((void *)0) == (unsigned long )outPathHead) { tmp___14 = pathToList(path); tmp___15 = newPath(); outPathHead = setPathNode(tmp___15, tmp___14); currPath = outPathHead; } else { tmp___16 = pathToList(path); tmp___17 = newPath(); tmp___18 = setPathNode(tmp___17, tmp___16); setNextPath(currPath, tmp___18); currPath = getNextPath(currPath); } pathHead___0 = getNextPath(pathHead___0); } return (outPathHead); } } void deletePaths(CDGPath *path ) { CDGPath *next ; CDGNode *tmp ; { if (! ((unsigned long )((void *)0) != (unsigned long )path)) { __assert_fail("((void *)0) != path", "src/src/cdg.c", 686U, "deletePaths"); } while (1) { next = getNextPath(path); tmp = getPathNode(path); deleteNodeList(tmp); setNextPath(path, (CDGPath *)((void *)0)); free((void *)path); path = next; if (! path) { break; } } return; } } CDGNode *addDummyNodes(CDGNode *node___0 ) { CDGNode *tmp ; CDGNode *tmp___0 ; CDGNode *tmp___1 ; CDGNode *tmp___2 ; int tmp___3 ; CDGNode *tmp___4 ; CDGNode *tmp___5 ; { while (node___0) { tmp___3 = isLeaf(node___0); if (! tmp___3) { tmp___2 = getTrueNodeSet(node___0); if ((unsigned long )((void *)0) == (unsigned long )tmp___2) { tmp = newBlankNode(); addTrueNode(node___0, tmp); } else { tmp___1 = getFalseNodeSet(node___0); if ((unsigned long )((void *)0) == (unsigned long )tmp___1) { tmp___0 = newBlankNode(); addFalseNode(node___0, tmp___0); } } } tmp___4 = getTrueNodeSet(node___0); addDummyNodes(tmp___4); tmp___5 = getFalseNodeSet(node___0); addDummyNodes(tmp___5); node___0 = getNextNode(node___0); } return (node___0); } } CDGNode *findNode(CDGNode *node___0 , int id ) { int tmp ; CDGNode *temp ; CDGNode *tmp___0 ; CDGNode *tmp___1 ; { if ((unsigned long )((void *)0) == (unsigned long )node___0) { return ((CDGNode *)((void *)0)); } tmp = getID(node___0); if (id == tmp) { return (node___0); } temp = (CDGNode *)((void *)0); tmp___0 = getNextNode(node___0); tmp___1 = findNode(tmp___0, id); return (tmp___1); } } int nodeExists(CDGNode *node___0 , int id ) { CDGNode *tmp ; { tmp = findNode(node___0, id); return ((unsigned long )((void *)0) != (unsigned long )tmp); } } CDGNode *buildFeasiblePath(CDGNode *node___0 , CDGNode *list ) { int tmp ; int tmp___0 ; CDGNode *out ; CDGNode *tmp___1 ; CDGNode *tmp___2 ; CDGNode *tmp___3 ; CDGNode *tmp___4 ; CDGNode *tmp___5 ; CDGNode *tmp___6 ; CDGNode *tmp___7 ; { while (1) { if (node___0) { tmp = getID(node___0); tmp___0 = nodeExists(list, tmp); if (! (0 == tmp___0)) { break; } } else { break; } node___0 = getNextNode(node___0); } if ((unsigned long )((void *)0) == (unsigned long )node___0) { return ((CDGNode *)((void *)0)); } out = (CDGNode *)((void *)0); tmp___1 = newBlankNode(); out = copyToPathNode(tmp___1, node___0); tmp___2 = getTrueNodeSet(node___0); tmp___3 = buildFeasiblePath(tmp___2, list); setTrueNodeSet(out, tmp___3); tmp___4 = getFalseNodeSet(node___0); tmp___5 = buildFeasiblePath(tmp___4, list); setFalseNodeSet(out, tmp___5); tmp___6 = getNextNode(node___0); tmp___7 = buildFeasiblePath(tmp___6, list); setNextNode(out, tmp___7); return (out); } } CDGNode *getFeasiblePath(CDGNode *path , CDGNode *list ) { CDGNode *tmp ; { tmp = buildFeasiblePath(path, list); return (tmp); } } CDGNode *getFeasibleSatNodes(CDGContext *ctx___0 , int pathRank___0 , CDGNode *list ) { CDGPath *topPath ; int tmp ; CDGNode *tmp___0 ; CDGNode *tmp___1 ; CDGNode *tmp___2 ; { if (! ((unsigned long )((void *)0) != (unsigned long )ctx___0)) { __assert_fail("((void *)0) != ctx", "src/src/cdg.c", 755U, "getFeasibleSatNodes"); } if (! ((unsigned long )((void *)0) != (unsigned long )ctx___0->topPaths)) { __assert_fail("((void *)0) != (*ctx).topPaths", "src/src/cdg.c", 756U, "getFeasibleSatNodes"); } topPath = ctx___0->topPaths; while (1) { tmp = pathRank___0; pathRank___0 --; if (! (0 < tmp)) { break; } topPath = getNextPath(topPath); } tmp___0 = getPathNode(topPath); tmp___1 = getFeasiblePath(tmp___0, list); tmp___2 = pathToList(tmp___1); return (tmp___2); } } int getPathLength(CDGNode *node___0 ) { CDGNode *tmp ; int tmp___0 ; { if ((unsigned long )((void *)0) == (unsigned long )node___0) { return (0); } tmp = getNextNode(node___0); tmp___0 = getPathLength(tmp); return (1 + tmp___0); } } #pragma merger("0","./cdgWrapper.i","-g,-g") extern void callInstrumentedFun() ; CDGNode *nodes[500] = { (CDGNode *)((void *)0)}; CDGNode *root = (CDGNode *)((void *)0); CDGNode *savePath = (CDGNode *)((void *)0); CDGContext ctx ; CDGPath *pathHead ; CDGPath *newSATPath ; int pathRank = 0; float previousCoverage = (float )0; int countAttempts = 0; int totalTestCases = 0; void preOrderCDG(CDGNode *node___0 ) ; void addtoCDGnode(int id , int pid , int branch ) ; void setArray(int id , char const *expr ) ; void printArray(void) ; int getTestCases(void) ; void addtoCDGnode(int id , int pid , int branch ) { CDGNode *node___0 ; CDGNode *par ; { if ((unsigned long )nodes[pid] == (unsigned long )((void *)0)) { par = newBlankNode(); nodes[pid] = par; setID(par, pid); } else { par = nodes[pid]; } if ((unsigned long )nodes[id] != (unsigned long )((void *)0)) { if ((unsigned long )(nodes[id])->parent != (unsigned long )((void *)0)) { if (((nodes[id])->parent)->id == pid) { return; } } } if ((unsigned long )nodes[id] != (unsigned long )((void *)0)) { node___0 = nodes[id]; } else { node___0 = newBlankNode(); } setID(node___0, id); if (0 == id) { root = node___0; } else if (branch) { addTrueNode(nodes[pid], node___0); } else { addFalseNode(nodes[pid], node___0); } nodes[id] = node___0; return; } } void setArray(int id , char const *expr ) { { setExpr(nodes[id], expr); return; } } void initializeCDG(void) { { updateCDG(root, 1); return; } } void printArray(void) { CDGNode *node___0 ; { node___0 = root; preOrderCDG(node___0); return; } } void preOrderCDG(CDGNode *node___0 ) { CDGNode *tmp ; CDGNode *tmp___0 ; { while (node___0) { tmp = getTrueNodeSet(node___0); preOrderCDG(tmp); tmp___0 = getFalseNodeSet(node___0); preOrderCDG(tmp___0); node___0 = getNextNode(node___0); } return; } } void printPath(CDGNode *node___0 ) { { while (node___0) { node___0 = getNextNode(node___0); } return; } } void sortPath(void) { CDGPath *curr ; CDGPath *temp ; CDGPath *save ; CDGPath *next_curr ; CDGPath *prev_curr ; int l1 ; int i ; int j ; int tmp ; { curr = newSATPath; i = 1; prev_curr = newSATPath; while ((unsigned long )curr != (unsigned long )((void *)0)) { printf((char const * __restrict )"id = %d\n", (curr->node)->id); l1 = getPathLength(curr->node); j = 0; save = newSATPath; temp = newSATPath; next_curr = curr->next; while (1) { if (j < i) { tmp = getPathLength(temp->node); if (! (l1 < tmp)) { break; } } else { break; } save = temp; temp = getNextPath(temp); j ++; } if (j == i) { prev_curr = curr; curr = next_curr; i ++; continue; } if ((unsigned long )save == (unsigned long )temp) { curr->next = newSATPath; newSATPath = curr; prev_curr->next = next_curr; } else { save->next = curr; curr->next = temp; prev_curr->next = next_curr; } i ++; curr = next_curr; } curr = newSATPath; while ((unsigned long )curr != (unsigned long )((void *)0)) { printf((char const * __restrict )"\n\n"); curr = curr->next; } return; } } void initializePathNodes(CDGNode *node___0 ) { CDGNode *curr ; int j ; int tmp ; { j = 0; while (j < 100) { pathNode[j] = (CDGNode *)((void *)0); j ++; } curr = node___0; while ((unsigned long )curr != (unsigned long )((void *)0)) { tmp = getID(curr); pathNode[tmp] = curr; curr = curr->next; } return; } } int getConditionalOutcome(int id , int expr ) { CDGNode *temp ; int tmp ; { if (CDG_Module == 1) { temp = pathNode[id]; if ((unsigned long )temp == (unsigned long )((void *)0)) { return (expr); } tmp = getOutcome(temp); return (tmp); } return (expr); } } int getCDGPaths(void) ; int startCDG(void) { CDGPath *curr ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; { if (CDG_Module == 1) { return (0); } tmp = countCoveredConditions(); tmp___0 = countTotalConditions(); if (tmp == 2 * tmp___0) { return (0); } if (CDG_Module == 2) { return (1); } if (countAttempts >= 10) { return (0); } tmp___1 = countCoveredConditions(); tmp___2 = countTotalConditions(); previousCoverage = (float )((tmp___1 * 100) / (2 * tmp___2)); CDG_Module = 1; print_conditions(); emptyQueue(); initializeCDG(); if ((unsigned long )newSATPath != (unsigned long )((void *)0)) { deletePaths(newSATPath); } newSATPath = (CDGPath *)((void *)0); tmp___3 = getCDGPaths(); if (! tmp___3) { return (0); } curr = newSATPath; while ((unsigned long )curr != (unsigned long )((void *)0)) { printPath(curr->node); curr = curr->next; } CDG_Module = 2; return (1); } } int getMaxFeasible(void) ; int getCDGPaths(void) { int tmp ; { pathHead = getTopPaths(& ctx, root, 5); if ((unsigned long )pathHead == (unsigned long )((void *)0)) { return (0); } ctx.topPaths = pathHead; pathRank = 0; while (1) { tmp = getMaxFeasible(); if (! tmp) { break; } pathRank ++; delete_allSTableEntry(); delete_allStructTableEntry(); } deletePaths(pathHead); pathHead = (CDGPath *)((void *)0); pathRank = 0; return (1); } } int getMaxFeasible(void) { CDGPath *currPath ; CDGNode *save ; CDGNode *curr ; CDGNode *temp ; CDGPath *pathNode___0 ; CDGNode *tmp ; CDGNode *new_head ; CDGNode *new_curr ; char *token ; char *condition ; int infeasible ; int i ; void *tmp___0 ; int tmp___1 ; size_t tmp___2 ; size_t tmp___3 ; void *tmp___4 ; FILE *pipe ; FILE *tmp___5 ; char buffer[100] ; char result[1000] ; char *tmp___6 ; int tmp___7 ; int i___0 ; { tmp = newBlankNode(); pathNode___0 = (CDGPath *)tmp; i = 0; tmp___0 = malloc(2UL * sizeof(char )); condition = (char *)tmp___0; currPath = pathHead; strcpy((char * __restrict )condition, (char const * __restrict )""); while (i < pathRank) { currPath = currPath->next; if ((unsigned long )currPath == (unsigned long )((void *)0)) { return (0); } i ++; } new_head = newNode((currPath->node)->id, (currPath->node)->score, (currPath->node)->outcome, (char const *)(currPath->node)->expr, (CDGNode *)((void *)0), (CDGNode *)((void *)0), (CDGNode *)((void *)0), (CDGNode *)((void *)0)); curr = (currPath->node)->next; save = currPath->node; initializePathNodes(currPath->node); callInstrumentedFun(); while ((unsigned long )curr != (unsigned long )((void *)0)) { tmp___1 = checkForAllConstants(curr->expr); if (tmp___1) { save->next = curr->next; temp = curr; free((void *)temp); curr = save->next; } else { save = curr; curr = curr->next; } } remove("src/src/printTest.smt"); getPrint(); curr = (currPath->node)->next; while ((unsigned long )curr != (unsigned long )((void *)0)) { tmp___2 = strlen((char const *)condition); tmp___3 = strlen((char const *)curr->expr); tmp___4 = realloc((void *)condition, (((tmp___2 + tmp___3) + 1UL) + 2UL) * sizeof(char )); condition = (char *)tmp___4; strcat((char * __restrict )condition, (char const * __restrict )curr->expr); strcat((char * __restrict )condition, (char const * __restrict )"##"); curr = curr->next; } strcat((char * __restrict )condition, (char const * __restrict )"\000"); writeProgramSVariables(); writeConditionsToFile(condition); tmp___5 = popen("z3/build/maxsat src/src/printTest.smt", "r"); pipe = tmp___5; if (! pipe) { return (0); } strcpy((char * __restrict )(result), (char const * __restrict )"\000"); while (1) { tmp___7 = feof(pipe); if (tmp___7) { break; } tmp___6 = fgets((char * __restrict )(buffer), 1000, (FILE * __restrict )pipe); if ((unsigned long )tmp___6 != (unsigned long )((void *)0)) { strcat((char * __restrict )(result), (char const * __restrict )(buffer)); } } pclose(pipe); curr = (currPath->node)->next; save = new_head; if ((int )result[0] != 0) { i___0 = 0; token = strtok((char * __restrict )(result), (char const * __restrict )" "); while ((unsigned long )token != (unsigned long )((void *)0)) { infeasible = atoi((char const *)token); token = strtok((char * __restrict )((void *)0), (char const * __restrict )" "); while (i___0 < infeasible) { new_curr = newNode(curr->id, curr->score, curr->outcome, (char const *)curr->expr, (CDGNode *)((void *)0), (CDGNode *)((void *)0), save, (CDGNode *)((void *)0)); save->next = new_curr; save = new_curr; curr = curr->next; i___0 ++; } if ((unsigned long )((void *)0) == (unsigned long )curr) { break; } curr = curr->next; i___0 ++; } } while ((unsigned long )curr != (unsigned long )((void *)0)) { new_curr = newNode(curr->id, curr->score, curr->outcome, (char const *)curr->expr, (CDGNode *)((void *)0), (CDGNode *)((void *)0), save, (CDGNode *)((void *)0)); save->next = new_curr; save = new_curr; curr = curr->next; } pathNode___0->node = getFeasibleSatNodes(& ctx, pathRank, new_head); pathNode___0->next = newSATPath; newSATPath = pathNode___0; free((void *)condition); return (1); } } int getTestCases(void) { CDGPath *currPath ; CDGNode *curr ; float percent ; float orgPercent ; int atleastOneConditionNotCovered ; int i ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; FILE *coveragefile ; FILE *tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; int tmp___7 ; FILE *coveragefile___0 ; FILE *tmp___8 ; FILE *fp ; FILE *tmp___9 ; int tmp___10 ; int tmp___11 ; int tmp___12 ; int tmp___13 ; int tmp___14 ; { atleastOneConditionNotCovered = 0; i = 0; currPath = newSATPath; tmp = countCoveredConditions(); tmp___0 = countTotalConditions(); percent = (float )((tmp * 100) / (2 * tmp___0)); tmp___1 = countOrgCoveredConditions(); tmp___2 = countOrgTotalConditions(); orgPercent = (float )((tmp___1 * 100) / (2 * tmp___2)); printf((char const * __restrict )"COVERAGE = %f....\n", (double )orgPercent); tmp___3 = fopen((char const * __restrict )"src/src/coverage.txt", (char const * __restrict )"ab+"); coveragefile = tmp___3; fprintf((FILE * __restrict )coveragefile, (char const * __restrict )"%.1f\n", (double )orgPercent); if ((unsigned long )savePath != (unsigned long )((void *)0)) { if (previousCoverage == percent) { countAttempts ++; while ((unsigned long )savePath != (unsigned long )((void *)0)) { if (savePath->id == 0) { break; } updateSidForPath(savePath->id, savePath->outcome); savePath = savePath->next; } } else { totalTestCases ++; countAttempts = 0; } } while (i < pathRank) { currPath = currPath->next; if ((unsigned long )currPath == (unsigned long )((void *)0)) { print_conditions(); tmp___4 = countCoveredConditions(); tmp___5 = countTotalConditions(); percent = (float )((tmp___4 * 100) / (2 * tmp___5)); tmp___6 = countOrgCoveredConditions(); tmp___7 = countOrgTotalConditions(); orgPercent = (float )((tmp___6 * 100) / (2 * tmp___7)); printf((char const * __restrict )"COVERAGE = %f....\n", (double )orgPercent); tmp___8 = fopen((char const * __restrict )"src/src/coverage.txt", (char const * __restrict )"ab+"); coveragefile___0 = tmp___8; fprintf((FILE * __restrict )coveragefile___0, (char const * __restrict )"%.1f\n", (double )orgPercent); CDG_Module = 0; return (0); } i ++; } curr = currPath->node; savePath = currPath->node; remove("src/src/printTest.smt"); getPrint(); writeProgramSVariables(); tmp___9 = fopen((char const * __restrict )"src/src/printTest.smt", (char const * __restrict )"a"); fp = tmp___9; if ((unsigned long )fp == (unsigned long )((void *)0)) { printf((char const * __restrict )"Error opening file!\n"); exit(1); } while ((unsigned long )curr != (unsigned long )((void *)0)) { if (curr->id == 0) { break; } tmp___14 = getOutcome(curr); if (tmp___14) { tmp___10 = checkForAllConstants(curr->expr); if (! tmp___10) { fprintf((FILE * __restrict )fp, (char const * __restrict )" :assumption %s\n", curr->expr); } tmp___11 = getBranchInfo(curr->id, 1); if (! tmp___11) { atleastOneConditionNotCovered = 1; } } else { tmp___12 = checkForAllConstants(curr->expr); if (! tmp___12) { fprintf((FILE * __restrict )fp, (char const * __restrict )" :assumption %s\n", curr->expr); } tmp___13 = getBranchInfo(curr->id, 0); if (! tmp___13) { atleastOneConditionNotCovered = 1; } } curr = curr->next; } fprintf((FILE * __restrict )fp, (char const * __restrict )"%s\n", ")"); fclose(fp); if (atleastOneConditionNotCovered) { getOutputFromConstraintSolver(); } previousCoverage = percent; pathRank ++; delete_allSTableEntry(); delete_allStructTableEntry(); return (1); } } #pragma merger("0","./stack.i","-g,-g") int stackSize(Stack *s ) ; void stackPeek(Stack *s , void *element ) ; Stack *stackNew(int elementSize ) { Stack *s ; void *tmp ; { tmp = malloc(sizeof(Stack )); s = (Stack *)tmp; s->elementSize = elementSize; s->elementsCnt = 0; s->head = (node *)((void *)0); return (s); } } void stackPush(Stack *s , void const *element ) { node *newHead ; void *tmp ; { tmp = malloc(sizeof(node )); newHead = (node *)tmp; if (! ((unsigned long )((void *)0) != (unsigned long )newHead)) { __assert_fail("((void *)0) != newHead", "src/src/stack.c", 15U, "stackPush"); } newHead->element = malloc((size_t )s->elementSize); if (! ((unsigned long )((void *)0) != (unsigned long )newHead->element)) { __assert_fail("((void *)0) != newHead->element", "src/src/stack.c", 17U, "stackPush"); } memcpy((void * __restrict )newHead->element, (void const * __restrict )element, (size_t )s->elementSize); newHead->next = s->head; s->head = newHead; (s->elementsCnt) ++; return; } } void stackPop(Stack *s , void *element ) { int tmp ; node *top ; { tmp = stackIsEmpty(s); if (tmp) { __assert_fail("!stackIsEmpty(s)", "src/src/stack.c", 25U, "stackPop"); } top = s->head; s->head = (s->head)->next; (s->elementsCnt) --; memcpy((void * __restrict )element, (void const * __restrict )top->element, (size_t )s->elementSize); free(top->element); free((void *)top); return; } } int stackIsEmpty(Stack *s ) { { if (0 == s->elementsCnt) { return (1); } return (0); } } void stackFree(Stack *s ) { node *current ; node *next ; { current = s->head; while ((unsigned long )((void *)0) != (unsigned long )current) { next = current->next; free(current->element); free((void *)current); current = next; } s->head = (node *)((void *)0); s->elementsCnt = 0; return; } } int stackSize(Stack *s ) { { return (s->elementsCnt); } } void stackPeek(Stack *s , void *element ) { int tmp ; { tmp = stackIsEmpty(s); if (tmp) { __assert_fail("!stackIsEmpty(s)", "src/src/stack.c", 62U, "stackPeek"); } memcpy((void * __restrict )element, (void const * __restrict )(s->head)->element, (size_t )s->elementSize); return; } } #pragma merger("0","./globalVerifyFunc.i","-g,-g") int whatever_a ; void foo(void) { { if (whatever_a < 0) { whatever_a = -1 * whatever_a; } return; } } void createCDG(void) { { addtoCDGnode(0, 0, 0); addtoCDGnode(1, 0, 1); addtoCDGnode(2, 0, 1); setArray(2, "(= whatever_a -1)"); addtoCDGnode(3, 2, 1); addtoCDGnode(4, 2, 0); addtoCDGnode(5, 0, 1); addtoCDGnode(5, 0, 1); addtoCDGnode(6, 0, 1); } } void isCopyOfHolder(void) { { } } void createSidTable(void) { { add_condition(2, "(= whatever_a -1)", "(not (= whatever_a -1))", 0, 0); } } struct arguments { int whatever_a ; }; struct arguments argvar ; int main1(int whatever_a ) { int b ; int exp_outcome ; int overall_outcome ; int __cil_tmp4 ; char *__cil_tmp5 ; char *symName ; void *addr ; char in[15] ; { __cil_tmp5 = malloc(100 * sizeof(char )); add_entryToSTable("__cil_tmp5", "Function", & __cil_tmp5, & __cil_tmp5, -1); sprintf(__cil_tmp5, "\t%d\n", whatever_a); printTestCase("globalVerifyFunc_main1_1433252497.tc", __cil_tmp5); add_entryToSTable("whatever_a", "s0", & whatever_a, & whatever_a, 1); foo(); { exp_outcome = whatever_a == -1; handleAssignmentSymbolically("exp_outcome", "(= whatever_a -1)", & exp_outcome, & exp_outcome, 1); overall_outcome = (int )getConditionalOutcome(2, exp_outcome); if (overall_outcome) { setBranchInfo(2, 1, 0); setTrueExpr(2, "(= whatever_a -1)"); setFalseExpr(2, "(not (= whatever_a -1))"); addToTree(2, 1, "(= whatever_a -1)", "(not (= whatever_a -1))", 0, 1); delete_allVariableTableEntry(); b = 1; add_entryToSTable("b", "Constant", & b, & b, 1); } else { setBranchInfo(2, 0, 1); setTrueExpr(2, "(= whatever_a -1)"); setFalseExpr(2, "(not (= whatever_a -1))"); addToTree(2, 1, "(= whatever_a -1)", "(not (= whatever_a -1))", 0, 0); delete_allVariableTableEntry(); b = 2; add_entryToSTable("b", "Constant", & b, & b, 1); } } __cil_tmp4 = isNotQueueEmpty(); if (__cil_tmp4) { enQueue(); directPathConditions(); delete_allSTableEntry(); delete_allStructTableEntry(); main1(whatever_a); } else { __cil_tmp4 = startCDG(); add_entryToSTable("__cil_tmp4", "Function", & __cil_tmp4, & __cil_tmp4, 1); if (__cil_tmp4) { __cil_tmp4 = getTestCases(); main1(whatever_a); } } return (0); } } void getPrint(void) { { printFile("(benchmark res\n :logic AUFLIA\n"); } } void callInstrumentedFun(void) { { enQueue(); main1(argvar.whatever_a); } } void main(void) { int whatever_a ; int temp ; int __cil_tmp2 ; { __cil_tmp2 = rand(); argvar.whatever_a = __cil_tmp2 % 20; initSID(); isCopyOfHolder(); createCDG(); createSidTable(); callInstrumentedFun(); } }
the_stack_data/627207.c
#include <stdio.h> #include <stdlib.h> int main() { printf("\nHello, world."); float height, width, area, paint; printf("\nWall height:"); scanf("%f", &height); printf("Wall Width: "); scanf("%f", &width); area = height * width; printf("Wall area: %fm2", area); paint = area / 2; printf("\nYou need %fl to paint the whole wall.", paint); return 0; }
the_stack_data/151704372.c
void _start() { for (;;) ; }
the_stack_data/386186.c
#include <stdio.h> #include <string.h> char s1[1000009], s2[1000009]; int s2_fail[1000009]; void get_fail(int *fail, const char *str); void kmp_cmp(const char *str1, const char *str2); int main(void) { int i; scanf("%s%s", s1, s2); kmp_cmp(s1, s2); for (i = 1; s2[i - 1] != '\0'; ++i) printf("%d ", s2_fail[i]); putchar('\n'); return 0; } void get_fail(int *fail, const char *str) { int i, j; fail[0] = 0; j = fail[0]; for (i = 1; str[i] != '\0'; ++i) { while (j != fail[0] && str[i] != str[j]) j = fail[j]; if (str[i] == str[j]) ++j; fail[i + 1] = j; } } void kmp_cmp(const char *str1, const char *str2) { int i, j, s2len = strlen(str2); get_fail(s2_fail, str2); j = 0; for (i = 0; str1[i] != '\0'; ++i) { while (j != s2_fail[0] && str2[j] != str1[i]) j = s2_fail[j]; if (str1[i] == str2[j]) ++j; if (str2[j] == '\0') printf("%d\n", i - s2len + 2); } }
the_stack_data/46961.c
/** * @file * Error Management module * */ /* * Copyright (c) 2001-2004 Swedish Institute of Computer Science. * 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. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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 file is part of the lwIP TCP/IP stack. * * Author: Adam Dunkels <[email protected]> * */ #ifdef LIBOHIBOARD_ETHERNET_LWIP_1_4_1 #include "lwip/err.h" #ifdef LWIP_DEBUG static const char *err_strerr[] = { "Ok.", /* ERR_OK 0 */ "Out of memory error.", /* ERR_MEM -1 */ "Buffer error.", /* ERR_BUF -2 */ "Timeout.", /* ERR_TIMEOUT -3 */ "Routing problem.", /* ERR_RTE -4 */ "Operation in progress.", /* ERR_INPROGRESS -5 */ "Illegal value.", /* ERR_VAL -6 */ "Operation would block.", /* ERR_WOULDBLOCK -7 */ "Address in use.", /* ERR_USE -8 */ "Already connected.", /* ERR_ISCONN -9 */ "Connection aborted.", /* ERR_ABRT -10 */ "Connection reset.", /* ERR_RST -11 */ "Connection closed.", /* ERR_CLSD -12 */ "Not connected.", /* ERR_CONN -13 */ "Illegal argument.", /* ERR_ARG -14 */ "Low-level netif error.", /* ERR_IF -15 */ }; /** * Convert an lwip internal error to a string representation. * * @param err an lwip internal err_t * @return a string representation for err */ const char * lwip_strerr(err_t err) { return err_strerr[-err]; } #endif /* LWIP_DEBUG */ #endif /* LIBOHIBOARD_ETHERNET_LWIP_1_4_1 */
the_stack_data/100140692.c
// possible deadlock in ovl_write_iter (2) // https://syzkaller.appspot.com/bug?id=54968ebfc84a36152bdd // status:6 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <arpa/inet.h> #include <dirent.h> #include <endian.h> #include <errno.h> #include <fcntl.h> #include <net/if.h> #include <net/if_arp.h> #include <netinet/in.h> #include <pthread.h> #include <sched.h> #include <setjmp.h> #include <signal.h> #include <stdarg.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/ioctl.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/resource.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/syscall.h> #include <sys/time.h> #include <sys/types.h> #include <sys/uio.h> #include <sys/wait.h> #include <time.h> #include <unistd.h> #include <linux/capability.h> #include <linux/futex.h> #include <linux/genetlink.h> #include <linux/if_addr.h> #include <linux/if_ether.h> #include <linux/if_link.h> #include <linux/if_tun.h> #include <linux/in6.h> #include <linux/ip.h> #include <linux/neighbour.h> #include <linux/net.h> #include <linux/netlink.h> #include <linux/rtnetlink.h> #include <linux/tcp.h> #include <linux/veth.h> unsigned long long procid; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_RELAXED)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } struct nlmsg { char* pos; int nesting; struct nlattr* nested[8]; char buf[1024]; }; static struct nlmsg nlmsg; static void netlink_init(struct nlmsg* nlmsg, int typ, int flags, const void* data, int size) { memset(nlmsg, 0, sizeof(*nlmsg)); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf; hdr->nlmsg_type = typ; hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags; memcpy(hdr + 1, data, size); nlmsg->pos = (char*)(hdr + 1) + NLMSG_ALIGN(size); } static void netlink_attr(struct nlmsg* nlmsg, int typ, const void* data, int size) { struct nlattr* attr = (struct nlattr*)nlmsg->pos; attr->nla_len = sizeof(*attr) + size; attr->nla_type = typ; memcpy(attr + 1, data, size); nlmsg->pos += NLMSG_ALIGN(attr->nla_len); } static void netlink_nest(struct nlmsg* nlmsg, int typ) { struct nlattr* attr = (struct nlattr*)nlmsg->pos; attr->nla_type = typ; nlmsg->pos += sizeof(*attr); nlmsg->nested[nlmsg->nesting++] = attr; } static void netlink_done(struct nlmsg* nlmsg) { struct nlattr* attr = nlmsg->nested[--nlmsg->nesting]; attr->nla_len = nlmsg->pos - (char*)attr; } static int netlink_send_ext(struct nlmsg* nlmsg, int sock, uint16_t reply_type, int* reply_len) { if (nlmsg->pos > nlmsg->buf + sizeof(nlmsg->buf) || nlmsg->nesting) exit(1); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf; hdr->nlmsg_len = nlmsg->pos - nlmsg->buf; struct sockaddr_nl addr; memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; unsigned n = sendto(sock, nlmsg->buf, hdr->nlmsg_len, 0, (struct sockaddr*)&addr, sizeof(addr)); if (n != hdr->nlmsg_len) exit(1); n = recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); if (hdr->nlmsg_type == NLMSG_DONE) { *reply_len = 0; return 0; } if (n < sizeof(struct nlmsghdr)) exit(1); if (reply_len && hdr->nlmsg_type == reply_type) { *reply_len = n; return 0; } if (n < sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr)) exit(1); if (hdr->nlmsg_type != NLMSG_ERROR) exit(1); return -((struct nlmsgerr*)(hdr + 1))->error; } static int netlink_send(struct nlmsg* nlmsg, int sock) { return netlink_send_ext(nlmsg, sock, 0, NULL); } static int netlink_next_msg(struct nlmsg* nlmsg, unsigned int offset, unsigned int total_len) { struct nlmsghdr* hdr = (struct nlmsghdr*)(nlmsg->buf + offset); if (offset == total_len || offset + hdr->nlmsg_len > total_len) return -1; return hdr->nlmsg_len; } static void netlink_add_device_impl(struct nlmsg* nlmsg, const char* type, const char* name) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); netlink_init(nlmsg, RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr)); if (name) netlink_attr(nlmsg, IFLA_IFNAME, name, strlen(name)); netlink_nest(nlmsg, IFLA_LINKINFO); netlink_attr(nlmsg, IFLA_INFO_KIND, type, strlen(type)); } static void netlink_add_device(struct nlmsg* nlmsg, int sock, const char* type, const char* name) { netlink_add_device_impl(nlmsg, type, name); netlink_done(nlmsg); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_add_veth(struct nlmsg* nlmsg, int sock, const char* name, const char* peer) { netlink_add_device_impl(nlmsg, "veth", name); netlink_nest(nlmsg, IFLA_INFO_DATA); netlink_nest(nlmsg, VETH_INFO_PEER); nlmsg->pos += sizeof(struct ifinfomsg); netlink_attr(nlmsg, IFLA_IFNAME, peer, strlen(peer)); netlink_done(nlmsg); netlink_done(nlmsg); netlink_done(nlmsg); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_add_hsr(struct nlmsg* nlmsg, int sock, const char* name, const char* slave1, const char* slave2) { netlink_add_device_impl(nlmsg, "hsr", name); netlink_nest(nlmsg, IFLA_INFO_DATA); int ifindex1 = if_nametoindex(slave1); netlink_attr(nlmsg, IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1)); int ifindex2 = if_nametoindex(slave2); netlink_attr(nlmsg, IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2)); netlink_done(nlmsg); netlink_done(nlmsg); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_add_linked(struct nlmsg* nlmsg, int sock, const char* type, const char* name, const char* link) { netlink_add_device_impl(nlmsg, type, name); netlink_done(nlmsg); int ifindex = if_nametoindex(link); netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex)); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_add_vlan(struct nlmsg* nlmsg, int sock, const char* name, const char* link, uint16_t id, uint16_t proto) { netlink_add_device_impl(nlmsg, "vlan", name); netlink_nest(nlmsg, IFLA_INFO_DATA); netlink_attr(nlmsg, IFLA_VLAN_ID, &id, sizeof(id)); netlink_attr(nlmsg, IFLA_VLAN_PROTOCOL, &proto, sizeof(proto)); netlink_done(nlmsg); netlink_done(nlmsg); int ifindex = if_nametoindex(link); netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex)); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_add_macvlan(struct nlmsg* nlmsg, int sock, const char* name, const char* link) { netlink_add_device_impl(nlmsg, "macvlan", name); netlink_nest(nlmsg, IFLA_INFO_DATA); uint32_t mode = MACVLAN_MODE_BRIDGE; netlink_attr(nlmsg, IFLA_MACVLAN_MODE, &mode, sizeof(mode)); netlink_done(nlmsg); netlink_done(nlmsg); int ifindex = if_nametoindex(link); netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex)); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_add_geneve(struct nlmsg* nlmsg, int sock, const char* name, uint32_t vni, struct in_addr* addr4, struct in6_addr* addr6) { netlink_add_device_impl(nlmsg, "geneve", name); netlink_nest(nlmsg, IFLA_INFO_DATA); netlink_attr(nlmsg, IFLA_GENEVE_ID, &vni, sizeof(vni)); if (addr4) netlink_attr(nlmsg, IFLA_GENEVE_REMOTE, addr4, sizeof(*addr4)); if (addr6) netlink_attr(nlmsg, IFLA_GENEVE_REMOTE6, addr6, sizeof(*addr6)); netlink_done(nlmsg); netlink_done(nlmsg); int err = netlink_send(nlmsg, sock); (void)err; } #define IFLA_IPVLAN_FLAGS 2 #define IPVLAN_MODE_L3S 2 #undef IPVLAN_F_VEPA #define IPVLAN_F_VEPA 2 static void netlink_add_ipvlan(struct nlmsg* nlmsg, int sock, const char* name, const char* link, uint16_t mode, uint16_t flags) { netlink_add_device_impl(nlmsg, "ipvlan", name); netlink_nest(nlmsg, IFLA_INFO_DATA); netlink_attr(nlmsg, IFLA_IPVLAN_MODE, &mode, sizeof(mode)); netlink_attr(nlmsg, IFLA_IPVLAN_FLAGS, &flags, sizeof(flags)); netlink_done(nlmsg); netlink_done(nlmsg); int ifindex = if_nametoindex(link); netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex)); int err = netlink_send(nlmsg, sock); (void)err; } static void netlink_device_change(struct nlmsg* nlmsg, int sock, const char* name, bool up, const char* master, const void* mac, int macsize, const char* new_name) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); if (up) hdr.ifi_flags = hdr.ifi_change = IFF_UP; hdr.ifi_index = if_nametoindex(name); netlink_init(nlmsg, RTM_NEWLINK, 0, &hdr, sizeof(hdr)); if (new_name) netlink_attr(nlmsg, IFLA_IFNAME, new_name, strlen(new_name)); if (master) { int ifindex = if_nametoindex(master); netlink_attr(nlmsg, IFLA_MASTER, &ifindex, sizeof(ifindex)); } if (macsize) netlink_attr(nlmsg, IFLA_ADDRESS, mac, macsize); int err = netlink_send(nlmsg, sock); (void)err; } static int netlink_add_addr(struct nlmsg* nlmsg, int sock, const char* dev, const void* addr, int addrsize) { struct ifaddrmsg hdr; memset(&hdr, 0, sizeof(hdr)); hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6; hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120; hdr.ifa_scope = RT_SCOPE_UNIVERSE; hdr.ifa_index = if_nametoindex(dev); netlink_init(nlmsg, RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr, sizeof(hdr)); netlink_attr(nlmsg, IFA_LOCAL, addr, addrsize); netlink_attr(nlmsg, IFA_ADDRESS, addr, addrsize); return netlink_send(nlmsg, sock); } static void netlink_add_addr4(struct nlmsg* nlmsg, int sock, const char* dev, const char* addr) { struct in_addr in_addr; inet_pton(AF_INET, addr, &in_addr); int err = netlink_add_addr(nlmsg, sock, dev, &in_addr, sizeof(in_addr)); (void)err; } static void netlink_add_addr6(struct nlmsg* nlmsg, int sock, const char* dev, const char* addr) { struct in6_addr in6_addr; inet_pton(AF_INET6, addr, &in6_addr); int err = netlink_add_addr(nlmsg, sock, dev, &in6_addr, sizeof(in6_addr)); (void)err; } static void netlink_add_neigh(struct nlmsg* nlmsg, int sock, const char* name, const void* addr, int addrsize, const void* mac, int macsize) { struct ndmsg hdr; memset(&hdr, 0, sizeof(hdr)); hdr.ndm_family = addrsize == 4 ? AF_INET : AF_INET6; hdr.ndm_ifindex = if_nametoindex(name); hdr.ndm_state = NUD_PERMANENT; netlink_init(nlmsg, RTM_NEWNEIGH, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr)); netlink_attr(nlmsg, NDA_DST, addr, addrsize); netlink_attr(nlmsg, NDA_LLADDR, mac, macsize); int err = netlink_send(nlmsg, sock); (void)err; } static int tunfd = -1; static int tun_frags_enabled; #define TUN_IFACE "syz_tun" #define LOCAL_MAC 0xaaaaaaaaaaaa #define REMOTE_MAC 0xaaaaaaaaaabb #define LOCAL_IPV4 "172.20.20.170" #define REMOTE_IPV4 "172.20.20.187" #define LOCAL_IPV6 "fe80::aa" #define REMOTE_IPV6 "fe80::bb" #define IFF_NAPI 0x0010 #define IFF_NAPI_FRAGS 0x0020 static void initialize_tun(void) { tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK); if (tunfd == -1) { printf("tun: can't open /dev/net/tun: please enable CONFIG_TUN=y\n"); printf("otherwise fuzzing or reproducing might not work as intended\n"); return; } const int kTunFd = 240; if (dup2(tunfd, kTunFd) < 0) exit(1); close(tunfd); tunfd = kTunFd; struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, TUN_IFACE, IFNAMSIZ); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) { exit(1); } char sysctl[64]; sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/accept_dad", TUN_IFACE); write_file(sysctl, "0"); sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/router_solicitations", TUN_IFACE); write_file(sysctl, "0"); int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); netlink_add_addr4(&nlmsg, sock, TUN_IFACE, LOCAL_IPV4); netlink_add_addr6(&nlmsg, sock, TUN_IFACE, LOCAL_IPV6); uint64_t macaddr = REMOTE_MAC; struct in_addr in_addr; inet_pton(AF_INET, REMOTE_IPV4, &in_addr); netlink_add_neigh(&nlmsg, sock, TUN_IFACE, &in_addr, sizeof(in_addr), &macaddr, ETH_ALEN); struct in6_addr in6_addr; inet_pton(AF_INET6, REMOTE_IPV6, &in6_addr); netlink_add_neigh(&nlmsg, sock, TUN_IFACE, &in6_addr, sizeof(in6_addr), &macaddr, ETH_ALEN); macaddr = LOCAL_MAC; netlink_device_change(&nlmsg, sock, TUN_IFACE, true, 0, &macaddr, ETH_ALEN, NULL); close(sock); } const int kInitNetNsFd = 239; #define DEVLINK_FAMILY_NAME "devlink" #define DEVLINK_CMD_PORT_GET 5 #define DEVLINK_CMD_RELOAD 37 #define DEVLINK_ATTR_BUS_NAME 1 #define DEVLINK_ATTR_DEV_NAME 2 #define DEVLINK_ATTR_NETDEV_NAME 7 #define DEVLINK_ATTR_NETNS_FD 138 static int netlink_devlink_id_get(struct nlmsg* nlmsg, int sock) { struct genlmsghdr genlhdr; struct nlattr* attr; int err, n; uint16_t id = 0; memset(&genlhdr, 0, sizeof(genlhdr)); genlhdr.cmd = CTRL_CMD_GETFAMILY; netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, DEVLINK_FAMILY_NAME, strlen(DEVLINK_FAMILY_NAME) + 1); err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n); if (err) { return -1; } attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(genlhdr))); for (; (char*)attr < nlmsg->buf + n; attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) { if (attr->nla_type == CTRL_ATTR_FAMILY_ID) { id = *(uint16_t*)(attr + 1); break; } } if (!id) { return -1; } recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); /* recv ack */ return id; } static void netlink_devlink_netns_move(const char* bus_name, const char* dev_name, int netns_fd) { struct genlmsghdr genlhdr; int sock; int id, err; sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (sock == -1) exit(1); id = netlink_devlink_id_get(&nlmsg, sock); if (id == -1) goto error; memset(&genlhdr, 0, sizeof(genlhdr)); genlhdr.cmd = DEVLINK_CMD_RELOAD; netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(&nlmsg, DEVLINK_ATTR_BUS_NAME, bus_name, strlen(bus_name) + 1); netlink_attr(&nlmsg, DEVLINK_ATTR_DEV_NAME, dev_name, strlen(dev_name) + 1); netlink_attr(&nlmsg, DEVLINK_ATTR_NETNS_FD, &netns_fd, sizeof(netns_fd)); err = netlink_send(&nlmsg, sock); if (err) { } error: close(sock); } static struct nlmsg nlmsg2; static void initialize_devlink_ports(const char* bus_name, const char* dev_name, const char* netdev_prefix) { struct genlmsghdr genlhdr; int len, total_len, id, err, offset; uint16_t netdev_index; int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (sock == -1) exit(1); int rtsock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (rtsock == -1) exit(1); id = netlink_devlink_id_get(&nlmsg, sock); if (id == -1) goto error; memset(&genlhdr, 0, sizeof(genlhdr)); genlhdr.cmd = DEVLINK_CMD_PORT_GET; netlink_init(&nlmsg, id, NLM_F_DUMP, &genlhdr, sizeof(genlhdr)); netlink_attr(&nlmsg, DEVLINK_ATTR_BUS_NAME, bus_name, strlen(bus_name) + 1); netlink_attr(&nlmsg, DEVLINK_ATTR_DEV_NAME, dev_name, strlen(dev_name) + 1); err = netlink_send_ext(&nlmsg, sock, id, &total_len); if (err) { goto error; } offset = 0; netdev_index = 0; while ((len = netlink_next_msg(&nlmsg, offset, total_len)) != -1) { struct nlattr* attr = (struct nlattr*)(nlmsg.buf + offset + NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(genlhdr))); for (; (char*)attr < nlmsg.buf + offset + len; attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) { if (attr->nla_type == DEVLINK_ATTR_NETDEV_NAME) { char* port_name; char netdev_name[IFNAMSIZ]; port_name = (char*)(attr + 1); snprintf(netdev_name, sizeof(netdev_name), "%s%d", netdev_prefix, netdev_index); netlink_device_change(&nlmsg2, rtsock, port_name, true, 0, 0, 0, netdev_name); break; } } offset += len; netdev_index++; } error: close(rtsock); close(sock); } static void initialize_devlink_pci(void) { int netns = open("/proc/self/ns/net", O_RDONLY); if (netns == -1) exit(1); int ret = setns(kInitNetNsFd, 0); if (ret == -1) exit(1); netlink_devlink_netns_move("pci", "0000:00:10.0", netns); ret = setns(netns, 0); if (ret == -1) exit(1); close(netns); initialize_devlink_ports("pci", "0000:00:10.0", "netpci"); } #define DEV_IPV4 "172.20.20.%d" #define DEV_IPV6 "fe80::%02x" #define DEV_MAC 0x00aaaaaaaaaa static void netdevsim_add(unsigned int addr, unsigned int port_count) { char buf[16]; sprintf(buf, "%u %u", addr, port_count); if (write_file("/sys/bus/netdevsim/new_device", buf)) { snprintf(buf, sizeof(buf), "netdevsim%d", addr); initialize_devlink_ports("netdevsim", buf, "netdevsim"); } } #define WG_GENL_NAME "wireguard" enum wg_cmd { WG_CMD_GET_DEVICE, WG_CMD_SET_DEVICE, }; enum wgdevice_attribute { WGDEVICE_A_UNSPEC, WGDEVICE_A_IFINDEX, WGDEVICE_A_IFNAME, WGDEVICE_A_PRIVATE_KEY, WGDEVICE_A_PUBLIC_KEY, WGDEVICE_A_FLAGS, WGDEVICE_A_LISTEN_PORT, WGDEVICE_A_FWMARK, WGDEVICE_A_PEERS, }; enum wgpeer_attribute { WGPEER_A_UNSPEC, WGPEER_A_PUBLIC_KEY, WGPEER_A_PRESHARED_KEY, WGPEER_A_FLAGS, WGPEER_A_ENDPOINT, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, WGPEER_A_LAST_HANDSHAKE_TIME, WGPEER_A_RX_BYTES, WGPEER_A_TX_BYTES, WGPEER_A_ALLOWEDIPS, WGPEER_A_PROTOCOL_VERSION, }; enum wgallowedip_attribute { WGALLOWEDIP_A_UNSPEC, WGALLOWEDIP_A_FAMILY, WGALLOWEDIP_A_IPADDR, WGALLOWEDIP_A_CIDR_MASK, }; static int netlink_wireguard_id_get(struct nlmsg* nlmsg, int sock) { struct genlmsghdr genlhdr; struct nlattr* attr; int err, n; uint16_t id = 0; memset(&genlhdr, 0, sizeof(genlhdr)); genlhdr.cmd = CTRL_CMD_GETFAMILY; netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, WG_GENL_NAME, strlen(WG_GENL_NAME) + 1); err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n); if (err) { return -1; } attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(genlhdr))); for (; (char*)attr < nlmsg->buf + n; attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) { if (attr->nla_type == CTRL_ATTR_FAMILY_ID) { id = *(uint16_t*)(attr + 1); break; } } if (!id) { return -1; } recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); /* recv ack */ return id; } static void netlink_wireguard_setup(void) { const char ifname_a[] = "wg0"; const char ifname_b[] = "wg1"; const char ifname_c[] = "wg2"; const char private_a[] = "\xa0\x5c\xa8\x4f\x6c\x9c\x8e\x38\x53\xe2\xfd\x7a\x70\xae\x0f\xb2\x0f\xa1" "\x52\x60\x0c\xb0\x08\x45\x17\x4f\x08\x07\x6f\x8d\x78\x43"; const char private_b[] = "\xb0\x80\x73\xe8\xd4\x4e\x91\xe3\xda\x92\x2c\x22\x43\x82\x44\xbb\x88\x5c" "\x69\xe2\x69\xc8\xe9\xd8\x35\xb1\x14\x29\x3a\x4d\xdc\x6e"; const char private_c[] = "\xa0\xcb\x87\x9a\x47\xf5\xbc\x64\x4c\x0e\x69\x3f\xa6\xd0\x31\xc7\x4a\x15" "\x53\xb6\xe9\x01\xb9\xff\x2f\x51\x8c\x78\x04\x2f\xb5\x42"; const char public_a[] = "\x97\x5c\x9d\x81\xc9\x83\xc8\x20\x9e\xe7\x81\x25\x4b\x89\x9f\x8e\xd9\x25" "\xae\x9f\x09\x23\xc2\x3c\x62\xf5\x3c\x57\xcd\xbf\x69\x1c"; const char public_b[] = "\xd1\x73\x28\x99\xf6\x11\xcd\x89\x94\x03\x4d\x7f\x41\x3d\xc9\x57\x63\x0e" "\x54\x93\xc2\x85\xac\xa4\x00\x65\xcb\x63\x11\xbe\x69\x6b"; const char public_c[] = "\xf4\x4d\xa3\x67\xa8\x8e\xe6\x56\x4f\x02\x02\x11\x45\x67\x27\x08\x2f\x5c" "\xeb\xee\x8b\x1b\xf5\xeb\x73\x37\x34\x1b\x45\x9b\x39\x22"; const uint16_t listen_a = 20001; const uint16_t listen_b = 20002; const uint16_t listen_c = 20003; const uint16_t af_inet = AF_INET; const uint16_t af_inet6 = AF_INET6; /* Unused, but useful in case we change this: const struct sockaddr_in endpoint_a_v4 = { .sin_family = AF_INET, .sin_port = htons(listen_a), .sin_addr = {htonl(INADDR_LOOPBACK)}};*/ const struct sockaddr_in endpoint_b_v4 = { .sin_family = AF_INET, .sin_port = htons(listen_b), .sin_addr = {htonl(INADDR_LOOPBACK)}}; const struct sockaddr_in endpoint_c_v4 = { .sin_family = AF_INET, .sin_port = htons(listen_c), .sin_addr = {htonl(INADDR_LOOPBACK)}}; struct sockaddr_in6 endpoint_a_v6 = {.sin6_family = AF_INET6, .sin6_port = htons(listen_a)}; endpoint_a_v6.sin6_addr = in6addr_loopback; /* Unused, but useful in case we change this: const struct sockaddr_in6 endpoint_b_v6 = { .sin6_family = AF_INET6, .sin6_port = htons(listen_b)}; endpoint_b_v6.sin6_addr = in6addr_loopback; */ struct sockaddr_in6 endpoint_c_v6 = {.sin6_family = AF_INET6, .sin6_port = htons(listen_c)}; endpoint_c_v6.sin6_addr = in6addr_loopback; const struct in_addr first_half_v4 = {0}; const struct in_addr second_half_v4 = {htonl(128 << 24)}; const struct in6_addr first_half_v6 = {{{0}}}; const struct in6_addr second_half_v6 = {{{0x80}}}; const uint8_t half_cidr = 1; const uint16_t persistent_keepalives[] = {1, 3, 7, 9, 14, 19}; struct genlmsghdr genlhdr = {.cmd = WG_CMD_SET_DEVICE, .version = 1}; int sock; int id, err; sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (sock == -1) { return; } id = netlink_wireguard_id_get(&nlmsg, sock); if (id == -1) goto error; netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_a, strlen(ifname_a) + 1); netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_a, 32); netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_a, 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32); netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4, sizeof(endpoint_b_v4)); netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, &persistent_keepalives[0], 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4, sizeof(first_half_v4)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6, sizeof(first_half_v6)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32); netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v6, sizeof(endpoint_c_v6)); netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, &persistent_keepalives[1], 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4, sizeof(second_half_v4)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6, sizeof(second_half_v6)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); err = netlink_send(&nlmsg, sock); if (err) { } netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_b, strlen(ifname_b) + 1); netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_b, 32); netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_b, 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32); netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6, sizeof(endpoint_a_v6)); netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, &persistent_keepalives[2], 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4, sizeof(first_half_v4)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6, sizeof(first_half_v6)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32); netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v4, sizeof(endpoint_c_v4)); netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, &persistent_keepalives[3], 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4, sizeof(second_half_v4)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6, sizeof(second_half_v6)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); err = netlink_send(&nlmsg, sock); if (err) { } netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_c, strlen(ifname_c) + 1); netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_c, 32); netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_c, 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32); netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6, sizeof(endpoint_a_v6)); netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, &persistent_keepalives[4], 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4, sizeof(first_half_v4)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6, sizeof(first_half_v6)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32); netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4, sizeof(endpoint_b_v4)); netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, &persistent_keepalives[5], 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4, sizeof(second_half_v4)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6, sizeof(second_half_v6)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); err = netlink_send(&nlmsg, sock); if (err) { } error: close(sock); } static void initialize_netdevices(void) { char netdevsim[16]; sprintf(netdevsim, "netdevsim%d", (int)procid); struct { const char* type; const char* dev; } devtypes[] = { {"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"}, {"vcan", "vcan0"}, {"bond", "bond0"}, {"team", "team0"}, {"dummy", "dummy0"}, {"nlmon", "nlmon0"}, {"caif", "caif0"}, {"batadv", "batadv0"}, {"vxcan", "vxcan1"}, {"netdevsim", netdevsim}, {"veth", 0}, {"xfrm", "xfrm0"}, {"wireguard", "wg0"}, {"wireguard", "wg1"}, {"wireguard", "wg2"}, }; const char* devmasters[] = {"bridge", "bond", "team", "batadv"}; struct { const char* name; int macsize; bool noipv6; } devices[] = { {"lo", ETH_ALEN}, {"sit0", 0}, {"bridge0", ETH_ALEN}, {"vcan0", 0, true}, {"tunl0", 0}, {"gre0", 0}, {"gretap0", ETH_ALEN}, {"ip_vti0", 0}, {"ip6_vti0", 0}, {"ip6tnl0", 0}, {"ip6gre0", 0}, {"ip6gretap0", ETH_ALEN}, {"erspan0", ETH_ALEN}, {"bond0", ETH_ALEN}, {"veth0", ETH_ALEN}, {"veth1", ETH_ALEN}, {"team0", ETH_ALEN}, {"veth0_to_bridge", ETH_ALEN}, {"veth1_to_bridge", ETH_ALEN}, {"veth0_to_bond", ETH_ALEN}, {"veth1_to_bond", ETH_ALEN}, {"veth0_to_team", ETH_ALEN}, {"veth1_to_team", ETH_ALEN}, {"veth0_to_hsr", ETH_ALEN}, {"veth1_to_hsr", ETH_ALEN}, {"hsr0", 0}, {"dummy0", ETH_ALEN}, {"nlmon0", 0}, {"vxcan0", 0, true}, {"vxcan1", 0, true}, {"caif0", ETH_ALEN}, {"batadv0", ETH_ALEN}, {netdevsim, ETH_ALEN}, {"xfrm0", ETH_ALEN}, {"veth0_virt_wifi", ETH_ALEN}, {"veth1_virt_wifi", ETH_ALEN}, {"virt_wifi0", ETH_ALEN}, {"veth0_vlan", ETH_ALEN}, {"veth1_vlan", ETH_ALEN}, {"vlan0", ETH_ALEN}, {"vlan1", ETH_ALEN}, {"macvlan0", ETH_ALEN}, {"macvlan1", ETH_ALEN}, {"ipvlan0", ETH_ALEN}, {"ipvlan1", ETH_ALEN}, {"veth0_macvtap", ETH_ALEN}, {"veth1_macvtap", ETH_ALEN}, {"macvtap0", ETH_ALEN}, {"macsec0", ETH_ALEN}, {"veth0_to_batadv", ETH_ALEN}, {"veth1_to_batadv", ETH_ALEN}, {"batadv_slave_0", ETH_ALEN}, {"batadv_slave_1", ETH_ALEN}, {"geneve0", ETH_ALEN}, {"geneve1", ETH_ALEN}, {"wg0", 0}, {"wg1", 0}, {"wg2", 0}, }; int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) netlink_add_device(&nlmsg, sock, devtypes[i].type, devtypes[i].dev); for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) { char master[32], slave0[32], veth0[32], slave1[32], veth1[32]; sprintf(slave0, "%s_slave_0", devmasters[i]); sprintf(veth0, "veth0_to_%s", devmasters[i]); netlink_add_veth(&nlmsg, sock, slave0, veth0); sprintf(slave1, "%s_slave_1", devmasters[i]); sprintf(veth1, "veth1_to_%s", devmasters[i]); netlink_add_veth(&nlmsg, sock, slave1, veth1); sprintf(master, "%s0", devmasters[i]); netlink_device_change(&nlmsg, sock, slave0, false, master, 0, 0, NULL); netlink_device_change(&nlmsg, sock, slave1, false, master, 0, 0, NULL); } netlink_device_change(&nlmsg, sock, "bridge_slave_0", true, 0, 0, 0, NULL); netlink_device_change(&nlmsg, sock, "bridge_slave_1", true, 0, 0, 0, NULL); netlink_add_veth(&nlmsg, sock, "hsr_slave_0", "veth0_to_hsr"); netlink_add_veth(&nlmsg, sock, "hsr_slave_1", "veth1_to_hsr"); netlink_add_hsr(&nlmsg, sock, "hsr0", "hsr_slave_0", "hsr_slave_1"); netlink_device_change(&nlmsg, sock, "hsr_slave_0", true, 0, 0, 0, NULL); netlink_device_change(&nlmsg, sock, "hsr_slave_1", true, 0, 0, 0, NULL); netlink_add_veth(&nlmsg, sock, "veth0_virt_wifi", "veth1_virt_wifi"); netlink_add_linked(&nlmsg, sock, "virt_wifi", "virt_wifi0", "veth1_virt_wifi"); netlink_add_veth(&nlmsg, sock, "veth0_vlan", "veth1_vlan"); netlink_add_vlan(&nlmsg, sock, "vlan0", "veth0_vlan", 0, htons(ETH_P_8021Q)); netlink_add_vlan(&nlmsg, sock, "vlan1", "veth0_vlan", 1, htons(ETH_P_8021AD)); netlink_add_macvlan(&nlmsg, sock, "macvlan0", "veth1_vlan"); netlink_add_macvlan(&nlmsg, sock, "macvlan1", "veth1_vlan"); netlink_add_ipvlan(&nlmsg, sock, "ipvlan0", "veth0_vlan", IPVLAN_MODE_L2, 0); netlink_add_ipvlan(&nlmsg, sock, "ipvlan1", "veth0_vlan", IPVLAN_MODE_L3S, IPVLAN_F_VEPA); netlink_add_veth(&nlmsg, sock, "veth0_macvtap", "veth1_macvtap"); netlink_add_linked(&nlmsg, sock, "macvtap", "macvtap0", "veth0_macvtap"); netlink_add_linked(&nlmsg, sock, "macsec", "macsec0", "veth1_macvtap"); char addr[32]; sprintf(addr, DEV_IPV4, 14 + 10); struct in_addr geneve_addr4; if (inet_pton(AF_INET, addr, &geneve_addr4) <= 0) exit(1); struct in6_addr geneve_addr6; if (inet_pton(AF_INET6, "fc00::01", &geneve_addr6) <= 0) exit(1); netlink_add_geneve(&nlmsg, sock, "geneve0", 0, &geneve_addr4, 0); netlink_add_geneve(&nlmsg, sock, "geneve1", 1, 0, &geneve_addr6); netdevsim_add((int)procid, 4); netlink_wireguard_setup(); for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) { char addr[32]; sprintf(addr, DEV_IPV4, i + 10); netlink_add_addr4(&nlmsg, sock, devices[i].name, addr); if (!devices[i].noipv6) { sprintf(addr, DEV_IPV6, i + 10); netlink_add_addr6(&nlmsg, sock, devices[i].name, addr); } uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40); netlink_device_change(&nlmsg, sock, devices[i].name, true, 0, &macaddr, devices[i].macsize, NULL); } close(sock); } static void initialize_netdevices_init(void) { int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); struct { const char* type; int macsize; bool noipv6; bool noup; } devtypes[] = { {"nr", 7, true}, {"rose", 5, true, true}, }; unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) { char dev[32], addr[32]; sprintf(dev, "%s%d", devtypes[i].type, (int)procid); sprintf(addr, "172.30.%d.%d", i, (int)procid + 1); netlink_add_addr4(&nlmsg, sock, dev, addr); if (!devtypes[i].noipv6) { sprintf(addr, "fe88::%02x:%02x", i, (int)procid + 1); netlink_add_addr6(&nlmsg, sock, dev, addr); } int macsize = devtypes[i].macsize; uint64_t macaddr = 0xbbbbbb + ((unsigned long long)i << (8 * (macsize - 2))) + (procid << (8 * (macsize - 1))); netlink_device_change(&nlmsg, sock, dev, !devtypes[i].noup, 0, &macaddr, macsize, NULL); } close(sock); } static int read_tun(char* data, int size) { if (tunfd < 0) return -1; int rv = read(tunfd, data, size); if (rv < 0) { if (errno == EAGAIN) return -1; if (errno == EBADFD) return -1; exit(1); } return rv; } static void flush_tun() { char data[1000]; while (read_tun(&data[0], sizeof(data)) != -1) { } } #define MAX_FDS 30 #define XT_TABLE_SIZE 1536 #define XT_MAX_ENTRIES 10 struct xt_counters { uint64_t pcnt, bcnt; }; struct ipt_getinfo { char name[32]; unsigned int valid_hooks; unsigned int hook_entry[5]; unsigned int underflow[5]; unsigned int num_entries; unsigned int size; }; struct ipt_get_entries { char name[32]; unsigned int size; void* entrytable[XT_TABLE_SIZE / sizeof(void*)]; }; struct ipt_replace { char name[32]; unsigned int valid_hooks; unsigned int num_entries; unsigned int size; unsigned int hook_entry[5]; unsigned int underflow[5]; unsigned int num_counters; struct xt_counters* counters; char entrytable[XT_TABLE_SIZE]; }; struct ipt_table_desc { const char* name; struct ipt_getinfo info; struct ipt_replace replace; }; static struct ipt_table_desc ipv4_tables[] = { {.name = "filter"}, {.name = "nat"}, {.name = "mangle"}, {.name = "raw"}, {.name = "security"}, }; static struct ipt_table_desc ipv6_tables[] = { {.name = "filter"}, {.name = "nat"}, {.name = "mangle"}, {.name = "raw"}, {.name = "security"}, }; #define IPT_BASE_CTL 64 #define IPT_SO_SET_REPLACE (IPT_BASE_CTL) #define IPT_SO_GET_INFO (IPT_BASE_CTL) #define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1) struct arpt_getinfo { char name[32]; unsigned int valid_hooks; unsigned int hook_entry[3]; unsigned int underflow[3]; unsigned int num_entries; unsigned int size; }; struct arpt_get_entries { char name[32]; unsigned int size; void* entrytable[XT_TABLE_SIZE / sizeof(void*)]; }; struct arpt_replace { char name[32]; unsigned int valid_hooks; unsigned int num_entries; unsigned int size; unsigned int hook_entry[3]; unsigned int underflow[3]; unsigned int num_counters; struct xt_counters* counters; char entrytable[XT_TABLE_SIZE]; }; struct arpt_table_desc { const char* name; struct arpt_getinfo info; struct arpt_replace replace; }; static struct arpt_table_desc arpt_tables[] = { {.name = "filter"}, }; #define ARPT_BASE_CTL 96 #define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL) #define ARPT_SO_GET_INFO (ARPT_BASE_CTL) #define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1) static void checkpoint_iptables(struct ipt_table_desc* tables, int num_tables, int family, int level) { struct ipt_get_entries entries; socklen_t optlen; int fd, i; fd = socket(family, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < num_tables; i++) { struct ipt_table_desc* table = &tables[i]; strcpy(table->info.name, table->name); strcpy(table->replace.name, table->name); optlen = sizeof(table->info); if (getsockopt(fd, level, IPT_SO_GET_INFO, &table->info, &optlen)) { switch (errno) { case EPERM: case ENOENT: case ENOPROTOOPT: continue; } exit(1); } if (table->info.size > sizeof(table->replace.entrytable)) exit(1); if (table->info.num_entries > XT_MAX_ENTRIES) exit(1); memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size; if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); table->replace.valid_hooks = table->info.valid_hooks; table->replace.num_entries = table->info.num_entries; table->replace.size = table->info.size; memcpy(table->replace.hook_entry, table->info.hook_entry, sizeof(table->replace.hook_entry)); memcpy(table->replace.underflow, table->info.underflow, sizeof(table->replace.underflow)); memcpy(table->replace.entrytable, entries.entrytable, table->info.size); } close(fd); } static void reset_iptables(struct ipt_table_desc* tables, int num_tables, int family, int level) { struct xt_counters counters[XT_MAX_ENTRIES]; struct ipt_get_entries entries; struct ipt_getinfo info; socklen_t optlen; int fd, i; fd = socket(family, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < num_tables; i++) { struct ipt_table_desc* table = &tables[i]; if (table->info.valid_hooks == 0) continue; memset(&info, 0, sizeof(info)); strcpy(info.name, table->name); optlen = sizeof(info); if (getsockopt(fd, level, IPT_SO_GET_INFO, &info, &optlen)) exit(1); if (memcmp(&table->info, &info, sizeof(table->info)) == 0) { memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size; if (getsockopt(fd, level, IPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); if (memcmp(table->replace.entrytable, entries.entrytable, table->info.size) == 0) continue; } table->replace.num_counters = info.num_entries; table->replace.counters = counters; optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) + table->replace.size; if (setsockopt(fd, level, IPT_SO_SET_REPLACE, &table->replace, optlen)) exit(1); } close(fd); } static void checkpoint_arptables(void) { struct arpt_get_entries entries; socklen_t optlen; unsigned i; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) { struct arpt_table_desc* table = &arpt_tables[i]; strcpy(table->info.name, table->name); strcpy(table->replace.name, table->name); optlen = sizeof(table->info); if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &table->info, &optlen)) { switch (errno) { case EPERM: case ENOENT: case ENOPROTOOPT: continue; } exit(1); } if (table->info.size > sizeof(table->replace.entrytable)) exit(1); if (table->info.num_entries > XT_MAX_ENTRIES) exit(1); memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + table->info.size; if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); table->replace.valid_hooks = table->info.valid_hooks; table->replace.num_entries = table->info.num_entries; table->replace.size = table->info.size; memcpy(table->replace.hook_entry, table->info.hook_entry, sizeof(table->replace.hook_entry)); memcpy(table->replace.underflow, table->info.underflow, sizeof(table->replace.underflow)); memcpy(table->replace.entrytable, entries.entrytable, table->info.size); } close(fd); } static void reset_arptables() { struct xt_counters counters[XT_MAX_ENTRIES]; struct arpt_get_entries entries; struct arpt_getinfo info; socklen_t optlen; unsigned i; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(arpt_tables) / sizeof(arpt_tables[0]); i++) { struct arpt_table_desc* table = &arpt_tables[i]; if (table->info.valid_hooks == 0) continue; memset(&info, 0, sizeof(info)); strcpy(info.name, table->name); optlen = sizeof(info); if (getsockopt(fd, SOL_IP, ARPT_SO_GET_INFO, &info, &optlen)) exit(1); if (memcmp(&table->info, &info, sizeof(table->info)) == 0) { memset(&entries, 0, sizeof(entries)); strcpy(entries.name, table->name); entries.size = table->info.size; optlen = sizeof(entries) - sizeof(entries.entrytable) + entries.size; if (getsockopt(fd, SOL_IP, ARPT_SO_GET_ENTRIES, &entries, &optlen)) exit(1); if (memcmp(table->replace.entrytable, entries.entrytable, table->info.size) == 0) continue; } else { } table->replace.num_counters = info.num_entries; table->replace.counters = counters; optlen = sizeof(table->replace) - sizeof(table->replace.entrytable) + table->replace.size; if (setsockopt(fd, SOL_IP, ARPT_SO_SET_REPLACE, &table->replace, optlen)) exit(1); } close(fd); } #define NF_BR_NUMHOOKS 6 #define EBT_TABLE_MAXNAMELEN 32 #define EBT_CHAIN_MAXNAMELEN 32 #define EBT_BASE_CTL 128 #define EBT_SO_SET_ENTRIES (EBT_BASE_CTL) #define EBT_SO_GET_INFO (EBT_BASE_CTL) #define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO + 1) #define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES + 1) #define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO + 1) struct ebt_replace { char name[EBT_TABLE_MAXNAMELEN]; unsigned int valid_hooks; unsigned int nentries; unsigned int entries_size; struct ebt_entries* hook_entry[NF_BR_NUMHOOKS]; unsigned int num_counters; struct ebt_counter* counters; char* entries; }; struct ebt_entries { unsigned int distinguisher; char name[EBT_CHAIN_MAXNAMELEN]; unsigned int counter_offset; int policy; unsigned int nentries; char data[0] __attribute__((aligned(__alignof__(struct ebt_replace)))); }; struct ebt_table_desc { const char* name; struct ebt_replace replace; char entrytable[XT_TABLE_SIZE]; }; static struct ebt_table_desc ebt_tables[] = { {.name = "filter"}, {.name = "nat"}, {.name = "broute"}, }; static void checkpoint_ebtables(void) { socklen_t optlen; unsigned i; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) { struct ebt_table_desc* table = &ebt_tables[i]; strcpy(table->replace.name, table->name); optlen = sizeof(table->replace); if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_INFO, &table->replace, &optlen)) { switch (errno) { case EPERM: case ENOENT: case ENOPROTOOPT: continue; } exit(1); } if (table->replace.entries_size > sizeof(table->entrytable)) exit(1); table->replace.num_counters = 0; table->replace.entries = table->entrytable; optlen = sizeof(table->replace) + table->replace.entries_size; if (getsockopt(fd, SOL_IP, EBT_SO_GET_INIT_ENTRIES, &table->replace, &optlen)) exit(1); } close(fd); } static void reset_ebtables() { struct ebt_replace replace; char entrytable[XT_TABLE_SIZE]; socklen_t optlen; unsigned i, j, h; int fd; fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { switch (errno) { case EAFNOSUPPORT: case ENOPROTOOPT: return; } exit(1); } for (i = 0; i < sizeof(ebt_tables) / sizeof(ebt_tables[0]); i++) { struct ebt_table_desc* table = &ebt_tables[i]; if (table->replace.valid_hooks == 0) continue; memset(&replace, 0, sizeof(replace)); strcpy(replace.name, table->name); optlen = sizeof(replace); if (getsockopt(fd, SOL_IP, EBT_SO_GET_INFO, &replace, &optlen)) exit(1); replace.num_counters = 0; table->replace.entries = 0; for (h = 0; h < NF_BR_NUMHOOKS; h++) table->replace.hook_entry[h] = 0; if (memcmp(&table->replace, &replace, sizeof(table->replace)) == 0) { memset(&entrytable, 0, sizeof(entrytable)); replace.entries = entrytable; optlen = sizeof(replace) + replace.entries_size; if (getsockopt(fd, SOL_IP, EBT_SO_GET_ENTRIES, &replace, &optlen)) exit(1); if (memcmp(table->entrytable, entrytable, replace.entries_size) == 0) continue; } for (j = 0, h = 0; h < NF_BR_NUMHOOKS; h++) { if (table->replace.valid_hooks & (1 << h)) { table->replace.hook_entry[h] = (struct ebt_entries*)table->entrytable + j; j++; } } table->replace.entries = table->entrytable; optlen = sizeof(table->replace) + table->replace.entries_size; if (setsockopt(fd, SOL_IP, EBT_SO_SET_ENTRIES, &table->replace, optlen)) exit(1); } close(fd); } static void checkpoint_net_namespace(void) { checkpoint_ebtables(); checkpoint_arptables(); checkpoint_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]), AF_INET, SOL_IP); checkpoint_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]), AF_INET6, SOL_IPV6); } static void reset_net_namespace(void) { reset_ebtables(); reset_arptables(); reset_iptables(ipv4_tables, sizeof(ipv4_tables) / sizeof(ipv4_tables[0]), AF_INET, SOL_IP); reset_iptables(ipv6_tables, sizeof(ipv6_tables) / sizeof(ipv6_tables[0]), AF_INET6, SOL_IPV6); } static void setup_cgroups() { if (mkdir("/syzcgroup", 0777)) { } if (mkdir("/syzcgroup/unified", 0777)) { } if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) { } if (chmod("/syzcgroup/unified", 0777)) { } write_file("/syzcgroup/unified/cgroup.subtree_control", "+cpu +memory +io +pids +rdma"); if (mkdir("/syzcgroup/cpu", 0777)) { } if (mount("none", "/syzcgroup/cpu", "cgroup", 0, "cpuset,cpuacct,perf_event,hugetlb")) { } write_file("/syzcgroup/cpu/cgroup.clone_children", "1"); if (chmod("/syzcgroup/cpu", 0777)) { } if (mkdir("/syzcgroup/net", 0777)) { } if (mount("none", "/syzcgroup/net", "cgroup", 0, "net_cls,net_prio,devices,freezer")) { } if (chmod("/syzcgroup/net", 0777)) { } } static void setup_cgroups_loop() { int pid = getpid(); char file[128]; char cgroupdir[64]; snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/pids.max", cgroupdir); write_file(file, "32"); snprintf(file, sizeof(file), "%s/memory.low", cgroupdir); write_file(file, "%d", 298 << 20); snprintf(file, sizeof(file), "%s/memory.high", cgroupdir); write_file(file, "%d", 299 << 20); snprintf(file, sizeof(file), "%s/memory.max", cgroupdir); write_file(file, "%d", 300 << 20); snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); } static void setup_cgroups_test() { char cgroupdir[64]; snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid); if (symlink(cgroupdir, "./cgroup")) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid); if (symlink(cgroupdir, "./cgroup.cpu")) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid); if (symlink(cgroupdir, "./cgroup.net")) { } } static void setup_common() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } setup_cgroups(); } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setsid(); int netns = open("/proc/self/ns/net", O_RDONLY); if (netns == -1) exit(1); if (dup2(netns, kInitNetNsFd) < 0) exit(1); close(netns); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (200 << 20); setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static void drop_caps(void) { struct __user_cap_header_struct cap_hdr = {}; struct __user_cap_data_struct cap_data[2] = {}; cap_hdr.version = _LINUX_CAPABILITY_VERSION_3; cap_hdr.pid = getpid(); if (syscall(SYS_capget, &cap_hdr, &cap_data)) exit(1); const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE); cap_data[0].effective &= ~drop; cap_data[0].permitted &= ~drop; cap_data[0].inheritable &= ~drop; if (syscall(SYS_capset, &cap_hdr, &cap_data)) exit(1); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); setup_common(); sandbox_common(); drop_caps(); initialize_netdevices_init(); if (unshare(CLONE_NEWNET)) { } initialize_devlink_pci(); initialize_tun(); initialize_netdevices(); loop(); exit(1); } #define FS_IOC_SETFLAGS _IOW('f', 2, long) static void remove_dir(const char* dir) { DIR* dp; struct dirent* ep; int iter = 0; retry: while (umount2(dir, MNT_DETACH) == 0) { } dp = opendir(dir); if (dp == NULL) { if (errno == EMFILE) { exit(1); } exit(1); } while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); while (umount2(filename, MNT_DETACH) == 0) { } struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } int i; for (i = 0;; i++) { if (unlink(filename) == 0) break; if (errno == EPERM) { int fd = open(filename, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno != EBUSY || i > 100) exit(1); if (umount2(filename, MNT_DETACH)) exit(1); } } closedir(dp); int i; for (i = 0;; i++) { if (rmdir(dir) == 0) break; if (i < 100) { if (errno == EPERM) { int fd = open(dir, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno == EBUSY) { if (umount2(dir, MNT_DETACH)) exit(1); continue; } if (errno == ENOTEMPTY) { if (iter < 100) { iter++; goto retry; } } } exit(1); } } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); int i; for (i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } static void setup_loop() { setup_cgroups_loop(); checkpoint_net_namespace(); } static void reset_loop() { reset_net_namespace(); } static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setup_cgroups_test(); write_file("/proc/self/oom_score_adj", "1000"); flush_tun(); } static void close_fds() { int fd; for (fd = 3; fd < MAX_FDS; fd++) close(fd); } static void setup_binfmt_misc() { if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0)) { } write_file("/proc/sys/fs/binfmt_misc/register", ":syz0:M:0:\x01::./file0:"); write_file("/proc/sys/fs/binfmt_misc/register", ":syz1:M:1:\x02::./file0:POC"); } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; int collide = 0; again: for (call = 0; call < 90; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); if (collide && (call % 2) == 0) break; event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); close_fds(); if (!collide) { collide = 1; goto again; } } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { setup_loop(); int iter; for (iter = 0;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); reset_loop(); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); setup_test(); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[21] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res; switch (call) { case 0: res = syscall(__NR_pipe, 0x20000200ul); if (res != -1) { NONFAILING(r[0] = *(uint32_t*)0x20000200); NONFAILING(r[1] = *(uint32_t*)0x20000204); } break; case 1: res = syscall(__NR_socket, 2ul, 2ul, 0ul); if (res != -1) r[2] = res; break; case 2: syscall(__NR_close, r[2]); break; case 3: NONFAILING(memcpy((void*)0x20000200, "./file1\000", 8)); syscall(__NR_mkdir, 0x20000200ul, 0ul); break; case 4: NONFAILING(memcpy((void*)0x20000300, "./bus\000", 6)); syscall(__NR_mkdir, 0x20000300ul, 0ul); break; case 5: NONFAILING(memcpy((void*)0x20000280, "./file0\000", 8)); syscall(__NR_mkdir, 0x20000280ul, 0ul); break; case 6: NONFAILING(memcpy((void*)0x20000000, "./bus\000", 6)); NONFAILING(memcpy((void*)0x20000400, "overlay\000", 8)); NONFAILING(memcpy((void*)0x20000300, "lowerdir=./bus,workdir=./file1,upperdir=./file0", 47)); syscall(__NR_mount, 0x400000ul, 0x20000000ul, 0x20000400ul, 0ul, 0x20000300ul); break; case 7: NONFAILING(memcpy((void*)0x200000c0, "./file1\000", 8)); syscall(__NR_rename, 0ul, 0x200000c0ul); break; case 8: NONFAILING(memcpy((void*)0x20000140, "./bus\000", 6)); syscall(__NR_chdir, 0x20000140ul); break; case 9: syscall(__NR_ioctl, r[1], 0x400454caul, 0ul); break; case 10: NONFAILING(memcpy((void*)0x20000040, "./file0\000", 8)); syscall(__NR_open, 0x20000040ul, 0x200c2ul, 0ul); break; case 11: syscall(__NR_socket, 0x10ul, 3ul, 0ul); break; case 12: syscall(__NR_write, r[1], 0x20000000ul, 0xfffffeccul); break; case 13: syscall(__NR_splice, r[0], 0ul, r[2], 0ul, 0x4ffe0ul, 0ul); break; case 14: NONFAILING(memcpy( (void*)0x20000340, "\x21\xbe\xa1\x61\x04\x4c\x93\x2d\xf6\xdd\x49\xad\x24\x11\x08\xde\xd5" "\xa7\x71\x7a\xbb\xcf\xb8\x6b\xd9\x8a\xc9\x70\xbf\x7c\x12\x45\x4e\x6a" "\x44\x41\xfa\x6a\x98\xfa\x26\x8c\xd7\xe6\x4c\x93\x9e\xd9\x8a\x12\x57" "\x0e\xba\x14\xc6\x51\x79\x6c\x9a\x2b\x86\xe8\xdb\xe9\xd3\xfc\x7c\xe5" "\x0b\x7e\x7e\xb5\xc5\xcb\xf1\x78\xf4\x63\x14\xad\xc8\xdf\x55\xbd\x58" "\xf1\x4c\x6e\xfb\x57\x19\x5c\xf0\x9c\x9c\x69\xb9\x9c\xbd\xe9\x7a\xc8" "\x0f\xe7\x97\xab\x7c\x92\x6f\xec\xcf\xb9\x1e\xdd\xd0\x1b\xc8\xd4\x54" "\xe3\x22\xd5\xb2\xcd\x64\xa1\x1f\x8f\xf4\x59\xcd\x5b\xdb\xcd\x5e\x50" "\xdc\xf8\xd5\x6d\x94\x67\x8c\x5e\xe5", 145)); res = syscall(__NR_add_key, 0ul, 0ul, 0x20000340ul, 0x91ul, 0); if (res != -1) r[3] = res; break; case 15: NONFAILING(memcpy((void*)0x20000480, "./file0\000", 8)); syscall(__NR_stat, 0x20000480ul, 0ul); break; case 16: res = syscall(__NR_fstat, -1, 0x20001b80ul); if (res != -1) NONFAILING(r[4] = *(uint32_t*)0x20001b98); break; case 17: syscall(__NR_getuid); break; case 18: res = syscall(__NR_mq_open, 0ul, 0x6e93ebbbcc0884f2ul, 0ul, 0ul); if (res != -1) r[5] = res; break; case 19: syscall(__NR_mq_timedreceive, r[5], 0ul, 0ul, 0ul, 0ul); break; case 20: NONFAILING(*(uint64_t*)0x200000c0 = 0x77359400); NONFAILING(*(uint64_t*)0x200000c8 = 0); syscall(__NR_mq_timedreceive, r[5], 0x20000040ul, 0x32ul, 0ul, 0x200000c0ul); break; case 21: syscall(__NR_mq_timedsend, r[5], 0x20000100ul, 0ul, 0ul, 0ul); break; case 22: NONFAILING(memcpy((void*)0x2084dff0, "!selinuxselinux\000", 16)); res = syscall(__NR_mq_open, 0x2084dff0ul, 0x6e93ebbbcc0884f2ul, 0ul, 0ul); if (res != -1) r[6] = res; break; case 23: NONFAILING(*(uint64_t*)0x200000c0 = 0x77359400); NONFAILING(*(uint64_t*)0x200000c8 = 0); syscall(__NR_mq_timedreceive, r[6], 0x20000040ul, 0x32ul, 0ul, 0x200000c0ul); break; case 24: NONFAILING(*(uint64_t*)0x20000180 = 0); NONFAILING(*(uint64_t*)0x20000188 = 0); syscall(__NR_mq_timedsend, r[6], 0ul, 0ul, 0ul, 0x20000180ul); break; case 25: syscall(__NR_mq_timedsend, r[6], 0x20000100ul, 0ul, 0ul, 0ul); break; case 26: syscall(__NR_mq_timedreceive, -1, 0x20000000ul, 0x18ul, 0ul, 0ul); break; case 27: NONFAILING(*(uint64_t*)0x200000c0 = 0x77359400); NONFAILING(*(uint64_t*)0x200000c8 = 0); syscall(__NR_mq_timedreceive, -1, 0x20000040ul, 0x32ul, 0ul, 0x200000c0ul); break; case 28: NONFAILING(*(uint64_t*)0x20000180 = 0); NONFAILING(*(uint64_t*)0x20000188 = 0); syscall(__NR_mq_timedsend, -1, 0x20000100ul, 0ul, 0ul, 0x20000180ul); break; case 29: NONFAILING(memcpy((void*)0x2084dff0, "!selinuxselinux\000", 16)); NONFAILING(*(uint64_t*)0x20664fc0 = 0); NONFAILING(*(uint64_t*)0x20664fc8 = 1); NONFAILING(*(uint64_t*)0x20664fd0 = 0); NONFAILING(*(uint64_t*)0x20664fd8 = 0); NONFAILING(*(uint64_t*)0x20664fe0 = 0); NONFAILING(*(uint64_t*)0x20664fe8 = 0); NONFAILING(*(uint64_t*)0x20664ff0 = 0); NONFAILING(*(uint64_t*)0x20664ff8 = 0); res = syscall(__NR_mq_open, 0x2084dff0ul, 0x6e93ebbbcc0884f2ul, 0ul, 0x20664fc0ul); if (res != -1) r[7] = res; break; case 30: syscall(__NR_mq_timedreceive, r[7], 0ul, 0ul, 0ul, 0ul); break; case 31: syscall(__NR_mq_timedreceive, r[7], 0x20000040ul, 0x32ul, 0ul, 0ul); break; case 32: syscall(__NR_mq_timedsend, r[7], 0x20000100ul, 0ul, 0ul, 0ul); break; case 33: syscall(__NR_mq_timedsend, r[7], 0ul, 0ul, 0ul, 0ul); break; case 34: NONFAILING(*(uint64_t*)0x20664fc0 = 0); NONFAILING(*(uint64_t*)0x20664fc8 = 1); NONFAILING(*(uint64_t*)0x20664fd0 = 0); NONFAILING(*(uint64_t*)0x20664fd8 = 0); NONFAILING(*(uint64_t*)0x20664fe0 = 0); NONFAILING(*(uint64_t*)0x20664fe8 = 0); NONFAILING(*(uint64_t*)0x20664ff0 = 0); NONFAILING(*(uint64_t*)0x20664ff8 = 0); res = syscall(__NR_mq_open, 0ul, 0x6e93ebbbcc0884f2ul, 0ul, 0x20664fc0ul); if (res != -1) r[8] = res; break; case 35: syscall(__NR_mq_timedreceive, r[8], 0x20000040ul, 0x32ul, 0ul, 0ul); break; case 36: NONFAILING(*(uint64_t*)0x20000180 = 0); NONFAILING(*(uint64_t*)0x20000188 = 0); syscall(__NR_mq_timedsend, r[8], 0ul, 0ul, 0ul, 0x20000180ul); break; case 37: syscall(__NR_mq_timedsend, r[8], 0x20000100ul, 0ul, 0ul, 0ul); break; case 38: syscall(__NR_mq_timedreceive, -1, 0ul, 0ul, 0ul, 0ul); break; case 39: NONFAILING(memcpy((void*)0x2084dff0, "!selinuxselinux\000", 16)); res = syscall(__NR_mq_open, 0x2084dff0ul, 0x6e93ebbbcc0884f2ul, 0ul, 0ul); if (res != -1) r[9] = res; break; case 40: syscall(__NR_mq_timedreceive, r[9], 0x20000040ul, 0x32ul, 0ul, 0ul); break; case 41: syscall(__NR_mq_timedsend, r[9], 0x20000100ul, 0ul, 0ul, 0ul); break; case 42: syscall(__NR_mq_timedsend, r[9], 0x20000100ul, 0ul, 0ul, 0ul); break; case 43: NONFAILING(memcpy((void*)0x2084dff0, "!selinuxselinux\000", 16)); NONFAILING(*(uint64_t*)0x20000440 = 9); NONFAILING(*(uint64_t*)0x20000448 = 0x10001); NONFAILING(*(uint64_t*)0x20000450 = 0x10005); NONFAILING(*(uint64_t*)0x20000458 = 0xfffffffffffffffe); NONFAILING(*(uint64_t*)0x20000460 = 0); NONFAILING(*(uint64_t*)0x20000468 = 0); NONFAILING(*(uint64_t*)0x20000470 = 0); NONFAILING(*(uint64_t*)0x20000478 = 0); res = syscall(__NR_mq_open, 0x2084dff0ul, 0x40ul, 0x92ul, 0x20000440ul); if (res != -1) r[10] = res; break; case 44: NONFAILING(*(uint64_t*)0x200000c0 = 0x77359400); NONFAILING(*(uint64_t*)0x200000c8 = 0); syscall(__NR_mq_timedreceive, r[10], 0ul, 0ul, 0ul, 0x200000c0ul); break; case 45: NONFAILING(*(uint64_t*)0x20000180 = 0); NONFAILING(*(uint64_t*)0x20000188 = 0); syscall(__NR_mq_timedsend, r[10], 0x20000100ul, 0ul, 0ul, 0x20000180ul); break; case 46: syscall(__NR_mq_timedsend, r[10], 0x20000100ul, 0ul, 0ul, 0ul); break; case 47: NONFAILING(memcpy( (void*)0x20000380, "!selinexselinux\000t\000\300`K\340\245b\344}\266\302\233\'\031\005/" "\340s2Y9\310L\nb\000\200\005\330\256F0U\300y\277\265_" "\257\355\313\277m\032\342(\247Z\245E\266\025\344\222\3226\372\341)" "a\273!\366_q\251<o\310\356u\336}" "\262\371\340sh\220L\037ab\004\354\'\332\234\202{\f\347\2101g\302\221?" "S\221\335z%\234\372\273\250\235\246\326\366\355\202\254\253\350\267*" "\335X\031m\210\000V\031\267\316\v\265\246\227\021\215ON\333$\323+Ok$" "\377*\357m{\002\271", 167)); NONFAILING(*(uint64_t*)0x20664fc0 = 0); NONFAILING(*(uint64_t*)0x20664fc8 = 1); NONFAILING(*(uint64_t*)0x20664fd0 = 9); NONFAILING(*(uint64_t*)0x20664fd8 = 0); NONFAILING(*(uint64_t*)0x20664fe0 = 0); NONFAILING(*(uint64_t*)0x20664fe8 = 0); NONFAILING(*(uint64_t*)0x20664ff0 = 0); NONFAILING(*(uint64_t*)0x20664ff8 = 0); res = syscall(__NR_mq_open, 0x20000380ul, 0x6e93ebbbcc0884f2ul, 0ul, 0x20664fc0ul); if (res != -1) r[11] = res; break; case 48: syscall(__NR_mq_timedreceive, r[11], 0ul, 0ul, 0ul, 0ul); break; case 49: NONFAILING(*(uint64_t*)0x200000c0 = 0x77359400); NONFAILING(*(uint64_t*)0x200000c8 = 0); syscall(__NR_mq_timedreceive, r[11], 0x20000040ul, 0x32ul, 0ul, 0x200000c0ul); break; case 50: NONFAILING(*(uint64_t*)0x20000180 = 0); NONFAILING(*(uint64_t*)0x20000188 = 0); syscall(__NR_mq_timedsend, r[11], 0ul, 0ul, 0ul, 0x20000180ul); break; case 51: syscall(__NR_mq_timedsend, r[11], 0ul, 0ul, 0ul, 0ul); break; case 52: syscall(__NR_getsockopt, -1, 1ul, 0x11ul, 0ul, 0ul); break; case 53: res = syscall(__NR_fstat, -1, 0x20001b80ul); if (res != -1) NONFAILING(r[12] = *(uint32_t*)0x20001b9c); break; case 54: res = syscall(__NR_getpgid, 0); if (res != -1) r[13] = res; break; case 55: NONFAILING(*(uint32_t*)0x20000840 = 0x798e2635 + procid * 4); NONFAILING(*(uint32_t*)0x20000844 = 0); NONFAILING(*(uint32_t*)0x20000848 = r[12]); NONFAILING(*(uint32_t*)0x2000084c = 0); NONFAILING(*(uint32_t*)0x20000850 = r[12]); NONFAILING(*(uint32_t*)0x20000854 = 0); NONFAILING(*(uint16_t*)0x20000858 = 0); NONFAILING(*(uint32_t*)0x2000085c = 0xb8fb); NONFAILING(*(uint64_t*)0x20000860 = 0xffc); NONFAILING(*(uint64_t*)0x20000868 = 0); NONFAILING(*(uint64_t*)0x20000870 = 0x8000); NONFAILING(*(uint32_t*)0x20000878 = 0); NONFAILING(*(uint32_t*)0x2000087c = r[13]); NONFAILING(*(uint16_t*)0x20000880 = 0x81); NONFAILING(*(uint16_t*)0x20000882 = 0); NONFAILING(*(uint64_t*)0x20000888 = 0); NONFAILING(*(uint64_t*)0x20000890 = 0); syscall(__NR_shmctl, 0, 1ul, 0x20000840ul); break; case 56: syscall(__NR_getuid); break; case 57: NONFAILING(*(uint64_t*)0x20664fc0 = 0); NONFAILING(*(uint64_t*)0x20664fc8 = 0); NONFAILING(*(uint64_t*)0x20664fd0 = 5); NONFAILING(*(uint64_t*)0x20664fd8 = 0); NONFAILING(*(uint64_t*)0x20664fe0 = 0); NONFAILING(*(uint64_t*)0x20664fe8 = 0); NONFAILING(*(uint64_t*)0x20664ff0 = 0); NONFAILING(*(uint64_t*)0x20664ff8 = 0); res = syscall(__NR_mq_open, 0ul, 0x6e93ebbbcc0884f2ul, 0ul, 0x20664fc0ul); if (res != -1) r[14] = res; break; case 58: syscall(__NR_mq_timedreceive, r[14], 0ul, 0ul, 0ul, 0ul); break; case 59: NONFAILING(*(uint64_t*)0x200000c0 = 0x77359400); NONFAILING(*(uint64_t*)0x200000c8 = 0); syscall(__NR_mq_timedreceive, r[14], 0ul, 0ul, 0ul, 0x200000c0ul); break; case 60: syscall(__NR_mq_timedsend, r[14], 0x20000100ul, 0ul, 0ul, 0ul); break; case 61: NONFAILING(*(uint64_t*)0x20664fc0 = 0); NONFAILING(*(uint64_t*)0x20664fc8 = 1); NONFAILING(*(uint64_t*)0x20664fd0 = 5); NONFAILING(*(uint64_t*)0x20664fd8 = 0); NONFAILING(*(uint64_t*)0x20664fe0 = 0); NONFAILING(*(uint64_t*)0x20664fe8 = 0); NONFAILING(*(uint64_t*)0x20664ff0 = 0); NONFAILING(*(uint64_t*)0x20664ff8 = 0); res = syscall(__NR_mq_open, 0ul, 0x6e93ebbbcc0884f2ul, 0ul, 0x20664fc0ul); if (res != -1) r[15] = res; break; case 62: syscall(__NR_mq_timedsend, r[15], 0ul, 0ul, 0ul, 0ul); break; case 63: NONFAILING(memcpy((void*)0x2084dff0, "!selinuxselinux\000", 16)); res = syscall(__NR_mq_open, 0x2084dff0ul, 0x6e93ebbbcc0884f2ul, 0ul, 0ul); if (res != -1) r[16] = res; break; case 64: NONFAILING(*(uint64_t*)0x200000c0 = 0x77359400); NONFAILING(*(uint64_t*)0x200000c8 = 0); syscall(__NR_mq_timedreceive, r[16], 0x20000040ul, 0x32ul, 0ul, 0x200000c0ul); break; case 65: NONFAILING(*(uint64_t*)0x20000180 = 0); NONFAILING(*(uint64_t*)0x20000188 = 0); syscall(__NR_mq_timedsend, r[16], 0ul, 0ul, 0ul, 0x20000180ul); break; case 66: syscall(__NR_mq_timedsend, r[16], 0x20000100ul, 0ul, 0ul, 0ul); break; case 67: NONFAILING(memcpy((void*)0x2084dff0, "!selinuxselinux\000", 16)); res = syscall(__NR_mq_open, 0x2084dff0ul, 0x6e93ebbbcc0884f2ul, 0ul, 0ul); if (res != -1) r[17] = res; break; case 68: NONFAILING(*(uint64_t*)0x200000c0 = 0x77359400); NONFAILING(*(uint64_t*)0x200000c8 = 0); syscall(__NR_mq_timedreceive, r[17], 0ul, 0ul, 0ul, 0x200000c0ul); break; case 69: NONFAILING(*(uint64_t*)0x20000180 = 0); NONFAILING(*(uint64_t*)0x20000188 = 0); syscall(__NR_mq_timedsend, r[17], 0ul, 0ul, 0ul, 0x20000180ul); break; case 70: syscall(__NR_mq_timedsend, r[17], 0ul, 0ul, 0ul, 0ul); break; case 71: syscall(__NR_mq_timedreceive, -1, 0ul, 0ul, 0ul, 0ul); break; case 72: syscall(__NR_mq_timedsend, -1, 0ul, 0ul, 0ul, 0ul); break; case 73: NONFAILING(*(uint64_t*)0x20664fc0 = 0); NONFAILING(*(uint64_t*)0x20664fc8 = 1); NONFAILING(*(uint64_t*)0x20664fd0 = 5); NONFAILING(*(uint64_t*)0x20664fd8 = 0); NONFAILING(*(uint64_t*)0x20664fe0 = 0); NONFAILING(*(uint64_t*)0x20664fe8 = 0); NONFAILING(*(uint64_t*)0x20664ff0 = 0); NONFAILING(*(uint64_t*)0x20664ff8 = 0); res = syscall(__NR_mq_open, 0ul, 0x6e93ebbbcc0884f2ul, 0ul, 0x20664fc0ul); if (res != -1) r[18] = res; break; case 74: syscall(__NR_mq_timedreceive, r[18], 0x20000000ul, 0x18ul, 0ul, 0ul); break; case 75: syscall(__NR_mq_timedreceive, r[18], 0ul, 0ul, 0ul, 0ul); break; case 76: NONFAILING(*(uint64_t*)0x20000180 = 0); NONFAILING(*(uint64_t*)0x20000188 = 0); syscall(__NR_mq_timedsend, r[18], 0ul, 0ul, 0ul, 0x20000180ul); break; case 77: res = syscall(__NR_mq_open, 0ul, 0x6e93ebbbcc0884f2ul, 0ul, 0ul); if (res != -1) r[19] = res; break; case 78: NONFAILING(*(uint64_t*)0x20000180 = 0); NONFAILING(*(uint64_t*)0x20000188 = 0); syscall(__NR_mq_timedsend, r[19], 0ul, 0ul, 0ul, 0x20000180ul); break; case 79: syscall(__NR_mq_timedreceive, -1, 0ul, 0ul, 0ul, 0ul); break; case 80: syscall(__NR_mq_timedreceive, -1, 0ul, 0ul, 0ul, 0ul); break; case 81: syscall(__NR_mq_timedsend, -1, 0ul, 0ul, 0ul, 0ul); break; case 82: syscall(__NR_mq_timedsend, -1, 0x20000100ul, 0ul, 0ul, 0ul); break; case 83: NONFAILING(memcpy( (void*)0x20000380, "!selinexselinux\000t\000\300`K\340\245b\344}\266\302\233\'\031\005/" "\340s2Y9\310L\nb\000\200\005\330\256F0U\300y\277\265_" "\257\355\313\277m\032\342(\247Z\245E\266\025\344\222\3226\372\341)" "a\273!\366_q\251<o\310\356u\336}" "\262\371\340sh\220L\037ab\004\354\'\332\234\202{\f\347\2101g\302\221?" "S\221\335z%\234\372\273\250\235\246\326\366\355\202\254\253\350\267*" "\335X\031m\210\000V\031\267\316\v\265\246\227\021\215ON\333$\323+Ok$" "\377*\357m{\002\271", 167)); res = syscall(__NR_mq_open, 0x20000380ul, 0x6e93ebbbcc0884f2ul, 0ul, 0ul); if (res != -1) r[20] = res; break; case 84: syscall(__NR_mq_timedreceive, r[20], 0x20000000ul, 0x18ul, 0ul, 0ul); break; case 85: NONFAILING(*(uint64_t*)0x200000c0 = 0x77359400); NONFAILING(*(uint64_t*)0x200000c8 = 0); syscall(__NR_mq_timedreceive, r[20], 0x20000040ul, 0x32ul, 0ul, 0x200000c0ul); break; case 86: syscall(__NR_mq_timedsend, r[20], 0x20000100ul, 0ul, 0ul, 0ul); break; case 87: syscall(__NR_mq_timedsend, r[20], 0x20000100ul, 0ul, 0ul, 0ul); break; case 88: NONFAILING(memcpy((void*)0x20000300, "\xeb\x5b\x26\x5d\x66\x64\x6b", 7)); NONFAILING(sprintf((char*)0x20000307, "0x%016llx", (long long)-1)); NONFAILING(sprintf((char*)0x20000319, "0x%016llx", (long long)-1)); NONFAILING(sprintf((char*)0x2000032b, "%020llu", (long long)-1)); NONFAILING(memcpy((void*)0x2000033f, "\x2c\x49\xf9\xa0\x67\x72\x6f\x5b\xac\xac\x64\x3d", 12)); NONFAILING(sprintf((char*)0x2000034b, "%020llu", (long long)r[12])); NONFAILING(*(uint64_t*)0x2000035f = 0); syscall(__NR_mount, 0ul, 0ul, 0ul, 0ul, 0x20000300ul); break; case 89: syscall(__NR_keyctl, 4ul, r[3], r[4], 0, 0); break; } } int main(void) { syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x32ul, -1, 0); setup_binfmt_misc(); install_segv_handler(); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; }
the_stack_data/468043.c
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { static char str1[20],str2[20],str3[20]; int i=0,j=0,k=0; scanf("%s%s",str1,str2); while(str1[i]!='\0'&&str2[j]!='\0'){ if(str1[i]<str2[j]){ str3[k]=str1[i]; k++;i++; } else if(str1[i]==str2[j]){ str3[k]=str1[i]; k++;i++; str3[k]=str2[j]; k++;j++; } else{ str3[k]=str2[j]; k++;j++; } } if(str1[i]=='\0') while(str2[j]!='\0'){ str3[k]=str2[j]; k++;j++; } else while(str1[i]!='\0'){ str3[k]=str1[i]; k++;i++; } puts(str3); return 0; }
the_stack_data/1211764.c
#include<stdio.h> #include<stdlib.h> int main(){ int n1,n2,n3,n4; printf("Digite dois numeros inteiros (o segundo diferente de zero): "); scanf("%i %i",&n1,&n2); n3=n1/n2; n4=n1%n2; printf("\na. Dividendo: %i",n1); printf("\nb. Divisor: %i",n2); printf("\nc. Quociente: %i",n3); printf("\nd. Resto: %i\n",n4); }
the_stack_data/242329702.c
//Fibonacci series till Input number #include <stdio.h> #include <stdlib.h> int main() { int a,i=0,temp1=1,temp2=0; printf("ENter a number\n"); scanf("%d",&a); printf("%d %d ",i ,temp1); while(a){ temp2=i+temp1; i=temp1; temp1=temp2; temp2<a ? printf("%d ",temp2): exit(1); } return 0; }
the_stack_data/92325578.c
/* Test that the BUS_ADRALN macro is defined. */ #include <signal.h> #ifndef BUS_ADRALN #error BUS_ADRALN not defined #endif
the_stack_data/190768146.c
#include <stdio.h> #include <stdint.h> // lengths of the headers #define LEN_BITMAP_HDR 14 #define LEN_DIB_HDR 108 // addresses of LSBs of Bitmap header fields #define ADDR_FILE_SIZE 0x02 #define ADDR_OFFSET 0x0A // lengths of Bitmap header fields #define LEN_FILE_SIZE 4 #define LEN_OFFSET 4 // addresses of LSBs of DIP header fields #define ADDR_WIDTH 0x04 #define ADDR_HEIGHT 0x08 #define ADDR_COLOR_PLANES 0x0C #define ADDR_BPP 0x0E #define ADDR_IMG_SIZE 0x14 // lengths of DIP header fields #define LEN_WIDTH 4 #define LEN_HEIGHT 4 #define LEN_COLOR_PLANES 2 #define LEN_BPP 2 #define LEN_IMG_SIZE 4 int main(int argc, char **argv){ FILE *file; uint8_t bitmap_hdr[LEN_BITMAP_HDR], dib_hdr[LEN_DIB_HDR], file_size_a[LEN_FILE_SIZE], offset_a[LEN_OFFSET], width_a[LEN_WIDTH], height_a[LEN_HEIGHT], color_planes_a[LEN_COLOR_PLANES], bpp_a[LEN_BPP], img_size_a[LEN_IMG_SIZE]; // open the file for reading file = fopen(argv[1], "r"); if(!file) { printf("Erro a abrir %s\n", argv[1]); return -1; } // read the Bitmap header int n_read = fread(bitmap_hdr, 1, LEN_BITMAP_HDR, file); if(n_read!=LEN_BITMAP_HDR) { printf("Bitmap: leitura inválida, %d/%d bytes\n", n_read, LEN_BITMAP_HDR); return -1; } // read the DIB header n_read = fread(dib_hdr, 1, LEN_DIB_HDR, file); if(n_read!=LEN_DIB_HDR) { printf("DIB: leitura inválida, %d/%d bytes\n", n_read, LEN_DIB_HDR); return -1; } // parse the Bitmap header for(int addr=0x00; addr<LEN_BITMAP_HDR; addr++) { switch(addr) { case ADDR_FILE_SIZE ... ADDR_FILE_SIZE + LEN_FILE_SIZE - 1: file_size_a[addr-ADDR_FILE_SIZE] = bitmap_hdr[addr]; break; case ADDR_OFFSET ... ADDR_OFFSET + LEN_OFFSET - 1: offset_a[addr-ADDR_OFFSET] = bitmap_hdr[addr]; break; } } // parse the DIB header for(int addr=0x00; addr<LEN_DIB_HDR; addr++) { switch(addr) { case ADDR_WIDTH ... ADDR_WIDTH + LEN_WIDTH - 1: width_a[addr-ADDR_WIDTH] = dib_hdr[addr]; break; case ADDR_HEIGHT ... ADDR_HEIGHT + LEN_HEIGHT - 1: height_a[addr-ADDR_HEIGHT] = dib_hdr[addr]; break; case ADDR_COLOR_PLANES ... ADDR_COLOR_PLANES + LEN_COLOR_PLANES - 1: color_planes_a[addr-ADDR_COLOR_PLANES] = dib_hdr[addr]; break; case ADDR_BPP ... ADDR_BPP + LEN_BPP - 1: bpp_a[addr-ADDR_BPP] = dib_hdr[addr]; break; case ADDR_IMG_SIZE ... ADDR_IMG_SIZE + LEN_IMG_SIZE - 1: img_size_a[addr-ADDR_IMG_SIZE] = dib_hdr[addr]; break; default: break; } } // cast char (byte) arrays to int int file_size = (int) *(uint32_t *)file_size_a; int offset = (int) *(uint32_t *)offset_a; int width = (int) *(int32_t *)width_a; int height = (int) *(int32_t *)height_a; int color_planes = (int) *(uint16_t *)color_planes_a; int bpp = (int) *(uint16_t *)bpp_a; int img_size = (int) *(uint32_t *)img_size_a; // compute actual width and size (with zero padding) int width_4 = (width%4==0) ? width : width + 4 - width%4; int img_size_4 = height * width_4 * 3; // image array unsigned char image[height][width_4][3]; // jump to the start of the image array fseek(file, offset, SEEK_SET); // read image data (starting on the last line) for(int i=height-1, pix, byte_cnt=0; i>-1; i--) { for(int j=0; j<width_4; j++) { for(int k=0; k<3; k++, byte_cnt++) { if((pix=getc(file))==EOF) { printf("EOF antes do esperado, %d/%d bytes lidos\n", byte_cnt, img_size_4); return -1; } image[i][j][k] = (unsigned char)pix; } } } fclose(file); printf("Tamanho total do ficheiro BMP (bytes): %d\n", file_size); printf("Largura da imagem: %d\n", width); printf("Altura da imagem: %d\n", height); printf("Planos de cor: %d\n", color_planes); printf("Bits por pixel: %d\n", bpp); printf("Tamanho da imagem (bytes): %d\n", img_size); printf("Valor RGB no pixel (0,0): %d %d %d\n", (int)image[0][0][2], (int)image[0][0][1], (int)image[0][0][0]); printf("Valor RGB no pixel (532,0): %d %d %d\n", (int)image[532][0][2], (int)image[532][0][1], (int)image[532][0][0]); printf("Valor RGB no pixel (408,443): %d %d %d\n", (int)image[408][443][2], (int)image[408][443][1], (int)image[408][443][0]); return 0; }
the_stack_data/126692.c
/* * pr_pset07_11: * * Write a program that uses a switch statement in a loop such that a response * of a lets the user enter the pounds of artichokes desired, b the pounds of * beets, c the pounds of carrots, and q allows the user to exit the ordering * process. The program should keep track of cumulative totals. That is, if * the user enters 4 pounds of beets and later enters 5 pounds of beets, * the program should use report 9 pounds of beets. The program then should * compute the total charges, the discount, if any, the shipping charges, * and the grand total. The program then should display all the purchase * information: the cost per pound, the pounds ordered, and the cost for that * order for each vegetable, the total cost of the order, the discount * (if there is one), the shipping charge, and the grand total of all * the charges. */ #include <stdio.h> #define ARTICH_PRICE 2.05 #define BEETS_PRICE 1.15 #define CARROT_PRICE 1.09 #define ORDER_BASE 100.0 #define DISCOUNT 0.05 #define WEIGHT_BASE1 5 #define WEIGHT_BASE2 20 #define SHIP_COST1 6.5 #define SHIP_COST2 14.0 #define SHIP_COST_EX 0.5 // Print header menue. void printheader(void); // Ask user for pounds. float get_weight(void); // Calculate, print and return product's charge float set_charge(char name[], float weight, float prise); int main(void) { int choice; float w_artich, w_beet, w_carrot; // cumulative totals of weight float weight = 0.0; // total order's weight float total = 0.0; // grand total float discount = 0.0; float shipping; w_artich = w_beet = w_carrot = 0.0; printheader(); while (((choice = getchar()) != 'q') && (choice != 'Q')) { switch(choice) { case 'a' : case 'A' : w_artich += get_weight(); break; case 'b' : case 'B' : w_beet += get_weight(); break; case 'c' : case 'C' : w_carrot += get_weight(); break; default : printf("Retry with letter (a,b,c or q).\n"); break; } while (getchar() != '\n') continue; printheader(); } weight = w_artich + w_beet + w_carrot; if (weight > 0) { printf("**********************************\n"); // Calculate total and print product charge. if (w_artich > 0) { total += set_charge("Artichokes", w_artich, ARTICH_PRICE); } if (w_beet > 0) { total += set_charge("Beets ", w_beet, BEETS_PRICE); } if (w_carrot > 0) { total += set_charge("Carrots ", w_carrot, CARROT_PRICE); } printf("Total : $%6.2f\n", total); // Calculate and print discount. if (total >= ORDER_BASE) { discount = total * DISCOUNT; printf("Discount (5%%) : $%6.2f\n", discount); } // Calculate and print shipping and handling if (weight <= WEIGHT_BASE1) { shipping = SHIP_COST1; } else if (weight <= WEIGHT_BASE2) { shipping = SHIP_COST2; } else { shipping = SHIP_COST2 + SHIP_COST_EX * (weight - WEIGHT_BASE2); } printf("Shipping of\t%5.1f lbs: $%6.2f\n", weight, shipping); // Print grand total charge. printf("**********************************\n"); printf("TOTAL : $%6.2f\n", total - discount + shipping); } return 0; } void printheader(void) { printf("******************************************************\n"); printf("Enter the letter corresponding to the desired product:\n"); printf("a) artichokes\tb) beets\tc) carrots\n"); printf("q) quit\n"); printf("******************************************************\n"); } float get_weight(void) { float pounds; printf("Enter weight (in pounds): "); while (scanf("%f", &pounds) != 1 && (pounds < 0)) { printf("Please, retry with some positive number: "); while (getchar () != '\n') continue; } return pounds; } float set_charge(char name[10], float weight, float prise) { float charge; charge = weight * prise; printf("%s\t%5.1f lbs: $%6.2f\n", name, weight, charge); return charge; }
the_stack_data/148578245.c
/* * Copyright (C) 2015-2018 Alibaba Group Holding Limited */ #include <stdio.h> void *HAL_Fopen(const char *path, const char *mode) { return NULL; } size_t HAL_Fread(void * buff,size_t size, size_t count, void *stream) { return 0; } size_t HAL_Fwrite(const void * ptr, size_t size, size_t count, void * stream) { return 0; } int HAL_Fseek(void *stream,long offset,int framewhere) { return 0; } int HAL_Fclose(FILE *stream) { return 0; } long HAL_Ftell(void *stream) { return 0; }
the_stack_data/107951890.c
#include <stdio.h> #include <stdlib.h> void cond(long a, long *p) { if( p && *p ) *p = a; } void cond_goto(long a, long *p) { if( p ) goto nextjudge; nextjudge: if( *p ) goto execut; execut: *p = a; } int main(int argc, char* argv[]) { long dd = 20; cond(50, &dd); }
the_stack_data/145453437.c
/* * C++ 'static const' works differently from C 'static const'. * This example compiles with gcc but not with g++. G++ will * issue errors. */ /* $ g++ -o /tmp/foo cxx_static_const.c -lm cxx_static_const.c:2:26: error: uninitialized const ‘N1’ [-fpermissive] static const struct node N1; ^ cxx_static_const.c:1:21: note: ‘const struct node’ has no user-provided default constructor struct node; struct node { const struct node *other; }; ^ cxx_static_const.c:1:47: note: and the implicitly-defined constructor does not initialize ‘const node* node::other’ struct node; struct node { const struct node *other; }; ^ cxx_static_const.c:3:26: error: uninitialized const ‘N2’ [-fpermissive] static const struct node N2; ^ cxx_static_const.c:1:21: note: ‘const struct node’ has no user-provided default constructor struct node; struct node { const struct node *other; }; ^ cxx_static_const.c:1:47: note: and the implicitly-defined constructor does not initialize ‘const node* node::other’ struct node; struct node { const struct node *other; }; ^ cxx_static_const.c:4:26: error: redefinition of ‘const node N1’ static const struct node N1 = { &N2 }; ^ cxx_static_const.c:2:26: error: ‘const node N1’ previously declared here static const struct node N1; ^ cxx_static_const.c:5:26: error: redefinition of ‘const node N2’ static const struct node N2 = { &N1 }; ^ cxx_static_const.c:3:26: error: ‘const node N2’ previously declared here static const struct node N2; */ struct node; struct node { const struct node *other; }; static const struct node N1; static const struct node N2; static const struct node N1 = { &N2 }; static const struct node N2 = { &N1 }; int main(int argc, char *argv[]) { (void) argc; (void) argv; return 0; }
the_stack_data/1096736.c
/******************************************************************************/ /* */ /* Broadcom BCM5700 Linux Network Driver, Copyright (c) 2001 Broadcom */ /* Corporation. */ /* All rights reserved. */ /* */ /* 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, located in the file LICENSE. */ /* */ /* History: */ /******************************************************************************/ #if !defined(CONFIG_NET_MULTI) #if INCLUDE_TBI_SUPPORT #include "bcm570x_autoneg.h" #include "bcm570x_mm.h" /******************************************************************************/ /* Description: */ /* */ /* Return: */ /******************************************************************************/ void MM_AnTxConfig( PAN_STATE_INFO pAnInfo) { PLM_DEVICE_BLOCK pDevice; pDevice = (PLM_DEVICE_BLOCK) pAnInfo->pContext; REG_WR(pDevice, MacCtrl.TxAutoNeg, (LM_UINT32) pAnInfo->TxConfig.AsUSHORT); pDevice->MacMode |= MAC_MODE_SEND_CONFIGS; REG_WR(pDevice, MacCtrl.Mode, pDevice->MacMode); } /******************************************************************************/ /* Description: */ /* */ /* Return: */ /******************************************************************************/ void MM_AnTxIdle( PAN_STATE_INFO pAnInfo) { PLM_DEVICE_BLOCK pDevice; pDevice = (PLM_DEVICE_BLOCK) pAnInfo->pContext; pDevice->MacMode &= ~MAC_MODE_SEND_CONFIGS; REG_WR(pDevice, MacCtrl.Mode, pDevice->MacMode); } /******************************************************************************/ /* Description: */ /* */ /* Return: */ /******************************************************************************/ char MM_AnRxConfig( PAN_STATE_INFO pAnInfo, unsigned short *pRxConfig) { PLM_DEVICE_BLOCK pDevice; LM_UINT32 Value32; char Retcode; Retcode = AN_FALSE; pDevice = (PLM_DEVICE_BLOCK) pAnInfo->pContext; Value32 = REG_RD(pDevice, MacCtrl.Status); if(Value32 & MAC_STATUS_RECEIVING_CFG) { Value32 = REG_RD(pDevice, MacCtrl.RxAutoNeg); *pRxConfig = (unsigned short) Value32; Retcode = AN_TRUE; } return Retcode; } /******************************************************************************/ /* Description: */ /* */ /* Return: */ /******************************************************************************/ void AutonegInit( PAN_STATE_INFO pAnInfo) { unsigned long j; for(j = 0; j < sizeof(AN_STATE_INFO); j++) { ((unsigned char *) pAnInfo)[j] = 0; } /* Initialize the default advertisement register. */ pAnInfo->mr_adv_full_duplex = 1; pAnInfo->mr_adv_sym_pause = 1; pAnInfo->mr_adv_asym_pause = 1; pAnInfo->mr_an_enable = 1; } /******************************************************************************/ /* Description: */ /* */ /* Return: */ /******************************************************************************/ AUTONEG_STATUS Autoneg8023z( PAN_STATE_INFO pAnInfo) { unsigned short RxConfig; unsigned long Delta_us; AUTONEG_STATUS AnRet; /* Get the current time. */ if(pAnInfo->State == AN_STATE_UNKNOWN) { pAnInfo->RxConfig.AsUSHORT = 0; pAnInfo->CurrentTime_us = 0; pAnInfo->LinkTime_us = 0; pAnInfo->AbilityMatchCfg = 0; pAnInfo->AbilityMatchCnt = 0; pAnInfo->AbilityMatch = AN_FALSE; pAnInfo->IdleMatch = AN_FALSE; pAnInfo->AckMatch = AN_FALSE; } /* Increment the timer tick. This function is called every microsecon. */ /* pAnInfo->CurrentTime_us++; */ /* Set the AbilityMatch, IdleMatch, and AckMatch flags if their */ /* corresponding conditions are satisfied. */ if(MM_AnRxConfig(pAnInfo, &RxConfig)) { if(RxConfig != pAnInfo->AbilityMatchCfg) { pAnInfo->AbilityMatchCfg = RxConfig; pAnInfo->AbilityMatch = AN_FALSE; pAnInfo->AbilityMatchCnt = 0; } else { pAnInfo->AbilityMatchCnt++; if(pAnInfo->AbilityMatchCnt > 1) { pAnInfo->AbilityMatch = AN_TRUE; pAnInfo->AbilityMatchCfg = RxConfig; } } if(RxConfig & AN_CONFIG_ACK) { pAnInfo->AckMatch = AN_TRUE; } else { pAnInfo->AckMatch = AN_FALSE; } pAnInfo->IdleMatch = AN_FALSE; } else { pAnInfo->IdleMatch = AN_TRUE; pAnInfo->AbilityMatchCfg = 0; pAnInfo->AbilityMatchCnt = 0; pAnInfo->AbilityMatch = AN_FALSE; pAnInfo->AckMatch = AN_FALSE; RxConfig = 0; } /* Save the last Config. */ pAnInfo->RxConfig.AsUSHORT = RxConfig; /* Default return code. */ AnRet = AUTONEG_STATUS_OK; /* Autoneg state machine as defined in 802.3z section 37.3.1.5. */ switch(pAnInfo->State) { case AN_STATE_UNKNOWN: if(pAnInfo->mr_an_enable || pAnInfo->mr_restart_an) { pAnInfo->CurrentTime_us = 0; pAnInfo->State = AN_STATE_AN_ENABLE; } /* Fall through.*/ case AN_STATE_AN_ENABLE: pAnInfo->mr_an_complete = AN_FALSE; pAnInfo->mr_page_rx = AN_FALSE; if(pAnInfo->mr_an_enable) { pAnInfo->LinkTime_us = 0; pAnInfo->AbilityMatchCfg = 0; pAnInfo->AbilityMatchCnt = 0; pAnInfo->AbilityMatch = AN_FALSE; pAnInfo->IdleMatch = AN_FALSE; pAnInfo->AckMatch = AN_FALSE; pAnInfo->State = AN_STATE_AN_RESTART_INIT; } else { pAnInfo->State = AN_STATE_DISABLE_LINK_OK; } break; case AN_STATE_AN_RESTART_INIT: pAnInfo->LinkTime_us = pAnInfo->CurrentTime_us; pAnInfo->mr_np_loaded = AN_FALSE; pAnInfo->TxConfig.AsUSHORT = 0; MM_AnTxConfig(pAnInfo); AnRet = AUTONEG_STATUS_TIMER_ENABLED; pAnInfo->State = AN_STATE_AN_RESTART; /* Fall through.*/ case AN_STATE_AN_RESTART: /* Get the current time and compute the delta with the saved */ /* link timer. */ Delta_us = pAnInfo->CurrentTime_us - pAnInfo->LinkTime_us; if(Delta_us > AN_LINK_TIMER_INTERVAL_US) { pAnInfo->State = AN_STATE_ABILITY_DETECT_INIT; } else { AnRet = AUTONEG_STATUS_TIMER_ENABLED; } break; case AN_STATE_DISABLE_LINK_OK: AnRet = AUTONEG_STATUS_DONE; break; case AN_STATE_ABILITY_DETECT_INIT: /* Note: in the state diagram, this variable is set to */ /* mr_adv_ability<12>. Is this right?. */ pAnInfo->mr_toggle_tx = AN_FALSE; /* Send the config as advertised in the advertisement register. */ pAnInfo->TxConfig.AsUSHORT = 0; pAnInfo->TxConfig.D5_FD = pAnInfo->mr_adv_full_duplex; pAnInfo->TxConfig.D6_HD = pAnInfo->mr_adv_half_duplex; pAnInfo->TxConfig.D7_PS1 = pAnInfo->mr_adv_sym_pause; pAnInfo->TxConfig.D8_PS2 = pAnInfo->mr_adv_asym_pause; pAnInfo->TxConfig.D12_RF1 = pAnInfo->mr_adv_remote_fault1; pAnInfo->TxConfig.D13_RF2 = pAnInfo->mr_adv_remote_fault2; pAnInfo->TxConfig.D15_NP = pAnInfo->mr_adv_next_page; MM_AnTxConfig(pAnInfo); pAnInfo->State = AN_STATE_ABILITY_DETECT; break; case AN_STATE_ABILITY_DETECT: if(pAnInfo->AbilityMatch == AN_TRUE && pAnInfo->RxConfig.AsUSHORT != 0) { pAnInfo->State = AN_STATE_ACK_DETECT_INIT; } break; case AN_STATE_ACK_DETECT_INIT: pAnInfo->TxConfig.D14_ACK = 1; MM_AnTxConfig(pAnInfo); pAnInfo->State = AN_STATE_ACK_DETECT; /* Fall through. */ case AN_STATE_ACK_DETECT: if(pAnInfo->AckMatch == AN_TRUE) { if((pAnInfo->RxConfig.AsUSHORT & ~AN_CONFIG_ACK) == (pAnInfo->AbilityMatchCfg & ~AN_CONFIG_ACK)) { pAnInfo->State = AN_STATE_COMPLETE_ACK_INIT; } else { pAnInfo->State = AN_STATE_AN_ENABLE; } } else if(pAnInfo->AbilityMatch == AN_TRUE && pAnInfo->RxConfig.AsUSHORT == 0) { pAnInfo->State = AN_STATE_AN_ENABLE; } break; case AN_STATE_COMPLETE_ACK_INIT: /* Make sure invalid bits are not set. */ if(pAnInfo->RxConfig.bits.D0 || pAnInfo->RxConfig.bits.D1 || pAnInfo->RxConfig.bits.D2 || pAnInfo->RxConfig.bits.D3 || pAnInfo->RxConfig.bits.D4 || pAnInfo->RxConfig.bits.D9 || pAnInfo->RxConfig.bits.D10 || pAnInfo->RxConfig.bits.D11) { AnRet = AUTONEG_STATUS_FAILED; break; } /* Set up the link partner advertisement register. */ pAnInfo->mr_lp_adv_full_duplex = pAnInfo->RxConfig.D5_FD; pAnInfo->mr_lp_adv_half_duplex = pAnInfo->RxConfig.D6_HD; pAnInfo->mr_lp_adv_sym_pause = pAnInfo->RxConfig.D7_PS1; pAnInfo->mr_lp_adv_asym_pause = pAnInfo->RxConfig.D8_PS2; pAnInfo->mr_lp_adv_remote_fault1 = pAnInfo->RxConfig.D12_RF1; pAnInfo->mr_lp_adv_remote_fault2 = pAnInfo->RxConfig.D13_RF2; pAnInfo->mr_lp_adv_next_page = pAnInfo->RxConfig.D15_NP; pAnInfo->LinkTime_us = pAnInfo->CurrentTime_us; pAnInfo->mr_toggle_tx = !pAnInfo->mr_toggle_tx; pAnInfo->mr_toggle_rx = pAnInfo->RxConfig.bits.D11; pAnInfo->mr_np_rx = pAnInfo->RxConfig.D15_NP; pAnInfo->mr_page_rx = AN_TRUE; pAnInfo->State = AN_STATE_COMPLETE_ACK; AnRet = AUTONEG_STATUS_TIMER_ENABLED; break; case AN_STATE_COMPLETE_ACK: if(pAnInfo->AbilityMatch == AN_TRUE && pAnInfo->RxConfig.AsUSHORT == 0) { pAnInfo->State = AN_STATE_AN_ENABLE; break; } Delta_us = pAnInfo->CurrentTime_us - pAnInfo->LinkTime_us; if(Delta_us > AN_LINK_TIMER_INTERVAL_US) { if(pAnInfo->mr_adv_next_page == 0 || pAnInfo->mr_lp_adv_next_page == 0) { pAnInfo->State = AN_STATE_IDLE_DETECT_INIT; } else { if(pAnInfo->TxConfig.bits.D15 == 0 && pAnInfo->mr_np_rx == 0) { pAnInfo->State = AN_STATE_IDLE_DETECT_INIT; } else { AnRet = AUTONEG_STATUS_FAILED; } } } break; case AN_STATE_IDLE_DETECT_INIT: pAnInfo->LinkTime_us = pAnInfo->CurrentTime_us; MM_AnTxIdle(pAnInfo); pAnInfo->State = AN_STATE_IDLE_DETECT; AnRet = AUTONEG_STATUS_TIMER_ENABLED; break; case AN_STATE_IDLE_DETECT: if(pAnInfo->AbilityMatch == AN_TRUE && pAnInfo->RxConfig.AsUSHORT == 0) { pAnInfo->State = AN_STATE_AN_ENABLE; break; } Delta_us = pAnInfo->CurrentTime_us - pAnInfo->LinkTime_us; if(Delta_us > AN_LINK_TIMER_INTERVAL_US) { #if 0 /* if(pAnInfo->IdleMatch == AN_TRUE) */ /* { */ #endif pAnInfo->State = AN_STATE_LINK_OK; #if 0 /* } */ /* else */ /* { */ /* AnRet = AUTONEG_STATUS_FAILED; */ /* break; */ /* } */ #endif } break; case AN_STATE_LINK_OK: pAnInfo->mr_an_complete = AN_TRUE; pAnInfo->mr_link_ok = AN_TRUE; AnRet = AUTONEG_STATUS_DONE; break; case AN_STATE_NEXT_PAGE_WAIT_INIT: break; case AN_STATE_NEXT_PAGE_WAIT: break; default: AnRet = AUTONEG_STATUS_FAILED; break; } return AnRet; } #endif /* INCLUDE_TBI_SUPPORT */ #endif /* !defined(CONFIG_NET_MULTI) */
the_stack_data/138456.c
/*numPass=0, numTotal=7 Verdict:WRONG_ANSWER, Visibility:1, Input:"1 4 5", ExpOutput:"1111 1 1 1 1 1 1 1111 ", Output:"" Verdict:WRONG_ANSWER, Visibility:1, Input:"2 5 6", ExpOutput:"22222 2 2 2 2 2 2 2 2 22222 ", Output:"" Verdict:WRONG_ANSWER, Visibility:1, Input:"9 6 7", ExpOutput:"999999 9 9 9 9 9 9 9 9 9 9 999999 ", Output:"" Verdict:WRONG_ANSWER, Visibility:1, Input:"3 4 5", ExpOutput:"3333 3 3 3 3 3 3 3333 ", Output:"" Verdict:WRONG_ANSWER, Visibility:1, Input:"2 2 2", ExpOutput:"22 22 ", Output:"" Verdict:WRONG_ANSWER, Visibility:0, Input:"3 3 3", ExpOutput:"333 3 3 333 ", Output:"" Verdict:WRONG_ANSWER, Visibility:0, Input:"1 1 1", ExpOutput:"1 ", Output:"" */ #include<stdio.h> int main(){ int n,w,h,x,y; scanf("%d",&n); scanf("%d",&w); scanf("%d",&h); for (x=0;x<=h,x++;){ for(y=0;y<=w,y++;){ printf("%d",n); } } //Enter your code here return 0; }
the_stack_data/256137.c
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : usbd_cdc_if.c * @version : v1.0_Cube * @brief : Usb device for Virtual Com Port. ****************************************************************************** * @attention * * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics. * All rights reserved.</center></h2> * * This software component is licensed by ST under Ultimate Liberty license * SLA0044, the "License"; You may not use this file except in compliance with * the License. You may obtain a copy of the License at: * www.st.com/SLA0044 * ****************************************************************************** */ #if 0 /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "usbd_cdc_if.h" /* USER CODE BEGIN INCLUDE */ /* USER CODE END INCLUDE */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ /* USER CODE END PV */ /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @brief Usb device library. * @{ */ /** @addtogroup USBD_CDC_IF * @{ */ /** @defgroup USBD_CDC_IF_Private_TypesDefinitions USBD_CDC_IF_Private_TypesDefinitions * @brief Private types. * @{ */ /* USER CODE BEGIN PRIVATE_TYPES */ /* USER CODE END PRIVATE_TYPES */ /** * @} */ /** @defgroup USBD_CDC_IF_Private_Defines USBD_CDC_IF_Private_Defines * @brief Private defines. * @{ */ /* USER CODE BEGIN PRIVATE_DEFINES */ /* USER CODE END PRIVATE_DEFINES */ /** * @} */ /** @defgroup USBD_CDC_IF_Private_Macros USBD_CDC_IF_Private_Macros * @brief Private macros. * @{ */ /* USER CODE BEGIN PRIVATE_MACRO */ /* USER CODE END PRIVATE_MACRO */ /** * @} */ /** @defgroup USBD_CDC_IF_Private_Variables USBD_CDC_IF_Private_Variables * @brief Private variables. * @{ */ /* Create buffer for reception and transmission */ /* It's up to user to redefine and/or remove those define */ /** Received data over USB are stored in this buffer */ uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; /** Data to send over USB CDC are stored in this buffer */ uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; /* USER CODE BEGIN PRIVATE_VARIABLES */ /* USER CODE END PRIVATE_VARIABLES */ /** * @} */ /** @defgroup USBD_CDC_IF_Exported_Variables USBD_CDC_IF_Exported_Variables * @brief Public variables. * @{ */ extern USBD_HandleTypeDef hUsbDeviceFS; /* USER CODE BEGIN EXPORTED_VARIABLES */ /* USER CODE END EXPORTED_VARIABLES */ /** * @} */ /** @defgroup USBD_CDC_IF_Private_FunctionPrototypes USBD_CDC_IF_Private_FunctionPrototypes * @brief Private functions declaration. * @{ */ static int8_t CDC_Init_FS(void); static int8_t CDC_DeInit_FS(void); static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length); static int8_t CDC_Receive_FS(uint8_t* pbuf, uint32_t *Len); static int8_t CDC_TransmitCplt_FS(uint8_t *pbuf, uint32_t *Len, uint8_t epnum); /* USER CODE BEGIN PRIVATE_FUNCTIONS_DECLARATION */ /* USER CODE END PRIVATE_FUNCTIONS_DECLARATION */ /** * @} */ USBD_CDC_ItfTypeDef USBD_Interface_fops_FS = { CDC_Init_FS, CDC_DeInit_FS, CDC_Control_FS, CDC_Receive_FS, CDC_TransmitCplt_FS }; /* Private functions ---------------------------------------------------------*/ /** * @brief Initializes the CDC media low layer over the FS USB IP * @retval USBD_OK if all operations are OK else USBD_FAIL */ static int8_t CDC_Init_FS(void) { /* USER CODE BEGIN 3 */ /* Set Application Buffers */ USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0); USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS); return (USBD_OK); /* USER CODE END 3 */ } /** * @brief DeInitializes the CDC media low layer * @retval USBD_OK if all operations are OK else USBD_FAIL */ static int8_t CDC_DeInit_FS(void) { /* USER CODE BEGIN 4 */ return (USBD_OK); /* USER CODE END 4 */ } /** * @brief Manage the CDC class requests * @param cmd: Command code * @param pbuf: Buffer containing command data (request parameters) * @param length: Number of data to be sent (in bytes) * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL */ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) { /* USER CODE BEGIN 5 */ switch(cmd) { case CDC_SEND_ENCAPSULATED_COMMAND: break; case CDC_GET_ENCAPSULATED_RESPONSE: break; case CDC_SET_COMM_FEATURE: break; case CDC_GET_COMM_FEATURE: break; case CDC_CLEAR_COMM_FEATURE: break; /*******************************************************************************/ /* Line Coding Structure */ /*-----------------------------------------------------------------------------*/ /* Offset | Field | Size | Value | Description */ /* 0 | dwDTERate | 4 | Number |Data terminal rate, in bits per second*/ /* 4 | bCharFormat | 1 | Number | Stop bits */ /* 0 - 1 Stop bit */ /* 1 - 1.5 Stop bits */ /* 2 - 2 Stop bits */ /* 5 | bParityType | 1 | Number | Parity */ /* 0 - None */ /* 1 - Odd */ /* 2 - Even */ /* 3 - Mark */ /* 4 - Space */ /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ /*******************************************************************************/ case CDC_SET_LINE_CODING: break; case CDC_GET_LINE_CODING: break; case CDC_SET_CONTROL_LINE_STATE: break; case CDC_SEND_BREAK: break; default: break; } return (USBD_OK); /* USER CODE END 5 */ } /** * @brief Data received over USB OUT endpoint are sent over CDC interface * through this function. * * @note * This function will issue a NAK packet on any OUT packet received on * USB endpoint until exiting this function. If you exit this function * before transfer is complete on CDC interface (ie. using DMA controller) * it will result in receiving more data while previous ones are still * not sent. * * @param Buf: Buffer of data to be received * @param Len: Number of data received (in bytes) * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL */ static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) { /* USER CODE BEGIN 6 */ USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); USBD_CDC_ReceivePacket(&hUsbDeviceFS); return (USBD_OK); /* USER CODE END 6 */ } /** * @brief CDC_Transmit_FS * Data to send over USB IN endpoint are sent over CDC interface * through this function. * @note * * * @param Buf: Buffer of data to be sent * @param Len: Number of data to be sent (in bytes) * @retval USBD_OK if all operations are OK else USBD_FAIL or USBD_BUSY */ uint8_t CDC_Transmit_FS(uint8_t* Buf, uint16_t Len) { uint8_t result = USBD_OK; /* USER CODE BEGIN 7 */ USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*)hUsbDeviceFS.pClassData; if (hcdc->TxState != 0){ return USBD_BUSY; } USBD_CDC_SetTxBuffer(&hUsbDeviceFS, Buf, Len); result = USBD_CDC_TransmitPacket(&hUsbDeviceFS); /* USER CODE END 7 */ return result; } /** * @brief CDC_TransmitCplt_FS * Data transmited callback * * @note * This function is IN transfer complete callback used to inform user that * the submitted Data is successfully sent over USB. * * @param Buf: Buffer of data to be received * @param Len: Number of data received (in bytes) * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL */ static int8_t CDC_TransmitCplt_FS(uint8_t *Buf, uint32_t *Len, uint8_t epnum) { uint8_t result = USBD_OK; /* USER CODE BEGIN 13 */ UNUSED(Buf); UNUSED(Len); UNUSED(epnum); /* USER CODE END 13 */ return result; } /* USER CODE BEGIN PRIVATE_FUNCTIONS_IMPLEMENTATION */ #endif // #if 0 /* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */ /** * @} */ /** * @} */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
the_stack_data/247018358.c
/* { dg-do compile } */ /* { dg-options "-O2 -Wuninitialized" } */ int foo, bar; static void decode_reloc(int reloc, int *is_alt) { if (reloc >= 20) *is_alt = 1; else if (reloc >= 10) *is_alt = 0; } void testfunc() { int alt_reloc; decode_reloc(foo, &alt_reloc); if (alt_reloc) /* { dg-warning "may be used uninitialized" } */ bar = 42; }
the_stack_data/398342.c
#include <stdio.h> #include <stdlib.h> typedef struct TempNode { int value; struct TempNode *left; struct TempNode *right; struct TempNode *parent; } TempNode; typedef struct tree { struct TempNode *root; int count; } Tree; typedef struct listTempNode { TempNode *Gig_node_tree; struct listTempNode *next; }TaskList; typedef struct list { TaskList *first; TaskList *last; }List; void createlist(List *r_); int input(List *r_, TempNode *n); void clearlist(List *r_); void init(Tree *tree) ; void clear(Tree *tree); int insert(Tree *tree, int value) ; int RemoveMin(TempNode *n, Tree *t) ; TempNode *search(TempNode *node, int value); TempNode *min(TempNode *root) ; int findTempNode(Tree *tree, int value, TempNode **node) ; int turnLeft(Tree* tree); int turnRight(Tree *tree) ; void print(Tree* Root); void printTree(Tree *tree) ; TempNode* _Remove(TempNode* tree, int value); int Remove(Tree *tree, int value) ; int CoutParentandSon(int m,Tree * tree); int main() { Tree *tree = (Tree*)malloc(sizeof(TempNode)); init(tree); int a[7]; scanf("%d%d%d%d%d%d%d", &a[0], &a[1], &a[2], &a[3] ,&a[4],&a[5],&a[6]); insert(tree, a[0]); insert(tree, a[1]); insert(tree, a[2]); insert(tree, a[3]); insert(tree, a[4]); insert(tree, a[5]); insert(tree, a[6]); print(tree); printf("\n"); } void createlist(List *r_) { r_->first = NULL; r_->last = NULL; } int CoutParentandSon(int m,Tree * tree) { TempNode *TreeNode = (TempNode*)malloc(sizeof(TempNode)); if (findTempNode(tree, m, &TreeNode) == 1) printf("-\n"); else { if (TreeNode->parent == NULL) printf("_ "); else printf("%d ", TreeNode->parent->value); if (TreeNode->left == NULL) printf("_ "); else printf("%d ", TreeNode->left->value); if (TreeNode->right == NULL) printf("_ "); else printf("%d ", TreeNode->right->value); } printf("\n"); } int input(List *r_, TempNode *n) { TaskList *newList = (TaskList*)malloc(sizeof(TaskList)); newList->Gig_node_tree = n; newList->next = NULL; if (r_->first) r_->last->next = newList; else r_->first = newList; r_->last = newList; return 0; } void clearlist(List *r_) { TaskList *TmpParam, *nr_; TmpParam = r_->first; do { nr_ = TmpParam; TmpParam = TmpParam->next; free(nr_); } while (TmpParam); r_->first = NULL; r_->last = NULL; } void init(Tree *tree) { tree->root = NULL; } void clear(Tree *tree) { while (tree->root != NULL) RemoveMin(tree->root, tree); } int insert(Tree *tree, int value) { TempNode *TmpParam = (TempNode*)malloc(sizeof(TempNode)); TmpParam->value = value; if (tree->root == NULL) { TmpParam->left = TmpParam->right = NULL; TmpParam->parent = NULL; tree->root = TmpParam; tree->count = 1; return 0; } if (TmpParam->value == tree->root->value) return -1; TempNode *TmpRoot = (TempNode*)malloc(sizeof(TempNode)), *root3 = NULL; TmpRoot = tree->root; while (TmpRoot != NULL) { root3 = TmpRoot; if (value < TmpRoot->value) TmpRoot = TmpRoot->left; else TmpRoot = TmpRoot->right; } if (TmpParam->value == root3->value) { return -1; } TmpParam->parent = root3; TmpParam->left = NULL; TmpParam->right = NULL; if (value < root3->value) root3->left = TmpParam; else root3->right = TmpParam; tree->count++; return 0; } int RemoveMin(TempNode *n, Tree *t) { t->count--; if (t->count != 1) { while (n->left != NULL) n = n->left; if (n->right != NULL) { n->right->parent = n->parent; if (n == t->root) t->root = n->right; else n->parent->left = n->right; } else n->parent->left = NULL; int value = n->value; free(n); return value; } else { t->root = NULL; t->count = 0; free(t->root); return 0; } } TempNode *search(TempNode *node, int value) { if ((node == NULL) || (node->value == value)) return node; if (value < node->value) return search(node->left, value); else return search(node->right, value); } TempNode *min(TempNode *root) { TempNode *l = root; while (l->left != NULL) l = l->left; return l; } int findTempNode(Tree *tree, int value, TempNode **node) { TempNode *TmpParam, *TmpRoot; TmpRoot = tree->root; TmpParam = search(TmpRoot, value); if (TmpParam == NULL) { return 1; } *node = TmpParam; return 0; } int turnLeft(Tree* tree) { TempNode *TmpParam = tree->root->right; if (TmpParam == NULL) return 1; tree->root->right = TmpParam->left; TmpParam->left = tree->root; TmpParam->parent = tree->root->parent; tree->root->parent = TmpParam; tree->root = TmpParam; return 0; } int turnRight(Tree *tree) { TempNode *TmpParam = tree->root->left; if (TmpParam == NULL) return 1; tree->root->left = TmpParam->right; TmpParam->right = tree->root; TmpParam->parent = tree->root->parent; tree->root->parent = TmpParam; tree->root = TmpParam; return 0; } void print(Tree* Root) { TempNode *mass[100]; TempNode *mass2[100]; int TmpForMass =0; int TmpForMass2 =0; TempNode * TempStruct = Root -> root; while(TmpForMass2 <Root ->count) { while (TempStruct!= NULL) { TmpForMass2 = TmpForMass2 + 1; if(TempStruct -> right != NULL) {TmpForMass = TmpForMass + 1 ; mass[TmpForMass] = TempStruct->right; } mass2[TmpForMass2] = TempStruct; TempStruct = TempStruct->left; } TempStruct = mass[TmpForMass]; TmpForMass = TmpForMass - 1 ; } for (int i = 1 ;i <= TmpForMass2;i++) { mass2[i] -> value; printf("%d ",mass2[i] -> value); } } TempNode* _Remove(TempNode* tree, int value) { TempNode* temp; if (!tree) { return tree; } else if (value < tree->value) { tree->left = _Remove(tree->left, value); } else if (value > tree->value) { tree->right = _Remove(tree->right, value); } else { if (tree->left && tree->right) { temp = min(tree->right); temp->left = tree->left; temp = tree->right; free(tree); return temp; } else if (tree->left == tree->right) { free(tree); return NULL; } else { if (!tree->left) temp =tree->right; else temp = tree->left; free(tree); return temp; } } return tree; } int Remove(Tree *tree, int value) { TempNode *TmpParam = _Remove(tree->root, value); if (!TmpParam) return 1; else { tree->count--; tree->root = TmpParam; return 0; } }
the_stack_data/97014122.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_is_prime.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: pstuart <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/01/31 15:31:19 by pstuart #+# #+# */ /* Updated: 2022/01/31 15:44:50 by pstuart ### ########.fr */ /* */ /* ************************************************************************** */ int ft_is_prime(int nb) { int index; index = 2; while (nb % index != 0) { if (index > nb) { break ; } index++; } if (nb == index) { return (1); } return (0); } /* #include <stdio.h> int main(void) { printf("\n\t check 13 is a prime number: %d", ft_is_prime(13)); printf("\n\t check 61 is a prime number: %d", ft_is_prime(61)); printf("\n\t check 73 is a prime number: %d", ft_is_prime(73)); printf("\n\t check 20 is a prime number: %d", ft_is_prime(20)); printf("\n\t check 45 is a prime number: %d", ft_is_prime(45)); return (0); } */
the_stack_data/16529.c
/* * (c) Copyright 1993, Silicon Graphics, Inc. * ALL RIGHTS RESERVED * Permission to use, copy, modify, and distribute this software for * any purpose and without fee is hereby granted, provided that the above * copyright notice appear in all copies and that both the copyright notice * and this permission notice appear in supporting documentation, and that * the name of Silicon Graphics, Inc. not be used in advertising * or publicity pertaining to distribution of the software without specific, * written prior permission. * * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. * * US Government Users Restricted Rights * Use, duplication, or disclosure by the Government is subject to * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph * (c)(1)(ii) of the Rights in Technical Data and Computer Software * clause at DFARS 252.227-7013 and/or in similar or successor * clauses in the FAR or the DOD or NASA FAR Supplement. * Unpublished-- rights reserved under the copyright laws of the * United States. Contractor/manufacturer is Silicon Graphics, * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. * * OpenGL(TM) is a trademark of Silicon Graphics, Inc. */ /* * model.c * This program demonstrates the use of OpenGL modeling * transformations. Four triangles are drawn, each with * a different transformation. */ #include <GL/gl.h> #include <GL/glu.h> #include <stdlib.h> void draw_triangle(void) { glBegin(GL_LINE_LOOP); glVertex2f(0.0, 25.0); glVertex2f(25.0, -25.0); glVertex2f(-25.0, -25.0); glEnd(); } /* Clear the screen. For each triangle, set the current * color and modify the modelview matrix. */ void display(void) { glClearColor (0.0, 0.0, 0.0, 1.0); glClear (GL_COLOR_BUFFER_BIT); glLoadIdentity (); glColor3f (1.0, 1.0, 1.0); draw_triangle (); glEnable (GL_LINE_STIPPLE); glLineStipple (1, 0xF0F0); glLoadIdentity (); glTranslatef (-20.0, 0.0, 0.0); draw_triangle (); glLineStipple (1, 0xF00F); glLoadIdentity (); glScalef (1.5, 0.5, 1.0); draw_triangle (); glLineStipple (1, 0x8888); glLoadIdentity (); glRotatef (90.0, 0.0, 0.0, 1.0); draw_triangle (); glDisable (GL_LINE_STIPPLE); glFlush(); } void myinit (void) { glShadeModel (GL_FLAT); } void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho (-50.0, 50.0, -50.0*(GLfloat)h/(GLfloat)w, 50.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0); else glOrtho (-50.0*(GLfloat)w/(GLfloat)h, 50.0*(GLfloat)w/(GLfloat)h, -50.0, 50.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); } int gl_width=500; int gl_height=500; void render_image(void) { myinit(); myReshape(gl_width,gl_height); display(); }
the_stack_data/925777.c
#include <stdio.h> //dato un numero n, inserisco da zero a n una sequenza ordinata di interi tranne uno. Il programma deve stampare il valore mancante. int main(void){ int n; int temp; int cont = 0; int prev = -1; int mancante = -1; printf("inserire la quantità n di numeri da inserire nell'insieme ordinato {0,1,2,...,n}: "); scanf("%d",&n); //finchè non inserico n numeri continuo a leggerli while(cont < n && scanf("%d",&temp)){ //a ogni inserimento controllo se la differenza con il precedente è diversa da uno, in quel caso in mezzo c'è il valore mancante. if((temp - prev) != 1){ mancante = temp -1; break; } prev = temp; cont++; } printf("Il valore mancante è: %d\n",mancante); return 0; }
the_stack_data/142326699.c
// Linked list implementation of Queue in C #include<stdio.h> #include<stdlib.h> struct node { int data; struct node* next; }; struct node* front; struct node* rear; void insert(); void delete(); void display(); void main() { printf("Implementation of Queue using Linked List\n"); int input = 0; while (input != 4) { printf("\n\nEnter the number of your choice:\n"); printf("1. Insert\n"); printf("2. Delete\n"); printf("3. Display\n"); printf("4. Exit\n"); scanf("%d", &input); printf("\n"); switch (input) { case 1: insert(); break; case 2: delete(); break; case 3: display(); break; case 4: exit(0); break; default: printf("Invalid Input\n"); } } } void insert() { struct node* ptr; int item; ptr = (struct node*)malloc(sizeof(struct node)); if (ptr == NULL) { printf("Error : Overflow\n"); return; } else { printf("Enter value?\n"); scanf("%d", &item); ptr->data = item; if (front == NULL) { front = ptr; rear = ptr; front->next = NULL; rear->next = NULL; } else { rear->next = ptr; rear = ptr; rear->next = NULL; } } } void delete () { struct node* ptr; if (front == NULL) { printf("Error : Underflow\n"); return; } else { ptr = front; front = front->next; free(ptr); } } void display() { struct node* ptr; ptr = front; if (front == NULL) { printf("Empty queue\n"); } else { while (ptr != NULL) { printf("%d\n", ptr->data); ptr = ptr->next; } } }
the_stack_data/82949511.c
#include <sys/socket.h> #include <linux/if_packet.h> #include <linux/if_ether.h> #include <net/ethernet.h> /* The l2 protocols */ #include <arpa/inet.h> //htons #include <stdio.h> //perror #include <stdlib.h> // exit #include <unistd.h> //close #include <sys/ioctl.h>//netdevice #include <net/if.h>//ioctl #include <string.h> // exit unsigned char MACorigen[6]; unsigned char MACbroad[6]={0xff,0xff,0xff,0xff,0xff,0xff,}; unsigned char ethertype[2]={0x0c,0x0c}; unsigned char tramaEnv[1514]; unsigned char tramaRec[1514]; int obtenerDatos (int ds) { struct ifreq nic; unsigned char nombre[20]; int i,index; printf("\nInserta el nombre de la interfaz: "); scanf("%s",nombre); strcpy(nic.ifr_name,nombre); if(ioctl(ds,SIOCGIFINDEX,&nic)==-1) { perror("\nError al obtener el index"); exit(0); } else { index=nic.ifr_ifindex; printf("\nEl indice es: %d",index); if(ioctl(ds,SIOCGIFHWADDR,&nic)==-1) { perror("\nError al obtener la MAC"); exit(0); } else { memcpy(MACorigen,nic.ifr_hwaddr.sa_data,6); printf("\nLa MAC es:\n"); for(i=0;i<6;i++) { printf("%.2x:",MACorigen[i]); } } } printf("\n"); return index; } void estructuraTrama(unsigned char *trama) { memcpy(trama+0,MACbroad,6); memcpy(trama+6,MACorigen,6); memcpy(trama+12,ethertype,2); memcpy(trama+14,"Fabian Gaspar Medina",30); } void enviarTrama(int ds, int index,unsigned char *trama) { int tam; struct sockaddr_ll interfaz; memset(&interfaz,0x00,sizeof(interfaz)); interfaz.sll_family=AF_PACKET, interfaz.sll_protocol=htons(ETH_P_ALL); interfaz.sll_ifindex=index; tam=sendto(ds,trama,60,0,(struct sockaddr *)&interfaz,sizeof(interfaz)); if(tam==-1) { perror("\nError al enviar:"); exit(0); } else perror("\n Exito al enviar"); } void imprimirTrama(unsigned char *paq, int len) { int i; for(i=0;i<len;i++) { if(i%16==0) printf("\n"); printf("%.2x:",paq[i]); } printf("\n"); } void recibirTrama(int ds, unsigned char *trama) { int tam; while(1) { tam=recvfrom(ds,trama,1514,0,NULL,0); if(tam==-1) { perror("\n Error al Recibir"); exit(0); } else { imprimirTrama(trama,tam); } } } int main() { int packet_socket,indice; packet_socket = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); if(packet_socket ==-1) { perror("\nError al abrir el socket"); exit(0); } else { perror("\nExito al abrir el socket"); indice=obtenerDatos(packet_socket); estructuraTrama(tramaEnv); enviarTrama(packet_socket,indice,tramaEnv); recibirTrama(packet_socket,tramaRec); } close(packet_socket); return 0; }
the_stack_data/57951556.c
#include<stdio.h> main() {int a,b,c;char x[3];scanf("%d%d%d%s",&a,&b,&c,x); if(x[0]=='A'&&x[1]=='B'&&x[2]=='C')printf("%d %d %d",a,b,c); if(x[0]=='A'&&x[1]=='C'&&x[2]=='B')printf("%d %d %d",a,c,b); if(x[0]=='B'&&x[1]=='A'&&x[2]=='C')printf("%d %d %d",b,a,c); if(x[0]=='B'&&x[1]=='C'&&x[2]=='A')printf("%d %d %d",b,c,a); if(x[0]=='C'&&x[1]=='B'&&x[2]=='A')printf("%d %d %d",c,b,a); if(x[0]=='C'&&x[1]=='A'&&x[2]=='B')printf("%d %d %d",c,a,b); }
the_stack_data/70451051.c
#include <stdio.h> int main() {printf("Hello world!");return 0;}
the_stack_data/968720.c
#include <stdio.h> extern void insertion_sort(int values[], int size); int main(){ int number_count=0; int numbers[] = {1,-900, 484, -78, 194, 518, 326, 125, 549, -145, 531, -416, 978, -416, 979, -421, -391, 841, -129, 561, 166, -3}; number_count = sizeof(numbers)/sizeof(int)-1; insertion_sort(numbers, number_count); int i; for(i=0; i<=number_count; i++){ printf("%d ", numbers[i]); } putchar('\n'); return 0; }
the_stack_data/3479.c
// To be broked by broker01.py void foo() { }
the_stack_data/192330825.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <math.h> #include <time.h> void main(int argc, char *argv[]) { double *mat; double amin=1E39,amax=-1E39; if (argc!=3) { fprintf(stderr,"Usage:\n\t%s <NunRows> <NumCols>\n",argv[0]); exit(1); } int sizex=atoi(argv[1]); int sizey=atoi(argv[2]); if (sizex<=0 || sizey <=0) { fprintf(stderr,"Illegal input parameter(s)\n"); exit(1); } int size=sizex*sizey*sizeof(double); mat=malloc(size); if (!mat) { perror("malloc"); exit(1); } srand((unsigned)time(NULL)); for (int i=0; i<sizex; i++) { for (int j=0; j<sizey; j++) { double f=(double)rand()/RAND_MAX; mat[i*sizey+j] = f; if (f>amax) amax=f; else if (f<amin) amin=f; } } for (int i=0; i<sizex; i++) { for (int j=0; j<sizey; j++) { fprintf(stderr,"%f ",mat[i*sizey+j]); } fprintf(stderr,"\n"); } printf("\n=====\nMin: %lf\nMax: %lf\n=====\n",amin,amax); FILE *fp=fopen("input.file","wb"); if (!fp) { perror("fopen"); exit(1); } if (fwrite(&sizex,1,sizeof(int),fp)<0) { perror("write"); exit(1); } if (fwrite(&sizey,1,sizeof(int),fp)<0) { perror("write"); exit(1); } if (fwrite(mat,1,size,fp)<0) { perror("write"); exit(1); } fclose(fp); exit(0); }
the_stack_data/193893372.c
#include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; #ifdef _MSC_VER static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;} static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;} static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;} static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;} #else static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #endif #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #ifdef _MSC_VER #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);} #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/Cd(b)._Val[1]);} #else #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #endif #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimagf(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle_() continue; #define myceiling_(w) {ceil(w)} #define myhuge_(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc_(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #ifdef _MSC_VER static _Fcomplex cpow_ui(complex x, integer n) { complex pow={1.0,0.0}; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i; for(u = n; ; ) { if(u & 01) pow.r *= x.r, pow.i *= x.i; if(u >>= 1) x.r *= x.r, x.i *= x.i; else break; } } _Fcomplex p={pow.r, pow.i}; return p; } #else static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #endif #ifdef _MSC_VER static _Dcomplex zpow_ui(_Dcomplex x, integer n) { _Dcomplex pow={1.0,0.0}; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1]; for(u = n; ; ) { if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1]; if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1]; else break; } } _Dcomplex p = {pow._Val[0], pow._Val[1]}; return p; } #else static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #endif static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Fcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0]; zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0]; zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1]; } } pCf(z) = zdotc; } #else _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } #endif static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Dcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0]; zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0]; zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1]; } } pCd(z) = zdotc; } #else _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Fcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0]; zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0]; zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1]; } } pCf(z) = zdotc; } #else _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } #endif static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Dcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0]; zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0]; zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1]; } } pCd(z) = zdotc; } #else _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static doublecomplex c_b1 = {1.,0.}; static integer c__1 = 1; /* > \brief \b ZSPRFS */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download ZSPRFS + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zsprfs. f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zsprfs. f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zsprfs. f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE ZSPRFS( UPLO, N, NRHS, AP, AFP, IPIV, B, LDB, X, LDX, */ /* FERR, BERR, WORK, RWORK, INFO ) */ /* CHARACTER UPLO */ /* INTEGER INFO, LDB, LDX, N, NRHS */ /* INTEGER IPIV( * ) */ /* DOUBLE PRECISION BERR( * ), FERR( * ), RWORK( * ) */ /* COMPLEX*16 AFP( * ), AP( * ), B( LDB, * ), WORK( * ), */ /* $ X( LDX, * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > ZSPRFS improves the computed solution to a system of linear */ /* > equations when the coefficient matrix is symmetric indefinite */ /* > and packed, and provides error bounds and backward error estimates */ /* > for the solution. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] UPLO */ /* > \verbatim */ /* > UPLO is CHARACTER*1 */ /* > = 'U': Upper triangle of A is stored; */ /* > = 'L': Lower triangle of A is stored. */ /* > \endverbatim */ /* > */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The order of the matrix A. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] NRHS */ /* > \verbatim */ /* > NRHS is INTEGER */ /* > The number of right hand sides, i.e., the number of columns */ /* > of the matrices B and X. NRHS >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] AP */ /* > \verbatim */ /* > AP is COMPLEX*16 array, dimension (N*(N+1)/2) */ /* > The upper or lower triangle of the symmetric matrix A, packed */ /* > columnwise in a linear array. The j-th column of A is stored */ /* > in the array AP as follows: */ /* > if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j; */ /* > if UPLO = 'L', AP(i + (j-1)*(2*n-j)/2) = A(i,j) for j<=i<=n. */ /* > \endverbatim */ /* > */ /* > \param[in] AFP */ /* > \verbatim */ /* > AFP is COMPLEX*16 array, dimension (N*(N+1)/2) */ /* > The factored form of the matrix A. AFP contains the block */ /* > diagonal matrix D and the multipliers used to obtain the */ /* > factor U or L from the factorization A = U*D*U**T or */ /* > A = L*D*L**T as computed by ZSPTRF, stored as a packed */ /* > triangular matrix. */ /* > \endverbatim */ /* > */ /* > \param[in] IPIV */ /* > \verbatim */ /* > IPIV is INTEGER array, dimension (N) */ /* > Details of the interchanges and the block structure of D */ /* > as determined by ZSPTRF. */ /* > \endverbatim */ /* > */ /* > \param[in] B */ /* > \verbatim */ /* > B is COMPLEX*16 array, dimension (LDB,NRHS) */ /* > The right hand side matrix B. */ /* > \endverbatim */ /* > */ /* > \param[in] LDB */ /* > \verbatim */ /* > LDB is INTEGER */ /* > The leading dimension of the array B. LDB >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[in,out] X */ /* > \verbatim */ /* > X is COMPLEX*16 array, dimension (LDX,NRHS) */ /* > On entry, the solution matrix X, as computed by ZSPTRS. */ /* > On exit, the improved solution matrix X. */ /* > \endverbatim */ /* > */ /* > \param[in] LDX */ /* > \verbatim */ /* > LDX is INTEGER */ /* > The leading dimension of the array X. LDX >= f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[out] FERR */ /* > \verbatim */ /* > FERR is DOUBLE PRECISION array, dimension (NRHS) */ /* > The estimated forward error bound for each solution vector */ /* > X(j) (the j-th column of the solution matrix X). */ /* > If XTRUE is the true solution corresponding to X(j), FERR(j) */ /* > is an estimated upper bound for the magnitude of the largest */ /* > element in (X(j) - XTRUE) divided by the magnitude of the */ /* > largest element in X(j). The estimate is as reliable as */ /* > the estimate for RCOND, and is almost always a slight */ /* > overestimate of the true error. */ /* > \endverbatim */ /* > */ /* > \param[out] BERR */ /* > \verbatim */ /* > BERR is DOUBLE PRECISION array, dimension (NRHS) */ /* > The componentwise relative backward error of each solution */ /* > vector X(j) (i.e., the smallest relative change in */ /* > any element of A or B that makes X(j) an exact solution). */ /* > \endverbatim */ /* > */ /* > \param[out] WORK */ /* > \verbatim */ /* > WORK is COMPLEX*16 array, dimension (2*N) */ /* > \endverbatim */ /* > */ /* > \param[out] RWORK */ /* > \verbatim */ /* > RWORK is DOUBLE PRECISION array, dimension (N) */ /* > \endverbatim */ /* > */ /* > \param[out] INFO */ /* > \verbatim */ /* > INFO is INTEGER */ /* > = 0: successful exit */ /* > < 0: if INFO = -i, the i-th argument had an illegal value */ /* > \endverbatim */ /* > \par Internal Parameters: */ /* ========================= */ /* > */ /* > \verbatim */ /* > ITMAX is the maximum number of steps of iterative refinement. */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date December 2016 */ /* > \ingroup complex16OTHERcomputational */ /* ===================================================================== */ /* Subroutine */ int zsprfs_(char *uplo, integer *n, integer *nrhs, doublecomplex *ap, doublecomplex *afp, integer *ipiv, doublecomplex * b, integer *ldb, doublecomplex *x, integer *ldx, doublereal *ferr, doublereal *berr, doublecomplex *work, doublereal *rwork, integer * info) { /* System generated locals */ integer b_dim1, b_offset, x_dim1, x_offset, i__1, i__2, i__3, i__4, i__5; doublereal d__1, d__2, d__3, d__4; doublecomplex z__1; /* Local variables */ integer kase; doublereal safe1, safe2; integer i__, j, k; doublereal s; extern logical lsame_(char *, char *); integer isave[3], count; logical upper; extern /* Subroutine */ int zcopy_(integer *, doublecomplex *, integer *, doublecomplex *, integer *), zaxpy_(integer *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, integer *), zspmv_( char *, integer *, doublecomplex *, doublecomplex *, doublecomplex *, integer *, doublecomplex *, doublecomplex *, integer *), zlacn2_(integer *, doublecomplex *, doublecomplex *, doublereal *, integer *, integer *); integer ik, kk; extern doublereal dlamch_(char *); doublereal xk; integer nz; doublereal safmin; extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); doublereal lstres; extern /* Subroutine */ int zsptrs_(char *, integer *, integer *, doublecomplex *, integer *, doublecomplex *, integer *, integer *); doublereal eps; /* -- LAPACK computational routine (version 3.7.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* December 2016 */ /* ===================================================================== */ /* Test the input parameters. */ /* Parameter adjustments */ --ap; --afp; --ipiv; b_dim1 = *ldb; b_offset = 1 + b_dim1 * 1; b -= b_offset; x_dim1 = *ldx; x_offset = 1 + x_dim1 * 1; x -= x_offset; --ferr; --berr; --work; --rwork; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*nrhs < 0) { *info = -3; } else if (*ldb < f2cmax(1,*n)) { *info = -8; } else if (*ldx < f2cmax(1,*n)) { *info = -10; } if (*info != 0) { i__1 = -(*info); xerbla_("ZSPRFS", &i__1, (ftnlen)6); return 0; } /* Quick return if possible */ if (*n == 0 || *nrhs == 0) { i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { ferr[j] = 0.; berr[j] = 0.; /* L10: */ } return 0; } /* NZ = maximum number of nonzero elements in each row of A, plus 1 */ nz = *n + 1; eps = dlamch_("Epsilon"); safmin = dlamch_("Safe minimum"); safe1 = nz * safmin; safe2 = safe1 / eps; /* Do for each right hand side */ i__1 = *nrhs; for (j = 1; j <= i__1; ++j) { count = 1; lstres = 3.; L20: /* Loop until stopping criterion is satisfied. */ /* Compute residual R = B - A * X */ zcopy_(n, &b[j * b_dim1 + 1], &c__1, &work[1], &c__1); z__1.r = -1., z__1.i = 0.; zspmv_(uplo, n, &z__1, &ap[1], &x[j * x_dim1 + 1], &c__1, &c_b1, & work[1], &c__1); /* Compute componentwise relative backward error from formula */ /* f2cmax(i) ( abs(R(i)) / ( abs(A)*abs(X) + abs(B) )(i) ) */ /* where abs(Z) is the componentwise absolute value of the matrix */ /* or vector Z. If the i-th component of the denominator is less */ /* than SAFE2, then SAFE1 is added to the i-th components of the */ /* numerator and denominator before dividing. */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__ + j * b_dim1; rwork[i__] = (d__1 = b[i__3].r, abs(d__1)) + (d__2 = d_imag(&b[ i__ + j * b_dim1]), abs(d__2)); /* L30: */ } /* Compute abs(A)*abs(X) + abs(B). */ kk = 1; if (upper) { i__2 = *n; for (k = 1; k <= i__2; ++k) { s = 0.; i__3 = k + j * x_dim1; xk = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[k + j * x_dim1]), abs(d__2)); ik = kk; i__3 = k - 1; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = ik; rwork[i__] += ((d__1 = ap[i__4].r, abs(d__1)) + (d__2 = d_imag(&ap[ik]), abs(d__2))) * xk; i__4 = ik; i__5 = i__ + j * x_dim1; s += ((d__1 = ap[i__4].r, abs(d__1)) + (d__2 = d_imag(&ap[ ik]), abs(d__2))) * ((d__3 = x[i__5].r, abs(d__3)) + (d__4 = d_imag(&x[i__ + j * x_dim1]), abs(d__4) )); ++ik; /* L40: */ } i__3 = kk + k - 1; rwork[k] = rwork[k] + ((d__1 = ap[i__3].r, abs(d__1)) + (d__2 = d_imag(&ap[kk + k - 1]), abs(d__2))) * xk + s; kk += k; /* L50: */ } } else { i__2 = *n; for (k = 1; k <= i__2; ++k) { s = 0.; i__3 = k + j * x_dim1; xk = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[k + j * x_dim1]), abs(d__2)); i__3 = kk; rwork[k] += ((d__1 = ap[i__3].r, abs(d__1)) + (d__2 = d_imag(& ap[kk]), abs(d__2))) * xk; ik = kk + 1; i__3 = *n; for (i__ = k + 1; i__ <= i__3; ++i__) { i__4 = ik; rwork[i__] += ((d__1 = ap[i__4].r, abs(d__1)) + (d__2 = d_imag(&ap[ik]), abs(d__2))) * xk; i__4 = ik; i__5 = i__ + j * x_dim1; s += ((d__1 = ap[i__4].r, abs(d__1)) + (d__2 = d_imag(&ap[ ik]), abs(d__2))) * ((d__3 = x[i__5].r, abs(d__3)) + (d__4 = d_imag(&x[i__ + j * x_dim1]), abs(d__4) )); ++ik; /* L60: */ } rwork[k] += s; kk += *n - k + 1; /* L70: */ } } s = 0.; i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { if (rwork[i__] > safe2) { /* Computing MAX */ i__3 = i__; d__3 = s, d__4 = ((d__1 = work[i__3].r, abs(d__1)) + (d__2 = d_imag(&work[i__]), abs(d__2))) / rwork[i__]; s = f2cmax(d__3,d__4); } else { /* Computing MAX */ i__3 = i__; d__3 = s, d__4 = ((d__1 = work[i__3].r, abs(d__1)) + (d__2 = d_imag(&work[i__]), abs(d__2)) + safe1) / (rwork[i__] + safe1); s = f2cmax(d__3,d__4); } /* L80: */ } berr[j] = s; /* Test stopping criterion. Continue iterating if */ /* 1) The residual BERR(J) is larger than machine epsilon, and */ /* 2) BERR(J) decreased by at least a factor of 2 during the */ /* last iteration, and */ /* 3) At most ITMAX iterations tried. */ if (berr[j] > eps && berr[j] * 2. <= lstres && count <= 5) { /* Update solution and try again. */ zsptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[1], n, info); zaxpy_(n, &c_b1, &work[1], &c__1, &x[j * x_dim1 + 1], &c__1); lstres = berr[j]; ++count; goto L20; } /* Bound error from formula */ /* norm(X - XTRUE) / norm(X) .le. FERR = */ /* norm( abs(inv(A))* */ /* ( abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) / norm(X) */ /* where */ /* norm(Z) is the magnitude of the largest component of Z */ /* inv(A) is the inverse of A */ /* abs(Z) is the componentwise absolute value of the matrix or */ /* vector Z */ /* NZ is the maximum number of nonzeros in any row of A, plus 1 */ /* EPS is machine epsilon */ /* The i-th component of abs(R)+NZ*EPS*(abs(A)*abs(X)+abs(B)) */ /* is incremented by SAFE1 if the i-th component of */ /* abs(A)*abs(X) + abs(B) is less than SAFE2. */ /* Use ZLACN2 to estimate the infinity-norm of the matrix */ /* inv(A) * diag(W), */ /* where W = abs(R) + NZ*EPS*( abs(A)*abs(X)+abs(B) ))) */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { if (rwork[i__] > safe2) { i__3 = i__; rwork[i__] = (d__1 = work[i__3].r, abs(d__1)) + (d__2 = d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__] ; } else { i__3 = i__; rwork[i__] = (d__1 = work[i__3].r, abs(d__1)) + (d__2 = d_imag(&work[i__]), abs(d__2)) + nz * eps * rwork[i__] + safe1; } /* L90: */ } kase = 0; L100: zlacn2_(n, &work[*n + 1], &work[1], &ferr[j], &kase, isave); if (kase != 0) { if (kase == 1) { /* Multiply by diag(W)*inv(A**T). */ zsptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[1], n, info); i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__; i__4 = i__; i__5 = i__; z__1.r = rwork[i__4] * work[i__5].r, z__1.i = rwork[i__4] * work[i__5].i; work[i__3].r = z__1.r, work[i__3].i = z__1.i; /* L110: */ } } else if (kase == 2) { /* Multiply by inv(A)*diag(W). */ i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { i__3 = i__; i__4 = i__; i__5 = i__; z__1.r = rwork[i__4] * work[i__5].r, z__1.i = rwork[i__4] * work[i__5].i; work[i__3].r = z__1.r, work[i__3].i = z__1.i; /* L120: */ } zsptrs_(uplo, n, &c__1, &afp[1], &ipiv[1], &work[1], n, info); } goto L100; } /* Normalize error. */ lstres = 0.; i__2 = *n; for (i__ = 1; i__ <= i__2; ++i__) { /* Computing MAX */ i__3 = i__ + j * x_dim1; d__3 = lstres, d__4 = (d__1 = x[i__3].r, abs(d__1)) + (d__2 = d_imag(&x[i__ + j * x_dim1]), abs(d__2)); lstres = f2cmax(d__3,d__4); /* L130: */ } if (lstres != 0.) { ferr[j] /= lstres; } /* L140: */ } return 0; /* End of ZSPRFS */ } /* zsprfs_ */
the_stack_data/54824026.c
// RUN: sed -e "s:INPUT_DIR:%S/Inputs:g" -e "s:OUT_DIR:%t:g" %S/Inputs/vfsoverlay.yaml > %t.yaml // RUN: %clang_cc1 -Werror -ivfsoverlay %t.yaml -I %t -include "not_real.h" -fsyntax-only %s // REQUIRES: shell void foo() { bar(); }
the_stack_data/881213.c
#include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct { char name[50]; int count; } List; void printList(List *list, int y) { for( int i = 0; i < y; i++) { printf("Palavra: %s, vezes: %d \n", list[i].name, list[i].count); } } int genererate(char phrase[10][50], int y) { y += 1; List list[y]; for ( int i = 0; i < y; i++ ) { list[i].count = 1; for ( int j = 0; j < y; j++ ) { if ( strcmp(phrase[i], phrase[j]) == 0 && i != j) { strcpy(list[i].name, phrase[i]); list[i].count += 1; } } } printList(list,y); return 0; } void printBV(char phrase[10][50], int y) { for (int i = 0; i <= y; i++) { printf("%s\n", phrase[i]); } } void toLowerCase(char *phrase) { for (int i = 0; i < strlen(phrase); i++) { phrase[i] = tolower(phrase[i]); } } char *mostRepetitiveWorld(char *phrase) { int words = 0; char vector[10][50]; for (int i = 0; i < strlen(phrase); i++) { if (phrase[i] == ' ') { words++; } } int i = 0; int j = 0; int k = 0; while (j <= words) { while (phrase[i] != ' ' && phrase[i] != '\0') { vector[j][i - k] = phrase[i]; i++; } vector[j][i - k] = '\0'; i++; j++; k = i; } /* printBV(vector, words); */ genererate(vector, words); return phrase; } int main(void) { char string[] = "Bom dia como vai você bom dia como"; toLowerCase(string); /* printf("%s\n", string); */ mostRepetitiveWorld(string); return 0; }
the_stack_data/152347.c
#include <stdio.h> #include <stdlib.h> #include <string.h> void print_flag() { char flag[64]; FILE *f = fopen("./flag.txt", "rt"); if (f == NULL) { puts("No flag.txt found"); return; } fgets(flag, 64, f); fclose(f); puts(flag); } void vuln() { char *src = malloc(16); char dest[8]; memset(src, 0, sizeof(src)); memset(dest, 0, sizeof(dest)); gets(src); if(!strncmp(src, "admin", 5)){ strncpy(dest, src, 9uLL); printf("Logged as %s! print_flag is here: %p\n", dest, print_flag); gets(dest); } free(src); } int main() { setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stdin, NULL, _IONBF, 0); vuln(); return 0; }
the_stack_data/704871.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_isalpha.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: lrudowic <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/29 12:59:59 by lrudowic #+# #+# */ /* Updated: 2019/05/20 16:40:13 by lrudowic ### ########.fr */ /* */ /* ************************************************************************** */ int ft_isalpha(int c) { if ((c <= 'z' && c >= 'a') || (c <= 'Z' && c >= 'A')) return (1); return (0); }
the_stack_data/44432.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> int main(void) { pid_t p = fork(); if ( p == -1 ) { perror("fork failed"); return EXIT_FAILURE; } else if ( p == 0 ) { execl("/bin/sh", "bin/sh", "-c", "./failing", "NULL"); return EXIT_FAILURE; } int status; if ( waitpid(p, &status, 0) == -1 ) { perror("waitpid failed"); return EXIT_FAILURE; } if ( WIFEXITED(status) ) { const int es = WEXITSTATUS(status); printf("exit status was %d\n", es); } return EXIT_SUCCESS; }
the_stack_data/73574969.c
#include <stddef.h> #include <stdint.h> #define KVM_HYPERCALL "vmcall" #define KVM_HC_HELLO_HYPERCALL 12 static void outb(uint16_t port, uint8_t value) { asm("outb %0,%1" : /* empty */ : "a" (value), "Nd" (port) : "memory"); } static inline long kvm_hypercall0(unsigned int nr) { long ret; asm volatile(KVM_HYPERCALL : "=a"(ret) : "a"(nr) : "memory"); return ret; } static inline long kvm_vmfunc(unsigned int eptp) { long ret; asm volatile("vmfunc" : "=q"(ret) : "c" (eptp), "a" (0) : "cc"); return ret; } void __attribute__((noreturn)) __attribute__((section(".start"))) _start(void) { const char *p; for (p = "Hello, world!\n"; *p; ++p) outb(0xE9, *p); *(long *) 0x400 = 42; kvm_hypercall0(KVM_HC_HELLO_HYPERCALL); kvm_vmfunc(0); kvm_hypercall0(KVM_HC_HELLO_HYPERCALL); kvm_vmfunc(1); kvm_hypercall0(KVM_HC_HELLO_HYPERCALL); kvm_vmfunc(2); for (;;) asm("hlt" : /* empty */ : "a" (42) : "memory"); }
the_stack_data/63374.c
int foo (int x) { return x; }
the_stack_data/162643849.c
#include <stdio.h> int main() { puts("ok"); return 0; }
the_stack_data/125849.c
#include<stdio.h> int main() { int n; scanf("%d",&n); int arr[n]; for(int i=0;i<n;i++) { scanf("%d",&arr[i]); } int l=0,ml=0,c=0,st; int arr2[n]; for(int i=0;i<n-1;i++) { if(arr[i]<=arr[i+1]) { l++; if(l>=ml) { ml=l; st=(i+1)-l; } } else { if(l==ml) { arr2[c]=st; c++; } l=0; } } for(int i=0;i<c;i++) { printf("%d ",arr[st+i]); } return 0; }
the_stack_data/115764212.c
#include <stdio.h> #include <string.h> const unsigned int FLAG_LEN = 26; void reset_flags_and_increment(unsigned int * flags, unsigned int * sum, int record_group) { for (int i=0; i < FLAG_LEN; i++) { if (flags[i] == record_group) { *sum += 1; } flags[i] = 0; } } int main( ) { unsigned int flags[FLAG_LEN]; char buf[FLAG_LEN*2]; unsigned int sum; unsigned int record_group = 0; FILE* fp = fopen("input" , "r"); if(fp == NULL) { perror("Error opening file"); return(-1); } // reset flags reset_flags_and_increment(flags, &sum, 9999); sum = 0; while (fgets(buf, FLAG_LEN*2-1, fp) != NULL) { if (strlen(buf) == 0 || buf[0] == '\n') { reset_flags_and_increment(flags, &sum, record_group); record_group = 0; } else if (strlen(buf) > 0) { int i = 0; while (buf[i] != '\n' && i < strlen(buf)) { int pos = buf[i] - 'a'; if (pos >= 0 && pos < FLAG_LEN) { flags[pos] += 1; } i++; } record_group++; } } reset_flags_and_increment(flags, &sum, record_group); printf("%d\n", sum); fclose(fp); return 0; }
the_stack_data/145451964.c
#include <stdio.h> #include <sys/time.h> #define MILLION 1000000L #define NUMDIF 20 int main(void) { int i; int numcalls = 1; int numdone = 0; long sum = 0; long timedif[NUMDIF]; struct timeval tlast; struct timeval tthis; if (gettimeofday(&tlast, NULL)) { fprintf(stderr, "Failed to get first gettimeofday.\n"); return 1; } while (numdone < NUMDIF) { numcalls++; if (gettimeofday(&tthis, NULL)) { fprintf(stderr, "Failed to get a later gettimeofday.\n"); return 1; } timedif[numdone] = MILLION*(tthis.tv_sec - tlast.tv_sec) + tthis.tv_usec - tlast.tv_usec; if (timedif[numdone] != 0) { numdone++; tlast = tthis; } } printf("Found %d differences in gettimeofday:\n", NUMDIF); printf("%d calls to gettimeofday were required\n", numcalls); for (i = 0; i < NUMDIF; i++) { printf("%2d: %10ld microseconds\n", i, timedif[i]); sum += timedif[i]; } printf("The average nonzero difference is %f\n", sum/(double)NUMDIF); return 0; }
the_stack_data/83632.c
/* PR c/6223 This testcase ICEd in internal check because a constant was not truncated for its mode. */ /* { dg-do compile } */ /* { dg-options "-O2" } */ /* { dg-options "-O2 -march=i686" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */ #if __INT_MAX__ > 32767 typedef struct { unsigned a : 16; unsigned b : 16; unsigned c : 5; unsigned d : 2; unsigned e : 1; unsigned f : 4; unsigned g : 1; unsigned h : 1; unsigned i : 1; unsigned j : 1; } T; inline void foo (T *x, unsigned int y) { if ((x->j = (y >= 0x100000))) y >>= 12; x->a = y; x->f = (y >> 16); } void __attribute__((noinline)) bar (T *x) { } void baz (unsigned int x, unsigned char y) { T t; foo (&t, x - 1); t.e = 1; t.c = y; t.g = 0; t.h = 0; t.i = (y & 0x40) != 0; if (x == 1) foo (&t, 1); bar (&t); } #endif /* __INT_MAX__ */
the_stack_data/665246.c
#include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <signal.h> void child_code(int delay); void parent_code(void); void sigchld_handler(int signum); int main(void) { int fork_ret; fork_ret = fork(); if (fork_ret == -1) { perror("fork"); } else if (fork_ret == 0) { child_code(2); } else { parent_code(); } exit(0); } void child_code(int delay) { printf("in child, my pid is %d\nsleep(%d)\n", getpid(), delay); sleep(delay); printf("out child\n"); } void parent_code(void) { signal(SIGCHLD, sigchld_handler); while (1) { pause(); } } void sigchld_handler(int signum) { printf("in handler and receive SIGCHLD\n"); exit(0); }
the_stack_data/100141451.c
#include <stdio.h> static char *text[] = { "Export of this program from the USA is governed by the US", "Munitions List from the ITAR (International Traffic in Arms", "Regulations). This list gives the specific categories of", "restricted exports and includes cryptographic exports. Traffic", "entirely external to, entirely internal to, or into the USA is", "not restricted.", "To obtain a copy of the program, email to [email protected]", "with a subject \"IOCCC request\". If you know that your 'From'", "line is incorrect, add a single line", "\"replyto [email protected]\" to the body of the message.", "A deamon will autoreply.", "WARNING: You must not re-export this out of the USA, or else", "the men in black might get you.", NULL }; int main() { char **ptr; for(ptr = text; *ptr; ptr++) printf("%s\n", *ptr); return 0; }
the_stack_data/242329649.c
/* * critical-unrelated.c -- Archer testcase */ //===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // // See tools/archer/LICENSE.txt for details. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // RUN: %libarcher-compile-and-run-race | FileCheck %s // RUN: %libarcher-compile-and-run-race-noserial | FileCheck %s // REQUIRES: tsan #include <omp.h> #include <stdio.h> int main(int argc, char *argv[]) { int var = 0; #pragma omp parallel num_threads(2) shared(var) { #pragma omp critical { // Dummy region. } var++; } fprintf(stderr, "DONE\n"); } // CHECK: WARNING: ThreadSanitizer: data race // CHECK-NEXT: {{(Write|Read)}} of size 4 // CHECK-NEXT: #0 {{.*}}critical-unrelated.c:29 // CHECK: Previous write of size 4 // CHECK-NEXT: #0 {{.*}}critical-unrelated.c:29 // CHECK: DONE // CHECK: ThreadSanitizer: reported 1 warnings
the_stack_data/232956037.c
#include <stdio.h> int main(){ int num, i, isPrime; isPrime = 1; printf("Enter a number: "); scanf("%d", &num); for(i=2;i<num;i++){ if(num % i == 0){ isPrime = 0; break; } } if(num > 1 && isPrime == 1){ printf("\n%d is a prime number\n", num); for(i=num;i>=-3;i--){ printf(" %d ", i); } }else{ printf("\n%d is not a prime number\n", num); } return 0; }
the_stack_data/92325433.c
#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <sys/stat.h> void daemonize(void) { pid_t pid; /* * * 成为一个新会话的首进程,失去控制终端 * */ if ((pid = fork()) < 0) { perror("fork"); exit(1); } else if (pid != 0) /* parent */ exit(0); setsid(); /* * * 改变当前工作目录到/目录下. * */ if (chdir("/") < 0) { perror("chdir"); exit(1); } /* 设置umask为0 */ umask(0); /* * * 重定向0,1,2文件描述符到 /dev/null,因为已经失去控制终端,再操作0,1,2没有意义. * */ close(0); open("/dev/null", O_RDWR); dup2(0, 1); dup2(0, 2); } int main(void) { daemonize(); while(1); /* 在此循环中可以实现守护进程的核心工作 */ }
the_stack_data/234517786.c
/* * Copyright (c) 2007 - 2015 Joseph Gaeddert * * 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. */ // // math_csqrtf_test.c // // complex square root test // #include <stdio.h> #include <stdlib.h> #include <complex.h> #include <math.h> #define sandbox_randf() ((float) rand() / (float) RAND_MAX) float complex sandbox_csqrtf(float complex _z) { float r = cabsf(_z); // magnitude of _z float a = crealf(_z); // real component of _z float re = sqrtf(0.5f*(r+a)); // real component of return value float im = sqrtf(0.5f*(r-a)); // imag component of return value // return value, retaining sign of imaginary component return cimagf(_z) > 0 ? re + _Complex_I*im : re - _Complex_I*im; } int main() { unsigned int n=32; // number of tests unsigned int d=2; // number of items per line // data arrays float complex z[n]; float complex test[n]; float complex err_max = 0.0f; unsigned int i; for (i=0; i<n; i++) { // generate random complex number z[i] = 2.0f*(2.0f*sandbox_randf() - 1.0f) + 2.0f*(2.0f*sandbox_randf() - 1.0f) * _Complex_I; test[i] = csqrtf(z[i]); float complex sqrtz_hat = sandbox_csqrtf(z[i]); float complex err = test[i] - sqrtz_hat; printf("%3u: z=%6.2f+j%6.2f, sqrt(z)=%6.2f+j%6.2f (%6.2f+j%6.2f) e=%12.4e\n", i, crealf(test[i]), cimagf(z[i]), crealf(test[i]), cimagf(test[i]), crealf(sqrtz_hat), cimagf(sqrtz_hat), cabsf(err)); if ( cabsf(err) > cabsf(err_max) ) err_max = err; } printf("maximum error: %12.4e;\n", cabsf(err_max)); // // print autotest lines // printf("\n"); printf(" float complex z[%u] = {\n ", n); for (i=0; i<n; i++) { printf("%12.4e+_Complex_I*%12.4e", crealf(z[i]), cimagf(z[i])); if ( i == n-1) printf(" "); else if ( ((i+1)%d)==0 ) printf(",\n "); else printf(", "); } printf("};\n"); printf("\n"); printf(" float complex test[%u] = {\n ", n); for (i=0; i<n; i++) { printf("%12.4e+_Complex_I*%12.4e", crealf(test[i]), cimagf(test[i])); if ( i == n-1) printf(" "); else if ( ((i+1)%d)==0 ) printf(",\n "); else printf(", "); } printf("};\n"); printf("done.\n"); return 0; }
the_stack_data/190769385.c
/* echo-thread.c * * Copyright (c) 2000 Sean Walton and Macmillan Publishers. Use may be in * whole or in part in accordance to the General Public License (GPL). * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /*****************************************************************************/ /*** echo-thread.c ***/ /*** ***/ /*** An echo server using threads. ***/ /*****************************************************************************/ #include <stdlib.h> #include <errno.h> #include <unistd.h> #include <string.h> #include <sys/wait.h> #include <sys/socket.h> #include <resolv.h> #include <arpa/inet.h> #include <pthread.h> void PANIC(char* msg); #define PANIC(msg) { perror(msg); exit(-1); } /*--------------------------------------------------------------------*/ /*--- Child - echo servlet ---*/ /*--------------------------------------------------------------------*/ void* Child(void* arg) { char line[100]; int bytes_read; int client = *(int *)arg; do { bytes_read = recv(client, line, sizeof(line), 0); send(client, line, bytes_read, 0); } while (strncmp(line, "bye\r", 4) != 0); close(client); return arg; } /*--------------------------------------------------------------------*/ /*--- main - setup server and await connections (no need to clean ---*/ /*--- up after terminated children. ---*/ /*--------------------------------------------------------------------*/ int main(void) { int sd; struct sockaddr_in addr; if ( (sd = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) PANIC("Socket"); addr.sin_family = AF_INET; addr.sin_port = htons(9999); addr.sin_addr.s_addr = INADDR_ANY; if ( bind(sd, (struct sockaddr*)&addr, sizeof(addr)) != 0 ) PANIC("Bind"); if ( listen(sd, 20) != 0 ) PANIC("Listen"); while (1) { int client, addr_size = sizeof(addr); pthread_t child; client = accept(sd, (struct sockaddr*)&addr, &addr_size); printf("Connected: %s:%d\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port)); if ( pthread_create(&child, NULL, Child, &client) != 0 ) perror("Thread creation"); else pthread_detach(child); /* disassociate from parent */ } return 0; }
the_stack_data/127451.c
/* ** EPITECH PROJECT, 2018 ** my_strlen.c ** File description: ** By Germain Gadel */ int my_strlen(char const *str) { int i = 0; while (str[i] != '\0') { i++; } return (i); }
the_stack_data/148579086.c
#include <stdio.h> int main() { int i, j, n, e, DiagPrinCres, DiagPrinDecres, DiagSecCres, DiagSecDecres, primary, secundary; scanf("%d", &n); for(i = 1; i <= n; i++) { for(j = 1; j <= n; j++) { scanf("%d", &e); if(j == i) { /*Entra na diagonal principal*/ if(j == 1 && i == 1) { DiagPrinCres = e; DiagPrinDecres = e; }else { if(e > DiagPrinCres) { /*Verifica se eh crescente*/ DiagPrinCres = e; if(j == n && i == n) { primary = 1; } }else { if(e < DiagPrinDecres) { DiagPrinDecres = e; /*Verifica se eh decrescente*/ if(j == n && i == n) { primary = 2; } } } } }else { if((i + j) == (n + 1)) { /*Entra na diagonal secundaria*/ if(j == n && i == 1) { DiagSecCres = e; DiagSecDecres = e; }else { if(e > DiagSecCres) { /*Verifica se eh crescente*/ DiagSecCres = e; if(j == 1 && i == n) { secundary = 1; } }else { if(e < DiagSecDecres) { DiagSecDecres = e; /*Verifica se eh decrescente*/ if(j == 1 && i == n) { secundary = 2; } } } } } } } } if((primary == 1 && secundary == 2) || (primary == 2 && secundary == 1)) { printf("diagonais invertidas\n"); }else { printf("nada de especial\n"); } return 0; }