file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/29366.c
/* { dg-do compile } */ /* { dg-options "-fno-strict-overflow -O2 -fdump-tree-optimized" } */ /* Source: Ian Lance Taylor. Dual of strict-overflow-4.c. */ /* We can only simplify the conditional when using strict overflow semantics. */ int foo (int i) { return i + 1 > i; } /* { dg-final { scan-tree-dump "\[^ \]*_.(\\\(D\\\))? (>|<) \[^ \]*_." "optimized" } } */
the_stack_data/82950790.c
// // BRKeccak.h // // Created by null3128 on 03/12/2018. // Copyright (c) 2018 AtomMiner.com // // 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 <stdint.h> #include <string.h> #define KECCAK_ROUNDS 24 #ifndef ROTL64 #define ROTL64(x, y) (((x) << (y)) | ((x) >> (64 - (y)))) #endif const uint64_t BR__keccakf_rndc[24] = { 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008 }; const int BR__keccakf_rotc[24] = { 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44 }; const int BR__keccakf_piln[24] = { 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1 }; void BR__keccakf__internal(uint64_t st[25], int rounds) { int i, j, round; uint64_t t, bc[5]; for (round = 0; round < rounds; round++) { for (i = 0; i < 5; i++) bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20]; for (i = 0; i < 5; i++) { t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1); for (j = 0; j < 25; j += 5) st[j + i] ^= t; } t = st[1]; for (i = 0; i < 24; i++) { j = BR__keccakf_piln[i]; bc[0] = st[j]; st[j] = ROTL64(t, BR__keccakf_rotc[i]); t = bc[0]; } for (j = 0; j < 25; j += 5) { for (i = 0; i < 5; i++) bc[i] = st[j + i]; for (i = 0; i < 5; i++) st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5]; } st[0] ^= BR__keccakf_rndc[round]; } } int MWKeccak256(uint8_t *hash, const uint8_t *in, size_t inlen) { uint64_t st[25]; uint8_t temp[144]; int i, rsiz, rsizw; rsiz = 136; rsizw = rsiz / 8; memset(st, 0, sizeof(st)); for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) { for (i = 0; i < rsizw; i++) st[i] ^= ((uint64_t *) in)[i]; BR__keccakf__internal(st, KECCAK_ROUNDS); } memcpy(temp, in, inlen); temp[inlen++] = 1; memset(temp + inlen, 0, rsiz - inlen); temp[rsiz - 1] |= 0x80; for (i = 0; i < rsizw; i++) st[i] ^= ((uint64_t *) temp)[i]; BR__keccakf__internal(st, KECCAK_ROUNDS); memcpy(hash, st, 32); return 0; }
the_stack_data/31389214.c
#include <stdio.h> int main() { /* * comments * declarations * variables * arithmetic expressions * loops * formatted output * * celsius = 5*(fahr-32)/9*/ int lower, upper; lower = 0; upper = 300; int step = 20; int fahr = lower; while (fahr <= upper) { float celsius = 5.0/9.0*(fahr-32); printf("farh: %3d, celsius: %3.3f \n", fahr, celsius); fahr = fahr + step; } }
the_stack_data/95449557.c
#include <stdio.h> int main() { int a; float b; printf("Enter integer and then a float: "); //Taking multiple inputs scanf ("%d%f", &a, &b); printf("You entered %d and %f", a, b); return 0; }
the_stack_data/107219.c
/* Take the rat from (0, 0) to (N, N in a maze) */ #include<stdio.h> #include<stdbool.h> #define N 4 int row[] = {0, 1, 1}; int col[] = {1, 1, 0}; bool isSafe(int maze[][N], int x, int y, int sol[][N]) { if(x < 0 || y>=N ) { return false; } if(maze[x][y] == 0 || sol[x][y] == 1) { return false; } return true; } bool solve_maze_util(int maze[][N], int x, int y, int sol[][N]) { // base case if(x==N-1 && y== N-1) { return true; } for(int k=0; k<3; k++) { if(isSafe(maze, x+row[k], y+col[k], sol)) { sol[x+row[k]][y+col[k]] = 1; if(solve_maze_util(maze, x+row[k], y+col[k], sol)) { return true; } sol[x+row[k]][y+col[k]] = 0; } } return false; } void print_sol(int sol[][N]) { for(int i=0; i<N; i++) { for(int j=0; j<N; j++) { printf("%d", sol[i][j]); } printf("\n"); } } void solve_maze(int maze[][N]) { int sol[N][N] = {0}; sol[0][0] = 1; if(solve_maze_util(maze, 0, 0, sol)) { print_sol(sol); } else { printf("solution does not exixts"); } } void main() { // 1 means open // 0 means block int maze[N][N] = { {1, 0, 0, 0}, {1, 1, 0, 1}, {0, 1, 0, 0}, {1, 1, 1, 1} }; solve_maze(maze); }
the_stack_data/184519163.c
/* * ◆◆ * Solution to Homework Problem 2.82 (Page 161) * * Consider numbers having a binary representation consisting of an infinite * string of the form 0.y y y y y y . . ., where y is a k-bit sequence. For * example, the binary representation of 1 3 is 0.01010101 . . . (y = 01), * while the representation of 5 1 is 0.001100110011 . . . (y = 0011). * * A. Let Y = B2U k (y), that is, the number having binary representation y. * Give a formula in terms of Y and k for the value represented by the * infinite string. * Hint: Consider the effect of shifting the binary point k positions to the right. * * B.What is the numeric value of the string for the following values of y? * * (a) 101 * (b) 0110 * (c) 010011 */ /* * My Answer * * A: We let x as the loop sequence, get following formula * x << k = x + Y, so easy to infer x = Y / (2^k - 1). * * Verify: * x = Y/2^k + Y/2^2k + Y/2^3k + ... + Y/2^nk * = Y(1/2^k + 1/2^2k + 1/2^3k + ... + 1/2^nk) * * include math formula: Y(1/2k * (1 -(1/2^k)^n) * * Since (1/2^k)^n -->> 0 * So that x = Y/(2^k-1) * * B: * (a) 1/7 * (b) 3/5 * (c) 7/63 1/9 * */
the_stack_data/41924.c
/* * author: Mahmud Ahsan * https://github.com/mahmudahsan * blog: http://thinkdiff.net * http://banglaprogramming.com * License: MIT License */ /* * Conditional Operator / Ternary operator * condition ? expression1 : expression2 */ #include <stdio.h> int main(){ int number; printf("Please enter a number: "); scanf("%d", &number); _Bool isEven = number % 2 == 0 ? 1 : 0; /* #include <stdbool.h> bool isEven = number % 2 == 0 ? true : false; */ if (isEven){ printf("%d is an even number\n", number); } else { printf("%d is a odd number\n", number); } return 0; }
the_stack_data/25138074.c
#include <stdio.h> void main(){ printf("Hello,Engine!"); }
the_stack_data/140765028.c
#pragma once #ifdef __AVR__ #include <avr/io.h> #include <avr/pgmspace.h> #elif defined(ESP8266) #include <pgmspace.h> #else #define PROGMEM #endif const unsigned char font[] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00, 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 0x00, 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 0x00, 0x18, 0x3C, 0x7E, 0x3C, 0x18, 0x00, 0x1C, 0x57, 0x7D, 0x57, 0x1C, 0x00, 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 0x00, 0x00, 0x18, 0x3C, 0x18, 0x00, 0x00, 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 0x00, 0x00, 0x18, 0x24, 0x18, 0x00, 0x00, 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 0x00, 0x30, 0x48, 0x3A, 0x06, 0x0E, 0x00, 0x26, 0x29, 0x79, 0x29, 0x26, 0x00, 0x40, 0x7F, 0x05, 0x05, 0x07, 0x00, 0x40, 0x7F, 0x05, 0x25, 0x3F, 0x00, 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 0x00, 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 0x00, 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 0x00, 0x14, 0x22, 0x7F, 0x22, 0x14, 0x00, 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 0x00, 0x06, 0x09, 0x7F, 0x01, 0x7F, 0x00, 0x00, 0x66, 0x89, 0x95, 0x6A, 0x00, 0x60, 0x60, 0x60, 0x60, 0x60, 0x00, 0x94, 0xA2, 0xFF, 0xA2, 0x94, 0x00, 0x08, 0x04, 0x7E, 0x04, 0x08, 0x00, 0x10, 0x20, 0x7E, 0x20, 0x10, 0x00, 0x08, 0x08, 0x2A, 0x1C, 0x08, 0x00, 0x08, 0x1C, 0x2A, 0x08, 0x08, 0x00, 0x1E, 0x10, 0x10, 0x10, 0x10, 0x00, 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 0x00, 0x30, 0x38, 0x3E, 0x38, 0x30, 0x00, 0x06, 0x0E, 0x3E, 0x0E, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00, 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00, 0x23, 0x13, 0x08, 0x64, 0x62, 0x00, 0x36, 0x49, 0x56, 0x20, 0x50, 0x00, 0x00, 0x08, 0x07, 0x03, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00, 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00, 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00, 0x00, 0x80, 0x70, 0x30, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0x00, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00, 0x72, 0x49, 0x49, 0x49, 0x46, 0x00, 0x21, 0x41, 0x49, 0x4D, 0x33, 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00, 0x27, 0x45, 0x45, 0x45, 0x39, 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x00, 0x41, 0x21, 0x11, 0x09, 0x07, 0x00, 0x36, 0x49, 0x49, 0x49, 0x36, 0x00, 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x40, 0x34, 0x00, 0x00, 0x00, 0x00, 0x08, 0x14, 0x22, 0x41, 0x00, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00, 0x00, 0x41, 0x22, 0x14, 0x08, 0x00, 0x02, 0x01, 0x59, 0x09, 0x06, 0x00, 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00, 0x3E, 0x41, 0x41, 0x51, 0x73, 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00, 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00, 0x26, 0x49, 0x49, 0x49, 0x32, 0x00, 0x03, 0x01, 0x7F, 0x01, 0x03, 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00, 0x63, 0x14, 0x08, 0x14, 0x63, 0x00, 0x03, 0x04, 0x78, 0x04, 0x03, 0x00, 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00, 0x00, 0x7F, 0x41, 0x41, 0x41, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00, 0x00, 0x41, 0x41, 0x41, 0x7F, 0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00, 0x03, 0x07, 0x08, 0x00, 0x00, 0x20, 0x54, 0x54, 0x78, 0x40, 0x00, 0x7F, 0x28, 0x44, 0x44, 0x38, 0x00, 0x38, 0x44, 0x44, 0x44, 0x28, 0x00, 0x38, 0x44, 0x44, 0x28, 0x7F, 0x00, 0x38, 0x54, 0x54, 0x54, 0x18, 0x00, 0x00, 0x08, 0x7E, 0x09, 0x02, 0x00, 0x58, 0xA4, 0xA4, 0x9C, 0x78, 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00, 0x00, 0x20, 0x40, 0x40, 0x3D, 0x00, 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00, 0x00, 0x7C, 0x04, 0x78, 0x04, 0x78, 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78, 0x00, 0x38, 0x44, 0x44, 0x44, 0x38, 0x00, 0xFC, 0x18, 0x24, 0x24, 0x18, 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC, 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08, 0x00, 0x48, 0x54, 0x54, 0x54, 0x24, 0x00, 0x04, 0x04, 0x3F, 0x44, 0x24, 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00, 0x44, 0x28, 0x10, 0x28, 0x44, 0x00, 0x4C, 0x10, 0x10, 0x10, 0x7C, 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00, 0x00, 0x08, 0x36, 0x41, 0x00, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x00, 0x41, 0x36, 0x08, 0x00, 0x00, 0x02, 0x01, 0x02, 0x04, 0x02, 0x00, 0x3C, 0x26, 0x23, 0x26, 0x3C, 0x00, 0x00, 0x00, 0xF0, 0xF8, 0x9C, 0x0C, 0x0C, 0x1C, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0xE0, 0xF8, 0x1C, 0x0C, 0x0C, 0x9C, 0xF8, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xFC, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE, 0xFE, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x60, 0xF8, 0x0C, 0x24, 0xE6, 0xE6, 0x24, 0x06, 0x06, 0x24, 0xE6, 0xE6, 0x24, 0x06, 0x06, 0x24, 0xE6, 0xE6, 0x24, 0x0C, 0xF8, 0x60, 0x00, 0x20, 0x30, 0x18, 0x0C, 0x06, 0xC3, 0xC3, 0x06, 0x0C, 0x18, 0x30, 0x20, 0x01, 0x03, 0x06, 0x0C, 0x18, 0x33, 0x33, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x81, 0xC3, 0xC3, 0xC3, 0xFF, 0xFF, 0xC3, 0xC3, 0xC3, 0xFF, 0xFF, 0xC3, 0xC3, 0xC3, 0x81, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x83, 0xC0, 0xC0, 0xE0, 0x60, 0x70, 0x30, 0x38, 0x18, 0x1C, 0x0C, 0x0E, 0x06, 0x07, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3C, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x18, 0x3C, 0x3C, 0x66, 0x66, 0xC3, 0xC3, 0x81, 0x81, 0x00, 0x00, 0x00, 0xDB, 0xFF, 0x00, 0x00, 0x1F, 0x3F, 0x70, 0xE0, 0xC0, 0xC0, 0xFF, 0xFF, 0xC0, 0xC0, 0xE0, 0x70, 0x3F, 0x1F, 0x00, 0x00, 0xFF, 0xDB, 0x00, 0x40, 0x60, 0x30, 0x18, 0x0C, 0xC6, 0xC6, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x02, 0x06, 0x0C, 0x18, 0x30, 0x63, 0x63, 0x30, 0x18, 0x0C, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x1F, 0x39, 0x30, 0x30, 0x18, 0x1F, 0x07, 0x00, 0x00, 0x00, 0x07, 0x1F, 0x38, 0x30, 0x30, 0x39, 0x1F, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0x3F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0x7F, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x00, 0x06, 0x1F, 0x30, 0x20, 0x60, 0x60, 0x20, 0x64, 0x64, 0x26, 0x67, 0x67, 0x26, 0x64, 0x64, 0x20, 0x60, 0x60, 0x20, 0x30, 0x1F, 0x06, 0x00, 0x80, 0xC0, 0x60, 0x30, 0x18, 0xCC, 0xCC, 0x18, 0x30, 0x60, 0xC0, 0x80, 0x04, 0x0C, 0x18, 0x30, 0x60, 0xC3, 0xC3, 0x60, 0x30, 0x18, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
the_stack_data/97013167.c
int j; void residual () { long double s; for (j = 3; j < 9; j++) s -= 3; }
the_stack_data/631090.c
/* mktime - command line implementation of mktime() C library function */ /* Copyright (C) 2013 The Regents of the University of California * See README in this or parent directory for licensing information. */ #include <stdio.h> #include <time.h> #include <unistd.h> #include <stdlib.h> void usage() { fprintf(stderr,"mktime - convert date string to unix timestamp\n"); fprintf(stderr,"usage: mktime YYYY-MM-DD HH:MM:SS\n"); fprintf(stderr,"valid dates: 1970-01-01 00:00:00 to 2038-01-19 03:14:07\n"); } int main( int argc, char **argv) { time_t timep = 0; struct tm tm; if (argc != 3){ usage(); exit(255);} if (sscanf(argv[1], "%4d-%2d-%2d", &(tm.tm_year), &(tm.tm_mon), &(tm.tm_mday)) != 3) { fprintf(stderr,"Couldn't parse given date \"%s\"", argv[1]); exit(255); } if (sscanf(argv[2], "%2d:%2d:%2d", &(tm.tm_hour), &(tm.tm_min), &(tm.tm_sec)) != 3) { fprintf(stderr,"Couldn't parse given date \"%s\"", argv[2]); exit(255); } tm.tm_year -= 1900; tm.tm_mon -= 1; tm.tm_isdst = -1; /* do not know, figure it out */ timep = mktime(&tm); printf("%d-%02d-%02d %02d:%02d:%02d %ld\n", 1900+tm.tm_year, 1+tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (unsigned long)timep); return(0); }
the_stack_data/922732.c
#include <stdio.h> int main( ) { // for ( ; ; ) // { // printf( "Hello" ); // } int i = 0; // SOME CODE HERE while ( i < 100 ) { // 100s of lines of code printf( "While loop now" ); } return 0; }
the_stack_data/159516109.c
/* * This file is part of the QDMA userspace application * to enable the user to execute the QDMA functionality * * Copyright (c) 2018-2019, Xilinx, Inc. * All rights reserved. * * This source code is licensed under BSD-style license (found in the * LICENSE file in the root directory of this source tree) */ #include <stdio.h> #include <stdint.h> #include <unistd.h> #include <time.h> #include <errno.h> #include <sys/types.h> /* * man 2 write: * On Linux, write() (and similar system calls) will transfer at most * 0x7ffff000 (2,147,479,552) bytes, returning the number of bytes * actually transferred. (This is true on both 32-bit and 64-bit * systems.) */ #define RW_MAX_SIZE 0x7ffff000 int verbose = 0; uint64_t getopt_integer(char *optarg) { int rc; uint64_t value; rc = sscanf(optarg, "0x%lx", &value); if (rc <= 0) rc = sscanf(optarg, "%lu", &value); //printf("sscanf() = %d, value = 0x%lx\n", rc, value); return value; } ssize_t read_to_buffer(char *fname, int fd, char *buffer, uint64_t size, uint64_t base) { ssize_t rc; uint64_t count = 0; char *buf = buffer; off_t offset = base; do { /* Support zero byte transfer */ uint64_t bytes = size - count; if (bytes > RW_MAX_SIZE) bytes = RW_MAX_SIZE; if (offset) { rc = lseek(fd, offset, SEEK_SET); if (rc < 0) { fprintf(stderr, "%s, seek off 0x%lx failed %zd.\n", fname, offset, rc); perror("seek file"); return -EIO; } if (rc != offset) { fprintf(stderr, "%s, seek off 0x%lx != 0x%lx.\n", fname, rc, offset); return -EIO; } } /* read data from file into memory buffer */ rc = read(fd, buf, bytes); if (rc < 0) { fprintf(stderr, "%s, read off 0x%lx + 0x%lx failed %zd.\n", fname, offset, bytes, rc); perror("read file"); return -EIO; } if (rc != bytes) { fprintf(stderr, "%s, R off 0x%lx, 0x%lx != 0x%lx.\n", fname, count, rc, bytes); return -EIO; } count += bytes; buf += bytes; offset += bytes; } while (count < size); if (count != size) { fprintf(stderr, "%s, R failed 0x%lx != 0x%lx.\n", fname, count, size); return -EIO; } return count; } ssize_t write_from_buffer(char *fname, int fd, char *buffer, uint64_t size, uint64_t base) { ssize_t rc; uint64_t count = 0; char *buf = buffer; off_t offset = base; do { /* Support zero byte transfer */ uint64_t bytes = size - count; if (bytes > RW_MAX_SIZE) bytes = RW_MAX_SIZE; if (offset) { rc = lseek(fd, offset, SEEK_SET); if (rc < 0) { fprintf(stderr, "%s, seek off 0x%lx failed %zd.\n", fname, offset, rc); perror("seek file"); return -EIO; } if (rc != offset) { fprintf(stderr, "%s, seek off 0x%lx != 0x%lx.\n", fname, rc, offset); return -EIO; } } /* write data to file from memory buffer */ rc = write(fd, buf, bytes); if (rc < 0) { fprintf(stderr, "%s, W off 0x%lx, 0x%lx failed %zd.\n", fname, offset, bytes, rc); perror("write file"); return -EIO; } if (rc != bytes) { fprintf(stderr, "%s, W off 0x%lx, 0x%lx != 0x%lx.\n", fname, offset, rc, bytes); return -EIO; } count += bytes; buf += bytes; offset += bytes; } while (count < size); if (count != size) { fprintf(stderr, "%s, R failed 0x%lx != 0x%lx.\n", fname, count, size); return -EIO; } return count; } /* Subtract timespec t2 from t1 * * Both t1 and t2 must already be normalized * i.e. 0 <= nsec < 1000000000 */ static int timespec_check(struct timespec *t) { if ((t->tv_nsec < 0) || (t->tv_nsec >= 1000000000)) return -1; return 0; } void timespec_sub(struct timespec *t1, struct timespec *t2) { if (timespec_check(t1) < 0) { fprintf(stderr, "invalid time #1: %lld.%.9ld.\n", (long long)t1->tv_sec, t1->tv_nsec); return; } if (timespec_check(t2) < 0) { fprintf(stderr, "invalid time #2: %lld.%.9ld.\n", (long long)t2->tv_sec, t2->tv_nsec); return; } t1->tv_sec -= t2->tv_sec; t1->tv_nsec -= t2->tv_nsec; if (t1->tv_nsec >= 1000000000) { t1->tv_sec++; t1->tv_nsec -= 1000000000; } else if (t1->tv_nsec < 0) { t1->tv_sec--; t1->tv_nsec += 1000000000; } }
the_stack_data/118355.c
// RUN: %clang_analyze_cc1 -analyzer-checker=core.builtin.NoReturnFunctions -analyzer-display-progress %s 2>&1 | FileCheck %s // Do not analyze test1() again because it was inlined void test1(); void test2() { test1(); } void test1() { } // CHECK: analysis-order.c test2 // CHECK-NEXT: analysis-order.c test1 // CHECK-NEXT: analysis-order.c test2
the_stack_data/630318.c
#include <errno.h> #include <stdarg.h> #include <string.h> #include <syslog.h> #define FORMAT_BUFFER_SIZE 128 #define LOGMSG_ERROR_PREFIX "[%s:%d] %s (errno=%d)" static const char *LOGMSG_ERROR_LEADING = LOGMSG_ERROR_PREFIX ": "; static const char *LOGMSG_ERROR_LARGE = LOGMSG_ERROR_PREFIX " ..."; #define LOGMSG_INFO_PREFIX "[%s:%d]" static const char *LOGMSG_INFO_LEADING = LOGMSG_INFO_PREFIX ": "; static const char *LOGMSG_INFO_LARGE = LOGMSG_INFO_PREFIX " ..."; #ifdef MOCKED_VSYSLOG #warning "with mocked vsyslog" #define vsyslog MOCKED_VSYSLOG void MOCKED_VSYSLOG(int priority, const char *format, va_list ap); #endif /* MOCKED_VSYSLOG */ static void _recordlogs_internal_record_impl(size_t msg_leading_len, const char *msg_leading, const char *msg_large, int priority, const char *format, va_list ap) { size_t fmtbuf_remain; fmtbuf_remain = FORMAT_BUFFER_SIZE - msg_leading_len - 1; if (strlen(format) > fmtbuf_remain) { vsyslog(priority, msg_large, ap); vsyslog(priority, format, ap); } else { char fmtbuf[FORMAT_BUFFER_SIZE]; strncpy(fmtbuf, msg_leading, FORMAT_BUFFER_SIZE); strncpy(fmtbuf + msg_leading_len, format, fmtbuf_remain); fmtbuf[(FORMAT_BUFFER_SIZE - 1)] = '\0'; vsyslog(priority, fmtbuf, ap); } } void _recordlogs_internal_record_error(int priority, const char *format, ...) { va_list ap; va_start(ap, format); _recordlogs_internal_record_impl(strlen(LOGMSG_ERROR_LEADING), LOGMSG_ERROR_LEADING, LOGMSG_ERROR_LARGE, priority, format, ap); va_end(ap); } void _recordlogs_internal_record_info(int priority, const char *format, ...) { va_list ap; va_start(ap, format); _recordlogs_internal_record_impl(strlen(LOGMSG_INFO_LEADING), LOGMSG_INFO_LEADING, LOGMSG_INFO_LARGE, priority, format, ap); va_end(ap); }
the_stack_data/242330583.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/in.h> #include <stdint.h> #include <netdb.h> #include <time.h> #include <sys/select.h> int port = 9057; void server0() { int sockfd, connfd; struct sockaddr_in server_addr; struct sockaddr_in client_addr; socklen_t sinlen; ssize_t nbytes; const char hello[] = "I am server xiao hong"; char buffer[128]; if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket fail"); return; } memset(&server_addr, 0, sizeof(struct sockaddr_in)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_ANY); //inet_addr("192.168.1.0") server_addr.sin_port = htons(port); printf("server listen address = %s\n", inet_ntoa(server_addr.sin_addr)); if (bind(sockfd, (struct sockaddr *)(&server_addr), sizeof(struct sockaddr)) == -1) { perror("bind fail"); return; } if (listen(sockfd, 5) == -1) { perror("listen fail"); return; } printf("sizeof(fd_set)=%ld\n", sizeof(fd_set)); int selectnum; int maxfd; fd_set rdset, wrset, exceptset; fd_set originrdset, originwrset, originexceptset; FD_ZERO(&originrdset); FD_ZERO(&originwrset); FD_ZERO(&originexceptset); FD_SET(sockfd, &originrdset); maxfd = sockfd; while(1) { rdset = originrdset; selectnum = select(maxfd+1, &rdset, NULL, NULL, NULL); if (selectnum == -1) { perror("select fail"); return; } else if (selectnum == 0) { printf("selectnum=0\n"); continue; } else { for (int fd = 0; fd < maxfd+1; fd++) { if (FD_ISSET(fd, &rdset)) { if (fd == sockfd) { sinlen = sizeof(struct sockaddr_in); memset(&client_addr, 0, sizeof(struct sockaddr_in)); if ((connfd = accept(fd, (struct sockaddr *)(&client_addr), &sinlen)) == -1) { perror("accept fail"); return; } printf("server sinlen:%d, server get connection from ip:%s\n", sinlen, inet_ntoa(client_addr.sin_addr)); FD_SET(connfd, &originrdset); if (connfd > maxfd) { maxfd = connfd; } } else { memset(buffer, 0, sizeof(buffer)); nbytes = recv(fd, buffer, sizeof(buffer), 0); if (nbytes < 0) { perror("recv fail"); return; } else if (nbytes == 0) { close(fd); FD_CLR(fd, &originrdset); printf("conn close\n\n\n"); continue; } buffer[nbytes] = '\0'; printf("server recv data:%s\n", buffer); snprintf(buffer, sizeof(buffer), "%s%d", hello, fd); if (send(fd, buffer, strlen(buffer), 0) == -1) { perror("send fail"); return; } } } } } } close(sockfd); } void server() { int sockfd, connfd; struct sockaddr_in server_addr; struct sockaddr_in client_addr; socklen_t sinlen; ssize_t nbytes; const char hello[] = "I am server xiao hong"; char buffer[128]; if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket fail"); return; } memset(&server_addr, 0, sizeof(struct sockaddr_in)); server_addr.sin_family = AF_INET; server_addr.sin_addr.s_addr = htonl(INADDR_ANY); //inet_addr("192.168.1.0") server_addr.sin_port = htons(port); printf("server listen address = %s\n", inet_ntoa(server_addr.sin_addr)); if (bind(sockfd, (struct sockaddr *)(&server_addr), sizeof(struct sockaddr)) == -1) { perror("bind fail"); return; } if (listen(sockfd, 5) == -1) { perror("listen fail"); return; } printf("sizeof(fd_set)=%ld\n", sizeof(fd_set)); int selectnum; fd_set rdset, wrset, exceptset; fd_set originrdset, originwrset, originexceptset; FD_ZERO(&originrdset); FD_ZERO(&originwrset); FD_ZERO(&originexceptset); FD_SET(sockfd, &originrdset); while(1) { rdset = originrdset; selectnum = select(FD_SETSIZE, &rdset, NULL, NULL, NULL); if (selectnum == -1) { perror("select fail"); return; } else if (selectnum == 0) { printf("selectnum=0\n"); continue; } else { for (int fd = 0; fd < FD_SETSIZE; fd++) { if (FD_ISSET(fd, &rdset)) { if (fd == sockfd) { sinlen = sizeof(struct sockaddr_in); memset(&client_addr, 0, sizeof(struct sockaddr_in)); if ((connfd = accept(fd, (struct sockaddr *)(&client_addr), &sinlen)) == -1) { perror("accept fail"); return; } printf("server sinlen:%d, server get connection from ip:%s\n", sinlen, inet_ntoa(client_addr.sin_addr)); FD_SET(connfd, &originrdset); } else { memset(buffer, 0, sizeof(buffer)); nbytes = recv(fd, buffer, sizeof(buffer), 0); if (nbytes < 0) { perror("recv fail"); return; } else if (nbytes == 0) { close(fd); FD_CLR(fd, &originrdset); printf("conn close\n\n\n"); continue; } buffer[nbytes] = '\0'; printf("server recv data:%s\n", buffer); snprintf(buffer, sizeof(buffer), "%s%d", hello, fd); if (send(fd, buffer, strlen(buffer), 0) == -1) { perror("send fail"); return; } } } } } } close(sockfd); } void client() { int sockfd; const char sendbuf[] = "I am client xiao ming."; char recvbuf[128]; struct sockaddr_in server_addr; ssize_t nbytes; if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket fail"); return; } memset(&server_addr, 0, sizeof(server_addr)); server_addr.sin_family = AF_INET; server_addr.sin_port = htons(port); server_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); if (connect(sockfd, (struct sockaddr *)(&server_addr), sizeof(struct sockaddr)) == -1) { perror("connect fail"); return; } if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) { perror("send fail"); return; } memset(recvbuf, 0, sizeof(recvbuf)); nbytes = recv(sockfd, recvbuf, sizeof(recvbuf), 0); if (nbytes < 0) { perror("recv fail"); return; } recvbuf[nbytes] = '\0'; printf("client recv data:%s\n", recvbuf); close(sockfd); } void do1() { srand(time(NULL)); port = rand()%100 + 4000; printf("port:%d\n", port); pid_t pid; pid = fork(); if (pid == -1) { printf("fork fail\n"); return; } else if (pid == 0) { printf("son start, pid = %d, ppid = %d\n", getpid(), getppid()); for (int i = 0; i < 10; ++i) { client(); sleep(1); } printf("son end, pid = %d, ppid = %d\n", getpid(), getppid()); exit(0); } else { server0(); //server(); int status = 0; int ret = waitpid(pid, &status, 0); if (ret == -1) { printf("son ret = %d, status = %d\n", ret, status); return; } printf("son ret = %d, status = %d\n", ret, status); } } int main(int argc, char const *argv[]) { do1(); return 0; }
the_stack_data/87638894.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); extern unsigned int __VERIFIER_nondet_uint(void); void __VERIFIER_assert(int cond) { if (!(cond)) { ERROR: __VERIFIER_error(); } return; } int true = 1; int false = 0; int correct_version(int w) { int is_divisible = true; if(w < 4) is_divisible = false; else { int i; for(i = 0; i < w; i += 2) {} if(i != w) is_divisible = false; } return is_divisible; } int student_version(int w) { int is_divisible = true; if(w < 4) is_divisible = false; else { int i; for(i = 0; i < w; i += 2) {} if(i != w) is_divisible = false; } return is_divisible; } int main(){ unsigned int w=__VERIFIER_nondet_uint(); int is_divisible1 = true, is_divisible2 = true; if(w > 0 && w < 10000000) { is_divisible1 = correct_version(w); is_divisible2 = student_version(w); __VERIFIER_assert(is_divisible1 == is_divisible2); } return 0; }
the_stack_data/155302.c
// a program to add array at first position #include<stdio.h> int main() { int a[] = {2,5,6,7}; int N=4; int j=10; printf("The array before assertion\n"); for (int i = 0; i < N; ++i) { printf("a[%d] = %d\n",i,a[i]); } for (int i = N; i >= 0; i--) { a[i+1]= a[i]; } a[0]=j; N++; printf("The array after editing\n"); for (int i = 0; i < N; ++i) { printf("a[%d] = %d\n",i,a[i]); } return 0; }
the_stack_data/72013568.c
struct a { int b; char c; int d; int e; int f; long g; long h; int attr }; struct j { char k; long l; void *m; void *g; int n; void *adate; void *cdate; void *date; void *ctime; int name }; o, p; q() { struct a *a; struct j *b, r[o]; void *c; int i, d; for (; i; i--, a++) a->b = d = &p + d; b = a; s(b->name, r, &c); b->ctime = b->date = b->cdate = b->adate = c; b->n = b; b->m = t(); b->l = 0; }
the_stack_data/193894337.c
/** ****************************************************************************** * @file : default_handlers.c * @brief : Event Handlers ****************************************************************************** * @attention * * <h2><center>&copy; Copyright (c) 2020 RoboJackets. * All rights reserved.</center></h2> * * This software component is licensed by RoboJackets under Apache License * 2.0; You may not use this file except in compliance with the License. You * may obtain a copy of the License at: * https://www.apache.org/licenses/LICENSE-2.0 ****************************************************************************** */ /** * @brief Infinite loop event handler * @retval None */ void Handler_Loop(void) { while(1) {}; } /** * @brief Do nothing event handler * @retval None */ void Handler_Nothing(void) { } void BoardConfigExternal(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void Error_Handler(void) __attribute__ ((weak, alias ("Handler_Loop"))); void NMI_Handler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void HardFault_Handler(void) __attribute__ ((weak, alias ("Handler_Loop"))); void MemManage_Handler(void) __attribute__ ((weak, alias ("Handler_Loop"))); void BusFault_Handler(void) __attribute__ ((weak, alias ("Handler_Loop"))); void UsageFault_Handler(void) __attribute__ ((weak, alias ("Handler_Loop"))); void SVC_Handler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DebugMon_Handler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void PendSV_Handler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void WWDG_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void PVD_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TAMP_STAMP_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void RTC_WKUP_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void FLASH_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void RCC_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void EXTI0_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void EXTI1_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void EXTI2_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void EXTI3_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void EXTI4_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA1_Stream0_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA1_Stream1_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA1_Stream2_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA1_Stream3_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA1_Stream4_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA1_Stream5_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA1_Stream6_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void ADC_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void CAN1_TX_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void CAN1_RX0_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void CAN1_RX1_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void CAN1_SCE_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void EXTI9_5_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM1_BRK_TIM9_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM1_UP_TIM10_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM1_TRG_COM_TIM11_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM1_CC_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM2_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM3_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM4_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void I2C1_EV_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void I2C1_ER_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void I2C2_EV_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void I2C2_ER_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void SPI1_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void SPI2_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void USART1_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void USART2_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void USART3_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void EXTI15_10_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void RTC_Alarm_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void OTG_FS_WKUP_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM8_BRK_TIM12_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM8_UP_TIM13_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM8_TRG_COM_TIM14_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM8_CC_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA1_Stream7_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void FMC_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void SDMMC1_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM5_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void SPI3_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void UART4_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void UART5_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM6_DAC_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void TIM7_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA2_Stream0_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA2_Stream1_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA2_Stream2_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA2_Stream3_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA2_Stream4_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void ETH_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void ETH_WKUP_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void CAN2_TX_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void CAN2_RX0_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void CAN2_RX1_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void CAN2_SCE_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void OTG_FS_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA2_Stream5_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA2_Stream6_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA2_Stream7_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void USART6_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void I2C3_EV_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void I2C3_ER_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void OTG_HS_EP1_OUT_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void OTG_HS_EP1_IN_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void OTG_HS_WKUP_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void OTG_HS_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DCMI_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void RNG_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void FPU_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void UART7_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void UART8_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void SPI4_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void SPI5_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void SPI6_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void SAI1_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void LTDC_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void LTDC_ER_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DMA2D_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void SAI2_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void QUADSPI_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void LPTIM1_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void CEC_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void I2C4_EV_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void I2C4_ER_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void SPDIF_RX_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DSI_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DFSDM1_FLT0_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DFSDM1_FLT1_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DFSDM1_FLT2_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void DFSDM1_FLT3_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void SDMMC2_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void CAN3_TX_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void CAN3_RX0_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void CAN3_RX1_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void CAN3_SCE_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void JPEG_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); void MDIOS_IRQHandler(void) __attribute__ ((weak, alias ("Handler_Nothing"))); // TODO: Put this in interrupt handlers or hardware init void SysTick_Handler(void) { HAL_IncTick(); HAL_SYSTICK_IRQHandler(); }
the_stack_data/886256.c
/* Copyright 2001, 2002 Georges Menie (www.menie.org) stdarg version contributed by Christian Ettinger This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Changes for the FreeRTOS ports: - The dot in "%-8.8s" - The specifiers 'l' (long) and 'L' (long long) - The specifier 'u' for unsigned - Dot notation for IP addresses: sprintf("IP = %xip\n", 0xC0A80164); will produce "IP = 192.168.1.100\n" sprintf("IP = %pip\n", pxIPv6_Address); */ #if 0 // DISABLED FOR NOW, SINCE THIS IMPLEMENTATION IS NOT PERFECT/WELL SUITED FOR FLOATS // If printf operations takes too long, maybe we should consider a tiny version supporting floats, eg. https://github.com/ARMmbed/minimal-printf or https://github.com/mpaland/printf #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "FreeRTOS.h" #include "Debug.h" #define SPRINTF_LONG_LONG 0 #define PAD_RIGHT 1 #define PAD_ZERO 2 #pragma GCC push_options #pragma GCC optimize("O3") /* * Return 1 for readable, 2 for writeable, 3 for both. * Function must be provided by the application. */ extern BaseType_t xApplicationMemoryPermissions( uint32_t aAddress ); void vOutputChar( const char cChar, const TickType_t xTicksToWait ) { // DO NOTHING! Should otherwise be implemented elsewhere } static const TickType_t xTicksToWait = pdMS_TO_TICKS( 20 ); int tiny_printf( const char *format, ... ); /* Defined here: write a large amount as GB, MB, KB or bytes */ const char *mkSize (unsigned long long aSize, char *apBuf, int aLen); typedef union { uint8_t ucBytes[ 4 ]; uint16_t ucShorts[ 2 ]; uint32_t ulWords[ 1 ]; } _U32; struct xPrintFlags { int base; int width; int printLimit; unsigned pad : 8, letBase : 8, isSigned : 1, isNumber : 1, long32 : 1, long64 : 1; }; struct SStringBuf { char *str; const char *orgStr; const char *nulPos; int curLen; struct xPrintFlags flags; }; const static _U32 u32 = { ucBytes : { 0, 1, 2, 3 } }; static void strbuf_init( struct SStringBuf *apStr, char *apBuf, const char *apMaxStr ) { apStr->str = apBuf; apStr->orgStr = apBuf; apStr->nulPos = apMaxStr-1; apStr->curLen = 0; memset( &apStr->flags, '\0', sizeof apStr->flags ); } /*-----------------------------------------------------------*/ static BaseType_t strbuf_printchar( struct SStringBuf *apStr, int c ) { if( apStr->str == NULL ) { vOutputChar( ( char ) c, xTicksToWait ); apStr->curLen++; return pdTRUE; } if( apStr->str < apStr->nulPos ) { *( apStr->str++ ) = c; apStr->curLen++; return pdTRUE; } if( apStr->str == apStr->nulPos ) { *( apStr->str++ ) = '\0'; } return pdFALSE; } /*-----------------------------------------------------------*/ static portINLINE BaseType_t strbuf_printchar_inline( struct SStringBuf *apStr, int c ) { if( apStr->str == NULL ) { vOutputChar( ( char ) c, xTicksToWait ); if( c == 0 ) { return pdFALSE; } apStr->curLen++; return pdTRUE; } if( apStr->str < apStr->nulPos ) { *(apStr->str++) = c; if( c == 0 ) { return pdFALSE; } apStr->curLen++; return pdTRUE; } if( apStr->str == apStr->nulPos ) { *( apStr->str++ ) = '\0'; } return pdFALSE; } /*-----------------------------------------------------------*/ static portINLINE int i2hex( int aCh ) { int iResult; if( aCh < 10 ) { iResult = '0' + aCh; } else { iResult = 'A' + aCh - 10; } return iResult; } /*-----------------------------------------------------------*/ static BaseType_t prints(struct SStringBuf *apBuf, const char *apString ) { register int padchar = ' '; int i,len; #if 0 if( xApplicationMemoryPermissions( ( uint32_t )apString ) == 0 ) { /* The user has probably made a mistake with the parameter for '%s', the memory is not readbale. */ apString = "INV_MEM"; } #endif if( apBuf->flags.width > 0 ) { register int count = 0; register const char *ptr; for( ptr = apString; *ptr; ++ptr ) { ++count; } if( count >= apBuf->flags.width ) { apBuf->flags.width = 0; } else { apBuf->flags.width -= count; } if( apBuf->flags.pad & PAD_ZERO ) { padchar = '0'; } } if( ( apBuf->flags.pad & PAD_RIGHT ) == 0 ) { for( ; apBuf->flags.width > 0; --apBuf->flags.width ) { if( strbuf_printchar( apBuf, padchar ) == 0 ) { return pdFALSE; } } } if( ( apBuf->flags.isNumber == pdTRUE ) && ( apBuf->flags.pad == pdTRUE ) ) { /* The string to print represents an integer number. * In this case, printLimit is the min number of digits to print * If the length of the number to print is less than the min nb of i * digits to display, we add 0 before printing the number */ len = strlen( apString ); if( len < apBuf->flags.printLimit ) { i = apBuf->flags.printLimit - len; for( ; i; i-- ) { if( strbuf_printchar( apBuf, '0' ) == 0 ) { return pdFALSE; } } } } /* The string to print is not the result of a number conversion to ascii. * For a string, printLimit is the max number of characters to display */ for( ; apBuf->flags.printLimit && *apString ; ++apString, --apBuf->flags.printLimit ) { if( !strbuf_printchar( apBuf, *apString ) ) { return pdFALSE; } } for( ; apBuf->flags.width > 0; --apBuf->flags.width ) { if( !strbuf_printchar( apBuf, padchar ) ) { return pdFALSE; } } return pdTRUE; } /*-----------------------------------------------------------*/ /* the following should be enough for 32 bit int */ #define PRINT_BUF_LEN 12 /* to print 4294967296 */ #if SPRINTF_LONG_LONG #warning 64-bit libraries will be included as well static BaseType_t printll( struct SStringBuf *apBuf, long long i ) { char print_buf[ 2 * PRINT_BUF_LEN ]; register char *s; register int t, neg = 0; register unsigned long long u = i; lldiv_t lldiv_result; /* typedef struct * { * long long int quot; // quotient * long long int rem; // remainder * } lldiv_t; */ apBuf->flags.isNumber = pdTRUE; /* Parameter for prints */ if( i == 0LL ) { print_buf[ 0 ] = '0'; print_buf[ 1 ] = '\0'; return prints( apBuf, print_buf ); } if( ( apBuf->flags.isSigned == pdTRUE ) && ( apBuf->flags.base == 10 ) && ( i < 0LL ) ) { neg = 1; u = -i; } s = print_buf + sizeof print_buf - 1; *s = '\0'; /* 18446744073709551616 */ while( u != 0 ) { lldiv_result = lldiv( u, ( unsigned long long ) apBuf->flags.base ); t = lldiv_result.rem; if( t >= 10 ) { t += apBuf->flags.letBase - '0' - 10; } *( --s ) = t + '0'; u = lldiv_result.quot; } if( neg != 0 ) { if( ( apBuf->flags.width != 0 ) && ( apBuf->flags.pad & PAD_ZERO ) ) { if( !strbuf_printchar( apBuf, '-' ) ) { return pdFALSE; } --apBuf->flags.width; } else { *( --s ) = '-'; } } return prints( apBuf, s ); } #endif /* SPRINTF_LONG_LONG */ /*-----------------------------------------------------------*/ static BaseType_t printi( struct SStringBuf *apBuf, int i ) { char print_buf[ PRINT_BUF_LEN ]; register char *s; register int t, neg = 0; register unsigned int u = i; register unsigned base = apBuf->flags.base; apBuf->flags.isNumber = pdTRUE; /* Parameter for prints */ if( i == 0 ) { print_buf[ 0 ] = '0'; print_buf[ 1 ] = '\0'; return prints( apBuf, print_buf ); } if( ( apBuf->flags.isSigned == pdTRUE ) && ( base == 10 ) && ( i < 0 ) ) { neg = 1; u = -i; } s = print_buf + sizeof print_buf - 1; *s = '\0'; switch( base ) { case 16: while( u != 0 ) { t = u & 0xF; if( t >= 10 ) { t += apBuf->flags.letBase - '0' - 10; } *( --s ) = t + '0'; u >>= 4; } break; case 8: case 10: /* GCC compiles very efficient */ while( u ) { t = u % base; *( --s ) = t + '0'; u /= base; } break; /* // The generic case, not yet in use default: while( u ) { t = u % base; if( t >= 10) { t += apBuf->flags.letBase - '0' - 10; } *( --s ) = t + '0'; u /= base; } break; */ } if( neg != 0 ) { if( apBuf->flags.width && (apBuf->flags.pad & PAD_ZERO ) ) { if( strbuf_printchar( apBuf, '-' ) == 0 ) { return pdFALSE; } --apBuf->flags.width; } else { *( --s ) = '-'; } } return prints( apBuf, s ); } /*-----------------------------------------------------------*/ static BaseType_t printl( struct SStringBuf *apBuf, long i ) { char print_buf[ PRINT_BUF_LEN ]; register char *s; register int neg = 0; register long t = 0; register unsigned long u = i; register unsigned base = apBuf->flags.base; apBuf->flags.isNumber = pdTRUE; /* Parameter for prints */ if( i == 0 ) { print_buf[ 0 ] = '0'; print_buf[ 1 ] = '\0'; return prints( apBuf, print_buf ); } if( ( apBuf->flags.isSigned == pdTRUE ) && ( base == 10 ) && ( i < 0 ) ) { neg = 1; u = -i; } s = print_buf + sizeof print_buf - 1; *s = '\0'; switch( base ) { case 16: while( u != 0 ) { t = u & 0xF; if( t >= 10 ) { t += apBuf->flags.letBase - '0' - 10; } *( --s ) = t + '0'; u >>= 4; } break; case 8: case 10: /* GCC compiles very efficient */ while( u ) { t = u % base; *( --s ) = t + '0'; u /= base; } break; /* // The generic case, not yet in use default: while( u ) { t = u % base; if( t >= 10) { t += apBuf->flags.letBase - '0' - 10; } *( --s ) = t + '0'; u /= base; } break; */ } if( neg != 0 ) { if( apBuf->flags.width && (apBuf->flags.pad & PAD_ZERO ) ) { if( strbuf_printchar( apBuf, '-' ) == 0 ) { return pdFALSE; } --apBuf->flags.width; } else { *( --s ) = '-'; } } return prints( apBuf, s ); } static BaseType_t printIp(struct SStringBuf *apBuf, unsigned i ) { char print_buf[16]; sprintf( print_buf, "%u.%u.%u.%u", i >> 24, ( i >> 16 ) & 0xff, ( i >> 8 ) & 0xff, i & 0xff ); apBuf->flags.isNumber = pdTRUE; /* Parameter for prints */ prints( apBuf, print_buf ); return pdTRUE; } /*-----------------------------------------------------------*/ static uint16_t usNetToHost( uint16_t usValue ) { if( u32.ulWords[ 0 ] == 0x00010203 ) { return usValue; } else { return ( usValue << 8 ) | ( usValue >> 8 ); } } static BaseType_t printIPv6( struct SStringBuf *apBuf, uint16_t *pusAddress ) { int iIndex; int iZeroStart = -1; int iZeroLength = 0; int iCurStart = 0; int iCurLength = 0; for( iIndex = 0; iIndex < 8; iIndex++ ) { uint16_t usValue = pusAddress[ iIndex ]; if( usValue == 0 ) { if( iCurLength == 0 ) { iCurStart = iIndex; } iCurLength++; } if( ( usValue != 0 ) || ( iIndex == 7 ) ) { if( iZeroLength < iCurLength ) { iZeroLength = iCurLength; iZeroStart = iCurStart; } iCurLength = 0; } } apBuf->flags.base = 16; apBuf->flags.letBase = 'a'; /* use lower-case letters 'a' to 'f' */ for( iIndex = 0; iIndex < 8; iIndex++ ) { if( iIndex == iZeroStart ) { iIndex += iZeroLength - 1; strbuf_printchar( apBuf, ':' ); if( iIndex == 7 ) { strbuf_printchar( apBuf, ':' ); } } else { if( iIndex > 0 ) { strbuf_printchar( apBuf, ':' ); } printi( apBuf, ( int ) ( ( uint32_t ) usNetToHost( pusAddress[ iIndex ] ) ) ); } } return pdTRUE; } /*-----------------------------------------------------------*/ static void tiny_print( struct SStringBuf *apBuf, const char *format, va_list args ) { char scr[2]; for( ; ; ) { int ch = *( format++ ); if( ch != '%' ) { do { /* Put the most like flow in a small loop */ if( strbuf_printchar_inline( apBuf, ch ) == 0 ) { return; } ch = *( format++ ); } while( ch != '%' ); } ch = *( format++ ); /* Now ch has character after '%', format pointing to next */ if( ch == '\0' ) { break; } if( ch == '%' ) { if( strbuf_printchar( apBuf, ch ) == 0 ) { return; } continue; } memset( &apBuf->flags, '\0', sizeof apBuf->flags ); if( ch == '-' ) { ch = *( format++ ); apBuf->flags.pad = PAD_RIGHT; } while( ch == '0' ) { ch = *( format++ ); apBuf->flags.pad |= PAD_ZERO; } if( ch == '*' ) { ch = *( format++ ); apBuf->flags.width = va_arg( args, int ); } else { while( ch >= '0' && ch <= '9' ) { apBuf->flags.width *= 10; apBuf->flags.width += ch - '0'; ch = *( format++ ); } } if( ch == '.' ) { ch = *( format++ ); if( ch == '*' ) { apBuf->flags.printLimit = va_arg( args, int ); ch = *( format++ ); } else { while( ch >= '0' && ch <= '9' ) { apBuf->flags.printLimit *= 10; apBuf->flags.printLimit += ch - '0'; ch = *( format++ ); } } } if( apBuf->flags.printLimit == 0 ) { apBuf->flags.printLimit--; /* -1: make it unlimited */ } if( ch == 'p' ) { if( format[0] == 'i' && format[1] == 'p' ) { format += 2; /* eat the "pi" of "pip" */ /* Print a IPv6 address */ if( printIPv6( apBuf, va_arg( args, uint16_t* ) ) == 0 ) { break; } continue; } } if( ch == 's' ) { register char *s = ( char * )va_arg( args, int ); if( prints( apBuf, s ? s : "(null)" ) == 0 ) { break; } continue; } if( ch == 'c' ) { /* char are converted to int then pushed on the stack */ scr[0] = ( char ) va_arg( args, int ); if( strbuf_printchar( apBuf, scr[0] ) == 0 ) { return; } continue; } if( ch == 'l' ) { ch = *( format++ ); apBuf->flags.long32 = 1; /* Makes not difference as u32 == long */ } if( ch == 'L' ) { ch = *( format++ ); apBuf->flags.long64 = 1; /* Does make a difference */ } apBuf->flags.base = 10; apBuf->flags.letBase = 'a'; if( ch == 'd' || ch == 'u' ) { apBuf->flags.isSigned = ( ch == 'd' ); #if SPRINTF_LONG_LONG if( apBuf->flags.long64 != pdFALSE ) { if( printll( apBuf, va_arg( args, long long ) ) == 0 ) { break; } } else #endif /* SPRINTF_LONG_LONG */ if( apBuf->flags.long32 != pdFALSE ) { if( printl( apBuf, va_arg( args, long ) ) == 0 ) { break; } } else { if( printi( apBuf, va_arg( args, int ) ) == 0 ) { break; } } continue; } /* OBS. This is not necessarily a full/complete/proper floating point implementation of sprintf */ if( ch == 'f' ) { double value; value = va_arg( args, double ); long integer, integerAbs, decimal, decimalAbs; integer = value; integerAbs = abs(value); int totalLength = apBuf->flags.width; int decimalLength = apBuf->flags.printLimit; if (decimalLength < 0) decimalLength = 5; if (totalLength <= 0) totalLength = decimalLength + 2; long decimalPower = 1; for (int i = 0; i < decimalLength; i++) decimalPower *= 10; decimal = (long)((value - (double)integer) * decimalPower); decimalAbs = abs(decimal); _Bool neg = ((integer != integerAbs) || (decimal != decimalAbs)); apBuf->flags.isSigned = 0; apBuf->flags.width = -1; // totalLength - decimalLength - 1; apBuf->flags.printLimit = totalLength; // apBuf->flags.width; //if (apBuf->flags.width < 0) break; if (neg) { if( strbuf_printchar( apBuf, '-' ) == 0 ) { break; } //--apBuf->flags.width; } if( printl( apBuf, integerAbs ) == 0 ) { break; } if( strbuf_printchar( apBuf, '.' ) == 0 ) { break; } if (apBuf->flags.width > decimalLength) apBuf->flags.width = decimalLength; apBuf->flags.printLimit = apBuf->flags.width; apBuf->flags.pad = PAD_ZERO; if( printl( apBuf, decimalAbs ) == 0 ) { break; } continue; } apBuf->flags.base = 16; /* From here all hexadecimal */ if( ch == 'x' && format[0] == 'i' && format[1] == 'p' ) { format += 2; /* eat the "xi" of "xip" */ /* Will use base 10 again */ if( printIp( apBuf, va_arg( args, int ) ) == 0 ) { break; } continue; } if( ch == 'x' || ch == 'X' || ch == 'p' || ch == 'o' ) { if( ch == 'X' ) { apBuf->flags.letBase = 'A'; } else if( ch == 'o' ) { apBuf->flags.base = 8; } #if SPRINTF_LONG_LONG if( apBuf->flags.long64 != pdFALSE ) { if( printll( apBuf, va_arg( args, long long ) ) == 0 ) { break; } } else #endif /* SPRINTF_LONG_LONG */ if( printi( apBuf, va_arg( args, int ) ) == 0 ) { break; } continue; } } strbuf_printchar( apBuf, '\0' ); } /*-----------------------------------------------------------*/ int tiny_printf( const char *format, ... ) { va_list args; va_start( args, format ); struct SStringBuf strBuf; strbuf_init( &strBuf, NULL, ( const char* )NULL ); tiny_print( &strBuf, format, args ); va_end( args ); return strBuf.curLen; } /*-----------------------------------------------------------*/ int vsnprintf( char *apBuf, size_t aMaxLen, const char *apFmt, va_list args ) { struct SStringBuf strBuf; strbuf_init( &strBuf, apBuf, ( const char* )apBuf + aMaxLen ); tiny_print( &strBuf, apFmt, args ); return strBuf.curLen; } /*-----------------------------------------------------------*/ int snprintf( char *apBuf, size_t aMaxLen, const char *apFmt, ... ) { va_list args; va_start( args, apFmt ); struct SStringBuf strBuf; strbuf_init( &strBuf, apBuf, ( const char* )apBuf + aMaxLen ); tiny_print( &strBuf, apFmt, args ); va_end( args ); return strBuf.curLen; } /*-----------------------------------------------------------*/ int sprintf( char *apBuf, const char *apFmt, ... ) { va_list args; va_start( args, apFmt ); struct SStringBuf strBuf; strbuf_init( &strBuf, apBuf, ( const char * )apBuf + 1024 ); tiny_print( &strBuf, apFmt, args ); va_end( args ); return strBuf.curLen; } /*-----------------------------------------------------------*/ int vsprintf( char *apBuf, const char *apFmt, va_list args ) { struct SStringBuf strBuf; strbuf_init( &strBuf, apBuf, ( const char* ) apBuf + 1024 ); tiny_print( &strBuf, apFmt, args ); return strBuf.curLen; } /*-----------------------------------------------------------*/ const char *mkSize (unsigned long long aSize, char *apBuf, int aLen) { static char retString[33]; size_t gb, mb, kb, sb; if (apBuf == NULL) { apBuf = retString; aLen = sizeof retString; } gb = aSize / (1024*1024*1024); aSize -= gb * (1024*1024*1024); mb = aSize / (1024*1024); aSize -= mb * (1024*1024); kb = aSize / (1024); aSize -= kb * (1024); sb = aSize; if( gb ) { snprintf (apBuf, aLen, "%u.%02u GB", ( unsigned ) gb, ( unsigned ) ( ( 100 * mb ) / 1024ul ) ); } else if( mb ) { snprintf (apBuf, aLen, "%u.%02u MB", ( unsigned ) mb, ( unsigned ) ( ( 100 * kb) / 1024ul ) ); } else if( kb != 0ul ) { snprintf (apBuf, aLen, "%u.%02u KB", ( unsigned ) kb, ( unsigned ) ( ( 100 * sb) / 1024ul ) ); } else { snprintf (apBuf, aLen, "%u bytes", ( unsigned ) sb); } return apBuf; } #pragma GCC pop_options #endif
the_stack_data/43889212.c
//Built in Linux using Clang, not compatible with MinGW #include <stdint.h> #include <stdio.h> #include <stdlib.h> typedef uint8_t BYTE; int main(int argc, char *argv[]) { // Checking usage scenario if (argc != 3) { fprintf(stderr, "Usage: copy SOURCE DESTINATION\n"); return 1; } // File to be copied FILE *source = fopen(argv[1], "r"); if (source == NULL) { printf("Could not open %s.\n", argv[1]); return 1; } // Location of copying FILE *destination = fopen(argv[2], "w"); if (destination == NULL) { fclose(source); printf("Could not create %s.\n", argv[2]); return 1; } //Copying 1 Byte at a time BYTE buffer; while (fread(&buffer, sizeof(BYTE), 1, source)) { fwrite(&buffer, sizeof(BYTE), 1, destination); } // Close files fclose(source); fclose(destination); return 0; }
the_stack_data/948023.c
/** ******************************************************************************* * Copyright(c) 2015, Realtek Semiconductor Corporation. All rights reserved. ******************************************************************************* * @file btrtl_fwconfig.c * @details * @author Alex Lu * @version v1.0 * @date 2016-10-17 */ /** @brief configuration */ unsigned char rtlbt_config[] = { 0x55, 0xab, 0x23, 0x87, 0x06, 0x00, }; /** @brief The length of configuration */ unsigned int rtlbt_config_len = sizeof(rtlbt_config);
the_stack_data/51699285.c
#include <stdio.h> #include <strings.h> #include <stdlib.h> int main() { char fizz[] = "fizz "; char buzz[] = "buzz"; int n = 1; char numstr[3]; while(n <= 100) { sprintf(numstr, "%d", n * (n % 3 != 0) * (n % 5 != 0)); numstr[0] = numstr[0] * (numstr[0] != '0'); fizz[0] = 'f' * (n % 3 == 0); buzz[0] = 'b' * (n % 5 == 0); printf("%s%s%s\n", numstr, fizz, buzz); n += 1; } return 0; }
the_stack_data/84677.c
/*- * SPDX-License-Identifier: BSD-3-Clause * * Copyright (c) 1991, 1993, 1994 * 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/param.h> #include <err.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> static void usage(void); extern char *__progname; int main(int argc, char *argv[]) { char buf[PATH_MAX]; char *p; const char *path; int ch, qflag, rval; qflag = 0; while ((ch = getopt(argc, argv, "q")) != -1) { switch (ch) { case 'q': qflag = 1; break; case '?': default: usage(); } } argc -= optind; argv += optind; path = *argv != NULL ? *argv++ : "."; rval = 0; do { if ((p = realpath(path, buf)) == NULL) { if (!qflag) warn("%s", path); rval = 1; } else (void)printf("%s\n", p); } while ((path = *argv++) != NULL); exit(rval); } static void usage(void) { (void)fprintf(stderr, "usage: %s [-q] [path ...]\n", __progname); exit(1); }
the_stack_data/165767194.c
//quartz2963_6790/_tests/_group_4/_test_8.c //+1.0587E-88 +1.0282E306 -1.0115E-322 // /* This is a automatically generated test. Do not modify */ #include <stdio.h> #include <stdlib.h> #include <math.h> void compute(double comp, double var_1,double var_2) { comp += (var_1 * var_2); printf("%.17g\n", comp); } double* initPointer(double v) { double *ret = (double*) malloc(sizeof(double)*10); for(int i=0; i < 10; ++i) ret[i] = v; return ret; } int main(int argc, char** argv) { /* Program variables */ double tmp_1 = atof(argv[1]); double tmp_2 = atof(argv[2]); double tmp_3 = atof(argv[3]); compute(tmp_1,tmp_2,tmp_3); return 0; }
the_stack_data/70449158.c
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifdef WIN32 #include "httpd.h" #include "http_main.h" #include "http_log.h" #include "http_config.h" /* for read_config */ #include "http_core.h" /* for get_remote_host */ #include "http_connection.h" #include "apr_portable.h" #include "apr_thread_proc.h" #include "apr_getopt.h" #include "apr_strings.h" #include "apr_lib.h" #include "apr_shm.h" #include "apr_thread_mutex.h" #include "ap_mpm.h" #include "apr_general.h" #include "ap_config.h" #include "ap_listen.h" #include "mpm_default.h" #include "mpm_winnt.h" #include "mpm_common.h" #include <malloc.h> #include "apr_atomic.h" #include "scoreboard.h" #ifdef __WATCOMC__ #define _environ environ #endif /* scoreboard.c does the heavy lifting; all we do is create the child * score by moving a handle down the pipe into the child's stdin. */ extern apr_shm_t *ap_scoreboard_shm; /* my_generation is returned to the scoreboard code */ static volatile ap_generation_t my_generation=0; /* Definitions of WINNT MPM specific config globals */ static HANDLE shutdown_event; /* used to signal the parent to shutdown */ static HANDLE restart_event; /* used to signal the parent to restart */ static int one_process = 0; static char const* signal_arg = NULL; OSVERSIONINFO osver; /* VER_PLATFORM_WIN32_NT */ /* set by child_main to STACK_SIZE_PARAM_IS_A_RESERVATION for NT >= 5.1 (XP/2003) */ DWORD stack_res_flag; static DWORD parent_pid; DWORD my_pid; /* used by parent to signal the child to start and exit */ apr_proc_mutex_t *start_mutex; HANDLE exit_event; int ap_threads_per_child = 0; static int thread_limit = 0; static int first_thread_limit = 0; int winnt_mpm_state = AP_MPMQ_STARTING; /* shared by service.c as global, although * perhaps it should be private. */ apr_pool_t *pconf; /* definitions from child.c */ void child_main(apr_pool_t *pconf); /* Only one of these, the pipe from our parent, meant only for * one child worker's consumption (not to be inherited!) * XXX: decorate this name for the trunk branch, was left simplified * only to make the 2.2 patch trivial to read. */ static HANDLE pipe; /* Stub functions until this MPM supports the connection status API */ AP_DECLARE(void) ap_update_connection_status(long conn_id, const char *key, \ const char *value) { /* NOP */ } AP_DECLARE(void) ap_reset_connection_status(long conn_id) { /* NOP */ } AP_DECLARE(apr_array_header_t *) ap_get_status_table(apr_pool_t *p) { /* NOP */ return NULL; } /* * Command processors */ static const char *set_threads_per_child (cmd_parms *cmd, void *dummy, char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); if (err != NULL) { return err; } ap_threads_per_child = atoi(arg); return NULL; } static const char *set_thread_limit (cmd_parms *cmd, void *dummy, const char *arg) { const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); if (err != NULL) { return err; } thread_limit = atoi(arg); return NULL; } static const command_rec winnt_cmds[] = { LISTEN_COMMANDS, AP_INIT_TAKE1("ThreadsPerChild", set_threads_per_child, NULL, RSRC_CONF, "Number of threads each child creates" ), AP_INIT_TAKE1("ThreadLimit", set_thread_limit, NULL, RSRC_CONF, "Maximum worker threads in a server for this run of Apache"), { NULL } }; /* * Signalling Apache on NT. * * Under Unix, Apache can be told to shutdown or restart by sending various * signals (HUP, USR, TERM). On NT we don't have easy access to signals, so * we use "events" instead. The parent apache process goes into a loop * where it waits forever for a set of events. Two of those events are * called * * apPID_shutdown * apPID_restart * * (where PID is the PID of the apache parent process). When one of these * is signalled, the Apache parent performs the appropriate action. The events * can become signalled through internal Apache methods (e.g. if the child * finds a fatal error and needs to kill its parent), via the service * control manager (the control thread will signal the shutdown event when * requested to stop the Apache service), from the -k Apache command line, * or from any external program which finds the Apache PID from the * httpd.pid file. * * The signal_parent() function, below, is used to signal one of these events. * It can be called by any child or parent process, since it does not * rely on global variables. * * On entry, type gives the event to signal. 0 means shutdown, 1 means * graceful restart. */ /* * Initialise the signal names, in the global variables signal_name_prefix, * signal_restart_name and signal_shutdown_name. */ #define MAX_SIGNAL_NAME 30 /* Long enough for apPID_shutdown, where PID is an int */ char signal_name_prefix[MAX_SIGNAL_NAME]; char signal_restart_name[MAX_SIGNAL_NAME]; char signal_shutdown_name[MAX_SIGNAL_NAME]; void setup_signal_names(char *prefix) { apr_snprintf(signal_name_prefix, sizeof(signal_name_prefix), prefix); apr_snprintf(signal_shutdown_name, sizeof(signal_shutdown_name), "%s_shutdown", signal_name_prefix); apr_snprintf(signal_restart_name, sizeof(signal_restart_name), "%s_restart", signal_name_prefix); } AP_DECLARE(void) ap_signal_parent(ap_signal_parent_e type) { HANDLE e; char *signal_name; if (parent_pid == my_pid) { switch(type) { case SIGNAL_PARENT_SHUTDOWN: { SetEvent(shutdown_event); break; } /* This MPM supports only graceful restarts right now */ case SIGNAL_PARENT_RESTART: case SIGNAL_PARENT_RESTART_GRACEFUL: { SetEvent(restart_event); break; } } return; } switch(type) { case SIGNAL_PARENT_SHUTDOWN: { signal_name = signal_shutdown_name; break; } /* This MPM supports only graceful restarts right now */ case SIGNAL_PARENT_RESTART: case SIGNAL_PARENT_RESTART_GRACEFUL: { signal_name = signal_restart_name; break; } default: return; } e = OpenEvent(EVENT_MODIFY_STATE, FALSE, signal_name); if (!e) { /* Um, problem, can't signal the parent, which means we can't * signal ourselves to die. Ignore for now... */ ap_log_error(APLOG_MARK, APLOG_EMERG, apr_get_os_error(), ap_server_conf, "OpenEvent on %s event", signal_name); return; } if (SetEvent(e) == 0) { /* Same problem as above */ ap_log_error(APLOG_MARK, APLOG_EMERG, apr_get_os_error(), ap_server_conf, "SetEvent on %s event", signal_name); CloseHandle(e); return; } CloseHandle(e); } /* * Passed the following handles [in sync with send_handles_to_child()] * * ready event [signal the parent immediately, then close] * exit event [save to poll later] * start mutex [signal from the parent to begin accept()] * scoreboard shm handle [to recreate the ap_scoreboard] */ void get_handles_from_parent(server_rec *s, HANDLE *child_exit_event, apr_proc_mutex_t **child_start_mutex, apr_shm_t **scoreboard_shm) { HANDLE hScore; HANDLE ready_event; HANDLE os_start; DWORD BytesRead; void *sb_shared; apr_status_t rv; /* *** We now do this was back in winnt_rewrite_args * pipe = GetStdHandle(STD_INPUT_HANDLE); */ if (!ReadFile(pipe, &ready_event, sizeof(HANDLE), &BytesRead, (LPOVERLAPPED) NULL) || (BytesRead != sizeof(HANDLE))) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Child %d: Unable to retrieve the ready event from the parent", my_pid); exit(APEXIT_CHILDINIT); } SetEvent(ready_event); CloseHandle(ready_event); if (!ReadFile(pipe, child_exit_event, sizeof(HANDLE), &BytesRead, (LPOVERLAPPED) NULL) || (BytesRead != sizeof(HANDLE))) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Child %d: Unable to retrieve the exit event from the parent", my_pid); exit(APEXIT_CHILDINIT); } if (!ReadFile(pipe, &os_start, sizeof(os_start), &BytesRead, (LPOVERLAPPED) NULL) || (BytesRead != sizeof(os_start))) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Child %d: Unable to retrieve the start_mutex from the parent", my_pid); exit(APEXIT_CHILDINIT); } *child_start_mutex = NULL; if ((rv = apr_os_proc_mutex_put(child_start_mutex, &os_start, s->process->pool)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Child %d: Unable to access the start_mutex from the parent", my_pid); exit(APEXIT_CHILDINIT); } if (!ReadFile(pipe, &hScore, sizeof(hScore), &BytesRead, (LPOVERLAPPED) NULL) || (BytesRead != sizeof(hScore))) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Child %d: Unable to retrieve the scoreboard from the parent", my_pid); exit(APEXIT_CHILDINIT); } *scoreboard_shm = NULL; if ((rv = apr_os_shm_put(scoreboard_shm, &hScore, s->process->pool)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Child %d: Unable to access the scoreboard from the parent", my_pid); exit(APEXIT_CHILDINIT); } rv = ap_reopen_scoreboard(s->process->pool, scoreboard_shm, 1); if (rv || !(sb_shared = apr_shm_baseaddr_get(*scoreboard_shm))) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Child %d: Unable to reopen the scoreboard from the parent", my_pid); exit(APEXIT_CHILDINIT); } /* We must 'initialize' the scoreboard to relink all the * process-local pointer arrays into the shared memory block. */ ap_init_scoreboard(sb_shared); ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, "Child %d: Retrieved our scoreboard from the parent.", my_pid); } static int send_handles_to_child(apr_pool_t *p, HANDLE child_ready_event, HANDLE child_exit_event, apr_proc_mutex_t *child_start_mutex, apr_shm_t *scoreboard_shm, HANDLE hProcess, apr_file_t *child_in) { apr_status_t rv; HANDLE hCurrentProcess = GetCurrentProcess(); HANDLE hDup; HANDLE os_start; HANDLE hScore; apr_size_t BytesWritten; if (!DuplicateHandle(hCurrentProcess, child_ready_event, hProcess, &hDup, EVENT_MODIFY_STATE | SYNCHRONIZE, FALSE, 0)) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Parent: Unable to duplicate the ready event handle for the child"); return -1; } if ((rv = apr_file_write_full(child_in, &hDup, sizeof(hDup), &BytesWritten)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Parent: Unable to send the exit event handle to the child"); return -1; } if (!DuplicateHandle(hCurrentProcess, child_exit_event, hProcess, &hDup, EVENT_MODIFY_STATE | SYNCHRONIZE, FALSE, 0)) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Parent: Unable to duplicate the exit event handle for the child"); return -1; } if ((rv = apr_file_write_full(child_in, &hDup, sizeof(hDup), &BytesWritten)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Parent: Unable to send the exit event handle to the child"); return -1; } if ((rv = apr_os_proc_mutex_get(&os_start, child_start_mutex)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Parent: Unable to retrieve the start mutex for the child"); return -1; } if (!DuplicateHandle(hCurrentProcess, os_start, hProcess, &hDup, SYNCHRONIZE, FALSE, 0)) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Parent: Unable to duplicate the start mutex to the child"); return -1; } if ((rv = apr_file_write_full(child_in, &hDup, sizeof(hDup), &BytesWritten)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Parent: Unable to send the start mutex to the child"); return -1; } if ((rv = apr_os_shm_get(&hScore, scoreboard_shm)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Parent: Unable to retrieve the scoreboard handle for the child"); return -1; } if (!DuplicateHandle(hCurrentProcess, hScore, hProcess, &hDup, FILE_MAP_READ | FILE_MAP_WRITE, FALSE, 0)) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Parent: Unable to duplicate the scoreboard handle to the child"); return -1; } if ((rv = apr_file_write_full(child_in, &hDup, sizeof(hDup), &BytesWritten)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Parent: Unable to send the scoreboard handle to the child"); return -1; } ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, "Parent: Sent the scoreboard to the child"); return 0; } /* * get_listeners_from_parent() * The listen sockets are opened in the parent. This function, which runs * exclusively in the child process, receives them from the parent and * makes them availeble in the child. */ void get_listeners_from_parent(server_rec *s) { WSAPROTOCOL_INFO WSAProtocolInfo; ap_listen_rec *lr; DWORD BytesRead; int lcnt = 0; SOCKET nsd; /* Set up a default listener if necessary */ if (ap_listeners == NULL) { ap_listen_rec *lr; lr = apr_palloc(s->process->pool, sizeof(ap_listen_rec)); lr->sd = NULL; lr->next = ap_listeners; ap_listeners = lr; } /* Open the pipe to the parent process to receive the inherited socket * data. The sockets have been set to listening in the parent process. * * *** We now do this was back in winnt_rewrite_args * pipe = GetStdHandle(STD_INPUT_HANDLE); */ for (lr = ap_listeners; lr; lr = lr->next, ++lcnt) { if (!ReadFile(pipe, &WSAProtocolInfo, sizeof(WSAPROTOCOL_INFO), &BytesRead, (LPOVERLAPPED) NULL)) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "setup_inherited_listeners: Unable to read socket data from parent"); exit(APEXIT_CHILDINIT); } nsd = WSASocket(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, &WSAProtocolInfo, 0, 0); if (nsd == INVALID_SOCKET) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_netos_error(), ap_server_conf, "Child %d: setup_inherited_listeners(), WSASocket failed to open the inherited socket.", my_pid); exit(APEXIT_CHILDINIT); } if (!SetHandleInformation((HANDLE)nsd, HANDLE_FLAG_INHERIT, 0)) { ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), ap_server_conf, "set_listeners_noninheritable: SetHandleInformation failed."); } apr_os_sock_put(&lr->sd, &nsd, s->process->pool); } ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, "Child %d: retrieved %d listeners from parent", my_pid, lcnt); } static int send_listeners_to_child(apr_pool_t *p, DWORD dwProcessId, apr_file_t *child_in) { apr_status_t rv; int lcnt = 0; ap_listen_rec *lr; LPWSAPROTOCOL_INFO lpWSAProtocolInfo; apr_size_t BytesWritten; /* Run the chain of open sockets. For each socket, duplicate it * for the target process then send the WSAPROTOCOL_INFO * (returned by dup socket) to the child. */ for (lr = ap_listeners; lr; lr = lr->next, ++lcnt) { apr_os_sock_t nsd; lpWSAProtocolInfo = apr_pcalloc(p, sizeof(WSAPROTOCOL_INFO)); apr_os_sock_get(&nsd,lr->sd); ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, ap_server_conf, "Parent: Duplicating socket %d and sending it to child process %d", nsd, dwProcessId); if (WSADuplicateSocket(nsd, dwProcessId, lpWSAProtocolInfo) == SOCKET_ERROR) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_netos_error(), ap_server_conf, "Parent: WSADuplicateSocket failed for socket %d. Check the FAQ.", lr->sd ); return -1; } if ((rv = apr_file_write_full(child_in, lpWSAProtocolInfo, sizeof(WSAPROTOCOL_INFO), &BytesWritten)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Parent: Unable to write duplicated socket %d to the child.", lr->sd ); return -1; } } ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, "Parent: Sent %d listeners to child %d", lcnt, dwProcessId); return 0; } enum waitlist_e { waitlist_ready = 0, waitlist_term = 1 }; static int create_process(apr_pool_t *p, HANDLE *child_proc, HANDLE *child_exit_event, DWORD *child_pid) { /* These NEVER change for the lifetime of this parent */ static char **args = NULL; static char pidbuf[28]; apr_status_t rv; apr_pool_t *ptemp; apr_procattr_t *attr; apr_proc_t new_child; HANDLE hExitEvent; HANDLE waitlist[2]; /* see waitlist_e */ char *cmd; char *cwd; char **env; int envc; apr_pool_create_ex(&ptemp, p, NULL, NULL); /* Build the command line. Should look something like this: * C:/apache/bin/httpd.exe -f ap_server_confname * First, get the path to the executable... */ apr_procattr_create(&attr, ptemp); apr_procattr_cmdtype_set(attr, APR_PROGRAM); apr_procattr_detach_set(attr, 1); if (((rv = apr_filepath_get(&cwd, 0, ptemp)) != APR_SUCCESS) || ((rv = apr_procattr_dir_set(attr, cwd)) != APR_SUCCESS)) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Parent: Failed to get the current path"); } if (!args) { /* Build the args array, only once since it won't change * for the lifetime of this parent process. */ if ((rv = ap_os_proc_filepath(&cmd, ptemp)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, ERROR_BAD_PATHNAME, ap_server_conf, "Parent: Failed to get full path of %s", ap_server_conf->process->argv[0]); apr_pool_destroy(ptemp); return -1; } args = malloc((ap_server_conf->process->argc + 1) * sizeof (char*)); memcpy(args + 1, ap_server_conf->process->argv + 1, (ap_server_conf->process->argc - 1) * sizeof (char*)); args[0] = malloc(strlen(cmd) + 1); strcpy(args[0], cmd); args[ap_server_conf->process->argc] = NULL; } else { cmd = args[0]; } /* Create a pipe to send handles to the child */ if ((rv = apr_procattr_io_set(attr, APR_FULL_BLOCK, APR_NO_PIPE, APR_NO_PIPE)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Parent: Unable to create child stdin pipe."); apr_pool_destroy(ptemp); return -1; } /* Create the child_ready_event */ waitlist[waitlist_ready] = CreateEvent(NULL, TRUE, FALSE, NULL); if (!waitlist[waitlist_ready]) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Parent: Could not create ready event for child process"); apr_pool_destroy (ptemp); return -1; } /* Create the child_exit_event */ hExitEvent = CreateEvent(NULL, TRUE, FALSE, NULL); if (!hExitEvent) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Parent: Could not create exit event for child process"); apr_pool_destroy(ptemp); CloseHandle(waitlist[waitlist_ready]); return -1; } /* Build the env array */ for (envc = 0; _environ[envc]; ++envc) { ; } env = apr_palloc(ptemp, (envc + 2) * sizeof (char*)); memcpy(env, _environ, envc * sizeof (char*)); apr_snprintf(pidbuf, sizeof(pidbuf), "AP_PARENT_PID=%i", parent_pid); env[envc] = pidbuf; env[envc + 1] = NULL; rv = apr_proc_create(&new_child, cmd, (const char * const *)args, (const char * const *)env, attr, ptemp); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, ap_server_conf, "Parent: Failed to create the child process."); apr_pool_destroy(ptemp); CloseHandle(hExitEvent); CloseHandle(waitlist[waitlist_ready]); CloseHandle(new_child.hproc); return -1; } ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf, "Parent: Created child process %d", new_child.pid); if (send_handles_to_child(ptemp, waitlist[waitlist_ready], hExitEvent, start_mutex, ap_scoreboard_shm, new_child.hproc, new_child.in)) { /* * This error is fatal, mop up the child and move on * We toggle the child's exit event to cause this child * to quit even as it is attempting to start. */ SetEvent(hExitEvent); apr_pool_destroy(ptemp); CloseHandle(hExitEvent); CloseHandle(waitlist[waitlist_ready]); CloseHandle(new_child.hproc); return -1; } /* Important: * Give the child process a chance to run before dup'ing the sockets. * We have already set the listening sockets noninheritable, but if * WSADuplicateSocket runs before the child process initializes * the listeners will be inherited anyway. */ waitlist[waitlist_term] = new_child.hproc; rv = WaitForMultipleObjects(2, waitlist, FALSE, INFINITE); CloseHandle(waitlist[waitlist_ready]); if (rv != WAIT_OBJECT_0) { /* * Outch... that isn't a ready signal. It's dead, Jim! */ SetEvent(hExitEvent); apr_pool_destroy(ptemp); CloseHandle(hExitEvent); CloseHandle(new_child.hproc); return -1; } if (send_listeners_to_child(ptemp, new_child.pid, new_child.in)) { /* * This error is fatal, mop up the child and move on * We toggle the child's exit event to cause this child * to quit even as it is attempting to start. */ SetEvent(hExitEvent); apr_pool_destroy(ptemp); CloseHandle(hExitEvent); CloseHandle(new_child.hproc); return -1; } apr_file_close(new_child.in); *child_exit_event = hExitEvent; *child_proc = new_child.hproc; *child_pid = new_child.pid; return 0; } /*********************************************************************** * master_main() * master_main() runs in the parent process. It creates the child * process which handles HTTP requests then waits on one of three * events: * * restart_event * ------------- * The restart event causes master_main to start a new child process and * tells the old child process to exit (by setting the child_exit_event). * The restart event is set as a result of one of the following: * 1. An apache -k restart command on the command line * 2. A command received from Windows service manager which gets * translated into an ap_signal_parent(SIGNAL_PARENT_RESTART) * call by code in service.c. * 3. The child process calling ap_signal_parent(SIGNAL_PARENT_RESTART) * as a result of hitting MaxConnectionsPerChild. * * shutdown_event * -------------- * The shutdown event causes master_main to tell the child process to * exit and that the server is shutting down. The shutdown event is * set as a result of one of the following: * 1. An apache -k shutdown command on the command line * 2. A command received from Windows service manager which gets * translated into an ap_signal_parent(SIGNAL_PARENT_SHUTDOWN) * call by code in service.c. * * child process handle * -------------------- * The child process handle will be signaled if the child process * exits for any reason. In a normal running server, the signaling * of this event means that the child process has exited prematurely * due to a seg fault or other irrecoverable error. For server * robustness, master_main will restart the child process under this * condtion. * * master_main uses the child_exit_event to signal the child process * to exit. **********************************************************************/ #define NUM_WAIT_HANDLES 3 #define CHILD_HANDLE 0 #define SHUTDOWN_HANDLE 1 #define RESTART_HANDLE 2 static int master_main(server_rec *s, HANDLE shutdown_event, HANDLE restart_event) { int rv, cld; int restart_pending; int shutdown_pending; HANDLE child_exit_event; HANDLE event_handles[NUM_WAIT_HANDLES]; DWORD child_pid; restart_pending = shutdown_pending = 0; event_handles[SHUTDOWN_HANDLE] = shutdown_event; event_handles[RESTART_HANDLE] = restart_event; /* Create a single child process */ rv = create_process(pconf, &event_handles[CHILD_HANDLE], &child_exit_event, &child_pid); if (rv < 0) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "master_main: create child process failed. Exiting."); shutdown_pending = 1; goto die_now; } if (!strcasecmp(signal_arg, "runservice")) { mpm_service_started(); } /* Update the scoreboard. Note that there is only a single active * child at once. */ ap_scoreboard_image->parent[0].quiescing = 0; ap_scoreboard_image->parent[0].pid = child_pid; /* Wait for shutdown or restart events or for child death */ winnt_mpm_state = AP_MPMQ_RUNNING; rv = WaitForMultipleObjects(NUM_WAIT_HANDLES, (HANDLE *) event_handles, FALSE, INFINITE); cld = rv - WAIT_OBJECT_0; if (rv == WAIT_FAILED) { /* Something serious is wrong */ ap_log_error(APLOG_MARK,APLOG_CRIT, apr_get_os_error(), ap_server_conf, "master_main: WaitForMultipeObjects WAIT_FAILED -- doing server shutdown"); shutdown_pending = 1; } else if (rv == WAIT_TIMEOUT) { /* Hey, this cannot happen */ ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), s, "master_main: WaitForMultipeObjects with INFINITE wait exited with WAIT_TIMEOUT"); shutdown_pending = 1; } else if (cld == SHUTDOWN_HANDLE) { /* shutdown_event signalled */ shutdown_pending = 1; ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, s, "Parent: Received shutdown signal -- Shutting down the server."); if (ResetEvent(shutdown_event) == 0) { ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), s, "ResetEvent(shutdown_event)"); } } else if (cld == RESTART_HANDLE) { /* Received a restart event. Prepare the restart_event to be reused * then signal the child process to exit. */ restart_pending = 1; ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, s, "Parent: Received restart signal -- Restarting the server."); if (ResetEvent(restart_event) == 0) { ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), s, "Parent: ResetEvent(restart_event) failed."); } if (SetEvent(child_exit_event) == 0) { ap_log_error(APLOG_MARK, APLOG_ERR, apr_get_os_error(), s, "Parent: SetEvent for child process %d failed.", event_handles[CHILD_HANDLE]); } /* Don't wait to verify that the child process really exits, * just move on with the restart. */ CloseHandle(event_handles[CHILD_HANDLE]); event_handles[CHILD_HANDLE] = NULL; } else { /* The child process exited prematurely due to a fatal error. */ DWORD exitcode; if (!GetExitCodeProcess(event_handles[CHILD_HANDLE], &exitcode)) { /* HUH? We did exit, didn't we? */ exitcode = APEXIT_CHILDFATAL; } if ( exitcode == APEXIT_CHILDFATAL || exitcode == APEXIT_CHILDINIT || exitcode == APEXIT_INIT) { ap_log_error(APLOG_MARK, APLOG_CRIT, 0, ap_server_conf, "Parent: child process exited with status %u -- Aborting.", exitcode); shutdown_pending = 1; } else { int i; restart_pending = 1; ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf, "Parent: child process exited with status %u -- Restarting.", exitcode); for (i = 0; i < ap_threads_per_child; i++) { ap_update_child_status_from_indexes(0, i, SERVER_DEAD, NULL); } } CloseHandle(event_handles[CHILD_HANDLE]); event_handles[CHILD_HANDLE] = NULL; } if (restart_pending) { ++my_generation; ap_scoreboard_image->global->running_generation = my_generation; } die_now: if (shutdown_pending) { int timeout = 30000; /* Timeout is milliseconds */ winnt_mpm_state = AP_MPMQ_STOPPING; /* This shutdown is only marginally graceful. We will give the * child a bit of time to exit gracefully. If the time expires, * the child will be wacked. */ if (!strcasecmp(signal_arg, "runservice")) { mpm_service_stopping(); } /* Signal the child processes to exit */ if (SetEvent(child_exit_event) == 0) { ap_log_error(APLOG_MARK,APLOG_ERR, apr_get_os_error(), ap_server_conf, "Parent: SetEvent for child process %d failed", event_handles[CHILD_HANDLE]); } if (event_handles[CHILD_HANDLE]) { rv = WaitForSingleObject(event_handles[CHILD_HANDLE], timeout); if (rv == WAIT_OBJECT_0) { ap_log_error(APLOG_MARK,APLOG_NOTICE, APR_SUCCESS, ap_server_conf, "Parent: Child process exited successfully."); CloseHandle(event_handles[CHILD_HANDLE]); event_handles[CHILD_HANDLE] = NULL; } else { ap_log_error(APLOG_MARK,APLOG_NOTICE, APR_SUCCESS, ap_server_conf, "Parent: Forcing termination of child process %d ", event_handles[CHILD_HANDLE]); TerminateProcess(event_handles[CHILD_HANDLE], 1); CloseHandle(event_handles[CHILD_HANDLE]); event_handles[CHILD_HANDLE] = NULL; } } CloseHandle(child_exit_event); return 0; /* Tell the caller we do not want to restart */ } winnt_mpm_state = AP_MPMQ_STARTING; CloseHandle(child_exit_event); return 1; /* Tell the caller we want a restart */ } /* service_nt_main_fn needs to append the StartService() args * outside of our call stack and thread as the service starts... */ apr_array_header_t *mpm_new_argv; /* Remember service_to_start failures to log and fail in pre_config. * Remember inst_argc and inst_argv for installing or starting the * service after we preflight the config. */ static int winnt_query(int query_code, int *result, apr_status_t *rv) { *rv = APR_SUCCESS; switch (query_code) { case AP_MPMQ_MAX_DAEMON_USED: *result = MAXIMUM_WAIT_OBJECTS; break; case AP_MPMQ_IS_THREADED: *result = AP_MPMQ_STATIC; break; case AP_MPMQ_IS_FORKED: *result = AP_MPMQ_NOT_SUPPORTED; break; case AP_MPMQ_HARD_LIMIT_DAEMONS: *result = HARD_SERVER_LIMIT; break; case AP_MPMQ_HARD_LIMIT_THREADS: *result = thread_limit; break; case AP_MPMQ_MAX_THREADS: *result = ap_threads_per_child; break; case AP_MPMQ_MIN_SPARE_DAEMONS: *result = 0; break; case AP_MPMQ_MIN_SPARE_THREADS: *result = 0; break; case AP_MPMQ_MAX_SPARE_DAEMONS: *result = 0; break; case AP_MPMQ_MAX_SPARE_THREADS: *result = 0; break; case AP_MPMQ_MAX_REQUESTS_DAEMON: *result = ap_max_requests_per_child; break; case AP_MPMQ_MAX_DAEMONS: *result = 0; break; case AP_MPMQ_MPM_STATE: *result = winnt_mpm_state; break; case AP_MPMQ_GENERATION: *result = my_generation; break; default: *rv = APR_ENOTIMPL; break; } return OK; } static const char *winnt_get_name(void) { return "WinNT"; } #define SERVICE_UNSET (-1) static apr_status_t service_set = SERVICE_UNSET; static apr_status_t service_to_start_success; static int inst_argc; static const char * const *inst_argv; static const char *service_name = NULL; void winnt_rewrite_args(process_rec *process) { /* Handle the following SCM aspects in this phase: * * -k runservice [transition in service context only] * -k install * -k config * -k uninstall * -k stop * -k shutdown (same as -k stop). Maintained for backward compatability. * * We can't leave this phase until we know our identity * and modify the command arguments appropriately. * * We do not care if the .conf file exists or is parsable when * attempting to stop or uninstall a service. */ apr_status_t rv; char *def_server_root; char *binpath; char optbuf[3]; const char *opt_arg; int fixed_args; char *pid; apr_getopt_t *opt; int running_as_service = 1; int errout = 0; apr_file_t *nullfile; pconf = process->pconf; osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osver); /* We wish this was *always* a reservation, but sadly it wasn't so and * we couldn't break a hard limit prior to NT Kernel 5.1 */ if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT && ((osver.dwMajorVersion > 5) || ((osver.dwMajorVersion == 5) && (osver.dwMinorVersion > 0)))) { stack_res_flag = STACK_SIZE_PARAM_IS_A_RESERVATION; } /* AP_PARENT_PID is only valid in the child */ pid = getenv("AP_PARENT_PID"); if (pid) { HANDLE filehand; HANDLE hproc = GetCurrentProcess(); /* This is the child */ my_pid = GetCurrentProcessId(); parent_pid = (DWORD) atol(pid); /* Prevent holding open the (nonexistant) console */ ap_real_exit_code = 0; /* The parent gave us stdin, we need to remember this * handle, and no longer inherit it at our children * (we can't slurp it up now, we just aren't ready yet). * The original handle is closed below, at apr_file_dup2() */ pipe = GetStdHandle(STD_INPUT_HANDLE); if (DuplicateHandle(hproc, pipe, hproc, &filehand, 0, FALSE, DUPLICATE_SAME_ACCESS)) { pipe = filehand; } /* The parent gave us stdout of the NUL device, * and expects us to suck up stdin of all of our * shared handles and data from the parent. * Don't infect child processes with our stdin * handle, use another handle to NUL! */ { apr_file_t *infile, *outfile; if ((apr_file_open_stdout(&outfile, process->pool) == APR_SUCCESS) && (apr_file_open_stdin(&infile, process->pool) == APR_SUCCESS)) apr_file_dup2(infile, outfile, process->pool); } /* This child needs the existing stderr opened for logging, * already */ /* The parent is responsible for providing the * COMPLETE ARGUMENTS REQUIRED to the child. * * No further argument parsing is needed, but * for good measure we will provide a simple * signal string for later testing. */ signal_arg = "runchild"; return; } /* This is the parent, we have a long way to go :-) */ parent_pid = my_pid = GetCurrentProcessId(); /* This behavior is voided by setting real_exit_code to 0 */ atexit(hold_console_open_on_error); /* Rewrite process->argv[]; * * strip out -k signal into signal_arg * strip out -n servicename and set the names * add default -d serverroot from the path of this executable * * The end result will look like: * * The invocation command (%0) * The -d serverroot default from the running executable * The requested service's (-n) registry ConfigArgs * The WinNT SCM's StartService() args */ if ((rv = ap_os_proc_filepath(&binpath, process->pconf)) != APR_SUCCESS) { ap_log_error(APLOG_MARK,APLOG_CRIT, rv, NULL, "Failed to get the full path of %s", process->argv[0]); exit(APEXIT_INIT); } /* WARNING: There is an implict assumption here that the * executable resides in ServerRoot or ServerRoot\bin */ def_server_root = (char *) apr_filepath_name_get(binpath); if (def_server_root > binpath) { *(def_server_root - 1) = '\0'; def_server_root = (char *) apr_filepath_name_get(binpath); if (!strcasecmp(def_server_root, "bin")) *(def_server_root - 1) = '\0'; } apr_filepath_merge(&def_server_root, NULL, binpath, APR_FILEPATH_TRUENAME, process->pool); /* Use process->pool so that the rewritten argv * lasts for the lifetime of the server process, * because pconf will be destroyed after the * initial pre-flight of the config parser. */ mpm_new_argv = apr_array_make(process->pool, process->argc + 2, sizeof(const char *)); *(const char **)apr_array_push(mpm_new_argv) = process->argv[0]; *(const char **)apr_array_push(mpm_new_argv) = "-d"; *(const char **)apr_array_push(mpm_new_argv) = def_server_root; fixed_args = mpm_new_argv->nelts; optbuf[0] = '-'; optbuf[2] = '\0'; apr_getopt_init(&opt, process->pool, process->argc, process->argv); opt->errfn = NULL; while ((rv = apr_getopt(opt, "wn:k:" AP_SERVER_BASEARGS, optbuf + 1, &opt_arg)) == APR_SUCCESS) { switch (optbuf[1]) { /* Shortcuts; include the -w option to hold the window open on error. * This must not be toggled once we reset ap_real_exit_code to 0! */ case 'w': if (ap_real_exit_code) ap_real_exit_code = 2; break; case 'n': service_set = mpm_service_set_name(process->pool, &service_name, opt_arg); break; case 'k': signal_arg = opt_arg; break; case 'E': errout = 1; /* Fall through so the Apache main() handles the 'E' arg */ default: *(const char **)apr_array_push(mpm_new_argv) = apr_pstrdup(process->pool, optbuf); if (opt_arg) { *(const char **)apr_array_push(mpm_new_argv) = opt_arg; } break; } } /* back up to capture the bad argument */ if (rv == APR_BADCH || rv == APR_BADARG) { opt->ind--; } while (opt->ind < opt->argc) { *(const char **)apr_array_push(mpm_new_argv) = apr_pstrdup(process->pool, opt->argv[opt->ind++]); } /* Track the number of args actually entered by the user */ inst_argc = mpm_new_argv->nelts - fixed_args; /* Provide a default 'run' -k arg to simplify signal_arg tests */ if (!signal_arg) { signal_arg = "run"; running_as_service = 0; } if (!strcasecmp(signal_arg, "runservice")) { /* Start the NT Service _NOW_ because the WinNT SCM is * expecting us to rapidly assume control of our own * process, the SCM will tell us our service name, and * may have extra StartService() command arguments to * add for us. * * The SCM will generally invoke the executable with * the c:\win\system32 default directory. This is very * lethal if folks use ServerRoot /foopath on windows * without a drive letter. Change to the default root * (path to apache root, above /bin) for safety. */ apr_filepath_set(def_server_root, process->pool); /* Any other process has a console, so we don't to begin * a Win9x service until the configuration is parsed and * any command line errors are reported. * * We hold the return value so that we can die in pre_config * after logging begins, and the failure can land in the log. */ if (!errout) { mpm_nt_eventlog_stderr_open((char*)service_name, process->pool); } service_to_start_success = mpm_service_to_start(&service_name, process->pool); if (service_to_start_success == APR_SUCCESS) { service_set = APR_SUCCESS; } /* Open a null handle to soak stdout in this process. * Windows service processes are missing any file handle * usable for stdin/out/err. This was the cause of later * trouble with invocations of apr_file_open_stdout() */ if ((rv = apr_file_open(&nullfile, "NUL", APR_READ | APR_WRITE, APR_OS_DEFAULT, process->pool)) == APR_SUCCESS) { apr_file_t *nullstdout; if (apr_file_open_stdout(&nullstdout, process->pool) == APR_SUCCESS) apr_file_dup2(nullstdout, nullfile, process->pool); apr_file_close(nullfile); } } /* Get the default for any -k option, except run */ if (service_set == SERVICE_UNSET && strcasecmp(signal_arg, "run")) { service_set = mpm_service_set_name(process->pool, &service_name, AP_DEFAULT_SERVICE_NAME); } if (!strcasecmp(signal_arg, "install")) /* -k install */ { if (service_set == APR_SUCCESS) { ap_log_error(APLOG_MARK,APLOG_ERR, 0, NULL, "%s: Service is already installed.", service_name); exit(APEXIT_INIT); } } else if (running_as_service) { if (service_set == APR_SUCCESS) { /* Attempt to Uninstall, or stop, before * we can read the arguments or .conf files */ if (!strcasecmp(signal_arg, "uninstall")) { rv = mpm_service_uninstall(); exit(rv); } if ((!strcasecmp(signal_arg, "stop")) || (!strcasecmp(signal_arg, "shutdown"))) { mpm_signal_service(process->pool, 0); exit(0); } rv = mpm_merge_service_args(process->pool, mpm_new_argv, fixed_args); if (rv == APR_SUCCESS) { ap_log_error(APLOG_MARK,APLOG_INFO, 0, NULL, "Using ConfigArgs of the installed service " "\"%s\".", service_name); } else { ap_log_error(APLOG_MARK,APLOG_WARNING, rv, NULL, "No installed ConfigArgs for the service " "\"%s\", using Apache defaults.", service_name); } } else { ap_log_error(APLOG_MARK,APLOG_ERR, service_set, NULL, "No installed service named \"%s\".", service_name); exit(APEXIT_INIT); } } if (strcasecmp(signal_arg, "install") && service_set && service_set != SERVICE_UNSET) { ap_log_error(APLOG_MARK,APLOG_ERR, service_set, NULL, "No installed service named \"%s\".", service_name); exit(APEXIT_INIT); } /* Track the args actually entered by the user. * These will be used for the -k install parameters, as well as * for the -k start service override arguments. */ inst_argv = (const char * const *)mpm_new_argv->elts + mpm_new_argv->nelts - inst_argc; /* Now, do service install or reconfigure then proceed to * post_config to test the installed configuration. */ if (!strcasecmp(signal_arg, "config")) { /* -k config */ /* Reconfigure the service */ rv = mpm_service_install(process->pool, inst_argc, inst_argv, 1); if (rv != APR_SUCCESS) { exit(rv); } fprintf(stderr,"Testing httpd.conf....\n"); fprintf(stderr,"Errors reported here must be corrected before the " "service can be started.\n"); } else if (!strcasecmp(signal_arg, "install")) { /* -k install */ /* Install the service */ rv = mpm_service_install(process->pool, inst_argc, inst_argv, 0); if (rv != APR_SUCCESS) { exit(rv); } fprintf(stderr,"Testing httpd.conf....\n"); fprintf(stderr,"Errors reported here must be corrected before the " "service can be started.\n"); } process->argc = mpm_new_argv->nelts; process->argv = (const char * const *) mpm_new_argv->elts; } static int winnt_pre_config(apr_pool_t *pconf_, apr_pool_t *plog, apr_pool_t *ptemp) { /* Handle the following SCM aspects in this phase: * * -k runservice [WinNT errors logged from rewrite_args] */ /* Initialize shared static objects. * TODO: Put config related statics into an sconf structure. */ pconf = pconf_; if (ap_exists_config_define("ONE_PROCESS") || ap_exists_config_define("DEBUG")) one_process = -1; /* XXX: presume proper privilages; one nice thing would be * a loud emit if running as "LocalSystem"/"SYSTEM" to indicate * they should change to a user with write access to logs/ alone. */ ap_sys_privileges_handlers(1); if (!strcasecmp(signal_arg, "runservice") && (service_to_start_success != APR_SUCCESS)) { ap_log_error(APLOG_MARK,APLOG_CRIT, service_to_start_success, NULL, "%s: Unable to start the service manager.", service_name); exit(APEXIT_INIT); } else if (!one_process && !my_generation) { /* Open a null handle to soak stdout in this process. * We need to emulate apr_proc_detach, unix performs this * same check in the pre_config hook (although it is * arguably premature). Services already fixed this. */ apr_file_t *nullfile; apr_status_t rv; apr_pool_t *pproc = apr_pool_parent_get(pconf); if ((rv = apr_file_open(&nullfile, "NUL", APR_READ | APR_WRITE, APR_OS_DEFAULT, pproc)) == APR_SUCCESS) { apr_file_t *nullstdout; if (apr_file_open_stdout(&nullstdout, pproc) == APR_SUCCESS) apr_file_dup2(nullstdout, nullfile, pproc); apr_file_close(nullfile); } } ap_listen_pre_config(); thread_limit = DEFAULT_THREAD_LIMIT; ap_threads_per_child = DEFAULT_THREADS_PER_CHILD; ap_pid_fname = DEFAULT_PIDLOG; ap_max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD; ap_max_mem_free = APR_ALLOCATOR_MAX_FREE_UNLIMITED; apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir)); return OK; } static int winnt_check_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec* s) { int is_parent; static int restart_num = 0; int startup = 0; /* We want this only in the parent and only the first time around */ is_parent = (parent_pid == my_pid); if (is_parent && restart_num++ == 0) { startup = 1; } if (thread_limit > MAX_THREAD_LIMIT) { if (startup) { ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, "WARNING: ThreadLimit of %d exceeds compile-time " "limit of", thread_limit); ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, " %d threads, decreasing to %d.", MAX_THREAD_LIMIT, MAX_THREAD_LIMIT); } else if (is_parent) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "ThreadLimit of %d exceeds compile-time limit " "of %d, decreasing to match", thread_limit, MAX_THREAD_LIMIT); } thread_limit = MAX_THREAD_LIMIT; } else if (thread_limit < 1) { if (startup) { ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, "WARNING: ThreadLimit of %d not allowed, " "increasing to 1.", thread_limit); } else if (is_parent) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "ThreadLimit of %d not allowed, increasing to 1", thread_limit); } thread_limit = 1; } /* You cannot change ThreadLimit across a restart; ignore * any such attempts. */ if (!first_thread_limit) { first_thread_limit = thread_limit; } else if (thread_limit != first_thread_limit) { /* Don't need a startup console version here */ if (is_parent) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "changing ThreadLimit to %d from original value " "of %d not allowed during restart", thread_limit, first_thread_limit); } thread_limit = first_thread_limit; } if (ap_threads_per_child > thread_limit) { if (startup) { ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, "WARNING: ThreadsPerChild of %d exceeds ThreadLimit " "of", ap_threads_per_child); ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, " %d threads, decreasing to %d.", thread_limit, thread_limit); ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, " To increase, please see the ThreadLimit " "directive."); } else if (is_parent) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "ThreadsPerChild of %d exceeds ThreadLimit " "of %d, decreasing to match", ap_threads_per_child, thread_limit); } ap_threads_per_child = thread_limit; } else if (ap_threads_per_child < 1) { if (startup) { ap_log_error(APLOG_MARK, APLOG_WARNING | APLOG_STARTUP, 0, NULL, "WARNING: ThreadsPerChild of %d not allowed, " "increasing to 1.", ap_threads_per_child); } else if (is_parent) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s, "ThreadsPerChild of %d not allowed, increasing to 1", ap_threads_per_child); } ap_threads_per_child = 1; } return OK; } static int winnt_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec* s) { static int restart_num = 0; apr_status_t rv = 0; /* Handle the following SCM aspects in this phase: * * -k install (catch and exit as install was handled in rewrite_args) * -k config (catch and exit as config was handled in rewrite_args) * -k start * -k restart * -k runservice [Win95, only once - after we parsed the config] * * because all of these signals are useful _only_ if there * is a valid conf\httpd.conf environment to start. * * We reached this phase by avoiding errors that would cause * these options to fail unexpectedly in another process. */ if (!strcasecmp(signal_arg, "install")) { /* Service install happens in the rewrite_args hooks. If we * made it this far, the server configuration is clean and the * service will successfully start. */ apr_pool_destroy(s->process->pool); apr_terminate(); exit(0); } if (!strcasecmp(signal_arg, "config")) { /* Service reconfiguration happens in the rewrite_args hooks. If we * made it this far, the server configuration is clean and the * service will successfully start. */ apr_pool_destroy(s->process->pool); apr_terminate(); exit(0); } if (!strcasecmp(signal_arg, "start")) { ap_listen_rec *lr; /* Close the listening sockets. */ for (lr = ap_listeners; lr; lr = lr->next) { apr_socket_close(lr->sd); lr->active = 0; } rv = mpm_service_start(ptemp, inst_argc, inst_argv); apr_pool_destroy(s->process->pool); apr_terminate(); exit (rv); } if (!strcasecmp(signal_arg, "restart")) { mpm_signal_service(ptemp, 1); apr_pool_destroy(s->process->pool); apr_terminate(); exit (rv); } if (parent_pid == my_pid) { if (restart_num++ == 1) { /* This code should be run once in the parent and not run * across a restart */ PSECURITY_ATTRIBUTES sa = GetNullACL(); /* returns NULL if invalid (Win95?) */ setup_signal_names(apr_psprintf(pconf,"ap%d", parent_pid)); ap_log_pid(pconf, ap_pid_fname); /* Create shutdown event, apPID_shutdown, where PID is the parent * Apache process ID. Shutdown is signaled by 'apache -k shutdown'. */ shutdown_event = CreateEvent(sa, FALSE, FALSE, signal_shutdown_name); if (!shutdown_event) { ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Parent: Cannot create shutdown event %s", signal_shutdown_name); CleanNullACL((void *)sa); return HTTP_INTERNAL_SERVER_ERROR; } /* Create restart event, apPID_restart, where PID is the parent * Apache process ID. Restart is signaled by 'apache -k restart'. */ restart_event = CreateEvent(sa, FALSE, FALSE, signal_restart_name); if (!restart_event) { CloseHandle(shutdown_event); ap_log_error(APLOG_MARK, APLOG_CRIT, apr_get_os_error(), ap_server_conf, "Parent: Cannot create restart event %s", signal_restart_name); CleanNullACL((void *)sa); return HTTP_INTERNAL_SERVER_ERROR; } CleanNullACL((void *)sa); /* Create the start mutex, as an unnamed object for security. * Ths start mutex is used during a restart to prevent more than * one child process from entering the accept loop at once. */ rv = apr_proc_mutex_create(&start_mutex, NULL, APR_LOCK_DEFAULT, ap_server_conf->process->pool); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK,APLOG_ERR, rv, ap_server_conf, "%s: Unable to create the start_mutex.", service_name); return HTTP_INTERNAL_SERVER_ERROR; } } /* Always reset our console handler to be the first, even on a restart * because some modules (e.g. mod_perl) might have set a console * handler to terminate the process. */ if (strcasecmp(signal_arg, "runservice")) mpm_start_console_handler(); } else /* parent_pid != my_pid */ { mpm_start_child_console_handler(); } return OK; } /* This really should be a post_config hook, but the error log is already * redirected by that point, so we need to do this in the open_logs phase. */ static int winnt_open_logs(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) { /* Initialize shared static objects. */ if (parent_pid != my_pid) { return OK; } /* We cannot initialize our listeners if we are restarting * (the parent process already has glomed on to them) * nor should we do so for service reconfiguration * (since the service may already be running.) */ if (!strcasecmp(signal_arg, "restart") || !strcasecmp(signal_arg, "config")) { return OK; } if (ap_setup_listeners(s) < 1) { ap_log_error(APLOG_MARK, APLOG_ALERT|APLOG_STARTUP, 0, NULL, "no listening sockets available, shutting down"); return DONE; } return OK; } static void winnt_child_init(apr_pool_t *pchild, struct server_rec *s) { apr_status_t rv; setup_signal_names(apr_psprintf(pchild,"ap%d", parent_pid)); /* This is a child process, not in single process mode */ if (!one_process) { /* Set up events and the scoreboard */ get_handles_from_parent(s, &exit_event, &start_mutex, &ap_scoreboard_shm); /* Set up the listeners */ get_listeners_from_parent(s); /* Done reading from the parent, close that channel */ CloseHandle(pipe); my_generation = ap_scoreboard_image->global->running_generation; } else { /* Single process mode - this lock doesn't even need to exist */ rv = apr_proc_mutex_create(&start_mutex, signal_name_prefix, APR_LOCK_DEFAULT, s->process->pool); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK,APLOG_ERR, rv, ap_server_conf, "%s child %d: Unable to init the start_mutex.", service_name, my_pid); exit(APEXIT_CHILDINIT); } /* Borrow the shutdown_even as our _child_ loop exit event */ exit_event = shutdown_event; } } static int winnt_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s ) { static int restart = 0; /* Default is "not a restart" */ /* ### If non-graceful restarts are ever introduced - we need to rerun * the pre_mpm hook on subsequent non-graceful restarts. But Win32 * has only graceful style restarts - and we need this hook to act * the same on Win32 as on Unix. */ if (!restart && ((parent_pid == my_pid) || one_process)) { /* Set up the scoreboard. */ if (ap_run_pre_mpm(s->process->pool, SB_SHARED) != OK) { return DONE; } } if ((parent_pid != my_pid) || one_process) { /* The child process or in one_process (debug) mode */ ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf, "Child %d: Child process is running", my_pid); child_main(pconf); ap_log_error(APLOG_MARK, APLOG_NOTICE, APR_SUCCESS, ap_server_conf, "Child %d: Child process is exiting", my_pid); return DONE; } else { /* A real-honest to goodness parent */ ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, "%s configured -- resuming normal operations", ap_get_server_description()); ap_log_error(APLOG_MARK, APLOG_NOTICE, 0, ap_server_conf, "Server built: %s", ap_get_server_built()); ap_log_command_line(plog, s); restart = master_main(ap_server_conf, shutdown_event, restart_event); if (!restart) { /* Shutting down. Clean up... */ const char *pidfile = ap_server_root_relative (pconf, ap_pid_fname); if (pidfile != NULL && unlink(pidfile) == 0) { ap_log_error(APLOG_MARK, APLOG_INFO, APR_SUCCESS, ap_server_conf, "removed PID file %s (pid=%ld)", pidfile, GetCurrentProcessId()); } apr_proc_mutex_destroy(start_mutex); CloseHandle(restart_event); CloseHandle(shutdown_event); return DONE; } } return OK; /* Restart */ } static void winnt_hooks(apr_pool_t *p) { /* Our open_logs hook function must run before the core's, or stderr * will be redirected to a file, and the messages won't print to the * console. */ static const char *const aszSucc[] = {"core.c", NULL}; ap_hook_pre_config(winnt_pre_config, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_check_config(winnt_check_config, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_post_config(winnt_post_config, NULL, NULL, 0); ap_hook_child_init(winnt_child_init, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_open_logs(winnt_open_logs, NULL, aszSucc, APR_HOOK_REALLY_FIRST); ap_hook_mpm(winnt_run, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_mpm_query(winnt_query, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_mpm_get_name(winnt_get_name, NULL, NULL, APR_HOOK_MIDDLE); } AP_DECLARE_MODULE(mpm_winnt) = { MPM20_MODULE_STUFF, winnt_rewrite_args, /* hook to run before apache parses args */ NULL, /* create per-directory config structure */ NULL, /* merge per-directory config structures */ NULL, /* create per-server config structure */ NULL, /* merge per-server config structures */ winnt_cmds, /* command apr_table_t */ winnt_hooks /* register_hooks */ }; #endif /* def WIN32 */
the_stack_data/43477.c
/************ myclock.c *************************/ /* MIMD version 7 */ #include "time.h" #include "stdio.h" void myclock(int restart, char* msg) { double secs; static double lastsecs; static double initsecs; secs = clock()/(CLOCKS_PER_SEC/100); secs/=100; if (restart) initsecs=secs; else printf("TIMING %s : %e %e\n",msg,secs-lastsecs,secs-initsecs); lastsecs=secs; }
the_stack_data/64331.c
#include <stdio.h> int main() { printf ("Hello World!\n") ; }
the_stack_data/100139475.c
#include <stdio.h> #include <stdlib.h> typedef struct GrafoMA{ int V; // número de vértices int A; // número de arestas int **mat; } GrafoMA; int** iniciar_MA(int n){ int i, j; int **mat = (int**) malloc(n * sizeof(int*)); for (i = 0; i < n; i++) mat[i] = (int*) malloc(n * sizeof(int)); for (i = 0; i < n; i++) for (j = 0; j < n; j++) mat[i][j] = 0; return mat; } GrafoMA* iniciar_grafoMA(int v){ GrafoMA* G = (GrafoMA*) malloc(sizeof(GrafoMA)); G->V = v; G->A = 0; G->mat = iniciar_MA(G->V); return G; } int valida_vertice(GrafoMA* G, int v){ return (v >= 0) && (v < G->V); } int aresta_existe(GrafoMA* G, int v1, int v2){ return (G != NULL) && valida_vertice(G, v1) && valida_vertice(G, v2) && (G->mat[v1][v2] == 1); } void inserir_aresta(GrafoMA* G, int v1, int v2){ if ((G != NULL) && (valida_vertice(G, v1)) && (valida_vertice(G, v2)) && (!aresta_existe(G, v1, v2))){ G->mat[v1][v2] = G->mat[v2][v1] = 1; G->A++; } } void liberarGMA(GrafoMA* G){ if (G != NULL){ free(G->mat); free(G); } } int main() { int n, aux; scanf(" %d",&n); GrafoMA *gMA = iniciar_grafoMA(n); int i=0, j=0; while(i<n){ j=0; while(j<n){ scanf(" %d",&aux); if(aux==1) inserir_aresta(gMA, i, j); j++; } i++; } int aux1, aux2; do{ scanf("%d",&aux1); scanf("%d",&aux2); if(aux1 == -1 || aux2 == -1) break; if(aresta_existe(gMA, aux1, aux2)==1){ printf("sim\n"); } else printf("nao\n"); i++; }while((aux1 != -1)); liberarGMA(gMA); return 0; }
the_stack_data/110971.c
/* * Copyright (C) 2010 The Android Open Source Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* ChangeLog for this library: * * NDK r8d: Add android_setCpu(). * * NDK r8c: Add new ARM CPU features: VFPv2, VFP_D32, VFP_FP16, * VFP_FMA, NEON_FMA, IDIV_ARM, IDIV_THUMB2 and iWMMXt. * * Rewrite the code to parse /proc/self/auxv instead of * the "Features" field in /proc/cpuinfo. * * Dynamically allocate the buffer that hold the content * of /proc/cpuinfo to deal with newer hardware. * * NDK r7c: Fix CPU count computation. The old method only reported the * number of _active_ CPUs when the library was initialized, * which could be less than the real total. * * NDK r5: Handle buggy kernels which report a CPU Architecture number of 7 * for an ARMv6 CPU (see below). * * Handle kernels that only report 'neon', and not 'vfpv3' * (VFPv3 is mandated by the ARM architecture is Neon is implemented) * * Handle kernels that only report 'vfpv3d16', and not 'vfpv3' * * Fix x86 compilation. Report ANDROID_CPU_FAMILY_X86 in * android_getCpuFamily(). * * NDK r4: Initial release */ #ifdef __ANDROID__ #if defined(__le32__) // When users enter this, we should only provide interface and // libportable will give the implementations. #else // !__le32__ #include <sys/system_properties.h> #include <pthread.h> #include "cpu-features.h" #include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <errno.h> static pthread_once_t g_once; static int g_inited; static AndroidCpuFamily g_cpuFamily; static uint64_t g_cpuFeatures; static int g_cpuCount; #ifdef __arm__ static uint32_t g_cpuIdArm; #endif static const int android_cpufeatures_debug = 0; #ifdef __arm__ # define DEFAULT_CPU_FAMILY ANDROID_CPU_FAMILY_ARM #elif defined __i386__ # define DEFAULT_CPU_FAMILY ANDROID_CPU_FAMILY_X86 #else # define DEFAULT_CPU_FAMILY ANDROID_CPU_FAMILY_UNKNOWN #endif #ifndef __ANDROID__ #define D(...) \ do { \ if (android_cpufeatures_debug) { \ printf(__VA_ARGS__); fflush(stdout); \ } \ } while (0) #else #include <android/log.h> #define D(...) \ do { \ if (android_cpufeatures_debug) { \ __android_log_print(ANDROID_LOG_WARN, "theora_debug", __VA_ARGS__); \ } \ } while (0) #endif #ifdef __i386__ static __inline__ void x86_cpuid(int func, int values[4]) { int a, b, c, d; /* We need to preserve ebx since we're compiling PIC code */ /* this means we can't use "=b" for the second output register */ __asm__ __volatile__ ( \ "push %%ebx\n" "cpuid\n" \ "mov %%ebx, %1\n" "pop %%ebx\n" : "=a" (a), "=r" (b), "=c" (c), "=d" (d) \ : "a" (func) \ ); values[0] = a; values[1] = b; values[2] = c; values[3] = d; } #endif /* Get the size of a file by reading it until the end. This is needed * because files under /proc do not always return a valid size when * using fseek(0, SEEK_END) + ftell(). Nor can they be mmap()-ed. */ static int get_file_size(const char* pathname) { int fd, result = 0; char buffer[256]; fd = open(pathname, O_RDONLY); if (fd < 0) { D("Can't open %s: %s\n", pathname, strerror(errno)); return -1; } for (;;) { int ret = read(fd, buffer, sizeof buffer); if (ret < 0) { if (errno == EINTR) continue; D("Error while reading %s: %s\n", pathname, strerror(errno)); break; } if (ret == 0) break; result += ret; } close(fd); return result; } /* Read the content of /proc/cpuinfo into a user-provided buffer. * Return the length of the data, or -1 on error. Does *not* * zero-terminate the content. Will not read more * than 'buffsize' bytes. */ static int read_file(const char* pathname, char* buffer, size_t buffsize) { int fd, count; fd = open(pathname, O_RDONLY); if (fd < 0) { D("Could not open %s: %s\n", pathname, strerror(errno)); return -1; } count = 0; while (count < (int)buffsize) { int ret = read(fd, buffer + count, buffsize - count); if (ret < 0) { if (errno == EINTR) continue; D("Error while reading from %s: %s\n", pathname, strerror(errno)); if (count == 0) count = -1; break; } if (ret == 0) break; count += ret; } close(fd); return count; } #if defined(__arm__) /* Extract the content of a the first occurence of a given field in * the content of /proc/cpuinfo and return it as a heap-allocated * string that must be freed by the caller. * * Return NULL if not found */ static char* extract_cpuinfo_field(const char* buffer, int buflen, const char* field) { int fieldlen = strlen(field); const char* bufend = buffer + buflen; char* result = NULL; int len; const char *p, *q; /* Look for first field occurence, and ensures it starts the line. */ p = buffer; for (;;) { p = memmem(p, bufend-p, field, fieldlen); if (p == NULL) goto EXIT; if (p == buffer || p[-1] == '\n') break; p += fieldlen; } /* Skip to the first column followed by a space */ p += fieldlen; p = memchr(p, ':', bufend-p); if (p == NULL || p[1] != ' ') goto EXIT; /* Find the end of the line */ p += 2; q = memchr(p, '\n', bufend-p); if (q == NULL) q = bufend; /* Copy the line into a heap-allocated buffer */ len = q-p; result = malloc(len+1); if (result == NULL) goto EXIT; memcpy(result, p, len); result[len] = '\0'; EXIT: return result; } #endif /* Checks that a space-separated list of items contains one given 'item'. * Returns 1 if found, 0 otherwise. */ #if defined(__arm__) static int has_list_item(const char* list, const char* item) { const char* p = list; int itemlen = strlen(item); if (list == NULL) return 0; while (*p) { const char* q; /* skip spaces */ while (*p == ' ' || *p == '\t') p++; /* find end of current list item */ q = p; while (*q && *q != ' ' && *q != '\t') q++; if (itemlen == q-p && !memcmp(p, item, itemlen)) return 1; /* skip to next item */ p = q; } return 0; } #endif /* Parse a number starting from 'input', but not going further * than 'limit'. Return the value into '*result'. * * NOTE: Does not skip over leading spaces, or deal with sign characters. * NOTE: Ignores overflows. * * The function returns NULL in case of error (bad format), or the new * position after the decimal number in case of success (which will always * be <= 'limit'). */ static const char* parse_number(const char* input, const char* limit, int base, int* result) { const char* p = input; int val = 0; while (p < limit) { int d = (*p - '0'); if ((unsigned)d >= 10U) { d = (*p - 'a'); if ((unsigned)d >= 6U) d = (*p - 'A'); if ((unsigned)d >= 6U) break; d += 10; } if (d >= base) break; val = val*base + d; p++; } if (p == input) return NULL; *result = val; return p; } static const char* parse_decimal(const char* input, const char* limit, int* result) { return parse_number(input, limit, 10, result); } #if defined(__arm__) static const char* parse_hexadecimal(const char* input, const char* limit, int* result) { return parse_number(input, limit, 16, result); } #endif /* This small data type is used to represent a CPU list / mask, as read * from sysfs on Linux. See http://www.kernel.org/doc/Documentation/cputopology.txt * * For now, we don't expect more than 32 cores on mobile devices, so keep * everything simple. */ typedef struct { uint32_t mask; } CpuList; static __inline__ void cpulist_init(CpuList* list) { list->mask = 0; } static __inline__ void cpulist_and(CpuList* list1, CpuList* list2) { list1->mask &= list2->mask; } static __inline__ void cpulist_set(CpuList* list, int index) { if ((unsigned)index < 32) { list->mask |= (uint32_t)(1U << index); } } static __inline__ int cpulist_count(CpuList* list) { return __builtin_popcount(list->mask); } /* Parse a textual list of cpus and store the result inside a CpuList object. * Input format is the following: * - comma-separated list of items (no spaces) * - each item is either a single decimal number (cpu index), or a range made * of two numbers separated by a single dash (-). Ranges are inclusive. * * Examples: 0 * 2,4-127,128-143 * 0-1 */ static void cpulist_parse(CpuList* list, const char* line, int line_len) { const char* p = line; const char* end = p + line_len; const char* q; /* NOTE: the input line coming from sysfs typically contains a * trailing newline, so take care of it in the code below */ while (p < end && *p != '\n') { int val, start_value, end_value; /* Find the end of current item, and put it into 'q' */ q = memchr(p, ',', end-p); if (q == NULL) { q = end; } /* Get first value */ p = parse_decimal(p, q, &start_value); if (p == NULL) goto BAD_FORMAT; end_value = start_value; /* If we're not at the end of the item, expect a dash and * and integer; extract end value. */ if (p < q && *p == '-') { p = parse_decimal(p+1, q, &end_value); if (p == NULL) goto BAD_FORMAT; } /* Set bits CPU list bits */ for (val = start_value; val <= end_value; val++) { cpulist_set(list, val); } /* Jump to next item */ p = q; if (p < end) p++; } BAD_FORMAT: ; } /* Read a CPU list from one sysfs file */ static void cpulist_read_from(CpuList* list, const char* filename) { char file[64]; int filelen; cpulist_init(list); filelen = read_file(filename, file, sizeof file); if (filelen < 0) { D("Could not read %s: %s\n", filename, strerror(errno)); return; } cpulist_parse(list, file, filelen); } // See <asm/hwcap.h> kernel header. #define HWCAP_VFP (1 << 6) #define HWCAP_IWMMXT (1 << 9) #define HWCAP_NEON (1 << 12) #define HWCAP_VFPv3 (1 << 13) #define HWCAP_VFPv3D16 (1 << 14) #define HWCAP_VFPv4 (1 << 16) #define HWCAP_IDIVA (1 << 17) #define HWCAP_IDIVT (1 << 18) #define AT_HWCAP 16 #if defined(__arm__) /* Compute the ELF HWCAP flags. */ static uint32_t get_elf_hwcap(const char* cpuinfo, int cpuinfo_len) { /* IMPORTANT: * Accessing /proc/self/auxv doesn't work anymore on all * platform versions. More specifically, when running inside * a regular application process, most of /proc/self/ will be * non-readable, including /proc/self/auxv. This doesn't * happen however if the application is debuggable, or when * running under the "shell" UID, which is why this was not * detected appropriately. */ #if 0 uint32_t result = 0; const char filepath[] = "/proc/self/auxv"; int fd = open(filepath, O_RDONLY); if (fd < 0) { D("Could not open %s: %s\n", filepath, strerror(errno)); return 0; } struct { uint32_t tag; uint32_t value; } entry; for (;;) { int ret = read(fd, (char*)&entry, sizeof entry); if (ret < 0) { if (errno == EINTR) continue; D("Error while reading %s: %s\n", filepath, strerror(errno)); break; } // Detect end of list. if (ret == 0 || (entry.tag == 0 && entry.value == 0)) break; if (entry.tag == AT_HWCAP) { result = entry.value; break; } } close(fd); return result; #else // Recreate ELF hwcaps by parsing /proc/cpuinfo Features tag. uint32_t hwcaps = 0; char* cpuFeatures = extract_cpuinfo_field(cpuinfo, cpuinfo_len, "Features"); if (cpuFeatures != NULL) { D("Found cpuFeatures = '%s'\n", cpuFeatures); if (has_list_item(cpuFeatures, "vfp")) hwcaps |= HWCAP_VFP; if (has_list_item(cpuFeatures, "vfpv3")) hwcaps |= HWCAP_VFPv3; if (has_list_item(cpuFeatures, "vfpv3d16")) hwcaps |= HWCAP_VFPv3D16; if (has_list_item(cpuFeatures, "vfpv4")) hwcaps |= HWCAP_VFPv4; if (has_list_item(cpuFeatures, "neon")) hwcaps |= HWCAP_NEON; if (has_list_item(cpuFeatures, "idiva")) hwcaps |= HWCAP_IDIVA; if (has_list_item(cpuFeatures, "idivt")) hwcaps |= HWCAP_IDIVT; if (has_list_item(cpuFeatures, "idiv")) hwcaps |= HWCAP_IDIVA | HWCAP_IDIVT; if (has_list_item(cpuFeatures, "iwmmxt")) hwcaps |= HWCAP_IWMMXT; free(cpuFeatures); } return hwcaps; #endif } #endif /* __arm__ */ /* Return the number of cpus present on a given device. * * To handle all weird kernel configurations, we need to compute the * intersection of the 'present' and 'possible' CPU lists and count * the result. */ static int get_cpu_count(void) { CpuList cpus_present[1]; CpuList cpus_possible[1]; cpulist_read_from(cpus_present, "/sys/devices/system/cpu/present"); cpulist_read_from(cpus_possible, "/sys/devices/system/cpu/possible"); /* Compute the intersection of both sets to get the actual number of * CPU cores that can be used on this device by the kernel. */ cpulist_and(cpus_present, cpus_possible); return cpulist_count(cpus_present); } static void android_cpuInitFamily(void) { #if defined(__arm__) g_cpuFamily = ANDROID_CPU_FAMILY_ARM; #elif defined(__i386__) g_cpuFamily = ANDROID_CPU_FAMILY_X86; #elif defined(__mips64) /* Needs to be before __mips__ since the compiler defines both */ g_cpuFamily = ANDROID_CPU_FAMILY_MIPS64; #elif defined(__mips__) g_cpuFamily = ANDROID_CPU_FAMILY_MIPS; #elif defined(__aarch64__) g_cpuFamily = ANDROID_CPU_FAMILY_ARM64; #elif defined(__x86_64__) g_cpuFamily = ANDROID_CPU_FAMILY_X86_64; #else g_cpuFamily = ANDROID_CPU_FAMILY_UNKNOWN; #endif } static void android_cpuInit(void) { char* cpuinfo = NULL; int cpuinfo_len; android_cpuInitFamily(); g_cpuFeatures = 0; g_cpuCount = 1; g_inited = 1; cpuinfo_len = get_file_size("/proc/cpuinfo"); if (cpuinfo_len < 0) { D("cpuinfo_len cannot be computed!"); return; } cpuinfo = malloc(cpuinfo_len); if (cpuinfo == NULL) { D("cpuinfo buffer could not be allocated"); return; } cpuinfo_len = read_file("/proc/cpuinfo", cpuinfo, cpuinfo_len); D("cpuinfo_len is (%d):\n%.*s\n", cpuinfo_len, cpuinfo_len >= 0 ? cpuinfo_len : 0, cpuinfo); if (cpuinfo_len < 0) /* should not happen */ { free(cpuinfo); return; } /* Count the CPU cores, the value may be 0 for single-core CPUs */ g_cpuCount = get_cpu_count(); if (g_cpuCount == 0) { g_cpuCount = 1; } D("found cpuCount = %d\n", g_cpuCount); #ifdef __arm__ { /* Extract architecture from the "CPU Architecture" field. * The list is well-known, unlike the the output of * the 'Processor' field which can vary greatly. * * See the definition of the 'proc_arch' array in * $KERNEL/arch/arm/kernel/setup.c and the 'c_show' function in * same file. */ char* cpuArch = extract_cpuinfo_field(cpuinfo, cpuinfo_len, "CPU architecture"); if (cpuArch != NULL) { char* end; long archNumber; int hasARMv7 = 0; D("found cpuArch = '%s'\n", cpuArch); /* read the initial decimal number, ignore the rest */ archNumber = strtol(cpuArch, &end, 10); /* Here we assume that ARMv8 will be upwards compatible with v7 * in the future. Unfortunately, there is no 'Features' field to * indicate that Thumb-2 is supported. */ if (end > cpuArch && archNumber >= 7) { hasARMv7 = 1; } /* Unfortunately, it seems that certain ARMv6-based CPUs * report an incorrect architecture number of 7! * * See http://code.google.com/p/android/issues/detail?id=10812 * * We try to correct this by looking at the 'elf_format' * field reported by the 'Processor' field, which is of the * form of "(v7l)" for an ARMv7-based CPU, and "(v6l)" for * an ARMv6-one. */ if (hasARMv7) { char* cpuProc = extract_cpuinfo_field(cpuinfo, cpuinfo_len, "Processor"); if (cpuProc != NULL) { D("found cpuProc = '%s'\n", cpuProc); if (has_list_item(cpuProc, "(v6l)")) { D("CPU processor and architecture mismatch!!\n"); hasARMv7 = 0; } free(cpuProc); } } if (hasARMv7) { g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_ARMv7; } /* The LDREX / STREX instructions are available from ARMv6 */ if (archNumber >= 6) { g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_LDREX_STREX; } free(cpuArch); } /* Extract the list of CPU features from ELF hwcaps */ uint32_t hwcaps = get_elf_hwcap(cpuinfo, cpuinfo_len); if (hwcaps != 0) { int has_vfp = (hwcaps & HWCAP_VFP); int has_vfpv3 = (hwcaps & HWCAP_VFPv3); int has_vfpv3d16 = (hwcaps & HWCAP_VFPv3D16); int has_vfpv4 = (hwcaps & HWCAP_VFPv4); int has_neon = (hwcaps & HWCAP_NEON); int has_idiva = (hwcaps & HWCAP_IDIVA); int has_idivt = (hwcaps & HWCAP_IDIVT); int has_iwmmxt = (hwcaps & HWCAP_IWMMXT); // The kernel does a poor job at ensuring consistency when // describing CPU features. So lots of guessing is needed. // 'vfpv4' implies VFPv3|VFP_FMA|FP16 if (has_vfpv4) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv3 | ANDROID_CPU_ARM_FEATURE_VFP_FP16 | ANDROID_CPU_ARM_FEATURE_VFP_FMA; // 'vfpv3' or 'vfpv3d16' imply VFPv3. Note that unlike GCC, // a value of 'vfpv3' doesn't necessarily mean that the D32 // feature is present, so be conservative. All CPUs in the // field that support D32 also support NEON, so this should // not be a problem in practice. if (has_vfpv3 || has_vfpv3d16) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv3; // 'vfp' is super ambiguous. Depending on the kernel, it can // either mean VFPv2 or VFPv3. Make it depend on ARMv7. if (has_vfp) { if (g_cpuFeatures & ANDROID_CPU_ARM_FEATURE_ARMv7) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv3; else g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv2; } // Neon implies VFPv3|D32, and if vfpv4 is detected, NEON_FMA if (has_neon) { g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv3 | ANDROID_CPU_ARM_FEATURE_NEON | ANDROID_CPU_ARM_FEATURE_VFP_D32; if (has_vfpv4) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_NEON_FMA; } // VFPv3 implies VFPv2 and ARMv7 if (g_cpuFeatures & ANDROID_CPU_ARM_FEATURE_VFPv3) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_VFPv2 | ANDROID_CPU_ARM_FEATURE_ARMv7; if (has_idiva) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_IDIV_ARM; if (has_idivt) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_IDIV_THUMB2; if (has_iwmmxt) g_cpuFeatures |= ANDROID_CPU_ARM_FEATURE_iWMMXt; } /* Extract the cpuid value from various fields */ // The CPUID value is broken up in several entries in /proc/cpuinfo. // This table is used to rebuild it from the entries. static const struct CpuIdEntry { const char* field; char format; char bit_lshift; char bit_length; } cpu_id_entries[] = { { "CPU implementer", 'x', 24, 8 }, { "CPU variant", 'x', 20, 4 }, { "CPU part", 'x', 4, 12 }, { "CPU revision", 'd', 0, 4 }, }; size_t i; D("Parsing /proc/cpuinfo to recover CPUID\n"); for (i = 0; i < sizeof(cpu_id_entries)/sizeof(cpu_id_entries[0]); ++i) { const struct CpuIdEntry* entry = &cpu_id_entries[i]; char* value = extract_cpuinfo_field(cpuinfo, cpuinfo_len, entry->field); if (value == NULL) continue; D("field=%s value='%s'\n", entry->field, value); char* value_end = value + strlen(value); int val = 0; const char* start = value; const char* p; if (value[0] == '0' && (value[1] == 'x' || value[1] == 'X')) { start += 2; p = parse_hexadecimal(start, value_end, &val); } else if (entry->format == 'x') p = parse_hexadecimal(value, value_end, &val); else p = parse_decimal(value, value_end, &val); if (p > (const char*)start) { val &= ((1 << entry->bit_length)-1); val <<= entry->bit_lshift; g_cpuIdArm |= (uint32_t) val; } free(value); } // Handle kernel configuration bugs that prevent the correct // reporting of CPU features. static const struct CpuFix { uint32_t cpuid; uint64_t or_flags; } cpu_fixes[] = { /* The Nexus 4 (Qualcomm Krait) kernel configuration * forgets to report IDIV support. */ { 0x510006f2, ANDROID_CPU_ARM_FEATURE_IDIV_ARM | ANDROID_CPU_ARM_FEATURE_IDIV_THUMB2 }, { 0x510006f3, ANDROID_CPU_ARM_FEATURE_IDIV_ARM | ANDROID_CPU_ARM_FEATURE_IDIV_THUMB2 }, }; size_t n; for (n = 0; n < sizeof(cpu_fixes)/sizeof(cpu_fixes[0]); ++n) { const struct CpuFix* entry = &cpu_fixes[n]; if (g_cpuIdArm == entry->cpuid) g_cpuFeatures |= entry->or_flags; } } #endif /* __arm__ */ #ifdef __i386__ int regs[4]; /* According to http://en.wikipedia.org/wiki/CPUID */ #define VENDOR_INTEL_b 0x756e6547 #define VENDOR_INTEL_c 0x6c65746e #define VENDOR_INTEL_d 0x49656e69 x86_cpuid(0, regs); int vendorIsIntel = (regs[1] == VENDOR_INTEL_b && regs[2] == VENDOR_INTEL_c && regs[3] == VENDOR_INTEL_d); x86_cpuid(1, regs); if ((regs[2] & (1 << 9)) != 0) { g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_SSSE3; } if ((regs[2] & (1 << 23)) != 0) { g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_POPCNT; } if (vendorIsIntel && (regs[2] & (1 << 22)) != 0) { g_cpuFeatures |= ANDROID_CPU_X86_FEATURE_MOVBE; } #endif free(cpuinfo); } AndroidCpuFamily libtheoraplayer_android_getCpuFamily(void) { pthread_once(&g_once, android_cpuInit); return g_cpuFamily; } uint64_t libtheoraplayer_android_getCpuFeaturesExt(void) { pthread_once(&g_once, android_cpuInit); return g_cpuFeatures; } int libtheoraplayer_android_getCpuCount(void) { pthread_once(&g_once, android_cpuInit); return g_cpuCount; } static void libtheoraplayer_android_cpuInitDummy(void) { g_inited = 1; } int libtheoraplayer_android_setCpu(int cpu_count, uint64_t cpu_features) { /* Fail if the library was already initialized. */ if (g_inited) return 0; android_cpuInitFamily(); g_cpuCount = (cpu_count <= 0 ? 1 : cpu_count); g_cpuFeatures = cpu_features; pthread_once(&g_once, libtheoraplayer_android_cpuInitDummy); return 1; } #ifdef __arm__ uint32_t libtheoraplayer_android_getCpuIdArm(void) { pthread_once(&g_once, android_cpuInit); return g_cpuIdArm; } int libtheoraplayer_android_setCpuArm(int cpu_count, uint64_t cpu_features, uint32_t cpu_id) { if (!libtheoraplayer_android_setCpu(cpu_count, cpu_features)) return 0; g_cpuIdArm = cpu_id; return 1; } #endif /* __arm__ */ /* * Technical note: Making sense of ARM's FPU architecture versions. * * FPA was ARM's first attempt at an FPU architecture. There is no Android * device that actually uses it since this technology was already obsolete * when the project started. If you see references to FPA instructions * somewhere, you can be sure that this doesn't apply to Android at all. * * FPA was followed by "VFP", soon renamed "VFPv1" due to the emergence of * new versions / additions to it. ARM considers this obsolete right now, * and no known Android device implements it either. * * VFPv2 added a few instructions to VFPv1, and is an *optional* extension * supported by some ARMv5TE, ARMv6 and ARMv6T2 CPUs. Note that a device * supporting the 'armeabi' ABI doesn't necessarily support these. * * VFPv3-D16 adds a few instructions on top of VFPv2 and is typically used * on ARMv7-A CPUs which implement a FPU. Note that it is also mandated * by the Android 'armeabi-v7a' ABI. The -D16 suffix in its name means * that it provides 16 double-precision FPU registers (d0-d15) and 32 * single-precision ones (s0-s31) which happen to be mapped to the same * register banks. * * VFPv3-D32 is the name of an extension to VFPv3-D16 that provides 16 * additional double precision registers (d16-d31). Note that there are * still only 32 single precision registers. * * VFPv3xD is a *subset* of VFPv3-D16 that only provides single-precision * registers. It is only used on ARMv7-M (i.e. on micro-controllers) which * are not supported by Android. Note that it is not compatible with VFPv2. * * NOTE: The term 'VFPv3' usually designate either VFPv3-D16 or VFPv3-D32 * depending on context. For example GCC uses it for VFPv3-D32, but * the Linux kernel code uses it for VFPv3-D16 (especially in * /proc/cpuinfo). Always try to use the full designation when * possible. * * NEON, a.k.a. "ARM Advanced SIMD" is an extension that provides * instructions to perform parallel computations on vectors of 8, 16, * 32, 64 and 128 bit quantities. NEON requires VFPv32-D32 since all * NEON registers are also mapped to the same register banks. * * VFPv4-D16, adds a few instructions on top of VFPv3-D16 in order to * perform fused multiply-accumulate on VFP registers, as well as * half-precision (16-bit) conversion operations. * * VFPv4-D32 is VFPv4-D16 with 32, instead of 16, FPU double precision * registers. * * VPFv4-NEON is VFPv4-D32 with NEON instructions. It also adds fused * multiply-accumulate instructions that work on the NEON registers. * * NOTE: Similarly, "VFPv4" might either reference VFPv4-D16 or VFPv4-D32 * depending on context. * * The following information was determined by scanning the binutils-2.22 * sources: * * Basic VFP instruction subsets: * * #define FPU_VFP_EXT_V1xD 0x08000000 // Base VFP instruction set. * #define FPU_VFP_EXT_V1 0x04000000 // Double-precision insns. * #define FPU_VFP_EXT_V2 0x02000000 // ARM10E VFPr1. * #define FPU_VFP_EXT_V3xD 0x01000000 // VFPv3 single-precision. * #define FPU_VFP_EXT_V3 0x00800000 // VFPv3 double-precision. * #define FPU_NEON_EXT_V1 0x00400000 // Neon (SIMD) insns. * #define FPU_VFP_EXT_D32 0x00200000 // Registers D16-D31. * #define FPU_VFP_EXT_FP16 0x00100000 // Half-precision extensions. * #define FPU_NEON_EXT_FMA 0x00080000 // Neon fused multiply-add * #define FPU_VFP_EXT_FMA 0x00040000 // VFP fused multiply-add * * FPU types (excluding NEON) * * FPU_VFP_V1xD (EXT_V1xD) * | * +--------------------------+ * | | * FPU_VFP_V1 (+EXT_V1) FPU_VFP_V3xD (+EXT_V2+EXT_V3xD) * | | * | | * FPU_VFP_V2 (+EXT_V2) FPU_VFP_V4_SP_D16 (+EXT_FP16+EXT_FMA) * | * FPU_VFP_V3D16 (+EXT_Vx3D+EXT_V3) * | * +--------------------------+ * | | * FPU_VFP_V3 (+EXT_D32) FPU_VFP_V4D16 (+EXT_FP16+EXT_FMA) * | | * | FPU_VFP_V4 (+EXT_D32) * | * FPU_VFP_HARD (+EXT_FMA+NEON_EXT_FMA) * * VFP architectures: * * ARCH_VFP_V1xD (EXT_V1xD) * | * +------------------+ * | | * | ARCH_VFP_V3xD (+EXT_V2+EXT_V3xD) * | | * | ARCH_VFP_V3xD_FP16 (+EXT_FP16) * | | * | ARCH_VFP_V4_SP_D16 (+EXT_FMA) * | * ARCH_VFP_V1 (+EXT_V1) * | * ARCH_VFP_V2 (+EXT_V2) * | * ARCH_VFP_V3D16 (+EXT_V3xD+EXT_V3) * | * +-------------------+ * | | * | ARCH_VFP_V3D16_FP16 (+EXT_FP16) * | * +-------------------+ * | | * | ARCH_VFP_V4_D16 (+EXT_FP16+EXT_FMA) * | | * | ARCH_VFP_V4 (+EXT_D32) * | | * | ARCH_NEON_VFP_V4 (+EXT_NEON+EXT_NEON_FMA) * | * ARCH_VFP_V3 (+EXT_D32) * | * +-------------------+ * | | * | ARCH_VFP_V3_FP16 (+EXT_FP16) * | * ARCH_VFP_V3_PLUS_NEON_V1 (+EXT_NEON) * | * ARCH_NEON_FP16 (+EXT_FP16) * * -fpu=<name> values and their correspondance with FPU architectures above: * * {"vfp", FPU_ARCH_VFP_V2}, * {"vfp9", FPU_ARCH_VFP_V2}, * {"vfp3", FPU_ARCH_VFP_V3}, // For backwards compatbility. * {"vfp10", FPU_ARCH_VFP_V2}, * {"vfp10-r0", FPU_ARCH_VFP_V1}, * {"vfpxd", FPU_ARCH_VFP_V1xD}, * {"vfpv2", FPU_ARCH_VFP_V2}, * {"vfpv3", FPU_ARCH_VFP_V3}, * {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16}, * {"vfpv3-d16", FPU_ARCH_VFP_V3D16}, * {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16}, * {"vfpv3xd", FPU_ARCH_VFP_V3xD}, * {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16}, * {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1}, * {"neon-fp16", FPU_ARCH_NEON_FP16}, * {"vfpv4", FPU_ARCH_VFP_V4}, * {"vfpv4-d16", FPU_ARCH_VFP_V4D16}, * {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16}, * {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4}, * * * Simplified diagram that only includes FPUs supported by Android: * Only ARCH_VFP_V3D16 is actually mandated by the armeabi-v7a ABI, * all others are optional and must be probed at runtime. * * ARCH_VFP_V3D16 (EXT_V1xD+EXT_V1+EXT_V2+EXT_V3xD+EXT_V3) * | * +-------------------+ * | | * | ARCH_VFP_V3D16_FP16 (+EXT_FP16) * | * +-------------------+ * | | * | ARCH_VFP_V4_D16 (+EXT_FP16+EXT_FMA) * | | * | ARCH_VFP_V4 (+EXT_D32) * | | * | ARCH_NEON_VFP_V4 (+EXT_NEON+EXT_NEON_FMA) * | * ARCH_VFP_V3 (+EXT_D32) * | * +-------------------+ * | | * | ARCH_VFP_V3_FP16 (+EXT_FP16) * | * ARCH_VFP_V3_PLUS_NEON_V1 (+EXT_NEON) * | * ARCH_NEON_FP16 (+EXT_FP16) * */ #endif // defined(__le32__) #endif
the_stack_data/215767733.c
/* * Copyright (C) 2015-2018 Alibaba Group Holding Limited */ /* * The NIST SP 800-90 DRBGs are described in the following publucation. * * http://csrc.nist.gov/publications/nistpubs/800-90/SP800-90revised_March2007.pdf */ #ifdef SUPPORT_TLS #if !defined(MBEDTLS_CONFIG_FILE) #include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif #if defined(MBEDTLS_CTR_DRBG_C) #include "mbedtls/ctr_drbg.h" #include <string.h> #if defined(MBEDTLS_FS_IO) #include <stdio.h> #endif #if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" #else #include <stdio.h> #include "mbedtls/debug.h" #define mbedtls_printf tls_info #endif /* MBEDTLS_PLATFORM_C */ #endif /* MBEDTLS_SELF_TEST */ /* Implementation that should never be optimized out by the compiler */ static void mbedtls_zeroize( void *v, size_t n ) { volatile unsigned char *p = v; while( n-- ) *p++ = 0; } /* * CTR_DRBG context initialization */ void mbedtls_ctr_drbg_init( mbedtls_ctr_drbg_context *ctx ) { memset( ctx, 0, sizeof( mbedtls_ctr_drbg_context ) ); #if defined(MBEDTLS_THREADING_C) mbedtls_mutex_init( &ctx->mutex ); #endif } /* * Non-public function wrapped by mbedtls_ctr_drbg_seed(). Necessary to allow * NIST tests to succeed (which require known length fixed entropy) */ int mbedtls_ctr_drbg_seed_entropy_len( mbedtls_ctr_drbg_context *ctx, int (*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len, size_t entropy_len ) { int ret; unsigned char key[MBEDTLS_CTR_DRBG_KEYSIZE]; memset( key, 0, MBEDTLS_CTR_DRBG_KEYSIZE ); mbedtls_aes_init( &ctx->aes_ctx ); ctx->f_entropy = f_entropy; ctx->p_entropy = p_entropy; ctx->entropy_len = entropy_len; ctx->reseed_interval = MBEDTLS_CTR_DRBG_RESEED_INTERVAL; /* * Initialize with an empty key */ mbedtls_aes_setkey_enc( &ctx->aes_ctx, key, MBEDTLS_CTR_DRBG_KEYBITS ); if( ( ret = mbedtls_ctr_drbg_reseed( ctx, custom, len ) ) != 0 ) return( ret ); return( 0 ); } int mbedtls_ctr_drbg_seed( mbedtls_ctr_drbg_context *ctx, int (*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len ) { return( mbedtls_ctr_drbg_seed_entropy_len( ctx, f_entropy, p_entropy, custom, len, MBEDTLS_CTR_DRBG_ENTROPY_LEN ) ); } void mbedtls_ctr_drbg_free( mbedtls_ctr_drbg_context *ctx ) { if( ctx == NULL ) return; #if defined(MBEDTLS_THREADING_C) mbedtls_mutex_free( &ctx->mutex ); #endif mbedtls_aes_free( &ctx->aes_ctx ); mbedtls_zeroize( ctx, sizeof( mbedtls_ctr_drbg_context ) ); } void mbedtls_ctr_drbg_set_prediction_resistance( mbedtls_ctr_drbg_context *ctx, int resistance ) { ctx->prediction_resistance = resistance; } void mbedtls_ctr_drbg_set_entropy_len( mbedtls_ctr_drbg_context *ctx, size_t len ) { ctx->entropy_len = len; } void mbedtls_ctr_drbg_set_reseed_interval( mbedtls_ctr_drbg_context *ctx, int interval ) { ctx->reseed_interval = interval; } static int block_cipher_df( unsigned char *output, const unsigned char *data, size_t data_len ) { unsigned char buf[MBEDTLS_CTR_DRBG_MAX_SEED_INPUT + MBEDTLS_CTR_DRBG_BLOCKSIZE + 16]; unsigned char tmp[MBEDTLS_CTR_DRBG_SEEDLEN]; unsigned char key[MBEDTLS_CTR_DRBG_KEYSIZE]; unsigned char chain[MBEDTLS_CTR_DRBG_BLOCKSIZE]; unsigned char *p, *iv; mbedtls_aes_context aes_ctx; int i, j; size_t buf_len, use_len; if( data_len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT ) return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ); memset( buf, 0, MBEDTLS_CTR_DRBG_MAX_SEED_INPUT + MBEDTLS_CTR_DRBG_BLOCKSIZE + 16 ); mbedtls_aes_init( &aes_ctx ); /* * Construct IV (16 bytes) and S in buffer * IV = Counter (in 32-bits) padded to 16 with zeroes * S = Length input string (in 32-bits) || Length of output (in 32-bits) || * data || 0x80 * (Total is padded to a multiple of 16-bytes with zeroes) */ p = buf + MBEDTLS_CTR_DRBG_BLOCKSIZE; *p++ = ( data_len >> 24 ) & 0xff; *p++ = ( data_len >> 16 ) & 0xff; *p++ = ( data_len >> 8 ) & 0xff; *p++ = ( data_len ) & 0xff; p += 3; *p++ = MBEDTLS_CTR_DRBG_SEEDLEN; memcpy( p, data, data_len ); p[data_len] = 0x80; buf_len = MBEDTLS_CTR_DRBG_BLOCKSIZE + 8 + data_len + 1; for( i = 0; i < MBEDTLS_CTR_DRBG_KEYSIZE; i++ ) key[i] = i; mbedtls_aes_setkey_enc( &aes_ctx, key, MBEDTLS_CTR_DRBG_KEYBITS ); /* * Reduce data to MBEDTLS_CTR_DRBG_SEEDLEN bytes of data */ for( j = 0; j < MBEDTLS_CTR_DRBG_SEEDLEN; j += MBEDTLS_CTR_DRBG_BLOCKSIZE ) { p = buf; memset( chain, 0, MBEDTLS_CTR_DRBG_BLOCKSIZE ); use_len = buf_len; while( use_len > 0 ) { for( i = 0; i < MBEDTLS_CTR_DRBG_BLOCKSIZE; i++ ) chain[i] ^= p[i]; p += MBEDTLS_CTR_DRBG_BLOCKSIZE; use_len -= ( use_len >= MBEDTLS_CTR_DRBG_BLOCKSIZE ) ? MBEDTLS_CTR_DRBG_BLOCKSIZE : use_len; mbedtls_aes_crypt_ecb( &aes_ctx, MBEDTLS_AES_ENCRYPT, chain, chain ); } memcpy( tmp + j, chain, MBEDTLS_CTR_DRBG_BLOCKSIZE ); /* * Update IV */ buf[3]++; } /* * Do final encryption with reduced data */ mbedtls_aes_setkey_enc( &aes_ctx, tmp, MBEDTLS_CTR_DRBG_KEYBITS ); iv = tmp + MBEDTLS_CTR_DRBG_KEYSIZE; p = output; for( j = 0; j < MBEDTLS_CTR_DRBG_SEEDLEN; j += MBEDTLS_CTR_DRBG_BLOCKSIZE ) { mbedtls_aes_crypt_ecb( &aes_ctx, MBEDTLS_AES_ENCRYPT, iv, iv ); memcpy( p, iv, MBEDTLS_CTR_DRBG_BLOCKSIZE ); p += MBEDTLS_CTR_DRBG_BLOCKSIZE; } mbedtls_aes_free( &aes_ctx ); return( 0 ); } static int ctr_drbg_update_internal( mbedtls_ctr_drbg_context *ctx, const unsigned char data[MBEDTLS_CTR_DRBG_SEEDLEN] ) { unsigned char tmp[MBEDTLS_CTR_DRBG_SEEDLEN]; unsigned char *p = tmp; int i, j; memset( tmp, 0, MBEDTLS_CTR_DRBG_SEEDLEN ); for( j = 0; j < MBEDTLS_CTR_DRBG_SEEDLEN; j += MBEDTLS_CTR_DRBG_BLOCKSIZE ) { /* * Increase counter */ for( i = MBEDTLS_CTR_DRBG_BLOCKSIZE; i > 0; i-- ) if( ++ctx->counter[i - 1] != 0 ) break; /* * Crypt counter block */ mbedtls_aes_crypt_ecb( &ctx->aes_ctx, MBEDTLS_AES_ENCRYPT, ctx->counter, p ); p += MBEDTLS_CTR_DRBG_BLOCKSIZE; } for( i = 0; i < MBEDTLS_CTR_DRBG_SEEDLEN; i++ ) tmp[i] ^= data[i]; /* * Update key and counter */ mbedtls_aes_setkey_enc( &ctx->aes_ctx, tmp, MBEDTLS_CTR_DRBG_KEYBITS ); memcpy( ctx->counter, tmp + MBEDTLS_CTR_DRBG_KEYSIZE, MBEDTLS_CTR_DRBG_BLOCKSIZE ); return( 0 ); } void mbedtls_ctr_drbg_update( mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len ) { unsigned char add_input[MBEDTLS_CTR_DRBG_SEEDLEN]; if( add_len > 0 ) { /* MAX_INPUT would be more logical here, but we have to match * block_cipher_df()'s limits since we can't propagate errors */ if( add_len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT ) add_len = MBEDTLS_CTR_DRBG_MAX_SEED_INPUT; block_cipher_df( add_input, additional, add_len ); ctr_drbg_update_internal( ctx, add_input ); } } int mbedtls_ctr_drbg_reseed( mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t len ) { unsigned char seed[MBEDTLS_CTR_DRBG_MAX_SEED_INPUT]; size_t seedlen = 0; if( ctx->entropy_len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT || len > MBEDTLS_CTR_DRBG_MAX_SEED_INPUT - ctx->entropy_len ) return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ); memset( seed, 0, MBEDTLS_CTR_DRBG_MAX_SEED_INPUT ); /* * Gather entropy_len bytes of entropy to seed state */ if( 0 != ctx->f_entropy( ctx->p_entropy, seed, ctx->entropy_len ) ) { return( MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED ); } seedlen += ctx->entropy_len; /* * Add additional data */ if( additional && len ) { memcpy( seed + seedlen, additional, len ); seedlen += len; } /* * Reduce to 384 bits */ block_cipher_df( seed, seed, seedlen ); /* * Update state */ ctr_drbg_update_internal( ctx, seed ); ctx->reseed_counter = 1; return( 0 ); } int mbedtls_ctr_drbg_random_with_add( void *p_rng, unsigned char *output, size_t output_len, const unsigned char *additional, size_t add_len ) { int ret = 0; mbedtls_ctr_drbg_context *ctx = (mbedtls_ctr_drbg_context *) p_rng; unsigned char add_input[MBEDTLS_CTR_DRBG_SEEDLEN]; unsigned char *p = output; unsigned char tmp[MBEDTLS_CTR_DRBG_BLOCKSIZE]; int i; size_t use_len; if( output_len > MBEDTLS_CTR_DRBG_MAX_REQUEST ) return( MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG ); if( add_len > MBEDTLS_CTR_DRBG_MAX_INPUT ) return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ); memset( add_input, 0, MBEDTLS_CTR_DRBG_SEEDLEN ); if( ctx->reseed_counter > ctx->reseed_interval || ctx->prediction_resistance ) { if( ( ret = mbedtls_ctr_drbg_reseed( ctx, additional, add_len ) ) != 0 ) return( ret ); add_len = 0; } if( add_len > 0 ) { block_cipher_df( add_input, additional, add_len ); ctr_drbg_update_internal( ctx, add_input ); } while( output_len > 0 ) { /* * Increase counter */ for( i = MBEDTLS_CTR_DRBG_BLOCKSIZE; i > 0; i-- ) if( ++ctx->counter[i - 1] != 0 ) break; /* * Crypt counter block */ mbedtls_aes_crypt_ecb( &ctx->aes_ctx, MBEDTLS_AES_ENCRYPT, ctx->counter, tmp ); use_len = ( output_len > MBEDTLS_CTR_DRBG_BLOCKSIZE ) ? MBEDTLS_CTR_DRBG_BLOCKSIZE : output_len; /* * Copy random block to destination */ memcpy( p, tmp, use_len ); p += use_len; output_len -= use_len; } ctr_drbg_update_internal( ctx, add_input ); ctx->reseed_counter++; return( 0 ); } int mbedtls_ctr_drbg_random( void *p_rng, unsigned char *output, size_t output_len ) { int ret; mbedtls_ctr_drbg_context *ctx = (mbedtls_ctr_drbg_context *) p_rng; #if defined(MBEDTLS_THREADING_C) if( ( ret = mbedtls_mutex_lock( &ctx->mutex ) ) != 0 ) return( ret ); #endif ret = mbedtls_ctr_drbg_random_with_add( ctx, output, output_len, NULL, 0 ); #if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &ctx->mutex ) != 0 ) return( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); #endif return( ret ); } #if defined(MBEDTLS_FS_IO) int mbedtls_ctr_drbg_write_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path ) { int ret = MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR; FILE *f; unsigned char buf[ MBEDTLS_CTR_DRBG_MAX_INPUT ]; if( ( f = fopen( path, "wb" ) ) == NULL ) return( MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR ); if( ( ret = mbedtls_ctr_drbg_random( ctx, buf, MBEDTLS_CTR_DRBG_MAX_INPUT ) ) != 0 ) goto exit; if( fwrite( buf, 1, MBEDTLS_CTR_DRBG_MAX_INPUT, f ) != MBEDTLS_CTR_DRBG_MAX_INPUT ) { ret = MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR; goto exit; } ret = 0; exit: fclose( f ); return( ret ); } int mbedtls_ctr_drbg_update_seed_file( mbedtls_ctr_drbg_context *ctx, const char *path ) { FILE *f; size_t n; unsigned char buf[ MBEDTLS_CTR_DRBG_MAX_INPUT ]; if( ( f = fopen( path, "rb" ) ) == NULL ) return( MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR ); fseek( f, 0, SEEK_END ); n = (size_t) ftell( f ); fseek( f, 0, SEEK_SET ); if( n > MBEDTLS_CTR_DRBG_MAX_INPUT ) { fclose( f ); return( MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG ); } if( fread( buf, 1, n, f ) != n ) { fclose( f ); return( MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR ); } fclose( f ); mbedtls_ctr_drbg_update( ctx, buf, n ); return( mbedtls_ctr_drbg_write_seed_file( ctx, path ) ); } #endif /* MBEDTLS_FS_IO */ #if defined(MBEDTLS_SELF_TEST) static const unsigned char entropy_source_pr[96] = { 0xc1, 0x80, 0x81, 0xa6, 0x5d, 0x44, 0x02, 0x16, 0x19, 0xb3, 0xf1, 0x80, 0xb1, 0xc9, 0x20, 0x02, 0x6a, 0x54, 0x6f, 0x0c, 0x70, 0x81, 0x49, 0x8b, 0x6e, 0xa6, 0x62, 0x52, 0x6d, 0x51, 0xb1, 0xcb, 0x58, 0x3b, 0xfa, 0xd5, 0x37, 0x5f, 0xfb, 0xc9, 0xff, 0x46, 0xd2, 0x19, 0xc7, 0x22, 0x3e, 0x95, 0x45, 0x9d, 0x82, 0xe1, 0xe7, 0x22, 0x9f, 0x63, 0x31, 0x69, 0xd2, 0x6b, 0x57, 0x47, 0x4f, 0xa3, 0x37, 0xc9, 0x98, 0x1c, 0x0b, 0xfb, 0x91, 0x31, 0x4d, 0x55, 0xb9, 0xe9, 0x1c, 0x5a, 0x5e, 0xe4, 0x93, 0x92, 0xcf, 0xc5, 0x23, 0x12, 0xd5, 0x56, 0x2c, 0x4a, 0x6e, 0xff, 0xdc, 0x10, 0xd0, 0x68 }; static const unsigned char entropy_source_nopr[64] = { 0x5a, 0x19, 0x4d, 0x5e, 0x2b, 0x31, 0x58, 0x14, 0x54, 0xde, 0xf6, 0x75, 0xfb, 0x79, 0x58, 0xfe, 0xc7, 0xdb, 0x87, 0x3e, 0x56, 0x89, 0xfc, 0x9d, 0x03, 0x21, 0x7c, 0x68, 0xd8, 0x03, 0x38, 0x20, 0xf9, 0xe6, 0x5e, 0x04, 0xd8, 0x56, 0xf3, 0xa9, 0xc4, 0x4a, 0x4c, 0xbd, 0xc1, 0xd0, 0x08, 0x46, 0xf5, 0x98, 0x3d, 0x77, 0x1c, 0x1b, 0x13, 0x7e, 0x4e, 0x0f, 0x9d, 0x8e, 0xf4, 0x09, 0xf9, 0x2e }; static const unsigned char nonce_pers_pr[16] = { 0xd2, 0x54, 0xfc, 0xff, 0x02, 0x1e, 0x69, 0xd2, 0x29, 0xc9, 0xcf, 0xad, 0x85, 0xfa, 0x48, 0x6c }; static const unsigned char nonce_pers_nopr[16] = { 0x1b, 0x54, 0xb8, 0xff, 0x06, 0x42, 0xbf, 0xf5, 0x21, 0xf1, 0x5c, 0x1c, 0x0b, 0x66, 0x5f, 0x3f }; static const unsigned char result_pr[16] = { 0x34, 0x01, 0x16, 0x56, 0xb4, 0x29, 0x00, 0x8f, 0x35, 0x63, 0xec, 0xb5, 0xf2, 0x59, 0x07, 0x23 }; static const unsigned char result_nopr[16] = { 0xa0, 0x54, 0x30, 0x3d, 0x8a, 0x7e, 0xa9, 0x88, 0x9d, 0x90, 0x3e, 0x07, 0x7c, 0x6f, 0x21, 0x8f }; static size_t test_offset; static int ctr_drbg_self_test_entropy( void *data, unsigned char *buf, size_t len ) { const unsigned char *p = data; memcpy( buf, p + test_offset, len ); test_offset += len; return( 0 ); } #define CHK( c ) if( (c) != 0 ) \ { \ if( verbose != 0 ) \ mbedtls_printf( "failed\n" ); \ return( 1 ); \ } /* * Checkup routine */ int mbedtls_ctr_drbg_self_test( int verbose ) { mbedtls_ctr_drbg_context ctx; unsigned char buf[16]; mbedtls_ctr_drbg_init( &ctx ); /* * Based on a NIST CTR_DRBG test vector (PR = True) */ if( verbose != 0 ) mbedtls_printf( " CTR_DRBG (PR = TRUE) : " ); test_offset = 0; CHK( mbedtls_ctr_drbg_seed_entropy_len( &ctx, ctr_drbg_self_test_entropy, (void *) entropy_source_pr, nonce_pers_pr, 16, 32 ) ); mbedtls_ctr_drbg_set_prediction_resistance( &ctx, MBEDTLS_CTR_DRBG_PR_ON ); CHK( mbedtls_ctr_drbg_random( &ctx, buf, MBEDTLS_CTR_DRBG_BLOCKSIZE ) ); CHK( mbedtls_ctr_drbg_random( &ctx, buf, MBEDTLS_CTR_DRBG_BLOCKSIZE ) ); CHK( memcmp( buf, result_pr, MBEDTLS_CTR_DRBG_BLOCKSIZE ) ); mbedtls_ctr_drbg_free( &ctx ); if( verbose != 0 ) mbedtls_printf( "passed\n" ); /* * Based on a NIST CTR_DRBG test vector (PR = FALSE) */ if( verbose != 0 ) mbedtls_printf( " CTR_DRBG (PR = FALSE): " ); mbedtls_ctr_drbg_init( &ctx ); test_offset = 0; CHK( mbedtls_ctr_drbg_seed_entropy_len( &ctx, ctr_drbg_self_test_entropy, (void *) entropy_source_nopr, nonce_pers_nopr, 16, 32 ) ); CHK( mbedtls_ctr_drbg_random( &ctx, buf, 16 ) ); CHK( mbedtls_ctr_drbg_reseed( &ctx, NULL, 0 ) ); CHK( mbedtls_ctr_drbg_random( &ctx, buf, 16 ) ); CHK( memcmp( buf, result_nopr, 16 ) ); mbedtls_ctr_drbg_free( &ctx ); if( verbose != 0 ) mbedtls_printf( "passed\n" ); if( verbose != 0 ) mbedtls_printf( "\n" ); return( 0 ); } #endif /* MBEDTLS_SELF_TEST */ #endif /* MBEDTLS_CTR_DRBG_C */ #endif
the_stack_data/103264915.c
#include <stdio.h> int main(void) { int count = 0, i, x; // Get number from user printf("Enter a number: "); scanf("%d", &x); for (int j = 2; j <= x; j++) { for (i = 2; i * i <= j; i++) if (j % i == 0) break; if (i * i > j) count++; } // For reference, there are 1229 primes from 1 to 10000 printf("\nThere are %d prime numbers from 1 to %d\n", count, x); return 0; }
the_stack_data/206392182.c
/* This program by D E Knuth is in the public domain and freely copyable * AS LONG AS YOU MAKE ABSOLUTELY NO CHANGES! * It is explained in Seminumerical Algorithms, 3rd edition, Section 3.6 * (or in the errata to the 2nd edition --- see * http://www-cs-faculty.stanford.edu/~knuth/taocp.html * in the changes to Volume 2 on pages 171 and following). */ /* N.B. The MODIFICATIONS introduced in the 9th printing (2002) are included here; there's no backwards compatibility with the original. */ /* This version also adopts Brendan McKay's suggestion to accommodate naive users who forget to call ran_start(seed). */ /* If you find any bugs, please report them immediately to * [email protected] * (and you will be rewarded if the bug is genuine). Thanks! */ /************ see the book for explanations and caveats! *******************/ /************ in particular, you need two's complement arithmetic **********/ #define KK 100 /* the long lag */ #define LL 37 /* the short lag */ #define MM (1L<<30) /* the modulus */ #define mod_diff(x,y) (((x)-(y))&(MM-1)) /* subtraction mod MM */ long ran_x[KK]; /* the generator state */ #ifdef __STDC__ void ran_array(long aa[], int n) #else void ran_array(aa, n) /* put n new random numbers in aa */ long * aa; /* destination */ int n; /* array length (must be at least KK) */ #endif { register int i, j; for (j = 0; j < KK; j++) { aa[j] = ran_x[j]; } for (; j < n; j++) { aa[j] = mod_diff(aa[j - KK], aa[j - LL]); } for (i = 0; i < LL; i++, j++) { ran_x[i] = mod_diff(aa[j - KK], aa[j - LL]); } for (; i < KK; i++, j++) { ran_x[i] = mod_diff(aa[j - KK], ran_x[i - LL]); } } /* the following routines are from exercise 3.6--15 */ /* after calling ran_start, get new randoms by, e.g., "x=ran_arr_next()" */ #define QUALITY 1009 /* recommended quality level for high-res use */ long ran_arr_buf[QUALITY]; long ran_arr_dummy = -1, ran_arr_started = -1; long * ran_arr_ptr = &ran_arr_dummy; /* the next random number, or -1 */ #define TT 70 /* guaranteed separation between streams */ #define is_odd(x) ((x)&1) /* units bit of x */ #ifdef __STDC__ void ran_start(long seed) #else void ran_start(seed) /* do this before using ran_array */ long seed; /* selector for different streams */ #endif { register int t, j; long x[KK + KK - 1]; /* the preparation buffer */ register long ss = (seed + 2) & (MM - 2); for (j = 0; j < KK; j++) { x[j] = ss; /* bootstrap the buffer */ ss <<= 1; if (ss >= MM) { ss -= MM - 2; /* cyclic shift 29 bits */ } } x[1]++; /* make x[1] (and only x[1]) odd */ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wcomma" for (ss = seed & (MM - 1), t = TT - 1; t; ) { for (j = KK - 1; j > 0; j--) { x[j + j] = x[j], x[j + j - 1] = 0; /* "square" */ } for (j = KK + KK - 2; j >= KK; j--) x[j - (KK - LL)] = mod_diff(x[j - (KK - LL)], x[j]), x[j - KK] = mod_diff(x[j - KK], x[j]); if (is_odd(ss)) { /* "multiply by z" */ for (j = KK; j > 0; j--) { x[j] = x[j - 1]; } x[0] = x[KK]; /* shift the buffer cyclically */ x[LL] = mod_diff(x[LL], x[KK]); } if (ss) { ss >>= 1; } else { t--; } } #pragma clang diagnostic pop for (j = 0; j < LL; j++) { ran_x[j + KK - LL] = x[j]; } for (; j < KK; j++) { ran_x[j - LL] = x[j]; } for (j = 0; j < 10; j++) { ran_array(x, KK + KK - 1); /* warm things up */ } ran_arr_ptr = &ran_arr_started; } #define ran_arr_next() (*ran_arr_ptr>=0? *ran_arr_ptr++: ran_arr_cycle()) long ran_arr_cycle() { if (ran_arr_ptr == &ran_arr_dummy) { ran_start(314159L); /* the user forgot to initialize */ } ran_array(ran_arr_buf, QUALITY); ran_arr_buf[KK] = -1; ran_arr_ptr = ran_arr_buf + 1; return ran_arr_buf[0]; } /* Tweaked to include as a library - Fletcher T. Penney */ /*#include <stdio.h> int main() { register int m; long a[2009]; ran_start(310952L); for (m=0;m<=2009;m++) ran_array(a,1009); printf("%ld\n", a[0]); *//* 995235265 */ /* ran_start(310952L); for (m=0;m<=1009;m++) ran_array(a,2009); printf("%ld\n", a[0]); *//* 995235265 */ /* printf("%ld\n",ran_arr_next()); return 0; } */ long ran_num_next(void) { return ran_arr_next(); }
the_stack_data/758083.c
extern int gInitialisersCalled; __attribute__((constructor)) static void onLoad() { ++gInitialisersCalled; } int foo() { return 0; }
the_stack_data/176706632.c
#include <assert.h> #include <inttypes.h> union U { uint8_t a[4]; }; int main() { uint32_t x[2] = {0xDEADBEEF, 0xDEADBEEF}; union U *u = x; uint8_t c4 = u->a[4]; unsigned word = 1; if(*(char *)&word == 1) assert(c4 == 0xEF); // little endian else assert(c4 == 0xDE); // big endian }
the_stack_data/70682.c
#include <stdio.h> int diviseurImpair(int a) { while ((a % 2) == 0) a = a / 2; return a; } int main(int argc, char**argv) { printf("pour 4, ca donne %d\n",diviseurImpair(4)); printf("pour 7, ca donne %d\n",diviseurImpair(7)); printf("pour 28, ca donne %d\n",diviseurImpair(28)); printf("pour 86, ca donne %d\n",diviseurImpair(86)); printf("pour 50, ca donne %d\n",diviseurImpair(50)); }
the_stack_data/247017939.c
#include<stdio.h> double jiecheng(double x) {double i,q=1; for(i=1;i<=x;i++) q=q*i; return q; } int main() { double m,n,a,b,c,d; scanf("%lf%lf",&m,&n); a=jiecheng(m); b=jiecheng(n); c=jiecheng(m-n); d=a/(b*c); printf("%.0f",d); return 0; }
the_stack_data/151704905.c
#include <stdio.h> void scilab_rt_contour_i2i2d2d0d0d0_(int in00, int in01, int matrixin0[in00][in01], int in10, int in11, int matrixin1[in10][in11], int in20, int in21, double matrixin2[in20][in21], double scalarin0, double scalarin1, double scalarin2) { int i; int j; int val0 = 0; int val1 = 0; double val2 = 0; for (i = 0; i < in00; ++i) { for (j = 0; j < in01; ++j) { val0 += matrixin0[i][j]; } } printf("%d", val0); for (i = 0; i < in10; ++i) { for (j = 0; j < in11; ++j) { val1 += matrixin1[i][j]; } } printf("%d", val1); for (i = 0; i < in20; ++i) { for (j = 0; j < in21; ++j) { val2 += matrixin2[i][j]; } } printf("%f", val2); printf("%f", scalarin0); printf("%f", scalarin1); printf("%f", scalarin2); }
the_stack_data/49300.c
/* FUNCTION <<strnlen>>---character string length INDEX strnlen ANSI_SYNOPSIS #include <string.h> size_t strnlen(const char *<[str]>, size_t <[n]>); TRAD_SYNOPSIS #include <string.h> size_t strnlen(<[str]>, <[n]>) char *<[src]>; size_t <[n]>; DESCRIPTION The <<strnlen>> function works out the length of the string starting at <<*<[str]>>> by counting chararacters until it reaches a NUL character or the maximum: <[n]> number of characters have been inspected. RETURNS <<strnlen>> returns the character count or <[n]>. PORTABILITY <<strnlen>> is a GNU extension. <<strnlen>> requires no supporting OS subroutines. */ #include "string.h" size_t strnlen(const char *str, size_t n) { const char *start = str; while (n-- > 0 && *str) str++; return str - start; }
the_stack_data/15761462.c
#include <stdio.h> #include <stdlib.h> #include <math.h> typedef struct node { int value; struct node *left; struct node *right; struct node *parent; }node; typedef struct tree { node *root; int size; }tree; // инициализация пустого дерева void init(tree *t) { t->root=NULL; t->size=0; } //удалить все элементы из дерева /* поиск элемента по значению. вернуть 0 если элемент найд ен и ссылку на найденнйы элемент в переменную n если n != NULL. в случае если элемент не найден вернуть 1 */ int find_tree(tree *t, int znachenie, node **n) { node *tmp=t->root; while (tmp != NULL) { if (znachenie < tmp->value) { tmp=tmp->left; } else if (znachenie > tmp->value) { tmp=tmp->right; } else if (znachenie == tmp->value) { *n=tmp; tmp=NULL; return 0; } } tmp=NULL; return 1; } /* вставка значения в дерево. вернуть 0 если вставка выпол нена успешна, 1 если элемент уже существует 2 если не удалось выделить память для нового элемента */ int insert(tree *t, int znachenie) { int i; node *pred=NULL; node *tmp=t->root; if (tmp != NULL) { while (tmp != NULL) { if (znachenie < tmp->value) { if (tmp->left == NULL) { pred=tmp; //i=0; node *element_spiska=malloc(sizeof(node)); if (element_spiska == NULL) return 2; element_spiska->parent=pred; element_spiska->value=znachenie; element_spiska->left=NULL; element_spiska->right=NULL; pred->left=element_spiska; (t->size)++; tmp=NULL; return 0; } tmp=tmp->left; } else if (znachenie > tmp->value) { if (tmp->right == NULL) { pred=tmp; //i=0; node *element_spiska=malloc(sizeof(node)); if (element_spiska == NULL) return 2; element_spiska->parent=pred; element_spiska->value=znachenie; element_spiska->left=NULL; element_spiska->right=NULL; pred->right=element_spiska; (t->size)++; tmp=NULL; return 0; } tmp=tmp->right; } else if (znachenie == tmp->value) { tmp=NULL; return 1; } } } node *element_spiska=malloc(sizeof(node)); if (element_spiska == NULL) return 2; element_spiska->parent=NULL; element_spiska->value=znachenie; element_spiska->left=NULL; element_spiska->right=NULL; t->root=element_spiska; (t->size)++; tmp=NULL; return 0; } /* удалить элемент из дерева по указанному значению. вернуть 0 если элемент был удален и 1 если нет элемента с указанным значением */ int remove_(tree* t, int znachenie) { node *tmp = t -> root, *udal_elem=NULL; node *min_right = NULL; find_tree(t,znachenie,&udal_elem); if (udal_elem == NULL) return 1; else if (udal_elem == t -> root) { if((udal_elem -> left == NULL ) && (udal_elem -> right == NULL)) { t -> root = NULL; free(udal_elem); (t->size)--; return 0; } if((udal_elem -> left == NULL) && (udal_elem ->right != NULL)) { udal_elem -> right -> parent = NULL; t -> root = udal_elem -> right; free(udal_elem); (t->size)--; return 0; } if((udal_elem -> left != NULL) && (udal_elem ->right == NULL)) { udal_elem -> left -> parent = NULL; t -> root = udal_elem -> left; free(udal_elem); (t->size)--; return 0; } if ((udal_elem -> left != NULL) && (udal_elem -> right !=NULL)) { min_right = udal_elem -> right; if (min_right -> left == NULL) { udal_elem -> value = min_right -> value; if (min_right -> right == NULL) { udal_elem -> right= NULL; } else { udal_elem -> right = min_right->right; min_right->right->parent = udal_elem; } min_right=NULL; free(min_right); (t->size)--; return 0; } else { while (min_right -> left != NULL)//ищем минимальный правого поддерева min_right = min_right -> left; udal_elem -> value = min_right -> value; if (min_right -> right == NULL) min_right -> parent -> left = NULL; else { min_right -> parent -> left = min_right -> right; min_right -> right -> parent = min_right -> parent; } free(min_right); (t->size)--; return 0; } } } else { if((udal_elem -> left == NULL ) && (udal_elem -> right == NULL)) { tmp= udal_elem -> parent; if (udal_elem == tmp -> right) tmp -> right = NULL; else tmp ->left = NULL; free(udal_elem); (t->size)--; return 0; } if((udal_elem -> left == NULL) && (udal_elem ->right != NULL)) { tmp = udal_elem -> parent; if (udal_elem == tmp -> right) tmp -> right = udal_elem -> right; else tmp -> left = udal_elem -> right; udal_elem -> right -> parent = tmp; free(udal_elem); (t->size)--; return 0; } if((udal_elem -> left != NULL) && (udal_elem ->right == NULL)) { tmp = udal_elem -> parent; if (udal_elem == tmp -> right) tmp -> right = udal_elem -> left; else tmp -> left = udal_elem -> left; udal_elem -> left -> parent = tmp; free(udal_elem); (t->size)--; return 0; } if ((udal_elem -> left != NULL) && (udal_elem -> right !=NULL)) { min_right = udal_elem -> right; if (min_right -> left == NULL) { udal_elem -> value = min_right -> value; udal_elem -> right = NULL; free(min_right); (t->size)--; return 0; } else { while (min_right -> left != NULL)//ищем минимальный правого поддерева min_right = min_right -> left; udal_elem -> value = min_right -> value; if (min_right -> right == NULL) min_right -> parent -> left = NULL; else { min_right -> parent -> left = min_right -> right; min_right -> right -> parent = min_right -> parent; } free(min_right); (t->size)--; return 0; } } } } /* удалить минимальный элемент из поддерева, корнем которо го является n. вернуть значение удаленного элемента */ int revomeMin(node* n) { int znach=0; node* min = n; node* tmp = n; while (min -> left != NULL) min = min -> left; if(min -> right == NULL) { tmp= min -> parent; if (min == tmp -> right) tmp -> right = NULL; else tmp ->left = NULL; znach= min -> value; free(min); return znach; } if(min -> right != NULL) { tmp = min -> parent; if (min == tmp -> right) tmp -> right = min -> right; else tmp -> left = min -> right; min -> right -> parent = tmp; znach= min -> value; free(min); return znach; } } /* выполнить левое вращение поддерева, корнем которого явл яется n. вернуть 0 при успещшно выполнение операции и 1 в случае если вращение невозможно */ int rotateLeft(node *n) { node* tmp1=n; node* tmp2=n -> right; if (n->right != NULL) { if (n->right->left==NULL) { tmp1->right=NULL; tmp1->parent=tmp2; tmp2->left=tmp1; } else { tmp1->right=tmp2->left; tmp2->left->parent=tmp1; tmp1->parent=tmp2; tmp2->left=tmp1; } return 0; } else return 1; } int rotateRight(node *n) { node* tmp1=n; node* tmp2=n -> left; if (n->left != NULL) { if (n->left->right==NULL) { tmp1->left=NULL; tmp1->parent=tmp2; tmp2->right=tmp1; } else { tmp1->left=tmp2->right; tmp2->right->parent=tmp1; tmp1->parent=tmp2; tmp2->right=tmp1; } return 0; } else return 1; } void clear(tree *t) { int a=0; while (t->size!=0) { a=remove_(t,t->root->value); } } int max_(int x, int y) { return (((x) > (y)) ? (x) : (y)); } int getDepth(node* n, int depth) { if (n == NULL) return depth; return max_(getDepth(n->left,depth +1),getDepth(n->right,depth +1)); } /*вывести все значения из поддерева корнем которого являе тся n по уровнем, начиная с корня. каждый уровень выводитс я на своей строке. элементы в строке разделяются пробелом. если на указанном месте нет элемента, заменить его значен ием '_'. Если дерево пусто вывести '-' */ void print(node* n) { node* tmp=n; node* tmp3=n; node* tmp2=NULL;// glubina количество уровней дерева int lvl=1,i=0,j=0,glubina=0,z=0,y=0;// lvl дерева считаем от 0, просто нулевой уровень выводим не в цикле if (tmp==NULL) printf("-\n"); else { printf("%d\n",tmp3->value); } glubina=getDepth(tmp3,glubina); while (lvl < glubina)//повышение уровня { z= (1<<lvl)-1; for (i=0;i<(1<<lvl);i++)//проход вдоль уровня { y=z; int *arr; arr = (int*)malloc(lvl * sizeof(int)); for (int k=lvl-1;k>=0;k--) { arr[k]=y%2; y /= 2; } tmp2 = tmp; for (j=0;j<lvl;j++)// проход вниз от корня до элемента этого уровня { if (tmp2 == NULL) { break; } else { if(arr[j]==1) { tmp2 = tmp2->left; } else { tmp2 = tmp2->right; } } } if (tmp2 == NULL) printf("_"); else printf("%d",tmp2->value); if ((i+1)<(1<<lvl)) printf(" "); z--; free(arr); } lvl++; printf("\n"); } tmp=NULL; tmp2=NULL; free(tmp); free(tmp2); } void printTree(tree* t) { print(t->root); } void obhod_v_shirinu(node* n) { node* tmp=n; node* tmp3=n; node* tmp2=NULL;// glubina количество уровней дерева int lvl=1,i=0,j=0,glubina=0,z=0,y=0;// lvl дерева считаем от 0, просто нулевой уровень выводим не в цикле if (tmp==NULL) printf("-\n"); else { printf("%d ",tmp3->value); } glubina=getDepth(tmp3,glubina); while (lvl < glubina)//повышение уровня { z= (1<<lvl)-1; for (i=0;i<(1<<lvl);i++)//проход вдоль уровня { y=z; int *arr; arr = (int*)malloc(lvl * sizeof(int)); for (int k=lvl-1;k>=0;k--) { arr[k]=y%2; y /= 2; } tmp2 = tmp; for (j=0;j<lvl;j++)// проход вниз от корня до элемента этого уровня { if (tmp2 == NULL) { break; } else { if(arr[j]==1) { tmp2 = tmp2->left; } else { tmp2 = tmp2->right; } } } //if (tmp2 == NULL) // printf("_"); if (tmp2 != NULL) { printf("%d",tmp2->value); if ((i+1)<(1<<lvl)) printf(" "); } z--; free(arr); } lvl++; printf(" "); } printf("\n"); tmp=NULL; tmp2=NULL; free(tmp); free(tmp2); } /*void obhod_simm(node* root) { node* tmp=root; node* lastNode=NULL; while(tmp) { if (lastNode == tmp->parent) { if (tmp->left != NULL) { lastNode = tmp; tmp = tmp->left; } else lastNode = NULL; } if (lastNode == tmp->left) { printf("%d",tmp->value); if (tmp->right != NULL) { lastNode = tmp; tmp = tmp -> right; } else lastNode = NULL; } if (lastNode == tmp ->right) { lastNode = tmp; tmp = tmp ->parent; } } } */ void obhod_obratniy(node* root) { if (root) { obhod_obratniy(root->left); obhod_obratniy(root->right); printf("%d ",root->value); } } void obhod_pryamoi(node* root,int razm) { node* tmp=root; if (root->left ==NULL && root->right == NULL) printf("%d",root->value); else printf("%d ",root->value); razm--; while(tmp) { int i=0; if (tmp->left != NULL) { tmp = tmp->left; razm--; if (razm==0) printf("%d",tmp->value); else printf("%d ",tmp->value); i++; } else if (tmp -> right != NULL) { tmp = tmp -> right; razm--; if (razm==0) printf("%d",tmp->value); else printf("%d ",tmp->value); i++; } else if (tmp->left == NULL && tmp->right == NULL) { while (tmp->parent != NULL) { if ((tmp == tmp->parent->left) && (tmp -> parent -> right != NULL)) { tmp = tmp -> parent -> right; razm--; if (razm==0) printf("%d",tmp->value); else printf("%d ",tmp->value); i++; } else tmp = tmp -> parent; if (i!=0) break; } } if (i==0) tmp = NULL; } } int main(void) { int i,a,ost=1; tree* tree_a=NULL; tree_a=(tree *)malloc(sizeof(tree)); init(tree_a); for(i=0;i<7;i++) { scanf("%d",&a); insert(tree_a, a); } obhod_pryamoi(tree_a->root,tree_a->size); printf("\n"); return 0; }
the_stack_data/22012040.c
//@ ltl invariant negative: ( ([] ( (! ( AP((s0_l1 != 0)) && (! AP((s0_l0 != 0))))) || (<> ( (! AP((s0_l0 != 0))) && (! AP((s0_l1 != 0))))))) || (! ([] (<> AP((1.0 <= _diverge_delta)))))); extern float __VERIFIER_nondet_float(void); extern int __VERIFIER_nondet_int(void); char __VERIFIER_nondet_bool(void) { return __VERIFIER_nondet_int() != 0; } float _diverge_delta, _x__diverge_delta; float s2_x, _x_s2_x; float s1_x, _x_s1_x; char s2_evt0, _x_s2_evt0; char s1_evt0, _x_s1_evt0; char s0_l1, _x_s0_l1; char s0_l0, _x_s0_l0; float delta, _x_delta; char s2_evt2, _x_s2_evt2; char s1_evt2, _x_s1_evt2; int bus_j, _x_bus_j; float s0_x, _x_s0_x; float bus_x, _x_bus_x; char s2_evt1, _x_s2_evt1; char s1_evt1, _x_s1_evt1; int bus_cd_id, _x_bus_cd_id; char bus_evt0, _x_bus_evt0; char bus_evt1, _x_bus_evt1; char bus_l0, _x_bus_l0; char bus_evt2, _x_bus_evt2; char bus_l1, _x_bus_l1; char s2_l0, _x_s2_l0; char s1_l0, _x_s1_l0; char s0_evt0, _x_s0_evt0; char s2_l1, _x_s2_l1; char s1_l1, _x_s1_l1; char s0_evt1, _x_s0_evt1; char s0_evt2, _x_s0_evt2; int main() { _diverge_delta = __VERIFIER_nondet_float(); s2_x = __VERIFIER_nondet_float(); s1_x = __VERIFIER_nondet_float(); s2_evt0 = __VERIFIER_nondet_bool(); s1_evt0 = __VERIFIER_nondet_bool(); s0_l1 = __VERIFIER_nondet_bool(); s0_l0 = __VERIFIER_nondet_bool(); delta = __VERIFIER_nondet_float(); s2_evt2 = __VERIFIER_nondet_bool(); s1_evt2 = __VERIFIER_nondet_bool(); bus_j = __VERIFIER_nondet_int(); s0_x = __VERIFIER_nondet_float(); bus_x = __VERIFIER_nondet_float(); s2_evt1 = __VERIFIER_nondet_bool(); s1_evt1 = __VERIFIER_nondet_bool(); bus_cd_id = __VERIFIER_nondet_int(); bus_evt0 = __VERIFIER_nondet_bool(); bus_evt1 = __VERIFIER_nondet_bool(); bus_l0 = __VERIFIER_nondet_bool(); bus_evt2 = __VERIFIER_nondet_bool(); bus_l1 = __VERIFIER_nondet_bool(); s2_l0 = __VERIFIER_nondet_bool(); s1_l0 = __VERIFIER_nondet_bool(); s0_evt0 = __VERIFIER_nondet_bool(); s2_l1 = __VERIFIER_nondet_bool(); s1_l1 = __VERIFIER_nondet_bool(); s0_evt1 = __VERIFIER_nondet_bool(); s0_evt2 = __VERIFIER_nondet_bool(); int __ok = ((((((((( !(s2_l0 != 0)) && ( !(s2_l1 != 0))) && (s2_x == 0.0)) && ((( !(s2_evt2 != 0)) && ((s2_evt0 != 0) && ( !(s2_evt1 != 0)))) || (((( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0)))) || ((s2_evt2 != 0) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0))))) || ((( !(s2_evt2 != 0)) && ((s2_evt1 != 0) && ( !(s2_evt0 != 0)))) || ((s2_evt2 != 0) && ((s2_evt1 != 0) && ( !(s2_evt0 != 0)))))))) && ((( !(s2_l0 != 0)) && ( !(s2_l1 != 0))) || (((s2_l1 != 0) && ( !(s2_l0 != 0))) || ((s2_l0 != 0) && ( !(s2_l1 != 0)))))) && ((s2_x <= 404.0) || ( !((s2_l1 != 0) && ( !(s2_l0 != 0)))))) && ((s2_x <= 26.0) || ( !((s2_l0 != 0) && ( !(s2_l1 != 0)))))) && (((((((( !(s1_l0 != 0)) && ( !(s1_l1 != 0))) && (s1_x == 0.0)) && ((( !(s1_evt2 != 0)) && ((s1_evt0 != 0) && ( !(s1_evt1 != 0)))) || (((( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0)))) || ((s1_evt2 != 0) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0))))) || ((( !(s1_evt2 != 0)) && ((s1_evt1 != 0) && ( !(s1_evt0 != 0)))) || ((s1_evt2 != 0) && ((s1_evt1 != 0) && ( !(s1_evt0 != 0)))))))) && ((( !(s1_l0 != 0)) && ( !(s1_l1 != 0))) || (((s1_l1 != 0) && ( !(s1_l0 != 0))) || ((s1_l0 != 0) && ( !(s1_l1 != 0)))))) && ((s1_x <= 404.0) || ( !((s1_l1 != 0) && ( !(s1_l0 != 0)))))) && ((s1_x <= 26.0) || ( !((s1_l0 != 0) && ( !(s1_l1 != 0)))))) && (((((((( !(s0_l0 != 0)) && ( !(s0_l1 != 0))) && (s0_x == 0.0)) && ((( !(s0_evt2 != 0)) && ((s0_evt0 != 0) && ( !(s0_evt1 != 0)))) || (((( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0)))) || ((s0_evt2 != 0) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0))))) || ((( !(s0_evt2 != 0)) && ((s0_evt1 != 0) && ( !(s0_evt0 != 0)))) || ((s0_evt2 != 0) && ((s0_evt1 != 0) && ( !(s0_evt0 != 0)))))))) && ((( !(s0_l0 != 0)) && ( !(s0_l1 != 0))) || (((s0_l1 != 0) && ( !(s0_l0 != 0))) || ((s0_l0 != 0) && ( !(s0_l1 != 0)))))) && ((s0_x <= 404.0) || ( !((s0_l1 != 0) && ( !(s0_l0 != 0)))))) && ((s0_x <= 26.0) || ( !((s0_l0 != 0) && ( !(s0_l1 != 0)))))) && (((((( !(bus_l0 != 0)) && ( !(bus_l1 != 0))) && (((( !(bus_evt2 != 0)) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0)))) || ((((bus_evt2 != 0) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0)))) || (( !(bus_evt2 != 0)) && ((bus_evt1 != 0) && ( !(bus_evt0 != 0))))) || (((bus_evt2 != 0) && ((bus_evt1 != 0) && ( !(bus_evt0 != 0)))) || (( !(bus_evt2 != 0)) && ((bus_evt0 != 0) && ( !(bus_evt1 != 0))))))) && (((( !(bus_l0 != 0)) && ( !(bus_l1 != 0))) || ((bus_l1 != 0) && ( !(bus_l0 != 0)))) || (((bus_l0 != 0) && ( !(bus_l1 != 0))) || ((bus_l0 != 0) && (bus_l1 != 0)))))) && ((bus_j == 0) && (bus_x == 0.0))) && ((( !(13.0 <= bus_x)) || ( !((bus_l0 != 0) && ( !(bus_l1 != 0))))) && ((delta == 0.0) || ( !((bus_l0 != 0) && (bus_l1 != 0)))))) && (0.0 <= delta))))) && (delta == _diverge_delta)); while (__ok) { _x__diverge_delta = __VERIFIER_nondet_float(); _x_s2_x = __VERIFIER_nondet_float(); _x_s1_x = __VERIFIER_nondet_float(); _x_s2_evt0 = __VERIFIER_nondet_bool(); _x_s1_evt0 = __VERIFIER_nondet_bool(); _x_s0_l1 = __VERIFIER_nondet_bool(); _x_s0_l0 = __VERIFIER_nondet_bool(); _x_delta = __VERIFIER_nondet_float(); _x_s2_evt2 = __VERIFIER_nondet_bool(); _x_s1_evt2 = __VERIFIER_nondet_bool(); _x_bus_j = __VERIFIER_nondet_int(); _x_s0_x = __VERIFIER_nondet_float(); _x_bus_x = __VERIFIER_nondet_float(); _x_s2_evt1 = __VERIFIER_nondet_bool(); _x_s1_evt1 = __VERIFIER_nondet_bool(); _x_bus_cd_id = __VERIFIER_nondet_int(); _x_bus_evt0 = __VERIFIER_nondet_bool(); _x_bus_evt1 = __VERIFIER_nondet_bool(); _x_bus_l0 = __VERIFIER_nondet_bool(); _x_bus_evt2 = __VERIFIER_nondet_bool(); _x_bus_l1 = __VERIFIER_nondet_bool(); _x_s2_l0 = __VERIFIER_nondet_bool(); _x_s1_l0 = __VERIFIER_nondet_bool(); _x_s0_evt0 = __VERIFIER_nondet_bool(); _x_s2_l1 = __VERIFIER_nondet_bool(); _x_s1_l1 = __VERIFIER_nondet_bool(); _x_s0_evt1 = __VERIFIER_nondet_bool(); _x_s0_evt2 = __VERIFIER_nondet_bool(); __ok = ((((((((((((((((((((((((((((((( !(_x_s2_evt2 != 0)) && ((_x_s2_evt0 != 0) && ( !(_x_s2_evt1 != 0)))) || (((( !(_x_s2_evt2 != 0)) && (( !(_x_s2_evt0 != 0)) && ( !(_x_s2_evt1 != 0)))) || ((_x_s2_evt2 != 0) && (( !(_x_s2_evt0 != 0)) && ( !(_x_s2_evt1 != 0))))) || ((( !(_x_s2_evt2 != 0)) && ((_x_s2_evt1 != 0) && ( !(_x_s2_evt0 != 0)))) || ((_x_s2_evt2 != 0) && ((_x_s2_evt1 != 0) && ( !(_x_s2_evt0 != 0))))))) && ((( !(_x_s2_l0 != 0)) && ( !(_x_s2_l1 != 0))) || (((_x_s2_l1 != 0) && ( !(_x_s2_l0 != 0))) || ((_x_s2_l0 != 0) && ( !(_x_s2_l1 != 0)))))) && ((_x_s2_x <= 404.0) || ( !((_x_s2_l1 != 0) && ( !(_x_s2_l0 != 0)))))) && ((_x_s2_x <= 26.0) || ( !((_x_s2_l0 != 0) && ( !(_x_s2_l1 != 0)))))) && ((delta <= 0.0) || ((((s2_l0 != 0) == (_x_s2_l0 != 0)) && ((s2_l1 != 0) == (_x_s2_l1 != 0))) && ((delta + (s2_x + (-1.0 * _x_s2_x))) == 0.0)))) && (((((s2_l0 != 0) == (_x_s2_l0 != 0)) && ((s2_l1 != 0) == (_x_s2_l1 != 0))) && ((delta + (s2_x + (-1.0 * _x_s2_x))) == 0.0)) || ( !(( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0))))))) && ((((_x_s2_l0 != 0) && ( !(_x_s2_l1 != 0))) || ((( !(_x_s2_l0 != 0)) && ( !(_x_s2_l1 != 0))) || ((_x_s2_l1 != 0) && ( !(_x_s2_l0 != 0))))) || ( !((( !(s2_l0 != 0)) && ( !(s2_l1 != 0))) && ((delta == 0.0) && ( !(( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0)))))))))) && (((( !(s2_evt2 != 0)) && ((s2_evt0 != 0) && ( !(s2_evt1 != 0)))) && (_x_s2_x == 0.0)) || ( !((( !(_x_s2_l0 != 0)) && ( !(_x_s2_l1 != 0))) && ((( !(s2_l0 != 0)) && ( !(s2_l1 != 0))) && ((delta == 0.0) && ( !(( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0))))))))))) && ((((s2_evt2 != 0) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0)))) && (_x_s2_x == 0.0)) || ( !(((_x_s2_l1 != 0) && ( !(_x_s2_l0 != 0))) && ((( !(s2_l0 != 0)) && ( !(s2_l1 != 0))) && ((delta == 0.0) && ( !(( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0))))))))))) && (((_x_s2_x == 0.0) && (((s2_evt2 != 0) && ((s2_evt1 != 0) && ( !(s2_evt0 != 0)))) || (( !(s2_evt2 != 0)) && ((s2_evt0 != 0) && ( !(s2_evt1 != 0)))))) || ( !(((_x_s2_l0 != 0) && ( !(_x_s2_l1 != 0))) && ((( !(s2_l0 != 0)) && ( !(s2_l1 != 0))) && ((delta == 0.0) && ( !(( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0))))))))))) && (((( !(_x_s2_l0 != 0)) && ( !(_x_s2_l1 != 0))) || ((_x_s2_l0 != 0) && ( !(_x_s2_l1 != 0)))) || ( !(((s2_l1 != 0) && ( !(s2_l0 != 0))) && ((delta == 0.0) && ( !(( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0)))))))))) && (((404.0 <= s2_x) && ((( !(s2_evt2 != 0)) && ((s2_evt1 != 0) && ( !(s2_evt0 != 0)))) && (_x_s2_x == 0.0))) || ( !((( !(_x_s2_l0 != 0)) && ( !(_x_s2_l1 != 0))) && (((s2_l1 != 0) && ( !(s2_l0 != 0))) && ((delta == 0.0) && ( !(( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0))))))))))) && (((s2_x <= 26.0) && ((( !(s2_evt2 != 0)) && ((s2_evt0 != 0) && ( !(s2_evt1 != 0)))) && (_x_s2_x == 0.0))) || ( !(((_x_s2_l0 != 0) && ( !(_x_s2_l1 != 0))) && (((s2_l1 != 0) && ( !(s2_l0 != 0))) && ((delta == 0.0) && ( !(( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0))))))))))) && ((((_x_s2_l1 != 0) && ( !(_x_s2_l0 != 0))) || ((_x_s2_l0 != 0) && ( !(_x_s2_l1 != 0)))) || ( !(((s2_l0 != 0) && ( !(s2_l1 != 0))) && ((delta == 0.0) && ( !(( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0)))))))))) && (((s2_x <= 26.0) && ((( !(s2_evt2 != 0)) && ((s2_evt0 != 0) && ( !(s2_evt1 != 0)))) && (_x_s2_x == 0.0))) || ( !(((_x_s2_l0 != 0) && ( !(_x_s2_l1 != 0))) && (((s2_l0 != 0) && ( !(s2_l1 != 0))) && ((delta == 0.0) && ( !(( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0))))))))))) && (((s2_x <= 26.0) && (((s2_evt2 != 0) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0)))) && (_x_s2_x == 0.0))) || ( !(((_x_s2_l1 != 0) && ( !(_x_s2_l0 != 0))) && (((s2_l0 != 0) && ( !(s2_l1 != 0))) && ((delta == 0.0) && ( !(( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0))))))))))) && ((((((((((((((((((( !(_x_s1_evt2 != 0)) && ((_x_s1_evt0 != 0) && ( !(_x_s1_evt1 != 0)))) || (((( !(_x_s1_evt2 != 0)) && (( !(_x_s1_evt0 != 0)) && ( !(_x_s1_evt1 != 0)))) || ((_x_s1_evt2 != 0) && (( !(_x_s1_evt0 != 0)) && ( !(_x_s1_evt1 != 0))))) || ((( !(_x_s1_evt2 != 0)) && ((_x_s1_evt1 != 0) && ( !(_x_s1_evt0 != 0)))) || ((_x_s1_evt2 != 0) && ((_x_s1_evt1 != 0) && ( !(_x_s1_evt0 != 0))))))) && ((( !(_x_s1_l0 != 0)) && ( !(_x_s1_l1 != 0))) || (((_x_s1_l1 != 0) && ( !(_x_s1_l0 != 0))) || ((_x_s1_l0 != 0) && ( !(_x_s1_l1 != 0)))))) && ((_x_s1_x <= 404.0) || ( !((_x_s1_l1 != 0) && ( !(_x_s1_l0 != 0)))))) && ((_x_s1_x <= 26.0) || ( !((_x_s1_l0 != 0) && ( !(_x_s1_l1 != 0)))))) && ((delta <= 0.0) || ((((s1_l0 != 0) == (_x_s1_l0 != 0)) && ((s1_l1 != 0) == (_x_s1_l1 != 0))) && ((delta + (s1_x + (-1.0 * _x_s1_x))) == 0.0)))) && (((((s1_l0 != 0) == (_x_s1_l0 != 0)) && ((s1_l1 != 0) == (_x_s1_l1 != 0))) && ((delta + (s1_x + (-1.0 * _x_s1_x))) == 0.0)) || ( !(( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0))))))) && ((((_x_s1_l0 != 0) && ( !(_x_s1_l1 != 0))) || ((( !(_x_s1_l0 != 0)) && ( !(_x_s1_l1 != 0))) || ((_x_s1_l1 != 0) && ( !(_x_s1_l0 != 0))))) || ( !((( !(s1_l0 != 0)) && ( !(s1_l1 != 0))) && ((delta == 0.0) && ( !(( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0)))))))))) && (((( !(s1_evt2 != 0)) && ((s1_evt0 != 0) && ( !(s1_evt1 != 0)))) && (_x_s1_x == 0.0)) || ( !((( !(_x_s1_l0 != 0)) && ( !(_x_s1_l1 != 0))) && ((( !(s1_l0 != 0)) && ( !(s1_l1 != 0))) && ((delta == 0.0) && ( !(( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0))))))))))) && ((((s1_evt2 != 0) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0)))) && (_x_s1_x == 0.0)) || ( !(((_x_s1_l1 != 0) && ( !(_x_s1_l0 != 0))) && ((( !(s1_l0 != 0)) && ( !(s1_l1 != 0))) && ((delta == 0.0) && ( !(( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0))))))))))) && (((_x_s1_x == 0.0) && (((s1_evt2 != 0) && ((s1_evt1 != 0) && ( !(s1_evt0 != 0)))) || (( !(s1_evt2 != 0)) && ((s1_evt0 != 0) && ( !(s1_evt1 != 0)))))) || ( !(((_x_s1_l0 != 0) && ( !(_x_s1_l1 != 0))) && ((( !(s1_l0 != 0)) && ( !(s1_l1 != 0))) && ((delta == 0.0) && ( !(( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0))))))))))) && (((( !(_x_s1_l0 != 0)) && ( !(_x_s1_l1 != 0))) || ((_x_s1_l0 != 0) && ( !(_x_s1_l1 != 0)))) || ( !(((s1_l1 != 0) && ( !(s1_l0 != 0))) && ((delta == 0.0) && ( !(( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0)))))))))) && (((404.0 <= s1_x) && ((( !(s1_evt2 != 0)) && ((s1_evt1 != 0) && ( !(s1_evt0 != 0)))) && (_x_s1_x == 0.0))) || ( !((( !(_x_s1_l0 != 0)) && ( !(_x_s1_l1 != 0))) && (((s1_l1 != 0) && ( !(s1_l0 != 0))) && ((delta == 0.0) && ( !(( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0))))))))))) && (((s1_x <= 26.0) && ((( !(s1_evt2 != 0)) && ((s1_evt0 != 0) && ( !(s1_evt1 != 0)))) && (_x_s1_x == 0.0))) || ( !(((_x_s1_l0 != 0) && ( !(_x_s1_l1 != 0))) && (((s1_l1 != 0) && ( !(s1_l0 != 0))) && ((delta == 0.0) && ( !(( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0))))))))))) && ((((_x_s1_l1 != 0) && ( !(_x_s1_l0 != 0))) || ((_x_s1_l0 != 0) && ( !(_x_s1_l1 != 0)))) || ( !(((s1_l0 != 0) && ( !(s1_l1 != 0))) && ((delta == 0.0) && ( !(( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0)))))))))) && (((s1_x <= 26.0) && ((( !(s1_evt2 != 0)) && ((s1_evt0 != 0) && ( !(s1_evt1 != 0)))) && (_x_s1_x == 0.0))) || ( !(((_x_s1_l0 != 0) && ( !(_x_s1_l1 != 0))) && (((s1_l0 != 0) && ( !(s1_l1 != 0))) && ((delta == 0.0) && ( !(( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0))))))))))) && (((s1_x <= 26.0) && (((s1_evt2 != 0) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0)))) && (_x_s1_x == 0.0))) || ( !(((_x_s1_l1 != 0) && ( !(_x_s1_l0 != 0))) && (((s1_l0 != 0) && ( !(s1_l1 != 0))) && ((delta == 0.0) && ( !(( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0))))))))))) && ((((((((((((((((((( !(_x_s0_evt2 != 0)) && ((_x_s0_evt0 != 0) && ( !(_x_s0_evt1 != 0)))) || (((( !(_x_s0_evt2 != 0)) && (( !(_x_s0_evt0 != 0)) && ( !(_x_s0_evt1 != 0)))) || ((_x_s0_evt2 != 0) && (( !(_x_s0_evt0 != 0)) && ( !(_x_s0_evt1 != 0))))) || ((( !(_x_s0_evt2 != 0)) && ((_x_s0_evt1 != 0) && ( !(_x_s0_evt0 != 0)))) || ((_x_s0_evt2 != 0) && ((_x_s0_evt1 != 0) && ( !(_x_s0_evt0 != 0))))))) && ((( !(_x_s0_l0 != 0)) && ( !(_x_s0_l1 != 0))) || (((_x_s0_l1 != 0) && ( !(_x_s0_l0 != 0))) || ((_x_s0_l0 != 0) && ( !(_x_s0_l1 != 0)))))) && ((_x_s0_x <= 404.0) || ( !((_x_s0_l1 != 0) && ( !(_x_s0_l0 != 0)))))) && ((_x_s0_x <= 26.0) || ( !((_x_s0_l0 != 0) && ( !(_x_s0_l1 != 0)))))) && ((delta <= 0.0) || ((((s0_l0 != 0) == (_x_s0_l0 != 0)) && ((s0_l1 != 0) == (_x_s0_l1 != 0))) && ((delta + (s0_x + (-1.0 * _x_s0_x))) == 0.0)))) && (((((s0_l0 != 0) == (_x_s0_l0 != 0)) && ((s0_l1 != 0) == (_x_s0_l1 != 0))) && ((delta + (s0_x + (-1.0 * _x_s0_x))) == 0.0)) || ( !(( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0))))))) && ((((_x_s0_l0 != 0) && ( !(_x_s0_l1 != 0))) || ((( !(_x_s0_l0 != 0)) && ( !(_x_s0_l1 != 0))) || ((_x_s0_l1 != 0) && ( !(_x_s0_l0 != 0))))) || ( !((( !(s0_l0 != 0)) && ( !(s0_l1 != 0))) && ((delta == 0.0) && ( !(( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0)))))))))) && (((( !(s0_evt2 != 0)) && ((s0_evt0 != 0) && ( !(s0_evt1 != 0)))) && (_x_s0_x == 0.0)) || ( !((( !(_x_s0_l0 != 0)) && ( !(_x_s0_l1 != 0))) && ((( !(s0_l0 != 0)) && ( !(s0_l1 != 0))) && ((delta == 0.0) && ( !(( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0))))))))))) && ((((s0_evt2 != 0) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0)))) && (_x_s0_x == 0.0)) || ( !(((_x_s0_l1 != 0) && ( !(_x_s0_l0 != 0))) && ((( !(s0_l0 != 0)) && ( !(s0_l1 != 0))) && ((delta == 0.0) && ( !(( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0))))))))))) && (((_x_s0_x == 0.0) && (((s0_evt2 != 0) && ((s0_evt1 != 0) && ( !(s0_evt0 != 0)))) || (( !(s0_evt2 != 0)) && ((s0_evt0 != 0) && ( !(s0_evt1 != 0)))))) || ( !(((_x_s0_l0 != 0) && ( !(_x_s0_l1 != 0))) && ((( !(s0_l0 != 0)) && ( !(s0_l1 != 0))) && ((delta == 0.0) && ( !(( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0))))))))))) && (((( !(_x_s0_l0 != 0)) && ( !(_x_s0_l1 != 0))) || ((_x_s0_l0 != 0) && ( !(_x_s0_l1 != 0)))) || ( !(((s0_l1 != 0) && ( !(s0_l0 != 0))) && ((delta == 0.0) && ( !(( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0)))))))))) && (((404.0 <= s0_x) && ((( !(s0_evt2 != 0)) && ((s0_evt1 != 0) && ( !(s0_evt0 != 0)))) && (_x_s0_x == 0.0))) || ( !((( !(_x_s0_l0 != 0)) && ( !(_x_s0_l1 != 0))) && (((s0_l1 != 0) && ( !(s0_l0 != 0))) && ((delta == 0.0) && ( !(( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0))))))))))) && (((s0_x <= 26.0) && ((( !(s0_evt2 != 0)) && ((s0_evt0 != 0) && ( !(s0_evt1 != 0)))) && (_x_s0_x == 0.0))) || ( !(((_x_s0_l0 != 0) && ( !(_x_s0_l1 != 0))) && (((s0_l1 != 0) && ( !(s0_l0 != 0))) && ((delta == 0.0) && ( !(( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0))))))))))) && ((((_x_s0_l1 != 0) && ( !(_x_s0_l0 != 0))) || ((_x_s0_l0 != 0) && ( !(_x_s0_l1 != 0)))) || ( !(((s0_l0 != 0) && ( !(s0_l1 != 0))) && ((delta == 0.0) && ( !(( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0)))))))))) && (((s0_x <= 26.0) && ((( !(s0_evt2 != 0)) && ((s0_evt0 != 0) && ( !(s0_evt1 != 0)))) && (_x_s0_x == 0.0))) || ( !(((_x_s0_l0 != 0) && ( !(_x_s0_l1 != 0))) && (((s0_l0 != 0) && ( !(s0_l1 != 0))) && ((delta == 0.0) && ( !(( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0))))))))))) && (((s0_x <= 26.0) && (((s0_evt2 != 0) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0)))) && (_x_s0_x == 0.0))) || ( !(((_x_s0_l1 != 0) && ( !(_x_s0_l0 != 0))) && (((s0_l0 != 0) && ( !(s0_l1 != 0))) && ((delta == 0.0) && ( !(( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0))))))))))) && (((((((((((((((( !(_x_bus_evt2 != 0)) && (( !(_x_bus_evt0 != 0)) && ( !(_x_bus_evt1 != 0)))) || ((((_x_bus_evt2 != 0) && (( !(_x_bus_evt0 != 0)) && ( !(_x_bus_evt1 != 0)))) || (( !(_x_bus_evt2 != 0)) && ((_x_bus_evt1 != 0) && ( !(_x_bus_evt0 != 0))))) || (((_x_bus_evt2 != 0) && ((_x_bus_evt1 != 0) && ( !(_x_bus_evt0 != 0)))) || (( !(_x_bus_evt2 != 0)) && ((_x_bus_evt0 != 0) && ( !(_x_bus_evt1 != 0))))))) && (((( !(_x_bus_l0 != 0)) && ( !(_x_bus_l1 != 0))) || ((_x_bus_l1 != 0) && ( !(_x_bus_l0 != 0)))) || (((_x_bus_l0 != 0) && ( !(_x_bus_l1 != 0))) || ((_x_bus_l0 != 0) && (_x_bus_l1 != 0))))) && ((( !(13.0 <= _x_bus_x)) || ( !((_x_bus_l0 != 0) && ( !(_x_bus_l1 != 0))))) && ((_x_delta == 0.0) || ( !((_x_bus_l0 != 0) && (_x_bus_l1 != 0)))))) && ((delta <= 0.0) || (((delta + (bus_x + (-1.0 * _x_bus_x))) == 0.0) && ((((bus_l0 != 0) == (_x_bus_l0 != 0)) && ((bus_l1 != 0) == (_x_bus_l1 != 0))) && (bus_j == _x_bus_j))))) && ((((delta + (bus_x + (-1.0 * _x_bus_x))) == 0.0) && ((((bus_l0 != 0) == (_x_bus_l0 != 0)) && ((bus_l1 != 0) == (_x_bus_l1 != 0))) && (bus_j == _x_bus_j))) || ( !(( !(bus_evt2 != 0)) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0))))))) && (((((bus_evt2 != 0) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0)))) && ((_x_bus_l1 != 0) && ( !(_x_bus_l0 != 0)))) && ((bus_j == _x_bus_j) && (_x_bus_x == 0.0))) || ( !((( !(bus_l0 != 0)) && ( !(bus_l1 != 0))) && ((delta == 0.0) && ( !(( !(bus_evt2 != 0)) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0)))))))))) && (((bus_j == _x_bus_j) && (((_x_bus_l0 != 0) && ( !(_x_bus_l1 != 0))) || ((( !(_x_bus_l0 != 0)) && ( !(_x_bus_l1 != 0))) || ((_x_bus_l1 != 0) && ( !(_x_bus_l0 != 0)))))) || ( !(((bus_l1 != 0) && ( !(bus_l0 != 0))) && ((delta == 0.0) && ( !(( !(bus_evt2 != 0)) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0)))))))))) && (((( !(bus_evt2 != 0)) && ((bus_evt1 != 0) && ( !(bus_evt0 != 0)))) && (_x_bus_x == 0.0)) || ( !(((delta == 0.0) && ( !(( !(bus_evt2 != 0)) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0)))))) && ((( !(_x_bus_l0 != 0)) && ( !(_x_bus_l1 != 0))) && ((bus_l1 != 0) && ( !(bus_l0 != 0)))))))) && ((((bus_evt2 != 0) && ((bus_evt1 != 0) && ( !(bus_evt0 != 0)))) && ((13.0 <= bus_x) && (bus_x == _x_bus_x))) || ( !(((delta == 0.0) && ( !(( !(bus_evt2 != 0)) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0)))))) && (((bus_l1 != 0) && ( !(bus_l0 != 0))) && ((_x_bus_l1 != 0) && ( !(_x_bus_l0 != 0)))))))) && ((((bus_evt2 != 0) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0)))) && (( !(13.0 <= bus_x)) && (_x_bus_x == 0.0))) || ( !(((delta == 0.0) && ( !(( !(bus_evt2 != 0)) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0)))))) && (((bus_l1 != 0) && ( !(bus_l0 != 0))) && ((_x_bus_l0 != 0) && ( !(_x_bus_l1 != 0)))))))) && ((((((_x_bus_l0 != 0) && (_x_bus_l1 != 0)) && ( !(13.0 <= bus_x))) && ((( !(bus_evt2 != 0)) && ((bus_evt0 != 0) && ( !(bus_evt1 != 0)))) && (bus_cd_id == bus_j))) && ((_x_bus_x == 0.0) && ((bus_j + (-1 * _x_bus_j)) == -1))) || ( !(((bus_l0 != 0) && ( !(bus_l1 != 0))) && ((delta == 0.0) && ( !(( !(bus_evt2 != 0)) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0)))))))))) && ((((bus_j + (-1 * _x_bus_j)) == -1) && (((( !(bus_evt2 != 0)) && ((bus_evt0 != 0) && ( !(bus_evt1 != 0)))) && (bus_cd_id == bus_j)) && ((_x_bus_x == 0.0) && ( !(2 <= bus_j))))) || ( !(((delta == 0.0) && ( !(( !(bus_evt2 != 0)) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0)))))) && (((bus_l0 != 0) && (bus_l1 != 0)) && ((_x_bus_l0 != 0) && (_x_bus_l1 != 0))))))) && (((((( !(bus_evt2 != 0)) && ((bus_evt0 != 0) && ( !(bus_evt1 != 0)))) && (bus_j == 2)) && ((_x_bus_x == 0.0) && (bus_cd_id == bus_j))) && (_x_bus_j == 0)) || ( !(((delta == 0.0) && ( !(( !(bus_evt2 != 0)) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0)))))) && ((( !(_x_bus_l0 != 0)) && ( !(_x_bus_l1 != 0))) && ((bus_l0 != 0) && (bus_l1 != 0))))))) && (0.0 <= _x_delta))))) && (((( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0)))) || (( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0))))) || ( !(delta == 0.0)))) && (( !(delta == 0.0)) || ((( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0)))) || (( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0))))))) && (( !(delta == 0.0)) || ((( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0)))) || (( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0))))))) && (( !(delta == 0.0)) || (( !(( !(s2_evt2 != 0)) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0))))) || (( !(( !(s1_evt2 != 0)) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0))))) || (( !(( !(bus_evt2 != 0)) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0))))) || ( !(( !(s0_evt2 != 0)) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0)))))))))) && (( !(delta == 0.0)) || (((bus_evt2 != 0) && (( !(bus_evt0 != 0)) && ( !(bus_evt1 != 0)))) == (((s2_evt2 != 0) && (( !(s2_evt0 != 0)) && ( !(s2_evt1 != 0)))) || (((s0_evt2 != 0) && (( !(s0_evt0 != 0)) && ( !(s0_evt1 != 0)))) || ((s1_evt2 != 0) && (( !(s1_evt0 != 0)) && ( !(s1_evt1 != 0))))))))) && (( !(delta == 0.0)) || ((( !(bus_evt2 != 0)) && ((bus_evt1 != 0) && ( !(bus_evt0 != 0)))) == ((( !(s2_evt2 != 0)) && ((s2_evt1 != 0) && ( !(s2_evt0 != 0)))) || ((( !(s0_evt2 != 0)) && ((s0_evt1 != 0) && ( !(s0_evt0 != 0)))) || (( !(s1_evt2 != 0)) && ((s1_evt1 != 0) && ( !(s1_evt0 != 0))))))))) && (( !(delta == 0.0)) || (((bus_evt2 != 0) && ((bus_evt1 != 0) && ( !(bus_evt0 != 0)))) == (((s2_evt2 != 0) && ((s2_evt1 != 0) && ( !(s2_evt0 != 0)))) || (((s0_evt2 != 0) && ((s0_evt1 != 0) && ( !(s0_evt0 != 0)))) || ((s1_evt2 != 0) && ((s1_evt1 != 0) && ( !(s1_evt0 != 0))))))))) && (( !(delta == 0.0)) || ((( !(bus_evt2 != 0)) && ((bus_evt0 != 0) && ( !(bus_evt1 != 0)))) == ((( !(s2_evt2 != 0)) && ((s2_evt0 != 0) && ( !(s2_evt1 != 0)))) || ((( !(s0_evt2 != 0)) && ((s0_evt0 != 0) && ( !(s0_evt1 != 0)))) || (( !(s1_evt2 != 0)) && ((s1_evt0 != 0) && ( !(s1_evt1 != 0))))))))) && (( !(delta == 0.0)) || ((( !(s0_evt2 != 0)) && ((s0_evt0 != 0) && ( !(s0_evt1 != 0)))) == ((( !(bus_evt2 != 0)) && ((bus_evt0 != 0) && ( !(bus_evt1 != 0)))) && (bus_cd_id == 0))))) && (( !(delta == 0.0)) || ((( !(s1_evt2 != 0)) && ((s1_evt0 != 0) && ( !(s1_evt1 != 0)))) == ((( !(bus_evt2 != 0)) && ((bus_evt0 != 0) && ( !(bus_evt1 != 0)))) && (bus_cd_id == 1))))) && (( !(delta == 0.0)) || ((( !(s2_evt2 != 0)) && ((s2_evt0 != 0) && ( !(s2_evt1 != 0)))) == ((( !(bus_evt2 != 0)) && ((bus_evt0 != 0) && ( !(bus_evt1 != 0)))) && (bus_cd_id == 2))))) && (((delta == _x__diverge_delta) || ( !(1.0 <= _diverge_delta))) && ((1.0 <= _diverge_delta) || ((delta + (_diverge_delta + (-1.0 * _x__diverge_delta))) == 0.0)))); _diverge_delta = _x__diverge_delta; s2_x = _x_s2_x; s1_x = _x_s1_x; s2_evt0 = _x_s2_evt0; s1_evt0 = _x_s1_evt0; s0_l1 = _x_s0_l1; s0_l0 = _x_s0_l0; delta = _x_delta; s2_evt2 = _x_s2_evt2; s1_evt2 = _x_s1_evt2; bus_j = _x_bus_j; s0_x = _x_s0_x; bus_x = _x_bus_x; s2_evt1 = _x_s2_evt1; s1_evt1 = _x_s1_evt1; bus_cd_id = _x_bus_cd_id; bus_evt0 = _x_bus_evt0; bus_evt1 = _x_bus_evt1; bus_l0 = _x_bus_l0; bus_evt2 = _x_bus_evt2; bus_l1 = _x_bus_l1; s2_l0 = _x_s2_l0; s1_l0 = _x_s1_l0; s0_evt0 = _x_s0_evt0; s2_l1 = _x_s2_l1; s1_l1 = _x_s1_l1; s0_evt1 = _x_s0_evt1; s0_evt2 = _x_s0_evt2; } }
the_stack_data/140539.c
/* * Copyright (c) 2013-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ typedef struct Point { int x; int y; } Point; int return_5() { return 5; } void init_Point() { struct Point p = {1, return_5() + 3}; } int point_coords_set_correctly(Point* p) { *p = (Point){4, 5}; return 1 / (p->x - 4); } struct Employee { int ssn; float salary; struct date { int date; int month; int year; } doj; } emp1; int field_set_correctly() { struct Employee e = {12, 3000.50, 12, 12, 2010}; return 1 / (e.ssn - 12); } struct dotdot { int a; int b; }; struct dot { struct dotdot x; int y; }; struct rect { struct dot origin; int z; int size; }; typedef struct rect rect; int implicit_expr_set_correctly() { rect imageDrawRect; imageDrawRect = (rect){.size = 5}; return 1 / imageDrawRect.origin.x.a; }
the_stack_data/48088.c
#include "malloc.h" #include "stdio.h" void vectorInitialize(float *Ah, int elemNum) { float summ = 0.0; int i; for (i = 0; i < elemNum; i++) { summ += 1.0; //*(Ah+sizeof(float)*i) = summ; *(Ah+i) = summ; } } void vectorPrint(float *Ah, int elemNum) { int i; for (i = 0; i < elemNum; i++) { //printf("%f\t", *(Ah+sizeof(float)*i)); printf("%f\t", *(Ah+i)); } printf("\n"); } int main() { // 变量初始化 float *Ad, *Bd; // GPU设备端变量 float *Ah, *Bh; // CPU主机端变量 // 设定原始矩阵A的维度 int elemNum = 5; // dimNum = 2 int size = sizeof(float) * elemNum; // CPU主机端申请空间 Ah = (float*)malloc(size); //Bh = (float*)malloc(size); // GPU设备端申请空间 //cudaMalloc((void**)&Ad, size); //cudaMalloc((void**)&Bd, size); // 初始化原始向量A vectorInitialize(Ah, elemNum); // 打印原始矩阵A vectorPrint(Ah, elemNum); return 0; }
the_stack_data/668574.c
#include<stdio.h> #include <math.h> double df(double x); double f(double x); int main(void){ int i; double x,eps; x=5.0; eps = 1.0e-4; for(i=0;i<=1000;i++){ double x1 = x - f(x)/df(x); if(fabs(x-x1)<eps){ break; } x=x1; printf("x1=%lf,x-x1=%.8f, iteration=%d\n",x,x-x1,i+1); } x = -1.0; for(i=0;i<=1000;i++){ double x1 = x - f(x)/df(x); //printf("%lf\n", x1); if(fabs(x1-x)<eps){ break; } x=x1; printf("x2=%lf,x-x1=%.8f, iteration=%d\n",x,x-x1,i+1); } return 0; } double df(double x){ double c,eff=104.8; c=4*eff*x*exp(-eff*pow(x,2))-eff*exp(eff*x); return c; } double f(double x){ double d,eff=104.8; d=2*exp(-eff*pow(x,2))-exp(eff*x); return d; }
the_stack_data/21942.c
# include <stdio.h> int main(void) { int x, sum; sum = 0; x = 1; while (x < 256) { printf("%d ",x); sum = sum + x; x = x + 1; } printf("\nSum = %d\n", sum); }
the_stack_data/148577824.c
/* ******************************************************************************* * Copyright (c) 2020-2021, STMicroelectronics * All rights reserved. * * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ******************************************************************************* */ #if defined(ARDUINO_GENERIC_F410T8YX) || defined(ARDUINO_GENERIC_F410TBYX) #include "pins_arduino.h" /** * @brief System Clock Configuration * @param None * @retval None */ WEAK void SystemClock_Config(void) { /* SystemClock_Config can be generated by STM32CubeMX */ #warning "SystemClock_Config() is empty. Default clock at reset is used." } #endif /* ARDUINO_GENERIC_* */
the_stack_data/237644244.c
/** * @file lv_templ.c * */ /********************* * INCLUDES *********************/ /********************* * DEFINES *********************/ /********************** * TYPEDEFS **********************/ /* This typedef exists purely to keep -Wpedantic happy when the file is empty. */ /* It can be removed. */ typedef int _keep_pedantic_happy; /********************** * STATIC PROTOTYPES **********************/ /********************** * STATIC VARIABLES **********************/ /********************** * MACROS **********************/ /********************** * GLOBAL FUNCTIONS **********************/ /********************** * STATIC FUNCTIONS **********************/
the_stack_data/1251001.c
// Check that the -fprofile-instrument-path= form works. // RUN: %clang_cc1 -main-file-name c-generate.c %s -o - -emit-llvm -fprofile-instrument=clang -fprofile-instrument-path=c-generate-test.profraw | FileCheck %s --check-prefix=PROF-INSTR-PATH // RUN: %clang_cc1 %s -o - -emit-llvm -fprofile-instrument=none | FileCheck %s --check-prefix=PROF-INSTR-NONE // RUN: not %clang_cc1 %s -o - -emit-llvm -fprofile-instrument=garbage 2>&1 | FileCheck %s --check-prefix=PROF-INSTR-GARBAGE // // PROF-INSTR-PATH: constant [24 x i8] c"c-generate-test.profraw\00" // // PROF-INSTR-NONE-NOT: __llvm_prf // // PROF-INSTR-GARBAGE: invalid value 'garbage' in '-fprofile-instrument=garbage' int main(void) { return 0; }
the_stack_data/761501.c
// RUN: %libomptarget-compile-generic -DSHARED -fPIC -shared -o %t.so && %clang %flags %s -o %t -ldl && %libomptarget-run-generic %t.so 2>&1 | %fcheck-generic #ifdef SHARED #include <stdio.h> int foo() { #pragma omp target ; printf("%s\n", "DONE."); return 0; } #else #include <dlfcn.h> #include <stdio.h> int main(int argc, char **argv) { void *Handle = dlopen(argv[1], RTLD_NOW); int (*Foo)(void); if (Handle == NULL) { printf("dlopen() failed: %s\n", dlerror()); return 1; } Foo = (int (*)(void)) dlsym(Handle, "foo"); if (Handle == NULL) { printf("dlsym() failed: %s\n", dlerror()); return 1; } // CHECK: DONE. // CHECK-NOT: {{abort|fault}} return Foo(); } #endif
the_stack_data/175144243.c
#include <stdio.h> #include <string.h> unsigned int ft_strlcat(char *dest, char *src, unsigned int size); void test(char *dest, char *src, unsigned int size, int t, unsigned int r1, char *r) { unsigned int r2; printf("Test %d\n", t); r2 = ft_strlcat(dest, src, size); printf("Expected: %d\n", r1); printf("Expected s: %s\n", r); printf("Result: %d\n", r2); if (r1 == r2 && strcmp(dest, r) == 0) printf("SUCCESS\n"); else printf("INVALID RESULT\n"); printf("%s\n", dest); printf("---------------------\n"); } int main(void) { char dest[100]; char sdest[1]; test(dest, "AAAAAA", 4, 0, 6, "AAA"); test(dest, "B", 8, 1, 4, "AAAB"); test(dest, "CCCCCCCCC", 6, 2, 13, "AAABC"); test(dest, "AB", 1, 3, 3, "AAABC"); test(dest, "", 10, 4, 5, "AAABC"); test(dest, "", 0, 5, 0, "AAABC"); test(dest, "", 1, 6, 1, "AAABC"); test(dest, "AFBR", 10, 7, 9, "AAABCAFBR"); test(dest, "AFBR", 0, 8, 4, "AAABCAFBR"); test(sdest, "AFBR", 12, 9, 4, "AFBR"); return (0); }
the_stack_data/15763931.c
#include<stdio.h> #include<math.h> #define K 15 void prime(int h); void binary(int j); int main() { printf("First prime binary numbers:\n"); prime(K); } void binary(int j){ int i = 0; int base[10] = {0}; while(j > 0){ base[i] = j % 2; j /= 2; ++i; } for(int x = 9; x >= 0; --x){ printf("%01d",base[x]); } printf("\n"); } void prime(int k){ int count, i, flag, sr; int h = 1; count = 1; while(count <= k){ sr = sqrt(h); flag = 0; for(i = 2; i <= sr; i++){ if(h % i ==0){ flag = 1; break; } } if(flag == 0){ binary(h); count++; } h++; } } /* Task carried out with the help of ANGEL RAUL CHAVEZ CARRILLO. */
the_stack_data/198580056.c
/* Exercise 1 - Calculations Write a C program to input marks of two subjects. Calculate and print the average of the two marks. */ #include <stdio.h> int main() { //Main funtion float s1, s2, avg; //variables printf("Enter marks for subject 1 :"); //Enter mark scanf("%f", &s1); printf("Enter marks for subject 2 :");//Enter mark scanf("%f", &s2); avg = (s1+s2) / 2; //Calculate average printf("Average is %.2f", avg); //Display average return 0; //End Of the program }
the_stack_data/465771.c
/*Name: Sangeeta Singh Roll no: 22339 Batch: F7 */ #include <stdio.h> int main() { int n, reverse = 0, temp; printf("Enter a number: "); scanf("%d", &n); temp = n; while (n) { reverse = (reverse * 10) + (n % 10); n /= 10; } if (temp == reverse) printf("palindrome number "); else printf("not palindrome"); return 0; }
the_stack_data/1155271.c
#include <string.h> size_t strlen(const char *s) { size_t len = 0; while (s[len] != '\0') len += 1; return len; }
the_stack_data/22799.c
/* 1 */ typedef struct { /* 2 */ char* data; /* 3 */ int key; /* 4 */ } item; /* 5 */ /* 6 */ item array[] = { /* 7 */ {"bill", 3}, /* 8 */ {"neil", 4}, /* 9 */ {"john", 2}, /* 10 */ {"rick", 5}, /* 11 */ {"alex", 1}, /* 12 */ }; /* 13 */ /* 14 */ sort(a, n) /* 15 */ item* a; /* 16 */ { /* 17 */ int i = 0, j = 0; /* 18 */ int s = 1; /* 19 */ /* 20 */ for (; i < n && s != 0; i++) { /* 21 */ s = 0; /* 22 */ for (j = 0; j < n; j++) { /* 23 */ if (a[j].key > a[j + 1].key) { /* 24 */ item t = a[j]; /* 25 */ a[j] = a[j + 1]; /* 26 */ a[j + 1] = t; /* 27 */ s++; /* 28 */ } /* 29 */ } /* 30 */ n--; /* 31 */ } /* 32 */ } /* 33 */ /* 34 */ main() /* 35 */ { /* 36 */ int i; /* 37 */ sort(array, 5); /* 38 */ for (i = 0; i < 5; i++) /* 39 */ printf("array[%d] = {%s, %d}\n", /* 40 */ i, array[i].data, array[i].key); /* 41 */ }
the_stack_data/151706456.c
typedef char int8_t; typedef unsigned char uint8_t; typedef short int16_t; typedef unsigned short uint16_t; typedef int int32_t; typedef unsigned int uint32_t; typedef long long int64_t; typedef unsigned long long uint64_t; uint8_t * const cga = (uint8_t * const) 0xb8000; uint32_t cursor = 6*2*80; int cgaPrint(const char *msg) { uint16_t i = 0; for (;;) { uint8_t c = msg[i++]; if (c == '\n') { uint32_t line = cursor / (80*2); cursor = (line + 1) * (80*2); continue; } if (c == 0) break; cga[cursor++] = c; cga[cursor++] = 0x1f; } return i; } void _start() { cgaPrint(u8"Hello from 64-bit C\n 1- compile to elf64-x86-64 with script loader\n 2- extract .text, .data and .bss\n 3- update boot loader to initialize sections\n 4- jump to entrypoint"); }
the_stack_data/181393095.c
/* Copyright (c) 2015 EF66_129 Released under the MIT license http://opensource.org/licenses/mit-license.php */ #include <stdio.h> #include <stdlib.h> #include <time.h> #define D_NUM 10000 #define D_MAX 20000 #define HASH_NUM (D_NUM * 2) #define OUTPUT_FILENAME "hash.txt" int hash_func(int value) { return value % HASH_NUM; } int main(void) { int D[D_NUM]; int *Hash[HASH_NUM] = {0}; FILE *fp; srand((unsigned)time(NULL)); for (int i = 0; i < D_NUM; i++) { D[i] = rand() % D_MAX; } for (int i = 0; i < D_NUM; i++) { int k; for (k = hash_func(D[i]); Hash[k]; k++) { k = k % HASH_NUM; } Hash[k] = &D[i]; } #ifdef _MSC_VER if (fopen_s(&fp, OUTPUT_FILENAME, "w") == 0) { #else if ((fp = fopen(OUTPUT_FILENAME, "w"))) { #endif for (int i = 0; i < HASH_NUM; i++) { if (Hash[i]) { fprintf(fp, "%d\n", *Hash[i]); } else { fprintf(fp, "NULL\n"); } } printf("結果を" OUTPUT_FILENAME "に書き込みました。\n"); } else { printf("ファイルに結果を書き込めませんでした。\n"); return -1; } return 0; }
the_stack_data/37637748.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdint.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <mqueue.h> struct edge_os_mq_priv { char *queue_id; int the_owner; mqd_t q; }; void *edge_os_mq_create(const char *name, size_t queue_length, size_t msg_size) { struct mq_attr attr; struct edge_os_mq_priv *priv; priv = calloc(1, sizeof(struct edge_os_mq_priv)); if (!priv) { return NULL; } if ((queue_length > 0) && (msg_size > 0)) { memset(&attr, 0, sizeof(attr)); attr.mq_flags = 0; attr.mq_maxmsg = queue_length; attr.mq_msgsize = msg_size; priv->q = mq_open(name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, &attr); } else { priv->q = mq_open(name, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, NULL); } if (priv->q == (mqd_t)-1) { goto bad; } priv->the_owner = 1; priv->queue_id = strdup(name); return priv; bad: free(priv); return NULL; } struct edge_os_mqattr_r { // the nonblock is removed size_t mq_maxmsgs; size_t mq_msgsize; size_t mq_curmsgs; }; int edge_os_get_mq_wait_fd(void *priv) { struct edge_os_mq_priv *q = priv; return (int)(q->q); } void *edge_os_mq_open(const char *name) { struct edge_os_mq_priv *priv; priv = calloc(1, sizeof(struct edge_os_mq_priv)); if (!priv) { return NULL; } priv->q = mq_open(name, O_RDWR); if (priv->q == (mqd_t)-1) { goto bad; } priv->the_owner = 0; return priv; bad: free(priv); return NULL; } int edge_os_mq_getattr(void *priv, struct edge_os_mqattr_r *attr) { int ret; struct mq_attr qattr; struct edge_os_mq_priv *q = priv; ret = mq_getattr(q->q, &qattr); if (ret < 0) { return -1; } attr->mq_maxmsgs = qattr.mq_maxmsg; attr->mq_msgsize = qattr.mq_msgsize; attr->mq_curmsgs = qattr.mq_curmsgs; return 0; } int edge_os_mq_send(void *priv, const char *data, size_t length, uint32_t prio) { struct edge_os_mq_priv *q = priv; int ret; ret = mq_send(q->q, data, length, prio); if (ret < 0) { return -1; } return 0; } int edge_os_mq_receive(void *priv, char *data, size_t length, uint32_t *prio) { struct edge_os_mq_priv *q = priv; int ret; ret = mq_receive(q->q, data, length, prio); if (ret < 0) { return -1; } return 0; } void edge_os_mq_delete(void *priv) { struct edge_os_mq_priv *q = priv; mq_close(q->q); mq_unlink(q->queue_id); free(q->queue_id); free(q); }
the_stack_data/262387.c
//#include <stdio.h> //#include <stdlib.h> // For exit() //#include <string.h> // //#define BUFF_SIZE 1024 //#define NAME_TYPE_SIZE 10 //#define VALUE_SIZE 20 // //#define NOT_ENOUGH_MEMORY 1 //#define CANT_OPEN_FILE 2 //#define FILE_ENDED 3 //#define TOO_BIG_STR 4 //#define CANT_FORMAT_VALUE 5 //#define NOT_FOUND_LINE 6 // //#define SEARCH_NAME "A" // //#pragma warning(disable : 4996) // for vs // //struct variable { // char type[NAME_TYPE_SIZE]; // char name[NAME_TYPE_SIZE]; // int value; //}; // //int find_var_in_file(char* file_path, char* find_name, struct variable* dest); // //int main() //{ // struct variable* object2 = malloc(sizeof(struct variable)); // // if (NULL == object2) // { // printf("not enough memory"); // return NOT_ENOUGH_MEMORY; // } // // int error = find_var_in_file("input.txt", SEARCH_NAME, object2); // // if (CANT_OPEN_FILE == error) // { // return printf("can't open file"); // } // // if (error == 0) // { // // Printing data to check validity // printf("read: type: %s name: %s value: %d", object2->type, object2->name, object2->value); // int a = object2->value; // // do stuff with a // } // else // { // if (error == NOT_FOUND_LINE) // { // printf("not find the var \"" SEARCH_NAME "\" in the file"); // } // else // { // printf("error reading the file. error code: %d", error); // } // } // // free(object2); // // return 0; //} // //int read_line(char* buffer, int buffer_size, char* dest, int dest_size, FILE* stream) //{ // if (!fgets(buffer, buffer_size, stream)) // { // return NOT_FOUND_LINE; // } // // int read_len = strlen(buffer); // // if ('\n' == buffer[read_len - 1]) // { // if (read_len == 1) // { // return NOT_FOUND_LINE; // } // buffer[read_len - 1] = '\0'; // remove "\n" in the end // } // // if (dest_size <= strlen(buffer)) // last chat is null // { // return TOO_BIG_STR; // } // // strcpy(dest, buffer); // // // clear the read // memset(buffer, '\0', read_len); // // return 0; //} // //int find_var_in_file(char* file_path, char* find_name, struct variable* dest) //{ // char file_buffer[BUFF_SIZE] = { 0 }; // Buffer to store data // FILE* stream = fopen(file_path, "r"); // if (NULL == stream) // { // return CANT_OPEN_FILE; // } // // int error = 0; // while (1) // { // // read type // int read_type_result = read_line(file_buffer, BUFF_SIZE, dest->type, NAME_TYPE_SIZE, stream); // if (read_type_result != 0) // { // error = read_type_result; // break; // } // // int read_name_result = read_line(file_buffer, BUFF_SIZE, dest->name, NAME_TYPE_SIZE, stream); // // if (read_name_result != 0) // { // error = read_name_result; // break; // } // // char value_buffer[VALUE_SIZE] = { 0 }; // int read_value_result = read_line(file_buffer, BUFF_SIZE, value_buffer, VALUE_SIZE, stream); // if (read_value_result != 0) // { // error = read_value_result; // break; // } // // if (0 == strcmp(find_name, dest->name)) // { // if (1 != sscanf(value_buffer, "%d", &dest->value)) // { // error = CANT_FORMAT_VALUE; // } // break; // } // } // // fclose(stream); // // return error; //}
the_stack_data/23411.c
/* Usage: float huber(float x); Returns Huber weight function for scaled residual x = r/d where d is the scale factor (i.e. this routine assumes data are prescaled) Author: Gary Pavlis Written: June 1992 Reference: Chave and Thompson (1989) JGR, 94, p. 14217. */ #define HUBER_PARAMETER_A 1.5 /* Parameter "a" in Huber weight formula */ #include <math.h> float huber(float x) { if(fabs((double)x)<=HUBER_PARAMETER_A) return(1.0); else return((float)(HUBER_PARAMETER_A/fabs((double)x))); } /* $Id$ */
the_stack_data/36076369.c
static long aa = 10; short bb = 20; void func( ) { static long cc = 30; short dd = 40; }
the_stack_data/28261529.c
/** * @file do_ctors.c * @brief C++ constructor handling * @ingroup system */ #include <stdint.h> /** * @addtogroup system * @{ */ /** @brief Function pointer */ typedef void (*func_ptr)(void); /** @brief Pointer to the beginning of the constructor list */ extern func_ptr __CTOR_LIST__ __attribute__((section (".data"))); /** @brief Pointer to the end of the constructor list */ extern func_ptr __CTOR_END__ __attribute__((section (".data"))); /** * @brief Execute global constructors * "Constructors are called in reverse order of the list" * @see https://gcc.gnu.org/onlinedocs/gccint/Initialization.html */ void __do_global_ctors() { func_ptr * ctor_addr = &__CTOR_END__ - 1; func_ptr * ctor_sentinel = &__CTOR_LIST__; while (ctor_addr > ctor_sentinel) { if (*ctor_addr) (*ctor_addr)(); ctor_addr--; } } /** @} */
the_stack_data/26699641.c
/* * Implementation of C99 function "double hypot()" from: * * http://en.wikipedia.org/wiki/Hypot * */ #include <math.h> double hypot(double x, double y) { double t; x = abs(x); y = abs(y); t = min(x,y); x = max(x,y); t = t/x; return x*sqrt(1+t*t); }
the_stack_data/573648.c
/* 2d.c */ #include<stdio.h> /* void add(int x[2][3], const int a[2][3], const int b[2][3]){ for(int i = 0; i < 2; i++){ for(int j = 0; j < 3; j++){ x[i][j] = a[i][j] + b[i][j]; } } } int main(void){ int X[2][3]; int A[2][3] = { {1, 2, 3}, {4, 5, 6}, }; int B[2][3] = { {7, 8, 9}, {-1, -2, -3}, }; add(X, A, B); for(int I = 0; I < 2; I++){ for(int J = 0; J < 3; J++){ printf("%d\t", X[I][J]); } printf("\n"); } return 0; } */
the_stack_data/73859.c
/**************************************************************************/ /*************************************************************************** aahzd.c - a 'Demo Daemon' by Andrei Borovsky <[email protected]> Based on the 'Hello World' public domain demon written by David Gillies <[email protected]> Sep 2003 and inspired by Robert L. Asprin greate funny books This code is placed in the public domain. Unrestricted use or modification of this code is permitted without attribution to the author. ***************************************************************************/ /* Note by A.B.: all the things referring to daemon name are renamed to aahz in the name of the Asprin's daemon hero. /**************************************************************************/ #ifdef __GNUC__ #define _GNU_SOURCE /* for strsignal() */ #endif #include <stdio.h> #include <string.h> #include <stdlib.h> #include <stddef.h> #include <unistd.h> #include <netdb.h> #include <fcntl.h> #include <time.h> #include <signal.h> #include <syslog.h> #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> #include <netinet/in.h> /*************************************************************************/ /* global variables and constants */ volatile sig_atomic_t gGracefulShutdown=0; volatile sig_atomic_t gCaughtHupSignal=0; int gLockFileDesc=-1; int gMasterSocket=-1; /* the 'well-known' port on which our server will be listening */ const int gaahzdPort=30333; /* the path to our lock file */ /* Note by A.B: there was a slight bug here in the original version, sunce ths variable was not actually used */ const char *const gLockFilePath = "/var/run/aahzd.pid"; /*************************************************************************/ /* prototypes */ int BecomeDaemonProcess(const char *const lockFileName, const char *const logPrefix, const int logLevel, int *const lockFileDesc, int *const thisPID); int ConfigureSignalHandlers(void); int BindPassiveSocket(const int portNum, int *const boundSocket); int AcceptConnections(const int master); int HandleConnection(const int slave); int WriteToSocket(const int sock,const char *const buffer, const size_t buflen); int ReadLine(const int sock,char *const buffer,const size_t buflen, size_t *const bytesRead); void FatalSigHandler(int sig); void TermHandler(int sig); void HupHandler(int sig); void Usr1Handler(int sig); void TidyUp(void); /*************************************************************************/ int main(int argc,char *argv[]) { int result; pid_t daemonPID; /**************************************************************/ /* Note by A.B.: Here is some code added to manage daemon */ /* via it's own executable. */ /**************************************************************/ if (argc > 1) { int fd, len; pid_t pid; char pid_buf[16]; if ((fd = open(gLockFilePath, O_RDONLY)) < 0) { perror("Lock file not found. May be the server is not running?"); exit(fd); } len = read(fd, pid_buf, 16); pid_buf[len] = 0; pid = atoi(pid_buf); if(!strcmp(argv[1], "stop")) { kill(pid, SIGUSR1); exit(EXIT_SUCCESS); } if(!strcmp(argv[1], "restart")) { kill(pid, SIGHUP); exit(EXIT_SUCCESS); } printf ("usage %s [stop|restart]\n", argv[0]); exit (EXIT_FAILURE); } /*************************************************************/ /* perhaps at this stage you would read a configuration file */ /*************************************************************/ /* the first task is to put ourself into the background (i.e become a daemon. */ if((result=BecomeDaemonProcess(gLockFilePath,"aahzd", LOG_DEBUG,&gLockFileDesc,&daemonPID))<0) { perror("Failed to become daemon process"); exit(result); } /* set up signal processing */ if((result=ConfigureSignalHandlers())<0) { syslog(LOG_LOCAL0|LOG_INFO,"ConfigureSignalHandlers failed, errno=%d",errno); unlink(gLockFilePath); exit(result); } /* now we must create a socket and bind it to a port */ if((result=BindPassiveSocket(gaahzdPort,&gMasterSocket))<0) { syslog(LOG_LOCAL0|LOG_INFO,"BindPassiveSocket failed, errno=%d",errno); unlink(gLockFilePath); exit(result); } /* now enter an infinite loop handling connections */ do { if(AcceptConnections(gMasterSocket)<0) { syslog(LOG_LOCAL0|LOG_INFO,"AcceptConnections failed, errno=%d",errno); unlink(gLockFilePath); exit(result); } /* the next conditional will be true if we caught signal SIGUSR1 */ if((gGracefulShutdown==1)&&(gCaughtHupSignal==0)) break; /* if we caught SIGHUP, then start handling connections again */ gGracefulShutdown=gCaughtHupSignal=0; }while(1); TidyUp(); /* close the socket and kill the lock file */ return 0; } /**************************************************************************/ /*************************************************************************** BecomeDaemonProcess Fork the process into the background, make a lock file, and open the system log. Inputs: lockFileName I the path to the lock file logPrefix I the string that will appear at the start of all log messages logLevel I the logging level for this process lockFileDesc O the file descriptor of the lock file thisPID O the PID of this process after fork() has placed it in the background Returns: status code indicating success - 0 = success ***************************************************************************/ /**************************************************************************/ int BecomeDaemonProcess(const char *const lockFileName, const char *const logPrefix, const int logLevel, int *const lockFileDesc, pid_t *const thisPID) { int curPID,stdioFD,lockResult,killResult,lockFD,i, numFiles; char pidBuf[17],*lfs,pidStr[7]; FILE *lfp; unsigned long lockPID; struct flock exclusiveLock; /* set our current working directory to root to avoid tying up any directories. In a real server, we might later change to another directory and call chroot() for security purposes (especially if we are writing something that serves files */ chdir("/"); /* try to grab the lock file */ lockFD=open(lockFileName,O_RDWR|O_CREAT|O_EXCL,0644); if(lockFD==-1) { /* Perhaps the lock file already exists. Try to open it */ lfp=fopen(lockFileName,"r"); if(lfp==0) /* Game over. Bail out */ { perror("Can't get lockfile"); return -1; } /* We opened the lockfile. Our lockfiles store the daemon PID in them. Find out what that PID is */ lfs=fgets(pidBuf,16,lfp); if(lfs!=0) { if(pidBuf[strlen(pidBuf)-1]=='\n') /* strip linefeed */ pidBuf[strlen(pidBuf)-1]=0; lockPID=strtoul(pidBuf,(char**)0,10); /* see if that process is running. Signal 0 in kill(2) doesn't send a signal, but still performs error checking */ killResult=kill(lockPID,0); if(killResult==0) { printf("\n\nERROR\n\nA lock file %s has been detected. It appears it is owned\nby the (active) process with PID %ld.\n\n",lockFileName,lockPID); } else { if(errno==ESRCH) /* non-existent process */ { printf("\n\nERROR\n\nA lock file %s has been detected. It appears it is owned\nby the process with PID %ld, which is now defunct. Delete the lock file\nand try again.\n\n",lockFileName,lockPID); } else { perror("Could not acquire exclusive lock on lock file"); } } } else perror("Could not read lock file"); fclose(lfp); return -1; } /* we have got this far so we have acquired access to the lock file. Set a lock on it */ exclusiveLock.l_type=F_WRLCK; /* exclusive write lock */ exclusiveLock.l_whence=SEEK_SET; /* use start and len */ exclusiveLock.l_len=exclusiveLock.l_start=0; /* whole file */ exclusiveLock.l_pid=0; /* don't care about this */ lockResult=fcntl(lockFD,F_SETLK,&exclusiveLock); if(lockResult<0) /* can't get a lock */ { close(lockFD); perror("Can't get lockfile"); return -1; } /* now we move ourselves into the background and become a daemon. Remember that fork() inherits open file descriptors among others so our lock file is still valid */ curPID=fork(); switch(curPID) { case 0: /* we are the child process */ break; case -1: /* error - bail out (fork failing is very bad) */ fprintf(stderr,"Error: initial fork failed: %s\n", strerror(errno)); return -1; break; default: /* we are the parent, so exit */ exit(0); break; } /* make the process a session and process group leader. This simplifies job control if we are spawning child servers, and starts work on detaching us from a controlling TTY */ if(setsid()<0) return -1; /* Note by A.B.: we skipped another fork here */ /* log PID to lock file */ /* truncate just in case file already existed */ if(ftruncate(lockFD,0)<0) return -1; /* store our PID. Then we can kill the daemon with kill `cat <lockfile>` where <lockfile> is the path to our lockfile */ sprintf(pidStr,"%d\n",(int)getpid()); write(lockFD,pidStr,strlen(pidStr)); *lockFileDesc=lockFD; /* return lock file descriptor to caller */ /* close open file descriptors */ /* Note by A.B.: sysconf(_SC_OPEN_MAX) does work under Linux. No need in ad hoc guessing */ numFiles = sysconf(_SC_OPEN_MAX); /* how many file descriptors? */ for(i=numFiles-1;i>=0;--i) /* close all open files except lock */ { if(i!=lockFD) /* don't close the lock file! */ close(i); } /* stdin/out/err to /dev/null */ umask(0); /* set this to whatever is appropriate for you */ stdioFD=open("/dev/null",O_RDWR); /* fd 0 = stdin */ dup(stdioFD); /* fd 1 = stdout */ dup(stdioFD); /* fd 2 = stderr */ /* open the system log - here we are using the LOCAL0 facility */ openlog(logPrefix,LOG_PID|LOG_CONS|LOG_NDELAY|LOG_NOWAIT,LOG_LOCAL0); (void)setlogmask(LOG_UPTO(logLevel)); /* set logging level */ /* put server into its own process group. If this process now spawns child processes, a signal sent to the parent will be propagated to the children */ setpgrp(); return 0; } /**************************************************************************/ /*************************************************************************** ConfigureSignalHandlers Set up the behaviour of the various signal handlers for this process. Signals are divided into three groups: those we can ignore; those that cause a fatal error but in which we are not particularly interested and those that are used to control the server daemon. We don't bother with the new real-time signals under Linux since these are blocked by default anyway. Returns: none ***************************************************************************/ /**************************************************************************/ int ConfigureSignalHandlers(void) { struct sigaction sighupSA,sigusr1SA,sigtermSA; /* ignore several signals because they do not concern us. In a production server, SIGPIPE would have to be handled as this is raised when attempting to write to a socket that has been closed or has gone away (for example if the client has crashed). SIGURG is used to handle out-of-band data. SIGIO is used to handle asynchronous I/O. SIGCHLD is very important if the server has forked any child processes. */ signal(SIGUSR2, SIG_IGN); signal(SIGPIPE, SIG_IGN); signal(SIGALRM, SIG_IGN); signal(SIGTSTP, SIG_IGN); signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); signal(SIGURG, SIG_IGN); signal(SIGXCPU, SIG_IGN); signal(SIGXFSZ, SIG_IGN); signal(SIGVTALRM, SIG_IGN); signal(SIGPROF, SIG_IGN); signal(SIGIO, SIG_IGN); signal(SIGCHLD, SIG_IGN); /* these signals mainly indicate fault conditions and should be logged. Note we catch SIGCONT, which is used for a type of job control that is usually inapplicable to a daemon process. We don't do anyting to SIGSTOP since this signal can't be caught or ignored. SIGEMT is not supported under Linux as of kernel v2.4 */ signal(SIGQUIT, FatalSigHandler); signal(SIGILL, FatalSigHandler); signal(SIGTRAP, FatalSigHandler); signal(SIGABRT, FatalSigHandler); signal(SIGIOT, FatalSigHandler); signal(SIGBUS, FatalSigHandler); #ifdef SIGEMT /* this is not defined under Linux */ signal(SIGEMT,FatalSigHandler); #endif signal(SIGFPE, FatalSigHandler); signal(SIGSEGV, FatalSigHandler); signal(SIGSTKFLT, FatalSigHandler); signal(SIGCONT, FatalSigHandler); signal(SIGPWR, FatalSigHandler); signal(SIGSYS, FatalSigHandler); /* these handlers are important for control of the daemon process */ /* TERM - shut down immediately */ sigtermSA.sa_handler=TermHandler; sigemptyset(&sigtermSA.sa_mask); sigtermSA.sa_flags=0; sigaction(SIGTERM,&sigtermSA,NULL); /* USR1 - finish serving the current connection and then close down (graceful shutdown) */ sigusr1SA.sa_handler=Usr1Handler; sigemptyset(&sigusr1SA.sa_mask); sigusr1SA.sa_flags=0; sigaction(SIGUSR1,&sigusr1SA,NULL); /* HUP - finish serving the current connection and then restart connection handling. This could be used to force a re-read of a configuration file for example */ sighupSA.sa_handler=HupHandler; sigemptyset(&sighupSA.sa_mask); sighupSA.sa_flags=0; sigaction(SIGHUP,&sighupSA,NULL); return 0; } /**************************************************************************/ /*************************************************************************** BindPassiveSocket Create a socket, bind it to a port and then place it in passive (listen) mode to handle client connections. Inputs: interface I the IP address that should be bound to the socket. This is important for multihomed hosts, which may want to restrict themselves to listening on a given interface. If this is not the case, use the special constant INADDR_ANY to listen on all interfaces. Returns: status code indicating success - 0 = success ***************************************************************************/ /**************************************************************************/ int BindPassiveSocket(const int portNum, int *const boundSocket) { /* Note by A.B.: simplified this function code a bit */ struct sockaddr_in sin; int newsock,optval; size_t optlen; /* clear the socket address structure */ memset(&sin.sin_zero, 0, 8); /* set up the fields. Note htonX macros are important for portability */ sin.sin_port=htons(portNum); sin.sin_family=AF_INET; /* Usage: AF_XXX here, PF_XXX in socket() */ sin.sin_addr.s_addr=htonl(INADDR_ANY); if((newsock=socket(PF_INET, SOCK_STREAM, 0))<0) return -1; /* The SO_REUSEADDR socket option allows the kernel to re-bind local addresses without delay (for our purposes, it allows re-binding while the previous socket is in TIME_WAIT status, which lasts for two times the Maximum Segment Lifetime - anything from 30 seconds to two minutes). It should be used with care as in general you don't want two processes sharing the same port. There are also dangers if a client tries to re-connect to the same port a previous server used within the 2*MSL window that TIME_WAIT provides. It's handy for us so the server can be restarted without having to wait for termination of the TIME_WAIT period. */ optval=1; optlen=sizeof(int); setsockopt(newsock,SOL_SOCKET,SO_REUSEADDR,&optval,optlen); /* bind to the requested port */ if(bind(newsock,(struct sockaddr*)&sin,sizeof(struct sockaddr_in))<0) return -1; /* put the socket into passive mode so it is lisetning for connections */ if(listen(newsock,SOMAXCONN)<0) return -1; *boundSocket=newsock; return 0; } /* Note on restartable system calls: several of the following functions check the return value from 'slow' system calls (i.e. calls that can block indefinitely in the kernel) and continue operation if the return value is EINTR. This error is given if a system call is interrupted by a signal. However, many systems can automatically restart system calls. Automatic restart is enabled by setting the SA_RESTART flag in the sa_flags field of the struct sigaction. We do not do this as we want the loop on accept() in AcceptConnections() to look at the gGracefulShutdown flag which is set on recept of SIGHUP and SIGUSR1 and is used to control the server. You should still check for return code EINTR even if you have set SA_RESTART to be on the safe side. Note that this simple behaviour WILL NOT WORK for the connect() system call on many systems (although Linux appears to be an exception). On such systems, you will need to call poll() or select() if connect() is interrupted. */ /**************************************************************************/ /*************************************************************************** AcceptConnections Repeatedly handle connections, blocking on accept() and then handing off the request to the HandleConnection function. Inputs: master I the master socket that has been bound to a port and is listening for connection attempts Returns: status code indicating success - 0 = success ***************************************************************************/ /**************************************************************************/ int AcceptConnections(const int master) { int proceed=1,slave,retval=0; struct sockaddr_in client; socklen_t clilen; while((proceed==1)&&(gGracefulShutdown==0)) { /* block in accept() waiting for a request */ clilen=sizeof(client); slave=accept(master,(struct sockaddr *)&client,&clilen); if(slave<0) /* accept() failed */ { if(errno==EINTR) continue; syslog(LOG_LOCAL0|LOG_INFO,"accept() failed: %m\n"); proceed=0; retval=-1; } else { retval=HandleConnection(slave); /* process connection */ if(retval) proceed=0; } close(slave); } return retval; } /**************************************************************************/ /*************************************************************************** HandleConnection Service connections from the client. In practice, this function would probably be used as a 'switchboard' to dispatch control to helper functions based on the exact content of the client request. Here, we simply read a CRLF-terminated line (the server is intended to be exercised for demo purposes via a telnet client) and echo it back to the client. Inputs: sock I the socket descriptor for this particular connection event Returns: status code indicating success - 0 = success ***************************************************************************/ /**************************************************************************/ int HandleConnection(const int slave) { char readbuf[1025]; size_t bytesRead; const size_t buflen=1024; int retval; retval=ReadLine(slave,readbuf,buflen,&bytesRead); if(retval==0) WriteToSocket(slave,readbuf,bytesRead); return retval; } /**************************************************************************/ /*************************************************************************** WriteToSocket Write a buffer full of data to a socket. Keep writing until all the data has been put into the socket. sock I the socket to read from buffer I the buffer into which the data is to be deposited buflen I the length of the buffer in bytes Returns: status code indicating success - 0 = success ***************************************************************************/ /**************************************************************************/ int WriteToSocket(const int sock,const char *const buffer, const size_t buflen) { size_t bytesWritten=0; ssize_t writeResult; int retval=0,done=0; do { writeResult=send(sock,buffer+bytesWritten,buflen-bytesWritten,0); if(writeResult==-1) { if(errno==EINTR) writeResult=0; else { retval=1; done=1; } } else { bytesWritten+=writeResult; if(writeResult==0) done=1; } }while(done==0); return retval; } /**************************************************************************/ /*************************************************************************** ReadLine Read a CRLF terminated line from a TCP socket. This is not the most efficient of functions, as it reads a byte at a time, but enhancements are beyond the scope of this example. sock I the socket to read from buffer O the buffer into which the data is to be deposited buflen I the length of the buffer in bytes bytesRead O the amount of data read Returns: status code indicating success - 0 = success ***************************************************************************/ /**************************************************************************/ int ReadLine(const int sock,char *const buffer,const size_t buflen, size_t *const bytesRead) { int done=0,retval=0; char c,lastC=0; size_t bytesSoFar=0; ssize_t readResult; do { readResult=recv(sock,&c,1,0); switch(readResult) { case -1: if(errno!=EINTR) { retval=-1; done=1; } break; case 0: retval=0; done=1; break; case 1: buffer[bytesSoFar]=c; bytesSoFar+=readResult; if(bytesSoFar>=buflen) { done=1; retval=-1; } if((c=='\n')&&(lastC=='\r')) done=1; lastC=c; break; } }while(!done); buffer[bytesSoFar]=0; *bytesRead=bytesSoFar; return retval; } /**************************************************************************/ /*************************************************************************** FatalSigHandler General catch-all signal handler to mop up signals that we aren't especially interested in. It shouldn't be called (if it is it probably indicates an error). It simply dumps a report of the signal to the log and dies. Note the strsignal() function may not be available on all platform/compiler combinations. sig I the signal number Returns: none ***************************************************************************/ /**************************************************************************/ void FatalSigHandler(int sig) { #ifdef _GNU_SOURCE syslog(LOG_LOCAL0|LOG_INFO,"caught signal: %s - exiting",strsignal(sig)); #else syslog(LOG_LOCAL0|LOG_INFO,"caught signal: %d - exiting",sig); #endif closelog(); TidyUp(); _exit(0); } /**************************************************************************/ /*************************************************************************** TermHandler Handler for the SIGTERM signal. It cleans up the lock file and closes the server's master socket, then immediately exits. sig I the signal number (SIGTERM) Returns: none ***************************************************************************/ /**************************************************************************/ void TermHandler(int sig) { TidyUp(); _exit(0); } /**************************************************************************/ /*************************************************************************** HupHandler Handler for the SIGHUP signal. It sets the gGracefulShutdown and gCaughtHupSignal flags. The latter is used to distinguish this from catching SIGUSR1. Typically in real-world servers, SIGHUP is used to tell the server that it should re-read its configuration file. Many important daemons do this, including syslog and xinetd (under Linux). sig I the signal number (SIGTERM) Returns: none ***************************************************************************/ /**************************************************************************/ void HupHandler(int sig) { syslog(LOG_LOCAL0|LOG_INFO,"caught SIGHUP"); gGracefulShutdown=1; gCaughtHupSignal=1; /****************************************************************/ /* perhaps at this point you would re-read a configuration file */ /****************************************************************/ return; } /**************************************************************************/ /*************************************************************************** Usr1Handler Handler for the SIGUSR1 signal. This sets the gGracefulShutdown flag, which permits active connections to run to completion before shutdown. It is therefore a more friendly way to shut down the server than sending SIGTERM. sig I the signal number (SIGTERM) Returns: none ***************************************************************************/ /**************************************************************************/ void Usr1Handler(int sig) { syslog(LOG_LOCAL0|LOG_INFO,"caught SIGUSR1 - soft shutdown"); gGracefulShutdown=1; return; } /**************************************************************************/ /*************************************************************************** TidyUp Dispose of system resources. This function is not strictly necessary, as UNIX processes clean up after themselves (heap memory is freed, file descriptors are closed, etc.) but it is good practice to explicitly release that which you have allocated. Returns: none ***************************************************************************/ /**************************************************************************/ void TidyUp(void) { if(gLockFileDesc!=-1) { close(gLockFileDesc); unlink(gLockFilePath); gLockFileDesc=-1; } if(gMasterSocket!=-1) { close(gMasterSocket); gMasterSocket=-1; } }
the_stack_data/103266446.c
#include <stdio.h> int main() { int n; scanf("%i", &n); for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) printf("*"); puts(""); } for (int i = n-1; i > 0; i--) { for (int j = i; j > 0; j--) printf("*"); puts(""); } return 0; }
the_stack_data/112422.c
#include <stdio.h> #include <stdlib.h> #define HAVE_SSE2 1 /* DO NOT COMPILE WITH -O/-O2/-O3 ! GENERATES INVALID ASSEMBLY. */ /* mmx.h MultiMedia eXtensions GCC interface library for IA32. To use this library, simply include this header file and compile with GCC. You MUST have inlining enabled in order for mmx_ok() to work; this can be done by simply using -O on the GCC command line. Compiling with -DMMX_TRACE will cause detailed trace output to be sent to stderr for each mmx operation. This adds lots of code, and obviously slows execution to a crawl, but can be very useful for debugging. THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY PARTICULAR PURPOSE. June 11, 1998 by H. Dietz and R. Fisher */ /* The type of an value that fits in an MMX register (note that long long constant values MUST be suffixed by LL and unsigned long long values by ULL, lest they be truncated by the compiler) */ typedef union { long long q; /* Quadword (64-bit) value */ unsigned long long uq; /* Unsigned Quadword */ int d[2]; /* 2 Doubleword (32-bit) values */ unsigned int ud[2]; /* 2 Unsigned Doubleword */ short w[4]; /* 4 Word (16-bit) values */ unsigned short uw[4]; /* 4 Unsigned Word */ char b[8]; /* 8 Byte (8-bit) values */ unsigned char ub[8]; /* 8 Unsigned Byte */ } mmx_t; /* Function to test if mmx instructions are supported... */ inline extern int mmx_ok(void) { /* Returns 1 if mmx instructions are ok, 0 if hardware does not support mmx */ register int ok = 0; __asm__ __volatile__ ( /* Get CPU version information */ "movl $1, %%eax\n\t" "cpuid\n\t" "movl %%edx, %0" : "=a" (ok) : /* no input */ ); return((ok & 0x800000) == 0x800000); } /* Helper functions for the instruction macros that follow... (note that memory-to-register, m2r, instructions are nearly as efficient as register-to-register, r2r, instructions; however, memory-to-memory instructions are really simulated as a convenience, and are only 1/3 as efficient) */ #ifdef MMX_TRACE /* Include the stuff for printing a trace to stderr... */ #include <stdio.h> #define mmx_m2r(op, mem, reg) \ { \ mmx_t mmx_trace; \ mmx_trace = (mem); \ fprintf(stderr, #op "_m2r(" #mem "=0x%016llx, ", mmx_trace.q); \ __asm__ __volatile__ ("movq %%" #reg ", %0" \ : "=X" (mmx_trace) \ : /* nothing */ ); \ fprintf(stderr, #reg "=0x%016llx) => ", mmx_trace.q); \ __asm__ __volatile__ (#op " %0, %%" #reg \ : /* nothing */ \ : "X" (mem)); \ __asm__ __volatile__ ("movq %%" #reg ", %0" \ : "=X" (mmx_trace) \ : /* nothing */ ); \ fprintf(stderr, #reg "=0x%016llx\n", mmx_trace.q); \ } #define mmx_r2m(op, reg, mem) \ { \ mmx_t mmx_trace; \ __asm__ __volatile__ ("movq %%" #reg ", %0" \ : "=X" (mmx_trace) \ : /* nothing */ ); \ fprintf(stderr, #op "_r2m(" #reg "=0x%016llx, ", mmx_trace.q); \ mmx_trace = (mem); \ fprintf(stderr, #mem "=0x%016llx) => ", mmx_trace.q); \ __asm__ __volatile__ (#op " %%" #reg ", %0" \ : "=X" (mem) \ : /* nothing */ ); \ mmx_trace = (mem); \ fprintf(stderr, #mem "=0x%016llx\n", mmx_trace.q); \ } #define mmx_r2r(op, regs, regd) \ { \ mmx_t mmx_trace; \ __asm__ __volatile__ ("movq %%" #regs ", %0" \ : "=X" (mmx_trace) \ : /* nothing */ ); \ fprintf(stderr, #op "_r2r(" #regs "=0x%016llx, ", mmx_trace.q); \ __asm__ __volatile__ ("movq %%" #regd ", %0" \ : "=X" (mmx_trace) \ : /* nothing */ ); \ fprintf(stderr, #regd "=0x%016llx) => ", mmx_trace.q); \ __asm__ __volatile__ (#op " %" #regs ", %" #regd); \ __asm__ __volatile__ ("movq %%" #regd ", %0" \ : "=X" (mmx_trace) \ : /* nothing */ ); \ fprintf(stderr, #regd "=0x%016llx\n", mmx_trace.q); \ } #define mmx_m2m(op, mems, memd) \ { \ mmx_t mmx_trace; \ mmx_trace = (mems); \ fprintf(stderr, #op "_m2m(" #mems "=0x%016llx, ", mmx_trace.q); \ mmx_trace = (memd); \ fprintf(stderr, #memd "=0x%016llx) => ", mmx_trace.q); \ __asm__ __volatile__ ("movq %0, %%mm0\n\t" \ #op " %1, %%mm0\n\t" \ "movq %%mm0, %0" \ : "=X" (memd) \ : "X" (mems)); \ mmx_trace = (memd); \ fprintf(stderr, #memd "=0x%016llx\n", mmx_trace.q); \ } #else /* These macros are a lot simpler without the tracing... */ #define mmx_m2r(op, mem, reg) \ __asm__ __volatile__ (#op " %0, %%" #reg \ : /* nothing */ \ : "X" (mem)) #define mmx_r2m(op, reg, mem) \ __asm__ __volatile__ (#op " %%" #reg ", %0" \ : "=X" (mem) \ : /* nothing */ ) #define mmx_r2r(op, regs, regd) \ __asm__ __volatile__ (#op " %" #regs ", %" #regd) #define mmx_m2m(op, mems, memd) \ __asm__ __volatile__ ("movq %0, %%mm0\n\t" \ #op " %1, %%mm0\n\t" \ "movq %%mm0, %0" \ : "=X" (memd) \ : "X" (mems)) #endif /* 1x64 MOVe Quadword (this is both a load and a store... in fact, it is the only way to store) */ #define movq_m2r(var, reg) mmx_m2r(movq, var, reg) #define movq_r2m(reg, var) mmx_r2m(movq, reg, var) #define movq_r2r(regs, regd) mmx_r2r(movq, regs, regd) #define movq(vars, vard) \ __asm__ __volatile__ ("movq %1, %%mm0\n\t" \ "movq %%mm0, %0" \ : "=X" (vard) \ : "X" (vars)) /* 1x64 MOVe Doubleword (like movq, this is both load and store... but is most useful for moving things between mmx registers and ordinary registers) */ #define movd_m2r(var, reg) mmx_m2r(movd, var, reg) #define movd_r2m(reg, var) mmx_r2m(movd, reg, var) #define movd_r2r(regs, regd) mmx_r2r(movd, regs, regd) #define movd(vars, vard) \ __asm__ __volatile__ ("movd %1, %%mm0\n\t" \ "movd %%mm0, %0" \ : "=X" (vard) \ : "X" (vars)) /* 2x32, 4x16, and 8x8 Parallel ADDs */ #define paddd_m2r(var, reg) mmx_m2r(paddd, var, reg) #define paddd_r2r(regs, regd) mmx_r2r(paddd, regs, regd) #define paddd(vars, vard) mmx_m2m(paddd, vars, vard) #define paddw_m2r(var, reg) mmx_m2r(paddw, var, reg) #define paddw_r2r(regs, regd) mmx_r2r(paddw, regs, regd) #define paddw(vars, vard) mmx_m2m(paddw, vars, vard) #define paddb_m2r(var, reg) mmx_m2r(paddb, var, reg) #define paddb_r2r(regs, regd) mmx_r2r(paddb, regs, regd) #define paddb(vars, vard) mmx_m2m(paddb, vars, vard) /* 4x16 and 8x8 Parallel ADDs using Saturation arithmetic */ #define paddsw_m2r(var, reg) mmx_m2r(paddsw, var, reg) #define paddsw_r2r(regs, regd) mmx_r2r(paddsw, regs, regd) #define paddsw(vars, vard) mmx_m2m(paddsw, vars, vard) #define paddsb_m2r(var, reg) mmx_m2r(paddsb, var, reg) #define paddsb_r2r(regs, regd) mmx_r2r(paddsb, regs, regd) #define paddsb(vars, vard) mmx_m2m(paddsb, vars, vard) /* 4x16 and 8x8 Parallel ADDs using Unsigned Saturation arithmetic */ #define paddusw_m2r(var, reg) mmx_m2r(paddusw, var, reg) #define paddusw_r2r(regs, regd) mmx_r2r(paddusw, regs, regd) #define paddusw(vars, vard) mmx_m2m(paddusw, vars, vard) #define paddusb_m2r(var, reg) mmx_m2r(paddusb, var, reg) #define paddusb_r2r(regs, regd) mmx_r2r(paddusb, regs, regd) #define paddusb(vars, vard) mmx_m2m(paddusb, vars, vard) /* 2x32, 4x16, and 8x8 Parallel SUBs */ #define psubd_m2r(var, reg) mmx_m2r(psubd, var, reg) #define psubd_r2r(regs, regd) mmx_r2r(psubd, regs, regd) #define psubd(vars, vard) mmx_m2m(psubd, vars, vard) #define psubw_m2r(var, reg) mmx_m2r(psubw, var, reg) #define psubw_r2r(regs, regd) mmx_r2r(psubw, regs, regd) #define psubw(vars, vard) mmx_m2m(psubw, vars, vard) #define psubb_m2r(var, reg) mmx_m2r(psubb, var, reg) #define psubb_r2r(regs, regd) mmx_r2r(psubb, regs, regd) #define psubb(vars, vard) mmx_m2m(psubb, vars, vard) /* 4x16 and 8x8 Parallel SUBs using Saturation arithmetic */ #define psubsw_m2r(var, reg) mmx_m2r(psubsw, var, reg) #define psubsw_r2r(regs, regd) mmx_r2r(psubsw, regs, regd) #define psubsw(vars, vard) mmx_m2m(psubsw, vars, vard) #define psubsb_m2r(var, reg) mmx_m2r(psubsb, var, reg) #define psubsb_r2r(regs, regd) mmx_r2r(psubsb, regs, regd) #define psubsb(vars, vard) mmx_m2m(psubsb, vars, vard) /* 4x16 and 8x8 Parallel SUBs using Unsigned Saturation arithmetic */ #define psubusw_m2r(var, reg) mmx_m2r(psubusw, var, reg) #define psubusw_r2r(regs, regd) mmx_r2r(psubusw, regs, regd) #define psubusw(vars, vard) mmx_m2m(psubusw, vars, vard) #define psubusb_m2r(var, reg) mmx_m2r(psubusb, var, reg) #define psubusb_r2r(regs, regd) mmx_r2r(psubusb, regs, regd) #define psubusb(vars, vard) mmx_m2m(psubusb, vars, vard) /* 4x16 Parallel MULs giving Low 4x16 portions of results */ #define pmullw_m2r(var, reg) mmx_m2r(pmullw, var, reg) #define pmullw_r2r(regs, regd) mmx_r2r(pmullw, regs, regd) #define pmullw(vars, vard) mmx_m2m(pmullw, vars, vard) /* 4x16 Parallel MULs giving High 4x16 portions of results */ #define pmulhw_m2r(var, reg) mmx_m2r(pmulhw, var, reg) #define pmulhw_r2r(regs, regd) mmx_r2r(pmulhw, regs, regd) #define pmulhw(vars, vard) mmx_m2m(pmulhw, vars, vard) /* 4x16->2x32 Parallel Mul-ADD (muls like pmullw, then adds adjacent 16-bit fields in the multiply result to make the final 2x32 result) */ #define pmaddwd_m2r(var, reg) mmx_m2r(pmaddwd, var, reg) #define pmaddwd_r2r(regs, regd) mmx_r2r(pmaddwd, regs, regd) #define pmaddwd(vars, vard) mmx_m2m(pmaddwd, vars, vard) /* 1x64 bitwise AND */ #define pand_m2r(var, reg) mmx_m2r(pand, var, reg) #define pand_r2r(regs, regd) mmx_r2r(pand, regs, regd) #define pand(vars, vard) mmx_m2m(pand, vars, vard) /* 1x64 bitwise AND with Not the destination */ #define pandn_m2r(var, reg) mmx_m2r(pandn, var, reg) #define pandn_r2r(regs, regd) mmx_r2r(pandn, regs, regd) #define pandn(vars, vard) mmx_m2m(pandn, vars, vard) /* 1x64 bitwise OR */ #define por_m2r(var, reg) mmx_m2r(por, var, reg) #define por_r2r(regs, regd) mmx_r2r(por, regs, regd) #define por(vars, vard) mmx_m2m(por, vars, vard) /* 1x64 bitwise eXclusive OR */ #define pxor_m2r(var, reg) mmx_m2r(pxor, var, reg) #define pxor_r2r(regs, regd) mmx_r2r(pxor, regs, regd) #define pxor(vars, vard) mmx_m2m(pxor, vars, vard) /* 2x32, 4x16, and 8x8 Parallel CoMPare for EQuality (resulting fields are either 0 or -1) */ #define pcmpeqd_m2r(var, reg) mmx_m2r(pcmpeqd, var, reg) #define pcmpeqd_r2r(regs, regd) mmx_r2r(pcmpeqd, regs, regd) #define pcmpeqd(vars, vard) mmx_m2m(pcmpeqd, vars, vard) #define pcmpeqw_m2r(var, reg) mmx_m2r(pcmpeqw, var, reg) #define pcmpeqw_r2r(regs, regd) mmx_r2r(pcmpeqw, regs, regd) #define pcmpeqw(vars, vard) mmx_m2m(pcmpeqw, vars, vard) #define pcmpeqb_m2r(var, reg) mmx_m2r(pcmpeqb, var, reg) #define pcmpeqb_r2r(regs, regd) mmx_r2r(pcmpeqb, regs, regd) #define pcmpeqb(vars, vard) mmx_m2m(pcmpeqb, vars, vard) /* 2x32, 4x16, and 8x8 Parallel CoMPare for Greater Than (resulting fields are either 0 or -1) */ #define pcmpgtd_m2r(var, reg) mmx_m2r(pcmpgtd, var, reg) #define pcmpgtd_r2r(regs, regd) mmx_r2r(pcmpgtd, regs, regd) #define pcmpgtd(vars, vard) mmx_m2m(pcmpgtd, vars, vard) #define pcmpgtw_m2r(var, reg) mmx_m2r(pcmpgtw, var, reg) #define pcmpgtw_r2r(regs, regd) mmx_r2r(pcmpgtw, regs, regd) #define pcmpgtw(vars, vard) mmx_m2m(pcmpgtw, vars, vard) #define pcmpgtb_m2r(var, reg) mmx_m2r(pcmpgtb, var, reg) #define pcmpgtb_r2r(regs, regd) mmx_r2r(pcmpgtb, regs, regd) #define pcmpgtb(vars, vard) mmx_m2m(pcmpgtb, vars, vard) /* 1x64, 2x32, and 4x16 Parallel Shift Left Logical */ #define psllq_m2r(var, reg) mmx_m2r(psllq, var, reg) #define psllq_r2r(regs, regd) mmx_r2r(psllq, regs, regd) #define psllq(vars, vard) mmx_m2m(psllq, vars, vard) #define pslld_m2r(var, reg) mmx_m2r(pslld, var, reg) #define pslld_r2r(regs, regd) mmx_r2r(pslld, regs, regd) #define pslld(vars, vard) mmx_m2m(pslld, vars, vard) #define psllw_m2r(var, reg) mmx_m2r(psllw, var, reg) #define psllw_r2r(regs, regd) mmx_r2r(psllw, regs, regd) #define psllw(vars, vard) mmx_m2m(psllw, vars, vard) /* 1x64, 2x32, and 4x16 Parallel Shift Right Logical */ #define psrlq_m2r(var, reg) mmx_m2r(psrlq, var, reg) #define psrlq_r2r(regs, regd) mmx_r2r(psrlq, regs, regd) #define psrlq(vars, vard) mmx_m2m(psrlq, vars, vard) #define psrld_m2r(var, reg) mmx_m2r(psrld, var, reg) #define psrld_r2r(regs, regd) mmx_r2r(psrld, regs, regd) #define psrld(vars, vard) mmx_m2m(psrld, vars, vard) #define psrlw_m2r(var, reg) mmx_m2r(psrlw, var, reg) #define psrlw_r2r(regs, regd) mmx_r2r(psrlw, regs, regd) #define psrlw(vars, vard) mmx_m2m(psrlw, vars, vard) /* 2x32 and 4x16 Parallel Shift Right Arithmetic */ #define psrad_m2r(var, reg) mmx_m2r(psrad, var, reg) #define psrad_r2r(regs, regd) mmx_r2r(psrad, regs, regd) #define psrad(vars, vard) mmx_m2m(psrad, vars, vard) #define psraw_m2r(var, reg) mmx_m2r(psraw, var, reg) #define psraw_r2r(regs, regd) mmx_r2r(psraw, regs, regd) #define psraw(vars, vard) mmx_m2m(psraw, vars, vard) /* 2x32->4x16 and 4x16->8x8 PACK and Signed Saturate (packs source and dest fields into dest in that order) */ #define packssdw_m2r(var, reg) mmx_m2r(packssdw, var, reg) #define packssdw_r2r(regs, regd) mmx_r2r(packssdw, regs, regd) #define packssdw(vars, vard) mmx_m2m(packssdw, vars, vard) #define packsswb_m2r(var, reg) mmx_m2r(packsswb, var, reg) #define packsswb_r2r(regs, regd) mmx_r2r(packsswb, regs, regd) #define packsswb(vars, vard) mmx_m2m(packsswb, vars, vard) /* 4x16->8x8 PACK and Unsigned Saturate (packs source and dest fields into dest in that order) */ #define packuswb_m2r(var, reg) mmx_m2r(packuswb, var, reg) #define packuswb_r2r(regs, regd) mmx_r2r(packuswb, regs, regd) #define packuswb(vars, vard) mmx_m2m(packuswb, vars, vard) /* 2x32->1x64, 4x16->2x32, and 8x8->4x16 UNPaCK Low (interleaves low half of dest with low half of source as padding in each result field) */ #define punpckldq_m2r(var, reg) mmx_m2r(punpckldq, var, reg) #define punpckldq_r2r(regs, regd) mmx_r2r(punpckldq, regs, regd) #define punpckldq(vars, vard) mmx_m2m(punpckldq, vars, vard) #define punpcklwd_m2r(var, reg) mmx_m2r(punpcklwd, var, reg) #define punpcklwd_r2r(regs, regd) mmx_r2r(punpcklwd, regs, regd) #define punpcklwd(vars, vard) mmx_m2m(punpcklwd, vars, vard) #define punpcklbw_m2r(var, reg) mmx_m2r(punpcklbw, var, reg) #define punpcklbw_r2r(regs, regd) mmx_r2r(punpcklbw, regs, regd) #define punpcklbw(vars, vard) mmx_m2m(punpcklbw, vars, vard) /* 2x32->1x64, 4x16->2x32, and 8x8->4x16 UNPaCK High (interleaves high half of dest with high half of source as padding in each result field) */ #define punpckhdq_m2r(var, reg) mmx_m2r(punpckhdq, var, reg) #define punpckhdq_r2r(regs, regd) mmx_r2r(punpckhdq, regs, regd) #define punpckhdq(vars, vard) mmx_m2m(punpckhdq, vars, vard) #define punpckhwd_m2r(var, reg) mmx_m2r(punpckhwd, var, reg) #define punpckhwd_r2r(regs, regd) mmx_r2r(punpckhwd, regs, regd) #define punpckhwd(vars, vard) mmx_m2m(punpckhwd, vars, vard) #define punpckhbw_m2r(var, reg) mmx_m2r(punpckhbw, var, reg) #define punpckhbw_r2r(regs, regd) mmx_r2r(punpckhbw, regs, regd) #define punpckhbw(vars, vard) mmx_m2m(punpckhbw, vars, vard) /* 1x64 add/sub -- this is in sse2, not in mmx. */ #define paddq_m2r(var, reg) mmx_m2r(paddq, var, reg) #define paddq_r2r(regs, regd) mmx_r2r(paddq, regs, regd) #define paddq(vars, vard) mmx_m2m(paddq, vars, vard) #define psubq_m2r(var, reg) mmx_m2r(psubq, var, reg) #define psubq_r2r(regs, regd) mmx_r2r(psubq, regs, regd) #define psubq(vars, vard) mmx_m2m(psubq, vars, vard) /* Empty MMx State (used to clean-up when going from mmx to float use of the registers that are shared by both; note that there is no float-to-mmx operation needed, because only the float tag word info is corruptible) */ #ifdef MMX_TRACE #define emms() \ { \ fprintf(stderr, "emms()\n"); \ __asm__ __volatile__ ("emms"); \ } #else #define emms() __asm__ __volatile__ ("emms") #endif void mkRand( mmx_t* mm ) { mm->uw[0] = 0xFFFF & (random() >> 7); mm->uw[1] = 0xFFFF & (random() >> 7); mm->uw[2] = 0xFFFF & (random() >> 7); mm->uw[3] = 0xFFFF & (random() >> 7); } int main( void ) { int i; // int rval; mmx_t ma; mmx_t mb; mmx_t ma0, mb0; movq_r2r(mm0, mm1); // rval = mmx_ok(); /* Announce return value of mmx_ok() */ // printf("Value returned from init was %x.", rval); // printf(" (Indicates MMX %s available)\n\n",(rval)? "is" : "not"); // fflush(stdout); fflush(stdout); // if(rval) #define do_test(_name, _operation) \ for (i = 0; i < 25000; i++) { \ mkRand(&ma); \ mkRand(&mb); \ ma0 = ma; mb0 = mb; \ _operation; \ fprintf(stdout, "%s ( %016llx, %016llx ) -> %016llx\n", \ _name, ma0.q, mb0.q, mb.q); \ fflush(stdout); \ } { do_test("paddd", paddd(ma,mb)); do_test("paddw", paddw(ma,mb)); do_test("paddb", paddb(ma,mb)); do_test("paddsw", paddsw(ma,mb)); do_test("paddsb", paddsb(ma,mb)); do_test("paddusw", paddusw(ma,mb)); do_test("paddusb", paddusb(ma,mb)); do_test("psubd", psubd(ma,mb)); do_test("psubw", psubw(ma,mb)); do_test("psubb", psubb(ma,mb)); do_test("psubsw", psubsw(ma,mb)); do_test("psubsb", psubsb(ma,mb)); do_test("psubusw", psubusw(ma,mb)); do_test("psubusb", psubusb(ma,mb)); do_test("pmulhw", pmulhw(ma,mb)); do_test("pmullw", pmullw(ma,mb)); do_test("pmaddwd", pmaddwd(ma,mb)); do_test("pcmpeqd", pcmpeqd(ma,mb)); do_test("pcmpeqw", pcmpeqw(ma,mb)); do_test("pcmpeqb", pcmpeqb(ma,mb)); do_test("pcmpgtd", pcmpgtd(ma,mb)); do_test("pcmpgtw", pcmpgtw(ma,mb)); do_test("pcmpgtb", pcmpgtb(ma,mb)); do_test("packssdw", packssdw(ma,mb)); do_test("packsswb", packsswb(ma,mb)); do_test("packuswb", packuswb(ma,mb)); do_test("punpckhdq", punpckhdq(ma,mb)); do_test("punpckhwd", punpckhwd(ma,mb)); do_test("punpckhbw", punpckhbw(ma,mb)); do_test("punpckldq", punpckldq(ma,mb)); do_test("punpcklwd", punpcklwd(ma,mb)); do_test("punpcklbw", punpcklbw(ma,mb)); do_test("pand", pand(ma,mb)); do_test("pandn", pandn(ma,mb)); do_test("por", por(ma,mb)); do_test("pxor", pxor(ma,mb)); do_test("psllq", psllq(ma,mb)); do_test("pslld", pslld(ma,mb)); do_test("psllw", psllw(ma,mb)); do_test("psrlq", psrlq(ma,mb)); do_test("psrld", psrld(ma,mb)); do_test("psrlw", psrlw(ma,mb)); do_test("psrad", psrad(ma,mb)); do_test("psraw", psraw(ma,mb)); #if HAVE_SSE2 do_test("paddq", paddq(ma,mb)); do_test("psubq", psubq(ma,mb)); #endif emms(); } /* Clean-up and exit nicely */ exit(0); }
the_stack_data/135364.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 num1, int num2 );//declaring function prototype int maximum( int num1, int num2 );//declaring function prototype int multiply( int num1, int num2 );//declaring function prototype 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 num1, int num2 )//beginin of the minimum function { if( num1 > num2 ){//checks wheather num1 greater than num2 return num2; //returns the minimum number } else if( num1 < num2 ){//checks wheather num2 greater than num1 return num1;//returns the minimum number } //end of the minimum function } int maximum( int num1, int num2 )//beginin of the maximum function { if( num1 > num2 ){//checks wheather num1 greater than num2 return num1;//returns the maximum number } else if( num1 < num2 ){//checks wheather num2 greater than num1 return num2;//returns the maximum number } //end of the maximum function } int multiply( int num1, int num2 )//begining of the multiply function { return num1 * num2;//returns the multiplied answer //end of the multiply function }
the_stack_data/98576696.c
#include <string.h> #include <stdio.h> int main(int argc, char* argv[]) { printf("%d\n", strncmp("a", "aa", 2)); printf("%d\n", strncmp("a", "aä", 2)); printf("%d\n", strncmp("\xFF", "\xFE", 2)); printf("%d\n", strncmp("", "\xFF", 1)); printf("%d\n", strncmp("a", "c", 1)); printf("%d\n", strncmp("a", "a", 2)); return 0; }
the_stack_data/1202292.c
/* this program can be found at: http://www.thegeekstuff.com/2012/05/c-mutex-examples/?refcom */ #include<stdio.h> #include<string.h> #include<pthread.h> #include<stdlib.h> #include<unistd.h> pthread_t tid[2]; int counter; void* doSomeThing(void *arg) { unsigned long i = 0; counter += 1; printf("\n Job %d started\n", counter); for(i=0; i<(0xFFFFFFFF);i++); printf("\n Job %d finished\n", counter); return NULL; } int main(void) { int i = 0; int err; while(i < 2) { err = pthread_create(&(tid[i]), NULL, &doSomeThing, NULL); if (err != 0) printf("\ncan't create thread :[%s]", strerror(err)); i++; } pthread_join(tid[0], NULL); pthread_join(tid[1], NULL); return 0; }
the_stack_data/193893905.c
#include <stdio.h> #include <stdlib.h> int *add(int m, int n) { static int sum=0; sum=m+n; return (&sum); } void main() { int *p=add(10,15); printf("%p:%d\n",p,*p); }
the_stack_data/152930.c
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #define LV_ATTRIBUTE_MEM_ALIGN #define LV_ATTRIBUTE_IMG_ALARM_16PX #define LV_COLOR_DEPTH 32 //#define LV_COLOR_DEPTH 16 #define LV_IMG_PX_SIZE_ALPHA_BYTE 4 /* for 32 bit color */ //#define LV_IMG_PX_SIZE_ALPHA_BYTE 3 /* for 16 bit color */ #define LV_IMG_CF_TRUE_COLOR_ALPHA 5 /* for 32 bit color */ // #define LV_IMG_CF_TRUE_COLOR_ALPHA 3 /* for 16 bit color */ // #define LV_COLOR_16_SWAP 1 /** Image header it is compatible with * the result from image converter utility*/ typedef struct { uint32_t cf : 5; /* Color format: See `lv_img_color_format_t`*/ uint32_t always_zero : 3; /*It the upper bits of the first byte. Always zero to look like a non-printable character*/ uint32_t reserved : 2; /*Reserved to be used later*/ uint32_t w : 11; /*Width of the image map*/ uint32_t h : 11; /*Height of the image map*/ } lv_img_header_t; typedef struct { lv_img_header_t header; uint32_t data_size; const uint8_t * data; } lv_img_dsc_t; #ifndef LV_ATTRIBUTE_MEM_ALIGN #define LV_ATTRIBUTE_MEM_ALIGN #endif #ifndef LV_ATTRIBUTE_IMG_INFO_1_16PX #define LV_ATTRIBUTE_IMG_INFO_1_16PX #endif const LV_ATTRIBUTE_MEM_ALIGN LV_ATTRIBUTE_IMG_INFO_1_16PX uint8_t info_1_16px_map[] = { #if LV_COLOR_DEPTH == 1 || LV_COLOR_DEPTH == 8 /*Pixel format: Alpha 8 bit, Red: 3 bit, Green: 3 bit, Blue: 2 bit*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x3c, 0x18, 0x9c, 0x18, 0xdb, 0x18, 0xfb, 0x18, 0xf7, 0x18, 0xd0, 0x18, 0x8b, 0x18, 0x24, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x0f, 0x18, 0xac, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xfb, 0x18, 0x83, 0x18, 0x03, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x18, 0x10, 0x18, 0xd3, 0x18, 0xff, 0x18, 0xff, 0x39, 0xff, 0x7e, 0xff, 0xbe, 0xff, 0x9e, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xa7, 0x18, 0x03, 0x00, 0x00, 0x18, 0x00, 0x18, 0xb4, 0x18, 0xff, 0x18, 0xff, 0x59, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0x77, 0x18, 0x00, 0x18, 0x48, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x38, 0xff, 0x9e, 0xff, 0x39, 0xff, 0xdf, 0xff, 0xff, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xf7, 0x18, 0x18, 0x18, 0xac, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0xdf, 0xff, 0xff, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0x74, 0x18, 0xef, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0xdf, 0xff, 0xff, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xb4, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0xdf, 0xff, 0xff, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xd7, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0xdf, 0xff, 0xff, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xd7, 0x18, 0xef, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0xdf, 0xff, 0xff, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xb4, 0x18, 0xac, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0xdf, 0xff, 0xff, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0x74, 0x18, 0x48, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x39, 0xff, 0x39, 0xff, 0xdf, 0xff, 0xff, 0xff, 0x39, 0xff, 0x39, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xf7, 0x18, 0x18, 0x18, 0x00, 0x18, 0xb3, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7e, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0x77, 0x18, 0x00, 0x04, 0x00, 0x18, 0x10, 0x18, 0xd3, 0x18, 0xff, 0x18, 0xff, 0x39, 0xff, 0x59, 0xff, 0x59, 0xff, 0x59, 0xff, 0x59, 0xff, 0x59, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xa7, 0x18, 0x03, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x0f, 0x18, 0xac, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xff, 0x18, 0xfb, 0x18, 0x80, 0x18, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x18, 0x3c, 0x18, 0x9c, 0x18, 0xdb, 0x18, 0xfb, 0x18, 0xf7, 0x18, 0xcf, 0x18, 0x8b, 0x18, 0x24, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, #endif #if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP == 0 /*Pixel format: Alpha 8 bit, Red: 5 bit, Green: 6 bit, Blue: 5 bit*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x06, 0x00, 0x40, 0x06, 0x3c, 0x40, 0x06, 0x9c, 0x40, 0x06, 0xdb, 0x40, 0x06, 0xfb, 0x40, 0x06, 0xf7, 0x40, 0x06, 0xd0, 0x40, 0x06, 0x8b, 0x40, 0x06, 0x24, 0x40, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x06, 0x00, 0x40, 0x06, 0x0f, 0x40, 0x06, 0xac, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xfb, 0x40, 0x06, 0x83, 0x40, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x40, 0x06, 0x10, 0x40, 0x06, 0xd3, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x44, 0x26, 0xff, 0xac, 0x66, 0xff, 0x14, 0xa7, 0xff, 0xf2, 0x96, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xa7, 0x20, 0x06, 0x03, 0x00, 0x00, 0x00, 0x60, 0x06, 0x00, 0x40, 0x06, 0xb4, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x66, 0x36, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbd, 0xef, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0x77, 0x20, 0x06, 0x00, 0x40, 0x06, 0x48, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x44, 0x26, 0xff, 0xd1, 0x8e, 0xff, 0x65, 0x2e, 0xff, 0x58, 0xc7, 0xff, 0xbd, 0xef, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xf7, 0x40, 0x06, 0x18, 0x40, 0x06, 0xac, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x58, 0xc7, 0xff, 0xbd, 0xef, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0x74, 0x40, 0x06, 0xef, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x58, 0xc7, 0xff, 0xbd, 0xef, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xb4, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x58, 0xc7, 0xff, 0xbd, 0xef, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xd7, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x58, 0xc7, 0xff, 0xbd, 0xef, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xd7, 0x40, 0x06, 0xef, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x58, 0xc7, 0xff, 0xbd, 0xef, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xb4, 0x40, 0x06, 0xac, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x58, 0xc7, 0xff, 0xbd, 0xef, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0x74, 0x40, 0x06, 0x48, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x65, 0x2e, 0xff, 0x65, 0x2e, 0xff, 0x79, 0xcf, 0xff, 0xdd, 0xef, 0xff, 0x65, 0x2e, 0xff, 0x65, 0x2e, 0xff, 0x41, 0x0e, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xf7, 0x40, 0x06, 0x18, 0x60, 0x06, 0x00, 0x40, 0x06, 0xb3, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0xfe, 0xf7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8c, 0x66, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0x77, 0x60, 0x06, 0x00, 0x00, 0x01, 0x00, 0x40, 0x06, 0x10, 0x40, 0x06, 0xd3, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x66, 0x36, 0xff, 0x66, 0x36, 0xff, 0x66, 0x36, 0xff, 0x66, 0x36, 0xff, 0x66, 0x36, 0xff, 0x66, 0x36, 0xff, 0x42, 0x16, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xa7, 0x40, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x06, 0x00, 0x40, 0x06, 0x0f, 0x40, 0x06, 0xac, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xff, 0x40, 0x06, 0xfb, 0x40, 0x06, 0x80, 0x40, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x06, 0x00, 0x40, 0x06, 0x3c, 0x40, 0x06, 0x9c, 0x40, 0x06, 0xdb, 0x40, 0x06, 0xfb, 0x40, 0x06, 0xf7, 0x40, 0x06, 0xcf, 0x40, 0x06, 0x8b, 0x40, 0x06, 0x24, 0x40, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, #endif #if LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP != 0 /*Pixel format: Alpha 8 bit, Red: 5 bit, Green: 6 bit, Blue: 5 bit BUT the 2 color bytes are swapped*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x40, 0x00, 0x06, 0x40, 0x3c, 0x06, 0x40, 0x9c, 0x06, 0x40, 0xdb, 0x06, 0x40, 0xfb, 0x06, 0x40, 0xf7, 0x06, 0x40, 0xd0, 0x06, 0x40, 0x8b, 0x06, 0x40, 0x24, 0x06, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x40, 0x00, 0x06, 0x40, 0x0f, 0x06, 0x40, 0xac, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xfb, 0x06, 0x40, 0x83, 0x06, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x06, 0x40, 0x10, 0x06, 0x40, 0xd3, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x26, 0x44, 0xff, 0x66, 0xac, 0xff, 0xa7, 0x14, 0xff, 0x96, 0xf2, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xa7, 0x06, 0x20, 0x03, 0x00, 0x00, 0x00, 0x06, 0x60, 0x00, 0x06, 0x40, 0xb4, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x36, 0x66, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xef, 0xbd, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0x77, 0x06, 0x20, 0x00, 0x06, 0x40, 0x48, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x26, 0x44, 0xff, 0x8e, 0xd1, 0xff, 0x2e, 0x65, 0xff, 0xc7, 0x58, 0xff, 0xef, 0xbd, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xf7, 0x06, 0x40, 0x18, 0x06, 0x40, 0xac, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0xc7, 0x58, 0xff, 0xef, 0xbd, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0x74, 0x06, 0x40, 0xef, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0xc7, 0x58, 0xff, 0xef, 0xbd, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xb4, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0xc7, 0x58, 0xff, 0xef, 0xbd, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xd7, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0xc7, 0x58, 0xff, 0xef, 0xbd, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xd7, 0x06, 0x40, 0xef, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0xc7, 0x58, 0xff, 0xef, 0xbd, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xb4, 0x06, 0x40, 0xac, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0xc7, 0x58, 0xff, 0xef, 0xbd, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0x74, 0x06, 0x40, 0x48, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x2e, 0x65, 0xff, 0x2e, 0x65, 0xff, 0xcf, 0x79, 0xff, 0xef, 0xdd, 0xff, 0x2e, 0x65, 0xff, 0x2e, 0x65, 0xff, 0x0e, 0x41, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xf7, 0x06, 0x40, 0x18, 0x06, 0x60, 0x00, 0x06, 0x40, 0xb3, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0xf7, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x66, 0x8c, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0x77, 0x06, 0x60, 0x00, 0x01, 0x00, 0x00, 0x06, 0x40, 0x10, 0x06, 0x40, 0xd3, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x36, 0x66, 0xff, 0x36, 0x66, 0xff, 0x36, 0x66, 0xff, 0x36, 0x66, 0xff, 0x36, 0x66, 0xff, 0x36, 0x66, 0xff, 0x16, 0x42, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xa7, 0x06, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x40, 0x00, 0x06, 0x40, 0x0f, 0x06, 0x40, 0xac, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xff, 0x06, 0x40, 0xfb, 0x06, 0x40, 0x80, 0x06, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x60, 0x00, 0x06, 0x40, 0x3c, 0x06, 0x40, 0x9c, 0x06, 0x40, 0xdb, 0x06, 0x40, 0xfb, 0x06, 0x40, 0xf7, 0x06, 0x40, 0xcf, 0x06, 0x40, 0x8b, 0x06, 0x40, 0x24, 0x06, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, #endif #if LV_COLOR_DEPTH == 32 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xca, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x3c, 0x00, 0xc8, 0x00, 0x9c, 0x00, 0xc8, 0x00, 0xdb, 0x00, 0xc8, 0x00, 0xfb, 0x00, 0xc8, 0x00, 0xf7, 0x00, 0xc8, 0x00, 0xd0, 0x00, 0xc8, 0x00, 0x8b, 0x00, 0xc8, 0x00, 0x24, 0x00, 0xc7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc7, 0x00, 0x00, 0x00, 0xc9, 0x00, 0x0f, 0x00, 0xc8, 0x00, 0xac, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xfb, 0x00, 0xc8, 0x00, 0x83, 0x00, 0xc8, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xc9, 0x00, 0x10, 0x00, 0xc8, 0x00, 0xd3, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x22, 0xc9, 0x22, 0xff, 0x61, 0xd3, 0x61, 0xff, 0x9e, 0xdf, 0x9e, 0xff, 0x90, 0xdc, 0x90, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xa7, 0x00, 0xc6, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcb, 0x00, 0x00, 0x00, 0xc8, 0x00, 0xb4, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x33, 0xcd, 0x33, 0xff, 0xf6, 0xfd, 0xf6, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfa, 0xfe, 0xfa, 0xff, 0xe7, 0xf6, 0xe7, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0x77, 0x00, 0xc6, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x48, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x20, 0xca, 0x20, 0xff, 0x88, 0xda, 0x88, 0xff, 0x29, 0xcd, 0x29, 0xff, 0xc2, 0xe9, 0xc2, 0xff, 0xe7, 0xf6, 0xe7, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xf7, 0x00, 0xc8, 0x00, 0x18, 0x00, 0xc8, 0x00, 0xac, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0xc3, 0xe9, 0xc3, 0xff, 0xe7, 0xf6, 0xe7, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0x74, 0x00, 0xc8, 0x00, 0xef, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0xc3, 0xe9, 0xc3, 0xff, 0xe7, 0xf6, 0xe7, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xb4, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0xc3, 0xe9, 0xc3, 0xff, 0xe7, 0xf6, 0xe7, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xd7, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0xc3, 0xe9, 0xc3, 0xff, 0xe7, 0xf6, 0xe7, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xd7, 0x00, 0xc8, 0x00, 0xef, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0xc3, 0xe9, 0xc3, 0xff, 0xe7, 0xf6, 0xe7, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xb4, 0x00, 0xc8, 0x00, 0xac, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0xc3, 0xe9, 0xc3, 0xff, 0xe7, 0xf6, 0xe7, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0x74, 0x00, 0xc8, 0x00, 0x48, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x27, 0xcd, 0x27, 0xff, 0x2a, 0xce, 0x2a, 0xff, 0xc5, 0xeb, 0xc5, 0xff, 0xe8, 0xf7, 0xe8, 0xff, 0x29, 0xce, 0x29, 0xff, 0x2a, 0xce, 0x2a, 0xff, 0x0a, 0xc9, 0x0a, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xf7, 0x00, 0xc8, 0x00, 0x18, 0x00, 0xce, 0x00, 0x00, 0x00, 0xc8, 0x00, 0xb3, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc7, 0x00, 0xff, 0xf2, 0xfc, 0xf2, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x61, 0xd2, 0x61, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0x77, 0x00, 0xcb, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x10, 0x00, 0xc8, 0x00, 0xd3, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x2f, 0xcc, 0x2f, 0xff, 0x33, 0xcc, 0x33, 0xff, 0x33, 0xcc, 0x33, 0xff, 0x33, 0xcc, 0x33, 0xff, 0x33, 0xcc, 0x33, 0xff, 0x33, 0xcc, 0x33, 0xff, 0x0d, 0xc9, 0x0d, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xa7, 0x00, 0xc9, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc7, 0x00, 0x00, 0x00, 0xc9, 0x00, 0x0f, 0x00, 0xc8, 0x00, 0xac, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xff, 0x00, 0xc8, 0x00, 0xfb, 0x00, 0xc8, 0x00, 0x80, 0x00, 0xc8, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x3c, 0x00, 0xc8, 0x00, 0x9c, 0x00, 0xc8, 0x00, 0xdb, 0x00, 0xc8, 0x00, 0xfb, 0x00, 0xc8, 0x00, 0xf7, 0x00, 0xc8, 0x00, 0xcf, 0x00, 0xc8, 0x00, 0x8b, 0x00, 0xc8, 0x00, 0x24, 0x00, 0xca, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, #endif }; const lv_img_dsc_t info_1_16px = { .header.always_zero = 0, .header.w = 16, .header.h = 16, .data_size = 256 * LV_IMG_PX_SIZE_ALPHA_BYTE, .header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA, .data = info_1_16px_map, }; /* * writing the pixel map */ int main(int argc, char **argv) { FILE *fp; char *binFile; binFile="info_1_16px_argb8888.bin"; /* 32 bit color */ fp = fopen(binFile, "wb"); fwrite(info_1_16px_map,info_1_16px.data_size,1,fp); fclose(fp); }
the_stack_data/89201046.c
#include <stdio.h> #define LENGTH 10 #define WIDTH 5 #define NEWLINE '\n' int main() { int area; area = LENGTH * WIDTH; printf("value of area : %d", area); printf("%c", NEWLINE); return 0; }
the_stack_data/34512130.c
/* * stdlib/abort.c * * This file is part of JunOS C Library. * * Copyright (C) 2016, Liu Xiaofeng <[email protected]> * Licensed under MIT, http://opensource.org/licenses/MIT. */ #include <stdlib.h> #include <sys/unistd.h> #include <signal.h> void abort(void) { sigsend(getpid(), SIGABRT); }
the_stack_data/15185.c
#include<stdio.h> #include<stdlib.h> int sorting_shell(int *arr, int arr_len) { int tmp,shet=0,j; for (int d = arr_len / 2; d > 0; d=d/2) { for (int i = d; i < arr_len; ++i) { tmp = arr[i]; for ( j = i; j >= d; j = j - d) { shet++; if (tmp < arr[j - d]) { //shet++; arr[j] = arr[j - d]; } else break; } shet++; arr[j] = tmp; } } return shet; } int main() { int shet,n,*arr; scanf("%d", &n); arr = (int*)malloc(n * sizeof(int)); for (int i = 0; i < n; ++i) { scanf("%d", &arr[i]); } sorting_shell(arr, n); for (int i = 0; i < n-1; ++i) { printf("%d ", arr[i]); } printf("%d\n", arr[n-1]); free(arr); return 0; }
the_stack_data/192330252.c
/*** * This code is a part of EvoApproxLib library (ehw.fit.vutbr.cz/approxlib) distributed under The MIT License. * When used, please cite the following article(s): PRABAKARAN B. S., MRAZEK V., VASICEK Z., SEKANINA L., SHAFIQUE M. ApproxFPGAs: Embracing ASIC-based Approximate Arithmetic Components for FPGA-Based Systems. DAC 2020. ***/ // MAE% = 0.22 % // MAE = 147 // WCE% = 0.94 % // WCE = 614 // WCRE% = 100.00 % // EP% = 98.64 % // MRE% = 4.98 % // MSE = 33225 // FPGA_POWER = 0.81 // FPGA_DELAY = 9.6 // FPGA_LUT = 42 #include <stdint.h> #include <stdlib.h> uint64_t mul8u_18VP(const uint64_t B,const uint64_t A) { uint64_t O, dout_23, dout_30, dout_42, dout_45, dout_51, dout_53, dout_82, dout_84, dout_85, dout_87, dout_88, dout_94, dout_95, dout_96, dout_118, dout_122, dout_123, dout_124, dout_125, dout_126, dout_127, dout_128, dout_129, dout_130, dout_131, dout_135, dout_136, dout_137, dout_138, dout_139, dout_158, dout_160, dout_162, dout_163, dout_164, dout_165, dout_166, dout_167, dout_168, dout_169, dout_170, dout_171, dout_172, dout_173, dout_174, dout_178, dout_179, dout_180, dout_181, dout_182, dout_198, dout_199, dout_200, dout_201, dout_202, dout_203, dout_204, dout_205, dout_206, dout_207, dout_208, dout_209, dout_210, dout_211, dout_212, dout_213, dout_214, dout_215, dout_216, dout_217, dout_220, dout_221, dout_222, dout_223, dout_224, dout_225, dout_236, dout_237, dout_241, dout_242, dout_243, dout_244, dout_245, dout_246, dout_247, dout_248, dout_249, dout_250, dout_251, dout_252, dout_253, dout_254, dout_255, dout_256, dout_257, dout_258, dout_259, dout_260, dout_263, dout_264, dout_265, dout_266, dout_267, dout_268, dout_275, dout_279, dout_280, dout_281, dout_282, dout_283, dout_284, dout_285, dout_286, dout_287, dout_288, dout_289, dout_290, dout_291, dout_292, dout_293, dout_294, dout_295, dout_296, dout_297, dout_298, dout_299, dout_300, dout_301, dout_302, dout_303, dout_306, dout_308, dout_311, dout_312, dout_313, dout_314, dout_315, dout_316, dout_317, dout_318, dout_319, dout_320, dout_322, dout_323, dout_324, dout_325, dout_326, dout_327, dout_328, dout_329, dout_330, dout_331, dout_332, dout_333, dout_334, dout_335, dout_336, dout_339, dout_340, dout_341, dout_344, dout_345, dout_348, dout_349, dout_350, dout_351, dout_352, dout_353, dout_354, dout_355, dout_356, dout_357, dout_358, dout_361, dout_362; int avg=0; dout_23=((B >> 7)&1)&((A >> 1)&1); dout_30=((B >> 6)&1)&((A >> 1)&1); dout_42=((A >> 1)&1)&((B >> 7)&1); dout_45=dout_23|dout_30; dout_51=((B >> 5)&1)&((A >> 2)&1); dout_53=((B >> 7)&1)&((A >> 2)&1); dout_82=((A >> 2)&1)&((B >> 6)&1); dout_84=dout_42^dout_82; dout_85=((A >> 2)&1)&dout_30; dout_87=dout_84^dout_45; dout_88=dout_85|dout_42; dout_94=((B >> 5)&1)&((A >> 3)&1); dout_95=((B >> 6)&1)&((A >> 3)&1); dout_96=((B >> 7)&1)&((A >> 3)&1); dout_118=((A >> 3)&1)&((B >> 4)&1); dout_122=dout_87^dout_94; dout_123=dout_87&dout_94; dout_124=dout_122&dout_51; dout_125=dout_122^dout_51; dout_126=dout_123|dout_124; dout_127=dout_53^dout_95; dout_128=dout_53&dout_95; dout_129=dout_127&dout_88; dout_130=dout_127^dout_88; dout_131=dout_128|dout_129; dout_135=((A >> 4)&1)&((B >> 3)&1); dout_136=((B >> 4)&1)&((A >> 4)&1); dout_137=((B >> 5)&1)&((A >> 4)&1); dout_138=((B >> 6)&1)&((A >> 4)&1); dout_139=((B >> 7)&1)&((A >> 4)&1); dout_158=dout_136&dout_125; dout_160=dout_125^dout_136; dout_162=dout_160&dout_118; dout_163=dout_160^dout_118; dout_164=dout_158|dout_162; dout_165=dout_130^dout_137; dout_166=dout_130&dout_137; dout_167=dout_165&dout_126; dout_168=dout_165^dout_126; dout_169=dout_166|dout_167; dout_170=dout_96^dout_138; dout_171=dout_96&dout_138; dout_172=dout_170&dout_131; dout_173=dout_170^dout_131; dout_174=dout_171|dout_172; dout_178=((B >> 3)&1)&((A >> 5)&1); dout_179=((B >> 4)&1)&((A >> 5)&1); dout_180=((B >> 5)&1)&((A >> 5)&1); dout_181=((B >> 6)&1)&((A >> 5)&1); dout_182=((B >> 7)&1)&((A >> 5)&1); dout_198=dout_163^dout_178; dout_199=dout_163&dout_178; dout_200=dout_198&dout_135; dout_201=dout_198^dout_135; dout_202=dout_199|dout_200; dout_203=dout_168^dout_179; dout_204=dout_168&dout_179; dout_205=dout_203&dout_164; dout_206=dout_203^dout_164; dout_207=dout_204|dout_205; dout_208=dout_173^dout_180; dout_209=dout_173&dout_180; dout_210=dout_208&dout_169; dout_211=dout_208^dout_169; dout_212=dout_209|dout_210; dout_213=dout_139^dout_181; dout_214=dout_139&dout_181; dout_215=dout_213&dout_174; dout_216=dout_213^dout_174; dout_217=dout_214|dout_215; dout_220=((B >> 2)&1)&((A >> 6)&1); dout_221=((B >> 3)&1)&((A >> 6)&1); dout_222=((B >> 4)&1)&((A >> 6)&1); dout_223=((B >> 5)&1)&((A >> 6)&1); dout_224=((B >> 6)&1)&((A >> 6)&1); dout_225=((B >> 7)&1)&((A >> 6)&1); dout_236=dout_201^dout_220; dout_237=dout_201&dout_220; dout_241=dout_206^dout_221; dout_242=dout_206&dout_221; dout_243=dout_241&dout_202; dout_244=dout_241^dout_202; dout_245=dout_242|dout_243; dout_246=dout_211^dout_222; dout_247=dout_211&dout_222; dout_248=dout_246&dout_207; dout_249=dout_246^dout_207; dout_250=dout_247|dout_248; dout_251=dout_216^dout_223; dout_252=dout_216&dout_223; dout_253=dout_251&dout_212; dout_254=dout_251^dout_212; dout_255=dout_252|dout_253; dout_256=dout_182^dout_224; dout_257=dout_182&dout_224; dout_258=dout_256&dout_217; dout_259=dout_256^dout_217; dout_260=dout_257|dout_258; dout_263=((B >> 2)&1)&((A >> 7)&1); dout_264=((B >> 3)&1)&((A >> 7)&1); dout_265=((B >> 4)&1)&((A >> 7)&1); dout_266=((B >> 5)&1)&((A >> 7)&1); dout_267=((B >> 6)&1)&((A >> 7)&1); dout_268=((B >> 7)&1)&((A >> 7)&1); dout_275=((B >> 1)&1)&((A >> 7)&1); dout_279=dout_244^dout_263; dout_280=dout_244&dout_263; dout_281=dout_279&dout_237; dout_282=dout_279^dout_237; dout_283=dout_280|dout_281; dout_284=dout_249^dout_264; dout_285=dout_249&dout_264; dout_286=dout_284&dout_245; dout_287=dout_284^dout_245; dout_288=dout_285|dout_286; dout_289=dout_254^dout_265; dout_290=dout_254&dout_265; dout_291=dout_289&dout_250; dout_292=dout_289^dout_250; dout_293=dout_290|dout_291; dout_294=dout_259^dout_266; dout_295=dout_259&dout_266; dout_296=dout_294&dout_255; dout_297=dout_294^dout_255; dout_298=dout_295|dout_296; dout_299=dout_225^dout_267; dout_300=dout_225&dout_267; dout_301=dout_299&dout_260; dout_302=dout_299^dout_260; dout_303=dout_300|dout_301; dout_306=dout_282^dout_275; dout_308=dout_282&dout_275; dout_311=dout_287^dout_283; dout_312=dout_287&dout_283; dout_313=dout_311&dout_308; dout_314=dout_311^dout_308; dout_315=dout_312|dout_313; dout_316=dout_292^dout_288; dout_317=dout_292&dout_288; dout_318=dout_316&dout_315; dout_319=dout_316^dout_315; dout_320=dout_317|dout_318; dout_322=dout_297&dout_293; dout_323=dout_302^dout_298; dout_324=dout_302&dout_298; dout_325=dout_323&dout_322; dout_326=dout_323^dout_322; dout_327=dout_324|dout_325; dout_328=dout_268^dout_303; dout_329=dout_268&dout_303; dout_330=dout_328&dout_327; dout_331=dout_328^dout_327; dout_332=dout_329|dout_330; dout_333=dout_297^dout_293; dout_334=dout_320^0xFFFFFFFFFFFFFFFFU; dout_335=dout_333^0xFFFFFFFFFFFFFFFFU; dout_336=dout_322|dout_333; dout_339=dout_323&dout_336; dout_340=dout_323^dout_336; dout_341=dout_324|dout_339; dout_344=dout_328&dout_341; dout_345=dout_328^dout_341; dout_348=dout_333&dout_334; dout_349=dout_335&dout_320; dout_350=dout_348|dout_349; dout_351=dout_320^0xFFFFFFFFFFFFFFFFU; dout_352=dout_326&dout_351; dout_353=dout_340&dout_320; dout_354=dout_352|dout_353; dout_355=dout_320^0xFFFFFFFFFFFFFFFFU; dout_356=dout_331&dout_355; dout_357=dout_345&dout_320; dout_358=dout_356|dout_357; dout_361=dout_344&dout_320; dout_362=dout_332|dout_361; O = 0; O |= (dout_207&1) << 0; O |= (dout_53&1) << 1; O |= (dout_174&1) << 2; O |= (dout_302&1) << 3; O |= (dout_214&1) << 4; O |= (dout_214&1) << 5; O |= (dout_182&1) << 6; O |= (dout_220&1) << 7; O |= (dout_236&1) << 8; O |= (dout_306&1) << 9; O |= (dout_314&1) << 10; O |= (dout_319&1) << 11; O |= (dout_350&1) << 12; O |= (dout_354&1) << 13; O |= (dout_358&1) << 14; O |= (dout_362&1) << 15; return O; }
the_stack_data/115764865.c
#define true 1 #define false 0 typedef unsigned char byte; typedef struct uart { unsigned int dr; unsigned int sr; unsigned int ackint; unsigned int setint; } UART; UART* uart0 = (UART*)(0x10000000); //UART* uart0; byte outbuffer[280]; byte inbuffer[80]; int breakopcode; void putc(byte c) { // wait while busy: while ((uart0->sr & 0x1) == 0x1); // transmit char: uart0->dr = c; } byte getc() { // wait for rx available: while ((uart0->sr & 0x2) == 0x0); // receive char: return uart0->dr; } void ackint() { uart0->ackint = 1; } void ioprint(char* txt) { while (*txt) { putc(*txt); txt++; } } void ioprint_int(int i) { int b; int c; ioprint("0x"); for (b = 28; b >= 0; b = b - 4) { c = (i >> b) & 0xF; if (c < 10) { putc( 48 + c ); } else { putc( 65 - 10 + c ); } } putc(10); // Newline! } int hexchar2int(byte ch) { if(ch>=0x61 && ch<0x67) { return(ch-0x61+10); } if(ch>=0x30 && ch<0x3A) { return(ch-0x30); } if(ch>=0x41 && ch<0x47) { return(ch-0x41+10); } return(-1); } byte highhex(byte ch) { ch=ch>>4 & 0xf; if(ch>9) { ch+= 0x37; } else { ch+= 0x30; } return(ch); } byte lowhex(byte ch) { ch&= 0xf; if(ch>9) { ch+= 0x37; } else { ch+= 0x30; } return(ch); } int hexstring2int(byte* ptr, int* val) { int numchars = 0; byte ch; int res; ch = *ptr; res = hexchar2int(ch); //io.print_int(res); while(res != -1) { *val=(*val<<4)+res; numchars+=1; ptr+=1; ch=*ptr; res = hexchar2int(ch); //io.print_int(res); } return(numchars); } int get_packet(byte* data) { byte checksum; int xmitcsum; byte bch; // wait for $ bch=getc(); while (bch != 0x24) { bch=getc(); } checksum = 0; xmitcsum = -1; // read until # bch = getc(); while (bch!=0x23) { checksum = checksum + bch; *data = bch; data += 1; bch = getc(); } *data = 0; bch = getc(); xmitcsum = hexchar2int(bch) << 4; bch = getc(); xmitcsum = xmitcsum + hexchar2int(bch); checksum &= 0xff; if (checksum != xmitcsum) { // failed checksum - putc(0x2d); ioprint("Received:"); ioprint_int(xmitcsum); ioprint("Calculated:"); ioprint_int(checksum); return(-1); } else { // successful transfer + putc(0x2b); return(0); } } void put_packet(byte* data) { byte checksum; int count; byte bch; putc(0x24); checksum = 0; bch = *data; while (bch != 0) { putc(bch); checksum += bch; data += 1; bch=*data; } checksum&=0xff; putc(0x23); putc(highhex(checksum)); putc(lowhex(checksum)); bch=getc(); } void readmem(byte* cmdptr,byte* dataptr) { int addr = 0; int length = 0; int res = 0; byte ch; byte* memptr; res=hexstring2int(cmdptr,&addr); cmdptr+=res+1; res=hexstring2int(cmdptr,&length); memptr=(byte*)addr; while(length>0) { ch=*memptr; *dataptr=highhex(ch); dataptr+=1; *dataptr=lowhex(ch); memptr+=1; dataptr+=1; length-=1; } *dataptr=0; } void readreg(byte* cmdptr,byte* regs, byte* dataptr) { int regnr = 0; int res = 0; int i; byte bch; byte* memptr; res=hexstring2int(cmdptr,&regnr); regs+=regnr*4; for(i=0;i<4;i+=1) { bch = *regs; *dataptr = highhex(bch); dataptr += 1; *dataptr = lowhex(bch); dataptr += 1; regs += 1; } *dataptr=0; } void readregs(byte* regs, byte* dataptr) { int i,j; byte bch = 0; for(i=0;i<33;i=i+1) { for(j=0;j<4;j+=1) { bch = *regs; *dataptr = highhex(bch); dataptr += 1; *dataptr = lowhex(bch); dataptr += 1; regs += 1; } } *dataptr=0; } void writereg(byte* cmdptr,byte* regs) { int regnr = 0; int res = 0; int i; byte ch = 0; byte* memptr; res = hexstring2int(cmdptr,&regnr); cmdptr += res+1; regs += regnr*4; for(i=0;i<4;i+=1) { ch = *cmdptr; res = hexchar2int(ch); cmdptr += 1; ch = *cmdptr; res = (res<<4) + hexchar2int(ch); cmdptr += 1; *regs = res; regs += 1; } } void writeregs(byte* cmdptr,byte* regs) { int i,j; int res = 0; byte ch = 0; for(i=0;i<33;i=i+1) { for(j=0;j<4;j+=1) { ch = *cmdptr; res = hexchar2int(ch); cmdptr += 1; ch = *cmdptr; res = (res<<4) + hexchar2int(ch); cmdptr += 1; *regs = res; regs += 1; } } } void writemem(byte* cmdptr) { int addr = 0; int length = 0; int res = 0; byte ch; byte* memptr; res = hexstring2int(cmdptr,&addr); cmdptr += res+1; res = hexstring2int(cmdptr,&length); memptr = (byte*)addr; cmdptr += res+1; while(length>0) { ch = *cmdptr; res = hexchar2int(ch); cmdptr += 1; ch = *cmdptr; res = (res<<4) + hexchar2int(ch); cmdptr += 1; *memptr = res; memptr += 1; length -= 1; } } void setbreak(byte* cmdptr, int* memval) { int addr = 0; int* memptr; int res = 0; res=hexstring2int(cmdptr,&addr); memptr=(int*)addr; *memval=*memptr; *memptr=0x100073; } void clearbreak(byte* cmdptr, int* memval) { int addr = 0; int* memptr; int res = 0; res=hexstring2int(cmdptr,&addr); memptr=(int*)addr; *memptr=*memval; } void status(byte id, byte* regs, byte* dataptr) { int i; byte bch; *dataptr = 0x54; // "T" dataptr += 1; *dataptr = highhex(id); dataptr += 1; *dataptr = lowhex(id); dataptr += 1; *dataptr = 0x32; //"2" = PC dataptr += 1; *dataptr = 0x30; //"0" = PC dataptr += 1; *dataptr = 0x3a; // ":" dataptr += 1; regs+=128; for(i=0;i<4;i+=1) { bch = *regs; *dataptr = highhex(bch); dataptr += 1; *dataptr = lowhex(bch); dataptr += 1; regs += 1; } *dataptr=0x3b; // ";" dataptr+=1; *dataptr=0; } int irq_irq(byte* regs,int irqs) { int i = 0 , j = 0; byte bch; byte* outptr = 0; byte* regsptr = 0; int debug = true; int res = 0; int steps = 0; // uart0 = (UART*)(0x10000000); status(irqs, regs, &outbuffer[0]); put_packet(&outbuffer[0]); while(debug) { res = get_packet(&inbuffer[0]); bch = inbuffer[0]; if(bch == 0x6d) { readmem(&inbuffer[2],&outbuffer[0]); put_packet(&outbuffer[0]); } if(bch == 0x4d) { writemem(&inbuffer[2]); outbuffer[0] = 0x4f; outbuffer[1] = 0x4b; outbuffer[2] = 0; put_packet(&outbuffer[0]); } if(bch == 0x70) { readreg(&inbuffer[2], regs, &outbuffer[0]); put_packet(&outbuffer[0]); } if(bch == 0x50) { writereg(&inbuffer[2], regs); outbuffer[0] = 0x4f; outbuffer[1] = 0x4b; outbuffer[2] = 0; put_packet(&outbuffer[0]); } if(bch == 0x67) { readregs(regs, &outbuffer[0]); put_packet(&outbuffer[0]); } if(bch == 0x47) { writeregs(&inbuffer[2], regs); outbuffer[0] = 0x4f; outbuffer[1] = 0x4b; outbuffer[2] = 0; put_packet(&outbuffer[0]); } if(bch == 0x5a) { setbreak(&inbuffer[3], &breakopcode); outbuffer[0] = 0x4f; outbuffer[1] = 0x4b; outbuffer[2] = 0; put_packet(&outbuffer[0]); } if(bch == 0x7a) { clearbreak(&inbuffer[3], &breakopcode); outbuffer[0] = 0x4f; outbuffer[1] = 0x4b; outbuffer[2] = 0; put_packet(&outbuffer[0]); } if(bch == 0x3f) { status(irqs, regs, &outbuffer[0]); put_packet(&outbuffer[0]); } if(bch == 0x63) { debug=false; } if(bch == 0x73) { uart0->setint = 1; return(1); } if(bch == 0x6e) { res = hexstring2int(&inbuffer[2],&steps); uart0->setint = 1; return(steps); } } ackint(); return(0); }
the_stack_data/73575096.c
/* This testcase is part of GDB, the GNU debugger. Copyright 2011-2021 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ static void pendfunc1 (void) { int x = 0; int y = x + 4; } void pendfunc (int x) { pendfunc1 (); }
the_stack_data/232954658.c
#include <assert.h> #include <stdlib.h> void main() { char *data; data = nondet() ? malloc(1) : malloc(2); assert(__CPROVER_OBJECT_SIZE(data) <= 2); }
the_stack_data/51701502.c
/* Test file for semantic errors. Contains exactly one error. */ int a; int main(void) { a = foo(a); // Function 'foo' not defined }
the_stack_data/1074554.c
#include <stdio.h> #include <stdlib.h> #include <limits.h> #include <ctype.h> /* * http://www.algorithmist.com/index.php/Kadane's_Algorithm * O(n) algorithm The algorithm keeps track of the tentative maximum subsequence in (maxSum, maxStartIndex, maxEndIndex). It accumulates a partial sum in currentMaxSum and updates the optimal range when this partial sum becomes larger than maxSum. Kadane's Algorithm(array[1..n]) begin (maxSum, maxStartIndex, maxEndIndex) := (-INFINITY, 0, 0) currentMaxSum := 0 currentStartIndex := 1 for currentEndIndex := 1 to n do currentMaxSum := currentMaxSum + array[currentEndIndex] if currentMaxSum > maxSum then (maxSum, maxStartIndex, maxEndIndex) := (currentMaxSum, currentStartIndex, currentEndIndex) endif if currentMaxSum < 0 then currentMaxSum := 0 currentStartIndex := currentEndIndex + 1 endif endfor return (maxSum, maxStartIndex, maxEndIndex) end */ int main(int argc, char const *argv[]) { //int a[] = {-5, -1, 2, -3, 0, -3, 3}; int a[] = {-2,1,-3,4,-1,2,1,-5,4}; int size = sizeof(a)/sizeof(a[0]); int maxSum = INT_MIN, maxStartIndex = 0, maxEndIndex = 0, currentMaxSum = 0; for (int i = 0; i < size; ++i) { /* code */ currentMaxSum += a[i]; if(currentMaxSum > maxSum) { maxSum = currentMaxSum; maxEndIndex = i; } if(currentMaxSum < 0) { maxStartIndex = i +1; currentMaxSum = 0; } } printf("The maxSum is %d, maxStartIndex is %d, maxEndIndex is %d \n",maxSum, maxStartIndex, maxEndIndex ); return 0; }
the_stack_data/1213040.c
#include <stdio.h> #include <stdlib.h> #include <math.h> #ifndef RANDSEED #define RANDSEED 1 #endif /* routine to test*/ void dgemm_test(const int M,const int N,const int K,const double alpha,const double* A,const int lda,const double* B,const int ldb,const double beta,double* C,const int ldc) ; /* macro for the value of routine parameter */ #ifndef SIZE #define SIZE 200 #endif void dgemm_test_ref(const int M,const int N,const int K,const double alpha,const double* A,const int lda,const double* B,const int ldb,const double beta,double* C,const int ldc) { int i; int j; int l; for (j=0; j<N; j+=1) { for (i=0; i<M; i+=1) { C[j*ldc+i] = beta*C[j*ldc+i]; for (l=0; l<K; l+=1) { C[j*ldc+i] = C[j*ldc+i]+alpha*A[l*lda+i]*B[j*ldb+l]; } } } } int main(int argc, char **argv) { /* induction variables */ int __pt_i0, __pt_i1, __pt_i2; /* Declaring parameters of the routine */ int M; int N; int K; double alpha; double* A; int lda; double* B; int ldb; double beta; double* C_comp; double* C; int ldc; double* B_buf; int B_size; double* A_buf; int A_size; double* C_buf; int C_size; double* C_comp_buf; int C_comp_size; /* parameter initializations */ srand(RANDSEED); ldc = SIZE; beta = rand();; ldb = SIZE; lda = SIZE; alpha = rand();; K = SIZE; N = SIZE; M = SIZE; B_size=N*ldb+K; B_buf = (double*)calloc(B_size, sizeof(double)); A_size=K*lda+M; A_buf = (double*)calloc(A_size, sizeof(double)); C_size=N*ldc+M; C_buf = (double*)calloc(C_size, sizeof(double)); C_comp_size=N*ldc+M; C_comp_buf = (double*)calloc(C_comp_size, sizeof(double)); for (__pt_i0=0; __pt_i0<B_size; ++__pt_i0) { B_buf[__pt_i0] = rand();; } B = B_buf; for (__pt_i0=0; __pt_i0<A_size; ++__pt_i0) { A_buf[__pt_i0] = rand();; } A = A_buf; for (__pt_i0=0; __pt_i0<C_size; ++__pt_i0) { C_buf[__pt_i0] = rand();; } C = C_buf; for (__pt_i0=0; __pt_i0<C_comp_size; ++__pt_i0) { C_comp_buf[__pt_i0] = rand();; } C_comp = C_comp_buf; for (__pt_i0=0; __pt_i0<C_size; ++__pt_i0) { C_comp_buf[__pt_i0] = C_buf[__pt_i0]; } dgemm_test (M,N,K,alpha,A,lda,B,ldb,beta,C_comp,ldc); dgemm_test_ref (M,N,K,alpha,A,lda,B,ldb,beta,C,ldc); { int diff_flag = 0; for (__pt_i0=0; __pt_i0<N*ldc+M; ++__pt_i0) { if(C_comp_buf[__pt_i0] != C_buf[__pt_i0]) { diff_flag = 1; printf("Position %d (%f) and Position %d (%f) differ by %.15f\n", __pt_i0, C_comp_buf[__pt_i0], __pt_i0, C_buf[__pt_i0], fabs(C_comp_buf[__pt_i0]-C_buf[__pt_i0])); } /*else { printf("Identical output at index %d\n", __pt_i0); } */ } if(diff_flag) { printf("Output differs\n"); }else { printf("Output is identical\n"); } } return(0); }
the_stack_data/102578.c
#include<stdio.h> int main() { int n,i,count=0; char name; float total,c2,r2,s2,c=0,r=0,s=0,num; scanf("%d",&n); printf("%d",n); for(i=1;i<=n;i++) { scanf("%f%c",&num,&name); scanf("%c",&name); printf("%d %d\n",i,n); } }
the_stack_data/90762720.c
// Check that ld gets arch_multiple. // RUN: %clang -target i386-apple-darwin9 -arch i386 -arch x86_64 %s -### -o foo 2> %t.log // RUN: grep '".*ld.*" .*"-arch_multiple" "-final_output" "foo"' %t.log // Make sure we run dsymutil on source input files. // RUN: %clang -target i386-apple-darwin9 -### -g %s -o BAR 2> %t.log // RUN: grep -E '".*dsymutil(\.exe)?" "-o" "BAR.dSYM" "BAR"' %t.log // RUN: %clang -target i386-apple-darwin9 -### -g -filelist FOO %s -o BAR 2> %t.log // RUN: grep -E '".*dsymutil(\.exe)?" "-o" "BAR.dSYM" "BAR"' %t.log // Check linker changes that came with new linkedit format. // RUN: touch %t.o // RUN: %clang -target i386-apple-darwin9 -fuse-ld= -mlinker-version=400 -### -arch armv6 -miphoneos-version-min=3.0 %t.o 2> %t.log // RUN: %clang -target i386-apple-darwin9 -fuse-ld= -mlinker-version=400 -### -arch armv6 -miphoneos-version-min=3.0 -dynamiclib %t.o 2>> %t.log // RUN: %clang -target i386-apple-darwin9 -fuse-ld= -mlinker-version=400 -### -arch armv6 -miphoneos-version-min=3.0 -bundle %t.o 2>> %t.log // RUN: FileCheck -check-prefix=LINK_IPHONE_3_0 %s < %t.log // LINK_IPHONE_3_0: {{ld(.exe)?"}} // LINK_IPHONE_3_0: -iphoneos_version_min // LINK_IPHONE_3_0: 3.0.0 // LINK_IPHONE_3_0-NOT: -lcrt1.3.1.o // LINK_IPHONE_3_0: -lcrt1.o // LINK_IPHONE_3_0: -lSystem // LINK_IPHONE_3_0: {{ld(.exe)?"}} // LINK_IPHONE_3_0: -dylib // LINK_IPHONE_3_0: -ldylib1.o // LINK_IPHONE_3_0: -lSystem // LINK_IPHONE_3_0: {{ld(.exe)?"}} // LINK_IPHONE_3_0: -lbundle1.o // LINK_IPHONE_3_0: -lSystem // RUN: %clang -target i386-apple-darwin9 -fuse-ld= -mlinker-version=400 -### -arch armv7 -miphoneos-version-min=3.1 %t.o 2> %t.log // RUN: %clang -target i386-apple-darwin9 -fuse-ld= -mlinker-version=400 -### -arch armv7 -miphoneos-version-min=3.1 -dynamiclib %t.o 2>> %t.log // RUN: %clang -target i386-apple-darwin9 -fuse-ld= -mlinker-version=400 -### -arch armv7 -miphoneos-version-min=3.1 -bundle %t.o 2>> %t.log // RUN: FileCheck -check-prefix=LINK_IPHONE_3_1 %s < %t.log // LINK_IPHONE_3_1: {{ld(.exe)?"}} // LINK_IPHONE_3_1: -iphoneos_version_min // LINK_IPHONE_3_1: 3.1.0 // LINK_IPHONE_3_1-NOT: -lcrt1.o // LINK_IPHONE_3_1: -lcrt1.3.1.o // LINK_IPHONE_3_1: -lSystem // LINK_IPHONE_3_1: {{ld(.exe)?"}} // LINK_IPHONE_3_1: -dylib // LINK_IPHONE_3_1-NOT: -ldylib1.o // LINK_IPHONE_3_1: -lSystem // LINK_IPHONE_3_1: {{ld(.exe)?"}} // LINK_IPHONE_3_1-NOT: -lbundle1.o // LINK_IPHONE_3_1: -lSystem // RUN: %clang -target i386-apple-darwin9 -fuse-ld= -mlinker-version=400 -### -arch i386 -mios-simulator-version-min=3.0 %t.o 2> %t.log // RUN: %clang -target i386-apple-darwin9 -fuse-ld= -mlinker-version=400 -### -arch i386 -mios-simulator-version-min=3.0 -dynamiclib %t.o 2>> %t.log // RUN: %clang -target i386-apple-darwin9 -fuse-ld= -mlinker-version=400 -### -arch i386 -mios-simulator-version-min=3.0 -bundle %t.o 2>> %t.log // RUN: FileCheck -check-prefix=LINK_IOSSIM_3_0 %s < %t.log // LINK_IOSSIM_3_0: {{ld(.exe)?"}} // LINK_IOSSIM_3_0: -ios_simulator_version_min // LINK_IOSSIM_3_0: 3.0.0 // LINK_IOSSIM_3_0-NOT: -lcrt1.o // LINK_IOSSIM_3_0: -lSystem // LINK_IOSSIM_3_0: {{ld(.exe)?"}} // LINK_IOSSIM_3_0: -dylib // LINK_IOSSIM_3_0-NOT: -ldylib1.o // LINK_IOSSIM_3_0: -lSystem // LINK_IOSSIM_3_0: {{ld(.exe)?"}} // LINK_IOSSIM_3_0-NOT: -lbundle1.o // LINK_IOSSIM_3_0: -lSystem // RUN: %clang -target i386-apple-darwin9 -### -fpie %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_EXPLICIT_PIE %s < %t.log // // LINK_EXPLICIT_PIE: {{ld(.exe)?"}} // LINK_EXPLICIT_PIE: "-pie" // RUN: %clang -target i386-apple-darwin9 -### -fno-pie %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_EXPLICIT_NO_PIE %s < %t.log // // LINK_EXPLICIT_NO_PIE: {{ld(.exe)?"}} // LINK_EXPLICIT_NO_PIE: "-no_pie" // RUN: %clang -target x86_64-apple-darwin10 -### %t.o \ // RUN: -fuse-ld= -mlinker-version=100 2> %t.log // RUN: FileCheck -check-prefix=LINK_NEWER_DEMANGLE %s < %t.log // // LINK_NEWER_DEMANGLE: {{ld(.exe)?"}} // LINK_NEWER_DEMANGLE: "-demangle" // RUN: %clang -target x86_64-apple-darwin10 -### %t.o \ // RUN: -fuse-ld= -mlinker-version=100 -Wl,--no-demangle 2> %t.log // RUN: FileCheck -check-prefix=LINK_NEWER_NODEMANGLE %s < %t.log // // LINK_NEWER_NODEMANGLE: {{ld(.exe)?"}} // LINK_NEWER_NODEMANGLE-NOT: "-demangle" // LINK_NEWER_NODEMANGLE: "-lSystem" // RUN: %clang -target x86_64-apple-darwin10 -### %t.o \ // RUN: -fuse-ld= -mlinker-version=95 2> %t.log // RUN: FileCheck -check-prefix=LINK_OLDER_NODEMANGLE %s < %t.log // // LINK_OLDER_NODEMANGLE: {{ld(.exe)?"}} // LINK_OLDER_NODEMANGLE-NOT: "-demangle" // LINK_OLDER_NODEMANGLE: "-lSystem" // RUN: %clang -target x86_64-apple-darwin10 -### %s \ // RUN: -fuse-ld= -mlinker-version=117 -flto 2> %t.log // RUN: cat %t.log // RUN: FileCheck -check-prefix=LINK_OBJECT_LTO_PATH %s < %t.log // // LINK_OBJECT_LTO_PATH: {{ld(.exe)?"}} // LINK_OBJECT_LTO_PATH: "-object_path_lto" // RUN: %clang -target x86_64-apple-darwin10 -### %t.o \ // RUN: -force_load a -force_load b 2> %t.log // RUN: cat %t.log // RUN: FileCheck -check-prefix=FORCE_LOAD %s < %t.log // // FORCE_LOAD: {{ld(.exe)?"}} // FORCE_LOAD: "-force_load" "a" "-force_load" "b" // RUN: %clang -target x86_64-apple-darwin10 -### %t.o \ // RUN: -lazy_framework Framework 2> %t.log // // RUN: FileCheck -check-prefix=LINK_LAZY_FRAMEWORK %s < %t.log // LINK_LAZY_FRAMEWORK: {{ld(.exe)?"}} // LINK_LAZY_FRAMEWORK: "-lazy_framework" "Framework" // RUN: %clang -target x86_64-apple-darwin10 -### %t.o \ // RUN: -lazy_library Library 2> %t.log // // RUN: FileCheck -check-prefix=LINK_LAZY_LIBRARY %s < %t.log // LINK_LAZY_LIBRARY: {{ld(.exe)?"}} // LINK_LAZY_LIBRARY: "-lazy_library" "Library" // RUN: %clang -target x86_64-apple-darwin10 -fuse-ld= -mlinker-version=400 -### %t.o 2> %t.log // RUN: %clang -target x86_64-apple-macosx10.7 -fuse-ld= -mlinker-version=400 -### %t.o 2>> %t.log // RUN: FileCheck -check-prefix=LINK_VERSION_MIN %s < %t.log // LINK_VERSION_MIN: {{ld(.exe)?"}} // LINK_VERSION_MIN: "-macosx_version_min" "10.6.0" // LINK_VERSION_MIN: {{ld(.exe)?"}} // LINK_VERSION_MIN: "-macosx_version_min" "10.7.0" // RUN: %clang -target x86_64-apple-ios13.1-macabi -fuse-ld= -mlinker-version=400 -### %t.o 2>> %t.log // RUN: FileCheck -check-prefix=LINK_VERSION_MIN_MACABI %s < %t.log // LINK_VERSION_MIN_MACABI: {{ld(.exe)?"}} // LINK_VERSION_MIN_MACABI: "-maccatalyst_version_min" "13.1.0" // LINK_VERSION_MIN_MACABI-NOT: macosx_version_min // LINK_VERSION_MIN_MACABI-NOT: macos_version_min // RUN: %clang -target x86_64-apple-darwin12 -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_NO_CRT1 %s < %t.log // LINK_NO_CRT1-NOT: crt // RUN: %clang -target armv7-apple-ios6.0 -miphoneos-version-min=6.0 -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_NO_IOS_CRT1 %s < %t.log // LINK_NO_IOS_CRT1-NOT: crt // RUN: %clang -target arm64-apple-ios5.0 -miphoneos-version-min=5.0 -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_NO_IOS_ARM64_CRT1 %s < %t.log // LINK_NO_IOS_ARM64_CRT1-NOT: crt // RUN: %clang -target x86_64-apple-ios6.0 -miphoneos-version-min=6.0 -fprofile-instr-generate -resource-dir=%S/Inputs/resource_dir -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_IOSSIM_PROFILE %s < %t.log // LINK_IOSSIM_PROFILE: {{ld(.exe)?"}} // LINK_IOSSIM_PROFILE: libclang_rt.profile_iossim.a // LINK_IOSSIM_PROFILE: libclang_rt.iossim.a // RUN: %clang -target x86_64-apple-ios13-macabi -mlinker-version=400 -fprofile-instr-generate -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_MACABI_PROFILE %s < %t.log // LINK_MACABI_PROFILE: {{ld(.exe)?"}} // LINK_MACABI_PROFILE: libclang_rt.profile_osx.a // RUN: %clang -target arm64-apple-tvos8.3 -fuse-ld= -mlinker-version=400 -mtvos-version-min=8.3 -resource-dir=%S/Inputs/resource_dir -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_TVOS_ARM64 %s < %t.log // LINK_TVOS_ARM64: {{ld(.exe)?"}} // LINK_TVOS_ARM64: -tvos_version_min // LINK_TVOS_ARM64-NOT: crt // LINK_TVOS_ARM64-NOT: lgcc_s.1 // LINK_TVOS_ARM64: libclang_rt.tvos.a // RUN: %clang -target arm64-apple-tvos8.3 -fuse-ld= -mlinker-version=400 -mtvos-version-min=8.3 -fprofile-instr-generate -resource-dir=%S/Inputs/resource_dir -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_TVOS_PROFILE %s < %t.log // LINK_TVOS_PROFILE: {{ld(.exe)?"}} // LINK_TVOS_PROFILE: libclang_rt.profile_tvos.a // LINK_TVOS_PROFILE: libclang_rt.tvos.a // RUN: %clang -target arm64-apple-tvos8.3 -fuse-ld= -mlinker-version=400 -mtvos-version-min=8.3 -resource-dir=%S/Inputs/resource_dir -### %t.o -lcc_kext 2> %t.log // RUN: FileCheck -check-prefix=LINK_TVOS_KEXT %s < %t.log // LINK_TVOS_KEXT: {{ld(.exe)?"}} // LINK_TVOS_KEXT: libclang_rt.cc_kext_tvos.a // LINK_TVOS_KEXT: libclang_rt.tvos.a // RUN: %clang -target armv7k-apple-watchos2.0 -fuse-ld= -mlinker-version=400 -mwatchos-version-min=2.0 -resource-dir=%S/Inputs/resource_dir -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_WATCHOS_ARM %s < %t.log // LINK_WATCHOS_ARM: {{ld(.exe)?"}} // LINK_WATCHOS_ARM: -watchos_version_min // LINK_WATCHOS_ARM-NOT: crt // LINK_WATCHOS_ARM-NOT: lgcc_s.1 // LINK_WATCHOS_ARM: libclang_rt.watchos.a // RUN: %clang -target armv7k-apple-watchos2.0 -fuse-ld= -mlinker-version=400 -mwatchos-version-min=2.0 -resource-dir=%S/Inputs/resource_dir -fprofile-instr-generate -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_WATCHOS_PROFILE %s < %t.log // LINK_WATCHOS_PROFILE: {{ld(.exe)?"}} // LINK_WATCHOS_PROFILE: libclang_rt.profile_watchos.a // LINK_WATCHOS_PROFILE: libclang_rt.watchos.a // RUN: %clang -target armv7k-apple-watchos2.0 -fuse-ld= -mlinker-version=400 -mwatchos-version-min=2.0 -resource-dir=%S/Inputs/resource_dir -### %t.o -lcc_kext 2> %t.log // RUN: FileCheck -check-prefix=LINK_WATCHOS_KEXT %s < %t.log // LINK_WATCHOS_KEXT: {{ld(.exe)?"}} // LINK_WATCHOS_KEXT: libclang_rt.cc_kext_watchos.a // LINK_WATCHOS_KEXT: libclang_rt.watchos.a // RUN: %clang -target i386-apple-darwin12 -pg -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_PG %s < %t.log // LINK_PG: -lgcrt1.o // LINK_PG: -no_new_main // RUN: %clang -target i386-apple-darwin13 -pg -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_PG_NO_SUPPORT_OSX %s < %t.log // LINK_PG_NO_SUPPORT_OSX: error: the clang compiler does not support -pg option on versions of OS X // RUN: %clang -target x86_64-apple-ios5.0 -pg -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_PG_NO_SUPPORT %s < %t.log // LINK_PG_NO_SUPPORT: error: the clang compiler does not support -pg option on Darwin // Check that clang links with libgcc_s.1 for iOS 4 and earlier, but not arm64. // RUN: %clang -target armv7-apple-ios4.0 -miphoneos-version-min=4.0 -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_IOS_LIBGCC_S %s < %t.log // LINK_IOS_LIBGCC_S: lgcc_s.1 // RUN: %clang -target arm64-apple-ios4.0 -miphoneos-version-min=4.0 -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_NO_IOS_ARM64_LIBGCC_S %s < %t.log // LINK_NO_IOS_ARM64_LIBGCC_S-NOT: lgcc_s.1 // RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \ // RUN: -fuse-ld= -mlinker-version=100 2> %t.log // RUN: FileCheck -check-prefix=LINK_NO_EXPORT_DYNAMIC %s < %t.log // LINK_NO_EXPORT_DYNAMIC: {{ld(.exe)?"}} // LINK_NO_EXPORT_DYNAMIC-NOT: "-export_dynamic" // RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \ // RUN: -fuse-ld= -mlinker-version=137 2> %t.log // RUN: FileCheck -check-prefix=LINK_EXPORT_DYNAMIC %s < %t.log // RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \ // RUN: -fuse-ld=lld -B%S/Inputs/lld -mlinker-version=100 2> %t.log // RUN: FileCheck -check-prefix=LINK_EXPORT_DYNAMIC %s < %t.log // LINK_EXPORT_DYNAMIC: {{ld(.exe)?"}} // LINK_EXPORT_DYNAMIC: "-export_dynamic" // RUN: %clang -target x86_64h-apple-darwin -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_X86_64H_ARCH %s < %t.log // // LINK_X86_64H_ARCH: {{ld(.exe)?"}} // LINK_X86_64H_ARCH: "x86_64h" // RUN: %clang -target x86_64-apple-darwin -arch x86_64 -arch x86_64h -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_X86_64H_MULTIARCH %s < %t.log // // LINK_X86_64H_MULTIARCH: {{ld(.exe)?"}} // LINK_X86_64H_MULTIARCH: "x86_64" // // LINK_X86_64H_MULTIARCH: {{ld(.exe)?"}} // LINK_X86_64H_MULTIARCH: "x86_64h" // Check for the linker options to specify the iOS version when the // IPHONEOS_DEPLOYMENT_TARGET variable is used instead of the command-line // deployment target options. // RUN: env IPHONEOS_DEPLOYMENT_TARGET=7.0 \ // RUN: %clang -target arm64-apple-darwin -fuse-ld= -mlinker-version=400 -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_IPHONEOS_VERSION_MIN %s < %t.log // RUN: env IPHONEOS_DEPLOYMENT_TARGET=7.0 \ // RUN: %clang -target i386-apple-darwin -fuse-ld= -mlinker-version=400 -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_IOS_SIMULATOR_VERSION_MIN %s < %t.log // LINK_IPHONEOS_VERSION_MIN: -iphoneos_version_min // LINK_IOS_SIMULATOR_VERSION_MIN: -ios_simulator_version_min // Ditto for tvOS.... // RUN: env TVOS_DEPLOYMENT_TARGET=7.0 \ // RUN: %clang -target armv7-apple-darwin -fuse-ld= -mlinker-version=400 -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_TVOS_VERSION_MIN %s < %t.log // RUN: env TVOS_DEPLOYMENT_TARGET=7.0 \ // RUN: %clang -target x86_64-apple-darwin -fuse-ld= -mlinker-version=400 -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_TVOS_SIMULATOR_VERSION_MIN %s < %t.log // LINK_TVOS_VERSION_MIN: -tvos_version_min // LINK_TVOS_SIMULATOR_VERSION_MIN: -tvos_simulator_version_min // ...and for watchOS. // RUN: env WATCHOS_DEPLOYMENT_TARGET=2.0 \ // RUN: %clang -target armv7k-apple-darwin -fuse-ld= -mlinker-version=400 -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_WATCHOS_VERSION_MIN %s < %t.log // RUN: env WATCHOS_DEPLOYMENT_TARGET=2.0 \ // RUN: %clang -target i386-apple-darwin -fuse-ld= -mlinker-version=400 -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=LINK_WATCHOS_SIMULATOR_VERSION_MIN %s < %t.log // LINK_WATCHOS_VERSION_MIN: -watchos_version_min // LINK_WATCHOS_SIMULATOR_VERSION_MIN: -watchos_simulator_version_min // Check -iframework gets forward to ld as -F // RUN: %clang -target x86_64-apple-darwin %s -iframework Bar -framework Foo -### 2>&1 | \ // RUN: FileCheck --check-prefix=LINK-IFRAMEWORK %s // LINK-IFRAMEWORK: {{ld(.exe)?"}} // LINK-IFRAMEWORK: "-FBar" // Check ld64 accepts up to 5 digits with no extra characters // RUN: %clang -target x86_64-apple-darwin12 %s -### -o %t \ // RUN: -fuse-ld= -mlinker-version=133.3 2> %t.log // RUN: %clang -target x86_64-apple-darwin12 %s -### -o %t \ // RUN: -fuse-ld= -mlinker-version=133.3.0 2>> %t.log // RUN: %clang -target x86_64-apple-darwin12 %s -### -o %t \ // RUN: -fuse-ld= -mlinker-version=133.3.0.1 2>> %t.log // RUN: %clang -target x86_64-apple-darwin12 %s -### -o %t \ // RUN: -fuse-ld= -mlinker-version=133.3.0.1.2 2>> %t.log // RUN: %clang -target x86_64-apple-darwin12 %s -### -o %t \ // RUN: -fuse-ld= -mlinker-version=133.3.0.1.2.6 2>> %t.log // RUN: %clang -target x86_64-apple-darwin12 %s -### -o %t \ // RUN: -fuse-ld= -mlinker-version=133.3.0.1.a 2>> %t.log // RUN: %clang -target x86_64-apple-darwin12 %s -### -o %t \ // RUN: -fuse-ld= -mlinker-version=133.3.0.1a 2>> %t.log // RUN: FileCheck -check-prefix=LINK_VERSION_DIGITS %s < %t.log // LINK_VERSION_DIGITS-NOT: invalid version number in '-mlinker-version=133.3' // LINK_VERSION_DIGITS-NOT: invalid version number in '-mlinker-version=133.3.0' // LINK_VERSION_DIGITS-NOT: invalid version number in '-mlinker-version=133.3.0.1' // LINK_VERSION_DIGITS: invalid version number in '-mlinker-version=133.3.0.1.2' // LINK_VERSION_DIGITS: invalid version number in '-mlinker-version=133.3.0.1.2.6' // LINK_VERSION_DIGITS: invalid version number in '-mlinker-version=133.3.0.1.a' // LINK_VERSION_DIGITS: invalid version number in '-mlinker-version=133.3.0.1a' // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=PROFILE_SECTALIGN %s < %t.log // RUN: %clang -target arm64-apple-ios12 -fprofile-instr-generate -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=PROFILE_SECTALIGN %s < %t.log // PROFILE_SECTALIGN: "-sectalign" "__DATA" "__llvm_prf_cnts" "0x4000" "-sectalign" "__DATA" "__llvm_prf_data" "0x4000" // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -exported_symbols_list /dev/null -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -Wl,-exported_symbols_list,/dev/null -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -Wl,-exported_symbol,foo -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -Xlinker -exported_symbol -Xlinker foo -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -Xlinker -exported_symbols_list -Xlinker /dev/null -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log // PROFILE_EXPORT: "-exported_symbol" "___llvm_profile_filename" "-exported_symbol" "___llvm_profile_raw_version" // // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate --coverage -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=NO_PROFILE_EXPORT %s < %t.log // NO_PROFILE_EXPORT-NOT: "-exported_symbol" // // RUN: %clang -target x86_64-apple-darwin12 --coverage -exported_symbols_list /dev/null -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=GCOV_EXPORT %s < %t.log // RUN: %clang -target x86_64-apple-darwin12 -fprofile-arcs -Wl,-exported_symbols_list,/dev/null -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=GCOV_EXPORT %s < %t.log // RUN: %clang -target x86_64-apple-darwin12 -fprofile-arcs -Wl,-exported_symbol,foo -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=GCOV_EXPORT %s < %t.log // RUN: %clang -target x86_64-apple-darwin12 -fprofile-arcs -Xlinker -exported_symbol -Xlinker foo -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=GCOV_EXPORT %s < %t.log // RUN: %clang -target x86_64-apple-darwin12 -fprofile-arcs -Xlinker -exported_symbols_list -Xlinker /dev/null -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=GCOV_EXPORT %s < %t.log // GCOV_EXPORT: "-exported_symbol" "___gcov_dump" // GCOV_EXPORT: "-exported_symbol" "___gcov_reset" // // Check that we can pass the outliner down to the linker. // RUN: env IPHONEOS_DEPLOYMENT_TARGET=7.0 \ // RUN: %clang -target arm64-apple-darwin -moutline -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=MOUTLINE %s < %t.log // MOUTLINE: {{ld(.exe)?"}} // MOUTLINE-SAME: "-mllvm" "-enable-machine-outliner" "-mllvm" "-enable-linkonceodr-outlining" // RUN: env IPHONEOS_DEPLOYMENT_TARGET=7.0 \ // RUN: %clang -target arm64-apple-darwin -mno-outline -### %t.o 2> %t.log // RUN: FileCheck -check-prefix=MNO_OUTLINE %s < %t.log // MNO_OUTLINE: {{ld(.exe)?"}} // MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never"
the_stack_data/63903.c
/* * Random number generation test */ typedef unsigned long RandType; RandType r = 260158; #define BIT64 0x80000000 #define BIT63 0x40000000 #define BIT5 0x00000000 #define BIT2 0x00000000 RandType rnd(void) { int b; RandType m1, m2, m3, m4, m5; m1 = r & BIT64; m1 >>= 31; m2 = r & BIT63; m2 >>= 30; m3 = r & 0x00001000; m3 >>= 4; m4 = r & BIT2; m4 >>= 1; b = m1^m2^m3^m4^m5; r <<= 1; printf("m1=%ld, m2=%d, m3=%d, m4=%d, b=%d r=%d\n", m1, m2, m3, m4, b, r); } int main(int argc, char ** argv) { rnd(); }
the_stack_data/148578832.c
int main() { int a = 13, b = 5, c; c = a*(b - a%b); }
the_stack_data/81116.c
/*Name: Sangeeta Singh Roll no: 22339 Batch: F7 */ #include <stdio.h> int main() { int n, i, flag = 0; printf("Enter the number: "); scanf("%d", &n); for (i = 2; i <= n / 2; i++) { if (n % i == 0) { printf("%d is not a prime number", n); flag = 1; break; } } if (flag == 0) printf("%d is a prime number", n); return 0; }
the_stack_data/115766536.c
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include <math.h> int partition(int l, int r, char** a) { char* pivot = malloc(sizeof(a[r])); strcpy(pivot, a[r]); int left = l-1; int right = r; while (1) { while (!strcasecmp(a[++left], pivot)) { /* code */ } while ( (right>0) && (strcasecmp(a[--right], pivot)>0) ) { /* code */ } if (left>=right) { break; } else { char* temp = (char*)malloc(sizeof(a[left])); strcpy(temp, a[left]); strcpy(a[left], a[right]); strcpy(a[right], temp); } } char* temp = (char*)malloc(sizeof(a[r])); strcpy(temp, a[r]); strcpy(a[r], a[left]); strcpy(a[left], temp); return left; } void quicksort(int l, int r, char** a) { int partIndex; if(r-l<=0) { return; } else { partIndex = partition(l, r, a); quicksort(a, l, partIndex-1); quicksort(a, partIndex+1, r); } } int main(int argc, char** argv) { // Check that user isn't entering bullshit like more than one argument. if(argc != 2) { printf("Please use only 1 argument.\ni.e. ./pointersorter \"the*string*of*some*sort\"\nExiting...\n"); return 1; } /* input is the string that we're handling. * maxSize is the max number of "words" that can appear in an argument. * Theory is that a string can contain at most the ceiling of half its length. * Like if a string is half non alphabet letters. * ex: "a*a*a*a" */ char* input = argv[1]; int maxSize = (int)ceil(((double)strlen(input))/2)+1; printf("Max Size of Array: %d\n", maxSize); //char* strArray[maxSize]; // = { NULL }; // Initialize all elements in array to null char** strArray = (char**)malloc(maxSize*sizeof(char*)); int currentstrArray = 0; int wordStart = 0; int wordEnd; for (wordEnd = 0; wordEnd <= strlen(input)-1; wordEnd++) { printf("index %d : %c\n", wordEnd, input[wordEnd]); // If the current char isn't a alphabet letter if(!isalpha(input[wordEnd])) { // Handles case where first character isn't an alphabet letter if(wordEnd == 0) { wordStart = 1; printf("wordStart: %d\n", wordStart); continue; } else if( (!isalpha(input[wordEnd-1])) && (wordEnd==strlen(input)-1) ) { // handles case where there's multiple non alphabet letters at the end // prevents overcounting currentstrArray--; printf("%s\n", "Ending"); break; } else if(!isalpha(input[wordEnd-1])) { // handles case where there's multiple non alphabet letters wordStart = wordEnd+1; printf("%s\n", "Multiple no alphas\n"); continue; } else if(wordEnd == strlen(input)-1) { // handles case where current char is non alphabet letter, but is the last char in input int subLength = wordEnd-wordStart+1; printf("Substring Length: %d\n", subLength); char subStr[subLength]; strncpy(subStr, &input[wordStart], subLength-1); subStr[subLength-1] = '\0'; // add null terminating byte printf("Substring: %s\nSubstring length: %zd\n", subStr, strlen(subStr)); // Assign new string to a spot on strArray. strArray[currentstrArray] = malloc(sizeof(subStr)); strcpy(strArray[currentstrArray], subStr); printf("inserting string: %s at index: %d\n", strArray[currentstrArray], currentstrArray); break; } // Case where we've found the end of a new word. Create a substring first. int subLength = wordEnd-wordStart+1; printf("Substring Length: %d\n", subLength); char subStr[subLength]; strncpy(subStr, &input[wordStart], subLength-1); subStr[subLength-1] = '\0'; // add null terminating byte printf("Substring: %s\nSubstring length: %zd\n", subStr, strlen(subStr)); // Assign new string to a spot on strArray. strArray[currentstrArray] = malloc(sizeof(subStr)); strcpy(strArray[currentstrArray], subStr); printf("inserting string: %s at index: %d\n", strArray[currentstrArray], currentstrArray); currentstrArray++; // set the start of a new word to be the next char wordStart = wordEnd+1; continue; } else if(wordEnd==strlen(input)-1) { printf("%s\n", "ending\n"); // Case where we've found the end of a new word. Create a substring first. int subLength = wordEnd-wordStart+2; printf("Substring Length: %d\n", subLength); char subStr[subLength]; strncpy(subStr, &input[wordStart], subLength-1); subStr[subLength-1] = '\0'; // add null terminating byte printf("Substring: %s\nSubstring length: %zd\n", subStr, strlen(subStr)); // Assign new string to a spot on strArray. strArray[currentstrArray] = malloc(sizeof(subStr)); strcpy(strArray[currentstrArray], subStr); printf("inserting string: %s at index: %d\n", strArray[currentstrArray], currentstrArray); break; } } // Quicksort algorithm quicksort(0, currentstrArray, strArray); // Print out results for (int i = 0; i <= currentstrArray; i++) { printf("Index: %d\n", i); printf("%s\n", strArray[i]); } printf("Length: %ld\n", strlen(input)); }
the_stack_data/509003.c
#include <stdio.h> #include <string.h> int main() { char vec[24][30]; int d[24],i,p,med,med2,mes1,mes2; float pp; for(i=0;i<24;i++) { scanf(" %s",vec[i]); scanf("%d",&d[i]); } mes1=d[0]; mes2=d[12]; med=(mes2+mes1)/2; med2=(d[23]+d[22]+d[21])/3; p=(med+med2)/2; pp=(med+med2)/2; if(pp>p) { p++; } printf("%d\n",p); return 0; }
the_stack_data/154830484.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } } #define N 100000 int main( ) { int a1[N]; int a2[N]; int a3[N]; int a4[N]; int a5[N]; int a6[N]; int a7[N]; int i; for ( i = 0 ; i < N ; i++ ) { a2[i] = a1[i]; } for ( i = 0 ; i < N ; i++ ) { a3[i] = a2[i]; } for ( i = 0 ; i < N ; i++ ) { a4[i] = a3[i]; } for ( i = 0 ; i < N ; i++ ) { a5[i] = a4[i]; } for ( i = 0 ; i < N ; i++ ) { a6[i] = a5[i]; } for ( i = 0 ; i < N ; i++ ) { a7[i] = a6[i]; } int x; for ( x = 0 ; x < N ; x++ ) { __VERIFIER_assert( a1[x] == a7[x] ); } return 0; }
the_stack_data/122015114.c
#include <stdio.h> #include <stdlib.h> void vassume(int b){} void vtrace1(int x, int y, int z, int k){} int mainQ(int z, int k){ vassume(z>=0); vassume(z<=10); vassume(k>0); vassume(k<=10); int x = 1; int y = 1; int c = 1; while (1){ //assert(1+x*z-x-z*y==0); vtrace1(x, y, z, k); if(!(c < k)) break; c = c + 1; x = x*z + 1; y = y*z; } return x; } void main(int argc, char **argv){ mainQ(atoi(argv[1]), atoi(argv[2])); }
the_stack_data/211080640.c
#include <stdio.h> #include <stdlib.h> struct rect { int x, y, w, h; }; struct rect * rect_new (void) { struct rect *r = malloc(sizeof *r); r->x = r->y = r->w = r->h = 0; return r; } void rect_drag (struct rect *r, int dx, int dy) { r->x += dx; r->y += dy; } void rect_print (struct rect *r) { printf("x: %d\ny: %d\nw: %d\nh: %d\n\n", r->x, r->y, r->w, r->h ); }
the_stack_data/61450.c
#include <stdio.h> int main () { printf("\"C:\\Download\\hello.cpp\""); return 0; }
the_stack_data/46316.c
/* This file was automatically generated by CasADi. The CasADi copyright holders make no ownership claim of its contents. */ #ifdef __cplusplus extern "C" { #endif /* How to prefix internal symbols */ #ifdef CASADI_CODEGEN_PREFIX #define CASADI_NAMESPACE_CONCAT(NS, ID) _CASADI_NAMESPACE_CONCAT(NS, ID) #define _CASADI_NAMESPACE_CONCAT(NS, ID) NS ## ID #define CASADI_PREFIX(ID) CASADI_NAMESPACE_CONCAT(CODEGEN_PREFIX, ID) #else #define CASADI_PREFIX(ID) FBDynamics_ ## ID #endif #include <math.h> #ifndef casadi_real #define casadi_real double #endif #ifndef casadi_int #define casadi_int long long int #endif /* Add prefix to internal symbols */ #define casadi_f0 CASADI_PREFIX(f0) #define casadi_s0 CASADI_PREFIX(s0) #define casadi_s1 CASADI_PREFIX(s1) #define casadi_s2 CASADI_PREFIX(s2) /* Symbol visibility in DLLs */ #ifndef CASADI_SYMBOL_EXPORT #if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__) #if defined(STATIC_LINKED) #define CASADI_SYMBOL_EXPORT #else #define CASADI_SYMBOL_EXPORT __declspec(dllexport) #endif #elif defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY) #define CASADI_SYMBOL_EXPORT __attribute__ ((visibility ("default"))) #else #define CASADI_SYMBOL_EXPORT #endif #endif static const casadi_int casadi_s0[10] = {6, 1, 0, 6, 0, 1, 2, 3, 4, 5}; static const casadi_int casadi_s1[8] = {4, 1, 0, 4, 0, 1, 2, 3}; static const casadi_int casadi_s2[6] = {2, 1, 0, 2, 0, 1}; /* FBDynamics:(i0[6],i1[4],i2[4],i3[2])->(o0[6]) */ static int casadi_f0(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, int mem) { casadi_real a0, a1, a2, a3, a4, a5, a6, a7, a8; a0=arg[0]? arg[0][3] : 0; if (res[0]!=0) res[0][0]=a0; a0=arg[0]? arg[0][4] : 0; if (res[0]!=0) res[0][1]=a0; a0=arg[0]? arg[0][5] : 0; if (res[0]!=0) res[0][2]=a0; a0=arg[3]? arg[3][0] : 0; a1=arg[1]? arg[1][0] : 0; a2=(a0*a1); a3=8.2520000000000007e+000; a2=(a2/a3); a4=arg[3]? arg[3][1] : 0; a5=arg[1]? arg[1][2] : 0; a6=(a4*a5); a6=(a6/a3); a2=(a2+a6); if (res[0]!=0) res[0][3]=a2; a2=arg[1]? arg[1][1] : 0; a6=(a0*a2); a6=(a6/a3); a7=arg[1]? arg[1][3] : 0; a8=(a4*a7); a8=(a8/a3); a6=(a6+a8); a8=-9.8100000000000005e+000; a6=(a6+a8); if (res[0]!=0) res[0][4]=a6; a6=arg[2]? arg[2][1] : 0; a8=arg[0]? arg[0][1] : 0; a6=(a6-a8); a6=(a6*a1); a1=arg[2]? arg[2][0] : 0; a3=arg[0]? arg[0][0] : 0; a1=(a1-a3); a1=(a1*a2); a6=(a6-a1); a1=2.3216549759999999e-001; a6=(a6/a1); a0=(a0*a6); a6=arg[2]? arg[2][3] : 0; a6=(a6-a8); a6=(a6*a5); a5=arg[2]? arg[2][2] : 0; a5=(a5-a3); a5=(a5*a7); a6=(a6-a5); a6=(a6/a1); a4=(a4*a6); a0=(a0+a4); if (res[0]!=0) res[0][5]=a0; return 0; } CASADI_SYMBOL_EXPORT int FBDynamics(const casadi_real** arg, casadi_real** res, casadi_int* iw, casadi_real* w, int mem){ return casadi_f0(arg, res, iw, w, mem); } CASADI_SYMBOL_EXPORT int FBDynamics_alloc_mem(void) { return 0; } CASADI_SYMBOL_EXPORT int FBDynamics_init_mem(int mem) { return 0; } CASADI_SYMBOL_EXPORT void FBDynamics_free_mem(int mem) { } CASADI_SYMBOL_EXPORT int FBDynamics_checkout(void) { return 0; } CASADI_SYMBOL_EXPORT void FBDynamics_release(int mem) { } CASADI_SYMBOL_EXPORT void FBDynamics_incref(void) { } CASADI_SYMBOL_EXPORT void FBDynamics_decref(void) { } CASADI_SYMBOL_EXPORT casadi_int FBDynamics_n_in(void) { return 4;} CASADI_SYMBOL_EXPORT casadi_int FBDynamics_n_out(void) { return 1;} CASADI_SYMBOL_EXPORT casadi_real FBDynamics_default_in(casadi_int i){ switch (i) { default: return 0; } } CASADI_SYMBOL_EXPORT const char* FBDynamics_name_in(casadi_int i){ switch (i) { case 0: return "i0"; case 1: return "i1"; case 2: return "i2"; case 3: return "i3"; default: return 0; } } CASADI_SYMBOL_EXPORT const char* FBDynamics_name_out(casadi_int i){ switch (i) { case 0: return "o0"; default: return 0; } } CASADI_SYMBOL_EXPORT const casadi_int* FBDynamics_sparsity_in(casadi_int i) { switch (i) { case 0: return casadi_s0; case 1: return casadi_s1; case 2: return casadi_s1; case 3: return casadi_s2; default: return 0; } } CASADI_SYMBOL_EXPORT const casadi_int* FBDynamics_sparsity_out(casadi_int i) { switch (i) { case 0: return casadi_s0; default: return 0; } } CASADI_SYMBOL_EXPORT int FBDynamics_work(casadi_int *sz_arg, casadi_int* sz_res, casadi_int *sz_iw, casadi_int *sz_w) { if (sz_arg) *sz_arg = 4; if (sz_res) *sz_res = 1; if (sz_iw) *sz_iw = 0; if (sz_w) *sz_w = 0; return 0; } #ifdef __cplusplus } /* extern "C" */ #endif
the_stack_data/187643631.c
/* cnd_wait( cnd_t *, mtx_t * ) This file is part of the Public Domain C Library (PDCLib). Permission is granted to use, modify, and / or redistribute at will. */ #ifndef REGTEST #include <threads.h> /* Implicitly casting the parameters. */ extern int pthread_cond_wait( cnd_t *, mtx_t * ); int cnd_wait( cnd_t * cond, mtx_t * mtx ) { if ( pthread_cond_wait( cond, mtx ) == 0 ) { return thrd_success; } else { return thrd_error; } } #endif #ifdef TEST #include "_PDCLIB_test.h" int main( void ) { #ifndef REGTEST TESTCASE( NO_TESTDRIVER ); #endif return TEST_RESULTS; } #endif
the_stack_data/168894550.c
int reverse_array_diff(int n, int in_order[], int reverse_order[]){ int j = n-1; for(int i=0; i<n; i++){ reverse_order[i] = in_order[j]; j--; } return 0; }
the_stack_data/93886458.c
#include <stdio.h> #include <stdlib.h> #define TAILLE 500 void function_test (int A[TAILLE], int i) { for (i = 30; i < TAILLE; i++) A[i] = A[i-1]; } int main () { int A[TAILLE]; int i = 0; function_test(A, i); return 0; }
the_stack_data/31818.c
int main() { int x; x = -1; return x > 2; }
the_stack_data/125141382.c
/* * Copyright (C) 2015-2017 Alibaba Group Holding Limited */ #ifdef CONFIG_AOS_MESH #include <string.h> #include <stdarg.h> #include <stdio.h> #include "umesh_hal.h" #include <umesh_80211.h> #include <hal/wifi.h> struct phy_channel_info { uint32_t info1; uint32_t info2; }; extern uint32_t bk_wlan_is_ap(void); extern uint32_t bk_wlan_is_sta(void); extern int bk_wlan_start_monitor(void); extern void hal_machw_exit_monitor_mode(void); extern void tpc_update_tx_power(int8_t pwr); extern void wlan_register_mesh_monitor_cb(monitor_data_cb_t fn); extern int wlan_set_mesh_bssid(uint8_t *bssid); extern int bmsg_tx_raw_sender(uint8_t *payload, uint16_t length); extern void phy_get_channel(struct phy_channel_info *info, uint8_t index); extern uint8_t rw_ieee80211_get_chan_id(uint32_t freq); extern uint32_t rw_ieee80211_get_centre_frequency(uint32_t chan_id); extern void phy_set_channel(uint8_t band, uint8_t type, uint16_t prim20_freq, uint16_t center1_freq, uint16_t center2_freq, uint8_t index); #define NXMAC_MAX_POWER_LEVEL_ADDR 0xC00000A0 #define REG_PL_RD(addr) (*(volatile uint32_t *)(addr)) static inline uint8_t nxmac_dsss_max_pwr_level_getf(void) { uint32_t localVal = REG_PL_RD(NXMAC_MAX_POWER_LEVEL_ADDR); return ((localVal & ((uint32_t)0x0000FF00)) >> 8); } struct tx_policy_tbl { uint32_t upatterntx; uint32_t phycntrlinfo1; uint32_t phycntrlinfo2; uint32_t maccntrlinfo1; uint32_t maccntrlinfo2; uint32_t ratecntrlinfo[4]; uint32_t powercntrlinfo[4]; }; struct txl_buffer_control { struct tx_policy_tbl policy_tbl; uint32_t mac_control_info; uint32_t phy_control_info; uint32_t status; }; extern struct txl_buffer_control txl_buffer_control_24G; enum { WIFI_MESH_OFFSET = 32, WIFI_DST_OFFSET = 4, WIFI_SRC_OFFSET = 10, WIFI_BSSID_OFFSET = 16, WIFI_MAC_ADDR_SIZE = 6, }; enum { DEFAULT_MTU_SIZE = 512, }; typedef struct { uint32_t u_mtu; uint32_t b_mtu; uint8_t channel; uint8_t chn_num; const uint8_t *channels; umesh_handle_received_frame_t rxcb; void *context; umesh_hal_module_t *module; mesh_key_t keys[2]; unsigned char bssid[WIFI_MAC_ADDR_SIZE]; unsigned char macaddr[WIFI_MAC_ADDR_SIZE]; frame_stats_t stats; } mesh_hal_priv_t; typedef struct send_ext_s { void *context; void *sent; frame_t *frame; } send_cxt_t; static send_cxt_t g_send_ucast_cxt; static send_cxt_t g_send_bcast_cxt; typedef struct { frame_t frm; frame_info_t fino; mesh_hal_priv_t *priv; } compound_msg_t; typedef struct mac_entry_s { uint64_t mactime; uint16_t last_seq; uint8_t macaddr[6]; } mac_entry_t; enum { ENT_NUM = 32, }; static mac_entry_t entries[ENT_NUM]; static mesh_hal_priv_t *g_hal_priv; static void pass_to_umesh(const void* arg) { compound_msg_t *cmsg = (compound_msg_t *)arg; frame_t *frm = &cmsg->frm; frame_info_t *fino = &cmsg->fino; mesh_hal_priv_t *priv = cmsg->priv; if (priv->rxcb) { priv->rxcb(priv->context, frm, fino, 0); } aos_free(cmsg); } static void wifi_monitor_cb(uint8_t *data, int len, hal_wifi_link_info_t *info) { compound_msg_t *pf; mesh_hal_priv_t *priv = g_hal_priv; umesh_hal_module_t *module = priv->module; if (umesh_80211_filter_frame(module, data, len)) { return; } #ifdef AOS_DEBUG_MESH dump_packet(true, data, len); #endif pf = aos_malloc(sizeof(*pf) + len - WIFI_MESH_OFFSET); bzero(pf, sizeof(*pf)); pf->frm.len = len - WIFI_MESH_OFFSET; pf->frm.data = (void *)(pf + 1); memcpy(pf->fino.peer.addr, data + WIFI_SRC_OFFSET, WIFI_MAC_ADDR_SIZE); pf->fino.peer.len = 8; module = hal_umesh_get_default_module(); pf->fino.channel = hal_umesh_get_channel(module); pf->fino.rssi = info->rssi; pf->priv = priv; memcpy(pf->frm.data, data + WIFI_MESH_OFFSET, pf->frm.len); priv->stats.in_frames++; pass_to_umesh(pf); } static int beken_wifi_mesh_init(umesh_hal_module_t *module, void *config) { mesh_hal_priv_t *priv = module->base.priv_dev; g_hal_priv = priv; wifi_get_mac_address(priv->macaddr); return 0; } static int beken_wifi_mesh_enable(umesh_hal_module_t *module) { mesh_hal_priv_t *priv = module->base.priv_dev; struct tx_policy_tbl *pol; if (bk_wlan_is_ap() == 0 && bk_wlan_is_sta() == 0) { bk_wlan_start_monitor(); hal_machw_exit_monitor_mode(); tpc_update_tx_power(10); pol = &txl_buffer_control_24G.policy_tbl; pol->powercntrlinfo[0] = nxmac_dsss_max_pwr_level_getf(); } wlan_register_mesh_monitor_cb(wifi_monitor_cb); wlan_set_mesh_bssid(priv->bssid); return 0; } static int beken_wifi_mesh_disable(umesh_hal_module_t *module) { wlan_register_mesh_monitor_cb(NULL); return 0; } static int send_frame(umesh_hal_module_t *module, frame_t *frame, mac_address_t *dest, send_cxt_t *cxt) { mesh_hal_priv_t *priv = module->base.priv_dev; uint8_t *pkt; int len = frame->len + WIFI_MESH_OFFSET; umesh_handle_sent_ucast_t sent; int result = 0; pkt = aos_malloc(len); if (pkt == NULL) { result = 1; goto tx_exit; } umesh_80211_make_frame(module, frame, dest, pkt); if (bmsg_tx_raw_sender(pkt, len) != 0) { result = 1; } else { priv->stats.out_frames++; } tx_exit: if (cxt) { sent = cxt->sent; (*sent)(cxt->context, cxt->frame, result); } return 0; } static int beken_wifi_mesh_send_ucast(umesh_hal_module_t *module, frame_t *frame, mac_address_t *dest, umesh_handle_sent_ucast_t sent, void *context) { int error; mesh_hal_priv_t *priv = module->base.priv_dev; if(frame == NULL) { return -1; } if(frame->len > priv->u_mtu) { return -2; } g_send_ucast_cxt.context = context; g_send_ucast_cxt.sent = sent; g_send_ucast_cxt.frame = frame; error = send_frame(module, frame, dest, &g_send_ucast_cxt); return error; } static int beken_wifi_mesh_send_bcast(umesh_hal_module_t *module, frame_t *frame, umesh_handle_sent_bcast_t sent, void *context) { int error; mesh_hal_priv_t *priv = module->base.priv_dev; mac_address_t dest; if(frame == NULL) { return -1; } if(frame->len > priv->b_mtu) { return -2; } g_send_bcast_cxt.context = context; g_send_bcast_cxt.sent = sent; g_send_bcast_cxt.frame = frame; dest.len = 8; memset(dest.addr, 0xff, sizeof(dest.addr)); error = send_frame(module, frame, &dest, &g_send_bcast_cxt); return error; } static int beken_wifi_mesh_register_receiver(umesh_hal_module_t *module, umesh_handle_received_frame_t received, void *context) { mesh_hal_priv_t *priv = module->base.priv_dev; if(received == NULL) { return -1; } priv->rxcb = received; priv->context = context; return 0; } static int beken_wifi_mesh_get_mtu(umesh_hal_module_t *module) { mesh_hal_priv_t *priv = module->base.priv_dev; return priv->u_mtu; } static const mac_address_t *beken_wifi_mesh_get_mac_address( umesh_hal_module_t *module) { static mac_address_t addr; mesh_hal_priv_t *priv = module->base.priv_dev; memcpy(addr.addr, priv->macaddr, WIFI_MAC_ADDR_SIZE); addr.len = 8; return &addr; } static int beken_wifi_mesh_get_channel(umesh_hal_module_t *module) { int channel; struct phy_channel_info phy_info; phy_get_channel(&phy_info, 0); channel = rw_ieee80211_get_chan_id(phy_info.info1 >> 16); return channel; } static int beken_wifi_mesh_set_channel(umesh_hal_module_t *module, uint8_t channel) { uint32_t freq; if (channel < 1 || channel > 14) { return -1; } freq = rw_ieee80211_get_centre_frequency(channel); phy_set_channel(0, 0, freq, freq, 0, 0); return 0; } static int beken_wifi_mesh_get_channel_list(umesh_hal_module_t *module, const uint8_t **chnlist) { mesh_hal_priv_t *priv = module->base.priv_dev; if (chnlist == NULL) { return -1; } *chnlist = priv->channels; return priv->chn_num; } int beken_wifi_mesh_set_extnetid(umesh_hal_module_t *module, const umesh_extnetid_t *extnetid) { mesh_hal_priv_t *priv = module->base.priv_dev; memcpy(priv->bssid, extnetid->netid, WIFI_MAC_ADDR_SIZE); wlan_set_mesh_bssid(priv->bssid); return 0; } void beken_wifi_mesh_get_extnetid(umesh_hal_module_t *module, umesh_extnetid_t *extnetid) { mesh_hal_priv_t *priv = module->base.priv_dev; if (extnetid == NULL) { return; } extnetid->len = WIFI_MAC_ADDR_SIZE; memcpy(extnetid->netid, priv->bssid, extnetid->len); } static const frame_stats_t *beken_wifi_mesh_get_stats( umesh_hal_module_t *module) { mesh_hal_priv_t *priv = module->base.priv_dev; return &priv->stats; } static umesh_hal_module_t beken_wifi_mesh_module; static const uint8_t g_wifi_channels[] = {1, 4, 6, 9, 11}; static mesh_hal_priv_t g_wifi_priv = { .u_mtu = DEFAULT_MTU_SIZE, .b_mtu = DEFAULT_MTU_SIZE, .channel = 0, .chn_num = sizeof(g_wifi_channels), .channels = g_wifi_channels, .module = &beken_wifi_mesh_module, .bssid = {0xb0, 0xf8, 0x93, 0x00, 0x00, 0x07}, }; static umesh_hal_module_t beken_wifi_mesh_module = { .base.name = "beken7231_mesh_wifi_module", .base.priv_dev = &g_wifi_priv, .type = MEDIA_TYPE_WIFI, .umesh_hal_init = beken_wifi_mesh_init, .umesh_hal_enable = beken_wifi_mesh_enable, .umesh_hal_disable = beken_wifi_mesh_disable, .umesh_hal_send_ucast_request = beken_wifi_mesh_send_ucast, .umesh_hal_send_bcast_request = beken_wifi_mesh_send_bcast, .umesh_hal_register_receiver = beken_wifi_mesh_register_receiver, .umesh_hal_get_bcast_mtu = beken_wifi_mesh_get_mtu, .umesh_hal_get_ucast_mtu = beken_wifi_mesh_get_mtu, .umesh_hal_get_mac_address = beken_wifi_mesh_get_mac_address, .umesh_hal_get_channel = beken_wifi_mesh_get_channel, .umesh_hal_set_channel = beken_wifi_mesh_set_channel, .umesh_hal_set_extnetid = beken_wifi_mesh_set_extnetid, .umesh_hal_get_extnetid = beken_wifi_mesh_get_extnetid, .umesh_hal_get_stats = beken_wifi_mesh_get_stats, .umesh_hal_get_chnlist = beken_wifi_mesh_get_channel_list, }; #endif void beken_wifi_mesh_register(void) { #ifdef CONFIG_AOS_MESH hal_umesh_register_module(&beken_wifi_mesh_module); #endif }