file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/153940.c
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright by The HDF Group. * * All rights reserved. * * * * This file is part of HDF5. The full HDF5 copyright notice, including * * terms governing use, modification, and redistribution, is contained in * * the COPYING file, which can be found at the root of the source code * * distribution tree, or in https://www.hdfgroup.org/licenses. * * If you do not have access to either file, you may request a copy from * * [email protected]. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /*------------------------------------------------------------------------- * * Created: atomic_writer.c * * Purpose: This is the "writer" part of the standalone test to check * atomic read-write operation on a system. * a) atomic_writer.c--the writer (this file) * b) atomic_reader.c--the reader * c) atomic_data--the name of the data file used by writer and reader * *------------------------------------------------------------------------- */ /***********/ /* Headers */ /***********/ #include <assert.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #if !defined(WIN32) && !defined(__MINGW32__) #include <fcntl.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/wait.h> /****************/ /* Local Macros */ /****************/ #define FILENAME "atomic_data" /********************/ /* Local Prototypes */ /********************/ static void usage(void); /*------------------------------------------------------------------------- * Function: usage * * Purpose: To print information about the command line options * * Parameters: None * * Return: void * *------------------------------------------------------------------------- */ static void usage(void) { printf("\n"); printf("Usage error!\n"); printf("Usage: atomic_writer -n <number of integers to write> -i <number of iterations for writer>\n"); printf(" Note**The number of integers for option n has to be positive\n"); printf(" Note**The number of integers for option i has to be positive\n"); printf("\n"); } /* usage() */ /*------------------------------------------------------------------------- * Function: main * * Purpose: To write a series of integers to a file for the reader to verify the data. * A write is atomic if the whole amount written in one operation is not interleaved * with data from any other process. * (1) Iterate with i iterations * (2) Write a series of integers (0 to n-1) to the file with this pattern: * offset 0: 0000000000000000000000000000000 * offset 1: 111111111111111111111111111111 * offset 2: 22222222222222222222222222222 * offset 3: 3333333333333333333333333333 * ... * ... * offset n-1: (n-1) * * At the end of the writes, the data in the file will be: * 01234567........(n-1) * * Note: * (a) The # of integers (via -n option) used by the writer and reader should be the same. * (b) The data file used by the writer and reader should be the same. * * Future enhancement: * 1) Provide default values for n and i and allow user to run with either 0 or 1 option * 2) Use HDF library HD<system calls> instead of the system calls * 3) Handle large sized buffer (gigabytes) if needed * * Return: Success: EXIT_SUCCESS * Failure: EXIT_FAILURE * *------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { int fd = -1; /* file descriptor */ ssize_t bytes_wrote; /* the nubmer of bytes written */ unsigned int *buf = NULL; /* buffer to hold written data */ unsigned int n, u, i; /* local index variable */ int temp; /* temporary variable */ unsigned int iterations = 0; /* the input for "-i" */ unsigned int num = 0; /* the input for "-n" */ int opt = 0; /* option char */ /* Ensure the # of arguments is as expected */ if (argc != 5) { usage(); exit(EXIT_FAILURE); } /* end if */ /* Parse command line options */ while ((opt = getopt(argc, argv, "n:i:")) != -1) { switch (opt) { case 'n': if ((temp = atoi(optarg)) < 0) { usage(); exit(EXIT_FAILURE); } /* end if */ num = (unsigned int)temp; break; case 'i': if ((temp = atoi(optarg)) < 0) { usage(); exit(EXIT_FAILURE); } /* end if */ iterations = (unsigned int)temp; break; default: printf("Invalid option encountered\n"); break; } /* end switch */ } /* end while */ printf("WRITER: # of integers to write = %u; # of iterations = %d\n", num, iterations); /* Remove existing data file if needed */ if (remove(FILENAME) < 0) { if (errno == ENOENT) printf("WRITER: remove %s--%s\n", FILENAME, strerror(errno)); else { printf("WRITER: error from remove: %d--%s\n", errno, strerror(errno)); goto error; } /* end else */ } else printf("WRITER: %s is removed\n", FILENAME); /* Create the data file */ if ((fd = open(FILENAME, O_RDWR | O_TRUNC | O_CREAT, 0664)) < 0) { printf("WRITER: error from open\n"); goto error; } /* end if */ /* Allocate buffer for holding data to be written */ if ((buf = (unsigned int *)malloc(num * sizeof(unsigned int))) == NULL) { printf("WRITER: error from malloc\n"); if (fd >= 0 && close(fd) < 0) printf("WRITER: error from close\n"); goto error; } /* end if */ printf("\n"); for (i = 1; i <= iterations; i++) { printf("WRITER: *****start iteration %u*****\n", i); /* Write the series of integers to the file */ for (n = 0; n < num; n++) { /* Set up data to be written */ for (u = 0; u < num; u++) buf[u] = n; /* Position the file to the proper location */ if (lseek(fd, (off_t)(n * sizeof(unsigned int)), SEEK_SET) < 0) { printf("WRITER: error from lseek\n"); goto error; } /* end if */ /* Write the data */ if ((bytes_wrote = write(fd, buf, ((num - n) * sizeof(unsigned int)))) < 0) { printf("WRITER: error from write\n"); goto error; } /* end if */ /* Verify the bytes written is correct */ if (bytes_wrote != (ssize_t)((num - n) * sizeof(unsigned int))) { printf("WRITER: error from bytes written\n"); goto error; } /* end if */ } /* end for */ printf("WRITER: *****end iteration %u*****\n\n", i); } /* end for */ /* Close the file */ if (close(fd) < 0) { printf("WRITER: error from close\n"); goto error; } /* end if */ /* Free the buffer */ if (buf) free(buf); return EXIT_SUCCESS; error: return EXIT_FAILURE; } /* end main() */ #else /* WIN32 / MINGW32 */ int main(void) { printf("Non-POSIX platform. Exiting.\n"); return EXIT_FAILURE; } /* end main() */ #endif /* WIN32 / MINGW32 */
the_stack_data/193892975.c
#include<stdio.h> /* return x with the n bits that begin at position p inverted * leaving the others unchanged*/ unsigned invert(unsigned x,int p,int n); /* getbits: get n bits from position p (from K&R p.49) */ unsigned getbits(unsigned x, int p, int n); /* Prints the 32-bit binary form of a decimal value */ void dec2bin(unsigned x); int main(void) { unsigned x = 170; int p = 4; int n = 3; invert(x,p,n); return 0; } /* return x with the n bits that begin at position p inverted * leaving the others unchanged*/ unsigned invert(unsigned x, int p, int n) { // Generate n 1 bits int r = ~(~0 << n); int shift_value = (p+1-n); // Shift n 1-bits into position p int bitmask = r << shift_value; // Uncomment to verify values in stdout //printf("x = ");dec2bin(x); //printf("rhs = ");dec2bin(bitmask); //printf("x^rhs = ");dec2bin(x^bitmask); return x^bitmask; } /* getbits: get n bits from position p * from K&R p. 49 */ unsigned getbits(unsigned x, int p, int n) { return (x >> (p+1-n)) & ~(~0 << n); } /* Prints the 32-bit binary form of a decimal value */ void dec2bin(unsigned x) { char i; for (i = 32-1; i >= 0; i--) { printf("%d", getbits(x,i,1)); if(!(i%8)) { putchar(' '); } } printf(" = %d\n",x); }
the_stack_data/192331222.c
#include<stdlib.h> #include<time.h> int main() { int* mem = malloc(77); while(1) { srand(time(NULL)); mem[0] = rand(); // } }
the_stack_data/76700716.c
/** ****************************************************************************** * @file stm32f2xx_ll_dma.c * @author MCD Application Team * @brief DMA LL module driver. ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2> * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of STMicroelectronics nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************** */ #if defined(USE_FULL_LL_DRIVER) /* Includes ------------------------------------------------------------------*/ #include "stm32f2xx_ll_dma.h" #include "stm32f2xx_ll_bus.h" #ifdef USE_FULL_ASSERT #include "stm32_assert.h" #else #define assert_param(expr) ((void)0U) #endif /** @addtogroup STM32F2xx_LL_Driver * @{ */ #if defined (DMA1) || defined (DMA2) /** @defgroup DMA_LL DMA * @{ */ /* Private types -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private constants ---------------------------------------------------------*/ /* Private macros ------------------------------------------------------------*/ /** @addtogroup DMA_LL_Private_Macros * @{ */ #define IS_LL_DMA_DIRECTION(__VALUE__) (((__VALUE__) == LL_DMA_DIRECTION_PERIPH_TO_MEMORY) || \ ((__VALUE__) == LL_DMA_DIRECTION_MEMORY_TO_PERIPH) || \ ((__VALUE__) == LL_DMA_DIRECTION_MEMORY_TO_MEMORY)) #define IS_LL_DMA_MODE(__VALUE__) (((__VALUE__) == LL_DMA_MODE_NORMAL) || \ ((__VALUE__) == LL_DMA_MODE_CIRCULAR) || \ ((__VALUE__) == LL_DMA_MODE_PFCTRL)) #define IS_LL_DMA_PERIPHINCMODE(__VALUE__) (((__VALUE__) == LL_DMA_PERIPH_INCREMENT) || \ ((__VALUE__) == LL_DMA_PERIPH_NOINCREMENT)) #define IS_LL_DMA_MEMORYINCMODE(__VALUE__) (((__VALUE__) == LL_DMA_MEMORY_INCREMENT) || \ ((__VALUE__) == LL_DMA_MEMORY_NOINCREMENT)) #define IS_LL_DMA_PERIPHDATASIZE(__VALUE__) (((__VALUE__) == LL_DMA_PDATAALIGN_BYTE) || \ ((__VALUE__) == LL_DMA_PDATAALIGN_HALFWORD) || \ ((__VALUE__) == LL_DMA_PDATAALIGN_WORD)) #define IS_LL_DMA_MEMORYDATASIZE(__VALUE__) (((__VALUE__) == LL_DMA_MDATAALIGN_BYTE) || \ ((__VALUE__) == LL_DMA_MDATAALIGN_HALFWORD) || \ ((__VALUE__) == LL_DMA_MDATAALIGN_WORD)) #define IS_LL_DMA_NBDATA(__VALUE__) ((__VALUE__) <= (uint32_t)0x0000FFFFU) #define IS_LL_DMA_CHANNEL(__VALUE__) (((__VALUE__) == LL_DMA_CHANNEL_0) || \ ((__VALUE__) == LL_DMA_CHANNEL_1) || \ ((__VALUE__) == LL_DMA_CHANNEL_2) || \ ((__VALUE__) == LL_DMA_CHANNEL_3) || \ ((__VALUE__) == LL_DMA_CHANNEL_4) || \ ((__VALUE__) == LL_DMA_CHANNEL_5) || \ ((__VALUE__) == LL_DMA_CHANNEL_6) || \ ((__VALUE__) == LL_DMA_CHANNEL_7)) #define IS_LL_DMA_PRIORITY(__VALUE__) (((__VALUE__) == LL_DMA_PRIORITY_LOW) || \ ((__VALUE__) == LL_DMA_PRIORITY_MEDIUM) || \ ((__VALUE__) == LL_DMA_PRIORITY_HIGH) || \ ((__VALUE__) == LL_DMA_PRIORITY_VERYHIGH)) #define IS_LL_DMA_ALL_STREAM_INSTANCE(INSTANCE, STREAM) ((((INSTANCE) == DMA1) && \ (((STREAM) == LL_DMA_STREAM_0) || \ ((STREAM) == LL_DMA_STREAM_1) || \ ((STREAM) == LL_DMA_STREAM_2) || \ ((STREAM) == LL_DMA_STREAM_3) || \ ((STREAM) == LL_DMA_STREAM_4) || \ ((STREAM) == LL_DMA_STREAM_5) || \ ((STREAM) == LL_DMA_STREAM_6) || \ ((STREAM) == LL_DMA_STREAM_7) || \ ((STREAM) == LL_DMA_STREAM_ALL))) ||\ (((INSTANCE) == DMA2) && \ (((STREAM) == LL_DMA_STREAM_0) || \ ((STREAM) == LL_DMA_STREAM_1) || \ ((STREAM) == LL_DMA_STREAM_2) || \ ((STREAM) == LL_DMA_STREAM_3) || \ ((STREAM) == LL_DMA_STREAM_4) || \ ((STREAM) == LL_DMA_STREAM_5) || \ ((STREAM) == LL_DMA_STREAM_6) || \ ((STREAM) == LL_DMA_STREAM_7) || \ ((STREAM) == LL_DMA_STREAM_ALL)))) #define IS_LL_DMA_FIFO_MODE_STATE(STATE) (((STATE) == LL_DMA_FIFOMODE_DISABLE ) || \ ((STATE) == LL_DMA_FIFOMODE_ENABLE)) #define IS_LL_DMA_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == LL_DMA_FIFOTHRESHOLD_1_4) || \ ((THRESHOLD) == LL_DMA_FIFOTHRESHOLD_1_2) || \ ((THRESHOLD) == LL_DMA_FIFOTHRESHOLD_3_4) || \ ((THRESHOLD) == LL_DMA_FIFOTHRESHOLD_FULL)) #define IS_LL_DMA_MEMORY_BURST(BURST) (((BURST) == LL_DMA_MBURST_SINGLE) || \ ((BURST) == LL_DMA_MBURST_INC4) || \ ((BURST) == LL_DMA_MBURST_INC8) || \ ((BURST) == LL_DMA_MBURST_INC16)) #define IS_LL_DMA_PERIPHERAL_BURST(BURST) (((BURST) == LL_DMA_PBURST_SINGLE) || \ ((BURST) == LL_DMA_PBURST_INC4) || \ ((BURST) == LL_DMA_PBURST_INC8) || \ ((BURST) == LL_DMA_PBURST_INC16)) /** * @} */ /* Private function prototypes -----------------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /** @addtogroup DMA_LL_Exported_Functions * @{ */ /** @addtogroup DMA_LL_EF_Init * @{ */ /** * @brief De-initialize the DMA registers to their default reset values. * @param DMAx DMAx Instance * @param Stream This parameter can be one of the following values: * @arg @ref LL_DMA_STREAM_0 * @arg @ref LL_DMA_STREAM_1 * @arg @ref LL_DMA_STREAM_2 * @arg @ref LL_DMA_STREAM_3 * @arg @ref LL_DMA_STREAM_4 * @arg @ref LL_DMA_STREAM_5 * @arg @ref LL_DMA_STREAM_6 * @arg @ref LL_DMA_STREAM_7 * @arg @ref LL_DMA_STREAM_ALL * @retval An ErrorStatus enumeration value: * - SUCCESS: DMA registers are de-initialized * - ERROR: DMA registers are not de-initialized */ uint32_t LL_DMA_DeInit(DMA_TypeDef *DMAx, uint32_t Stream) { DMA_Stream_TypeDef *tmp = (DMA_Stream_TypeDef *)DMA1_Stream0; ErrorStatus status = SUCCESS; /* Check the DMA Instance DMAx and Stream parameters*/ assert_param(IS_LL_DMA_ALL_STREAM_INSTANCE(DMAx, Stream)); if (Stream == LL_DMA_STREAM_ALL) { if (DMAx == DMA1) { /* Force reset of DMA clock */ LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_DMA1); /* Release reset of DMA clock */ LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_DMA1); } else if (DMAx == DMA2) { /* Force reset of DMA clock */ LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_DMA2); /* Release reset of DMA clock */ LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_DMA2); } else { status = ERROR; } } else { /* Disable the selected Stream */ LL_DMA_DisableStream(DMAx,Stream); /* Get the DMA Stream Instance */ tmp = (DMA_Stream_TypeDef *)(__LL_DMA_GET_STREAM_INSTANCE(DMAx, Stream)); /* Reset DMAx_Streamy configuration register */ LL_DMA_WriteReg(tmp, CR, 0U); /* Reset DMAx_Streamy remaining bytes register */ LL_DMA_WriteReg(tmp, NDTR, 0U); /* Reset DMAx_Streamy peripheral address register */ LL_DMA_WriteReg(tmp, PAR, 0U); /* Reset DMAx_Streamy memory address register */ LL_DMA_WriteReg(tmp, M0AR, 0U); /* Reset DMAx_Streamy memory address register */ LL_DMA_WriteReg(tmp, M1AR, 0U); /* Reset DMAx_Streamy FIFO control register */ LL_DMA_WriteReg(tmp, FCR, 0x00000021U); /* Reset Channel register field for DMAx Stream*/ LL_DMA_SetChannelSelection(DMAx, Stream, LL_DMA_CHANNEL_0); if(Stream == LL_DMA_STREAM_0) { /* Reset the Stream0 pending flags */ DMAx->LIFCR = 0x0000003F ; } else if(Stream == LL_DMA_STREAM_1) { /* Reset the Stream1 pending flags */ DMAx->LIFCR = 0x00000F40 ; } else if(Stream == LL_DMA_STREAM_2) { /* Reset the Stream2 pending flags */ DMAx->LIFCR = 0x003F0000 ; } else if(Stream == LL_DMA_STREAM_3) { /* Reset the Stream3 pending flags */ DMAx->LIFCR = 0x0F400000 ; } else if(Stream == LL_DMA_STREAM_4) { /* Reset the Stream4 pending flags */ DMAx->HIFCR = 0x0000003F ; } else if(Stream == LL_DMA_STREAM_5) { /* Reset the Stream5 pending flags */ DMAx->HIFCR = 0x00000F40 ; } else if(Stream == LL_DMA_STREAM_6) { /* Reset the Stream6 pending flags */ DMAx->HIFCR = 0x003F0000 ; } else if(Stream == LL_DMA_STREAM_7) { /* Reset the Stream7 pending flags */ DMAx->HIFCR = 0x0F400000 ; } else { status = ERROR; } } return status; } /** * @brief Initialize the DMA registers according to the specified parameters in DMA_InitStruct. * @note To convert DMAx_Streamy Instance to DMAx Instance and Streamy, use helper macros : * @arg @ref __LL_DMA_GET_INSTANCE * @arg @ref __LL_DMA_GET_STREAM * @param DMAx DMAx Instance * @param Stream This parameter can be one of the following values: * @arg @ref LL_DMA_STREAM_0 * @arg @ref LL_DMA_STREAM_1 * @arg @ref LL_DMA_STREAM_2 * @arg @ref LL_DMA_STREAM_3 * @arg @ref LL_DMA_STREAM_4 * @arg @ref LL_DMA_STREAM_5 * @arg @ref LL_DMA_STREAM_6 * @arg @ref LL_DMA_STREAM_7 * @param DMA_InitStruct pointer to a @ref LL_DMA_InitTypeDef structure. * @retval An ErrorStatus enumeration value: * - SUCCESS: DMA registers are initialized * - ERROR: Not applicable */ uint32_t LL_DMA_Init(DMA_TypeDef *DMAx, uint32_t Stream, LL_DMA_InitTypeDef *DMA_InitStruct) { /* Check the DMA Instance DMAx and Stream parameters*/ assert_param(IS_LL_DMA_ALL_STREAM_INSTANCE(DMAx, Stream)); /* Check the DMA parameters from DMA_InitStruct */ assert_param(IS_LL_DMA_DIRECTION(DMA_InitStruct->Direction)); assert_param(IS_LL_DMA_MODE(DMA_InitStruct->Mode)); assert_param(IS_LL_DMA_PERIPHINCMODE(DMA_InitStruct->PeriphOrM2MSrcIncMode)); assert_param(IS_LL_DMA_MEMORYINCMODE(DMA_InitStruct->MemoryOrM2MDstIncMode)); assert_param(IS_LL_DMA_PERIPHDATASIZE(DMA_InitStruct->PeriphOrM2MSrcDataSize)); assert_param(IS_LL_DMA_MEMORYDATASIZE(DMA_InitStruct->MemoryOrM2MDstDataSize)); assert_param(IS_LL_DMA_NBDATA(DMA_InitStruct->NbData)); assert_param(IS_LL_DMA_CHANNEL(DMA_InitStruct->Channel)); assert_param(IS_LL_DMA_PRIORITY(DMA_InitStruct->Priority)); assert_param(IS_LL_DMA_FIFO_MODE_STATE(DMA_InitStruct->FIFOMode)); /* Check the memory burst, peripheral burst and FIFO threshold parameters only when FIFO mode is enabled */ if(DMA_InitStruct->FIFOMode != LL_DMA_FIFOMODE_DISABLE) { assert_param(IS_LL_DMA_FIFO_THRESHOLD(DMA_InitStruct->FIFOThreshold)); assert_param(IS_LL_DMA_MEMORY_BURST(DMA_InitStruct->MemBurst)); assert_param(IS_LL_DMA_PERIPHERAL_BURST(DMA_InitStruct->PeriphBurst)); } /*---------------------------- DMAx SxCR Configuration ------------------------ * Configure DMAx_Streamy: data transfer direction, data transfer mode, * peripheral and memory increment mode, * data size alignment and priority level with parameters : * - Direction: DMA_SxCR_DIR[1:0] bits * - Mode: DMA_SxCR_CIRC bit * - PeriphOrM2MSrcIncMode: DMA_SxCR_PINC bit * - MemoryOrM2MDstIncMode: DMA_SxCR_MINC bit * - PeriphOrM2MSrcDataSize: DMA_SxCR_PSIZE[1:0] bits * - MemoryOrM2MDstDataSize: DMA_SxCR_MSIZE[1:0] bits * - Priority: DMA_SxCR_PL[1:0] bits */ LL_DMA_ConfigTransfer(DMAx, Stream, DMA_InitStruct->Direction | \ DMA_InitStruct->Mode | \ DMA_InitStruct->PeriphOrM2MSrcIncMode | \ DMA_InitStruct->MemoryOrM2MDstIncMode | \ DMA_InitStruct->PeriphOrM2MSrcDataSize | \ DMA_InitStruct->MemoryOrM2MDstDataSize | \ DMA_InitStruct->Priority ); if(DMA_InitStruct->FIFOMode != LL_DMA_FIFOMODE_DISABLE) { /*---------------------------- DMAx SxFCR Configuration ------------------------ * Configure DMAx_Streamy: fifo mode and fifo threshold with parameters : * - FIFOMode: DMA_SxFCR_DMDIS bit * - FIFOThreshold: DMA_SxFCR_FTH[1:0] bits */ LL_DMA_ConfigFifo(DMAx, Stream, DMA_InitStruct->FIFOMode, DMA_InitStruct->FIFOThreshold); /*---------------------------- DMAx SxCR Configuration -------------------------- * Configure DMAx_Streamy: memory burst transfer with parameters : * - MemBurst: DMA_SxCR_MBURST[1:0] bits */ LL_DMA_SetMemoryBurstxfer(DMAx,Stream,DMA_InitStruct->MemBurst); /*---------------------------- DMAx SxCR Configuration -------------------------- * Configure DMAx_Streamy: peripheral burst transfer with parameters : * - PeriphBurst: DMA_SxCR_PBURST[1:0] bits */ LL_DMA_SetPeriphBurstxfer(DMAx,Stream,DMA_InitStruct->PeriphBurst); } /*-------------------------- DMAx SxM0AR Configuration -------------------------- * Configure the memory or destination base address with parameter : * - MemoryOrM2MDstAddress: DMA_SxM0AR_M0A[31:0] bits */ LL_DMA_SetMemoryAddress(DMAx, Stream, DMA_InitStruct->MemoryOrM2MDstAddress); /*-------------------------- DMAx SxPAR Configuration --------------------------- * Configure the peripheral or source base address with parameter : * - PeriphOrM2MSrcAddress: DMA_SxPAR_PA[31:0] bits */ LL_DMA_SetPeriphAddress(DMAx, Stream, DMA_InitStruct->PeriphOrM2MSrcAddress); /*--------------------------- DMAx SxNDTR Configuration ------------------------- * Configure the peripheral base address with parameter : * - NbData: DMA_SxNDT[15:0] bits */ LL_DMA_SetDataLength(DMAx, Stream, DMA_InitStruct->NbData); /*--------------------------- DMA SxCR_CHSEL Configuration ---------------------- * Configure the peripheral base address with parameter : * - PeriphRequest: DMA_SxCR_CHSEL[2:0] bits */ LL_DMA_SetChannelSelection(DMAx, Stream, DMA_InitStruct->Channel); return SUCCESS; } /** * @brief Set each @ref LL_DMA_InitTypeDef field to default value. * @param DMA_InitStruct Pointer to a @ref LL_DMA_InitTypeDef structure. * @retval None */ void LL_DMA_StructInit(LL_DMA_InitTypeDef *DMA_InitStruct) { /* Set DMA_InitStruct fields to default values */ DMA_InitStruct->PeriphOrM2MSrcAddress = 0x00000000U; DMA_InitStruct->MemoryOrM2MDstAddress = 0x00000000U; DMA_InitStruct->Direction = LL_DMA_DIRECTION_PERIPH_TO_MEMORY; DMA_InitStruct->Mode = LL_DMA_MODE_NORMAL; DMA_InitStruct->PeriphOrM2MSrcIncMode = LL_DMA_PERIPH_NOINCREMENT; DMA_InitStruct->MemoryOrM2MDstIncMode = LL_DMA_MEMORY_NOINCREMENT; DMA_InitStruct->PeriphOrM2MSrcDataSize = LL_DMA_PDATAALIGN_BYTE; DMA_InitStruct->MemoryOrM2MDstDataSize = LL_DMA_MDATAALIGN_BYTE; DMA_InitStruct->NbData = 0x00000000U; DMA_InitStruct->Channel = LL_DMA_CHANNEL_0; DMA_InitStruct->Priority = LL_DMA_PRIORITY_LOW; DMA_InitStruct->FIFOMode = LL_DMA_FIFOMODE_DISABLE; DMA_InitStruct->FIFOThreshold = LL_DMA_FIFOTHRESHOLD_1_4; DMA_InitStruct->MemBurst = LL_DMA_MBURST_SINGLE; DMA_InitStruct->PeriphBurst = LL_DMA_PBURST_SINGLE; } /** * @} */ /** * @} */ /** * @} */ #endif /* DMA1 || DMA2 */ /** * @} */ #endif /* USE_FULL_LL_DRIVER */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
the_stack_data/882547.c
/* f2c.h -- Standard Fortran to C header file */ /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ #ifndef F2C_INCLUDE #define F2C_INCLUDE #include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimag(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static complex c_b1 = {0.f,0.f}; static integer c__1 = 1; static integer c__0 = 0; static real c_b10 = 1.f; static real c_b35 = 0.f; /* > \brief \b CLALSD uses the singular value decomposition of A to solve the least squares problem. */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download CLALSD + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clalsd. f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clalsd. f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clalsd. f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE CLALSD( UPLO, SMLSIZ, N, NRHS, D, E, B, LDB, RCOND, */ /* RANK, WORK, RWORK, IWORK, INFO ) */ /* CHARACTER UPLO */ /* INTEGER INFO, LDB, N, NRHS, RANK, SMLSIZ */ /* REAL RCOND */ /* INTEGER IWORK( * ) */ /* REAL D( * ), E( * ), RWORK( * ) */ /* COMPLEX B( LDB, * ), WORK( * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > CLALSD uses the singular value decomposition of A to solve the least */ /* > squares problem of finding X to minimize the Euclidean norm of each */ /* > column of A*X-B, where A is N-by-N upper bidiagonal, and X and B */ /* > are N-by-NRHS. The solution X overwrites B. */ /* > */ /* > The singular values of A smaller than RCOND times the largest */ /* > singular value are treated as zero in solving the least squares */ /* > problem; in this case a minimum norm solution is returned. */ /* > The actual singular values are returned in D in ascending order. */ /* > */ /* > This code makes very mild assumptions about floating point */ /* > arithmetic. It will work on machines with a guard digit in */ /* > add/subtract, or on those binary machines without guard digits */ /* > which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2. */ /* > It could conceivably fail on hexadecimal or decimal machines */ /* > without guard digits, but we know of none. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] UPLO */ /* > \verbatim */ /* > UPLO is CHARACTER*1 */ /* > = 'U': D and E define an upper bidiagonal matrix. */ /* > = 'L': D and E define a lower bidiagonal matrix. */ /* > \endverbatim */ /* > */ /* > \param[in] SMLSIZ */ /* > \verbatim */ /* > SMLSIZ is INTEGER */ /* > The maximum size of the subproblems at the bottom of the */ /* > computation tree. */ /* > \endverbatim */ /* > */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The dimension of the bidiagonal matrix. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] NRHS */ /* > \verbatim */ /* > NRHS is INTEGER */ /* > The number of columns of B. NRHS must be at least 1. */ /* > \endverbatim */ /* > */ /* > \param[in,out] D */ /* > \verbatim */ /* > D is REAL array, dimension (N) */ /* > On entry D contains the main diagonal of the bidiagonal */ /* > matrix. On exit, if INFO = 0, D contains its singular values. */ /* > \endverbatim */ /* > */ /* > \param[in,out] E */ /* > \verbatim */ /* > E is REAL array, dimension (N-1) */ /* > Contains the super-diagonal entries of the bidiagonal matrix. */ /* > On exit, E has been destroyed. */ /* > \endverbatim */ /* > */ /* > \param[in,out] B */ /* > \verbatim */ /* > B is COMPLEX array, dimension (LDB,NRHS) */ /* > On input, B contains the right hand sides of the least */ /* > squares problem. On output, B contains the solution X. */ /* > \endverbatim */ /* > */ /* > \param[in] LDB */ /* > \verbatim */ /* > LDB is INTEGER */ /* > The leading dimension of B in the calling subprogram. */ /* > LDB must be at least f2cmax(1,N). */ /* > \endverbatim */ /* > */ /* > \param[in] RCOND */ /* > \verbatim */ /* > RCOND is REAL */ /* > The singular values of A less than or equal to RCOND times */ /* > the largest singular value are treated as zero in solving */ /* > the least squares problem. If RCOND is negative, */ /* > machine precision is used instead. */ /* > For example, if diag(S)*X=B were the least squares problem, */ /* > where diag(S) is a diagonal matrix of singular values, the */ /* > solution would be X(i) = B(i) / S(i) if S(i) is greater than */ /* > RCOND*f2cmax(S), and X(i) = 0 if S(i) is less than or equal to */ /* > RCOND*f2cmax(S). */ /* > \endverbatim */ /* > */ /* > \param[out] RANK */ /* > \verbatim */ /* > RANK is INTEGER */ /* > The number of singular values of A greater than RCOND times */ /* > the largest singular value. */ /* > \endverbatim */ /* > */ /* > \param[out] WORK */ /* > \verbatim */ /* > WORK is COMPLEX array, dimension (N * NRHS). */ /* > \endverbatim */ /* > */ /* > \param[out] RWORK */ /* > \verbatim */ /* > RWORK is REAL array, dimension at least */ /* > (9*N + 2*N*SMLSIZ + 8*N*NLVL + 3*SMLSIZ*NRHS + */ /* > MAX( (SMLSIZ+1)**2, N*(1+NRHS) + 2*NRHS ), */ /* > where */ /* > NLVL = MAX( 0, INT( LOG_2( MIN( M,N )/(SMLSIZ+1) ) ) + 1 ) */ /* > \endverbatim */ /* > */ /* > \param[out] IWORK */ /* > \verbatim */ /* > IWORK is INTEGER array, dimension (3*N*NLVL + 11*N). */ /* > \endverbatim */ /* > */ /* > \param[out] INFO */ /* > \verbatim */ /* > INFO is INTEGER */ /* > = 0: successful exit. */ /* > < 0: if INFO = -i, the i-th argument had an illegal value. */ /* > > 0: The algorithm failed to compute a singular value while */ /* > working on the submatrix lying in rows and columns */ /* > INFO/(N+1) through MOD(INFO,N+1). */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date December 2016 */ /* > \ingroup complexOTHERcomputational */ /* > \par Contributors: */ /* ================== */ /* > */ /* > Ming Gu and Ren-Cang Li, Computer Science Division, University of */ /* > California at Berkeley, USA \n */ /* > Osni Marques, LBNL/NERSC, USA \n */ /* ===================================================================== */ /* Subroutine */ int clalsd_(char *uplo, integer *smlsiz, integer *n, integer *nrhs, real *d__, real *e, complex *b, integer *ldb, real *rcond, integer *rank, complex *work, real *rwork, integer *iwork, integer * info) { /* System generated locals */ integer b_dim1, b_offset, i__1, i__2, i__3, i__4, i__5, i__6; real r__1; complex q__1; /* Local variables */ integer difl, difr; real rcnd; integer jcol, irwb, perm, nsub, nlvl, sqre, bxst, jrow, irwu, c__, i__, j, k; real r__; integer s, u, jimag, z__, jreal; extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *, integer *, real *, real *, integer *, real *, integer *, real *, real *, integer *); integer irwib; extern /* Subroutine */ int ccopy_(integer *, complex *, integer *, complex *, integer *); integer poles, sizei, irwrb, nsize; extern /* Subroutine */ int csrot_(integer *, complex *, integer *, complex *, integer *, real *, real *); integer irwvt, icmpq1, icmpq2; real cs; integer bx; extern /* Subroutine */ int clalsa_(integer *, integer *, integer *, integer *, complex *, integer *, complex *, integer *, real *, integer *, real *, integer *, real *, real *, real *, real *, integer *, integer *, integer *, integer *, real *, real *, real * , real *, integer *, integer *); real sn; extern /* Subroutine */ int clascl_(char *, integer *, integer *, real *, real *, integer *, integer *, complex *, integer *, integer *); integer st; extern real slamch_(char *); extern /* Subroutine */ int slasda_(integer *, integer *, integer *, integer *, real *, real *, real *, integer *, real *, integer *, real *, real *, real *, real *, integer *, integer *, integer *, integer *, real *, real *, real *, real *, integer *, integer *); integer vt; extern /* Subroutine */ int clacpy_(char *, integer *, integer *, complex *, integer *, complex *, integer *), claset_(char *, integer *, integer *, complex *, complex *, complex *, integer *), xerbla_(char *, integer *, ftnlen), slascl_(char *, integer *, integer *, real *, real *, integer *, integer *, real * , integer *, integer *); extern integer isamax_(integer *, real *, integer *); integer givcol; extern /* Subroutine */ int slasdq_(char *, integer *, integer *, integer *, integer *, integer *, real *, real *, real *, integer *, real * , integer *, real *, integer *, real *, integer *), slaset_(char *, integer *, integer *, real *, real *, real *, integer *), slartg_(real *, real *, real *, real *, real * ); real orgnrm; integer givnum; extern real slanst_(char *, integer *, real *, real *); extern /* Subroutine */ int slasrt_(char *, integer *, real *, integer *); integer givptr, nm1, nrwork, irwwrk, smlszp, st1; real eps; integer iwk; real tol; /* -- 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 */ --d__; --e; b_dim1 = *ldb; b_offset = 1 + b_dim1 * 1; b -= b_offset; --work; --rwork; --iwork; /* Function Body */ *info = 0; if (*n < 0) { *info = -3; } else if (*nrhs < 1) { *info = -4; } else if (*ldb < 1 || *ldb < *n) { *info = -8; } if (*info != 0) { i__1 = -(*info); xerbla_("CLALSD", &i__1, (ftnlen)6); return 0; } eps = slamch_("Epsilon"); /* Set up the tolerance. */ if (*rcond <= 0.f || *rcond >= 1.f) { rcnd = eps; } else { rcnd = *rcond; } *rank = 0; /* Quick return if possible. */ if (*n == 0) { return 0; } else if (*n == 1) { if (d__[1] == 0.f) { claset_("A", &c__1, nrhs, &c_b1, &c_b1, &b[b_offset], ldb); } else { *rank = 1; clascl_("G", &c__0, &c__0, &d__[1], &c_b10, &c__1, nrhs, &b[ b_offset], ldb, info); d__[1] = abs(d__[1]); } return 0; } /* Rotate the matrix if it is lower bidiagonal. */ if (*(unsigned char *)uplo == 'L') { i__1 = *n - 1; for (i__ = 1; i__ <= i__1; ++i__) { slartg_(&d__[i__], &e[i__], &cs, &sn, &r__); d__[i__] = r__; e[i__] = sn * d__[i__ + 1]; d__[i__ + 1] = cs * d__[i__ + 1]; if (*nrhs == 1) { csrot_(&c__1, &b[i__ + b_dim1], &c__1, &b[i__ + 1 + b_dim1], & c__1, &cs, &sn); } else { rwork[(i__ << 1) - 1] = cs; rwork[i__ * 2] = sn; } /* L10: */ } if (*nrhs > 1) { i__1 = *nrhs; for (i__ = 1; i__ <= i__1; ++i__) { i__2 = *n - 1; for (j = 1; j <= i__2; ++j) { cs = rwork[(j << 1) - 1]; sn = rwork[j * 2]; csrot_(&c__1, &b[j + i__ * b_dim1], &c__1, &b[j + 1 + i__ * b_dim1], &c__1, &cs, &sn); /* L20: */ } /* L30: */ } } } /* Scale. */ nm1 = *n - 1; orgnrm = slanst_("M", n, &d__[1], &e[1]); if (orgnrm == 0.f) { claset_("A", n, nrhs, &c_b1, &c_b1, &b[b_offset], ldb); return 0; } slascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, &c__1, &d__[1], n, info); slascl_("G", &c__0, &c__0, &orgnrm, &c_b10, &nm1, &c__1, &e[1], &nm1, info); /* If N is smaller than the minimum divide size SMLSIZ, then solve */ /* the problem with another solver. */ if (*n <= *smlsiz) { irwu = 1; irwvt = irwu + *n * *n; irwwrk = irwvt + *n * *n; irwrb = irwwrk; irwib = irwrb + *n * *nrhs; irwb = irwib + *n * *nrhs; slaset_("A", n, n, &c_b35, &c_b10, &rwork[irwu], n); slaset_("A", n, n, &c_b35, &c_b10, &rwork[irwvt], n); slasdq_("U", &c__0, n, n, n, &c__0, &d__[1], &e[1], &rwork[irwvt], n, &rwork[irwu], n, &rwork[irwwrk], &c__1, &rwork[irwwrk], info); if (*info != 0) { return 0; } /* In the real version, B is passed to SLASDQ and multiplied */ /* internally by Q**H. Here B is complex and that product is */ /* computed below in two steps (real and imaginary parts). */ j = irwb - 1; i__1 = *nrhs; for (jcol = 1; jcol <= i__1; ++jcol) { i__2 = *n; for (jrow = 1; jrow <= i__2; ++jrow) { ++j; i__3 = jrow + jcol * b_dim1; rwork[j] = b[i__3].r; /* L40: */ } /* L50: */ } sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwu], n, &rwork[irwb], n, &c_b35, &rwork[irwrb], n); j = irwb - 1; i__1 = *nrhs; for (jcol = 1; jcol <= i__1; ++jcol) { i__2 = *n; for (jrow = 1; jrow <= i__2; ++jrow) { ++j; rwork[j] = r_imag(&b[jrow + jcol * b_dim1]); /* L60: */ } /* L70: */ } sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwu], n, &rwork[irwb], n, &c_b35, &rwork[irwib], n); jreal = irwrb - 1; jimag = irwib - 1; i__1 = *nrhs; for (jcol = 1; jcol <= i__1; ++jcol) { i__2 = *n; for (jrow = 1; jrow <= i__2; ++jrow) { ++jreal; ++jimag; i__3 = jrow + jcol * b_dim1; i__4 = jreal; i__5 = jimag; q__1.r = rwork[i__4], q__1.i = rwork[i__5]; b[i__3].r = q__1.r, b[i__3].i = q__1.i; /* L80: */ } /* L90: */ } tol = rcnd * (r__1 = d__[isamax_(n, &d__[1], &c__1)], abs(r__1)); i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { if (d__[i__] <= tol) { claset_("A", &c__1, nrhs, &c_b1, &c_b1, &b[i__ + b_dim1], ldb); } else { clascl_("G", &c__0, &c__0, &d__[i__], &c_b10, &c__1, nrhs, &b[ i__ + b_dim1], ldb, info); ++(*rank); } /* L100: */ } /* Since B is complex, the following call to SGEMM is performed */ /* in two steps (real and imaginary parts). That is for V * B */ /* (in the real version of the code V**H is stored in WORK). */ /* CALL SGEMM( 'T', 'N', N, NRHS, N, ONE, WORK, N, B, LDB, ZERO, */ /* $ WORK( NWORK ), N ) */ j = irwb - 1; i__1 = *nrhs; for (jcol = 1; jcol <= i__1; ++jcol) { i__2 = *n; for (jrow = 1; jrow <= i__2; ++jrow) { ++j; i__3 = jrow + jcol * b_dim1; rwork[j] = b[i__3].r; /* L110: */ } /* L120: */ } sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwvt], n, &rwork[irwb], n, &c_b35, &rwork[irwrb], n); j = irwb - 1; i__1 = *nrhs; for (jcol = 1; jcol <= i__1; ++jcol) { i__2 = *n; for (jrow = 1; jrow <= i__2; ++jrow) { ++j; rwork[j] = r_imag(&b[jrow + jcol * b_dim1]); /* L130: */ } /* L140: */ } sgemm_("T", "N", n, nrhs, n, &c_b10, &rwork[irwvt], n, &rwork[irwb], n, &c_b35, &rwork[irwib], n); jreal = irwrb - 1; jimag = irwib - 1; i__1 = *nrhs; for (jcol = 1; jcol <= i__1; ++jcol) { i__2 = *n; for (jrow = 1; jrow <= i__2; ++jrow) { ++jreal; ++jimag; i__3 = jrow + jcol * b_dim1; i__4 = jreal; i__5 = jimag; q__1.r = rwork[i__4], q__1.i = rwork[i__5]; b[i__3].r = q__1.r, b[i__3].i = q__1.i; /* L150: */ } /* L160: */ } /* Unscale. */ slascl_("G", &c__0, &c__0, &c_b10, &orgnrm, n, &c__1, &d__[1], n, info); slasrt_("D", n, &d__[1], info); clascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, nrhs, &b[b_offset], ldb, info); return 0; } /* Book-keeping and setting up some constants. */ nlvl = (integer) (log((real) (*n) / (real) (*smlsiz + 1)) / log(2.f)) + 1; smlszp = *smlsiz + 1; u = 1; vt = *smlsiz * *n + 1; difl = vt + smlszp * *n; difr = difl + nlvl * *n; z__ = difr + (nlvl * *n << 1); c__ = z__ + nlvl * *n; s = c__ + *n; poles = s + *n; givnum = poles + (nlvl << 1) * *n; nrwork = givnum + (nlvl << 1) * *n; bx = 1; irwrb = nrwork; irwib = irwrb + *smlsiz * *nrhs; irwb = irwib + *smlsiz * *nrhs; sizei = *n + 1; k = sizei + *n; givptr = k + *n; perm = givptr + *n; givcol = perm + nlvl * *n; iwk = givcol + (nlvl * *n << 1); st = 1; sqre = 0; icmpq1 = 1; icmpq2 = 0; nsub = 0; i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { if ((r__1 = d__[i__], abs(r__1)) < eps) { d__[i__] = r_sign(&eps, &d__[i__]); } /* L170: */ } i__1 = nm1; for (i__ = 1; i__ <= i__1; ++i__) { if ((r__1 = e[i__], abs(r__1)) < eps || i__ == nm1) { ++nsub; iwork[nsub] = st; /* Subproblem found. First determine its size and then */ /* apply divide and conquer on it. */ if (i__ < nm1) { /* A subproblem with E(I) small for I < NM1. */ nsize = i__ - st + 1; iwork[sizei + nsub - 1] = nsize; } else if ((r__1 = e[i__], abs(r__1)) >= eps) { /* A subproblem with E(NM1) not too small but I = NM1. */ nsize = *n - st + 1; iwork[sizei + nsub - 1] = nsize; } else { /* A subproblem with E(NM1) small. This implies an */ /* 1-by-1 subproblem at D(N), which is not solved */ /* explicitly. */ nsize = i__ - st + 1; iwork[sizei + nsub - 1] = nsize; ++nsub; iwork[nsub] = *n; iwork[sizei + nsub - 1] = 1; ccopy_(nrhs, &b[*n + b_dim1], ldb, &work[bx + nm1], n); } st1 = st - 1; if (nsize == 1) { /* This is a 1-by-1 subproblem and is not solved */ /* explicitly. */ ccopy_(nrhs, &b[st + b_dim1], ldb, &work[bx + st1], n); } else if (nsize <= *smlsiz) { /* This is a small subproblem and is solved by SLASDQ. */ slaset_("A", &nsize, &nsize, &c_b35, &c_b10, &rwork[vt + st1], n); slaset_("A", &nsize, &nsize, &c_b35, &c_b10, &rwork[u + st1], n); slasdq_("U", &c__0, &nsize, &nsize, &nsize, &c__0, &d__[st], & e[st], &rwork[vt + st1], n, &rwork[u + st1], n, & rwork[nrwork], &c__1, &rwork[nrwork], info) ; if (*info != 0) { return 0; } /* In the real version, B is passed to SLASDQ and multiplied */ /* internally by Q**H. Here B is complex and that product is */ /* computed below in two steps (real and imaginary parts). */ j = irwb - 1; i__2 = *nrhs; for (jcol = 1; jcol <= i__2; ++jcol) { i__3 = st + nsize - 1; for (jrow = st; jrow <= i__3; ++jrow) { ++j; i__4 = jrow + jcol * b_dim1; rwork[j] = b[i__4].r; /* L180: */ } /* L190: */ } sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[u + st1] , n, &rwork[irwb], &nsize, &c_b35, &rwork[irwrb], & nsize); j = irwb - 1; i__2 = *nrhs; for (jcol = 1; jcol <= i__2; ++jcol) { i__3 = st + nsize - 1; for (jrow = st; jrow <= i__3; ++jrow) { ++j; rwork[j] = r_imag(&b[jrow + jcol * b_dim1]); /* L200: */ } /* L210: */ } sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[u + st1] , n, &rwork[irwb], &nsize, &c_b35, &rwork[irwib], & nsize); jreal = irwrb - 1; jimag = irwib - 1; i__2 = *nrhs; for (jcol = 1; jcol <= i__2; ++jcol) { i__3 = st + nsize - 1; for (jrow = st; jrow <= i__3; ++jrow) { ++jreal; ++jimag; i__4 = jrow + jcol * b_dim1; i__5 = jreal; i__6 = jimag; q__1.r = rwork[i__5], q__1.i = rwork[i__6]; b[i__4].r = q__1.r, b[i__4].i = q__1.i; /* L220: */ } /* L230: */ } clacpy_("A", &nsize, nrhs, &b[st + b_dim1], ldb, &work[bx + st1], n); } else { /* A large problem. Solve it using divide and conquer. */ slasda_(&icmpq1, smlsiz, &nsize, &sqre, &d__[st], &e[st], & rwork[u + st1], n, &rwork[vt + st1], &iwork[k + st1], &rwork[difl + st1], &rwork[difr + st1], &rwork[z__ + st1], &rwork[poles + st1], &iwork[givptr + st1], & iwork[givcol + st1], n, &iwork[perm + st1], &rwork[ givnum + st1], &rwork[c__ + st1], &rwork[s + st1], & rwork[nrwork], &iwork[iwk], info); if (*info != 0) { return 0; } bxst = bx + st1; clalsa_(&icmpq2, smlsiz, &nsize, nrhs, &b[st + b_dim1], ldb, & work[bxst], n, &rwork[u + st1], n, &rwork[vt + st1], & iwork[k + st1], &rwork[difl + st1], &rwork[difr + st1] , &rwork[z__ + st1], &rwork[poles + st1], &iwork[ givptr + st1], &iwork[givcol + st1], n, &iwork[perm + st1], &rwork[givnum + st1], &rwork[c__ + st1], &rwork[ s + st1], &rwork[nrwork], &iwork[iwk], info); if (*info != 0) { return 0; } } st = i__ + 1; } /* L240: */ } /* Apply the singular values and treat the tiny ones as zero. */ tol = rcnd * (r__1 = d__[isamax_(n, &d__[1], &c__1)], abs(r__1)); i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { /* Some of the elements in D can be negative because 1-by-1 */ /* subproblems were not solved explicitly. */ if ((r__1 = d__[i__], abs(r__1)) <= tol) { claset_("A", &c__1, nrhs, &c_b1, &c_b1, &work[bx + i__ - 1], n); } else { ++(*rank); clascl_("G", &c__0, &c__0, &d__[i__], &c_b10, &c__1, nrhs, &work[ bx + i__ - 1], n, info); } d__[i__] = (r__1 = d__[i__], abs(r__1)); /* L250: */ } /* Now apply back the right singular vectors. */ icmpq2 = 1; i__1 = nsub; for (i__ = 1; i__ <= i__1; ++i__) { st = iwork[i__]; st1 = st - 1; nsize = iwork[sizei + i__ - 1]; bxst = bx + st1; if (nsize == 1) { ccopy_(nrhs, &work[bxst], n, &b[st + b_dim1], ldb); } else if (nsize <= *smlsiz) { /* Since B and BX are complex, the following call to SGEMM */ /* is performed in two steps (real and imaginary parts). */ /* CALL SGEMM( 'T', 'N', NSIZE, NRHS, NSIZE, ONE, */ /* $ RWORK( VT+ST1 ), N, RWORK( BXST ), N, ZERO, */ /* $ B( ST, 1 ), LDB ) */ j = bxst - *n - 1; jreal = irwb - 1; i__2 = *nrhs; for (jcol = 1; jcol <= i__2; ++jcol) { j += *n; i__3 = nsize; for (jrow = 1; jrow <= i__3; ++jrow) { ++jreal; i__4 = j + jrow; rwork[jreal] = work[i__4].r; /* L260: */ } /* L270: */ } sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[vt + st1], n, &rwork[irwb], &nsize, &c_b35, &rwork[irwrb], &nsize); j = bxst - *n - 1; jimag = irwb - 1; i__2 = *nrhs; for (jcol = 1; jcol <= i__2; ++jcol) { j += *n; i__3 = nsize; for (jrow = 1; jrow <= i__3; ++jrow) { ++jimag; rwork[jimag] = r_imag(&work[j + jrow]); /* L280: */ } /* L290: */ } sgemm_("T", "N", &nsize, nrhs, &nsize, &c_b10, &rwork[vt + st1], n, &rwork[irwb], &nsize, &c_b35, &rwork[irwib], &nsize); jreal = irwrb - 1; jimag = irwib - 1; i__2 = *nrhs; for (jcol = 1; jcol <= i__2; ++jcol) { i__3 = st + nsize - 1; for (jrow = st; jrow <= i__3; ++jrow) { ++jreal; ++jimag; i__4 = jrow + jcol * b_dim1; i__5 = jreal; i__6 = jimag; q__1.r = rwork[i__5], q__1.i = rwork[i__6]; b[i__4].r = q__1.r, b[i__4].i = q__1.i; /* L300: */ } /* L310: */ } } else { clalsa_(&icmpq2, smlsiz, &nsize, nrhs, &work[bxst], n, &b[st + b_dim1], ldb, &rwork[u + st1], n, &rwork[vt + st1], & iwork[k + st1], &rwork[difl + st1], &rwork[difr + st1], & rwork[z__ + st1], &rwork[poles + st1], &iwork[givptr + st1], &iwork[givcol + st1], n, &iwork[perm + st1], &rwork[ givnum + st1], &rwork[c__ + st1], &rwork[s + st1], &rwork[ nrwork], &iwork[iwk], info); if (*info != 0) { return 0; } } /* L320: */ } /* Unscale and sort the singular values. */ slascl_("G", &c__0, &c__0, &c_b10, &orgnrm, n, &c__1, &d__[1], n, info); slasrt_("D", n, &d__[1], info); clascl_("G", &c__0, &c__0, &orgnrm, &c_b10, n, nrhs, &b[b_offset], ldb, info); return 0; /* End of CLALSD */ } /* clalsd_ */
the_stack_data/151413.c
#include <stdio.h> /* Simple Fahrenheit to Celsius Converter * using floating point numbers. */ #define LOWER_LIMIT 0 #define UPPER_LIMIT 300 #define STEP 20 int main(void) { float fahr; for (fahr = 0.0; fahr <= UPPER_LIMIT; fahr += STEP) { printf("%6.2f\t%6.2f\n", fahr, (fahr - 32) * 5 / 9); } return 0; }
the_stack_data/30868.c
#include <stdio.h> int main() { char listA[3]; scanf("%s", listA); printf("%c %c %c\n", listA[0], listA[1], listA[2]); return(0); }
the_stack_data/862001.c
/****************************************** * Adam Bajguz ******************************************/ #include <stdlib.h> #include <stdio.h> #include <time.h> #include <stdint.h> #define ARRAY_3D_PRINT 0 #define USE_SKIPPING_METHOD 1 #define FILE_ID "0" #define MAKE_FILENAME(name) name FILE_ID ".txt" #define INPUT_FILENAME MAKE_FILENAME("in") #define OUTPUT_FILENAME "out.txt" #define ANSWER_FILENAME MAKE_FILENAME("out") #define DATA_STRUCT data #define SOLDIERS_STRUCT soldiers #define MAX_FOOD DATA_STRUCT.max_food #define MAX_FOOD_REF DATA_STRUCT->max_food #define MAX_ENT DATA_STRUCT.max_entertainment #define MAX_ENT_REF DATA_STRUCT->max_entertainment #define SOLDIERS_NUM DATA_STRUCT.soldiers_num #define SOLDIERS_NUM_REF DATA_STRUCT->soldiers_num #define OUTPUT DATA_STRUCT.output #define OUTPUT_REF DATA_STRUCT->output #define SOLDIERS DATA_STRUCT.SOLDIERS_STRUCT #define SOLDIERS_REF DATA_STRUCT->SOLDIERS_STRUCT #define SEL_SOLDIERS OUTPUT.sel_soldiers #define SEL_SOLDIERS_REF OUTPUT_REF.sel_soldiers #define ARRAY_GET(REF, x) ((REF) + (x)) #define STRENGTH_RESULTS DATA_STRUCT.strength_results #define STRENGTH_RESULTS_REF DATA_STRUCT->strength_results #define RESULTS(x, y, z) ((STRENGTH_RESULTS_REF) + (MAX_FOOD_REF + 1)*(MAX_ENT_REF + 1)*(x) + (MAX_ENT_REF + 1)*(y) + (z)) #define RESULTS_LENGTH (SOLDIERS_NUM_REF + 1) * (MAX_FOOD_REF + 1) * (MAX_ENT_REF + 1) #ifndef max #define max(a, b) ((a) > (b) ? (a) : (b)) #endif struct t_soldier { uint8_t id; uint32_t strength, food, entertainment; }; struct t_output { uint32_t max_strength; uint8_t last_soldier_index; uint8_t *sel_soldiers; }; struct t_data { uint16_t max_food, max_entertainment; uint8_t soldiers_num; struct t_soldier *soldiers; struct t_output output; uint32_t *strength_results; }; void read_file(struct t_data *const data) __attribute__ ((always_inline)); void algorithm(struct t_data *const data) __attribute__ ((always_inline)); void write_output_to_file(const struct t_data *const data) __attribute__ ((always_inline)); void read_answer_file() __attribute__ ((always_inline)); int main() { clock_t exec_begin_all = clock(); struct t_data data; OUTPUT.last_soldier_index = 0; read_file(&data); clock_t exec_begin_algo = clock(); algorithm(&data); clock_t exec_end_algo = clock(); write_output_to_file(&data); clock_t exec_end_all = clock(); double exec_time_all = ((double) (exec_end_all - exec_begin_all)) / CLOCKS_PER_SEC; double exec_time_algo = ((double) (exec_end_algo - exec_begin_algo)) / CLOCKS_PER_SEC; printf("\n OUTPUT: %d", OUTPUT.max_strength); printf("\n "); if(OUTPUT.max_strength) { uint8_t lsi = OUTPUT.last_soldier_index - 1; do printf("%d ", *ARRAY_GET(SEL_SOLDIERS, lsi)); while (lsi--); printf("\n"); } read_answer_file(); printf("\nSTATISTICS:\n"); printf(" Execution time: %f seconds.\n", exec_time_all); printf(" Execution time without operations on files: %f seconds.\n", exec_time_algo); free(SOLDIERS); free(SEL_SOLDIERS); free(STRENGTH_RESULTS); return 0; } void read_file(struct t_data *const data) { FILE *in = fopen(INPUT_FILENAME, "rt"); if (in) { fscanf(in, "%hu %hu %u", &MAX_FOOD_REF, &MAX_ENT_REF, &SOLDIERS_NUM_REF); SOLDIERS_REF = malloc(sizeof(*SOLDIERS_REF) * SOLDIERS_NUM_REF); #if USE_SKIPPING_METHOD == 1 register uint8_t next_i = 0; uint32_t tmp_strength, tmp_food, tmp_ent; register uint8_t end = SOLDIERS_NUM_REF; #else register uint8_t end = SOLDIERS_NUM_REF; #endif for (register uint8_t i = 0; i < end; ++i) { #if USE_SKIPPING_METHOD == 1 fscanf(in, "%u %u %u", &tmp_strength, &tmp_food, &tmp_ent); if(tmp_food > MAX_FOOD_REF || tmp_ent > MAX_ENT_REF) --SOLDIERS_NUM_REF; else { ARRAY_GET(SOLDIERS_REF, next_i)->id = i+1; ARRAY_GET(SOLDIERS_REF, next_i)->strength = tmp_strength; ARRAY_GET(SOLDIERS_REF, next_i)->food = tmp_food; ARRAY_GET(SOLDIERS_REF, next_i)->entertainment = tmp_ent; ++next_i; } #else fscanf(in, "%u %u %u", &ARRAY_GET(SOLDIERS_REF, i)->strength, &ARRAY_GET(SOLDIERS_REF, i)->food, &ARRAY_GET(SOLDIERS_REF, i)->entertainment); #endif } SEL_SOLDIERS_REF = malloc(sizeof(*SEL_SOLDIERS_REF) * SOLDIERS_NUM_REF); STRENGTH_RESULTS_REF = calloc(RESULTS_LENGTH, sizeof(*STRENGTH_RESULTS_REF)); fclose(in); } else { printf("Error reading from %s!", INPUT_FILENAME); exit(1); } } void algorithm(struct t_data *const data) { register uint8_t soldier = 1; register uint16_t food, ent; register int32_t food_test, ent_test; // Zaczynamy od n = 1, bo pierwsza plaszczyzna jest wypelniona zerami for (register uint8_t prev_soldier = 0; soldier <= SOLDIERS_NUM_REF; ++prev_soldier, ++soldier) { for (food = 1; food <= MAX_FOOD_REF; ++food) { for (ent = 1; ent <= MAX_ENT_REF; ++ent) { // n-1 poniewaz iterujemy od 1 ze wzgledu na strukture results (dodatkowe 3 plaszczyzny wypelnione zerami) food_test = food - ARRAY_GET(SOLDIERS_REF, prev_soldier)->food; ent_test = ent - ARRAY_GET(SOLDIERS_REF, prev_soldier)->entertainment; // Jezeli zolnierz za duzo wymaga to kopiujemy poprzedniego zolnierza if (food_test < 0 || ent_test < 0) *RESULTS(soldier, food, ent) = *RESULTS(prev_soldier, food, ent); else // W przeciwnym wypadku sprawdzamy go maxem! // Tzn jezeli nie oplaca sie wziac, to przepisujemy poprzedniego (pierwszy argument Max jest wiekszy) // a jezeli oplaca sie go wziac, to go wpisujemy do naszych ziomkiw (drugi argument Max jest wiekszy) *RESULTS(soldier, food, ent) = max(*RESULTS(prev_soldier, food, ent), ARRAY_GET(SOLDIERS_REF, prev_soldier)->strength + *RESULTS(prev_soldier, food_test, ent_test)); } } } // Zaczynamy wyznaczanie zolnierzy od konca soldier = SOLDIERS_NUM_REF; food = MAX_ENT_REF, ent = MAX_FOOD_REF; OUTPUT_REF.max_strength = *RESULTS(soldier, ent, food); if(OUTPUT_REF.max_strength) while (soldier > 0) { if (*RESULTS(soldier, ent, food) != *RESULTS(soldier - 1, ent, food)) { ent -= ARRAY_GET(SOLDIERS_REF, soldier - 1)->food; food -= ARRAY_GET(SOLDIERS_REF, soldier - 1)->entertainment; #if USE_SKIPPING_METHOD == 1 *ARRAY_GET(SEL_SOLDIERS_REF, OUTPUT_REF.last_soldier_index++) = ARRAY_GET(SOLDIERS_REF, soldier - 1)->id; #else *ARRAY_GET(SEL_SOLDIERS_REF, OUTPUT_REF.last_soldier_index++) = soldier; #endif } --soldier; } #if ARRAY_3D_PRINT != 0 for (uint8_t soldier = 1; soldier <= SOLDIERS_NUM_REF ; soldier++) { for (uint16_t food = 1; food <= MAX_FOOD_REF; food++) { for (uint16_t ent = 1; ent <= MAX_ENT_REF; ent++) { printf("%d ", *RESULTS(soldier, food, ent)); } printf("\n"); } printf("\n\n"); } #endif } void write_output_to_file(const struct t_data *const data) { FILE *out = fopen(OUTPUT_FILENAME, "wt"); if (out) { fprintf(out, "%u\n", OUTPUT_REF.max_strength); if(OUTPUT_REF.max_strength) { uint8_t lsi = OUTPUT_REF.last_soldier_index - 1; do fprintf(out, "%d ", *ARRAY_GET(SEL_SOLDIERS_REF, lsi)); while (lsi--); } fclose(out); } else printf("\nError writing to %s!\n", OUTPUT_FILENAME); } void read_answer_file() { FILE *in = fopen(ANSWER_FILENAME, "rt"); uint32_t tmp; if (in) { fscanf(in, "%d", &tmp); printf("\n ANSWER: %d", tmp); printf("\n "); while (!feof(in)) { if (fscanf(in, "%d", &tmp) == 1) printf("%d ", tmp); } printf("\n"); fclose(in); } else { printf("Error reading from %s!", ANSWER_FILENAME); } }
the_stack_data/18887565.c
/* 无法证明数学判断条件,不推荐 https://www.luogu.com.cn/blog/_post/969 */ #include <stdio.h> int main() { int a, b, c; // 123 for it's the smallest number // 333 for c = 3*333 =999 the biggest number for (a = 123; a <= 333; a++) { b = a * 2; c = a * 3; /* 2个集合内所有数相加相乘结果一样,2个集合的内容一样(出去一) */ if ((a / 100 + a / 10 % 10 + a % 10 + b / 100 + b / 10 % 10 + b % 10 + c / 100 + c / 10 % 10 + c % 10 == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9) && ((a / 100) * (a / 10 % 10) * (a % 10) * (b / 100) * (b / 10 % 10) * (b % 10) * (c / 100) * (c / 10 % 10) * (c % 10) == (1) * (2) * (3) * (4) * (5) * (6) * (7) * (8) * (9))) { printf("%d %d %d\n", a, b, c); } } return 0; }
the_stack_data/196613.c
/*Program to find the average of n numbers*/ void main() { int num; //num is the number to be inputed. long s=0; //s is the sum of the given numbers. unsigned int n=0,lim; //n is the loop control variable and lim is the limit clrscr(); printf("Enter the limit : "); scanf("%u",&lim); while(n<lim) { printf("Enter the number%d : ",n+1); scanf("%u",&num); s=s+num; n++; } printf("The average of the numbers is :%f",(float)s/lim); printf("\nPress any key..... "); getch(); }
the_stack_data/1108084.c
/* * $Id: GF16.c 942 2008-05-01 07:49:48Z owenhsin $ */
the_stack_data/508073.c
#include <sys/wait.h> #include <stdlib.h> #include <sys/types.h> #include <stdio.h> #include <unistd.h> int main(int argc, char** argv) { char estado = 'p'; int my_pid = getpid(); int child_pid; printf("%d: processos antes da criação do processo filho\n", my_pid); system("ps -f"); printf("%d: criando processo filho\n", my_pid); if ((child_pid = fork()) == 0) { printf("%d: minha cópia de pid ainda tem o id de meu pai: %d\n", getpid(), my_pid); my_pid = getpid(); printf("%d: o valor da variável estado no processo filho é: %c\n", my_pid, estado); printf("%d: filho está aguardando uma entrada do teclado\n", my_pid); estado = getchar(); } else { printf("%d: processos depois da criação do processo filho\n", my_pid); system("ps -f"); printf("%d: pai está esperando pelo filho: %d\n", my_pid, child_pid); wait(&child_pid); } printf("%d: terminando com o valor da variável estado igual a: %c\n", my_pid, estado); }
the_stack_data/211081630.c
/* { dg-do run } */ /* { dg-require-effective-target int32plus } */ /* { dg-options "-O -fno-tree-ccp -fno-tree-fre -fno-tree-copy-prop -fwrapv" } */ static inline int test5 (int x) { int y = 0x80000000; return x + y; } int main () { if (test5 (0x80000000) != 0) __builtin_abort (); return 0; }
the_stack_data/169219.c
/* Description: This program implements my Genetic Algorithm method of solving the "N-Queens Problem" Author: Georgios Evangelou (1046900) Year: 5 Parallel Programming in Machine Learning Problems Electrical and Computer Engineering Department, University of Patras System Specifications: CPU: AMD Ryzen 2600 (6 cores/12 threads, @3.8 GHz, 6786.23 bogomips) GPU: Nvidia GTX 1050 (dual-fan, overclocked) RAM: 8GB (dual-channel, @2666 MHz) Version Notes: Compiles/Runs/Debugs with: gcc gen04.c -o gen04 -lm -fopt-info -fopenmp -pg && time ./gen04 && gprof ./gen04 Inherits all features of previous version if not stated otherwise Supports multi-threaded execution. Each thread has a separate set of genes to work on and all of them try to find a solution Worse execution time compared to single-threaded version, probably because of the call to rand() function Profiler output for N=100 queens, GENES=600 genes and no optimizations: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls s/call s/call name 63.57 31.10 31.10 608981 0.00 0.00 UtilityFunction 30.54 46.05 14.94 627289 0.00 0.00 MutationFunction 3.09 47.56 1.51 194284123 0.00 0.00 RandomInteger 2.41 48.74 1.18 936 0.00 0.02 BreedGeneration 0.45 48.96 0.22 305403 0.00 0.00 CrossoverFunction 0.02 48.97 0.01 frame_dummy 0.00 48.97 0.00 993 0.00 0.03 CalculateAllUtilityValues 0.00 48.97 0.00 11 0.00 0.00 GeneInitialization 0.00 48.97 0.00 7 0.00 6.99 Solve Without any optimizations and 12 threads reported: For N=50 queens a solution is found after: ~0m00,532s and 178 generations, using 50 genes per thread(2130 summed generations) For N=100 queens a solution is found after: ~0m02,345s and 385 generations, using 100 genes per thread(4643 summed generations) For N=200 queens a solution is found after: ~0m25,780s and 96 generations, using 600 genes per thread(1130 summed generations) */ // **************************************************************************************************************** //#pragma GCC optimize("O3","unroll-loops","omit-frame-pointer","inline") //Apply O3 and extra optimizations //#pragma GCC option("arch=native","tune=native","no-zero-upper") //Adapt to the current system //#pragma GCC target("avx") //Enable AVX // **************************************************************************************************************** #include "stdio.h" #include "stdlib.h" #include "math.h" #include "stdbool.h" #include "time.h" #include "omp.h" // **************************************************************************************************************** #define N 200 //Number of queens #define GENES 600 //Number of genes (must by even) #define TARGET_THREADS 12 //Number of threads to ask /** * Produces a random integer in the range [mini,maxi] */ int RandomInteger(int mini, int maxi) { int gap = maxi-mini; int randomInGap = (int) (gap * ((float)rand())/((float)RAND_MAX) ); //[0,gap] return mini + randomInGap; //[mini,mini+gap]==[mini,maxi] } /** * Initializes positional array given */ void GeneInitialization(int genes[GENES][N]) { for (int i=0; i<GENES; i++) { for (int j=0; j<N; j++) { genes[i][j] = RandomInteger(0,N-1); } } } /** * Prints a map of the queens until the M-th positioned queen */ void Map3(int posY[N], int M) { for (int i=0; i<N; i++) printf("==="); printf("===\n---"); for (int i=0; i<N/3; i++) printf("---"); printf(" FITTEST GENE "); for (int i=0; i<N/3; i++) printf("---"); printf("---\n==="); for (int i=0; i<N; i++) printf("==="); printf("\n"); for (int i=0; i<N; i++) printf("---"); printf("---\n##|"); for (int i=0; i<N; i++) printf("%2d ", i+1); printf("\n---"); for (int i=0; i<N; i++) printf("---"); printf("\n"); for (int y=0; y<N; y++) { printf("%2d| ", y+1); for (int x=0; x<N; x++) { bool flag = false; for (int i=0; i<M; i++) { if (i==x && posY[i]==y) { flag = true; } } if (flag) printf("Q"); else printf("~"); printf(" "); } printf("\n"); } for (int i=0; i<N; i++) printf("---"); printf("---\n"); } /** * Checks if a position is safe */ bool isSafeFromPrevious(int posY[N], int x, int y) { int currentQueen = x; for (int oldQueen=0; oldQueen<currentQueen; oldQueen++) { //printf(" Checking %d %d and %d %d \n",posX[q],posY[q],x,y); if (oldQueen==x || posY[oldQueen]==y) return false; //If row/column is endangered else if (y==posY[oldQueen]+(currentQueen-oldQueen) || y==posY[oldQueen]-(currentQueen-oldQueen)) return false; //If diagonal is endangered } return true; } /** * Finds the number collisions between the queens */ int UtilityFunction(int posY[N]) { int collisions = 0; for (int crnt=1; crnt<N; crnt++) { for (int old=0; old<crnt; old++) { if (old==crnt || posY[old]==posY[crnt]) collisions++; //If row/column is endangered else if (posY[crnt]==posY[old]+(crnt-old) || posY[crnt]==posY[old]-(crnt-old)) collisions++; //If diagonal is endangered } } return collisions; } /** * Takes two parent genes and produces two child genes */ void CrossoverFunction(int gene1[N], int gene2[N]) { for (int i=1; i<N; i++) { if (abs(gene1[i-1]-gene1[i])<2 || abs(gene2[i-1]-gene2[i])<2) { int temp = gene1[i]; gene1[i] = gene2[i]; gene2[i] = temp; } } } /** * Takes a gene and mutates it */ void MutationFunction(int gene[N]) { // Mark all values missing from the gene, so they can be used to replace duplicates int inGene[N] = {0}; // Un-mark all existing values for (int i=0; i<N; i++) { inGene[gene[i]] = 1; } // Find duplicates and replace them with non-used values for (int i=1; i<N; i++) { for (int j=0; j<i; j++) { if (gene[i]==gene[j]) { for (int k=0; k<N; k++){ if (inGene[k]==0) { gene[i] = k; inGene[k] = 1; k = N; } } } } } // Performs the actual swapping int barrier = RandomInteger(1,N-3); // [1, N-3] int swapA = RandomInteger(0,barrier); // [0,barrier] int swapB = RandomInteger(barrier+1,N-1); // [barrier+1,N-1] int temp = gene[swapA]; gene[swapA] = gene[swapB]; gene[swapB] = temp; } /** * Breeds next generation */ void BreedGeneration(int genes[GENES][N], int utilityValues[GENES]) { int genesNew[GENES][N] = {-1}; // For all pairs of genes to create for (int i=0; i<GENES-1; i+=2) { int index1 = -1, index2 = -1; float limit_value = INFINITY; float value1 = limit_value, value2 = limit_value; //...access all current genes and in a semi-stochastic way, pick two low-value parents for (int j=0; j<GENES; j++) { float value = (float) (10 + RandomInteger(10,20)*utilityValues[j] ); if (value<=value1) { value2 = value1; index2 = index1; value1 = value; index1 = j; } else if (value<value2) { value2 = value; index2 = j; } } //...then copy the parents to the new array for (int k=0; k<N; k++) { genesNew[i][k] = genes[index1][k]; genesNew[i+1][k] = genes[index2][k]; } //...breed and mutate their children CrossoverFunction(genesNew[i], genesNew[i+1]); MutationFunction(genesNew[i]); MutationFunction(genesNew[i+1]); } // Finally copy the new genes into the old ones for (int i=0; i<GENES; i++) { for (int j=0; j<N; j++) { genes[i][j] = genesNew[i][j]; } } } /** * Calculate and store all current genes utility values */ unsigned CalculateAllUtilityValues(int genes[GENES][N], int utilityValues[GENES]) { int bestUtilityValueFoundAt = 0; for (int i=0; i<GENES; i++) { utilityValues[i] = UtilityFunction(genes[i]); if (utilityValues[i] < utilityValues[bestUtilityValueFoundAt]) { bestUtilityValueFoundAt = i; } } return bestUtilityValueFoundAt; } /** * Runs the genetic algorithm to solve the problem */ long int Solve(int fittestGene[N], unsigned threadID, int *whoHasFinished, unsigned *solversGenerations) { srand(threadID); int genes[GENES][N]; int utilityValues[GENES] = {1}; //Create a random set of genes GeneInitialization(genes); long int generation = 0; unsigned bestGene = 0; //While no solution is found while(utilityValues[bestGene]!=0 && *whoHasFinished<0) { generation++; //...for each repetition create the next generation of genes BreedGeneration(genes, utilityValues); //...and calculate all genes's utility values bestGene = CalculateAllUtilityValues(genes, utilityValues); } //After a correct gene has been found, store it in <fittestGene[N]> that is visible to main() #pragma omp critical { *whoHasFinished = threadID; *solversGenerations = generation; for (int i=0; i<N; i++) fittestGene[i] = genes[bestGene][i]; } return generation; } /** * The main program */ int main() { printf("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("This program implements my Genetic Algorithm method of solving the \"N-Queens Problem\".\n"); printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"); int fittestGene[N] = {0}; int numberOfThreads = 1, whoHasFinished = -1; unsigned solversGenerations = 0; long int totalGenerations = 0; printf("Queens set at: %d Genes set at: %d\n", N, GENES); printf("Now solving the problem. Please wait...\n"); #pragma omp parallel num_threads(TARGET_THREADS) reduction(+:totalGenerations) { //Check how many threads were created #pragma omp single numberOfThreads = omp_get_num_threads(); //Tell each thread to start searching for a solution totalGenerations = Solve(fittestGene, omp_get_thread_num(), &whoHasFinished, &solversGenerations); } printf("Algorithm completed. Number of threads used: %d Total generations: %ld\n", numberOfThreads, totalGenerations); printf("Solution found by thread #%d in #%u generations.\n", whoHasFinished, solversGenerations); printf("The solution found is:\n"); //Map3(fittestGene, N); return 0; }
the_stack_data/80166.c
#include<stdio.h> int main(void){ printf("output of main.c\n"); return 0; }
the_stack_data/93887428.c
// 1131 - Grenais #include <stdio.h> int main(){ int golInter, golGremio, vitInter, vitGremio, empates ,nGrenais; int golTgremio, golTinter; golInter = golGremio = vitInter = vitGremio = nGrenais = empates =0; int controle; while(1){ scanf("%d %d", &golInter, &golGremio); nGrenais +=1; if(golInter == golGremio){ empates += 1; } else{ if(golInter > golGremio){ vitInter += 1; } else{ vitGremio += 1; } } golTinter += golInter; golTgremio += golTgremio; printf("Novo grenal (1-sim 2-nao)\n"); scanf("%d", &controle); if(controle == 1){ //sim continue; } else{ // não printf("%d grenais\n", nGrenais); printf("Inter:%d\n", vitInter); printf("Gremio:%d\n", vitGremio); printf("Empates:%d\n", empates); if(vitInter == vitGremio){ printf("Nao houve vencedor\n"); } else{ if(vitInter > vitGremio){ printf("Inter venceu mais\n"); } else{ printf("Gremio venceu mais\n"); } } break; } } return 0; }
the_stack_data/60420.c
/* Check that the three loops are fused. */ /* Make sure we fuse the loops like this: AST generated by isl: for (int c0 = 0; c0 <= 99; c0 += 1) { S_3(c0); S_6(c0); S_9(c0); } */ /* { dg-final { scan-tree-dump-times "AST generated by isl:.*for \\(int c0 = 0; c0 <= 99; c0 \\+= 1\\) \\{.*S_.*\\(c0\\);.*S_.*\\(c0\\);.*S_.*\\(c0\\);.*\\}" 1 "graphite" } } */ #define MAX 100 int A[MAX], B[MAX], C[MAX]; extern void abort (); int main (void) { int i; /* The next three loops should be fused. */ for (i = 0; i < MAX; i++) { A[i] = i; B[i] = i + 2; C[i] = i + 1; } for(i=0; i<MAX; i++) A[i] += B[i]; for(i=0; i<MAX; i++) A[i] += C[i]; for (i = 0; i < MAX; i++) if (A[i] != 3*i+3) abort (); return 0; }
the_stack_data/47366.c
/* { dg-do compile } */ /* { dg-options "-fsanitize-recover=all" } */ int i;
the_stack_data/126702783.c
//***************************************************************************** // // startup_ccs.c - Startup code for use with TI's Code Composer Studio. // // Copyright (c) 2009-2012 Texas Instruments Incorporated. All rights reserved. // Software License Agreement // // Texas Instruments (TI) is supplying this software for use solely and // exclusively on TI's microcontroller products. The software is owned by // TI and/or its suppliers, and is protected under applicable copyright // laws. You may not combine this software with "viral" open-source // software in order to form a larger program. // // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL // DAMAGES, FOR ANY REASON WHATSOEVER. // // This is part of revision 8555 of the EK-LM3S9B90 Firmware Package. // //***************************************************************************** //***************************************************************************** // // Forward declaration of the default fault handlers. // //***************************************************************************** void ResetISR(void); static void NmiSR(void); static void FaultISR(void); static void IntDefaultHandler(void); //***************************************************************************** // // External declaration for the reset handler that is to be called when the // processor is started // //***************************************************************************** extern void _c_int00(void); //***************************************************************************** // // Linker variable that marks the top of the stack. // //***************************************************************************** extern unsigned long __STACK_TOP; //***************************************************************************** // // The vector table. Note that the proper constructs must be placed on this to // ensure that it ends up at physical address 0x0000.0000 or at the start of // the program if located at a start address other than 0. // //***************************************************************************** #pragma DATA_SECTION(g_pfnVectors, ".intvecs") void (* const g_pfnVectors[])(void) = { (void (*)(void))((unsigned long)&__STACK_TOP), // The initial stack pointer ResetISR, // The reset handler NmiSR, // The NMI handler FaultISR, // The hard fault handler IntDefaultHandler, // The MPU fault handler IntDefaultHandler, // The bus fault handler IntDefaultHandler, // The usage fault handler 0, // Reserved 0, // Reserved 0, // Reserved 0, // Reserved IntDefaultHandler, // SVCall handler IntDefaultHandler, // Debug monitor handler 0, // Reserved IntDefaultHandler, // The PendSV handler IntDefaultHandler, // The SysTick handler IntDefaultHandler, // GPIO Port A IntDefaultHandler, // GPIO Port B IntDefaultHandler, // GPIO Port C IntDefaultHandler, // GPIO Port D IntDefaultHandler, // GPIO Port E IntDefaultHandler, // UART0 Rx and Tx IntDefaultHandler, // UART1 Rx and Tx IntDefaultHandler, // SSI0 Rx and Tx IntDefaultHandler, // I2C0 Master and Slave IntDefaultHandler, // PWM Fault IntDefaultHandler, // PWM Generator 0 IntDefaultHandler, // PWM Generator 1 IntDefaultHandler, // PWM Generator 2 IntDefaultHandler, // Quadrature Encoder 0 IntDefaultHandler, // ADC Sequence 0 IntDefaultHandler, // ADC Sequence 1 IntDefaultHandler, // ADC Sequence 2 IntDefaultHandler, // ADC Sequence 3 IntDefaultHandler, // Watchdog timer IntDefaultHandler, // Timer 0 subtimer A IntDefaultHandler, // Timer 0 subtimer B IntDefaultHandler, // Timer 1 subtimer A IntDefaultHandler, // Timer 1 subtimer B IntDefaultHandler, // Timer 2 subtimer A IntDefaultHandler, // Timer 2 subtimer B IntDefaultHandler, // Analog Comparator 0 IntDefaultHandler, // Analog Comparator 1 IntDefaultHandler, // Analog Comparator 2 IntDefaultHandler, // System Control (PLL, OSC, BO) IntDefaultHandler, // FLASH Control IntDefaultHandler, // GPIO Port F IntDefaultHandler, // GPIO Port G IntDefaultHandler, // GPIO Port H IntDefaultHandler, // UART2 Rx and Tx IntDefaultHandler, // SSI1 Rx and Tx IntDefaultHandler, // Timer 3 subtimer A IntDefaultHandler, // Timer 3 subtimer B IntDefaultHandler, // I2C1 Master and Slave IntDefaultHandler, // Quadrature Encoder 1 IntDefaultHandler, // CAN0 IntDefaultHandler, // CAN1 IntDefaultHandler, // CAN2 IntDefaultHandler, // Ethernet IntDefaultHandler, // Hibernate IntDefaultHandler, // USB0 IntDefaultHandler, // PWM Generator 3 IntDefaultHandler, // uDMA Software Transfer IntDefaultHandler, // uDMA Error IntDefaultHandler, // ADC1 Sequence 0 IntDefaultHandler, // ADC1 Sequence 1 IntDefaultHandler, // ADC1 Sequence 2 IntDefaultHandler, // ADC1 Sequence 3 IntDefaultHandler, // I2S0 IntDefaultHandler, // External Bus Interface 0 IntDefaultHandler // GPIO Port J }; //***************************************************************************** // // This is the code that gets called when the processor first starts execution // following a reset event. Only the absolutely necessary set is performed, // after which the application supplied entry() routine is called. Any fancy // actions (such as making decisions based on the reset cause register, and // resetting the bits in that register) are left solely in the hands of the // application. // //***************************************************************************** void ResetISR(void) { // // Jump to the CCS C initialization routine. // __asm(" .global _c_int00\n" " b.w _c_int00"); } //***************************************************************************** // // This is the code that gets called when the processor receives a NMI. This // simply enters an infinite loop, preserving the system state for examination // by a debugger. // //***************************************************************************** static void NmiSR(void) { // // Enter an infinite loop. // while(1) { } } //***************************************************************************** // // This is the code that gets called when the processor receives a fault // interrupt. This simply enters an infinite loop, preserving the system state // for examination by a debugger. // //***************************************************************************** static void FaultISR(void) { // // Enter an infinite loop. // while(1) { } } //***************************************************************************** // // This is the code that gets called when the processor receives an unexpected // interrupt. This simply enters an infinite loop, preserving the system state // for examination by a debugger. // //***************************************************************************** static void IntDefaultHandler(void) { // // Go into an infinite loop. // while(1) { } }
the_stack_data/187642641.c
int kbd_test_scan(unsigned short assembly) { /* To be completed */ } int kbd_test_poll() { /* To be completed */ } int kbd_test_timed_scan(unsigned short n) { /* To be completed */ }
the_stack_data/22013030.c
#include <stdio.h> #include <unistd.h> #include <stdint.h> #include <sys/stat.h> #include <sys/types.h> #include <errno.h> #include <fcntl.h> void jump_esp() { __asm__ ("jmp *%esp;"); } void read_into_buffer(int fd) { char buf[10]; read(fd, buf, 1000); } int main(int argc, char ** argv) { if (argc != 2) { printf("usage: buffer_overrun $FILE\n"); return 1; } int fd = open(argv[1], O_RDONLY); if (fd < 0) { printf("No such file\n"); return 1; } read_into_buffer(fd); return 0; }
the_stack_data/48370.c
#include <stdio.h> int main() { int ara[1001]; int n, t = 0, steps = 1, i, j = 0; scanf("%d", &n); for(i = 0; i < n; i++) { scanf("%d", &ara[i]); } for(i = 0; i < n; i++) { if(ara[i] == 1) t += 1; } printf("%d\n", t); for(i = 0; i < n; i++) { if(ara[i] == 1) { steps = 1; j = i + 1; for(; ara[j] != 1; j++) { if(j >= n) break; steps += 1; } printf("%d ", steps); } } return 0; }
the_stack_data/151705975.c
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <time.h> #define LOTTO_NUMBER_MAX 49 #define NUMBER_DRAWS 6 int main(int argc, const char *argv[]) { // Erzeuge random werte srand(time(NULL)); // Lege das array an bool arr[LOTTO_NUMBER_MAX]; // Setze alle werte auf false for(int i = 0; i < LOTTO_NUMBER_MAX; ++i) { arr[i] = false; } // Ziehung for(int i = 0; i < NUMBER_DRAWS; ++i) { int z; do { z = rand() % LOTTO_NUMBER_MAX; } while (arr[z]); arr[z] = true; } // Gezogene Zahlen ausgeben, true bedeutet Ziehung printf("\nDas sind die Lottozahlen:\n"); for(int i = 0; i < LOTTO_NUMBER_MAX; ++i) { if(arr[i]) { printf(">> %d\n", i+1); } } return 0; }
the_stack_data/1250071.c
/* * Copyright (c) 2014 - 2015, Kurt Cancemi ([email protected]) * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ int OPENSSL_issetugid(void) { return 1; }
the_stack_data/760571.c
// Program 10.5 // Program to illustrate the %s scanf format characters #include<stdio.h> int main( void ) { char s1[81], s2[81], s3[81]; printf( "Enter text:\n" ); scanf( "%s%s%s", s1, s2, s3 ); printf( "\ns1 = %s\ns2 = %s\ns3 = %s\n", s1, s2, s3 ); return 0; }
the_stack_data/429756.c
// PARAM: --set ana.activated[+] "'region'" #include<pthread.h> #include<stdlib.h> #include<stdio.h> struct s { int datum; struct s *next; } *A, *B; struct s *new(int x) { struct s *p = malloc(sizeof(struct s)); p->datum = x; p->next = NULL; return p; } pthread_mutex_t A_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t B_mutex = PTHREAD_MUTEX_INITIALIZER; void *t_fun(void *arg) { pthread_mutex_lock(&A_mutex); A->datum++; // RACE <-- this line is also relevant. pthread_mutex_unlock(&A_mutex); pthread_mutex_lock(&B_mutex); B->datum++; // <-- this is not relevant at all. pthread_mutex_unlock(&B_mutex); return NULL; } int main () { pthread_t t1; A = new(3); B = new(5); pthread_create(&t1, NULL, t_fun, NULL); int *data; pthread_mutex_lock(&A_mutex); data = &A->datum; // NORACE pthread_mutex_unlock(&A_mutex); *data = 42; // RACE <-- this is the real bug! return 0; }
the_stack_data/20932.c
static void __attribute__ ((constructor)) mylib_init(void) { hs_init(0, 0); }
the_stack_data/148576854.c
#include <stdio.h> int main() { printf("Hello, World!\n"); printf("Welcome to C programming."); return 0; }
the_stack_data/141549.c
// WARNING: The files in this directory have not been extensively tested // and may be incorrect. --JTB void main(int N) { int x = 2; int y = 1; int z = 1; for(int t = 0; t < N; t++) { if (x > y) { y = y + 2; z = (x - y) * (x - y); } else { x = x + 2; z = (x - y) * (x - y); } } assert((x - y) * (x - y) == 1); }
the_stack_data/669504.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strcmp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: cado-car <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/06/18 16:40:06 by cado-car #+# #+# */ /* Updated: 2021/06/18 16:40:07 by cado-car ### ########.fr */ /* */ /* ************************************************************************** */ int ft_strcmp(char *s1, char *s2) { while ((*s1 && *s2) != '\0' && *s1 == *s2) { s1++; s2++; } return (*(unsigned char *)s1 - *(unsigned char *)s2); }
the_stack_data/18888573.c
#include<stdlib.h> int main(){ system("./../../Files/22.sh"); return 0; }
the_stack_data/103265965.c
#include <math.h> extern double cephes_Gamma (double x); #define EPS 1.0e-17 double besselpoly(double a, double lambda, double nu) { int m, factor=0; double Sm, relerr, Sol; double sum=0.0; /* Special handling for a = 0.0 */ if (a == 0.0) { if (nu == 0.0) return 1.0/(lambda + 1); else return 0.0; } /* Special handling for negative and integer nu */ if ((nu < 0) && (floor(nu)==nu)) { nu = -nu; factor = ((int) nu) % 2; } Sm = exp(nu*log(a))/(cephes_Gamma(nu+1)*(lambda+nu+1)); m = 0; do { sum += Sm; Sol = Sm; Sm *= -a*a*(lambda+nu+1+2*m)/((nu+m+1)*(m+1)*(lambda+nu+1+2*m+2)); m++; relerr = fabs((Sm-Sol)/Sm); } while (relerr > EPS && m < 1000); if (!factor) return sum; else return -sum; }
the_stack_data/111901.c
#include <stdio.h> #define MAXLINE 10 int my_getline(char s[], int lim); void my_reverse(char s[]); int main() { int len; char line[MAXLINE]; while ((len = my_getline(line, MAXLINE)) > 0) { printf("origin: %s", line); my_reverse(line); printf("%s", line); } return 0; } void my_reverse(char s[]) { int i = 0, len = 0; char tmp; while (s[len] != '\n') { ++len; } printf("len: %d\n", len); printf("len/2: %d\n", len/2); for (i = 0; i < len/2; ++i) { tmp = s[i]; s[i] = s[len -i]; s[len - i] = tmp; } } int my_getline(char s[], int lim) { int c, i, j; j = 0; for (i = 0; (c = getchar())!=EOF && c!='\n'; ++i) { if (i < lim - 2) { s[j] = c; ++j; } } if (c == '\n') { s[j] = c; ++j; ++i; } s[j] = '\0'; return i; }
the_stack_data/199605.c
/* ID: fabioya1 LANG: C PROG: beads */ #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { FILE *fin = fopen("beads.in", "r"); FILE *fout = fopen("beads.out", "w"); int n, attempt, best, i, j, changed; char color; char necklace[800]; fscanf(fin, "%d", &n); fscanf(fin, "%s", necklace); // duplicate the necklance strncpy(&necklace[n], necklace, n); best = 0; for (i = 0; i < n; ++i) { attempt = 0; color = 0; changed = 0; for (j = 0; j < n; ++j) { if (necklace[i+j] == 'w') { /* wildcard */ attempt += 1; } else if (necklace[i+j] == 'r' || necklace[i+j] == 'b') { if (color == 0) { // set the initial bead color color = necklace[i+j]; } if (color == necklace[i+j]) { attempt += 1; } else { if (changed) { break; } else { changed = 1; color = necklace[i+j]; attempt += 1; } } } } if (attempt > best) { best = attempt; } } fprintf(fout, "%d\n", best); exit(0); }
the_stack_data/14200856.c
#include <stdio.h> #include <stdlib.h> int main(int argc, char** argv){ if (argc != 3 && 1) { printf("Nombre de parametres insuffisant\n"); return 1; } int i, distance = atoi(argv[1]), days = atoi(argv[2]), kmPerDay[days]; float totalDiesel, totalEssence, temp, dieselPricePerDay[days], bestPrice; char bestCarburant; totalDiesel = totalEssence = 0; for(i = 0; i < days; i++) kmPerDay[i] = distance/days; kmPerDay[days-1] += (distance % days); for(i = 0; i < days; i++){ (temp = kmPerDay[i]*0.13) > 10 ? (totalEssence += temp) : (totalEssence += 10); (temp = kmPerDay[i]*0.11) > 8 ? (totalDiesel += temp) : (totalDiesel += 8); totalEssence += 30; totalDiesel += 33.4; } (totalEssence < totalDiesel) ? (bestCarburant = 'e') : (bestCarburant = 'd'); (totalEssence < totalDiesel) ? (bestPrice = totalEssence) : (bestPrice = totalDiesel); printf("e %.2f d %.2f m %c %.2f", (totalEssence*1.196), (totalDiesel*1.196), bestCarburant, (bestPrice*1.196)); return 0; }
the_stack_data/20449400.c
//////////////////////////////////////////////////////////////////////////// // a.c // Copyright (C) 2013-2014 Katayama Hirofumi MZ. All rights reserved. //////////////////////////////////////////////////////////////////////////// // This file is part of CodeReverse. //////////////////////////////////////////////////////////////////////////// // gcc -m32 -O0 -o a.exe a.c #include <stdio.h> int main(void) { char b; int n1, n2; n1 = 0x7FFFFFFF; n2 = 1; __asm__( "stc\n" "movl $0x7FFFFFFF,%%eax\n" "adc $1,%%eax\n" "seto %0\n" :: "m"(b) : "%eax"); printf("0x%08lX + 0x%08lX = 0x%08lX (%d) ", n1, n2, n1 + n2, b); printf("%d\n", (n1 < 0 && n2 < 0 && n1 + n2 + 1 >= 0) || (n1 >= 0 && n2 >= 0 && n1 + n2 + 1 < 0)); n1 = 0x7FFFFFFF; n2 = -1; __asm__( "stc\n" "movl $0x7FFFFFFF,%%eax\n" "adc $-1,%%eax\n" "seto %0\n" :: "m"(b) : "%eax"); printf("0x%08lX + 0x%08lX = 0x%08lX (%d) ", n1, n2, n1 + n2, b); printf("%d\n", (n1 < 0 && n2 < 0 && n1 + n2 + 1 >= 0) || (n1 >= 0 && n2 >= 0 && n1 + n2 + 1 < 0)); n1 = -1; n2 = 0x7FFFFFFF; __asm__( "stc\n" "movl $-1,%%eax\n" "adc $0x7FFFFFFF,%%eax\n" "seto %0\n" :: "m"(b) : "%eax"); printf("0x%08lX + 0x%08lX = 0x%08lX (%d) ", n1, n2, n1 + n2, b); printf("%d\n", (n1 < 0 && n2 < 0 && n1 + n2 + 1 >= 0) || (n1 >= 0 && n2 >= 0 && n1 + n2 + 1 < 0)); n1 = 1; n2 = 0x7FFFFFFF; __asm__( "stc\n" "movl $1,%%eax\n" "adc $0x7FFFFFFF,%%eax\n" "seto %0\n" :: "m"(b) : "%eax"); printf("0x%08lX + 0x%08lX = 0x%08lX (%d) ", n1, n2, n1 + n2, b); printf("%d\n", (n1 < 0 && n2 < 0 && n1 + n2 + 1 >= 0) || (n1 >= 0 && n2 >= 0 && n1 + n2 + 1 < 0)); n1 = -1; n2 = 1; __asm__( "stc\n" "movl $-1,%%eax\n" "adc $1,%%eax\n" "seto %0\n" :: "m"(b) : "%eax"); printf("0x%08lX + 0x%08lX = 0x%08lX (%d) ", n1, n2, n1 + n2, b); printf("%d\n", (n1 < 0 && n2 < 0 && n1 + n2 + 1 >= 0) || (n1 >= 0 && n2 >= 0 && n1 + n2 + 1 < 0)); n1 = 1; n2 = -1; __asm__( "stc\n" "movl $1,%%eax\n" "adc $-1,%%eax\n" "seto %0\n" :: "m"(b) : "%eax"); printf("0x%08lX + 0x%08lX = 0x%08lX (%d) ", n1, n2, n1 + n2, b); printf("%d\n", (n1 < 0 && n2 < 0 && n1 + n2 + 1 >= 0) || (n1 >= 0 && n2 >= 0 && n1 + n2 + 1 < 0)); n1 = -1; n2 = 2; __asm__( "stc\n" "movl $-1,%%eax\n" "adc $2,%%eax\n" "seto %0\n" :: "m"(b) : "%eax"); printf("0x%08lX + 0x%08lX = 0x%08lX (%d) ", n1, n2, n1 + n2, b); printf("%d\n", (n1 < 0 && n2 < 0 && n1 + n2 + 1 >= 0) || (n1 >= 0 && n2 >= 0 && n1 + n2 + 1 < 0)); n1 = 1; n2 = -2; __asm__( "stc\n" "movl $1,%%eax\n" "adc $-2,%%eax\n" "seto %0\n" :: "m"(b) : "%eax"); printf("0x%08lX + 0x%08lX = 0x%08lX (%d) ", n1, n2, n1 + n2, b); printf("%d\n", (n1 < 0 && n2 < 0 && n1 + n2 + 1 >= 0) || (n1 >= 0 && n2 >= 0 && n1 + n2 + 1 < 0)); n1 = 2; n2 = -2; __asm__( "stc\n" "movl $2,%%eax\n" "adc $-2,%%eax\n" "seto %0\n" :: "m"(b) : "%eax"); printf("0x%08lX + 0x%08lX = 0x%08lX (%d) ", n1, n2, n1 + n2, b); printf("%d\n", (n1 < 0 && n2 < 0 && n1 + n2 + 1 >= 0) || (n1 >= 0 && n2 >= 0 && n1 + n2 + 1 < 0)); n1 = 0x80000000; n2 = 0x80000000; __asm__( "stc\n" "movl $0x80000000,%%eax\n" "adc $0x80000000,%%eax\n" "seto %0\n" :: "m"(b) : "%eax"); printf("0x%08lX + 0x%08lX = 0x%08lX (%d) ", n1, n2, n1 + n2, b); printf("%d\n", (n1 < 0 && n2 < 0 && n1 + n2 + 1 >= 0) || (n1 >= 0 && n2 >= 0 && n1 + n2 + 1 < 0)); n1 = -3; n2 = -2; __asm__( "stc\n" "movl $-3,%%eax\n" "adc $-2,%%eax\n" "seto %0\n" :: "m"(b) : "%eax"); printf("0x%08lX + 0x%08lX = 0x%08lX (%d) ", n1, n2, n1 + n2, b); printf("%d\n", (n1 < 0 && n2 < 0 && n1 + n2 + 1 >= 0) || (n1 >= 0 && n2 >= 0 && n1 + n2 + 1 < 0)); return 0; }
the_stack_data/247016949.c
/******************************************************************************* * PROGRAM: simple_edge * PURPOSE: This program implements a simple edge detector. The processing * steps are as follows: * * 1) Take the dx and dy the first derivatives using [-1,0,1] and [1,0,-1]'. * 2) Compute the magnitude: sqrt(dx*dx+dy*dy). * 3) Perform non-maximal suppression. * 4) Perform hysteresis. * * The user must input three parameters. These are as follows: * * tlow = Specifies the low value to use in hysteresis. This is a * fraction (0-1) of the computed high threshold edge strength value. * thigh = Specifies the high value to use in hysteresis. This fraction (0-1) * specifies the percentage point in a histogram of the gradient of * the magnitude. Magnitude values of zero are not counted in the * histogram. * * NAME: Mike Heath * Computer Vision Laboratory * University of South Florida * [email protected] * * DATE: 9/11/97 *******************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #define NOEDGE 255 #define POSSIBLE_EDGE 128 #define EDGE 0 #define NOTMAIN #define VERBOSE 0 #define BOOSTBLURFACTOR 1.0 int read_pgm_image(char *infilename, unsigned char **image, int *rows, int *cols); int write_pgm_image(char *outfilename, unsigned char *image, int rows, int cols, char *comment, int maxval); void gaussian_smooth(unsigned short int *image, int rows, int cols, float sigma, float **smoothedim); void make_gaussian_kernel(float sigma, float **kernel, int *windowsize); void derrivative_x_y(short int *smoothedim, int rows, int cols, short int **delta_x, short int **delta_y); void magnitude_x_y(short int *delta_x, short int *delta_y, int rows, int cols, short int **magnitude); void apply_hysteresis(short int *mag, unsigned char *nms, int rows, int cols, float tlow, float thigh, unsigned char *edge); void radian_direction(short int *delta_x, short int *delta_y, int rows, int cols, float **dir_radians, int xdirtag, int ydirtag); double angle_radians(double x, double y); /******************************************************************************* * Procedure: radian_direction * Purpose: To compute a direction of the gradient image from component dx and * dy images. Because not all derriviatives are computed in the same way, this * code allows for dx or dy to have been calculated in different ways. * * FOR X: xdirtag = -1 for [-1 0 1] * xdirtag = 1 for [ 1 0 -1] * * FOR Y: ydirtag = -1 for [-1 0 1]' * ydirtag = 1 for [ 1 0 -1]' * * The resulting angle is in radians measured counterclockwise from the * xdirection. The angle points "up the gradient". *******************************************************************************/ void radian_direction(short int *delta_x, short int *delta_y, int rows, int cols, float **dir_radians, int xdirtag, int ydirtag) { int r, c, pos; float *dirim=NULL; double dx, dy; /**************************************************************************** * Allocate an image to store the direction of the gradient. ****************************************************************************/ if((dirim = (float *) calloc(rows*cols, sizeof(float))) == NULL){ fprintf(stderr, "Error allocating the gradient direction image.\n"); exit(1); } *dir_radians = dirim; for(r=0,pos=0;r<rows;r++){ for(c=0;c<cols;c++,pos++){ dx = (double)delta_x[pos]; dy = (double)delta_y[pos]; if(xdirtag == 1) dx = -dx; if(ydirtag == -1) dy = -dy; dirim[pos] = (float)angle_radians(dx, dy); } } } /******************************************************************************* * FUNCTION: angle_radians * PURPOSE: This procedure computes the angle of a vector with components x and * y. It returns this angle in radians with the answer being in the range * 0 <= angle <2*PI. *******************************************************************************/ double angle_radians(double x, double y) { double xu, yu, ang; xu = fabs(x); yu = fabs(y); if((xu == 0) && (yu == 0)) return(0); ang = atan(yu/xu); if(x >= 0){ if(y >= 0) return(ang); else return(2*M_PI - ang); } else{ if(y >= 0) return(M_PI - ang); else return(M_PI + ang); } } /******************************************************************************* * PROCEDURE: magnitude_x_y * PURPOSE: Compute the magnitude of the gradient. This is the square root of * the sum of the squared derivative values. * NAME: Mike Heath * DATE: 2/15/96 *******************************************************************************/ void magnitude_x_y(short int *delta_x, short int *delta_y, int rows, int cols, short int **magnitude) { int r, c, pos, sq1, sq2; /**************************************************************************** * Allocate an image to store the magnitude of the gradient. ****************************************************************************/ if((*magnitude = (short *) calloc(rows*cols, sizeof(short))) == NULL){ fprintf(stderr, "Error allocating the magnitude image.\n"); exit(1); } for(r=0,pos=0;r<rows;r++){ for(c=0;c<cols;c++,pos++){ sq1 = (int)delta_x[pos] * (int)delta_x[pos]; sq2 = (int)delta_y[pos] * (int)delta_y[pos]; (*magnitude)[pos] = (short)(0.5 + sqrt((float)sq1 + (float)sq2)); } } } /******************************************************************************* * PROCEDURE: derrivative_x_y * PURPOSE: Compute the first derivative of the image in both the x any y * directions. The differential filters that are used are: * * -1 * dx = -1 0 +1 and dy = 0 * +1 * * NAME: Mike Heath * DATE: 2/15/96 *******************************************************************************/ void derrivative_x_y(short int *smoothedim, int rows, int cols, short int **delta_x, short int **delta_y) { int r, c, pos; /**************************************************************************** * Allocate images to store the derivatives. ****************************************************************************/ if(((*delta_x) = (short *) calloc(rows*cols, sizeof(short))) == NULL){ fprintf(stderr, "Error allocating the delta_x image.\n"); exit(1); } if(((*delta_y) = (short *) calloc(rows*cols, sizeof(short))) == NULL){ fprintf(stderr, "Error allocating the delta_x image.\n"); exit(1); } /**************************************************************************** * Compute the x-derivative. Adjust the derivative at the borders to avoid * losing pixels. ****************************************************************************/ if(VERBOSE) printf(" Computing the X-direction derivative.\n"); for(r=0;r<rows;r++){ pos = r * cols; (*delta_x)[pos] = smoothedim[pos+1] - smoothedim[pos]; pos++; for(c=1;c<(cols-1);c++,pos++){ (*delta_x)[pos] = smoothedim[pos+1] - smoothedim[pos-1]; } (*delta_x)[pos] = smoothedim[pos] - smoothedim[pos-1]; } /**************************************************************************** * Compute the y-derivative. Adjust the derivative at the borders to avoid * losing pixels. ****************************************************************************/ if(VERBOSE) printf(" Computing the Y-direction derivative.\n"); for(c=0;c<cols;c++){ pos = c; (*delta_y)[pos] = smoothedim[pos+cols] - smoothedim[pos]; pos += cols; for(r=1;r<(rows-1);r++,pos+=cols){ (*delta_y)[pos] = smoothedim[pos+cols] - smoothedim[pos-cols]; } (*delta_y)[pos] = smoothedim[pos] - smoothedim[pos-cols]; } } /******************************************************************************* * PROCEDURE: gaussian_smooth * PURPOSE: Blur an image with a gaussian filter. * NAME: Mike Heath * DATE: 2/15/96 *******************************************************************************/ void gaussian_smooth(unsigned short int *image, int rows, int cols, float sigma, float **smoothedim) { int r, c, rr, cc, /* Counter variables. */ windowsize, /* Dimension of the gaussian kernel. */ center; /* Half of the windowsize. */ float *tempim, /* Buffer for separable filter gaussian smoothing. */ *kernel, /* A one dimensional gaussian kernel. */ dot, /* Dot product summing variable. */ sum; /* Sum of the kernel weights variable. */ /**************************************************************************** * Create a 1-dimensional gaussian smoothing kernel. ****************************************************************************/ if(VERBOSE) printf(" Computing the gaussian smoothing kernel.\n"); make_gaussian_kernel(sigma, &kernel, &windowsize); center = windowsize / 2; /**************************************************************************** * Allocate a temporary buffer image and the smoothed image. ****************************************************************************/ if((tempim = (float *) calloc(rows*cols, sizeof(float))) == NULL){ fprintf(stderr, "Error allocating the buffer image.\n"); exit(1); } if(((*smoothedim) = (float *) calloc(rows*cols, sizeof(float))) == NULL){ fprintf(stderr, "Error allocating the smoothed image.\n"); exit(1); } /**************************************************************************** * Blur in the x - direction. ****************************************************************************/ if(VERBOSE) printf(" Bluring the image in the X-direction.\n"); for(r=0;r<rows;r++){ for(c=0;c<cols;c++){ dot = 0.0; sum = 0.0; for(cc=(-center);cc<=center;cc++){ if(((c+cc) >= 0) && ((c+cc) < cols)){ dot += (float)image[r*cols+(c+cc)] * kernel[center+cc]; sum += kernel[center+cc]; } } tempim[r*cols+c] = dot/sum; } } /**************************************************************************** * Blur in the y - direction. ****************************************************************************/ if(VERBOSE) printf(" Bluring the image in the Y-direction.\n"); for(c=0;c<cols;c++){ for(r=0;r<rows;r++){ sum = 0.0; dot = 0.0; for(rr=(-center);rr<=center;rr++){ if(((r+rr) >= 0) && ((r+rr) < rows)){ dot += tempim[(r+rr)*cols+c] * kernel[center+rr]; sum += kernel[center+rr]; } } (*smoothedim)[r*cols+c] = dot*BOOSTBLURFACTOR/sum; } } free(tempim); free(kernel); } /******************************************************************************* * PROCEDURE: make_gaussian_kernel * PURPOSE: Create a one dimensional gaussian kernel. * NAME: Mike Heath * DATE: 2/15/96 *******************************************************************************/ void make_gaussian_kernel(float sigma, float **kernel, int *windowsize) { int i, center; float x, fx, sum=0.0; *windowsize = 1 + 2 * ceil(2.5 * sigma); center = (*windowsize) / 2; if(VERBOSE) printf(" The kernel has %d elements.\n", *windowsize); if((*kernel = (float *) calloc((*windowsize), sizeof(float))) == NULL){ fprintf(stderr, "Error callocing the gaussian kernel array.\n"); exit(1); } for(i=0;i<(*windowsize);i++){ x = (float)(i - center); fx = pow(2.71828, -0.5*x*x/(sigma*sigma)) / (sigma * sqrt(6.2831853)); (*kernel)[i] = fx; sum += fx; } for(i=0;i<(*windowsize);i++) (*kernel)[i] /= sum; if(VERBOSE){ printf("The filter coefficients are:\n"); for(i=0;i<(*windowsize);i++) printf("kernel[%d] = %f\n", i, (*kernel)[i]); } } /******************************************************************************* * FILE: hysteresis.c * This code was re-written by Mike Heath from original code obtained indirectly * from Michigan State University. [email protected] (Re-written in 1996). *******************************************************************************/ /******************************************************************************* * PROCEDURE: follow_edges * PURPOSE: This procedure edges is a recursive routine that traces edgs along * all paths whose magnitude values remain above some specifyable lower * threshhold. * NAME: Mike Heath * DATE: 2/15/96 *******************************************************************************/ follow_edges(unsigned char *edgemapptr, short *edgemagptr, short lowval, int cols) { short *tempmagptr; unsigned char *tempmapptr; int i; float thethresh; int x[8] = {1,1,0,-1,-1,-1,0,1}, y[8] = {0,1,1,1,0,-1,-1,-1}; for(i=0;i<8;i++){ tempmapptr = edgemapptr - y[i]*cols + x[i]; tempmagptr = edgemagptr - y[i]*cols + x[i]; if((*tempmapptr == POSSIBLE_EDGE) && (*tempmagptr > lowval)){ *tempmapptr = (unsigned char) EDGE; follow_edges(tempmapptr,tempmagptr, lowval, cols); } } } /******************************************************************************* * PROCEDURE: apply_hysteresis * PURPOSE: This routine finds edges that are above some high threshhold or * are connected to a high pixel by a path of pixels greater than a low * threshold. * NAME: Mike Heath * DATE: 2/15/96 *******************************************************************************/ void apply_hysteresis(short int *mag, unsigned char *nms, int rows, int cols, float tlow, float thigh, unsigned char *edge) { int r, c, pos, numedges, lowcount, highcount, lowthreshold, highthreshold, i, hist[32768], rr, cc; short int maximum_mag, sumpix; /**************************************************************************** * Initialize the edge map to possible edges everywhere the non-maximal * suppression suggested there could be an edge except for the border. At * the border we say there can not be an edge because it makes the * follow_edges algorithm more efficient to not worry about tracking an * edge off the side of the image. ****************************************************************************/ printf("Initializing the edge image.\n"); for(r=0,pos=0;r<rows;r++){ for(c=0;c<cols;c++,pos++){ if(nms[pos] == POSSIBLE_EDGE) edge[pos] = POSSIBLE_EDGE; else edge[pos] = NOEDGE; } } for(r=0,pos=0;r<rows;r++,pos+=cols){ edge[pos] = NOEDGE; edge[pos+cols-1] = NOEDGE; } pos = (rows-1) * cols; for(c=0;c<cols;c++,pos++){ edge[c] = NOEDGE; edge[pos] = NOEDGE; } /**************************************************************************** * Compute the histogram of the magnitude image. Then use the histogram to * compute hysteresis thresholds. ****************************************************************************/ printf("Computing the histogram.\n"); for(r=0;r<32768;r++) hist[r] = 0; for(r=0,pos=0;r<rows;r++){ for(c=0;c<cols;c++,pos++){ if(edge[pos] == POSSIBLE_EDGE) hist[mag[pos]]++; } } /**************************************************************************** * Compute the number of pixels that passed the nonmaximal suppression. ****************************************************************************/ for(r=1,numedges=0;r<32768;r++){ if(hist[r] != 0) maximum_mag = r; numedges += hist[r]; } highcount = (int)(numedges * thigh + 0.5); /**************************************************************************** * Compute the high threshold value as the (100 * thigh) percentage point * in the magnitude of the gradient histogram of all the pixels that passes * non-maximal suppression. Then calculate the low threshold as a fraction * of the computed high threshold value. John Canny said in his paper * "A Computational Approach to Edge Detection" that "The ratio of the * high to low threshold in the implementation is in the range two or three * to one." That means that in terms of this implementation, we should * choose tlow ~= 0.5 or 0.33333. ****************************************************************************/ printf("Computing the high and low thresholds.\n"); r = 1; numedges = hist[1]; while((r<(maximum_mag-1)) && (numedges < highcount)){ r++; numedges += hist[r]; } highthreshold = r; lowthreshold = (int)(highthreshold * tlow + 0.5); if(VERBOSE){ printf("The input low and high fractions of %f and %f computed to\n", tlow, thigh); printf("magnitude of the gradient threshold values of: %d %d\n", lowthreshold, highthreshold); } /**************************************************************************** * This loop looks for pixels above the highthreshold to locate edges and * then calls follow_edges to continue the edge. ****************************************************************************/ printf("Doing the thresholding with the recursive function calls.\n"); for(r=0,pos=0;r<rows;r++){ for(c=0;c<cols;c++,pos++){ if((edge[pos] == POSSIBLE_EDGE) && (mag[pos] >= highthreshold)){ edge[pos] = EDGE; follow_edges((edge+pos), (mag+pos), lowthreshold, cols); } } } /**************************************************************************** * Set all the remaining possible edges to non-edges. ****************************************************************************/ printf("Setting all other pixels to non-edges.\n"); for(r=0,pos=0;r<rows;r++){ for(c=0;c<cols;c++,pos++) if(edge[pos] != EDGE) edge[pos] = NOEDGE; } } /******************************************************************************* * PROCEDURE: non_max_supp * PURPOSE: This routine applies non-maximal suppression to the magnitude of * the gradient image. * NAME: Mike Heath * DATE: 2/15/96 *******************************************************************************/ non_max_supp(short *mag, short *gradx, short *grady, int nrows, int ncols, unsigned char *result) { int rowcount, colcount,count; short *magrowptr,*magptr; short *gxrowptr,*gxptr; short *gyrowptr,*gyptr,z1,z2; short m00,gx,gy; float mag1,mag2,xperp,yperp; unsigned char *resultrowptr, *resultptr; /**************************************************************************** * Zero the edges of the result image. ****************************************************************************/ for(count=0,resultrowptr=result,resultptr=result+ncols*(nrows-1); count<ncols; resultptr++,resultrowptr++,count++){ *resultrowptr = *resultptr = (unsigned char) 0; } for(count=0,resultptr=result,resultrowptr=result+ncols-1; count<nrows; count++,resultptr+=ncols,resultrowptr+=ncols){ *resultptr = *resultrowptr = (unsigned char) 0; } /**************************************************************************** * Suppress non-maximum points. ****************************************************************************/ for(rowcount=1,magrowptr=mag+ncols+1,gxrowptr=gradx+ncols+1, gyrowptr=grady+ncols+1,resultrowptr=result+ncols+1; rowcount<nrows-2; rowcount++,magrowptr+=ncols,gyrowptr+=ncols,gxrowptr+=ncols, resultrowptr+=ncols){ for(colcount=1,magptr=magrowptr,gxptr=gxrowptr,gyptr=gyrowptr, resultptr=resultrowptr;colcount<ncols-2; colcount++,magptr++,gxptr++,gyptr++,resultptr++){ m00 = *magptr; if(m00 == 0){ *resultptr = (unsigned char) NOEDGE; } else{ xperp = -(gx = *gxptr)/((float)m00); yperp = (gy = *gyptr)/((float)m00); } if(gx >= 0){ if(gy >= 0){ if (gx >= gy) { /* 111 */ /* Left point */ z1 = *(magptr - 1); z2 = *(magptr - ncols - 1); mag1 = (m00 - z1)*xperp + (z2 - z1)*yperp; /* Right point */ z1 = *(magptr + 1); z2 = *(magptr + ncols + 1); mag2 = (m00 - z1)*xperp + (z2 - z1)*yperp; } else { /* 110 */ /* Left point */ z1 = *(magptr - ncols); z2 = *(magptr - ncols - 1); mag1 = (z1 - z2)*xperp + (z1 - m00)*yperp; /* Right point */ z1 = *(magptr + ncols); z2 = *(magptr + ncols + 1); mag2 = (z1 - z2)*xperp + (z1 - m00)*yperp; } } else { if (gx >= -gy) { /* 101 */ /* Left point */ z1 = *(magptr - 1); z2 = *(magptr + ncols - 1); mag1 = (m00 - z1)*xperp + (z1 - z2)*yperp; /* Right point */ z1 = *(magptr + 1); z2 = *(magptr - ncols + 1); mag2 = (m00 - z1)*xperp + (z1 - z2)*yperp; } else { /* 100 */ /* Left point */ z1 = *(magptr + ncols); z2 = *(magptr + ncols - 1); mag1 = (z1 - z2)*xperp + (m00 - z1)*yperp; /* Right point */ z1 = *(magptr - ncols); z2 = *(magptr - ncols + 1); mag2 = (z1 - z2)*xperp + (m00 - z1)*yperp; } } } else { if ((gy = *gyptr) >= 0) { if (-gx >= gy) { /* 011 */ /* Left point */ z1 = *(magptr + 1); z2 = *(magptr - ncols + 1); mag1 = (z1 - m00)*xperp + (z2 - z1)*yperp; /* Right point */ z1 = *(magptr - 1); z2 = *(magptr + ncols - 1); mag2 = (z1 - m00)*xperp + (z2 - z1)*yperp; } else { /* 010 */ /* Left point */ z1 = *(magptr - ncols); z2 = *(magptr - ncols + 1); mag1 = (z2 - z1)*xperp + (z1 - m00)*yperp; /* Right point */ z1 = *(magptr + ncols); z2 = *(magptr + ncols - 1); mag2 = (z2 - z1)*xperp + (z1 - m00)*yperp; } } else { if (-gx > -gy) { /* 001 */ /* Left point */ z1 = *(magptr + 1); z2 = *(magptr + ncols + 1); mag1 = (z1 - m00)*xperp + (z1 - z2)*yperp; /* Right point */ z1 = *(magptr - 1); z2 = *(magptr - ncols - 1); mag2 = (z1 - m00)*xperp + (z1 - z2)*yperp; } else { /* 000 */ /* Left point */ z1 = *(magptr + ncols); z2 = *(magptr + ncols + 1); mag1 = (z2 - z1)*xperp + (m00 - z1)*yperp; /* Right point */ z1 = *(magptr - ncols); z2 = *(magptr - ncols - 1); mag2 = (z2 - z1)*xperp + (m00 - z1)*yperp; } } } /* Now determine if the current point is a maximum point */ if ((mag1 > 0.0) || (mag2 > 0.0)) { *resultptr = (unsigned char) NOEDGE; } else { if (mag2 == 0.0) *resultptr = (unsigned char) NOEDGE; else *resultptr = (unsigned char) POSSIBLE_EDGE; } } } }
the_stack_data/113452.c
/* * Copyright (c) 2008-2010 Sander van der Burg * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <string.h> #include <fcntl.h> #include <netdb.h> #include <errno.h> #include <signal.h> #include <sys/types.h> #include <sys/socket.h> #include <sys/un.h> #include <sys/time.h> #include <sys/wait.h> #include <sys/stat.h> #include <arpa/inet.h> #define BUFFER_SIZE 4096 #define TRUE 1 #define FALSE 0 int num_of_connections = 0; static void print_usage(void) { printf("Usage:\n"); printf("disnix-proxy source_port destination_hostname destination_port lock_filename\n"); } static void set_nonblock(int sockfd) { int fl; /* Get the file status flags */ if((fl = fcntl(sockfd, F_GETFL, 0)) < 0) { fprintf(stderr, "Error getting filestatus flags: %s\n", strerror(errno)); _exit(1); } /* Set the file status flags on non-blocking */ if(fcntl(sockfd, F_SETFL, fl | O_NONBLOCK) < 0) { fprintf(stderr, "Error setting filestatus flags: %s\n", strerror(errno)); _exit(1); } } static int create_server_socket(int source_port) { int sockfd, on = 1; struct sockaddr_in client_addr; /* Create socket */ sockfd = socket(AF_INET, SOCK_STREAM, 0); if(sockfd < 0) fprintf(stderr, "Error creating server socket\n"); /* Create address struct */ memset(&client_addr, '\0', sizeof(client_addr)); client_addr.sin_family = AF_INET; client_addr.sin_addr.s_addr = htonl(INADDR_ANY); client_addr.sin_port = htons(source_port); /* Set socket options to reuse the address */ setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, 4); /* Bind the name (ip address) to the socket */ if(bind(sockfd, (struct sockaddr *)&client_addr, sizeof(client_addr)) < 0) fprintf(stderr, "Error binding to port: %d, %s\n", source_port, strerror(errno)); /* Listen for connections on the socket */ if(listen(sockfd, 5) < 0) fprintf(stderr, "Error listening on port: %d\n", source_port); /* Return the socket filedescriptor */ return sockfd; } static int create_admin_socket(char *socket_path) { int sockfd; struct sockaddr_un client_addr; /* Create socket */ sockfd = socket(AF_UNIX, SOCK_STREAM, 0); if(sockfd < 0) fprintf(stderr, "Error creating admin socket\n"); /* Create address struct */ memset(&client_addr, '\0', sizeof(client_addr)); client_addr.sun_family = AF_UNIX; strcpy(client_addr.sun_path, socket_path); /* Bind the name (ip address) to the socket */ unlink(socket_path); if(bind(sockfd, (struct sockaddr *)&client_addr, sizeof(client_addr)) < 0) fprintf(stderr, "Error binding: %s: %s\n", socket_path, strerror(errno)); /* Listen for connections on the socket */ if(listen(sockfd, 5) < 0) fprintf(stderr, "Error listening on %s\n", socket_path); /* Return the socket filedescriptor */ return sockfd; } static int wait_for_connection(int server_sockfd) { int client_sockfd, len; struct sockaddr_in peer; /* Accept client connection and create client socket */ len = sizeof(struct sockaddr); if((client_sockfd = accept(server_sockfd, (struct sockaddr *)&peer, &len)) < 0) { if(errno == EAGAIN || errno == EWOULDBLOCK) return -1; /* Stop annoying messages */ else if(errno != EINTR) { fprintf(stderr, "Error creating client socket: %s\n", strerror(errno)); return -1; } } /* Set socket on non blocking mode */ set_nonblock(client_sockfd); /* Return the socket filedescriptor */ return client_sockfd; } static int open_remote_host(char *host, int port) { struct hostent *hostinfo; int target_sockfd; int on = 1; struct sockaddr_in target_addr; /* Get hostname */ if(!(hostinfo = gethostbyname(host))) return -2; /* Create socket to target remote host */ if((target_sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) return target_sockfd; /* Set socket options to reuse the address */ setsockopt(target_sockfd, SOL_SOCKET, SO_REUSEADDR, &on, 4); /* Create the address struct */ memset(&target_addr, '\0', sizeof(target_addr)); target_addr.sin_family = AF_INET; memcpy(&target_addr.sin_addr, hostinfo->h_addr, hostinfo->h_length); target_addr.sin_port = htons(port); /* Connect to the remote host */ if(connect(target_sockfd, (struct sockaddr *)&target_addr, sizeof(target_addr)) < 0) { close(target_sockfd); return -1; } /* Set socket on non blocking mode */ set_nonblock(target_sockfd); /* Return the socket filedescriptor */ return target_sockfd; } static int mywrite(int fd, char *buf, int *len) { /* Write the bytes to the file descriptor */ int num_of_written_bytes = write(fd, buf, *len); /* If no bytes are written or an error occurs, return the result */ if(num_of_written_bytes <= 0) return num_of_written_bytes; /* If not all bytes are written, create a new buffer with the unwritten bytes */ if(num_of_written_bytes != *len) memmove(buf, buf+num_of_written_bytes, (*len)-num_of_written_bytes); /* Decrease the length with number of written bytes (should be 0 if all bytes are written) */ *len -= num_of_written_bytes; /* Return number of written bytes */ return num_of_written_bytes; } static void do_proxy(int client_sockfd, int target_sockfd) { int maxfd; char *client_buffer, *target_buffer; int client_buffer_offset = 0, target_buffer_offset = 0; int num_of_fds, n; fd_set fds; /* Get memory for buffers */ client_buffer = (char*)malloc(BUFFER_SIZE); target_buffer = (char*)malloc(BUFFER_SIZE); /* Get highest filedescriptor value */ maxfd = client_sockfd > target_sockfd ? client_sockfd : target_sockfd; maxfd++; /* Keep sending all incoming data from client to target */ while(TRUE) { struct timeval to; /* Write everything in the client buffer to the target socket */ if(client_buffer_offset > 0) { if(mywrite(target_sockfd, client_buffer, &client_buffer_offset) < 0 && errno != EWOULDBLOCK) { fprintf(stderr, "Error writing to target socket: %s\n", strerror(errno)); _exit(1); } } /* Write everything in the target buffer to the client socket */ if(target_buffer_offset > 0) { if(mywrite(client_sockfd, target_buffer, &target_buffer_offset) < 0 && errno != EWOULDBLOCK) { fprintf(stderr, "Error writing to client socket: %s\n", strerror(errno)); _exit(1); } } /* Clear the filedescriptor set */ FD_ZERO(&fds); /* Add buffers to filedescriptor set if they are not full yet */ if(client_buffer_offset < BUFFER_SIZE) FD_SET(client_sockfd, &fds); if(target_buffer_offset < BUFFER_SIZE) FD_SET(target_sockfd, &fds); /* Set the monitor timeout */ to.tv_sec = 0; to.tv_usec = 1000; /* Monitor the filedescriptors in the set */ num_of_fds = select(maxfd+1, &fds, 0, 0, &to); if(num_of_fds > 0) { if(FD_ISSET(client_sockfd, &fds)) { /* Read bytes from client socket */ n = read(client_sockfd, client_buffer+client_buffer_offset, BUFFER_SIZE - client_buffer_offset); if(n > 0) client_buffer_offset += n; else { close(client_sockfd); close(target_sockfd); _exit(0); } } if(FD_ISSET(target_sockfd, &fds)) { /* Read bytes from target socket */ n = read(target_sockfd, target_buffer+target_buffer_offset, BUFFER_SIZE - target_buffer_offset); if(n > 0) target_buffer_offset += n; else { close(target_sockfd); close(client_sockfd); _exit(0); } } } else if(num_of_fds < 0 && errno != EINTR) { fprintf(stderr, "Error with select: %s\n", strerror(errno)); close(target_sockfd); close(client_sockfd); } } } static int is_blocking(char *lock_filename) { int fd = open(lock_filename, O_RDONLY); if(fd == -1) return FALSE; else { close(fd); return TRUE; } } void cleanup(int signal) { printf("Cleaning up...\n"); _exit(0); } void sigreap(int sig) { pid_t pid; int status; num_of_connections--; signal(SIGCHLD, sigreap); /* Event handler when a child terminates */ while((pid = waitpid(-1, &status, WNOHANG)) > 0); /* Wait until all child processes terminate */ } int main(int argc, char *argv[]) { int source_port; char *destination_address; int destination_port; int server_sockfd = -1, client_sockfd = -1, target_sockfd = -1, admin_sockfd = -1, admin_client_sockfd = -1; char *lock_filename; /* Check parameters */ if(argc != 5) { print_usage(); _exit(1); } /* Get parameter values */ source_port = atoi(argv[1]); destination_address = strdup(argv[2]); destination_port = atoi(argv[3]); lock_filename = strdup(argv[4]); /* Create signal handlers */ signal(SIGINT, cleanup); /* Event handler for interruption */ signal(SIGCHLD, sigreap); /* Event handler when a child terminates */ /* Create server socket */ server_sockfd = create_server_socket(source_port); set_nonblock(server_sockfd); /* Create admin socket */ admin_sockfd = create_admin_socket("/tmp/disnix-tcp-proxy.sock"); set_nonblock(admin_sockfd); /* Main loop */ while(TRUE) { int status; /* Create admin client socket if there is an incoming connection */ if((admin_client_sockfd = wait_for_connection(admin_sockfd)) >= 0) { char msg[BUFFER_SIZE]; printf("Admin connection from client\n"); sprintf(msg, "%d", num_of_connections); if(send(admin_client_sockfd, msg, strlen(msg), 0) < 0) fprintf(stderr, "Error sending message to admin client: %s\n", strerror(errno)); close(admin_client_sockfd); admin_client_sockfd = -1; } /* If we want to block do not accept any incoming client connections */ if(is_blocking(lock_filename)) continue; /* Create client if there is an incoming connection */ if((client_sockfd = wait_for_connection(server_sockfd)) < 0) continue; /* Connect to the remote host */ if((target_sockfd = open_remote_host(destination_address, destination_port)) < 0) { close(client_sockfd); client_sockfd = -1; continue; } /* Fork a new process for each incoming client */ status = fork(); if(status == 0) { printf("Connection from client\n"); close(server_sockfd); close(admin_sockfd); do_proxy(client_sockfd, target_sockfd); abort(); } else if(status == -1) fprintf(stderr, "Error in forking process\n"); else num_of_connections++; /* Close the connections to the remote host and client */ close(client_sockfd); client_sockfd = -1; close(target_sockfd); target_sockfd = -1; } return 0; }
the_stack_data/134314.c
// KASAN: use-after-free Read in _copy_from_iter // https://syzkaller.appspot.com/bug?id=b830ba394114596a75b51add2ec8f1f040639903 // status:fixed // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include <endian.h> #include <linux/futex.h> #include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <sys/syscall.h> #include <unistd.h> __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #include <errno.h> #include <stdarg.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> const int kFailStatus = 67; const int kRetryStatus = 69; static void fail(const char* msg, ...) { int e = errno; va_list args; va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); fprintf(stderr, " (errno %d)\n", e); doexit((e == ENOMEM || e == EAGAIN) ? kRetryStatus : kFailStatus); } static void use_temporary_dir() { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) fail("failed to mkdtemp"); if (chmod(tmpdir, 0777)) fail("failed to chmod"); if (chdir(tmpdir)) fail("failed to chdir"); } struct thread_t { int created, running, call; pthread_t th; }; 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 (;;) { while (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &th->running, FUTEX_WAIT, 0, 0); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 0, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); } return 0; } static void execute(int num_calls) { int call, thread; running = 0; for (call = 0; call < num_calls; call++) { for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); pthread_create(&th->th, &attr, thr, th); } if (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) { th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 20 * 1000 * 1000; syscall(SYS_futex, &th->running, FUTEX_WAIT, 1, &ts); if (__atomic_load_n(&running, __ATOMIC_RELAXED)) usleep((call == num_calls - 1) ? 10000 : 1000); break; } } } } uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: memcpy((void*)0x20000100, "./file0", 8); syscall(__NR_mknod, 0x20000100, 0, 0); break; case 1: res = syscall(__NR_pipe, 0x20000080); if (res != -1) { r[0] = *(uint32_t*)0x20000080; r[1] = *(uint32_t*)0x20000084; } break; case 2: syscall(__NR_write, r[1], 0x200001c0, 0xfffffef3); break; case 3: memcpy((void*)0x20000300, "./file0", 8); memcpy((void*)0x20000340, "9p", 3); memcpy((void*)0x20000380, "trans=fd,", 9); memcpy((void*)0x20000389, "rfdno", 5); *(uint8_t*)0x2000038e = 0x3d; sprintf((char*)0x2000038f, "0x%016llx", (long long)r[0]); *(uint8_t*)0x200003a1 = 0x2c; memcpy((void*)0x200003a2, "wfdno", 5); *(uint8_t*)0x200003a7 = 0x3d; sprintf((char*)0x200003a8, "0x%016llx", (long long)r[1]); *(uint8_t*)0x200003ba = 0x2c; *(uint8_t*)0x200003bb = 0; syscall(__NR_mount, 0, 0x20000300, 0x20000340, 0, 0x20000380); break; case 4: syscall(__NR_read, r[0], 0x20000200, 0x50c7e3e3); break; } } void loop() { execute(5); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); use_temporary_dir(); loop(); return 0; }
the_stack_data/374146.c
#include <math.h> float bessi1(float x) { float ax,ans; double y; if ((ax=fabs(x)) < 3.75) { y=x/3.75; y*=y; ans=ax*(0.5+y*(0.87890594+y*(0.51498869+y*(0.15084934 +y*(0.2658733e-1+y*(0.301532e-2+y*0.32411e-3)))))); } else { y=3.75/ax; ans=0.2282967e-1+y*(-0.2895312e-1+y*(0.1787654e-1 -y*0.420059e-2)); ans=0.39894228+y*(-0.3988024e-1+y*(-0.362018e-2 +y*(0.163801e-2+y*(-0.1031555e-1+y*ans)))); ans *= (exp(ax)/sqrt(ax)); } return x < 0.0 ? -ans : ans; }
the_stack_data/72829.c
#include<stdio.h> int main() { int k=-1; switch(k) { case 1: puts("Too small~"); break; case 2: puts("Just so so~"); break; case 3: puts("It is ok~"); break; default: puts("I am default~"); break; } return 0; }
the_stack_data/1085138.c
/* * Copyright (c) 2020 roleo. * * 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, version 3. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * Dump h264 content from /dev/shm/fshare_frame_buffer to stdout */ #define _GNU_SOURCE #include <string.h> #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <sys/types.h> #include <time.h> #include <unistd.h> #include <sys/mman.h> #include <getopt.h> #define Y21GA 0 #define R30GB 1 #define BUF_OFFSET_Y21GA 368 #define BUF_SIZE_Y21GA 1786224 #define FRAME_HEADER_SIZE_Y21GA 28 #define DATA_OFFSET_Y21GA 4 #define BUF_OFFSET_R30GB 300 #define BUF_SIZE_R30GB 1786156 #define FRAME_HEADER_SIZE_R30GB 22 #define DATA_OFFSET_R30GB 0 #define USLEEP 100000 #define RESOLUTION_LOW 360 #define RESOLUTION_HIGH 1080 #define BUFFER_FILE "/dev/shm/fshare_frame_buf" int buf_offset; int buf_size; int frame_header_size; int data_offset; unsigned char IDR[] = {0x65, 0xB8}; unsigned char NAL_START[] = {0x00, 0x00, 0x00, 0x01}; unsigned char IDR_START[] = {0x00, 0x00, 0x00, 0x01, 0x65, 0x88}; unsigned char PFR_START[] = {0x00, 0x00, 0x00, 0x01, 0x41}; unsigned char SPS_START[] = {0x00, 0x00, 0x00, 0x01, 0x67}; unsigned char PPS_START[] = {0x00, 0x00, 0x00, 0x01, 0x68}; unsigned char SPS_640X360[] = {0x00, 0x00, 0x00, 0x01, 0x67, 0x4D, 0x00, 0x14, 0x96, 0x54, 0x05, 0x01, 0x7B, 0xCB, 0x37, 0x01, 0x01, 0x01, 0x02}; unsigned char SPS_1920X1080[] = {0x00, 0x00, 0x00, 0x01, 0x67, 0x4D, 0x00, 0x20, 0x96, 0x54, 0x03, 0xC0, 0x11, 0x2F, 0x2C, 0xDC, 0x04, 0x04, 0x04, 0x08}; unsigned char *addr; /* Pointer to shared memory region (header) */ int debug = 0; /* Set to 1 to debug this .c */ int resolution; /* Locate a string in the circular buffer */ unsigned char * cb_memmem(unsigned char *src, int src_len, unsigned char *what, int what_len) { unsigned char *p; unsigned char *buffer = addr + buf_offset; int buffer_size = buf_size; if (src_len >= 0) { p = (unsigned char*) memmem(src, src_len, what, what_len); } else { // From src to the end of the buffer p = (unsigned char*) memmem(src, buffer + buffer_size - src, what, what_len); if (p == NULL) { // And from the start of the buffer size src_len p = (unsigned char*) memmem(buffer, src + src_len - buffer, what, what_len); } } return p; } unsigned char * cb_move(unsigned char *buf, int offset) { buf += offset; if ((offset > 0) && (buf > addr + buf_size)) buf -= (buf_size - buf_offset); if ((offset < 0) && (buf < addr + buf_offset)) buf += (buf_size - buf_offset); return buf; } // The second argument is the circular buffer int cb_memcmp(unsigned char *str1, unsigned char *str2, size_t n) { int ret; if (str2 + n > addr + buf_size) { ret = memcmp(str1, str2, addr + buf_size - str2); if (ret != 0) return ret; ret = memcmp(str1 + (addr + buf_size - str2), addr + buf_offset, n - (addr + buf_size - str2)); } else { ret = memcmp(str1, str2, n); } return ret; } // The second argument is the circular buffer void cb_memcpy(unsigned char *dest, unsigned char *src, size_t n) { if (src + n > addr + buf_size) { memcpy(dest, src, addr + buf_size - src); memcpy(dest + (addr + buf_size - src), addr + buf_offset, n - (addr + buf_size - src)); } else { memcpy(dest, src, n); } } void print_usage(char *progname) { fprintf(stderr, "\nUsage: %s [-r RES] [-d]\n\n", progname); fprintf(stderr, "\t-m MODEL, --model MODEL\n"); fprintf(stderr, "\t\tset model: y21ga or r30gb (default y21ga)\n"); fprintf(stderr, "\t-r RES, --resolution RES\n"); fprintf(stderr, "\t\tset resolution: LOW or HIGH (default HIGH)\n"); fprintf(stderr, "\t-d, --debug\n"); fprintf(stderr, "\t\tenable debug\n"); } int main(int argc, char **argv) { unsigned char *buf_idx_1, *buf_idx_2; unsigned char *buf_idx_w, *buf_idx_tmp; unsigned char *buf_idx_start, *buf_idx_end; unsigned char *sps_addr; int sps_len; FILE *fFid; int frame_res, frame_len, frame_counter, frame_counter_prev = -1; int i, c; int write_enable = 0; int sync_lost = 1; time_t ta, tb; resolution = RESOLUTION_HIGH; debug = 0; buf_offset = BUF_OFFSET_Y21GA; buf_size = BUF_SIZE_Y21GA; frame_header_size = FRAME_HEADER_SIZE_Y21GA; data_offset = DATA_OFFSET_Y21GA; while (1) { static struct option long_options[] = { {"model", required_argument, 0, 'm'}, {"resolution", required_argument, 0, 'r'}, {"debug", no_argument, 0, 'd'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; c = getopt_long (argc, argv, "m:r:dh", long_options, &option_index); /* Detect the end of the options. */ if (c == -1) break; switch (c) { case 'm': if (strcasecmp("y21ga", optarg) == 0) { buf_offset = BUF_OFFSET_Y21GA; buf_size = BUF_SIZE_Y21GA; frame_header_size = FRAME_HEADER_SIZE_Y21GA; data_offset = DATA_OFFSET_Y21GA; } else if (strcasecmp("r30gb", optarg) == 0) { buf_offset = BUF_OFFSET_R30GB; buf_size = BUF_SIZE_R30GB; frame_header_size = FRAME_HEADER_SIZE_R30GB; data_offset = DATA_OFFSET_R30GB; } break; case 'r': if (strcasecmp("low", optarg) == 0) { resolution = RESOLUTION_LOW; } else if (strcasecmp("high", optarg) == 0) { resolution = RESOLUTION_HIGH; } break; case 'd': fprintf (stderr, "debug on\n"); debug = 1; break; case 'h': print_usage(argv[0]); return -1; break; case '?': /* getopt_long already printed an error message. */ break; default: print_usage(argv[0]); return -1; } } if (resolution == RESOLUTION_LOW) { sps_addr = SPS_640X360; sps_len = sizeof(SPS_640X360); } else if (resolution == RESOLUTION_HIGH) { sps_addr = SPS_1920X1080; sps_len = sizeof(SPS_1920X1080); } // Opening an existing file fFid = fopen(BUFFER_FILE, "r") ; if ( fFid == NULL ) { if (debug) fprintf(stderr, "could not open file %s\n", BUFFER_FILE) ; return -1; } // Map file to memory addr = (unsigned char*) mmap(NULL, buf_size, PROT_READ, MAP_SHARED, fileno(fFid), 0); if (addr == MAP_FAILED) { if (debug) fprintf(stderr, "error mapping file %s\n", BUFFER_FILE); return -2; } if (debug) fprintf(stderr, "mapping file %s, size %d, to %08x\n", BUFFER_FILE, buf_size, (unsigned int) addr); // Closing the file if (debug) fprintf(stderr, "closing the file %s\n", BUFFER_FILE) ; fclose(fFid) ; memcpy(&i, addr + 16, sizeof(i)); buf_idx_w = addr + buf_offset + i; buf_idx_1 = buf_idx_w; // Infinite loop while (1) { memcpy(&i, addr + 16, sizeof(i)); buf_idx_w = addr + buf_offset + i; // if (debug) fprintf(stderr, "buf_idx_w: %08x\n", (unsigned int) buf_idx_w); buf_idx_tmp = cb_memmem(buf_idx_1, buf_idx_w - buf_idx_1, NAL_START, sizeof(NAL_START)); if (buf_idx_tmp == NULL) { usleep(USLEEP); continue; } else { buf_idx_1 = buf_idx_tmp; } // if (debug) fprintf(stderr, "found buf_idx_1: %08x\n", (unsigned int) buf_idx_1); buf_idx_tmp = cb_memmem(buf_idx_1 + 1, buf_idx_w - (buf_idx_1 + 1), NAL_START, sizeof(NAL_START)); if (buf_idx_tmp == NULL) { usleep(USLEEP); continue; } else { buf_idx_2 = buf_idx_tmp; } // if (debug) fprintf(stderr, "found buf_idx_2: %08x\n", (unsigned int) buf_idx_2); if ((write_enable) && (!sync_lost)) { tb = time(NULL); if (buf_idx_start + frame_len > addr + buf_size) { fwrite(buf_idx_start, 1, addr + buf_size - buf_idx_start, stdout); fwrite(addr + buf_offset, 1, frame_len - (addr + buf_size - buf_idx_start), stdout); } else { fwrite(buf_idx_start, 1, frame_len, stdout); } ta = time(NULL); if ((frame_counter - frame_counter_prev != 1) && (frame_counter_prev != -1)) { fprintf(stderr, "frames lost: %d\n", frame_counter - frame_counter_prev); } if (ta - tb > 3) { sync_lost = 1; fprintf(stderr, "sync lost\n"); sleep(3); } frame_counter_prev = frame_counter; } if (cb_memcmp(sps_addr, buf_idx_1, sps_len) == 0) { // SPS frame write_enable = 1; sync_lost = 0; buf_idx_1 = cb_move(buf_idx_1, - (6 + frame_header_size)); if (buf_idx_1[17 + data_offset] == 8) { frame_res = RESOLUTION_LOW; } else if (buf_idx_1[17 + data_offset] == 4) { frame_res = RESOLUTION_HIGH; } else { write_enable = 0; } if (frame_res == resolution) { cb_memcpy((unsigned char *) &frame_len, buf_idx_1, 4); frame_len -= 6; // -6 only for SPS frame_counter = (int) buf_idx_1[18 + data_offset] + (int) buf_idx_1[19 + data_offset] *256; buf_idx_1 = cb_move(buf_idx_1, 6 + frame_header_size); buf_idx_start = buf_idx_1; if (debug) fprintf(stderr, "SPS detected - frame_res: %d - frame_len: %d - frame_counter: %d\n", frame_res, frame_len, frame_counter); } else { write_enable = 0; } } else if ((cb_memcmp(PPS_START, buf_idx_1, sizeof(PPS_START)) == 0) || (cb_memcmp(IDR_START, buf_idx_1, sizeof(IDR_START)) == 0) || (cb_memcmp(PFR_START, buf_idx_1, sizeof(PFR_START)) == 0)) { // PPS, IDR and PFR frames write_enable = 1; buf_idx_1 = cb_move(buf_idx_1, -frame_header_size); if (buf_idx_1[17 + data_offset] == 8) { frame_res = RESOLUTION_LOW; } else if (buf_idx_1[17 + data_offset] == 4) { frame_res = RESOLUTION_HIGH; } else { write_enable = 0; } if (frame_res == resolution) { cb_memcpy((unsigned char *) &frame_len, buf_idx_1, 4); frame_counter = (int) buf_idx_1[18 + data_offset] + (int) buf_idx_1[19 + data_offset] *256; buf_idx_1 = cb_move(buf_idx_1, frame_header_size); buf_idx_start = buf_idx_1; if (debug) fprintf(stderr, "frame detected - frame_res: %d - frame_len: %d - frame_counter: %d\n", frame_res, frame_len, frame_counter); } else { write_enable = 0; } } else { write_enable = 0; } buf_idx_1 = buf_idx_2; } // Unreacheable path // Unmap file from memory if (munmap(addr, buf_size) == -1) { if (debug) fprintf(stderr, "error munmapping file"); } else { if (debug) fprintf(stderr, "unmapping file %s, size %d, from %08x\n", BUFFER_FILE, buf_size, addr); } return 0; }
the_stack_data/176704899.c
// PARAM: --sets ana.activated[+] thread --sets ana.path_sens[+] threadflag --sets ana.path_sens[+] thread #include <pthread.h> #include <stdio.h> int myglobal; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; void *t_fun(void *arg) { pthread_mutex_lock(&mutex); myglobal=myglobal+1; // NORACE pthread_mutex_unlock(&mutex); return NULL; } int main(void) { int x1; pthread_t id1; if (x1) pthread_create(&id1, NULL, t_fun, NULL); pthread_mutex_lock(&mutex); myglobal=myglobal+1; // NORACE pthread_mutex_unlock(&mutex); int x2; pthread_t id2; if (x2) pthread_create(&id2, NULL, t_fun, NULL); pthread_mutex_lock(&mutex); myglobal=myglobal+1; // NORACE pthread_mutex_unlock(&mutex); if (x1) pthread_join (id1, NULL); pthread_mutex_lock(&mutex); myglobal=myglobal+1; // NORACE pthread_mutex_unlock(&mutex); if (x2) pthread_join (id2, NULL); myglobal=myglobal+1; // NORACE return 0; }
the_stack_data/36076091.c
/*====================================================================* * * sv_html[] - * *. Motley Tools by Charles Maier *: Published 1982-2005 by Charles Maier for personal use *; Licensed under the Internet Software Consortium License * *--------------------------------------------------------------------*/ #include <stddef.h> #define HTML_O_A 0 #define HTML_O_ABBR 1 #define HTML_O_ACRONYM 2 #define HTML_O_ADDRESS 3 #define HTML_O_APPLET 4 #define HTML_O_AREA 5 #define HTML_O_B 6 #define HTML_O_BASE 7 #define HTML_O_BASEFONT 8 #define HTML_O_BDO 9 #define HTML_O_BGSOUND 10 #define HTML_O_BIG 11 #define HTML_O_BLOCKQUOTE 12 #define HTML_O_BODY 13 #define HTML_O_BR 14 #define HTML_O_BUTTON 15 #define HTML_O_CAPTION 16 #define HTML_O_CENTER 17 #define HTML_O_CITE 18 #define HTML_O_CODE 19 #define HTML_O_COL 20 #define HTML_O_COLGROUP 21 #define HTML_O_DD 22 #define HTML_O_DEL 23 #define HTML_O_DFN 24 #define HTML_O_DIR 25 #define HTML_O_DIV 26 #define HTML_O_DL 27 #define HTML_O_DT 28 #define HTML_O_EM 29 #define HTML_O_EMBED 30 #define HTML_O_FIELDSET 31 #define HTML_O_FONT 32 #define HTML_O_FORM 33 #define HTML_O_FRAME 34 #define HTML_O_FRAMESET 35 #define HTML_O_H1 36 #define HTML_O_H2 37 #define HTML_O_H3 38 #define HTML_O_H4 39 #define HTML_O_H5 40 #define HTML_O_H6 41 #define HTML_O_HEAD 42 #define HTML_O_HR 43 #define HTML_O_HTML 44 #define HTML_O_I 45 #define HTML_O_IFRAME 46 #define HTML_O_IMG 47 #define HTML_O_INPUT 48 #define HTML_O_INS 49 #define HTML_O_ISINDEX 50 #define HTML_O_KBD 51 #define HTML_O_LABEL 52 #define HTML_O_LI 53 #define HTML_O_LINK 54 #define HTML_O_LISTING 55 #define HTML_O_MAP 56 #define HTML_O_MARQUEE 57 #define HTML_O_MENU 58 #define HTML_O_META 59 #define HTML_O_NOFRAMES 60 #define HTML_O_NOSCRIPT 61 #define HTML_O_OBJECT 62 #define HTML_O_OL 63 #define HTML_O_OPTGROUP 64 #define HTML_O_OPTION 65 #define HTML_O_P 66 #define HTML_O_PARAM 67 #define HTML_O_PLAINTEXT 68 #define HTML_O_PRE 69 #define HTML_O_Q 70 #define HTML_O_S 71 #define HTML_O_SAMP 72 #define HTML_O_SCRIPT 73 #define HTML_O_SELECT 74 #define HTML_O_SMALL 75 #define HTML_O_SPAN 76 #define HTML_O_STRIKE 77 #define HTML_O_STRONG 78 #define HTML_O_STYLE 79 #define HTML_O_SUB 80 #define HTML_O_SUP 81 #define HTML_O_TABLE 82 #define HTML_O_TBODY 83 #define HTML_O_TD 84 #define HTML_O_TEXTAREA 85 #define HTML_O_TFOOT 86 #define HTML_O_TH 87 #define HTML_O_THEAD 88 #define HTML_O_TITLE 89 #define HTML_O_TR 90 #define HTML_O_TT 91 #define HTML_O_U 92 #define HTML_O_UL 93 #define HTML_O_VAR 94 #define HTML_O_WBR 95 #define HTML_O_XML 96 #define HTML_O_XMP 97 #define HTML_O_NULL 98 char const *sv_html [] = { "a", "abbr", "acronym", "address", "applet", "area", "b", "base", "basefont", "bdo", "bgsound", "big", "blockquote", "body", "br", "button", "caption", "center", "cite", "code", "col", "colgroup", "dd", "del", "dfn", "dir", "div", "dl", "dt", "em", "embed", "fieldset", "font", "form", "frame", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "hr", "html", "i", "iframe", "img", "input", "ins", "isindex", "kbd", "label", "li", "link", "listing", "map", "marquee", "menu", "meta", "noframes", "noscript", "object", "ol", "optgroup", "option", "p", "param", "plaintext", "pre", "q", "s", "samp", "script", "select", "small", "span", "strike", "strong", "style", "sub", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "title", "tr", "tt", "u", "ul", "var", "wbr", "xml", "xmp", NULL };
the_stack_data/139201712.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #define BUFFER_SIZE 1024 int main(int argc, char *argv[]) { if (argc!=5) { perror("Argument count is wrong"); exit(-1); } int argv1_notempty = strcmp(argv[1], "")!=0; int argv2_notempty = strcmp(argv[2], "")!=0; int argv3_notempty = strcmp(argv[3], "")!=0; int argv4_notempty = strcmp(argv[4], "")!=0; int checkfornotempty134 = argv1_notempty && argv3_notempty && argv4_notempty; if (!checkfornotempty134) { perror("One or more of your arguments are empty"); exit(-1); } printf("<!DOCTYPE html><html><head>"); if (!argv2_notempty) { // ./a.out "sitename" "" "style_gajs_header.txt" "keywords.txt" printf("<title>%s</title>\n", argv[1]); } else { // ./a.out "sitename" "pagename" "style_gajs_header.txt" "keywords.txt" printf("<title>%s | %s</title>\n", argv[1], argv[2]); } int styleFilenameExists = access(argv[3], R_OK) != -1; int keywordsFilenameExists = access(argv[4], R_OK) != -1; if (! (styleFilenameExists && keywordsFilenameExists)) { perror("An error has occurred"); exit(-1); } printf("<meta charset=\"UTF-8\"/><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/><meta name=\"keywords\" content=\""); FILE *infile = fopen(argv[4], "r");// read in and print out keywords char buffer[BUFFER_SIZE]={0}; while (!feof(infile)) { fgets(buffer, BUFFER_SIZE, infile); for (int i = strlen(buffer)-1; i >= 0; i--) { if (buffer[i] == '\n') { buffer[i] = '\0'; break; } } printf("%s, ", buffer); memset(buffer, 0, BUFFER_SIZE); } fclose(infile); printf("\b\b\b\b\"/>\n"); infile = fopen(argv[3], "r");// cat out the aggregate style + analytics header file memset(buffer, 0, BUFFER_SIZE); while (!feof(infile)) { fgets(buffer, BUFFER_SIZE, infile); printf("%s", buffer); } fclose(infile); return 0; }
the_stack_data/37636738.c
/* This program converts real numbers to binary */ #include <stdio.h> #include <stdlib.h> #include <math.h> #define n 20 #define m 10 main(){ double ar, dek; int ak; int x[n]; int y[n]; int dib[n]; int k, i=0, j, neg; printf("Enter real number:"); scanf("%lf",&ar); printf("Your input: %lf\n", ar); neg=0; if(ar<0) { ar=ar*(-1); neg=1; } ak = floor(ar); dek = ar - floor(ar); while (ak>=1){ y[i]=ak%2; ak=ak/2; i++; } j=0; while ((dek!=1) && (j<=m)) { dek=dek - floor(dek); dek=dek*2; if(dek<1) dib[j]=0; else dib[j]=1; j++; } for(k=0; k<i;k++) x[k]=y[i-k-1]; printf("Binary number:"); if(neg) printf("-"); for(k=0;k<i;k++) printf("%d",x[k]); printf(","); for(k=0;k<j;k++) printf("%d",dib[k]); printf("\n"); system("pause"); }
the_stack_data/179829820.c
/** timeserv.c - a socket-based time of day server */ #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <time.h> #include <strings.h> #define PORTNUM 13000 /* our time service phone number */ #define HOSTLEN 256 #define oops(msg) { perror(msg); exit(1); } void print_ip(struct sockaddr *); int main(int ac, char *av[]) { struct sockaddr_in saddr; /* build our address here */ struct hostent *hp; /* this is part of our */ char hostname[HOSTLEN]; /* address */ int sock_id,sock_fd; /* line id, file desc */ FILE *sock_fp; /* use socket as stream */ char *ctime(); /* convert secs to string */ time_t thetime; /* the time we report */ /* * Step 1: ask kernel for a socket */ sock_id = socket( PF_INET, SOCK_STREAM, 0 ); /* get a socket */ if ( sock_id == -1 ) oops( "socket" ); /* * Step 2: bind address to socket. Address is host,port */ bzero( (void *)&saddr, sizeof(saddr) ); /* clear out struct */ gethostname( hostname, HOSTLEN ); /* where am I ? */ printf("My hostname is: %s\n", hostname); hp = gethostbyname( hostname ); /* get info about host */ printf("h_name: %s\n", hp->h_name); print_ip((struct sockaddr *)hp); saddr.sin_port = htons(PORTNUM); /* fill in socket port */ saddr.sin_family = AF_INET ; /* fill in addr family */ if ( bind(sock_id, (struct sockaddr *)&saddr, sizeof(saddr)) != 0 ) oops( "bind" ); /* * Step 3: allow incoming calls with Qsize=1 on socket */ if ( listen(sock_id, 1) != 0 ) oops( "listen" ); /* * main loop: accept(), write(), close() */ while ( 1 ){ struct sockaddr caller_addr; socklen_t addr_len; sock_fd = accept(sock_id, &caller_addr, &addr_len); /* wait for call */ print_ip(&caller_addr); printf("Wow! got a call!\n"); if ( sock_fd == -1 ) oops( "accept" ); /* error getting calls */ sock_fp = fdopen(sock_fd,"w"); /* we'll write to the */ if ( sock_fp == NULL ) /* socket as a stream */ oops( "fdopen" ); /* unless we can't */ thetime = time(NULL); /* get time */ /* and convert to strng */ fprintf( sock_fp, "The time here is .." ); fprintf( sock_fp, "%s", ctime(&thetime) ); fclose( sock_fp ); /* release connection */ } } void print_ip(struct sockaddr *res) /** * * @ref https://stackoverflow.com/questions/1276294/getting-ipv4-address-from-a-sockaddr-structure * @param addr_in */ { char *s = NULL; switch(res->sa_family) { case AF_INET: { struct sockaddr_in *addr_in = (struct sockaddr_in *)res; s = malloc(INET_ADDRSTRLEN); inet_ntop(AF_INET, &(addr_in->sin_addr), s, INET_ADDRSTRLEN); break; } case AF_INET6: { struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)res; s = malloc(INET6_ADDRSTRLEN); inet_ntop(AF_INET6, &(addr_in6->sin6_addr), s, INET6_ADDRSTRLEN); break; } default: printf("UNKNOWN sa_family\n"); break; } printf("IP address: %s\n", s); free(s); }
the_stack_data/15762941.c
abs(int arg) { if(arg < 0) arg = -arg; return(arg); }
the_stack_data/198581026.c
/* * A C program to reverse an array. * * MIT License * * Copyright (c) 2017 Benn * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #include <stdio.h> #include <stdlib.h> /* * reverse the given array */ void reverse(int A[], int n) { int start = 0, end = n - 1; while(start < end) { int temp; temp = A[start]; A[start] = A[end]; A[end] = temp; start++; end--; } } // driver function int main() { int A[] = {1, 2, 3, 4}; int n = sizeof(A)/sizeof(int); reverse(A, n); for(int i = 0; i < n; i++) { printf("%d ", A[i]); } printf("\n"); return 0; }
the_stack_data/936179.c
#include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <omp.h> /* Compilacao: gcc -o exec openmp.c -fopenmp -O3 Execucao: ./exec 2048 2000 4 */ #define SRAND_VALUE 1985 int tam; int ger; #define ESQ(i) (i + tam - 1) % tam #define DIR(i) (i + 1) % tam #define CIMA(i) (i + tam - 1) % tam #define BAIXO(i) (i + 1) % tam int ** old = NULL; int ** new = NULL; int GerarMatriz(int ** grid) { int i, j, c = 0; srand(SRAND_VALUE); for (i = 0; i < tam; i++) { //laço sobre as células do tabuleiro sem contar com um eventual halo for (j = 0; j < tam; j++) { grid[i][j] = rand() % 2; c += grid[i][j]; } } return c; } void inicializacao () { // Cria matrizes dinamicamente old = (int**) malloc(tam * sizeof(int*)); new = (int**) malloc(tam * sizeof(int*)); int i; for (i = 0; i < tam; i++) { old[i] = (int*)malloc(tam * sizeof(int)); new[i] = (int*)malloc(tam * sizeof(int)); } // Gera matriz e demonstra condicao inicial printf("Condicao inicial: %d\n", GerarMatriz(old)); } void trocar_matrizes(int*** A, int*** B) { int** aux = *A; *A = *B; *B = aux; } int getNeighbors(int** grid, int i, int j) { // Soma todos os vizinhos return ( grid[CIMA(i)][ESQ(j)] + grid[CIMA(i)][j] + grid[CIMA(i)][DIR(j)] ) + ( grid[i][ESQ(j)] + grid[i][DIR(j)] ) + ( grid[BAIXO(i)][ESQ(j)] + grid[BAIXO(i)][j] + grid[BAIXO(i)][DIR(j)] ); } int ViverOuMorrer(int** grid, int i, int j) { //Captura o número de vizinhos vivos int vizinhosVivos = getNeighbors(grid, i, j); if (grid[i][j] == 1) // Se vivo { // Morte por poucos ou muitos vizinhos if (vizinhosVivos < 2 || 4 <= vizinhosVivos) return 0; else return 1; } else // Se morto { // Vive, se tiver a quantidade correta de vizinhos if (vizinhosVivos == 3) return 1; else return 0; } } int Evoluir(int** old, int** new) { int i, j, c = 0; #pragma omp parallel private(i, j) reduction (+:c) { #pragma omp for collapse(2) for (i = 0; i < tam; i++){ for (j = 0; j < tam; j++){ new[i][j] = ViverOuMorrer(old, i, j); c += new[i][j]; } } } return c; } void TempoDecorrido(struct timeval inicio, struct timeval fim){ int tmili = (int) (1000*(fim.tv_sec - inicio.tv_sec)+ (fim.tv_usec - inicio.tv_usec)/1000); int segundos = tmili/1000; int milisegundos = tmili-segundos*1000; printf("\nTempo: %d segundos %d milisegundos\n", segundos, milisegundos); } int main(int argc, char **argv) { struct timeval inicio, final; int totalVivos; tam = atoi(argv[1]); ger = atoi(argv[2]); int num_threads = atoi(argv[3]); omp_set_num_threads(num_threads); inicializacao(); gettimeofday(&inicio, NULL); for (int i = 0; i < ger; i++) { totalVivos = Evoluir(old, new); printf("Geracao %d: %d\n", i + 1, totalVivos); trocar_matrizes(&old, &new); } gettimeofday(&final, NULL); TempoDecorrido(inicio, final); return 0; }
the_stack_data/22461.c
#include <stdlib.h> struct x { unsigned x1:1; unsigned x2:2; unsigned x3:3; }; void foobar (int x, int y, int z) { struct x a = {x, y, z}; struct x b = {x, y, z}; struct x *c = &b; c->x3 += (a.x2 - a.x1) * c->x2; if (a.x1 != 1 || c->x3 != 5) abort (); exit (0); } int main() { foobar (1, 2, 3); }
the_stack_data/724097.c
// ---------------------------------------------------------------------------- // Copyright 2015-2017 ARM Ltd. // // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ---------------------------------------------------------------------------- // This critical section implementation is generic for mbed OS targets, // except Nordic ones #if defined(TARGET_LIKE_MBED) && !defined(TARGET_NORDIC) #include <stdint.h> // uint32_t, UINT32_MAX #include <stddef.h> // NULL #if defined(MBED_EDGE_BUILD_CFG_MBED_OS) #include "cmsis-core/core_generic.h" //__disable_irq, __enable_irq #else #include "cmsis.h" #endif #include <assert.h> // Module include #include "aq_critical.h" static volatile uint32_t interruptEnableCounter = 0; static volatile uint32_t critical_primask = 0; void aq_critical_section_enter() { uint32_t primask = __get_PRIMASK(); // get the current interrupt enabled state __disable_irq(); // Save the interrupt enabled state as it was prior to any nested critical section lock use if (!interruptEnableCounter) { critical_primask = primask & 0x1; } /* If the interruptEnableCounter overflows or we are in a nested critical section and interrupts are enabled, then something has gone badly wrong thus assert an error. */ /* FIXME: This assertion needs to be commented out for the moment, as it * triggers a fault when uVisor is enabled. For more information on * the fault please checkout ARMmbed/mbed-drivers#176. */ /* assert(interruptEnableCounter < UINT32_MAX); */ if (interruptEnableCounter > 0) { /* FIXME: This assertion needs to be commented out for the moment, as it * triggers a fault when uVisor is enabled. For more information * on the fault please checkout ARMmbed/mbed-drivers#176. */ /* assert(primask & 0x1); */ } interruptEnableCounter++; } void aq_critical_section_exit() { // If critical_section_enter has not previously been called, do nothing if (interruptEnableCounter) { uint32_t primask = __get_PRIMASK(); // get the current interrupt enabled state /* FIXME: This assertion needs to be commented out for the moment, as it * triggers a fault when uVisor is enabled. For more information * on the fault please checkout ARMmbed/mbed-drivers#176. */ /* assert(primask & 0x1); // Interrupts must be disabled on invoking an exit from a critical section */ interruptEnableCounter--; /* Only re-enable interrupts if we are exiting the last of the nested critical sections and interrupts were enabled on entry to the first critical section. */ if (!interruptEnableCounter && !critical_primask) { __enable_irq(); } } } #endif // defined(TARGET_LIKE_MBED) && !defined(TARGET_NORDIC)
the_stack_data/123461.c
void main() { int a = 1; int b = 1; int c = a + b; }
the_stack_data/192329541.c
#include <stdio.h> int main() { printf("Dummy test\n"); return 0; }
the_stack_data/104327.c
#define _XOPEN_SOURCE 700 #include <errno.h> #include <limits.h> #include <locale.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> enum FLAGS { FLAG_r = 1 << 0, }; int flags; int alphacompare(const void *s1, const void *s2) { int ret = strcoll(*(const char **) s1, *(const char **) s2); if (flags & FLAG_r) ret *= -1; return ret; } void free_lines(char **lines, int n) { for (int i = 0; i < n; i++) free(lines[i]); free(lines); } int sort(FILE *f) { char **lines = malloc(sizeof(char *)); if (lines == NULL) { fprintf(stderr, "sort: %s\n", strerror(errno)); return 1; } size_t lsize = sizeof(char *); size_t lused = 0; int i = 0; char *buf = NULL; ssize_t bufused = 0; size_t bufsize = 0; while ((bufused = getline(&buf, &bufsize, f)) != -1) { if (bufused + lused > lsize) { char **tmp = realloc(lines, bufused + lused); if (tmp == NULL) { fprintf(stderr, "sort: %s\n", strerror(errno)); free_lines(lines, i); free(buf); return 1; } lused += bufused; lines = tmp; } lines[i] = strndup(buf, bufused); //strncpy(lines[i], buf, bufused); lines[i][bufused] = '\0'; i++; bufused = 0; } if (ferror(f)) { fprintf(stderr, "sort: %s\n", strerror(errno)); free_lines(lines, i); free(buf); return 1; } qsort(lines, i, sizeof lines[0], alphacompare); for (int j = 0; j < i; j++) { printf("%s", lines[j]); } free_lines(lines, i); free(buf); return 0; } int main(int argc, char **argv) { setlocale(LC_ALL, ""); int c; int ret = 0; flags = 0; while ((c = getopt(argc, argv, "r")) != -1) { switch (c) { case 'r': flags |= FLAG_r; break; } } argc -= optind; argv += optind - 1; if (argc == 0) return sort(stdin); while (*++argv) { FILE *f; if (**argv == '-' && *(*argv + 1) == '\0') f = stdin; else { f = fopen(*argv, "r"); if (f == NULL) { fprintf(stderr, "sort: %s: %s\n", *argv, strerror(errno)); ret = 1; continue; } } if (sort(f) != 0) ret = 1; if (f != stdin && fclose(f) == EOF) { fprintf(stderr, "sort: %s: %s\n", *argv, strerror(errno)); ret = 1; continue; } } return ret; }
the_stack_data/84992.c
#include<stdio.h> void main() { int a[100],n,m,i,j,temp; scanf("%d%d",&n,&m); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<11-m;i++)//一个一个移动直到移动4个 { temp=a[0]; for(j=0;j<n-1;j++)// a[j]=a[j+1]; a[j]=temp; } for(i=0;i<n;i++) printf("%d ",a[i]); printf("\n"); }
the_stack_data/231393137.c
#include <stdlib.h> struct icon_spin_s { int icon; int spin; }; #define MAX_DSO_ICONS (350) const struct icon_spin_s dso_icons[] = { { 21000, 1 }, { 21001, 2 }, { 21002, 3 }, { 21003, 4 }, { 21004, 5 }, { 21005, 6 }, { 21006, 7 }, { 21007, 8 }, { 21008, 9 }, { 21009, 10 }, { 21010, 11 }, { 21011, 12 }, { 21012, 13 }, { 21013, 14 }, { 21014, 15 }, { 21015, 16 }, { 21016, 17 }, { 21017, 18 }, { 21018, 19 }, { 21019, 20 }, { 21020, 21 }, { 21021, 22 }, { 21022, 23 }, { 21023, 24 }, { 21024, 25 }, { 21025, 26 }, { 21026, 27 }, { 21027, 28 }, { 21028, 29 }, { 21029, 30 }, { 21030, 31 }, { 21031, 32 }, { 21032, 33 }, { 21033, 34 }, { 21034, 35 }, { 21035, 36 }, { 21036, 37 }, { 21037, 38 }, { 21038, 39 }, { 21039, 40 }, { 21040, 41 }, { 21041, 42 }, { 21042, 43 }, { 21043, 44 }, { 21044, 45 }, { 21045, 46 }, { 21046, 47 }, { 21047, 48 }, { 21048, 49 }, { 21049, 50 }, { 21050, 51 }, { 21051, 52 }, { 21052, 53 }, { 21053, 54 }, { 21054, 55 }, { 21055, 56 }, { 21056, 57 }, { 21057, 58 }, { 21058, 59 }, { 21059, 60 }, { 21060, 61 }, { 21061, 62 }, { 21062, 63 }, { 21063, 64 }, { 21064, 65 }, { 21065, 66 }, { 21066, 67 }, { 21067, 68 }, { 21068, 69 }, { 21069, 70 }, { 21070, 71 }, { 21071, 72 }, { 21072, 73 }, { 21073, 74 }, { 21074, 75 }, { 21075, 76 }, { 21076, 77 }, { 21077, 78 }, { 21078, 79 }, { 21079, 80 }, { 21080, 81 }, { 21081, 82 }, { 21082, 83 }, { 21083, 84 }, { 21084, 85 }, { 21085, 86 }, { 21086, 87 }, { 21087, 88 }, { 21088, 89 }, { 21089, 90 }, { 21090, 91 }, { 21091, 92 }, { 21092, 93 }, { 21093, 94 }, { 21094, 95 }, { 21095, 96 }, { 21096, 97 }, { 21097, 98 }, { 21098, 99 }, { 21099, 100 }, { 21100, 101 }, { 21101, 102 }, { 21102, 103 }, { 21103, 104 }, { 21104, 105 }, { 21105, 106 }, { 21106, 107 }, { 21107, 108 }, { 21108, 109 }, { 21109, 110 }, { 21110, 111 }, { 21111, 112 }, { 21112, 113 }, { 21113, 114 }, { 21114, 115 }, // Wall of Ash? { 21069, 116 }, // Bless { 21070, 117 }, { 21071, 118 }, { 21072, 119 }, { 21073, 120 }, { 21074, 121 }, { 21075, 122 }, { 21076, 123 }, { 21077, 124 }, { 21078, 125 }, { 21079, 126 }, { 21080, 127 }, { 21081, 128 }, { 21082, 129 }, { 21083, 130 }, { 21084, 131 }, { 21085, 132 }, { 21086, 133 }, { 21087, 134 }, { 21088, 135 }, { 21089, 136 }, { 21090, 137 }, { 21091, 138 }, { 21092, 139 }, { 21093, 140 }, { 21094, 141 }, { 21095, 142 }, { 21096, 143 }, { 21097, 144 }, { 21098, 145 }, { 21099, 146 }, { 21100, 147 }, { 21101, 148 }, { 21102, 149 }, { 21103, 150 }, { 21104, 151 }, { 21105, 152 }, { 21106, 153 }, { 21107, 154 }, { 21108, 155 }, { 21109, 156 }, { 21110, 157 }, { 21111, 158 }, { 21112, 159 }, { 21113, 160 }, { 21114, 161 }, { 21115, 162 }, { 21116, 163 }, { 21117, 164 }, { 21118, 165 }, { 21119, 166 }, { 21120, 167 }, { 21121, 168 }, { 21122, 169 }, { 21123, 170 }, { 21124, 171 }, { 21125, 172 }, { 21126, 173 }, { 21127, 174 }, { 21128, 175 }, { 21129, 176 }, { 21130, 177 }, { 21131, 178 }, { 21132, 179 }, { 21133, 180 }, { 21134, 181 }, { 21135, 182 }, { 21186, 183 }, { 21187, 184 }, { 21188, 185 }, { 21185, 186 }, { 21186, 187 }, { 21187, 188 }, { 21188, 189 }, { 21189, 190 }, { 21190, 191 }, { 21191, 192 }, { 21192, 193 }, { 21193, 194 }, { 21194, 195 }, { 21195, 196 }, { 21196, 197 }, { 21197, 198 }, { 21198, 199 }, { 21199, 200 }, { 21200, 201 }, { 21201, 202 }, { 21202, 203 }, { 21203, 204 }, { 21204, 205 }, { 21205, 206 }, { 21206, 207 }, { 21207, 208 }, { 21208, 209 }, { 21209, 210 }, { 21210, 211 }, { 21211, 212 }, { 21212, 213 }, { 21213, 214 }, { 21214, 215 }, { 21215, 216 }, { 21216, 217 }, { 21217, 218 }, { 21218, 219 }, { 21219, 220 }, { 21220, 221 }, { 21221, 222 }, { 21222, 223 }, { 21223, 224 }, { 21224, 225 }, { 21225, 226 }, { 21226, 227 }, { 21227, 228 }, { 21228, 229 }, { 21229, 230 }, { 21230, 231 }, { 21231, 232 }, { 21232, 233 }, { 21233, 234 }, { 21234, 235 }, { 21235, 236 }, { 21236, 237 }, { 21237, 238 }, { 21238, 239 }, { 21239, 240 }, { 21240, 241 }, { 21241, 242 }, { 21242, 243 }, { 21243, 244 }, { 21244, 245 }, { 21245, 246 }, { 21246, 247 }, { 21247, 248 }, { 21248, 249 }, { 21249, 250 }, { 21250, 251 }, { 21251, 252 }, { 21252, 253 }, { 21253, 254 }, { 21254, 255 }, { 21255, 256 }, { 21256, 257 }, { 21257, 258 }, { 21258, 259 }, { 21259, 260 }, { 21260, 261 }, { 21261, 262 }, { 21262, 263 }, { 21263, 264 }, { 21264, 265 }, { 21265, 266 }, { 21266, 267 }, { 21267, 268 }, { 21268, 269 }, { -1, -1 }, // 270 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 280 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 290 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 300 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 310 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 320 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 330 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 340 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // index 345: DS1 start { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 350 }; const struct icon_spin_s ds1_icons[] = { { 21000, 1 }, { 21001, 2 }, { 21002, 3 }, { 21003, 4 }, { 21004, 5 }, { 21005, 6 }, { 21006, 7 }, { 21007, 8 }, { 21008, 9 }, { 21009, 10 }, { 21010, 11 }, { 21011, 12 }, { 21012, 13 }, { 21013, 14 }, { 21014, 15 }, { 21015, 16 }, { 21016, 17 }, { 21017, 18 }, { 21018, 19 }, { 21019, 20 }, { 21020, 21 }, { 21021, 22 }, { 21022, 23 }, { 21023, 24 }, { 21024, 25 }, { 21025, 26 }, { 21026, 27 }, { 21027, 28 }, { 21028, 29 }, { 21029, 30 }, { 21030, 31 }, { 21031, 32 }, { 21032, 33 }, { 21033, 34 }, { 21034, 35 }, { 21036, 37 }, { 21037, 38 }, { 21038, 39 }, { 21039, 40 }, { 21040, 41 }, { 21041, 42 }, { 21043, 44 }, { 21044, 45 }, { 21045, 46 }, { 21046, 47 }, { 21047, 48 }, { 21048, 49 }, { 21035, 36 }, { 21042, 43 }, { 21050, 51 }, { 21051, 52 }, { 21049, 50 }, { 21052, 53 }, { 21053, 54 }, { 21054, 55 }, { 21055, 56 }, { 21056, 57 }, { 21057, 58 }, { 21058, 59 }, { 21059, 60 }, { 21060, 61 }, { 21061, 62 }, { 21062, 63 }, { 21063, 64 }, { 21064, 65 }, { 21066, 67 }, { 21067, 68 }, { 21068, 69 }, { 21065, 66 }, { 21069, 70 }, { 21070, 71 }, { 21071, 72 }, { 21072, 73 }, { 21073, 74 }, { 21074, 75 }, { 21075, 76 }, { 21076, 77 }, { 21077, 78 }, { 21078, 79 }, { 21079, 80 }, { 21080, 81 }, { 21081, 82 }, { 21082, 83 }, { 21083, 84 }, { 21084, 85 }, { 21085, 86 }, { 21086, 87 }, { 21087, 88 }, { 21088, 89 }, { 21089, 90 }, { 21090, 91 }, { 21091, 92 }, { 21092, 93 }, { 21093, 94 }, { 21094, 95 }, { 21095, 96 }, { 21096, 97 }, { 21097, 98 }, { 21098, 99 }, { 21099, 100 }, { 21100, 101 }, { 21101, 102 }, { 21102, 103 }, { 21103, 104 }, { 21104, 105 }, { 21105, 106 }, { 21106, 107 }, { 21107, 108 }, { 21108, 109 }, { 21109, 110 }, { 21110, 111 }, { 21111, 112 }, { 21112, 113 }, { 21113, 114 }, { 21114, 115 }, // Wall of Ash? { 21115, 116 }, { 21116, 117 }, { 21117, 118 }, { 21118, 119 }, { 21119, 120 }, { 21120, 121 }, { 21121, 122 }, { 21122, 123 }, { 21123, 124 }, { 21124, 125 }, { 21125, 126 }, { 21126, 127 }, { 21127, 128 }, { 21128, 129 }, { 21129, 130 }, { 21130, 131 }, { 21131, 132 }, { 21132, 133 }, { 21133, 134 }, { 21134, 135 }, { 21135, 136 }, { 21136, 137 }, { 21137, 138 }, { 21138, 139 }, { 21139, 140 }, { 21140, 141 }, { 21141, 142 }, { 21142, 143 }, { 21143, 144 }, { 21144, 145 }, { 21145, 146 }, { 21146, 147 }, { 21147, 148 }, { 21148, 149 }, { 21149, 150 }, { 21150, 151 }, { 21151, 152 }, { 21152, 153 }, { 21153, 154 }, { 21154, 155 }, { 21155, 156 }, { 21156, 157 }, { 21157, 158 }, { 21158, 159 }, { 21159, 160 }, { 21160, 161 }, { 21161, 162 }, { 21162, 163 }, { 21163, 164 }, { 21164, 165 }, { 21165, 166 }, { 21166, 167 }, { 21167, 168 }, { 21168, 169 }, { 21169, 170 }, { 21170, 171 }, { 21171, 172 }, { 21172, 173 }, { 21173, 174 }, { 21174, 175 }, { 21175, 176 }, { 21176, 177 }, { 21177, 178 }, { 21178, 179 }, { 21179, 180 }, { 21180, 181 }, { 21181, 182 }, { 21182, 183 }, { 21183, 184 }, { 21184, 185 }, { 21185, 186 }, { 21186, 187 }, { 21187, 188 }, { 21188, 189 }, { 21189, 190 }, { 21190, 191 }, { 21191, 192 }, { 21192, 193 }, { 21193, 194 }, { 21194, 195 }, { 21195, 196 }, { 21196, 197 }, { 21197, 198 }, { 21198, 199 }, { 21199, 200 }, { 21200, 201 }, { 21201, 202 }, { 21202, 203 }, { 21203, 204 }, { 21204, 205 }, { 21205, 206 }, { 21206, 207 }, { 21207, 208 }, { 21208, 209 }, { 21209, 210 }, { 21210, 211 }, { 21211, 212 }, { 21212, 213 }, { 21213, 214 }, { 21214, 215 }, { 21215, 216 }, { 21216, 217 }, { 21217, 218 }, { 21218, 219 }, { 21219, 220 }, { 21220, 221 }, { 21221, 222 }, { 21222, 223 }, { 21223, 224 }, { 21224, 225 }, { 21225, 226 }, { 21226, 227 }, { 21227, 228 }, { 21228, 229 }, { 21229, 230 }, { 21230, 231 }, { 21231, 232 }, { 21232, 233 }, { 21233, 234 }, { 21234, 235 }, { 3000, 236 }, //Detonate { 3001, 237 }, { 3002, 238 }, { 3003, 239 }, { 3004, 240 }, { 3005, 241 }, { 3006, 242 }, { 3007, 243 }, { 3008, 244 }, { 3009, 245 }, { 3010, 246 }, { 3011, 247 }, { 3012, 248 }, { 3013, 249 }, { 3014, 250 }, { 3015, 251 }, { 3016, 252 }, { 3017, 253 }, { 3018, 254 }, { 3019, 255 }, { 3020, 256 }, { 3021, 257 }, { 3022, 258 }, { 3023, 259 }, { 3024, 260 }, { 3025, 261 }, { 3026, 262 }, { 3027, 263 }, { 3028, 264 }, { 3029, 265 }, { 3030, 266 }, { 3031, 267 }, { 3032, 268 }, { 3033, 269 }, { -1, -1 }, // 270 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 280 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 290 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 300 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 310 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 320 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 330 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, // 340 { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { -1, -1 }, { 21035, 36 }, // index 345: DS1 start Monster Summoning I { 21049, 50 }, // Monster Summoning II { 21065, 66 }, // Monster Summoning III { 21042, 43 }, // Evard's Black Tentacles { 4004, -1 }, // 350 }; static const char *priest_spells[] = { "BLESS", "CURSE", "CURLTWND", "CASLTWND", "ENTANGLE", "INVISUND", "MAGSTONE", "PROTEVIL", "REMFEAR", "CAUSFEAR", "SANCTURY", "SHILELAG", "AID", "ALTRUISM", "BARKSKIN", "CHNSTNCH", "CHRMPRML", "DUSTDEVL", "FNDTRAPS", "FLMBLADE", "HESITATN", "HLDPERSP", "MUSICSPH", "RESTFIRE", "RESTCOLD", "SILENC15", "SPRHAMER", "STELBRTH", "AIR_LENS", "BRMBSTAF", "CRTSMOKE", "CURBLIDF", "CASBLIDF", "CURDISES", "CASDISES", "DISMAGCP", "HEATXHST", "MAGCVEST", "NGPLNPRO", "PLNTGROW", "PRAYER", "PROTFIRE", "REMCURSE", "BSTCURSE", "REMPARAL", "SANDSPRA", "SPIKEGRO", "STONESHA", "STRNGTHO", "SUMINSCT", "ABJURE", "BLOODFLW", "CLKBRAVY", "CLKOFEAR", "CONDENSE", "CURSRWND", "CASSRWND", "DEHYDRAT", "DUSTCLOD", "FOCSHEAT", "FREEACT", "LUNGWATR", "MAGMABLD", "NEUTPOIS", "POISON", "PRODFIRE", "QUCHFIRE", "PROEVL10", "PROLIGHT", "PROWEATH", "INTENSFW", "RETEARTH", "SOOTHE", "THRNBIND", "CONAIRE", "CONFIREE", "CONEARHE", "CONWATRE", "CRUMBLE", "CURECRIT", "CAUSCRIT", "DEFLECTN", "DISPEVIL", "FLMSTRIK", "INSPLAGE", "IRONSKIN", "RAINBOW", "QUIKSAND", "RASEDEAD", "SLAYLIVG", "SANDSTOR", "SPIKSTON", "WALLFIRE", "BLADEBAR", "FIRESEED", "HEAL", "HARM", "HEARTSEE", "SUNSTROK", "WALTHORN", "WATOLIFE", "CONFUSIN", "CONGEL_A", "CONGEL_F", "CONGEL_E", "CONGEL_W", "CREEPING", "FIRESTOR", "GLASSTOR", "RESTORE", "ENERGYDR", "SCIROCCO", "SUNRAY", "SYM_HOPL", "SYM_PAIN", "SYM_PERS", "REV_WIND", "DISRUPTN", "INSCHOST", "RIFTPR", NULL }; static const char *wizard_spells[] = { "ARMOR", "BURNINGH", "CHARMPER", "CHILL", "COLORSPR", "ENLARGE", "GAZEREFL", "GREASE", "MAGICMIS", "SHIELD", "SHOKGRSP", "WALLOFOG", "BLUR", "DETINVIS", "FLMSPHER", "FOGCLOUD", "GLITTERD", "INVISBEL", "ACIDAROW", "MIRRORIM", "PROPARAL", "SCARE", "STINKCLD", "STRENGTH", "WEB", "BLINK", "DISWIZRD", "FIREBALL", "FLMARROW", "HASTE", "HOLDWIZ", "HLDUNDED", "LITNBOLT", "MINMETOR", "MINMALIS", "PRONMMIS", "SLOW", "SPIRARMR", "VAMTOUCH", "CHARMMON", "CNFUSWIZ", "FEAR", "FIRESHLD", "ICESTORM", "IMPVISIB", "MGBINVUL", "MINSPTUR", "ORSPHERE", "PSIDAMPR", "RAINBOWP", "SOLIDFOG", "SSTRAND", "STONSKIN", "PEBTOBOD", "WALLFIRW", "WALLOICE", "CHAOS", "CLODKILL", "CNOFCOLD", "CONELEMN", "DISMISAL", "DOMINATE", "FEEBLEMD", "HLDMONST", "LOWRESMG", "SUMSHADW", "WALLFORC", "WALLSTON", "ANTIMAGS", "CHAINLIT", "DEATHFOG", "DEATHSPL", "DISNTWIZ", "GLOBEINV", "IMPHASTE", "IMPSLOW", "MONSUMM4", "REINCARN", "STNTFLSH", "FLSHTSTN", "TNSRTRAN", "CGELMENT", "CNUNDEAD", "DELAYFBA", "FINGEROD", "FORCAGE", "MASINVSB", "MONSUMM5", "MORDSWRD", "POWSTUN", "PRISPRAY", "SPELTURN", "BIGBYFST", "INCNDCLD", "MASCHARM", "MINDBLKW", "MONSUMM6", "OTSPHERE", "OTTODANC", "POWBLIND", "PRISWALL", "SSPELLIM", "BIGBYHND", "CRYSBRTL", "LVLDRAIN", "METEORSW", "MONSUMM7", "MORDDISJ", "POWKILL", "PRISPHER", "TIMESTOP", "DOMEINVL", "MAGPLAGU", "RIFT", "WALLASH", "MONSUMM1", "MONSUMM2", "MONSUMM3", "EVARDSBT", NULL }; static const char *psionics[] = { "DETONATE", "DISNTGRT", "PRJTFRCE", "BLSTCATK", "CNTLBODY", "INERTBAR", "ANMAFFIN", "ENRGECON", "LIFDRAIN", "ABSRBDIS", "ADRENCNT", "BIOFEDBK", "BODYWEAP", "CELLADG", "DISPLACE", "ENSTRENG", "FLESHARM", "GRAFWEAP", "LNDHEALH", "SHARESTR", "PSIDOMNT", "MASSDOM", "PSICRUSH", "SUPINVIS", "TWRIRONW", "EGO_WHIP", "IDINSINT", "INTELFOR", "MENTLBAR", "MIND_BAR", "MNDBLANK", "PSIBLAST", "SYNPSTAT", "THOTSHLD", NULL }; static const char *innate_power_full[] = { "COLD TOUCH", "PARALYSIS TOUCH", "ACID TOUCH", "WEB", "POISON 10", "POISON 30", "CORROSIVE POISON", "PARALYSIS GAZE", "LAUNCH DARTS", "FIRE BERATH", "STUN SCREAM", "ENFEEBLEMENT GAZE", "ROTTING DISEASE", "FIRE BREATH", "CORRODE ARMOR", "CORRODE WEAPON", "CONE OF SKULLS", "STUN", "CLAMP AND SHAKE", "SWALLOW", "GATE_AIR", "GATE_EARTH", "GATE_FIRE", "GATE_WATER", "EARTHQUAKE", "FEYR_FEAR", "SMASH_FISTS", "RADIATE_HEAT", "BURNING TOUCH", "CRUSH", "AURA_OF_FEAR", "MIND_BLAST", "EAT_BRAIN", "TERRASQUE_TRAMPLE", "CONSTRICT", "PARALYSE_SPIT", "THRIKREEN POISON", "TURN UNDEAD", "TWINKLE", "GENERIC ZAP", "BURNING_WEB", "ETC_POISON_PARALYZING ", "ETC_SCHRAPNEL_D10 ", "ROD_OF_TEETH", "NINE_LIFE_STEALER", "RAINBOW BOW", "HEART_SEEKER ", "SWORD_OF_MAGMA", "SWORD_OF_WOUNDING", "LOCK_JAWS", "UMBERHULK", "POISON", "SCREECH", "DETONATE", "SLIME", "POISON", "BANSHEE GAZE", "FIRE EEL", "GHOST FEAR", "MASTRYIAL", "BLACK MASTRYIAL", "DISEASE", "RAMPAGER_FEAR", "DISEASE", "HOWL", "PSIONIC BLAST", "GREATER SHADOW", "SLAAD DISEASE", "RED SLAAD STUN", "POISON", "SPINE LAUNCH", "STYR BREATH", "TANARRI SCREECH", "TYRIAN SLIME", "XORN CORROSION", "ZOMBIE", NULL }; static const char *innate_power_short[] = { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "RODOFTTH", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "PSIBLAST", " ", " ", " ", "POISON", "SPINES", " ", " ", " ", " ", " ", " ", NULL}; static const char *ds1_power_names[] = {"DNE", "ARMOR", "BURNING HANDS", "CHARM PERSON", "CHILL TOUCH", "COLOR SPRAY", "ENLARGE", "GAZE REFLECTION", "GREASE", "MAGIC MISSILE", "SHIELD", "SHOCKING GRASP", "WALL OF FOG", "BLUR", "DETECT INVISIBLE", "FLAMING SPHERE", "FOG CLOUD", "GLITTER DUST", "INVISIBILITY", "ACID ARROW", "MIRROR IMAGE", "PROTECTION FROM PARALYSIS", "SCARE", "STINKING CLOUD", "STRENGTH", "WEB", "BLINK", "DISPEL MAGIC", "FIREBALL", "FLAMING ARROW", "HASTE", "HOLD PERSON", "HOLD UNDEAD", "LIGHTNING BOLT", "MINUTE METEORS", "MINOR MALISON", "MONSTER SUMMONING I", "PROTECTION FROM MISSILES", "SLOW", "SPIRIT ARMOR", "VAMPIRIC TOUCH", "CHARM MONSTER", "CONFUSION", "EVARD'S BLACK TENTACLES", "FEAR", "FIRE SHIELD", "ICE STORM", "IMPROVED INVISIBILITY", "M GLOBE OF INVULNERABILITY", "MINOR SPELL TURNING", "MONSTER SUMMONING II", "RAINBOW PATTERN", "SOLID FOG", "STONE SKIN", "PEBBLE TO BOULDER", "WALL OF FIRE", "WALL OF ICE", "CHAOS", "CLOUD KILL", "CONE OF COLD", "CONJURE ELEMENTAL", "DISMISSAL", "DOMINATE", "FEEBLE MIND", "HOLD MONSTER", "LOWER RESISTANCE", "MONSTER SUMMONING III", "SUMMON SHADOW", "WALL OF FORCE", "WALL OF STONE", "BLESS", "CURSE", "CURE LIGHT WOUNDS", "CAUSE LIGHT WOUNDS", "ENTANGLE", "INVISIBLE TO UNDEAD", "MAGIC STONE", "PROTECTION FROM EVIL", "REMOVE FEAR", "CAUSE FEAR", "SHILLELAGH", "AID", "BARKSKIN", "CHARM MAMMAL", "DUSTDEVIL", "FIND TRAPS", "FLAME BLADE", "HOLD PERSON", "RESIST FIRE", "RESIST COLD", "SPIRITUAL HAMMER", "CONJURE AIR ELEMENTAL", "CONJURE FIRE ELEMENTAL", "CONJURE EARTH ELEMENTAL", "CONJURE WATER ELEMENTAL", "CURE BLINDNESS", "CAUSE BLINDNESS", "CURE DISEASE", "CAUSE DISEASE", "DISPEL MAGIC", "MAGIC VESTMENT", "NEGATIVE PLANE PROTECTION", "PRAYER", "PROTECTION FROM FIRE", "REMOVE CURSE", "BESTOW CURSE", "REMOVE PARALYSIS", "SUMMON INSECTS", "ABJURE", "BLOOD FLOW", "CLOAK OF BRAVERY", "CLOAK OF FEAR", "CONDENSE", "CURE SERIOUS WOUNDS", "CAUSE SERIOUS WOUNDS", "DEHYDRATE", "DUST CLOUD", "FOCUS HEAT", "FREE ACTION", "NEUTRALIZE POISON", "POISON", "PRODUCE FIRE", "PROTECTION FROM EVIL 10", "PROTECTION FROM LIGHTNING", "CONJURE GREATER AIR ELEMENTAL", "CONJURE GREATER FIRE ELEMENTAL", "CONJURE GREATER EARTH ELEMENTAL", "CONJURE GREATER WATER ELEMENTAL", "CURE CRITICAL WOUNDS", "CAUSE CRITICAL WOUNDS", "DEFLECTION", "DISPEL EVIL", "FLAME STRIKE", "INSECT PLAGUE", "IRON SKIN", "QUICKSAND", "RAISE DEAD", "SLAY LIVING", "WALL OF FIRE", "DETONATE", "DISINTEGRATE", "PROJECT FORCE", "BALLISTIC ATTACK", "CONTROL BODY", "INERTIAL BARRIER", "ANIMAL AFFINITY", "ENERGY CONTROL", "LIFE DRAIN", "ABSORB DISEASE", "ADRENALIN CONTROL", "BIOFEEDBACK", "BODY WEAPONRY", "CELLULAR ADJUSTMENT", "DISPLACEMENT", "ENHANCED STRENGTH", "FLESH ARMOR", "GRAFT WEAPON", "LEND HEALTH", "SHARE STRENGTH", "DOMINATION", "MASS DOMINATION", "PSYCHIC CRUSH", "SUPERIOR INVISIBILITY", "TOWER OF IRON WILL", "EGO WHIP", "ID INSINUATION", "INTELLECT FORTRESS", "MENTAL BARRIER", "PSIONIC MIND BAR", "MIND BLANK", "PSIONIC BLAST", "SYNAPTIC STATIC", "THOUGHT SHIELD", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "TURN UNDEAD", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "DNE", "TURN UNDEAD", "MONSTER SUMMONING I", "MONSTER SUMMONING II", "MONSTER SUMMONING III", "EVARD'S BLACK TENTACLES" };
the_stack_data/35314.c
#include <stdio.h> #include <math.h> #include <stdlib.h> #define MAX_SIZE 101 #define SWAP(x,y,t) ((t)=(x),(x)=(y),(y)=(t)) void SelectSort(int *,int ); int main(int argc, char **argv) { int i,n; int list[MAX_SIZE]; printf("Enter the number of numbers generate:"); scanf("%d",&n); if(n<0||n>MAX_SIZE) { fprintf(stderr,"Improper value !\n"); exit(1); } for(i=0;i<n;i++) { /*random generate number*/ list[i]=rand()%1000; printf("%d ",list[i]); } SelectSort(list,n); printf("\nSorted array is:\n"); for(i=0;i<n;i++) printf("%d ",list[i]); printf("\n"); return 0; } void SelectSort(int *ptrl,int n) { int i,j,min,tmp; for(i=0;i<n-1;i++) { min=i; for(j=i+1;j<n;j++) { if(*(ptrl+j) < *(ptrl+min) ) min = j; } if(min!=i) { SWAP(*(ptrl+i),*(ptrl+min),tmp); } } }
the_stack_data/12452.c
#include<stdio.h> #include<stdlib.h> #include<pthread.h> #include<semaphore.h> // Global Semaphore sem_t sem; // Global Variable Balance int balance = 1000; // Thread Handler Function to Deposit Money into the Ballance void *deposit(void *arg) { // Critical Section sem_post(&sem); int deposit_amount = *(int *)arg; balance += deposit_amount; printf("Balance: $%i\n", balance); sem_wait(&sem); // End of Critical Section } // Main Functoin int main(int argc, char *argv[]) { int result; pthread_t thread1, thread2; int deposit_amount = 200; // Semaphore Initialization sem_init(&sem, 0, 0); // Create Thread result = pthread_create(&thread1, NULL, &deposit, &deposit_amount); if(result == -1) { printf("Error creating thread one.\n"); return EXIT_FAILURE; // -1 } result = pthread_create(&thread2, NULL, &deposit, &deposit_amount); if(result == -1) { printf("Error creating thread two.\n"); return EXIT_FAILURE; // -1 } // Execute and join the results pthread_join(thread1, NULL); pthread_join(thread2, NULL); // Semaphore Destroy sem_destroy(&sem); return EXIT_SUCCESS; // 0 }
the_stack_data/6386689.c
#include <stdio.h> #include <stdlib.h> typedef struct NODE { struct NODE *fwd; struct NODE *bwd; int value; }Node; void create(Node *root) { Node *pPrev, *pCurr; int i = 0; pPrev = root; for(i = 0; i < 3; i++) { pCurr = (Node *)malloc(sizeof(Node)); pCurr->value = i + 1; pCurr->fwd = NULL; pCurr->bwd = pPrev; pPrev->fwd = pCurr; pPrev = pCurr; } } int dll_remove(struct NODE *rootp, struct NODE *node) { while(rootp != NULL && rootp != node) { rootp = rootp->fwd; } if (rootp == node) { rootp->bwd->fwd = rootp->fwd; rootp->fwd->bwd = rootp->bwd; free(rootp); return 1; } return 0; } void my_list(Node *first) { while (first != NULL) { printf("%d\n", first->value); first = first->fwd; } } Node *find(Node *root, int x) { while(root != NULL) { if (root->value == x) { return root; } root = root->fwd; } return NULL; } int main (void) { Node *root; root = (Node *)malloc(sizeof(Node)); root->value = -1; create(root); my_list(root); Node *node; node = find(root, 2); printf("remove is %d\n", dll_remove(root, node)); my_list(root); }
the_stack_data/72012905.c
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. #include <assert.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/syscall.h> #include <unistd.h> static __inline__ long syscall0(long n) { unsigned long ret; __asm__ __volatile__("syscall" : "=a"(ret) : "a"(n) : "rcx", "r11", "memory"); return (long)ret; } static __inline__ long syscall1(long n, long x1) { unsigned long ret; __asm__ __volatile__("syscall" : "=a"(ret) : "a"(n), "D"(x1) : "rcx", "r11", "memory"); return (long)ret; } static __inline__ long syscall2(long n, long x1, long x2) { unsigned long ret; __asm__ __volatile__("syscall" : "=a"(ret) : "a"(n), "D"(x1), "S"(x2) : "rcx", "r11", "memory"); return (long)ret; } static __inline__ long syscall3(long n, long x1, long x2, long x3) { unsigned long ret; __asm__ __volatile__("syscall" : "=a"(ret) : "a"(n), "D"(x1), "S"(x2), "d"(x3) : "rcx", "r11", "memory"); return (long)ret; } static __inline__ long syscall4(long n, long x1, long x2, long x3, long x4) { unsigned long ret; register long r10 __asm__("r10") = x4; __asm__ __volatile__("syscall" : "=a"(ret) : "a"(n), "D"(x1), "S"(x2), "d"(x3), "r"(r10) : "rcx", "r11", "memory"); return (long)ret; } static __inline__ long syscall5(long n, long x1, long x2, long x3, long x4, long x5) { unsigned long ret; register long r10 __asm__("r10") = x4; register long r8 __asm__("r8") = x5; __asm__ __volatile__("syscall" : "=a"(ret) : "a"(n), "D"(x1), "S"(x2), "d"(x3), "r"(r10), "r"(r8) : "rcx", "r11", "memory"); return (long)ret; } static __inline__ long syscall6(long n, long x1, long x2, long x3, long x4, long x5, long x6) { unsigned long ret; register long r10 __asm__("r10") = x4; register long r8 __asm__("r8") = x5; register long r9 __asm__("r9") = x6; __asm__ __volatile__( "syscall" : "=a"(ret) : "a"(n), "D"(x1), "S"(x2), "d"(x3), "r"(r10), "r"(r8), "r"(r9) : "rcx", "r11", "memory"); return (long)ret; } static __inline__ long print_string(const char* str) { return syscall3(SYS_write, 1, (long)str, strlen(str)); } int main(int argc, const char* argv[]) { const char msg[] = "Hello world!\n"; long ret = print_string(msg); assert(ret == sizeof(msg) - 1); return 0; }
the_stack_data/140766116.c
#include<stdio.h> int main(){ int num, rev=0; printf("Enter number:\n"); scanf("%d",&num); while(num>0){ rev=rev*10+num%10; num/=10; } printf("\n%d is the reversed number\n",rev); }
the_stack_data/6387501.c
#include <stdio.h> #include <sys/socket.h> #include <arpa/inet.h> #include <unistd.h> #include <string.h> #define PORT 8080 int main(int argc, char const *argv[]) { int sock = 0, valread; struct sockaddr_in serv_addr; if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("\n Socket creation error \n"); return -1; } serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(PORT); // Convert IPv4 and IPv6 addresses from text to binary form if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0) { printf("\nInvalid address/ Address not supported \n"); return -1; } if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { printf("\nConnection Failed \n"); return -1; } printf("Enter the text : "); char stri[1024]; scanf("%s", stri); send(sock , stri , sizeof(stri), 0); printf("Text sent\n"); char res[1024]; valread = read( sock , res, sizeof(res)); printf("The text recieved : %s\n", res); int i=0; if(strlen(stri)!=strlen(res)) { printf("Echo Unuccessful!!\n"); } else { int flag = 1; for(i=0;i<strlen(res);i++) { if(res[i]!=stri[i]) { flag=0; break; } } if(flag) { printf("Echo Successful!!\n"); } else { printf("Echo Unuccessful!!\n"); } } return 0; }
the_stack_data/633226.c
/* * libgcc/__ashldi3.c */ #include <stdint.h> #include <stddef.h> uint64_t __ashldi3(uint64_t v, int cnt) { int c = cnt & 31; uint32_t vl = (uint32_t) v; uint32_t vh = (uint32_t) (v >> 32); if (cnt & 32) { vh = (vl << c); vl = 0; } else { vh = (vh << c) + (vl >> (32 - c)); vl = (vl << c); } return ((uint64_t) vh << 32) + vl; }
the_stack_data/87638771.c
int foo(void); int foo(void) { int p = 5; int i = 7; i = 5 <= p; return i; }
the_stack_data/920584.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/fcntl.h> #include <string.h> #include <sys/time.h> void resonable_file_size(int pFile, unsigned int block_size){ long begin, end; struct timeval timecheck; unsigned int block_count=0; size_t file_size=0,bytes_read; float time; int x=1; gettimeofday(&timecheck, NULL); begin = (long)timecheck.tv_sec * 1000 + (long)timecheck.tv_usec / 1000; while (1){ unsigned int* buffer=(unsigned int*) malloc(sizeof(unsigned int)*block_size); bytes_read=read (pFile,buffer,block_size*sizeof(unsigned int)); if(bytes_read<1){ free(buffer); break; } else{ file_size += bytes_read; free(buffer); if (block_count==x){ x=2*x; gettimeofday(&timecheck, NULL); end = (long)timecheck.tv_sec * 1000 + (long)timecheck.tv_usec / 1000; time = (float)(end - begin)/1000; if (time >= 5){ file_size=(unsigned long long int)block_size*block_count*4; printf("Block size: %u\nBlock count: %u\nFile size in bytes: %zu\n", block_size, block_count,file_size); printf("Total execution time in seconds: %f\n", time ); printf("Read speed in B/s: %.0f\n",(float)file_size/(time)); printf("Read speed in MiB/s: %.3f\n",(float)file_size/(1024*1024*time)); close(pFile); exit(0); } } } block_count++; } gettimeofday(&timecheck, NULL); end = (long)timecheck.tv_sec * 1000 + (long)timecheck.tv_usec / 1000; time = (float)(end - begin)/1000; file_size=(unsigned long long int)block_size*block_count*4; printf("Block size: %u\nBlock count: %u\nFile size in bytes: %zu\n", block_size, block_count,file_size); printf("Total execution time in seconds: %f\n", time ); printf("Read speed in B/s: %.0f\n",(float)file_size/(time)); printf("Read speed in MiB/s: %.3f\n",(float)file_size/(1024*1024*time)); } int main(int argc,char *argv[]){ int block_size, file_size, pFile; unsigned int block_count ; pFile=open(argv[1],O_RDONLY); if(pFile < 0){ printf("cannot open file %s.\n",argv[1]); exit(1); } else if(argc!=3){ printf("Invalid number of arguments.\n"); exit(1); } else{ block_size=atoi(argv[2]); resonable_file_size(pFile, block_size); exit(0); } close(pFile); exit(0); }
the_stack_data/5851.c
/* * Copyright (c) 1988, 1993 * The Regents of the University of California. 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 University 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 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. */ #include <sys/cdefs.h> #include <errno.h> #include <stdio.h> #include <string.h> void perror(s) const char *s; { if (s != NULL && *s != '\0') { fputs(s, stderr); fputs(": ", stderr); } fputs(strerror(errno), stderr); fputs("\n", stderr); }
the_stack_data/159515037.c
/* ****************************************** Count numbers in a 2^k sieve meant for reducing to 1. Also find deltaN. Compile and run via something like... clang -O3 collatzSieve2toK_FindPatterns_reduceTo1_Aequals0.c -fopenmp time ./a.out >> log.txt To configure OpenMP, you can change the argument of num_threads(). Just search this code for "num_threads". I wouldn't do more threads than physical CPU cores to prevent bottlenecks due to sharing resources. Since reducing to 1 in k steps is rare, there might be a faster way of doing this. (c) 2021 Bradley Knockel ****************************************** */ #include <stdlib.h> #include <stdio.h> #include <stdint.h> #include <inttypes.h> #include <sys/time.h> struct timeval tv1, tv2; /* This code uses 64-bit integers, so k < 41 */ const int k = 17; const uint64_t deltaN = 21845; /* 2^K is the number of numbers processed by each CPU thread K <= k K should ideally be a good amount less than k To use less RAM, K shouldn't be TOO much less than k */ int32_t K = 12; int main(void) { const uint64_t k2 = (uint64_t)1 << k; // 2^k const uint64_t collectLength = (uint64_t)1 << (k-K); const uint64_t b0perThread = (uint64_t)1 << K; printf(" k = %i\n", k); printf(" deltaN = %" PRIu64 "\n", deltaN); fflush(stdout); // start timing gettimeofday(&tv1, NULL); // for OpenMP threads to write to uint64_t *collectCount = malloc(sizeof(uint64_t) * collectLength); uint64_t *collectMaxM = malloc(sizeof(uint64_t) * collectLength); //// find max deltaN and count numbers that need testing #pragma omp parallel for schedule(guided) num_threads(6) for (size_t index=0; index<collectLength; index++){ uint64_t countTiny = 0; uint64_t maxMtiny = 0; for (uint64_t b0 = index*b0perThread; b0 < (index+1)*b0perThread; b0++) { int temp = 1; // acts as a boolean if (b0 != 0) { // lists for b0 uint64_t b0steps[k+1]; int b0c[k+1]; b0steps[0] = b0; b0c[0] = 0; for (size_t i=1; i<=k; i++){ if (b0steps[i-1] & 1) { // bitwise test for odd b0steps[i] = 3*(b0steps[i-1]/2) + 2; // note that b0steps[i-1] is odd b0c[i] = b0c[i-1]+1; } else { b0steps[i] = (b0steps[i-1] >> 1); b0c[i] = b0c[i-1]; } } uint64_t lenList = ((deltaN+1) < (b0-1)) ? (deltaN+1) : (b0-1) ; // get min(deltaN+1, b0-1) for(uint64_t m=1; m<lenList; m++) { // loop over m uint64_t n = b0-m; int c = 0; for(size_t j=1; j<=k; j++) { // steps // take step if (n & 1) { // bitwise test for odd n = 3*(n/2) + 2; // note that n is odd c++; } else { n >>= 1; if ( n == 1 ) {n = 0;} } // check against b0 lists if ( n == b0steps[j] && c == b0c[j] ) { if(m > maxMtiny){ maxMtiny = m; } temp = 0; m = lenList; // break out of the m loop break; } } } } if (temp) countTiny++; } collectCount[index] = countTiny; collectMaxM[index] = maxMtiny; } uint64_t count = 0; uint64_t maxM = 0; // see if deltaN is ever really reached for (size_t index=0; index<collectLength; index++){ count += collectCount[index]; uint64_t maxMtiny = collectMaxM[index]; if (maxMtiny > maxM) maxM = maxMtiny; } gettimeofday(&tv2, NULL); printf(" Elapsed wall time is %e seconds\n", (double)(tv2.tv_usec - tv1.tv_usec) / 1000000.0 + (double)(tv2.tv_sec - tv1.tv_sec) ); printf("%" PRIu64 " out of %" PRIu64 " need testing, so %f\n", count, k2, (double)count / (double)k2); if (maxM > 0) printf(" max deltaN = %" PRIu64 "\n", maxM); printf("\n"); return 0; }
the_stack_data/885368.c
int f() { int age[4]; age[0]=23; age[1]=34; age[2]=65; age[3]=74; return age[0] + age[1] + age[2] + age[3]; }
the_stack_data/510710.c
#include <stdio.h> int main() { int a[2][3] = {{1,2,3},{4,5,6}},b[3][2],i,j; printf("array a:\n"); for(i=0;i<=1;i++) { for(j=0;j<=2;j++) { printf("%5d\t",a[i][j]); b[j][i]=a[i][j]; } printf("\n"); } printf("array b:\n"); for(i=0;i<=2;i++) { for(j=0;j<=1;j++) printf("%d\t",b[i][j]); printf("\n"); } return 0; }
the_stack_data/154829397.c
#include <stdio.h> int main(void) { int x, y; while (scanf("%d%d",&x,&y)!=EOF) { printf("%d\n", x + y); } return 0; }
the_stack_data/98605.c
#include<stdlib.h> #include<math.h> #include<stdio.h> // forward kinematics: (theta1, theta2, theta3) -> (x0, y0, z0) // returned status: 0=OK, -1=non-existing position struct re_val_forKin { float x; float y; float z; }; struct re_val_InvKin { float theta1; float theta2; float theta3; }; float e = 50; // end effector float f = 70; // base float re = 460; float rf = 200; // trigonometric constants const float sqrt3 = 1.73205; //sqrt(3.0); const float pi = 3.141592653; // PI const float sin120 = 0.86602; //sqrt3/2.0; const float cos120 = -0.5; const float tan60 = 1.73205; const float sin30 = 0.5; const float tan30 = 0.57735; //1.0/sqrt3; struct re_val_forKin delta_calcForward(float theta1, float theta2, float theta3) { //input: Getting input theta1,theta2 and theta3 //output: Returns the (x,y,z) location of object //Description: Used for calcuating the delta forward kinematics float x0,y0,z0; float t = (f-e)*tan30/2; float y1 = -(t + rf*cos(theta1)); float z1 = -rf*sin(theta1); float y2 = (t + rf*cos(theta2))*sin30; float x2 = y2*tan60; float z2 = -rf*sin(theta2); float y3 = (t + rf*cos(theta3))*sin30; float x3 = -y3*tan60; float z3 = -rf*sin(theta3); float dnm = (y2-y1)*x3-(y3-y1)*x2; float w1 = y1*y1 + z1*z1; float w2 = x2*x2 + y2*y2 + z2*z2; float w3 = x3*x3 + y3*y3 + z3*z3; float a1 = (z2-z1)*(y3-y1)-(z3-z1)*(y2-y1); float b1 = -((w2-w1)*(y3-y1)-(w3-w1)*(y2-y1))/2.0; float a2 = -(z2-z1)*x3+(z3-z1)*x2; float b2 = ((w2-w1)*x3 - (w3-w1)*x2)/2.0; float a = a1*a1 + a2*a2 + dnm*dnm; float b = 2*(a1*b1 + a2*(b2-y1*dnm) - z1*dnm*dnm); float c = (b2-y1*dnm)*(b2-y1*dnm) + b1*b1 + dnm*dnm*(z1*z1 - re*re); // discriminant float d = b*b - (float)4.0*a*c; if (d < 0) perror("Non existing point"); // non-existing point z0 = -(float)0.5*(b+sqrt(d))/a; x0 = (a1*z0 + b1)/dnm; y0 = (a2*z0 + b2)/dnm; //printf("x0:%f, y0:%f, z0:%f \n",x0,y0,z0); struct re_val_forKin r; r.x = x0; r.y = y0; r.z = z0; return r; } // inverse kinematics // helper functions, calculates angle theta1 (for YZ-pane) int delta_calcAngleYZ(float x0, float y0, float z0, float* theta) { float y1 = -0.5 * 0.57735 * f; // f/2 * tg 30 y0 -= 0.5 * 0.57735 * e; // shift center to edge // z = a + b*y float a = (x0*x0 + y0*y0 + z0*z0 +rf*rf - re*re - y1*y1)/(2*z0); float b = (y1-y0)/z0; // discriminant float d = -(a+b*y1)*(a+b*y1)+rf*(b*b*rf+rf); if (d < 0) return -1; // non-existing point float yj = (y1 - a*b - sqrt(d))/(b*b + 1); // choosing outer point float zj = a + b*yj; *theta = 180.0*atan(-zj/(y1 - yj))/pi + ((yj>y1)?180.0:0.0); return 0; } // inverse kinematics: (x0, y0, z0) -> (theta1, theta2, theta3) // returned status: 0=OK, -1=non-existing position struct re_val_InvKin delta_calcInverse(float x0, float y0, float z0) { //input: Getting input (x,y,z) //output: Returns the (theta1,theta2,theta3) for each stepper motor //Description: Used for calcuating the delta inverse kinematics float t1 ,t2 ,t3 = 0; float t = (f-e)*tan30/2; float dtr = pi/(float)180.0; //theta1 *= dtr; //theta2 *= dtr; //theta3 *= dtr; int status = delta_calcAngleYZ(x0, y0, z0, &t1); if (status == 0) { status = delta_calcAngleYZ(x0*cos120 + y0*sin120, y0*cos120-x0*sin120, z0, &t2); // rotate coords to +120 deg } if (status == 0) { status = delta_calcAngleYZ(x0*cos120 - y0*sin120, y0*cos120+x0*sin120, z0, &t3); // rotate coords to -120 deg } struct re_val_InvKin invKin; invKin.theta1 = t1; //* dtr; invKin.theta2 = t2; //* dtr; invKin.theta3 = t3; //* dtr; return invKin; } void connect() { printf("Connected to C extension\n"); }
the_stack_data/10901.c
# 1 "reorder_bad.c" # 1 "<built-in>" # 1 "<command line>" # 1 "reorder_bad.c" # 1 "/usr/include/stdio.h" 1 3 4 # 28 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/features.h" 1 3 4 # 329 "/usr/include/features.h" 3 4 # 1 "/usr/include/sys/cdefs.h" 1 3 4 # 313 "/usr/include/sys/cdefs.h" 3 4 # 1 "/usr/include/bits/wordsize.h" 1 3 4 # 314 "/usr/include/sys/cdefs.h" 2 3 4 # 330 "/usr/include/features.h" 2 3 4 # 352 "/usr/include/features.h" 3 4 # 1 "/usr/include/gnu/stubs.h" 1 3 4 #include <assert.h> # 1 "/usr/include/bits/wordsize.h" 1 3 4 # 5 "/usr/include/gnu/stubs.h" 2 3 4 # 1 "/usr/include/gnu/stubs-64.h" 1 3 4 # 10 "/usr/include/gnu/stubs.h" 2 3 4 # 353 "/usr/include/features.h" 2 3 4 # 29 "/usr/include/stdio.h" 2 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 214 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 3 4 typedef long unsigned int size_t; # 35 "/usr/include/stdio.h" 2 3 4 # 1 "/usr/include/bits/types.h" 1 3 4 # 28 "/usr/include/bits/types.h" 3 4 # 1 "/usr/include/bits/wordsize.h" 1 3 4 # 29 "/usr/include/bits/types.h" 2 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 32 "/usr/include/bits/types.h" 2 3 4 typedef unsigned char __u_char; typedef unsigned short int __u_short; typedef unsigned int __u_int; typedef unsigned long int __u_long; typedef signed char __int8_t; typedef unsigned char __uint8_t; typedef signed short int __int16_t; typedef unsigned short int __uint16_t; typedef signed int __int32_t; typedef unsigned int __uint32_t; typedef signed long int __int64_t; typedef unsigned long int __uint64_t; typedef long int __quad_t; typedef unsigned long int __u_quad_t; # 134 "/usr/include/bits/types.h" 3 4 # 1 "/usr/include/bits/typesizes.h" 1 3 4 # 135 "/usr/include/bits/types.h" 2 3 4 typedef unsigned long int __dev_t; typedef unsigned int __uid_t; typedef unsigned int __gid_t; typedef unsigned long int __ino_t; typedef unsigned long int __ino64_t; typedef unsigned int __mode_t; typedef unsigned long int __nlink_t; typedef long int __off_t; typedef long int __off64_t; typedef int __pid_t; typedef struct { int __val[2]; } __fsid_t; typedef long int __clock_t; typedef unsigned long int __rlim_t; typedef unsigned long int __rlim64_t; typedef unsigned int __id_t; typedef long int __time_t; typedef unsigned int __useconds_t; typedef long int __suseconds_t; typedef int __daddr_t; typedef long int __swblk_t; typedef int __key_t; typedef int __clockid_t; typedef void * __timer_t; typedef long int __blksize_t; typedef long int __blkcnt_t; typedef long int __blkcnt64_t; typedef unsigned long int __fsblkcnt_t; typedef unsigned long int __fsblkcnt64_t; typedef unsigned long int __fsfilcnt_t; typedef unsigned long int __fsfilcnt64_t; typedef long int __ssize_t; typedef __off64_t __loff_t; typedef __quad_t *__qaddr_t; typedef char *__caddr_t; typedef long int __intptr_t; typedef unsigned int __socklen_t; # 37 "/usr/include/stdio.h" 2 3 4 typedef struct _IO_FILE FILE; # 62 "/usr/include/stdio.h" 3 4 typedef struct _IO_FILE __FILE; # 72 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/libio.h" 1 3 4 # 32 "/usr/include/libio.h" 3 4 # 1 "/usr/include/_G_config.h" 1 3 4 # 14 "/usr/include/_G_config.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 326 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 3 4 typedef int wchar_t; # 355 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 3 4 typedef unsigned int wint_t; # 15 "/usr/include/_G_config.h" 2 3 4 # 24 "/usr/include/_G_config.h" 3 4 # 1 "/usr/include/wchar.h" 1 3 4 # 48 "/usr/include/wchar.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 49 "/usr/include/wchar.h" 2 3 4 # 1 "/usr/include/bits/wchar.h" 1 3 4 # 51 "/usr/include/wchar.h" 2 3 4 # 76 "/usr/include/wchar.h" 3 4 typedef struct { int __count; union { wint_t __wch; char __wchb[4]; } __value; } __mbstate_t; # 25 "/usr/include/_G_config.h" 2 3 4 typedef struct { __off_t __pos; __mbstate_t __state; } _G_fpos_t; typedef struct { __off64_t __pos; __mbstate_t __state; } _G_fpos64_t; # 44 "/usr/include/_G_config.h" 3 4 # 1 "/usr/include/gconv.h" 1 3 4 # 28 "/usr/include/gconv.h" 3 4 # 1 "/usr/include/wchar.h" 1 3 4 # 48 "/usr/include/wchar.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 49 "/usr/include/wchar.h" 2 3 4 # 29 "/usr/include/gconv.h" 2 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 32 "/usr/include/gconv.h" 2 3 4 enum { __GCONV_OK = 0, __GCONV_NOCONV, __GCONV_NODB, __GCONV_NOMEM, __GCONV_EMPTY_INPUT, __GCONV_FULL_OUTPUT, __GCONV_ILLEGAL_INPUT, __GCONV_INCOMPLETE_INPUT, __GCONV_ILLEGAL_DESCRIPTOR, __GCONV_INTERNAL_ERROR }; enum { __GCONV_IS_LAST = 0x0001, __GCONV_IGNORE_ERRORS = 0x0002 }; struct __gconv_step; struct __gconv_step_data; struct __gconv_loaded_object; struct __gconv_trans_data; typedef int (*__gconv_fct) (struct __gconv_step *, struct __gconv_step_data *, __const unsigned char **, __const unsigned char *, unsigned char **, size_t *, int, int); typedef wint_t (*__gconv_btowc_fct) (struct __gconv_step *, unsigned char); typedef int (*__gconv_init_fct) (struct __gconv_step *); typedef void (*__gconv_end_fct) (struct __gconv_step *); typedef int (*__gconv_trans_fct) (struct __gconv_step *, struct __gconv_step_data *, void *, __const unsigned char *, __const unsigned char **, __const unsigned char *, unsigned char **, size_t *); typedef int (*__gconv_trans_context_fct) (void *, __const unsigned char *, __const unsigned char *, unsigned char *, unsigned char *); typedef int (*__gconv_trans_query_fct) (__const char *, __const char ***, size_t *); typedef int (*__gconv_trans_init_fct) (void **, const char *); typedef void (*__gconv_trans_end_fct) (void *); struct __gconv_trans_data { __gconv_trans_fct __trans_fct; __gconv_trans_context_fct __trans_context_fct; __gconv_trans_end_fct __trans_end_fct; void *__data; struct __gconv_trans_data *__next; }; struct __gconv_step { struct __gconv_loaded_object *__shlib_handle; __const char *__modname; int __counter; char *__from_name; char *__to_name; __gconv_fct __fct; __gconv_btowc_fct __btowc_fct; __gconv_init_fct __init_fct; __gconv_end_fct __end_fct; int __min_needed_from; int __max_needed_from; int __min_needed_to; int __max_needed_to; int __stateful; void *__data; }; struct __gconv_step_data { unsigned char *__outbuf; unsigned char *__outbufend; int __flags; int __invocation_counter; int __internal_use; __mbstate_t *__statep; __mbstate_t __state; struct __gconv_trans_data *__trans; }; typedef struct __gconv_info { size_t __nsteps; struct __gconv_step *__steps; __extension__ struct __gconv_step_data __data []; } *__gconv_t; # 45 "/usr/include/_G_config.h" 2 3 4 typedef union { struct __gconv_info __cd; struct { struct __gconv_info __cd; struct __gconv_step_data __data; } __combined; } _G_iconv_t; typedef int _G_int16_t __attribute__ ((__mode__ (__HI__))); typedef int _G_int32_t __attribute__ ((__mode__ (__SI__))); typedef unsigned int _G_uint16_t __attribute__ ((__mode__ (__HI__))); typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__))); # 33 "/usr/include/libio.h" 2 3 4 # 53 "/usr/include/libio.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stdarg.h" 1 3 4 # 43 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stdarg.h" 3 4 typedef __builtin_va_list __gnuc_va_list; # 54 "/usr/include/libio.h" 2 3 4 # 167 "/usr/include/libio.h" 3 4 struct _IO_jump_t; struct _IO_FILE; # 177 "/usr/include/libio.h" 3 4 typedef void _IO_lock_t; struct _IO_marker { struct _IO_marker *_next; struct _IO_FILE *_sbuf; int _pos; # 200 "/usr/include/libio.h" 3 4 }; enum __codecvt_result { __codecvt_ok, __codecvt_partial, __codecvt_error, __codecvt_noconv }; # 268 "/usr/include/libio.h" 3 4 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; # 316 "/usr/include/libio.h" 3 4 __off64_t _offset; # 325 "/usr/include/libio.h" 3 4 void *__pad1; void *__pad2; void *__pad3; void *__pad4; size_t __pad5; int _mode; char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]; }; typedef struct _IO_FILE _IO_FILE; struct _IO_FILE_plus; extern struct _IO_FILE_plus _IO_2_1_stdin_; extern struct _IO_FILE_plus _IO_2_1_stdout_; extern struct _IO_FILE_plus _IO_2_1_stderr_; # 361 "/usr/include/libio.h" 3 4 typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes); typedef __ssize_t __io_write_fn (void *__cookie, __const char *__buf, size_t __n); typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w); typedef int __io_close_fn (void *__cookie); # 413 "/usr/include/libio.h" 3 4 extern int __underflow (_IO_FILE *); extern int __uflow (_IO_FILE *); extern int __overflow (_IO_FILE *, int); extern wint_t __wunderflow (_IO_FILE *); extern wint_t __wuflow (_IO_FILE *); extern wint_t __woverflow (_IO_FILE *, wint_t); # 451 "/usr/include/libio.h" 3 4 extern int _IO_getc (_IO_FILE *__fp); extern int _IO_putc (int __c, _IO_FILE *__fp); extern int _IO_feof (_IO_FILE *__fp) __attribute__ ((__nothrow__)); extern int _IO_ferror (_IO_FILE *__fp) __attribute__ ((__nothrow__)); extern int _IO_peekc_locked (_IO_FILE *__fp); extern void _IO_flockfile (_IO_FILE *) __attribute__ ((__nothrow__)); extern void _IO_funlockfile (_IO_FILE *) __attribute__ ((__nothrow__)); extern int _IO_ftrylockfile (_IO_FILE *) __attribute__ ((__nothrow__)); # 481 "/usr/include/libio.h" 3 4 extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict, __gnuc_va_list, int *__restrict); extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict, __gnuc_va_list); extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t); extern size_t _IO_sgetn (_IO_FILE *, void *, size_t); extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int); extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int); extern void _IO_free_backup_area (_IO_FILE *) __attribute__ ((__nothrow__)); # 73 "/usr/include/stdio.h" 2 3 4 # 86 "/usr/include/stdio.h" 3 4 typedef _G_fpos_t fpos_t; # 138 "/usr/include/stdio.h" 3 4 # 1 "/usr/include/bits/stdio_lim.h" 1 3 4 # 139 "/usr/include/stdio.h" 2 3 4 extern struct _IO_FILE *stdin; extern struct _IO_FILE *stdout; extern struct _IO_FILE *stderr; extern int remove (__const char *__filename) __attribute__ ((__nothrow__)); extern int rename (__const char *__old, __const char *__new) __attribute__ ((__nothrow__)); extern FILE *tmpfile (void); # 185 "/usr/include/stdio.h" 3 4 extern char *tmpnam (char *__s) __attribute__ ((__nothrow__)); extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__)); # 203 "/usr/include/stdio.h" 3 4 extern char *tempnam (__const char *__dir, __const char *__pfx) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)); extern int fclose (FILE *__stream); extern int fflush (FILE *__stream); # 228 "/usr/include/stdio.h" 3 4 extern int fflush_unlocked (FILE *__stream); # 242 "/usr/include/stdio.h" 3 4 extern FILE *fopen (__const char *__restrict __filename, __const char *__restrict __modes); extern FILE *freopen (__const char *__restrict __filename, __const char *__restrict __modes, FILE *__restrict __stream); # 269 "/usr/include/stdio.h" 3 4 # 280 "/usr/include/stdio.h" 3 4 extern FILE *fdopen (int __fd, __const char *__modes) __attribute__ ((__nothrow__)); # 300 "/usr/include/stdio.h" 3 4 extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__)); extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf, int __modes, size_t __n) __attribute__ ((__nothrow__)); extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf, size_t __size) __attribute__ ((__nothrow__)); extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__)); extern int fprintf (FILE *__restrict __stream, __const char *__restrict __format, ...); extern int printf (__const char *__restrict __format, ...); extern int sprintf (char *__restrict __s, __const char *__restrict __format, ...) __attribute__ ((__nothrow__)); extern int vfprintf (FILE *__restrict __s, __const char *__restrict __format, __gnuc_va_list __arg); extern int vprintf (__const char *__restrict __format, __gnuc_va_list __arg); extern int vsprintf (char *__restrict __s, __const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__nothrow__)); extern int snprintf (char *__restrict __s, size_t __maxlen, __const char *__restrict __format, ...) __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4))); extern int vsnprintf (char *__restrict __s, size_t __maxlen, __const char *__restrict __format, __gnuc_va_list __arg) __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0))); # 394 "/usr/include/stdio.h" 3 4 extern int fscanf (FILE *__restrict __stream, __const char *__restrict __format, ...) ; extern int scanf (__const char *__restrict __format, ...) ; extern int sscanf (__const char *__restrict __s, __const char *__restrict __format, ...) __attribute__ ((__nothrow__)); # 436 "/usr/include/stdio.h" 3 4 extern int fgetc (FILE *__stream); extern int getc (FILE *__stream); extern int getchar (void); # 460 "/usr/include/stdio.h" 3 4 extern int getc_unlocked (FILE *__stream); extern int getchar_unlocked (void); # 471 "/usr/include/stdio.h" 3 4 extern int fgetc_unlocked (FILE *__stream); extern int fputc (int __c, FILE *__stream); extern int putc (int __c, FILE *__stream); extern int putchar (int __c); # 504 "/usr/include/stdio.h" 3 4 extern int fputc_unlocked (int __c, FILE *__stream); extern int putc_unlocked (int __c, FILE *__stream); extern int putchar_unlocked (int __c); extern int getw (FILE *__stream); extern int putw (int __w, FILE *__stream); extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) ; extern char *gets (char *__s) ; # 585 "/usr/include/stdio.h" 3 4 extern int fputs (__const char *__restrict __s, FILE *__restrict __stream); extern int puts (__const char *__s); extern int ungetc (int __c, FILE *__stream); extern size_t fread (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) ; extern size_t fwrite (__const void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __s) ; # 638 "/usr/include/stdio.h" 3 4 extern size_t fread_unlocked (void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) ; extern size_t fwrite_unlocked (__const void *__restrict __ptr, size_t __size, size_t __n, FILE *__restrict __stream) ; extern int fseek (FILE *__stream, long int __off, int __whence); extern long int ftell (FILE *__stream) ; extern void rewind (FILE *__stream); # 674 "/usr/include/stdio.h" 3 4 extern int fseeko (FILE *__stream, __off_t __off, int __whence); extern __off_t ftello (FILE *__stream) ; # 693 "/usr/include/stdio.h" 3 4 extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos); extern int fsetpos (FILE *__stream, __const fpos_t *__pos); # 716 "/usr/include/stdio.h" 3 4 # 725 "/usr/include/stdio.h" 3 4 extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__)); extern int feof (FILE *__stream) __attribute__ ((__nothrow__)) ; extern int ferror (FILE *__stream) __attribute__ ((__nothrow__)) ; extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__)); extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__)) ; extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__)) ; extern void perror (__const char *__s); # 1 "/usr/include/bits/sys_errlist.h" 1 3 4 # 27 "/usr/include/bits/sys_errlist.h" 3 4 extern int sys_nerr; extern __const char *__const sys_errlist[]; # 755 "/usr/include/stdio.h" 2 3 4 extern int fileno (FILE *__stream) __attribute__ ((__nothrow__)) ; extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__)) ; # 774 "/usr/include/stdio.h" 3 4 extern FILE *popen (__const char *__command, __const char *__modes) ; extern int pclose (FILE *__stream); extern char *ctermid (char *__s) __attribute__ ((__nothrow__)); # 814 "/usr/include/stdio.h" 3 4 extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__)); extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__)) ; extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__)); # 844 "/usr/include/stdio.h" 3 4 # 2 "reorder_bad.c" 2 # 1 "/usr/include/stdlib.h" 1 3 4 # 33 "/usr/include/stdlib.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 34 "/usr/include/stdlib.h" 2 3 4 # 96 "/usr/include/stdlib.h" 3 4 typedef struct { int quot; int rem; } div_t; typedef struct { long int quot; long int rem; } ldiv_t; # 140 "/usr/include/stdlib.h" 3 4 extern size_t __ctype_get_mb_cur_max (void) __attribute__ ((__nothrow__)) ; extern double atof (__const char *__nptr) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; extern int atoi (__const char *__nptr) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; extern long int atol (__const char *__nptr) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern long long int atoll (__const char *__nptr) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; extern double strtod (__const char *__restrict __nptr, char **__restrict __endptr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; # 182 "/usr/include/stdlib.h" 3 4 extern long int strtol (__const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern unsigned long int strtoul (__const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern long long int strtoq (__const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern unsigned long long int strtouq (__const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern long long int strtoll (__const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern unsigned long long int strtoull (__const char *__restrict __nptr, char **__restrict __endptr, int __base) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; # 279 "/usr/include/stdlib.h" 3 4 extern double __strtod_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern float __strtof_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern long double __strtold_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern long int __strtol_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern unsigned long int __strtoul_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern long long int __strtoll_internal (__const char *__restrict __nptr, char **__restrict __endptr, int __base, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; __extension__ extern unsigned long long int __strtoull_internal (__const char * __restrict __nptr, char **__restrict __endptr, int __base, int __group) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; # 429 "/usr/include/stdlib.h" 3 4 extern char *l64a (long int __n) __attribute__ ((__nothrow__)) ; extern long int a64l (__const char *__s) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))) ; # 1 "/usr/include/sys/types.h" 1 3 4 # 29 "/usr/include/sys/types.h" 3 4 typedef __u_char u_char; typedef __u_short u_short; typedef __u_int u_int; typedef __u_long u_long; typedef __quad_t quad_t; typedef __u_quad_t u_quad_t; typedef __fsid_t fsid_t; typedef __loff_t loff_t; typedef __ino_t ino_t; # 62 "/usr/include/sys/types.h" 3 4 typedef __dev_t dev_t; typedef __gid_t gid_t; typedef __mode_t mode_t; typedef __nlink_t nlink_t; typedef __uid_t uid_t; typedef __off_t off_t; # 100 "/usr/include/sys/types.h" 3 4 typedef __pid_t pid_t; typedef __id_t id_t; typedef __ssize_t ssize_t; typedef __daddr_t daddr_t; typedef __caddr_t caddr_t; typedef __key_t key_t; # 133 "/usr/include/sys/types.h" 3 4 # 1 "/usr/include/time.h" 1 3 4 # 75 "/usr/include/time.h" 3 4 typedef __time_t time_t; # 93 "/usr/include/time.h" 3 4 typedef __clockid_t clockid_t; # 105 "/usr/include/time.h" 3 4 typedef __timer_t timer_t; # 134 "/usr/include/sys/types.h" 2 3 4 # 147 "/usr/include/sys/types.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 148 "/usr/include/sys/types.h" 2 3 4 typedef unsigned long int ulong; typedef unsigned short int ushort; typedef unsigned int uint; # 195 "/usr/include/sys/types.h" 3 4 typedef int int8_t __attribute__ ((__mode__ (__QI__))); typedef int int16_t __attribute__ ((__mode__ (__HI__))); typedef int int32_t __attribute__ ((__mode__ (__SI__))); typedef int int64_t __attribute__ ((__mode__ (__DI__))); typedef unsigned int u_int8_t __attribute__ ((__mode__ (__QI__))); typedef unsigned int u_int16_t __attribute__ ((__mode__ (__HI__))); typedef unsigned int u_int32_t __attribute__ ((__mode__ (__SI__))); typedef unsigned int u_int64_t __attribute__ ((__mode__ (__DI__))); typedef int register_t __attribute__ ((__mode__ (__word__))); # 217 "/usr/include/sys/types.h" 3 4 # 1 "/usr/include/endian.h" 1 3 4 # 37 "/usr/include/endian.h" 3 4 # 1 "/usr/include/bits/endian.h" 1 3 4 # 38 "/usr/include/endian.h" 2 3 4 # 218 "/usr/include/sys/types.h" 2 3 4 # 1 "/usr/include/sys/select.h" 1 3 4 # 31 "/usr/include/sys/select.h" 3 4 # 1 "/usr/include/bits/select.h" 1 3 4 # 32 "/usr/include/sys/select.h" 2 3 4 # 1 "/usr/include/bits/sigset.h" 1 3 4 # 23 "/usr/include/bits/sigset.h" 3 4 typedef int __sig_atomic_t; typedef struct { unsigned long int __val[(1024 / (8 * sizeof (unsigned long int)))]; } __sigset_t; # 35 "/usr/include/sys/select.h" 2 3 4 typedef __sigset_t sigset_t; # 1 "/usr/include/time.h" 1 3 4 # 121 "/usr/include/time.h" 3 4 struct timespec { __time_t tv_sec; long int tv_nsec; }; # 45 "/usr/include/sys/select.h" 2 3 4 # 1 "/usr/include/bits/time.h" 1 3 4 # 69 "/usr/include/bits/time.h" 3 4 struct timeval { __time_t tv_sec; __suseconds_t tv_usec; }; # 47 "/usr/include/sys/select.h" 2 3 4 typedef __suseconds_t suseconds_t; typedef long int __fd_mask; # 67 "/usr/include/sys/select.h" 3 4 typedef struct { __fd_mask __fds_bits[1024 / (8 * sizeof (__fd_mask))]; } fd_set; typedef __fd_mask fd_mask; # 99 "/usr/include/sys/select.h" 3 4 # 109 "/usr/include/sys/select.h" 3 4 extern int select (int __nfds, fd_set *__restrict __readfds, fd_set *__restrict __writefds, fd_set *__restrict __exceptfds, struct timeval *__restrict __timeout); # 121 "/usr/include/sys/select.h" 3 4 extern int pselect (int __nfds, fd_set *__restrict __readfds, fd_set *__restrict __writefds, fd_set *__restrict __exceptfds, const struct timespec *__restrict __timeout, const __sigset_t *__restrict __sigmask); # 221 "/usr/include/sys/types.h" 2 3 4 # 1 "/usr/include/sys/sysmacros.h" 1 3 4 # 29 "/usr/include/sys/sysmacros.h" 3 4 __extension__ extern __inline unsigned int gnu_dev_major (unsigned long long int __dev) __attribute__ ((__nothrow__)); __extension__ extern __inline unsigned int gnu_dev_minor (unsigned long long int __dev) __attribute__ ((__nothrow__)); __extension__ extern __inline unsigned long long int gnu_dev_makedev (unsigned int __major, unsigned int __minor) __attribute__ ((__nothrow__)); __extension__ extern __inline unsigned int __attribute__ ((__nothrow__)) gnu_dev_major (unsigned long long int __dev) { return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff); } __extension__ extern __inline unsigned int __attribute__ ((__nothrow__)) gnu_dev_minor (unsigned long long int __dev) { return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff); } __extension__ extern __inline unsigned long long int __attribute__ ((__nothrow__)) gnu_dev_makedev (unsigned int __major, unsigned int __minor) { return ((__minor & 0xff) | ((__major & 0xfff) << 8) | (((unsigned long long int) (__minor & ~0xff)) << 12) | (((unsigned long long int) (__major & ~0xfff)) << 32)); } # 224 "/usr/include/sys/types.h" 2 3 4 # 235 "/usr/include/sys/types.h" 3 4 typedef __blkcnt_t blkcnt_t; typedef __fsblkcnt_t fsblkcnt_t; typedef __fsfilcnt_t fsfilcnt_t; # 270 "/usr/include/sys/types.h" 3 4 # 1 "/usr/include/bits/pthreadtypes.h" 1 3 4 # 23 "/usr/include/bits/pthreadtypes.h" 3 4 # 1 "/usr/include/bits/wordsize.h" 1 3 4 # 24 "/usr/include/bits/pthreadtypes.h" 2 3 4 # 50 "/usr/include/bits/pthreadtypes.h" 3 4 typedef unsigned long int pthread_t; typedef union { char __size[56]; long int __align; } pthread_attr_t; typedef struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __pthread_list_t; # 76 "/usr/include/bits/pthreadtypes.h" 3 4 typedef union { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; int __spins; __pthread_list_t __list; # 101 "/usr/include/bits/pthreadtypes.h" 3 4 } __data; char __size[40]; long int __align; } pthread_mutex_t; typedef union { char __size[4]; int __align; } pthread_mutexattr_t; typedef union { struct { int __lock; unsigned int __futex; __extension__ unsigned long long int __total_seq; __extension__ unsigned long long int __wakeup_seq; __extension__ unsigned long long int __woken_seq; void *__mutex; unsigned int __nwaiters; unsigned int __broadcast_seq; } __data; char __size[48]; __extension__ long long int __align; } pthread_cond_t; typedef union { char __size[4]; int __align; } pthread_condattr_t; typedef unsigned int pthread_key_t; typedef int pthread_once_t; typedef union { struct { int __lock; unsigned int __nr_readers; unsigned int __readers_wakeup; unsigned int __writer_wakeup; unsigned int __nr_readers_queued; unsigned int __nr_writers_queued; int __writer; int __pad1; unsigned long int __pad2; unsigned long int __pad3; unsigned int __flags; } __data; # 184 "/usr/include/bits/pthreadtypes.h" 3 4 char __size[56]; long int __align; } pthread_rwlock_t; typedef union { char __size[8]; long int __align; } pthread_rwlockattr_t; typedef volatile int pthread_spinlock_t; typedef union { char __size[32]; long int __align; } pthread_barrier_t; typedef union { char __size[4]; int __align; } pthread_barrierattr_t; # 271 "/usr/include/sys/types.h" 2 3 4 # 439 "/usr/include/stdlib.h" 2 3 4 extern long int random (void) __attribute__ ((__nothrow__)); extern void srandom (unsigned int __seed) __attribute__ ((__nothrow__)); extern char *initstate (unsigned int __seed, char *__statebuf, size_t __statelen) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); extern char *setstate (char *__statebuf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); struct random_data { int32_t *fptr; int32_t *rptr; int32_t *state; int rand_type; int rand_deg; int rand_sep; int32_t *end_ptr; }; extern int random_r (struct random_data *__restrict __buf, int32_t *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int srandom_r (unsigned int __seed, struct random_data *__buf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); extern int initstate_r (unsigned int __seed, char *__restrict __statebuf, size_t __statelen, struct random_data *__restrict __buf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2, 4))); extern int setstate_r (char *__restrict __statebuf, struct random_data *__restrict __buf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int rand (void) __attribute__ ((__nothrow__)); extern void srand (unsigned int __seed) __attribute__ ((__nothrow__)); extern int rand_r (unsigned int *__seed) __attribute__ ((__nothrow__)); extern double drand48 (void) __attribute__ ((__nothrow__)); extern double erand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern long int lrand48 (void) __attribute__ ((__nothrow__)); extern long int nrand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern long int mrand48 (void) __attribute__ ((__nothrow__)); extern long int jrand48 (unsigned short int __xsubi[3]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern void srand48 (long int __seedval) __attribute__ ((__nothrow__)); extern unsigned short int *seed48 (unsigned short int __seed16v[3]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern void lcong48 (unsigned short int __param[7]) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); struct drand48_data { unsigned short int __x[3]; unsigned short int __old_x[3]; unsigned short int __c; unsigned short int __init; unsigned long long int __a; }; extern int drand48_r (struct drand48_data *__restrict __buffer, double *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int erand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, double *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int lrand48_r (struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int nrand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int mrand48_r (struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int jrand48_r (unsigned short int __xsubi[3], struct drand48_data *__restrict __buffer, long int *__restrict __result) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int srand48_r (long int __seedval, struct drand48_data *__buffer) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); extern int seed48_r (unsigned short int __seed16v[3], struct drand48_data *__buffer) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int lcong48_r (unsigned short int __param[7], struct drand48_data *__buffer) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern void *malloc (size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) ; extern void *calloc (size_t __nmemb, size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) ; extern void *realloc (void *__ptr, size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) __attribute__ ((__warn_unused_result__)); extern void free (void *__ptr) __attribute__ ((__nothrow__)); extern void cfree (void *__ptr) __attribute__ ((__nothrow__)); # 1 "/usr/include/alloca.h" 1 3 4 # 25 "/usr/include/alloca.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 26 "/usr/include/alloca.h" 2 3 4 extern void *alloca (size_t __size) __attribute__ ((__nothrow__)); # 613 "/usr/include/stdlib.h" 2 3 4 extern void *valloc (size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__malloc__)) ; extern int posix_memalign (void **__memptr, size_t __alignment, size_t __size) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern void abort (void) __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__)); extern int atexit (void (*__func) (void)) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int on_exit (void (*__func) (int __status, void *__arg), void *__arg) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern void exit (int __status) __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__)); # 658 "/usr/include/stdlib.h" 3 4 extern char *getenv (__const char *__name) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern char *__secure_getenv (__const char *__name) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern int putenv (char *__string) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int setenv (__const char *__name, __const char *__value, int __replace) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); extern int unsetenv (__const char *__name) __attribute__ ((__nothrow__)); extern int clearenv (void) __attribute__ ((__nothrow__)); # 698 "/usr/include/stdlib.h" 3 4 extern char *mktemp (char *__template) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; # 709 "/usr/include/stdlib.h" 3 4 extern int mkstemp (char *__template) __attribute__ ((__nonnull__ (1))) ; # 729 "/usr/include/stdlib.h" 3 4 extern char *mkdtemp (char *__template) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; extern int system (__const char *__command) ; # 756 "/usr/include/stdlib.h" 3 4 extern char *realpath (__const char *__restrict __name, char *__restrict __resolved) __attribute__ ((__nothrow__)) ; typedef int (*__compar_fn_t) (__const void *, __const void *); extern void *bsearch (__const void *__key, __const void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 2, 5))) ; extern void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t __compar) __attribute__ ((__nonnull__ (1, 4))); extern int abs (int __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)) ; extern long int labs (long int __x) __attribute__ ((__nothrow__)) __attribute__ ((__const__)) ; extern div_t div (int __numer, int __denom) __attribute__ ((__nothrow__)) __attribute__ ((__const__)) ; extern ldiv_t ldiv (long int __numer, long int __denom) __attribute__ ((__nothrow__)) __attribute__ ((__const__)) ; # 821 "/usr/include/stdlib.h" 3 4 extern char *ecvt (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4))) ; extern char *fcvt (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4))) ; extern char *gcvt (double __value, int __ndigit, char *__buf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3))) ; extern char *qecvt (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4))) ; extern char *qfcvt (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4))) ; extern char *qgcvt (long double __value, int __ndigit, char *__buf) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3))) ; extern int ecvt_r (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5))); extern int fcvt_r (double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5))); extern int qecvt_r (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5))); extern int qfcvt_r (long double __value, int __ndigit, int *__restrict __decpt, int *__restrict __sign, char *__restrict __buf, size_t __len) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3, 4, 5))); extern int mblen (__const char *__s, size_t __n) __attribute__ ((__nothrow__)) ; extern int mbtowc (wchar_t *__restrict __pwc, __const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__)) ; extern int wctomb (char *__s, wchar_t __wchar) __attribute__ ((__nothrow__)) ; extern size_t mbstowcs (wchar_t *__restrict __pwcs, __const char *__restrict __s, size_t __n) __attribute__ ((__nothrow__)); extern size_t wcstombs (char *__restrict __s, __const wchar_t *__restrict __pwcs, size_t __n) __attribute__ ((__nothrow__)); extern int rpmatch (__const char *__response) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) ; # 926 "/usr/include/stdlib.h" 3 4 extern int posix_openpt (int __oflag) ; # 961 "/usr/include/stdlib.h" 3 4 extern int getloadavg (double __loadavg[], int __nelem) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); # 977 "/usr/include/stdlib.h" 3 4 # 3 "reorder_bad.c" 2 # 1 "/usr/include/pthread.h" 1 3 4 # 23 "/usr/include/pthread.h" 3 4 # 1 "/usr/include/sched.h" 1 3 4 # 29 "/usr/include/sched.h" 3 4 # 1 "/usr/include/time.h" 1 3 4 # 30 "/usr/include/sched.h" 2 3 4 # 1 "/usr/include/bits/sched.h" 1 3 4 # 65 "/usr/include/bits/sched.h" 3 4 struct sched_param { int __sched_priority; }; extern int clone (int (*__fn) (void *__arg), void *__child_stack, int __flags, void *__arg, ...) __attribute__ ((__nothrow__)); extern int unshare (int __flags) __attribute__ ((__nothrow__)); struct __sched_param { int __sched_priority; }; # 104 "/usr/include/bits/sched.h" 3 4 typedef unsigned long int __cpu_mask; typedef struct { __cpu_mask __bits[1024 / (8 * sizeof (__cpu_mask))]; } cpu_set_t; # 33 "/usr/include/sched.h" 2 3 4 extern int sched_setparam (__pid_t __pid, __const struct sched_param *__param) __attribute__ ((__nothrow__)); extern int sched_getparam (__pid_t __pid, struct sched_param *__param) __attribute__ ((__nothrow__)); extern int sched_setscheduler (__pid_t __pid, int __policy, __const struct sched_param *__param) __attribute__ ((__nothrow__)); extern int sched_getscheduler (__pid_t __pid) __attribute__ ((__nothrow__)); extern int sched_yield (void) __attribute__ ((__nothrow__)); extern int sched_get_priority_max (int __algorithm) __attribute__ ((__nothrow__)); extern int sched_get_priority_min (int __algorithm) __attribute__ ((__nothrow__)); extern int sched_rr_get_interval (__pid_t __pid, struct timespec *__t) __attribute__ ((__nothrow__)); # 84 "/usr/include/sched.h" 3 4 # 24 "/usr/include/pthread.h" 2 3 4 # 1 "/usr/include/time.h" 1 3 4 # 31 "/usr/include/time.h" 3 4 # 1 "/usr/lib/gcc/x86_64-redhat-linux/4.1.2/include/stddef.h" 1 3 4 # 40 "/usr/include/time.h" 2 3 4 # 1 "/usr/include/bits/time.h" 1 3 4 # 44 "/usr/include/time.h" 2 3 4 # 59 "/usr/include/time.h" 3 4 typedef __clock_t clock_t; # 132 "/usr/include/time.h" 3 4 struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long int tm_gmtoff; __const char *tm_zone; }; struct itimerspec { struct timespec it_interval; struct timespec it_value; }; struct sigevent; # 181 "/usr/include/time.h" 3 4 extern clock_t clock (void) __attribute__ ((__nothrow__)); extern time_t time (time_t *__timer) __attribute__ ((__nothrow__)); extern double difftime (time_t __time1, time_t __time0) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern time_t mktime (struct tm *__tp) __attribute__ ((__nothrow__)); extern size_t strftime (char *__restrict __s, size_t __maxsize, __const char *__restrict __format, __const struct tm *__restrict __tp) __attribute__ ((__nothrow__)); # 229 "/usr/include/time.h" 3 4 extern struct tm *gmtime (__const time_t *__timer) __attribute__ ((__nothrow__)); extern struct tm *localtime (__const time_t *__timer) __attribute__ ((__nothrow__)); extern struct tm *gmtime_r (__const time_t *__restrict __timer, struct tm *__restrict __tp) __attribute__ ((__nothrow__)); extern struct tm *localtime_r (__const time_t *__restrict __timer, struct tm *__restrict __tp) __attribute__ ((__nothrow__)); extern char *asctime (__const struct tm *__tp) __attribute__ ((__nothrow__)); extern char *ctime (__const time_t *__timer) __attribute__ ((__nothrow__)); extern char *asctime_r (__const struct tm *__restrict __tp, char *__restrict __buf) __attribute__ ((__nothrow__)); extern char *ctime_r (__const time_t *__restrict __timer, char *__restrict __buf) __attribute__ ((__nothrow__)); extern char *__tzname[2]; extern int __daylight; extern long int __timezone; extern char *tzname[2]; extern void tzset (void) __attribute__ ((__nothrow__)); extern int daylight; extern long int timezone; extern int stime (__const time_t *__when) __attribute__ ((__nothrow__)); # 312 "/usr/include/time.h" 3 4 extern time_t timegm (struct tm *__tp) __attribute__ ((__nothrow__)); extern time_t timelocal (struct tm *__tp) __attribute__ ((__nothrow__)); extern int dysize (int __year) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); # 327 "/usr/include/time.h" 3 4 extern int nanosleep (__const struct timespec *__requested_time, struct timespec *__remaining); extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __attribute__ ((__nothrow__)); extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __attribute__ ((__nothrow__)); extern int clock_settime (clockid_t __clock_id, __const struct timespec *__tp) __attribute__ ((__nothrow__)); extern int clock_nanosleep (clockid_t __clock_id, int __flags, __const struct timespec *__req, struct timespec *__rem); extern int clock_getcpuclockid (pid_t __pid, clockid_t *__clock_id) __attribute__ ((__nothrow__)); extern int timer_create (clockid_t __clock_id, struct sigevent *__restrict __evp, timer_t *__restrict __timerid) __attribute__ ((__nothrow__)); extern int timer_delete (timer_t __timerid) __attribute__ ((__nothrow__)); extern int timer_settime (timer_t __timerid, int __flags, __const struct itimerspec *__restrict __value, struct itimerspec *__restrict __ovalue) __attribute__ ((__nothrow__)); extern int timer_gettime (timer_t __timerid, struct itimerspec *__value) __attribute__ ((__nothrow__)); extern int timer_getoverrun (timer_t __timerid) __attribute__ ((__nothrow__)); # 416 "/usr/include/time.h" 3 4 # 25 "/usr/include/pthread.h" 2 3 4 # 1 "/usr/include/signal.h" 1 3 4 # 31 "/usr/include/signal.h" 3 4 # 1 "/usr/include/bits/sigset.h" 1 3 4 # 34 "/usr/include/signal.h" 2 3 4 # 400 "/usr/include/signal.h" 3 4 # 28 "/usr/include/pthread.h" 2 3 4 # 1 "/usr/include/bits/setjmp.h" 1 3 4 # 27 "/usr/include/bits/setjmp.h" 3 4 # 1 "/usr/include/bits/wordsize.h" 1 3 4 # 28 "/usr/include/bits/setjmp.h" 2 3 4 typedef long int __jmp_buf[8]; # 30 "/usr/include/pthread.h" 2 3 4 # 1 "/usr/include/bits/wordsize.h" 1 3 4 # 31 "/usr/include/pthread.h" 2 3 4 enum { PTHREAD_CREATE_JOINABLE, PTHREAD_CREATE_DETACHED }; enum { PTHREAD_MUTEX_TIMED_NP, PTHREAD_MUTEX_RECURSIVE_NP, PTHREAD_MUTEX_ERRORCHECK_NP, PTHREAD_MUTEX_ADAPTIVE_NP # 61 "/usr/include/pthread.h" 3 4 }; # 113 "/usr/include/pthread.h" 3 4 enum { PTHREAD_RWLOCK_PREFER_READER_NP, PTHREAD_RWLOCK_PREFER_WRITER_NP, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, PTHREAD_RWLOCK_DEFAULT_NP = PTHREAD_RWLOCK_PREFER_READER_NP }; # 143 "/usr/include/pthread.h" 3 4 enum { PTHREAD_INHERIT_SCHED, PTHREAD_EXPLICIT_SCHED }; enum { PTHREAD_SCOPE_SYSTEM, PTHREAD_SCOPE_PROCESS }; enum { PTHREAD_PROCESS_PRIVATE, PTHREAD_PROCESS_SHARED }; # 178 "/usr/include/pthread.h" 3 4 struct _pthread_cleanup_buffer { void (*__routine) (void *); void *__arg; int __canceltype; struct _pthread_cleanup_buffer *__prev; }; enum { PTHREAD_CANCEL_ENABLE, PTHREAD_CANCEL_DISABLE }; enum { PTHREAD_CANCEL_DEFERRED, PTHREAD_CANCEL_ASYNCHRONOUS }; # 216 "/usr/include/pthread.h" 3 4 extern int pthread_create (pthread_t *__restrict __newthread, __const pthread_attr_t *__restrict __attr, void *(*__start_routine) (void *), void *__restrict __arg) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 3))); extern void pthread_exit (void *__retval) __attribute__ ((__noreturn__)); extern int pthread_join (pthread_t __th, void **__thread_return); # 259 "/usr/include/pthread.h" 3 4 extern int pthread_detach (pthread_t __th) __attribute__ ((__nothrow__)); extern pthread_t pthread_self (void) __attribute__ ((__nothrow__)) __attribute__ ((__const__)); extern int pthread_equal (pthread_t __thread1, pthread_t __thread2) __attribute__ ((__nothrow__)); extern int pthread_attr_init (pthread_attr_t *__attr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_attr_destroy (pthread_attr_t *__attr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_attr_getdetachstate (__const pthread_attr_t *__attr, int *__detachstate) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_attr_setdetachstate (pthread_attr_t *__attr, int __detachstate) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_attr_getguardsize (__const pthread_attr_t *__attr, size_t *__guardsize) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_attr_setguardsize (pthread_attr_t *__attr, size_t __guardsize) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_attr_getschedparam (__const pthread_attr_t *__restrict __attr, struct sched_param *__restrict __param) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_attr_setschedparam (pthread_attr_t *__restrict __attr, __const struct sched_param *__restrict __param) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_attr_getschedpolicy (__const pthread_attr_t *__restrict __attr, int *__restrict __policy) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_attr_setschedpolicy (pthread_attr_t *__attr, int __policy) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_attr_getinheritsched (__const pthread_attr_t *__restrict __attr, int *__restrict __inherit) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_attr_setinheritsched (pthread_attr_t *__attr, int __inherit) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_attr_getscope (__const pthread_attr_t *__restrict __attr, int *__restrict __scope) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_attr_setscope (pthread_attr_t *__attr, int __scope) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_attr_getstackaddr (__const pthread_attr_t *__restrict __attr, void **__restrict __stackaddr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))) __attribute__ ((__deprecated__)); extern int pthread_attr_setstackaddr (pthread_attr_t *__attr, void *__stackaddr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))) __attribute__ ((__deprecated__)); extern int pthread_attr_getstacksize (__const pthread_attr_t *__restrict __attr, size_t *__restrict __stacksize) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_attr_setstacksize (pthread_attr_t *__attr, size_t __stacksize) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_attr_getstack (__const pthread_attr_t *__restrict __attr, void **__restrict __stackaddr, size_t *__restrict __stacksize) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2, 3))); extern int pthread_attr_setstack (pthread_attr_t *__attr, void *__stackaddr, size_t __stacksize) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); # 409 "/usr/include/pthread.h" 3 4 extern int pthread_setschedparam (pthread_t __target_thread, int __policy, __const struct sched_param *__param) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (3))); extern int pthread_getschedparam (pthread_t __target_thread, int *__restrict __policy, struct sched_param *__restrict __param) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2, 3))); extern int pthread_setschedprio (pthread_t __target_thread, int __prio) __attribute__ ((__nothrow__)); # 462 "/usr/include/pthread.h" 3 4 extern int pthread_once (pthread_once_t *__once_control, void (*__init_routine) (void)) __attribute__ ((__nonnull__ (1, 2))); # 474 "/usr/include/pthread.h" 3 4 extern int pthread_setcancelstate (int __state, int *__oldstate); extern int pthread_setcanceltype (int __type, int *__oldtype); extern int pthread_cancel (pthread_t __th); extern void pthread_testcancel (void); typedef struct { struct { __jmp_buf __cancel_jmp_buf; int __mask_was_saved; } __cancel_jmp_buf[1]; void *__pad[4]; } __pthread_unwind_buf_t __attribute__ ((__aligned__)); # 508 "/usr/include/pthread.h" 3 4 struct __pthread_cleanup_frame { void (*__cancel_routine) (void *); void *__cancel_arg; int __do_it; int __cancel_type; }; # 648 "/usr/include/pthread.h" 3 4 extern void __pthread_register_cancel (__pthread_unwind_buf_t *__buf) ; # 659 "/usr/include/pthread.h" 3 4 extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf) ; # 699 "/usr/include/pthread.h" 3 4 extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf) __attribute__ ((__noreturn__)) __attribute__ ((__weak__)) ; struct __jmp_buf_tag; extern int __sigsetjmp (struct __jmp_buf_tag *__env, int __savemask) __attribute__ ((__nothrow__)); extern int pthread_mutex_init (pthread_mutex_t *__mutex, __const pthread_mutexattr_t *__mutexattr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_mutex_destroy (pthread_mutex_t *__mutex) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_mutex_trylock (pthread_mutex_t *__mutex) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_mutex_lock (pthread_mutex_t *__mutex) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex, __const struct timespec *__restrict __abstime) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_mutex_unlock (pthread_mutex_t *__mutex) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); # 770 "/usr/include/pthread.h" 3 4 extern int pthread_mutexattr_init (pthread_mutexattr_t *__attr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_mutexattr_destroy (pthread_mutexattr_t *__attr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_mutexattr_getpshared (__const pthread_mutexattr_t * __restrict __attr, int *__restrict __pshared) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_mutexattr_setpshared (pthread_mutexattr_t *__attr, int __pshared) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); # 842 "/usr/include/pthread.h" 3 4 extern int pthread_rwlock_init (pthread_rwlock_t *__restrict __rwlock, __const pthread_rwlockattr_t *__restrict __attr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_rwlock_destroy (pthread_rwlock_t *__rwlock) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_rwlock_rdlock (pthread_rwlock_t *__rwlock) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_rwlock_tryrdlock (pthread_rwlock_t *__rwlock) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock, __const struct timespec *__restrict __abstime) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_rwlock_trywrlock (pthread_rwlock_t *__rwlock) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock, __const struct timespec *__restrict __abstime) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_rwlockattr_init (pthread_rwlockattr_t *__attr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_rwlockattr_destroy (pthread_rwlockattr_t *__attr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_rwlockattr_getpshared (__const pthread_rwlockattr_t * __restrict __attr, int *__restrict __pshared) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_rwlockattr_setpshared (pthread_rwlockattr_t *__attr, int __pshared) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_rwlockattr_getkind_np (__const pthread_rwlockattr_t * __restrict __attr, int *__restrict __pref) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_rwlockattr_setkind_np (pthread_rwlockattr_t *__attr, int __pref) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_cond_init (pthread_cond_t *__restrict __cond, __const pthread_condattr_t *__restrict __cond_attr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_cond_destroy (pthread_cond_t *__cond) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_cond_signal (pthread_cond_t *__cond) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_cond_broadcast (pthread_cond_t *__cond) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_cond_wait (pthread_cond_t *__restrict __cond, pthread_mutex_t *__restrict __mutex) __attribute__ ((__nonnull__ (1, 2))); # 954 "/usr/include/pthread.h" 3 4 extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond, pthread_mutex_t *__restrict __mutex, __const struct timespec *__restrict __abstime) __attribute__ ((__nonnull__ (1, 2, 3))); extern int pthread_condattr_init (pthread_condattr_t *__attr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_condattr_destroy (pthread_condattr_t *__attr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_condattr_getpshared (__const pthread_condattr_t * __restrict __attr, int *__restrict __pshared) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_condattr_setpshared (pthread_condattr_t *__attr, int __pshared) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_condattr_getclock (__const pthread_condattr_t * __restrict __attr, __clockid_t *__restrict __clock_id) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_condattr_setclock (pthread_condattr_t *__attr, __clockid_t __clock_id) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); # 998 "/usr/include/pthread.h" 3 4 extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_spin_destroy (pthread_spinlock_t *__lock) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_spin_lock (pthread_spinlock_t *__lock) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_spin_trylock (pthread_spinlock_t *__lock) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_spin_unlock (pthread_spinlock_t *__lock) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_barrier_init (pthread_barrier_t *__restrict __barrier, __const pthread_barrierattr_t *__restrict __attr, unsigned int __count) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_barrier_destroy (pthread_barrier_t *__barrier) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_barrier_wait (pthread_barrier_t *__barrier) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_barrierattr_init (pthread_barrierattr_t *__attr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_barrierattr_destroy (pthread_barrierattr_t *__attr) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_barrierattr_getpshared (__const pthread_barrierattr_t * __restrict __attr, int *__restrict __pshared) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2))); extern int pthread_barrierattr_setpshared (pthread_barrierattr_t *__attr, int __pshared) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); # 1065 "/usr/include/pthread.h" 3 4 extern int pthread_key_create (pthread_key_t *__key, void (*__destr_function) (void *)) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1))); extern int pthread_key_delete (pthread_key_t __key) __attribute__ ((__nothrow__)); extern void *pthread_getspecific (pthread_key_t __key) __attribute__ ((__nothrow__)); extern int pthread_setspecific (pthread_key_t __key, __const void *__pointer) __attribute__ ((__nothrow__)) ; extern int pthread_getcpuclockid (pthread_t __thread_id, __clockid_t *__clock_id) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (2))); # 1099 "/usr/include/pthread.h" 3 4 extern int pthread_atfork (void (*__prepare) (void), void (*__parent) (void), void (*__child) (void)) __attribute__ ((__nothrow__)); # 1113 "/usr/include/pthread.h" 3 4 # 4 "reorder_bad.c" 2 static int iSet = 9; static int iCheck = 1; static int a = 0; static int b = 0; void __ESBMC_yield(); void *setThread(void *param); void *checkThread(void *param); void set(); int check(); int main(int argc, char *argv[]) { int i, err; if (argc != 1) { if (argc != 3) { fprintf(stderr, "./reorder <param1> <param2>\n"); exit(-1); } else { sscanf(argv[1], "%d", &iSet); sscanf(argv[2], "%d", &iCheck); } } pthread_t setPool[iSet]; pthread_t checkPool[iCheck]; for (i = 0; i < iSet; i++) { if (0 != (err = pthread_create(&setPool[i], ((void *)0), &setThread, ((void *)0)))) { fprintf(stderr, "Error [%d] found creating set thread.\n", err); exit(-1); } } for (i = 0; i < iCheck; i++) { if (0 != (err = pthread_create(&checkPool[i], ((void *)0), &checkThread, ((void *)0)))) { fprintf(stderr, "Error [%d] found creating check thread.\n", err); exit(-1); } } for (i = 0; i < iSet; i++) { if (0 != (err = pthread_join(setPool[i], ((void *)0)))) { fprintf(stderr, "pthread join error: %d\n", err); exit(-1); } } for (i = 0; i < iCheck; i++) { if (0 != (err = pthread_join(checkPool[i], ((void *)0)))) { fprintf(stderr, "pthread join error: %d\n", err); exit(-1); } } return 0; } void *setThread(void *param) { a = 1; b = -1; return ((void *)0); } void *checkThread(void *param) { if (! ((a == 0 && b == 0) || (a == 1 && b == -1))) { fprintf(stderr, "Bug found!\n"); assert(0); } return ((void *)0); }
the_stack_data/211079415.c
#define _POSIX_C_SOURCE 199309L //required for clock #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <wait.h> #include <limits.h> #include <fcntl.h> #include <time.h> #include <pthread.h> #include <inttypes.h> #include <math.h> void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; } int * shareMem(size_t size){ key_t mem_key = IPC_PRIVATE; int shm_id = shmget(mem_key, size, IPC_CREAT | 0666); return (int*)shmat(shm_id, NULL, 0); } void merge(int *arr, int low, int high){ int mid = low+(high-low)/2; int n1 = mid-low+1, n2 = high-mid; int L[n1], R[n2]; for (int i = 0; i < n1; i++) L[i]=arr[i+low]; for (int i = 0; i < n2; i++) R[i]=arr[i+mid+1]; int i=0,j=0,c=low; while (i<n1 && j<n2) { if (L[i] <= R[j]) arr[c++] = L[i++]; else arr[c++] = R[j++]; } while(i<n1) arr[c++] = L[i++]; while(j<n2) arr[c++] = R[j++]; } void normal_mergeSort(int *arr, int low, int high){ if (low >= high) return; int mid = low+(high-low)/2; normal_mergeSort(arr, low, mid); normal_mergeSort(arr, mid+1, high); merge(arr,low,high); } void mergeSort(int *arr, int low, int high){ if (low>=high) _exit(1); // selection sort if (high-low+1 < 5) { for (int i = low; i <= high-1; i++) { int mini = i; for (int j = i+1; j <= high; j++) if (arr[j]<arr[mini]) mini = j; swap(&arr[i], &arr[mini]); } return; } int mid = low+(high-low)/2; int pid1=fork(); if (pid1==0) { mergeSort(arr,low,mid); _exit(1); } else { int pid2=fork(); if (pid2==0) { mergeSort(arr,mid+1,high); _exit(1); } else { int status; waitpid(pid1,&status,0); waitpid(pid2,&status,0); } } merge(arr,low,high); return; } struct arg{ int l; int r; int* arr; }; void *threaded_mergeSort(void* a){ //note that we are passing a struct to the threads for simplicity. struct arg *args = (struct arg*) a; int l = args->l; int r = args->r; int *arr = args->arr; if(l>r) return NULL; int m = l+(r-l)/2; // selection sort if (r-l+1 < 5) { for (int i = l; i <= r-1; i++) { int mini = i; for (int j = i+1; j <= r; j++) if (arr[j]<arr[mini]) mini = j; swap(&arr[i], &arr[mini]); } return NULL; } //sort left half array struct arg a1; a1.l = l; a1.r = m; a1.arr = arr; pthread_t tid1; pthread_create(&tid1, NULL, threaded_mergeSort, &a1); //sort right half array struct arg a2; a2.l = m+1; a2.r = r; a2.arr = arr; pthread_t tid2; pthread_create(&tid2, NULL, threaded_mergeSort, &a2); //wait for the two halves to get sorted pthread_join(tid1, NULL); pthread_join(tid2, NULL); merge(arr,l,r); } void runSorts(long long int n){ struct timespec ts; printf("Enter the array: \n"); //getting shared memory int *arr = shareMem(sizeof(int)*(n+1)); for(int i=0;i<n;i++) scanf("%d", arr+i); int brr[n+1], crr[n+1]; for(int i=0;i<n;i++) { brr[i] = arr[i]; crr[i] = arr[i]; } printf("Running concurrent_mergesort for n = %lld\n", n); clock_gettime(CLOCK_MONOTONIC_RAW, &ts); long double st = ts.tv_nsec/(1e9)+ts.tv_sec; //multiprocess mergesort ( sorts arr[] )------------------------------------------------------------ mergeSort(arr, 0, n-1); for(int i=0; i<n; i++){ printf("%d ",arr[i]); } printf("\n"); clock_gettime(CLOCK_MONOTONIC_RAW, &ts); long double en = ts.tv_nsec/(1e9)+ts.tv_sec; printf("time = %Lf\n", en - st); long double t1 = en-st; pthread_t tid; struct arg a; a.l = 0; a.r = n-1; a.arr = brr; printf("Running threaded_concurrent_mergesort for n = %lld\n", n); clock_gettime(CLOCK_MONOTONIC_RAW, &ts); st = ts.tv_nsec/(1e9)+ts.tv_sec; //multithreaded mergesort ( sorts brr[] )---------------------------------------------------------- pthread_create(&tid, NULL, threaded_mergeSort, &a); pthread_join(tid, NULL); for(int i=0; i<n; i++){ printf("%d ",a.arr[i]); } printf("\n"); clock_gettime(CLOCK_MONOTONIC_RAW, &ts); en = ts.tv_nsec/(1e9)+ts.tv_sec; printf("time = %Lf\n", en - st); long double t2 = en-st; printf("Running normal_mergesort for n = %lld\n", n); clock_gettime(CLOCK_MONOTONIC_RAW, &ts); st = ts.tv_nsec/(1e9)+ts.tv_sec; // normal mergesort ( sorts crr[] )---------------------------------------------------------------- normal_mergeSort(crr, 0, n-1); for(int i=0; i<n; i++){ printf("%d ",crr[i]); } printf("\n"); clock_gettime(CLOCK_MONOTONIC_RAW, &ts); en = ts.tv_nsec/(1e9)+ts.tv_sec; printf("time = %Lf\n", en - st); long double t3 = en - st; printf("normal_mergesort ran:\n\t[ %Lf ] times faster than concurrent_mergesort\n\t[ %Lf ] times faster than threaded_concurrent_mergesort\n\n\n", t1/t3, t2/t3); shmdt(arr); return; } int main(){ long long int n; printf("Enter size of array to be sorted: "); scanf("%lld", &n); runSorts(n); return 0; }
the_stack_data/842168.c
struct S { int x; }; extern struct S *s; void f() { s->x = 5; }
the_stack_data/243893131.c
#include <stdio.h> #include <malloc.h> #include <stdlib.h> // ---- #define MAXWIDTH 1000 #define MAXHEIGHT 1000 typedef struct { unsigned char r; unsigned char g; unsigned char b; } color; typedef struct { long height; long width; color data[MAXHEIGHT][MAXWIDTH]; } img; // ---- WriteBmp ---- static void WrUI(FILE *fp, unsigned int value) { fputc((value >> 0) & 0xff, fp); fputc((value >> 8) & 0xff, fp); fputc((value >> 16) & 0xff, fp); fputc((value >> 24) & 0xff, fp); } void WriteBmp(char *filename, img *tp) { FILE *fp = fopen(filename, "wb"); unsigned int szimg; int x; int y; if(!fp) return; // open error ! szimg = ((tp->width * 3 + 3) / 4) * 4 * tp->height; fputc('B', fp); fputc('M', fp); WrUI(fp, szimg + 0x36); WrUI(fp, 0); WrUI(fp, 0x36); WrUI(fp, 0x28); WrUI(fp, tp->width); WrUI(fp, tp->height); WrUI(fp, 0x00180001); WrUI(fp, 0); WrUI(fp, szimg); WrUI(fp, 0); WrUI(fp, 0); WrUI(fp, 0); WrUI(fp, 0); for(y = tp->height - 1; 0 <= y; y--) { for(x = 0; x < tp->width; x++) { color *col = tp->data[y] + x; fputc(col->b, fp); fputc(col->g, fp); fputc(col->r, fp); } for(x = tp->width % 4; x; x--) { fputc(0x00, fp); } } fclose(fp); } // ---- int main(int argc, char **argv) { int i,j; img *tmp1,*tmp2; tmp1=(img *)malloc(sizeof(img)); tmp2=(img *)malloc(sizeof(img)); // char *filename = argv[1]; #if 1 tmp1->height = 200; tmp1->width = 300; for(i=0;i<tmp1->height;i++) for(j=0;j<tmp1->width;j++) { tmp1->data[i][j].r = rand()%256; tmp1->data[i][j].g = rand()%256; tmp1->data[i][j].b = rand()%256; } #else tmp1->height = 500; tmp1->width = 400; for(i=0;i<tmp1->height;i++) for(j=0;j<tmp1->width;j++) { tmp1->data[i][j].r = i == 0 || j == 0 || i == tmp1->height - 1 || j == tmp1->width - 1 ? 255 : 0; tmp1->data[i][j].g = 0; tmp1->data[i][j].b = 0; } #endif // WriteBmp("noise.bmp", tmp1); WriteBmp("1.bmp", tmp1); }
the_stack_data/7502.c
#ifdef COMPILE_FOR_TEST #include <assert.h> #define assume(cond) assert(cond) #endif void main(int argc, char* argv[]) { int x_0_0;//sh_buf.outcnt int x_0_1;//sh_buf.outcnt int x_0_2;//sh_buf.outcnt int x_0_3;//sh_buf.outcnt int x_0_4;//sh_buf.outcnt int x_0_5;//sh_buf.outcnt int x_0_6;//sh_buf.outcnt int x_0_7;//sh_buf.outcnt int x_1_0;//sh_buf.outbuf[0] int x_1_1;//sh_buf.outbuf[0] int x_2_0;//sh_buf.outbuf[1] int x_2_1;//sh_buf.outbuf[1] int x_3_0;//sh_buf.outbuf[2] int x_3_1;//sh_buf.outbuf[2] int x_4_0;//sh_buf.outbuf[3] int x_4_1;//sh_buf.outbuf[3] int x_5_0;//sh_buf.outbuf[4] int x_5_1;//sh_buf.outbuf[4] int x_6_0;//sh_buf.outbuf[5] int x_7_0;//sh_buf.outbuf[6] int x_8_0;//sh_buf.outbuf[7] int x_9_0;//sh_buf.outbuf[8] int x_10_0;//sh_buf.outbuf[9] int x_11_0;//LOG_BUFSIZE int x_11_1;//LOG_BUFSIZE int x_12_0;//CREST_scheduler::lock_0 int x_13_0;//t3 T0 int x_14_0;//t2 T0 int x_15_0;//arg T0 int x_16_0;//functioncall::param T0 int x_16_1;//functioncall::param T0 int x_17_0;//buffered T0 int x_18_0;//functioncall::param T0 int x_18_1;//functioncall::param T0 int x_19_0;//functioncall::param T0 int x_19_1;//functioncall::param T0 int x_20_0;//functioncall::param T0 int x_20_1;//functioncall::param T0 int x_21_0;//functioncall::param T0 int x_21_1;//functioncall::param T0 int x_22_0;//direction T0 int x_23_0;//functioncall::param T0 int x_23_1;//functioncall::param T0 int x_24_0;//functioncall::param T0 int x_24_1;//functioncall::param T0 int x_25_0;//functioncall::param T0 int x_25_1;//functioncall::param T0 int x_26_0;//functioncall::param T0 int x_26_1;//functioncall::param T0 int x_27_0;//functioncall::param T0 int x_27_1;//functioncall::param T0 int x_28_0;//functioncall::param T0 int x_28_1;//functioncall::param T0 int x_29_0;//functioncall::param T0 int x_29_1;//functioncall::param T0 int x_30_0;//functioncall::param T0 int x_30_1;//functioncall::param T0 int x_31_0;//functioncall::param T0 int x_31_1;//functioncall::param T0 int x_32_0;//functioncall::param T0 int x_32_1;//functioncall::param T0 int x_33_0;//functioncall::param T0 int x_33_1;//functioncall::param T0 int x_34_0;//functioncall::param T0 int x_34_1;//functioncall::param T0 int x_35_0;//functioncall::param T1 int x_35_1;//functioncall::param T1 int x_36_0;//functioncall::param T1 int x_36_1;//functioncall::param T1 int x_37_0;//i T1 int x_37_1;//i T1 int x_37_2;//i T1 int x_38_0;//rv T1 int x_39_0;//rv T1 int x_39_1;//rv T1 int x_40_0;//functioncall::param T1 int x_40_1;//functioncall::param T1 int x_41_0;//functioncall::param T1 int x_41_1;//functioncall::param T1 int x_42_0;//functioncall::param T1 int x_42_1;//functioncall::param T1 int x_43_0;//functioncall::param T1 int x_43_1;//functioncall::param T1 int x_44_0;//functioncall::param T1 int x_44_1;//functioncall::param T1 int x_45_0;//functioncall::param T1 int x_45_1;//functioncall::param T1 int x_46_0;//functioncall::param T1 int x_46_1;//functioncall::param T1 int x_47_0;//functioncall::param T1 int x_47_1;//functioncall::param T1 int x_48_0;//functioncall::param T1 int x_48_1;//functioncall::param T1 int x_49_0;//functioncall::param T2 int x_49_1;//functioncall::param T2 int x_50_0;//functioncall::param T2 int x_50_1;//functioncall::param T2 int x_51_0;//i T2 int x_51_1;//i T2 int x_51_2;//i T2 int x_51_3;//i T2 int x_52_0;//rv T2 int x_53_0;//rv T2 int x_53_1;//rv T2 int x_54_0;//functioncall::param T2 int x_54_1;//functioncall::param T2 int x_55_0;//functioncall::param T2 int x_55_1;//functioncall::param T2 int x_56_0;//functioncall::param T2 int x_56_1;//functioncall::param T2 int x_57_0;//functioncall::param T2 int x_57_1;//functioncall::param T2 int x_58_0;//functioncall::param T2 int x_58_1;//functioncall::param T2 int x_59_0;//functioncall::param T2 int x_59_1;//functioncall::param T2 int x_59_2;//functioncall::param T2 int x_60_0;//functioncall::param T2 int x_60_1;//functioncall::param T2 T_0_0_0: x_0_0 = 0; T_0_1_0: x_1_0 = 0; T_0_2_0: x_2_0 = 0; T_0_3_0: x_3_0 = 0; T_0_4_0: x_4_0 = 0; T_0_5_0: x_5_0 = 0; T_0_6_0: x_6_0 = 0; T_0_7_0: x_7_0 = 0; T_0_8_0: x_8_0 = 0; T_0_9_0: x_9_0 = 0; T_0_10_0: x_10_0 = 0; T_0_11_0: x_11_0 = 0; T_0_12_0: x_13_0 = 228792496; T_0_13_0: x_14_0 = 3921846880; T_0_14_0: x_15_0 = 0; T_0_15_0: x_16_0 = 170036333; T_0_16_0: x_16_1 = -1; T_0_17_0: x_17_0 = 0; T_0_18_0: x_18_0 = 2036614447; T_0_19_0: x_18_1 = x_17_0; T_0_20_0: x_19_0 = 182762999; T_0_21_0: x_19_1 = 97; T_0_22_0: x_20_0 = 143353926; T_0_23_0: x_20_1 = 0; T_0_24_0: x_21_0 = 1341387006; T_0_25_0: x_21_1 = 0; T_0_26_0: x_22_0 = -373125056; T_0_27_0: x_23_0 = 885468799; T_0_28_0: x_23_1 = x_22_0; T_0_29_0: x_24_0 = 934963423; T_0_30_0: x_24_1 = 0; T_0_31_0: x_12_0 = -1; T_0_32_0: x_0_1 = 5; T_0_33_0: x_1_1 = 72; T_0_34_0: x_2_1 = 69; T_0_35_0: x_3_1 = 76; T_0_36_0: x_4_1 = 76; T_0_37_0: x_5_1 = 79; T_0_38_0: x_25_0 = 1409016420; T_0_39_0: x_25_1 = 83; T_0_40_0: x_26_0 = 288897707; T_0_41_0: x_26_1 = 1; T_0_42_0: x_27_0 = 2017515442; T_0_43_0: x_27_1 = 1; T_0_44_0: x_28_0 = 779618456; T_0_45_0: x_28_1 = 1; T_0_46_0: x_29_0 = 655473294; T_0_47_0: x_29_1 = 82; T_0_48_0: x_30_0 = 954304416; T_0_49_0: x_30_1 = 90; T_0_50_0: x_31_0 = 753373909; T_0_51_0: x_31_1 = 1; T_0_52_0: x_32_0 = 2032490579; T_0_53_0: x_32_1 = 1; T_0_54_0: x_33_0 = 1571324100; T_0_55_0: x_33_1 = 2; T_0_56_0: x_34_0 = 507223101; T_0_57_0: x_34_1 = 2; T_0_58_0: x_11_1 = 5; T_1_59_1: x_35_0 = 1414560013; T_1_60_1: x_35_1 = x_27_1; T_1_61_1: x_36_0 = 1768495312; T_1_62_1: x_36_1 = x_28_1; T_1_63_1: x_37_0 = 0; T_1_64_1: x_38_0 = 324563457; T_2_65_2: x_49_0 = 755701230; T_2_66_2: x_49_1 = x_33_1; T_2_67_2: x_50_0 = 358985069; T_2_68_2: x_50_1 = x_34_1; T_2_69_2: x_51_0 = 0; T_2_70_2: x_52_0 = 322462209; T_1_71_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_39_0 = 0; T_2_72_2: if (x_0_1 + x_50_1 > x_11_1 && x_0_1 != 0) x_53_0 = -366057552; T_2_73_2: if (x_0_1 + x_50_1 > x_11_1 && x_0_1 != 0 && x_18_1 == 0 && x_18_1 == 0) x_54_0 = 209744715; T_2_74_2: if (x_0_1 + x_50_1 > x_11_1 && x_0_1 != 0 && x_18_1 == 0 && x_18_1 == 0) x_54_1 = -1; T_2_75_2: if (x_0_1 + x_50_1 > x_11_1 && x_0_1 != 0 && x_18_1 == 0 && x_18_1 == 0) x_53_1 = x_54_1; T_2_76_2: if (x_0_1 + x_50_1 > x_11_1 && x_0_1 != 0 && x_18_1 == 0 && x_53_1 + 1 == 0) x_0_2 = 0; T_2_77_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 == 0 && x_18_1 == 0) x_40_0 = 798227616; T_2_78_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 == 0 && x_18_1 == 0) x_40_1 = -1; T_2_79_2: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 == 0 && x_18_1 == 0) x_39_1 = x_40_1; T_1_80_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0 && x_18_1 == 0 && x_39_1 + 1 == 0) x_0_3 = 0; T_1_81_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_41_0 = 1072058251; T_1_82_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_41_1 = 9; T_1_83_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_42_0 = 1171255122; T_1_84_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_42_1 = x_41_1; T_1_85_1: if (x_0_1 + x_36_1 > x_11_1 && x_0_1 != 0) x_0_4 = 0; T_1_86_1: if (x_0_1 + x_50_1 > x_11_1 && x_0_1 != 0) x_55_0 = 1084419835; T_1_87_1: if (x_0_1 + x_50_1 > x_11_1 && x_0_1 != 0) x_55_1 = 9; T_1_88_1: if (x_0_1 + x_50_1 > x_11_1 && x_0_1 != 0) x_56_0 = 1105083442; T_1_89_1: if (x_0_1 + x_50_1 > x_11_1 && x_0_1 != 0) x_56_1 = x_55_1; T_2_90_2: if (x_0_1 + x_50_1 > x_11_1 && x_0_1 != 0) x_0_5 = 0; T_2_91_2: if (x_50_1 < x_11_1) x_57_0 = 1373354055; T_2_92_2: if (x_50_1 < x_11_1) x_57_1 = 47673814525696; T_2_93_2: if (x_36_1 < x_11_1) x_43_0 = 692319451; T_2_94_2: if (x_36_1 < x_11_1) x_43_1 = 47673812424448; T_2_95_2: if (x_50_1 < x_11_1) x_58_0 = 325439267; T_1_96_1: if (x_50_1 < x_11_1) x_58_1 = x_0_5 + x_50_1; T_1_97_1: if (x_50_1 < x_11_1) x_51_1 = 0; T_2_98_2: if (x_50_1 < x_11_1 && x_51_1 < x_49_1) x_59_0 = 360600227; T_2_99_2: if (x_50_1 < x_11_1 && x_51_1 < x_49_1) x_59_1 = 47673814525696; T_2_100_2: if (x_50_1 < x_11_1) x_51_2 = 1 + x_51_1; T_2_101_2: if (x_50_1 < x_11_1 && x_51_2 < x_49_1) x_59_2 = 47673814525696; T_2_102_2: if (x_50_1 < x_11_1) x_51_3 = 1 + x_51_2; T_2_103_2: if (x_50_1 < x_11_1) x_60_0 = 862355784; T_2_104_2: if (x_50_1 < x_11_1) x_60_1 = 47673814525696; T_2_105_2: if (x_36_1 < x_11_1) x_44_0 = 214570066; T_2_106_2: if (x_36_1 < x_11_1) x_44_1 = x_0_5 + x_36_1; T_2_107_2: if (x_36_1 < x_11_1) x_37_1 = 0; T_1_108_1: if (x_36_1 < x_11_1 && x_37_1 < x_35_1) x_45_0 = 543363226; T_1_109_1: if (x_36_1 < x_11_1 && x_37_1 < x_35_1) x_45_1 = 47673812424448; T_1_110_1: if (x_36_1 < x_11_1) x_37_2 = 1 + x_37_1; T_1_111_1: if (x_36_1 < x_11_1) x_46_0 = 1005709710; T_1_112_1: if (x_36_1 < x_11_1) x_46_1 = 47673812424448; T_1_113_1: if (x_36_1 < x_11_1) x_0_6 = x_0_5 + x_36_1; T_1_114_1: if (x_36_1 < x_11_1) x_47_0 = 1555957072; T_1_115_1: if (x_36_1 < x_11_1) x_47_1 = 47673812424448; T_1_116_1: if (x_50_1 < x_11_1) x_0_7 = x_0_5 + x_50_1; T_1_117_1: if (x_36_1 < x_11_1) x_48_0 = 1428832025; T_1_118_1: if (x_36_1 < x_11_1) x_48_1 = 47673812424448; T_1_119_1: if (x_36_1 < x_11_1) assert(x_0_7 == x_44_1); }
the_stack_data/3263012.c
// MIT License // // Copyright (c) 2018 Xiao Wang ([email protected]) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // // Enquiries about further applications and development opportunities are // welcome. #include <assert.h> #include <emmintrin.h> #include <smmintrin.h> #include <stdint.h> #include <stdlib.h> #include <wmmintrin.h> #include <xmmintrin.h> #define INP(x, y) inp[(x)*ncols / 8 + (y) / 8] #define OUT(x, y) out[(y)*nrows / 8 + (x) / 8] // Modified from // https://mischasan.wordpress.com/2011/10/03/the-full-sse2-bit-matrix-transpose-routine/ // with inner most loops changed to _mm_set_epi8 and _mm_set_epi16 void sse_trans(uint8_t *out, uint8_t const *inp, uint64_t nrows, uint64_t ncols) { uint64_t rr, cc; int i, h; union { __m128i x; uint8_t b[16]; } tmp; __m128i vec; assert(nrows % 8 == 0 && ncols % 8 == 0); // Do the main body in 16x8 blocks: for (rr = 0; rr <= nrows - 16; rr += 16) { for (cc = 0; cc < ncols; cc += 8) { vec = _mm_set_epi8(INP(rr + 15, cc), INP(rr + 14, cc), INP(rr + 13, cc), INP(rr + 12, cc), INP(rr + 11, cc), INP(rr + 10, cc), INP(rr + 9, cc), INP(rr + 8, cc), INP(rr + 7, cc), INP(rr + 6, cc), INP(rr + 5, cc), INP(rr + 4, cc), INP(rr + 3, cc), INP(rr + 2, cc), INP(rr + 1, cc), INP(rr + 0, cc)); for (i = 8; --i >= 0; vec = _mm_slli_epi64(vec, 1)) *(uint16_t *)&OUT(rr, cc + i) = _mm_movemask_epi8(vec); } } if (rr == nrows) return; // The remainder is a block of 8x(16n+8) bits (n may be 0). // Do a PAIR of 8x8 blocks in each step: if ((ncols % 8 == 0 && ncols % 16 != 0) || (nrows % 8 == 0 && nrows % 16 != 0)) { // The fancy optimizations in the else-branch don't work if the above if-condition // holds, so we use the simpler non-simd variant for that case. for (cc = 0; cc <= ncols - 16; cc += 16) { for (i = 0; i < 8; ++i) { tmp.b[i] = h = *(uint16_t const *)&INP(rr + i, cc); tmp.b[i + 8] = h >> 8; } for (i = 8; --i >= 0; tmp.x = _mm_slli_epi64(tmp.x, 1)) { OUT(rr, cc + i) = h = _mm_movemask_epi8(tmp.x); OUT(rr, cc + i + 8) = h >> 8; } } } else { for (cc = 0; cc <= ncols - 16; cc += 16) { vec = _mm_set_epi16(*(uint16_t const *)&INP(rr + 7, cc), *(uint16_t const *)&INP(rr + 6, cc), *(uint16_t const *)&INP(rr + 5, cc), *(uint16_t const *)&INP(rr + 4, cc), *(uint16_t const *)&INP(rr + 3, cc), *(uint16_t const *)&INP(rr + 2, cc), *(uint16_t const *)&INP(rr + 1, cc), *(uint16_t const *)&INP(rr + 0, cc)); for (i = 8; --i >= 0; vec = _mm_slli_epi64(vec, 1)) { OUT(rr, cc + i) = h = _mm_movemask_epi8(vec); OUT(rr, cc + i + 8) = h >> 8; } } } if (cc == ncols) return; // Do the remaining 8x8 block: for (i = 0; i < 8; ++i) tmp.b[i] = INP(rr + i, cc); for (i = 8; --i >= 0; tmp.x = _mm_slli_epi64(tmp.x, 1)) OUT(rr, cc + i) = _mm_movemask_epi8(tmp.x); }
the_stack_data/78343.c
/* Addition Program */ #include <stdio.h> int main() { int integer1, interger2, sum; printf("Enter the first intger\n"); scanf("%d", &integer1); printf("Enter second integer\n"); scanf("%d", &interger2); sum = integer1 + interger2; printf("Sum is %d\n", sum); return 0; }
the_stack_data/168893087.c
#define GPIO_FSEL3 ((unsigned int *)0x2020000c) #define GPIO_SET1 ((unsigned int *)0x20200020) #define GPIO_CLR1 ((unsigned int *)0x2020002c) // Red power LED (on Pi board) is GPIO 35. #define ABORT_OUTPUT (1 << (3*5)) #define ABORT_BIT (1 << (35-32)) #define DELAY 0x100000 // abort goes into an infinite loop that flashes the red power LED. void abort(void) { // First, configure GPIO 35 function to be output. // This assignment wipes functions for other pins in this register // (GPIO 30-39), but that's okay, because this is a dead-end routine. *GPIO_FSEL3 = ABORT_OUTPUT; while (1) { *GPIO_SET1 = ABORT_BIT; // These delay loops have volatile counters to prevent being // optimized out. for (volatile int i = 0; i < DELAY; i++) ; *GPIO_CLR1 = ABORT_BIT; for (volatile int i = 0; i < DELAY; i++) ; } }
the_stack_data/227611.c
#include <stdio.h> int main() { char *s = "hello, world!"; printf("%s\n", s); // test with strings array char *ss[10] = {"hello", ",", "world", "!", NULL}; char **p; for (p = ss; *p != NULL; p++) { printf("%s ", *p); } printf("\n"); return 0; }
the_stack_data/82950875.c
// Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. int nothingB817067A_D13C_43AE_BA6F_CD16AD2BF441 = 0;
the_stack_data/173578950.c
#include<stdio.h> int main() { int rem,result=0,number,count=0,cnt,fact=1; printf("Enter any number:"); scanf("%d",&number); int q=number; while(q!=0) { q=q/10; count++; } q=number; cnt=count; while(q!=0) { rem=q%10; while(rem!=1) { fact=fact*rem; rem--; } result=result+fact; q=q/10; cnt=count; fact=1; } printf("%d ",result); if(result==number) { printf("YES"); } else { printf("NO"); } }
the_stack_data/126704224.c
#include <stdio.h> int main(){ int i=1, j=60; printf("I=%d J=%d\n", i, j); while(j!=0){ i += 3; j -= 5 ; printf("I=%d J=%d\n", i, j); } return 0; }
the_stack_data/149370.c
#include<stdio.h> typedef enum {false, true} bool; enum operations {ADD, SUB, MUL, DIV}; void print(char* str) { printf("%s\n", str); } int reduce_bytecode(int* bytecode, int len) { if (len == 1) return bytecode[0]; // loop over instructions and find highest order function. [inst are at odd indexes] int i = 1; int max_inst=0; int max_inst_count=0; int max_inst_indexes[len]; // cannot be more than the $len in anyway. while(i < len) { int code = bytecode[i]; if (code > max_inst) { max_inst = code; max_inst_count = 0; // clear the indexes_list; maybe we dont need this because we are also using length ! think ! //for (int j = 0; j < max_inst_count; j++) { // max_inst_indexes[j] = 0; //} } if (code == max_inst) { max_inst_indexes[max_inst_count++] = i; } i += 2; } // evaluate the indexes where max_values are; printf("max_inst_count: %d\n", max_inst_count); printf("max_inst: %d\n", max_inst); printf("INDEXES => "); for (int j = 0; j < max_inst_count; j++) { printf("%d ", max_inst_indexes[j]); } // evaluate the highest order bytecode operation indexes and store the result in left side index // and shift all the values after the index to the left; int offset = 0; for (int counter = 0; counter < max_inst_count; counter++) { int i = max_inst_indexes[counter] - offset; // evaluate the operation //enum operations {ADD, SUB, MUL, DIV}; int op = bytecode[i]; int op1 = bytecode[i - 1]; int op2 = bytecode[i + 1]; int res; switch (op) { case ADD: res = op1 + op2; break; // will this break break the for loop too ? case SUB: res = op1 - op2; break; case MUL: res = op1 * op2; break; case DIV: res = op1 / op2; break; default: fprintf(stderr, "ERROR ENCOUNTERED ! INVALID OPERATOR CODE : %d", op); return 1; break; } printf("RESULTS ARE => "); printf("%d ", res); // shift instructions to the right to the left side ! bytecode[i-1] = res; for (int jj=i; jj < len; jj++) { if (len <= jj + 2) { break; } bytecode[jj] = bytecode[jj + 2]; } offset += 2; // index offset for max_inst_indexes } return reduce_bytecode(bytecode, len - offset); } int main(int argc, char** argv) { print("Testing Structs in C"); struct Address { char name[50]; char address[100]; unsigned age; unsigned marks; bool vaccinated; }; struct Address h_addr = {"harshit", "address_string", 20, 100, true}; /* C only has initialisation literals for Structs not assignment literals ! h_addr = {"", "", 20, 77, false}; // doesnt work h_addr = (struct Address){"", "", 20, 77, false}; // works */ //printf("%s\n", h_addr.name); //printf("%s\n", h_addr.address); //printf("%d\n", h_addr.age); //printf("%d\n", h_addr.marks); //printf("%d\n", h_addr.vaccinated); int bytecode[] = {2, 0, 2, 3, 2, 0, 10, 3, 10}; int len = 9; int res = reduce_bytecode(bytecode, len); printf("res: %d\n", res); return 0; } // todo counting with static
the_stack_data/66187.c
/* Nutation, IAU 2000b model */ /* Translated from Pat Wallace's Fortran subroutine iau_nut00b (June 26 2007) into C by Doug Mink on September 5, 2008 */ #define NLS 77 /* number of terms in the luni-solar nutation model */ void compnut (dj, dpsi, deps, eps0) double dj; /* Julian Date */ double *dpsi; /* Nutation in longitude in radians (returned) */ double *deps; /* Nutation in obliquity in radians (returned) */ double *eps0; /* Mean obliquity in radians (returned) */ /* This routine is translated from the International Astronomical Union's * SOFA (Standards Of Fundamental Astronomy) software collection. * * notes: * * 1) the nutation components in longitude and obliquity are in radians * and with respect to the equinox and ecliptic of date. the * obliquity at j2000 is assumed to be the lieske et al. (1977) value * of 84381.448 arcsec. (the errors that result from using this * routine with the iau 2006 value of 84381.406 arcsec can be * neglected.) * * the nutation model consists only of luni-solar terms, but includes * also a fixed offset which compensates for certain long-period * planetary terms (note 7). * * 2) this routine is an implementation of the iau 2000b abridged * nutation model formally adopted by the iau general assembly in * 2000. the routine computes the mhb_2000_short luni-solar nutation * series (luzum 2001), but without the associated corrections for * the precession rate adjustments and the offset between the gcrs * and j2000 mean poles. * * 3) the full IAU 2000a (mhb2000) nutation model contains nearly 1400 * terms. the IAU 2000b model (mccarthy & luzum 2003) contains only * 77 terms, plus additional simplifications, yet still delivers * results of 1 mas accuracy at present epochs. this combination of * accuracy and size makes the IAU 2000b abridged nutation model * suitable for most practical applications. * * the routine delivers a pole accurate to 1 mas from 1900 to 2100 * (usually better than 1 mas, very occasionally just outside 1 mas). * the full IAU 2000a model, which is implemented in the routine * iau_nut00a (q.v.), delivers considerably greater accuracy at * current epochs; however, to realize this improved accuracy, * corrections for the essentially unpredictable free-core-nutation * (fcn) must also be included. * * 4) the present routine provides classical nutation. the * mhb_2000_short algorithm, from which it is adapted, deals also * with (i) the offsets between the gcrs and mean poles and (ii) the * adjustments in longitude and obliquity due to the changed * precession rates. these additional functions, namely frame bias * and precession adjustments, are supported by the sofa routines * iau_bi00 and iau_pr00. * * 6) the mhb_2000_short algorithm also provides "total" nutations, * comprising the arithmetic sum of the frame bias, precession * adjustments, and nutation (luni-solar + planetary). these total * nutations can be used in combination with an existing IAU 1976 * precession implementation, such as iau_pmat76, to deliver gcrs-to- * true predictions of mas accuracy at current epochs. however, for * symmetry with the iau_nut00a routine (q.v. for the reasons), the * sofa routines do not generate the "total nutations" directly. * should they be required, they could of course easily be generated * by calling iau_bi00, iau_pr00 and the present routine and adding * the results. * * 7) the IAU 2000b model includes "planetary bias" terms that are fixed * in size but compensate for long-period nutations. the amplitudes * quoted in mccarthy & luzum (2003), namely dpsi = -1.5835 mas and * depsilon = +1.6339 mas, are optimized for the "total nutations" * method described in note 6. the luzum (2001) values used in this * sofa implementation, namely -0.135 mas and +0.388 mas, are * optimized for the "rigorous" method, where frame bias, precession * and nutation are applied separately and in that order. during the * interval 1995-2050, the sofa implementation delivers a maximum * error of 1.001 mas (not including fcn). * * References from original Fortran subroutines: * * Hilton, J. et al., 2006, Celest.Mech.Dyn.Astron. 94, 351 * * Lieske, J.H., Lederle, T., Fricke, W., Morando, B., "Expressions * for the precession quantities based upon the IAU 1976 system of * astronomical constants", Astron.Astrophys. 58, 1-2, 1-16. (1977) * * Luzum, B., private communication, 2001 (Fortran code * mhb_2000_short) * * McCarthy, D.D. & Luzum, B.J., "An abridged model of the * precession-nutation of the celestial pole", Cel.Mech.Dyn.Astron. * 85, 37-49 (2003) * * Simon, J.-L., Bretagnon, P., Chapront, J., Chapront-Touze, M., * Francou, G., Laskar, J., Astron.Astrophys. 282, 663-683 (1994) * */ { double as2r = 0.000004848136811095359935899141; /* arcseconds to radians */ double dmas2r = as2r / 1000.0; /* milliarcseconds to radians */ double as2pi = 1296000.0; /* arc seconds in a full circle */ double d2pi = 6.283185307179586476925287; /* 2pi */ double u2r = as2r / 10000000.0; /* units of 0.1 microarcsecond to radians */ double dj0 = 2451545.0; /* reference epoch (j2000), jd */ double djc = 36525.0; /* Days per julian century */ /* Miscellaneous */ double t, el, elp, f, d, om, arg, dp, de, sarg, carg; double dpsils, depsls, dpsipl, depspl; int i, j; int nls = NLS; /* number of terms in the luni-solar nutation model */ /* Fixed offset in lieu of planetary terms (radians) */ double dpplan = - 0.135 * dmas2r; double deplan = + 0.388 * dmas2r; /* Tables of argument and term coefficients */ /* Coefficients for fundamental arguments /* Luni-solar argument multipliers: */ /* l l' f d om */ static int nals[5*NLS]= {0, 0, 0, 0, 1, 0, 0, 2, -2, 2, 0, 0, 2, 0, 2, 0, 0, 0, 0, 2, 0, 1, 0, 0, 0, 0, 1, 2, -2, 2, 1, 0, 0, 0, 0, 0, 0, 2, 0, 1, 1, 0, 2, 0, 2, 0, -1, 2, -2, 2, 0, 0, 2, -2, 1, -1, 0, 2, 0, 2, -1, 0, 0, 2, 0, 1, 0, 0, 0, 1, -1, 0, 0, 0, 1, -1, 0, 2, 2, 2, 1, 0, 2, 0, 1, -2, 0, 2, 0, 1, 0, 0, 0, 2, 0, 0, 0, 2, 2, 2, 0, -2, 2, -2, 2, -2, 0, 0, 2, 0, 2, 0, 2, 0, 2, 1, 0, 2, -2, 2, -1, 0, 2, 0, 1, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 0, 1, -1, 0, 0, 2, 1, 0, 2, 2, -2, 2, 0, 0, -2, 2, 0, 1, 0, 0, -2, 1, 0, -1, 0, 0, 1, -1, 0, 2, 2, 1, 0, 2, 0, 0, 0, 1, 0, 2, 2, 2, -2, 0, 2, 0, 0, 0, 1, 2, 0, 2, 0, 0, 2, 2, 1, 0, -1, 2, 0, 2, 0, 0, 0, 2, 1, 1, 0, 2, -2, 1, 2, 0, 2, -2, 2, -2, 0, 0, 2, 1, 2, 0, 2, 0, 1, 0, -1, 2, -2, 1, 0, 0, 0, -2, 1, -1, -1, 0, 2, 0, 2, 0, 0, -2, 1, 1, 0, 0, 2, 0, 0, 1, 2, -2, 1, 1, -1, 0, 0, 0, -2, 0, 2, 0, 2, 3, 0, 2, 0, 2, 0, -1, 0, 2, 0, 1, -1, 2, 0, 2, 0, 0, 0, 1, 0, -1, -1, 2, 2, 2, -1, 0, 2, 0, 0, 0, -1, 2, 2, 2, -2, 0, 0, 0, 1, 1, 1, 2, 0, 2, 2, 0, 0, 0, 1, -1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 2, 0, 0, -1, 0, 2, -2, 1, 1, 0, 0, 0, 2, -1, 0, 0, 1, 0, 0, 0, 2, 1, 2, -1, 0, 2, 4, 2, -1, 1, 0, 1, 1, 0, -2, 2, -2, 1, 1, 0, 2, 2, 1, -2, 0, 2, 2, 2, -1, 0, 0, 0, 2, 1, 1, 2, -2, 2}; /* Luni-solar nutation coefficients, in 1e-7 arcsec */ /* longitude (sin, t*sin, cos), obliquity (cos, t*cos, sin) */ static double cls[6*NLS]= {-172064161.0, -174666.0, 33386.0, 92052331.0, 9086.0, 15377.0, -13170906.0, -1675.0, -13696.0, 5730336.0, -3015.0, -4587.0, -2276413.0, -234.0, 2796.0, 978459.0, -485.0, 1374.0, 2074554.0, 207.0, -698.0, -897492.0, 470.0, -291.0, 1475877.0, -3633.0, 11817.0, 73871.0, -184.0, -1924.0, -516821.0, 1226.0, -524.0, 224386.0, -677.0, -174.0, 711159.0, 73.0, -872.0, -6750.0, 0.0, 358.0, -387298.0, -367.0, 380.0, 200728.0, 18.0, 318.0, -301461.0, -36.0, 816.0, 129025.0, -63.0, 367.0, 215829.0, -494.0, 111.0, -95929.0, 299.0, 132.0, 128227.0, 137.0, 181.0, -68982.0, -9.0, 39.0, 123457.0, 11.0, 19.0, -53311.0, 32.0, -4.0, 156994.0, 10.0, -168.0, -1235.0, 0.0, 82.0, 63110.0, 63.0, 27.0, -33228.0, 0.0, -9.0, -57976.0, -63.0, -189.0, 31429.0, 0.0, -75.0, -59641.0, -11.0, 149.0, 25543.0, -11.0, 66.0, -51613.0, -42.0, 129.0, 26366.0, 0.0, 78.0, 45893.0, 50.0, 31.0, -24236.0, -10.0, 20.0, 63384.0, 11.0, -150.0, -1220.0, 0.0, 29.0, -38571.0, -1.0, 158.0, 16452.0, -11.0, 68.0, 32481.0, 0.0, 0.0, -13870.0, 0.0, 0.0, -47722.0, 0.0, -18.0, 477.0, 0.0, -25.0, -31046.0, -1.0, 131.0, 13238.0, -11.0, 59.0, 28593.0, 0.0, -1.0, -12338.0, 10.0, -3.0, 20441.0, 21.0, 10.0, -10758.0, 0.0, -3.0, 29243.0, 0.0, -74.0, -609.0, 0.0, 13.0, 25887.0, 0.0, -66.0, -550.0, 0.0, 11.0, -14053.0, -25.0, 79.0, 8551.0, -2.0, -45.0, 15164.0, 10.0, 11.0, -8001.0, 0.0, -1.0, -15794.0, 72.0, -16.0, 6850.0, -42.0, -5.0, 21783.0, 0.0, 13.0, -167.0, 0.0, 13.0, -12873.0, -10.0, -37.0, 6953.0, 0.0, -14.0, -12654.0, 11.0, 63.0, 6415.0, 0.0, 26.0, -10204.0, 0.0, 25.0, 5222.0, 0.0, 15.0, 16707.0, -85.0, -10.0, 168.0, -1.0, 10.0, -7691.0, 0.0, 44.0, 3268.0, 0.0, 19.0, -11024.0, 0.0, -14.0, 104.0, 0.0, 2.0, 7566.0, -21.0, -11.0, -3250.0, 0.0, -5.0, -6637.0, -11.0, 25.0, 3353.0, 0.0, 14.0, -7141.0, 21.0, 8.0, 3070.0, 0.0, 4.0, -6302.0, -11.0, 2.0, 3272.0, 0.0, 4.0, 5800.0, 10.0, 2.0, -3045.0, 0.0, -1.0, 6443.0, 0.0, -7.0, -2768.0, 0.0, -4.0, -5774.0, -11.0, -15.0, 3041.0, 0.0, -5.0, -5350.0, 0.0, 21.0, 2695.0, 0.0, 12.0, -4752.0, -11.0, -3.0, 2719.0, 0.0, -3.0, -4940.0, -11.0, -21.0, 2720.0, 0.0, -9.0, 7350.0, 0.0, -8.0, -51.0, 0.0, 4.0, 4065.0, 0.0, 6.0, -2206.0, 0.0, 1.0, 6579.0, 0.0, -24.0, -199.0, 0.0, 2.0, 3579.0, 0.0, 5.0, -1900.0, 0.0, 1.0, 4725.0, 0.0, -6.0, -41.0, 0.0, 3.0, -3075.0, 0.0, -2.0, 1313.0, 0.0, -1.0, -2904.0, 0.0, 15.0, 1233.0, 0.0, 7.0, 4348.0, 0.0, -10.0, -81.0, 0.0, 2.0, -2878.0, 0.0, 8.0, 1232.0, 0.0, 4.0, -4230.0, 0.0, 5.0, -20.0, 0.0, -2.0, -2819.0, 0.0, 7.0, 1207.0, 0.0, 3.0, -4056.0, 0.0, 5.0, 40.0, 0.0, -2.0, -2647.0, 0.0, 11.0, 1129.0, 0.0, 5.0, -2294.0, 0.0, -10.0, 1266.0, 0.0, -4.0, 2481.0, 0.0, -7.0, -1062.0, 0.0, -3.0, 2179.0, 0.0, -2.0, -1129.0, 0.0, -2.0, 3276.0, 0.0, 1.0, -9.0, 0.0, 0.0, -3389.0, 0.0, 5.0, 35.0, 0.0, -2.0, 3339.0, 0.0, -13.0, -107.0, 0.0, 1.0, -1987.0, 0.0, -6.0, 1073.0, 0.0, -2.0, -1981.0, 0.0, 0.0, 854.0, 0.0, 0.0, 4026.0, 0.0, -353.0, -553.0, 0.0, -139.0, 1660.0, 0.0, -5.0, -710.0, 0.0, -2.0, -1521.0, 0.0, 9.0, 647.0, 0.0, 4.0, 1314.0, 0.0, 0.0, -700.0, 0.0, 0.0, -1283.0, 0.0, 0.0, 672.0, 0.0, 0.0, -1331.0, 0.0, 8.0, 663.0, 0.0, 4.0, 1383.0, 0.0, -2.0, -594.0, 0.0, -2.0, 1405.0, 0.0, 4.0, -610.0, 0.0, 2.0, 1290.0, 0.0, 0.0, -556.0, 0.0, 0.0}; /* Interval between fundamental epoch J2000.0 and given date (JC) */ t = (dj - dj0) / djc; /* Luni-solar nutation */ /* Fundamental (delaunay) arguments from Simon et al. (1994) */ /* Mean anomaly of the moon */ el = fmod (485868.249036 + (1717915923.2178 * t), as2pi) * as2r; /* Mean anomaly of the sun */ elp = fmod (1287104.79305 + (129596581.0481 * t), as2pi) * as2r; /* Mean argument of the latitude of the moon */ f = fmod (335779.526232 + (1739527262.8478 * t), as2pi) * as2r; /* Mean elongation of the moon from the sun */ d = fmod (1072260.70369 + (1602961601.2090 * t), as2pi ) * as2r; /* Mean longitude of the ascending node of the moon */ om = fmod (450160.398036 - (6962890.5431 * t), as2pi ) * as2r; /* Initialize the nutation values */ dp = 0.0; de = 0.0; /* Summation of luni-solar nutation series (in reverse order) */ for (i = nls; i > 0; i=i-1) { j = i - 1; /* Argument and functions */ arg = fmod ( (double) (nals[5*j]) * el + (double) (nals[1+5*j]) * elp + (double) (nals[2+5*j]) * f + (double) (nals[3+5*j]) * d + (double) (nals[4+5*j]) * om, d2pi); sarg = sin (arg); carg = cos (arg); /* Terms */ dp = dp + (cls[6*j] + cls[1+6*j] * t) * sarg + cls[2+6*j] * carg; de = de + (cls[3+6*j] + cls[4+6*j] * t) * carg + cls[5+6*j] * sarg; } /* Convert from 0.1 microarcsec units to radians */ dpsils = dp * u2r; depsls = de * u2r; /* In lieu of planetary nutation */ /* Fixed offset to correct for missing terms in truncated series */ dpsipl = dpplan; depspl = deplan; /* Results */ /* Add luni-solar and planetary components */ *dpsi = dpsils + dpsipl; *deps = depsls + depspl; /* Mean Obliquity in radians (IAU 2006, Hilton, et al.) */ *eps0 = ( 84381.406 + ( -46.836769 + ( -0.0001831 + ( 0.00200340 + ( -0.000000576 + ( -0.0000000434 ) * t ) * t ) * t ) * t ) * t ) * as2r; }
the_stack_data/87749.c
#include <stdio.h> int main() { int i = 0, j; long int counter = 0; while (i < 100000) { j = i; while (j < 100000) { j++; counter++; } i++; } printf("%ld iterations\n", counter); }
the_stack_data/111077606.c
#include <stdio.h> #include <stdbool.h> #define BUCKET_SIZE 50 #define MAX_INPUT_SIZE 10 typedef struct cell { char *key; char *value; struct cell *next; } CELL; CELL *hash_table[BUCKET_SIZE]; static int gen_hash(const char *s); static char *find(const char *key); static int insert(const char *key, const char *value); int main(void) { init(); insert("A", "hogeA"); insert("B", "hogeB"); insert("C", "hogeC"); insert("D", "hogeD"); int i; char *input; for (i = 0; i < MAX_INPUT_SIZE; i++) { fgets(input, 2, stdin); if (input != NULL && *input != '\0') { if (find(input) != NULL) { printf("key %s is found. value: %s \n", input, find(input)); break; } else { printf("key %s is not found \n", input); continue; } } } } /** * initialize hash table */ void init() { int i; for (i = 0; i < BUCKET_SIZE; i++) { hash_table[i] = NULL; } } /** * Create a hash value */ int gen_hash(const char *s) { int i = 0; while (*s) { i += *s++; } return i % 100; } char *find(const char *key) { CELL *p; for (p = hash_table[gen_hash(key)]; p != NULL; p = p->next) { if (strcmp(key, p->key) == 0) { return p->value; } } return NULL; } int insert(const char *key, const char *value) { CELL *p; int h; if (find(key) != NULL) { return 0; } if ((p = malloc(sizeof(CELL))) == NULL) { fprintf(stderr, "out of memory\n"); exit(2); } h = gen_hash(key); p->key = key; p->value = value; p->next = hash_table[h]; hash_table[h] = p; p->next = NULL; return 1; }
the_stack_data/92323950.c
/* * Math Tools in C * FACTORS * * https://afaan.ml/math-tools-in-c * * (c) Afaan Bilal (https://google.com/+AfaanBilal) * */ #include <stdio.h> int main() { int n, i = 1; printf("Enter the number: "); scanf("%d", &n); printf("Factors of %d: ", n); while (i <= (n / 2)) { if (n % i == 0) printf("%d ", i); i++; } getch(); return 0; }
the_stack_data/9512075.c
/* */ #include <sys/types.h> int main(void){return 0;}
the_stack_data/165765322.c
/************************************************************************* > File Name: helloengine_xcb.c > Author: 刘傲天 > Mail: [email protected] > Created Time: 2018年10月11日 星期四 23时39分17秒 ************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <xcb/xcb.h> int main(void) { xcb_connection_t *pConn; xcb_screen_t *pScreen; xcb_window_t window; xcb_gcontext_t foreground; xcb_gcontext_t background; xcb_generic_event_t *pEvent; uint32_t mask = 0; uint32_t values[2]; uint8_t isQuit = 0; char title[] = "Hello, Engine!"; char title_icon[] = "Hello, Engine! (iconified)"; pConn = xcb_connect(0, 0); pScreen = xcb_setup_roots_iterator(xcb_get_setup(pConn)).data; window = pScreen->root; foreground = xcb_generate_id(pConn); mask = XCB_GC_BACKGROUND | XCB_GC_GRAPHICS_EXPOSURES; values[0] = pScreen->white_pixel; values[1] = 0; xcb_create_gc(pConn, background, window, mask, values); /* create window */ window = xcb_generate_id(pConn); mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; values[0] = pScreen->white_pixel; values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS; xcb_create_window (pConn, /* connection */ XCB_COPY_FROM_PARENT, /* depth */ window, /* window ID */ pScreen->root, /* parent window */ 20, 20, /* x, y */ 640, 480, /* width, height */ 10, /* boarder width */ XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */ pScreen->root_visual, /* visual */ mask, values); /* masks */ /* set the title of the window */ xcb_change_property(pConn, XCB_PROP_MODE_REPLACE, window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, strlen(title), title); /* set the title of the window icon */ xcb_change_property(pConn, XCB_PROP_MODE_REPLACE, window, XCB_ATOM_WM_ICON_NAME, XCB_ATOM_STRING, 8, strlen(title_icon), title_icon); /* map the window on the screen */ xcb_map_window(pConn, window); xcb_flush(pConn); while((pEvent = xcb_wait_for_event(pConn)) && !isQuit) { switch(pEvent->response_type & ~0x80) { case XCB_EXPOSE: break; case XCB_KEY_PRESS: isQuit = 1; break; } free(pEvent); } return 0; }
the_stack_data/121932.c
#include <stdint.h> // // AUTOGENERATED BY BUILD // DO NOT MODIFY - CHANGES WILL BE OVERWRITTEN // uint32_t RESOURCE_ID_IMAGE_MENU_ICON = 1; uint32_t RESOURCE_ID_IMAGE_LOGO_SPLASH = 2; uint32_t RESOURCE_ID_IMAGE_TILE_SPLASH = 3; uint32_t RESOURCE_ID_MONO_FONT_14 = 4;
the_stack_data/40549.c
/*Exercise 4 - Functions Implement the three functions minimum(), maximum() and multiply() below the main() function. Do not change the code given in the main() function when you are implementing your solution.*/ #include <stdio.h> int minimum(int no1,int no2); int maximum(int no1,int no2); int multiply(int no1,int no2); int main() { int no1, no2; printf("Enter a value for no 1 : "); scanf("%d", &no1); printf("Enter a value for no 2 : "); scanf("%d", &no2); printf("%d ", minimum(no1, no2)); printf("%d ", maximum(no1, no2)); printf("%d ", multiply(no1, no2)); return 0; } int minimum(int no1, int no2){ int answer; if(no1>no2){ answer = no2; } else{ answer = no1; } return answer; } int maximum(int no1,int no2){ int answer; if(no1>no2){ answer=no1; } else{ answer =no2; } return answer; } int multiply(int no1,int no2){ int answer = no1*no2; return answer; }
the_stack_data/237643793.c
#ifndef __clang__ #include <stdbool.h> bool __builtin_add_overflow(signed long, signed long, signed long *); #endif int main(int argc, const char **argv) { signed long res; if (__builtin_add_overflow((signed long)0x0, (signed long)0x0, &res)) { return -1; } if (__builtin_add_overflow((signed long)0x7FFFFFFFFFFFFFFF, (signed long)0x0, &res)) { return -1; } if (__builtin_add_overflow((signed long)0x0, (signed long)0x7FFFFFFFFFFFFFFF, &res)) { return -1; } if (__builtin_add_overflow((signed long)0x8000000000000000, (signed long)0x7FFFFFFFFFFFFFFF, &res)) { return -1; } if (__builtin_add_overflow((signed long)0x7FFFFFFFFFFFFFFF, (signed long)0x8000000000000000, &res)) { return -1; } if (!__builtin_add_overflow((signed long)0x7FFFFFFFFFFFFFFF, (signed long)0x1, &res)) { return -1; } if (!__builtin_add_overflow((signed long)0x1, (signed long)0x7FFFFFFFFFFFFFFF, &res)) { return -1; } if (!__builtin_add_overflow((signed long)0x7FFFFFFFFFFFFFFF, (signed long)0x7FFFFFFFFFFFFFFF, &res)) { return -1; } if (!__builtin_add_overflow((signed long)0x8000000000000000, (signed long)0x8000000000000000, &res)) { return -1; } return 0; }
the_stack_data/175143794.c
//--------------------------------------------------------------------- // program EP //--------------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <sys/time.h> #if !defined(CLASS_W) && !defined(CLASS_S) && !defined(CLASS_A) && !defined(CLASS_B) && !defined(CLASS_C) && !defined(CLASS_D) && !defined(CLASS_E) # define CLASS_W #endif //---------- // Class S: //---------- #ifdef CLASS_S # define M 24 # define CLASS 'S' #endif //---------- // Class W: //---------- #ifdef CLASS_W # define M 25 # define CLASS 'W' #endif //---------- // Class A: //---------- #ifdef CLASS_A # define M 28 # define CLASS 'A' #endif //---------- // Class B: //---------- #ifdef CLASS_B # define M 30 # define CLASS 'B' #endif //---------- // Class C: //---------- #ifdef CLASS_C # define M 32 # define CLASS 'C' #endif //---------- // Class D: //---------- #ifdef CLASS_D # define M 36 # define CLASS 'D' #endif //---------- // Class E: //---------- #ifdef CLASS_E # define M 40 # define CLASS 'E' #endif typedef struct { double real; double imag; } dcomplex; #define min(x,y) ((x) < (y) ? (x) : (y)) #define max(x,y) ((x) > (y) ? (x) : (y)) #define MAX(X,Y) (((X) > (Y)) ? (X) : (Y)) #define MK 16 #define MM (M - MK) #define NN (1 << MM) #define NK (1 << MK) #define NQ 10 #define EPSILON 1.0e-8 #define A 1220703125.0 #define S 271828183.0 double randlc( double *x, double a ); void vranlc( int n, double *x, double a, double y[] ); void print_results(char *name, char class, int n1, int n2, int n3, int niter, double t, double mops, char *optype, int verified); double start[64], elapsed[64]; double elapsed_time( void ); void timer_clear( int n ); void timer_start( int n ); void timer_stop( int n ); double timer_read( int n ); void wtime(double *t); int main() { double Mops, t1, t2, t3, t4, x1, x2; double sx, sy, tm, an, tt, gc; double sx_verify_value, sy_verify_value, sx_err, sy_err; int np; int i, ik, kk, l, k, nit; int k_offset, j; int verified; double dum[3] = {1.0, 1.0, 1.0}; char size[16]; double x[2 * NK]; double q[NQ]; FILE *fp; //-------------------------------------------------------------------- // Because the size of the problem is too large to store in a 32-bit // integer for some classes, we put it into a string (for printing). // Have to strip off the decimal point put in there by the floating // point print statement (internal file) //-------------------------------------------------------------------- sprintf(size, "%15.0lf", pow(2.0, M + 1)); j = 14; if (size[j] == '.') j--; size[j + 1] = '\0'; printf("\n\n NAS Parallel Benchmarks (NPB3.3-SER-C) - EP Benchmark\n"); printf("\n Number of random numbers generated: %15s\n", size); verified = 0; //-------------------------------------------------------------------- // Compute the number of "batches" of random number pairs generated // per processor. Adjust if the number of processors does not evenly // divide the total number //-------------------------------------------------------------------- np = NN; //-------------------------------------------------------------------- // Call the random number generator functions and initialize // the x-array to reduce the effects of paging on the timings. // Also, call all mathematical functions that are used. Make // sure these initializations cannot be eliminated as dead code. //-------------------------------------------------------------------- vranlc(0, &dum[0], dum[1], &dum[2]); dum[0] = randlc(&dum[1], dum[2]); for (i = 0; i < 2 * NK; i++) { x[i] = -1.0e99; } Mops = log(sqrt(fabs(MAX(1.0, 1.0)))); timer_clear(0); timer_clear(1); timer_clear(2); timer_start(0); t1 = A; vranlc(0, &t1, A, x); //-------------------------------------------------------------------- // Compute AN = A ^ (2 * NK) (mod 2^46). //-------------------------------------------------------------------- t1 = A; for (i = 0; i < MK + 1; i++) { t2 = randlc(&t1, t1); } an = t1; tt = S; gc = 0.0; sx = 0.0; sy = 0.0; for (i = 0; i < NQ; i++) { q[i] = 0.0; } //-------------------------------------------------------------------- // Each instance of this loop may be performed independently. We compute // the k offsets separately to take into account the fact that some nodes // have more numbers to generate than others //-------------------------------------------------------------------- k_offset = -1; for (k = 1; k <= np; k++) { kk = k_offset + k; t1 = S; t2 = an; // Find starting seed t1 for this kk. for (i = 1; i <= 100; i++) { ik = kk / 2; if ((2 * ik) != kk) t3 = randlc(&t1, t2); if (ik == 0) break; t3 = randlc(&t2, t2); kk = ik; } //-------------------------------------------------------------------- // Compute uniform pseudorandom numbers. //-------------------------------------------------------------------- vranlc(2 * NK, &t1, A, x); //-------------------------------------------------------------------- // Compute Gaussian deviates by acceptance-rejection method and // tally counts in concentri//square annuli. This loop is not // vectorizable. //-------------------------------------------------------------------- for (i = 0; i < NK; i++) { x1 = 2.0 * x[2 * i] - 1.0; x2 = 2.0 * x[2 * i + 1] - 1.0; t1 = x1 * x1 + x2 * x2; if (t1 <= 1.0) { t2 = sqrt(-2.0 * log(t1) / t1); t3 = (x1 * t2); t4 = (x2 * t2); l = MAX(fabs(t3), fabs(t4)); q[l] = q[l] + 1.0; sx = sx + t3; sy = sy + t4; } } } for (i = 0; i < NQ; i++) { gc = gc + q[i]; } timer_stop(0); tm = timer_read(0); nit = 0; verified = 1; if (M == 24) { sx_verify_value = -3.247834652034740e+3; sy_verify_value = -6.958407078382297e+3; } else if (M == 25) { sx_verify_value = -2.863319731645753e+3; sy_verify_value = -6.320053679109499e+3; } else if (M == 28) { sx_verify_value = -4.295875165629892e+3; sy_verify_value = -1.580732573678431e+4; } else if (M == 30) { sx_verify_value = 4.033815542441498e+4; sy_verify_value = -2.660669192809235e+4; } else if (M == 32) { sx_verify_value = 4.764367927995374e+4; sy_verify_value = -8.084072988043731e+4; } else if (M == 36) { sx_verify_value = 1.982481200946593e+5; sy_verify_value = -1.020596636361769e+5; } else if (M == 40) { sx_verify_value = -5.319717441530e+05; sy_verify_value = -3.688834557731e+05; } else { verified = 0; } if (verified) { sx_err = fabs((sx - sx_verify_value) / sx_verify_value); sy_err = fabs((sy - sy_verify_value) / sy_verify_value); verified = ((sx_err <= EPSILON) && (sy_err <= EPSILON)); } Mops = pow(2.0, M + 1) / tm / 1000000.0; printf("\nEP Benchmark Results:\n\n"); printf("CPU Time =%10.4lf\n", tm); printf("N = 2^%5d\n", M); printf("No. Gaussian Pairs = %15.0lf\n", gc); printf("Sums = %25.15lE %25.15lE\n", sx, sy); printf("Counts: \n"); for (i = 0; i < NQ; i++) { printf("%3d%15.0lf\n", i, q[i]); } print_results("EP", CLASS, M + 1, 0, 0, nit, tm, Mops, "Random numbers generated", verified); int exitValue = verified ? 0 : 1; return exitValue; } double randlc( double *x, double a ) { //-------------------------------------------------------------------- // // This routine returns a uniform pseudorandom double precision number in the // range (0, 1) by using the linear congruential generator // // x_{k+1} = a x_k (mod 2^46) // // where 0 < x_k < 2^46 and 0 < a < 2^46. This scheme generates 2^44 numbers // before repeating. The argument A is the same as 'a' in the above formula, // and X is the same as x_0. A and X must be odd double precision integers // in the range (1, 2^46). The returned value RANDLC is normalized to be // between 0 and 1, i.e. RANDLC = 2^(-46) * x_1. X is updated to contain // the new seed x_1, so that subsequent calls to RANDLC using the same // arguments will generate a continuous sequence. // // This routine should produce the same results on any computer with at least // 48 mantissa bits in double precision floating point data. On 64 bit // systems, double precision should be disabled. // // David H. Bailey October 26, 1990 // //-------------------------------------------------------------------- // r23 = pow(0.5, 23.0); //// pow(0.5, 23.0) = 1.1920928955078125e-07 // r46 = r23 * r23; // t23 = pow(2.0, 23.0); //// pow(2.0, 23.0) = 8.388608e+06 // t46 = t23 * t23; const double r23 = 1.1920928955078125e-07; const double r46 = r23 * r23; const double t23 = 8.388608e+06; const double t46 = t23 * t23; double t1, t2, t3, t4, a1, a2, x1, x2, z; double r; //-------------------------------------------------------------------- // Break A into two parts such that A = 2^23 * A1 + A2. //-------------------------------------------------------------------- t1 = r23 * a; a1 = (int) t1; a2 = a - t23 * a1; //-------------------------------------------------------------------- // Break X into two parts such that X = 2^23 * X1 + X2, compute // Z = A1 * X2 + A2 * X1 (mod 2^23), and then // X = 2^23 * Z + A2 * X2 (mod 2^46). //-------------------------------------------------------------------- t1 = r23 * (*x); x1 = (int) t1; x2 = *x - t23 * x1; t1 = a1 * x2 + a2 * x1; t2 = (int) (r23 * t1); z = t1 - t23 * t2; t3 = t23 * z + a2 * x2; t4 = (int) (r46 * t3); *x = t3 - t46 * t4; r = r46 * (*x); return r; } void vranlc( int n, double *x, double a, double y[] ) { //-------------------------------------------------------------------- // // This routine generates N uniform pseudorandom double precision numbers in // the range (0, 1) by using the linear congruential generator // // x_{k+1} = a x_k (mod 2^46) // // where 0 < x_k < 2^46 and 0 < a < 2^46. This scheme generates 2^44 numbers // before repeating. The argument A is the same as 'a' in the above formula, // and X is the same as x_0. A and X must be odd double precision integers // in the range (1, 2^46). The N results are placed in Y and are normalized // to be between 0 and 1. X is updated to contain the new seed, so that // subsequent calls to VRANLC using the same arguments will generate a // continuous sequence. If N is zero, only initialization is performed, and // the variables X, A and Y are ignored. // // This routine is the standard version designed for scalar or RISC systems. // However, it should produce the same results on any single processor // computer with at least 48 mantissa bits in double precision floating point // data. On 64 bit systems, double precision should be disabled. // //-------------------------------------------------------------------- // r23 = pow(0.5, 23.0); //// pow(0.5, 23.0) = 1.1920928955078125e-07 // r46 = r23 * r23; // t23 = pow(2.0, 23.0); //// pow(2.0, 23.0) = 8.388608e+06 // t46 = t23 * t23; const double r23 = 1.1920928955078125e-07; const double r46 = r23 * r23; const double t23 = 8.388608e+06; const double t46 = t23 * t23; double t1, t2, t3, t4, a1, a2, x1, x2, z; int i; //-------------------------------------------------------------------- // Break A into two parts such that A = 2^23 * A1 + A2. //-------------------------------------------------------------------- t1 = r23 * a; a1 = (int) t1; a2 = a - t23 * a1; //-------------------------------------------------------------------- // Generate N results. This loop is not vectorizable. //-------------------------------------------------------------------- for ( i = 0; i < n; i++ ) { //-------------------------------------------------------------------- // Break X into two parts such that X = 2^23 * X1 + X2, compute // Z = A1 * X2 + A2 * X1 (mod 2^23), and then // X = 2^23 * Z + A2 * X2 (mod 2^46). //-------------------------------------------------------------------- t1 = r23 * (*x); x1 = (int) t1; x2 = *x - t23 * x1; t1 = a1 * x2 + a2 * x1; t2 = (int) (r23 * t1); z = t1 - t23 * t2; t3 = t23 * z + a2 * x2; t4 = (int) (r46 * t3) ; *x = t3 - t46 * t4; y[i] = r46 * (*x); } return; } void print_results(char *name, char class, int n1, int n2, int n3, int niter, double t, double mops, char *optype, int verified) { char size[16]; int j; printf( "\n\n %s Benchmark Completed.\n", name ); printf( " Class = %12c\n", class ); // If this is not a grid-based problem (EP, FT, CG), then // we only print n1, which contains some measure of the // problem size. In that case, n2 and n3 are both zero. // Otherwise, we print the grid size n1xn2xn3 if ( ( n2 == 0 ) && ( n3 == 0 ) ) { if ( ( name[0] == 'E' ) && ( name[1] == 'P' ) ) { sprintf( size, "%15.0lf", pow(2.0, n1) ); j = 14; if ( size[j] == '.' ) { size[j] = ' '; j--; } size[j + 1] = '\0'; printf( " Size = %15s\n", size ); } else { printf( " Size = %12d\n", n1 ); } } else { printf( " Size = %4dx%4dx%4d\n", n1, n2, n3 ); } printf( " Iterations = %12d\n", niter ); printf( " Time in seconds = %12.2lf\n", t ); printf( " Mop/s total = %15.2lf\n", mops ); printf( " Operation type = %24s\n", optype ); if ( verified ) printf( " Verification = %12s\n", "SUCCESSFUL" ); else printf( " Verification = %12s\n", "UNSUCCESSFUL" ); } void wtime(double *t) { static int sec = -1; struct timeval tv; gettimeofday(&tv, (void *)0); if (sec < 0) sec = tv.tv_sec; *t = (tv.tv_sec - sec) + 1.0e-6 * tv.tv_usec; } /*****************************************************************/ /****** E L A P S E D _ T I M E ******/ /*****************************************************************/ double elapsed_time( void ) { double t; wtime( &t ); return ( t ); } /*****************************************************************/ /****** T I M E R _ C L E A R ******/ /*****************************************************************/ void timer_clear( int n ) { elapsed[n] = 0.0; } /*****************************************************************/ /****** T I M E R _ S T A R T ******/ /*****************************************************************/ void timer_start( int n ) { start[n] = elapsed_time(); } /*****************************************************************/ /****** T I M E R _ S T O P ******/ /*****************************************************************/ void timer_stop( int n ) { double t, now; now = elapsed_time(); t = now - start[n]; elapsed[n] += t; } /*****************************************************************/ /****** T I M E R _ R E A D ******/ /*****************************************************************/ double timer_read( int n ) { return ( elapsed[n] ); }
the_stack_data/875774.c
#include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include <netinet/in.h> #include <sys/time.h> #include <sys/ioctl.h> #include <unistd.h> #include <stdlib.h> int main() { int server_sockfd, client_sockfd; int server_len, client_len; struct sockaddr_in server_address; struct sockaddr_in client_address; int result; fd_set readfds, testfds; server_sockfd = socket(AF_INET, SOCK_STREAM, 0);//建立服务器端socket server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = htonl(INADDR_ANY); server_address.sin_port = htons(9734); server_len = sizeof(server_address); bind(server_sockfd, (struct sockaddr *)&server_address, server_len); listen(server_sockfd, 5); FD_ZERO(&readfds); FD_SET(server_sockfd, &readfds);//将服务器端socket加入到集合中 while(1) { char ch; int fd; int nread; testfds = readfds; printf("server waiting/n"); /*无限期阻塞,并测试文件描述符变动 */ result = select(FD_SETSIZE, &testfds, (fd_set *)0,(fd_set *)0, (struct timeval *) 0); if(result < 1) { perror("server5"); exit(1); } /*扫描所有的文件描述符*/ for(fd = 0; fd < FD_SETSIZE; fd++) { /*找到相关文件描述符*/ if(FD_ISSET(fd,&testfds)) { /*判断是否为服务器套接字,是则表示为客户请求连接。*/ if(fd == server_sockfd) { client_len = sizeof(client_address); client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, &client_len); FD_SET(client_sockfd, &readfds);//将客户端socket加入到集合中 printf("adding client on fd %d/n", client_sockfd); } /*客户端socket中有数据请求时*/ else { ioctl(fd, FIONREAD, &nread);//取得数据量交给nread /*客户数据请求完毕,关闭套接字,从集合中清除相应描述符 */ if(nread == 0) { close(fd); FD_CLR(fd, &readfds); printf("removing client on fd %d/n", fd); } /*处理客户数据请求*/ else { read(fd, &ch, 1); sleep(5); printf("serving client on fd %d/n", fd); ch++; write(fd, &ch, 1); } } } } } }
the_stack_data/68219.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> int numDecodings(char *s) { if (s == NULL) return 0; int len = strlen(s); if (len == 0) return 0; int *dp = (int *)malloc((len + 1) * sizeof(int)); int i; dp[0] = 1; dp[1] = (s[0] == '0') ? 0 : 1; for (i = 2; i < len + 1; i++) { dp[i] = (s[i - 1] == '0') ? 0 : dp[i - 1]; /*1 step*/ if (s[i - 2] == '1' || (s[i - 2] == '2' && s[i - 1] <= '6')) /*2 steps*/ dp[i] += dp[i - 2]; } int ans = dp[len]; free(dp); return ans; } int main() { char s0[] = "301"; char s1[] = ""; char s2[] = "0"; char s3[] = "01"; char s4[] = "112"; assert(numDecodings(s0) == 0); assert(numDecodings(s1) == 0); assert(numDecodings(s2) == 0); assert(numDecodings(s3) == 0); assert(numDecodings(s4) == 3); printf("all tests passed!\n"); return 0; }
the_stack_data/61074491.c
/* pointy.c * Pointy interpreter * by Marinus Oosters * * see http://esoteric.voxelperfect.net/wiki/Pointy * * Memory cells are 32-bit, unsigned integers. * Labels are not case-sensitive. * Comments start with ; (because that's what they did on the esolang wiki page), * or with # (so I can do #!/), and end with a newline. */ #include <stdio.h> #define MEMSZ 0x10000 #define N_LBL 0x100 // max number of labels in a program #define LBL_LEN 20 // max label length #define LINE_LEN 200 // max line length #define N_LINES 0x10000 // max number of lines in a program; #define ARG_LEN 140 // max argument length /* err */ void die(char *errmsg) { fprintf(stderr, "error: %s\n", errmsg); exit(0); } /* labels */ typedef struct { char name [LBL_LEN]; int line; } label; char c[50]; int lbl_amt=0; label lbls[N_LBL]; int getlbl(char *l) { // get line no for label name int i,r=-1; for (i=0; i<lbl_amt; i++) { if (!strcasecmp(lbls[i].name,l)) { r = lbls[i].line; break; } } if (r == -1) { sprintf(c,"%s does not exist.",l); die(c); } return r; } void setlbl(char *l, int ln) { // set label if (lbl_amt < N_LBL) { lbls[lbl_amt].line = ln; strcpy(lbls[lbl_amt++].name,l); } else { sprintf(c,"cannot store %s, too many labels (max %n).",l,N_LBL); die(c); } } // memory unsigned int memory[MEMSZ]; // dereference int value(char *n) { // gets value for number/pointer in n int r=0,i,a=0; char *t=n; while (*t && !isdigit(*t)) t++; r = atoi(t); // got the number, start dereferencing while (*n && !isdigit(*n)) if (*(n++)=='*') a++; for (;a;a--) { if (r<0||r>MEMSZ) { sprintf(c,"cannot dereference, %d is outside allocated memory (%d-%d)",r,0,MEMSZ); die(c); } r = memory[r]; } return r; } // some more error checking int memval(int n) { if (n<0||n>MEMSZ) { sprintf(c,"cannot dereference, %d is outside allocated memory (%d-%d)",n,0,MEMSZ); die(c); } return memory[n]; } void setval(int n, int v) { if (n<0||n>MEMSZ) { sprintf(c,"cannot assign, %d is outside allocated memory (%d-%d)",n,0,MEMSZ); die(c); } memory[n]=v; } // program code typedef enum { LBL, CPY, INC, DEC, OUT, INP } instr_t; typedef struct { instr_t instruction; char op1[ARG_LEN]; char op2[ARG_LEN]; } line; line pgm [N_LINES]; int n_of_lines=0, ip=0; // read program void readprogram(char *filename){ char buf[LINE_LEN], *lc=buf, ch, *ptr; bzero(pgm,sizeof(pgm)); bzero(buf,LINE_LEN); // read in the program FILE *f; f=fopen(filename, "r"); if (!f) { sprintf(c,"cannot open %s for reading",filename); die(c); } while (!feof(f)) { ch = fgetc(f); if (ch==';'||ch=='#') while (!feof(f) && (ch=fgetc(f))!='\n'); if (ch=='\n' || feof(f)) { // try to parse. *lc = 0; lc = buf; while (*lc && isspace(*lc)) lc++; if (!*lc) { // empty line or only a comment bzero(buf,LINE_LEN); lc=buf; continue; } // get instruction if (!strncasecmp(lc,"LBL",3)) pgm[n_of_lines].instruction = LBL; else if (!strncasecmp(lc,"CPY",3)) pgm[n_of_lines].instruction = CPY; else if (!strncasecmp(lc,"INC",3)) pgm[n_of_lines].instruction = INC; else if (!strncasecmp(lc,"DEC",3)) pgm[n_of_lines].instruction = DEC; else if (!strncasecmp(lc,"OUT",3)) pgm[n_of_lines].instruction = OUT; else if (!strncasecmp(lc,"INP",3)) pgm[n_of_lines].instruction = INP; else { strncpy(c,lc,3); c[3] = 0; sprintf(c,"%d: '%s' is not a valid instruction.",n_of_lines+1,c); die(c); } // get first argument lc += 3; while (*lc && isspace(*lc)) lc++; if (!*lc) { sprintf(c,"%d: no arguments given.",n_of_lines); die(c); } ptr = pgm[n_of_lines].op1; while (*lc && !isspace(*lc)) *(ptr++) = *(lc++); // if CPY or DEC, get second output. if (pgm[n_of_lines].instruction == CPY || pgm[n_of_lines].instruction == DEC) { while (*lc && isspace(*lc)) lc++; if (!*lc) { sprintf(c,"%d: instruction requires two arguments, but only one was given.",n_of_lines+1); die(c); } ptr = pgm[n_of_lines].op2; while (*lc && !isspace(*lc)) *(ptr++) = *(lc++); } // we're done. n_of_lines++; bzero(buf,LINE_LEN); lc = buf; } else *(lc++)=ch; } // find all the labels and store them for (ip = 0; ip < n_of_lines; ip++) if (pgm[ip].instruction == LBL) setlbl(pgm[ip].op1, ip); } /* Of a 209-line interpreter, the actual interpreting function is only 17 lines... */ void run() { // run the program for (ip = 0; ip < n_of_lines; ip++) { switch (pgm[ip].instruction) { case LBL: break; // don't do anything, labels have already been stored. case CPY: setval(value(pgm[ip].op2),value(pgm[ip].op1)); break; case INC: setval(value(pgm[ip].op1),memval(value(pgm[ip].op1))+1); break; case DEC: if (memval(value(pgm[ip].op1))) { setval(value(pgm[ip].op1), memval(value(pgm[ip].op1))-1); } else { ip = getlbl(pgm[ip].op2); }; break; case OUT: putchar(value(pgm[ip].op1));break; case INP: setval(value(pgm[ip].op1),feof(stdin)?0:getchar());break; } } } int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr,"%s - Pointy interpreter\nWritten by Marinus Oosters\n\tusage: %s program\n\n", argv[0],argv[0]); exit(0); } readprogram(argv[1]); run(); return 0; }
the_stack_data/67326482.c
// // vsum.c : Demo of multi-target mulit-source OpenMP offload // #include <stdio.h> void vsum(int*a, int*b, int*c, int N){ #pragma omp target teams map(to: a[0:N],b[0:N]) map(from:c[0:N]) #pragma omp distribute parallel for for(int i=0;i<N;i++) { c[i]=a[i]+b[i]; } }
the_stack_data/1270118.c
#include <stdio.h> #include <stdlib.h> #include <math.h> int isprime(int number) { int i; double lim=sqrt(number)+1; //printf("lim of %d: %g\n", number, lim); if(number==2) return 1; if(number%2==0) return 0; for(i=3; i<lim; i+=2) if (number % i == 0) return 0; return 1; } int main(void) { int i, limit=2000000; unsigned long long int sum=0; for(i=2;i<limit;i++) if(isprime(i)) { sum+=i; printf("i = %d || sum = %llu\n", i, sum); } printf("Sum of primes up to %d: %llu\n", limit, sum, sum); system("PAUSE"); return 0; }